@mapomodule/uikit 2.0.0-beta.7 → 2.0.0-experimental.1

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.
Files changed (199) hide show
  1. package/README.md +47 -174
  2. package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
  3. package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
  4. package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
  5. package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
  6. package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
  7. package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
  8. package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
  9. package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
  10. package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
  11. package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
  12. package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
  13. package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
  14. package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
  15. package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
  16. package/dist/__tests__/formValues.test.d.ts +2 -0
  17. package/dist/__tests__/formValues.test.d.ts.map +1 -0
  18. package/dist/__tests__/langInfo.test.d.ts +2 -0
  19. package/dist/__tests__/langInfo.test.d.ts.map +1 -0
  20. package/dist/__tests__/listTable.test.d.ts +2 -0
  21. package/dist/__tests__/listTable.test.d.ts.map +1 -0
  22. package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
  23. package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
  24. package/dist/__tests__/runtimePages.test.d.ts +2 -0
  25. package/dist/__tests__/runtimePages.test.d.ts.map +1 -0
  26. package/dist/index.d.mts +2 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.mjs +1 -1
  30. package/dist/module.d.mts +2 -0
  31. package/dist/module.d.ts.map +1 -1
  32. package/dist/module.json +1 -1
  33. package/dist/module.mjs +23 -2
  34. package/dist/runtime/assets/main.css +1 -1
  35. package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
  36. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
  37. package/dist/runtime/components/MapoDetail.vue +301 -63
  38. package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
  39. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
  40. package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
  41. package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
  42. package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
  43. package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
  44. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
  45. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
  46. package/dist/runtime/components/MapoDropArea.vue +5 -1
  47. package/dist/runtime/components/MapoDropArea.vue.d.ts +1 -1
  48. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
  49. package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
  50. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
  51. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
  52. package/dist/runtime/components/MapoList.vue +7 -3
  53. package/dist/runtime/components/MapoList.vue.d.ts +14 -4
  54. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
  55. package/dist/runtime/components/MapoListActions.vue +27 -13
  56. package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
  57. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
  58. package/dist/runtime/components/MapoListFilters.vue +4 -2
  59. package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
  60. package/dist/runtime/components/MapoListQuickEdit.vue +12 -8
  61. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
  62. package/dist/runtime/components/MapoListTable.vue +116 -45
  63. package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
  64. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
  65. package/dist/runtime/components/MapoLogin.vue +13 -10
  66. package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
  67. package/dist/runtime/components/MapoLogoutButton.vue +4 -2
  68. package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
  69. package/dist/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
  70. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -1
  71. package/dist/runtime/components/MapoMediaEditor.vue +36 -20
  72. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
  73. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
  74. package/dist/runtime/components/MapoMediaFileChanger.vue +7 -3
  75. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -1
  76. package/dist/runtime/components/MapoMediaFolders.vue +36 -14
  77. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -1
  78. package/dist/runtime/components/MapoMediaGallery.vue +15 -5
  79. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -1
  80. package/dist/runtime/components/MapoMediaManager.vue +17 -7
  81. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -1
  82. package/dist/runtime/components/MapoMediaManagerDialog.vue +8 -4
  83. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -1
  84. package/dist/runtime/components/MapoMediaUploader.vue +53 -29
  85. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
  86. package/dist/runtime/components/MapoMenuManager.vue +293 -0
  87. package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
  88. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
  89. package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
  90. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
  91. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
  92. package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
  93. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
  94. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
  95. package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
  96. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
  97. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
  98. package/dist/runtime/components/MapoSidebar.vue +3 -1
  99. package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
  100. package/dist/runtime/components/MapoSidebarList.vue +1 -1
  101. package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
  102. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
  103. package/dist/runtime/components/MapoSnackBar.vue +11 -0
  104. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
  105. package/dist/runtime/components/MapoThemeToggle.vue +5 -1
  106. package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
  107. package/dist/runtime/components/menuDndContext.d.ts +19 -0
  108. package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
  109. package/dist/runtime/components/menuDndContext.js +3 -0
  110. package/dist/runtime/composables/defineDetailExtension.d.ts +32 -0
  111. package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
  112. package/dist/runtime/composables/defineDetailExtension.js +34 -0
  113. package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
  114. package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
  115. package/dist/runtime/composables/useMapoDetail.js +5 -0
  116. package/dist/runtime/page-meta.nuxt.d.ts +4 -0
  117. package/dist/runtime/pages/index.vue +4 -2
  118. package/dist/runtime/pages/index.vue.d.ts.map +1 -1
  119. package/dist/runtime/plugins/media-adapter.d.ts.map +1 -1
  120. package/dist/runtime/plugins/media-adapter.js +2 -1
  121. package/dist/runtime/stores/media.d.ts +8 -2
  122. package/dist/runtime/stores/media.d.ts.map +1 -1
  123. package/dist/runtime/stores/media.js +45 -13
  124. package/dist/runtime/types/detail.d.ts +167 -0
  125. package/dist/runtime/types/detail.d.ts.map +1 -0
  126. package/dist/runtime/types/detail.js +0 -0
  127. package/dist/runtime/types/list.d.ts +10 -2
  128. package/dist/runtime/types/list.d.ts.map +1 -1
  129. package/dist/runtime/types/menu.d.ts +66 -0
  130. package/dist/runtime/types/menu.d.ts.map +1 -0
  131. package/dist/runtime/types/menu.js +30 -0
  132. package/dist/runtime/utils/formValues.d.ts +8 -0
  133. package/dist/runtime/utils/formValues.d.ts.map +1 -0
  134. package/dist/runtime/utils/formValues.js +19 -0
  135. package/dist/runtime/utils/langInfo.d.ts +30 -0
  136. package/dist/runtime/utils/langInfo.d.ts.map +1 -0
  137. package/dist/runtime/utils/langInfo.js +8 -0
  138. package/dist/runtime/utils/listTable.d.ts +29 -0
  139. package/dist/runtime/utils/listTable.d.ts.map +1 -0
  140. package/dist/runtime/utils/listTable.js +21 -0
  141. package/package.json +12 -10
  142. package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
  143. package/src/__tests__/MapoDetail.component.test.ts +1107 -0
  144. package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
  145. package/src/__tests__/MapoListActions.component.test.ts +175 -0
  146. package/src/__tests__/MapoListTable.component.test.ts +504 -0
  147. package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
  148. package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
  149. package/src/__tests__/formValues.test.ts +31 -0
  150. package/src/__tests__/langInfo.test.ts +48 -0
  151. package/src/__tests__/listTable.test.ts +82 -0
  152. package/src/__tests__/mediaLanguages.test.ts +66 -0
  153. package/src/__tests__/runtimePages.test.ts +17 -0
  154. package/src/index.ts +20 -0
  155. package/src/module.ts +29 -0
  156. package/src/runtime/assets/main.css +13 -0
  157. package/src/runtime/components/MapoConfirmDialog.vue +33 -4
  158. package/src/runtime/components/MapoDetail.vue +520 -89
  159. package/src/runtime/components/MapoDetailExtensions.vue +39 -0
  160. package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
  161. package/src/runtime/components/MapoDropArea.vue +6 -1
  162. package/src/runtime/components/MapoLangSwitcher.vue +74 -0
  163. package/src/runtime/components/MapoList.vue +21 -6
  164. package/src/runtime/components/MapoListActions.vue +32 -14
  165. package/src/runtime/components/MapoListFilters.vue +5 -2
  166. package/src/runtime/components/MapoListQuickEdit.vue +12 -9
  167. package/src/runtime/components/MapoListTable.vue +147 -55
  168. package/src/runtime/components/MapoLogin.vue +13 -10
  169. package/src/runtime/components/MapoLogoutButton.vue +4 -2
  170. package/src/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
  171. package/src/runtime/components/MapoMediaEditor.vue +43 -20
  172. package/src/runtime/components/MapoMediaFileChanger.vue +8 -3
  173. package/src/runtime/components/MapoMediaFolders.vue +37 -15
  174. package/src/runtime/components/MapoMediaGallery.vue +17 -5
  175. package/src/runtime/components/MapoMediaManager.vue +17 -7
  176. package/src/runtime/components/MapoMediaManagerDialog.vue +10 -4
  177. package/src/runtime/components/MapoMediaUploader.vue +60 -29
  178. package/src/runtime/components/MapoMenuManager.vue +437 -0
  179. package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
  180. package/src/runtime/components/MapoMenuTreeview.vue +264 -0
  181. package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
  182. package/src/runtime/components/MapoSidebar.vue +3 -1
  183. package/src/runtime/components/MapoSidebarList.vue +1 -1
  184. package/src/runtime/components/MapoSidebarProfile.vue +6 -2
  185. package/src/runtime/components/MapoSnackBar.vue +12 -0
  186. package/src/runtime/components/MapoThemeToggle.vue +5 -1
  187. package/src/runtime/components/menuDndContext.ts +22 -0
  188. package/src/runtime/composables/defineDetailExtension.ts +78 -0
  189. package/src/runtime/composables/useMapoDetail.ts +24 -0
  190. package/src/runtime/page-meta.nuxt.d.ts +4 -0
  191. package/src/runtime/pages/index.vue +5 -2
  192. package/src/runtime/plugins/media-adapter.ts +9 -5
  193. package/src/runtime/stores/media.ts +61 -13
  194. package/src/runtime/types/detail.ts +178 -0
  195. package/src/runtime/types/list.ts +10 -2
  196. package/src/runtime/types/menu.ts +105 -0
  197. package/src/runtime/utils/formValues.ts +28 -0
  198. package/src/runtime/utils/langInfo.ts +38 -0
  199. package/src/runtime/utils/listTable.ts +54 -0
