@contember/react-form 2.1.0-alpha.36 → 2.1.0-alpha.39
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/development/index.cjs +30 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +30 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/src/components/FormCheckbox.cjs +83 -0
- package/dist/development/src/components/FormCheckbox.cjs.map +1 -0
- package/dist/development/src/components/FormCheckbox.js +67 -0
- package/dist/development/src/components/FormCheckbox.js.map +1 -0
- package/dist/development/src/components/FormError.cjs +22 -0
- package/dist/development/src/components/FormError.cjs.map +1 -0
- package/dist/development/src/components/FormError.js +22 -0
- package/dist/development/src/components/FormError.js.map +1 -0
- package/dist/development/src/components/FormFieldScope.cjs +33 -0
- package/dist/development/src/components/FormFieldScope.cjs.map +1 -0
- package/dist/development/src/components/FormFieldScope.js +33 -0
- package/dist/development/src/components/FormFieldScope.js.map +1 -0
- package/dist/development/src/components/FormFieldStateProvider.cjs +56 -0
- package/dist/development/src/components/FormFieldStateProvider.cjs.map +1 -0
- package/dist/development/src/components/FormFieldStateProvider.js +56 -0
- package/dist/development/src/components/FormFieldStateProvider.js.map +1 -0
- package/dist/development/src/components/FormHasManyRelationScope.cjs +33 -0
- package/dist/development/src/components/FormHasManyRelationScope.cjs.map +1 -0
- package/dist/development/src/components/FormHasManyRelationScope.js +33 -0
- package/dist/development/src/components/FormHasManyRelationScope.js.map +1 -0
- package/dist/development/src/components/FormHasOneRelationScope.cjs +33 -0
- package/dist/development/src/components/FormHasOneRelationScope.cjs.map +1 -0
- package/dist/development/src/components/FormHasOneRelationScope.js +33 -0
- package/dist/development/src/components/FormHasOneRelationScope.js.map +1 -0
- package/dist/development/src/components/FormInput.cjs +62 -0
- package/dist/development/src/components/FormInput.cjs.map +1 -0
- package/dist/development/src/components/FormInput.js +62 -0
- package/dist/development/src/components/FormInput.js.map +1 -0
- package/dist/development/src/components/FormLabel.cjs +34 -0
- package/dist/development/src/components/FormLabel.cjs.map +1 -0
- package/dist/development/src/components/FormLabel.js +34 -0
- package/dist/development/src/components/FormLabel.js.map +1 -0
- package/dist/development/src/components/FormRadioInput.cjs +55 -0
- package/dist/development/src/components/FormRadioInput.cjs.map +1 -0
- package/dist/development/src/components/FormRadioInput.js +55 -0
- package/dist/development/src/components/FormRadioInput.js.map +1 -0
- package/dist/development/src/contexts.cjs +13 -0
- package/dist/development/src/contexts.cjs.map +1 -0
- package/dist/development/src/contexts.js +13 -0
- package/dist/development/src/contexts.js.map +1 -0
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs +80 -0
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs.map +1 -0
- package/dist/development/src/hooks/useFormInputValidationHandler.js +64 -0
- package/dist/development/src/hooks/useFormInputValidationHandler.js.map +1 -0
- package/dist/development/src/internal/useFormInputHandler.cjs +122 -0
- package/dist/development/src/internal/useFormInputHandler.cjs.map +1 -0
- package/dist/development/src/internal/useFormInputHandler.js +122 -0
- package/dist/development/src/internal/useFormInputHandler.js.map +1 -0
- package/dist/production/index.cjs +30 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +30 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/src/components/FormCheckbox.cjs +71 -0
- package/dist/production/src/components/FormCheckbox.cjs.map +1 -0
- package/dist/production/src/components/FormCheckbox.js +55 -0
- package/dist/production/src/components/FormCheckbox.js.map +1 -0
- package/dist/production/src/components/FormError.cjs +22 -0
- package/dist/production/src/components/FormError.cjs.map +1 -0
- package/dist/production/src/components/FormError.js +22 -0
- package/dist/production/src/components/FormError.js.map +1 -0
- package/dist/production/src/components/FormFieldScope.cjs +25 -0
- package/dist/production/src/components/FormFieldScope.cjs.map +1 -0
- package/dist/production/src/components/FormFieldScope.js +25 -0
- package/dist/production/src/components/FormFieldScope.js.map +1 -0
- package/dist/production/src/components/FormFieldStateProvider.cjs +34 -0
- package/dist/production/src/components/FormFieldStateProvider.cjs.map +1 -0
- package/dist/production/src/components/FormFieldStateProvider.js +34 -0
- package/dist/production/src/components/FormFieldStateProvider.js.map +1 -0
- package/dist/production/src/components/FormHasManyRelationScope.cjs +25 -0
- package/dist/production/src/components/FormHasManyRelationScope.cjs.map +1 -0
- package/dist/production/src/components/FormHasManyRelationScope.js +25 -0
- package/dist/production/src/components/FormHasManyRelationScope.js.map +1 -0
- package/dist/production/src/components/FormHasOneRelationScope.cjs +25 -0
- package/dist/production/src/components/FormHasOneRelationScope.cjs.map +1 -0
- package/dist/production/src/components/FormHasOneRelationScope.js +25 -0
- package/dist/production/src/components/FormHasOneRelationScope.js.map +1 -0
- package/dist/production/src/components/FormInput.cjs +50 -0
- package/dist/production/src/components/FormInput.cjs.map +1 -0
- package/dist/production/src/components/FormInput.js +50 -0
- package/dist/production/src/components/FormInput.js.map +1 -0
- package/dist/production/src/components/FormLabel.cjs +26 -0
- package/dist/production/src/components/FormLabel.cjs.map +1 -0
- package/dist/production/src/components/FormLabel.js +26 -0
- package/dist/production/src/components/FormLabel.js.map +1 -0
- package/dist/production/src/components/FormRadioInput.cjs +43 -0
- package/dist/production/src/components/FormRadioInput.cjs.map +1 -0
- package/dist/production/src/components/FormRadioInput.js +43 -0
- package/dist/production/src/components/FormRadioInput.js.map +1 -0
- package/dist/production/src/contexts.cjs +13 -0
- package/dist/production/src/contexts.cjs.map +1 -0
- package/dist/production/src/contexts.js +13 -0
- package/dist/production/src/contexts.js.map +1 -0
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs +80 -0
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs.map +1 -0
- package/dist/production/src/hooks/useFormInputValidationHandler.js +64 -0
- package/dist/production/src/hooks/useFormInputValidationHandler.js.map +1 -0
- package/dist/production/src/internal/useFormInputHandler.cjs +122 -0
- package/dist/production/src/internal/useFormInputHandler.cjs.map +1 -0
- package/dist/production/src/internal/useFormInputHandler.js +122 -0
- package/dist/production/src/internal/useFormInputHandler.js.map +1 -0
- package/dist/types/components/FormCheckbox.d.ts +11 -0
- package/dist/types/components/FormCheckbox.d.ts.map +1 -0
- package/dist/types/components/FormError.d.ts +7 -0
- package/dist/types/components/FormError.d.ts.map +1 -0
- package/dist/types/components/FormFieldScope.d.ts +9 -0
- package/dist/types/components/FormFieldScope.d.ts.map +1 -0
- package/dist/types/components/FormFieldStateProvider.d.ts +36 -0
- package/dist/types/components/FormFieldStateProvider.d.ts.map +1 -0
- package/dist/types/components/FormHasManyRelationScope.d.ts +12 -0
- package/dist/types/components/FormHasManyRelationScope.d.ts.map +1 -0
- package/dist/types/components/FormHasOneRelationScope.d.ts +9 -0
- package/dist/types/components/FormHasOneRelationScope.d.ts.map +1 -0
- package/dist/types/components/FormInput.d.ts +13 -0
- package/dist/types/components/FormInput.d.ts.map +1 -0
- package/dist/types/components/FormLabel.d.ts +5 -0
- package/dist/types/components/FormLabel.d.ts.map +1 -0
- package/dist/types/components/FormRadioInput.d.ts +11 -0
- package/dist/types/components/FormRadioInput.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/contexts.d.ts +12 -0
- package/dist/types/contexts.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/useFormInputValidationHandler.d.ts +8 -0
- package/dist/types/hooks/useFormInputValidationHandler.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/internal/useFormInputHandler.d.ts +4 -0
- package/dist/types/internal/useFormInputHandler.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types/index.d.ts +23 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const reactBinding = require("@contember/react-binding");
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
+
if (e) {
|
|
8
|
+
for (const k in e) {
|
|
9
|
+
if (k !== "default") {
|
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: () => e[k]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
|
+
const useFormInputValidationHandler = (field) => {
|
|
23
|
+
const accessorGetter = field.getAccessor;
|
|
24
|
+
const validationMessage = React.useRef(void 0);
|
|
25
|
+
const [focus, setFocus] = React__namespace.useState(false);
|
|
26
|
+
const inputRef = React__namespace.useRef(null);
|
|
27
|
+
reactBinding.useEntityBeforePersist(React.useCallback(() => {
|
|
28
|
+
if (validationMessage.current) {
|
|
29
|
+
accessorGetter().addError(validationMessage.current);
|
|
30
|
+
}
|
|
31
|
+
}, [accessorGetter]));
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (!inputRef.current) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const input = inputRef.current;
|
|
37
|
+
const valid = input.validity?.valid;
|
|
38
|
+
const message = valid ? void 0 : input?.validationMessage;
|
|
39
|
+
const previousMessage = validationMessage.current;
|
|
40
|
+
validationMessage.current = message;
|
|
41
|
+
const accessor = accessorGetter();
|
|
42
|
+
if (!message) {
|
|
43
|
+
if (previousMessage) {
|
|
44
|
+
clearSpecificError(accessor, previousMessage);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (message === previousMessage) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!field.isTouched) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!focus || !!previousMessage) {
|
|
55
|
+
accessor.clearErrors();
|
|
56
|
+
accessor.addError(message);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
ref: inputRef,
|
|
61
|
+
onFocus: React.useCallback(() => {
|
|
62
|
+
setFocus(true);
|
|
63
|
+
}, []),
|
|
64
|
+
onBlur: React.useCallback(() => {
|
|
65
|
+
setFocus(false);
|
|
66
|
+
accessorGetter().clearErrors();
|
|
67
|
+
if (validationMessage.current) {
|
|
68
|
+
accessorGetter().addError(validationMessage.current);
|
|
69
|
+
}
|
|
70
|
+
}, [accessorGetter])
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
const clearSpecificError = (field, message) => {
|
|
74
|
+
const errors = field.errors?.errors ?? [];
|
|
75
|
+
const error = errors.filter((e) => !(e.type === "validation" && e.message === message));
|
|
76
|
+
field.clearErrors();
|
|
77
|
+
error.forEach((e) => field.addError(e));
|
|
78
|
+
};
|
|
79
|
+
exports.useFormInputValidationHandler = useFormInputValidationHandler;
|
|
80
|
+
//# sourceMappingURL=useFormInputValidationHandler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormInputValidationHandler.cjs","sources":["../../../../../packages/react-form/src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>(undefined)\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tconst previousMessage = validationMessage.current\n\t\tvalidationMessage.current = message\n\n\t\tconst accessor = accessorGetter()\n\t\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\tif (previousMessage) {\n\t\t\t\tclearSpecificError(accessor, previousMessage)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (message === previousMessage) {\n\t\t\treturn\n\t\t}\n\t\t// if the input is not touched, we don't want to show the error message\n\t\tif (!field.isTouched) {\n\t\t\treturn\n\t\t}\n\n\t\t// if the input is not focused, we want to show the error message\n\t\t// also, even the input is focused, we want to replace the previous message\n\t\tif (!focus || !!previousMessage) {\n\t\t\taccessor.clearErrors()\n\t\t\taccessor.addError(message)\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n\nconst clearSpecificError = (field: FieldAccessor<any>, message: string) => {\n\tconst errors = field.errors?.errors ?? []\n\tconst error = errors.filter(e => !(e.type === 'validation' && e.message === message))\n\tfield.clearErrors()\n\terror.forEach(e => field.addError(e))\n}\n"],"names":["useRef","React","useEntityBeforePersist","useCallback","useEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIO,MAAM,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoBA,MAAAA,OAAe,MAAS;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAIC,iBAAM,SAAS,KAAK;AAC9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QAAQ;AACpF,QAAM,YAAA;AACN,QAAM,QAAQ,CAAA,MAAK,MAAM,SAAS,CAAC,CAAC;AACrC;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useRef, useCallback, useEffect } from "react";
|
|
3
|
+
import { useEntityBeforePersist } from "@contember/react-binding";
|
|
4
|
+
const useFormInputValidationHandler = (field) => {
|
|
5
|
+
const accessorGetter = field.getAccessor;
|
|
6
|
+
const validationMessage = useRef(void 0);
|
|
7
|
+
const [focus, setFocus] = React.useState(false);
|
|
8
|
+
const inputRef = React.useRef(null);
|
|
9
|
+
useEntityBeforePersist(useCallback(() => {
|
|
10
|
+
if (validationMessage.current) {
|
|
11
|
+
accessorGetter().addError(validationMessage.current);
|
|
12
|
+
}
|
|
13
|
+
}, [accessorGetter]));
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!inputRef.current) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const input = inputRef.current;
|
|
19
|
+
const valid = input.validity?.valid;
|
|
20
|
+
const message = valid ? void 0 : input?.validationMessage;
|
|
21
|
+
const previousMessage = validationMessage.current;
|
|
22
|
+
validationMessage.current = message;
|
|
23
|
+
const accessor = accessorGetter();
|
|
24
|
+
if (!message) {
|
|
25
|
+
if (previousMessage) {
|
|
26
|
+
clearSpecificError(accessor, previousMessage);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (message === previousMessage) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!field.isTouched) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!focus || !!previousMessage) {
|
|
37
|
+
accessor.clearErrors();
|
|
38
|
+
accessor.addError(message);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
ref: inputRef,
|
|
43
|
+
onFocus: useCallback(() => {
|
|
44
|
+
setFocus(true);
|
|
45
|
+
}, []),
|
|
46
|
+
onBlur: useCallback(() => {
|
|
47
|
+
setFocus(false);
|
|
48
|
+
accessorGetter().clearErrors();
|
|
49
|
+
if (validationMessage.current) {
|
|
50
|
+
accessorGetter().addError(validationMessage.current);
|
|
51
|
+
}
|
|
52
|
+
}, [accessorGetter])
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const clearSpecificError = (field, message) => {
|
|
56
|
+
const errors = field.errors?.errors ?? [];
|
|
57
|
+
const error = errors.filter((e) => !(e.type === "validation" && e.message === message));
|
|
58
|
+
field.clearErrors();
|
|
59
|
+
error.forEach((e) => field.addError(e));
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
useFormInputValidationHandler
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=useFormInputValidationHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormInputValidationHandler.js","sources":["../../../../../packages/react-form/src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>(undefined)\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tconst previousMessage = validationMessage.current\n\t\tvalidationMessage.current = message\n\n\t\tconst accessor = accessorGetter()\n\t\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\tif (previousMessage) {\n\t\t\t\tclearSpecificError(accessor, previousMessage)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (message === previousMessage) {\n\t\t\treturn\n\t\t}\n\t\t// if the input is not touched, we don't want to show the error message\n\t\tif (!field.isTouched) {\n\t\t\treturn\n\t\t}\n\n\t\t// if the input is not focused, we want to show the error message\n\t\t// also, even the input is focused, we want to replace the previous message\n\t\tif (!focus || !!previousMessage) {\n\t\t\taccessor.clearErrors()\n\t\t\taccessor.addError(message)\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n\nconst clearSpecificError = (field: FieldAccessor<any>, message: string) => {\n\tconst errors = field.errors?.errors ?? []\n\tconst error = errors.filter(e => !(e.type === 'validation' && e.message === message))\n\tfield.clearErrors()\n\terror.forEach(e => field.addError(e))\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoB,OAAe,MAAS;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,WAAW,MAAM,OAAyB,IAAI;AACpD,yBAAuB,YAAY,MAAM;AACxC,QAAI,kBAAkB,SAAS;AAC9B,uBAAiB,SAAS,kBAAkB,OAAO;AAAA,IACpD;AAAA,EACD,GAAG,CAAC,cAAc,CAAC,CAAC;AAEpB,YAAU,MAAM;AACf,QAAI,CAAC,SAAS,SAAS;AACtB;AAAA,IACD;AAEA,UAAM,QAAQ,SAAS;AACvB,UAAM,QAAQ,MAAM,UAAU;AAE9B,UAAM,UAAU,QAAQ,SAAY,OAAO;AAC3C,UAAM,kBAAkB,kBAAkB;AAC1C,sBAAkB,UAAU;AAE5B,UAAM,WAAW,eAAA;AAEjB,QAAI,CAAC,SAAS;AACb,UAAI,iBAAiB;AACpB,2BAAmB,UAAU,eAAe;AAAA,MAC7C;AACA;AAAA,IACD;AACA,QAAI,YAAY,iBAAiB;AAChC;AAAA,IACD;AAEA,QAAI,CAAC,MAAM,WAAW;AACrB;AAAA,IACD;AAIA,QAAI,CAAC,SAAS,CAAC,CAAC,iBAAiB;AAChC,eAAS,YAAA;AACT,eAAS,SAAS,OAAO;AAAA,IAC1B;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN,KAAK;AAAA,IACL,SAAS,YAAY,MAAM;AAC1B,eAAS,IAAI;AAAA,IACd,GAAG,CAAA,CAAE;AAAA,IACL,QAAQ,YAAY,MAAM;AACzB,eAAS,KAAK;AACd,qBAAA,EAAiB,YAAA;AACjB,UAAI,kBAAkB,SAAS;AAC9B,yBAAiB,SAAS,kBAAkB,OAAO;AAAA,MACpD;AAAA,IACD,GAAG,CAAC,cAAc,CAAC;AAAA,EAAA;AAErB;AAEA,MAAM,qBAAqB,CAAC,OAA2B,YAAoB;AAC1E,QAAM,SAAS,MAAM,QAAQ,UAAU,CAAA;AACvC,QAAM,QAAQ,OAAO,OAAO,CAAA,MAAK,EAAE,EAAE,SAAS,gBAAgB,EAAE,YAAY,QAAQ;AACpF,QAAM,YAAA;AACN,QAAM,QAAQ,CAAA,MAAK,MAAM,SAAS,CAAC,CAAC;AACrC;"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const useFormInputHandler = (field, { formatValue, parseValue }) => {
|
|
5
|
+
return React.useMemo(() => {
|
|
6
|
+
const schema = field.schema;
|
|
7
|
+
const columnType = schema.type;
|
|
8
|
+
const handlerFactory = ColumnTypeHandlerFactories[columnType] ?? defaultHandlerFactory;
|
|
9
|
+
const handler = handlerFactory(schema, field.getAccessor);
|
|
10
|
+
return {
|
|
11
|
+
defaultInputProps: handler.defaultInputProps,
|
|
12
|
+
formatValue: formatValue ?? handler.formatValue,
|
|
13
|
+
parseValue: parseValue ?? handler.parseValue
|
|
14
|
+
};
|
|
15
|
+
}, [field.getAccessor, field.schema, formatValue, parseValue]);
|
|
16
|
+
};
|
|
17
|
+
const defaultHandlerFactory = (schema, field) => ({
|
|
18
|
+
parseValue: (value) => {
|
|
19
|
+
if (value === "" && schema.nullable && field().valueOnServer === null) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
},
|
|
24
|
+
formatValue: (value) => value ?? ""
|
|
25
|
+
});
|
|
26
|
+
const ColumnTypeHandlerFactories = {
|
|
27
|
+
String: defaultHandlerFactory,
|
|
28
|
+
Integer: () => ({
|
|
29
|
+
parseValue: (value) => {
|
|
30
|
+
if (value === "") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const parsed = parseInt(value, 10);
|
|
34
|
+
return isNaN(parsed) ? null : parsed;
|
|
35
|
+
},
|
|
36
|
+
formatValue: (value) => {
|
|
37
|
+
return value === null ? "" : value.toString(10);
|
|
38
|
+
},
|
|
39
|
+
defaultInputProps: {
|
|
40
|
+
type: "number"
|
|
41
|
+
}
|
|
42
|
+
}),
|
|
43
|
+
Double: () => ({
|
|
44
|
+
parseValue: (value, ctx) => {
|
|
45
|
+
if (value === "") {
|
|
46
|
+
ctx.setState({ rawValue: "", parsedValue: null });
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const parsed = parseFloat(value);
|
|
50
|
+
const parsedValue = isNaN(parsed) ? null : parsed;
|
|
51
|
+
ctx.setState({ rawValue: value, parsedValue });
|
|
52
|
+
return parsedValue;
|
|
53
|
+
},
|
|
54
|
+
formatValue: (value, ctx) => {
|
|
55
|
+
if (value === ctx.state?.parsedValue) {
|
|
56
|
+
return ctx.state.rawValue;
|
|
57
|
+
}
|
|
58
|
+
return value === null ? "" : value.toString(10);
|
|
59
|
+
},
|
|
60
|
+
defaultInputProps: {
|
|
61
|
+
type: "number"
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
Date: () => ({
|
|
65
|
+
parseValue: (value) => {
|
|
66
|
+
if (value === "") {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const parsed = Date.parse(value);
|
|
70
|
+
return isNaN(parsed) ? null : new Date(parsed).toISOString().split("T")[0];
|
|
71
|
+
},
|
|
72
|
+
formatValue: (value) => {
|
|
73
|
+
const parsed = value ? Date.parse(value) : null;
|
|
74
|
+
return !parsed || isNaN(parsed) ? "" : new Date(parsed).toISOString().split("T")[0];
|
|
75
|
+
},
|
|
76
|
+
defaultInputProps: {
|
|
77
|
+
type: "date"
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
DateTime: () => ({
|
|
81
|
+
parseValue: (value) => {
|
|
82
|
+
if (value === "") {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const parsed = Date.parse(value);
|
|
86
|
+
return isNaN(parsed) ? null : new Date(parsed).toISOString();
|
|
87
|
+
},
|
|
88
|
+
formatValue: (value) => {
|
|
89
|
+
const parsed = value ? Date.parse(value) : null;
|
|
90
|
+
return !parsed || isNaN(parsed) ? "" : toLocalDate(new Date(parsed));
|
|
91
|
+
},
|
|
92
|
+
defaultInputProps: {
|
|
93
|
+
type: "datetime-local"
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
Time: () => ({
|
|
97
|
+
parseValue: (value) => {
|
|
98
|
+
if (value === "") {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
},
|
|
103
|
+
formatValue: (value) => {
|
|
104
|
+
return value ?? "";
|
|
105
|
+
},
|
|
106
|
+
defaultInputProps: {
|
|
107
|
+
type: "time"
|
|
108
|
+
}
|
|
109
|
+
}),
|
|
110
|
+
Bool: void 0,
|
|
111
|
+
Enum: void 0,
|
|
112
|
+
Uuid: void 0
|
|
113
|
+
};
|
|
114
|
+
const toLocalDate = (date) => {
|
|
115
|
+
const pad = (num, length = 2) => {
|
|
116
|
+
const str = num.toString();
|
|
117
|
+
return "0".repeat(Math.max(0, length - str.length)) + str;
|
|
118
|
+
};
|
|
119
|
+
return pad(date.getFullYear(), 4) + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + "T" + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds());
|
|
120
|
+
};
|
|
121
|
+
exports.useFormInputHandler = useFormInputHandler;
|
|
122
|
+
//# sourceMappingURL=useFormInputHandler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormInputHandler.cjs","sources":["../../../../../packages/react-form/src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport { useMemo } from 'react'\nimport { FormInputHandler } from '../types'\n\nexport const useFormInputHandler = (field: FieldAccessor, { formatValue, parseValue }: Partial<FormInputHandler>): FormInputHandler => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType] ?? defaultHandlerFactory\n\t\tconst handler = handlerFactory(schema, field.getAccessor)\n\t\treturn {\n\t\t\tdefaultInputProps: handler.defaultInputProps,\n\t\t\tformatValue: formatValue ?? handler.formatValue,\n\t\t\tparseValue: parseValue ?? handler.parseValue,\n\t\t}\n\t}, [field.getAccessor, field.schema, formatValue, parseValue])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler<any>\n\nconst defaultHandlerFactory: ColumnTypeHandlerFactory = (schema, field) => ({\n\tparseValue: (value: string) => {\n\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\treturn null\n\t\t}\n\t\treturn value\n\t},\n\tformatValue: (value: string | null) => value ?? '',\n})\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory | undefined> = {\n\tString: defaultHandlerFactory,\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: (): FormInputHandler<{ rawValue: string; parsedValue: number | null }> => ({\n\t\tparseValue: (value: string, ctx) => {\n\t\t\tif (value === '') {\n\t\t\t\tctx.setState({ rawValue: '', parsedValue: null })\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\tconst parsedValue = isNaN(parsed) ? null : parsed\n\t\t\tctx.setState({ rawValue: value, parsedValue })\n\t\t\treturn parsedValue\n\t\t},\n\t\tformatValue: (value: number | null, ctx) => {\n\t\t\tif (value === ctx.state?.parsedValue) {\n\t\t\t\treturn ctx.state.rawValue\n\t\t\t}\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString().split('T')[0]\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString()\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : toLocalDate(new Date(parsed))\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\treturn value ?? ''\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'time',\n\t\t},\n\t}),\n\tBool: undefined,\n\tEnum: undefined,\n\tUuid: undefined,\n}\n\nconst toLocalDate = (date: Date) => {\n\tconst pad = (num: number, length: number = 2) => {\n\t\tconst str = num.toString()\n\t\treturn '0'.repeat(Math.max(0, length - str.length)) + str\n\t}\n\n\treturn pad(date.getFullYear(), 4)\n\t\t+ '-' + pad(date.getMonth() + 1)\n\t\t+ '-' + pad(date.getDate())\n\t\t+ 'T' + pad(date.getHours())\n\t\t+ ':' + pad(date.getMinutes())\n\t\t+ ':' + pad(date.getSeconds())\n}\n"],"names":["useMemo"],"mappings":";;;AAIO,MAAM,sBAAsB,CAAC,OAAsB,EAAE,aAAa,iBAA8D;AACtI,SAAOA,MAAAA,QAAQ,MAAM;AACpB,UAAM,SAAS,MAAM;AACrB,UAAM,aAAa,OAAO;AAC1B,UAAM,iBAAiB,2BAA2B,UAAmC,KAAK;AAC1F,UAAM,UAAU,eAAe,QAAQ,MAAM,WAAW;AACxD,WAAO;AAAA,MACN,mBAAmB,QAAQ;AAAA,MAC3B,aAAa,eAAe,QAAQ;AAAA,MACpC,YAAY,cAAc,QAAQ;AAAA,IAAA;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;AAEA,MAAM,cAAc,CAAC,SAAe;AACnC,QAAM,MAAM,CAAC,KAAa,SAAiB,MAAM;AAChD,UAAM,MAAM,IAAI,SAAA;AAChB,WAAO,IAAI,OAAO,KAAK,IAAI,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI;AAAA,EACvD;AAEA,SAAO,IAAI,KAAK,YAAA,GAAe,CAAC,IAC7B,MAAM,IAAI,KAAK,aAAa,CAAC,IAC7B,MAAM,IAAI,KAAK,QAAA,CAAS,IACxB,MAAM,IAAI,KAAK,SAAA,CAAU,IACzB,MAAM,IAAI,KAAK,WAAA,CAAY,IAC3B,MAAM,IAAI,KAAK,YAAY;AAC/B;;"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
const useFormInputHandler = (field, { formatValue, parseValue }) => {
|
|
3
|
+
return useMemo(() => {
|
|
4
|
+
const schema = field.schema;
|
|
5
|
+
const columnType = schema.type;
|
|
6
|
+
const handlerFactory = ColumnTypeHandlerFactories[columnType] ?? defaultHandlerFactory;
|
|
7
|
+
const handler = handlerFactory(schema, field.getAccessor);
|
|
8
|
+
return {
|
|
9
|
+
defaultInputProps: handler.defaultInputProps,
|
|
10
|
+
formatValue: formatValue ?? handler.formatValue,
|
|
11
|
+
parseValue: parseValue ?? handler.parseValue
|
|
12
|
+
};
|
|
13
|
+
}, [field.getAccessor, field.schema, formatValue, parseValue]);
|
|
14
|
+
};
|
|
15
|
+
const defaultHandlerFactory = (schema, field) => ({
|
|
16
|
+
parseValue: (value) => {
|
|
17
|
+
if (value === "" && schema.nullable && field().valueOnServer === null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
},
|
|
22
|
+
formatValue: (value) => value ?? ""
|
|
23
|
+
});
|
|
24
|
+
const ColumnTypeHandlerFactories = {
|
|
25
|
+
String: defaultHandlerFactory,
|
|
26
|
+
Integer: () => ({
|
|
27
|
+
parseValue: (value) => {
|
|
28
|
+
if (value === "") {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const parsed = parseInt(value, 10);
|
|
32
|
+
return isNaN(parsed) ? null : parsed;
|
|
33
|
+
},
|
|
34
|
+
formatValue: (value) => {
|
|
35
|
+
return value === null ? "" : value.toString(10);
|
|
36
|
+
},
|
|
37
|
+
defaultInputProps: {
|
|
38
|
+
type: "number"
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
Double: () => ({
|
|
42
|
+
parseValue: (value, ctx) => {
|
|
43
|
+
if (value === "") {
|
|
44
|
+
ctx.setState({ rawValue: "", parsedValue: null });
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const parsed = parseFloat(value);
|
|
48
|
+
const parsedValue = isNaN(parsed) ? null : parsed;
|
|
49
|
+
ctx.setState({ rawValue: value, parsedValue });
|
|
50
|
+
return parsedValue;
|
|
51
|
+
},
|
|
52
|
+
formatValue: (value, ctx) => {
|
|
53
|
+
if (value === ctx.state?.parsedValue) {
|
|
54
|
+
return ctx.state.rawValue;
|
|
55
|
+
}
|
|
56
|
+
return value === null ? "" : value.toString(10);
|
|
57
|
+
},
|
|
58
|
+
defaultInputProps: {
|
|
59
|
+
type: "number"
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
Date: () => ({
|
|
63
|
+
parseValue: (value) => {
|
|
64
|
+
if (value === "") {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const parsed = Date.parse(value);
|
|
68
|
+
return isNaN(parsed) ? null : new Date(parsed).toISOString().split("T")[0];
|
|
69
|
+
},
|
|
70
|
+
formatValue: (value) => {
|
|
71
|
+
const parsed = value ? Date.parse(value) : null;
|
|
72
|
+
return !parsed || isNaN(parsed) ? "" : new Date(parsed).toISOString().split("T")[0];
|
|
73
|
+
},
|
|
74
|
+
defaultInputProps: {
|
|
75
|
+
type: "date"
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
DateTime: () => ({
|
|
79
|
+
parseValue: (value) => {
|
|
80
|
+
if (value === "") {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const parsed = Date.parse(value);
|
|
84
|
+
return isNaN(parsed) ? null : new Date(parsed).toISOString();
|
|
85
|
+
},
|
|
86
|
+
formatValue: (value) => {
|
|
87
|
+
const parsed = value ? Date.parse(value) : null;
|
|
88
|
+
return !parsed || isNaN(parsed) ? "" : toLocalDate(new Date(parsed));
|
|
89
|
+
},
|
|
90
|
+
defaultInputProps: {
|
|
91
|
+
type: "datetime-local"
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
Time: () => ({
|
|
95
|
+
parseValue: (value) => {
|
|
96
|
+
if (value === "") {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
},
|
|
101
|
+
formatValue: (value) => {
|
|
102
|
+
return value ?? "";
|
|
103
|
+
},
|
|
104
|
+
defaultInputProps: {
|
|
105
|
+
type: "time"
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
Bool: void 0,
|
|
109
|
+
Enum: void 0,
|
|
110
|
+
Uuid: void 0
|
|
111
|
+
};
|
|
112
|
+
const toLocalDate = (date) => {
|
|
113
|
+
const pad = (num, length = 2) => {
|
|
114
|
+
const str = num.toString();
|
|
115
|
+
return "0".repeat(Math.max(0, length - str.length)) + str;
|
|
116
|
+
};
|
|
117
|
+
return pad(date.getFullYear(), 4) + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + "T" + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds());
|
|
118
|
+
};
|
|
119
|
+
export {
|
|
120
|
+
useFormInputHandler
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=useFormInputHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormInputHandler.js","sources":["../../../../../packages/react-form/src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport { useMemo } from 'react'\nimport { FormInputHandler } from '../types'\n\nexport const useFormInputHandler = (field: FieldAccessor, { formatValue, parseValue }: Partial<FormInputHandler>): FormInputHandler => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType] ?? defaultHandlerFactory\n\t\tconst handler = handlerFactory(schema, field.getAccessor)\n\t\treturn {\n\t\t\tdefaultInputProps: handler.defaultInputProps,\n\t\t\tformatValue: formatValue ?? handler.formatValue,\n\t\t\tparseValue: parseValue ?? handler.parseValue,\n\t\t}\n\t}, [field.getAccessor, field.schema, formatValue, parseValue])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler<any>\n\nconst defaultHandlerFactory: ColumnTypeHandlerFactory = (schema, field) => ({\n\tparseValue: (value: string) => {\n\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\treturn null\n\t\t}\n\t\treturn value\n\t},\n\tformatValue: (value: string | null) => value ?? '',\n})\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory | undefined> = {\n\tString: defaultHandlerFactory,\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: (): FormInputHandler<{ rawValue: string; parsedValue: number | null }> => ({\n\t\tparseValue: (value: string, ctx) => {\n\t\t\tif (value === '') {\n\t\t\t\tctx.setState({ rawValue: '', parsedValue: null })\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\tconst parsedValue = isNaN(parsed) ? null : parsed\n\t\t\tctx.setState({ rawValue: value, parsedValue })\n\t\t\treturn parsedValue\n\t\t},\n\t\tformatValue: (value: number | null, ctx) => {\n\t\t\tif (value === ctx.state?.parsedValue) {\n\t\t\t\treturn ctx.state.rawValue\n\t\t\t}\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString().split('T')[0]\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString()\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : toLocalDate(new Date(parsed))\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\treturn value ?? ''\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'time',\n\t\t},\n\t}),\n\tBool: undefined,\n\tEnum: undefined,\n\tUuid: undefined,\n}\n\nconst toLocalDate = (date: Date) => {\n\tconst pad = (num: number, length: number = 2) => {\n\t\tconst str = num.toString()\n\t\treturn '0'.repeat(Math.max(0, length - str.length)) + str\n\t}\n\n\treturn pad(date.getFullYear(), 4)\n\t\t+ '-' + pad(date.getMonth() + 1)\n\t\t+ '-' + pad(date.getDate())\n\t\t+ 'T' + pad(date.getHours())\n\t\t+ ':' + pad(date.getMinutes())\n\t\t+ ':' + pad(date.getSeconds())\n}\n"],"names":[],"mappings":";AAIO,MAAM,sBAAsB,CAAC,OAAsB,EAAE,aAAa,iBAA8D;AACtI,SAAO,QAAQ,MAAM;AACpB,UAAM,SAAS,MAAM;AACrB,UAAM,aAAa,OAAO;AAC1B,UAAM,iBAAiB,2BAA2B,UAAmC,KAAK;AAC1F,UAAM,UAAU,eAAe,QAAQ,MAAM,WAAW;AACxD,WAAO;AAAA,MACN,mBAAmB,QAAQ;AAAA,MAC3B,aAAa,eAAe,QAAQ;AAAA,MACpC,YAAY,cAAc,QAAQ;AAAA,IAAA;AAAA,EAEpC,GAAG,CAAC,MAAM,aAAa,MAAM,QAAQ,aAAa,UAAU,CAAC;AAC9D;AAIA,MAAM,wBAAkD,CAAC,QAAQ,WAAW;AAAA,EAC3E,YAAY,CAAC,UAAkB;AAC9B,QAAI,UAAU,MAAM,OAAO,YAAY,MAAA,EAAQ,kBAAkB,MAAM;AACtE,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR;AAAA,EACA,aAAa,CAAC,UAAyB,SAAS;AACjD;AAEA,MAAM,6BAAkG;AAAA,EACvG,QAAQ;AAAA,EACR,SAAS,OAAO;AAAA,IACf,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACjB,eAAO;AAAA,MACR;AACA,YAAM,SAAS,SAAS,OAAO,EAAE;AACjC,aAAO,MAAM,MAAM,IAAI,OAAO;AAAA,IAC/B;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,aAAO,UAAU,OAAO,KAAK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R;AAEA,YAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,aAAO,MAAM,MAAM,IAAI,OAAQ,IAAI,KAAK,MAAM,EAAG,YAAA;AAAA,IAClD;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,YAAM,SAAS,QAAQ,KAAK,MAAM,KAAK,IAAI;AAC3C,aAAO,CAAC,UAAU,MAAM,MAAM,IAAI,KAAK,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IACpE;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACP;AAAA,EAED,MAAM,OAAO;AAAA,IACZ,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACjB,eAAO;AAAA,MACR;AACA,aAAO;AAAA,IACR;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,aAAO,SAAS;AAAA,IACjB;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACP;AAAA,EAED,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACP;AAEA,MAAM,cAAc,CAAC,SAAe;AACnC,QAAM,MAAM,CAAC,KAAa,SAAiB,MAAM;AAChD,UAAM,MAAM,IAAI,SAAA;AAChB,WAAO,IAAI,OAAO,KAAK,IAAI,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI;AAAA,EACvD;AAEA,SAAO,IAAI,KAAK,YAAA,GAAe,CAAC,IAC7B,MAAM,IAAI,KAAK,aAAa,CAAC,IAC7B,MAAM,IAAI,KAAK,QAAA,CAAS,IACxB,MAAM,IAAI,KAAK,SAAA,CAAU,IACzB,MAAM,IAAI,KAAK,WAAA,CAAY,IAC3B,MAAM,IAAI,KAAK,YAAY;AAC/B;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
import { OptionallyVariableFieldValue, SugaredRelativeSingleField } from '@contember/react-binding';
|
|
4
|
+
export interface FormCheckboxProps {
|
|
5
|
+
field: SugaredRelativeSingleField['field'];
|
|
6
|
+
isNonbearing?: boolean;
|
|
7
|
+
defaultValue?: OptionallyVariableFieldValue;
|
|
8
|
+
children: ReactElement<HTMLInputElement, 'input'>;
|
|
9
|
+
}
|
|
10
|
+
export declare const FormCheckbox: React.NamedExoticComponent<FormCheckboxProps>;
|
|
11
|
+
//# sourceMappingURL=FormCheckbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormCheckbox.d.ts","sourceRoot":"","sources":["../../../src/components/FormCheckbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAsB,YAAY,EAA0B,MAAM,OAAO,CAAA;AAChF,OAAO,EAGN,4BAA4B,EAC5B,0BAA0B,EAG1B,MAAM,0BAA0B,CAAA;AAQjC,MAAM,WAAW,iBAAiB;IACjC,KAAK,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAA;IAC1C,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,4BAA4B,CAAA;IAC3C,QAAQ,EAAE,YAAY,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAA;CACjD;AAED,eAAO,MAAM,YAAY,+CA6CvB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { ErrorAccessor } from '@contember/react-binding';
|
|
3
|
+
export declare const FormError: ({ children, formatter }: {
|
|
4
|
+
formatter: (errors: ErrorAccessor.Error[]) => ReactNode[];
|
|
5
|
+
children: ReactElement<any>;
|
|
6
|
+
}) => ReactElement<any, string | import("react").JSXElementConstructor<any>>[];
|
|
7
|
+
//# sourceMappingURL=FormError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormError.d.ts","sourceRoot":"","sources":["../../../src/components/FormError.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAE,SAAS,EAAW,MAAM,OAAO,CAAA;AAEtE,OAAO,EAAgB,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAEtE,eAAO,MAAM,SAAS,GAAI,yBAAyB;IAClD,SAAS,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,SAAS,EAAE,CAAA;IACzD,QAAQ,EAAE,YAAY,CAAC,GAAG,CAAC,CAAA;CAC3B,6EAcA,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SugaredRelativeSingleField } from '@contember/react-binding';
|
|
3
|
+
export type FormFieldScopeProps = {
|
|
4
|
+
field: SugaredRelativeSingleField['field'];
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const FormFieldScope: ({ field, children, required }: FormFieldScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//# sourceMappingURL=FormFieldScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldScope.d.ts","sourceRoot":"","sources":["../../../src/components/FormFieldScope.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,0BAA0B,EAAY,MAAM,0BAA0B,CAAA;AAG/E,MAAM,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAA;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,+BAA+B,mBAAmB,4CAiBhF,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ErrorAccessor } from '@contember/react-binding';
|
|
2
|
+
import { FormFieldState } from '../types';
|
|
3
|
+
export type FormFieldStateProvider = Partial<FormFieldState> & {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export declare const FormFieldStateProvider: ({ children, required, errors, dirty, htmlId, field }: FormFieldStateProvider) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
/**
|
|
8
|
+
* BC for
|
|
9
|
+
* <FormFieldIdContext.Provider value={id}>
|
|
10
|
+
* <FormErrorContext.Provider value={[]}>
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
14
|
+
*/
|
|
15
|
+
export declare const FormFieldIdContext: {
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
18
|
+
*/
|
|
19
|
+
Provider: ({ children, value }: {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
value: string;
|
|
22
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
26
|
+
*/
|
|
27
|
+
export declare const FormErrorContext: {
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
30
|
+
*/
|
|
31
|
+
Provider: ({ children, value }: {
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
value: ErrorAccessor.Error[];
|
|
34
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=FormFieldStateProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldStateProvider.d.ts","sourceRoot":"","sources":["../../../src/components/FormFieldStateProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAGxD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAIzC,MAAM,MAAM,sBAAsB,GAC/B,OAAO,CAAC,cAAc,CAAC,GACvB;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CACzB,CAAA;AAEF,eAAO,MAAM,sBAAsB,GAAI,sDAAiF,sBAAsB,4CAK7I,CAAA;AAED;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC9B;;OAEG;oCAC6B;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;CAa5E,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAC5B;;OAEG;oCAC6B;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,CAAA;KAAE;CAa3F,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SugaredRelativeEntityList } from '@contember/react-binding';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export type FormHasManyRelationScopeProps = {
|
|
4
|
+
field: SugaredRelativeEntityList['field'];
|
|
5
|
+
orderBy?: SugaredRelativeEntityList['orderBy'];
|
|
6
|
+
limit?: SugaredRelativeEntityList['limit'];
|
|
7
|
+
offset?: SugaredRelativeEntityList['offset'];
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const FormHasManyRelationScope: ({ children, required, ...props }: FormHasManyRelationScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
//# sourceMappingURL=FormHasManyRelationScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormHasManyRelationScope.d.ts","sourceRoot":"","sources":["../../../src/components/FormHasManyRelationScope.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyB,yBAAyB,EAAiB,MAAM,0BAA0B,CAAA;AAC1G,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,MAAM,6BAA6B,GAAG;IAC3C,KAAK,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAA;IACzC,OAAO,CAAC,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAA;IAC9C,KAAK,CAAC,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAA;IAC1C,MAAM,CAAC,EAAE,yBAAyB,CAAC,QAAQ,CAAC,CAAA;IAC5C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,kCAAkC,6BAA6B,4CAiBvG,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SugaredRelativeSingleEntity } from '@contember/react-binding';
|
|
3
|
+
export type FormHasOneRelationScopeProps = {
|
|
4
|
+
field: SugaredRelativeSingleEntity['field'];
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const FormHasOneRelationScope: ({ field, children, required }: FormHasOneRelationScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//# sourceMappingURL=FormHasOneRelationScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormHasOneRelationScope.d.ts","sourceRoot":"","sources":["../../../src/components/FormHasOneRelationScope.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAwB,2BAA2B,EAAa,MAAM,0BAA0B,CAAA;AAIvG,MAAM,MAAM,4BAA4B,GAAG;IAC1C,KAAK,EAAE,2BAA2B,CAAC,OAAO,CAAC,CAAA;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,+BAA+B,4BAA4B,4CAgBlG,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { OptionallyVariableFieldValue, SugaredRelativeSingleField } from '@contember/react-binding';
|
|
3
|
+
import { FormInputHandler } from '../types';
|
|
4
|
+
export interface FormInputProps {
|
|
5
|
+
field: SugaredRelativeSingleField['field'];
|
|
6
|
+
isNonbearing?: boolean;
|
|
7
|
+
defaultValue?: OptionallyVariableFieldValue;
|
|
8
|
+
children: React.ReactElement;
|
|
9
|
+
formatValue?: FormInputHandler['formatValue'];
|
|
10
|
+
parseValue?: FormInputHandler['parseValue'];
|
|
11
|
+
}
|
|
12
|
+
export declare const FormInput: React.NamedExoticComponent<FormInputProps>;
|
|
13
|
+
//# sourceMappingURL=FormInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormInput.d.ts","sourceRoot":"","sources":["../../../src/components/FormInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAoB,4BAA4B,EAAE,0BAA0B,EAAY,MAAM,0BAA0B,CAAA;AAK/H,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAM3C,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAA;IAC1C,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,4BAA4B,CAAA;IAC3C,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAA;IAC5B,WAAW,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAC7C,UAAU,CAAC,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;CAC3C;AAED,eAAO,MAAM,SAAS,4CAsCrB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormLabel.d.ts","sourceRoot":"","sources":["../../../src/components/FormLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,eAAO,MAAM,SAAS,GAAI,OAAO;IAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAA;CAC5B,4CAeA,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OptionallyVariableFieldValue, SugaredRelativeSingleField } from '@contember/react-binding';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export interface FormRadioItemProps {
|
|
4
|
+
field: SugaredRelativeSingleField['field'];
|
|
5
|
+
value: string | null | number | boolean;
|
|
6
|
+
isNonbearing?: boolean;
|
|
7
|
+
defaultValue?: OptionallyVariableFieldValue;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const FormRadioInput: React.NamedExoticComponent<FormRadioItemProps>;
|
|
11
|
+
//# sourceMappingURL=FormRadioInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormRadioInput.d.ts","sourceRoot":"","sources":["../../../src/components/FormRadioInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,4BAA4B,EAAE,0BAA0B,EAAY,MAAM,0BAA0B,CAAA;AAG/H,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAA;IAC1C,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,CAAA;IACvC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,4BAA4B,CAAA;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CACzB;AAED,eAAO,MAAM,cAAc,gDAiCzB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './FormError';
|
|
2
|
+
export * from './FormCheckbox';
|
|
3
|
+
export * from './FormFieldScope';
|
|
4
|
+
export * from './FormFieldStateProvider';
|
|
5
|
+
export * from './FormHasOneRelationScope';
|
|
6
|
+
export * from './FormHasManyRelationScope';
|
|
7
|
+
export * from './FormInput';
|
|
8
|
+
export * from './FormLabel';
|
|
9
|
+
export * from './FormRadioInput';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FormFieldState } from './types';
|
|
2
|
+
export declare const FormFieldStateContext: import("react").Context<FormFieldState | undefined>;
|
|
3
|
+
export declare const useFormFieldState: () => FormFieldState | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use `useFormState` instead
|
|
6
|
+
*/
|
|
7
|
+
export declare const useFormFieldId: () => string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated use `useFormState` instead
|
|
10
|
+
*/
|
|
11
|
+
export declare const useFormError: () => import("@contember/binding-common").ErrorAccessor.Error[] | undefined;
|
|
12
|
+
//# sourceMappingURL=contexts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/contexts.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGxC,eAAO,MAAM,qBAAqB,qDAA4B,CAAA;AAC9D,eAAO,MAAM,iBAAiB,kCAA4B,CAAA;AAE1D;;GAEG;AACH,eAAO,MAAM,cAAc,0BAAoC,CAAA;AAE/D;;GAEG;AACH,eAAO,MAAM,YAAY,6EAAoC,CAAA"}
|