@passui/tanstack 0.1.2 → 0.2.1

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 (70) hide show
  1. package/README.md +56 -32
  2. package/dist/client/chunks/form-fields-DlWu70u5.js +630 -0
  3. package/dist/client/src/solid/auth-shell/index.js +28 -0
  4. package/dist/client/src/solid/document/index.js +51 -0
  5. package/dist/client/src/solid/form-fields/index.js +1 -0
  6. package/dist/client/src/solid/forms/index.js +33 -0
  7. package/dist/client/src/solid/mutation/index.js +46 -0
  8. package/dist/client/src/solid/route-boundary/index.js +73 -0
  9. package/dist/client/src/solid/settings/index.js +173 -0
  10. package/dist/client/src/solid/tables/index.js +500 -0
  11. package/dist/server/src/solid/auth-shell/index.js +28 -0
  12. package/dist/server/src/solid/document/index.js +55 -0
  13. package/dist/server/src/solid/form-fields/index.js +598 -0
  14. package/dist/server/src/solid/forms/index.js +33 -0
  15. package/dist/server/src/solid/mutation/index.js +46 -0
  16. package/dist/server/src/solid/route-boundary/index.js +73 -0
  17. package/dist/server/src/solid/settings/index.js +169 -0
  18. package/dist/server/src/solid/tables/index.js +480 -0
  19. package/dist/types/src/shared/optimistic.d.ts +2 -0
  20. package/dist/types/src/solid/auth-shell/auth-shell.d.ts +4 -0
  21. package/dist/types/src/solid/auth-shell/index.d.ts +1 -0
  22. package/dist/types/src/solid/document/compose-viewport.d.ts +14 -0
  23. package/dist/types/src/solid/document/index.d.ts +1 -0
  24. package/dist/types/src/solid/form-fields/avatar.d.ts +26 -0
  25. package/dist/types/src/solid/form-fields/fields.d.ts +45 -0
  26. package/dist/types/src/solid/form-fields/index.d.ts +3 -0
  27. package/dist/types/src/solid/form-fields/submit.d.ts +3 -0
  28. package/dist/types/src/solid/forms/contexts.d.ts +1 -0
  29. package/dist/types/src/solid/forms/form-alert.d.ts +6 -0
  30. package/dist/types/src/solid/forms/index.d.ts +43 -0
  31. package/dist/types/src/solid/mutation/index.d.ts +1 -0
  32. package/dist/types/src/solid/mutation/use-app-mutation.d.ts +22 -0
  33. package/dist/types/src/solid/route-boundary/boundaries.d.ts +8 -0
  34. package/dist/types/src/solid/route-boundary/index.d.ts +1 -0
  35. package/dist/types/src/solid/settings/index.d.ts +1 -0
  36. package/dist/types/src/solid/settings/setting-list.d.ts +37 -0
  37. package/dist/types/src/solid/tables/columns.d.ts +4 -0
  38. package/dist/types/src/solid/tables/data-table.d.ts +58 -0
  39. package/dist/types/src/solid/tables/filter-row.d.ts +9 -0
  40. package/dist/types/src/solid/tables/index.d.ts +4 -0
  41. package/dist/types/src/solid/tables/pagination.d.ts +7 -0
  42. package/package.json +154 -13
  43. package/src/mutation/use-app-mutation.ts +2 -6
  44. package/src/shared/index.ts +2 -0
  45. package/src/shared/optimistic.ts +7 -0
  46. package/src/shared/table.ts +30 -0
  47. package/src/solid/auth-shell/auth-shell.tsx +20 -0
  48. package/src/solid/auth-shell/index.ts +1 -0
  49. package/src/solid/document/compose-viewport.tsx +69 -0
  50. package/src/solid/document/index.ts +1 -0
  51. package/src/solid/form-fields/avatar.tsx +370 -0
  52. package/src/solid/form-fields/fields.tsx +336 -0
  53. package/src/solid/form-fields/index.ts +3 -0
  54. package/src/solid/form-fields/submit.tsx +31 -0
  55. package/src/solid/forms/contexts.ts +7 -0
  56. package/src/solid/forms/form-alert.tsx +19 -0
  57. package/src/solid/forms/index.ts +32 -0
  58. package/src/solid/mutation/index.ts +5 -0
  59. package/src/solid/mutation/use-app-mutation.ts +171 -0
  60. package/src/solid/route-boundary/boundaries.tsx +104 -0
  61. package/src/solid/route-boundary/index.ts +1 -0
  62. package/src/solid/settings/index.ts +1 -0
  63. package/src/solid/settings/setting-list.tsx +185 -0
  64. package/src/solid/styles.css +2 -0
  65. package/src/solid/tables/columns.tsx +40 -0
  66. package/src/solid/tables/data-table.tsx +448 -0
  67. package/src/solid/tables/filter-row.tsx +161 -0
  68. package/src/solid/tables/index.ts +4 -0
  69. package/src/solid/tables/pagination.tsx +78 -0
  70. package/src/tables/utils.ts +5 -35
