@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,336 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import {
|
|
3
|
-
createContext,
|
|
4
|
-
For,
|
|
5
|
-
Show,
|
|
6
|
-
splitProps,
|
|
7
|
-
useContext,
|
|
8
|
-
type JSX,
|
|
9
|
-
} from "solid-js"
|
|
10
|
-
import {
|
|
11
|
-
TextField,
|
|
12
|
-
type TextFieldProps,
|
|
13
|
-
} from "@passui/solid/text-field"
|
|
14
|
-
import { TextEditor } from "@passui/solid/text-editor"
|
|
15
|
-
import { Toggle } from "@passui/solid/toggle"
|
|
16
|
-
import { cn } from "@passui/solid/cn"
|
|
17
|
-
import { useFieldContext } from "../forms/contexts"
|
|
18
|
-
export const PeachFieldLabels = createContext<{
|
|
19
|
-
show: string
|
|
20
|
-
hide: string
|
|
21
|
-
}>()
|
|
22
|
-
function errors(values: unknown[]) {
|
|
23
|
-
return values.flatMap((error) =>
|
|
24
|
-
typeof error === "string"
|
|
25
|
-
? [error]
|
|
26
|
-
: error &&
|
|
27
|
-
typeof error === "object" &&
|
|
28
|
-
"message" in error
|
|
29
|
-
? [String(error.message)]
|
|
30
|
-
: []
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
export function FieldInput(
|
|
34
|
-
props: Omit<
|
|
35
|
-
TextFieldProps,
|
|
36
|
-
"value" | "onInput" | "onBlur" | "name"
|
|
37
|
-
>
|
|
38
|
-
) {
|
|
39
|
-
const field = useFieldContext<string>(),
|
|
40
|
-
reveal = useContext(PeachFieldLabels)
|
|
41
|
-
return (
|
|
42
|
-
<TextField
|
|
43
|
-
revealLabels={reveal}
|
|
44
|
-
{...props}
|
|
45
|
-
name={field().name}
|
|
46
|
-
value={field().state.value}
|
|
47
|
-
onInput={(event) =>
|
|
48
|
-
field().handleChange(
|
|
49
|
-
event.currentTarget.value
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
onBlur={() => field().handleBlur()}
|
|
53
|
-
errors={
|
|
54
|
-
field().state.meta.isTouched
|
|
55
|
-
? errors(field().state.meta.errors)
|
|
56
|
-
: []
|
|
57
|
-
}
|
|
58
|
-
/>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
export function FieldCheckbox(props: {
|
|
62
|
-
label: string
|
|
63
|
-
disabled?: boolean
|
|
64
|
-
}) {
|
|
65
|
-
const field = useFieldContext<boolean>()
|
|
66
|
-
return (
|
|
67
|
-
<Toggle
|
|
68
|
-
style="checkbox"
|
|
69
|
-
label={props.label}
|
|
70
|
-
disabled={props.disabled}
|
|
71
|
-
checked={field().state.value}
|
|
72
|
-
onChange={(checked) => {
|
|
73
|
-
field().handleChange(checked)
|
|
74
|
-
field().handleBlur()
|
|
75
|
-
}}
|
|
76
|
-
/>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
export function FieldSwitch(props: {
|
|
80
|
-
label: string
|
|
81
|
-
description?: string
|
|
82
|
-
disabled?: boolean
|
|
83
|
-
}) {
|
|
84
|
-
const field = useFieldContext<boolean>()
|
|
85
|
-
return (
|
|
86
|
-
<div class="flex items-center justify-between gap-4">
|
|
87
|
-
<div class="text-subheadline">
|
|
88
|
-
{props.label}
|
|
89
|
-
<Show when={props.description}>
|
|
90
|
-
<p class="text-footnote text-label-secondary">
|
|
91
|
-
{props.description}
|
|
92
|
-
</p>
|
|
93
|
-
</Show>
|
|
94
|
-
</div>
|
|
95
|
-
<Toggle
|
|
96
|
-
label={props.label}
|
|
97
|
-
checked={field().state.value}
|
|
98
|
-
disabled={props.disabled}
|
|
99
|
-
onChange={(checked) => {
|
|
100
|
-
field().handleChange(checked)
|
|
101
|
-
field().handleBlur()
|
|
102
|
-
}}
|
|
103
|
-
/>
|
|
104
|
-
</div>
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
export function FieldTextarea(
|
|
108
|
-
props: Omit<
|
|
109
|
-
JSX.TextareaHTMLAttributes<HTMLTextAreaElement>,
|
|
110
|
-
"value" | "onInput" | "onBlur"
|
|
111
|
-
> & { label: string; icon?: JSX.Element }
|
|
112
|
-
) {
|
|
113
|
-
const [local, rest] = splitProps(props, [
|
|
114
|
-
"label",
|
|
115
|
-
"icon",
|
|
116
|
-
]),
|
|
117
|
-
field = useFieldContext<string>()
|
|
118
|
-
const messages = () =>
|
|
119
|
-
field().state.meta.isTouched
|
|
120
|
-
? errors(field().state.meta.errors)
|
|
121
|
-
: []
|
|
122
|
-
return (
|
|
123
|
-
<div class="flex flex-col gap-2">
|
|
124
|
-
<label
|
|
125
|
-
for={field().name}
|
|
126
|
-
class="text-subheadline font-semibold"
|
|
127
|
-
>
|
|
128
|
-
{local.icon}
|
|
129
|
-
{local.label}
|
|
130
|
-
</label>
|
|
131
|
-
<TextEditor
|
|
132
|
-
{...rest}
|
|
133
|
-
id={field().name}
|
|
134
|
-
name={field().name}
|
|
135
|
-
aria-invalid={messages().length > 0}
|
|
136
|
-
aria-describedby={
|
|
137
|
-
messages().length
|
|
138
|
-
? `${field().name}-errors`
|
|
139
|
-
: undefined
|
|
140
|
-
}
|
|
141
|
-
value={field().state.value}
|
|
142
|
-
onBlur={() => field().handleBlur()}
|
|
143
|
-
onInput={(event) =>
|
|
144
|
-
field().handleChange(
|
|
145
|
-
event.currentTarget.value
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
/>
|
|
149
|
-
<Show when={messages().length}>
|
|
150
|
-
<p
|
|
151
|
-
id={`${field().name}-errors`}
|
|
152
|
-
role="alert"
|
|
153
|
-
class="text-footnote text-danger"
|
|
154
|
-
>
|
|
155
|
-
{Array.from(new Set(messages())).join(
|
|
156
|
-
". "
|
|
157
|
-
)}
|
|
158
|
-
</p>
|
|
159
|
-
</Show>
|
|
160
|
-
</div>
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
export function FieldOtp(props: {
|
|
164
|
-
label: string
|
|
165
|
-
maxLength?: number
|
|
166
|
-
onComplete?: (value: string) => void
|
|
167
|
-
}) {
|
|
168
|
-
const field = useFieldContext<string>()
|
|
169
|
-
return (
|
|
170
|
-
<TextField
|
|
171
|
-
label={props.label}
|
|
172
|
-
name={field().name}
|
|
173
|
-
value={field().state.value}
|
|
174
|
-
inputmode="numeric"
|
|
175
|
-
autocomplete="one-time-code"
|
|
176
|
-
pattern="[0-9]*"
|
|
177
|
-
maxLength={props.maxLength ?? 6}
|
|
178
|
-
onBlur={() => field().handleBlur()}
|
|
179
|
-
onInput={(event) => {
|
|
180
|
-
const value = event.currentTarget.value
|
|
181
|
-
.replace(/\D/g, "")
|
|
182
|
-
.slice(0, props.maxLength ?? 6)
|
|
183
|
-
field().handleChange(value)
|
|
184
|
-
if (value.length === (props.maxLength ?? 6))
|
|
185
|
-
props.onComplete?.(value)
|
|
186
|
-
}}
|
|
187
|
-
errors={
|
|
188
|
-
field().state.meta.isTouched
|
|
189
|
-
? errors(field().state.meta.errors)
|
|
190
|
-
: []
|
|
191
|
-
}
|
|
192
|
-
/>
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
export type FieldOption = {
|
|
196
|
-
label: string
|
|
197
|
-
value: string
|
|
198
|
-
description?: string
|
|
199
|
-
icon?: JSX.Element
|
|
200
|
-
disabled?: boolean
|
|
201
|
-
}
|
|
202
|
-
export function FieldRadioCard(props: {
|
|
203
|
-
label: string
|
|
204
|
-
description?: string
|
|
205
|
-
options: FieldOption[]
|
|
206
|
-
disabled?: boolean
|
|
207
|
-
columns?: 1 | 2
|
|
208
|
-
}) {
|
|
209
|
-
const field = useFieldContext<string>()
|
|
210
|
-
return (
|
|
211
|
-
<fieldset
|
|
212
|
-
disabled={props.disabled}
|
|
213
|
-
class="flex flex-col gap-2"
|
|
214
|
-
>
|
|
215
|
-
<legend class="text-subheadline font-semibold">
|
|
216
|
-
{props.label}
|
|
217
|
-
</legend>
|
|
218
|
-
<Show when={props.description}>
|
|
219
|
-
<p class="text-footnote text-label-secondary">
|
|
220
|
-
{props.description}
|
|
221
|
-
</p>
|
|
222
|
-
</Show>
|
|
223
|
-
<div
|
|
224
|
-
class={cn(
|
|
225
|
-
"grid gap-2",
|
|
226
|
-
props.columns === 2 && "md:grid-cols-2"
|
|
227
|
-
)}
|
|
228
|
-
>
|
|
229
|
-
<For each={props.options}>
|
|
230
|
-
{(option) => (
|
|
231
|
-
<label
|
|
232
|
-
class={cn(
|
|
233
|
-
"flex items-start gap-3 rounded-xl border p-3",
|
|
234
|
-
field().state.value ===
|
|
235
|
-
option.value
|
|
236
|
-
? "border-accent-text bg-accent/10"
|
|
237
|
-
: "border-separator bg-elevated",
|
|
238
|
-
(props.disabled ||
|
|
239
|
-
option.disabled) &&
|
|
240
|
-
"opacity-40"
|
|
241
|
-
)}
|
|
242
|
-
>
|
|
243
|
-
<input
|
|
244
|
-
type="radio"
|
|
245
|
-
name={field().name}
|
|
246
|
-
value={option.value}
|
|
247
|
-
checked={
|
|
248
|
-
field().state.value ===
|
|
249
|
-
option.value
|
|
250
|
-
}
|
|
251
|
-
disabled={option.disabled}
|
|
252
|
-
onBlur={() =>
|
|
253
|
-
field().handleBlur()
|
|
254
|
-
}
|
|
255
|
-
onChange={() =>
|
|
256
|
-
field().handleChange(
|
|
257
|
-
option.value
|
|
258
|
-
)
|
|
259
|
-
}
|
|
260
|
-
class="mt-1 accent-accent-text"
|
|
261
|
-
/>
|
|
262
|
-
{option.icon}
|
|
263
|
-
<span class="text-subheadline">
|
|
264
|
-
{option.label}
|
|
265
|
-
<Show
|
|
266
|
-
when={option.description}
|
|
267
|
-
>
|
|
268
|
-
<span class="block text-footnote text-label-secondary">
|
|
269
|
-
{option.description}
|
|
270
|
-
</span>
|
|
271
|
-
</Show>
|
|
272
|
-
</span>
|
|
273
|
-
</label>
|
|
274
|
-
)}
|
|
275
|
-
</For>
|
|
276
|
-
</div>
|
|
277
|
-
</fieldset>
|
|
278
|
-
)
|
|
279
|
-
}
|
|
280
|
-
export function FieldMultiselect(props: {
|
|
281
|
-
label: string
|
|
282
|
-
description?: string
|
|
283
|
-
options: FieldOption[]
|
|
284
|
-
}) {
|
|
285
|
-
const field = useFieldContext<string[]>()
|
|
286
|
-
return (
|
|
287
|
-
<fieldset class="flex flex-col gap-3">
|
|
288
|
-
<legend class="text-subheadline font-semibold">
|
|
289
|
-
{props.label}
|
|
290
|
-
</legend>
|
|
291
|
-
<Show when={props.description}>
|
|
292
|
-
<p class="text-footnote text-label-secondary">
|
|
293
|
-
{props.description}
|
|
294
|
-
</p>
|
|
295
|
-
</Show>
|
|
296
|
-
<For each={props.options}>
|
|
297
|
-
{(option) => (
|
|
298
|
-
<div>
|
|
299
|
-
<Toggle
|
|
300
|
-
style="checkbox"
|
|
301
|
-
label={option.label}
|
|
302
|
-
disabled={option.disabled}
|
|
303
|
-
checked={field().state.value.includes(
|
|
304
|
-
option.value
|
|
305
|
-
)}
|
|
306
|
-
onChange={(checked) => {
|
|
307
|
-
field().handleChange(
|
|
308
|
-
checked
|
|
309
|
-
? Array.from(
|
|
310
|
-
new Set([
|
|
311
|
-
...field()
|
|
312
|
-
.state
|
|
313
|
-
.value,
|
|
314
|
-
option.value,
|
|
315
|
-
])
|
|
316
|
-
)
|
|
317
|
-
: field().state.value.filter(
|
|
318
|
-
(value) =>
|
|
319
|
-
value !==
|
|
320
|
-
option.value
|
|
321
|
-
)
|
|
322
|
-
)
|
|
323
|
-
field().handleBlur()
|
|
324
|
-
}}
|
|
325
|
-
/>
|
|
326
|
-
<Show when={option.description}>
|
|
327
|
-
<p class="pl-8 text-footnote text-label-secondary">
|
|
328
|
-
{option.description}
|
|
329
|
-
</p>
|
|
330
|
-
</Show>
|
|
331
|
-
</div>
|
|
332
|
-
)}
|
|
333
|
-
</For>
|
|
334
|
-
</fieldset>
|
|
335
|
-
)
|
|
336
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import { Button } from "@passui/solid/button"
|
|
3
|
-
import { useFormContext } from "../forms/contexts"
|
|
4
|
-
export function Submit(props: { label: string }) {
|
|
5
|
-
const form = useFormContext()
|
|
6
|
-
return (
|
|
7
|
-
<form.Subscribe
|
|
8
|
-
selector={(state) => ({
|
|
9
|
-
pending: state.isSubmitting,
|
|
10
|
-
valid: state.canSubmit,
|
|
11
|
-
dirty: state.isDirty,
|
|
12
|
-
touched: state.isTouched,
|
|
13
|
-
})}
|
|
14
|
-
>
|
|
15
|
-
{(state) => (
|
|
16
|
-
<Button
|
|
17
|
-
type="submit"
|
|
18
|
-
isPending={state().pending}
|
|
19
|
-
disabled={
|
|
20
|
-
!state().valid ||
|
|
21
|
-
!state().dirty ||
|
|
22
|
-
!state().touched
|
|
23
|
-
}
|
|
24
|
-
class="w-full"
|
|
25
|
-
>
|
|
26
|
-
{props.label}
|
|
27
|
-
</Button>
|
|
28
|
-
)}
|
|
29
|
-
</form.Subscribe>
|
|
30
|
-
)
|
|
31
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import type { JSX } from "solid-js"
|
|
3
|
-
import { cn } from "@passui/solid/cn"
|
|
4
|
-
export function FormAlert(props: {
|
|
5
|
-
children: JSX.Element
|
|
6
|
-
className?: string
|
|
7
|
-
}) {
|
|
8
|
-
return (
|
|
9
|
-
<div
|
|
10
|
-
role="alert"
|
|
11
|
-
class={cn(
|
|
12
|
-
"flex items-start gap-2.5 rounded-2xl bg-danger/12 px-4 py-3 text-subheadline font-medium text-danger ring-1 ring-danger/25 motion-safe:animate-in motion-safe:fade-in-0",
|
|
13
|
-
props.className
|
|
14
|
-
)}
|
|
15
|
-
>
|
|
16
|
-
<span class="min-w-0">{props.children}</span>
|
|
17
|
-
</div>
|
|
18
|
-
)
|
|
19
|
-
}
|
package/src/solid/forms/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createFormHook } from "@tanstack/solid-form"
|
|
2
|
-
import { fieldContext, formContext } from "./contexts"
|
|
3
|
-
import {
|
|
4
|
-
FieldInput,
|
|
5
|
-
FieldCheckbox,
|
|
6
|
-
FieldTextarea,
|
|
7
|
-
FieldSwitch,
|
|
8
|
-
FieldOtp,
|
|
9
|
-
FieldRadioCard,
|
|
10
|
-
FieldMultiselect,
|
|
11
|
-
} from "../form-fields/fields"
|
|
12
|
-
import { FieldAvatar } from "../form-fields/avatar"
|
|
13
|
-
import { Submit } from "../form-fields/submit"
|
|
14
|
-
export const { useAppForm, withForm } = createFormHook({
|
|
15
|
-
fieldContext,
|
|
16
|
-
formContext,
|
|
17
|
-
fieldComponents: {
|
|
18
|
-
input: FieldInput,
|
|
19
|
-
avatar: FieldAvatar,
|
|
20
|
-
checkbox: FieldCheckbox,
|
|
21
|
-
textarea: FieldTextarea,
|
|
22
|
-
switch: FieldSwitch,
|
|
23
|
-
otp: FieldOtp,
|
|
24
|
-
radioCard: FieldRadioCard,
|
|
25
|
-
multiselect: FieldMultiselect,
|
|
26
|
-
},
|
|
27
|
-
formComponents: { submit: Submit },
|
|
28
|
-
})
|
|
29
|
-
export { useAppForm as createAppForm }
|
|
30
|
-
export { useStore, useSelector } from "@tanstack/solid-form"
|
|
31
|
-
export * from "../form-fields"
|
|
32
|
-
export * from "./form-alert"
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useMutation,
|
|
3
|
-
useQueryClient,
|
|
4
|
-
} from "@tanstack/solid-query"
|
|
5
|
-
import type {
|
|
6
|
-
QueryKey,
|
|
7
|
-
MutationOptions,
|
|
8
|
-
} from "@tanstack/solid-query"
|
|
9
|
-
import { toast } from "@passui/solid/toast"
|
|
10
|
-
|
|
11
|
-
type OptimisticUpdate<TOptimisticData, TVariables> = {
|
|
12
|
-
queryKey: QueryKey
|
|
13
|
-
/** 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
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type MutationContext<TOptimisticData> =
|
|
21
|
-
| {
|
|
22
|
-
previous: TOptimisticData | undefined
|
|
23
|
-
next: TOptimisticData
|
|
24
|
-
}
|
|
25
|
-
| undefined
|
|
26
|
-
|
|
27
|
-
import { shouldRestoreOptimisticSnapshot } from "../../shared/optimistic"
|
|
28
|
-
export { shouldRestoreOptimisticSnapshot } from "../../shared/optimistic"
|
|
29
|
-
|
|
30
|
-
type AppMutationOptions<TData, TVariables, TOptimisticData> =
|
|
31
|
-
Omit<
|
|
32
|
-
MutationOptions<
|
|
33
|
-
TData,
|
|
34
|
-
Error,
|
|
35
|
-
TVariables,
|
|
36
|
-
MutationContext<TOptimisticData>
|
|
37
|
-
>,
|
|
38
|
-
"onSuccess" | "onError" | "onMutate" | "onSettled"
|
|
39
|
-
> & {
|
|
40
|
-
/** Query keys to invalidate once the mutation settles, win or lose. */
|
|
41
|
-
invalidates?: QueryKey[]
|
|
42
|
-
optimisticUpdate?: OptimisticUpdate<
|
|
43
|
-
TOptimisticData,
|
|
44
|
-
TVariables
|
|
45
|
-
>
|
|
46
|
-
successMessage?:
|
|
47
|
-
| string
|
|
48
|
-
| ((
|
|
49
|
-
data: NoInfer<TData>,
|
|
50
|
-
variables: NoInfer<TVariables>
|
|
51
|
-
) => string)
|
|
52
|
-
successDescription?:
|
|
53
|
-
| string
|
|
54
|
-
| ((
|
|
55
|
-
data: NoInfer<TData>,
|
|
56
|
-
variables: NoInfer<TVariables>
|
|
57
|
-
) => string | undefined)
|
|
58
|
-
errorMessage?: string
|
|
59
|
-
onSuccess?: (
|
|
60
|
-
data: NoInfer<TData>,
|
|
61
|
-
variables: NoInfer<TVariables>
|
|
62
|
-
) => void
|
|
63
|
-
onError?: (
|
|
64
|
-
error: Error,
|
|
65
|
-
variables: NoInfer<TVariables>
|
|
66
|
-
) => void
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// every domain mutation hook in both infra and www builds on this instead
|
|
70
|
-
// of calling useMutation directly; optimisticUpdate's rollback only
|
|
71
|
-
// restores the snapshot if nothing else wrote to the same queryKey in the
|
|
72
|
-
// meantime
|
|
73
|
-
export function useAppMutation<
|
|
74
|
-
TData,
|
|
75
|
-
TVariables = void,
|
|
76
|
-
TOptimisticData = unknown,
|
|
77
|
-
>(
|
|
78
|
-
getOptions: () => AppMutationOptions<
|
|
79
|
-
TData,
|
|
80
|
-
TVariables,
|
|
81
|
-
TOptimisticData
|
|
82
|
-
>
|
|
83
|
-
) {
|
|
84
|
-
const q = useQueryClient()
|
|
85
|
-
return useMutation<
|
|
86
|
-
TData,
|
|
87
|
-
Error,
|
|
88
|
-
TVariables,
|
|
89
|
-
MutationContext<TOptimisticData>
|
|
90
|
-
>(() => {
|
|
91
|
-
const {
|
|
92
|
-
invalidates = [],
|
|
93
|
-
optimisticUpdate,
|
|
94
|
-
successMessage,
|
|
95
|
-
successDescription,
|
|
96
|
-
errorMessage,
|
|
97
|
-
onSuccess,
|
|
98
|
-
onError,
|
|
99
|
-
...options
|
|
100
|
-
} = getOptions()
|
|
101
|
-
return {
|
|
102
|
-
...options,
|
|
103
|
-
onMutate: async (variables) => {
|
|
104
|
-
if (!optimisticUpdate) return undefined
|
|
105
|
-
const { queryKey, updater } = optimisticUpdate
|
|
106
|
-
await q.cancelQueries({ queryKey })
|
|
107
|
-
const previous =
|
|
108
|
-
q.getQueryData<TOptimisticData>(queryKey)
|
|
109
|
-
const next = updater(previous, variables)
|
|
110
|
-
q.setQueryData<TOptimisticData>(
|
|
111
|
-
queryKey,
|
|
112
|
-
next
|
|
113
|
-
)
|
|
114
|
-
return { previous, next }
|
|
115
|
-
},
|
|
116
|
-
onSuccess: (data, variables) => {
|
|
117
|
-
if (successMessage) {
|
|
118
|
-
toast.success(
|
|
119
|
-
typeof successMessage === "function"
|
|
120
|
-
? successMessage(data, variables)
|
|
121
|
-
: successMessage,
|
|
122
|
-
{
|
|
123
|
-
description:
|
|
124
|
-
typeof successDescription ===
|
|
125
|
-
"function"
|
|
126
|
-
? successDescription(
|
|
127
|
-
data,
|
|
128
|
-
variables
|
|
129
|
-
)
|
|
130
|
-
: successDescription,
|
|
131
|
-
}
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
onSuccess?.(data, variables)
|
|
135
|
-
},
|
|
136
|
-
onError: (error, variables, context) => {
|
|
137
|
-
if (optimisticUpdate && context) {
|
|
138
|
-
const current = q.getQueryData(
|
|
139
|
-
optimisticUpdate.queryKey
|
|
140
|
-
)
|
|
141
|
-
// only roll back if nothing else has written to this key
|
|
142
|
-
// since our optimistic value landed, otherwise this would
|
|
143
|
-
// silently discard a concurrent mutation's newer change
|
|
144
|
-
if (
|
|
145
|
-
shouldRestoreOptimisticSnapshot(
|
|
146
|
-
current,
|
|
147
|
-
context.next
|
|
148
|
-
)
|
|
149
|
-
) {
|
|
150
|
-
q.setQueryData(
|
|
151
|
-
optimisticUpdate.queryKey,
|
|
152
|
-
context.previous
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
toast.error(
|
|
157
|
-
errorMessage ?? "Something went wrong",
|
|
158
|
-
{
|
|
159
|
-
description: error.message,
|
|
160
|
-
}
|
|
161
|
-
)
|
|
162
|
-
onError?.(error, variables)
|
|
163
|
-
},
|
|
164
|
-
onSettled: () => {
|
|
165
|
-
for (const queryKey of invalidates) {
|
|
166
|
-
void q.invalidateQueries({ queryKey })
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
}
|
|
170
|
-
})
|
|
171
|
-
}
|