@conform-to/dom 0.1.1 → 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.
- package/README.md +4 -4
- package/_virtual/_rollupPluginBabelHelpers.js +47 -0
- package/index.d.ts +47 -24
- package/index.js +83 -45
- package/module/_virtual/_rollupPluginBabelHelpers.js +42 -0
- package/module/index.js +81 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
## API Reference
|
|
6
6
|
|
|
7
|
-
- [
|
|
8
|
-
- [
|
|
7
|
+
- [getControlButtonProps](#getControlButtonProps)
|
|
8
|
+
- [getFieldProps](#getFieldProps)
|
|
9
9
|
- [getFieldElements](#getFieldElements)
|
|
10
10
|
- [getName](#getName)
|
|
11
11
|
- [getPaths](#getPaths)
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
- [setFieldState](#setFieldState)
|
|
18
18
|
- [transform](#transform)
|
|
19
19
|
|
|
20
|
-
###
|
|
20
|
+
### getControlButtonProps
|
|
21
21
|
|
|
22
|
-
###
|
|
22
|
+
### getFieldProps
|
|
23
23
|
|
|
24
24
|
### getFieldElements
|
|
25
25
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function ownKeys(object, enumerableOnly) {
|
|
6
|
+
var keys = Object.keys(object);
|
|
7
|
+
|
|
8
|
+
if (Object.getOwnPropertySymbols) {
|
|
9
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
10
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
11
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
12
|
+
})), keys.push.apply(keys, symbols);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return keys;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _objectSpread2(target) {
|
|
19
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
20
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
21
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
22
|
+
_defineProperty(target, key, source[key]);
|
|
23
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
24
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return target;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _defineProperty(obj, key, value) {
|
|
32
|
+
if (key in obj) {
|
|
33
|
+
Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
obj[key] = value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.defineProperty = _defineProperty;
|
|
47
|
+
exports.objectSpread2 = _objectSpread2;
|
package/index.d.ts
CHANGED
|
@@ -2,18 +2,17 @@ export declare type Constraint = {
|
|
|
2
2
|
required?: boolean;
|
|
3
3
|
minLength?: number;
|
|
4
4
|
maxLength?: number;
|
|
5
|
-
min?: string;
|
|
6
|
-
max?: string;
|
|
5
|
+
min?: string | number;
|
|
6
|
+
max?: string | number;
|
|
7
7
|
step?: string;
|
|
8
8
|
multiple?: boolean;
|
|
9
9
|
pattern?: string;
|
|
10
10
|
};
|
|
11
|
-
export interface
|
|
11
|
+
export interface FieldProps<Type = any> extends Constraint {
|
|
12
12
|
name: string;
|
|
13
|
-
|
|
13
|
+
defaultValue?: FieldsetData<Type, string>;
|
|
14
14
|
error?: FieldsetData<Type, string>;
|
|
15
15
|
form?: string;
|
|
16
|
-
constraint?: Constraint;
|
|
17
16
|
}
|
|
18
17
|
export declare type Schema<Type extends Record<string, any>> = {
|
|
19
18
|
fields: {
|
|
@@ -24,7 +23,7 @@ export declare type Schema<Type extends Record<string, any>> = {
|
|
|
24
23
|
/**
|
|
25
24
|
* Data structure of the form value
|
|
26
25
|
*/
|
|
27
|
-
export declare type FieldsetData<Type, Value> = Type extends string | number | Date | undefined ? Value : Type extends Array<infer InnerType> ? Array<FieldsetData<InnerType, Value>> : Type extends Object ? {
|
|
26
|
+
export declare type FieldsetData<Type, Value> = Type extends string | number | Date | boolean | undefined ? Value : Type extends Array<infer InnerType> ? Array<FieldsetData<InnerType, Value>> : Type extends Object ? {
|
|
28
27
|
[Key in keyof Type]?: FieldsetData<Type[Key], Value>;
|
|
29
28
|
} : unknown;
|
|
30
29
|
/**
|
|
@@ -36,41 +35,65 @@ export declare type FieldsetElement = HTMLFormElement | HTMLFieldSetElement;
|
|
|
36
35
|
* Element type that might be a candiate of Constraint Validation
|
|
37
36
|
*/
|
|
38
37
|
export declare type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLButtonElement;
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
export interface FormState<T> {
|
|
39
|
+
value: FieldsetData<T, string>;
|
|
40
|
+
error: FieldsetData<T, string>;
|
|
41
|
+
}
|
|
42
|
+
export declare type Submission<T extends Record<string, unknown>> = {
|
|
43
|
+
state: 'modified';
|
|
44
|
+
form: FormState<T>;
|
|
43
45
|
} | {
|
|
44
46
|
state: 'rejected';
|
|
45
|
-
|
|
46
|
-
error: FieldsetData<T, string>;
|
|
47
|
+
form: FormState<T>;
|
|
47
48
|
} | {
|
|
48
49
|
state: 'accepted';
|
|
49
|
-
|
|
50
|
+
data: T;
|
|
51
|
+
form: FormState<T>;
|
|
50
52
|
};
|
|
53
|
+
export interface ControlButtonProps {
|
|
54
|
+
type: 'submit';
|
|
55
|
+
name: string;
|
|
56
|
+
value: string;
|
|
57
|
+
formNoValidate: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface ControlAction<T = unknown> {
|
|
60
|
+
prepend: {
|
|
61
|
+
defaultValue: T;
|
|
62
|
+
};
|
|
63
|
+
append: {
|
|
64
|
+
defaultValue: T;
|
|
65
|
+
};
|
|
66
|
+
replace: {
|
|
67
|
+
defaultValue: T;
|
|
68
|
+
index: number;
|
|
69
|
+
};
|
|
70
|
+
remove: {
|
|
71
|
+
index: number;
|
|
72
|
+
};
|
|
73
|
+
reorder: {
|
|
74
|
+
from: number;
|
|
75
|
+
to: number;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
51
78
|
export declare function isFieldsetElement(element: unknown): element is FieldsetElement;
|
|
52
79
|
export declare function isFieldElement(element: unknown): element is FieldElement;
|
|
53
80
|
export declare function setFieldState(field: unknown, state: {
|
|
54
81
|
touched: boolean;
|
|
55
82
|
}): void;
|
|
56
83
|
export declare function reportValidity(fieldset: FieldsetElement): boolean;
|
|
57
|
-
export declare function
|
|
84
|
+
export declare function getFieldProps<Type extends Record<string, any>>(schema: Schema<Type>, options: {
|
|
58
85
|
name?: string;
|
|
59
86
|
form?: string;
|
|
60
|
-
|
|
87
|
+
defaultValue?: FieldsetData<Type, string>;
|
|
61
88
|
error?: FieldsetData<Type, string>;
|
|
62
89
|
}): {
|
|
63
|
-
[Key in keyof Type]-?:
|
|
90
|
+
[Key in keyof Type]-?: FieldProps<Type[Key]>;
|
|
64
91
|
};
|
|
65
92
|
export declare function shouldSkipValidate(event: SubmitEvent): boolean;
|
|
66
93
|
export declare function getPaths(name?: string): Array<string | number>;
|
|
67
94
|
export declare function getName(paths: Array<string | number>): string;
|
|
68
|
-
export declare function transform(entries: Array<[string, FormDataEntryValue]> | Iterable<[string, FormDataEntryValue]>): unknown
|
|
69
|
-
export declare function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
value: string;
|
|
73
|
-
formNoValidate: boolean;
|
|
74
|
-
};
|
|
75
|
-
export declare function parse(payload: FormData | URLSearchParams): FormResult<unknown>;
|
|
95
|
+
export declare function transform(entries: Array<[string, FormDataEntryValue]> | Iterable<[string, FormDataEntryValue]>): Record<string, unknown>;
|
|
96
|
+
export declare function getControlButtonProps<Action extends keyof ControlAction, Payload extends ControlAction[Action]>(name: string, action: Action, payload: Payload): ControlButtonProps;
|
|
97
|
+
export declare function applyControlCommand<Type, Action extends keyof ControlAction<Type>, Payload extends ControlAction<Type>[Action]>(list: Array<Type>, action: Action | string, payload: Payload): Array<Type>;
|
|
98
|
+
export declare function parse(payload: FormData | URLSearchParams): Submission<Record<string, unknown>>;
|
|
76
99
|
export declare function getFieldElements(fieldset: FieldsetElement, key: string): FieldElement[];
|
package/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Data structure of the form value
|
|
7
9
|
*/
|
|
@@ -51,21 +53,22 @@ function reportValidity(fieldset) {
|
|
|
51
53
|
|
|
52
54
|
return isValid;
|
|
53
55
|
}
|
|
54
|
-
function
|
|
56
|
+
function getFieldProps(schema, options) {
|
|
55
57
|
var result = {};
|
|
56
58
|
|
|
57
59
|
for (var key of Object.keys(schema.fields)) {
|
|
58
|
-
var _options$
|
|
60
|
+
var _options$defaultValue, _options$error;
|
|
59
61
|
|
|
60
62
|
var constraint = schema.fields[key];
|
|
61
|
-
|
|
63
|
+
|
|
64
|
+
var props = _rollupPluginBabelHelpers.objectSpread2({
|
|
62
65
|
name: options.name ? "".concat(options.name, ".").concat(key) : key,
|
|
63
66
|
form: options.form,
|
|
64
|
-
|
|
65
|
-
error: (_options$error = options.error) === null || _options$error === void 0 ? void 0 : _options$error[key]
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
result[key] =
|
|
67
|
+
defaultValue: (_options$defaultValue = options.defaultValue) === null || _options$defaultValue === void 0 ? void 0 : _options$defaultValue[key],
|
|
68
|
+
error: (_options$error = options.error) === null || _options$error === void 0 ? void 0 : _options$error[key]
|
|
69
|
+
}, constraint);
|
|
70
|
+
|
|
71
|
+
result[key] = props;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
return result;
|
|
@@ -143,14 +146,65 @@ function transform(entries) {
|
|
|
143
146
|
|
|
144
147
|
return result;
|
|
145
148
|
}
|
|
146
|
-
function
|
|
149
|
+
function getControlButtonProps(name, action, payload) {
|
|
147
150
|
return {
|
|
148
151
|
type: 'submit',
|
|
149
152
|
name: '__conform__',
|
|
150
|
-
value: [name, action, JSON.stringify(
|
|
153
|
+
value: [name, action, JSON.stringify(payload)].join('::'),
|
|
151
154
|
formNoValidate: true
|
|
152
155
|
};
|
|
153
156
|
}
|
|
157
|
+
function applyControlCommand(list, action, payload) {
|
|
158
|
+
switch (action) {
|
|
159
|
+
case 'prepend':
|
|
160
|
+
{
|
|
161
|
+
var {
|
|
162
|
+
defaultValue
|
|
163
|
+
} = payload;
|
|
164
|
+
list.unshift(defaultValue);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
case 'append':
|
|
169
|
+
{
|
|
170
|
+
var {
|
|
171
|
+
defaultValue: _defaultValue
|
|
172
|
+
} = payload;
|
|
173
|
+
list.push(_defaultValue);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
case 'replace':
|
|
178
|
+
{
|
|
179
|
+
var {
|
|
180
|
+
defaultValue: _defaultValue2,
|
|
181
|
+
index: _index
|
|
182
|
+
} = payload;
|
|
183
|
+
list.splice(_index, 1, _defaultValue2);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
case 'remove':
|
|
188
|
+
var {
|
|
189
|
+
index
|
|
190
|
+
} = payload;
|
|
191
|
+
list.splice(index, 1);
|
|
192
|
+
break;
|
|
193
|
+
|
|
194
|
+
case 'reorder':
|
|
195
|
+
var {
|
|
196
|
+
from,
|
|
197
|
+
to
|
|
198
|
+
} = payload;
|
|
199
|
+
list.splice(to, 0, ...list.splice(from, 1));
|
|
200
|
+
break;
|
|
201
|
+
|
|
202
|
+
default:
|
|
203
|
+
throw new Error('Invalid action found');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return list;
|
|
207
|
+
}
|
|
154
208
|
function parse(payload) {
|
|
155
209
|
var command = payload.get('__conform__');
|
|
156
210
|
|
|
@@ -181,52 +235,35 @@ function parse(payload) {
|
|
|
181
235
|
throw new Error('');
|
|
182
236
|
}
|
|
183
237
|
|
|
184
|
-
|
|
185
|
-
case 'prepend':
|
|
186
|
-
{
|
|
187
|
-
var initialValue = JSON.parse(json);
|
|
188
|
-
list.unshift(initialValue);
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
case 'append':
|
|
193
|
-
{
|
|
194
|
-
var _initialValue = JSON.parse(json);
|
|
195
|
-
|
|
196
|
-
list.push(_initialValue);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
case 'remove':
|
|
201
|
-
var {
|
|
202
|
-
index
|
|
203
|
-
} = JSON.parse(json);
|
|
204
|
-
list.splice(index, 1);
|
|
205
|
-
break;
|
|
206
|
-
|
|
207
|
-
default:
|
|
208
|
-
throw new Error('Invalid action found; Only `prepend`, `append` and `remove` is accepted');
|
|
209
|
-
}
|
|
238
|
+
applyControlCommand(list, action, JSON.parse(json));
|
|
210
239
|
} catch (e) {
|
|
211
240
|
return {
|
|
212
241
|
state: 'rejected',
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
242
|
+
form: {
|
|
243
|
+
value,
|
|
244
|
+
error: {
|
|
245
|
+
__conform__: e instanceof Error ? e.message : 'Something went wrong'
|
|
246
|
+
}
|
|
216
247
|
}
|
|
217
248
|
};
|
|
218
249
|
}
|
|
219
250
|
|
|
220
251
|
return {
|
|
221
|
-
state: '
|
|
222
|
-
|
|
223
|
-
|
|
252
|
+
state: 'modified',
|
|
253
|
+
form: {
|
|
254
|
+
value,
|
|
255
|
+
error: {}
|
|
256
|
+
}
|
|
224
257
|
};
|
|
225
258
|
}
|
|
226
259
|
|
|
227
260
|
return {
|
|
228
261
|
state: 'accepted',
|
|
229
|
-
value
|
|
262
|
+
data: value,
|
|
263
|
+
form: {
|
|
264
|
+
value,
|
|
265
|
+
error: {}
|
|
266
|
+
}
|
|
230
267
|
};
|
|
231
268
|
}
|
|
232
269
|
function getFieldElements(fieldset, key) {
|
|
@@ -238,9 +275,10 @@ function getFieldElements(fieldset, key) {
|
|
|
238
275
|
return nodes.filter(isFieldElement);
|
|
239
276
|
}
|
|
240
277
|
|
|
241
|
-
exports.
|
|
242
|
-
exports.
|
|
278
|
+
exports.applyControlCommand = applyControlCommand;
|
|
279
|
+
exports.getControlButtonProps = getControlButtonProps;
|
|
243
280
|
exports.getFieldElements = getFieldElements;
|
|
281
|
+
exports.getFieldProps = getFieldProps;
|
|
244
282
|
exports.getName = getName;
|
|
245
283
|
exports.getPaths = getPaths;
|
|
246
284
|
exports.isFieldElement = isFieldElement;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) {
|
|
2
|
+
var keys = Object.keys(object);
|
|
3
|
+
|
|
4
|
+
if (Object.getOwnPropertySymbols) {
|
|
5
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
6
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
7
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
8
|
+
})), keys.push.apply(keys, symbols);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return keys;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function _objectSpread2(target) {
|
|
15
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
16
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
17
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
18
|
+
_defineProperty(target, key, source[key]);
|
|
19
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
20
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function _defineProperty(obj, key, value) {
|
|
28
|
+
if (key in obj) {
|
|
29
|
+
Object.defineProperty(obj, key, {
|
|
30
|
+
value: value,
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
obj[key] = value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2 };
|
package/module/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Data structure of the form value
|
|
3
5
|
*/
|
|
@@ -47,21 +49,22 @@ function reportValidity(fieldset) {
|
|
|
47
49
|
|
|
48
50
|
return isValid;
|
|
49
51
|
}
|
|
50
|
-
function
|
|
52
|
+
function getFieldProps(schema, options) {
|
|
51
53
|
var result = {};
|
|
52
54
|
|
|
53
55
|
for (var key of Object.keys(schema.fields)) {
|
|
54
|
-
var _options$
|
|
56
|
+
var _options$defaultValue, _options$error;
|
|
55
57
|
|
|
56
58
|
var constraint = schema.fields[key];
|
|
57
|
-
|
|
59
|
+
|
|
60
|
+
var props = _objectSpread2({
|
|
58
61
|
name: options.name ? "".concat(options.name, ".").concat(key) : key,
|
|
59
62
|
form: options.form,
|
|
60
|
-
|
|
61
|
-
error: (_options$error = options.error) === null || _options$error === void 0 ? void 0 : _options$error[key]
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
result[key] =
|
|
63
|
+
defaultValue: (_options$defaultValue = options.defaultValue) === null || _options$defaultValue === void 0 ? void 0 : _options$defaultValue[key],
|
|
64
|
+
error: (_options$error = options.error) === null || _options$error === void 0 ? void 0 : _options$error[key]
|
|
65
|
+
}, constraint);
|
|
66
|
+
|
|
67
|
+
result[key] = props;
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
return result;
|
|
@@ -139,14 +142,65 @@ function transform(entries) {
|
|
|
139
142
|
|
|
140
143
|
return result;
|
|
141
144
|
}
|
|
142
|
-
function
|
|
145
|
+
function getControlButtonProps(name, action, payload) {
|
|
143
146
|
return {
|
|
144
147
|
type: 'submit',
|
|
145
148
|
name: '__conform__',
|
|
146
|
-
value: [name, action, JSON.stringify(
|
|
149
|
+
value: [name, action, JSON.stringify(payload)].join('::'),
|
|
147
150
|
formNoValidate: true
|
|
148
151
|
};
|
|
149
152
|
}
|
|
153
|
+
function applyControlCommand(list, action, payload) {
|
|
154
|
+
switch (action) {
|
|
155
|
+
case 'prepend':
|
|
156
|
+
{
|
|
157
|
+
var {
|
|
158
|
+
defaultValue
|
|
159
|
+
} = payload;
|
|
160
|
+
list.unshift(defaultValue);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
case 'append':
|
|
165
|
+
{
|
|
166
|
+
var {
|
|
167
|
+
defaultValue: _defaultValue
|
|
168
|
+
} = payload;
|
|
169
|
+
list.push(_defaultValue);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
case 'replace':
|
|
174
|
+
{
|
|
175
|
+
var {
|
|
176
|
+
defaultValue: _defaultValue2,
|
|
177
|
+
index: _index
|
|
178
|
+
} = payload;
|
|
179
|
+
list.splice(_index, 1, _defaultValue2);
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
case 'remove':
|
|
184
|
+
var {
|
|
185
|
+
index
|
|
186
|
+
} = payload;
|
|
187
|
+
list.splice(index, 1);
|
|
188
|
+
break;
|
|
189
|
+
|
|
190
|
+
case 'reorder':
|
|
191
|
+
var {
|
|
192
|
+
from,
|
|
193
|
+
to
|
|
194
|
+
} = payload;
|
|
195
|
+
list.splice(to, 0, ...list.splice(from, 1));
|
|
196
|
+
break;
|
|
197
|
+
|
|
198
|
+
default:
|
|
199
|
+
throw new Error('Invalid action found');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return list;
|
|
203
|
+
}
|
|
150
204
|
function parse(payload) {
|
|
151
205
|
var command = payload.get('__conform__');
|
|
152
206
|
|
|
@@ -177,52 +231,35 @@ function parse(payload) {
|
|
|
177
231
|
throw new Error('');
|
|
178
232
|
}
|
|
179
233
|
|
|
180
|
-
|
|
181
|
-
case 'prepend':
|
|
182
|
-
{
|
|
183
|
-
var initialValue = JSON.parse(json);
|
|
184
|
-
list.unshift(initialValue);
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
case 'append':
|
|
189
|
-
{
|
|
190
|
-
var _initialValue = JSON.parse(json);
|
|
191
|
-
|
|
192
|
-
list.push(_initialValue);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
case 'remove':
|
|
197
|
-
var {
|
|
198
|
-
index
|
|
199
|
-
} = JSON.parse(json);
|
|
200
|
-
list.splice(index, 1);
|
|
201
|
-
break;
|
|
202
|
-
|
|
203
|
-
default:
|
|
204
|
-
throw new Error('Invalid action found; Only `prepend`, `append` and `remove` is accepted');
|
|
205
|
-
}
|
|
234
|
+
applyControlCommand(list, action, JSON.parse(json));
|
|
206
235
|
} catch (e) {
|
|
207
236
|
return {
|
|
208
237
|
state: 'rejected',
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
238
|
+
form: {
|
|
239
|
+
value,
|
|
240
|
+
error: {
|
|
241
|
+
__conform__: e instanceof Error ? e.message : 'Something went wrong'
|
|
242
|
+
}
|
|
212
243
|
}
|
|
213
244
|
};
|
|
214
245
|
}
|
|
215
246
|
|
|
216
247
|
return {
|
|
217
|
-
state: '
|
|
218
|
-
|
|
219
|
-
|
|
248
|
+
state: 'modified',
|
|
249
|
+
form: {
|
|
250
|
+
value,
|
|
251
|
+
error: {}
|
|
252
|
+
}
|
|
220
253
|
};
|
|
221
254
|
}
|
|
222
255
|
|
|
223
256
|
return {
|
|
224
257
|
state: 'accepted',
|
|
225
|
-
value
|
|
258
|
+
data: value,
|
|
259
|
+
form: {
|
|
260
|
+
value,
|
|
261
|
+
error: {}
|
|
262
|
+
}
|
|
226
263
|
};
|
|
227
264
|
}
|
|
228
265
|
function getFieldElements(fieldset, key) {
|
|
@@ -234,4 +271,4 @@ function getFieldElements(fieldset, key) {
|
|
|
234
271
|
return nodes.filter(isFieldElement);
|
|
235
272
|
}
|
|
236
273
|
|
|
237
|
-
export {
|
|
274
|
+
export { applyControlCommand, getControlButtonProps, getFieldElements, getFieldProps, getName, getPaths, isFieldElement, isFieldsetElement, parse, reportValidity, setFieldState, shouldSkipValidate, transform };
|
package/package.json
CHANGED