@mapomodule/uikit 2.0.0-beta.12 → 2.0.0-beta.14

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 (68) hide show
  1. package/README.md +46 -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__/MapoListTable.component.test.d.ts +2 -0
  9. package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
  10. package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
  11. package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
  12. package/dist/__tests__/listTable.test.d.ts +2 -0
  13. package/dist/__tests__/listTable.test.d.ts.map +1 -0
  14. package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
  15. package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
  16. package/dist/module.json +1 -1
  17. package/dist/runtime/assets/main.css +1 -1
  18. package/dist/runtime/components/MapoConfirmDialog.vue +18 -1
  19. package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
  20. package/dist/runtime/components/MapoDetail.vue +43 -11
  21. package/dist/runtime/components/MapoDetail.vue.d.ts +76 -0
  22. package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
  23. package/dist/runtime/components/MapoDetailLangSwitch.vue +21 -25
  24. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
  25. package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
  26. package/dist/runtime/components/MapoList.vue +3 -2
  27. package/dist/runtime/components/MapoList.vue.d.ts +9 -4
  28. package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
  29. package/dist/runtime/components/MapoListTable.vue +98 -32
  30. package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
  31. package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
  32. package/dist/runtime/components/MapoMediaEditor.vue +10 -4
  33. package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
  34. package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
  35. package/dist/runtime/components/MapoMediaPreview.vue.d.ts +1 -1
  36. package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -1
  37. package/dist/runtime/components/MapoMediaUploader.vue +21 -21
  38. package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
  39. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +1 -1
  40. package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -1
  41. package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +2 -2
  42. package/dist/runtime/stores/media.d.ts +8 -2
  43. package/dist/runtime/stores/media.d.ts.map +1 -1
  44. package/dist/runtime/stores/media.js +16 -0
  45. package/dist/runtime/types/list.d.ts +10 -2
  46. package/dist/runtime/types/list.d.ts.map +1 -1
  47. package/dist/runtime/utils/listTable.d.ts +29 -0
  48. package/dist/runtime/utils/listTable.d.ts.map +1 -0
  49. package/dist/runtime/utils/listTable.js +21 -0
  50. package/package.json +6 -6
  51. package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
  52. package/src/__tests__/MapoDetail.component.test.ts +293 -0
  53. package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
  54. package/src/__tests__/MapoListTable.component.test.ts +504 -0
  55. package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
  56. package/src/__tests__/listTable.test.ts +82 -0
  57. package/src/__tests__/mediaLanguages.test.ts +66 -0
  58. package/src/runtime/assets/main.css +9 -0
  59. package/src/runtime/components/MapoConfirmDialog.vue +28 -1
  60. package/src/runtime/components/MapoDetail.vue +78 -11
  61. package/src/runtime/components/MapoDetailLangSwitch.vue +26 -27
  62. package/src/runtime/components/MapoList.vue +13 -5
  63. package/src/runtime/components/MapoListTable.vue +128 -41
  64. package/src/runtime/components/MapoMediaEditor.vue +17 -4
  65. package/src/runtime/components/MapoMediaUploader.vue +25 -21
  66. package/src/runtime/stores/media.ts +32 -0
  67. package/src/runtime/types/list.ts +10 -2
  68. package/src/runtime/utils/listTable.ts +54 -0
