Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Panel package #6955

Draft
wants to merge 33 commits into
base: v5/develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2bcb9e6
Move Panel Ui classes into subpackages
distantnative Jan 25, 2025
a29d738
Non-static `Panel\Document`
distantnative Jan 25, 2025
7e08385
`Panel\Access` class
distantnative Jan 25, 2025
dadb3b9
`Panel\Router` class
distantnative Jan 25, 2025
fd30c46
Start turning `Panel\Panel` non-static
distantnative Jan 25, 2025
33e4a39
Move `Panel::reponse` to `Router` class
distantnative Jan 25, 2025
c483be8
Non-static `Panel\Panel`
distantnative Jan 25, 2025
47cb456
Simplify class usage in `Panel\Panel`
distantnative Jan 25, 2025
51b55ce
Non-static `Panel\View`
distantnative Jan 25, 2025
e9505fc
New `Panel\Fiber` class
distantnative Jan 25, 2025
0a0057b
Fiber: Move data/globals each to their own method
distantnative Jan 25, 2025
000c243
Bring back `Panel\View` as static
distantnative Jan 25, 2025
34e2e62
Fix Panel router routes test
distantnative Jan 25, 2025
865eb77
Fiber data remove `$` prefix
distantnative Jan 25, 2025
89b50be
Fiber unit tests: assign coverage for methods
distantnative Jan 25, 2025
79f23a8
Non-static `Panel\Home`
distantnative Jan 25, 2025
92fca2c
Fix cs
distantnative Jan 25, 2025
11c4494
Add more unit tests
distantnative Jan 25, 2025
8cec2dc
New Area class
bastianallgeier Feb 2, 2025
a02985d
Fix area icon
bastianallgeier Feb 2, 2025
59cae7b
New Menu Item class
bastianallgeier Feb 2, 2025
9aa6dce
Use new Area and MenuItem classes
bastianallgeier Feb 2, 2025
afd58bf
Add unit tests
bastianallgeier Feb 3, 2025
53afe94
Fix cs issues
bastianallgeier Feb 3, 2025
e3c6b9f
Add unit tests for the Area class
bastianallgeier Feb 3, 2025
aef2b3e
Simplify menu item creation
bastianallgeier Feb 3, 2025
fc41466
Improve Menu unit tests
bastianallgeier Feb 3, 2025
ad396c7
Simplify code
bastianallgeier Feb 3, 2025
a005f14
Fix docblock
bastianallgeier Feb 3, 2025
38b3376
Menu/MenuItem as Ui Components
distantnative Feb 3, 2025
1909271
Improve unit tests
bastianallgeier Feb 4, 2025
7c39af1
Make Menu less dependant on the Kirby instance
bastianallgeier Feb 4, 2025
b636e70
Lab examples for `k-panel-menu`
distantnative Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/areas/account/dialogs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Kirby\Panel\UserTotpEnableDialog;
use Kirby\Panel\Ui\Dialogs\UserTotpEnableDialog;

$dialogs = require __DIR__ . '/../users/dialogs.php';

Expand Down
9 changes: 5 additions & 4 deletions config/areas/files/dialogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Kirby\Cms\Find;
use Kirby\Panel\Field;
use Kirby\Panel\Panel;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\I18n;

Expand Down Expand Up @@ -40,7 +39,9 @@
},
'submit' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
$name = $file->kirby()->request()->get('name');
$kirby = $file->kirby();
$referrer = $kirby->panel()->referrer();
$name = $kirby->request()->get('name');
$renamed = $file->changeName($name);
$oldUrl = $file->panel()->url(true);
$newUrl = $renamed->panel()->url(true);
Expand All @@ -49,7 +50,7 @@
];

