formo-react 0.0.0-stage → 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/LICENSE +201 -0
- package/README.md +21 -2
- package/dist/components/FormoBlueprint.d.ts +5 -0
- package/dist/components/FormoBlueprint.js +30 -0
- package/dist/components/FormoButton.d.ts +6 -0
- package/dist/components/FormoButton.js +23 -0
- package/dist/components/FormoCheckbox.d.ts +7 -0
- package/dist/components/FormoCheckbox.js +10 -0
- package/dist/components/FormoChecklist.d.ts +5 -0
- package/dist/components/FormoChecklist.js +15 -0
- package/dist/components/FormoChoices.d.ts +8 -0
- package/dist/components/FormoChoices.js +33 -0
- package/dist/components/FormoContext.d.ts +27 -0
- package/dist/components/FormoContext.js +69 -0
- package/dist/components/FormoErrors.d.ts +5 -0
- package/dist/components/FormoErrors.js +14 -0
- package/dist/components/FormoField.d.ts +17 -0
- package/dist/components/FormoField.js +148 -0
- package/dist/components/FormoForm.d.ts +15 -0
- package/dist/components/FormoForm.js +76 -0
- package/dist/components/FormoGroup.d.ts +5 -0
- package/dist/components/FormoGroup.js +15 -0
- package/dist/components/FormoHelp.d.ts +6 -0
- package/dist/components/FormoHelp.js +9 -0
- package/dist/components/FormoInput.d.ts +6 -0
- package/dist/components/FormoInput.js +24 -0
- package/dist/components/FormoLabel.d.ts +6 -0
- package/dist/components/FormoLabel.js +9 -0
- package/dist/components/FormoProvider.d.ts +11 -0
- package/dist/components/FormoProvider.js +13 -0
- package/dist/components/FormoRest.d.ts +6 -0
- package/dist/components/FormoRest.js +23 -0
- package/dist/components/FormoSelect.d.ts +6 -0
- package/dist/components/FormoSelect.js +36 -0
- package/dist/components/FormoUneditable.d.ts +6 -0
- package/dist/components/FormoUneditable.js +12 -0
- package/dist/core/builder.d.ts +42 -0
- package/dist/core/builder.js +166 -0
- package/dist/core/controls.d.ts +27 -0
- package/dist/core/controls.js +24 -0
- package/dist/core/fields.d.ts +63 -0
- package/dist/core/fields.js +177 -0
- package/dist/core/messages.d.ts +35 -0
- package/dist/core/messages.js +69 -0
- package/dist/core/normalize.d.ts +35 -0
- package/dist/core/normalize.js +234 -0
- package/dist/core/options.d.ts +44 -0
- package/dist/core/options.js +146 -0
- package/dist/core/rules.d.ts +41 -0
- package/dist/core/rules.js +230 -0
- package/dist/core/store.d.ts +155 -0
- package/dist/core/store.js +830 -0
- package/dist/core/theme.d.ts +20 -0
- package/dist/core/theme.js +21 -0
- package/dist/core/tree.d.ts +74 -0
- package/dist/core/tree.js +119 -0
- package/dist/core/utils.d.ts +35 -0
- package/dist/core/utils.js +206 -0
- package/dist/hooks/subscriptions.d.ts +38 -0
- package/dist/hooks/subscriptions.js +65 -0
- package/dist/hooks/useFormo.d.ts +18 -0
- package/dist/hooks/useFormo.js +25 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +27 -0
- package/dist/schema/form.d.ts +92 -0
- package/dist/schema/form.js +304 -0
- package/dist/schema/index.d.ts +22 -0
- package/dist/schema/index.js +21 -0
- package/dist/schema/ir.d.ts +189 -0
- package/dist/schema/ir.js +130 -0
- package/dist/schema/json-schema.d.ts +25 -0
- package/dist/schema/json-schema.js +351 -0
- package/dist/schema/laravel.d.ts +57 -0
- package/dist/schema/laravel.js +555 -0
- package/dist/schema/openapi.d.ts +24 -0
- package/dist/schema/openapi.js +67 -0
- package/dist/schema/policy.d.ts +60 -0
- package/dist/schema/policy.js +315 -0
- package/dist/schema/spec.d.ts +75 -0
- package/dist/schema/spec.js +1 -0
- package/dist/schema/values.d.ts +35 -0
- package/dist/schema/values.js +151 -0
- package/dist/schema/zod.d.ts +79 -0
- package/dist/schema/zod.js +236 -0
- package/dist/types.d.ts +400 -0
- package/dist/types.js +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { requirementMessages, validationMessages } from './messages';
|
|
2
|
+
import { getPath, humanize, interpolate, isEmptyValue, isPlainObject, toArray } from './utils';
|
|
3
|
+
function isStandardSchema(value) {
|
|
4
|
+
return !!value && (typeof value === 'object' || typeof value === 'function') && '~standard' in value;
|
|
5
|
+
}
|
|
6
|
+
/** `'min:3'` → `{ name: 'min', params: ['3'] }` (only the first `:` separates — regexes keep theirs) */
|
|
7
|
+
function parseRuleString(str) {
|
|
8
|
+
const idx = str.indexOf(':');
|
|
9
|
+
if (idx === -1)
|
|
10
|
+
return { name: str.trim(), params: [] };
|
|
11
|
+
return { name: str.slice(0, idx).trim(), params: str.slice(idx + 1).split(',') };
|
|
12
|
+
}
|
|
13
|
+
const schemaRule = (schema) => async (value) => {
|
|
14
|
+
const result = (await schema['~standard'].validate(value));
|
|
15
|
+
return result && Array.isArray(result.issues) && result.issues.length ? result.issues[0].message : true;
|
|
16
|
+
};
|
|
17
|
+
/** Any notation formo-vue accepts → parsed rules */
|
|
18
|
+
export function parseRule(spec) {
|
|
19
|
+
if (typeof spec === 'string') {
|
|
20
|
+
return spec
|
|
21
|
+
.split('|')
|
|
22
|
+
.map((s) => s.trim())
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.map(parseRuleString);
|
|
25
|
+
}
|
|
26
|
+
if (typeof spec === 'function')
|
|
27
|
+
return [{ name: spec.name || 'custom', params: [], fn: spec }];
|
|
28
|
+
if (isStandardSchema(spec))
|
|
29
|
+
return [{ name: 'schema', params: [], fn: schemaRule(spec) }];
|
|
30
|
+
if (Array.isArray(spec)) {
|
|
31
|
+
const [rule, params = []] = spec;
|
|
32
|
+
const list = toArray(params);
|
|
33
|
+
if (typeof rule === 'function')
|
|
34
|
+
return [{ name: rule.name || 'custom', params: list, fn: rule }];
|
|
35
|
+
return [{ name: String(rule), params: list }];
|
|
36
|
+
}
|
|
37
|
+
if (isPlainObject(spec) && 'rule' in spec) {
|
|
38
|
+
const { rule, params = [], message, label } = spec;
|
|
39
|
+
if (typeof rule === 'function')
|
|
40
|
+
return [{ name: rule.name || 'custom', params, fn: rule, message, label }];
|
|
41
|
+
return [{ name: String(rule), params, message, label }];
|
|
42
|
+
}
|
|
43
|
+
if (isPlainObject(spec)) {
|
|
44
|
+
// VeeValidate object notation: { required: true, min: 3, between: [1, 10] }
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const [name, value] of Object.entries(spec)) {
|
|
47
|
+
if (value === false || value === undefined || value === null)
|
|
48
|
+
continue;
|
|
49
|
+
if (typeof value === 'function') {
|
|
50
|
+
out.push({ name, params: [], fn: value });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
out.push({ name, params: value === true ? [] : Array.isArray(value) ? value : [value] });
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
export function parseRules(specs) {
|
|
60
|
+
return specs.flatMap(parseRule);
|
|
61
|
+
}
|
|
62
|
+
/* -------------------------------------------------------------------------- */
|
|
63
|
+
/* Built-in rules */
|
|
64
|
+
/* -------------------------------------------------------------------------- */
|
|
65
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
66
|
+
function toRegExp(value) {
|
|
67
|
+
if (value instanceof RegExp)
|
|
68
|
+
return value;
|
|
69
|
+
const str = String(value ?? '');
|
|
70
|
+
const m = str.match(/^\/(.*)\/([a-z]*)$/s);
|
|
71
|
+
return m ? new RegExp(m[1], m[2]) : new RegExp(str);
|
|
72
|
+
}
|
|
73
|
+
/** String length rules check every element of an array (VeeValidate) */
|
|
74
|
+
const eachString = (v, test) => (Array.isArray(v) ? v.every((x) => test(String(x ?? ''))) : test(String(v)));
|
|
75
|
+
/**
|
|
76
|
+
* Built-in rules. Names follow formo-vue (VeeValidate + Laravel).
|
|
77
|
+
* Every rule except `required` and `accepted` passes on empty values.
|
|
78
|
+
*/
|
|
79
|
+
export const builtinRules = {
|
|
80
|
+
required: (v) => !isEmptyValue(v) && v !== false,
|
|
81
|
+
not_empty: (v) => !isEmptyValue(v),
|
|
82
|
+
accepted: (v) => v === true || v === 1 || ['1', 'yes', 'on', 'true'].includes(String(v ?? '').toLowerCase()),
|
|
83
|
+
email: (v) => isEmptyValue(v) || EMAIL_RE.test(String(v)),
|
|
84
|
+
min: (v, p) => isEmptyValue(v) || eachString(v, (s) => s.length >= Number(p[0])),
|
|
85
|
+
max: (v, p) => isEmptyValue(v) || eachString(v, (s) => s.length <= Number(p[0])),
|
|
86
|
+
numeric: (v) => isEmptyValue(v) || !Number.isNaN(Number(v)),
|
|
87
|
+
integer: (v) => isEmptyValue(v) || /^-?\d+$/.test(String(v)),
|
|
88
|
+
digits: (v, p) => isEmptyValue(v) || new RegExp(`^\\d{${Number(p[0])}}$`).test(String(v)),
|
|
89
|
+
min_value: (v, p) => isEmptyValue(v) || Number(v) >= Number(p[0]),
|
|
90
|
+
max_value: (v, p) => isEmptyValue(v) || Number(v) <= Number(p[0]),
|
|
91
|
+
regex: (v, p) => isEmptyValue(v) || eachString(v, (s) => toRegExp(p[0]).test(s)),
|
|
92
|
+
alpha_dash: (v) => isEmptyValue(v) || eachString(v, (s) => /^[\p{L}\p{N}_-]*$/u.test(s)),
|
|
93
|
+
/** The value (or every value of a list) is one of the params */
|
|
94
|
+
one_of: (v, p) => isEmptyValue(v) || toArray(v).every((x) => p.flat().some((o) => String(o) === String(x))),
|
|
95
|
+
not_one_of: (v, p) => isEmptyValue(v) || toArray(v).every((x) => !p.flat().some((o) => String(o) === String(x))),
|
|
96
|
+
/** `confirmed:@password` — equal to another field */
|
|
97
|
+
confirmed: (v, p) => (isEmptyValue(v) && isEmptyValue(p[0])) || String(v ?? '') === String(p[0] ?? ''),
|
|
98
|
+
matches: (v, p) => String(v ?? '') === String(p[0] ?? ''),
|
|
99
|
+
/** At least N items (checkboxes, multiple selects) */
|
|
100
|
+
min_items: (v, p) => isEmptyValue(v) || toArray(v).length >= Number(p[0]),
|
|
101
|
+
max_items: (v, p) => isEmptyValue(v) || toArray(v).length <= Number(p[0]),
|
|
102
|
+
/** Laravel `Password::mixedCase()`, `letters()`, `numbers()`, `symbols()` */
|
|
103
|
+
mixed_case: (v) => isEmptyValue(v) || (/\p{Lu}/u.test(String(v)) && /\p{Ll}/u.test(String(v))),
|
|
104
|
+
letters: (v) => isEmptyValue(v) || /\p{L}/u.test(String(v)),
|
|
105
|
+
numbers: (v) => isEmptyValue(v) || /\p{N}/u.test(String(v)),
|
|
106
|
+
symbols: (v) => isEmptyValue(v) || /[\p{Z}\p{S}\p{P}]/u.test(String(v)),
|
|
107
|
+
};
|
|
108
|
+
/** Rules implied by the field being required — not listed in checklists (unless labelled) */
|
|
109
|
+
const IMPLIED = new Set(['required', 'not_empty']);
|
|
110
|
+
function parentPathOf(path) {
|
|
111
|
+
const idx = path.lastIndexOf('.');
|
|
112
|
+
return idx === -1 ? '' : path.slice(0, idx);
|
|
113
|
+
}
|
|
114
|
+
function makeContext(values, path, opts) {
|
|
115
|
+
const parentPath = parentPathOf(path);
|
|
116
|
+
const parentValues = opts.parentValues ?? (parentPath ? (getPath(values, parentPath) ?? {}) : values);
|
|
117
|
+
return { values, parentValues, path };
|
|
118
|
+
}
|
|
119
|
+
/** `@other_field` params become that field's value, relative to the group first */
|
|
120
|
+
function substitute(param, ctx) {
|
|
121
|
+
if (typeof param !== 'string' || !param.startsWith('@') || param.length < 2)
|
|
122
|
+
return param;
|
|
123
|
+
const ref = param.slice(1);
|
|
124
|
+
const relative = getPath(ctx.parentValues, ref);
|
|
125
|
+
return relative !== undefined ? relative : getPath(ctx.values, ref);
|
|
126
|
+
}
|
|
127
|
+
function fieldLabel(node) {
|
|
128
|
+
return node.label || humanize(node.alias);
|
|
129
|
+
}
|
|
130
|
+
/** Everything a message can use: `:field`, `:value`, `:param1`…, `:params`, `:other` */
|
|
131
|
+
function messageParams(rule, node, value, ctx, opts) {
|
|
132
|
+
const labelFor = opts.labelFor ?? ((p) => humanize(p.split('.').pop() ?? p));
|
|
133
|
+
const shown = rule.params.map((p) => (typeof p === 'string' && p.startsWith('@') ? labelFor(resolveRefPath(p.slice(1), ctx)) : p));
|
|
134
|
+
const params = { params: shown };
|
|
135
|
+
shown.forEach((p, i) => (params[`param${i + 1}`] = p));
|
|
136
|
+
if (rule.name === 'confirmed' || rule.name === 'matches') {
|
|
137
|
+
const ref = rule.params.find((p) => typeof p === 'string');
|
|
138
|
+
params.other = ref ? labelFor(resolveRefPath(ref.replace(/^@/, ''), ctx)) : '';
|
|
139
|
+
}
|
|
140
|
+
return { ...params, value: Array.isArray(value) ? value.join(', ') : value, field: fieldLabel(node), attribute: fieldLabel(node) };
|
|
141
|
+
}
|
|
142
|
+
/** The full path of an `@ref` (the sibling's path when it exists in the group) */
|
|
143
|
+
function resolveRefPath(ref, ctx) {
|
|
144
|
+
const parent = parentPathOf(ctx.path);
|
|
145
|
+
return parent && getPath(ctx.parentValues, ref) !== undefined ? `${parent}.${ref}` : ref;
|
|
146
|
+
}
|
|
147
|
+
/** The message for a failed rule: the rule's own `message`, `errorMessages[rule]`, the built-in one, its label */
|
|
148
|
+
function buildMessage(rule, node, value, ctx, opts) {
|
|
149
|
+
const params = messageParams(rule, node, value, ctx, opts);
|
|
150
|
+
const explicit = rule.message || node.errorMessages[rule.name];
|
|
151
|
+
if (explicit)
|
|
152
|
+
return interpolate(explicit, params);
|
|
153
|
+
const builtin = validationMessages[rule.name];
|
|
154
|
+
if (builtin)
|
|
155
|
+
return interpolate(builtin, params);
|
|
156
|
+
// A custom rule with a checklist label says more than ":field is invalid"
|
|
157
|
+
if (rule.label)
|
|
158
|
+
return interpolate(rule.label, params);
|
|
159
|
+
return interpolate(validationMessages.default, params);
|
|
160
|
+
}
|
|
161
|
+
/** Requirement text for a checklist line (`null` when none is known) */
|
|
162
|
+
function buildRequirement(rule, node, value, ctx, opts) {
|
|
163
|
+
const text = rule.label || node.requirements[rule.name] || requirementMessages[rule.name];
|
|
164
|
+
return text ? interpolate(text, messageParams(rule, node, value, ctx, opts)) : null;
|
|
165
|
+
}
|
|
166
|
+
/** Run one rule. `message` is set when it fails. Unknown rule names pass */
|
|
167
|
+
async function runRule(rule, node, value, ctx, opts) {
|
|
168
|
+
const fn = rule.fn ?? builtinRules[rule.name];
|
|
169
|
+
if (!fn)
|
|
170
|
+
return { passed: true };
|
|
171
|
+
const params = rule.params.map((p) => substitute(p, ctx));
|
|
172
|
+
const result = await fn(value, params, ctx);
|
|
173
|
+
if (result === true || result === undefined)
|
|
174
|
+
return { passed: true };
|
|
175
|
+
const message = typeof result === 'string' ? result : buildMessage(rule, node, value, ctx, opts);
|
|
176
|
+
return { passed: false, message };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Every failing message of a field. `bails` (default `true`) stops at the first
|
|
180
|
+
* one — fields showing `all` errors or a checklist run every rule.
|
|
181
|
+
*/
|
|
182
|
+
export async function validateFieldAll(node, value, values, path, opts = {}) {
|
|
183
|
+
if (node.editable === false)
|
|
184
|
+
return [];
|
|
185
|
+
const ctx = makeContext(values, path, opts);
|
|
186
|
+
const errors = [];
|
|
187
|
+
for (const rule of parseRules(node.rules)) {
|
|
188
|
+
const { passed, message } = await runRule(rule, node, value, ctx, opts);
|
|
189
|
+
if (passed)
|
|
190
|
+
continue;
|
|
191
|
+
errors.push(message);
|
|
192
|
+
if (opts.bails !== false)
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
return errors;
|
|
196
|
+
}
|
|
197
|
+
/** The first failing message of a field (`undefined` when it's valid) */
|
|
198
|
+
export async function validateField(node, value, values, path, opts = {}) {
|
|
199
|
+
const [first] = await validateFieldAll(node, value, values, path, { ...opts, bails: true });
|
|
200
|
+
return first;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Evaluate every rule independently for a checklist. Empty values meet no
|
|
204
|
+
* requirement (rules normally pass on empty values). `required` is left out
|
|
205
|
+
* unless it has a label — it's implied by the required marker.
|
|
206
|
+
*/
|
|
207
|
+
export async function evaluateChecklist(node, value, values, path, opts = {}) {
|
|
208
|
+
const ctx = makeContext(values, path, opts);
|
|
209
|
+
const empty = isEmptyValue(value);
|
|
210
|
+
const items = [];
|
|
211
|
+
for (const rule of parseRules(node.rules)) {
|
|
212
|
+
const implied = IMPLIED.has(rule.name);
|
|
213
|
+
if (implied && !rule.label && !node.requirements[rule.name])
|
|
214
|
+
continue;
|
|
215
|
+
let passed;
|
|
216
|
+
let message;
|
|
217
|
+
if (empty && !implied) {
|
|
218
|
+
passed = false;
|
|
219
|
+
message = buildMessage(rule, node, value, ctx, opts);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
const result = await runRule(rule, node, value, ctx, opts);
|
|
223
|
+
passed = result.passed;
|
|
224
|
+
message = result.message ?? buildMessage(rule, node, value, ctx, opts);
|
|
225
|
+
}
|
|
226
|
+
const label = buildRequirement(rule, node, value, ctx, opts) ?? message;
|
|
227
|
+
items.push({ rule: rule.name, label, passed, message });
|
|
228
|
+
}
|
|
229
|
+
return items;
|
|
230
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { ChecklistItem, FieldNode, FormoConfig, FormoController, FormoDefinition, FormoFields, FormoHandle, FormoOutcome, FormoRowHandle } from '../types';
|
|
2
|
+
import { type FormoLeaf, type TreeItem } from './tree';
|
|
3
|
+
/**
|
|
4
|
+
* The form's state, framework-free. Everything a component needs to render is
|
|
5
|
+
* read from here through per-path subscriptions, so a keystroke in one field
|
|
6
|
+
* re-renders that field only — not the form, not the screen around it.
|
|
7
|
+
*/
|
|
8
|
+
/** Everything in a form that changes */
|
|
9
|
+
export interface FormoState {
|
|
10
|
+
values: Record<string, any>;
|
|
11
|
+
/** The first error per path (groups included; `''` is the form's own) */
|
|
12
|
+
errors: Record<string, string>;
|
|
13
|
+
allErrors: Record<string, string[]>;
|
|
14
|
+
touched: Record<string, boolean>;
|
|
15
|
+
checklists: Record<string, ChecklistItem[]>;
|
|
16
|
+
/** A field's value differs from the initial values, or rows were added / removed */
|
|
17
|
+
dirty: boolean;
|
|
18
|
+
submitting: boolean;
|
|
19
|
+
outcome: FormoOutcome | null;
|
|
20
|
+
}
|
|
21
|
+
export interface FormoStoreOptions {
|
|
22
|
+
initialValues?: Record<string, any>;
|
|
23
|
+
/** Form-wide settings (`{ errorDisplay: 'all' }`) — the definition's own `config` wins over these */
|
|
24
|
+
config?: FormoConfig;
|
|
25
|
+
onSubmit?: (values: Record<string, any>) => unknown;
|
|
26
|
+
onSuccess?: (data: unknown, outcome: FormoOutcome) => void;
|
|
27
|
+
onInvalid?: (errors: Record<string, string>, outcome: FormoOutcome) => void;
|
|
28
|
+
onRejected?: (outcome: FormoOutcome) => void;
|
|
29
|
+
onSettled?: (outcome: FormoOutcome) => void;
|
|
30
|
+
}
|
|
31
|
+
type Listener = () => void;
|
|
32
|
+
export declare class FormoStore {
|
|
33
|
+
definition: FormoDefinition;
|
|
34
|
+
options: FormoStoreOptions;
|
|
35
|
+
root: FieldNode;
|
|
36
|
+
config: FormoConfig;
|
|
37
|
+
baseline: Record<string, any>;
|
|
38
|
+
readonly controller: FormoController;
|
|
39
|
+
values: Record<string, any>;
|
|
40
|
+
errors: Record<string, string>;
|
|
41
|
+
allErrors: Record<string, string[]>;
|
|
42
|
+
touched: Record<string, boolean>;
|
|
43
|
+
checklists: Record<string, ChecklistItem[]>;
|
|
44
|
+
submitting: boolean;
|
|
45
|
+
outcome: FormoOutcome | null;
|
|
46
|
+
private dirtyPaths;
|
|
47
|
+
private structureDirty;
|
|
48
|
+
private stateCache;
|
|
49
|
+
tree: TreeItem[];
|
|
50
|
+
items: Map<string, TreeItem>;
|
|
51
|
+
leaves: FormoLeaf[];
|
|
52
|
+
/** Container path (`''`, a group's path, a row's path) → its items */
|
|
53
|
+
private children;
|
|
54
|
+
/** Fields whose state depends on every value (`editable` functions) */
|
|
55
|
+
private valueDependents;
|
|
56
|
+
/**
|
|
57
|
+
* `namespaces: false` groups: their value is the object their fields live in
|
|
58
|
+
* (not at their own path) — value path → the groups showing it
|
|
59
|
+
*/
|
|
60
|
+
private valueWatchers;
|
|
61
|
+
private checklistPaths;
|
|
62
|
+
private globalChecklists;
|
|
63
|
+
private labelFor;
|
|
64
|
+
private rowKeys;
|
|
65
|
+
private nextKey;
|
|
66
|
+
private listeners;
|
|
67
|
+
private allListeners;
|
|
68
|
+
private pendingNotify;
|
|
69
|
+
private handles;
|
|
70
|
+
private snapshots;
|
|
71
|
+
private fieldsCache;
|
|
72
|
+
private rowsCache;
|
|
73
|
+
private rowCache;
|
|
74
|
+
private checklistRuns;
|
|
75
|
+
private submitLock;
|
|
76
|
+
private configKey;
|
|
77
|
+
private initialValues;
|
|
78
|
+
/** The definition's content (a builder's `toSchema()`), to tell a new object from a new definition */
|
|
79
|
+
private schema;
|
|
80
|
+
constructor(definition: FormoDefinition, options?: FormoStoreOptions);
|
|
81
|
+
/** Listen to one path: its value, error, touched state, checklist — and what's below it structurally */
|
|
82
|
+
subscribe: (path: string, listener: Listener) => (() => void);
|
|
83
|
+
/** Listen to every change (form-wide selectors: `useFormoState`) */
|
|
84
|
+
subscribeAll: (listener: Listener) => (() => void);
|
|
85
|
+
/** A summary when printed / serialized (the store references the whole form) */
|
|
86
|
+
toJSON(): FormoState;
|
|
87
|
+
/** Everything that changes, as one immutable object (a new one after each change) */
|
|
88
|
+
getState: () => FormoState;
|
|
89
|
+
private notify;
|
|
90
|
+
private notifyEverything;
|
|
91
|
+
/**
|
|
92
|
+
* A value changed at `path`: the field, the groups above it, `namespaces: false`
|
|
93
|
+
* groups whose values object contains it, fields depending on every value
|
|
94
|
+
*/
|
|
95
|
+
private notifyValue;
|
|
96
|
+
/**
|
|
97
|
+
* Called while rendering `useFormo`: take a new definition, `config` or
|
|
98
|
+
* `initialValues` into account without notifying (React forbids updates
|
|
99
|
+
* during render) — `flush()` does it after commit. Returns whether anything changed.
|
|
100
|
+
*/
|
|
101
|
+
sync(definition: FormoDefinition, options: FormoStoreOptions): boolean;
|
|
102
|
+
/** Notify what `sync()` changed (after commit) */
|
|
103
|
+
flush(): void;
|
|
104
|
+
private computeBaseline;
|
|
105
|
+
/** Rebuild the tree for the current values (after a structural change) */
|
|
106
|
+
private rebuild;
|
|
107
|
+
/**
|
|
108
|
+
* Rows that are gone (fewer rows after `load()`, `val()`, `reset()`) take their
|
|
109
|
+
* errors and touched state with them — a row added later at that index starts clean
|
|
110
|
+
*/
|
|
111
|
+
private pruneMissingRows;
|
|
112
|
+
private recomputeDirty;
|
|
113
|
+
/** Replace every value (structural changes, load, reset): rebuild, notify everyone */
|
|
114
|
+
private replaceValues;
|
|
115
|
+
/** Keys of a blueprint's rows: the ones we have (rows changed from outside keep theirs), new rows get new ones */
|
|
116
|
+
private keysOf;
|
|
117
|
+
getValue(path: string): unknown;
|
|
118
|
+
/**
|
|
119
|
+
* Set a value. A field's value is written in place of the old one (only the
|
|
120
|
+
* objects along its path are copied) and notifies that field, the groups above
|
|
121
|
+
* it, and fields depending on every value. Anything else (a group, a blueprint's
|
|
122
|
+
* rows) is a structural change.
|
|
123
|
+
*/
|
|
124
|
+
setValue(path: string, value: unknown): void;
|
|
125
|
+
load(next: Record<string, any>): void;
|
|
126
|
+
reset(next?: Record<string, any>): void;
|
|
127
|
+
touch(path: string): void;
|
|
128
|
+
addRow(path: string, rowValues?: Record<string, unknown>): void;
|
|
129
|
+
removeRow(path: string, index: number): void;
|
|
130
|
+
/** Replace the errors, notifying only the paths whose errors changed (unchanged lists keep their identity) */
|
|
131
|
+
private setErrorState;
|
|
132
|
+
setErrors(input: Record<string, unknown>): void;
|
|
133
|
+
/** Validate fields, then group rules; store and return the errors */
|
|
134
|
+
runValidation(): Promise<Record<string, string>>;
|
|
135
|
+
validate(): Promise<boolean>;
|
|
136
|
+
/** After a field changed: its own checklist, and checklists reading other fields */
|
|
137
|
+
private runChecklistsAfter;
|
|
138
|
+
/** Evaluate checklists (async); a result only lands if it's the latest for its path and differs */
|
|
139
|
+
private runChecklists;
|
|
140
|
+
private setStatus;
|
|
141
|
+
submit(handler?: (values: Record<string, any>) => unknown): Promise<boolean>;
|
|
142
|
+
/** The live handle of a path — one object per path; its getters read the current state */
|
|
143
|
+
handleAt(path: string): FormoHandle;
|
|
144
|
+
/** By path (as written, or a server's `phones.0.number`), else by alias — the shallowest match */
|
|
145
|
+
field(pathOrAlias: string): FormoHandle | undefined;
|
|
146
|
+
/** The handles of a container (`''`, a group, a row), by alias — the same object while they're the same */
|
|
147
|
+
fieldsOf(containerPath: string): FormoFields;
|
|
148
|
+
/** A blueprint's rows — the same array while nothing about them changed */
|
|
149
|
+
rowsOf(path: string): FormoRowHandle[];
|
|
150
|
+
/** What a handle shows right now, as a plain object — the same object until something in it changes */
|
|
151
|
+
snapshot(path: string, withValue?: boolean): FormoHandle;
|
|
152
|
+
/** A field's value; a subform's values object; a blueprint's rows */
|
|
153
|
+
valueOf(item: TreeItem): unknown;
|
|
154
|
+
}
|
|
155
|
+
export {};
|