@passui/tanstack 0.2.6 → 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.
Files changed (139) hide show
  1. package/dist/{types/src/auth-shell → auth-shell}/auth-shell.d.ts +3 -3
  2. package/dist/auth-shell/auth-shell.js +17 -0
  3. package/dist/auth-shell.d.ts +2 -0
  4. package/dist/auth-shell.js +1 -0
  5. package/dist/core.d.ts +3 -0
  6. package/dist/core.js +3 -0
  7. package/dist/{types/src/document → document}/compose-viewport.d.ts +11 -11
  8. package/dist/document/compose-viewport.js +43 -0
  9. package/dist/document.d.ts +2 -0
  10. package/dist/document.js +1 -0
  11. package/dist/form-fields/fields.d.ts +30 -0
  12. package/dist/form-fields/fields.js +160 -0
  13. package/dist/form-fields/selection.d.ts +21 -0
  14. package/dist/form-fields/selection.js +73 -0
  15. package/dist/form-fields/submit.d.ts +3 -0
  16. package/dist/form-fields/submit.js +26 -0
  17. package/dist/form-fields.d.ts +7 -0
  18. package/dist/form-fields.js +7 -0
  19. package/dist/forms/contexts.js +4 -0
  20. package/dist/{types/src/forms → forms}/elements/form-alert.d.ts +4 -4
  21. package/dist/forms/elements/form-alert.js +19 -0
  22. package/dist/forms/fields/avatar-picker.d.ts +10 -0
  23. package/dist/forms/fields/avatar-picker.js +228 -0
  24. package/dist/forms/fields/avatar.d.ts +30 -0
  25. package/dist/forms/fields/avatar.js +188 -0
  26. package/dist/forms/fields/checkbox.d.ts +2 -0
  27. package/dist/forms/fields/index.d.ts +21 -0
  28. package/dist/forms/fields/index.js +15 -0
  29. package/dist/forms/fields/input.d.ts +2 -0
  30. package/dist/forms/fields/multiselect.d.ts +2 -0
  31. package/dist/forms/fields/otp.d.ts +2 -0
  32. package/dist/forms/fields/radio-card.d.ts +2 -0
  33. package/dist/forms/fields/switch.d.ts +2 -0
  34. package/dist/forms/fields/textarea.d.ts +2 -0
  35. package/dist/forms.d.ts +45 -0
  36. package/dist/forms.js +16 -0
  37. package/dist/mutation/use-app-mutation.d.ts +23 -0
  38. package/dist/mutation/use-app-mutation.js +41 -0
  39. package/dist/mutation.d.ts +3 -0
  40. package/dist/mutation.js +3 -0
  41. package/dist/route-boundary/default-boundary.d.ts +2 -0
  42. package/dist/route-boundary/default-boundary.js +40 -0
  43. package/dist/route-boundary/default-loader.d.ts +6 -0
  44. package/dist/route-boundary/default-loader.js +17 -0
  45. package/dist/{types/src/route-boundary → route-boundary}/not-founder.d.ts +2 -2
  46. package/dist/route-boundary/not-founder.js +44 -0
  47. package/dist/route-boundary.d.ts +4 -0
  48. package/dist/route-boundary.js +4 -0
  49. package/dist/settings/setting-list.d.ts +51 -0
  50. package/dist/settings/setting-list.js +122 -0
  51. package/dist/settings.d.ts +2 -0
  52. package/dist/settings.js +1 -0
  53. package/dist/{types/src/shared → shared}/optimistic.d.ts +2 -2
  54. package/dist/shared/optimistic.js +16 -0
  55. package/dist/{types/src/shared → shared}/table.d.ts +7 -7
  56. package/dist/shared/table.js +12 -0
  57. package/dist/tables/columns.d.ts +3 -0
  58. package/dist/tables/columns.js +21 -0
  59. package/dist/tables/data-table.d.ts +76 -0
  60. package/dist/tables/data-table.js +307 -0
  61. package/dist/tables/filter-row.js +137 -0
  62. package/dist/tables/pagination.d.ts +8 -0
  63. package/dist/tables/pagination.js +86 -0
  64. package/dist/tables.d.ts +4 -0
  65. package/dist/tables.js +4 -0
  66. package/package.json +129 -128
  67. package/src/styles.css +1 -0
  68. package/dist/types/src/auth-shell/index.d.ts +0 -1
  69. package/dist/types/src/document/index.d.ts +0 -1
  70. package/dist/types/src/form-fields/fields.d.ts +0 -24
  71. package/dist/types/src/form-fields/index.d.ts +0 -2
  72. package/dist/types/src/form-fields/selection.d.ts +0 -21
  73. package/dist/types/src/form-fields/submit.d.ts +0 -3
  74. package/dist/types/src/forms/contexts.d.ts +0 -1
  75. package/dist/types/src/forms/elements/submit.d.ts +0 -1
  76. package/dist/types/src/forms/fields/avatar-picker.d.ts +0 -30
  77. package/dist/types/src/forms/fields/avatar.d.ts +0 -30
  78. package/dist/types/src/forms/fields/checkbox.d.ts +0 -1
  79. package/dist/types/src/forms/fields/index.d.ts +0 -21
  80. package/dist/types/src/forms/fields/input.d.ts +0 -1
  81. package/dist/types/src/forms/fields/multiselect.d.ts +0 -1
  82. package/dist/types/src/forms/fields/otp.d.ts +0 -1
  83. package/dist/types/src/forms/fields/radio-card.d.ts +0 -1
  84. package/dist/types/src/forms/fields/switch.d.ts +0 -1
  85. package/dist/types/src/forms/fields/textarea.d.ts +0 -1
  86. package/dist/types/src/forms/index.d.ts +0 -41
  87. package/dist/types/src/mutation/index.d.ts +0 -1
  88. package/dist/types/src/mutation/use-app-mutation.d.ts +0 -22
  89. package/dist/types/src/route-boundary/default-boundary.d.ts +0 -2
  90. package/dist/types/src/route-boundary/default-loader.d.ts +0 -6
  91. package/dist/types/src/route-boundary/index.d.ts +0 -3
  92. package/dist/types/src/settings/index.d.ts +0 -1
  93. package/dist/types/src/settings/setting-list.d.ts +0 -51
  94. package/dist/types/src/shared/index.d.ts +0 -2
  95. package/dist/types/src/tables/columns.d.ts +0 -3
  96. package/dist/types/src/tables/data-table.d.ts +0 -76
  97. package/dist/types/src/tables/filter-row.d.ts +0 -9
  98. package/dist/types/src/tables/index.d.ts +0 -3
  99. package/dist/types/src/tables/pagination.d.ts +0 -8
  100. package/dist/types/src/tables/utils.d.ts +0 -1
  101. package/src/auth-shell/auth-shell.tsx +0 -16
  102. package/src/auth-shell/index.ts +0 -1
  103. package/src/document/compose-viewport.tsx +0 -80
  104. package/src/document/index.ts +0 -1
  105. package/src/form-fields/fields.tsx +0 -147
  106. package/src/form-fields/index.ts +0 -2
  107. package/src/form-fields/selection.tsx +0 -109
  108. package/src/form-fields/submit.tsx +0 -35
  109. package/src/forms/contexts.ts +0 -4
  110. package/src/forms/elements/form-alert.tsx +0 -21
  111. package/src/forms/elements/submit.tsx +0 -1
  112. package/src/forms/fields/avatar-picker.tsx +0 -319
  113. package/src/forms/fields/avatar.tsx +0 -269
  114. package/src/forms/fields/checkbox.tsx +0 -1
  115. package/src/forms/fields/index.ts +0 -29
  116. package/src/forms/fields/input.tsx +0 -1
  117. package/src/forms/fields/multiselect.tsx +0 -1
  118. package/src/forms/fields/otp.tsx +0 -1
  119. package/src/forms/fields/radio-card.tsx +0 -1
  120. package/src/forms/fields/switch.tsx +0 -1
  121. package/src/forms/fields/textarea.tsx +0 -1
  122. package/src/forms/index.ts +0 -26
  123. package/src/mutation/index.ts +0 -1
  124. package/src/mutation/use-app-mutation.ts +0 -100
  125. package/src/route-boundary/default-boundary.tsx +0 -46
  126. package/src/route-boundary/default-loader.tsx +0 -23
  127. package/src/route-boundary/index.ts +0 -3
  128. package/src/route-boundary/not-founder.tsx +0 -39
  129. package/src/settings/index.ts +0 -1
  130. package/src/settings/setting-list.tsx +0 -221
  131. package/src/shared/index.ts +0 -2
  132. package/src/shared/optimistic.ts +0 -19
  133. package/src/shared/table.ts +0 -12
  134. package/src/tables/columns.tsx +0 -30
  135. package/src/tables/data-table.tsx +0 -522
  136. package/src/tables/filter-row.tsx +0 -196
  137. package/src/tables/index.ts +0 -3
  138. package/src/tables/pagination.tsx +0 -85
  139. package/src/tables/utils.ts +0 -5
