@mapomodule/uikit 2.0.0-beta.8 → 2.0.0-experimental.2

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,39 @@
1
+ <script setup lang="ts">
2
+ import { computed } from "vue";
3
+ import { useMapoDetail } from "../composables/useMapoDetail";
4
+ import { detailExtensions } from "../composables/defineDetailExtension";
5
+ import type { DetailExtensionPlacement } from "../types/detail";
6
+
7
+ /**
8
+ * Renders the extensions registered with `defineDetailExtension()` for one
9
+ * placement of the surrounding `MapoDetail`, in their order. `MapoDetail` uses
10
+ * it itself; place it in a slot that replaces one of those places, such as
11
+ * `side-buttons`, to keep the extensions there.
12
+ */
13
+ const props = defineProps<{
14
+ /** Which extensions: `actions` or `body-top`. */
15
+ placement: DetailExtensionPlacement;
16
+ }>();
17
+
18
+ const detail = useMapoDetail();
19
+ const registry = detailExtensions();
20
+
21
+ const shown = computed(() => {
22
+ if (!detail) return [];
23
+ const allowed = detail.extensions.value;
24
+ if (allowed === false) return [];
25
+ return registry
26
+ .filter((extension) => extension.placement === props.placement)
27
+ .filter((extension) => allowed === true || allowed.includes(extension.key))
28
+ .filter((extension) => extension.visible?.(detail) ?? true)
29
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
30
+ });
31
+ </script>
32
+
33
+ <template>
34
+ <component
35
+ :is="extension.component"
36
+ v-for="extension in shown"
37
+ :key="extension.key"
38
+ />
39
+ </template>
@@ -9,8 +9,9 @@ const props = withDefaults(
9
9
  errors?: Record<string, string[]>;
10
10
  noRouteChange?: boolean;
11
11
  /**
12
- * Number of languages above which the select also shows a dropdown
13
- * alongside the tab bar (for quick navigation). Default: `8`.
12
+ * Number of languages above which a searchable select appears next to the
13
+ * tab bar, for quick navigation. Default: `8`. `0` always shows it,
14
+ * `Infinity` never does.
14
15
  */
15
16
  langThreshold?: number;
16
17
  }>(),
