@mapomodule/uikit 2.0.0-beta.2 → 2.0.0-beta.20
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 +46 -142
- 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__/MapoList.component.test.d.ts +2 -0
- package/dist/__tests__/MapoList.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__/MapoMediaEditor.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMenuManager.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__/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__/mediaDrag.test.d.ts +2 -0
- package/dist/__tests__/mediaDrag.test.d.ts.map +1 -0
- package/dist/__tests__/mediaFolders.test.d.ts +2 -0
- package/dist/__tests__/mediaFolders.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__/mediaMetadata.test.d.ts +2 -0
- package/dist/__tests__/mediaMetadata.test.d.ts.map +1 -0
- package/dist/__tests__/mediaStore.test.d.ts +2 -0
- package/dist/__tests__/mediaStore.test.d.ts.map +1 -0
- package/dist/__tests__/mediaUrl.test.d.ts +2 -0
- package/dist/__tests__/mediaUrl.test.d.ts.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/module.d.mts +48 -1
- package/dist/module.d.ts +44 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +71 -2
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts +15 -0
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
- package/dist/runtime/adapters/defaultMediaAdapter.js +35 -0
- 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 +127 -55
- package/dist/runtime/components/MapoDetail.vue.d.ts +102 -5
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- 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 +110 -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 +45 -31
- package/dist/runtime/components/MapoList.vue.d.ts +18 -5
- 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 +20 -10
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +125 -49
- package/dist/runtime/components/MapoListTable.vue.d.ts +13 -5
- 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 +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 +382 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +13 -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/MapoMediaFolderPicker.vue +129 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts +33 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolders.vue +402 -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 +304 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManager.vue +144 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts +44 -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 +94 -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 +294 -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 +301 -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/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/pages/index.vue +4 -3
- package/dist/runtime/pages/index.vue.d.ts.map +1 -1
- package/dist/runtime/pages/login.vue +0 -4
- package/dist/runtime/pages/login.vue.d.ts.map +1 -1
- 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 +505 -0
- package/dist/runtime/stores/media.d.ts.map +1 -0
- package/dist/runtime/stores/media.js +545 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/types/media.d.ts +131 -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/contentLanguages.d.ts +9 -0
- package/dist/runtime/utils/contentLanguages.d.ts.map +1 -0
- package/dist/runtime/utils/contentLanguages.js +8 -0
- package/dist/runtime/utils/langInfo.d.ts +43 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +17 -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/dist/runtime/utils/mediaDrag.d.ts +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts.map +1 -0
- package/dist/runtime/utils/mediaDrag.js +11 -0
- package/dist/runtime/utils/mediaFolders.d.ts +65 -0
- package/dist/runtime/utils/mediaFolders.d.ts.map +1 -0
- package/dist/runtime/utils/mediaFolders.js +97 -0
- package/dist/runtime/utils/mediaMetadata.d.ts +39 -0
- package/dist/runtime/utils/mediaMetadata.d.ts.map +1 -0
- package/dist/runtime/utils/mediaMetadata.js +97 -0
- package/dist/runtime/utils/mediaUrl.d.ts +16 -0
- package/dist/runtime/utils/mediaUrl.d.ts.map +1 -0
- package/dist/runtime/utils/mediaUrl.js +12 -0
- package/dist/types.d.mts +1 -1
- package/package.json +15 -11
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +393 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoList.component.test.ts +166 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +545 -0
- package/src/__tests__/MapoMediaEditor.component.test.ts +447 -0
- package/src/__tests__/MapoMediaFolderPicker.component.test.ts +220 -0
- package/src/__tests__/MapoMediaFolders.component.test.ts +519 -0
- package/src/__tests__/MapoMediaGallery.component.test.ts +211 -0
- package/src/__tests__/MapoMediaUploadHandover.component.test.ts +241 -0
- package/src/__tests__/MapoMenuManager.component.test.ts +175 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/langInfo.test.ts +85 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaDrag.test.ts +42 -0
- package/src/__tests__/mediaFolders.test.ts +204 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/mediaMetadata.test.ts +169 -0
- package/src/__tests__/mediaStore.test.ts +569 -0
- package/src/__tests__/mediaUrl.test.ts +44 -0
- package/src/index.ts +21 -0
- package/src/module.ts +155 -0
- package/src/runtime/adapters/defaultMediaAdapter.ts +67 -0
- package/src/runtime/assets/main.css +9 -0
- package/src/runtime/components/MapoConfirmDialog.vue +33 -4
- package/src/runtime/components/MapoDetail.vue +229 -73
- package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
- package/src/runtime/components/MapoDropArea.vue +145 -0
- package/src/runtime/components/MapoLangSwitcher.vue +74 -0
- package/src/runtime/components/MapoList.vue +65 -34
- package/src/runtime/components/MapoListActions.vue +32 -14
- package/src/runtime/components/MapoListFilters.vue +5 -2
- package/src/runtime/components/MapoListQuickEdit.vue +22 -10
- package/src/runtime/components/MapoListTable.vue +159 -59
- 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 +447 -0
- package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
- package/src/runtime/components/MapoMediaFolderPicker.vue +176 -0
- package/src/runtime/components/MapoMediaFolders.vue +478 -0
- package/src/runtime/components/MapoMediaGallery.vue +350 -0
- package/src/runtime/components/MapoMediaManager.vue +194 -0
- package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
- package/src/runtime/components/MapoMediaPreview.vue +116 -0
- package/src/runtime/components/MapoMediaUploader.vue +362 -0
- package/src/runtime/components/MapoMenuManager.vue +454 -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/page-meta.nuxt.d.ts +4 -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 +820 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/types/media.ts +144 -0
- package/src/runtime/types/menu.ts +105 -0
- package/src/runtime/utils/contentLanguages.ts +18 -0
- package/src/runtime/utils/langInfo.ts +63 -0
- package/src/runtime/utils/listTable.ts +54 -0
- package/src/runtime/utils/mediaDrag.ts +29 -0
- package/src/runtime/utils/mediaFolders.ts +182 -0
- package/src/runtime/utils/mediaMetadata.ts +165 -0
- package/src/runtime/utils/mediaUrl.ts +30 -0
|
@@ -10,15 +10,26 @@ import {
|
|
|
10
10
|
provide,
|
|
11
11
|
type Ref,
|
|
12
12
|
type VNode,
|
|
13
|
+
shallowRef,
|
|
13
14
|
} from "vue";
|
|
14
|
-
import { useRouter, onBeforeRouteLeave } from "
|
|
15
|
-
import {
|
|
15
|
+
import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
|
|
16
|
+
import { useI18n } from "vue-i18n";
|
|
16
17
|
import { objectDiff, debounce, deepClone } from "@mapomodule/utils";
|
|
17
18
|
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
19
|
+
import {
|
|
20
|
+
getErrorData,
|
|
21
|
+
getErrorDetail,
|
|
22
|
+
getErrorStatus,
|
|
23
|
+
} from "@mapomodule/core/runtime/utils/fetchError";
|
|
18
24
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
19
25
|
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
20
26
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
21
27
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
28
|
+
import { languagesFromMetadata, restrictLanguages } from "../utils/langInfo";
|
|
29
|
+
import { useContentLanguages } from "../utils/contentLanguages";
|
|
30
|
+
import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
|
|
31
|
+
import type { UseFormFromSchemaOptions } from "@mapomodule/form/runtime/composables/useFormFromSchema";
|
|
32
|
+
import type { JSONSchema } from "@mapomodule/utils";
|
|
22
33
|
import type { MultipartPolicy } from "@mapomodule/core";
|
|
23
34
|
|
|
24
35
|
// ─── Props ────────────────────────────────────────────────────────────────────
|
|
@@ -29,12 +40,38 @@ const props = withDefaults(
|
|
|
29
40
|
endpoint: string;
|
|
30
41
|
/** Record id. Pass `'new'` to create. */
|
|
31
42
|
id: string | number;
|
|
32
|
-
/**
|
|
33
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Fields for the main body form.
|
|
45
|
+
*
|
|
46
|
+
* Optional only so `experimentalFieldsFromSchema` can supply them; pass them
|
|
47
|
+
* explicitly for any form you care about the layout of.
|
|
48
|
+
*/
|
|
49
|
+
fields?: AnyFieldDescriptor<T>[];
|
|
50
|
+
/**
|
|
51
|
+
* EXPERIMENTAL. Build the body fields from the endpoint's OPTIONS schema
|
|
52
|
+
* when `fields` is not given.
|
|
53
|
+
*
|
|
54
|
+
* Off by default and deliberately opt-in: a derived form knows types,
|
|
55
|
+
* labels, relations and what is read-only, but nothing editorial — no tabs,
|
|
56
|
+
* no column widths, no rich-text vs textarea, no sidebar split, and no
|
|
57
|
+
* opinion about field order beyond the serializer's. Treat it as a
|
|
58
|
+
* scaffold to start from, not a finished panel.
|
|
59
|
+
*
|
|
60
|
+
* Requires a backend that publishes `schema` on OPTIONS (camomilla >= 6.6).
|
|
61
|
+
*/
|
|
62
|
+
experimentalFieldsFromSchema?: boolean;
|
|
63
|
+
/** Passed straight to useFormFromSchema when deriving. */
|
|
64
|
+
schemaFieldOptions?: UseFormFromSchemaOptions;
|
|
34
65
|
/** Fields for the sidebar form (optional). */
|
|
35
66
|
sidebarFields?: AnyFieldDescriptor<T>[];
|
|
36
67
|
/** Translation language codes (e.g. ['it', 'en']). */
|
|
37
68
|
languages?: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Number of languages above which the language switcher adds a searchable
|
|
71
|
+
* select next to its tabs. Default `8` (from MapoDetailLangSwitch); `0`
|
|
72
|
+
* always shows it.
|
|
73
|
+
*/
|
|
74
|
+
langThreshold?: number;
|
|
38
75
|
/** Human readable model name shown in the page title. */
|
|
39
76
|
modelName?: string | null;
|
|
40
77
|
/** Sidebar column span (1–11 in a 12-col grid). */
|
|
@@ -81,15 +118,19 @@ const props = withDefaults(
|
|
|
81
118
|
*/
|
|
82
119
|
previewField?: string;
|
|
83
120
|
/**
|
|
84
|
-
* Override the language list regardless of what
|
|
85
|
-
*
|
|
86
|
-
*
|
|
121
|
+
* Override the language list regardless of what the backend declares
|
|
122
|
+
* (`lang_info.languages`). Takes precedence over the `languages` prop, the
|
|
123
|
+
* auto-derived list and the app's `mapo.uikit.contentLanguages`.
|
|
87
124
|
*/
|
|
88
125
|
forceLanguages?: string[];
|
|
89
126
|
}>(),
|
|
90
127
|
{
|
|
128
|
+
fields: undefined,
|
|
129
|
+
experimentalFieldsFromSchema: false,
|
|
130
|
+
schemaFieldOptions: undefined,
|
|
91
131
|
sidebarFields: () => [],
|
|
92
132
|
languages: () => [],
|
|
133
|
+
langThreshold: undefined,
|
|
93
134
|
sidebarCols: 4,
|
|
94
135
|
sticky: true,
|
|
95
136
|
usePatch: true,
|
|
@@ -128,6 +169,7 @@ const { $mapoFormRegistry } = useNuxtApp() as unknown as {
|
|
|
128
169
|
};
|
|
129
170
|
const registry = computed(() => props.registry ?? $mapoFormRegistry);
|
|
130
171
|
|
|
172
|
+
const { t } = useI18n();
|
|
131
173
|
const router = useRouter();
|
|
132
174
|
const snack = useSnackStore();
|
|
133
175
|
const confirm = useConfirmStore();
|
|
@@ -161,9 +203,25 @@ const errors = ref<Record<string, string[]>>({});
|
|
|
161
203
|
// Start in loading state for existing items so MapoForm is never mounted with
|
|
162
204
|
// empty data and then immediately unmounted when the spinner appears on mount.
|
|
163
205
|
const isLoading = ref(String(props.id) !== "new");
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The action under way, from the click until its work is done, navigation
|
|
209
|
+
* included: one at a time, so a second click cannot save again or go back one
|
|
210
|
+
* more step in the history. Named after the buttons.
|
|
211
|
+
*/
|
|
212
|
+
type DetailAction = "save" | "saveContinue" | "delete" | "back";
|
|
213
|
+
const pendingAction = ref<DetailAction | null>(null);
|
|
214
|
+
const isBusy = computed(() => pendingAction.value !== null);
|
|
215
|
+
const isSaving = computed(() => {
|
|
216
|
+
const savingAndLeaving = pendingAction.value === "save";
|
|
217
|
+
const savingAndStaying = pendingAction.value === "saveContinue";
|
|
218
|
+
return savingAndLeaving || savingAndStaying;
|
|
219
|
+
});
|
|
220
|
+
const isDeleting = computed(() => pendingAction.value === "delete");
|
|
221
|
+
// Set by the `activeLangs` watcher below, to the first language actually
|
|
222
|
+
// offered: `languages[0]` can be one `mapo.uikit.contentLanguages` hides or
|
|
223
|
+
// puts later.
|
|
224
|
+
const currentLang = ref("");
|
|
167
225
|
const draftBanner = ref<{
|
|
168
226
|
savedAt: Date;
|
|
169
227
|
restore: () => void;
|
|
@@ -178,19 +236,29 @@ const isDirty = computed(
|
|
|
178
236
|
const mainCols = computed(() => 12 - props.sidebarCols);
|
|
179
237
|
|
|
180
238
|
// ─── Languages (auto-derive from lang_info) ──────────────────────────────────
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
//
|
|
239
|
+
// Camomilla describes the MODEL's language situation in the endpoint's OPTIONS
|
|
240
|
+
// metadata, so the host page doesn't hard-code a language list — and a model
|
|
241
|
+
// that is not registered for translation shows no switcher at all, rather than
|
|
242
|
+
// tabs whose extra values the backend would drop.
|
|
243
|
+
// forceLanguages > (props.languages > derived), narrowed to the app's
|
|
244
|
+
// `mapo.uikit.contentLanguages`.
|
|
184
245
|
const derivedLangs = ref<string[]>([]);
|
|
246
|
+
const contentLanguages = useContentLanguages();
|
|
185
247
|
const activeLangs = computed<string[]>(() => {
|
|
186
248
|
if (props.forceLanguages?.length) return props.forceLanguages;
|
|
187
|
-
|
|
188
|
-
|
|
249
|
+
const declared = props.languages.length
|
|
250
|
+
? props.languages
|
|
251
|
+
: derivedLangs.value;
|
|
252
|
+
return restrictLanguages(declared, contentLanguages);
|
|
189
253
|
});
|
|
254
|
+
// Start on the first language, and move there when the current one is not
|
|
255
|
+
// offered (any more): the first of `languages` can be one the app hides.
|
|
190
256
|
watch(
|
|
191
257
|
activeLangs,
|
|
192
258
|
(langs) => {
|
|
193
|
-
|
|
259
|
+
const isOffered = langs.includes(currentLang.value);
|
|
260
|
+
if (isOffered || !langs.length) return;
|
|
261
|
+
currentLang.value = langs[0]!;
|
|
194
262
|
},
|
|
195
263
|
{ immediate: true },
|
|
196
264
|
);
|
|
@@ -318,6 +386,58 @@ if (props.draft || props.draftKey) {
|
|
|
318
386
|
|
|
319
387
|
// ─── Fetch ───────────────────────────────────────────────────────────────────
|
|
320
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Body fields derived from the OPTIONS schema; empty unless opted in.
|
|
391
|
+
*
|
|
392
|
+
* shallowRef, not ref: the array is replaced wholesale, never mutated in place,
|
|
393
|
+
* and deep reactivity over descriptors (which carry functions) buys nothing.
|
|
394
|
+
* It also keeps the generic intact — ref()'s UnwrapRef erases the T in
|
|
395
|
+
* `key: DeepKeyOf<T>`.
|
|
396
|
+
*/
|
|
397
|
+
const derivedFields = shallowRef<AnyFieldDescriptor<T>[]>([]);
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* The fields actually rendered. An explicit `fields` prop always wins — the
|
|
401
|
+
* derived set is a scaffold, never an override of a hand-built form.
|
|
402
|
+
*/
|
|
403
|
+
const activeFields = computed<AnyFieldDescriptor<T>[]>(() =>
|
|
404
|
+
props.fields?.length ? props.fields : derivedFields.value,
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Ask the endpoint to describe itself, ONCE, and take from that answer both the
|
|
409
|
+
* languages and (when opted in) the fields.
|
|
410
|
+
*
|
|
411
|
+
* Runs for existing records as well as new ones: the metadata lives on OPTIONS
|
|
412
|
+
* only, so reading the fetched record would leave an edit form with no tabs.
|
|
413
|
+
*/
|
|
414
|
+
async function describeEndpoint() {
|
|
415
|
+
const wantsLangs = !props.languages.length && !props.forceLanguages?.length;
|
|
416
|
+
const wantsFields =
|
|
417
|
+
props.experimentalFieldsFromSchema && !props.fields?.length;
|
|
418
|
+
if (!wantsLangs && !wantsFields) return;
|
|
419
|
+
|
|
420
|
+
let metadata: Record<string, unknown>;
|
|
421
|
+
try {
|
|
422
|
+
metadata = (await crud.options()) as Record<string, unknown>;
|
|
423
|
+
} catch {
|
|
424
|
+
// A backend without OPTIONS metadata is not an error worth surfacing: it
|
|
425
|
+
// just means nothing is auto-derived.
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (wantsLangs) derivedLangs.value = languagesFromMetadata(metadata);
|
|
430
|
+
if (wantsFields) {
|
|
431
|
+
const schema = metadata.schema as JSONSchema | undefined;
|
|
432
|
+
if (schema?.properties) {
|
|
433
|
+
derivedFields.value = useFormFromSchema(
|
|
434
|
+
schema,
|
|
435
|
+
props.schemaFieldOptions,
|
|
436
|
+
) as AnyFieldDescriptor<T>[];
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
321
441
|
async function fetchModel() {
|
|
322
442
|
if (isNew.value) {
|
|
323
443
|
backup.value = null;
|
|
@@ -328,27 +448,10 @@ async function fetchModel() {
|
|
|
328
448
|
try {
|
|
329
449
|
model.value = await crud.detail(props.id);
|
|
330
450
|
backup.value = deepClone(model.value) as T;
|
|
331
|
-
// Auto-derive languages from the backend response when the host page does
|
|
332
|
-
// not hard-code them. Camomilla embeds site_languages inside lang_info.
|
|
333
|
-
const langInfo = (model.value as Record<string, unknown>)?.lang_info as
|
|
334
|
-
| Record<string, unknown>
|
|
335
|
-
| undefined;
|
|
336
|
-
const siteLangs = langInfo?.site_languages as string[] | undefined;
|
|
337
|
-
if (
|
|
338
|
-
siteLangs?.length &&
|
|
339
|
-
!props.languages.length &&
|
|
340
|
-
!props.forceLanguages?.length
|
|
341
|
-
) {
|
|
342
|
-
derivedLangs.value = siteLangs;
|
|
343
|
-
}
|
|
344
451
|
checkDraft();
|
|
345
452
|
} catch (err: unknown) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const detail = (err as { response?: { data?: { detail?: string } } })
|
|
349
|
-
?.response?.data?.detail;
|
|
350
|
-
snack.show(detail ?? "Failed to load item", "error");
|
|
351
|
-
if (status === 404) router.back();
|
|
453
|
+
snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
|
|
454
|
+
if (getErrorStatus(err) === 404) router.back();
|
|
352
455
|
} finally {
|
|
353
456
|
isLoading.value = false;
|
|
354
457
|
}
|
|
@@ -357,6 +460,10 @@ async function fetchModel() {
|
|
|
357
460
|
// ─── Save ────────────────────────────────────────────────────────────────────
|
|
358
461
|
|
|
359
462
|
async function save(andBack = false) {
|
|
463
|
+
// The built-in buttons are disabled meanwhile; a custom one bound to `save`
|
|
464
|
+
// may not be.
|
|
465
|
+
if (isBusy.value) return;
|
|
466
|
+
|
|
360
467
|
const validationResults = formValidators.map((fn) => fn());
|
|
361
468
|
const allValid = validationResults.every((r) => r.valid);
|
|
362
469
|
if (!allValid) {
|
|
@@ -365,13 +472,14 @@ async function save(andBack = false) {
|
|
|
365
472
|
);
|
|
366
473
|
const message = fieldErrors.length
|
|
367
474
|
? fieldErrors.map(([field, msg]) => `${field}: ${msg}`).join("\n")
|
|
368
|
-
: "
|
|
475
|
+
: t("mapo.fixErrors");
|
|
369
476
|
snack.show(message, "error");
|
|
370
477
|
return;
|
|
371
478
|
}
|
|
372
479
|
|
|
373
480
|
errors.value = {};
|
|
374
|
-
|
|
481
|
+
pendingAction.value = andBack ? "save" : "saveContinue";
|
|
482
|
+
let leaving = false;
|
|
375
483
|
try {
|
|
376
484
|
const multipartOpts = { multipart: props.multipart };
|
|
377
485
|
let result: T;
|
|
@@ -397,7 +505,7 @@ async function save(andBack = false) {
|
|
|
397
505
|
backup.value = deepClone(model.value) as T;
|
|
398
506
|
clearDraft();
|
|
399
507
|
snack.show(
|
|
400
|
-
isNew.value ? "
|
|
508
|
+
isNew.value ? t("mapo.createSuccess") : t("mapo.saveSuccess"),
|
|
401
509
|
"success",
|
|
402
510
|
);
|
|
403
511
|
emit("saved", model.value);
|
|
@@ -407,12 +515,10 @@ async function save(andBack = false) {
|
|
|
407
515
|
params: { id },
|
|
408
516
|
});
|
|
409
517
|
}
|
|
410
|
-
if (andBack)
|
|
518
|
+
if (andBack) leaving = leave();
|
|
411
519
|
} catch (err: unknown) {
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
const data = response?.data;
|
|
415
|
-
if (response?.status === 400 && data && typeof data === "object") {
|
|
520
|
+
const data = getErrorData(err);
|
|
521
|
+
if (getErrorStatus(err) === 400 && data && typeof data === "object") {
|
|
416
522
|
errors.value = data as Record<string, string[]>;
|
|
417
523
|
// Field-level errors: the useMapoForm watcher shows the detailed toast.
|
|
418
524
|
// Only surface a toast here if the response carries a top-level detail message.
|
|
@@ -420,10 +526,11 @@ async function save(andBack = false) {
|
|
|
420
526
|
if (detail) snack.show(detail, "error");
|
|
421
527
|
} else {
|
|
422
528
|
const detail = (data as { detail?: string } | undefined)?.detail;
|
|
423
|
-
snack.show(detail ?? "
|
|
529
|
+
snack.show(detail ?? t("mapo.saveError"), "error");
|
|
424
530
|
}
|
|
425
531
|
} finally {
|
|
426
|
-
|
|
532
|
+
// Going back: still busy until the page is gone (see leave()).
|
|
533
|
+
if (!leaving) pendingAction.value = null;
|
|
427
534
|
}
|
|
428
535
|
}
|
|
429
536
|
|
|
@@ -435,42 +542,68 @@ function getPatch(): Partial<T> {
|
|
|
435
542
|
// ─── Delete ──────────────────────────────────────────────────────────────────
|
|
436
543
|
|
|
437
544
|
async function deleteItem() {
|
|
545
|
+
if (isBusy.value) return;
|
|
438
546
|
const ok = await confirm.ask({
|
|
439
|
-
title: "
|
|
440
|
-
message:
|
|
441
|
-
|
|
442
|
-
confirmText: "Delete",
|
|
547
|
+
title: t("mapo.delete"),
|
|
548
|
+
message: t("mapo.detail.deleteQuestion"),
|
|
549
|
+
confirmText: t("mapo.delete"),
|
|
443
550
|
dangerous: true,
|
|
444
551
|
});
|
|
445
552
|
if (!ok) return;
|
|
446
|
-
|
|
553
|
+
pendingAction.value = "delete";
|
|
554
|
+
let leaving = false;
|
|
447
555
|
try {
|
|
448
556
|
await crud.delete(recordId());
|
|
449
557
|
backup.value = deepClone(model.value) as T; // clear dirty so guard doesn't fire
|
|
450
|
-
snack.show("
|
|
558
|
+
snack.show(t("mapo.deleteSuccess"), "success");
|
|
451
559
|
emit("deleted");
|
|
452
|
-
|
|
560
|
+
leaving = leave();
|
|
453
561
|
} catch (err: unknown) {
|
|
454
|
-
|
|
455
|
-
?.response?.data?.detail;
|
|
456
|
-
snack.show(detail ?? "Failed to delete", "error");
|
|
562
|
+
snack.show(getErrorDetail(err) ?? t("mapo.deleteError"), "error");
|
|
457
563
|
} finally {
|
|
458
|
-
|
|
564
|
+
if (!leaving) pendingAction.value = null;
|
|
459
565
|
}
|
|
460
566
|
}
|
|
461
567
|
|
|
462
568
|
// ─── Navigation guard ────────────────────────────────────────────────────────
|
|
463
569
|
|
|
464
570
|
function back() {
|
|
571
|
+
if (isBusy.value) return;
|
|
572
|
+
pendingAction.value = "back";
|
|
573
|
+
const leaving = leave();
|
|
574
|
+
if (!leaving) pendingAction.value = null;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Goes back one step and tells whether that is a navigation inside the app.
|
|
579
|
+
*
|
|
580
|
+
* router.back() does not wait for the navigation, and this page stays on screen
|
|
581
|
+
* until the previous route is ready. So the caller keeps its action pending
|
|
582
|
+
* until the page is gone; if the navigation fails (a guard kept the page, such
|
|
583
|
+
* as the unsaved-changes one), the action is released and the buttons work
|
|
584
|
+
* again.
|
|
585
|
+
*/
|
|
586
|
+
function leave(): boolean {
|
|
587
|
+
// Opened directly (a new tab, a bookmark): no page of the app to go back to,
|
|
588
|
+
// router.back() leaves the app or does nothing, and nothing would release
|
|
589
|
+
// the buttons.
|
|
590
|
+
const hasPreviousPage = router.options.history.state.back != null;
|
|
591
|
+
if (hasPreviousPage) {
|
|
592
|
+
const stopWatching = router.afterEach((_to, _from, failure) => {
|
|
593
|
+
stopWatching();
|
|
594
|
+
if (failure) pendingAction.value = null;
|
|
595
|
+
});
|
|
596
|
+
}
|
|
465
597
|
router.back();
|
|
598
|
+
return hasPreviousPage;
|
|
466
599
|
}
|
|
467
600
|
|
|
468
601
|
async function guardUnsaved(): Promise<boolean> {
|
|
469
602
|
if (!isDirty.value) return true;
|
|
470
603
|
return confirm.ask({
|
|
471
|
-
title: "
|
|
472
|
-
message: "
|
|
473
|
-
confirmText: "
|
|
604
|
+
title: t("mapo.unsavedData"),
|
|
605
|
+
message: t("mapo.confirmLeaveChanges"),
|
|
606
|
+
confirmText: t("mapo.leave"),
|
|
474
607
|
dangerous: true,
|
|
475
608
|
});
|
|
476
609
|
}
|
|
@@ -497,6 +630,9 @@ onMounted(() => {
|
|
|
497
630
|
preventWindowClose,
|
|
498
631
|
);
|
|
499
632
|
}
|
|
633
|
+
// Independent of the record fetch: languages come from OPTIONS either way,
|
|
634
|
+
// and a new record has no fetch to piggyback on.
|
|
635
|
+
describeEndpoint();
|
|
500
636
|
fetchModel();
|
|
501
637
|
});
|
|
502
638
|
|
|
@@ -557,14 +693,19 @@ type SlotBindings = {
|
|
|
557
693
|
currentLang: string;
|
|
558
694
|
isNew: boolean;
|
|
559
695
|
isLoading: boolean;
|
|
696
|
+
/** From the click until the save is done; after `save(true)`, until the page has gone back. */
|
|
560
697
|
isSaving: boolean;
|
|
698
|
+
/** From the confirmation until the delete is done and the page has gone back. */
|
|
561
699
|
isDeleting: boolean;
|
|
562
700
|
isDirty: boolean;
|
|
563
701
|
draftBanner: DraftBannerState;
|
|
564
702
|
readonly: boolean;
|
|
565
703
|
canDelete: boolean;
|
|
704
|
+
/** Ignored while a save, a delete or a navigation back is under way. */
|
|
566
705
|
save: (andBack?: boolean) => Promise<void>;
|
|
706
|
+
/** Ignored while a save, a delete or a navigation back is under way. */
|
|
567
707
|
deleteItem: () => Promise<void>;
|
|
708
|
+
/** Ignored while a save, a delete or a navigation back is under way. */
|
|
568
709
|
back: () => void;
|
|
569
710
|
};
|
|
570
711
|
|
|
@@ -636,12 +777,16 @@ defineSlots<{
|
|
|
636
777
|
color="warning"
|
|
637
778
|
variant="subtle"
|
|
638
779
|
class="mb-3"
|
|
639
|
-
:title="
|
|
640
|
-
|
|
780
|
+
:title="
|
|
781
|
+
t('mapo.detail.draftSavedAt', {
|
|
782
|
+
date: draftBanner.savedAt.toLocaleString(),
|
|
783
|
+
})
|
|
784
|
+
"
|
|
785
|
+
:description="t('mapo.detail.draftFound')"
|
|
641
786
|
>
|
|
642
787
|
<template #actions>
|
|
643
788
|
<UButton size="xs" color="warning" @click="draftBanner?.restore()">
|
|
644
|
-
|
|
789
|
+
{{ t("mapo.restore") }}
|
|
645
790
|
</UButton>
|
|
646
791
|
<UButton
|
|
647
792
|
size="xs"
|
|
@@ -649,7 +794,7 @@ defineSlots<{
|
|
|
649
794
|
variant="ghost"
|
|
650
795
|
@click="draftBanner?.discard()"
|
|
651
796
|
>
|
|
652
|
-
|
|
797
|
+
{{ t("mapo.discard") }}
|
|
653
798
|
</UButton>
|
|
654
799
|
</template>
|
|
655
800
|
</UAlert>
|
|
@@ -659,7 +804,7 @@ defineSlots<{
|
|
|
659
804
|
<!-- Title -->
|
|
660
805
|
<slot name="title" v-bind="slotBindings">
|
|
661
806
|
<h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-6">
|
|
662
|
-
{{ isNew ? "
|
|
807
|
+
{{ isNew ? t("mapo.new") : t("mapo.edit") }}
|
|
663
808
|
<span v-if="modelName"> {{ modelName }}</span>
|
|
664
809
|
</h1>
|
|
665
810
|
</slot>
|
|
@@ -674,6 +819,7 @@ defineSlots<{
|
|
|
674
819
|
v-model="currentLang"
|
|
675
820
|
:langs="activeLangs"
|
|
676
821
|
:errors="errors"
|
|
822
|
+
:lang-threshold="langThreshold"
|
|
677
823
|
/>
|
|
678
824
|
</slot>
|
|
679
825
|
|
|
@@ -683,7 +829,7 @@ defineSlots<{
|
|
|
683
829
|
<slot name="body" v-bind="slotBindings">
|
|
684
830
|
<MapoForm
|
|
685
831
|
v-model="model"
|
|
686
|
-
:fields="
|
|
832
|
+
:fields="activeFields"
|
|
687
833
|
:errors="errors"
|
|
688
834
|
:languages="activeLangs"
|
|
689
835
|
:current-lang="currentLang"
|
|
@@ -706,7 +852,8 @@ defineSlots<{
|
|
|
706
852
|
<!-- Sidebar column -->
|
|
707
853
|
<div :class="sidebarColsClass">
|
|
708
854
|
<div :style="sidebarStyle" class="space-y-4">
|
|
709
|
-
<!-- Action buttons (Save / Save&continue / Back — no delete here)
|
|
855
|
+
<!-- Action buttons (Save / Save&continue / Back — no delete here).
|
|
856
|
+
While one works, it spins and all of them are disabled. -->
|
|
710
857
|
<slot name="side-buttons" v-bind="slotBindings">
|
|
711
858
|
<UCard>
|
|
712
859
|
<div class="flex flex-col gap-2">
|
|
@@ -714,11 +861,12 @@ defineSlots<{
|
|
|
714
861
|
<UButton
|
|
715
862
|
v-if="!effectiveReadonly"
|
|
716
863
|
block
|
|
717
|
-
:loading="
|
|
864
|
+
:loading="pendingAction === 'save'"
|
|
865
|
+
:disabled="isBusy"
|
|
718
866
|
icon="i-lucide-save"
|
|
719
867
|
@click="save(true)"
|
|
720
868
|
>
|
|
721
|
-
{{ isNew ? "
|
|
869
|
+
{{ isNew ? t("mapo.create") : t("mapo.save") }}
|
|
722
870
|
</UButton>
|
|
723
871
|
</slot>
|
|
724
872
|
|
|
@@ -727,11 +875,14 @@ defineSlots<{
|
|
|
727
875
|
v-if="!effectiveReadonly"
|
|
728
876
|
block
|
|
729
877
|
variant="soft"
|
|
730
|
-
:loading="
|
|
878
|
+
:loading="pendingAction === 'saveContinue'"
|
|
879
|
+
:disabled="isBusy"
|
|
731
880
|
icon="i-lucide-save"
|
|
732
881
|
@click="save(false)"
|
|
733
882
|
>
|
|
734
|
-
{{
|
|
883
|
+
{{
|
|
884
|
+
isNew ? t("mapo.createContinue") : t("mapo.saveContinue")
|
|
885
|
+
}}
|
|
735
886
|
</UButton>
|
|
736
887
|
</slot>
|
|
737
888
|
|
|
@@ -740,9 +891,11 @@ defineSlots<{
|
|
|
740
891
|
block
|
|
741
892
|
variant="ghost"
|
|
742
893
|
icon="i-lucide-arrow-left"
|
|
894
|
+
:loading="pendingAction === 'back'"
|
|
895
|
+
:disabled="isBusy"
|
|
743
896
|
@click="back"
|
|
744
897
|
>
|
|
745
|
-
|
|
898
|
+
{{ t("mapo.back") }}
|
|
746
899
|
</UButton>
|
|
747
900
|
</slot>
|
|
748
901
|
</div>
|
|
@@ -764,6 +917,7 @@ defineSlots<{
|
|
|
764
917
|
:current-lang="currentLang"
|
|
765
918
|
:registry="registry"
|
|
766
919
|
:readonly="effectiveReadonly"
|
|
920
|
+
:notify-errors="false"
|
|
767
921
|
>
|
|
768
922
|
<template
|
|
769
923
|
v-for="slotName in formSlotNames"
|
|
@@ -783,6 +937,7 @@ defineSlots<{
|
|
|
783
937
|
:current-lang="currentLang"
|
|
784
938
|
:registry="registry"
|
|
785
939
|
:readonly="effectiveReadonly"
|
|
940
|
+
:notify-errors="false"
|
|
786
941
|
>
|
|
787
942
|
<template
|
|
788
943
|
v-for="slotName in formSlotNames"
|
|
@@ -805,7 +960,7 @@ defineSlots<{
|
|
|
805
960
|
icon="i-lucide-eye"
|
|
806
961
|
@click="previewOpen = true"
|
|
807
962
|
>
|
|
808
|
-
|
|
963
|
+
{{ t("mapo.preview") }}
|
|
809
964
|
</UButton>
|
|
810
965
|
|
|
811
966
|
<!-- Danger zone: delete action, visually separated from save actions -->
|
|
@@ -817,10 +972,11 @@ defineSlots<{
|
|
|
817
972
|
color="error"
|
|
818
973
|
variant="soft"
|
|
819
974
|
:loading="isDeleting"
|
|
975
|
+
:disabled="isBusy"
|
|
820
976
|
icon="i-lucide-trash-2"
|
|
821
977
|
@click="deleteItem"
|
|
822
978
|
>
|
|
823
|
-
|
|
979
|
+
{{ t("mapo.delete") }}
|
|
824
980
|
</UButton>
|
|
825
981
|
</slot>
|
|
826
982
|
</UCard>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, computed, watch, onMounted, nextTick } from "vue";
|
|
3
|
-
import { useRoute, useRouter } from "
|
|
3
|
+
import { useRoute, useRouter } from "#app";
|
|
4
4
|
|
|
5
5
|
const props = withDefaults(
|
|
6
6
|
defineProps<{
|
|
@@ -9,8 +9,9 @@ const props = withDefaults(
|
|
|
9
9
|
errors?: Record<string, string[]>;
|
|
10
10
|
noRouteChange?: boolean;
|
|
11
11
|
/**
|
|
12
|
-
* Number of languages above which
|
|
13
|
-
*
|
|
12
|
+
* Number of languages above which a searchable select appears next to the
|
|
13
|
+
* tab bar, for quick navigation. Default: `8`. `0` always shows it,
|
|
14
|
+
* `Infinity` never does.
|
|
14
15
|
*/
|
|
15
16
|
langThreshold?: number;
|
|
16
17
|
}>(),
|
|
@@ -69,6 +70,9 @@ function onSelectChange(v: unknown) {
|
|
|
69
70
|
|
|
70
71
|
// ─── Select menu items ────────────────────────────────────────────────────────
|
|
71
72
|
|
|
73
|
+
// A few languages fit in the tab bar; the select only helps once they overflow it.
|
|
74
|
+
const showSelect = computed(() => props.langs.length > props.langThreshold);
|
|
75
|
+
|
|
72
76
|
const selectItems = computed(() =>
|
|
73
77
|
props.langs.map((lang) => ({
|
|
74
78
|
label: lang.toUpperCase(),
|
|
@@ -106,26 +110,21 @@ watch(
|
|
|
106
110
|
<div
|
|
107
111
|
class="flex items-end gap-0 border-b border-gray-200 dark:border-gray-700 mt-2 mb-4"
|
|
108
112
|
>
|
|
109
|
-
<!-- Language select —
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
:trailing-icon="
|
|
125
|
-
open ? 'i-lucide-chevron-up' : 'i-lucide-chevron-down'
|
|
126
|
-
"
|
|
127
|
-
class="w-full justify-between font-medium"
|
|
128
|
-
>
|
|
113
|
+
<!-- Language select — above langThreshold only, aligned at bottom of row -->
|
|
114
|
+
<template v-if="showSelect">
|
|
115
|
+
<USelectMenu
|
|
116
|
+
:model-value="modelValue"
|
|
117
|
+
:items="selectItems"
|
|
118
|
+
value-key="value"
|
|
119
|
+
label-key="label"
|
|
120
|
+
size="sm"
|
|
121
|
+
variant="ghost"
|
|
122
|
+
class="w-28 shrink-0 mb-px font-medium"
|
|
123
|
+
@update:model-value="onSelectChange"
|
|
124
|
+
>
|
|
125
|
+
<!-- The trigger is already a button with its own chevron: the slot
|
|
126
|
+
holds only what it shows, never another button. -->
|
|
127
|
+
<template #default>
|
|
129
128
|
<span class="flex items-center gap-1">
|
|
130
129
|
<span
|
|
131
130
|
v-if="hasErrors(modelValue)"
|
|
@@ -133,12 +132,12 @@ watch(
|
|
|
133
132
|
/>
|
|
134
133
|
{{ modelValue.toUpperCase() }}
|
|
135
134
|
</span>
|
|
136
|
-
</
|
|
137
|
-
</
|
|
138
|
-
</USelectMenu>
|
|
135
|
+
</template>
|
|
136
|
+
</USelectMenu>
|
|
139
137
|
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
<!-- Divider -->
|
|
139
|
+
<div class="h-5 w-px bg-gray-200 dark:bg-gray-700 mx-2 shrink-0" />
|
|
140
|
+
</template>
|
|
142
141
|
|
|
143
142
|
<!-- Tab bar — always shown, scrollable -->
|
|
144
143
|
<div class="flex gap-1 overflow-x-auto scrollbar-none flex-1">
|