@mapomodule/uikit 2.0.0-beta.8 → 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 (133) 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 +1 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/module.d.mts +1 -0
  30. package/dist/module.d.ts.map +1 -1
  31. package/dist/module.json +1 -1
  32. package/dist/module.mjs +10 -0
  33. package/dist/runtime/assets/main.css +1 -1
  34. package/dist/runtime/components/MapoConfirmDialog.vue +18 -1
  35. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
  36. package/dist/runtime/components/MapoDetail.vue +263 -33
  37. package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
  38. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
  39. package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
  40. package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
  41. package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
  42. package/dist/runtime/components/MapoDetailLangSwitch.vue +21 -25
  43. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
  44. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
  45. package/dist/runtime/components/MapoDropArea.vue.d.ts +1 -1
  46. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
  47. package/dist/runtime/components/MapoList.vue +7 -3
  48. package/dist/runtime/components/MapoList.vue.d.ts +14 -4
  49. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
  50. package/dist/runtime/components/MapoListActions.vue +12 -5
  51. package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
  52. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
  53. package/dist/runtime/components/MapoListQuickEdit.vue +1 -1
  54. package/dist/runtime/components/MapoListTable.vue +99 -33
  55. package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
  56. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
  57. package/dist/runtime/components/MapoMediaEditor.vue +10 -4
  58. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
  59. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
  60. package/dist/runtime/components/MapoMediaFileChanger.vue +1 -1
  61. package/dist/runtime/components/MapoMediaManager.vue +1 -1
  62. package/dist/runtime/components/MapoMediaManagerDialog.vue +1 -1
  63. package/dist/runtime/components/MapoMediaPreview.vue +1 -1
  64. package/dist/runtime/components/MapoMediaUploader.vue +21 -21
  65. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
  66. package/dist/runtime/components/MapoMenuManager.vue +23 -3
  67. package/dist/runtime/components/MapoMenuManager.vue.d.ts +2 -2
  68. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -1
  69. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +1 -1
  70. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -1
  71. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +2 -2
  72. package/dist/runtime/components/MapoSnackBar.vue +11 -0
  73. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
  74. package/dist/runtime/composables/defineDetailExtension.d.ts +32 -0
  75. package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
  76. package/dist/runtime/composables/defineDetailExtension.js +34 -0
  77. package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
  78. package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
  79. package/dist/runtime/composables/useMapoDetail.js +5 -0
  80. package/dist/runtime/page-meta.nuxt.d.ts +4 -0
  81. package/dist/runtime/stores/media.d.ts +8 -2
  82. package/dist/runtime/stores/media.d.ts.map +1 -1
  83. package/dist/runtime/stores/media.js +16 -0
  84. package/dist/runtime/types/detail.d.ts +167 -0
  85. package/dist/runtime/types/detail.d.ts.map +1 -0
  86. package/dist/runtime/types/detail.js +0 -0
  87. package/dist/runtime/types/list.d.ts +10 -2
  88. package/dist/runtime/types/list.d.ts.map +1 -1
  89. package/dist/runtime/utils/formValues.d.ts +8 -0
  90. package/dist/runtime/utils/formValues.d.ts.map +1 -0
  91. package/dist/runtime/utils/formValues.js +19 -0
  92. package/dist/runtime/utils/langInfo.d.ts +30 -0
  93. package/dist/runtime/utils/langInfo.d.ts.map +1 -0
  94. package/dist/runtime/utils/langInfo.js +8 -0
  95. package/dist/runtime/utils/listTable.d.ts +29 -0
  96. package/dist/runtime/utils/listTable.d.ts.map +1 -0
  97. package/dist/runtime/utils/listTable.js +21 -0
  98. package/package.json +7 -8
  99. package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
  100. package/src/__tests__/MapoDetail.component.test.ts +1107 -0
  101. package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
  102. package/src/__tests__/MapoListActions.component.test.ts +175 -0
  103. package/src/__tests__/MapoListTable.component.test.ts +504 -0
  104. package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
  105. package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
  106. package/src/__tests__/formValues.test.ts +31 -0
  107. package/src/__tests__/langInfo.test.ts +48 -0
  108. package/src/__tests__/listTable.test.ts +82 -0
  109. package/src/__tests__/mediaLanguages.test.ts +66 -0
  110. package/src/__tests__/runtimePages.test.ts +17 -0
  111. package/src/index.ts +8 -0
  112. package/src/module.ts +12 -0
  113. package/src/runtime/assets/main.css +13 -0
  114. package/src/runtime/components/MapoConfirmDialog.vue +28 -1
  115. package/src/runtime/components/MapoDetail.vue +481 -53
  116. package/src/runtime/components/MapoDetailExtensions.vue +39 -0
  117. package/src/runtime/components/MapoDetailLangSwitch.vue +26 -27
  118. package/src/runtime/components/MapoList.vue +20 -5
  119. package/src/runtime/components/MapoListActions.vue +16 -4
  120. package/src/runtime/components/MapoListTable.vue +128 -41
  121. package/src/runtime/components/MapoMediaEditor.vue +17 -4
  122. package/src/runtime/components/MapoMediaUploader.vue +25 -21
  123. package/src/runtime/components/MapoMenuManager.vue +38 -3
  124. package/src/runtime/components/MapoSnackBar.vue +12 -0
  125. package/src/runtime/composables/defineDetailExtension.ts +78 -0
  126. package/src/runtime/composables/useMapoDetail.ts +24 -0
  127. package/src/runtime/page-meta.nuxt.d.ts +4 -0
  128. package/src/runtime/stores/media.ts +32 -0
  129. package/src/runtime/types/detail.ts +178 -0
  130. package/src/runtime/types/list.ts +10 -2
  131. package/src/runtime/utils/formValues.ts +28 -0
  132. package/src/runtime/utils/langInfo.ts +38 -0
  133. package/src/runtime/utils/listTable.ts +54 -0
