@k8ordo/form 1.4.1 → 1.4.2

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.
@@ -1,4 +1,3 @@
1
- //#region src/async-check.d.ts
2
1
  /**
3
2
  * Ask the server about one field while the person is still filling the form.
4
3
  *
@@ -17,5 +16,4 @@ export type AsyncCheck = {
17
16
  /** True while an answer is outstanding, for disabling submit. */
18
17
  isChecking: boolean;
19
18
  };
20
- export declare const useAsyncCheck: (check: (value: string) => Promise<string | undefined>) => AsyncCheck;
21
- //#endregion
19
+ export declare const useAsyncCheck: (check: (value: string) => Promise<string | undefined>) => AsyncCheck;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useCallback, useEffect, useRef, useState } from "react";
3
- //#region src/async-check.ts
3
+ // src/async-check.ts
4
4
  const useAsyncCheck = (check) => {
5
5
  const control = useRef(null);
6
6
  const latest = useRef(0);
@@ -45,5 +45,4 @@ const useAsyncCheck = (check) => {
45
45
  isChecking
46
46
  };
47
47
  };
48
- //#endregion
49
48
  export { useAsyncCheck };
@@ -1,5 +1,4 @@
1
1
  import { DroppedCheck, FieldInput } from "../types.mjs";
2
- //#region src/derive/attributes.d.ts
3
2
  /** The subset of JSON Schema that `z.toJSONSchema` emits for a leaf field. */
