formstand 0.19.0 → 0.21.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.
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ // src/core/mode.ts
4
+ var shouldValidateOn = (trigger, mode, reValidateMode, submitAttempted, touched = false) => {
5
+ const effective = submitAttempted ? reValidateMode : mode;
6
+ switch (effective) {
7
+ case "onChange":
8
+ return trigger === "change";
9
+ case "onBlur":
10
+ return trigger === "blur";
11
+ case "onSubmit":
12
+ return false;
13
+ case "onTouched":
14
+ return trigger === "blur" || touched;
15
+ case "all":
16
+ return true;
17
+ }
18
+ };
19
+
20
+ // src/testing/index.ts
21
+ var fillField = (form, path, value) => {
22
+ const before = form.store.getState();
23
+ form.setValue(path, value);
24
+ const state = form.store.getState();
25
+ if (state === before) return;
26
+ if (shouldValidateOn(
27
+ "change",
28
+ state.mode,
29
+ state.reValidateMode,
30
+ state.submitCount > 0,
31
+ state.touched[path] ?? false
32
+ )) {
33
+ form.validateField(path);
34
+ }
35
+ };
36
+ var blurField = (form, path) => {
37
+ form.setTouched(path, true);
38
+ const state = form.store.getState();
39
+ if (shouldValidateOn(
40
+ "blur",
41
+ state.mode,
42
+ state.reValidateMode,
43
+ state.submitCount > 0,
44
+ true
45
+ )) {
46
+ form.validateField(path);
47
+ }
48
+ };
49
+ var fillAndBlurField = (form, path, value) => {
50
+ fillField(form, path, value);
51
+ blurField(form, path);
52
+ };
53
+ var fillFields = (form, values) => {
54
+ Object.entries(values).forEach(([path, value]) => {
55
+ fillField(
56
+ form,
57
+ path,
58
+ value
59
+ );
60
+ });
61
+ };
62
+ var submitForm = (form) => form.submit(() => void 0);
63
+
64
+ exports.blurField = blurField;
65
+ exports.fillAndBlurField = fillAndBlurField;
66
+ exports.fillField = fillField;
67
+ exports.fillFields = fillFields;
68
+ exports.submitForm = submitForm;
69
+ //# sourceMappingURL=index.cjs.map
70
+ //# sourceMappingURL=index.cjs.map
@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IAAA,CAAK,KAAA,CAAM,QAAA,EAAS;AAClC,EAAA,IACE,gBAAA;AAAA,IACE,MAAA;AAAA,IACA,KAAA,CAAM,IAAA;AAAA,IACN,KAAA,CAAM,cAAA;AAAA,IACN,MAAM,WAAA,GAAc,CAAA;AAAA,IACpB;AAAA,GACF,EACA;AACA,IAAA,IAAA,CAAK,cAAc,IAAI,CAAA;AAAA,EACzB;AACF;AAIO,IAAM,gBAAA,GAAmB,CAK9B,IAAA,EACA,IAAA,EACA,KAAA,KACS;AACT,EAAA,SAAA,CAAU,IAAA,EAAM,MAAM,KAAK,CAAA;AAC3B,EAAA,SAAA,CAAU,MAAM,IAAI,CAAA;AACtB;AAMO,IAAM,UAAA,GAAa,CAIxB,IAAA,EACA,MAAA,KAGS;AACT,EAAA,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAC,IAAA,EAAM,KAAK,CAAA,KAAM;AAChD,IAAA,SAAA;AAAA,MACE,IAAA;AAAA,MACA,IAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF,CAAC,CAAA;AACH;AAQO,IAAM,aAAa,CAIxB,IAAA,KAC6C,IAAA,CAAK,MAAA,CAAO,MAAM,MAAS","file":"index.cjs","sourcesContent":["export type ValidationMode =\n | \"onChange\"\n | \"onBlur\"\n | \"onSubmit\"\n // Validate on blur always; on change only once the field has been touched.\n | \"onTouched\"\n // Validate on both change and blur.\n | \"all\";\n\nexport type ValidationTrigger = \"change\" | \"blur\";\n\nexport const shouldValidateOn = (\n trigger: ValidationTrigger,\n mode: ValidationMode,\n reValidateMode: ValidationMode,\n submitAttempted: boolean,\n touched: boolean = false,\n): boolean => {\n const effective = submitAttempted ? reValidateMode : mode;\n switch (effective) {\n case \"onChange\":\n return trigger === \"change\";\n case \"onBlur\":\n return trigger === \"blur\";\n case \"onSubmit\":\n return false;\n case \"onTouched\":\n return trigger === \"blur\" || touched;\n case \"all\":\n return true;\n }\n};\n","import type { z } from \"zod\";\nimport type { Form, SubmitResult } from \"../core/createForm\";\nimport type {\n DefaultPathDepth,\n FieldPath,\n FieldValue,\n PathDepth,\n} from \"../core/fieldPath\";\nimport { shouldValidateOn } from \"../core/mode\";\n\n// formstand/testing: drive a form in tests the way the HOOKS drive it —\n// mode-gated validation included — without mounting components. Tests\n// that call form.setValue directly get the imperative, validation-silent\n// write (correct for the imperative API, wrong for simulating a user),\n// and re-deriving the change/blur gates by hand is exactly the kind of\n// mode-semantics knowledge a test should not have to carry. These\n// helpers restate useField's own recipes over the core API, so a test\n// exercises the same validation flow a rendered input would, at store\n// speed. They are framework-agnostic on purpose: they return plain data\n// and write plain state; your test runner's assertions do the judging.\n\n// A user edit: write the value, then validate under the CHANGE gate —\n// exactly useField's setValue, including the no-op guard (writing the\n// identical value leaves state untouched, so the gate is skipped too).\nexport const fillField = <\n TSchema extends z.ZodType,\n P extends FieldPath<z.input<TSchema>, D>,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n path: P,\n value: FieldValue<z.input<TSchema>, P>,\n): void => {\n const before = form.store.getState();\n form.setValue(path, value);\n const state = form.store.getState();\n if (state === before) return;\n if (\n shouldValidateOn(\n \"change\",\n state.mode,\n state.reValidateMode,\n state.submitCount > 0,\n state.touched[path] ?? false,\n )\n ) {\n form.validateField(path);\n }\n};\n\n// A user leaving the field: mark it touched, then validate under the\n// BLUR gate — exactly useField's onBlur.\nexport const blurField = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n path: FieldPath<z.input<TSchema>, D>,\n): void => {\n form.setTouched(path, true);\n const state = form.store.getState();\n if (\n shouldValidateOn(\n \"blur\",\n state.mode,\n state.reValidateMode,\n state.submitCount > 0,\n true,\n )\n ) {\n form.validateField(path);\n }\n};\n\n// Edit-then-leave, the way a user fills a form field. The common case in\n// a test that wants touched-gated error UIs to show what they would show.\nexport const fillAndBlurField = <\n TSchema extends z.ZodType,\n P extends FieldPath<z.input<TSchema>, D>,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n path: P,\n value: FieldValue<z.input<TSchema>, P>,\n): void => {\n fillField(form, path, value);\n blurField(form, path);\n};\n\n// Fill several fields in one call — entries are applied in order, each\n// through the full fillField recipe. The object shape is deliberately\n// runtime-keyed (a test's fixture data), so values are checked per key\n// where the paths are literal and degrade to unknown otherwise.\nexport const fillFields = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n values: Readonly<\n Partial<Record<FieldPath<z.input<TSchema>, D>, unknown>>\n >,\n): void => {\n Object.entries(values).forEach(([path, value]) => {\n fillField(\n form,\n path as FieldPath<z.input<TSchema>, D>,\n value as never,\n );\n });\n};\n\n// Submit with a no-op handler and hand back the SubmitResult: \"valid\"\n// carries the parsed z.output data, \"invalid\" the ErrorMap (written to\n// the store and marked touched, like any failed submit), \"error\" cannot\n// occur (the handler cannot throw), and \"skipped\" means a submit was\n// already in flight. Await it and switch — the discriminant does the\n// asserting-shape work.\nexport const submitForm = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n): Promise<SubmitResult<z.output<TSchema>>> => form.submit(() => undefined);\n"]}
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ import { P as PathDepth, D as DefaultPathDepth, F as Form, c as FieldPath, d as FieldValue, l as SubmitResult } from '../createForm-B73p1TgL.cjs';
3
+ import 'zustand/vanilla';
4
+
5
+ declare const fillField: <TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P, value: FieldValue<z.input<TSchema>, P>) => void;
6
+ declare const blurField: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: FieldPath<z.input<TSchema>, D>) => void;
7
+ declare const fillAndBlurField: <TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P, value: FieldValue<z.input<TSchema>, P>) => void;
8
+ declare const fillFields: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, values: Readonly<Partial<Record<FieldPath<z.input<TSchema>, D>, unknown>>>) => void;
9
+ declare const submitForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>) => Promise<SubmitResult<z.output<TSchema>>>;
10
+
11
+ export { blurField, fillAndBlurField, fillField, fillFields, submitForm };
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ import { P as PathDepth, D as DefaultPathDepth, F as Form, c as FieldPath, d as FieldValue, l as SubmitResult } from '../createForm-B73p1TgL.js';
3
+ import 'zustand/vanilla';
4
+
5
+ declare const fillField: <TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P, value: FieldValue<z.input<TSchema>, P>) => void;
6
+ declare const blurField: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: FieldPath<z.input<TSchema>, D>) => void;
7
+ declare const fillAndBlurField: <TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P, value: FieldValue<z.input<TSchema>, P>) => void;
8
+ declare const fillFields: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, values: Readonly<Partial<Record<FieldPath<z.input<TSchema>, D>, unknown>>>) => void;
9
+ declare const submitForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>) => Promise<SubmitResult<z.output<TSchema>>>;
10
+
11
+ export { blurField, fillAndBlurField, fillField, fillFields, submitForm };
@@ -0,0 +1,49 @@
1
+ import { shouldValidateOn } from '../chunk-MQ6262S3.js';
2
+
3
+ // src/testing/index.ts
4
+ var fillField = (form, path, value) => {
5
+ const before = form.store.getState();
6
+ form.setValue(path, value);
7
+ const state = form.store.getState();
8
+ if (state === before) return;
9
+ if (shouldValidateOn(
10
+ "change",
11
+ state.mode,
12
+ state.reValidateMode,
13
+ state.submitCount > 0,
14
+ state.touched[path] ?? false
15
+ )) {
16
+ form.validateField(path);
17
+ }
18
+ };
19
+ var blurField = (form, path) => {
20
+ form.setTouched(path, true);
21
+ const state = form.store.getState();
22
+ if (shouldValidateOn(
23
+ "blur",
24
+ state.mode,
25
+ state.reValidateMode,
26
+ state.submitCount > 0,
27
+ true
28
+ )) {
29
+ form.validateField(path);
30
+ }
31
+ };
32
+ var fillAndBlurField = (form, path, value) => {
33
+ fillField(form, path, value);
34
+ blurField(form, path);
35
+ };
36
+ var fillFields = (form, values) => {
37
+ Object.entries(values).forEach(([path, value]) => {
38
+ fillField(
39
+ form,
40
+ path,
41
+ value
42
+ );
43
+ });
44
+ };
45
+ var submitForm = (form) => form.submit(() => void 0);
46
+
47
+ export { blurField, fillAndBlurField, fillField, fillFields, submitForm };
48
+ //# sourceMappingURL=index.js.map
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/testing/index.ts"],"names":[],"mappings":";;;AAwBO,IAAM,SAAA,GAAY,CAKvB,IAAA,EACA,IAAA,EACA,KAAA,KACS;AACT,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,QAAA,EAAS;AACnC,EAAA,IAAA,CAAK,QAAA,CAAS,MAAM,KAAK,CAAA;AACzB,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,QAAA,EAAS;AAClC,EAAA,IAAI,UAAU,MAAA,EAAQ;AACtB,EAAA,IACE,gBAAA;AAAA,IACE,QAAA;AAAA,IACA,KAAA,CAAM,IAAA;AAAA,IACN,KAAA,CAAM,cAAA;AAAA,IACN,MAAM,WAAA,GAAc,CAAA;AAAA,IACpB,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,IAAK;AAAA,GACzB,EACA;AACA,IAAA,IAAA,CAAK,cAAc,IAAI,CAAA;AAAA,EACzB;AACF;AAIO,IAAM,SAAA,GAAY,CAIvB,IAAA,EACA,IAAA,KACS;AACT,EAAA,IAAA,CAAK,UAAA,CAAW,MAAM,IAAI,CAAA;AAC1B,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,QAAA,EAAS;AAClC,EAAA,IACE,gBAAA;AAAA,IACE,MAAA;AAAA,IACA,KAAA,CAAM,IAAA;AAAA,IACN,KAAA,CAAM,cAAA;AAAA,IACN,MAAM,WAAA,GAAc,CAAA;AAAA,IACpB;AAAA,GACF,EACA;AACA,IAAA,IAAA,CAAK,cAAc,IAAI,CAAA;AAAA,EACzB;AACF;AAIO,IAAM,gBAAA,GAAmB,CAK9B,IAAA,EACA,IAAA,EACA,KAAA,KACS;AACT,EAAA,SAAA,CAAU,IAAA,EAAM,MAAM,KAAK,CAAA;AAC3B,EAAA,SAAA,CAAU,MAAM,IAAI,CAAA;AACtB;AAMO,IAAM,UAAA,GAAa,CAIxB,IAAA,EACA,MAAA,KAGS;AACT,EAAA,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAC,IAAA,EAAM,KAAK,CAAA,KAAM;AAChD,IAAA,SAAA;AAAA,MACE,IAAA;AAAA,MACA,IAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF,CAAC,CAAA;AACH;AAQO,IAAM,aAAa,CAIxB,IAAA,KAC6C,IAAA,CAAK,MAAA,CAAO,MAAM,MAAS","file":"index.js","sourcesContent":["import type { z } from \"zod\";\nimport type { Form, SubmitResult } from \"../core/createForm\";\nimport type {\n DefaultPathDepth,\n FieldPath,\n FieldValue,\n PathDepth,\n} from \"../core/fieldPath\";\nimport { shouldValidateOn } from \"../core/mode\";\n\n// formstand/testing: drive a form in tests the way the HOOKS drive it —\n// mode-gated validation included — without mounting components. Tests\n// that call form.setValue directly get the imperative, validation-silent\n// write (correct for the imperative API, wrong for simulating a user),\n// and re-deriving the change/blur gates by hand is exactly the kind of\n// mode-semantics knowledge a test should not have to carry. These\n// helpers restate useField's own recipes over the core API, so a test\n// exercises the same validation flow a rendered input would, at store\n// speed. They are framework-agnostic on purpose: they return plain data\n// and write plain state; your test runner's assertions do the judging.\n\n// A user edit: write the value, then validate under the CHANGE gate —\n// exactly useField's setValue, including the no-op guard (writing the\n// identical value leaves state untouched, so the gate is skipped too).\nexport const fillField = <\n TSchema extends z.ZodType,\n P extends FieldPath<z.input<TSchema>, D>,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n path: P,\n value: FieldValue<z.input<TSchema>, P>,\n): void => {\n const before = form.store.getState();\n form.setValue(path, value);\n const state = form.store.getState();\n if (state === before) return;\n if (\n shouldValidateOn(\n \"change\",\n state.mode,\n state.reValidateMode,\n state.submitCount > 0,\n state.touched[path] ?? false,\n )\n ) {\n form.validateField(path);\n }\n};\n\n// A user leaving the field: mark it touched, then validate under the\n// BLUR gate — exactly useField's onBlur.\nexport const blurField = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n path: FieldPath<z.input<TSchema>, D>,\n): void => {\n form.setTouched(path, true);\n const state = form.store.getState();\n if (\n shouldValidateOn(\n \"blur\",\n state.mode,\n state.reValidateMode,\n state.submitCount > 0,\n true,\n )\n ) {\n form.validateField(path);\n }\n};\n\n// Edit-then-leave, the way a user fills a form field. The common case in\n// a test that wants touched-gated error UIs to show what they would show.\nexport const fillAndBlurField = <\n TSchema extends z.ZodType,\n P extends FieldPath<z.input<TSchema>, D>,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n path: P,\n value: FieldValue<z.input<TSchema>, P>,\n): void => {\n fillField(form, path, value);\n blurField(form, path);\n};\n\n// Fill several fields in one call — entries are applied in order, each\n// through the full fillField recipe. The object shape is deliberately\n// runtime-keyed (a test's fixture data), so values are checked per key\n// where the paths are literal and degrade to unknown otherwise.\nexport const fillFields = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n values: Readonly<\n Partial<Record<FieldPath<z.input<TSchema>, D>, unknown>>\n >,\n): void => {\n Object.entries(values).forEach(([path, value]) => {\n fillField(\n form,\n path as FieldPath<z.input<TSchema>, D>,\n value as never,\n );\n });\n};\n\n// Submit with a no-op handler and hand back the SubmitResult: \"valid\"\n// carries the parsed z.output data, \"invalid\" the ErrorMap (written to\n// the store and marked touched, like any failed submit), \"error\" cannot\n// occur (the handler cannot throw), and \"skipped\" means a submit was\n// already in flight. Await it and switch — the discriminant does the\n// asserting-shape work.\nexport const submitForm = <\n TSchema extends z.ZodType,\n D extends PathDepth = DefaultPathDepth,\n>(\n form: Form<TSchema, D>,\n): Promise<SubmitResult<z.output<TSchema>>> => form.submit(() => undefined);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formstand",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Zod-schema-first React 19 form library backed by zustand",
5
5
  "license": "MIT",
