@mapomodule/uikit 2.0.0-beta.17 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts.map +1 -0
- package/dist/__tests__/mediaDrag.test.d.ts +2 -0
- package/dist/__tests__/mediaDrag.test.d.ts.map +1 -0
- package/dist/__tests__/mediaFolders.test.d.ts +2 -0
- package/dist/__tests__/mediaFolders.test.d.ts.map +1 -0
- package/dist/__tests__/mediaMetadata.test.d.ts +2 -0
- package/dist/__tests__/mediaMetadata.test.d.ts.map +1 -0
- package/dist/__tests__/mediaStore.test.d.ts +2 -0
- package/dist/__tests__/mediaStore.test.d.ts.map +1 -0
- package/dist/__tests__/mediaUrl.test.d.ts +2 -0
- package/dist/__tests__/mediaUrl.test.d.ts.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/module.d.mts +17 -0
- package/dist/module.d.ts +16 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -0
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts +1 -0
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -1
- package/dist/runtime/adapters/defaultMediaAdapter.js +6 -1
- package/dist/runtime/components/MapoDetail.vue +9 -5
- package/dist/runtime/components/MapoDetail.vue.d.ts +3 -3
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue +17 -6
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +7 -1
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaEditor.vue +94 -38
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFolderPicker.vue +129 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts +33 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolders.vue +254 -72
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaGallery.vue +228 -143
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts +5 -1
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManager.vue +6 -2
- package/dist/runtime/components/MapoMediaManager.vue.d.ts +11 -2
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +1 -1
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaPreview.vue +5 -3
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaUploader.vue +5 -1
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuManager.vue +13 -5
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -1
- package/dist/runtime/stores/media.d.ts +43 -6
- package/dist/runtime/stores/media.d.ts.map +1 -1
- package/dist/runtime/stores/media.js +201 -16
- package/dist/runtime/types/media.d.ts +17 -2
- package/dist/runtime/types/media.d.ts.map +1 -1
- package/dist/runtime/utils/contentLanguages.d.ts +9 -0
- package/dist/runtime/utils/contentLanguages.d.ts.map +1 -0
- package/dist/runtime/utils/contentLanguages.js +8 -0
- package/dist/runtime/utils/langInfo.d.ts +13 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -1
- package/dist/runtime/utils/langInfo.js +9 -0
- package/dist/runtime/utils/mediaDrag.d.ts +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts.map +1 -0
- package/dist/runtime/utils/mediaDrag.js +11 -0
- package/dist/runtime/utils/mediaFolders.d.ts +65 -0
- package/dist/runtime/utils/mediaFolders.d.ts.map +1 -0
- package/dist/runtime/utils/mediaFolders.js +97 -0
- package/dist/runtime/utils/mediaMetadata.d.ts +39 -0
- package/dist/runtime/utils/mediaMetadata.d.ts.map +1 -0
- package/dist/runtime/utils/mediaMetadata.js +97 -0
- package/dist/runtime/utils/mediaUrl.d.ts +16 -0
- package/dist/runtime/utils/mediaUrl.d.ts.map +1 -0
- package/dist/runtime/utils/mediaUrl.js +12 -0
- package/package.json +3 -3
- package/src/__tests__/MapoDetail.component.test.ts +64 -1
- package/src/__tests__/MapoMediaEditor.component.test.ts +447 -0
- package/src/__tests__/MapoMediaFolderPicker.component.test.ts +220 -0
- package/src/__tests__/MapoMediaFolders.component.test.ts +519 -0
- package/src/__tests__/MapoMediaGallery.component.test.ts +211 -0
- package/src/__tests__/MapoMediaUploadHandover.component.test.ts +241 -0
- package/src/__tests__/MapoMenuManager.component.test.ts +175 -0
- package/src/__tests__/langInfo.test.ts +38 -1
- package/src/__tests__/mediaDrag.test.ts +42 -0
- package/src/__tests__/mediaFolders.test.ts +204 -0
- package/src/__tests__/mediaMetadata.test.ts +169 -0
- package/src/__tests__/mediaStore.test.ts +569 -0
- package/src/__tests__/mediaUrl.test.ts +44 -0
- package/src/index.ts +1 -0
- package/src/module.ts +25 -0
- package/src/runtime/adapters/defaultMediaAdapter.ts +11 -1
- package/src/runtime/components/MapoDetail.vue +21 -9
- package/src/runtime/components/MapoDropArea.vue +24 -6
- package/src/runtime/components/MapoListQuickEdit.vue +10 -1
- package/src/runtime/components/MapoMediaEditor.vue +131 -47
- package/src/runtime/components/MapoMediaFolderPicker.vue +176 -0
- package/src/runtime/components/MapoMediaFolders.vue +311 -72
- package/src/runtime/components/MapoMediaGallery.vue +263 -152
- package/src/runtime/components/MapoMediaManager.vue +16 -2
- package/src/runtime/components/MapoMediaPreview.vue +8 -3
- package/src/runtime/components/MapoMediaUploader.vue +8 -1
- package/src/runtime/components/MapoMenuManager.vue +24 -7
- package/src/runtime/stores/media.ts +335 -21
- package/src/runtime/types/media.ts +20 -2
- package/src/runtime/utils/contentLanguages.ts +18 -0
- package/src/runtime/utils/langInfo.ts +25 -0
- package/src/runtime/utils/mediaDrag.ts +29 -0
- package/src/runtime/utils/mediaFolders.ts +182 -0
- package/src/runtime/utils/mediaMetadata.ts +165 -0
- package/src/runtime/utils/mediaUrl.ts +30 -0
|
@@ -6,3 +6,12 @@ export function languagesFromMetadata(metadata) {
|
|
|
6
6
|
(code) => typeof code === "string"
|
|
7
7
|
);
|
|
8
8
|
}
|
|
9
|
+
export function restrictLanguages(languages, allowed) {
|
|
10
|
+
if (!allowed.length) return languages;
|
|
11
|
+
return allowed.filter((lang) => languages.includes(lang));
|
|
12
|
+
}
|
|
13
|
+
export function pickLanguage(languages, preferred) {
|
|
14
|
+
if (!preferred) return languages[0] ?? "";
|
|
15
|
+
const isOffered = languages.includes(preferred);
|
|
16
|
+
return isOffered ? preferred : languages[0] ?? "";
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MediaFolder } from "../types/media.js";
|
|
2
|
+
/**
|
|
3
|
+
* Data type of every drag started inside the media manager: a gallery card,
|
|
4
|
+
* the bulk selection, a folder of the tree. Drop zones for files from the
|
|
5
|
+
* computer ignore it, since Chrome reports an image dragged from the page as
|
|
6
|
+
* "Files" too.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MEDIA_DRAG_TYPE = "application/x-mapo-media-drag";
|
|
9
|
+
/** What is being dragged inside the media manager. */
|
|
10
|
+
export type MediaDrag = {
|
|
11
|
+
kind: "media";
|
|
12
|
+
ids: number[];
|
|
13
|
+
} | {
|
|
14
|
+
kind: "folder";
|
|
15
|
+
folder: MediaFolder;
|
|
16
|
+
};
|
|
17
|
+
/** Whether `event` drags something from inside the media manager. */
|
|
18
|
+
export declare function isMediaDrag(event: DragEvent): boolean;
|
|
19
|
+
/** Starts dragging `drag`: the data type that marks it, and a move. */
|
|
20
|
+
export declare function startMediaDrag(event: DragEvent, drag: MediaDrag): void;
|
|
21
|
+
//# sourceMappingURL=mediaDrag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaDrag.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/mediaDrag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,kCAAkC,CAAC;AAE/D,sDAAsD;AACtD,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,EAAE,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC;AAE5C,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAGrD;AAED,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,CAMtE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const MEDIA_DRAG_TYPE = "application/x-mapo-media-drag";
|
|
2
|
+
export function isMediaDrag(event) {
|
|
3
|
+
const types = Array.from(event.dataTransfer?.types ?? []);
|
|
4
|
+
return types.includes(MEDIA_DRAG_TYPE);
|
|
5
|
+
}
|
|
6
|
+
export function startMediaDrag(event, drag) {
|
|
7
|
+
const transfer = event.dataTransfer;
|
|
8
|
+
if (!transfer) return;
|
|
9
|
+
transfer.setData(MEDIA_DRAG_TYPE, JSON.stringify(drag));
|
|
10
|
+
transfer.effectAllowed = "move";
|
|
11
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { TreeItem } from "@nuxt/ui";
|
|
2
|
+
import type { MediaFolder } from "../types/media.js";
|
|
3
|
+
/** Key of the media root in the folder tree and in the store's folder cache. */
|
|
4
|
+
export declare const ROOT_FOLDER_KEY = "root";
|
|
5
|
+
/**
|
|
6
|
+
* Key of a folder in the folder tree and in the store's `folderChildren`
|
|
7
|
+
* cache: its id, or `ROOT_FOLDER_KEY` for the root (`null`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function folderKey(id: number | null | undefined): string;
|
|
10
|
+
/**
|
|
11
|
+
* `folder` with its `parent` as an id, as the store and the folder tree read
|
|
12
|
+
* it. Camomilla serializes a folder's parent (`updir`) as the whole parent
|
|
13
|
+
* folder, and an adapter may hand that object on as `parent`; it is read by
|
|
14
|
+
* its `id` (none is the root).
|
|
15
|
+
*/
|
|
16
|
+
export declare function canonicalFolder(folder: MediaFolder): MediaFolder;
|
|
17
|
+
/** A node of the folder tree: the root (`folder: null`), a folder, or the placeholder of a branch still loading. */
|
|
18
|
+
export interface FolderNode extends TreeItem {
|
|
19
|
+
key: string;
|
|
20
|
+
label: string;
|
|
21
|
+
folder: MediaFolder | null;
|
|
22
|
+
children?: FolderNode[];
|
|
23
|
+
/** Placeholder in a branch whose subfolders are not loaded yet. */
|
|
24
|
+
pending?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The folder tree, from the store's `folderChildren` cache: the root, then the
|
|
28
|
+
* folders. A branch not loaded yet holds one placeholder child, so it shows as
|
|
29
|
+
* expandable; a loaded branch with no subfolders is a leaf. A folder met twice
|
|
30
|
+
* on the same path (a cycle in the backend's data) is not expanded again.
|
|
31
|
+
*
|
|
32
|
+
* `exclude` leaves out folders and everything under them, as a destination
|
|
33
|
+
* picker needs when a folder cannot go inside itself.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildFolderTree(folderChildren: Record<string, MediaFolder[]>, labels: {
|
|
36
|
+
root: string;
|
|
37
|
+
loading: string;
|
|
38
|
+
}, options?: {
|
|
39
|
+
exclude?: ReadonlySet<number>;
|
|
40
|
+
}): FolderNode[];
|
|
41
|
+
/** The node with `key` in the tree, at any depth. */
|
|
42
|
+
export declare function findFolderNode(nodes: FolderNode[] | undefined, key: string): FolderNode | undefined;
|
|
43
|
+
/** Icon of a tree node: a spinner while loading, an open folder when it shows children. */
|
|
44
|
+
export declare function folderNodeIcon(node: FolderNode, isOpen: boolean): string;
|
|
45
|
+
/**
|
|
46
|
+
* The parent of `folder` as the tree shows it: the cached branch that lists
|
|
47
|
+
* it, else its `parent`, which a backend may leave out.
|
|
48
|
+
*/
|
|
49
|
+
export declare function folderParentId(folderChildren: Record<string, MediaFolder[]>, folder: MediaFolder): number | null;
|
|
50
|
+
/**
|
|
51
|
+
* Whether `folder` can move into folder `targetId` (the root when `null`):
|
|
52
|
+
* not into itself or one of its subfolders, as far as the cache knows the
|
|
53
|
+
* tree, and not where it already is.
|
|
54
|
+
*/
|
|
55
|
+
export declare function canMoveFolderTo(folderChildren: Record<string, MediaFolder[]>, folder: MediaFolder, targetId: number | null): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The path to folder `id` read from the `folderChildren` cache: its ancestors
|
|
58
|
+
* from the top level down, then the folder itself. `undefined` when the cache
|
|
59
|
+
* cannot place it, or one of its ancestors, or meets a cycle.
|
|
60
|
+
*
|
|
61
|
+
* Breadcrumbs need it once the tree lets the user jump to any folder: a
|
|
62
|
+
* folder opened from another branch is not a child of the one on screen.
|
|
63
|
+
*/
|
|
64
|
+
export declare function folderPath(folderChildren: Record<string, MediaFolder[]>, id: number): MediaFolder[] | undefined;
|
|
65
|
+
//# sourceMappingURL=mediaFolders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaFolders.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/mediaFolders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,gFAAgF;AAChF,eAAO,MAAM,eAAe,SAAS,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAOhE;AAED,oHAAoH;AACpH,MAAM,WAAW,UAAW,SAAQ,QAAQ;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,mEAAmE;IACnE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAC7C,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACzC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GAC9C,UAAU,EAAE,CAmCd;AAED,qDAAqD;AACrD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,EAAE,GAAG,SAAS,EAC/B,GAAG,EAAE,MAAM,GACV,UAAU,GAAG,SAAS,CAOxB;AAED,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAIxE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAC7C,MAAM,EAAE,WAAW,GAClB,MAAM,GAAG,IAAI,CAQf;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAC7C,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAST;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAC7C,EAAE,EAAE,MAAM,GACT,WAAW,EAAE,GAAG,SAAS,CAwB3B"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const ROOT_FOLDER_KEY = "root";
|
|
2
|
+
export function folderKey(id) {
|
|
3
|
+
return id == null ? ROOT_FOLDER_KEY : String(id);
|
|
4
|
+
}
|
|
5
|
+
export function canonicalFolder(folder) {
|
|
6
|
+
const parent = folder.parent;
|
|
7
|
+
const isObject = typeof parent === "object";
|
|
8
|
+
const isNull = parent === null;
|
|
9
|
+
if (!isObject || isNull) return folder;
|
|
10
|
+
const parentId = parent.id ?? null;
|
|
11
|
+
return { ...folder, parent: parentId };
|
|
12
|
+
}
|
|
13
|
+
export function buildFolderTree(folderChildren, labels, options = {}) {
|
|
14
|
+
const excluded = options.exclude ?? /* @__PURE__ */ new Set();
|
|
15
|
+
const branch = (parentKey, seen) => {
|
|
16
|
+
const loaded = folderChildren[parentKey];
|
|
17
|
+
if (!loaded) {
|
|
18
|
+
const placeholder = {
|
|
19
|
+
key: `${parentKey}:pending`,
|
|
20
|
+
label: labels.loading,
|
|
21
|
+
folder: null,
|
|
22
|
+
pending: true
|
|
23
|
+
};
|
|
24
|
+
return [placeholder];
|
|
25
|
+
}
|
|
26
|
+
const shown = loaded.filter((folder) => !excluded.has(folder.id));
|
|
27
|
+
if (!shown.length) return void 0;
|
|
28
|
+
return shown.map((folder) => {
|
|
29
|
+
const key = folderKey(folder.id);
|
|
30
|
+
const isRepeated = seen.has(key);
|
|
31
|
+
const children = isRepeated ? void 0 : branch(key, new Set(seen).add(key));
|
|
32
|
+
return { key, label: folder.name, folder, children };
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const root = {
|
|
36
|
+
key: ROOT_FOLDER_KEY,
|
|
37
|
+
label: labels.root,
|
|
38
|
+
folder: null,
|
|
39
|
+
children: branch(ROOT_FOLDER_KEY, /* @__PURE__ */ new Set([ROOT_FOLDER_KEY]))
|
|
40
|
+
};
|
|
41
|
+
return [root];
|
|
42
|
+
}
|
|
43
|
+
export function findFolderNode(nodes, key) {
|
|
44
|
+
for (const node of nodes ?? []) {
|
|
45
|
+
if (node.key === key) return node;
|
|
46
|
+
const inner = findFolderNode(node.children, key);
|
|
47
|
+
if (inner) return inner;
|
|
48
|
+
}
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
export function folderNodeIcon(node, isOpen) {
|
|
52
|
+
if (node.pending) return "i-lucide-loader-circle";
|
|
53
|
+
const showsChildren = isOpen && !!node.children?.length;
|
|
54
|
+
return showsChildren ? "i-lucide-folder-open" : "i-lucide-folder";
|
|
55
|
+
}
|
|
56
|
+
export function folderParentId(folderChildren, folder) {
|
|
57
|
+
const entries = Object.entries(folderChildren);
|
|
58
|
+
const branch = entries.find(
|
|
59
|
+
([, children]) => children.some((child) => child.id === folder.id)
|
|
60
|
+
);
|
|
61
|
+
if (!branch) return folder.parent ?? null;
|
|
62
|
+
const isRoot = branch[0] === ROOT_FOLDER_KEY;
|
|
63
|
+
return isRoot ? null : Number(branch[0]);
|
|
64
|
+
}
|
|
65
|
+
export function canMoveFolderTo(folderChildren, folder, targetId) {
|
|
66
|
+
const isSelf = targetId === folder.id;
|
|
67
|
+
if (isSelf) return false;
|
|
68
|
+
const targetPath = targetId == null ? [] : folderPath(folderChildren, targetId) ?? [];
|
|
69
|
+
const isInside = targetPath.some((f) => f.id === folder.id);
|
|
70
|
+
if (isInside) return false;
|
|
71
|
+
const staysPut = folderParentId(folderChildren, folder) === targetId;
|
|
72
|
+
return !staysPut;
|
|
73
|
+
}
|
|
74
|
+
export function folderPath(folderChildren, id) {
|
|
75
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
76
|
+
const byId = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const [key, children] of Object.entries(folderChildren)) {
|
|
78
|
+
const parentId = key === ROOT_FOLDER_KEY ? null : Number(key);
|
|
79
|
+
for (const child of children) {
|
|
80
|
+
parentOf.set(child.id, parentId);
|
|
81
|
+
byId.set(child.id, child);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const path = [];
|
|
85
|
+
const seen = /* @__PURE__ */ new Set();
|
|
86
|
+
let currentId = id;
|
|
87
|
+
while (currentId != null) {
|
|
88
|
+
const folder = byId.get(currentId);
|
|
89
|
+
const isKnown = folder !== void 0;
|
|
90
|
+
const isCycle = seen.has(currentId);
|
|
91
|
+
if (!isKnown || isCycle) return void 0;
|
|
92
|
+
path.unshift(folder);
|
|
93
|
+
seen.add(currentId);
|
|
94
|
+
currentId = parentOf.get(currentId) ?? null;
|
|
95
|
+
}
|
|
96
|
+
return path;
|
|
97
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MediaItem, MediaUploadPayload } from "../types/media.js";
|
|
2
|
+
/** The text metadata of a media: the fields the editor and the uploader fill. */
|
|
3
|
+
export declare const MEDIA_METADATA_FIELDS: readonly ["title", "alt_text", "description"];
|
|
4
|
+
export type MediaMetadataField = (typeof MEDIA_METADATA_FIELDS)[number];
|
|
5
|
+
/**
|
|
6
|
+
* The metadata of `media` that differs from `previous`, as a PATCH body: plain
|
|
7
|
+
* fields, and `translations` narrowed to the languages and fields that changed.
|
|
8
|
+
*
|
|
9
|
+
* A full body breaks translated media in two ways. A backend that translates
|
|
10
|
+
* media (Camomilla, through django-modeltranslation) maps a plain field and its
|
|
11
|
+
* active-language translation to the same column, so a body carrying both
|
|
12
|
+
* writes whichever the backend applies last, and Camomilla applies the
|
|
13
|
+
* translations, holding the values read when the editor opened. And every other
|
|
14
|
+
* language is rewritten with those values, over any change made since.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mediaMetadataPatch(media: MediaItem, previous: MediaItem): Record<string, unknown>;
|
|
17
|
+
/** The text metadata of a media, to carry edits over a fresh server copy. */
|
|
18
|
+
export declare function pickMetadata(media: MediaItem): Pick<MediaItem, MediaMetadataField | "translations">;
|
|
19
|
+
/**
|
|
20
|
+
* The body of an upload request, before the multipart encoding.
|
|
21
|
+
*
|
|
22
|
+
* With a `lang`, the text metadata goes into `translations[lang]`: a backend
|
|
23
|
+
* that translates media ignores plain translatable fields (Camomilla drops them
|
|
24
|
+
* on write), and the upload would lose its title and alt text. Without one it
|
|
25
|
+
* stays in plain fields. Empty values are left out.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildUploadBody(payload: MediaUploadPayload, lang?: string): Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Lines for an error toast, out of a DRF error body: `Label: message` for each
|
|
30
|
+
* field.
|
|
31
|
+
*
|
|
32
|
+
* Covers the shapes a media save fails with: plain fields (`title`),
|
|
33
|
+
* per-language columns (`title_it`, as Camomilla reports them) and nested
|
|
34
|
+
* translations (`translations.it.title`). `detail` and `non_field_errors` are
|
|
35
|
+
* about the whole request and show without a label; a field missing from
|
|
36
|
+
* `labels` shows its key.
|
|
37
|
+
*/
|
|
38
|
+
export declare function describeMediaErrors(data: unknown, labels: Record<string, string>): string[];
|
|
39
|
+
//# sourceMappingURL=mediaMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaMetadata.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/mediaMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,+CAIxB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAUxE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,SAAS,GAClB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqBzB;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,GACf,IAAI,CAAC,SAAS,EAAE,kBAAkB,GAAG,cAAc,CAAC,CAOtD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,kBAAkB,EAC3B,IAAI,CAAC,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAczB;AA2BD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,MAAM,EAAE,CA+BV"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const MEDIA_METADATA_FIELDS = [
|
|
2
|
+
"title",
|
|
3
|
+
"alt_text",
|
|
4
|
+
"description"
|
|
5
|
+
];
|
|
6
|
+
function sameValue(a, b) {
|
|
7
|
+
return (a ?? "") === (b ?? "");
|
|
8
|
+
}
|
|
9
|
+
export function mediaMetadataPatch(media, previous) {
|
|
10
|
+
const patch = {};
|
|
11
|
+
for (const field of MEDIA_METADATA_FIELDS) {
|
|
12
|
+
if (sameValue(media[field], previous[field])) continue;
|
|
13
|
+
patch[field] = media[field] ?? "";
|
|
14
|
+
}
|
|
15
|
+
const translations = {};
|
|
16
|
+
for (const [lang, values] of Object.entries(media.translations ?? {})) {
|
|
17
|
+
const before = previous.translations?.[lang] ?? {};
|
|
18
|
+
for (const field of MEDIA_METADATA_FIELDS) {
|
|
19
|
+
const value = values?.[field];
|
|
20
|
+
if (sameValue(value, before[field])) continue;
|
|
21
|
+
const changed = translations[lang] ??= {};
|
|
22
|
+
changed[field] = value ?? "";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const hasTranslations = Object.keys(translations).length > 0;
|
|
26
|
+
if (hasTranslations) patch.translations = translations;
|
|
27
|
+
return patch;
|
|
28
|
+
}
|
|
29
|
+
export function pickMetadata(media) {
|
|
30
|
+
return {
|
|
31
|
+
title: media.title,
|
|
32
|
+
alt_text: media.alt_text,
|
|
33
|
+
description: media.description,
|
|
34
|
+
translations: media.translations
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function buildUploadBody(payload, lang) {
|
|
38
|
+
const body = { file: payload.file };
|
|
39
|
+
const metadata = {};
|
|
40
|
+
for (const field of MEDIA_METADATA_FIELDS) {
|
|
41
|
+
const value = payload[field];
|
|
42
|
+
if (value) metadata[field] = value;
|
|
43
|
+
}
|
|
44
|
+
const hasMetadata = Object.keys(metadata).length > 0;
|
|
45
|
+
if (hasMetadata && lang) body.translations = { [lang]: metadata };
|
|
46
|
+
else Object.assign(body, metadata);
|
|
47
|
+
if (payload.folder != null) body.folder = payload.folder;
|
|
48
|
+
return body;
|
|
49
|
+
}
|
|
50
|
+
const GENERAL_ERROR_KEYS = /* @__PURE__ */ new Set(["detail", "non_field_errors"]);
|
|
51
|
+
function errorLabel(path, labels) {
|
|
52
|
+
const key = path.join(".");
|
|
53
|
+
if (GENERAL_ERROR_KEYS.has(key)) return "";
|
|
54
|
+
const [head, lang = "", field = ""] = path;
|
|
55
|
+
const isTranslation = head === "translations";
|
|
56
|
+
const hasLangAndField = path.length === 3;
|
|
57
|
+
if (isTranslation && hasLangAndField) {
|
|
58
|
+
return `${labels[field] ?? field} (${lang.toUpperCase()})`;
|
|
59
|
+
}
|
|
60
|
+
const ownLabel = labels[key];
|
|
61
|
+
if (ownLabel) return ownLabel;
|
|
62
|
+
for (const [name, label] of Object.entries(labels)) {
|
|
63
|
+
if (!key.startsWith(`${name}_`)) continue;
|
|
64
|
+
return `${label} (${key.slice(name.length + 1).toUpperCase()})`;
|
|
65
|
+
}
|
|
66
|
+
return key;
|
|
67
|
+
}
|
|
68
|
+
export function describeMediaErrors(data, labels) {
|
|
69
|
+
const lines = [];
|
|
70
|
+
const add = (path, messages) => {
|
|
71
|
+
if (!messages.length) return;
|
|
72
|
+
const label = errorLabel(path, labels);
|
|
73
|
+
const text = messages.join(", ");
|
|
74
|
+
lines.push(label ? `${label}: ${text}` : text);
|
|
75
|
+
};
|
|
76
|
+
const walk = (value, path) => {
|
|
77
|
+
const isMessage = typeof value === "string";
|
|
78
|
+
const isUnderAKey = path.length > 0;
|
|
79
|
+
if (isMessage) {
|
|
80
|
+
if (isUnderAKey) add(path, [value]);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
add(
|
|
85
|
+
path,
|
|
86
|
+
value.filter((item) => typeof item === "string")
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!value || typeof value !== "object") return;
|
|
91
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
92
|
+
walk(nested, [...path, key]);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
walk(data, []);
|
|
96
|
+
return lines;
|
|
97
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MediaItem } from "../types/media.js";
|
|
2
|
+
type VersionedMedia = Pick<MediaItem, "file"> & Partial<Pick<MediaItem, "modified" | "created">>;
|
|
3
|
+
/**
|
|
4
|
+
* The URL to load a media file from in the backoffice: `file`, with
|
|
5
|
+
* `v=<modified, else created>` appended, so a file replaced at the same URL
|
|
6
|
+
* ("Keep current URL") is fetched again instead of served from the browser
|
|
7
|
+
* cache. Camomilla's `created` changes on every save, a replacement included.
|
|
8
|
+
*
|
|
9
|
+
* The URL is left as it is when it already has a query string (a signed URL
|
|
10
|
+
* would stop matching its signature), when it is a `data:` or `blob:` URL, and
|
|
11
|
+
* when the media carries no date. Display only: the stored `file` never
|
|
12
|
+
* changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function mediaFileUrl(media: VersionedMedia): string;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=mediaUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaUrl.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/mediaUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,KAAK,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAC3C,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAa1D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function mediaFileUrl(media) {
|
|
2
|
+
const url = media.file ?? "";
|
|
3
|
+
const version = media.modified || media.created;
|
|
4
|
+
if (!url || !version) return url;
|
|
5
|
+
const isInline = /^(data|blob):/i.test(url);
|
|
6
|
+
const hasQuery = url.includes("?");
|
|
7
|
+
if (isInline || hasQuery) return url;
|
|
8
|
+
const hashAt = url.indexOf("#");
|
|
9
|
+
const path = hashAt === -1 ? url : url.slice(0, hashAt);
|
|
10
|
+
const hash = hashAt === -1 ? "" : url.slice(hashAt);
|
|
11
|
+
return `${path}?v=${encodeURIComponent(version)}${hash}`;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/uikit",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.19",
|
|
4
4
|
"description": "Mapo UI components: Sidebar, Topbar, Login, SnackBar, ConfirmDialog, List, Detail, Media",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"lint": "eslint src"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@mapomodule/form": "2.0.0-beta.
|
|
49
|
-
"@mapomodule/i18n": "2.0.0-beta.
|
|
48
|
+
"@mapomodule/form": "2.0.0-beta.16",
|
|
49
|
+
"@mapomodule/i18n": "2.0.0-beta.7",
|
|
50
50
|
"@mapomodule/store": "2.0.0-beta.6",
|
|
51
51
|
"@mapomodule/utils": "2.0.0-beta.7",
|
|
52
52
|
"@mapomodule/core": "2.0.0-beta.12",
|
|
@@ -26,10 +26,16 @@ const crud = vi.hoisted(() => ({
|
|
|
26
26
|
const confirm = vi.hoisted(() => ({ ask: vi.fn() }));
|
|
27
27
|
const mapoFormProps: Array<{ notifyErrors: boolean }> = [];
|
|
28
28
|
|
|
29
|
+
// The app's `mapo.uikit` runtime config, changed by the content-language tests.
|
|
30
|
+
const runtimeConfig = vi.hoisted(() => ({
|
|
31
|
+
public: { mapoUikit: { contentLanguages: [] as string[] } },
|
|
32
|
+
}));
|
|
33
|
+
|
|
29
34
|
vi.mock("#app", () => ({
|
|
30
35
|
useRouter: () => router,
|
|
31
36
|
onBeforeRouteLeave: () => {},
|
|
32
37
|
useNuxtApp: () => ({ $mapoFormRegistry: {} }),
|
|
38
|
+
useRuntimeConfig: () => runtimeConfig,
|
|
33
39
|
}));
|
|
34
40
|
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
|
|
35
41
|
vi.mock("@mapomodule/core/runtime/api/crud", () => ({ useCrud: () => crud }));
|
|
@@ -133,6 +139,10 @@ const UButton: Component = {
|
|
|
133
139
|
},
|
|
134
140
|
};
|
|
135
141
|
|
|
142
|
+
// The language switch the detail renders, with what it was given.
|
|
143
|
+
let langSwitch: { readonly langs: string[]; readonly value: string } | null =
|
|
144
|
+
null;
|
|
145
|
+
|
|
136
146
|
const stubs: Record<string, Component> = {
|
|
137
147
|
UButton,
|
|
138
148
|
UCard: passthrough("UCard"),
|
|
@@ -151,7 +161,24 @@ const stubs: Record<string, Component> = {
|
|
|
151
161
|
return () => h("div", null, slots.default?.());
|
|
152
162
|
},
|
|
153
163
|
},
|
|
154
|
-
MapoDetailLangSwitch:
|
|
164
|
+
MapoDetailLangSwitch: {
|
|
165
|
+
name: "MapoDetailLangSwitch",
|
|
166
|
+
props: { modelValue: String, langs: Array },
|
|
167
|
+
setup(props: { modelValue?: string; langs?: string[] }) {
|
|
168
|
+
langSwitch = {
|
|
169
|
+
get langs() {
|
|
170
|
+
return props.langs ?? [];
|
|
171
|
+
},
|
|
172
|
+
get value() {
|
|
173
|
+
return props.modelValue ?? "";
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
onUnmounted(() => {
|
|
177
|
+
langSwitch = null;
|
|
178
|
+
});
|
|
179
|
+
return () => h("div");
|
|
180
|
+
},
|
|
181
|
+
},
|
|
155
182
|
};
|
|
156
183
|
|
|
157
184
|
const button = (label: string) => {
|
|
@@ -198,6 +225,7 @@ const finishNavigation = (failure?: Error) => {
|
|
|
198
225
|
const record = { id: 5, title: "News" };
|
|
199
226
|
|
|
200
227
|
beforeEach(() => {
|
|
228
|
+
runtimeConfig.public.mapoUikit.contentLanguages = [];
|
|
201
229
|
router.back.mockReset();
|
|
202
230
|
router.replace.mockReset();
|
|
203
231
|
router.afterEach.mockReset();
|
|
@@ -328,3 +356,38 @@ describe("MapoDetail actions", () => {
|
|
|
328
356
|
expect(button("mapo.delete").loading).toBe(true);
|
|
329
357
|
});
|
|
330
358
|
});
|
|
359
|
+
|
|
360
|
+
describe("MapoDetail content languages", () => {
|
|
361
|
+
it("keeps only the app's content languages, and hides a single one", async () => {
|
|
362
|
+
runtimeConfig.public.mapoUikit.contentLanguages = ["it"];
|
|
363
|
+
mountDetail({}, { languages: ["it", "en"] });
|
|
364
|
+
await settle();
|
|
365
|
+
|
|
366
|
+
expect(langSwitch).toBeNull();
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("follows the app's order, so its first language is the starting one", async () => {
|
|
370
|
+
runtimeConfig.public.mapoUikit.contentLanguages = ["en", "it"];
|
|
371
|
+
mountDetail({}, { languages: ["it", "en"] });
|
|
372
|
+
await settle();
|
|
373
|
+
|
|
374
|
+
expect(langSwitch?.langs).toEqual(["en", "it"]);
|
|
375
|
+
expect(langSwitch?.value).toBe("en");
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("never adds a language the page does not declare", async () => {
|
|
379
|
+
runtimeConfig.public.mapoUikit.contentLanguages = ["it", "de"];
|
|
380
|
+
mountDetail({}, { languages: ["it", "en"] });
|
|
381
|
+
await settle();
|
|
382
|
+
|
|
383
|
+
expect(langSwitch).toBeNull();
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("lets forceLanguages bypass it", async () => {
|
|
387
|
+
runtimeConfig.public.mapoUikit.contentLanguages = ["it"];
|
|
388
|
+
mountDetail({}, { languages: ["it", "en"], forceLanguages: ["it", "en"] });
|
|
389
|
+
await settle();
|
|
390
|
+
|
|
391
|
+
expect(langSwitch?.langs).toEqual(["it", "en"]);
|
|
392
|
+
});
|
|
393
|
+
});
|