@conform-to/dom 1.2.0 → 1.2.2

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/dom.d.ts CHANGED
@@ -2,10 +2,7 @@
2
2
  * Element that user can interact with,
3
3
  * includes `<input>`, `<select>` and `<textarea>`.
4
4
  */
5
- export type FieldElement =
6
- | HTMLInputElement
7
- | HTMLSelectElement
8
- | HTMLTextAreaElement;
5
+ export type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
9
6
  /**
10
7
  * HTML Element that can be used as a form control,
11
8
  * includes `<input>`, `<select>`, `<textarea>` and `<button>`.
@@ -23,9 +20,7 @@ export declare function isFormControl(element: unknown): element is FormControl;
23
20
  * A type guard to check if the provided element is a field element, which
24
21
  * is a form control excluding submit, button and reset type.
25
22
  */
26
- export declare function isFieldElement(
27
- element: unknown,
28
- ): element is FieldElement;
23
+ export declare function isFieldElement(element: unknown): element is FieldElement;
29
24
  /**
30
25
  * Resolves the action from the submit event
31
26
  * with respect to the submitter `formaction` attribute.
@@ -35,21 +30,14 @@ export declare function getFormAction(event: SubmitEvent): string;
35
30
  * Resolves the encoding type from the submit event
36
31
  * with respect to the submitter `formenctype` attribute.
37
32
  */
38
- export declare function getFormEncType(
39
- event: SubmitEvent,
40
- ): 'application/x-www-form-urlencoded' | 'multipart/form-data';
33
+ export declare function getFormEncType(event: SubmitEvent): 'application/x-www-form-urlencoded' | 'multipart/form-data';
41
34
  /**
42
35
  * Resolves the method from the submit event
43
36
  * with respect to the submitter `formmethod` attribute.
44
37
  */
45
- export declare function getFormMethod(
46
- event: SubmitEvent,
47
- ): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
38
+ export declare function getFormMethod(event: SubmitEvent): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
48
39
  /**
49
40
  * Trigger a form submit event with an optional submitter.
50
41
  * If the submitter is not mounted, it will be appended to the form and removed after submission.
51
42
  */
52
- export declare function requestSubmit(
53
- form: HTMLFormElement | null | undefined,
54
- submitter: Submitter | null,
55
- ): void;
43
+ export declare function requestSubmit(form: HTMLFormElement | null | undefined, submitter: Submitter | null): void;
package/form.js CHANGED
@@ -22,7 +22,9 @@ function createFormMeta(options, initialized) {
22
22
  value: initialValue,
23
23
  constraint: (_options$constraint = options.constraint) !== null && _options$constraint !== void 0 ? _options$constraint : {},
24
24
  validated: (_lastResult$state$val = lastResult === null || lastResult === void 0 || (_lastResult$state = lastResult.state) === null || _lastResult$state === void 0 ? void 0 : _lastResult$state.validated) !== null && _lastResult$state$val !== void 0 ? _lastResult$state$val : {},
25
- key: getDefaultKey(defaultValue),
25
+ key: !initialized ? getDefaultKey(defaultValue) : _rollupPluginBabelHelpers.objectSpread2({
26
+ '': util.generateId()
27
+ }, getDefaultKey(defaultValue)),
26
28
  // The `lastResult` should comes from the server which we won't expect the error to be null
27
29
  // We can consider adding a warning if it happens
28
30
  error: (_ref = lastResult === null || lastResult === void 0 ? void 0 : lastResult.error) !== null && _ref !== void 0 ? _ref : {}
@@ -41,9 +43,7 @@ function getDefaultKey(defaultValue, prefix) {
41
43
  }
42
44
  }
43
45
  return result;
44
- }, {
45
- [prefix !== null && prefix !== void 0 ? prefix : '']: util.generateId()
46
- });
46
+ }, {});
47
47
  }