6
6
  "author": "Tim Frank <timfrankdev@gmail.com>",
@@ -41,6 +41,16 @@
41
41
  "default": "./dist/devtools/index.cjs"
42
42
  }
43
43
  },
44
+ "./testing": {
45
+ "import": {
46
+ "types": "./dist/testing/index.d.ts",
47
+ "default": "./dist/testing/index.js"
48
+ },
49
+ "require": {
50
+ "types": "./dist/testing/index.d.cts",
51
+ "default": "./dist/testing/index.cjs"
52
+ }
53
+ },
44
54
  "./package.json": "./package.json"
45
55
  },
46
56
  "files": [
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/equality.ts","../src/core/path.ts","../src/react/useFormSelector.ts"],"names":[],"mappings":";;;;AAAO,IAAM,aAAA,GAAgB,CAAC,CAAA,KAA6C;AACzE,EAAA,IAAI,OAAO,CAAA,KAAM,QAAA,IAAY,CAAA,KAAM,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,CAAS,IAAA,CAAK,KAAA,EAAO,UAAA,CAAW,QAAQ,CAAC,CAAA;AAClD","file":"chunk-N7WPXYCU.js","sourcesContent":["export const isPlainObject = (v: unknown): v is Record<string, unknown> => {\n if (typeof v !== \"object\" || v === null) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n};\n\n// Structural equality used to decide whether a field still matches its initial\n// value. Recurses into arrays and plain objects; Dates compare by timestamp\n// (re-picking the same date must not leave the field permanently dirty);\n// other exotic objects fall back to Object.is so a real change is never\n// mistaken for \"unchanged\".\nexport const valuesEqual = (a: unknown, b: unknown): boolean => {\n if (Object.is(a, b)) return true;\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((v, i) => valuesEqual(v, b[i]));\n }\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n // hasOwn matters: equal counts don't imply equal key SETS. Without it,\n // { realname: undefined } vs { nickname: \"Ann\" } passes (1 === 1, and\n // a.realname === missing b.realname === undefined) without b's real key\n // ever being inspected — dirty tracking would read a real change as\n // clean. With hasOwn plus the length check the key sets must match, so\n // the compare is also symmetric.\n return (\n aKeys.length === bKeys.length &&\n aKeys.every((k) => Object.hasOwn(b, k) && valuesEqual(a[k], b[k]))\n );\n }\n return false;\n};\n\n// The deep compare for a container-valued field runs inside store selectors\n// and watch subscriptions, i.e. on every store change — cache verdicts per\n// value object, keyed by the initial-slice reference each was computed for.\n// A small list (not a single slot) so distinct fields/forms sharing one value\n// object (a module-level default, a shared sentinel array) coexist instead of\n// evicting each other; bounded so no entry grows without limit. Form state is\n// immutable, so identical references always mean an identical verdict, and\n// the WeakMap releases everything when the value object dies.\ntype DirtyVerdict = Readonly<{ initial: unknown; dirty: boolean }>;\nconst dirtyCache = new WeakMap<object, readonly DirtyVerdict[]>();\nconst MAX_VERDICTS = 4;\n\n// The single definition of dirtiness: the current value slice differs\n// structurally from its initial-values slice. Derived (rather than tracked by\n// writers) so reads are accurate at any depth.\nexport const isFieldDirty = (value: unknown, initialValue: unknown): boolean => {\n if (Object.is(value, initialValue)) return false;\n if (typeof value !== \"object\" || value === null) {\n return !valuesEqual(value, initialValue);\n }\n const cached = dirtyCache.get(value) ?? [];\n const hit = cached.find((v) => Object.is(v.initial, initialValue));\n if (hit !== undefined) return hit.dirty;\n const dirty = !valuesEqual(value, initialValue);\n dirtyCache.set(\n value,\n [{ initial: initialValue, dirty }, ...cached].slice(0, MAX_VERDICTS),\n );\n return dirty;\n};\n","import { isPlainObject } from \"./equality\";\n\nexport type PathSegment = string | number;\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 like equality's dirtyCache: a\n// pathological unbounded key set resets the cache instead of growing it\n// forever (the reset only costs re-parsing, never correctness).\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) return cached;\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) parseCache.clear();\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): readonly unknown[] => {\n const length = Math.max(arr.length, index + 1);\n return Array.from({ length }, (_, i) =>\n i === index ? writeSegments(arr[i], rest, value) : 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): 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);\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 { ...obj, [key]: writeSegments(obj[key], rest, value) };\n }\n\n // Absent (or non-container) value: create a container from the segment type.\n if (typeof head === \"number\") {\n if (refusesHugeIndex(head)) return obj;\n return writeIntoArray([], head, rest, value);\n }\n return { [head]: writeSegments(undefined, rest, value) };\n};\n\nexport const setAtPath = <T>(obj: T, path: string, value: unknown): T =>\n writeSegments(obj, parsePath(path), value) 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"]}