@contember/react-form 2.0.0-alpha.9 → 2.0.0-beta.1
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 +6 -2
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +5 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/components/FormCheckbox.cjs +9 -6
- package/dist/development/src/components/FormCheckbox.cjs.map +1 -1
- package/dist/development/src/components/FormCheckbox.js +10 -7
- package/dist/development/src/components/FormCheckbox.js.map +1 -1
- package/dist/development/src/components/FormError.cjs +5 -5
- package/dist/development/src/components/FormError.cjs.map +1 -1
- package/dist/development/src/components/FormError.js +6 -6
- package/dist/development/src/components/FormError.js.map +1 -1
- package/dist/development/src/components/FormFieldScope.cjs +24 -14
- package/dist/development/src/components/FormFieldScope.cjs.map +1 -1
- package/dist/development/src/components/FormFieldScope.js +25 -15
- package/dist/development/src/components/FormFieldScope.js.map +1 -1
- 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 +25 -15
- package/dist/development/src/components/FormHasManyRelationScope.cjs.map +1 -1
- package/dist/development/src/components/FormHasManyRelationScope.js +26 -16
- package/dist/development/src/components/FormHasManyRelationScope.js.map +1 -1
- package/dist/development/src/components/FormHasOneRelationScope.cjs +25 -15
- package/dist/development/src/components/FormHasOneRelationScope.cjs.map +1 -1
- package/dist/development/src/components/FormHasOneRelationScope.js +25 -15
- package/dist/development/src/components/FormHasOneRelationScope.js.map +1 -1
- package/dist/development/src/components/FormInput.cjs +11 -6
- package/dist/development/src/components/FormInput.cjs.map +1 -1
- package/dist/development/src/components/FormInput.js +12 -7
- package/dist/development/src/components/FormInput.js.map +1 -1
- package/dist/development/src/components/FormLabel.cjs +7 -5
- package/dist/development/src/components/FormLabel.cjs.map +1 -1
- package/dist/development/src/components/FormLabel.js +8 -6
- package/dist/development/src/components/FormLabel.js.map +1 -1
- package/dist/development/src/components/FormRadioInput.cjs +17 -13
- package/dist/development/src/components/FormRadioInput.cjs.map +1 -1
- package/dist/development/src/components/FormRadioInput.js +18 -14
- package/dist/development/src/components/FormRadioInput.js.map +1 -1
- package/dist/development/src/contexts.cjs +7 -8
- package/dist/development/src/contexts.cjs.map +1 -1
- package/dist/development/src/contexts.js +8 -9
- package/dist/development/src/contexts.js.map +1 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs +12 -3
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs.map +1 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.js +12 -3
- package/dist/development/src/hooks/useFormInputValidationHandler.js.map +1 -1
- package/dist/development/src/internal/useFormInputHandler.cjs.map +1 -1
- package/dist/development/src/internal/useFormInputHandler.js.map +1 -1
- package/dist/production/index.cjs +6 -2
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +5 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/components/FormCheckbox.cjs +7 -4
- package/dist/production/src/components/FormCheckbox.cjs.map +1 -1
- package/dist/production/src/components/FormCheckbox.js +8 -5
- package/dist/production/src/components/FormCheckbox.js.map +1 -1
- package/dist/production/src/components/FormError.cjs +5 -5
- package/dist/production/src/components/FormError.cjs.map +1 -1
- package/dist/production/src/components/FormError.js +6 -6
- package/dist/production/src/components/FormError.js.map +1 -1
- package/dist/production/src/components/FormFieldScope.cjs +16 -6
- package/dist/production/src/components/FormFieldScope.cjs.map +1 -1
- package/dist/production/src/components/FormFieldScope.js +17 -7
- package/dist/production/src/components/FormFieldScope.js.map +1 -1
- 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 +17 -7
- package/dist/production/src/components/FormHasManyRelationScope.cjs.map +1 -1
- package/dist/production/src/components/FormHasManyRelationScope.js +18 -8
- package/dist/production/src/components/FormHasManyRelationScope.js.map +1 -1
- package/dist/production/src/components/FormHasOneRelationScope.cjs +17 -7
- package/dist/production/src/components/FormHasOneRelationScope.cjs.map +1 -1
- package/dist/production/src/components/FormHasOneRelationScope.js +17 -7
- package/dist/production/src/components/FormHasOneRelationScope.js.map +1 -1
- package/dist/production/src/components/FormInput.cjs +9 -4
- package/dist/production/src/components/FormInput.cjs.map +1 -1
- package/dist/production/src/components/FormInput.js +10 -5
- package/dist/production/src/components/FormInput.js.map +1 -1
- package/dist/production/src/components/FormLabel.cjs +7 -5
- package/dist/production/src/components/FormLabel.cjs.map +1 -1
- package/dist/production/src/components/FormLabel.js +8 -6
- package/dist/production/src/components/FormLabel.js.map +1 -1
- package/dist/production/src/components/FormRadioInput.cjs +15 -11
- package/dist/production/src/components/FormRadioInput.cjs.map +1 -1
- package/dist/production/src/components/FormRadioInput.js +16 -12
- package/dist/production/src/components/FormRadioInput.js.map +1 -1
- package/dist/production/src/contexts.cjs +7 -8
- package/dist/production/src/contexts.cjs.map +1 -1
- package/dist/production/src/contexts.js +8 -9
- package/dist/production/src/contexts.js.map +1 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs +12 -3
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs.map +1 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.js +12 -3
- package/dist/production/src/hooks/useFormInputValidationHandler.js.map +1 -1
- package/dist/production/src/internal/useFormInputHandler.cjs.map +1 -1
- package/dist/production/src/internal/useFormInputHandler.js.map +1 -1
- package/dist/types/components/FormCheckbox.d.ts.map +1 -1
- package/dist/types/components/FormFieldScope.d.ts +2 -1
- package/dist/types/components/FormFieldScope.d.ts.map +1 -1
- 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 +5 -1
- package/dist/types/components/FormHasManyRelationScope.d.ts.map +1 -1
- package/dist/types/components/FormHasOneRelationScope.d.ts +2 -1
- package/dist/types/components/FormHasOneRelationScope.d.ts.map +1 -1
- package/dist/types/components/FormInput.d.ts.map +1 -1
- package/dist/types/components/FormLabel.d.ts.map +1 -1
- package/dist/types/components/FormRadioInput.d.ts +1 -1
- package/dist/types/components/FormRadioInput.d.ts.map +1 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/index.d.ts.map +1 -1
- package/dist/types/contexts.d.ts +10 -6
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/hooks/useFormInputValidationHandler.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/index.d.ts +12 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/components/FormCheckbox.tsx +17 -6
- package/src/components/FormError.tsx +6 -6
- package/src/components/FormFieldScope.tsx +17 -12
- package/src/components/FormFieldStateProvider.tsx +71 -0
- package/src/components/FormHasManyRelationScope.tsx +22 -14
- package/src/components/FormHasOneRelationScope.tsx +17 -13
- package/src/components/FormInput.tsx +12 -5
- package/src/components/FormLabel.tsx +8 -6
- package/src/components/FormRadioInput.tsx +22 -15
- package/src/components/index.ts +1 -0
- package/src/contexts.tsx +18 -0
- package/src/hooks/useFormInputValidationHandler.tsx +13 -3
- package/src/tsconfig.json +5 -2
- package/src/types/index.ts +13 -0
- package/src/contexts.ts +0 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormRadioInput.js","sources":["../../../../../packages/react-form/src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport
|
|
1
|
+
{"version":3,"file":"FormRadioInput.js","sources":["../../../../../packages/react-form/src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { Slot } from '@radix-ui/react-slot'\nimport * as React from 'react'\nimport { ChangeEventHandler, useCallback } from 'react'\nimport { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormRadioItemProps {\n\tfield: SugaredRelativeSingleField['field']\n\tvalue: string | null | number | boolean\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactNode\n}\n\nexport const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\tconst handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\taccessorGetter().updateValue(value)\n\t}, [accessorGetter, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\ttype=\"radio\"\n\t\t\tvalue={typeof value === 'string' ? value : undefined}\n\t\t\tchecked={accessor.value === value}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tname={id ? id + '-input' : undefined}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={handleChange}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }) => {\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}/>\n})\n"],"names":[],"mappings":";;;;;;;AAQA,MAAM,YAAY;AAUL,MAAA,iBAAiB,UAA8B,CAAC,EAAE,OAAO,OAAO,cAAc,cAAc,GAAG,YAAY;AACjH,QAAA,WAAW,SAAS,KAAK;AAE/B,QAAM,YAAY,kBAAkB;AACpC,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAE3C,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAI,8BAA8B,QAAQ;AAEjE,QAAA,eAAe,YAAkD,CAAK,MAAA;AAC5D,mBAAA,EAAE,YAAY,KAAK;AAAA,EAAA,GAChC,CAAC,gBAAgB,KAAK,CAAC;AAGzB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,MAAK;AAAA,MACL,OAAO,OAAO,UAAU,WAAW,QAAQ;AAAA,MAC3C,SAAS,SAAS,UAAU;AAAA,MAC5B,gBAAc,cAAc,SAAS;AAAA,MACrC,cAAY,cAAc,KAAK;AAAA,MAC/B,MAAM,KAAK,KAAK,WAAW;AAAA,MAC3B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACT,GAAG;AAAA,IAAA;AAAA,EACL;AAEF,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,aAA2B,CAAA;AACpF,CAAC;"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const reactUtils = require("@contember/react-utils");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
exports.FormErrorContext = FormErrorContext;
|
|
11
|
-
exports.FormFieldIdContext = FormFieldIdContext;
|
|
4
|
+
const FormFieldStateContext_ = reactUtils.createContext("FormFieldStateContext", void 0);
|
|
5
|
+
const FormFieldStateContext = FormFieldStateContext_[0];
|
|
6
|
+
const useFormFieldState = FormFieldStateContext_[1];
|
|
7
|
+
const useFormFieldId = () => useFormFieldState()?.htmlId;
|
|
8
|
+
const useFormError = () => useFormFieldState()?.errors;
|
|
9
|
+
exports.FormFieldStateContext = FormFieldStateContext;
|
|
12
10
|
exports.useFormError = useFormError;
|
|
13
11
|
exports.useFormFieldId = useFormFieldId;
|
|
12
|
+
exports.useFormFieldState = useFormFieldState;
|
|
14
13
|
//# sourceMappingURL=contexts.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.cjs","sources":["../../../../packages/react-form/src/contexts.
|
|
1
|
+
{"version":3,"file":"contexts.cjs","sources":["../../../../packages/react-form/src/contexts.tsx"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { FormFieldState } from './types'\n\n\nconst FormFieldStateContext_ = createContext<FormFieldState | undefined>('FormFieldStateContext', undefined)\nexport const FormFieldStateContext = FormFieldStateContext_[0]\nexport const useFormFieldState = FormFieldStateContext_[1]\n\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormFieldId = () => useFormFieldState()?.htmlId\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormError = () => useFormFieldState()?.errors\n"],"names":["createContext"],"mappings":";;;AAIA,MAAM,yBAAyBA,WAA0C,cAAA,yBAAyB,MAAS;AAC9F,MAAA,wBAAwB,uBAAuB,CAAC;AAChD,MAAA,oBAAoB,uBAAuB,CAAC;AAM5C,MAAA,iBAAiB,MAAM,qBAAqB;AAK5C,MAAA,eAAe,MAAM,qBAAqB;;;;;"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { createContext } from "@contember/react-utils";
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const useFormError = FormErrorContext_[1];
|
|
2
|
+
const FormFieldStateContext_ = createContext("FormFieldStateContext", void 0);
|
|
3
|
+
const FormFieldStateContext = FormFieldStateContext_[0];
|
|
4
|
+
const useFormFieldState = FormFieldStateContext_[1];
|
|
5
|
+
const useFormFieldId = () => useFormFieldState()?.htmlId;
|
|
6
|
+
const useFormError = () => useFormFieldState()?.errors;
|
|
8
7
|
export {
|
|
9
|
-
|
|
10
|
-
FormFieldIdContext,
|
|
8
|
+
FormFieldStateContext,
|
|
11
9
|
useFormError,
|
|
12
|
-
useFormFieldId
|
|
10
|
+
useFormFieldId,
|
|
11
|
+
useFormFieldState
|
|
13
12
|
};
|
|
14
13
|
//# sourceMappingURL=contexts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.js","sources":["../../../../packages/react-form/src/contexts.
|
|
1
|
+
{"version":3,"file":"contexts.js","sources":["../../../../packages/react-form/src/contexts.tsx"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { FormFieldState } from './types'\n\n\nconst FormFieldStateContext_ = createContext<FormFieldState | undefined>('FormFieldStateContext', undefined)\nexport const FormFieldStateContext = FormFieldStateContext_[0]\nexport const useFormFieldState = FormFieldStateContext_[1]\n\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormFieldId = () => useFormFieldState()?.htmlId\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormError = () => useFormFieldState()?.errors\n"],"names":[],"mappings":";AAIA,MAAM,yBAAyB,cAA0C,yBAAyB,MAAS;AAC9F,MAAA,wBAAwB,uBAAuB,CAAC;AAChD,MAAA,oBAAoB,uBAAuB,CAAC;AAM5C,MAAA,iBAAiB,MAAM,qBAAqB;AAK5C,MAAA,eAAe,MAAM,qBAAqB;"}
|
|
@@ -38,8 +38,11 @@ const useFormInputValidationHandler = (field) => {
|
|
|
38
38
|
const message = valid ? void 0 : input?.validationMessage;
|
|
39
39
|
const previousMessage = validationMessage.current;
|
|
40
40
|
validationMessage.current = message;
|
|
41
|
+
const accessor = accessorGetter();
|
|
41
42
|
if (!message) {
|
|
42
|
-
|
|
43
|
+
if (previousMessage) {
|
|
44
|
+
clearSpecificError(accessor, previousMessage);
|
|
45
|
+
}
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
45
48
|
if (message === previousMessage) {
|
|
@@ -49,8 +52,8 @@ const useFormInputValidationHandler = (field) => {
|
|
|
49
52
|
return;
|
|
50
53
|
}
|
|
51
54
|
if (!focus || !!previousMessage) {
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
accessor.clearErrors();
|
|
56
|
+
accessor.addError(message);
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
return {
|
|
@@ -67,5 +70,11 @@ const useFormInputValidationHandler = (field) => {
|
|
|
67
70
|
}, [accessorGetter])
|
|
68
71
|
};
|
|
69
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
|
+
};
|
|
70
79
|
exports.useFormInputValidationHandler = useFormInputValidationHandler;
|
|
71
80
|
//# sourceMappingURL=useFormInputValidationHandler.cjs.map
|
|
@@ -1 +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>()\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\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\
|
|
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>()\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":";;;;;;;;;;;;;;;;;;;;;AAIa,MAAA,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoBA,MAAAA,OAAe;AACzC,QAAM,CAAC,OAAO,QAAQ,IAAIC,iBAAM,SAAS,KAAK;AACxC,QAAA,WAAWA,iBAAM,OAAyB,IAAI;AACpDC,eAAA,uBAAuBC,kBAAY,MAAM;AACxC,QAAI,kBAAkB,SAAS;AACf,uBAAE,SAAS,kBAAkB,OAAO;AAAA,IAAA;AAAA,EACpD,GACE,CAAC,cAAc,CAAC,CAAC;AAEpBC,QAAAA,UAAU,MAAM;AACX,QAAA,CAAC,SAAS,SAAS;AACtB;AAAA,IAAA;AAGD,UAAM,QAAQ,SAAS;AACjB,UAAA,QAAQ,MAAM,UAAU;AAExB,UAAA,UAAU,QAAQ,SAAY,OAAO;AAC3C,UAAM,kBAAkB,kBAAkB;AAC1C,sBAAkB,UAAU;AAE5B,UAAM,WAAW,eAAe;AAEhC,QAAI,CAAC,SAAS;AACb,UAAI,iBAAiB;AACpB,2BAAmB,UAAU,eAAe;AAAA,MAAA;AAE7C;AAAA,IAAA;AAED,QAAI,YAAY,iBAAiB;AAChC;AAAA,IAAA;AAGG,QAAA,CAAC,MAAM,WAAW;AACrB;AAAA,IAAA;AAKD,QAAI,CAAC,SAAS,CAAC,CAAC,iBAAiB;AAChC,eAAS,YAAY;AACrB,eAAS,SAAS,OAAO;AAAA,IAAA;AAAA,EAC1B,CACA;AAEM,SAAA;AAAA,IACN,KAAK;AAAA,IACL,SAASD,kBAAY,MAAM;AAC1B,eAAS,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,IACL,QAAQA,kBAAY,MAAM;AACzB,eAAS,KAAK;AACd,qBAAA,EAAiB,YAAY;AAC7B,UAAI,kBAAkB,SAAS;AACf,yBAAE,SAAS,kBAAkB,OAAO;AAAA,MAAA;AAAA,IAErD,GAAG,CAAC,cAAc,CAAC;AAAA,EACpB;AACD;AAEA,MAAM,qBAAqB,CAAC,OAA2B,YAAoB;AAC1E,QAAM,SAAS,MAAM,QAAQ,UAAU,CAAC;AAClC,QAAA,QAAQ,OAAO,OAAO,CAAK,MAAA,EAAE,EAAE,SAAS,gBAAgB,EAAE,YAAY,QAAQ;AACpF,QAAM,YAAY;AAClB,QAAM,QAAQ,CAAA,MAAK,MAAM,SAAS,CAAC,CAAC;AACrC;;"}
|
|
@@ -20,8 +20,11 @@ const useFormInputValidationHandler = (field) => {
|
|
|
20
20
|
const message = valid ? void 0 : input?.validationMessage;
|
|
21
21
|
const previousMessage = validationMessage.current;
|
|
22
22
|
validationMessage.current = message;
|
|
23
|
+
const accessor = accessorGetter();
|
|
23
24
|
if (!message) {
|
|
24
|
-
|
|
25
|
+
if (previousMessage) {
|
|
26
|
+
clearSpecificError(accessor, previousMessage);
|
|
27
|
+
}
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
27
30
|
if (message === previousMessage) {
|
|
@@ -31,8 +34,8 @@ const useFormInputValidationHandler = (field) => {
|
|
|
31
34
|
return;
|
|
32
35
|
}
|
|
33
36
|
if (!focus || !!previousMessage) {
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
accessor.clearErrors();
|
|
38
|
+
accessor.addError(message);
|
|
36
39
|
}
|
|
37
40
|
});
|
|
38
41
|
return {
|
|
@@ -49,6 +52,12 @@ const useFormInputValidationHandler = (field) => {
|
|
|
49
52
|
}, [accessorGetter])
|
|
50
53
|
};
|
|
51
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
|
+
};
|
|
52
61
|
export {
|
|
53
62
|
useFormInputValidationHandler
|
|
54
63
|
};
|
|
@@ -1 +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>()\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\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\
|
|
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>()\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":";;;AAIa,MAAA,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoB,OAAe;AACzC,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AACxC,QAAA,WAAW,MAAM,OAAyB,IAAI;AACpD,yBAAuB,YAAY,MAAM;AACxC,QAAI,kBAAkB,SAAS;AACf,uBAAE,SAAS,kBAAkB,OAAO;AAAA,IAAA;AAAA,EACpD,GACE,CAAC,cAAc,CAAC,CAAC;AAEpB,YAAU,MAAM;AACX,QAAA,CAAC,SAAS,SAAS;AACtB;AAAA,IAAA;AAGD,UAAM,QAAQ,SAAS;AACjB,UAAA,QAAQ,MAAM,UAAU;AAExB,UAAA,UAAU,QAAQ,SAAY,OAAO;AAC3C,UAAM,kBAAkB,kBAAkB;AAC1C,sBAAkB,UAAU;AAE5B,UAAM,WAAW,eAAe;AAEhC,QAAI,CAAC,SAAS;AACb,UAAI,iBAAiB;AACpB,2BAAmB,UAAU,eAAe;AAAA,MAAA;AAE7C;AAAA,IAAA;AAED,QAAI,YAAY,iBAAiB;AAChC;AAAA,IAAA;AAGG,QAAA,CAAC,MAAM,WAAW;AACrB;AAAA,IAAA;AAKD,QAAI,CAAC,SAAS,CAAC,CAAC,iBAAiB;AAChC,eAAS,YAAY;AACrB,eAAS,SAAS,OAAO;AAAA,IAAA;AAAA,EAC1B,CACA;AAEM,SAAA;AAAA,IACN,KAAK;AAAA,IACL,SAAS,YAAY,MAAM;AAC1B,eAAS,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,IACL,QAAQ,YAAY,MAAM;AACzB,eAAS,KAAK;AACd,qBAAA,EAAiB,YAAY;AAC7B,UAAI,kBAAkB,SAAS;AACf,yBAAE,SAAS,kBAAkB,OAAO;AAAA,MAAA;AAAA,IAErD,GAAG,CAAC,cAAc,CAAC;AAAA,EACpB;AACD;AAEA,MAAM,qBAAqB,CAAC,OAA2B,YAAoB;AAC1E,QAAM,SAAS,MAAM,QAAQ,UAAU,CAAC;AAClC,QAAA,QAAQ,OAAO,OAAO,CAAK,MAAA,EAAE,EAAE,SAAS,gBAAgB,EAAE,YAAY,QAAQ;AACpF,QAAM,YAAY;AAClB,QAAM,QAAQ,CAAA,MAAK,MAAM,SAAS,CAAC,CAAC;AACrC;"}
|
|
@@ -1 +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\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: () => ({\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 = parseFloat(value)\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\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\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,cAAQ,MAAM;AACpB,UAAM,SAAS,MAAM;AACrB,UAAM,aAAa,OAAO;AACpB,UAAA,iBAAiB,2BAA2B,UAAmC,KAAK;AAC1F,UAAM,UAAU,eAAe,QAAQ,MAAM,WAAW;AACjD,WAAA;AAAA,MACN,mBAAmB,QAAQ;AAAA,MAC3B,aAAa,eAAe,QAAQ;AAAA,MACpC,YAAY,cAAc,QAAQ;AAAA,
|
|
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\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: () => ({\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 = parseFloat(value)\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\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\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":"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"}
|
|
@@ -1 +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\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: () => ({\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 = parseFloat(value)\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\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\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;AACpB,UAAA,iBAAiB,2BAA2B,UAAmC,KAAK;AAC1F,UAAM,UAAU,eAAe,QAAQ,MAAM,WAAW;AACjD,WAAA;AAAA,MACN,mBAAmB,QAAQ;AAAA,MAC3B,aAAa,eAAe,QAAQ;AAAA,MACpC,YAAY,cAAc,QAAQ;AAAA,
|
|
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\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: () => ({\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 = parseFloat(value)\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\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\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":"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"}
|
|
@@ -1 +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,
|
|
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,+CA4CvB,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { SugaredRelativeSingleField } from '@contember/react-binding';
|
|
|
3
3
|
export type FormFieldScopeProps = {
|
|
4
4
|
field: SugaredRelativeSingleField['field'];
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
required?: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare const FormFieldScope: ({ field, children }: FormFieldScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const FormFieldScope: ({ field, children, required }: FormFieldScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
9
|
//# sourceMappingURL=FormFieldScope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldScope.d.ts","sourceRoot":"","sources":["../../../src/components/FormFieldScope.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
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,kCAAmC,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,yDAAqF,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;CAc5E,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;CAc3F,CAAA"}
|
|
@@ -2,7 +2,11 @@ import { SugaredRelativeEntityList } from '@contember/react-binding';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
export type FormHasManyRelationScopeProps = {
|
|
4
4
|
field: SugaredRelativeEntityList['field'];
|
|
5
|
+
orderBy?: SugaredRelativeEntityList['orderBy'];
|
|
6
|
+
limit?: SugaredRelativeEntityList['limit'];
|
|
7
|
+
offset?: SugaredRelativeEntityList['offset'];
|
|
5
8
|
children: React.ReactNode;
|
|
9
|
+
required?: boolean;
|
|
6
10
|
};
|
|
7
|
-
export declare const FormHasManyRelationScope: ({
|
|
11
|
+
export declare const FormHasManyRelationScope: ({ children, required, ...props }: FormHasManyRelationScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
12
|
//# sourceMappingURL=FormHasManyRelationScope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormHasManyRelationScope.d.ts","sourceRoot":"","sources":["../../../src/components/FormHasManyRelationScope.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,qCAAsC,6BAA6B,4CAiBvG,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { SugaredRelativeSingleEntity } from '@contember/react-binding';
|
|
|
3
3
|
export type FormHasOneRelationScopeProps = {
|
|
4
4
|
field: SugaredRelativeSingleEntity['field'];
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
required?: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare const FormHasOneRelationScope: ({ field, children }: FormHasOneRelationScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const FormHasOneRelationScope: ({ field, children, required }: FormHasOneRelationScopeProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
9
|
//# sourceMappingURL=FormHasOneRelationScope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormHasOneRelationScope.d.ts","sourceRoot":"","sources":["../../../src/components/FormHasOneRelationScope.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
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,kCAAmC,4BAA4B,4CAgBlG,CAAA"}
|
|
@@ -1 +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;AAK3C,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,
|
|
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;AAK3C,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,4CAiCpB,CAAA"}
|
|
@@ -1 +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,UAAW;IAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAA;CAC5B,
|
|
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,UAAW;IAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAA;CAC5B,4CAeA,CAAA"}
|
|
@@ -2,7 +2,7 @@ import { OptionallyVariableFieldValue, SugaredRelativeSingleField } from '@conte
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
export interface FormRadioItemProps {
|
|
4
4
|
field: SugaredRelativeSingleField['field'];
|
|
5
|
-
value: string;
|
|
5
|
+
value: string | null | number | boolean;
|
|
6
6
|
isNonbearing?: boolean;
|
|
7
7
|
defaultValue?: OptionallyVariableFieldValue;
|
|
8
8
|
children: React.ReactNode;
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -1 +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,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
|
|
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"}
|
package/dist/types/contexts.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
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
|
+
*/
|
|
4
7
|
export declare const useFormFieldId: () => string | undefined;
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated use `useFormState` instead
|
|
10
|
+
*/
|
|
11
|
+
export declare const useFormError: () => import("@contember/binding-common").ErrorAccessor.Error[] | undefined;
|
|
8
12
|
//# sourceMappingURL=contexts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/contexts.
|
|
1
|
+
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/contexts.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,qBAAqB,qDAA4B,CAAA;AAC9D,eAAO,MAAM,iBAAiB,kCAA4B,CAAA;AAG1D;;GAEG;AACH,eAAO,MAAM,cAAc,0BAAoC,CAAA;AAE/D;;GAEG;AACH,eAAO,MAAM,YAAY,6EAAoC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormInputValidationHandler.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFormInputValidationHandler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,aAAa,EAA0B,MAAM,0BAA0B,CAAA;AAEhF,eAAO,MAAM,6BAA6B,UAAW,aAAa,CAAC,GAAG,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"useFormInputValidationHandler.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFormInputValidationHandler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,aAAa,EAA0B,MAAM,0BAA0B,CAAA;AAEhF,eAAO,MAAM,6BAA6B,UAAW,aAAa,CAAC,GAAG,CAAC;;;;CA4DtE,CAAA"}
|