@conform-to/dom 1.1.4 → 1.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/dom.d.ts CHANGED
@@ -2,7 +2,10 @@
2
2
  * Element that user can interact with,
3
3
  * includes `<input>`, `<select>` and `<textarea>`.
4
4
  */
5
- export type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
5
+ export type FieldElement =
6
+ | HTMLInputElement
7
+ | HTMLSelectElement
8
+ | HTMLTextAreaElement;
6
9
  /**
7
10
  * HTML Element that can be used as a form control,
8
11
  * includes `<input>`, `<select>`, `<textarea>` and `<button>`.
@@ -20,7 +23,9 @@ export declare function isFormControl(element: unknown): element is FormControl;
20
23
  * A type guard to check if the provided element is a field element, which
21
24
  * is a form control excluding submit, button and reset type.
22
25
  */
23
- export declare function isFieldElement(element: unknown): element is FieldElement;
26
+ export declare function isFieldElement(
27
+ element: unknown,
28
+ ): element is FieldElement;
24
29
  /**
25
30
  * Resolves the action from the submit event
26
31
  * with respect to the submitter `formaction` attribute.
@@ -30,14 +35,21 @@ export declare function getFormAction(event: SubmitEvent): string;
30
35
  * Resolves the encoding type from the submit event
31
36
  * with respect to the submitter `formenctype` attribute.
32
37
  */
33
- export declare function getFormEncType(event: SubmitEvent): 'application/x-www-form-urlencoded' | 'multipart/form-data';
38
+ export declare function getFormEncType(
39
+ event: SubmitEvent,
40
+ ): 'application/x-www-form-urlencoded' | 'multipart/form-data';
34
41
  /**
35
42
  * Resolves the method from the submit event
36
43
  * with respect to the submitter `formmethod` attribute.
37
44
  */
38
- export declare function getFormMethod(event: SubmitEvent): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
45
+ export declare function getFormMethod(
46
+ event: SubmitEvent,
47
+ ): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
39
48
  /**
40
49
  * Trigger a form submit event with an optional submitter.
41
50
  * If the submitter is not mounted, it will be appended to the form and removed after submission.
42
51
  */
43
- export declare function requestSubmit(form: HTMLFormElement | null | undefined, submitter: Submitter | null): void;
52
+ export declare function requestSubmit(
53
+ form: HTMLFormElement | null | undefined,
54
+ submitter: Submitter | null,
55
+ ): void;
package/form.d.ts CHANGED
@@ -9,7 +9,7 @@ export type DefaultValue<Schema> = Schema extends string | number | boolean | Da
9
9
  } | null | undefined : string | null | undefined;
10
10
  export type FormValue<Schema> = Schema extends string | number | boolean | Date | bigint | null | undefined ? string | undefined : Schema extends File ? File | undefined : Schema extends File[] ? File | Array<File> | undefined : Schema extends Array<infer Item> ? string | Array<FormValue<Item>> | undefined : Schema extends Record<string, any> ? {
11
11
  [Key in keyof Schema]?: FormValue<Schema[Key]>;
12
- } | null | undefined : unknown;
12
+ } | undefined : unknown;
13
13
  declare const error: unique symbol;
14
14
  declare const field: unique symbol;
15
15
  declare const form: unique symbol;
package/form.js CHANGED
@@ -22,9 +22,7 @@ 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: !initialized ? getDefaultKey(defaultValue) : _rollupPluginBabelHelpers.objectSpread2({
26
- '': util.generateId()
27
- }, getDefaultKey(defaultValue)),
25
+ key: getDefaultKey(defaultValue),
28
26
  // The `lastResult` should comes from the server which we won't expect the error to be null
29
27
  // We can consider adding a warning if it happens
30
28
  error: (_ref = lastResult === null || lastResult === void 0 ? void 0 : lastResult.error) !== null && _ref !== void 0 ? _ref : {}
@@ -43,7 +41,9 @@ function getDefaultKey(defaultValue, prefix) {
43
41
  }
44
42
  }
45
43
  return result;
