formo-react 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -2
  3. package/dist/components/FormoBlueprint.d.ts +5 -0
  4. package/dist/components/FormoBlueprint.js +30 -0
  5. package/dist/components/FormoButton.d.ts +6 -0
  6. package/dist/components/FormoButton.js +23 -0
  7. package/dist/components/FormoCheckbox.d.ts +7 -0
  8. package/dist/components/FormoCheckbox.js +10 -0
  9. package/dist/components/FormoChecklist.d.ts +5 -0
  10. package/dist/components/FormoChecklist.js +15 -0
  11. package/dist/components/FormoChoices.d.ts +8 -0
  12. package/dist/components/FormoChoices.js +33 -0
  13. package/dist/components/FormoContext.d.ts +27 -0
  14. package/dist/components/FormoContext.js +69 -0
  15. package/dist/components/FormoErrors.d.ts +5 -0
  16. package/dist/components/FormoErrors.js +14 -0
  17. package/dist/components/FormoField.d.ts +17 -0
  18. package/dist/components/FormoField.js +148 -0
  19. package/dist/components/FormoForm.d.ts +15 -0
  20. package/dist/components/FormoForm.js +76 -0
  21. package/dist/components/FormoGroup.d.ts +5 -0
  22. package/dist/components/FormoGroup.js +15 -0
  23. package/dist/components/FormoHelp.d.ts +6 -0
  24. package/dist/components/FormoHelp.js +9 -0
  25. package/dist/components/FormoInput.d.ts +6 -0
  26. package/dist/components/FormoInput.js +24 -0
  27. package/dist/components/FormoLabel.d.ts +6 -0
  28. package/dist/components/FormoLabel.js +9 -0
  29. package/dist/components/FormoProvider.d.ts +11 -0
  30. package/dist/components/FormoProvider.js +13 -0
  31. package/dist/components/FormoRest.d.ts +6 -0
  32. package/dist/components/FormoRest.js +23 -0
  33. package/dist/components/FormoSelect.d.ts +6 -0
  34. package/dist/components/FormoSelect.js +36 -0
  35. package/dist/components/FormoUneditable.d.ts +6 -0
  36. package/dist/components/FormoUneditable.js +12 -0
  37. package/dist/core/builder.d.ts +42 -0
  38. package/dist/core/builder.js +166 -0
  39. package/dist/core/controls.d.ts +27 -0
  40. package/dist/core/controls.js +24 -0
  41. package/dist/core/fields.d.ts +63 -0
  42. package/dist/core/fields.js +177 -0
  43. package/dist/core/messages.d.ts +35 -0
  44. package/dist/core/messages.js +69 -0
  45. package/dist/core/normalize.d.ts +35 -0
  46. package/dist/core/normalize.js +234 -0
  47. package/dist/core/options.d.ts +44 -0
  48. package/dist/core/options.js +146 -0
  49. package/dist/core/rules.d.ts +41 -0
  50. package/dist/core/rules.js +230 -0
  51. package/dist/core/store.d.ts +155 -0
  52. package/dist/core/store.js +830 -0
  53. package/dist/core/theme.d.ts +20 -0
  54. package/dist/core/theme.js +21 -0
  55. package/dist/core/tree.d.ts +74 -0
  56. package/dist/core/tree.js +119 -0
  57. package/dist/core/utils.d.ts +35 -0
  58. package/dist/core/utils.js +206 -0
  59. package/dist/hooks/subscriptions.d.ts +38 -0
  60. package/dist/hooks/subscriptions.js +65 -0
  61. package/dist/hooks/useFormo.d.ts +18 -0
  62. package/dist/hooks/useFormo.js +25 -0
  63. package/dist/index.d.ts +28 -0
  64. package/dist/index.js +27 -0
  65. package/dist/schema/form.d.ts +92 -0
  66. package/dist/schema/form.js +304 -0
  67. package/dist/schema/index.d.ts +22 -0
  68. package/dist/schema/index.js +21 -0
  69. package/dist/schema/ir.d.ts +189 -0
  70. package/dist/schema/ir.js +130 -0
  71. package/dist/schema/json-schema.d.ts +25 -0
  72. package/dist/schema/json-schema.js +351 -0
  73. package/dist/schema/laravel.d.ts +57 -0
  74. package/dist/schema/laravel.js +555 -0
  75. package/dist/schema/openapi.d.ts +24 -0
  76. package/dist/schema/openapi.js +67 -0
  77. package/dist/schema/policy.d.ts +60 -0
  78. package/dist/schema/policy.js +315 -0
  79. package/dist/schema/spec.d.ts +75 -0
  80. package/dist/schema/spec.js +1 -0
  81. package/dist/schema/values.d.ts +35 -0
  82. package/dist/schema/values.js +151 -0
  83. package/dist/schema/zod.d.ts +79 -0
  84. package/dist/schema/zod.js +236 -0
  85. package/dist/types.d.ts +400 -0
  86. package/dist/types.js +1 -0
  87. package/package.json +70 -4
