@mapomodule/uikit 2.0.0-beta.19 → 2.0.0-beta.20

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MapoList.component.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoList.component.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/MapoList.component.test.ts"],"names":[],"mappings":""}
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
3
  "configKey": "mapoUikit",
4
- "version": "2.0.0-beta.19",
4
+ "version": "2.0.0-beta.20",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -105,6 +105,15 @@ defineExpose({ refresh });
105
105
  defineSlots();
106
106
  const slots = useSlots();
107
107
  const forwardedSlotNames = computed(() => Object.keys(slots));
108
+ const forwardedTableSlotNames = computed(
109
+ () => forwardedSlotNames.value.filter((name) => name !== "dtable.toolbar")
110
+ );
111
+ const hasSelection = computed(
112
+ () => selection.value === "all" || selection.value.length > 0
113
+ );
114
+ const hasTableToolbar = computed(
115
+ () => props.searchable || !!slots["dtable.toolbar"] || hasSelection.value
116
+ );
108
117
  watch([activeTab, activeFilters], () => {
109
118
  selection.value = [];
110
119
  });
@@ -127,35 +136,20 @@ watch([activeTab, activeFilters], () => {
127
136
  @update:model-value="activeTab = $event"
128
137
  />
129
138
 
130
- <!-- Toolbar: filters + actions -->
131
- <div class="flex flex-wrap items-center gap-2">
132
- <MapoListFilters
133
- :filters="filters"
134
- :model-value="activeFilters"
135
- @update:model-value="activeFilters = $event"
139
+ <!-- Filters (they render nothing without filters) -->
140
+ <MapoListFilters
141
+ :filters="filters"
142
+ :model-value="activeFilters"
143
+ @update:model-value="activeFilters = $event"
144
+ >
145
+ <template
146
+ v-for="name in forwardedSlotNames"
147
+ :key="name"
148
+ #[name]="slotProps"
136
149
  >
137
- <template
138
- v-for="name in forwardedSlotNames"
139
- :key="name"
140
- #[name]="slotProps"
141
- >
142
- <slot :name="name" v-bind="slotProps ?? {}" />
143
- </template>
144
- </MapoListFilters>
145
-
146
- <div class="ml-auto">
147
- <MapoListActions
148
- :actions="actions"
149
- :selection="selection"
150
- :selection-query="selectionQuery"
151
- :endpoint="crudEndpoint"
152
- :lookup="lookup"
153
- :permission-model="permissionModel"
154
- :default-actions="defaultActions"
155
- @action-completed="refresh"
156
- />
157
- </div>
158
- </div>
150
+ <slot :name="name" v-bind="slotProps ?? {}" />
151
+ </template>
152
+ </MapoListFilters>
159
153
 
160
154
  <!-- Table -->
161
155
  <MapoListTable
@@ -184,12 +178,28 @@ watch([activeTab, activeFilters], () => {
184
178
  @update:items="emit('update:items', $event)"
185
179
  >
186
180
  <template
187
- v-for="name in forwardedSlotNames"
181
+ v-for="name in forwardedTableSlotNames"
188
182
  :key="name"
189
183
  #[name]="slotProps"
190
184
  >
191
185
  <slot :name="name" v-bind="slotProps ?? {}" />
192
186
  </template>
187
+ <!-- The bulk actions act on the selected rows: they sit in the table's
188
+ toolbar, after the search and the app's toolbar content. -->
189
+ <template v-if="hasTableToolbar" #[`dtable.toolbar`]>
190
+ <slot name="dtable.toolbar" />
191
+ <MapoListActions
192
+ class="ml-auto"
193
+ :actions="actions"
194
+ :selection="selection"
195
+ :selection-query="selectionQuery"
196
+ :endpoint="crudEndpoint"
197
+ :lookup="lookup"
198
+ :permission-model="permissionModel"
199
+ :default-actions="defaultActions"
200
+ @action-completed="refresh"
201
+ />
202
+ </template>
193
203
  </MapoListTable>
194
204
  </div>
195
205
  </template>
@@ -90,7 +90,10 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
90
90
  }) => unknown;
91
91
  /** Content rendered inside the list head area (title, breadcrumbs, action buttons). */
92
92
  head(): unknown;
93
- /** Extra content rendered alongside the search input in the table toolbar. */
93
+ /**
94
+ * Extra content in the table's toolbar, after the search input. The bulk
95
+ * actions follow it, at the end of the row, while rows are selected.
96
+ */
94
97
  "dtable.toolbar"(): unknown;
95
98
  /** Override for the empty state displayed when no rows are found. */
96
99
  "dtable.empty"(): unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"MapoList.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoList.vue"],"names":[],"mappings":"AAuWA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,YAAY,EAEZ,gBAAgB,EAChB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAIhF,QAAA,MAAM,YAAY,GAAK,CAAC,SAAS,MAAM,EACtC,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAC9D,YAAY,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,EAC3G,gBAAgB,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EAClE;WAyhBO,OAAO,KAAK,EAAE,WAAW,GAAG,mBAAmB,CAAC;mBAvhBzC,MAAM;QACjB;;;;;WAKG;gBACK,CAAC,EAAE;QACX;;;;;WAKG;qBACU,OAAO;QACpB,8FAA8F;iBACrF,UAAU,CAAC,CAAC,CAAC,EAAE;iBACf,MAAM;kBAEL,gBAAgB,EAAE;kBAElB,gBAAgB,CAAC,CAAC,CAAC,EAAE;eAExB,WAAW,EAAE;qBACP,MAAM;wBACH,MAAM;qBAET,OAAO;oBACR,OAAO;wBACH,MAAM;qBAET,kBAAkB,CAAC,CAAC,CAAC,EAAE;oBACxB,MAAM,EAAE;mBACT,aAAa;QACxB,0FAA0F;qBAC7E,MAAM;QACnB;;;;WAIG;0BACe,MAAM;QACx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I,CAAC;YAClD,cAAc,CAAC,EAAE,CACf,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,YAAY,KACjB,OAAO,CAAC;SACd,KAAK,OAAO;QA1Bb,uFAAuF;gBAC/E,OAAO;QACf;;;WAGG;4BACiB,OAAO;QAC3B,qEAAqE;0BACnD,OAAO;QACzB,+EAA+E;4BAC3D,OAAO;QAiB3B;;;WAGG;uBACY,CAAC,KAAK,EAAE;YAAE,KAAK,EAAE,CAAC,CAAA;SAAE,KAAK,OAAO;WAK9C,CAAC,8CAA8C;QAC9C,IAAI,EAAE,CAAC,CAAC;QACR,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;KACb,KAAK,OAAO;;EA6Tb,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAI,CAAC;wBACvD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,CAAC,GAAG,EAAE,CAAC"}