@@ -69,6 +70,9 @@ function onSelectChange(v: unknown) {
69
70
 
70
71
  // ─── Select menu items ────────────────────────────────────────────────────────
71
72
 
73
+ // A few languages fit in the tab bar; the select only helps once they overflow it.
74
+ const showSelect = computed(() => props.langs.length > props.langThreshold);
75
+
72
76
  const selectItems = computed(() =>
73
77
  props.langs.map((lang) => ({
74
78
  label: lang.toUpperCase(),
@@ -106,26 +110,21 @@ watch(
106
110
  <div
107
111
  class="flex items-end gap-0 border-b border-gray-200 dark:border-gray-700 mt-2 mb-4"
108
112
  >
109
- <!-- Language select — always visible, aligned at bottom of row -->
110
- <USelectMenu
111
- :model-value="modelValue"
112
- :items="selectItems"
113
- value-key="value"
114
- label-key="label"
115
- size="sm"
116
- class="w-28 shrink-0 mb-px"
117
- @update:model-value="onSelectChange"
118
- >
119
- <template #default="{ open }">
120
- <UButton
121
- size="sm"
122
- variant="ghost"
123
- color="neutral"
124
- :trailing-icon="
125
- open ? 'i-lucide-chevron-up' : 'i-lucide-chevron-down'
126
- "
127
- class="w-full justify-between font-medium"
128
- >
113
+ <!-- Language select — above langThreshold only, aligned at bottom of row -->
114
+ <template v-if="showSelect">
115
+ <USelectMenu
116
+ :model-value="modelValue"
117
+ :items="selectItems"
118
+ value-key="value"
119
+ label-key="label"
120
+ size="sm"
121
+ variant="ghost"
122
+ class="w-28 shrink-0 mb-px font-medium"
123
+ @update:model-value="onSelectChange"
124
+ >
125
+ <!-- The trigger is already a button with its own chevron: the slot
126
+ holds only what it shows, never another button. -->
127
+ <template #default>
129
128
  <span class="flex items-center gap-1">
130
129
  <span
131
130
  v-if="hasErrors(modelValue)"
@@ -133,12 +132,12 @@ watch(
133
132
  />
134
133
  {{ modelValue.toUpperCase() }}
135
134
  </span>
136
- </UButton>
137
- </template>
138
- </USelectMenu>
135
+ </template>
136
+ </USelectMenu>
139
137
 
140
- <!-- Divider -->
141
- <div class="h-5 w-px bg-gray-200 dark:bg-gray-700 mx-2 shrink-0" />
138
+ <!-- Divider -->
139
+ <div class="h-5 w-px bg-gray-200 dark:bg-gray-700 mx-2 shrink-0" />
140
+ </template>
142
141
 
143
142
  <!-- Tab bar — always shown, scrollable -->
144
143
  <div class="flex gap-1 overflow-x-auto scrollbar-none flex-1">
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts" generic="T extends object">
2
- import { ref, computed, watch, useSlots } from "vue";
2
+ import { ref, computed, watch, useSlots, onBeforeUnmount } from "vue";
3
3
  import type { Ref } from "vue";
4
4
  import type {
5
5
  ListColumn,
@@ -30,6 +30,7 @@ const props = withDefaults(
30
30
  * Ignored when `items` is provided.
31
31
  */
32
32
  clientSide?: boolean;
33
+ /** Column definitions. A dotted `key` (`category.name`) reads a field of a related object. */
33
34
  columns: ListColumn<T>[];
34
35
  lookup?: string;
35
36
  // Filters
@@ -56,11 +57,20 @@ const props = withDefaults(
56
57
  * hides the trash unless the user has `delete_article`. Omit to always show both.
57
58
  */
58
59
  permissionModel?: string;
60
+ /**
61
+ * Whether to include the built-in permanent delete bulk action.
62
+ * Defaults to `true`; custom `actions` are unaffected.
63
+ */
64
+ defaultActions?: boolean;
59
65
  // Pagination
60
- /** Initial page size. Default: 20. */
61
- defaultPageSize?: number;
62
- /** Page size options shown in the per-page selector. Default: [10, 20, 50, 100]. */
63
- pageSizeOptions?: number[];
66
+ /** Initial page size: a number, or `"all"`. Default: 20. */
67
+ defaultPageSize?: number | "all";
68
+ /**
69
+ * Options of the per-page selector. `"all"` adds an option that requests
70
+ * the list without pagination params, like `clientSide` does: the backend
71
+ * has to return the whole collection then. Default: [10, 20, 50, 100].
72
+ */
73
+ pageSizeOptions?: (number | "all")[];
64
74
  /**
65
75
  * Custom response parser. Replaces the built-in DRF / flat-array detection.
66
76
  * Return `{ items, total }` from any shape your backend returns.
@@ -169,6 +179,9 @@ const writeUrlState = debounce(() => {
169
179
 
170
180
  watch([activeTab, activeFilters], writeUrlState, { deep: true });
171
181
 
182
+ // A URL write still pending when the list goes away would land on the next page.
183
+ onBeforeUnmount(() => writeUrlState.cancel());
184
+
172
185
  // --- crudEndpoint: base path for mutations (no query string). ---
173
186
  const crudEndpoint = computed(
174
187
  () => (props.endpoint ?? "").split("?")[0] || (props.endpoint ?? ""),
@@ -296,6 +309,8 @@ watch([activeTab, activeFilters], () => {
296
309
  :selection-query="selectionQuery"
297
310
  :endpoint="crudEndpoint"
298
311
  :lookup="lookup"
312
+ :permission-model="permissionModel"
313
+ :default-actions="defaultActions"
299
314
  @action-completed="refresh"
300
315
  />
301
316
  </div>
@@ -15,10 +15,16 @@ const props = withDefaults(
15
15
  selectionQuery: URLSearchParams;
16
16
  endpoint: string;
17
17
  lookup?: string;
18
+ /** Django model label used to gate the built-in permanent delete action. */
19
+ permissionModel?: string;
20
+ /** Whether to include the built-in permanent delete action. */
21
+ defaultActions?: boolean;
18
22
  }>(),
19
23
  {
20
24
  actions: () => [],
21
25
  lookup: "id",
26
+ permissionModel: undefined,
27
+ defaultActions: true,
22
28
  },
23
29
  );
24
30
 
@@ -34,11 +40,12 @@ defineSlots<{
34
40
  const { t } = useI18n();
35
41
  const snack = useSnackStore();
36
42
  const confirm = useConfirmStore();
43
+ const { canDelete, checkPermission } = usePermissions();
37
44
  const crud = useCrud<T>(props.endpoint);
38
45
 
39
46
  const isRunning = ref(false);
40
47
 
41
- const defaultActions = computed<ActionDescriptor<T>[]>(() => [
48
+ const builtInActions = computed<ActionDescriptor<T>[]>(() => [
42
49
  {
43
50
  label: t("mapo.listActions.permanentDelete"),
44
51
  handler: async ({ selection }) => {
@@ -51,13 +58,15 @@ const defaultActions = computed<ActionDescriptor<T>[]>(() => [
51
58
  ),
52
59
  );
53
60
  },
54
- permissions: "delete",
55
61
  handleMultiple: true,
56
62
  handleAll: false,
57
63
  },
58
64
  ]);
59
65
 
60
- const allActions = computed(() => [...defaultActions.value, ...props.actions]);
66
+ const allActions = computed(() => [
67
+ ...(props.defaultActions ? builtInActions.value : []),
68
+ ...props.actions,
69
+ ]);
61
70
 
62
71
  const visibleActions = computed(() =>
63
72
  allActions.value.filter((a) =>
@@ -80,13 +89,16 @@ const applyButtonColor = computed(() =>
80
89
  );
81
90
 
82
91
  function canRun(action: ActionDescriptor<T>): boolean {
92
+ if (builtInActions.value.includes(action)) {
93
+ return !props.permissionModel || canDelete(props.permissionModel);
94
+ }
95
+
83
96
  const perms = action.permissions
84
97
  ? Array.isArray(action.permissions)
85
98
  ? action.permissions
86
99
  : [action.permissions]
87
100
  : [];
88
101
  if (!perms.length) return true;
89
- const { checkPermission } = usePermissions();
90
102
  return perms.every((p) => checkPermission(p));
91
103
  }
92
104
 
@@ -7,6 +7,7 @@ import {
7
7
  h,
8
8
  resolveComponent,
9
9
  useSlots,
10
+ onBeforeUnmount,
10
11
  } from "vue";
11
12
  import type { Ref } from "vue";
12
13
  import { useI18n } from "vue-i18n";
@@ -18,8 +19,20 @@ import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
18
19
  import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
19
20
  import { useCrud } from "@mapomodule/core/runtime/api/crud";
20
21
  import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
21
- import { debounce, splitEndpointParams } from "@mapomodule/utils";
22
+ import {
23
+ debounce,
24
+ getNestedValue,
25
+ splitEndpointParams,
26
+ } from "@mapomodule/utils";
22
27
  import { useRoute, useRouter } from "#app";
28
+ import {
29
+ ALL_ROWS,
30
+ formatPageSize,
31
+ nextSorting,
32
+ orderingParam,
33
+ parsePageSize,
34
+ toPageSize,
35
+ } from "../utils/listTable.js";
23
36
 
24
37
  const props = withDefaults(
25
38
  defineProps<{
@@ -44,10 +57,14 @@ const props = withDefaults(
44
57
  * and tab params without baking them into the endpoint string.
45
58
  */
46
59
  filterParams?: Record<string, unknown>;
47
- /** Initial page size. Default: 20. */
48
- defaultPageSize?: number;
49
- /** Page size options shown in the per-page selector. Default: [10, 20, 50, 100]. */
50
- pageSizeOptions?: number[];
60
+ /** Initial page size: a number, or `"all"`. Default: 20. */
61
+ defaultPageSize?: number | "all";
62
+ /**
63
+ * Options of the per-page selector. `"all"` adds an option that requests
64
+ * the list without pagination params, like `clientSide` does: the backend
65
+ * has to return the whole collection then. Default: [10, 20, 50, 100].
66
+ */
67
+ pageSizeOptions?: (number | "all")[];
51
68
  /**
52
69
  * Custom response parser. When provided it replaces the built-in DRF / flat-array
53
70
  * detection. Return `{ items, total }` from any shape your backend returns.
@@ -70,6 +87,7 @@ const props = withDefaults(
70
87
  * still hit the backend, then re-fetch. Ignored when `items` is provided.
71
88
  */
72
89
  clientSide?: boolean;
90
+ /** Column definitions. A dotted `key` (`category.name`) reads a field of a related object. */
73
91
  columns: ListColumn<T>[];
74
92
  lookup?: string;
75
93
  searchable?: boolean;
@@ -135,10 +153,11 @@ defineSlots<
135
153
 
136
154
  const slots = useSlots();
137
155
 
138
- // T extends object but not Record<string,unknown>, so dynamic key access needs a cast.
139
- // Casting the key to keyof T returns the union of all property types rather than `unknown`,
140
- // which is both accurate and avoids any implicit-any errors at the call sites.
141
- const atKey = (item: T, key: string): T[keyof T] => item[key as keyof T];
156
+ // A key can be a dotted path into a related object (`category.name`). The cast to
157
+ // T[keyof T] gives the call sites the union of the row's property types rather
158
+ // than `unknown`.
159
+ const atKey = (item: T, key: string): T[keyof T] =>
160
+ getNestedValue(item, key) as T[keyof T];
142
161
 
143
162
  const { t } = useI18n();
144
163
  const snack = useSnackStore();
@@ -187,14 +206,24 @@ function toPositiveNumber(value: unknown, fallback: number): number {
187
206
  }
188
207
 
189
208
  // --- Pagination (restored from URL) ---
209
+ // "All rows" is stored as the ALL_ROWS page size and written as `page_size=all`.
210
+ const defaultPageSize = toPageSize(props.defaultPageSize);
190
211
  const pagination = ref<PaginationState>({
191
212
  pageIndex: route.query.page
192
213
  ? Math.max(0, toPositiveNumber(route.query.page, 1) - 1)
193
214
  : 0,
194
215
  pageSize: route.query.page_size
195
- ? toPositiveNumber(route.query.page_size, props.defaultPageSize)
196
- : props.defaultPageSize,
216
+ ? parsePageSize(route.query.page_size, defaultPageSize)
217
+ : defaultPageSize,
197
218
  });
219
+ const showsAllRows = computed(() => pagination.value.pageSize === ALL_ROWS);
220
+ const pageSizeItems = computed(() =>
221
+ props.pageSizeOptions.map((option) =>
222
+ option === "all"
223
+ ? { label: t("mapo.listTable.allRows"), value: ALL_ROWS }
224
+ : { label: t("mapo.listTable.perPage", { n: option }), value: option },
225
+ ),
226
+ );
198
227
 
199
228
  // --- Sorting (restored from URL) ---
200
229
  const sorting = ref<SortingState>(
@@ -226,8 +255,8 @@ const writeUrlState = debounce(() => {
226
255
  const page = pagination.value.pageIndex + 1;
227
256
  if (page > 1) query.page = String(page);
228
257
  else delete query.page;
229
- if (pagination.value.pageSize !== props.defaultPageSize)
230
- query.page_size = String(pagination.value.pageSize);
258
+ if (pagination.value.pageSize !== defaultPageSize)
259
+ query.page_size = formatPageSize(pagination.value.pageSize);
231
260
  else delete query.page_size;
232
261
  if (search.value) query.search = search.value;
233
262
  else delete query.search;
@@ -241,6 +270,13 @@ const writeUrlState = debounce(() => {
241
270
 
242
271
  watch([pagination, search, sorting], writeUrlState, { deep: true });
243
272
 
273
+ // A debounced call still pending when the list goes away would act on the next
274
+ // page: the URL write would put this list's query on it.
275
+ onBeforeUnmount(() => {
276
+ onSearchInput.cancel();
277
+ writeUrlState.cancel();
278
+ });
279
+
244
280
  // --- Row selection ---
245
281
  // Selection is keyed by primary key (lookup), not by row index, so pagination/sort/refresh
246
282
  // changes do not affect which rows are marked as selected.
@@ -266,11 +302,12 @@ watch(selectedRows, (rows) => {
266
302
 
267
303
  function buildSelectionQuery(): URLSearchParams {
268
304
  const params = new URLSearchParams();
269
- params.set("page_size", String(pagination.value.pageSize));
305
+ if (!showsAllRows.value)
306
+ params.set("page_size", String(pagination.value.pageSize));
270
307
  if (search.value) params.set("search", search.value);
271
- sorting.value.forEach((s) =>
272
- params.set("ordering", `${s.desc ? "-" : ""}${s.id}`),
273
- );
308
+ // The same ordering the list request sends.
309
+ if (sorting.value.length)
310
+ params.set("ordering", orderingParam(sorting.value));
274
311
  return params;
275
312
  }
276
313
 
@@ -476,7 +513,7 @@ function applyOffline(source: T[]) {
476
513
  const q = search.value.toLowerCase();
477
514
  arr = arr.filter((row) =>
478
515
  props.columns.some((c) =>
479
- String(row[c.key] ?? "")
516
+ String(atKey(row, c.key) ?? "")
480
517
  .toLowerCase()
481
518
  .includes(q),
482
519
  ),
@@ -589,13 +626,11 @@ async function refresh() {
589
626
  const params: Record<string, unknown> = {
590
627
  ...endpointParams,
591
628
  ...(props.filterParams ?? {}),
592
- ...paginationP,
629
+ // "All rows" sends no pagination params: the backend returns the whole collection.
630
+ ...(showsAllRows.value ? {} : paginationP),
593
631
  };
594
632
  if (search.value) params.search = search.value;
595
- if (sorting.value.length)
596
- params.ordering = sorting.value
597
- .map((s) => `${s.desc ? "-" : ""}${s.id}`)
598
- .join(",");
633
+ if (sorting.value.length) params.ordering = orderingParam(sorting.value);
599
634
 
600
635
  const res = await crud.list(params as Record<string, string>);
601
636
 
@@ -657,13 +692,23 @@ watch(
657
692
  search,
658
693
  ],
659
694
  ([newEndpoint, , newFilters], [oldEndpoint, , oldFilters]) => {
660
- const contextChanged =
661
- newEndpoint !== oldEndpoint || newFilters !== oldFilters;
662
- if (contextChanged && pagination.value.pageIndex !== 0) {
663
- pagination.value = { ...pagination.value, pageIndex: 0 };
664
- } else {
695
+ // The immediate first run has no old values: it is the initial load, so it
696
+ // fetches the page restored from the URL.
697
+ const isFirstRun = oldFilters === undefined;
698
+ if (isFirstRun) {
665
699
  refresh();
700
+ return;
666
701
  }
702
+ const endpointChanged = newEndpoint !== oldEndpoint;
703
+ const filtersChanged = newFilters !== oldFilters;
704
+ const contextChanged = endpointChanged || filtersChanged;
705
+ const isOnFirstPage = pagination.value.pageIndex === 0;
706
+ // Moving to the first page runs this watcher again, and that run fetches.
707
+ if (contextChanged && !isOnFirstPage) {
708
+ pagination.value = { ...pagination.value, pageIndex: 0 };
709
+ return;
710
+ }
711
+ refresh();
667
712
  },
668
713
  { immediate: true, deep: true },
669
714
  );
@@ -673,6 +718,35 @@ const UCheckbox = resolveComponent("UCheckbox");
673
718
  const UButton = resolveComponent("UButton");
674
719
  const UIcon = resolveComponent("UIcon");
675
720
 
721
+ // A sortable header is a button: the icon shows the current direction, the
722
+ // accessible name says what the next click does (UTable sets no `aria-sort`).
723
+ const SORT_ICONS = {
724
+ none: "i-lucide-arrow-up-down",
725
+ asc: "i-lucide-arrow-up-narrow-wide",
726
+ desc: "i-lucide-arrow-down-wide-narrow",
727
+ };
728
+ const SORT_NEXT_ACTION = {
729
+ none: "mapo.listTable.sortAscending",
730
+ asc: "mapo.listTable.sortDescending",
731
+ desc: "mapo.listTable.clearSorting",
732
+ };
733
+
734
+ function sortHeader(col: ListColumn<T>) {
735
+ const sort = sorting.value.find((s) => s.id === col.key);
736
+ const direction = !sort ? "none" : sort.desc ? "desc" : "asc";
737
+ return h(UButton, {
738
+ color: "neutral",
739
+ variant: "ghost",
740
+ label: col.label,
741
+ icon: SORT_ICONS[direction],
742
+ class: "-mx-2.5",
743
+ "aria-label": t(SORT_NEXT_ACTION[direction], { column: col.label }),
744
+ onClick: () => {
745
+ sorting.value = nextSorting(sorting.value, col.key);
746
+ },
747
+ });
748
+ }
749
+
676
750
  const tableColumns = computed<TableColumn<T>[]>(() => {
677
751
  const cols: TableColumn<T>[] = [];
678
752
 
@@ -731,8 +805,11 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
731
805
  const col = props.columns[i]!;
732
806
  const isFirst = i === 0 && !!props.detailBase;
733
807
  cols.push({
808
+ // TanStack would turn a dotted key into `category_name`; the sorting
809
+ // state uses the column key, so the id must be the key itself.
810
+ id: col.key,
734
811
  accessorKey: col.key,
735
- header: col.label,
812
+ header: col.sortable ? () => sortHeader(col) : col.label,
736
813
  cell: ({ row }: { row: { original: T } }) => {
737
814
  const cellSlot = slots[`cell.${col.key}`];
738
815
  if (cellSlot)
@@ -770,6 +847,7 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
770
847
  variant: "ghost",
771
848
  color: "neutral",
772
849
  icon: "i-lucide-pencil",
850
+ "aria-label": t("mapo.edit"),
773
851
  onClick: () =>
774
852
  openQuickEdit(
775
853
  atKey(row.original, props.lookup) as string | number,
@@ -784,6 +862,7 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
784
862
  variant: "ghost",
785
863
  color: "error",
786
864
  icon: "i-lucide-trash-2",
865
+ "aria-label": t("mapo.delete"),
787
866
  onClick: () => deleteRow(row.original),
788
867
  }),
789
868
  );
@@ -800,6 +879,19 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
800
879
  return cols;
801
880
  });
802
881
 
882
+ // A search or a filter with no match reads differently from an empty list.
883
+ const emptyText = computed(() => {
884
+ const isSearching = !!search.value;
885
+ const isFiltering = Object.values(props.filterParams ?? {}).some(
886
+ (value) => value != null && value !== "",
887
+ );
888
+ return t(
889
+ isSearching || isFiltering
890
+ ? "mapo.listTable.noResults"
891
+ : "mapo.listTable.noItems",
892
+ );
893
+ });
894
+
803
895
  // --- Pagination for UTable ---
804
896
  const paginationOptions = computed(() => ({
805
897
  manualPagination: true,
@@ -841,7 +933,7 @@ const sortingOptions = computed(() => ({
841
933
  :pagination-options="paginationOptions"
842
934
  :sorting="sorting"
843
935
  :sorting-options="sortingOptions"
844
- :empty="t('mapo.listTable.noItems')"
936
+ :empty="emptyText"
845
937
  @update:pagination="pagination = $event ?? pagination"
846
938
  @update:sorting="sorting = $event ?? sorting"
847
939
  >
@@ -849,7 +941,7 @@ const sortingOptions = computed(() => ({
849
941
  <slot name="dtable.empty">
850
942
  <div class="flex flex-col items-center gap-2 py-8 text-muted">
851
943
  <UIcon name="i-lucide-inbox" class="h-8 w-8" />
852
- <span class="text-sm">{{ t("mapo.listTable.noItems") }}</span>
944
+ <span class="text-sm">{{ emptyText }}</span>
853
945
  </div>
854
946
  </slot>
855
947
  </template>
@@ -870,23 +962,18 @@ const sortingOptions = computed(() => ({
870
962
  <!-- Pagination controls -->
871
963
  <div class="flex items-center justify-between text-sm text-muted">
872
964
  <span>{{ t("mapo.listTable.totalItems", { total }) }}</span>
965
+ <!-- Nuxt UI 4's UPagination models `page`: with `modelValue` it runs uncontrolled. -->
873
966
  <UPagination
874
- :model-value="pagination.pageIndex + 1"
967
+ v-if="!showsAllRows"
968
+ :page="pagination.pageIndex + 1"
875
969
  :total="total"
876
970
  :items-per-page="pagination.pageSize"
877
971
  size="sm"
878
- @update:model-value="
879
- pagination = { ...pagination, pageIndex: $event - 1 }
880
- "
972
+ @update:page="pagination = { ...pagination, pageIndex: $event - 1 }"
881
973
  />
882
974
  <USelect
883
975
  :model-value="pagination.pageSize"
884
- :items="
885
- pageSizeOptions.map((n) => ({
886
- label: t('mapo.listTable.perPage', { n }),
887
- value: n,
888
- }))
889
- "
976
+ :items="pageSizeItems"
890
977
  size="xs"
891
978
  class="w-28"
892
979
  @update:model-value="
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { ref, watch, computed } from "vue";
2
+ import { ref, watch, computed, onMounted } from "vue";
3
3
  import { useI18n } from "vue-i18n";
4
4
  import { useRuntimeConfig } from "#app";
5
5
  import {
@@ -12,7 +12,8 @@ import { usePermissions } from "@mapomodule/store/runtime/composables/usePermiss
12
12
  import { useMediaStore } from "../stores/media.js";
13
13
  import type { MediaItem } from "../types/media.js";
14
14
 
15
- defineProps<{
15
+ const props = defineProps<{
16
+ /** Overrides the languages read from the endpoint. Rarely needed. */
16
17
  languages?: string[];
17
18
  defaultLang?: string;
18
19
  }>();
@@ -35,6 +36,18 @@ const saving = ref(false);
35
36
  const newFile = ref<File | null>(null);
36
37
  const maintainUrl = ref(false);
37
38
  const currentLang = ref("");
39
+
40
+ // The languages actually offered. An explicit prop wins; otherwise they come
41
+ // from the media endpoint's own OPTIONS metadata, so a host page never has to
42
+ // restate what the backend already knows — and a media model nobody registered
43
+ // for translation shows no switcher rather than tabs whose values it discards.
44
+ const activeLangs = computed(() =>
45
+ props.languages?.length ? props.languages : store.languages,
46
+ );
47
+
48
+ onMounted(() => {
49
+ store.deriveLanguages();
50
+ });
38
51
  // Pristine copy taken when entering edit mode, restored on Cancel — the form
39
52
  // mutates store.editMedia directly, so without this Cancel would leave the
40
53
  // unsaved edits visible in the info panel (legacy used deepClone the same way).
@@ -254,7 +267,7 @@ function formatDate(dateStr: string): string {
254
267
  <!-- Edit form (shown when editing) -->
255
268
  <div v-if="editing" class="space-y-4 px-4 py-3">
256
269
  <!-- Lang switch -->
257
- <UFieldGroup v-if="languages && languages.length > 1" size="xs">
270
+ <UFieldGroup v-if="activeLangs.length > 1" size="xs">
258
271
  <UButton
259
272
  :variant="currentLang === '' ? 'solid' : 'outline'"
260
273
  color="neutral"
@@ -263,7 +276,7 @@ function formatDate(dateStr: string): string {
263
276
  {{ t("mapo.mediaEditor.defaultLang") }}
264
277
  </UButton>
265
278
  <UButton
266
- v-for="lang in languages"
279
+ v-for="lang in activeLangs"
267
280
  :key="lang"
268
281
  :variant="currentLang === lang ? 'solid' : 'outline'"
269
282
  color="neutral"