46
- }, {});
44
+ }, {
45
+ [prefix !== null && prefix !== void 0 ? prefix : '']: util.generateId()
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,9 +147,7 @@ function updateValue(meta, name, value) {
147
147
  if (name === '') {
148
148
  meta.initialValue = value;
149
149
  meta.value = value;
150
- meta.key = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getDefaultKey(value)), {}, {
151
- '': util.generateId()
152
- });
150
+ meta.key = getDefaultKey(value);
153
151
  return;
154
152
  }
155
153
  meta.initialValue = util.clone(meta.initialValue);
package/form.mjs CHANGED
@@ -18,9 +18,7 @@ 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: !initialized ? getDefaultKey(defaultValue) : _objectSpread2({
22
- '': generateId()
23
- }, getDefaultKey(defaultValue)),
21
+ key: getDefaultKey(defaultValue),
24
22
  // The `lastResult` should comes from the server which we won't expect the error to be null
25
23
  // We can consider adding a warning if it happens
26
24
  error: (_ref = lastResult === null || lastResult === void 0 ? void 0 : lastResult.error) !== null && _ref !== void 0 ? _ref : {}
@@ -39,7 +37,9 @@ function getDefaultKey(defaultValue, prefix) {
39
37
  }
40
38
  }
41
39
  return result;
