@conform-to/dom 1.0.0-pre.6 → 1.0.0-rc.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 +32 -0
- package/form.d.ts +38 -20
- package/form.js +97 -57
- package/form.mjs +98 -58
- package/formdata.js +2 -3
- package/formdata.mjs +2 -3
- package/index.d.ts +3 -4
- package/index.js +3 -7
- package/index.mjs +3 -4
- package/package.json +1 -1
- package/submission.d.ts +24 -55
- package/submission.js +85 -101
- package/submission.mjs +83 -98
- package/README.md +0 -17
package/form.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHe
|
|
|
2
2
|
import { flatten, formatPaths, getPaths, getValue, setValue, isPlainObject, simplify, getFormData, isPrefix } from './formdata.mjs';
|
|
3
3
|
import { getFormAction, getFormEncType, getFormMethod, isFieldElement, requestSubmit } from './dom.mjs';
|
|
4
4
|
import { generateId, clone, invariant } from './util.mjs';
|
|
5
|
-
import { serialize, setListState, setListValue, setState, getSubmissionContext,
|
|
5
|
+
import { serialize, setListState, setListValue, setState, getSubmissionContext, INTENT, serializeIntent, STATE } from './submission.mjs';
|
|
6
6
|
|
|
7
7
|
function createFormMeta(options, initialized) {
|
|
8
8
|
var _lastResult$initialVa, _options$constraint, _lastResult$state$val, _lastResult$state, _ref;
|
|
@@ -23,8 +23,8 @@ function createFormMeta(options, initialized) {
|
|
|
23
23
|
// We can consider adding a warning if it happens
|
|
24
24
|
error: (_ref = lastResult === null || lastResult === void 0 ? void 0 : lastResult.error) !== null && _ref !== void 0 ? _ref : {}
|
|
25
25
|
};
|
|
26
|
-
if (lastResult !== null && lastResult !== void 0 && lastResult.
|
|
27
|
-
|
|
26
|
+
if (lastResult !== null && lastResult !== void 0 && lastResult.intent) {
|
|
27
|
+
handleIntent(result, lastResult.intent);
|
|
28
28
|
}
|
|
29
29
|
return result;
|
|
30
30
|
}
|
|
@@ -41,24 +41,24 @@ function getDefaultKey(defaultValue, prefix) {
|
|
|
41
41
|
return result;
|
|
42
42
|
}, {});
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
switch (
|
|
46
|
-
case '
|
|
44
|
+
function handleIntent(meta, intent, initialized) {
|
|
45
|
+
switch (intent.type) {
|
|
46
|
+
case 'update':
|
|
47
47
|
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
if (typeof intent.payload.value !== 'undefined') {
|
|
49
|
+
var _intent$payload$name;
|
|
50
|
+
var _name = (_intent$payload$name = intent.payload.name) !== null && _intent$payload$name !== void 0 ? _intent$payload$name : '';
|
|
51
|
+
var value = intent.payload.value;
|
|
52
|
+
updateValue(meta, _name, value);
|
|
53
|
+
}
|
|
52
54
|
break;
|
|
53
55
|
}
|
|
54
56
|
case 'reset':
|
|
55
57
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
updateValue(meta, _name2, _value);
|
|
61
|
-
}
|
|
58
|
+
var _intent$payload$name2;
|
|
59
|
+
var _name2 = (_intent$payload$name2 = intent.payload.name) !== null && _intent$payload$name2 !== void 0 ? _intent$payload$name2 : '';
|
|
60
|
+
var _value = getValue(meta.defaultValue, _name2);
|
|
61
|
+
updateValue(meta, _name2, _value);
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
64
|
case 'insert':
|
|
@@ -68,8 +68,8 @@ function handleControl(meta, control, initialized) {
|
|
|
68
68
|
if (initialized) {
|
|
69
69
|
meta.initialValue = clone(meta.initialValue);
|
|
70
70
|
meta.key = clone(meta.key);
|
|
71
|
-
setListState(meta.key,
|
|
72
|
-
setListValue(meta.initialValue,
|
|
71
|
+
setListState(meta.key, intent, generateId);
|
|
72
|
+
setListValue(meta.initialValue, intent);
|
|
73
73
|
}
|
|
74
74
|
break;
|
|
75
75
|
}
|
|
@@ -145,7 +145,18 @@ function createKeyProxy(key) {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
function createValidProxy(error) {
|
|
148
|
-
return createStateProxy(name =>
|
|
148
|
+
return createStateProxy(name => {
|
|
149
|
+
var keys = Object.keys(error);
|
|
150
|
+
if (name === '') {
|
|
151
|
+
return keys.length === 0;
|
|
152
|
+
}
|
|
153
|
+
for (var key of keys) {
|
|
154
|
+
if (isPrefix(key, name) && typeof error[key] !== 'undefined') {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
});
|
|
149
160
|
}
|
|
150
161
|
function createDirtyProxy(defaultValue, value, shouldDirtyConsider) {
|
|
151
162
|
return createStateProxy(name => JSON.stringify(defaultValue[name]) !== JSON.stringify(value[name], (key, value) => {
|
|
@@ -254,12 +265,12 @@ function createFormContext(options) {
|
|
|
254
265
|
var element = form.elements.namedItem(STATE);
|
|
255
266
|
invariant(element === null || isFieldElement(element), "The input name \"".concat(STATE, "\" is reserved by Conform. Please use another name."));
|
|
256
267
|
if (!element) {
|
|
257
|
-
var
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
form.append(
|
|
262
|
-
return
|
|
268
|
+
var input = document.createElement('input');
|
|
269
|
+
input.type = 'hidden';
|
|
270
|
+
input.name = STATE;
|
|
271
|
+
input.value = '';
|
|
272
|
+
form.append(input);
|
|
273
|
+
return input;
|
|
263
274
|
}
|
|
264
275
|
return element;
|
|
265
276
|
}
|
|
@@ -286,21 +297,22 @@ function createFormContext(options) {
|
|
|
286
297
|
if (typeof (latestOptions === null || latestOptions === void 0 ? void 0 : latestOptions.onValidate) === 'undefined') {
|
|
287
298
|
var _latestOptions$onSubm;
|
|
288
299
|
(_latestOptions$onSubm = latestOptions.onSubmit) === null || _latestOptions$onSubm === void 0 || _latestOptions$onSubm.call(latestOptions, event, context);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
var submission = latestOptions.onValidate({
|
|
303
|
+
form,
|
|
304
|
+
formData,
|
|
305
|
+
submitter
|
|
306
|
+
});
|
|
307
|
+
if (submission.status !== 'success' && submission.error !== null) {
|
|
308
|
+
report(submission.reply());
|
|
289
309
|
} else {
|
|
290
310
|
var _latestOptions$onSubm2;
|
|
291
|
-
var submission = latestOptions.onValidate({
|
|
292
|
-
form,
|
|
293
|
-
formData,
|
|
294
|
-
submitter
|
|
295
|
-
});
|
|
296
|
-
if (submission.status !== 'success' && submission.error !== null) {
|
|
297
|
-
report(submission.reply());
|
|
298
|
-
event.preventDefault();
|
|
299
|
-
}
|
|
300
311
|
(_latestOptions$onSubm2 = latestOptions.onSubmit) === null || _latestOptions$onSubm2 === void 0 || _latestOptions$onSubm2.call(latestOptions, event, _objectSpread2(_objectSpread2({}, context), {}, {
|
|
301
312
|
submission
|
|
302
313
|
}));
|
|
303
314
|
}
|
|
315
|
+
return submission;
|
|
304
316
|
}
|
|
305
317
|
function resolveTarget(event) {
|
|
306
318
|
var form = getFormElement();
|
|
@@ -318,7 +330,7 @@ function createFormContext(options) {
|
|
|
318
330
|
var validated = meta.validated[element.name];
|
|
319
331
|
return validated ? shouldRevalidate === eventName : shouldValidate === eventName;
|
|
320
332
|
}
|
|
321
|
-
function
|
|
333
|
+
function onInput(event) {
|
|
322
334
|
var element = resolveTarget(event);
|
|
323
335
|
if (!element || !element.form) {
|
|
324
336
|
return;
|
|
@@ -330,21 +342,27 @@ function createFormContext(options) {
|
|
|
330
342
|
value: result.payload
|
|
331
343
|
}));
|
|
332
344
|
} else {
|
|
333
|
-
dispatch(
|
|
334
|
-
|
|
335
|
-
|
|
345
|
+
dispatch({
|
|
346
|
+
type: 'validate',
|
|
347
|
+
payload: {
|
|
348
|
+
name: element.name
|
|
349
|
+
}
|
|
350
|
+
});
|
|
336
351
|
}
|
|
337
352
|
}
|
|
338
|
-
function
|
|
353
|
+
function onBlur(event) {
|
|
339
354
|
var element = resolveTarget(event);
|
|
340
355
|
if (!element || event.defaultPrevented || !willValidate(element, 'onBlur')) {
|
|
341
356
|
return;
|
|
342
357
|
}
|
|
343
|
-
dispatch(
|
|
344
|
-
|
|
345
|
-
|
|
358
|
+
dispatch({
|
|
359
|
+
type: 'validate',
|
|
360
|
+
payload: {
|
|
361
|
+
name: element.name
|
|
362
|
+
}
|
|
363
|
+
});
|
|
346
364
|
}
|
|
347
|
-
function
|
|
365
|
+
function onReset(event) {
|
|
348
366
|
var element = getFormElement();
|
|
349
367
|
if (event.type !== 'reset' || event.target !== element || event.defaultPrevented) {
|
|
350
368
|
return;
|
|
@@ -372,8 +390,8 @@ function createFormContext(options) {
|
|
|
372
390
|
error,
|
|
373
391
|
validated: (_result$state$validat = (_result$state = result.state) === null || _result$state === void 0 ? void 0 : _result$state.validated) !== null && _result$state$validat !== void 0 ? _result$state$validat : {}
|
|
374
392
|
});
|
|
375
|
-
if (result.
|
|
376
|
-
|
|
393
|
+
if (result.intent) {
|
|
394
|
+
handleIntent(update, result.intent, true);
|
|
377
395
|
}
|
|
378
396
|
updateFormMeta(update);
|
|
379
397
|
if (result.status === 'error') {
|
|
@@ -385,7 +403,7 @@ function createFormContext(options) {
|
|
|
385
403
|
}
|
|
386
404
|
}
|
|
387
405
|
}
|
|
388
|
-
function
|
|
406
|
+
function onUpdate(options) {
|
|
389
407
|
var currentFormId = latestOptions.formId;
|
|
390
408
|
var currentResult = latestOptions.lastResult;
|
|
391
409
|
|
|
@@ -393,7 +411,7 @@ function createFormContext(options) {
|
|
|
393
411
|
Object.assign(latestOptions, options);
|
|
394
412
|
if (latestOptions.formId !== currentFormId) {
|
|
395
413
|
getFormElement().reset();
|
|
396
|
-
} else if (
|
|
414
|
+
} else if (options.lastResult && options.lastResult !== currentResult) {
|
|
397
415
|
report(options.lastResult);
|
|
398
416
|
}
|
|
399
417
|
}
|
|
@@ -410,10 +428,10 @@ function createFormContext(options) {
|
|
|
410
428
|
function getState() {
|
|
411
429
|
return state;
|
|
412
430
|
}
|
|
413
|
-
function dispatch(
|
|
431
|
+
function dispatch(intent) {
|
|
414
432
|
var form = getFormElement();
|
|
415
433
|
var submitter = document.createElement('button');
|
|
416
|
-
var buttonProps = getControlButtonProps(
|
|
434
|
+
var buttonProps = getControlButtonProps(intent);
|
|
417
435
|
submitter.name = buttonProps.name;
|
|
418
436
|
submitter.value = buttonProps.value;
|
|
419
437
|
submitter.hidden = true;
|
|
@@ -422,25 +440,47 @@ function createFormContext(options) {
|
|
|
422
440
|
requestSubmit(form, submitter);
|
|
423
441
|
form === null || form === void 0 || form.removeChild(submitter);
|
|
424
442
|
}
|
|
425
|
-
function getControlButtonProps(
|
|
443
|
+
function getControlButtonProps(intent) {
|
|
426
444
|
return {
|
|
427
|
-
name:
|
|
428
|
-
value:
|
|
445
|
+
name: INTENT,
|
|
446
|
+
value: serializeIntent(intent),
|
|
429
447
|
form: latestOptions.formId,
|
|
430
448
|
formNoValidate: true
|
|
431
449
|
};
|
|
432
450
|
}
|
|
451
|
+
function createFormControl(type) {
|
|
452
|
+
var control = function control() {
|
|
453
|
+
var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
454
|
+
return dispatch({
|
|
455
|
+
type,
|
|
456
|
+
payload
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
return Object.assign(control, {
|
|
460
|
+
getButtonProps() {
|
|
461
|
+
var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
462
|
+
return getControlButtonProps({
|
|
463
|
+
type,
|
|
464
|
+
payload
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
433
469
|
return {
|
|
434
470
|
get formId() {
|
|
435
471
|
return latestOptions.formId;
|
|
436
472
|
},
|
|
437
473
|
submit,
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
474
|
+
onReset,
|
|
475
|
+
onInput,
|
|
476
|
+
onBlur,
|
|
477
|
+
onUpdate,
|
|
478
|
+
validate: createFormControl('validate'),
|
|
479
|
+
reset: createFormControl('reset'),
|
|
480
|
+
update: createFormControl('update'),
|
|
481
|
+
insert: createFormControl('insert'),
|
|
482
|
+
remove: createFormControl('remove'),
|
|
483
|
+
reorder: createFormControl('reorder'),
|
|
444
484
|
subscribe,
|
|
445
485
|
getState,
|
|
446
486
|
getSerializedState
|
package/formdata.js
CHANGED
|
@@ -137,9 +137,8 @@ function isFile(obj) {
|
|
|
137
137
|
|
|
138
138
|
function simplify(value) {
|
|
139
139
|
if (isPlainObject(value)) {
|
|
140
|
-
var obj = Object.
|
|
141
|
-
var [key
|
|
142
|
-
var data = simplify(value);
|
|
140
|
+
var obj = Object.keys(value).sort().reduce((result, key) => {
|
|
141
|
+
var data = simplify(value[key]);
|
|
143
142
|
if (typeof data !== 'undefined') {
|
|
144
143
|
result[key] = data;
|
|
145
144
|
}
|
package/formdata.mjs
CHANGED
|
@@ -133,9 +133,8 @@ function isFile(obj) {
|
|
|
133
133
|
|
|
134
134
|
function simplify(value) {
|
|
135
135
|
if (isPlainObject(value)) {
|
|
136
|
-
var obj = Object.
|
|
137
|
-
var [key
|
|
138
|
-
var data = simplify(value);
|
|
136
|
+
var obj = Object.keys(value).sort().reduce((result, key) => {
|
|
137
|
+
var data = simplify(value[key]);
|
|
139
138
|
if (typeof data !== 'undefined') {
|
|
140
139
|
result[key] = data;
|
|
141
140
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { type UnionKeyof, type UnionKeyType, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext, } from './form';
|
|
2
|
-
export { type FieldElement, isFieldElement
|
|
3
|
-
export {
|
|
4
|
-
export { type Submission, type SubmissionResult, type FormControl, CONTROL, STATE, control, serializeControl, parse, } from './submission';
|
|
1
|
+
export { type UnionKeyof, type UnionKeyType, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, } from './form';
|
|
2
|
+
export { type FieldElement, isFieldElement } from './dom';
|
|
3
|
+
export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
|
|
5
4
|
export { getPaths, formatPaths, isPrefix } from './formdata';
|
package/index.js
CHANGED
|
@@ -4,21 +4,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var form = require('./form.js');
|
|
6
6
|
var dom = require('./dom.js');
|
|
7
|
-
var util = require('./util.js');
|
|
8
7
|
var submission = require('./submission.js');
|
|
9
8
|
var formdata = require('./formdata.js');
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
exports.
|
|
12
|
+
exports.unstable_createFormContext = form.createFormContext;
|
|
14
13
|
exports.isFieldElement = dom.isFieldElement;
|
|
15
|
-
exports.
|
|
16
|
-
exports.invariant = util.invariant;
|
|
17
|
-
exports.CONTROL = submission.CONTROL;
|
|
14
|
+
exports.INTENT = submission.INTENT;
|
|
18
15
|
exports.STATE = submission.STATE;
|
|
19
|
-
exports.control = submission.control;
|
|
20
16
|
exports.parse = submission.parse;
|
|
21
|
-
exports.
|
|
17
|
+
exports.serializeIntent = submission.serializeIntent;
|
|
22
18
|
exports.formatPaths = formdata.formatPaths;
|
|
23
19
|
exports.getPaths = formdata.getPaths;
|
|
24
20
|
exports.isPrefix = formdata.isPrefix;
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { createFormContext } from './form.mjs';
|
|
2
|
-
export { isFieldElement
|
|
3
|
-
export {
|
|
4
|
-
export { CONTROL, STATE, control, parse, serializeControl } from './submission.mjs';
|
|
1
|
+
export { createFormContext as unstable_createFormContext } from './form.mjs';
|
|
2
|
+
export { isFieldElement } from './dom.mjs';
|
|
3
|
+
export { INTENT, STATE, parse, serializeIntent } from './submission.mjs';
|
|
5
4
|
export { formatPaths, getPaths, isPrefix } from './formdata.mjs';
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A set of opinionated helpers built on top of the Constraint Validation API",
|
|
4
4
|
"homepage": "https://conform.guide",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "1.0.0-
|
|
6
|
+
"version": "1.0.0-rc.0",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
package/submission.d.ts
CHANGED
|
@@ -2,18 +2,18 @@ import type { DefaultValue, FieldName, FormValue } from './form';
|
|
|
2
2
|
export type SubmissionState = {
|
|
3
3
|
validated: Record<string, boolean>;
|
|
4
4
|
};
|
|
5
|
-
export type SubmissionContext<Value = null, FormError =
|
|
6
|
-
|
|
5
|
+
export type SubmissionContext<Value = null, FormError = string[]> = {
|
|
6
|
+
intent: Intent | null;
|
|
7
7
|
payload: Record<string, unknown>;
|
|
8
8
|
fields: string[];
|
|
9
9
|
value?: Value;
|
|
10
10
|
error?: Record<string, FormError | null> | null;
|
|
11
11
|
state: SubmissionState;
|
|
12
12
|
};
|
|
13
|
-
export type Submission<Schema, FormError = string[],
|
|
13
|
+
export type Submission<Schema, FormError = string[], FormValue = Schema> = {
|
|
14
14
|
status: 'success';
|
|
15
15
|
payload: Record<string, unknown>;
|
|
16
|
-
value:
|
|
16
|
+
value: FormValue;
|
|
17
17
|
reply(options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
|
|
18
18
|
} | {
|
|
19
19
|
status: 'error' | undefined;
|
|
@@ -23,7 +23,7 @@ export type Submission<Schema, FormError = string[], Value = Schema> = {
|
|
|
23
23
|
};
|
|
24
24
|
export type SubmissionResult<FormError = string[]> = {
|
|
25
25
|
status?: 'error' | 'success';
|
|
26
|
-
|
|
26
|
+
intent?: Intent;
|
|
27
27
|
initialValue?: Record<string, unknown> | null;
|
|
28
28
|
error?: Record<string, FormError | null>;
|
|
29
29
|
state?: SubmissionState;
|
|
@@ -38,26 +38,26 @@ export type ReplyOptions<FormError> = {
|
|
|
38
38
|
/**
|
|
39
39
|
* The name to be used when submitting a form control
|
|
40
40
|
*/
|
|
41
|
-
export declare const
|
|
41
|
+
export declare const INTENT = "__intent__";
|
|
42
42
|
/**
|
|
43
43
|
* The name to be used when submitting a state
|
|
44
44
|
*/
|
|
45
45
|
export declare const STATE = "__state__";
|
|
46
46
|
export declare function getSubmissionContext(body: FormData | URLSearchParams): SubmissionContext;
|
|
47
47
|
export declare function parse<FormValue, FormError>(payload: FormData | URLSearchParams, options: {
|
|
48
|
-
resolve: (payload: Record<string, any>,
|
|
48
|
+
resolve: (payload: Record<string, any>, intent: Intent | null) => {
|
|
49
49
|
value?: FormValue;
|
|
50
50
|
error?: Record<string, FormError | null> | null;
|
|
51
51
|
};
|
|
52
52
|
}): Submission<FormValue, FormError>;
|
|
53
53
|
export declare function parse<FormValue, FormError>(payload: FormData | URLSearchParams, options: {
|
|
54
|
-
resolve: (payload: Record<string, any>,
|
|
54
|
+
resolve: (payload: Record<string, any>, intent: Intent | null) => Promise<{
|
|
55
55
|
value?: FormValue;
|
|
56
56
|
error?: Record<string, FormError | null> | null;
|
|
57
57
|
}>;
|
|
58
58
|
}): Promise<Submission<FormValue, FormError>>;
|
|
59
59
|
export declare function parse<FormValue, FormError>(payload: FormData | URLSearchParams, options: {
|
|
60
|
-
resolve: (payload: Record<string, any>,
|
|
60
|
+
resolve: (payload: Record<string, any>, intent: Intent | null) => {
|
|
61
61
|
value?: FormValue;
|
|
62
62
|
error?: Record<string, FormError | null> | null;
|
|
63
63
|
} | Promise<{
|
|
@@ -67,36 +67,34 @@ export declare function parse<FormValue, FormError>(payload: FormData | URLSearc
|
|
|
67
67
|
}): Submission<FormValue, FormError> | Promise<Submission<FormValue, FormError>>;
|
|
68
68
|
export declare function createSubmission<FormValue, FormError>(context: SubmissionContext<FormValue, FormError>): Submission<FormValue, FormError>;
|
|
69
69
|
export declare function replySubmission<FormError>(context: SubmissionContext<unknown, FormError>, options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
|
|
70
|
-
export type
|
|
70
|
+
export type ValidateIntent<Schema = any> = {
|
|
71
71
|
type: 'validate';
|
|
72
72
|
payload: {
|
|
73
73
|
name?: FieldName<Schema>;
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
-
export type
|
|
76
|
+
export type ResetIntent<Schema = any> = {
|
|
77
77
|
type: 'reset';
|
|
78
78
|
payload: {
|
|
79
79
|
name?: FieldName<Schema>;
|
|
80
|
-
value?: boolean;
|
|
81
|
-
validated?: boolean;
|
|
82
80
|
};
|
|
83
81
|
};
|
|
84
|
-
export type
|
|
85
|
-
type: '
|
|
82
|
+
export type UpdateIntent<Schema = unknown> = {
|
|
83
|
+
type: 'update';
|
|
86
84
|
payload: {
|
|
87
|
-
name
|
|
88
|
-
value
|
|
85
|
+
name?: FieldName<Schema>;
|
|
86
|
+
value?: NonNullable<DefaultValue<Schema>>;
|
|
89
87
|
validated?: boolean;
|
|
90
88
|
};
|
|
91
89
|
};
|
|
92
|
-
export type
|
|
90
|
+
export type RemoveIntent<Schema extends Array<any> = any> = {
|
|
93
91
|
type: 'remove';
|
|
94
92
|
payload: {
|
|
95
93
|
name: FieldName<Schema>;
|
|
96
94
|
index: number;
|
|
97
95
|
};
|
|
98
96
|
};
|
|
99
|
-
export type
|
|
97
|
+
export type InsertIntent<Schema extends Array<any> = any> = {
|
|
100
98
|
type: 'insert';
|
|
101
99
|
payload: {
|
|
102
100
|
name: FieldName<Schema>;
|
|
@@ -104,7 +102,7 @@ export type InsertControl<Schema extends Array<any> = any> = {
|
|
|
104
102
|
index?: number;
|
|
105
103
|
};
|
|
106
104
|
};
|
|
107
|
-
export type
|
|
105
|
+
export type ReorderIntent<Schema extends Array<any> = any> = {
|
|
108
106
|
type: 'reorder';
|
|
109
107
|
payload: {
|
|
110
108
|
name: FieldName<Schema>;
|
|
@@ -112,40 +110,11 @@ export type ReorderControl<Schema extends Array<any> = any> = {
|
|
|
112
110
|
to: number;
|
|
113
111
|
};
|
|
114
112
|
};
|
|
115
|
-
export type
|
|
116
|
-
export declare function
|
|
117
|
-
export declare function
|
|
118
|
-
export declare function updateList(list: unknown,
|
|
119
|
-
export declare function setListValue(data: Record<string, unknown>,
|
|
113
|
+
export type Intent<Schema = unknown> = ValidateIntent<Schema> | ResetIntent<Schema> | UpdateIntent<Schema> | ReorderIntent<Schema extends Array<any> ? Schema : any> | RemoveIntent<Schema extends Array<any> ? Schema : any> | InsertIntent<Schema extends Array<any> ? Schema : any>;
|
|
114
|
+
export declare function getIntent(serializedIntent: string | null | undefined): Intent | null;
|
|
115
|
+
export declare function serializeIntent<Schema>(intent: Intent<Schema>): string;
|
|
116
|
+
export declare function updateList(list: unknown, intent: InsertIntent | RemoveIntent | ReorderIntent): void;
|
|
117
|
+
export declare function setListValue(data: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent): void;
|
|
120
118
|
export declare function setState(state: Record<string, unknown>, name: string, valueFn: (value: unknown) => unknown): void;
|
|
121
|
-
export declare function setListState(state: Record<string, unknown>,
|
|
119
|
+
export declare function setListState(state: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent, getDefaultValue?: () => string): void;
|
|
122
120
|
export declare function serialize<Schema>(defaultValue: DefaultValue<Schema>): FormValue<Schema>;
|
|
123
|
-
export declare const control: {
|
|
124
|
-
reset: <Schema>(payload?: {
|
|
125
|
-
name?: FieldName<Schema> | undefined;
|
|
126
|
-
value?: boolean | undefined;
|
|
127
|
-
validated?: boolean | undefined;
|
|
128
|
-
} | undefined) => ResetControl<Schema>;
|
|
129
|
-
validate: <Schema_1>(payload?: {
|
|
130
|
-
name?: FieldName<Schema_1> | undefined;
|
|
131
|
-
} | undefined) => ValidateControl<Schema_1>;
|
|
132
|
-
replace: <Schema_2>(payload: {
|
|
133
|
-
name: FieldName<Schema_2>;
|
|
134
|
-
value: NonNullable<DefaultValue<Schema_2>>;
|
|
135
|
-
validated?: boolean | undefined;
|
|
136
|
-
}) => ReplaceControl<Schema_2>;
|
|
137
|
-
reorder: <Schema_3>(payload: {
|
|
138
|
-
name: FieldName<Schema_3 extends any[] ? Schema_3 : any>;
|
|
139
|
-
from: number;
|
|
140
|
-
to: number;
|
|
141
|
-
}) => ReorderControl<Schema_3 extends any[] ? Schema_3 : any>;
|
|
142
|
-
remove: <Schema_4>(payload: {
|
|
143
|
-
name: FieldName<Schema_4 extends any[] ? Schema_4 : any>;
|
|
144
|
-
index: number;
|
|
145
|
-
}) => RemoveControl<Schema_4 extends any[] ? Schema_4 : any>;
|
|
146
|
-
insert: <Schema_5>(payload: {
|
|
147
|
-
name: FieldName<Schema_5 extends any[] ? Schema_5 : any>;
|
|
148
|
-
defaultValue?: ((Schema_5 extends any[] ? Schema_5 : any) extends infer T ? T extends (Schema_5 extends any[] ? Schema_5 : any) ? T extends (infer Item)[] ? DefaultValue<Item> : never : never : never) | undefined;
|
|
149
|
-
index?: number | undefined;
|
|
150
|
-
}) => InsertControl<Schema_5 extends any[] ? Schema_5 : any>;
|
|
151
|
-
};
|