// check for a necessary redirect after the filename has changed
if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) {
if ($referrer === $oldUrl && $oldUrl !== $newUrl) {
$response['redirect'] = $newUrl;
}

Expand Down Expand Up @@ -144,7 +145,7 @@
'submit' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
$redirect = false;
$referrer = Panel::referrer();
$referrer = $file->kirby()->panel()->referrer();
$url = $file->panel()->url(true);

$file->delete();
Expand Down
2 changes: 1 addition & 1 deletion config/areas/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

return function ($kirby) {
return [
'icon' => 'user',
'icon' => 'logout',
'label' => I18n::translate('logout'),
'views' => [
'logout' => [
Expand Down
16 changes: 8 additions & 8 deletions config/areas/site/dialogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\PermissionException;
use Kirby\Panel\ChangesDialog;
use Kirby\Panel\Field;
use Kirby\Panel\PageCreateDialog;
use Kirby\Panel\Panel;
use Kirby\Panel\Ui\Dialogs\ChangesDialog;
use Kirby\Panel\Ui\Dialogs\PageCreateDialog;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
Expand Down Expand Up @@ -268,12 +267,13 @@
if ($page->slug() !== $slug) {
$response['event'][] = 'page.changeSlug';

$newPage = $page->changeSlug($slug);
$oldUrl = $page->panel()->url(true);
$newUrl = $newPage->panel()->url(true);
$newPage = $page->changeSlug($slug);
$oldUrl = $page->panel()->url(true);
$newUrl = $newPage->panel()->url(true);
$referrer = $page->kirby()->panel()->referrer();

// check for a necessary redirect after the slug has changed
if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) {
if ($referrer === $oldUrl && $oldUrl !== $newUrl) {
$response['redirect'] = $newUrl;
}
}
Expand Down Expand Up @@ -358,7 +358,7 @@

$page = Find::page($id);
$redirect = false;
$referrer = Panel::referrer();
$referrer = $page->kirby()->panel()->referrer();
$url = $page->panel()->url(true);

if (
Expand Down
7 changes: 3 additions & 4 deletions config/areas/users/dialogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Panel\Field;
use Kirby\Panel\Panel;
use Kirby\Panel\UserTotpDisableDialog;
use Kirby\Panel\Ui\Dialogs\UserTotpDisableDialog;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\I18n;

Expand Down Expand Up @@ -139,7 +138,7 @@
return [
'event' => 'user.changeLanguage',
'reload' => [
'globals' => '$translation'
'globals' => 'translation'
]
];
}
Expand Down Expand Up @@ -296,7 +295,7 @@
'submit' => function (string $id) {
$user = Find::user($id);
$redirect = false;
$referrer = Panel::referrer();
$referrer = $user->kirby()->panel()->referrer();
$url = $user->panel()->url(true);

$user->delete();
Expand Down
5 changes: 2 additions & 3 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use Kirby\Cms\App;
use Kirby\Cms\LanguageRoutes;
use Kirby\Cms\Media;
use Kirby\Panel\Panel;
use Kirby\Panel\Plugins;
use Kirby\Plugin\Assets;
use Kirby\Toolkit\Str;
Expand Down Expand Up @@ -125,8 +124,8 @@
'pattern' => $panel . '/(:all?)',
'method' => 'ALL',
'env' => 'panel',
'action' => function (string|null $path = null) {
return Panel::router($path);
'action' => function (string|null $path = null) use ($kirby) {
return $kirby->panel()->router($path);
}
],
// permalinks for page/file UUIDs
Expand Down
97 changes: 97 additions & 0 deletions panel/lab/components/menu/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<template>
<k-lab-examples>
<k-box theme="info">
Try these examples with the actual Panel menu collapsed as otherwise the
global open state will overwrite the local example state.
</k-box>

<k-lab-example label="Sections">
<k-panel-menu :items="items" />
</k-lab-example>
<k-lab-example label="Has search">
<k-panel-menu :items="items" :searches="searches" />
</k-lab-example>
<k-lab-example label="Open/Close (and hovered)">
<div class="k-panel" :data-menu="isOpen">
<k-panel-menu
:items="items"
:is-hovered="isHovered"
:is-open="isOpen"
@hover="isHovered = $event"
@toggle="isOpen = !isOpen"
/>
</div>
</k-lab-example>
<k-lab-example label="License: missing">
<k-panel-menu :items="items" license="missing" />
</k-lab-example>
<k-lab-example label="License: legacy">
<k-panel-menu :items="items" license="legacy" />
</k-lab-example>
</k-lab-examples>
</template>

<script>
export default {
data() {
return {
isHovered: false,
isOpen: true
};
},
computed: {
items() {
return [
{
component: "k-button",
key: "a",
props: { text: "Site", icon: "home", current: true }
},
{
component: "k-button",
key: "b",
props: { text: "Users", icon: "users" }
},
{
component: "k-button",
key: "c",
props: { text: "Settings", icon: "settings" }
},
"-",
{
component: "k-button",
key: "d",
props: { text: "Changes", icon: "edit-line" }
},
{
component: "k-button",
key: "e",
props: { text: "Account", icon: "account" }
},
{
component: "k-button",
key: "f",
props: { text: "Sign out", icon: "logout" }
}
];
},
searches() {
return {
shops: {}
};
}
}
};
</script>

<style>
.k-lab-example-canvas {
position: relative;
min-height: 20rem;
}

.k-lab-example-canvas .k-panel-menu {
position: absolute;
z-index: var(--z-content);
}
</style>
11 changes: 10 additions & 1 deletion panel/src/components/View/Inside.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<template>
<k-panel class="k-panel-inside">
<k-panel-menu />
<k-panel-menu
v-bind="$panel.menu.props"
:is-hovered="$panel.menu.isHovered"
:is-open="$panel.menu.isOpen"
:license="$panel.license"
:searches="$panel.searches"
@hover="$panel.menu.isHovered = $event"
@search="$panel.search()"
@toggle="$panel.menu.toggle()"
/>
<main class="k-panel-main">
<k-topbar :breadcrumb="$panel.view.breadcrumb" :view="$panel.view">
<!-- @slot Additional content for the Topbar -->
Expand Down
56 changes: 33 additions & 23 deletions panel/src/components/View/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<nav
class="k-panel-menu"
:aria-label="$t('menu')"
:data-hover="$panel.menu.hover"
@mouseenter="$panel.menu.hover = true"
@mouseleave="$panel.menu.hover = false"
:data-hover="isHovered"
@mouseenter="$emit('hover', true)"
@mouseleave="$emit('hover', false)"
>
<div class="k-panel-menu-body">
<!-- Search button -->
Expand All @@ -13,7 +13,7 @@
:text="$t('search')"
icon="search"
class="k-panel-menu-search k-panel-menu-button"
@click="$panel.search()"
@click="$emit('search')"
/>

<!-- Menus -->
Expand All @@ -23,13 +23,14 @@
:data-second-last="menuIndex === menus.length - 2"
class="k-panel-menu-buttons"
>
<k-button
v-for="entry in menu"
:key="entry.id"
v-bind="entry"
:title="entry.title ?? entry.text"
class="k-panel-menu-button"
/>
<template v-for="entry in menu">
<component
:is="entry.component"
:key="entry.key"
v-bind="entry.props"
class="k-panel-menu-button"
/>
</template>
</menu>

<menu v-if="activationButton">
Expand All @@ -40,17 +41,17 @@
theme="love"
variant="filled"
/>
<k-activation :status="$panel.license" />
<k-activation :status="license" />
</menu>
</div>

<!-- Collapse/expand toggle -->
<k-button
:icon="$panel.menu.isOpen ? 'angle-left' : 'angle-right'"
:title="$panel.menu.isOpen ? $t('collapse') : $t('expand')"
:icon="isOpen ? 'angle-left' : 'angle-right'"
:title="isOpen ? $t('collapse') : $t('expand')"
size="xs"
class="k-panel-menu-toggle"
@click="$panel.menu.toggle()"
@click="$emit('toggle')"
/>
</nav>
</template>
Expand All @@ -61,21 +62,30 @@
* @internal
*/
export default {
data() {
return {
over: false
};
props: {
isHovered: Boolean,
isOpen: Boolean,
items: {
type: Array,
default: () => []
},
license: String,
searches: {
type: Object,
default: () => ({})
}
},
emits: ["search", "toggle"],
computed: {
activationButton() {
if (this.$panel.license === "missing") {
if (this.license === "missing") {
return {
click: () => this.$dialog("registration"),
text: this.$t("activate")
};
}

if (this.$panel.license === "legacy") {
if (this.license === "legacy") {
return {
click: () => this.$dialog("license"),
text: this.$t("renew")
Expand All @@ -85,10 +95,10 @@ export default {
return false;
},
hasSearch() {
return this.$helper.object.length(this.$panel.searches) > 0;
return this.$helper.object.length(this.searches) > 0;
},
menus() {
return this.$helper.array.split(this.$panel.menu.entries, "-");
return this.$helper.array.split(this.items, "-");
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions panel/src/panel/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const defaults = () => {
* @since 4.0.0
*
* @param {Object} panel The panel singleton
* @param {String} key Sets the $key for the feature. Backend responses use this key for features.
* @param {String} key Sets the key for the feature. Backend responses use this key for features.
* @param {Object} defaults Sets the default state of the feature
*/
export default (panel, key, defaults) => {
Expand Down Expand Up @@ -185,7 +185,7 @@ export default (panel, key, defaults) => {
options.url = options.url ?? this.url();

const response = await panel.get(options.url, options);
const state = response["$" + this.key()];
const state = response[this.key()];

// the state cannot be updated
if (!state || state.component !== this.component) {
Expand Down
Loading