@mapomodule/uikit 2.0.0-beta.17 → 2.0.0-beta.18

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 (121) hide show
  1. package/dist/__tests__/MapoMediaEditor.component.test.d.ts +2 -0
  2. package/dist/__tests__/MapoMediaEditor.component.test.d.ts.map +1 -0
  3. package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts +2 -0
  4. package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts.map +1 -0
  5. package/dist/__tests__/MapoMediaFolders.component.test.d.ts +2 -0
  6. package/dist/__tests__/MapoMediaFolders.component.test.d.ts.map +1 -0
  7. package/dist/__tests__/MapoMediaGallery.component.test.d.ts +2 -0
  8. package/dist/__tests__/MapoMediaGallery.component.test.d.ts.map +1 -0
  9. package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts +2 -0
  10. package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts.map +1 -0
  11. package/dist/__tests__/MapoMenuManager.component.test.d.ts +2 -0
  12. package/dist/__tests__/MapoMenuManager.component.test.d.ts.map +1 -0
  13. package/dist/__tests__/mediaDrag.test.d.ts +2 -0
  14. package/dist/__tests__/mediaDrag.test.d.ts.map +1 -0
  15. package/dist/__tests__/mediaFolders.test.d.ts +2 -0
  16. package/dist/__tests__/mediaFolders.test.d.ts.map +1 -0
  17. package/dist/__tests__/mediaMetadata.test.d.ts +2 -0
  18. package/dist/__tests__/mediaMetadata.test.d.ts.map +1 -0
  19. package/dist/__tests__/mediaStore.test.d.ts +2 -0
  20. package/dist/__tests__/mediaStore.test.d.ts.map +1 -0
  21. package/dist/__tests__/mediaUrl.test.d.ts +2 -0
  22. package/dist/__tests__/mediaUrl.test.d.ts.map +1 -0
  23. package/dist/index.d.mts +1 -0
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/module.d.mts +17 -0
  27. package/dist/module.d.ts +16 -0
  28. package/dist/module.d.ts.map +1 -1
  29. package/dist/module.json +1 -1
  30. package/dist/module.mjs +4 -0
  31. package/dist/runtime/adapters/defaultMediaAdapter.d.ts +1 -0
  32. package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -1
  33. package/dist/runtime/adapters/defaultMediaAdapter.js +6 -1
  34. package/dist/runtime/components/MapoDetail.vue +9 -5
  35. package/dist/runtime/components/MapoDetail.vue.d.ts +3 -3
  36. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
  37. package/dist/runtime/components/MapoDropArea.vue +17 -6
  38. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
  39. package/dist/runtime/components/MapoListQuickEdit.vue +7 -1
  40. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
  41. package/dist/runtime/components/MapoMediaEditor.vue +94 -38
  42. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +4 -0
  43. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
  44. package/dist/runtime/components/MapoMediaFolderPicker.vue +129 -0
  45. package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts +33 -0
  46. package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts.map +1 -0
  47. package/dist/runtime/components/MapoMediaFolders.vue +254 -72
  48. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -1
  49. package/dist/runtime/components/MapoMediaGallery.vue +228 -143
  50. package/dist/runtime/components/MapoMediaGallery.vue.d.ts +5 -1
  51. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -1
  52. package/dist/runtime/components/MapoMediaManager.vue +6 -2
  53. package/dist/runtime/components/MapoMediaManager.vue.d.ts +11 -2
  54. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -1
  55. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +1 -1
  56. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -1
  57. package/dist/runtime/components/MapoMediaPreview.vue +5 -3
  58. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -1
  59. package/dist/runtime/components/MapoMediaUploader.vue +5 -1
  60. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
  61. package/dist/runtime/components/MapoMenuManager.vue +13 -5
  62. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -1
  63. package/dist/runtime/stores/media.d.ts +43 -6
  64. package/dist/runtime/stores/media.d.ts.map +1 -1
  65. package/dist/runtime/stores/media.js +201 -16
  66. package/dist/runtime/types/media.d.ts +17 -2
  67. package/dist/runtime/types/media.d.ts.map +1 -1
  68. package/dist/runtime/utils/contentLanguages.d.ts +9 -0
  69. package/dist/runtime/utils/contentLanguages.d.ts.map +1 -0
  70. package/dist/runtime/utils/contentLanguages.js +8 -0
  71. package/dist/runtime/utils/langInfo.d.ts +13 -0
  72. package/dist/runtime/utils/langInfo.d.ts.map +1 -1
  73. package/dist/runtime/utils/langInfo.js +9 -0
  74. package/dist/runtime/utils/mediaDrag.d.ts +21 -0
  75. package/dist/runtime/utils/mediaDrag.d.ts.map +1 -0
  76. package/dist/runtime/utils/mediaDrag.js +11 -0
  77. package/dist/runtime/utils/mediaFolders.d.ts +65 -0
  78. package/dist/runtime/utils/mediaFolders.d.ts.map +1 -0
  79. package/dist/runtime/utils/mediaFolders.js +97 -0
  80. package/dist/runtime/utils/mediaMetadata.d.ts +39 -0
  81. package/dist/runtime/utils/mediaMetadata.d.ts.map +1 -0
  82. package/dist/runtime/utils/mediaMetadata.js +97 -0
  83. package/dist/runtime/utils/mediaUrl.d.ts +16 -0
  84. package/dist/runtime/utils/mediaUrl.d.ts.map +1 -0
  85. package/dist/runtime/utils/mediaUrl.js +12 -0
  86. package/package.json +3 -3
  87. package/src/__tests__/MapoDetail.component.test.ts +64 -1
  88. package/src/__tests__/MapoMediaEditor.component.test.ts +447 -0
  89. package/src/__tests__/MapoMediaFolderPicker.component.test.ts +220 -0
  90. package/src/__tests__/MapoMediaFolders.component.test.ts +519 -0
  91. package/src/__tests__/MapoMediaGallery.component.test.ts +211 -0
  92. package/src/__tests__/MapoMediaUploadHandover.component.test.ts +241 -0
  93. package/src/__tests__/MapoMenuManager.component.test.ts +175 -0
  94. package/src/__tests__/langInfo.test.ts +38 -1
  95. package/src/__tests__/mediaDrag.test.ts +42 -0
  96. package/src/__tests__/mediaFolders.test.ts +204 -0
  97. package/src/__tests__/mediaMetadata.test.ts +169 -0
  98. package/src/__tests__/mediaStore.test.ts +569 -0
  99. package/src/__tests__/mediaUrl.test.ts +44 -0
  100. package/src/index.ts +1 -0
  101. package/src/module.ts +25 -0
  102. package/src/runtime/adapters/defaultMediaAdapter.ts +11 -1
  103. package/src/runtime/components/MapoDetail.vue +21 -9
  104. package/src/runtime/components/MapoDropArea.vue +24 -6
  105. package/src/runtime/components/MapoListQuickEdit.vue +10 -1
  106. package/src/runtime/components/MapoMediaEditor.vue +131 -47
  107. package/src/runtime/components/MapoMediaFolderPicker.vue +176 -0
  108. package/src/runtime/components/MapoMediaFolders.vue +311 -72
  109. package/src/runtime/components/MapoMediaGallery.vue +263 -152
  110. package/src/runtime/components/MapoMediaManager.vue +16 -2
  111. package/src/runtime/components/MapoMediaPreview.vue +8 -3
  112. package/src/runtime/components/MapoMediaUploader.vue +8 -1
  113. package/src/runtime/components/MapoMenuManager.vue +24 -7
  114. package/src/runtime/stores/media.ts +335 -21
  115. package/src/runtime/types/media.ts +20 -2
  116. package/src/runtime/utils/contentLanguages.ts +18 -0
  117. package/src/runtime/utils/langInfo.ts +25 -0
  118. package/src/runtime/utils/mediaDrag.ts +29 -0
  119. package/src/runtime/utils/mediaFolders.ts +182 -0
  120. package/src/runtime/utils/mediaMetadata.ts +165 -0
  121. package/src/runtime/utils/mediaUrl.ts +30 -0
