{"version":3,"file":"form.mjs","names":[],"sources":["../src/form/form.context.ts","../src/form/components/form.tsx","../src/form/components/form-when.tsx","../src/form/form-field.model.ts","../src/form/form.model.ts","../src/form/use-form.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { FormModel } from \"./form.model\";\n\nexport const formContext = createContext<FormModel | undefined>(undefined);\nexport const useFormContext = () => {\n  const context = useContext(formContext);\n  if (!context) {\n    throw new Error(\n      \"Form context not available. Make sure you are within the <Form> component or providing the form context manually.\",\n    );\n  }\n  return context;\n};\n\nexport const FormProvider = formContext.Provider;\n\nexport const useFormContextIfAvailable = () => useContext(formContext);\n","import { forwardRef } from \"react\";\nimport { FormProvider } from \"../form.context\";\nimport type { FormModel } from \"../form.model\";\n\nexport interface MobxFormProps extends Omit<\n  React.HTMLProps<HTMLFormElement>,\n  \"form\" | \"action\" | \"method\"\n> {\n  form: FormModel<any>;\n}\n\nexport const MobxForm = forwardRef(function MobxForm(\n  { form, children, ...formProps }: MobxFormProps,\n  ref,\n) {\n  return (\n    <FormProvider value={form}>\n      <form noValidate {...formProps} ref={ref} {...form.props()}>\n        {children}\n      </form>\n    </FormProvider>\n  );\n});\n","import type { TUnion } from \"typebox\";\nimport { Observer } from \"mobx-react-lite\";\nimport type { FormModel } from \"../form.model\";\nimport type { FormFieldModel } from \"../form-field.model\";\nimport type {\n  DiscriminatorKeys,\n  DiscriminatorValue,\n  FormFields,\n  MatchVariant,\n} from \"../form.types\";\n\nexport interface FormWhenProps<T extends TUnion, D extends DiscriminatorKeys<T>, V extends string> {\n  form: FormModel<T>;\n  /** The discriminator field name. */\n  field: D;\n  /** Render the children only while the discriminator field equals this value. */\n  value: V & DiscriminatorValue<T, D>;\n  /** Receives the matching variant's fields. The form itself is already in scope. */\n  children: (fields: FormFields<MatchVariant<T, D, V>>) => React.ReactNode;\n}\n\n/**\n * Renders its children only when the form's discriminator field currently holds\n * `value`, passing the fields narrowed to that variant. Stack one per variant to\n * lay out a discriminated-union form without manual conditionals or casts.\n */\nexport function FormWhen<T extends TUnion, D extends DiscriminatorKeys<T>, V extends string>({\n  form,\n  field,\n  value,\n  children,\n}: FormWhenProps<T, D, V>) {\n  return (\n    <Observer>\n      {() => {\n        const fields = form.rawFields as Record<string, FormFieldModel>;\n        if (fields[field as string]?.value !== value) return null;\n        return <>{children(fields as unknown as FormFields<MatchVariant<T, D, V>>)}</>;\n      }}\n    </Observer>\n  );\n}\n","import Schema, { Validator } from \"typebox/schema\";\nimport * as Value from \"typebox/value\";\nimport * as T from \"typebox\";\nimport { makeAutoObservable, toJS } from \"mobx\";\nimport type { FormFieldConfig } from \"./form.types\";\n\n// TODO: should infer required prop\n// TODO: should also allow for \"id\", defaulting to name\n// TODO: probably shouldn't assume value is of correct type, maybe unknown?\n\nexport class FormFieldModel<T extends T.TSchema = T.TSchema> {\n  readonly name: string;\n  readonly schema: T;\n  readonly config: FormFieldConfig<T>;\n  readonly validator: Validator<T>;\n\n  value: T.Static<T> | undefined;\n  touched = false;\n\n  /**\n   * An error set by hand rather than derived from the schema — typically a server response, or a rule\n   * the schema can't express, applied from inside `handleSubmit`. Use `setError`.\n   *\n   * Distinct from `errorMessage`, which is what to *display*: this one when set, the schema's otherwise.\n   */\n  error: string | undefined = undefined;\n\n  get valid(): boolean {\n    if (this.error) return false;\n    if (this.value === undefined && T.IsOptional(this.schema)) return true;\n    return this.validator.Check(this.value);\n  }\n\n  get errorMessage(): string {\n    // Shown regardless of `touched`: it was set deliberately, usually in response to a submit the\n    // user just made, and a field like a file picker may never be \"touched\" at all.\n    if (this.error) return this.error;\n    if (this.valid || !this.touched) return \"\";\n    // TODO: revisit this, now that .Errors returns success/fail\n    const [_, errors] = this.validator.Errors(this.value);\n    const error = errors.at(0);\n\n    if (!error) return \"\";\n\n    if (!T.IsOptional(this.schema) && (this.value === undefined || this.value === \"\")) {\n      return \"This field is required.\";\n    }\n\n    if (\"errorMessage\" in this.schema) {\n      if (typeof this.schema.errorMessage === \"string\") {\n        return this.schema.errorMessage;\n      } else if (typeof this.schema.errorMessage === \"function\") {\n        return this.schema.errorMessage(this.value, this.schema);\n      }\n    }\n\n    if (T.IsString(this.schema) && \"format\" in this.schema) {\n      return `Please enter a valid ${String(this.schema.format)}`;\n    }\n\n    return error.message;\n  }\n\n  constructor(config: FormFieldConfig<T>) {\n    this.config = config;\n    this.name = config.name;\n    this.schema = config.schema;\n    this.validator = Schema.Compile(this.schema);\n    this.value = this.convertValue(config.initialValue);\n\n    makeAutoObservable(this, {\n      name: false,\n      schema: false,\n      config: false,\n      validator: false,\n    });\n  }\n\n  setValue(value?: T.Static<T>) {\n    // An edit invalidates a message that described the previous value — otherwise \"that username is\n    // taken\" survives the user typing a different one, and the field stays stuck invalid.\n    this.error = undefined;\n    // TODO: does this still make sense? If value is invalid,\n    // then type will be wrong...revisit this\n    this.value = this.convertValue(value);\n  }\n\n  /** Set (or with `undefined`, clear) a manual error. Cleared automatically by an edit, a reset, or the next submit. */\n  setError(error: string | undefined) {\n    this.error = error;\n  }\n\n  private convertValue(value: unknown): T.Static<T> | undefined {\n    // Value.Convert fabricates zero-values for undefined primitives (\"\" / 0 / false).\n    // Only \"\" and false faithfully represent an empty control; a fabricated 0 reads\n    // as real input (e.g. an epoch-0 date), so everything else stays undefined.\n    if (value === undefined && !T.IsString(this.schema) && !T.IsBoolean(this.schema)) {\n      return undefined;\n    }\n    return Value.Convert(this.schema, value) as T.Static<T>;\n  }\n\n  setTouched(touched: boolean) {\n    this.touched = touched;\n  }\n\n  reset() {\n    this.setTouched(false);\n    this.setError(undefined);\n    this.setValue(this.config.initialValue);\n  }\n\n  // TODO: this any type is dangerous, need to figure out a good way\n  // to make this work OTTB for most form controls, while allowing\n  // some kind of escape hatch for special cases\n  props(): any {\n    return {\n      name: this.name,\n      onChange: (v?: T.Static<T>) => this.setValue(v),\n      value: this.value,\n      onBlur: () => {\n        this.setTouched(true);\n      },\n    };\n  }\n\n  toJSON(): T.Static<T> | undefined {\n    return toJS(this.value);\n  }\n}\n","import * as Format from \"typebox/format\";\nimport * as Value from \"typebox/value\";\nimport Schema, { type Validator } from \"typebox/schema\";\nimport { IsUnion, Union, type Static, type TObject, type TSchema } from \"typebox\";\nimport { makeAutoObservable } from \"mobx\";\nimport type { FormConfig, FormFields, FormSchema, RawFormFields } from \"./form.types\";\nimport { FormFieldModel } from \"./form-field.model\";\nimport { flattenVariants, type UnionSchema } from \"../util/union-schema\";\n\n// should these be here?\nFormat.Set(\"password\", () => true);\nFormat.Set(\"phone\", () => true);\n\n// Flatten a schema's fields into a single property map. For a discriminated\n// union this merges the properties of every variant — nested unions included, as\n// `flattenVariants` collapses them — unioning the schemas of any field that appears\n// in more than one variant (which naturally turns the discriminator into a union of\n// its literals).\nfunction resolveProperties(schema: FormSchema): Record<string, TSchema> {\n  if (!IsUnion(schema)) return schema.properties;\n\n  const groups: Record<string, TSchema[]> = {};\n  for (const variant of flattenVariants(schema as UnionSchema)) {\n    for (const [key, propSchema] of Object.entries((variant as TObject).properties)) {\n      (groups[key] ??= []).push(propSchema as TSchema);\n    }\n  }\n\n  const merged: Record<string, TSchema> = {};\n  for (const [key, schemas] of Object.entries(groups)) {\n    const distinct = [...new Map(schemas.map((s) => [JSON.stringify(s), s])).values()];\n    merged[key] = distinct.length === 1 ? distinct[0]! : Union(distinct);\n  }\n  return merged;\n}\n\n// consider using enumerable to allow spreading of\n// field model instead of calling props() unless we need\n// to pass data to props...\n\n// TODO:\n// `field.setError` covers applying API errors to fields, but the caller has to throw afterwards to\n// stop `submitted` being set. A dedicated error thrown from handleSubmit — carrying a\n// { field: message } map and recognised in the catch — would collapse that into one step and keep it\n// out of `submitError`.\n\n// TODO: discriminator-aware union forms (considered 2026-09-01, deferred).\n// `resolveProperties` unions each key's schema across variants and never reads `required`, so a\n// field validates against the loosest schema of any variant and knows nothing about being required\n// by the active one. Whole-object `valid` keeps *submit* correct, but a union form can be invalid\n// with no field-level error anywhere pointing at the culprit — `validate()` clears every field's\n// error and then only asks the whole-object question.\n// Fixing it needs the *active* variant, and structural matching (what `Value.Clean` does) can't\n// supply it: mid-edit a half-filled form matches no variant, which is exactly when field-level\n// errors matter most. A named discriminator can, from the moment that one field is set — so\n// `discriminator?: D` on `FormConfig` plus `FormModel<T, D = never>` (defaulted, to keep existing\n// annotations compiling), re-pointing each field at the active variant's own schema.\n// No second class needed: unlike `makeUnionModel`, nothing here puts the resource union in a\n// base-class position, so the TS2509 problem that forced that separate factory doesn't apply here.\n\nexport class FormModel<T extends FormSchema = TObject> {\n  /** Shared fields only (for unions); every field for a plain object schema. */\n  readonly fields: FormFields<T>;\n  /** Every field across all variants — escape hatch for reaching variant fields. */\n  readonly rawFields: RawFormFields<T>;\n  readonly config: FormConfig<T>;\n  readonly schema: T;\n  readonly validator: Validator<T>;\n\n  // TODO: maybe refactor into a \"state\" property?\n  submitting = false;\n  submitted = false;\n\n  /**\n   * Whatever `handleSubmit` last threw. `unknown` rather than `any`: it may be an `Error`, an API\n   * error object, or a string, and narrowing at the render site is the only safe way to read it.\n   */\n  submitError: unknown;\n\n  constructor(schema: T, config: FormConfig<T>) {\n    this.schema = schema;\n    this.config = config;\n    this.validator = Schema.Compile(schema);\n\n    makeAutoObservable(this, {\n      fields: false,\n      rawFields: false,\n      schema: false,\n      config: false,\n      validator: false,\n    });\n\n    const initialValues = config?.initialValues as Record<string, unknown> | undefined;\n    const fields = Object.entries(resolveProperties(schema)).reduce(\n      (fields, [fieldName, fieldSchema]) => {\n        fields[fieldName] = new FormFieldModel({\n          name: fieldName,\n          schema: fieldSchema,\n          initialValue: initialValues?.[fieldName],\n        });\n        return fields;\n      },\n      {} as Record<string, FormFieldModel<TSchema>>,\n    );\n\n    // `fields` and `rawFields` are the same object; the types differ so that a\n    // union form only surfaces shared fields by default.\n    this.rawFields = fields as unknown as RawFormFields<T>;\n    this.fields = fields as unknown as FormFields<T>;\n  }\n\n  get valid(): boolean {\n    // A union form can't be validated field-by-field — fields belonging to the\n    // inactive variant would fail — so validate the assembled object instead.\n    if (IsUnion(this.schema)) {\n      const data = this.toJSON() as Record<string, unknown>;\n      // Manual errors still have to block, but only for fields the active variant actually has:\n      // `toJSON` has already dropped the others, so a stale error on an inactive field can't wedge\n      // a submit that doesn't include it.\n      const blocked = Object.values<FormFieldModel<TSchema>>(this.fields).some(\n        (field) => field.error && field.name in data,\n      );\n      return !blocked && this.validator.Check(data);\n    }\n    return Object.values(this.fields).every((field) => field.valid);\n  }\n\n  props(): any {\n    return {\n      onSubmit: (e: React.FormEvent<HTMLFormElement>) => {\n        e.preventDefault();\n\n        // A second submit while one is in flight would call handleSubmit twice — a double-click on\n        // the button is enough, since nothing here was checking.\n        if (this.submitting) {\n          return;\n        }\n\n        this.setSubmitError(undefined);\n        // `submitted` reports the outcome of the *last* attempt, so a retry must not still claim\n        // success while it is in flight.\n        this.setSubmitted(false);\n\n        if (!this.validate()) {\n          return;\n        }\n\n        this.setSubmitting(true);\n        this.config\n          .handleSubmit(this.toJSON() as Static<T>)\n          .then((resp) => {\n            this.setSubmitted(true);\n            return resp;\n          })\n          .catch((e: unknown) => {\n            // Stored *before* handleError runs, so a handler that wants to own presentation\n            // entirely can clear it with `form.setSubmitError(undefined)`.\n            this.setSubmitError(e);\n\n            if (this.config.handleError) {\n              this.config.handleError(e, this);\n              return;\n            }\n\n            // Nothing is configured to surface this and the catch has already consumed the\n            // rejection, so without a log a throw inside handleSubmit — a network failure, or a\n            // plain bug — is invisible in development and in production alike.\n            console.error(e);\n          })\n          .finally(() => {\n            this.setSubmitting(false);\n          });\n      },\n    };\n  }\n\n  setSubmitError(error: unknown): void {\n    this.submitError = error;\n  }\n\n  protected setSubmitting(submitting: boolean): void {\n    this.submitting = submitting;\n  }\n\n  protected setSubmitted(submitted: boolean): void {\n    this.submitted = submitted;\n  }\n\n  reset(): void {\n    this.setSubmitError(undefined);\n    // Without this, one successful submit left `submitted` true forever — a \"save another\" flow\n    // would keep reporting success against an empty form.\n    this.setSubmitted(false);\n    for (const field of Object.values(this.fields)) {\n      field.reset();\n    }\n  }\n\n  validate(): boolean {\n    for (const field of Object.values<FormFieldModel<TSchema>>(this.fields)) {\n      field.setTouched(true);\n      // Each attempt is judged fresh. Without this a manual error would make the form permanently\n      // invalid until the user happened to edit that field, so clicking submit again would silently\n      // do nothing rather than retrying.\n      field.setError(undefined);\n    }\n    return this.valid;\n  }\n\n  toJSON(): Partial<Static<T>> {\n    const data = Object.values(this.fields).reduce(\n      (fields, field) => {\n        fields[field.name] = field.toJSON();\n        return fields;\n      },\n      {} as Record<string, unknown>,\n    );\n\n    // Drop fields belonging to the inactive variant so submitted data matches\n    // the selected member of the union exactly.\n    if (IsUnion(this.schema)) {\n      return Value.Clean(this.schema, data) as Partial<Static<T>>;\n    }\n    return data as Partial<Static<T>>;\n  }\n}\n","import type { TObject } from \"typebox\";\nimport { useRef } from \"react\";\nimport { FormModel } from \"./form.model\";\nimport type { FormConfig, FormSchema } from \"./form.types\";\n\nexport const useForm = <T extends FormSchema = TObject>(\n  schema: T,\n  config: FormConfig<T>,\n): FormModel<T> => {\n  const formRef = useRef<FormModel<T>>(undefined);\n  if (formRef.current) {\n    Object.assign(formRef.current.config, config);\n  } else {\n    formRef.current = new FormModel<T>(schema, config);\n  }\n\n  return formRef.current;\n};\n"],"mappings":";;;;;;;;;;;;AAGA,MAAa,cAAc,cAAqC,MAAS;AACzE,MAAa,uBAAuB;CAClC,MAAM,UAAU,WAAW,WAAW;CACtC,IAAI,CAAC,SACH,MAAM,IAAI,MACR,mHACF;CAEF,OAAO;AACT;AAEA,MAAa,eAAe,YAAY;AAExC,MAAa,kCAAkC,WAAW,WAAW;;;;ACLrE,MAAa,WAAW,WAAW,SAAS,SAC1C,EAAE,MAAM,UAAU,GAAG,aACrB,KACA;CACA,OACE,oBAAC,cAAD;EAAc,OAAO;YACnB,oBAAC,QAAD;GAAM;GAAW,GAAI;GAAgB;GAAK,GAAI,KAAK,MAAM;GACtD;EACG;CACM;AAElB,CAAC;;;;;;;;;ACID,SAAgB,SAA6E,EAC3F,MAC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