@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
@@ -10,15 +10,41 @@ import {
10
10
  provide,
11
11
  type Ref,
12
12
  type VNode,
13
+ shallowRef,
14
+ getCurrentScope,
15
+ onScopeDispose,
13
16
  } from "vue";
14
- import { useRouter, onBeforeRouteLeave } from "vue-router";
15
- import { useNuxtApp } from "#app";
16
- import { objectDiff, debounce, deepClone } from "@mapomodule/utils";
17
+ import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
18
+ import { useI18n } from "vue-i18n";
19
+ import {
20
+ objectDiff,
21
+ debounce,
22
+ deepClone,
23
+ metadataToJsonSchema,
24
+ } from "@mapomodule/utils";
17
25
  import { useCrud } from "@mapomodule/core/runtime/api/crud";
26
+ import {
27
+ getErrorData,
28
+ getErrorDetail,
29
+ getErrorStatus,
30
+ } from "@mapomodule/core/runtime/utils/fetchError";
18
31
  import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
19
32
  import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
20
- import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
33
+ import { useAuthStore } from "@mapomodule/store/runtime/stores/auth";
34
+ import type {
35
+ AnyFieldDescriptor,
36
+ FieldAnnotations,
37
+ FieldRegistry,
38
+ UseFormFromSchemaOptions,
39
+ } from "@mapomodule/form/types";
21
40
  import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
41
+ import { languagesFromMetadata } from "../utils/langInfo";
42
+ import { holdsFormValue } from "../utils/formValues";
43
+ import { DETAIL_KEY } from "../composables/useMapoDetail";
44
+ import type { MapoDetailContext, MapoDetailDraftPart } from "../types/detail";
45
+ import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
46
+ import { modelForDraft } from "@mapomodule/form/runtime/utils/draft";
47
+ import type { JSONSchema } from "@mapomodule/utils";
22
48
  import type { MultipartPolicy } from "@mapomodule/core";
23
49
 
24
50
  // ─── Props ────────────────────────────────────────────────────────────────────
