@mapomodule/uikit 2.0.0-beta.1 → 2.0.0-beta.10

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 (193) hide show
  1. package/README.md +33 -1
  2. package/dist/index.d.mts +5 -2
  3. package/dist/index.d.ts +6 -2
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.mjs +1 -18
  6. package/dist/module.d.mts +60 -2
  7. package/dist/module.d.ts +55 -2
  8. package/dist/module.d.ts.map +1 -0
  9. package/dist/module.json +1 -1
  10. package/dist/module.mjs +174 -13
  11. package/dist/runtime/adapters/defaultMediaAdapter.d.ts +14 -0
  12. package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
  13. package/dist/runtime/adapters/defaultMediaAdapter.js +30 -0
  14. package/dist/runtime/assets/main.css +1 -0
  15. package/dist/runtime/components/MapoConfirmDialog.vue +35 -0
  16. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts +4 -0
  17. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -0
  18. package/dist/runtime/components/MapoDetail.vue +606 -0
  19. package/dist/runtime/components/MapoDetail.vue.d.ts +401 -0
  20. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -0
  21. package/dist/runtime/components/MapoDetailLangSwitch.vue +126 -0
  22. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +23 -0
  23. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -0
  24. package/dist/runtime/components/MapoDropArea.vue +99 -0
  25. package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
  26. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
  27. package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
  28. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
  29. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
  30. package/dist/runtime/components/MapoList.vue +191 -0
  31. package/dist/runtime/components/MapoList.vue.d.ts +111 -0
  32. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -0
  33. package/dist/runtime/components/MapoListActions.vue +119 -0
  34. package/dist/runtime/components/MapoListActions.vue.d.ts +33 -0
  35. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -0
  36. package/dist/runtime/components/MapoListFilters.vue +246 -0
  37. package/dist/runtime/components/MapoListFilters.vue.d.ts +38 -0
  38. package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -0
  39. package/dist/runtime/components/MapoListHead.vue +9 -0
  40. package/dist/runtime/components/MapoListHead.vue.d.ts +14 -0
  41. package/dist/runtime/components/MapoListHead.vue.d.ts.map +1 -0
  42. package/dist/runtime/components/MapoListQuickEdit.vue +123 -0
  43. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts +47 -0
  44. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -0
  45. package/dist/runtime/components/MapoListTable.vue +665 -0
  46. package/dist/runtime/components/MapoListTable.vue.d.ts +105 -0
  47. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -0
  48. package/dist/runtime/components/MapoListTabs.vue +38 -0
  49. package/dist/runtime/components/MapoListTabs.vue.d.ts +26 -0
  50. package/dist/runtime/components/MapoListTabs.vue.d.ts.map +1 -0
  51. package/dist/runtime/components/MapoLogin.vue +196 -0
  52. package/dist/runtime/components/MapoLogin.vue.d.ts +22 -0
  53. package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -0
  54. package/dist/runtime/components/MapoLogoutButton.vue +27 -0
  55. package/dist/runtime/components/MapoLogoutButton.vue.d.ts +29 -0
  56. package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -0
  57. package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
  58. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
  59. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
  60. package/dist/runtime/components/MapoMediaEditor.vue +320 -0
  61. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +8 -0
  62. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
  63. package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
  64. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
  65. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
  66. package/dist/runtime/components/MapoMediaFolders.vue +220 -0
  67. package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
  68. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
  69. package/dist/runtime/components/MapoMediaGallery.vue +219 -0
  70. package/dist/runtime/components/MapoMediaGallery.vue.d.ts +4 -0
  71. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
  72. package/dist/runtime/components/MapoMediaManager.vue +140 -0
  73. package/dist/runtime/components/MapoMediaManager.vue.d.ts +35 -0
  74. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
  75. package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
  76. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
  77. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
  78. package/dist/runtime/components/MapoMediaPreview.vue +92 -0
  79. package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
  80. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
  81. package/dist/runtime/components/MapoMediaUploader.vue +290 -0
  82. package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
  83. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
  84. package/dist/runtime/components/MapoMenuManager.vue +273 -0
  85. package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
  86. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
  87. package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
  88. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
  89. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
  90. package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
  91. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
  92. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
  93. package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
  94. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
  95. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
  96. package/dist/runtime/components/MapoRootComponents.vue +9 -0
  97. package/dist/runtime/components/MapoRootComponents.vue.d.ts +4 -0
  98. package/dist/runtime/components/MapoRootComponents.vue.d.ts.map +1 -0
  99. package/dist/runtime/components/MapoSidebar.vue +89 -0
  100. package/dist/runtime/components/MapoSidebar.vue.d.ts +22 -0
  101. package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -0
  102. package/dist/runtime/components/MapoSidebarList.vue +27 -0
  103. package/dist/runtime/components/MapoSidebarList.vue.d.ts +8 -0
  104. package/dist/runtime/components/MapoSidebarList.vue.d.ts.map +1 -0
  105. package/dist/runtime/components/MapoSidebarListItem.vue +74 -0
  106. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts +9 -0
  107. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts.map +1 -0
  108. package/dist/runtime/components/MapoSidebarProfile.vue +55 -0
  109. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts +10 -0
  110. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -0
  111. package/dist/runtime/components/MapoSnackBar.vue +38 -0
  112. package/dist/runtime/components/MapoSnackBar.vue.d.ts +4 -0
  113. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -0
  114. package/dist/runtime/components/MapoThemeToggle.vue +23 -0
  115. package/dist/runtime/components/MapoThemeToggle.vue.d.ts +4 -0
  116. package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -0
  117. package/dist/runtime/components/MapoTopbar.vue +30 -0
  118. package/dist/runtime/components/MapoTopbar.vue.d.ts +15 -0
  119. package/dist/runtime/components/MapoTopbar.vue.d.ts.map +1 -0
  120. package/dist/runtime/components/menuDndContext.d.ts +19 -0
  121. package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
  122. package/dist/runtime/components/menuDndContext.js +3 -0
  123. package/dist/runtime/layouts/default.vue +43 -0
  124. package/dist/runtime/layouts/default.vue.d.ts +20 -0
  125. package/dist/runtime/layouts/default.vue.d.ts.map +1 -0
  126. package/dist/runtime/layouts/empty.vue +9 -0
  127. package/dist/runtime/layouts/empty.vue.d.ts +14 -0
  128. package/dist/runtime/layouts/empty.vue.d.ts.map +1 -0
  129. package/dist/runtime/page-meta.nuxt.d.ts +45 -0
  130. package/dist/runtime/pages/index.vue +14 -0
  131. package/dist/runtime/pages/index.vue.d.ts +4 -0
  132. package/dist/runtime/pages/index.vue.d.ts.map +1 -0
  133. package/dist/runtime/pages/login.vue +3 -0
  134. package/dist/runtime/pages/login.vue.d.ts +4 -0
  135. package/dist/runtime/pages/login.vue.d.ts.map +1 -0
  136. package/dist/runtime/plugins/media-adapter.d.ts +18 -0
  137. package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
  138. package/dist/runtime/plugins/media-adapter.js +8 -0
  139. package/dist/runtime/stores/media.d.ts +462 -0
  140. package/dist/runtime/stores/media.d.ts.map +1 -0
  141. package/dist/runtime/stores/media.js +344 -0
  142. package/dist/runtime/types/list.d.ts +59 -0
  143. package/dist/runtime/types/list.d.ts.map +1 -0
  144. package/dist/runtime/types/list.js +0 -0
  145. package/dist/runtime/types/media.d.ts +116 -0
  146. package/dist/runtime/types/media.d.ts.map +1 -0
  147. package/dist/runtime/types/media.js +0 -0
  148. package/dist/runtime/types/menu.d.ts +66 -0
  149. package/dist/runtime/types/menu.d.ts.map +1 -0
  150. package/dist/runtime/types/menu.js +30 -0
  151. package/dist/types.d.mts +6 -10
  152. package/package.json +15 -11
  153. package/src/index.ts +20 -0
  154. package/src/module.ts +130 -0
  155. package/src/runtime/adapters/defaultMediaAdapter.ts +57 -0
  156. package/src/runtime/components/MapoConfirmDialog.vue +5 -3
  157. package/src/runtime/components/MapoDetail.vue +39 -36
  158. package/src/runtime/components/MapoDetailLangSwitch.vue +1 -1
  159. package/src/runtime/components/MapoDropArea.vue +127 -0
  160. package/src/runtime/components/MapoLangSwitcher.vue +74 -0
  161. package/src/runtime/components/MapoList.vue +1 -1
  162. package/src/runtime/components/MapoListActions.vue +16 -10
  163. package/src/runtime/components/MapoListFilters.vue +5 -2
  164. package/src/runtime/components/MapoListQuickEdit.vue +12 -9
  165. package/src/runtime/components/MapoListTable.vue +26 -21
  166. package/src/runtime/components/MapoLogin.vue +13 -10
  167. package/src/runtime/components/MapoLogoutButton.vue +4 -2
  168. package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
  169. package/src/runtime/components/MapoMediaEditor.vue +350 -0
  170. package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
  171. package/src/runtime/components/MapoMediaFolders.vue +239 -0
  172. package/src/runtime/components/MapoMediaGallery.vue +239 -0
  173. package/src/runtime/components/MapoMediaManager.vue +180 -0
  174. package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
  175. package/src/runtime/components/MapoMediaPreview.vue +111 -0
  176. package/src/runtime/components/MapoMediaUploader.vue +351 -0
  177. package/src/runtime/components/MapoMenuManager.vue +402 -0
  178. package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
  179. package/src/runtime/components/MapoMenuTreeview.vue +264 -0
  180. package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
  181. package/src/runtime/components/MapoSidebar.vue +3 -1
  182. package/src/runtime/components/MapoSidebarList.vue +1 -1
  183. package/src/runtime/components/MapoSidebarProfile.vue +6 -2
  184. package/src/runtime/components/MapoThemeToggle.vue +5 -1
  185. package/src/runtime/components/menuDndContext.ts +22 -0
  186. package/src/runtime/pages/index.vue +4 -3
  187. package/src/runtime/pages/login.vue +0 -4
  188. package/src/runtime/plugins/media-adapter.ts +33 -0
  189. package/src/runtime/stores/media.ts +474 -0
  190. package/src/runtime/types/media.ts +126 -0
  191. package/src/runtime/types/menu.ts +105 -0
  192. package/dist/index.d.cts +0 -2
  193. package/dist/module.d.cts +0 -2
