@mapomodule/uikit 2.0.0-beta.1 β†’ 2.0.0-beta.11

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 (200) hide show
  1. package/README.md +33 -1
  2. package/dist/__tests__/langInfo.test.d.ts +2 -0
  3. package/dist/__tests__/langInfo.test.d.ts.map +1 -0
  4. package/dist/index.d.mts +5 -2
  5. package/dist/index.d.ts +6 -2
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.mjs +1 -18
  8. package/dist/module.d.mts +60 -2
  9. package/dist/module.d.ts +55 -2
  10. package/dist/module.d.ts.map +1 -0
  11. package/dist/module.json +1 -1
  12. package/dist/module.mjs +174 -13
  13. package/dist/runtime/adapters/defaultMediaAdapter.d.ts +14 -0
  14. package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
  15. package/dist/runtime/adapters/defaultMediaAdapter.js +30 -0
  16. package/dist/runtime/assets/main.css +1 -0
  17. package/dist/runtime/components/MapoConfirmDialog.vue +35 -0
  18. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts +4 -0
  19. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -0
  20. package/dist/runtime/components/MapoDetail.vue +632 -0
  21. package/dist/runtime/components/MapoDetail.vue.d.ts +422 -0
  22. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -0
  23. package/dist/runtime/components/MapoDetailLangSwitch.vue +126 -0
  24. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +23 -0
  25. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -0
  26. package/dist/runtime/components/MapoDropArea.vue +99 -0
  27. package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
  28. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
  29. package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
  30. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
  31. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
  32. package/dist/runtime/components/MapoList.vue +191 -0
  33. package/dist/runtime/components/MapoList.vue.d.ts +111 -0
  34. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -0
  35. package/dist/runtime/components/MapoListActions.vue +119 -0
  36. package/dist/runtime/components/MapoListActions.vue.d.ts +33 -0
  37. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -0
  38. package/dist/runtime/components/MapoListFilters.vue +246 -0
  39. package/dist/runtime/components/MapoListFilters.vue.d.ts +38 -0
  40. package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -0
  41. package/dist/runtime/components/MapoListHead.vue +9 -0
  42. package/dist/runtime/components/MapoListHead.vue.d.ts +14 -0
  43. package/dist/runtime/components/MapoListHead.vue.d.ts.map +1 -0
  44. package/dist/runtime/components/MapoListQuickEdit.vue +123 -0
  45. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts +47 -0
  46. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -0
  47. package/dist/runtime/components/MapoListTable.vue +665 -0
  48. package/dist/runtime/components/MapoListTable.vue.d.ts +105 -0
  49. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -0
  50. package/dist/runtime/components/MapoListTabs.vue +38 -0
  51. package/dist/runtime/components/MapoListTabs.vue.d.ts +26 -0
  52. package/dist/runtime/components/MapoListTabs.vue.d.ts.map +1 -0
  53. package/dist/runtime/components/MapoLogin.vue +196 -0
  54. package/dist/runtime/components/MapoLogin.vue.d.ts +22 -0
  55. package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -0
  56. package/dist/runtime/components/MapoLogoutButton.vue +27 -0
  57. package/dist/runtime/components/MapoLogoutButton.vue.d.ts +29 -0
  58. package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -0
  59. package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
  60. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
  61. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
  62. package/dist/runtime/components/MapoMediaEditor.vue +320 -0
  63. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +8 -0
  64. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
  65. package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
  66. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
  67. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
  68. package/dist/runtime/components/MapoMediaFolders.vue +220 -0
  69. package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
  70. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
  71. package/dist/runtime/components/MapoMediaGallery.vue +219 -0
  72. package/dist/runtime/components/MapoMediaGallery.vue.d.ts +4 -0
  73. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
  74. package/dist/runtime/components/MapoMediaManager.vue +140 -0
  75. package/dist/runtime/components/MapoMediaManager.vue.d.ts +35 -0
  76. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
  77. package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
  78. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
  79. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
  80. package/dist/runtime/components/MapoMediaPreview.vue +92 -0
  81. package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
  82. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
  83. package/dist/runtime/components/MapoMediaUploader.vue +290 -0
  84. package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
  85. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
  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/MapoRootComponents.vue +9 -0
  99. package/dist/runtime/components/MapoRootComponents.vue.d.ts +4 -0
  100. package/dist/runtime/components/MapoRootComponents.vue.d.ts.map +1 -0
  101. package/dist/runtime/components/MapoSidebar.vue +89 -0
  102. package/dist/runtime/components/MapoSidebar.vue.d.ts +22 -0
  103. package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -0
  104. package/dist/runtime/components/MapoSidebarList.vue +27 -0
  105. package/dist/runtime/components/MapoSidebarList.vue.d.ts +8 -0
  106. package/dist/runtime/components/MapoSidebarList.vue.d.ts.map +1 -0
  107. package/dist/runtime/components/MapoSidebarListItem.vue +74 -0
  108. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts +9 -0
  109. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts.map +1 -0
  110. package/dist/runtime/components/MapoSidebarProfile.vue +55 -0
  111. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts +10 -0
  112. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -0
  113. package/dist/runtime/components/MapoSnackBar.vue +38 -0
  114. package/dist/runtime/components/MapoSnackBar.vue.d.ts +4 -0
  115. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -0
  116. package/dist/runtime/components/MapoThemeToggle.vue +23 -0
  117. package/dist/runtime/components/MapoThemeToggle.vue.d.ts +4 -0
  118. package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -0
  119. package/dist/runtime/components/MapoTopbar.vue +30 -0
  120. package/dist/runtime/components/MapoTopbar.vue.d.ts +15 -0
  121. package/dist/runtime/components/MapoTopbar.vue.d.ts.map +1 -0
  122. package/dist/runtime/components/menuDndContext.d.ts +19 -0
  123. package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
  124. package/dist/runtime/components/menuDndContext.js +3 -0
  125. package/dist/runtime/layouts/default.vue +43 -0
  126. package/dist/runtime/layouts/default.vue.d.ts +20 -0
  127. package/dist/runtime/layouts/default.vue.d.ts.map +1 -0
  128. package/dist/runtime/layouts/empty.vue +9 -0
  129. package/dist/runtime/layouts/empty.vue.d.ts +14 -0
  130. package/dist/runtime/layouts/empty.vue.d.ts.map +1 -0
  131. package/dist/runtime/page-meta.nuxt.d.ts +45 -0
  132. package/dist/runtime/pages/index.vue +14 -0
  133. package/dist/runtime/pages/index.vue.d.ts +4 -0
  134. package/dist/runtime/pages/index.vue.d.ts.map +1 -0
  135. package/dist/runtime/pages/login.vue +3 -0
  136. package/dist/runtime/pages/login.vue.d.ts +4 -0
  137. package/dist/runtime/pages/login.vue.d.ts.map +1 -0
  138. package/dist/runtime/plugins/media-adapter.d.ts +18 -0
  139. package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
  140. package/dist/runtime/plugins/media-adapter.js +8 -0
  141. package/dist/runtime/stores/media.d.ts +462 -0
  142. package/dist/runtime/stores/media.d.ts.map +1 -0
  143. package/dist/runtime/stores/media.js +344 -0
  144. package/dist/runtime/types/list.d.ts +59 -0
  145. package/dist/runtime/types/list.d.ts.map +1 -0
  146. package/dist/runtime/types/list.js +0 -0
  147. package/dist/runtime/types/media.d.ts +116 -0
  148. package/dist/runtime/types/media.d.ts.map +1 -0
  149. package/dist/runtime/types/media.js +0 -0
  150. package/dist/runtime/types/menu.d.ts +66 -0
  151. package/dist/runtime/types/menu.d.ts.map +1 -0
  152. package/dist/runtime/types/menu.js +30 -0
  153. package/dist/runtime/utils/langInfo.d.ts +30 -0
  154. package/dist/runtime/utils/langInfo.d.ts.map +1 -0
  155. package/dist/runtime/utils/langInfo.js +8 -0
  156. package/dist/types.d.mts +6 -10
  157. package/package.json +15 -11
  158. package/src/__tests__/langInfo.test.ts +48 -0
  159. package/src/index.ts +20 -0
  160. package/src/module.ts +130 -0
  161. package/src/runtime/adapters/defaultMediaAdapter.ts +57 -0
  162. package/src/runtime/components/MapoConfirmDialog.vue +5 -3
  163. package/src/runtime/components/MapoDetail.vue +130 -55
  164. package/src/runtime/components/MapoDetailLangSwitch.vue +1 -1
  165. package/src/runtime/components/MapoDropArea.vue +127 -0
  166. package/src/runtime/components/MapoLangSwitcher.vue +74 -0
  167. package/src/runtime/components/MapoList.vue +1 -1
  168. package/src/runtime/components/MapoListActions.vue +16 -10
  169. package/src/runtime/components/MapoListFilters.vue +5 -2
  170. package/src/runtime/components/MapoListQuickEdit.vue +12 -9
  171. package/src/runtime/components/MapoListTable.vue +26 -21
  172. package/src/runtime/components/MapoLogin.vue +13 -10
  173. package/src/runtime/components/MapoLogoutButton.vue +4 -2
  174. package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
  175. package/src/runtime/components/MapoMediaEditor.vue +350 -0
  176. package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
  177. package/src/runtime/components/MapoMediaFolders.vue +239 -0
  178. package/src/runtime/components/MapoMediaGallery.vue +239 -0
  179. package/src/runtime/components/MapoMediaManager.vue +180 -0
  180. package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
  181. package/src/runtime/components/MapoMediaPreview.vue +111 -0
  182. package/src/runtime/components/MapoMediaUploader.vue +351 -0
  183. package/src/runtime/components/MapoMenuManager.vue +437 -0
  184. package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
  185. package/src/runtime/components/MapoMenuTreeview.vue +264 -0
  186. package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
  187. package/src/runtime/components/MapoSidebar.vue +3 -1
  188. package/src/runtime/components/MapoSidebarList.vue +1 -1
  189. package/src/runtime/components/MapoSidebarProfile.vue +6 -2
  190. package/src/runtime/components/MapoThemeToggle.vue +5 -1
  191. package/src/runtime/components/menuDndContext.ts +22 -0
  192. package/src/runtime/pages/index.vue +4 -3
  193. package/src/runtime/pages/login.vue +0 -4
  194. package/src/runtime/plugins/media-adapter.ts +33 -0
  195. package/src/runtime/stores/media.ts +474 -0
  196. package/src/runtime/types/media.ts +126 -0
  197. package/src/runtime/types/menu.ts +105 -0
  198. package/src/runtime/utils/langInfo.ts +38 -0
  199. package/dist/index.d.cts +0 -2
  200. package/dist/module.d.cts +0 -2