@@ -0,0 +1,31 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ import { createFormHookContexts } from "@tanstack/solid-form"
2
+ export const {
3
+ fieldContext,
4
+ formContext,
5
+ useFieldContext,
6
+ useFormContext,
7
+ } = createFormHookContexts()
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,32 @@
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"
@@ -0,0 +1,5 @@
1
+ export {
2
+ useAppMutation,
3
+ useAppMutation as createAppMutation,
4
+ shouldRestoreOptimisticSnapshot,
5
+ } from "./use-app-mutation"
@@ -0,0 +1,171 @@
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
+ }
@@ -0,0 +1,104 @@
1
+ /** @jsxImportSource solid-js */
2
+ import { Show, type JSX } from "solid-js"
3
+ import {
4
+ Link,
5
+ ErrorComponent,
6
+ useRouter,
7
+ useLocation,
8
+ type ErrorComponentProps,
9
+ } from "@tanstack/solid-router"
10
+ import { Button, buttonStyle } from "@passui/solid/button"
11
+ export function DefaultLoader() {
12
+ return (
13
+ <section class="flex h-screen w-screen items-center justify-center bg-background">
14
+ <span
15
+ role="progressbar"
16
+ class="size-5 animate-spin rounded-full border-2 border-current border-r-transparent"
17
+ />
18
+ </section>
19
+ )
20
+ }
21
+ export function DefaultBoundary(props: ErrorComponentProps) {
22
+ const router = useRouter(),
23
+ isRoot = useLocation({
24
+ select: (location) => location.pathname === "/",
25
+ })
26
+ return (
27
+ <div class="flex min-h-100 w-full flex-col items-center justify-center gap-6 p-6 text-center">
28
+ <div class="w-full max-w-md overflow-hidden rounded-md border border-danger/20 bg-danger/5 p-4 text-start">
29
+ <p class="mb-2 text-caption font-semibold text-danger">
30
+ Application Error
31
+ </p>
32
+ <ErrorComponent error={props.error} />
33
+ </div>
34
+ <div class="flex flex-wrap justify-center gap-2">
35
+ <Button
36
+ onClick={() => router.invalidate()}
37
+ variant="secondary"
38
+ size="sm"
39
+ >
40
+ Try Again
41
+ </Button>
42
+ <Show
43
+ when={isRoot()}
44
+ fallback={
45
+ <Button
46
+ onClick={() =>
47
+ router.history.back()
48
+ }
49
+ size="sm"
50
+ >
51
+ Go Back
52
+ </Button>
53
+ }
54
+ >
55
+ <Link
56
+ to="/"
57
+ class={buttonStyle({ size: "sm" })}
58
+ >
59
+ Go Home
60
+ </Link>
61
+ </Show>
62
+ </div>
63
+ </div>
64
+ )
65
+ }
66
+ export function NotFound(props: { children?: JSX.Element }) {
67
+ const router = useRouter()
68
+ return (
69
+ <div class="flex min-h-[80svh] w-full items-center justify-center text-center">
70
+ <section class="mx-auto flex w-full max-w-sm flex-col items-center gap-4">
71
+ {props.children ?? (
72
+ <div class="flex flex-col gap-2">
73
+ <span class="font-mono text-caption text-danger">
74
+ Error 404
75
+ </span>
76
+ <h2 class="text-title2 font-bold">
77
+ Page Not Found
78
+ </h2>
79
+ <p class="text-subheadline text-label-secondary">
80
+ The page you are looking for might
81
+ have been moved, renamed, or
82
+ deleted.
83
+ </p>
84
+ </div>
85
+ )}
86
+ <div class="mt-2 flex gap-2">
87
+ <Button
88
+ onClick={() => router.history.back()}
89
+ variant="secondary"
90
+ size="sm"
91
+ >
92
+ Go back
93
+ </Button>
94
+ <Link
95
+ to="/"
96
+ class={buttonStyle({ size: "sm" })}
97
+ >
98
+ Start Over
99
+ </Link>
100
+ </div>
101
+ </section>
102
+ </div>
103
+ )
104
+ }
@@ -0,0 +1 @@
1
+ export * from "./boundaries"
@@ -0,0 +1 @@
1
+ export * from "./setting-list"
@@ -0,0 +1,185 @@
1
+ /** @jsxImportSource solid-js */
2
+ import {
3
+ createSignal,
4
+ onCleanup,
5
+ Show,
6
+ type JSX,
7
+ } from "solid-js"
8
+ import { Dynamic } from "solid-js/web"
9
+ import { Link, type LinkProps } from "@tanstack/solid-router"
10
+ import { cn } from "@passui/solid/cn"
11
+ import {
12
+ IconButton,
13
+ type IconButtonSize,
14
+ } from "@passui/solid/icon-button"
15
+ function Row(props: {
16
+ icon?: JSX.Element
17
+ title: JSX.Element
18
+ description?: JSX.Element
19
+ value?: JSX.Element
20
+ trailing?: JSX.Element
21
+ to?: LinkProps["to"]
22
+ params?: LinkProps["params"]
23
+ hash?: string
24
+ onClick?: () => void
25
+ chevron?: boolean
26
+ tone?: "default" | "destructive"
27
+ }) {
28
+ const style = () =>
29
+ cn(
30
+ "setting-row flex min-h-10 w-full items-center gap-3 px-3.5 py-1.5 text-start",
31
+ (props.to || props.onClick) &&
32
+ "cursor-pointer hover:bg-fill focus-visible:bg-fill",
33
+ props.tone === "destructive" &&
34
+ "[&_h3]:text-danger"
35
+ )
36
+ const body = () => (
37
+ <>
38
+ {props.icon}
39
+ <span class="flex min-w-0 flex-1 flex-col">
40
+ <h3 class="truncate text-subheadline">
41
+ {props.title}
42
+ </h3>
43
+ <Show when={props.description}>
44
+ <p class="text-footnote text-label-secondary">
45
+ {props.description}
46
+ </p>
47
+ </Show>
48
+ </span>
49
+ <Show when={props.value}>
50
+ <span class="max-w-[45%] truncate text-subheadline text-label-secondary">
51
+ {props.value}
52
+ </span>
53
+ </Show>
54
+ {props.trailing}
55
+ <Show
56
+ when={
57
+ props.chevron ??
58
+ Boolean(props.to || props.onClick)
59
+ }
60
+ >
61
+ <span
62
+ aria-hidden="true"
63
+ class="text-label-tertiary"
64
+ >
65
+ ›
66
+ </span>
67
+ </Show>
68
+ </>
69
+ )
70
+ return (
71
+ <Show
72
+ when={props.to}
73
+ fallback={
74
+ <Dynamic
75
+ component={
76
+ props.onClick ? "button" : "div"
77
+ }
78
+ type={
79
+ props.onClick ? "button" : undefined
80
+ }
81
+ onClick={() => props.onClick?.()}
82
+ class={style()}
83
+ >
84
+ {body()}
85
+ </Dynamic>
86
+ }
87
+ >
88
+ <Link
89
+ to={props.to}
90
+ params={props.params}
91
+ hash={props.hash}
92
+ class={style()}
93
+ >
94
+ {body()}
95
+ </Link>
96
+ </Show>
97
+ )
98
+ }
99
+ function Copy(props: {
100
+ value: string
101
+ label?: string
102
+ size?: IconButtonSize
103
+ }) {
104
+ const [copied, setCopied] = createSignal(false)
105
+ let timer: ReturnType<typeof setTimeout> | undefined
106
+ onCleanup(() => clearTimeout(timer))
107
+ return (
108
+ <IconButton
109
+ variant="ghost"
110
+ size={props.size ?? "icon-xs"}
111
+ label={props.label ?? "Copy"}
112
+ onClick={async (event) => {
113
+ event.stopPropagation()
114
+ await navigator.clipboard.writeText(
115
+ props.value
116
+ )
117
+ setCopied(true)
118
+ clearTimeout(timer)
119
+ timer = setTimeout(
120
+ () => setCopied(false),
121
+ 1500
122
+ )
123
+ }}
124
+ >
125
+ <span aria-hidden="true">
126
+ {copied() ? "✓" : "⧉"}
127
+ </span>
128
+ </IconButton>
129
+ )
130
+ }
131
+ export const SettingList = Object.assign(
132
+ function SettingList(props: {
133
+ id?: string
134
+ as?: "h2" | "h3"
135
+ icon?: JSX.Element
136
+ title?: string
137
+ description?: string
138
+ action?: JSX.Element
139
+ variant?: "inset" | "tile"
140
+ children: JSX.Element
141
+ className?: string
142
+ }) {
143
+ return (
144
+ <section
145
+ id={props.id}
146
+ class={cn(
147
+ "flex scroll-mt-20 flex-col gap-3 [&_.setting-row]:min-h-16 [&_.setting-row]:px-4 [&_.setting-row]:py-3",
148
+ props.variant === "tile" &&
149
+ "overflow-hidden rounded-3xl border border-separator/70 bg-elevated shadow-sm",
150
+ props.className
151
+ )}
152
+ >
153
+ <Show when={props.title}>
154
+ <div
155
+ class={cn(
156
+ "flex items-start gap-3",
157
+ props.variant === "tile" &&
158
+ "border-b border-separator/60 px-4 py-4"
159
+ )}
160
+ >
161
+ {props.icon}
162
+ <div class="min-w-0 flex-1">
163
+ <Dynamic
164
+ component={props.as ?? "h2"}
165
+ class="text-subheadline font-semibold"
166
+ >
167
+ {props.title}
168
+ </Dynamic>
169
+ <Show when={props.description}>
170
+ <p class="text-footnote text-label-secondary">
171
+ {props.description}
172
+ </p>
173
+ </Show>
174
+ </div>
175
+ {props.action}
176
+ </div>
177
+ </Show>
178
+ <div class="flex flex-col overflow-hidden rounded-2xl border border-separator/35 bg-elevated [&>*+*]:border-t [&>*+*]:border-separator/40">
179
+ {props.children}
180
+ </div>
181
+ </section>
182
+ )
183
+ },
184
+ { Row, Copy }
185
+ )
@@ -0,0 +1,2 @@
1
+ @import "@passui/solid/styles.css";
2
+ @source "./";
@@ -0,0 +1,40 @@
1
+ /** @jsxImportSource solid-js */
2
+ import type { RowData } from "@tanstack/solid-table"
3
+ import { Toggle } from "@passui/solid/toggle"
4
+ import type { DataTableColumnDef } from "./data-table"
5
+
6
+ export function selectColumn<
7
+ TData extends RowData,
8
+ >(): DataTableColumnDef<TData> {
9
+ return {
10
+ id: "select",
11
+ enableColumnFilter: false,
12
+ enableGlobalFilter: false,
13
+ header: ({ table }) => (
14
+ <Toggle
15
+ style="checkbox"
16
+ labelHidden
17
+ checked={table.getIsAllPageRowsSelected()}
18
+ mixed={
19
+ table.getIsSomePageRowsSelected() &&
20
+ !table.getIsAllPageRowsSelected()
21
+ }
22
+ onChange={(checked) =>
23
+ table.toggleAllPageRowsSelected(checked)
24
+ }
25
+ label="Select all"
26
+ />
27
+ ),
28
+ cell: ({ row }) => (
29
+ <Toggle
30
+ style="checkbox"
31
+ labelHidden
32
+ checked={row.getIsSelected()}
33
+ onChange={(checked) =>
34
+ row.toggleSelected(checked)
35
+ }
36
+ label="Select row"
37
+ />
38
+ ),
39
+ }
40
+ }