48
48
  function setFieldsValidated(meta, fields) {
49
49
  for (var _name of Object.keys(meta.error).concat(fields !== null && fields !== void 0 ? fields : [])) {
@@ -147,7 +147,9 @@ function updateValue(meta, name, value) {
147
147
  if (name === '') {
148
148
  meta.initialValue = value;
149
149
  meta.value = value;
150
- meta.key = getDefaultKey(value);
150
+ meta.key = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getDefaultKey(value)), {}, {
151
+ '': util.generateId()
152
+ });
151
153
  return;
152
154
  }
153
155
  meta.initialValue = util.clone(meta.initialValue);
package/form.mjs CHANGED
@@ -18,7 +18,9 @@ function createFormMeta(options, initialized) {
18
18
  value: initialValue,
19
19
  constraint: (_options$constraint = options.constraint) !== null && _options$constraint !== void 0 ? _options$constraint : {},
20
20
  validated: (_lastResult$state$val = lastResult === null || lastResult === void 0 || (_lastResult$state = lastResult.state) === null || _lastResult$state === void 0 ? void 0 : _lastResult$state.validated) !== null && _lastResult$state$val !== void 0 ? _lastResult$state$val : {},
21
- key: getDefaultKey(defaultValue),
21
+ key: !initialized ? getDefaultKey(defaultValue) : _objectSpread2({
22
+ '': generateId()
23
+ }, getDefaultKey(defaultValue)),
22
24
  // The `lastResult` should comes from the server which we won't expect the error to be null
23
25
  // We can consider adding a warning if it happens
24
26
  error: (_ref = lastResult === null || lastResult === void 0 ? void 0 : lastResult.error) !== null && _ref !== void 0 ? _ref : {}
@@ -37,9 +39,7 @@ function getDefaultKey(defaultValue, prefix) {
37
39
  }
38
40
  }
39
41
  return result;
40
- }, {
41
- [prefix !== null && prefix !== void 0 ? prefix : '']: generateId()
42
- });
42
+ }, {});
43
43
  }
