@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
@@ -4,9 +4,11 @@ import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
4
4
  import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
5
5
  import { normalizeEndpoint } from "@mapomodule/utils";
6
6
  import { useCrud } from "@mapomodule/core/runtime/api/crud";
7
+ import { useMapoT } from "@mapomodule/i18n/runtime/composables/useMapoT";
7
8
  import { applyMultipartPolicy } from "@mapomodule/core/runtime/api/multipart";
8
9
  import { useNuxtApp, useRuntimeConfig } from "#app";
9
10
  import { defaultMediaAdapter } from "../adapters/defaultMediaAdapter.js";
11
+ import { languagesFromMetadata } from "../utils/langInfo.js";
10
12
  import type {
11
13
  MediaItem,
12
14
  MediaFolder,
@@ -84,6 +86,14 @@ export const useMediaStore = defineStore("mapo-media", () => {
84
86
  const _currentAll = ref(false);
85
87
  const _currentLang = ref<string | undefined>(undefined);
86
88
 
89
+ // Language codes the media model is actually registered for, read once from
90
+ // the endpoint's OPTIONS. It lives here rather than in the editor because all
91
+ // three entry points — manager, picker dialog, and the `media` form field —
92
+ // mount their own editor, and each would otherwise need the host page to hand
93
+ // it a hardcoded list.
94
+ const languages = ref<string[]>([]);
95
+ let languagesPromise: Promise<void> | null = null;
96
+
87
97
  // ─── Getters ──────────────────────────────────────────────────────────────
88
98
  const parentFolder = computed(
89
99
  () => parentFolders.value[parentFolders.value.length - 1] ?? null,
@@ -119,6 +129,27 @@ export const useMediaStore = defineStore("mapo-media", () => {
119
129
  return useCrud<MediaFolder>(endpoints.folders);
120
130
  }
121
131
 
132
+ /**
133
+ * Ask the media endpoint to describe its language situation, at most once.
134
+ *
135
+ * `lang_info` is served on OPTIONS only: it describes the model, so there is
136
+ * no record to read it from, and a media library nobody registered for
137
+ * translation reports none — which is the point. The in-flight promise is
138
+ * kept so several editors mounting at once share a single request.
139
+ */
140
+ async function deriveLanguages(): Promise<void> {
141
+ if (languagesPromise) return languagesPromise;
142
+ languagesPromise = (async () => {
143
+ try {
144
+ languages.value = languagesFromMetadata(await mediaCrud().options());
145
+ } catch {
146
+ // A backend without OPTIONS metadata just gets no language switcher.
147
+ languagesPromise = null;
148
+ }
149
+ })();
150
+ return languagesPromise;
151
+ }
152
+
122
153
  // ─── Breadcrumb maintenance ─────────────────────────────────────────────
123
154
  // Driven by the response's `parent_folder` (matches the legacy contract):
124
155
  // push when entering a new folder, slice when navigating back up.
@@ -219,7 +250,7 @@ export const useMediaStore = defineStore("mapo-media", () => {
219
250
  const updated = await mediaCrud().partialUpdate(media.id, payload as never);
220
251
  // Keep the open editor in sync with the server response (legacy behavior).
221
252
  if (editMedia.value?.id === media.id) editMedia.value = updated;
222
- useSnackStore().show("Media updated", "success");
253
+ useSnackStore().show(useMapoT()("mapo.mediaManager.fileInfo"), "success");
223
254
  await getRoot();
224
255
  return updated;
225
256
  }
@@ -258,10 +289,11 @@ export const useMediaStore = defineStore("mapo-media", () => {
258
289
  }
259
290
 
260
291
  async function deleteFolder(folder: MediaFolder): Promise<void> {
292
+ const t = useMapoT();
261
293
  const confirmed = await useConfirmStore().ask({
262
- title: "Delete folder",
263
- message: `Delete folder "${folder.name}"? Media inside it will not be deleted.`,
264
- confirmText: "Delete",
294
+ title: t("mapo.mediaFolders.deleteTitle"),
295
+ message: t("mapo.mediaFolders.confirmDelete", { name: folder.name }),
296
+ confirmText: t("mapo.delete"),
265
297
  dangerous: true,
266
298
  });
267
299
  if (!confirmed) return;
@@ -270,10 +302,13 @@ export const useMediaStore = defineStore("mapo-media", () => {
270
302
  }
271
303
 
272
304
  async function deleteMedia(media: MediaItem): Promise<void> {
305
+ const t = useMapoT();
273
306
  const confirmed = await useConfirmStore().ask({
274
- title: "Delete media",
275
- message: `Delete "${media.title || media.file}"?`,
276
- confirmText: "Delete",
307
+ title: t("mapo.mediaManager.deleteTitle"),
308
+ message: t("mapo.mediaEditor.confirmDelete", {
309
+ name: media.title || media.file,
310
+ }),
311
+ confirmText: t("mapo.delete"),
277
312
  dangerous: true,
278
313
  });
279
314
  if (!confirmed) return;
@@ -333,16 +368,20 @@ export const useMediaStore = defineStore("mapo-media", () => {
333
368
  async function deleteSelected(): Promise<void> {
334
369
  const count = editList.value.length;
335
370
  if (count === 0) return;
371
+ const t = useMapoT();
336
372
  const confirmed = await useConfirmStore().ask({
337
- title: "Delete selected media",
338
- message: `Delete ${count} selected media?`,
339
- confirmText: `Delete ${count}`,
373
+ title: t("mapo.mediaGallery.deleteTitle"),
374
+ message: t("mapo.mediaGallery.deleteSelected", { number: count }),
375
+ confirmText: t("mapo.delete"),
340
376
  dangerous: true,
341
377
  });
342
378
  if (!confirmed) return;
343
379
  await Promise.all(editList.value.map((id) => mediaCrud().delete(id)));
344
380
  editList.value = [];
345
- useSnackStore().show(`${count} media deleted`, "success");
381
+ useSnackStore().show(
382
+ t("mapo.mediaGallery.deleteSuccess", { number: count }),
383
+ "success",
384
+ );
346
385
  await getRoot();
347
386
  }
348
387
 
@@ -379,10 +418,17 @@ export const useMediaStore = defineStore("mapo-media", () => {
379
418
  resolve(xhr.response as MediaItem);
380
419
  } else {
381
420
  const detail = (xhr.response as { detail?: string } | null)?.detail;
382
- reject(new Error(detail || `Upload failed (${xhr.status})`));
421
+ reject(
422
+ new Error(
423
+ detail ||
424
+ `${useMapoT()("mapo.mediaUploader.uploadFailed")} (${xhr.status})`,
425
+ ),
426
+ );
383
427
  }
384
428
  });
385
- xhr.addEventListener("error", () => reject(new Error("Upload failed")));
429
+ xhr.addEventListener("error", () =>
430
+ reject(new Error(useMapoT()("mapo.mediaUploader.uploadFailed"))),
431
+ );
386
432
  xhr.send(formData);
387
433
  });
388
434
  }
@@ -429,12 +475,14 @@ export const useMediaStore = defineStore("mapo-media", () => {
429
475
  selection,
430
476
  editList,
431
477
  selectMode,
478
+ languages,
432
479
  // getters
433
480
  parentFolder,
434
481
  editListSet,
435
482
  editListState,
436
483
  // actions
437
484
  getRoot,
485
+ deriveLanguages,
438
486
  navigateToFolder,
439
487
  openEditor,
440
488
  closeEditor,
@@ -0,0 +1,178 @@
1
+ import type { Component, ComputedRef, Ref } from "vue";
2
+ import type {
3
+ AnyFieldDescriptor,
4
+ FieldAnnotations,
5
+ FieldRegistry,
6
+ } from "@mapomodule/form/types";
7
+ import type { JSONSchema } from "@mapomodule/utils";
8
+
9
+ /**
10
+ * What `MapoDetail` shares with the components inside it: its slots, its forms
11
+ * and the extensions it renders. Read it with `useMapoDetail()`.
12
+ */
13
+ export interface MapoDetailContext<T extends object = Record<string, unknown>> {
14
+ /** The REST endpoint of the record. */
15
+ endpoint: ComputedRef<string>;
16
+ /** The record id; `"new"` for a record not created yet. */
17
+ id: ComputedRef<string | number>;
18
+ isNew: ComputedRef<boolean>;
19
+ /**
20
+ * The name of the record's model for people, as the page titles it
21
+ * (`modelName`): "Article"; `null` without one. `MapoDetail` always gives
22
+ * it; optional, so a context built elsewhere, as a test's, still compiles.
23
+ */
24
+ modelName?: ComputedRef<string | null>;
25
+ /**
26
+ * The backend model the page checks the permissions of (`permissionModel`):
27
+ * `article`; `undefined` without one. `MapoDetail` always gives it;
28
+ * optional, as `modelName`.
29
+ */
30
+ permissionModel?: ComputedRef<string | undefined>;
31
+ /** The record being edited: write to it to change the values of the form. */
32
+ model: Ref<T>;
33
+ /** The body fields rendered: the `fields` prop, or the ones derived from the schema. */
34
+ fields: ComputedRef<AnyFieldDescriptor<T>[]>;
35
+ /** The sidebar fields rendered. */
36
+ sidebarFields: ComputedRef<AnyFieldDescriptor<T>[]>;
37
+ /** The languages of the record; empty when it is not translated. */
38
+ languages: ComputedRef<string[]>;
39
+ /** The language being edited: write to it to switch. */
40
+ currentLang: Ref<string>;
41
+ /** The field registry the forms use. */
42
+ registry: ComputedRef<FieldRegistry>;
43
+ /** Server errors by field path, as the last save returned them. */
44
+ errors: Readonly<Ref<Record<string, string[]>>>;
45
+ /** Whether the record is read-only for this user. */
46
+ readonly: ComputedRef<boolean>;
47
+ /** While the record loads. */
48
+ isLoading: Readonly<Ref<boolean>>;
49
+ /** From a save until it is done; after `save(true)`, until the page has gone back. */
50
+ isSaving: ComputedRef<boolean>;
51
+ /** While a save, a delete or a navigation back is under way. */
52
+ isBusy: ComputedRef<boolean>;
53
+ /**
54
+ * Whether the model differs from the record as loaded or last saved; for
55
+ * a new record, whether it holds a value it did not hold when the page
56
+ * opened (a blank text, an empty list or an empty object is none).
57
+ */
58
+ isDirty: ComputedRef<boolean>;
59
+ /**
60
+ * Marks set from inside the detail, shown with those of the `annotations`
61
+ * prop; on the same path the prop wins. Replace the map to change them.
62
+ */
63
+ annotations: Ref<FieldAnnotations>;
64
+ /** Which extensions the page allows: all, none, or the listed keys. */
65
+ extensions: ComputedRef<boolean | readonly string[]>;
66
+ /** Saves the record, as the Save buttons do; ignored while busy. */
67
+ save: (andBack?: boolean) => Promise<void>;
68
+ /** Goes back, as the Back button does; ignored while busy. */
69
+ back: () => void;
70
+ /**
71
+ * The endpoint's `OPTIONS` response, requested once per page and shared
72
+ * with `MapoDetail`, or `undefined` when the endpoint has none.
73
+ */
74
+ metadata: () => Promise<Record<string, unknown> | undefined>;
75
+ /**
76
+ * How the page turns the `OPTIONS` response into a JSON Schema
77
+ * (`schemaFromMetadata`), when it has its own way; `undefined`: Mapo's
78
+ * `metadataToJsonSchema`. `MapoDetail` always gives it; optional, as
79
+ * `modelName`.
80
+ */
81
+ schemaFromMetadata?: ComputedRef<
82
+ ((metadata: Record<string, unknown>) => JSONSchema | undefined) | undefined
83
+ >;
84
+ /**
85
+ * Calls `handler` after each save that succeeds, with the record as the
86
+ * backend returned it, before the page moves to a new record's address
87
+ * or goes back. Returns the function that removes it; one registered in
88
+ * a component's setup goes with the component. A handler that throws
89
+ * leaves the save done. `MapoDetail` always gives it; optional, as
90
+ * `modelName`.
91
+ */
92
+ onSaved?: (handler: (record: T) => void) => () => void;
93
+ /**
94
+ * The detail's draft, for a component that keeps a state of its own
95
+ * beside the record's values: it is saved, restored, discarded and
96
+ * cleared with them. With drafts off nothing is kept. `MapoDetail` always
97
+ * gives it; optional, as `modelName`.
98
+ */
99
+ draft?: MapoDetailDraft;
100
+ /**
101
+ * Takes the operator to a field: the form that holds it, the body's or
102
+ * the sidebar's, opens its tab, group or sub-tab and repeater item,
103
+ * scrolls the field into view and puts the focus on its control. The
104
+ * path is the one of its mark: `title`, `translations.it.title`,
105
+ * `blocks.0.title`. Resolves whether the control took the focus: `false`
106
+ * for a field no form has or shows. `MapoDetail` always gives it;
107
+ * optional, as `modelName`.
108
+ */
109
+ revealField?: (path: string) => Promise<boolean>;
110
+ }
111
+
112
+ /**
113
+ * A part of the detail's draft: the state of a component inside it, saved
114
+ * and restored with the record's values.
115
+ */
116
+ export interface MapoDetailDraftPart {
117
+ /**
118
+ * What to keep, as data `JSON.stringify()` can write; `undefined` when
119
+ * there is nothing. Called each time the draft is saved; a part that
120
+ * throws is left out of that save.
121
+ */
122
+ save: () => unknown;
123
+ /**
124
+ * Puts back what `save()` returned, when the operator restores the
125
+ * draft, after the record's values; `undefined` when the draft holds
126
+ * nothing for the part, which then starts again from nothing. It comes
127
+ * from the browser's storage: read it as outside data.
128
+ */
129
+ restore: (data: unknown) => void;
130
+ }
131
+
132
+ /** The draft of a `MapoDetail`, for the components inside it. */
133
+ export interface MapoDetailDraft {
134
+ /**
135
+ * Keeps a part of the draft under `key`, one per detail: registering the
136
+ * key again replaces the part. The draft is saved when the record changed
137
+ * or a part has something to keep. A part registered after the draft was
138
+ * restored gets its data then. Returns the function that removes it; one
139
+ * registered in a component's setup goes with the component.
140
+ */
141
+ part: (key: string, part: MapoDetailDraftPart) => () => void;
142
+ /**
143
+ * Saves the draft soon, after a change of a part's state: a change of
144
+ * the record's values saves it by itself.
145
+ */
146
+ touch: () => void;
147
+ }
148
+
149
+ /**
150
+ * Where `MapoDetail` renders an extension: `actions`, the sidebar card above
151
+ * Save; `body-top`, above the body form.
152
+ */
153
+ export type DetailExtensionPlacement = "actions" | "body-top";
154
+
155
+ /** A component that loads another: `() => import("./MyAction.vue")`. */
156
+ export type DetailExtensionLoader = () => Promise<
157
+ Component | { default: Component }
158
+ >;
159
+
160
+ /** A component added to every `MapoDetail`, registered with `defineDetailExtension()`. */
161
+ export interface DetailExtension {
162
+ /**
163
+ * Names the extension. A page picks extensions by key with the `extensions`
164
+ * prop, and registering a key again replaces the extension.
165
+ */
166
+ key: string;
167
+ /** Where the detail renders it. */
168
+ placement: DetailExtensionPlacement;
169
+ /**
170
+ * The component, or a loader of it. It reads the detail with
171
+ * `useMapoDetail()`. A function is always taken as a loader.
172
+ */
173
+ component: Component | DetailExtensionLoader;
174
+ /** Whether a detail page shows it. Default: always. */
175
+ visible?: (detail: MapoDetailContext) => boolean;
176
+ /** Order among the extensions of a placement, lower first. Default: `0`. */
177
+ order?: number;
178
+ }
@@ -1,8 +1,16 @@
1
1
  /** Defines a single column in the list table. */
2
2
  export interface ListColumn<T = Record<string, unknown>> {
3
- /** Property name on the row object. Must be a key of `T`. */
4
- key: keyof T & string;
3
+ /**
4
+ * Property of the row to show, a key of `T`. A dotted path (`category.name`)
5
+ * reads a field of a related object; it starts with a key of `T`.
6
+ */
7
+ key: (keyof T & string) | `${keyof T & string}.${string}`;
5
8
  label: string;
9
+ /**
10
+ * Turns the header into a button that cycles ascending, descending and
11
+ * unsorted. The list sends the order to the backend as `ordering`, or sorts
12
+ * in memory in offline and hybrid mode.
13
+ */
6
14
  sortable?: boolean;
7
15
  /** CSS class applied to the `<td>` cell. */
8
16
  class?: string;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Menu Manager types — the canonical tree contract matches the Camomilla
3
+ * `/api/camomilla/menus` payload (v1 parity): a menu is a keyed collection
4
+ * of recursively nested nodes, optionally translated per language.
5
+ */
6
+
7
+ /** Link carried by a menu node: relational (a CMS page) or static (raw URL). */
8
+ export interface MenuNodeLink {
9
+ /** `"RE"` = relational (page picked from the backend), `"ST"` = static URL. */
10
+ link_type?: "RE" | "ST";
11
+ /** Static URL used when `link_type === "ST"`. */
12
+ static?: string;
13
+ /** Content-type id used when `link_type === "RE"`. */
14
+ content_type?: number | string | null;
15
+ /** Routable node id of the linked page when `link_type === "RE"`. */
16
+ url_node?: number | string | null;
17
+ [key: string]: unknown;
18
+ }
19
+
20
+ /** A single node of the menu tree. */
21
+ export interface MenuTreeNode {
22
+ /**
23
+ * Node identity. Nodes created client-side get a random string id;
24
+ * the backend may replace it with a numeric one on save.
25
+ */
26
+ id: string | number;
27
+ title: string;
28
+ link: MenuNodeLink;
29
+ /**
30
+ * Free-form node metadata (e.g. `style`, `target_bank`).
31
+ * `target_bank` keeps the v1/Camomilla key for data compatibility.
32
+ */
33
+ meta: Record<string, unknown>;
34
+ /** Child nodes. */
35
+ nodes: MenuTreeNode[];
36
+ /** Per-field backend validation errors attached by the manager. */
37
+ errors?: Record<string, string[]>;
38
+ [key: string]: unknown;
39
+ }
40
+
41
+ /** Per-language node tree used when the menu is translatable. */
42
+ export interface MenuTranslation {
43
+ nodes: MenuTreeNode[];
44
+ [key: string]: unknown;
45
+ }
46
+
47
+ /** The full menu payload handled by `MapoMenuManager`. */
48
+ export interface MapoMenu {
49
+ id?: number | string;
50
+ /** Unique menu identifier (e.g. `"navbar"`, `"footer"`). */
51
+ key: string;
52
+ enabled?: boolean;
53
+ /** Node tree used when the menu is NOT translatable. */
54
+ nodes?: MenuTreeNode[];
55
+ /** Per-language node trees used when the menu IS translatable. */
56
+ translations?: Record<string, MenuTranslation>;
57
+ [key: string]: unknown;
58
+ }
59
+
60
+ /** Create an empty client-side node with a unique temporary id. */
61
+ export function createMenuNode(
62
+ partial: Partial<MenuTreeNode> = {},
63
+ ): MenuTreeNode {
64
+ return {
65
+ id: Math.random().toString(36).slice(2),
66
+ title: "",
67
+ link: {},
68
+ meta: {},
69
+ nodes: [],
70
+ ...partial,
71
+ };
72
+ }
73
+
74
+ /** Maximum nesting depth of a menu node tree (a flat list = depth 1). */
75
+ export function menuTreeDepth(nodes: MenuTreeNode[]): number {
76
+ if (!nodes.length) return 0;
77
+ return 1 + Math.max(...nodes.map((n) => menuTreeDepth(n.nodes ?? [])));
78
+ }
79
+
80
+ /** Depth-first search for a node id. Returns the node and its ancestor chain. */
81
+ export function findMenuNode(
82
+ nodes: MenuTreeNode[],
83
+ id: string | number,
84
+ parents: MenuTreeNode[] = [],
85
+ ): { node: MenuTreeNode; parents: MenuTreeNode[] } | null {
86
+ for (const node of nodes) {
87
+ if (String(node.id) === String(id)) return { node, parents };
88
+ const found = findMenuNode(node.nodes ?? [], id, [...parents, node]);
89
+ if (found) return found;
90
+ }
91
+ return null;
92
+ }
93
+
94
+ /** Remove a node (by id) anywhere in the tree. Returns `true` when removed. */
95
+ export function removeMenuNode(
96
+ nodes: MenuTreeNode[],
97
+ id: string | number,
98
+ ): boolean {
99
+ const index = nodes.findIndex((n) => String(n.id) === String(id));
100
+ if (index !== -1) {
101
+ nodes.splice(index, 1);
102
+ return true;
103
+ }
104
+ return nodes.some((n) => removeMenuNode(n.nodes ?? [], id));
105
+ }
@@ -0,0 +1,28 @@
1
+ /** What a rich text editor writes into a field it leaves empty. */
2
+ const BLANK_MARKUP = /<\/?p>|<br\s*\/?>|&nbsp;/gi;
3
+
4
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
5
+ if (typeof value !== "object") return false;
6
+ if (value === null) return false;
7
+ const prototype: unknown = Object.getPrototypeOf(value);
8
+ const isLiteral = prototype === Object.prototype;
9
+ const isBare = prototype === null;
10
+ return isLiteral || isBare;
11
+ }
12
+
13
+ /**
14
+ * Whether a form's value holds something: not `undefined` or `null`, not a
15
+ * blank text (the empty paragraphs and line breaks of a rich text editor
16
+ * included), not an empty list, not an object whose values all hold
17
+ * nothing. `false`, `0` and any other object, such as a file, are values.
18
+ */
19
+ export function holdsFormValue(value: unknown): boolean {
20
+ if (value === undefined) return false;
21
+ if (value === null) return false;
22
+ if (typeof value === "string") {
23
+ return value.replace(BLANK_MARKUP, " ").trim() !== "";
24
+ }
25
+ if (Array.isArray(value)) return value.length > 0;
26
+ if (isPlainObject(value)) return Object.values(value).some(holdsFormValue);
27
+ return true;
28
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `lang_info`, as served by Camomilla on an endpoint's OPTIONS response.
3
+ *
4
+ * It describes the MODEL, not the site and not a record: a multilingual site can
5
+ * still expose models nobody registered for translation, and rendering a
6
+ * language switcher for those invites the user to type values the backend will
7
+ * drop on save.
8
+ *
9
+ * OPTIONS rather than the record payload because it is metadata, and because a
10
+ * "create new" form has no record to read it from.
11
+ */
12
+ export interface LangInfo {
13
+ /** Whether this model is registered for translation at all. */
14
+ translatable?: boolean;
15
+ /** Codes usable for THIS model. Empty when it is not translatable. */
16
+ languages?: string[];
17
+ /** What the site supports. Present for context; not model-specific. */
18
+ site_languages?: string[];
19
+ default?: string;
20
+ active?: string;
21
+ }
22
+
23
+ /**
24
+ * Language codes a model can be translated into, read from its OPTIONS metadata.
25
+ *
26
+ * Returns `[]` — meaning "render no language switcher" — when the model is not
27
+ * translatable and when `lang_info` is absent entirely. A backend that does not
28
+ * publish the field cannot be assumed multilingual.
29
+ */
30
+ export function languagesFromMetadata(metadata: unknown): string[] {
31
+ const info = (metadata as Record<string, unknown> | null | undefined)
32
+ ?.lang_info as LangInfo | undefined;
33
+ if (!info || info.translatable === false) return [];
34
+ if (!Array.isArray(info.languages)) return [];
35
+ return info.languages.filter(
36
+ (code): code is string => typeof code === "string",
37
+ );
38
+ }
@@ -0,0 +1,54 @@
1
+ /** One sort key as `UTable` holds it: the column id and the direction. */
2
+ export interface TableSort {
3
+ id: string;
4
+ desc: boolean;
5
+ }
6
+
7
+ /**
8
+ * The page size that stands for "all rows". A plain number, so the paging
9
+ * arithmetic and the in-memory slicing keep working unchanged.
10
+ */
11
+ export const ALL_ROWS = Number.MAX_SAFE_INTEGER;
12
+
13
+ /** A `pageSizeOptions` entry as the table stores it: `"all"` → {@link ALL_ROWS}. */
14
+ export function toPageSize(option: number | "all"): number {
15
+ return option === "all" ? ALL_ROWS : option;
16
+ }
17
+
18
+ /** Reads `page_size` from the URL: `all`, or a positive number, else `fallback`. */
19
+ export function parsePageSize(value: unknown, fallback: number): number {
20
+ if (value === "all") return ALL_ROWS;
21
+ const size = Number(value);
22
+ return Number.isFinite(size) && size > 0 ? size : fallback;
23
+ }
24
+
25
+ /** Writes a page size to the URL: {@link ALL_ROWS} as `all`. */
26
+ export function formatPageSize(size: number): string {
27
+ return size === ALL_ROWS ? "all" : String(size);
28
+ }
29
+
30
+ /**
31
+ * The sorting after a click on a sortable header. The column goes from
32
+ * unsorted to ascending, to descending, and back to unsorted, so the natural
33
+ * order (needed by drag reorder) is one click away. It replaces any other key.
34
+ */
35
+ export function nextSorting(
36
+ sorting: TableSort[],
37
+ columnId: string,
38
+ ): TableSort[] {
39
+ const current = sorting.find((sort) => sort.id === columnId);
40
+ if (!current) return [{ id: columnId, desc: false }];
41
+ if (!current.desc) return [{ id: columnId, desc: true }];
42
+ return [];
43
+ }
44
+
45
+ /**
46
+ * The `ordering` param for a sorting: comma-separated keys, `-` for descending.
47
+ * A dotted key becomes a Django lookup (`category.name` → `category__name`),
48
+ * the way DRF's OrderingFilter reaches a field of a related object.
49
+ */
50
+ export function orderingParam(sorting: TableSort[]): string {
51
+ return sorting
52
+ .map((sort) => `${sort.desc ? "-" : ""}${sort.id.split(".").join("__")}`)
53
+ .join(",");
54
+ }