@contember/react-form 1.3.0-alpha.14
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/components/FormCheckbox.cjs +68 -0
- package/dist/development/components/FormCheckbox.cjs.map +1 -0
- package/dist/development/components/FormCheckbox.js +52 -0
- package/dist/development/components/FormCheckbox.js.map +1 -0
- package/dist/development/components/FormError.cjs +22 -0
- package/dist/development/components/FormError.cjs.map +1 -0
- package/dist/development/components/FormError.js +22 -0
- package/dist/development/components/FormError.js.map +1 -0
- package/dist/development/components/FormFieldScope.cjs +15 -0
- package/dist/development/components/FormFieldScope.cjs.map +1 -0
- package/dist/development/components/FormFieldScope.js +15 -0
- package/dist/development/components/FormFieldScope.js.map +1 -0
- package/dist/development/components/FormHasManyRelationScope.cjs +15 -0
- package/dist/development/components/FormHasManyRelationScope.cjs.map +1 -0
- package/dist/development/components/FormHasManyRelationScope.js +15 -0
- package/dist/development/components/FormHasManyRelationScope.js.map +1 -0
- package/dist/development/components/FormHasOneRelationScope.cjs +15 -0
- package/dist/development/components/FormHasOneRelationScope.cjs.map +1 -0
- package/dist/development/components/FormHasOneRelationScope.js +15 -0
- package/dist/development/components/FormHasOneRelationScope.js.map +1 -0
- package/dist/development/components/FormInput.cjs +40 -0
- package/dist/development/components/FormInput.cjs.map +1 -0
- package/dist/development/components/FormInput.js +40 -0
- package/dist/development/components/FormInput.js.map +1 -0
- package/dist/development/components/FormLabel.cjs +24 -0
- package/dist/development/components/FormLabel.cjs.map +1 -0
- package/dist/development/components/FormLabel.js +24 -0
- package/dist/development/components/FormLabel.js.map +1 -0
- package/dist/development/components/FormRadioInput.cjs +39 -0
- package/dist/development/components/FormRadioInput.cjs.map +1 -0
- package/dist/development/components/FormRadioInput.js +39 -0
- package/dist/development/components/FormRadioInput.js.map +1 -0
- package/dist/development/contexts.cjs +14 -0
- package/dist/development/contexts.cjs.map +1 -0
- package/dist/development/contexts.js +14 -0
- package/dist/development/contexts.js.map +1 -0
- package/dist/development/hooks/useFormInputValidationHandler.cjs +64 -0
- package/dist/development/hooks/useFormInputValidationHandler.cjs.map +1 -0
- package/dist/development/hooks/useFormInputValidationHandler.js +48 -0
- package/dist/development/hooks/useFormInputValidationHandler.js.map +1 -0
- package/dist/development/index.cjs +26 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +26 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/internal/useFormInputHandler.cjs +98 -0
- package/dist/development/internal/useFormInputHandler.cjs.map +1 -0
- package/dist/development/internal/useFormInputHandler.js +98 -0
- package/dist/development/internal/useFormInputHandler.js.map +1 -0
- package/dist/production/components/FormCheckbox.cjs +68 -0
- package/dist/production/components/FormCheckbox.cjs.map +1 -0
- package/dist/production/components/FormCheckbox.js +52 -0
- package/dist/production/components/FormCheckbox.js.map +1 -0
- package/dist/production/components/FormError.cjs +22 -0
- package/dist/production/components/FormError.cjs.map +1 -0
- package/dist/production/components/FormError.js +22 -0
- package/dist/production/components/FormError.js.map +1 -0
- package/dist/production/components/FormFieldScope.cjs +15 -0
- package/dist/production/components/FormFieldScope.cjs.map +1 -0
- package/dist/production/components/FormFieldScope.js +15 -0
- package/dist/production/components/FormFieldScope.js.map +1 -0
- package/dist/production/components/FormHasManyRelationScope.cjs +15 -0
- package/dist/production/components/FormHasManyRelationScope.cjs.map +1 -0
- package/dist/production/components/FormHasManyRelationScope.js +15 -0
- package/dist/production/components/FormHasManyRelationScope.js.map +1 -0
- package/dist/production/components/FormHasOneRelationScope.cjs +15 -0
- package/dist/production/components/FormHasOneRelationScope.cjs.map +1 -0
- package/dist/production/components/FormHasOneRelationScope.js +15 -0
- package/dist/production/components/FormHasOneRelationScope.js.map +1 -0
- package/dist/production/components/FormInput.cjs +40 -0
- package/dist/production/components/FormInput.cjs.map +1 -0
- package/dist/production/components/FormInput.js +40 -0
- package/dist/production/components/FormInput.js.map +1 -0
- package/dist/production/components/FormLabel.cjs +24 -0
- package/dist/production/components/FormLabel.cjs.map +1 -0
- package/dist/production/components/FormLabel.js +24 -0
- package/dist/production/components/FormLabel.js.map +1 -0
- package/dist/production/components/FormRadioInput.cjs +39 -0
- package/dist/production/components/FormRadioInput.cjs.map +1 -0
- package/dist/production/components/FormRadioInput.js +39 -0
- package/dist/production/components/FormRadioInput.js.map +1 -0
- package/dist/production/contexts.cjs +14 -0
- package/dist/production/contexts.cjs.map +1 -0
- package/dist/production/contexts.js +14 -0
- package/dist/production/contexts.js.map +1 -0
- package/dist/production/hooks/useFormInputValidationHandler.cjs +64 -0
- package/dist/production/hooks/useFormInputValidationHandler.cjs.map +1 -0
- package/dist/production/hooks/useFormInputValidationHandler.js +48 -0
- package/dist/production/hooks/useFormInputValidationHandler.js.map +1 -0
- package/dist/production/index.cjs +26 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +26 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/internal/useFormInputHandler.cjs +98 -0
- package/dist/production/internal/useFormInputHandler.cjs.map +1 -0
- package/dist/production/internal/useFormInputHandler.js +98 -0
- package/dist/production/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 +8 -0
- package/dist/types/components/FormFieldScope.d.ts.map +1 -0
- package/dist/types/components/FormHasManyRelationScope.d.ts +8 -0
- package/dist/types/components/FormHasManyRelationScope.d.ts.map +1 -0
- package/dist/types/components/FormHasOneRelationScope.d.ts +8 -0
- package/dist/types/components/FormHasOneRelationScope.d.ts.map +1 -0
- package/dist/types/components/FormInput.d.ts +10 -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 +9 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/contexts.d.ts +8 -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 +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/internal/useFormInputHandler.d.ts +8 -0
- package/dist/types/internal/useFormInputHandler.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +57 -0
- package/src/components/FormCheckbox.tsx +58 -0
- package/src/components/FormError.tsx +22 -0
- package/src/components/FormFieldScope.tsx +24 -0
- package/src/components/FormHasManyRelationScope.tsx +24 -0
- package/src/components/FormHasOneRelationScope.tsx +24 -0
- package/src/components/FormInput.tsx +46 -0
- package/src/components/FormLabel.tsx +22 -0
- package/src/components/FormRadioInput.tsx +45 -0
- package/src/components/index.ts +8 -0
- package/src/contexts.ts +12 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useFormInputValidationHandler.tsx +47 -0
- package/src/index.ts +3 -0
- package/src/internal/useFormInputHandler.ts +104 -0
- package/src/tsconfig.json +11 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const contexts = require("../contexts.cjs");
|
|
6
|
+
const reactBinding = require("@contember/react-binding");
|
|
7
|
+
const emptyArr = [];
|
|
8
|
+
const FormFieldScope = ({ field, children }) => {
|
|
9
|
+
const id = React.useId();
|
|
10
|
+
const fieldAccessor = reactBinding.useField({ field });
|
|
11
|
+
const errors = fieldAccessor.errors?.errors;
|
|
12
|
+
return /* @__PURE__ */ jsxRuntime.jsx(contexts.FormFieldIdContext.Provider, { value: id, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.FormErrorContext.Provider, { value: errors ?? emptyArr, children }) });
|
|
13
|
+
};
|
|
14
|
+
exports.FormFieldScope = FormFieldScope;
|
|
15
|
+
//# sourceMappingURL=FormFieldScope.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldScope.cjs","sources":["../../../src/components/FormFieldScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useId } from 'react'\nimport { FormErrorContext, FormFieldIdContext } from '../contexts'\nimport { SugaredRelativeSingleField, useField } from '@contember/react-binding'\n\nconst emptyArr: [] = []\n\nexport type FormFieldScopeProps = {\n\tfield: SugaredRelativeSingleField['field']\n\tchildren: React.ReactNode\n}\n\nexport const FormFieldScope = ({ field, children }: FormFieldScopeProps) => {\n\tconst id = useId()\n\tconst fieldAccessor = useField({ field })\n\tconst errors = fieldAccessor.errors?.errors\n\treturn (\n\t\t<FormFieldIdContext.Provider value={id}>\n\t\t\t<FormErrorContext.Provider value={errors ?? emptyArr}>\n\t\t\t\t{children}\n\t\t\t</FormErrorContext.Provider>\n\t\t</FormFieldIdContext.Provider>\n\t)\n}\n"],"names":["useId","useField","jsx","FormFieldIdContext","FormErrorContext"],"mappings":";;;;;;AAKA,MAAM,WAAe,CAAA;AAOd,MAAM,iBAAiB,CAAC,EAAE,OAAO,eAAoC;AAC3E,QAAM,KAAKA,MAAAA;AACX,QAAM,gBAAgBC,aAAAA,SAAS,EAAE,MAAO,CAAA;AAClC,QAAA,SAAS,cAAc,QAAQ;AACrC,SACEC,2BAAAA,IAAAC,SAAAA,mBAAmB,UAAnB,EAA4B,OAAO,IACnC,UAAAD,2BAAA,IAACE,SAAiB,iBAAA,UAAjB,EAA0B,OAAO,UAAU,UAC1C,UACF,EACD,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { FormFieldIdContext, FormErrorContext } from "../contexts.js";
|
|
4
|
+
import { useField } from "@contember/react-binding";
|
|
5
|
+
const emptyArr = [];
|
|
6
|
+
const FormFieldScope = ({ field, children }) => {
|
|
7
|
+
const id = useId();
|
|
8
|
+
const fieldAccessor = useField({ field });
|
|
9
|
+
const errors = fieldAccessor.errors?.errors;
|
|
10
|
+
return /* @__PURE__ */ jsx(FormFieldIdContext.Provider, { value: id, children: /* @__PURE__ */ jsx(FormErrorContext.Provider, { value: errors ?? emptyArr, children }) });
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
FormFieldScope
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=FormFieldScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldScope.js","sources":["../../../src/components/FormFieldScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useId } from 'react'\nimport { FormErrorContext, FormFieldIdContext } from '../contexts'\nimport { SugaredRelativeSingleField, useField } from '@contember/react-binding'\n\nconst emptyArr: [] = []\n\nexport type FormFieldScopeProps = {\n\tfield: SugaredRelativeSingleField['field']\n\tchildren: React.ReactNode\n}\n\nexport const FormFieldScope = ({ field, children }: FormFieldScopeProps) => {\n\tconst id = useId()\n\tconst fieldAccessor = useField({ field })\n\tconst errors = fieldAccessor.errors?.errors\n\treturn (\n\t\t<FormFieldIdContext.Provider value={id}>\n\t\t\t<FormErrorContext.Provider value={errors ?? emptyArr}>\n\t\t\t\t{children}\n\t\t\t</FormErrorContext.Provider>\n\t\t</FormFieldIdContext.Provider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,WAAe,CAAA;AAOd,MAAM,iBAAiB,CAAC,EAAE,OAAO,eAAoC;AAC3E,QAAM,KAAK;AACX,QAAM,gBAAgB,SAAS,EAAE,MAAO,CAAA;AAClC,QAAA,SAAS,cAAc,QAAQ;AACrC,SACE,oBAAA,mBAAmB,UAAnB,EAA4B,OAAO,IACnC,UAAA,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,UAAU,UAC1C,UACF,EACD,CAAA;AAEF;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const reactBinding = require("@contember/react-binding");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const contexts = require("../contexts.cjs");
|
|
7
|
+
const emptyArr = [];
|
|
8
|
+
const FormHasManyRelationScope = ({ field, children }) => {
|
|
9
|
+
const id = React.useId();
|
|
10
|
+
const entityRelation = reactBinding.useEntityList({ field });
|
|
11
|
+
const errors = entityRelation.errors?.errors;
|
|
12
|
+
return /* @__PURE__ */ jsxRuntime.jsx(contexts.FormFieldIdContext.Provider, { value: id, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.FormErrorContext.Provider, { value: errors ?? emptyArr, children }) });
|
|
13
|
+
};
|
|
14
|
+
exports.FormHasManyRelationScope = FormHasManyRelationScope;
|
|
15
|
+
//# sourceMappingURL=FormHasManyRelationScope.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormHasManyRelationScope.cjs","sources":["../../../src/components/FormHasManyRelationScope.tsx"],"sourcesContent":["import { SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport * as React from 'react'\nimport { useId } from 'react'\nimport { FormErrorContext, FormFieldIdContext } from '../contexts'\n\nconst emptyArr: [] = []\n\nexport type FormHasManyRelationScopeProps = {\n\tfield: SugaredRelativeEntityList['field']\n\tchildren: React.ReactNode\n}\n\nexport const FormHasManyRelationScope = ({ field, children }: FormHasManyRelationScopeProps) => {\n\tconst id = useId()\n\tconst entityRelation = useEntityList({ field })\n\tconst errors = entityRelation.errors?.errors\n\treturn (\n\t\t<FormFieldIdContext.Provider value={id}>\n\t\t\t<FormErrorContext.Provider value={errors ?? emptyArr}>\n\t\t\t\t{children}\n\t\t\t</FormErrorContext.Provider>\n\t\t</FormFieldIdContext.Provider>\n\t)\n}\n"],"names":["useId","useEntityList","jsx","FormFieldIdContext","FormErrorContext"],"mappings":";;;;;;AAKA,MAAM,WAAe,CAAA;AAOd,MAAM,2BAA2B,CAAC,EAAE,OAAO,eAA8C;AAC/F,QAAM,KAAKA,MAAAA;AACX,QAAM,iBAAiBC,aAAAA,cAAc,EAAE,MAAO,CAAA;AACxC,QAAA,SAAS,eAAe,QAAQ;AACtC,SACEC,2BAAAA,IAAAC,SAAAA,mBAAmB,UAAnB,EAA4B,OAAO,IACnC,UAAAD,2BAAA,IAACE,SAAiB,iBAAA,UAAjB,EAA0B,OAAO,UAAU,UAC1C,UACF,EACD,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEntityList } from "@contember/react-binding";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { FormFieldIdContext, FormErrorContext } from "../contexts.js";
|
|
5
|
+
const emptyArr = [];
|
|
6
|
+
const FormHasManyRelationScope = ({ field, children }) => {
|
|
7
|
+
const id = useId();
|
|
8
|
+
const entityRelation = useEntityList({ field });
|
|
9
|
+
const errors = entityRelation.errors?.errors;
|
|
10
|
+
return /* @__PURE__ */ jsx(FormFieldIdContext.Provider, { value: id, children: /* @__PURE__ */ jsx(FormErrorContext.Provider, { value: errors ?? emptyArr, children }) });
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
FormHasManyRelationScope
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=FormHasManyRelationScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormHasManyRelationScope.js","sources":["../../../src/components/FormHasManyRelationScope.tsx"],"sourcesContent":["import { SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport * as React from 'react'\nimport { useId } from 'react'\nimport { FormErrorContext, FormFieldIdContext } from '../contexts'\n\nconst emptyArr: [] = []\n\nexport type FormHasManyRelationScopeProps = {\n\tfield: SugaredRelativeEntityList['field']\n\tchildren: React.ReactNode\n}\n\nexport const FormHasManyRelationScope = ({ field, children }: FormHasManyRelationScopeProps) => {\n\tconst id = useId()\n\tconst entityRelation = useEntityList({ field })\n\tconst errors = entityRelation.errors?.errors\n\treturn (\n\t\t<FormFieldIdContext.Provider value={id}>\n\t\t\t<FormErrorContext.Provider value={errors ?? emptyArr}>\n\t\t\t\t{children}\n\t\t\t</FormErrorContext.Provider>\n\t\t</FormFieldIdContext.Provider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,WAAe,CAAA;AAOd,MAAM,2BAA2B,CAAC,EAAE,OAAO,eAA8C;AAC/F,QAAM,KAAK;AACX,QAAM,iBAAiB,cAAc,EAAE,MAAO,CAAA;AACxC,QAAA,SAAS,eAAe,QAAQ;AACtC,SACE,oBAAA,mBAAmB,UAAnB,EAA4B,OAAO,IACnC,UAAA,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,UAAU,UAC1C,UACF,EACD,CAAA;AAEF;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const contexts = require("../contexts.cjs");
|
|
6
|
+
const reactBinding = require("@contember/react-binding");
|
|
7
|
+
const emptyArr = [];
|
|
8
|
+
const FormHasOneRelationScope = ({ field, children }) => {
|
|
9
|
+
const id = React.useId();
|
|
10
|
+
const entityRelation = reactBinding.useEntity({ field });
|
|
11
|
+
const errors = entityRelation.errors?.errors;
|
|
12
|
+
return /* @__PURE__ */ jsxRuntime.jsx(contexts.FormFieldIdContext.Provider, { value: id, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.FormErrorContext.Provider, { value: errors ?? emptyArr, children }) });
|
|
13
|
+
};
|
|
14
|
+
exports.FormHasOneRelationScope = FormHasOneRelationScope;
|
|
15
|
+
//# sourceMappingURL=FormHasOneRelationScope.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormHasOneRelationScope.cjs","sources":["../../../src/components/FormHasOneRelationScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useId } from 'react'\nimport { FormErrorContext, FormFieldIdContext } from '../contexts'\nimport { SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\n\nconst emptyArr: [] = []\n\nexport type FormHasOneRelationScopeProps = {\n\tfield: SugaredRelativeSingleEntity['field']\n\tchildren: React.ReactNode\n}\n\nexport const FormHasOneRelationScope = ({ field, children }: FormHasOneRelationScopeProps) => {\n\tconst id = useId()\n\tconst entityRelation = useEntity({ field })\n\tconst errors = entityRelation.errors?.errors\n\treturn (\n\t\t<FormFieldIdContext.Provider value={id}>\n\t\t\t<FormErrorContext.Provider value={errors ?? emptyArr}>\n\t\t\t\t{children}\n\t\t\t</FormErrorContext.Provider>\n\t\t</FormFieldIdContext.Provider>\n\t)\n}\n"],"names":["useId","useEntity","jsx","FormFieldIdContext","FormErrorContext"],"mappings":";;;;;;AAKA,MAAM,WAAe,CAAA;AAOd,MAAM,0BAA0B,CAAC,EAAE,OAAO,eAA6C;AAC7F,QAAM,KAAKA,MAAAA;AACX,QAAM,iBAAiBC,aAAAA,UAAU,EAAE,MAAO,CAAA;AACpC,QAAA,SAAS,eAAe,QAAQ;AACtC,SACEC,2BAAAA,IAAAC,SAAAA,mBAAmB,UAAnB,EAA4B,OAAO,IACnC,UAAAD,2BAAA,IAACE,SAAiB,iBAAA,UAAjB,EAA0B,OAAO,UAAU,UAC1C,UACF,EACD,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { FormFieldIdContext, FormErrorContext } from "../contexts.js";
|
|
4
|
+
import { useEntity } from "@contember/react-binding";
|
|
5
|
+
const emptyArr = [];
|
|
6
|
+
const FormHasOneRelationScope = ({ field, children }) => {
|
|
7
|
+
const id = useId();
|
|
8
|
+
const entityRelation = useEntity({ field });
|
|
9
|
+
const errors = entityRelation.errors?.errors;
|
|
10
|
+
return /* @__PURE__ */ jsx(FormFieldIdContext.Provider, { value: id, children: /* @__PURE__ */ jsx(FormErrorContext.Provider, { value: errors ?? emptyArr, children }) });
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
FormHasOneRelationScope
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=FormHasOneRelationScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormHasOneRelationScope.js","sources":["../../../src/components/FormHasOneRelationScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useId } from 'react'\nimport { FormErrorContext, FormFieldIdContext } from '../contexts'\nimport { SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\n\nconst emptyArr: [] = []\n\nexport type FormHasOneRelationScopeProps = {\n\tfield: SugaredRelativeSingleEntity['field']\n\tchildren: React.ReactNode\n}\n\nexport const FormHasOneRelationScope = ({ field, children }: FormHasOneRelationScopeProps) => {\n\tconst id = useId()\n\tconst entityRelation = useEntity({ field })\n\tconst errors = entityRelation.errors?.errors\n\treturn (\n\t\t<FormFieldIdContext.Provider value={id}>\n\t\t\t<FormErrorContext.Provider value={errors ?? emptyArr}>\n\t\t\t\t{children}\n\t\t\t</FormErrorContext.Provider>\n\t\t</FormFieldIdContext.Provider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,WAAe,CAAA;AAOd,MAAM,0BAA0B,CAAC,EAAE,OAAO,eAA6C;AAC7F,QAAM,KAAK;AACX,QAAM,iBAAiB,UAAU,EAAE,MAAO,CAAA;AACpC,QAAA,SAAS,eAAe,QAAQ;AACtC,SACE,oBAAA,mBAAmB,UAAnB,EAA4B,OAAO,IACnC,UAAA,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,UAAU,UAC1C,UACF,EACD,CAAA;AAEF;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
6
|
+
const reactBinding = require("@contember/react-binding");
|
|
7
|
+
const utilities = require("@contember/utilities");
|
|
8
|
+
const useFormInputHandler = require("../internal/useFormInputHandler.cjs");
|
|
9
|
+
const contexts = require("../contexts.cjs");
|
|
10
|
+
const useFormInputValidationHandler = require("../hooks/useFormInputValidationHandler.cjs");
|
|
11
|
+
const SlotInput = reactSlot.Slot;
|
|
12
|
+
const FormInput = reactBinding.Component(({ field, isNonbearing, defaultValue, ...props }) => {
|
|
13
|
+
const id = contexts.useFormFieldId();
|
|
14
|
+
const accessor = reactBinding.useField(field);
|
|
15
|
+
const errors = contexts.useFormError() ?? accessor.errors?.errors ?? [];
|
|
16
|
+
const { parseValue, formatValue, defaultInputProps } = useFormInputHandler.useFormInputHandler(accessor);
|
|
17
|
+
const accessorGetter = accessor.getAccessor;
|
|
18
|
+
const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
|
|
19
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
20
|
+
SlotInput,
|
|
21
|
+
{
|
|
22
|
+
ref,
|
|
23
|
+
value: formatValue(accessor.value),
|
|
24
|
+
"data-invalid": utilities.dataAttribute(errors.length > 0),
|
|
25
|
+
onFocus,
|
|
26
|
+
onBlur,
|
|
27
|
+
onChange: React.useCallback((e) => {
|
|
28
|
+
accessorGetter().updateValue(parseValue(e.target.value));
|
|
29
|
+
}, [accessorGetter, parseValue]),
|
|
30
|
+
...defaultInputProps,
|
|
31
|
+
id: id ? `${id}-input` : void 0,
|
|
32
|
+
required: !accessor.schema.nullable,
|
|
33
|
+
...props
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}, ({ field, isNonbearing, defaultValue }) => {
|
|
37
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { field, isNonbearing, defaultValue });
|
|
38
|
+
});
|
|
39
|
+
exports.FormInput = FormInput;
|
|
40
|
+
//# sourceMappingURL=FormInput.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormInput.cjs","sources":["../../../src/components/FormInput.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ComponentType, useCallback } from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputHandler } from '../internal/useFormInputHandler'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks/useFormInputValidationHandler'\n\ntype InputProps = React.JSX.IntrinsicElements['input']\nconst SlotInput = Slot as ComponentType<InputProps>\n\nexport interface FormInputProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactElement\n}\n\nexport const FormInput = Component<FormInputProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField(field)\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor)\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\tvalue={formatValue(accessor.value)}\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(parseValue(e.target.value))\n\t\t\t}, [accessorGetter, parseValue])}\n\t\t\t{...defaultInputProps}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\trequired={!accessor.schema.nullable}\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":["Slot","Component","useFormFieldId","useField","useFormError","useFormInputHandler","useFormInputValidationHandler","jsx","dataAttribute","useCallback","Field"],"mappings":";;;;;;;;;;AAUA,MAAM,YAAYA,UAAAA;AASL,MAAA,YAAYC,uBAA0B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAM,KAAKC,SAAAA;AACL,QAAA,WAAWC,sBAAS,KAAK;AAC/B,QAAM,SAASC,SAAAA,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,EAAE,YAAY,aAAa,kBAAkB,IAAIC,oBAAAA,oBAAoB,QAAQ;AACnF,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAIC,8BAAAA,8BAA8B,QAAQ;AAGtE,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,OAAO,YAAY,SAAS,KAAK;AAAA,MACjC,gBAAcC,UAAA,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C;AAAA,MACA;AAAA,MACA,UAAUC,MAAAA,YAAkD,CAAK,MAAA;AAChE,uBAAA,EAAiB,YAAY,WAAW,EAAE,OAAO,KAAK,CAAC;AAAA,MAAA,GACrD,CAAC,gBAAgB,UAAU,CAAC;AAAA,MAC9B,GAAG;AAAA,MACJ,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB,UAAU,CAAC,SAAS,OAAO;AAAA,MAC1B,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQF,2BAAAA,IAAAG,aAAAA,OAAA,EAAM,OAAc,cAA4B,aAA4B,CAAA;AACrF,CAAC;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
4
|
+
import { Component, useField, Field } from "@contember/react-binding";
|
|
5
|
+
import { dataAttribute } from "@contember/utilities";
|
|
6
|
+
import { useFormInputHandler } from "../internal/useFormInputHandler.js";
|
|
7
|
+
import { useFormFieldId, useFormError } from "../contexts.js";
|
|
8
|
+
import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
|
|
9
|
+
const SlotInput = Slot;
|
|
10
|
+
const FormInput = Component(({ field, isNonbearing, defaultValue, ...props }) => {
|
|
11
|
+
const id = useFormFieldId();
|
|
12
|
+
const accessor = useField(field);
|
|
13
|
+
const errors = useFormError() ?? accessor.errors?.errors ?? [];
|
|
14
|
+
const { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor);
|
|
15
|
+
const accessorGetter = accessor.getAccessor;
|
|
16
|
+
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
|
|
17
|
+
return /* @__PURE__ */ jsx(
|
|
18
|
+
SlotInput,
|
|
19
|
+
{
|
|
20
|
+
ref,
|
|
21
|
+
value: formatValue(accessor.value),
|
|
22
|
+
"data-invalid": dataAttribute(errors.length > 0),
|
|
23
|
+
onFocus,
|
|
24
|
+
onBlur,
|
|
25
|
+
onChange: useCallback((e) => {
|
|
26
|
+
accessorGetter().updateValue(parseValue(e.target.value));
|
|
27
|
+
}, [accessorGetter, parseValue]),
|
|
28
|
+
...defaultInputProps,
|
|
29
|
+
id: id ? `${id}-input` : void 0,
|
|
30
|
+
required: !accessor.schema.nullable,
|
|
31
|
+
...props
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}, ({ field, isNonbearing, defaultValue }) => {
|
|
35
|
+
return /* @__PURE__ */ jsx(Field, { field, isNonbearing, defaultValue });
|
|
36
|
+
});
|
|
37
|
+
export {
|
|
38
|
+
FormInput
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=FormInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormInput.js","sources":["../../../src/components/FormInput.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ComponentType, useCallback } from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputHandler } from '../internal/useFormInputHandler'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks/useFormInputValidationHandler'\n\ntype InputProps = React.JSX.IntrinsicElements['input']\nconst SlotInput = Slot as ComponentType<InputProps>\n\nexport interface FormInputProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactElement\n}\n\nexport const FormInput = Component<FormInputProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField(field)\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor)\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\tvalue={formatValue(accessor.value)}\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(parseValue(e.target.value))\n\t\t\t}, [accessorGetter, parseValue])}\n\t\t\t{...defaultInputProps}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\trequired={!accessor.schema.nullable}\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":";;;;;;;;AAUA,MAAM,YAAY;AASL,MAAA,YAAY,UAA0B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAM,KAAK;AACL,QAAA,WAAW,SAAS,KAAK;AAC/B,QAAM,SAAS,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,EAAE,YAAY,aAAa,kBAAkB,IAAI,oBAAoB,QAAQ;AACnF,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAI,8BAA8B,QAAQ;AAGtE,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,OAAO,YAAY,SAAS,KAAK;AAAA,MACjC,gBAAc,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C;AAAA,MACA;AAAA,MACA,UAAU,YAAkD,CAAK,MAAA;AAChE,uBAAA,EAAiB,YAAY,WAAW,EAAE,OAAO,KAAK,CAAC;AAAA,MAAA,GACrD,CAAC,gBAAgB,UAAU,CAAC;AAAA,MAC9B,GAAG;AAAA,MACJ,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB,UAAU,CAAC,SAAS,OAAO;AAAA,MAC1B,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,aAA4B,CAAA;AACrF,CAAC;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
5
|
+
const utilities = require("@contember/utilities");
|
|
6
|
+
const contexts = require("../contexts.cjs");
|
|
7
|
+
const reactBinding = require("@contember/react-binding");
|
|
8
|
+
const FormLabel = (props) => {
|
|
9
|
+
const id = contexts.useFormFieldId();
|
|
10
|
+
const errors = contexts.useFormError();
|
|
11
|
+
if (errors === void 0 || id === void 0) {
|
|
12
|
+
throw new reactBinding.BindingError("FormLabel must be used inside a FormField");
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
15
|
+
reactSlot.Slot,
|
|
16
|
+
{
|
|
17
|
+
"data-invalid": utilities.dataAttribute(errors.length > 0),
|
|
18
|
+
...{ htmlFor: `${id}-input` },
|
|
19
|
+
...props
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
exports.FormLabel = FormLabel;
|
|
24
|
+
//# sourceMappingURL=FormLabel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormLabel.cjs","sources":["../../../src/components/FormLabel.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { BindingError } from '@contember/react-binding'\n\nexport const FormLabel = (props: {\n\tchildren: React.ReactElement\n}) => {\n\tconst id = useFormFieldId()\n\tconst errors = useFormError()\n\tif (errors === undefined || id === undefined) {\n\t\tthrow new BindingError('FormLabel must be used inside a FormField')\n\t}\n\treturn (\n\t\t<Slot\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\t{...{ htmlFor: `${id}-input` }}\n\t\t\t{...props}\n\t\t/>\n\t)\n}\n"],"names":["useFormFieldId","useFormError","BindingError","jsx","Slot","dataAttribute"],"mappings":";;;;;;;AAMa,MAAA,YAAY,CAAC,UAEpB;AACL,QAAM,KAAKA,SAAAA;AACX,QAAM,SAASC,SAAAA;AACX,MAAA,WAAW,UAAa,OAAO,QAAW;AACvC,UAAA,IAAIC,aAAAA,aAAa,2CAA2C;AAAA,EACnE;AAEC,SAAAC,2BAAA;AAAA,IAACC,UAAA;AAAA,IAAA;AAAA,MACA,gBAAcC,UAAA,cAAc,OAAO,SAAS,CAAC;AAAA,MAC5C,GAAG,EAAE,SAAS,GAAG,EAAE,SAAS;AAAA,MAC5B,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
3
|
+
import { dataAttribute } from "@contember/utilities";
|
|
4
|
+
import { useFormFieldId, useFormError } from "../contexts.js";
|
|
5
|
+
import { BindingError } from "@contember/react-binding";
|
|
6
|
+
const FormLabel = (props) => {
|
|
7
|
+
const id = useFormFieldId();
|
|
8
|
+
const errors = useFormError();
|
|
9
|
+
if (errors === void 0 || id === void 0) {
|
|
10
|
+
throw new BindingError("FormLabel must be used inside a FormField");
|
|
11
|
+
}
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
Slot,
|
|
14
|
+
{
|
|
15
|
+
"data-invalid": dataAttribute(errors.length > 0),
|
|
16
|
+
...{ htmlFor: `${id}-input` },
|
|
17
|
+
...props
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
FormLabel
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=FormLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormLabel.js","sources":["../../../src/components/FormLabel.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { BindingError } from '@contember/react-binding'\n\nexport const FormLabel = (props: {\n\tchildren: React.ReactElement\n}) => {\n\tconst id = useFormFieldId()\n\tconst errors = useFormError()\n\tif (errors === undefined || id === undefined) {\n\t\tthrow new BindingError('FormLabel must be used inside a FormField')\n\t}\n\treturn (\n\t\t<Slot\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\t{...{ htmlFor: `${id}-input` }}\n\t\t\t{...props}\n\t\t/>\n\t)\n}\n"],"names":[],"mappings":";;;;;AAMa,MAAA,YAAY,CAAC,UAEpB;AACL,QAAM,KAAK;AACX,QAAM,SAAS;AACX,MAAA,WAAW,UAAa,OAAO,QAAW;AACvC,UAAA,IAAI,aAAa,2CAA2C;AAAA,EACnE;AAEC,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,gBAAc,cAAc,OAAO,SAAS,CAAC;AAAA,MAC5C,GAAG,EAAE,SAAS,GAAG,EAAE,SAAS;AAAA,MAC5B,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const reactBinding = require("@contember/react-binding");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
7
|
+
const contexts = require("../contexts.cjs");
|
|
8
|
+
const utilities = require("@contember/utilities");
|
|
9
|
+
const useFormInputValidationHandler = require("../hooks/useFormInputValidationHandler.cjs");
|
|
10
|
+
const SlotInput = reactSlot.Slot;
|
|
11
|
+
const FormRadioInput = reactBinding.Component(({ field, value, defaultValue, isNonbearing, ...props }) => {
|
|
12
|
+
const id = contexts.useFormFieldId();
|
|
13
|
+
const accessor = reactBinding.useField(field);
|
|
14
|
+
const errors = contexts.useFormError() ?? accessor.errors?.errors ?? [];
|
|
15
|
+
const accessorGetter = accessor.getAccessor;
|
|
16
|
+
const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
18
|
+
SlotInput,
|
|
19
|
+
{
|
|
20
|
+
ref,
|
|
21
|
+
type: "radio",
|
|
22
|
+
value,
|
|
23
|
+
checked: accessor.value === value,
|
|
24
|
+
"data-invalid": utilities.dataAttribute(errors.length > 0),
|
|
25
|
+
name: id + "-input",
|
|
26
|
+
id: `${id}-input-${value}`,
|
|
27
|
+
onFocus,
|
|
28
|
+
onBlur,
|
|
29
|
+
onChange: React.useCallback((e) => {
|
|
30
|
+
accessorGetter().updateValue(value);
|
|
31
|
+
}, [accessorGetter, value]),
|
|
32
|
+
...props
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}, ({ field, isNonbearing, defaultValue }) => {
|
|
36
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { field, isNonbearing, defaultValue });
|
|
37
|
+
});
|
|
38
|
+
exports.FormRadioInput = FormRadioInput;
|
|
39
|
+
//# sourceMappingURL=FormRadioInput.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormRadioInput.cjs","sources":["../../../src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport * as React from 'react'\nimport { ChangeEventHandler, useCallback } from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { dataAttribute } from '@contember/utilities'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormRadioItemProps {\n\tfield: SugaredRelativeSingleField['field']\n\tvalue: string\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactNode\n}\n\nexport const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField<string>(field)\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\ttype=\"radio\"\n\t\t\tvalue={value}\n\t\t\tchecked={accessor.value === value}\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tname={id + '-input'}\n\t\t\tid={`${id}-input-${value}`}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(value)\n\t\t\t}, [accessorGetter, value])}\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":["Slot","Component","useFormFieldId","useField","useFormError","useFormInputValidationHandler","jsx","dataAttribute","useCallback","Field"],"mappings":";;;;;;;;;AAQA,MAAM,YAAYA,UAAAA;AAUL,MAAA,iBAAiBC,aAAAA,UAA8B,CAAC,EAAE,OAAO,OAAO,cAAc,cAAc,GAAG,YAAY;AACvH,QAAM,KAAKC,SAAAA;AACL,QAAA,WAAWC,sBAAiB,KAAK;AACvC,QAAM,SAASC,SAAAA,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAIC,8BAAAA,8BAA8B,QAAQ;AAGtE,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,MAAK;AAAA,MACL;AAAA,MACA,SAAS,SAAS,UAAU;AAAA,MAC5B,gBAAcC,UAAA,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,MAAM,KAAK;AAAA,MACX,IAAI,GAAG,EAAE,UAAU,KAAK;AAAA,MACxB;AAAA,MACA;AAAA,MACA,UAAUC,MAAAA,YAAkD,CAAK,MAAA;AACjD,uBAAA,EAAE,YAAY,KAAK;AAAA,MAAA,GAChC,CAAC,gBAAgB,KAAK,CAAC;AAAA,MACzB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQF,2BAAAA,IAAAG,aAAAA,OAAA,EAAM,OAAc,cAA4B,aAA4B,CAAA;AACrF,CAAC;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Component, useField, Field } from "@contember/react-binding";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import { useFormFieldId, useFormError } from "../contexts.js";
|
|
6
|
+
import { dataAttribute } from "@contember/utilities";
|
|
7
|
+
import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
|
|
8
|
+
const SlotInput = Slot;
|
|
9
|
+
const FormRadioInput = Component(({ field, value, defaultValue, isNonbearing, ...props }) => {
|
|
10
|
+
const id = useFormFieldId();
|
|
11
|
+
const accessor = useField(field);
|
|
12
|
+
const errors = useFormError() ?? accessor.errors?.errors ?? [];
|
|
13
|
+
const accessorGetter = accessor.getAccessor;
|
|
14
|
+
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
SlotInput,
|
|
17
|
+
{
|
|
18
|
+
ref,
|
|
19
|
+
type: "radio",
|
|
20
|
+
value,
|
|
21
|
+
checked: accessor.value === value,
|
|
22
|
+
"data-invalid": dataAttribute(errors.length > 0),
|
|
23
|
+
name: id + "-input",
|
|
24
|
+
id: `${id}-input-${value}`,
|
|
25
|
+
onFocus,
|
|
26
|
+
onBlur,
|
|
27
|
+
onChange: useCallback((e) => {
|
|
28
|
+
accessorGetter().updateValue(value);
|
|
29
|
+
}, [accessorGetter, value]),
|
|
30
|
+
...props
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}, ({ field, isNonbearing, defaultValue }) => {
|
|
34
|
+
return /* @__PURE__ */ jsx(Field, { field, isNonbearing, defaultValue });
|
|
35
|
+
});
|
|
36
|
+
export {
|
|
37
|
+
FormRadioInput
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=FormRadioInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormRadioInput.js","sources":["../../../src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport * as React from 'react'\nimport { ChangeEventHandler, useCallback } from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { dataAttribute } from '@contember/utilities'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormRadioItemProps {\n\tfield: SugaredRelativeSingleField['field']\n\tvalue: string\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactNode\n}\n\nexport const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField<string>(field)\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\ttype=\"radio\"\n\t\t\tvalue={value}\n\t\t\tchecked={accessor.value === value}\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tname={id + '-input'}\n\t\t\tid={`${id}-input-${value}`}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(value)\n\t\t\t}, [accessorGetter, value])}\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;AACvH,QAAM,KAAK;AACL,QAAA,WAAW,SAAiB,KAAK;AACvC,QAAM,SAAS,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAI,8BAA8B,QAAQ;AAGtE,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,MAAK;AAAA,MACL;AAAA,MACA,SAAS,SAAS,UAAU;AAAA,MAC5B,gBAAc,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,MAAM,KAAK;AAAA,MACX,IAAI,GAAG,EAAE,UAAU,KAAK;AAAA,MACxB;AAAA,MACA;AAAA,MACA,UAAU,YAAkD,CAAK,MAAA;AACjD,uBAAA,EAAE,YAAY,KAAK;AAAA,MAAA,GAChC,CAAC,gBAAgB,KAAK,CAAC;AAAA,MACzB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,aAA4B,CAAA;AACrF,CAAC;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const reactUtils = require("@contember/react-utils");
|
|
4
|
+
const FormFieldIdContext_ = reactUtils.createContext("FormFieldIdContext", void 0);
|
|
5
|
+
const FormFieldIdContext = FormFieldIdContext_[0];
|
|
6
|
+
const useFormFieldId = FormFieldIdContext_[1];
|
|
7
|
+
const FormErrorContext_ = reactUtils.createContext("FormErrorContext", void 0);
|
|
8
|
+
const FormErrorContext = FormErrorContext_[0];
|
|
9
|
+
const useFormError = FormErrorContext_[1];
|
|
10
|
+
exports.FormErrorContext = FormErrorContext;
|
|
11
|
+
exports.FormFieldIdContext = FormFieldIdContext;
|
|
12
|
+
exports.useFormError = useFormError;
|
|
13
|
+
exports.useFormFieldId = useFormFieldId;
|
|
14
|
+
//# sourceMappingURL=contexts.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contexts.cjs","sources":["../../src/contexts.ts"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { ErrorAccessor } from '@contember/react-binding'\n\nconst FormFieldIdContext_ = createContext<string | undefined>('FormFieldIdContext', undefined)\n/** @internal */\nexport const FormFieldIdContext = FormFieldIdContext_[0]\nexport const useFormFieldId = FormFieldIdContext_[1]\n\nconst FormErrorContext_ = createContext<ErrorAccessor.Error[] | undefined>('FormErrorContext', undefined)\n/** @internal */\nexport const FormErrorContext = FormErrorContext_[0]\nexport const useFormError = FormErrorContext_[1]\n"],"names":["createContext"],"mappings":";;;AAGA,MAAM,sBAAsBA,WAAkC,cAAA,sBAAsB,MAAS;AAEhF,MAAA,qBAAqB,oBAAoB,CAAC;AAC1C,MAAA,iBAAiB,oBAAoB,CAAC;AAEnD,MAAM,oBAAoBA,WAAiD,cAAA,oBAAoB,MAAS;AAE3F,MAAA,mBAAmB,kBAAkB,CAAC;AACtC,MAAA,eAAe,kBAAkB,CAAC;;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createContext } from "@contember/react-utils";
|
|
2
|
+
const FormFieldIdContext_ = createContext("FormFieldIdContext", void 0);
|
|
3
|
+
const FormFieldIdContext = FormFieldIdContext_[0];
|
|
4
|
+
const useFormFieldId = FormFieldIdContext_[1];
|
|
5
|
+
const FormErrorContext_ = createContext("FormErrorContext", void 0);
|
|
6
|
+
const FormErrorContext = FormErrorContext_[0];
|
|
7
|
+
const useFormError = FormErrorContext_[1];
|
|
8
|
+
export {
|
|
9
|
+
FormErrorContext,
|
|
10
|
+
FormFieldIdContext,
|
|
11
|
+
useFormError,
|
|
12
|
+
useFormFieldId
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=contexts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contexts.js","sources":["../../src/contexts.ts"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { ErrorAccessor } from '@contember/react-binding'\n\nconst FormFieldIdContext_ = createContext<string | undefined>('FormFieldIdContext', undefined)\n/** @internal */\nexport const FormFieldIdContext = FormFieldIdContext_[0]\nexport const useFormFieldId = FormFieldIdContext_[1]\n\nconst FormErrorContext_ = createContext<ErrorAccessor.Error[] | undefined>('FormErrorContext', undefined)\n/** @internal */\nexport const FormErrorContext = FormErrorContext_[0]\nexport const useFormError = FormErrorContext_[1]\n"],"names":[],"mappings":";AAGA,MAAM,sBAAsB,cAAkC,sBAAsB,MAAS;AAEhF,MAAA,qBAAqB,oBAAoB,CAAC;AAC1C,MAAA,iBAAiB,oBAAoB,CAAC;AAEnD,MAAM,oBAAoB,cAAiD,oBAAoB,MAAS;AAE3F,MAAA,mBAAmB,kBAAkB,CAAC;AACtC,MAAA,eAAe,kBAAkB,CAAC;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
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();
|
|
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
|
+
if (message !== validationMessage.current) {
|
|
40
|
+
validationMessage.current = message;
|
|
41
|
+
if (!message || !focus) {
|
|
42
|
+
accessorGetter().clearErrors();
|
|
43
|
+
}
|
|
44
|
+
if (!focus && message) {
|
|
45
|
+
accessorGetter().addError(message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
ref: inputRef,
|
|
51
|
+
onFocus: React.useCallback(() => {
|
|
52
|
+
setFocus(true);
|
|
53
|
+
}, []),
|
|
54
|
+
onBlur: React.useCallback(() => {
|
|
55
|
+
setFocus(false);
|
|
56
|
+
accessorGetter().clearErrors();
|
|
57
|
+
if (validationMessage.current) {
|
|
58
|
+
accessorGetter().addError(validationMessage.current);
|
|
59
|
+
}
|
|
60
|
+
}, [accessorGetter])
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
exports.useFormInputValidationHandler = useFormInputValidationHandler;
|
|
64
|
+
//# sourceMappingURL=useFormInputValidationHandler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormInputValidationHandler.cjs","sources":["../../../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\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tif (message !== validationMessage.current) {\n\t\t\tvalidationMessage.current = message\n\t\t\tif (!message || !focus) {\n\t\t\t\taccessorGetter().clearErrors()\n\t\t\t}\n\t\t\tif (!focus && message) {\n\t\t\t\taccessorGetter().addError(message)\n\t\t\t}\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"],"names":["useRef","React","useEntityBeforePersist","useCallback","useEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIa,MAAA,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoBA,MAAAA;AAC1B,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,IACpD;AAAA,EAAA,GACE,CAAC,cAAc,CAAC,CAAC;AAEpBC,QAAAA,UAAU,MAAM;AACX,QAAA,CAAC,SAAS,SAAS;AACtB;AAAA,IACD;AACA,UAAM,QAAQ,SAAS;AACjB,UAAA,QAAQ,MAAM,UAAU;AACxB,UAAA,UAAU,QAAQ,SAAY,OAAO;AACvC,QAAA,YAAY,kBAAkB,SAAS;AAC1C,wBAAkB,UAAU;AACxB,UAAA,CAAC,WAAW,CAAC,OAAO;AACvB,uBAAA,EAAiB;MAClB;AACI,UAAA,CAAC,SAAS,SAAS;AACP,uBAAA,EAAE,SAAS,OAAO;AAAA,MAClC;AAAA,IACD;AAAA,EAAA,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;AACjB,UAAI,kBAAkB,SAAS;AACf,yBAAE,SAAS,kBAAkB,OAAO;AAAA,MACpD;AAAA,IAAA,GACE,CAAC,cAAc,CAAC;AAAA,EAAA;AAErB;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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();
|
|
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
|
+
if (message !== validationMessage.current) {
|
|
22
|
+
validationMessage.current = message;
|
|
23
|
+
if (!message || !focus) {
|
|
24
|
+
accessorGetter().clearErrors();
|
|
25
|
+
}
|
|
26
|
+
if (!focus && message) {
|
|
27
|
+
accessorGetter().addError(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
ref: inputRef,
|
|
33
|
+
onFocus: useCallback(() => {
|
|
34
|
+
setFocus(true);
|
|
35
|
+
}, []),
|
|
36
|
+
onBlur: useCallback(() => {
|
|
37
|
+
setFocus(false);
|
|
38
|
+
accessorGetter().clearErrors();
|
|
39
|
+
if (validationMessage.current) {
|
|
40
|
+
accessorGetter().addError(validationMessage.current);
|
|
41
|
+
}
|
|
42
|
+
}, [accessorGetter])
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
useFormInputValidationHandler
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=useFormInputValidationHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormInputValidationHandler.js","sources":["../../../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\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tif (message !== validationMessage.current) {\n\t\t\tvalidationMessage.current = message\n\t\t\tif (!message || !focus) {\n\t\t\t\taccessorGetter().clearErrors()\n\t\t\t}\n\t\t\tif (!focus && message) {\n\t\t\t\taccessorGetter().addError(message)\n\t\t\t}\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"],"names":[],"mappings":";;;AAIa,MAAA,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoB;AAC1B,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,IACpD;AAAA,EAAA,GACE,CAAC,cAAc,CAAC,CAAC;AAEpB,YAAU,MAAM;AACX,QAAA,CAAC,SAAS,SAAS;AACtB;AAAA,IACD;AACA,UAAM,QAAQ,SAAS;AACjB,UAAA,QAAQ,MAAM,UAAU;AACxB,UAAA,UAAU,QAAQ,SAAY,OAAO;AACvC,QAAA,YAAY,kBAAkB,SAAS;AAC1C,wBAAkB,UAAU;AACxB,UAAA,CAAC,WAAW,CAAC,OAAO;AACvB,uBAAA,EAAiB;MAClB;AACI,UAAA,CAAC,SAAS,SAAS;AACP,uBAAA,EAAE,SAAS,OAAO;AAAA,MAClC;AAAA,IACD;AAAA,EAAA,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;AACjB,UAAI,kBAAkB,SAAS;AACf,yBAAE,SAAS,kBAAkB,OAAO;AAAA,MACpD;AAAA,IAAA,GACE,CAAC,cAAc,CAAC;AAAA,EAAA;AAErB;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const contexts = require("./contexts.cjs");
|
|
4
|
+
const FormError = require("./components/FormError.cjs");
|
|
5
|
+
const FormCheckbox = require("./components/FormCheckbox.cjs");
|
|
6
|
+
const FormFieldScope = require("./components/FormFieldScope.cjs");
|
|
7
|
+
const FormHasOneRelationScope = require("./components/FormHasOneRelationScope.cjs");
|
|
8
|
+
const FormHasManyRelationScope = require("./components/FormHasManyRelationScope.cjs");
|
|
9
|
+
const FormInput = require("./components/FormInput.cjs");
|
|
10
|
+
const FormLabel = require("./components/FormLabel.cjs");
|
|
11
|
+
const FormRadioInput = require("./components/FormRadioInput.cjs");
|
|
12
|
+
const useFormInputValidationHandler = require("./hooks/useFormInputValidationHandler.cjs");
|
|
13
|
+
exports.FormErrorContext = contexts.FormErrorContext;
|
|
14
|
+
exports.FormFieldIdContext = contexts.FormFieldIdContext;
|
|
15
|
+
exports.useFormError = contexts.useFormError;
|
|
16
|
+
exports.useFormFieldId = contexts.useFormFieldId;
|
|
17
|
+
exports.FormError = FormError.FormError;
|
|
18
|
+
exports.FormCheckbox = FormCheckbox.FormCheckbox;
|
|
19
|
+
exports.FormFieldScope = FormFieldScope.FormFieldScope;
|
|
20
|
+
exports.FormHasOneRelationScope = FormHasOneRelationScope.FormHasOneRelationScope;
|
|
21
|
+
exports.FormHasManyRelationScope = FormHasManyRelationScope.FormHasManyRelationScope;
|
|
22
|
+
exports.FormInput = FormInput.FormInput;
|
|
23
|
+
exports.FormLabel = FormLabel.FormLabel;
|
|
24
|
+
exports.FormRadioInput = FormRadioInput.FormRadioInput;
|
|
25
|
+
exports.useFormInputValidationHandler = useFormInputValidationHandler.useFormInputValidationHandler;
|
|
26
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FormErrorContext, FormFieldIdContext, useFormError, useFormFieldId } from "./contexts.js";
|
|
2
|
+
import { FormError } from "./components/FormError.js";
|
|
3
|
+
import { FormCheckbox } from "./components/FormCheckbox.js";
|
|
4
|
+
import { FormFieldScope } from "./components/FormFieldScope.js";
|
|
5
|
+
import { FormHasOneRelationScope } from "./components/FormHasOneRelationScope.js";
|
|
6
|
+
import { FormHasManyRelationScope } from "./components/FormHasManyRelationScope.js";
|
|
7
|
+
import { FormInput } from "./components/FormInput.js";
|
|
8
|
+
import { FormLabel } from "./components/FormLabel.js";
|
|
9
|
+
import { FormRadioInput } from "./components/FormRadioInput.js";
|
|
10
|
+
import { useFormInputValidationHandler } from "./hooks/useFormInputValidationHandler.js";
|
|
11
|
+
export {
|
|
12
|
+
FormCheckbox,
|
|
13
|
+
FormError,
|
|
14
|
+
FormErrorContext,
|
|
15
|
+
FormFieldIdContext,
|
|
16
|
+
FormFieldScope,
|
|
17
|
+
FormHasManyRelationScope,
|
|
18
|
+
FormHasOneRelationScope,
|
|
19
|
+
FormInput,
|
|
20
|
+
FormLabel,
|
|
21
|
+
FormRadioInput,
|
|
22
|
+
useFormError,
|
|
23
|
+
useFormFieldId,
|
|
24
|
+
useFormInputValidationHandler
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|