@mapomodule/uikit 2.0.0-beta.10 → 2.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/MapoDetail.vue +34 -8
- package/dist/runtime/components/MapoDetail.vue.d.ts +23 -2
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -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/MapoMediaPreview.vue.d.ts +1 -1
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuManager.vue +23 -3
- package/dist/runtime/components/MapoMenuManager.vue.d.ts +2 -2
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -1
- 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/package.json +5 -5
- package/src/__tests__/langInfo.test.ts +48 -0
- package/src/runtime/components/MapoDetail.vue +91 -19
- package/src/runtime/components/MapoMenuManager.vue +38 -3
- package/src/runtime/utils/langInfo.ts +38 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langInfo.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/langInfo.test.ts"],"names":[],"mappings":""}
|
package/dist/module.json
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
useSlots,
|
|
8
8
|
onMounted,
|
|
9
9
|
onBeforeUnmount,
|
|
10
|
-
provide
|
|
10
|
+
provide,
|
|
11
|
+
shallowRef
|
|
11
12
|
} from "vue";
|
|
12
13
|
import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
|
|
13
14
|
import { useI18n } from "vue-i18n";
|
|
@@ -21,10 +22,14 @@ import {
|
|
|
21
22
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
22
23
|
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
23
24
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
25
|
+
import { languagesFromMetadata } from "../utils/langInfo";
|
|
26
|
+
import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
|
|
24
27
|
const props = defineProps({
|
|
25
28
|
endpoint: { type: String, required: true },
|
|
26
29
|
id: { type: [String, Number], required: true },
|
|
27
|
-
fields: { type: Array, required:
|
|
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 },
|
|
28
33
|
sidebarFields: { type: Array, required: false, default: () => [] },
|
|
29
34
|
languages: { type: Array, required: false, default: () => [] },
|
|
30
35
|
modelName: { type: [String, null], required: false, default: null },
|
|
@@ -178,6 +183,31 @@ if (props.draft || props.draftKey) {
|
|
|
178
183
|
}, 2e3);
|
|
179
184
|
watch(model, saveDraft, { deep: true });
|
|
180
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
|
+
}
|
|
181
211
|
async function fetchModel() {
|
|
182
212
|
if (isNew.value) {
|
|
183
213
|
backup.value = null;
|
|
@@ -188,11 +218,6 @@ async function fetchModel() {
|
|
|
188
218
|
try {
|
|
189
219
|
model.value = await crud.detail(props.id);
|
|
190
220
|
backup.value = deepClone(model.value);
|
|
191
|
-
const langInfo = model.value?.lang_info;
|
|
192
|
-
const siteLangs = langInfo?.site_languages;
|
|
193
|
-
if (siteLangs?.length && !props.languages.length && !props.forceLanguages?.length) {
|
|
194
|
-
derivedLangs.value = siteLangs;
|
|
195
|
-
}
|
|
196
221
|
checkDraft();
|
|
197
222
|
} catch (err) {
|
|
198
223
|
snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
|
|
@@ -321,6 +346,7 @@ onMounted(() => {
|
|
|
321
346
|
preventWindowClose
|
|
322
347
|
);
|
|
323
348
|
}
|
|
349
|
+
describeEndpoint();
|
|
324
350
|
fetchModel();
|
|
325
351
|
});
|
|
326
352
|
onBeforeUnmount(() => {
|
|
@@ -426,7 +452,7 @@ defineSlots();
|
|
|
426
452
|
<slot name="body" v-bind="slotBindings">
|
|
427
453
|
<MapoForm
|
|
428
454
|
v-model="model"
|
|
429
|
-
:fields="
|
|
455
|
+
:fields="activeFields"
|
|
430
456
|
:errors="errors"
|
|
431
457
|
:languages="activeLangs"
|
|
432
458
|
:current-lang="currentLang"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type VNode } from "vue";
|
|
2
2
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
3
|
+
import type { UseFormFromSchemaOptions } from "@mapomodule/form/runtime/composables/useFormFromSchema";
|
|
3
4
|
import type { MultipartPolicy } from "@mapomodule/core";
|
|
4
5
|
declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
5
6
|
props: import("vue").PublicProps & __VLS_PrettifyLocal<{
|
|
@@ -7,8 +8,28 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
|
|
|
7
8
|
endpoint: string;
|
|
8
9
|
/** Record id. Pass `'new'` to create. */
|
|
9
10
|
id: string | number;
|
|
10
|
-
/**
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Fields for the main body form.
|
|
13
|
+
*
|
|
14
|
+
* Optional only so `experimentalFieldsFromSchema` can supply them; pass them
|
|
15
|
+
* explicitly for any form you care about the layout of.
|
|
16
|
+
*/
|
|
17
|
+
fields?: AnyFieldDescriptor<T>[];
|
|
18
|
+
/**
|
|
19
|
+
* EXPERIMENTAL. Build the body fields from the endpoint's OPTIONS schema
|
|
20
|
+
* when `fields` is not given.
|
|
21
|
+
*
|
|
22
|
+
* Off by default and deliberately opt-in: a derived form knows types,
|
|
23
|
+
* labels, relations and what is read-only, but nothing editorial — no tabs,
|
|
24
|
+
* no column widths, no rich-text vs textarea, no sidebar split, and no
|
|
25
|
+
* opinion about field order beyond the serializer's. Treat it as a
|
|
26
|
+
* scaffold to start from, not a finished panel.
|
|
27
|
+
*
|
|
28
|
+
* Requires a backend that publishes `schema` on OPTIONS (camomilla >= 6.6).
|
|
29
|
+
*/
|
|
30
|
+
experimentalFieldsFromSchema?: boolean;
|
|
31
|
+
/** Passed straight to useFormFromSchema when deriving. */
|
|
32
|
+
schemaFieldOptions?: UseFormFromSchemaOptions;
|
|
12
33
|
/** Fields for the sidebar form (optional). */
|
|
13
34
|
sidebarFields?: AnyFieldDescriptor<T>[];
|
|
14
35
|
/** Translation language codes (e.g. ['it', 'en']). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapoDetail.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoDetail.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MapoDetail.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoDetail.vue"],"names":[],"mappings":"AA26BA,OAAO,EAUL,KAAK,KAAK,EAEX,MAAM,KAAK,CAAC;AAYb,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAIhF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wDAAwD,CAAC;AAEvG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,QAAA,MAAM,YAAY,GAAK,CAAC,SAAS,MAAM,EACtC,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAC9D,YAAY,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,EAC3G,gBAAgB,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EAClE;WAw2CO,OAAO,KAAK,EAAE,WAAW,GAAG,mBAAmB,CAAC;QAp2CpD,uCAAuC;kBAC7B,MAAM;QAChB,yCAAyC;YACrC,MAAM,GAAG,MAAM;QACnB;;;;;WAKG;iBACM,kBAAkB,CAAC,CAAC,CAAC,EAAE;QAChC;;;;;;;;;;;WAWG;uCAC4B,OAAO;QACtC,0DAA0D;6BACrC,wBAAwB;QAC7C,8CAA8C;wBAC9B,kBAAkB,CAAC,CAAC,CAAC,EAAE;QACvC,sDAAsD;oBAC1C,MAAM,EAAE;QACpB,yDAAyD;oBAC7C,MAAM,GAAG,IAAI;QAC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AI,WACJ,MAAM,IAAI,WACV,MAAM,IAAI,GAClB,IAAI;;EAovCL,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAI,CAAC;wBACvD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,CAAC,GAAG,EAAE,CAAC"}
|
|
@@ -18,8 +18,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
|
18
18
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
19
19
|
onFiles?: ((files: File[]) => any) | undefined;
|
|
20
20
|
}>, {
|
|
21
|
-
accept: string;
|
|
22
21
|
multiple: boolean;
|
|
22
|
+
accept: string;
|
|
23
23
|
disabled: boolean;
|
|
24
24
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
25
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapoDropArea.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoDropArea.vue"],"names":[],"mappings":"AAuIA,KAAK,WAAW,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAiDJ,iBAAS,WAAW,SAEnB;AAgJD,QAAA,IAAI,OAAO;;;CAAW,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAO/C,QAAA,MAAM,UAAU;;;;;;;
|
|
1
|
+
{"version":3,"file":"MapoDropArea.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoDropArea.vue"],"names":[],"mappings":"AAuIA,KAAK,WAAW,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAiDJ,iBAAS,WAAW,SAEnB;AAgJD,QAAA,IAAI,OAAO;;;CAAW,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAO/C,QAAA,MAAM,UAAU;;;;;;;cA9MD,OAAO;YADT,MAAM;cAEJ,OAAO;6EAkNpB,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -8,8 +8,8 @@ type __VLS_Props = {
|
|
|
8
8
|
videoAutoplay?: boolean;
|
|
9
9
|
};
|
|
10
10
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
11
|
-
size: "xs" | "sm" | "md" | "lg";
|
|
12
11
|
contain: boolean;
|
|
12
|
+
size: "xs" | "sm" | "md" | "lg";
|
|
13
13
|
showFilename: boolean;
|
|
14
14
|
videoControls: boolean;
|
|
15
15
|
videoAutoplay: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapoMediaPreview.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaPreview.vue"],"names":[],"mappings":"AAmHA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,KAAK,WAAW,GAAG;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAoMJ,QAAA,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"MapoMediaPreview.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaPreview.vue"],"names":[],"mappings":"AAmHA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,KAAK,WAAW,GAAG;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAoMJ,QAAA,MAAM,YAAY;aAxMJ,OAAO;UADV,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI;kBAEjB,OAAO;mBACN,OAAO;mBACP,OAAO;6EAwMzB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "@mapomodule/core/runtime/utils/fetchError";
|
|
10
10
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
11
11
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
12
|
+
import { languagesFromMetadata } from "../utils/langInfo";
|
|
12
13
|
import { deepClone, objectDiff } from "@mapomodule/utils";
|
|
13
14
|
import {
|
|
14
15
|
findMenuNode
|
|
@@ -40,12 +41,16 @@ const model = ref(
|
|
|
40
41
|
);
|
|
41
42
|
let backup = deepClone(model.value);
|
|
42
43
|
const selected = ref(null);
|
|
44
|
+
const derivedLangs = ref([]);
|
|
45
|
+
const activeLangs = computed(
|
|
46
|
+
() => props.languages.length ? props.languages : derivedLangs.value
|
|
47
|
+
);
|
|
43
48
|
const currentLang = ref(props.lang ?? props.languages[0] ?? "");
|
|
44
49
|
const isLoading = ref(String(props.identifier) !== "new");
|
|
45
50
|
const isSaving = ref(false);
|
|
46
51
|
const isNew = computed(() => String(props.identifier) === "new");
|
|
47
52
|
const translationsActive = computed(
|
|
48
|
-
() => props.translatable &&
|
|
53
|
+
() => props.translatable && activeLangs.value.length > 0
|
|
49
54
|
);
|
|
50
55
|
const { canAdd, canChange } = usePermissions();
|
|
51
56
|
const effectiveReadonly = computed(() => {
|
|
@@ -53,10 +58,17 @@ const effectiveReadonly = computed(() => {
|
|
|
53
58
|
if (!props.permissionModel) return false;
|
|
54
59
|
return isNew.value ? !canAdd(props.permissionModel) : !canChange(props.permissionModel);
|
|
55
60
|
});
|
|
61
|
+
watch(
|
|
62
|
+
activeLangs,
|
|
63
|
+
(langs) => {
|
|
64
|
+
if (!currentLang.value && langs.length) currentLang.value = langs[0];
|
|
65
|
+
},
|
|
66
|
+
{ immediate: true }
|
|
67
|
+
);
|
|
56
68
|
watch(
|
|
57
69
|
() => props.lang,
|
|
58
70
|
(val) => {
|
|
59
|
-
if (val &&
|
|
71
|
+
if (val && activeLangs.value.includes(val)) currentLang.value = val;
|
|
60
72
|
}
|
|
61
73
|
);
|
|
62
74
|
watch(currentLang, (val) => {
|
|
@@ -89,7 +101,15 @@ watch(
|
|
|
89
101
|
}
|
|
90
102
|
);
|
|
91
103
|
watch(model, (val) => emit("update:modelValue", val));
|
|
104
|
+
async function deriveLanguages() {
|
|
105
|
+
if (props.languages.length) return;
|
|
106
|
+
try {
|
|
107
|
+
derivedLangs.value = languagesFromMetadata(await crud.options());
|
|
108
|
+
} catch {
|
|
109
|
+
}
|
|
110
|
+
}
|
|
92
111
|
onMounted(async () => {
|
|
112
|
+
deriveLanguages();
|
|
93
113
|
if (isNew.value) return;
|
|
94
114
|
isLoading.value = true;
|
|
95
115
|
try {
|
|
@@ -202,7 +222,7 @@ const treeview = ref(null);
|
|
|
202
222
|
<div class="border-b border-default px-2 pt-2">
|
|
203
223
|
<MapoDetailLangSwitch
|
|
204
224
|
v-model="currentLang"
|
|
205
|
-
:langs="
|
|
225
|
+
:langs="activeLangs"
|
|
206
226
|
:errors="langErrors"
|
|
207
227
|
no-route-change
|
|
208
228
|
/>
|
|
@@ -68,9 +68,10 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
|
|
|
68
68
|
"onUpdate:modelValue"?: ((menu: MapoMenu) => any) | undefined;
|
|
69
69
|
"onUpdate:lang"?: ((lang: string) => any) | undefined;
|
|
70
70
|
}>, {
|
|
71
|
+
translatable: boolean;
|
|
72
|
+
readonly: boolean;
|
|
71
73
|
languages: string[];
|
|
72
74
|
usePatch: boolean;
|
|
73
|
-
readonly: boolean;
|
|
74
75
|
permissionModel: string;
|
|
75
76
|
modelValue: MapoMenu | null;
|
|
76
77
|
lang: string;
|
|
@@ -79,7 +80,6 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
|
|
|
79
80
|
additionalFields: AnyFieldDescriptor[];
|
|
80
81
|
availableClasses: Record<string, string>;
|
|
81
82
|
identifier: string | number;
|
|
82
|
-
translatable: boolean;
|
|
83
83
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
84
84
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
85
85
|
declare const _default: typeof __VLS_export;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapoMenuManager.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMenuManager.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MapoMenuManager.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMenuManager.vue"],"names":[],"mappings":"AAocA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAEL,KAAK,QAAQ,EAEd,MAAM,kBAAkB,CAAC;AAI1B;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,WAAW,GAAG;IACf,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,sFAAsF;IACtF,UAAU,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC7B,8DAA8D;IAC9D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sDAAsD;IACtD,UAAU,CAAC,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;IACzC,6DAA6D;IAC7D,gBAAgB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACxC,gFAAgF;IAChF,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC;AA2BJ,KAAK,WAAW,GAAG;IACjB,kEAAkE;IAClE,KAAK,IAAI,OAAO,CAAC;IACjB,0CAA0C;IAC1C,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IAC3D,qCAAqC;IACrC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IACvD,0CAA0C;IAC1C,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;CAC/D,CAAC;AA2iBF,QAAA,MAAM,UAAU;;;;;;;;;kBArmBG,OAAO;cAeX,OAAO;eAXN,MAAM,EAAE;cAET,OAAO;qBAOA,MAAM;gBAfX,QAAQ,GAAG,IAAI;UAIrB,MAAM;cAMF,MAAM;gBASJ,kBAAkB,EAAE,GAAG,IAAI;sBAErB,kBAAkB,EAAE;sBAEpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;gBAzB5B,MAAM,GAAG,MAAM;6EA6mB9B,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `lang_info`, as served by Camomilla on an endpoint's OPTIONS response.
|
|
3
|
+
*
|
|
4
|
+
* It describes the MODEL, not the site and not a record: a multilingual site can
|
|
5
|
+
* still expose models nobody registered for translation, and rendering a
|
|
6
|
+
* language switcher for those invites the user to type values the backend will
|
|
7
|
+
* drop on save.
|
|
8
|
+
*
|
|
9
|
+
* OPTIONS rather than the record payload because it is metadata, and because a
|
|
10
|
+
* "create new" form has no record to read it from.
|
|
11
|
+
*/
|
|
12
|
+
export interface LangInfo {
|
|
13
|
+
/** Whether this model is registered for translation at all. */
|
|
14
|
+
translatable?: boolean;
|
|
15
|
+
/** Codes usable for THIS model. Empty when it is not translatable. */
|
|
16
|
+
languages?: string[];
|
|
17
|
+
/** What the site supports. Present for context; not model-specific. */
|
|
18
|
+
site_languages?: string[];
|
|
19
|
+
default?: string;
|
|
20
|
+
active?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Language codes a model can be translated into, read from its OPTIONS metadata.
|
|
24
|
+
*
|
|
25
|
+
* Returns `[]` — meaning "render no language switcher" — when the model is not
|
|
26
|
+
* translatable and when `lang_info` is absent entirely. A backend that does not
|
|
27
|
+
* publish the field cannot be assumed multilingual.
|
|
28
|
+
*/
|
|
29
|
+
export declare function languagesFromMetadata(metadata: unknown): string[];
|
|
30
|
+
//# sourceMappingURL=langInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langInfo.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/langInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,QAAQ;IACvB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAQjE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function languagesFromMetadata(metadata) {
|
|
2
|
+
const info = metadata?.lang_info;
|
|
3
|
+
if (!info || info.translatable === false) return [];
|
|
4
|
+
if (!Array.isArray(info.languages)) return [];
|
|
5
|
+
return info.languages.filter(
|
|
6
|
+
(code) => typeof code === "string"
|
|
7
|
+
);
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/uikit",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.12",
|
|
4
4
|
"description": "Mapo UI components: Sidebar, Topbar, Login, SnackBar, ConfirmDialog, List, Detail, Media",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"lint": "eslint src"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@mapomodule/form": "2.0.0-beta.
|
|
48
|
+
"@mapomodule/form": "2.0.0-beta.10",
|
|
49
49
|
"@mapomodule/i18n": "2.0.0-beta.2",
|
|
50
|
-
"@mapomodule/store": "2.0.0-beta.
|
|
51
|
-
"@mapomodule/utils": "2.0.0-beta.
|
|
52
|
-
"@mapomodule/core": "2.0.0-beta.
|
|
50
|
+
"@mapomodule/store": "2.0.0-beta.6",
|
|
51
|
+
"@mapomodule/utils": "2.0.0-beta.5",
|
|
52
|
+
"@mapomodule/core": "2.0.0-beta.9",
|
|
53
53
|
"tailwindcss": "^4.0.0",
|
|
54
54
|
"vue-draggable-plus": "^0.6.0",
|
|
55
55
|
"vue-i18n": "^11.4.0"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { languagesFromMetadata } from "../runtime/utils/langInfo";
|
|
4
|
+
|
|
5
|
+
describe("languagesFromMetadata", () => {
|
|
6
|
+
it("reads the model's own language list", () => {
|
|
7
|
+
expect(
|
|
8
|
+
languagesFromMetadata({
|
|
9
|
+
lang_info: { translatable: true, languages: ["it", "en"] },
|
|
10
|
+
}),
|
|
11
|
+
).toEqual(["it", "en"]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("returns nothing for a model that is not translatable", () => {
|
|
15
|
+
// The site is multilingual; this model is not. Tabs here would collect
|
|
16
|
+
// values the backend silently discards.
|
|
17
|
+
expect(
|
|
18
|
+
languagesFromMetadata({
|
|
19
|
+
lang_info: {
|
|
20
|
+
translatable: false,
|
|
21
|
+
languages: [],
|
|
22
|
+
site_languages: ["it", "en"],
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("never falls back to the site's languages", () => {
|
|
29
|
+
// site_languages is context, not permission to translate this model.
|
|
30
|
+
expect(
|
|
31
|
+
languagesFromMetadata({ lang_info: { site_languages: ["it", "en"] } }),
|
|
32
|
+
).toEqual([]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("treats missing lang_info as not translatable", () => {
|
|
36
|
+
expect(languagesFromMetadata({ actions: {} })).toEqual([]);
|
|
37
|
+
expect(languagesFromMetadata(null)).toEqual([]);
|
|
38
|
+
expect(languagesFromMetadata(undefined)).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("drops entries that are not codes", () => {
|
|
42
|
+
expect(
|
|
43
|
+
languagesFromMetadata({
|
|
44
|
+
lang_info: { translatable: true, languages: ["it", 42, null] },
|
|
45
|
+
}),
|
|
46
|
+
).toEqual(["it"]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
provide,
|
|
11
11
|
type Ref,
|
|
12
12
|
type VNode,
|
|
13
|
+
shallowRef,
|
|
13
14
|
} from "vue";
|
|
14
15
|
import { useRouter, onBeforeRouteLeave, useNuxtApp } from "#app";
|
|
15
16
|
import { useI18n } from "vue-i18n";
|
|
@@ -24,6 +25,10 @@ import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
|
24
25
|
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
25
26
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
26
27
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
28
|
+
import { languagesFromMetadata } from "../utils/langInfo";
|
|
29
|
+
import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
|
|
30
|
+
import type { UseFormFromSchemaOptions } from "@mapomodule/form/runtime/composables/useFormFromSchema";
|
|
31
|
+
import type { JSONSchema } from "@mapomodule/utils";
|
|
27
32
|
import type { MultipartPolicy } from "@mapomodule/core";
|
|
28
33
|
|
|
29
34
|
// ─── Props ────────────────────────────────────────────────────────────────────
|
|
@@ -34,8 +39,28 @@ const props = withDefaults(
|
|
|
34
39
|
endpoint: string;
|
|
35
40
|
/** Record id. Pass `'new'` to create. */
|
|
36
41
|
id: string | number;
|
|
37
|
-
/**
|
|
38
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Fields for the main body form.
|
|
44
|
+
*
|
|
45
|
+
* Optional only so `experimentalFieldsFromSchema` can supply them; pass them
|
|
46
|
+
* explicitly for any form you care about the layout of.
|
|
47
|
+
*/
|
|
48
|
+
fields?: AnyFieldDescriptor<T>[];
|
|
49
|
+
/**
|
|
50
|
+
* EXPERIMENTAL. Build the body fields from the endpoint's OPTIONS schema
|
|
51
|
+
* when `fields` is not given.
|
|
52
|
+
*
|
|
53
|
+
* Off by default and deliberately opt-in: a derived form knows types,
|
|
54
|
+
* labels, relations and what is read-only, but nothing editorial — no tabs,
|
|
55
|
+
* no column widths, no rich-text vs textarea, no sidebar split, and no
|
|
56
|
+
* opinion about field order beyond the serializer's. Treat it as a
|
|
57
|
+
* scaffold to start from, not a finished panel.
|
|
58
|
+
*
|
|
59
|
+
* Requires a backend that publishes `schema` on OPTIONS (camomilla >= 6.6).
|
|
60
|
+
*/
|
|
61
|
+
experimentalFieldsFromSchema?: boolean;
|
|
62
|
+
/** Passed straight to useFormFromSchema when deriving. */
|
|
63
|
+
schemaFieldOptions?: UseFormFromSchemaOptions;
|
|
39
64
|
/** Fields for the sidebar form (optional). */
|
|
40
65
|
sidebarFields?: AnyFieldDescriptor<T>[];
|
|
41
66
|
/** Translation language codes (e.g. ['it', 'en']). */
|
|
@@ -93,6 +118,9 @@ const props = withDefaults(
|
|
|
93
118
|
forceLanguages?: string[];
|
|
94
119
|
}>(),
|
|
95
120
|
{
|
|
121
|
+
fields: undefined,
|
|
122
|
+
experimentalFieldsFromSchema: false,
|
|
123
|
+
schemaFieldOptions: undefined,
|
|
96
124
|
sidebarFields: () => [],
|
|
97
125
|
languages: () => [],
|
|
98
126
|
sidebarCols: 4,
|
|
@@ -184,9 +212,11 @@ const isDirty = computed(
|
|
|
184
212
|
const mainCols = computed(() => 12 - props.sidebarCols);
|
|
185
213
|
|
|
186
214
|
// ─── Languages (auto-derive from lang_info) ──────────────────────────────────
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
//
|
|
215
|
+
// Camomilla describes the MODEL's language situation in the endpoint's OPTIONS
|
|
216
|
+
// metadata, so the host page doesn't hard-code a language list — and a model
|
|
217
|
+
// that is not registered for translation shows no switcher at all, rather than
|
|
218
|
+
// tabs whose extra values the backend would drop.
|
|
219
|
+
// forceLanguages > props.languages > derived.
|
|
190
220
|
const derivedLangs = ref<string[]>([]);
|
|
191
221
|
const activeLangs = computed<string[]>(() => {
|
|
192
222
|
if (props.forceLanguages?.length) return props.forceLanguages;
|
|
@@ -324,6 +354,58 @@ if (props.draft || props.draftKey) {
|
|
|
324
354
|
|
|
325
355
|
// ─── Fetch ───────────────────────────────────────────────────────────────────
|
|
326
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Body fields derived from the OPTIONS schema; empty unless opted in.
|
|
359
|
+
*
|
|
360
|
+
* shallowRef, not ref: the array is replaced wholesale, never mutated in place,
|
|
361
|
+
* and deep reactivity over descriptors (which carry functions) buys nothing.
|
|
362
|
+
* It also keeps the generic intact — ref()'s UnwrapRef erases the T in
|
|
363
|
+
* `key: DeepKeyOf<T>`.
|
|
364
|
+
*/
|
|
365
|
+
const derivedFields = shallowRef<AnyFieldDescriptor<T>[]>([]);
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* The fields actually rendered. An explicit `fields` prop always wins — the
|
|
369
|
+
* derived set is a scaffold, never an override of a hand-built form.
|
|
370
|
+
*/
|
|
371
|
+
const activeFields = computed<AnyFieldDescriptor<T>[]>(() =>
|
|
372
|
+
props.fields?.length ? props.fields : derivedFields.value,
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Ask the endpoint to describe itself, ONCE, and take from that answer both the
|
|
377
|
+
* languages and (when opted in) the fields.
|
|
378
|
+
*
|
|
379
|
+
* Runs for existing records as well as new ones: the metadata lives on OPTIONS
|
|
380
|
+
* only, so reading the fetched record would leave an edit form with no tabs.
|
|
381
|
+
*/
|
|
382
|
+
async function describeEndpoint() {
|
|
383
|
+
const wantsLangs = !props.languages.length && !props.forceLanguages?.length;
|
|
384
|
+
const wantsFields =
|
|
385
|
+
props.experimentalFieldsFromSchema && !props.fields?.length;
|
|
386
|
+
if (!wantsLangs && !wantsFields) return;
|
|
387
|
+
|
|
388
|
+
let metadata: Record<string, unknown>;
|
|
389
|
+
try {
|
|
390
|
+
metadata = (await crud.options()) as Record<string, unknown>;
|
|
391
|
+
} catch {
|
|
392
|
+
// A backend without OPTIONS metadata is not an error worth surfacing: it
|
|
393
|
+
// just means nothing is auto-derived.
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (wantsLangs) derivedLangs.value = languagesFromMetadata(metadata);
|
|
398
|
+
if (wantsFields) {
|
|
399
|
+
const schema = metadata.schema as JSONSchema | undefined;
|
|
400
|
+
if (schema?.properties) {
|
|
401
|
+
derivedFields.value = useFormFromSchema(
|
|
402
|
+
schema,
|
|
403
|
+
props.schemaFieldOptions,
|
|
404
|
+
) as AnyFieldDescriptor<T>[];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
327
409
|
async function fetchModel() {
|
|
328
410
|
if (isNew.value) {
|
|
329
411
|
backup.value = null;
|
|
@@ -334,19 +416,6 @@ async function fetchModel() {
|
|
|
334
416
|
try {
|
|
335
417
|
model.value = await crud.detail(props.id);
|
|
336
418
|
backup.value = deepClone(model.value) as T;
|
|
337
|
-
// Auto-derive languages from the backend response when the host page does
|
|
338
|
-
// not hard-code them. Camomilla embeds site_languages inside lang_info.
|
|
339
|
-
const langInfo = (model.value as Record<string, unknown>)?.lang_info as
|
|
340
|
-
| Record<string, unknown>
|
|
341
|
-
| undefined;
|
|
342
|
-
const siteLangs = langInfo?.site_languages as string[] | undefined;
|
|
343
|
-
if (
|
|
344
|
-
siteLangs?.length &&
|
|
345
|
-
!props.languages.length &&
|
|
346
|
-
!props.forceLanguages?.length
|
|
347
|
-
) {
|
|
348
|
-
derivedLangs.value = siteLangs;
|
|
349
|
-
}
|
|
350
419
|
checkDraft();
|
|
351
420
|
} catch (err: unknown) {
|
|
352
421
|
snack.show(getErrorDetail(err) ?? t("mapo.loadItemError"), "error");
|
|
@@ -494,6 +563,9 @@ onMounted(() => {
|
|
|
494
563
|
preventWindowClose,
|
|
495
564
|
);
|
|
496
565
|
}
|
|
566
|
+
// Independent of the record fetch: languages come from OPTIONS either way,
|
|
567
|
+
// and a new record has no fetch to piggyback on.
|
|
568
|
+
describeEndpoint();
|
|
497
569
|
fetchModel();
|
|
498
570
|
});
|
|
499
571
|
|
|
@@ -684,7 +756,7 @@ defineSlots<{
|
|
|
684
756
|
<slot name="body" v-bind="slotBindings">
|
|
685
757
|
<MapoForm
|
|
686
758
|
v-model="model"
|
|
687
|
-
:fields="
|
|
759
|
+
:fields="activeFields"
|
|
688
760
|
:errors="errors"
|
|
689
761
|
:languages="activeLangs"
|
|
690
762
|
:current-lang="currentLang"
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "@mapomodule/core/runtime/utils/fetchError";
|
|
10
10
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
11
11
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
12
|
+
import { languagesFromMetadata } from "../utils/langInfo";
|
|
12
13
|
import { deepClone, objectDiff } from "@mapomodule/utils";
|
|
13
14
|
import type { AnyFieldDescriptor } from "@mapomodule/form/types";
|
|
14
15
|
import {
|
|
@@ -115,13 +116,23 @@ const model = ref<MapoMenu>(
|
|
|
115
116
|
let backup: MapoMenu = deepClone(model.value);
|
|
116
117
|
|
|
117
118
|
const selected = ref<MenuTreeNode | null>(null);
|
|
119
|
+
// ─── Languages (auto-derive from lang_info) ──────────────────────────────────
|
|
120
|
+
// Camomilla describes the model's language situation in the endpoint's OPTIONS
|
|
121
|
+
// metadata; reading it means a host page no longer hardcodes a list, and a menu
|
|
122
|
+
// model that is not registered for translation shows no switcher instead of tabs
|
|
123
|
+
// the backend would drop. props.languages still wins when a page insists.
|
|
124
|
+
const derivedLangs = ref<string[]>([]);
|
|
125
|
+
const activeLangs = computed<string[]>(() =>
|
|
126
|
+
props.languages.length ? props.languages : derivedLangs.value,
|
|
127
|
+
);
|
|
128
|
+
|
|
118
129
|
const currentLang = ref(props.lang ?? props.languages[0] ?? "");
|
|
119
130
|
const isLoading = ref(String(props.identifier) !== "new");
|
|
120
131
|
const isSaving = ref(false);
|
|
121
132
|
|
|
122
133
|
const isNew = computed(() => String(props.identifier) === "new");
|
|
123
134
|
const translationsActive = computed(
|
|
124
|
-
() => props.translatable &&
|
|
135
|
+
() => props.translatable && activeLangs.value.length > 0,
|
|
125
136
|
);
|
|
126
137
|
|
|
127
138
|
// ─── Permissions ─────────────────────────────────────────────────────────────
|
|
@@ -137,10 +148,20 @@ const effectiveReadonly = computed(() => {
|
|
|
137
148
|
|
|
138
149
|
// ─── Language handling ───────────────────────────────────────────────────────
|
|
139
150
|
|
|
151
|
+
// Derivation resolves after mount, so the initial currentLang is "" whenever the
|
|
152
|
+
// list is not hardcoded. Adopt the first language as soon as one is known.
|
|
153
|
+
watch(
|
|
154
|
+
activeLangs,
|
|
155
|
+
(langs) => {
|
|
156
|
+
if (!currentLang.value && langs.length) currentLang.value = langs[0]!;
|
|
157
|
+
},
|
|
158
|
+
{ immediate: true },
|
|
159
|
+
);
|
|
160
|
+
|
|
140
161
|
watch(
|
|
141
162
|
() => props.lang,
|
|
142
163
|
(val) => {
|
|
143
|
-
if (val &&
|
|
164
|
+
if (val && activeLangs.value.includes(val)) currentLang.value = val;
|
|
144
165
|
},
|
|
145
166
|
);
|
|
146
167
|
|
|
@@ -189,7 +210,21 @@ watch(
|
|
|
189
210
|
|
|
190
211
|
watch(model, (val) => emit("update:modelValue", val));
|
|
191
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Ask the endpoint to describe itself. `lang_info` lives on OPTIONS only, so
|
|
215
|
+
* this runs for an existing menu as well as a brand new one.
|
|
216
|
+
*/
|
|
217
|
+
async function deriveLanguages() {
|
|
218
|
+
if (props.languages.length) return;
|
|
219
|
+
try {
|
|
220
|
+
derivedLangs.value = languagesFromMetadata(await crud.options());
|
|
221
|
+
} catch {
|
|
222
|
+
// Backend without OPTIONS metadata: just no auto-derived languages.
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
192
226
|
onMounted(async () => {
|
|
227
|
+
deriveLanguages();
|
|
193
228
|
if (isNew.value) return;
|
|
194
229
|
isLoading.value = true;
|
|
195
230
|
try {
|
|
@@ -331,7 +366,7 @@ const treeview = ref<InstanceType<typeof MapoMenuTreeview> | null>(null);
|
|
|
331
366
|
<div class="border-b border-default px-2 pt-2">
|
|
332
367
|
<MapoDetailLangSwitch
|
|
333
368
|
v-model="currentLang"
|
|
334
|
-
:langs="
|
|
369
|
+
:langs="activeLangs"
|
|
335
370
|
:errors="langErrors"
|
|
336
371
|
no-route-change
|
|
337
372
|
/>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `lang_info`, as served by Camomilla on an endpoint's OPTIONS response.
|
|
3
|
+
*
|
|
4
|
+
* It describes the MODEL, not the site and not a record: a multilingual site can
|
|
5
|
+
* still expose models nobody registered for translation, and rendering a
|
|
6
|
+
* language switcher for those invites the user to type values the backend will
|
|
7
|
+
* drop on save.
|
|
8
|
+
*
|
|
9
|
+
* OPTIONS rather than the record payload because it is metadata, and because a
|
|
10
|
+
* "create new" form has no record to read it from.
|
|
11
|
+
*/
|
|
12
|
+
export interface LangInfo {
|
|
13
|
+
/** Whether this model is registered for translation at all. */
|
|
14
|
+
translatable?: boolean;
|
|
15
|
+
/** Codes usable for THIS model. Empty when it is not translatable. */
|
|
16
|
+
languages?: string[];
|
|
17
|
+
/** What the site supports. Present for context; not model-specific. */
|
|
18
|
+
site_languages?: string[];
|
|
19
|
+
default?: string;
|
|
20
|
+
active?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Language codes a model can be translated into, read from its OPTIONS metadata.
|
|
25
|
+
*
|
|
26
|
+
* Returns `[]` — meaning "render no language switcher" — when the model is not
|
|
27
|
+
* translatable and when `lang_info` is absent entirely. A backend that does not
|
|
28
|
+
* publish the field cannot be assumed multilingual.
|
|
29
|
+
*/
|
|
30
|
+
export function languagesFromMetadata(metadata: unknown): string[] {
|
|
31
|
+
const info = (metadata as Record<string, unknown> | null | undefined)
|
|
32
|
+
?.lang_info as LangInfo | undefined;
|
|
33
|
+
if (!info || info.translatable === false) return [];
|
|
34
|
+
if (!Array.isArray(info.languages)) return [];
|
|
35
|
+
return info.languages.filter(
|
|
36
|
+
(code): code is string => typeof code === "string",
|
|
37
|
+
);
|
|
38
|
+
}
|