@mapomodule/uikit 2.0.0-beta.2 → 2.0.0-beta.20

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 (258) hide show
  1. package/README.md +46 -142
  2. package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
  3. package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
  4. package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
  5. package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
  6. package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
  7. package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
  8. package/dist/__tests__/MapoList.component.test.d.ts +2 -0
  9. package/dist/__tests__/MapoList.component.test.d.ts.map +1 -0
  10. package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
  11. package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
  12. package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
  13. package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
  14. package/dist/__tests__/MapoMediaEditor.component.test.d.ts +2 -0
  15. package/dist/__tests__/MapoMediaEditor.component.test.d.ts.map +1 -0
  16. package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts +2 -0
  17. package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts.map +1 -0
  18. package/dist/__tests__/MapoMediaFolders.component.test.d.ts +2 -0
  19. package/dist/__tests__/MapoMediaFolders.component.test.d.ts.map +1 -0
  20. package/dist/__tests__/MapoMediaGallery.component.test.d.ts +2 -0
  21. package/dist/__tests__/MapoMediaGallery.component.test.d.ts.map +1 -0
  22. package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts +2 -0
  23. package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts.map +1 -0
  24. package/dist/__tests__/MapoMenuManager.component.test.d.ts +2 -0
  25. package/dist/__tests__/MapoMenuManager.component.test.d.ts.map +1 -0
  26. package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
  27. package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
  28. package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
  29. package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
  30. package/dist/__tests__/langInfo.test.d.ts +2 -0
  31. package/dist/__tests__/langInfo.test.d.ts.map +1 -0
  32. package/dist/__tests__/listTable.test.d.ts +2 -0
  33. package/dist/__tests__/listTable.test.d.ts.map +1 -0
  34. package/dist/__tests__/mediaDrag.test.d.ts +2 -0
  35. package/dist/__tests__/mediaDrag.test.d.ts.map +1 -0
  36. package/dist/__tests__/mediaFolders.test.d.ts +2 -0
  37. package/dist/__tests__/mediaFolders.test.d.ts.map +1 -0
  38. package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
  39. package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
  40. package/dist/__tests__/mediaMetadata.test.d.ts +2 -0
  41. package/dist/__tests__/mediaMetadata.test.d.ts.map +1 -0
  42. package/dist/__tests__/mediaStore.test.d.ts +2 -0
  43. package/dist/__tests__/mediaStore.test.d.ts.map +1 -0
  44. package/dist/__tests__/mediaUrl.test.d.ts +2 -0
  45. package/dist/__tests__/mediaUrl.test.d.ts.map +1 -0
  46. package/dist/index.d.mts +3 -0
  47. package/dist/index.d.ts +4 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.mjs +1 -1
  50. package/dist/module.d.mts +48 -1
  51. package/dist/module.d.ts +44 -0
  52. package/dist/module.d.ts.map +1 -1
  53. package/dist/module.json +1 -1
  54. package/dist/module.mjs +71 -2
  55. package/dist/runtime/adapters/defaultMediaAdapter.d.ts +15 -0
  56. package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
  57. package/dist/runtime/adapters/defaultMediaAdapter.js +35 -0
  58. package/dist/runtime/assets/main.css +1 -1
  59. package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
  60. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
  61. package/dist/runtime/components/MapoDetail.vue +127 -55
  62. package/dist/runtime/components/MapoDetail.vue.d.ts +102 -5
  63. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
  64. package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
  65. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
  66. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
  67. package/dist/runtime/components/MapoDropArea.vue +110 -0
  68. package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
  69. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
  70. package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
  71. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
  72. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
  73. package/dist/runtime/components/MapoList.vue +45 -31
  74. package/dist/runtime/components/MapoList.vue.d.ts +18 -5
  75. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
  76. package/dist/runtime/components/MapoListActions.vue +27 -13
  77. package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
  78. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
  79. package/dist/runtime/components/MapoListFilters.vue +4 -2
  80. package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
  81. package/dist/runtime/components/MapoListQuickEdit.vue +20 -10
  82. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
  83. package/dist/runtime/components/MapoListTable.vue +125 -49
  84. package/dist/runtime/components/MapoListTable.vue.d.ts +13 -5
  85. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
  86. package/dist/runtime/components/MapoLogin.vue +13 -10
  87. package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
  88. package/dist/runtime/components/MapoLogoutButton.vue +4 -2
  89. package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
  90. package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
  91. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
  92. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
  93. package/dist/runtime/components/MapoMediaEditor.vue +382 -0
  94. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +13 -0
  95. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
  96. package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
  97. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
  98. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
  99. package/dist/runtime/components/MapoMediaFolderPicker.vue +129 -0
  100. package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts +33 -0
  101. package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts.map +1 -0
  102. package/dist/runtime/components/MapoMediaFolders.vue +402 -0
  103. package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
  104. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
  105. package/dist/runtime/components/MapoMediaGallery.vue +304 -0
  106. package/dist/runtime/components/MapoMediaGallery.vue.d.ts +8 -0
  107. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
  108. package/dist/runtime/components/MapoMediaManager.vue +144 -0
  109. package/dist/runtime/components/MapoMediaManager.vue.d.ts +44 -0
  110. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
  111. package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
  112. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
  113. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
  114. package/dist/runtime/components/MapoMediaPreview.vue +94 -0
  115. package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
  116. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
  117. package/dist/runtime/components/MapoMediaUploader.vue +294 -0
  118. package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
  119. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
  120. package/dist/runtime/components/MapoMenuManager.vue +301 -0
  121. package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
  122. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
  123. package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
  124. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
  125. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
  126. package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
  127. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
  128. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
  129. package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
  130. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
  131. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
  132. package/dist/runtime/components/MapoSidebar.vue +3 -1
  133. package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
  134. package/dist/runtime/components/MapoSidebarList.vue +1 -1
  135. package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
  136. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
  137. package/dist/runtime/components/MapoSnackBar.vue +11 -0
  138. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
  139. package/dist/runtime/components/MapoThemeToggle.vue +5 -1
  140. package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
  141. package/dist/runtime/components/menuDndContext.d.ts +19 -0
  142. package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
  143. package/dist/runtime/components/menuDndContext.js +3 -0
  144. package/dist/runtime/page-meta.nuxt.d.ts +4 -0
  145. package/dist/runtime/pages/index.vue +4 -3
  146. package/dist/runtime/pages/index.vue.d.ts.map +1 -1
  147. package/dist/runtime/pages/login.vue +0 -4
  148. package/dist/runtime/pages/login.vue.d.ts.map +1 -1
  149. package/dist/runtime/plugins/media-adapter.d.ts +18 -0
  150. package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
  151. package/dist/runtime/plugins/media-adapter.js +8 -0
  152. package/dist/runtime/stores/media.d.ts +505 -0
  153. package/dist/runtime/stores/media.d.ts.map +1 -0
  154. package/dist/runtime/stores/media.js +545 -0
  155. package/dist/runtime/types/list.d.ts +10 -2
  156. package/dist/runtime/types/list.d.ts.map +1 -1
  157. package/dist/runtime/types/media.d.ts +131 -0
  158. package/dist/runtime/types/media.d.ts.map +1 -0
  159. package/dist/runtime/types/media.js +0 -0
  160. package/dist/runtime/types/menu.d.ts +66 -0
  161. package/dist/runtime/types/menu.d.ts.map +1 -0
  162. package/dist/runtime/types/menu.js +30 -0
  163. package/dist/runtime/utils/contentLanguages.d.ts +9 -0
  164. package/dist/runtime/utils/contentLanguages.d.ts.map +1 -0
  165. package/dist/runtime/utils/contentLanguages.js +8 -0
  166. package/dist/runtime/utils/langInfo.d.ts +43 -0
  167. package/dist/runtime/utils/langInfo.d.ts.map +1 -0
  168. package/dist/runtime/utils/langInfo.js +17 -0
  169. package/dist/runtime/utils/listTable.d.ts +29 -0
  170. package/dist/runtime/utils/listTable.d.ts.map +1 -0
  171. package/dist/runtime/utils/listTable.js +21 -0
  172. package/dist/runtime/utils/mediaDrag.d.ts +21 -0
  173. package/dist/runtime/utils/mediaDrag.d.ts.map +1 -0
  174. package/dist/runtime/utils/mediaDrag.js +11 -0
  175. package/dist/runtime/utils/mediaFolders.d.ts +65 -0
  176. package/dist/runtime/utils/mediaFolders.d.ts.map +1 -0
  177. package/dist/runtime/utils/mediaFolders.js +97 -0
  178. package/dist/runtime/utils/mediaMetadata.d.ts +39 -0
  179. package/dist/runtime/utils/mediaMetadata.d.ts.map +1 -0
  180. package/dist/runtime/utils/mediaMetadata.js +97 -0
  181. package/dist/runtime/utils/mediaUrl.d.ts +16 -0
  182. package/dist/runtime/utils/mediaUrl.d.ts.map +1 -0
  183. package/dist/runtime/utils/mediaUrl.js +12 -0
  184. package/dist/types.d.mts +1 -1
  185. package/package.json +15 -11
  186. package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
  187. package/src/__tests__/MapoDetail.component.test.ts +393 -0
  188. package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
  189. package/src/__tests__/MapoList.component.test.ts +166 -0
  190. package/src/__tests__/MapoListActions.component.test.ts +175 -0
  191. package/src/__tests__/MapoListTable.component.test.ts +545 -0
  192. package/src/__tests__/MapoMediaEditor.component.test.ts +447 -0
  193. package/src/__tests__/MapoMediaFolderPicker.component.test.ts +220 -0
  194. package/src/__tests__/MapoMediaFolders.component.test.ts +519 -0
  195. package/src/__tests__/MapoMediaGallery.component.test.ts +211 -0
  196. package/src/__tests__/MapoMediaUploadHandover.component.test.ts +241 -0
  197. package/src/__tests__/MapoMenuManager.component.test.ts +175 -0
  198. package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
  199. package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
  200. package/src/__tests__/langInfo.test.ts +85 -0
  201. package/src/__tests__/listTable.test.ts +82 -0
  202. package/src/__tests__/mediaDrag.test.ts +42 -0
  203. package/src/__tests__/mediaFolders.test.ts +204 -0
  204. package/src/__tests__/mediaLanguages.test.ts +66 -0
  205. package/src/__tests__/mediaMetadata.test.ts +169 -0
  206. package/src/__tests__/mediaStore.test.ts +569 -0
  207. package/src/__tests__/mediaUrl.test.ts +44 -0
  208. package/src/index.ts +21 -0
  209. package/src/module.ts +155 -0
  210. package/src/runtime/adapters/defaultMediaAdapter.ts +67 -0
  211. package/src/runtime/assets/main.css +9 -0
  212. package/src/runtime/components/MapoConfirmDialog.vue +33 -4
  213. package/src/runtime/components/MapoDetail.vue +229 -73
  214. package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
  215. package/src/runtime/components/MapoDropArea.vue +145 -0
  216. package/src/runtime/components/MapoLangSwitcher.vue +74 -0
  217. package/src/runtime/components/MapoList.vue +65 -34
  218. package/src/runtime/components/MapoListActions.vue +32 -14
  219. package/src/runtime/components/MapoListFilters.vue +5 -2
  220. package/src/runtime/components/MapoListQuickEdit.vue +22 -10
  221. package/src/runtime/components/MapoListTable.vue +159 -59
  222. package/src/runtime/components/MapoLogin.vue +13 -10
  223. package/src/runtime/components/MapoLogoutButton.vue +4 -2
  224. package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
  225. package/src/runtime/components/MapoMediaEditor.vue +447 -0
  226. package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
  227. package/src/runtime/components/MapoMediaFolderPicker.vue +176 -0
  228. package/src/runtime/components/MapoMediaFolders.vue +478 -0
  229. package/src/runtime/components/MapoMediaGallery.vue +350 -0
  230. package/src/runtime/components/MapoMediaManager.vue +194 -0
  231. package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
  232. package/src/runtime/components/MapoMediaPreview.vue +116 -0
  233. package/src/runtime/components/MapoMediaUploader.vue +362 -0
  234. package/src/runtime/components/MapoMenuManager.vue +454 -0
  235. package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
  236. package/src/runtime/components/MapoMenuTreeview.vue +264 -0
  237. package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
  238. package/src/runtime/components/MapoSidebar.vue +3 -1
  239. package/src/runtime/components/MapoSidebarList.vue +1 -1
  240. package/src/runtime/components/MapoSidebarProfile.vue +6 -2
  241. package/src/runtime/components/MapoSnackBar.vue +12 -0
  242. package/src/runtime/components/MapoThemeToggle.vue +5 -1
  243. package/src/runtime/components/menuDndContext.ts +22 -0
  244. package/src/runtime/page-meta.nuxt.d.ts +4 -0
  245. package/src/runtime/pages/index.vue +4 -3
  246. package/src/runtime/pages/login.vue +0 -4
  247. package/src/runtime/plugins/media-adapter.ts +33 -0
  248. package/src/runtime/stores/media.ts +820 -0
  249. package/src/runtime/types/list.ts +10 -2
  250. package/src/runtime/types/media.ts +144 -0
  251. package/src/runtime/types/menu.ts +105 -0
  252. package/src/runtime/utils/contentLanguages.ts +18 -0
  253. package/src/runtime/utils/langInfo.ts +63 -0
  254. package/src/runtime/utils/listTable.ts +54 -0
  255. package/src/runtime/utils/mediaDrag.ts +29 -0
  256. package/src/runtime/utils/mediaFolders.ts +182 -0
  257. package/src/runtime/utils/mediaMetadata.ts +165 -0
  258. package/src/runtime/utils/mediaUrl.ts +30 -0
