@conform-to/react 0.1.0 → 0.3.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.
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,48 +1,53 @@
1
1
  function input(config) {
2
- var _config$initialValue, _config$constraint, _config$constraint2, _config$constraint3, _config$constraint4, _config$constraint5, _config$constraint6, _config$constraint7;
3
-
4
2
  var {
5
3
  type,
6
4
  value
7
5
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8
6
  var isCheckboxOrRadio = type === 'checkbox' || type === 'radio';
9
- return {
7
+ var attributes = {
10
8
  type,
11
9
  name: config.name,
12
10
  form: config.form,
13
- value: isCheckboxOrRadio ? value : undefined,
14
- defaultValue: !isCheckboxOrRadio ? "".concat((_config$initialValue = config.initialValue) !== null && _config$initialValue !== void 0 ? _config$initialValue : '') : undefined,
15
- defaultChecked: isCheckboxOrRadio ? config.initialValue === value : undefined,
16
- required: (_config$constraint = config.constraint) === null || _config$constraint === void 0 ? void 0 : _config$constraint.required,
17
- minLength: (_config$constraint2 = config.constraint) === null || _config$constraint2 === void 0 ? void 0 : _config$constraint2.minLength,
18
- maxLength: (_config$constraint3 = config.constraint) === null || _config$constraint3 === void 0 ? void 0 : _config$constraint3.maxLength,
19
- min: (_config$constraint4 = config.constraint) === null || _config$constraint4 === void 0 ? void 0 : _config$constraint4.min,
20
- max: (_config$constraint5 = config.constraint) === null || _config$constraint5 === void 0 ? void 0 : _config$constraint5.max,
21
- step: (_config$constraint6 = config.constraint) === null || _config$constraint6 === void 0 ? void 0 : _config$constraint6.step,
22
- 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
23
19
  };
20
+
21
+ if (isCheckboxOrRadio) {
22
+ attributes.value = value !== null && value !== void 0 ? value : 'on';
23
+ attributes.defaultChecked = config.defaultValue === attributes.value;
24
+ } else {
25
+ attributes.defaultValue = config.defaultValue;
26
+ }
27
+
28
+ return attributes;
24
29
  }
25
30
  function select(config) {
26
- var _config$initialValue2, _config$constraint8, _config$constraint9;
31
+ var _config$defaultValue;
27
32
 
28
33
  return {
29
34
  name: config.name,
30
35
  form: config.form,
31
- defaultValue: "".concat((_config$initialValue2 = config.initialValue) !== null && _config$initialValue2 !== void 0 ? _config$initialValue2 : ''),
32
- required: (_config$constraint8 = config.constraint) === null || _config$constraint8 === void 0 ? void 0 : _config$constraint8.required,
33
- 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
34
39
  };
35
40
  }
36
41
  function textarea(config) {
37
- var _config$initialValue3, _config$constraint10, _config$constraint11, _config$constraint12;
42
+ var _config$defaultValue2;
38
43
 
39
44
  return {
40
45
  name: config.name,
41
46
  form: config.form,
42
- defaultValue: "".concat((_config$initialValue3 = config.initialValue) !== null && _config$initialValue3 !== void 0 ? _config$initialValue3 : ''),
43
- required: (_config$constraint10 = config.constraint) === null || _config$constraint10 === void 0 ? void 0 : _config$constraint10.required,
44
- minLength: (_config$constraint11 = config.constraint) === null || _config$constraint11 === void 0 ? void 0 : _config$constraint11.minLength,
45
- 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
46
51
  };
47
52
  }
48
53