@mapomodule/uikit 2.0.0-beta.3 → 2.0.0-beta.5

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 (75) hide show
  1. package/README.md +33 -1
  2. package/dist/index.d.mts +1 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/module.d.mts +30 -1
  6. package/dist/module.d.ts +28 -0
  7. package/dist/module.d.ts.map +1 -1
  8. package/dist/module.json +1 -1
  9. package/dist/module.mjs +56 -2
  10. package/dist/runtime/adapters/defaultMediaAdapter.d.ts +14 -0
  11. package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
  12. package/dist/runtime/adapters/defaultMediaAdapter.js +30 -0
  13. package/dist/runtime/components/MapoDropArea.vue +95 -0
  14. package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
  15. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
  16. package/dist/runtime/components/MapoMediaBreadcrumbs.vue +45 -0
  17. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
  18. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
  19. package/dist/runtime/components/MapoMediaEditor.vue +310 -0
  20. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +8 -0
  21. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
  22. package/dist/runtime/components/MapoMediaFileChanger.vue +108 -0
  23. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
  24. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
  25. package/dist/runtime/components/MapoMediaFolders.vue +198 -0
  26. package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
  27. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
  28. package/dist/runtime/components/MapoMediaGallery.vue +209 -0
  29. package/dist/runtime/components/MapoMediaGallery.vue.d.ts +4 -0
  30. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
  31. package/dist/runtime/components/MapoMediaManager.vue +130 -0
  32. package/dist/runtime/components/MapoMediaManager.vue.d.ts +35 -0
  33. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
  34. package/dist/runtime/components/MapoMediaManagerDialog.vue +112 -0
  35. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
  36. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
  37. package/dist/runtime/components/MapoMediaPreview.vue +92 -0
  38. package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
  39. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
  40. package/dist/runtime/components/MapoMediaUploader.vue +266 -0
  41. package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
  42. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
  43. package/dist/runtime/pages/index.vue +0 -1
  44. package/dist/runtime/pages/index.vue.d.ts.map +1 -1
  45. package/dist/runtime/pages/login.vue +0 -4
  46. package/dist/runtime/pages/login.vue.d.ts.map +1 -1
  47. package/dist/runtime/plugins/media-adapter.d.ts +18 -0
  48. package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
  49. package/dist/runtime/plugins/media-adapter.js +7 -0
  50. package/dist/runtime/stores/media.d.ts +462 -0
  51. package/dist/runtime/stores/media.d.ts.map +1 -0
  52. package/dist/runtime/stores/media.js +323 -0
  53. package/dist/runtime/types/media.d.ts +116 -0
  54. package/dist/runtime/types/media.d.ts.map +1 -0
  55. package/dist/runtime/types/media.js +0 -0
  56. package/dist/types.d.mts +1 -1
  57. package/package.json +8 -6
  58. package/src/index.ts +8 -0
  59. package/src/module.ts +113 -0
  60. package/src/runtime/adapters/defaultMediaAdapter.ts +57 -0
  61. package/src/runtime/components/MapoDropArea.vue +122 -0
  62. package/src/runtime/components/MapoMediaBreadcrumbs.vue +51 -0
  63. package/src/runtime/components/MapoMediaEditor.vue +340 -0
  64. package/src/runtime/components/MapoMediaFileChanger.vue +131 -0
  65. package/src/runtime/components/MapoMediaFolders.vue +217 -0
  66. package/src/runtime/components/MapoMediaGallery.vue +227 -0
  67. package/src/runtime/components/MapoMediaManager.vue +170 -0
  68. package/src/runtime/components/MapoMediaManagerDialog.vue +142 -0
  69. package/src/runtime/components/MapoMediaPreview.vue +111 -0
  70. package/src/runtime/components/MapoMediaUploader.vue +324 -0
  71. package/src/runtime/pages/index.vue +0 -2
  72. package/src/runtime/pages/login.vue +0 -4
  73. package/src/runtime/plugins/media-adapter.ts +29 -0
  74. package/src/runtime/stores/media.ts +435 -0
  75. package/src/runtime/types/media.ts +126 -0
