@mapomodule/uikit 2.0.0-beta.8 → 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.
Files changed (133) hide show
  1. package/README.md +47 -174
  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__/MapoListActions.component.test.d.ts +2 -0
  9. package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
  10. package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
  11. package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
  12. package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
  13. package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
  14. package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
  15. package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
  16. package/dist/__tests__/formValues.test.d.ts +2 -0
  17. package/dist/__tests__/formValues.test.d.ts.map +1 -0
  18. package/dist/__tests__/langInfo.test.d.ts +2 -0
  19. package/dist/__tests__/langInfo.test.d.ts.map +1 -0
  20. package/dist/__tests__/listTable.test.d.ts +2 -0
  21. package/dist/__tests__/listTable.test.d.ts.map +1 -0
  22. package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
  23. package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
  24. package/dist/__tests__/runtimePages.test.d.ts +2 -0
  25. package/dist/__tests__/runtimePages.test.d.ts.map +1 -0
  26. package/dist/index.d.mts +1 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/module.d.mts +1 -0
  30. package/dist/module.d.ts.map +1 -1
  31. package/dist/module.json +1 -1
  32. package/dist/module.mjs +10 -0
  33. package/dist/runtime/assets/main.css +1 -1
  34. package/dist/runtime/components/MapoConfirmDialog.vue +18 -1
  35. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
  36. package/dist/runtime/components/MapoDetail.vue +263 -33
  37. package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
  38. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
  39. package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
  40. package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
  41. package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
  42. package/dist/runtime/components/MapoDetailLangSwitch.vue +21 -25
  43. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
  44. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
  45. package/dist/runtime/components/MapoDropArea.vue.d.ts +1 -1
  46. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
  47. package/dist/runtime/components/MapoList.vue +7 -3
  48. package/dist/runtime/components/MapoList.vue.d.ts +14 -4
  49. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
  50. package/dist/runtime/components/MapoListActions.vue +12 -5
  51. package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
  52. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
  53. package/dist/runtime/components/MapoListQuickEdit.vue +1 -1
  54. package/dist/runtime/components/MapoListTable.vue +99 -33
  55. package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
  56. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
  57. package/dist/runtime/components/MapoMediaEditor.vue +10 -4
  58. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
  59. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
  60. package/dist/runtime/components/MapoMediaFileChanger.vue +1 -1
  61. package/dist/runtime/components/MapoMediaManager.vue +1 -1
  62. package/dist/runtime/components/MapoMediaManagerDialog.vue +1 -1
  63. package/dist/runtime/components/MapoMediaPreview.vue +1 -1
  64. package/dist/runtime/components/MapoMediaUploader.vue +21 -21
  65. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
  66. package/dist/runtime/components/MapoMenuManager.vue +23 -3
  67. package/dist/runtime/components/MapoMenuManager.vue.d.ts +2 -2
  68. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -1
  69. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +1 -1
  70. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -1
  71. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +2 -2
  72. package/dist/runtime/components/MapoSnackBar.vue +11 -0
  73. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
  74. package/dist/runtime/composables/defineDetailExtension.d.ts +32 -0
  75. package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
  76. package/dist/runtime/composables/defineDetailExtension.js +34 -0
  77. package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
  78. package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
  79. package/dist/runtime/composables/useMapoDetail.js +5 -0
  80. package/dist/runtime/page-meta.nuxt.d.ts +4 -0
  81. package/dist/runtime/stores/media.d.ts +8 -2
  82. package/dist/runtime/stores/media.d.ts.map +1 -1
  83. package/dist/runtime/stores/media.js +16 -0
  84. package/dist/runtime/types/detail.d.ts +167 -0
  85. package/dist/runtime/types/detail.d.ts.map +1 -0
  86. package/dist/runtime/types/detail.js +0 -0
  87. package/dist/runtime/types/list.d.ts +10 -2
  88. package/dist/runtime/types/list.d.ts.map +1 -1
  89. package/dist/runtime/utils/formValues.d.ts +8 -0
  90. package/dist/runtime/utils/formValues.d.ts.map +1 -0
  91. package/dist/runtime/utils/formValues.js +19 -0
  92. package/dist/runtime/utils/langInfo.d.ts +30 -0
  93. package/dist/runtime/utils/langInfo.d.ts.map +1 -0
  94. package/dist/runtime/utils/langInfo.js +8 -0
  95. package/dist/runtime/utils/listTable.d.ts +29 -0
  96. package/dist/runtime/utils/listTable.d.ts.map +1 -0
  97. package/dist/runtime/utils/listTable.js +21 -0
  98. package/package.json +7 -8
  99. package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
  100. package/src/__tests__/MapoDetail.component.test.ts +1107 -0
  101. package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
  102. package/src/__tests__/MapoListActions.component.test.ts +175 -0
  103. package/src/__tests__/MapoListTable.component.test.ts +504 -0
  104. package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
  105. package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
  106. package/src/__tests__/formValues.test.ts +31 -0
  107. package/src/__tests__/langInfo.test.ts +48 -0
  108. package/src/__tests__/listTable.test.ts +82 -0
  109. package/src/__tests__/mediaLanguages.test.ts +66 -0
  110. package/src/__tests__/runtimePages.test.ts +17 -0
  111. package/src/index.ts +8 -0
  112. package/src/module.ts +12 -0
  113. package/src/runtime/assets/main.css +13 -0
  114. package/src/runtime/components/MapoConfirmDialog.vue +28 -1
  115. package/src/runtime/components/MapoDetail.vue +481 -53
  116. package/src/runtime/components/MapoDetailExtensions.vue +39 -0
  117. package/src/runtime/components/MapoDetailLangSwitch.vue +26 -27
  118. package/src/runtime/components/MapoList.vue +20 -5
  119. package/src/runtime/components/MapoListActions.vue +16 -4
  120. package/src/runtime/components/MapoListTable.vue +128 -41
  121. package/src/runtime/components/MapoMediaEditor.vue +17 -4
  122. package/src/runtime/components/MapoMediaUploader.vue +25 -21
  123. package/src/runtime/components/MapoMenuManager.vue +38 -3
  124. package/src/runtime/components/MapoSnackBar.vue +12 -0
  125. package/src/runtime/composables/defineDetailExtension.ts +78 -0
  126. package/src/runtime/composables/useMapoDetail.ts +24 -0
  127. package/src/runtime/page-meta.nuxt.d.ts +4 -0
  128. package/src/runtime/stores/media.ts +32 -0
  129. package/src/runtime/types/detail.ts +178 -0
  130. package/src/runtime/types/list.ts +10 -2
  131. package/src/runtime/utils/formValues.ts +28 -0
  132. package/src/runtime/utils/langInfo.ts +38 -0
  133. package/src/runtime/utils/listTable.ts +54 -0
