@marktiderman/genesis-forms 0.4.2 → 0.6.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.
@@ -1,5 +1,5 @@
1
- import { e as FormEvent, J as Json, F as FormDefinition, a as FieldBlock, B as Block } from './types-BBKBQ8sp.cjs';
2
- import { F as FieldValidator } from './validate-BXXqi0fq.cjs';
1
+ import { e as FormEvent, J as Json, F as FormDefinition, a as FieldBlock, B as Block } from './types-oAckGR_Z.js';
2
+ import { F as FieldValidator, H as HostOptions, L as LinkParams } from './validate-GpTXPwyl.js';
3
3
 
4
4
  /** Guards and helpers for event logs and other untrusted JSON. No dependencies. */
5
5
 
@@ -29,6 +29,11 @@ interface FormState {
29
29
  current: string | null;
30
30
  /** Visited blocks, for Back. */
31
31
  history: string[];
32
+ /**
33
+ * The furthest block reached by moving on (`next`), kept after going back;
34
+ * the first block until then. `formProgress` reads it.
35
+ */
36
+ furthest: string | null;
32
37
  errors: Record<string, string>;
33
38
  status: "in_progress" | "completed";
34
39
  /** The ending reached once completed. */
@@ -43,8 +48,33 @@ interface CreateFormOptions {
43
48
  validators?: Record<string, FieldValidator> | undefined;
44
49
  /** Timestamps on events. Pass `() => undefined` to record none (anonymous forms). */
45
50
  clock?: (() => number | undefined) | undefined;
51
+ /**
52
+ * Pick up where the respondent was (with `initialValues` holding their saved
53
+ * answers): a block id, usually `formProgress`'s `fieldId` from an earlier
54
+ * visit. The form moves on from the first block with Next, as they did, until
55
+ * it reaches this one, so Back still walks their path; it stops early at a
56
+ * step that no longer passes (a question since made required), and does
57
+ * nothing when the block isn't on the path.
58
+ */
59
+ resumeAt?: string | null | undefined;
60
+ /**
61
+ * The option lists this app supplies, by key, for choice fields with
62
+ * `props.optionsFrom: { source: "host", key }` (see `withHostOptions`).
63
+ * `engine.definition` is the definition with them filled in, so renderers
64
+ * show them and validation accepts only them (and the field's own options).
65
+ * Pass the same lists to `validateSubmission` on the server.
66
+ */
67
+ hostOptions?: HostOptions | undefined;
68
+ /**
69
+ * The query parameters of the link the form was opened from (a `URLSearchParams` or a record).
70
+ * Choice questions with `props.prefill: { param }` take their parameter's value when it is one
71
+ * of their options (`prefillFromLink`); `initialValues` win over the link. A question with
72
+ * `props.prefill.hideWhenPrefilled` is then stepped over (`hiddenByPrefill`).
73
+ */
74
+ linkParams?: LinkParams | undefined;
46
75
  }
47
76
  interface FormEngine {
77
+ /** The definition being filled in, with `hostOptions` filled in (`withHostOptions`). */
48
78
  readonly definition: FormDefinition;
49
79
  getState(): FormState;
50
80
  subscribe(listener: () => void): () => void;
@@ -72,6 +102,6 @@ interface FormEngine {
72
102
  }
73
103
  declare function createForm(definition: FormDefinition, options?: CreateFormOptions): FormEngine;
74
104
  /** Rebuild a form's state from its event log. Timestamps are ignored. */
75
- declare function replay(definition: FormDefinition, events: FormEvent[], options?: Omit<CreateFormOptions, "clock" | "initialValues">): FormEngine;
105
+ declare function replay(definition: FormDefinition, events: FormEvent[], options?: Omit<CreateFormOptions, "clock" | "initialValues" | "linkParams">): FormEngine;
76
106
 
77
107
  export { type CreateFormOptions as C, type FormEngine as F, type FormState as a, isJson as b, createForm as c, compactEvents as d, isFormEvent as i, replay as r };
@@ -1,5 +1,5 @@
1
- import { e as FormEvent, J as Json, F as FormDefinition, a as FieldBlock, B as Block } from './types-BBKBQ8sp.js';
2
- import { F as FieldValidator } from './validate-BjNwF1UE.js';
1
+ import { e as FormEvent, J as Json, F as FormDefinition, a as FieldBlock, B as Block } from './types-oAckGR_Z.cjs';
2
+ import { F as FieldValidator, H as HostOptions, L as LinkParams } from './validate-B5WKHbst.cjs';
3
3
 
4
4
  /** Guards and helpers for event logs and other untrusted JSON. No dependencies. */
5
5
 
@@ -29,6 +29,11 @@ interface FormState {
29
29
  current: string | null;
30
30
  /** Visited blocks, for Back. */
31
31
  history: string[];
32
+ /**
33
+ * The furthest block reached by moving on (`next`), kept after going back;
34
+ * the first block until then. `formProgress` reads it.
35
+ */
36
+ furthest: string | null;
32
37
  errors: Record<string, string>;
33
38
  status: "in_progress" | "completed";
34
39
  /** The ending reached once completed. */
@@ -43,8 +48,33 @@ interface CreateFormOptions {
43
48
  validators?: Record<string, FieldValidator> | undefined;
44
49
  /** Timestamps on events. Pass `() => undefined` to record none (anonymous forms). */
45
50
  clock?: (() => number | undefined) | undefined;
51
+ /**
52
+ * Pick up where the respondent was (with `initialValues` holding their saved
53
+ * answers): a block id, usually `formProgress`'s `fieldId` from an earlier
54
+ * visit. The form moves on from the first block with Next, as they did, until
55
+ * it reaches this one, so Back still walks their path; it stops early at a
56
+ * step that no longer passes (a question since made required), and does
57
+ * nothing when the block isn't on the path.
58
+ */
59
+ resumeAt?: string | null | undefined;
60
+ /**
61
+ * The option lists this app supplies, by key, for choice fields with
62
+ * `props.optionsFrom: { source: "host", key }` (see `withHostOptions`).
63
+ * `engine.definition` is the definition with them filled in, so renderers
64
+ * show them and validation accepts only them (and the field's own options).
65
+ * Pass the same lists to `validateSubmission` on the server.
66
+ */
67
+ hostOptions?: HostOptions | undefined;
68
+ /**
69
+ * The query parameters of the link the form was opened from (a `URLSearchParams` or a record).
70
+ * Choice questions with `props.prefill: { param }` take their parameter's value when it is one
71
+ * of their options (`prefillFromLink`); `initialValues` win over the link. A question with
72
+ * `props.prefill.hideWhenPrefilled` is then stepped over (`hiddenByPrefill`).
73
+ */
74
+ linkParams?: LinkParams | undefined;
46
75
  }
47
76
  interface FormEngine {
77
+ /** The definition being filled in, with `hostOptions` filled in (`withHostOptions`). */
48
78
  readonly definition: FormDefinition;
49
79
  getState(): FormState;
50
80
  subscribe(listener: () => void): () => void;
@@ -72,6 +102,6 @@ interface FormEngine {
72
102
  }
73
103
  declare function createForm(definition: FormDefinition, options?: CreateFormOptions): FormEngine;
74
104
  /** Rebuild a form's state from its event log. Timestamps are ignored. */
75
- declare function replay(definition: FormDefinition, events: FormEvent[], options?: Omit<CreateFormOptions, "clock" | "initialValues">): FormEngine;
105
+ declare function replay(definition: FormDefinition, events: FormEvent[], options?: Omit<CreateFormOptions, "clock" | "initialValues" | "linkParams">): FormEngine;
76
106
 
77
107
  export { type CreateFormOptions as C, type FormEngine as F, type FormState as a, isJson as b, createForm as c, compactEvents as d, isFormEvent as i, replay as r };