@@ -628,9 +628,14 @@ const sortingOptions = computed(() => ({
628
628
 
629
629
  <template>
630
630
  <div class="mapo-list-table space-y-3">
631
- <!-- Search -->
632
- <div v-if="searchable" class="flex items-center gap-2">
631
+ <!-- Toolbar: the search and the `dtable.toolbar` content (in MapoList,
632
+ the bulk actions), also without the search -->
633
+ <div
634
+ v-if="searchable || $slots['dtable.toolbar']"
635
+ class="flex flex-wrap items-center gap-2"
636
+ >
633
637
  <UInput
638
+ v-if="searchable"
634
639
  :model-value="search"
635
640
  :placeholder="t('mapo.search')"
636
641
  icon="i-lucide-search"
@@ -74,9 +74,9 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
74
74
  */
75
75
  permissionModel?: string;
76
76
  } & {
77
+ "onUpdate:items"?: ((value: T[]) => any) | undefined;
77
78
  "onUpdate:selection"?: ((value: "all" | T[]) => any) | undefined;
78
79
  "onUpdate:selectionQuery"?: ((value: URLSearchParams) => any) | undefined;
79
- "onUpdate:items"?: ((value: T[]) => any) | undefined;
80
80
  }> & (typeof globalThis extends {
81
81
  __VLS_PROPS_FALLBACK: infer P;
82
82
  } ? P : {});
@@ -86,7 +86,10 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
86
86
  attrs: any;
87
87
  slots: {
88
88
  [K: string]: (...args: any[]) => any;
89
- /** Extra content rendered alongside the search input in the toolbar. */
89
+ /**
90
+ * Content of the toolbar row, after the search input; the row shows it
91
+ * without the search too. `MapoList` puts its bulk actions here.
92
+ */
90
93
  "dtable.toolbar"(): any;
91
94
  /** Override for the empty state displayed when no rows are found. */
92
95
  "dtable.empty"(): any;
@@ -96,7 +99,7 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
96
99
  item: T;
97
100
  value: T[K];
98
101
  }) => any; };
