@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,266 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, computed, onUnmounted } from "vue";
|
|
3
|
+
import { humanFileSize } from "@mapomodule/utils";
|
|
4
|
+
import { useMediaStore } from "../stores/media.js";
|
|
5
|
+
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
6
|
+
import { useRuntimeConfig } from "#app";
|
|
7
|
+
const ROOT_FOLDER = -1;
|
|
8
|
+
const emit = defineEmits(["uploaded"]);
|
|
9
|
+
const store = useMediaStore();
|
|
10
|
+
const snack = useSnackStore();
|
|
11
|
+
const config = useRuntimeConfig();
|
|
12
|
+
const mediaConfig = config.public.mapoMedia ?? {};
|
|
13
|
+
const MAX_IMAGE = (mediaConfig.maxImageSize ?? 10) * 1024 * 1024;
|
|
14
|
+
const MAX_VIDEO = (mediaConfig.maxVideoSize ?? 100) * 1024 * 1024;
|
|
15
|
+
const MAX_DEFAULT = (mediaConfig.maxDefaultSize ?? 10) * 1024 * 1024;
|
|
16
|
+
const entries = ref([]);
|
|
17
|
+
const uploading = ref(false);
|
|
18
|
+
const canUpload = computed(
|
|
19
|
+
() => entries.value.length > 0 && entries.value.some((e) => e.status === "pending")
|
|
20
|
+
);
|
|
21
|
+
const pendingCount = computed(
|
|
22
|
+
() => entries.value.filter((e) => e.status === "pending").length
|
|
23
|
+
);
|
|
24
|
+
const folderOptions = computed(() => [
|
|
25
|
+
{
|
|
26
|
+
label: store.parentFolder?.path ?? "/",
|
|
27
|
+
value: store.parentFolder?.id ?? ROOT_FOLDER
|
|
28
|
+
},
|
|
29
|
+
...store.folders.map((f) => ({ label: f.path ?? f.name, value: f.id }))
|
|
30
|
+
]);
|
|
31
|
+
function onFiles(files) {
|
|
32
|
+
for (const file of files) {
|
|
33
|
+
const limit = file.type.startsWith("image/") ? MAX_IMAGE : file.type.startsWith("video/") ? MAX_VIDEO : MAX_DEFAULT;
|
|
34
|
+
if (file.size > limit) {
|
|
35
|
+
snack.show(
|
|
36
|
+
`File "${file.name}" too large (max ${(limit / (1024 * 1024)).toFixed(0)} MB)`,
|
|
37
|
+
"error"
|
|
38
|
+
);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const previewUrl = file.type.startsWith("image/") ? URL.createObjectURL(file) : void 0;
|
|
42
|
+
const baseName = file.name.replace(/\.[^.]+$/, "");
|
|
43
|
+
entries.value.push({
|
|
44
|
+
file,
|
|
45
|
+
title: baseName,
|
|
46
|
+
alt_text: baseName,
|
|
47
|
+
description: "",
|
|
48
|
+
folder: store.parentFolder?.id ?? ROOT_FOLDER,
|
|
49
|
+
progress: 0,
|
|
50
|
+
status: "pending",
|
|
51
|
+
previewUrl
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function remove(index) {
|
|
56
|
+
const entry = entries.value[index];
|
|
57
|
+
if (entry?.previewUrl) URL.revokeObjectURL(entry.previewUrl);
|
|
58
|
+
entries.value.splice(index, 1);
|
|
59
|
+
}
|
|
60
|
+
async function upload() {
|
|
61
|
+
uploading.value = true;
|
|
62
|
+
let successCount = 0;
|
|
63
|
+
for (const entry of entries.value) {
|
|
64
|
+
if (entry.status !== "pending") continue;
|
|
65
|
+
entry.status = "uploading";
|
|
66
|
+
entry.progress = 0;
|
|
67
|
+
const payload = {
|
|
68
|
+
file: entry.file,
|
|
69
|
+
title: entry.title || void 0,
|
|
70
|
+
alt_text: entry.alt_text || void 0,
|
|
71
|
+
description: entry.description || void 0,
|
|
72
|
+
folder: entry.folder === ROOT_FOLDER ? null : entry.folder
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
await store.uploadMedia(payload, (pct) => {
|
|
76
|
+
entry.progress = pct;
|
|
77
|
+
});
|
|
78
|
+
entry.status = "done";
|
|
79
|
+
entry.progress = 100;
|
|
80
|
+
successCount++;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
entry.status = "error";
|
|
83
|
+
entry.error = err instanceof Error ? err.message : "Upload failed";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
uploading.value = false;
|
|
87
|
+
if (successCount > 0) {
|
|
88
|
+
snack.show(
|
|
89
|
+
`${successCount} ${successCount === 1 ? "file" : "files"} uploaded successfully`,
|
|
90
|
+
"success"
|
|
91
|
+
);
|
|
92
|
+
await store.getRoot({ page: 1 });
|
|
93
|
+
entries.value = entries.value.filter((e) => e.status !== "done");
|
|
94
|
+
emit("uploaded");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function clearAll() {
|
|
98
|
+
entries.value.forEach((e) => {
|
|
99
|
+
if (e.previewUrl) URL.revokeObjectURL(e.previewUrl);
|
|
100
|
+
});
|
|
101
|
+
entries.value = [];
|
|
102
|
+
}
|
|
103
|
+
onUnmounted(clearAll);
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<template>
|
|
107
|
+
<div class="mapo-media-uploader space-y-4">
|
|
108
|
+
<!-- Drop zone -->
|
|
109
|
+
<MapoDropArea accept="*/*" multiple :disabled="uploading" @files="onFiles">
|
|
110
|
+
<template #default="{ triggerPick, isDragging }">
|
|
111
|
+
<div
|
|
112
|
+
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"
|
|
113
|
+
:class="
|
|
114
|
+
isDragging ? 'border-primary bg-primary/10' : 'border-default hover:border-accented'
|
|
115
|
+
"
|
|
116
|
+
@click="triggerPick"
|
|
117
|
+
>
|
|
118
|
+
<UIcon name="i-lucide-upload-cloud" class="size-10 text-dimmed" />
|
|
119
|
+
<div class="text-center">
|
|
120
|
+
<p class="text-sm font-medium text-muted">
|
|
121
|
+
Drag files here or
|
|
122
|
+
<span class="text-primary">browse</span>
|
|
123
|
+
</p>
|
|
124
|
+
<p class="mt-0.5 text-xs text-dimmed">
|
|
125
|
+
Images up to {{ (MAX_IMAGE / (1024 * 1024)).toFixed(0) }} MB ·
|
|
126
|
+
Videos up to {{ (MAX_VIDEO / (1024 * 1024)).toFixed(0) }} MB
|
|
127
|
+
</p>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
</template>
|
|
131
|
+
</MapoDropArea>
|
|
132
|
+
|
|
133
|
+
<!-- File list -->
|
|
134
|
+
<div v-if="entries.length > 0" class="space-y-2">
|
|
135
|
+
<div class="flex items-center justify-between">
|
|
136
|
+
<p class="text-xs font-medium text-muted">
|
|
137
|
+
{{ entries.length }}
|
|
138
|
+
{{ entries.length === 1 ? "file" : "files" }} selected
|
|
139
|
+
</p>
|
|
140
|
+
<UButton
|
|
141
|
+
v-if="!uploading"
|
|
142
|
+
size="xs"
|
|
143
|
+
variant="ghost"
|
|
144
|
+
color="neutral"
|
|
145
|
+
icon="i-lucide-x"
|
|
146
|
+
@click="clearAll"
|
|
147
|
+
>
|
|
148
|
+
Clear
|
|
149
|
+
</UButton>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<div class="space-y-2 max-h-96 overflow-y-auto pr-1">
|
|
153
|
+
<div
|
|
154
|
+
v-for="(entry, i) in entries"
|
|
155
|
+
:key="i"
|
|
156
|
+
class="rounded-lg border p-3 transition-colors"
|
|
157
|
+
:class="{
|
|
158
|
+
'border-success/40 bg-success/10': entry.status === 'done',
|
|
159
|
+
'border-error/40 bg-error/10': entry.status === 'error',
|
|
160
|
+
'border-default': entry.status === 'pending' || entry.status === 'uploading'
|
|
161
|
+
}"
|
|
162
|
+
>
|
|
163
|
+
<div class="flex items-start gap-3">
|
|
164
|
+
<!-- Preview -->
|
|
165
|
+
<div class="size-12 shrink-0 overflow-hidden rounded bg-elevated">
|
|
166
|
+
<img
|
|
167
|
+
v-if="entry.previewUrl"
|
|
168
|
+
:src="entry.previewUrl"
|
|
169
|
+
class="size-full object-cover"
|
|
170
|
+
alt=""
|
|
171
|
+
/>
|
|
172
|
+
<div v-else class="flex size-full items-center justify-center">
|
|
173
|
+
<UIcon name="i-lucide-file" class="size-6 text-dimmed" />
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<div class="flex-1 min-w-0 space-y-1.5">
|
|
178
|
+
<!-- Filename + size -->
|
|
179
|
+
<div class="flex items-center gap-2">
|
|
180
|
+
<span class="truncate text-xs font-medium text-default">
|
|
181
|
+
{{ entry.file.name }}
|
|
182
|
+
</span>
|
|
183
|
+
<span class="shrink-0 text-xs text-dimmed">
|
|
184
|
+
{{ humanFileSize(entry.file.size) }}
|
|
185
|
+
</span>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<!-- Metadata inputs (only for pending) -->
|
|
189
|
+
<div
|
|
190
|
+
v-if="entry.status === 'pending'"
|
|
191
|
+
class="grid grid-cols-2 gap-1.5"
|
|
192
|
+
>
|
|
193
|
+
<UInput v-model="entry.title" size="xs" placeholder="Title" />
|
|
194
|
+
<UInput
|
|
195
|
+
v-model="entry.alt_text"
|
|
196
|
+
size="xs"
|
|
197
|
+
placeholder="Alt text"
|
|
198
|
+
/>
|
|
199
|
+
<UInput
|
|
200
|
+
v-model="entry.description"
|
|
201
|
+
size="xs"
|
|
202
|
+
placeholder="Description"
|
|
203
|
+
/>
|
|
204
|
+
<USelect
|
|
205
|
+
v-model="entry.folder"
|
|
206
|
+
:items="folderOptions"
|
|
207
|
+
size="xs"
|
|
208
|
+
placeholder="Folder"
|
|
209
|
+
/>
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<!-- Progress bar -->
|
|
213
|
+
<div v-if="entry.status === 'uploading'" class="space-y-0.5">
|
|
214
|
+
<UProgress :model-value="entry.progress" size="xs" />
|
|
215
|
+
<p class="text-right text-xs text-dimmed">
|
|
216
|
+
{{ entry.progress }}%
|
|
217
|
+
</p>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<!-- Status badges -->
|
|
221
|
+
<div
|
|
222
|
+
v-if="entry.status === 'done'"
|
|
223
|
+
class="flex items-center gap-1 text-success"
|
|
224
|
+
>
|
|
225
|
+
<UIcon name="i-lucide-check-circle" class="size-3.5" />
|
|
226
|
+
<span class="text-xs">Uploaded</span>
|
|
227
|
+
</div>
|
|
228
|
+
<div
|
|
229
|
+
v-if="entry.status === 'error'"
|
|
230
|
+
class="flex items-center gap-1 text-error"
|
|
231
|
+
>
|
|
232
|
+
<UIcon name="i-lucide-alert-circle" class="size-3.5" />
|
|
233
|
+
<span class="text-xs">{{ entry.error }}</span>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<!-- Remove -->
|
|
238
|
+
<UButton
|
|
239
|
+
v-if="
|
|
240
|
+
!uploading || entry.status === 'done' || entry.status === 'error'
|
|
241
|
+
"
|
|
242
|
+
icon="i-lucide-x"
|
|
243
|
+
size="xs"
|
|
244
|
+
variant="ghost"
|
|
245
|
+
color="neutral"
|
|
246
|
+
@click="remove(i)"
|
|
247
|
+
/>
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
|
|
252
|
+
<!-- Upload CTA -->
|
|
253
|
+
<div class="flex justify-end pt-2">
|
|
254
|
+
<UButton
|
|
255
|
+
icon="i-lucide-upload"
|
|
256
|
+
:loading="uploading"
|
|
257
|
+
:disabled="!canUpload"
|
|
258
|
+
color="primary"
|
|
259
|
+
@click="upload"
|
|
260
|
+
>
|
|
261
|
+
Upload {{ pendingCount }} {{ pendingCount === 1 ? "file" : "files" }}
|
|
262
|
+
</UButton>
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
</template>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
2
|
+
uploaded: () => any;
|
|
3
|
+
}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
|
|
4
|
+
onUploaded?: (() => any) | undefined;
|
|
5
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
6
|
+
declare const _default: typeof __VLS_export;
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=MapoMediaUploader.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoMediaUploader.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaUploader.vue"],"names":[],"mappings":"AAy9BA,QAAA,MAAM,YAAY;;;;iFAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MediaAdapter } from "../types/media.js";
|
|
2
|
+
declare module "#app" {
|
|
3
|
+
interface NuxtApp {
|
|
4
|
+
$mapoMediaAdapter: MediaAdapter;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
declare module "vue" {
|
|
8
|
+
interface ComponentCustomProperties {
|
|
9
|
+
$mapoMediaAdapter: MediaAdapter;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare const _default: import("#app").Plugin<{
|
|
13
|
+
mapoMediaAdapter: Required<MediaAdapter>;
|
|
14
|
+
}> & import("#app").ObjectPlugin<{
|
|
15
|
+
mapoMediaAdapter: Required<MediaAdapter>;
|
|
16
|
+
}>;
|
|
17
|
+
export default _default;
|
|
18
|
+
//# sourceMappingURL=media-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-adapter.d.ts","sourceRoot":"","sources":["../../../src/runtime/plugins/media-adapter.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAU,OAAO;QACf,iBAAiB,EAAE,YAAY,CAAC;KACjC;CACF;AAED,OAAO,QAAQ,KAAK,CAAC;IACnB,UAAU,yBAAyB;QACjC,iBAAiB,EAAE,YAAY,CAAC;KACjC;CACF;;;;;;AAED,wBAIG"}
|