@@ -29,12 +55,51 @@ const props = withDefaults(
29
55
  endpoint: string;
30
56
  /** Record id. Pass `'new'` to create. */
31
57
  id: string | number;
32
- /** Fields for the main body form. */
33
- fields: AnyFieldDescriptor<T>[];
58
+ /**
59
+ * Fields for the main body form.
60
+ *
61
+ * Optional only so `experimentalFieldsFromSchema` can supply them; pass them
62
+ * explicitly for any form you care about the layout of.
63
+ */
64
+ fields?: AnyFieldDescriptor<T>[];
65
+ /**
66
+ * EXPERIMENTAL. Build the body fields from the endpoint's OPTIONS response
67
+ * when `fields` is not given.
68
+ *
69
+ * Off by default and deliberately opt-in: a derived form knows types,
70
+ * labels, relations and what is read-only, but nothing editorial — no tabs,
71
+ * no column widths, no rich-text vs textarea, no sidebar split, and no
72
+ * opinion about field order beyond the serializer's. Treat it as a
73
+ * scaffold to start from, not a finished panel.
74
+ *
75
+ * Reads the `schema` the endpoint publishes on OPTIONS (camomilla >= 6.6)
76
+ * or, without one, Django REST Framework's standard metadata
77
+ * (`actions.POST`, which DRF serves to users who can create).
78
+ * `schemaFromMetadata` changes how.
79
+ */
80
+ experimentalFieldsFromSchema?: boolean;
81
+ /**
82
+ * Turns the OPTIONS response into the JSON Schema the body fields are
83
+ * built from, with `experimentalFieldsFromSchema`. Default:
84
+ * `metadataToJsonSchema` from `@mapomodule/utils`, which reads a published
85
+ * `schema`, then DRF metadata. Call it with options, or return your own
86
+ * schema; `undefined` derives no fields.
87
+ */
88
+ schemaFromMetadata?: (
89
+ metadata: Record<string, unknown>,
90
+ ) => JSONSchema | undefined;
91
+ /** Passed straight to useFormFromSchema when deriving. */
92
+ schemaFieldOptions?: UseFormFromSchemaOptions;
34
93
  /** Fields for the sidebar form (optional). */
35
94
  sidebarFields?: AnyFieldDescriptor<T>[];
36
95
  /** Translation language codes (e.g. ['it', 'en']). */
37
96
  languages?: string[];
97
+ /**
98
+ * Number of languages above which the language switcher adds a searchable
99
+ * select next to its tabs. Default `8` (from MapoDetailLangSwitch); `0`
100
+ * always shows it.
101
+ */
102
+ langThreshold?: number;
38
103
  /** Human readable model name shown in the page title. */
39
104
  modelName?: string | null;
40
105
  /** Sidebar column span (1–11 in a 12-col grid). */
@@ -51,13 +116,16 @@ const props = withDefaults(
51
116
  * Enable automatic draft persistence to localStorage.
52
117
  * When `true`, the key is auto-generated as `${endpoint}:${id}`.
53
118
  * Provide `draftKey` to override with a custom key.
54
- * Drafts expire after 24 h. The built-in banner handles restore/discard.
119
+ * Drafts are kept per user, leave out the fields marked `noDraft`, and
120
+ * expire after 24 h. A new record is saved as a draft once it holds a
121
+ * value. The built-in banner handles restore/discard.
55
122
  */
56
123
  draft?: boolean;
57
124
  /**
58
- * Custom localStorage key for draft persistence. Requires `draft: true`.
59
- * Key is prefixed with `mapo:draft:`.
60
- * Example: `"article:42"` → `mapo:draft:article:42`.
125
+ * Custom localStorage key for draft persistence; setting it also turns
126
+ * drafts on. Key is prefixed with `mapo:draft:` and the signed-in
127
+ * user's id (`anonymous` without one).
128
+ * Example: `"article:42"` → `mapo:draft:1:article:42` for the user with id `1`.
61
129
  * Falls back to `${endpoint}:${id}` when omitted.
62
130
  */
63
131
  draftKey?: string;
@@ -86,10 +154,26 @@ const props = withDefaults(
86
154
  * the auto-derived list.
87
155
  */
88
156
  forceLanguages?: string[];
157
+ /**
158
+ * Marks shown next to the field labels and counted on the tabs, in the body
159
+ * and in the sidebar forms, keyed by the path of the value (`title`,
160
+ * `translations.it.title`, `blocks.0.title`). See `MapoForm`.
161
+ */
162
+ annotations?: FieldAnnotations;
163
+ /**
164
+ * Which extensions registered with `defineDetailExtension()` the page
165
+ * shows: all (`true`), none (`false`) or the listed keys.
166
+ */
167
+ extensions?: boolean | string[];
89
168
  }>(),
90
169
  {
170
+ fields: undefined,
171
+ experimentalFieldsFromSchema: false,
172
+ schemaFromMetadata: undefined,
173
+ schemaFieldOptions: undefined,
91
174
  sidebarFields: () => [],
92
175
  languages: () => [],
176
+ langThreshold: undefined,
93
177
  sidebarCols: 4,
94
178
  sticky: true,
95
179
  usePatch: true,
@@ -102,6 +186,8 @@ const props = withDefaults(
102
186
  permissionModel: undefined,
103
187
  previewField: undefined,
104
188
  forceLanguages: undefined,
189
+ annotations: undefined,
190
+ extensions: true,
105
191
  },
106
192
  );
107
193
 
@@ -128,9 +214,11 @@ const { $mapoFormRegistry } = useNuxtApp() as unknown as {
128
214
  };
129
215
  const registry = computed(() => props.registry ?? $mapoFormRegistry);
130
216
 
217
+ const { t } = useI18n();
131
218
  const router = useRouter();
132
219
  const snack = useSnackStore();
133
220
  const confirm = useConfirmStore();
221
+ const auth = useAuthStore();
134
222
  const crud = useCrud<T>(props.endpoint);
135
223
 
136
224
  type ValidateClientFn = () => {
@@ -147,6 +235,31 @@ provide("mapoDetailRegisterValidator", (fn: ValidateClientFn) => {
147
235
  };
148
236
  });
149
237
 
238
+ // Each form inside, the body's and the sidebar's, a slot's own included,
239
+ // brings its fields into view: `revealField()` asks them in turn.
240
+ type RevealFieldFn = (path: string) => Promise<boolean>;
241
+ const formRevealers: RevealFieldFn[] = [];
242
+
243
+ provide("mapoDetailRegisterReveal", (fn: RevealFieldFn) => {
244
+ formRevealers.push(fn);
245
+ return () => {
246
+ const at = formRevealers.indexOf(fn);
247
+ if (at >= 0) formRevealers.splice(at, 1);
248
+ };
249
+ });
250
+
251
+ /**
252
+ * Brings a field into view through the form that holds it: its tab, group
253
+ * and repeater item open, and its control takes the focus. A form without
254
+ * the field answers `false` at once, so the next one is asked.
255
+ */
256
+ async function revealField(path: string): Promise<boolean> {
257
+ for (const reveal of [...formRevealers]) {
258
+ if (await reveal(path)) return true;
259
+ }
260
+ return false;
261
+ }
262
+
150
263
  const isNew = computed(() => String(props.id) === "new");
151
264
  // Cast keeps the generic exact: `ref<T>` would expose `UnwrapRef<T>`, which
152
265
  // TS cannot prove to extend `object` when forwarding to MapoForm.
@@ -161,8 +274,21 @@ const errors = ref<Record<string, string[]>>({});
161
274
  // Start in loading state for existing items so MapoForm is never mounted with
162
275
  // empty data and then immediately unmounted when the spinner appears on mount.
163
276
  const isLoading = ref(String(props.id) !== "new");
164
- const isSaving = ref(false);
165
- const isDeleting = ref(false);
277
+
278
+ /**
279
+ * The action under way, from the click until its work is done, navigation
280
+ * included: one at a time, so a second click cannot save again or go back one
281
+ * more step in the history. Named after the buttons.
282
+ */
283
+ type DetailAction = "save" | "saveContinue" | "delete" | "back";
284
+ const pendingAction = ref<DetailAction | null>(null);
285
+ const isBusy = computed(() => pendingAction.value !== null);
286
+ const isSaving = computed(() => {
287
+ const savingAndLeaving = pendingAction.value === "save";
288
+ const savingAndStaying = pendingAction.value === "saveContinue";
289
+ return savingAndLeaving || savingAndStaying;
290
+ });
291
+ const isDeleting = computed(() => pendingAction.value === "delete");
166
292
  const currentLang = ref(props.languages[0] ?? "");
167
293
  const draftBanner = ref<{
168
294
  savedAt: Date;
@@ -170,17 +296,34 @@ const draftBanner = ref<{
170
296
  discard: () => void;
171
297
  } | null>(null);
172
298
 
173
- const isDirty = computed(
174
- () =>
175
- backup.value !== null &&
176
- Object.keys(objectDiff(backup.value, model.value)).length > 0,
177
- );
299
+ /**
300
+ * What a new record held when the page opened, as the page and the
301
+ * components inside it set it up: none of it is the operator's change.
302
+ */
303
+ const opened = ref<T | null>(null);
304
+
305
+ /**
306
+ * The record differs from the one loaded or last saved. A new record has
307
+ * none to differ from: it counts as changed once it holds a value it did
308
+ * not hold when the page opened, so it gets a draft and the warnings on
309
+ * leaving, as an existing record does.
310
+ */
311
+ const isDirty = computed(() => {
312
+ if (backup.value !== null) {
313
+ return Object.keys(objectDiff(backup.value, model.value)).length > 0;
314
+ }
315
+ if (!isNew.value) return false;
316
+ const start = opened.value ?? ({} as T);
317
+ return holdsFormValue(objectDiff(start, model.value));
318
+ });
178
319
  const mainCols = computed(() => 12 - props.sidebarCols);
179
320
 
180
321
  // ─── Languages (auto-derive from lang_info) ──────────────────────────────────
181
- // Backends like Camomilla embed site_languages inside the fetched model.
182
- // We read them after the first successful fetch so the host page doesn't need
183
- // to hard-code the language list. forceLanguages > props.languages > derived.
322
+ // Camomilla describes the MODEL's language situation in the endpoint's OPTIONS
323
+ // metadata, so the host page doesn't hard-code a language list — and a model
324
+ // that is not registered for translation shows no switcher at all, rather than
325
+ // tabs whose extra values the backend would drop.
326
+ // forceLanguages > props.languages > derived.
184
327
  const derivedLangs = ref<string[]>([]);
185
328
  const activeLangs = computed<string[]>(() => {
186
329
  if (props.forceLanguages?.length) return props.forceLanguages;
@@ -261,13 +404,32 @@ const sidebarColsClass = computed(
261
404
 
262
405
  const DRAFT_TTL = 86_400_000; // 24h
263
406
 
264
- function draftStorageKey() {
407
+ /** The page's own key of the draft, without the prefix; `null` with drafts off. */
408
+ function draftName(): string | null {
265
409
  if (!props.draft && !props.draftKey) return null;
266
- const key = props.draftKey ?? `${props.endpoint}:${props.id}`;
267
- return `mapo:draft:${key}`;
410
+ return props.draftKey ?? `${props.endpoint}:${props.id}`;
411
+ }
412
+
413
+ /** Where the draft is kept: one per user, so accounts on a browser never share one. */
414
+ function draftStorageKey(): string | null {
415
+ const name = draftName();
416
+ if (name === null) return null;
417
+ const userId = auth.info?.id ?? "anonymous";
418
+ return `mapo:draft:${userId}:${name}`;
419
+ }
420
+
421
+ /**
422
+ * Removes a draft kept before drafts were kept per user: nobody can say
423
+ * whose it is, so it is never offered.
424
+ */
425
+ function removeUnownedDraft(): void {
426
+ const name = draftName();
427
+ if (name === null) return;
428
+ localStorage.removeItem(`mapo:draft:${name}`);
268
429
  }
269
430
 
270
431
  function clearDraft() {
432
+ unclaimedParts.clear();
271
433
  const key = draftStorageKey();
272
434
  if (key && typeof localStorage !== "undefined") localStorage.removeItem(key);
273
435
  }
@@ -276,9 +438,14 @@ function checkDraft() {
276
438
  const key = draftStorageKey();
277
439
  if (!key || typeof localStorage === "undefined") return;
278
440
  try {
441
+ removeUnownedDraft();
279
442
  const raw = localStorage.getItem(key);
280
443
  if (!raw) return;
281
- const entry = JSON.parse(raw) as { model: T; savedAt: number };
444
+ const entry = JSON.parse(raw) as {
445
+ model: T;
446
+ savedAt: number;
447
+ parts?: unknown;
448
+ };
282
449
  if (Date.now() - entry.savedAt > DRAFT_TTL) {
283
450
  localStorage.removeItem(key);
284
451
  return;
@@ -286,6 +453,7 @@ function checkDraft() {
286
453
  const savedAt = new Date(entry.savedAt);
287
454
  const restore = () => {
288
455
  Object.assign(model.value, entry.model);
456
+ restoreParts(entry.parts);
289
457
  draftBanner.value = null;
290
458
  };
291
459
  const discard = () => {
@@ -299,28 +467,157 @@ function checkDraft() {
299
467
  }
300
468
  }
301
469
 
470
+ // ─── Draft parts ─────────────────────────────────────────────────────────────
471
+ // A component inside the detail keeps a state of its own in the draft, beside
472
+ // the record's values: the context's `draft`.
473
+
474
+ const draftParts = new Map<string, MapoDetailDraftPart>();
475
+ /** Data of a restored draft whose part was not there yet: it gets it when it comes. */
476
+ const unclaimedParts = new Map<string, unknown>();
477
+
478
+ function addDraftPart(key: string, part: MapoDetailDraftPart): () => void {
479
+ draftParts.set(key, part);
480
+ if (unclaimedParts.has(key)) {
481
+ const data = unclaimedParts.get(key);
482
+ unclaimedParts.delete(key);
483
+ restorePart(part, data);
484
+ }
485
+ const remove = () => {
486
+ if (draftParts.get(key) === part) draftParts.delete(key);
487
+ };
488
+ if (getCurrentScope()) onScopeDispose(remove);
489
+ return remove;
490
+ }
491
+
492
+ function restorePart(part: MapoDetailDraftPart, data: unknown): void {
493
+ try {
494
+ part.restore(data);
495
+ } catch {
496
+ // A component's failure leaves the record's values restored.
497
+ }
498
+ }
499
+
500
+ /**
501
+ * Puts back each part of a restored draft, as read from the storage: a
502
+ * part the draft holds nothing for starts again from nothing.
503
+ */
504
+ function restoreParts(parts: unknown): void {
505
+ const isRecord =
506
+ typeof parts === "object" && parts !== null && !Array.isArray(parts);
507
+ const kept = new Map(isRecord ? Object.entries(parts) : []);
508
+ for (const [key, part] of draftParts) {
509
+ restorePart(part, kept.get(key));
510
+ kept.delete(key);
511
+ }
512
+ for (const [key, data] of kept) unclaimedParts.set(key, data);
513
+ }
514
+
515
+ /** What the parts keep, by key; `undefined` when none keeps anything. */
516
+ function keptParts(): Record<string, unknown> | undefined {
517
+ const kept: Record<string, unknown> = {};
518
+ for (const [key, part] of draftParts) {
519
+ let data: unknown;
520
+ try {
521
+ data = part.save();
522
+ } catch {
523
+ continue;
524
+ }
525
+ if (data !== undefined) kept[key] = data;
526
+ }
527
+ return Object.keys(kept).length > 0 ? kept : undefined;
528
+ }
529
+
530
+ /** Saves the draft two seconds after the last change; nothing with drafts off. */
531
+ let saveDraftSoon: () => void = () => {};
532
+
302
533
  // Auto-save draft debounced whenever model changes and form is dirty.
303
534
  if (props.draft || props.draftKey) {
535
+ /** This page wrote the draft: once nothing is left to keep, it goes. */
536
+ let isWritten = false;
304
537
  const saveDraft = debounce(() => {
305
538
  const key = draftStorageKey();
306
- if (!key || !isDirty.value || typeof localStorage === "undefined") return;
539
+ if (!key || typeof localStorage === "undefined") return;
307
540
  try {
308
- localStorage.setItem(
309
- key,
310
- JSON.stringify({ model: toRaw(model.value), savedAt: Date.now() }),
311
- );
541
+ const parts = keptParts();
542
+ // Back as loaded, and no part keeps anything: a draft written by an
543
+ // earlier visit stays on offer, the one this page wrote goes.
544
+ const hasParts = parts !== undefined;
545
+ if (!isDirty.value && !hasParts) {
546
+ if (isWritten) localStorage.removeItem(key);
547
+ isWritten = false;
548
+ return;
549
+ }
550
+ // The fields marked `noDraft` hold nothing in the draft, at any path.
551
+ const fields = [...activeFields.value, ...(props.sidebarFields ?? [])];
552
+ const values = modelForDraft(toRaw(model.value), fields);
553
+ const entry = { model: values, savedAt: Date.now(), parts };
554
+ localStorage.setItem(key, JSON.stringify(entry));
555
+ isWritten = true;
312
556
  } catch {
313
- /* quota exceeded — ignore */
557
+ /* quota exceeded, or a value with no JSON form — ignore */
314
558
  }
315
559
  }, 2000);
316
560
  watch(model, saveDraft, { deep: true });
561
+ saveDraftSoon = () => saveDraft();
317
562
  }
318
563
 
319
564
  // ─── Fetch ───────────────────────────────────────────────────────────────────
320
565
 
566
+ /**
567
+ * Body fields derived from the OPTIONS schema; empty unless opted in.
568
+ *
569
+ * shallowRef, not ref: the array is replaced wholesale, never mutated in place,
570
+ * and deep reactivity over descriptors (which carry functions) buys nothing.
571
+ * It also keeps the generic intact — ref()'s UnwrapRef erases the T in
572
+ * `key: DeepKeyOf<T>`.
573
+ */
574
+ const derivedFields = shallowRef<AnyFieldDescriptor<T>[]>([]);
575
+
576
+ /**
577
+ * The fields actually rendered. An explicit `fields` prop always wins — the
578
+ * derived set is a scaffold, never an override of a hand-built form.
579
+ */
580
+ const activeFields = computed<AnyFieldDescriptor<T>[]>(() =>
581
+ props.fields?.length ? props.fields : derivedFields.value,
582
+ );
583
+
584
+ /**
585
+ * Ask the endpoint to describe itself, ONCE, and take from that answer both the
586
+ * languages and (when opted in) the fields.
587
+ *
588
+ * Runs for existing records as well as new ones: the metadata lives on OPTIONS
589
+ * only, so reading the fetched record would leave an edit form with no tabs.
590
+ */
591
+ async function describeEndpoint() {
592
+ const wantsLangs = !props.languages.length && !props.forceLanguages?.length;
593
+ const wantsFields =
594
+ props.experimentalFieldsFromSchema && !props.fields?.length;
595
+ if (!wantsLangs && !wantsFields) return;
596
+
597
+ const metadata = await describe();
598
+ // A backend without OPTIONS metadata is not an error worth surfacing: it
599
+ // just means nothing is auto-derived.
600
+ if (!metadata) return;
601
+
602
+ if (wantsLangs) derivedLangs.value = languagesFromMetadata(metadata);
603
+ if (wantsFields) {
604
+ const toSchema = props.schemaFromMetadata ?? metadataToJsonSchema;
605
+ const schema = toSchema(metadata);
606
+ if (schema?.properties) {
607
+ derivedFields.value = useFormFromSchema(
608
+ schema,
609
+ props.schemaFieldOptions,
610
+ ) as AnyFieldDescriptor<T>[];
611
+ }
612
+ }
613
+ }
614
+
321
615
  async function fetchModel() {
322
616
  if (isNew.value) {
323
617
  backup.value = null;
618
+ // The components inside are set up by now: what they and the page put
619
+ // in is where the record starts.
620
+ opened.value = deepClone(model.value) as T;
324
621
  checkDraft();
325
622
  return;
326
623
  }
@@ -328,35 +625,47 @@ async function fetchModel() {
328
625
  try {
329
626
  model.value = await crud.detail(props.id);
330
627
  backup.value = deepClone(model.value) as T;
331
- // Auto-derive languages from the backend response when the host page does
332
- // not hard-code them. Camomilla embeds site_languages inside lang_info.
333
- const langInfo = (model.value as Record<string, unknown>)?.lang_info as
334
- | Record<string, unknown>
335
- | undefined;
336
- const siteLangs = langInfo?.site_languages as string[] | undefined;
337
- if (
338
- siteLangs?.length &&
339
- !props.languages.length &&
340
- !props.forceLanguages?.length
341
- ) {
342
- derivedLangs.value = siteLangs;
343
- }
344
628
  checkDraft();
345
629
  } catch (err: unknown) {
346
- const status = (err as { response?: { status?: number } })?.response
347
- ?.status;
348
- const detail = (err as { response?: { data?: { detail?: string } } })
349
- ?.response?.data?.detail;
350
- snack.show(detail ?? "Failed to load item", "error");
351
- if (status === 404) router.back();
630
+ snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
631
+ if (getErrorStatus(err) === 404) router.back();
352
632
  } finally {
353
633
  isLoading.value = false;
354
634
  }
355
635
  }
356
636
 
637
+ // ─── Saved ───────────────────────────────────────────────────────────────────
638
+ // The components inside hear of each save that succeeds before the page
639
+ // moves: a new record's page gives way to the record's own address.
640
+
641
+ const savedHandlers = new Set<(record: T) => void>();
642
+
643
+ function onSaved(handler: (record: T) => void): () => void {
644
+ savedHandlers.add(handler);
645
+ const remove = () => {
646
+ savedHandlers.delete(handler);
647
+ };
648
+ if (getCurrentScope()) onScopeDispose(remove);
649
+ return remove;
650
+ }
651
+
652
+ function notifySaved(record: T): void {
653
+ for (const handler of [...savedHandlers]) {
654
+ try {
655
+ handler(record);
656
+ } catch {
657
+ // A component's failure leaves the save done.
658
+ }
659
+ }
660
+ }
661
+
357
662
  // ─── Save ────────────────────────────────────────────────────────────────────
358
663
 
359
664
  async function save(andBack = false) {
665
+ // The built-in buttons are disabled meanwhile; a custom one bound to `save`
666
+ // may not be.
667
+ if (isBusy.value) return;
668
+
360
669
  const validationResults = formValidators.map((fn) => fn());
361
670
  const allValid = validationResults.every((r) => r.valid);
362
671
  if (!allValid) {
@@ -365,13 +674,14 @@ async function save(andBack = false) {
365
674
  );
366
675
  const message = fieldErrors.length
367
676
  ? fieldErrors.map(([field, msg]) => `${field}: ${msg}`).join("\n")
368
- : "Please fix the errors before saving.";
677
+ : t("mapo.fixErrors");
369
678
  snack.show(message, "error");
370
679
  return;
371
680
  }
372
681
 
373
682
  errors.value = {};
374
- isSaving.value = true;
683
+ pendingAction.value = andBack ? "save" : "saveContinue";
684
+ let leaving = false;
375
685
  try {
376
686
  const multipartOpts = { multipart: props.multipart };
377
687
  let result: T;
@@ -397,22 +707,21 @@ async function save(andBack = false) {
397
707
  backup.value = deepClone(model.value) as T;
398
708
  clearDraft();
399
709
  snack.show(
400
- isNew.value ? "Created successfully" : "Saved successfully",
710
+ isNew.value ? t("mapo.createSuccess") : t("mapo.saveSuccess"),
401
711
  "success",
402
712
  );
403
713
  emit("saved", model.value);
714
+ notifySaved(model.value);
404
715
  if (isNew.value && result && "id" in result) {
405
716
  const id = (result as unknown as { id: string | number }).id;
406
717
  await router.replace({
407
718
  params: { id },
408
719
  });
409
720
  }
410
- if (andBack) back();
721
+ if (andBack) leaving = leave();
411
722
  } catch (err: unknown) {
412
- const response = (err as { response?: { status?: number; data?: unknown } })
413
- ?.response;
414
- const data = response?.data;
415
- if (response?.status === 400 && data && typeof data === "object") {
723
+ const data = getErrorData(err);
724
+ if (getErrorStatus(err) === 400 && data && typeof data === "object") {
416
725
  errors.value = data as Record<string, string[]>;
417
726
  // Field-level errors: the useMapoForm watcher shows the detailed toast.
418
727
  // Only surface a toast here if the response carries a top-level detail message.
@@ -420,10 +729,11 @@ async function save(andBack = false) {
420
729
  if (detail) snack.show(detail, "error");
421
730
  } else {
422
731
  const detail = (data as { detail?: string } | undefined)?.detail;
423
- snack.show(detail ?? "Failed to save", "error");
732
+ snack.show(detail ?? t("mapo.saveError"), "error");
424
733
  }
425
734
  } finally {
426
- isSaving.value = false;
735
+ // Going back: still busy until the page is gone (see leave()).
736
+ if (!leaving) pendingAction.value = null;
427
737
  }
428
738
  }
429
739
 
@@ -435,42 +745,68 @@ function getPatch(): Partial<T> {
435
745
  // ─── Delete ──────────────────────────────────────────────────────────────────
436
746
 
437
747
  async function deleteItem() {
748
+ if (isBusy.value) return;
438
749
  const ok = await confirm.ask({
439
- title: "Delete",
440
- message:
441
- "Are you sure you want to delete this item? This action cannot be undone.",
442
- confirmText: "Delete",
750
+ title: t("mapo.delete"),
751
+ message: t("mapo.detail.deleteQuestion"),
752
+ confirmText: t("mapo.delete"),
443
753
  dangerous: true,
444
754
  });
445
755
  if (!ok) return;
446
- isDeleting.value = true;
756
+ pendingAction.value = "delete";
757
+ let leaving = false;
447
758
  try {
448
759
  await crud.delete(recordId());
449
760
  backup.value = deepClone(model.value) as T; // clear dirty so guard doesn't fire
450
- snack.show("Deleted successfully", "success");
761
+ snack.show(t("mapo.deleteSuccess"), "success");
451
762
  emit("deleted");
452
- back();
763
+ leaving = leave();
453
764
  } catch (err: unknown) {
454
- const detail = (err as { response?: { data?: { detail?: string } } })
455
- ?.response?.data?.detail;
456
- snack.show(detail ?? "Failed to delete", "error");
765
+ snack.show(getErrorDetail(err) ?? t("mapo.deleteError"), "error");
457
766
  } finally {
458
- isDeleting.value = false;
767
+ if (!leaving) pendingAction.value = null;
459
768
  }
460
769
  }
461
770
 
462
771
  // ─── Navigation guard ────────────────────────────────────────────────────────
463
772
 
464
773
  function back() {
774
+ if (isBusy.value) return;
775
+ pendingAction.value = "back";
776
+ const leaving = leave();
777
+ if (!leaving) pendingAction.value = null;
778
+ }
779
+
780
+ /**
781
+ * Goes back one step and tells whether that is a navigation inside the app.
782
+ *
783
+ * router.back() does not wait for the navigation, and this page stays on screen
784
+ * until the previous route is ready. So the caller keeps its action pending
785
+ * until the page is gone; if the navigation fails (a guard kept the page, such
786
+ * as the unsaved-changes one), the action is released and the buttons work
787
+ * again.
788
+ */
789
+ function leave(): boolean {
790
+ // Opened directly (a new tab, a bookmark): no page of the app to go back to,
791
+ // router.back() leaves the app or does nothing, and nothing would release
792
+ // the buttons.
793
+ const hasPreviousPage = router.options.history.state.back != null;
794
+ if (hasPreviousPage) {
795
+ const stopWatching = router.afterEach((_to, _from, failure) => {
796
+ stopWatching();
797
+ if (failure) pendingAction.value = null;
798
+ });
799
+ }
465
800
  router.back();
801
+ return hasPreviousPage;
466
802
  }
467
803
 
468
804
  async function guardUnsaved(): Promise<boolean> {
469
805
  if (!isDirty.value) return true;
470
806
  return confirm.ask({
471
- title: "Unsaved changes",
472
- message: "You have unsaved changes. Do you want to leave without saving?",
473
- confirmText: "Leave",
807
+ title: t("mapo.unsavedData"),
808
+ message: t("mapo.confirmLeaveChanges"),
809
+ confirmText: t("mapo.leave"),
474
810
  dangerous: true,
475
811
  });
476
812
  }
@@ -497,6 +833,9 @@ onMounted(() => {
497
833
  preventWindowClose,
498
834
  );
499
835
  }
836
+ // Independent of the record fetch: languages come from OPTIONS either way,
837
+ // and a new record has no fetch to piggyback on.
838
+ describeEndpoint();
500
839
  fetchModel();
501
840
  });
502
841
 
@@ -512,6 +851,61 @@ onBeforeUnmount(() => {
512
851
  }
513
852
  });
514
853
 
854
+ // ─── Context ─────────────────────────────────────────────────────────────────
855
+ // What the components inside the detail read with useMapoDetail(): its slots,
856
+ // its forms and the extensions registered with defineDetailExtension().
857
+
858
+ /** Marks set from inside the detail; the `annotations` prop wins on a path. */
859
+ const innerAnnotations = ref<FieldAnnotations>({});
860
+ const formAnnotations = computed<FieldAnnotations>(() => ({
861
+ ...innerAnnotations.value,
862
+ ...(props.annotations ?? {}),
863
+ }));
864
+
865
+ let metadataRequest: Promise<Record<string, unknown> | undefined> | undefined;
866
+
867
+ /** The endpoint's OPTIONS response, requested once and shared. */
868
+ function describe(): Promise<Record<string, unknown> | undefined> {
869
+ metadataRequest ??= crud.options().then(
870
+ (response) =>
871
+ typeof response === "object" && response !== null
872
+ ? (response as Record<string, unknown>)
873
+ : undefined,
874
+ () => undefined,
875
+ );
876
+ return metadataRequest;
877
+ }
878
+
879
+ const context: MapoDetailContext<T> = {
880
+ endpoint: computed(() => props.endpoint),
881
+ id: computed(() => props.id),
882
+ isNew,
883
+ modelName: computed(() => props.modelName ?? null),
884
+ permissionModel: computed(() => props.permissionModel),
885
+ model,
886
+ fields: activeFields,
887
+ sidebarFields: computed(() => props.sidebarFields ?? []),
888
+ languages: activeLangs,
889
+ currentLang,
890
+ registry,
891
+ errors,
892
+ readonly: effectiveReadonly,
893
+ isLoading,
894
+ isSaving,
895
+ isBusy,
896
+ isDirty,
897
+ annotations: innerAnnotations,
898
+ extensions: computed(() => props.extensions),
899
+ save,
900
+ back,
901
+ metadata: describe,
902
+ schemaFromMetadata: computed(() => props.schemaFromMetadata),
903
+ onSaved,
904
+ draft: { part: addDraftPart, touch: () => saveDraftSoon() },
905
+ revealField,
906
+ };
907
+ provide(DETAIL_KEY, context as unknown as MapoDetailContext);
908
+
515
909
  // ─── Slot bindings ───────────────────────────────────────────────────────────
516
910
 
517
911
  // Forward field-level (`field.*`), group-level (`group.*`) and tab-level (`tab.*`,
@@ -530,6 +924,8 @@ const formSlotNames = computed(() =>
530
924
 
531
925
  const slotBindings = computed(() => ({
532
926
  model: model.value,
927
+ fields: activeFields.value,
928
+ sidebarFields: props.sidebarFields ?? [],
533
929
  errors: errors.value,
534
930
  currentLang: currentLang.value,
535
931
  isNew: isNew.value,
@@ -553,18 +949,27 @@ type DraftBannerState = {
553
949
 
554
950
  type SlotBindings = {
555
951
  model: T;
952
+ /** The body fields rendered: the `fields` prop, or the ones derived from the schema. */
953
+ fields: AnyFieldDescriptor<T>[];
954
+ /** The sidebar fields rendered. */
955
+ sidebarFields: AnyFieldDescriptor<T>[];
556
956
  errors: Record<string, string[]>;
557
957
  currentLang: string;
558
958
  isNew: boolean;
559
959
  isLoading: boolean;
960
+ /** From the click until the save is done; after `save(true)`, until the page has gone back. */
560
961
  isSaving: boolean;
962
+ /** From the confirmation until the delete is done and the page has gone back. */
561
963
  isDeleting: boolean;
562
964
  isDirty: boolean;
563
965
  draftBanner: DraftBannerState;
564
966
  readonly: boolean;
565
967
  canDelete: boolean;
968
+ /** Ignored while a save, a delete or a navigation back is under way. */
566
969
  save: (andBack?: boolean) => Promise<void>;
970
+ /** Ignored while a save, a delete or a navigation back is under way. */
567
971
  deleteItem: () => Promise<void>;
972
+ /** Ignored while a save, a delete or a navigation back is under way. */
568
973
  back: () => void;
569
974
  };
570
975
 
@@ -576,7 +981,9 @@ defineSlots<{
576
981
  /**
577
982
  * Draft restore banner shown when a localStorage draft is found.
578
983
  * Receives `draftBanner` (with `savedAt`, `restore`, `discard`) plus the full slot bindings.
579
- * Override to render a completely custom banner; set to an empty slot to suppress it.
984
+ * Override to render a completely custom banner. To hide it, render an
985
+ * element of your own, such as `<span hidden />`: a slot that gives no
986
+ * element, an empty one included, renders the built-in banner.
580
987
  */
581
988
  "draft-banner"(props: SlotBindings): VNode[];
582
989
  /** Extra content above the main form. */
@@ -601,7 +1008,9 @@ defineSlots<{
601
1008
  "side-bottom"(props: SlotBindings): VNode[];
602
1009
  /**
603
1010
  * Danger-zone card at the very bottom of the sidebar (delete action).
604
- * Rendered only for existing records (`!isNew`). Override to replace or suppress it.
1011
+ * Rendered only for existing records (`!isNew`). Override to replace it;
1012
+ * to hide it, render an element of your own, such as `<span hidden />`: a
1013
+ * slot that gives no element, an empty one included, renders the built-in card.
605
1014
  */
606
1015
  "side-danger"(props: SlotBindings): VNode[];
607
1016
  /** Per-field slot. Slot name: `field.{key}`, `field.{key}.before`, `field.{key}.after`. */
@@ -636,12 +1045,16 @@ defineSlots<{
636
1045
  color="warning"
637
1046
  variant="subtle"
638
1047
  class="mb-3"
639
- :title="`Unsaved draft found — last edited ${draftBanner.savedAt.toLocaleString()}`"
640
- description="You have a local draft that was not saved. Do you want to restore it or discard it?"
1048
+ :title="
1049
+ t('mapo.detail.draftSavedAt', {
1050
+ date: draftBanner.savedAt.toLocaleString(),
1051
+ })
1052
+ "
1053
+ :description="t('mapo.detail.draftFound')"
641
1054
  >
642
1055
  <template #actions>
643
1056
  <UButton size="xs" color="warning" @click="draftBanner?.restore()">
644
- Restore draft
1057
+ {{ t("mapo.restore") }}
645
1058
  </UButton>
646
1059
  <UButton
647
1060
  size="xs"
@@ -649,7 +1062,7 @@ defineSlots<{
649
1062
  variant="ghost"
650
1063
  @click="draftBanner?.discard()"
651
1064
  >
652
- Discard
1065
+ {{ t("mapo.discard") }}
653
1066
  </UButton>
654
1067
  </template>
655
1068
  </UAlert>
@@ -659,7 +1072,7 @@ defineSlots<{
659
1072
  <!-- Title -->
660
1073
  <slot name="title" v-bind="slotBindings">
661
1074
  <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-6">
662
- {{ isNew ? "New" : "Edit" }}
1075
+ {{ isNew ? t("mapo.new") : t("mapo.edit") }}
663
1076
  <span v-if="modelName"> {{ modelName }}</span>
664
1077
  </h1>
665
1078
  </slot>
@@ -674,21 +1087,25 @@ defineSlots<{
674
1087
  v-model="currentLang"
675
1088
  :langs="activeLangs"
676
1089
  :errors="errors"
1090
+ :lang-threshold="langThreshold"
677
1091
  />
678
1092
  </slot>
679
1093
 
1094
+ <MapoDetailExtensions placement="body-top" />
1095
+
680
1096
  <slot name="body-top" v-bind="slotBindings" />
681
1097
 
682
1098
  <!-- Main form -->
683
1099
  <slot name="body" v-bind="slotBindings">
684
1100
  <MapoForm
685
1101
  v-model="model"
686
- :fields="fields"
1102
+ :fields="activeFields"
687
1103
  :errors="errors"
688
1104
  :languages="activeLangs"
689
1105
  :current-lang="currentLang"
690
1106
  :registry="registry"
691
1107
  :readonly="effectiveReadonly"
1108
+ :annotations="formAnnotations"
692
1109
  >
693
1110
  <template
694
1111
  v-for="slotName in formSlotNames"
@@ -706,19 +1123,23 @@ defineSlots<{
706
1123
  <!-- Sidebar column -->
707
1124
  <div :class="sidebarColsClass">
708
1125
  <div :style="sidebarStyle" class="space-y-4">
709
- <!-- Action buttons (Save / Save&continue / Back — no delete here) -->
1126
+ <!-- Action buttons (Save / Save&continue / Back — no delete here).
1127
+ While one works, it spins and all of them are disabled. -->
710
1128
  <slot name="side-buttons" v-bind="slotBindings">
711
1129
  <UCard>
712
1130
  <div class="flex flex-col gap-2">
1131
+ <MapoDetailExtensions placement="actions" />
1132
+
713
1133
  <slot name="button-save" v-bind="slotBindings">
714
1134
  <UButton
715
1135
  v-if="!effectiveReadonly"
716
1136
  block
717
- :loading="isSaving"
1137
+ :loading="pendingAction === 'save'"
1138
+ :disabled="isBusy"
718
1139
  icon="i-lucide-save"
719
1140
  @click="save(true)"
720
1141
  >
721
- {{ isNew ? "Create" : "Save" }}
1142
+ {{ isNew ? t("mapo.create") : t("mapo.save") }}
722
1143
  </UButton>
723
1144
  </slot>
724
1145
 
@@ -727,11 +1148,14 @@ defineSlots<{
727
1148
  v-if="!effectiveReadonly"
728
1149
  block
729
1150
  variant="soft"
730
- :loading="isSaving"
1151
+ :loading="pendingAction === 'saveContinue'"
1152
+ :disabled="isBusy"
731
1153
  icon="i-lucide-save"
732
1154
  @click="save(false)"
733
1155
  >
734
- {{ isNew ? "Create and continue" : "Save and continue" }}
1156
+ {{
1157
+ isNew ? t("mapo.createContinue") : t("mapo.saveContinue")
1158
+ }}
735
1159
  </UButton>
736
1160
  </slot>
737
1161
 
@@ -740,9 +1164,11 @@ defineSlots<{
740
1164
  block
741
1165
  variant="ghost"
742
1166
  icon="i-lucide-arrow-left"
1167
+ :loading="pendingAction === 'back'"
1168
+ :disabled="isBusy"
743
1169
  @click="back"
744
1170
  >
745
- Back
1171
+ {{ t("mapo.back") }}
746
1172
  </UButton>
747
1173
  </slot>
748
1174
  </div>
@@ -764,6 +1190,8 @@ defineSlots<{
764
1190
  :current-lang="currentLang"
765
1191
  :registry="registry"
766
1192
  :readonly="effectiveReadonly"
1193
+ :annotations="formAnnotations"
1194
+ :notify-errors="false"
767
1195
  >
768
1196
  <template
769
1197
  v-for="slotName in formSlotNames"
@@ -783,6 +1211,8 @@ defineSlots<{
783
1211
  :current-lang="currentLang"
784
1212
  :registry="registry"
785
1213
  :readonly="effectiveReadonly"
1214
+ :annotations="formAnnotations"
1215
+ :notify-errors="false"
786
1216
  >
787
1217
  <template
788
1218
  v-for="slotName in formSlotNames"
@@ -805,7 +1235,7 @@ defineSlots<{
805
1235
  icon="i-lucide-eye"
806
1236
  @click="previewOpen = true"
807
1237
  >
808
- Preview
1238
+ {{ t("mapo.preview") }}
809
1239
  </UButton>
810
1240
 
811
1241
  <!-- Danger zone: delete action, visually separated from save actions -->
@@ -817,10 +1247,11 @@ defineSlots<{
817
1247
  color="error"
818
1248
  variant="soft"
819
1249
  :loading="isDeleting"
1250
+ :disabled="isBusy"
820
1251
  icon="i-lucide-trash-2"
821
1252
  @click="deleteItem"
822
1253
  >
823
- Delete
1254
+ {{ t("mapo.delete") }}
824
1255
  </UButton>
825
1256
  </slot>
826
1257
  </UCard>