@danderson00/react-forms 0.0.41 → 0.0.43
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/dist/ErrorMessage.js +0 -5
- package/dist/ErrorMessage.js.map +1 -1
- package/dist/Form.js +26 -69
- package/dist/Form.js.map +1 -1
- package/dist/Group.js +5 -17
- package/dist/Group.js.map +1 -1
- package/dist/index.js +3 -28
- package/dist/index.js.map +1 -1
- package/dist/injectCss.js +0 -2
- package/dist/injectCss.js.map +1 -1
- package/dist/input.js +73 -118
- package/dist/input.js.map +1 -1
- package/dist/inputTypes.js +7 -17
- package/dist/inputTypes.js.map +1 -1
- package/dist/styles.js +0 -2
- package/dist/styles.js.map +1 -1
- package/dist/submit.js +14 -37
- package/dist/submit.js.map +1 -1
- package/dist/throttle.js +0 -3
- package/dist/throttle.js.map +1 -1
- package/dist/useForm.js +2 -6
- package/dist/useForm.js.map +1 -1
- package/dist/useFormValues.js +0 -3
- package/dist/useFormValues.js.map +1 -1
- package/dist/usePrevious.js +0 -2
- package/dist/usePrevious.js.map +1 -1
- package/dist/useUpdate.js +0 -2
- package/dist/useUpdate.js.map +1 -1
- package/package.json +3 -3
- package/src/Form.js +6 -6
- package/src/input.js +24 -16
package/dist/submit.js
CHANGED
|
@@ -1,69 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
9
|
var _excluded = ["onSubmit", "registerFieldValidator", "setFieldValue", "getFieldValue", "getFieldValues", "valid", "validate", "disableInvalid", "values"];
|
|
13
|
-
|
|
14
10
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
-
|
|
20
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
|
|
22
14
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
-
|
|
24
15
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
-
|
|
26
16
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
27
|
-
|
|
28
17
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
-
|
|
30
18
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
31
|
-
|
|
32
19
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
33
|
-
|
|
34
20
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
|
-
|
|
36
21
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
37
|
-
|
|
38
22
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
39
|
-
|
|
40
23
|
var _default = function _default(render) {
|
|
41
24
|
return function Submit(props) {
|
|
42
25
|
if (!props.onSubmit) throw new Error('Button components must be contained within a Form component');
|
|
43
|
-
|
|
44
26
|
var onSubmit = props.onSubmit,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
27
|
+
registerFieldValidator = props.registerFieldValidator,
|
|
28
|
+
setFieldValue = props.setFieldValue,
|
|
29
|
+
getFieldValue = props.getFieldValue,
|
|
30
|
+
getFieldValues = props.getFieldValues,
|
|
31
|
+
valid = props.valid,
|
|
32
|
+
validate = props.validate,
|
|
33
|
+
disableInvalid = props.disableInvalid,
|
|
34
|
+
values = props.values,
|
|
35
|
+
propsToPass = _objectWithoutProperties(props, _excluded);
|
|
36
|
+
|
|
37
|
+
// TODO: set executing when form is triggered by enter key
|
|
56
38
|
var _useState = (0, _react.useState)(false),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
40
|
+
executing = _useState2[0],
|
|
41
|
+
setExecuting = _useState2[1];
|
|
61
42
|
var onClick = function onClick(e) {
|
|
62
43
|
var result = onSubmit(e, {
|
|
63
44
|
validate: validate,
|
|
64
45
|
additionalValues: values
|
|
65
46
|
});
|
|
66
|
-
|
|
67
47
|
if (result && result["finally"] && typeof result["finally"] === 'function') {
|
|
68
48
|
setExecuting(true);
|
|
69
49
|
result["finally"](function () {
|
|
@@ -71,15 +51,12 @@ var _default = function _default(render) {
|
|
|
71
51
|
});
|
|
72
52
|
}
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
var finalProps = _objectSpread(_objectSpread({}, propsToPass), {}, {
|
|
76
55
|
onClick: onClick,
|
|
77
56
|
disabled: props.disabled || executing || disableInvalid && !valid
|
|
78
57
|
});
|
|
79
|
-
|
|
80
58
|
return render(finalProps);
|
|
81
59
|
};
|
|
82
60
|
};
|
|
83
|
-
|
|
84
61
|
exports["default"] = _default;
|
|
85
62
|
//# sourceMappingURL=submit.js.map
|
package/dist/submit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submit.js","names":["render","Submit","props","onSubmit","Error","registerFieldValidator","setFieldValue","getFieldValue","getFieldValues","valid","validate","disableInvalid","values","propsToPass","useState","executing","setExecuting","onClick","e","result","additionalValues","finalProps","disabled"],"sources":["../src/submit.js"],"sourcesContent":["import React, { useState } from 'react'\n\nexport default render => function Submit(props) {\n if(!props.onSubmit) throw new Error('Button components must be contained within a Form component')\n\n const {\n onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,\n valid, validate, disableInvalid, values, ...propsToPass\n } = props\n\n // TODO: set executing when form is triggered by enter key\n const [executing, setExecuting] = useState(false)\n\n const onClick = e => {\n const result = onSubmit(e, { validate, additionalValues: values })\n if(result && result.finally && typeof result.finally === 'function') {\n setExecuting(true)\n result.finally(() => setExecuting(false))\n }\n }\n\n const finalProps = {\n ...propsToPass,\n onClick,\n disabled: props.disabled || executing || (disableInvalid && !valid)\n }\n\n return render(finalProps)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"submit.js","names":["render","Submit","props","onSubmit","Error","registerFieldValidator","setFieldValue","getFieldValue","getFieldValues","valid","validate","disableInvalid","values","propsToPass","useState","executing","setExecuting","onClick","e","result","additionalValues","finalProps","disabled"],"sources":["../src/submit.js"],"sourcesContent":["import React, { useState } from 'react'\n\nexport default render => function Submit(props) {\n if(!props.onSubmit) throw new Error('Button components must be contained within a Form component')\n\n const {\n onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,\n valid, validate, disableInvalid, values, ...propsToPass\n } = props\n\n // TODO: set executing when form is triggered by enter key\n const [executing, setExecuting] = useState(false)\n\n const onClick = e => {\n const result = onSubmit(e, { validate, additionalValues: values })\n if(result && result.finally && typeof result.finally === 'function') {\n setExecuting(true)\n result.finally(() => setExecuting(false))\n }\n }\n\n const finalProps = {\n ...propsToPass,\n onClick,\n disabled: props.disabled || executing || (disableInvalid && !valid)\n }\n\n return render(finalProps)\n}\n"],"mappings":";;;;;;;AAAA;AAAuC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAExB,kBAAAA,MAAM;EAAA,OAAI,SAASC,MAAM,CAACC,KAAK,EAAE;IAC9C,IAAG,CAACA,KAAK,CAACC,QAAQ,EAAE,MAAM,IAAIC,KAAK,CAAC,6DAA6D,CAAC;IAElG,IACED,QAAQ,GAEND,KAAK,CAFPC,QAAQ;MAAEE,sBAAsB,GAE9BH,KAAK,CAFGG,sBAAsB;MAAEC,aAAa,GAE7CJ,KAAK,CAF2BI,aAAa;MAAEC,aAAa,GAE5DL,KAAK,CAF0CK,aAAa;MAAEC,cAAc,GAE5EN,KAAK,CAFyDM,cAAc;MAC9EC,KAAK,GACHP,KAAK,CADPO,KAAK;MAAEC,QAAQ,GACbR,KAAK,CADAQ,QAAQ;MAAEC,cAAc,GAC7BT,KAAK,CADUS,cAAc;MAAEC,MAAM,GACrCV,KAAK,CAD0BU,MAAM;MAAKC,WAAW,4BACrDX,KAAK;;IAET;IACA,gBAAkC,IAAAY,eAAQ,EAAC,KAAK,CAAC;MAAA;MAA1CC,SAAS;MAAEC,YAAY;IAE9B,IAAMC,OAAO,GAAG,SAAVA,OAAO,CAAGC,CAAC,EAAI;MACnB,IAAMC,MAAM,GAAGhB,QAAQ,CAACe,CAAC,EAAE;QAAER,QAAQ,EAARA,QAAQ;QAAEU,gBAAgB,EAAER;MAAO,CAAC,CAAC;MAClE,IAAGO,MAAM,IAAIA,MAAM,WAAQ,IAAI,OAAOA,MAAM,WAAQ,KAAK,UAAU,EAAE;QACnEH,YAAY,CAAC,IAAI,CAAC;QAClBG,MAAM,WAAQ,CAAC;UAAA,OAAMH,YAAY,CAAC,KAAK,CAAC;QAAA,EAAC;MAC3C;IACF,CAAC;IAED,IAAMK,UAAU,mCACXR,WAAW;MACdI,OAAO,EAAPA,OAAO;MACPK,QAAQ,EAAEpB,KAAK,CAACoB,QAAQ,IAAIP,SAAS,IAAKJ,cAAc,IAAI,CAACF;IAAM,EACpE;IAED,OAAOT,MAAM,CAACqB,UAAU,CAAC;EAC3B,CAAC;AAAA;AAAA"}
|
package/dist/throttle.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _default = function _default(target) {
|
|
9
8
|
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
|
|
10
9
|
var timeout;
|
|
@@ -12,13 +11,11 @@ var _default = function _default(target) {
|
|
|
12
11
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
13
12
|
args[_key] = arguments[_key];
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
clearTimeout(timeout);
|
|
17
15
|
timeout = setTimeout(function () {
|
|
18
16
|
return target.apply(void 0, args);
|
|
19
17
|
}, delay);
|
|
20
18
|
};
|
|
21
19
|
};
|
|
22
|
-
|
|
23
20
|
exports["default"] = _default;
|
|
24
21
|
//# sourceMappingURL=throttle.js.map
|
package/dist/throttle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttle.js","names":["target","delay","timeout","args","clearTimeout","setTimeout"],"sources":["../src/throttle.js"],"sourcesContent":["export default (target, delay = 200) => {\n let timeout\n\n return (...args) => {\n clearTimeout(timeout)\n timeout = setTimeout(\n () => target(...args),\n delay\n )\n }\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"throttle.js","names":["target","delay","timeout","args","clearTimeout","setTimeout"],"sources":["../src/throttle.js"],"sourcesContent":["export default (target, delay = 200) => {\n let timeout\n\n return (...args) => {\n clearTimeout(timeout)\n timeout = setTimeout(\n () => target(...args),\n delay\n )\n }\n}"],"mappings":";;;;;;eAAe,kBAACA,MAAM,EAAkB;EAAA,IAAhBC,KAAK,uEAAG,GAAG;EACjC,IAAIC,OAAO;EAEX,OAAO,YAAa;IAAA,kCAATC,IAAI;MAAJA,IAAI;IAAA;IACbC,YAAY,CAACF,OAAO,CAAC;IACrBA,OAAO,GAAGG,UAAU,CAClB;MAAA,OAAML,MAAM,eAAIG,IAAI,CAAC;IAAA,GACrBF,KAAK,CACN;EACH,CAAC;AACH,CAAC;AAAA"}
|
package/dist/useForm.js
CHANGED
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _default = function _default(context) {
|
|
11
9
|
return function useForm() {
|
|
12
10
|
var _useContext = (0, _react.useContext)(context),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
onSubmit = _useContext.onSubmit,
|
|
12
|
+
getFieldValues = _useContext.getFieldValues;
|
|
16
13
|
return {
|
|
17
14
|
submit: function submit(options) {
|
|
18
15
|
return onSubmit(undefined, options);
|
|
@@ -23,6 +20,5 @@ var _default = function _default(context) {
|
|
|
23
20
|
};
|
|
24
21
|
};
|
|
25
22
|
};
|
|
26
|
-
|
|
27
23
|
exports["default"] = _default;
|
|
28
24
|
//# sourceMappingURL=useForm.js.map
|
package/dist/useForm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.js","names":["context","useForm","useContext","onSubmit","getFieldValues","submit","options","undefined","values"],"sources":["../src/useForm.js"],"sourcesContent":["import { useContext } from 'react'\n\nexport default context => function useForm() {\n const { onSubmit, getFieldValues } = useContext(context)\n\n return {\n submit: options => onSubmit(undefined, options),\n values: () => getFieldValues()\n }\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useForm.js","names":["context","useForm","useContext","onSubmit","getFieldValues","submit","options","undefined","values"],"sources":["../src/useForm.js"],"sourcesContent":["import { useContext } from 'react'\n\nexport default context => function useForm() {\n const { onSubmit, getFieldValues } = useContext(context)\n\n return {\n submit: options => onSubmit(undefined, options),\n values: () => getFieldValues()\n }\n}"],"mappings":";;;;;;AAAA;AAAkC,eAEnB,kBAAAA,OAAO;EAAA,OAAI,SAASC,OAAO,GAAG;IAC3C,kBAAqC,IAAAC,iBAAU,EAACF,OAAO,CAAC;MAAhDG,QAAQ,eAARA,QAAQ;MAAEC,cAAc,eAAdA,cAAc;IAEhC,OAAO;MACLC,MAAM,EAAE,gBAAAC,OAAO;QAAA,OAAIH,QAAQ,CAACI,SAAS,EAAED,OAAO,CAAC;MAAA;MAC/CE,MAAM,EAAE;QAAA,OAAMJ,cAAc,EAAE;MAAA;IAChC,CAAC;EACH,CAAC;AAAA;AAAA"}
|
package/dist/useFormValues.js
CHANGED
|
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _default = function _default(context) {
|
|
11
9
|
return function useFormValues() {
|
|
12
10
|
return (0, _react.useContext)(context).getFieldValues();
|
|
13
11
|
};
|
|
14
12
|
};
|
|
15
|
-
|
|
16
13
|
exports["default"] = _default;
|
|
17
14
|
//# sourceMappingURL=useFormValues.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormValues.js","names":["context","useFormValues","useContext","getFieldValues"],"sources":["../src/useFormValues.js"],"sourcesContent":["import { useContext } from 'react'\n\nexport default context => function useFormValues() {\n return useContext(context).getFieldValues()\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFormValues.js","names":["context","useFormValues","useContext","getFieldValues"],"sources":["../src/useFormValues.js"],"sourcesContent":["import { useContext } from 'react'\n\nexport default context => function useFormValues() {\n return useContext(context).getFieldValues()\n}"],"mappings":";;;;;;AAAA;AAAkC,eAEnB,kBAAAA,OAAO;EAAA,OAAI,SAASC,aAAa,GAAG;IACjD,OAAO,IAAAC,iBAAU,EAACF,OAAO,CAAC,CAACG,cAAc,EAAE;EAC7C,CAAC;AAAA;AAAA"}
|
package/dist/usePrevious.js
CHANGED
package/dist/usePrevious.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrevious.js","names":["usePrevious","value","ref","useRef","useEffect","current"],"sources":["../src/usePrevious.js"],"sourcesContent":["import { useRef, useEffect } from 'react'\n\nexport default function usePrevious(value) {\n const ref = useRef()\n useEffect(() => {\n ref.current = value\n })\n return ref.current\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePrevious.js","names":["usePrevious","value","ref","useRef","useEffect","current"],"sources":["../src/usePrevious.js"],"sourcesContent":["import { useRef, useEffect } from 'react'\n\nexport default function usePrevious(value) {\n const ref = useRef()\n useEffect(() => {\n ref.current = value\n })\n return ref.current\n}"],"mappings":";;;;;;AAAA;AAEe,SAASA,WAAW,CAACC,KAAK,EAAE;EACzC,IAAMC,GAAG,GAAG,IAAAC,aAAM,GAAE;EACpB,IAAAC,gBAAS,EAAC,YAAM;IACdF,GAAG,CAACG,OAAO,GAAGJ,KAAK;EACrB,CAAC,CAAC;EACF,OAAOC,GAAG,CAACG,OAAO;AACpB"}
|
package/dist/useUpdate.js
CHANGED
package/dist/useUpdate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpdate.js","names":["useUpdate","hook","inputs","didMountRef","useRef","useEffect","current"],"sources":["../src/useUpdate.js"],"sourcesContent":["import { useRef, useEffect } from 'react'\n\nexport default function useUpdate(hook, inputs) {\n const didMountRef = useRef(false)\n\n useEffect(() => {\n if (didMountRef.current)\n hook()\n else\n didMountRef.current = true\n }, inputs)\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUpdate.js","names":["useUpdate","hook","inputs","didMountRef","useRef","useEffect","current"],"sources":["../src/useUpdate.js"],"sourcesContent":["import { useRef, useEffect } from 'react'\n\nexport default function useUpdate(hook, inputs) {\n const didMountRef = useRef(false)\n\n useEffect(() => {\n if (didMountRef.current)\n hook()\n else\n didMountRef.current = true\n }, inputs)\n}"],"mappings":";;;;;;AAAA;AAEe,SAASA,SAAS,CAACC,IAAI,EAAEC,MAAM,EAAE;EAC9C,IAAMC,WAAW,GAAG,IAAAC,aAAM,EAAC,KAAK,CAAC;EAEjC,IAAAC,gBAAS,EAAC,YAAM;IACd,IAAIF,WAAW,CAACG,OAAO,EACrBL,IAAI,EAAE,MAENE,WAAW,CAACG,OAAO,GAAG,IAAI;EAC9B,CAAC,EAAEJ,MAAM,CAAC;AACZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danderson00/react-forms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
4
4
|
"description": "Ultra simple, stateless, validated forms for use in React function components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"babel-jest": "26.6.3",
|
|
25
25
|
"enzyme": "^3.9.0",
|
|
26
26
|
"jest": "26.6.3",
|
|
27
|
-
"react": "^
|
|
28
|
-
"react-dom": "^
|
|
27
|
+
"react": "^18.2.0",
|
|
28
|
+
"react-dom": "^18.2.0"
|
|
29
29
|
},
|
|
30
30
|
"jest": {
|
|
31
31
|
"moduleNameMapper": {
|
package/src/Form.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createElement, createRef, useEffect, useReducer, useState } from 'react'
|
|
1
|
+
import { createElement, createRef, useCallback, useEffect, useReducer, useState } from 'react'
|
|
2
2
|
import { get, set } from 'object-path-immutable'
|
|
3
3
|
|
|
4
4
|
const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
@@ -15,8 +15,8 @@ const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
15
15
|
}
|
|
16
16
|
}, [form.current])
|
|
17
17
|
|
|
18
|
-
const getFieldValue = path => get(fieldValues, path)
|
|
19
|
-
const getFieldValues = () => fieldValues
|
|
18
|
+
const getFieldValue = useCallback(path => get(fieldValues, path), [fieldValues])
|
|
19
|
+
const getFieldValues = useCallback(() => fieldValues, [fieldValues])
|
|
20
20
|
const mapFieldValues = target => Object.keys(target).reduce(
|
|
21
21
|
(values, name) => set(values, name, target[name]),
|
|
22
22
|
{}
|
|
@@ -29,9 +29,9 @@ const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const onSubmit = (e, { additionalValues, validate } = {}) => {
|
|
32
|
+
const onSubmit = useCallback((e, { additionalValues, validate } = {}) => {
|
|
33
33
|
if(validate !== false) {
|
|
34
|
-
fieldValidators.forEach(setFieldValidated => setFieldValidated())
|
|
34
|
+
fieldValidators.forEach(setFieldValidated => setFieldValidated(undefined, fieldValues))
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if((validate === false || form.current.checkValidity()) && props.onSubmit) {
|
|
@@ -73,7 +73,7 @@ const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
73
73
|
|
|
74
74
|
e && e.preventDefault && e.preventDefault()
|
|
75
75
|
e && e.stopPropagation && e.stopPropagation()
|
|
76
|
-
}
|
|
76
|
+
}, [props, fieldValues])
|
|
77
77
|
|
|
78
78
|
const classNames = ['react-forms', props.className]
|
|
79
79
|
if(row) {
|
package/src/input.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react'
|
|
1
|
+
import { useCallback, useState, useEffect } from 'react'
|
|
2
2
|
import usePrevious from './usePrevious'
|
|
3
3
|
import useUpdate from './useUpdate'
|
|
4
4
|
import types from './inputTypes'
|
|
@@ -27,8 +27,8 @@ export default (render, options = {}) => function Input(props) {
|
|
|
27
27
|
// don't override values that were set from passing a values prop to the form
|
|
28
28
|
if(getFieldValue(name) === undefined) {
|
|
29
29
|
// TODO: change setter to a getter and return a private `UNSET` symbol to indicate not to call the field setter
|
|
30
|
-
//
|
|
31
|
-
//
|
|
30
|
+
// this allows us to set the default value with useState above and not have an initial render cycle without the default value
|
|
31
|
+
// BUT... to get the default value of a select list, we need to render it first? dilemma....
|
|
32
32
|
|
|
33
33
|
setInitialValue({
|
|
34
34
|
// pass a setter function - radio buttons do not always want to set a value!
|
|
@@ -52,8 +52,25 @@ export default (render, options = {}) => function Input(props) {
|
|
|
52
52
|
}
|
|
53
53
|
}, [props])
|
|
54
54
|
|
|
55
|
+
const updateValidationState = useCallback((newValue, oldValues) => {
|
|
56
|
+
const { getValidationMessage, getFieldValue, getFieldValues } = props
|
|
57
|
+
const element = document.querySelector(`#${id}`)
|
|
58
|
+
const validationMessage = getValidationMessage && getValidationMessage(
|
|
59
|
+
newValue === undefined ? getFieldValue(name) : newValue,
|
|
60
|
+
oldValues || getFieldValues()
|
|
61
|
+
)
|
|
62
|
+
element.setCustomValidity(validationMessage || "")
|
|
63
|
+
|
|
64
|
+
setFieldValidated(true)
|
|
65
|
+
// this is a little hacky, but the simplest way I could think of to determine the
|
|
66
|
+
// validity of the actual input element. :invalid is also not supported by enzyme
|
|
67
|
+
const invalid = !!validationMessage || Boolean(document.querySelector(`#${id}:invalid`))
|
|
68
|
+
setError(invalid)
|
|
69
|
+
props.onValidated && props.onValidated(!invalid)
|
|
70
|
+
}, [props])
|
|
71
|
+
|
|
55
72
|
// TODO: refactor bubbling to prop pattern
|
|
56
|
-
const onChange = (...args) => {
|
|
73
|
+
const onChange = useCallback((...args) => {
|
|
57
74
|
const [event] = args
|
|
58
75
|
const { setFieldValue, onChange, submitOnChange } = props
|
|
59
76
|
const { valueFromEvent } = options
|
|
@@ -67,7 +84,7 @@ export default (render, options = {}) => function Input(props) {
|
|
|
67
84
|
|
|
68
85
|
if(event && event.target && event.target.checkValidity) {
|
|
69
86
|
event.target.checkValidity()
|
|
70
|
-
updateValidationState()
|
|
87
|
+
updateValidationState(applyValueTransforms(elementValue))
|
|
71
88
|
}
|
|
72
89
|
|
|
73
90
|
if(onChange) {
|
|
@@ -79,7 +96,7 @@ export default (render, options = {}) => function Input(props) {
|
|
|
79
96
|
// setting state requires an additional render cycle - we need to pass in the new value so it's set correctly
|
|
80
97
|
submitHandler(undefined, { additionalValues: { [name]: applyValueTransforms(elementValue) } })
|
|
81
98
|
}
|
|
82
|
-
}
|
|
99
|
+
}, [props.setFieldValue, props.onChange, props.submitOnChange, props.setFieldValue, updateValidationState])
|
|
83
100
|
|
|
84
101
|
const onBlur = (...args) => {
|
|
85
102
|
const { submitOnBlur, onSubmit, onBlur } = props
|
|
@@ -126,21 +143,12 @@ export default (render, options = {}) => function Input(props) {
|
|
|
126
143
|
}
|
|
127
144
|
}
|
|
128
145
|
|
|
129
|
-
const updateValidationState = () => {
|
|
130
|
-
setFieldValidated(true)
|
|
131
|
-
// this is a little hacky, but the simplest way I could think of to determine the
|
|
132
|
-
// validity of the actual input element. :invalid is also not supported by enzyme
|
|
133
|
-
const invalid = Boolean(document.querySelector(`#${id}:invalid`))
|
|
134
|
-
setError(invalid)
|
|
135
|
-
props.onValidated && props.onValidated(!invalid)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
146
|
/* render */ {
|
|
139
147
|
const { passErrorProp } = options
|
|
140
148
|
const { getValueProps } = types(props, options)
|
|
141
149
|
|
|
142
150
|
const {
|
|
143
|
-
type, value, checked, defaultValue, numeric,
|
|
151
|
+
type, value, checked, defaultValue, numeric, getValidationMessage,
|
|
144
152
|
onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,
|
|
145
153
|
submitOnChange, submitOnBlur, selectOnFocus, throttle, valid, onValidated,
|
|
146
154
|
...passThroughProps
|