@@ -1,8 +1,16 @@
1
1
  /** Defines a single column in the list table. */
2
2
  export interface ListColumn<T = Record<string, unknown>> {
3
- /** Property name on the row object. Must be a key of `T`. */
4
- key: keyof T & string;
3
+ /**
4
+ * Property of the row to show, a key of `T`. A dotted path (`category.name`)
5
+ * reads a field of a related object; it starts with a key of `T`.
6
+ */
7
+ key: (keyof T & string) | `${keyof T & string}.${string}`;
5
8
  label: string;
9
+ /**
10
+ * Turns the header into a button that cycles ascending, descending and
11
+ * unsorted. The list sends the order to the backend as `ordering`, or sorts
12
+ * in memory in offline and hybrid mode.
13
+ */
6
14
  sortable?: boolean;
7
15
  /** CSS class applied to the `<td>` cell. */
8
16
  class?: string;
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Media **value** types are owned by `@mapomodule/form` (they are the value that
3
+ * lands in the form model, next to their descriptors) and re-exported here so the
4
+ * Media Manager keeps a single import surface. `uikit` already depends on `form`,
5
+ * so this direction introduces no cycle.
6
+ */
7
+ export type {
8
+ MediaLink,
9
+ MediaItem,
10
+ EnhancedMediaValue,
11
+ } from "@mapomodule/form/types";
12
+
13
+ import type { MediaItem } from "@mapomodule/form/types";
14
+
15
+ export interface MediaFolder {
16
+ id: number;
17
+ name: string;
18
+ /**
19
+ * Id of the parent folder, `null` at the top level. The store reads a
20
+ * parent given as an object (Camomilla's nested `updir`) by its `id`.
21
+ */
22
+ parent?: number | null;
23
+ /**
24
+ * Materialized path of the folder (e.g. "root/images/hero").
25
+ * Camomilla returns it and the breadcrumb uses it for deduplication.
26
+ * Falls back to `id` when absent.
27
+ */
28
+ path?: string;
29
+ }
30
+
31
+ export interface MediaApiResponse {
32
+ media: {
33
+ items: MediaItem[];
34
+ paginator: { page: number; pages: number };
35
+ };
36
+ folders: MediaFolder[];
37
+ parent_folder: MediaFolder | null;
38
+ }
39
+
40
+ export type SelectMode = "none" | "single" | "multi";
41
+
42
+ export interface MediaGetRootParams {
43
+ page?: number;
44
+ folder?: number | null;
45
+ search?: string;
46
+ mime?: string | null;
47
+ all?: boolean;
48
+ }
49
+
50
+ export interface MediaUploadPayload {
51
+ file: File;
52
+ title?: string;
53
+ alt_text?: string;
54
+ description?: string;
55
+ folder?: number | null;
56
+ }
57
+
58
+ /**
59
+ * REST endpoints used by the media store. Configured via
60
+ * `mapo.uikit.media.endpoints` in `nuxt.config.ts` and forwarded to
61
+ * `runtimeConfig.public.mapoMedia`.
62
+ */
63
+ export interface MediaEndpoints {
64
+ /** Single-media CRUD: detail, partialUpdate, delete, upload (POST). Default `/api/media`. */
65
+ media: string;
66
+ /** Folder navigation + CRUD: list (root), detail (enter folder), create, delete. Default `/api/media-folders`. */
67
+ folders: string;
68
+ }
69
+
70
+ /**
71
+ * Context passed to the adapter when building list/detail query params.
72
+ * Values are the **canonical** Mapo params — the adapter maps them to the
73
+ * shape the target backend expects (e.g. `mime` → `fltr=mime_type=`).
74
+ */
75
+ export interface MediaListParamsContext {
76
+ page?: number;
77
+ search?: string;
78
+ mime?: string | null;
79
+ all?: boolean;
80
+ }
81
+
82
+ /**
83
+ * Backend adapter for the media store. Lets integrations (e.g. Camomilla)
84
+ * remap request params and normalize responses without coupling the store to a
85
+ * specific backend. Injected as `$mapoMediaAdapter` by a Nuxt plugin — functions
86
+ * are not serializable through `runtimeConfig`, so this mirrors the
87
+ * `$mapoFormRegistry` pattern.
88
+ *
89
+ * Every method is optional; the default adapter applies plain REST semantics.
90
+ */
91
+ export interface MediaAdapter {
92
+ /**
93
+ * Build the query params object for the `getRoot` list/detail request.
94
+ * @example
95
+ * // Camomilla: { page, search, fltr: 'mime_type=image/png' }
96
+ */
97
+ buildListParams?(ctx: MediaListParamsContext): Record<string, unknown>;
98
+ /**
99
+ * Normalize a raw `getRoot` response (folder list or detail) into the
100
+ * canonical {@link MediaApiResponse} shape. Default = identity.
101
+ */
102
+ parseRootResponse?(raw: unknown): MediaApiResponse;
103
+ /**
104
+ * Build query params for the single-media detail fetch (`openEditor`).
105
+ * @example
106
+ * // Camomilla: { language_code: 'it' }
107
+ */
108
+ buildDetailParams?(ctx: { lang?: string }): Record<string, unknown>;
109
+ /**
110
+ * Map a canonical folder (`{ name, parent }`) to the backend's create/update
111
+ * payload.
112
+ * @example
113
+ * // Camomilla: { title, slug: slugify(title), updir: parent }
114
+ */
115
+ buildFolderPayload?(folder: Partial<MediaFolder>): Record<string, unknown>;
116
+ /**
117
+ * Build the PATCH payload for a media metadata update.
118
+ *
119
+ * `previous` is the media as it was when editing started; the editor always
120
+ * passes it. Default: with `previous`, only the fields that changed, with
121
+ * `translations` narrowed to the changed languages and fields; without it,
122
+ * `{ title, alt_text, description, translations }`. An empty object skips
123
+ * the request.
124
+ */
125
+ buildMediaPatchPayload?(
126
+ media: MediaItem,
127
+ previous?: MediaItem,
128
+ ): Record<string, unknown>;
129
+ /**
130
+ * Build the PATCH payload that moves a media to folder `folderId` (`null`
131
+ * is the root). Default: `{ folder: folderId }`, which Camomilla takes as
132
+ * it is.
133
+ */
134
+ buildMoveMediaPayload?(folderId: number | null): Record<string, unknown>;
135
+ /**
136
+ * Build the multipart PATCH payload for a file replacement.
137
+ * @example
138
+ * // Default REST: { file, maintain_url } — Camomilla: { file, same_url }
139
+ */
140
+ buildReplaceFilePayload?(
141
+ file: File,
142
+ maintainUrl: boolean,
143
+ ): Record<string, unknown>;
144
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Menu Manager types — the canonical tree contract matches the Camomilla
3
+ * `/api/camomilla/menus` payload (v1 parity): a menu is a keyed collection
4
+ * of recursively nested nodes, optionally translated per language.
5
+ */
6
+
7
+ /** Link carried by a menu node: relational (a CMS page) or static (raw URL). */
8
+ export interface MenuNodeLink {
9
+ /** `"RE"` = relational (page picked from the backend), `"ST"` = static URL. */
10
+ link_type?: "RE" | "ST";
11
+ /** Static URL used when `link_type === "ST"`. */
12
+ static?: string;
13
+ /** Content-type id used when `link_type === "RE"`. */
14
+ content_type?: number | string | null;
15
+ /** Routable node id of the linked page when `link_type === "RE"`. */
16
+ url_node?: number | string | null;
17
+ [key: string]: unknown;
18
+ }
19
+
20
+ /** A single node of the menu tree. */
21
+ export interface MenuTreeNode {
22
+ /**
23
+ * Node identity. Nodes created client-side get a random string id;
24
+ * the backend may replace it with a numeric one on save.
25
+ */
26
+ id: string | number;
27
+ title: string;
28
+ link: MenuNodeLink;
29
+ /**
30
+ * Free-form node metadata (e.g. `style`, `target_bank`).
31
+ * `target_bank` keeps the v1/Camomilla key for data compatibility.
32
+ */
33
+ meta: Record<string, unknown>;
34
+ /** Child nodes. */
35
+ nodes: MenuTreeNode[];
36
+ /** Per-field backend validation errors attached by the manager. */
37
+ errors?: Record<string, string[]>;
38
+ [key: string]: unknown;
39
+ }
40
+
41
+ /** Per-language node tree used when the menu is translatable. */
42
+ export interface MenuTranslation {
43
+ nodes: MenuTreeNode[];
44
+ [key: string]: unknown;
45
+ }
46
+
47
+ /** The full menu payload handled by `MapoMenuManager`. */
48
+ export interface MapoMenu {
49
+ id?: number | string;
50
+ /** Unique menu identifier (e.g. `"navbar"`, `"footer"`). */
51
+ key: string;
52
+ enabled?: boolean;
53
+ /** Node tree used when the menu is NOT translatable. */
54
+ nodes?: MenuTreeNode[];
55
+ /** Per-language node trees used when the menu IS translatable. */
56
+ translations?: Record<string, MenuTranslation>;
57
+ [key: string]: unknown;
58
+ }
59
+
60
+ /** Create an empty client-side node with a unique temporary id. */
61
+ export function createMenuNode(
62
+ partial: Partial<MenuTreeNode> = {},
63
+ ): MenuTreeNode {
64
+ return {
65
+ id: Math.random().toString(36).slice(2),
66
+ title: "",
67
+ link: {},
68
+ meta: {},
69
+ nodes: [],
70
+ ...partial,
71
+ };
72
+ }
73
+
74
+ /** Maximum nesting depth of a menu node tree (a flat list = depth 1). */
75
+ export function menuTreeDepth(nodes: MenuTreeNode[]): number {
76
+ if (!nodes.length) return 0;
77
+ return 1 + Math.max(...nodes.map((n) => menuTreeDepth(n.nodes ?? [])));
78
+ }
79
+
80
+ /** Depth-first search for a node id. Returns the node and its ancestor chain. */
81
+ export function findMenuNode(
82
+ nodes: MenuTreeNode[],
83
+ id: string | number,
84
+ parents: MenuTreeNode[] = [],
85
+ ): { node: MenuTreeNode; parents: MenuTreeNode[] } | null {
86
+ for (const node of nodes) {
87
+ if (String(node.id) === String(id)) return { node, parents };
88
+ const found = findMenuNode(node.nodes ?? [], id, [...parents, node]);
89
+ if (found) return found;
90
+ }
91
+ return null;
92
+ }
93
+
94
+ /** Remove a node (by id) anywhere in the tree. Returns `true` when removed. */
95
+ export function removeMenuNode(
96
+ nodes: MenuTreeNode[],
97
+ id: string | number,
98
+ ): boolean {
99
+ const index = nodes.findIndex((n) => String(n.id) === String(id));
100
+ if (index !== -1) {
101
+ nodes.splice(index, 1);
102
+ return true;
103
+ }
104
+ return nodes.some((n) => removeMenuNode(n.nodes ?? [], id));
105
+ }
@@ -0,0 +1,18 @@
1
+ import { useRuntimeConfig } from "#app";
2
+
3
+ /**
4
+ * The app's `mapo.uikit.contentLanguages`: the content languages editors may
5
+ * switch between, in order. Empty when the app sets none, which restricts
6
+ * nothing. Narrow a list with `restrictLanguages` from `./langInfo`.
7
+ *
8
+ * Kept apart from `langInfo.ts`, whose helpers stay free of Nuxt imports.
9
+ */
10
+ export function useContentLanguages(): string[] {
11
+ const runtimeConfig = useRuntimeConfig();
12
+ const uikit = (runtimeConfig.public.mapoUikit ?? {}) as {
13
+ contentLanguages?: unknown;
14
+ };
15
+ const configured = uikit.contentLanguages;
16
+ if (!Array.isArray(configured)) return [];
17
+ return configured.filter((code): code is string => typeof code === "string");
18
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `lang_info`, as served by Camomilla on an endpoint's OPTIONS response.
3
+ *
4
+ * It describes the MODEL, not the site and not a record: a multilingual site can
5
+ * still expose models nobody registered for translation, and rendering a
6
+ * language switcher for those invites the user to type values the backend will
7
+ * drop on save.
8
+ *
9
+ * OPTIONS rather than the record payload because it is metadata, and because a
10
+ * "create new" form has no record to read it from.
11
+ */
12
+ export interface LangInfo {
13
+ /** Whether this model is registered for translation at all. */
14
+ translatable?: boolean;
15
+ /** Codes usable for THIS model. Empty when it is not translatable. */
16
+ languages?: string[];
17
+ /** What the site supports. Present for context; not model-specific. */
18
+ site_languages?: string[];
19
+ default?: string;
20
+ active?: string;
21
+ }
22
+
23
+ /**
24
+ * Language codes a model can be translated into, read from its OPTIONS metadata.
25
+ *
26
+ * Returns `[]` — meaning "render no language switcher" — when the model is not
27
+ * translatable and when `lang_info` is absent entirely. A backend that does not
28
+ * publish the field cannot be assumed multilingual.
29
+ */
30
+ export function languagesFromMetadata(metadata: unknown): string[] {
31
+ const info = (metadata as Record<string, unknown> | null | undefined)
32
+ ?.lang_info as LangInfo | undefined;
33
+ if (!info || info.translatable === false) return [];
34
+ if (!Array.isArray(info.languages)) return [];
35
+ return info.languages.filter(
36
+ (code): code is string => typeof code === "string",
37
+ );
38
+ }
39
+
40
+ /**
41
+ * `languages` narrowed to `allowed` (the app's `mapo.uikit.contentLanguages`),
42
+ * in `allowed`'s order, so its first language is the one editing starts on.
43
+ * An empty `allowed` restricts nothing. It never adds a language the list does
44
+ * not offer: the backend would drop whatever is typed for it.
45
+ */
46
+ export function restrictLanguages(
47
+ languages: string[],
48
+ allowed: string[],
49
+ ): string[] {
50
+ if (!allowed.length) return languages;
51
+ return allowed.filter((lang) => languages.includes(lang));
52
+ }
53
+
54
+ /**
55
+ * The language to start from: `preferred` when the list offers it, else the
56
+ * first one. Returns `""` for an empty list, which callers read as "this
57
+ * model is not translated".
58
+ */
59
+ export function pickLanguage(languages: string[], preferred?: string): string {
60
+ if (!preferred) return languages[0] ?? "";
61
+ const isOffered = languages.includes(preferred);
62
+ return isOffered ? preferred : (languages[0] ?? "");
63
+ }
@@ -0,0 +1,54 @@
1
+ /** One sort key as `UTable` holds it: the column id and the direction. */
2
+ export interface TableSort {
3
+ id: string;
4
+ desc: boolean;
5
+ }
6
+
7
+ /**
8
+ * The page size that stands for "all rows". A plain number, so the paging
9
+ * arithmetic and the in-memory slicing keep working unchanged.
10
+ */
11
+ export const ALL_ROWS = Number.MAX_SAFE_INTEGER;
12
+
13
+ /** A `pageSizeOptions` entry as the table stores it: `"all"` → {@link ALL_ROWS}. */
14
+ export function toPageSize(option: number | "all"): number {
15
+ return option === "all" ? ALL_ROWS : option;
16
+ }
17
+
18
+ /** Reads `page_size` from the URL: `all`, or a positive number, else `fallback`. */
19
+ export function parsePageSize(value: unknown, fallback: number): number {
20
+ if (value === "all") return ALL_ROWS;
21
+ const size = Number(value);
22
+ return Number.isFinite(size) && size > 0 ? size : fallback;
23
+ }
24
+
25
+ /** Writes a page size to the URL: {@link ALL_ROWS} as `all`. */
26
+ export function formatPageSize(size: number): string {
27
+ return size === ALL_ROWS ? "all" : String(size);
28
+ }
29
+
30
+ /**
31
+ * The sorting after a click on a sortable header. The column goes from
32
+ * unsorted to ascending, to descending, and back to unsorted, so the natural
33
+ * order (needed by drag reorder) is one click away. It replaces any other key.
34
+ */
35
+ export function nextSorting(
36
+ sorting: TableSort[],
37
+ columnId: string,
38
+ ): TableSort[] {
39
+ const current = sorting.find((sort) => sort.id === columnId);
40
+ if (!current) return [{ id: columnId, desc: false }];
41
+ if (!current.desc) return [{ id: columnId, desc: true }];
42
+ return [];
43
+ }
44
+
45
+ /**
46
+ * The `ordering` param for a sorting: comma-separated keys, `-` for descending.
47
+ * A dotted key becomes a Django lookup (`category.name` → `category__name`),
48
+ * the way DRF's OrderingFilter reaches a field of a related object.
49
+ */
50
+ export function orderingParam(sorting: TableSort[]): string {
51
+ return sorting
52
+ .map((sort) => `${sort.desc ? "-" : ""}${sort.id.split(".").join("__")}`)
53
+ .join(",");
54
+ }
@@ -0,0 +1,29 @@
1
+ import type { MediaFolder } from "../types/media.js";
2
+
3
+ /**
4
+ * Data type of every drag started inside the media manager: a gallery card,
5
+ * the bulk selection, a folder of the tree. Drop zones for files from the
6
+ * computer ignore it, since Chrome reports an image dragged from the page as
7
+ * "Files" too.
8
+ */
9
+ export const MEDIA_DRAG_TYPE = "application/x-mapo-media-drag";
10
+
11
+ /** What is being dragged inside the media manager. */
12
+ export type MediaDrag =
13
+ | { kind: "media"; ids: number[] }
14
+ | { kind: "folder"; folder: MediaFolder };
15
+
16
+ /** Whether `event` drags something from inside the media manager. */
17
+ export function isMediaDrag(event: DragEvent): boolean {
18
+ const types = Array.from(event.dataTransfer?.types ?? []);
19
+ return types.includes(MEDIA_DRAG_TYPE);
20
+ }
21
+
22
+ /** Starts dragging `drag`: the data type that marks it, and a move. */
23
+ export function startMediaDrag(event: DragEvent, drag: MediaDrag): void {
24
+ const transfer = event.dataTransfer;
25
+ if (!transfer) return;
26
+ // Firefox starts a drag only once some data is set.
27
+ transfer.setData(MEDIA_DRAG_TYPE, JSON.stringify(drag));
28
+ transfer.effectAllowed = "move";
29
+ }
@@ -0,0 +1,182 @@
1
+ import type { TreeItem } from "@nuxt/ui";
2
+ import type { MediaFolder } from "../types/media.js";
3
+
4
+ /** Key of the media root in the folder tree and in the store's folder cache. */
5
+ export const ROOT_FOLDER_KEY = "root";
6
+
7
+ /**
8
+ * Key of a folder in the folder tree and in the store's `folderChildren`
9
+ * cache: its id, or `ROOT_FOLDER_KEY` for the root (`null`).
10
+ */
11
+ export function folderKey(id: number | null | undefined): string {
12
+ return id == null ? ROOT_FOLDER_KEY : String(id);
13
+ }
14
+
15
+ /**
16
+ * `folder` with its `parent` as an id, as the store and the folder tree read
17
+ * it. Camomilla serializes a folder's parent (`updir`) as the whole parent
18
+ * folder, and an adapter may hand that object on as `parent`; it is read by
19
+ * its `id` (none is the root).
20
+ */
21
+ export function canonicalFolder(folder: MediaFolder): MediaFolder {
22
+ const parent: unknown = folder.parent;
23
+ const isObject = typeof parent === "object";
24
+ const isNull = parent === null;
25
+ if (!isObject || isNull) return folder;
26
+ const parentId = (parent as { id?: number | null }).id ?? null;
27
+ return { ...folder, parent: parentId };
28
+ }
29
+
30
+ /** A node of the folder tree: the root (`folder: null`), a folder, or the placeholder of a branch still loading. */
31
+ export interface FolderNode extends TreeItem {
32
+ key: string;
33
+ label: string;
34
+ folder: MediaFolder | null;
35
+ children?: FolderNode[];
36
+ /** Placeholder in a branch whose subfolders are not loaded yet. */
37
+ pending?: boolean;
38
+ }
39
+
40
+ /**
41
+ * The folder tree, from the store's `folderChildren` cache: the root, then the
42
+ * folders. A branch not loaded yet holds one placeholder child, so it shows as
43
+ * expandable; a loaded branch with no subfolders is a leaf. A folder met twice
44
+ * on the same path (a cycle in the backend's data) is not expanded again.
45
+ *
46
+ * `exclude` leaves out folders and everything under them, as a destination
47
+ * picker needs when a folder cannot go inside itself.
48
+ */
49
+ export function buildFolderTree(
50
+ folderChildren: Record<string, MediaFolder[]>,
51
+ labels: { root: string; loading: string },
52
+ options: { exclude?: ReadonlySet<number> } = {},
53
+ ): FolderNode[] {
54
+ const excluded = options.exclude ?? new Set<number>();
55
+ const branch = (
56
+ parentKey: string,
57
+ seen: Set<string>,
58
+ ): FolderNode[] | undefined => {
59
+ const loaded = folderChildren[parentKey];
60
+ if (!loaded) {
61
+ const placeholder: FolderNode = {
62
+ key: `${parentKey}:pending`,
63
+ label: labels.loading,
64
+ folder: null,
65
+ pending: true,
66
+ };
67
+ return [placeholder];
68
+ }
69
+ const shown = loaded.filter((folder) => !excluded.has(folder.id));
70
+ if (!shown.length) return undefined;
71
+ return shown.map((folder) => {
72
+ const key = folderKey(folder.id);
73
+ const isRepeated = seen.has(key);
74
+ const children = isRepeated
75
+ ? undefined
76
+ : branch(key, new Set(seen).add(key));
77
+ return { key, label: folder.name, folder, children };
78
+ });
79
+ };
80
+
81
+ const root: FolderNode = {
82
+ key: ROOT_FOLDER_KEY,
83
+ label: labels.root,
84
+ folder: null,
85
+ children: branch(ROOT_FOLDER_KEY, new Set([ROOT_FOLDER_KEY])),
86
+ };
87
+ return [root];
88
+ }
89
+
90
+ /** The node with `key` in the tree, at any depth. */
91
+ export function findFolderNode(
92
+ nodes: FolderNode[] | undefined,
93
+ key: string,
94
+ ): FolderNode | undefined {
95
+ for (const node of nodes ?? []) {
96
+ if (node.key === key) return node;
97
+ const inner = findFolderNode(node.children, key);
98
+ if (inner) return inner;
99
+ }
100
+ return undefined;
101
+ }
102
+
103
+ /** Icon of a tree node: a spinner while loading, an open folder when it shows children. */
104
+ export function folderNodeIcon(node: FolderNode, isOpen: boolean): string {
105
+ if (node.pending) return "i-lucide-loader-circle";
106
+ const showsChildren = isOpen && !!node.children?.length;
107
+ return showsChildren ? "i-lucide-folder-open" : "i-lucide-folder";
108
+ }
109
+
110
+ /**
111
+ * The parent of `folder` as the tree shows it: the cached branch that lists
112
+ * it, else its `parent`, which a backend may leave out.
113
+ */
114
+ export function folderParentId(
115
+ folderChildren: Record<string, MediaFolder[]>,
116
+ folder: MediaFolder,
117
+ ): number | null {
118
+ const entries = Object.entries(folderChildren);
119
+ const branch = entries.find(([, children]) =>
120
+ children.some((child) => child.id === folder.id),
121
+ );
122
+ if (!branch) return folder.parent ?? null;
123
+ const isRoot = branch[0] === ROOT_FOLDER_KEY;
124
+ return isRoot ? null : Number(branch[0]);
125
+ }
126
+
127
+ /**
128
+ * Whether `folder` can move into folder `targetId` (the root when `null`):
129
+ * not into itself or one of its subfolders, as far as the cache knows the
130
+ * tree, and not where it already is.
131
+ */
132
+ export function canMoveFolderTo(
133
+ folderChildren: Record<string, MediaFolder[]>,
134
+ folder: MediaFolder,
135
+ targetId: number | null,
136
+ ): boolean {
137
+ const isSelf = targetId === folder.id;
138
+ if (isSelf) return false;
139
+ const targetPath =
140
+ targetId == null ? [] : (folderPath(folderChildren, targetId) ?? []);
141
+ const isInside = targetPath.some((f) => f.id === folder.id);
142
+ if (isInside) return false;
143
+ const staysPut = folderParentId(folderChildren, folder) === targetId;
144
+ return !staysPut;
145
+ }
146
+
147
+ /**
148
+ * The path to folder `id` read from the `folderChildren` cache: its ancestors
149
+ * from the top level down, then the folder itself. `undefined` when the cache
150
+ * cannot place it, or one of its ancestors, or meets a cycle.
151
+ *
152
+ * Breadcrumbs need it once the tree lets the user jump to any folder: a
153
+ * folder opened from another branch is not a child of the one on screen.
154
+ */
155
+ export function folderPath(
156
+ folderChildren: Record<string, MediaFolder[]>,
157
+ id: number,
158
+ ): MediaFolder[] | undefined {
159
+ const parentOf = new Map<number, number | null>();
160
+ const byId = new Map<number, MediaFolder>();
161
+ for (const [key, children] of Object.entries(folderChildren)) {
162
+ const parentId = key === ROOT_FOLDER_KEY ? null : Number(key);
163
+ for (const child of children) {
164
+ parentOf.set(child.id, parentId);
165
+ byId.set(child.id, child);
166
+ }
167
+ }
168
+
169
+ const path: MediaFolder[] = [];
170
+ const seen = new Set<number>();
171
+ let currentId: number | null = id;
172
+ while (currentId != null) {
173
+ const folder = byId.get(currentId);
174
+ const isKnown = folder !== undefined;
175
+ const isCycle = seen.has(currentId);
176
+ if (!isKnown || isCycle) return undefined;
177
+ path.unshift(folder);
178
+ seen.add(currentId);
179
+ currentId = parentOf.get(currentId) ?? null;
180
+ }
181
+ return path;
182
+ }