@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,68 @@
|
|
|
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 reactBinding = require("@contember/react-binding");
|
|
6
|
+
const contexts = require("../contexts.cjs");
|
|
7
|
+
const utilities = require("@contember/utilities");
|
|
8
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
9
|
+
const useFormInputValidationHandler = require("../hooks/useFormInputValidationHandler.cjs");
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
12
|
+
if (e) {
|
|
13
|
+
for (const k in e) {
|
|
14
|
+
if (k !== "default") {
|
|
15
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: () => e[k]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
27
|
+
const SlotInput = reactSlot.Slot;
|
|
28
|
+
const FormCheckbox = reactBinding.Component(({ field, isNonbearing, defaultValue, ...props }) => {
|
|
29
|
+
const id = contexts.useFormFieldId();
|
|
30
|
+
const accessor = reactBinding.useField(field);
|
|
31
|
+
const value = accessor.value;
|
|
32
|
+
const errors = contexts.useFormError() ?? accessor.errors?.errors ?? [];
|
|
33
|
+
const accessorGetter = accessor.getAccessor;
|
|
34
|
+
const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
|
|
35
|
+
const [checkboxRef, setCheckboxRef] = React__namespace.useState(null);
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
if (!checkboxRef) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
ref.current = checkboxRef;
|
|
41
|
+
if (value === null) {
|
|
42
|
+
checkboxRef.indeterminate = true;
|
|
43
|
+
}
|
|
44
|
+
}, [checkboxRef, ref, value]);
|
|
45
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
46
|
+
SlotInput,
|
|
47
|
+
{
|
|
48
|
+
ref: setCheckboxRef,
|
|
49
|
+
type: "checkbox",
|
|
50
|
+
checked: accessor.value === true,
|
|
51
|
+
"data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
|
|
52
|
+
"data-invalid": utilities.dataAttribute(errors.length > 0),
|
|
53
|
+
id: `${id}-input`,
|
|
54
|
+
onFocus,
|
|
55
|
+
onBlur,
|
|
56
|
+
onChange: React.useCallback((e) => {
|
|
57
|
+
accessorGetter().updateValue(e.target.checked);
|
|
58
|
+
}, [accessorGetter]),
|
|
59
|
+
...props
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}, ({ field, isNonbearing, defaultValue }, env) => {
|
|
63
|
+
const node = reactBinding.TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
|
|
64
|
+
const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
|
|
65
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { field, isNonbearing, defaultValue: resolvedDefaultValue });
|
|
66
|
+
});
|
|
67
|
+
exports.FormCheckbox = FormCheckbox;
|
|
68
|
+
//# sourceMappingURL=FormCheckbox.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormCheckbox.cjs","sources":["../../../src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, TreeNodeEnvironmentFactory, useField } from '@contember/react-binding'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { Slot } from '@radix-ui/react-slot'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormCheckboxProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: ReactElement<HTMLInputElement, 'input'>\n}\n\nexport const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField<boolean>(field)\n\tconst value = accessor.value\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\tconst [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)\n\n\tuseEffect(() => {\n\t\tif (!checkboxRef) {\n\t\t\treturn\n\t\t}\n\t\t(ref as any).current = checkboxRef\n\t\tif (value === null) {\n\t\t\tcheckboxRef.indeterminate = true\n\t\t}\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t\t<SlotInput\n\t\t\t\tref={setCheckboxRef}\n\t\t\t\ttype=\"checkbox\"\n\t\t\t\tchecked={accessor.value === true}\n\t\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\t\tid={`${id}-input`}\n\t\t\t\tonFocus={onFocus}\n\t\t\t\tonBlur={onBlur}\n\t\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t\t}, [accessorGetter])}\n\t\t\t\t{...props}\n\t\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }, env) => {\n\tconst node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode()\n\tconst resolvedDefaultValue = defaultValue !== undefined ? defaultValue : (node.field.defaultValue ?? (node.field.nullable ? null : false))\n\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={resolvedDefaultValue} />\n})\n"],"names":["Slot","Component","useFormFieldId","useField","useFormError","useFormInputValidationHandler","React","useEffect","jsx","dataAttribute","useCallback","TreeNodeEnvironmentFactory","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,YAAYA,UAAAA;AASL,MAAA,eAAeC,uBAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AAC7G,QAAM,KAAKC,SAAAA;AACL,QAAA,WAAWC,sBAAkB,KAAK;AACxC,QAAM,QAAQ,SAAS;AACvB,QAAM,SAASC,SAAAA,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAIC,8BAAAA,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAIC,iBAAM,SAAkC,IAAI;AAElFC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACC,QAAY,UAAU;AACvB,QAAI,UAAU,MAAM;AACnB,kBAAY,gBAAgB;AAAA,IAC7B;AAAA,EACE,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG1B,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK;AAAA,MACL,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAcC,UAAA,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,IAAI,GAAG,EAAE;AAAA,MACT;AAAA,MACA;AAAA,MACA,UAAUC,MAAAA,YAAkD,CAAK,MAAA;AAChE,uBAAiB,EAAA,YAAY,EAAE,OAAO,OAAO;AAAA,MAAA,GAC3C,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGR,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAOC,wCAA2B,0BAA0B,KAAK,EAAE,MAAO,CAAA,EAAE;AAC5E,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQH,2BAAAA,IAAAI,aAAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,qBAAsB,CAAA;AAC7F,CAAC;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useEffect, useCallback } from "react";
|
|
4
|
+
import { Component, useField, TreeNodeEnvironmentFactory, Field } from "@contember/react-binding";
|
|
5
|
+
import { useFormFieldId, useFormError } from "../contexts.js";
|
|
6
|
+
import { dataAttribute } from "@contember/utilities";
|
|
7
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
8
|
+
import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
|
|
9
|
+
const SlotInput = Slot;
|
|
10
|
+
const FormCheckbox = Component(({ field, isNonbearing, defaultValue, ...props }) => {
|
|
11
|
+
const id = useFormFieldId();
|
|
12
|
+
const accessor = useField(field);
|
|
13
|
+
const value = accessor.value;
|
|
14
|
+
const errors = useFormError() ?? accessor.errors?.errors ?? [];
|
|
15
|
+
const accessorGetter = accessor.getAccessor;
|
|
16
|
+
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
|
|
17
|
+
const [checkboxRef, setCheckboxRef] = React.useState(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!checkboxRef) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
ref.current = checkboxRef;
|
|
23
|
+
if (value === null) {
|
|
24
|
+
checkboxRef.indeterminate = true;
|
|
25
|
+
}
|
|
26
|
+
}, [checkboxRef, ref, value]);
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
SlotInput,
|
|
29
|
+
{
|
|
30
|
+
ref: setCheckboxRef,
|
|
31
|
+
type: "checkbox",
|
|
32
|
+
checked: accessor.value === true,
|
|
33
|
+
"data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
|
|
34
|
+
"data-invalid": dataAttribute(errors.length > 0),
|
|
35
|
+
id: `${id}-input`,
|
|
36
|
+
onFocus,
|
|
37
|
+
onBlur,
|
|
38
|
+
onChange: useCallback((e) => {
|
|
39
|
+
accessorGetter().updateValue(e.target.checked);
|
|
40
|
+
}, [accessorGetter]),
|
|
41
|
+
...props
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
}, ({ field, isNonbearing, defaultValue }, env) => {
|
|
45
|
+
const node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
|
|
46
|
+
const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
|
|
47
|
+
return /* @__PURE__ */ jsx(Field, { field, isNonbearing, defaultValue: resolvedDefaultValue });
|
|
48
|
+
});
|
|
49
|
+
export {
|
|
50
|
+
FormCheckbox
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=FormCheckbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormCheckbox.js","sources":["../../../src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, TreeNodeEnvironmentFactory, useField } from '@contember/react-binding'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { Slot } from '@radix-ui/react-slot'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormCheckboxProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: ReactElement<HTMLInputElement, 'input'>\n}\n\nexport const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField<boolean>(field)\n\tconst value = accessor.value\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\tconst [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)\n\n\tuseEffect(() => {\n\t\tif (!checkboxRef) {\n\t\t\treturn\n\t\t}\n\t\t(ref as any).current = checkboxRef\n\t\tif (value === null) {\n\t\t\tcheckboxRef.indeterminate = true\n\t\t}\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t\t<SlotInput\n\t\t\t\tref={setCheckboxRef}\n\t\t\t\ttype=\"checkbox\"\n\t\t\t\tchecked={accessor.value === true}\n\t\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\t\tid={`${id}-input`}\n\t\t\t\tonFocus={onFocus}\n\t\t\t\tonBlur={onBlur}\n\t\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t\t}, [accessorGetter])}\n\t\t\t\t{...props}\n\t\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }, env) => {\n\tconst node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode()\n\tconst resolvedDefaultValue = defaultValue !== undefined ? defaultValue : (node.field.defaultValue ?? (node.field.nullable ? null : false))\n\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={resolvedDefaultValue} />\n})\n"],"names":[],"mappings":";;;;;;;;AAQA,MAAM,YAAY;AASL,MAAA,eAAe,UAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AAC7G,QAAM,KAAK;AACL,QAAA,WAAW,SAAkB,KAAK;AACxC,QAAM,QAAQ,SAAS;AACvB,QAAM,SAAS,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAI,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAAkC,IAAI;AAElF,YAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACC,QAAY,UAAU;AACvB,QAAI,UAAU,MAAM;AACnB,kBAAY,gBAAgB;AAAA,IAC7B;AAAA,EACE,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG1B,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK;AAAA,MACL,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAc,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,IAAI,GAAG,EAAE;AAAA,MACT;AAAA,MACA;AAAA,MACA,UAAU,YAAkD,CAAK,MAAA;AAChE,uBAAiB,EAAA,YAAY,EAAE,OAAO,OAAO;AAAA,MAAA,GAC3C,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGR,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAO,2BAA2B,0BAA0B,KAAK,EAAE,MAAO,CAAA,EAAE;AAC5E,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,qBAAsB,CAAA;AAC7F,CAAC;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const contexts = require("../contexts.cjs");
|
|
5
|
+
const reactBinding = require("@contember/react-binding");
|
|
6
|
+
const FormError = ({ children, formatter }) => {
|
|
7
|
+
const errors = contexts.useFormError();
|
|
8
|
+
const id = contexts.useFormFieldId();
|
|
9
|
+
const formatted = React.useMemo(() => formatter(errors ?? []), [errors, formatter]);
|
|
10
|
+
if (errors === void 0 || id === void 0) {
|
|
11
|
+
throw new reactBinding.BindingError("FormError must be used inside a FormField");
|
|
12
|
+
}
|
|
13
|
+
return formatted.map((it, index) => {
|
|
14
|
+
return React.cloneElement(children, {
|
|
15
|
+
key: index,
|
|
16
|
+
...{ id: `${id}-error-${index}` },
|
|
17
|
+
children: it
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.FormError = FormError;
|
|
22
|
+
//# sourceMappingURL=FormError.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormError.cjs","sources":["../../../src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { BindingError, ErrorAccessor } from '@contember/react-binding'\n\nexport const FormError = ({ children, formatter }: {\n\tformatter: (errors: ErrorAccessor.Error[]) => ReactNode[]\n\tchildren: ReactElement\n}) => {\n\tconst errors = useFormError()\n\tconst id = useFormFieldId()\n\tconst formatted = useMemo(() => formatter(errors ?? []), [errors, formatter])\n\tif (errors === undefined || id === undefined) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...{ id: `${id}-error-${index}` },\n\t\t\tchildren: it,\n\t\t})\n\t})\n}\n"],"names":["useFormError","useFormFieldId","useMemo","BindingError","cloneElement"],"mappings":";;;;;AAIO,MAAM,YAAY,CAAC,EAAE,UAAU,gBAGhC;AACL,QAAM,SAASA,SAAAA;AACf,QAAM,KAAKC,SAAAA;AACL,QAAA,YAAYC,cAAQ,MAAM,UAAU,UAAU,CAAE,CAAA,GAAG,CAAC,QAAQ,SAAS,CAAC;AACxE,MAAA,WAAW,UAAa,OAAO,QAAW;AACvC,UAAA,IAAIC,aAAAA,aAAa,2CAA2C;AAAA,EACnE;AACA,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAOC,MAAAA,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAG,EAAE,IAAI,GAAG,EAAE,UAAU,KAAK,GAAG;AAAA,MAChC,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useMemo, cloneElement } from "react";
|
|
2
|
+
import { useFormError, useFormFieldId } from "../contexts.js";
|
|
3
|
+
import { BindingError } from "@contember/react-binding";
|
|
4
|
+
const FormError = ({ children, formatter }) => {
|
|
5
|
+
const errors = useFormError();
|
|
6
|
+
const id = useFormFieldId();
|
|
7
|
+
const formatted = useMemo(() => formatter(errors ?? []), [errors, formatter]);
|
|
8
|
+
if (errors === void 0 || id === void 0) {
|
|
9
|
+
throw new BindingError("FormError must be used inside a FormField");
|
|
10
|
+
}
|
|
11
|
+
return formatted.map((it, index) => {
|
|
12
|
+
return cloneElement(children, {
|
|
13
|
+
key: index,
|
|
14
|
+
...{ id: `${id}-error-${index}` },
|
|
15
|
+
children: it
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
FormError
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=FormError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormError.js","sources":["../../../src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { BindingError, ErrorAccessor } from '@contember/react-binding'\n\nexport const FormError = ({ children, formatter }: {\n\tformatter: (errors: ErrorAccessor.Error[]) => ReactNode[]\n\tchildren: ReactElement\n}) => {\n\tconst errors = useFormError()\n\tconst id = useFormFieldId()\n\tconst formatted = useMemo(() => formatter(errors ?? []), [errors, formatter])\n\tif (errors === undefined || id === undefined) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...{ id: `${id}-error-${index}` },\n\t\t\tchildren: it,\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,YAAY,CAAC,EAAE,UAAU,gBAGhC;AACL,QAAM,SAAS;AACf,QAAM,KAAK;AACL,QAAA,YAAY,QAAQ,MAAM,UAAU,UAAU,CAAE,CAAA,GAAG,CAAC,QAAQ,SAAS,CAAC;AACxE,MAAA,WAAW,UAAa,OAAO,QAAW;AACvC,UAAA,IAAI,aAAa,2CAA2C;AAAA,EACnE;AACA,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAO,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAG,EAAE,IAAI,GAAG,EAAE,UAAU,KAAK,GAAG;AAAA,MAChC,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;"}
|
|
@@ -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;;;;;"}
|