4
3
  export type LeafSchema = {
5
4
  type?: string;
@@ -63,5 +62,4 @@ export type PatternHints = {
63
62
  export declare const attributesFor: (name: string, schema: LeafSchema, required: boolean, hints?: PatternHints) => {
64
63
  input: FieldInput;
65
64
  dropped: DroppedCheck[];
66
- };
67
- //#endregion
65
+ };
@@ -1,4 +1,4 @@
1
- //#region src/derive/attributes.ts
1
+ // src/derive/attributes.ts
2
2
  const controlKindOf = (schema) => {
3
3
  if (schema.format === "binary") return "file";
4
4
  if (schema.enum !== void 0) return "choice";
@@ -181,5 +181,4 @@ const attributesFor = (name, schema, required, hints = {}) => {
181
181
  dropped
182
182
  };
183
183
  };
184
- //#endregion
185
184
  export { attributesFor, controlKindOf, emptySubmissionOf, namesAControl };
@@ -2,7 +2,6 @@ import { FormFields } from "../types.mjs";
2
2
  import { ArrayPathsOf, FieldPathsOf, StringCheckboxPathsOf } from "../paths.mjs";
3
3
  import { ObjectSchema } from "../schema/object-schema.mjs";
4
4
  import { FormDefinition } from "../rules/define-form.mjs";
5
- //#region src/derive/form-fields.d.ts
6
5
  /**
7
6
  * Derive input attributes and messages from one zod object schema.
8
7
  *
@@ -12,5 +11,4 @@ import { FormDefinition } from "../rules/define-form.mjs";
12
11
  * function message — so when one follows the request (its locale, say), call
13
12
  * it during the render, not at module scope.
14
13
  */
15
- export declare const formFields: <Schema extends ObjectSchema>(input: FormDefinition<Schema> | Schema) => FormFields<FieldPathsOf<Schema>, ArrayPathsOf<Schema>, StringCheckboxPathsOf<Schema>>;
16
- //#endregion
14
+ export declare const formFields: <Schema extends ObjectSchema>(input: FormDefinition<Schema> | Schema) => FormFields<FieldPathsOf<Schema>, ArrayPathsOf<Schema>, StringCheckboxPathsOf<Schema>>;
@@ -4,7 +4,7 @@ import { asProbe } from "../schema/object-schema.mjs";
4
4
  import { attributesFor, emptySubmissionOf, namesAControl } from "./attributes.mjs";
5
5
  import { schemaMap, unwrap } from "../schema/walk.mjs";
6
6
  import { messagesFor } from "./messages.mjs";
7
- //#region src/derive/form-fields.ts
7
+ // src/derive/form-fields.ts
8
8
  const objectLevelCheckCount = (schema) => schema._zod?.def?.checks?.length ?? 0;
9
9
  /**
10
10
  * The string formats a leaf declares — its own (`z.email()`) first, then the
@@ -136,5 +136,4 @@ const formFields = (input) => {
136
136
  dropped
137
137
  };
138
138
  };
139
- //#endregion
140
139
  export { formFields };
@@ -1,11 +1,9 @@
1
1
  import { FieldInput, ValidityFlag } from "../types.mjs";
2
2
  import { $ZodType } from "zod/v4/core";
3
- //#region src/derive/messages.d.ts
4
3
  /**
5
4
  * Run each probe through the field's own schema and keep the message zod
6
5
  * returns. A probe that unexpectedly passes simply yields no message for that
7
6
  * flag — the browser's own wording is never used, since it is locale-dependent
8
7
  * and cannot be controlled.
9
8
  */
10
- export declare const messagesFor: (schema: $ZodType, input: FieldInput, required: boolean, emptySubmission: unknown) => Partial<Record<ValidityFlag, string>>;
11
- //#endregion
9
+ export declare const messagesFor: (schema: $ZodType, input: FieldInput, required: boolean, emptySubmission: unknown) => Partial<Record<ValidityFlag, string>>;
@@ -1,5 +1,5 @@
1
1
  import { asProbe } from "../schema/object-schema.mjs";
2
- //#region src/derive/messages.ts
2
+ // src/derive/messages.ts
3
3
  const repeat = (length) => "a".repeat(Math.max(length, 0));
4
4
  const probesFor = (input, required, emptySubmission) => {
5
5
  const probes = [];
@@ -73,5 +73,4 @@ const messagesFor = (schema, input, required, emptySubmission) => {
73
73
  }
74
74
  return messages;
75
75
  };
76
- //#endregion
77
76
  export { messagesFor };
@@ -1,5 +1,4 @@
1
1
  import { FC } from "react";
2
- //#region src/hidden-value.d.ts
3
2
  /**
4
3
  * A hidden input that carries a value the visible component never submits.
5
4
  *
@@ -17,5 +16,4 @@ import { FC } from "react";
17
16
  export declare const HiddenValue: FC<{
18
17
  name: string;
19
18
  value: string;
20
- }>;
21
- //#endregion
19
+ }>;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useCallback, useEffect, useRef } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
- //#region src/hidden-value.tsx
4
+ // src/hidden-value.tsx
5
5
  /**
6
6
  * A hidden input that carries a value the visible component never submits.
7
7
  *
@@ -36,5 +36,4 @@ const HiddenValue = ({ name, value }) => {
36
36
  value
37
37
  });
38
38
  };
39
- //#endregion
40
39
  export { HiddenValue };
@@ -2,7 +2,6 @@ import { FormState } from "../types.mjs";
2
2
  import { ObjectSchema } from "../schema/object-schema.mjs";
3
3
  import { FormDefinition } from "../rules/define-form.mjs";
4
4
  import { output } from "zod/v4/core";
5
- //#region src/parse/parse-form.d.ts
6
5
  export type ParseResult<Output> = {
7
6
  success: true;
8
7
  data: Output;
@@ -21,5 +20,4 @@ export type ParseResult<Output> = {
21
20
  * schema's job via `z.coerce`, so the schema keeps describing what it
22
21
  * actually validates.
23
22
  */
24
- export declare const parseForm: <Shape extends ObjectSchema>(input: FormDefinition<Shape> | Shape, formData: FormData) => ParseResult<output<Shape>>;
25
- //#endregion
23
+ export declare const parseForm: <Shape extends ObjectSchema>(input: FormDefinition<Shape> | Shape, formData: FormData) => ParseResult<output<Shape>>;
@@ -3,7 +3,7 @@ import { asDefinition } from "../rules/define-form.mjs";
3
3
  import { asProbe } from "../schema/object-schema.mjs";
4
4
  import { INDEX, schemaMap } from "../schema/walk.mjs";
5
5
  import { nameOf, setPath } from "./paths.mjs";
6
- //#region src/parse/parse-form.ts
6
+ // src/parse/parse-form.ts
7
7
  /**
8
8
  * The submitted names are the only source for row counts, and anyone can POST
9
9
  * anything: without a ceiling, one forged `items[99999999].name` key makes the
@@ -135,5 +135,4 @@ const parseForm = (input, formData) => {
135
135
  }
136
136
  };
137
137
  };
138
- //#endregion
139
138
  export { parseForm };
@@ -1,4 +1,3 @@
1
- //#region src/parse/paths.d.ts
2
1
  /** One step of a name: an object key, or an array index. */
3
2
  type Step = {
4
3
  key: string;
@@ -16,5 +15,4 @@ export declare const stepsOf: (name: string) => Step[];
16
15
  export declare const setPath: (root: Record<string, unknown>, name: string, value: unknown) => void;
17
16
  /** Turn a zod issue path into the `name` of the input that produced it. */
18
17
  export declare const nameOf: (path: readonly PropertyKey[]) => string;
19
- //#endregion
20
18
  export {};
@@ -1,4 +1,4 @@
1
- //#region src/parse/paths.ts
1
+ // src/parse/paths.ts
2
2
  const STEP = /([^.[\]]+)|\[(\d+)\]/gu;
3
3
  /** Split `items[1].name` into its steps. */
4
4
  const stepsOf = (name) => {
@@ -48,5 +48,4 @@ const nameOf = (path) => {
48
48
  else name += name === "" ? String(segment) : `.${String(segment)}`;
49
49
  return name;
50
50
  };
51
- //#endregion
52
51
  export { nameOf, setPath, stepsOf };
package/dist/paths.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/paths.d.ts
2
1
  /**
3
2
  * Dotted paths derived from a zod object type, so `field('titel')` fails to
4
3
  * compile rather than at runtime. Arrays of objects are reached through
@@ -82,5 +81,4 @@ type EncodesTrueAsString<Schema> = Schema extends {
82
81
  export type StringCheckboxPathsOf<Schema, Prefix extends string = ''> = Unwrap<Schema> extends (infer Bare) ? Bare extends {
83
82
  shape: infer Shape;
84
83
  } ? { [Key in keyof Shape & string]: StringCheckboxPathsOf<Shape[Key], Join<Prefix, Key>>; }[keyof Shape & string] : Prefix extends '' ? never : EncodesTrueAsString<Bare> extends true ? Prefix : never : never;
85
- //#endregion
86
84
  export {};
@@ -1,7 +1,6 @@
1
1
  import { Rule } from "./rules.mjs";
2
2
  import { FieldPathsOf } from "../paths.mjs";
3
3
  import { ObjectSchema } from "../schema/object-schema.mjs";
4
- //#region src/rules/define-form.d.ts
5
4
  /**
6
5
  * A schema plus the checks HTML cannot express. Declaring them together is
7
6
  * what keeps the client and the server working from one source: `formFields`
@@ -16,5 +15,4 @@ export type FormDefinition<Schema extends ObjectSchema = ObjectSchema> = {
16
15
  };
17
16
  export declare const defineForm: <Schema extends ObjectSchema>(schema: Schema, rules?: Array<Rule<FieldPathsOf<Schema>>>) => FormDefinition<Schema>;
18
17
  /** Accept either a bare schema or a definition, so rules stay optional. */
19
- export declare const asDefinition: <Schema extends ObjectSchema>(input: FormDefinition<Schema> | Schema) => FormDefinition<Schema>;
20
- //#endregion
18
+ export declare const asDefinition: <Schema extends ObjectSchema>(input: FormDefinition<Schema> | Schema) => FormDefinition<Schema>;
@@ -1,4 +1,4 @@
1
- //#region src/rules/define-form.ts
1
+ // src/rules/define-form.ts
2
2
  const defineForm = (schema, rules = []) => ({
3
3
  schema,
4
4
  rules
@@ -8,5 +8,4 @@ const asDefinition = (input) => "schema" in input ? input : {
8
8
  schema: input,
9
9
  rules: []
10
10
  };
11
- //#endregion
12
11
  export { asDefinition, defineForm };
@@ -1,4 +1,3 @@
1
- //#region src/rules/rules.d.ts
2
1
  /**
3
2
  * Checks HTML has no attribute for. They are plain data so they cross to the
4
3
  * client with everything else, and both sides run the same evaluator against
@@ -53,5 +52,4 @@ export declare const requiredWhen: <Field extends string>(field: Field, when: Fi
53
52
  export declare const deriveRule: (rule: Rule) => DerivedRule;
54
53
  /** The message when the rule is broken, or undefined when it holds. */
55
54
  export declare const breachOf: (rule: Rule, values: Values) => string | undefined;
56
- //#endregion
57
55
  export {};
@@ -1,4 +1,4 @@
1
- //#region src/rules/rules.ts
1
+ // src/rules/rules.ts
2
2
  /** The value must equal another field's. Password confirmation, and the like. */
3
3
  const sameAs = (field, other, message) => ({
4
4
  kind: "sameAs",
@@ -38,5 +38,4 @@ const deriveRule = (rule) => ({
38
38
  });
39
39
  /** The message when the rule is broken, or undefined when it holds. */
40
40
  const breachOf = (rule, values) => holds(rule, values) ? void 0 : textOf(rule.message);
41
- //#endregion
42
41
  export { breachOf, deriveRule, minChecked, requiredWhen, sameAs };
@@ -1,5 +1,4 @@
1
1
  import { $ZodObject, $ZodShape, $ZodType } from "zod/v4/core";
2
- //#region src/schema/object-schema.d.ts
3
2
  /**
4
3
  * The common ground between `zod` and `zod/mini`: both build on the shared core
5
4
  * object and both expose `shape`. Accepting this instead of the classic
@@ -30,5 +29,4 @@ export type ProbeSchema = $ZodType & {
30
29
  };
31
30
  };
32
31
  };
33
- export declare const asProbe: (schema: $ZodType) => ProbeSchema;
34
- //#endregion
32
+ export declare const asProbe: (schema: $ZodType) => ProbeSchema;
@@ -1,4 +1,3 @@
1
- //#region src/schema/object-schema.ts
1
+ // src/schema/object-schema.ts
2
2
  const asProbe = (schema) => schema;
3
- //#endregion
4
3
  export { asProbe };
@@ -1,7 +1,6 @@
1
1
  import { ControlKind, LeafSchema } from "../derive/attributes.mjs";
2
2
  import { ObjectSchema } from "./object-schema.mjs";
3
3
  import { $ZodType } from "zod/v4/core";
4
- //#region src/schema/walk.d.ts
5
4
  /** Placeholder an array item's name carries until a row index is known. */
6
5
  export declare const INDEX = "{index}";
7
6
  export type LeafNode = {
@@ -52,5 +51,4 @@ export declare const unwrap: ($schema: $ZodType) => $ZodType;
52
51
  * that becomes a repeatable group. Both the derivation and the parse read this,
53
52
  * so the two can never disagree about what the form contains.
54
53
  */
55
- export declare const schemaMap: (schema: ObjectSchema) => SchemaMap;
56
- //#endregion
54
+ export declare const schemaMap: (schema: ObjectSchema) => SchemaMap;
@@ -1,7 +1,7 @@
1
1
  import { asProbe } from "./object-schema.mjs";
2
2
  import { controlKindOf, emptySubmissionOf } from "../derive/attributes.mjs";
3
3
  import { safeEncode, toJSONSchema } from "zod/v4/core";
4
- //#region src/schema/walk.ts
4
+ // src/schema/walk.ts
5
5
  /** Placeholder an array item's name carries until a row index is known. */
6
6
  const INDEX = "{index}";
7
7
  /**
@@ -191,5 +191,4 @@ const schemaMap = (schema) => {
191
191
  cache.set(schema, out);
192
192
  return out;
193
193
  };
194
- //#endregion
195
194
  export { INDEX, schemaMap, unwrap };
package/dist/types.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { DerivedRule } from "./rules/rules.mjs";
2
- //#region src/types.d.ts
3
2
  /** ValidityState flags a derived field can report a message for. */
4
3
  export type ValidityFlag = 'badInput' | 'patternMismatch' | 'rangeOverflow' | 'rangeUnderflow' | 'stepMismatch' | 'tooLong' | 'tooShort' | 'typeMismatch' | 'valueMissing';
5
4
  /** Attributes spread onto the input element itself. */
@@ -93,5 +92,4 @@ export type FormState = {
93
92
  * as two on the client — content alone cannot tell them apart.
94
93
  */
95
94
  token?: string;
96
- };
97
- //#endregion
95
+ };
@@ -1,6 +1,5 @@
1
1
  import { FieldInput, FormFields, FormState, StringCheckboxInput } from "./types.mjs";
2
2
  import { FocusEvent, Ref, SubmitEvent, SyntheticEvent } from "react";
3
- //#region src/use-form.d.ts
4
3
  export type FieldView<Input extends FieldInput = FieldInput> = {
5
4
  input: Input;
6
5
  error: string | undefined;
@@ -60,5 +59,4 @@ export type UseFormReturn<FieldPath extends string = string, ArrayPath extends s
60
59
  * identity of each repeated row, one dirty flag, and the row counts adding or
61
60
  * removing a row is measured against.
62
61
  */
63
- export declare const useForm: <FieldPath extends string, ArrayPath extends string, StringCheckboxPath extends string = never>(fields: FormFields<FieldPath, ArrayPath, StringCheckboxPath>, state?: FormState) => UseFormReturn<FieldPath, ArrayPath, StringCheckboxPath>;
64
- //#endregion
62
+ export declare const useForm: <FieldPath extends string, ArrayPath extends string, StringCheckboxPath extends string = never>(fields: FormFields<FieldPath, ArrayPath, StringCheckboxPath>, state?: FormState) => UseFormReturn<FieldPath, ArrayPath, StringCheckboxPath>;
package/dist/use-form.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { breachOf } from "./rules/rules.mjs";
3
3
  import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
4
- //#region src/use-form.ts
4
+ // src/use-form.ts
5
5
  const INDEX = "{index}";
6
6
  const FLAGS = [
7
7
  "valueMissing",
@@ -419,5 +419,4 @@ const isSelectDirty = (select) => {
419
419
  const baseline = options.filter((option) => option.defaultSelected).at(-1) ?? (select.size > 1 ? void 0 : options.find((option) => !option.disabled));
420
420
  return select.selectedIndex !== (baseline?.index ?? -1);
421
421
  };
422
- //#endregion
423
422
  export { useForm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k8ordo/form",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Derive HTML constraint attributes and per-field errors from one zod schema. Works without JavaScript.",
5
5
  "keywords": [
6
6
  "constraint-validation",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@arethetypeswrong/cli": "0.18.5",
46
- "@k8ordo/state": "^1.4.1",
46
+ "@k8ordo/state": "^1.4.2",
47
47
  "@types/react": "19.3.0",
48
48
  "@vitejs/plugin-react": "6.1.2",
49
49
  "@vitest/browser-playwright": "5.0.5",
@@ -51,8 +51,8 @@
51
51
  "react": "19.3.1",
52
52
  "react-dom": "19.3.1",
53
53
  "typescript": "7.0.2",
54
- "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
55
- "vite-plus": "1.3.0",
54
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
55
+ "vite-plus": "1.4.0",
56
56
  "vitest": "5.0.5",
57
57
  "vitest-browser-react": "2.3.0",
58
58
  "zod": "4.6.7"