@passui/tanstack 0.2.7 → 0.3.0
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/dist/{types/src/auth-shell → auth-shell}/auth-shell.d.ts +3 -3
- package/dist/auth-shell/auth-shell.js +17 -0
- package/dist/auth-shell.d.ts +2 -0
- package/dist/auth-shell.js +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.js +3 -0
- package/dist/{types/src/document → document}/compose-viewport.d.ts +11 -11
- package/dist/document/compose-viewport.js +43 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.js +1 -0
- package/dist/form-fields/fields.d.ts +30 -0
- package/dist/form-fields/fields.js +160 -0
- package/dist/form-fields/selection.d.ts +21 -0
- package/dist/form-fields/selection.js +73 -0
- package/dist/form-fields/submit.d.ts +3 -0
- package/dist/form-fields/submit.js +26 -0
- package/dist/form-fields.d.ts +7 -0
- package/dist/form-fields.js +7 -0
- package/dist/forms/contexts.js +4 -0
- package/dist/{types/src/forms → forms}/elements/form-alert.d.ts +4 -4
- package/dist/forms/elements/form-alert.js +19 -0
- package/dist/forms/fields/avatar-picker.d.ts +10 -0
- package/dist/forms/fields/avatar-picker.js +228 -0
- package/dist/forms/fields/avatar.d.ts +30 -0
- package/dist/forms/fields/avatar.js +188 -0
- package/dist/forms/fields/checkbox.d.ts +2 -0
- package/dist/forms/fields/index.d.ts +21 -0
- package/dist/forms/fields/index.js +15 -0
- package/dist/forms/fields/input.d.ts +2 -0
- package/dist/forms/fields/multiselect.d.ts +2 -0
- package/dist/forms/fields/otp.d.ts +2 -0
- package/dist/forms/fields/radio-card.d.ts +2 -0
- package/dist/forms/fields/switch.d.ts +2 -0
- package/dist/forms/fields/textarea.d.ts +2 -0
- package/dist/forms.d.ts +45 -0
- package/dist/forms.js +16 -0
- package/dist/mutation/use-app-mutation.d.ts +23 -0
- package/dist/mutation/use-app-mutation.js +41 -0
- package/dist/mutation.d.ts +3 -0
- package/dist/mutation.js +3 -0
- package/dist/route-boundary/default-boundary.d.ts +2 -0
- package/dist/route-boundary/default-boundary.js +40 -0
- package/dist/route-boundary/default-loader.d.ts +6 -0
- package/dist/route-boundary/default-loader.js +17 -0
- package/dist/{types/src/route-boundary → route-boundary}/not-founder.d.ts +2 -2
- package/dist/route-boundary/not-founder.js +44 -0
- package/dist/route-boundary.d.ts +4 -0
- package/dist/route-boundary.js +4 -0
- package/dist/settings/setting-list.d.ts +51 -0
- package/dist/settings/setting-list.js +122 -0
- package/dist/settings.d.ts +2 -0
- package/dist/settings.js +1 -0
- package/dist/{types/src/shared → shared}/optimistic.d.ts +2 -2
- package/dist/shared/optimistic.js +16 -0
- package/dist/{types/src/shared → shared}/table.d.ts +7 -7
- package/dist/shared/table.js +12 -0
- package/dist/tables/columns.d.ts +3 -0
- package/dist/tables/columns.js +21 -0
- package/dist/tables/data-table.d.ts +76 -0
- package/dist/tables/data-table.js +307 -0
- package/dist/tables/filter-row.js +137 -0
- package/dist/tables/pagination.d.ts +8 -0
- package/dist/tables/pagination.js +86 -0
- package/dist/tables.d.ts +4 -0
- package/dist/tables.js +4 -0
- package/package.json +129 -128
- package/src/styles.css +1 -0
- package/dist/types/src/auth-shell/index.d.ts +0 -1
- package/dist/types/src/document/index.d.ts +0 -1
- package/dist/types/src/form-fields/fields.d.ts +0 -24
- package/dist/types/src/form-fields/index.d.ts +0 -2
- package/dist/types/src/form-fields/selection.d.ts +0 -21
- package/dist/types/src/form-fields/submit.d.ts +0 -3
- package/dist/types/src/forms/contexts.d.ts +0 -1
- package/dist/types/src/forms/elements/submit.d.ts +0 -1
- package/dist/types/src/forms/fields/avatar-picker.d.ts +0 -30
- package/dist/types/src/forms/fields/avatar.d.ts +0 -30
- package/dist/types/src/forms/fields/checkbox.d.ts +0 -1
- package/dist/types/src/forms/fields/index.d.ts +0 -21
- package/dist/types/src/forms/fields/input.d.ts +0 -1
- package/dist/types/src/forms/fields/multiselect.d.ts +0 -1
- package/dist/types/src/forms/fields/otp.d.ts +0 -1
- package/dist/types/src/forms/fields/radio-card.d.ts +0 -1
- package/dist/types/src/forms/fields/switch.d.ts +0 -1
- package/dist/types/src/forms/fields/textarea.d.ts +0 -1
- package/dist/types/src/forms/index.d.ts +0 -41
- package/dist/types/src/mutation/index.d.ts +0 -1
- package/dist/types/src/mutation/use-app-mutation.d.ts +0 -22
- package/dist/types/src/route-boundary/default-boundary.d.ts +0 -2
- package/dist/types/src/route-boundary/default-loader.d.ts +0 -6
- package/dist/types/src/route-boundary/index.d.ts +0 -3
- package/dist/types/src/settings/index.d.ts +0 -1
- package/dist/types/src/settings/setting-list.d.ts +0 -51
- package/dist/types/src/shared/index.d.ts +0 -2
- package/dist/types/src/tables/columns.d.ts +0 -3
- package/dist/types/src/tables/data-table.d.ts +0 -76
- package/dist/types/src/tables/filter-row.d.ts +0 -9
- package/dist/types/src/tables/index.d.ts +0 -3
- package/dist/types/src/tables/pagination.d.ts +0 -8
- package/dist/types/src/tables/utils.d.ts +0 -1
- package/src/auth-shell/auth-shell.tsx +0 -16
- package/src/auth-shell/index.ts +0 -1
- package/src/document/compose-viewport.tsx +0 -80
- package/src/document/index.ts +0 -1
- package/src/form-fields/fields.tsx +0 -147
- package/src/form-fields/index.ts +0 -2
- package/src/form-fields/selection.tsx +0 -109
- package/src/form-fields/submit.tsx +0 -35
- package/src/forms/contexts.ts +0 -4
- package/src/forms/elements/form-alert.tsx +0 -21
- package/src/forms/elements/submit.tsx +0 -1
- package/src/forms/fields/avatar-picker.tsx +0 -319
- package/src/forms/fields/avatar.tsx +0 -269
- package/src/forms/fields/checkbox.tsx +0 -1
- package/src/forms/fields/index.ts +0 -29
- package/src/forms/fields/input.tsx +0 -1
- package/src/forms/fields/multiselect.tsx +0 -1
- package/src/forms/fields/otp.tsx +0 -1
- package/src/forms/fields/radio-card.tsx +0 -1
- package/src/forms/fields/switch.tsx +0 -1
- package/src/forms/fields/textarea.tsx +0 -1
- package/src/forms/index.ts +0 -26
- package/src/mutation/index.ts +0 -1
- package/src/mutation/use-app-mutation.ts +0 -100
- package/src/route-boundary/default-boundary.tsx +0 -46
- package/src/route-boundary/default-loader.tsx +0 -23
- package/src/route-boundary/index.ts +0 -3
- package/src/route-boundary/not-founder.tsx +0 -39
- package/src/settings/index.ts +0 -1
- package/src/settings/setting-list.tsx +0 -223
- package/src/shared/index.ts +0 -2
- package/src/shared/optimistic.ts +0 -19
- package/src/shared/table.ts +0 -12
- package/src/tables/columns.tsx +0 -30
- package/src/tables/data-table.tsx +0 -524
- package/src/tables/filter-row.tsx +0 -196
- package/src/tables/index.ts +0 -3
- package/src/tables/pagination.tsx +0 -85
- package/src/tables/utils.ts +0 -5
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { IconButton } from "@passui/react/icon-button"
|
|
2
|
-
import { useMemo } from "react"
|
|
3
|
-
import type { Column, RowData } from "@tanstack/react-table"
|
|
4
|
-
import { HugeiconsIcon } from "@hugeicons/react"
|
|
5
|
-
import { Cancel01Icon } from "@hugeicons/core-free-icons"
|
|
6
|
-
import { Button } from "@passui/react/button"
|
|
7
|
-
import { Toggle } from "@passui/react/toggle"
|
|
8
|
-
import type { DataTableFeatures } from "./data-table"
|
|
9
|
-
import { getColumnLabel } from "./utils"
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The quick-filter checkbox list's own candidate values. For a plain scalar
|
|
13
|
-
* column, one value per distinct cell. For an array-valued column, the
|
|
14
|
-
* individual items across every row's array are what should show up as
|
|
15
|
-
* checkboxes.
|
|
16
|
-
*/
|
|
17
|
-
function useQuickFilterValues<TData>(
|
|
18
|
-
data: TData[],
|
|
19
|
-
colId: string,
|
|
20
|
-
exclude: string[],
|
|
21
|
-
isArrayColumn: boolean
|
|
22
|
-
) {
|
|
23
|
-
return useMemo(() => {
|
|
24
|
-
if (exclude.includes(colId)) return []
|
|
25
|
-
if (isArrayColumn) {
|
|
26
|
-
const flattened = data.flatMap((row) => {
|
|
27
|
-
const value = (row as Record<string, unknown>)[colId]
|
|
28
|
-
return Array.isArray(value) ? value : []
|
|
29
|
-
})
|
|
30
|
-
const unique = [
|
|
31
|
-
...new Set(flattened.filter((v) => v !== null && v !== undefined && v !== "")),
|
|
32
|
-
]
|
|
33
|
-
if (unique.length < 2 || unique.length > 20) return []
|
|
34
|
-
return unique.map((v) => String(v))
|
|
35
|
-
}
|
|
36
|
-
const raw = data.map((row) => (row as Record<string, unknown>)[colId])
|
|
37
|
-
const unique = [
|
|
38
|
-
...new Set(
|
|
39
|
-
raw.filter(
|
|
40
|
-
(v) => v !== null && v !== undefined && v !== "" && typeof v !== "object"
|
|
41
|
-
)
|
|
42
|
-
),
|
|
43
|
-
]
|
|
44
|
-
if (unique.length < 2 || unique.length > 12) return []
|
|
45
|
-
return unique.map((v) => String(v))
|
|
46
|
-
}, [data, colId, exclude, isArrayColumn])
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function FilterRow<TData extends RowData>({
|
|
50
|
-
column,
|
|
51
|
-
data,
|
|
52
|
-
skip,
|
|
53
|
-
isArrayColumn,
|
|
54
|
-
isDateColumn,
|
|
55
|
-
}: {
|
|
56
|
-
column: Column<DataTableFeatures, TData, unknown>
|
|
57
|
-
data: TData[]
|
|
58
|
-
skip: string[]
|
|
59
|
-
isArrayColumn: boolean
|
|
60
|
-
isDateColumn: boolean
|
|
61
|
-
}) {
|
|
62
|
-
const uniqueValues = useQuickFilterValues(data, column.id, skip, isArrayColumn)
|
|
63
|
-
const label = getColumnLabel(column)
|
|
64
|
-
|
|
65
|
-
// A date column never gets the enumerated-values treatment below —
|
|
66
|
-
// every row realistically has its own distinct timestamp — a from/to
|
|
67
|
-
// range is what's actually useful.
|
|
68
|
-
if (isDateColumn) {
|
|
69
|
-
const [from, to] = (column.getFilterValue() as [string?, string?] | undefined) ?? []
|
|
70
|
-
return (
|
|
71
|
-
<div className="flex items-center gap-3">
|
|
72
|
-
<span className="w-20 shrink-0 text-caption2 font-medium text-muted-foreground">
|
|
73
|
-
{label}
|
|
74
|
-
</span>
|
|
75
|
-
<div className="flex items-center gap-2">
|
|
76
|
-
<input
|
|
77
|
-
type="date"
|
|
78
|
-
value={from ?? ""}
|
|
79
|
-
onChange={(e) => column.setFilterValue([e.target.value || undefined, to])}
|
|
80
|
-
className="h-7 rounded-none border border-dashed border-input/40 bg-background px-2 text-caption outline-none"
|
|
81
|
-
/>
|
|
82
|
-
<span className="text-caption2 text-muted-foreground">to</span>
|
|
83
|
-
<input
|
|
84
|
-
type="date"
|
|
85
|
-
value={to ?? ""}
|
|
86
|
-
onChange={(e) => column.setFilterValue([from, e.target.value || undefined])}
|
|
87
|
-
className="h-7 rounded-none border border-dashed border-input/40 bg-background px-2 text-caption outline-none"
|
|
88
|
-
/>
|
|
89
|
-
{(from || to) && (
|
|
90
|
-
<IconButton
|
|
91
|
-
label="Clear filter"
|
|
92
|
-
type="button"
|
|
93
|
-
size="icon-sm"
|
|
94
|
-
onClick={() => column.setFilterValue(undefined)}
|
|
95
|
-
className="text-muted-foreground hover:text-foreground"
|
|
96
|
-
>
|
|
97
|
-
<HugeiconsIcon icon={Cancel01Icon} className="size-3" />
|
|
98
|
-
</IconButton>
|
|
99
|
-
)}
|
|
100
|
-
</div>
|
|
101
|
-
</div>
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// `activeFilter` is a bare value for a plain scalar column, or a
|
|
106
|
-
// one-element array for an array-valued column (array-contains matching
|
|
107
|
-
// needs an array of values to check for overlap, even when only one is
|
|
108
|
-
// ever picked here).
|
|
109
|
-
const activeFilter = column.getFilterValue() as string | string[] | undefined
|
|
110
|
-
const activeValue = isArrayColumn
|
|
111
|
-
? Array.isArray(activeFilter)
|
|
112
|
-
? activeFilter[0]
|
|
113
|
-
: undefined
|
|
114
|
-
: (activeFilter as string | undefined)
|
|
115
|
-
|
|
116
|
-
if (uniqueValues.length > 0) {
|
|
117
|
-
return (
|
|
118
|
-
<div className="flex flex-col gap-1">
|
|
119
|
-
<span className="text-caption">{label}</span>
|
|
120
|
-
<div className="flex flex-wrap items-center gap-3">
|
|
121
|
-
{uniqueValues.map((value) => {
|
|
122
|
-
const active = activeValue === value
|
|
123
|
-
const setActive = () =>
|
|
124
|
-
column.setFilterValue(
|
|
125
|
-
active ? undefined : isArrayColumn ? [value] : value
|
|
126
|
-
)
|
|
127
|
-
return (
|
|
128
|
-
<div
|
|
129
|
-
key={value}
|
|
130
|
-
className="flex cursor-pointer items-center gap-2"
|
|
131
|
-
onClick={setActive}
|
|
132
|
-
>
|
|
133
|
-
<Toggle
|
|
134
|
-
style="checkbox"
|
|
135
|
-
labelHidden
|
|
136
|
-
label={value}
|
|
137
|
-
checked={active}
|
|
138
|
-
onChange={setActive}
|
|
139
|
-
/>
|
|
140
|
-
<span className="text-caption">{value}</span>
|
|
141
|
-
</div>
|
|
142
|
-
)
|
|
143
|
-
})}
|
|
144
|
-
{activeValue && (
|
|
145
|
-
<Button
|
|
146
|
-
type="button"
|
|
147
|
-
variant="ghost"
|
|
148
|
-
size="sm"
|
|
149
|
-
onClick={() => column.setFilterValue(undefined)}
|
|
150
|
-
className="text-muted-foreground hover:text-foreground"
|
|
151
|
-
>
|
|
152
|
-
<HugeiconsIcon icon={Cancel01Icon} className="size-3" />
|
|
153
|
-
Clear
|
|
154
|
-
</Button>
|
|
155
|
-
)}
|
|
156
|
-
</div>
|
|
157
|
-
</div>
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return (
|
|
162
|
-
<div className="flex items-center gap-3">
|
|
163
|
-
<span className="w-20 shrink-0 text-caption2 font-medium text-muted-foreground capitalize">
|
|
164
|
-
{label}
|
|
165
|
-
</span>
|
|
166
|
-
<div className="relative max-w-xs flex-1">
|
|
167
|
-
<input
|
|
168
|
-
type="text"
|
|
169
|
-
placeholder={`Filter ${label.toLowerCase()}…`}
|
|
170
|
-
value={activeValue ?? ""}
|
|
171
|
-
onChange={(e) =>
|
|
172
|
-
column.setFilterValue(
|
|
173
|
-
e.target.value
|
|
174
|
-
? isArrayColumn
|
|
175
|
-
? [e.target.value]
|
|
176
|
-
: e.target.value
|
|
177
|
-
: undefined
|
|
178
|
-
)
|
|
179
|
-
}
|
|
180
|
-
className="h-7 w-full rounded-none border border-dashed border-input/40 bg-background px-2.5 text-caption outline-none placeholder:text-muted-foreground/40"
|
|
181
|
-
/>
|
|
182
|
-
{activeValue && (
|
|
183
|
-
<IconButton
|
|
184
|
-
label="Clear filter"
|
|
185
|
-
type="button"
|
|
186
|
-
size="icon-sm"
|
|
187
|
-
onClick={() => column.setFilterValue(undefined)}
|
|
188
|
-
className="absolute top-1/2 right-1 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
|
189
|
-
>
|
|
190
|
-
<HugeiconsIcon icon={Cancel01Icon} className="size-3" />
|
|
191
|
-
</IconButton>
|
|
192
|
-
)}
|
|
193
|
-
</div>
|
|
194
|
-
</div>
|
|
195
|
-
)
|
|
196
|
-
}
|
package/src/tables/index.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { IconButton } from "@passui/react/icon-button"
|
|
2
|
-
import { HugeiconsIcon } from "@hugeicons/react"
|
|
3
|
-
import {
|
|
4
|
-
ChevronFirstIcon,
|
|
5
|
-
ChevronLastIcon,
|
|
6
|
-
ChevronLeftIcon,
|
|
7
|
-
ChevronRightIcon,
|
|
8
|
-
} from "@hugeicons/core-free-icons"
|
|
9
|
-
import type { ReactTable, RowData } from "@tanstack/react-table"
|
|
10
|
-
import { Picker } from "@passui/react"
|
|
11
|
-
import type { DataTableFeatures } from "./data-table"
|
|
12
|
-
|
|
13
|
-
type DataTablePaginationProps<TData extends RowData> = {
|
|
14
|
-
table: ReactTable<DataTableFeatures, TData>
|
|
15
|
-
pageSizeOptions?: number[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function DataTablePagination<TData extends RowData>({
|
|
19
|
-
table,
|
|
20
|
-
pageSizeOptions = [10, 20, 30, 50],
|
|
21
|
-
}: DataTablePaginationProps<TData>) {
|
|
22
|
-
const { pageIndex, pageSize } = table.state.pagination
|
|
23
|
-
const pageCount = table.getPageCount()
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<div className="flex flex-wrap items-center gap-x-4 gap-y-2">
|
|
27
|
-
<p className="shrink-0 whitespace-nowrap text-footnote text-label-secondary">
|
|
28
|
-
Page {pageCount ? pageIndex + 1 : 0} of {pageCount}
|
|
29
|
-
</p>
|
|
30
|
-
|
|
31
|
-
<div className="flex items-center gap-1">
|
|
32
|
-
<IconButton
|
|
33
|
-
label="First page"
|
|
34
|
-
type="button"
|
|
35
|
-
size="icon-sm"
|
|
36
|
-
disabled={!table.getCanPreviousPage()}
|
|
37
|
-
onClick={() => table.setPageIndex(0)}
|
|
38
|
-
>
|
|
39
|
-
<HugeiconsIcon icon={ChevronFirstIcon} />
|
|
40
|
-
</IconButton>
|
|
41
|
-
<IconButton
|
|
42
|
-
label="Previous page"
|
|
43
|
-
type="button"
|
|
44
|
-
size="icon-sm"
|
|
45
|
-
disabled={!table.getCanPreviousPage()}
|
|
46
|
-
onClick={() => table.previousPage()}
|
|
47
|
-
>
|
|
48
|
-
<HugeiconsIcon icon={ChevronLeftIcon} />
|
|
49
|
-
</IconButton>
|
|
50
|
-
<IconButton
|
|
51
|
-
label="Next page"
|
|
52
|
-
type="button"
|
|
53
|
-
size="icon-sm"
|
|
54
|
-
disabled={!table.getCanNextPage()}
|
|
55
|
-
onClick={() => table.nextPage()}
|
|
56
|
-
>
|
|
57
|
-
<HugeiconsIcon icon={ChevronRightIcon} />
|
|
58
|
-
</IconButton>
|
|
59
|
-
<IconButton
|
|
60
|
-
label="Last page"
|
|
61
|
-
type="button"
|
|
62
|
-
size="icon-sm"
|
|
63
|
-
disabled={!table.getCanNextPage()}
|
|
64
|
-
onClick={() => table.setPageIndex(pageCount - 1)}
|
|
65
|
-
>
|
|
66
|
-
<HugeiconsIcon icon={ChevronLastIcon} />
|
|
67
|
-
</IconButton>
|
|
68
|
-
</div>
|
|
69
|
-
|
|
70
|
-
<div className="w-20 shrink-0">
|
|
71
|
-
<Picker
|
|
72
|
-
className="w-full"
|
|
73
|
-
label="Rows per page"
|
|
74
|
-
value={String(pageSize)}
|
|
75
|
-
onChange={(value) => table.setPageSize(Number(value))}
|
|
76
|
-
options={pageSizeOptions.map((size) => ({
|
|
77
|
-
value: String(size),
|
|
78
|
-
label: String(size),
|
|
79
|
-
}))}
|
|
80
|
-
searchable={false}
|
|
81
|
-
/>
|
|
82
|
-
</div>
|
|
83
|
-
</div>
|
|
84
|
-
)
|
|
85
|
-
}
|