@bjj/nuxt-layer-shadcn-ui 0.15.6 → 0.15.7
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.vue +10 -0
- package/app/components/ui/AsyncDataTable/types.ts +1 -1
- package/app/components/ui/DataTable/index.vue +6 -4
- package/app/components/ui/StaticDataTable/index.vue +9 -0
- package/app/components/ui/StaticDataTable/types.ts +1 -1
- package/package.json +2 -2
|
@@ -46,6 +46,14 @@ function onSelectionChange (value: TData | TData[] | null) {
|
|
|
46
46
|
emit('update:selection', Array.isArray(value) ? value : value ? [ value ] : [])
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// A fetch replaces the rows on screen — a different page, a different filter,
|
|
50
|
+
// or fresh objects for the same records — so nothing picked before it can
|
|
51
|
+
// still be pointed at. Cleared alongside the rows, in the same tick, so the
|
|
52
|
+
// checkboxes and the batch-action count never disagree about what's selected.
|
|
53
|
+
function clearSelection () {
|
|
54
|
+
if (selectionValue.value.length) emit('update:selection', [])
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
// -- Internal state --
|
|
50
58
|
|
|
51
59
|
const loading = ref(false)
|
|
@@ -171,6 +179,7 @@ async function fetchData (page?: number, forceRefresh = false) {
|
|
|
171
179
|
|
|
172
180
|
internalData.value = result.items as TData[]
|
|
173
181
|
pagination.value.total = result.total
|
|
182
|
+
clearSelection()
|
|
174
183
|
} catch (error) {
|
|
175
184
|
if (currentVersion !== requestVersion.value) return
|
|
176
185
|
console.error('AsyncDataTable fetchData failed:', error)
|
|
@@ -178,6 +187,7 @@ async function fetchData (page?: number, forceRefresh = false) {
|
|
|
178
187
|
// previous page's rows on screen while the pagination already moved on.
|
|
179
188
|
errored.value = true
|
|
180
189
|
internalData.value = []
|
|
190
|
+
clearSelection()
|
|
181
191
|
} finally {
|
|
182
192
|
if (currentVersion === requestVersion.value) loading.value = false
|
|
183
193
|
}
|
|
@@ -48,6 +48,6 @@ export interface AsyncDataTableProps<T = Record<string, any>> {
|
|
|
48
48
|
clickable?: boolean
|
|
49
49
|
/** Batch action definitions for selected rows */
|
|
50
50
|
batchActions?: AsyncDataTableBatchAction<T>[]
|
|
51
|
-
/** Selected rows (v-model:selection) */
|
|
51
|
+
/** Selected rows (v-model:selection). Cleared whenever a fetch replaces the rows — paging, sorting, filtering, refresh. */
|
|
52
52
|
selection?: T[]
|
|
53
53
|
}
|
|
@@ -59,13 +59,15 @@ const selectedSet = computed(() => {
|
|
|
59
59
|
return new Set(selection.value.map(r => toRaw(r) as TData))
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
// Header "select all" checkbox
|
|
62
|
+
// Header "select all" checkbox. Derived from the rows on screen rather than
|
|
63
|
+
// from the selection size, so a selection still holding rows from elsewhere
|
|
64
|
+
// can't read as "all selected".
|
|
63
65
|
const allChecked = computed({
|
|
64
66
|
get () {
|
|
65
67
|
if (!props.data?.length) return false
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
if (
|
|
68
|
+
const selectedOnPage = props.data.filter(row => selectedSet.value.has(toRaw(row) as TData)).length
|
|
69
|
+
if (selectedOnPage === props.data.length) return true
|
|
70
|
+
if (selectedOnPage > 0) return 'indeterminate' as const
|
|
69
71
|
return false
|
|
70
72
|
},
|
|
71
73
|
set (val: boolean | 'indeterminate') {
|
|
@@ -42,6 +42,12 @@ function onSelectionChange (value: TData | TData[] | null) {
|
|
|
42
42
|
emit('update:selection', Array.isArray(value) ? value : value ? [ value ] : [])
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// Whatever swaps the visible rows also drops what was picked from them, so the
|
|
46
|
+
// checkboxes and the batch-action count never disagree about what's selected.
|
|
47
|
+
function clearSelection () {
|
|
48
|
+
if (selectionValue.value.length) emit('update:selection', [])
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
// -- Internal state --
|
|
46
52
|
|
|
47
53
|
const pagination = ref<StaticDataTablePagination>({
|
|
@@ -91,6 +97,7 @@ watch(
|
|
|
91
97
|
[ () => props.data, () => sortState.value.sortBy, () => sortState.value.sortOrder ],
|
|
92
98
|
() => {
|
|
93
99
|
pagination.value.page = 1
|
|
100
|
+
clearSelection()
|
|
94
101
|
},
|
|
95
102
|
)
|
|
96
103
|
|
|
@@ -129,12 +136,14 @@ const batchMenuItems = computed<DropdownItem[]>(() =>
|
|
|
129
136
|
function onPageChange (newPage: number) {
|
|
130
137
|
if (newPage === pagination.value.page) return
|
|
131
138
|
pagination.value.page = newPage
|
|
139
|
+
clearSelection()
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
function onPageSizeChange (newSize: number) {
|
|
135
143
|
if (newSize === pagination.value.size) return
|
|
136
144
|
pagination.value.size = newSize
|
|
137
145
|
pagination.value.page = 1
|
|
146
|
+
clearSelection()
|
|
138
147
|
}
|
|
139
148
|
|
|
140
149
|
function onSortByUpdate (value: string | null) {
|
|
@@ -32,6 +32,6 @@ export interface StaticDataTableProps<T = Record<string, any>> {
|
|
|
32
32
|
clickable?: boolean
|
|
33
33
|
/** Batch action definitions for selected rows */
|
|
34
34
|
batchActions?: StaticDataTableBatchAction<T>[]
|
|
35
|
-
/** Selected rows (v-model:selection) */
|
|
35
|
+
/** Selected rows (v-model:selection). Cleared whenever the visible rows are swapped — paging, sorting, new data. */
|
|
36
36
|
selection?: T[]
|
|
37
37
|
}
|
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.7",
|
|
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": "f9c5a4ca3f0fa3ab4cdfb8f950487d3142031058"
|
|
46
46
|
}
|