@mapomodule/uikit 2.0.0-beta.11 → 2.0.0-beta.13
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 +15 -5
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/MapoMediaEditor.vue +10 -4
- 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/MapoMenuManager.vue.d.ts +1 -1
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -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 +16 -0
- package/package.json +5 -5
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/runtime/components/MapoMediaEditor.vue +17 -4
- package/src/runtime/stores/media.ts +32 -0
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ When installed via `mapomodule`, configure under `mapo.uikit` instead.
|
|
|
46
46
|
| `MapoSidebarProfile` | User profile row (avatar + username + logout) for the sidebar footer |
|
|
47
47
|
| `MapoTopbar` | Top bar with drawer toggle and left/default/right slots |
|
|
48
48
|
| `MapoThemeToggle` | Dark/light mode toggle via `useColorMode()` — drop-in for any slot |
|
|
49
|
+
| `MapoLangSwitcher` | Interface locale switcher over the `@nuxtjs/i18n` locales, with flag emoji |
|
|
49
50
|
| `MapoLogoutButton` | Standalone logout button with `variant`, `color`, `size`, `iconOnly` props |
|
|
50
51
|
|
|
51
52
|
#### Feedback
|
|
@@ -103,10 +104,19 @@ mapo: {
|
|
|
103
104
|
|
|
104
105
|
#### Detail shell
|
|
105
106
|
|
|
106
|
-
| Component | Description
|
|
107
|
-
| ---------------------- |
|
|
108
|
-
| `MapoDetail` | Two-column detail shell: `useCrud` lifecycle, differential PATCH, error mapping, draft auto-save (`:draft="true"`). Supports permission gating (`permissionModel`), multipart control (`multipart`), live preview (`previewField`), and
|
|
109
|
-
| `MapoDetailLangSwitch` | Language tabs with per-language error badge — syncs the `?lang=` query param
|
|
107
|
+
| Component | Description |
|
|
108
|
+
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
109
|
+
| `MapoDetail` | Two-column detail shell: `useCrud` lifecycle, differential PATCH, error mapping, draft auto-save (`:draft="true"`). Supports permission gating (`permissionModel`), multipart control (`multipart`), live preview (`previewField`), and languages derived from the endpoint's OPTIONS `lang_info` (overridable with `languages` / `forceLanguages`). |
|
|
110
|
+
| `MapoDetailLangSwitch` | Language tabs with per-language error badge — syncs the `?lang=` query param |
|
|
111
|
+
|
|
112
|
+
#### Menu manager
|
|
113
|
+
|
|
114
|
+
| Component | Description |
|
|
115
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `MapoMenuManager` | Split-pane menu editor: `useCrud` load/save, per-language node trees (`translatable`), differential save (`usePatch`), permission gating (`permissionModel`) |
|
|
117
|
+
| `MapoMenuTreeview` | Left pane — drag-and-drop node tree with nesting limit (`maxDepth`) and confirm-on-delete |
|
|
118
|
+
| `MapoMenuTreeviewNode` | Recursive node renderer: nested drag lists for re-parenting, inline rename, per-node error badge |
|
|
119
|
+
| `MapoMenuNodeEditor` | Right pane — `MapoForm` for the selected node (title, link type, style, new tab, page picker, static URL); `coreFields` / `additionalFields` swap the field set |
|
|
110
120
|
|
|
111
121
|
### Layout slots (`mapo-default`)
|
|
112
122
|
|
|
@@ -172,7 +182,7 @@ app/
|
|
|
172
182
|
|
|
173
183
|
The `@mapomodule/uikit` module hooks into Nuxt's `components:extend` and swaps the `filePath` — no imports, no registration needed. Keep props and slots compatible with the original.
|
|
174
184
|
|
|
175
|
-
Overridable components: `MapoTopbar`, `MapoSidebar`, `MapoSidebarList`, `MapoSidebarListItem`, `MapoSidebarProfile`, `MapoLogin`, `MapoLogoutButton`, `MapoThemeToggle`, `MapoSnackBar`, `MapoConfirmDialog`, `MapoRootComponents`, `MapoDetail`, `MapoDetailLangSwitch`, `MapoList`, `MapoListTable`, `MapoListFilters`, `MapoListActions`, `MapoListHead`, `MapoListQuickEdit`, `MapoMediaManager`, `MapoMediaManagerDialog`, `MapoMediaGallery`, `MapoMediaEditor`, `MapoMediaUploader`, `MapoMediaFolders`.
|
|
185
|
+
Overridable components: `MapoTopbar`, `MapoSidebar`, `MapoSidebarList`, `MapoSidebarListItem`, `MapoSidebarProfile`, `MapoLogin`, `MapoLogoutButton`, `MapoThemeToggle`, `MapoLangSwitcher`, `MapoSnackBar`, `MapoConfirmDialog`, `MapoRootComponents`, `MapoDetail`, `MapoDetailLangSwitch`, `MapoList`, `MapoListTable`, `MapoListFilters`, `MapoListActions`, `MapoListHead`, `MapoListQuickEdit`, `MapoMediaManager`, `MapoMediaManagerDialog`, `MapoMediaGallery`, `MapoMediaEditor`, `MapoMediaUploader`, `MapoMediaFolders`, `MapoMenuManager`, `MapoMenuTreeview`, `MapoMenuTreeviewNode`, `MapoMenuNodeEditor`.
|
|
176
186
|
|
|
177
187
|
## Dev workflow
|
|
178
188
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaLanguages.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/mediaLanguages.test.ts"],"names":[],"mappings":""}
|
package/dist/module.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { ref, watch, computed } from "vue";
|
|
2
|
+
import { ref, watch, computed, onMounted } from "vue";
|
|
3
3
|
import { useI18n } from "vue-i18n";
|
|
4
4
|
import { useRuntimeConfig } from "#app";
|
|
5
5
|
import {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "@mapomodule/utils";
|
|
11
11
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
12
12
|
import { useMediaStore } from "../stores/media.js";
|
|
13
|
-
defineProps({
|
|
13
|
+
const props = defineProps({
|
|
14
14
|
languages: { type: Array, required: false },
|
|
15
15
|
defaultLang: { type: String, required: false }
|
|
16
16
|
});
|
|
@@ -26,6 +26,12 @@ const saving = ref(false);
|
|
|
26
26
|
const newFile = ref(null);
|
|
27
27
|
const maintainUrl = ref(false);
|
|
28
28
|
const currentLang = ref("");
|
|
29
|
+
const activeLangs = computed(
|
|
30
|
+
() => props.languages?.length ? props.languages : store.languages
|
|
31
|
+
);
|
|
32
|
+
onMounted(() => {
|
|
33
|
+
store.deriveLanguages();
|
|
34
|
+
});
|
|
29
35
|
let editSnapshot = null;
|
|
30
36
|
const media = computed(() => store.editMedia);
|
|
31
37
|
watch(
|
|
@@ -224,7 +230,7 @@ function formatDate(dateStr) {
|
|
|
224
230
|
<!-- Edit form (shown when editing) -->
|
|
225
231
|
<div v-if="editing" class="space-y-4 px-4 py-3">
|
|
226
232
|
<!-- Lang switch -->
|
|
227
|
-
<UFieldGroup v-if="
|
|
233
|
+
<UFieldGroup v-if="activeLangs.length > 1" size="xs">
|
|
228
234
|
<UButton
|
|
229
235
|
:variant="currentLang === '' ? 'solid' : 'outline'"
|
|
230
236
|
color="neutral"
|
|
@@ -233,7 +239,7 @@ function formatDate(dateStr) {
|
|
|
233
239
|
{{ t("mapo.mediaEditor.defaultLang") }}
|
|
234
240
|
</UButton>
|
|
235
241
|
<UButton
|
|
236
|
-
v-for="lang in
|
|
242
|
+
v-for="lang in activeLangs"
|
|
237
243
|
:key="lang"
|
|
238
244
|
:variant="currentLang === lang ? 'solid' : 'outline'"
|
|
239
245
|
color="neutral"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapoMediaEditor.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaEditor.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MapoMediaEditor.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaEditor.vue"],"names":[],"mappings":"AA2XA,KAAK,WAAW,GAAG;IACjB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AA2xBF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -69,8 +69,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
|
|
|
69
69
|
"onUpdate:lang"?: ((lang: string) => any) | undefined;
|
|
70
70
|
}>, {
|
|
71
71
|
translatable: boolean;
|
|
72
|
-
readonly: boolean;
|
|
73
72
|
languages: string[];
|
|
73
|
+
readonly: boolean;
|
|
74
74
|
usePatch: boolean;
|
|
75
75
|
permissionModel: string;
|
|
76
76
|
modelValue: MapoMenu | null;
|
|
@@ -1 +1 @@
|
|
|
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,OA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ErB,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"}
|
|
@@ -120,6 +120,7 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
120
120
|
selection: import("vue").ShallowRef<MediaItem | MediaItem[] | null, MediaItem | MediaItem[] | null>;
|
|
121
121
|
editList: import("vue").Ref<number[], number[]>;
|
|
122
122
|
selectMode: import("vue").Ref<SelectMode, SelectMode>;
|
|
123
|
+
languages: import("vue").Ref<string[], string[]>;
|
|
123
124
|
parentFolder: import("vue").ComputedRef<{
|
|
124
125
|
id: number;
|
|
125
126
|
name: string;
|
|
@@ -133,6 +134,7 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
133
134
|
outside: boolean;
|
|
134
135
|
}>;
|
|
135
136
|
getRoot: (params?: MediaGetRootParams) => Promise<void>;
|
|
137
|
+
deriveLanguages: () => Promise<void>;
|
|
136
138
|
navigateToFolder: (folder: MediaFolder | null) => Promise<void>;
|
|
137
139
|
openEditor: (media: MediaItem) => Promise<void>;
|
|
138
140
|
closeEditor: () => void;
|
|
@@ -152,7 +154,7 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
152
154
|
setMimeType: (mime: string | null) => void;
|
|
153
155
|
lockMimeType: (mime: string | null) => void;
|
|
154
156
|
reset: () => void;
|
|
155
|
-
}, "pages" | "page" | "medias" | "folders" | "parentFolders" | "mimeType" | "lockedMime" | "loading" | "editMedia" | "selection" | "editList" | "selectMode">, Pick<{
|
|
157
|
+
}, "pages" | "page" | "medias" | "folders" | "parentFolders" | "mimeType" | "lockedMime" | "loading" | "editMedia" | "selection" | "editList" | "selectMode" | "languages">, Pick<{
|
|
156
158
|
medias: import("vue").Ref<{
|
|
157
159
|
id: number;
|
|
158
160
|
file: string;
|
|
@@ -273,6 +275,7 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
273
275
|
selection: import("vue").ShallowRef<MediaItem | MediaItem[] | null, MediaItem | MediaItem[] | null>;
|
|
274
276
|
editList: import("vue").Ref<number[], number[]>;
|
|
275
277
|
selectMode: import("vue").Ref<SelectMode, SelectMode>;
|
|
278
|
+
languages: import("vue").Ref<string[], string[]>;
|
|
276
279
|
parentFolder: import("vue").ComputedRef<{
|
|
277
280
|
id: number;
|
|
278
281
|
name: string;
|
|
@@ -286,6 +289,7 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
286
289
|
outside: boolean;
|
|
287
290
|
}>;
|
|
288
291
|
getRoot: (params?: MediaGetRootParams) => Promise<void>;
|
|
292
|
+
deriveLanguages: () => Promise<void>;
|
|
289
293
|
navigateToFolder: (folder: MediaFolder | null) => Promise<void>;
|
|
290
294
|
openEditor: (media: MediaItem) => Promise<void>;
|
|
291
295
|
closeEditor: () => void;
|
|
@@ -426,6 +430,7 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
426
430
|
selection: import("vue").ShallowRef<MediaItem | MediaItem[] | null, MediaItem | MediaItem[] | null>;
|
|
427
431
|
editList: import("vue").Ref<number[], number[]>;
|
|
428
432
|
selectMode: import("vue").Ref<SelectMode, SelectMode>;
|
|
433
|
+
languages: import("vue").Ref<string[], string[]>;
|
|
429
434
|
parentFolder: import("vue").ComputedRef<{
|
|
430
435
|
id: number;
|
|
431
436
|
name: string;
|
|
@@ -439,6 +444,7 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
439
444
|
outside: boolean;
|
|
440
445
|
}>;
|
|
441
446
|
getRoot: (params?: MediaGetRootParams) => Promise<void>;
|
|
447
|
+
deriveLanguages: () => Promise<void>;
|
|
442
448
|
navigateToFolder: (folder: MediaFolder | null) => Promise<void>;
|
|
443
449
|
openEditor: (media: MediaItem) => Promise<void>;
|
|
444
450
|
closeEditor: () => void;
|
|
@@ -458,5 +464,5 @@ export declare const useMediaStore: import("pinia").StoreDefinition<"mapo-media"
|
|
|
458
464
|
setMimeType: (mime: string | null) => void;
|
|
459
465
|
lockMimeType: (mime: string | null) => void;
|
|
460
466
|
reset: () => void;
|
|
461
|
-
}, "getRoot" | "navigateToFolder" | "openEditor" | "closeEditor" | "setLang" | "updateMedia" | "replaceFile" | "updateOrCreateFolder" | "deleteFolder" | "deleteMedia" | "select" | "setSelectionMode" | "setSelection" | "editSelect" | "editSelectAll" | "deleteSelected" | "uploadMedia" | "setMimeType" | "lockMimeType" | "reset">>;
|
|
467
|
+
}, "getRoot" | "deriveLanguages" | "navigateToFolder" | "openEditor" | "closeEditor" | "setLang" | "updateMedia" | "replaceFile" | "updateOrCreateFolder" | "deleteFolder" | "deleteMedia" | "select" | "setSelectionMode" | "setSelection" | "editSelect" | "editSelectAll" | "deleteSelected" | "uploadMedia" | "setMimeType" | "lockMimeType" | "reset">>;
|
|
462
468
|
//# sourceMappingURL=media.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../src/runtime/stores/media.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../src/runtime/stores/media.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EAEX,kBAAkB,EAClB,kBAAkB,EAGlB,UAAU,EACX,MAAM,mBAAmB,CAAC;AAE3B,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;iBAET,CAAC;oBAChB,CAAD;uBAA6B,CAAC;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBADd,CAAC;oBAChB,CAAD;uBAA6B,CAAC;;;;;;;;;;;;;;;;;;;;iBADd,CAAC;oBAChB,CAAD;uBAA6B,CAAC;;;;;;;;;;;;;;;eA+EpB,OAAO;uBACC,OAAO;iBACb,OAAO;;uBAuEa,kBAAkB,KAAQ,OAAO,CAAC,IAAI,CAAC;2BAtCpC,OAAO,CAAC,IAAI,CAAC;+BA6EP,WAAW,GAAG,IAAI,KAAG,OAAO,CAAC,IAAI,CAAC;wBAOzC,SAAS,KAAG,OAAO,CAAC,IAAI,CAAC;uBAalC,IAAI;oBAIL,MAAM,GAAG,SAAS,KAAG,IAAI;yBAId,SAAS,KAAG,OAAO,CAAC,SAAS,CAAC;2BAcrD,MAAM,QACT,IAAI,4BAET,OAAO,CAAC,SAAS,CAAC;mCAgBX,OAAO,CAAC,WAAW,CAAC,KAC3B,OAAO,CAAC,IAAI,CAAC;2BAYoB,WAAW,KAAG,OAAO,CAAC,IAAI,CAAC;yBAa7B,SAAS,KAAG,OAAO,CAAC,IAAI,CAAC;oBAgBpC,SAAS,KAAG,IAAI;6BAkBP,UAAU,KAAG,IAAI;0BAKpB,SAAS,GAAG,SAAS,EAAE,GAAG,IAAI,KAAG,IAAI;qBAI1C,MAAM,GAAG,MAAM,EAAE,KAAG,IAAI;yBAUtB,IAAI;0BAWG,OAAO,CAAC,IAAI,CAAC;2BAqBnC,kBAAkB,eACd,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,KACrC,OAAO,CAAC,SAAS,CAAC;wBA6CM,MAAM,GAAG,IAAI,KAAG,IAAI;yBAKnB,MAAM,GAAG,IAAI,KAAG,IAAI;iBAK9B,IAAI;4VA4DtB,CAAC"}
|
|
@@ -8,6 +8,7 @@ import { useMapoT } from "@mapomodule/i18n/runtime/composables/useMapoT";
|
|
|
8
8
|
import { applyMultipartPolicy } from "@mapomodule/core/runtime/api/multipart";
|
|
9
9
|
import { useNuxtApp, useRuntimeConfig } from "#app";
|
|
10
10
|
import { defaultMediaAdapter } from "../adapters/defaultMediaAdapter.js";
|
|
11
|
+
import { languagesFromMetadata } from "../utils/langInfo.js";
|
|
11
12
|
export const useMediaStore = defineStore("mapo-media", () => {
|
|
12
13
|
const runtimeConfig = useRuntimeConfig();
|
|
13
14
|
const mediaConfig = runtimeConfig.public.mapoMedia ?? {};
|
|
@@ -40,6 +41,8 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
40
41
|
const _currentSearch = ref("");
|
|
41
42
|
const _currentAll = ref(false);
|
|
42
43
|
const _currentLang = ref(void 0);
|
|
44
|
+
const languages = ref([]);
|
|
45
|
+
let languagesPromise = null;
|
|
43
46
|
const parentFolder = computed(
|
|
44
47
|
() => parentFolders.value[parentFolders.value.length - 1] ?? null
|
|
45
48
|
);
|
|
@@ -65,6 +68,17 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
65
68
|
function folderCrud() {
|
|
66
69
|
return useCrud(endpoints.folders);
|
|
67
70
|
}
|
|
71
|
+
async function deriveLanguages() {
|
|
72
|
+
if (languagesPromise) return languagesPromise;
|
|
73
|
+
languagesPromise = (async () => {
|
|
74
|
+
try {
|
|
75
|
+
languages.value = languagesFromMetadata(await mediaCrud().options());
|
|
76
|
+
} catch {
|
|
77
|
+
languagesPromise = null;
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
return languagesPromise;
|
|
81
|
+
}
|
|
68
82
|
function applyParentFolder(pf) {
|
|
69
83
|
if (!pf) {
|
|
70
84
|
parentFolders.value = [];
|
|
@@ -315,12 +329,14 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
315
329
|
selection,
|
|
316
330
|
editList,
|
|
317
331
|
selectMode,
|
|
332
|
+
languages,
|
|
318
333
|
// getters
|
|
319
334
|
parentFolder,
|
|
320
335
|
editListSet,
|
|
321
336
|
editListState,
|
|
322
337
|
// actions
|
|
323
338
|
getRoot,
|
|
339
|
+
deriveLanguages,
|
|
324
340
|
navigateToFolder,
|
|
325
341
|
openEditor,
|
|
326
342
|
closeEditor,
|
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.13",
|
|
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,66 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { createPinia, setActivePinia } from "pinia";
|
|
3
|
+
|
|
4
|
+
const optionsMock = vi.fn();
|
|
5
|
+
|
|
6
|
+
vi.mock("#app", () => ({
|
|
7
|
+
useRuntimeConfig: () => ({ public: {} }),
|
|
8
|
+
useNuxtApp: () => ({ $mapoFetch: vi.fn() }),
|
|
9
|
+
}));
|
|
10
|
+
vi.mock("@mapomodule/core/runtime/api/crud", () => ({
|
|
11
|
+
useCrud: () => ({ options: optionsMock }),
|
|
12
|
+
}));
|
|
13
|
+
vi.mock("@mapomodule/i18n/runtime/composables/useMapoT", () => ({
|
|
14
|
+
useMapoT: () => (key: string) => key,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const { useMediaStore } = await import("../runtime/stores/media");
|
|
18
|
+
|
|
19
|
+
describe("media store — languages from OPTIONS", () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
setActivePinia(createPinia());
|
|
22
|
+
optionsMock.mockReset();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("reads the media model's own languages", async () => {
|
|
26
|
+
optionsMock.mockResolvedValue({
|
|
27
|
+
lang_info: { translatable: true, languages: ["it", "en"] },
|
|
28
|
+
});
|
|
29
|
+
const store = useMediaStore();
|
|
30
|
+
await store.deriveLanguages();
|
|
31
|
+
expect(store.languages).toEqual(["it", "en"]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("offers none when the model is not registered for translation", async () => {
|
|
35
|
+
optionsMock.mockResolvedValue({
|
|
36
|
+
lang_info: { translatable: false, languages: [] },
|
|
37
|
+
});
|
|
38
|
+
const store = useMediaStore();
|
|
39
|
+
await store.deriveLanguages();
|
|
40
|
+
expect(store.languages).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Manager, picker dialog and the `media` form field each mount an editor;
|
|
44
|
+
// without the shared promise that is one OPTIONS request per editor.
|
|
45
|
+
it("asks once however many editors mount", async () => {
|
|
46
|
+
optionsMock.mockResolvedValue({ lang_info: { languages: ["it"] } });
|
|
47
|
+
const store = useMediaStore();
|
|
48
|
+
await Promise.all([
|
|
49
|
+
store.deriveLanguages(),
|
|
50
|
+
store.deriveLanguages(),
|
|
51
|
+
store.deriveLanguages(),
|
|
52
|
+
]);
|
|
53
|
+
expect(optionsMock).toHaveBeenCalledOnce();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("retries after a failure instead of caching the empty result", async () => {
|
|
57
|
+
optionsMock.mockRejectedValueOnce(new Error("offline"));
|
|
58
|
+
const store = useMediaStore();
|
|
59
|
+
await store.deriveLanguages();
|
|
60
|
+
expect(store.languages).toEqual([]);
|
|
61
|
+
|
|
62
|
+
optionsMock.mockResolvedValue({ lang_info: { languages: ["it"] } });
|
|
63
|
+
await store.deriveLanguages();
|
|
64
|
+
expect(store.languages).toEqual(["it"]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref, watch, computed } from "vue";
|
|
2
|
+
import { ref, watch, computed, onMounted } from "vue";
|
|
3
3
|
import { useI18n } from "vue-i18n";
|
|
4
4
|
import { useRuntimeConfig } from "#app";
|
|
5
5
|
import {
|
|
@@ -12,7 +12,8 @@ import { usePermissions } from "@mapomodule/store/runtime/composables/usePermiss
|
|
|
12
12
|
import { useMediaStore } from "../stores/media.js";
|
|
13
13
|
import type { MediaItem } from "../types/media.js";
|
|
14
14
|
|
|
15
|
-
defineProps<{
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
/** Overrides the languages read from the endpoint. Rarely needed. */
|
|
16
17
|
languages?: string[];
|
|
17
18
|
defaultLang?: string;
|
|
18
19
|
}>();
|
|
@@ -35,6 +36,18 @@ const saving = ref(false);
|
|
|
35
36
|
const newFile = ref<File | null>(null);
|
|
36
37
|
const maintainUrl = ref(false);
|
|
37
38
|
const currentLang = ref("");
|
|
39
|
+
|
|
40
|
+
// The languages actually offered. An explicit prop wins; otherwise they come
|
|
41
|
+
// from the media endpoint's own OPTIONS metadata, so a host page never has to
|
|
42
|
+
// restate what the backend already knows — and a media model nobody registered
|
|
43
|
+
// for translation shows no switcher rather than tabs whose values it discards.
|
|
44
|
+
const activeLangs = computed(() =>
|
|
45
|
+
props.languages?.length ? props.languages : store.languages,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
store.deriveLanguages();
|
|
50
|
+
});
|
|
38
51
|
// Pristine copy taken when entering edit mode, restored on Cancel — the form
|
|
39
52
|
// mutates store.editMedia directly, so without this Cancel would leave the
|
|
40
53
|
// unsaved edits visible in the info panel (legacy used deepClone the same way).
|
|
@@ -254,7 +267,7 @@ function formatDate(dateStr: string): string {
|
|
|
254
267
|
<!-- Edit form (shown when editing) -->
|
|
255
268
|
<div v-if="editing" class="space-y-4 px-4 py-3">
|
|
256
269
|
<!-- Lang switch -->
|
|
257
|
-
<UFieldGroup v-if="
|
|
270
|
+
<UFieldGroup v-if="activeLangs.length > 1" size="xs">
|
|
258
271
|
<UButton
|
|
259
272
|
:variant="currentLang === '' ? 'solid' : 'outline'"
|
|
260
273
|
color="neutral"
|
|
@@ -263,7 +276,7 @@ function formatDate(dateStr: string): string {
|
|
|
263
276
|
{{ t("mapo.mediaEditor.defaultLang") }}
|
|
264
277
|
</UButton>
|
|
265
278
|
<UButton
|
|
266
|
-
v-for="lang in
|
|
279
|
+
v-for="lang in activeLangs"
|
|
267
280
|
:key="lang"
|
|
268
281
|
:variant="currentLang === lang ? 'solid' : 'outline'"
|
|
269
282
|
color="neutral"
|
|
@@ -8,6 +8,7 @@ import { useMapoT } from "@mapomodule/i18n/runtime/composables/useMapoT";
|
|
|
8
8
|
import { applyMultipartPolicy } from "@mapomodule/core/runtime/api/multipart";
|
|
9
9
|
import { useNuxtApp, useRuntimeConfig } from "#app";
|
|
10
10
|
import { defaultMediaAdapter } from "../adapters/defaultMediaAdapter.js";
|
|
11
|
+
import { languagesFromMetadata } from "../utils/langInfo.js";
|
|
11
12
|
import type {
|
|
12
13
|
MediaItem,
|
|
13
14
|
MediaFolder,
|
|
@@ -85,6 +86,14 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
85
86
|
const _currentAll = ref(false);
|
|
86
87
|
const _currentLang = ref<string | undefined>(undefined);
|
|
87
88
|
|
|
89
|
+
// Language codes the media model is actually registered for, read once from
|
|
90
|
+
// the endpoint's OPTIONS. It lives here rather than in the editor because all
|
|
91
|
+
// three entry points — manager, picker dialog, and the `media` form field —
|
|
92
|
+
// mount their own editor, and each would otherwise need the host page to hand
|
|
93
|
+
// it a hardcoded list.
|
|
94
|
+
const languages = ref<string[]>([]);
|
|
95
|
+
let languagesPromise: Promise<void> | null = null;
|
|
96
|
+
|
|
88
97
|
// ─── Getters ──────────────────────────────────────────────────────────────
|
|
89
98
|
const parentFolder = computed(
|
|
90
99
|
() => parentFolders.value[parentFolders.value.length - 1] ?? null,
|
|
@@ -120,6 +129,27 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
120
129
|
return useCrud<MediaFolder>(endpoints.folders);
|
|
121
130
|
}
|
|
122
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Ask the media endpoint to describe its language situation, at most once.
|
|
134
|
+
*
|
|
135
|
+
* `lang_info` is served on OPTIONS only: it describes the model, so there is
|
|
136
|
+
* no record to read it from, and a media library nobody registered for
|
|
137
|
+
* translation reports none — which is the point. The in-flight promise is
|
|
138
|
+
* kept so several editors mounting at once share a single request.
|
|
139
|
+
*/
|
|
140
|
+
async function deriveLanguages(): Promise<void> {
|
|
141
|
+
if (languagesPromise) return languagesPromise;
|
|
142
|
+
languagesPromise = (async () => {
|
|
143
|
+
try {
|
|
144
|
+
languages.value = languagesFromMetadata(await mediaCrud().options());
|
|
145
|
+
} catch {
|
|
146
|
+
// A backend without OPTIONS metadata just gets no language switcher.
|
|
147
|
+
languagesPromise = null;
|
|
148
|
+
}
|
|
149
|
+
})();
|
|
150
|
+
return languagesPromise;
|
|
151
|
+
}
|
|
152
|
+
|
|
123
153
|
// ─── Breadcrumb maintenance ─────────────────────────────────────────────
|
|
124
154
|
// Driven by the response's `parent_folder` (matches the legacy contract):
|
|
125
155
|
// push when entering a new folder, slice when navigating back up.
|
|
@@ -445,12 +475,14 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
445
475
|
selection,
|
|
446
476
|
editList,
|
|
447
477
|
selectMode,
|
|
478
|
+
languages,
|
|
448
479
|
// getters
|
|
449
480
|
parentFolder,
|
|
450
481
|
editListSet,
|
|
451
482
|
editListState,
|
|
452
483
|
// actions
|
|
453
484
|
getRoot,
|
|
485
|
+
deriveLanguages,
|
|
454
486
|
navigateToFolder,
|
|
455
487
|
openEditor,
|
|
456
488
|
closeEditor,
|