@schema-engine/forms-react 0.0.0-stage → 0.5.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.
Files changed (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -2
  3. package/dist/chunk-5XCNXEJB.js +19 -0
  4. package/dist/chunk-5XCNXEJB.js.map +7 -0
  5. package/dist/chunk-6RI4LMM6.js +19 -0
  6. package/dist/chunk-6RI4LMM6.js.map +7 -0
  7. package/dist/chunk-7QNWPTT7.js +20 -0
  8. package/dist/chunk-7QNWPTT7.js.map +7 -0
  9. package/dist/chunk-7RUFT6EJ.js +39 -0
  10. package/dist/chunk-7RUFT6EJ.js.map +7 -0
  11. package/dist/chunk-AALIXTCD.js +56 -0
  12. package/dist/chunk-AALIXTCD.js.map +7 -0
  13. package/dist/chunk-CPJMN2IH.js +128 -0
  14. package/dist/chunk-CPJMN2IH.js.map +7 -0
  15. package/dist/chunk-DTJ64NZQ.js +142 -0
  16. package/dist/chunk-DTJ64NZQ.js.map +7 -0
  17. package/dist/chunk-EYDB6NR6.js +9 -0
  18. package/dist/chunk-EYDB6NR6.js.map +7 -0
  19. package/dist/chunk-GH2QO3WC.js +11 -0
  20. package/dist/chunk-GH2QO3WC.js.map +7 -0
  21. package/dist/chunk-H25SUEJE.js +8 -0
  22. package/dist/chunk-H25SUEJE.js.map +7 -0
  23. package/dist/chunk-HT43MPKW.js +0 -0
  24. package/dist/chunk-HT43MPKW.js.map +7 -0
  25. package/dist/chunk-IHX6VMAQ.js +0 -0
  26. package/dist/chunk-IHX6VMAQ.js.map +7 -0
  27. package/dist/chunk-ISDPSORR.js +265 -0
  28. package/dist/chunk-ISDPSORR.js.map +7 -0
  29. package/dist/chunk-IXRV3YCF.js +36 -0
  30. package/dist/chunk-IXRV3YCF.js.map +7 -0
  31. package/dist/chunk-K3LLWGXU.js +30 -0
  32. package/dist/chunk-K3LLWGXU.js.map +7 -0
  33. package/dist/chunk-K66J2V73.js +108 -0
  34. package/dist/chunk-K66J2V73.js.map +7 -0
  35. package/dist/chunk-KG6Q7MNI.js +51 -0
  36. package/dist/chunk-KG6Q7MNI.js.map +7 -0
  37. package/dist/chunk-MBN4WIAC.js +41 -0
  38. package/dist/chunk-MBN4WIAC.js.map +7 -0
  39. package/dist/chunk-NDFV5AQW.js +39 -0
  40. package/dist/chunk-NDFV5AQW.js.map +7 -0
  41. package/dist/chunk-QUZN42PL.js +128 -0
  42. package/dist/chunk-QUZN42PL.js.map +7 -0
  43. package/dist/chunk-SED35QJC.js +78 -0
  44. package/dist/chunk-SED35QJC.js.map +7 -0
  45. package/dist/chunk-ULKJHK3P.js +6 -0
  46. package/dist/chunk-ULKJHK3P.js.map +7 -0
  47. package/dist/chunk-USRF3EEE.js +122 -0
  48. package/dist/chunk-USRF3EEE.js.map +7 -0
  49. package/dist/chunk-WFRWVH4X.js +44 -0
  50. package/dist/chunk-WFRWVH4X.js.map +7 -0
  51. package/dist/chunk-WOTW7A2I.js +7 -0
  52. package/dist/chunk-WOTW7A2I.js.map +7 -0
  53. package/dist/chunk-WRJWSEL7.js +98 -0
  54. package/dist/chunk-WRJWSEL7.js.map +7 -0
  55. package/dist/chunk-XWHP2AGG.js +7 -0
  56. package/dist/chunk-XWHP2AGG.js.map +7 -0
  57. package/dist/chunk-ZWEYALBG.js +25 -0
  58. package/dist/chunk-ZWEYALBG.js.map +7 -0
  59. package/dist/components/form-debugger/form-debugger.css +374 -0
  60. package/dist/components/form-debugger/form-debugger.css.map +7 -0
  61. package/dist/components/form-debugger/form-debugger.d.ts +23 -0
  62. package/dist/components/form-debugger/form-debugger.js +17 -0
  63. package/dist/components/form-debugger/form-debugger.js.map +7 -0
  64. package/dist/components/form-debugger/index.css +374 -0
  65. package/dist/components/form-debugger/index.css.map +7 -0
  66. package/dist/components/form-debugger/index.d.ts +2 -0
  67. package/dist/components/form-debugger/index.js +17 -0
  68. package/dist/components/form-debugger/index.js.map +7 -0
  69. package/dist/components/form-engine-provider.d.ts +7 -0
  70. package/dist/components/form-engine-provider.js +7 -0
  71. package/dist/components/form-engine-provider.js.map +7 -0
  72. package/dist/components/form-provider.d.ts +23 -0
  73. package/dist/components/form-provider.js +13 -0
  74. package/dist/components/form-provider.js.map +7 -0
  75. package/dist/components/index.d.ts +4 -0
  76. package/dist/components/index.js +43 -0
  77. package/dist/components/index.js.map +7 -0
  78. package/dist/components/internals/element-error.d.ts +9 -0
  79. package/dist/components/internals/element-error.js +6 -0
  80. package/dist/components/internals/element-error.js.map +7 -0
  81. package/dist/components/internals/field-renderer.d.ts +26 -0
  82. package/dist/components/internals/field-renderer.js +24 -0
  83. package/dist/components/internals/field-renderer.js.map +7 -0
  84. package/dist/components/internals/form-elements.d.ts +20 -0
  85. package/dist/components/internals/form-elements.js +25 -0
  86. package/dist/components/internals/form-elements.js.map +7 -0
  87. package/dist/components/internals/form-renderer.d.ts +28 -0
  88. package/dist/components/internals/form-renderer.js +31 -0
  89. package/dist/components/internals/form-renderer.js.map +7 -0
  90. package/dist/components/internals/recipe-renderer.d.ts +10 -0
  91. package/dist/components/internals/recipe-renderer.js +17 -0
  92. package/dist/components/internals/recipe-renderer.js.map +7 -0
  93. package/dist/components/provider.d.ts +18 -0
  94. package/dist/components/provider.js +8 -0
  95. package/dist/components/provider.js.map +7 -0
  96. package/dist/contexts/field-constraint-context.d.ts +15 -0
  97. package/dist/contexts/field-constraint-context.js +6 -0
  98. package/dist/contexts/field-constraint-context.js.map +7 -0
  99. package/dist/contexts/index.d.ts +2 -0
  100. package/dist/contexts/index.js +6 -0
  101. package/dist/contexts/index.js.map +7 -0
  102. package/dist/contexts/view-context.d.ts +14 -0
  103. package/dist/contexts/view-context.js +16 -0
  104. package/dist/contexts/view-context.js.map +7 -0
  105. package/dist/global.css +8 -0
  106. package/dist/hooks/field-text.d.ts +6 -0
  107. package/dist/hooks/field-text.js +6 -0
  108. package/dist/hooks/field-text.js.map +7 -0
  109. package/dist/hooks/form-state/context.d.ts +27 -0
  110. package/dist/hooks/form-state/context.js +10 -0
  111. package/dist/hooks/form-state/context.js.map +7 -0
  112. package/dist/hooks/form-state/field-registry.d.ts +60 -0
  113. package/dist/hooks/form-state/field-registry.js +9 -0
  114. package/dist/hooks/form-state/field-registry.js.map +7 -0
  115. package/dist/hooks/form-state/index.d.ts +8 -0
  116. package/dist/hooks/form-state/index.js +27 -0
  117. package/dist/hooks/form-state/index.js.map +7 -0
  118. package/dist/hooks/form-state/native-control.d.ts +39 -0
  119. package/dist/hooks/form-state/native-control.js +17 -0
  120. package/dist/hooks/form-state/native-control.js.map +7 -0
  121. package/dist/hooks/form-state/types.d.ts +191 -0
  122. package/dist/hooks/form-state/types.js +0 -0
  123. package/dist/hooks/form-state/types.js.map +7 -0
  124. package/dist/hooks/form-state/use-field-array.d.ts +12 -0
  125. package/dist/hooks/form-state/use-field-array.js +7 -0
  126. package/dist/hooks/form-state/use-field-array.js.map +7 -0
  127. package/dist/hooks/form-state/use-form-context.d.ts +10 -0
  128. package/dist/hooks/form-state/use-form-context.js +7 -0
  129. package/dist/hooks/form-state/use-form-context.js.map +7 -0
  130. package/dist/hooks/form-state/use-form-field.d.ts +24 -0
  131. package/dist/hooks/form-state/use-form-field.js +11 -0
  132. package/dist/hooks/form-state/use-form-field.js.map +7 -0
  133. package/dist/hooks/form-state/use-watch.d.ts +12 -0
  134. package/dist/hooks/form-state/use-watch.js +7 -0
  135. package/dist/hooks/form-state/use-watch.js.map +7 -0
  136. package/dist/hooks/index.d.ts +7 -0
  137. package/dist/hooks/index.js +78 -0
  138. package/dist/hooks/index.js.map +7 -0
  139. package/dist/hooks/is-element-required.d.ts +5 -0
  140. package/dist/hooks/is-element-required.js +6 -0
  141. package/dist/hooks/is-element-required.js.map +7 -0
  142. package/dist/hooks/use-debounce.d.ts +14 -0
  143. package/dist/hooks/use-debounce.js +8 -0
  144. package/dist/hooks/use-debounce.js.map +7 -0
  145. package/dist/hooks/use-field.d.ts +44 -0
  146. package/dist/hooks/use-field.js +16 -0
  147. package/dist/hooks/use-field.js.map +7 -0
  148. package/dist/hooks/use-form-context.d.ts +63 -0
  149. package/dist/hooks/use-form-context.js +18 -0
  150. package/dist/hooks/use-form-context.js.map +7 -0
  151. package/dist/hooks/use-mobile.d.ts +9 -0
  152. package/dist/hooks/use-mobile.js +6 -0
  153. package/dist/hooks/use-mobile.js.map +7 -0
  154. package/dist/index.d.ts +2 -0
  155. package/dist/index.js +43 -0
  156. package/dist/index.js.map +7 -0
  157. package/dist/lib/logger.d.ts +2 -0
  158. package/dist/lib/object-identity.d.ts +6 -0
  159. package/dist/primitives.d.ts +28 -0
  160. package/dist/primitives.js +37 -0
  161. package/dist/primitives.js.map +7 -0
  162. package/package.json +139 -3
  163. package/skill/SKILL.md +79 -0
  164. package/skill/reference/forms-react-widgets.md +222 -0
  165. package/skill/reference/forms-react.md +92 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/hooks/form-state/use-form-field.ts"],
4
+ "sourcesContent": ["import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from 'react';\nimport type { ChangeEvent, CSSProperties } from 'react';\nimport { mergeControlProps, createDefaultValidationRegistry, type ValidationRegistry } from '@schema-engine/forms';\nimport { issueText, selectFieldState, selectValue } from '@schema-engine/forms/state-container';\nimport { getGridItemVariables } from '@schema-engine/layout';\nimport { isElementRequired } from '@/hooks/is-element-required';\nimport { useOptionalFormEngine } from '@/hooks/use-form-context';\nimport { logger } from '@/lib/logger';\nimport { useContainerSelector, useFormStateContext } from './context';\nimport type { ControlledFormField, FormField, FormFieldConfig, FormFieldOptions, FormFieldStatus } from './types';\n\nlet fallbackValidationRegistry: ValidationRegistry | undefined;\n\n/**\n * The built-in validation registry a field uses when it renders outside a form engine.\n *\n * @remarks\n * Built on first use and shared. A registry is read-only, and building one checks every built-in\n * rule's schema, so a field should not build its own on each mount.\n */\nfunction getFallbackValidationRegistry(): ValidationRegistry {\n\tfallbackValidationRegistry ??= createDefaultValidationRegistry();\n\treturn fallbackValidationRegistry;\n}\n\n/** The state of the field at `path`, with its texts formatted. */\nfunction useFieldStatus(path: string): FormFieldStatus {\n\tconst { formatIssue } = useFormStateContext();\n\tconst { error, warning, invalid, isTouched, isDirty, isValidating } = useContainerSelector((snapshot) =>\n\t\tselectFieldState(snapshot, path),\n\t);\n\treturn {\n\t\terror: error && issueText(error, path, formatIssue),\n\t\twarning: warning && issueText(warning, path, formatIssue),\n\t\tissue: error,\n\t\tinvalid,\n\t\tisTouched,\n\t\tisDirty,\n\t\tisValidating,\n\t};\n}\n\nconst noValue = () => undefined;\n\n/**\n * The value of the field at `path` when the component renders it, and nothing when it does not.\n *\n * @remarks\n * The hook is called in both modes with a selector that always answers `undefined`, so an uncontrolled field\n * subscribes to the container and is never told a value changed: a keystroke renders nothing.\n */\nfunction useControlledValue(path: string, controlled: boolean): unknown {\n\treturn useContainerSelector(controlled ? (snapshot) => selectValue(snapshot, path) : noValue);\n}\n\nconst subscribeNever = () => () => undefined;\n\n/**\n * The value an uncontrolled control starts with, frozen when the field mounts.\n *\n * @remarks\n * While the form hydrates it reads the container's server snapshot, so the control renders the markup the\n * server sent. It never follows the container afterwards: the control owns its text, and the registry writes\n * the container's changes back into it.\n */\nfunction useDefaultValue(path: string): unknown {\n\tconst { container } = useFormStateContext();\n\tconst first = useSyncExternalStore(\n\t\tsubscribeNever,\n\t\t() => selectValue(container.getSnapshot(), path),\n\t\t() => selectValue(container.getServerSnapshot(), path),\n\t);\n\treturn useState(first)[0];\n}\n\n/**\n * The `ref` of the field's controls.\n *\n * @remarks\n * Relies on React 19, where a ref callback returns its own cleanup: the registry's disposer runs when the\n * control detaches or the path changes, and the callback is never called with `null`.\n */\nfunction useFieldRef(path: string, controlled: boolean, rendered: unknown) {\n\tconst { fields } = useFormStateContext();\n\treturn useCallback(\n\t\t(element: HTMLElement | null) =>\n\t\t\telement\n\t\t\t\t? fields.register(\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\telement,\n\t\t\t\t\t\tcontrolled ? { mode: 'controlled' } : { mode: 'uncontrolled', rendered },\n\t\t\t\t\t)\n\t\t\t\t: undefined,\n\t\t[fields, path, controlled, rendered],\n\t);\n}\n\n/**\n * Reports what the browser says about the field's native control after each render, and warns in development\n * when an uncontrolled field has none.\n *\n * @remarks\n * A control's verdict changes with its constraint attributes (`required`, `min`, `disabled`) and, in controlled\n * mode, with the value the component renders. Both reach the control through a render of this field, so\n * reading after every render keeps the fact current. The container ignores a fact it already holds, so a\n * render that changed nothing costs a read.\n */\nfunction useNativeBinding(path: string, controlled: boolean, bound: boolean): void {\n\tconst { fields } = useFormStateContext();\n\tuseEffect(() => {\n\t\tif (bound) fields.reportNative(path);\n\t});\n\tuseEffect(() => {\n\t\tif (!bound || controlled || process.env.NODE_ENV === 'production') return;\n\t\tconst { registered, native } = fields.inspect(path);\n\t\tif (registered && !native) {\n\t\t\tlogger.warn(\n\t\t\t\t`The field \"${path}\" is uncontrolled but its ref is not on an input, select or textarea. Use useFormField(config, { controlled: true }) for a component that takes value and onChange.`,\n\t\t\t);\n\t\t}\n\t}, [fields, path, controlled, bound]);\n}\n\n/**\n * Whether a field is required: the field's own rules say so, or a `require` constraint of it or of a container around it holds.\n *\n * @remarks The constraint part is the container's (`selectFieldState`), so it agrees with show and hide. With no config it is not required.\n */\nfunction useFieldRequired(config: FormFieldConfig | undefined): boolean {\n\tconst { required: constraintRequired } = useContainerSelector((snapshot) =>\n\t\tselectFieldState(snapshot, config?.name ?? ''),\n\t);\n\tconst engineContext = useOptionalFormEngine();\n\tconst registry = useMemo(\n\t\t() => engineContext?.engine.getValidationRegistry() ?? getFallbackValidationRegistry(),\n\t\t[engineContext],\n\t);\n\treturn constraintRequired || (config !== undefined && isElementRequired(config, registry));\n}\n\n/**\n * Binds a widget to a field of the form.\n *\n * @remarks\n * Given the config of an element it is everything a registry widget needs: the field's state (`error`,\n * `warning`, `issue`, `invalid` and the flags), its `required` evaluated against the element's constraints,\n * and the props of its control, label and error (`fieldProps`, `labelProps`, `errorProps`, `containerStyles`).\n * Given a path (a field, an array, or `FORM_ROOT` for the form itself) it is the state and formatted texts\n * of that path alone; `useWatch` reads values.\n *\n * By default the control keeps its own value (`defaultValue`, `fieldProps.onChange`) and the field\n * re-renders only when its error, warning or flags change, never for a keystroke. A component that takes only\n * `value` and `onChange` props passes `{ controlled: true }` and re-renders with its value. In both modes\n * `fieldProps.ref` also reports what the browser says about a native control (`validity`) as the native\n * facts of the container, and focuses it for `setFocus` and a failed submit.\n */\nexport function useFormField(path: string): FormFieldStatus;\nexport function useFormField(config: FormFieldConfig, options: { controlled: true }): ControlledFormField;\nexport function useFormField(config: FormFieldConfig, options?: { controlled?: false }): FormField;\nexport function useFormField(\n\ttarget: string | FormFieldConfig,\n\toptions?: FormFieldOptions,\n): FormFieldStatus | FormField | ControlledFormField {\n\tconst config = typeof target === 'string' ? undefined : target;\n\tif (config && !config.name) {\n\t\tthrow new Error(`Field configuration is missing required \"name\" property. Config: ${JSON.stringify(config)}`);\n\t}\n\tconst path = typeof target === 'string' ? target : target.name;\n\tconst controlled = options?.controlled === true;\n\tconst { container, fields } = useFormStateContext();\n\tconst status = useFieldStatus(path);\n\tconst required = useFieldRequired(config);\n\tconst value = useControlledValue(path, controlled);\n\tconst defaultValue = useDefaultValue(path);\n\tuseNativeBinding(path, controlled, config !== undefined);\n\n\tconst ref = useFieldRef(path, controlled, defaultValue);\n\tconst onNativeChange = useCallback(\n\t\t(event: ChangeEvent<HTMLElement>) => fields.change(path, event.currentTarget),\n\t\t[fields, path],\n\t);\n\tconst onNativeBlur = useCallback(() => fields.blur(path), [fields, path]);\n\tconst onValueChange = useCallback((next: unknown) => container.setValue(path, next), [container, path]);\n\tif (!config) return status;\n\n\tconst disabled = Boolean(config.disabled);\n\tconst control = mergeControlProps(\n\t\t{\n\t\t\tid: config.id,\n\t\t\tname: path,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly: config.readonly,\n\t\t\tref,\n\t\t\t'aria-invalid': status.invalid,\n\t\t\t'aria-describedby': status.error ? `${config.id}-error` : undefined,\n\t\t},\n\t\tconfig.htmlAttributes,\n\t);\n\tconst element = {\n\t\t...status,\n\t\trequired,\n\t\tdisabled,\n\t\tlabelProps: { htmlFor: config.id },\n\t\terrorProps: status.error ? { id: `${config.id}-error`, role: 'alert' as const } : null,\n\t\tcontainerStyles: { ...getGridItemVariables(config.grid), ...config.style } satisfies CSSProperties,\n\t};\n\tif (controlled) {\n\t\treturn { ...element, value, onChange: onValueChange, onBlur: onNativeBlur, fieldProps: control };\n\t}\n\treturn { ...element, defaultValue, fieldProps: { ...control, onChange: onNativeChange, onBlur: onNativeBlur } };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA,SAAS,aAAa,WAAW,SAAS,UAAU,4BAA4B;AAEhF,SAAS,mBAAmB,uCAAgE;AAC5F,SAAS,WAAW,kBAAkB,mBAAmB;AACzD,SAAS,4BAA4B;AAOrC,IAAI;AASJ,SAAS,gCAAoD;AAC5D,iCAA+B,gCAAgC;AAC/D,SAAO;AACR;AAGA,SAAS,eAAe,MAA+B;AACtD,QAAM,EAAE,YAAY,IAAI,oBAAoB;AAC5C,QAAM,EAAE,OAAO,SAAS,SAAS,WAAW,SAAS,aAAa,IAAI;AAAA,IAAqB,CAAC,aAC3F,iBAAiB,UAAU,IAAI;AAAA,EAChC;AACA,SAAO;AAAA,IACN,OAAO,SAAS,UAAU,OAAO,MAAM,WAAW;AAAA,IAClD,SAAS,WAAW,UAAU,SAAS,MAAM,WAAW;AAAA,IACxD,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,IAAM,UAAU,MAAM;AAStB,SAAS,mBAAmB,MAAc,YAA8B;AACvE,SAAO,qBAAqB,aAAa,CAAC,aAAa,YAAY,UAAU,IAAI,IAAI,OAAO;AAC7F;AAEA,IAAM,iBAAiB,MAAM,MAAM;AAUnC,SAAS,gBAAgB,MAAuB;AAC/C,QAA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,OAAO,GAAG;AAAA,IACjC,YAAY,OAAO,QAAQ,EAAE,IAAI,GAAG,OAAO,EAAE,UAAU,MAAM,QAAiB,IAAI;AAAA,IAClF,iBAAiB,EAAE,GAAG,qBAAqB,OAAO,IAAI,GAAG,GAAG,OAAO,MAAM;AAAA,EAC1E;AACA,MAAI,YAAY;AACf,WAAO,EAAE,GAAG,SAAS,OAAO,UAAU,eAAe,QAAQ,cAAc,YAAY,QAAQ;AAAA,EAChG;AACA,SAAO,EAAE,GAAG,SAAS,cAAc,YAAY,EAAE,GAAG,SAAS,UAAU,gBAAgB,QAAQ,aAAa,EAAE;AAC/G;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ // src/hooks/is-element-required.ts
2
+ import { getValidationRulesForElement, isFieldRequired } from "@schema-engine/forms";
3
+ function isElementRequired(element, registry) {
4
+ return isFieldRequired(getValidationRulesForElement(element, registry));
5
+ }
6
+
7
+ export {
8
+ isElementRequired
9
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/hooks/is-element-required.ts"],
4
+ "sourcesContent": ["import { type ValidationRegistry, getValidationRulesForElement, isFieldRequired } from '@schema-engine/forms';\n\n/** The parts of an element its required flag is derived from. */\nexport type RequiredFlagSource = Parameters<typeof getValidationRulesForElement>[0];\n\n/** Base required flag before constraints: authored rules plus the type's default rules. */\nexport function isElementRequired(element: RequiredFlagSource, registry: ValidationRegistry): boolean {\n\treturn isFieldRequired(getValidationRulesForElement(element, registry));\n}\n"],
5
+ "mappings": ";AAAA,SAAkC,8BAA8B,uBAAuB;AAMhF,SAAS,kBAAkB,SAA6B,UAAuC;AACrG,SAAO,gBAAgB,6BAA6B,SAAS,QAAQ,CAAC;AACvE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,11 @@
1
+ // src/components/provider.tsx
2
+ import { createContext } from "react";
3
+ function createFormEngineContextValue(engine) {
4
+ return { engine };
5
+ }
6
+ var FormEngineContext = createContext(null);
7
+
8
+ export {
9
+ createFormEngineContextValue,
10
+ FormEngineContext
11
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/components/provider.tsx"],
4
+ "sourcesContent": ["import { createContext } from 'react';\nimport type { EngineOutputMaps, FormEngineRuntime as FormEngine } from '@schema-engine/forms';\n\n/**\n * Form Engine context value\n */\nexport interface FormEngineContextValue<\n\tTElements extends Record<string, unknown> = Record<string, unknown>,\n\tTRecipes extends Record<string, unknown> = Record<string, unknown>,\n\tTActions extends Record<string, unknown> = Record<string, unknown>,\n\tTOutputs extends EngineOutputMaps = EngineOutputMaps,\n> {\n\tengine: FormEngine<TElements, TRecipes, TActions, TOutputs>;\n}\n\n/**\n * Erases registration maps for context storage.\n *\n * @remarks `useFormEngine` reapplies the consumer's maps after reading context.\n */\nexport function createFormEngineContextValue<\n\tTElements extends Record<string, unknown>,\n\tTRecipes extends Record<string, unknown>,\n\tTActions extends Record<string, unknown>,\n\tTOutputs extends EngineOutputMaps,\n>(engine: FormEngine<TElements, TRecipes, TActions, TOutputs>): FormEngineContextValue {\n\treturn { engine: engine as unknown as FormEngineContextValue['engine'] };\n}\n\n/**\n * Form Engine context\n * Provides access to the FormEngine instance\n */\nexport const FormEngineContext = createContext<FormEngineContextValue | null>(null);\n"],
5
+ "mappings": ";AAAA,SAAS,qBAAqB;AAoBvB,SAAS,6BAKd,QAAqF;AACtF,SAAO,EAAE,OAA8D;AACxE;AAMO,IAAM,oBAAoB,cAA6C,IAAI;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ // src/hooks/field-text.ts
2
+ function fieldText(value) {
3
+ return typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" ? String(value) : "";
4
+ }
5
+
6
+ export {
7
+ fieldText
8
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/hooks/field-text.ts"],
4
+ "sourcesContent": ["/**\n * A field value as the text of a text control: a string as it is, a number or boolean as its string, anything else as `''`.\n *\n * @remarks For a control whose value is text; a control that holds a list or a number narrows the value itself.\n */\nexport function fieldText(value: unknown): string {\n\treturn typeof value === 'string'\n\t\t? value\n\t\t: typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint'\n\t\t\t? String(value)\n\t\t\t: '';\n}\n"],
5
+ "mappings": ";AAKO,SAAS,UAAU,OAAwB;AACjD,SAAO,OAAO,UAAU,WACrB,QACA,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa,OAAO,UAAU,WAC3E,OAAO,KAAK,IACZ;AACL;",
6
+ "names": []
7
+ }
File without changes
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
File without changes
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,265 @@
1
+ import {
2
+ useWatch
3
+ } from "./chunk-NDFV5AQW.js";
4
+ import {
5
+ useFormContext
6
+ } from "./chunk-K66J2V73.js";
7
+ import {
8
+ useOptionalViewContext
9
+ } from "./chunk-IXRV3YCF.js";
10
+
11
+ // src/components/form-debugger/form-debugger.tsx
12
+ import { useEffect, useRef, useState } from "react";
13
+ import { createPortal } from "react-dom";
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
+ function CloseIcon() {
16
+ return /* @__PURE__ */ jsxs(
17
+ "svg",
18
+ {
19
+ xmlns: "http://www.w3.org/2000/svg",
20
+ width: "18",
21
+ height: "18",
22
+ viewBox: "0 0 24 24",
23
+ fill: "none",
24
+ stroke: "currentColor",
25
+ strokeWidth: "2",
26
+ "aria-hidden": "true",
27
+ children: [
28
+ /* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }),
29
+ /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })
30
+ ]
31
+ }
32
+ );
33
+ }
34
+ function DebuggerHeader({
35
+ title,
36
+ currentStep,
37
+ totalSteps,
38
+ onClose
39
+ }) {
40
+ return /* @__PURE__ */ jsxs("div", { className: "form-debugger__header", children: [
41
+ /* @__PURE__ */ jsxs("div", { children: [
42
+ /* @__PURE__ */ jsx("h3", { className: "form-debugger__header-title", children: title }),
43
+ totalSteps > 1 && /* @__PURE__ */ jsxs("span", { className: "form-debugger__header-subtitle", children: [
44
+ "Step ",
45
+ currentStep + 1,
46
+ " / ",
47
+ totalSteps
48
+ ] })
49
+ ] }),
50
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: onClose, className: "form-debugger__close-button", "aria-label": "Close debugger", children: /* @__PURE__ */ jsx(CloseIcon, {}) })
51
+ ] });
52
+ }
53
+ function DebuggerProgress({ currentStep, totalSteps }) {
54
+ return /* @__PURE__ */ jsxs("div", { children: [
55
+ /* @__PURE__ */ jsx("div", { className: "form-debugger__section-title", children: "Progress" }),
56
+ /* @__PURE__ */ jsx("div", { className: "form-debugger__progress", children: /* @__PURE__ */ jsx(
57
+ "div",
58
+ {
59
+ className: "form-debugger__progress-fill",
60
+ style: { width: `${(currentStep + 1) / totalSteps * 100}%` }
61
+ }
62
+ ) })
63
+ ] });
64
+ }
65
+ function DebuggerSteps({
66
+ steps,
67
+ currentStep,
68
+ showDetails
69
+ }) {
70
+ return /* @__PURE__ */ jsxs("div", { children: [
71
+ /* @__PURE__ */ jsx("div", { className: "form-debugger__section-title", children: "Steps" }),
72
+ /* @__PURE__ */ jsx("div", { className: "form-debugger__timeline", children: steps.map((step, index) => /* @__PURE__ */ jsx(
73
+ "div",
74
+ {
75
+ className: `form-debugger__timeline-item ${index === currentStep ? "form-debugger__timeline-item--active" : ""}`,
76
+ children: /* @__PURE__ */ jsxs("div", { children: [
77
+ /* @__PURE__ */ jsx("div", { className: "form-debugger__step-title", children: step.title ?? `Step ${index + 1}` }),
78
+ step.description && showDetails && /* @__PURE__ */ jsx("div", { className: "form-debugger__step-description", children: step.description }),
79
+ /* @__PURE__ */ jsxs("div", { className: "form-debugger__timeline-meta", children: [
80
+ !step.isInvalid && step.isVisited && /* @__PURE__ */ jsx("span", { className: "form-debugger__badge form-debugger__badge--valid", children: "Valid" }),
81
+ step.isInvalid && /* @__PURE__ */ jsx("span", { className: "form-debugger__badge form-debugger__badge--invalid", children: "Invalid" }),
82
+ step.isVisited && /* @__PURE__ */ jsx("span", { className: "form-debugger__badge form-debugger__badge--visited", children: "Visited" })
83
+ ] })
84
+ ] })
85
+ },
86
+ step.id
87
+ )) })
88
+ ] });
89
+ }
90
+ function DebuggerFormState({
91
+ formState,
92
+ formValues,
93
+ submissionStatus,
94
+ invalidSteps
95
+ }) {
96
+ return /* @__PURE__ */ jsxs("div", { children: [
97
+ /* @__PURE__ */ jsx("div", { className: "form-debugger__section-title", children: "Form state" }),
98
+ /* @__PURE__ */ jsxs("div", { className: "form-debugger__details", children: [
99
+ /* @__PURE__ */ jsxs("div", { className: "form-debugger__detail-row", children: [
100
+ /* @__PURE__ */ jsx("span", { className: "form-debugger__detail-label", children: "Valid" }),
101
+ /* @__PURE__ */ jsx("code", { className: "form-debugger__detail-value", children: String(formState.isValid) })
102
+ ] }),
103
+ /* @__PURE__ */ jsxs("div", { className: "form-debugger__detail-row", children: [
104
+ /* @__PURE__ */ jsx("span", { className: "form-debugger__detail-label", children: "Submission" }),
105
+ /* @__PURE__ */ jsx("code", { className: "form-debugger__detail-value", children: submissionStatus })
106
+ ] }),
107
+ invalidSteps ? /* @__PURE__ */ jsxs("div", { className: "form-debugger__detail-row", children: [
108
+ /* @__PURE__ */ jsx("span", { className: "form-debugger__detail-label", children: "Invalid steps" }),
109
+ /* @__PURE__ */ jsx("code", { className: "form-debugger__detail-value", children: JSON.stringify(invalidSteps) })
110
+ ] }) : null
111
+ ] }),
112
+ /* @__PURE__ */ jsx("pre", { className: "form-debugger__pre", children: JSON.stringify(formValues, null, 2) }),
113
+ Object.keys(formState.errors).length > 0 && /* @__PURE__ */ jsx("pre", { className: "form-debugger__pre", children: JSON.stringify(formState.errors, null, 2) })
114
+ ] });
115
+ }
116
+ function DebuggerNav({
117
+ steps,
118
+ currentStep,
119
+ navigation
120
+ }) {
121
+ return /* @__PURE__ */ jsxs("div", { className: "form-debugger__nav", children: [
122
+ /* @__PURE__ */ jsx(
123
+ "button",
124
+ {
125
+ type: "button",
126
+ onClick: navigation.goToPreviousStep,
127
+ disabled: navigation.isFirstStep,
128
+ className: "form-debugger__nav-button",
129
+ children: "Previous"
130
+ }
131
+ ),
132
+ /* @__PURE__ */ jsx("div", { className: "form-debugger__nav-dots", children: steps.map((step, index) => /* @__PURE__ */ jsx(
133
+ "button",
134
+ {
135
+ type: "button",
136
+ onClick: () => navigation.goToStep(step.id),
137
+ disabled: index !== currentStep && !navigation.canGoToStep(step.id),
138
+ className: [
139
+ "form-debugger__nav-dot",
140
+ index === currentStep && "form-debugger__nav-dot--active",
141
+ index < currentStep && "form-debugger__nav-dot--completed",
142
+ index !== currentStep && !navigation.canGoToStep(step.id) && "form-debugger__nav-dot--disabled"
143
+ ].filter(Boolean).join(" "),
144
+ "aria-label": `Go to ${step.title ?? `step ${index + 1}`}`
145
+ },
146
+ step.id
147
+ )) }),
148
+ /* @__PURE__ */ jsx(
149
+ "button",
150
+ {
151
+ type: "button",
152
+ onClick: navigation.goToNextStep,
153
+ disabled: !navigation.canGoNext,
154
+ className: "form-debugger__nav-button",
155
+ children: "Next"
156
+ }
157
+ )
158
+ ] });
159
+ }
160
+ function FormDebuggerPanel({
161
+ onClose,
162
+ showStepDetails,
163
+ showFormState
164
+ }) {
165
+ const { formState } = useFormContext();
166
+ const formValues = useWatch();
167
+ const view = useOptionalViewContext();
168
+ const steps = view?.steps ?? [];
169
+ const currentStep = view?.currentStepIndex ?? 0;
170
+ const totalSteps = steps.length;
171
+ const navigation = view?.navigation;
172
+ const isMultiStep = totalSteps > 1;
173
+ return /* @__PURE__ */ jsxs("div", { className: "form-debugger__panel", children: [
174
+ /* @__PURE__ */ jsx(
175
+ DebuggerHeader,
176
+ {
177
+ title: view?.form.title ?? "Form Debugger",
178
+ currentStep,
179
+ totalSteps,
180
+ onClose
181
+ }
182
+ ),
183
+ /* @__PURE__ */ jsxs("div", { className: "form-debugger__content", children: [
184
+ isMultiStep && /* @__PURE__ */ jsx(DebuggerProgress, { currentStep, totalSteps }),
185
+ isMultiStep && steps.length > 0 && /* @__PURE__ */ jsx(DebuggerSteps, { steps, currentStep, showDetails: showStepDetails }),
186
+ showFormState && /* @__PURE__ */ jsx(
187
+ DebuggerFormState,
188
+ {
189
+ formState,
190
+ formValues,
191
+ submissionStatus: formState.submission.status,
192
+ invalidSteps: steps.filter(({ isInvalid }) => isInvalid).map(({ id }) => id)
193
+ }
194
+ )
195
+ ] }),
196
+ isMultiStep && navigation ? /* @__PURE__ */ jsx(DebuggerNav, { steps, currentStep, navigation }) : null
197
+ ] });
198
+ }
199
+ function FormDebugger({
200
+ defaultOpen = false,
201
+ showStepDetails = true,
202
+ showFormState = true
203
+ } = {}) {
204
+ const [isExpanded, setIsExpanded] = useState(defaultOpen);
205
+ const panelRef = useRef(null);
206
+ useEffect(() => {
207
+ if (!isExpanded) return;
208
+ const handleClickOutside = (event) => {
209
+ if (panelRef.current && !panelRef.current.contains(event.target)) {
210
+ setIsExpanded(false);
211
+ }
212
+ };
213
+ document.addEventListener("mousedown", handleClickOutside);
214
+ return () => document.removeEventListener("mousedown", handleClickOutside);
215
+ }, [isExpanded]);
216
+ if (typeof document === "undefined") return null;
217
+ return createPortal(
218
+ /* @__PURE__ */ jsx("div", { className: "form-debugger", children: /* @__PURE__ */ jsx(
219
+ "div",
220
+ {
221
+ ref: panelRef,
222
+ className: `form-debugger__widget ${isExpanded ? "form-debugger__widget--expanded" : ""}`,
223
+ children: !isExpanded ? /* @__PURE__ */ jsx(
224
+ "button",
225
+ {
226
+ type: "button",
227
+ onClick: () => setIsExpanded(true),
228
+ className: "form-debugger__fab",
229
+ "aria-label": "Open form debugger",
230
+ children: /* @__PURE__ */ jsxs(
231
+ "svg",
232
+ {
233
+ xmlns: "http://www.w3.org/2000/svg",
234
+ width: "20",
235
+ height: "20",
236
+ viewBox: "0 0 24 24",
237
+ fill: "none",
238
+ stroke: "currentColor",
239
+ strokeWidth: "2",
240
+ "aria-hidden": "true",
241
+ children: [
242
+ /* @__PURE__ */ jsx("path", { d: "m8 6 4-4 4 4" }),
243
+ /* @__PURE__ */ jsx("path", { d: "M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22" }),
244
+ /* @__PURE__ */ jsx("path", { d: "m20 22-5-5" })
245
+ ]
246
+ }
247
+ )
248
+ }
249
+ ) : /* @__PURE__ */ jsx(
250
+ FormDebuggerPanel,
251
+ {
252
+ onClose: () => setIsExpanded(false),
253
+ showStepDetails,
254
+ showFormState
255
+ }
256
+ )
257
+ }
258
+ ) }),
259
+ document.body
260
+ );
261
+ }
262
+
263
+ export {
264
+ FormDebugger
265
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/components/form-debugger/form-debugger.tsx"],
4
+ "sourcesContent": ["import { useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { useFormContext, useWatch } from '@/hooks/form-state';\nimport { useOptionalViewContext } from '@/contexts/view-context';\nimport './form-debugger.css';\n\nexport interface FormDebuggerProps {\n\t/** Open the panel on mount instead of showing the collapsed trigger. */\n\tdefaultOpen?: boolean;\n\t/** Show each step's description in the step timeline. */\n\tshowStepDetails?: boolean;\n\t/** Show the form state, values, and errors section. */\n\tshowFormState?: boolean;\n}\n\nfunction CloseIcon() {\n\treturn (\n\t\t<svg\n\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\twidth=\"18\"\n\t\t\theight=\"18\"\n\t\t\tviewBox=\"0 0 24 24\"\n\t\t\tfill=\"none\"\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeWidth=\"2\"\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t<path d=\"M18 6 6 18\" />\n\t\t\t<path d=\"m6 6 12 12\" />\n\t\t</svg>\n\t);\n}\n\nfunction DebuggerHeader({\n\ttitle,\n\tcurrentStep,\n\ttotalSteps,\n\tonClose,\n}: {\n\ttitle: string;\n\tcurrentStep: number;\n\ttotalSteps: number;\n\tonClose: () => void;\n}) {\n\treturn (\n\t\t<div className=\"form-debugger__header\">\n\t\t\t<div>\n\t\t\t\t<h3 className=\"form-debugger__header-title\">{title}</h3>\n\t\t\t\t{totalSteps > 1 && (\n\t\t\t\t\t<span className=\"form-debugger__header-subtitle\">\n\t\t\t\t\t\tStep {currentStep + 1} / {totalSteps}\n\t\t\t\t\t</span>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t\t<button type=\"button\" onClick={onClose} className=\"form-debugger__close-button\" aria-label=\"Close debugger\">\n\t\t\t\t<CloseIcon />\n\t\t\t</button>\n\t\t</div>\n\t);\n}\n\nfunction DebuggerProgress({ currentStep, totalSteps }: { currentStep: number; totalSteps: number }) {\n\treturn (\n\t\t<div>\n\t\t\t<div className=\"form-debugger__section-title\">Progress</div>\n\t\t\t<div className=\"form-debugger__progress\">\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"form-debugger__progress-fill\"\n\t\t\t\t\tstyle={{ width: `${((currentStep + 1) / totalSteps) * 100}%` }}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction DebuggerSteps({\n\tsteps,\n\tcurrentStep,\n\tshowDetails,\n}: {\n\tsteps: Array<{\n\t\tid: string;\n\t\ttitle?: string;\n\t\tdescription?: string;\n\t\tisInvalid?: boolean;\n\t\tisVisited?: boolean;\n\t}>;\n\tcurrentStep: number;\n\tshowDetails: boolean;\n}) {\n\treturn (\n\t\t<div>\n\t\t\t<div className=\"form-debugger__section-title\">Steps</div>\n\t\t\t<div className=\"form-debugger__timeline\">\n\t\t\t\t{steps.map((step, index) => (\n\t\t\t\t\t<div\n\t\t\t\t\t\tkey={step.id}\n\t\t\t\t\t\tclassName={`form-debugger__timeline-item ${index === currentStep ? 'form-debugger__timeline-item--active' : ''}`}\n\t\t\t\t\t>\n\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t<div className=\"form-debugger__step-title\">{step.title ?? `Step ${index + 1}`}</div>\n\t\t\t\t\t\t\t{step.description && showDetails && (\n\t\t\t\t\t\t\t\t<div className=\"form-debugger__step-description\">{step.description}</div>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t<div className=\"form-debugger__timeline-meta\">\n\t\t\t\t\t\t\t\t{!step.isInvalid && step.isVisited && (\n\t\t\t\t\t\t\t\t\t<span className=\"form-debugger__badge form-debugger__badge--valid\">Valid</span>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t{step.isInvalid && (\n\t\t\t\t\t\t\t\t\t<span className=\"form-debugger__badge form-debugger__badge--invalid\">Invalid</span>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t{step.isVisited && (\n\t\t\t\t\t\t\t\t\t<span className=\"form-debugger__badge form-debugger__badge--visited\">Visited</span>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t))}\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction DebuggerFormState({\n\tformState,\n\tformValues,\n\tsubmissionStatus,\n\tinvalidSteps,\n}: {\n\tformState: { isValid: boolean; errors: Record<string, unknown> };\n\tformValues: unknown;\n\tsubmissionStatus: string;\n\tinvalidSteps?: string[];\n}) {\n\treturn (\n\t\t<div>\n\t\t\t<div className=\"form-debugger__section-title\">Form state</div>\n\t\t\t<div className=\"form-debugger__details\">\n\t\t\t\t<div className=\"form-debugger__detail-row\">\n\t\t\t\t\t<span className=\"form-debugger__detail-label\">Valid</span>\n\t\t\t\t\t<code className=\"form-debugger__detail-value\">{String(formState.isValid)}</code>\n\t\t\t\t</div>\n\t\t\t\t<div className=\"form-debugger__detail-row\">\n\t\t\t\t\t<span className=\"form-debugger__detail-label\">Submission</span>\n\t\t\t\t\t<code className=\"form-debugger__detail-value\">{submissionStatus}</code>\n\t\t\t\t</div>\n\t\t\t\t{invalidSteps ? (\n\t\t\t\t\t<div className=\"form-debugger__detail-row\">\n\t\t\t\t\t\t<span className=\"form-debugger__detail-label\">Invalid steps</span>\n\t\t\t\t\t\t<code className=\"form-debugger__detail-value\">{JSON.stringify(invalidSteps)}</code>\n\t\t\t\t\t</div>\n\t\t\t\t) : null}\n\t\t\t</div>\n\t\t\t<pre className=\"form-debugger__pre\">{JSON.stringify(formValues, null, 2)}</pre>\n\t\t\t{Object.keys(formState.errors).length > 0 && (\n\t\t\t\t<pre className=\"form-debugger__pre\">{JSON.stringify(formState.errors, null, 2)}</pre>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n\nfunction DebuggerNav({\n\tsteps,\n\tcurrentStep,\n\tnavigation,\n}: {\n\tsteps: Array<{ id: string; title?: string; isVisited?: boolean }>;\n\tcurrentStep: number;\n\tnavigation: {\n\t\tgoToPreviousStep: () => void;\n\t\tgoToNextStep: () => void;\n\t\tgoToStep: (stepId: string) => void;\n\t\tcanGoToStep: (stepId: string) => boolean;\n\t\tisFirstStep: boolean;\n\t\tcanGoNext: boolean;\n\t};\n}) {\n\treturn (\n\t\t<div className=\"form-debugger__nav\">\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tonClick={navigation.goToPreviousStep}\n\t\t\t\tdisabled={navigation.isFirstStep}\n\t\t\t\tclassName=\"form-debugger__nav-button\"\n\t\t\t>\n\t\t\t\tPrevious\n\t\t\t</button>\n\t\t\t<div className=\"form-debugger__nav-dots\">\n\t\t\t\t{steps.map((step, index) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\tkey={step.id}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tonClick={() => navigation.goToStep(step.id)}\n\t\t\t\t\t\tdisabled={index !== currentStep && !navigation.canGoToStep(step.id)}\n\t\t\t\t\t\tclassName={[\n\t\t\t\t\t\t\t'form-debugger__nav-dot',\n\t\t\t\t\t\t\tindex === currentStep && 'form-debugger__nav-dot--active',\n\t\t\t\t\t\t\tindex < currentStep && 'form-debugger__nav-dot--completed',\n\t\t\t\t\t\t\tindex !== currentStep &&\n\t\t\t\t\t\t\t\t!navigation.canGoToStep(step.id) &&\n\t\t\t\t\t\t\t\t'form-debugger__nav-dot--disabled',\n\t\t\t\t\t\t]\n\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t.join(' ')}\n\t\t\t\t\t\taria-label={`Go to ${step.title ?? `step ${index + 1}`}`}\n\t\t\t\t\t/>\n\t\t\t\t))}\n\t\t\t</div>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tonClick={navigation.goToNextStep}\n\t\t\t\tdisabled={!navigation.canGoNext}\n\t\t\t\tclassName=\"form-debugger__nav-button\"\n\t\t\t>\n\t\t\t\tNext\n\t\t\t</button>\n\t\t</div>\n\t);\n}\n\nfunction FormDebuggerPanel({\n\tonClose,\n\tshowStepDetails,\n\tshowFormState,\n}: { onClose: () => void } & Required<Omit<FormDebuggerProps, 'defaultOpen'>>) {\n\tconst { formState } = useFormContext();\n\tconst formValues = useWatch();\n\tconst view = useOptionalViewContext();\n\n\tconst steps = view?.steps ?? [];\n\tconst currentStep = view?.currentStepIndex ?? 0;\n\tconst totalSteps = steps.length;\n\tconst navigation = view?.navigation;\n\tconst isMultiStep = totalSteps > 1;\n\n\treturn (\n\t\t<div className=\"form-debugger__panel\">\n\t\t\t<DebuggerHeader\n\t\t\t\ttitle={view?.form.title ?? 'Form Debugger'}\n\t\t\t\tcurrentStep={currentStep}\n\t\t\t\ttotalSteps={totalSteps}\n\t\t\t\tonClose={onClose}\n\t\t\t/>\n\t\t\t<div className=\"form-debugger__content\">\n\t\t\t\t{isMultiStep && <DebuggerProgress currentStep={currentStep} totalSteps={totalSteps} />}\n\t\t\t\t{isMultiStep && steps.length > 0 && (\n\t\t\t\t\t<DebuggerSteps steps={steps} currentStep={currentStep} showDetails={showStepDetails} />\n\t\t\t\t)}\n\t\t\t\t{showFormState && (\n\t\t\t\t\t<DebuggerFormState\n\t\t\t\t\t\tformState={formState}\n\t\t\t\t\t\tformValues={formValues}\n\t\t\t\t\t\tsubmissionStatus={formState.submission.status}\n\t\t\t\t\t\tinvalidSteps={steps.filter(({ isInvalid }) => isInvalid).map(({ id }) => id)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t\t{isMultiStep && navigation ? (\n\t\t\t\t<DebuggerNav steps={steps} currentStep={currentStep} navigation={navigation} />\n\t\t\t) : null}\n\t\t</div>\n\t);\n}\n\n/**\n * Opt-in dev tool. Mount it as a child of `FormRenderer` to inspect values,\n * errors, and multi-step state:\n *\n * ```tsx\n * <FormRenderer config={config} engine={engine}>\n * <FormDebugger />\n * </FormRenderer>\n * ```\n *\n * Nothing in the library mounts this for you, so it stays out of production\n * bundles unless you import it.\n */\nexport function FormDebugger({\n\tdefaultOpen = false,\n\tshowStepDetails = true,\n\tshowFormState = true,\n}: FormDebuggerProps = {}) {\n\tconst [isExpanded, setIsExpanded] = useState(defaultOpen);\n\tconst panelRef = useRef<HTMLDivElement>(null);\n\n\tuseEffect(() => {\n\t\tif (!isExpanded) return;\n\n\t\tconst handleClickOutside = (event: MouseEvent) => {\n\t\t\tif (panelRef.current && !panelRef.current.contains(event.target as Node)) {\n\t\t\t\tsetIsExpanded(false);\n\t\t\t}\n\t\t};\n\n\t\tdocument.addEventListener('mousedown', handleClickOutside);\n\t\treturn () => document.removeEventListener('mousedown', handleClickOutside);\n\t}, [isExpanded]);\n\n\tif (typeof document === 'undefined') return null;\n\n\treturn createPortal(\n\t\t<div className=\"form-debugger\">\n\t\t\t<div\n\t\t\t\tref={panelRef}\n\t\t\t\tclassName={`form-debugger__widget ${isExpanded ? 'form-debugger__widget--expanded' : ''}`}\n\t\t\t>\n\t\t\t\t{!isExpanded ? (\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tonClick={() => setIsExpanded(true)}\n\t\t\t\t\t\tclassName=\"form-debugger__fab\"\n\t\t\t\t\t\taria-label=\"Open form debugger\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\t\t\t\twidth=\"20\"\n\t\t\t\t\t\t\theight=\"20\"\n\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\t\tstrokeWidth=\"2\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<path d=\"m8 6 4-4 4 4\" />\n\t\t\t\t\t\t\t<path d=\"M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22\" />\n\t\t\t\t\t\t\t<path d=\"m20 22-5-5\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t</button>\n\t\t\t\t) : (\n\t\t\t\t\t<FormDebuggerPanel\n\t\t\t\t\t\tonClose={() => setIsExpanded(false)}\n\t\t\t\t\t\tshowStepDetails={showStepDetails}\n\t\t\t\t\t\tshowFormState={showFormState}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>,\n\t\tdocument.body,\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,oBAAoB;AAgB3B,SAUC,KAVD;AAFF,SAAS,YAAY;AACpB,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAM;AAAA,MACN,OAAM;AAAA,MACN,QAAO;AAAA,MACP,SAAQ;AAAA,MACR,MAAK;AAAA,MACL,QAAO;AAAA,MACP,aAAY;AAAA,MACZ,eAAY;AAAA,MAEZ;AAAA,4BAAC,UAAK,GAAE,cAAa;AAAA,QACrB,oBAAC,UAAK,GAAE,cAAa;AAAA;AAAA;AA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;AAAA;AAAA,gBACA,OAAM;AAAA,gBACN,OAAM;AAAA,gBACN,QAAO;AAAA,gBACP,SAAQ;AAAA,gBACR,MAAK;AAAA,gBACL,QAAO;AAAA,gBACP,aAAY;AAAA,gBACZ,eAAY;AAAA,gBAEZ;AAAA,sCAAC,UAAK,GAAE,gBAAe;AAAA,kBACvB,oBAAC,UAAK,GAAE,yCAAwC;AAAA,kBAChD,oBAAC,UAAK,GAAE,cAAa;AAAA;AAAA;AAAA,YACtB;AAAA;AAAA,QACD,IAEA;AAAA,UAAC;AAAA;AAAA,YACA,SAAS,MAAM,cAAc,KAAK;AAAA,YAClC;AAAA,YACA;AAAA;AAAA,QACD;AAAA;AAAA,IAEF,GACD;AAAA,IACA,SAAS;AAAA,EACV;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,36 @@
1
+ // src/contexts/view-context.tsx
2
+ import { createContext, useContext } from "react";
3
+ import { getSlotConfig } from "@schema-engine/forms/recipes";
4
+ import { jsx } from "react/jsx-runtime";
5
+ var ViewContext = createContext(null);
6
+ function ViewProvider({ children, value }) {
7
+ return /* @__PURE__ */ jsx(ViewContext.Provider, { value, children });
8
+ }
9
+ function useViewContext() {
10
+ const context = useContext(ViewContext);
11
+ if (!context) {
12
+ throw new Error("useViewContext must be used within a ViewProvider");
13
+ }
14
+ return context;
15
+ }
16
+ function useOptionalViewContext() {
17
+ return useContext(ViewContext);
18
+ }
19
+ function useActiveStep() {
20
+ return useViewContext().activeStep;
21
+ }
22
+ function useFormNavigation() {
23
+ return useViewContext().navigation;
24
+ }
25
+ function useViewConfig(slot, schema) {
26
+ return getSlotConfig(useViewContext().viewConfig, slot, schema);
27
+ }
28
+
29
+ export {
30
+ ViewProvider,
31
+ useViewContext,
32
+ useOptionalViewContext,
33
+ useActiveStep,
34
+ useFormNavigation,
35
+ useViewConfig
36
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/contexts/view-context.tsx"],
4
+ "sourcesContent": ["import { createContext, useContext, type ReactNode } from 'react';\nimport type * as z from 'zod/mini';\nimport type { RecipeSlot, ViewModel, ViewNavigation } from '@schema-engine/forms/recipes';\nimport { getSlotConfig } from '@schema-engine/forms/recipes';\n\nexport type { ViewModel as ViewContextValue, ViewNavigation, ViewStep } from '@schema-engine/forms/recipes';\n\nconst ViewContext = createContext<ViewModel | null>(null);\n\nexport function ViewProvider({ children, value }: { children: ReactNode; value: ViewModel }) {\n\treturn <ViewContext.Provider value={value}>{children}</ViewContext.Provider>;\n}\n\nexport function useViewContext(): ViewModel {\n\tconst context = useContext(ViewContext);\n\tif (!context) {\n\t\tthrow new Error('useViewContext must be used within a ViewProvider');\n\t}\n\treturn context;\n}\n\nexport function useOptionalViewContext(): ViewModel | null {\n\treturn useContext(ViewContext);\n}\n\nexport function useActiveStep() {\n\treturn useViewContext().activeStep;\n}\n\nexport function useFormNavigation(): ViewNavigation {\n\treturn useViewContext().navigation;\n}\n\n/** Reads the complete config of one slot, typed by the slot schema's output. */\nexport function useViewConfig<TSchema extends z.ZodMiniType>(slot: RecipeSlot, schema: TSchema): z.output<TSchema> {\n\treturn getSlotConfig(useViewContext().viewConfig, slot, schema);\n}\n"],
5
+ "mappings": ";AAAA,SAAS,eAAe,kBAAkC;AAG1D,SAAS,qBAAqB;AAOtB;AAHR,IAAM,cAAc,cAAgC,IAAI;AAEjD,SAAS,aAAa,EAAE,UAAU,MAAM,GAA8C;AAC5F,SAAO,oBAAC,YAAY,UAAZ,EAAqB,OAAe,UAAS;AACtD;AAEO,SAAS,iBAA4B;AAC3C,QAAM,UAAU,WAAW,WAAW;AACtC,MAAI,CAAC,SAAS;AACb,UAAM,IAAI,MAAM,mDAAmD;AAAA,EACpE;AACA,SAAO;AACR;AAEO,SAAS,yBAA2C;AAC1D,SAAO,WAAW,WAAW;AAC9B;AAEO,SAAS,gBAAgB;AAC/B,SAAO,eAAe,EAAE;AACzB;AAEO,SAAS,oBAAoC;AACnD,SAAO,eAAe,EAAE;AACzB;AAGO,SAAS,cAA6C,MAAkB,QAAoC;AAClH,SAAO,cAAc,eAAe,EAAE,YAAY,MAAM,MAAM;AAC/D;",
6
+ "names": []
7
+ }
@@ -0,0 +1,30 @@
1
+ import {
2
+ FormElement
3
+ } from "./chunk-KG6Q7MNI.js";
4
+
5
+ // src/components/internals/form-elements.tsx
6
+ import {
7
+ composeElementKey,
8
+ composeFieldId,
9
+ composeFieldName
10
+ } from "@schema-engine/forms";
11
+ import { Fragment, jsx } from "react/jsx-runtime";
12
+ function FormElements({ elements, className, style, namePrefix, nameStrategy, instanceId }) {
13
+ const scope = { namePrefix, nameStrategy, instanceId };
14
+ return /* @__PURE__ */ jsx(Fragment, { children: elements.map((element, index) => /* @__PURE__ */ jsx(
15
+ FormElement,
16
+ {
17
+ config: element,
18
+ name: composeFieldName(element, scope),
19
+ id: composeFieldId(element, scope),
20
+ instanceId,
21
+ className,
22
+ style
23
+ },
24
+ composeElementKey(element, index, scope)
25
+ )) });
26
+ }
27
+
28
+ export {
29
+ FormElements
30
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/components/internals/form-elements.tsx"],
4
+ "sourcesContent": ["import type React from 'react';\nimport {\n\ttype FieldScope,\n\tcomposeElementKey,\n\tcomposeFieldId,\n\tcomposeFieldName,\n\ttype NormalizedElementConfig,\n} from '@schema-engine/forms';\nimport { FormElement } from './field-renderer';\n\nexport interface FormElementsProps {\n\telements: ReadonlyArray<NormalizedElementConfig>;\n\tclassName?: string;\n\tstyle?: React.CSSProperties;\n\t/**\n\t * Object scope (`address`) or array-item scope (`contacts.0`).\n\t * Fieldsets pass `config.name`; array items pass `${config.name}.${index}`.\n\t */\n\tnamePrefix?: string;\n\t/**\n\t * `join` (default): `${namePrefix}.${child.name}`.\n\t * `replace`: scalar array items bind to `namePrefix` itself.\n\t */\n\tnameStrategy?: FieldScope['nameStrategy'];\n\t/** Stable array-item identity. Do not pass the item index. */\n\tinstanceId?: string;\n}\n\nexport function FormElements({ elements, className, style, namePrefix, nameStrategy, instanceId }: FormElementsProps) {\n\tconst scope: FieldScope = { namePrefix, nameStrategy, instanceId };\n\n\treturn (\n\t\t<>\n\t\t\t{elements.map((element, index) => (\n\t\t\t\t<FormElement\n\t\t\t\t\tkey={composeElementKey(element, index, scope)}\n\t\t\t\t\tconfig={element}\n\t\t\t\t\tname={composeFieldName(element, scope)}\n\t\t\t\t\tid={composeFieldId(element, scope)}\n\t\t\t\t\tinstanceId={instanceId}\n\t\t\t\t\tclassName={className}\n\t\t\t\t\tstyle={style}\n\t\t\t\t/>\n\t\t\t))}\n\t\t</>\n\t);\n}\n"],
5
+ "mappings": ";;;;;AACA;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAyBL,mBAEE,WAFF;AAJK,SAAS,aAAa,EAAE,UAAU,WAAW,OAAO,YAAY,cAAc,WAAW,GAAsB;AACrH,QAAM,QAAoB,EAAE,YAAY,cAAc,WAAW;AAEjE,SACC,gCACE,mBAAS,IAAI,CAAC,SAAS,UACvB;AAAA,IAAC;AAAA;AAAA,MAEA,QAAQ;AAAA,MACR,MAAM,iBAAiB,SAAS,KAAK;AAAA,MACrC,IAAI,eAAe,SAAS,KAAK;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA;AAAA,IANK,kBAAkB,SAAS,OAAO,KAAK;AAAA,EAO7C,CACA,GACF;AAEF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,108 @@
1
+ import {
2
+ useFormStateContext
3
+ } from "./chunk-ZWEYALBG.js";
4
+
5
+ // src/hooks/form-state/use-form-context.ts
6
+ import { useMemo, useSyncExternalStore } from "react";
7
+ import {
8
+ issueText
9
+ } from "@schema-engine/forms/state-container";
10
+ function createTexts(formatIssue) {
11
+ const byErrors = /* @__PURE__ */ new WeakMap();
12
+ return (errors) => {
13
+ let texts = byErrors.get(errors);
14
+ if (!texts) {
15
+ texts = Object.fromEntries(
16
+ Object.entries(errors).map(([path, error]) => {
17
+ const message = issueText(error, path, formatIssue);
18
+ return [path, message === void 0 ? {} : { message }];
19
+ })
20
+ );
21
+ byErrors.set(errors, texts);
22
+ }
23
+ return texts;
24
+ };
25
+ }
26
+ function createTrackedFormState({ container, runtime }, formatIssue) {
27
+ const seen = /* @__PURE__ */ new Map();
28
+ const texts = createTexts(formatIssue);
29
+ let version = 0;
30
+ const read = (key) => {
31
+ switch (key) {
32
+ case "errors":
33
+ return container.getSnapshot().errors;
34
+ case "isValid":
35
+ return container.getSnapshot().isValid;
36
+ case "submission":
37
+ return runtime.getSnapshot().submission;
38
+ }
39
+ };
40
+ const track = (key, value) => {
41
+ if (!seen.has(key)) seen.set(key, read(key));
42
+ return value;
43
+ };
44
+ const formState = {
45
+ get errors() {
46
+ return track("errors", texts(container.getSnapshot().errors));
47
+ },
48
+ get isValid() {
49
+ return track("isValid", container.getSnapshot().isValid);
50
+ },
51
+ get submission() {
52
+ return track("submission", runtime.getSnapshot().submission);
53
+ }
54
+ };
55
+ const notify = (listener) => {
56
+ let changed = false;
57
+ seen.forEach((previous, key) => {
58
+ const current = read(key);
59
+ if (!Object.is(current, previous)) {
60
+ seen.set(key, current);
61
+ changed = true;
62
+ }
63
+ });
64
+ if (changed) {
65
+ version += 1;
66
+ listener();
67
+ }
68
+ };
69
+ return {
70
+ formState,
71
+ subscribe: (listener) => {
72
+ const onChange = () => notify(listener);
73
+ const stopContainer = container.subscribe(onChange);
74
+ const stopRuntime = runtime.subscribe(onChange);
75
+ onChange();
76
+ return () => {
77
+ stopContainer();
78
+ stopRuntime();
79
+ };
80
+ },
81
+ getSnapshot: () => version
82
+ };
83
+ }
84
+ function useFormContext() {
85
+ const { container, formatIssue, fields, runtime } = useFormStateContext();
86
+ const tracked = useMemo(
87
+ () => createTrackedFormState({ container, runtime }, formatIssue),
88
+ [container, runtime, formatIssue]
89
+ );
90
+ useSyncExternalStore(tracked.subscribe, tracked.getSnapshot, tracked.getSnapshot);
91
+ return useMemo(
92
+ () => ({
93
+ getValues: () => container.getSnapshot().values,
94
+ setValue: (name, value) => container.setValue(name, value),
95
+ validate: (name) => container.validate(typeof name === "string" ? [name] : name),
96
+ reset: (values) => container.reset(values),
97
+ setFocus: (name) => fields.focus(name),
98
+ formatIssue: (issue, { path }) => issueText(issue, path, formatIssue),
99
+ clearSubmission: () => runtime.clearSubmission(),
100
+ formState: tracked.formState
101
+ }),
102
+ [container, fields, runtime, formatIssue, tracked]
103
+ );
104
+ }
105
+
106
+ export {
107
+ useFormContext
108
+ };