@@ -0,0 +1,166 @@
1
+ import { formFromModel } from '../schema/form';
2
+ import { cleanAlias, isPlainObject } from './utils';
3
+ /**
4
+ * Minimal React Native port of Formo's fluent form builder.
5
+ * Pure TypeScript — no React or React Native imports.
6
+ */
7
+ export class Formo {
8
+ #def;
9
+ #fields = [];
10
+ static form(def = {}) {
11
+ const d = typeof def === 'string' ? { alias: def } : def;
12
+ return new Formo({ alias: 'formo', driver: 'form', ...d });
13
+ }
14
+ static group(alias, def = {}) {
15
+ const d = isPlainObject(alias) ? alias : { ...def, alias };
16
+ return new Formo({ driver: 'group', ...d });
17
+ }
18
+ static fromModel(model, options = {}) {
19
+ return new Formo(formFromModel(model, options));
20
+ }
21
+ constructor(def = {}) {
22
+ const d = typeof def === 'string' ? { alias: def } : { ...def };
23
+ const fields = d.fields;
24
+ delete d.fields;
25
+ if (d.alias !== undefined)
26
+ d.alias = cleanAlias(d.alias);
27
+ this.#def = d;
28
+ if (Array.isArray(fields)) {
29
+ for (const f of fields)
30
+ if (f)
31
+ this.#fields.push(Formo.#toFormo(f));
32
+ }
33
+ else if (isPlainObject(fields)) {
34
+ // formo-vue: keys are aliases, strings are drivers, builders keep their identity, falsy entries are skipped
35
+ for (const [alias, f] of Object.entries(fields)) {
36
+ if (!f)
37
+ continue;
38
+ if (f instanceof Formo) {
39
+ f.#def.alias = cleanAlias(alias);
40
+ if (f.#def.driver === 'form')
41
+ f.#def.driver = 'group';
42
+ this.#fields.push(f);
43
+ continue;
44
+ }
45
+ this.#fields.push(new Formo(typeof f === 'string' ? { alias, driver: f } : { ...f, alias }));
46
+ }
47
+ }
48
+ }
49
+ static #toFormo(input) {
50
+ if (input instanceof Formo)
51
+ return input;
52
+ // Another builder (anything with toSchema()): its definition
53
+ if (!Array.isArray(input) && typeof input === 'object' && typeof input.toSchema === 'function') {
54
+ return new Formo(input.toSchema());
55
+ }
56
+ if (typeof input === 'string')
57
+ return new Formo({ alias: input });
58
+ if (Array.isArray(input)) {
59
+ const [alias, driver, val, opts] = input;
60
+ return new Formo({ ...(opts ?? {}), alias, ...(driver ? { driver } : {}), ...(input.length >= 3 ? { val } : {}) });
61
+ }
62
+ return new Formo(input);
63
+ }
64
+ alias() {
65
+ return this.#def.alias;
66
+ }
67
+ /**
68
+ * Add a field or subform (formo-vue's signatures):
69
+ *
70
+ * add('username')
71
+ * add('notes', 'textarea', 'My notes')
72
+ * add('email', 'input|email', { required: true }) // 3rd arg object = options
73
+ * add('hobbies', 'checkboxes', ['run'], { opts }) // alias, driver, val, opts
74
+ * add('notes', { driver: 'textarea', val: 'My notes' })
75
+ * add('address', Formo.form().add('street')) // subform (a form added to a form is a group)
76
+ * add(Formo.group('phones').add('number').padBlueprint(1)) // repeatable rows
77
+ */
78
+ add(aliasOrField, driver, valOrOpts, opts) {
79
+ let field;
80
+ const formoArg = [aliasOrField, driver, valOrOpts, opts].find((a) => a instanceof Formo);
81
+ if (formoArg) {
82
+ field = formoArg;
83
+ if (typeof aliasOrField === 'string' || typeof aliasOrField === 'number')
84
+ field.#def.alias = cleanAlias(aliasOrField);
85
+ if (typeof driver === 'string')
86
+ field.#def.driver = driver;
87
+ const settings = [driver, valOrOpts, opts].find((a) => isPlainObject(a));
88
+ if (settings)
89
+ Object.assign(field.#def, settings);
90
+ }
91
+ else if (isPlainObject(aliasOrField)) {
92
+ field = new Formo(aliasOrField);
93
+ }
94
+ else if (isPlainObject(driver)) {
95
+ field = new Formo({ ...driver, alias: aliasOrField });
96
+ }
97
+ else {
98
+ const def = { ...(opts ?? {}), alias: aliasOrField };
99
+ if (typeof driver === 'string')
100
+ def.driver = driver;
101
+ if (isPlainObject(valOrOpts))
102
+ Object.assign(def, valOrOpts);
103
+ else if (valOrOpts !== undefined)
104
+ def.val = valOrOpts;
105
+ field = new Formo(def);
106
+ }
107
+ // "form" is used once: Formo turns added forms into groups
108
+ if (field.#def.driver === 'form')
109
+ field.#def.driver = 'group';
110
+ this.#fields.push(field);
111
+ return this;
112
+ }
113
+ /**
114
+ * Fields that rely on options (select, radios, checkboxes):
115
+ * addGroup('hobby', 'select', { run: 'Running' }, 'run', { label: 'Hobby' })
116
+ */
117
+ addGroup(alias, driver, opts, val, settings = {}) {
118
+ const def = { ...settings, alias, driver, opts };
119
+ if (val !== undefined)
120
+ def.val = val;
121
+ return this.add(def);
122
+ }
123
+ /**
124
+ * Blueprints: make this group repeatable, optionally pre-filled:
125
+ * Formo.group('phones').add('number').padBlueprint(2)
126
+ * Formo.group('phones').add('number').padBlueprint([{ number: '555-1234' }])
127
+ */
128
+ padBlueprint(countOrRows = 1) {
129
+ this.#def.blueprint = true;
130
+ const current = Array.isArray(this.#def.val) ? this.#def.val : [];
131
+ if (typeof countOrRows === 'number') {
132
+ const rows = [...current];
133
+ while (rows.length < countOrRows)
134
+ rows.push({});
135
+ this.#def.val = rows;
136
+ }
137
+ else {
138
+ this.#def.val = [...countOrRows];
139
+ }
140
+ return this;
141
+ }
142
+ find(alias) {
143
+ for (const child of this.#fields) {
144
+ if (String(child.alias()) === alias)
145
+ return child;
146
+ const nested = child.find(alias);
147
+ if (nested)
148
+ return nested;
149
+ }
150
+ return undefined;
151
+ }
152
+ remove(alias) {
153
+ this.#fields = this.#fields.filter((f) => String(f.alias()) !== alias);
154
+ return this;
155
+ }
156
+ set(key, value) {
157
+ this.#def[key] = value;
158
+ return this;
159
+ }
160
+ toSchema() {
161
+ return {
162
+ ...this.#def,
163
+ ...(this.#fields.length > 0 ? { fields: this.#fields.map((f) => f.toSchema()) } : {}),
164
+ };
165
+ }
166
+ }
@@ -0,0 +1,27 @@
1
+ import type { ComponentRef, ControlModel, FormoControl, FormoFieldHandle } from '../types';
2
+ export interface ControlInput {
3
+ component: ComponentRef;
4
+ /** Props computed from the field's state — the field's own `props` win over them */
5
+ props?: (field: FormoFieldHandle) => Record<string, unknown>;
6
+ model?: ControlModel;
7
+ }
8
+ /**
9
+ * Wrap any React component as a Formo control with its prop/event contract:
10
+ *
11
+ * ```tsx
12
+ * <FormoProvider
13
+ * components={{
14
+ * rating: defineControl({
15
+ * component: StarRating,
16
+ * props: (field) => ({ disabled: field.disabled }),
17
+ * }),
18
+ * slider: defineControl({
19
+ * component: Slider,
20
+ * model: { prop: 'value', event: 'onValueChange' },
21
+ * }),
22
+ * }}
23
+ * >
24
+ * ```
25
+ */
26
+ export declare function defineControl(input: ControlInput): FormoControl;
27
+ export declare function isControl(value: unknown): value is FormoControl;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Wrap any React component as a Formo control with its prop/event contract:
3
+ *
4
+ * ```tsx
5
+ * <FormoProvider
6
+ * components={{
7
+ * rating: defineControl({
8
+ * component: StarRating,
9
+ * props: (field) => ({ disabled: field.disabled }),
10
+ * }),
11
+ * slider: defineControl({
12
+ * component: Slider,
13
+ * model: { prop: 'value', event: 'onValueChange' },
14
+ * }),
15
+ * }}
16
+ * >
17
+ * ```
18
+ */
19
+ export function defineControl(input) {
20
+ return { ...input, __formoControl: true };
21
+ }
22
+ export function isControl(value) {
23
+ return !!value && typeof value === 'object' && value.__formoControl === true;
24
+ }
@@ -0,0 +1,63 @@
1
+ import type { ChecklistItem, ErrorDisplay, FieldNode, FormoConfig } from '../types';
2
+ import { type FormoLeaf, type TreeItem } from './tree';
3
+ /**
4
+ * Form-level logic shared by `useFormo` — pure TypeScript, no React.
5
+ */
6
+ export type { FormoLeaf } from './tree';
7
+ /**
8
+ * Every leaf field of a form, blueprint rows included (their number comes from
9
+ * `values` — default: the initial values). `config` cascades like formo-vue's:
10
+ * the form's options (`useFormo(def, { config })`), then the root's `config`,
11
+ * then each group's.
12
+ */
13
+ export declare function collectLeaves(root: FieldNode, config?: FormoConfig, values?: Record<string, any>): FormoLeaf[];
14
+ /** `editable`, resolved (it can be a function of the values) */
15
+ export declare function isEditable(leaf: FormoLeaf, values: Record<string, any>): boolean;
16
+ /**
17
+ * `exclude: true` on the field or a group around it — not validated, not submitted.
18
+ * (Conditional `exclude` objects aren't supported yet)
19
+ */
20
+ export declare function isExcluded(leaf: FormoLeaf): boolean;
21
+ /**
22
+ * Settle select values like a browser `<select>` (see `settleValue`). Mutates
23
+ * `values` and returns it.
24
+ */
25
+ export declare function settleValues(leaves: FormoLeaf[], values: Record<string, any>): Record<string, any>;
26
+ /**
27
+ * Make values fit the form: blueprint values become arrays of complete rows (the
28
+ * row defaults under each row's own values — rows loaded from a server may lack
29
+ * fields), recursively, and selects settle like a browser's. Mutates `values`
30
+ * and returns it.
31
+ */
32
+ export declare function fitValues(root: FieldNode, values: Record<string, any>, config?: FormoConfig): Record<string, any>;
33
+ /** What a submit sends: the values without excluded fields / groups, and without buttons */
34
+ export declare function submittableValues(items: TreeItem[] | FormoLeaf[], values: Record<string, any>): Record<string, any>;
35
+ /** Label of a field by path, for `:other` in messages */
36
+ export declare function labelResolver(leaves: FormoLeaf[]): (path: string) => string;
37
+ /**
38
+ * Validate every field. `first` fields stop at their first failing rule,
39
+ * `all` / `checklist` fields collect every message. Read-only and excluded
40
+ * fields aren't validated.
41
+ */
42
+ export declare function validateLeaves(leaves: FormoLeaf[], values: Record<string, any>): Promise<{
43
+ errors: Record<string, string>;
44
+ allErrors: Record<string, string[]>;
45
+ }>;
46
+ /**
47
+ * Group / blueprint rules (`rules` on a subform run against its values object,
48
+ * on a blueprint against its array of rows) — deepest first, and only for groups
49
+ * whose fields all passed (formo-vue's `runGroupRules`). Adds to `errors`.
50
+ */
51
+ export declare function validateGroups(items: TreeItem[], values: Record<string, any>, errors: Record<string, string>, allErrors: Record<string, string[]>): Promise<void>;
52
+ /** The live requirement lists of every `checklist` field, by path */
53
+ export declare function evaluateChecklists(leaves: FormoLeaf[], values: Record<string, any>): Promise<Record<string, ChecklistItem[]>>;
54
+ /**
55
+ * The error the `errors` region shows for a field: with a checklist, only a
56
+ * message the list doesn't already show (ex: `required`); otherwise the first one.
57
+ */
58
+ export declare function visibleError(field: {
59
+ error?: string;
60
+ errors: string[];
61
+ errorDisplay: ErrorDisplay;
62
+ checklist: ChecklistItem[];
63
+ }): string | undefined;
@@ -0,0 +1,177 @@
1
+ import { buildInitialValues, groupNamespaces, isGroupNode, isValueless, nodeConfig, rowDefaults } from './normalize';
2
+ import { settleValue } from './options';
3
+ import { evaluateChecklist, validateFieldAll } from './rules';
4
+ import { buildTree, groupsOf, isUnder, leavesOf, valuePathOf } from './tree';
5
+ import { deepClone, deepMerge, getPath, humanize, isPlainObject, joinPath, setPath, unsetPath } from './utils';
6
+ /**
7
+ * Every leaf field of a form, blueprint rows included (their number comes from
8
+ * `values` — default: the initial values). `config` cascades like formo-vue's:
9
+ * the form's options (`useFormo(def, { config })`), then the root's `config`,
10
+ * then each group's.
11
+ */
12
+ export function collectLeaves(root, config = {}, values) {
13
+ return leavesOf(buildTree(root, values ?? buildInitialValues(root, config), config));
14
+ }
15
+ const parentValuesOf = (leaf, values) => leaf.parentPath ? (getPath(values, leaf.parentPath) ?? {}) : values;
16
+ /** `editable`, resolved (it can be a function of the values) */
17
+ export function isEditable(leaf, values) {
18
+ const e = leaf.node.editable;
19
+ if (typeof e === 'function') {
20
+ return e({ values, parentValues: parentValuesOf(leaf, values), node: leaf.node, path: leaf.path }) !== false;
21
+ }
22
+ return e !== false;
23
+ }
24
+ /**
25
+ * `exclude: true` on the field or a group around it — not validated, not submitted.
26
+ * (Conditional `exclude` objects aren't supported yet)
27
+ */
28
+ export function isExcluded(leaf) {
29
+ return leaf.excluded || leaf.node.exclude === true;
30
+ }
31
+ /**
32
+ * Settle select values like a browser `<select>` (see `settleValue`). Mutates
33
+ * `values` and returns it.
34
+ */
35
+ export function settleValues(leaves, values) {
36
+ for (const leaf of leaves) {
37
+ if (leaf.node.driver !== 'select')
38
+ continue;
39
+ const current = getPath(values, leaf.path);
40
+ const settled = settleValue(leaf.node, current);
41
+ if (settled !== current)
42
+ setPath(values, leaf.path, settled);
43
+ }
44
+ return values;
45
+ }
46
+ /**
47
+ * Make values fit the form: blueprint values become arrays of complete rows (the
48
+ * row defaults under each row's own values — rows loaded from a server may lack
49
+ * fields), recursively, and selects settle like a browser's. Mutates `values`
50
+ * and returns it.
51
+ */
52
+ export function fitValues(root, values, config = {}) {
53
+ fitNode(root, values, '', config);
54
+ return values;
55
+ }
56
+ function fitNode(node, values, prefix, config) {
57
+ const cfg = nodeConfig(node, config);
58
+ for (const child of node.fields) {
59
+ const path = joinPath(prefix, child.alias);
60
+ if (isGroupNode(child)) {
61
+ if (!child.blueprint) {
62
+ fitNode(child, values, groupNamespaces(child, cfg) ? path : prefix, cfg);
63
+ continue;
64
+ }
65
+ const childCfg = nodeConfig(child, cfg);
66
+ const rows = getPath(values, path);
67
+ const defaults = rowDefaults(child, childCfg);
68
+ const fitted = Array.isArray(rows) ? rows.map((row) => deepMerge(deepClone(defaults), isPlainObject(row) ? row : {})) : [];
69
+ setPath(values, path, fitted);
70
+ const rowNode = { ...child, blueprint: false };
71
+ fitted.forEach((_, i) => fitNode(rowNode, values, `${path}[${i}]`, cfg));
72
+ continue;
73
+ }
74
+ if (child.driver !== 'select')
75
+ continue;
76
+ const current = getPath(values, path);
77
+ const settled = settleValue(child, current);
78
+ if (settled !== current)
79
+ setPath(values, path, settled);
80
+ }
81
+ }
82
+ /** What a submit sends: the values without excluded fields / groups, and without buttons */
83
+ export function submittableValues(items, values) {
84
+ const out = deepClone(values);
85
+ const all = items;
86
+ const flat = all.some((i) => i.kind !== 'field') ? [...groupsOf(all), ...leavesOf(all)] : all;
87
+ // Deepest first, so removing a row's field never shifts another one
88
+ for (const item of [...flat].sort((a, b) => b.path.length - a.path.length)) {
89
+ if (item.kind === 'field') {
90
+ if (isExcluded(item) || isValueless(item.node))
91
+ unsetPath(out, item.path);
92
+ }
93
+ else if (item.node.exclude === true && valuePathOf(item) !== '') {
94
+ unsetPath(out, valuePathOf(item));
95
+ }
96
+ }
97
+ return out;
98
+ }
99
+ /** Label of a field by path, for `:other` in messages */
100
+ export function labelResolver(leaves) {
101
+ const byPath = new Map(leaves.map((l) => [l.path, l.node]));
102
+ return (path) => {
103
+ const node = byPath.get(path);
104
+ return node?.label || humanize(path.split('.').pop() ?? path);
105
+ };
106
+ }
107
+ /**
108
+ * Validate every field. `first` fields stop at their first failing rule,
109
+ * `all` / `checklist` fields collect every message. Read-only and excluded
110
+ * fields aren't validated.
111
+ */
112
+ export async function validateLeaves(leaves, values) {
113
+ const labelFor = labelResolver(leaves);
114
+ const errors = {};
115
+ const allErrors = {};
116
+ for (const leaf of leaves) {
117
+ if (isExcluded(leaf) || !isEditable(leaf, values))
118
+ continue;
119
+ const messages = await validateFieldAll(leaf.node, getPath(values, leaf.path), values, leaf.path, {
120
+ parentValues: parentValuesOf(leaf, values),
121
+ labelFor,
122
+ bails: leaf.errorDisplay === 'first',
123
+ });
124
+ if (messages.length) {
125
+ errors[leaf.path] = messages[0];
126
+ allErrors[leaf.path] = messages;
127
+ }
128
+ }
129
+ return { errors, allErrors };
130
+ }
131
+ /**
132
+ * Group / blueprint rules (`rules` on a subform run against its values object,
133
+ * on a blueprint against its array of rows) — deepest first, and only for groups
134
+ * whose fields all passed (formo-vue's `runGroupRules`). Adds to `errors`.
135
+ */
136
+ export async function validateGroups(items, values, errors, allErrors) {
137
+ const groups = groupsOf(items)
138
+ .filter((g) => g.node.rules.length && !g.excluded)
139
+ .sort((a, b) => b.depth - a.depth);
140
+ const labelFor = labelResolver(leavesOf(items));
141
+ for (const group of groups) {
142
+ if (Object.keys(errors).some((p) => p !== group.path && isUnder(p, group.path)))
143
+ continue;
144
+ const valuePath = valuePathOf(group);
145
+ const value = valuePath === '' ? values : getPath(values, valuePath);
146
+ const parentValues = group.parentPath ? (getPath(values, group.parentPath) ?? {}) : values;
147
+ const messages = await validateFieldAll(group.node, value, values, group.path, { parentValues, labelFor, bails: true });
148
+ if (messages.length) {
149
+ errors[group.path] = messages[0];
150
+ allErrors[group.path] = messages;
151
+ }
152
+ }
153
+ }
154
+ /** The live requirement lists of every `checklist` field, by path */
155
+ export async function evaluateChecklists(leaves, values) {
156
+ const labelFor = labelResolver(leaves);
157
+ const out = {};
158
+ for (const leaf of leaves) {
159
+ if (leaf.errorDisplay !== 'checklist')
160
+ continue;
161
+ out[leaf.path] = await evaluateChecklist(leaf.node, getPath(values, leaf.path), values, leaf.path, {
162
+ parentValues: parentValuesOf(leaf, values),
163
+ labelFor,
164
+ });
165
+ }
166
+ return out;
167
+ }
168
+ /**
169
+ * The error the `errors` region shows for a field: with a checklist, only a
170
+ * message the list doesn't already show (ex: `required`); otherwise the first one.
171
+ */
172
+ export function visibleError(field) {
173
+ if (!field.error || field.errorDisplay !== 'checklist')
174
+ return field.error;
175
+ const listed = new Set(field.checklist.map((item) => item.message));
176
+ return field.errors.find((message) => !listed.has(message));
177
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * English texts. Placeholders: `:field` (label), `:value`, `:param1`…, `:params`, `:other`.
3
+ *
4
+ * Messages of the rules this port already had keep their wording; the others
5
+ * (and the checklist requirements / UI strings) follow formo-vue's `en` locale.
6
+ */
7
+ export declare const validationMessages: Record<string, string>;
8
+ /** How rules read in a requirements checklist (`errorDisplay: 'checklist'`) */
9
+ export declare const requirementMessages: Record<string, string>;
10
+ export interface FormoUiStrings {
11
+ yes: string;
12
+ no: string;
13
+ /** Read-only field without a value */
14
+ empty: string;
15
+ /** A select's blank option (`blank: true`) */
16
+ selectItem: string;
17
+ /** A multiple select with nothing selected */
18
+ selectItems: string;
19
+ /** Closes a multiple select's list */
20
+ done: string;
21
+ /** The backdrop behind a select's list (closes it) */
22
+ close: string;
23
+ /** Checklist screen-reader prefixes */
24
+ met: string;
25
+ notMet: string;
26
+ /** Checklist accessibility label — `:field`, `:met`, `:total` */
27
+ checklistSummary: string;
28
+ /** Blueprint "add row" button */
29
+ add: string;
30
+ /** Blueprint "remove row" button */
31
+ remove: string;
32
+ /** Blueprint row heading — `:label`, `:index` */
33
+ rowLabel: string;
34
+ }
35
+ export declare const uiStrings: FormoUiStrings;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * English texts. Placeholders: `:field` (label), `:value`, `:param1`…, `:params`, `:other`.
3
+ *
4
+ * Messages of the rules this port already had keep their wording; the others
5
+ * (and the checklist requirements / UI strings) follow formo-vue's `en` locale.
6
+ */
7
+ export const validationMessages = {
8
+ default: ':field is invalid',
9
+ required: ':field is required',
10
+ not_empty: ':field is required',
11
+ accepted: ':field must be accepted',
12
+ email: ':field must be a valid email',
13
+ min: ':field must be at least :param1 characters',
14
+ max: ':field must be at most :param1 characters',
15
+ numeric: ':field must be a number',
16
+ integer: ':field must be a whole number',
17
+ digits: ':field must be :param1 digits',
18
+ min_value: ':field must be at least :param1',
19
+ max_value: ':field must be at most :param1',
20
+ regex: ':field does not match the required format',
21
+ alpha_dash: ':field must contain only numbers, letters and dashes',
22
+ one_of: ':field must be one of the available options',
23
+ not_one_of: ':field is not an allowed value',
24
+ confirmed: ':field must be the same as :other',
25
+ matches: ':field must be the same as :other',
26
+ min_items: 'Choose at least :param1 :field',
27
+ max_items: 'Choose at most :param1 :field',
28
+ mixed_case: ':field must contain at least one uppercase and one lowercase letter',
29
+ letters: ':field must contain at least one letter',
30
+ numbers: ':field must contain at least one number',
31
+ symbols: ':field must contain at least one symbol',
32
+ };
33
+ /** How rules read in a requirements checklist (`errorDisplay: 'checklist'`) */
34
+ export const requirementMessages = {
35
+ required: 'Required',
36
+ email: 'A valid email address',
37
+ min: 'At least :param1 characters',
38
+ max: 'At most :param1 characters',
39
+ numeric: 'A number',
40
+ integer: 'A whole number',
41
+ digits: 'Exactly :param1 digits',
42
+ min_value: ':param1 or more',
43
+ max_value: ':param1 or less',
44
+ alpha_dash: 'Letters, numbers, dashes and underscores only',
45
+ confirmed: 'Matches :other',
46
+ matches: 'Matches :other',
47
+ min_items: 'At least :param1 selected',
48
+ max_items: 'At most :param1 selected',
49
+ mixed_case: 'Uppercase and lowercase letters',
50
+ letters: 'At least one letter',
51
+ numbers: 'At least one number',
52
+ symbols: 'At least one symbol',
53
+ accepted: 'Accepted',
54
+ };
55
+ export const uiStrings = {
56
+ yes: 'Yes',
57
+ no: 'No',
58
+ empty: '—',
59
+ selectItem: 'Select item',
60
+ selectItems: 'Select items',
61
+ done: 'Done',
62
+ close: 'Close',
63
+ met: 'Met:',
64
+ notMet: 'Not met:',
65
+ checklistSummary: ':field: :met of :total requirements met',
66
+ add: 'Add another',
67
+ remove: 'Remove',
68
+ rowLabel: ':label #:index',
69
+ };
@@ -0,0 +1,35 @@
1
+ import type { FieldNode, FormoDefinition } from '../types';
2
+ import type { FormoConfig } from '../types';
3
+ export declare function normalize(input: FormoDefinition): FieldNode;
4
+ /**
5
+ * A name for a field even when its label is hidden (`label: false`): for
6
+ * accessibility labels, button texts, messages
7
+ */
8
+ export declare function accessibleLabel(node: FieldNode): string;
9
+ /** Subforms and blueprints: nodes whose children are fields */
10
+ export declare function isGroupNode(node: FieldNode): boolean;
11
+ /** Buttons: rendered, but no value */
12
+ export declare function isValueless(node: FieldNode): boolean;
13
+ /** `hidden` fields (`driver: 'hidden'`, `input|hidden`): a value, nothing rendered */
14
+ export declare function isHidden(node: FieldNode): boolean;
15
+ /** Whether a group nests its fields' values under its alias (`namespaces` config, cascading) */
16
+ export declare function groupNamespaces(node: FieldNode, inherited: FormoConfig): boolean;
17
+ /** `config` of a node, layered over what it inherits */
18
+ export declare function nodeConfig(node: FieldNode, inherited: FormoConfig): FormoConfig;
19
+ /**
20
+ * The value a field starts with when its definition has no `val` (formo-vue's driver defaults):
21
+ * `checkbox` / `switch` → `false`, `checkboxes` and multiple selects → `[]`, `radios` → `null`,
22
+ * a select with a blank option → `null`, a select without one → its first enabled option
23
+ * (what a browser `<select>` selects), everything else → `''`.
24
+ */
25
+ export declare function defaultValueFor(node: FieldNode): unknown;
26
+ /** The values of one new row of a blueprint: its fields' defaults */
27
+ export declare function rowDefaults(blueprint: FieldNode, config?: FormoConfig): Record<string, any>;
28
+ /**
29
+ * The initial values of a form (formo-vue's `buildInitialValues`): each field's
30
+ * `val`, or its driver's default. Groups nest (unless `namespaces: false`),
31
+ * blueprints are arrays of rows — their `val` rows over the row defaults, else
32
+ * `min` empty rows. A group's (or the form's) `val` object is merged in.
33
+ * Buttons have no value.
34
+ */
35
+ export declare function buildInitialValues(node: FieldNode, config?: FormoConfig, out?: Record<string, any>, prefix?: string): Record<string, any>;