@conform-to/dom 1.0.0-pre.7 → 1.0.0-rc.1

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 CHANGED
@@ -8,9 +8,9 @@
8
8
  ╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
9
9
 
10
10
 
11
- Version 1.0.0-pre.7 / License MIT / Copyright (c) 2024 Edmund Hung
11
+ Version 1.0.0-rc.0 / License MIT / Copyright (c) 2024 Edmund Hung
12
12
 
13
- A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix route action and Next.js server actions.
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
14
 
15
15
  > Getting Started
16
16
 
@@ -21,7 +21,7 @@ Check out the overview and tutorial at our website https://conform.guide
21
21
  The documentation is divided into several sections:
22
22
 
23
23
  * Overview: https://conform.guide/overview
24
- * Example Usages: https://conform.guide/examples
24
+ * Examples: https://conform.guide/examples
25
25
  * Complex structures: https://conform.guide/complex-structures
26
26
  * UI Integrations: https://conform.guide/integrations
27
27
  * Accessibility Guide: https://conform.guide/accessibility
package/dom.js CHANGED
@@ -84,17 +84,16 @@ function getFormMethod(event) {
84
84
  */
85
85
  function requestSubmit(form, submitter) {
86
86
  util.invariant(!!form, 'Failed to submit the form. The element provided is null or undefined.');
87
-
88
- // if (typeof form.requestSubmit === 'function') {
89
- // form.requestSubmit(submitter);
90
- // } else {
91
- var event = new SubmitEvent('submit', {
92
- bubbles: true,
93
- cancelable: true,
94
- submitter
95
- });
96
- form.dispatchEvent(event);
97
- // }
87
+ if (typeof form.requestSubmit === 'function') {
88
+ form.requestSubmit(submitter);
89
+ } else {
90
+ var event = new SubmitEvent('submit', {
91
+ bubbles: true,
92
+ cancelable: true,
93
+ submitter
94
+ });
95
+ form.dispatchEvent(event);
96
+ }
98
97
  }
99
98
 
100
99
  exports.getFormAction = getFormAction;
package/dom.mjs CHANGED
@@ -80,17 +80,16 @@ function getFormMethod(event) {
80
80
  */
81
81
  function requestSubmit(form, submitter) {
82
82
  invariant(!!form, 'Failed to submit the form. The element provided is null or undefined.');
83
-
84
- // if (typeof form.requestSubmit === 'function') {
85
- // form.requestSubmit(submitter);
86
- // } else {
87
- var event = new SubmitEvent('submit', {
88
- bubbles: true,
89
- cancelable: true,
90
- submitter
91
- });
92
- form.dispatchEvent(event);
93
- // }
83
+ if (typeof form.requestSubmit === 'function') {
84
+ form.requestSubmit(submitter);
85
+ } else {
86
+ var event = new SubmitEvent('submit', {
87
+ bubbles: true,
88
+ cancelable: true,
89
+ submitter
90
+ });
91
+ form.dispatchEvent(event);
92
+ }
94
93
  }
95
94
 
96
95
  export { getFormAction, getFormEncType, getFormMethod, isFieldElement, isFormControl, requestSubmit };
package/form.d.ts CHANGED
@@ -62,7 +62,7 @@ export type FormOptions<Schema, FormError = string[], FormValue = Schema> = {
62
62
  /**
63
63
  * An object describing the result of the last submission
64
64
  */
65
- lastResult?: SubmissionResult<FormError> | null;
65
+ lastResult?: SubmissionResult<FormError> | null | undefined;
66
66
  /**
67
67
  * Define when conform should start validation.
68
68
  * Support "onSubmit", "onInput", "onBlur".
@@ -90,16 +90,6 @@ export type FormOptions<Schema, FormError = string[], FormValue = Schema> = {
90
90
  submitter: HTMLInputElement | HTMLButtonElement | null;
91
91
  formData: FormData;
92
92
  }) => Submission<Schema, FormError, FormValue>;
93
- /**
94
- * A function to be called before the form is submitted.
95
- */
96
- onSubmit?: (event: SubmitEvent, context: {
97
- formData: FormData;
98
- action: ReturnType<typeof getFormAction>;
99
- encType: ReturnType<typeof getFormEncType>;
100
- method: ReturnType<typeof getFormMethod>;
101
- submission?: Submission<Schema, FormError, FormValue>;
102
- }) => void;
103
93
  };
104
94
  export type SubscriptionSubject = {
105
95
  [key in 'error' | 'initialValue' | 'value' | 'key' | 'valid' | 'dirty']?: SubscriptionScope;
@@ -116,9 +106,15 @@ export type ControlButtonProps = {
116
106
  form: string;
117
107
  formNoValidate: boolean;
118
108
  };
119
- export type FormContext<Schema extends Record<string, any> = any, FormValue = Schema, FormError = string[]> = {
109
+ export type FormContext<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema> = {
120
110
  formId: string;
121
- submit(event: SubmitEvent): Submission<Schema, FormError, FormValue> | undefined;
111
+ submit(event: SubmitEvent): {
112
+ formData: FormData;
113
+ action: ReturnType<typeof getFormAction>;
114
+ encType: ReturnType<typeof getFormEncType>;
115
+ method: ReturnType<typeof getFormMethod>;
116
+ submission?: Submission<Schema, FormError, FormValue>;
117
+ };
122
118
  onReset(event: Event): void;
123
119
  onInput(event: Event): void;
124
120
  onBlur(event: Event): void;
@@ -143,5 +139,5 @@ export type FormContext<Schema extends Record<string, any> = any, FormValue = Sc
143
139
  }>['payload']): ControlButtonProps;
144
140
  };
145
141
  };
146
- export declare function createFormContext<Schema extends Record<string, any>, FormValue, FormError>(options: FormOptions<Schema, FormError, FormValue>): FormContext<Schema, FormValue, FormError>;
142
+ export declare function createFormContext<Schema extends Record<string, any>, FormError = string[], FormValue = Schema>(options: FormOptions<Schema, FormError, FormValue>): FormContext<Schema, FormError, FormValue>;
147
143
  export {};
package/form.js CHANGED
@@ -145,7 +145,7 @@ function createKeyProxy(key) {
145
145
  if (typeof parentKey === 'undefined') {
146
146
  return currentKey;
147
147
  }
148
- return "".concat(parentKey, "/").concat(currentKey !== null && currentKey !== void 0 ? currentKey : name);
148
+ return "".concat(parentKey, "/").concat(currentKey !== null && currentKey !== void 0 ? currentKey : paths.at(-1));
149
149
  });
