@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,447 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch, computed, onMounted } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import { useRuntimeConfig } from "#app";
|
|
5
|
+
import {
|
|
6
|
+
humanFileSize,
|
|
7
|
+
deepClone,
|
|
8
|
+
getNestedValue,
|
|
9
|
+
setNestedValue,
|
|
10
|
+
} from "@mapomodule/utils";
|
|
11
|
+
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
12
|
+
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
13
|
+
import { getErrorData } from "@mapomodule/core/runtime/utils/fetchError";
|
|
14
|
+
import { useMediaStore } from "../stores/media.js";
|
|
15
|
+
import { pickLanguage, restrictLanguages } from "../utils/langInfo.js";
|
|
16
|
+
import { useContentLanguages } from "../utils/contentLanguages.js";
|
|
17
|
+
import { describeMediaErrors, pickMetadata } from "../utils/mediaMetadata.js";
|
|
18
|
+
import { mediaFileUrl } from "../utils/mediaUrl.js";
|
|
19
|
+
import type { MediaFolder, MediaItem } from "../types/media.js";
|
|
20
|
+
|
|
21
|
+
const props = defineProps<{
|
|
22
|
+
/** Overrides the languages read from the endpoint. Rarely needed. */
|
|
23
|
+
languages?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Language the editor opens on, when it is among the languages. Default: the
|
|
26
|
+
* first one. A `?lang=` in the page URL wins, as in `MapoDetail`.
|
|
27
|
+
*/
|
|
28
|
+
defaultLang?: string;
|
|
29
|
+
}>();
|
|
30
|
+
|
|
31
|
+
const { t } = useI18n();
|
|
32
|
+
const store = useMediaStore();
|
|
33
|
+
const snack = useSnackStore();
|
|
34
|
+
|
|
35
|
+
// Model-permission gating (legacy parity): edit/delete only with the
|
|
36
|
+
// change/delete permission on the configured media model.
|
|
37
|
+
const runtimeConfig = useRuntimeConfig();
|
|
38
|
+
const permissionsModel =
|
|
39
|
+
((runtimeConfig.public.mapoMedia ?? {}) as { permissionsModel?: string })
|
|
40
|
+
.permissionsModel ?? "media";
|
|
41
|
+
const { canChange, canDelete } = usePermissions();
|
|
42
|
+
const canEdit = computed(() => canChange(permissionsModel));
|
|
43
|
+
const canRemove = computed(() => canDelete(permissionsModel));
|
|
44
|
+
|
|
45
|
+
const editing = ref(false);
|
|
46
|
+
const saving = ref(false);
|
|
47
|
+
const newFile = ref<File | null>(null);
|
|
48
|
+
const maintainUrl = ref(false);
|
|
49
|
+
// Remounts the file changer, clearing the file it shows, once that file is stored.
|
|
50
|
+
const fileChangerKey = ref(0);
|
|
51
|
+
|
|
52
|
+
// The languages actually offered. An explicit prop wins; otherwise the store's
|
|
53
|
+
// list: the manager's own, or the media endpoint's OPTIONS metadata, so a host
|
|
54
|
+
// page never has to restate what the backend already knows — and a media model
|
|
55
|
+
// nobody registered for translation shows no switcher rather than tabs whose
|
|
56
|
+
// values it discards. Either is narrowed to the app's content languages: the
|
|
57
|
+
// store's list already is, the prop is here.
|
|
58
|
+
const contentLanguages = useContentLanguages();
|
|
59
|
+
const activeLangs = computed(() =>
|
|
60
|
+
props.languages?.length
|
|
61
|
+
? restrictLanguages(props.languages, contentLanguages)
|
|
62
|
+
: store.activeLanguages,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// The language being edited, `""` when media are not translated. There is no
|
|
66
|
+
// "untranslated" tab next to the languages: on a backend that translates media
|
|
67
|
+
// the plain fields are the active language's columns under another name, and
|
|
68
|
+
// Camomilla drops them on write, so every edit goes to a translation.
|
|
69
|
+
const currentLang = ref("");
|
|
70
|
+
watch(
|
|
71
|
+
activeLangs,
|
|
72
|
+
(langs) => {
|
|
73
|
+
const isOffered = langs.includes(currentLang.value);
|
|
74
|
+
if (isOffered) return;
|
|
75
|
+
currentLang.value = pickLanguage(
|
|
76
|
+
langs,
|
|
77
|
+
props.defaultLang ?? store.initialLanguage,
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
{ immediate: true },
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
onMounted(() => {
|
|
84
|
+
store.deriveLanguages();
|
|
85
|
+
});
|
|
86
|
+
// Pristine copy taken when entering edit mode, restored on Cancel — the form
|
|
87
|
+
// mutates store.editMedia directly, so without this Cancel would leave the
|
|
88
|
+
// unsaved edits visible in the info panel (legacy used deepClone the same way).
|
|
89
|
+
let editSnapshot: MediaItem | null = null;
|
|
90
|
+
|
|
91
|
+
const media = computed(() => store.editMedia);
|
|
92
|
+
|
|
93
|
+
// Reset the edit session only when a DIFFERENT media is opened. Watching the
|
|
94
|
+
// object itself would fire on every keystroke: setFieldValue reassigns
|
|
95
|
+
// store.editMedia (setNestedValue is immutable) and would close the form.
|
|
96
|
+
watch(
|
|
97
|
+
() => store.editMedia?.id,
|
|
98
|
+
(id, oldId) => {
|
|
99
|
+
if (id != null && id !== oldId) {
|
|
100
|
+
editing.value = false;
|
|
101
|
+
newFile.value = null;
|
|
102
|
+
maintainUrl.value = false;
|
|
103
|
+
editSnapshot = null;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// Links open the versioned URL, so a file replaced at the same URL shows its new
|
|
109
|
+
// content; the text stays the real URL, the one worth copying.
|
|
110
|
+
const fileUrl = computed(() => (media.value ? mediaFileUrl(media.value) : ""));
|
|
111
|
+
|
|
112
|
+
const metaRows = computed<
|
|
113
|
+
{ label: string; value: string; isUrl: boolean; href?: string }[]
|
|
114
|
+
>(() => {
|
|
115
|
+
if (!media.value) return [];
|
|
116
|
+
const m = media.value;
|
|
117
|
+
return [
|
|
118
|
+
{
|
|
119
|
+
label: t("mapo.file"),
|
|
120
|
+
value: m.file?.split("/").pop() ?? "",
|
|
121
|
+
isUrl: false,
|
|
122
|
+
},
|
|
123
|
+
{ label: t("mapo.mime"), value: m.mime_type, isUrl: false },
|
|
124
|
+
{
|
|
125
|
+
label: t("mapo.size"),
|
|
126
|
+
value: m.size ? humanFileSize(m.size) : "—",
|
|
127
|
+
isUrl: false,
|
|
128
|
+
},
|
|
129
|
+
{ label: t("mapo.created"), value: formatDate(m.created), isUrl: false },
|
|
130
|
+
{ label: t("mapo.url"), value: m.file, isUrl: true, href: fileUrl.value },
|
|
131
|
+
];
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const editFields = computed(() => {
|
|
135
|
+
const lang = currentLang.value;
|
|
136
|
+
const prefix = lang ? `translations.${lang}.` : "";
|
|
137
|
+
return [
|
|
138
|
+
{ path: `${prefix}title`, label: t("mapo.title"), type: "text" },
|
|
139
|
+
{ path: `${prefix}alt_text`, label: t("mapo.altTag"), type: "text" },
|
|
140
|
+
{
|
|
141
|
+
path: `${prefix}description`,
|
|
142
|
+
label: t("mapo.description"),
|
|
143
|
+
type: "textarea",
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
function getFieldValue(path: string): string {
|
|
149
|
+
if (!media.value) return "";
|
|
150
|
+
return (
|
|
151
|
+
(getNestedValue(
|
|
152
|
+
media.value as unknown as Record<string, unknown>,
|
|
153
|
+
path,
|
|
154
|
+
) as string) ?? ""
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function setFieldValue(path: string, value: string) {
|
|
159
|
+
if (!media.value) return;
|
|
160
|
+
store.editMedia = setNestedValue(
|
|
161
|
+
media.value as unknown as Record<string, unknown>,
|
|
162
|
+
path,
|
|
163
|
+
value,
|
|
164
|
+
) as unknown as MediaItem;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function startEditing() {
|
|
168
|
+
editSnapshot = media.value ? deepClone(media.value) : null;
|
|
169
|
+
editing.value = true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function cancelEditing() {
|
|
173
|
+
if (editSnapshot) store.editMedia = editSnapshot;
|
|
174
|
+
editSnapshot = null;
|
|
175
|
+
editing.value = false;
|
|
176
|
+
newFile.value = null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Moving the media: it leaves the folder on screen, so the drawer closes.
|
|
180
|
+
const movePickerOpen = ref(false);
|
|
181
|
+
|
|
182
|
+
async function moveTo(folder: MediaFolder | null) {
|
|
183
|
+
if (!media.value) return;
|
|
184
|
+
const moved = await store.moveMedia([media.value.id], folder?.id ?? null);
|
|
185
|
+
if (moved.length) store.closeEditor();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Field labels for the error toast, keyed like the backend reports the fields.
|
|
189
|
+
const errorLabels = computed(() => ({
|
|
190
|
+
title: t("mapo.title"),
|
|
191
|
+
alt_text: t("mapo.altTag"),
|
|
192
|
+
description: t("mapo.description"),
|
|
193
|
+
file: t("mapo.file"),
|
|
194
|
+
}));
|
|
195
|
+
|
|
196
|
+
function notifySaveError(error: unknown) {
|
|
197
|
+
const lines = describeMediaErrors(getErrorData(error), errorLabels.value);
|
|
198
|
+
snack.show(lines.join("\n") || t("mapo.genericError"), "error");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function save() {
|
|
202
|
+
if (!media.value) return;
|
|
203
|
+
saving.value = true;
|
|
204
|
+
// Snapshot the edited metadata BEFORE replacing the file: replaceFile
|
|
205
|
+
// syncs editMedia with the server response, which would otherwise
|
|
206
|
+
// silently discard the user's unsaved title/alt/description edits.
|
|
207
|
+
const edited = { ...media.value };
|
|
208
|
+
try {
|
|
209
|
+
if (newFile.value) {
|
|
210
|
+
const replaced = await store.replaceFile(
|
|
211
|
+
edited.id,
|
|
212
|
+
newFile.value,
|
|
213
|
+
maintainUrl.value,
|
|
214
|
+
);
|
|
215
|
+
// The file is stored: a retry after a failed metadata save must not
|
|
216
|
+
// upload it again, and the form keeps the edits over the server copy.
|
|
217
|
+
newFile.value = null;
|
|
218
|
+
maintainUrl.value = false;
|
|
219
|
+
fileChangerKey.value++;
|
|
220
|
+
store.editMedia = { ...replaced, ...pickMetadata(edited) };
|
|
221
|
+
}
|
|
222
|
+
await store.updateMedia(edited, editSnapshot ?? undefined);
|
|
223
|
+
editSnapshot = null;
|
|
224
|
+
editing.value = false;
|
|
225
|
+
newFile.value = null;
|
|
226
|
+
maintainUrl.value = false;
|
|
227
|
+
} catch (error) {
|
|
228
|
+
// Stay in edit mode with the edits on screen, so they can be fixed.
|
|
229
|
+
notifySaveError(error);
|
|
230
|
+
} finally {
|
|
231
|
+
saving.value = false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function formatDate(dateStr: string): string {
|
|
236
|
+
if (!dateStr) return "—";
|
|
237
|
+
return new Date(dateStr).toLocaleDateString(undefined, {
|
|
238
|
+
day: "2-digit",
|
|
239
|
+
month: "short",
|
|
240
|
+
year: "numeric",
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
</script>
|
|
244
|
+
|
|
245
|
+
<template>
|
|
246
|
+
<USlideover
|
|
247
|
+
:open="!!media"
|
|
248
|
+
side="right"
|
|
249
|
+
class="mapo-media-editor"
|
|
250
|
+
:ui="{ content: 'max-w-md w-full' }"
|
|
251
|
+
@update:open="!$event && store.closeEditor()"
|
|
252
|
+
>
|
|
253
|
+
<!-- #content: the default slot is the trigger in Nuxt UI v4 -->
|
|
254
|
+
<template #content>
|
|
255
|
+
<div v-if="media" class="flex h-full flex-col">
|
|
256
|
+
<!-- Header -->
|
|
257
|
+
<div class="flex items-center gap-2 border-b border-default px-4 py-3">
|
|
258
|
+
<UButton
|
|
259
|
+
icon="i-lucide-x"
|
|
260
|
+
variant="ghost"
|
|
261
|
+
color="neutral"
|
|
262
|
+
size="xs"
|
|
263
|
+
@click="store.closeEditor()"
|
|
264
|
+
/>
|
|
265
|
+
<p class="flex-1 truncate text-sm font-semibold text-highlighted">
|
|
266
|
+
{{ media.title || media.file?.split("/").pop() }}
|
|
267
|
+
</p>
|
|
268
|
+
<UButton
|
|
269
|
+
v-if="!editing && canEdit"
|
|
270
|
+
icon="i-lucide-pencil"
|
|
271
|
+
size="xs"
|
|
272
|
+
variant="soft"
|
|
273
|
+
color="neutral"
|
|
274
|
+
@click="startEditing"
|
|
275
|
+
>
|
|
276
|
+
{{ t("mapo.edit") }}
|
|
277
|
+
</UButton>
|
|
278
|
+
<UButton
|
|
279
|
+
icon="i-lucide-external-link"
|
|
280
|
+
size="xs"
|
|
281
|
+
variant="ghost"
|
|
282
|
+
color="neutral"
|
|
283
|
+
:href="fileUrl"
|
|
284
|
+
target="_blank"
|
|
285
|
+
:title="t('mapo.mediaEditor.openInNewTab')"
|
|
286
|
+
/>
|
|
287
|
+
</div>
|
|
288
|
+
|
|
289
|
+
<div class="flex-1 overflow-y-auto">
|
|
290
|
+
<!-- Preview -->
|
|
291
|
+
<div class="flex justify-center bg-elevated p-4">
|
|
292
|
+
<MapoMediaPreview :media="media" size="lg" contain />
|
|
293
|
+
</div>
|
|
294
|
+
|
|
295
|
+
<!-- Metadata table -->
|
|
296
|
+
<div class="border-b border-default px-4 py-3">
|
|
297
|
+
<p
|
|
298
|
+
class="mb-2 text-xs font-semibold uppercase tracking-wide text-dimmed"
|
|
299
|
+
>
|
|
300
|
+
{{ t("mapo.mediaEditor.details") }}
|
|
301
|
+
</p>
|
|
302
|
+
<dl class="space-y-1">
|
|
303
|
+
<div
|
|
304
|
+
v-for="row in metaRows"
|
|
305
|
+
:key="row.label"
|
|
306
|
+
class="flex gap-2 text-xs"
|
|
307
|
+
>
|
|
308
|
+
<dt class="w-24 shrink-0 text-dimmed">
|
|
309
|
+
{{ row.label }}
|
|
310
|
+
</dt>
|
|
311
|
+
<dd class="flex-1 truncate font-mono text-default">
|
|
312
|
+
<a
|
|
313
|
+
v-if="row.isUrl"
|
|
314
|
+
:href="row.href ?? row.value"
|
|
315
|
+
target="_blank"
|
|
316
|
+
rel="noopener"
|
|
317
|
+
class="text-primary hover:underline"
|
|
318
|
+
>{{ row.value }}</a
|
|
319
|
+
>
|
|
320
|
+
<span v-else>{{ row.value }}</span>
|
|
321
|
+
</dd>
|
|
322
|
+
</div>
|
|
323
|
+
</dl>
|
|
324
|
+
|
|
325
|
+
<!-- Linked models (Camomilla `links`) -->
|
|
326
|
+
<div v-if="media.links?.length" class="mt-3">
|
|
327
|
+
<p
|
|
328
|
+
class="mb-1 text-xs font-semibold uppercase tracking-wide text-dimmed"
|
|
329
|
+
>
|
|
330
|
+
{{ t("mapo.linkedModels") }}
|
|
331
|
+
</p>
|
|
332
|
+
<ul class="space-y-0.5 text-xs text-muted">
|
|
333
|
+
<li
|
|
334
|
+
v-for="link in media.links"
|
|
335
|
+
:key="`${link.model}-${link.id}`"
|
|
336
|
+
>
|
|
337
|
+
<b>{{ link.model }} (id: {{ link.id }})</b> — {{ link.name }}
|
|
338
|
+
</li>
|
|
339
|
+
</ul>
|
|
340
|
+
</div>
|
|
341
|
+
</div>
|
|
342
|
+
|
|
343
|
+
<!-- Edit form (shown when editing) -->
|
|
344
|
+
<div v-if="editing" class="space-y-4 px-4 py-3">
|
|
345
|
+
<!-- Lang switch: the one MapoDetail and the menu manager use, so
|
|
346
|
+
an app that replaces it (MapoOverride) replaces it here too.
|
|
347
|
+
The drawer has no route of its own: the URL stays as it is. -->
|
|
348
|
+
<MapoDetailLangSwitch
|
|
349
|
+
v-if="activeLangs.length > 1"
|
|
350
|
+
v-model="currentLang"
|
|
351
|
+
:langs="activeLangs"
|
|
352
|
+
no-route-change
|
|
353
|
+
/>
|
|
354
|
+
|
|
355
|
+
<!-- Field inputs -->
|
|
356
|
+
<div class="space-y-3">
|
|
357
|
+
<UFormField
|
|
358
|
+
v-for="field in editFields"
|
|
359
|
+
:key="field.path"
|
|
360
|
+
:label="field.label"
|
|
361
|
+
size="sm"
|
|
362
|
+
>
|
|
363
|
+
<UTextarea
|
|
364
|
+
v-if="field.type === 'textarea'"
|
|
365
|
+
:model-value="getFieldValue(field.path)"
|
|
366
|
+
:rows="2"
|
|
367
|
+
class="w-full"
|
|
368
|
+
@update:model-value="setFieldValue(field.path, $event)"
|
|
369
|
+
/>
|
|
370
|
+
<UInput
|
|
371
|
+
v-else
|
|
372
|
+
:model-value="getFieldValue(field.path)"
|
|
373
|
+
class="w-full"
|
|
374
|
+
@update:model-value="setFieldValue(field.path, $event)"
|
|
375
|
+
/>
|
|
376
|
+
</UFormField>
|
|
377
|
+
</div>
|
|
378
|
+
|
|
379
|
+
<!-- File replace -->
|
|
380
|
+
<MapoMediaFileChanger
|
|
381
|
+
:key="fileChangerKey"
|
|
382
|
+
:media="media"
|
|
383
|
+
@update:file="newFile = $event"
|
|
384
|
+
@update:maintain-url="maintainUrl = $event"
|
|
385
|
+
/>
|
|
386
|
+
</div>
|
|
387
|
+
</div>
|
|
388
|
+
|
|
389
|
+
<!-- Destination picker for "Move to": teleported, mounted when open -->
|
|
390
|
+
<MapoMediaFolderPicker
|
|
391
|
+
v-model:open="movePickerOpen"
|
|
392
|
+
@confirm="moveTo"
|
|
393
|
+
/>
|
|
394
|
+
|
|
395
|
+
<!-- Footer -->
|
|
396
|
+
<div
|
|
397
|
+
class="flex items-center justify-between gap-2 border-t border-default px-4 py-3"
|
|
398
|
+
>
|
|
399
|
+
<div class="flex gap-2">
|
|
400
|
+
<UButton
|
|
401
|
+
v-if="canRemove"
|
|
402
|
+
icon="i-lucide-trash-2"
|
|
403
|
+
size="sm"
|
|
404
|
+
variant="soft"
|
|
405
|
+
color="error"
|
|
406
|
+
@click="store.deleteMedia(media)"
|
|
407
|
+
>
|
|
408
|
+
{{ t("mapo.delete") }}
|
|
409
|
+
</UButton>
|
|
410
|
+
<UButton
|
|
411
|
+
v-if="canEdit && !editing"
|
|
412
|
+
icon="i-lucide-folder-input"
|
|
413
|
+
size="sm"
|
|
414
|
+
variant="soft"
|
|
415
|
+
color="neutral"
|
|
416
|
+
@click="movePickerOpen = true"
|
|
417
|
+
>
|
|
418
|
+
{{ t("mapo.mediaMove.moveTo") }}
|
|
419
|
+
</UButton>
|
|
420
|
+
</div>
|
|
421
|
+
|
|
422
|
+
<div class="flex gap-2">
|
|
423
|
+
<UButton
|
|
424
|
+
v-if="editing"
|
|
425
|
+
size="sm"
|
|
426
|
+
variant="ghost"
|
|
427
|
+
color="neutral"
|
|
428
|
+
@click="cancelEditing"
|
|
429
|
+
>
|
|
430
|
+
{{ t("mapo.cancel") }}
|
|
431
|
+
</UButton>
|
|
432
|
+
<UButton
|
|
433
|
+
v-if="editing"
|
|
434
|
+
size="sm"
|
|
435
|
+
color="primary"
|
|
436
|
+
:loading="saving"
|
|
437
|
+
icon="i-lucide-save"
|
|
438
|
+
@click="save"
|
|
439
|
+
>
|
|
440
|
+
{{ t("mapo.save") }}
|
|
441
|
+
</UButton>
|
|
442
|
+
</div>
|
|
443
|
+
</div>
|
|
444
|
+
</div>
|
|
445
|
+
</template>
|
|
446
|
+
</USlideover>
|
|
447
|
+
</template>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, onUnmounted } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import { humanFileSize } from "@mapomodule/utils";
|
|
5
|
+
import type { MediaItem } from "../types/media.js";
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n();
|
|
8
|
+
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
media: MediaItem;
|
|
11
|
+
accept?: string;
|
|
12
|
+
}>();
|
|
13
|
+
|
|
14
|
+
const emit = defineEmits<{
|
|
15
|
+
"update:file": [file: File | null];
|
|
16
|
+
"update:maintainUrl": [value: boolean];
|
|
17
|
+
}>();
|
|
18
|
+
|
|
19
|
+
const newFile = ref<File | null>(null);
|
|
20
|
+
const maintainUrl = ref(false);
|
|
21
|
+
const previewUrl = ref<string | null>(null);
|
|
22
|
+
|
|
23
|
+
const isImage = computed(() =>
|
|
24
|
+
newFile.value
|
|
25
|
+
? newFile.value.type.startsWith("image/")
|
|
26
|
+
: props.media.mime_type?.startsWith("image/"),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Accept the whole mime family of the current file (legacy parity): a JPEG
|
|
30
|
+
// can be replaced with any image, not only another JPEG.
|
|
31
|
+
const acceptTypes = computed(() => {
|
|
32
|
+
if (props.accept) return props.accept;
|
|
33
|
+
const family = props.media.mime_type?.split("/")[0];
|
|
34
|
+
return family && ["image", "video", "audio"].includes(family)
|
|
35
|
+
? `${family}/*`
|
|
36
|
+
: "*/*";
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function revokePreview() {
|
|
40
|
+
if (previewUrl.value) URL.revokeObjectURL(previewUrl.value);
|
|
41
|
+
previewUrl.value = null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function onFileSelected(files: File[]) {
|
|
45
|
+
const file = files[0] ?? null;
|
|
46
|
+
newFile.value = file;
|
|
47
|
+
emit("update:file", file);
|
|
48
|
+
revokePreview();
|
|
49
|
+
if (file && file.type.startsWith("image/")) {
|
|
50
|
+
previewUrl.value = URL.createObjectURL(file);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function clearFile() {
|
|
55
|
+
newFile.value = null;
|
|
56
|
+
revokePreview();
|
|
57
|
+
emit("update:file", null);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
onUnmounted(revokePreview);
|
|
61
|
+
|
|
62
|
+
// UCheckbox emits `boolean | "indeterminate"`; this checkbox is binary.
|
|
63
|
+
function onMaintainUrlChange(v: boolean | "indeterminate") {
|
|
64
|
+
const checked = v === true;
|
|
65
|
+
maintainUrl.value = checked;
|
|
66
|
+
emit("update:maintainUrl", checked);
|
|
67
|
+
}
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<template>
|
|
71
|
+
<div class="mapo-media-file-changer space-y-2">
|
|
72
|
+
<p class="text-xs font-medium text-muted">
|
|
73
|
+
{{ t("mapo.mediaFileChanger.replaceFile") }}
|
|
74
|
+
</p>
|
|
75
|
+
|
|
76
|
+
<MapoDropArea
|
|
77
|
+
:accept="acceptTypes"
|
|
78
|
+
:multiple="false"
|
|
79
|
+
@files="onFileSelected"
|
|
80
|
+
>
|
|
81
|
+
<template #default="{ triggerPick, isDragging }">
|
|
82
|
+
<div
|
|
83
|
+
class="flex cursor-pointer items-center gap-3 rounded-lg border border-dashed p-3 transition-colors"
|
|
84
|
+
:class="
|
|
85
|
+
isDragging
|
|
86
|
+
? 'border-primary bg-primary/10'
|
|
87
|
+
: 'border-default hover:border-accented'
|
|
88
|
+
"
|
|
89
|
+
@click="triggerPick"
|
|
90
|
+
>
|
|
91
|
+
<!-- New file preview -->
|
|
92
|
+
<div v-if="newFile" class="flex items-center gap-2 flex-1">
|
|
93
|
+
<img
|
|
94
|
+
v-if="isImage && previewUrl"
|
|
95
|
+
:src="previewUrl"
|
|
96
|
+
class="size-12 rounded object-cover"
|
|
97
|
+
alt=""
|
|
98
|
+
/>
|
|
99
|
+
<UIcon v-else name="i-lucide-file" class="size-8 text-dimmed" />
|
|
100
|
+
<div class="flex-1 min-w-0">
|
|
101
|
+
<p class="truncate text-xs font-medium">
|
|
102
|
+
{{ newFile.name }}
|
|
103
|
+
</p>
|
|
104
|
+
<p class="text-xs text-dimmed">
|
|
105
|
+
{{ humanFileSize(newFile.size) }}
|
|
106
|
+
</p>
|
|
107
|
+
</div>
|
|
108
|
+
<UButton
|
|
109
|
+
icon="i-lucide-x"
|
|
110
|
+
size="xs"
|
|
111
|
+
variant="ghost"
|
|
112
|
+
color="neutral"
|
|
113
|
+
@click.stop="clearFile"
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<!-- Placeholder -->
|
|
118
|
+
<div
|
|
119
|
+
v-else
|
|
120
|
+
class="flex flex-1 items-center gap-2 text-sm text-dimmed"
|
|
121
|
+
>
|
|
122
|
+
<UIcon name="i-lucide-upload" class="size-5" />
|
|
123
|
+
<span>{{ t("mapo.mediaFileChanger.dragOrClick") }}</span>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</template>
|
|
127
|
+
</MapoDropArea>
|
|
128
|
+
|
|
129
|
+
<UCheckbox
|
|
130
|
+
v-if="newFile"
|
|
131
|
+
:model-value="maintainUrl"
|
|
132
|
+
:label="t('mapo.mediaFileChanger.keepUrl')"
|
|
133
|
+
@update:model-value="onMaintainUrlChange"
|
|
134
|
+
/>
|
|
135
|
+
</div>
|
|
136
|
+
</template>
|