formstand 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +186 -0
- package/README.md +7 -1
- package/dist/{createForm-BexUOCjZ.d.cts → createForm-CMVALnc3.d.cts} +1 -1
- package/dist/{createForm-BexUOCjZ.d.ts → createForm-CMVALnc3.d.ts} +1 -1
- package/dist/devtools/index.cjs +4 -1
- package/dist/devtools/index.cjs.map +1 -1
- package/dist/devtools/index.d.cts +9 -1
- package/dist/devtools/index.d.ts +9 -1
- package/dist/devtools/index.js +4 -1
- package/dist/devtools/index.js.map +1 -1
- package/dist/index.cjs +37 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -20
- package/dist/index.d.ts +36 -20
- package/dist/index.js +37 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,191 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.25.0 — 2026-11-12
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `useVariantFieldArray(form, unionPath, field)`, the array twin of
|
|
8
|
+
`useVariantField`: a `z.array` that lives in one variant of a
|
|
9
|
+
discriminated union sits at a path `useFieldArray` cannot take, since
|
|
10
|
+
`FieldPath` on a union offers only the keys every variant shares. The
|
|
11
|
+
hook binds `${unionPath}.${field}` and types the rows from the variants
|
|
12
|
+
that declare the array; `field` is a variant sub-path (`"lights"`,
|
|
13
|
+
`"spec.lights"`, or a row template for an array nested in another
|
|
14
|
+
variant array's rows), and a common-key array stays with plain
|
|
15
|
+
`useFieldArray`, which the variant hook rejects. Same return as
|
|
16
|
+
`useFieldArray`, row ids included. `createFormHooks` gains the bound
|
|
17
|
+
`use{Name}VariantFieldArray`, and the type `VariantArrayFieldPath` is
|
|
18
|
+
exported. formstand-cli emits it for arrays inside union variants.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- `createFormHooks(createForm(schema, options), name)` with the form
|
|
23
|
+
created inline collapsed every depth-typed bound hook (`useXField`,
|
|
24
|
+
`useXFieldArray`, `useXIsDirty`) to a `never` path: the inner call
|
|
25
|
+
inferred its depth from the outer call's still-unresolved depth
|
|
26
|
+
parameter, so the depth became the whole budget union. `createForm` and
|
|
27
|
+
`useForm` now take their depth from `pathDepth` alone (`NoInfer` on the
|
|
28
|
+
returned form), so the inline shape types like the const-form shape the
|
|
29
|
+
docs show, and an explicit `pathDepth` still infers its literal.
|
|
30
|
+
|
|
31
|
+
## formstand-cli 0.26.0 — 2026-11-12
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- An **array inside a union variant** generates instead of degrading to a
|
|
36
|
+
TODO, in both layouts and every kit: a `{Stem}Rows` component on
|
|
37
|
+
`useVariantFieldArray(form, unionPath, "lights")` (formstand 0.25), its
|
|
38
|
+
row leaves on the variant path (the Bound components in the single-file
|
|
39
|
+
layout, `useVariantField` on a row template in the module layout), the
|
|
40
|
+
empty item typed from the hook, and deeper lists under those rows bound
|
|
41
|
+
the same way. Under a union row item the row's own index renames to the
|
|
42
|
+
next hole for the extracted component, as nested lists already do. Still
|
|
43
|
+
a TODO: a union inside a variant, a union or tuple inside a variant
|
|
44
|
+
array's rows, and an array every variant shares (a plain path, left to
|
|
45
|
+
`useFieldArray`). Generated output with a variant array needs formstand
|
|
46
|
+
0.25 or newer.
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
- **Arrays of flat object rows generate as tables.** Where every row
|
|
51
|
+
field is a scalar within the path budget and none carries a component
|
|
52
|
+
override, the array renders as a table in both layouts and every kit:
|
|
53
|
+
one column per row field with
|
|
54
|
+
the label in the header (a description becomes the header's title), a
|
|
55
|
+
`{Stem}Row` component per row binding each cell from hoisted `useField`
|
|
56
|
+
hooks (`useVariantField` for an array inside a union variant) and
|
|
57
|
+
naming the control through `aria-label`, a Remove column, and the
|
|
58
|
+
array-level error plus the Add button under the table. antd's
|
|
59
|
+
data-driven `Table` gets one cell component per column. Rows holding a
|
|
60
|
+
container, scalar rows and rows with an overridden field keep the
|
|
61
|
+
cards, and the new `fields: { "<path>": { layout: "cards" } }` opts a
|
|
62
|
+
flat array back out; `layout: "table"` asserts one and errors, naming
|
|
63
|
+
the row field, where it cannot be built.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- The single-file layout's TODO for a container that still degrades inside
|
|
68
|
+
a row union's variant printed the hole-stripped naming path
|
|
69
|
+
(`"pavements.sub"`), which names no field a reader can find. It prints
|
|
70
|
+
the row template (`"pavements.${index}.sub"`), as the module layout
|
|
71
|
+
already did.
|
|
72
|
+
- Two usage walks passed the wrong budget when descending into an
|
|
73
|
+
array's rows, so anything two objects deep under a row was skipped: a
|
|
74
|
+
discriminated union there rendered its variant controls without
|
|
75
|
+
importing the prop builders they call, and a described leaf there was
|
|
76
|
+
handed a `description` prop the Bound components did not declare.
|
|
77
|
+
Both walks carry the real budget now.
|
|
78
|
+
|
|
79
|
+
## 0.24.0 — 2026-10-23
|
|
80
|
+
|
|
81
|
+
### Added
|
|
82
|
+
|
|
83
|
+
- `FormstandDevtools` takes `enabled`, an override for the build gate in
|
|
84
|
+
either direction: `true` mounts the panel in a production build, for a
|
|
85
|
+
page whose purpose is showing the form state; `false` hides it in
|
|
86
|
+
development. Unset keeps the gate, which is what an app wants.
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
|
|
90
|
+
- The container rule for absent slots (0.23.0) stood on the introspection
|
|
91
|
+
walk, which reads a union's key from the first member that declares it,
|
|
92
|
+
so a `z.discriminatedUnion` whose variants declare the same key as an
|
|
93
|
+
object and as an array made every write create the first variant's
|
|
94
|
+
record, and the array variant then failed its own validation. The rule
|
|
95
|
+
now has no opinion wherever a union sits on the path, and the segment
|
|
96
|
+
type decides there, as the typed-paths guide already said.
|
|
97
|
+
|
|
98
|
+
### Internal
|
|
99
|
+
|
|
100
|
+
- The root `overrides` pin vite 6.4 and esbuild 0.25 under VitePress 1, in
|
|
101
|
+
place of the esbuild-only pin. Vite 5 has no release for the three
|
|
102
|
+
launch-editor advisories and VitePress 1 pins `^5.4`; its Vue plugin
|
|
103
|
+
accepts vite 6, and the docs build, link check, painted pages and dev
|
|
104
|
+
server all pass under it. Clears the root audit. Goes with VitePress 2.
|
|
105
|
+
- CI typechecks the core and the hooks with `lib: ["ES2022"]` and no DOM
|
|
106
|
+
types (`npm run typecheck:nodom`), against a declaration of the only
|
|
107
|
+
host globals they use; a DOM call reaching the core fails there.
|
|
108
|
+
- CI budgets the gzip size of the library's three entries and the
|
|
109
|
+
playground's main chunk and stylesheet (`scripts/check-bundle-size.mjs`),
|
|
110
|
+
a few percent above measured, so a bundle cannot regrow unnoticed.
|
|
111
|
+
|
|
112
|
+
### Docs
|
|
113
|
+
|
|
114
|
+
- "Public API and stability": which exports of `formstand`,
|
|
115
|
+
`formstand/testing`, `formstand/devtools`, `formstand-cli` and
|
|
116
|
+
`formstand-cli/codegen` are the contract (listed from the built
|
|
117
|
+
declarations), what is internal and may move in a minor, the optional
|
|
118
|
+
member rule of the structural form contracts, the stable parts of
|
|
119
|
+
generated code, how semver is applied, and the deprecation policy. The
|
|
120
|
+
roadmap's 1.0 criteria point at it.
|
|
121
|
+
- "Messages and localization": messages are strings the schema owns;
|
|
122
|
+
per-check `error` text, zod's locales and `customError` for a whole app,
|
|
123
|
+
stable keys translated at render, and the fact that the generator's
|
|
124
|
+
emitted checks carry no messages. The errors guide links it.
|
|
125
|
+
- A Next.js example at `examples/next`: an app router page whose client
|
|
126
|
+
form submits through `useFormActionState` to a `"use server"` action
|
|
127
|
+
that re-parses the payload with the same zod schema before doing
|
|
128
|
+
anything, with the rejection path shown end to end. CI builds it with
|
|
129
|
+
`next build` against the published package; the suite renders the form
|
|
130
|
+
and runs the action in-process against the source. The SSR guide's form
|
|
131
|
+
actions section and the examples page link it.
|
|
132
|
+
- A starter template at `templates/vite-react`: Vite, React 19, zod,
|
|
133
|
+
zustand, formstand's bound components on one schema, and formstand-cli
|
|
134
|
+
as a dev dependency with an `npm run generate` script. Getting started
|
|
135
|
+
and the README point at it with one `npx degit` line. CI installs and
|
|
136
|
+
builds it against the published packages; the suite renders its form
|
|
137
|
+
against the source.
|
|
138
|
+
- SSR guide: a "React Native and other DOM-free runtimes" section states
|
|
139
|
+
the split the CI check enforces (core and hooks DOM-free; the bound
|
|
140
|
+
components, prop builders, masked and number inputs, focus helpers and
|
|
141
|
+
the devtools panel are DOM-only), shows a `TextInput` binding, and
|
|
142
|
+
names the two caveats: `persistForm` wants a synchronous storage, and
|
|
143
|
+
the statement is a typecheck plus a Node import, not a shipped Expo app.
|
|
144
|
+
- CLI: "Adding a UI kit", the contributor's checklist for a new `--ui`
|
|
145
|
+
backend: the `UiTarget` parser and its refusal rules, the adapter
|
|
146
|
+
helpers and `Backend` record in codegen.ts, the module layout's kit
|
|
147
|
+
arms, the structural stub the typecheck tests map in, the playground
|
|
148
|
+
tab and regeneration script, the matrix alias and probe, and the docs
|
|
149
|
+
rows, with the antd backend named as the reference at each step. Linked
|
|
150
|
+
from the UI kits page, the CLI index and the CLI README.
|
|
151
|
+
- The introduction states that formstand is zod only, by decision: the
|
|
152
|
+
typed paths, the introspection, the field-scoped fast path and the
|
|
153
|
+
generator read zod's own schema tree, so a Standard Schema adapter
|
|
154
|
+
would keep validation and lose the rest. Getting started repeats it
|
|
155
|
+
next to the peer ranges, and the roadmap records the decision and what
|
|
156
|
+
would reopen it.
|
|
157
|
+
- Recipes: "Several async checks at once" shows the form-level
|
|
158
|
+
`useIsValidating(form)` line, the submit gated on it, why `form.submit`
|
|
159
|
+
cannot race a debounced check, and when to settle a batch with
|
|
160
|
+
`validateFieldsAsync`; the validation guide's race section links it.
|
|
161
|
+
The playground's Async demo gains a second async field with a different
|
|
162
|
+
latency, the form-level line, and the gated submit.
|
|
163
|
+
- Playground: a Devtools tab mounts `formstand/devtools` next to a form
|
|
164
|
+
built to fill every panel section (a root `refine`, an array rule, a
|
|
165
|
+
server error button), so the panel can be tried without installing. The
|
|
166
|
+
devtools guide links it and documents `enabled`.
|
|
167
|
+
|
|
168
|
+
## formstand-cli 0.25.0 — 2026-10-23
|
|
169
|
+
|
|
170
|
+
### Added
|
|
171
|
+
|
|
172
|
+
- `--json`: a machine-readable run. The same generation, then exactly one
|
|
173
|
+
JSON document on stdout and nothing on stderr: `{ ok, files: [{ path,
|
|
174
|
+
content, written }], notes, error? }`. Files are written under `--out`
|
|
175
|
+
as before (`written: true`, path relative to the working directory) and
|
|
176
|
+
only described without it (`written: false`, the path `--out` would
|
|
177
|
+
have used); warnings become `notes`; a failed run keeps its exit code
|
|
178
|
+
and carries the error text. Not with `--watch`; `--help` stays text.
|
|
179
|
+
- `--manifest`: the generator described as data (inputs, every flag and
|
|
180
|
+
whether it takes a value, the kits with the MUI majors, layouts, section
|
|
181
|
+
styles, columns, test runners, the `--json` document shape), derived
|
|
182
|
+
from the parser's own constants. Runs alone. Together these are the
|
|
183
|
+
agent-facing surface of formstand-cli; the MCP server that would wrap
|
|
184
|
+
them belongs to generators-for-ai. One `--json` run per process at a
|
|
185
|
+
time: a second run started while one is in flight (an in-process caller)
|
|
186
|
+
refuses with its own document instead of pouring its files into the
|
|
187
|
+
first; `--manifest --json` refuses as a document too.
|
|
188
|
+
|
|
3
189
|
## 0.23.0 — 2026-10-22
|
|
4
190
|
|
|
5
191
|
### Added
|
package/README.md
CHANGED
|
@@ -30,6 +30,12 @@ npm install formstand zustand zod react
|
|
|
30
30
|
|
|
31
31
|
Peer-dep ranges: `zod ^4.2`, `zustand ^5.0`, `react ^19.0`.
|
|
32
32
|
|
|
33
|
+
Or start from the Vite + React template, one schema-driven form with the CLI wired in:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx degit Scrumrot/formstand/templates/vite-react my-form-app
|
|
37
|
+
```
|
|
38
|
+
|
|
33
39
|
## Quickstart
|
|
34
40
|
|
|
35
41
|
```tsx
|
|
@@ -117,7 +123,7 @@ PATCH-ready payload of exactly what changed.
|
|
|
117
123
|
| Area | What's there | Docs |
|
|
118
124
|
| --- | --- | --- |
|
|
119
125
|
| Form instance | `createForm`, `setValue`/`setValues`, `reset`/`resetField`/`adoptValues`, `submit`/`handleSubmit`, `diff`/`dirtyFields`, `snapshot`/`restore`, array ops | [createForm & Form](https://scrumrot.github.io/formstand/documentation/api/) |
|
|
120
|
-
| Hooks | `useForm`, `useField`, `useFieldArray`, `useVariantField`, `useFormSelector`, `useFormValues`, the flag hooks, `createFormContext`, `createFormHooks` | [Hooks](https://scrumrot.github.io/formstand/documentation/api/hooks) |
|
|
126
|
+
| Hooks | `useForm`, `useField`, `useFieldArray`, `useVariantField`, `useVariantFieldArray`, `useFormSelector`, `useFormValues`, the flag hooks, `createFormContext`, `createFormHooks` | [Hooks](https://scrumrot.github.io/formstand/documentation/api/hooks) |
|
|
121
127
|
| Components | `TextField`, `NumberField`, `DateField`, `CheckboxField`, `SelectField`, the prop builders, `useNumberInput`, `focusField`/`focusFirstError` | [Components & bindings](https://scrumrot.github.io/formstand/documentation/api/components) |
|
|
122
128
|
| Validation | five modes plus `reValidateMode`, field-scoped passes, async refines with race handling, per-field `debounceMs` | [Validation](https://scrumrot.github.io/formstand/documentation/validation) |
|
|
123
129
|
| Utilities | `parsePath`/`getAtPath`/`setAtPath`, `validateSync`/`validateAsync`, `persistForm`, and the full type list | [Utilities & types](https://scrumrot.github.io/formstand/documentation/api/utilities) |
|
|
@@ -202,7 +202,7 @@ type Form<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = R
|
|
|
202
202
|
snapshot: () => FormState<z.input<TSchema>>;
|
|
203
203
|
restore: (snapshot: FormState<z.input<TSchema>>) => void;
|
|
204
204
|
}>;
|
|
205
|
-
declare const createForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D
|
|
205
|
+
declare const createForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, NoInfer<D>>;
|
|
206
206
|
|
|
207
207
|
export { createForm as p, emptyValueForSchema as q, flattenIssues as r, isAsyncRequiredError as s, isClearableSchema as t, shouldValidateOn as u, validateAsync as v, validateSync as w };
|
|
208
208
|
export type { ArrayFieldPath as A, BoolMap as B, CreateFormOptions as C, DefaultPathDepth as D, ErrorMap as E, Form as F, InvalidSubmitHandler as I, PathDepth as P, ReadonlyStoreApi as R, SettledFieldValidationResult as S, ValidationMode as V, FormState as a, FieldValidationResult as b, FieldPath as c, FieldValue as d, ArrayItemOf as e, FieldSnapshot as f, FieldsValidationResult as g, ResetOptions as h, SettledFieldsValidationResult as i, SettledValidationResult as j, SubmitHandler as k, SubmitOptions as l, SubmitResult as m, ValidationResult as n, ValidationTrigger as o };
|
|
@@ -202,7 +202,7 @@ type Form<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = R
|
|
|
202
202
|
snapshot: () => FormState<z.input<TSchema>>;
|
|
203
203
|
restore: (snapshot: FormState<z.input<TSchema>>) => void;
|
|
204
204
|
}>;
|
|
205
|
-
declare const createForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D
|
|
205
|
+
declare const createForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, NoInfer<D>>;
|
|
206
206
|
|
|
207
207
|
export { createForm as p, emptyValueForSchema as q, flattenIssues as r, isAsyncRequiredError as s, isClearableSchema as t, shouldValidateOn as u, validateAsync as v, validateSync as w };
|
|
208
208
|
export type { ArrayFieldPath as A, BoolMap as B, CreateFormOptions as C, DefaultPathDepth as D, ErrorMap as E, Form as F, InvalidSubmitHandler as I, PathDepth as P, ReadonlyStoreApi as R, SettledFieldValidationResult as S, ValidationMode as V, FormState as a, FieldValidationResult as b, FieldPath as c, FieldValue as d, ArrayItemOf as e, FieldSnapshot as f, FieldsValidationResult as g, ResetOptions as h, SettledFieldsValidationResult as i, SettledValidationResult as j, SubmitHandler as k, SubmitOptions as l, SubmitResult as m, ValidationResult as n, ValidationTrigger as o };
|
package/dist/devtools/index.cjs
CHANGED
|
@@ -317,7 +317,10 @@ var DevtoolsPanel = ({
|
|
|
317
317
|
}
|
|
318
318
|
) });
|
|
319
319
|
};
|
|
320
|
-
var FormstandDevtools = (
|
|
320
|
+
var FormstandDevtools = ({
|
|
321
|
+
enabled,
|
|
322
|
+
...props
|
|
323
|
+
}) => enabled ?? isDevToolsBuild() ? /* @__PURE__ */ jsxRuntime.jsx(DevtoolsPanel, { ...props }) : null;
|
|
321
324
|
|
|
322
325
|
exports.FormstandDevtools = FormstandDevtools;
|
|
323
326
|
exports.leafPaths = leafPaths;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/env.ts","../../src/core/path.ts","../../src/react/useFormSelector.ts","../../src/devtools/paths.ts","../../src/devtools/styles.ts","../../src/devtools/FormstandDevtools.tsx"],"names":["useStore","useShallow","jsxs","jsx","useState"],"mappings":";;;;;;;;;;AAuBO,IAAM,kBAAkB,MAAe;AAC5C,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,EAAa,OAAO,KAAA;AAC3C,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,GAAM,UAAU,CAAA;AACpC,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,YAAA;AAC5C,CAAA;;;ACRA,IAAM,cAAA,GAAiB,CAAC,CAAA,KAAuB;AAC7C,EAAA,MAAM,CAAA,GAAI,OAAO,CAAC,CAAA;AAClB,EAAA,OAAO,MAAA,CAAO,UAAU,CAAC,CAAA,IAAK,KAAK,CAAA,IAAK,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA;A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AE1B,QAAA,EAAA;AAAA,QAAA,KAAA;AAAA,QACA,OAAO,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,CAAE,SAAS,CAAA,GAChC,CAAA,MAAA,EAAM,MAAA,CAAO,MAAA,CAAO,KAAK,KAAA,CAAM,MAAM,CAAA,CAAE,MAAM,CAAC,CAAA,IAAA,CAAA,GAC9C;AAAA;AAAA;AAAA,GACN,EAEJ,CAAA;AAEJ,CAAA;AAWO,IAAM,iBAAA,GAAoB,CAI/B,KAAA,KACI,eAAA,qBAAoBC,cAAA,CAAC,aAAA,EAAA,EAAe,GAAG,KAAA,EAAO,CAAA,GAAK","file":"index.cjs","sourcesContent":["// The dev-build test the library consults before emitting a console\n// warning. Bundlers that define NODE_ENV fold it to a constant and drop the\n// dev-only branches; the `typeof process` guard keeps the SAME expression\n// from throwing in a runtime that defines no `process` at all (a CDN/ESM\n// consumer, a test runner without the define). That last case matters most\n// on the submit path: handleSubmit promises never to reject, and the\n// warning that fires only when a save failed was the one line that could\n// break the promise exactly on the failure path. It FAILS OPEN on purpose:\n// an unknowable environment gets the warnings, which cost nothing but a\n// console line.\nexport const isDevBuild = (): boolean =>\n typeof process === \"undefined\" ||\n process.env?.[\"NODE_ENV\"] !== \"production\";\n\n// The gate for the two sites that EXPOSE form state: the FormstandDevtools\n// panel (renders every value and error into the page) and the zustand\n// devtools middleware (streams every write to the Redux extension). These\n// must FAIL CLOSED: isDevBuild's \"no process means dev\" reading let a\n// CDN/ESM, Deno, or worker production build mount the panel and keep the\n// middleware live for any end user with the extension installed. Only a\n// readable NODE_ENV that is a string other than \"production\" counts as\n// development; no process, no env, or an unset NODE_ENV all read as\n// production here.\nexport const isDevToolsBuild = (): boolean => {\n if (typeof process === \"undefined\") return false;\n const env = process.env?.[\"NODE_ENV\"];\n return typeof env === \"string\" && env !== \"production\";\n};\n","import { isPlainObject } from \"./equality\";\n\nexport type PathSegment = string | number;\n\n// What setAtPath creates at an ABSENT slot. The segment type alone cannot\n// tell a z.record keyed by numeric strings from an array (both read\n// \"lookup.0\"), so a caller that knows the schema hands in a resolver; it\n// answers for the dotted prefix being created and returns null where it\n// has no opinion, which falls back to the segment-type rule.\nexport type ContainerKind = \"array\" | \"record\";\nexport type ContainerKindAt = (prefix: string) => ContainerKind | null;\n\n// Segment keys containing \".\" are not addressable (paths are split on dots);\n// use nested objects or index-free keys instead.\n\n// Writes above this index are refused — a typo'd path like \"items.4294967296\"\n// must not allocate a multi-gigabyte array.\nconst MAX_ARRAY_INDEX = 100_000;\n\nconst isIndexSegment = (s: string): boolean => {\n const n = Number(s);\n return Number.isInteger(n) && n >= 0 && String(n) === s;\n};\n\n// Hot path: every field subscription re-resolves its path on every store\n// notification (getAtPath in selectors), so parsing is memoized — a form's\n// paths are a small fixed set. Bounded as an LRU over Map insertion order:\n// a hit re-inserts its key (moving it to the back) and an overflow evicts\n// the front, so an app whose LIVE path set exceeds the cap keeps its hot\n// paths cached instead of re-parsing every one of them after each reset\n// (the old wholesale clear). Eviction only costs re-parsing, never\n// correctness. Same delete-then-set recency idiom as useFieldArray's\n// per-path id cache.\nconst PARSE_CACHE_MAX = 4096;\nconst parseCache = new Map<string, readonly PathSegment[]>();\n\nexport const parsePath = (path: string): readonly PathSegment[] => {\n const cached = parseCache.get(path);\n if (cached !== undefined) {\n parseCache.delete(path);\n parseCache.set(path, cached);\n return cached;\n }\n // Frozen because the array is now SHARED across every caller (and cached):\n // parsePath is a public export, and pre-cache each call returned a private\n // array that was safe to mutate. Freezing enforces the `readonly` type at\n // runtime so an external `.sort()`/`.reverse()`/`.push()` throws instead of\n // silently corrupting the cache for every later lookup of this path.\n const segments = Object.freeze(\n path === \"\"\n ? []\n : path.split(\".\").map((s) => (isIndexSegment(s) ? Number(s) : s)),\n );\n if (parseCache.size >= PARSE_CACHE_MAX) {\n const oldest = parseCache.keys().next().value;\n if (oldest !== undefined) parseCache.delete(oldest);\n }\n parseCache.set(path, segments);\n return segments;\n};\n\nconst isPlainRecord = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\n\n// The existing container decides how a segment is interpreted: arrays take\n// numeric segments as indices, records take any segment as a string key (so a\n// z.record keyed \"0\" reads/writes the record key, not an array index). Only\n// when the container is absent does the segment type pick what gets created.\nconst readSegment = (obj: unknown, segment: PathSegment): unknown => {\n if (obj == null) return undefined;\n if (Array.isArray(obj)) {\n return typeof segment === \"number\" ? obj[segment] : undefined;\n }\n // Own properties only: a runtime-built path like \"lookup.constructor\" on a\n // z.record must read as absent, not leak Object.prototype members as field\n // values.\n return isPlainRecord(obj) && Object.hasOwn(obj, String(segment))\n ? obj[String(segment)]\n : undefined;\n};\n\nexport const getAtPath = (obj: unknown, path: string): unknown =>\n parsePath(path).reduce<unknown>(readSegment, obj);\n\nexport type SlotAtPath =\n | Readonly<{ exists: true; value: unknown }>\n | Readonly<{ exists: false }>;\n\n// Resolve `path` while checking that every segment is read from a real\n// container: an in-range array index, or a key on a plain record (containers\n// decide, mirroring readSegment). A segment into an absent or non-container\n// value addresses no slot at all — a full-form parse would key that error at\n// the missing ANCESTOR, not here, so field-scoped validation must skip it\n// rather than parse the leaf's subschema against undefined (which would\n// fabricate a spurious \"required\" error the full pass never produces). Note\n// this checks the CONTAINER, not the value: a leaf that is undefined at the\n// FINAL step through a real record is still an addressable (legitimately\n// empty) slot. Returns the resolved value so callers don't walk twice.\nexport const slotAtPath = (obj: unknown, path: string): SlotAtPath => {\n const walked = parsePath(path).reduce<\n Readonly<{ ok: boolean; current: unknown }>\n >(\n (acc, segment) => {\n const container = acc.current;\n const addressable =\n typeof segment === \"number\"\n ? Array.isArray(container)\n ? segment < container.length\n : isPlainRecord(container)\n : isPlainRecord(container);\n return !acc.ok || !addressable\n ? { ok: false, current: undefined }\n : { ok: true, current: readSegment(container, segment) };\n },\n { ok: true, current: obj },\n );\n return walked.ok ? { exists: true, value: walked.current } : { exists: false };\n};\n\n// Whether the path addresses an OWN slot: every step reads a real\n// container's own key / in-range array index, the final segment included.\n// This is stricter than slotAtPath, which treats a MISSING final key on a\n// real record as an addressable (legitimately empty) slot — here it reads\n// false. The consumer is setValue's identity guard: writing `undefined`\n// over an ABSENT key is NOT a no-op (it creates the key, a real state\n// change — key-count dirtiness, persisted shape), while writing it over a\n// key that exists holding undefined is.\nexport const hasOwnSlot = (obj: unknown, path: string): boolean =>\n parsePath(path).reduce<Readonly<{ ok: boolean; current: unknown }>>(\n (acc, segment) => {\n const container = acc.current;\n const owns = Array.isArray(container)\n ? typeof segment === \"number\" && segment < container.length\n : isPlainRecord(container) && Object.hasOwn(container, String(segment));\n return !acc.ok || !owns\n ? { ok: false, current: undefined }\n : { ok: true, current: readSegment(container, segment) };\n },\n { ok: true, current: obj },\n ).ok;\n\nconst writeIntoArray = (\n arr: readonly unknown[],\n index: number,\n rest: readonly PathSegment[],\n value: unknown,\n kindAt: ContainerKindAt | undefined,\n prefix: readonly PathSegment[],\n): readonly unknown[] => {\n const length = Math.max(arr.length, index + 1);\n return Array.from({ length }, (_, i) =>\n i === index\n ? writeSegments(arr[i], rest, value, kindAt, [...prefix, index])\n : arr[i],\n );\n};\n\nconst refusesHugeIndex = (index: number): boolean => {\n if (index > MAX_ARRAY_INDEX) {\n console.warn(\n `[formstand] refusing to write array index ${index} (max ${MAX_ARRAY_INDEX}); value left unchanged.`,\n );\n return true;\n }\n return false;\n};\n\nconst writeSegments = (\n obj: unknown,\n segments: readonly PathSegment[],\n value: unknown,\n kindAt: ContainerKindAt | undefined,\n prefix: readonly PathSegment[],\n): unknown => {\n const [head, ...rest] = segments;\n if (head === undefined) return value;\n\n if (Array.isArray(obj)) {\n if (typeof head !== \"number\") {\n console.warn(\n `[formstand] cannot write string key \"${head}\" into an array; value left unchanged.`,\n );\n return obj;\n }\n if (refusesHugeIndex(head)) return obj;\n return writeIntoArray(obj, head, rest, value, kindAt, prefix);\n }\n\n // Records take any segment as a string key (mirroring readSegment), so a\n // z.record keyed by a large numeric id is writable — the array-index cap\n // only applies where an array actually exists or would be created.\n if (isPlainRecord(obj)) {\n // Spreading is only safe for PLAIN objects: spreading a Date/Map/Set or\n // class instance keeps own enumerable props but drops the prototype (and\n // for Map/Set, every entry) — the original would be silently destroyed.\n // Refuse, like the other unwritable shapes above.\n if (!isPlainObject(obj)) {\n console.warn(\n `[formstand] cannot write key \"${String(head)}\" through a non-plain object (Date/Map/Set/class instance); value left unchanged.`,\n );\n return obj;\n }\n const key = String(head);\n return {\n ...obj,\n [key]: writeSegments(obj[key], rest, value, kindAt, [...prefix, key]),\n };\n }\n\n // Absent (or non-container) value: create a container. The schema's\n // answer for this slot wins when the caller supplied one (a z.record\n // keyed \"0\" must not become an array, and a z.array must not become a\n // record); otherwise the segment type decides, as the docs state.\n const kind =\n kindAt?.(prefix.map(String).join(\".\")) ??\n (typeof head === \"number\" ? \"array\" : \"record\");\n if (kind === \"array\") {\n if (typeof head !== \"number\") {\n console.warn(\n `[formstand] cannot write string key \"${head}\" into an array; value left unchanged.`,\n );\n return obj;\n }\n if (refusesHugeIndex(head)) return obj;\n return writeIntoArray([], head, rest, value, kindAt, prefix);\n }\n const key = String(head);\n return { [key]: writeSegments(undefined, rest, value, kindAt, [...prefix, key]) };\n};\n\n// `containerKindAt` is optional so the bare utility keeps its segment-type\n// rule; createForm passes the schema-derived resolver from validation.ts.\nexport const setAtPath = <T>(\n obj: T,\n path: string,\n value: unknown,\n containerKindAt?: ContainerKindAt,\n): T => writeSegments(obj, parsePath(path), value, containerKindAt, []) as T;\n","import type { z } from \"zod\";\nimport type { StoreApi } from \"zustand/vanilla\";\nimport { useStore } from \"zustand/react\";\nimport { useShallow } from \"zustand/react/shallow\";\nimport type { Form } from \"../core/createForm\";\nimport type { DefaultPathDepth, PathDepth } from \"../core/fieldPath\";\nimport type { FormState } from \"../core/types\";\n\ntype ReadonlyStore<T> = Pick<\n StoreApi<T>,\n \"getState\" | \"getInitialState\" | \"subscribe\"\n>;\n\nexport type FormStateApi = Readonly<{\n store: ReadonlyStore<FormState<unknown>>;\n}>;\n\nexport function useFormSelector<\n TSchema extends z.ZodType,\n U,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n selector: (state: FormState<z.input<TSchema>>) => U,\n): U;\n// The `schema?: undefined` brand forces Form<TSchema> (which has a real\n// `schema` property) to bind only the typed overload above. Without\n// it, Form<TSchema> would structurally satisfy FormStateApi too and a\n// bad selector could silently widen to FormState<unknown>.\nexport function useFormSelector<U>(\n form: FormStateApi & { readonly schema?: undefined },\n selector: (state: FormState<unknown>) => U,\n): U;\nexport function useFormSelector<U>(\n form: FormStateApi,\n selector: (state: FormState<unknown>) => U,\n): U {\n return useStore(form.store, selector);\n}\n\nexport function useFormSelectorShallow<\n TSchema extends z.ZodType,\n U,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n selector: (state: FormState<z.input<TSchema>>) => U,\n): U;\nexport function useFormSelectorShallow<U>(\n form: FormStateApi & { readonly schema?: undefined },\n selector: (state: FormState<unknown>) => U,\n): U;\nexport function useFormSelectorShallow<U>(\n form: FormStateApi,\n selector: (state: FormState<unknown>) => U,\n): U {\n return useStore(form.store, useShallow(selector));\n}\n","// Walking a values object into the list of paths the panel shows.\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n // A Date is a leaf, not a container to recurse into: its own keys are\n // methods, and useField binds the Date itself.\n !(value instanceof Date);\n\n// The addressable leaf paths of a values object, in declaration order.\n// Arrays contribute one path per ROW rather than one for the array, because\n// that is what a field binds to; the array's own path still shows up in the\n// panel via the error map, which is where `z.array().min(1)` lands.\n//\n// An empty object or array is itself a leaf here. It has no children to\n// describe, and dropping it would hide a field that exists in the schema.\nexport const leafPaths = (value: unknown, base = \"\"): readonly string[] => {\n const join = (key: string | number): string =>\n base === \"\" ? String(key) : `${base}.${String(key)}`;\n\n if (Array.isArray(value)) {\n return value.length === 0\n ? [base]\n : value.flatMap((item, index) => leafPaths(item, join(index)));\n }\n if (isPlainObject(value)) {\n const keys = Object.keys(value);\n return keys.length === 0\n ? [base]\n : keys.flatMap((key) => leafPaths(value[key], join(key)));\n }\n return [base];\n};\n\n// Error keys that no leaf path covers: the root \"\" key (a schema-wide\n// refine), array-level messages keyed at the container, and server verdicts\n// written at a path that holds no value yet. Without this the panel would\n// silently drop exactly the errors that are hardest to debug.\nexport const unmatchedErrorKeys = (\n errorKeys: readonly string[],\n leaves: readonly string[],\n): readonly string[] => {\n const covered = new Set(leaves);\n return errorKeys.filter((key) => !covered.has(key));\n};\n","import type { CSSProperties } from \"react\";\n\n// Inline styles on purpose: a devtools panel that needs the consumer to\n// import a stylesheet is a devtools panel that renders unstyled the first\n// time someone tries it. Inline also means nothing here can leak into or be\n// overridden by the host app's CSS, which matters when the whole job is\n// showing you the truth about your form.\n\nexport type DevtoolsPosition =\n | \"bottom-right\"\n | \"bottom-left\"\n | \"top-right\"\n | \"top-left\";\n\nconst ANCHOR: Readonly<Record<DevtoolsPosition, CSSProperties>> = {\n \"bottom-right\": { bottom: 12, right: 12 },\n \"bottom-left\": { bottom: 12, left: 12 },\n \"top-right\": { top: 12, right: 12 },\n \"top-left\": { top: 12, left: 12 },\n};\n\nconst MONO =\n 'ui-monospace, SFMono-Regular, Menlo, Consolas, \"Liberation Mono\", monospace';\n\nexport const anchorFor = (position: DevtoolsPosition): CSSProperties =>\n ANCHOR[position];\n\nexport const styles = {\n root: {\n position: \"fixed\",\n zIndex: 2147483000,\n fontFamily: MONO,\n fontSize: 11,\n lineHeight: 1.45,\n color: \"#e6e6e6\",\n colorScheme: \"dark\",\n } satisfies CSSProperties,\n toggle: {\n background: \"#1b1b1f\",\n border: \"1px solid #3a3a42\",\n color: \"#e6e6e6\",\n borderRadius: 6,\n padding: \"6px 10px\",\n font: \"inherit\",\n cursor: \"pointer\",\n } satisfies CSSProperties,\n panel: {\n width: \"min(440px, calc(100vw - 24px))\",\n maxHeight: \"min(60vh, 520px)\",\n overflow: \"auto\",\n background: \"#141417\",\n border: \"1px solid #3a3a42\",\n borderRadius: 8,\n boxShadow: \"0 12px 32px rgba(0,0,0,0.45)\",\n } satisfies CSSProperties,\n header: {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n gap: 8,\n padding: \"8px 10px\",\n borderBottom: \"1px solid #2a2a31\",\n position: \"sticky\",\n top: 0,\n background: \"#141417\",\n } satisfies CSSProperties,\n section: { padding: \"8px 10px\", borderBottom: \"1px solid #23232a\" },\n sectionTitle: {\n color: \"#9aa0aa\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.06em\",\n fontSize: 10,\n margin: \"0 0 6px\",\n } satisfies CSSProperties,\n table: {\n width: \"100%\",\n borderCollapse: \"collapse\",\n tableLayout: \"fixed\",\n } satisfies CSSProperties,\n th: {\n textAlign: \"left\",\n color: \"#9aa0aa\",\n fontWeight: 400,\n padding: \"2px 4px\",\n borderBottom: \"1px solid #2a2a31\",\n } satisfies CSSProperties,\n td: {\n padding: \"2px 4px\",\n verticalAlign: \"top\",\n wordBreak: \"break-word\",\n } satisfies CSSProperties,\n path: { color: \"#c8b6ff\" } satisfies CSSProperties,\n error: { color: \"#ff8f8f\" } satisfies CSSProperties,\n muted: { color: \"#7d838d\" } satisfies CSSProperties,\n flag: { color: \"#7ddca4\" } satisfies CSSProperties,\n pre: {\n margin: 0,\n whiteSpace: \"pre-wrap\",\n wordBreak: \"break-word\",\n } satisfies CSSProperties,\n button: {\n background: \"#22222a\",\n border: \"1px solid #3a3a42\",\n color: \"#e6e6e6\",\n borderRadius: 5,\n padding: \"3px 8px\",\n font: \"inherit\",\n cursor: \"pointer\",\n } satisfies CSSProperties,\n} as const;\n","import { type ReactNode, useState } from \"react\";\nimport { isDevToolsBuild } from \"../core/env\";\nimport type { z } from \"zod\";\nimport type { Form } from \"../core/createForm\";\nimport type {\n DefaultPathDepth,\n FieldPath,\n PathDepth,\n} from \"../core/fieldPath\";\nimport { getAtPath } from \"../core/path\";\nimport type { FormState } from \"../core/types\";\nimport { useFormSelectorShallow } from \"../react/useFormSelector\";\nimport { leafPaths, unmatchedErrorKeys } from \"./paths\";\nimport { type DevtoolsPosition, anchorFor, styles } from \"./styles\";\n\n// D (the form's typed-path depth budget) is carried so a `pathDepth: 12`\n// form is accepted: Form<S, 12> is deliberately not assignable to Form<S, 9>,\n// so the depth-less prop type rejected every widened form (TS2375).\nexport type FormstandDevtoolsProps<\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n> = Readonly<{\n form: Form<TSchema, D>;\n position?: DevtoolsPosition;\n defaultOpen?: boolean;\n /** Shown on the toggle, for telling two mounted panels apart. */\n label?: string;\n}>;\n\ntype FieldRow = Readonly<{\n path: string;\n value: unknown;\n error: readonly string[] | undefined;\n touched: boolean;\n dirty: boolean;\n isValidating: boolean;\n}>;\n\n// Non-production only, matching createForm's own devtools gate: the panel is\n// a debugging affordance, and shipping it to end users would leak the whole\n// form state into the page. Bundlers that define NODE_ENV drop the panel\n// entirely. The gate fails CLOSED (isDevToolsBuild): a runtime with no\n// readable NODE_ENV at all (a CDN/ESM consumer, Deno, a worker) renders\n// nothing rather than assuming it is a dev build the way the console\n// warnings may.\n\nconst preview = (value: unknown): string => {\n if (value === undefined) return \"undefined\";\n if (value instanceof Date) return value.toISOString();\n const json = JSON.stringify(value);\n // Long strings and big row objects would push the value column past the\n // panel; the full value is one expand away in the Values section.\n return json === undefined\n ? String(value)\n : json.length > 60\n ? `${json.slice(0, 57)}…`\n : json;\n};\n\nconst flags = (row: FieldRow): string =>\n [\n row.touched ? \"touched\" : \"\",\n row.dirty ? \"dirty\" : \"\",\n row.isValidating ? \"validating\" : \"\",\n ]\n .filter((flag) => flag !== \"\")\n .join(\" \");\n\n// Reads every slice the panel renders in ONE shallow-compared subscription.\n// Each member is a stored reference the form replaces on write, so shallow\n// equality is stable — deriving anything fresh (an array from dirtyFields())\n// inside the selector would hand the store a new reference every pass and\n// loop it (React #185).\nconst useDevtoolsState = <TSchema extends z.ZodType, D extends PathDepth>(\n form: Form<TSchema, D>,\n) =>\n useFormSelectorShallow(form, (state) => ({\n values: state.values,\n errors: state.errors,\n schemaErrors: state.schemaErrors,\n serverErrors: state.serverErrors,\n touched: state.touched,\n isValidating: state.isValidating,\n isSubmitting: state.isSubmitting,\n isValidatingForm: state.isValidatingForm,\n submitCount: state.submitCount,\n mode: state.mode,\n }));\n\nconst Section = ({\n title,\n children,\n}: Readonly<{ title: string; children: ReactNode }>) => (\n <div style={styles.section}>\n <p style={styles.sectionTitle}>{title}</p>\n {children}\n </div>\n);\n\nconst DevtoolsPanel = <TSchema extends z.ZodType, D extends PathDepth>({\n form,\n position = \"bottom-right\",\n defaultOpen = false,\n label = \"formstand\",\n}: FormstandDevtoolsProps<TSchema, D>) => {\n const state = useDevtoolsState(form);\n const [open, setOpen] = useState(defaultOpen);\n const [held, setHeld] = useState<FormState<z.input<TSchema>> | null>(null);\n\n // Computed every render rather than memoized. getFieldState and diff() read\n // through `form`, not through anything in a dependency array, so a memo\n // would need deps the linter can't see and would go stale the moment one\n // was missed. This component only re-renders when the subscription above\n // reports a real change, so recomputing is both cheap and always right.\n const rows: readonly FieldRow[] = leafPaths(state.values).map((path) => {\n // Runtime-built strings need the cast the typed surface documents.\n // getFieldState rather than re-deriving dirty here, so the panel reports\n // the library's own comparison rules (Dates by timestamp, deep for\n // containers) instead of offering a second opinion.\n const field = form.getFieldState(path as FieldPath<z.input<TSchema>, D>);\n return {\n path,\n value: field.value,\n error: field.error,\n touched: field.touched,\n dirty: field.dirty,\n isValidating: field.isValidating,\n };\n });\n\n const orphanErrors = unmatchedErrorKeys(\n Object.keys(state.errors),\n rows.map((row) => row.path),\n );\n\n const diff = form.diff();\n\n return (\n <div style={{ ...styles.root, ...anchorFor(position) }}>\n {open ? (\n <div style={styles.panel}>\n <div style={styles.header}>\n <strong>{label}</strong>\n <span style={styles.muted}>\n {state.mode}\n {state.isSubmitting ? \" · submitting\" : \"\"}\n {state.isValidatingForm ? \" · validating\" : \"\"}\n {state.submitCount > 0 ? ` · submits ${state.submitCount}` : \"\"}\n </span>\n <button\n type=\"button\"\n style={styles.button}\n onClick={() => setOpen(false)}\n >\n close\n </button>\n </div>\n\n <Section title={`fields (${rows.length})`}>\n <table style={styles.table}>\n <thead>\n <tr>\n <th style={{ ...styles.th, width: \"38%\" }}>path</th>\n <th style={styles.th}>value</th>\n <th style={{ ...styles.th, width: \"26%\" }}>state</th>\n </tr>\n </thead>\n <tbody>\n {rows.map((row) => (\n <tr key={row.path}>\n <td style={{ ...styles.td, ...styles.path }}>{row.path}</td>\n <td style={styles.td}>\n {preview(row.value)}\n {row.error === undefined ? null : (\n <div style={styles.error}>{row.error.join(\", \")}</div>\n )}\n </td>\n <td style={{ ...styles.td, ...styles.flag }}>\n {flags(row)}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </Section>\n\n {orphanErrors.length === 0 ? null : (\n // Errors with no field of their own: the root \"\" key, array-level\n // messages, server verdicts on paths that hold no value yet.\n <Section title=\"errors without a field\">\n {orphanErrors.map((key) => (\n <div key={key}>\n <span style={styles.path}>{key === \"\" ? \"(root)\" : key}</span>{\" \"}\n <span style={styles.error}>\n {(state.errors[key] ?? []).join(\", \")}\n </span>\n </div>\n ))}\n </Section>\n )}\n\n <Section title=\"error channels\">\n <div style={styles.muted}>\n schema {Object.keys(state.schemaErrors).length} · server{\" \"}\n {Object.keys(state.serverErrors).length}\n </div>\n {Object.entries(state.serverErrors).map(([key, messages]) => (\n <div key={key}>\n <span style={styles.path}>{key === \"\" ? \"(root)\" : key}</span>{\" \"}\n <span style={styles.error}>{messages.join(\", \")}</span>{\" \"}\n <span style={styles.muted}>\n {getAtPath(state.schemaErrors, key) === undefined\n ? \"(showing)\"\n : \"(behind a schema error)\"}\n </span>\n </div>\n ))}\n </Section>\n\n <Section title=\"diff vs initial\">\n <pre style={styles.pre}>\n {Object.keys(diff).length === 0\n ? \"clean\"\n : JSON.stringify(diff, null, 2)}\n </pre>\n </Section>\n\n <Section title=\"time travel\">\n <button\n type=\"button\"\n style={styles.button}\n onClick={() => setHeld(form.snapshot())}\n >\n snapshot\n </button>{\" \"}\n <button\n type=\"button\"\n style={styles.button}\n disabled={held === null}\n onClick={() => {\n if (held !== null) form.restore(held);\n }}\n >\n restore\n </button>{\" \"}\n <span style={styles.muted}>\n {held === null ? \"nothing held\" : \"snapshot held\"}\n </span>\n </Section>\n </div>\n ) : (\n <button\n type=\"button\"\n style={styles.toggle}\n onClick={() => setOpen(true)}\n >\n {label}\n {Object.keys(state.errors).length > 0\n ? ` · ${String(Object.keys(state.errors).length)} err`\n : \"\"}\n </button>\n )}\n </div>\n );\n};\n\n/**\n * A form-aware debugging panel: every field's value, error, and flags, the\n * two error channels shown separately, the live diff against initial values,\n * and snapshot/restore time travel.\n *\n * Renders nothing in production builds, and nothing wherever NODE_ENV is not\n * readable (no `process` global, or one without NODE_ENV): the panel exposes\n * the whole form state, so an unknowable environment is treated as shipped.\n */\nexport const FormstandDevtools = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>(\n props: FormstandDevtoolsProps<TSchema, D>,\n) => (isDevToolsBuild() ? <DevtoolsPanel {...props} /> : null);\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/env.ts","../../src/core/path.ts","../../src/react/useFormSelector.ts","../../src/devtools/paths.ts","../../src/devtools/styles.ts","../../src/devtools/FormstandDevtools.tsx"],"names":["useStore","useShallow","jsxs","jsx","useState"],"mappings":";;;;;;;;;;AAuBO,IAAM,kBAAkB,MAAe;AAC5C,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,EAAa,OAAO,KAAA;AAC3C,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,GAAM,UAAU,CAAA;AACpC,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,YAAA;AAC5C,CAAA;;;ACRA,IAAM,cAAA,GAAiB,CAAC,CAAA,KAAuB;AAC7C,EAAA,MAAM,CAAA,GAA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AAA;AAAA,MACC,IAAA,EAAK,QAAA;AAAA,MACL,OAAO,MAAA,CAAO,MAAA;AAAA,MACd,OAAA,EAAS,MAAM,OAAA,CAAQ,IAAI,CAAA;AAAA,MAE1B,QAAA,EAAA;AAAA,QAAA,KAAA;AAAA,QACA,OAAO,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,CAAE,SAAS,CAAA,GAChC,CAAA,MAAA,EAAM,MAAA,CAAO,MAAA,CAAO,KAAK,KAAA,CAAM,MAAM,CAAA,CAAE,MAAM,CAAC,CAAA,IAAA,CAAA,GAC9C;AAAA;AAAA;AAAA,GACN,EAEJ,CAAA;AAEJ,CAAA;AAWO,IAAM,oBAAoB,CAG/B;AAAA,EACA,OAAA;AAAA,EACA,GAAG;AACL,CAAA,KACG,WAAW,eAAA,EAAgB,kCAAM,aAAA,EAAA,EAAe,GAAG,OAAO,CAAA,GAAK","file":"index.cjs","sourcesContent":["// The dev-build test the library consults before emitting a console\n// warning. Bundlers that define NODE_ENV fold it to a constant and drop the\n// dev-only branches; the `typeof process` guard keeps the SAME expression\n// from throwing in a runtime that defines no `process` at all (a CDN/ESM\n// consumer, a test runner without the define). That last case matters most\n// on the submit path: handleSubmit promises never to reject, and the\n// warning that fires only when a save failed was the one line that could\n// break the promise exactly on the failure path. It FAILS OPEN on purpose:\n// an unknowable environment gets the warnings, which cost nothing but a\n// console line.\nexport const isDevBuild = (): boolean =>\n typeof process === \"undefined\" ||\n process.env?.[\"NODE_ENV\"] !== \"production\";\n\n// The gate for the two sites that EXPOSE form state: the FormstandDevtools\n// panel (renders every value and error into the page) and the zustand\n// devtools middleware (streams every write to the Redux extension). These\n// must FAIL CLOSED: isDevBuild's \"no process means dev\" reading let a\n// CDN/ESM, Deno, or worker production build mount the panel and keep the\n// middleware live for any end user with the extension installed. Only a\n// readable NODE_ENV that is a string other than \"production\" counts as\n// development; no process, no env, or an unset NODE_ENV all read as\n// production here.\nexport const isDevToolsBuild = (): boolean => {\n if (typeof process === \"undefined\") return false;\n const env = process.env?.[\"NODE_ENV\"];\n return typeof env === \"string\" && env !== \"production\";\n};\n","import { isPlainObject } from \"./equality\";\n\nexport type PathSegment = string | number;\n\n// What setAtPath creates at an ABSENT slot. The segment type alone cannot\n// tell a z.record keyed by numeric strings from an array (both read\n// \"lookup.0\"), so a caller that knows the schema hands in a resolver; it\n// answers for the dotted prefix being created and returns null where it\n// has no opinion, which falls back to the segment-type rule.\nexport type ContainerKind = \"array\" | \"record\";\nexport type ContainerKindAt = (prefix: string) => ContainerKind | null;\n\n// Segment keys containing \".\" are not addressable (paths are split on dots);\n// use nested objects or index-free keys instead.\n\n// Writes above this index are refused — a typo'd path like \"items.4294967296\"\n// must not allocate a multi-gigabyte array.\nconst MAX_ARRAY_INDEX = 100_000;\n\nconst isIndexSegment = (s: string): boolean => {\n const n = Number(s);\n return Number.isInteger(n) && n >= 0 && String(n) === s;\n};\n\n// Hot path: every field subscription re-resolves its path on every store\n// notification (getAtPath in selectors), so parsing is memoized — a form's\n// paths are a small fixed set. Bounded as an LRU over Map insertion order:\n// a hit re-inserts its key (moving it to the back) and an overflow evicts\n// the front, so an app whose LIVE path set exceeds the cap keeps its hot\n// paths cached instead of re-parsing every one of them after each reset\n// (the old wholesale clear). Eviction only costs re-parsing, never\n// correctness. Same delete-then-set recency idiom as useFieldArray's\n// per-path id cache.\nconst PARSE_CACHE_MAX = 4096;\nconst parseCache = new Map<string, readonly PathSegment[]>();\n\nexport const parsePath = (path: string): readonly PathSegment[] => {\n const cached = parseCache.get(path);\n if (cached !== undefined) {\n parseCache.delete(path);\n parseCache.set(path, cached);\n return cached;\n }\n // Frozen because the array is now SHARED across every caller (and cached):\n // parsePath is a public export, and pre-cache each call returned a private\n // array that was safe to mutate. Freezing enforces the `readonly` type at\n // runtime so an external `.sort()`/`.reverse()`/`.push()` throws instead of\n // silently corrupting the cache for every later lookup of this path.\n const segments = Object.freeze(\n path === \"\"\n ? []\n : path.split(\".\").map((s) => (isIndexSegment(s) ? Number(s) : s)),\n );\n if (parseCache.size >= PARSE_CACHE_MAX) {\n const oldest = parseCache.keys().next().value;\n if (oldest !== undefined) parseCache.delete(oldest);\n }\n parseCache.set(path, segments);\n return segments;\n};\n\nconst isPlainRecord = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\n\n// The existing container decides how a segment is interpreted: arrays take\n// numeric segments as indices, records take any segment as a string key (so a\n// z.record keyed \"0\" reads/writes the record key, not an array index). Only\n// when the container is absent does the segment type pick what gets created.\nconst readSegment = (obj: unknown, segment: PathSegment): unknown => {\n if (obj == null) return undefined;\n if (Array.isArray(obj)) {\n return typeof segment === \"number\" ? obj[segment] : undefined;\n }\n // Own properties only: a runtime-built path like \"lookup.constructor\" on a\n // z.record must read as absent, not leak Object.prototype members as field\n // values.\n return isPlainRecord(obj) && Object.hasOwn(obj, String(segment))\n ? obj[String(segment)]\n : undefined;\n};\n\nexport const getAtPath = (obj: unknown, path: string): unknown =>\n parsePath(path).reduce<unknown>(readSegment, obj);\n\nexport type SlotAtPath =\n | Readonly<{ exists: true; value: unknown }>\n | Readonly<{ exists: false }>;\n\n// Resolve `path` while checking that every segment is read from a real\n// container: an in-range array index, or a key on a plain record (containers\n// decide, mirroring readSegment). A segment into an absent or non-container\n// value addresses no slot at all — a full-form parse would key that error at\n// the missing ANCESTOR, not here, so field-scoped validation must skip it\n// rather than parse the leaf's subschema against undefined (which would\n// fabricate a spurious \"required\" error the full pass never produces). Note\n// this checks the CONTAINER, not the value: a leaf that is undefined at the\n// FINAL step through a real record is still an addressable (legitimately\n// empty) slot. Returns the resolved value so callers don't walk twice.\nexport const slotAtPath = (obj: unknown, path: string): SlotAtPath => {\n const walked = parsePath(path).reduce<\n Readonly<{ ok: boolean; current: unknown }>\n >(\n (acc, segment) => {\n const container = acc.current;\n const addressable =\n typeof segment === \"number\"\n ? Array.isArray(container)\n ? segment < container.length\n : isPlainRecord(container)\n : isPlainRecord(container);\n return !acc.ok || !addressable\n ? { ok: false, current: undefined }\n : { ok: true, current: readSegment(container, segment) };\n },\n { ok: true, current: obj },\n );\n return walked.ok ? { exists: true, value: walked.current } : { exists: false };\n};\n\n// Whether the path addresses an OWN slot: every step reads a real\n// container's own key / in-range array index, the final segment included.\n// This is stricter than slotAtPath, which treats a MISSING final key on a\n// real record as an addressable (legitimately empty) slot — here it reads\n// false. The consumer is setValue's identity guard: writing `undefined`\n// over an ABSENT key is NOT a no-op (it creates the key, a real state\n// change — key-count dirtiness, persisted shape), while writing it over a\n// key that exists holding undefined is.\nexport const hasOwnSlot = (obj: unknown, path: string): boolean =>\n parsePath(path).reduce<Readonly<{ ok: boolean; current: unknown }>>(\n (acc, segment) => {\n const container = acc.current;\n const owns = Array.isArray(container)\n ? typeof segment === \"number\" && segment < container.length\n : isPlainRecord(container) && Object.hasOwn(container, String(segment));\n return !acc.ok || !owns\n ? { ok: false, current: undefined }\n : { ok: true, current: readSegment(container, segment) };\n },\n { ok: true, current: obj },\n ).ok;\n\nconst writeIntoArray = (\n arr: readonly unknown[],\n index: number,\n rest: readonly PathSegment[],\n value: unknown,\n kindAt: ContainerKindAt | undefined,\n prefix: readonly PathSegment[],\n): readonly unknown[] => {\n const length = Math.max(arr.length, index + 1);\n return Array.from({ length }, (_, i) =>\n i === index\n ? writeSegments(arr[i], rest, value, kindAt, [...prefix, index])\n : arr[i],\n );\n};\n\nconst refusesHugeIndex = (index: number): boolean => {\n if (index > MAX_ARRAY_INDEX) {\n console.warn(\n `[formstand] refusing to write array index ${index} (max ${MAX_ARRAY_INDEX}); value left unchanged.`,\n );\n return true;\n }\n return false;\n};\n\nconst writeSegments = (\n obj: unknown,\n segments: readonly PathSegment[],\n value: unknown,\n kindAt: ContainerKindAt | undefined,\n prefix: readonly PathSegment[],\n): unknown => {\n const [head, ...rest] = segments;\n if (head === undefined) return value;\n\n if (Array.isArray(obj)) {\n if (typeof head !== \"number\") {\n console.warn(\n `[formstand] cannot write string key \"${head}\" into an array; value left unchanged.`,\n );\n return obj;\n }\n if (refusesHugeIndex(head)) return obj;\n return writeIntoArray(obj, head, rest, value, kindAt, prefix);\n }\n\n // Records take any segment as a string key (mirroring readSegment), so a\n // z.record keyed by a large numeric id is writable — the array-index cap\n // only applies where an array actually exists or would be created.\n if (isPlainRecord(obj)) {\n // Spreading is only safe for PLAIN objects: spreading a Date/Map/Set or\n // class instance keeps own enumerable props but drops the prototype (and\n // for Map/Set, every entry) — the original would be silently destroyed.\n // Refuse, like the other unwritable shapes above.\n if (!isPlainObject(obj)) {\n console.warn(\n `[formstand] cannot write key \"${String(head)}\" through a non-plain object (Date/Map/Set/class instance); value left unchanged.`,\n );\n return obj;\n }\n const key = String(head);\n return {\n ...obj,\n [key]: writeSegments(obj[key], rest, value, kindAt, [...prefix, key]),\n };\n }\n\n // Absent (or non-container) value: create a container. The schema's\n // answer for this slot wins when the caller supplied one (a z.record\n // keyed \"0\" must not become an array, and a z.array must not become a\n // record); otherwise the segment type decides, as the docs state.\n const kind =\n kindAt?.(prefix.map(String).join(\".\")) ??\n (typeof head === \"number\" ? \"array\" : \"record\");\n if (kind === \"array\") {\n if (typeof head !== \"number\") {\n console.warn(\n `[formstand] cannot write string key \"${head}\" into an array; value left unchanged.`,\n );\n return obj;\n }\n if (refusesHugeIndex(head)) return obj;\n return writeIntoArray([], head, rest, value, kindAt, prefix);\n }\n const key = String(head);\n return { [key]: writeSegments(undefined, rest, value, kindAt, [...prefix, key]) };\n};\n\n// `containerKindAt` is optional so the bare utility keeps its segment-type\n// rule; createForm passes the schema-derived resolver from validation.ts.\nexport const setAtPath = <T>(\n obj: T,\n path: string,\n value: unknown,\n containerKindAt?: ContainerKindAt,\n): T => writeSegments(obj, parsePath(path), value, containerKindAt, []) as T;\n","import type { z } from \"zod\";\nimport type { StoreApi } from \"zustand/vanilla\";\nimport { useStore } from \"zustand/react\";\nimport { useShallow } from \"zustand/react/shallow\";\nimport type { Form } from \"../core/createForm\";\nimport type { DefaultPathDepth, PathDepth } from \"../core/fieldPath\";\nimport type { FormState } from \"../core/types\";\n\ntype ReadonlyStore<T> = Pick<\n StoreApi<T>,\n \"getState\" | \"getInitialState\" | \"subscribe\"\n>;\n\nexport type FormStateApi = Readonly<{\n store: ReadonlyStore<FormState<unknown>>;\n}>;\n\nexport function useFormSelector<\n TSchema extends z.ZodType,\n U,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n selector: (state: FormState<z.input<TSchema>>) => U,\n): U;\n// The `schema?: undefined` brand forces Form<TSchema> (which has a real\n// `schema` property) to bind only the typed overload above. Without\n// it, Form<TSchema> would structurally satisfy FormStateApi too and a\n// bad selector could silently widen to FormState<unknown>.\nexport function useFormSelector<U>(\n form: FormStateApi & { readonly schema?: undefined },\n selector: (state: FormState<unknown>) => U,\n): U;\nexport function useFormSelector<U>(\n form: FormStateApi,\n selector: (state: FormState<unknown>) => U,\n): U {\n return useStore(form.store, selector);\n}\n\nexport function useFormSelectorShallow<\n TSchema extends z.ZodType,\n U,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n selector: (state: FormState<z.input<TSchema>>) => U,\n): U;\nexport function useFormSelectorShallow<U>(\n form: FormStateApi & { readonly schema?: undefined },\n selector: (state: FormState<unknown>) => U,\n): U;\nexport function useFormSelectorShallow<U>(\n form: FormStateApi,\n selector: (state: FormState<unknown>) => U,\n): U {\n return useStore(form.store, useShallow(selector));\n}\n","// Walking a values object into the list of paths the panel shows.\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n // A Date is a leaf, not a container to recurse into: its own keys are\n // methods, and useField binds the Date itself.\n !(value instanceof Date);\n\n// The addressable leaf paths of a values object, in declaration order.\n// Arrays contribute one path per ROW rather than one for the array, because\n// that is what a field binds to; the array's own path still shows up in the\n// panel via the error map, which is where `z.array().min(1)` lands.\n//\n// An empty object or array is itself a leaf here. It has no children to\n// describe, and dropping it would hide a field that exists in the schema.\nexport const leafPaths = (value: unknown, base = \"\"): readonly string[] => {\n const join = (key: string | number): string =>\n base === \"\" ? String(key) : `${base}.${String(key)}`;\n\n if (Array.isArray(value)) {\n return value.length === 0\n ? [base]\n : value.flatMap((item, index) => leafPaths(item, join(index)));\n }\n if (isPlainObject(value)) {\n const keys = Object.keys(value);\n return keys.length === 0\n ? [base]\n : keys.flatMap((key) => leafPaths(value[key], join(key)));\n }\n return [base];\n};\n\n// Error keys that no leaf path covers: the root \"\" key (a schema-wide\n// refine), array-level messages keyed at the container, and server verdicts\n// written at a path that holds no value yet. Without this the panel would\n// silently drop exactly the errors that are hardest to debug.\nexport const unmatchedErrorKeys = (\n errorKeys: readonly string[],\n leaves: readonly string[],\n): readonly string[] => {\n const covered = new Set(leaves);\n return errorKeys.filter((key) => !covered.has(key));\n};\n","import type { CSSProperties } from \"react\";\n\n// Inline styles on purpose: a devtools panel that needs the consumer to\n// import a stylesheet is a devtools panel that renders unstyled the first\n// time someone tries it. Inline also means nothing here can leak into or be\n// overridden by the host app's CSS, which matters when the whole job is\n// showing you the truth about your form.\n\nexport type DevtoolsPosition =\n | \"bottom-right\"\n | \"bottom-left\"\n | \"top-right\"\n | \"top-left\";\n\nconst ANCHOR: Readonly<Record<DevtoolsPosition, CSSProperties>> = {\n \"bottom-right\": { bottom: 12, right: 12 },\n \"bottom-left\": { bottom: 12, left: 12 },\n \"top-right\": { top: 12, right: 12 },\n \"top-left\": { top: 12, left: 12 },\n};\n\nconst MONO =\n 'ui-monospace, SFMono-Regular, Menlo, Consolas, \"Liberation Mono\", monospace';\n\nexport const anchorFor = (position: DevtoolsPosition): CSSProperties =>\n ANCHOR[position];\n\nexport const styles = {\n root: {\n position: \"fixed\",\n zIndex: 2147483000,\n fontFamily: MONO,\n fontSize: 11,\n lineHeight: 1.45,\n color: \"#e6e6e6\",\n colorScheme: \"dark\",\n } satisfies CSSProperties,\n toggle: {\n background: \"#1b1b1f\",\n border: \"1px solid #3a3a42\",\n color: \"#e6e6e6\",\n borderRadius: 6,\n padding: \"6px 10px\",\n font: \"inherit\",\n cursor: \"pointer\",\n } satisfies CSSProperties,\n panel: {\n width: \"min(440px, calc(100vw - 24px))\",\n maxHeight: \"min(60vh, 520px)\",\n overflow: \"auto\",\n background: \"#141417\",\n border: \"1px solid #3a3a42\",\n borderRadius: 8,\n boxShadow: \"0 12px 32px rgba(0,0,0,0.45)\",\n } satisfies CSSProperties,\n header: {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n gap: 8,\n padding: \"8px 10px\",\n borderBottom: \"1px solid #2a2a31\",\n position: \"sticky\",\n top: 0,\n background: \"#141417\",\n } satisfies CSSProperties,\n section: { padding: \"8px 10px\", borderBottom: \"1px solid #23232a\" },\n sectionTitle: {\n color: \"#9aa0aa\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.06em\",\n fontSize: 10,\n margin: \"0 0 6px\",\n } satisfies CSSProperties,\n table: {\n width: \"100%\",\n borderCollapse: \"collapse\",\n tableLayout: \"fixed\",\n } satisfies CSSProperties,\n th: {\n textAlign: \"left\",\n color: \"#9aa0aa\",\n fontWeight: 400,\n padding: \"2px 4px\",\n borderBottom: \"1px solid #2a2a31\",\n } satisfies CSSProperties,\n td: {\n padding: \"2px 4px\",\n verticalAlign: \"top\",\n wordBreak: \"break-word\",\n } satisfies CSSProperties,\n path: { color: \"#c8b6ff\" } satisfies CSSProperties,\n error: { color: \"#ff8f8f\" } satisfies CSSProperties,\n muted: { color: \"#7d838d\" } satisfies CSSProperties,\n flag: { color: \"#7ddca4\" } satisfies CSSProperties,\n pre: {\n margin: 0,\n whiteSpace: \"pre-wrap\",\n wordBreak: \"break-word\",\n } satisfies CSSProperties,\n button: {\n background: \"#22222a\",\n border: \"1px solid #3a3a42\",\n color: \"#e6e6e6\",\n borderRadius: 5,\n padding: \"3px 8px\",\n font: \"inherit\",\n cursor: \"pointer\",\n } satisfies CSSProperties,\n} as const;\n","import { type ReactNode, useState } from \"react\";\nimport { isDevToolsBuild } from \"../core/env\";\nimport type { z } from \"zod\";\nimport type { Form } from \"../core/createForm\";\nimport type {\n DefaultPathDepth,\n FieldPath,\n PathDepth,\n} from \"../core/fieldPath\";\nimport { getAtPath } from \"../core/path\";\nimport type { FormState } from \"../core/types\";\nimport { useFormSelectorShallow } from \"../react/useFormSelector\";\nimport { leafPaths, unmatchedErrorKeys } from \"./paths\";\nimport { type DevtoolsPosition, anchorFor, styles } from \"./styles\";\n\n// D (the form's typed-path depth budget) is carried so a `pathDepth: 12`\n// form is accepted: Form<S, 12> is deliberately not assignable to Form<S, 9>,\n// so the depth-less prop type rejected every widened form (TS2375).\nexport type FormstandDevtoolsProps<\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n> = Readonly<{\n form: Form<TSchema, D>;\n position?: DevtoolsPosition;\n defaultOpen?: boolean;\n /** Shown on the toggle, for telling two mounted panels apart. */\n label?: string;\n /**\n * Overrides the build gate. Unset, the panel renders only where NODE_ENV\n * is readable and not \"production\", which is what an app wants. `true`\n * mounts it regardless, for the one place where showing the form state\n * IS the page's purpose (a demo, an internal tool shipped in production\n * mode); `false` hides it in development without unmounting the form.\n */\n enabled?: boolean;\n}>;\n\ntype FieldRow = Readonly<{\n path: string;\n value: unknown;\n error: readonly string[] | undefined;\n touched: boolean;\n dirty: boolean;\n isValidating: boolean;\n}>;\n\n// Non-production only, matching createForm's own devtools gate: the panel is\n// a debugging affordance, and shipping it to end users would leak the whole\n// form state into the page. Bundlers that define NODE_ENV drop the panel\n// entirely. The gate fails CLOSED (isDevToolsBuild): a runtime with no\n// readable NODE_ENV at all (a CDN/ESM consumer, Deno, a worker) renders\n// nothing rather than assuming it is a dev build the way the console\n// warnings may.\n\nconst preview = (value: unknown): string => {\n if (value === undefined) return \"undefined\";\n if (value instanceof Date) return value.toISOString();\n const json = JSON.stringify(value);\n // Long strings and big row objects would push the value column past the\n // panel; the full value is one expand away in the Values section.\n return json === undefined\n ? String(value)\n : json.length > 60\n ? `${json.slice(0, 57)}…`\n : json;\n};\n\nconst flags = (row: FieldRow): string =>\n [\n row.touched ? \"touched\" : \"\",\n row.dirty ? \"dirty\" : \"\",\n row.isValidating ? \"validating\" : \"\",\n ]\n .filter((flag) => flag !== \"\")\n .join(\" \");\n\n// Reads every slice the panel renders in ONE shallow-compared subscription.\n// Each member is a stored reference the form replaces on write, so shallow\n// equality is stable — deriving anything fresh (an array from dirtyFields())\n// inside the selector would hand the store a new reference every pass and\n// loop it (React #185).\nconst useDevtoolsState = <TSchema extends z.ZodType, D extends PathDepth>(\n form: Form<TSchema, D>,\n) =>\n useFormSelectorShallow(form, (state) => ({\n values: state.values,\n errors: state.errors,\n schemaErrors: state.schemaErrors,\n serverErrors: state.serverErrors,\n touched: state.touched,\n isValidating: state.isValidating,\n isSubmitting: state.isSubmitting,\n isValidatingForm: state.isValidatingForm,\n submitCount: state.submitCount,\n mode: state.mode,\n }));\n\nconst Section = ({\n title,\n children,\n}: Readonly<{ title: string; children: ReactNode }>) => (\n <div style={styles.section}>\n <p style={styles.sectionTitle}>{title}</p>\n {children}\n </div>\n);\n\nconst DevtoolsPanel = <TSchema extends z.ZodType, D extends PathDepth>({\n form,\n position = \"bottom-right\",\n defaultOpen = false,\n label = \"formstand\",\n}: FormstandDevtoolsProps<TSchema, D>) => {\n const state = useDevtoolsState(form);\n const [open, setOpen] = useState(defaultOpen);\n const [held, setHeld] = useState<FormState<z.input<TSchema>> | null>(null);\n\n // Computed every render rather than memoized. getFieldState and diff() read\n // through `form`, not through anything in a dependency array, so a memo\n // would need deps the linter can't see and would go stale the moment one\n // was missed. This component only re-renders when the subscription above\n // reports a real change, so recomputing is both cheap and always right.\n const rows: readonly FieldRow[] = leafPaths(state.values).map((path) => {\n // Runtime-built strings need the cast the typed surface documents.\n // getFieldState rather than re-deriving dirty here, so the panel reports\n // the library's own comparison rules (Dates by timestamp, deep for\n // containers) instead of offering a second opinion.\n const field = form.getFieldState(path as FieldPath<z.input<TSchema>, D>);\n return {\n path,\n value: field.value,\n error: field.error,\n touched: field.touched,\n dirty: field.dirty,\n isValidating: field.isValidating,\n };\n });\n\n const orphanErrors = unmatchedErrorKeys(\n Object.keys(state.errors),\n rows.map((row) => row.path),\n );\n\n const diff = form.diff();\n\n return (\n <div style={{ ...styles.root, ...anchorFor(position) }}>\n {open ? (\n <div style={styles.panel}>\n <div style={styles.header}>\n <strong>{label}</strong>\n <span style={styles.muted}>\n {state.mode}\n {state.isSubmitting ? \" · submitting\" : \"\"}\n {state.isValidatingForm ? \" · validating\" : \"\"}\n {state.submitCount > 0 ? ` · submits ${state.submitCount}` : \"\"}\n </span>\n <button\n type=\"button\"\n style={styles.button}\n onClick={() => setOpen(false)}\n >\n close\n </button>\n </div>\n\n <Section title={`fields (${rows.length})`}>\n <table style={styles.table}>\n <thead>\n <tr>\n <th style={{ ...styles.th, width: \"38%\" }}>path</th>\n <th style={styles.th}>value</th>\n <th style={{ ...styles.th, width: \"26%\" }}>state</th>\n </tr>\n </thead>\n <tbody>\n {rows.map((row) => (\n <tr key={row.path}>\n <td style={{ ...styles.td, ...styles.path }}>{row.path}</td>\n <td style={styles.td}>\n {preview(row.value)}\n {row.error === undefined ? null : (\n <div style={styles.error}>{row.error.join(\", \")}</div>\n )}\n </td>\n <td style={{ ...styles.td, ...styles.flag }}>\n {flags(row)}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </Section>\n\n {orphanErrors.length === 0 ? null : (\n // Errors with no field of their own: the root \"\" key, array-level\n // messages, server verdicts on paths that hold no value yet.\n <Section title=\"errors without a field\">\n {orphanErrors.map((key) => (\n <div key={key}>\n <span style={styles.path}>{key === \"\" ? \"(root)\" : key}</span>{\" \"}\n <span style={styles.error}>\n {(state.errors[key] ?? []).join(\", \")}\n </span>\n </div>\n ))}\n </Section>\n )}\n\n <Section title=\"error channels\">\n <div style={styles.muted}>\n schema {Object.keys(state.schemaErrors).length} · server{\" \"}\n {Object.keys(state.serverErrors).length}\n </div>\n {Object.entries(state.serverErrors).map(([key, messages]) => (\n <div key={key}>\n <span style={styles.path}>{key === \"\" ? \"(root)\" : key}</span>{\" \"}\n <span style={styles.error}>{messages.join(\", \")}</span>{\" \"}\n <span style={styles.muted}>\n {getAtPath(state.schemaErrors, key) === undefined\n ? \"(showing)\"\n : \"(behind a schema error)\"}\n </span>\n </div>\n ))}\n </Section>\n\n <Section title=\"diff vs initial\">\n <pre style={styles.pre}>\n {Object.keys(diff).length === 0\n ? \"clean\"\n : JSON.stringify(diff, null, 2)}\n </pre>\n </Section>\n\n <Section title=\"time travel\">\n <button\n type=\"button\"\n style={styles.button}\n onClick={() => setHeld(form.snapshot())}\n >\n snapshot\n </button>{\" \"}\n <button\n type=\"button\"\n style={styles.button}\n disabled={held === null}\n onClick={() => {\n if (held !== null) form.restore(held);\n }}\n >\n restore\n </button>{\" \"}\n <span style={styles.muted}>\n {held === null ? \"nothing held\" : \"snapshot held\"}\n </span>\n </Section>\n </div>\n ) : (\n <button\n type=\"button\"\n style={styles.toggle}\n onClick={() => setOpen(true)}\n >\n {label}\n {Object.keys(state.errors).length > 0\n ? ` · ${String(Object.keys(state.errors).length)} err`\n : \"\"}\n </button>\n )}\n </div>\n );\n};\n\n/**\n * A form-aware debugging panel: every field's value, error, and flags, the\n * two error channels shown separately, the live diff against initial values,\n * and snapshot/restore time travel.\n *\n * Renders nothing in production builds, and nothing wherever NODE_ENV is not\n * readable (no `process` global, or one without NODE_ENV): the panel exposes\n * the whole form state, so an unknowable environment is treated as shipped.\n */\nexport const FormstandDevtools = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>({\n enabled,\n ...props\n}: FormstandDevtoolsProps<TSchema, D>) =>\n (enabled ?? isDevToolsBuild()) ? <DevtoolsPanel {...props} /> : null;\n"]}
|
|
@@ -11,6 +11,14 @@ type FormstandDevtoolsProps<TSchema extends z.ZodType, D extends PathDepth = Def
|
|
|
11
11
|
defaultOpen?: boolean;
|
|
12
12
|
/** Shown on the toggle, for telling two mounted panels apart. */
|
|
13
13
|
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Overrides the build gate. Unset, the panel renders only where NODE_ENV
|
|
16
|
+
* is readable and not "production", which is what an app wants. `true`
|
|
17
|
+
* mounts it regardless, for the one place where showing the form state
|
|
18
|
+
* IS the page's purpose (a demo, an internal tool shipped in production
|
|
19
|
+
* mode); `false` hides it in development without unmounting the form.
|
|
20
|
+
*/
|
|
21
|
+
enabled?: boolean;
|
|
14
22
|
}>;
|
|
15
23
|
/**
|
|
16
24
|
* A form-aware debugging panel: every field's value, error, and flags, the
|
|
@@ -21,7 +29,7 @@ type FormstandDevtoolsProps<TSchema extends z.ZodType, D extends PathDepth = Def
|
|
|
21
29
|
* readable (no `process` global, or one without NODE_ENV): the panel exposes
|
|
22
30
|
* the whole form state, so an unknowable environment is treated as shipped.
|
|
23
31
|
*/
|
|
24
|
-
declare const FormstandDevtools: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(props: FormstandDevtoolsProps<TSchema, D>) => react.JSX.Element | null;
|
|
32
|
+
declare const FormstandDevtools: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>({ enabled, ...props }: FormstandDevtoolsProps<TSchema, D>) => react.JSX.Element | null;
|
|
25
33
|
|
|
26
34
|
declare const leafPaths: (value: unknown, base?: string) => readonly string[];
|
|
27
35
|
declare const unmatchedErrorKeys: (errorKeys: readonly string[], leaves: readonly string[]) => readonly string[];
|
package/dist/devtools/index.d.ts
CHANGED
|
@@ -11,6 +11,14 @@ type FormstandDevtoolsProps<TSchema extends z.ZodType, D extends PathDepth = Def
|
|
|
11
11
|
defaultOpen?: boolean;
|
|
12
12
|
/** Shown on the toggle, for telling two mounted panels apart. */
|
|
13
13
|
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Overrides the build gate. Unset, the panel renders only where NODE_ENV
|
|
16
|
+
* is readable and not "production", which is what an app wants. `true`
|
|
17
|
+
* mounts it regardless, for the one place where showing the form state
|
|
18
|
+
* IS the page's purpose (a demo, an internal tool shipped in production
|
|
19
|
+
* mode); `false` hides it in development without unmounting the form.
|
|
20
|
+
*/
|
|
21
|
+
enabled?: boolean;
|
|
14
22
|
}>;
|
|
15
23
|
/**
|
|
16
24
|
* A form-aware debugging panel: every field's value, error, and flags, the
|
|
@@ -21,7 +29,7 @@ type FormstandDevtoolsProps<TSchema extends z.ZodType, D extends PathDepth = Def
|
|
|
21
29
|
* readable (no `process` global, or one without NODE_ENV): the panel exposes
|
|
22
30
|
* the whole form state, so an unknowable environment is treated as shipped.
|
|
23
31
|
*/
|
|
24
|
-
declare const FormstandDevtools: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(props: FormstandDevtoolsProps<TSchema, D>) => react.JSX.Element | null;
|
|
32
|
+
declare const FormstandDevtools: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>({ enabled, ...props }: FormstandDevtoolsProps<TSchema, D>) => react.JSX.Element | null;
|
|
25
33
|
|
|
26
34
|
declare const leafPaths: (value: unknown, base?: string) => readonly string[];
|
|
27
35
|
declare const unmatchedErrorKeys: (errorKeys: readonly string[], leaves: readonly string[]) => readonly string[];
|
package/dist/devtools/index.js
CHANGED
|
@@ -268,7 +268,10 @@ var DevtoolsPanel = ({
|
|
|
268
268
|
}
|
|
269
269
|
) });
|
|
270
270
|
};
|
|
271
|
-
var FormstandDevtools = (
|
|
271
|
+
var FormstandDevtools = ({
|
|
272
|
+
enabled,
|
|
273
|
+
...props
|
|
274
|
+
}) => enabled ?? isDevToolsBuild() ? /* @__PURE__ */ jsx(DevtoolsPanel, { ...props }) : null;
|
|
272
275
|
|
|
273
276
|
export { FormstandDevtools, leafPaths, unmatchedErrorKeys };
|
|
274
277
|
//# sourceMappingURL=index.js.map
|