99
- emit: ((evt: "update:selection", value: "all" | T[]) => void) & ((evt: "update:selectionQuery", value: URLSearchParams) => void) & ((evt: "update:items", value: T[]) => void);
102
+ emit: ((evt: "update:items", value: T[]) => void) & ((evt: "update:selection", value: "all" | T[]) => void) & ((evt: "update:selectionQuery", value: URLSearchParams) => void);
100
103
  }>) => import("vue").VNode & {
101
104
  __ctx?: Awaited<typeof __VLS_setup>;
102
105
  };
@@ -1 +1 @@
1
- {"version":3,"file":"MapoListTable.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoListTable.vue"],"names":[],"mappings":"AA2gCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAKnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAgBhF,QAAA,MAA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EAA+E;4BAC3D,GAAG;WAOtB,CAAC,8CAA8C;QAC9C,IAAI,EAAE,CAAC,CAAC;QACR,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;KACb,KAAK,GAAG;;EAmmCT,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAI,CAAC;wBACvD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,CAAC,GAAG,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "2.0.0-beta.19",
3
+ "version": "2.0.0-beta.20",
4
4
  "description": "Mapo UI components: Sidebar, Topbar, Login, SnackBar, ConfirmDialog, List, Detail, Media",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -45,8 +45,8 @@
45
45
  "lint": "eslint src"
46
46
  },