@@ -0,0 +1,82 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import {
4
+ ALL_ROWS,
5
+ formatPageSize,
6
+ nextSorting,
7
+ orderingParam,
8
+ parsePageSize,
9
+ toPageSize,
10
+ } from "../runtime/utils/listTable";
11
+
12
+ describe("nextSorting", () => {
13
+ it("cycles a column through ascending, descending and unsorted", () => {
14
+ const asc = nextSorting([], "title");
15
+ expect(asc).toEqual([{ id: "title", desc: false }]);
16
+ const desc = nextSorting(asc, "title");
17
+ expect(desc).toEqual([{ id: "title", desc: true }]);
18
+ expect(nextSorting(desc, "title")).toEqual([]);
19
+ });
20
+
21
+ it("replaces the sort on another column", () => {
22
+ expect(
23
+ nextSorting(
24
+ [
25
+ { id: "title", desc: true },
26
+ { id: "status", desc: false },
27
+ ],
28
+ "created_at",
29
+ ),
30
+ ).toEqual([{ id: "created_at", desc: false }]);
31
+ });
32
+
33
+ it("keeps only the clicked key of a multi-column sort", () => {
34
+ // A multi-column sort can come from the URL; a click narrows it to one key.
35
+ expect(
36
+ nextSorting(
37
+ [
38
+ { id: "title", desc: false },
39
+ { id: "status", desc: false },
40
+ ],
41
+ "status",
42
+ ),
43
+ ).toEqual([{ id: "status", desc: true }]);
44
+ });
45
+ });
46
+
47
+ describe("page size helpers", () => {
48
+ it("stores the 'all' option as ALL_ROWS", () => {
49
+ expect(toPageSize("all")).toBe(ALL_ROWS);
50
+ expect(toPageSize(50)).toBe(50);
51
+ });
52
+
53
+ it("reads page_size from the URL", () => {
54
+ expect(parsePageSize("all", 20)).toBe(ALL_ROWS);
55
+ expect(parsePageSize("50", 20)).toBe(50);
56
+ expect(parsePageSize("-3", 20)).toBe(20);
57
+ expect(parsePageSize("abc", 20)).toBe(20);
58
+ expect(parsePageSize(undefined, 20)).toBe(20);
59
+ });
60
+
61
+ it("writes page_size to the URL", () => {
62
+ expect(formatPageSize(ALL_ROWS)).toBe("all");
63
+ expect(formatPageSize(50)).toBe("50");
64
+ });
65
+ });
66
+
67
+ describe("orderingParam", () => {
68
+ it("joins the keys, with `-` for descending", () => {
69
+ expect(
70
+ orderingParam([
71
+ { id: "title", desc: true },
72
+ { id: "published_at", desc: false },
73
+ ]),
74
+ ).toBe("-title,published_at");
75
+ });
76
+
77
+ it("writes a related object's field as a Django lookup", () => {
78
+ expect(orderingParam([{ id: "parent.category.name", desc: true }])).toBe(
79
+ "-parent__category__name",
80
+ );
81
+ });
82
+ });
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { createPinia, setActivePinia } from "pinia";
3
+
4
+ const optionsMock = vi.fn();
5
+
6
+ vi.mock("#app", () => ({
7
+ useRuntimeConfig: () => ({ public: {} }),
8
+ useNuxtApp: () => ({ $mapoFetch: vi.fn() }),
9
+ }));
10
+ vi.mock("@mapomodule/core/runtime/api/crud", () => ({
11
+ useCrud: () => ({ options: optionsMock }),
12
+ }));
13
+ vi.mock("@mapomodule/i18n/runtime/composables/useMapoT", () => ({
14
+ useMapoT: () => (key: string) => key,
15
+ }));
16
+
17
+ const { useMediaStore } = await import("../runtime/stores/media");
18
+
19
+ describe("media store — languages from OPTIONS", () => {
20
+ beforeEach(() => {
21
+ setActivePinia(createPinia());
22
+ optionsMock.mockReset();
23
+ });
24
+
25
+ it("reads the media model's own languages", async () => {
26
+ optionsMock.mockResolvedValue({
27
+ lang_info: { translatable: true, languages: ["it", "en"] },
28
+ });
29
+ const store = useMediaStore();
30
+ await store.deriveLanguages();
31
+ expect(store.languages).toEqual(["it", "en"]);
32
+ });
33
+
34
+ it("offers none when the model is not registered for translation", async () => {
35
+ optionsMock.mockResolvedValue({
36
+ lang_info: { translatable: false, languages: [] },
37
+ });
38
+ const store = useMediaStore();
39
+ await store.deriveLanguages();
40
+ expect(store.languages).toEqual([]);
41
+ });
42
+
43
+ // Manager, picker dialog and the `media` form field each mount an editor;
44
+ // without the shared promise that is one OPTIONS request per editor.
45
+ it("asks once however many editors mount", async () => {
46
+ optionsMock.mockResolvedValue({ lang_info: { languages: ["it"] } });
47
+ const store = useMediaStore();
48
+ await Promise.all([
49
+ store.deriveLanguages(),
50
+ store.deriveLanguages(),
51
+ store.deriveLanguages(),
52
+ ]);
53
+ expect(optionsMock).toHaveBeenCalledOnce();
54
+ });
55
+
56
+ it("retries after a failure instead of caching the empty result", async () => {
57
+ optionsMock.mockRejectedValueOnce(new Error("offline"));
58
+ const store = useMediaStore();
59
+ await store.deriveLanguages();
60
+ expect(store.languages).toEqual([]);
61
+
62
+ optionsMock.mockResolvedValue({ lang_info: { languages: ["it"] } });
63
+ await store.deriveLanguages();
64
+ expect(store.languages).toEqual(["it"]);
65
+ });
66
+ });
@@ -56,4 +56,13 @@
56
56
  #__nuxt > * {