@@ -5,6 +5,7 @@ import type {
5
5
  MediaItem,
6
6
  MediaListParamsContext,
7
7
  } from "../types/media.js";
8
+ import { mediaMetadataPatch } from "../utils/mediaMetadata.js";
8
9
 
9
10
  /**
10
11
  * Default media adapter — plain REST semantics.
@@ -13,6 +14,7 @@ import type {
13
14
  * - Response: assumes the backend already returns the canonical
14
15
  * `{ media: { items, paginator }, folders, parent_folder }` shape.
15
16
  * - Detail params: passes `language_code` when a language is active.
17
+ * - Metadata PATCH: only the edited fields when the pre-edit copy is known.
16
18
  *
17
19
  * Integrations override any subset of these via their own `$mapoMediaAdapter`
18
20
  * plugin (see `@mapomodule/mapo-integrations-camomilla`).
@@ -39,7 +41,11 @@ export const defaultMediaAdapter: Required<MediaAdapter> = {
39
41
  return { ...folder };
40
42
  },
41
43
 
42
- buildMediaPatchPayload(media: MediaItem): Record<string, unknown> {
44
+ buildMediaPatchPayload(
45
+ media: MediaItem,
46
+ previous?: MediaItem,
47
+ ): Record<string, unknown> {
48
+ if (previous) return mediaMetadataPatch(media, previous);
43
49
  return {
44
50
  title: media.title,
45
51
  alt_text: media.alt_text,
@@ -48,6 +54,10 @@ export const defaultMediaAdapter: Required<MediaAdapter> = {
48
54
  };
49
55
  },
50
56
 
57
+ buildMoveMediaPayload(folderId: number | null): Record<string, unknown> {
58
+ return { folder: folderId };
59
+ },
60
+
51
61
  buildReplaceFilePayload(
52
62
  file: File,
53
63
  maintainUrl: boolean,
@@ -25,7 +25,8 @@ import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
25
25
  import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
26
26
  import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
27
27
  import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
28
- import { languagesFromMetadata } from "../utils/langInfo";
28
+ import { languagesFromMetadata, restrictLanguages } from "../utils/langInfo";
29
+ import { useContentLanguages } from "../utils/contentLanguages";
29
30
  import { useFormFromSchema } from "@mapomodule/form/runtime/composables/useFormFromSchema";
30
31
  import type { UseFormFromSchemaOptions } from "@mapomodule/form/runtime/composables/useFormFromSchema";
31
32
  import type { JSONSchema } from "@mapomodule/utils";
@@ -117,9 +118,9 @@ const props = withDefaults(
117
118
  */
