@mapomodule/uikit 2.0.0-beta.7 → 2.0.0-experimental.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -174
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/formValues.test.d.ts +2 -0
- package/dist/__tests__/formValues.test.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/runtimePages.test.d.ts +2 -0
- package/dist/__tests__/runtimePages.test.d.ts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/module.d.mts +2 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +23 -2
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +301 -63
- package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue +5 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts +1 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoList.vue +7 -3
- package/dist/runtime/components/MapoList.vue.d.ts +14 -4
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +27 -13
- package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
- package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListFilters.vue +4 -2
- package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +12 -8
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +116 -45
- package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogin.vue +13 -10
- package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogoutButton.vue +4 -2
- package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaEditor.vue +36 -20
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFileChanger.vue +7 -3
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFolders.vue +36 -14
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaGallery.vue +15 -5
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManager.vue +17 -7
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManagerDialog.vue +8 -4
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaUploader.vue +53 -29
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuManager.vue +293 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoSidebar.vue +3 -1
- package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSidebarList.vue +1 -1
- package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
- package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoThemeToggle.vue +5 -1
- package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
- package/dist/runtime/components/menuDndContext.d.ts +19 -0
- package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
- package/dist/runtime/components/menuDndContext.js +3 -0
- package/dist/runtime/composables/defineDetailExtension.d.ts +32 -0
- package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
- package/dist/runtime/composables/defineDetailExtension.js +34 -0
- package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
- package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
- package/dist/runtime/composables/useMapoDetail.js +5 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/pages/index.vue +4 -2
- package/dist/runtime/pages/index.vue.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.js +2 -1
- package/dist/runtime/stores/media.d.ts +8 -2
- package/dist/runtime/stores/media.d.ts.map +1 -1
- package/dist/runtime/stores/media.js +45 -13
- package/dist/runtime/types/detail.d.ts +167 -0
- package/dist/runtime/types/detail.d.ts.map +1 -0
- package/dist/runtime/types/detail.js +0 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/types/menu.d.ts +66 -0
- package/dist/runtime/types/menu.d.ts.map +1 -0
- package/dist/runtime/types/menu.js +30 -0
- package/dist/runtime/utils/formValues.d.ts +8 -0
- package/dist/runtime/utils/formValues.d.ts.map +1 -0
- package/dist/runtime/utils/formValues.js +19 -0
- package/dist/runtime/utils/langInfo.d.ts +30 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +8 -0
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/package.json +12 -10
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +1107 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +504 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/formValues.test.ts +31 -0
- package/src/__tests__/langInfo.test.ts +48 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/runtimePages.test.ts +17 -0
- package/src/index.ts +20 -0
- package/src/module.ts +29 -0
- package/src/runtime/assets/main.css +13 -0
- package/src/runtime/components/MapoConfirmDialog.vue +33 -4
- package/src/runtime/components/MapoDetail.vue +520 -89
- package/src/runtime/components/MapoDetailExtensions.vue +39 -0
- package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
- package/src/runtime/components/MapoDropArea.vue +6 -1
- package/src/runtime/components/MapoLangSwitcher.vue +74 -0
- package/src/runtime/components/MapoList.vue +21 -6
- package/src/runtime/components/MapoListActions.vue +32 -14
- package/src/runtime/components/MapoListFilters.vue +5 -2
- package/src/runtime/components/MapoListQuickEdit.vue +12 -9
- package/src/runtime/components/MapoListTable.vue +147 -55
- package/src/runtime/components/MapoLogin.vue +13 -10
- package/src/runtime/components/MapoLogoutButton.vue +4 -2
- package/src/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
- package/src/runtime/components/MapoMediaEditor.vue +43 -20
- package/src/runtime/components/MapoMediaFileChanger.vue +8 -3
- package/src/runtime/components/MapoMediaFolders.vue +37 -15
- package/src/runtime/components/MapoMediaGallery.vue +17 -5
- package/src/runtime/components/MapoMediaManager.vue +17 -7
- package/src/runtime/components/MapoMediaManagerDialog.vue +10 -4
- package/src/runtime/components/MapoMediaUploader.vue +60 -29
- package/src/runtime/components/MapoMenuManager.vue +437 -0
- package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
- package/src/runtime/components/MapoMenuTreeview.vue +264 -0
- package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
- package/src/runtime/components/MapoSidebar.vue +3 -1
- package/src/runtime/components/MapoSidebarList.vue +1 -1
- package/src/runtime/components/MapoSidebarProfile.vue +6 -2
- package/src/runtime/components/MapoSnackBar.vue +12 -0
- package/src/runtime/components/MapoThemeToggle.vue +5 -1
- package/src/runtime/components/menuDndContext.ts +22 -0
- package/src/runtime/composables/defineDetailExtension.ts +78 -0
- package/src/runtime/composables/useMapoDetail.ts +24 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/pages/index.vue +5 -2
- package/src/runtime/plugins/media-adapter.ts +9 -5
- package/src/runtime/stores/media.ts +61 -13
- package/src/runtime/types/detail.ts +178 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/types/menu.ts +105 -0
- package/src/runtime/utils/formValues.ts +28 -0
- package/src/runtime/utils/langInfo.ts +38 -0
- package/src/runtime/utils/listTable.ts +54 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function createMenuNode(partial = {}) {
|
|
2
|
+
return {
|
|
3
|
+
id: Math.random().toString(36).slice(2),
|
|
4
|
+
title: "",
|
|
5
|
+
link: {},
|
|
6
|
+
meta: {},
|
|
7
|
+
nodes: [],
|
|
8
|
+
...partial
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function menuTreeDepth(nodes) {
|
|
12
|
+
if (!nodes.length) return 0;
|
|
13
|
+
return 1 + Math.max(...nodes.map((n) => menuTreeDepth(n.nodes ?? [])));
|
|
14
|
+
}
|
|
15
|
+
export function findMenuNode(nodes, id, parents = []) {
|
|
16
|
+
for (const node of nodes) {
|
|
17
|
+
if (String(node.id) === String(id)) return { node, parents };
|
|
18
|
+
const found = findMenuNode(node.nodes ?? [], id, [...parents, node]);
|
|
19
|
+
if (found) return found;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
export function removeMenuNode(nodes, id) {
|
|
24
|
+
const index = nodes.findIndex((n) => String(n.id) === String(id));
|
|
25
|
+
if (index !== -1) {
|
|
26
|
+
nodes.splice(index, 1);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return nodes.some((n) => removeMenuNode(n.nodes ?? [], id));
|
|
30
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a form's value holds something: not `undefined` or `null`, not a
|
|
3
|
+
* blank text (the empty paragraphs and line breaks of a rich text editor
|
|
4
|
+
* included), not an empty list, not an object whose values all hold
|
|
5
|
+
* nothing. `false`, `0` and any other object, such as a file, are values.
|
|
6
|
+
*/
|
|
7
|
+
export declare function holdsFormValue(value: unknown): boolean;
|
|
8
|
+
//# sourceMappingURL=formValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/formValues.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAStD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const BLANK_MARKUP = /<\/?p>|<br\s*\/?>| /gi;
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
if (typeof value !== "object") return false;
|
|
4
|
+
if (value === null) return false;
|
|
5
|
+
const prototype = Object.getPrototypeOf(value);
|
|
6
|
+
const isLiteral = prototype === Object.prototype;
|
|
7
|
+
const isBare = prototype === null;
|
|
8
|
+
return isLiteral || isBare;
|
|
9
|
+
}
|
|
10
|
+
export function holdsFormValue(value) {
|
|
11
|
+
if (value === void 0) return false;
|
|
12
|
+
if (value === null) return false;
|
|
13
|
+
if (typeof value === "string") {
|
|
14
|
+
return value.replace(BLANK_MARKUP, " ").trim() !== "";
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
17
|
+
if (isPlainObject(value)) return Object.values(value).some(holdsFormValue);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
* Language codes a model can be translated into, read from its OPTIONS metadata.
|
|
24
|
+
*
|
|
25
|
+
* Returns `[]` — meaning "render no language switcher" — when the model is not
|
|
26
|
+
* translatable and when `lang_info` is absent entirely. A backend that does not
|
|
27
|
+
* publish the field cannot be assumed multilingual.
|
|
28
|
+
*/
|
|
29
|
+
export declare function languagesFromMetadata(metadata: unknown): string[];
|
|
30
|
+
//# sourceMappingURL=langInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langInfo.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/langInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,QAAQ;IACvB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAQjE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function languagesFromMetadata(metadata) {
|
|
2
|
+
const info = metadata?.lang_info;
|
|
3
|
+
if (!info || info.translatable === false) return [];
|
|
4
|
+
if (!Array.isArray(info.languages)) return [];
|
|
5
|
+
return info.languages.filter(
|
|
6
|
+
(code) => typeof code === "string"
|
|
7
|
+
);
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
* The page size that stands for "all rows". A plain number, so the paging
|
|
8
|
+
* arithmetic and the in-memory slicing keep working unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ALL_ROWS: number;
|
|
11
|
+
/** A `pageSizeOptions` entry as the table stores it: `"all"` → {@link ALL_ROWS}. */
|
|
12
|
+
export declare function toPageSize(option: number | "all"): number;
|
|
13
|
+
/** Reads `page_size` from the URL: `all`, or a positive number, else `fallback`. */
|
|
14
|
+
export declare function parsePageSize(value: unknown, fallback: number): number;
|
|
15
|
+
/** Writes a page size to the URL: {@link ALL_ROWS} as `all`. */
|
|
16
|
+
export declare function formatPageSize(size: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* The sorting after a click on a sortable header. The column goes from
|
|
19
|
+
* unsorted to ascending, to descending, and back to unsorted, so the natural
|
|
20
|
+
* order (needed by drag reorder) is one click away. It replaces any other key.
|
|
21
|
+
*/
|
|
22
|
+
export declare function nextSorting(sorting: TableSort[], columnId: string): TableSort[];
|
|
23
|
+
/**
|
|
24
|
+
* The `ordering` param for a sorting: comma-separated keys, `-` for descending.
|
|
25
|
+
* A dotted key becomes a Django lookup (`category.name` → `category__name`),
|
|
26
|
+
* the way DRF's OrderingFilter reaches a field of a related object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function orderingParam(sorting: TableSort[]): string;
|
|
29
|
+
//# sourceMappingURL=listTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listTable.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/listTable.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAA0B,CAAC;AAEhD,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAEzD;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAItE;AAED,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,EAAE,EACpB,QAAQ,EAAE,MAAM,GACf,SAAS,EAAE,CAKb;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAI1D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const ALL_ROWS = Number.MAX_SAFE_INTEGER;
|
|
2
|
+
export function toPageSize(option) {
|
|
3
|
+
return option === "all" ? ALL_ROWS : option;
|
|
4
|
+
}
|
|
5
|
+
export function parsePageSize(value, fallback) {
|
|
6
|
+
if (value === "all") return ALL_ROWS;
|
|
7
|
+
const size = Number(value);
|
|
8
|
+
return Number.isFinite(size) && size > 0 ? size : fallback;
|
|
9
|
+
}
|
|
10
|
+
export function formatPageSize(size) {
|
|
11
|
+
return size === ALL_ROWS ? "all" : String(size);
|
|
12
|
+
}
|
|
13
|
+
export function nextSorting(sorting, columnId) {
|
|
14
|
+
const current = sorting.find((sort) => sort.id === columnId);
|
|
15
|
+
if (!current) return [{ id: columnId, desc: false }];
|
|
16
|
+
if (!current.desc) return [{ id: columnId, desc: true }];
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
export function orderingParam(sorting) {
|
|
20
|
+
return sorting.map((sort) => `${sort.desc ? "-" : ""}${sort.id.split(".").join("__")}`).join(",");
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/uikit",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-experimental.1",
|
|
4
4
|
"description": "Mapo UI components: Sidebar, Topbar, Login, SnackBar, ConfirmDialog, List, Detail, Media",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,17 +40,19 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "nuxt-module-build build && vue-tsc -p tsconfig.build-types.json && node ../../../scripts/clean-empty-vue-dts.mjs dist",
|
|
42
42
|
"dev": "nuxt-module-build build --stub --watch",
|
|
43
|
-
"prepack": "pnpm build",
|
|
44
43
|
"dev:prepare": "nuxt-module-build build --stub",
|
|
45
44
|
"typecheck": "vue-tsc --noEmit",
|
|
46
45
|
"lint": "eslint src"
|
|
47
46
|
},
|
|
48
47
|
"dependencies": {
|
|
49
|
-
"@mapomodule/form": "2.0.0-
|
|
50
|
-
"@mapomodule/
|
|
51
|
-
"@mapomodule/
|
|
52
|
-
"@mapomodule/
|
|
53
|
-
"
|
|
48
|
+
"@mapomodule/form": "2.0.0-experimental.1",
|
|
49
|
+
"@mapomodule/i18n": "2.0.0-experimental.1",
|
|
50
|
+
"@mapomodule/store": "2.0.0-experimental.1",
|
|
51
|
+
"@mapomodule/utils": "2.0.0-experimental.1",
|
|
52
|
+
"@mapomodule/core": "2.0.0-experimental.1",
|
|
53
|
+
"tailwindcss": "^4.0.0",
|
|
54
|
+
"vue-draggable-plus": "^0.6.0",
|
|
55
|
+
"vue-i18n": "^11.4.8"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
56
58
|
"@nuxt/ui": ">=4.0.0",
|
|
@@ -63,10 +65,10 @@
|
|
|
63
65
|
"@nuxt/schema": "4.4.2",
|
|
64
66
|
"@nuxt/ui": "^4.7.0",
|
|
65
67
|
"@tanstack/vue-table": "^8.21.3",
|
|
66
|
-
"nuxt": "^4.
|
|
68
|
+
"nuxt": "^4.5.1",
|
|
67
69
|
"pinia": "^3.0.4",
|
|
68
|
-
"vue": "^3.5.
|
|
69
|
-
"vue-router": "^5.0
|
|
70
|
+
"vue": "^3.5.40",
|
|
71
|
+
"vue-router": "^5.2.0",
|
|
70
72
|
"vue-tsc": "^3.3.4"
|
|
71
73
|
}
|
|
72
74
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createRenderer, h, nextTick, onUnmounted, ref } from "vue";
|
|
3
|
+
import type { App, Component, SetupContext } from "vue";
|
|
4
|
+
import { createPinia, setActivePinia } from "pinia";
|
|
5
|
+
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
6
|
+
|
|
7
|
+
import MapoConfirmDialog from "../runtime/components/MapoConfirmDialog.vue";
|
|
8
|
+
|
|
9
|
+
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
|
|
10
|
+
|
|
11
|
+
// Tests run in Node without a DOM. A renderer whose nodes are plain objects is
|
|
12
|
+
// enough to mount the component with real reactivity, watchers and events.
|
|
13
|
+
interface HeadlessNode {
|
|
14
|
+
parent: HeadlessNode | null;
|
|
15
|
+
children: HeadlessNode[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const headlessNode = (): HeadlessNode => ({ parent: null, children: [] });
|
|
19
|
+
|
|
20
|
+
const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
|
|
21
|
+
createElement: headlessNode,
|
|
22
|
+
createText: headlessNode,
|
|
23
|
+
createComment: headlessNode,
|
|
24
|
+
setText: () => {},
|
|
25
|
+
setElementText: () => {},
|
|
26
|
+
patchProp: () => {},
|
|
27
|
+
insert(child, parent, anchor) {
|
|
28
|
+
child.parent = parent;
|
|
29
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1;
|
|
30
|
+
parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
|
|
31
|
+
},
|
|
32
|
+
remove(child) {
|
|
33
|
+
child.parent?.children.splice(child.parent.children.indexOf(child), 1);
|
|
34
|
+
child.parent = null;
|
|
35
|
+
},
|
|
36
|
+
parentNode: (node) => node.parent,
|
|
37
|
+
nextSibling: (node) =>
|
|
38
|
+
node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const passthrough = (name: string): Component => ({
|
|
42
|
+
name,
|
|
43
|
+
inheritAttrs: false,
|
|
44
|
+
setup(_props: unknown, { slots }: SetupContext) {
|
|
45
|
+
return () => h("div", null, slots.default?.());
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Nuxt UI overlays have no z-index: they stack in the order their portals enter
|
|
50
|
+
// <body>, which is the order the overlays mount. The stubs record that order.
|
|
51
|
+
const mountOrder: string[] = [];
|
|
52
|
+
|
|
53
|
+
// `UModal` declares what the dialog binds: `open` in, and `after:leave` out once
|
|
54
|
+
// the close animation has ended.
|
|
55
|
+
let modal: { readonly open: boolean | undefined; finishLeave(): void } | null =
|
|
56
|
+
null;
|
|
57
|
+
|
|
58
|
+
const UModal: Component = {
|
|
59
|
+
name: "UModal",
|
|
60
|
+
props: { open: Boolean, dismissible: Boolean },
|
|
61
|
+
emits: ["after:leave"],
|
|
62
|
+
setup(props: { open?: boolean }, { emit }: SetupContext<["after:leave"]>) {
|
|
63
|
+
mountOrder.push("confirm");
|
|
64
|
+
modal = {
|
|
65
|
+
get open() {
|
|
66
|
+
return props.open;
|
|
67
|
+
},
|
|
68
|
+
finishLeave: () => emit("after:leave"),
|
|
69
|
+
};
|
|
70
|
+
onUnmounted(() => {
|
|
71
|
+
modal = null;
|
|
72
|
+
});
|
|
73
|
+
return () => h("div");
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// An overlay that a page opens once the layout is already there, like the media
|
|
78
|
+
// editor drawer.
|
|
79
|
+
const Drawer: Component = {
|
|
80
|
+
name: "Drawer",
|
|
81
|
+
setup() {
|
|
82
|
+
mountOrder.push("drawer");
|
|
83
|
+
return () => h("div");
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const drawerOpen = ref(false);
|
|
88
|
+
|
|
89
|
+
let app: App<HeadlessNode> | undefined;
|
|
90
|
+
|
|
91
|
+
/** Mounts the dialog the way the layout does; returns the store that drives it. */
|
|
92
|
+
function mountLayout() {
|
|
93
|
+
const pinia = createPinia();
|
|
94
|
+
setActivePinia(pinia);
|
|
95
|
+
const root: Component = {
|
|
96
|
+
// The page comes first, then the root components, as in `mapo-default`.
|
|
97
|
+
render: () => [
|
|
98
|
+
drawerOpen.value ? h(Drawer) : null,
|
|
99
|
+
h(MapoConfirmDialog as Component),
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
app = createApp(root);
|
|
103
|
+
app.use(pinia);
|
|
104
|
+
app.component("UModal", UModal);
|
|
105
|
+
app.component("UButton", passthrough("UButton"));
|
|
106
|
+
app.mount(headlessNode());
|
|
107
|
+
return useConfirmStore();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
beforeEach(() => {
|
|
111
|
+
mountOrder.length = 0;
|
|
112
|
+
drawerOpen.value = false;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
afterEach(() => {
|
|
116
|
+
app?.unmount();
|
|
117
|
+
app = undefined;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("MapoConfirmDialog", () => {
|
|
121
|
+
it("opens above an overlay the page opened after the layout", async () => {
|
|
122
|
+
const confirm = mountLayout();
|
|
123
|
+
drawerOpen.value = true;
|
|
124
|
+
await nextTick();
|
|
125
|
+
|
|
126
|
+
void confirm.ask({ message: "Delete?" });
|
|
127
|
+
await nextTick();
|
|
128
|
+
|
|
129
|
+
expect(modal?.open).toBe(true);
|
|
130
|
+
expect(mountOrder).toEqual(["drawer", "confirm"]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("stays mounted until its close animation has ended", async () => {
|
|
134
|
+
const confirm = mountLayout();
|
|
135
|
+
const answer = confirm.ask({ message: "Delete?" });
|
|
136
|
+
await nextTick();
|
|
137
|
+
|
|
138
|
+
confirm.confirm();
|
|
139
|
+
await nextTick();
|
|
140
|
+
|
|
141
|
+
expect(modal?.open).toBe(false);
|
|
142
|
+
modal?.finishLeave();
|
|
143
|
+
await nextTick();
|
|
144
|
+
|
|
145
|
+
expect(modal).toBeNull();
|
|
146
|
+
await expect(answer).resolves.toBe(true);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("stays open when asked again while it was closing", async () => {
|
|
150
|
+
const confirm = mountLayout();
|
|
151
|
+
void confirm.ask({ message: "First?" });
|
|
152
|
+
await nextTick();
|
|
153
|
+
confirm.cancel();
|
|
154
|
+
await nextTick();
|
|
155
|
+
const closing = modal;
|
|
156
|
+
|
|
157
|
+
void confirm.ask({ message: "Second?" });
|
|
158
|
+
await nextTick();
|
|
159
|
+
// The first close animation reports its end after the second question.
|
|
160
|
+
closing?.finishLeave();
|
|
161
|
+
await nextTick();
|
|
162
|
+
|
|
163
|
+
expect(modal?.open).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
});
|