47
47
  "dependencies": {
48
- "@mapomodule/form": "2.0.0-beta.16",
49
- "@mapomodule/i18n": "2.0.0-beta.7",
48
+ "@mapomodule/form": "2.0.0-beta.17",
49
+ "@mapomodule/i18n": "2.0.0-beta.8",
50
50
  "@mapomodule/store": "2.0.0-beta.6",
51
51
  "@mapomodule/utils": "2.0.0-beta.7",
52
52
  "@mapomodule/core": "2.0.0-beta.12",
@@ -0,0 +1,166 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { createRenderer, h, nextTick } from "vue";
3
+ import type { App, Component, SetupContext } from "vue";
4
+
5
+ import MapoList from "../runtime/components/MapoList.vue";
6
+
7
+ // Where MapoList puts its bulk actions: in the table's toolbar, next to the
8
+ // search, together with the app's `dtable.toolbar` content. Its children are
9
+ // stubs: the table renders the toolbar slot it gets and reports selections.
10
+
11
+ const route = vi.hoisted(() => ({ query: {} as Record<string, string> }));
12
+ const router = vi.hoisted(() => ({ replace: vi.fn() }));
13
+ vi.mock("#app", () => ({ useRoute: () => route, useRouter: () => router }));
14
+
15
+ // Nodes are plain objects that keep their tag and props.
16
+ interface HeadlessNode {
17
+ type: string;
18
+ parent: HeadlessNode | null;
19
+ children: HeadlessNode[];
20
+ props: Record<string, unknown>;
21
+ }
22
+
23
+ const headlessNode = (type: string): HeadlessNode => ({
24
+ type,
25
+ parent: null,
26
+ children: [],
27
+ props: {},
28
+ });
29
+
30
+ const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
31
+ createElement: (type) => headlessNode(type),
32
+ createText: () => headlessNode("#text"),
33
+ createComment: () => headlessNode("#comment"),
34
+ setText: () => {},
35
+ setElementText: () => {},
36
+ patchProp(node, key, _previous, next) {
37
+ node.props[key] = next;
38
+ },
39
+ insert(child, parent, anchor) {
40
+ child.parent = parent;
41
+ const at = anchor ? parent.children.indexOf(anchor) : -1;
42
+ parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
43
+ },
44
+ remove(child) {
45
+ child.parent?.children.splice(child.parent.children.indexOf(child), 1);
46
+ child.parent = null;
47
+ },
48
+ parentNode: (node) => node.parent,
49
+ nextSibling: (node) =>
50
+ node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
51
+ });
52
+
53
+ // What the table stub was given, and how to make it report a selection.
54
+ const table = vi.hoisted(() => ({
55
+ slotNames: [] as string[],
56
+ select: undefined as ((rows: unknown[]) => void) | undefined,
57
+ }));
58
+
59
+ const stubs: Record<string, Component> = {
60
+ MapoListHead: { render: () => null },
61
+ MapoListTabs: { render: () => null },
62
+ MapoListFilters: { render: () => null },
63
+ MapoListActions: {
64
+ props: { selection: { type: [Array, String], default: () => [] } },
65
+ setup: (props: Record<string, unknown>) => () =>
66
+ h("actions", { selection: props.selection }),
67
+ },
68
+ MapoListTable: {
69
+ emits: ["update:selection", "update:selectionQuery", "update:items"],
70
+ setup(_props: unknown, { slots, emit, expose }: SetupContext) {
71
+ expose({ refresh: () => {} });
72
+ table.select = (rows) => emit("update:selection", rows);
73
+ return () => {
74
+ table.slotNames = Object.keys(slots);
75
+ return h("table", null, [
76
+ slots["dtable.toolbar"]
77
+ ? h("toolbar", null, slots["dtable.toolbar"]())
78
+ : null,
79
+ ]);
80
+ };
81
+ },
82
+ },
83
+ };
84
+
85
+ let app: App<HeadlessNode> | undefined;
86
+ let root: HeadlessNode;
87
+
88
+ function mount(
89
+ props: Record<string, unknown> = {},
90
+ slots: Record<string, () => unknown> = {},
91
+ ) {
92
+ root = headlessNode("root");
93
+ const host: Component = {
94
+ render: () =>
95
+ h(
96
+ MapoList as Component,
97
+ { endpoint: "/api/news/", columns: [], ...props },
98
+ slots,
99
+ ),
100
+ };
101
+ app = createApp(host);
102
+ for (const [name, stub] of Object.entries(stubs)) app.component(name, stub);
103
+ app.mount(root);
104
+ }
105
+
106
+ const all = (node: HeadlessNode): HeadlessNode[] => [
107
+ node,
108
+ ...node.children.flatMap(all),
109
+ ];
110
+ const find = (type: string) => all(root).find((node) => node.type === type);
111
+ /** The toolbar's elements in order, without the anchors of fragments. */
112
+ const toolbarItems = () =>
113
+ find("toolbar")!.children.filter((node) => !node.type.startsWith("#"));
114
+
115
+ beforeEach(() => {
116
+ route.query = {};
117
+ table.slotNames = [];
118
+ table.select = undefined;
119
+ });
120
+
121
+ afterEach(() => {
122
+ app?.unmount();
123
+ app = undefined;
124
+ });
125
+
126
+ describe("MapoList bulk actions", () => {
127
+ it("puts them in the table's toolbar, where the search is", () => {
128
+ mount();
129
+
130
+ const actions = find("actions")!;
131
+ expect(actions.parent).toBe(find("toolbar"));
132
+ expect(actions.props.class).toBe("ml-auto");
133
+ });
134
+
135
+ it("puts the app's dtable.toolbar content before them", () => {
136
+ mount({}, { "dtable.toolbar": () => h("custom") });
137
+
138
+ expect(toolbarItems().map((node) => node.type)).toEqual([
139
+ "custom",
140
+ "actions",
141
+ ]);
142
+ });
143
+
144
+ it("gives a list without search a toolbar only while rows are selected", async () => {
145
+ mount({ searchable: false });
146
+ expect(table.slotNames).not.toContain("dtable.toolbar");
147
+ expect(find("actions")).toBeUndefined();
148
+
149
+ table.select!([{ id: 1 }]);
150
+ await nextTick();
151
+
152
+ expect(find("actions")!.props.selection).toEqual([{ id: 1 }]);
153
+
154
+ table.select!([]);
155
+ await nextTick();
156
+ expect(find("toolbar")).toBeUndefined();
157
+ });
158
+
159
+ it("forwards the other slots to the table unchanged", () => {
160
+ mount({}, { "cell.title": () => h("cell"), "dtable.empty": () => null });
161
+
162
+ expect(table.slotNames).toEqual(
163
+ expect.arrayContaining(["cell.title", "dtable.empty", "dtable.toolbar"]),
164
+ );
165
+ });
166
+ });
@@ -58,10 +58,14 @@ const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
58
58
  node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
59
59
  });
60
60
 
