@mapomodule/uikit 2.0.0-beta.8 → 2.0.0-experimental.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -174
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/formValues.test.d.ts +2 -0
- package/dist/__tests__/formValues.test.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/runtimePages.test.d.ts +2 -0
- package/dist/__tests__/runtimePages.test.d.ts.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +10 -0
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +18 -1
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +263 -33
- package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoDetailLangSwitch.vue +21 -25
- 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.d.ts +1 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoList.vue +7 -3
- package/dist/runtime/components/MapoList.vue.d.ts +14 -4
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +12 -5
- 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/MapoListQuickEdit.vue +1 -1
- package/dist/runtime/components/MapoListTable.vue +99 -33
- package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/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/MapoMediaFileChanger.vue +1 -1
- package/dist/runtime/components/MapoMediaManager.vue +1 -1
- package/dist/runtime/components/MapoMediaManagerDialog.vue +1 -1
- package/dist/runtime/components/MapoMediaPreview.vue +1 -1
- package/dist/runtime/components/MapoMediaUploader.vue +21 -21
- package/dist/runtime/components/MapoMediaUploader.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/components/MapoMenuTreeview.vue.d.ts +1 -1
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +2 -2
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/composables/defineDetailExtension.d.ts +32 -0
- package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
- package/dist/runtime/composables/defineDetailExtension.js +34 -0
- package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
- package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
- package/dist/runtime/composables/useMapoDetail.js +5 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/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/dist/runtime/types/detail.d.ts +167 -0
- package/dist/runtime/types/detail.d.ts.map +1 -0
- package/dist/runtime/types/detail.js +0 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/utils/formValues.d.ts +8 -0
- package/dist/runtime/utils/formValues.d.ts.map +1 -0
- package/dist/runtime/utils/formValues.js +19 -0
- package/dist/runtime/utils/langInfo.d.ts +30 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +8 -0
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/package.json +7 -8
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +1107 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +504 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/formValues.test.ts +31 -0
- package/src/__tests__/langInfo.test.ts +48 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/runtimePages.test.ts +17 -0
- package/src/index.ts +8 -0
- package/src/module.ts +12 -0
- package/src/runtime/assets/main.css +13 -0
- package/src/runtime/components/MapoConfirmDialog.vue +28 -1
- package/src/runtime/components/MapoDetail.vue +481 -53
- package/src/runtime/components/MapoDetailExtensions.vue +39 -0
- package/src/runtime/components/MapoDetailLangSwitch.vue +26 -27
- package/src/runtime/components/MapoList.vue +20 -5
- package/src/runtime/components/MapoListActions.vue +16 -4
- package/src/runtime/components/MapoListTable.vue +128 -41
- package/src/runtime/components/MapoMediaEditor.vue +17 -4
- package/src/runtime/components/MapoMediaUploader.vue +25 -21
- package/src/runtime/components/MapoMenuManager.vue +38 -3
- package/src/runtime/components/MapoSnackBar.vue +12 -0
- package/src/runtime/composables/defineDetailExtension.ts +78 -0
- package/src/runtime/composables/useMapoDetail.ts +24 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/stores/media.ts +32 -0
- package/src/runtime/types/detail.ts +178 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/utils/formValues.ts +28 -0
- package/src/runtime/utils/langInfo.ts +38 -0
- package/src/runtime/utils/listTable.ts +54 -0
|
@@ -55,6 +55,15 @@ const pendingCount = computed(
|
|
|
55
55
|
() => entries.value.filter((e) => e.status === "pending").length,
|
|
56
56
|
);
|
|
57
57
|
|
|
58
|
+
// The text metadata of a pending file, labelled like MapoMediaEditor's fields.
|
|
59
|
+
// Labels, not placeholders: title and alt text start from the file name, so a
|
|
60
|
+
// placeholder would never show what they are.
|
|
61
|
+
const textFields = computed(() => [
|
|
62
|
+
{ key: "title" as const, label: t("mapo.title") },
|
|
63
|
+
{ key: "alt_text" as const, label: t("mapo.altTag") },
|
|
64
|
+
{ key: "description" as const, label: t("mapo.description") },
|
|
65
|
+
]);
|
|
66
|
+
|
|
58
67
|
// Destination options: the current folder plus its subfolders (legacy parity).
|
|
59
68
|
const folderOptions = computed(() => [
|
|
60
69
|
{
|
|
@@ -260,32 +269,27 @@ onUnmounted(clearAll);
|
|
|
260
269
|
</span>
|
|
261
270
|
</div>
|
|
262
271
|
|
|
263
|
-
<!-- Metadata inputs (only for pending)
|
|
272
|
+
<!-- Metadata inputs (only for pending). The inputs take their
|
|
273
|
+
size from UFormField. -->
|
|
264
274
|
<div
|
|
265
275
|
v-if="entry.status === 'pending'"
|
|
266
276
|
class="grid grid-cols-2 gap-1.5"
|
|
267
277
|
>
|
|
268
|
-
<
|
|
269
|
-
v-
|
|
270
|
-
|
|
271
|
-
:
|
|
272
|
-
/>
|
|
273
|
-
<UInput
|
|
274
|
-
v-model="entry.alt_text"
|
|
275
|
-
size="xs"
|
|
276
|
-
:placeholder="t('mapo.altTag')"
|
|
277
|
-
/>
|
|
278
|
-
<UInput
|
|
279
|
-
v-model="entry.description"
|
|
280
|
-
size="xs"
|
|
281
|
-
:placeholder="t('mapo.description')"
|
|
282
|
-
/>
|
|
283
|
-
<USelect
|
|
284
|
-
v-model="entry.folder"
|
|
285
|
-
:items="folderOptions"
|
|
278
|
+
<UFormField
|
|
279
|
+
v-for="field in textFields"
|
|
280
|
+
:key="field.key"
|
|
281
|
+
:label="field.label"
|
|
286
282
|
size="xs"
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
>
|
|
284
|
+
<UInput v-model="entry[field.key]" class="w-full" />
|
|
285
|
+
</UFormField>
|
|
286
|
+
<UFormField :label="t('mapo.folder')" size="xs">
|
|
287
|
+
<USelect
|
|
288
|
+
v-model="entry.folder"
|
|
289
|
+
:items="folderOptions"
|
|
290
|
+
class="w-full"
|
|
291
|
+
/>
|
|
292
|
+
</UFormField>
|
|
289
293
|
</div>
|
|
290
294
|
|
|
291
295
|
<!-- Progress bar -->
|
|
@@ -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
|
/>
|
|
@@ -8,6 +8,17 @@ const toast = useToast();
|
|
|
8
8
|
|
|
9
9
|
const _shown = new Set<number>();
|
|
10
10
|
|
|
11
|
+
function dismissEvictedMessages() {
|
|
12
|
+
const activeToastIds = new Set(
|
|
13
|
+
toast.toasts.value.map(({ id }) => String(id)),
|
|
14
|
+
);
|
|
15
|
+
for (const id of _shown) {
|
|
16
|
+
if (activeToastIds.has(String(id))) continue;
|
|
17
|
+
_shown.delete(id);
|
|
18
|
+
snack.dismiss(id);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
11
22
|
watch(
|
|
12
23
|
() => snack.messages,
|
|
13
24
|
(msgs) => {
|
|
@@ -30,6 +41,7 @@ watch(
|
|
|
30
41
|
if (!open) snack.dismiss(msg.id);
|
|
31
42
|
},
|
|
32
43
|
});
|
|
44
|
+
dismissEvictedMessages();
|
|
33
45
|
}
|
|
34
46
|
},
|
|
35
47
|
{ deep: true },
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { defineAsyncComponent, shallowReactive } from "vue";
|
|
2
|
+
import type { Component } from "vue";
|
|
3
|
+
import { useNuxtApp } from "#app";
|
|
4
|
+
import type {
|
|
5
|
+
DetailExtension,
|
|
6
|
+
DetailExtensionLoader,
|
|
7
|
+
} from "../types/detail.js";
|
|
8
|
+
|
|
9
|
+
// One list per app instance: on the server, one per request.
|
|
10
|
+
const registries = new WeakMap<object, DetailExtension[]>();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The extensions registered in the app, created on first use. `MapoDetail`
|
|
14
|
+
* renders them through `MapoDetailExtensions`. @internal
|
|
15
|
+
*/
|
|
16
|
+
export function detailExtensions(
|
|
17
|
+
nuxtApp: object = useNuxtApp(),
|
|
18
|
+
): DetailExtension[] {
|
|
19
|
+
let list = registries.get(nuxtApp);
|
|
20
|
+
if (!list) {
|
|
21
|
+
list = shallowReactive<DetailExtension[]>([]);
|
|
22
|
+
registries.set(nuxtApp, list);
|
|
23
|
+
}
|
|
24
|
+
return list;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A loader becomes an async component once, when the extension is registered.
|
|
29
|
+
* It takes the `default` export itself: Vue does so only for a real module.
|
|
30
|
+
*/
|
|
31
|
+
function toComponent(entry: Component | DetailExtensionLoader): Component {
|
|
32
|
+
if (typeof entry !== "function") return entry;
|
|
33
|
+
const load = entry as DetailExtensionLoader;
|
|
34
|
+
return defineAsyncComponent(async () => {
|
|
35
|
+
const loaded = await load();
|
|
36
|
+
const isModule = typeof loaded === "object" && "default" in loaded;
|
|
37
|
+
return isModule ? loaded.default : loaded;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Adds a component to every `MapoDetail` of the app: an action in the sidebar
|
|
43
|
+
* card above Save (`placement: "actions"`), or content above the body form
|
|
44
|
+
* (`"body-top"`). The component reads the detail with `useMapoDetail()`.
|
|
45
|
+
*
|
|
46
|
+
* Call it from a plugin, so it applies to every page. Registering a key again
|
|
47
|
+
* replaces the extension; a page shows only some extensions, or none, with the
|
|
48
|
+
* `extensions` prop of `MapoDetail`.
|
|
49
|
+
*
|
|
50
|
+
* @param extension Its key, placement, component and, optionally, `visible`
|
|
51
|
+
* and `order`.
|
|
52
|
+
* @returns A function that removes the extension.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // app/plugins/detail-actions.ts
|
|
56
|
+
* export default defineNuxtPlugin(() => {
|
|
57
|
+
* defineDetailExtension({
|
|
58
|
+
* key: "duplicate",
|
|
59
|
+
* placement: "actions",
|
|
60
|
+
* component: () => import("~/components/DuplicateButton.vue"),
|
|
61
|
+
* visible: (detail) => !detail.isNew.value,
|
|
62
|
+
* });
|
|
63
|
+
* });
|
|
64
|
+
*/
|
|
65
|
+
export function defineDetailExtension(extension: DetailExtension): () => void {
|
|
66
|
+
const list = detailExtensions();
|
|
67
|
+
const entry: DetailExtension = {
|
|
68
|
+
...extension,
|
|
69
|
+
component: toComponent(extension.component),
|
|
70
|
+
};
|
|
71
|
+
const index = list.findIndex((item) => item.key === extension.key);
|
|
72
|
+
if (index >= 0) list.splice(index, 1, entry);
|
|
73
|
+
else list.push(entry);
|
|
74
|
+
return () => {
|
|
75
|
+
const at = list.indexOf(entry);
|
|
76
|
+
if (at >= 0) list.splice(at, 1);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { inject } from "vue";
|
|
2
|
+
import type { InjectionKey } from "vue";
|
|
3
|
+
import type { MapoDetailContext } from "../types/detail.js";
|
|
4
|
+
|
|
5
|
+
/** The key `MapoDetail` provides its context under. @internal */
|
|
6
|
+
export const DETAIL_KEY: InjectionKey<MapoDetailContext> = Symbol("MapoDetail");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The context of the `MapoDetail` around the calling component: record, fields,
|
|
10
|
+
* languages, state, `save()`, the annotations channel and the shared `OPTIONS`
|
|
11
|
+
* response. Use it in a slot, a field or an extension, instead of passing the
|
|
12
|
+
* same values down again.
|
|
13
|
+
*
|
|
14
|
+
* @returns The context, or `undefined` outside a `MapoDetail`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const detail = useMapoDetail<Article>();
|
|
18
|
+
* if (detail) detail.model.value.title = "Chi siamo";
|
|
19
|
+
*/
|
|
20
|
+
export function useMapoDetail<T extends object = Record<string, unknown>>():
|
|
21
|
+
| MapoDetailContext<T>
|
|
22
|
+
| undefined {
|
|
23
|
+
return inject(DETAIL_KEY, undefined) as MapoDetailContext<T> | undefined;
|
|
24
|
+
}
|
|
@@ -10,6 +10,8 @@ declare module "#app" {
|
|
|
10
10
|
parent?: string;
|
|
11
11
|
/** Pin this page to the sidebar footer instead of the main navigation list. */
|
|
12
12
|
sidebarFooter?: boolean;
|
|
13
|
+
/** Sort this page among siblings in the sidebar; lower values appear first. */
|
|
14
|
+
sidebarOrder?: number;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -29,6 +31,8 @@ declare module "vue-router" {
|
|
|
29
31
|
parent?: string;
|
|
30
32
|
/** Pin this page to the sidebar footer instead of the main navigation list. */
|
|
31
33
|
sidebarFooter?: boolean;
|
|
34
|
+
/** Sort this page among siblings in the sidebar; lower values appear first. */
|
|
35
|
+
sidebarOrder?: number;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -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,
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { Component, ComputedRef, Ref } from "vue";
|
|
2
|
+
import type {
|
|
3
|
+
AnyFieldDescriptor,
|
|
4
|
+
FieldAnnotations,
|
|
5
|
+
FieldRegistry,
|
|
6
|
+
} from "@mapomodule/form/types";
|
|
7
|
+
import type { JSONSchema } from "@mapomodule/utils";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What `MapoDetail` shares with the components inside it: its slots, its forms
|
|
11
|
+
* and the extensions it renders. Read it with `useMapoDetail()`.
|
|
12
|
+
*/
|
|
13
|
+
export interface MapoDetailContext<T extends object = Record<string, unknown>> {
|
|
14
|
+
/** The REST endpoint of the record. */
|
|
15
|
+
endpoint: ComputedRef<string>;
|
|
16
|
+
/** The record id; `"new"` for a record not created yet. */
|
|
17
|
+
id: ComputedRef<string | number>;
|
|
18
|
+
isNew: ComputedRef<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the record's model for people, as the page titles it
|
|
21
|
+
* (`modelName`): "Article"; `null` without one. `MapoDetail` always gives
|
|
22
|
+
* it; optional, so a context built elsewhere, as a test's, still compiles.
|
|
23
|
+
*/
|
|
24
|
+
modelName?: ComputedRef<string | null>;
|
|
25
|
+
/**
|
|
26
|
+
* The backend model the page checks the permissions of (`permissionModel`):
|
|
27
|
+
* `article`; `undefined` without one. `MapoDetail` always gives it;
|
|
28
|
+
* optional, as `modelName`.
|
|
29
|
+
*/
|
|
30
|
+
permissionModel?: ComputedRef<string | undefined>;
|
|
31
|
+
/** The record being edited: write to it to change the values of the form. */
|
|
32
|
+
model: Ref<T>;
|
|
33
|
+
/** The body fields rendered: the `fields` prop, or the ones derived from the schema. */
|
|
34
|
+
fields: ComputedRef<AnyFieldDescriptor<T>[]>;
|
|
35
|
+
/** The sidebar fields rendered. */
|
|
36
|
+
sidebarFields: ComputedRef<AnyFieldDescriptor<T>[]>;
|
|
37
|
+
/** The languages of the record; empty when it is not translated. */
|
|
38
|
+
languages: ComputedRef<string[]>;
|
|
39
|
+
/** The language being edited: write to it to switch. */
|
|
40
|
+
currentLang: Ref<string>;
|
|
41
|
+
/** The field registry the forms use. */
|
|
42
|
+
registry: ComputedRef<FieldRegistry>;
|
|
43
|
+
/** Server errors by field path, as the last save returned them. */
|
|
44
|
+
errors: Readonly<Ref<Record<string, string[]>>>;
|
|
45
|
+
/** Whether the record is read-only for this user. */
|
|
46
|
+
readonly: ComputedRef<boolean>;
|
|
47
|
+
/** While the record loads. */
|
|
48
|
+
isLoading: Readonly<Ref<boolean>>;
|
|
49
|
+
/** From a save until it is done; after `save(true)`, until the page has gone back. */
|
|
50
|
+
isSaving: ComputedRef<boolean>;
|
|
51
|
+
/** While a save, a delete or a navigation back is under way. */
|
|
52
|
+
isBusy: ComputedRef<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the model differs from the record as loaded or last saved; for
|
|
55
|
+
* a new record, whether it holds a value it did not hold when the page
|
|
56
|
+
* opened (a blank text, an empty list or an empty object is none).
|
|
57
|
+
*/
|
|
58
|
+
isDirty: ComputedRef<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Marks set from inside the detail, shown with those of the `annotations`
|
|
61
|
+
* prop; on the same path the prop wins. Replace the map to change them.
|
|
62
|
+
*/
|
|
63
|
+
annotations: Ref<FieldAnnotations>;
|
|
64
|
+
/** Which extensions the page allows: all, none, or the listed keys. */
|
|
65
|
+
extensions: ComputedRef<boolean | readonly string[]>;
|
|
66
|
+
/** Saves the record, as the Save buttons do; ignored while busy. */
|
|
67
|
+
save: (andBack?: boolean) => Promise<void>;
|
|
68
|
+
/** Goes back, as the Back button does; ignored while busy. */
|
|
69
|
+
back: () => void;
|
|
70
|
+
/**
|
|
71
|
+
* The endpoint's `OPTIONS` response, requested once per page and shared
|
|
72
|
+
* with `MapoDetail`, or `undefined` when the endpoint has none.
|
|
73
|
+
*/
|
|
74
|
+
metadata: () => Promise<Record<string, unknown> | undefined>;
|
|
75
|
+
/**
|
|
76
|
+
* How the page turns the `OPTIONS` response into a JSON Schema
|
|
77
|
+
* (`schemaFromMetadata`), when it has its own way; `undefined`: Mapo's
|
|
78
|
+
* `metadataToJsonSchema`. `MapoDetail` always gives it; optional, as
|
|
79
|
+
* `modelName`.
|
|
80
|
+
*/
|
|
81
|
+
schemaFromMetadata?: ComputedRef<
|
|
82
|
+
((metadata: Record<string, unknown>) => JSONSchema | undefined) | undefined
|
|
83
|
+
>;
|
|
84
|
+
/**
|
|
85
|
+
* Calls `handler` after each save that succeeds, with the record as the
|
|
86
|
+
* backend returned it, before the page moves to a new record's address
|
|
87
|
+
* or goes back. Returns the function that removes it; one registered in
|
|
88
|
+
* a component's setup goes with the component. A handler that throws
|
|
89
|
+
* leaves the save done. `MapoDetail` always gives it; optional, as
|
|
90
|
+
* `modelName`.
|
|
91
|
+
*/
|
|
92
|
+
onSaved?: (handler: (record: T) => void) => () => void;
|
|
93
|
+
/**
|
|
94
|
+
* The detail's draft, for a component that keeps a state of its own
|
|
95
|
+
* beside the record's values: it is saved, restored, discarded and
|
|
96
|
+
* cleared with them. With drafts off nothing is kept. `MapoDetail` always
|
|
97
|
+
* gives it; optional, as `modelName`.
|
|
98
|
+
*/
|
|
99
|
+
draft?: MapoDetailDraft;
|
|
100
|
+
/**
|
|
101
|
+
* Takes the operator to a field: the form that holds it, the body's or
|
|
102
|
+
* the sidebar's, opens its tab, group or sub-tab and repeater item,
|
|
103
|
+
* scrolls the field into view and puts the focus on its control. The
|
|
104
|
+
* path is the one of its mark: `title`, `translations.it.title`,
|
|
105
|
+
* `blocks.0.title`. Resolves whether the control took the focus: `false`
|
|
106
|
+
* for a field no form has or shows. `MapoDetail` always gives it;
|
|
107
|
+
* optional, as `modelName`.
|
|
108
|
+
*/
|
|
109
|
+
revealField?: (path: string) => Promise<boolean>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A part of the detail's draft: the state of a component inside it, saved
|
|
114
|
+
* and restored with the record's values.
|
|
115
|
+
*/
|
|
116
|
+
export interface MapoDetailDraftPart {
|
|
117
|
+
/**
|
|
118
|
+
* What to keep, as data `JSON.stringify()` can write; `undefined` when
|
|
119
|
+
* there is nothing. Called each time the draft is saved; a part that
|
|
120
|
+
* throws is left out of that save.
|
|
121
|
+
*/
|
|
122
|
+
save: () => unknown;
|
|
123
|
+
/**
|
|
124
|
+
* Puts back what `save()` returned, when the operator restores the
|
|
125
|
+
* draft, after the record's values; `undefined` when the draft holds
|
|
126
|
+
* nothing for the part, which then starts again from nothing. It comes
|
|
127
|
+
* from the browser's storage: read it as outside data.
|
|
128
|
+
*/
|
|
129
|
+
restore: (data: unknown) => void;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The draft of a `MapoDetail`, for the components inside it. */
|
|
133
|
+
export interface MapoDetailDraft {
|
|
134
|
+
/**
|
|
135
|
+
* Keeps a part of the draft under `key`, one per detail: registering the
|
|
136
|
+
* key again replaces the part. The draft is saved when the record changed
|
|
137
|
+
* or a part has something to keep. A part registered after the draft was
|
|
138
|
+
* restored gets its data then. Returns the function that removes it; one
|
|
139
|
+
* registered in a component's setup goes with the component.
|
|
140
|
+
*/
|
|
141
|
+
part: (key: string, part: MapoDetailDraftPart) => () => void;
|
|
142
|
+
/**
|
|
143
|
+
* Saves the draft soon, after a change of a part's state: a change of
|
|
144
|
+
* the record's values saves it by itself.
|
|
145
|
+
*/
|
|
146
|
+
touch: () => void;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Where `MapoDetail` renders an extension: `actions`, the sidebar card above
|
|
151
|
+
* Save; `body-top`, above the body form.
|
|
152
|
+
*/
|
|
153
|
+
export type DetailExtensionPlacement = "actions" | "body-top";
|
|
154
|
+
|
|
155
|
+
/** A component that loads another: `() => import("./MyAction.vue")`. */
|
|
156
|
+
export type DetailExtensionLoader = () => Promise<
|
|
157
|
+
Component | { default: Component }
|
|
158
|
+
>;
|
|
159
|
+
|
|
160
|
+
/** A component added to every `MapoDetail`, registered with `defineDetailExtension()`. */
|
|
161
|
+
export interface DetailExtension {
|
|
162
|
+
/**
|
|
163
|
+
* Names the extension. A page picks extensions by key with the `extensions`
|
|
164
|
+
* prop, and registering a key again replaces the extension.
|
|
165
|
+
*/
|
|
166
|
+
key: string;
|
|
167
|
+
/** Where the detail renders it. */
|
|
168
|
+
placement: DetailExtensionPlacement;
|
|
169
|
+
/**
|
|
170
|
+
* The component, or a loader of it. It reads the detail with
|
|
171
|
+
* `useMapoDetail()`. A function is always taken as a loader.
|
|
172
|
+
*/
|
|
173
|
+
component: Component | DetailExtensionLoader;
|
|
174
|
+
/** Whether a detail page shows it. Default: always. */
|
|
175
|
+
visible?: (detail: MapoDetailContext) => boolean;
|
|
176
|
+
/** Order among the extensions of a placement, lower first. Default: `0`. */
|
|
177
|
+
order?: number;
|
|
178
|
+
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/** Defines a single column in the list table. */
|
|
2
2
|
export interface ListColumn<T = Record<string, unknown>> {
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Property of the row to show, a key of `T`. A dotted path (`category.name`)
|
|
5
|
+
* reads a field of a related object; it starts with a key of `T`.
|
|
6
|
+
*/
|
|
7
|
+
key: (keyof T & string) | `${keyof T & string}.${string}`;
|
|
5
8
|
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* Turns the header into a button that cycles ascending, descending and
|
|
11
|
+
* unsorted. The list sends the order to the backend as `ordering`, or sorts
|
|
12
|
+
* in memory in offline and hybrid mode.
|
|
13
|
+
*/
|
|
6
14
|
sortable?: boolean;
|
|
7
15
|
/** CSS class applied to the `<td>` cell. */
|
|
8
16
|
class?: string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** What a rich text editor writes into a field it leaves empty. */
|
|
2
|
+
const BLANK_MARKUP = /<\/?p>|<br\s*\/?>| /gi;
|
|
3
|
+
|
|
4
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
5
|
+
if (typeof value !== "object") return false;
|
|
6
|
+
if (value === null) return false;
|
|
7
|
+
const prototype: unknown = Object.getPrototypeOf(value);
|
|
8
|
+
const isLiteral = prototype === Object.prototype;
|
|
9
|
+
const isBare = prototype === null;
|
|
10
|
+
return isLiteral || isBare;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Whether a form's value holds something: not `undefined` or `null`, not a
|
|
15
|
+
* blank text (the empty paragraphs and line breaks of a rich text editor
|
|
16
|
+
* included), not an empty list, not an object whose values all hold
|
|
17
|
+
* nothing. `false`, `0` and any other object, such as a file, are values.
|
|
18
|
+
*/
|
|
19
|
+
export function holdsFormValue(value: unknown): boolean {
|
|
20
|
+
if (value === undefined) return false;
|
|
21
|
+
if (value === null) return false;
|
|
22
|
+
if (typeof value === "string") {
|
|
23
|
+
return value.replace(BLANK_MARKUP, " ").trim() !== "";
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
26
|
+
if (isPlainObject(value)) return Object.values(value).some(holdsFormValue);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
@@ -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
|
+
}
|