@mapomodule/uikit 2.0.0-beta.7 → 2.0.0-experimental.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -174
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/formValues.test.d.ts +2 -0
- package/dist/__tests__/formValues.test.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/runtimePages.test.d.ts +2 -0
- package/dist/__tests__/runtimePages.test.d.ts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/module.d.mts +2 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +23 -2
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +301 -63
- package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue +5 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts +1 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
- 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 +7 -3
- package/dist/runtime/components/MapoList.vue.d.ts +14 -4
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +27 -13
- package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
- package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListFilters.vue +4 -2
- package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +12 -8
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +116 -45
- package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogin.vue +13 -10
- package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogoutButton.vue +4 -2
- package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaEditor.vue +36 -20
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFileChanger.vue +7 -3
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFolders.vue +36 -14
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaGallery.vue +15 -5
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManager.vue +17 -7
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManagerDialog.vue +8 -4
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaUploader.vue +53 -29
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
- 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/MapoSidebar.vue +3 -1
- package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSidebarList.vue +1 -1
- package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
- package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoThemeToggle.vue +5 -1
- package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
- 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/composables/defineDetailExtension.d.ts +32 -0
- package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
- package/dist/runtime/composables/defineDetailExtension.js +34 -0
- package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
- package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
- package/dist/runtime/composables/useMapoDetail.js +5 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/pages/index.vue +4 -2
- package/dist/runtime/pages/index.vue.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.js +2 -1
- package/dist/runtime/stores/media.d.ts +8 -2
- package/dist/runtime/stores/media.d.ts.map +1 -1
- package/dist/runtime/stores/media.js +45 -13
- package/dist/runtime/types/detail.d.ts +167 -0
- package/dist/runtime/types/detail.d.ts.map +1 -0
- package/dist/runtime/types/detail.js +0 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- 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/formValues.d.ts +8 -0
- package/dist/runtime/utils/formValues.d.ts.map +1 -0
- package/dist/runtime/utils/formValues.js +19 -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/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/package.json +12 -10
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +1107 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +504 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/formValues.test.ts +31 -0
- package/src/__tests__/langInfo.test.ts +48 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/runtimePages.test.ts +17 -0
- package/src/index.ts +20 -0
- package/src/module.ts +29 -0
- package/src/runtime/assets/main.css +13 -0
- package/src/runtime/components/MapoConfirmDialog.vue +33 -4
- package/src/runtime/components/MapoDetail.vue +520 -89
- package/src/runtime/components/MapoDetailExtensions.vue +39 -0
- package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
- package/src/runtime/components/MapoDropArea.vue +6 -1
- package/src/runtime/components/MapoLangSwitcher.vue +74 -0
- package/src/runtime/components/MapoList.vue +21 -6
- package/src/runtime/components/MapoListActions.vue +32 -14
- package/src/runtime/components/MapoListFilters.vue +5 -2
- package/src/runtime/components/MapoListQuickEdit.vue +12 -9
- package/src/runtime/components/MapoListTable.vue +147 -55
- package/src/runtime/components/MapoLogin.vue +13 -10
- package/src/runtime/components/MapoLogoutButton.vue +4 -2
- package/src/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
- package/src/runtime/components/MapoMediaEditor.vue +43 -20
- package/src/runtime/components/MapoMediaFileChanger.vue +8 -3
- package/src/runtime/components/MapoMediaFolders.vue +37 -15
- package/src/runtime/components/MapoMediaGallery.vue +17 -5
- package/src/runtime/components/MapoMediaManager.vue +17 -7
- package/src/runtime/components/MapoMediaManagerDialog.vue +10 -4
- package/src/runtime/components/MapoMediaUploader.vue +60 -29
- 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/MapoSnackBar.vue +12 -0
- package/src/runtime/components/MapoThemeToggle.vue +5 -1
- package/src/runtime/components/menuDndContext.ts +22 -0
- package/src/runtime/composables/defineDetailExtension.ts +78 -0
- package/src/runtime/composables/useMapoDetail.ts +24 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/pages/index.vue +5 -2
- package/src/runtime/plugins/media-adapter.ts +9 -5
- package/src/runtime/stores/media.ts +61 -13
- package/src/runtime/types/detail.ts +178 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/types/menu.ts +105 -0
- package/src/runtime/utils/formValues.ts +28 -0
- package/src/runtime/utils/langInfo.ts +38 -0
- package/src/runtime/utils/listTable.ts +54 -0
|
@@ -7,21 +7,44 @@ import {
|
|
|
7
7
|
useSlots,
|
|
8
8
|
onMounted,
|
|
9
9
|
onBeforeUnmount,
|
|
10
|
-
provide
|
|
10
|
+
provide,
|
|
11
|
+
shallowRef,
|
|
12
|
+
getCurrentScope,
|
|
13
|
+
onScopeDispose
|
|
11
14
|
} from "vue";
|
|
12
|
-
import { useRouter, onBeforeRouteLeave } from "
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
+
import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
|
|
16
|
+
import { useI18n } from "vue-i18n";
|
|
17
|
+
import {
|
|
18
|
+
objectDiff,
|
|
19
|
+
debounce,
|
|
20
|
+
deepClone,
|
|
21
|
+
metadataToJsonSchema
|
|
22
|
+
} from "@mapomodule/utils";
|
|
15
23
|
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
24
|
+
import {
|
|
25
|
+
getErrorData,
|
|
26
|
+
getErrorDetail,
|
|
27
|
+
getErrorStatus
|
|
28
|
+
} from "@mapomodule/core/runtime/utils/fetchError";
|
|
16
29
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
17
30
|
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
31
|
+
import { useAuthStore } from "@mapomodule/store/runtime/stores/auth";
|
|
18
32
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
33
|
+
import { languagesFromMetadata } from "../utils/langInfo";
|
|
34
|
+
import { holdsFormValue } from "../utils/formValues";
|
|
35
|
+
import { DETAIL_KEY } from "../composables/useMapoDetail";
|
|
36
|
+
import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
|
|
37
|
+
import { modelForDraft } from "@mapomodule/form/runtime/utils/draft";
|
|
19
38
|
const props = defineProps({
|
|
20
39
|
endpoint: { type: String, required: true },
|
|
21
40
|
id: { type: [String, Number], required: true },
|
|
22
|
-
fields: { type: Array, required:
|
|
41
|
+
fields: { type: Array, required: false, default: void 0 },
|
|
42
|
+
experimentalFieldsFromSchema: { type: Boolean, required: false, default: false },
|
|
43
|
+
schemaFromMetadata: { type: Function, required: false, default: void 0 },
|
|
44
|
+
schemaFieldOptions: { type: Object, required: false, default: void 0 },
|
|
23
45
|
sidebarFields: { type: Array, required: false, default: () => [] },
|
|
24
46
|
languages: { type: Array, required: false, default: () => [] },
|
|
47
|
+
langThreshold: { type: Number, required: false, default: void 0 },
|
|
25
48
|
modelName: { type: [String, null], required: false, default: null },
|
|
26
49
|
sidebarCols: { type: Number, required: false, default: 4 },
|
|
27
50
|
sticky: { type: Boolean, required: false, default: true },
|
|
@@ -33,14 +56,18 @@ const props = defineProps({
|
|
|
33
56
|
multipart: { type: null, required: false, default: "auto" },
|
|
34
57
|
permissionModel: { type: String, required: false, default: void 0 },
|
|
35
58
|
previewField: { type: String, required: false, default: void 0 },
|
|
36
|
-
forceLanguages: { type: Array, required: false, default: void 0 }
|
|
59
|
+
forceLanguages: { type: Array, required: false, default: void 0 },
|
|
60
|
+
annotations: { type: Object, required: false, default: void 0 },
|
|
61
|
+
extensions: { type: [Boolean, Array], required: false, default: true }
|
|
37
62
|
});
|
|
38
63
|
const emit = defineEmits(["saved", "deleted", "draft-found"]);
|
|
39
64
|
const { $mapoFormRegistry } = useNuxtApp();
|
|
40
65
|
const registry = computed(() => props.registry ?? $mapoFormRegistry);
|
|
66
|
+
const { t } = useI18n();
|
|
41
67
|
const router = useRouter();
|
|
42
68
|
const snack = useSnackStore();
|
|
43
69
|
const confirm = useConfirmStore();
|
|
70
|
+
const auth = useAuthStore();
|
|
44
71
|
const crud = useCrud(props.endpoint);
|
|
45
72
|
const formValidators = [];
|
|
46
73
|
provide("mapoDetailRegisterValidator", (fn) => {
|
|
@@ -50,6 +77,20 @@ provide("mapoDetailRegisterValidator", (fn) => {
|
|
|
50
77
|
if (idx >= 0) formValidators.splice(idx, 1);
|
|
51
78
|
};
|
|
52
79
|
});
|
|
80
|
+
const formRevealers = [];
|
|
81
|
+
provide("mapoDetailRegisterReveal", (fn) => {
|
|
82
|
+
formRevealers.push(fn);
|
|
83
|
+
return () => {
|
|
84
|
+
const at = formRevealers.indexOf(fn);
|
|
85
|
+
if (at >= 0) formRevealers.splice(at, 1);
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
async function revealField(path) {
|
|
89
|
+
for (const reveal of [...formRevealers]) {
|
|
90
|
+
if (await reveal(path)) return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
53
94
|
const isNew = computed(() => String(props.id) === "new");
|
|
54
95
|
const model = ref({});
|
|
55
96
|
function recordId() {
|
|
@@ -58,13 +99,25 @@ function recordId() {
|
|
|
58
99
|
const backup = ref(null);
|
|
59
100
|
const errors = ref({});
|
|
60
101
|
const isLoading = ref(String(props.id) !== "new");
|
|
61
|
-
const
|
|
62
|
-
const
|
|
102
|
+
const pendingAction = ref(null);
|
|
103
|
+
const isBusy = computed(() => pendingAction.value !== null);
|
|
104
|
+
const isSaving = computed(() => {
|
|
105
|
+
const savingAndLeaving = pendingAction.value === "save";
|
|
106
|
+
const savingAndStaying = pendingAction.value === "saveContinue";
|
|
107
|
+
return savingAndLeaving || savingAndStaying;
|
|
108
|
+
});
|
|
109
|
+
const isDeleting = computed(() => pendingAction.value === "delete");
|
|
63
110
|
const currentLang = ref(props.languages[0] ?? "");
|
|
64
111
|
const draftBanner = ref(null);
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
)
|
|
112
|
+
const opened = ref(null);
|
|
113
|
+
const isDirty = computed(() => {
|
|
114
|
+
if (backup.value !== null) {
|
|
115
|
+
return Object.keys(objectDiff(backup.value, model.value)).length > 0;
|
|
116
|
+
}
|
|
117
|
+
if (!isNew.value) return false;
|
|
118
|
+
const start = opened.value ?? {};
|
|
119
|
+
return holdsFormValue(objectDiff(start, model.value));
|
|
120
|
+
});
|
|
68
121
|
const mainCols = computed(() => 12 - props.sidebarCols);
|
|
69
122
|
const derivedLangs = ref([]);
|
|
70
123
|
const activeLangs = computed(() => {
|
|
@@ -124,12 +177,23 @@ const sidebarColsClass = computed(
|
|
|
124
177
|
() => `col-span-12 ${MD_COL_SPAN[props.sidebarCols] ?? "md:col-span-4"}`
|
|
125
178
|
);
|
|
126
179
|
const DRAFT_TTL = 864e5;
|
|
127
|
-
function
|
|
180
|
+
function draftName() {
|
|
128
181
|
if (!props.draft && !props.draftKey) return null;
|
|
129
|
-
|
|
130
|
-
|
|
182
|
+
return props.draftKey ?? `${props.endpoint}:${props.id}`;
|
|
183
|
+
}
|
|
184
|
+
function draftStorageKey() {
|
|
185
|
+
const name = draftName();
|
|
186
|
+
if (name === null) return null;
|
|
187
|
+
const userId = auth.info?.id ?? "anonymous";
|
|
188
|
+
return `mapo:draft:${userId}:${name}`;
|
|
189
|
+
}
|
|
190
|
+
function removeUnownedDraft() {
|
|
191
|
+
const name = draftName();
|
|
192
|
+
if (name === null) return;
|
|
193
|
+
localStorage.removeItem(`mapo:draft:${name}`);
|
|
131
194
|
}
|
|
132
195
|
function clearDraft() {
|
|
196
|
+
unclaimedParts.clear();
|
|
133
197
|
const key = draftStorageKey();
|
|
134
198
|
if (key && typeof localStorage !== "undefined") localStorage.removeItem(key);
|
|
135
199
|
}
|
|
@@ -137,6 +201,7 @@ function checkDraft() {
|
|
|
137
201
|
const key = draftStorageKey();
|
|
138
202
|
if (!key || typeof localStorage === "undefined") return;
|
|
139
203
|
try {
|
|
204
|
+
removeUnownedDraft();
|
|
140
205
|
const raw = localStorage.getItem(key);
|
|
141
206
|
if (!raw) return;
|
|
142
207
|
const entry = JSON.parse(raw);
|
|
@@ -147,6 +212,7 @@ function checkDraft() {
|
|
|
147
212
|
const savedAt = new Date(entry.savedAt);
|
|
148
213
|
const restore = () => {
|
|
149
214
|
Object.assign(model.value, entry.model);
|
|
215
|
+
restoreParts(entry.parts);
|
|
150
216
|
draftBanner.value = null;
|
|
151
217
|
};
|
|
152
218
|
const discard = () => {
|
|
@@ -158,23 +224,101 @@ function checkDraft() {
|
|
|
158
224
|
} catch {
|
|
159
225
|
}
|
|
160
226
|
}
|
|
227
|
+
const draftParts = /* @__PURE__ */ new Map();
|
|
228
|
+
const unclaimedParts = /* @__PURE__ */ new Map();
|
|
229
|
+
function addDraftPart(key, part) {
|
|
230
|
+
draftParts.set(key, part);
|
|
231
|
+
if (unclaimedParts.has(key)) {
|
|
232
|
+
const data = unclaimedParts.get(key);
|
|
233
|
+
unclaimedParts.delete(key);
|
|
234
|
+
restorePart(part, data);
|
|
235
|
+
}
|
|
236
|
+
const remove = () => {
|
|
237
|
+
if (draftParts.get(key) === part) draftParts.delete(key);
|
|
238
|
+
};
|
|
239
|
+
if (getCurrentScope()) onScopeDispose(remove);
|
|
240
|
+
return remove;
|
|
241
|
+
}
|
|
242
|
+
function restorePart(part, data) {
|
|
243
|
+
try {
|
|
244
|
+
part.restore(data);
|
|
245
|
+
} catch {
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function restoreParts(parts) {
|
|
249
|
+
const isRecord = typeof parts === "object" && parts !== null && !Array.isArray(parts);
|
|
250
|
+
const kept = new Map(isRecord ? Object.entries(parts) : []);
|
|
251
|
+
for (const [key, part] of draftParts) {
|
|
252
|
+
restorePart(part, kept.get(key));
|
|
253
|
+
kept.delete(key);
|
|
254
|
+
}
|
|
255
|
+
for (const [key, data] of kept) unclaimedParts.set(key, data);
|
|
256
|
+
}
|
|
257
|
+
function keptParts() {
|
|
258
|
+
const kept = {};
|
|
259
|
+
for (const [key, part] of draftParts) {
|
|
260
|
+
let data;
|
|
261
|
+
try {
|
|
262
|
+
data = part.save();
|
|
263
|
+
} catch {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (data !== void 0) kept[key] = data;
|
|
267
|
+
}
|
|
268
|
+
return Object.keys(kept).length > 0 ? kept : void 0;
|
|
269
|
+
}
|
|
270
|
+
let saveDraftSoon = () => {
|
|
271
|
+
};
|
|
161
272
|
if (props.draft || props.draftKey) {
|
|
273
|
+
let isWritten = false;
|
|
162
274
|
const saveDraft = debounce(() => {
|
|
163
275
|
const key = draftStorageKey();
|
|
164
|
-
if (!key ||
|
|
276
|
+
if (!key || typeof localStorage === "undefined") return;
|
|
165
277
|
try {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
278
|
+
const parts = keptParts();
|
|
279
|
+
const hasParts = parts !== void 0;
|
|
280
|
+
if (!isDirty.value && !hasParts) {
|
|
281
|
+
if (isWritten) localStorage.removeItem(key);
|
|
282
|
+
isWritten = false;
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const fields = [...activeFields.value, ...props.sidebarFields ?? []];
|
|
286
|
+
const values = modelForDraft(toRaw(model.value), fields);
|
|
287
|
+
const entry = { model: values, savedAt: Date.now(), parts };
|
|
288
|
+
localStorage.setItem(key, JSON.stringify(entry));
|
|
289
|
+
isWritten = true;
|
|
170
290
|
} catch {
|
|
171
291
|
}
|
|
172
292
|
}, 2e3);
|
|
173
293
|
watch(model, saveDraft, { deep: true });
|
|
294
|
+
saveDraftSoon = () => saveDraft();
|
|
295
|
+
}
|
|
296
|
+
const derivedFields = shallowRef([]);
|
|
297
|
+
const activeFields = computed(
|
|
298
|
+
() => props.fields?.length ? props.fields : derivedFields.value
|
|
299
|
+
);
|
|
300
|
+
async function describeEndpoint() {
|
|
301
|
+
const wantsLangs = !props.languages.length && !props.forceLanguages?.length;
|
|
302
|
+
const wantsFields = props.experimentalFieldsFromSchema && !props.fields?.length;
|
|
303
|
+
if (!wantsLangs && !wantsFields) return;
|
|
304
|
+
const metadata = await describe();
|
|
305
|
+
if (!metadata) return;
|
|
306
|
+
if (wantsLangs) derivedLangs.value = languagesFromMetadata(metadata);
|
|
307
|
+
if (wantsFields) {
|
|
308
|
+
const toSchema = props.schemaFromMetadata ?? metadataToJsonSchema;
|
|
309
|
+
const schema = toSchema(metadata);
|
|
310
|
+
if (schema?.properties) {
|
|
311
|
+
derivedFields.value = useFormFromSchema(
|
|
312
|
+
schema,
|
|
313
|
+
props.schemaFieldOptions
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
174
317
|
}
|
|
175
318
|
async function fetchModel() {
|
|
176
319
|
if (isNew.value) {
|
|
177
320
|
backup.value = null;
|
|
321
|
+
opened.value = deepClone(model.value);
|
|
178
322
|
checkDraft();
|
|
179
323
|
return;
|
|
180
324
|
}
|
|
@@ -182,34 +326,46 @@ async function fetchModel() {
|
|
|
182
326
|
try {
|
|
183
327
|
model.value = await crud.detail(props.id);
|
|
184
328
|
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
329
|
checkDraft();
|
|
191
330
|
} catch (err) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
snack.show(detail ?? "Failed to load item", "error");
|
|
195
|
-
if (status === 404) router.back();
|
|
331
|
+
snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
|
|
332
|
+
if (getErrorStatus(err) === 404) router.back();
|
|
196
333
|
} finally {
|
|
197
334
|
isLoading.value = false;
|
|
198
335
|
}
|
|
199
336
|
}
|
|
337
|
+
const savedHandlers = /* @__PURE__ */ new Set();
|
|
338
|
+
function onSaved(handler) {
|
|
339
|
+
savedHandlers.add(handler);
|
|
340
|
+
const remove = () => {
|
|
341
|
+
savedHandlers.delete(handler);
|
|
342
|
+
};
|
|
343
|
+
if (getCurrentScope()) onScopeDispose(remove);
|
|
344
|
+
return remove;
|
|
345
|
+
}
|
|
346
|
+
function notifySaved(record) {
|
|
347
|
+
for (const handler of [...savedHandlers]) {
|
|
348
|
+
try {
|
|
349
|
+
handler(record);
|
|
350
|
+
} catch {
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
200
354
|
async function save(andBack = false) {
|
|
355
|
+
if (isBusy.value) return;
|
|
201
356
|
const validationResults = formValidators.map((fn) => fn());
|
|
202
357
|
const allValid = validationResults.every((r) => r.valid);
|
|
203
358
|
if (!allValid) {
|
|
204
359
|
const fieldErrors = validationResults.flatMap(
|
|
205
360
|
(r) => Object.entries(r.errors)
|
|
206
361
|
);
|
|
207
|
-
const message = fieldErrors.length ? fieldErrors.map(([field, msg]) => `${field}: ${msg}`).join("\n") : "
|
|
362
|
+
const message = fieldErrors.length ? fieldErrors.map(([field, msg]) => `${field}: ${msg}`).join("\n") : t("mapo.fixErrors");
|
|
208
363
|
snack.show(message, "error");
|
|
209
364
|
return;
|
|
210
365
|
}
|
|
211
366
|
errors.value = {};
|
|
212
|
-
|
|
367
|
+
pendingAction.value = andBack ? "save" : "saveContinue";
|
|
368
|
+
let leaving = false;
|
|
213
369
|
try {
|
|
214
370
|
const multipartOpts = { multipart: props.multipart };
|
|
215
371
|
let result;
|
|
@@ -235,30 +391,30 @@ async function save(andBack = false) {
|
|
|
235
391
|
backup.value = deepClone(model.value);
|
|
236
392
|
clearDraft();
|
|
237
393
|
snack.show(
|
|
238
|
-
isNew.value ? "
|
|
394
|
+
isNew.value ? t("mapo.createSuccess") : t("mapo.saveSuccess"),
|
|
239
395
|
"success"
|
|
240
396
|
);
|
|
241
397
|
emit("saved", model.value);
|
|
398
|
+
notifySaved(model.value);
|
|
242
399
|
if (isNew.value && result && "id" in result) {
|
|
243
400
|
const id = result.id;
|
|
244
401
|
await router.replace({
|
|
245
402
|
params: { id }
|
|
246
403
|
});
|
|
247
404
|
}
|
|
248
|
-
if (andBack)
|
|
405
|
+
if (andBack) leaving = leave();
|
|
249
406
|
} catch (err) {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
if (response?.status === 400 && data && typeof data === "object") {
|
|
407
|
+
const data = getErrorData(err);
|
|
408
|
+
if (getErrorStatus(err) === 400 && data && typeof data === "object") {
|
|
253
409
|
errors.value = data;
|
|
254
410
|
const detail = data.detail;
|
|
255
411
|
if (detail) snack.show(detail, "error");
|
|
256
412
|
} else {
|
|
257
413
|
const detail = data?.detail;
|
|
258
|
-
snack.show(detail ?? "
|
|
414
|
+
snack.show(detail ?? t("mapo.saveError"), "error");
|
|
259
415
|
}
|
|
260
416
|
} finally {
|
|
261
|
-
|
|
417
|
+
if (!leaving) pendingAction.value = null;
|
|
262
418
|
}
|
|
263
419
|
}
|
|
264
420
|
function getPatch() {
|
|
@@ -266,36 +422,51 @@ function getPatch() {
|
|
|
266
422
|
return objectDiff(backup.value, model.value);
|
|
267
423
|
}
|
|
268
424
|
async function deleteItem() {
|
|
425
|
+
if (isBusy.value) return;
|
|
269
426
|
const ok = await confirm.ask({
|
|
270
|
-
title: "
|
|
271
|
-
message: "
|
|
272
|
-
confirmText: "
|
|
427
|
+
title: t("mapo.delete"),
|
|
428
|
+
message: t("mapo.detail.deleteQuestion"),
|
|
429
|
+
confirmText: t("mapo.delete"),
|
|
273
430
|
dangerous: true
|
|
274
431
|
});
|
|
275
432
|
if (!ok) return;
|
|
276
|
-
|
|
433
|
+
pendingAction.value = "delete";
|
|
434
|
+
let leaving = false;
|
|
277
435
|
try {
|
|
278
436
|
await crud.delete(recordId());
|
|
279
437
|
backup.value = deepClone(model.value);
|
|
280
|
-
snack.show("
|
|
438
|
+
snack.show(t("mapo.deleteSuccess"), "success");
|
|
281
439
|
emit("deleted");
|
|
282
|
-
|
|
440
|
+
leaving = leave();
|
|
283
441
|
} catch (err) {
|
|
284
|
-
|
|
285
|
-
snack.show(detail ?? "Failed to delete", "error");
|
|
442
|
+
snack.show(getErrorDetail(err) ?? t("mapo.deleteError"), "error");
|
|
286
443
|
} finally {
|
|
287
|
-
|
|
444
|
+
if (!leaving) pendingAction.value = null;
|
|
288
445
|
}
|
|
289
446
|
}
|
|
290
447
|
function back() {
|
|
448
|
+
if (isBusy.value) return;
|
|
449
|
+
pendingAction.value = "back";
|
|
450
|
+
const leaving = leave();
|
|
451
|
+
if (!leaving) pendingAction.value = null;
|
|
452
|
+
}
|
|
453
|
+
function leave() {
|
|
454
|
+
const hasPreviousPage = router.options.history.state.back != null;
|
|
455
|
+
if (hasPreviousPage) {
|
|
456
|
+
const stopWatching = router.afterEach((_to, _from, failure) => {
|
|
457
|
+
stopWatching();
|
|
458
|
+
if (failure) pendingAction.value = null;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
291
461
|
router.back();
|
|
462
|
+
return hasPreviousPage;
|
|
292
463
|
}
|
|
293
464
|
async function guardUnsaved() {
|
|
294
465
|
if (!isDirty.value) return true;
|
|
295
466
|
return confirm.ask({
|
|
296
|
-
title: "
|
|
297
|
-
message: "
|
|
298
|
-
confirmText: "
|
|
467
|
+
title: t("mapo.unsavedData"),
|
|
468
|
+
message: t("mapo.confirmLeaveChanges"),
|
|
469
|
+
confirmText: t("mapo.leave"),
|
|
299
470
|
dangerous: true
|
|
300
471
|
});
|
|
301
472
|
}
|
|
@@ -319,6 +490,7 @@ onMounted(() => {
|
|
|
319
490
|
preventWindowClose
|
|
320
491
|
);
|
|
321
492
|
}
|
|
493
|
+
describeEndpoint();
|
|
322
494
|
fetchModel();
|
|
323
495
|
});
|
|
324
496
|
onBeforeUnmount(() => {
|
|
@@ -329,6 +501,48 @@ onBeforeUnmount(() => {
|
|
|
329
501
|
);
|
|
330
502
|
}
|
|
331
503
|
});
|
|
504
|
+
const innerAnnotations = ref({});
|
|
505
|
+
const formAnnotations = computed(() => ({
|
|
506
|
+
...innerAnnotations.value,
|
|
507
|
+
...props.annotations ?? {}
|
|
508
|
+
}));
|
|
509
|
+
let metadataRequest;
|
|
510
|
+
function describe() {
|
|
511
|
+
metadataRequest ??= crud.options().then(
|
|
512
|
+
(response) => typeof response === "object" && response !== null ? response : void 0,
|
|
513
|
+
() => void 0
|
|
514
|
+
);
|
|
515
|
+
return metadataRequest;
|
|
516
|
+
}
|
|
517
|
+
const context = {
|
|
518
|
+
endpoint: computed(() => props.endpoint),
|
|
519
|
+
id: computed(() => props.id),
|
|
520
|
+
isNew,
|
|
521
|
+
modelName: computed(() => props.modelName ?? null),
|
|
522
|
+
permissionModel: computed(() => props.permissionModel),
|
|
523
|
+
model,
|
|
524
|
+
fields: activeFields,
|
|
525
|
+
sidebarFields: computed(() => props.sidebarFields ?? []),
|
|
526
|
+
languages: activeLangs,
|
|
527
|
+
currentLang,
|
|
528
|
+
registry,
|
|
529
|
+
errors,
|
|
530
|
+
readonly: effectiveReadonly,
|
|
531
|
+
isLoading,
|
|
532
|
+
isSaving,
|
|
533
|
+
isBusy,
|
|
534
|
+
isDirty,
|
|
535
|
+
annotations: innerAnnotations,
|
|
536
|
+
extensions: computed(() => props.extensions),
|
|
537
|
+
save,
|
|
538
|
+
back,
|
|
539
|
+
metadata: describe,
|
|
540
|
+
schemaFromMetadata: computed(() => props.schemaFromMetadata),
|
|
541
|
+
onSaved,
|
|
542
|
+
draft: { part: addDraftPart, touch: () => saveDraftSoon() },
|
|
543
|
+
revealField
|
|
544
|
+
};
|
|
545
|
+
provide(DETAIL_KEY, context);
|
|
332
546
|
const slots = useSlots();
|
|
333
547
|
const formSlotNames = computed(
|
|
334
548
|
() => Object.keys(slots).filter(
|
|
@@ -337,6 +551,8 @@ const formSlotNames = computed(
|
|
|
337
551
|
);
|
|
338
552
|
const slotBindings = computed(() => ({
|
|
339
553
|
model: model.value,
|
|
554
|
+
fields: activeFields.value,
|
|
555
|
+
sidebarFields: props.sidebarFields ?? [],
|
|
340
556
|
errors: errors.value,
|
|
341
557
|
currentLang: currentLang.value,
|
|
342
558
|
isNew: isNew.value,
|
|
@@ -373,12 +589,16 @@ defineSlots();
|
|
|
373
589
|
color="warning"
|
|
374
590
|
variant="subtle"
|
|
375
591
|
class="mb-3"
|
|
376
|
-
:title="
|
|
377
|
-
|
|
592
|
+
:title="
|
|
593
|
+
t('mapo.detail.draftSavedAt', {
|
|
594
|
+
date: draftBanner.savedAt.toLocaleString()
|
|
595
|
+
})
|
|
596
|
+
"
|
|
597
|
+
:description="t('mapo.detail.draftFound')"
|
|
378
598
|
>
|
|
379
599
|
<template #actions>
|
|
380
600
|
<UButton size="xs" color="warning" @click="draftBanner?.restore()">
|
|
381
|
-
|
|
601
|
+
{{ t("mapo.restore") }}
|
|
382
602
|
</UButton>
|
|
383
603
|
<UButton
|
|
384
604
|
size="xs"
|
|
@@ -386,7 +606,7 @@ defineSlots();
|
|
|
386
606
|
variant="ghost"
|
|
387
607
|
@click="draftBanner?.discard()"
|
|
388
608
|
>
|
|
389
|
-
|
|
609
|
+
{{ t("mapo.discard") }}
|
|
390
610
|
</UButton>
|
|
391
611
|
</template>
|
|
392
612
|
</UAlert>
|
|
@@ -396,7 +616,7 @@ defineSlots();
|
|
|
396
616
|
<!-- Title -->
|
|
397
617
|
<slot name="title" v-bind="slotBindings">
|
|
398
618
|
<h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-6">
|
|
399
|
-
{{ isNew ? "
|
|
619
|
+
{{ isNew ? t("mapo.new") : t("mapo.edit") }}
|
|
400
620
|
<span v-if="modelName"> {{ modelName }}</span>
|
|
401
621
|
</h1>
|
|
402
622
|
</slot>
|
|
@@ -411,21 +631,25 @@ defineSlots();
|
|
|
411
631
|
v-model="currentLang"
|
|
412
632
|
:langs="activeLangs"
|
|
413
633
|
:errors="errors"
|
|
634
|
+
:lang-threshold="langThreshold"
|
|
414
635
|
/>
|
|
415
636
|
</slot>
|
|
416
637
|
|
|
638
|
+
<MapoDetailExtensions placement="body-top" />
|
|
639
|
+
|
|
417
640
|
<slot name="body-top" v-bind="slotBindings" />
|
|
418
641
|
|
|
419
642
|
<!-- Main form -->
|
|
420
643
|
<slot name="body" v-bind="slotBindings">
|
|
421
644
|
<MapoForm
|
|
422
645
|
v-model="model"
|
|
423
|
-
:fields="
|
|
646
|
+
:fields="activeFields"
|
|
424
647
|
:errors="errors"
|
|
425
648
|
:languages="activeLangs"
|
|
426
649
|
:current-lang="currentLang"
|
|
427
650
|
:registry="registry"
|
|
428
651
|
:readonly="effectiveReadonly"
|
|
652
|
+
:annotations="formAnnotations"
|
|
429
653
|
>
|
|
430
654
|
<template
|
|
431
655
|
v-for="slotName in formSlotNames"
|
|
@@ -443,19 +667,23 @@ defineSlots();
|
|
|
443
667
|
<!-- Sidebar column -->
|
|
444
668
|
<div :class="sidebarColsClass">
|
|
445
669
|
<div :style="sidebarStyle" class="space-y-4">
|
|
446
|
-
<!-- Action buttons (Save / Save&continue / Back — no delete here)
|
|
670
|
+
<!-- Action buttons (Save / Save&continue / Back — no delete here).
|
|
671
|
+
While one works, it spins and all of them are disabled. -->
|
|
447
672
|
<slot name="side-buttons" v-bind="slotBindings">
|
|
448
673
|
<UCard>
|
|
449
674
|
<div class="flex flex-col gap-2">
|
|
675
|
+
<MapoDetailExtensions placement="actions" />
|
|
676
|
+
|
|
450
677
|
<slot name="button-save" v-bind="slotBindings">
|
|
451
678
|
<UButton
|
|
452
679
|
v-if="!effectiveReadonly"
|
|
453
680
|
block
|
|
454
|
-
:loading="
|
|
681
|
+
:loading="pendingAction === 'save'"
|
|
682
|
+
:disabled="isBusy"
|
|
455
683
|
icon="i-lucide-save"
|
|
456
684
|
@click="save(true)"
|
|
457
685
|
>
|
|
458
|
-
{{ isNew ? "
|
|
686
|
+
{{ isNew ? t("mapo.create") : t("mapo.save") }}
|
|
459
687
|
</UButton>
|
|
460
688
|
</slot>
|
|
461
689
|
|
|
@@ -464,11 +692,14 @@ defineSlots();
|
|
|
464
692
|
v-if="!effectiveReadonly"
|
|
465
693
|
block
|
|
466
694
|
variant="soft"
|
|
467
|
-
:loading="
|
|
695
|
+
:loading="pendingAction === 'saveContinue'"
|
|
696
|
+
:disabled="isBusy"
|
|
468
697
|
icon="i-lucide-save"
|
|
469
698
|
@click="save(false)"
|
|
470
699
|
>
|
|
471
|
-
{{
|
|
700
|
+
{{
|
|
701
|
+
isNew ? t("mapo.createContinue") : t("mapo.saveContinue")
|
|
702
|
+
}}
|
|
472
703
|
</UButton>
|
|
473
704
|
</slot>
|
|
474
705
|
|
|
@@ -477,9 +708,11 @@ defineSlots();
|
|
|
477
708
|
block
|
|
478
709
|
variant="ghost"
|
|
479
710
|
icon="i-lucide-arrow-left"
|
|
711
|
+
:loading="pendingAction === 'back'"
|
|
712
|
+
:disabled="isBusy"
|
|
480
713
|
@click="back"
|
|
481
714
|
>
|
|
482
|
-
|
|
715
|
+
{{ t("mapo.back") }}
|
|
483
716
|
</UButton>
|
|
484
717
|
</slot>
|
|
485
718
|
</div>
|
|
@@ -501,6 +734,8 @@ defineSlots();
|
|
|
501
734
|
:current-lang="currentLang"
|
|
502
735
|
:registry="registry"
|
|
503
736
|
:readonly="effectiveReadonly"
|
|
737
|
+
:annotations="formAnnotations"
|
|
738
|
+
:notify-errors="false"
|
|
504
739
|
>
|
|
505
740
|
<template
|
|
506
741
|
v-for="slotName in formSlotNames"
|
|
@@ -520,6 +755,8 @@ defineSlots();
|
|
|
520
755
|
:current-lang="currentLang"
|
|
521
756
|
:registry="registry"
|
|
522
757
|
:readonly="effectiveReadonly"
|
|
758
|
+
:annotations="formAnnotations"
|
|
759
|
+
:notify-errors="false"
|
|
523
760
|
>
|
|
524
761
|
<template
|
|
525
762
|
v-for="slotName in formSlotNames"
|
|
@@ -542,7 +779,7 @@ defineSlots();
|
|
|
542
779
|
icon="i-lucide-eye"
|
|
543
780
|
@click="previewOpen = true"
|
|
544
781
|
>
|
|
545
|
-
|
|
782
|
+
{{ t("mapo.preview") }}
|
|
546
783
|
</UButton>
|
|
547
784
|
|
|
548
785
|
<!-- Danger zone: delete action, visually separated from save actions -->
|
|
@@ -554,10 +791,11 @@ defineSlots();
|
|
|
554
791
|
color="error"
|
|
555
792
|
variant="soft"
|
|
556
793
|
:loading="isDeleting"
|
|
794
|
+
:disabled="isBusy"
|
|
557
795
|
icon="i-lucide-trash-2"
|
|
558
796
|
@click="deleteItem"
|
|
559
797
|
>
|
|
560
|
-
|
|
798
|
+
{{ t("mapo.delete") }}
|
|
561
799
|
</UButton>
|
|
562
800
|
</slot>
|
|
563
801
|
</UCard>
|