@mapomodule/uikit 2.0.0-beta.2 → 2.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -142
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoList.component.test.d.ts +2 -0
- package/dist/__tests__/MapoList.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaDrag.test.d.ts +2 -0
- package/dist/__tests__/mediaDrag.test.d.ts.map +1 -0
- package/dist/__tests__/mediaFolders.test.d.ts +2 -0
- package/dist/__tests__/mediaFolders.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/mediaMetadata.test.d.ts +2 -0
- package/dist/__tests__/mediaMetadata.test.d.ts.map +1 -0
- package/dist/__tests__/mediaStore.test.d.ts +2 -0
- package/dist/__tests__/mediaStore.test.d.ts.map +1 -0
- package/dist/__tests__/mediaUrl.test.d.ts +2 -0
- package/dist/__tests__/mediaUrl.test.d.ts.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/module.d.mts +48 -1
- package/dist/module.d.ts +44 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +71 -2
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts +15 -0
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
- package/dist/runtime/adapters/defaultMediaAdapter.js +35 -0
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +127 -55
- package/dist/runtime/components/MapoDetail.vue.d.ts +102 -5
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue +110 -0
- package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoList.vue +45 -31
- package/dist/runtime/components/MapoList.vue.d.ts +18 -5
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +27 -13
- package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
- package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListFilters.vue +4 -2
- package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +20 -10
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +125 -49
- package/dist/runtime/components/MapoListTable.vue.d.ts +13 -5
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogin.vue +13 -10
- package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogoutButton.vue +4 -2
- package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue +382 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +13 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue +129 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts +33 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolders.vue +402 -0
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaGallery.vue +304 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManager.vue +144 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts +44 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaPreview.vue +94 -0
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaUploader.vue +294 -0
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuManager.vue +301 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoSidebar.vue +3 -1
- package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSidebarList.vue +1 -1
- package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
- package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoThemeToggle.vue +5 -1
- package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
- package/dist/runtime/components/menuDndContext.d.ts +19 -0
- package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
- package/dist/runtime/components/menuDndContext.js +3 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/pages/index.vue +4 -3
- package/dist/runtime/pages/index.vue.d.ts.map +1 -1
- package/dist/runtime/pages/login.vue +0 -4
- package/dist/runtime/pages/login.vue.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.d.ts +18 -0
- package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
- package/dist/runtime/plugins/media-adapter.js +8 -0
- package/dist/runtime/stores/media.d.ts +505 -0
- package/dist/runtime/stores/media.d.ts.map +1 -0
- package/dist/runtime/stores/media.js +545 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/types/media.d.ts +131 -0
- package/dist/runtime/types/media.d.ts.map +1 -0
- package/dist/runtime/types/media.js +0 -0
- package/dist/runtime/types/menu.d.ts +66 -0
- package/dist/runtime/types/menu.d.ts.map +1 -0
- package/dist/runtime/types/menu.js +30 -0
- package/dist/runtime/utils/contentLanguages.d.ts +9 -0
- package/dist/runtime/utils/contentLanguages.d.ts.map +1 -0
- package/dist/runtime/utils/contentLanguages.js +8 -0
- package/dist/runtime/utils/langInfo.d.ts +43 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +17 -0
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts.map +1 -0
- package/dist/runtime/utils/mediaDrag.js +11 -0
- package/dist/runtime/utils/mediaFolders.d.ts +65 -0
- package/dist/runtime/utils/mediaFolders.d.ts.map +1 -0
- package/dist/runtime/utils/mediaFolders.js +97 -0
- package/dist/runtime/utils/mediaMetadata.d.ts +39 -0
- package/dist/runtime/utils/mediaMetadata.d.ts.map +1 -0
- package/dist/runtime/utils/mediaMetadata.js +97 -0
- package/dist/runtime/utils/mediaUrl.d.ts +16 -0
- package/dist/runtime/utils/mediaUrl.d.ts.map +1 -0
- package/dist/runtime/utils/mediaUrl.js +12 -0
- package/dist/types.d.mts +1 -1
- package/package.json +15 -11
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +393 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoList.component.test.ts +166 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +545 -0
- package/src/__tests__/MapoMediaEditor.component.test.ts +447 -0
- package/src/__tests__/MapoMediaFolderPicker.component.test.ts +220 -0
- package/src/__tests__/MapoMediaFolders.component.test.ts +519 -0
- package/src/__tests__/MapoMediaGallery.component.test.ts +211 -0
- package/src/__tests__/MapoMediaUploadHandover.component.test.ts +241 -0
- package/src/__tests__/MapoMenuManager.component.test.ts +175 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/langInfo.test.ts +85 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaDrag.test.ts +42 -0
- package/src/__tests__/mediaFolders.test.ts +204 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/mediaMetadata.test.ts +169 -0
- package/src/__tests__/mediaStore.test.ts +569 -0
- package/src/__tests__/mediaUrl.test.ts +44 -0
- package/src/index.ts +21 -0
- package/src/module.ts +155 -0
- package/src/runtime/adapters/defaultMediaAdapter.ts +67 -0
- package/src/runtime/assets/main.css +9 -0
- package/src/runtime/components/MapoConfirmDialog.vue +33 -4
- package/src/runtime/components/MapoDetail.vue +229 -73
- package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
- package/src/runtime/components/MapoDropArea.vue +145 -0
- package/src/runtime/components/MapoLangSwitcher.vue +74 -0
- package/src/runtime/components/MapoList.vue +65 -34
- package/src/runtime/components/MapoListActions.vue +32 -14
- package/src/runtime/components/MapoListFilters.vue +5 -2
- package/src/runtime/components/MapoListQuickEdit.vue +22 -10
- package/src/runtime/components/MapoListTable.vue +159 -59
- package/src/runtime/components/MapoLogin.vue +13 -10
- package/src/runtime/components/MapoLogoutButton.vue +4 -2
- package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
- package/src/runtime/components/MapoMediaEditor.vue +447 -0
- package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
- package/src/runtime/components/MapoMediaFolderPicker.vue +176 -0
- package/src/runtime/components/MapoMediaFolders.vue +478 -0
- package/src/runtime/components/MapoMediaGallery.vue +350 -0
- package/src/runtime/components/MapoMediaManager.vue +194 -0
- package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
- package/src/runtime/components/MapoMediaPreview.vue +116 -0
- package/src/runtime/components/MapoMediaUploader.vue +362 -0
- package/src/runtime/components/MapoMenuManager.vue +454 -0
- package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
- package/src/runtime/components/MapoMenuTreeview.vue +264 -0
- package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
- package/src/runtime/components/MapoSidebar.vue +3 -1
- package/src/runtime/components/MapoSidebarList.vue +1 -1
- package/src/runtime/components/MapoSidebarProfile.vue +6 -2
- package/src/runtime/components/MapoSnackBar.vue +12 -0
- package/src/runtime/components/MapoThemeToggle.vue +5 -1
- package/src/runtime/components/menuDndContext.ts +22 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/pages/index.vue +4 -3
- package/src/runtime/pages/login.vue +0 -4
- package/src/runtime/plugins/media-adapter.ts +33 -0
- package/src/runtime/stores/media.ts +820 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/types/media.ts +144 -0
- package/src/runtime/types/menu.ts +105 -0
- package/src/runtime/utils/contentLanguages.ts +18 -0
- package/src/runtime/utils/langInfo.ts +63 -0
- package/src/runtime/utils/listTable.ts +54 -0
- package/src/runtime/utils/mediaDrag.ts +29 -0
- package/src/runtime/utils/mediaFolders.ts +182 -0
- package/src/runtime/utils/mediaMetadata.ts +165 -0
- package/src/runtime/utils/mediaUrl.ts +30 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, watch, onMounted } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
5
|
+
import {
|
|
6
|
+
getErrorData,
|
|
7
|
+
getErrorDetail,
|
|
8
|
+
getErrorStatus,
|
|
9
|
+
} from "@mapomodule/core/runtime/utils/fetchError";
|
|
10
|
+
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
11
|
+
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
12
|
+
import { languagesFromMetadata, restrictLanguages } from "../utils/langInfo";
|
|
13
|
+
import { useContentLanguages } from "../utils/contentLanguages";
|
|
14
|
+
import { deepClone, objectDiff } from "@mapomodule/utils";
|
|
15
|
+
import type { AnyFieldDescriptor } from "@mapomodule/form/types";
|
|
16
|
+
import {
|
|
17
|
+
findMenuNode,
|
|
18
|
+
type MapoMenu,
|
|
19
|
+
type MenuTreeNode,
|
|
20
|
+
} from "../types/menu.js";
|
|
21
|
+
import MapoMenuTreeview from "./MapoMenuTreeview.vue";
|
|
22
|
+
import MapoMenuNodeEditor from "./MapoMenuNodeEditor.vue";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Menu Manager shell — split-pane editor for hierarchical navigation menus.
|
|
26
|
+
*
|
|
27
|
+
* Left: drag & drop node tree (`MapoMenuTreeview`).
|
|
28
|
+
* Right: form editor for the selected node (`MapoMenuNodeEditor`).
|
|
29
|
+
*
|
|
30
|
+
* Loads the menu from `endpoint`/`identifier` on mount (v1 parity), keeps
|
|
31
|
+
* per-language node trees when `translatable`, and saves the whole structure
|
|
32
|
+
* with `create`/`update`/`partialUpdate` depending on state and `usePatch`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* <MapoMenuManager
|
|
36
|
+
* endpoint="/api/menus"
|
|
37
|
+
* :identifier="route.params.id"
|
|
38
|
+
* :languages="['it', 'en']"
|
|
39
|
+
* :max-depth="5"
|
|
40
|
+
* />
|
|
41
|
+
*/
|
|
42
|
+
const props = withDefaults(
|
|
43
|
+
defineProps<{
|
|
44
|
+
/** Menu CRUD endpoint (e.g. `/api/menus`). */
|
|
45
|
+
endpoint: string;
|
|
46
|
+
/** Menu id to load, or `"new"` to start from an empty menu. */
|
|
47
|
+
identifier?: string | number;
|
|
48
|
+
/** Menu payload (v-model). Used as the initial model when `identifier` is `"new"`. */
|
|
49
|
+
modelValue?: MapoMenu | null;
|
|
50
|
+
/** Manage one node tree per language under `translations`. */
|
|
51
|
+
translatable?: boolean;
|
|
52
|
+
/** Active editing language (v-model:lang). Defaults to the first of `languages`. */
|
|
53
|
+
lang?: string;
|
|
54
|
+
/** Translation language codes (e.g. `['it', 'en']`). */
|
|
55
|
+
languages?: string[];
|
|
56
|
+
/** Save with `partialUpdate` sending only the changed keys. */
|
|
57
|
+
usePatch?: boolean;
|
|
58
|
+
/** Max nesting depth; `-1` = unlimited. */
|
|
59
|
+
maxDepth?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Django model used for permission gating (`add_<model>` / `change_<model>`).
|
|
62
|
+
* When the user lacks the permission the manager renders read-only.
|
|
63
|
+
*/
|
|
64
|
+
permissionModel?: string;
|
|
65
|
+
/** Force read-only mode. */
|
|
66
|
+
readonly?: boolean;
|
|
67
|
+
/** Replaces the node editor's default core fields. */
|
|
68
|
+
coreFields?: AnyFieldDescriptor[] | null;
|
|
69
|
+
/** Extra node editor fields appended after the core ones. */
|
|
70
|
+
additionalFields?: AnyFieldDescriptor[];
|
|
71
|
+
/** CSS classes offered by the node `style` select, as `{ label: cssClass }`. */
|
|
72
|
+
availableClasses?: Record<string, string>;
|
|
73
|
+
}>(),
|
|
74
|
+
{
|
|
75
|
+
identifier: "new",
|
|
76
|
+
modelValue: null,
|
|
77
|
+
translatable: true,
|
|
78
|
+
lang: undefined,
|
|
79
|
+
languages: () => [],
|
|
80
|
+
usePatch: false,
|
|
81
|
+
maxDepth: -1,
|
|
82
|
+
permissionModel: undefined,
|
|
83
|
+
readonly: false,
|
|
84
|
+
coreFields: null,
|
|
85
|
+
additionalFields: () => [],
|
|
86
|
+
availableClasses: () => ({}),
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const emit = defineEmits<{
|
|
91
|
+
"update:modelValue": [menu: MapoMenu];
|
|
92
|
+
"update:lang": [lang: string];
|
|
93
|
+
/** Emitted after a successful save with the server response. */
|
|
94
|
+
saved: [menu: MapoMenu];
|
|
95
|
+
}>();
|
|
96
|
+
|
|
97
|
+
defineSlots<{
|
|
98
|
+
/** Rendered when no node is selected (right pane placeholder). */
|
|
99
|
+
empty(): unknown;
|
|
100
|
+
/** Content above the node editor form. */
|
|
101
|
+
"editor-form-top"(props: Record<string, unknown>): unknown;
|
|
102
|
+
/** Replaces the node editor form. */
|
|
103
|
+
"editor-form"(props: Record<string, unknown>): unknown;
|
|
104
|
+
/** Content below the node editor form. */
|
|
105
|
+
"editor-form-bottom"(props: Record<string, unknown>): unknown;
|
|
106
|
+
}>();
|
|
107
|
+
|
|
108
|
+
const { t } = useI18n();
|
|
109
|
+
const snack = useSnackStore();
|
|
110
|
+
const crud = useCrud<MapoMenu>(props.endpoint);
|
|
111
|
+
|
|
112
|
+
// ─── State ────────────────────────────────────────────────────────────────────
|
|
113
|
+
|
|
114
|
+
const model = ref<MapoMenu>(
|
|
115
|
+
props.modelValue ?? { key: "", nodes: [], translations: {} },
|
|
116
|
+
);
|
|
117
|
+
let backup: MapoMenu = deepClone(model.value);
|
|
118
|
+
|
|
119
|
+
const selected = ref<MenuTreeNode | null>(null);
|
|
120
|
+
// ─── Languages (auto-derive from lang_info) ──────────────────────────────────
|
|
121
|
+
// Camomilla describes the model's language situation in the endpoint's OPTIONS
|
|
122
|
+
// metadata; reading it means a host page no longer hardcodes a list, and a menu
|
|
123
|
+
// model that is not registered for translation shows no switcher instead of tabs
|
|
124
|
+
// the backend would drop. props.languages still wins when a page insists; the
|
|
125
|
+
// app's `mapo.uikit.contentLanguages` narrows either list.
|
|
126
|
+
const derivedLangs = ref<string[]>([]);
|
|
127
|
+
const contentLanguages = useContentLanguages();
|
|
128
|
+
const activeLangs = computed<string[]>(() =>
|
|
129
|
+
restrictLanguages(
|
|
130
|
+
props.languages.length ? props.languages : derivedLangs.value,
|
|
131
|
+
contentLanguages,
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// The page's `lang` when it passes one; otherwise the `activeLangs` watcher
|
|
136
|
+
// below sets the first language actually offered (`languages[0]` can be one
|
|
137
|
+
// `mapo.uikit.contentLanguages` hides or puts later).
|
|
138
|
+
const currentLang = ref(props.lang ?? "");
|
|
139
|
+
const isLoading = ref(String(props.identifier) !== "new");
|
|
140
|
+
const isSaving = ref(false);
|
|
141
|
+
|
|
142
|
+
const isNew = computed(() => String(props.identifier) === "new");
|
|
143
|
+
const translationsActive = computed(
|
|
144
|
+
() => props.translatable && activeLangs.value.length > 0,
|
|
145
|
+
);
|
|
146
|
+
// The switch only picks between languages: with a single one it stays hidden,
|
|
147
|
+
// as in MapoDetail, while the tree still lives under that language's
|
|
148
|
+
// `translations` entry (`translationsActive` decides where the nodes are).
|
|
149
|
+
const hasSeveralLanguages = computed(() => activeLangs.value.length > 1);
|
|
150
|
+
|
|
151
|
+
// ─── Permissions ─────────────────────────────────────────────────────────────
|
|
152
|
+
|
|
153
|
+
const { canAdd, canChange } = usePermissions();
|
|
154
|
+
const effectiveReadonly = computed(() => {
|
|
155
|
+
if (props.readonly) return true;
|
|
156
|
+
if (!props.permissionModel) return false;
|
|
157
|
+
return isNew.value
|
|
158
|
+
? !canAdd(props.permissionModel)
|
|
159
|
+
: !canChange(props.permissionModel);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// ─── Language handling ───────────────────────────────────────────────────────
|
|
163
|
+
|
|
164
|
+
// Derivation resolves after mount, so the initial currentLang is "" whenever the
|
|
165
|
+
// list is not hardcoded. Adopt the first language as soon as one is known, and
|
|
166
|
+
// move there when the current one is not offered: the first of `languages`, or
|
|
167
|
+
// the `lang` the page passed, can be one the app hides.
|
|
168
|
+
watch(
|
|
169
|
+
activeLangs,
|
|
170
|
+
(langs) => {
|
|
171
|
+
const isOffered = langs.includes(currentLang.value);
|
|
172
|
+
if (isOffered || !langs.length) return;
|
|
173
|
+
currentLang.value = langs[0]!;
|
|
174
|
+
},
|
|
175
|
+
{ immediate: true },
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
watch(
|
|
179
|
+
() => props.lang,
|
|
180
|
+
(val) => {
|
|
181
|
+
if (val && activeLangs.value.includes(val)) currentLang.value = val;
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
watch(currentLang, (val) => {
|
|
186
|
+
// Nodes are per-language: the old selection does not exist in the new tree.
|
|
187
|
+
selected.value = null;
|
|
188
|
+
emit("update:lang", val);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// ─── Active node tree (translations-aware) ───────────────────────────────────
|
|
192
|
+
// The container the active tree lives in is created eagerly by a watcher rather
|
|
193
|
+
// than lazily inside the `nodes` computed: the tree is mutated in place by the
|
|
194
|
+
// drag & drop lists, so it must be a stable reactive array, and a computed that
|
|
195
|
+
// writes to the model on read would be a side effect.
|
|
196
|
+
|
|
197
|
+
function ensureTree() {
|
|
198
|
+
if (translationsActive.value) {
|
|
199
|
+
model.value.translations ??= {};
|
|
200
|
+
const lang = currentLang.value;
|
|
201
|
+
model.value.translations[lang] ??= { nodes: [] };
|
|
202
|
+
model.value.translations[lang].nodes ??= [];
|
|
203
|
+
} else {
|
|
204
|
+
model.value.nodes ??= [];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
watch([model, currentLang, translationsActive], ensureTree, {
|
|
209
|
+
immediate: true,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const nodes = computed<MenuTreeNode[]>(() => {
|
|
213
|
+
if (translationsActive.value) {
|
|
214
|
+
return model.value.translations?.[currentLang.value]?.nodes ?? [];
|
|
215
|
+
}
|
|
216
|
+
return model.value.nodes ?? [];
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// ─── Load ────────────────────────────────────────────────────────────────────
|
|
220
|
+
|
|
221
|
+
watch(
|
|
222
|
+
() => props.modelValue,
|
|
223
|
+
(val) => {
|
|
224
|
+
if (val) model.value = val;
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
watch(model, (val) => emit("update:modelValue", val));
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Ask the endpoint to describe itself. `lang_info` lives on OPTIONS only, so
|
|
232
|
+
* this runs for an existing menu as well as a brand new one.
|
|
233
|
+
*/
|
|
234
|
+
async function deriveLanguages() {
|
|
235
|
+
if (props.languages.length) return;
|
|
236
|
+
try {
|
|
237
|
+
derivedLangs.value = languagesFromMetadata(await crud.options());
|
|
238
|
+
} catch {
|
|
239
|
+
// Backend without OPTIONS metadata: just no auto-derived languages.
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
onMounted(async () => {
|
|
244
|
+
deriveLanguages();
|
|
245
|
+
if (isNew.value) return;
|
|
246
|
+
isLoading.value = true;
|
|
247
|
+
try {
|
|
248
|
+
model.value = await crud.detail(props.identifier);
|
|
249
|
+
backup = deepClone(model.value);
|
|
250
|
+
} catch (err: unknown) {
|
|
251
|
+
snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
|
|
252
|
+
} finally {
|
|
253
|
+
isLoading.value = false;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// ─── Save ────────────────────────────────────────────────────────────────────
|
|
258
|
+
|
|
259
|
+
async function save() {
|
|
260
|
+
if (effectiveReadonly.value) return;
|
|
261
|
+
clearErrors();
|
|
262
|
+
isSaving.value = true;
|
|
263
|
+
try {
|
|
264
|
+
let response: MapoMenu;
|
|
265
|
+
if (!model.value.id) {
|
|
266
|
+
response = await crud.create(model.value);
|
|
267
|
+
} else if (props.usePatch) {
|
|
268
|
+
const diff = objectDiff(backup, model.value) as Partial<MapoMenu>;
|
|
269
|
+
response = await crud.partialUpdate(model.value.id, diff);
|
|
270
|
+
} else {
|
|
271
|
+
response = await crud.update(model.value.id, model.value);
|
|
272
|
+
}
|
|
273
|
+
model.value = response;
|
|
274
|
+
backup = deepClone(response);
|
|
275
|
+
selected.value = null;
|
|
276
|
+
snack.show(
|
|
277
|
+
isNew.value ? t("mapo.createSuccess") : t("mapo.saveSuccess"),
|
|
278
|
+
"success",
|
|
279
|
+
);
|
|
280
|
+
emit("saved", response);
|
|
281
|
+
} catch (err: unknown) {
|
|
282
|
+
const data = getErrorData(err);
|
|
283
|
+
if (getErrorStatus(err) === 400 && data) parseErrors(data);
|
|
284
|
+
snack.show(getErrorDetail(err) ?? t("mapo.genericError"), "error");
|
|
285
|
+
} finally {
|
|
286
|
+
isSaving.value = false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ─── Backend error mapping ───────────────────────────────────────────────────
|
|
291
|
+
// DRF mirrors the payload shape: errors for nested nodes arrive at the same
|
|
292
|
+
// position in a nested `nodes` array. Walk both trees in parallel and attach
|
|
293
|
+
// the node-level errors; select the first errored node in the active tree.
|
|
294
|
+
|
|
295
|
+
function clearErrors() {
|
|
296
|
+
const walk = (list: MenuTreeNode[]) => {
|
|
297
|
+
for (const node of list) {
|
|
298
|
+
if (node.errors) delete node.errors;
|
|
299
|
+
walk(node.nodes ?? []);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
if (model.value.nodes) walk(model.value.nodes);
|
|
303
|
+
for (const tr of Object.values(model.value.translations ?? {})) {
|
|
304
|
+
walk(tr.nodes ?? []);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function parseErrors(data: Record<string, unknown>) {
|
|
309
|
+
const attach = (
|
|
310
|
+
list: MenuTreeNode[],
|
|
311
|
+
errors: unknown[],
|
|
312
|
+
inActiveTree: boolean,
|
|
313
|
+
) => {
|
|
314
|
+
errors.forEach((err, i) => {
|
|
315
|
+
const node = list[i];
|
|
316
|
+
if (!node || !err || typeof err !== "object") return;
|
|
317
|
+
const { nodes: childErrors, ...nodeErrors } = err as Record<
|
|
318
|
+
string,
|
|
319
|
+
unknown
|
|
320
|
+
>;
|
|
321
|
+
if (Object.keys(nodeErrors).length > 0) {
|
|
322
|
+
node.errors = nodeErrors as Record<string, string[]>;
|
|
323
|
+
if (inActiveTree && !selected.value) selected.value = node;
|
|
324
|
+
}
|
|
325
|
+
if (Array.isArray(childErrors)) {
|
|
326
|
+
attach(node.nodes ?? [], childErrors, inActiveTree);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
if (translationsActive.value) {
|
|
332
|
+
const translations = data.translations as
|
|
333
|
+
| Record<string, { nodes?: unknown[] }>
|
|
334
|
+
| undefined;
|
|
335
|
+
for (const [lang, trErrors] of Object.entries(translations ?? {})) {
|
|
336
|
+
const tree = model.value.translations?.[lang]?.nodes ?? [];
|
|
337
|
+
if (Array.isArray(trErrors?.nodes)) {
|
|
338
|
+
attach(tree, trErrors.nodes, lang === currentLang.value);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
} else if (Array.isArray(data.nodes)) {
|
|
342
|
+
attach(model.value.nodes ?? [], data.nodes, true);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ─── Editor errors for the lang switch ───────────────────────────────────────
|
|
347
|
+
// MapoDetailLangSwitch highlights languages whose keys start with
|
|
348
|
+
// `translations.<lang>.` — build that map from the per-node errors.
|
|
349
|
+
|
|
350
|
+
const langErrors = computed<Record<string, string[]>>(() => {
|
|
351
|
+
const map: Record<string, string[]> = {};
|
|
352
|
+
const hasErrors = (list: MenuTreeNode[]): boolean =>
|
|
353
|
+
list.some(
|
|
354
|
+
(n) =>
|
|
355
|
+
(n.errors && Object.keys(n.errors).length > 0) ||
|
|
356
|
+
hasErrors(n.nodes ?? []),
|
|
357
|
+
);
|
|
358
|
+
for (const [lang, tr] of Object.entries(model.value.translations ?? {})) {
|
|
359
|
+
if (hasErrors(tr.nodes ?? [])) {
|
|
360
|
+
map[`translations.${lang}.nodes`] = [t("mapo.fixErrors")];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return map;
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const treeview = ref<InstanceType<typeof MapoMenuTreeview> | null>(null);
|
|
367
|
+
</script>
|
|
368
|
+
|
|
369
|
+
<template>
|
|
370
|
+
<div class="mapo-menu-manager flex h-full min-h-0 overflow-hidden">
|
|
371
|
+
<!-- Left pane: tree -->
|
|
372
|
+
<div class="flex w-72 shrink-0 flex-col border-r border-default bg-default">
|
|
373
|
+
<MapoMenuTreeview
|
|
374
|
+
ref="treeview"
|
|
375
|
+
v-model="selected"
|
|
376
|
+
:nodes="nodes"
|
|
377
|
+
:title="`${t('mapo.menuManager.menu')}: ${model.key || '—'}`"
|
|
378
|
+
:max-depth="maxDepth"
|
|
379
|
+
:readonly="effectiveReadonly"
|
|
380
|
+
:loading="isLoading"
|
|
381
|
+
>
|
|
382
|
+
<template v-if="translationsActive && hasSeveralLanguages" #top>
|
|
383
|
+
<div class="border-b border-default px-2 pt-2">
|
|
384
|
+
<MapoDetailLangSwitch
|
|
385
|
+
v-model="currentLang"
|
|
386
|
+
:langs="activeLangs"
|
|
387
|
+
:errors="langErrors"
|
|
388
|
+
no-route-change
|
|
389
|
+
/>
|
|
390
|
+
</div>
|
|
391
|
+
</template>
|
|
392
|
+
<template #bottom>
|
|
393
|
+
<div class="border-t border-default p-2">
|
|
394
|
+
<UButton
|
|
395
|
+
v-if="!effectiveReadonly"
|
|
396
|
+
block
|
|
397
|
+
icon="i-lucide-save"
|
|
398
|
+
:loading="isSaving"
|
|
399
|
+
@click="save"
|
|
400
|
+
>
|
|
401
|
+
{{ t("mapo.save") }}
|
|
402
|
+
</UButton>
|
|
403
|
+
</div>
|
|
404
|
+
</template>
|
|
405
|
+
</MapoMenuTreeview>
|
|
406
|
+
</div>
|
|
407
|
+
|
|
408
|
+
<!-- Right pane -->
|
|
409
|
+
<div v-if="isLoading" class="flex flex-1 items-center justify-center">
|
|
410
|
+
<UIcon
|
|
411
|
+
name="i-lucide-loader-circle"
|
|
412
|
+
class="size-8 animate-spin text-muted"
|
|
413
|
+
/>
|
|
414
|
+
</div>
|
|
415
|
+
|
|
416
|
+
<MapoMenuNodeEditor
|
|
417
|
+
v-else-if="selected"
|
|
418
|
+
:model-value="selected"
|
|
419
|
+
:nodes="nodes"
|
|
420
|
+
:menu-endpoint="endpoint"
|
|
421
|
+
:core-fields="coreFields"
|
|
422
|
+
:additional-fields="additionalFields"
|
|
423
|
+
:available-classes="availableClasses"
|
|
424
|
+
:readonly="effectiveReadonly"
|
|
425
|
+
@update:model-value="
|
|
426
|
+
selected = findMenuNode(nodes, $event.id)?.node ?? $event
|
|
427
|
+
"
|
|
428
|
+
@delete="treeview?.deleteSelectedNode()"
|
|
429
|
+
>
|
|
430
|
+
<template #form-top="slotProps">
|
|
431
|
+
<slot name="editor-form-top" v-bind="slotProps" />
|
|
432
|
+
</template>
|
|
433
|
+
<template v-if="$slots['editor-form']" #form="slotProps">
|
|
434
|
+
<slot name="editor-form" v-bind="slotProps" />
|
|
435
|
+
</template>
|
|
436
|
+
<template #form-bottom="slotProps">
|
|
437
|
+
<slot name="editor-form-bottom" v-bind="slotProps" />
|
|
438
|
+
</template>
|
|
439
|
+
</MapoMenuNodeEditor>
|
|
440
|
+
|
|
441
|
+
<!-- Empty state -->
|
|
442
|
+
<div
|
|
443
|
+
v-else
|
|
444
|
+
class="flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center"
|
|
445
|
+
>
|
|
446
|
+
<slot name="empty">
|
|
447
|
+
<UIcon name="i-lucide-network" class="size-12 text-dimmed" />
|
|
448
|
+
<p class="max-w-xs text-sm text-muted">
|
|
449
|
+
{{ t("mapo.menuManager.noSelectedNode") }}
|
|
450
|
+
</p>
|
|
451
|
+
</slot>
|
|
452
|
+
</div>
|
|
453
|
+
</div>
|
|
454
|
+
</template>
|