@@ -0,0 +1,282 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed, watch, resolveComponent } from "vue";
3
+ import { useI18n } from "vue-i18n";
4
+ import { useCrud } from "@mapomodule/core/runtime/api/crud";
5
+ import type { AnyFieldDescriptor } from "@mapomodule/form/types";
6
+ import { findMenuNode, type MenuTreeNode } from "../types/menu.js";
7
+
8
+ /**
9
+ * Right pane of `MapoMenuManager`: edits the selected node with a `MapoForm`.
10
+ *
11
+ * The default field set matches v1/Camomilla (title, link type, style,
12
+ * new-tab flag, relational page picker, static URL). Consumers can replace it
13
+ * entirely (`core-fields`) or append their own (`additional-fields`).
14
+ */
15
+ const props = withDefaults(
16
+ defineProps<{
17
+ /** Selected node (v-model). Mutated in place — the tree owns the data. */
18
+ modelValue: MenuTreeNode;
19
+ /** Full node tree, used to compute the breadcrumb trail. */
20
+ nodes?: MenuTreeNode[];
21
+ /** Menu CRUD endpoint; `<endpoint>/page_types` feeds the relational picker. */
22
+ menuEndpoint?: string;
23
+ /** Replaces the default core field set entirely. */
24
+ coreFields?: AnyFieldDescriptor[] | null;
25
+ /** Extra fields appended after the core ones. */
26
+ additionalFields?: AnyFieldDescriptor[];
27
+ /** CSS classes offered by the `style` select, as `{ label: cssClass }`. */
28
+ availableClasses?: Record<string, string>;
29
+ readonly?: boolean;
30
+ }>(),
31
+ {
32
+ nodes: () => [],
33
+ menuEndpoint: "",
34
+ coreFields: null,
35
+ additionalFields: () => [],
36
+ availableClasses: () => ({}),
37
+ readonly: false,
38
+ },
39
+ );
40
+
41
+ const emit = defineEmits<{
42
+ "update:modelValue": [node: MenuTreeNode];
43
+ /** Delete-node button pressed. */
44
+ delete: [];
45
+ }>();
46
+
47
+ defineSlots<{
48
+ /** Content above the form. Receives the slot bindings. */
49
+ "form-top"(props: SlotBindings): unknown;
50
+ /** Replaces the whole form. Receives the slot bindings. */
51
+ form(props: SlotBindings): unknown;
52
+ /** Content below the form. Receives the slot bindings. */
53
+ "form-bottom"(props: SlotBindings): unknown;
54
+ }>();
55
+
56
+ interface SlotBindings {
57
+ model: MenuTreeNode;
58
+ fields: AnyFieldDescriptor[];
59
+ errors: Record<string, string[]>;
60
+ readonly: boolean;
61
+ }
62
+
63
+ const { t } = useI18n();
64
+
65
+ // ─── Relational page picker ──────────────────────────────────────────────────
66
+ // `<menuEndpoint>/page_types` lists the content types; its detail returns the
67
+ // routable pages of that type (Camomilla contract, v1 parity).
68
+
69
+ const pageTypesEndpoint = computed(
70
+ () => `${props.menuEndpoint.replace(/\/$/, "")}/page_types`,
71
+ );
72
+
73
+ interface AvailablePage {
74
+ name: string;
75
+ url_node_id: number | string;
76
+ }
77
+
78
+ const availablePages = ref<AvailablePage[]>([]);
79
+
80
+ async function loadPages() {
81
+ const contentType = props.modelValue?.link?.content_type;
82
+ if (!contentType || !props.menuEndpoint) {
83
+ availablePages.value = [];
84
+ return;
85
+ }
86
+ try {
87
+ const crud = useCrud<AvailablePage[]>(pageTypesEndpoint.value);
88
+ const id =
89
+ typeof contentType === "object"
90
+ ? ((contentType as { id?: number | string }).id ?? "")
91
+ : contentType;
92
+ availablePages.value = (await crud.detail(
93
+ id,
94
+ )) as unknown as AvailablePage[];
95
+ } catch {
96
+ availablePages.value = [];
97
+ }
98
+ }
99
+
100
+ watch(() => props.modelValue?.id, loadPages, { immediate: true });
101
+
102
+ // ─── Fields ──────────────────────────────────────────────────────────────────
103
+
104
+ const defaultCoreFields = computed<AnyFieldDescriptor[]>(() => [
105
+ {
106
+ key: "title",
107
+ label: t("mapo.menuNodeEditor.title"),
108
+ type: "text",
109
+ required: true,
110
+ },
111
+ {
112
+ key: "link.link_type",
113
+ label: t("mapo.menuNodeEditor.linkTypeLabel"),
114
+ type: "select",
115
+ cols: { md: 4 },
116
+ attrs: {
117
+ items: [
118
+ { label: t("mapo.menuNodeEditor.relational"), value: "RE" },
119
+ { label: t("mapo.menuNodeEditor.static"), value: "ST" },
120
+ ],
121
+ },
122
+ },
123
+ ...(Object.keys(props.availableClasses).length
124
+ ? [
125
+ {
126
+ key: "meta.style",
127
+ label: t("mapo.menuNodeEditor.styleLabel"),
128
+ type: "select",
129
+ cols: { md: 4 },
130
+ attrs: {
131
+ items: Object.entries(props.availableClasses).map(
132
+ ([label, value]) => ({ label, value }),
133
+ ),
134
+ },
135
+ } as AnyFieldDescriptor,
136
+ ]
137
+ : []),
138
+ {
139
+ // `target_bank` keeps the v1/Camomilla meta key for data compatibility.
140
+ key: "meta.target_bank",
141
+ label: t("mapo.menuNodeEditor.openInNewTabLabel"),
142
+ type: "switch",
143
+ cols: { md: 4 },
144
+ },
145
+ {
146
+ key: "link.content_type",
147
+ label: t("mapo.menuNodeEditor.relContentTypeLabel"),
148
+ type: "fks",
149
+ cols: { md: 6 },
150
+ show: ({ model }) => (model as MenuTreeNode).link?.link_type === "RE",
151
+ onChange: () => loadPages(),
152
+ attrs: {
153
+ endpoint: pageTypesEndpoint.value,
154
+ itemText: "verbose_name_plural",
155
+ itemValue: "id",
156
+ returnObject: false,
157
+ multiple: false,
158
+ },
159
+ },
160
+ {
161
+ key: "link.url_node",
162
+ label: t("mapo.menuNodeEditor.relPageIdLabel"),
163
+ type: "select",
164
+ cols: { md: 6 },
165
+ show: ({ model }) => (model as MenuTreeNode).link?.link_type === "RE",
166
+ attrs: {
167
+ items: availablePages.value.map((p) => ({
168
+ label: p.name,
169
+ value: p.url_node_id,
170
+ })),
171
+ },
172
+ },
173
+ {
174
+ key: "link.static",
175
+ label: t("mapo.menuNodeEditor.staticLabel"),
176
+ type: "text",
177
+ show: ({ model }) => (model as MenuTreeNode).link?.link_type === "ST",
178
+ },
179
+ ]);
180
+
181
+ const fields = computed<AnyFieldDescriptor[]>(() => [
182
+ ...(props.coreFields ?? defaultCoreFields.value),
183
+ ...props.additionalFields,
184
+ ]);
185
+
186
+ // ─── Breadcrumbs ─────────────────────────────────────────────────────────────
187
+
188
+ const breadcrumbs = computed<MenuTreeNode[]>(() => {
189
+ const found = findMenuNode(props.nodes, props.modelValue.id);
190
+ return found ? [...found.parents, found.node] : [props.modelValue];
191
+ });
192
+
193
+ // ─── Errors ──────────────────────────────────────────────────────────────────
194
+ // Node errors arrive nested from the backend ({ title: [...], link: {...} });
195
+ // MapoForm expects a flat dot-notation Record<string, string[]>.
196
+
197
+ const errors = computed<Record<string, string[]>>(() => {
198
+ const flat: Record<string, string[]> = {};
199
+ const walk = (obj: unknown, prefix: string) => {
200
+ if (Array.isArray(obj)) {
201
+ flat[prefix] = obj.map(String);
202
+ } else if (obj && typeof obj === "object") {
203
+ for (const [k, v] of Object.entries(obj)) {
204
+ walk(v, prefix ? `${prefix}.${k}` : k);
205
+ }
206
+ }
207
+ };
208
+ walk(props.modelValue?.errors ?? {}, "");
209
+ return flat;
210
+ });
211
+
212
+ const slotBindings = computed<SlotBindings>(() => ({
213
+ model: props.modelValue,
214
+ fields: fields.value,
215
+ errors: errors.value,
216
+ readonly: props.readonly,
217
+ }));
218
+
219
+ // MapoForm is globally registered by @mapomodule/form.
220
+ const MapoForm = resolveComponent("MapoForm");
221
+ </script>
222
+
223
+ <template>
224
+ <div class="mapo-menu-node-editor flex h-full min-w-0 flex-1 flex-col">
225
+ <!-- Top bar: breadcrumbs + delete -->
226
+ <div
227
+ class="flex items-center justify-between gap-2 border-b border-default px-4 py-2"
228
+ >
229
+ <p class="flex min-w-0 items-center gap-1 truncate text-sm">
230
+ <span class="shrink-0 text-dimmed"
231
+ >{{ t("mapo.menuNodeEditor.editNode") }}:</span
232
+ >
233
+ <template v-for="(node, i) in breadcrumbs" :key="node.id">
234
+ <button
235
+ type="button"
236
+ class="max-w-40 truncate hover:underline"
237
+ :class="
238
+ i === breadcrumbs.length - 1
239
+ ? 'font-medium text-highlighted'
240
+ : 'text-muted'
241
+ "
242
+ @click="emit('update:modelValue', node)"
243
+ >
244
+ {{ node.title || "…" }}
245
+ </button>
246
+ <UIcon
247
+ v-if="i !== breadcrumbs.length - 1"
248
+ name="i-lucide-chevron-right"
249
+ class="size-3 shrink-0 text-dimmed"
250
+ />
251
+ </template>
252
+ </p>
253
+ <UButton
254
+ v-if="!readonly"
255
+ icon="i-lucide-trash-2"
256
+ size="xs"
257
+ color="error"
258
+ variant="soft"
259
+ @click="emit('delete')"
260
+ >
261
+ {{ t("mapo.delete") }}
262
+ </UButton>
263
+ </div>
264
+
265
+ <!-- Form -->
266
+ <div class="flex-1 overflow-y-auto p-4">
267
+ <slot name="form-top" v-bind="slotBindings" />
268
+ <slot name="form" v-bind="slotBindings">
269
+ <component
270
+ :is="MapoForm"
271
+ :model-value="modelValue"
272
+ :fields="fields"
273
+ :errors="errors"
274
+ :readonly="readonly"
275
+ immediate
276
+ @update:model-value="emit('update:modelValue', $event)"
277
+ />
278
+ </slot>
279
+ <slot name="form-bottom" v-bind="slotBindings" />
280
+ </div>
281
+ </div>
282
+ </template>
@@ -0,0 +1,264 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed, provide } from "vue";
3
+ import { useI18n } from "vue-i18n";
4
+ import { VueDraggable } from "vue-draggable-plus";
5
+ import { deepClone } from "@mapomodule/utils";
6
+ import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
7
+ import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
8
+ import {
9
+ createMenuNode,
10
+ menuTreeDepth,
11
+ removeMenuNode,
12
+ type MenuTreeNode,
13
+ } from "../types/menu.js";
14
+ import { MENU_DND_CTX, type MenuDndContext } from "./menuDndContext.js";
15
+ import MapoMenuTreeviewNode from "./MapoMenuTreeviewNode.vue";
16
+
17
+ /**
18
+ * Drag & drop tree of menu nodes (left pane of `MapoMenuManager`).
19
+ *
20
+ * The node arrays are mutated in place by the nested draggables; the tree is
21
+ * owned by the parent through the `nodes` prop. `update:nodes` is emitted on
22
+ * every structural change so a parent can also `v-model:nodes`.
23
+ */
24
+ const props = withDefaults(
25
+ defineProps<{
26
+ nodes: MenuTreeNode[];
27
+ /** Currently selected node (v-model). */
28
+ modelValue?: MenuTreeNode | null;
29
+ title?: string;
30
+ /** Max nesting depth; `-1` = unlimited. */
31
+ maxDepth?: number;
32
+ readonly?: boolean;
33
+ /** Show a skeleton instead of the empty state while the tree is being fetched. */
34
+ loading?: boolean;
35
+ }>(),
36
+ {
37
+ modelValue: null,
38
+ title: "",
39
+ maxDepth: -1,
40
+ readonly: false,
41
+ loading: false,
42
+ },
43
+ );
44
+
45
+ const emit = defineEmits<{
46
+ "update:modelValue": [node: MenuTreeNode | null];
47
+ "update:nodes": [nodes: MenuTreeNode[]];
48
+ }>();
49
+
50
+ defineSlots<{
51
+ /** Content above the tree (e.g. a language switch). */
52
+ top(): unknown;
53
+ /** Content below the tree (e.g. a save button). */
54
+ bottom(): unknown;
55
+ }>();
56
+
57
+ const { t } = useI18n();
58
+ const confirm = useConfirmStore();
59
+ const snack = useSnackStore();
60
+
61
+ /**
62
+ * The node tree, as a writable reference.
63
+ *
64
+ * `nodes` is deliberately shared by reference with the parent's model: the
65
+ * nested drag & drop lists reorder and re-parent nodes by mutating these arrays
66
+ * in place, which is what keeps every level of the recursion in sync without a
67
+ * round-trip through the manager. Going through this computed makes that intent
68
+ * explicit — and lets `VueDraggable` write back a replaced array through the
69
+ * setter when it doesn't splice.
70
+ */
71
+ const tree = computed({
72
+ get: () => props.nodes,
73
+ set: (value: MenuTreeNode[]) => emit("update:nodes", value),
74
+ });
75
+
76
+ // ─── Selection ────────────────────────────────────────────────────────────────
77
+
78
+ function select(node: MenuTreeNode | null) {
79
+ emit("update:modelValue", node);
80
+ }
81
+
82
+ // ─── Depth-validated drag & drop ─────────────────────────────────────────────
83
+ // Nested SortableJS lists mutate the arrays in place: snapshot on start,
84
+ // validate on end, restore the snapshot when the drop exceeds maxDepth.
85
+
86
+ const dragging = ref(false);
87
+ let snapshot: MenuTreeNode[] | null = null;
88
+
89
+ const dndCtx: MenuDndContext = {
90
+ dragging,
91
+ onStart() {
92
+ dragging.value = true;
93
+ snapshot = deepClone(tree.value);
94
+ },
95
+ onEnd() {
96
+ dragging.value = false;
97
+ if (
98
+ props.maxDepth > 0 &&
99
+ snapshot &&
100
+ menuTreeDepth(tree.value) > props.maxDepth
101
+ ) {
102
+ tree.value.splice(0, tree.value.length, ...snapshot);
103
+ snack.show(
104
+ t("mapo.menuTreeview.maxDepthReached", { max: props.maxDepth }),
105
+ "warning",
106
+ );
107
+ }
108
+ snapshot = null;
109
+ emit("update:nodes", tree.value);
110
+ },
111
+ };
112
+
113
+ provide(MENU_DND_CTX, dndCtx);
114
+
115
+ // ─── Node CRUD ────────────────────────────────────────────────────────────────
116
+
117
+ type NodeInstance = { openIfChild: (child: MenuTreeNode) => void };
118
+
119
+ const nodeRefs = ref<Array<NodeInstance | null>>([]);
120
+
121
+ // Declared here rather than inline in the template: template expressions are
122
+ // transpiled as plain JS at build time, so a TS cast there fails to parse.
123
+ function setNodeRef(index: number, el: unknown) {
124
+ nodeRefs.value[index] = (el as NodeInstance | null) ?? null;
125
+ }
126
+
127
+ /**
128
+ * Create a node. Appended to the selected node's children when possible
129
+ * (respecting maxDepth), to the root otherwise. The new node is selected
130
+ * right away so the editor opens on it (v1 opened an inline rename instead).
131
+ */
132
+ function newNode() {
133
+ if (props.readonly) return;
134
+ const node = createMenuNode();
135
+ const target = props.modelValue;
136
+ if (target) {
137
+ const targetDepth = depthOf(target);
138
+ if (props.maxDepth > 0 && targetDepth + 1 > props.maxDepth) {
139
+ tree.value.push(node);
140
+ } else {
141
+ target.nodes.push(node);
142
+ nodeRefs.value.forEach((r) => r?.openIfChild(node));
143
+ }
144
+ } else {
145
+ tree.value.push(node);
146
+ }
147
+ select(node);
148
+ emit("update:nodes", tree.value);
149
+ }
150
+
151
+ function depthOf(
152
+ node: MenuTreeNode,
153
+ nodes: MenuTreeNode[] = tree.value,
154
+ depth = 1,
155
+ ): number {
156
+ for (const n of nodes) {
157
+ if (String(n.id) === String(node.id)) return depth;
158
+ const found = depthOf(node, n.nodes ?? [], depth + 1);
159
+ if (found > 0) return found;
160
+ }
161
+ return 0;
162
+ }
163
+
164
+ async function deleteNode(node: MenuTreeNode) {
165
+ if (props.readonly) return;
166
+ const ok = await confirm.ask({
167
+ title: t("mapo.menuTreeview.deleteTitle"),
168
+ message: t("mapo.menuTreeview.areYouSureDelete"),
169
+ confirmText: t("mapo.delete"),
170
+ dangerous: true,
171
+ });
172
+ if (!ok) return;
173
+ silentDeleteNode(node);
174
+ }
175
+
176
+ /** Remove without confirmation (used for empty aborted nodes). */
177
+ function silentDeleteNode(node: MenuTreeNode) {
178
+ removeMenuNode(tree.value, node.id);
179
+ if (String(props.modelValue?.id) === String(node.id)) select(null);
180
+ emit("update:nodes", tree.value);
181
+ }
182
+
183
+ function deleteSelectedNode() {
184
+ if (props.modelValue) deleteNode(props.modelValue);
185
+ }
186
+
187
+ defineExpose({ deleteSelectedNode, newNode });
188
+ </script>
189
+
190
+ <template>
191
+ <div class="mapo-menu-treeview flex h-full flex-col">
192
+ <slot name="top" />
193
+
194
+ <!-- Toolbar -->
195
+ <div
196
+ class="flex items-center justify-between border-b border-default px-3 py-2"
197
+ >
198
+ <p class="truncate text-sm font-semibold text-highlighted">
199
+ {{ title }}
200
+ </p>
201
+ <UButton
202
+ v-if="!readonly"
203
+ icon="i-lucide-list-plus"
204
+ size="xs"
205
+ variant="ghost"
206
+ color="neutral"
207
+ :title="t('mapo.menuTreeview.newNode')"
208
+ @click="newNode"
209
+ />
210
+ </div>
211
+
212
+ <!-- Tree -->
213
+ <div class="flex-1 overflow-y-auto p-2" @click.self="select(null)">
214
+ <VueDraggable
215
+ v-model="tree"
216
+ group="mapo-menu-nodes"
217
+ handle=".mapo-menu-drag-handle"
218
+ :animation="150"
219
+ :disabled="readonly"
220
+ ghost-class="mapo-menu-ghost"
221
+ class="min-h-8 space-y-0.5"
222
+ @start="dndCtx.onStart()"
223
+ @end="dndCtx.onEnd()"
224
+ >
225
+ <MapoMenuTreeviewNode
226
+ v-for="(node, i) in nodes"
227
+ :key="node.id"
228
+ :ref="(el) => setNodeRef(i, el)"
229
+ :node="node"
230
+ :depth="1"
231
+ :selected-id="modelValue?.id ?? null"
232
+ :readonly="readonly"
233
+ @select="select($event)"
234
+ @delete="deleteNode($event)"
235
+ />
236
+ </VueDraggable>
237
+
238
+ <!-- Loading skeleton — shown instead of the empty state so a menu that
239
+ is still being fetched never reads as "no nodes". -->
240
+ <div v-if="loading && nodes.length === 0" class="space-y-1.5 p-1">
241
+ <USkeleton v-for="n in 4" :key="n" class="h-6 w-full" />
242
+ </div>
243
+
244
+ <!-- Empty state -->
245
+ <button
246
+ v-else-if="nodes.length === 0 && !readonly"
247
+ type="button"
248
+ class="flex w-full flex-col items-center gap-2 rounded-lg border border-dashed border-default py-8 text-dimmed transition-colors hover:border-accented hover:text-muted"
249
+ @click="newNode"
250
+ >
251
+ <UIcon name="i-lucide-list-plus" class="size-8" />
252
+ <span class="text-xs">{{ t("mapo.menuTreeview.noRootNodes") }}</span>
253
+ </button>
254
+ </div>
255
+
256
+ <slot name="bottom" />
257
+ </div>
258
+ </template>
259
+
260
+ <style scoped>
261
+ .mapo-menu-ghost {
262
+ opacity: 0.4;
263
+ }
264
+ </style>