@@ -7,11 +7,19 @@ import {
7
7
  useSlots,
8
8
  onMounted,
9
9
  onBeforeUnmount,
10
- provide
10
+ provide,
11
+ shallowRef,
12
+ getCurrentScope,
13
+ onScopeDispose
11
14
  } from "vue";
12
15
  import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
13
16
  import { useI18n } from "vue-i18n";
14
- import { objectDiff, debounce, deepClone } from "@mapomodule/utils";
17
+ import {
18
+ objectDiff,
19
+ debounce,
20
+ deepClone,
21
+ metadataToJsonSchema
22
+ } from "@mapomodule/utils";
15
23
  import { useCrud } from "@mapomodule/core/runtime/api/crud";
16
24
  import {
17
25
  getErrorData,
@@ -20,25 +28,37 @@ import {
20
28
  } from "@mapomodule/core/runtime/utils/fetchError";
21
29
  import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
22
30
  import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
31
+ import { useAuthStore } from "@mapomodule/store/runtime/stores/auth";
23
32
  import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
33
+ import { languagesFromMetadata } from "../utils/langInfo";
34
+ import { holdsFormValue } from "../utils/formValues";
35
+ import { DETAIL_KEY } from "../composables/useMapoDetail";
36
+ import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
37
+ import { modelForDraft } from "@mapomodule/form/runtime/utils/draft";
24
38
  const props = defineProps({
25
39
  endpoint: { type: String, required: true },
26
40
  id: { type: [String, Number], required: true },
27
- fields: { type: Array, required: true },
41
+ fields: { type: Array, required: false, default: void 0 },
42
+ experimentalFieldsFromSchema: { type: Boolean, required: false, default: false },
43
+ schemaFromMetadata: { type: Function, required: false, default: void 0 },
44
+ schemaFieldOptions: { type: Object, required: false, default: void 0 },
28
45
  sidebarFields: { type: Array, required: false, default: () => [] },
29
46
  languages: { type: Array, required: false, default: () => [] },
47
+ langThreshold: { type: Number, required: false, default: void 0 },
30
48
  modelName: { type: [String, null], required: false, default: null },
31
49
  sidebarCols: { type: Number, required: false, default: 4 },
32
50
  sticky: { type: Boolean, required: false, default: true },
33
51
  usePatch: { type: Boolean, required: false, default: true },
34
52
  readonly: { type: Boolean, required: false, default: false },
35
- registry: { type: null, required: false, default: null },
53
+ registry: { type: [Object, null], required: false, default: null },
36
54
  draft: { type: Boolean, required: false, default: false },
37
55
  draftKey: { type: String, required: false, default: void 0 },
38
56
  multipart: { type: null, required: false, default: "auto" },
39
57
  permissionModel: { type: String, required: false, default: void 0 },
40
58
  previewField: { type: String, required: false, default: void 0 },
41
- forceLanguages: { type: Array, required: false, default: void 0 }
59
+ forceLanguages: { type: Array, required: false, default: void 0 },
60
+ annotations: { type: Object, required: false, default: void 0 },
61
+ extensions: { type: [Boolean, Array], required: false, default: true }
42
62
  });
43
63
  const emit = defineEmits(["saved", "deleted", "draft-found"]);
44
64
  const { $mapoFormRegistry } = useNuxtApp();
@@ -47,6 +67,7 @@ const { t } = useI18n();
47
67
  const router = useRouter();
48
68
  const snack = useSnackStore();
49
69
  const confirm = useConfirmStore();
70
+ const auth = useAuthStore();
50
71
  const crud = useCrud(props.endpoint);
51
72
  const formValidators = [];
52
73
  provide("mapoDetailRegisterValidator", (fn) => {
@@ -56,6 +77,20 @@ provide("mapoDetailRegisterValidator", (fn) => {
56
77
  if (idx >= 0) formValidators.splice(idx, 1);
57
78
  };
58
79
  });
80
+ const formRevealers = [];
81
+ provide("mapoDetailRegisterReveal", (fn) => {
82
+ formRevealers.push(fn);
83
+ return () => {
84
+ const at = formRevealers.indexOf(fn);
85
+ if (at >= 0) formRevealers.splice(at, 1);
86
+ };
87
+ });
88
+ async function revealField(path) {
89
+ for (const reveal of [...formRevealers]) {
90
+ if (await reveal(path)) return true;
91
+ }
92
+ return false;
93
+ }
59
94
  const isNew = computed(() => String(props.id) === "new");
60
95
  const model = ref({});
61
96
  function recordId() {
@@ -64,13 +99,25 @@ function recordId() {
64
99
  const backup = ref(null);
65
100
  const errors = ref({});
66
101
  const isLoading = ref(String(props.id) !== "new");
67
- const isSaving = ref(false);
68
- const isDeleting = ref(false);
102
+ const pendingAction = ref(null);
103
+ const isBusy = computed(() => pendingAction.value !== null);
104
+ const isSaving = computed(() => {
105
+ const savingAndLeaving = pendingAction.value === "save";
106
+ const savingAndStaying = pendingAction.value === "saveContinue";
107
+ return savingAndLeaving || savingAndStaying;
108
+ });
109
+ const isDeleting = computed(() => pendingAction.value === "delete");
69
110
  const currentLang = ref(props.languages[0] ?? "");
70
111
  const draftBanner = ref(null);
71
- const isDirty = computed(
72
- () => backup.value !== null && Object.keys(objectDiff(backup.value, model.value)).length > 0
73
- );
112
+ const opened = ref(null);
113
+ const isDirty = computed(() => {
114
+ if (backup.value !== null) {
115
+ return Object.keys(objectDiff(backup.value, model.value)).length > 0;
116
+ }
117
+ if (!isNew.value) return false;
118
+ const start = opened.value ?? {};
119
+ return holdsFormValue(objectDiff(start, model.value));
120
+ });
74
121
  const mainCols = computed(() => 12 - props.sidebarCols);
75
122
  const derivedLangs = ref([]);
76
123
  const activeLangs = computed(() => {
@@ -130,12 +177,23 @@ const sidebarColsClass = computed(
130
177
  () => `col-span-12 ${MD_COL_SPAN[props.sidebarCols] ?? "md:col-span-4"}`
131
178
  );
132
179
  const DRAFT_TTL = 864e5;
133
- function draftStorageKey() {
180
+ function draftName() {
134
181
  if (!props.draft && !props.draftKey) return null;
135
- const key = props.draftKey ?? `${props.endpoint}:${props.id}`;
136
- return `mapo:draft:${key}`;
182
+ return props.draftKey ?? `${props.endpoint}:${props.id}`;
183
+ }
184
+ function draftStorageKey() {
185
+ const name = draftName();
186
+ if (name === null) return null;
187
+ const userId = auth.info?.id ?? "anonymous";
188
+ return `mapo:draft:${userId}:${name}`;
189
+ }
190
+ function removeUnownedDraft() {
191
+ const name = draftName();
192
+ if (name === null) return;
193
+ localStorage.removeItem(`mapo:draft:${name}`);
137
194
  }
138
195
  function clearDraft() {
196
+ unclaimedParts.clear();
139
197
  const key = draftStorageKey();
140
198
  if (key && typeof localStorage !== "undefined") localStorage.removeItem(key);
141
199
  }
@@ -143,6 +201,7 @@ function checkDraft() {
143
201
  const key = draftStorageKey();
144
202
  if (!key || typeof localStorage === "undefined") return;
145
203
  try {
204
+ removeUnownedDraft();
146
205
  const raw = localStorage.getItem(key);
147
206
  if (!raw) return;
148
207
  const entry = JSON.parse(raw);
@@ -153,6 +212,7 @@ function checkDraft() {
153
212
  const savedAt = new Date(entry.savedAt);
154
213
  const restore = () => {
155
214
  Object.assign(model.value, entry.model);
215
+ restoreParts(entry.parts);
156
216
  draftBanner.value = null;
157
217
  };
158
218
  const discard = () => {
@@ -164,23 +224,101 @@ function checkDraft() {
164
224
  } catch {
165
225
  }
166
226
  }
227
+ const draftParts = /* @__PURE__ */ new Map();
228
+ const unclaimedParts = /* @__PURE__ */ new Map();
229
+ function addDraftPart(key, part) {
230
+ draftParts.set(key, part);
231
+ if (unclaimedParts.has(key)) {
232
+ const data = unclaimedParts.get(key);
233
+ unclaimedParts.delete(key);
234
+ restorePart(part, data);
235
+ }
236
+ const remove = () => {
237
+ if (draftParts.get(key) === part) draftParts.delete(key);
238
+ };
239
+ if (getCurrentScope()) onScopeDispose(remove);
240
+ return remove;
241
+ }
242
+ function restorePart(part, data) {
243
+ try {
244
+ part.restore(data);
245
+ } catch {
246
+ }
247
+ }
248
+ function restoreParts(parts) {
249
+ const isRecord = typeof parts === "object" && parts !== null && !Array.isArray(parts);
250
+ const kept = new Map(isRecord ? Object.entries(parts) : []);
251
+ for (const [key, part] of draftParts) {
252
+ restorePart(part, kept.get(key));
253
+ kept.delete(key);
254
+ }
255
+ for (const [key, data] of kept) unclaimedParts.set(key, data);
256
+ }
257
+ function keptParts() {
258
+ const kept = {};
259
+ for (const [key, part] of draftParts) {
260
+ let data;
261
+ try {
262
+ data = part.save();
263
+ } catch {
264
+ continue;
265
+ }
266
+ if (data !== void 0) kept[key] = data;
267
+ }
268
+ return Object.keys(kept).length > 0 ? kept : void 0;
269
+ }
270
+ let saveDraftSoon = () => {
271
+ };
167
272
  if (props.draft || props.draftKey) {
273
+ let isWritten = false;
168
274
  const saveDraft = debounce(() => {
169
275
  const key = draftStorageKey();
170
- if (!key || !isDirty.value || typeof localStorage === "undefined") return;
276
+ if (!key || typeof localStorage === "undefined") return;
171
277
  try {
172
- localStorage.setItem(
173
- key,
174
- JSON.stringify({ model: toRaw(model.value), savedAt: Date.now() })
175
- );
278
+ const parts = keptParts();
279
+ const hasParts = parts !== void 0;
280
+ if (!isDirty.value && !hasParts) {
281
+ if (isWritten) localStorage.removeItem(key);
282
+ isWritten = false;
283
+ return;
284
+ }
285
+ const fields = [...activeFields.value, ...props.sidebarFields ?? []];
286
+ const values = modelForDraft(toRaw(model.value), fields);
287
+ const entry = { model: values, savedAt: Date.now(), parts };
288
+ localStorage.setItem(key, JSON.stringify(entry));
289
+ isWritten = true;
176
290
  } catch {
177
291
  }
178
292
  }, 2e3);
179
293
  watch(model, saveDraft, { deep: true });
294
+ saveDraftSoon = () => saveDraft();
295
+ }
296
+ const derivedFields = shallowRef([]);
297
+ const activeFields = computed(
298
+ () => props.fields?.length ? props.fields : derivedFields.value
299
+ );
300
+ async function describeEndpoint() {
301
+ const wantsLangs = !props.languages.length && !props.forceLanguages?.length;
302
+ const wantsFields = props.experimentalFieldsFromSchema && !props.fields?.length;
303
+ if (!wantsLangs && !wantsFields) return;
304
+ const metadata = await describe();
305
+ if (!metadata) return;
306
+ if (wantsLangs) derivedLangs.value = languagesFromMetadata(metadata);
307
+ if (wantsFields) {
308
+ const toSchema = props.schemaFromMetadata ?? metadataToJsonSchema;
309
+ const schema = toSchema(metadata);
310
+ if (schema?.properties) {
311
+ derivedFields.value = useFormFromSchema(
312
+ schema,
313
+ props.schemaFieldOptions
314
+ );
315
+ }
316
+ }
180
317
  }
181
318
  async function fetchModel() {
182
319
  if (isNew.value) {
183
320
  backup.value = null;
321
+ opened.value = deepClone(model.value);
184
322
  checkDraft();
185
323
  return;
186
324
  }
@@ -188,11 +326,6 @@ async function fetchModel() {
188
326
  try {
189
327
  model.value = await crud.detail(props.id);
190
328
  backup.value = deepClone(model.value);
191
- const langInfo = model.value?.lang_info;
192
- const siteLangs = langInfo?.site_languages;
193
- if (siteLangs?.length && !props.languages.length && !props.forceLanguages?.length) {
194
- derivedLangs.value = siteLangs;
195
- }
196
329
  checkDraft();
197
330
  } catch (err) {
198
331
  snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
@@ -201,7 +334,25 @@ async function fetchModel() {
201
334
  isLoading.value = false;
202
335
  }
203
336
  }
337
+ const savedHandlers = /* @__PURE__ */ new Set();
338
+ function onSaved(handler) {
339
+ savedHandlers.add(handler);
340
+ const remove = () => {
341
+ savedHandlers.delete(handler);
342
+ };
343
+ if (getCurrentScope()) onScopeDispose(remove);
344
+ return remove;
345
+ }
346
+ function notifySaved(record) {
347
+ for (const handler of [...savedHandlers]) {
348
+ try {
349
+ handler(record);
350
+ } catch {
351
+ }
352
+ }
353
+ }
204
354
  async function save(andBack = false) {
355
+ if (isBusy.value) return;
205
356
  const validationResults = formValidators.map((fn) => fn());
206
357
  const allValid = validationResults.every((r) => r.valid);
207
358
  if (!allValid) {
@@ -213,7 +364,8 @@ async function save(andBack = false) {
213
364
  return;
214
365
  }
215
366
  errors.value = {};
216
- isSaving.value = true;
367
+ pendingAction.value = andBack ? "save" : "saveContinue";
368
+ let leaving = false;
217
369
  try {
218
370
  const multipartOpts = { multipart: props.multipart };
219
371
  let result;
@@ -243,13 +395,14 @@ async function save(andBack = false) {
243
395
  "success"
244
396
  );
245
397
  emit("saved", model.value);
398
+ notifySaved(model.value);
246
399
  if (isNew.value && result && "id" in result) {
247
400
  const id = result.id;
248
401
  await router.replace({
249
402
  params: { id }
250
403
  });
251
404
  }
252
- if (andBack) back();
405
+ if (andBack) leaving = leave();
253
406
  } catch (err) {
254
407
  const data = getErrorData(err);
255
408
  if (getErrorStatus(err) === 400 && data && typeof data === "object") {
@@ -261,7 +414,7 @@ async function save(andBack = false) {
261
414
  snack.show(detail ?? t("mapo.saveError"), "error");
262
415
  }
263
416
  } finally {
264
- isSaving.value = false;
417
+ if (!leaving) pendingAction.value = null;
265
418
  }
266
419
  }
267
420
  function getPatch() {
@@ -269,6 +422,7 @@ function getPatch() {
269
422
  return objectDiff(backup.value, model.value);
270
423
  }
271
424
  async function deleteItem() {
425
+ if (isBusy.value) return;
272
426
  const ok = await confirm.ask({
273
427
  title: t("mapo.delete"),
274
428
  message: t("mapo.detail.deleteQuestion"),
@@ -276,21 +430,36 @@ async function deleteItem() {
276
430
  dangerous: true
277
431
  });
278
432
  if (!ok) return;
279
- isDeleting.value = true;
433
+ pendingAction.value = "delete";
434
+ let leaving = false;
280
435
  try {
281
436
  await crud.delete(recordId());
282
437
  backup.value = deepClone(model.value);
283
438
  snack.show(t("mapo.deleteSuccess"), "success");
284
439
  emit("deleted");
285
- back();
440
+ leaving = leave();
286
441
  } catch (err) {
287
442
  snack.show(getErrorDetail(err) ?? t("mapo.deleteError"), "error");
288
443
  } finally {
289
- isDeleting.value = false;
444
+ if (!leaving) pendingAction.value = null;
290
445
  }
291
446
  }
292
447
  function back() {
448
+ if (isBusy.value) return;
449
+ pendingAction.value = "back";
450
+ const leaving = leave();
451
+ if (!leaving) pendingAction.value = null;
452
+ }
453
+ function leave() {
454
+ const hasPreviousPage = router.options.history.state.back != null;
455
+ if (hasPreviousPage) {
456
+ const stopWatching = router.afterEach((_to, _from, failure) => {
457
+ stopWatching();
458
+ if (failure) pendingAction.value = null;
459
+ });
460
+ }
293
461
  router.back();
462
+ return hasPreviousPage;
294
463
  }
295
464
  async function guardUnsaved() {
296
465
  if (!isDirty.value) return true;
@@ -321,6 +490,7 @@ onMounted(() => {
321
490
  preventWindowClose
322
491
  );
323
492
  }
493
+ describeEndpoint();
324
494
  fetchModel();
325
495
  });
326
496
  onBeforeUnmount(() => {
@@ -331,6 +501,48 @@ onBeforeUnmount(() => {
331
501
  );
332
502
  }
333
503
  });
504
+ const innerAnnotations = ref({});
505
+ const formAnnotations = computed(() => ({
506
+ ...innerAnnotations.value,
507
+ ...props.annotations ?? {}
508
+ }));
509
+ let metadataRequest;
510
+ function describe() {
511
+ metadataRequest ??= crud.options().then(
512
+ (response) => typeof response === "object" && response !== null ? response : void 0,
513
+ () => void 0
514
+ );
515
+ return metadataRequest;
516
+ }
517
+ const context = {
518
+ endpoint: computed(() => props.endpoint),
519
+ id: computed(() => props.id),
520
+ isNew,
521
+ modelName: computed(() => props.modelName ?? null),
522
+ permissionModel: computed(() => props.permissionModel),
523
+ model,
524
+ fields: activeFields,
525
+ sidebarFields: computed(() => props.sidebarFields ?? []),
526
+ languages: activeLangs,
527
+ currentLang,
528
+ registry,
529
+ errors,
530
+ readonly: effectiveReadonly,
531
+ isLoading,
532
+ isSaving,
533
+ isBusy,
534
+ isDirty,
535
+ annotations: innerAnnotations,
536
+ extensions: computed(() => props.extensions),
537
+ save,
538
+ back,
539
+ metadata: describe,
540
+ schemaFromMetadata: computed(() => props.schemaFromMetadata),
541
+ onSaved,
542
+ draft: { part: addDraftPart, touch: () => saveDraftSoon() },
543
+ revealField
544
+ };
545
+ provide(DETAIL_KEY, context);
334
546
  const slots = useSlots();
335
547
  const formSlotNames = computed(
336
548
  () => Object.keys(slots).filter(
@@ -339,6 +551,8 @@ const formSlotNames = computed(
339
551
  );
340
552
  const slotBindings = computed(() => ({
341
553
  model: model.value,
554
+ fields: activeFields.value,
555
+ sidebarFields: props.sidebarFields ?? [],
342
556
  errors: errors.value,
343
557
  currentLang: currentLang.value,
344
558
  isNew: isNew.value,
@@ -417,21 +631,25 @@ defineSlots();
417
631
  v-model="currentLang"
418
632
  :langs="activeLangs"
419
633
  :errors="errors"
634
+ :lang-threshold="langThreshold"
420
635
  />
421
636
  </slot>
422
637
 
638
+ <MapoDetailExtensions placement="body-top" />
639
+
423
640
  <slot name="body-top" v-bind="slotBindings" />
424
641
 
425
642
  <!-- Main form -->
426
643
  <slot name="body" v-bind="slotBindings">
427
644
  <MapoForm
428
645
  v-model="model"
429
- :fields="fields"
646
+ :fields="activeFields"
430
647
  :errors="errors"
431
648
  :languages="activeLangs"
432
649
  :current-lang="currentLang"
433
650
  :registry="registry"
434
651
  :readonly="effectiveReadonly"
652
+ :annotations="formAnnotations"
435
653
  >
436
654
  <template
437
655
  v-for="slotName in formSlotNames"
@@ -449,15 +667,19 @@ defineSlots();
449
667
  <!-- Sidebar column -->
450
668
  <div :class="sidebarColsClass">
451
669
  <div :style="sidebarStyle" class="space-y-4">
452
- <!-- Action buttons (Save / Save&continue / Back — no delete here) -->
670
+ <!-- Action buttons (Save / Save&continue / Back — no delete here).
671
+ While one works, it spins and all of them are disabled. -->
453
672
  <slot name="side-buttons" v-bind="slotBindings">
454
673
  <UCard>
455
674
  <div class="flex flex-col gap-2">
675
+ <MapoDetailExtensions placement="actions" />
676
+
456
677
  <slot name="button-save" v-bind="slotBindings">
457
678
  <UButton
458
679
  v-if="!effectiveReadonly"
459
680
  block
460
- :loading="isSaving"
681
+ :loading="pendingAction === 'save'"
682
+ :disabled="isBusy"
461
683
  icon="i-lucide-save"
462
684
  @click="save(true)"
463
685
  >
@@ -470,7 +692,8 @@ defineSlots();
470
692
  v-if="!effectiveReadonly"
471
693
  block
472
694
  variant="soft"
473
- :loading="isSaving"
695
+ :loading="pendingAction === 'saveContinue'"
696
+ :disabled="isBusy"
474
697
  icon="i-lucide-save"
475
698
  @click="save(false)"
476
699
  >
@@ -485,6 +708,8 @@ defineSlots();
485
708
  block
486
709
  variant="ghost"
487
710
  icon="i-lucide-arrow-left"
711
+ :loading="pendingAction === 'back'"
712
+ :disabled="isBusy"
488
713
  @click="back"
489
714
  >
490
715
  {{ t("mapo.back") }}
@@ -509,6 +734,8 @@ defineSlots();
509
734
  :current-lang="currentLang"
510
735
  :registry="registry"
511
736
  :readonly="effectiveReadonly"
737
+ :annotations="formAnnotations"
738
+ :notify-errors="false"
512
739
  >
513
740
  <template
514
741
  v-for="slotName in formSlotNames"
@@ -528,6 +755,8 @@ defineSlots();
528
755
  :current-lang="currentLang"
529
756
  :registry="registry"
530
757
  :readonly="effectiveReadonly"
758
+ :annotations="formAnnotations"
759
+ :notify-errors="false"
531
760
  >
532
761
  <template
533
762
  v-for="slotName in formSlotNames"
@@ -562,6 +791,7 @@ defineSlots();
562
791
  color="error"
563
792
  variant="soft"
564
793
  :loading="isDeleting"
794
+ :disabled="isBusy"
565
795
  icon="i-lucide-trash-2"
566
796
  @click="deleteItem"
567
797
  >