57
57
  height: 100%;
58
58
  }
59
+
60
+ /* Tailwind v4 leaves buttons with the browser's arrow and Nuxt UI adds no
61
+ cursor-pointer, so only links (a UButton with `to`) showed the hand. This
62
+ is the rule Tailwind's upgrade guide suggests. A disabled button keeps Nuxt
63
+ UI's `cursor-not-allowed`: a utility, so it wins over this base rule. */
64
+ button:not(:disabled),
65
+ [role="button"]:not(:disabled) {
66
+ cursor: pointer;
67
+ }
59
68
  }
@@ -1,13 +1,40 @@
1
1
  <script setup lang="ts">
2
+ import { ref, watch } from "vue";
2
3
  import { useI18n } from "vue-i18n";
3
4
  import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
4
5
 
5
6
  const { t } = useI18n();
6
7
  const store = useConfirmStore();
8
+
9
+ // Nuxt UI gives overlays no z-index: they stack in the order their portals sit
10
+ // in <body>, and a portal takes its place there when its overlay mounts.
11
+ // Mounted with the layout, this modal would come before every overlay a page
12
+ // opens later, such as the media editor drawer, and show under it while the
13
+ // drawer takes every click. So it mounts when a confirmation is asked, above
14
+ // whatever asked for it, and unmounts once its close animation has ended.
15
+ const modalMounted = ref(store.active);
16
+
17
+ watch(
18
+ () => store.active,
19
+ (active) => {
20
+ if (active) modalMounted.value = true;
21
+ },
22
+ );
23
+
24
+ function onAfterLeave() {
25
+ // Asked again while the previous dialog was closing: it is open again.
26
+ if (store.active) return;
27
+ modalMounted.value = false;
28
+ }
7
29
  </script>
8
30
 
9
31
  <template>
10
- <UModal v-model:open="store.active" :dismissible="false">
32
+ <UModal
33
+ v-if="modalMounted"
34
+ v-model:open="store.active"
35
+ :dismissible="false"
36
+ @after:leave="onAfterLeave"
37
+ >
11
38
  <template #content>
12
39
  <div class="p-6 space-y-4">
13
40
  <div class="space-y-1">
