@mapomodule/uikit 2.0.0-beta.4 → 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.
- package/README.md +33 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/module.d.mts +30 -1
- package/dist/module.d.ts +28 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +51 -2
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts +14 -0
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
- package/dist/runtime/adapters/defaultMediaAdapter.js +30 -0
- package/dist/runtime/components/MapoDropArea.vue +95 -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/MapoMediaBreadcrumbs.vue +45 -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 +310 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue +108 -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/MapoMediaFolders.vue +198 -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 +209 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManager.vue +130 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts +35 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue +112 -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 +92 -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 +266 -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/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 +7 -0
- package/dist/runtime/stores/media.d.ts +462 -0
- package/dist/runtime/stores/media.d.ts.map +1 -0
- package/dist/runtime/stores/media.js +323 -0
- package/dist/runtime/types/media.d.ts +116 -0
- package/dist/runtime/types/media.d.ts.map +1 -0
- package/dist/runtime/types/media.js +0 -0
- package/dist/types.d.mts +1 -1
- package/package.json +7 -5
- package/src/index.ts +8 -0
- package/src/module.ts +103 -0
- package/src/runtime/adapters/defaultMediaAdapter.ts +57 -0
- package/src/runtime/components/MapoDropArea.vue +122 -0
- package/src/runtime/components/MapoMediaBreadcrumbs.vue +51 -0
- package/src/runtime/components/MapoMediaEditor.vue +340 -0
- package/src/runtime/components/MapoMediaFileChanger.vue +131 -0
- package/src/runtime/components/MapoMediaFolders.vue +217 -0
- package/src/runtime/components/MapoMediaGallery.vue +227 -0
- package/src/runtime/components/MapoMediaManager.vue +170 -0
- package/src/runtime/components/MapoMediaManagerDialog.vue +142 -0
- package/src/runtime/components/MapoMediaPreview.vue +111 -0
- package/src/runtime/components/MapoMediaUploader.vue +324 -0
- package/src/runtime/plugins/media-adapter.ts +29 -0
- package/src/runtime/stores/media.ts +435 -0
- package/src/runtime/types/media.ts +126 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed } from "vue";
|
|
3
|
+
import { useMediaStore } from "../stores/media.js";
|
|
4
|
+
import type { MediaFolder } from "../types/media.js";
|
|
5
|
+
|
|
6
|
+
const store = useMediaStore();
|
|
7
|
+
|
|
8
|
+
const editingFolder = ref<Partial<MediaFolder> | null>(null);
|
|
9
|
+
const folderName = ref("");
|
|
10
|
+
const saving = ref(false);
|
|
11
|
+
|
|
12
|
+
const ALL_MIME_FILTERS = [
|
|
13
|
+
{ label: "All", icon: "i-lucide-layers", mime: null as string | null },
|
|
14
|
+
{ label: "Images", icon: "i-lucide-image", mime: "image/*" },
|
|
15
|
+
{ label: "Videos", icon: "i-lucide-film", mime: "video/*" },
|
|
16
|
+
{ label: "Audio", icon: "i-lucide-music", mime: "audio/*" },
|
|
17
|
+
// Family filter (legacy parity): pdf, zip, office docs — not just pdf.
|
|
18
|
+
{ label: "Documents", icon: "i-lucide-file-text", mime: "application/*" },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// When the host locks a mime (picker fields), only the matching filter is
|
|
22
|
+
// offered — "All" would let the user select media of the wrong type.
|
|
23
|
+
const mimeFilters = computed(() =>
|
|
24
|
+
store.lockedMime
|
|
25
|
+
? ALL_MIME_FILTERS.filter((f) => f.mime === store.lockedMime)
|
|
26
|
+
: ALL_MIME_FILTERS,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
function startCreate() {
|
|
30
|
+
editingFolder.value = {};
|
|
31
|
+
folderName.value = "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function startEdit(folder: MediaFolder) {
|
|
35
|
+
editingFolder.value = { ...folder };
|
|
36
|
+
folderName.value = folder.name;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function cancelEdit() {
|
|
40
|
+
editingFolder.value = null;
|
|
41
|
+
folderName.value = "";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function saveFolder() {
|
|
45
|
+
if (!folderName.value.trim()) return;
|
|
46
|
+
saving.value = true;
|
|
47
|
+
try {
|
|
48
|
+
await store.updateOrCreateFolder({
|
|
49
|
+
...editingFolder.value,
|
|
50
|
+
name: folderName.value.trim(),
|
|
51
|
+
});
|
|
52
|
+
cancelEdit();
|
|
53
|
+
} finally {
|
|
54
|
+
saving.value = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function selectMime(mime: string | null) {
|
|
59
|
+
store.setMimeType(mime);
|
|
60
|
+
// Mime filters act as virtual folders spanning the whole library (legacy
|
|
61
|
+
// behavior); clearing back to "All" returns to the current folder scope.
|
|
62
|
+
store.getRoot({ page: 1, all: !!mime });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Single keyup handler — @keyup.enter + @keyup.esc on the same element compile
|
|
66
|
+
// to duplicate object keys (TS1117 under vue-tsc).
|
|
67
|
+
function onNameKeyup(event: KeyboardEvent) {
|
|
68
|
+
if (event.key === "Enter") saveFolder();
|
|
69
|
+
else if (event.key === "Escape") cancelEdit();
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<template>
|
|
74
|
+
<div class="mapo-media-folders flex h-full flex-col gap-2 py-2">
|
|
75
|
+
<!-- MIME filters -->
|
|
76
|
+
<div class="space-y-0.5 px-2">
|
|
77
|
+
<p
|
|
78
|
+
class="mb-1 px-1 text-xs font-semibold uppercase tracking-wide text-dimmed"
|
|
79
|
+
>
|
|
80
|
+
Type
|
|
81
|
+
</p>
|
|
82
|
+
<UButton
|
|
83
|
+
v-for="f in mimeFilters"
|
|
84
|
+
:key="f.mime ?? 'all'"
|
|
85
|
+
variant="ghost"
|
|
86
|
+
color="neutral"
|
|
87
|
+
size="xs"
|
|
88
|
+
block
|
|
89
|
+
:icon="f.icon"
|
|
90
|
+
class="justify-start"
|
|
91
|
+
:class="{ 'bg-elevated': store.mimeType === f.mime }"
|
|
92
|
+
@click="selectMime(f.mime)"
|
|
93
|
+
>
|
|
94
|
+
{{ f.label }}
|
|
95
|
+
</UButton>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<USeparator />
|
|
99
|
+
|
|
100
|
+
<!-- Folders header -->
|
|
101
|
+
<div class="flex items-center justify-between px-3">
|
|
102
|
+
<p class="text-xs font-semibold uppercase tracking-wide text-dimmed">
|
|
103
|
+
Folders
|
|
104
|
+
</p>
|
|
105
|
+
<UButton
|
|
106
|
+
icon="i-lucide-folder-plus"
|
|
107
|
+
size="xs"
|
|
108
|
+
variant="ghost"
|
|
109
|
+
color="neutral"
|
|
110
|
+
title="New folder"
|
|
111
|
+
@click="startCreate"
|
|
112
|
+
/>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<!-- New folder input -->
|
|
116
|
+
<div v-if="editingFolder && !editingFolder.id" class="px-2">
|
|
117
|
+
<UInput
|
|
118
|
+
v-model="folderName"
|
|
119
|
+
size="xs"
|
|
120
|
+
placeholder="Folder name"
|
|
121
|
+
autofocus
|
|
122
|
+
@keyup="onNameKeyup"
|
|
123
|
+
>
|
|
124
|
+
<template #trailing>
|
|
125
|
+
<UButton
|
|
126
|
+
icon="i-lucide-check"
|
|
127
|
+
size="xs"
|
|
128
|
+
variant="ghost"
|
|
129
|
+
color="primary"
|
|
130
|
+
:loading="saving"
|
|
131
|
+
@click="saveFolder"
|
|
132
|
+
/>
|
|
133
|
+
</template>
|
|
134
|
+
</UInput>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<!-- Folder list -->
|
|
138
|
+
<div class="flex-1 overflow-y-auto px-2">
|
|
139
|
+
<div v-for="folder in store.folders" :key="folder.id">
|
|
140
|
+
<!-- Editing this folder -->
|
|
141
|
+
<UInput
|
|
142
|
+
v-if="editingFolder?.id === folder.id"
|
|
143
|
+
v-model="folderName"
|
|
144
|
+
size="xs"
|
|
145
|
+
autofocus
|
|
146
|
+
@keyup="onNameKeyup"
|
|
147
|
+
>
|
|
148
|
+
<template #trailing>
|
|
149
|
+
<UButton
|
|
150
|
+
icon="i-lucide-check"
|
|
151
|
+
size="xs"
|
|
152
|
+
variant="ghost"
|
|
153
|
+
color="primary"
|
|
154
|
+
:loading="saving"
|
|
155
|
+
@click="saveFolder"
|
|
156
|
+
/>
|
|
157
|
+
</template>
|
|
158
|
+
</UInput>
|
|
159
|
+
|
|
160
|
+
<!-- Folder row -->
|
|
161
|
+
<div
|
|
162
|
+
v-else
|
|
163
|
+
class="group flex items-center gap-1 rounded px-1 py-1 hover:bg-elevated"
|
|
164
|
+
>
|
|
165
|
+
<UButton
|
|
166
|
+
variant="ghost"
|
|
167
|
+
color="neutral"
|
|
168
|
+
size="xs"
|
|
169
|
+
icon="i-lucide-folder"
|
|
170
|
+
class="flex-1 justify-start truncate"
|
|
171
|
+
@click="store.navigateToFolder(folder)"
|
|
172
|
+
>
|
|
173
|
+
{{ folder.name }}
|
|
174
|
+
</UButton>
|
|
175
|
+
<div class="hidden items-center gap-0.5 group-hover:flex">
|
|
176
|
+
<UButton
|
|
177
|
+
icon="i-lucide-pencil"
|
|
178
|
+
size="xs"
|
|
179
|
+
variant="ghost"
|
|
180
|
+
color="neutral"
|
|
181
|
+
@click.stop="startEdit(folder)"
|
|
182
|
+
/>
|
|
183
|
+
<UButton
|
|
184
|
+
icon="i-lucide-trash-2"
|
|
185
|
+
size="xs"
|
|
186
|
+
variant="ghost"
|
|
187
|
+
color="error"
|
|
188
|
+
@click.stop="store.deleteFolder(folder)"
|
|
189
|
+
/>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<p
|
|
195
|
+
v-if="store.folders.length === 0"
|
|
196
|
+
class="px-2 py-3 text-xs text-dimmed italic"
|
|
197
|
+
>
|
|
198
|
+
No folders
|
|
199
|
+
</p>
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
<!-- Back -->
|
|
203
|
+
<div v-if="store.parentFolder" class="border-t border-default px-2 pt-2">
|
|
204
|
+
<UButton
|
|
205
|
+
icon="i-lucide-arrow-left"
|
|
206
|
+
size="xs"
|
|
207
|
+
variant="ghost"
|
|
208
|
+
color="neutral"
|
|
209
|
+
block
|
|
210
|
+
class="justify-start"
|
|
211
|
+
@click="store.navigateToFolder(null)"
|
|
212
|
+
>
|
|
213
|
+
Back to root
|
|
214
|
+
</UButton>
|
|
215
|
+
</div>
|
|
216
|
+
</div>
|
|
217
|
+
</template>
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed } from "vue";
|
|
3
|
+
import { humanFileSize } from "@mapomodule/utils";
|
|
4
|
+
import { useMediaStore } from "../stores/media.js";
|
|
5
|
+
import type { MediaItem } from "../types/media.js";
|
|
6
|
+
|
|
7
|
+
const store = useMediaStore();
|
|
8
|
+
|
|
9
|
+
const isPickerMode = computed(
|
|
10
|
+
() => store.selectMode === "single" || store.selectMode === "multi",
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const multiSelection = computed<MediaItem[]>(() =>
|
|
14
|
+
store.selectMode === "multi" && Array.isArray(store.selection)
|
|
15
|
+
? store.selection
|
|
16
|
+
: [],
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
function isInSelection(media: MediaItem): boolean {
|
|
20
|
+
if (store.selectMode === "single") {
|
|
21
|
+
return (store.selection as MediaItem | null)?.id === media.id;
|
|
22
|
+
}
|
|
23
|
+
if (store.selectMode === "multi") {
|
|
24
|
+
return (
|
|
25
|
+
(store.selection as MediaItem[])?.some((m) => m.id === media.id) ?? false
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function onClickItem(media: MediaItem) {
|
|
32
|
+
if (isPickerMode.value) {
|
|
33
|
+
store.select(media);
|
|
34
|
+
} else {
|
|
35
|
+
store.openEditor(media);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Selection strip drag reorder (legacy parity: v1 used vuedraggable) —
|
|
40
|
+
// the picker order is the order the m2m relation is saved in.
|
|
41
|
+
const dragIndex = ref<number | null>(null);
|
|
42
|
+
|
|
43
|
+
function onDragStart(index: number) {
|
|
44
|
+
dragIndex.value = index;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function onDragOverItem(index: number) {
|
|
48
|
+
if (dragIndex.value === null || dragIndex.value === index) return;
|
|
49
|
+
const items = [...multiSelection.value];
|
|
50
|
+
const [moved] = items.splice(dragIndex.value, 1);
|
|
51
|
+
if (!moved) return;
|
|
52
|
+
items.splice(index, 0, moved);
|
|
53
|
+
dragIndex.value = index;
|
|
54
|
+
store.setSelection(items);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function onDragEnd() {
|
|
58
|
+
dragIndex.value = null;
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<div class="mapo-media-gallery flex flex-col gap-3">
|
|
64
|
+
<!-- Multi-picker selection strip: click to deselect, drag to reorder -->
|
|
65
|
+
<div
|
|
66
|
+
v-if="multiSelection.length > 0"
|
|
67
|
+
class="flex items-center gap-2 overflow-x-auto rounded-lg bg-elevated p-2"
|
|
68
|
+
>
|
|
69
|
+
<div
|
|
70
|
+
v-for="(media, i) in multiSelection"
|
|
71
|
+
:key="media.id"
|
|
72
|
+
class="group relative shrink-0 cursor-grab"
|
|
73
|
+
:class="{ 'opacity-50': dragIndex === i }"
|
|
74
|
+
draggable="true"
|
|
75
|
+
@dragstart="onDragStart(i)"
|
|
76
|
+
@dragover.prevent="onDragOverItem(i)"
|
|
77
|
+
@dragend="onDragEnd"
|
|
78
|
+
@click.stop="store.select(media)"
|
|
79
|
+
>
|
|
80
|
+
<MapoMediaPreview :media="media" size="xs" />
|
|
81
|
+
<div
|
|
82
|
+
class="absolute inset-0 hidden items-center justify-center rounded bg-black/50 text-white group-hover:flex"
|
|
83
|
+
>
|
|
84
|
+
<UIcon name="i-lucide-x" class="size-4" />
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
<span class="ml-auto shrink-0 pl-2 text-xs text-muted">
|
|
88
|
+
{{ multiSelection.length }} selected
|
|
89
|
+
</span>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<!-- Bulk actions bar -->
|
|
93
|
+
<div
|
|
94
|
+
v-if="!isPickerMode && store.editList.length > 0"
|
|
95
|
+
class="flex items-center gap-2 rounded-lg bg-elevated px-3 py-2"
|
|
96
|
+
>
|
|
97
|
+
<UCheckbox
|
|
98
|
+
:model-value="
|
|
99
|
+
store.editListState.indeterminate
|
|
100
|
+
? 'indeterminate'
|
|
101
|
+
: store.editListState.value
|
|
102
|
+
"
|
|
103
|
+
:label="store.editListState.value ? 'Deselect all' : 'Select all'"
|
|
104
|
+
@update:model-value="store.editSelectAll()"
|
|
105
|
+
/>
|
|
106
|
+
<span class="text-sm text-muted">
|
|
107
|
+
{{ store.editList.length }} selected
|
|
108
|
+
</span>
|
|
109
|
+
<div class="flex-1" />
|
|
110
|
+
<UButton
|
|
111
|
+
icon="i-lucide-trash-2"
|
|
112
|
+
size="xs"
|
|
113
|
+
color="error"
|
|
114
|
+
variant="soft"
|
|
115
|
+
@click="store.deleteSelected()"
|
|
116
|
+
>
|
|
117
|
+
Delete selected
|
|
118
|
+
</UButton>
|
|
119
|
+
<UButton
|
|
120
|
+
icon="i-lucide-x"
|
|
121
|
+
size="xs"
|
|
122
|
+
variant="ghost"
|
|
123
|
+
color="neutral"
|
|
124
|
+
@click="store.editList = []"
|
|
125
|
+
/>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<!-- Loading skeleton -->
|
|
129
|
+
<div
|
|
130
|
+
v-if="store.loading"
|
|
131
|
+
class="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3"
|
|
132
|
+
>
|
|
133
|
+
<USkeleton v-for="n in 12" :key="n" class="aspect-square rounded-lg" />
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<!-- Empty state -->
|
|
137
|
+
<div
|
|
138
|
+
v-else-if="store.medias.length === 0"
|
|
139
|
+
class="flex flex-col items-center gap-3 py-16 text-center"
|
|
140
|
+
>
|
|
141
|
+
<UIcon name="i-lucide-image-off" class="size-12 text-dimmed" />
|
|
142
|
+
<p class="text-sm text-muted">No media found</p>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
<!-- Grid -->
|
|
146
|
+
<div
|
|
147
|
+
v-else
|
|
148
|
+
class="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3"
|
|
149
|
+
>
|
|
150
|
+
<div
|
|
151
|
+
v-for="media in store.medias"
|
|
152
|
+
:key="media.id"
|
|
153
|
+
class="group relative cursor-pointer overflow-hidden rounded-lg bg-elevated"
|
|
154
|
+
:class="{
|
|
155
|
+
'ring-2 ring-primary': isInSelection(media),
|
|
156
|
+
'ring-2 ring-primary ring-offset-1': store.editListSet.has(media.id),
|
|
157
|
+
}"
|
|
158
|
+
@click="onClickItem(media)"
|
|
159
|
+
>
|
|
160
|
+
<!-- Preview -->
|
|
161
|
+
<div class="aspect-square">
|
|
162
|
+
<MapoMediaPreview :media="media" size="lg" class="size-full" />
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
<!-- Hover overlay with filename -->
|
|
166
|
+
<div
|
|
167
|
+
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"
|
|
168
|
+
>
|
|
169
|
+
<p class="truncate text-[10px] text-white">
|
|
170
|
+
{{ media.title || media.file?.split("/").pop() }}
|
|
171
|
+
</p>
|
|
172
|
+
<p class="text-[9px] text-white/60">
|
|
173
|
+
{{ humanFileSize(media.size) }}
|
|
174
|
+
</p>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<!-- Selection checkmark (picker mode) -->
|
|
178
|
+
<div
|
|
179
|
+
v-if="isPickerMode && isInSelection(media)"
|
|
180
|
+
class="absolute right-1.5 top-1.5 flex size-5 items-center justify-center rounded-full bg-primary text-inverted"
|
|
181
|
+
>
|
|
182
|
+
<UIcon name="i-lucide-check" class="size-3" />
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<!-- Bulk checkbox (gallery mode, no selection) -->
|
|
186
|
+
<div
|
|
187
|
+
v-if="!isPickerMode"
|
|
188
|
+
class="absolute left-1.5 top-1.5 opacity-0 transition-opacity group-hover:opacity-100"
|
|
189
|
+
:class="{ '!opacity-100': store.editListSet.has(media.id) }"
|
|
190
|
+
@click.stop
|
|
191
|
+
>
|
|
192
|
+
<UCheckbox
|
|
193
|
+
:model-value="store.editListSet.has(media.id)"
|
|
194
|
+
@update:model-value="store.editSelect(media.id)"
|
|
195
|
+
/>
|
|
196
|
+
</div>
|
|
197
|
+
|
|
198
|
+
<!-- Edit button (gallery mode, visible on hover) -->
|
|
199
|
+
<div
|
|
200
|
+
v-if="!isPickerMode"
|
|
201
|
+
class="absolute right-1.5 top-1.5 opacity-0 transition-opacity group-hover:opacity-100"
|
|
202
|
+
>
|
|
203
|
+
<UButton
|
|
204
|
+
icon="i-lucide-pencil"
|
|
205
|
+
size="xs"
|
|
206
|
+
variant="solid"
|
|
207
|
+
color="neutral"
|
|
208
|
+
class="shadow"
|
|
209
|
+
@click.stop="store.openEditor(media)"
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<!-- Pagination -->
|
|
216
|
+
<div v-if="store.pages > 1" class="flex justify-center pt-2">
|
|
217
|
+
<!-- The backend paginator only exposes page/pages (no item count), so the
|
|
218
|
+
page count is mapped 1:1 with items-per-page=1. -->
|
|
219
|
+
<UPagination
|
|
220
|
+
:page="store.page"
|
|
221
|
+
:total="store.pages"
|
|
222
|
+
:items-per-page="1"
|
|
223
|
+
@update:page="store.getRoot({ page: $event })"
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
</template>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, onMounted, onUnmounted, watch } from "vue";
|
|
3
|
+
import { debounce } from "@mapomodule/utils";
|
|
4
|
+
import { useMediaStore } from "../stores/media.js";
|
|
5
|
+
import type { SelectMode } from "../types/media.js";
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(
|
|
8
|
+
defineProps<{
|
|
9
|
+
selectionMode?: SelectMode;
|
|
10
|
+
mime?: string | null;
|
|
11
|
+
noFolders?: boolean;
|
|
12
|
+
languages?: string[];
|
|
13
|
+
defaultLang?: string;
|
|
14
|
+
/** Pre-seed the picker selection (e.g. the field's current value). */
|
|
15
|
+
initialSelection?:
|
|
16
|
+
| import("../types/media.js").MediaItem
|
|
17
|
+
| import("../types/media.js").MediaItem[]
|
|
18
|
+
| null;
|
|
19
|
+
}>(),
|
|
20
|
+
{
|
|
21
|
+
selectionMode: "none",
|
|
22
|
+
mime: null,
|
|
23
|
+
noFolders: false,
|
|
24
|
+
languages: undefined,
|
|
25
|
+
defaultLang: undefined,
|
|
26
|
+
initialSelection: null,
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{
|
|
31
|
+
/** Emitted on every selection change in single/multi picker mode */
|
|
32
|
+
"update:selection": [
|
|
33
|
+
value:
|
|
34
|
+
| import("../types/media.js").MediaItem
|
|
35
|
+
| import("../types/media.js").MediaItem[]
|
|
36
|
+
| null,
|
|
37
|
+
];
|
|
38
|
+
}>();
|
|
39
|
+
|
|
40
|
+
const store = useMediaStore();
|
|
41
|
+
// string (not a union) because UTabs' v-model emits string | number
|
|
42
|
+
const activeTab = ref<string>("gallery");
|
|
43
|
+
const tabItems = [
|
|
44
|
+
{ label: "Gallery", icon: "i-lucide-images", value: "gallery" },
|
|
45
|
+
{ label: "Upload", icon: "i-lucide-upload-cloud", value: "upload" },
|
|
46
|
+
];
|
|
47
|
+
const searchValue = ref("");
|
|
48
|
+
const showFolders = ref(!props.noFolders);
|
|
49
|
+
|
|
50
|
+
// Searches span the whole library (`all: true`, legacy behavior); clearing the
|
|
51
|
+
// field drops back to the current folder scope.
|
|
52
|
+
const debouncedSearch = debounce((val: string) => {
|
|
53
|
+
store.getRoot({ page: 1, search: val, all: !!val });
|
|
54
|
+
}, 500);
|
|
55
|
+
|
|
56
|
+
watch(searchValue, (val) => debouncedSearch(val));
|
|
57
|
+
|
|
58
|
+
watch(
|
|
59
|
+
() => store.selection,
|
|
60
|
+
(sel) => {
|
|
61
|
+
if (props.selectionMode !== "none") {
|
|
62
|
+
emit("update:selection", sel);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
onMounted(async () => {
|
|
68
|
+
store.setSelectionMode(props.selectionMode);
|
|
69
|
+
if (props.initialSelection) store.setSelection(props.initialSelection);
|
|
70
|
+
// The mime prop is a hard constraint (picker fields): lock it so the
|
|
71
|
+
// folders panel cannot widen the filter past it.
|
|
72
|
+
if (props.mime) store.lockMimeType(props.mime);
|
|
73
|
+
// Detail fetches send language_code when a default language is provided
|
|
74
|
+
// (legacy parity: v1 passed $i18n.locale).
|
|
75
|
+
if (props.defaultLang) store.setLang(props.defaultLang);
|
|
76
|
+
await store.getRoot({ page: 1 });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
onUnmounted(() => {
|
|
80
|
+
store.reset();
|
|
81
|
+
});
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<div class="mapo-media-manager flex h-full overflow-hidden">
|
|
86
|
+
<!-- Folders sidebar -->
|
|
87
|
+
<div
|
|
88
|
+
v-if="showFolders"
|
|
89
|
+
class="w-48 shrink-0 border-r border-default bg-default"
|
|
90
|
+
>
|
|
91
|
+
<MapoMediaFolders />
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
<!-- Main area -->
|
|
95
|
+
<div class="flex min-w-0 flex-1 flex-col">
|
|
96
|
+
<!-- Top bar: breadcrumbs + search + tabs toggle -->
|
|
97
|
+
<div
|
|
98
|
+
class="flex items-center gap-3 border-b border-default bg-default px-4 py-2"
|
|
99
|
+
>
|
|
100
|
+
<!-- Toggle folders button -->
|
|
101
|
+
<UButton
|
|
102
|
+
v-if="!noFolders"
|
|
103
|
+
:icon="
|
|
104
|
+
showFolders
|
|
105
|
+
? 'i-lucide-panel-left-close'
|
|
106
|
+
: 'i-lucide-panel-left-open'
|
|
107
|
+
"
|
|
108
|
+
size="xs"
|
|
109
|
+
variant="ghost"
|
|
110
|
+
color="neutral"
|
|
111
|
+
@click="showFolders = !showFolders"
|
|
112
|
+
/>
|
|
113
|
+
|
|
114
|
+
<!-- Breadcrumbs -->
|
|
115
|
+
<MapoMediaBreadcrumbs class="flex-1" />
|
|
116
|
+
|
|
117
|
+
<!-- Search -->
|
|
118
|
+
<div v-if="activeTab === 'gallery'" class="w-48 shrink-0">
|
|
119
|
+
<UInput
|
|
120
|
+
v-model="searchValue"
|
|
121
|
+
size="xs"
|
|
122
|
+
placeholder="Search..."
|
|
123
|
+
icon="i-lucide-search"
|
|
124
|
+
:loading="store.loading"
|
|
125
|
+
/>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<!-- Refresh -->
|
|
129
|
+
<UButton
|
|
130
|
+
icon="i-lucide-refresh-cw"
|
|
131
|
+
size="xs"
|
|
132
|
+
variant="ghost"
|
|
133
|
+
color="neutral"
|
|
134
|
+
title="Refresh"
|
|
135
|
+
@click="store.getRoot()"
|
|
136
|
+
/>
|
|
137
|
+
|
|
138
|
+
<!-- Tab switcher -->
|
|
139
|
+
<UTabs
|
|
140
|
+
v-model="activeTab"
|
|
141
|
+
:items="tabItems"
|
|
142
|
+
:content="false"
|
|
143
|
+
size="xs"
|
|
144
|
+
color="neutral"
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<!-- Content -->
|
|
149
|
+
<div class="flex-1 overflow-y-auto p-4">
|
|
150
|
+
<MapoMediaGallery v-if="activeTab === 'gallery'" />
|
|
151
|
+
<MapoMediaUploader v-else @uploaded="activeTab = 'gallery'" />
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<!-- Custom actions (legacy parity: v1 exposed an `actions` card slot) -->
|
|
155
|
+
<div
|
|
156
|
+
v-if="$slots.actions"
|
|
157
|
+
class="flex items-center justify-end gap-2 border-t border-default px-4 py-2"
|
|
158
|
+
>
|
|
159
|
+
<slot name="actions" />
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<!-- Editor drawer (overlays from right, only in gallery mode, none-selection) -->
|
|
164
|
+
<MapoMediaEditor
|
|
165
|
+
v-if="activeTab === 'gallery'"
|
|
166
|
+
:languages="languages"
|
|
167
|
+
:default-lang="defaultLang"
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
</template>
|