@conform-to/react 1.0.0-pre.5 → 1.0.0-pre.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -430,7 +430,7 @@ import { Form } from 'react-router-dom';
430
430
  export default function SignupForm() {
431
431
  const [form, { email, password, confirmPassword }] = useForm({
432
432
  onValidate(context) {
433
- // This enables validating each field based on the validity state and custom cosntraint if defined
433
+ // This enables validating each field based on the validity state and custom constraint if defined
434
434
  return validateConstraint(
435
435
  ...context,
436
436
  constraint: {
@@ -37,6 +37,33 @@ function _defineProperty(obj, key, value) {
37
37
  }
38
38
  return obj;
39
39
  }
40
+ function _objectWithoutPropertiesLoose(source, excluded) {
41
+ if (source == null) return {};
42
+ var target = {};
43
+ var sourceKeys = Object.keys(source);
44
+ var key, i;
45
+ for (i = 0; i < sourceKeys.length; i++) {
46
+ key = sourceKeys[i];
47
+ if (excluded.indexOf(key) >= 0) continue;
48
+ target[key] = source[key];
49
+ }
50
+ return target;
51
+ }
52
+ function _objectWithoutProperties(source, excluded) {
53
+ if (source == null) return {};
54
+ var target = _objectWithoutPropertiesLoose(source, excluded);
55
+ var key, i;
56
+ if (Object.getOwnPropertySymbols) {
57
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
58
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
59
+ key = sourceSymbolKeys[i];
60
+ if (excluded.indexOf(key) >= 0) continue;
61
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
62
+ target[key] = source[key];
63
+ }
64
+ }
65
+ return target;
66
+ }
40
67
  function _toPrimitive(input, hint) {
41
68
  if (typeof input !== "object" || input === null) return input;
42
69
  var prim = input[Symbol.toPrimitive];
@@ -54,5 +81,7 @@ function _toPropertyKey(arg) {
54
81
 
55
82
  exports.defineProperty = _defineProperty;
56
83
  exports.objectSpread2 = _objectSpread2;
84
+ exports.objectWithoutProperties = _objectWithoutProperties;
85
+ exports.objectWithoutPropertiesLoose = _objectWithoutPropertiesLoose;
57
86
  exports.toPrimitive = _toPrimitive;
58
87
  exports.toPropertyKey = _toPropertyKey;
@@ -33,6 +33,33 @@ function _defineProperty(obj, key, value) {
33
33
  }
34
34
  return obj;
35
35
  }
36
+ function _objectWithoutPropertiesLoose(source, excluded) {
37
+ if (source == null) return {};
38
+ var target = {};
39
+ var sourceKeys = Object.keys(source);
40
+ var key, i;
41
+ for (i = 0; i < sourceKeys.length; i++) {
42
+ key = sourceKeys[i];
43
+ if (excluded.indexOf(key) >= 0) continue;
44
+ target[key] = source[key];
45
+ }
46
+ return target;
47
+ }
48
+ function _objectWithoutProperties(source, excluded) {
49
+ if (source == null) return {};
50
+ var target = _objectWithoutPropertiesLoose(source, excluded);
51
+ var key, i;
52
+ if (Object.getOwnPropertySymbols) {
53
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
54
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
55
+ key = sourceSymbolKeys[i];
56
+ if (excluded.indexOf(key) >= 0) continue;
57
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
58
+ target[key] = source[key];
59
+ }
60
+ }
61
+ return target;
62
+ }
36
63
  function _toPrimitive(input, hint) {
37
64
  if (typeof input !== "object" || input === null) return input;
38
65
  var prim = input[Symbol.toPrimitive];
@@ -48,4 +75,4 @@ function _toPropertyKey(arg) {
48
75
  return typeof key === "symbol" ? key : String(key);
49
76
  }
50
77
 
51
- export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
78
+ export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2, _objectWithoutProperties as objectWithoutProperties, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
package/hooks.js CHANGED
@@ -7,6 +7,8 @@ var dom = require('@conform-to/dom');
7
7
  var react = require('react');
8
8
  var context = require('./context.js');
9
9
 
10
+ var _excluded = ["id"];
11
+
10
12
  /**
11
13
  * useLayoutEffect is client-only.
12
14
  * This basically makes it a no-op on server
@@ -30,11 +32,14 @@ function useNoValidate() {
30
32
  return noValidate;
31
33
  }
32
34
  function useForm(options) {
33
- var formId = useFormId(options.id);
34
- var [context$1] = react.useState(() => dom.createFormContext(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, options), {}, {
35
+ var {
36
+ id
37
+ } = options,
38
+ formConfig = _rollupPluginBabelHelpers.objectWithoutProperties(options, _excluded);
39
+ var formId = useFormId(id);
40
+ var [context$1] = react.useState(() => dom.createFormContext(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, formConfig), {}, {
35
41
  formId
36
42
  })));
37
- var optionsRef = react.useRef(options);
38
43
  useSafeLayoutEffect(() => {
39
44
  document.addEventListener('input', context$1.input);
40
45
  document.addEventListener('focusout', context$1.blur);
@@ -46,17 +51,7 @@ function useForm(options) {
46
51
  };
47
52
  }, [context$1]);
48
53
  useSafeLayoutEffect(() => {
49
- if (options.lastResult === optionsRef.current.lastResult) {
50
- // If there is no change, do nothing
51
- return;
52
- }
53
- if (options.lastResult) {
54
- context$1.report(options.lastResult);
55
- }
56
- }, [context$1, options.lastResult]);
57
- useSafeLayoutEffect(() => {
58
- optionsRef.current = options;
59
- context$1.update(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, options), {}, {
54
+ context$1.update(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, formConfig), {}, {
60
55
  formId
61
56
  }));
62
57
  });
package/hooks.mjs CHANGED
@@ -1,8 +1,10 @@
1
- import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
1
+ import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
2
  import { createFormContext } from '@conform-to/dom';
3
- import { useState, useRef, useEffect, useLayoutEffect, useId } from 'react';
3
+ import { useState, useEffect, useLayoutEffect, useId } from 'react';
4
4
  import { useSubjectRef, useFormState, getFormMetadata, useFormContext, getFieldMetadata } from './context.mjs';
5
5
 
6
+ var _excluded = ["id"];
7
+
6
8
  /**
7
9
  * useLayoutEffect is client-only.
8
10
  * This basically makes it a no-op on server
@@ -26,11 +28,14 @@ function useNoValidate() {
26
28
  return noValidate;
27
29
  }
28
30
  function useForm(options) {
29
- var formId = useFormId(options.id);
30
- var [context] = useState(() => createFormContext(_objectSpread2(_objectSpread2({}, options), {}, {
31
+ var {
32
+ id
33
+ } = options,
34
+ formConfig = _objectWithoutProperties(options, _excluded);
35
+ var formId = useFormId(id);
36
+ var [context] = useState(() => createFormContext(_objectSpread2(_objectSpread2({}, formConfig), {}, {
31
37
  formId
32
38
  })));
33
- var optionsRef = useRef(options);
34
39
  useSafeLayoutEffect(() => {
35
40
  document.addEventListener('input', context.input);
36
41
  document.addEventListener('focusout', context.blur);
@@ -42,17 +47,7 @@ function useForm(options) {
42
47
  };
43
48
  }, [context]);
44
49
  useSafeLayoutEffect(() => {
45
- if (options.lastResult === optionsRef.current.lastResult) {
46
- // If there is no change, do nothing
47
- return;
48
- }
49
- if (options.lastResult) {
50
- context.report(options.lastResult);
51
- }
52
- }, [context, options.lastResult]);
53
- useSafeLayoutEffect(() => {
54
- optionsRef.current = options;
55
- context.update(_objectSpread2(_objectSpread2({}, options), {}, {
50
+ context.update(_objectSpread2(_objectSpread2({}, formConfig), {}, {
56
51
  formId
57
52
  }));
58
53
  });
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { type Submission, type SubmissionResult, type FormControl, type FormId, type FieldName, requestSubmit, isFieldElement, control, } from '@conform-to/dom';
1
+ export { type Submission, type SubmissionResult, type DefaultValue, type FormControl, type FormId, type FieldName, requestSubmit, isFieldElement, control, } from '@conform-to/dom';
2
2
  export { type FieldMetadata, type FormMetadata, FormProvider, FormStateInput, } from './context';
3
3
  export { useForm, useFormMetadata, useField } from './hooks';
4
4
  export { useInputControl } from './integrations';
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Conform view adapter for react",
4
4
  "homepage": "https://conform.guide",
5
5
  "license": "MIT",
6
- "version": "1.0.0-pre.5",
6
+ "version": "1.0.0-pre.6",
7
7
  "main": "index.js",
8
8
  "module": "index.mjs",
9
9
  "types": "index.d.ts",
@@ -30,7 +30,7 @@
30
30
  "url": "https://github.com/edmundhung/conform/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@conform-to/dom": "1.0.0-pre.5"
33
+ "@conform-to/dom": "1.0.0-pre.6"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/react": "^18.2.43",