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