@@ -10,15 +10,25 @@ import {
10
10
  provide,
11
11
  type Ref,
12
12
  type VNode,
13
+ shallowRef,
13
14
  } from "vue";
14
- import { useRouter, onBeforeRouteLeave } from "vue-router";
15
- import { useNuxtApp } from "#app";
15
+ import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
16
+ import { useI18n } from "vue-i18n";
16
17
  import { objectDiff, debounce, deepClone } from "@mapomodule/utils";
17
18
  import { useCrud } from "@mapomodule/core/runtime/api/crud";
19
+ import {
20
+ getErrorData,
21
+ getErrorDetail,
22
+ getErrorStatus,
23
+ } from "@mapomodule/core/runtime/utils/fetchError";
18
24
  import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
19
25
  import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
20
26
  import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
21
27
  import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
28
+ import { languagesFromMetadata } from "../utils/langInfo";
29
+ import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
30
+ import type { UseFormFromSchemaOptions } from "@mapomodule/form/runtime/composables/useFormFromSchema";
31
+ import type { JSONSchema } from "@mapomodule/utils";
22
32
  import type { MultipartPolicy } from "@mapomodule/core";
23
33
 
24
34
  // ─── Props ────────────────────────────────────────────────────────────────────
@@ -29,8 +39,28 @@ const props = withDefaults(
29
39
  endpoint: string;
30
40
  /** Record id. Pass `'new'` to create. */
31
41
  id: string | number;
32
- /** Fields for the main body form. */
33
- fields: AnyFieldDescriptor<T>[];
42
+ /**
43
+ * Fields for the main body form.
44
+ *
45
+ * Optional only so `experimentalFieldsFromSchema` can supply them; pass them
46
+ * explicitly for any form you care about the layout of.
47
+ */
48
+ fields?: AnyFieldDescriptor<T>[];
49
+ /**
50
+ * EXPERIMENTAL. Build the body fields from the endpoint's OPTIONS schema
51
+ * when `fields` is not given.
52
+ *
53
+ * Off by default and deliberately opt-in: a derived form knows types,
54
+ * labels, relations and what is read-only, but nothing editorial β€” no tabs,
55
+ * no column widths, no rich-text vs textarea, no sidebar split, and no
56
+ * opinion about field order beyond the serializer's. Treat it as a
57
+ * scaffold to start from, not a finished panel.
58
+ *
59
+ * Requires a backend that publishes `schema` on OPTIONS (camomilla >= 6.6).
60
+ */
61
+ experimentalFieldsFromSchema?: boolean;
62
+ /** Passed straight to useFormFromSchema when deriving. */
63
+ schemaFieldOptions?: UseFormFromSchemaOptions;
34
64
  /** Fields for the sidebar form (optional). */
35
65
  sidebarFields?: AnyFieldDescriptor<T>[];
36
66
  /** Translation language codes (e.g. ['it', 'en']). */
@@ -88,6 +118,9 @@ const props = withDefaults(
88
118
  forceLanguages?: string[];
89
119
  }>(),
90
120
  {
121
+ fields: undefined,
122
+ experimentalFieldsFromSchema: false,
123
+ schemaFieldOptions: undefined,
91
124
  sidebarFields: () => [],
92
125
  languages: () => [],
93
126
  sidebarCols: 4,
@@ -128,6 +161,7 @@ const { $mapoFormRegistry } = useNuxtApp() as unknown as {
128
161
  };
129
162
  const registry = computed(() => props.registry ?? $mapoFormRegistry);
130
163
 
164
+ const { t } = useI18n();
131
165
  const router = useRouter();
132
166
  const snack = useSnackStore();
133
167
  const confirm = useConfirmStore();
@@ -178,9 +212,11 @@ const isDirty = computed(
178
212
  const mainCols = computed(() => 12 - props.sidebarCols);
179
213
 
180
214
  // ─── 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.
215
+ // Camomilla describes the MODEL's language situation in the endpoint's OPTIONS
216
+ // metadata, so the host page doesn't hard-code a language list β€” and a model
217
+ // that is not registered for translation shows no switcher at all, rather than
218
+ // tabs whose extra values the backend would drop.
219
+ // forceLanguages > props.languages > derived.
184
220
  const derivedLangs = ref<string[]>([]);
185
221
  const activeLangs = computed<string[]>(() => {
186
222
  if (props.forceLanguages?.length) return props.forceLanguages;
@@ -318,6 +354,58 @@ if (props.draft || props.draftKey) {
318
354
 
319
355
  // ─── Fetch ───────────────────────────────────────────────────────────────────
320
356
 
357
+ /**
358
+ * Body fields derived from the OPTIONS schema; empty unless opted in.
359
+ *
360
+ * shallowRef, not ref: the array is replaced wholesale, never mutated in place,
361
+ * and deep reactivity over descriptors (which carry functions) buys nothing.
362
+ * It also keeps the generic intact β€” ref()'s UnwrapRef erases the T in
363
+ * `key: DeepKeyOf<T>`.
364
+ */
365
+ const derivedFields = shallowRef<AnyFieldDescriptor<T>[]>([]);
366
+
367
+ /**
368
+ * The fields actually rendered. An explicit `fields` prop always wins β€” the
369
+ * derived set is a scaffold, never an override of a hand-built form.
370
+ */
371
+ const activeFields = computed<AnyFieldDescriptor<T>[]>(() =>
372
+ props.fields?.length ? props.fields : derivedFields.value,
373
+ );
374
+
375
+ /**
376
+ * Ask the endpoint to describe itself, ONCE, and take from that answer both the
377
+ * languages and (when opted in) the fields.
378
+ *
379
+ * Runs for existing records as well as new ones: the metadata lives on OPTIONS
380
+ * only, so reading the fetched record would leave an edit form with no tabs.
381
+ */
382
+ async function describeEndpoint() {
383
+ const wantsLangs = !props.languages.length && !props.forceLanguages?.length;
384
+ const wantsFields =
385
+ props.experimentalFieldsFromSchema && !props.fields?.length;
386
+ if (!wantsLangs && !wantsFields) return;
387
+
388
+ let metadata: Record<string, unknown>;
389
+ try {
390
+ metadata = (await crud.options()) as Record<string, unknown>;
391
+ } catch {
392
+ // A backend without OPTIONS metadata is not an error worth surfacing: it
393
+ // just means nothing is auto-derived.
394
+ return;
395
+ }
396
+
397
+ if (wantsLangs) derivedLangs.value = languagesFromMetadata(metadata);
398
+ if (wantsFields) {
399
+ const schema = metadata.schema as JSONSchema | undefined;
400
+ if (schema?.properties) {
401
+ derivedFields.value = useFormFromSchema(
402
+ schema,
403
+ props.schemaFieldOptions,
404
+ ) as AnyFieldDescriptor<T>[];
405
+ }
406
+ }
407
+ }
408
+
321
409
  async function fetchModel() {
322
410
  if (isNew.value) {
323
411
  backup.value = null;
@@ -328,27 +416,10 @@ async function fetchModel() {
328
416
  try {
329
417
  model.value = await crud.detail(props.id);
330
418
  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
419
  checkDraft();
345
420
  } 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();
421
+ snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
422
+ if (getErrorStatus(err) === 404) router.back();
352
423
  } finally {
353
424
  isLoading.value = false;
354
425
  }
@@ -365,7 +436,7 @@ async function save(andBack = false) {
365
436
  );
366
437
  const message = fieldErrors.length
367
438
  ? fieldErrors.map(([field, msg]) => `${field}: ${msg}`).join("\n")
368
- : "Please fix the errors before saving.";
439
+ : t("mapo.fixErrors");
369
440
  snack.show(message, "error");
370
441
  return;
371
442
  }
@@ -397,7 +468,7 @@ async function save(andBack = false) {
397
468
  backup.value = deepClone(model.value) as T;
398
469
  clearDraft();
399
470
  snack.show(
400
- isNew.value ? "Created successfully" : "Saved successfully",
471
+ isNew.value ? t("mapo.createSuccess") : t("mapo.saveSuccess"),
401
472
  "success",
402
473
  );
403
474
  emit("saved", model.value);
@@ -409,10 +480,8 @@ async function save(andBack = false) {
409
480
  }
410
481
  if (andBack) back();
411
482
  } 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") {
483
+ const data = getErrorData(err);
484
+ if (getErrorStatus(err) === 400 && data && typeof data === "object") {
416
485
  errors.value = data as Record<string, string[]>;
417
486
  // Field-level errors: the useMapoForm watcher shows the detailed toast.
418
487
  // Only surface a toast here if the response carries a top-level detail message.
@@ -420,7 +489,7 @@ async function save(andBack = false) {
420
489
  if (detail) snack.show(detail, "error");
421
490
  } else {
422
491
  const detail = (data as { detail?: string } | undefined)?.detail;
423
- snack.show(detail ?? "Failed to save", "error");
492
+ snack.show(detail ?? t("mapo.saveError"), "error");
424
493
  }
425
494
  } finally {
426
495
  isSaving.value = false;
@@ -436,10 +505,9 @@ function getPatch(): Partial<T> {
436
505
 
437
506
  async function deleteItem() {
438
507
  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",
508
+ title: t("mapo.delete"),
509
+ message: t("mapo.detail.deleteQuestion"),
510
+ confirmText: t("mapo.delete"),
443
511
  dangerous: true,
444
512
  });
445
513
  if (!ok) return;
@@ -447,13 +515,11 @@ async function deleteItem() {
447
515
  try {
448
516
  await crud.delete(recordId());
449
517
  backup.value = deepClone(model.value) as T; // clear dirty so guard doesn't fire
450
- snack.show("Deleted successfully", "success");
518
+ snack.show(t("mapo.deleteSuccess"), "success");
451
519
  emit("deleted");
452
520
  back();
453
521
  } catch (err: unknown) {
454
- const detail = (err as { response?: { data?: { detail?: string } } })
455
- ?.response?.data?.detail;
456
- snack.show(detail ?? "Failed to delete", "error");
522
+ snack.show(getErrorDetail(err) ?? t("mapo.deleteError"), "error");
457
523
  } finally {
458
524
  isDeleting.value = false;
459
525
  }
@@ -468,9 +534,9 @@ function back() {
468
534
  async function guardUnsaved(): Promise<boolean> {
469
535
  if (!isDirty.value) return true;
470
536
  return confirm.ask({
471
- title: "Unsaved changes",
472
- message: "You have unsaved changes. Do you want to leave without saving?",
473
- confirmText: "Leave",
537
+ title: t("mapo.unsavedData"),
538
+ message: t("mapo.confirmLeaveChanges"),
539
+ confirmText: t("mapo.leave"),
474
540
  dangerous: true,
475
541
  });
476
542
  }
@@ -497,6 +563,9 @@ onMounted(() => {
497
563
  preventWindowClose,
498
564
  );
499
565
  }
566
+ // Independent of the record fetch: languages come from OPTIONS either way,
567
+ // and a new record has no fetch to piggyback on.
568
+ describeEndpoint();
500
569
  fetchModel();
501
570
  });
502
571
 
@@ -636,12 +705,16 @@ defineSlots<{
636
705
  color="warning"
637
706
  variant="subtle"
638
707
  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?"
708
+ :title="
709
+ t('mapo.detail.draftSavedAt', {
710
+ date: draftBanner.savedAt.toLocaleString(),
711
+ })
712
+ "
713
+ :description="t('mapo.detail.draftFound')"
641
714
  >
642
715
  <template #actions>
643
716
  <UButton size="xs" color="warning" @click="draftBanner?.restore()">
644
- Restore draft
717
+ {{ t("mapo.restore") }}
645
718
  </UButton>
646
719
  <UButton
647
720
  size="xs"
@@ -649,7 +722,7 @@ defineSlots<{
649
722
  variant="ghost"
650
723
  @click="draftBanner?.discard()"
651
724
  >
652
- Discard
725
+ {{ t("mapo.discard") }}
653
726
  </UButton>
654
727
  </template>
655
728
  </UAlert>
@@ -659,7 +732,7 @@ defineSlots<{
659
732
  <!-- Title -->
660
733
  <slot name="title" v-bind="slotBindings">
661
734
  <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-6">
662
- {{ isNew ? "New" : "Edit" }}
735
+ {{ isNew ? t("mapo.new") : t("mapo.edit") }}
663
736
  <span v-if="modelName"> {{ modelName }}</span>
664
737
  </h1>
665
738
  </slot>
@@ -683,7 +756,7 @@ defineSlots<{
683
756
  <slot name="body" v-bind="slotBindings">
684
757
  <MapoForm
685
758
  v-model="model"
686
- :fields="fields"
759
+ :fields="activeFields"
687
760
  :errors="errors"
688
761
  :languages="activeLangs"
689
762
  :current-lang="currentLang"
@@ -718,7 +791,7 @@ defineSlots<{
718
791
  icon="i-lucide-save"
719
792
  @click="save(true)"
720
793
  >
721
- {{ isNew ? "Create" : "Save" }}
794
+ {{ isNew ? t("mapo.create") : t("mapo.save") }}
722
795
  </UButton>
723
796
  </slot>
724
797
 
@@ -731,7 +804,9 @@ defineSlots<{
731
804
  icon="i-lucide-save"
732
805
  @click="save(false)"
733
806
  >
734
- {{ isNew ? "Create and continue" : "Save and continue" }}
807
+ {{
808
+ isNew ? t("mapo.createContinue") : t("mapo.saveContinue")
809
+ }}
735
810
  </UButton>
736
811
  </slot>
737
812
 
@@ -742,7 +817,7 @@ defineSlots<{
742
817
  icon="i-lucide-arrow-left"
743
818
  @click="back"
744
819
  >
745
- Back
820
+ {{ t("mapo.back") }}
746
821
  </UButton>
747
822
  </slot>
748
823
  </div>
@@ -805,7 +880,7 @@ defineSlots<{
805
880
  icon="i-lucide-eye"
806
881
  @click="previewOpen = true"
807
882
  >
808
- Preview
883
+ {{ t("mapo.preview") }}
809
884
  </UButton>
810
885
 
811
886
  <!-- Danger zone: delete action, visually separated from save actions -->
@@ -820,7 +895,7 @@ defineSlots<{
820
895
  icon="i-lucide-trash-2"
821
896
  @click="deleteItem"
822
897
  >
823
- Delete
898
+ {{ t("mapo.delete") }}
824
899
  </UButton>
825
900
  </slot>
826
901
  </UCard>
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { ref, computed, watch, onMounted, nextTick } from "vue";
3
- import { useRoute, useRouter } from "vue-router";
3
+ import { useRoute, useRouter } from "#app";
4
4
 
5
5
  const props = withDefaults(
6
6
  defineProps<{
@@ -0,0 +1,127 @@
1
+ <script setup lang="ts">
2
+ import { ref } from "vue";
3
+ import { useI18n } from "vue-i18n";
4
+
5
+ const { t } = useI18n();
6
+
7
+ const props = withDefaults(
8
+ defineProps<{
9
+ accept?: string;
10
+ multiple?: boolean;
11
+ disabled?: boolean;
12
+ }>(),
13
+ {
14
+ accept: "*/*",
15
+ multiple: true,
16
+ disabled: false,
17
+ },
18
+ );
19
+
20
+ const emit = defineEmits<{
21
+ files: [files: File[]];
22
+ }>();
23
+
24
+ const isDragging = ref(false);
25
+ const fileInput = ref<HTMLInputElement | null>(null);
26
+ let dragCounter = 0;
27
+
28
+ function onDragEnter(e: DragEvent) {
29
+ if (props.disabled) return;
30
+ e.preventDefault();
31
+ dragCounter++;
32
+ isDragging.value = true;
33
+ }
34
+
35
+ function onDragLeave() {
36
+ dragCounter--;
37
+ if (dragCounter <= 0) {
38
+ dragCounter = 0;
39
+ isDragging.value = false;
40
+ }
41
+ }
42
+
43
+ function onDrop(e: DragEvent) {
44
+ if (props.disabled) return;
45
+ isDragging.value = false;
46
+ dragCounter = 0;
47
+ const files = filterFiles(Array.from(e.dataTransfer?.files ?? []));
48
+ if (files.length) emit("files", files);
49
+ }
50
+
51
+ function onFileInput(e: Event) {
52
+ const input = e.target as HTMLInputElement;
53
+ const files = filterFiles(Array.from(input.files ?? []));
54
+ if (files.length) emit("files", files);
55
+ input.value = "";
56
+ }
57
+
58
+ function triggerPick() {
59
+ if (!props.disabled) fileInput.value?.click();
60
+ }
61
+
62
+ function filterFiles(files: File[]): File[] {
63
+ if (!props.accept || props.accept === "*/*") return files;
64
+ return files.filter((f) => matchesMime(f.type, props.accept));
65
+ }
66
+
67
+ function matchesMime(mime: string, accept: string): boolean {
68
+ return accept.split(",").some((pattern) => {
69
+ const p = pattern.trim();
70
+ if (p === "*/*") return true;
71
+ if (p.endsWith("/*")) return mime.startsWith(p.replace("/*", "/"));
72
+ return mime === p;
73
+ });
74
+ }
75
+
76
+ defineExpose({ triggerPick });
77
+ </script>
78
+
79
+ <template>
80
+ <div
81
+ class="mapo-drop-area relative"
82
+ :class="{
83
+ 'mapo-drop-area--dragging': isDragging,
84
+ 'opacity-50 pointer-events-none': disabled,
85
+ }"
86
+ @dragenter.prevent="onDragEnter"
87
+ @dragover.prevent
88
+ @dragleave="onDragLeave"
89
+ @drop.prevent="onDrop"
90
+ >
91
+ <input
92
+ ref="fileInput"
93
+ type="file"
94
+ class="sr-only"
95
+ :accept="accept"
96
+ :multiple="multiple"
97
+ @change="onFileInput"
98
+ />
99
+
100
+ <slot :trigger-pick="triggerPick" :is-dragging="isDragging" />
101
+
102
+ <Transition name="drop-overlay">
103
+ <div
104
+ v-if="isDragging"
105
+ class="pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-default/80"
106
+ >
107
+ <div class="flex flex-col items-center gap-2 text-primary">
108
+ <UIcon name="i-lucide-upload-cloud" class="size-10" />
109
+ <span class="text-sm font-medium">{{
110
+ t("mapo.dropArea.dropHere")
111
+ }}</span>
112
+ </div>
113
+ </div>
114
+ </Transition>
115
+ </div>
116
+ </template>
117
+
118
+ <style scoped>
119
+ .drop-overlay-enter-active,
120
+ .drop-overlay-leave-active {
121
+ transition: opacity 0.15s ease;
122
+ }
123
+ .drop-overlay-enter-from,
124
+ .drop-overlay-leave-to {
125
+ opacity: 0;
126
+ }
127
+ </style>
@@ -0,0 +1,74 @@
1
+ <script setup lang="ts">
2
+ import { computed } from "vue";
3
+ import type { Ref } from "vue";
4
+ import { useI18n } from "vue-i18n";
5
+
6
+ /**
7
+ * UI locale switcher β€” lists the locales configured in `@nuxtjs/i18n`
8
+ * (via `@mapomodule/i18n`) and switches the interface language with
9
+ * cookie persistence. Port of the v1 `LangSwitcher`.
10
+ */
11
+ const props = withDefaults(
12
+ defineProps<{
13
+ /** Show the flag emoji derived from the locale `language` tag. */
14
+ flags?: boolean;
15
+ /** Nuxt UI USelectMenu `size` prop. */
16
+ size?: "xs" | "sm" | "md" | "lg" | "xl";
17
+ }>(),
18
+ { flags: true, size: "sm" },
19
+ );
20
+
21
+ interface SwitcherLocale {
22
+ code: string;
23
+ name?: string;
24
+ language?: string;
25
+ }
26
+
27
+ // `locales` and `setLocale` are @nuxtjs/i18n Composer extensions; the uikit
28
+ // package only depends on vue-i18n types, so they are typed structurally.
29
+ const { locale, locales, setLocale } = useI18n() as unknown as {
30
+ locale: Ref<string>;
31
+ locales: Ref<SwitcherLocale[]>;
32
+ setLocale: (code: string) => Promise<void>;
33
+ };
34
+
35
+ /** Regional-indicator flag emoji from a BCP-47 tag (e.g. `en-US` β†’ πŸ‡ΊπŸ‡Έ). */
36
+ function getFlag(language?: string): string {
37
+ const region = language?.split("-").at(-1);
38
+ if (!region || region.length !== 2 || !/^[A-Za-z]+$/.test(region)) return "";
39
+ const codePoints = region
40
+ .toUpperCase()
41
+ .split("")
42
+ .map((char) => 127397 + char.charCodeAt(0));
43
+ return String.fromCodePoint(...codePoints);
44
+ }
45
+
46
+ const items = computed(() =>
47
+ locales.value.map((l) => ({
48
+ label:
49
+ props.flags && getFlag(l.language)
50
+ ? `${getFlag(l.language)} ${l.name ?? l.code.toUpperCase()}`
51
+ : (l.name ?? l.code.toUpperCase()),
52
+ value: l.code,
53
+ })),
54
+ );
55
+
56
+ const current = computed({
57
+ get: () => locale.value,
58
+ set: (code: string) => {
59
+ if (code && code !== locale.value) setLocale(code);
60
+ },
61
+ });
62
+ </script>
63
+
64
+ <template>
65
+ <USelectMenu
66
+ v-model="current"
67
+ :items="items"
68
+ value-key="value"
69
+ label-key="label"
70
+ :size="size"
71
+ :search-input="false"
72
+ class="w-40"
73
+ />
74
+ </template>
@@ -11,7 +11,7 @@ import type {
11
11
  } from "../types/list.js";
12
12
  import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
13
13
  import { debounce } from "@mapomodule/utils";
14
- import { useRoute, useRouter } from "vue-router";
14
+ import { useRoute, useRouter } from "#app";
15
15
 
16
16
  const props = withDefaults(
17
17
  defineProps<{
@@ -1,10 +1,12 @@
1
1
  <script setup lang="ts" generic="T extends object">
2
2
  import { ref, computed } from "vue";
3
+ import { useI18n } from "vue-i18n";
3
4
  import type { ActionDescriptor } from "../types/list.js";
4
5
  import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
5
6
  import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
6
7
  import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
7
8
  import { useCrud } from "@mapomodule/core/runtime/api/crud";
9
+ import { getErrorDetail } from "@mapomodule/core/runtime/utils/fetchError";
8
10
 
9
11
  const props = withDefaults(
10
12
  defineProps<{
@@ -29,6 +31,7 @@ defineSlots<{
29
31
  append(): any;
30
32
  }>();
31
33
 
34
+ const { t } = useI18n();
32
35
  const snack = useSnackStore();
33
36
  const confirm = useConfirmStore();
34
37
  const crud = useCrud<T>(props.endpoint);
@@ -37,7 +40,7 @@ const isRunning = ref(false);
37
40
 
38
41
  const defaultActions = computed<ActionDescriptor<T>[]>(() => [
39
42
  {
40
- label: "Delete permanently",
43
+ label: t("mapo.listActions.permanentDelete"),
41
44
  handler: async ({ selection }) => {
42
45
  if (!selection) return;
43
46
  await Promise.all(
@@ -95,9 +98,11 @@ async function runAction() {
95
98
  title: action.label,
96
99
  message:
97
100
  props.selection === "all"
98
- ? "This action will be applied to all items. Do you want to continue?"
99
- : `This action will be applied to ${(props.selection as T[]).length} item(s). Do you want to continue?`,
100
- confirmText: "Confirm",
101
+ ? t("mapo.listActions.confirmBulk")
102
+ : t("mapo.listActions.confirmBulkCount", {
103
+ count: (props.selection as T[]).length,
104
+ }),
105
+ confirmText: t("mapo.confirm"),
101
106
  dangerous: !!action.dangerous,
102
107
  });
103
108
  if (!ok) return;
@@ -109,13 +114,14 @@ async function runAction() {
109
114
  selectionQuery: props.selectionQuery,
110
115
  lookup: props.lookup,
111
116
  });
112
- snack.show("Action completed", "success");
117
+ snack.show(t("mapo.listActions.actionCompleted"), "success");
113
118
  emit("actionCompleted");
114
119
  selectedLabel.value = undefined;
115
120
  } catch (err: unknown) {
116
- const detail = (err as { response?: { data?: { detail?: string } } })
117
- ?.response?.data?.detail;
118
- snack.show(detail ?? "Action failed", "error");
121
+ snack.show(
122
+ getErrorDetail(err) ?? t("mapo.listActions.actionFailed"),
123
+ "error",
124
+ );
119
125
  } finally {
120
126
  isRunning.value = false;
121
127
  }
@@ -134,7 +140,7 @@ const isActive = computed(
134
140
  :items="visibleActions"
135
141
  value-key="label"
136
142
  label-key="label"
137
- placeholder="Bulk actions..."
143
+ :placeholder="t('mapo.listActions.bulkActions')"
138
144
  size="sm"
139
145
  class="min-w-48"
140
146
  />
@@ -145,7 +151,7 @@ const isActive = computed(
145
151
  :disabled="!selectedAction || !canRun(selectedAction)"
146
152
  @click="runAction"
147
153
  >
148
- Apply
154
+ {{ t("mapo.apply") }}
149
155
  </UButton>
150
156
  <slot name="append" />
151
157
  </div>