@conform-to/react 0.1.1 → 0.3.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/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { type FieldConfig, type Schema, parse, getFieldElements, } from '@conform-to/dom';
1
+ export { type FormState, type FieldsetConstraint, type Schema, type Submission, createSubmission, createValidate, } from '@conform-to/dom';
2
2
  export * from './hooks';
3
3
  export * as conform from './helpers';
package/index.js CHANGED
@@ -8,13 +8,13 @@ var helpers = require('./helpers.js');
8
8
 
9
9
 
10
10
 
11
- Object.defineProperty(exports, 'getFieldElements', {
11
+ Object.defineProperty(exports, 'createSubmission', {
12
12
  enumerable: true,
13
- get: function () { return dom.getFieldElements; }
13
+ get: function () { return dom.createSubmission; }
14
14
  });
15
- Object.defineProperty(exports, 'parse', {
15
+ Object.defineProperty(exports, 'createValidate', {
16
16
  enumerable: true,
17
- get: function () { return dom.parse; }
17
+ get: function () { return dom.createValidate; }
18
18
  });
19
19
  exports.useControlledInput = hooks.useControlledInput;
20
20
  exports.useFieldList = hooks.useFieldList;
package/module/helpers.js CHANGED
@@ -1,6 +1,4 @@
1
1
  function input(config) {
2
- var _config$constraint, _config$constraint2, _config$constraint3, _config$constraint4, _config$constraint5, _config$constraint6, _config$constraint7;
3
-
4
2
  var {
5
3
  type,
6
4
  value
@@ -10,47 +8,46 @@ function input(config) {
10
8
  type,
11
9
  name: config.name,
12
10
  form: config.form,
13
- required: (_config$constraint = config.constraint) === null || _config$constraint === void 0 ? void 0 : _config$constraint.required,
14
- minLength: (_config$constraint2 = config.constraint) === null || _config$constraint2 === void 0 ? void 0 : _config$constraint2.minLength,
15
- maxLength: (_config$constraint3 = config.constraint) === null || _config$constraint3 === void 0 ? void 0 : _config$constraint3.maxLength,
16
- min: (_config$constraint4 = config.constraint) === null || _config$constraint4 === void 0 ? void 0 : _config$constraint4.min,
17
- max: (_config$constraint5 = config.constraint) === null || _config$constraint5 === void 0 ? void 0 : _config$constraint5.max,
18
- step: (_config$constraint6 = config.constraint) === null || _config$constraint6 === void 0 ? void 0 : _config$constraint6.step,
19
- pattern: (_config$constraint7 = config.constraint) === null || _config$constraint7 === void 0 ? void 0 : _config$constraint7.pattern
11
+ required: config.required,
12
+ minLength: config.minLength,
13
+ maxLength: config.maxLength,
14
+ min: config.min,
15
+ max: config.max,
16
+ step: config.step,
17
+ pattern: config.pattern,
18
+ multiple: config.multiple
20
19
  };
21
20
 
22
21
  if (isCheckboxOrRadio) {
23
22
  attributes.value = value !== null && value !== void 0 ? value : 'on';
24
- attributes.defaultChecked = config.initialValue === attributes.value;
23
+ attributes.defaultChecked = config.defaultValue === attributes.value;
25
24
  } else {
26
- var _config$initialValue;
27
-
28
- attributes.defaultValue = "".concat((_config$initialValue = config.initialValue) !== null && _config$initialValue !== void 0 ? _config$initialValue : '');
25
+ attributes.defaultValue = config.defaultValue;
29
26
  }
30
27
 
31
28
  return attributes;
32
29
  }
33
30
  function select(config) {
34
- var _config$initialValue2, _config$constraint8, _config$constraint9;
31
+ var _config$defaultValue;
35
32
 
36
33
  return {
37
34
  name: config.name,
38
35
  form: config.form,
39
- defaultValue: "".concat((_config$initialValue2 = config.initialValue) !== null && _config$initialValue2 !== void 0 ? _config$initialValue2 : ''),
40
- required: (_config$constraint8 = config.constraint) === null || _config$constraint8 === void 0 ? void 0 : _config$constraint8.required,
41
- multiple: (_config$constraint9 = config.constraint) === null || _config$constraint9 === void 0 ? void 0 : _config$constraint9.multiple
36
+ defaultValue: config.multiple ? Array.isArray(config.defaultValue) ? config.defaultValue : [] : "".concat((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : ''),
37
+ required: config.required,
38
+ multiple: config.multiple
42
39
  };
43
40
  }
44
41
  function textarea(config) {
45
- var _config$initialValue3, _config$constraint10, _config$constraint11, _config$constraint12;
42
+ var _config$defaultValue2;
46
43
 
47
44
  return {
48
45
  name: config.name,
49
46
  form: config.form,
50
- defaultValue: "".concat((_config$initialValue3 = config.initialValue) !== null && _config$initialValue3 !== void 0 ? _config$initialValue3 : ''),
51
- required: (_config$constraint10 = config.constraint) === null || _config$constraint10 === void 0 ? void 0 : _config$constraint10.required,
52
- minLength: (_config$constraint11 = config.constraint) === null || _config$constraint11 === void 0 ? void 0 : _config$constraint11.minLength,
53
- maxLength: (_config$constraint12 = config.constraint) === null || _config$constraint12 === void 0 ? void 0 : _config$constraint12.maxLength
47
+ defaultValue: "".concat((_config$defaultValue2 = config.defaultValue) !== null && _config$defaultValue2 !== void 0 ? _config$defaultValue2 : ''),
48
+ required: config.required,
49
+ minLength: config.minLength,
50
+ maxLength: config.maxLength
54
51
  };
55
52
  }
56
53