@contember/react-form 2.1.0-alpha.8 → 2.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +19 -0
- package/dist/development/index.cjs +6 -6
- package/dist/development/index.js +3 -3
- package/dist/development/src/components/FormCheckbox.cjs +2 -2
- package/dist/development/src/components/FormCheckbox.cjs.map +1 -1
- package/dist/development/src/components/FormCheckbox.js +2 -2
- package/dist/development/src/components/FormCheckbox.js.map +1 -1
- package/dist/development/src/components/FormError.cjs.map +1 -1
- package/dist/development/src/components/FormError.js.map +1 -1
- package/dist/development/src/components/FormFieldScope.cjs.map +1 -1
- package/dist/development/src/components/FormFieldScope.js.map +1 -1
- package/dist/development/src/components/FormFieldStateProvider.cjs +2 -2
- package/dist/development/src/components/FormFieldStateProvider.cjs.map +1 -1
- package/dist/development/src/components/FormFieldStateProvider.js +4 -4
- package/dist/development/src/components/FormFieldStateProvider.js.map +1 -1
- package/dist/development/src/components/FormHasManyRelationScope.cjs.map +1 -1
- package/dist/development/src/components/FormHasManyRelationScope.js.map +1 -1
- package/dist/development/src/components/FormHasOneRelationScope.cjs.map +1 -1
- package/dist/development/src/components/FormHasOneRelationScope.js.map +1 -1
- package/dist/development/src/components/FormInput.cjs +47 -44
- package/dist/development/src/components/FormInput.cjs.map +1 -1
- package/dist/development/src/components/FormInput.js +47 -44
- package/dist/development/src/components/FormInput.js.map +1 -1
- package/dist/development/src/components/FormLabel.cjs.map +1 -1
- package/dist/development/src/components/FormLabel.js.map +1 -1
- package/dist/development/src/components/FormRadioInput.cjs.map +1 -1
- package/dist/development/src/components/FormRadioInput.js.map +1 -1
- package/dist/development/src/contexts.cjs.map +1 -1
- package/dist/development/src/contexts.js.map +1 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs +1 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs.map +1 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.js +1 -1
- package/dist/development/src/hooks/useFormInputValidationHandler.js.map +1 -1
- package/dist/development/src/internal/useFormInputHandler.cjs.map +1 -1
- package/dist/development/src/internal/useFormInputHandler.js.map +1 -1
- package/dist/production/index.cjs +6 -6
- package/dist/production/index.js +3 -3
- package/dist/production/src/components/FormCheckbox.cjs.map +1 -1
- package/dist/production/src/components/FormCheckbox.js.map +1 -1
- package/dist/production/src/components/FormError.cjs.map +1 -1
- package/dist/production/src/components/FormError.js.map +1 -1
- package/dist/production/src/components/FormFieldScope.cjs.map +1 -1
- package/dist/production/src/components/FormFieldScope.js.map +1 -1
- package/dist/production/src/components/FormFieldStateProvider.cjs.map +1 -1
- package/dist/production/src/components/FormFieldStateProvider.js +1 -1
- package/dist/production/src/components/FormFieldStateProvider.js.map +1 -1
- package/dist/production/src/components/FormHasManyRelationScope.cjs.map +1 -1
- package/dist/production/src/components/FormHasManyRelationScope.js.map +1 -1
- package/dist/production/src/components/FormHasOneRelationScope.cjs.map +1 -1
- package/dist/production/src/components/FormHasOneRelationScope.js.map +1 -1
- package/dist/production/src/components/FormInput.cjs +36 -33
- package/dist/production/src/components/FormInput.cjs.map +1 -1
- package/dist/production/src/components/FormInput.js +36 -33
- package/dist/production/src/components/FormInput.js.map +1 -1
- package/dist/production/src/components/FormLabel.cjs.map +1 -1
- package/dist/production/src/components/FormLabel.js.map +1 -1
- package/dist/production/src/components/FormRadioInput.cjs.map +1 -1
- package/dist/production/src/components/FormRadioInput.js.map +1 -1
- package/dist/production/src/contexts.cjs.map +1 -1
- package/dist/production/src/contexts.js.map +1 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs +1 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs.map +1 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.js +1 -1
- package/dist/production/src/hooks/useFormInputValidationHandler.js.map +1 -1
- package/dist/production/src/internal/useFormInputHandler.cjs.map +1 -1
- package/dist/production/src/internal/useFormInputHandler.js.map +1 -1
- package/dist/types/components/FormCheckbox.d.ts.map +1 -1
- package/dist/types/components/FormError.d.ts +1 -1
- package/dist/types/components/FormError.d.ts.map +1 -1
- package/dist/types/components/FormFieldStateProvider.d.ts.map +1 -1
- package/dist/types/components/FormInput.d.ts.map +1 -1
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/hooks/useFormInputValidationHandler.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- 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
|
@@ -1 +1 @@
|
|
|
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}
|
|
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>(\n\t({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {\n\t\tconst accessor = useField(field)\n\n\t\tconst formState = useFormFieldState()\n\t\tconst id = formState?.htmlId\n\t\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\t\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\t\tconst required = formState?.required ?? !accessor.schema.nullable\n\n\t\tconst [state, setState] = useState<any>(undefined)\n\n\t\tconst { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn })\n\t\tconst accessorGetter = accessor.getAccessor\n\t\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\t\treturn (\n\t\t\t<SlotInput\n\t\t\t\tref={ref}\n\t\t\t\tvalue={formatValue(accessor.value, { state, setState })}\n\t\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\t\tdata-required={dataAttribute(required)}\n\t\t\t\tonFocus={onFocus}\n\t\t\t\tonBlur={onBlur}\n\t\t\t\tonChange={useReferentiallyStableCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\t\taccessorGetter().updateValue(parseValue(e.target.value, { state, setState }))\n\t\t\t\t})}\n\t\t\t\t{...defaultInputProps}\n\t\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\t\trequired={required}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t)\n\t},\n\t({ field, isNonbearing, defaultValue }) => {\n\t\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue} />\n\t},\n)\n"],"names":["this"],"mappings":";;;;;;;;;AAYA,MAAM,YAAY;AAWX,MAAM,YAAY;AAAA,EACxB,CAAC,EAAE,OAAO,cAAc,cAAc,aAAa,eAAe,YAAY,cAAc,GAAG,YAAY;AAC1G,UAAM,WAAW,SAAS,KAAK;AAE/B,UAAM,YAAY,kBAAA;AAClB,UAAM,KAAK,WAAW;AACtB,UAAM,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACvF,UAAM,QAAQ,WAAW,SAAS,SAAS;AAC3C,UAAM,WAAW,WAAW,YAAY,CAAC,SAAS,OAAO;AAEzD,UAAM,CAAC,OAAO,QAAQ,IAAI,SAAc,MAAS;AAEjD,UAAM,EAAE,YAAY,aAAa,kBAAA,IAAsB,oBAAoB,UAAU,EAAE,aAAa,eAAe,YAAY,aAAA,CAAc;AAC7I,UAAM,iBAAiB,SAAS;AAChC,UAAM,EAAE,KAAK,SAAS,OAAA,IAAW,8BAA8B,QAAQ;AAEvE,WACC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA;AAAA,QACA,OAAO,YAAY,SAAS,OAAO,EAAE,OAAO,UAAU;AAAA,QACtD,gBAAc,cAAc,SAAS;AAAA,QACrC,cAAY,cAAc,KAAK;AAAA,QAC/B,iBAAe,cAAc,QAAQ;AAAA,QACrC;AAAA,QACA;AAAA,QACA,UAAU,+BAAqE,CAAA,MAAK;AACnF,yBAAA,EAAiB,YAAY,WAAW,EAAE,OAAO,OAAO,EAAE,OAAO,SAAA,CAAU,CAAC;AAAA,QAC7E,CAAC;AAAA,QACA,GAAG;AAAA,QACJ,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,QACzB;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,MAdL;AAAA,MAAA;AAAA,MAAA;AAAA,QAAA,UAAA;AAAA,QAAA,YAAA;AAAA,QAAA,cAAA;AAAA,MAAA;AAAA,MAAAA;AAAAA,IAAA;AAAA,EAiBF;AAAA,EACA,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC1C,WAAO,uBAAC,OAAA,EAAM,OAAc,cAA4B,aAAA,GAAjD,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAA,MAA6E;AAAA,EACrF;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormLabel.cjs","sources":["../../../../../packages/react-form/src/components/FormLabel.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormFieldState } from '../contexts'\nimport { BindingError } from '@contember/react-binding'\n\nexport const FormLabel = (props: {\n\tchildren: React.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, dirty, required } = formState\n\treturn (\n\t\t<Slot\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tdata-required={dataAttribute(required)}\n\t\t\t{...(htmlId ? { htmlFor: `${htmlId}-input` } : {})}\n\t\t\t{...props}\n\t\t/>\n\t)\n}\n"],"names":["useFormFieldState","BindingError","jsxDEV","Slot","dataAttribute","this"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"FormLabel.cjs","sources":["../../../../../packages/react-form/src/components/FormLabel.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormFieldState } from '../contexts'\nimport { BindingError } from '@contember/react-binding'\n\nexport const FormLabel = (props: {\n\tchildren: React.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, dirty, required } = formState\n\treturn (\n\t\t<Slot\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tdata-required={dataAttribute(required)}\n\t\t\t{...(htmlId ? { htmlFor: `${htmlId}-input` } : {})}\n\t\t\t{...props}\n\t\t/>\n\t)\n}\n"],"names":["useFormFieldState","BindingError","jsxDEV","Slot","dataAttribute","this"],"mappings":";;;;;;;AAMO,MAAM,YAAY,CAAC,UAEpB;AACL,QAAM,YAAYA,SAAAA,kBAAA;AAClB,MAAI,CAAC,WAAW;AACf,UAAM,IAAIC,aAAAA,aAAa,2CAA2C;AAAA,EACnE;AACA,QAAM,EAAE,QAAQ,QAAQ,OAAO,aAAa;AAC5C,SACCC,8BAAAA;AAAAA,IAACC,UAAAA;AAAAA,IAAA;AAAA,MACA,gBAAcC,UAAAA,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,cAAYA,UAAAA,cAAc,KAAK;AAAA,MAC/B,iBAAeA,UAAAA,cAAc,QAAQ;AAAA,MACpC,GAAI,SAAS,EAAE,SAAS,GAAG,MAAM,SAAA,IAAa,CAAA;AAAA,MAC9C,GAAG;AAAA,IAAA;AAAA,IALL;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAC;AAAAA,EAAA;AAQF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormLabel.js","sources":["../../../../../packages/react-form/src/components/FormLabel.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormFieldState } from '../contexts'\nimport { BindingError } from '@contember/react-binding'\n\nexport const FormLabel = (props: {\n\tchildren: React.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, dirty, required } = formState\n\treturn (\n\t\t<Slot\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tdata-required={dataAttribute(required)}\n\t\t\t{...(htmlId ? { htmlFor: `${htmlId}-input` } : {})}\n\t\t\t{...props}\n\t\t/>\n\t)\n}\n"],"names":["this"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"FormLabel.js","sources":["../../../../../packages/react-form/src/components/FormLabel.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormFieldState } from '../contexts'\nimport { BindingError } from '@contember/react-binding'\n\nexport const FormLabel = (props: {\n\tchildren: React.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, dirty, required } = formState\n\treturn (\n\t\t<Slot\n\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tdata-required={dataAttribute(required)}\n\t\t\t{...(htmlId ? { htmlFor: `${htmlId}-input` } : {})}\n\t\t\t{...props}\n\t\t/>\n\t)\n}\n"],"names":["this"],"mappings":";;;;;AAMO,MAAM,YAAY,CAAC,UAEpB;AACL,QAAM,YAAY,kBAAA;AAClB,MAAI,CAAC,WAAW;AACf,UAAM,IAAI,aAAa,2CAA2C;AAAA,EACnE;AACA,QAAM,EAAE,QAAQ,QAAQ,OAAO,aAAa;AAC5C,SACC;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,gBAAc,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,cAAY,cAAc,KAAK;AAAA,MAC/B,iBAAe,cAAc,QAAQ;AAAA,MACpC,GAAI,SAAS,EAAE,SAAS,GAAG,MAAM,SAAA,IAAa,CAAA;AAAA,MAC9C,GAAG;AAAA,IAAA;AAAA,IALL;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAA;AAAAA,EAAA;AAQF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormRadioInput.cjs","sources":["../../../../../packages/react-form/src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { Slot } from '@radix-ui/react-slot'\nimport * as React from 'react'\nimport { ChangeEventHandler, useCallback } from 'react'\nimport { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormRadioItemProps {\n\tfield: SugaredRelativeSingleField['field']\n\tvalue: string | null | number | boolean\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactNode\n}\n\nexport const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\tconst handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\taccessorGetter().updateValue(value)\n\t}, [accessorGetter, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\ttype=\"radio\"\n\t\t\tvalue={typeof value === 'string' ? value : undefined}\n\t\t\tchecked={accessor.value === value}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tname={id ? id + '-input' : undefined}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={handleChange}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }) => {\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}/>\n})\n"],"names":["Slot","Component","useField","useFormFieldState","useFormInputValidationHandler","useCallback","jsxDEV","dataAttribute","this","Field"],"mappings":";;;;;;;;;AAQA,MAAM,YAAYA,
|
|
1
|
+
{"version":3,"file":"FormRadioInput.cjs","sources":["../../../../../packages/react-form/src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { Slot } from '@radix-ui/react-slot'\nimport * as React from 'react'\nimport { ChangeEventHandler, useCallback } from 'react'\nimport { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormRadioItemProps {\n\tfield: SugaredRelativeSingleField['field']\n\tvalue: string | null | number | boolean\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactNode\n}\n\nexport const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\tconst handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\taccessorGetter().updateValue(value)\n\t}, [accessorGetter, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\ttype=\"radio\"\n\t\t\tvalue={typeof value === 'string' ? value : undefined}\n\t\t\tchecked={accessor.value === value}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tname={id ? id + '-input' : undefined}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={handleChange}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }) => {\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue} />\n})\n"],"names":["Slot","Component","useField","useFormFieldState","useFormInputValidationHandler","useCallback","jsxDEV","dataAttribute","this","Field"],"mappings":";;;;;;;;;AAQA,MAAM,YAAYA,UAAAA;AAUX,MAAM,iBAAiBC,aAAAA,UAA8B,CAAC,EAAE,OAAO,OAAO,cAAc,cAAc,GAAG,YAAY;AACvH,QAAM,WAAWC,aAAAA,SAAS,KAAK;AAE/B,QAAM,YAAYC,SAAAA,kBAAA;AAClB,QAAM,KAAK,WAAW;AACtB,QAAM,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACvF,QAAM,QAAQ,WAAW,SAAS,SAAS;AAE3C,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAA,IAAWC,8BAAAA,8BAA8B,QAAQ;AAEvE,QAAM,eAAeC,kBAAkD,CAAA,MAAK;AAC3E,mBAAA,EAAiB,YAAY,KAAK;AAAA,EACnC,GAAG,CAAC,gBAAgB,KAAK,CAAC;AAE1B,SACCC,8BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,MAAK;AAAA,MACL,OAAO,OAAO,UAAU,WAAW,QAAQ;AAAA,MAC3C,SAAS,SAAS,UAAU;AAAA,MAC5B,gBAAcC,UAAAA,cAAc,SAAS;AAAA,MACrC,cAAYA,UAAAA,cAAc,KAAK;AAAA,MAC/B,MAAM,KAAK,KAAK,WAAW;AAAA,MAC3B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACT,GAAG;AAAA,IAAA;AAAA,IAZL;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAC;AAAAA,EAAA;AAeF,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAOF,8BAAAA,OAACG,aAAAA,OAAA,EAAM,OAAc,cAA4B,aAAA,GAAjD,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAA,GAAAD,MAA6E;AACrF,CAAC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormRadioInput.js","sources":["../../../../../packages/react-form/src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { Slot } from '@radix-ui/react-slot'\nimport * as React from 'react'\nimport { ChangeEventHandler, useCallback } from 'react'\nimport { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormRadioItemProps {\n\tfield: SugaredRelativeSingleField['field']\n\tvalue: string | null | number | boolean\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactNode\n}\n\nexport const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\tconst handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\taccessorGetter().updateValue(value)\n\t}, [accessorGetter, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\ttype=\"radio\"\n\t\t\tvalue={typeof value === 'string' ? value : undefined}\n\t\t\tchecked={accessor.value === value}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tname={id ? id + '-input' : undefined}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={handleChange}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }) => {\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}/>\n})\n"],"names":["this"],"mappings":";;;;;;;AAQA,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"FormRadioInput.js","sources":["../../../../../packages/react-form/src/components/FormRadioInput.tsx"],"sourcesContent":["import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { Slot } from '@radix-ui/react-slot'\nimport * as React from 'react'\nimport { ChangeEventHandler, useCallback } from 'react'\nimport { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormRadioItemProps {\n\tfield: SugaredRelativeSingleField['field']\n\tvalue: string | null | number | boolean\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactNode\n}\n\nexport const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\tconst handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\taccessorGetter().updateValue(value)\n\t}, [accessorGetter, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\ttype=\"radio\"\n\t\t\tvalue={typeof value === 'string' ? value : undefined}\n\t\t\tchecked={accessor.value === value}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tname={id ? id + '-input' : undefined}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={handleChange}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }) => {\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue} />\n})\n"],"names":["this"],"mappings":";;;;;;;AAQA,MAAM,YAAY;AAUX,MAAM,iBAAiB,UAA8B,CAAC,EAAE,OAAO,OAAO,cAAc,cAAc,GAAG,YAAY;AACvH,QAAM,WAAW,SAAS,KAAK;AAE/B,QAAM,YAAY,kBAAA;AAClB,QAAM,KAAK,WAAW;AACtB,QAAM,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACvF,QAAM,QAAQ,WAAW,SAAS,SAAS;AAE3C,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAA,IAAW,8BAA8B,QAAQ;AAEvE,QAAM,eAAe,YAAkD,CAAA,MAAK;AAC3E,mBAAA,EAAiB,YAAY,KAAK;AAAA,EACnC,GAAG,CAAC,gBAAgB,KAAK,CAAC;AAE1B,SACC;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,MAAK;AAAA,MACL,OAAO,OAAO,UAAU,WAAW,QAAQ;AAAA,MAC3C,SAAS,SAAS,UAAU;AAAA,MAC5B,gBAAc,cAAc,SAAS;AAAA,MACrC,cAAY,cAAc,KAAK;AAAA,MAC/B,MAAM,KAAK,KAAK,WAAW;AAAA,MAC3B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACT,GAAG;AAAA,IAAA;AAAA,IAZL;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAA;AAAAA,EAAA;AAeF,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAO,uBAAC,OAAA,EAAM,OAAc,cAA4B,aAAA,GAAjD,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAA,GAAAA,MAA6E;AACrF,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.cjs","sources":["../../../../packages/react-form/src/contexts.tsx"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { FormFieldState } from './types'\n\
|
|
1
|
+
{"version":3,"file":"contexts.cjs","sources":["../../../../packages/react-form/src/contexts.tsx"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { FormFieldState } from './types'\n\nconst FormFieldStateContext_ = createContext<FormFieldState | undefined>('FormFieldStateContext', undefined)\nexport const FormFieldStateContext = FormFieldStateContext_[0]\nexport const useFormFieldState = FormFieldStateContext_[1]\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormFieldId = () => useFormFieldState()?.htmlId\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormError = () => useFormFieldState()?.errors\n"],"names":["createContext"],"mappings":";;;AAGA,MAAM,yBAAyBA,WAAAA,cAA0C,yBAAyB,MAAS;AACpG,MAAM,wBAAwB,uBAAuB,CAAC;AACtD,MAAM,oBAAoB,uBAAuB,CAAC;AAKlD,MAAM,iBAAiB,MAAM,qBAAqB;AAKlD,MAAM,eAAe,MAAM,qBAAqB;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.js","sources":["../../../../packages/react-form/src/contexts.tsx"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { FormFieldState } from './types'\n\
|
|
1
|
+
{"version":3,"file":"contexts.js","sources":["../../../../packages/react-form/src/contexts.tsx"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { FormFieldState } from './types'\n\nconst FormFieldStateContext_ = createContext<FormFieldState | undefined>('FormFieldStateContext', undefined)\nexport const FormFieldStateContext = FormFieldStateContext_[0]\nexport const useFormFieldState = FormFieldStateContext_[1]\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormFieldId = () => useFormFieldState()?.htmlId\n\n/**\n * @deprecated use `useFormState` instead\n */\nexport const useFormError = () => useFormFieldState()?.errors\n"],"names":[],"mappings":";AAGA,MAAM,yBAAyB,cAA0C,yBAAyB,MAAS;AACpG,MAAM,wBAAwB,uBAAuB,CAAC;AACtD,MAAM,oBAAoB,uBAAuB,CAAC;AAKlD,MAAM,iBAAiB,MAAM,qBAAqB;AAKlD,MAAM,eAAe,MAAM,qBAAqB;"}
|
|
@@ -21,7 +21,7 @@ function _interopNamespaceDefault(e) {
|
|
|
21
21
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
22
|
const useFormInputValidationHandler = (field) => {
|
|
23
23
|
const accessorGetter = field.getAccessor;
|
|
24
|
-
const validationMessage = React.useRef();
|
|
24
|
+
const validationMessage = React.useRef(void 0);
|
|
25
25
|
const [focus, setFocus] = React__namespace.useState(false);
|
|
26
26
|
const inputRef = React__namespace.useRef(null);
|
|
27
27
|
reactBinding.useEntityBeforePersist(React.useCallback(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormInputValidationHandler.cjs","sources":["../../../../../packages/react-form/src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>()\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tconst previousMessage = validationMessage.current\n\t\tvalidationMessage.current = message\n\n\t\tconst accessor = accessorGetter()\n\t\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\tif (previousMessage) {\n\t\t\t\tclearSpecificError(accessor, previousMessage)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (message === previousMessage) {\n\t\t\treturn\n\t\t}\n\t\t// if the input is not touched, we don't want to show the error message\n\t\tif (!field.isTouched) {\n\t\t\treturn\n\t\t}\n\n\t\t// if the input is not focused, we want to show the error message\n\t\t// also, even the input is focused, we want to replace the previous message\n\t\tif (!focus || !!previousMessage) {\n\t\t\taccessor.clearErrors()\n\t\t\taccessor.addError(message)\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n\nconst clearSpecificError = (field: FieldAccessor<any>, message: string) => {\n\tconst errors = field.errors?.errors ?? []\n\tconst error = errors.filter(e => !(e.type === 'validation' && e.message === message))\n\tfield.clearErrors()\n\terror.forEach(e => field.addError(e))\n}\n"],"names":["useRef","React","useEntityBeforePersist","useCallback","useEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useFormInputValidationHandler.cjs","sources":["../../../../../packages/react-form/src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>(undefined)\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tconst previousMessage = validationMessage.current\n\t\tvalidationMessage.current = message\n\n\t\tconst accessor = accessorGetter()\n\t\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\tif (previousMessage) {\n\t\t\t\tclearSpecificError(accessor, previousMessage)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (message === previousMessage) {\n\t\t\treturn\n\t\t}\n\t\t// if the input is not touched, we don't want to show the error message\n\t\tif (!field.isTouched) {\n\t\t\treturn\n\t\t}\n\n\t\t// if the input is not focused, we want to show the error message\n\t\t// also, even the input is focused, we want to replace the previous message\n\t\tif (!focus || !!previousMessage) {\n\t\t\taccessor.clearErrors()\n\t\t\taccessor.addError(message)\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n\nconst clearSpecificError = (field: FieldAccessor<any>, message: string) => {\n\tconst errors = field.errors?.errors ?? []\n\tconst error = errors.filter(e => !(e.type === 'validation' && e.message === message))\n\tfield.clearErrors()\n\terror.forEach(e => field.addError(e))\n}\n"],"names":["useRef","React","useEntityBeforePersist","useCallback","useEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIO,MAAM,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoBA,MAAAA,OAAe,MAAS;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAIC,iBAAM,SAAS,KAAK;AAC9C,QAAM,WAAWA,iBAAM,OAAyB,IAAI;AACpDC,eAAAA,uBAAuBC,MAAAA,YAAY,MAAM;AACxC,QAAI,kBAAkB,SAAS;AAC9B,uBAAiB,SAAS,kBAAkB,OAAO;AAAA,IACpD;AAAA,EACD,GAAG,CAAC,cAAc,CAAC,CAAC;AAEpBC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,SAAS,SAAS;AACtB;AAAA,IACD;AAEA,UAAM,QAAQ,SAAS;AACvB,UAAM,QAAQ,MAAM,UAAU;AAE9B,UAAM,UAAU,QAAQ,SAAY,OAAO;AAC3C,UAAM,kBAAkB,kBAAkB;AAC1C,sBAAkB,UAAU;AAE5B,UAAM,WAAW,eAAA;AAEjB,QAAI,CAAC,SAAS;AACb,UAAI,iBAAiB;AACpB,2BAAmB,UAAU,eAAe;AAAA,MAC7C;AACA;AAAA,IACD;AACA,QAAI,YAAY,iBAAiB;AAChC;AAAA,IACD;AAEA,QAAI,CAAC,MAAM,WAAW;AACrB;AAAA,IACD;AAIA,QAAI,CAAC,SAAS,CAAC,CAAC,iBAAiB;AAChC,eAAS,YAAA;AACT,eAAS,SAAS,OAAO;AAAA,IAC1B;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN,KAAK;AAAA,IACL,SAASD,MAAAA,YAAY,MAAM;AAC1B,eAAS,IAAI;AAAA,IACd,GAAG,CAAA,CAAE;AAAA,IACL,QAAQA,MAAAA,YAAY,MAAM;AACzB,eAAS,KAAK;AACd,qBAAA,EAAiB,YAAA;AACjB,UAAI,kBAAkB,SAAS;AAC9B,yBAAiB,SAAS,kBAAkB,OAAO;AAAA,MACpD;AAAA,IACD,GAAG,CAAC,cAAc,CAAC;AAAA,EAAA;AAErB;AAEA,MAAM,qBAAqB,CAAC,OAA2B,YAAoB;AAC1E,QAAM,SAAS,MAAM,QAAQ,UAAU,CAAA;AACvC,QAAM,QAAQ,OAAO,OAAO,CAAA,MAAK,EAAE,EAAE,SAAS,gBAAgB,EAAE,YAAY,QAAQ;AACpF,QAAM,YAAA;AACN,QAAM,QAAQ,CAAA,MAAK,MAAM,SAAS,CAAC,CAAC;AACrC;;"}
|
|
@@ -3,7 +3,7 @@ import { useRef, useCallback, useEffect } from "react";
|
|
|
3
3
|
import { useEntityBeforePersist } from "@contember/react-binding";
|
|
4
4
|
const useFormInputValidationHandler = (field) => {
|
|
5
5
|
const accessorGetter = field.getAccessor;
|
|
6
|
-
const validationMessage = useRef();
|
|
6
|
+
const validationMessage = useRef(void 0);
|
|
7
7
|
const [focus, setFocus] = React.useState(false);
|
|
8
8
|
const inputRef = React.useRef(null);
|
|
9
9
|
useEntityBeforePersist(useCallback(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormInputValidationHandler.js","sources":["../../../../../packages/react-form/src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>()\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tconst previousMessage = validationMessage.current\n\t\tvalidationMessage.current = message\n\n\t\tconst accessor = accessorGetter()\n\t\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\tif (previousMessage) {\n\t\t\t\tclearSpecificError(accessor, previousMessage)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (message === previousMessage) {\n\t\t\treturn\n\t\t}\n\t\t// if the input is not touched, we don't want to show the error message\n\t\tif (!field.isTouched) {\n\t\t\treturn\n\t\t}\n\n\t\t// if the input is not focused, we want to show the error message\n\t\t// also, even the input is focused, we want to replace the previous message\n\t\tif (!focus || !!previousMessage) {\n\t\t\taccessor.clearErrors()\n\t\t\taccessor.addError(message)\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n\nconst clearSpecificError = (field: FieldAccessor<any>, message: string) => {\n\tconst errors = field.errors?.errors ?? []\n\tconst error = errors.filter(e => !(e.type === 'validation' && e.message === message))\n\tfield.clearErrors()\n\terror.forEach(e => field.addError(e))\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useFormInputValidationHandler.js","sources":["../../../../../packages/react-form/src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>(undefined)\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tconst previousMessage = validationMessage.current\n\t\tvalidationMessage.current = message\n\n\t\tconst accessor = accessorGetter()\n\t\t// if there is no message, we want to clear the error\n\t\tif (!message) {\n\t\t\tif (previousMessage) {\n\t\t\t\tclearSpecificError(accessor, previousMessage)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (message === previousMessage) {\n\t\t\treturn\n\t\t}\n\t\t// if the input is not touched, we don't want to show the error message\n\t\tif (!field.isTouched) {\n\t\t\treturn\n\t\t}\n\n\t\t// if the input is not focused, we want to show the error message\n\t\t// also, even the input is focused, we want to replace the previous message\n\t\tif (!focus || !!previousMessage) {\n\t\t\taccessor.clearErrors()\n\t\t\taccessor.addError(message)\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n\nconst clearSpecificError = (field: FieldAccessor<any>, message: string) => {\n\tconst errors = field.errors?.errors ?? []\n\tconst error = errors.filter(e => !(e.type === 'validation' && e.message === message))\n\tfield.clearErrors()\n\terror.forEach(e => field.addError(e))\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoB,OAAe,MAAS;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,WAAW,MAAM,OAAyB,IAAI;AACpD,yBAAuB,YAAY,MAAM;AACxC,QAAI,kBAAkB,SAAS;AAC9B,uBAAiB,SAAS,kBAAkB,OAAO;AAAA,IACpD;AAAA,EACD,GAAG,CAAC,cAAc,CAAC,CAAC;AAEpB,YAAU,MAAM;AACf,QAAI,CAAC,SAAS,SAAS;AACtB;AAAA,IACD;AAEA,UAAM,QAAQ,SAAS;AACvB,UAAM,QAAQ,MAAM,UAAU;AAE9B,UAAM,UAAU,QAAQ,SAAY,OAAO;AAC3C,UAAM,kBAAkB,kBAAkB;AAC1C,sBAAkB,UAAU;AAE5B,UAAM,WAAW,eAAA;AAEjB,QAAI,CAAC,SAAS;AACb,UAAI,iBAAiB;AACpB,2BAAmB,UAAU,eAAe;AAAA,MAC7C;AACA;AAAA,IACD;AACA,QAAI,YAAY,iBAAiB;AAChC;AAAA,IACD;AAEA,QAAI,CAAC,MAAM,WAAW;AACrB;AAAA,IACD;AAIA,QAAI,CAAC,SAAS,CAAC,CAAC,iBAAiB;AAChC,eAAS,YAAA;AACT,eAAS,SAAS,OAAO;AAAA,IAC1B;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN,KAAK;AAAA,IACL,SAAS,YAAY,MAAM;AAC1B,eAAS,IAAI;AAAA,IACd,GAAG,CAAA,CAAE;AAAA,IACL,QAAQ,YAAY,MAAM;AACzB,eAAS,KAAK;AACd,qBAAA,EAAiB,YAAA;AACjB,UAAI,kBAAkB,SAAS;AAC9B,yBAAiB,SAAS,kBAAkB,OAAO;AAAA,MACpD;AAAA,IACD,GAAG,CAAC,cAAc,CAAC;AAAA,EAAA;AAErB;AAEA,MAAM,qBAAqB,CAAC,OAA2B,YAAoB;AAC1E,QAAM,SAAS,MAAM,QAAQ,UAAU,CAAA;AACvC,QAAM,QAAQ,OAAO,OAAO,CAAA,MAAK,EAAE,EAAE,SAAS,gBAAgB,EAAE,YAAY,QAAQ;AACpF,QAAM,YAAA;AACN,QAAM,QAAQ,CAAA,MAAK,MAAM,SAAS,CAAC,CAAC;AACrC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormInputHandler.cjs","sources":["../../../../../packages/react-form/src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport { useMemo } from 'react'\nimport { FormInputHandler } from '../types'\n\nexport const useFormInputHandler = (field: FieldAccessor, { formatValue, parseValue }: Partial<FormInputHandler>): FormInputHandler => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType] ?? defaultHandlerFactory\n\t\tconst handler = handlerFactory(schema, field.getAccessor)\n\t\treturn {\n\t\t\tdefaultInputProps: handler.defaultInputProps,\n\t\t\tformatValue: formatValue ?? handler.formatValue,\n\t\t\tparseValue: parseValue ?? handler.parseValue,\n\t\t}\n\t}, [field.getAccessor, field.schema, formatValue, parseValue])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler<any>\n\nconst defaultHandlerFactory: ColumnTypeHandlerFactory = (schema, field) => ({\n\tparseValue: (value: string) => {\n\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\treturn null\n\t\t}\n\t\treturn value\n\t},\n\tformatValue: (value: string | null) => value ?? '',\n})\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory | undefined> = {\n\tString: defaultHandlerFactory,\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: (): FormInputHandler<{ rawValue: string; parsedValue: number | null }> => ({\n\t\tparseValue: (value: string, ctx) => {\n\t\t\tif (value === '') {\n\t\t\t\tctx.setState({ rawValue: '', parsedValue: null })\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\tconst parsedValue = isNaN(parsed) ? null : parsed\n\t\t\tctx.setState({ rawValue: value, parsedValue })\n\t\t\treturn parsedValue\n\t\t},\n\t\tformatValue: (value: number | null, ctx) => {\n\t\t\tif (value === ctx.state?.parsedValue) {\n\t\t\t\treturn ctx.state.rawValue\n\t\t\t}\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString().split('T')[0]\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString()\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : toLocalDate(new Date(parsed))\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\treturn value ?? ''\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'time',\n\t\t},\n\t}),\n\tBool: undefined,\n\tEnum: undefined,\n\tUuid: undefined,\n}\n\nconst toLocalDate = (date: Date) => {\n\tconst pad = (num: number, length: number = 2) => {\n\t\tconst str = num.toString()\n\t\treturn '0'.repeat(Math.max(0, length - str.length)) + str\n\t}\n\n\treturn pad(date.getFullYear(), 4)
|
|
1
|
+
{"version":3,"file":"useFormInputHandler.cjs","sources":["../../../../../packages/react-form/src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport { useMemo } from 'react'\nimport { FormInputHandler } from '../types'\n\nexport const useFormInputHandler = (field: FieldAccessor, { formatValue, parseValue }: Partial<FormInputHandler>): FormInputHandler => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType] ?? defaultHandlerFactory\n\t\tconst handler = handlerFactory(schema, field.getAccessor)\n\t\treturn {\n\t\t\tdefaultInputProps: handler.defaultInputProps,\n\t\t\tformatValue: formatValue ?? handler.formatValue,\n\t\t\tparseValue: parseValue ?? handler.parseValue,\n\t\t}\n\t}, [field.getAccessor, field.schema, formatValue, parseValue])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler<any>\n\nconst defaultHandlerFactory: ColumnTypeHandlerFactory = (schema, field) => ({\n\tparseValue: (value: string) => {\n\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\treturn null\n\t\t}\n\t\treturn value\n\t},\n\tformatValue: (value: string | null) => value ?? '',\n})\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory | undefined> = {\n\tString: defaultHandlerFactory,\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: (): FormInputHandler<{ rawValue: string; parsedValue: number | null }> => ({\n\t\tparseValue: (value: string, ctx) => {\n\t\t\tif (value === '') {\n\t\t\t\tctx.setState({ rawValue: '', parsedValue: null })\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\tconst parsedValue = isNaN(parsed) ? null : parsed\n\t\t\tctx.setState({ rawValue: value, parsedValue })\n\t\t\treturn parsedValue\n\t\t},\n\t\tformatValue: (value: number | null, ctx) => {\n\t\t\tif (value === ctx.state?.parsedValue) {\n\t\t\t\treturn ctx.state.rawValue\n\t\t\t}\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString().split('T')[0]\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString()\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : toLocalDate(new Date(parsed))\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\treturn value ?? ''\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'time',\n\t\t},\n\t}),\n\tBool: undefined,\n\tEnum: undefined,\n\tUuid: undefined,\n}\n\nconst toLocalDate = (date: Date) => {\n\tconst pad = (num: number, length: number = 2) => {\n\t\tconst str = num.toString()\n\t\treturn '0'.repeat(Math.max(0, length - str.length)) + str\n\t}\n\n\treturn pad(date.getFullYear(), 4)\n\t\t+ '-' + pad(date.getMonth() + 1)\n\t\t+ '-' + pad(date.getDate())\n\t\t+ 'T' + pad(date.getHours())\n\t\t+ ':' + pad(date.getMinutes())\n\t\t+ ':' + pad(date.getSeconds())\n}\n"],"names":["useMemo"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormInputHandler.js","sources":["../../../../../packages/react-form/src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport { useMemo } from 'react'\nimport { FormInputHandler } from '../types'\n\nexport const useFormInputHandler = (field: FieldAccessor, { formatValue, parseValue }: Partial<FormInputHandler>): FormInputHandler => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType] ?? defaultHandlerFactory\n\t\tconst handler = handlerFactory(schema, field.getAccessor)\n\t\treturn {\n\t\t\tdefaultInputProps: handler.defaultInputProps,\n\t\t\tformatValue: formatValue ?? handler.formatValue,\n\t\t\tparseValue: parseValue ?? handler.parseValue,\n\t\t}\n\t}, [field.getAccessor, field.schema, formatValue, parseValue])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler<any>\n\nconst defaultHandlerFactory: ColumnTypeHandlerFactory = (schema, field) => ({\n\tparseValue: (value: string) => {\n\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\treturn null\n\t\t}\n\t\treturn value\n\t},\n\tformatValue: (value: string | null) => value ?? '',\n})\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory | undefined> = {\n\tString: defaultHandlerFactory,\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: (): FormInputHandler<{ rawValue: string; parsedValue: number | null }> => ({\n\t\tparseValue: (value: string, ctx) => {\n\t\t\tif (value === '') {\n\t\t\t\tctx.setState({ rawValue: '', parsedValue: null })\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\tconst parsedValue = isNaN(parsed) ? null : parsed\n\t\t\tctx.setState({ rawValue: value, parsedValue })\n\t\t\treturn parsedValue\n\t\t},\n\t\tformatValue: (value: number | null, ctx) => {\n\t\t\tif (value === ctx.state?.parsedValue) {\n\t\t\t\treturn ctx.state.rawValue\n\t\t\t}\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString().split('T')[0]\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString()\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : toLocalDate(new Date(parsed))\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\treturn value ?? ''\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'time',\n\t\t},\n\t}),\n\tBool: undefined,\n\tEnum: undefined,\n\tUuid: undefined,\n}\n\nconst toLocalDate = (date: Date) => {\n\tconst pad = (num: number, length: number = 2) => {\n\t\tconst str = num.toString()\n\t\treturn '0'.repeat(Math.max(0, length - str.length)) + str\n\t}\n\n\treturn pad(date.getFullYear(), 4)
|
|
1
|
+
{"version":3,"file":"useFormInputHandler.js","sources":["../../../../../packages/react-form/src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport { useMemo } from 'react'\nimport { FormInputHandler } from '../types'\n\nexport const useFormInputHandler = (field: FieldAccessor, { formatValue, parseValue }: Partial<FormInputHandler>): FormInputHandler => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType] ?? defaultHandlerFactory\n\t\tconst handler = handlerFactory(schema, field.getAccessor)\n\t\treturn {\n\t\t\tdefaultInputProps: handler.defaultInputProps,\n\t\t\tformatValue: formatValue ?? handler.formatValue,\n\t\t\tparseValue: parseValue ?? handler.parseValue,\n\t\t}\n\t}, [field.getAccessor, field.schema, formatValue, parseValue])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler<any>\n\nconst defaultHandlerFactory: ColumnTypeHandlerFactory = (schema, field) => ({\n\tparseValue: (value: string) => {\n\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\treturn null\n\t\t}\n\t\treturn value\n\t},\n\tformatValue: (value: string | null) => value ?? '',\n})\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory | undefined> = {\n\tString: defaultHandlerFactory,\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: (): FormInputHandler<{ rawValue: string; parsedValue: number | null }> => ({\n\t\tparseValue: (value: string, ctx) => {\n\t\t\tif (value === '') {\n\t\t\t\tctx.setState({ rawValue: '', parsedValue: null })\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\tconst parsedValue = isNaN(parsed) ? null : parsed\n\t\t\tctx.setState({ rawValue: value, parsedValue })\n\t\t\treturn parsedValue\n\t\t},\n\t\tformatValue: (value: number | null, ctx) => {\n\t\t\tif (value === ctx.state?.parsedValue) {\n\t\t\t\treturn ctx.state.rawValue\n\t\t\t}\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString().split('T')[0]\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : (new Date(parsed)).toISOString()\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : toLocalDate(new Date(parsed))\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\treturn value ?? ''\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'time',\n\t\t},\n\t}),\n\tBool: undefined,\n\tEnum: undefined,\n\tUuid: undefined,\n}\n\nconst toLocalDate = (date: Date) => {\n\tconst pad = (num: number, length: number = 2) => {\n\t\tconst str = num.toString()\n\t\treturn '0'.repeat(Math.max(0, length - str.length)) + str\n\t}\n\n\treturn pad(date.getFullYear(), 4)\n\t\t+ '-' + pad(date.getMonth() + 1)\n\t\t+ '-' + pad(date.getDate())\n\t\t+ 'T' + pad(date.getHours())\n\t\t+ ':' + pad(date.getMinutes())\n\t\t+ ':' + pad(date.getSeconds())\n}\n"],"names":[],"mappings":";AAIO,MAAM,sBAAsB,CAAC,OAAsB,EAAE,aAAa,iBAA8D;AACtI,SAAO,QAAQ,MAAM;AACpB,UAAM,SAAS,MAAM;AACrB,UAAM,aAAa,OAAO;AAC1B,UAAM,iBAAiB,2BAA2B,UAAmC,KAAK;AAC1F,UAAM,UAAU,eAAe,QAAQ,MAAM,WAAW;AACxD,WAAO;AAAA,MACN,mBAAmB,QAAQ;AAAA,MAC3B,aAAa,eAAe,QAAQ;AAAA,MACpC,YAAY,cAAc,QAAQ;AAAA,IAAA;AAAA,EAEpC,GAAG,CAAC,MAAM,aAAa,MAAM,QAAQ,aAAa,UAAU,CAAC;AAC9D;AAIA,MAAM,wBAAkD,CAAC,QAAQ,WAAW;AAAA,EAC3E,YAAY,CAAC,UAAkB;AAC9B,QAAI,UAAU,MAAM,OAAO,YAAY,MAAA,EAAQ,kBAAkB,MAAM;AACtE,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR;AAAA,EACA,aAAa,CAAC,UAAyB,SAAS;AACjD;AAEA,MAAM,6BAAkG;AAAA,EACvG,QAAQ;AAAA,EACR,SAAS,OAAO;AAAA,IACf,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACjB,eAAO;AAAA,MACR;AACA,YAAM,SAAS,SAAS,OAAO,EAAE;AACjC,aAAO,MAAM,MAAM,IAAI,OAAO;AAAA,IAC/B;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,aAAO,UAAU,OAAO,KAAK,MAAM,SAAS,EAAE;AAAA,IAC/C;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACP;AAAA,EAED,QAAQ,OAA2E;AAAA,IAClF,YAAY,CAAC,OAAe,QAAQ;AACnC,UAAI,UAAU,IAAI;AACjB,YAAI,SAAS,EAAE,UAAU,IAAI,aAAa,MAAM;AAChD,eAAO;AAAA,MACR;AACA,YAAM,SAAS,WAAW,KAAK;AAC/B,YAAM,cAAc,MAAM,MAAM,IAAI,OAAO;AAC3C,UAAI,SAAS,EAAE,UAAU,OAAO,aAAa;AAC7C,aAAO;AAAA,IACR;AAAA,IACA,aAAa,CAAC,OAAsB,QAAQ;AAC3C,UAAI,UAAU,IAAI,OAAO,aAAa;AACrC,eAAO,IAAI,MAAM;AAAA,MAClB;AACA,aAAO,UAAU,OAAO,KAAK,MAAM,SAAS,EAAE;AAAA,IAC/C;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACP;AAAA,EAGD,MAAM,OAAO;AAAA,IACZ,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACjB,eAAO;AAAA,MACR;AACA,YAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,aAAO,MAAM,MAAM,IAAI,OAAQ,IAAI,KAAK,MAAM,EAAG,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC;AAAA,IAC5E;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,YAAM,SAAS,QAAQ,KAAK,MAAM,KAAK,IAAI;AAC3C,aAAO,CAAC,UAAU,MAAM,MAAM,IAAI,KAAK,IAAI,KAAK,MAAM,EAAE,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC;AAAA,IACnF;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACP;AAAA,EAED,UAAU,OAAO;AAAA,IAChB,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACjB,eAAO;AAAA,MACR;AAEA,YAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,aAAO,MAAM,MAAM,IAAI,OAAQ,IAAI,KAAK,MAAM,EAAG,YAAA;AAAA,IAClD;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,YAAM,SAAS,QAAQ,KAAK,MAAM,KAAK,IAAI;AAC3C,aAAO,CAAC,UAAU,MAAM,MAAM,IAAI,KAAK,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IACpE;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACP;AAAA,EAED,MAAM,OAAO;AAAA,IACZ,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACjB,eAAO;AAAA,MACR;AACA,aAAO;AAAA,IACR;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,aAAO,SAAS;AAAA,IACjB;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACP;AAAA,EAED,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACP;AAEA,MAAM,cAAc,CAAC,SAAe;AACnC,QAAM,MAAM,CAAC,KAAa,SAAiB,MAAM;AAChD,UAAM,MAAM,IAAI,SAAA;AAChB,WAAO,IAAI,OAAO,KAAK,IAAI,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI;AAAA,EACvD;AAEA,SAAO,IAAI,KAAK,YAAA,GAAe,CAAC,IAC7B,MAAM,IAAI,KAAK,aAAa,CAAC,IAC7B,MAAM,IAAI,KAAK,QAAA,CAAS,IACxB,MAAM,IAAI,KAAK,SAAA,CAAU,IACzB,MAAM,IAAI,KAAK,WAAA,CAAY,IAC3B,MAAM,IAAI,KAAK,YAAY;AAC/B;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const contexts = require("./src/contexts.cjs");
|
|
4
|
-
const FormError = require("./src/components/FormError.cjs");
|
|
5
4
|
const FormCheckbox = require("./src/components/FormCheckbox.cjs");
|
|
6
|
-
const
|
|
5
|
+
const FormError = require("./src/components/FormError.cjs");
|
|
7
6
|
const FormFieldStateProvider = require("./src/components/FormFieldStateProvider.cjs");
|
|
8
|
-
const
|
|
7
|
+
const FormFieldScope = require("./src/components/FormFieldScope.cjs");
|
|
9
8
|
const FormHasManyRelationScope = require("./src/components/FormHasManyRelationScope.cjs");
|
|
9
|
+
const FormHasOneRelationScope = require("./src/components/FormHasOneRelationScope.cjs");
|
|
10
10
|
const FormInput = require("./src/components/FormInput.cjs");
|
|
11
11
|
const FormLabel = require("./src/components/FormLabel.cjs");
|
|
12
12
|
const FormRadioInput = require("./src/components/FormRadioInput.cjs");
|
|
@@ -15,14 +15,14 @@ exports.FormFieldStateContext = contexts.FormFieldStateContext;
|
|
|
15
15
|
exports.useFormError = contexts.useFormError;
|
|
16
16
|
exports.useFormFieldId = contexts.useFormFieldId;
|
|
17
17
|
exports.useFormFieldState = contexts.useFormFieldState;
|
|
18
|
-
exports.FormError = FormError.FormError;
|
|
19
18
|
exports.FormCheckbox = FormCheckbox.FormCheckbox;
|
|
20
|
-
exports.
|
|
19
|
+
exports.FormError = FormError.FormError;
|
|
21
20
|
exports.FormErrorContext = FormFieldStateProvider.FormErrorContext;
|
|
22
21
|
exports.FormFieldIdContext = FormFieldStateProvider.FormFieldIdContext;
|
|
23
22
|
exports.FormFieldStateProvider = FormFieldStateProvider.FormFieldStateProvider;
|
|
24
|
-
exports.
|
|
23
|
+
exports.FormFieldScope = FormFieldScope.FormFieldScope;
|
|
25
24
|
exports.FormHasManyRelationScope = FormHasManyRelationScope.FormHasManyRelationScope;
|
|
25
|
+
exports.FormHasOneRelationScope = FormHasOneRelationScope.FormHasOneRelationScope;
|
|
26
26
|
exports.FormInput = FormInput.FormInput;
|
|
27
27
|
exports.FormLabel = FormLabel.FormLabel;
|
|
28
28
|
exports.FormRadioInput = FormRadioInput.FormRadioInput;
|
package/dist/production/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FormFieldStateContext, useFormError, useFormFieldId, useFormFieldState } from "./src/contexts.js";
|
|
2
|
-
import { FormError } from "./src/components/FormError.js";
|
|
3
2
|
import { FormCheckbox } from "./src/components/FormCheckbox.js";
|
|
4
|
-
import {
|
|
3
|
+
import { FormError } from "./src/components/FormError.js";
|
|
5
4
|
import { FormErrorContext, FormFieldIdContext, FormFieldStateProvider } from "./src/components/FormFieldStateProvider.js";
|
|
6
|
-
import {
|
|
5
|
+
import { FormFieldScope } from "./src/components/FormFieldScope.js";
|
|
7
6
|
import { FormHasManyRelationScope } from "./src/components/FormHasManyRelationScope.js";
|
|
7
|
+
import { FormHasOneRelationScope } from "./src/components/FormHasOneRelationScope.js";
|
|
8
8
|
import { FormInput } from "./src/components/FormInput.js";
|
|
9
9
|
import { FormLabel } from "./src/components/FormLabel.js";
|
|
10
10
|
import { FormRadioInput } from "./src/components/FormRadioInput.js";
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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\t// biome-ignore lint/correctness/useExhaustiveDependencies: intentional\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,UAAAA;AASX,MAAM,eAAeC,aAAAA,UAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AAC7G,QAAM,WAAWC,aAAAA,SAAkB,KAAK;AAExC,QAAM,YAAYC,SAAAA,kBAAA;AAClB,QAAM,KAAK,WAAW;AACtB,QAAM,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACvF,QAAM,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,QAAQ,SAAS;AACvB,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAA,IAAWC,8BAAAA,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAIC,iBAAM,SAAkC,IAAI;AAGlFC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACA,gBAAY,gBAAgB,UAAU;AAAA,EACvC,GAAG,CAAC,aAAa,KAAK,KAAK,CAAC;AAE5B,SACCC,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK,CAAA,OAAM;AACR,YAAY,UAAU;AACxB,uBAAe,EAAE;AAAA,MAClB;AAAA,MACA,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAcC,UAAAA,cAAc,SAAS;AAAA,MACrC,cAAYA,UAAAA,cAAc,KAAK;AAAA,MAC/B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACA;AAAA,MACA,UAAUC,MAAAA,YAAkD,CAAA,MAAK;AAChE,uBAAA,EAAiB,YAAY,EAAE,OAAO,OAAO;AAAA,MAC9C,GAAG,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAClD,QAAM,OAAOC,aAAAA,2BAA2B,0BAA0B,KAAK,EAAE,MAAA,CAAO,EAAE,eAAA;AAClF,QAAM,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAOH,2BAAAA,IAACI,aAAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,sBAAsB;AAC7F,CAAC;;"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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\t// biome-ignore lint/correctness/useExhaustiveDependencies: intentional\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;AASX,MAAM,eAAe,UAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AAC7G,QAAM,WAAW,SAAkB,KAAK;AAExC,QAAM,YAAY,kBAAA;AAClB,QAAM,KAAK,WAAW;AACtB,QAAM,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACvF,QAAM,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,QAAQ,SAAS;AACvB,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAA,IAAW,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAAkC,IAAI;AAGlF,YAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACA,gBAAY,gBAAgB,UAAU;AAAA,EACvC,GAAG,CAAC,aAAa,KAAK,KAAK,CAAC;AAE5B,SACC;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK,CAAA,OAAM;AACR,YAAY,UAAU;AACxB,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,CAAA,MAAK;AAChE,uBAAA,EAAiB,YAAY,EAAE,OAAO,OAAO;AAAA,MAC9C,GAAG,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAClD,QAAM,OAAO,2BAA2B,0BAA0B,KAAK,EAAE,MAAA,CAAO,EAAE,eAAA;AAClF,QAAM,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAO,oBAAC,OAAA,EAAM,OAAc,cAA4B,cAAc,sBAAsB;AAC7F,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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<any>\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,kBAAA;AAClB,MAAI,CAAC,WAAW;AACf,UAAM,IAAIC,aAAAA,aAAa,2CAA2C;AAAA,EACnE;AACA,QAAM,EAAE,QAAQ,OAAA,IAAW;AAC3B,QAAM,YAAYC,MAAAA,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,WAAOC,MAAAA,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAI,SAAS,EAAE,IAAI,GAAG,MAAM,UAAU,KAAK,GAAA,IAAO,CAAA;AAAA,MAClD,UAAU;AAAA,IAAA,CACV;AAAA,EACF,CAAC;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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<any>\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,kBAAA;AAClB,MAAI,CAAC,WAAW;AACf,UAAM,IAAI,aAAa,2CAA2C;AAAA,EACnE;AACA,QAAM,EAAE,QAAQ,OAAA,IAAW;AAC3B,QAAM,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,GAAA,IAAO,CAAA;AAAA,MAClD,UAAU;AAAA,IAAA,CACV;AAAA,EACF,CAAC;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AACxC,QAAM,aAAa,cAAc,UAAA,EAAY;AAC7C,QAAM,YAAY,cAAc;AAChC,QAAM,WAAW,cAAc,OAAO,YAAY;AAClD,QAAM,YAAYC,MAAAA,QAAQ,OAAO,EAAE,YAAY,WAAW,SAAA,IAAa,CAAC,YAAY,WAAW,QAAQ,CAAC;AAExG,SACCC,2BAAAA;AAAAA,IAACC,uBAAAA;AAAAA,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,EAAA;AAGJ;;"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AACxC,QAAM,aAAa,cAAc,UAAA,EAAY;AAC7C,QAAM,YAAY,cAAc;AAChC,QAAM,WAAW,cAAc,OAAO,YAAY;AAClD,QAAM,YAAY,QAAQ,OAAO,EAAE,YAAY,WAAW,SAAA,IAAa,CAAC,YAAY,WAAW,QAAQ,CAAC;AAExG,SACC;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,EAAA;AAGJ;"}
|
|
@@ -1 +1 @@
|
|
|
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\
|
|
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\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\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,CAAA;AAQd,MAAM,yBAAyB,CAAC,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,QAAQ,OAAO,QAAQ,MAAA,MAAoC;AAClJ,QAAM,cAAcA,MAAAA,MAAA;AACpB,aAAA,SAAW;AACX,QAAM,QAAQC,MAAAA,QAAQ,OAAO,EAAE,QAAQ,UAAU,QAAQ,OAAO,MAAA,IAAU,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,kBAAA;AAMd,0CACE,wBAAA,EAAwB,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;AAKO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAI/B,UAAU,CAAC,EAAE,UAAU,YAAyE;AAC/F,UAAM,QAAQA,SAAAA,kBAAA;AAMd,0CACE,wBAAA,EAAwB,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useId, useMemo } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { useFormFieldState, FormFieldStateContext } from "../contexts.js";
|
|
4
4
|
const emptyArr = [];
|
|
5
5
|
const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }) => {
|
|
6
6
|
const generatedId = useId();
|
|
@@ -1 +1 @@
|
|
|
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\
|
|
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\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\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,CAAA;AAQd,MAAM,yBAAyB,CAAC,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,QAAQ,OAAO,QAAQ,MAAA,MAAoC;AAClJ,QAAM,cAAc,MAAA;AACpB,aAAA,SAAW;AACX,QAAM,QAAQ,QAAQ,OAAO,EAAE,QAAQ,UAAU,QAAQ,OAAO,MAAA,IAAU,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,kBAAA;AAMd,+BACE,wBAAA,EAAwB,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;AAKO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAI/B,UAAU,CAAC,EAAE,UAAU,YAAyE;AAC/F,UAAM,QAAQ,kBAAA;AAMd,+BACE,wBAAA,EAAwB,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAC5G,QAAM,iBAAiBA,aAAAA,cAAc,KAAK;AAC1C,QAAM,aAAa,eAAe,UAAA,EAAa;AAC/C,QAAM,SAAS,eAAe,UAAA;AAC9B,QAAM,YAAY,OAAO,WAAW;AACpC,QAAM,YAAYC,cAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AAEpF,SACCC,2BAAAA;AAAAA,IAACC,uBAAAA;AAAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;;"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAC5G,QAAM,iBAAiB,cAAc,KAAK;AAC1C,QAAM,aAAa,eAAe,UAAA,EAAa;AAC/C,QAAM,SAAS,eAAe,UAAA;AAC9B,QAAM,YAAY,OAAO,WAAW;AACpC,QAAM,YAAY,QAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AAEpF,SACC;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAC1C,QAAM,SAAS,eAAe,UAAA;AAC9B,QAAM,YAAY,OAAO,WAAW;AACpC,QAAM,aAAa,eAAe,UAAA,EAAa;AAC/C,QAAM,YAAYC,cAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AACpF,SACCC,2BAAAA;AAAAA,IAACC,uBAAAA;AAAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;;"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAC1C,QAAM,SAAS,eAAe,UAAA;AAC9B,QAAM,YAAY,OAAO,WAAW;AACpC,QAAM,aAAa,eAAe,UAAA,EAAa;AAC/C,QAAM,YAAY,QAAQ,OAAO,EAAE,YAAY,cAAc,CAAC,YAAY,SAAS,CAAC;AACpF,SACC;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
|