@mapomodule/uikit 2.0.0-beta.2 → 2.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -142
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoList.component.test.d.ts +2 -0
- package/dist/__tests__/MapoList.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaDrag.test.d.ts +2 -0
- package/dist/__tests__/mediaDrag.test.d.ts.map +1 -0
- package/dist/__tests__/mediaFolders.test.d.ts +2 -0
- package/dist/__tests__/mediaFolders.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/mediaMetadata.test.d.ts +2 -0
- package/dist/__tests__/mediaMetadata.test.d.ts.map +1 -0
- package/dist/__tests__/mediaStore.test.d.ts +2 -0
- package/dist/__tests__/mediaStore.test.d.ts.map +1 -0
- package/dist/__tests__/mediaUrl.test.d.ts +2 -0
- package/dist/__tests__/mediaUrl.test.d.ts.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/module.d.mts +48 -1
- package/dist/module.d.ts +44 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +71 -2
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts +15 -0
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
- package/dist/runtime/adapters/defaultMediaAdapter.js +35 -0
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +127 -55
- package/dist/runtime/components/MapoDetail.vue.d.ts +102 -5
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue +110 -0
- package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoList.vue +45 -31
- package/dist/runtime/components/MapoList.vue.d.ts +18 -5
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +27 -13
- package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
- package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListFilters.vue +4 -2
- package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +20 -10
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +125 -49
- package/dist/runtime/components/MapoListTable.vue.d.ts +13 -5
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogin.vue +13 -10
- package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogoutButton.vue +4 -2
- package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue +382 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +13 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue +129 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts +33 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolders.vue +402 -0
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaGallery.vue +304 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManager.vue +144 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts +44 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaPreview.vue +94 -0
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaUploader.vue +294 -0
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuManager.vue +301 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoSidebar.vue +3 -1
- package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSidebarList.vue +1 -1
- package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
- package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoThemeToggle.vue +5 -1
- package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
- package/dist/runtime/components/menuDndContext.d.ts +19 -0
- package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
- package/dist/runtime/components/menuDndContext.js +3 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/pages/index.vue +4 -3
- package/dist/runtime/pages/index.vue.d.ts.map +1 -1
- package/dist/runtime/pages/login.vue +0 -4
- package/dist/runtime/pages/login.vue.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.d.ts +18 -0
- package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
- package/dist/runtime/plugins/media-adapter.js +8 -0
- package/dist/runtime/stores/media.d.ts +505 -0
- package/dist/runtime/stores/media.d.ts.map +1 -0
- package/dist/runtime/stores/media.js +545 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/types/media.d.ts +131 -0
- package/dist/runtime/types/media.d.ts.map +1 -0
- package/dist/runtime/types/media.js +0 -0
- package/dist/runtime/types/menu.d.ts +66 -0
- package/dist/runtime/types/menu.d.ts.map +1 -0
- package/dist/runtime/types/menu.js +30 -0
- package/dist/runtime/utils/contentLanguages.d.ts +9 -0
- package/dist/runtime/utils/contentLanguages.d.ts.map +1 -0
- package/dist/runtime/utils/contentLanguages.js +8 -0
- package/dist/runtime/utils/langInfo.d.ts +43 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +17 -0
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts.map +1 -0
- package/dist/runtime/utils/mediaDrag.js +11 -0
- package/dist/runtime/utils/mediaFolders.d.ts +65 -0
- package/dist/runtime/utils/mediaFolders.d.ts.map +1 -0
- package/dist/runtime/utils/mediaFolders.js +97 -0
- package/dist/runtime/utils/mediaMetadata.d.ts +39 -0
- package/dist/runtime/utils/mediaMetadata.d.ts.map +1 -0
- package/dist/runtime/utils/mediaMetadata.js +97 -0
- package/dist/runtime/utils/mediaUrl.d.ts +16 -0
- package/dist/runtime/utils/mediaUrl.d.ts.map +1 -0
- package/dist/runtime/utils/mediaUrl.js +12 -0
- package/dist/types.d.mts +1 -1
- package/package.json +15 -11
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +393 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoList.component.test.ts +166 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +545 -0
- package/src/__tests__/MapoMediaEditor.component.test.ts +447 -0
- package/src/__tests__/MapoMediaFolderPicker.component.test.ts +220 -0
- package/src/__tests__/MapoMediaFolders.component.test.ts +519 -0
- package/src/__tests__/MapoMediaGallery.component.test.ts +211 -0
- package/src/__tests__/MapoMediaUploadHandover.component.test.ts +241 -0
- package/src/__tests__/MapoMenuManager.component.test.ts +175 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/langInfo.test.ts +85 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaDrag.test.ts +42 -0
- package/src/__tests__/mediaFolders.test.ts +204 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/mediaMetadata.test.ts +169 -0
- package/src/__tests__/mediaStore.test.ts +569 -0
- package/src/__tests__/mediaUrl.test.ts +44 -0
- package/src/index.ts +21 -0
- package/src/module.ts +155 -0
- package/src/runtime/adapters/defaultMediaAdapter.ts +67 -0
- package/src/runtime/assets/main.css +9 -0
- package/src/runtime/components/MapoConfirmDialog.vue +33 -4
- package/src/runtime/components/MapoDetail.vue +229 -73
- package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
- package/src/runtime/components/MapoDropArea.vue +145 -0
- package/src/runtime/components/MapoLangSwitcher.vue +74 -0
- package/src/runtime/components/MapoList.vue +65 -34
- package/src/runtime/components/MapoListActions.vue +32 -14
- package/src/runtime/components/MapoListFilters.vue +5 -2
- package/src/runtime/components/MapoListQuickEdit.vue +22 -10
- package/src/runtime/components/MapoListTable.vue +159 -59
- package/src/runtime/components/MapoLogin.vue +13 -10
- package/src/runtime/components/MapoLogoutButton.vue +4 -2
- package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
- package/src/runtime/components/MapoMediaEditor.vue +447 -0
- package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
- package/src/runtime/components/MapoMediaFolderPicker.vue +176 -0
- package/src/runtime/components/MapoMediaFolders.vue +478 -0
- package/src/runtime/components/MapoMediaGallery.vue +350 -0
- package/src/runtime/components/MapoMediaManager.vue +194 -0
- package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
- package/src/runtime/components/MapoMediaPreview.vue +116 -0
- package/src/runtime/components/MapoMediaUploader.vue +362 -0
- package/src/runtime/components/MapoMenuManager.vue +454 -0
- package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
- package/src/runtime/components/MapoMenuTreeview.vue +264 -0
- package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
- package/src/runtime/components/MapoSidebar.vue +3 -1
- package/src/runtime/components/MapoSidebarList.vue +1 -1
- package/src/runtime/components/MapoSidebarProfile.vue +6 -2
- package/src/runtime/components/MapoSnackBar.vue +12 -0
- package/src/runtime/components/MapoThemeToggle.vue +5 -1
- package/src/runtime/components/menuDndContext.ts +22 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/pages/index.vue +4 -3
- package/src/runtime/pages/login.vue +0 -4
- package/src/runtime/plugins/media-adapter.ts +33 -0
- package/src/runtime/stores/media.ts +820 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/types/media.ts +144 -0
- package/src/runtime/types/menu.ts +105 -0
- package/src/runtime/utils/contentLanguages.ts +18 -0
- package/src/runtime/utils/langInfo.ts +63 -0
- package/src/runtime/utils/listTable.ts +54 -0
- package/src/runtime/utils/mediaDrag.ts +29 -0
- package/src/runtime/utils/mediaFolders.ts +182 -0
- package/src/runtime/utils/mediaMetadata.ts +165 -0
- package/src/runtime/utils/mediaUrl.ts +30 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import { isMediaDrag } from "../utils/mediaDrag.js";
|
|
5
|
+
|
|
6
|
+
const { t } = useI18n();
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
accept?: string;
|
|
11
|
+
multiple?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}>(),
|
|
14
|
+
{
|
|
15
|
+
accept: "*/*",
|
|
16
|
+
multiple: true,
|
|
17
|
+
disabled: false,
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits<{
|
|
22
|
+
files: [files: File[]];
|
|
23
|
+
}>();
|
|
24
|
+
|
|
25
|
+
const isDragging = ref(false);
|
|
26
|
+
const fileInput = ref<HTMLInputElement | null>(null);
|
|
27
|
+
let dragCounter = 0;
|
|
28
|
+
|
|
29
|
+
// Only files dragged in from the computer are drops for this area: an element
|
|
30
|
+
// dragged inside the page (a gallery card, a selection being reordered) is
|
|
31
|
+
// left to whatever handles it, with no overlay and no default prevented.
|
|
32
|
+
// Chrome reports an image dragged from the page as "Files" too, so a drag the
|
|
33
|
+
// media manager started is told apart by its own data type.
|
|
34
|
+
function carriesFiles(e: DragEvent): boolean {
|
|
35
|
+
const hasFiles = Array.from(e.dataTransfer?.types ?? []).includes("Files");
|
|
36
|
+
return hasFiles && !isMediaDrag(e);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function onDragEnter(e: DragEvent) {
|
|
40
|
+
if (props.disabled || !carriesFiles(e)) return;
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
dragCounter++;
|
|
43
|
+
isDragging.value = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function onDragOver(e: DragEvent) {
|
|
47
|
+
if (props.disabled || !carriesFiles(e)) return;
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function onDragLeave(e: DragEvent) {
|
|
52
|
+
if (!carriesFiles(e)) return;
|
|
53
|
+
dragCounter--;
|
|
54
|
+
if (dragCounter <= 0) {
|
|
55
|
+
dragCounter = 0;
|
|
56
|
+
isDragging.value = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function onDrop(e: DragEvent) {
|
|
61
|
+
if (props.disabled || !carriesFiles(e)) return;
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
isDragging.value = false;
|
|
64
|
+
dragCounter = 0;
|
|
65
|
+
const files = filterFiles(Array.from(e.dataTransfer?.files ?? []));
|
|
66
|
+
if (files.length) emit("files", files);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function onFileInput(e: Event) {
|
|
70
|
+
const input = e.target as HTMLInputElement;
|
|
71
|
+
const files = filterFiles(Array.from(input.files ?? []));
|
|
72
|
+
if (files.length) emit("files", files);
|
|
73
|
+
input.value = "";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function triggerPick() {
|
|
77
|
+
if (!props.disabled) fileInput.value?.click();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function filterFiles(files: File[]): File[] {
|
|
81
|
+
if (!props.accept || props.accept === "*/*") return files;
|
|
82
|
+
return files.filter((f) => matchesMime(f.type, props.accept));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function matchesMime(mime: string, accept: string): boolean {
|
|
86
|
+
return accept.split(",").some((pattern) => {
|
|
87
|
+
const p = pattern.trim();
|
|
88
|
+
if (p === "*/*") return true;
|
|
89
|
+
if (p.endsWith("/*")) return mime.startsWith(p.replace("/*", "/"));
|
|
90
|
+
return mime === p;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
defineExpose({ triggerPick });
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<template>
|
|
98
|
+
<div
|
|
99
|
+
class="mapo-drop-area relative"
|
|
100
|
+
:class="{
|
|
101
|
+
'mapo-drop-area--dragging': isDragging,
|
|
102
|
+
'opacity-50 pointer-events-none': disabled,
|
|
103
|
+
}"
|
|
104
|
+
@dragenter="onDragEnter"
|
|
105
|
+
@dragover="onDragOver"
|
|
106
|
+
@dragleave="onDragLeave"
|
|
107
|
+
@drop="onDrop"
|
|
108
|
+
>
|
|
109
|
+
<input
|
|
110
|
+
ref="fileInput"
|
|
111
|
+
type="file"
|
|
112
|
+
class="sr-only"
|
|
113
|
+
:accept="accept"
|
|
114
|
+
:multiple="multiple"
|
|
115
|
+
@change="onFileInput"
|
|
116
|
+
/>
|
|
117
|
+
|
|
118
|
+
<slot :trigger-pick="triggerPick" :is-dragging="isDragging" />
|
|
119
|
+
|
|
120
|
+
<Transition name="drop-overlay">
|
|
121
|
+
<div
|
|
122
|
+
v-if="isDragging"
|
|
123
|
+
class="pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-default/80"
|
|
124
|
+
>
|
|
125
|
+
<div class="flex flex-col items-center gap-2 text-primary">
|
|
126
|
+
<UIcon name="i-lucide-upload-cloud" class="size-10" />
|
|
127
|
+
<span class="text-sm font-medium">{{
|
|
128
|
+
t("mapo.dropArea.dropHere")
|
|
129
|
+
}}</span>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</Transition>
|
|
133
|
+
</div>
|
|
134
|
+
</template>
|
|
135
|
+
|
|
136
|
+
<style scoped>
|
|
137
|
+
.drop-overlay-enter-active,
|
|
138
|
+
.drop-overlay-leave-active {
|
|
139
|
+
transition: opacity 0.15s ease;
|
|
140
|
+
}
|
|
141
|
+
.drop-overlay-enter-from,
|
|
142
|
+
.drop-overlay-leave-to {
|
|
143
|
+
opacity: 0;
|
|
144
|
+
}
|
|
145
|
+
</style>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { Ref } from "vue";
|
|
4
|
+
import { useI18n } from "vue-i18n";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* UI locale switcher — lists the locales configured in `@nuxtjs/i18n`
|
|
8
|
+
* (via `@mapomodule/i18n`) and switches the interface language with
|
|
9
|
+
* cookie persistence. Port of the v1 `LangSwitcher`.
|
|
10
|
+
*/
|
|
11
|
+
const props = withDefaults(
|
|
12
|
+
defineProps<{
|
|
13
|
+
/** Show the flag emoji derived from the locale `language` tag. */
|
|
14
|
+
flags?: boolean;
|
|
15
|
+
/** Nuxt UI USelectMenu `size` prop. */
|
|
16
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
17
|
+
}>(),
|
|
18
|
+
{ flags: true, size: "sm" },
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
interface SwitcherLocale {
|
|
22
|
+
code: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
language?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// `locales` and `setLocale` are @nuxtjs/i18n Composer extensions; the uikit
|
|
28
|
+
// package only depends on vue-i18n types, so they are typed structurally.
|
|
29
|
+
const { locale, locales, setLocale } = useI18n() as unknown as {
|
|
30
|
+
locale: Ref<string>;
|
|
31
|
+
locales: Ref<SwitcherLocale[]>;
|
|
32
|
+
setLocale: (code: string) => Promise<void>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Regional-indicator flag emoji from a BCP-47 tag (e.g. `en-US` → 🇺🇸). */
|
|
36
|
+
function getFlag(language?: string): string {
|
|
37
|
+
const region = language?.split("-").at(-1);
|
|
38
|
+
if (!region || region.length !== 2 || !/^[A-Za-z]+$/.test(region)) return "";
|
|
39
|
+
const codePoints = region
|
|
40
|
+
.toUpperCase()
|
|
41
|
+
.split("")
|
|
42
|
+
.map((char) => 127397 + char.charCodeAt(0));
|
|
43
|
+
return String.fromCodePoint(...codePoints);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const items = computed(() =>
|
|
47
|
+
locales.value.map((l) => ({
|
|
48
|
+
label:
|
|
49
|
+
props.flags && getFlag(l.language)
|
|
50
|
+
? `${getFlag(l.language)} ${l.name ?? l.code.toUpperCase()}`
|
|
51
|
+
: (l.name ?? l.code.toUpperCase()),
|
|
52
|
+
value: l.code,
|
|
53
|
+
})),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const current = computed({
|
|
57
|
+
get: () => locale.value,
|
|
58
|
+
set: (code: string) => {
|
|
59
|
+
if (code && code !== locale.value) setLocale(code);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<USelectMenu
|
|
66
|
+
v-model="current"
|
|
67
|
+
:items="items"
|
|
68
|
+
value-key="value"
|
|
69
|
+
label-key="label"
|
|
70
|
+
:size="size"
|
|
71
|
+
:search-input="false"
|
|
72
|
+
class="w-40"
|
|
73
|
+
/>
|
|
74
|
+
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends object">
|
|
2
|
-
import { ref, computed, watch, useSlots } from "vue";
|
|
2
|
+
import { ref, computed, watch, useSlots, onBeforeUnmount } from "vue";
|
|
3
3
|
import type { Ref } from "vue";
|
|
4
4
|
import type {
|
|
5
5
|
ListColumn,
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
} from "../types/list.js";
|
|
12
12
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
13
13
|
import { debounce } from "@mapomodule/utils";
|
|
14
|
-
import { useRoute, useRouter } from "
|
|
14
|
+
import { useRoute, useRouter } from "#app";
|
|
15
15
|
|
|
16
16
|
const props = withDefaults(
|
|
17
17
|
defineProps<{
|
|
@@ -30,6 +30,7 @@ const props = withDefaults(
|
|
|
30
30
|
* Ignored when `items` is provided.
|
|
31
31
|
*/
|
|
32
32
|
clientSide?: boolean;
|
|
33
|
+
/** Column definitions. A dotted `key` (`category.name`) reads a field of a related object. */
|
|
33
34
|
columns: ListColumn<T>[];
|
|
34
35
|
lookup?: string;
|
|
35
36
|
// Filters
|
|
@@ -56,11 +57,20 @@ const props = withDefaults(
|
|
|
56
57
|
* hides the trash unless the user has `delete_article`. Omit to always show both.
|
|
57
58
|
*/
|
|
58
59
|
permissionModel?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to include the built-in permanent delete bulk action.
|
|
62
|
+
* Defaults to `true`; custom `actions` are unaffected.
|
|
63
|
+
*/
|
|
64
|
+
defaultActions?: boolean;
|
|
59
65
|
// Pagination
|
|
60
|
-
/** Initial page size
|
|
61
|
-
defaultPageSize?: number;
|
|
62
|
-
/**
|
|
63
|
-
|
|
66
|
+
/** Initial page size: a number, or `"all"`. Default: 20. */
|
|
67
|
+
defaultPageSize?: number | "all";
|
|
68
|
+
/**
|
|
69
|
+
* Options of the per-page selector. `"all"` adds an option that requests
|
|
70
|
+
* the list without pagination params, like `clientSide` does: the backend
|
|
71
|
+
* has to return the whole collection then. Default: [10, 20, 50, 100].
|
|
72
|
+
*/
|
|
73
|
+
pageSizeOptions?: (number | "all")[];
|
|
64
74
|
/**
|
|
65
75
|
* Custom response parser. Replaces the built-in DRF / flat-array detection.
|
|
66
76
|
* Return `{ items, total }` from any shape your backend returns.
|
|
@@ -169,6 +179,9 @@ const writeUrlState = debounce(() => {
|
|
|
169
179
|
|
|
170
180
|
watch([activeTab, activeFilters], writeUrlState, { deep: true });
|
|
171
181
|
|
|
182
|
+
// A URL write still pending when the list goes away would land on the next page.
|
|
183
|
+
onBeforeUnmount(() => writeUrlState.cancel());
|
|
184
|
+
|
|
172
185
|
// --- crudEndpoint: base path for mutations (no query string). ---
|
|
173
186
|
const crudEndpoint = computed(
|
|
174
187
|
() => (props.endpoint ?? "").split("?")[0] || (props.endpoint ?? ""),
|
|
@@ -204,7 +217,10 @@ defineSlots<
|
|
|
204
217
|
{
|
|
205
218
|
/** Content rendered inside the list head area (title, breadcrumbs, action buttons). */
|
|
206
219
|
head(): unknown;
|
|
207
|
-
/**
|
|
220
|
+
/**
|
|
221
|
+
* Extra content in the table's toolbar, after the search input. The bulk
|
|
222
|
+
* actions follow it, at the end of the row, while rows are selected.
|
|
223
|
+
*/
|
|
208
224
|
"dtable.toolbar"(): unknown;
|
|
209
225
|
/** Override for the empty state displayed when no rows are found. */
|
|
210
226
|
"dtable.empty"(): unknown;
|
|
@@ -249,6 +265,18 @@ defineSlots<
|
|
|
249
265
|
const slots = useSlots();
|
|
250
266
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
251
267
|
const forwardedSlotNames = computed(() => Object.keys(slots) as any[]);
|
|
268
|
+
// `dtable.toolbar` reaches the table together with the bulk actions, below.
|
|
269
|
+
const forwardedTableSlotNames = computed(() =>
|
|
270
|
+
forwardedSlotNames.value.filter((name) => name !== "dtable.toolbar"),
|
|
271
|
+
);
|
|
272
|
+
const hasSelection = computed(
|
|
273
|
+
() => selection.value === "all" || selection.value.length > 0,
|
|
274
|
+
);
|
|
275
|
+
// The table's toolbar row: with the search, with the app's toolbar content,
|
|
276
|
+
// or for the bulk actions while rows are selected.
|
|
277
|
+
const hasTableToolbar = computed(
|
|
278
|
+
() => props.searchable || !!slots["dtable.toolbar"] || hasSelection.value,
|
|
279
|
+
);
|
|
252
280
|
|
|
253
281
|
// Reset selection when the active tab or filters change
|
|
254
282
|
watch([activeTab, activeFilters], () => {
|
|
@@ -273,33 +301,20 @@ watch([activeTab, activeFilters], () => {
|
|
|
273
301
|
@update:model-value="activeTab = $event"
|
|
274
302
|
/>
|
|
275
303
|
|
|
276
|
-
<!--
|
|
277
|
-
<
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
304
|
+
<!-- Filters (they render nothing without filters) -->
|
|
305
|
+
<MapoListFilters
|
|
306
|
+
:filters="filters"
|
|
307
|
+
:model-value="activeFilters"
|
|
308
|
+
@update:model-value="activeFilters = $event"
|
|
309
|
+
>
|
|
310
|
+
<template
|
|
311
|
+
v-for="name in forwardedSlotNames"
|
|
312
|
+
:key="name"
|
|
313
|
+
#[name]="slotProps"
|
|
282
314
|
>
|
|
283
|
-
<
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
#[name]="slotProps"
|
|
287
|
-
>
|
|
288
|
-
<slot :name="name" v-bind="slotProps ?? {}" />
|
|
289
|
-
</template>
|
|
290
|
-
</MapoListFilters>
|
|
291
|
-
|
|
292
|
-
<div class="ml-auto">
|
|
293
|
-
<MapoListActions
|
|
294
|
-
:actions="actions"
|
|
295
|
-
:selection="selection"
|
|
296
|
-
:selection-query="selectionQuery"
|
|
297
|
-
:endpoint="crudEndpoint"
|
|
298
|
-
:lookup="lookup"
|
|
299
|
-
@action-completed="refresh"
|
|
300
|
-
/>
|
|
301
|
-
</div>
|
|
302
|
-
</div>
|
|
315
|
+
<slot :name="name" v-bind="slotProps ?? {}" />
|
|
316
|
+
</template>
|
|
317
|
+
</MapoListFilters>
|
|
303
318
|
|
|
304
319
|
<!-- Table -->
|
|
305
320
|
<MapoListTable
|
|
@@ -328,12 +343,28 @@ watch([activeTab, activeFilters], () => {
|
|
|
328
343
|
@update:items="emit('update:items', $event)"
|
|
329
344
|
>
|
|
330
345
|
<template
|
|
331
|
-
v-for="name in
|
|
346
|
+
v-for="name in forwardedTableSlotNames"
|
|
332
347
|
:key="name"
|
|
333
348
|
#[name]="slotProps"
|
|
334
349
|
>
|
|
335
350
|
<slot :name="name" v-bind="slotProps ?? {}" />
|
|
336
351
|
</template>
|
|
352
|
+
<!-- The bulk actions act on the selected rows: they sit in the table's
|
|
353
|
+
toolbar, after the search and the app's toolbar content. -->
|
|
354
|
+
<template v-if="hasTableToolbar" #[`dtable.toolbar`]>
|
|
355
|
+
<slot name="dtable.toolbar" />
|
|
356
|
+
<MapoListActions
|
|
357
|
+
class="ml-auto"
|
|
358
|
+
:actions="actions"
|
|
359
|
+
:selection="selection"
|
|
360
|
+
:selection-query="selectionQuery"
|
|
361
|
+
:endpoint="crudEndpoint"
|
|
362
|
+
:lookup="lookup"
|
|
363
|
+
:permission-model="permissionModel"
|
|
364
|
+
:default-actions="defaultActions"
|
|
365
|
+
@action-completed="refresh"
|
|
366
|
+
/>
|
|
367
|
+
</template>
|
|
337
368
|
</MapoListTable>
|
|
338
369
|
</div>
|
|
339
370
|
</template>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends object">
|
|
2
2
|
import { ref, computed } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
3
4
|
import type { ActionDescriptor } from "../types/list.js";
|
|
4
5
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
5
6
|
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
6
7
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
7
8
|
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
9
|
+
import { getErrorDetail } from "@mapomodule/core/runtime/utils/fetchError";
|
|
8
10
|
|
|
9
11
|
const props = withDefaults(
|
|
10
12
|
defineProps<{
|
|
@@ -13,10 +15,16 @@ const props = withDefaults(
|
|
|
13
15
|
selectionQuery: URLSearchParams;
|
|
14
16
|
endpoint: string;
|
|
15
17
|
lookup?: string;
|
|
18
|
+
/** Django model label used to gate the built-in permanent delete action. */
|
|
19
|
+
permissionModel?: string;
|
|
20
|
+
/** Whether to include the built-in permanent delete action. */
|
|
21
|
+
defaultActions?: boolean;
|
|
16
22
|
}>(),
|
|
17
23
|
{
|
|
18
24
|
actions: () => [],
|
|
19
25
|
lookup: "id",
|
|
26
|
+
permissionModel: undefined,
|
|
27
|
+
defaultActions: true,
|
|
20
28
|
},
|
|
21
29
|
);
|
|
22
30
|
|
|
@@ -29,15 +37,17 @@ defineSlots<{
|
|
|
29
37
|
append(): any;
|
|
30
38
|
}>();
|
|
31
39
|
|
|
40
|
+
const { t } = useI18n();
|
|
32
41
|
const snack = useSnackStore();
|
|
33
42
|
const confirm = useConfirmStore();
|
|
43
|
+
const { canDelete, checkPermission } = usePermissions();
|
|
34
44
|
const crud = useCrud<T>(props.endpoint);
|
|
35
45
|
|
|
36
46
|
const isRunning = ref(false);
|
|
37
47
|
|
|
38
|
-
const
|
|
48
|
+
const builtInActions = computed<ActionDescriptor<T>[]>(() => [
|
|
39
49
|
{
|
|
40
|
-
label: "
|
|
50
|
+
label: t("mapo.listActions.permanentDelete"),
|
|
41
51
|
handler: async ({ selection }) => {
|
|
42
52
|
if (!selection) return;
|
|
43
53
|
await Promise.all(
|
|
@@ -48,13 +58,15 @@ const defaultActions = computed<ActionDescriptor<T>[]>(() => [
|
|
|
48
58
|
),
|
|
49
59
|
);
|
|
50
60
|
},
|
|
51
|
-
permissions: "delete",
|
|
52
61
|
handleMultiple: true,
|
|
53
62
|
handleAll: false,
|
|
54
63
|
},
|
|
55
64
|
]);
|
|
56
65
|
|
|
57
|
-
const allActions = computed(() => [
|
|
66
|
+
const allActions = computed(() => [
|
|
67
|
+
...(props.defaultActions ? builtInActions.value : []),
|
|
68
|
+
...props.actions,
|
|
69
|
+
]);
|
|
58
70
|
|
|
59
71
|
const visibleActions = computed(() =>
|
|
60
72
|
allActions.value.filter((a) =>
|
|
@@ -77,13 +89,16 @@ const applyButtonColor = computed(() =>
|
|
|
77
89
|
);
|
|
78
90
|
|
|
79
91
|
function canRun(action: ActionDescriptor<T>): boolean {
|
|
92
|
+
if (builtInActions.value.includes(action)) {
|
|
93
|
+
return !props.permissionModel || canDelete(props.permissionModel);
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
const perms = action.permissions
|
|
81
97
|
? Array.isArray(action.permissions)
|
|
82
98
|
? action.permissions
|
|
83
99
|
: [action.permissions]
|
|
84
100
|
: [];
|
|
85
101
|
if (!perms.length) return true;
|
|
86
|
-
const { checkPermission } = usePermissions();
|
|
87
102
|
return perms.every((p) => checkPermission(p));
|
|
88
103
|
}
|
|
89
104
|
|
|
@@ -95,9 +110,11 @@ async function runAction() {
|
|
|
95
110
|
title: action.label,
|
|
96
111
|
message:
|
|
97
112
|
props.selection === "all"
|
|
98
|
-
? "
|
|
99
|
-
:
|
|
100
|
-
|
|
113
|
+
? t("mapo.listActions.confirmBulk")
|
|
114
|
+
: t("mapo.listActions.confirmBulkCount", {
|
|
115
|
+
count: (props.selection as T[]).length,
|
|
116
|
+
}),
|
|
117
|
+
confirmText: t("mapo.confirm"),
|
|
101
118
|
dangerous: !!action.dangerous,
|
|
102
119
|
});
|
|
103
120
|
if (!ok) return;
|
|
@@ -109,13 +126,14 @@ async function runAction() {
|
|
|
109
126
|
selectionQuery: props.selectionQuery,
|
|
110
127
|
lookup: props.lookup,
|
|
111
128
|
});
|
|
112
|
-
snack.show("
|
|
129
|
+
snack.show(t("mapo.listActions.actionCompleted"), "success");
|
|
113
130
|
emit("actionCompleted");
|
|
114
131
|
selectedLabel.value = undefined;
|
|
115
132
|
} catch (err: unknown) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
snack.show(
|
|
134
|
+
getErrorDetail(err) ?? t("mapo.listActions.actionFailed"),
|
|
135
|
+
"error",
|
|
136
|
+
);
|
|
119
137
|
} finally {
|
|
120
138
|
isRunning.value = false;
|
|
121
139
|
}
|
|
@@ -134,7 +152,7 @@ const isActive = computed(
|
|
|
134
152
|
:items="visibleActions"
|
|
135
153
|
value-key="label"
|
|
136
154
|
label-key="label"
|
|
137
|
-
placeholder="
|
|
155
|
+
:placeholder="t('mapo.listActions.bulkActions')"
|
|
138
156
|
size="sm"
|
|
139
157
|
class="min-w-48"
|
|
140
158
|
/>
|
|
@@ -145,7 +163,7 @@ const isActive = computed(
|
|
|
145
163
|
:disabled="!selectedAction || !canRun(selectedAction)"
|
|
146
164
|
@click="runAction"
|
|
147
165
|
>
|
|
148
|
-
|
|
166
|
+
{{ t("mapo.apply") }}
|
|
149
167
|
</UButton>
|
|
150
168
|
<slot name="append" />
|
|
151
169
|
</div>
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, computed, watch } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
3
4
|
import type {
|
|
4
5
|
FilterDescriptor,
|
|
5
6
|
ActiveFilter,
|
|
6
7
|
FilterChoice,
|
|
7
8
|
} from "../types/list.js";
|
|
8
9
|
|
|
10
|
+
const { t } = useI18n();
|
|
11
|
+
|
|
9
12
|
const props = defineProps<{
|
|
10
13
|
filters: FilterDescriptor[];
|
|
11
14
|
modelValue: ActiveFilter[];
|
|
@@ -188,7 +191,7 @@ const isOpen = ref(false);
|
|
|
188
191
|
color="neutral"
|
|
189
192
|
@click="removeAll"
|
|
190
193
|
>
|
|
191
|
-
|
|
194
|
+
{{ t("mapo.listFilters.clearAll") }}
|
|
192
195
|
</UButton>
|
|
193
196
|
|
|
194
197
|
<!-- Filter dropdown button -->
|
|
@@ -201,7 +204,7 @@ const isOpen = ref(false);
|
|
|
201
204
|
:disabled="disabled"
|
|
202
205
|
trailing-icon=""
|
|
203
206
|
>
|
|
204
|
-
|
|
207
|
+
{{ t("mapo.listFilters.filters") }}
|
|
205
208
|
</UButton>
|
|
206
209
|
|
|
207
210
|
<template #content>
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends object">
|
|
2
2
|
import { ref, computed, watch } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
3
4
|
import type { Ref } from "vue";
|
|
4
5
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
5
6
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
6
7
|
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
8
|
+
import { getErrorDetail } from "@mapomodule/core/runtime/utils/fetchError";
|
|
9
|
+
import { restrictLanguages } from "../utils/langInfo";
|
|
10
|
+
import { useContentLanguages } from "../utils/contentLanguages";
|
|
7
11
|
|
|
8
12
|
const props = withDefaults(
|
|
9
13
|
defineProps<{
|
|
@@ -45,9 +49,17 @@ defineSlots<{
|
|
|
45
49
|
extra(props: { model: T }): any;
|
|
46
50
|
}>();
|
|
47
51
|
|
|
52
|
+
const { t } = useI18n();
|
|
48
53
|
const snack = useSnackStore();
|
|
49
54
|
const crud = useCrud<T>(props.endpoint);
|
|
50
55
|
|
|
56
|
+
// The languages the form syncs `synci18n` fields into, narrowed to the app's
|
|
57
|
+
// `mapo.uikit.contentLanguages` as MapoDetail narrows its own.
|
|
58
|
+
const contentLanguages = useContentLanguages();
|
|
59
|
+
const formLanguages = computed(() =>
|
|
60
|
+
restrictLanguages(props.languages ?? [], contentLanguages),
|
|
61
|
+
);
|
|
62
|
+
|
|
51
63
|
// Typed as Ref<T> (not Ref<UnwrapRef<T>>) so the template unwrap stays exactly T,
|
|
52
64
|
// which keeps the `extra` slot's `:model` binding type-correct for the generic T.
|
|
53
65
|
const model = ref({} as T) as Ref<T>;
|
|
@@ -77,7 +89,7 @@ watch(
|
|
|
77
89
|
try {
|
|
78
90
|
model.value = await crud.detail(id as string | number);
|
|
79
91
|
} catch {
|
|
80
|
-
snack.show("
|
|
92
|
+
snack.show(t("mapo.loadItemError"), "error");
|
|
81
93
|
isOpen.value = false;
|
|
82
94
|
} finally {
|
|
83
95
|
loading.value = false;
|
|
@@ -91,7 +103,7 @@ async function save() {
|
|
|
91
103
|
// Offline: no backend roundtrip — emit the locally edited model and let
|
|
92
104
|
// the parent splice it back into the source array.
|
|
93
105
|
if (props.offline) {
|
|
94
|
-
snack.show("
|
|
106
|
+
snack.show(t("mapo.saveSuccess"), "success");
|
|
95
107
|
emit("saved", { ...model.value } as T);
|
|
96
108
|
isOpen.value = false;
|
|
97
109
|
return;
|
|
@@ -100,13 +112,11 @@ async function save() {
|
|
|
100
112
|
props.itemId != null
|
|
101
113
|
? await crud.partialUpdate(props.itemId as string | number, model.value)
|
|
102
114
|
: await crud.create(model.value);
|
|
103
|
-
snack.show("
|
|
115
|
+
snack.show(t("mapo.saveSuccess"), "success");
|
|
104
116
|
emit("saved", result);
|
|
105
117
|
isOpen.value = false;
|
|
106
118
|
} catch (err: unknown) {
|
|
107
|
-
|
|
108
|
-
?.response?.data?.detail;
|
|
109
|
-
snack.show(detail ?? "Failed to save", "error");
|
|
119
|
+
snack.show(getErrorDetail(err) ?? t("mapo.saveError"), "error");
|
|
110
120
|
} finally {
|
|
111
121
|
saving.value = false;
|
|
112
122
|
}
|
|
@@ -119,7 +129,9 @@ async function save() {
|
|
|
119
129
|
<div class="p-6 space-y-4">
|
|
120
130
|
<div class="flex items-center justify-between">
|
|
121
131
|
<h3 class="text-base font-semibold text-highlighted">
|
|
122
|
-
{{
|
|
132
|
+
{{
|
|
133
|
+
itemId != null ? t("mapo.edit") : t("mapo.listQuickEdit.newItem")
|
|
134
|
+
}}
|
|
123
135
|
</h3>
|
|
124
136
|
<UButton
|
|
125
137
|
size="xs"
|
|
@@ -141,7 +153,7 @@ async function save() {
|
|
|
141
153
|
<MapoForm
|
|
142
154
|
v-model="model"
|
|
143
155
|
:fields="editFields"
|
|
144
|
-
:languages="
|
|
156
|
+
:languages="formLanguages"
|
|
145
157
|
:registry="registry"
|
|
146
158
|
immediate
|
|
147
159
|
/>
|
|
@@ -150,10 +162,10 @@ async function save() {
|
|
|
150
162
|
|
|
151
163
|
<div class="flex justify-end gap-2 pt-2">
|
|
152
164
|
<UButton variant="ghost" color="neutral" @click="isOpen = false">
|
|
153
|
-
|
|
165
|
+
{{ t("mapo.cancel") }}
|
|
154
166
|
</UButton>
|
|
155
167
|
<UButton color="primary" :loading="saving" @click="save">
|
|
156
|
-
|
|
168
|
+
{{ t("mapo.save") }}
|
|
157
169
|
</UButton>
|
|
158
170
|
</div>
|
|
159
171
|
</template>
|