@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,310 @@
1
+ <script setup>
2
+ import { ref, watch, computed } from "vue";
3
+ import { useRuntimeConfig } from "#app";
4
+ import {
5
+ humanFileSize,
6
+ deepClone,
7
+ getNestedValue,
8
+ setNestedValue
9
+ } from "@mapomodule/utils";
10
+ import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
11
+ import { useMediaStore } from "../stores/media.js";
12
+ defineProps({
13
+ languages: { type: Array, required: false },
14
+ defaultLang: { type: String, required: false }
15
+ });
16
+ const store = useMediaStore();
17
+ const runtimeConfig = useRuntimeConfig();
18
+ const permissionsModel = (runtimeConfig.public.mapoMedia ?? {}).permissionsModel ?? "media";
19
+ const { canChange, canDelete } = usePermissions();
20
+ const canEdit = computed(() => canChange(permissionsModel));
21
+ const canRemove = computed(() => canDelete(permissionsModel));
22
+ const editing = ref(false);
23
+ const saving = ref(false);
24
+ const newFile = ref(null);
25
+ const maintainUrl = ref(false);
26
+ const currentLang = ref("");
27
+ let editSnapshot = null;
28
+ const media = computed(() => store.editMedia);
29
+ watch(
30
+ () => store.editMedia?.id,
31
+ (id, oldId) => {
32
+ if (id != null && id !== oldId) {
33
+ editing.value = false;
34
+ newFile.value = null;
35
+ maintainUrl.value = false;
36
+ editSnapshot = null;
37
+ }
38
+ }
39
+ );
40
+ const metaRows = computed(() => {
41
+ if (!media.value) return [];
42
+ const m = media.value;
43
+ return [
44
+ { label: "File", value: m.file?.split("/").pop() ?? "", isUrl: false },
45
+ { label: "MIME", value: m.mime_type, isUrl: false },
46
+ {
47
+ label: "Size",
48
+ value: m.size ? humanFileSize(m.size) : "\u2014",
49
+ isUrl: false
50
+ },
51
+ { label: "Created", value: formatDate(m.created), isUrl: false },
52
+ { label: "URL", value: m.file, isUrl: true }
53
+ ];
54
+ });
55
+ const editFields = computed(() => {
56
+ const lang = currentLang.value;
57
+ const prefix = lang ? `translations.${lang}.` : "";
58
+ return [
59
+ { path: `${prefix}title`, label: "Title", type: "text" },
60
+ { path: `${prefix}alt_text`, label: "Alt text", type: "text" },
61
+ { path: `${prefix}description`, label: "Description", type: "textarea" }
62
+ ];
63
+ });
64
+ function getFieldValue(path) {
65
+ if (!media.value) return "";
66
+ return getNestedValue(
67
+ media.value,
68
+ path
69
+ ) ?? "";
70
+ }
71
+ function setFieldValue(path, value) {
72
+ if (!media.value) return;
73
+ store.editMedia = setNestedValue(
74
+ media.value,
75
+ path,
76
+ value
77
+ );
78
+ }
79
+ function startEditing() {
80
+ editSnapshot = media.value ? deepClone(media.value) : null;
81
+ editing.value = true;
82
+ }
83
+ function cancelEditing() {
84
+ if (editSnapshot) store.editMedia = editSnapshot;
85
+ editSnapshot = null;
86
+ editing.value = false;
87
+ newFile.value = null;
88
+ }
89
+ async function save() {
90
+ if (!media.value) return;
91
+ saving.value = true;
92
+ try {
93
+ const edited = { ...media.value };
94
+ if (newFile.value) {
95
+ await store.replaceFile(edited.id, newFile.value, maintainUrl.value);
96
+ }
97
+ await store.updateMedia(edited);
98
+ editSnapshot = null;
99
+ editing.value = false;
100
+ newFile.value = null;
101
+ maintainUrl.value = false;
102
+ } finally {
103
+ saving.value = false;
104
+ }
105
+ }
106
+ function formatDate(dateStr) {
107
+ if (!dateStr) return "\u2014";
108
+ return new Date(dateStr).toLocaleDateString(void 0, {
109
+ day: "2-digit",
110
+ month: "short",
111
+ year: "numeric"
112
+ });
113
+ }
114
+ </script>
115
+
116
+ <template>
117
+ <USlideover
118
+ :open="!!media"
119
+ side="right"
120
+ class="mapo-media-editor"
121
+ :ui="{ content: 'max-w-md w-full' }"
122
+ @update:open="!$event && store.closeEditor()"
123
+ >
124
+ <!-- #content: the default slot is the trigger in Nuxt UI v4 -->
125
+ <template #content>
126
+ <div v-if="media" class="flex h-full flex-col">
127
+ <!-- Header -->
128
+ <div class="flex items-center gap-2 border-b border-default px-4 py-3">
129
+ <UButton
130
+ icon="i-lucide-x"
131
+ variant="ghost"
132
+ color="neutral"
133
+ size="xs"
134
+ @click="store.closeEditor()"
135
+ />
136
+ <p class="flex-1 truncate text-sm font-semibold text-highlighted">
137
+ {{ media.title || media.file?.split("/").pop() }}
138
+ </p>
139
+ <UButton
140
+ v-if="!editing && canEdit"
141
+ icon="i-lucide-pencil"
142
+ size="xs"
143
+ variant="soft"
144
+ color="neutral"
145
+ @click="startEditing"
146
+ >
147
+ Edit
148
+ </UButton>
149
+ <UButton
150
+ icon="i-lucide-external-link"
151
+ size="xs"
152
+ variant="ghost"
153
+ color="neutral"
154
+ :href="media.file"
155
+ target="_blank"
156
+ title="Open in new tab"
157
+ />
158
+ </div>
159
+
160
+ <div class="flex-1 overflow-y-auto">
161
+ <!-- Preview -->
162
+ <div class="flex justify-center bg-elevated p-4">
163
+ <MapoMediaPreview :media="media" size="lg" contain />
164
+ </div>
165
+
166
+ <!-- Metadata table -->
167
+ <div class="border-b border-default px-4 py-3">
168
+ <p
169
+ class="mb-2 text-xs font-semibold uppercase tracking-wide text-dimmed"
170
+ >
171
+ Info
172
+ </p>
173
+ <dl class="space-y-1">
174
+ <div
175
+ v-for="row in metaRows"
176
+ :key="row.label"
177
+ class="flex gap-2 text-xs"
178
+ >
179
+ <dt class="w-24 shrink-0 text-dimmed">
180
+ {{ row.label }}
181
+ </dt>
182
+ <dd class="flex-1 truncate font-mono text-default">
183
+ <a
184
+ v-if="row.isUrl"
185
+ :href="row.value"
186
+ target="_blank"
187
+ rel="noopener"
188
+ class="text-primary hover:underline"
189
+ >{{ row.value }}</a
190
+ >
191
+ <span v-else>{{ row.value }}</span>
192
+ </dd>
193
+ </div>
194
+ </dl>
195
+
196
+ <!-- Linked models (Camomilla `links`) -->
197
+ <div v-if="media.links?.length" class="mt-3">
198
+ <p
199
+ class="mb-1 text-xs font-semibold uppercase tracking-wide text-dimmed"
200
+ >
201
+ Linked models
202
+ </p>
203
+ <ul class="space-y-0.5 text-xs text-muted">
204
+ <li
205
+ v-for="link in media.links"
206
+ :key="`${link.model}-${link.id}`"
207
+ >
208
+ <b>{{ link.model }} (id: {{ link.id }})</b> — {{ link.name }}
209
+ </li>
210
+ </ul>
211
+ </div>
212
+ </div>
213
+
214
+ <!-- Edit form (shown when editing) -->
215
+ <div v-if="editing" class="space-y-4 px-4 py-3">
216
+ <!-- Lang switch -->
217
+ <UFieldGroup v-if="languages && languages.length > 1" size="xs">
218
+ <UButton
219
+ :variant="currentLang === '' ? 'solid' : 'outline'"
220
+ color="neutral"
221
+ @click="currentLang = ''"
222
+ >
223
+ Default
224
+ </UButton>
225
+ <UButton
226
+ v-for="lang in languages"
227
+ :key="lang"
228
+ :variant="currentLang === lang ? 'solid' : 'outline'"
229
+ color="neutral"
230
+ @click="currentLang = lang"
231
+ >
232
+ {{ lang.toUpperCase() }}
233
+ </UButton>
234
+ </UFieldGroup>
235
+
236
+ <!-- Field inputs -->
237
+ <div class="space-y-3">
238
+ <UFormField
239
+ v-for="field in editFields"
240
+ :key="field.path"
241
+ :label="field.label"
242
+ size="sm"
243
+ >
244
+ <UTextarea
245
+ v-if="field.type === 'textarea'"
246
+ :model-value="getFieldValue(field.path)"
247
+ :rows="2"
248
+ class="w-full"
249
+ @update:model-value="setFieldValue(field.path, $event)"
250
+ />
251
+ <UInput
252
+ v-else
253
+ :model-value="getFieldValue(field.path)"
254
+ class="w-full"
255
+ @update:model-value="setFieldValue(field.path, $event)"
256
+ />
257
+ </UFormField>
258
+ </div>
259
+
260
+ <!-- File replace -->
261
+ <MapoMediaFileChanger
262
+ :media="media"
263
+ @update:file="newFile = $event"
264
+ @update:maintain-url="maintainUrl = $event"
265
+ />
266
+ </div>
267
+ </div>
268
+
269
+ <!-- Footer -->
270
+ <div
271
+ class="flex items-center justify-between gap-2 border-t border-default px-4 py-3"
272
+ >
273
+ <UButton
274
+ v-if="canRemove"
275
+ icon="i-lucide-trash-2"
276
+ size="sm"
277
+ variant="soft"
278
+ color="error"
279
+ @click="store.deleteMedia(media)"
280
+ >
281
+ Delete
282
+ </UButton>
283
+ <span v-else />
284
+
285
+ <div class="flex gap-2">
286
+ <UButton
287
+ v-if="editing"
288
+ size="sm"
289
+ variant="ghost"
290
+ color="neutral"
291
+ @click="cancelEditing"
292
+ >
293
+ Cancel
294
+ </UButton>
295
+ <UButton
296
+ v-if="editing"
297
+ size="sm"
298
+ color="primary"
299
+ :loading="saving"
300
+ icon="i-lucide-save"
301
+ @click="save"
302
+ >
303
+ Save
304
+ </UButton>
305
+ </div>
306
+ </div>
307
+ </div>
308
+ </template>
309
+ </USlideover>
310
+ </template>
@@ -0,0 +1,8 @@
1
+ type __VLS_Props = {
2
+ languages?: string[];
3
+ defaultLang?: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
8
+ //# sourceMappingURL=MapoMediaEditor.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoMediaEditor.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaEditor.vue"],"names":[],"mappings":"AAmWA,KAAK,WAAW,GAAG;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AA6vBF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -0,0 +1,108 @@
1
+ <script setup>
2
+ import { ref, computed, onUnmounted } from "vue";
3
+ import { humanFileSize } from "@mapomodule/utils";
4
+ const props = defineProps({
5
+ media: { type: null, required: true },
6
+ accept: { type: String, required: false }
7
+ });
8
+ const emit = defineEmits(["update:file", "update:maintainUrl"]);
9
+ const newFile = ref(null);
10
+ const maintainUrl = ref(false);
11
+ const previewUrl = ref(null);
12
+ const isImage = computed(
13
+ () => newFile.value ? newFile.value.type.startsWith("image/") : props.media.mime_type?.startsWith("image/")
14
+ );
15
+ const acceptTypes = computed(() => {
16
+ if (props.accept) return props.accept;
17
+ const family = props.media.mime_type?.split("/")[0];
18
+ return family && ["image", "video", "audio"].includes(family) ? `${family}/*` : "*/*";
19
+ });
20
+ function revokePreview() {
21
+ if (previewUrl.value) URL.revokeObjectURL(previewUrl.value);
22
+ previewUrl.value = null;
23
+ }
24
+ function onFileSelected(files) {
25
+ const file = files[0] ?? null;
26
+ newFile.value = file;
27
+ emit("update:file", file);
28
+ revokePreview();
29
+ if (file && file.type.startsWith("image/")) {
30
+ previewUrl.value = URL.createObjectURL(file);
31
+ }
32
+ }
33
+ function clearFile() {
34
+ newFile.value = null;
35
+ revokePreview();
36
+ emit("update:file", null);
37
+ }
38
+ onUnmounted(revokePreview);
39
+ function onMaintainUrlChange(v) {
40
+ const checked = v === true;
41
+ maintainUrl.value = checked;
42
+ emit("update:maintainUrl", checked);
43
+ }
44
+ </script>
45
+
46
+ <template>
47
+ <div class="mapo-media-file-changer space-y-2">
48
+ <p class="text-xs font-medium text-muted">Replace file</p>
49
+
50
+ <MapoDropArea
51
+ :accept="acceptTypes"
52
+ :multiple="false"
53
+ @files="onFileSelected"
54
+ >
55
+ <template #default="{ triggerPick, isDragging }">
56
+ <div
57
+ class="flex cursor-pointer items-center gap-3 rounded-lg border border-dashed p-3 transition-colors"
58
+ :class="
59
+ isDragging ? 'border-primary bg-primary/10' : 'border-default hover:border-accented'
60
+ "
61
+ @click="triggerPick"
62
+ >
63
+ <!-- New file preview -->
64
+ <div v-if="newFile" class="flex items-center gap-2 flex-1">
65
+ <img
66
+ v-if="isImage && previewUrl"
67
+ :src="previewUrl"
68
+ class="size-12 rounded object-cover"
69
+ alt=""
70
+ />
71
+ <UIcon v-else name="i-lucide-file" class="size-8 text-dimmed" />
72
+ <div class="flex-1 min-w-0">
73
+ <p class="truncate text-xs font-medium">
74
+ {{ newFile.name }}
75
+ </p>
76
+ <p class="text-xs text-dimmed">
77
+ {{ humanFileSize(newFile.size) }}
78
+ </p>
79
+ </div>
80
+ <UButton
81
+ icon="i-lucide-x"
82
+ size="xs"
83
+ variant="ghost"
84
+ color="neutral"
85
+ @click.stop="clearFile"
86
+ />
87
+ </div>
88
+
89
+ <!-- Placeholder -->
90
+ <div
91
+ v-else
92
+ class="flex flex-1 items-center gap-2 text-sm text-dimmed"
93
+ >
94
+ <UIcon name="i-lucide-upload" class="size-5" />
95
+ <span>Drag or click to choose a file</span>
96
+ </div>
97
+ </div>
98
+ </template>
99
+ </MapoDropArea>
100
+
101
+ <UCheckbox
102
+ v-if="newFile"
103
+ :model-value="maintainUrl"
104
+ label="Keep current URL"
105
+ @update:model-value="onMaintainUrlChange"
106
+ />
107
+ </div>
108
+ </template>
@@ -0,0 +1,15 @@
1
+ import type { MediaItem } from "../types/media.js";
2
+ type __VLS_Props = {
3
+ media: MediaItem;
4
+ accept?: string;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ "update:file": (file: File | null) => any;
8
+ "update:maintainUrl": (value: boolean) => any;
9
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
10
+ "onUpdate:file"?: ((file: File | null) => any) | undefined;
11
+ "onUpdate:maintainUrl"?: ((value: boolean) => any) | undefined;
12
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const _default: typeof __VLS_export;
14
+ export default _default;
15
+ //# sourceMappingURL=MapoMediaFileChanger.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoMediaFileChanger.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaFileChanger.vue"],"names":[],"mappings":"AAwIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAoRF,QAAA,MAAM,YAAY;;;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -0,0 +1,198 @@
1
+ <script setup>
2
+ import { ref, computed } from "vue";
3
+ import { useMediaStore } from "../stores/media.js";
4
+ const store = useMediaStore();
5
+ const editingFolder = ref(null);
6
+ const folderName = ref("");
7
+ const saving = ref(false);
8
+ const ALL_MIME_FILTERS = [
9
+ { label: "All", icon: "i-lucide-layers", mime: null },
10
+ { label: "Images", icon: "i-lucide-image", mime: "image/*" },
11
+ { label: "Videos", icon: "i-lucide-film", mime: "video/*" },
12
+ { label: "Audio", icon: "i-lucide-music", mime: "audio/*" },
13
+ // Family filter (legacy parity): pdf, zip, office docs — not just pdf.
14
+ { label: "Documents", icon: "i-lucide-file-text", mime: "application/*" }
15
+ ];
16
+ const mimeFilters = computed(
17
+ () => store.lockedMime ? ALL_MIME_FILTERS.filter((f) => f.mime === store.lockedMime) : ALL_MIME_FILTERS
18
+ );
19
+ function startCreate() {
20
+ editingFolder.value = {};
21
+ folderName.value = "";
22
+ }
23
+ function startEdit(folder) {
24
+ editingFolder.value = { ...folder };
25
+ folderName.value = folder.name;
26
+ }
27
+ function cancelEdit() {
28
+ editingFolder.value = null;
29
+ folderName.value = "";
30
+ }
31
+ async function saveFolder() {
32
+ if (!folderName.value.trim()) return;
33
+ saving.value = true;
34
+ try {
35
+ await store.updateOrCreateFolder({
36
+ ...editingFolder.value,
37
+ name: folderName.value.trim()
38
+ });
39
+ cancelEdit();
40
+ } finally {
41
+ saving.value = false;
42
+ }
43
+ }
44
+ function selectMime(mime) {
45
+ store.setMimeType(mime);
46
+ store.getRoot({ page: 1, all: !!mime });
47
+ }
48
+ function onNameKeyup(event) {
49
+ if (event.key === "Enter") saveFolder();
50
+ else if (event.key === "Escape") cancelEdit();
51
+ }
52
+ </script>
53
+
54
+ <template>
55
+ <div class="mapo-media-folders flex h-full flex-col gap-2 py-2">
56
+ <!-- MIME filters -->
57
+ <div class="space-y-0.5 px-2">
58
+ <p
59
+ class="mb-1 px-1 text-xs font-semibold uppercase tracking-wide text-dimmed"
60
+ >
61
+ Type
62
+ </p>
63
+ <UButton
64
+ v-for="f in mimeFilters"
65
+ :key="f.mime ?? 'all'"
66
+ variant="ghost"
67
+ color="neutral"
68
+ size="xs"
69
+ block
70
+ :icon="f.icon"
71
+ class="justify-start"
72
+ :class="{ 'bg-elevated': store.mimeType === f.mime }"
73
+ @click="selectMime(f.mime)"
74
+ >
75
+ {{ f.label }}
76
+ </UButton>
77
+ </div>
78
+
79
+ <USeparator />
80
+
81
+ <!-- Folders header -->
82
+ <div class="flex items-center justify-between px-3">
83
+ <p class="text-xs font-semibold uppercase tracking-wide text-dimmed">
84
+ Folders
85
+ </p>
86
+ <UButton
87
+ icon="i-lucide-folder-plus"
88
+ size="xs"
89
+ variant="ghost"
90
+ color="neutral"
91
+ title="New folder"
92
+ @click="startCreate"
93
+ />
94
+ </div>
95
+
96
+ <!-- New folder input -->
97
+ <div v-if="editingFolder && !editingFolder.id" class="px-2">
98
+ <UInput
99
+ v-model="folderName"
100
+ size="xs"
101
+ placeholder="Folder name"
102
+ autofocus
103
+ @keyup="onNameKeyup"
104
+ >
105
+ <template #trailing>
106
+ <UButton
107
+ icon="i-lucide-check"
108
+ size="xs"
109
+ variant="ghost"
110
+ color="primary"
111
+ :loading="saving"
112
+ @click="saveFolder"
113
+ />
114
+ </template>
115
+ </UInput>
116
+ </div>
117
+
118
+ <!-- Folder list -->
119
+ <div class="flex-1 overflow-y-auto px-2">
120
+ <div v-for="folder in store.folders" :key="folder.id">
121
+ <!-- Editing this folder -->
122
+ <UInput
123
+ v-if="editingFolder?.id === folder.id"
124
+ v-model="folderName"
125
+ size="xs"
126
+ autofocus
127
+ @keyup="onNameKeyup"
128
+ >
129
+ <template #trailing>
130
+ <UButton
131
+ icon="i-lucide-check"
132
+ size="xs"
133
+ variant="ghost"
134
+ color="primary"
135
+ :loading="saving"
136
+ @click="saveFolder"
137
+ />
138
+ </template>
139
+ </UInput>
140
+
141
+ <!-- Folder row -->
142
+ <div
143
+ v-else
144
+ class="group flex items-center gap-1 rounded px-1 py-1 hover:bg-elevated"
145
+ >
146
+ <UButton
147
+ variant="ghost"
148
+ color="neutral"
149
+ size="xs"
150
+ icon="i-lucide-folder"
151
+ class="flex-1 justify-start truncate"
152
+ @click="store.navigateToFolder(folder)"
153
+ >
154
+ {{ folder.name }}
155
+ </UButton>
156
+ <div class="hidden items-center gap-0.5 group-hover:flex">
157
+ <UButton
158
+ icon="i-lucide-pencil"
159
+ size="xs"
160
+ variant="ghost"
161
+ color="neutral"
162
+ @click.stop="startEdit(folder)"
163
+ />
164
+ <UButton
165
+ icon="i-lucide-trash-2"
166
+ size="xs"
167
+ variant="ghost"
168
+ color="error"
169
+ @click.stop="store.deleteFolder(folder)"
170
+ />
171
+ </div>
172
+ </div>
173
+ </div>
174
+
175
+ <p
176
+ v-if="store.folders.length === 0"
177
+ class="px-2 py-3 text-xs text-dimmed italic"
178
+ >
179
+ No folders
180
+ </p>
181
+ </div>
182
+
183
+ <!-- Back -->
184
+ <div v-if="store.parentFolder" class="border-t border-default px-2 pt-2">
185
+ <UButton
186
+ icon="i-lucide-arrow-left"
187
+ size="xs"
188
+ variant="ghost"
189
+ color="neutral"
190
+ block
191
+ class="justify-start"
192
+ @click="store.navigateToFolder(null)"
193
+ >
194
+ Back to root
195
+ </UButton>
196
+ </div>
197
+ </div>
198
+ </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=MapoMediaFolders.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoMediaFolders.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoMediaFolders.vue"],"names":[],"mappings":"AAivBA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}