44
44
  function setFieldsValidated(meta, fields) {
45
45
  for (var _name of Object.keys(meta.error).concat(fields !== null && fields !== void 0 ? fields : [])) {
@@ -143,7 +143,9 @@ function updateValue(meta, name, value) {
143
143
  if (name === '') {
144
144
  meta.initialValue = value;
145
145
  meta.value = value;
146
- meta.key = getDefaultKey(value);
146
+ meta.key = _objectSpread2(_objectSpread2({}, getDefaultKey(value)), {}, {
147
+ '': generateId()
148
+ });
147
149
  return;
148
150
  }
149
151
  meta.initialValue = clone(meta.initialValue);
package/index.d.ts CHANGED
@@ -1,26 +1,4 @@
1
- export {
2
- type Combine,
3
- type Constraint,
4
- type ControlButtonProps,
5
- type FormId,
6
- type FieldName,
7
- type DefaultValue,
8
- type FormValue,
9
- type FormOptions,
10
- type FormState,
11
- type FormContext,
12
- type SubscriptionSubject,
13
- type SubscriptionScope,
14
- createFormContext as unstable_createFormContext,
15
- } from './form';
1
+ export { type Combine, 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';
16
2
  export { type FieldElement, isFieldElement } from './dom';
17
- export {
18
- type Submission,
19
- type SubmissionResult,
20
- type Intent,
21
- INTENT,
22
- STATE,
23
- serializeIntent,
24
- parse,
25
- } from './submission';
3
+ export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
26
4
  export { getPaths, formatPaths, isPrefix } from './formdata';
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.2.0",
6
+ "version": "1.2.2",
7
7
  "main": "index.js",
8
8
  "module": "index.mjs",
9
9
  "types": "index.d.ts",
package/util.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- export declare function invariant(
2
- expectedCondition: boolean,
3
- message: string,
4
- ): asserts expectedCondition;
1
+ export declare function invariant(expectedCondition: boolean, message: string): asserts expectedCondition;
5
2
  export declare function generateId(): string;
6
3
  export declare function clone<Data>(data: Data): Data;
package/README DELETED
@@ -1,37 +0,0 @@
1
-
2
-
3
- ███████╗ ██████╗ ███╗ ██╗ ████████╗ ██████╗ ███████╗ ███╗ ███╗
4
- ██╔═════╝ ██╔═══██╗ ████╗ ██║ ██╔═════╝ ██╔═══██╗ ██╔═══██╗ ████████║
5
- ██║ ██║ ██║ ██╔██╗██║ ███████╗ ██║ ██║ ███████╔╝ ██╔██╔██║
6
- ██║ ██║ ██║ ██║╚████║ ██╔════╝ ██║ ██║ ██╔═══██╗ ██║╚═╝██║
7
- ╚███████╗ ╚██████╔╝ ██║ ╚███║ ██║ ╚██████╔╝ ██║ ██║ ██║ ██║
8
- ╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
9
-
10
-
11
- Version 1.1.3 / License MIT / Copyright (c) 2024 Edmund Hung
12
-
13
- A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix and Next.js.
14
-
15
- # Getting Started
16
-
17
- Check out the overview and tutorial at our website https://conform.guide
18
-
19
- # Features
20
-
21
- - Progressive enhancement first APIs
22
- - Type-safe field inference
23
- - Fine-grained subscription
24
- - Built-in accessibility helpers
25
- - Automatic type coercion with Zod
26
-
27
- # Documentation
28
-
29
- - Validation: https://conform.guide/validation
30
- - Nested object and Array: https://conform.guide/complex-structures
31
- - UI Integrations: https://conform.guide/integration/ui-libraries
32
- - Intent button: https://conform.guide/intent-button
33
- - Accessibility Guide: https://conform.guide/accessibility
34
-
35
- # Support
36
-
37
- To report a bug, please open an issue on the repository at https://github.com/edmundhung/conform. For feature requests and questions, you can post them in the Discussions section.
package/intent.d.ts DELETED
@@ -1,114 +0,0 @@
1
- import { type Pretty } from './types.js';
2
- export interface IntentButtonProps {
3
- name: typeof INTENT;
4
- value: string;
5
- formNoValidate?: boolean;
6
- }
7
- export type ListIntentPayload<Schema = unknown> =
8
- | {
9
- name: string;
10
- operation: 'insert';
11
- defaultValue?: Schema;
12
- index?: number;
13
- }
14
- | {
15
- name: string;
16
- operation: 'prepend';
17
- defaultValue?: Schema;
18
- }
19
- | {
20
- name: string;
21
- operation: 'append';
22
- defaultValue?: Schema;
23
- }
24
- | {
25
- name: string;
26
- operation: 'replace';
27
- defaultValue: Schema;
28
- index: number;
29
- }
30
- | {
31
- name: string;
32
- operation: 'remove';
33
- index: number;
34
- }
35
- | {
36
- name: string;
37
- operation: 'reorder';
38
- from: number;
39
- to: number;
40
- };
41
- type ExtractListIntentPayload<Operation, Schema = unknown> = Pretty<
42
- Omit<
43
- Extract<
44
- ListIntentPayload<Schema>,
45
- {
46
- operation: Operation;
47
- }
48
- >,
49
- 'name' | 'operation'
50
- >
51
- >;
52
- type ListIntent<Operation> =
53
- {} extends ExtractListIntentPayload<Operation>
54
- ? <Schema>(
55
- name: string,
56
- payload?: ExtractListIntentPayload<Operation, Schema>,
57
- ) => IntentButtonProps
58
- : <Schema>(
59
- name: string,
60
- payload: ExtractListIntentPayload<Operation, Schema>,
61
- ) => IntentButtonProps;
62
- /**
63
- * Helpers to configure an intent button for modifying a list
64
- *
65
- * @see https://conform.guide/api/react#list
66
- */
67
- export declare const list: {
68
- /**
69
- * @deprecated You can use `insert` without specifying an index instead
70
- */
71
- append: ListIntent<'append'>;
72
- /**
73
- * @deprecated You can use `insert` with zero index instead
74
- */
75
- prepend: ListIntent<'prepend'>;
76
- insert: ListIntent<'insert'>;
77
- replace: ListIntent<'replace'>;
78
- remove: ListIntent<'remove'>;
79
- reorder: ListIntent<'reorder'>;
80
- };
81
- export declare const INTENT = '__intent__';
82
- /**
83
- * Returns the intent from the form data or search params.
84
- * It throws an error if multiple intent is set.
85
- */
86
- export declare function getIntent(payload: FormData | URLSearchParams): string;
87
- /**
88
- * Returns the properties required to configure an intent button for validation
89
- *
90
- * @see https://conform.guide/api/react#validate
91
- */
92
- export declare function validate(field: string): IntentButtonProps;
93
- export declare function requestIntent(
94
- form: HTMLFormElement | null | undefined,
95
- buttonProps: {
96
- value: string;
97
- formNoValidate?: boolean;
98
- },
99
- ): void;
100
- export declare function parseIntent<Schema>(intent: string):
101
- | {
102
- type: 'validate';
103
- payload: string;
104
- }
105
- | {
106
- type: 'list';
107
- payload: ListIntentPayload<Schema>;
108
- }
109
- | null;
110
- export declare function updateList<Schema>(
111
- list: Array<Schema>,
112
- payload: ListIntentPayload<Schema>,
113
- ): Array<Schema>;
114
- export {};
package/intent.js DELETED
@@ -1,136 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
6
- var dom = require('./dom.js');
7
-
8
- /**
9
- * Helpers to configure an intent button for modifying a list
10
- *
11
- * @see https://conform.guide/api/react#list
12
- */
13
- var list = new Proxy({}, {
14
- get(_target, operation) {
15
- return function (name) {
16
- var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
- return {
18
- name: INTENT,
19
- value: "list/".concat(JSON.stringify(_rollupPluginBabelHelpers.objectSpread2({
20
- name,
21
- operation
22
- }, payload))),
23
- formNoValidate: true
24
- };
25
- };
26
- }
27
- });
28
- var INTENT = '__intent__';
29
-
30
- /**
31
- * Returns the intent from the form data or search params.
32
- * It throws an error if multiple intent is set.
33
- */
34
- function getIntent(payload) {
35
- if (!payload.has(INTENT)) {
36
- return 'submit';
37
- }
38
- var [intent, secondIntent, ...rest] = payload.getAll(INTENT);
39
-
40
- // The submitter value is included in the formData directly on Safari 15.6.
41
- // This causes the intent to be duplicated in the payload.
42
- // We will ignore the second intent if it is the same as the first one.
43
- if (typeof intent !== 'string' || secondIntent && intent !== secondIntent || rest.length > 0) {
44
- throw new Error('The intent could only be set on a button');
45
- }
46
- return intent;
47
- }
48
-
49
- /**
50
- * Returns the properties required to configure an intent button for validation
51
- *
52
- * @see https://conform.guide/api/react#validate
53
- */
54
- function validate(field) {
55
- return {
56
- name: INTENT,
57
- value: "validate/".concat(field),
58
- formNoValidate: true
59
- };
60
- }
61
- function requestIntent(form, buttonProps) {
62
- if (!form) {
63
- // eslint-disable-next-line no-console
64
- console.warn('No form element is provided');
65
- return;
66
- }
67
- var submitter = dom.createSubmitter({
68
- name: INTENT,
69
- value: buttonProps.value,
70
- hidden: true,
71
- formNoValidate: buttonProps.formNoValidate
72
- });
73
- dom.requestSubmit(form, submitter);
74
- }
75
- function parseIntent(intent) {
76
- var seperatorIndex = intent.indexOf('/');
77
- if (seperatorIndex > -1) {
78
- var type = intent.slice(0, seperatorIndex);
79
- var _payload = intent.slice(seperatorIndex + 1);
80
- if (typeof _payload !== 'undefined') {
81
- try {
82
- switch (type) {
83
- case 'validate':
84
- return {
85
- type,
86
- payload: _payload
87
- };
88
- case 'list':
89
- return {
90
- type,
91
- payload: JSON.parse(_payload)
92
- };
93
- }
94
- } catch (error) {
95
- throw new Error("Failed parsing intent: ".concat(intent), {
96
- cause: error
97
- });
98
- }
99
- }
100
- }
101
- return null;
102
- }
103
- function updateList(list, payload) {
104
- var _payload$index;
105
- switch (payload.operation) {
106
- case 'prepend':
107
- list.unshift(payload.defaultValue);
108
- break;
109
- case 'append':
110
- list.push(payload.defaultValue);
111
- break;
112
- case 'insert':
113
- list.splice((_payload$index = payload.index) !== null && _payload$index !== void 0 ? _payload$index : list.length, 0, payload.defaultValue);
114
- break;
115
- case 'replace':
116
- list.splice(payload.index, 1, payload.defaultValue);
117
- break;
118
- case 'remove':
119
- list.splice(payload.index, 1);
120
- break;
121
- case 'reorder':
122
- list.splice(payload.to, 0, ...list.splice(payload.from, 1));
123
- break;
124
- default:
125
- throw new Error('Unknown list intent received');
126
- }
127
- return list;
128
- }
129
-
130
- exports.INTENT = INTENT;
131
- exports.getIntent = getIntent;
132
- exports.list = list;
133
- exports.parseIntent = parseIntent;
134
- exports.requestIntent = requestIntent;
135
- exports.updateList = updateList;
136
- exports.validate = validate;
package/intent.mjs DELETED
@@ -1,126 +0,0 @@
1
- import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
- import { createSubmitter, requestSubmit } from './dom.mjs';
3
-
4
- /**
5
- * Helpers to configure an intent button for modifying a list
6
- *
7
- * @see https://conform.guide/api/react#list
8
- */
9
- var list = new Proxy({}, {
10
- get(_target, operation) {
11
- return function (name) {
12
- var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13
- return {
14
- name: INTENT,
15
- value: "list/".concat(JSON.stringify(_objectSpread2({
16
- name,
17
- operation
18
- }, payload))),
19
- formNoValidate: true
20
- };
21
- };
22
- }
23
- });
24
- var INTENT = '__intent__';
25
-
26
- /**
27
- * Returns the intent from the form data or search params.
28
- * It throws an error if multiple intent is set.
29
- */
30
- function getIntent(payload) {
31
- if (!payload.has(INTENT)) {
32
- return 'submit';
33
- }
34
- var [intent, secondIntent, ...rest] = payload.getAll(INTENT);
35
-
36
- // The submitter value is included in the formData directly on Safari 15.6.
37
- // This causes the intent to be duplicated in the payload.
38
- // We will ignore the second intent if it is the same as the first one.
39
- if (typeof intent !== 'string' || secondIntent && intent !== secondIntent || rest.length > 0) {
40
- throw new Error('The intent could only be set on a button');
41
- }
42
- return intent;
43
- }
44
-
45
- /**
46
- * Returns the properties required to configure an intent button for validation
47
- *
48
- * @see https://conform.guide/api/react#validate
49
- */
50
- function validate(field) {
51
- return {
52
- name: INTENT,
53
- value: "validate/".concat(field),
54
- formNoValidate: true
55
- };
56
- }
57
- function requestIntent(form, buttonProps) {
58
- if (!form) {
59
- // eslint-disable-next-line no-console
60
- console.warn('No form element is provided');
61
- return;
62
- }
63
- var submitter = createSubmitter({
64
- name: INTENT,
65
- value: buttonProps.value,
66
- hidden: true,
67
- formNoValidate: buttonProps.formNoValidate
68
- });
69
- requestSubmit(form, submitter);
70
- }
71
- function parseIntent(intent) {
72
- var seperatorIndex = intent.indexOf('/');
73
- if (seperatorIndex > -1) {
74
- var type = intent.slice(0, seperatorIndex);
75
- var _payload = intent.slice(seperatorIndex + 1);
76
- if (typeof _payload !== 'undefined') {
77
- try {
78
- switch (type) {
79
- case 'validate':
80
- return {
81
- type,
82
- payload: _payload
83
- };
84
- case 'list':
85
- return {
86
- type,
87
- payload: JSON.parse(_payload)
88
- };
89
- }
90
- } catch (error) {
91
- throw new Error("Failed parsing intent: ".concat(intent), {
92
- cause: error
93
- });
94
- }
95
- }
96
- }
97
- return null;
98
- }
99
- function updateList(list, payload) {
100
- var _payload$index;
101
- switch (payload.operation) {
102
- case 'prepend':
103
- list.unshift(payload.defaultValue);
104
- break;
105
- case 'append':
106
- list.push(payload.defaultValue);
107
- break;
108
- case 'insert':
109
- list.splice((_payload$index = payload.index) !== null && _payload$index !== void 0 ? _payload$index : list.length, 0, payload.defaultValue);
110
- break;
111
- case 'replace':
112
- list.splice(payload.index, 1, payload.defaultValue);
113
- break;
114
- case 'remove':
115
- list.splice(payload.index, 1);
116
- break;
117
- case 'reorder':
118
- list.splice(payload.to, 0, ...list.splice(payload.from, 1));
119
- break;
120
- default:
121
- throw new Error('Unknown list intent received');
122
- }
123
- return list;
124
- }
125
-
126
- export { INTENT, getIntent, list, parseIntent, requestIntent, updateList, validate };
package/parse.d.ts DELETED
@@ -1,50 +0,0 @@
1
- export type Submission<Schema = any> = {
2
- intent: string;
3
- payload: Record<string, unknown>;
4
- error: Record<string, string[]>;
5
- value?: Schema | null;
6
- };
7
- export declare const VALIDATION_UNDEFINED = '__undefined__';
8
- export declare const VALIDATION_SKIPPED = '__skipped__';
9
- export declare function parse(payload: FormData | URLSearchParams): Submission;
10
- export declare function parse<Schema>(
11
- payload: FormData | URLSearchParams,
12
- options?: {
13
- resolve?: (
14
- payload: Record<string, any>,
15
- intent: string,
16
- ) => {
17
- value?: Schema;
18
- error?: Record<string, string[]>;
19
- };
20
- },
21
- ): Submission<Schema>;
22
- export declare function parse<Schema>(
23
- payload: FormData | URLSearchParams,
24
- options?: {
25
- resolve?: (
26
- payload: Record<string, any>,
27
- intent: string,
28
- ) => Promise<{
29
- value?: Schema;
30
- error?: Record<string, string[]>;
31
- }>;
32
- },
33
- ): Promise<Submission<Schema>>;
34
- export declare function parse<Schema>(
35
- payload: FormData | URLSearchParams,
36
- options?: {
37
- resolve?: (
38
- payload: Record<string, any>,
39
- intent: string,
40
- ) =>
41
- | {
42
- value?: Schema;
43
- error?: Record<string, string[]>;
44
- }
45
- | Promise<{
46
- value?: Schema;
47
- error?: Record<string, string[]>;
48
- }>;
49
- },
50
- ): Submission<Schema> | Promise<Submission<Schema>>;
package/parse.js DELETED
@@ -1,43 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
6
- var formdata = require('./formdata.js');
7
- var intent = require('./intent.js');
8
-
9
- var VALIDATION_UNDEFINED = '__undefined__';
10
- var VALIDATION_SKIPPED = '__skipped__';
11
- function parse(payload, options) {
12
- var submission = {
13
- intent: intent.getIntent(payload),
14
- payload: formdata.resolve(payload, {
15
- ignoreKeys: [intent.INTENT]
16
- }),
17
- error: {}
18
- };
19
- var intent$1 = intent.parseIntent(submission.intent);
20
- if (intent$1 && intent$1.type === 'list') {
21
- formdata.setValue(submission.payload, intent$1.payload.name, list => {
22
- if (typeof list !== 'undefined' && !Array.isArray(list)) {
23
- throw new Error('The list intent can only be applied to a list');
24
- }
25
- return intent.updateList(list !== null && list !== void 0 ? list : [], intent$1.payload);
26
- });
27
- }
28
- if (typeof (options === null || options === void 0 ? void 0 : options.resolve) === 'undefined') {
29
- return submission;
30
- }
31
- var result = options.resolve(submission.payload, submission.intent);
32
- var mergeResolveResult = resolved => {
33
- return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, submission), resolved);
34
- };
35
- if (result instanceof Promise) {
36
- return result.then(mergeResolveResult);
37
- }
38
- return mergeResolveResult(result);
39
- }
40
-
41
- exports.VALIDATION_SKIPPED = VALIDATION_SKIPPED;
42
- exports.VALIDATION_UNDEFINED = VALIDATION_UNDEFINED;
43
- exports.parse = parse;
package/parse.mjs DELETED
@@ -1,37 +0,0 @@
1
- import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
- import { resolve, setValue } from './formdata.mjs';
3
- import { getIntent, parseIntent, updateList, INTENT } from './intent.mjs';
4
-
5
- var VALIDATION_UNDEFINED = '__undefined__';
6
- var VALIDATION_SKIPPED = '__skipped__';
7
- function parse(payload, options) {
8
- var submission = {
9
- intent: getIntent(payload),
10
- payload: resolve(payload, {
11
- ignoreKeys: [INTENT]
12
- }),
13
- error: {}
14
- };
15
- var intent = parseIntent(submission.intent);
16
- if (intent && intent.type === 'list') {
17
- setValue(submission.payload, intent.payload.name, list => {
18
- if (typeof list !== 'undefined' && !Array.isArray(list)) {
19
- throw new Error('The list intent can only be applied to a list');
20
- }
21
- return updateList(list !== null && list !== void 0 ? list : [], intent.payload);
22
- });
23
- }
24
- if (typeof (options === null || options === void 0 ? void 0 : options.resolve) === 'undefined') {
25
- return submission;
26
- }
27
- var result = options.resolve(submission.payload, submission.intent);
28
- var mergeResolveResult = resolved => {
29
- return _objectSpread2(_objectSpread2({}, submission), resolved);
30
- };
31
- if (result instanceof Promise) {
32
- return result.then(mergeResolveResult);
33
- }
34
- return mergeResolveResult(result);
35
- }
36
-
37
- export { VALIDATION_SKIPPED, VALIDATION_UNDEFINED, parse };
package/types.d.ts DELETED
@@ -1,23 +0,0 @@
1
- export type Pretty<T> = {
2
- [K in keyof T]: T[K];
3
- } & {};
4
- export type FieldConstraint<Schema = any> = {
5
- required?: boolean;
6
- minLength?: number;
7
- maxLength?: number;
8
- min?: Schema extends number ? number : string | number;
9
- max?: Schema extends number ? number : string | number;
10
- step?: Schema extends number ? number : string | number;
11
- multiple?: boolean;
12
- pattern?: string;
13
- };
14
- export type KeysOf<T> = T extends any ? keyof T : never;
15
- export type ResolveType<T, K extends KeysOf<T>> = T extends {
16
- [k in K]?: any;
17
- }
18
- ? T[K]
19
- : undefined;
20
- export type FieldsetConstraint<Schema extends Record<string, any> | undefined> =
21
- {
22
- [Key in KeysOf<Schema>]?: FieldConstraint<ResolveType<Schema, Key>>;
23
- };