@@ -0,0 +1,209 @@
1
+ <script setup>
2
+ import { ref, computed } from "vue";
3
+ import { humanFileSize } from "@mapomodule/utils";
4
+ import { useMediaStore } from "../stores/media.js";
5
+ const store = useMediaStore();
6
+ const isPickerMode = computed(
7
+ () => store.selectMode === "single" || store.selectMode === "multi"
8
+ );
9
+ const multiSelection = computed(
10
+ () => store.selectMode === "multi" && Array.isArray(store.selection) ? store.selection : []
11
+ );
12
+ function isInSelection(media) {
13
+ if (store.selectMode === "single") {
14
+ return store.selection?.id === media.id;
15
+ }
16
+ if (store.selectMode === "multi") {
17
+ return store.selection?.some((m) => m.id === media.id) ?? false;
18
+ }
19
+ return false;
20
+ }
21
+ function onClickItem(media) {
22
+ if (isPickerMode.value) {
23
+ store.select(media);
24
+ } else {
25
+ store.openEditor(media);
26
+ }
27
+ }
28
+ const dragIndex = ref(null);
29
+ function onDragStart(index) {
30
+ dragIndex.value = index;
31
+ }
32
+ function onDragOverItem(index) {
33
+ if (dragIndex.value === null || dragIndex.value === index) return;
34
+ const items = [...multiSelection.value];
35
+ const [moved] = items.splice(dragIndex.value, 1);
36
+ if (!moved) return;
37
+ items.splice(index, 0, moved);
38
+ dragIndex.value = index;
39
+ store.setSelection(items);
40
+ }
41
+ function onDragEnd() {
42
+ dragIndex.value = null;
43
+ }
44
+ </script>
45
+
46
+ <template>
47
+ <div class="mapo-media-gallery flex flex-col gap-3">
48
+ <!-- Multi-picker selection strip: click to deselect, drag to reorder -->
49
+ <div
50
+ v-if="multiSelection.length > 0"
51
+ class="flex items-center gap-2 overflow-x-auto rounded-lg bg-elevated p-2"
52
+ >
53
+ <div
54
+ v-for="(media, i) in multiSelection"
55
+ :key="media.id"
56
+ class="group relative shrink-0 cursor-grab"
57
+ :class="{ 'opacity-50': dragIndex === i }"
58
+ draggable="true"
59
+ @dragstart="onDragStart(i)"
60
+ @dragover.prevent="onDragOverItem(i)"
61
+ @dragend="onDragEnd"
62
+ @click.stop="store.select(media)"
63
+ >
64
+ <MapoMediaPreview :media="media" size="xs" />
65
+ <div
66
+ class="absolute inset-0 hidden items-center justify-center rounded bg-black/50 text-white group-hover:flex"
67
+ >
68
+ <UIcon name="i-lucide-x" class="size-4" />
69
+ </div>
70
+ </div>
71
+ <span class="ml-auto shrink-0 pl-2 text-xs text-muted">
72
+ {{ multiSelection.length }} selected
73
+ </span>
74
+ </div>
75
+
76
+ <!-- Bulk actions bar -->
77
+ <div
78
+ v-if="!isPickerMode && store.editList.length > 0"
79
+ class="flex items-center gap-2 rounded-lg bg-elevated px-3 py-2"
80
+ >
81
+ <UCheckbox
82
+ :model-value="
83
+ store.editListState.indeterminate ? 'indeterminate' : store.editListState.value
84
+ "
85
+ :label="store.editListState.value ? 'Deselect all' : 'Select all'"
86
+ @update:model-value="store.editSelectAll()"
87
+ />
88
+ <span class="text-sm text-muted">
89
+ {{ store.editList.length }} selected
90
+ </span>
91
+ <div class="flex-1" />
92
+ <UButton
93
+ icon="i-lucide-trash-2"
94
+ size="xs"
95
+ color="error"
96
+ variant="soft"
97
+ @click="store.deleteSelected()"
98
+ >
99
+ Delete selected
100
+ </UButton>
101
+ <UButton
102
+ icon="i-lucide-x"
103
+ size="xs"
104
+ variant="ghost"
105
+ color="neutral"
106
+ @click="store.editList = []"
107
+ />
108
+ </div>
109
+
110
+ <!-- Loading skeleton -->
111
+ <div
112
+ v-if="store.loading"
113
+ class="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3"
114
+ >
115
+ <USkeleton v-for="n in 12" :key="n" class="aspect-square rounded-lg" />
116
+ </div>
117
+
118
+ <!-- Empty state -->
119
+ <div
120
+ v-else-if="store.medias.length === 0"
121
+ class="flex flex-col items-center gap-3 py-16 text-center"
122
+ >
123
+ <UIcon name="i-lucide-image-off" class="size-12 text-dimmed" />
124
+ <p class="text-sm text-muted">No media found</p>
125
+ </div>
126
+
127
+ <!-- Grid -->
128
+ <div
129
+ v-else
130
+ class="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3"
131
+ >
132
+ <div
133
+ v-for="media in store.medias"
134
+ :key="media.id"
135
+ class="group relative cursor-pointer overflow-hidden rounded-lg bg-elevated"
136
+ :class="{
137
+ 'ring-2 ring-primary': isInSelection(media),
138
+ 'ring-2 ring-primary ring-offset-1': store.editListSet.has(media.id)
139
+ }"
140
+ @click="onClickItem(media)"
141
+ >
142
+ <!-- Preview -->
143
+ <div class="aspect-square">
144
+ <MapoMediaPreview :media="media" size="lg" class="size-full" />
145
+ </div>
146
+
147
+ <!-- Hover overlay with filename -->
148
+ <div
149
+ class="absolute inset-x-0 bottom-0 translate-y-full bg-black/60 px-1.5 py-1 transition-transform group-hover:translate-y-0"
150
+ >
151
+ <p class="truncate text-[10px] text-white">
152
+ {{ media.title || media.file?.split("/").pop() }}
153
+ </p>
154
+ <p class="text-[9px] text-white/60">
155
+ {{ humanFileSize(media.size) }}
156
+ </p>
157
+ </div>
158
+
159
+ <!-- Selection checkmark (picker mode) -->
160
+ <div
161
+ v-if="isPickerMode && isInSelection(media)"
162
+ class="absolute right-1.5 top-1.5 flex size-5 items-center justify-center rounded-full bg-primary text-inverted"
163
+ >
164
+ <UIcon name="i-lucide-check" class="size-3" />
165
+ </div>
166
+
167
+ <!-- Bulk checkbox (gallery mode, no selection) -->
168
+ <div
169
+ v-if="!isPickerMode"
170
+ class="absolute left-1.5 top-1.5 opacity-0 transition-opacity group-hover:opacity-100"
171
+ :class="{ '!opacity-100': store.editListSet.has(media.id) }"
172
+ @click.stop
173
+ >
174
+ <UCheckbox
175
+ :model-value="store.editListSet.has(media.id)"
176
+ @update:model-value="store.editSelect(media.id)"
177
+ />
178
+ </div>
179
+
180
+ <!-- Edit button (gallery mode, visible on hover) -->
181
+ <div
182
+ v-if="!isPickerMode"
183
+ class="absolute right-1.5 top-1.5 opacity-0 transition-opacity group-hover:opacity-100"
184
+ >
185
+ <UButton
186
+ icon="i-lucide-pencil"
187
+ size="xs"
188
+ variant="solid"
189
+ color="neutral"
190
+ class="shadow"
191
+ @click.stop="store.openEditor(media)"
192
+ />
193
+ </div>
194
+ </div>
195
+ </div>
196
+
197
+ <!-- Pagination -->
198
+ <div v-if="store.pages > 1" class="flex justify-center pt-2">
199
+ <!-- The backend paginator only exposes page/pages (no item count), so the
200
+ page count is mapped 1:1 with items-per-page=1. -->
201
+ <UPagination
202
+ :page="store.page"
203
+ :total="store.pages"
204
+ :items-per-page="1"
205
+ @update:page="store.getRoot({ page: $event })"
206
+ />
207
+ </div>
208
+ </div>
209
+ </template>
@@ -0,0 +1,4 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
4
+ //# sourceMappingURL=MapoMediaGallery.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoMediaGallery.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaGallery.vue"],"names":[],"mappings":"AAszBA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -0,0 +1,130 @@
1
+ <script setup>
2
+ import { ref, onMounted, onUnmounted, watch } from "vue";
3
+ import { debounce } from "@mapomodule/utils";
4
+ import { useMediaStore } from "../stores/media.js";
5
+ const props = defineProps({
6
+ selectionMode: { type: String, required: false, default: "none" },
7
+ mime: { type: [String, null], required: false, default: null },
8
+ noFolders: { type: Boolean, required: false, default: false },
9
+ languages: { type: Array, required: false, default: void 0 },
10
+ defaultLang: { type: String, required: false, default: void 0 },
11
+ initialSelection: { type: null, required: false, default: null }
12
+ });
13
+ const emit = defineEmits(["update:selection"]);
14
+ const store = useMediaStore();
15
+ const activeTab = ref("gallery");
16
+ const tabItems = [
17
+ { label: "Gallery", icon: "i-lucide-images", value: "gallery" },
18
+ { label: "Upload", icon: "i-lucide-upload-cloud", value: "upload" }
19
+ ];
20
+ const searchValue = ref("");
21
+ const showFolders = ref(!props.noFolders);
22
+ const debouncedSearch = debounce((val) => {
23
+ store.getRoot({ page: 1, search: val, all: !!val });
24
+ }, 500);
25
+ watch(searchValue, (val) => debouncedSearch(val));
26
+ watch(
27
+ () => store.selection,
28
+ (sel) => {
29
+ if (props.selectionMode !== "none") {
30
+ emit("update:selection", sel);
31
+ }
32
+ }
33
+ );
34
+ onMounted(async () => {
35
+ store.setSelectionMode(props.selectionMode);
36
+ if (props.initialSelection) store.setSelection(props.initialSelection);
37
+ if (props.mime) store.lockMimeType(props.mime);
38
+ if (props.defaultLang) store.setLang(props.defaultLang);
39
+ await store.getRoot({ page: 1 });
40
+ });
41
+ onUnmounted(() => {
42
+ store.reset();
43
+ });
44
+ </script>
45
+
46
+ <template>
47
+ <div class="mapo-media-manager flex h-full overflow-hidden">
48
+ <!-- Folders sidebar -->
49
+ <div
50
+ v-if="showFolders"
51
+ class="w-48 shrink-0 border-r border-default bg-default"
52
+ >
53
+ <MapoMediaFolders />
54
+ </div>
55
+
56
+ <!-- Main area -->
57
+ <div class="flex min-w-0 flex-1 flex-col">
58
+ <!-- Top bar: breadcrumbs + search + tabs toggle -->
59
+ <div
60
+ class="flex items-center gap-3 border-b border-default bg-default px-4 py-2"
61
+ >
62
+ <!-- Toggle folders button -->
63
+ <UButton
64
+ v-if="!noFolders"
65
+ :icon="
66
+ showFolders ? 'i-lucide-panel-left-close' : 'i-lucide-panel-left-open'
67
+ "
68
+ size="xs"
69
+ variant="ghost"
70
+ color="neutral"
71
+ @click="showFolders = !showFolders"
72
+ />
73
+
74
+ <!-- Breadcrumbs -->
75
+ <MapoMediaBreadcrumbs class="flex-1" />
76
+
77
+ <!-- Search -->
78
+ <div v-if="activeTab === 'gallery'" class="w-48 shrink-0">
79
+ <UInput
80
+ v-model="searchValue"
81
+ size="xs"
82
+ placeholder="Search..."
83
+ icon="i-lucide-search"
84
+ :loading="store.loading"
85
+ />
86
+ </div>
87
+
88
+ <!-- Refresh -->
89
+ <UButton
90
+ icon="i-lucide-refresh-cw"
91
+ size="xs"
92
+ variant="ghost"
93
+ color="neutral"
94
+ title="Refresh"
95
+ @click="store.getRoot()"
96
+ />
97
+
98
+ <!-- Tab switcher -->
99
+ <UTabs
100
+ v-model="activeTab"
101
+ :items="tabItems"
102
+ :content="false"
103
+ size="xs"
104
+ color="neutral"
105
+ />
106
+ </div>
107
+
108
+ <!-- Content -->
109
+ <div class="flex-1 overflow-y-auto p-4">
110
+ <MapoMediaGallery v-if="activeTab === 'gallery'" />
111
+ <MapoMediaUploader v-else @uploaded="activeTab = 'gallery'" />
112
+ </div>
113
+
114
+ <!-- Custom actions (legacy parity: v1 exposed an `actions` card slot) -->
115
+ <div
116
+ v-if="$slots.actions"
117
+ class="flex items-center justify-end gap-2 border-t border-default px-4 py-2"
118
+ >
119
+ <slot name="actions" />
120
+ </div>
121
+ </div>
122
+
123
+ <!-- Editor drawer (overlays from right, only in gallery mode, none-selection) -->
124
+ <MapoMediaEditor
125
+ v-if="activeTab === 'gallery'"
126
+ :languages="languages"
127
+ :default-lang="defaultLang"
128
+ />
129
+ </div>
130
+ </template>
@@ -0,0 +1,35 @@
1
+ import type { SelectMode } from "../types/media.js";
2
+ type __VLS_Props = {
3
+ selectionMode?: SelectMode;
4
+ mime?: string | null;
5
+ noFolders?: boolean;
6
+ languages?: string[];
7
+ defaultLang?: string;
8
+ /** Pre-seed the picker selection (e.g. the field's current value). */
9
+ initialSelection?: import("../types/media.js").MediaItem | import("../types/media.js").MediaItem[] | null;
10
+ };
11
+ declare var __VLS_47: {};
12
+ type __VLS_Slots = {} & {
13
+ actions?: (props: typeof __VLS_47) => any;
14
+ };
15
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
16
+ "update:selection": (value: import("@mapomodule/form/types").MediaItem | import("@mapomodule/form/types").MediaItem[] | null) => any;
17
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
18
+ "onUpdate:selection"?: ((value: import("@mapomodule/form/types").MediaItem | import("@mapomodule/form/types").MediaItem[] | null) => any) | undefined;
19
+ }>, {
20
+ mime: string | null;
21
+ languages: string[];
22
+ defaultLang: string;
23
+ selectionMode: SelectMode;
24
+ noFolders: boolean;
25
+ initialSelection: import("../types/media.js").MediaItem | import("../types/media.js").MediaItem[] | null;
26
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
27
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
28
+ declare const _default: typeof __VLS_export;
29
+ export default _default;
30
+ type __VLS_WithSlots<T, S> = T & {
31
+ new (): {
32
+ $slots: S;
33
+ };
34
+ };
35
+ //# sourceMappingURL=MapoMediaManager.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoMediaManager.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaManager.vue"],"names":[],"mappings":"AAgLA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,KAAK,WAAW,GAAG;IACf,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,gBAAgB,CAAC,EACb,OAAO,mBAAmB,EAAE,SAAS,GACrC,OAAO,mBAAmB,EAAE,SAAS,EAAE,GACvC,IAAI,CAAC;CACV,CAAC;AAgVJ,QAAA,IAAI,QAAQ,IAAY,CAAE;AAC1B,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAKhD,QAAA,MAAM,UAAU;;;;;UAhWL,MAAM,GAAG,IAAI;eAER,MAAM,EAAE;iBACN,MAAM;mBAJJ,UAAU;eAEd,OAAO;sBAKf,OAAO,mBAAmB,EAAE,SAAS,GACrC,OAAO,mBAAmB,EAAE,SAAS,EAAE,GACvC,IAAI;6EA4VV,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -0,0 +1,112 @@
1
+ <script setup>
2
+ import { ref, watch, computed } from "vue";
3
+ import { useMediaStore } from "../stores/media.js";
4
+ const props = defineProps({
5
+ modelValue: { type: Boolean, required: false, default: false },
6
+ selectionMode: { type: String, required: false, default: "single" },
7
+ mime: { type: [String, null], required: false, default: null },
8
+ noFolders: { type: Boolean, required: false, default: false },
9
+ languages: { type: Array, required: false, default: void 0 },
10
+ defaultLang: { type: String, required: false, default: void 0 },
11
+ selected: { type: null, required: false, default: null }
12
+ });
13
+ const emit = defineEmits(["update:modelValue", "confirm"]);
14
+ const store = useMediaStore();
15
+ const open = ref(props.modelValue);
16
+ watch(
17
+ () => props.modelValue,
18
+ (v) => open.value = v
19
+ );
20
+ watch(open, (v) => emit("update:modelValue", v));
21
+ const hasSelection = computed(() => {
22
+ if (props.selectionMode === "single") return !!store.selection;
23
+ return Array.isArray(store.selection) && store.selection.length > 0;
24
+ });
25
+ const selectionCount = computed(() => {
26
+ if (props.selectionMode === "multi" && Array.isArray(store.selection)) {
27
+ return store.selection.length;
28
+ }
29
+ return 0;
30
+ });
31
+ function confirm() {
32
+ if (!store.selection) return;
33
+ emit("confirm", store.selection);
34
+ open.value = false;
35
+ }
36
+ function cancel() {
37
+ open.value = false;
38
+ }
39
+ watch(
40
+ () => store.selection,
41
+ (sel) => {
42
+ if (!open.value || props.selectionMode !== "single") return;
43
+ if (Array.isArray(sel) || !sel) return;
44
+ const initial = props.selected;
45
+ if (sel.id !== initial?.id) confirm();
46
+ }
47
+ );
48
+ </script>
49
+
50
+ <template>
51
+ <!-- Activator slot: the caller provides the trigger button -->
52
+ <slot name="activator" :open="() => open = true" />
53
+
54
+ <UModal v-model:open="open" :ui="{ content: 'max-w-5xl w-full h-[80vh]' }">
55
+ <!-- #content gives full control: the default slot is the trigger in Nuxt UI v4 -->
56
+ <template #content>
57
+ <div class="flex h-full flex-col">
58
+ <!-- Header -->
59
+ <div class="flex items-center gap-2 border-b border-default px-4 py-3">
60
+ <UIcon name="i-lucide-image" class="size-4 text-dimmed" />
61
+ <span class="flex-1 font-semibold text-highlighted">
62
+ {{ selectionMode === "multi" ? "Select media" : "Select a media" }}
63
+ </span>
64
+ <UButton
65
+ icon="i-lucide-x"
66
+ size="xs"
67
+ variant="ghost"
68
+ color="neutral"
69
+ @click="cancel"
70
+ />
71
+ </div>
72
+
73
+ <!-- Body: media manager fills remaining space -->
74
+ <div class="min-h-0 flex-1">
75
+ <MapoMediaManager
76
+ :selection-mode="selectionMode"
77
+ :mime="mime"
78
+ :no-folders="noFolders"
79
+ :languages="languages"
80
+ :default-lang="defaultLang"
81
+ :initial-selection="selected"
82
+ />
83
+ </div>
84
+
85
+ <!-- Footer -->
86
+ <div
87
+ class="flex items-center justify-between gap-2 border-t border-default px-4 py-3"
88
+ >
89
+ <p
90
+ v-if="selectionMode === 'multi' && selectionCount > 0"
91
+ class="text-sm text-muted"
92
+ >
93
+ {{ selectionCount }} selected
94
+ </p>
95
+ <div class="ml-auto flex gap-2">
96
+ <UButton variant="ghost" color="neutral" @click="cancel">
97
+ Cancel
98
+ </UButton>
99
+ <UButton
100
+ color="primary"
101
+ :disabled="!hasSelection"
102
+ icon="i-lucide-check"
103
+ @click="confirm"
104
+ >
105
+ Confirm
106
+ </UButton>
107
+ </div>
108
+ </div>
109
+ </div>
110
+ </template>
111
+ </UModal>
112
+ </template>
@@ -0,0 +1,41 @@
1
+ import type { MediaItem, SelectMode } from "../types/media.js";
2
+ type __VLS_Props = {
3
+ modelValue?: boolean;
4
+ selectionMode?: Exclude<SelectMode, "none">;
5
+ mime?: string | null;
6
+ noFolders?: boolean;
7
+ languages?: string[];
8
+ defaultLang?: string;
9
+ /** Current value of the host field — pre-seeds the picker selection. */
10
+ selected?: MediaItem | MediaItem[] | null;
11
+ };
12
+ declare var __VLS_1: {
13
+ open: () => boolean;
14
+ };
15
+ type __VLS_Slots = {} & {
16
+ activator?: (props: typeof __VLS_1) => any;
17
+ };
18
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
19
+ confirm: (value: MediaItem | MediaItem[]) => any;
20
+ "update:modelValue": (value: boolean) => any;
21
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
22
+ onConfirm?: ((value: MediaItem | MediaItem[]) => any) | undefined;
23
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
24
+ }>, {
25
+ mime: string | null;
26
+ languages: string[];
27
+ modelValue: boolean;
28
+ defaultLang: string;
29
+ selectionMode: Exclude<SelectMode, "none">;
30
+ noFolders: boolean;
31
+ selected: MediaItem | MediaItem[] | null;
32
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
33
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
34
+ declare const _default: typeof __VLS_export;
35
+ export default _default;
36
+ type __VLS_WithSlots<T, S> = T & {
37
+ new (): {
38
+ $slots: S;
39
+ };
40
+ };
41
+ //# sourceMappingURL=MapoMediaManagerDialog.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoMediaManagerDialog.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaManagerDialog.vue"],"names":[],"mappings":"AAmJA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/D,KAAK,WAAW,GAAG;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC5C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,IAAI,CAAC;CAC3C,CAAC;AA6RJ,QAAA,IAAI,OAAO;;CAAW,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAGjD,QAAA,MAAM,UAAU;;;;;;;UAxSL,MAAM,GAAG,IAAI;eAER,MAAM,EAAE;gBAJP,OAAO;iBAKN,MAAM;mBAJJ,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC;eAE/B,OAAO;cAIR,SAAS,GAAG,SAAS,EAAE,GAAG,IAAI;6EAuS3C,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -0,0 +1,92 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ const props = defineProps({
4
+ media: { type: null, required: true },
5
+ size: { type: String, required: false, default: "md" },
6
+ contain: { type: Boolean, required: false, default: false },
7
+ showFilename: { type: Boolean, required: false, default: false },
8
+ videoControls: { type: Boolean, required: false, default: false },
9
+ videoAutoplay: { type: Boolean, required: false, default: false }
10
+ });
11
+ const isImage = computed(() => props.media.mime_type?.startsWith("image/"));
12
+ const isVideo = computed(() => props.media.mime_type?.startsWith("video/"));
13
+ const isAudio = computed(() => props.media.mime_type?.startsWith("audio/"));
14
+ const isPdf = computed(() => props.media.mime_type === "application/pdf");
15
+ const sizeClass = computed(() => {
16
+ const map = {
17
+ xs: "size-10",
18
+ sm: "size-16",
19
+ md: "size-24",
20
+ lg: "size-40"
21
+ };
22
+ return map[props.size];
23
+ });
24
+ const iconName = computed(() => {
25
+ if (isVideo.value) return "i-lucide-film";
26
+ if (isAudio.value) return "i-lucide-music";
27
+ if (isPdf.value) return "i-lucide-file-text";
28
+ return "i-lucide-file";
29
+ });
30
+ const displayName = computed(
31
+ () => props.media.title || props.media.name || props.media.file?.split("/").pop() || ""
32
+ );
33
+ </script>
34
+
35
+ <template>
36
+ <div class="mapo-media-preview flex flex-col items-center gap-1">
37
+ <div
38
+ class="overflow-hidden rounded bg-elevated flex items-center justify-center"
39
+ :class="sizeClass"
40
+ >
41
+ <!-- Image -->
42
+ <img
43
+ v-if="isImage"
44
+ :src="media.file"
45
+ :alt="media.alt_text || displayName"
46
+ class="size-full"
47
+ :class="contain ? 'object-contain' : 'object-cover'"
48
+ loading="lazy"
49
+ decoding="async"
50
+ />
51
+
52
+ <!-- Video -->
53
+ <video
54
+ v-else-if="isVideo"
55
+ :src="media.file"
56
+ class="size-full object-cover"
57
+ :controls="videoControls"
58
+ :autoplay="videoAutoplay"
59
+ muted
60
+ playsinline
61
+ />
62
+
63
+ <!-- Audio -->
64
+ <div
65
+ v-else-if="isAudio"
66
+ class="flex flex-col items-center gap-1 p-2 text-center"
67
+ >
68
+ <UIcon :name="iconName" class="size-8 text-dimmed" />
69
+ <audio v-if="videoControls" :src="media.file" controls class="w-full" />
70
+ </div>
71
+
72
+ <!-- Generic file icon -->
73
+ <div v-else class="flex flex-col items-center gap-1 p-2 text-center">
74
+ <UIcon :name="iconName" class="size-8 text-dimmed" />
75
+ <span
76
+ v-if="size !== 'xs'"
77
+ class="line-clamp-2 break-all text-[10px] text-muted"
78
+ >
79
+ {{ media.mime_type }}
80
+ </span>
81
+ </div>
82
+ </div>
83
+
84
+ <span
85
+ v-if="showFilename"
86
+ class="max-w-full truncate text-center text-xs text-muted"
87
+ :title="displayName"
88
+ >
89
+ {{ displayName }}
90
+ </span>
91
+ </div>
92
+ </template>
@@ -0,0 +1,19 @@
1
+ import type { MediaItem } from "../types/media.js";
2
+ type __VLS_Props = {
3
+ media: MediaItem;
4
+ size?: "xs" | "sm" | "md" | "lg";
5
+ contain?: boolean;
6
+ showFilename?: boolean;
7
+ videoControls?: boolean;
8
+ videoAutoplay?: boolean;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
11
+ size: "xs" | "sm" | "md" | "lg";
12
+ contain: boolean;
13
+ showFilename: boolean;
14
+ videoControls: boolean;
15
+ videoAutoplay: boolean;
16
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
+ declare const _default: typeof __VLS_export;
18
+ export default _default;
19
+ //# sourceMappingURL=MapoMediaPreview.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoMediaPreview.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaPreview.vue"],"names":[],"mappings":"AAmHA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,KAAK,WAAW,GAAG;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAoMJ,QAAA,MAAM,YAAY;UAzMP,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI;aACtB,OAAO;kBACF,OAAO;mBACN,OAAO;mBACP,OAAO;6EAwMzB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}