@mapomodule/uikit 2.0.0-beta.1 → 2.0.0-beta.11

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.
Files changed (200) hide show
  1. package/README.md +33 -1
  2. package/dist/__tests__/langInfo.test.d.ts +2 -0
  3. package/dist/__tests__/langInfo.test.d.ts.map +1 -0
  4. package/dist/index.d.mts +5 -2
  5. package/dist/index.d.ts +6 -2
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.mjs +1 -18
  8. package/dist/module.d.mts +60 -2
  9. package/dist/module.d.ts +55 -2
  10. package/dist/module.d.ts.map +1 -0
  11. package/dist/module.json +1 -1
  12. package/dist/module.mjs +174 -13
  13. package/dist/runtime/adapters/defaultMediaAdapter.d.ts +14 -0
  14. package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
  15. package/dist/runtime/adapters/defaultMediaAdapter.js +30 -0
  16. package/dist/runtime/assets/main.css +1 -0
  17. package/dist/runtime/components/MapoConfirmDialog.vue +35 -0
  18. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts +4 -0
  19. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -0
  20. package/dist/runtime/components/MapoDetail.vue +632 -0
  21. package/dist/runtime/components/MapoDetail.vue.d.ts +422 -0
  22. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -0
  23. package/dist/runtime/components/MapoDetailLangSwitch.vue +126 -0
  24. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +23 -0
  25. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -0
  26. package/dist/runtime/components/MapoDropArea.vue +99 -0
  27. package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
  28. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
  29. package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
  30. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
  31. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
  32. package/dist/runtime/components/MapoList.vue +191 -0
  33. package/dist/runtime/components/MapoList.vue.d.ts +111 -0
  34. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -0
  35. package/dist/runtime/components/MapoListActions.vue +119 -0
  36. package/dist/runtime/components/MapoListActions.vue.d.ts +33 -0
  37. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -0
  38. package/dist/runtime/components/MapoListFilters.vue +246 -0
  39. package/dist/runtime/components/MapoListFilters.vue.d.ts +38 -0
  40. package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -0
  41. package/dist/runtime/components/MapoListHead.vue +9 -0
  42. package/dist/runtime/components/MapoListHead.vue.d.ts +14 -0
  43. package/dist/runtime/components/MapoListHead.vue.d.ts.map +1 -0
  44. package/dist/runtime/components/MapoListQuickEdit.vue +123 -0
  45. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts +47 -0
  46. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -0
  47. package/dist/runtime/components/MapoListTable.vue +665 -0
  48. package/dist/runtime/components/MapoListTable.vue.d.ts +105 -0
  49. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -0
  50. package/dist/runtime/components/MapoListTabs.vue +38 -0
  51. package/dist/runtime/components/MapoListTabs.vue.d.ts +26 -0
  52. package/dist/runtime/components/MapoListTabs.vue.d.ts.map +1 -0
  53. package/dist/runtime/components/MapoLogin.vue +196 -0
  54. package/dist/runtime/components/MapoLogin.vue.d.ts +22 -0
  55. package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -0
  56. package/dist/runtime/components/MapoLogoutButton.vue +27 -0
  57. package/dist/runtime/components/MapoLogoutButton.vue.d.ts +29 -0
  58. package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -0
  59. package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
  60. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
  61. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
  62. package/dist/runtime/components/MapoMediaEditor.vue +320 -0
  63. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +8 -0
  64. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
  65. package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
  66. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
  67. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
  68. package/dist/runtime/components/MapoMediaFolders.vue +220 -0
  69. package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
  70. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
  71. package/dist/runtime/components/MapoMediaGallery.vue +219 -0
  72. package/dist/runtime/components/MapoMediaGallery.vue.d.ts +4 -0
  73. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
  74. package/dist/runtime/components/MapoMediaManager.vue +140 -0
  75. package/dist/runtime/components/MapoMediaManager.vue.d.ts +35 -0
  76. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
  77. package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
  78. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
  79. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
  80. package/dist/runtime/components/MapoMediaPreview.vue +92 -0
  81. package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
  82. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
  83. package/dist/runtime/components/MapoMediaUploader.vue +290 -0
  84. package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
  85. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
  86. package/dist/runtime/components/MapoMenuManager.vue +293 -0
  87. package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
  88. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
  89. package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
  90. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
  91. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
  92. package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
  93. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
  94. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
  95. package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
  96. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
  97. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
  98. package/dist/runtime/components/MapoRootComponents.vue +9 -0
  99. package/dist/runtime/components/MapoRootComponents.vue.d.ts +4 -0
  100. package/dist/runtime/components/MapoRootComponents.vue.d.ts.map +1 -0
  101. package/dist/runtime/components/MapoSidebar.vue +89 -0
  102. package/dist/runtime/components/MapoSidebar.vue.d.ts +22 -0
  103. package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -0
  104. package/dist/runtime/components/MapoSidebarList.vue +27 -0
  105. package/dist/runtime/components/MapoSidebarList.vue.d.ts +8 -0
  106. package/dist/runtime/components/MapoSidebarList.vue.d.ts.map +1 -0
  107. package/dist/runtime/components/MapoSidebarListItem.vue +74 -0
  108. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts +9 -0
  109. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts.map +1 -0
  110. package/dist/runtime/components/MapoSidebarProfile.vue +55 -0
  111. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts +10 -0
  112. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -0
  113. package/dist/runtime/components/MapoSnackBar.vue +38 -0
  114. package/dist/runtime/components/MapoSnackBar.vue.d.ts +4 -0
  115. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -0
  116. package/dist/runtime/components/MapoThemeToggle.vue +23 -0
  117. package/dist/runtime/components/MapoThemeToggle.vue.d.ts +4 -0
  118. package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -0
  119. package/dist/runtime/components/MapoTopbar.vue +30 -0
  120. package/dist/runtime/components/MapoTopbar.vue.d.ts +15 -0
  121. package/dist/runtime/components/MapoTopbar.vue.d.ts.map +1 -0
  122. package/dist/runtime/components/menuDndContext.d.ts +19 -0
  123. package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
  124. package/dist/runtime/components/menuDndContext.js +3 -0
  125. package/dist/runtime/layouts/default.vue +43 -0
  126. package/dist/runtime/layouts/default.vue.d.ts +20 -0
  127. package/dist/runtime/layouts/default.vue.d.ts.map +1 -0
  128. package/dist/runtime/layouts/empty.vue +9 -0
  129. package/dist/runtime/layouts/empty.vue.d.ts +14 -0
  130. package/dist/runtime/layouts/empty.vue.d.ts.map +1 -0
  131. package/dist/runtime/page-meta.nuxt.d.ts +45 -0
  132. package/dist/runtime/pages/index.vue +14 -0
  133. package/dist/runtime/pages/index.vue.d.ts +4 -0
  134. package/dist/runtime/pages/index.vue.d.ts.map +1 -0
  135. package/dist/runtime/pages/login.vue +3 -0
  136. package/dist/runtime/pages/login.vue.d.ts +4 -0
  137. package/dist/runtime/pages/login.vue.d.ts.map +1 -0
  138. package/dist/runtime/plugins/media-adapter.d.ts +18 -0
  139. package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
  140. package/dist/runtime/plugins/media-adapter.js +8 -0
  141. package/dist/runtime/stores/media.d.ts +462 -0
  142. package/dist/runtime/stores/media.d.ts.map +1 -0
  143. package/dist/runtime/stores/media.js +344 -0
  144. package/dist/runtime/types/list.d.ts +59 -0
  145. package/dist/runtime/types/list.d.ts.map +1 -0
  146. package/dist/runtime/types/list.js +0 -0
  147. package/dist/runtime/types/media.d.ts +116 -0
  148. package/dist/runtime/types/media.d.ts.map +1 -0
  149. package/dist/runtime/types/media.js +0 -0
  150. package/dist/runtime/types/menu.d.ts +66 -0
  151. package/dist/runtime/types/menu.d.ts.map +1 -0
  152. package/dist/runtime/types/menu.js +30 -0
  153. package/dist/runtime/utils/langInfo.d.ts +30 -0
  154. package/dist/runtime/utils/langInfo.d.ts.map +1 -0
  155. package/dist/runtime/utils/langInfo.js +8 -0
  156. package/dist/types.d.mts +6 -10
  157. package/package.json +15 -11
  158. package/src/__tests__/langInfo.test.ts +48 -0
  159. package/src/index.ts +20 -0
  160. package/src/module.ts +130 -0
  161. package/src/runtime/adapters/defaultMediaAdapter.ts +57 -0
  162. package/src/runtime/components/MapoConfirmDialog.vue +5 -3
  163. package/src/runtime/components/MapoDetail.vue +130 -55
  164. package/src/runtime/components/MapoDetailLangSwitch.vue +1 -1
  165. package/src/runtime/components/MapoDropArea.vue +127 -0
  166. package/src/runtime/components/MapoLangSwitcher.vue +74 -0
  167. package/src/runtime/components/MapoList.vue +1 -1
  168. package/src/runtime/components/MapoListActions.vue +16 -10
  169. package/src/runtime/components/MapoListFilters.vue +5 -2
  170. package/src/runtime/components/MapoListQuickEdit.vue +12 -9
  171. package/src/runtime/components/MapoListTable.vue +26 -21
  172. package/src/runtime/components/MapoLogin.vue +13 -10
  173. package/src/runtime/components/MapoLogoutButton.vue +4 -2
  174. package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
  175. package/src/runtime/components/MapoMediaEditor.vue +350 -0
  176. package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
  177. package/src/runtime/components/MapoMediaFolders.vue +239 -0
  178. package/src/runtime/components/MapoMediaGallery.vue +239 -0
  179. package/src/runtime/components/MapoMediaManager.vue +180 -0
  180. package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
  181. package/src/runtime/components/MapoMediaPreview.vue +111 -0
  182. package/src/runtime/components/MapoMediaUploader.vue +351 -0
  183. package/src/runtime/components/MapoMenuManager.vue +437 -0
  184. package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
  185. package/src/runtime/components/MapoMenuTreeview.vue +264 -0
  186. package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
  187. package/src/runtime/components/MapoSidebar.vue +3 -1
  188. package/src/runtime/components/MapoSidebarList.vue +1 -1
  189. package/src/runtime/components/MapoSidebarProfile.vue +6 -2
  190. package/src/runtime/components/MapoThemeToggle.vue +5 -1
  191. package/src/runtime/components/menuDndContext.ts +22 -0
  192. package/src/runtime/pages/index.vue +4 -3
  193. package/src/runtime/pages/login.vue +0 -4
  194. package/src/runtime/plugins/media-adapter.ts +33 -0
  195. package/src/runtime/stores/media.ts +474 -0
  196. package/src/runtime/types/media.ts +126 -0
  197. package/src/runtime/types/menu.ts +105 -0
  198. package/src/runtime/utils/langInfo.ts +38 -0
  199. package/dist/index.d.cts +0 -2
  200. package/dist/module.d.cts +0 -2