118
119
  previewField?: string;
119
120
  /**
120
- * Override the language list regardless of what `lang_info.site_languages`
121
- * returns from the backend. Takes precedence over both `languages` prop and
122
- * the auto-derived list.
121
+ * Override the language list regardless of what the backend declares
122
+ * (`lang_info.languages`). Takes precedence over the `languages` prop, the
123
+ * auto-derived list and the app's `mapo.uikit.contentLanguages`.
123
124
  */
124
125
  forceLanguages?: string[];
125
126
  }>(),
@@ -217,7 +218,10 @@ const isSaving = computed(() => {
217
218
  return savingAndLeaving || savingAndStaying;
218
219
  });
219
220
  const isDeleting = computed(() => pendingAction.value === "delete");
220
- const currentLang = ref(props.languages[0] ?? "");
221
+ // Set by the `activeLangs` watcher below, to the first language actually
222
+ // offered: `languages[0]` can be one `mapo.uikit.contentLanguages` hides or
223
+ // puts later.
224
+ const currentLang = ref("");
221
225
  const draftBanner = ref<{
222
226
  savedAt: Date;
223
227
  restore: () => void;
@@ -236,17 +240,25 @@ const mainCols = computed(() => 12 - props.sidebarCols);
236
240
  // metadata, so the host page doesn't hard-code a language list — and a model
237
241
  // that is not registered for translation shows no switcher at all, rather than
238
242
  // tabs whose extra values the backend would drop.
239
- // forceLanguages > props.languages > derived.
243
+ // forceLanguages > (props.languages > derived), narrowed to the app's
244
+ // `mapo.uikit.contentLanguages`.
240
245
  const derivedLangs = ref<string[]>([]);
246
+ const contentLanguages = useContentLanguages();
241
247
  const activeLangs = computed<string[]>(() => {
242
248
  if (props.forceLanguages?.length) return props.forceLanguages;
243
- if (props.languages.length) return props.languages;
244
- return derivedLangs.value;
249
+ const declared = props.languages.length
250
+ ? props.languages
251
+ : derivedLangs.value;
252
+ return restrictLanguages(declared, contentLanguages);
245
253
  });
254
+ // Start on the first language, and move there when the current one is not
255
+ // offered (any more): the first of `languages` can be one the app hides.
246
256
  watch(
247
257
  activeLangs,
248
258
  (langs) => {
249
- if (!currentLang.value && langs.length) currentLang.value = langs[0]!;
259
+ const isOffered = langs.includes(currentLang.value);
260
+ if (isOffered || !langs.length) return;
261
+ currentLang.value = langs[0]!;
250
262
  },
251
263
  { immediate: true },
252
264
  );
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { ref } from "vue";
3
3
  import { useI18n } from "vue-i18n";
4
+ import { isMediaDrag } from "../utils/mediaDrag.js";
4
5
 
5
6
  const { t } = useI18n();
6
7
 
@@ -25,14 +26,30 @@ const isDragging = ref(false);
25
26
  const fileInput = ref<HTMLInputElement | null>(null);
26
27
  let dragCounter = 0;
27
28
 
29
+ // Only files dragged in from the computer are drops for this area: an element
30
+ // dragged inside the page (a gallery card, a selection being reordered) is
31
+ // left to whatever handles it, with no overlay and no default prevented.
32
+ // Chrome reports an image dragged from the page as "Files" too, so a drag the
33
+ // media manager started is told apart by its own data type.
34
+ function carriesFiles(e: DragEvent): boolean {
35
+ const hasFiles = Array.from(e.dataTransfer?.types ?? []).includes("Files");
36
+ return hasFiles && !isMediaDrag(e);
37
+ }
38
+
28
39
  function onDragEnter(e: DragEvent) {
29
- if (props.disabled) return;
40
+ if (props.disabled || !carriesFiles(e)) return;
30
41
  e.preventDefault();
31
42
  dragCounter++;
32
43
  isDragging.value = true;
33
44
  }
34
45
 
35
- function onDragLeave() {
46
+ function onDragOver(e: DragEvent) {
47
+ if (props.disabled || !carriesFiles(e)) return;
48
+ e.preventDefault();
49
+ }
50
+
51
+ function onDragLeave(e: DragEvent) {
52
+ if (!carriesFiles(e)) return;
36
53
  dragCounter--;
37
54
  if (dragCounter <= 0) {
38
55
  dragCounter = 0;
@@ -41,7 +58,8 @@ function onDragLeave() {
41
58
  }
42
59
 
43
60
  function onDrop(e: DragEvent) {
44
- if (props.disabled) return;
61
+ if (props.disabled || !carriesFiles(e)) return;
62
+ e.preventDefault();
45
63
  isDragging.value = false;
46
64
  dragCounter = 0;
47
65
  const files = filterFiles(Array.from(e.dataTransfer?.files ?? []));
@@ -83,10 +101,10 @@ defineExpose({ triggerPick });
83
101
  'mapo-drop-area--dragging': isDragging,
84
102
  'opacity-50 pointer-events-none': disabled,
85
103
  }"
86
- @dragenter.prevent="onDragEnter"
87
- @dragover.prevent
104
+ @dragenter="onDragEnter"
105
+ @dragover="onDragOver"
88
106
  @dragleave="onDragLeave"
89
- @drop.prevent="onDrop"
107
+ @drop="onDrop"
90
108
  >
91
109
  <input
92
110
  ref="fileInput"
@@ -6,6 +6,8 @@ import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
6
6
  import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
7
7
  import { useCrud } from "@mapomodule/core/runtime/api/crud";
8
8
  import { getErrorDetail } from "@mapomodule/core/runtime/utils/fetchError";
9
+ import { restrictLanguages } from "../utils/langInfo";
10
+ import { useContentLanguages } from "../utils/contentLanguages";
9
11
 
10
12
  const props = withDefaults(
11
13
  defineProps<{
@@ -51,6 +53,13 @@ const { t } = useI18n();
51
53
  const snack = useSnackStore();
52
54
  const crud = useCrud<T>(props.endpoint);
53
55
 
56
+ // The languages the form syncs `synci18n` fields into, narrowed to the app's
57
+ // `mapo.uikit.contentLanguages` as MapoDetail narrows its own.
58
+ const contentLanguages = useContentLanguages();
59
+ const formLanguages = computed(() =>
60
+ restrictLanguages(props.languages ?? [], contentLanguages),
61
+ );
62
+
54
63
  // Typed as Ref<T> (not Ref<UnwrapRef<T>>) so the template unwrap stays exactly T,
55
64
  // which keeps the `extra` slot's `:model` binding type-correct for the generic T.
56
65
  const model = ref({} as T) as Ref<T>;
@@ -144,7 +153,7 @@ async function save() {
144
153
  <MapoForm
145
154
  v-model="model"
146
155
  :fields="editFields"
147
- :languages="languages"
156
+ :languages="formLanguages"
148
157
  :registry="registry"
149
158
  immediate
150
159
  />
@@ -9,17 +9,28 @@ import {
9
9
  setNestedValue,
10
10
  } from "@mapomodule/utils";
11
11
  import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
12
+ import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
13
+ import { getErrorData } from "@mapomodule/core/runtime/utils/fetchError";
12
14
  import { useMediaStore } from "../stores/media.js";
13
- import type { MediaItem } from "../types/media.js";
15
+ import { pickLanguage, restrictLanguages } from "../utils/langInfo.js";
16
+ import { useContentLanguages } from "../utils/contentLanguages.js";
17
+ import { describeMediaErrors, pickMetadata } from "../utils/mediaMetadata.js";
18
+ import { mediaFileUrl } from "../utils/mediaUrl.js";
19
+ import type { MediaFolder, MediaItem } from "../types/media.js";
14
20
 
15
21
  const props = defineProps<{
16
22
  /** Overrides the languages read from the endpoint. Rarely needed. */
17
23
  languages?: string[];
24
+ /**
25
+ * Language the editor opens on, when it is among the languages. Default: the
26
+ * first one. A `?lang=` in the page URL wins, as in `MapoDetail`.
27
+ */
18
28
  defaultLang?: string;
19
29
  }>();
20
30
 
21
31
  const { t } = useI18n();
22
32
  const store = useMediaStore();
33
+ const snack = useSnackStore();
23
34
 
24
35
  // Model-permission gating (legacy parity): edit/delete only with the
25
36
  // change/delete permission on the configured media model.
@@ -35,14 +46,38 @@ const editing = ref(false);
35
46
  const saving = ref(false);
36
47
  const newFile = ref<File | null>(null);
37
48
  const maintainUrl = ref(false);
38
- const currentLang = ref("");
49
+ // Remounts the file changer, clearing the file it shows, once that file is stored.
50
+ const fileChangerKey = ref(0);
39
51
 
40
- // The languages actually offered. An explicit prop wins; otherwise they come
41
- // from the media endpoint's own OPTIONS metadata, so a host page never has to
42
- // restate what the backend already knows — and a media model nobody registered
43
- // for translation shows no switcher rather than tabs whose values it discards.
52
+ // The languages actually offered. An explicit prop wins; otherwise the store's
53
+ // list: the manager's own, or the media endpoint's OPTIONS metadata, so a host
54
+ // page never has to restate what the backend already knows — and a media model
55
+ // nobody registered for translation shows no switcher rather than tabs whose
56
+ // values it discards. Either is narrowed to the app's content languages: the
57
+ // store's list already is, the prop is here.
58
+ const contentLanguages = useContentLanguages();
44
59
  const activeLangs = computed(() =>
45
- props.languages?.length ? props.languages : store.languages,
60
+ props.languages?.length
61
+ ? restrictLanguages(props.languages, contentLanguages)
62
+ : store.activeLanguages,
63
+ );
64
+
65
+ // The language being edited, `""` when media are not translated. There is no
66
+ // "untranslated" tab next to the languages: on a backend that translates media
67
+ // the plain fields are the active language's columns under another name, and
68
+ // Camomilla drops them on write, so every edit goes to a translation.
69
+ const currentLang = ref("");
70
+ watch(
71
+ activeLangs,
72
+ (langs) => {
73
+ const isOffered = langs.includes(currentLang.value);
74
+ if (isOffered) return;
75
+ currentLang.value = pickLanguage(
76
+ langs,
77
+ props.defaultLang ?? store.initialLanguage,
78
+ );
79
+ },
80
+ { immediate: true },
46
81
  );
47
82
 
48
83
  onMounted(() => {
@@ -70,7 +105,13 @@ watch(
70
105
  },
71
106
  );
72
107
 
73
- const metaRows = computed(() => {
108
+ // Links open the versioned URL, so a file replaced at the same URL shows its new
109
+ // content; the text stays the real URL, the one worth copying.
110
+ const fileUrl = computed(() => (media.value ? mediaFileUrl(media.value) : ""));
111
+
112
+ const metaRows = computed<
113
+ { label: string; value: string; isUrl: boolean; href?: string }[]
114
+ >(() => {
74
115
  if (!media.value) return [];
75
116
  const m = media.value;
76
117
  return [
@@ -86,7 +127,7 @@ const metaRows = computed(() => {
86
127
  isUrl: false,
87
128
  },
88
129
  { label: t("mapo.created"), value: formatDate(m.created), isUrl: false },
89
- { label: t("mapo.url"), value: m.file, isUrl: true },
130
+ { label: t("mapo.url"), value: m.file, isUrl: true, href: fileUrl.value },
90
131
  ];
91
132
  });
92
133
 
@@ -135,22 +176,57 @@ function cancelEditing() {
135
176
  newFile.value = null;
136
177
  }
137
178
 
179
+ // Moving the media: it leaves the folder on screen, so the drawer closes.
180
+ const movePickerOpen = ref(false);
181
+
182
+ async function moveTo(folder: MediaFolder | null) {
183
+ if (!media.value) return;
184
+ const moved = await store.moveMedia([media.value.id], folder?.id ?? null);
185
+ if (moved.length) store.closeEditor();
186
+ }
187
+
188
+ // Field labels for the error toast, keyed like the backend reports the fields.
189
+ const errorLabels = computed(() => ({
190
+ title: t("mapo.title"),
191
+ alt_text: t("mapo.altTag"),
192
+ description: t("mapo.description"),
193
+ file: t("mapo.file"),
194
+ }));
195
+
196
+ function notifySaveError(error: unknown) {
197
+ const lines = describeMediaErrors(getErrorData(error), errorLabels.value);
198
+ snack.show(lines.join("\n") || t("mapo.genericError"), "error");
199
+ }
200
+
138
201
  async function save() {
139
202
  if (!media.value) return;
140
203
  saving.value = true;
204
+ // Snapshot the edited metadata BEFORE replacing the file: replaceFile
205
+ // syncs editMedia with the server response, which would otherwise
206
+ // silently discard the user's unsaved title/alt/description edits.
207
+ const edited = { ...media.value };
141
208
  try {
142
- // Snapshot the edited metadata BEFORE replacing the file: replaceFile
143
- // syncs editMedia with the server response, which would otherwise
144
- // silently discard the user's unsaved title/alt/description edits.
145
- const edited = { ...media.value };
146
209
  if (newFile.value) {
147
- await store.replaceFile(edited.id, newFile.value, maintainUrl.value);
210
+ const replaced = await store.replaceFile(
211
+ edited.id,
212
+ newFile.value,
213
+ maintainUrl.value,
214
+ );
215
+ // The file is stored: a retry after a failed metadata save must not
216
+ // upload it again, and the form keeps the edits over the server copy.
217
+ newFile.value = null;
218
+ maintainUrl.value = false;
219
+ fileChangerKey.value++;
220
+ store.editMedia = { ...replaced, ...pickMetadata(edited) };
148
221
  }
149
- await store.updateMedia(edited);
222
+ await store.updateMedia(edited, editSnapshot ?? undefined);
150
223
  editSnapshot = null;
151
224
  editing.value = false;
152
225
  newFile.value = null;
153
226
  maintainUrl.value = false;
227
+ } catch (error) {
228
+ // Stay in edit mode with the edits on screen, so they can be fixed.
229
+ notifySaveError(error);
154
230
  } finally {
155
231
  saving.value = false;
156
232
  }
@@ -204,7 +280,7 @@ function formatDate(dateStr: string): string {
204
280
  size="xs"
205
281
  variant="ghost"
206
282
  color="neutral"
207
- :href="media.file"
283
+ :href="fileUrl"
208
284
  target="_blank"
209
285
  :title="t('mapo.mediaEditor.openInNewTab')"
210
286
  />
@@ -235,7 +311,7 @@ function formatDate(dateStr: string): string {
235
311
  <dd class="flex-1 truncate font-mono text-default">
236
312
  <a
237
313
  v-if="row.isUrl"
238
- :href="row.value"
314
+ :href="row.href ?? row.value"
239
315
  target="_blank"
240
316
  rel="noopener"
241
317
  class="text-primary hover:underline"
@@ -266,25 +342,15 @@ function formatDate(dateStr: string): string {
266
342
 
267
343
  <!-- Edit form (shown when editing) -->
268
344
  <div v-if="editing" class="space-y-4 px-4 py-3">
269
- <!-- Lang switch -->
270
- <UFieldGroup v-if="activeLangs.length > 1" size="xs">
271
- <UButton
272
- :variant="currentLang === '' ? 'solid' : 'outline'"
273
- color="neutral"
274
- @click="currentLang = ''"
275
- >
276
- {{ t("mapo.mediaEditor.defaultLang") }}
277
- </UButton>
278
- <UButton
279
- v-for="lang in activeLangs"
280
- :key="lang"
281
- :variant="currentLang === lang ? 'solid' : 'outline'"
282
- color="neutral"
283
- @click="currentLang = lang"
284
- >
285
- {{ lang.toUpperCase() }}
286
- </UButton>
287
- </UFieldGroup>
345
+ <!-- Lang switch: the one MapoDetail and the menu manager use, so
346
+ an app that replaces it (MapoOverride) replaces it here too.
347
+ The drawer has no route of its own: the URL stays as it is. -->
348
+ <MapoDetailLangSwitch
349
+ v-if="activeLangs.length > 1"
350
+ v-model="currentLang"
351
+ :langs="activeLangs"
352
+ no-route-change
353
+ />
288
354
 
289
355
  <!-- Field inputs -->
290
356
  <div class="space-y-3">
@@ -312,6 +378,7 @@ function formatDate(dateStr: string): string {
312
378
 
313
379
  <!-- File replace -->
314
380
  <MapoMediaFileChanger
381
+ :key="fileChangerKey"
315
382
  :media="media"
316
383
  @update:file="newFile = $event"
317
384
  @update:maintain-url="maintainUrl = $event"
@@ -319,21 +386,38 @@ function formatDate(dateStr: string): string {
319
386
  </div>
320
387
  </div>
321
388
 
389
+ <!-- Destination picker for "Move to": teleported, mounted when open -->
390
+ <MapoMediaFolderPicker
391
+ v-model:open="movePickerOpen"
392
+ @confirm="moveTo"
393
+ />
394
+
322
395
  <!-- Footer -->
323
396
  <div
324
397
  class="flex items-center justify-between gap-2 border-t border-default px-4 py-3"
325
398
  >
326
- <UButton
327
- v-if="canRemove"
328
- icon="i-lucide-trash-2"
329
- size="sm"
330
- variant="soft"
331
- color="error"
332
- @click="store.deleteMedia(media)"
333
- >
334
- {{ t("mapo.delete") }}
335
- </UButton>
336
- <span v-else />
399
+ <div class="flex gap-2">
400
+ <UButton
401
+ v-if="canRemove"
402
+ icon="i-lucide-trash-2"
403
+ size="sm"
404
+ variant="soft"
405
+ color="error"
406
+ @click="store.deleteMedia(media)"
407
+ >
408
+ {{ t("mapo.delete") }}
409
+ </UButton>
410
+ <UButton
411
+ v-if="canEdit && !editing"
412
+ icon="i-lucide-folder-input"
413
+ size="sm"
414
+ variant="soft"
415
+ color="neutral"
416
+ @click="movePickerOpen = true"
417
+ >
418
+ {{ t("mapo.mediaMove.moveTo") }}
419
+ </UButton>
420
+ </div>
337
421
 
338
422
  <div class="flex gap-2">
339
423
  <UButton
@@ -0,0 +1,176 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed, watch } from "vue";
3
+ import { useI18n } from "vue-i18n";
4
+ import { useMediaStore } from "../stores/media.js";
5
+ import {
6
+ ROOT_FOLDER_KEY,
7
+ buildFolderTree,
8
+ findFolderNode,
9
+ folderKey,
10
+ folderNodeIcon,
11
+ type FolderNode,
12
+ } from "../utils/mediaFolders.js";
13
+ import type { MediaFolder } from "../types/media.js";
14
+
15
+ /**
16
+ * Dialog to pick a media folder, the root included, from the same folder tree
17
+ * as the manager's sidebar (it shares the store's folder cache and loads the
18
+ * branches it opens). Used to move media and folders.
19
+ */
20
+ const props = withDefaults(
21
+ defineProps<{
22
+ /** Whether the dialog is open (`v-model:open`). */
23
+ open: boolean;
24
+ /** Dialog title. Default: "Move to folder". */
25
+ title?: string;
26
+ /** Label of the confirm button. Default: "Move here". */
27
+ confirmLabel?: string;
28
+ /**
29
+ * Folder ids that cannot be picked, hidden with everything under them:
30
+ * a folder cannot go inside itself.
31
+ */
32
+ exclude?: number[];
33
+ }>(),
34
+ {
35
+ title: undefined,
36
+ confirmLabel: undefined,
37
+ exclude: () => [],
38
+ },
39
+ );
40
+
41
+ const emit = defineEmits<{
42
+ /** The dialog opened or closed. */
43
+ "update:open": [open: boolean];
44
+ /** The folder picked: `null` is the root. */
45
+ confirm: [folder: MediaFolder | null];
46
+ }>();
47
+
48
+ const { t } = useI18n();
49
+ const store = useMediaStore();
50
+
51
+ const pickedKey = ref<string | null>(null);
52
+ const expanded = ref<string[]>([ROOT_FOLDER_KEY]);
53
+
54
+ // Opens on the folder on screen: its path expanded, nothing picked yet.
55
+ function prepare() {
56
+ pickedKey.value = null;
57
+ const path = store.parentFolders.map((folder) => folderKey(folder.id));
58
+ expanded.value = [ROOT_FOLDER_KEY, ...path];
59
+ const hasRoot = store.folderChildren[ROOT_FOLDER_KEY] !== undefined;
60
+ if (!hasRoot) store.loadFolderChildren(null).catch(() => {});
61
+ }
62
+
63
+ // Nuxt UI overlays have no z-index: they stack in the order they mount. The
64
+ // picker can open from the editor drawer, so it mounts when it opens, above
65
+ // it, and unmounts once its close animation has ended.
66
+ const modalMounted = ref(props.open);
67
+ if (props.open) prepare();
68
+ watch(
69
+ () => props.open,
70
+ (open) => {
71
+ if (!open) return;
72
+ modalMounted.value = true;
73
+ prepare();
74
+ },
75
+ );
76
+
77
+ function onAfterLeave() {
78
+ // Opened again while closing: it is open again.
79
+ if (props.open) return;
80
+ modalMounted.value = false;
81
+ }
82
+
83
+ const excluded = computed(() => new Set(props.exclude));
84
+ const tree = computed(() =>
85
+ buildFolderTree(
86
+ store.folderChildren,
87
+ { root: t("mapo.mediaManager.root"), loading: t("mapo.loading") },
88
+ { exclude: excluded.value },
89
+ ),
90
+ );
91
+ const pickedNode = computed(() =>
92
+ pickedKey.value ? findFolderNode(tree.value, pickedKey.value) : undefined,
93
+ );
94
+ const nodeKey = (node: FolderNode) => node.key;
95
+
96
+ // The picked folder is this component's state: Reka's own selection is
97
+ // cancelled, as in the sidebar, so a second click does not unpick it.
98
+ function onSelectNode(event: { preventDefault(): void }, node: FolderNode) {
99
+ event.preventDefault();
100
+ if (node.pending) return;
101
+ pickedKey.value = node.key;
102
+ }
103
+
104
+ function onToggleNode(
105
+ event: { detail: { isExpanded: boolean } },
106
+ node: FolderNode,
107
+ ) {
108
+ const isOpening = !event.detail.isExpanded;
109
+ const isLoaded = store.folderChildren[node.key] !== undefined;
110
+ if (!isOpening || isLoaded || node.pending) return;
111
+ // On failure the branch keeps its placeholder; opening it again retries.
112
+ store.loadFolderChildren(node.folder?.id ?? null).catch(() => {});
113
+ }
114
+
115
+ function close() {
116
+ emit("update:open", false);
117
+ }
118
+
119
+ function confirm() {
120
+ const node = pickedNode.value;
121
+ if (!node) return;
122
+ emit("confirm", node.folder);
123
+ close();
124
+ }
125
+ </script>
126
+
127
+ <template>
128
+ <UModal
129
+ v-if="modalMounted"
130
+ :open="open"
131
+ :title="title ?? t('mapo.mediaMove.title')"
132
+ :ui="{ content: 'max-w-md' }"
133
+ @update:open="emit('update:open', $event)"
134
+ @after:leave="onAfterLeave"
135
+ >
136
+ <template #body>
137
+ <UTree
138
+ v-model:expanded="expanded"
139
+ :items="tree"
140
+ :model-value="pickedNode"
141
+ :get-key="nodeKey"
142
+ size="sm"
143
+ color="neutral"
144
+ class="max-h-[50vh] overflow-y-auto"
145
+ @select="onSelectNode"
146
+ @toggle="onToggleNode"
147
+ >
148
+ <template #item-leading="{ item, expanded: isOpen, ui }">
149
+ <UIcon
150
+ :name="folderNodeIcon(item, isOpen)"
151
+ :class="[ui.linkLeadingIcon(), item.pending && 'animate-spin']"
152
+ />
153
+ </template>
154
+ </UTree>
155
+ </template>
156
+
157
+ <template #footer>
158
+ <div class="flex w-full justify-end gap-2">
159
+ <UButton
160
+ variant="ghost"
161
+ color="neutral"
162
+ :label="t('mapo.cancel')"
163
+ @click="close"
164
+ />
165
+ <UButton
166
+ color="primary"
167
+ icon="i-lucide-folder-input"
168
+ :disabled="!pickedNode"
169
+ @click="confirm"
170
+ >
171
+ {{ confirmLabel ?? t("mapo.mediaMove.confirm") }}
172
+ </UButton>
173
+ </div>
174
+ </template>
175
+ </UModal>
176
+ </template>