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