61
+ // The names of the passthrough stubs mounted since the last test began.
62
+ const mountedStubs: string[] = [];
63
+
61
64
  const passthrough = (name: string): Component => ({
62
65
  name,
63
66
  inheritAttrs: false,
64
67
  setup(_props: unknown, { slots }: SetupContext) {
68
+ mountedStubs.push(name);
65
69
  return () => h("div", null, slots.default?.());
66
70
  },
67
71
  });
@@ -173,10 +177,13 @@ const stubs: Record<string, Component> = {
173
177
  let app: App<HeadlessNode> | undefined;
174
178
 
175
179
  /** Mounts the table; the returned props stay reactive, so a test can change them. */
176
- function mountTable(initial: Record<string, unknown>) {
180
+ function mountTable(
181
+ initial: Record<string, unknown>,
182
+ slots: Record<string, () => unknown> = {},
183
+ ) {
177
184
  const props = reactive({ ...initial });
178
185
  const root: Component = {
179
- render: () => h(MapoListTable as Component, props),
186
+ render: () => h(MapoListTable as Component, props, slots),
180
187
  };
181
188
  app = createApp(root);
182
189
  for (const [name, stub] of Object.entries(stubs)) app.component(name, stub);
@@ -222,6 +229,7 @@ const listProps = {
222
229
  beforeEach(() => {
223
230
  vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
224
231
  route.query = {};
232
+ mountedStubs.length = 0;
225
233
  router.replace.mockReset();
226
234
  crud.list.mockReset();
227
235
  crud.list.mockResolvedValue({ results: rows(20), count: 95 });
@@ -502,3 +510,36 @@ describe("MapoListTable empty state and row actions", () => {
502
510
  expect(labels).toEqual(["mapo.edit", "mapo.delete"]);
503
511
  });
504
512
  });
513
+
514
+ describe("MapoListTable toolbar", () => {
515
+ it("shows the search and, after it, the dtable.toolbar content", async () => {
516
+ const toolbar = vi.fn(() => []);
517
+ mountTable(
518
+ { ...listProps, searchable: true },
519
+ { "dtable.toolbar": toolbar },
520
+ );
521
+ await settle();
522
+
523
+ expect(mountedStubs).toContain("UInput");
524
+ expect(toolbar).toHaveBeenCalled();
525
+ });
526
+
527
+ it("shows the dtable.toolbar content without the search", async () => {
528
+ const toolbar = vi.fn(() => []);
529
+ mountTable(
530
+ { ...listProps, searchable: false },
531
+ { "dtable.toolbar": toolbar },
532
+ );
533
+ await settle();
534
+
535
+ expect(mountedStubs).not.toContain("UInput");
536
+ expect(toolbar).toHaveBeenCalled();
537
+ });
538
+
539
+ it("has no toolbar without the search and without content", async () => {
540
+ mountTable({ ...listProps, searchable: false });
541
+ await settle();
542
+
543
+ expect(mountedStubs).not.toContain("UInput");
544
+ });
545
+ });
@@ -217,7 +217,10 @@ defineSlots<
217
217
  {
218
218
  /** Content rendered inside the list head area (title, breadcrumbs, action buttons). */
219
219
  head(): unknown;
220
- /** Extra content rendered alongside the search input in the table toolbar. */
220
+ /**
221
+ * Extra content in the table's toolbar, after the search input. The bulk
222
+ * actions follow it, at the end of the row, while rows are selected.
223
+ */
221
224
  "dtable.toolbar"(): unknown;
222
225
  /** Override for the empty state displayed when no rows are found. */
223
226
  "dtable.empty"(): unknown;
@@ -262,6 +265,18 @@ defineSlots<
262
265
  const slots = useSlots();
263
266
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
264
267
  const forwardedSlotNames = computed(() => Object.keys(slots) as any[]);
268
+ // `dtable.toolbar` reaches the table together with the bulk actions, below.
269
+ const forwardedTableSlotNames = computed(() =>
270
+ forwardedSlotNames.value.filter((name) => name !== "dtable.toolbar"),
271
+ );
272
+ const hasSelection = computed(
273
+ () => selection.value === "all" || selection.value.length > 0,
274
+ );
275
+ // The table's toolbar row: with the search, with the app's toolbar content,
276
+ // or for the bulk actions while rows are selected.
277
+ const hasTableToolbar = computed(
278
+ () => props.searchable || !!slots["dtable.toolbar"] || hasSelection.value,
279
+ );
265
280
 
266
281
  // Reset selection when the active tab or filters change
267
282
  watch([activeTab, activeFilters], () => {
@@ -286,35 +301,20 @@ watch([activeTab, activeFilters], () => {
286
301
  @update:model-value="activeTab = $event"
287
302
  />
288
303
 
289
- <!-- Toolbar: filters + actions -->
290
- <div class="flex flex-wrap items-center gap-2">
291
- <MapoListFilters
292
- :filters="filters"
293
- :model-value="activeFilters"
294
- @update:model-value="activeFilters = $event"
304
+ <!-- Filters (they render nothing without filters) -->
305
+ <MapoListFilters
306
+ :filters="filters"
307
+ :model-value="activeFilters"
308
+ @update:model-value="activeFilters = $event"
309
+ >
310
+ <template
311
+ v-for="name in forwardedSlotNames"
312
+ :key="name"
313
+ #[name]="slotProps"
295
314
  >
296
- <template
297
- v-for="name in forwardedSlotNames"
298
- :key="name"
299
- #[name]="slotProps"
300
- >
301
- <slot :name="name" v-bind="slotProps ?? {}" />
302
- </template>
303
- </MapoListFilters>
304
-
305
- <div class="ml-auto">
306
- <MapoListActions
307
- :actions="actions"
308
- :selection="selection"
309
- :selection-query="selectionQuery"
310
- :endpoint="crudEndpoint"
311
- :lookup="lookup"
312
- :permission-model="permissionModel"
313
- :default-actions="defaultActions"
314
- @action-completed="refresh"
315
- />
316
- </div>
317
- </div>
315
+ <slot :name="name" v-bind="slotProps ?? {}" />
316
+ </template>
317
+ </MapoListFilters>
318
318
 
319
319
  <!-- Table -->
320
320
  <MapoListTable
@@ -343,12 +343,28 @@ watch([activeTab, activeFilters], () => {
343
343
  @update:items="emit('update:items', $event)"
344
344
  >
345
345
  <template
346
- v-for="name in forwardedSlotNames"
346
+ v-for="name in forwardedTableSlotNames"
347
347
  :key="name"
348
348
  #[name]="slotProps"
349
349
  >
350
350
  <slot :name="name" v-bind="slotProps ?? {}" />
351
351
  </template>
352
+ <!-- The bulk actions act on the selected rows: they sit in the table's
353
+ toolbar, after the search and the app's toolbar content. -->
354
+ <template v-if="hasTableToolbar" #[`dtable.toolbar`]>
355
+ <slot name="dtable.toolbar" />
356
+ <MapoListActions
357
+ class="ml-auto"
358
+ :actions="actions"
359
+ :selection="selection"
360
+ :selection-query="selectionQuery"
361
+ :endpoint="crudEndpoint"
362
+ :lookup="lookup"
363
+ :permission-model="permissionModel"
364
+ :default-actions="defaultActions"
365
+ @action-completed="refresh"
366
+ />
367
+ </template>
352
368
  </MapoListTable>
353
369
  </div>
354
370
  </template>
@@ -132,7 +132,10 @@ defineExpose({ refresh });
132
132
 
133
133
  defineSlots<
134
134
  {
135
- /** Extra content rendered alongside the search input in the toolbar. */
135
+ /**
136
+ * Content of the toolbar row, after the search input; the row shows it
137
+ * without the search too. `MapoList` puts its bulk actions here.
138
+ */
136
139
  "dtable.toolbar"(): any;
137
140
  /** Override for the empty state displayed when no rows are found. */
138
141
  "dtable.empty"(): any;
@@ -905,9 +908,14 @@ const sortingOptions = computed(() => ({
905
908
 
906
909
  <template>
907
910
  <div class="mapo-list-table space-y-3">
908
- <!-- Search -->
909
- <div v-if="searchable" class="flex items-center gap-2">
911
+ <!-- Toolbar: the search and the `dtable.toolbar` content (in MapoList,
912
+ the bulk actions), also without the search -->
913
+ <div
914
+ v-if="searchable || $slots['dtable.toolbar']"
915
+ class="flex flex-wrap items-center gap-2"
916
+ >
910
917
  <UInput
918
+ v-if="searchable"
911
919
  :model-value="search"
912
920
  :placeholder="t('mapo.search')"
913
921
  icon="i-lucide-search"