@@ -1,100 +0,0 @@
1
- import { useMutation, useQueryClient } from "@tanstack/react-query"
2
- import type { QueryKey, UseMutationOptions } from "@tanstack/react-query"
3
- import { toast } from "@passui/react/toast"
4
-
5
- type OptimisticUpdate<TOptimisticData, TVariables> = {
6
- queryKey: QueryKey
7
- /** Applied to the cache immediately, before the mutation resolves. Rolled back if it errors. */
8
- updater: (old: TOptimisticData | undefined, variables: TVariables) => TOptimisticData
9
- }
10
-
11
- type MutationContext<TOptimisticData> =
12
- | {
13
- previous: TOptimisticData | undefined
14
- next: TOptimisticData
15
- }
16
- | undefined
17
-
18
- import { restoreOptimisticSnapshot } from "../shared/optimistic"
19
- export { shouldRestoreOptimisticSnapshot, restoreOptimisticSnapshot } from "../shared/optimistic"
20
-
21
- type AppMutationOptions<TData, TVariables, TOptimisticData> = Omit<
22
- UseMutationOptions<TData, Error, TVariables, MutationContext<TOptimisticData>>,
23
- "onSuccess" | "onError" | "onMutate" | "onSettled"
24
- > & {
25
- /** Query keys to invalidate once the mutation settles, win or lose. */
26
- invalidates?: QueryKey[]
27
- optimisticUpdate?: OptimisticUpdate<TOptimisticData, TVariables>
28
- successMessage?: string | ((data: TData, variables: TVariables) => string)
29
- successDescription?: string | ((data: TData, variables: TVariables) => string | undefined)
30
- errorMessage?: string
31
- onSuccess?: (data: TData, variables: TVariables) => void
32
- onError?: (error: Error, variables: TVariables) => void
33
- }
34
-
35
- // every domain mutation hook in both infra and www builds on this instead
36
- // of calling useMutation directly; optimisticUpdate's rollback only
37
- // restores the snapshot if nothing else wrote to the same queryKey in the
38
- // meantime
39
- export function useAppMutation<TData, TVariables = void, TOptimisticData = unknown>({
40
- invalidates = [],
41
- optimisticUpdate,
42
- successMessage,
43
- successDescription,
44
- errorMessage,
45
- onSuccess,
46
- onError,
47
- ...options
48
- }: AppMutationOptions<TData, TVariables, TOptimisticData>) {
49
- const q = useQueryClient()
50
- return useMutation<TData, Error, TVariables, MutationContext<TOptimisticData>>({
51
- ...options,
52
- onMutate: async (variables) => {
53
- if (!optimisticUpdate) return undefined
54
- const { queryKey, updater } = optimisticUpdate
55
- await q.cancelQueries({ queryKey })
56
- const previous = q.getQueryData<TOptimisticData>(queryKey)
57
- const next = updater(previous, variables)
58
- q.setQueryData<TOptimisticData>(queryKey, next)
59
- return { previous, next }
60
- },
61
- onSuccess: (data, variables) => {
62
- if (successMessage) {
63
- toast.success(
64
- typeof successMessage === "function"
65
- ? successMessage(data, variables)
66
- : successMessage,
67
- {
68
- description:
69
- typeof successDescription === "function"
70
- ? successDescription(data, variables)
71
- : successDescription,
72
- }
73
- )
74
- }
75
- onSuccess?.(data, variables)
76
- },
77
- onError: (error, variables, context) => {
78
- if (optimisticUpdate && context) {
79
- // only roll back if nothing else has written to this key
80
- // since our optimistic value landed, otherwise this would
81
- // silently discard a concurrent mutation's newer change
82
- restoreOptimisticSnapshot(
83
- q,
84
- optimisticUpdate.queryKey,
85
- context.previous,
86
- context.next
87
- )
88
- }
89
- toast.error(errorMessage ?? "Something went wrong", {
90
- description: error.message,
91
- })
92
- onError?.(error, variables)
93
- },
94
- onSettled: () => {
95
- for (const queryKey of invalidates) {
96
- void q.invalidateQueries({ queryKey })
97
- }
98
- },
99
- })
100
- }
@@ -1,46 +0,0 @@
1
- import type { ErrorComponentProps } from "@tanstack/react-router"
2
- import { Button, buttonStyle } from "@passui/react/button"
3
- import { ErrorComponent, Link, useLocation, useRouter } from "@tanstack/react-router"
4
- import { cn } from "@passui/react/cn"
5
-
6
- export function DefaultBoundary({ error }: ErrorComponentProps) {
7
- const router = useRouter()
8
- const isRoot = useLocation({
9
- select: (location) => location.pathname === "/",
10
- })
11
-
12
- return (
13
- <div className="flex min-h-100 w-full flex-col items-center justify-center gap-6 p-6 text-center">
14
- <div className="w-full max-w-md overflow-hidden rounded-md border border-destructive/20 bg-destructive/5 p-4 text-left">
15
- <p className="mb-2 text-xs font-semibold tracking-wider text-destructive uppercase">
16
- Application Error
17
- </p>
18
- <ErrorComponent error={error} />
19
- </div>
20
-
21
- <div className="flex flex-wrap items-center justify-center gap-2">
22
- <Button onClick={() => router.invalidate()} variant="secondary" size="sm">
23
- Try Again
24
- </Button>
25
-
26
- {isRoot ? (
27
- <Link
28
- to="/"
29
- className={cn(
30
- buttonStyle({
31
- variant: "default",
32
- size: "sm",
33
- })
34
- )}
35
- >
36
- Go Home
37
- </Link>
38
- ) : (
39
- <Button onClick={() => router.history.back()} variant="default" size="sm">
40
- Go Back
41
- </Button>
42
- )}
43
- </div>
44
- </div>
45
- )
46
- }
@@ -1,23 +0,0 @@
1
- import { LoadingIcon } from "@passui/react/icons"
2
- import { cn } from "@passui/react/cn"
3
-
4
- export type DefaultLoaderProps = {
5
- /** Translated loading status for assistive technology; never displayed visually. */
6
- label?: string
7
- className?: string
8
- }
9
-
10
- export function DefaultLoader({ label, className }: DefaultLoaderProps = {}) {
11
- return (
12
- <section
13
- role="status"
14
- aria-label={label}
15
- className={cn("flex min-h-80 flex-1 items-center justify-center p-6", className)}
16
- >
17
- <LoadingIcon
18
- aria-hidden="true"
19
- className="size-6! animate-spin motion-reduce:animate-none"
20
- />
21
- </section>
22
- )
23
- }
@@ -1,3 +0,0 @@
1
- export * from "./default-boundary"
2
- export * from "./default-loader"
3
- export * from "./not-founder"
@@ -1,39 +0,0 @@
1
- import { Link, useRouter } from "@tanstack/react-router"
2
- import { Button, buttonStyle } from "@passui/react/button"
3
- import type { PropsWithChildren } from "react"
4
- import { cn } from "@passui/react/cn"
5
-
6
- type NotFoundProps = PropsWithChildren
7
-
8
- export function NotFound({ children }: NotFoundProps) {
9
- const router = useRouter()
10
-
11
- return (
12
- <div className="flex min-h-[80svh] w-full flex-col items-center justify-center text-center">
13
- <section className="mx-auto flex w-full max-w-sm flex-col items-center justify-center gap-4">
14
- {children ?? (
15
- <div className="flex flex-col items-center gap-2">
16
- <span className="font-mono text-xs font-semibold tracking-widest text-destructive uppercase">
17
- Error 404
18
- </span>
19
- <h2 className="text-2xl font-bold tracking-tight text-foreground">
20
- Page Not Found
21
- </h2>
22
- <p className="max-w-70 text-sm text-muted-foreground">
23
- The page you are looking for might have been moved, renamed, or deleted.
24
- </p>
25
- </div>
26
- )}
27
-
28
- <div className="mt-2 flex items-center gap-2">
29
- <Button onClick={() => router.history.back()} variant="secondary" size="sm">
30
- Go back
31
- </Button>
32
- <Link to="/" className={cn(buttonStyle({ size: "sm" }))}>
33
- Start Over
34
- </Link>
35
- </div>
36
- </section>
37
- </div>
38
- )
39
- }
@@ -1 +0,0 @@
1
- export * from "./setting-list"
@@ -1,221 +0,0 @@
1
- import { IconButton, type IconButtonSize } from "@passui/react/icon-button"
2
- import { ArrowRight01Icon, Copy01Icon, Tick02Icon } from "@hugeicons/core-free-icons"
3
- import { HugeiconsIcon } from "@hugeicons/react"
4
- import { cn } from "@passui/react/cn"
5
- import { Link } from "@tanstack/react-router"
6
- import type { LinkProps } from "@tanstack/react-router"
7
- import type { ReactNode } from "react"
8
- import { useState } from "react"
9
-
10
- type SettingListProps = {
11
- id?: string
12
- /** h3 when the list sits inside an Area that already has the h2. */
13
- as?: "h2" | "h3"
14
- /** A Glyph beside the heading; rows themselves stay plain. */
15
- icon?: ReactNode
16
- title?: string
17
- description?: string
18
- /** Right of the heading: an Add button, or a Coming soon badge. */
19
- action?: ReactNode
20
- /** "tile": the rounded, lifted card of the account app's overview. */
21
- variant?: "inset" | "tile"
22
- children: ReactNode
23
- className?: string
24
- }
25
-
26
- type RowProps = {
27
- icon?: ReactNode
28
- title: ReactNode
29
- description?: ReactNode
30
- /** The current value, muted on the right, like "On" or an email. */
31
- value?: ReactNode
32
- trailing?: ReactNode
33
- to?: LinkProps["to"]
34
- params?: LinkProps["params"]
35
- hash?: string
36
- onClick?: () => void
37
- /** Show the chevron without a destination, for a preview row. */
38
- chevron?: boolean
39
- tone?: "default" | "destructive"
40
- }
41
-
42
- /**
43
- * A titled group of settings in one inset card, hairlines between rows
44
- * (even rows wrapped in a Preview), a soft highlight under the one you point at.
45
- */
46
- export function SettingList({
47
- id,
48
- as: Heading = "h2",
49
- icon,
50
- title,
51
- description,
52
- action,
53
- variant = "inset",
54
- children,
55
- className,
56
- }: SettingListProps) {
57
- const lines = cn(
58
- "[&>*+*]:border-t [&>*+*]:border-border/40",
59
- "[&_.setting-row+.setting-row]:border-t [&_.setting-row+.setting-row]:border-border/40"
60
- )
61
-
62
- // the account app's tile: the heading lives inside the card, on a tinted band
63
- if (variant === "tile")
64
- return (
65
- <section
66
- id={id}
67
- className={cn(
68
- "flex scroll-mt-24 flex-col overflow-hidden rounded-3xl border border-separator/70 bg-elevated shadow-sm",
69
- className
70
- )}
71
- >
72
- {title && (
73
- <div className="flex items-center gap-3 border-b border-separator/60 px-4 py-4 sm:px-5 [&>span:first-child]:size-9 [&>span:first-child_.glyph]:size-4">
74
- {icon}
75
- <div className="flex min-w-0 flex-1 flex-col">
76
- <Heading className="text-base">{title}</Heading>
77
- {description && (
78
- <p className="text-[13px] text-muted-foreground">{description}</p>
79
- )}
80
- </div>
81
- {action}
82
- </div>
83
- )}
84
- <div
85
- className={cn(
86
- "flex flex-col py-1 [&_.setting-row]:min-h-16 [&_.setting-row]:px-4 sm:[&_.setting-row]:px-5 [&_.setting-row_h3]:text-subheadline [&_.setting-row_p]:text-footnote",
87
- lines
88
- )}
89
- >
90
- {children}
91
- </div>
92
- </section>
93
- )
94
-
95
- return (
96
- <section
97
- id={id}
98
- className={cn(
99
- "flex scroll-mt-20 flex-col gap-3",
100
- "[&>div:last-child]:rounded-2xl [&>div:last-child]:shadow-xs",
101
- "[&>div:first-child_h2]:text-subheadline [&>div:first-child_h2]:font-semibold",
102
- "[&>div:first-child_p]:text-footnote [&>div:first-child_p]:text-label-secondary",
103
- "[&_.setting-row]:min-h-16 [&_.setting-row]:px-4 [&_.setting-row]:py-3",
104
- "[&_.setting-row_h3]:whitespace-normal [&_.setting-row_h3]:wrap-anywhere [&_.setting-row_h3]:text-subheadline",
105
- "[&_.setting-row_p]:wrap-anywhere [&_.setting-row_p]:text-footnote [&_.setting-row_p]:text-label-secondary",
106
- "[&_.setting-row>span]:whitespace-normal [&_.setting-row>span]:wrap-anywhere",
107
- className
108
- )}
109
- >
110
- {title && (
111
- <div className="flex flex-wrap items-start justify-between gap-3">
112
- <div className="flex min-w-0 flex-1 items-start gap-3">
113
- {icon}
114
- <div className="min-w-0 wrap-anywhere">
115
- <Heading>{title}</Heading>
116
- {description && <p className="text-sm">{description}</p>}
117
- </div>
118
- </div>
119
- {action}
120
- </div>
121
- )}
122
- <div
123
- className={cn(
124
- "flex flex-col overflow-hidden rounded-xl border border-border/35 bg-card shadow-xs",
125
- lines
126
- )}
127
- >
128
- {children}
129
- </div>
130
- </section>
131
- )
132
- }
133
-
134
- function Row({
135
- icon,
136
- title,
137
- description,
138
- value,
139
- trailing,
140
- to,
141
- params,
142
- hash,
143
- onClick,
144
- chevron,
145
- tone = "default",
146
- }: RowProps) {
147
- const interactive = Boolean(to || onClick)
148
- const className = cn(
149
- "setting-row flex min-h-10 w-full items-center gap-3 px-3.5 py-1.5 text-left",
150
- interactive &&
151
- "cursor-pointer transition-colors hover:bg-foreground/[0.035] focus-visible:bg-foreground/[0.05] focus-visible:outline-none",
152
- tone === "destructive" && "[&_h3]:text-destructive"
153
- )
154
- const body = (
155
- <>
156
- {icon}
157
- <span className="flex min-w-0 flex-1 flex-col">
158
- <h3 className="truncate text-sm">{title}</h3>
159
- {description && <p className="text-xs">{description}</p>}
160
- </span>
161
- {value && (
162
- <span className="max-w-[45%] truncate text-sm text-muted-foreground">{value}</span>
163
- )}
164
- {trailing}
165
- {(chevron ?? interactive) && (
166
- <HugeiconsIcon
167
- icon={ArrowRight01Icon}
168
- className="size-4 shrink-0 text-muted-foreground/60"
169
- />
170
- )}
171
- </>
172
- )
173
-
174
- if (to) {
175
- return (
176
- <Link to={to} params={params} hash={hash} className={className}>
177
- {body}
178
- </Link>
179
- )
180
- }
181
- if (onClick) {
182
- return (
183
- <button type="button" onClick={onClick} className={className}>
184
- {body}
185
- </button>
186
- )
187
- }
188
- return <div className={className}>{body}</div>
189
- }
190
-
191
- /** A row's trailing copy button; shows a tick for a moment after copying. */
192
- function Copy({
193
- value,
194
- label = "Copy",
195
- size = "icon-xs",
196
- }: {
197
- value: string
198
- label?: string
199
- /** Quiet and row-sized by default; any of Passui's icon sizes. */
200
- size?: IconButtonSize
201
- }) {
202
- const [copied, setCopied] = useState(false)
203
- return (
204
- <IconButton
205
- variant="ghost"
206
- size={size}
207
- label={label}
208
- onClick={async (event) => {
209
- event.stopPropagation()
210
- await navigator.clipboard.writeText(value)
211
- setCopied(true)
212
- setTimeout(() => setCopied(false), 1500)
213
- }}
214
- >
215
- <HugeiconsIcon icon={copied ? Tick02Icon : Copy01Icon} className="size-4" />
216
- </IconButton>
217
- )
218
- }
219
-
220
- SettingList.Row = Row
221
- SettingList.Copy = Copy
@@ -1,2 +0,0 @@
1
- export * from "./optimistic"
2
- export * from "./table"
@@ -1,19 +0,0 @@
1
- import type { QueryClient, QueryKey } from "@tanstack/react-query"
2
-
3
- /** Restore only the snapshot this mutation wrote, preserving newer concurrent writes. */
4
- export function shouldRestoreOptimisticSnapshot<T>(current: T | undefined, expected: T) {
5
- return current === expected
6
- }
7
-
8
- /** Remove a new optimistic cache entry when no cache value existed before the mutation. */
9
- export function restoreOptimisticSnapshot<T>(
10
- client: Pick<QueryClient, "getQueryData" | "setQueryData" | "removeQueries">,
11
- queryKey: QueryKey,
12
- previous: T | undefined,
13
- expected: T
14
- ) {
15
- if (!shouldRestoreOptimisticSnapshot(client.getQueryData<T>(queryKey), expected)) return false
16
- if (previous === undefined) client.removeQueries({ queryKey, exact: true })
17
- else client.setQueryData(queryKey, previous)
18
- return true
19
- }
@@ -1,12 +0,0 @@
1
- export function isArrayValuedColumn<TData>(data: TData[], colId: string): boolean {
2
- return data.some((row) => Array.isArray((row as Record<string, unknown>)[colId]))
3
- }
4
- export function getColumnLabel(column: { columnDef: { header?: unknown }; id: string }) {
5
- const header = column.columnDef.header
6
- return typeof header === "string"
7
- ? header
8
- : column.id.replace(/([A-Z])/g, " $1").replace(/^./, (value) => value.toUpperCase())
9
- }
10
- export function columnIdOf(column: { id?: string; accessorKey?: unknown }): string | undefined {
11
- return column.id || (typeof column.accessorKey === "string" ? column.accessorKey : undefined)
12
- }
@@ -1,30 +0,0 @@
1
- import type { RowData } from "@tanstack/react-table"
2
- import { Toggle } from "@passui/react/toggle"
3
- import type { DataTableColumnDef } from "./data-table"
4
-
5
- export function selectColumn<TData extends RowData>(): DataTableColumnDef<TData> {
6
- return {
7
- id: "select",
8
- enableColumnFilter: false,
9
- enableGlobalFilter: false,
10
- header: ({ table }) => (
11
- <Toggle
12
- style="checkbox"
13
- labelHidden
14
- checked={table.getIsAllPageRowsSelected()}
15
- mixed={table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected()}
16
- onChange={(checked) => table.toggleAllPageRowsSelected(checked)}
17
- label="Select all"
18
- />
19
- ),
20
- cell: ({ row }) => (
21
- <Toggle
22
- style="checkbox"
23
- labelHidden
24
- checked={row.getIsSelected()}
25
- onChange={(checked) => row.toggleSelected(checked)}
26
- label="Select row"
27
- />
28
- ),
29
- }
30
- }