@bjj/nuxt-layer-shadcn-ui 0.15.4 → 0.15.6
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.
- package/app/components/ui/AsyncDataTable/index.stories.ts +117 -6
- package/app/components/ui/AsyncDataTable/index.vue +54 -6
- package/app/components/ui/AsyncDataTable/types.ts +7 -1
- package/app/components/ui/DataTable/index.vue +14 -1
- package/app/components/ui/InfiniteDataTable/index.stories.ts +86 -5
- package/app/components/ui/InfiniteDataTable/index.vue +44 -6
- package/app/components/ui/InfiniteDataTable/types.ts +7 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3'
|
|
2
2
|
import type { AsyncDataTableBatchAction, AsyncDataTableFetchParams, AsyncDataTableFetchResult } from './types'
|
|
3
3
|
import type { DataTableColumn } from '../DataTable/types'
|
|
4
|
+
import { useArgsModel } from '#storybook/argsModel'
|
|
4
5
|
import AsyncDataTable from './index.vue'
|
|
5
6
|
|
|
6
7
|
interface User {
|
|
@@ -33,12 +34,18 @@ const columns: DataTableColumn[] = [
|
|
|
33
34
|
{ field: 'createdAt', title: 'Created', width: '140px', type: 'date' },
|
|
34
35
|
]
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
const sortableFields = columns.filter(column => column.sortable).map(column => column.field)
|
|
38
|
+
|
|
39
|
+
/** Simulated async fetch with filtering and sorting support */
|
|
37
40
|
function mockFetch (params: AsyncDataTableFetchParams): Promise<AsyncDataTableFetchResult<User>> {
|
|
38
41
|
return new Promise(resolve => {
|
|
39
42
|
setTimeout(() => {
|
|
40
43
|
const data = [ ...allUsers ]
|
|
41
44
|
|
|
45
|
+
if (params.role) {
|
|
46
|
+
data.splice(0, data.length, ...data.filter(u => u.role === params.role))
|
|
47
|
+
}
|
|
48
|
+
|
|
42
49
|
if (params.sortBy) {
|
|
43
50
|
const order = params.sortOrder ?? 1
|
|
44
51
|
data.sort((a, b) => {
|
|
@@ -103,11 +110,14 @@ const meta = {
|
|
|
103
110
|
batchActions: [],
|
|
104
111
|
selection: [],
|
|
105
112
|
},
|
|
106
|
-
render: args =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
render: args => {
|
|
114
|
+
const onUpdateFilters = useArgsModel('filters')
|
|
115
|
+
return {
|
|
116
|
+
components: { AsyncDataTable },
|
|
117
|
+
setup: () => ({ args, onUpdateFilters }),
|
|
118
|
+
template: '<AsyncDataTable v-bind="args" @update:filters="onUpdateFilters" />',
|
|
119
|
+
}
|
|
120
|
+
},
|
|
111
121
|
} satisfies Meta<typeof AsyncDataTable>
|
|
112
122
|
|
|
113
123
|
export default meta
|
|
@@ -159,6 +169,107 @@ export const WithBatchActions: Story = {
|
|
|
159
169
|
}),
|
|
160
170
|
}
|
|
161
171
|
|
|
172
|
+
/** `v-model:filters` holds the whole query state: `page` / `size` / `sortBy` / `sortOrder` live in the same bag as the caller's own filters, so an external panel drives sorting while the table writes its paging and header sorting back. */
|
|
173
|
+
export const FiltersModel: Story = {
|
|
174
|
+
parameters: {
|
|
175
|
+
...noControls,
|
|
176
|
+
docs: {
|
|
177
|
+
source: {
|
|
178
|
+
code: `
|
|
179
|
+
<template>
|
|
180
|
+
<select v-model="filters.role">
|
|
181
|
+
<option value="">All</option>
|
|
182
|
+
<option value="Admin">Admin</option>
|
|
183
|
+
<option value="Editor">Editor</option>
|
|
184
|
+
<option value="User">User</option>
|
|
185
|
+
</select>
|
|
186
|
+
<select v-model="filters.sortBy">
|
|
187
|
+
<option :value="null">none</option>
|
|
188
|
+
<option v-for="f in sortableFields" :key="f" :value="f">{{ f }}</option>
|
|
189
|
+
</select>
|
|
190
|
+
<select v-model="filters.sortOrder">
|
|
191
|
+
<option :value="null">none</option>
|
|
192
|
+
<option :value="1">asc</option>
|
|
193
|
+
<option :value="-1">desc</option>
|
|
194
|
+
</select>
|
|
195
|
+
<input v-model="filters.page" type="number" min="1">
|
|
196
|
+
<AsyncDataTable
|
|
197
|
+
:columns="columns"
|
|
198
|
+
:fetchMethod="mockFetch"
|
|
199
|
+
v-model:filters="filters"
|
|
200
|
+
/>
|
|
201
|
+
</template>
|
|
202
|
+
|
|
203
|
+
<script setup>
|
|
204
|
+
const filters = ref({ role: '', sortBy: null, sortOrder: null })
|
|
205
|
+
</script>
|
|
206
|
+
`.trim(),
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
render: () => ({
|
|
211
|
+
components: { AsyncDataTable },
|
|
212
|
+
setup () {
|
|
213
|
+
const filters = ref<Record<string, any>>({ role: '', sortBy: null, sortOrder: null })
|
|
214
|
+
return { columns, mockFetch, sortableFields, filters }
|
|
215
|
+
},
|
|
216
|
+
template: `
|
|
217
|
+
<div class="space-y-3">
|
|
218
|
+
<div class="gap-3 text-sm flex flex-wrap items-center">
|
|
219
|
+
<label class="gap-2 flex items-center">
|
|
220
|
+
Role:
|
|
221
|
+
<select
|
|
222
|
+
v-model="filters.role"
|
|
223
|
+
class="px-2 py-1 border rounded"
|
|
224
|
+
>
|
|
225
|
+
<option value="">All</option>
|
|
226
|
+
<option value="Admin">Admin</option>
|
|
227
|
+
<option value="Editor">Editor</option>
|
|
228
|
+
<option value="User">User</option>
|
|
229
|
+
</select>
|
|
230
|
+
</label>
|
|
231
|
+
<label class="gap-2 flex items-center">
|
|
232
|
+
Sort by:
|
|
233
|
+
<select
|
|
234
|
+
v-model="filters.sortBy"
|
|
235
|
+
class="px-2 py-1 border rounded"
|
|
236
|
+
>
|
|
237
|
+
<option :value="null">none</option>
|
|
238
|
+
<option v-for="f in sortableFields" :key="f" :value="f">{{ f }}</option>
|
|
239
|
+
</select>
|
|
240
|
+
</label>
|
|
241
|
+
<label class="gap-2 flex items-center">
|
|
242
|
+
Order:
|
|
243
|
+
<select
|
|
244
|
+
v-model="filters.sortOrder"
|
|
245
|
+
class="px-2 py-1 border rounded"
|
|
246
|
+
>
|
|
247
|
+
<option :value="null">none</option>
|
|
248
|
+
<option :value="1">asc</option>
|
|
249
|
+
<option :value="-1">desc</option>
|
|
250
|
+
</select>
|
|
251
|
+
</label>
|
|
252
|
+
<label class="gap-2 flex items-center">
|
|
253
|
+
Page:
|
|
254
|
+
<input
|
|
255
|
+
v-model="filters.page"
|
|
256
|
+
type="number"
|
|
257
|
+
min="1"
|
|
258
|
+
class="px-2 py-1 w-16 border rounded"
|
|
259
|
+
>
|
|
260
|
+
</label>
|
|
261
|
+
</div>
|
|
262
|
+
<AsyncDataTable
|
|
263
|
+
:columns="columns"
|
|
264
|
+
:fetchMethod="mockFetch"
|
|
265
|
+
v-model:filters="filters"
|
|
266
|
+
/>
|
|
267
|
+
<pre class="text-xs text-muted-foreground">{{ filters }}</pre>
|
|
268
|
+
</div>
|
|
269
|
+
`,
|
|
270
|
+
}),
|
|
271
|
+
}
|
|
272
|
+
|
|
162
273
|
/** Custom toolbar slot with action button */
|
|
163
274
|
export const WithCustomToolbar: Story = {
|
|
164
275
|
parameters: {
|
|
@@ -62,8 +62,8 @@ const pagination = ref<AsyncDataTablePagination>({
|
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
const sortState = ref<{ sortBy: string | null, sortOrder: number | null }>({
|
|
65
|
-
sortBy: props.filters?.sortBy
|
|
66
|
-
sortOrder: props.filters?.sortOrder
|
|
65
|
+
sortBy: normalizeSortBy(props.filters?.sortBy),
|
|
66
|
+
sortOrder: normalizeSortOrder(props.filters?.sortOrder),
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
// -- Computed --
|
|
@@ -109,13 +109,38 @@ function getFilters (overrides?: Record<string, any>): Record<string, any> {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
//
|
|
112
|
+
// Isolate the caller-owned part of `filters`; the component-owned keys are
|
|
113
|
+
// compared by value instead (see the filters watcher).
|
|
113
114
|
function getExternalFilters (filters: Record<string, any> | undefined) {
|
|
114
115
|
if (!filters) return {}
|
|
115
116
|
const { page, size, sortBy, sortOrder, ...rest } = filters
|
|
116
117
|
return rest
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
function normalizeSortBy (value: unknown): string | null {
|
|
121
|
+
return value ? String(value) : null
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function normalizeSortOrder (value: unknown): number | null {
|
|
125
|
+
return value ? Number(value) : null
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Incoming shape of the component-owned keys. A query string hands numbers back
|
|
129
|
+
// as strings and drops null keys, so values are coerced before they're compared:
|
|
130
|
+
// that's what keeps our own emits inert when they return through v-model.
|
|
131
|
+
// An absent key means "unspecified — keep what we have"; `sortBy: null` clears
|
|
132
|
+
// the sort, while a missing `page` / `size` has no such meaning.
|
|
133
|
+
function normalizeFilters (filters: Record<string, any> | undefined) {
|
|
134
|
+
const bag = filters ?? {}
|
|
135
|
+
return {
|
|
136
|
+
page: bag.page == null ? pagination.value.page : Number(bag.page) || 1,
|
|
137
|
+
size: bag.size == null ? pagination.value.size : Number(bag.size) || pagination.value.size,
|
|
138
|
+
sortBy: bag.sortBy === undefined ? sortState.value.sortBy : normalizeSortBy(bag.sortBy),
|
|
139
|
+
sortOrder: bag.sortOrder === undefined ? sortState.value.sortOrder : normalizeSortOrder(bag.sortOrder),
|
|
140
|
+
external: JSON.stringify(getExternalFilters(bag)),
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
119
144
|
function buildFetchParams (): AsyncDataTableFetchParams {
|
|
120
145
|
const filters = getFilters()
|
|
121
146
|
const { page, size, ...rest } = filters
|
|
@@ -206,11 +231,34 @@ function scheduleAfterSort () {
|
|
|
206
231
|
})
|
|
207
232
|
}
|
|
208
233
|
|
|
209
|
-
// -- External filters
|
|
234
|
+
// -- External filters --
|
|
235
|
+
// `filters` carries the whole query state, so incoming page / size / sort are
|
|
236
|
+
// adopted as well — that's what lets a toolbar panel drive sorting or paging.
|
|
237
|
+
|
|
238
|
+
let lastExternalFilters = JSON.stringify(getExternalFilters(props.filters))
|
|
239
|
+
|
|
240
|
+
watch(() => normalizeFilters(props.filters), incoming => {
|
|
241
|
+
const externalChanged = incoming.external !== lastExternalFilters
|
|
242
|
+
lastExternalFilters = incoming.external
|
|
243
|
+
|
|
244
|
+
const pageChanged = incoming.page !== pagination.value.page
|
|
245
|
+
const sizeChanged = incoming.size !== pagination.value.size
|
|
246
|
+
const sortChanged = incoming.sortBy !== sortState.value.sortBy
|
|
247
|
+
|| incoming.sortOrder !== sortState.value.sortOrder
|
|
248
|
+
if (!externalChanged && !pageChanged && !sizeChanged && !sortChanged) return
|
|
210
249
|
|
|
211
|
-
|
|
250
|
+
// A different row set restarts at page 1, unless the same change also asked
|
|
251
|
+
// for a specific page — restoring a bookmarked query, say.
|
|
252
|
+
const rowSetChanged = externalChanged || sizeChanged || sortChanged
|
|
253
|
+
if (sortChanged) sortState.value = { sortBy: incoming.sortBy, sortOrder: incoming.sortOrder }
|
|
254
|
+
if (sizeChanged) pagination.value.size = incoming.size
|
|
255
|
+
if (pageChanged) pagination.value.page = incoming.page
|
|
256
|
+
else if (rowSetChanged) pagination.value.page = 1
|
|
257
|
+
if (rowSetChanged) pagination.value.total = 0
|
|
258
|
+
|
|
259
|
+
emit('update:filters', getFilters())
|
|
212
260
|
if (!started.value) return
|
|
213
|
-
|
|
261
|
+
fetchData(undefined, true)
|
|
214
262
|
})
|
|
215
263
|
|
|
216
264
|
// -- Expose --
|
|
@@ -24,7 +24,13 @@ export interface AsyncDataTableProps<T = Record<string, any>> {
|
|
|
24
24
|
autoFetch?: boolean
|
|
25
25
|
/** Column definitions */
|
|
26
26
|
columns?: DataTableColumn[]
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Whole query state (v-model:filters): the caller's own filter fields plus the
|
|
29
|
+
* component-owned `page` / `size` / `sortBy` / `sortOrder`. Incoming changes to
|
|
30
|
+
* the owned keys are adopted too, so an external panel can drive sorting and
|
|
31
|
+
* paging. An absent owned key keeps the current value; `sortBy: null` clears
|
|
32
|
+
* the sort. Changing anything else restarts at page 1.
|
|
33
|
+
*/
|
|
28
34
|
filters?: Record<string, any>
|
|
29
35
|
/** Whether to show top toolbar (undefined = auto when page size >= `topToolbarThreshold`) */
|
|
30
36
|
showTopToolbar?: boolean
|
|
@@ -550,6 +550,16 @@ defineExpose({
|
|
|
550
550
|
z-index: 20;
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
+
/* Separated border model: row-level borders are ignored here, so the row
|
|
554
|
+
divider lives on the cell, where it paints above the cell's opaque
|
|
555
|
+
background — collapsed borders land beneath it in WebKit once the row group
|
|
556
|
+
is clipped. The header's tinted band is its own boundary, so it carries no
|
|
557
|
+
divider. */
|
|
558
|
+
:deep([data-slot="table"]) {
|
|
559
|
+
border-collapse: separate;
|
|
560
|
+
border-spacing: 0;
|
|
561
|
+
}
|
|
562
|
+
|
|
553
563
|
/* clip-path is reliable on table-row-group, unlike overflow:hidden */
|
|
554
564
|
:deep(tbody) {
|
|
555
565
|
clip-path: inset(0 round 8px);
|
|
@@ -567,12 +577,15 @@ defineExpose({
|
|
|
567
577
|
/* Opaque card base under a translucent state overlay: frozen (sticky) cells
|
|
568
578
|
must fully occlude columns scrolling beneath them. */
|
|
569
579
|
:deep(tbody td) {
|
|
580
|
+
border-bottom: 1px solid var(--color-border);
|
|
570
581
|
background:
|
|
571
582
|
linear-gradient(var(--cell-overlay), var(--cell-overlay))
|
|
572
583
|
var(--color-card);
|
|
573
584
|
}
|
|
574
585
|
|
|
575
|
-
|
|
586
|
+
/* The row that ends the body carries no divider — the filler row when present */
|
|
587
|
+
:deep(tbody tr:last-child td),
|
|
588
|
+
:deep(tbody tr:has(+ tr[aria-hidden="true"]) td) {
|
|
576
589
|
border-bottom: 0;
|
|
577
590
|
}
|
|
578
591
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3'
|
|
2
2
|
import type { DataTableColumn } from '../DataTable/types'
|
|
3
3
|
import type { InfiniteDataTableFetchParams, InfiniteDataTableFetchResult } from './types'
|
|
4
|
+
import { useArgsModel } from '#storybook/argsModel'
|
|
4
5
|
import InfiniteDataTable from './index.vue'
|
|
5
6
|
|
|
6
7
|
interface User {
|
|
@@ -32,6 +33,8 @@ const columns: DataTableColumn[] = [
|
|
|
32
33
|
{ field: 'createdAt', title: 'Created', width: '140px', type: 'date' },
|
|
33
34
|
]
|
|
34
35
|
|
|
36
|
+
const sortableFields = columns.filter(column => column.sortable).map(column => column.field)
|
|
37
|
+
|
|
35
38
|
/** Mock fetch using offset as the opaque cursor */
|
|
36
39
|
function mockFetch (params: InfiniteDataTableFetchParams): Promise<InfiniteDataTableFetchResult<User>> {
|
|
37
40
|
return new Promise(resolve => {
|
|
@@ -86,11 +89,14 @@ const meta = {
|
|
|
86
89
|
height: '360px',
|
|
87
90
|
clickable: false,
|
|
88
91
|
},
|
|
89
|
-
render: args =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
render: args => {
|
|
93
|
+
const onUpdateFilters = useArgsModel('filters')
|
|
94
|
+
return {
|
|
95
|
+
components: { InfiniteDataTable: InfiniteDataTable as any },
|
|
96
|
+
setup: () => ({ args, onUpdateFilters }),
|
|
97
|
+
template: '<InfiniteDataTable v-bind="args" @update:filters="onUpdateFilters" />',
|
|
98
|
+
}
|
|
99
|
+
},
|
|
94
100
|
} satisfies Meta<typeof InfiniteDataTable>
|
|
95
101
|
|
|
96
102
|
export default meta
|
|
@@ -158,6 +164,81 @@ export const WithFilters: Story = {
|
|
|
158
164
|
}),
|
|
159
165
|
}
|
|
160
166
|
|
|
167
|
+
/** `v-model:filters` holds the whole query state: `sortBy` / `sortOrder` live in the same bag as the caller's own filters, so an external panel drives sorting while the table writes its header sorting back. */
|
|
168
|
+
export const FiltersModel: Story = {
|
|
169
|
+
parameters: {
|
|
170
|
+
...noControls,
|
|
171
|
+
docs: {
|
|
172
|
+
source: {
|
|
173
|
+
code: `
|
|
174
|
+
<template>
|
|
175
|
+
<select v-model="filters.sortBy">
|
|
176
|
+
<option :value="null">none</option>
|
|
177
|
+
<option v-for="f in sortableFields" :key="f" :value="f">{{ f }}</option>
|
|
178
|
+
</select>
|
|
179
|
+
<select v-model="filters.sortOrder">
|
|
180
|
+
<option :value="null">none</option>
|
|
181
|
+
<option :value="1">asc</option>
|
|
182
|
+
<option :value="-1">desc</option>
|
|
183
|
+
</select>
|
|
184
|
+
<InfiniteDataTable
|
|
185
|
+
:columns="columns"
|
|
186
|
+
:fetchMethod="mockFetch"
|
|
187
|
+
v-model:filters="filters"
|
|
188
|
+
height="360px"
|
|
189
|
+
/>
|
|
190
|
+
</template>
|
|
191
|
+
|
|
192
|
+
<script setup>
|
|
193
|
+
const filters = ref({ sortBy: null, sortOrder: null })
|
|
194
|
+
</script>
|
|
195
|
+
`.trim(),
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
render: () => ({
|
|
200
|
+
components: { InfiniteDataTable: InfiniteDataTable as any },
|
|
201
|
+
setup () {
|
|
202
|
+
const filters = ref<Record<string, any>>({ sortBy: null, sortOrder: null })
|
|
203
|
+
return { columns, mockFetch, sortableFields, filters }
|
|
204
|
+
},
|
|
205
|
+
template: `
|
|
206
|
+
<div class="space-y-3">
|
|
207
|
+
<div class="gap-3 text-sm flex flex-wrap items-center">
|
|
208
|
+
<label class="gap-2 flex items-center">
|
|
209
|
+
Sort by:
|
|
210
|
+
<select
|
|
211
|
+
v-model="filters.sortBy"
|
|
212
|
+
class="px-2 py-1 border rounded"
|
|
213
|
+
>
|
|
214
|
+
<option :value="null">none</option>
|
|
215
|
+
<option v-for="f in sortableFields" :key="f" :value="f">{{ f }}</option>
|
|
216
|
+
</select>
|
|
217
|
+
</label>
|
|
218
|
+
<label class="gap-2 flex items-center">
|
|
219
|
+
Order:
|
|
220
|
+
<select
|
|
221
|
+
v-model="filters.sortOrder"
|
|
222
|
+
class="px-2 py-1 border rounded"
|
|
223
|
+
>
|
|
224
|
+
<option :value="null">none</option>
|
|
225
|
+
<option :value="1">asc</option>
|
|
226
|
+
<option :value="-1">desc</option>
|
|
227
|
+
</select>
|
|
228
|
+
</label>
|
|
229
|
+
</div>
|
|
230
|
+
<InfiniteDataTable
|
|
231
|
+
:columns="columns"
|
|
232
|
+
:fetchMethod="mockFetch"
|
|
233
|
+
v-model:filters="filters"
|
|
234
|
+
height="360px"
|
|
235
|
+
/>
|
|
236
|
+
<pre class="text-xs text-muted-foreground">{{ filters }}</pre>
|
|
237
|
+
</div>
|
|
238
|
+
`,
|
|
239
|
+
}),
|
|
240
|
+
}
|
|
241
|
+
|
|
161
242
|
/** No fixed height — the page scrolls and triggers loading at the bottom */
|
|
162
243
|
export const PageScroll: Story = {
|
|
163
244
|
parameters: noControls,
|
|
@@ -38,8 +38,8 @@ const requestVersion = ref(0)
|
|
|
38
38
|
const started = ref(false)
|
|
39
39
|
|
|
40
40
|
const sortState = ref<{ sortBy: string | null, sortOrder: number | null }>({
|
|
41
|
-
sortBy: props.filters?.sortBy
|
|
42
|
-
sortOrder: props.filters?.sortOrder
|
|
41
|
+
sortBy: normalizeSortBy(props.filters?.sortBy),
|
|
42
|
+
sortOrder: normalizeSortOrder(props.filters?.sortOrder),
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
const isInitialLoad = computed(() => loading.value && internalData.value.length === 0)
|
|
@@ -89,13 +89,36 @@ function getFilters (): Record<string, any> {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
//
|
|
92
|
+
// Isolate the caller-owned part of `filters`; the component-owned keys are
|
|
93
|
+
// compared by value instead (see the filters watcher).
|
|
93
94
|
function getExternalFilters (filters: Record<string, any> | undefined) {
|
|
94
95
|
if (!filters) return {}
|
|
95
96
|
const { sortBy, sortOrder, ...rest } = filters
|
|
96
97
|
return rest
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
function normalizeSortBy (value: unknown): string | null {
|
|
101
|
+
return value ? String(value) : null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function normalizeSortOrder (value: unknown): number | null {
|
|
105
|
+
return value ? Number(value) : null
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Incoming shape of the component-owned keys. A query string hands numbers back
|
|
109
|
+
// as strings and drops null keys, so values are coerced before they're compared:
|
|
110
|
+
// that's what keeps our own emits inert when they return through v-model.
|
|
111
|
+
// An absent key means "unspecified — keep what we have"; `sortBy: null` clears
|
|
112
|
+
// the sort.
|
|
113
|
+
function normalizeFilters (filters: Record<string, any> | undefined) {
|
|
114
|
+
const bag = filters ?? {}
|
|
115
|
+
return {
|
|
116
|
+
sortBy: bag.sortBy === undefined ? sortState.value.sortBy : normalizeSortBy(bag.sortBy),
|
|
117
|
+
sortOrder: bag.sortOrder === undefined ? sortState.value.sortOrder : normalizeSortOrder(bag.sortOrder),
|
|
118
|
+
external: JSON.stringify(getExternalFilters(bag)),
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
99
122
|
function buildFetchParams (): InfiniteDataTableFetchParams {
|
|
100
123
|
return {
|
|
101
124
|
...getFilters(),
|
|
@@ -184,10 +207,25 @@ function scheduleAfterSort () {
|
|
|
184
207
|
})
|
|
185
208
|
}
|
|
186
209
|
|
|
187
|
-
// -- External filters
|
|
210
|
+
// -- External filters --
|
|
211
|
+
// `filters` carries the whole query state, so an incoming sort is adopted as
|
|
212
|
+
// well — that's what lets a toolbar panel drive sorting.
|
|
213
|
+
|
|
214
|
+
let lastExternalFilters = JSON.stringify(getExternalFilters(props.filters))
|
|
188
215
|
|
|
189
|
-
watch(() =>
|
|
190
|
-
|
|
216
|
+
watch(() => normalizeFilters(props.filters), incoming => {
|
|
217
|
+
const externalChanged = incoming.external !== lastExternalFilters
|
|
218
|
+
lastExternalFilters = incoming.external
|
|
219
|
+
|
|
220
|
+
const sortChanged = incoming.sortBy !== sortState.value.sortBy
|
|
221
|
+
|| incoming.sortOrder !== sortState.value.sortOrder
|
|
222
|
+
if (!externalChanged && !sortChanged) return
|
|
223
|
+
|
|
224
|
+
if (sortChanged) sortState.value = { sortBy: incoming.sortBy, sortOrder: incoming.sortOrder }
|
|
225
|
+
if (!started.value) {
|
|
226
|
+
emit('update:filters', getFilters())
|
|
227
|
+
return
|
|
228
|
+
}
|
|
191
229
|
refresh()
|
|
192
230
|
})
|
|
193
231
|
|
|
@@ -24,7 +24,13 @@ export interface InfiniteDataTableProps<T = Record<string, any>> {
|
|
|
24
24
|
columns?: DataTableColumn[]
|
|
25
25
|
/** Whether to fetch the first page on mount (default: true) */
|
|
26
26
|
autoFetch?: boolean
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Whole query state (v-model:filters): the caller's own filter fields plus the
|
|
29
|
+
* component-owned `sortBy` / `sortOrder`. Incoming changes to the owned keys
|
|
30
|
+
* are adopted too, so an external panel can drive sorting. An absent owned key
|
|
31
|
+
* keeps the current value; `sortBy: null` clears the sort. Any change resets
|
|
32
|
+
* and reloads.
|
|
33
|
+
*/
|
|
28
34
|
filters?: Record<string, any>
|
|
29
35
|
/** Number of rows per page (default: 30) */
|
|
30
36
|
pageSize?: number
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.6",
|
|
4
4
|
"description": "Nuxt layer providing shadcn-vue based UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"vue-i18n": "^11",
|
|
43
43
|
"vue-router": "^4 || ^5"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "2e5f9807a82224e4377e69e71fd3f1aa89757db6"
|
|
46
46
|
}
|