@@ -65,6 +65,12 @@ const props = withDefaults(
65
65
  sidebarFields?: AnyFieldDescriptor<T>[];
66
66
  /** Translation language codes (e.g. ['it', 'en']). */
67
67
  languages?: string[];
68
+ /**
69
+ * Number of languages above which the language switcher adds a searchable
70
+ * select next to its tabs. Default `8` (from MapoDetailLangSwitch); `0`
71
+ * always shows it.
72
+ */
73
+ langThreshold?: number;
68
74
  /** Human readable model name shown in the page title. */
69
75
  modelName?: string | null;
70
76
  /** Sidebar column span (1–11 in a 12-col grid). */
@@ -123,6 +129,7 @@ const props = withDefaults(
123
129
  schemaFieldOptions: undefined,
124
130
  sidebarFields: () => [],
125
131
  languages: () => [],
132
+ langThreshold: undefined,
126
133
  sidebarCols: 4,
127
134
  sticky: true,
128
135
  usePatch: true,
@@ -195,8 +202,21 @@ const errors = ref<Record<string, string[]>>({});
195
202
  // Start in loading state for existing items so MapoForm is never mounted with
196
203
  // empty data and then immediately unmounted when the spinner appears on mount.
197
204
  const isLoading = ref(String(props.id) !== "new");
198
- const isSaving = ref(false);
199
- const isDeleting = ref(false);
205
+
206
+ /**
207
+ * The action under way, from the click until its work is done, navigation
208
+ * included: one at a time, so a second click cannot save again or go back one
209
+ * more step in the history. Named after the buttons.
210
+ */
211
+ type DetailAction = "save" | "saveContinue" | "delete" | "back";
212
+ const pendingAction = ref<DetailAction | null>(null);
213
+ const isBusy = computed(() => pendingAction.value !== null);
214
+ const isSaving = computed(() => {
215
+ const savingAndLeaving = pendingAction.value === "save";
216
+ const savingAndStaying = pendingAction.value === "saveContinue";
217
+ return savingAndLeaving || savingAndStaying;
218
+ });
219
+ const isDeleting = computed(() => pendingAction.value === "delete");
200
220
  const currentLang = ref(props.languages[0] ?? "");
201
221
  const draftBanner = ref<{
202
222
  savedAt: Date;
@@ -428,6 +448,10 @@ async function fetchModel() {
428
448
  // ─── Save ────────────────────────────────────────────────────────────────────
429
449
 
430
450
  async function save(andBack = false) {
451
+ // The built-in buttons are disabled meanwhile; a custom one bound to `save`
452
+ // may not be.
453
+ if (isBusy.value) return;
454
+
431
455
  const validationResults = formValidators.map((fn) => fn());
432
456
  const allValid = validationResults.every((r) => r.valid);
433
457
  if (!allValid) {
@@ -442,7 +466,8 @@ async function save(andBack = false) {
442
466
  }
443
467
 
444
468
  errors.value = {};
445
- isSaving.value = true;
469
+ pendingAction.value = andBack ? "save" : "saveContinue";
470
+ let leaving = false;
446
471
  try {
447
472
  const multipartOpts = { multipart: props.multipart };
448
473
  let result: T;
@@ -478,7 +503,7 @@ async function save(andBack = false) {
478
503
  params: { id },
479
504
  });
480
505
  }
481
- if (andBack) back();
506
+ if (andBack) leaving = leave();
482
507
  } catch (err: unknown) {
483
508
  const data = getErrorData(err);
484
509
  if (getErrorStatus(err) === 400 && data && typeof data === "object") {
@@ -492,7 +517,8 @@ async function save(andBack = false) {
492
517
  snack.show(detail ?? t("mapo.saveError"), "error");
493
518
  }
494
519
  } finally {
495
- isSaving.value = false;
520
+ // Going back: still busy until the page is gone (see leave()).
521
+ if (!leaving) pendingAction.value = null;
496
522
  }
497
523
  }
498
524
 
@@ -504,6 +530,7 @@ function getPatch(): Partial<T> {
504
530
  // ─── Delete ──────────────────────────────────────────────────────────────────
505
531
 
506
532
  async function deleteItem() {
533
+ if (isBusy.value) return;
507
534
  const ok = await confirm.ask({
508
535
  title: t("mapo.delete"),
509
536
  message: t("mapo.detail.deleteQuestion"),
@@ -511,24 +538,52 @@ async function deleteItem() {
511
538
  dangerous: true,
512
539
  });
513
540
  if (!ok) return;
514
- isDeleting.value = true;
541
+ pendingAction.value = "delete";
542
+ let leaving = false;
515
543
  try {
516
544
  await crud.delete(recordId());
517
545
  backup.value = deepClone(model.value) as T; // clear dirty so guard doesn't fire
518
546
  snack.show(t("mapo.deleteSuccess"), "success");
519
547
  emit("deleted");
520
- back();
548
+ leaving = leave();
521
549
  } catch (err: unknown) {
522
550
  snack.show(getErrorDetail(err) ?? t("mapo.deleteError"), "error");
523
551
  } finally {
524
- isDeleting.value = false;
552
+ if (!leaving) pendingAction.value = null;
525
553
  }
526
554
  }
527
555
 
528
556
  // ─── Navigation guard ────────────────────────────────────────────────────────
529
557
 
530
558
  function back() {
559
+ if (isBusy.value) return;
560
+ pendingAction.value = "back";
561
+ const leaving = leave();
562
+ if (!leaving) pendingAction.value = null;
563
+ }
564
+
565
+ /**
566
+ * Goes back one step and tells whether that is a navigation inside the app.
567
+ *
568
+ * router.back() does not wait for the navigation, and this page stays on screen
569
+ * until the previous route is ready. So the caller keeps its action pending
570
+ * until the page is gone; if the navigation fails (a guard kept the page, such
571
+ * as the unsaved-changes one), the action is released and the buttons work
572
+ * again.
573
+ */
574
+ function leave(): boolean {
575
+ // Opened directly (a new tab, a bookmark): no page of the app to go back to,
576
+ // router.back() leaves the app or does nothing, and nothing would release
577
+ // the buttons.
578
+ const hasPreviousPage = router.options.history.state.back != null;
579
+ if (hasPreviousPage) {
580
+ const stopWatching = router.afterEach((_to, _from, failure) => {
581
+ stopWatching();
582
+ if (failure) pendingAction.value = null;
583
+ });
584
+ }
531
585
  router.back();
586
+ return hasPreviousPage;
532
587
  }
533
588
 
534
589
  async function guardUnsaved(): Promise<boolean> {
@@ -626,14 +681,19 @@ type SlotBindings = {
626
681
  currentLang: string;
627
682
  isNew: boolean;
628
683
  isLoading: boolean;
684
+ /** From the click until the save is done; after `save(true)`, until the page has gone back. */
629
685
  isSaving: boolean;
686
+ /** From the confirmation until the delete is done and the page has gone back. */
630
687
  isDeleting: boolean;
631
688
  isDirty: boolean;
632
689
  draftBanner: DraftBannerState;
633
690
  readonly: boolean;
634
691
  canDelete: boolean;
692
+ /** Ignored while a save, a delete or a navigation back is under way. */
635
693
  save: (andBack?: boolean) => Promise<void>;
694
+ /** Ignored while a save, a delete or a navigation back is under way. */
636
695
  deleteItem: () => Promise<void>;
696
+ /** Ignored while a save, a delete or a navigation back is under way. */
637
697
  back: () => void;
638
698
  };
639
699
 
@@ -747,6 +807,7 @@ defineSlots<{
747
807
  v-model="currentLang"
748
808
  :langs="activeLangs"
749
809
  :errors="errors"
810
+ :lang-threshold="langThreshold"
750
811
  />
751
812
  </slot>
752
813
 
@@ -779,7 +840,8 @@ defineSlots<{
779
840
  <!-- Sidebar column -->
780
841
  <div :class="sidebarColsClass">
781
842
  <div :style="sidebarStyle" class="space-y-4">
782
- <!-- Action buttons (Save / Save&continue / Back — no delete here) -->
843
+ <!-- Action buttons (Save / Save&continue / Back — no delete here).
844
+ While one works, it spins and all of them are disabled. -->
783
845
  <slot name="side-buttons" v-bind="slotBindings">
784
846
  <UCard>
785
847
  <div class="flex flex-col gap-2">
@@ -787,7 +849,8 @@ defineSlots<{
787
849
  <UButton
788
850
  v-if="!effectiveReadonly"
789
851
  block
790
- :loading="isSaving"
852
+ :loading="pendingAction === 'save'"
853
+ :disabled="isBusy"
791
854
  icon="i-lucide-save"
792
855
  @click="save(true)"
793
856
  >
@@ -800,7 +863,8 @@ defineSlots<{
800
863
  v-if="!effectiveReadonly"
801
864
  block
802
865
  variant="soft"
803
- :loading="isSaving"
866
+ :loading="pendingAction === 'saveContinue'"
867
+ :disabled="isBusy"
804
868
  icon="i-lucide-save"
805
869
  @click="save(false)"
806
870
  >
@@ -815,6 +879,8 @@ defineSlots<{
815
879
  block
816
880
  variant="ghost"
817
881
  icon="i-lucide-arrow-left"
882
+ :loading="pendingAction === 'back'"
883
+ :disabled="isBusy"
818
884
  @click="back"
819
885
  >
820
886
  {{ t("mapo.back") }}
@@ -892,6 +958,7 @@ defineSlots<{
892
958
  color="error"
893
959
  variant="soft"
894
960
  :loading="isDeleting"
961
+ :disabled="isBusy"
895
962
  icon="i-lucide-trash-2"
896
963
  @click="deleteItem"
897
964
  >
@@ -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
@@ -57,10 +58,14 @@ const props = withDefaults(
57
58
  */
58
59
  permissionModel?: string;
59
60
  // 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[];
61
+ /** Initial page size: a number, or `"all"`. Default: 20. */
62
+ defaultPageSize?: number | "all";
63
+ /**
64
+ * Options of the per-page selector. `"all"` adds an option that requests
65
+ * the list without pagination params, like `clientSide` does: the backend
66
+ * has to return the whole collection then. Default: [10, 20, 50, 100].
67
+ */
68
+ pageSizeOptions?: (number | "all")[];
64
69
  /**
65
70
  * Custom response parser. Replaces the built-in DRF / flat-array detection.
66
71
  * Return `{ items, total }` from any shape your backend returns.
@@ -169,6 +174,9 @@ const writeUrlState = debounce(() => {
169
174
 
170
175
  watch([activeTab, activeFilters], writeUrlState, { deep: true });
171
176
 
177
+ // A URL write still pending when the list goes away would land on the next page.
178
+ onBeforeUnmount(() => writeUrlState.cancel());
179
+
172
180
  // --- crudEndpoint: base path for mutations (no query string). ---
173
181
  const crudEndpoint = computed(
174
182
  () => (props.endpoint ?? "").split("?")[0] || (props.endpoint ?? ""),