@whatsaaaa/form-builder-react 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +37 -34
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ This is the React adapter of [form-builder](https://github.com/whatsaaaa/form-bu
|
|
|
18
18
|
pnpm add @whatsaaaa/form-builder-react @whatsaaaa/form-builder-schema @formisch/react valibot
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
React 18 or 19, `@formisch/react` 1.2 and Valibot 1.4.1 or later are required.
|
|
21
|
+
React 18 or 19, `@formisch/react` 1.2 and Valibot 1.4.1 or later are required. `@whatsaaaa/form-builder-schema` is a peer dependency, so install it too: the adapter and your code share its one copy, with the `createSchemaBuilder` and types your code imports.
|
|
22
22
|
|
|
23
23
|
## Example
|
|
24
24
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
import { checkComponents, checkLayoutComponents, coerceInput, createSchemaBuilder, dotPathOf, fieldPathsOfStep, findField, isRequired, issuesOfStep, selectFields, toFieldPath } from "@whatsaaaa/form-builder-schema";
|
|
2
2
|
import { focus, getErrors, getInput, insert, move, remove, setErrors, setInput, useField, useFieldArray, useForm, validate } from "@formisch/react";
|
|
3
3
|
import { Fragment, useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
-
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
5
4
|
import { INTERNAL, getFieldInput, setListener, untrack } from "@formisch/react/internals";
|
|
5
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/formisch-internals.ts
|
|
7
|
+
/** The `<form>` Formisch's `<Form>` renders, which it keeps on the store for its `submit()`. */
|
|
8
|
+
function formElementOf(form) {
|
|
9
|
+
return form["~internal"]?.element;
|
|
10
|
+
}
|
|
11
|
+
/** The form's input, read without subscribing the component that may be rendering now. */
|
|
12
|
+
const readInput = (form) => untrack(() => getFieldInput(form[INTERNAL]));
|
|
13
|
+
/**
|
|
14
|
+
* Calls `onChange` after each change of the form's input, until the function it returns is called.
|
|
15
|
+
* It reads the input as Formisch's own components do, with a listener: a signal that changes calls
|
|
16
|
+
* it once, so it reads the input again each time, the items of new array items too.
|
|
17
|
+
*/
|
|
18
|
+
function watchInput(form, onChange) {
|
|
19
|
+
const listener = [() => {
|
|
20
|
+
read();
|
|
21
|
+
onChange();
|
|
22
|
+
}, /* @__PURE__ */ new Set()];
|
|
23
|
+
const stop = () => {
|
|
24
|
+
for (const subscribers of listener[1]) subscribers.delete(listener);
|
|
25
|
+
listener[1].clear();
|
|
26
|
+
};
|
|
27
|
+
function read() {
|
|
28
|
+
stop();
|
|
29
|
+
untrack(() => {
|
|
30
|
+
setListener(listener);
|
|
31
|
+
try {
|
|
32
|
+
getFieldInput(form[INTERNAL]);
|
|
33
|
+
} finally {
|
|
34
|
+
setListener(void 0);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
read();
|
|
39
|
+
return stop;
|
|
40
|
+
}
|
|
6
41
|
// src/json-form-steps.ts
|
|
7
42
|
const fieldEvents = /* @__PURE__ */ new WeakMap();
|
|
8
43
|
/** What a field of `form` calls on each event, for a form with steps. Undefined with one step. */
|
|
@@ -176,10 +211,6 @@ function useJsonFormSteps(form, layout, modes, visibility) {
|
|
|
176
211
|
}
|
|
177
212
|
/** Resolves once the task that called it is over, and the browser is done with its event. */
|
|
178
213
|
const afterTask = () => new Promise((resolve) => setTimeout(resolve));
|
|
179
|
-
/** The `<form>` Formisch's `<Form>` renders, which it keeps on the store for its `submit()`. */
|
|
180
|
-
function formElementOf(form) {
|
|
181
|
-
return form["~internal"]?.element;
|
|
182
|
-
}
|
|
183
214
|
// src/array-field.tsx
|
|
184
215
|
/** Connects a container of kind `array` to Formisch, and renders your component for it. */
|
|
185
216
|
function ArrayField({ of, node, path, component: Component, renderItem }) {
|
|
@@ -409,37 +440,9 @@ function fieldsOf(nodes) {
|
|
|
409
440
|
*/
|
|
410
441
|
function useVisibility(form, visibility) {
|
|
411
442
|
const subscribe = useCallback((onChange) => visibility.conditional ? watchInput(form, onChange) : () => {}, [form, visibility]);
|
|
412
|
-
const getSnapshot = () => visibility.of(visibility.conditional ?
|
|
443
|
+
const getSnapshot = () => visibility.of(visibility.conditional ? readInput(form) : void 0);
|
|
413
444
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
414
445
|
}
|
|
415
|
-
/**
|
|
416
|
-
* Calls `onChange` after each change of the form's input, until the function it returns is called.
|
|
417
|
-
* It reads the input as Formisch's own components do, with a listener: a signal that changes calls
|
|
418
|
-
* it once, so it reads the input again each time, the items of new array items too.
|
|
419
|
-
*/
|
|
420
|
-
function watchInput(form, onChange) {
|
|
421
|
-
const listener = [() => {
|
|
422
|
-
read();
|
|
423
|
-
onChange();
|
|
424
|
-
}, /* @__PURE__ */ new Set()];
|
|
425
|
-
const stop = () => {
|
|
426
|
-
for (const subscribers of listener[1]) subscribers.delete(listener);
|
|
427
|
-
listener[1].clear();
|
|
428
|
-
};
|
|
429
|
-
function read() {
|
|
430
|
-
stop();
|
|
431
|
-
untrack(() => {
|
|
432
|
-
setListener(listener);
|
|
433
|
-
try {
|
|
434
|
-
getFieldInput(form[INTERNAL]);
|
|
435
|
-
} finally {
|
|
436
|
-
setListener(void 0);
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
read();
|
|
441
|
-
return stop;
|
|
442
|
-
}
|
|
443
446
|
// src/use-json-form.ts
|
|
444
447
|
function useJsonForm(definition, options = {}) {
|
|
445
448
|
const [built] = useState(() => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Display","Group"],"sources":["../src/json-form-steps.ts","../src/array-field.tsx","../src/value-field.tsx","../src/render-fields.tsx","../src/json-field.tsx","../src/render-layout.tsx","../src/json-fields.tsx","../src/use-visibility.ts","../src/use-json-form.ts"],"sourcesContent":["import {\n focus,\n type FormStore,\n getErrors,\n getInput,\n setErrors,\n validate,\n type ValidationMode,\n} from '@formisch/react'\nimport {\n type FieldPath,\n fieldPathsOfStep,\n type FormLayout,\n issuesOfStep,\n type LayoutStep,\n type StepIssue,\n type VisibilityState,\n} from '@whatsaaaa/form-builder-schema'\nimport { useEffect, useMemo, useRef, useState } from 'react'\n\n/** The steps of a form, from its layout. A form without `steps` in its layout has one. */\nexport interface JsonFormSteps {\n /**\n * The steps on show, in order. A step whose fields are all hidden by conditions, or that is\n * hidden itself, is left out, unless it is the current one: Next and Back skip it.\n */\n readonly list: readonly LayoutStep[]\n /** The index of the current step in `list`. */\n readonly index: number\n /** The step `<JsonFields>` renders. */\n readonly current: LayoutStep\n readonly isFirst: boolean\n readonly isLast: boolean\n /**\n * Validates the whole form, and moves to the next step when the fields of this one have no\n * issues. Otherwise it stays, and focuses the first field with an issue, in layout order.\n * Resolves to whether it moved.\n */\n next(): Promise<boolean>\n /** Moves to the step before, without validating. */\n back(): void\n /**\n * Moves to the step at `index`. Back is free, and forward validates every step on the way, like\n * `next()`, and stops at the first with issues. Resolves to whether it got there.\n */\n goTo(index: number): Promise<boolean>\n}\n\n/** A field's error messages in Formisch, or null. */\ntype Errors = [string, ...string[]] | null\n\n/** What a field tells the steps it was through, by Formisch's name for the validation mode. */\nexport type FieldEvent = Exclude<ValidationMode, 'initial' | 'submit'>\n\n/** Revalidates a step that failed Next on each field event, like a form after a failed submit. */\ntype FieldEvents = (event: FieldEvent) => void\n\nconst fieldEvents = new WeakMap<FormStore, FieldEvents>()\n\n/** What a field of `form` calls on each event, for a form with steps. Undefined with one step. */\nexport const fieldEventsOf = (form: FormStore): FieldEvents | undefined => fieldEvents.get(form)\n\ninterface Modes {\n validate?: ValidationMode | undefined\n revalidate?: Exclude<ValidationMode, 'initial'> | undefined\n}\n\n/**\n * The steps of `layout`, for `useJsonForm`. With more than one, a step shows the errors it had\n * when the user left it, and none the first time they get to it, a step that failed Next\n * revalidates as the user fixes it, a submit before the last step moves on like Next, and a submit\n * that fails because of an earlier step goes back to it. The steps `visibility` hides are skipped.\n * Like Formisch's `useForm`, it reads the validation modes on the first render.\n */\nexport function useJsonFormSteps(\n form: FormStore,\n layout: FormLayout,\n modes: Modes,\n visibility: VisibilityState,\n): JsonFormSteps {\n const all = layout.steps\n // The current step, by its index in `all`, as are the steps in `state` below.\n const [index, setIndex] = useState(0)\n // What the async methods and the event handlers read: always the latest.\n const state = useRef({\n index: 0,\n // The errors each step had when the user left it, by the JSON of each field's path.\n left: new Map<number, Map<string, Errors>>(),\n // The steps that failed Next, and haven't passed since.\n failed: new Set<number>(),\n // The field to focus once the step it is on has rendered.\n focus: undefined as FieldPath | undefined,\n // Whether a submit on the last step is on its way through Formisch.\n submitting: false,\n modes,\n })\n\n const methods = useMemo(() => {\n const at = state.current\n // The current step stays on show, so it never goes from under the user.\n const shown = () => all.filter((step, i) => i === at.index || !visibility.isStepHidden(step))\n const position = (list: readonly LayoutStep[]) => list.indexOf(all[at.index] as LayoutStep)\n\n async function goTo(target: number): Promise<boolean> {\n const list = shown()\n if (!Number.isInteger(target) || target < 0 || target >= list.length) {\n throw new RangeError(`No step ${target}. The form has ${list.length}.`)\n }\n const to = all.indexOf(list[target] as LayoutStep)\n if (target <= position(list)) {\n move(to)\n return true\n }\n // Next goes on once the task that called it is over. A click runs its default action after its\n // handlers, and React can render in between: a Next button that turns into the submit button on\n // the last step would then submit the form as the user gets there.\n await afterTask()\n const { issues } = await validate(form)\n for (const step of list.slice(position(list), target)) {\n const found = issuesOfStep(step, issues)\n if (found.length) {\n stop(all.indexOf(step), found)\n return false\n }\n at.failed.delete(all.indexOf(step))\n }\n move(to)\n return true\n }\n\n /**\n * Moves to a step as the user left it: with the errors it had then, and none the first time, and\n * revalidating if it failed Next. Validating the steps before set errors on its fields, which\n * the user never saw.\n */\n function move(target: number) {\n leave()\n const errors = at.left.get(target)\n for (const path of fieldPathsOfStep(all[target] as LayoutStep, getInput(form))) {\n setErrors(form, { path, errors: errors?.get(JSON.stringify(path)) ?? null } as never)\n }\n at.index = target\n setIndex(target)\n }\n\n /** Keeps the errors of the current step, for when the user comes back to it. */\n function leave() {\n const paths = fieldPathsOfStep(all[at.index] as LayoutStep, getInput(form))\n const errors = paths.map((path): [string, Errors] => [\n JSON.stringify(path),\n getErrors(form, { path } as never),\n ])\n at.left.set(at.index, new Map(errors))\n }\n\n /** Stays on, or goes to, the step at `target`, with its issues shown. */\n function stop(target: number, found: readonly StepIssue[]) {\n at.failed.add(target)\n // A group or an array has no element: the first field that has one gets the focus.\n const path = found.find((issue) => issue.field.role === 'value')?.path\n if (target === at.index) {\n if (path) focus(form, { path: path as never })\n return\n }\n leave()\n at.focus = path\n at.index = target\n setIndex(target)\n }\n\n const events: FieldEvents = (event) => {\n // In the other modes, Formisch revalidates a field with errors itself.\n const validateMode = at.modes.validate ?? 'submit'\n if (!at.failed.has(at.index) || validateMode !== 'submit' || form.isSubmitted) return\n if (event === (at.modes.revalidate ?? 'input')) void validate(form)\n }\n\n /** After a failed submit: back to the first step before this one with issues, if any. */\n async function afterSubmit() {\n const { issues } = await validate(form)\n const list = shown()\n const step = list.find((each) => issuesOfStep(each, issues).length)\n if (step && list.indexOf(step) < position(list)) {\n stop(all.indexOf(step), issuesOfStep(step, issues))\n }\n }\n\n const isLast = () => {\n const list = shown()\n return position(list) === list.length - 1\n }\n const next = () => (isLast() ? Promise.resolve(false) : goTo(position(shown()) + 1))\n const back = () => {\n const list = shown()\n const before = list[position(list) - 1]\n if (before) move(all.indexOf(before))\n }\n return { goTo, next, back, isLast, events, afterSubmit }\n }, [form, all, visibility])\n\n // The field a step was stopped on, once the step has rendered.\n useEffect(() => {\n const path = state.current.focus\n state.current.focus = undefined\n if (path) focus(form, { path: path as never })\n }, [form, index])\n\n const stepped = all.length > 1\n useEffect(() => {\n if (!stepped) return\n fieldEvents.set(form, methods.events)\n // Before the last step, a submit, like Enter in a step with a single text input, is a Next.\n // It is caught on its way down to the form, before Formisch's own handler sees it.\n const onSubmit = (event: Event) => {\n if (event.target !== formElementOf(form)) return\n if (methods.isLast()) {\n state.current.submitting = true\n return\n }\n event.preventDefault()\n event.stopImmediatePropagation()\n void methods.next()\n }\n document.addEventListener('submit', onSubmit, { capture: true })\n return () => {\n fieldEvents.delete(form)\n document.removeEventListener('submit', onSubmit, { capture: true })\n }\n }, [form, methods, stepped])\n\n // A submit that fails because of a step before the last, e.g. on a form rule, goes back to it.\n // React can batch the start and the end of a submit into one render, so the submit is marked\n // as it starts, and each render checks whether Formisch has finished it.\n const submitting = form.isSubmitting\n useEffect(() => {\n if (!state.current.submitting || submitting) return\n state.current.submitting = false\n if (!form.isValid) void methods.afterSubmit()\n })\n\n return useMemo(() => {\n const list = all.filter((step, i) => i === index || !visibility.isStepHidden(step))\n const current = all[index] as LayoutStep\n const at = list.indexOf(current)\n return {\n list,\n index: at,\n current,\n isFirst: at === 0,\n isLast: at === list.length - 1,\n next: methods.next,\n back: methods.back,\n goTo: methods.goTo,\n }\n }, [all, index, visibility, methods])\n}\n\n/** Resolves once the task that called it is over, and the browser is done with its event. */\nconst afterTask = () => new Promise<void>((resolve) => setTimeout(resolve))\n\n/** The `<form>` Formisch's `<Form>` renders, which it keeps on the store for its `submit()`. */\nfunction formElementOf(form: FormStore): HTMLFormElement | undefined {\n return (form as unknown as { '~internal'?: { element?: HTMLFormElement } })['~internal']?.element\n}\n","import { insert, move, remove, useFieldArray } from '@formisch/react'\nimport type { FieldNode, FieldPath } from '@whatsaaaa/form-builder-schema'\nimport { type ComponentType, type ReactElement, type ReactNode, useMemo } from 'react'\nimport type { ArrayFieldProps } from './field-components'\nimport { fieldEventsOf } from './json-form-steps'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\ninterface ArrayFieldConnectionProps {\n of: AnyJsonFormInstance\n node: FieldNode\n path: FieldPath\n component: ComponentType<ArrayFieldProps>\n /** Renders the fields of the item at `index`. */\n renderItem: (index: number) => ReactNode\n}\n\n/** Connects a container of kind `array` to Formisch, and renders your component for it. */\nexport function ArrayField({\n of,\n node,\n path,\n component: Component,\n renderItem,\n}: ArrayFieldConnectionProps): ReactElement {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const array = useFieldArray(of.form, { path: path as never })\n\n // Formisch keeps the path it got while the array is the same, so the methods stay the same too.\n const { form, builder } = of\n const { field } = node\n const at = array.path\n // In a form with steps, a step that failed Next revalidates on a change of its items too.\n const methods = useMemo(\n () => ({\n // A new item starts with the defaults of its fields, like the items of a new form.\n add: () => {\n insert(form, { path: at, initialInput: builder.getItemInput(field) as never })\n fieldEventsOf(form)?.('input')\n },\n remove: (index: number) => {\n remove(form, { path: at, at: index })\n fieldEventsOf(form)?.('input')\n },\n move: (from: number, to: number) => {\n move(form, { path: at, from, to })\n fieldEventsOf(form)?.('input')\n },\n }),\n [form, builder, field, at],\n )\n\n return (\n <Component field={field} path={path} items={array.items} errors={array.errors} {...methods}>\n {renderItem}\n </Component>\n )\n}\n","import { useField } from '@formisch/react'\nimport {\n coerceInput,\n type FieldNode,\n type FieldPath,\n isRequired,\n} from '@whatsaaaa/form-builder-schema'\nimport { type ComponentType, type ReactElement, useCallback } from 'react'\nimport type { ValueFieldProps } from './field-components'\nimport { fieldEventsOf } from './json-form-steps'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\ninterface ValueFieldConnectionProps {\n of: AnyJsonFormInstance\n node: FieldNode\n path: FieldPath\n component: ComponentType<ValueFieldProps>\n}\n\n/** Connects a field with a value to Formisch, and renders your component for it. */\nexport function ValueField({\n of,\n node,\n path,\n component: Component,\n}: ValueFieldConnectionProps): ReactElement {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const field = useField(of.form, { path: path as never })\n const { form } = of\n const setInput = useCallback(\n (input: unknown) => {\n field.onChange(coerceInput(input, node) as never)\n fieldEventsOf(form)?.('input')\n },\n [field, node, form],\n )\n // In a form with steps, a step that failed Next revalidates on these events too.\n const inputProps =\n of.steps.list.length > 1\n ? {\n ...field.props,\n onFocus: () => {\n field.props.onFocus()\n fieldEventsOf(form)?.('touch')\n },\n onChange: (event: Parameters<typeof field.props.onChange>[0]) => {\n field.props.onChange(event)\n fieldEventsOf(form)?.('input')\n fieldEventsOf(form)?.('change')\n },\n onBlur: () => {\n field.props.onBlur()\n fieldEventsOf(form)?.('blur')\n },\n }\n : field.props\n\n return (\n <Component\n field={node.field}\n path={path}\n kind={node.kind}\n required={isRequired(node.field)}\n input={field.input}\n errors={field.errors}\n inputProps={inputProps}\n setInput={setInput}\n />\n )\n}\n","import { dotPathOf, type FieldNode, toFieldPath } from '@whatsaaaa/form-builder-schema'\nimport type { ComponentType, ReactElement, ReactNode } from 'react'\nimport { ArrayField } from './array-field'\nimport type {\n ArrayFieldProps,\n DisplayFieldProps,\n FieldComponents,\n GroupFieldProps,\n ValueFieldProps,\n} from './field-components'\nimport type { AnyJsonFormInstance } from './use-json-form'\nimport { ValueField } from './value-field'\n\n/** What `<JsonFields>` and `<JsonField>` render with. */\nexport interface RenderContext {\n of: AnyJsonFormInstance\n components: FieldComponents\n}\n\n/** The components from the props, or else the ones `useJsonForm` got. */\nexport function resolveComponents(\n components: FieldComponents | undefined,\n of: AnyJsonFormInstance,\n): FieldComponents {\n const resolved = components ?? of.components\n if (!resolved) {\n throw new TypeError('No field components. Pass them to useJsonForm, or to the component.')\n }\n return resolved\n}\n\n/**\n * Renders the fields that conditions don't hide. `indexes` are the indexes of the array items the\n * fields are in, outermost first.\n */\nexport function renderFields(\n ctx: RenderContext,\n nodes: readonly FieldNode[],\n indexes: readonly number[],\n): ReactElement[] {\n const { visibility } = ctx.of\n // A display element is keyed by its position among all the nodes, which stays the same.\n return nodes.flatMap((node, position) =>\n visibility.isHidden(node, indexes)\n ? []\n : [\n renderField(ctx, node, indexes, dotPathOf(node) ?? `#${position}`, (inner) =>\n renderFields(ctx, node.children, inner),\n ),\n ],\n )\n}\n\n/**\n * Renders one field with its component. `children` renders the fields inside a group, or inside\n * the item of an array, with the indexes of the items they are in.\n */\nexport function renderField(\n ctx: RenderContext,\n node: FieldNode,\n indexes: readonly number[],\n key: string,\n children: (indexes: readonly number[]) => ReactNode,\n): ReactElement {\n // The fields were checked for components, and the role tells which props the component takes.\n const component = ctx.components[node.type]\n const path = toFieldPath(node.dataPath, indexes)\n switch (node.role) {\n case 'display': {\n const Display = component as ComponentType<DisplayFieldProps>\n return <Display key={key} field={node.field} />\n }\n case 'group': {\n const Group = component as ComponentType<GroupFieldProps>\n return (\n <Group key={key} field={node.field} path={path}>\n {children(indexes)}\n </Group>\n )\n }\n case 'array':\n return (\n <ArrayField\n key={key}\n of={ctx.of}\n node={node}\n path={path}\n component={component as ComponentType<ArrayFieldProps>}\n renderItem={(index) => children([...indexes, index])}\n />\n )\n case 'value':\n return (\n <ValueField\n key={key}\n of={ctx.of}\n node={node}\n path={path}\n component={component as ComponentType<ValueFieldProps>}\n />\n )\n }\n}\n","import { checkComponents, dotPathOf, findField } from '@whatsaaaa/form-builder-schema'\nimport type { ReactElement } from 'react'\nimport type { FieldComponents } from './field-components'\nimport { type RenderContext, renderField, renderFields, resolveComponents } from './render-fields'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\nexport interface JsonFieldProps {\n /** What `useJsonForm` returned. */\n of: AnyJsonFormInstance\n /** The field's path: `'email'`, or `'address.city'` for a field of a group. */\n path: string\n /** Defaults to the components `useJsonForm` got. */\n components?: FieldComponents | undefined\n}\n\n/**\n * Renders one field of a `useJsonForm` form, wherever you put it inside Formisch's `<Form>`. A\n * group or an array comes with its fields. Leave the field out of `<JsonFields>` with `except`.\n * It renders nothing while conditions hide the field.\n */\nexport function JsonField({ of, path, components }: JsonFieldProps): ReactElement | null {\n const node = findField(of.fields, path, { placed: true })\n const ctx: RenderContext = { of, components: resolveComponents(components, of) }\n checkComponents([node], ctx.components)\n\n if (of.visibility.isHidden(node, [])) return null\n return renderField(ctx, node, [], dotPathOf(node) ?? '#0', (indexes) =>\n renderFields(ctx, node.children, indexes),\n )\n}\n","import type { IsFieldShown, LayoutNode } from '@whatsaaaa/form-builder-schema'\nimport { type ComponentType, Fragment, type ReactElement, type ReactNode } from 'react'\nimport type { LayoutComponents, RowProps, SectionProps } from './field-components'\nimport { type RenderContext, renderField } from './render-fields'\n\n/** What `<JsonFields>` renders a layout with. */\nexport interface LayoutContext extends RenderContext {\n layoutComponents: LayoutComponents\n /** The content of the layout's slots, by name. */\n slots: Readonly<Record<string, ReactNode>>\n /** False for a field left out with `except`. */\n isShown: IsFieldShown\n}\n\n/**\n * Renders layout nodes. A field left out or hidden by conditions drops out, and so does a section\n * hidden by them, and a section or a row left without fields. `indexes` are the indexes of the\n * array items the nodes are in, outermost first.\n */\nexport function renderLayout(\n ctx: LayoutContext,\n nodes: readonly LayoutNode[],\n indexes: readonly number[],\n): ReactElement[] {\n return ctx.of.visibility\n .shownNodes(nodes, indexes, ctx.isShown)\n .map((node) => renderNode(ctx, node, indexes))\n}\n\nfunction renderNode(\n ctx: LayoutContext,\n node: LayoutNode,\n indexes: readonly number[],\n): ReactElement {\n const { key } = node\n switch (node.type) {\n case 'field':\n return renderField(ctx, node.node, indexes, key, (inner) =>\n renderLayout(ctx, node.children, inner),\n )\n case 'section': {\n // The layout was checked for components.\n const Section = ctx.layoutComponents.section as ComponentType<SectionProps>\n return (\n <Section key={key} section={node.section}>\n {renderLayout(ctx, node.children, indexes)}\n </Section>\n )\n }\n case 'row': {\n const Row = ctx.layoutComponents.row as ComponentType<RowProps>\n return (\n <Row key={key} row={node.row} spans={node.children.map((cell) => cell.span)}>\n {(index) => renderNode(ctx, node.children[index] as LayoutNode, indexes)}\n </Row>\n )\n }\n case 'slot':\n return <Fragment key={key}>{ctx.slots[node.name]}</Fragment>\n }\n}\n","import {\n checkComponents,\n checkLayoutComponents,\n dotPathOf,\n type FieldNode,\n type LayoutNode,\n selectFields,\n} from '@whatsaaaa/form-builder-schema'\nimport { Fragment, type ReactElement, type ReactNode } from 'react'\nimport type { FieldComponents, LayoutComponents } from './field-components'\nimport { type LayoutContext, renderLayout } from './render-layout'\nimport { type RenderContext, renderFields, resolveComponents } from './render-fields'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\nexport interface JsonFieldsProps {\n /** What `useJsonForm` returned. */\n of: AnyJsonFormInstance\n /** Defaults to the components `useJsonForm` got. */\n components?: FieldComponents | undefined\n /** Defaults to the layout components `useJsonForm` got. */\n layoutComponents?: LayoutComponents | undefined\n /** The content of the layout's slots, by name: `{ submit: <button type=\"submit\">Save</button> }`. */\n slots?: Readonly<Record<string, ReactNode>> | undefined\n /** Renders only these fields, by path, in the order of the definition, without the layout. */\n only?: readonly string[] | undefined\n /**\n * Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. A section or a\n * row left without fields drops out too.\n */\n except?: readonly string[] | undefined\n /** Renders the step at this index instead of the current one, e.g. on a review page. */\n step?: number | undefined\n}\n\n/**\n * Renders the fields of a `useJsonForm` form with your components, one per field type, where the\n * definition's `layout` puts them: the current step, with its sections, rows and slots. It renders\n * nothing of its own, so put it inside Formisch's `<Form>` with your own submit button.\n */\nexport function JsonFields(props: JsonFieldsProps): ReactElement {\n const { of, only, except } = props\n const ctx: RenderContext = { of, components: resolveComponents(props.components, of) }\n const nodes = selectFields(of.fields, { only, except })\n // Without a layout, it renders the fields the way it always did, and so with `only`.\n if (only || !of.definition.layout) {\n checkComponents(nodes, ctx.components)\n return <>{renderFields(ctx, nodes, [])}</>\n }\n\n const { layout, steps } = of\n const left = new Set(except)\n const layoutCtx: LayoutContext = {\n ...ctx,\n layoutComponents: props.layoutComponents ?? of.layoutComponents ?? {},\n slots: props.slots ?? {},\n isShown: (node) => !left.has(dotPathOf(node) ?? ''),\n }\n checkComponents(\n layout.steps.flatMap((step) => fieldsOf(step.children)),\n ctx.components,\n )\n checkLayoutComponents(layout, layoutCtx.layoutComponents, layoutCtx.slots)\n\n const index = props.step ?? steps.index\n const step = steps.list[index]\n if (!step) throw new RangeError(`No step ${props.step}. The form has ${steps.list.length}.`)\n // Keyed by the step, so another step's fields don't take over this one's components.\n return <Fragment key={index}>{renderLayout(layoutCtx, step.children, [])}</Fragment>\n}\n\n/** Every field of the nodes, display elements written in the layout included. */\nfunction fieldsOf(nodes: readonly LayoutNode[]): FieldNode[] {\n return nodes.flatMap((node) => {\n if (node.type === 'slot') return []\n const inner = fieldsOf(node.children)\n return node.type === 'field' ? [node.node, ...inner] : inner\n })\n}\n","import type { FormStore } from '@formisch/react'\nimport {\n getFieldInput,\n INTERNAL,\n type Listener,\n setListener,\n untrack,\n} from '@formisch/react/internals'\nimport type { Visibility, VisibilityState } from '@whatsaaaa/form-builder-schema'\nimport { useCallback, useSyncExternalStore } from 'react'\n\n/**\n * What the conditions of the definition hide for the form's input, as it changes. Formisch\n * re-renders a component for each signal it reads, so reading the whole input in `useJsonForm`\n * would re-render the form on every keystroke. This watches the input outside React instead, and\n * re-renders only when the state changes: `of()` gives the same object until then. Without\n * conditions, it watches nothing.\n */\nexport function useVisibility(form: FormStore, visibility: Visibility): VisibilityState {\n const subscribe = useCallback(\n (onChange: () => void) => (visibility.conditional ? watchInput(form, onChange) : () => {}),\n [form, visibility],\n )\n const getSnapshot = () =>\n visibility.of(visibility.conditional ? untrack(() => getFieldInput(form[INTERNAL])) : undefined)\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n}\n\n/**\n * Calls `onChange` after each change of the form's input, until the function it returns is called.\n * It reads the input as Formisch's own components do, with a listener: a signal that changes calls\n * it once, so it reads the input again each time, the items of new array items too.\n */\nfunction watchInput(form: FormStore, onChange: () => void): () => void {\n const listener: Listener = [\n () => {\n read()\n onChange()\n },\n new Set(),\n ]\n const stop = () => {\n for (const subscribers of listener[1]) subscribers.delete(listener)\n listener[1].clear()\n }\n function read() {\n stop()\n // untrack() sets back the listener of a component that may be rendering now.\n untrack(() => {\n setListener(listener)\n try {\n getFieldInput(form[INTERNAL])\n } finally {\n setListener(undefined)\n }\n })\n }\n read()\n return stop\n}\n","import {\n type FormSchema,\n type FormStore,\n setInput,\n useForm,\n type ValidationMode,\n} from '@formisch/react'\nimport {\n createSchemaBuilder,\n type FieldNode,\n type FormLayout,\n type JsonForm,\n type BuiltSchema,\n type SchemaBuilder,\n type TypedBuiltSchema,\n type VisibilityState,\n} from '@whatsaaaa/form-builder-schema'\nimport { useEffect, useMemo, useState } from 'react'\nimport type { FieldComponents, LayoutComponents } from './field-components'\nimport { type JsonFormSteps, useJsonFormSteps } from './json-form-steps'\nimport { useVisibility } from './use-visibility'\n\nexport interface UseJsonFormOptions {\n /** Builds the schema and knows your own types and rules. Defaults to `createSchemaBuilder()`. */\n builder?: SchemaBuilder\n /** Your component for each field type, so `<JsonFields>` and `<JsonField>` don't need them. */\n components?: FieldComponents\n /** Your component for each layout type the definition's `layout` uses, like `section`. */\n layoutComponents?: LayoutComponents\n /** When a field is validated the first time, as in Formisch. */\n validate?: ValidationMode\n /** When a field is validated again after that, as in Formisch. */\n revalidate?: Exclude<ValidationMode, 'initial'>\n}\n\n/** What `useJsonForm` returns. Pass it to `<JsonFields>`. */\nexport interface JsonFormInstance<TSchema extends FormSchema = BuiltSchema> {\n /** The Formisch form: pass it to Formisch's `<Form of>`, or to any of its methods. */\n readonly form: FormStore<TSchema>\n readonly definition: JsonForm\n readonly builder: SchemaBuilder\n /** The components from the options, if any. */\n readonly components: FieldComponents | undefined\n /** The layout components from the options, if any. */\n readonly layoutComponents: LayoutComponents | undefined\n /** The definition's fields as a tree, for `<JsonFields only>` and `<JsonField>`. */\n readonly fields: readonly FieldNode[]\n /** The definition's layout, the way `<JsonFields>` renders it. */\n readonly layout: FormLayout\n /** The layout's steps: the current one, and Next, Back and Go to. A form without steps has one. */\n readonly steps: JsonFormSteps\n /**\n * What the conditions of the builder's extensions hide for the form's input now, like the\n * `affects` of `@whatsaaaa/form-builder-affects`: `<JsonFields>` and `<JsonField>` leave it out.\n * Read it in your own renderers. A new object only when what is hidden changes, so the form\n * re-renders for that, not for every keystroke. Without conditions, it hides nothing.\n */\n readonly visibility: VisibilityState\n}\n\n/** Any form `useJsonForm` returns, typed or not: what the components take. */\nexport type AnyJsonFormInstance = JsonFormInstance<FormSchema>\n\n/**\n * A Formisch form for a definition, with its schema and initial input from the builder. A\n * definition with issues throws the builder's `DefinitionError`, so run `validate()` first when it\n * comes from outside your code. Like Formisch's `useForm`, it reads the definition, the builder and\n * the validation modes on the first render: give the component a new `key` to use another\n * definition. The components and layout components are read on every render. With conditions, it\n * clears the fields they clear as soon as they do, with Formisch's `setInput`, wherever the fields\n * are rendered.\n */\nexport function useJsonForm(definition: JsonForm, options?: UseJsonFormOptions): JsonFormInstance\n/**\n * The same, with the form typed by your input type, and output type when it differs, so Formisch's\n * paths and values are checked. The types are yours to keep in step with the definition.\n */\nexport function useJsonForm<TInput extends object, TOutput extends object = TInput>(\n definition: JsonForm,\n options?: UseJsonFormOptions,\n): JsonFormInstance<TypedBuiltSchema<TInput, TOutput>>\nexport function useJsonForm(\n definition: JsonForm,\n options: UseJsonFormOptions = {},\n): JsonFormInstance {\n // Formisch reads its config on the first render only, so the schema is built once too.\n const [built] = useState(() => {\n const builder = options.builder ?? createSchemaBuilder()\n return {\n definition,\n builder,\n schema: builder.build(definition),\n initialInput: builder.getInitialInput(definition),\n fields: builder.getFieldTree(definition),\n layout: builder.getLayout(definition),\n visibility: builder.getVisibility(definition),\n }\n })\n const form = useForm({\n schema: built.schema,\n initialInput: built.initialInput,\n validate: options.validate,\n revalidate: options.revalidate,\n })\n const visibility = useVisibility(form, built.visibility)\n // A new state means something to clear may have come. It is empty once the fields are blank.\n const { toClear } = visibility\n useEffect(() => {\n // The paths come from the definition at runtime, so the schema's types can't check them.\n for (const { path, input } of toClear) setInput(form, { path, input } as never)\n }, [form, toClear])\n const steps = useJsonFormSteps(form, built.layout, options, visibility)\n const { components, layoutComponents } = options\n return useMemo(\n () => ({\n form,\n definition: built.definition,\n builder: built.builder,\n components,\n layoutComponents,\n fields: built.fields,\n layout: built.layout,\n steps,\n visibility,\n }),\n [form, built, components, layoutComponents, steps, visibility],\n )\n}\n"],"mappings":";;;;;;AAyDA,MAAM,8BAAc,IAAI,QAAgC;;AAGxD,MAAa,iBAAiB,SAA6C,YAAY,IAAI,IAAI;;;;;;;;AAc/F,SAAgB,iBACd,MACA,QACA,OACA,YACe;CACf,MAAM,MAAM,OAAO;CAEnB,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CAEpC,MAAM,QAAQ,OAAO;EACnB,OAAO;EAEP,sBAAM,IAAI,IAAiC;EAE3C,wBAAQ,IAAI,IAAY;EAExB,OAAO,KAAA;EAEP,YAAY;EACZ;CACF,CAAC;CAED,MAAM,UAAU,cAAc;EAC5B,MAAM,KAAK,MAAM;EAEjB,MAAM,cAAc,IAAI,QAAQ,MAAM,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,aAAa,IAAI,CAAC;EAC5F,MAAM,YAAY,SAAgC,KAAK,QAAQ,IAAI,GAAG,MAAoB;EAE1F,eAAe,KAAK,QAAkC;GACpD,MAAM,OAAO,MAAM;GACnB,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,SAAS,KAAK,UAAU,KAAK,QAC5D,MAAM,IAAI,WAAW,WAAW,OAAO,iBAAiB,KAAK,OAAO,EAAE;GAExE,MAAM,KAAK,IAAI,QAAQ,KAAK,OAAqB;GACjD,IAAI,UAAU,SAAS,IAAI,GAAG;IAC5B,KAAK,EAAE;IACP,OAAO;GACT;GAIA,MAAM,UAAU;GAChB,MAAM,EAAE,WAAW,MAAM,SAAS,IAAI;GACtC,KAAK,MAAM,QAAQ,KAAK,MAAM,SAAS,IAAI,GAAG,MAAM,GAAG;IACrD,MAAM,QAAQ,aAAa,MAAM,MAAM;IACvC,IAAI,MAAM,QAAQ;KAChB,KAAK,IAAI,QAAQ,IAAI,GAAG,KAAK;KAC7B,OAAO;IACT;IACA,GAAG,OAAO,OAAO,IAAI,QAAQ,IAAI,C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,cAAc;GACZ,YAAY,QAAQ;GACpB,IAAI;IACF,cAAc,KAAK,SAAS;GAC9B,UAAU;IACR,YAAY,KAAA,CAAS;GACvB;EACF,CAAC;CACH;CACA,KAAK;CACL,OAAO;AACT;;ACsBA,SAAgB,YACd,YACA,UAA8B,CAAC,GACb;CAElB,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,UAAU,QAAQ,WAAW,oBAAoB;EACvD,OAAO;GACL;GACA;GACA,QAAQ,QAAQ,MAAM,UAAU;GAChC,cAAc,QAAQ,gBAAgB,UAAU;GAChD,QAAQ,QAAQ,aAAa,UAAU;GACvC,QAAQ,QAAQ,UAAU,UAAU;GACpC,YAAY,QAAQ,cAAc,UAAU;EAC9C;CACF,CAAC;CACD,MAAM,OAAO,QAAQ;EACnB,QAAQ,MAAM;EACd,cAAc,MAAM;EACpB,UAAU,QAAQ;EAClB,YAAY,QAAQ;CACtB,CAAC;CACD,MAAM,aAAa,cAAc,MAAM,MAAM,UAAU;CAEvD,MAAM,EAAE,YAAY;CACpB,gBAAgB;EAEd,KAAK,MAAM,EAAE,MAAM,WAAW,SAAS,SAAS,MAAM;GAAE;GAAM;EAAM,CAAU;CAChF,GAAG,CAAC,MAAM,OAAO,CAAC;CAClB,MAAM,QAAQ,iBAAiB,MAAM,MAAM,QAAQ,SAAS,UAAU;CACtE,MAAM,EAAE,YAAY,qBAAqB;CACzC,OAAO,eACE;EACL;EACA,YAAY,MAAM;EAClB,SAAS,MAAM;EACf;EACA;EACA,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd;EACA;CACF,IACA;EAAC;EAAM;EAAO;EAAY;EAAkB;EAAO;CAAU,CAC/D;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Display","Group"],"sources":["../src/formisch-internals.ts","../src/json-form-steps.ts","../src/array-field.tsx","../src/value-field.tsx","../src/render-fields.tsx","../src/json-field.tsx","../src/render-layout.tsx","../src/json-fields.tsx","../src/use-visibility.ts","../src/use-json-form.ts"],"sourcesContent":["// The parts of Formisch the adapter reads that Formisch keeps out of its public API, and so out of\n// semver: its store, and `@formisch/react/internals`. tests/formisch-internals.test.tsx fails if a\n// Formisch release moves them.\nimport type { FormStore } from '@formisch/react'\nimport {\n getFieldInput,\n INTERNAL,\n type Listener,\n setListener,\n untrack,\n} from '@formisch/react/internals'\n\n/** The `<form>` Formisch's `<Form>` renders, which it keeps on the store for its `submit()`. */\nexport function formElementOf(form: FormStore): HTMLFormElement | undefined {\n return (form as unknown as { '~internal'?: { element?: HTMLFormElement } })['~internal']?.element\n}\n\n/** The form's input, read without subscribing the component that may be rendering now. */\nexport const readInput = (form: FormStore): unknown => untrack(() => getFieldInput(form[INTERNAL]))\n\n/**\n * Calls `onChange` after each change of the form's input, until the function it returns is called.\n * It reads the input as Formisch's own components do, with a listener: a signal that changes calls\n * it once, so it reads the input again each time, the items of new array items too.\n */\nexport function watchInput(form: FormStore, onChange: () => void): () => void {\n const listener: Listener = [\n () => {\n read()\n onChange()\n },\n new Set(),\n ]\n const stop = () => {\n for (const subscribers of listener[1]) subscribers.delete(listener)\n listener[1].clear()\n }\n function read() {\n stop()\n // untrack() sets back the listener of a component that may be rendering now.\n untrack(() => {\n setListener(listener)\n try {\n getFieldInput(form[INTERNAL])\n } finally {\n setListener(undefined)\n }\n })\n }\n read()\n return stop\n}\n","import {\n focus,\n type FormStore,\n getErrors,\n getInput,\n setErrors,\n validate,\n type ValidationMode,\n} from '@formisch/react'\nimport {\n type FieldPath,\n fieldPathsOfStep,\n type FormLayout,\n issuesOfStep,\n type LayoutStep,\n type StepIssue,\n type VisibilityState,\n} from '@whatsaaaa/form-builder-schema'\nimport { useEffect, useMemo, useRef, useState } from 'react'\nimport { formElementOf } from './formisch-internals'\n\n/** The steps of a form, from its layout. A form without `steps` in its layout has one. */\nexport interface JsonFormSteps {\n /**\n * The steps on show, in order. A step whose fields are all hidden by conditions, or that is\n * hidden itself, is left out, unless it is the current one: Next and Back skip it.\n */\n readonly list: readonly LayoutStep[]\n /** The index of the current step in `list`. */\n readonly index: number\n /** The step `<JsonFields>` renders. */\n readonly current: LayoutStep\n readonly isFirst: boolean\n readonly isLast: boolean\n /**\n * Validates the whole form, and moves to the next step when the fields of this one have no\n * issues. Otherwise it stays, and focuses the first field with an issue, in layout order.\n * Resolves to whether it moved.\n */\n next(): Promise<boolean>\n /** Moves to the step before, without validating. */\n back(): void\n /**\n * Moves to the step at `index`. Back is free, and forward validates every step on the way, like\n * `next()`, and stops at the first with issues. Resolves to whether it got there.\n */\n goTo(index: number): Promise<boolean>\n}\n\n/** A field's error messages in Formisch, or null. */\ntype Errors = [string, ...string[]] | null\n\n/** What a field tells the steps it was through, by Formisch's name for the validation mode. */\nexport type FieldEvent = Exclude<ValidationMode, 'initial' | 'submit'>\n\n/** Revalidates a step that failed Next on each field event, like a form after a failed submit. */\ntype FieldEvents = (event: FieldEvent) => void\n\nconst fieldEvents = new WeakMap<FormStore, FieldEvents>()\n\n/** What a field of `form` calls on each event, for a form with steps. Undefined with one step. */\nexport const fieldEventsOf = (form: FormStore): FieldEvents | undefined => fieldEvents.get(form)\n\ninterface Modes {\n validate?: ValidationMode | undefined\n revalidate?: Exclude<ValidationMode, 'initial'> | undefined\n}\n\n/**\n * The steps of `layout`, for `useJsonForm`. With more than one, a step shows the errors it had\n * when the user left it, and none the first time they get to it, a step that failed Next\n * revalidates as the user fixes it, a submit before the last step moves on like Next, and a submit\n * that fails because of an earlier step goes back to it. The steps `visibility` hides are skipped.\n * Like Formisch's `useForm`, it reads the validation modes on the first render.\n */\nexport function useJsonFormSteps(\n form: FormStore,\n layout: FormLayout,\n modes: Modes,\n visibility: VisibilityState,\n): JsonFormSteps {\n const all = layout.steps\n // The current step, by its index in `all`, as are the steps in `state` below.\n const [index, setIndex] = useState(0)\n // What the async methods and the event handlers read: always the latest.\n const state = useRef({\n index: 0,\n // The errors each step had when the user left it, by the JSON of each field's path.\n left: new Map<number, Map<string, Errors>>(),\n // The steps that failed Next, and haven't passed since.\n failed: new Set<number>(),\n // The field to focus once the step it is on has rendered.\n focus: undefined as FieldPath | undefined,\n // Whether a submit on the last step is on its way through Formisch.\n submitting: false,\n modes,\n })\n\n const methods = useMemo(() => {\n const at = state.current\n // The current step stays on show, so it never goes from under the user.\n const shown = () => all.filter((step, i) => i === at.index || !visibility.isStepHidden(step))\n const position = (list: readonly LayoutStep[]) => list.indexOf(all[at.index] as LayoutStep)\n\n async function goTo(target: number): Promise<boolean> {\n const list = shown()\n if (!Number.isInteger(target) || target < 0 || target >= list.length) {\n throw new RangeError(`No step ${target}. The form has ${list.length}.`)\n }\n const to = all.indexOf(list[target] as LayoutStep)\n if (target <= position(list)) {\n move(to)\n return true\n }\n // Next goes on once the task that called it is over. A click runs its default action after its\n // handlers, and React can render in between: a Next button that turns into the submit button on\n // the last step would then submit the form as the user gets there.\n await afterTask()\n const { issues } = await validate(form)\n for (const step of list.slice(position(list), target)) {\n const found = issuesOfStep(step, issues)\n if (found.length) {\n stop(all.indexOf(step), found)\n return false\n }\n at.failed.delete(all.indexOf(step))\n }\n move(to)\n return true\n }\n\n /**\n * Moves to a step as the user left it: with the errors it had then, and none the first time, and\n * revalidating if it failed Next. Validating the steps before set errors on its fields, which\n * the user never saw.\n */\n function move(target: number) {\n leave()\n const errors = at.left.get(target)\n for (const path of fieldPathsOfStep(all[target] as LayoutStep, getInput(form))) {\n setErrors(form, { path, errors: errors?.get(JSON.stringify(path)) ?? null } as never)\n }\n at.index = target\n setIndex(target)\n }\n\n /** Keeps the errors of the current step, for when the user comes back to it. */\n function leave() {\n const paths = fieldPathsOfStep(all[at.index] as LayoutStep, getInput(form))\n const errors = paths.map((path): [string, Errors] => [\n JSON.stringify(path),\n getErrors(form, { path } as never),\n ])\n at.left.set(at.index, new Map(errors))\n }\n\n /** Stays on, or goes to, the step at `target`, with its issues shown. */\n function stop(target: number, found: readonly StepIssue[]) {\n at.failed.add(target)\n // A group or an array has no element: the first field that has one gets the focus.\n const path = found.find((issue) => issue.field.role === 'value')?.path\n if (target === at.index) {\n if (path) focus(form, { path: path as never })\n return\n }\n leave()\n at.focus = path\n at.index = target\n setIndex(target)\n }\n\n const events: FieldEvents = (event) => {\n // In the other modes, Formisch revalidates a field with errors itself.\n const validateMode = at.modes.validate ?? 'submit'\n if (!at.failed.has(at.index) || validateMode !== 'submit' || form.isSubmitted) return\n if (event === (at.modes.revalidate ?? 'input')) void validate(form)\n }\n\n /** After a failed submit: back to the first step before this one with issues, if any. */\n async function afterSubmit() {\n const { issues } = await validate(form)\n const list = shown()\n const step = list.find((each) => issuesOfStep(each, issues).length)\n if (step && list.indexOf(step) < position(list)) {\n stop(all.indexOf(step), issuesOfStep(step, issues))\n }\n }\n\n const isLast = () => {\n const list = shown()\n return position(list) === list.length - 1\n }\n const next = () => (isLast() ? Promise.resolve(false) : goTo(position(shown()) + 1))\n const back = () => {\n const list = shown()\n const before = list[position(list) - 1]\n if (before) move(all.indexOf(before))\n }\n return { goTo, next, back, isLast, events, afterSubmit }\n }, [form, all, visibility])\n\n // The field a step was stopped on, once the step has rendered.\n useEffect(() => {\n const path = state.current.focus\n state.current.focus = undefined\n if (path) focus(form, { path: path as never })\n }, [form, index])\n\n const stepped = all.length > 1\n useEffect(() => {\n if (!stepped) return\n fieldEvents.set(form, methods.events)\n // Before the last step, a submit, like Enter in a step with a single text input, is a Next.\n // It is caught on its way down to the form, before Formisch's own handler sees it.\n const onSubmit = (event: Event) => {\n if (event.target !== formElementOf(form)) return\n if (methods.isLast()) {\n state.current.submitting = true\n return\n }\n event.preventDefault()\n event.stopImmediatePropagation()\n void methods.next()\n }\n document.addEventListener('submit', onSubmit, { capture: true })\n return () => {\n fieldEvents.delete(form)\n document.removeEventListener('submit', onSubmit, { capture: true })\n }\n }, [form, methods, stepped])\n\n // A submit that fails because of a step before the last, e.g. on a form rule, goes back to it.\n // React can batch the start and the end of a submit into one render, so the submit is marked\n // as it starts, and each render checks whether Formisch has finished it.\n const submitting = form.isSubmitting\n useEffect(() => {\n if (!state.current.submitting || submitting) return\n state.current.submitting = false\n if (!form.isValid) void methods.afterSubmit()\n })\n\n return useMemo(() => {\n const list = all.filter((step, i) => i === index || !visibility.isStepHidden(step))\n const current = all[index] as LayoutStep\n const at = list.indexOf(current)\n return {\n list,\n index: at,\n current,\n isFirst: at === 0,\n isLast: at === list.length - 1,\n next: methods.next,\n back: methods.back,\n goTo: methods.goTo,\n }\n }, [all, index, visibility, methods])\n}\n\n/** Resolves once the task that called it is over, and the browser is done with its event. */\nconst afterTask = () => new Promise<void>((resolve) => setTimeout(resolve))\n","import { insert, move, remove, useFieldArray } from '@formisch/react'\nimport type { FieldNode, FieldPath } from '@whatsaaaa/form-builder-schema'\nimport { type ComponentType, type ReactElement, type ReactNode, useMemo } from 'react'\nimport type { ArrayFieldProps } from './field-components'\nimport { fieldEventsOf } from './json-form-steps'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\ninterface ArrayFieldConnectionProps {\n of: AnyJsonFormInstance\n node: FieldNode\n path: FieldPath\n component: ComponentType<ArrayFieldProps>\n /** Renders the fields of the item at `index`. */\n renderItem: (index: number) => ReactNode\n}\n\n/** Connects a container of kind `array` to Formisch, and renders your component for it. */\nexport function ArrayField({\n of,\n node,\n path,\n component: Component,\n renderItem,\n}: ArrayFieldConnectionProps): ReactElement {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const array = useFieldArray(of.form, { path: path as never })\n\n // Formisch keeps the path it got while the array is the same, so the methods stay the same too.\n const { form, builder } = of\n const { field } = node\n const at = array.path\n // In a form with steps, a step that failed Next revalidates on a change of its items too.\n const methods = useMemo(\n () => ({\n // A new item starts with the defaults of its fields, like the items of a new form.\n add: () => {\n insert(form, { path: at, initialInput: builder.getItemInput(field) as never })\n fieldEventsOf(form)?.('input')\n },\n remove: (index: number) => {\n remove(form, { path: at, at: index })\n fieldEventsOf(form)?.('input')\n },\n move: (from: number, to: number) => {\n move(form, { path: at, from, to })\n fieldEventsOf(form)?.('input')\n },\n }),\n [form, builder, field, at],\n )\n\n return (\n <Component field={field} path={path} items={array.items} errors={array.errors} {...methods}>\n {renderItem}\n </Component>\n )\n}\n","import { useField } from '@formisch/react'\nimport {\n coerceInput,\n type FieldNode,\n type FieldPath,\n isRequired,\n} from '@whatsaaaa/form-builder-schema'\nimport { type ComponentType, type ReactElement, useCallback } from 'react'\nimport type { ValueFieldProps } from './field-components'\nimport { fieldEventsOf } from './json-form-steps'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\ninterface ValueFieldConnectionProps {\n of: AnyJsonFormInstance\n node: FieldNode\n path: FieldPath\n component: ComponentType<ValueFieldProps>\n}\n\n/** Connects a field with a value to Formisch, and renders your component for it. */\nexport function ValueField({\n of,\n node,\n path,\n component: Component,\n}: ValueFieldConnectionProps): ReactElement {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const field = useField(of.form, { path: path as never })\n const { form } = of\n const setInput = useCallback(\n (input: unknown) => {\n field.onChange(coerceInput(input, node) as never)\n fieldEventsOf(form)?.('input')\n },\n [field, node, form],\n )\n // In a form with steps, a step that failed Next revalidates on these events too.\n const inputProps =\n of.steps.list.length > 1\n ? {\n ...field.props,\n onFocus: () => {\n field.props.onFocus()\n fieldEventsOf(form)?.('touch')\n },\n onChange: (event: Parameters<typeof field.props.onChange>[0]) => {\n field.props.onChange(event)\n fieldEventsOf(form)?.('input')\n fieldEventsOf(form)?.('change')\n },\n onBlur: () => {\n field.props.onBlur()\n fieldEventsOf(form)?.('blur')\n },\n }\n : field.props\n\n return (\n <Component\n field={node.field}\n path={path}\n kind={node.kind}\n required={isRequired(node.field)}\n input={field.input}\n errors={field.errors}\n inputProps={inputProps}\n setInput={setInput}\n />\n )\n}\n","import { dotPathOf, type FieldNode, toFieldPath } from '@whatsaaaa/form-builder-schema'\nimport type { ComponentType, ReactElement, ReactNode } from 'react'\nimport { ArrayField } from './array-field'\nimport type {\n ArrayFieldProps,\n DisplayFieldProps,\n FieldComponents,\n GroupFieldProps,\n ValueFieldProps,\n} from './field-components'\nimport type { AnyJsonFormInstance } from './use-json-form'\nimport { ValueField } from './value-field'\n\n/** What `<JsonFields>` and `<JsonField>` render with. */\nexport interface RenderContext {\n of: AnyJsonFormInstance\n components: FieldComponents\n}\n\n/** The components from the props, or else the ones `useJsonForm` got. */\nexport function resolveComponents(\n components: FieldComponents | undefined,\n of: AnyJsonFormInstance,\n): FieldComponents {\n const resolved = components ?? of.components\n if (!resolved) {\n throw new TypeError('No field components. Pass them to useJsonForm, or to the component.')\n }\n return resolved\n}\n\n/**\n * Renders the fields that conditions don't hide. `indexes` are the indexes of the array items the\n * fields are in, outermost first.\n */\nexport function renderFields(\n ctx: RenderContext,\n nodes: readonly FieldNode[],\n indexes: readonly number[],\n): ReactElement[] {\n const { visibility } = ctx.of\n // A display element is keyed by its position among all the nodes, which stays the same.\n return nodes.flatMap((node, position) =>\n visibility.isHidden(node, indexes)\n ? []\n : [\n renderField(ctx, node, indexes, dotPathOf(node) ?? `#${position}`, (inner) =>\n renderFields(ctx, node.children, inner),\n ),\n ],\n )\n}\n\n/**\n * Renders one field with its component. `children` renders the fields inside a group, or inside\n * the item of an array, with the indexes of the items they are in.\n */\nexport function renderField(\n ctx: RenderContext,\n node: FieldNode,\n indexes: readonly number[],\n key: string,\n children: (indexes: readonly number[]) => ReactNode,\n): ReactElement {\n // The fields were checked for components, and the role tells which props the component takes.\n const component = ctx.components[node.type]\n const path = toFieldPath(node.dataPath, indexes)\n switch (node.role) {\n case 'display': {\n const Display = component as ComponentType<DisplayFieldProps>\n return <Display key={key} field={node.field} />\n }\n case 'group': {\n const Group = component as ComponentType<GroupFieldProps>\n return (\n <Group key={key} field={node.field} path={path}>\n {children(indexes)}\n </Group>\n )\n }\n case 'array':\n return (\n <ArrayField\n key={key}\n of={ctx.of}\n node={node}\n path={path}\n component={component as ComponentType<ArrayFieldProps>}\n renderItem={(index) => children([...indexes, index])}\n />\n )\n case 'value':\n return (\n <ValueField\n key={key}\n of={ctx.of}\n node={node}\n path={path}\n component={component as ComponentType<ValueFieldProps>}\n />\n )\n }\n}\n","import { checkComponents, dotPathOf, findField } from '@whatsaaaa/form-builder-schema'\nimport type { ReactElement } from 'react'\nimport type { FieldComponents } from './field-components'\nimport { type RenderContext, renderField, renderFields, resolveComponents } from './render-fields'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\nexport interface JsonFieldProps {\n /** What `useJsonForm` returned. */\n of: AnyJsonFormInstance\n /** The field's path: `'email'`, or `'address.city'` for a field of a group. */\n path: string\n /** Defaults to the components `useJsonForm` got. */\n components?: FieldComponents | undefined\n}\n\n/**\n * Renders one field of a `useJsonForm` form, wherever you put it inside Formisch's `<Form>`. A\n * group or an array comes with its fields. Leave the field out of `<JsonFields>` with `except`.\n * It renders nothing while conditions hide the field.\n */\nexport function JsonField({ of, path, components }: JsonFieldProps): ReactElement | null {\n const node = findField(of.fields, path, { placed: true })\n const ctx: RenderContext = { of, components: resolveComponents(components, of) }\n checkComponents([node], ctx.components)\n\n if (of.visibility.isHidden(node, [])) return null\n return renderField(ctx, node, [], dotPathOf(node) ?? '#0', (indexes) =>\n renderFields(ctx, node.children, indexes),\n )\n}\n","import type { IsFieldShown, LayoutNode } from '@whatsaaaa/form-builder-schema'\nimport { type ComponentType, Fragment, type ReactElement, type ReactNode } from 'react'\nimport type { LayoutComponents, RowProps, SectionProps } from './field-components'\nimport { type RenderContext, renderField } from './render-fields'\n\n/** What `<JsonFields>` renders a layout with. */\nexport interface LayoutContext extends RenderContext {\n layoutComponents: LayoutComponents\n /** The content of the layout's slots, by name. */\n slots: Readonly<Record<string, ReactNode>>\n /** False for a field left out with `except`. */\n isShown: IsFieldShown\n}\n\n/**\n * Renders layout nodes. A field left out or hidden by conditions drops out, and so does a section\n * hidden by them, and a section or a row left without fields. `indexes` are the indexes of the\n * array items the nodes are in, outermost first.\n */\nexport function renderLayout(\n ctx: LayoutContext,\n nodes: readonly LayoutNode[],\n indexes: readonly number[],\n): ReactElement[] {\n return ctx.of.visibility\n .shownNodes(nodes, indexes, ctx.isShown)\n .map((node) => renderNode(ctx, node, indexes))\n}\n\nfunction renderNode(\n ctx: LayoutContext,\n node: LayoutNode,\n indexes: readonly number[],\n): ReactElement {\n const { key } = node\n switch (node.type) {\n case 'field':\n return renderField(ctx, node.node, indexes, key, (inner) =>\n renderLayout(ctx, node.children, inner),\n )\n case 'section': {\n // The layout was checked for components.\n const Section = ctx.layoutComponents.section as ComponentType<SectionProps>\n return (\n <Section key={key} section={node.section}>\n {renderLayout(ctx, node.children, indexes)}\n </Section>\n )\n }\n case 'row': {\n const Row = ctx.layoutComponents.row as ComponentType<RowProps>\n return (\n <Row key={key} row={node.row} spans={node.children.map((cell) => cell.span)}>\n {(index) => renderNode(ctx, node.children[index] as LayoutNode, indexes)}\n </Row>\n )\n }\n case 'slot':\n return <Fragment key={key}>{ctx.slots[node.name]}</Fragment>\n }\n}\n","import {\n checkComponents,\n checkLayoutComponents,\n dotPathOf,\n type FieldNode,\n type LayoutNode,\n selectFields,\n} from '@whatsaaaa/form-builder-schema'\nimport { Fragment, type ReactElement, type ReactNode } from 'react'\nimport type { FieldComponents, LayoutComponents } from './field-components'\nimport { type LayoutContext, renderLayout } from './render-layout'\nimport { type RenderContext, renderFields, resolveComponents } from './render-fields'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\nexport interface JsonFieldsProps {\n /** What `useJsonForm` returned. */\n of: AnyJsonFormInstance\n /** Defaults to the components `useJsonForm` got. */\n components?: FieldComponents | undefined\n /** Defaults to the layout components `useJsonForm` got. */\n layoutComponents?: LayoutComponents | undefined\n /** The content of the layout's slots, by name: `{ submit: <button type=\"submit\">Save</button> }`. */\n slots?: Readonly<Record<string, ReactNode>> | undefined\n /** Renders only these fields, by path, in the order of the definition, without the layout. */\n only?: readonly string[] | undefined\n /**\n * Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. A section or a\n * row left without fields drops out too.\n */\n except?: readonly string[] | undefined\n /** Renders the step at this index instead of the current one, e.g. on a review page. */\n step?: number | undefined\n}\n\n/**\n * Renders the fields of a `useJsonForm` form with your components, one per field type, where the\n * definition's `layout` puts them: the current step, with its sections, rows and slots. It renders\n * nothing of its own, so put it inside Formisch's `<Form>` with your own submit button.\n */\nexport function JsonFields(props: JsonFieldsProps): ReactElement {\n const { of, only, except } = props\n const ctx: RenderContext = { of, components: resolveComponents(props.components, of) }\n const nodes = selectFields(of.fields, { only, except })\n // Without a layout, it renders the fields the way it always did, and so with `only`.\n if (only || !of.definition.layout) {\n checkComponents(nodes, ctx.components)\n return <>{renderFields(ctx, nodes, [])}</>\n }\n\n const { layout, steps } = of\n const left = new Set(except)\n const layoutCtx: LayoutContext = {\n ...ctx,\n layoutComponents: props.layoutComponents ?? of.layoutComponents ?? {},\n slots: props.slots ?? {},\n isShown: (node) => !left.has(dotPathOf(node) ?? ''),\n }\n checkComponents(\n layout.steps.flatMap((step) => fieldsOf(step.children)),\n ctx.components,\n )\n checkLayoutComponents(layout, layoutCtx.layoutComponents, layoutCtx.slots)\n\n const index = props.step ?? steps.index\n const step = steps.list[index]\n if (!step) throw new RangeError(`No step ${props.step}. The form has ${steps.list.length}.`)\n // Keyed by the step, so another step's fields don't take over this one's components.\n return <Fragment key={index}>{renderLayout(layoutCtx, step.children, [])}</Fragment>\n}\n\n/** Every field of the nodes, display elements written in the layout included. */\nfunction fieldsOf(nodes: readonly LayoutNode[]): FieldNode[] {\n return nodes.flatMap((node) => {\n if (node.type === 'slot') return []\n const inner = fieldsOf(node.children)\n return node.type === 'field' ? [node.node, ...inner] : inner\n })\n}\n","import type { FormStore } from '@formisch/react'\nimport type { Visibility, VisibilityState } from '@whatsaaaa/form-builder-schema'\nimport { useCallback, useSyncExternalStore } from 'react'\nimport { readInput, watchInput } from './formisch-internals'\n\n/**\n * What the conditions of the definition hide for the form's input, as it changes. Formisch\n * re-renders a component for each signal it reads, so reading the whole input in `useJsonForm`\n * would re-render the form on every keystroke. This watches the input outside React instead, and\n * re-renders only when the state changes: `of()` gives the same object until then. Without\n * conditions, it watches nothing.\n */\nexport function useVisibility(form: FormStore, visibility: Visibility): VisibilityState {\n const subscribe = useCallback(\n (onChange: () => void) => (visibility.conditional ? watchInput(form, onChange) : () => {}),\n [form, visibility],\n )\n const getSnapshot = () => visibility.of(visibility.conditional ? readInput(form) : undefined)\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n}\n","import {\n type FormSchema,\n type FormStore,\n setInput,\n useForm,\n type ValidationMode,\n} from '@formisch/react'\nimport {\n createSchemaBuilder,\n type FieldNode,\n type FormLayout,\n type JsonForm,\n type BuiltSchema,\n type SchemaBuilder,\n type TypedBuiltSchema,\n type VisibilityState,\n} from '@whatsaaaa/form-builder-schema'\nimport { useEffect, useMemo, useState } from 'react'\nimport type { FieldComponents, LayoutComponents } from './field-components'\nimport { type JsonFormSteps, useJsonFormSteps } from './json-form-steps'\nimport { useVisibility } from './use-visibility'\n\nexport interface UseJsonFormOptions {\n /** Builds the schema and knows your own types and rules. Defaults to `createSchemaBuilder()`. */\n builder?: SchemaBuilder\n /** Your component for each field type, so `<JsonFields>` and `<JsonField>` don't need them. */\n components?: FieldComponents\n /** Your component for each layout type the definition's `layout` uses, like `section`. */\n layoutComponents?: LayoutComponents\n /** When a field is validated the first time, as in Formisch. */\n validate?: ValidationMode\n /** When a field is validated again after that, as in Formisch. */\n revalidate?: Exclude<ValidationMode, 'initial'>\n}\n\n/** What `useJsonForm` returns. Pass it to `<JsonFields>`. */\nexport interface JsonFormInstance<TSchema extends FormSchema = BuiltSchema> {\n /** The Formisch form: pass it to Formisch's `<Form of>`, or to any of its methods. */\n readonly form: FormStore<TSchema>\n readonly definition: JsonForm\n readonly builder: SchemaBuilder\n /** The components from the options, if any. */\n readonly components: FieldComponents | undefined\n /** The layout components from the options, if any. */\n readonly layoutComponents: LayoutComponents | undefined\n /** The definition's fields as a tree, for `<JsonFields only>` and `<JsonField>`. */\n readonly fields: readonly FieldNode[]\n /** The definition's layout, the way `<JsonFields>` renders it. */\n readonly layout: FormLayout\n /** The layout's steps: the current one, and Next, Back and Go to. A form without steps has one. */\n readonly steps: JsonFormSteps\n /**\n * What the conditions of the builder's extensions hide for the form's input now, like the\n * `affects` of `@whatsaaaa/form-builder-affects`: `<JsonFields>` and `<JsonField>` leave it out.\n * Read it in your own renderers. A new object only when what is hidden changes, so the form\n * re-renders for that, not for every keystroke. Without conditions, it hides nothing.\n */\n readonly visibility: VisibilityState\n}\n\n/** Any form `useJsonForm` returns, typed or not: what the components take. */\nexport type AnyJsonFormInstance = JsonFormInstance<FormSchema>\n\n/**\n * A Formisch form for a definition, with its schema and initial input from the builder. A\n * definition with issues throws the builder's `DefinitionError`, so run `validate()` first when it\n * comes from outside your code. Like Formisch's `useForm`, it reads the definition, the builder and\n * the validation modes on the first render: give the component a new `key` to use another\n * definition. The components and layout components are read on every render. With conditions, it\n * clears the fields they clear as soon as they do, with Formisch's `setInput`, wherever the fields\n * are rendered.\n */\nexport function useJsonForm(definition: JsonForm, options?: UseJsonFormOptions): JsonFormInstance\n/**\n * The same, with the form typed by your input type, and output type when it differs, so Formisch's\n * paths and values are checked. The types are yours to keep in step with the definition.\n */\nexport function useJsonForm<TInput extends object, TOutput extends object = TInput>(\n definition: JsonForm,\n options?: UseJsonFormOptions,\n): JsonFormInstance<TypedBuiltSchema<TInput, TOutput>>\nexport function useJsonForm(\n definition: JsonForm,\n options: UseJsonFormOptions = {},\n): JsonFormInstance {\n // Formisch reads its config on the first render only, so the schema is built once too.\n const [built] = useState(() => {\n const builder = options.builder ?? createSchemaBuilder()\n return {\n definition,\n builder,\n schema: builder.build(definition),\n initialInput: builder.getInitialInput(definition),\n fields: builder.getFieldTree(definition),\n layout: builder.getLayout(definition),\n visibility: builder.getVisibility(definition),\n }\n })\n const form = useForm({\n schema: built.schema,\n initialInput: built.initialInput,\n validate: options.validate,\n revalidate: options.revalidate,\n })\n const visibility = useVisibility(form, built.visibility)\n // A new state means something to clear may have come. It is empty once the fields are blank.\n const { toClear } = visibility\n useEffect(() => {\n // The paths come from the definition at runtime, so the schema's types can't check them.\n for (const { path, input } of toClear) setInput(form, { path, input } as never)\n }, [form, toClear])\n const steps = useJsonFormSteps(form, built.layout, options, visibility)\n const { components, layoutComponents } = options\n return useMemo(\n () => ({\n form,\n definition: built.definition,\n builder: built.builder,\n components,\n layoutComponents,\n fields: built.fields,\n layout: built.layout,\n steps,\n visibility,\n }),\n [form, built, components, layoutComponents, steps, visibility],\n )\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,cAAc,MAA8C;CAC1E,OAAQ,KAAoE,YAAY,EAAE;AAC5F;;AAGA,MAAa,aAAa,SAA6B,cAAc,cAAc,KAAK,SAAS,CAAC;;;;;;AAOlG,SAAgB,WAAW,MAAiB,UAAkC;CAC5E,MAAM,WAAqB,OACnB;EACJ,KAAK;EACL,SAAS;CACX,mBACA,IAAI,IAAI,CACV;CACA,MAAM,aAAa;EACjB,KAAK,MAAM,eAAe,SAAS,IAAI,YAAY,OAAO,QAAQ;EAClE,SAAS,EAAE,CAAC,MAAM;CACpB;CACA,SAAS,OAAO;EACd,KAAK;EAEL,cAAc;GACZ,YAAY,QAAQ;GACpB,IAAI;IACF,cAAc,KAAK,SAAS;GAC9B,UAAU;IACR,YAAY,KAAA,CAAS;GACvB;EACF,CAAC;CACH;CACA,KAAK;CACL,OAAO;AACT;;ACOA,MAAM,8BAAc,IAAI,QAAgC;;AAGxD,MAAa,iBAAiB,SAA6C,YAAY,IAAI,IAAI;;;;;;;;AAc/F,SAAgB,iBACd,MACA,QACA,OACA,YACe;CACf,MAAM,MAAM,OAAO;CAEnB,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CAEpC,MAAM,QAAQ,OAAO;EACnB,OAAO;EAEP,sBAAM,IAAI,IAAiC;EAE3C,wBAAQ,IAAI,IAAY;EAExB,OAAO,KAAA;EAEP,YAAY;EACZ;CACF,CAAC;CAED,MAAM,UAAU,cAAc;EAC5B,MAAM,KAAK,MAAM;EAEjB,MAAM,cAAc,IAAI,QAAQ,MAAM,MAAM,MAAM,G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C/D;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whatsaaaa/form-builder-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Render JSON form definitions with Formisch and your own React components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"form",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"json",
|
|
10
10
|
"react"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://github.
|
|
12
|
+
"homepage": "https://whatsaaaa.github.io/form-builder/frameworks/react",
|
|
13
13
|
"bugs": "https://github.com/whatsaaaa/form-builder/issues",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"author": "Whatsaaaa",
|
|
@@ -32,9 +32,6 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"@whatsaaaa/form-builder-schema": "^0.17.0"
|
|
37
|
-
},
|
|
38
35
|
"devDependencies": {
|
|
39
36
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
40
37
|
"@formisch/react": "^1.2.0",
|
|
@@ -42,7 +39,8 @@
|
|
|
42
39
|
"@types/react": "^19.3.0",
|
|
43
40
|
"@types/react-dom": "^19.3.0",
|
|
44
41
|
"@vitest/coverage-v8": "^5.0.5",
|
|
45
|
-
"@whatsaaaa/form-builder-affects": "^0.2.
|
|
42
|
+
"@whatsaaaa/form-builder-affects": "^0.2.1",
|
|
43
|
+
"@whatsaaaa/form-builder-schema": "^0.17.1",
|
|
46
44
|
"happy-dom": "^20.0.0",
|
|
47
45
|
"publint": "^0.3.25",
|
|
48
46
|
"react": "^19.3.1",
|
|
@@ -55,6 +53,7 @@
|
|
|
55
53
|
},
|
|
56
54
|
"peerDependencies": {
|
|
57
55
|
"@formisch/react": "^1.2.0",
|
|
56
|
+
"@whatsaaaa/form-builder-schema": "^0.17.1",
|
|
58
57
|
"react": "^18.0.0 || ^19.0.0",
|
|
59
58
|
"valibot": "^1.4.1"
|
|
60
59
|
},
|