@mapomodule/uikit 2.0.0-beta.1 → 2.0.0-beta.10

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 (193) hide show
  1. package/README.md +33 -1
  2. package/dist/index.d.mts +5 -2
  3. package/dist/index.d.ts +6 -2
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.mjs +1 -18
  6. package/dist/module.d.mts +60 -2
  7. package/dist/module.d.ts +55 -2
  8. package/dist/module.d.ts.map +1 -0
  9. package/dist/module.json +1 -1
  10. package/dist/module.mjs +174 -13
  11. package/dist/runtime/adapters/defaultMediaAdapter.d.ts +14 -0
  12. package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
  13. package/dist/runtime/adapters/defaultMediaAdapter.js +30 -0
  14. package/dist/runtime/assets/main.css +1 -0
  15. package/dist/runtime/components/MapoConfirmDialog.vue +35 -0
  16. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts +4 -0
  17. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -0
  18. package/dist/runtime/components/MapoDetail.vue +606 -0
  19. package/dist/runtime/components/MapoDetail.vue.d.ts +401 -0
  20. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -0
  21. package/dist/runtime/components/MapoDetailLangSwitch.vue +126 -0
  22. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +23 -0
  23. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -0
  24. package/dist/runtime/components/MapoDropArea.vue +99 -0
  25. package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
  26. package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
  27. package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
  28. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
  29. package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
  30. package/dist/runtime/components/MapoList.vue +191 -0
  31. package/dist/runtime/components/MapoList.vue.d.ts +111 -0
  32. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -0
  33. package/dist/runtime/components/MapoListActions.vue +119 -0
  34. package/dist/runtime/components/MapoListActions.vue.d.ts +33 -0
  35. package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -0
  36. package/dist/runtime/components/MapoListFilters.vue +246 -0
  37. package/dist/runtime/components/MapoListFilters.vue.d.ts +38 -0
  38. package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -0
  39. package/dist/runtime/components/MapoListHead.vue +9 -0
  40. package/dist/runtime/components/MapoListHead.vue.d.ts +14 -0
  41. package/dist/runtime/components/MapoListHead.vue.d.ts.map +1 -0
  42. package/dist/runtime/components/MapoListQuickEdit.vue +123 -0
  43. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts +47 -0
  44. package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -0
  45. package/dist/runtime/components/MapoListTable.vue +665 -0
  46. package/dist/runtime/components/MapoListTable.vue.d.ts +105 -0
  47. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -0
  48. package/dist/runtime/components/MapoListTabs.vue +38 -0
  49. package/dist/runtime/components/MapoListTabs.vue.d.ts +26 -0
  50. package/dist/runtime/components/MapoListTabs.vue.d.ts.map +1 -0
  51. package/dist/runtime/components/MapoLogin.vue +196 -0
  52. package/dist/runtime/components/MapoLogin.vue.d.ts +22 -0
  53. package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -0
  54. package/dist/runtime/components/MapoLogoutButton.vue +27 -0
  55. package/dist/runtime/components/MapoLogoutButton.vue.d.ts +29 -0
  56. package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -0
  57. package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
  58. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
  59. package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
  60. package/dist/runtime/components/MapoMediaEditor.vue +320 -0
  61. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +8 -0
  62. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
  63. package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
  64. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
  65. package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
  66. package/dist/runtime/components/MapoMediaFolders.vue +220 -0
  67. package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
  68. package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
  69. package/dist/runtime/components/MapoMediaGallery.vue +219 -0
  70. package/dist/runtime/components/MapoMediaGallery.vue.d.ts +4 -0
  71. package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
  72. package/dist/runtime/components/MapoMediaManager.vue +140 -0
  73. package/dist/runtime/components/MapoMediaManager.vue.d.ts +35 -0
  74. package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
  75. package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
  76. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
  77. package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
  78. package/dist/runtime/components/MapoMediaPreview.vue +92 -0
  79. package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
  80. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
  81. package/dist/runtime/components/MapoMediaUploader.vue +290 -0
  82. package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
  83. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
  84. package/dist/runtime/components/MapoMenuManager.vue +273 -0
  85. package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
  86. package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
  87. package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
  88. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
  89. package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
  90. package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
  91. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
  92. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
  93. package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
  94. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
  95. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
  96. package/dist/runtime/components/MapoRootComponents.vue +9 -0
  97. package/dist/runtime/components/MapoRootComponents.vue.d.ts +4 -0
  98. package/dist/runtime/components/MapoRootComponents.vue.d.ts.map +1 -0
  99. package/dist/runtime/components/MapoSidebar.vue +89 -0
  100. package/dist/runtime/components/MapoSidebar.vue.d.ts +22 -0
  101. package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -0
  102. package/dist/runtime/components/MapoSidebarList.vue +27 -0
  103. package/dist/runtime/components/MapoSidebarList.vue.d.ts +8 -0
  104. package/dist/runtime/components/MapoSidebarList.vue.d.ts.map +1 -0
  105. package/dist/runtime/components/MapoSidebarListItem.vue +74 -0
  106. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts +9 -0
  107. package/dist/runtime/components/MapoSidebarListItem.vue.d.ts.map +1 -0
  108. package/dist/runtime/components/MapoSidebarProfile.vue +55 -0
  109. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts +10 -0
  110. package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -0
  111. package/dist/runtime/components/MapoSnackBar.vue +38 -0
  112. package/dist/runtime/components/MapoSnackBar.vue.d.ts +4 -0
  113. package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -0
  114. package/dist/runtime/components/MapoThemeToggle.vue +23 -0
  115. package/dist/runtime/components/MapoThemeToggle.vue.d.ts +4 -0
  116. package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -0
  117. package/dist/runtime/components/MapoTopbar.vue +30 -0
  118. package/dist/runtime/components/MapoTopbar.vue.d.ts +15 -0
  119. package/dist/runtime/components/MapoTopbar.vue.d.ts.map +1 -0
  120. package/dist/runtime/components/menuDndContext.d.ts +19 -0
  121. package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
  122. package/dist/runtime/components/menuDndContext.js +3 -0
  123. package/dist/runtime/layouts/default.vue +43 -0
  124. package/dist/runtime/layouts/default.vue.d.ts +20 -0
  125. package/dist/runtime/layouts/default.vue.d.ts.map +1 -0
  126. package/dist/runtime/layouts/empty.vue +9 -0
  127. package/dist/runtime/layouts/empty.vue.d.ts +14 -0
  128. package/dist/runtime/layouts/empty.vue.d.ts.map +1 -0
  129. package/dist/runtime/page-meta.nuxt.d.ts +45 -0
  130. package/dist/runtime/pages/index.vue +14 -0
  131. package/dist/runtime/pages/index.vue.d.ts +4 -0
  132. package/dist/runtime/pages/index.vue.d.ts.map +1 -0
  133. package/dist/runtime/pages/login.vue +3 -0
  134. package/dist/runtime/pages/login.vue.d.ts +4 -0
  135. package/dist/runtime/pages/login.vue.d.ts.map +1 -0
  136. package/dist/runtime/plugins/media-adapter.d.ts +18 -0
  137. package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
  138. package/dist/runtime/plugins/media-adapter.js +8 -0
  139. package/dist/runtime/stores/media.d.ts +462 -0
  140. package/dist/runtime/stores/media.d.ts.map +1 -0
  141. package/dist/runtime/stores/media.js +344 -0
  142. package/dist/runtime/types/list.d.ts +59 -0
  143. package/dist/runtime/types/list.d.ts.map +1 -0
  144. package/dist/runtime/types/list.js +0 -0
  145. package/dist/runtime/types/media.d.ts +116 -0
  146. package/dist/runtime/types/media.d.ts.map +1 -0
  147. package/dist/runtime/types/media.js +0 -0
  148. package/dist/runtime/types/menu.d.ts +66 -0
  149. package/dist/runtime/types/menu.d.ts.map +1 -0
  150. package/dist/runtime/types/menu.js +30 -0
  151. package/dist/types.d.mts +6 -10
  152. package/package.json +15 -11
  153. package/src/index.ts +20 -0
  154. package/src/module.ts +130 -0
  155. package/src/runtime/adapters/defaultMediaAdapter.ts +57 -0
  156. package/src/runtime/components/MapoConfirmDialog.vue +5 -3
  157. package/src/runtime/components/MapoDetail.vue +39 -36
  158. package/src/runtime/components/MapoDetailLangSwitch.vue +1 -1
  159. package/src/runtime/components/MapoDropArea.vue +127 -0
  160. package/src/runtime/components/MapoLangSwitcher.vue +74 -0
  161. package/src/runtime/components/MapoList.vue +1 -1
  162. package/src/runtime/components/MapoListActions.vue +16 -10
  163. package/src/runtime/components/MapoListFilters.vue +5 -2
  164. package/src/runtime/components/MapoListQuickEdit.vue +12 -9
  165. package/src/runtime/components/MapoListTable.vue +26 -21
  166. package/src/runtime/components/MapoLogin.vue +13 -10
  167. package/src/runtime/components/MapoLogoutButton.vue +4 -2
  168. package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
  169. package/src/runtime/components/MapoMediaEditor.vue +350 -0
  170. package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
  171. package/src/runtime/components/MapoMediaFolders.vue +239 -0
  172. package/src/runtime/components/MapoMediaGallery.vue +239 -0
  173. package/src/runtime/components/MapoMediaManager.vue +180 -0
  174. package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
  175. package/src/runtime/components/MapoMediaPreview.vue +111 -0
  176. package/src/runtime/components/MapoMediaUploader.vue +351 -0
  177. package/src/runtime/components/MapoMenuManager.vue +402 -0
  178. package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
  179. package/src/runtime/components/MapoMenuTreeview.vue +264 -0
  180. package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
  181. package/src/runtime/components/MapoSidebar.vue +3 -1
  182. package/src/runtime/components/MapoSidebarList.vue +1 -1
  183. package/src/runtime/components/MapoSidebarProfile.vue +6 -2
  184. package/src/runtime/components/MapoThemeToggle.vue +5 -1
  185. package/src/runtime/components/menuDndContext.ts +22 -0
  186. package/src/runtime/pages/index.vue +4 -3
  187. package/src/runtime/pages/login.vue +0 -4
  188. package/src/runtime/plugins/media-adapter.ts +33 -0
  189. package/src/runtime/stores/media.ts +474 -0
  190. package/src/runtime/types/media.ts +126 -0
  191. package/src/runtime/types/menu.ts +105 -0
  192. package/dist/index.d.cts +0 -2
  193. package/dist/module.d.cts +0 -2