@@ -0,0 +1,606 @@
1
+ <script setup>
2
+ import {
3
+ ref,
4
+ computed,
5
+ toRaw,
6
+ watch,
7
+ useSlots,
8
+ onMounted,
9
+ onBeforeUnmount,
10
+ provide
11
+ } from "vue";
12
+ import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
13
+ import { useI18n } from "vue-i18n";
14
+ import { objectDiff, debounce, deepClone } from "@mapomodule/utils";
15
+ import { useCrud } from "@mapomodule/core/runtime/api/crud";
16
+ import {
17
+ getErrorData,
18
+ getErrorDetail,
19
+ getErrorStatus
20
+ } from "@mapomodule/core/runtime/utils/fetchError";
21
+ import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
22
+ import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
23
+ import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
24
+ const props = defineProps({
25
+ endpoint: { type: String, required: true },
26
+ id: { type: [String, Number], required: true },
27
+ fields: { type: Array, required: true },
28
+ sidebarFields: { type: Array, required: false, default: () => [] },
29
+ languages: { type: Array, required: false, default: () => [] },
30
+ modelName: { type: [String, null], required: false, default: null },
31
+ sidebarCols: { type: Number, required: false, default: 4 },
32
+ sticky: { type: Boolean, required: false, default: true },
33
+ usePatch: { type: Boolean, required: false, default: true },
34
+ readonly: { type: Boolean, required: false, default: false },
35
+ registry: { type: [Object, null], required: false, default: null },
36
+ draft: { type: Boolean, required: false, default: false },
37
+ draftKey: { type: String, required: false, default: void 0 },
38
+ multipart: { type: null, required: false, default: "auto" },
39
+ permissionModel: { type: String, required: false, default: void 0 },
40
+ previewField: { type: String, required: false, default: void 0 },
41
+ forceLanguages: { type: Array, required: false, default: void 0 }
42
+ });
43
+ const emit = defineEmits(["saved", "deleted", "draft-found"]);
44
+ const { $mapoFormRegistry } = useNuxtApp();
45
+ const registry = computed(() => props.registry ?? $mapoFormRegistry);
46
+ const { t } = useI18n();
47
+ const router = useRouter();
48
+ const snack = useSnackStore();
49
+ const confirm = useConfirmStore();
50
+ const crud = useCrud(props.endpoint);
51
+ const formValidators = [];
52
+ provide("mapoDetailRegisterValidator", (fn) => {
53
+ formValidators.push(fn);
54
+ return () => {
55
+ const idx = formValidators.indexOf(fn);
56
+ if (idx >= 0) formValidators.splice(idx, 1);
57
+ };
58
+ });
59
+ const isNew = computed(() => String(props.id) === "new");
60
+ const model = ref({});
61
+ function recordId() {
62
+ return model.value.id;
63
+ }
64
+ const backup = ref(null);
65
+ const errors = ref({});
66
+ const isLoading = ref(String(props.id) !== "new");
67
+ const isSaving = ref(false);
68
+ const isDeleting = ref(false);
69
+ const currentLang = ref(props.languages[0] ?? "");
70
+ const draftBanner = ref(null);
71
+ const isDirty = computed(
72
+ () => backup.value !== null && Object.keys(objectDiff(backup.value, model.value)).length > 0
73
+ );
74
+ const mainCols = computed(() => 12 - props.sidebarCols);
75
+ const derivedLangs = ref([]);
76
+ const activeLangs = computed(() => {
77
+ if (props.forceLanguages?.length) return props.forceLanguages;
78
+ if (props.languages.length) return props.languages;
79
+ return derivedLangs.value;
80
+ });
81
+ watch(
82
+ activeLangs,
83
+ (langs) => {
84
+ if (!currentLang.value && langs.length) currentLang.value = langs[0];
85
+ },
86
+ { immediate: true }
87
+ );
88
+ const { canAdd, canChange, canDelete: canDeletePerm } = usePermissions();
89
+ const effectiveReadonly = computed(() => {
90
+ if (props.readonly) return true;
91
+ if (!props.permissionModel) return false;
92
+ return isNew.value ? !canAdd(props.permissionModel) : !canChange(props.permissionModel);
93
+ });
94
+ const canDeleteItem = computed(
95
+ () => !props.permissionModel || canDeletePerm(props.permissionModel)
96
+ );
97
+ const previewOpen = ref(false);
98
+ const previewUrl = computed(() => {
99
+ if (!props.previewField) return null;
100
+ const url = model.value[props.previewField];
101
+ return typeof url === "string" ? url : null;
102
+ });
103
+ const sidebarHasGroups = computed(
104
+ () => (props.sidebarFields ?? []).some((f) => f.group != null)
105
+ );
106
+ const sidebarStyle = computed(
107
+ () => props.sticky ? {
108
+ position: "sticky",
109
+ top: "var(--mapo-topbar-height, 64px)"
110
+ } : {}
111
+ );
112
+ const MD_COL_SPAN = {
113
+ 1: "md:col-span-1",
114
+ 2: "md:col-span-2",
115
+ 3: "md:col-span-3",
116
+ 4: "md:col-span-4",
117
+ 5: "md:col-span-5",
118
+ 6: "md:col-span-6",
119
+ 7: "md:col-span-7",
120
+ 8: "md:col-span-8",
121
+ 9: "md:col-span-9",
122
+ 10: "md:col-span-10",
123
+ 11: "md:col-span-11",
124
+ 12: "md:col-span-12"
125
+ };
126
+ const mainColsClass = computed(
127
+ () => `col-span-12 ${MD_COL_SPAN[mainCols.value] ?? "md:col-span-8"}`
128
+ );
129
+ const sidebarColsClass = computed(
130
+ () => `col-span-12 ${MD_COL_SPAN[props.sidebarCols] ?? "md:col-span-4"}`
131
+ );
132
+ const DRAFT_TTL = 864e5;
133
+ function draftStorageKey() {
134
+ if (!props.draft && !props.draftKey) return null;
135
+ const key = props.draftKey ?? `${props.endpoint}:${props.id}`;
136
+ return `mapo:draft:${key}`;
137
+ }
138
+ function clearDraft() {
139
+ const key = draftStorageKey();
140
+ if (key && typeof localStorage !== "undefined") localStorage.removeItem(key);
141
+ }
142
+ function checkDraft() {
143
+ const key = draftStorageKey();
144
+ if (!key || typeof localStorage === "undefined") return;
145
+ try {
146
+ const raw = localStorage.getItem(key);
147
+ if (!raw) return;
148
+ const entry = JSON.parse(raw);
149
+ if (Date.now() - entry.savedAt > DRAFT_TTL) {
150
+ localStorage.removeItem(key);
151
+ return;
152
+ }
153
+ const savedAt = new Date(entry.savedAt);
154
+ const restore = () => {
155
+ Object.assign(model.value, entry.model);
156
+ draftBanner.value = null;
157
+ };
158
+ const discard = () => {
159
+ localStorage.removeItem(key);
160
+ draftBanner.value = null;
161
+ };
162
+ draftBanner.value = { savedAt, restore, discard };
163
+ emit("draft-found", entry.model, savedAt, restore, discard);
164
+ } catch {
165
+ }
166
+ }
167
+ if (props.draft || props.draftKey) {
168
+ const saveDraft = debounce(() => {
169
+ const key = draftStorageKey();
170
+ if (!key || !isDirty.value || typeof localStorage === "undefined") return;
171
+ try {
172
+ localStorage.setItem(
173
+ key,
174
+ JSON.stringify({ model: toRaw(model.value), savedAt: Date.now() })
175
+ );
176
+ } catch {
177
+ }
178
+ }, 2e3);
179
+ watch(model, saveDraft, { deep: true });
180
+ }
181
+ async function fetchModel() {
182
+ if (isNew.value) {
183
+ backup.value = null;
184
+ checkDraft();
185
+ return;
186
+ }
187
+ isLoading.value = true;
188
+ try {
189
+ model.value = await crud.detail(props.id);
190
+ 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
+ checkDraft();
197
+ } catch (err) {
198
+ snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
199
+ if (getErrorStatus(err) === 404) router.back();
200
+ } finally {
201
+ isLoading.value = false;
202
+ }
203
+ }
204
+ async function save(andBack = false) {
205
+ const validationResults = formValidators.map((fn) => fn());
206
+ const allValid = validationResults.every((r) => r.valid);
207
+ if (!allValid) {
208
+ const fieldErrors = validationResults.flatMap(
209
+ (r) => Object.entries(r.errors)
210
+ );
211
+ const message = fieldErrors.length ? fieldErrors.map(([field, msg]) => `${field}: ${msg}`).join("\n") : t("mapo.fixErrors");
212
+ snack.show(message, "error");
213
+ return;
214
+ }
215
+ errors.value = {};
216
+ isSaving.value = true;
217
+ try {
218
+ const multipartOpts = { multipart: props.multipart };
219
+ let result;
220
+ if (isNew.value) {
221
+ result = await crud.create(model.value, void 0, multipartOpts);
222
+ } else if (props.usePatch) {
223
+ const patch = getPatch();
224
+ result = await crud.partialUpdate(
225
+ recordId(),
226
+ patch,
227
+ void 0,
228
+ multipartOpts
229
+ );
230
+ } else {
231
+ result = await crud.update(
232
+ recordId(),
233
+ model.value,
234
+ void 0,
235
+ multipartOpts
236
+ );
237
+ }
238
+ Object.assign(model.value, result);
239
+ backup.value = deepClone(model.value);
240
+ clearDraft();
241
+ snack.show(
242
+ isNew.value ? t("mapo.createSuccess") : t("mapo.saveSuccess"),
243
+ "success"
244
+ );
245
+ emit("saved", model.value);
246
+ if (isNew.value && result && "id" in result) {
247
+ const id = result.id;
248
+ await router.replace({
249
+ params: { id }
250
+ });
251
+ }
252
+ if (andBack) back();
253
+ } catch (err) {
254
+ const data = getErrorData(err);
255
+ if (getErrorStatus(err) === 400 && data && typeof data === "object") {
256
+ errors.value = data;
257
+ const detail = data.detail;
258
+ if (detail) snack.show(detail, "error");
259
+ } else {
260
+ const detail = data?.detail;
261
+ snack.show(detail ?? t("mapo.saveError"), "error");
262
+ }
263
+ } finally {
264
+ isSaving.value = false;
265
+ }
266
+ }
267
+ function getPatch() {
268
+ if (!backup.value) return { ...model.value };
269
+ return objectDiff(backup.value, model.value);
270
+ }
271
+ async function deleteItem() {
272
+ const ok = await confirm.ask({
273
+ title: t("mapo.delete"),
274
+ message: t("mapo.detail.deleteQuestion"),
275
+ confirmText: t("mapo.delete"),
276
+ dangerous: true
277
+ });
278
+ if (!ok) return;
279
+ isDeleting.value = true;
280
+ try {
281
+ await crud.delete(recordId());
282
+ backup.value = deepClone(model.value);
283
+ snack.show(t("mapo.deleteSuccess"), "success");
284
+ emit("deleted");
285
+ back();
286
+ } catch (err) {
287
+ snack.show(getErrorDetail(err) ?? t("mapo.deleteError"), "error");
288
+ } finally {
289
+ isDeleting.value = false;
290
+ }
291
+ }
292
+ function back() {
293
+ router.back();
294
+ }
295
+ async function guardUnsaved() {
296
+ if (!isDirty.value) return true;
297
+ return confirm.ask({
298
+ title: t("mapo.unsavedData"),
299
+ message: t("mapo.confirmLeaveChanges"),
300
+ confirmText: t("mapo.leave"),
301
+ dangerous: true
302
+ });
303
+ }
304
+ onBeforeRouteLeave(
305
+ (_to, _from, next) => {
306
+ guardUnsaved().then((ok) => next(ok));
307
+ }
308
+ );
309
+ function preventWindowClose(e) {
310
+ if (isDirty.value && typeof globalThis !== "undefined") {
311
+ e.preventDefault();
312
+ if ("returnValue" in e) {
313
+ e.returnValue = "";
314
+ }
315
+ }
316
+ }
317
+ onMounted(() => {
318
+ if (typeof globalThis !== "undefined" && "addEventListener" in globalThis) {
319
+ globalThis.addEventListener(
320
+ "beforeunload",
321
+ preventWindowClose
322
+ );
323
+ }
324
+ fetchModel();
325
+ });
326
+ onBeforeUnmount(() => {
327
+ if (typeof globalThis !== "undefined" && "removeEventListener" in globalThis) {
328
+ globalThis.removeEventListener(
329
+ "beforeunload",
330
+ preventWindowClose
331
+ );
332
+ }
333
+ });
334
+ const slots = useSlots();
335
+ const formSlotNames = computed(
336
+ () => Object.keys(slots).filter(
337
+ (name) => name.startsWith("field.") || name.startsWith("group.") || name.startsWith("tab.") || name === "tab-bar-end"
338
+ )
339
+ );
340
+ const slotBindings = computed(() => ({
341
+ model: model.value,
342
+ errors: errors.value,
343
+ currentLang: currentLang.value,
344
+ isNew: isNew.value,
345
+ isLoading: isLoading.value,
346
+ isSaving: isSaving.value,
347
+ isDeleting: isDeleting.value,
348
+ isDirty: isDirty.value,
349
+ draftBanner: draftBanner.value,
350
+ readonly: effectiveReadonly.value,
351
+ canDelete: canDeleteItem.value,
352
+ save,
353
+ deleteItem,
354
+ back
355
+ }));
356
+ defineSlots();
357
+ </script>
358
+
359
+ <template>
360
+ <!-- Loading state -->
361
+ <div v-if="isLoading" class="flex items-center justify-center py-24">
362
+ <UIcon
363
+ name="i-lucide-loader-2"
364
+ class="w-8 h-8 animate-spin text-gray-400"
365
+ />
366
+ </div>
367
+
368
+ <div v-else>
369
+ <!-- Draft banner -->
370
+ <slot name="draft-banner" v-bind="slotBindings">
371
+ <Transition name="slide-down">
372
+ <UAlert
373
+ v-if="draftBanner"
374
+ icon="i-lucide-history"
375
+ color="warning"
376
+ variant="subtle"
377
+ class="mb-3"
378
+ :title="
379
+ t('mapo.detail.draftSavedAt', {
380
+ date: draftBanner.savedAt.toLocaleString()
381
+ })
382
+ "
383
+ :description="t('mapo.detail.draftFound')"
384
+ >
385
+ <template #actions>
386
+ <UButton size="xs" color="warning" @click="draftBanner?.restore()">
387
+ {{ t("mapo.restore") }}
388
+ </UButton>
389
+ <UButton
390
+ size="xs"
391
+ color="neutral"
392
+ variant="ghost"
393
+ @click="draftBanner?.discard()"
394
+ >
395
+ {{ t("mapo.discard") }}
396
+ </UButton>
397
+ </template>
398
+ </UAlert>
399
+ </Transition>
400
+ </slot>
401
+
402
+ <!-- Title -->
403
+ <slot name="title" v-bind="slotBindings">
404
+ <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-6">
405
+ {{ isNew ? t("mapo.new") : t("mapo.edit") }}
406
+ <span v-if="modelName"> {{ modelName }}</span>
407
+ </h1>
408
+ </slot>
409
+
410
+ <div class="grid grid-cols-12 gap-6 items-start">
411
+ <!-- Main column -->
412
+ <div :class="[mainColsClass, 'space-y-4']">
413
+ <!-- Lang switch -->
414
+ <slot name="body-lang" v-bind="slotBindings">
415
+ <MapoDetailLangSwitch
416
+ v-if="activeLangs.length > 1"
417
+ v-model="currentLang"
418
+ :langs="activeLangs"
419
+ :errors="errors"
420
+ />
421
+ </slot>
422
+
423
+ <slot name="body-top" v-bind="slotBindings" />
424
+
425
+ <!-- Main form -->
426
+ <slot name="body" v-bind="slotBindings">
427
+ <MapoForm
428
+ v-model="model"
429
+ :fields="fields"
430
+ :errors="errors"
431
+ :languages="activeLangs"
432
+ :current-lang="currentLang"
433
+ :registry="registry"
434
+ :readonly="effectiveReadonly"
435
+ >
436
+ <template
437
+ v-for="slotName in formSlotNames"
438
+ :key="slotName"
439
+ #[slotName]="slotProps"
440
+ >
441
+ <slot :name="slotName" v-bind="slotProps ?? {}" />
442
+ </template>
443
+ </MapoForm>
444
+ </slot>
445
+
446
+ <slot name="body-bottom" v-bind="slotBindings" />
447
+ </div>
448
+
449
+ <!-- Sidebar column -->
450
+ <div :class="sidebarColsClass">
451
+ <div :style="sidebarStyle" class="space-y-4">
452
+ <!-- Action buttons (Save / Save&continue / Back — no delete here) -->
453
+ <slot name="side-buttons" v-bind="slotBindings">
454
+ <UCard>
455
+ <div class="flex flex-col gap-2">
456
+ <slot name="button-save" v-bind="slotBindings">
457
+ <UButton
458
+ v-if="!effectiveReadonly"
459
+ block
460
+ :loading="isSaving"
461
+ icon="i-lucide-save"
462
+ @click="save(true)"
463
+ >
464
+ {{ isNew ? t("mapo.create") : t("mapo.save") }}
465
+ </UButton>
466
+ </slot>
467
+
468
+ <slot name="button-savecontinue" v-bind="slotBindings">
469
+ <UButton
470
+ v-if="!effectiveReadonly"
471
+ block
472
+ variant="soft"
473
+ :loading="isSaving"
474
+ icon="i-lucide-save"
475
+ @click="save(false)"
476
+ >
477
+ {{
478
+ isNew ? t("mapo.createContinue") : t("mapo.saveContinue")
479
+ }}
480
+ </UButton>
481
+ </slot>
482
+
483
+ <slot name="button-back" v-bind="slotBindings">
484
+ <UButton
485
+ block
486
+ variant="ghost"
487
+ icon="i-lucide-arrow-left"
488
+ @click="back"
489
+ >
490
+ {{ t("mapo.back") }}
491
+ </UButton>
492
+ </slot>
493
+ </div>
494
+ </UCard>
495
+ </slot>
496
+
497
+ <slot name="side-top" v-bind="slotBindings" />
498
+
499
+ <!-- Sidebar fields form.
500
+ Flat fields (no group) get a UCard wrapper for visual structure.
501
+ Grouped fields render their own group cards, so no outer wrapper. -->
502
+ <template v-if="sidebarFields && sidebarFields.length">
503
+ <UCard v-if="!sidebarHasGroups">
504
+ <MapoForm
505
+ v-model="model"
506
+ :fields="sidebarFields"
507
+ :errors="errors"
508
+ :languages="activeLangs"
509
+ :current-lang="currentLang"
510
+ :registry="registry"
511
+ :readonly="effectiveReadonly"
512
+ >
513
+ <template
514
+ v-for="slotName in formSlotNames"
515
+ :key="slotName"
516
+ #[slotName]="slotProps"
517
+ >
518
+ <slot :name="slotName" v-bind="slotProps ?? {}" />
519
+ </template>
520
+ </MapoForm>
521
+ </UCard>
522
+ <MapoForm
523
+ v-else
524
+ v-model="model"
525
+ :fields="sidebarFields"
526
+ :errors="errors"
527
+ :languages="activeLangs"
528
+ :current-lang="currentLang"
529
+ :registry="registry"
530
+ :readonly="effectiveReadonly"
531
+ >
532
+ <template
533
+ v-for="slotName in formSlotNames"
534
+ :key="slotName"
535
+ #[slotName]="slotProps"
536
+ >
537
+ <slot :name="slotName" v-bind="slotProps ?? {}" />
538
+ </template>
539
+ </MapoForm>
540
+ </template>
541
+
542
+ <slot name="side-bottom" v-bind="slotBindings" />
543
+
544
+ <!-- Preview button — shown when previewField resolves to a URL -->
545
+ <UButton
546
+ v-if="previewUrl"
547
+ block
548
+ variant="outline"
549
+ color="neutral"
550
+ icon="i-lucide-eye"
551
+ @click="previewOpen = true"
552
+ >
553
+ {{ t("mapo.preview") }}
554
+ </UButton>
555
+
556
+ <!-- Danger zone: delete action, visually separated from save actions -->
557
+ <slot name="side-danger" v-bind="slotBindings">
558
+ <UCard v-if="!isNew && canDeleteItem">
559
+ <slot name="button-delete" v-bind="slotBindings">
560
+ <UButton
561
+ block
562
+ color="error"
563
+ variant="soft"
564
+ :loading="isDeleting"
565
+ icon="i-lucide-trash-2"
566
+ @click="deleteItem"
567
+ >
568
+ {{ t("mapo.delete") }}
569
+ </UButton>
570
+ </slot>
571
+ </UCard>
572
+ </slot>
573
+ </div>
574
+ </div>
575
+ </div>
576
+
577
+ <!-- Preview iframe modal -->
578
+ <UModal
579
+ v-if="previewField"
580
+ v-model:open="previewOpen"
581
+ :ui="{ content: 'max-w-5xl' }"
582
+ >
583
+ <template #content>
584
+ <div class="flex flex-col" style="height: 80vh">
585
+ <div
586
+ class="flex items-center justify-between px-4 py-2 border-b border-default"
587
+ >
588
+ <span class="text-sm font-medium truncate">{{ previewUrl }}</span>
589
+ <UButton
590
+ size="xs"
591
+ variant="ghost"
592
+ color="neutral"
593
+ icon="i-lucide-x"
594
+ @click="previewOpen = false"
595
+ />
596
+ </div>
597
+ <iframe
598
+ :src="previewUrl ?? ''"
599
+ class="flex-1 w-full border-0"
600
+ sandbox="allow-scripts allow-same-origin allow-forms allow-popups"
601
+ />
602
+ </div>
603
+ </template>
604
+ </UModal>
605
+ </div>
606
+ </template>