@@ -0,0 +1,148 @@
1
+ <script setup lang="ts">
2
+ import { ref, watch, computed } from "vue";
3
+ import { useI18n } from "vue-i18n";
4
+ import { useMediaStore } from "../stores/media.js";
5
+ import type { MediaItem, SelectMode } from "../types/media.js";
6
+
7
+ const props = withDefaults(
8
+ defineProps<{
9
+ modelValue?: boolean;
10
+ selectionMode?: Exclude<SelectMode, "none">;
11
+ mime?: string | null;
12
+ noFolders?: boolean;
13
+ languages?: string[];
14
+ defaultLang?: string;
15
+ /** Current value of the host field — pre-seeds the picker selection. */
16
+ selected?: MediaItem | MediaItem[] | null;
17
+ }>(),
18
+ {
19
+ modelValue: false,
20
+ selectionMode: "single",
21
+ mime: null,
22
+ noFolders: false,
23
+ languages: undefined,
24
+ defaultLang: undefined,
25
+ selected: null,
26
+ },
27
+ );
28
+
29
+ const emit = defineEmits<{
30
+ "update:modelValue": [value: boolean];
31
+ /** Emitted when the user confirms their selection */
32
+ confirm: [value: MediaItem | MediaItem[]];
33
+ }>();
34
+
35
+ const { t } = useI18n();
36
+ const store = useMediaStore();
37
+ const open = ref(props.modelValue);
38
+
39
+ watch(
40
+ () => props.modelValue,
41
+ (v) => (open.value = v),
42
+ );
43
+
44
+ watch(open, (v) => emit("update:modelValue", v));
45
+
46
+ const hasSelection = computed(() => {
47
+ if (props.selectionMode === "single") return !!store.selection;
48
+ return Array.isArray(store.selection) && store.selection.length > 0;
49
+ });
50
+
51
+ const selectionCount = computed(() => {
52
+ if (props.selectionMode === "multi" && Array.isArray(store.selection)) {
53
+ return store.selection.length;
54
+ }
55
+ return 0;
56
+ });
57
+
58
+ function confirm() {
59
+ if (!store.selection) return;
60
+ emit("confirm", store.selection as MediaItem | MediaItem[]);
61
+ open.value = false;
62
+ }
63
+
64
+ function cancel() {
65
+ open.value = false;
66
+ }
67
+
68
+ // Legacy parity: in single mode the first pick confirms and closes right away.
69
+ // Guarded against the pre-seeded selection so reopening the dialog with a
70
+ // current value doesn't auto-close it.
71
+ watch(
72
+ () => store.selection,
73
+ (sel) => {
74
+ if (!open.value || props.selectionMode !== "single") return;
75
+ if (Array.isArray(sel) || !sel) return;
76
+ const initial = props.selected as MediaItem | null;
77
+ if (sel.id !== initial?.id) confirm();
78
+ },
79
+ );
80
+ </script>
81
+
82
+ <template>
83
+ <!-- Activator slot: the caller provides the trigger button -->
84
+ <slot name="activator" :open="() => (open = true)" />
85
+
86
+ <UModal v-model:open="open" :ui="{ content: 'max-w-5xl w-full h-[80vh]' }">
87
+ <!-- #content gives full control: the default slot is the trigger in Nuxt UI v4 -->
88
+ <template #content>
89
+ <div class="flex h-full flex-col">
90
+ <!-- Header -->
91
+ <div class="flex items-center gap-2 border-b border-default px-4 py-3">
92
+ <UIcon name="i-lucide-image" class="size-4 text-dimmed" />
93
+ <span class="flex-1 font-semibold text-highlighted">
94
+ {{
95
+ selectionMode === "multi"
96
+ ? t("mapo.mediaManager.selectMedia")
97
+ : t("mapo.mediaManager.selectAMedia")
98
+ }}
99
+ </span>
100
+ <UButton
101
+ icon="i-lucide-x"
102
+ size="xs"
103
+ variant="ghost"
104
+ color="neutral"
105
+ @click="cancel"
106
+ />
107
+ </div>
108
+
109
+ <!-- Body: media manager fills remaining space -->
110
+ <div class="min-h-0 flex-1">
111
+ <MapoMediaManager
112
+ :selection-mode="selectionMode"
113
+ :mime="mime"
114
+ :no-folders="noFolders"
115
+ :languages="languages"
116
+ :default-lang="defaultLang"
117
+ :initial-selection="selected"
118
+ />
119
+ </div>
120
+
121
+ <!-- Footer -->
122
+ <div
123
+ class="flex items-center justify-between gap-2 border-t border-default px-4 py-3"
124
+ >
125
+ <p
126
+ v-if="selectionMode === 'multi' && selectionCount > 0"
127
+ class="text-sm text-muted"
128
+ >
129
+ {{ t("mapo.mediaGallery.nSelected", { number: selectionCount }) }}
130
+ </p>
131
+ <div class="ml-auto flex gap-2">
132
+ <UButton variant="ghost" color="neutral" @click="cancel">
133
+ {{ t("mapo.cancel") }}
134
+ </UButton>
135
+ <UButton
136
+ color="primary"
137
+ :disabled="!hasSelection"
138
+ icon="i-lucide-check"
139
+ @click="confirm"
140
+ >
141
+ {{ t("mapo.confirm") }}
142
+ </UButton>
143
+ </div>
144
+ </div>
145
+ </div>
146
+ </template>
147
+ </UModal>
148
+ </template>
@@ -0,0 +1,111 @@
1
+ <script setup lang="ts">
2
+ import { computed } from "vue";
3
+ import type { MediaItem } from "../types/media.js";
4
+
5
+ const props = withDefaults(
6
+ defineProps<{
7
+ media: MediaItem;
8
+ size?: "xs" | "sm" | "md" | "lg";
9
+ contain?: boolean;
10
+ showFilename?: boolean;
11
+ videoControls?: boolean;
12
+ videoAutoplay?: boolean;
13
+ }>(),
14
+ {
15
+ size: "md",
16
+ contain: false,
17
+ showFilename: false,
18
+ videoControls: false,
19
+ videoAutoplay: false,
20
+ },
21
+ );
22
+
23
+ const isImage = computed(() => props.media.mime_type?.startsWith("image/"));
24
+ const isVideo = computed(() => props.media.mime_type?.startsWith("video/"));
25
+ const isAudio = computed(() => props.media.mime_type?.startsWith("audio/"));
26
+ const isPdf = computed(() => props.media.mime_type === "application/pdf");
27
+
28
+ const sizeClass = computed(() => {
29
+ const map: Record<string, string> = {
30
+ xs: "size-10",
31
+ sm: "size-16",
32
+ md: "size-24",
33
+ lg: "size-40",
34
+ };
35
+ return map[props.size];
36
+ });
37
+
38
+ const iconName = computed(() => {
39
+ if (isVideo.value) return "i-lucide-film";
40
+ if (isAudio.value) return "i-lucide-music";
41
+ if (isPdf.value) return "i-lucide-file-text";
42
+ return "i-lucide-file";
43
+ });
44
+
45
+ const displayName = computed(
46
+ () =>
47
+ props.media.title ||
48
+ props.media.name ||
49
+ props.media.file?.split("/").pop() ||
50
+ "",
51
+ );
52
+ </script>
53
+
54
+ <template>
55
+ <div class="mapo-media-preview flex flex-col items-center gap-1">
56
+ <div
57
+ class="overflow-hidden rounded bg-elevated flex items-center justify-center"
58
+ :class="sizeClass"
59
+ >
60
+ <!-- Image -->
61
+ <img
62
+ v-if="isImage"
63
+ :src="media.file"
64
+ :alt="media.alt_text || displayName"
65
+ class="size-full"
66
+ :class="contain ? 'object-contain' : 'object-cover'"
67
+ loading="lazy"
68
+ decoding="async"
69
+ />
70
+
71
+ <!-- Video -->
72
+ <video
73
+ v-else-if="isVideo"
74
+ :src="media.file"
75
+ class="size-full object-cover"
76
+ :controls="videoControls"
77
+ :autoplay="videoAutoplay"
78
+ muted
79
+ playsinline
80
+ />
81
+
82
+ <!-- Audio -->
83
+ <div
84
+ v-else-if="isAudio"
85
+ class="flex flex-col items-center gap-1 p-2 text-center"
86
+ >
87
+ <UIcon :name="iconName" class="size-8 text-dimmed" />
88
+ <audio v-if="videoControls" :src="media.file" controls class="w-full" />
89
+ </div>
90
+
91
+ <!-- Generic file icon -->
92
+ <div v-else class="flex flex-col items-center gap-1 p-2 text-center">
93
+ <UIcon :name="iconName" class="size-8 text-dimmed" />
94
+ <span
95
+ v-if="size !== 'xs'"
96
+ class="line-clamp-2 break-all text-[10px] text-muted"
97
+ >
98
+ {{ media.mime_type }}
99
+ </span>
100
+ </div>
101
+ </div>
102
+
103
+ <span
104
+ v-if="showFilename"
105
+ class="max-w-full truncate text-center text-xs text-muted"
106
+ :title="displayName"
107
+ >
108
+ {{ displayName }}
109
+ </span>
110
+ </div>
111
+ </template>
@@ -0,0 +1,351 @@
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 { useMediaStore } from "../stores/media.js";
6
+ import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
7
+ import { useRuntimeConfig } from "#app";
8
+ import type { MediaUploadPayload } from "../types/media.js";
9
+
10
+ // USelect items cannot carry `null` values, so the library root uses a sentinel.
11
+ const ROOT_FOLDER = -1;
12
+
13
+ interface UploadEntry {
14
+ file: File;
15
+ title: string;
16
+ alt_text: string;
17
+ description: string;
18
+ folder: number;
19
+ progress: number;
20
+ status: "pending" | "uploading" | "done" | "error";
21
+ error?: string;
22
+ previewUrl?: string;
23
+ }
24
+
25
+ const emit = defineEmits<{
26
+ /** Emitted after at least one file uploaded successfully (legacy parity: the manager switches back to the gallery). */
27
+ uploaded: [];
28
+ }>();
29
+
30
+ const { t } = useI18n();
31
+ const store = useMediaStore();
32
+ const snack = useSnackStore();
33
+
34
+ // Configurable size limits via runtimeConfig.public.mapoMedia
35
+ const config = useRuntimeConfig();
36
+ const mediaConfig = (config.public.mapoMedia ?? {}) as {
37
+ maxImageSize?: number;
38
+ maxVideoSize?: number;
39
+ maxDefaultSize?: number;
40
+ };
41
+ const MAX_IMAGE = (mediaConfig.maxImageSize ?? 10) * 1024 * 1024;
42
+ const MAX_VIDEO = (mediaConfig.maxVideoSize ?? 100) * 1024 * 1024;
43
+ const MAX_DEFAULT = (mediaConfig.maxDefaultSize ?? 10) * 1024 * 1024;
44
+
45
+ const entries = ref<UploadEntry[]>([]);
46
+ const uploading = ref(false);
47
+
48
+ const canUpload = computed(
49
+ () =>
50
+ entries.value.length > 0 &&
51
+ entries.value.some((e) => e.status === "pending"),
52
+ );
53
+
54
+ const pendingCount = computed(
55
+ () => entries.value.filter((e) => e.status === "pending").length,
56
+ );
57
+
58
+ // Destination options: the current folder plus its subfolders (legacy parity).
59
+ const folderOptions = computed(() => [
60
+ {
61
+ label: store.parentFolder?.path ?? "/",
62
+ value: store.parentFolder?.id ?? ROOT_FOLDER,
63
+ },
64
+ ...store.folders.map((f) => ({ label: f.path ?? f.name, value: f.id })),
65
+ ]);
66
+
67
+ function onFiles(files: File[]) {
68
+ for (const file of files) {
69
+ const limit = file.type.startsWith("image/")
70
+ ? MAX_IMAGE
71
+ : file.type.startsWith("video/")
72
+ ? MAX_VIDEO
73
+ : MAX_DEFAULT;
74
+
75
+ if (file.size > limit) {
76
+ snack.show(
77
+ t("mapo.mediaUploader.fileTooLarge", {
78
+ name: file.name,
79
+ max: (limit / (1024 * 1024)).toFixed(0),
80
+ }),
81
+ "error",
82
+ );
83
+ continue;
84
+ }
85
+
86
+ const previewUrl = file.type.startsWith("image/")
87
+ ? URL.createObjectURL(file)
88
+ : undefined;
89
+
90
+ const baseName = file.name.replace(/\.[^.]+$/, "");
91
+ entries.value.push({
92
+ file,
93
+ title: baseName,
94
+ alt_text: baseName,
95
+ description: "",
96
+ folder: store.parentFolder?.id ?? ROOT_FOLDER,
97
+ progress: 0,
98
+ status: "pending",
99
+ previewUrl,
100
+ });
101
+ }
102
+ }
103
+
104
+ function remove(index: number) {
105
+ const entry = entries.value[index];
106
+ if (entry?.previewUrl) URL.revokeObjectURL(entry.previewUrl);
107
+ entries.value.splice(index, 1);
108
+ }
109
+
110
+ async function upload() {
111
+ uploading.value = true;
112
+ let successCount = 0;
113
+
114
+ for (const entry of entries.value) {
115
+ if (entry.status !== "pending") continue;
116
+ entry.status = "uploading";
117
+ entry.progress = 0;
118
+
119
+ const payload: MediaUploadPayload = {
120
+ file: entry.file,
121
+ title: entry.title || undefined,
122
+ alt_text: entry.alt_text || undefined,
123
+ description: entry.description || undefined,
124
+ folder: entry.folder === ROOT_FOLDER ? null : entry.folder,
125
+ };
126
+
127
+ try {
128
+ await store.uploadMedia(payload, (pct) => {
129
+ entry.progress = pct;
130
+ });
131
+ entry.status = "done";
132
+ entry.progress = 100;
133
+ successCount++;
134
+ } catch (err) {
135
+ entry.status = "error";
136
+ entry.error =
137
+ err instanceof Error
138
+ ? err.message
139
+ : t("mapo.mediaUploader.uploadFailed");
140
+ }
141
+ }
142
+
143
+ uploading.value = false;
144
+
145
+ if (successCount > 0) {
146
+ snack.show(
147
+ t("mapo.mediaUploader.success", { numberFiles: successCount }),
148
+ "success",
149
+ );
150
+ await store.getRoot({ page: 1 });
151
+ // Clean up completed entries
152
+ entries.value = entries.value.filter((e) => e.status !== "done");
153
+ emit("uploaded");
154
+ }
155
+ }
156
+
157
+ function clearAll() {
158
+ entries.value.forEach((e) => {
159
+ if (e.previewUrl) URL.revokeObjectURL(e.previewUrl);
160
+ });
161
+ entries.value = [];
162
+ }
163
+
164
+ onUnmounted(clearAll);
165
+ </script>
166
+
167
+ <template>
168
+ <div class="mapo-media-uploader space-y-4">
169
+ <!-- Drop zone -->
170
+ <MapoDropArea accept="*/*" multiple :disabled="uploading" @files="onFiles">
171
+ <template #default="{ triggerPick, isDragging }">
172
+ <div
173
+ class="flex min-h-32 cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-6 transition-colors"
174
+ :class="
175
+ isDragging
176
+ ? 'border-primary bg-primary/10'
177
+ : 'border-default hover:border-accented'
178
+ "
179
+ @click="triggerPick"
180
+ >
181
+ <UIcon name="i-lucide-upload-cloud" class="size-10 text-dimmed" />
182
+ <div class="text-center">
183
+ <p class="text-sm font-medium text-muted">
184
+ {{ t("mapo.mediaUploader.dragHere") }}
185
+ <span class="text-primary">{{
186
+ t("mapo.mediaUploader.browse")
187
+ }}</span>
188
+ </p>
189
+ <p class="mt-0.5 text-xs text-dimmed">
190
+ {{
191
+ t("mapo.mediaUploader.limits", {
192
+ img: (MAX_IMAGE / (1024 * 1024)).toFixed(0),
193
+ vid: (MAX_VIDEO / (1024 * 1024)).toFixed(0),
194
+ })
195
+ }}
196
+ </p>
197
+ </div>
198
+ </div>
199
+ </template>
200
+ </MapoDropArea>
201
+
202
+ <!-- File list -->
203
+ <div v-if="entries.length > 0" class="space-y-2">
204
+ <div class="flex items-center justify-between">
205
+ <p class="text-xs font-medium text-muted">
206
+ {{
207
+ t(
208
+ "mapo.mediaUploader.nSelected",
209
+ { n: entries.length },
210
+ entries.length,
211
+ )
212
+ }}
213
+ </p>
214
+ <UButton
215
+ v-if="!uploading"
216
+ size="xs"
217
+ variant="ghost"
218
+ color="neutral"
219
+ icon="i-lucide-x"
220
+ @click="clearAll"
221
+ >
222
+ {{ t("mapo.clear") }}
223
+ </UButton>
224
+ </div>
225
+
226
+ <div class="space-y-2 max-h-96 overflow-y-auto pr-1">
227
+ <div
228
+ v-for="(entry, i) in entries"
229
+ :key="i"
230
+ class="rounded-lg border p-3 transition-colors"
231
+ :class="{
232
+ 'border-success/40 bg-success/10': entry.status === 'done',
233
+ 'border-error/40 bg-error/10': entry.status === 'error',
234
+ 'border-default':
235
+ entry.status === 'pending' || entry.status === 'uploading',
236
+ }"
237
+ >
238
+ <div class="flex items-start gap-3">
239
+ <!-- Preview -->
240
+ <div class="size-12 shrink-0 overflow-hidden rounded bg-elevated">
241
+ <img
242
+ v-if="entry.previewUrl"
243
+ :src="entry.previewUrl"
244
+ class="size-full object-cover"
245
+ alt=""
246
+ />
247
+ <div v-else class="flex size-full items-center justify-center">
248
+ <UIcon name="i-lucide-file" class="size-6 text-dimmed" />
249
+ </div>
250
+ </div>
251
+
252
+ <div class="flex-1 min-w-0 space-y-1.5">
253
+ <!-- Filename + size -->
254
+ <div class="flex items-center gap-2">
255
+ <span class="truncate text-xs font-medium text-default">
256
+ {{ entry.file.name }}
257
+ </span>
258
+ <span class="shrink-0 text-xs text-dimmed">
259
+ {{ humanFileSize(entry.file.size) }}
260
+ </span>
261
+ </div>
262
+
263
+ <!-- Metadata inputs (only for pending) -->
264
+ <div
265
+ v-if="entry.status === 'pending'"
266
+ class="grid grid-cols-2 gap-1.5"
267
+ >
268
+ <UInput
269
+ v-model="entry.title"
270
+ size="xs"
271
+ :placeholder="t('mapo.title')"
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"
286
+ size="xs"
287
+ :placeholder="t('mapo.folder')"
288
+ />
289
+ </div>
290
+
291
+ <!-- Progress bar -->
292
+ <div v-if="entry.status === 'uploading'" class="space-y-0.5">
293
+ <UProgress :model-value="entry.progress" size="xs" />
294
+ <p class="text-right text-xs text-dimmed">
295
+ {{ entry.progress }}%
296
+ </p>
297
+ </div>
298
+
299
+ <!-- Status badges -->
300
+ <div
301
+ v-if="entry.status === 'done'"
302
+ class="flex items-center gap-1 text-success"
303
+ >
304
+ <UIcon name="i-lucide-check-circle" class="size-3.5" />
305
+ <span class="text-xs">{{
306
+ t("mapo.mediaUploader.uploaded")
307
+ }}</span>
308
+ </div>
309
+ <div
310
+ v-if="entry.status === 'error'"
311
+ class="flex items-center gap-1 text-error"
312
+ >
313
+ <UIcon name="i-lucide-alert-circle" class="size-3.5" />
314
+ <span class="text-xs">{{ entry.error }}</span>
315
+ </div>
316
+ </div>
317
+
318
+ <!-- Remove -->
319
+ <UButton
320
+ v-if="
321
+ !uploading ||
322
+ entry.status === 'done' ||
323
+ entry.status === 'error'
324
+ "
325
+ icon="i-lucide-x"
326
+ size="xs"
327
+ variant="ghost"
328
+ color="neutral"
329
+ @click="remove(i)"
330
+ />
331
+ </div>
332
+ </div>
333
+ </div>
334
+
335
+ <!-- Upload CTA -->
336
+ <div class="flex justify-end pt-2">
337
+ <UButton
338
+ icon="i-lucide-upload"
339
+ :loading="uploading"
340
+ :disabled="!canUpload"
341
+ color="primary"
342
+ @click="upload"
343
+ >
344
+ {{
345
+ t("mapo.mediaUploader.uploadCta", { n: pendingCount }, pendingCount)
346
+ }}
347
+ </UButton>
348
+ </div>
349
+ </div>
350
+ </div>
351
+ </template>