@contember/react-form 2.1.0-alpha.3 → 2.1.0-alpha.35
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/package.json +10 -10
- package/src/components/FormCheckbox.tsx +2 -1
- package/src/components/FormError.tsx +1 -1
- package/src/components/FormFieldStateProvider.tsx +0 -2
- package/src/components/FormInput.tsx +35 -32
- package/src/components/FormRadioInput.tsx +1 -1
- package/src/contexts.tsx +0 -2
- package/src/hooks/useFormInputValidationHandler.tsx +1 -1
- package/src/internal/useFormInputHandler.ts +6 -6
- package/dist/development/index.cjs +0 -30
- package/dist/development/index.cjs.map +0 -1
- package/dist/development/index.js +0 -30
- package/dist/development/index.js.map +0 -1
- package/dist/development/src/components/FormCheckbox.cjs +0 -83
- package/dist/development/src/components/FormCheckbox.cjs.map +0 -1
- package/dist/development/src/components/FormCheckbox.js +0 -67
- package/dist/development/src/components/FormCheckbox.js.map +0 -1
- package/dist/development/src/components/FormError.cjs +0 -22
- package/dist/development/src/components/FormError.cjs.map +0 -1
- package/dist/development/src/components/FormError.js +0 -22
- package/dist/development/src/components/FormError.js.map +0 -1
- package/dist/development/src/components/FormFieldScope.cjs +0 -33
- package/dist/development/src/components/FormFieldScope.cjs.map +0 -1
- package/dist/development/src/components/FormFieldScope.js +0 -33
- package/dist/development/src/components/FormFieldScope.js.map +0 -1
- package/dist/development/src/components/FormFieldStateProvider.cjs +0 -56
- package/dist/development/src/components/FormFieldStateProvider.cjs.map +0 -1
- package/dist/development/src/components/FormFieldStateProvider.js +0 -56
- package/dist/development/src/components/FormFieldStateProvider.js.map +0 -1
- package/dist/development/src/components/FormHasManyRelationScope.cjs +0 -33
- package/dist/development/src/components/FormHasManyRelationScope.cjs.map +0 -1
- package/dist/development/src/components/FormHasManyRelationScope.js +0 -33
- package/dist/development/src/components/FormHasManyRelationScope.js.map +0 -1
- package/dist/development/src/components/FormHasOneRelationScope.cjs +0 -33
- package/dist/development/src/components/FormHasOneRelationScope.cjs.map +0 -1
- package/dist/development/src/components/FormHasOneRelationScope.js +0 -33
- package/dist/development/src/components/FormHasOneRelationScope.js.map +0 -1
- package/dist/development/src/components/FormInput.cjs +0 -59
- package/dist/development/src/components/FormInput.cjs.map +0 -1
- package/dist/development/src/components/FormInput.js +0 -59
- package/dist/development/src/components/FormInput.js.map +0 -1
- package/dist/development/src/components/FormLabel.cjs +0 -34
- package/dist/development/src/components/FormLabel.cjs.map +0 -1
- package/dist/development/src/components/FormLabel.js +0 -34
- package/dist/development/src/components/FormLabel.js.map +0 -1
- package/dist/development/src/components/FormRadioInput.cjs +0 -55
- package/dist/development/src/components/FormRadioInput.cjs.map +0 -1
- package/dist/development/src/components/FormRadioInput.js +0 -55
- package/dist/development/src/components/FormRadioInput.js.map +0 -1
- package/dist/development/src/contexts.cjs +0 -13
- package/dist/development/src/contexts.cjs.map +0 -1
- package/dist/development/src/contexts.js +0 -13
- package/dist/development/src/contexts.js.map +0 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs +0 -80
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs.map +0 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.js +0 -64
- package/dist/development/src/hooks/useFormInputValidationHandler.js.map +0 -1
- package/dist/development/src/internal/useFormInputHandler.cjs +0 -122
- package/dist/development/src/internal/useFormInputHandler.cjs.map +0 -1
- package/dist/development/src/internal/useFormInputHandler.js +0 -122
- package/dist/development/src/internal/useFormInputHandler.js.map +0 -1
- package/dist/production/index.cjs +0 -30
- package/dist/production/index.cjs.map +0 -1
- package/dist/production/index.js +0 -30
- package/dist/production/index.js.map +0 -1
- package/dist/production/src/components/FormCheckbox.cjs +0 -71
- package/dist/production/src/components/FormCheckbox.cjs.map +0 -1
- package/dist/production/src/components/FormCheckbox.js +0 -55
- package/dist/production/src/components/FormCheckbox.js.map +0 -1
- package/dist/production/src/components/FormError.cjs +0 -22
- package/dist/production/src/components/FormError.cjs.map +0 -1
- package/dist/production/src/components/FormError.js +0 -22
- package/dist/production/src/components/FormError.js.map +0 -1
- package/dist/production/src/components/FormFieldScope.cjs +0 -25
- package/dist/production/src/components/FormFieldScope.cjs.map +0 -1
- package/dist/production/src/components/FormFieldScope.js +0 -25
- package/dist/production/src/components/FormFieldScope.js.map +0 -1
- package/dist/production/src/components/FormFieldStateProvider.cjs +0 -34
- package/dist/production/src/components/FormFieldStateProvider.cjs.map +0 -1
- package/dist/production/src/components/FormFieldStateProvider.js +0 -34
- package/dist/production/src/components/FormFieldStateProvider.js.map +0 -1
- package/dist/production/src/components/FormHasManyRelationScope.cjs +0 -25
- package/dist/production/src/components/FormHasManyRelationScope.cjs.map +0 -1
- package/dist/production/src/components/FormHasManyRelationScope.js +0 -25
- package/dist/production/src/components/FormHasManyRelationScope.js.map +0 -1
- package/dist/production/src/components/FormHasOneRelationScope.cjs +0 -25
- package/dist/production/src/components/FormHasOneRelationScope.cjs.map +0 -1
- package/dist/production/src/components/FormHasOneRelationScope.js +0 -25
- package/dist/production/src/components/FormHasOneRelationScope.js.map +0 -1
- package/dist/production/src/components/FormInput.cjs +0 -47
- package/dist/production/src/components/FormInput.cjs.map +0 -1
- package/dist/production/src/components/FormInput.js +0 -47
- package/dist/production/src/components/FormInput.js.map +0 -1
- package/dist/production/src/components/FormLabel.cjs +0 -26
- package/dist/production/src/components/FormLabel.cjs.map +0 -1
- package/dist/production/src/components/FormLabel.js +0 -26
- package/dist/production/src/components/FormLabel.js.map +0 -1
- package/dist/production/src/components/FormRadioInput.cjs +0 -43
- package/dist/production/src/components/FormRadioInput.cjs.map +0 -1
- package/dist/production/src/components/FormRadioInput.js +0 -43
- package/dist/production/src/components/FormRadioInput.js.map +0 -1
- package/dist/production/src/contexts.cjs +0 -13
- package/dist/production/src/contexts.cjs.map +0 -1
- package/dist/production/src/contexts.js +0 -13
- package/dist/production/src/contexts.js.map +0 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs +0 -80
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs.map +0 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.js +0 -64
- package/dist/production/src/hooks/useFormInputValidationHandler.js.map +0 -1
- package/dist/production/src/internal/useFormInputHandler.cjs +0 -122
- package/dist/production/src/internal/useFormInputHandler.cjs.map +0 -1
- package/dist/production/src/internal/useFormInputHandler.js +0 -122
- package/dist/production/src/internal/useFormInputHandler.js.map +0 -1
- package/dist/types/components/FormCheckbox.d.ts +0 -11
- package/dist/types/components/FormCheckbox.d.ts.map +0 -1
- package/dist/types/components/FormError.d.ts +0 -7
- package/dist/types/components/FormError.d.ts.map +0 -1
- package/dist/types/components/FormFieldScope.d.ts +0 -9
- package/dist/types/components/FormFieldScope.d.ts.map +0 -1
- package/dist/types/components/FormFieldStateProvider.d.ts +0 -36
- package/dist/types/components/FormFieldStateProvider.d.ts.map +0 -1
- package/dist/types/components/FormHasManyRelationScope.d.ts +0 -12
- package/dist/types/components/FormHasManyRelationScope.d.ts.map +0 -1
- package/dist/types/components/FormHasOneRelationScope.d.ts +0 -9
- package/dist/types/components/FormHasOneRelationScope.d.ts.map +0 -1
- package/dist/types/components/FormInput.d.ts +0 -13
- package/dist/types/components/FormInput.d.ts.map +0 -1
- package/dist/types/components/FormLabel.d.ts +0 -5
- package/dist/types/components/FormLabel.d.ts.map +0 -1
- package/dist/types/components/FormRadioInput.d.ts +0 -11
- package/dist/types/components/FormRadioInput.d.ts.map +0 -1
- package/dist/types/components/index.d.ts +0 -10
- package/dist/types/components/index.d.ts.map +0 -1
- package/dist/types/contexts.d.ts +0 -12
- package/dist/types/contexts.d.ts.map +0 -1
- package/dist/types/hooks/index.d.ts +0 -2
- package/dist/types/hooks/index.d.ts.map +0 -1
- package/dist/types/hooks/useFormInputValidationHandler.d.ts +0 -8
- package/dist/types/hooks/useFormInputValidationHandler.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/internal/useFormInputHandler.d.ts +0 -4
- package/dist/types/internal/useFormInputHandler.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/dist/types/types/index.d.ts +0 -23
- package/dist/types/types/index.d.ts.map +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
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 accessor = reactBinding.useField(field);
|
|
30
|
-
const formState = contexts.useFormFieldState();
|
|
31
|
-
const id = formState?.htmlId;
|
|
32
|
-
const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
|
|
33
|
-
const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
|
|
34
|
-
const value = accessor.value;
|
|
35
|
-
const accessorGetter = accessor.getAccessor;
|
|
36
|
-
const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
|
|
37
|
-
const [checkboxRef, setCheckboxRef] = React__namespace.useState(null);
|
|
38
|
-
React.useEffect(() => {
|
|
39
|
-
if (!checkboxRef) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
checkboxRef.indeterminate = value === null;
|
|
43
|
-
}, [checkboxRef, ref, value]);
|
|
44
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
45
|
-
SlotInput,
|
|
46
|
-
{
|
|
47
|
-
ref: (it) => {
|
|
48
|
-
ref.current = checkboxRef;
|
|
49
|
-
setCheckboxRef(it);
|
|
50
|
-
},
|
|
51
|
-
type: "checkbox",
|
|
52
|
-
checked: accessor.value === true,
|
|
53
|
-
"data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
|
|
54
|
-
"data-invalid": utilities.dataAttribute(hasErrors),
|
|
55
|
-
"data-dirty": utilities.dataAttribute(dirty),
|
|
56
|
-
id: id ? `${id}-input` : void 0,
|
|
57
|
-
onFocus,
|
|
58
|
-
onBlur,
|
|
59
|
-
onChange: React.useCallback((e) => {
|
|
60
|
-
accessorGetter().updateValue(e.target.checked);
|
|
61
|
-
}, [accessorGetter]),
|
|
62
|
-
...props
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
}, ({ field, isNonbearing, defaultValue }, env) => {
|
|
66
|
-
const node = reactBinding.TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
|
|
67
|
-
const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
|
|
68
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { field, isNonbearing, defaultValue: resolvedDefaultValue });
|
|
69
|
-
});
|
|
70
|
-
exports.FormCheckbox = FormCheckbox;
|
|
71
|
-
//# sourceMappingURL=FormCheckbox.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormCheckbox.cjs","sources":["../../../../../packages/react-form/src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport {\n\tComponent,\n\tField,\n\tOptionallyVariableFieldValue,\n\tSugaredRelativeSingleField,\n\tTreeNodeEnvironmentFactory,\n\tuseField,\n} from '@contember/react-binding'\nimport { useFormFieldState } 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 accessor = useField<boolean>(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\tconst value = accessor.value\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\tcheckboxRef.indeterminate = value === null\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={it => {\n\t\t\t\t(ref as any).current = checkboxRef\n\t\t\t\tsetCheckboxRef(it)\n\t\t\t}}\n\t\t\ttype=\"checkbox\"\n\t\t\tchecked={accessor.value === true}\n\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t}, [accessorGetter])}\n\t\t\t{...props}\n\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","useField","useFormFieldState","useFormInputValidationHandler","React","useEffect","jsx","dataAttribute","useCallback","TreeNodeEnvironmentFactory","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,YAAYA,UAAA;AASL,MAAA,eAAeC,uBAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAA,WAAWC,sBAAkB,KAAK;AAExC,QAAM,YAAYC,SAAAA,kBAAkB;AACpC,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,QAAQ,SAAS;AACvB,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,IAAA;AAED,gBAAY,gBAAgB,UAAU;AAAA,EACpC,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG3B,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK,CAAM,OAAA;AACT,YAAY,UAAU;AACvB,uBAAe,EAAE;AAAA,MAClB;AAAA,MACA,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAcC,wBAAc,SAAS;AAAA,MACrC,cAAYA,wBAAc,KAAK;AAAA,MAC/B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;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,EACL;AAEF,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAOC,aAAAA,2BAA2B,0BAA0B,KAAK,EAAE,MAAM,CAAC,EAAE,eAAe;AAC3F,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQH,2BAAAA,IAAAI,aAAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,sBAAsB;AAC7F,CAAC;;"}
|
|
@@ -1,55 +0,0 @@
|
|
|
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 { useFormFieldState } 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 accessor = useField(field);
|
|
12
|
-
const formState = useFormFieldState();
|
|
13
|
-
const id = formState?.htmlId;
|
|
14
|
-
const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
|
|
15
|
-
const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
|
|
16
|
-
const value = accessor.value;
|
|
17
|
-
const accessorGetter = accessor.getAccessor;
|
|
18
|
-
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
|
|
19
|
-
const [checkboxRef, setCheckboxRef] = React.useState(null);
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (!checkboxRef) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
checkboxRef.indeterminate = value === null;
|
|
25
|
-
}, [checkboxRef, ref, value]);
|
|
26
|
-
return /* @__PURE__ */ jsx(
|
|
27
|
-
SlotInput,
|
|
28
|
-
{
|
|
29
|
-
ref: (it) => {
|
|
30
|
-
ref.current = checkboxRef;
|
|
31
|
-
setCheckboxRef(it);
|
|
32
|
-
},
|
|
33
|
-
type: "checkbox",
|
|
34
|
-
checked: accessor.value === true,
|
|
35
|
-
"data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
|
|
36
|
-
"data-invalid": dataAttribute(hasErrors),
|
|
37
|
-
"data-dirty": dataAttribute(dirty),
|
|
38
|
-
id: id ? `${id}-input` : void 0,
|
|
39
|
-
onFocus,
|
|
40
|
-
onBlur,
|
|
41
|
-
onChange: useCallback((e) => {
|
|
42
|
-
accessorGetter().updateValue(e.target.checked);
|
|
43
|
-
}, [accessorGetter]),
|
|
44
|
-
...props
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
}, ({ field, isNonbearing, defaultValue }, env) => {
|
|
48
|
-
const node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
|
|
49
|
-
const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
|
|
50
|
-
return /* @__PURE__ */ jsx(Field, { field, isNonbearing, defaultValue: resolvedDefaultValue });
|
|
51
|
-
});
|
|
52
|
-
export {
|
|
53
|
-
FormCheckbox
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=FormCheckbox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormCheckbox.js","sources":["../../../../../packages/react-form/src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport {\n\tComponent,\n\tField,\n\tOptionallyVariableFieldValue,\n\tSugaredRelativeSingleField,\n\tTreeNodeEnvironmentFactory,\n\tuseField,\n} from '@contember/react-binding'\nimport { useFormFieldState } 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 accessor = useField<boolean>(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\tconst value = accessor.value\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\tcheckboxRef.indeterminate = value === null\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={it => {\n\t\t\t\t(ref as any).current = checkboxRef\n\t\t\t\tsetCheckboxRef(it)\n\t\t\t}}\n\t\t\ttype=\"checkbox\"\n\t\t\tchecked={accessor.value === true}\n\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t}, [accessorGetter])}\n\t\t\t{...props}\n\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":";;;;;;;;AAeA,MAAM,YAAY;AASL,MAAA,eAAe,UAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAA,WAAW,SAAkB,KAAK;AAExC,QAAM,YAAY,kBAAkB;AACpC,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,QAAQ,SAAS;AACvB,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,IAAA;AAED,gBAAY,gBAAgB,UAAU;AAAA,EACpC,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG3B,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK,CAAM,OAAA;AACT,YAAY,UAAU;AACvB,uBAAe,EAAE;AAAA,MAClB;AAAA,MACA,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAc,cAAc,SAAS;AAAA,MACrC,cAAY,cAAc,KAAK;AAAA,MAC/B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;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,EACL;AAEF,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAO,2BAA2B,0BAA0B,KAAK,EAAE,MAAM,CAAC,EAAE,eAAe;AAC3F,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,sBAAsB;AAC7F,CAAC;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
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 formState = contexts.useFormFieldState();
|
|
8
|
-
if (!formState) {
|
|
9
|
-
throw new reactBinding.BindingError("FormError must be used inside a FormField");
|
|
10
|
-
}
|
|
11
|
-
const { errors, htmlId } = formState;
|
|
12
|
-
const formatted = React.useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter]);
|
|
13
|
-
return formatted.map((it, index) => {
|
|
14
|
-
return React.cloneElement(children, {
|
|
15
|
-
key: index,
|
|
16
|
-
...htmlId ? { id: `${htmlId}-error-${index}` } : {},
|
|
17
|
-
children: it
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
exports.FormError = FormError;
|
|
22
|
-
//# sourceMappingURL=FormError.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormError.cjs","sources":["../../../../../packages/react-form/src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormFieldState } 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 formState = useFormFieldState()\n\tif (!formState) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\tconst { errors, htmlId } = formState\n\tconst formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter])\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...(htmlId ? { id: `${htmlId}-error-${index}` } : {}),\n\t\t\tchildren: it,\n\t\t})\n\t})\n}\n"],"names":["useFormFieldState","BindingError","useMemo","cloneElement"],"mappings":";;;;;AAIO,MAAM,YAAY,CAAC,EAAE,UAAU,gBAGhC;AACL,QAAM,YAAYA,SAAAA,kBAAkB;AACpC,MAAI,CAAC,WAAW;AACT,UAAA,IAAIC,0BAAa,2CAA2C;AAAA,EAAA;AAE7D,QAAA,EAAE,QAAQ,OAAA,IAAW;AACrB,QAAA,YAAYC,cAAQ,MAAM,UAAU,UAAU,EAAE,EAAE,OAAO,CAAC,IAAI,OAAO,QAAQ,IAAI,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC,QAAQ,SAAS,CAAC;AAClI,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAOC,MAAAA,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAI,SAAS,EAAE,IAAI,GAAG,MAAM,UAAU,KAAK,GAAG,IAAI,CAAC;AAAA,MACnD,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useMemo, cloneElement } from "react";
|
|
2
|
-
import { useFormFieldState } from "../contexts.js";
|
|
3
|
-
import { BindingError } from "@contember/react-binding";
|
|
4
|
-
const FormError = ({ children, formatter }) => {
|
|
5
|
-
const formState = useFormFieldState();
|
|
6
|
-
if (!formState) {
|
|
7
|
-
throw new BindingError("FormError must be used inside a FormField");
|
|
8
|
-
}
|
|
9
|
-
const { errors, htmlId } = formState;
|
|
10
|
-
const formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter]);
|
|
11
|
-
return formatted.map((it, index) => {
|
|
12
|
-
return cloneElement(children, {
|
|
13
|
-
key: index,
|
|
14
|
-
...htmlId ? { id: `${htmlId}-error-${index}` } : {},
|
|
15
|
-
children: it
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
FormError
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=FormError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormError.js","sources":["../../../../../packages/react-form/src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormFieldState } 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 formState = useFormFieldState()\n\tif (!formState) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\tconst { errors, htmlId } = formState\n\tconst formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter])\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...(htmlId ? { id: `${htmlId}-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,YAAY,kBAAkB;AACpC,MAAI,CAAC,WAAW;AACT,UAAA,IAAI,aAAa,2CAA2C;AAAA,EAAA;AAE7D,QAAA,EAAE,QAAQ,OAAA,IAAW;AACrB,QAAA,YAAY,QAAQ,MAAM,UAAU,UAAU,EAAE,EAAE,OAAO,CAAC,IAAI,OAAO,QAAQ,IAAI,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC,QAAQ,SAAS,CAAC;AAClI,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAO,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAI,SAAS,EAAE,IAAI,GAAG,MAAM,UAAU,KAAK,GAAG,IAAI,CAAC;AAAA,MACnD,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
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 FormFieldStateProvider = require("./FormFieldStateProvider.cjs");
|
|
7
|
-
const FormFieldScope = ({ field, children, required }) => {
|
|
8
|
-
const fieldAccessor = reactBinding.useField({ field });
|
|
9
|
-
const entityName = fieldAccessor.getParent().name;
|
|
10
|
-
const fieldName = fieldAccessor.fieldName;
|
|
11
|
-
const enumName = fieldAccessor.schema.enumName ?? void 0;
|
|
12
|
-
const fieldInfo = React.useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName]);
|
|
13
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
14
|
-
FormFieldStateProvider.FormFieldStateProvider,
|
|
15
|
-
{
|
|
16
|
-
errors: fieldAccessor.errors?.errors,
|
|
17
|
-
required: required ?? !fieldAccessor.schema.nullable,
|
|
18
|
-
dirty: fieldAccessor.hasUnpersistedChanges,
|
|
19
|
-
field: fieldInfo,
|
|
20
|
-
children
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
exports.FormFieldScope = FormFieldScope;
|
|
25
|
-
//# sourceMappingURL=FormFieldScope.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldScope.cjs","sources":["../../../../../packages/react-form/src/components/FormFieldScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMemo } from 'react'\nimport { SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\n\nexport type FormFieldScopeProps = {\n\tfield: SugaredRelativeSingleField['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormFieldScope = ({ field, children, required }: FormFieldScopeProps) => {\n\tconst fieldAccessor = useField({ field })\n\tconst entityName = fieldAccessor.getParent().name\n\tconst fieldName = fieldAccessor.fieldName\n\tconst enumName = fieldAccessor.schema.enumName ?? undefined\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={fieldAccessor.errors?.errors}\n\t\t\trequired={required ?? !fieldAccessor.schema.nullable}\n\t\t\tdirty={fieldAccessor.hasUnpersistedChanges}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":["useField","useMemo","jsx","FormFieldStateProvider"],"mappings":";;;;;;AAWO,MAAM,iBAAiB,CAAC,EAAE,OAAO,UAAU,eAAoC;AACrF,QAAM,gBAAgBA,aAAAA,SAAS,EAAE,OAAO;AAClC,QAAA,aAAa,cAAc,UAAA,EAAY;AAC7C,QAAM,YAAY,cAAc;AAC1B,QAAA,WAAW,cAAc,OAAO,YAAY;AAClD,QAAM,YAAYC,MAAAA,QAAQ,OAAO,EAAE,YAAY,WAAW,SAAS,IAAI,CAAC,YAAY,WAAW,QAAQ,CAAC;AAGvG,SAAAC,2BAAA;AAAA,IAACC,uBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,cAAc,QAAQ;AAAA,MAC9B,UAAU,YAAY,CAAC,cAAc,OAAO;AAAA,MAC5C,OAAO,cAAc;AAAA,MACrB,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EACF;AAEF;;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useField } from "@contember/react-binding";
|
|
4
|
-
import { FormFieldStateProvider } from "./FormFieldStateProvider.js";
|
|
5
|
-
const FormFieldScope = ({ field, children, required }) => {
|
|
6
|
-
const fieldAccessor = useField({ field });
|
|
7
|
-
const entityName = fieldAccessor.getParent().name;
|
|
8
|
-
const fieldName = fieldAccessor.fieldName;
|
|
9
|
-
const enumName = fieldAccessor.schema.enumName ?? void 0;
|
|
10
|
-
const fieldInfo = useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName]);
|
|
11
|
-
return /* @__PURE__ */ jsx(
|
|
12
|
-
FormFieldStateProvider,
|
|
13
|
-
{
|
|
14
|
-
errors: fieldAccessor.errors?.errors,
|
|
15
|
-
required: required ?? !fieldAccessor.schema.nullable,
|
|
16
|
-
dirty: fieldAccessor.hasUnpersistedChanges,
|
|
17
|
-
field: fieldInfo,
|
|
18
|
-
children
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
FormFieldScope
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=FormFieldScope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldScope.js","sources":["../../../../../packages/react-form/src/components/FormFieldScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMemo } from 'react'\nimport { SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\n\nexport type FormFieldScopeProps = {\n\tfield: SugaredRelativeSingleField['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormFieldScope = ({ field, children, required }: FormFieldScopeProps) => {\n\tconst fieldAccessor = useField({ field })\n\tconst entityName = fieldAccessor.getParent().name\n\tconst fieldName = fieldAccessor.fieldName\n\tconst enumName = fieldAccessor.schema.enumName ?? undefined\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={fieldAccessor.errors?.errors}\n\t\t\trequired={required ?? !fieldAccessor.schema.nullable}\n\t\t\tdirty={fieldAccessor.hasUnpersistedChanges}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,iBAAiB,CAAC,EAAE,OAAO,UAAU,eAAoC;AACrF,QAAM,gBAAgB,SAAS,EAAE,OAAO;AAClC,QAAA,aAAa,cAAc,UAAA,EAAY;AAC7C,QAAM,YAAY,cAAc;AAC1B,QAAA,WAAW,cAAc,OAAO,YAAY;AAClD,QAAM,YAAY,QAAQ,OAAO,EAAE,YAAY,WAAW,SAAS,IAAI,CAAC,YAAY,WAAW,QAAQ,CAAC;AAGvG,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,cAAc,QAAQ;AAAA,MAC9B,UAAU,YAAY,CAAC,cAAc,OAAO;AAAA,MAC5C,OAAO,cAAc;AAAA,MACrB,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EACF;AAEF;"}
|
|
@@ -1,34 +0,0 @@
|
|
|
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 emptyArr = [];
|
|
7
|
-
const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }) => {
|
|
8
|
-
const generatedId = React.useId();
|
|
9
|
-
htmlId ?? (htmlId = generatedId);
|
|
10
|
-
const value = React.useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field]);
|
|
11
|
-
return /* @__PURE__ */ jsxRuntime.jsx(contexts.FormFieldStateContext.Provider, { value, children });
|
|
12
|
-
};
|
|
13
|
-
const FormFieldIdContext = {
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated use `FormFieldStateProvider` instead
|
|
16
|
-
*/
|
|
17
|
-
Provider: ({ children, value }) => {
|
|
18
|
-
const state = contexts.useFormFieldState();
|
|
19
|
-
return /* @__PURE__ */ jsxRuntime.jsx(FormFieldStateProvider, { ...state, htmlId: value, children });
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const FormErrorContext = {
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated use `FormFieldStateProvider` instead
|
|
25
|
-
*/
|
|
26
|
-
Provider: ({ children, value }) => {
|
|
27
|
-
const state = contexts.useFormFieldState();
|
|
28
|
-
return /* @__PURE__ */ jsxRuntime.jsx(FormFieldStateProvider, { ...state, errors: value, children });
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
exports.FormErrorContext = FormErrorContext;
|
|
32
|
-
exports.FormFieldIdContext = FormFieldIdContext;
|
|
33
|
-
exports.FormFieldStateProvider = FormFieldStateProvider;
|
|
34
|
-
//# sourceMappingURL=FormFieldStateProvider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldStateProvider.cjs","sources":["../../../../../packages/react-form/src/components/FormFieldStateProvider.tsx"],"sourcesContent":["import { ErrorAccessor } from '@contember/react-binding'\nimport { useEffect, useId, useMemo } from 'react'\nimport { FormFieldStateContext, useFormFieldState } from '../contexts'\nimport { FormFieldState } from '../types'\n\nconst emptyArr: [] = []\n\nexport type FormFieldStateProvider =\n\t& Partial<FormFieldState>\n\t& {\n\t\tchildren: React.ReactNode\n\t}\n\nexport const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }: FormFieldStateProvider) => {\n\tconst generatedId = useId()\n\thtmlId ??= generatedId\n\tconst value = useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field])\n\treturn <FormFieldStateContext.Provider value={value}>{children}</FormFieldStateContext.Provider>\n}\n\n/**\n * BC for\n * \t<FormFieldIdContext.Provider value={id}>\n * \t<FormErrorContext.Provider value={[]}>\n */\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormFieldIdContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: string }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormFieldIdContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} htmlId={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormErrorContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: ErrorAccessor.Error[] }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormErrorContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} errors={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n"],"names":["useId","useMemo","FormFieldStateContext","useFormFieldState"],"mappings":";;;;;AAKA,MAAM,WAAe,CAAC;AAQf,MAAM,yBAAyB,CAAC,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,QAAQ,OAAO,QAAQ,MAAA,MAAoC;AAClJ,QAAM,cAAcA,MAAAA,MAAM;AACf,aAAA,SAAA;AACX,QAAM,QAAQC,MAAAA,QAAQ,OAAO,EAAE,QAAQ,UAAU,QAAQ,OAAO,MAAM,IAAI,CAAC,QAAQ,UAAU,QAAQ,OAAO,KAAK,CAAC;AAClH,wCAAQC,SAAAA,sBAAsB,UAAtB,EAA+B,OAAe,UAAS;AAChE;AAWO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAIjC,UAAU,CAAC,EAAE,UAAU,YAA0D;AAChF,UAAM,QAAQC,SAAAA,kBAAkB;0CAQ9B,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAAA;AAGH;AAKO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAI/B,UAAU,CAAC,EAAE,UAAU,YAAyE;AAC/F,UAAM,QAAQA,SAAAA,kBAAkB;0CAQ9B,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAAA;AAGH;;;;"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useId, useMemo } from "react";
|
|
3
|
-
import { FormFieldStateContext, useFormFieldState } from "../contexts.js";
|
|
4
|
-
const emptyArr = [];
|
|
5
|
-
const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }) => {
|
|
6
|
-
const generatedId = useId();
|
|
7
|
-
htmlId ?? (htmlId = generatedId);
|
|
8
|
-
const value = useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field]);
|
|
9
|
-
return /* @__PURE__ */ jsx(FormFieldStateContext.Provider, { value, children });
|
|
10
|
-
};
|
|
11
|
-
const FormFieldIdContext = {
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated use `FormFieldStateProvider` instead
|
|
14
|
-
*/
|
|
15
|
-
Provider: ({ children, value }) => {
|
|
16
|
-
const state = useFormFieldState();
|
|
17
|
-
return /* @__PURE__ */ jsx(FormFieldStateProvider, { ...state, htmlId: value, children });
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const FormErrorContext = {
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated use `FormFieldStateProvider` instead
|
|
23
|
-
*/
|
|
24
|
-
Provider: ({ children, value }) => {
|
|
25
|
-
const state = useFormFieldState();
|
|
26
|
-
return /* @__PURE__ */ jsx(FormFieldStateProvider, { ...state, errors: value, children });
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export {
|
|
30
|
-
FormErrorContext,
|
|
31
|
-
FormFieldIdContext,
|
|
32
|
-
FormFieldStateProvider
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=FormFieldStateProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldStateProvider.js","sources":["../../../../../packages/react-form/src/components/FormFieldStateProvider.tsx"],"sourcesContent":["import { ErrorAccessor } from '@contember/react-binding'\nimport { useEffect, useId, useMemo } from 'react'\nimport { FormFieldStateContext, useFormFieldState } from '../contexts'\nimport { FormFieldState } from '../types'\n\nconst emptyArr: [] = []\n\nexport type FormFieldStateProvider =\n\t& Partial<FormFieldState>\n\t& {\n\t\tchildren: React.ReactNode\n\t}\n\nexport const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }: FormFieldStateProvider) => {\n\tconst generatedId = useId()\n\thtmlId ??= generatedId\n\tconst value = useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field])\n\treturn <FormFieldStateContext.Provider value={value}>{children}</FormFieldStateContext.Provider>\n}\n\n/**\n * BC for\n * \t<FormFieldIdContext.Provider value={id}>\n * \t<FormErrorContext.Provider value={[]}>\n */\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormFieldIdContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: string }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormFieldIdContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} htmlId={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormErrorContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: ErrorAccessor.Error[] }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormErrorContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} errors={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,WAAe,CAAC;AAQf,MAAM,yBAAyB,CAAC,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,QAAQ,OAAO,QAAQ,MAAA,MAAoC;AAClJ,QAAM,cAAc,MAAM;AACf,aAAA,SAAA;AACX,QAAM,QAAQ,QAAQ,OAAO,EAAE,QAAQ,UAAU,QAAQ,OAAO,MAAM,IAAI,CAAC,QAAQ,UAAU,QAAQ,OAAO,KAAK,CAAC;AAClH,6BAAQ,sBAAsB,UAAtB,EAA+B,OAAe,UAAS;AAChE;AAWO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAIjC,UAAU,CAAC,EAAE,UAAU,YAA0D;AAChF,UAAM,QAAQ,kBAAkB;+BAQ9B,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAAA;AAGH;AAKO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAI/B,UAAU,CAAC,EAAE,UAAU,YAAyE;AAC/F,UAAM,QAAQ,kBAAkB;+BAQ9B,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAAA;AAGH;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
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 FormFieldStateProvider = require("./FormFieldStateProvider.cjs");
|
|
6
|
-
const React = require("react");
|
|
7
|
-
const FormHasManyRelationScope = ({ children, required, ...props }) => {
|
|
8
|
-
const entityRelation = reactBinding.useEntityList(props);
|
|
9
|
-
const entityName = entityRelation.getParent().name;
|
|
10
|
-
const marker = entityRelation.getMarker();
|
|
11
|
-
const fieldName = marker.parameters.field;
|
|
12
|
-
const fieldInfo = React.useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
|
|
13
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
14
|
-
FormFieldStateProvider.FormFieldStateProvider,
|
|
15
|
-
{
|
|
16
|
-
errors: entityRelation.errors?.errors,
|
|
17
|
-
dirty: entityRelation.hasUnpersistedChanges,
|
|
18
|
-
required,
|
|
19
|
-
field: fieldInfo,
|
|
20
|
-
children
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
exports.FormHasManyRelationScope = FormHasManyRelationScope;
|
|
25
|
-
//# sourceMappingURL=FormHasManyRelationScope.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormHasManyRelationScope.cjs","sources":["../../../../../packages/react-form/src/components/FormHasManyRelationScope.tsx"],"sourcesContent":["import { HasManyRelationMarker, SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport * as React from 'react'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasManyRelationScopeProps = {\n\tfield: SugaredRelativeEntityList['field']\n\torderBy?: SugaredRelativeEntityList['orderBy']\n\tlimit?: SugaredRelativeEntityList['limit']\n\toffset?: SugaredRelativeEntityList['offset']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasManyRelationScope = ({ children, required, ...props }: FormHasManyRelationScopeProps) => {\n\tconst entityRelation = useEntityList(props)\n\tconst entityName = entityRelation.getParent()!.name\n\tconst marker = entityRelation.getMarker() as HasManyRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":["useEntityList","useMemo","jsx","FormFieldStateProvider"],"mappings":";;;;;;AAcO,MAAM,2BAA2B,CAAC,EAAE,UAAU,UAAU,GAAG,YAA2C;AACtG,QAAA,iBAAiBA,2BAAc,KAAK;AACpC,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,SAAS,eAAe,UAAU;AAClC,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,YAAYC,cAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AAGnF,SAAAC,2BAAA;AAAA,IAACC,uBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EACF;AAEF;;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEntityList } from "@contember/react-binding";
|
|
3
|
-
import { FormFieldStateProvider } from "./FormFieldStateProvider.js";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
|
-
const FormHasManyRelationScope = ({ children, required, ...props }) => {
|
|
6
|
-
const entityRelation = useEntityList(props);
|
|
7
|
-
const entityName = entityRelation.getParent().name;
|
|
8
|
-
const marker = entityRelation.getMarker();
|
|
9
|
-
const fieldName = marker.parameters.field;
|
|
10
|
-
const fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
|
|
11
|
-
return /* @__PURE__ */ jsx(
|
|
12
|
-
FormFieldStateProvider,
|
|
13
|
-
{
|
|
14
|
-
errors: entityRelation.errors?.errors,
|
|
15
|
-
dirty: entityRelation.hasUnpersistedChanges,
|
|
16
|
-
required,
|
|
17
|
-
field: fieldInfo,
|
|
18
|
-
children
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
FormHasManyRelationScope
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=FormHasManyRelationScope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormHasManyRelationScope.js","sources":["../../../../../packages/react-form/src/components/FormHasManyRelationScope.tsx"],"sourcesContent":["import { HasManyRelationMarker, SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport * as React from 'react'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasManyRelationScopeProps = {\n\tfield: SugaredRelativeEntityList['field']\n\torderBy?: SugaredRelativeEntityList['orderBy']\n\tlimit?: SugaredRelativeEntityList['limit']\n\toffset?: SugaredRelativeEntityList['offset']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasManyRelationScope = ({ children, required, ...props }: FormHasManyRelationScopeProps) => {\n\tconst entityRelation = useEntityList(props)\n\tconst entityName = entityRelation.getParent()!.name\n\tconst marker = entityRelation.getMarker() as HasManyRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAcO,MAAM,2BAA2B,CAAC,EAAE,UAAU,UAAU,GAAG,YAA2C;AACtG,QAAA,iBAAiB,cAAc,KAAK;AACpC,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,SAAS,eAAe,UAAU;AAClC,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,YAAY,QAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AAGnF,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EACF;AAEF;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
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 FormFieldStateProvider = require("./FormFieldStateProvider.cjs");
|
|
6
|
-
const React = require("react");
|
|
7
|
-
const FormHasOneRelationScope = ({ field, children, required }) => {
|
|
8
|
-
const entityRelation = reactBinding.useEntity({ field });
|
|
9
|
-
const marker = entityRelation.getMarker();
|
|
10
|
-
const fieldName = marker.parameters.field;
|
|
11
|
-
const entityName = entityRelation.getParent().name;
|
|
12
|
-
const fieldInfo = React.useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
|
|
13
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
14
|
-
FormFieldStateProvider.FormFieldStateProvider,
|
|
15
|
-
{
|
|
16
|
-
errors: entityRelation.errors?.errors,
|
|
17
|
-
dirty: entityRelation.hasUnpersistedChanges,
|
|
18
|
-
required,
|
|
19
|
-
field: fieldInfo,
|
|
20
|
-
children
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
exports.FormHasOneRelationScope = FormHasOneRelationScope;
|
|
25
|
-
//# sourceMappingURL=FormHasOneRelationScope.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormHasOneRelationScope.cjs","sources":["../../../../../packages/react-form/src/components/FormHasOneRelationScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { HasOneRelationMarker, SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasOneRelationScopeProps = {\n\tfield: SugaredRelativeSingleEntity['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasOneRelationScope = ({ field, children, required }: FormHasOneRelationScopeProps) => {\n\tconst entityRelation = useEntity({ field })\n\tconst marker = entityRelation.getMarker() as HasOneRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst entityName = entityRelation.getParent()!.name\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":["useEntity","useMemo","jsx","FormFieldStateProvider"],"mappings":";;;;;;AAWO,MAAM,0BAA0B,CAAC,EAAE,OAAO,UAAU,eAA6C;AACvG,QAAM,iBAAiBA,aAAAA,UAAU,EAAE,OAAO;AACpC,QAAA,SAAS,eAAe,UAAU;AAClC,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,YAAYC,cAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AAEnF,SAAAC,2BAAA;AAAA,IAACC,uBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EACF;AAEF;;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEntity } from "@contember/react-binding";
|
|
3
|
-
import { FormFieldStateProvider } from "./FormFieldStateProvider.js";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
|
-
const FormHasOneRelationScope = ({ field, children, required }) => {
|
|
6
|
-
const entityRelation = useEntity({ field });
|
|
7
|
-
const marker = entityRelation.getMarker();
|
|
8
|
-
const fieldName = marker.parameters.field;
|
|
9
|
-
const entityName = entityRelation.getParent().name;
|
|
10
|
-
const fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
|
|
11
|
-
return /* @__PURE__ */ jsx(
|
|
12
|
-
FormFieldStateProvider,
|
|
13
|
-
{
|
|
14
|
-
errors: entityRelation.errors?.errors,
|
|
15
|
-
dirty: entityRelation.hasUnpersistedChanges,
|
|
16
|
-
required,
|
|
17
|
-
field: fieldInfo,
|
|
18
|
-
children
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
FormHasOneRelationScope
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=FormHasOneRelationScope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormHasOneRelationScope.js","sources":["../../../../../packages/react-form/src/components/FormHasOneRelationScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { HasOneRelationMarker, SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasOneRelationScopeProps = {\n\tfield: SugaredRelativeSingleEntity['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasOneRelationScope = ({ field, children, required }: FormHasOneRelationScopeProps) => {\n\tconst entityRelation = useEntity({ field })\n\tconst marker = entityRelation.getMarker() as HasOneRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst entityName = entityRelation.getParent()!.name\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,0BAA0B,CAAC,EAAE,OAAO,UAAU,eAA6C;AACvG,QAAM,iBAAiB,UAAU,EAAE,OAAO;AACpC,QAAA,SAAS,eAAe,UAAU;AAClC,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,YAAY,QAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AAEnF,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EACF;AAEF;"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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 reactUtils = require("@contember/react-utils");
|
|
12
|
-
const SlotInput = reactSlot.Slot;
|
|
13
|
-
const FormInput = reactBinding.Component(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {
|
|
14
|
-
const accessor = reactBinding.useField(field);
|
|
15
|
-
const formState = contexts.useFormFieldState();
|
|
16
|
-
const id = formState?.htmlId;
|
|
17
|
-
const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
|
|
18
|
-
const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
|
|
19
|
-
const required = formState?.required ?? !accessor.schema.nullable;
|
|
20
|
-
const [state, setState] = React.useState(void 0);
|
|
21
|
-
const { parseValue, formatValue, defaultInputProps } = useFormInputHandler.useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn });
|
|
22
|
-
const accessorGetter = accessor.getAccessor;
|
|
23
|
-
const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
|
|
24
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
25
|
-
SlotInput,
|
|
26
|
-
{
|
|
27
|
-
ref,
|
|
28
|
-
value: formatValue(accessor.value, { state, setState }),
|
|
29
|
-
"data-invalid": utilities.dataAttribute(hasErrors),
|
|
30
|
-
"data-dirty": utilities.dataAttribute(dirty),
|
|
31
|
-
"data-required": utilities.dataAttribute(required),
|
|
32
|
-
onFocus,
|
|
33
|
-
onBlur,
|
|
34
|
-
onChange: reactUtils.useReferentiallyStableCallback((e) => {
|
|
35
|
-
accessorGetter().updateValue(parseValue(e.target.value, { state, setState }));
|
|
36
|
-
}),
|
|
37
|
-
...defaultInputProps,
|
|
38
|
-
id: id ? `${id}-input` : void 0,
|
|
39
|
-
required,
|
|
40
|
-
...props
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
}, ({ field, isNonbearing, defaultValue }) => {
|
|
44
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { field, isNonbearing, defaultValue });
|
|
45
|
-
});
|
|
46
|
-
exports.FormInput = FormInput;
|
|
47
|
-
//# sourceMappingURL=FormInput.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormInput.cjs","sources":["../../../../../packages/react-form/src/components/FormInput.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ComponentType, useCallback, useState } 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 { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks/useFormInputValidationHandler'\nimport { FormInputHandler } from '../types'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\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\tformatValue?: FormInputHandler['formatValue']\n\tparseValue?: FormInputHandler['parseValue']\n}\n\nexport const FormInput = Component<FormInputProps>(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\tconst required = formState?.required ?? !accessor.schema.nullable\n\n\tconst [state, setState] = useState<any>(undefined)\n\n\tconst { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn })\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, { state, setState })}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tdata-required={dataAttribute(required)}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useReferentiallyStableCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(parseValue(e.target.value, { state, setState }))\n\t\t\t})}\n\t\t\t{...defaultInputProps}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\trequired={required}\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","useField","useFormFieldState","useState","useFormInputHandler","useFormInputValidationHandler","jsx","dataAttribute","useReferentiallyStableCallback","Field"],"mappings":";;;;;;;;;;;AAYA,MAAM,YAAYA,UAAA;AAWX,MAAM,YAAYC,aAAA,UAA0B,CAAC,EAAE,OAAO,cAAc,cAAc,aAAa,eAAe,YAAY,cAAc,GAAG,YAAY;AACvJ,QAAA,WAAWC,sBAAS,KAAK;AAE/B,QAAM,YAAYC,SAAAA,kBAAkB;AACpC,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,WAAW,WAAW,YAAY,CAAC,SAAS,OAAO;AAEzD,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAc,MAAS;AAEjD,QAAM,EAAE,YAAY,aAAa,kBAAsB,IAAAC,oBAAA,oBAAoB,UAAU,EAAE,aAAa,eAAe,YAAY,aAAA,CAAc;AAC7I,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,OAAO,EAAE,OAAO,UAAU;AAAA,MACtD,gBAAcC,wBAAc,SAAS;AAAA,MACrC,cAAYA,wBAAc,KAAK;AAAA,MAC/B,iBAAeA,wBAAc,QAAQ;AAAA,MACrC;AAAA,MACA;AAAA,MACA,UAAUC,WAAAA,+BAAqE,CAAK,MAAA;AACpE,uBAAA,EAAE,YAAY,WAAW,EAAE,OAAO,OAAO,EAAE,OAAO,SAAS,CAAC,CAAC;AAAA,MAAA,CAC5E;AAAA,MACA,GAAG;AAAA,MACJ,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACC,GAAG;AAAA,IAAA;AAAA,EACL;AAEF,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQF,2BAAAA,IAAAG,aAAAA,OAAA,EAAM,OAAc,cAA4B,aAA4B,CAAA;AACrF,CAAC;;"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState } 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 { useFormFieldState } from "../contexts.js";
|
|
8
|
-
import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
|
|
9
|
-
import { useReferentiallyStableCallback } from "@contember/react-utils";
|
|
10
|
-
const SlotInput = Slot;
|
|
11
|
-
const FormInput = Component(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {
|
|
12
|
-
const accessor = useField(field);
|
|
13
|
-
const formState = useFormFieldState();
|
|
14
|
-
const id = formState?.htmlId;
|
|
15
|
-
const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
|
|
16
|
-
const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
|
|
17
|
-
const required = formState?.required ?? !accessor.schema.nullable;
|
|
18
|
-
const [state, setState] = useState(void 0);
|
|
19
|
-
const { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn });
|
|
20
|
-
const accessorGetter = accessor.getAccessor;
|
|
21
|
-
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
|
|
22
|
-
return /* @__PURE__ */ jsx(
|
|
23
|
-
SlotInput,
|
|
24
|
-
{
|
|
25
|
-
ref,
|
|
26
|
-
value: formatValue(accessor.value, { state, setState }),
|
|
27
|
-
"data-invalid": dataAttribute(hasErrors),
|
|
28
|
-
"data-dirty": dataAttribute(dirty),
|
|
29
|
-
"data-required": dataAttribute(required),
|
|
30
|
-
onFocus,
|
|
31
|
-
onBlur,
|
|
32
|
-
onChange: useReferentiallyStableCallback((e) => {
|
|
33
|
-
accessorGetter().updateValue(parseValue(e.target.value, { state, setState }));
|
|
34
|
-
}),
|
|
35
|
-
...defaultInputProps,
|
|
36
|
-
id: id ? `${id}-input` : void 0,
|
|
37
|
-
required,
|
|
38
|
-
...props
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
}, ({ field, isNonbearing, defaultValue }) => {
|
|
42
|
-
return /* @__PURE__ */ jsx(Field, { field, isNonbearing, defaultValue });
|
|
43
|
-
});
|
|
44
|
-
export {
|
|
45
|
-
FormInput
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=FormInput.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormInput.js","sources":["../../../../../packages/react-form/src/components/FormInput.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ComponentType, useCallback, useState } 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 { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks/useFormInputValidationHandler'\nimport { FormInputHandler } from '../types'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\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\tformatValue?: FormInputHandler['formatValue']\n\tparseValue?: FormInputHandler['parseValue']\n}\n\nexport const FormInput = Component<FormInputProps>(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\tconst required = formState?.required ?? !accessor.schema.nullable\n\n\tconst [state, setState] = useState<any>(undefined)\n\n\tconst { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn })\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, { state, setState })}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tdata-required={dataAttribute(required)}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useReferentiallyStableCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(parseValue(e.target.value, { state, setState }))\n\t\t\t})}\n\t\t\t{...defaultInputProps}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\trequired={required}\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":";;;;;;;;;AAYA,MAAM,YAAY;AAWX,MAAM,YAAY,UAA0B,CAAC,EAAE,OAAO,cAAc,cAAc,aAAa,eAAe,YAAY,cAAc,GAAG,YAAY;AACvJ,QAAA,WAAW,SAAS,KAAK;AAE/B,QAAM,YAAY,kBAAkB;AACpC,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,WAAW,WAAW,YAAY,CAAC,SAAS,OAAO;AAEzD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAc,MAAS;AAEjD,QAAM,EAAE,YAAY,aAAa,kBAAsB,IAAA,oBAAoB,UAAU,EAAE,aAAa,eAAe,YAAY,aAAA,CAAc;AAC7I,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,OAAO,EAAE,OAAO,UAAU;AAAA,MACtD,gBAAc,cAAc,SAAS;AAAA,MACrC,cAAY,cAAc,KAAK;AAAA,MAC/B,iBAAe,cAAc,QAAQ;AAAA,MACrC;AAAA,MACA;AAAA,MACA,UAAU,+BAAqE,CAAK,MAAA;AACpE,uBAAA,EAAE,YAAY,WAAW,EAAE,OAAO,OAAO,EAAE,OAAO,SAAS,CAAC,CAAC;AAAA,MAAA,CAC5E;AAAA,MACA,GAAG;AAAA,MACJ,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACC,GAAG;AAAA,IAAA;AAAA,EACL;AAEF,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,aAA4B,CAAA;AACrF,CAAC;"}
|