@conform-to/react 0.6.3 → 0.7.0-pre.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.
@@ -1,3 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
1
5
  function ownKeys(object, enumerableOnly) {
2
6
  var keys = Object.keys(object);
3
7
  if (Object.getOwnPropertySymbols) {
@@ -48,4 +52,7 @@ function _toPropertyKey(arg) {
48
52
  return typeof key === "symbol" ? key : String(key);
49
53
  }
50
54
 
51
- export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
55
+ exports.defineProperty = _defineProperty;
56
+ exports.objectSpread2 = _objectSpread2;
57
+ exports.toPrimitive = _toPrimitive;
58
+ exports.toPropertyKey = _toPropertyKey;
@@ -1,7 +1,3 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
1
  function ownKeys(object, enumerableOnly) {
6
2
  var keys = Object.keys(object);
7
3
  if (Object.getOwnPropertySymbols) {
@@ -52,7 +48,4 @@ function _toPropertyKey(arg) {
52
48
  return typeof key === "symbol" ? key : String(key);
53
49
  }
54
50
 
55
- exports.defineProperty = _defineProperty;
56
- exports.objectSpread2 = _objectSpread2;
57
- exports.toPrimitive = _toPrimitive;
58
- exports.toPropertyKey = _toPropertyKey;
51
+ export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
@@ -1,6 +1,10 @@
1
- import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.js';
2
- export { INTENT } from '@conform-to/dom';
3
- export { VALIDATION_SKIPPED, VALIDATION_UNDEFINED } from './hooks.js';
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.cjs');
6
+ var dom = require('@conform-to/dom');
7
+ var hooks = require('./hooks.cjs');
4
8
 
5
9
  /**
6
10
  * Style to make the input element visually hidden
@@ -47,7 +51,7 @@ function getFormControlProps(config, options) {
47
51
  }
48
52
  function input(config) {
49
53
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
50
- var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
54
+ var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
51
55
  type: options.type,
52
56
  minLength: config.minLength,
53
57
  maxLength: config.maxLength,
@@ -67,14 +71,14 @@ function input(config) {
67
71
  return props;
68
72
  }
69
73
  function select(config, options) {
70
- var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
74
+ var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
71
75
  defaultValue: config.defaultValue,
72
76
  multiple: config.multiple
73
77
  });
74
78
  return props;
75
79
  }
76
80
  function textarea(config, options) {
77
- var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
81
+ var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
78
82
  defaultValue: config.defaultValue,
79
83
  minLength: config.minLength,
80
84
  maxLength: config.maxLength
@@ -82,4 +86,12 @@ function textarea(config, options) {
82
86
  return props;
83
87
  }
84
88
 
85
- export { input, select, textarea };
89
+ Object.defineProperty(exports, 'INTENT', {
90
+ enumerable: true,
91
+ get: function () { return dom.INTENT; }
92
+ });
93
+ exports.VALIDATION_SKIPPED = hooks.VALIDATION_SKIPPED;
94
+ exports.VALIDATION_UNDEFINED = hooks.VALIDATION_UNDEFINED;
95
+ exports.input = input;
96
+ exports.select = select;
97
+ exports.textarea = textarea;
package/helpers.js CHANGED
@@ -1,10 +1,6 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
6
- var dom = require('@conform-to/dom');
7
- var hooks = require('./hooks.js');
1
+ import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.js';
2
+ export { INTENT } from '@conform-to/dom';
3
+ export { VALIDATION_SKIPPED, VALIDATION_UNDEFINED } from './hooks.js';
8
4
 
9
5
  /**
10
6
  * Style to make the input element visually hidden
@@ -51,7 +47,7 @@ function getFormControlProps(config, options) {
51
47
  }
52
48
  function input(config) {
53
49
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
54
- var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
50
+ var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
55
51
  type: options.type,
56
52
  minLength: config.minLength,
57
53
  maxLength: config.maxLength,
@@ -71,14 +67,14 @@ function input(config) {
71
67
  return props;
72
68
  }
73
69
  function select(config, options) {
74
- var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
70
+ var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
75
71
  defaultValue: config.defaultValue,
76
72
  multiple: config.multiple
77
73
  });
78
74
  return props;
79
75
  }
80
76
  function textarea(config, options) {
81
- var props = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
77
+ var props = _objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
82
78
  defaultValue: config.defaultValue,
83
79
  minLength: config.minLength,
84
80
  maxLength: config.maxLength
@@ -86,12 +82,4 @@ function textarea(config, options) {
86
82
  return props;
87
83
  }
88
84
 
89
- Object.defineProperty(exports, 'INTENT', {
90
- enumerable: true,
91
- get: function () { return dom.INTENT; }
92
- });
93
- exports.VALIDATION_SKIPPED = hooks.VALIDATION_SKIPPED;
94
- exports.VALIDATION_UNDEFINED = hooks.VALIDATION_UNDEFINED;
95
- exports.input = input;
96
- exports.select = select;
97
- exports.textarea = textarea;
85
+ export { input, select, textarea };
@@ -1,6 +1,10 @@
1
- import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.js';
2
- import { getScope, getFormData, parse, isSubmitting, getFormAction, getFormEncType, getFormMethod, getPaths, getName, isFieldElement, getErrors, getFormControls, getFormElement, parseListCommand, updateList, getValidationMessage, focusFormControl, focusFirstInvalidControl, INTENT, isFocusableFormControl, requestIntent, validate } from '@conform-to/dom';
3
- import { useState, useMemo, useEffect, useRef, useCallback, useLayoutEffect } from 'react';
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.cjs');
6
+ var dom = require('@conform-to/dom');
7
+ var react = require('react');
4
8
 
5
9
  /**
6
10
  * Normalize error to an array of string.
@@ -13,40 +17,40 @@ function normalizeError(error) {
13
17
  return [].concat(error);
14
18
  }
15
19
  function useNoValidate(defaultNoValidate, validateBeforeHydrate) {
16
- var [noValidate, setNoValidate] = useState(defaultNoValidate || !validateBeforeHydrate);
17
- useEffect(() => {
20
+ var [noValidate, setNoValidate] = react.useState(defaultNoValidate || !validateBeforeHydrate);
21
+ react.useEffect(() => {
18
22
  setNoValidate(true);
19
23
  }, []);
20
24
  return noValidate;
21
25
  }
22
26
  function useFormRef(userProvidedRef) {
23
- var formRef = useRef(null);
27
+ var formRef = react.useRef(null);
24
28
  return userProvidedRef !== null && userProvidedRef !== void 0 ? userProvidedRef : formRef;
25
29
  }
26
30
  function useConfigRef(config) {
27
- var ref = useRef(config);
31
+ var ref = react.useRef(config);
28
32
  useSafeLayoutEffect(() => {
29
33
  ref.current = config;
30
34
  });
31
35
  return ref;
32
36
  }
33
37
  function useFormReporter(ref, lastSubmission) {
34
- var [submission, setSubmission] = useState(lastSubmission);
35
- var report = useCallback((form, submission) => {
38
+ var [submission, setSubmission] = react.useState(lastSubmission);
39
+ var report = react.useCallback((form, submission) => {
36
40
  var event = new CustomEvent('conform', {
37
41
  detail: submission.intent
38
42
  });
39
43
  form.dispatchEvent(event);
40
44
  setSubmission(submission);
41
45
  }, []);
42
- useEffect(() => {
46
+ react.useEffect(() => {
43
47
  var form = ref.current;
44
48
  if (!form || !lastSubmission) {
45
49
  return;
46
50
  }
47
51
  report(form, lastSubmission);
48
52
  }, [ref, lastSubmission, report]);
49
- useEffect(() => {
53
+ react.useEffect(() => {
50
54
  var form = ref.current;
51
55
  if (!form || !submission) {
52
56
  return;
@@ -56,30 +60,30 @@ function useFormReporter(ref, lastSubmission) {
56
60
  return report;
57
61
  }
58
62
  function useFormError(ref, config) {
59
- var [error, setError] = useState(() => {
63
+ var [error, setError] = react.useState(() => {
60
64
  if (!config.initialError) {
61
65
  return {};
62
66
  }
63
67
  var result = {};
64
68
  for (var [name, message] of Object.entries(config.initialError)) {
65
- var paths = getPaths(name);
69
+ var paths = dom.getPaths(name);
66
70
  if (paths.length === 1) {
67
71
  result[paths[0]] = normalizeError(message);
68
72
  }
69
73
  }
70
74
  return result;
71
75
  });
72
- useEffect(() => {
76
+ react.useEffect(() => {
73
77
  var handleInvalid = event => {
74
- var form = getFormElement(ref.current);
78
+ var form = dom.getFormElement(ref.current);
75
79
  var element = event.target;
76
- if (!isFieldElement(element) || element.form !== form || !element.dataset.conformTouched) {
80
+ if (!dom.isFieldElement(element) || element.form !== form || !element.dataset.conformTouched) {
77
81
  return;
78
82
  }
79
83
  var key = element.name;
80
84
  if (config.name) {
81
- var scopePaths = getPaths(config.name);
82
- var fieldPaths = getPaths(element.name);
85
+ var scopePaths = dom.getPaths(config.name);
86
+ var fieldPaths = dom.getPaths(element.name);
83
87
  for (var i = 0; i <= scopePaths.length; i++) {
84
88
  var path = fieldPaths[i];
85
89
  if (i < scopePaths.length) {
@@ -93,17 +97,17 @@ function useFormError(ref, config) {
93
97
  }
94
98
  }
95
99
  setError(prev => {
96
- if (element.validationMessage === getValidationMessage(prev[key])) {
100
+ if (element.validationMessage === dom.getValidationMessage(prev[key])) {
97
101
  return prev;
98
102
  }
99
- return _objectSpread2(_objectSpread2({}, prev), {}, {
100
- [key]: getErrors(element.validationMessage)
103
+ return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, prev), {}, {
104
+ [key]: dom.getErrors(element.validationMessage)
101
105
  });
102
106
  });
103
107
  event.preventDefault();
104
108
  };
105
109
  var handleReset = event => {
106
- var form = getFormElement(ref.current);
110
+ var form = dom.getFormElement(ref.current);
107
111
  if (form && event.target === form) {
108
112
  setError({});
109
113
  }
@@ -131,16 +135,16 @@ function useForm() {
131
135
  var ref = useFormRef(config.ref);
132
136
  var noValidate = useNoValidate(config.noValidate, config.fallbackNative);
133
137
  var report = useFormReporter(ref, config.lastSubmission);
134
- var [errors, setErrors] = useState(() => {
138
+ var [errors, setErrors] = react.useState(() => {
135
139
  var _config$lastSubmissio;
136
140
  return normalizeError((_config$lastSubmissio = config.lastSubmission) === null || _config$lastSubmissio === void 0 ? void 0 : _config$lastSubmissio.error['']);
137
141
  });
138
- var initialError = useMemo(() => {
142
+ var initialError = react.useMemo(() => {
139
143
  var submission = config.lastSubmission;
140
144
  if (!submission) {
141
145
  return {};
142
146
  }
143
- var scope = getScope(submission.intent);
147
+ var scope = dom.getScope(submission.intent);
144
148
  return scope === null ? submission.error : {
145
149
  [scope]: submission.error[scope]
146
150
  };
@@ -151,7 +155,7 @@ function useForm() {
151
155
  constraint: config.constraint,
152
156
  form: config.id
153
157
  });
154
- useEffect(() => {
158
+ react.useEffect(() => {
155
159
  // custom validate handler
156
160
  var createValidateHandler = name => event => {
157
161
  var field = event.target;
@@ -161,22 +165,22 @@ function useForm() {
161
165
  shouldValidate = initialReport === 'onChange' ? 'onInput' : initialReport,
162
166
  shouldRevalidate = 'onInput'
163
167
  } = configRef.current;
164
- if (!form || !isFocusableFormControl(field) || field.form !== form || !field.name) {
168
+ if (!form || !dom.isFocusableFormControl(field) || field.form !== form || !field.name) {
165
169
  return;
166
170
  }
167
171
  if (field.dataset.conformTouched ? shouldRevalidate === name : shouldValidate === name) {
168
- requestIntent(form, validate(field.name));
172
+ dom.requestIntent(form, dom.validate(field.name));
169
173
  }
170
174
  };
171
175
  var handleInvalid = event => {
172
176
  var form = ref.current;
173
177
  var field = event.target;
174
- if (!form || !isFieldElement(field) || field.form !== form || field.name !== FORM_ERROR_ELEMENT_NAME) {
178
+ if (!form || !dom.isFieldElement(field) || field.form !== form || field.name !== FORM_ERROR_ELEMENT_NAME) {
175
179
  return;
176
180
  }
177
181
  event.preventDefault();
178
182
  if (field.dataset.conformTouched) {
179
- setErrors(getErrors(field.validationMessage));
183
+ setErrors(dom.getErrors(field.validationMessage));
180
184
  }
181
185
  };
182
186
  var handleReset = event => {
@@ -186,7 +190,7 @@ function useForm() {
186
190
  }
187
191
 
188
192
  // Reset all field state
189
- for (var element of getFormControls(form)) {
193
+ for (var element of dom.getFormControls(form)) {
190
194
  delete element.dataset.conformTouched;
191
195
  element.setCustomValidity('');
192
196
  }
@@ -221,11 +225,11 @@ function useForm() {
221
225
  }
222
226
  try {
223
227
  var _config$onValidate, _config$onValidate2;
224
- var formData = getFormData(form, submitter);
228
+ var formData = dom.getFormData(form, submitter);
225
229
  var submission = (_config$onValidate = (_config$onValidate2 = config.onValidate) === null || _config$onValidate2 === void 0 ? void 0 : _config$onValidate2.call(config, {
226
230
  form,
227
231
  formData
228
- })) !== null && _config$onValidate !== void 0 ? _config$onValidate : parse(formData);
232
+ })) !== null && _config$onValidate !== void 0 ? _config$onValidate : dom.parse(formData);
229
233
  var messages = Object.entries(submission.error).reduce((messages, _ref2) => {
230
234
  var [, message] = _ref2;
231
235
  return messages.concat(normalizeError(message));
@@ -234,7 +238,7 @@ function useForm() {
234
238
  var shouldFallbackToServer = messages.includes(VALIDATION_UNDEFINED);
235
239
  var hasClientValidation = typeof config.onValidate !== 'undefined';
236
240
  var isValid = messages.length === 0;
237
- if (hasClientValidation && (isSubmitting(submission.intent) ? shouldValidate && !isValid : !shouldFallbackToServer)) {
241
+ if (hasClientValidation && (dom.isSubmitting(submission.intent) ? shouldValidate && !isValid : !shouldFallbackToServer)) {
238
242
  report(form, submission);
239
243
  event.preventDefault();
240
244
  } else {
@@ -242,9 +246,9 @@ function useForm() {
242
246
  (_config$onSubmit = config.onSubmit) === null || _config$onSubmit === void 0 ? void 0 : _config$onSubmit.call(config, event, {
243
247
  formData,
244
248
  submission,
245
- action: getFormAction(nativeEvent),
246
- encType: getFormEncType(nativeEvent),
247
- method: getFormMethod(nativeEvent)
249
+ action: dom.getFormAction(nativeEvent),
250
+ encType: dom.getFormEncType(nativeEvent),
251
+ method: dom.getFormMethod(nativeEvent)
248
252
  });
249
253
  }
250
254
  } catch (e) {
@@ -291,13 +295,13 @@ function useFieldset(ref, config) {
291
295
  var errors = error === null || error === void 0 ? void 0 : error[key];
292
296
  var initialError = Object.entries((_fieldsetConfig$initi = fieldsetConfig.initialError) !== null && _fieldsetConfig$initi !== void 0 ? _fieldsetConfig$initi : {}).reduce((result, _ref3) => {
293
297
  var [name, message] = _ref3;
294
- var [field, ...paths] = getPaths(name);
298
+ var [field, ...paths] = dom.getPaths(name);
295
299
  if (field === key) {
296
- result[getName(paths)] = message;
300
+ result[dom.getName(paths)] = message;
297
301
  }
298
302
  return result;
299
303
  }, {});
300
- var field = _objectSpread2(_objectSpread2({}, constraint), {}, {
304
+ var field = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, constraint), {}, {
301
305
  name: fieldsetConfig.name ? "".concat(fieldsetConfig.name, ".").concat(key) : key,
302
306
  // @ts-expect-error The FieldValue type might need a rework
303
307
  defaultValue: (_fieldsetConfig$defau = fieldsetConfig.defaultValue) === null || _fieldsetConfig$defau === void 0 ? void 0 : _fieldsetConfig$defau[key],
@@ -327,17 +331,17 @@ function useFieldList(ref, config) {
327
331
  initialError: config.initialError,
328
332
  name: config.name
329
333
  });
330
- var [entries, setEntries] = useState(() => {
334
+ var [entries, setEntries] = react.useState(() => {
331
335
  var _config$defaultValue;
332
336
  return Object.entries((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : [undefined]);
333
337
  });
334
- useEffect(() => {
338
+ react.useEffect(() => {
335
339
  var conformHandler = event => {
336
- var form = getFormElement(ref.current);
340
+ var form = dom.getFormElement(ref.current);
337
341
  if (!form || event.target !== form) {
338
342
  return;
339
343
  }
340
- var command = parseListCommand(event.detail);
344
+ var command = dom.parseListCommand(event.detail);
341
345
  if ((command === null || command === void 0 ? void 0 : command.scope) !== configRef.current.name) {
342
346
  // Ensure the scope of the listener are limited to specific field name
343
347
  return;
@@ -347,8 +351,8 @@ function useFieldList(ref, config) {
347
351
  case 'append':
348
352
  case 'prepend':
349
353
  case 'replace':
350
- return updateList([...(entries !== null && entries !== void 0 ? entries : [])], _objectSpread2(_objectSpread2({}, command), {}, {
351
- payload: _objectSpread2(_objectSpread2({}, command.payload), {}, {
354
+ return dom.updateList([...(entries !== null && entries !== void 0 ? entries : [])], _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command), {}, {
355
+ payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command.payload), {}, {
352
356
  defaultValue: ["".concat(Date.now()),
353
357
  // @ts-expect-error unknown type as it is sent through network
354
358
  command.payload.defaultValue]
@@ -356,7 +360,7 @@ function useFieldList(ref, config) {
356
360
  }));
357
361
  default:
358
362
  {
359
- return updateList([...(entries !== null && entries !== void 0 ? entries : [])], command);
363
+ return dom.updateList([...(entries !== null && entries !== void 0 ? entries : [])], command);
360
364
  }
361
365
  }
362
366
  });
@@ -371,15 +375,15 @@ function useFieldList(ref, config) {
371
375
  case 'append':
372
376
  case 'prepend':
373
377
  case 'replace':
374
- errorList = updateList(errorList, _objectSpread2(_objectSpread2({}, command), {}, {
375
- payload: _objectSpread2(_objectSpread2({}, command.payload), {}, {
378
+ errorList = dom.updateList(errorList, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command), {}, {
379
+ payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command.payload), {}, {
376
380
  defaultValue: undefined
377
381
  })
378
382
  }));
379
383
  break;
380
384
  default:
381
385
  {
382
- errorList = updateList(errorList, command);
386
+ errorList = dom.updateList(errorList, command);
383
387
  break;
384
388
  }
385
389
  }
@@ -388,7 +392,7 @@ function useFieldList(ref, config) {
388
392
  };
389
393
  var resetHandler = event => {
390
394
  var _configRef$current$de;
391
- var form = getFormElement(ref.current);
395
+ var form = dom.getFormElement(ref.current);
392
396
  if (!form || event.target !== form) {
393
397
  return;
394
398
  }
@@ -410,9 +414,9 @@ function useFieldList(ref, config) {
410
414
  var errors = error[index];
411
415
  var initialError = Object.entries((_config$initialError = config.initialError) !== null && _config$initialError !== void 0 ? _config$initialError : {}).reduce((result, _ref5) => {
412
416
  var [name, message] = _ref5;
413
- var [field, ...paths] = getPaths(name);
417
+ var [field, ...paths] = dom.getPaths(name);
414
418
  if (field === index) {
415
- result[getName(paths)] = message;
419
+ result[dom.getName(paths)] = message;
416
420
  }
417
421
  return result;
418
422
  }, {});
@@ -429,7 +433,7 @@ function useFieldList(ref, config) {
429
433
  fieldConfig.errorId = "".concat(fieldConfig.id, "-error");
430
434
  fieldConfig.descriptionId = "".concat(fieldConfig.id, "-description");
431
435
  }
432
- return _objectSpread2({
436
+ return _rollupPluginBabelHelpers.objectSpread2({
433
437
  key
434
438
  }, fieldConfig);
435
439
  });
@@ -468,13 +472,13 @@ function setNativeValue(element, value) {
468
472
  * useLayoutEffect is client-only.
469
473
  * This basically makes it a no-op on server
470
474
  */
471
- var useSafeLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;
475
+ var useSafeLayoutEffect = typeof document === 'undefined' ? react.useEffect : react.useLayoutEffect;
472
476
  function useInputEvent(options) {
473
- var ref = useRef(null);
477
+ var ref = react.useRef(null);
474
478
  var optionsRef = useConfigRef(options);
475
- var changeDispatched = useRef(false);
476
- var focusDispatched = useRef(false);
477
- var blurDispatched = useRef(false);
479
+ var changeDispatched = react.useRef(false);
480
+ var focusDispatched = react.useRef(false);
481
+ var blurDispatched = react.useRef(false);
478
482
  useSafeLayoutEffect(() => {
479
483
  var getInputElement = () => {
480
484
  var _optionsRef$current$g, _optionsRef$current, _optionsRef$current$g2;
@@ -525,7 +529,7 @@ function useInputEvent(options) {
525
529
  document.removeEventListener('reset', resetHandler);
526
530
  };
527
531
  }, []);
528
- var control = useMemo(() => {
532
+ var control = react.useMemo(() => {
529
533
  var getInputElement = () => {
530
534
  var _optionsRef$current$g3, _optionsRef$current4, _optionsRef$current4$;
531
535
  return (_optionsRef$current$g3 = (_optionsRef$current4 = optionsRef.current) === null || _optionsRef$current4 === void 0 ? void 0 : (_optionsRef$current4$ = _optionsRef$current4.getElement) === null || _optionsRef$current4$ === void 0 ? void 0 : _optionsRef$current4$.call(_optionsRef$current4, ref.current)) !== null && _optionsRef$current$g3 !== void 0 ? _optionsRef$current$g3 : ref.current;
@@ -640,12 +644,12 @@ function validateConstraint(options) {
640
644
  } = _ref6;
641
645
  return defaultErrors;
642
646
  };
643
- return parse(formData, {
647
+ return dom.parse(formData, {
644
648
  resolve(payload, intent) {
645
649
  var error = {};
646
650
  var constraintPattern = /^constraint[A-Z][^A-Z]*$/;
647
651
  var _loop = function _loop(element) {
648
- if (isFieldElement(element)) {
652
+ if (dom.isFieldElement(element)) {
649
653
  var _options$acceptMultip, _options$acceptMultip2;
650
654
  var name = element.name !== FORM_ERROR_ELEMENT_NAME ? element.name : '';
651
655
  var constraint = Object.entries(element.dataset).reduce((result, _ref7) => {
@@ -718,8 +722,8 @@ function reportSubmission(form, submission) {
718
722
  form.appendChild(button);
719
723
  }
720
724
  }
721
- var scope = getScope(submission.intent);
722
- for (var element of getFormControls(form)) {
725
+ var scope = dom.getScope(submission.intent);
726
+ for (var element of dom.getFormControls(form)) {
723
727
  var _elementName = element.name !== FORM_ERROR_ELEMENT_NAME ? element.name : '';
724
728
  var messages = normalizeError(submission.error[_elementName]);
725
729
  if (scope === null || scope === _elementName) {
@@ -729,15 +733,15 @@ function reportSubmission(form, submission) {
729
733
  var invalidEvent = new Event('invalid', {
730
734
  cancelable: true
731
735
  });
732
- element.setCustomValidity(getValidationMessage(messages));
736
+ element.setCustomValidity(dom.getValidationMessage(messages));
733
737
  element.dispatchEvent(invalidEvent);
734
738
  }
735
739
  }
736
- if (isSubmitting(submission.intent) || isFocusedOnIntentButton(form, submission.intent)) {
740
+ if (dom.isSubmitting(submission.intent) || isFocusedOnIntentButton(form, submission.intent)) {
737
741
  if (scope) {
738
- focusFormControl(form, scope);
742
+ dom.focusFormControl(form, scope);
739
743
  } else {
740
- focusFirstInvalidControl(form);
744
+ dom.focusFirstInvalidControl(form);
741
745
  }
742
746
  }
743
747
  }
@@ -747,7 +751,16 @@ function reportSubmission(form, submission) {
747
751
  */
748
752
  function isFocusedOnIntentButton(form, intent) {
749
753
  var element = document.activeElement;
750
- return isFieldElement(element) && element.type === 'submit' && element.form === form && element.name === INTENT && element.value === intent;
754
+ return dom.isFieldElement(element) && element.type === 'submit' && element.form === form && element.name === dom.INTENT && element.value === intent;
751
755
  }
752
756
 
753
- export { FORM_ERROR_ELEMENT_NAME, VALIDATION_SKIPPED, VALIDATION_UNDEFINED, isFocusedOnIntentButton, reportSubmission, useFieldList, useFieldset, useForm, useInputEvent, validateConstraint };
757
+ exports.FORM_ERROR_ELEMENT_NAME = FORM_ERROR_ELEMENT_NAME;
758
+ exports.VALIDATION_SKIPPED = VALIDATION_SKIPPED;
759
+ exports.VALIDATION_UNDEFINED = VALIDATION_UNDEFINED;
760
+ exports.isFocusedOnIntentButton = isFocusedOnIntentButton;
761
+ exports.reportSubmission = reportSubmission;
762
+ exports.useFieldList = useFieldList;
763
+ exports.useFieldset = useFieldset;
764
+ exports.useForm = useForm;
765
+ exports.useInputEvent = useInputEvent;
766
+ exports.validateConstraint = validateConstraint;
package/hooks.js CHANGED
@@ -1,10 +1,6 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
6
- var dom = require('@conform-to/dom');
7
- var react = require('react');
1
+ import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.js';
2
+ import { getScope, getFormData, parse, isSubmitting, getFormAction, getFormEncType, getFormMethod, getPaths, getName, isFieldElement, getErrors, getFormControls, getFormElement, parseListCommand, updateList, getValidationMessage, focusFormControl, focusFirstInvalidControl, INTENT, isFocusableFormControl, requestIntent, validate } from '@conform-to/dom';
3
+ import { useState, useMemo, useEffect, useRef, useCallback, useLayoutEffect } from 'react';
8
4
 
9
5
  /**
10
6
  * Normalize error to an array of string.
@@ -17,40 +13,40 @@ function normalizeError(error) {
17
13
  return [].concat(error);
18
14
  }
19
15
  function useNoValidate(defaultNoValidate, validateBeforeHydrate) {
20
- var [noValidate, setNoValidate] = react.useState(defaultNoValidate || !validateBeforeHydrate);
21
- react.useEffect(() => {
16
+ var [noValidate, setNoValidate] = useState(defaultNoValidate || !validateBeforeHydrate);
17
+ useEffect(() => {
22
18
  setNoValidate(true);
23
19
  }, []);
24
20
  return noValidate;
25
21
  }
26
22
  function useFormRef(userProvidedRef) {
27
- var formRef = react.useRef(null);
23
+ var formRef = useRef(null);
28
24
  return userProvidedRef !== null && userProvidedRef !== void 0 ? userProvidedRef : formRef;
29
25
  }
30
26
  function useConfigRef(config) {
31
- var ref = react.useRef(config);
27
+ var ref = useRef(config);
32
28
  useSafeLayoutEffect(() => {
33
29
  ref.current = config;
34
30
  });
35
31
  return ref;
36
32
  }
37
33
  function useFormReporter(ref, lastSubmission) {
38
- var [submission, setSubmission] = react.useState(lastSubmission);
39
- var report = react.useCallback((form, submission) => {
34
+ var [submission, setSubmission] = useState(lastSubmission);
35
+ var report = useCallback((form, submission) => {
40
36
  var event = new CustomEvent('conform', {
41
37
  detail: submission.intent
42
38
  });
43
39
  form.dispatchEvent(event);
44
40
  setSubmission(submission);
45
41
  }, []);
46
- react.useEffect(() => {
42
+ useEffect(() => {
47
43
  var form = ref.current;
48
44
  if (!form || !lastSubmission) {
49
45
  return;
50
46
  }
51
47
  report(form, lastSubmission);
52
48
  }, [ref, lastSubmission, report]);
53
- react.useEffect(() => {
49
+ useEffect(() => {
54
50
  var form = ref.current;
55
51
  if (!form || !submission) {
56
52
  return;
@@ -60,30 +56,30 @@ function useFormReporter(ref, lastSubmission) {
60
56
  return report;
61
57
  }
62
58
  function useFormError(ref, config) {
63
- var [error, setError] = react.useState(() => {
59
+ var [error, setError] = useState(() => {
64
60
  if (!config.initialError) {
65
61
  return {};
66
62
  }
67
63
  var result = {};
68
64
  for (var [name, message] of Object.entries(config.initialError)) {
69
- var paths = dom.getPaths(name);
65
+ var paths = getPaths(name);
70
66
  if (paths.length === 1) {
71
67
  result[paths[0]] = normalizeError(message);
72
68
  }
73
69
  }
74
70
  return result;
75
71
  });
76
- react.useEffect(() => {
72
+ useEffect(() => {
77
73
  var handleInvalid = event => {
78
- var form = dom.getFormElement(ref.current);
74
+ var form = getFormElement(ref.current);
79
75
  var element = event.target;
80
- if (!dom.isFieldElement(element) || element.form !== form || !element.dataset.conformTouched) {
76
+ if (!isFieldElement(element) || element.form !== form || !element.dataset.conformTouched) {
81
77
  return;
82
78
  }
83
79
  var key = element.name;
84
80
  if (config.name) {
85
- var scopePaths = dom.getPaths(config.name);
86
- var fieldPaths = dom.getPaths(element.name);
81
+ var scopePaths = getPaths(config.name);
82
+ var fieldPaths = getPaths(element.name);
87
83
  for (var i = 0; i <= scopePaths.length; i++) {
88
84
  var path = fieldPaths[i];
89
85
  if (i < scopePaths.length) {
@@ -97,17 +93,17 @@ function useFormError(ref, config) {
97
93
  }
98
94
  }
99
95
  setError(prev => {
100
- if (element.validationMessage === dom.getValidationMessage(prev[key])) {
96
+ if (element.validationMessage === getValidationMessage(prev[key])) {
101
97
  return prev;
102
98
  }
103
- return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, prev), {}, {
104
- [key]: dom.getErrors(element.validationMessage)
99
+ return _objectSpread2(_objectSpread2({}, prev), {}, {
100
+ [key]: getErrors(element.validationMessage)
105
101
  });
106
102
  });
107
103
  event.preventDefault();
108
104
  };
109
105
  var handleReset = event => {
110
- var form = dom.getFormElement(ref.current);
106
+ var form = getFormElement(ref.current);
111
107
  if (form && event.target === form) {
112
108
  setError({});
113
109
  }
@@ -135,16 +131,16 @@ function useForm() {
135
131
  var ref = useFormRef(config.ref);
136
132
  var noValidate = useNoValidate(config.noValidate, config.fallbackNative);
137
133
  var report = useFormReporter(ref, config.lastSubmission);
138
- var [errors, setErrors] = react.useState(() => {
134
+ var [errors, setErrors] = useState(() => {
139
135
  var _config$lastSubmissio;
140
136
  return normalizeError((_config$lastSubmissio = config.lastSubmission) === null || _config$lastSubmissio === void 0 ? void 0 : _config$lastSubmissio.error['']);
141
137
  });
142
- var initialError = react.useMemo(() => {
138
+ var initialError = useMemo(() => {
143
139
  var submission = config.lastSubmission;
144
140
  if (!submission) {
145
141
  return {};
146
142
  }
147
- var scope = dom.getScope(submission.intent);
143
+ var scope = getScope(submission.intent);
148
144
  return scope === null ? submission.error : {
149
145
  [scope]: submission.error[scope]
150
146
  };
@@ -155,7 +151,7 @@ function useForm() {
155
151
  constraint: config.constraint,
156
152
  form: config.id
157
153
  });
158
- react.useEffect(() => {
154
+ useEffect(() => {
159
155
  // custom validate handler
160
156
  var createValidateHandler = name => event => {
161
157
  var field = event.target;
@@ -165,22 +161,22 @@ function useForm() {
165
161
  shouldValidate = initialReport === 'onChange' ? 'onInput' : initialReport,
166
162
  shouldRevalidate = 'onInput'
167
163
  } = configRef.current;
168
- if (!form || !dom.isFocusableFormControl(field) || field.form !== form || !field.name) {
164
+ if (!form || !isFocusableFormControl(field) || field.form !== form || !field.name) {
169
165
  return;
170
166
  }
171
167
  if (field.dataset.conformTouched ? shouldRevalidate === name : shouldValidate === name) {
172
- dom.requestIntent(form, dom.validate(field.name));
168
+ requestIntent(form, validate(field.name));
173
169
  }
174
170
  };
175
171
  var handleInvalid = event => {
176
172
  var form = ref.current;
177
173
  var field = event.target;
178
- if (!form || !dom.isFieldElement(field) || field.form !== form || field.name !== FORM_ERROR_ELEMENT_NAME) {
174
+ if (!form || !isFieldElement(field) || field.form !== form || field.name !== FORM_ERROR_ELEMENT_NAME) {
179
175
  return;
180
176
  }
181
177
  event.preventDefault();
182
178
  if (field.dataset.conformTouched) {
183
- setErrors(dom.getErrors(field.validationMessage));
179
+ setErrors(getErrors(field.validationMessage));
184
180
  }
185
181
  };
186
182
  var handleReset = event => {
@@ -190,7 +186,7 @@ function useForm() {
190
186
  }
191
187
 
192
188
  // Reset all field state
193
- for (var element of dom.getFormControls(form)) {
189
+ for (var element of getFormControls(form)) {
194
190
  delete element.dataset.conformTouched;
195
191
  element.setCustomValidity('');
196
192
  }
@@ -225,11 +221,11 @@ function useForm() {
225
221
  }
226
222
  try {
227
223
  var _config$onValidate, _config$onValidate2;
228
- var formData = dom.getFormData(form, submitter);
224
+ var formData = getFormData(form, submitter);
229
225
  var submission = (_config$onValidate = (_config$onValidate2 = config.onValidate) === null || _config$onValidate2 === void 0 ? void 0 : _config$onValidate2.call(config, {
230
226
  form,
231
227
  formData
232
- })) !== null && _config$onValidate !== void 0 ? _config$onValidate : dom.parse(formData);
228
+ })) !== null && _config$onValidate !== void 0 ? _config$onValidate : parse(formData);
233
229
  var messages = Object.entries(submission.error).reduce((messages, _ref2) => {
234
230
  var [, message] = _ref2;
235
231
  return messages.concat(normalizeError(message));
@@ -238,7 +234,7 @@ function useForm() {
238
234
  var shouldFallbackToServer = messages.includes(VALIDATION_UNDEFINED);
239
235
  var hasClientValidation = typeof config.onValidate !== 'undefined';
240
236
  var isValid = messages.length === 0;
241
- if (hasClientValidation && (dom.isSubmitting(submission.intent) ? shouldValidate && !isValid : !shouldFallbackToServer)) {
237
+ if (hasClientValidation && (isSubmitting(submission.intent) ? shouldValidate && !isValid : !shouldFallbackToServer)) {
242
238
  report(form, submission);
243
239
  event.preventDefault();
244
240
  } else {
@@ -246,9 +242,9 @@ function useForm() {
246
242
  (_config$onSubmit = config.onSubmit) === null || _config$onSubmit === void 0 ? void 0 : _config$onSubmit.call(config, event, {
247
243
  formData,
248
244
  submission,
249
- action: dom.getFormAction(nativeEvent),
250
- encType: dom.getFormEncType(nativeEvent),
251
- method: dom.getFormMethod(nativeEvent)
245
+ action: getFormAction(nativeEvent),
246
+ encType: getFormEncType(nativeEvent),
247
+ method: getFormMethod(nativeEvent)
252
248
  });
253
249
  }
254
250
  } catch (e) {
@@ -295,13 +291,13 @@ function useFieldset(ref, config) {
295
291
  var errors = error === null || error === void 0 ? void 0 : error[key];
296
292
  var initialError = Object.entries((_fieldsetConfig$initi = fieldsetConfig.initialError) !== null && _fieldsetConfig$initi !== void 0 ? _fieldsetConfig$initi : {}).reduce((result, _ref3) => {
297
293
  var [name, message] = _ref3;
298
- var [field, ...paths] = dom.getPaths(name);
294
+ var [field, ...paths] = getPaths(name);
299
295
  if (field === key) {
300
- result[dom.getName(paths)] = message;
296
+ result[getName(paths)] = message;
301
297
  }
302
298
  return result;
303
299
  }, {});
304
- var field = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, constraint), {}, {
300
+ var field = _objectSpread2(_objectSpread2({}, constraint), {}, {
305
301
  name: fieldsetConfig.name ? "".concat(fieldsetConfig.name, ".").concat(key) : key,
306
302
  // @ts-expect-error The FieldValue type might need a rework
307
303
  defaultValue: (_fieldsetConfig$defau = fieldsetConfig.defaultValue) === null || _fieldsetConfig$defau === void 0 ? void 0 : _fieldsetConfig$defau[key],
@@ -331,17 +327,17 @@ function useFieldList(ref, config) {
331
327
  initialError: config.initialError,
332
328
  name: config.name
333
329
  });
334
- var [entries, setEntries] = react.useState(() => {
330
+ var [entries, setEntries] = useState(() => {
335
331
  var _config$defaultValue;
336
332
  return Object.entries((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : [undefined]);
337
333
  });
338
- react.useEffect(() => {
334
+ useEffect(() => {
339
335
  var conformHandler = event => {
340
- var form = dom.getFormElement(ref.current);
336
+ var form = getFormElement(ref.current);
341
337
  if (!form || event.target !== form) {
342
338
  return;
343
339
  }
344
- var command = dom.parseListCommand(event.detail);
340
+ var command = parseListCommand(event.detail);
345
341
  if ((command === null || command === void 0 ? void 0 : command.scope) !== configRef.current.name) {
346
342
  // Ensure the scope of the listener are limited to specific field name
347
343
  return;
@@ -351,8 +347,8 @@ function useFieldList(ref, config) {
351
347
  case 'append':
352
348
  case 'prepend':
353
349
  case 'replace':
354
- return dom.updateList([...(entries !== null && entries !== void 0 ? entries : [])], _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command), {}, {
355
- payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command.payload), {}, {
350
+ return updateList([...(entries !== null && entries !== void 0 ? entries : [])], _objectSpread2(_objectSpread2({}, command), {}, {
351
+ payload: _objectSpread2(_objectSpread2({}, command.payload), {}, {
356
352
  defaultValue: ["".concat(Date.now()),
357
353
  // @ts-expect-error unknown type as it is sent through network
358
354
  command.payload.defaultValue]
@@ -360,7 +356,7 @@ function useFieldList(ref, config) {
360
356
  }));
361
357
  default:
362
358
  {
363
- return dom.updateList([...(entries !== null && entries !== void 0 ? entries : [])], command);
359
+ return updateList([...(entries !== null && entries !== void 0 ? entries : [])], command);
364
360
  }
365
361
  }
366
362
  });
@@ -375,15 +371,15 @@ function useFieldList(ref, config) {
375
371
  case 'append':
376
372
  case 'prepend':
377
373
  case 'replace':
378
- errorList = dom.updateList(errorList, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command), {}, {
379
- payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, command.payload), {}, {
374
+ errorList = updateList(errorList, _objectSpread2(_objectSpread2({}, command), {}, {
375
+ payload: _objectSpread2(_objectSpread2({}, command.payload), {}, {
380
376
  defaultValue: undefined
381
377
  })
382
378
  }));
383
379
  break;
384
380
  default:
385
381
  {
386
- errorList = dom.updateList(errorList, command);
382
+ errorList = updateList(errorList, command);
387
383
  break;
388
384
  }
389
385
  }
@@ -392,7 +388,7 @@ function useFieldList(ref, config) {
392
388
  };
393
389
  var resetHandler = event => {
394
390
  var _configRef$current$de;
395
- var form = dom.getFormElement(ref.current);
391
+ var form = getFormElement(ref.current);
396
392
  if (!form || event.target !== form) {
397
393
  return;
398
394
  }
@@ -414,9 +410,9 @@ function useFieldList(ref, config) {
414
410
  var errors = error[index];
415
411
  var initialError = Object.entries((_config$initialError = config.initialError) !== null && _config$initialError !== void 0 ? _config$initialError : {}).reduce((result, _ref5) => {
416
412
  var [name, message] = _ref5;
417
- var [field, ...paths] = dom.getPaths(name);
413
+ var [field, ...paths] = getPaths(name);
418
414
  if (field === index) {
419
- result[dom.getName(paths)] = message;
415
+ result[getName(paths)] = message;
420
416
  }
421
417
  return result;
422
418
  }, {});
@@ -433,7 +429,7 @@ function useFieldList(ref, config) {
433
429
  fieldConfig.errorId = "".concat(fieldConfig.id, "-error");
434
430
  fieldConfig.descriptionId = "".concat(fieldConfig.id, "-description");
435
431
  }
436
- return _rollupPluginBabelHelpers.objectSpread2({
432
+ return _objectSpread2({
437
433
  key
438
434
  }, fieldConfig);
439
435
  });
@@ -472,13 +468,13 @@ function setNativeValue(element, value) {
472
468
  * useLayoutEffect is client-only.
473
469
  * This basically makes it a no-op on server
474
470
  */
475
- var useSafeLayoutEffect = typeof document === 'undefined' ? react.useEffect : react.useLayoutEffect;
471
+ var useSafeLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;
476
472
  function useInputEvent(options) {
477
- var ref = react.useRef(null);
473
+ var ref = useRef(null);
478
474
  var optionsRef = useConfigRef(options);
479
- var changeDispatched = react.useRef(false);
480
- var focusDispatched = react.useRef(false);
481
- var blurDispatched = react.useRef(false);
475
+ var changeDispatched = useRef(false);
476
+ var focusDispatched = useRef(false);
477
+ var blurDispatched = useRef(false);
482
478
  useSafeLayoutEffect(() => {
483
479
  var getInputElement = () => {
484
480
  var _optionsRef$current$g, _optionsRef$current, _optionsRef$current$g2;
@@ -529,7 +525,7 @@ function useInputEvent(options) {
529
525
  document.removeEventListener('reset', resetHandler);
530
526
  };
531
527
  }, []);
532
- var control = react.useMemo(() => {
528
+ var control = useMemo(() => {
533
529
  var getInputElement = () => {
534
530
  var _optionsRef$current$g3, _optionsRef$current4, _optionsRef$current4$;
535
531
  return (_optionsRef$current$g3 = (_optionsRef$current4 = optionsRef.current) === null || _optionsRef$current4 === void 0 ? void 0 : (_optionsRef$current4$ = _optionsRef$current4.getElement) === null || _optionsRef$current4$ === void 0 ? void 0 : _optionsRef$current4$.call(_optionsRef$current4, ref.current)) !== null && _optionsRef$current$g3 !== void 0 ? _optionsRef$current$g3 : ref.current;
@@ -644,12 +640,12 @@ function validateConstraint(options) {
644
640
  } = _ref6;
645
641
  return defaultErrors;
646
642
  };
647
- return dom.parse(formData, {
643
+ return parse(formData, {
648
644
  resolve(payload, intent) {
649
645
  var error = {};
650
646
  var constraintPattern = /^constraint[A-Z][^A-Z]*$/;
651
647
  var _loop = function _loop(element) {
652
- if (dom.isFieldElement(element)) {
648
+ if (isFieldElement(element)) {
653
649
  var _options$acceptMultip, _options$acceptMultip2;
654
650
  var name = element.name !== FORM_ERROR_ELEMENT_NAME ? element.name : '';
655
651
  var constraint = Object.entries(element.dataset).reduce((result, _ref7) => {
@@ -722,8 +718,8 @@ function reportSubmission(form, submission) {
722
718
  form.appendChild(button);
723
719
  }
724
720
  }
725
- var scope = dom.getScope(submission.intent);
726
- for (var element of dom.getFormControls(form)) {
721
+ var scope = getScope(submission.intent);
722
+ for (var element of getFormControls(form)) {
727
723
  var _elementName = element.name !== FORM_ERROR_ELEMENT_NAME ? element.name : '';
728
724
  var messages = normalizeError(submission.error[_elementName]);
729
725
  if (scope === null || scope === _elementName) {
@@ -733,15 +729,15 @@ function reportSubmission(form, submission) {
733
729
  var invalidEvent = new Event('invalid', {
734
730
  cancelable: true
735
731
  });
736
- element.setCustomValidity(dom.getValidationMessage(messages));
732
+ element.setCustomValidity(getValidationMessage(messages));
737
733
  element.dispatchEvent(invalidEvent);
738
734
  }
739
735
  }
740
- if (dom.isSubmitting(submission.intent) || isFocusedOnIntentButton(form, submission.intent)) {
736
+ if (isSubmitting(submission.intent) || isFocusedOnIntentButton(form, submission.intent)) {
741
737
  if (scope) {
742
- dom.focusFormControl(form, scope);
738
+ focusFormControl(form, scope);
743
739
  } else {
744
- dom.focusFirstInvalidControl(form);
740
+ focusFirstInvalidControl(form);
745
741
  }
746
742
  }
747
743
  }
@@ -751,16 +747,7 @@ function reportSubmission(form, submission) {
751
747
  */
752
748
  function isFocusedOnIntentButton(form, intent) {
753
749
  var element = document.activeElement;
754
- return dom.isFieldElement(element) && element.type === 'submit' && element.form === form && element.name === dom.INTENT && element.value === intent;
750
+ return isFieldElement(element) && element.type === 'submit' && element.form === form && element.name === INTENT && element.value === intent;
755
751
  }
756
752
 
757
- exports.FORM_ERROR_ELEMENT_NAME = FORM_ERROR_ELEMENT_NAME;
758
- exports.VALIDATION_SKIPPED = VALIDATION_SKIPPED;
759
- exports.VALIDATION_UNDEFINED = VALIDATION_UNDEFINED;
760
- exports.isFocusedOnIntentButton = isFocusedOnIntentButton;
761
- exports.reportSubmission = reportSubmission;
762
- exports.useFieldList = useFieldList;
763
- exports.useFieldset = useFieldset;
764
- exports.useForm = useForm;
765
- exports.useInputEvent = useInputEvent;
766
- exports.validateConstraint = validateConstraint;
753
+ export { FORM_ERROR_ELEMENT_NAME, VALIDATION_SKIPPED, VALIDATION_UNDEFINED, isFocusedOnIntentButton, reportSubmission, useFieldList, useFieldset, useForm, useInputEvent, validateConstraint };
package/index.cjs ADDED
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var dom = require('@conform-to/dom');
6
+ var hooks = require('./hooks.cjs');
7
+ var helpers = require('./helpers.cjs');
8
+
9
+
10
+
11
+ Object.defineProperty(exports, 'isFieldElement', {
12
+ enumerable: true,
13
+ get: function () { return dom.isFieldElement; }
14
+ });
15
+ Object.defineProperty(exports, 'list', {
16
+ enumerable: true,
17
+ get: function () { return dom.list; }
18
+ });
19
+ Object.defineProperty(exports, 'parse', {
20
+ enumerable: true,
21
+ get: function () { return dom.parse; }
22
+ });
23
+ Object.defineProperty(exports, 'requestIntent', {
24
+ enumerable: true,
25
+ get: function () { return dom.requestIntent; }
26
+ });
27
+ Object.defineProperty(exports, 'validate', {
28
+ enumerable: true,
29
+ get: function () { return dom.validate; }
30
+ });
31
+ exports.useFieldList = hooks.useFieldList;
32
+ exports.useFieldset = hooks.useFieldset;
33
+ exports.useForm = hooks.useForm;
34
+ exports.useInputEvent = hooks.useInputEvent;
35
+ exports.validateConstraint = hooks.validateConstraint;
36
+ exports.conform = helpers;
package/index.js CHANGED
@@ -1,36 +1,4 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var dom = require('@conform-to/dom');
6
- var hooks = require('./hooks.js');
7
- var helpers = require('./helpers.js');
8
-
9
-
10
-
11
- Object.defineProperty(exports, 'isFieldElement', {
12
- enumerable: true,
13
- get: function () { return dom.isFieldElement; }
14
- });
15
- Object.defineProperty(exports, 'list', {
16
- enumerable: true,
17
- get: function () { return dom.list; }
18
- });
19
- Object.defineProperty(exports, 'parse', {
20
- enumerable: true,
21
- get: function () { return dom.parse; }
22
- });
23
- Object.defineProperty(exports, 'requestIntent', {
24
- enumerable: true,
25
- get: function () { return dom.requestIntent; }
26
- });
27
- Object.defineProperty(exports, 'validate', {
28
- enumerable: true,
29
- get: function () { return dom.validate; }
30
- });
31
- exports.useFieldList = hooks.useFieldList;
32
- exports.useFieldset = hooks.useFieldset;
33
- exports.useForm = hooks.useForm;
34
- exports.useInputEvent = hooks.useInputEvent;
35
- exports.validateConstraint = hooks.validateConstraint;
36
- exports.conform = helpers;
1
+ export { isFieldElement, list, parse, requestIntent, validate } from '@conform-to/dom';
2
+ export { useFieldList, useFieldset, useForm, useInputEvent, validateConstraint } from './hooks.js';
3
+ import * as helpers from './helpers.js';
4
+ export { helpers as conform };
package/package.json CHANGED
@@ -3,9 +3,20 @@
3
3
  "description": "Conform view adapter for react",
4
4
  "homepage": "https://conform.guide",
5
5
  "license": "MIT",
6
- "version": "0.6.3",
7
- "main": "index.js",
8
- "module": "module/index.js",
6
+ "version": "0.7.0-pre.0",
7
+ "type": "module",
8
+ "main": "index.cjs",
9
+ "module": "index.js",
10
+ "types": "index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./index.d.ts",
14
+ "module": "./index.js",
15
+ "import": "./index.js",
16
+ "require": "./index.cjs",
17
+ "default": "./index.js"
18
+ }
19
+ },
9
20
  "repository": {
10
21
  "type": "git",
11
22
  "url": "https://github.com/edmundhung/conform",
@@ -20,7 +31,7 @@
20
31
  "url": "https://github.com/edmundhung/conform/issues"
21
32
  },
22
33
  "dependencies": {
23
- "@conform-to/dom": "0.6.3"
34
+ "@conform-to/dom": "0.7.0-pre.0"
24
35
  },
25
36
  "peerDependencies": {
26
37
  "react": ">=16.8"
package/base.d.ts DELETED
File without changes
package/module/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { isFieldElement, list, parse, requestIntent, validate } from '@conform-to/dom';
2
- export { useFieldList, useFieldset, useForm, useInputEvent, validateConstraint } from './hooks.js';
3
- import * as helpers from './helpers.js';
4
- export { helpers as conform };