@@ -0,0 +1,665 @@
1
+ <script setup>
2
+ import {
3
+ ref,
4
+ shallowRef,
5
+ computed,
6
+ watch,
7
+ h,
8
+ resolveComponent,
9
+ useSlots
10
+ } from "vue";
11
+ import { useI18n } from "vue-i18n";
12
+ import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
13
+ import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
14
+ import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
15
+ import { useCrud } from "@mapomodule/core/runtime/api/crud";
16
+ import { debounce, splitEndpointParams } from "@mapomodule/utils";
17
+ import { useRoute, useRouter } from "#app";
18
+ const props = defineProps({
19
+ endpoint: { type: String, required: false, default: "" },
20
+ items: { type: Array, required: false, default: void 0 },
21
+ crudEndpoint: { type: String, required: false },
22
+ filterParams: { type: Object, required: false },
23
+ defaultPageSize: { type: Number, required: false, default: 20 },
24
+ pageSizeOptions: { type: Array, required: false, default: () => [10, 20, 50, 100] },
25
+ responseAdapter: { type: Function, required: false },
26
+ paginationParams: { type: Function, required: false },
27
+ clientSide: { type: Boolean, required: false, default: false },
28
+ columns: { type: Array, required: true },
29
+ lookup: { type: String, required: false, default: "id" },
30
+ searchable: { type: Boolean, required: false, default: true },
31
+ draggable: { type: Boolean, required: false, default: false },
32
+ positionField: { type: String, required: false, default: "position" },
33
+ editFields: { type: Array, required: false, default: () => [] },
34
+ languages: { type: Array, required: false },
35
+ registry: { type: Object, required: false },
36
+ detailBase: { type: String, required: false },
37
+ permissionModel: { type: String, required: false }
38
+ });
39
+ const offlineMode = computed(() => Array.isArray(props.items));
40
+ const hybridMode = computed(() => !offlineMode.value && props.clientSide);
41
+ const emit = defineEmits(["update:selection", "update:selectionQuery", "update:items"]);
42
+ defineExpose({ refresh });
43
+ defineSlots();
44
+ const slots = useSlots();
45
+ const atKey = (item, key) => item[key];
46
+ const { t } = useI18n();
47
+ const snack = useSnackStore();
48
+ const confirm = useConfirmStore();
49
+ const route = useRoute();
50
+ const router = useRouter();
51
+ const crudBase = props.crudEndpoint ?? (splitEndpointParams(props.endpoint).path || props.endpoint);
52
+ const crud = useCrud(crudBase);
53
+ const { canChange, canDelete: canDeletePerm } = usePermissions();
54
+ const canEditRow = computed(
55
+ () => !props.permissionModel || canChange(props.permissionModel)
56
+ );
57
+ const canDeleteRow = computed(
58
+ () => !props.permissionModel || canDeletePerm(props.permissionModel)
59
+ );
60
+ const rows = shallowRef([]);
61
+ const fullDataset = shallowRef([]);
62
+ const hybridLoaded = ref(false);
63
+ const total = ref(0);
64
+ const loading = ref(false);
65
+ function toPositiveNumber(value, fallback) {
66
+ const n = Number(value);
67
+ return Number.isFinite(n) && n > 0 ? n : fallback;
68
+ }
69
+ const pagination = ref({
70
+ pageIndex: route.query.page ? Math.max(0, toPositiveNumber(route.query.page, 1) - 1) : 0,
71
+ pageSize: route.query.page_size ? toPositiveNumber(route.query.page_size, props.defaultPageSize) : props.defaultPageSize
72
+ });
73
+ const sorting = ref(
74
+ route.query.ordering ? String(route.query.ordering).split(",").map((o) => ({
75
+ id: o.startsWith("-") ? o.slice(1) : o,
76
+ desc: o.startsWith("-")
77
+ })) : []
78
+ );
79
+ const search = ref(route.query.search ? String(route.query.search) : "");
80
+ const onSearchInput = debounce((val) => {
81
+ search.value = String(val ?? "");
82
+ pagination.value = { ...pagination.value, pageIndex: 0 };
83
+ }, 350);
84
+ const writeUrlState = debounce(() => {
85
+ const query = {
86
+ ...route.query
87
+ };
88
+ const page = pagination.value.pageIndex + 1;
89
+ if (page > 1) query.page = String(page);
90
+ else delete query.page;
91
+ if (pagination.value.pageSize !== props.defaultPageSize)
92
+ query.page_size = String(pagination.value.pageSize);
93
+ else delete query.page_size;
94
+ if (search.value) query.search = search.value;
95
+ else delete query.search;
96
+ if (sorting.value.length)
97
+ query.ordering = sorting.value.map((s) => `${s.desc ? "-" : ""}${s.id}`).join(",");
98
+ else delete query.ordering;
99
+ router.replace({ query });
100
+ }, 150);
101
+ watch([pagination, search, sorting], writeUrlState, { deep: true });
102
+ const rowSelection = ref({});
103
+ const pkOf = (row) => String(atKey(row, props.lookup));
104
+ const isAllSelected = computed(
105
+ () => rows.value.length > 0 && rows.value.every((r) => rowSelection.value[pkOf(r)])
106
+ );
107
+ const isIndeterminate = computed(() => {
108
+ const some = rows.value.some((r) => rowSelection.value[pkOf(r)]);
109
+ return some && !isAllSelected.value;
110
+ });
111
+ const selectedRows = computed(
112
+ () => rows.value.filter((r) => rowSelection.value[pkOf(r)])
113
+ );
114
+ watch(selectedRows, (rows2) => {
115
+ emit("update:selection", rows2);
116
+ emit("update:selectionQuery", buildSelectionQuery());
117
+ });
118
+ function buildSelectionQuery() {
119
+ const params = new URLSearchParams();
120
+ params.set("page_size", String(pagination.value.pageSize));
121
+ if (search.value) params.set("search", search.value);
122
+ sorting.value.forEach(
123
+ (s) => params.set("ordering", `${s.desc ? "-" : ""}${s.id}`)
124
+ );
125
+ return params;
126
+ }
127
+ function toggleAll() {
128
+ if (isAllSelected.value) {
129
+ const next = { ...rowSelection.value };
130
+ for (const r of rows.value) delete next[pkOf(r)];
131
+ rowSelection.value = next;
132
+ } else {
133
+ const next = { ...rowSelection.value };
134
+ for (const r of rows.value) next[pkOf(r)] = true;
135
+ rowSelection.value = next;
136
+ }
137
+ }
138
+ function toggleRowByKey(key) {
139
+ const next = { ...rowSelection.value };
140
+ if (next[key]) delete next[key];
141
+ else next[key] = true;
142
+ rowSelection.value = next;
143
+ }
144
+ const quickEditOpen = ref(false);
145
+ const quickEditId = ref(null);
146
+ function openQuickEdit(id) {
147
+ quickEditId.value = id;
148
+ quickEditOpen.value = true;
149
+ }
150
+ function onQuickEditSaved(updated) {
151
+ if (offlineMode.value) {
152
+ const lk = props.lookup;
153
+ const next = (props.items ?? []).map(
154
+ (r) => String(atKey(r, lk)) === String(atKey(updated, lk)) ? updated : r
155
+ );
156
+ emit("update:items", next);
157
+ return;
158
+ }
159
+ if (hybridMode.value) hybridLoaded.value = false;
160
+ refresh();
161
+ }
162
+ const quickEditLocalItem = computed(() => {
163
+ if (!offlineMode.value || quickEditId.value == null) return null;
164
+ return (props.items ?? []).find(
165
+ (r) => String(atKey(r, props.lookup)) === String(quickEditId.value)
166
+ ) ?? null;
167
+ });
168
+ async function deleteRow(item) {
169
+ const ok = await confirm.ask({
170
+ title: t("mapo.listTable.deleteItemTitle"),
171
+ message: t("mapo.confirmDelete"),
172
+ confirmText: t("mapo.delete"),
173
+ dangerous: true
174
+ });
175
+ if (!ok) return;
176
+ if (offlineMode.value) {
177
+ const next = (props.items ?? []).filter(
178
+ (r) => String(atKey(r, props.lookup)) !== String(atKey(item, props.lookup))
179
+ );
180
+ emit("update:items", next);
181
+ snack.show(t("mapo.listTable.itemDeleted"), "success");
182
+ return;
183
+ }
184
+ try {
185
+ await crud.delete(atKey(item, props.lookup));
186
+ snack.show(t("mapo.listTable.itemDeleted"), "success");
187
+ if (hybridMode.value) hybridLoaded.value = false;
188
+ refresh();
189
+ } catch {
190
+ snack.show(t("mapo.listTable.deleteItemError"), "error");
191
+ }
192
+ }
193
+ const canReorder = computed(
194
+ () => props.draggable && !search.value && sorting.value.length === 0
195
+ );
196
+ const tableWrapper = ref(null);
197
+ const dragFrom = ref(null);
198
+ const dragOverIndex = ref(null);
199
+ function rowElements() {
200
+ return tableWrapper.value ? Array.from(tableWrapper.value.querySelectorAll("tbody tr")) : [];
201
+ }
202
+ function clearRowClasses() {
203
+ for (const el of rowElements())
204
+ el.classList.remove(
205
+ "mapo-drop-before",
206
+ "mapo-drop-after",
207
+ "mapo-drag-source"
208
+ );
209
+ }
210
+ function clearDragState() {
211
+ clearRowClasses();
212
+ dragFrom.value = null;
213
+ dragOverIndex.value = null;
214
+ }
215
+ function onDragStart(idx) {
216
+ if (!canReorder.value) return;
217
+ dragFrom.value = idx;
218
+ }
219
+ function onRowDragOver(e) {
220
+ if (dragFrom.value === null) return;
221
+ e.preventDefault();
222
+ const tr = e.target?.closest(
223
+ "tbody tr"
224
+ );
225
+ if (!tr) return;
226
+ const els = rowElements();
227
+ const idx = els.indexOf(tr);
228
+ if (idx < 0) return;
229
+ const rect = tr.getBoundingClientRect();
230
+ const before = e.clientY < rect.top + rect.height / 2;
231
+ clearRowClasses();
232
+ tr.classList.add(before ? "mapo-drop-before" : "mapo-drop-after");
233
+ els[dragFrom.value]?.classList.add("mapo-drag-source");
234
+ dragOverIndex.value = idx;
235
+ }
236
+ function onRowDrop(e) {
237
+ e.preventDefault();
238
+ const from = dragFrom.value;
239
+ const to = dragOverIndex.value;
240
+ clearDragState();
241
+ if (from !== null && to !== null) void onDrop(from, to);
242
+ }
243
+ function onDragEnd() {
244
+ clearDragState();
245
+ }
246
+ async function onDrop(fromIdx, toIdx) {
247
+ if (fromIdx === toIdx) return;
248
+ const arr = [...rows.value];
249
+ const moved = arr[fromIdx];
250
+ const target = arr[toIdx];
251
+ arr.splice(fromIdx, 1);
252
+ arr.splice(toIdx, 0, moved);
253
+ rows.value = arr;
254
+ if (offlineMode.value) {
255
+ const lk = props.lookup;
256
+ const full = [...props.items ?? []];
257
+ const fIdx = full.findIndex(
258
+ (r) => String(atKey(r, lk)) === String(atKey(moved, lk))
259
+ );
260
+ const tIdx = full.findIndex(
261
+ (r) => String(atKey(r, lk)) === String(atKey(target, lk))
262
+ );
263
+ if (fIdx >= 0 && tIdx >= 0) {
264
+ const [m] = full.splice(fIdx, 1);
265
+ full.splice(tIdx, 0, m);
266
+ emit("update:items", full);
267
+ }
268
+ return;
269
+ }
270
+ try {
271
+ await crud.updateOrder(
272
+ atKey(moved, props.lookup),
273
+ atKey(target, props.lookup)
274
+ );
275
+ snack.show(t("mapo.listTable.orderSaved"), "success");
276
+ if (hybridMode.value) {
277
+ hybridLoaded.value = false;
278
+ refresh();
279
+ }
280
+ } catch {
281
+ snack.show(t("mapo.listTable.orderError"), "error");
282
+ refresh();
283
+ }
284
+ }
285
+ function applyOffline(source) {
286
+ let arr = [...source];
287
+ if (search.value) {
288
+ const q = search.value.toLowerCase();
289
+ arr = arr.filter(
290
+ (row) => props.columns.some(
291
+ (c) => String(row[c.key] ?? "").toLowerCase().includes(q)
292
+ )
293
+ );
294
+ }
295
+ for (const [key, rawVal] of Object.entries(props.filterParams ?? {})) {
296
+ if (rawVal == null || rawVal === "") continue;
297
+ const parts = String(rawVal).split(",");
298
+ const isDateRange = parts.length === 2 && parts.every((p) => !Number.isNaN(Date.parse(p)));
299
+ if (isDateRange) {
300
+ const [start2, end] = parts;
301
+ arr = arr.filter((row) => {
302
+ const v = atKey(row, key);
303
+ if (v == null) return false;
304
+ const s = String(v);
305
+ return s >= start2 && s <= end;
306
+ });
307
+ } else if (parts.length > 1) {
308
+ const set = new Set(parts);
309
+ arr = arr.filter((row) => set.has(String(atKey(row, key))));
310
+ } else {
311
+ arr = arr.filter((row) => String(atKey(row, key)) === parts[0]);
312
+ }
313
+ }
314
+ if (sorting.value.length) {
315
+ const sortDefs = sorting.value;
316
+ arr.sort((a, b) => {
317
+ for (const s of sortDefs) {
318
+ const av = atKey(a, s.id);
319
+ const bv = atKey(b, s.id);
320
+ if (av == null && bv == null) continue;
321
+ if (av == null) return 1;
322
+ if (bv == null) return -1;
323
+ if (av < bv) return s.desc ? 1 : -1;
324
+ if (av > bv) return s.desc ? -1 : 1;
325
+ }
326
+ return 0;
327
+ });
328
+ }
329
+ total.value = arr.length;
330
+ const start = pagination.value.pageIndex * pagination.value.pageSize;
331
+ if (arr.length > 0 && start >= arr.length) {
332
+ pagination.value = { ...pagination.value, pageIndex: 0 };
333
+ rows.value = arr.slice(0, pagination.value.pageSize);
334
+ return;
335
+ }
336
+ rows.value = arr.slice(start, start + pagination.value.pageSize);
337
+ }
338
+ async function fetchAll() {
339
+ loading.value = true;
340
+ try {
341
+ const endpointParams = splitEndpointParams(props.endpoint).params;
342
+ const res = await crud.list(endpointParams);
343
+ let nextItems = [];
344
+ if (props.responseAdapter) {
345
+ nextItems = props.responseAdapter(res).items;
346
+ } else if (res && typeof res === "object" && "results" in res) {
347
+ nextItems = res.results;
348
+ } else {
349
+ nextItems = res;
350
+ }
351
+ fullDataset.value = nextItems;
352
+ hybridLoaded.value = true;
353
+ } catch {
354
+ snack.show(t("mapo.loadError"), "error");
355
+ } finally {
356
+ loading.value = false;
357
+ }
358
+ }
359
+ async function refresh() {
360
+ if (offlineMode.value) {
361
+ applyOffline(props.items ?? []);
362
+ return;
363
+ }
364
+ if (hybridMode.value) {
365
+ if (!hybridLoaded.value) await fetchAll();
366
+ applyOffline(fullDataset.value);
367
+ return;
368
+ }
369
+ loading.value = true;
370
+ try {
371
+ const endpointParams = splitEndpointParams(props.endpoint).params;
372
+ const pageState = {
373
+ page: pagination.value.pageIndex + 1,
374
+ pageSize: pagination.value.pageSize
375
+ };
376
+ const paginationP = props.paginationParams ? props.paginationParams(pageState) : { page: pageState.page, page_size: pageState.pageSize };
377
+ const params = {
378
+ ...endpointParams,
379
+ ...props.filterParams ?? {},
380
+ ...paginationP
381
+ };
382
+ if (search.value) params.search = search.value;
383
+ if (sorting.value.length)
384
+ params.ordering = sorting.value.map((s) => `${s.desc ? "-" : ""}${s.id}`).join(",");
385
+ const res = await crud.list(params);
386
+ let nextItems = [];
387
+ let nextTotal = 0;
388
+ if (props.responseAdapter) {
389
+ const adapted = props.responseAdapter(res);
390
+ nextItems = adapted.items;
391
+ nextTotal = adapted.total;
392
+ } else if (res && typeof res === "object" && "results" in res) {
393
+ nextItems = res.results;
394
+ nextTotal = res.count;
395
+ } else {
396
+ nextItems = res;
397
+ nextTotal = res.length;
398
+ }
399
+ if (nextItems.length === 0 && nextTotal > 0 && pagination.value.pageIndex > 0) {
400
+ pagination.value = { ...pagination.value, pageIndex: 0 };
401
+ return;
402
+ }
403
+ rows.value = nextItems;
404
+ total.value = nextTotal;
405
+ } catch {
406
+ snack.show(t("mapo.loadError"), "error");
407
+ } finally {
408
+ loading.value = false;
409
+ }
410
+ }
411
+ watch([() => props.endpoint, () => props.clientSide], () => {
412
+ hybridLoaded.value = false;
413
+ });
414
+ const filterParamsKey = computed(
415
+ () => JSON.stringify(props.filterParams ?? {})
416
+ );
417
+ watch(
418
+ [
419
+ () => props.endpoint,
420
+ () => props.items,
421
+ filterParamsKey,
422
+ () => pagination.value.pageIndex,
423
+ () => pagination.value.pageSize,
424
+ sorting,
425
+ search
426
+ ],
427
+ ([newEndpoint, , newFilters], [oldEndpoint, , oldFilters]) => {
428
+ const contextChanged = newEndpoint !== oldEndpoint || newFilters !== oldFilters;
429
+ if (contextChanged && pagination.value.pageIndex !== 0) {
430
+ pagination.value = { ...pagination.value, pageIndex: 0 };
431
+ } else {
432
+ refresh();
433
+ }
434
+ },
435
+ { immediate: true, deep: true }
436
+ );
437
+ const UCheckbox = resolveComponent("UCheckbox");
438
+ const UButton = resolveComponent("UButton");
439
+ const UIcon = resolveComponent("UIcon");
440
+ const tableColumns = computed(() => {
441
+ const cols = [];
442
+ cols.push({
443
+ id: "__select__",
444
+ header: () => h(UCheckbox, {
445
+ modelValue: isAllSelected.value,
446
+ indeterminate: isIndeterminate.value,
447
+ "onUpdate:modelValue": toggleAll,
448
+ ariaLabel: t("mapo.listTable.selectAllRows")
449
+ }),
450
+ cell: ({ row }) => {
451
+ const k = pkOf(row.original);
452
+ return h(UCheckbox, {
453
+ modelValue: !!rowSelection.value[k],
454
+ "onUpdate:modelValue": () => toggleRowByKey(k),
455
+ ariaLabel: t("mapo.listTable.selectRow")
456
+ });
457
+ },
458
+ meta: { class: { th: "w-10", td: "w-10" } }
459
+ });
460
+ if (props.draggable) {
461
+ cols.push({
462
+ id: "__drag__",
463
+ header: "",
464
+ cell: ({ row }) => h(
465
+ "span",
466
+ {
467
+ class: canReorder.value ? "cursor-grab text-muted" : "cursor-not-allowed text-muted opacity-30",
468
+ draggable: canReorder.value,
469
+ title: canReorder.value ? t("mapo.listTable.dragToReorder") : t("mapo.listTable.clearToReorder"),
470
+ onDragstart: (e) => {
471
+ e.dataTransfer?.setData("text/plain", "");
472
+ onDragStart(row.index);
473
+ }
474
+ },
475
+ h(UIcon, { name: "i-lucide-grip-vertical", class: "h-4 w-4" })
476
+ ),
477
+ meta: { class: { th: "w-8", td: "w-8" } }
478
+ });
479
+ }
480
+ const NuxtLink = resolveComponent("NuxtLink");
481
+ for (let i = 0; i < props.columns.length; i++) {
482
+ const col = props.columns[i];
483
+ const isFirst = i === 0 && !!props.detailBase;
484
+ cols.push({
485
+ accessorKey: col.key,
486
+ header: col.label,
487
+ cell: ({ row }) => {
488
+ const cellSlot = slots[`cell.${col.key}`];
489
+ if (cellSlot)
490
+ return cellSlot({
491
+ item: row.original,
492
+ value: atKey(row.original, col.key)
493
+ });
494
+ const cellVal = atKey(row.original, col.key);
495
+ if (isFirst) {
496
+ return h(
497
+ NuxtLink,
498
+ {
499
+ to: `${props.detailBase}/${atKey(row.original, props.lookup)}`,
500
+ class: "font-medium hover:underline"
501
+ },
502
+ () => String(cellVal ?? "\u2014")
503
+ );
504
+ }
505
+ return String(cellVal ?? "\u2014");
506
+ },
507
+ meta: { class: { td: col.class ?? "" } }
508
+ });
509
+ }
510
+ cols.push({
511
+ id: "__actions__",
512
+ header: "",
513
+ cell: ({ row }) => {
514
+ const buttons = [];
515
+ if (props.editFields.length > 0 && canEditRow.value) {
516
+ buttons.push(
517
+ h(UButton, {
518
+ size: "xs",
519
+ variant: "ghost",
520
+ color: "neutral",
521
+ icon: "i-lucide-pencil",
522
+ onClick: () => openQuickEdit(
523
+ atKey(row.original, props.lookup)
524
+ )
525
+ })
526
+ );
527
+ }
528
+ if (canDeleteRow.value) {
529
+ buttons.push(
530
+ h(UButton, {
531
+ size: "xs",
532
+ variant: "ghost",
533
+ color: "error",
534
+ icon: "i-lucide-trash-2",
535
+ onClick: () => deleteRow(row.original)
536
+ })
537
+ );
538
+ }
539
+ return h(
540
+ "div",
541
+ { class: "flex items-center gap-1 justify-end" },
542
+ buttons
543
+ );
544
+ },
545
+ meta: { class: { th: "text-right", td: "text-right" } }
546
+ });
547
+ return cols;
548
+ });
549
+ const paginationOptions = computed(() => ({
550
+ manualPagination: true,
551
+ rowCount: total.value
552
+ }));
553
+ const sortingOptions = computed(() => ({
554
+ manualSorting: true
555
+ }));
556
+ </script>
557
+
558
+ <template>
559
+ <div class="mapo-list-table space-y-3">
560
+ <!-- Search -->
561
+ <div v-if="searchable" class="flex items-center gap-2">
562
+ <UInput
563
+ :model-value="search"
564
+ :placeholder="t('mapo.search')"
565
+ icon="i-lucide-search"
566
+ size="sm"
567
+ class="max-w-xs"
568
+ @update:model-value="onSearchInput"
569
+ />
570
+ <slot name="dtable.toolbar" />
571
+ </div>
572
+
573
+ <!-- Table — the drop area spans the whole row via delegated DnD on this wrapper. -->
574
+ <div
575
+ ref="tableWrapper"
576
+ @dragover="onRowDragOver"
577
+ @drop="onRowDrop"
578
+ @dragend="onDragEnd"
579
+ >
580
+ <UTable
581
+ :data="rows"
582
+ :columns="tableColumns"
583
+ :loading="loading"
584
+ :pagination="pagination"
585
+ :pagination-options="paginationOptions"
586
+ :sorting="sorting"
587
+ :sorting-options="sortingOptions"
588
+ :empty="t('mapo.listTable.noItems')"
589
+ @update:pagination="pagination = $event ?? pagination"
590
+ @update:sorting="sorting = $event ?? sorting"
591
+ >
592
+ <template #empty>
593
+ <slot name="dtable.empty">
594
+ <div class="flex flex-col items-center gap-2 py-8 text-muted">
595
+ <UIcon name="i-lucide-inbox" class="h-8 w-8" />
596
+ <span class="text-sm">{{ t("mapo.listTable.noItems") }}</span>
597
+ </div>
598
+ </slot>
599
+ </template>
600
+
601
+ <template #loading>
602
+ <slot name="dtable.loading">
603
+ <div class="flex justify-center py-8">
604
+ <UIcon
605
+ name="i-lucide-loader-circle"
606
+ class="h-6 w-6 animate-spin text-muted"
607
+ />
608
+ </div>
609
+ </slot>
610
+ </template>
611
+ </UTable>
612
+ </div>
613
+
614
+ <!-- Pagination controls -->
615
+ <div class="flex items-center justify-between text-sm text-muted">
616
+ <span>{{ t("mapo.listTable.totalItems", { total }) }}</span>
617
+ <UPagination
618
+ :model-value="pagination.pageIndex + 1"
619
+ :total="total"
620
+ :items-per-page="pagination.pageSize"
621
+ size="sm"
622
+ @update:model-value="
623
+ pagination = { ...pagination, pageIndex: $event - 1 }
624
+ "
625
+ />
626
+ <USelect
627
+ :model-value="pagination.pageSize"
628
+ :items="
629
+ pageSizeOptions.map((n) => ({
630
+ label: t('mapo.listTable.perPage', { n }),
631
+ value: n
632
+ }))
633
+ "
634
+ size="xs"
635
+ class="w-28"
636
+ @update:model-value="
637
+ pagination = { pageIndex: 0, pageSize: Number($event) }
638
+ "
639
+ />
640
+ </div>
641
+
642
+ <!-- Quick edit modal -->
643
+ <MapoListQuickEdit
644
+ v-if="editFields.length > 0"
645
+ v-model:open="quickEditOpen"
646
+ :endpoint="crudBase"
647
+ :item-id="quickEditId"
648
+ :edit-fields="editFields"
649
+ :lookup="lookup"
650
+ :languages="languages"
651
+ :registry="registry"
652
+ :offline="offlineMode"
653
+ :local-item="quickEditLocalItem"
654
+ @saved="onQuickEditSaved"
655
+ >
656
+ <template v-for="(_, name) in $slots" #[name]="slotProps">
657
+ <slot :name="`qedit.${String(name)}`" v-bind="slotProps ?? {}" />
658
+ </template>
659
+ </MapoListQuickEdit>
660
+ </div>
661
+ </template>
662
+
663
+ <style scoped>
664
+ .mapo-list-table :deep(tbody tr.mapo-drag-source){opacity:.4}.mapo-list-table :deep(tbody tr.mapo-drop-before>td){box-shadow:inset 0 2px 0 0 var(--ui-primary,#3b82f6)}.mapo-list-table :deep(tbody tr.mapo-drop-after>td){box-shadow:inset 0 -2px 0 0 var(--ui-primary,#3b82f6)}
665
+ </style>