42
- }, {});
40
+ }, {
41
+ [prefix !== null && prefix !== void 0 ? prefix : '']: generateId()
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,9 +143,7 @@ function updateValue(meta, name, value) {
143
143
  if (name === '') {
144
144
  meta.initialValue = value;
145
145
  meta.value = value;
146
- meta.key = _objectSpread2(_objectSpread2({}, getDefaultKey(value)), {}, {
147
- '': generateId()
148
- });
146
+ meta.key = getDefaultKey(value);
149
147
  return;
150
148
  }
151
149
  meta.initialValue = clone(meta.initialValue);
package/index.d.ts CHANGED
@@ -1,4 +1,26 @@
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';
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';
2
16
  export { type FieldElement, isFieldElement } from './dom';
3
- export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
17
+ export {
18
+ type Submission,
19
+ type SubmissionResult,
20
+ type Intent,
21
+ INTENT,
22
+ STATE,
23
+ serializeIntent,
24
+ parse,
25
+ } from './submission';
4
26
  export { getPaths, formatPaths, isPrefix } from './formdata';
package/intent.d.ts CHANGED
@@ -1,61 +1,84 @@
1
1
  import { type Pretty } from './types.js';
2
2
  export interface IntentButtonProps {
3
- name: typeof INTENT;
4
- value: string;
5
- formNoValidate?: boolean;
3
+ name: typeof INTENT;
4
+ value: string;
5
+ formNoValidate?: boolean;
6
6
  }
7
- export type ListIntentPayload<Schema = unknown> = {
8
- name: string;
9
- operation: 'insert';
10
- defaultValue?: Schema;
11
- index?: number;
12
- } | {
13
- name: string;
14
- operation: 'prepend';
15
- defaultValue?: Schema;
16
- } | {
17
- name: string;
18
- operation: 'append';
19
- defaultValue?: Schema;
20
- } | {
21
- name: string;
22
- operation: 'replace';
23
- defaultValue: Schema;
24
- index: number;
25
- } | {
26
- name: string;
27
- operation: 'remove';
28
- index: number;
29
- } | {
30
- name: string;
31
- operation: 'reorder';
32
- from: number;
33
- to: number;
34
- };
35
- type ExtractListIntentPayload<Operation, Schema = unknown> = Pretty<Omit<Extract<ListIntentPayload<Schema>, {
36
- operation: Operation;
37
- }>, 'name' | 'operation'>>;
38
- type ListIntent<Operation> = {} extends ExtractListIntentPayload<Operation> ? <Schema>(name: string, payload?: ExtractListIntentPayload<Operation, Schema>) => IntentButtonProps : <Schema>(name: string, payload: ExtractListIntentPayload<Operation, Schema>) => IntentButtonProps;
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;
39
62
  /**
40
63
  * Helpers to configure an intent button for modifying a list
41
64
  *
42
65
  * @see https://conform.guide/api/react#list
43
66
  */
44
67
  export declare const list: {
45
- /**
46
- * @deprecated You can use `insert` without specifying an index instead
47
- */
48
- append: ListIntent<'append'>;
49
- /**
50
- * @deprecated You can use `insert` with zero index instead
51
- */
52
- prepend: ListIntent<'prepend'>;
53
- insert: ListIntent<'insert'>;
54
- replace: ListIntent<'replace'>;
55
- remove: ListIntent<'remove'>;
56
- reorder: ListIntent<'reorder'>;
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'>;
57
80
  };
58
- export declare const INTENT = "__intent__";
81
+ export declare const INTENT = '__intent__';
59
82
  /**
60
83
  * Returns the intent from the form data or search params.
61
84
  * It throws an error if multiple intent is set.
@@ -67,16 +90,25 @@ export declare function getIntent(payload: FormData | URLSearchParams): string;
67
90
  * @see https://conform.guide/api/react#validate
68
91
  */
69
92
  export declare function validate(field: string): IntentButtonProps;
70
- export declare function requestIntent(form: HTMLFormElement | null | undefined, buttonProps: {
71
- value: string;
72
- formNoValidate?: boolean;
73
- }): void;
74
- export declare function parseIntent<Schema>(intent: string): {
75
- type: 'validate';
76
- payload: string;
77
- } | {
78
- type: 'list';
79
- payload: ListIntentPayload<Schema>;
80
- } | null;
81
- export declare function updateList<Schema>(list: Array<Schema>, payload: ListIntentPayload<Schema>): Array<Schema>;
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>;
82
114
  export {};
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.1.4",
6
+ "version": "1.2.0",
7
7
  "main": "index.js",
8
8
  "module": "index.mjs",
9
9
  "types": "index.d.ts",
package/parse.d.ts CHANGED
@@ -1,30 +1,50 @@
1
1
  export type Submission<Schema = any> = {
2
- intent: string;
3
- payload: Record<string, unknown>;
4
- error: Record<string, string[]>;
5
- value?: Schema | null;
2
+ intent: string;
3
+ payload: Record<string, unknown>;
4
+ error: Record<string, string[]>;
5
+ value?: Schema | null;
6
6
  };
7
- export declare const VALIDATION_UNDEFINED = "__undefined__";
8
- export declare const VALIDATION_SKIPPED = "__skipped__";
7
+ export declare const VALIDATION_UNDEFINED = '__undefined__';
8
+ export declare const VALIDATION_SKIPPED = '__skipped__';
9
9
  export declare function parse(payload: FormData | URLSearchParams): Submission;
10
- export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: {
11
- resolve?: (payload: Record<string, any>, intent: string) => {
12
- value?: Schema;
13
- error?: Record<string, string[]>;
14
- };
15
- }): Submission<Schema>;
16
- export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: {
17
- resolve?: (payload: Record<string, any>, intent: string) => Promise<{
18
- value?: Schema;
19
- error?: Record<string, string[]>;
20
- }>;
21
- }): Promise<Submission<Schema>>;
22
- export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: {
23
- resolve?: (payload: Record<string, any>, intent: string) => {
24
- value?: Schema;
25
- error?: Record<string, string[]>;
26
- } | Promise<{
27
- value?: Schema;
28
- error?: Record<string, string[]>;
29
- }>;
30
- }): Submission<Schema> | Promise<Submission<Schema>>;
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/submission.d.ts CHANGED
@@ -2,9 +2,12 @@ import type { DefaultValue, FieldName, FormValue } from './form';
2
2
  export type SubmissionState = {
3
3
  validated: Record<string, boolean>;
4
4
  };
