@passui/tanstack 0.2.4 → 0.2.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/README.md +3 -42
- package/dist/types/src/auth-shell/auth-shell.d.ts +5 -0
- package/dist/types/src/document/compose-viewport.d.ts +20 -0
- package/dist/types/src/form-fields/fields.d.ts +24 -0
- package/dist/types/src/form-fields/index.d.ts +2 -0
- package/dist/types/src/form-fields/selection.d.ts +21 -0
- package/dist/types/src/form-fields/submit.d.ts +3 -0
- package/dist/types/src/forms/contexts.d.ts +1 -0
- package/dist/types/src/forms/elements/form-alert.d.ts +6 -0
- package/dist/types/src/forms/elements/submit.d.ts +1 -0
- package/dist/types/src/forms/fields/avatar-picker.d.ts +30 -0
- package/dist/types/src/forms/fields/avatar.d.ts +30 -0
- package/dist/types/src/forms/fields/checkbox.d.ts +1 -0
- package/dist/types/src/forms/fields/index.d.ts +21 -0
- package/dist/types/src/forms/fields/input.d.ts +1 -0
- package/dist/types/src/forms/fields/multiselect.d.ts +1 -0
- package/dist/types/src/forms/fields/otp.d.ts +1 -0
- package/dist/types/src/forms/fields/radio-card.d.ts +1 -0
- package/dist/types/src/forms/fields/switch.d.ts +1 -0
- package/dist/types/src/forms/fields/textarea.d.ts +1 -0
- package/dist/types/src/forms/index.d.ts +41 -0
- package/dist/types/src/mutation/index.d.ts +1 -0
- package/dist/types/src/mutation/use-app-mutation.d.ts +22 -0
- package/dist/types/src/route-boundary/default-boundary.d.ts +2 -0
- package/dist/types/src/route-boundary/default-loader.d.ts +6 -0
- package/dist/types/src/route-boundary/index.d.ts +3 -0
- package/dist/types/src/route-boundary/not-founder.d.ts +4 -0
- package/dist/types/src/settings/setting-list.d.ts +51 -0
- package/dist/types/src/shared/index.d.ts +2 -0
- package/dist/types/src/shared/optimistic.d.ts +3 -0
- package/dist/types/src/shared/table.d.ts +11 -0
- package/dist/types/src/{solid/tables → tables}/columns.d.ts +1 -2
- package/dist/types/src/tables/data-table.d.ts +76 -0
- package/dist/types/src/tables/filter-row.d.ts +9 -0
- package/dist/types/src/{solid/tables → tables}/index.d.ts +0 -1
- package/dist/types/src/tables/pagination.d.ts +8 -0
- package/dist/types/src/tables/utils.d.ts +1 -0
- package/package.json +8 -93
- package/src/document/compose-viewport.tsx +4 -20
- package/src/form-fields/fields.tsx +17 -62
- package/src/form-fields/selection.tsx +12 -52
- package/src/form-fields/submit.tsx +1 -6
- package/src/forms/contexts.ts +2 -6
- package/src/forms/elements/form-alert.tsx +2 -11
- package/src/forms/fields/avatar-picker.tsx +39 -119
- package/src/forms/fields/avatar.tsx +13 -43
- package/src/forms/fields/index.ts +1 -4
- package/src/forms/index.ts +1 -5
- package/src/mutation/use-app-mutation.ts +32 -88
- package/src/route-boundary/default-boundary.tsx +4 -19
- package/src/route-boundary/default-loader.tsx +14 -10
- package/src/route-boundary/not-founder.tsx +3 -14
- package/src/settings/setting-list.tsx +10 -41
- package/src/shared/optimistic.ts +15 -3
- package/src/shared/table.ts +6 -24
- package/src/tables/columns.tsx +4 -13
- package/src/tables/data-table.tsx +130 -225
- package/src/tables/filter-row.tsx +19 -83
- package/src/tables/pagination.tsx +4 -12
- package/dist/client/chunks/form-fields-DlWu70u5.js +0 -630
- package/dist/client/src/solid/auth-shell/index.js +0 -15
- package/dist/client/src/solid/document/index.js +0 -51
- package/dist/client/src/solid/form-fields/index.js +0 -1
- package/dist/client/src/solid/forms/index.js +0 -33
- package/dist/client/src/solid/mutation/index.js +0 -46
- package/dist/client/src/solid/route-boundary/index.js +0 -73
- package/dist/client/src/solid/settings/index.js +0 -173
- package/dist/client/src/solid/tables/index.js +0 -500
- package/dist/server/src/solid/auth-shell/index.js +0 -15
- package/dist/server/src/solid/document/index.js +0 -55
- package/dist/server/src/solid/form-fields/index.js +0 -598
- package/dist/server/src/solid/forms/index.js +0 -33
- package/dist/server/src/solid/mutation/index.js +0 -46
- package/dist/server/src/solid/route-boundary/index.js +0 -73
- package/dist/server/src/solid/settings/index.js +0 -169
- package/dist/server/src/solid/tables/index.js +0 -480
- package/dist/types/src/solid/auth-shell/auth-shell.d.ts +0 -4
- package/dist/types/src/solid/document/compose-viewport.d.ts +0 -14
- package/dist/types/src/solid/form-fields/avatar.d.ts +0 -26
- package/dist/types/src/solid/form-fields/fields.d.ts +0 -45
- package/dist/types/src/solid/form-fields/index.d.ts +0 -3
- package/dist/types/src/solid/form-fields/submit.d.ts +0 -3
- package/dist/types/src/solid/forms/contexts.d.ts +0 -1
- package/dist/types/src/solid/forms/form-alert.d.ts +0 -6
- package/dist/types/src/solid/forms/index.d.ts +0 -43
- package/dist/types/src/solid/mutation/index.d.ts +0 -1
- package/dist/types/src/solid/mutation/use-app-mutation.d.ts +0 -22
- package/dist/types/src/solid/route-boundary/boundaries.d.ts +0 -8
- package/dist/types/src/solid/route-boundary/index.d.ts +0 -1
- package/dist/types/src/solid/settings/setting-list.d.ts +0 -37
- package/dist/types/src/solid/tables/data-table.d.ts +0 -58
- package/dist/types/src/solid/tables/filter-row.d.ts +0 -9
- package/dist/types/src/solid/tables/pagination.d.ts +0 -7
- package/src/solid/auth-shell/auth-shell.tsx +0 -16
- package/src/solid/auth-shell/index.ts +0 -1
- package/src/solid/document/compose-viewport.tsx +0 -69
- package/src/solid/document/index.ts +0 -1
- package/src/solid/form-fields/avatar.tsx +0 -370
- package/src/solid/form-fields/fields.tsx +0 -336
- package/src/solid/form-fields/index.ts +0 -3
- package/src/solid/form-fields/submit.tsx +0 -31
- package/src/solid/forms/contexts.ts +0 -7
- package/src/solid/forms/form-alert.tsx +0 -19
- package/src/solid/forms/index.ts +0 -32
- package/src/solid/mutation/index.ts +0 -5
- package/src/solid/mutation/use-app-mutation.ts +0 -171
- package/src/solid/route-boundary/boundaries.tsx +0 -104
- package/src/solid/route-boundary/index.ts +0 -1
- package/src/solid/settings/index.ts +0 -1
- package/src/solid/settings/setting-list.tsx +0 -185
- package/src/solid/styles.css +0 -2
- package/src/solid/tables/columns.tsx +0 -40
- package/src/solid/tables/data-table.tsx +0 -448
- package/src/solid/tables/filter-row.tsx +0 -161
- package/src/solid/tables/index.ts +0 -4
- package/src/solid/tables/pagination.tsx +0 -78
- /package/dist/types/src/{solid/auth-shell → auth-shell}/index.d.ts +0 -0
- /package/dist/types/src/{solid/document → document}/index.d.ts +0 -0
- /package/dist/types/src/{solid/settings → settings}/index.d.ts +0 -0
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Camera01Icon,
|
|
3
|
-
Delete02Icon,
|
|
4
|
-
Image01Icon,
|
|
5
|
-
TextFontIcon,
|
|
6
|
-
} from "@hugeicons/core-free-icons"
|
|
1
|
+
import { Camera01Icon, Delete02Icon, Image01Icon, TextFontIcon } from "@hugeicons/core-free-icons"
|
|
7
2
|
import { HugeiconsIcon } from "@hugeicons/react"
|
|
8
3
|
import { useEffect, useRef, useState } from "react"
|
|
9
4
|
import type { ReactNode } from "react"
|
|
@@ -69,45 +64,24 @@ const MONOGRAM_GRADIENTS = [
|
|
|
69
64
|
|
|
70
65
|
function initialsOf(label: string) {
|
|
71
66
|
const parts = label.trim().split(/\s+/).filter(Boolean)
|
|
72
|
-
const letters =
|
|
73
|
-
|
|
74
|
-
? [parts[0], parts[parts.length - 1]]
|
|
75
|
-
: parts
|
|
76
|
-
return (
|
|
77
|
-
letters
|
|
78
|
-
.map((part) => part[0]?.toUpperCase() ?? "")
|
|
79
|
-
.join("") || "?"
|
|
80
|
-
)
|
|
67
|
+
const letters = parts.length > 1 ? [parts[0], parts[parts.length - 1]] : parts
|
|
68
|
+
return letters.map((part) => part[0]?.toUpperCase() ?? "").join("") || "?"
|
|
81
69
|
}
|
|
82
70
|
|
|
83
|
-
async function toFile(
|
|
84
|
-
canvas
|
|
85
|
-
name: string,
|
|
86
|
-
type: string
|
|
87
|
-
) {
|
|
88
|
-
const blob = await new Promise<Blob | null>((resolve) =>
|
|
89
|
-
canvas.toBlob(resolve, type, 0.92)
|
|
90
|
-
)
|
|
71
|
+
async function toFile(canvas: HTMLCanvasElement, name: string, type: string) {
|
|
72
|
+
const blob = await new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, type, 0.92))
|
|
91
73
|
if (!blob) throw new Error("Could not export the image")
|
|
92
74
|
return new File([blob], name, { type })
|
|
93
75
|
}
|
|
94
76
|
|
|
95
|
-
async function renderMonogram(
|
|
96
|
-
initials: string,
|
|
97
|
-
[from, to]: readonly [string, string]
|
|
98
|
-
) {
|
|
77
|
+
async function renderMonogram(initials: string, [from, to]: readonly [string, string]) {
|
|
99
78
|
const size = 512
|
|
100
79
|
const canvas = document.createElement("canvas")
|
|
101
80
|
canvas.width = size
|
|
102
81
|
canvas.height = size
|
|
103
82
|
const context = canvas.getContext("2d")
|
|
104
83
|
if (!context) throw new Error("Canvas is not available")
|
|
105
|
-
const gradient = context.createLinearGradient(
|
|
106
|
-
0,
|
|
107
|
-
0,
|
|
108
|
-
0,
|
|
109
|
-
size
|
|
110
|
-
)
|
|
84
|
+
const gradient = context.createLinearGradient(0, 0, 0, size)
|
|
111
85
|
gradient.addColorStop(0, from)
|
|
112
86
|
gradient.addColorStop(1, to)
|
|
113
87
|
context.fillStyle = gradient
|
|
@@ -120,12 +94,7 @@ async function renderMonogram(
|
|
|
120
94
|
return toFile(canvas, "monogram.png", "image/png")
|
|
121
95
|
}
|
|
122
96
|
|
|
123
|
-
function Option({
|
|
124
|
-
icon,
|
|
125
|
-
tone = "default",
|
|
126
|
-
onClick,
|
|
127
|
-
children,
|
|
128
|
-
}: OptionProps) {
|
|
97
|
+
function Option({ icon, tone = "default", onClick, children }: OptionProps) {
|
|
129
98
|
return (
|
|
130
99
|
<button
|
|
131
100
|
type="button"
|
|
@@ -136,21 +105,14 @@ function Option({
|
|
|
136
105
|
tone === "destructive" && "text-destructive"
|
|
137
106
|
)}
|
|
138
107
|
>
|
|
139
|
-
<HugeiconsIcon
|
|
140
|
-
icon={icon}
|
|
141
|
-
className="size-4.5 shrink-0 opacity-80"
|
|
142
|
-
/>
|
|
108
|
+
<HugeiconsIcon icon={icon} className="size-4.5 shrink-0 opacity-80" />
|
|
143
109
|
{children}
|
|
144
110
|
</button>
|
|
145
111
|
)
|
|
146
112
|
}
|
|
147
113
|
|
|
148
114
|
/** The live selfie view: the frame under a circle, an iOS shutter below. */
|
|
149
|
-
function CameraView({
|
|
150
|
-
labels,
|
|
151
|
-
onCapture,
|
|
152
|
-
onCancel,
|
|
153
|
-
}: CameraViewProps) {
|
|
115
|
+
function CameraView({ labels, onCapture, onCancel }: CameraViewProps) {
|
|
154
116
|
const videoRef = useRef<HTMLVideoElement>(null)
|
|
155
117
|
const [failed, setFailed] = useState(false)
|
|
156
118
|
|
|
@@ -166,13 +128,11 @@ function CameraView({
|
|
|
166
128
|
})
|
|
167
129
|
.then((media) => {
|
|
168
130
|
stream = media
|
|
169
|
-
if (videoRef.current)
|
|
170
|
-
videoRef.current.srcObject = media
|
|
131
|
+
if (videoRef.current) videoRef.current.srcObject = media
|
|
171
132
|
})
|
|
172
133
|
.catch(() => setFailed(true))
|
|
173
134
|
return () => {
|
|
174
|
-
for (const track of stream?.getTracks() ?? [])
|
|
175
|
-
track.stop()
|
|
135
|
+
for (const track of stream?.getTracks() ?? []) track.stop()
|
|
176
136
|
}
|
|
177
137
|
}, [])
|
|
178
138
|
|
|
@@ -188,9 +148,7 @@ function CameraView({
|
|
|
188
148
|
context.translate(canvas.width, 0)
|
|
189
149
|
context.scale(-1, 1)
|
|
190
150
|
context.drawImage(video, 0, 0)
|
|
191
|
-
onCapture(
|
|
192
|
-
await toFile(canvas, "photo.jpg", "image/jpeg")
|
|
193
|
-
)
|
|
151
|
+
onCapture(await toFile(canvas, "photo.jpg", "image/jpeg"))
|
|
194
152
|
}
|
|
195
153
|
|
|
196
154
|
return (
|
|
@@ -250,17 +208,13 @@ export function AvatarPicker({
|
|
|
250
208
|
onChoose,
|
|
251
209
|
onRemove,
|
|
252
210
|
}: AvatarPickerProps) {
|
|
253
|
-
const [mode, setMode] = useState<"menu" | "camera">(
|
|
254
|
-
"menu"
|
|
255
|
-
)
|
|
211
|
+
const [mode, setMode] = useState<"menu" | "camera">("menu")
|
|
256
212
|
const [monogramOpen, setMonogramOpen] = useState(false)
|
|
257
213
|
const [canUseCamera, setCanUseCamera] = useState(false)
|
|
258
214
|
const initials = initialsOf(label)
|
|
259
215
|
|
|
260
216
|
useEffect(() => {
|
|
261
|
-
setCanUseCamera(
|
|
262
|
-
Boolean(navigator.mediaDevices?.getUserMedia)
|
|
263
|
-
)
|
|
217
|
+
setCanUseCamera(Boolean(navigator.mediaDevices?.getUserMedia))
|
|
264
218
|
}, [])
|
|
265
219
|
|
|
266
220
|
useEffect(() => {
|
|
@@ -275,18 +229,12 @@ export function AvatarPicker({
|
|
|
275
229
|
<Sheet
|
|
276
230
|
open={open}
|
|
277
231
|
onClose={() => onOpenChange(false)}
|
|
278
|
-
label={
|
|
279
|
-
mode === "camera"
|
|
280
|
-
? labels.takePhoto
|
|
281
|
-
: labels.photo
|
|
282
|
-
}
|
|
232
|
+
label={mode === "camera" ? labels.takePhoto : labels.photo}
|
|
283
233
|
className="gap-0 overflow-hidden rounded-3xl p-0 sm:max-w-[22rem]"
|
|
284
234
|
>
|
|
285
235
|
{mode === "camera" ? (
|
|
286
236
|
<>
|
|
287
|
-
<h2 className="sr-only">
|
|
288
|
-
{labels.takePhoto}
|
|
289
|
-
</h2>
|
|
237
|
+
<h2 className="sr-only">{labels.takePhoto}</h2>
|
|
290
238
|
<CameraView
|
|
291
239
|
labels={labels}
|
|
292
240
|
onCapture={onCapture}
|
|
@@ -300,10 +248,7 @@ export function AvatarPicker({
|
|
|
300
248
|
className="flex flex-col items-center gap-3 px-5 pt-8 pb-6 text-center"
|
|
301
249
|
>
|
|
302
250
|
<ProfileImage className="size-28 shadow-[0_12px_32px_-12px_rgb(0_0_0/0.45)] ring-1 ring-white/50">
|
|
303
|
-
<ProfileImageContent
|
|
304
|
-
src={image}
|
|
305
|
-
alt={label}
|
|
306
|
-
/>
|
|
251
|
+
<ProfileImageContent src={image} alt={label} />
|
|
307
252
|
<ProfileImageFallback className="text-3xl">
|
|
308
253
|
{initials}
|
|
309
254
|
</ProfileImageFallback>
|
|
@@ -315,65 +260,42 @@ export function AvatarPicker({
|
|
|
315
260
|
</Ambient>
|
|
316
261
|
|
|
317
262
|
<div className="m-3 flex flex-col divide-y divide-border/40 overflow-hidden rounded-2xl border border-border/35 bg-card shadow-xs">
|
|
318
|
-
<Option
|
|
319
|
-
icon={Image01Icon}
|
|
320
|
-
onClick={onChooseFile}
|
|
321
|
-
>
|
|
263
|
+
<Option icon={Image01Icon} onClick={onChooseFile}>
|
|
322
264
|
{labels.choosePhoto}
|
|
323
265
|
</Option>
|
|
324
266
|
{canUseCamera && (
|
|
325
|
-
<Option
|
|
326
|
-
icon={Camera01Icon}
|
|
327
|
-
onClick={() =>
|
|
328
|
-
setMode("camera")
|
|
329
|
-
}
|
|
330
|
-
>
|
|
267
|
+
<Option icon={Camera01Icon} onClick={() => setMode("camera")}>
|
|
331
268
|
{labels.takePhoto}
|
|
332
269
|
</Option>
|
|
333
270
|
)}
|
|
334
271
|
<Option
|
|
335
272
|
icon={TextFontIcon}
|
|
336
|
-
onClick={() =>
|
|
337
|
-
setMonogramOpen(
|
|
338
|
-
(current) => !current
|
|
339
|
-
)
|
|
340
|
-
}
|
|
273
|
+
onClick={() => setMonogramOpen((current) => !current)}
|
|
341
274
|
>
|
|
342
275
|
{labels.monogram}
|
|
343
276
|
</Option>
|
|
344
277
|
{monogramOpen && (
|
|
345
278
|
<div className="flex items-center justify-between gap-2 px-4 py-3">
|
|
346
|
-
{MONOGRAM_GRADIENTS.map(
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
backgroundImage: `linear-gradient(${gradient[0]}, ${gradient[1]})`,
|
|
363
|
-
}}
|
|
364
|
-
>
|
|
365
|
-
{initials}
|
|
366
|
-
</button>
|
|
367
|
-
)
|
|
368
|
-
)}
|
|
279
|
+
{MONOGRAM_GRADIENTS.map((gradient) => (
|
|
280
|
+
<button
|
|
281
|
+
key={gradient[0]}
|
|
282
|
+
type="button"
|
|
283
|
+
aria-label={`${labels.monogram} ${gradient[0]}`}
|
|
284
|
+
onClick={() =>
|
|
285
|
+
void renderMonogram(initials, gradient).then(onChoose)
|
|
286
|
+
}
|
|
287
|
+
className="flex size-10 items-center justify-center rounded-full text-sm font-semibold text-white shadow-xs ring-1 ring-black/5 transition-transform hover:scale-105 active:scale-95"
|
|
288
|
+
style={{
|
|
289
|
+
backgroundImage: `linear-gradient(${gradient[0]}, ${gradient[1]})`,
|
|
290
|
+
}}
|
|
291
|
+
>
|
|
292
|
+
{initials}
|
|
293
|
+
</button>
|
|
294
|
+
))}
|
|
369
295
|
</div>
|
|
370
296
|
)}
|
|
371
297
|
{clearable && image && (
|
|
372
|
-
<Option
|
|
373
|
-
icon={Delete02Icon}
|
|
374
|
-
tone="destructive"
|
|
375
|
-
onClick={onRemove}
|
|
376
|
-
>
|
|
298
|
+
<Option icon={Delete02Icon} tone="destructive" onClick={onRemove}>
|
|
377
299
|
{labels.removePhoto}
|
|
378
300
|
</Option>
|
|
379
301
|
)}
|
|
@@ -384,9 +306,7 @@ export function AvatarPicker({
|
|
|
384
306
|
type="button"
|
|
385
307
|
variant="secondary"
|
|
386
308
|
className="w-full rounded-2xl"
|
|
387
|
-
onClick={() =>
|
|
388
|
-
onOpenChange(false)
|
|
389
|
-
}
|
|
309
|
+
onClick={() => onOpenChange(false)}
|
|
390
310
|
>
|
|
391
311
|
{labels.cancel}
|
|
392
312
|
</Button>
|
|
@@ -47,8 +47,7 @@ type FieldAvatarProps = {
|
|
|
47
47
|
const DEFAULT_LABELS: FieldAvatarLabels = {
|
|
48
48
|
edit: "Edit",
|
|
49
49
|
remove: "Remove",
|
|
50
|
-
confirmHint:
|
|
51
|
-
"Press Enter to use this photo, Esc to cancel",
|
|
50
|
+
confirmHint: "Press Enter to use this photo, Esc to cancel",
|
|
52
51
|
save: "Use photo",
|
|
53
52
|
cancel: "Cancel",
|
|
54
53
|
photo: "Photo",
|
|
@@ -61,9 +60,7 @@ const DEFAULT_LABELS: FieldAvatarLabels = {
|
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
const imageFrom = (files: FileList | null | undefined) =>
|
|
64
|
-
[...(files ?? [])].find((file) =>
|
|
65
|
-
file.type.startsWith("image/")
|
|
66
|
-
) ?? null
|
|
63
|
+
[...(files ?? [])].find((file) => file.type.startsWith("image/")) ?? null
|
|
67
64
|
|
|
68
65
|
/**
|
|
69
66
|
* A photo you click to replace: a small menu (choose, take, monogram), then
|
|
@@ -84,9 +81,7 @@ export function FieldAvatar({
|
|
|
84
81
|
const [pending, setPending] = useState<File | null>(null)
|
|
85
82
|
const [sheetOpen, setSheetOpen] = useState(false)
|
|
86
83
|
const [dragOver, setDragOver] = useState(false)
|
|
87
|
-
const [preview, setPreview] = useState<string | null>(
|
|
88
|
-
null
|
|
89
|
-
)
|
|
84
|
+
const [preview, setPreview] = useState<string | null>(null)
|
|
90
85
|
const isCleared = field.state.value === false
|
|
91
86
|
const shown = pending ?? field.state.value
|
|
92
87
|
|
|
@@ -111,8 +106,7 @@ export function FieldAvatar({
|
|
|
111
106
|
if (event.key === "Escape") setPending(null)
|
|
112
107
|
}
|
|
113
108
|
window.addEventListener("keydown", onKey)
|
|
114
|
-
return () =>
|
|
115
|
-
window.removeEventListener("keydown", onKey)
|
|
109
|
+
return () => window.removeEventListener("keydown", onKey)
|
|
116
110
|
})
|
|
117
111
|
|
|
118
112
|
function keep() {
|
|
@@ -121,14 +115,8 @@ export function FieldAvatar({
|
|
|
121
115
|
setPending(null)
|
|
122
116
|
}
|
|
123
117
|
|
|
124
|
-
const currentImage = isCleared
|
|
125
|
-
|
|
126
|
-
: (preview ?? existingImage ?? undefined)
|
|
127
|
-
const canClear =
|
|
128
|
-
clearable &&
|
|
129
|
-
!pending &&
|
|
130
|
-
!isCleared &&
|
|
131
|
-
Boolean(currentImage)
|
|
118
|
+
const currentImage = isCleared ? undefined : (preview ?? existingImage ?? undefined)
|
|
119
|
+
const canClear = clearable && !pending && !isCleared && Boolean(currentImage)
|
|
132
120
|
|
|
133
121
|
function onDrop(event: DragEvent<HTMLButtonElement>) {
|
|
134
122
|
event.preventDefault()
|
|
@@ -149,9 +137,7 @@ export function FieldAvatar({
|
|
|
149
137
|
onDragLeave={() => setDragOver(false)}
|
|
150
138
|
onDrop={onDrop}
|
|
151
139
|
onPaste={(event) => {
|
|
152
|
-
const file = imageFrom(
|
|
153
|
-
event.clipboardData.files
|
|
154
|
-
)
|
|
140
|
+
const file = imageFrom(event.clipboardData.files)
|
|
155
141
|
if (file) setPending(file)
|
|
156
142
|
}}
|
|
157
143
|
className={cn(
|
|
@@ -164,12 +150,9 @@ export function FieldAvatar({
|
|
|
164
150
|
className={cn(
|
|
165
151
|
"relative ring-1 ring-white/40",
|
|
166
152
|
compact ? "size-16!" : "size-43!",
|
|
167
|
-
caption &&
|
|
168
|
-
!compact &&
|
|
169
|
-
"shadow-[0_16px_40px_-16px_rgb(0_0_0/0.5)]",
|
|
153
|
+
caption && !compact && "shadow-[0_16px_40px_-16px_rgb(0_0_0/0.5)]",
|
|
170
154
|
"transition-transform duration-300 ease-out group-hover:scale-[1.02] group-active:scale-[0.98]",
|
|
171
|
-
(dragOver || pending) &&
|
|
172
|
-
"scale-[1.04]"
|
|
155
|
+
(dragOver || pending) && "scale-[1.04]"
|
|
173
156
|
)}
|
|
174
157
|
>
|
|
175
158
|
<ProfileImageContent
|
|
@@ -177,14 +160,8 @@ export function FieldAvatar({
|
|
|
177
160
|
alt={label}
|
|
178
161
|
className="object-cover transition-[filter] duration-300 group-hover:brightness-90"
|
|
179
162
|
/>
|
|
180
|
-
<ProfileImageFallback
|
|
181
|
-
|
|
182
|
-
compact ? "text-xl" : "text-4xl"
|
|
183
|
-
}
|
|
184
|
-
>
|
|
185
|
-
{(
|
|
186
|
-
label.charAt(0) || "?"
|
|
187
|
-
).toUpperCase()}
|
|
163
|
+
<ProfileImageFallback className={compact ? "text-xl" : "text-4xl"}>
|
|
164
|
+
{(label.charAt(0) || "?").toUpperCase()}
|
|
188
165
|
</ProfileImageFallback>
|
|
189
166
|
</ProfileImage>
|
|
190
167
|
{/* the frosted "Edit" capsule sitting on the photo's lower edge */}
|
|
@@ -203,9 +180,7 @@ export function FieldAvatar({
|
|
|
203
180
|
</button>
|
|
204
181
|
{pending && (
|
|
205
182
|
<div className="flex flex-col items-center gap-2 animate-in fade-in-0 slide-in-from-top-1 duration-300">
|
|
206
|
-
<p className="text-muted-foreground">
|
|
207
|
-
{text.confirmHint}
|
|
208
|
-
</p>
|
|
183
|
+
<p className="text-muted-foreground">{text.confirmHint}</p>
|
|
209
184
|
<div className="flex items-center gap-1">
|
|
210
185
|
<Button
|
|
211
186
|
type="button"
|
|
@@ -215,12 +190,7 @@ export function FieldAvatar({
|
|
|
215
190
|
>
|
|
216
191
|
{text.cancel}
|
|
217
192
|
</Button>
|
|
218
|
-
<Button
|
|
219
|
-
variant="default"
|
|
220
|
-
type="button"
|
|
221
|
-
size="sm"
|
|
222
|
-
onClick={keep}
|
|
223
|
-
>
|
|
193
|
+
<Button variant="default" type="button" size="sm" onClick={keep}>
|
|
224
194
|
{text.save}
|
|
225
195
|
</Button>
|
|
226
196
|
</div>
|
|
@@ -5,10 +5,7 @@ import {
|
|
|
5
5
|
FieldSwitch,
|
|
6
6
|
FieldOtp,
|
|
7
7
|
} from "../../form-fields/fields"
|
|
8
|
-
import {
|
|
9
|
-
FieldRadioCard,
|
|
10
|
-
FieldMultiselect,
|
|
11
|
-
} from "../../form-fields/selection"
|
|
8
|
+
import { FieldRadioCard, FieldMultiselect } from "../../form-fields/selection"
|
|
12
9
|
import { FieldAvatar } from "./avatar"
|
|
13
10
|
|
|
14
11
|
export const fields = {
|
package/src/forms/index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createFormHook,
|
|
3
|
-
useSelector,
|
|
4
|
-
useStore,
|
|
5
|
-
} from "@tanstack/react-form"
|
|
1
|
+
import { createFormHook, useSelector, useStore } from "@tanstack/react-form"
|
|
6
2
|
import { fieldContext, formContext } from "./contexts"
|
|
7
3
|
import { Submit } from "./elements/submit"
|
|
8
4
|
import { fields } from "./fields/index"
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
useQueryClient,
|
|
4
|
-
} from "@tanstack/react-query"
|
|
5
|
-
import type {
|
|
6
|
-
QueryKey,
|
|
7
|
-
UseMutationOptions,
|
|
8
|
-
} from "@tanstack/react-query"
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
2
|
+
import type { QueryKey, UseMutationOptions } from "@tanstack/react-query"
|
|
9
3
|
import { toast } from "@passui/react/toast"
|
|
10
4
|
|
|
11
5
|
type OptimisticUpdate<TOptimisticData, TVariables> = {
|
|
12
6
|
queryKey: QueryKey
|
|
13
7
|
/** Applied to the cache immediately, before the mutation resolves. Rolled back if it errors. */
|
|
14
|
-
updater: (
|
|
15
|
-
old: TOptimisticData | undefined,
|
|
16
|
-
variables: TVariables
|
|
17
|
-
) => TOptimisticData
|
|
8
|
+
updater: (old: TOptimisticData | undefined, variables: TVariables) => TOptimisticData
|
|
18
9
|
}
|
|
19
10
|
|
|
20
11
|
type MutationContext<TOptimisticData> =
|
|
@@ -24,54 +15,28 @@ type MutationContext<TOptimisticData> =
|
|
|
24
15
|
}
|
|
25
16
|
| undefined
|
|
26
17
|
|
|
27
|
-
import {
|
|
28
|
-
export { shouldRestoreOptimisticSnapshot } from "../shared/optimistic"
|
|
18
|
+
import { restoreOptimisticSnapshot } from "../shared/optimistic"
|
|
19
|
+
export { shouldRestoreOptimisticSnapshot, restoreOptimisticSnapshot } from "../shared/optimistic"
|
|
29
20
|
|
|
30
|
-
type AppMutationOptions<TData, TVariables, TOptimisticData> =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
TOptimisticData,
|
|
44
|
-
TVariables
|
|
45
|
-
>
|
|
46
|
-
successMessage?:
|
|
47
|
-
| string
|
|
48
|
-
| ((data: TData, variables: TVariables) => string)
|
|
49
|
-
successDescription?:
|
|
50
|
-
| string
|
|
51
|
-
| ((
|
|
52
|
-
data: TData,
|
|
53
|
-
variables: TVariables
|
|
54
|
-
) => string | undefined)
|
|
55
|
-
errorMessage?: string
|
|
56
|
-
onSuccess?: (
|
|
57
|
-
data: TData,
|
|
58
|
-
variables: TVariables
|
|
59
|
-
) => void
|
|
60
|
-
onError?: (
|
|
61
|
-
error: Error,
|
|
62
|
-
variables: TVariables
|
|
63
|
-
) => void
|
|
64
|
-
}
|
|
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
|
+
}
|
|
65
34
|
|
|
66
35
|
// every domain mutation hook in both infra and www builds on this instead
|
|
67
36
|
// of calling useMutation directly; optimisticUpdate's rollback only
|
|
68
37
|
// restores the snapshot if nothing else wrote to the same queryKey in the
|
|
69
38
|
// meantime
|
|
70
|
-
export function useAppMutation<
|
|
71
|
-
TData,
|
|
72
|
-
TVariables = void,
|
|
73
|
-
TOptimisticData = unknown,
|
|
74
|
-
>({
|
|
39
|
+
export function useAppMutation<TData, TVariables = void, TOptimisticData = unknown>({
|
|
75
40
|
invalidates = [],
|
|
76
41
|
optimisticUpdate,
|
|
77
42
|
successMessage,
|
|
@@ -82,19 +47,13 @@ export function useAppMutation<
|
|
|
82
47
|
...options
|
|
83
48
|
}: AppMutationOptions<TData, TVariables, TOptimisticData>) {
|
|
84
49
|
const q = useQueryClient()
|
|
85
|
-
return useMutation<
|
|
86
|
-
TData,
|
|
87
|
-
Error,
|
|
88
|
-
TVariables,
|
|
89
|
-
MutationContext<TOptimisticData>
|
|
90
|
-
>({
|
|
50
|
+
return useMutation<TData, Error, TVariables, MutationContext<TOptimisticData>>({
|
|
91
51
|
...options,
|
|
92
52
|
onMutate: async (variables) => {
|
|
93
53
|
if (!optimisticUpdate) return undefined
|
|
94
54
|
const { queryKey, updater } = optimisticUpdate
|
|
95
55
|
await q.cancelQueries({ queryKey })
|
|
96
|
-
const previous =
|
|
97
|
-
q.getQueryData<TOptimisticData>(queryKey)
|
|
56
|
+
const previous = q.getQueryData<TOptimisticData>(queryKey)
|
|
98
57
|
const next = updater(previous, variables)
|
|
99
58
|
q.setQueryData<TOptimisticData>(queryKey, next)
|
|
100
59
|
return { previous, next }
|
|
@@ -107,12 +66,8 @@ export function useAppMutation<
|
|
|
107
66
|
: successMessage,
|
|
108
67
|
{
|
|
109
68
|
description:
|
|
110
|
-
typeof successDescription ===
|
|
111
|
-
|
|
112
|
-
? successDescription(
|
|
113
|
-
data,
|
|
114
|
-
variables
|
|
115
|
-
)
|
|
69
|
+
typeof successDescription === "function"
|
|
70
|
+
? successDescription(data, variables)
|
|
116
71
|
: successDescription,
|
|
117
72
|
}
|
|
118
73
|
)
|
|
@@ -121,30 +76,19 @@ export function useAppMutation<
|
|
|
121
76
|
},
|
|
122
77
|
onError: (error, variables, context) => {
|
|
123
78
|
if (optimisticUpdate && context) {
|
|
124
|
-
const current = q.getQueryData(
|
|
125
|
-
optimisticUpdate.queryKey
|
|
126
|
-
)
|
|
127
79
|
// only roll back if nothing else has written to this key
|
|
128
80
|
// since our optimistic value landed, otherwise this would
|
|
129
81
|
// silently discard a concurrent mutation's newer change
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
)
|
|
136
|
-
q.setQueryData(
|
|
137
|
-
optimisticUpdate.queryKey,
|
|
138
|
-
context.previous
|
|
139
|
-
)
|
|
140
|
-
}
|
|
82
|
+
restoreOptimisticSnapshot(
|
|
83
|
+
q,
|
|
84
|
+
optimisticUpdate.queryKey,
|
|
85
|
+
context.previous,
|
|
86
|
+
context.next
|
|
87
|
+
)
|
|
141
88
|
}
|
|
142
|
-
toast.error(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
description: error.message,
|
|
146
|
-
}
|
|
147
|
-
)
|
|
89
|
+
toast.error(errorMessage ?? "Something went wrong", {
|
|
90
|
+
description: error.message,
|
|
91
|
+
})
|
|
148
92
|
onError?.(error, variables)
|
|
149
93
|
},
|
|
150
94
|
onSettled: () => {
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import type { ErrorComponentProps } from "@tanstack/react-router"
|
|
2
2
|
import { Button, buttonStyle } from "@passui/react/button"
|
|
3
|
-
import {
|
|
4
|
-
ErrorComponent,
|
|
5
|
-
Link,
|
|
6
|
-
useLocation,
|
|
7
|
-
useRouter,
|
|
8
|
-
} from "@tanstack/react-router"
|
|
3
|
+
import { ErrorComponent, Link, useLocation, useRouter } from "@tanstack/react-router"
|
|
9
4
|
import { cn } from "@passui/react/cn"
|
|
10
5
|
|
|
11
|
-
export function DefaultBoundary({
|
|
12
|
-
error,
|
|
13
|
-
}: ErrorComponentProps) {
|
|
6
|
+
export function DefaultBoundary({ error }: ErrorComponentProps) {
|
|
14
7
|
const router = useRouter()
|
|
15
8
|
const isRoot = useLocation({
|
|
16
9
|
select: (location) => location.pathname === "/",
|
|
@@ -26,11 +19,7 @@ export function DefaultBoundary({
|
|
|
26
19
|
</div>
|
|
27
20
|
|
|
28
21
|
<div className="flex flex-wrap items-center justify-center gap-2">
|
|
29
|
-
<Button
|
|
30
|
-
onClick={() => router.invalidate()}
|
|
31
|
-
variant="secondary"
|
|
32
|
-
size="sm"
|
|
33
|
-
>
|
|
22
|
+
<Button onClick={() => router.invalidate()} variant="secondary" size="sm">
|
|
34
23
|
Try Again
|
|
35
24
|
</Button>
|
|
36
25
|
|
|
@@ -47,11 +36,7 @@ export function DefaultBoundary({
|
|
|
47
36
|
Go Home
|
|
48
37
|
</Link>
|
|
49
38
|
) : (
|
|
50
|
-
<Button
|
|
51
|
-
onClick={() => router.history.back()}
|
|
52
|
-
variant="default"
|
|
53
|
-
size="sm"
|
|
54
|
-
>
|
|
39
|
+
<Button onClick={() => router.history.back()} variant="default" size="sm">
|
|
55
40
|
Go Back
|
|
56
41
|
</Button>
|
|
57
42
|
)}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Loading03Icon } from "@hugeicons/core-free-icons"
|
|
1
|
+
import { LoadingIcon } from "@passui/react/icons"
|
|
3
2
|
import { cn } from "@passui/react/cn"
|
|
4
3
|
|
|
5
|
-
export
|
|
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 = {}) {
|
|
6
11
|
return (
|
|
7
12
|
<section
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)}
|
|
13
|
+
role="status"
|
|
14
|
+
aria-label={label}
|
|
15
|
+
className={cn("flex min-h-80 flex-1 items-center justify-center p-6", className)}
|
|
12
16
|
>
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
className="size-
|
|
17
|
+
<LoadingIcon
|
|
18
|
+
aria-hidden="true"
|
|
19
|
+
className="size-6! animate-spin motion-reduce:animate-none"
|
|
16
20
|
/>
|
|
17
21
|
</section>
|
|
18
22
|
)
|