150
150
  }
151
151
  function createValidProxy(error) {
@@ -292,16 +292,14 @@ function createFormContext(options) {
292
292
  // To ensure it capturing latest state before parsing
293
293
  input.value = getSerializedState();
294
294
  var formData = formdata.getFormData(form, submitter);
295
- var context = {
295
+ var result = {
296
296
  formData,
297
297
  action: dom.getFormAction(event),
298
298
  encType: dom.getFormEncType(event),
299
299
  method: dom.getFormMethod(event)
300
300
  };
301
301
  if (typeof (latestOptions === null || latestOptions === void 0 ? void 0 : latestOptions.onValidate) === 'undefined') {
302
- var _latestOptions$onSubm;
303
- (_latestOptions$onSubm = latestOptions.onSubmit) === null || _latestOptions$onSubm === void 0 || _latestOptions$onSubm.call(latestOptions, event, context);
304
- return;
302
+ return result;
305
303
  }
306
304
  var submission = latestOptions.onValidate({
307
305
  form,
@@ -310,13 +308,10 @@ function createFormContext(options) {
310
308
  });
311
309
  if (submission.status !== 'success' && submission.error !== null) {
312
310
  report(submission.reply());
313
- } else {
314
- var _latestOptions$onSubm2;
315
- (_latestOptions$onSubm2 = latestOptions.onSubmit) === null || _latestOptions$onSubm2 === void 0 || _latestOptions$onSubm2.call(latestOptions, event, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, context), {}, {
316
- submission
317
- }));
318
311
  }
319
- return submission;
312
+ return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, result), {}, {
313
+ submission
314
+ });
320
315
  }
321
316
  function resolveTarget(event) {
322
317
  var form = getFormElement();
package/form.mjs CHANGED
@@ -141,7 +141,7 @@ function createKeyProxy(key) {
141
141
  if (typeof parentKey === 'undefined') {
142
142
  return currentKey;
143
143
  }
144
- return "".concat(parentKey, "/").concat(currentKey !== null && currentKey !== void 0 ? currentKey : name);
144
+ return "".concat(parentKey, "/").concat(currentKey !== null && currentKey !== void 0 ? currentKey : paths.at(-1));
145
145
  });
146
146
  }
147
147
  function createValidProxy(error) {
@@ -288,16 +288,14 @@ function createFormContext(options) {
288
288
  // To ensure it capturing latest state before parsing
289
289
  input.value = getSerializedState();
290
290
  var formData = getFormData(form, submitter);
291
- var context = {
291
+ var result = {
292
292
  formData,
293
293
  action: getFormAction(event),
294
294
  encType: getFormEncType(event),
295
295
  method: getFormMethod(event)
296
296
  };
297
297
  if (typeof (latestOptions === null || latestOptions === void 0 ? void 0 : latestOptions.onValidate) === 'undefined') {
298
- var _latestOptions$onSubm;
299
- (_latestOptions$onSubm = latestOptions.onSubmit) === null || _latestOptions$onSubm === void 0 || _latestOptions$onSubm.call(latestOptions, event, context);
300
- return;
298
+ return result;
301
299
  }
302
300
  var submission = latestOptions.onValidate({
303
301
  form,
@@ -306,13 +304,10 @@ function createFormContext(options) {
306
304
  });
307
305
  if (submission.status !== 'success' && submission.error !== null) {
308
306
  report(submission.reply());
309
- } else {
310
- var _latestOptions$onSubm2;
311
- (_latestOptions$onSubm2 = latestOptions.onSubmit) === null || _latestOptions$onSubm2 === void 0 || _latestOptions$onSubm2.call(latestOptions, event, _objectSpread2(_objectSpread2({}, context), {}, {
312
- submission
313
- }));
314
307
  }
315
- return submission;
308
+ return _objectSpread2(_objectSpread2({}, result), {}, {
309
+ submission
310
+ });
316
311
  }
317
312
  function resolveTarget(event) {
318
313
  var form = getFormElement();
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-pre.7",
6
+ "version": "1.0.0-rc.1",
7
7
  "main": "index.js",
8
8
  "module": "index.mjs",
9
9
  "types": "index.d.ts",