@@ -0,0 +1,145 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { createRenderer, h, nextTick, onUnmounted } from "vue";
3
+ import type { App, Component, SetupContext } from "vue";
4
+
5
+ import MapoDetailLangSwitch from "../runtime/components/MapoDetailLangSwitch.vue";
6
+
7
+ const route = vi.hoisted(() => ({ query: {} as Record<string, string> }));
8
+ const router = vi.hoisted(() => ({ replace: vi.fn() }));
9
+
10
+ vi.mock("#app", () => ({ useRoute: () => route, useRouter: () => router }));
11
+
12
+ // Tests run in Node without a DOM. A renderer whose nodes are plain objects is
13
+ // enough to mount the component with real reactivity, watchers and events. The
14
+ // tabs are template refs the switch scrolls into view, hence the no-op method.
15
+ interface HeadlessNode {
16
+ parent: HeadlessNode | null;
17
+ children: HeadlessNode[];
18
+ scrollIntoView(): void;
19
+ }
20
+
21
+ const headlessNode = (): HeadlessNode => ({
22
+ parent: null,
23
+ children: [],
24
+ scrollIntoView: () => {},
25
+ });
26
+
27
+ const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
28
+ createElement: headlessNode,
29
+ createText: headlessNode,
30
+ createComment: headlessNode,
31
+ setText: () => {},
32
+ setElementText: () => {},
33
+ patchProp: () => {},
34
+ insert(child, parent, anchor) {
35
+ child.parent = parent;
36
+ const at = anchor ? parent.children.indexOf(anchor) : -1;
37
+ parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
38
+ },
39
+ remove(child) {
40
+ child.parent?.children.splice(child.parent.children.indexOf(child), 1);
41
+ child.parent = null;
42
+ },
43
+ parentNode: (node) => node.parent,
44
+ nextSibling: (node) =>
45
+ node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
46
+ });
47
+
48
+ // `USelectMenu` declares the contract the switch binds: `modelValue` and `items`
49
+ // in, `update:modelValue` out with the picked item's value (`value-key="value"`),
50
+ // and a default slot that receives `modelValue` and `open`.
51
+ interface SelectItem {
52
+ label: string;
53
+ value: string;
54
+ }
55
+ let select: { readonly items: SelectItem[]; pick(value: string): void } | null =
56
+ null;
57
+
58
+ const USelectMenu: Component = {
59
+ name: "USelectMenu",
60
+ props: { modelValue: String, items: Array },
61
+ emits: ["update:modelValue"],
62
+ setup(
63
+ props: { modelValue?: string; items?: SelectItem[] },
64
+ { emit, slots }: SetupContext<["update:modelValue"]>,
65
+ ) {
66
+ select = {
67
+ get items() {
68
+ return props.items ?? [];
69
+ },
70
+ pick: (value) => emit("update:modelValue", value),
71
+ };
72
+ onUnmounted(() => {
73
+ select = null;
74
+ });
75
+ return () =>
76
+ h(
77
+ "button",
78
+ null,
79
+ slots.default?.({ modelValue: props.modelValue, open: false }),
80
+ );
81
+ },
82
+ };
83
+
84
+ const NINE_LANGS = ["it", "en", "fr", "de", "es", "pt", "nl", "pl", "ru"];
85
+ const changes = vi.fn();
86
+
87
+ let app: App<HeadlessNode> | undefined;
88
+
89
+ function mountSwitch(props: Record<string, unknown>) {
90
+ const root: Component = {
91
+ render: () =>
92
+ h(MapoDetailLangSwitch as Component, {
93
+ modelValue: "it",
94
+ "onUpdate:modelValue": changes,
95
+ ...props,
96
+ }),
97
+ };
98
+ app = createApp(root);
99
+ app.component("USelectMenu", USelectMenu);
100
+ app.mount(headlessNode());
101
+ }
102
+
103
+ beforeEach(() => {
104
+ route.query = {};
105
+ router.replace.mockReset();
106
+ changes.mockReset();
107
+ });
108
+
109
+ afterEach(() => {
110
+ app?.unmount();
111
+ app = undefined;
112
+ });
113
+
114
+ describe("MapoDetailLangSwitch", () => {
115
+ it("shows only the tabs up to the threshold", async () => {
116
+ mountSwitch({ langs: NINE_LANGS.slice(0, 8) });
117
+ await nextTick();
118
+
119
+ expect(select).toBeNull();
120
+ });
121
+
122
+ it("adds the select above the threshold", async () => {
123
+ mountSwitch({ langs: NINE_LANGS });
124
+ await nextTick();
125
+
126
+ expect(select?.items.map((item) => item.value)).toEqual(NINE_LANGS);
127
+ });
128
+
129
+ it("follows a custom threshold", async () => {
130
+ mountSwitch({ langs: ["it", "en"], langThreshold: 0 });
131
+ await nextTick();
132
+
133
+ expect(select).not.toBeNull();
134
+ });
135
+
136
+ it("switches language from the select", async () => {
137
+ mountSwitch({ langs: NINE_LANGS });
138
+ await nextTick();
139
+
140
+ select?.pick("de");
141
+
142
+ expect(changes).toHaveBeenCalledWith("de");
143
+ expect(router.replace).toHaveBeenCalledWith({ query: { lang: "de" } });
144
+ });
145
+ });
@@ -0,0 +1,175 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import {
3
+ createRenderer,
4
+ defineComponent,
5
+ h,
6
+ nextTick,
7
+ onMounted,
8
+ watchEffect,
9
+ } from "vue";
10
+ import type { App, Component } from "vue";
11
+
12
+ import MapoListActions from "../runtime/components/MapoListActions.vue";
13
+ import type { ActionDescriptor } from "../runtime/types/list";
14
+
15
+ const permissions = vi.hoisted(() => ({
16
+ canDelete: vi.fn(),
17
+ checkPermission: vi.fn(),
18
+ }));
19
+ const crud = vi.hoisted(() => ({ delete: vi.fn() }));
20
+
21
+ vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
22
+ vi.mock("@mapomodule/store/runtime/stores/snack", () => ({
23
+ useSnackStore: () => ({ show: vi.fn() }),
24
+ }));
25
+ vi.mock("@mapomodule/store/runtime/stores/confirm", () => ({
26
+ useConfirmStore: () => ({ ask: vi.fn() }),
27
+ }));
28
+ vi.mock("@mapomodule/store/runtime/composables/usePermissions", () => ({
29
+ usePermissions: () => permissions,
30
+ }));
31
+ vi.mock("@mapomodule/core/runtime/api/crud", () => ({
32
+ useCrud: () => crud,
33
+ }));
34
+
35
+ interface HeadlessNode {
36
+ parent: HeadlessNode | null;
37
+ children: HeadlessNode[];
38
+ }
39
+
40
+ const headlessNode = (): HeadlessNode => ({ parent: null, children: [] });
41
+
42
+ const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
43
+ createElement: headlessNode,
44
+ createText: headlessNode,
45
+ createComment: headlessNode,
46
+ setText: () => {},
47
+ setElementText: () => {},
48
+ patchProp: () => {},
49
+ insert(child, parent, anchor) {
50
+ child.parent = parent;
51
+ const at = anchor ? parent.children.indexOf(anchor) : -1;
52
+ parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
53
+ },
54
+ remove(child) {
55
+ child.parent?.children.splice(child.parent.children.indexOf(child), 1);
56
+ child.parent = null;
57
+ },
58
+ parentNode: (node) => node.parent,
59
+ nextSibling: (node) =>
60
+ node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
61
+ });
62
+
63
+ let actionItems: { label: string }[];
64
+ let applyDisabled: boolean;
65
+
66
+ // eslint-disable-next-line vue/one-component-per-file
67
+ const USelect: Component = defineComponent({
68
+ name: "USelect",
69
+ props: {
70
+ items: { type: Array, default: () => [] },
71
+ modelValue: { type: String, default: undefined },
72
+ },
73
+ emits: ["update:modelValue"],
74
+ setup(
75
+ props: { items?: { label: string }[] },
76
+ { emit }: { emit: (event: "update:modelValue", value: string) => void },
77
+ ) {
78
+ actionItems = props.items ?? [];
79
+ onMounted(() => {
80
+ const firstAction = props.items?.[0];
81
+ if (firstAction) emit("update:modelValue", firstAction.label);
82
+ });
83
+ return () => h("select");
84
+ },
85
+ });
86
+
87
+ // eslint-disable-next-line vue/one-component-per-file -- Separate UI control stub.
88
+ const UButton: Component = defineComponent({
89
+ name: "UButton",
90
+ props: { disabled: Boolean },
91
+ setup(props: { disabled?: boolean }) {
92
+ watchEffect(() => {
93
+ applyDisabled = !!props.disabled;
94
+ });
95
+ return () => h("button");
96
+ },
97
+ });
98
+
99
+ function mount(props: {
100
+ permissionModel?: string;
101
+ defaultActions?: boolean;
102
+ actions?: ActionDescriptor<{ id: number }>[];
103
+ }): App<HeadlessNode> {
104
+ // eslint-disable-next-line vue/one-component-per-file -- Mount the generic component under test.
105
+ const app = createApp(MapoListActions as Component, {
106
+ selection: [{ id: 1 }],
107
+ selectionQuery: new URLSearchParams(),
108
+ endpoint: "/api/items/",
109
+ ...props,
110
+ });
111
+ app.component("USelect", USelect);
112
+ app.component("UButton", UButton);
113
+ app.mount(headlessNode());
114
+ return app;
115
+ }
116
+
117
+ describe("MapoListActions", () => {
118
+ beforeEach(() => {
119
+ permissions.canDelete.mockReset();
120
+ permissions.checkPermission.mockReset();
121
+ crud.delete.mockReset();
122
+ actionItems = [];
123
+ applyDisabled = true;
124
+ });
125
+
126
+ it("uses the model delete permission for its built-in action", async () => {
127
+ permissions.canDelete.mockReturnValue(false);
128
+ const deniedApp = mount({ permissionModel: "article" });
129
+ await nextTick();
130
+ await nextTick();
131
+
132
+ expect(actionItems.map(({ label }) => label)).toContain(
133
+ "mapo.listActions.permanentDelete",
134
+ );
135
+ expect(permissions.canDelete).toHaveBeenCalledWith("article");
136
+ expect(applyDisabled).toBe(true);
137
+
138
+ deniedApp.unmount();
139
+ permissions.canDelete.mockReturnValue(true);
140
+ const allowedApp = mount({ permissionModel: "article" });
141
+ await nextTick();
142
+ await nextTick();
143
+
144
+ expect(applyDisabled).toBe(false);
145
+ allowedApp.unmount();
146
+ });
147
+
148
+ it("preserves the built-in action when no permission model is provided", async () => {
149
+ const app = mount({});
150
+ await nextTick();
151
+ await nextTick();
152
+
153
+ expect(actionItems.map(({ label }) => label)).toContain(
154
+ "mapo.listActions.permanentDelete",
155
+ );
156
+ expect(applyDisabled).toBe(false);
157
+ expect(permissions.canDelete).not.toHaveBeenCalled();
158
+
159
+ app.unmount();
160
+ });
161
+
162
+ it("can omit the built-in action without omitting custom actions", async () => {
163
+ const customAction: ActionDescriptor<{ id: number }> = {
164
+ label: "Archive",
165
+ handler: async () => {},
166
+ };
167
+ const app = mount({ defaultActions: false, actions: [customAction] });
168
+ await nextTick();
169
+ await nextTick();
170
+
171
+ expect(actionItems.map(({ label }) => label)).toEqual(["Archive"]);
172
+
173
+ app.unmount();
174
+ });
175
+ });