5
+ export type SubmissionPayload<Entry extends FormDataEntryValue> = Entry | SubmissionPayload<Entry>[] | {
6
+ [key: string]: SubmissionPayload<Entry>;
7
+ };
5
8
  export type SubmissionContext<Value = null, FormError = string[]> = {
6
9
  intent: Intent | null;
7
- payload: Record<string, unknown>;
10
+ payload: Record<string, SubmissionPayload<FormDataEntryValue>>;
8
11
  fields: Set<string>;
9
12
  value?: Value;
10
13
  error?: Record<string, FormError | null> | null;
@@ -12,19 +15,19 @@ export type SubmissionContext<Value = null, FormError = string[]> = {
12
15
  };
13
16
  export type Submission<Schema, FormError = string[], FormValue = Schema> = {
14
17
  status: 'success';
15
- payload: Record<string, unknown>;
18
+ payload: Record<string, SubmissionPayload<FormDataEntryValue>>;
16
19
  value: FormValue;
17
20
  reply(options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
18
21
  } | {
19
22
  status: 'error' | undefined;
20
- payload: Record<string, unknown>;
23
+ payload: Record<string, SubmissionPayload<FormDataEntryValue>>;
21
24
  error: Record<string, FormError | null> | null;
22
25
  reply(options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
23
26
  };
24
27
  export type SubmissionResult<FormError = string[]> = {
25
28
  status?: 'error' | 'success';
26
29
  intent?: Intent;
27
- initialValue?: Record<string, unknown> | null;
30
+ initialValue?: Record<string, SubmissionPayload<string>> | null;
28
31
  fields?: string[];
29
32
  error?: Record<string, FormError | null>;
30
33
  state?: SubmissionState;
package/submission.js CHANGED
@@ -115,7 +115,7 @@ function createSubmission(context) {
115
115
  };
116
116
  }
117
117
  function replySubmission(context) {
118
- var _context$intent, _context$intent$paylo, _options$formErrors, _normalize;
118
+ var _context$intent, _context$intent$paylo, _options$formErrors, _ref;
119
119
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
120
120
  if ('resetForm' in options && options.resetForm || ((_context$intent = context.intent) === null || _context$intent === void 0 ? void 0 : _context$intent.type) === 'reset' && ((_context$intent$paylo = context.intent.payload.name) !== null && _context$intent$paylo !== void 0 ? _context$intent$paylo : '') === '') {
121
121
  return {
@@ -134,12 +134,17 @@ function replySubmission(context) {
134
134
  '': (_options$formErrors = options.formErrors) !== null && _options$formErrors !== void 0 ? _options$formErrors : null
135
135
  }, options.fieldErrors)) : null;
136
136
  var error = context.error || extraError ? _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, context.error), extraError) : undefined;
137
+ var initialValue = (_ref = formdata.normalize(context.payload,
138
+ // We can't serialize the file and send it back from the server, but we can preserve it in the client
139
+ typeof document !== 'undefined'
140
+ // We need the file on the client because it's treated as the form value
141
+ // But we will exclude the File type for now as it's only used by the internal
142
+ // form state and we will remove the need to preserve the file on the client soon
143
+ )) !== null && _ref !== void 0 ? _ref : {};
137
144
  return {
138
145
  status: context.intent ? undefined : error ? 'error' : 'success',
139
146
  intent: context.intent ? context.intent : undefined,
140
- initialValue: (_normalize = formdata.normalize(context.payload,
141
- // We can't serialize the file and send it back from the server, but we can preserve it in the client
142
- typeof document !== 'undefined')) !== null && _normalize !== void 0 ? _normalize : {},
147
+ initialValue,
143
148
  error,
144
149
  state: context.state,
145
150
  fields: Array.from(context.fields)
@@ -209,9 +214,9 @@ function setState(state, name, valueFn) {
209
214
  var keys = Object.keys(state).sort((prev, next) => next.localeCompare(prev));
210
215
  var target = {};
211
216
  var _loop2 = function _loop2() {
212
- var value = state[key];
213
- if (formdata.isPrefix(key, name) && key !== name) {
214
- formdata.setValue(target, key, currentValue => {
217
+ var value = state[_key];
218
+ if (formdata.isPrefix(_key, name) && _key !== name) {
219
+ formdata.setValue(target, _key, currentValue => {
215
220
  if (typeof currentValue === 'undefined') {
216
221
  return value;
217
222
  }
@@ -225,10 +230,10 @@ function setState(state, name, valueFn) {
225
230
  });
226
231
 
227
232
  // Remove the value from the data
228
- delete state[key];
233
+ delete state[_key];
229
234
  }
230
235
  };
231
- for (var key of keys) {
236
+ for (var _key of keys) {
232
237
  _loop2();
233
238
  }
234
239
  var result = valueFn(formdata.getValue(target, name));
@@ -266,8 +271,8 @@ function setListState(state, intent, getDefaultValue) {
266
271
  function serialize(defaultValue) {
267
272
  if (formdata.isPlainObject(defaultValue)) {
268
273
  // @ts-expect-error FIXME
269
- return Object.entries(defaultValue).reduce((result, _ref) => {
270
- var [key, value] = _ref;
274
+ return Object.entries(defaultValue).reduce((result, _ref2) => {
275
+ var [key, value] = _ref2;
271
276
  result[key] = serialize(value);
272
277
  return result;
273
278
  }, {});
package/submission.mjs CHANGED
@@ -111,7 +111,7 @@ function createSubmission(context) {
111
111
  };
112
112
  }
113
113
  function replySubmission(context) {
114
- var _context$intent, _context$intent$paylo, _options$formErrors, _normalize;
114
+ var _context$intent, _context$intent$paylo, _options$formErrors, _ref;
115
115
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
116
116
  if ('resetForm' in options && options.resetForm || ((_context$intent = context.intent) === null || _context$intent === void 0 ? void 0 : _context$intent.type) === 'reset' && ((_context$intent$paylo = context.intent.payload.name) !== null && _context$intent$paylo !== void 0 ? _context$intent$paylo : '') === '') {
117
117
  return {
@@ -130,12 +130,17 @@ function replySubmission(context) {
130
130
  '': (_options$formErrors = options.formErrors) !== null && _options$formErrors !== void 0 ? _options$formErrors : null
131
131
  }, options.fieldErrors)) : null;
132
132
  var error = context.error || extraError ? _objectSpread2(_objectSpread2({}, context.error), extraError) : undefined;
133
+ var initialValue = (_ref = normalize(context.payload,
134
+ // We can't serialize the file and send it back from the server, but we can preserve it in the client
135
+ typeof document !== 'undefined'
136
+ // We need the file on the client because it's treated as the form value
137
+ // But we will exclude the File type for now as it's only used by the internal
138
+ // form state and we will remove the need to preserve the file on the client soon
139
+ )) !== null && _ref !== void 0 ? _ref : {};
133
140
  return {
134
141
  status: context.intent ? undefined : error ? 'error' : 'success',
135
142
  intent: context.intent ? context.intent : undefined,
136
- initialValue: (_normalize = normalize(context.payload,
137
- // We can't serialize the file and send it back from the server, but we can preserve it in the client
138
- typeof document !== 'undefined')) !== null && _normalize !== void 0 ? _normalize : {},
143
+ initialValue,
139
144
  error,
140
145
  state: context.state,
141
146
  fields: Array.from(context.fields)
@@ -205,9 +210,9 @@ function setState(state, name, valueFn) {
205
210
  var keys = Object.keys(state).sort((prev, next) => next.localeCompare(prev));
206
211
  var target = {};
207
212
  var _loop2 = function _loop2() {
208
- var value = state[key];
209
- if (isPrefix(key, name) && key !== name) {
210
- setValue(target, key, currentValue => {
213
+ var value = state[_key];
214
+ if (isPrefix(_key, name) && _key !== name) {
215
+ setValue(target, _key, currentValue => {
211
216
  if (typeof currentValue === 'undefined') {
212
217
  return value;
213
218
  }
@@ -221,10 +226,10 @@ function setState(state, name, valueFn) {
221
226
  });
222
227
 
223
228
  // Remove the value from the data
224
- delete state[key];
229
+ delete state[_key];
225
230
  }
226
231
  };
227
- for (var key of keys) {
232
+ for (var _key of keys) {
228
233
  _loop2();
229
234
  }
230
235
  var result = valueFn(getValue(target, name));
@@ -262,8 +267,8 @@ function setListState(state, intent, getDefaultValue) {
262
267
  function serialize(defaultValue) {
263
268
  if (isPlainObject(defaultValue)) {
264
269
  // @ts-expect-error FIXME
265
- return Object.entries(defaultValue).reduce((result, _ref) => {
266
- var [key, value] = _ref;
270
+ return Object.entries(defaultValue).reduce((result, _ref2) => {
271
+ var [key, value] = _ref2;
267
272
  result[key] = serialize(value);
268
273
  return result;
269
274
  }, {});
package/types.d.ts CHANGED
@@ -1,20 +1,23 @@
1
1
  export type Pretty<T> = {
2
- [K in keyof T]: T[K];
2
+ [K in keyof T]: T[K];
3
3
  } & {};
4
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;
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
13
  };
14
14
  export type KeysOf<T> = T extends any ? keyof T : never;
15
15
  export type ResolveType<T, K extends KeysOf<T>> = T extends {
16
- [k in K]?: any;
17
- } ? T[K] : undefined;
18
- export type FieldsetConstraint<Schema extends Record<string, any> | undefined> = {
19
- [Key in KeysOf<Schema>]?: FieldConstraint<ResolveType<Schema, Key>>;
20
- };
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
+ };
package/util.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- export declare function invariant(expectedCondition: boolean, message: string): asserts expectedCondition;
1
+ export declare function invariant(
2
+ expectedCondition: boolean,
3
+ message: string,
4
+ ): asserts expectedCondition;
2
5
  export declare function generateId(): string;
3
6
  export declare function clone<Data>(data: Data): Data;
package/rollup.config.js DELETED
@@ -1,100 +0,0 @@
1
- import path from 'node:path';
2
- import babel from '@rollup/plugin-babel';
3
- import nodeResolve from '@rollup/plugin-node-resolve';
4
- import copy from 'rollup-plugin-copy';
5
-
6
- /** @returns {import("rollup").RollupOptions[]} */
7
- function configurePackage() {
8
- let sourceDir = '.';
9
- let outputDir = sourceDir;
10
-
11
- /** @type {import("rollup").RollupOptions} */
12
- let ESM = {
13
- external(id) {
14
- return !id.startsWith('.') && !path.isAbsolute(id);
15
- },
16
- input: `${sourceDir}/index.ts`,
17
- output: {
18
- dir: outputDir,
19
- format: 'esm',
20
- preserveModules: true,
21
- entryFileNames: '[name].mjs',
22
- },
23
- plugins: [
24
- babel({
25
- babelrc: false,
26
- configFile: false,
27
- presets: [
28
- [
29
- '@babel/preset-env',
30
- {
31
- targets: {
32
- node: '16',
33
- esmodules: true,
34
- },
35
- },
36
- ],
37
- '@babel/preset-typescript',
38
- ],
39
- plugins: [],
40
- babelHelpers: 'bundled',
41
- exclude: /node_modules/,
42
- extensions: ['.ts', '.tsx'],
43
- }),
44
- nodeResolve({
45
- extensions: ['.ts', '.tsx'],
46
- }),
47
- copy({
48
- targets: [
49
- { src: `../../README`, dest: sourceDir },
50
- { src: `../../LICENSE`, dest: sourceDir },
51
- ],
52
- }),
53
- ],
54
- };
55
-
56
- /** @type {import("rollup").RollupOptions} */
57
- let CJS = {
58
- external(id) {
59
- return !id.startsWith('.') && !path.isAbsolute(id);
60
- },
61
- input: `${sourceDir}/index.ts`,
62
- output: {
63
- dir: outputDir,
64
- format: 'cjs',
65
- preserveModules: true,
66
- exports: 'auto',
67
- },
68
- plugins: [
69
- babel({
70
- babelrc: false,
71
- configFile: false,
72
- presets: [
73
- [
74
- '@babel/preset-env',
75
- {
76
- targets: {
77
- node: '16',
78
- esmodules: true,
79
- },
80
- },
81
- ],
82
- '@babel/preset-typescript',
83
- ],
84
- plugins: [],
85
- babelHelpers: 'bundled',
86
- exclude: /node_modules/,
87
- extensions: ['.ts', '.tsx'],
88
- }),
89
- nodeResolve({
90
- extensions: ['.ts', '.tsx'],
91
- }),
92
- ],
93
- };
94
-
95
- return [ESM, CJS];
96
- }
97
-
98
- export default function rollup() {
99
- return configurePackage();
100
- }