@whatsaaaa/form-builder-vue 0.1.5 → 0.3.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.
package/README.md CHANGED
@@ -51,6 +51,7 @@ function save(output: unknown) {
51
51
  useJsonForm(definition, {
52
52
  builder: createSchemaBuilder({ fieldTypes: { money } }), // your own types, rules and messages
53
53
  components, // your component per field type, see below
54
+ layoutComponents, // your component per layout type, see Layout
54
55
  validate: 'blur', // when a field is validated the first time, as in Formisch
55
56
  revalidate: 'input', // when it is validated again
56
57
  })
@@ -194,9 +195,149 @@ defineProps<DisplayFieldProps>()
194
195
 
195
196
  Declare the props even when a component doesn't use them, like a divider, or Vue adds `field` to its element as an attribute.
196
197
 
198
+ ## Layout
199
+
200
+ A definition's [`layout`](https://github.com/whatsaaaa/form-builder/tree/main/packages/schema#layout) puts its fields in sections, rows of a 12-column grid and steps, and leaves slots for content of yours. `<JsonFields>` renders the current step of it. Give `useJsonForm` a component for each layout type the definition uses, and `<JsonFields>` a named slot for each of its slots:
201
+
202
+ ```vue
203
+ <!-- Row.vue: one line of a 12-column grid. On a narrow screen, give each cell the whole row. -->
204
+ <script setup lang="ts">
205
+ import type { RowProps, RowSlots } from '@whatsaaaa/form-builder-vue'
206
+
207
+ defineProps<RowProps>()
208
+ defineSlots<RowSlots>()
209
+ </script>
210
+
211
+ <template>
212
+ <div class="row">
213
+ <div v-for="(span, index) in spans" :key="index" :style="{ gridColumn: `span ${span}` }">
214
+ <slot :index="index" />
215
+ </div>
216
+ </div>
217
+ </template>
218
+
219
+ <style scoped>
220
+ .row {
221
+ display: grid;
222
+ grid-template-columns: repeat(12, 1fr);
223
+ gap: 1rem;
224
+ }
225
+ </style>
226
+ ```
227
+
228
+ ```vue
229
+ <!-- Section.vue -->
230
+ <script setup lang="ts">
231
+ import type { SectionProps, SectionSlots } from '@whatsaaaa/form-builder-vue'
232
+
233
+ defineProps<SectionProps>()
234
+ defineSlots<SectionSlots>()
235
+ </script>
236
+
237
+ <template>
238
+ <fieldset>
239
+ <legend>{{ section.label }}</legend>
240
+ <slot />
241
+ </fieldset>
242
+ </template>
243
+ ```
244
+
245
+ ```vue
246
+ <script setup lang="ts">
247
+ const jsonForm = useJsonForm(definition, {
248
+ components,
249
+ layoutComponents: { section: Section, row: Row },
250
+ })
251
+ </script>
252
+
253
+ <template>
254
+ <Form :of="jsonForm.form" @submit="save">
255
+ <JsonFields :of="jsonForm">
256
+ <template #submit><button type="submit">Place order</button></template>
257
+ </JsonFields>
258
+ </Form>
259
+ </template>
260
+ ```
261
+
262
+ | Layout type | Props | Slot |
263
+ | ----------- | ------------------------------------------------------------------------- | ---------------------------------------------- |
264
+ | `section` | `section`, as written, with its `id`, `label`, `description` and `ui` | default: the section's items |
265
+ | `row` | `row`, as written, with its `id` and `ui`; `spans`, the span of each cell | default, with `{ index }`: the cell at `index` |
266
+
267
+ The props are typed as `SectionProps` and `RowProps`, and the slots as `SectionSlots` and `RowSlots`.
268
+
269
+ - `layoutComponents` goes to `useJsonForm`, or to `<JsonFields>` as a prop, which wins. A definition without sections or rows needs none, and one without a `layout` renders as it always did.
270
+ - A layout type the layout uses without a component, or a slot without content, throws a `TypeError` naming each one when `<JsonFields>` sets up, on every step.
271
+ - Display elements written in the layout render with your field components, like the ones in `fields`.
272
+ - `except` leaves fields out of the layout too, and a section or a row left without fields drops out. The other cells of a row keep their spans. `only` renders the fields it names without the layout.
273
+ - The spans are for a wide screen: the layout says nothing about narrow ones, so your row component decides, e.g. with a media query.
274
+
275
+ ### Steps
276
+
277
+ `jsonForm.steps` is where the form is, and how to move. It is reactive, so templates follow it:
278
+
279
+ ```vue
280
+ <template>
281
+ <Form :of="jsonForm.form" @submit="save">
282
+ <ol>
283
+ <li
284
+ v-for="(step, i) in jsonForm.steps.list"
285
+ :key="step.step.id ?? i"
286
+ :aria-current="i === jsonForm.steps.index ? 'step' : undefined"
287
+ >
288
+ {{ step.step.label }}
289
+ </li>
290
+ </ol>
291
+ <JsonFields :of="jsonForm" />
292
+ <button v-if="!jsonForm.steps.isFirst" type="button" @click="jsonForm.steps.back()">
293
+ Back
294
+ </button>
295
+ <button v-if="!jsonForm.steps.isLast" type="button" @click="jsonForm.steps.next()">Next</button>
296
+ <button v-else type="submit">Sign up</button>
297
+ </Form>
298
+ </template>
299
+ ```
300
+
301
+ | Member | |
302
+ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
303
+ | `list` | the steps on show, each with its `step` as written (`id`, `label`, `description`, `ui`), `children` and `fields`: a step that [conditions](#conditions) hide is left out, unless the user is on it |
304
+ | `index`, `current` | the step `<JsonFields>` renders |
305
+ | `isFirst`, `isLast` | |
306
+ | `next()` | validates, and moves on when the step's fields have no issues. Resolves to whether it moved |
307
+ | `back()` | moves back, without validating |
308
+ | `goTo(index)` | back freely; forward through each step on the way, stopping at the first with issues |
309
+
310
+ The form is one Formisch form, so Formisch validates all of it at once. The steps make that work:
311
+
312
+ - **Next** validates the whole form, and only the issues on the current step's fields keep the user there. It focuses the first one, in layout order.
313
+ - **A step shows what the user left**: the errors it had when they left it, and none the first time they get to it, so the issues of steps nobody saw yet stay out of sight.
314
+ - **A step that failed Next revalidates** as the user fixes it, on the `revalidate` event, like a form after a failed submit.
315
+ - **A submit before the last step is a Next**, so Enter in a step with a single text input doesn't submit the form early. On the last step, Formisch submits as usual.
316
+ - **A submit that fails because of an earlier step**, like a form rule that reads fields of two steps, goes back to that step.
317
+ - `<JsonFields :step="2" />` renders a given step instead of the current one, e.g. on a review page. A form without steps has one, and nothing changes for it.
318
+
319
+ ## Conditions
320
+
321
+ With the [affects package](https://github.com/whatsaaaa/form-builder/tree/main/packages/affects), fields, sections and steps show and hide by the values of other fields. Pass `useJsonForm` a builder with the extension:
322
+
323
+ ```ts
324
+ import { affects } from '@whatsaaaa/form-builder-affects'
325
+
326
+ const builder = createSchemaBuilder({ extensions: [affects()] })
327
+ const jsonForm = useJsonForm(definition, { builder, components, layoutComponents })
328
+ ```
329
+
330
+ - **`<JsonFields>` and `<JsonField>` leave out what the conditions hide**: a hidden field, a hidden section, and a group, section or row whose fields are all hidden. A field hidden in a row drops out of it, and the others keep their spans.
331
+ - **Steps skip the hidden ones.** `steps.list` holds the steps on show, so a step whose fields are all hidden is left out, and Next and Back go past it. The step the user is on stays, until they leave it.
332
+ - **`useJsonForm` clears what `hideAndClear` clears**, with Formisch's `setInput`, as soon as it is cleared, wherever the field renders: in `<JsonFields>`, with `<JsonField>`, or by your own code. A field that starts hidden this way starts blank.
333
+ - **The schema skips hidden fields**, so they never block the form, and submits what the affects package says.
334
+ - **`jsonForm.visibility`** is the state for the form's input now, for your own renderers: `isHidden(node, indexes)`, `isStepHidden(step)`, `shownNodes(nodes, indexes)`. It is a new object only when what is hidden changes.
335
+
336
+ Without conditions, nothing is hidden, and nothing changes.
337
+
197
338
  ## Placing fields yourself
198
339
 
199
- `<JsonFields>` renders every field in the order of the definition. To put some of them somewhere else, place them with `<JsonField>` and leave them out of `<JsonFields>` with `except`:
340
+ Without a `layout`, `<JsonFields>` renders every field in the order of the definition. To put some of them somewhere else, in code rather than in the definition, place them with `<JsonField>` and leave them out of `<JsonFields>` with `except`:
200
341
 
201
342
  ```vue
202
343
  <template>
@@ -215,7 +356,7 @@ Declare the props even when a component doesn't use them, like a divider, or Vue
215
356
 
216
357
  - A path is the field's names joined with dots: `'email'`, or `'address.city'` for a field of a group. A placed field validates, focuses and submits like any other, because it is still part of the one Formisch form.
217
358
  - A group or an array comes with all its fields. A field of an array's items can't be placed on its own, because it has no index outside its item, so place the array. To leave such a field out of every item, use `'*'` for the index: `except: ['lines.*.note']`.
218
- - `only` renders just the fields it names, in the order of the definition: `<JsonFields :of="jsonForm" :only="['name', 'email']" />`. Display elements have no name, so `only` leaves them out.
359
+ - `only` renders just the fields it names, in the order of the definition: `<JsonFields :of="jsonForm" :only="['name', 'email']" />`. Display elements have no dot path, even with a name, so `only` leaves them out.
219
360
  - A path that names no field throws a `TypeError`, so a typo shows up at once. `only` and `except` are read when the component sets up.
220
361
 
221
362
  ## Typing the form
@@ -245,4 +386,4 @@ useFieldArray(jsonForm.form, { path: ['lines'] })
245
386
 
246
387
  - Labels and display text reach your components as written in the definition. The builder's `resolveMessage` only changes what goes into the schema, so translate `field.label` in your components.
247
388
  - `ui.widget` doesn't pick a component. A component can read `field.ui` itself, e.g. to show a multiselect as checkboxes.
248
- - Showing and hiding fields, or making one required because of another, belongs to a future affects package.
389
+ - Showing and hiding fields, or making one required because of another, belongs to a future affects package. The layout already hides a section, a row or a step whose fields are all hidden, through `shownNodes` in the schema package.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FieldNode, FieldNode as FieldNode$1, FieldPath, FieldPath as FieldPath$1, FieldRole, JsonField as JsonField$1, JsonForm, JsonFormSchema, JsonFormSchema as JsonFormSchema$1, SchemaBuilder, TypedJsonFormSchema, TypedJsonFormSchema as TypedJsonFormSchema$1, ValueKind } from "@whatsaaaa/form-builder-schema";
1
+ import { FieldNode, FieldNode as FieldNode$1, FieldPath, FieldPath as FieldPath$1, FieldRole, FormLayout, FormLayout as FormLayout$1, JsonField as JsonField$1, JsonForm, JsonFormSchema, JsonFormSchema as JsonFormSchema$1, JsonLayoutRow, JsonLayoutSection, LayoutNode, LayoutStep, LayoutStep as LayoutStep$1, SchemaBuilder, TypedJsonFormSchema, TypedJsonFormSchema as TypedJsonFormSchema$1, ValueKind, VisibilityState, VisibilityState as VisibilityState$1 } from "@whatsaaaa/form-builder-schema";
2
2
  import { Component, PropType, VNode } from "vue";
3
3
  import { FieldElementProps, FormSchema, FormStore, ValidationMode } from "@formisch/vue";
4
4
  /** Your component for each field type, by type name: `{ text: TextInput, group: Fieldset }`. */
@@ -52,11 +52,70 @@ interface ArrayFieldSlots {
52
52
  index: number;
53
53
  }): VNode[];
54
54
  }
55
+ /**
56
+ * Your component for each layout type a definition's `layout` uses: `{ section: Card, row: Grid }`.
57
+ * A definition without sections or rows needs none.
58
+ */
59
+ interface LayoutComponents {
60
+ section?: Component;
61
+ row?: Component;
62
+ }
63
+ /** The props of a component for a section of the layout. */
64
+ interface SectionProps {
65
+ /** The section as written, with its `id`, `label`, `description` and `ui`. */
66
+ section: JsonLayoutSection;
67
+ }
68
+ /** The slots of a section component: its default slot renders the section's items. */
69
+ interface SectionSlots {
70
+ default(): VNode[];
71
+ }
72
+ /** The props of a component for a row of the layout: one line of a 12-column grid. */
73
+ interface RowProps {
74
+ /** The row as written, with its `id` and `ui`. */
75
+ row: JsonLayoutRow;
76
+ /** How many of the 12 columns each cell takes, in order. They add up to 12 at most. */
77
+ spans: number[];
78
+ }
79
+ /** The slots of a row component: its default slot renders the cell at `index`. */
80
+ interface RowSlots {
81
+ default(props: {
82
+ index: number;
83
+ }): VNode[];
84
+ }
85
+ /** The steps of a form, from its layout. A form without `steps` in its layout has one. */
86
+ interface JsonFormSteps {
87
+ /**
88
+ * The steps on show, in order. A step whose fields are all hidden by conditions, or that is
89
+ * hidden itself, is left out, unless it is the current one: Next and Back skip it.
90
+ */
91
+ readonly list: readonly LayoutStep$1[];
92
+ /** The index of the current step in `list`. */
93
+ readonly index: number;
94
+ /** The step `<JsonFields>` renders. */
95
+ readonly current: LayoutStep$1;
96
+ readonly isFirst: boolean;
97
+ readonly isLast: boolean;
98
+ /**
99
+ * Validates the whole form, and moves to the next step when the fields of this one have no
100
+ * issues. Otherwise it stays, and focuses the first field with an issue, in layout order.
101
+ * Resolves to whether it moved.
102
+ */
103
+ next(): Promise<boolean>;
104
+ /** Moves to the step before, without validating. */
105
+ back(): void;
106
+ /**
107
+ * Moves to the step at `index`. Back is free, and forward validates every step on the way, like
108
+ * `next()`, and stops at the first with issues. Resolves to whether it got there.
109
+ */
110
+ goTo(index: number): Promise<boolean>;
111
+ }
55
112
  interface UseJsonFormOptions {
56
113
  /** Builds the schema and knows your own types and rules. Defaults to `createSchemaBuilder()`. */
57
114
  builder?: SchemaBuilder;
58
115
  /** Your component for each field type, so `<JsonFields>` and `<JsonField>` don't need them. */
59
116
  components?: FieldComponents;
117
+ /** Your component for each layout type the definition's `layout` uses, like `section`. */
118
+ layoutComponents?: LayoutComponents;
60
119
  /** When a field is validated the first time, as in Formisch. */
61
120
  validate?: ValidationMode;
62
121
  /** When a field is validated again after that, as in Formisch. */
@@ -70,8 +129,20 @@ interface JsonFormInstance<TSchema extends FormSchema = JsonFormSchema$1> {
70
129
  readonly builder: SchemaBuilder;
71
130
  /** The components from the options, if any. */
72
131
  readonly components: FieldComponents | undefined;
73
- /** The definition's fields as a tree, the way `<JsonFields>` renders them. */
132
+ /** The layout components from the options, if any. */
133
+ readonly layoutComponents: LayoutComponents | undefined;
134
+ /** The definition's fields as a tree, for `<JsonFields :only>` and `<JsonField>`. */
74
135
  readonly fields: readonly FieldNode$1[];
136
+ /** The definition's layout, the way `<JsonFields>` renders it. */
137
+ readonly layout: FormLayout$1;
138
+ /** The layout's steps: the current one, and Next, Back and Go to. A form without steps has one. */
139
+ readonly steps: JsonFormSteps;
140
+ /**
141
+ * What the conditions of the builder's extensions hide for the form's input now, like the
142
+ * `affects` of `@whatsaaaa/form-builder-affects`: `<JsonFields>` and `<JsonField>` leave it out.
143
+ * Read it in your own renderers. Without conditions, it hides nothing.
144
+ */
145
+ readonly visibility: VisibilityState$1;
75
146
  }
76
147
  /** Any form `useJsonForm` returns, typed or not: what the components take. */
77
148
  type AnyJsonFormInstance = JsonFormInstance<FormSchema>;
@@ -79,7 +150,8 @@ type AnyJsonFormInstance = JsonFormInstance<FormSchema>;
79
150
  * A Formisch form for a definition, with its schema and initial input from the builder. A
80
151
  * definition with issues throws the builder's `DefinitionError`, so run `validate()` first when it
81
152
  * comes from outside your code. The definition is read once: give the form a new `:key` to use
82
- * another one.
153
+ * another one. With conditions, it clears the fields they clear as soon as they do, with
154
+ * Formisch's `setInput`, wherever the fields are rendered.
83
155
  */
84
156
  export declare function useJsonForm(definition: JsonForm, options?: UseJsonFormOptions): JsonFormInstance;
85
157
  /**
@@ -90,6 +162,7 @@ export declare function useJsonForm<TInput extends object, TOutput extends objec
90
162
  /**
91
163
  * Renders one field of a `useJsonForm` form, wherever you put it inside Formisch's `<Form>`. A
92
164
  * group or an array comes with its fields. Leave the field out of `<JsonFields>` with `except`.
165
+ * It renders nothing while conditions hide the field.
93
166
  */
94
167
  export declare const JsonField: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
95
168
  /** What `useJsonForm` returned. */
@@ -108,7 +181,7 @@ export declare const JsonField: import("vue").DefineComponent<import("vue").Extr
108
181
  };
109
182
  }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
110
183
  [key: string]: any;
111
- }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
184
+ }> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
112
185
  /** What `useJsonForm` returned. */
113
186
  of: {
114
187
  type: PropType<AnyJsonFormInstance>;
@@ -125,9 +198,10 @@ export declare const JsonField: import("vue").DefineComponent<import("vue").Extr
125
198
  };
126
199
  }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
127
200
  /**
128
- * Renders the fields of a `useJsonForm` form with your components, one per field type. It renders
129
- * nothing of its own, so put it inside Formisch's `<Form>` with your own submit button. `only` and
130
- * `except` are read when it sets up.
201
+ * Renders the fields of a `useJsonForm` form with your components, one per field type, where the
202
+ * definition's `layout` puts them: the current step, with its sections, rows and slots. It renders
203
+ * nothing of its own, so put it inside Formisch's `<Form>` with your own submit button. Its named
204
+ * slots fill the layout's slots. `only` and `except` are read when it sets up.
131
205
  */
132
206
  export declare const JsonFields: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
133
207
  /** What `useJsonForm` returned. */
@@ -139,17 +213,30 @@ export declare const JsonFields: import("vue").DefineComponent<import("vue").Ext
139
213
  components: {
140
214
  type: PropType<FieldComponents>;
141
215
  };
142
- /** Renders only these fields, by path, in the order of the definition. */
216
+ /** Defaults to the layout components `useJsonForm` got. */
217
+ layoutComponents: {
218
+ type: PropType<LayoutComponents>;
219
+ };
220
+ /** Renders only these fields, by path, in the order of the definition, without the layout. */
143
221
  only: {
144
222
  type: PropType<readonly string[]>;
145
223
  };
146
- /** Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. */
224
+ /**
225
+ * Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. A section or a
226
+ * row left without fields drops out too.
227
+ */
147
228
  except: {
148
229
  type: PropType<readonly string[]>;
149
230
  };
150
- }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
231
+ /** Renders the step at this index instead of the current one, e.g. on a review page. */
232
+ step: {
233
+ type: NumberConstructor;
234
+ };
235
+ }>, (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
236
+ [key: string]: any;
237
+ }>[]) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
151
238
  [key: string]: any;
152
- }>[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
239
+ }>), {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
153
240
  /** What `useJsonForm` returned. */
154
241
  of: {
155
242
  type: PropType<AnyJsonFormInstance>;
@@ -159,14 +246,25 @@ export declare const JsonFields: import("vue").DefineComponent<import("vue").Ext
159
246
  components: {
160
247
  type: PropType<FieldComponents>;
161
248
  };
162
- /** Renders only these fields, by path, in the order of the definition. */
249
+ /** Defaults to the layout components `useJsonForm` got. */
250
+ layoutComponents: {
251
+ type: PropType<LayoutComponents>;
252
+ };
253
+ /** Renders only these fields, by path, in the order of the definition, without the layout. */
163
254
  only: {
164
255
  type: PropType<readonly string[]>;
165
256
  };
166
- /** Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. */
257
+ /**
258
+ * Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. A section or a
259
+ * row left without fields drops out too.
260
+ */
167
261
  except: {
168
262
  type: PropType<readonly string[]>;
169
263
  };
264
+ /** Renders the step at this index instead of the current one, e.g. on a review page. */
265
+ step: {
266
+ type: NumberConstructor;
267
+ };
170
268
  }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
171
- export type { AnyJsonFormInstance, ArrayFieldProps, ArrayFieldSlots, DisplayFieldProps, FieldComponents, FieldNode, FieldPath, FieldRole, GroupFieldProps, GroupFieldSlots, JsonFormInstance, JsonFormSchema, TypedJsonFormSchema, UseJsonFormOptions, ValueFieldProps };
269
+ export type { AnyJsonFormInstance, ArrayFieldProps, ArrayFieldSlots, DisplayFieldProps, FieldComponents, FieldNode, FieldPath, FieldRole, FormLayout, GroupFieldProps, GroupFieldSlots, JsonFormInstance, JsonFormSchema, JsonFormSteps, LayoutComponents, LayoutNode, LayoutStep, RowProps, RowSlots, SectionProps, SectionSlots, TypedJsonFormSchema, UseJsonFormOptions, ValueFieldProps, VisibilityState };
172
270
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,129 @@
1
- import { checkComponents, coerceInput, createSchemaBuilder, dotPathOf, findField, isRequired, selectFields, toFieldPath } from "@whatsaaaa/form-builder-schema";
2
- import { defineComponent, h } from "vue";
3
- import { insert, move, remove, useField, useFieldArray, useForm } from "@formisch/vue";
1
+ import { checkComponents, checkLayoutComponents, coerceInput, createSchemaBuilder, dotPathOf, fieldPathsOf, findField, isRequired, issuesOfStep, selectFields, toFieldPath } from "@whatsaaaa/form-builder-schema";
2
+ import { Fragment, computed, defineComponent, getCurrentScope, h, nextTick, onScopeDispose, ref, watch } from "vue";
3
+ import { focus, getErrors, getInput, insert, move, remove, setErrors, setInput, useField, useFieldArray, useForm, validate } from "@formisch/vue";
4
+ // src/json-form-steps.ts
5
+ const fieldEvents = /* @__PURE__ */ new WeakMap();
6
+ /** What a field of `form` calls on each event, for a form with steps. Undefined with one step. */
7
+ const fieldEventsOf = (form) => fieldEvents.get(form);
8
+ /**
9
+ * The steps of `layout`, for `useJsonForm`. With more than one, a step shows the errors it had
10
+ * when the user left it, and none the first time they get to it, a step that failed Next
11
+ * revalidates as the user fixes it, a submit before the last step moves on like Next, and a submit
12
+ * that fails because of an earlier step goes back to it. The steps `visibility` hides are skipped.
13
+ */
14
+ function useJsonFormSteps(form, layout, modes, visibility) {
15
+ const all = layout.steps;
16
+ const at = ref(0);
17
+ const current = computed(() => all[at.value]);
18
+ const list = computed(() => all.filter((step, i) => i === at.value || !visibility.value.isStepHidden(step)));
19
+ const index = computed(() => list.value.indexOf(current.value));
20
+ const left = /* @__PURE__ */ new Map();
21
+ const failed = /* @__PURE__ */ new Set();
22
+ async function goTo(target) {
23
+ const shown = list.value;
24
+ if (!Number.isInteger(target) || target < 0 || target >= shown.length) throw new RangeError(`No step ${target}. The form has ${shown.length}.`);
25
+ const to = all.indexOf(shown[target]);
26
+ if (target <= index.value) {
27
+ move(to);
28
+ return true;
29
+ }
30
+ await afterTask();
31
+ const { issues } = await validate(form);
32
+ for (const step of shown.slice(index.value, target)) {
33
+ const found = issuesOfStep(step, issues);
34
+ if (found.length) {
35
+ await stop(all.indexOf(step), found);
36
+ return false;
37
+ }
38
+ failed.delete(all.indexOf(step));
39
+ }
40
+ move(to);
41
+ return true;
42
+ }
43
+ /**
44
+ * Moves to a step as the user left it: with the errors it had then, and none the first time, and
45
+ * revalidating if it failed Next. Validating the steps before set errors on its fields, which
46
+ * the user never saw.
47
+ */
48
+ function move(target) {
49
+ leave();
50
+ const errors = left.get(target);
51
+ for (const path of fieldPathsOf(all[target], getInput(form))) setErrors(form, {
52
+ path,
53
+ errors: errors?.get(JSON.stringify(path)) ?? null
54
+ });
55
+ at.value = target;
56
+ }
57
+ /** Keeps the errors of the current step, for when the user comes back to it. */
58
+ function leave() {
59
+ const errors = fieldPathsOf(current.value, getInput(form)).map((path) => [JSON.stringify(path), errorsAt(path)]);
60
+ left.set(at.value, new Map(errors));
61
+ }
62
+ const errorsAt = (path) => getErrors(form, { path });
63
+ /** Stays on, or goes to, the step at `target`, with its issues shown. */
64
+ async function stop(target, found) {
65
+ failed.add(target);
66
+ if (target !== at.value) leave();
67
+ at.value = target;
68
+ await nextTick();
69
+ const first = found.find((issue) => issue.field.role === "value");
70
+ if (first) focus(form, { path: first.path });
71
+ }
72
+ const steps = {
73
+ get list() {
74
+ return list.value;
75
+ },
76
+ get index() {
77
+ return index.value;
78
+ },
79
+ get current() {
80
+ return current.value;
81
+ },
82
+ get isFirst() {
83
+ return index.value === 0;
84
+ },
85
+ get isLast() {
86
+ return index.value === list.value.length - 1;
87
+ },
88
+ next: () => steps.isLast ? Promise.resolve(false) : goTo(index.value + 1),
89
+ back: () => {
90
+ if (index.value > 0) move(all.indexOf(list.value[index.value - 1]));
91
+ },
92
+ goTo
93
+ };
94
+ if (all.length > 1) watchSteps();
95
+ return steps;
96
+ function watchSteps() {
97
+ fieldEvents.set(form, (event) => {
98
+ const validateMode = modes.validate ?? "submit";
99
+ if (!failed.has(at.value) || validateMode !== "submit" || form.isSubmitted) return;
100
+ if (event === (modes.revalidate ?? "input")) validate(form);
101
+ });
102
+ watch(() => form.isSubmitting, async (submitting, was) => {
103
+ if (submitting || !was || form.isValid) return;
104
+ const { issues } = await validate(form);
105
+ const shown = list.value;
106
+ const first = shown.find((step) => issuesOfStep(step, issues).length);
107
+ const target = first ? all.indexOf(first) : -1;
108
+ if (first && shown.indexOf(first) < index.value) await stop(target, issuesOfStep(first, issues));
109
+ });
110
+ if (typeof document === "undefined") return;
111
+ const onSubmit = (event) => {
112
+ if (event.target !== formElementOf(form) || steps.isLast) return;
113
+ event.preventDefault();
114
+ event.stopImmediatePropagation();
115
+ steps.next();
116
+ };
117
+ document.addEventListener("submit", onSubmit, { capture: true });
118
+ if (getCurrentScope()) onScopeDispose(() => document.removeEventListener("submit", onSubmit, { capture: true }));
119
+ }
120
+ }
121
+ /** Resolves once the task that called it is over, and the browser is done with its event. */
122
+ const afterTask = () => new Promise((resolve) => setTimeout(resolve));
123
+ /** The `<form>` Formisch's `<Form>` renders, which it keeps on the store for its `submit()`. */
124
+ function formElementOf(form) {
125
+ return form["~internal"]?.element;
126
+ }
4
127
  // src/array-field.ts
5
128
  /** Connects a container of kind `array` to Formisch, and renders your component for it. */
6
129
  const ArrayField = defineComponent({
@@ -31,20 +154,30 @@ const ArrayField = defineComponent({
31
154
  setup(props) {
32
155
  const path = () => props.path;
33
156
  const array = useFieldArray(() => props.of.form, () => ({ path: path() }));
157
+ const events = fieldEventsOf(props.of.form);
34
158
  const methods = {
35
- add: () => insert(props.of.form, {
36
- path: path(),
37
- initialInput: props.of.builder.getItemInput(props.node.field)
38
- }),
39
- remove: (index) => remove(props.of.form, {
40
- path: path(),
41
- at: index
42
- }),
43
- move: (from, to) => move(props.of.form, {
44
- path: path(),
45
- from,
46
- to
47
- })
159
+ add: () => {
160
+ insert(props.of.form, {
161
+ path: path(),
162
+ initialInput: props.of.builder.getItemInput(props.node.field)
163
+ });
164
+ events?.("input");
165
+ },
166
+ remove: (index) => {
167
+ remove(props.of.form, {
168
+ path: path(),
169
+ at: index
170
+ });
171
+ events?.("input");
172
+ },
173
+ move: (from, to) => {
174
+ move(props.of.form, {
175
+ path: path(),
176
+ from,
177
+ to
178
+ });
179
+ events?.("input");
180
+ }
48
181
  };
49
182
  return () => {
50
183
  const fieldProps = {
@@ -82,9 +215,32 @@ const ValueField = defineComponent({
82
215
  },
83
216
  setup(props) {
84
217
  const field = useField(() => props.of.form, () => ({ path: props.path }));
218
+ const events = fieldEventsOf(props.of.form);
85
219
  const setInput = (input) => {
86
220
  field.input = coerceInput(input, props.node);
221
+ events?.("input");
87
222
  };
223
+ const inputProps = events ? {
224
+ get name() {
225
+ return field.props.name;
226
+ },
227
+ get autofocus() {
228
+ return field.props.autofocus;
229
+ },
230
+ ref: (element) => field.props.ref(element),
231
+ onFocus: () => {
232
+ field.props.onFocus();
233
+ events("touch");
234
+ },
235
+ onChange: (event) => {
236
+ field.props.onChange(event);
237
+ events("change");
238
+ },
239
+ onBlur: () => {
240
+ field.props.onBlur();
241
+ events("blur");
242
+ }
243
+ } : field.props;
88
244
  return () => {
89
245
  const fieldProps = {
90
246
  field: props.node.field,
@@ -93,7 +249,7 @@ const ValueField = defineComponent({
93
249
  required: isRequired(props.node.field),
94
250
  input: field.input,
95
251
  errors: field.errors,
96
- inputProps: field.props,
252
+ inputProps,
97
253
  setInput
98
254
  };
99
255
  return h(props.component, fieldProps);
@@ -107,14 +263,21 @@ function resolveComponents(components, of) {
107
263
  if (!resolved) throw new TypeError("No field components. Pass them to useJsonForm, or to the component.");
108
264
  return resolved;
109
265
  }
110
- /** `indexes` are the indexes of the array items the fields are in, outermost first. */
266
+ /**
267
+ * Renders the fields that conditions don't hide. `indexes` are the indexes of the array items the
268
+ * fields are in, outermost first.
269
+ */
111
270
  function renderFields(ctx, nodes, indexes) {
112
- return nodes.map((node, position) => renderField(ctx, node, indexes, position));
271
+ const { visibility } = ctx.of;
272
+ return nodes.flatMap((node, position) => visibility.isHidden(node, indexes) ? [] : [renderField(ctx, node, indexes, dotPathOf(node) ?? `#${position}`, (inner) => renderFields(ctx, node.children, inner))]);
113
273
  }
114
- function renderField(ctx, node, indexes, position) {
274
+ /**
275
+ * Renders one field with its component. `children` renders the fields inside a group, or inside
276
+ * the item of an array, with the indexes of the items they are in.
277
+ */
278
+ function renderField(ctx, node, indexes, key, children) {
115
279
  const component = ctx.components[node.type];
116
280
  const path = toFieldPath(node.dataPath, indexes);
117
- const key = dotPathOf(node) ?? `#${position}`;
118
281
  switch (node.role) {
119
282
  case "display": return h(component, {
120
283
  key,
@@ -124,14 +287,14 @@ function renderField(ctx, node, indexes, position) {
124
287
  key,
125
288
  field: node.field,
126
289
  path
127
- }, { default: () => renderFields(ctx, node.children, indexes) });
290
+ }, { default: () => children(indexes) });
128
291
  case "array": return h(ArrayField, {
129
292
  key,
130
293
  of: ctx.of,
131
294
  node,
132
295
  path,
133
296
  component,
134
- renderItem: (index) => renderFields(ctx, node.children, [...indexes, index])
297
+ renderItem: (index) => children([...indexes, index])
135
298
  });
136
299
  case "value": return h(ValueField, {
137
300
  key,
@@ -146,6 +309,7 @@ function renderField(ctx, node, indexes, position) {
146
309
  /**
147
310
  * Renders one field of a `useJsonForm` form, wherever you put it inside Formisch's `<Form>`. A
148
311
  * group or an array comes with its fields. Leave the field out of `<JsonFields>` with `except`.
312
+ * It renders nothing while conditions hide the field.
149
313
  */
150
314
  const JsonField = defineComponent({
151
315
  name: "JsonField",
@@ -170,14 +334,40 @@ const JsonField = defineComponent({
170
334
  components: resolveComponents(props.components, props.of)
171
335
  };
172
336
  checkComponents([node], ctx.components);
173
- return () => renderField(ctx, node, [], 0);
337
+ return () => props.of.visibility.isHidden(node, []) ? null : renderField(ctx, node, [], dotPathOf(node) ?? "#0", (indexes) => renderFields(ctx, node.children, indexes));
174
338
  }
175
339
  });
340
+ // src/render-layout.ts
341
+ /**
342
+ * Renders layout nodes. A field left out or hidden by conditions drops out, and so does a section
343
+ * hidden by them, and a section or a row left without fields. `indexes` are the indexes of the
344
+ * array items the nodes are in, outermost first.
345
+ */
346
+ function renderLayout(ctx, nodes, indexes) {
347
+ return ctx.of.visibility.shownNodes(nodes, indexes, ctx.isShown).map((node) => renderNode(ctx, node, indexes));
348
+ }
349
+ function renderNode(ctx, node, indexes) {
350
+ const { key } = node;
351
+ switch (node.type) {
352
+ case "field": return renderField(ctx, node.node, indexes, key, (inner) => renderLayout(ctx, node.children, inner));
353
+ case "section": return h(ctx.layoutComponents.section, {
354
+ key,
355
+ section: node.section
356
+ }, { default: () => renderLayout(ctx, node.children, indexes) });
357
+ case "row": return h(ctx.layoutComponents.row, {
358
+ key,
359
+ row: node.row,
360
+ spans: node.children.map((cell) => cell.span)
361
+ }, { default: ({ index }) => [renderNode(ctx, node.children[index], indexes)] });
362
+ case "slot": return h(Fragment, { key }, ctx.slots[node.name]?.());
363
+ }
364
+ }
176
365
  // src/json-fields.ts
177
366
  /**
178
- * Renders the fields of a `useJsonForm` form with your components, one per field type. It renders
179
- * nothing of its own, so put it inside Formisch's `<Form>` with your own submit button. `only` and
180
- * `except` are read when it sets up.
367
+ * Renders the fields of a `useJsonForm` form with your components, one per field type, where the
368
+ * definition's `layout` puts them: the current step, with its sections, rows and slots. It renders
369
+ * nothing of its own, so put it inside Formisch's `<Form>` with your own submit button. Its named
370
+ * slots fill the layout's slots. `only` and `except` are read when it sets up.
181
371
  */
182
372
  const JsonFields = defineComponent({
183
373
  name: "JsonFields",
@@ -189,12 +379,19 @@ const JsonFields = defineComponent({
189
379
  },
190
380
  /** Defaults to the components `useJsonForm` got. */
191
381
  components: { type: Object },
192
- /** Renders only these fields, by path, in the order of the definition. */
382
+ /** Defaults to the layout components `useJsonForm` got. */
383
+ layoutComponents: { type: Object },
384
+ /** Renders only these fields, by path, in the order of the definition, without the layout. */
193
385
  only: { type: Array },
194
- /** Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. */
195
- except: { type: Array }
386
+ /**
387
+ * Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. A section or a
388
+ * row left without fields drops out too.
389
+ */
390
+ except: { type: Array },
391
+ /** Renders the step at this index instead of the current one, e.g. on a review page. */
392
+ step: { type: Number }
196
393
  },
197
- setup(props) {
394
+ setup(props, { slots }) {
198
395
  const ctx = {
199
396
  of: props.of,
200
397
  components: resolveComponents(props.components, props.of)
@@ -203,10 +400,36 @@ const JsonFields = defineComponent({
203
400
  only: props.only,
204
401
  except: props.except
205
402
  });
206
- checkComponents(nodes, ctx.components);
207
- return () => renderFields(ctx, nodes, []);
403
+ if (props.only || !props.of.definition.layout) {
404
+ checkComponents(nodes, ctx.components);
405
+ return () => renderFields(ctx, nodes, []);
406
+ }
407
+ const { layout, steps } = props.of;
408
+ const except = new Set(props.except);
409
+ const layoutCtx = {
410
+ ...ctx,
411
+ layoutComponents: props.layoutComponents ?? props.of.layoutComponents ?? {},
412
+ slots,
413
+ isShown: (node) => !except.has(dotPathOf(node) ?? "")
414
+ };
415
+ checkComponents(layout.steps.flatMap((step) => fieldsOf(step.children)), ctx.components);
416
+ checkLayoutComponents(layout, layoutCtx.layoutComponents, slots);
417
+ return () => {
418
+ const index = props.step ?? steps.index;
419
+ const step = steps.list[index];
420
+ if (!step) throw new RangeError(`No step ${props.step}. The form has ${steps.list.length}.`);
421
+ return h(Fragment, { key: index }, renderLayout(layoutCtx, step.children, []));
422
+ };
208
423
  }
209
424
  });
425
+ /** Every field of the nodes, display elements written in the layout included. */
426
+ function fieldsOf(nodes) {
427
+ return nodes.flatMap((node) => {
428
+ if (node.type === "slot") return [];
429
+ const inner = fieldsOf(node.children);
430
+ return node.type === "field" ? [node.node, ...inner] : inner;
431
+ });
432
+ }
210
433
  // src/use-json-form.ts
211
434
  function useJsonForm(definition, options = {}) {
212
435
  const builder = options.builder ?? createSchemaBuilder();
@@ -216,13 +439,27 @@ function useJsonForm(definition, options = {}) {
216
439
  validate: options.validate,
217
440
  revalidate: options.revalidate
218
441
  });
219
- const { components } = options;
442
+ const layout = builder.getLayout(definition);
443
+ const visibility = builder.getVisibility(definition);
444
+ const state = visibility.conditional ? computed(() => visibility.of(getInput(form))) : { value: visibility.of(void 0) };
445
+ if (visibility.conditional) watch(() => state.value.toClear, (fields) => {
446
+ for (const { path, input } of fields) setInput(form, {
447
+ path,
448
+ input
449
+ });
450
+ });
220
451
  return {
221
452
  form,
222
453
  definition,
223
454
  builder,
224
- components,
225
- fields: builder.getFieldTree(definition)
455
+ components: options.components,
456
+ layoutComponents: options.layoutComponents,
457
+ fields: builder.getFieldTree(definition),
458
+ layout,
459
+ steps: useJsonFormSteps(form, layout, options, state),
460
+ get visibility() {
461
+ return state.value;
462
+ }
226
463
  };
227
464
  }
228
465
  export { JsonField, JsonFields, useJsonForm };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/array-field.ts","../src/value-field.ts","../src/render-fields.ts","../src/json-field.ts","../src/json-fields.ts","../src/use-json-form.ts"],"sourcesContent":["import { insert, move, remove, useFieldArray } from '@formisch/vue'\nimport type { FieldNode, FieldPath } from '@whatsaaaa/form-builder-schema'\nimport { type Component, defineComponent, h, type PropType, type VNode } from 'vue'\nimport type { ArrayFieldProps } from './field-components'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\n/** Connects a container of kind `array` to Formisch, and renders your component for it. */\nexport const ArrayField = defineComponent({\n name: 'ArrayField',\n props: {\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n node: { type: Object as PropType<FieldNode>, required: true },\n path: { type: Array as PropType<FieldPath>, required: true },\n component: { type: [Object, Function] as PropType<Component>, required: true },\n /** Renders the fields of the item at `index`. */\n renderItem: { type: Function as PropType<(index: number) => VNode[]>, required: true },\n },\n setup(props) {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const path = () => props.path as never\n const array = useFieldArray(\n () => props.of.form,\n () => ({ path: path() }),\n )\n\n const methods = {\n // A new item starts with the defaults of its fields, like the items of a new form.\n add: () =>\n insert(props.of.form, {\n path: path(),\n initialInput: props.of.builder.getItemInput(props.node.field) as never,\n }),\n remove: (index: number) => remove(props.of.form, { path: path(), at: index }),\n move: (from: number, to: number) => move(props.of.form, { path: path(), from, to }),\n }\n\n return () => {\n const fieldProps: ArrayFieldProps = {\n field: props.node.field,\n path: props.path,\n items: array.items,\n errors: array.errors,\n ...methods,\n }\n return h(props.component, fieldProps, {\n default: ({ index }: { index: number }) => props.renderItem(index),\n })\n }\n },\n})\n","import { useField } from '@formisch/vue'\nimport {\n coerceInput,\n type FieldNode,\n type FieldPath,\n isRequired,\n} from '@whatsaaaa/form-builder-schema'\nimport { type Component, defineComponent, h, type PropType } from 'vue'\nimport type { ValueFieldProps } from './field-components'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\n/** Connects a field with a value to Formisch, and renders your component for it. */\nexport const ValueField = defineComponent({\n name: 'ValueField',\n props: {\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n node: { type: Object as PropType<FieldNode>, required: true },\n path: { type: Array as PropType<FieldPath>, required: true },\n component: { type: [Object, Function] as PropType<Component>, required: true },\n },\n setup(props) {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const field = useField(\n () => props.of.form,\n () => ({ path: props.path as never }),\n )\n\n const setInput = (input: unknown) => {\n field.input = coerceInput(input, props.node) as never\n }\n\n return () => {\n const fieldProps: ValueFieldProps = {\n field: props.node.field,\n path: props.path,\n kind: props.node.kind,\n required: isRequired(props.node.field),\n input: field.input,\n errors: field.errors,\n inputProps: field.props,\n setInput,\n }\n return h(props.component, fieldProps)\n }\n },\n})\n","import { dotPathOf, type FieldNode, toFieldPath } from '@whatsaaaa/form-builder-schema'\nimport { type Component, h, type VNode } from 'vue'\nimport { ArrayField } from './array-field'\nimport type { FieldComponents } 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/** `indexes` are the indexes of the array items the fields are in, outermost first. */\nexport function renderFields(\n ctx: RenderContext,\n nodes: readonly FieldNode[],\n indexes: readonly number[],\n): VNode[] {\n return nodes.map((node, position) => renderField(ctx, node, indexes, position))\n}\n\nexport function renderField(\n ctx: RenderContext,\n node: FieldNode,\n indexes: readonly number[],\n position: number,\n): VNode {\n const component = ctx.components[node.type] as Component\n const path = toFieldPath(node.dataPath, indexes)\n const key = dotPathOf(node) ?? `#${position}`\n switch (node.role) {\n case 'display':\n return h(component, { key, field: node.field })\n case 'group':\n return h(\n component,\n { key, field: node.field, path },\n { default: () => renderFields(ctx, node.children, indexes) },\n )\n case 'array':\n return h(ArrayField, {\n key,\n of: ctx.of,\n node,\n path,\n component,\n renderItem: (index: number) => renderFields(ctx, node.children, [...indexes, index]),\n })\n case 'value':\n return h(ValueField, { key, of: ctx.of, node, path, component })\n }\n}\n","import { checkComponents, findField } from '@whatsaaaa/form-builder-schema'\nimport { defineComponent, type PropType } from 'vue'\nimport type { FieldComponents } from './field-components'\nimport { type RenderContext, renderField, resolveComponents } from './render-fields'\nimport type { AnyJsonFormInstance } from './use-json-form'\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 */\nexport const JsonField = defineComponent({\n name: 'JsonField',\n props: {\n /** What `useJsonForm` returned. */\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n /** The field's path: `'email'`, or `'address.city'` for a field of a group. */\n path: { type: String, required: true },\n /** Defaults to the components `useJsonForm` got. */\n components: { type: Object as PropType<FieldComponents> },\n },\n setup(props) {\n const node = findField(props.of.fields, props.path, { placed: true })\n const ctx: RenderContext = {\n of: props.of,\n components: resolveComponents(props.components, props.of),\n }\n checkComponents([node], ctx.components)\n\n return () => renderField(ctx, node, [], 0)\n },\n})\n","import { checkComponents, selectFields } from '@whatsaaaa/form-builder-schema'\nimport { defineComponent, type PropType } from 'vue'\nimport type { FieldComponents } from './field-components'\nimport { type RenderContext, renderFields, resolveComponents } from './render-fields'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\n/**\n * Renders the fields of a `useJsonForm` form with your components, one per field type. It renders\n * nothing of its own, so put it inside Formisch's `<Form>` with your own submit button. `only` and\n * `except` are read when it sets up.\n */\nexport const JsonFields = defineComponent({\n name: 'JsonFields',\n props: {\n /** What `useJsonForm` returned. */\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n /** Defaults to the components `useJsonForm` got. */\n components: { type: Object as PropType<FieldComponents> },\n /** Renders only these fields, by path, in the order of the definition. */\n only: { type: Array as PropType<readonly string[]> },\n /** Leaves out these fields, by path, e.g. the ones you place with `<JsonField>`. */\n except: { type: Array as PropType<readonly string[]> },\n },\n setup(props) {\n const ctx: RenderContext = {\n of: props.of,\n components: resolveComponents(props.components, props.of),\n }\n const nodes = selectFields(props.of.fields, { only: props.only, except: props.except })\n checkComponents(nodes, ctx.components)\n\n return () => renderFields(ctx, nodes, [])\n },\n})\n","import { type FormSchema, type FormStore, useForm, type ValidationMode } from '@formisch/vue'\nimport {\n createSchemaBuilder,\n type FieldNode,\n type JsonForm,\n type JsonFormSchema,\n type SchemaBuilder,\n type TypedJsonFormSchema,\n} from '@whatsaaaa/form-builder-schema'\nimport type { FieldComponents } from './field-components'\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 /** 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 = JsonFormSchema> {\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 definition's fields as a tree, the way `<JsonFields>` renders them. */\n readonly fields: readonly FieldNode[]\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. The definition is read once: give the form a new `:key` to use\n * another one.\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<TypedJsonFormSchema<TInput, TOutput>>\nexport function useJsonForm(\n definition: JsonForm,\n options: UseJsonFormOptions = {},\n): JsonFormInstance {\n const builder = options.builder ?? createSchemaBuilder()\n const form = useForm({\n schema: builder.build(definition),\n initialInput: builder.getInitialInput(definition),\n validate: options.validate,\n revalidate: options.revalidate,\n })\n const { components } = options\n return { form, definition, builder, components, fields: builder.getFieldTree(definition) }\n}\n"],"mappings":";;;;;AAOA,MAAa,aAAa,gBAAgB;CACxC,MAAM;CACN,OAAO;EACL,IAAI;GAAE,MAAM;GAAyC,UAAU;EAAK;EACpE,MAAM;GAAE,MAAM;GAA+B,UAAU;EAAK;EAC5D,MAAM;GAAE,MAAM;GAA8B,UAAU;EAAK;EAC3D,WAAW;GAAE,MAAM,CAAC,QAAQ,QAAQ;GAA0B,UAAU;EAAK;;EAE7E,YAAY;GAAE,MAAM;GAAkD,UAAU;EAAK;CACvF;CACA,MAAM,OAAO;EAEX,MAAM,aAAa,MAAM;EACzB,MAAM,QAAQ,oBACN,MAAM,GAAG,aACR,EAAE,MAAM,KAAK,EAAE,EACxB;EAEA,MAAM,UAAU;GAEd,WACE,OAAO,MAAM,GAAG,MAAM;IACpB,MAAM,KAAK;IACX,cAAc,MAAM,GAAG,QAAQ,aAAa,MAAM,KAAK,KAAK;GAC9D,CAAC;GACH,SAAS,UAAkB,OAAO,MAAM,GAAG,MAAM;IAAE,MAAM,KAAK;IAAG,IAAI;GAAM,CAAC;GAC5E,OAAO,MAAc,OAAe,KAAK,MAAM,GAAG,MAAM;IAAE,MAAM,KAA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AqC;;EAEnD,QAAQ,EAAE,MAAM,MAAqC;CACvD;CACA,MAAM,OAAO;EACX,MAAM,MAAqB;GACzB,IAAI,MAAM;GACV,YAAY,kBAAkB,MAAM,YAAY,MAAM,EAAE;EAC1D;EACA,MAAM,QAAQ,aAAa,MAAM,GAAG,QAAQ;GAAE,MAAM,MAAM;GAAM,QAAQ,MAAM;EAAO,CAAC;EACtF,gBAAgB,OAAO,IAAI,UAAU;EAErC,aAAa,aAAa,KAAK,OAAO,CAAC,CAAC;CAC1C;AACF,CAAC;;ACmBD,SAAgB,YACd,YACA,UAA8B,CAAC,GACb;CAClB,MAAM,UAAU,QAAQ,WAAW,oBAAoB;CACvD,MAAM,OAAO,QAAQ;EACnB,QAAQ,QAAQ,MAAM,UAAU;EAChC,cAAc,QAAQ,gBAAgB,UAAU;EAChD,UAAU,QAAQ;EAClB,YAAY,QAAQ;CACtB,CAAC;CACD,MAAM,EAAE,eAAe;CACvB,OAAO;EAAE;EAAM;EAAY;EAAS;EAAY,QAAQ,QAAQ,aAAa,UAAU;CAAE;AAC3F"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/json-form-steps.ts","../src/array-field.ts","../src/value-field.ts","../src/render-fields.ts","../src/json-field.ts","../src/render-layout.ts","../src/json-fields.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/vue'\nimport {\n type FieldPath,\n fieldPathsOf,\n type FormLayout,\n issuesOfStep,\n type LayoutStep,\n type StepIssue,\n type VisibilityState,\n} from '@whatsaaaa/form-builder-schema'\nimport { computed, getCurrentScope, nextTick, onScopeDispose, ref, watch } from 'vue'\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\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 */\nexport function useJsonFormSteps(\n form: FormStore,\n layout: FormLayout,\n modes: {\n validate?: ValidationMode | undefined\n revalidate?: Exclude<ValidationMode, 'initial'> | undefined\n },\n visibility: { readonly value: VisibilityState },\n): JsonFormSteps {\n const all = layout.steps\n // The current step, by its index in `all`, as are the steps of the maps and sets below.\n const at = ref(0)\n const current = computed(() => all[at.value] as LayoutStep)\n // The current step stays on show, so it never goes from under the user.\n const list = computed(() =>\n all.filter((step, i) => i === at.value || !visibility.value.isStepHidden(step)),\n )\n const index = computed(() => list.value.indexOf(current.value))\n // The errors each step had when the user left it, by the JSON of each field's path.\n const left = new Map<number, Map<string, Errors>>()\n // The steps that failed Next, and haven't passed since.\n const failed = new Set<number>()\n\n async function goTo(target: number): Promise<boolean> {\n const shown = list.value\n if (!Number.isInteger(target) || target < 0 || target >= shown.length) {\n throw new RangeError(`No step ${target}. The form has ${shown.length}.`)\n }\n const to = all.indexOf(shown[target] as LayoutStep)\n if (target <= index.value) {\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 Vue 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 shown.slice(index.value, target)) {\n const found = issuesOfStep(step, issues)\n if (found.length) {\n await stop(all.indexOf(step), found)\n return false\n }\n 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 = left.get(target)\n for (const path of fieldPathsOf(all[target] as LayoutStep, getInput(form))) {\n setErrors(form, { path, errors: errors?.get(JSON.stringify(path)) ?? null } as never)\n }\n at.value = 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 = fieldPathsOf(current.value, getInput(form))\n const errors = paths.map((path): [string, Errors] => [JSON.stringify(path), errorsAt(path)])\n left.set(at.value, new Map(errors))\n }\n\n const errorsAt = (path: FieldPath): Errors => getErrors(form, { path } as never)\n\n /** Stays on, or goes to, the step at `target`, with its issues shown. */\n async function stop(target: number, found: readonly StepIssue[]) {\n failed.add(target)\n if (target !== at.value) leave()\n at.value = target\n await nextTick()\n // A group or an array has no element: the first field that has one gets the focus.\n const first = found.find((issue) => issue.field.role === 'value')\n if (first) focus(form, { path: first.path as never })\n }\n\n const steps: JsonFormSteps = {\n get list() {\n return list.value\n },\n get index() {\n return index.value\n },\n get current() {\n return current.value\n },\n get isFirst() {\n return index.value === 0\n },\n get isLast() {\n return index.value === list.value.length - 1\n },\n next: () => (steps.isLast ? Promise.resolve(false) : goTo(index.value + 1)),\n back: () => {\n if (index.value > 0) move(all.indexOf(list.value[index.value - 1] as LayoutStep))\n },\n goTo,\n }\n if (all.length > 1) watchSteps()\n return steps\n\n function watchSteps() {\n fieldEvents.set(form, (event) => {\n // In the other modes, Formisch revalidates a field with errors itself.\n const validateMode = modes.validate ?? 'submit'\n if (!failed.has(at.value) || validateMode !== 'submit' || form.isSubmitted) return\n if (event === (modes.revalidate ?? 'input')) void validate(form)\n })\n\n // A submit that fails because of a step before the last, e.g. on a form rule, goes back to it.\n watch(\n () => form.isSubmitting,\n async (submitting, was) => {\n if (submitting || !was || form.isValid) return\n const { issues } = await validate(form)\n const shown = list.value\n const first = shown.find((step) => issuesOfStep(step, issues).length)\n const target = first ? all.indexOf(first) : -1\n if (first && shown.indexOf(first) < index.value) {\n await stop(target, issuesOfStep(first, issues))\n }\n },\n )\n\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 if (typeof document === 'undefined') return\n const onSubmit = (event: Event) => {\n if (event.target !== formElementOf(form) || steps.isLast) return\n event.preventDefault()\n event.stopImmediatePropagation()\n void steps.next()\n }\n document.addEventListener('submit', onSubmit, { capture: true })\n if (getCurrentScope()) {\n onScopeDispose(() => document.removeEventListener('submit', onSubmit, { capture: true }))\n }\n }\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/vue'\nimport type { FieldNode, FieldPath } from '@whatsaaaa/form-builder-schema'\nimport { type Component, defineComponent, h, type PropType, type VNode } from 'vue'\nimport type { ArrayFieldProps } from './field-components'\nimport { fieldEventsOf } from './json-form-steps'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\n/** Connects a container of kind `array` to Formisch, and renders your component for it. */\nexport const ArrayField = defineComponent({\n name: 'ArrayField',\n props: {\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n node: { type: Object as PropType<FieldNode>, required: true },\n path: { type: Array as PropType<FieldPath>, required: true },\n component: { type: [Object, Function] as PropType<Component>, required: true },\n /** Renders the fields of the item at `index`. */\n renderItem: { type: Function as PropType<(index: number) => VNode[]>, required: true },\n },\n setup(props) {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const path = () => props.path as never\n const array = useFieldArray(\n () => props.of.form,\n () => ({ path: path() }),\n )\n\n // In a form with steps, a step that failed Next revalidates on a change of its items too.\n const events = fieldEventsOf(props.of.form)\n const methods = {\n // A new item starts with the defaults of its fields, like the items of a new form.\n add: () => {\n insert(props.of.form, {\n path: path(),\n initialInput: props.of.builder.getItemInput(props.node.field) as never,\n })\n events?.('input')\n },\n remove: (index: number) => {\n remove(props.of.form, { path: path(), at: index })\n events?.('input')\n },\n move: (from: number, to: number) => {\n move(props.of.form, { path: path(), from, to })\n events?.('input')\n },\n }\n\n return () => {\n const fieldProps: ArrayFieldProps = {\n field: props.node.field,\n path: props.path,\n items: array.items,\n errors: array.errors,\n ...methods,\n }\n return h(props.component, fieldProps, {\n default: ({ index }: { index: number }) => props.renderItem(index),\n })\n }\n },\n})\n","import { type FieldElementProps, useField } from '@formisch/vue'\nimport {\n coerceInput,\n type FieldNode,\n type FieldPath,\n isRequired,\n} from '@whatsaaaa/form-builder-schema'\nimport { type Component, defineComponent, h, type PropType } from 'vue'\nimport type { ValueFieldProps } from './field-components'\nimport { fieldEventsOf } from './json-form-steps'\nimport type { AnyJsonFormInstance } from './use-json-form'\n\n/** Connects a field with a value to Formisch, and renders your component for it. */\nexport const ValueField = defineComponent({\n name: 'ValueField',\n props: {\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n node: { type: Object as PropType<FieldNode>, required: true },\n path: { type: Array as PropType<FieldPath>, required: true },\n component: { type: [Object, Function] as PropType<Component>, required: true },\n },\n setup(props) {\n // The path comes from the definition at runtime, so the schema's types can't check it.\n const field = useField(\n () => props.of.form,\n () => ({ path: props.path as never }),\n )\n\n // In a form with steps, a step that failed Next revalidates on these events too.\n const events = fieldEventsOf(props.of.form)\n const setInput = (input: unknown) => {\n field.input = coerceInput(input, props.node) as never\n events?.('input')\n }\n const inputProps: FieldElementProps = events\n ? {\n get name() {\n return field.props.name\n },\n get autofocus() {\n return field.props.autofocus\n },\n ref: (element) => field.props.ref(element),\n onFocus: () => {\n field.props.onFocus()\n events('touch')\n },\n onChange: (event) => {\n field.props.onChange(event)\n events('change')\n },\n onBlur: () => {\n field.props.onBlur()\n events('blur')\n },\n }\n : field.props\n\n return () => {\n const fieldProps: ValueFieldProps = {\n field: props.node.field,\n path: props.path,\n kind: props.node.kind,\n required: isRequired(props.node.field),\n input: field.input,\n errors: field.errors,\n inputProps,\n setInput,\n }\n return h(props.component, fieldProps)\n }\n },\n})\n","import { dotPathOf, type FieldNode, toFieldPath } from '@whatsaaaa/form-builder-schema'\nimport { type Component, h, type VNode } from 'vue'\nimport { ArrayField } from './array-field'\nimport type { FieldComponents } 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): VNode[] {\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[]) => VNode[],\n): VNode {\n const component = ctx.components[node.type] as Component\n const path = toFieldPath(node.dataPath, indexes)\n switch (node.role) {\n case 'display':\n return h(component, { key, field: node.field })\n case 'group':\n return h(component, { key, field: node.field, path }, { default: () => children(indexes) })\n case 'array':\n return h(ArrayField, {\n key,\n of: ctx.of,\n node,\n path,\n component,\n renderItem: (index: number) => children([...indexes, index]),\n })\n case 'value':\n return h(ValueField, { key, of: ctx.of, node, path, component })\n }\n}\n","import { checkComponents, dotPathOf, findField } from '@whatsaaaa/form-builder-schema'\nimport { defineComponent, type PropType } from 'vue'\nimport type { FieldComponents } from './field-components'\nimport { type RenderContext, renderField, renderFields, resolveComponents } from './render-fields'\nimport type { AnyJsonFormInstance } from './use-json-form'\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 const JsonField = defineComponent({\n name: 'JsonField',\n props: {\n /** What `useJsonForm` returned. */\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n /** The field's path: `'email'`, or `'address.city'` for a field of a group. */\n path: { type: String, required: true },\n /** Defaults to the components `useJsonForm` got. */\n components: { type: Object as PropType<FieldComponents> },\n },\n setup(props) {\n const node = findField(props.of.fields, props.path, { placed: true })\n const ctx: RenderContext = {\n of: props.of,\n components: resolveComponents(props.components, props.of),\n }\n checkComponents([node], ctx.components)\n\n return () =>\n props.of.visibility.isHidden(node, [])\n ? null\n : renderField(ctx, node, [], dotPathOf(node) ?? '#0', (indexes) =>\n renderFields(ctx, node.children, indexes),\n )\n },\n})\n","import type { IsFieldShown, LayoutNode } from '@whatsaaaa/form-builder-schema'\nimport { type Component, Fragment, h, type Slots, type VNode } from 'vue'\nimport type { LayoutComponents } 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: Slots\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): VNode[] {\n return ctx.of.visibility\n .shownNodes(nodes, indexes, ctx.isShown)\n .map((node) => renderNode(ctx, node, indexes))\n}\n\nfunction renderNode(ctx: LayoutContext, node: LayoutNode, indexes: readonly number[]): VNode {\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 return h(\n ctx.layoutComponents.section as Component,\n { key, section: node.section },\n { default: () => renderLayout(ctx, node.children, indexes) },\n )\n case 'row':\n return h(\n ctx.layoutComponents.row as Component,\n { key, row: node.row, spans: node.children.map((cell) => cell.span) },\n {\n default: ({ index }: { index: number }) => [\n renderNode(ctx, node.children[index] as LayoutNode, indexes),\n ],\n },\n )\n case 'slot':\n return h(Fragment, { key }, ctx.slots[node.name]?.())\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 { defineComponent, Fragment, h, type PropType } from 'vue'\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\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. Its named\n * slots fill the layout's slots. `only` and `except` are read when it sets up.\n */\nexport const JsonFields = defineComponent({\n name: 'JsonFields',\n props: {\n /** What `useJsonForm` returned. */\n of: { type: Object as PropType<AnyJsonFormInstance>, required: true },\n /** Defaults to the components `useJsonForm` got. */\n components: { type: Object as PropType<FieldComponents> },\n /** Defaults to the layout components `useJsonForm` got. */\n layoutComponents: { type: Object as PropType<LayoutComponents> },\n /** Renders only these fields, by path, in the order of the definition, without the layout. */\n only: { type: Array as PropType<readonly string[]> },\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: { type: Array as PropType<readonly string[]> },\n /** Renders the step at this index instead of the current one, e.g. on a review page. */\n step: { type: Number },\n },\n setup(props, { slots }) {\n const ctx: RenderContext = {\n of: props.of,\n components: resolveComponents(props.components, props.of),\n }\n const nodes = selectFields(props.of.fields, { only: props.only, except: props.except })\n // Without a layout, it renders the fields the way it always did, and so with `only`.\n if (props.only || !props.of.definition.layout) {\n checkComponents(nodes, ctx.components)\n return () => renderFields(ctx, nodes, [])\n }\n\n const { layout, steps } = props.of\n const except = new Set(props.except)\n const layoutCtx: LayoutContext = {\n ...ctx,\n layoutComponents: props.layoutComponents ?? props.of.layoutComponents ?? {},\n slots,\n isShown: (node) => !except.has(dotPathOf(node) ?? ''),\n }\n checkComponents(\n layout.steps.flatMap((step) => fieldsOf(step.children)),\n ctx.components,\n )\n checkLayoutComponents(layout, layoutCtx.layoutComponents, slots)\n\n return () => {\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 h(Fragment, { key: index }, renderLayout(layoutCtx, step.children, []))\n }\n },\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 {\n type FormSchema,\n type FormStore,\n getInput,\n setInput,\n useForm,\n type ValidationMode,\n} from '@formisch/vue'\nimport {\n createSchemaBuilder,\n type FieldNode,\n type FormLayout,\n type JsonForm,\n type JsonFormSchema,\n type SchemaBuilder,\n type TypedJsonFormSchema,\n type VisibilityState,\n} from '@whatsaaaa/form-builder-schema'\nimport { computed, watch } from 'vue'\nimport type { FieldComponents, LayoutComponents } from './field-components'\nimport { type JsonFormSteps, useJsonFormSteps } from './json-form-steps'\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 = JsonFormSchema> {\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. 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. The definition is read once: give the form a new `:key` to use\n * another one. With conditions, it clears the fields they clear as soon as they do, with\n * Formisch's `setInput`, wherever the fields 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<TypedJsonFormSchema<TInput, TOutput>>\nexport function useJsonForm(\n definition: JsonForm,\n options: UseJsonFormOptions = {},\n): JsonFormInstance {\n const builder = options.builder ?? createSchemaBuilder()\n const form = useForm({\n schema: builder.build(definition),\n initialInput: builder.getInitialInput(definition),\n validate: options.validate,\n revalidate: options.revalidate,\n })\n const layout = builder.getLayout(definition)\n const visibility = builder.getVisibility(definition)\n // Without conditions, nothing is hidden whatever the input, so the input isn't watched.\n const state = visibility.conditional\n ? computed(() => visibility.of(getInput(form)))\n : { value: visibility.of(undefined) }\n // A new state means something to clear may have come. It is empty once the fields are blank.\n if (visibility.conditional) {\n watch(\n () => state.value.toClear,\n (fields) => {\n // The paths come from the definition at runtime, so the schema's types can't check them.\n for (const { path, input } of fields) setInput(form, { path, input } as never)\n },\n )\n }\n return {\n form,\n definition,\n builder,\n components: options.components,\n layoutComponents: options.layoutComponents,\n fields: builder.getFieldTree(definition),\n layout,\n steps: useJsonFormSteps(form, layout, options, state),\n get visibility() {\n return state.value\n },\n }\n}\n"],"mappings":";;;;AAyDA,MAAM,8BAAc,IAAI,QAAgC;;AAGxD,MAAa,iBAAiB,SAA6C,YAAY,IAAI,IAAI;;;;;;;AAQ/F,SAAgB,iBACd,MACA,QACA,OAIA,YACe;CACf,MAAM,MAAM,OAAO;CAEnB,MAAM,KAAK,IAAI,CAAC;CAChB,MAAM,UAAU,eAAe,IAAI,GAAG,MAAoB;CAE1D,MAAM,OAAO,eACX,IAAI,QAAQ,MAAM,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,MAAM,aAAa,IAAI,CAAC,CAChF;CACA,MAAM,QAAQ,eAAe,KAAK,MAAM,QAAQ,QAAQ,KAAK,CAAC;CAE9D,MAAM,uBAAO,IAAI,IAAiC;CAElD,MAAM,yBAAS,IAAI,IAAY;CAE/B,eAAe,KAAK,QAAkC;EACpD,MAAM,QAAQ,KAAK;EACnB,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,SAAS,KAAK,UAAU,MAAM,QAC7D,MAAM,IAAI,WAAW,WAAW,OAAO,iBAAiB,MAAM,OAAO,EAAE;EAEzE,MAAM,KAAK,IAAI,QAAQ,MAAM,OAAqB;EAClD,IAAI,UAAU,MAAM,OAAO;GACzB,KAAK,EAAE;GACP,OAAO;EACT;EAIA,MAAM,UAAU;EAChB,MAAM,EAAE,WAAW,MAAM,SAAS,IAAI;EACtC,KAAK,MAAM,QAAQ,MAAM,MAAM,MAAM,OAAO,MAAM,GAAG;GACnD,MAAM,QAAQ,aAAa,MAAM,MAAM;GACvC,IAAI,MAAM,QAAQ;IAChB,MAAM,KAAK,IAAI,QAAQ,IAAI,GAAG,KAAK;IACnC,OAAO;GACT;GACA,OAAO,OAAO,IAAI,QAAQ,IAAI,CAAC;EACjC;EACA,KAAK,EAAE;EACP,OAAO;CACT;;;;;;CAOA,SAAS,KA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UAAU;CAC3C,MAAM,aAAa,QAAQ,cAAc,UAAU;CAEnD,MAAM,QAAQ,WAAW,cACrB,eAAe,WAAW,GAAG,SAAS,IAAI,CAAC,CAAC,IAC5C,EAAE,OAAO,WAAW,GAAG,KAAA,CAAS,EAAE;CAEtC,IAAI,WAAW,aACb,YACQ,MAAM,MAAM,UACjB,WAAW;EAEV,KAAK,MAAM,EAAE,MAAM,WAAW,QAAQ,SAAS,MAAM;GAAE;GAAM;EAAM,CAAU;CAC/E,CACF;CAEF,OAAO;EACL;EACA;EACA;EACA,YAAY,QAAQ;EACpB,kBAAkB,QAAQ;EAC1B,QAAQ,QAAQ,aAAa,UAAU;EACvC;EACA,OAAO,iBAAiB,MAAM,QAAQ,SAAS,KAAK;EACpD,IAAI,aAAa;GACf,OAAO,MAAM;EACf;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatsaaaa/form-builder-vue",
3
- "version": "0.1.5",
3
+ "version": "0.3.0",
4
4
  "description": "Render JSON form definitions with Formisch and your own Vue components.",
5
5
  "keywords": [
6
6
  "form",
@@ -33,11 +33,12 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@whatsaaaa/form-builder-schema": "^0.13.0"
36
+ "@whatsaaaa/form-builder-schema": "^0.15.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@arethetypeswrong/cli": "^0.18.5",
40
40
  "@formisch/vue": "^1.1.1",
41
+ "@whatsaaaa/form-builder-affects": "^0.1.0",
41
42
  "happy-dom": "^20.0.0",
42
43
  "publint": "^0.3.25",
43
44
  "tsdown": "^0.23.2",