@form-os/react 0.4.0 → 0.5.0

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.
@@ -1,15 +1,14 @@
1
1
  import * as react from 'react';
2
2
  import { ComponentType } from 'react';
3
- import { FieldValues, Control, RegisterOptions } from 'react-hook-form';
3
+ import { FieldValues, Control } from 'react-hook-form';
4
4
  import { FieldConfig } from '@form-os/core';
5
5
 
6
6
  interface FieldProps<TFieldValues extends FieldValues = FieldValues> {
7
7
  field: FieldConfig;
8
8
  control: Control<TFieldValues>;
9
9
  component?: ComponentType<any>;
10
- rules?: RegisterOptions;
11
10
  [key: string]: any;
12
11
  }
13
- declare function Field<TFieldValues extends FieldValues = FieldValues>({ field, control, component, rules, ...rest }: FieldProps<TFieldValues>): react.JSX.Element | null;
12
+ declare function Field<TFieldValues extends FieldValues = FieldValues>({ field, control, component, ...rest }: FieldProps<TFieldValues>): react.JSX.Element | null;
14
13
 
15
14
  export { type FieldProps as F, Field as a };
@@ -1,15 +1,14 @@
1
1
  import * as react from 'react';
2
2
  import { ComponentType } from 'react';
3
- import { FieldValues, Control, RegisterOptions } from 'react-hook-form';
3
+ import { FieldValues, Control } from 'react-hook-form';
4
4
  import { FieldConfig } from '@form-os/core';
5
5
 
6
6
  interface FieldProps<TFieldValues extends FieldValues = FieldValues> {
7
7
  field: FieldConfig;
8
8
  control: Control<TFieldValues>;
9
9
  component?: ComponentType<any>;
10
- rules?: RegisterOptions;
11
10
  [key: string]: any;
12
11
  }
13
- declare function Field<TFieldValues extends FieldValues = FieldValues>({ field, control, component, rules, ...rest }: FieldProps<TFieldValues>): react.JSX.Element | null;
12
+ declare function Field<TFieldValues extends FieldValues = FieldValues>({ field, control, component, ...rest }: FieldProps<TFieldValues>): react.JSX.Element | null;
14
13
 
15
14
  export { type FieldProps as F, Field as a };
@@ -2,7 +2,7 @@
2
2
  import { useMemo } from "react";
3
3
  import { useController, useWatch } from "react-hook-form";
4
4
  import { getFieldState } from "@form-os/core";
5
- function useField(field, control, options = {}) {
5
+ function useField(field, control) {
6
6
  const values = useWatch({ control });
7
7
  const state = useMemo(
8
8
  () => getFieldState(field, values ?? {}),
@@ -11,8 +11,8 @@ function useField(field, control, options = {}) {
11
11
  const { field: f, fieldState } = useController({
12
12
  name: field.name,
13
13
  control,
14
- rules: options.rules ?? field.rules,
15
- defaultValue: options.defaultValue ?? field.defaultValue,
14
+ rules: field?.rules,
15
+ defaultValue: field?.defaultValue,
16
16
  disabled: state.disabled
17
17
  });
18
18
  return { field: f, fieldState, state };
@@ -35,12 +35,11 @@ function Field({
35
35
  field,
36
36
  control,
37
37
  component,
38
- rules,
39
38
  ...rest
40
39
  }) {
41
40
  const contextComponents = useFieldComponents();
42
41
  const Component = component ?? contextComponents[field.type] ?? contextComponents["text"];
43
- const { field: f, fieldState, state } = useField(field, control, { rules });
42
+ const { field: f, fieldState, state } = useField(field, control);
44
43
  if (!state.visible) {
45
44
  return null;
46
45
  }
@@ -64,4 +63,4 @@ export {
64
63
  useFieldComponents,
65
64
  Field
66
65
  };
67
- //# sourceMappingURL=chunk-IHVV2WZM.js.map
66
+ //# sourceMappingURL=chunk-V2X6FW6I.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useField.ts","../src/FormFieldsContext.tsx","../src/Field.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { useController, useWatch } from 'react-hook-form';\nimport type { Control, FieldPath, FieldValues, RegisterOptions } from 'react-hook-form';\nimport { getFieldState, type FieldConfig } from '@form-os/core';\n\nexport function useField<TFieldValues extends FieldValues = FieldValues>(\n field: FieldConfig,\n control: Control<TFieldValues>\n) {\n const values = useWatch({ control }) as Record<string, any>;\n\n const state = useMemo(\n () => getFieldState(field, values ?? {}),\n [field, values]\n );\n\n const { field: f, fieldState } = useController<TFieldValues>({\n name: field.name as FieldPath<TFieldValues>,\n control,\n rules: (field?.rules) as RegisterOptions<TFieldValues> | undefined,\n defaultValue: field?.defaultValue,\n disabled: state.disabled,\n });\n\n return { field: f, fieldState, state };\n}\n","import { createContext, useContext } from 'react';\nimport type { ComponentType, ReactNode } from 'react';\n\nexport type ComponentsMap = Record<string, ComponentType<any>>;\n\nconst FormFieldsContext = createContext<ComponentsMap>({});\n\nexport interface FormFieldsProviderProps {\n components: ComponentsMap;\n children: ReactNode;\n}\n\nexport function FormFieldsProvider({ components, children }: FormFieldsProviderProps) {\n return (\n <FormFieldsContext.Provider value={components}>\n {children}\n </FormFieldsContext.Provider>\n );\n}\n\nexport function useFieldComponents(): ComponentsMap {\n return useContext(FormFieldsContext);\n}\n","import type { ComponentType } from 'react';\nimport type { Control, FieldValues } from 'react-hook-form';\nimport type { FieldConfig } from '@form-os/core';\nimport { useField } from './useField';\nimport { useFieldComponents } from './FormFieldsContext';\n\nexport interface FieldProps<TFieldValues extends FieldValues = FieldValues> {\n field: FieldConfig;\n control: Control<TFieldValues>;\n component?: ComponentType<any>;\n [key: string]: any;\n}\n\nexport function Field<TFieldValues extends FieldValues = FieldValues>({\n field,\n control,\n component,\n ...rest\n}: FieldProps<TFieldValues>) {\n const contextComponents = useFieldComponents();\n const Component = component ?? contextComponents[field.type] ?? contextComponents['text'];\n const { field: f, fieldState, state } = useField(field, control);\n\n if (!state.visible) {\n return null;\n }\n\n return (\n <Component\n formField={f}\n fieldConfig={field}\n fieldState={state}\n error={fieldState.error}\n disabled={state.disabled}\n readonly={state.readonly}\n {...rest}\n />\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,eAAe,gBAAgB;AAExC,SAAS,qBAAuC;AAEzC,SAAS,SACd,OACA,SACA;AACA,QAAM,SAAS,SAAS,EAAE,QAAQ,CAAC;AAEnC,QAAM,QAAQ;AAAA,IACZ,MAAM,cAAc,OAAO,UAAU,CAAC,CAAC;AAAA,IACvC,CAAC,OAAO,MAAM;AAAA,EAChB;AAEA,QAAM,EAAE,OAAO,GAAG,WAAW,IAAI,cAA4B;AAAA,IAC3D,MAAM,MAAM;AAAA,IACZ;AAAA,IACA,OAAQ,OAAO;AAAA,IACf,cAAc,OAAO;AAAA,IACrB,UAAU,MAAM;AAAA,EAClB,CAAC;AAED,SAAO,EAAE,OAAO,GAAG,YAAY,MAAM;AACvC;;;ACzBA,SAAS,eAAe,kBAAkB;AActC;AATJ,IAAM,oBAAoB,cAA6B,CAAC,CAAC;AAOlD,SAAS,mBAAmB,EAAE,YAAY,SAAS,GAA4B;AACpF,SACE,oBAAC,kBAAkB,UAAlB,EAA2B,OAAO,YAChC,UACH;AAEJ;AAEO,SAAS,qBAAoC;AAClD,SAAO,WAAW,iBAAiB;AACrC;;;ACMI,gBAAAA,YAAA;AAfG,SAAS,MAAsD;AAAA,EACpE;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA6B;AAC3B,QAAM,oBAAoB,mBAAmB;AAC7C,QAAM,YAAY,aAAa,kBAAkB,MAAM,IAAI,KAAK,kBAAkB,MAAM;AACxF,QAAM,EAAE,OAAO,GAAG,YAAY,MAAM,IAAI,SAAS,OAAO,OAAO;AAE/D,MAAI,CAAC,MAAM,SAAS;AAClB,WAAO;AAAA,EACT;AAEA,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,MACX,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,OAAO,WAAW;AAAA,MAClB,UAAU,MAAM;AAAA,MAChB,UAAU,MAAM;AAAA,MACf,GAAG;AAAA;AAAA,EACN;AAEJ;","names":["jsx"]}
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/useField.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/useField.ts
2
2
  var _react = require('react');
3
3
  var _reacthookform = require('react-hook-form');
4
4
  var _core = require('@form-os/core');
5
- function useField(field, control, options = {}) {
5
+ function useField(field, control) {
6
6
  const values = _reacthookform.useWatch.call(void 0, { control });
7
7
  const state = _react.useMemo.call(void 0,
8
8
  () => _core.getFieldState.call(void 0, field, _nullishCoalesce(values, () => ( {}))),
@@ -11,8 +11,8 @@ function useField(field, control, options = {}) {
11
11
  const { field: f, fieldState } = _reacthookform.useController.call(void 0, {
12
12
  name: field.name,
13
13
  control,
14
- rules: _nullishCoalesce(options.rules, () => ( field.rules)),
15
- defaultValue: _nullishCoalesce(options.defaultValue, () => ( field.defaultValue)),
14
+ rules: _optionalChain([field, 'optionalAccess', _ => _.rules]),
15
+ defaultValue: _optionalChain([field, 'optionalAccess', _2 => _2.defaultValue]),
16
16
  disabled: state.disabled
17
17
  });
18
18
  return { field: f, fieldState, state };
@@ -35,12 +35,11 @@ function Field({
35
35
  field,
36
36
  control,
37
37
  component,
38
- rules,
39
38
  ...rest
40
39
  }) {
41
40
  const contextComponents = useFieldComponents();
42
41
  const Component = _nullishCoalesce(_nullishCoalesce(component, () => ( contextComponents[field.type])), () => ( contextComponents["text"]));
43
- const { field: f, fieldState, state } = useField(field, control, { rules });
42
+ const { field: f, fieldState, state } = useField(field, control);
44
43
  if (!state.visible) {
45
44
  return null;
46
45
  }
@@ -64,4 +63,4 @@ function Field({
64
63
 
65
64
 
66
65
  exports.useField = useField; exports.FormFieldsProvider = FormFieldsProvider; exports.useFieldComponents = useFieldComponents; exports.Field = Field;
67
- //# sourceMappingURL=chunk-3PMQZRSQ.cjs.map
66
+ //# sourceMappingURL=chunk-X5G3JO5T.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/abeleko/Documents/larven/formjs/packages/react/dist/chunk-X5G3JO5T.cjs","../src/useField.ts","../src/FormFieldsContext.tsx","../src/Field.tsx"],"names":["jsx"],"mappings":"AAAA;ACAA,8BAAwB;AACxB,gDAAwC;AAExC,qCAAgD;AAEzC,SAAS,QAAA,CACd,KAAA,EACA,OAAA,EACA;AACA,EAAA,MAAM,OAAA,EAAS,qCAAA,EAAW,QAAQ,CAAC,CAAA;AAEnC,EAAA,MAAM,MAAA,EAAQ,4BAAA;AAAA,IACZ,CAAA,EAAA,GAAM,iCAAA,KAAc,mBAAO,MAAA,UAAU,CAAC,GAAC,CAAA;AAAA,IACvC,CAAC,KAAA,EAAO,MAAM;AAAA,EAChB,CAAA;AAEA,EAAA,MAAM,EAAE,KAAA,EAAO,CAAA,EAAG,WAAW,EAAA,EAAI,0CAAA;AAA4B,IAC3D,IAAA,EAAM,KAAA,CAAM,IAAA;AAAA,IACZ,OAAA;AAAA,IACA,KAAA,kBAAQ,KAAA,2BAAO,OAAA;AAAA,IACf,YAAA,kBAAc,KAAA,6BAAO,cAAA;AAAA,IACrB,QAAA,EAAU,KAAA,CAAM;AAAA,EAClB,CAAC,CAAA;AAED,EAAA,OAAO,EAAE,KAAA,EAAO,CAAA,EAAG,UAAA,EAAY,MAAM,CAAA;AACvC;ADNA;AACA;AEpBA;AAcI,+CAAA;AATJ,IAAM,kBAAA,EAAoB,kCAAA,CAA8B,CAAC,CAAA;AAOlD,SAAS,kBAAA,CAAmB,EAAE,UAAA,EAAY,SAAS,CAAA,EAA4B;AACpF,EAAA,uBACE,6BAAA,iBAAC,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,UAAA,EAChC,SAAA,CACH,CAAA;AAEJ;AAEO,SAAS,kBAAA,CAAA,EAAoC;AAClD,EAAA,OAAO,+BAAA,iBAA4B,CAAA;AACrC;AFQA;AACA;AGHI;AAfG,SAAS,KAAA,CAAsD;AAAA,EACpE,KAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,EAA6B;AAC3B,EAAA,MAAM,kBAAA,EAAoB,kBAAA,CAAmB,CAAA;AAC7C,EAAA,MAAM,UAAA,oCAAY,SAAA,UAAa,iBAAA,CAAkB,KAAA,CAAM,IAAI,GAAA,UAAK,iBAAA,CAAkB,MAAM,GAAA;AACxF,EAAA,MAAM,EAAE,KAAA,EAAO,CAAA,EAAG,UAAA,EAAY,MAAM,EAAA,EAAI,QAAA,CAAS,KAAA,EAAO,OAAO,CAAA;AAE/D,EAAA,GAAA,CAAI,CAAC,KAAA,CAAM,OAAA,EAAS;AAClB,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,uBACEA,6BAAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,CAAA;AAAA,MACX,WAAA,EAAa,KAAA;AAAA,MACb,UAAA,EAAY,KAAA;AAAA,MACZ,KAAA,EAAO,UAAA,CAAW,KAAA;AAAA,MAClB,QAAA,EAAU,KAAA,CAAM,QAAA;AAAA,MAChB,QAAA,EAAU,KAAA,CAAM,QAAA;AAAA,MACf,GAAG;AAAA,IAAA;AAAA,EACN,CAAA;AAEJ;AHoBA;AACA;AACE;AACA;AACA;AACA;AACF,qJAAC","file":"/Users/abeleko/Documents/larven/formjs/packages/react/dist/chunk-X5G3JO5T.cjs","sourcesContent":[null,"import { useMemo } from 'react';\nimport { useController, useWatch } from 'react-hook-form';\nimport type { Control, FieldPath, FieldValues, RegisterOptions } from 'react-hook-form';\nimport { getFieldState, type FieldConfig } from '@form-os/core';\n\nexport function useField<TFieldValues extends FieldValues = FieldValues>(\n field: FieldConfig,\n control: Control<TFieldValues>\n) {\n const values = useWatch({ control }) as Record<string, any>;\n\n const state = useMemo(\n () => getFieldState(field, values ?? {}),\n [field, values]\n );\n\n const { field: f, fieldState } = useController<TFieldValues>({\n name: field.name as FieldPath<TFieldValues>,\n control,\n rules: (field?.rules) as RegisterOptions<TFieldValues> | undefined,\n defaultValue: field?.defaultValue,\n disabled: state.disabled,\n });\n\n return { field: f, fieldState, state };\n}\n","import { createContext, useContext } from 'react';\nimport type { ComponentType, ReactNode } from 'react';\n\nexport type ComponentsMap = Record<string, ComponentType<any>>;\n\nconst FormFieldsContext = createContext<ComponentsMap>({});\n\nexport interface FormFieldsProviderProps {\n components: ComponentsMap;\n children: ReactNode;\n}\n\nexport function FormFieldsProvider({ components, children }: FormFieldsProviderProps) {\n return (\n <FormFieldsContext.Provider value={components}>\n {children}\n </FormFieldsContext.Provider>\n );\n}\n\nexport function useFieldComponents(): ComponentsMap {\n return useContext(FormFieldsContext);\n}\n","import type { ComponentType } from 'react';\nimport type { Control, FieldValues } from 'react-hook-form';\nimport type { FieldConfig } from '@form-os/core';\nimport { useField } from './useField';\nimport { useFieldComponents } from './FormFieldsContext';\n\nexport interface FieldProps<TFieldValues extends FieldValues = FieldValues> {\n field: FieldConfig;\n control: Control<TFieldValues>;\n component?: ComponentType<any>;\n [key: string]: any;\n}\n\nexport function Field<TFieldValues extends FieldValues = FieldValues>({\n field,\n control,\n component,\n ...rest\n}: FieldProps<TFieldValues>) {\n const contextComponents = useFieldComponents();\n const Component = component ?? contextComponents[field.type] ?? contextComponents['text'];\n const { field: f, fieldState, state } = useField(field, control);\n\n if (!state.visible) {\n return null;\n }\n\n return (\n <Component\n formField={f}\n fieldConfig={field}\n fieldState={state}\n error={fieldState.error}\n disabled={state.disabled}\n readonly={state.readonly}\n {...rest}\n />\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunk3PMQZRSQcjs = require('../chunk-3PMQZRSQ.cjs');
3
+ var _chunkX5G3JO5Tcjs = require('../chunk-X5G3JO5T.cjs');
4
4
 
5
5
  // src/fields/TextField.tsx
6
6
  var _jsxruntime = require('react/jsx-runtime');
@@ -256,7 +256,7 @@ function DefaultField({
256
256
  }) {
257
257
  const components = defaultComponents;
258
258
  const resolved = _nullishCoalesce(_nullishCoalesce(component, () => ( components[field.type])), () => ( components["text"]));
259
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk3PMQZRSQcjs.Field, { field, control, component: resolved, ...rest });
259
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkX5G3JO5Tcjs.Field, { field, control, component: resolved, ...rest });
260
260
  }
261
261
 
262
262
 
@@ -1,7 +1,7 @@
1
1
  import { FieldConfig, FieldState } from '@form-os/core';
2
2
  import { ControllerRenderProps, FieldError, FieldValues } from 'react-hook-form';
3
3
  import * as react from 'react';
4
- import { F as FieldProps } from '../Field-BZNec30e.cjs';
4
+ import { F as FieldProps } from '../Field-5cPJnVTb.cjs';
5
5
 
6
6
  interface FieldComponentProps {
7
7
  formField: ControllerRenderProps;
@@ -1,7 +1,7 @@
1
1
  import { FieldConfig, FieldState } from '@form-os/core';
2
2
  import { ControllerRenderProps, FieldError, FieldValues } from 'react-hook-form';
3
3
  import * as react from 'react';
4
- import { F as FieldProps } from '../Field-BZNec30e.js';
4
+ import { F as FieldProps } from '../Field-5cPJnVTb.js';
5
5
 
6
6
  interface FieldComponentProps {
7
7
  formField: ControllerRenderProps;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Field
3
- } from "../chunk-IHVV2WZM.js";
3
+ } from "../chunk-V2X6FW6I.js";
4
4
 
5
5
  // src/fields/TextField.tsx
6
6
  import { jsx } from "react/jsx-runtime";
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunk3PMQZRSQcjs = require('./chunk-3PMQZRSQ.cjs');
6
+ var _chunkX5G3JO5Tcjs = require('./chunk-X5G3JO5T.cjs');
7
7
 
8
8
  // src/useFormConfig.ts
9
9
  var _react = require('react');
@@ -38,5 +38,5 @@ function useFormConfig(config) {
38
38
 
39
39
 
40
40
 
41
- exports.Field = _chunk3PMQZRSQcjs.Field; exports.FormFieldsProvider = _chunk3PMQZRSQcjs.FormFieldsProvider; exports.FormProvider = _reacthookform.FormProvider; exports.useField = _chunk3PMQZRSQcjs.useField; exports.useFieldComponents = _chunk3PMQZRSQcjs.useFieldComponents; exports.useForm = _reacthookform.useForm; exports.useFormConfig = useFormConfig; exports.useFormContext = _reacthookform.useFormContext;
41
+ exports.Field = _chunkX5G3JO5Tcjs.Field; exports.FormFieldsProvider = _chunkX5G3JO5Tcjs.FormFieldsProvider; exports.FormProvider = _reacthookform.FormProvider; exports.useField = _chunkX5G3JO5Tcjs.useField; exports.useFieldComponents = _chunkX5G3JO5Tcjs.useFieldComponents; exports.useForm = _reacthookform.useForm; exports.useFormConfig = useFormConfig; exports.useFormContext = _reacthookform.useFormContext;
42
42
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/abeleko/Documents/larven/formjs/packages/react/dist/index.cjs","../src/useFormConfig.ts","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACPA,8BAAwB;AACxB;AACE;AAAA,gDAIK;AACP,qCAAmE;AAE5D,SAAS,aAAA,CACd,MAAA,EACyD;AACzD,EAAA,MAAM,WAAA,EAAa,4BAAA,CAAQ,EAAA,GAAM,mCAAA,MAAsB,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAElE,EAAA,MAAM,cAAA,EAAgB,4BAAA;AAAA,IACpB,CAAA,EAAA,GACE,MAAA,CAAO,WAAA;AAAA,MACL,UAAA,CAAW,MAAA,CACR,MAAA,CAAO,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,aAAA,IAAiB,KAAA,CAAS,CAAA,CAC1C,GAAA,CAAI,CAAC,CAAA,EAAA,GAAM,CAAC,CAAA,CAAE,IAAA,EAAM,CAAA,CAAE,YAAY,CAAC;AAAA,IACxC,CAAA;AAAA,IACF,CAAC,UAAA,CAAW,MAAM;AAAA,EACpB,CAAA;AAEA,EAAA,MAAM,KAAA,EAAO,oCAAA;AAAsB,IACjC,aAAA;AAAA,IACA,IAAA,EAAM,UAAA,CAAW,cAAA;AAAA,IACjB,cAAA,EAAgB,UAAA,CAAW;AAAA,EAC7B,CAAC,CAAA;AAED,EAAA,OAAO,EAAE,GAAG,IAAA,EAAM,MAAA,EAAQ,UAAA,CAAW,OAAO,CAAA;AAC9C;ADHA;AACA;AEtBA;AFwBA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,0ZAAC","file":"/Users/abeleko/Documents/larven/formjs/packages/react/dist/index.cjs","sourcesContent":[null,"import { useMemo } from 'react';\nimport {\n useForm,\n type DefaultValues,\n type FieldValues,\n type UseFormReturn,\n} from 'react-hook-form';\nimport { normalizeConfig, type FieldConfig, type FormConfig } from '@form-os/core';\n\nexport function useFormConfig<TFieldValues extends FieldValues = FieldValues>(\n config: FieldConfig[] | FormConfig\n): UseFormReturn<TFieldValues> & { fields: FieldConfig[] } {\n const normalized = useMemo(() => normalizeConfig(config), [config]);\n\n const defaultValues = useMemo(\n () =>\n Object.fromEntries(\n normalized.fields\n .filter((f) => f.defaultValue !== undefined)\n .map((f) => [f.name, f.defaultValue])\n ),\n [normalized.fields]\n );\n\n const form = useForm<TFieldValues>({\n defaultValues: defaultValues as DefaultValues<TFieldValues>,\n mode: normalized.validationMode,\n reValidateMode: normalized.reValidateMode,\n });\n\n return { ...form, fields: normalized.fields };\n}\n","export { useFormConfig } from './useFormConfig';\nexport { Field } from './Field';\nexport type { FieldProps } from './Field';\nexport { useField } from './useField';\nexport type { UseFieldOptions } from './useField';\nexport { FormFieldsProvider, useFieldComponents } from './FormFieldsContext';\nexport type { ComponentsMap, FormFieldsProviderProps } from './FormFieldsContext';\nexport { FormProvider, useFormContext, useForm } from 'react-hook-form';\nexport type { Control, RegisterOptions, UseFormProps } from 'react-hook-form';\n"]}
1
+ {"version":3,"sources":["/Users/abeleko/Documents/larven/formjs/packages/react/dist/index.cjs","../src/useFormConfig.ts","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACPA,8BAAwB;AACxB;AACE;AAAA,gDAIK;AACP,qCAAmE;AAE5D,SAAS,aAAA,CACd,MAAA,EACyD;AACzD,EAAA,MAAM,WAAA,EAAa,4BAAA,CAAQ,EAAA,GAAM,mCAAA,MAAsB,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAElE,EAAA,MAAM,cAAA,EAAgB,4BAAA;AAAA,IACpB,CAAA,EAAA,GACE,MAAA,CAAO,WAAA;AAAA,MACL,UAAA,CAAW,MAAA,CACR,MAAA,CAAO,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,aAAA,IAAiB,KAAA,CAAS,CAAA,CAC1C,GAAA,CAAI,CAAC,CAAA,EAAA,GAAM,CAAC,CAAA,CAAE,IAAA,EAAM,CAAA,CAAE,YAAY,CAAC;AAAA,IACxC,CAAA;AAAA,IACF,CAAC,UAAA,CAAW,MAAM;AAAA,EACpB,CAAA;AAEA,EAAA,MAAM,KAAA,EAAO,oCAAA;AAAsB,IACjC,aAAA;AAAA,IACA,IAAA,EAAM,UAAA,CAAW,cAAA;AAAA,IACjB,cAAA,EAAgB,UAAA,CAAW;AAAA,EAC7B,CAAC,CAAA;AAED,EAAA,OAAO,EAAE,GAAG,IAAA,EAAM,MAAA,EAAQ,UAAA,CAAW,OAAO,CAAA;AAC9C;ADHA;AACA;AEvBA;AFyBA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,0ZAAC","file":"/Users/abeleko/Documents/larven/formjs/packages/react/dist/index.cjs","sourcesContent":[null,"import { useMemo } from 'react';\nimport {\n useForm,\n type DefaultValues,\n type FieldValues,\n type UseFormReturn,\n} from 'react-hook-form';\nimport { normalizeConfig, type FieldConfig, type FormConfig } from '@form-os/core';\n\nexport function useFormConfig<TFieldValues extends FieldValues = FieldValues>(\n config: FieldConfig[] | FormConfig\n): UseFormReturn<TFieldValues> & { fields: FieldConfig[] } {\n const normalized = useMemo(() => normalizeConfig(config), [config]);\n\n const defaultValues = useMemo(\n () =>\n Object.fromEntries(\n normalized.fields\n .filter((f) => f.defaultValue !== undefined)\n .map((f) => [f.name, f.defaultValue])\n ),\n [normalized.fields]\n );\n\n const form = useForm<TFieldValues>({\n defaultValues: defaultValues as DefaultValues<TFieldValues>,\n mode: normalized.validationMode,\n reValidateMode: normalized.reValidateMode,\n });\n\n return { ...form, fields: normalized.fields };\n}\n","export { useFormConfig } from './useFormConfig';\nexport { Field } from './Field';\nexport type { FieldProps } from './Field';\nexport { useField } from './useField';\nexport { FormFieldsProvider, useFieldComponents } from './FormFieldsContext';\nexport type { ComponentsMap, FormFieldsProviderProps } from './FormFieldsContext';\nexport { FormProvider, useFormContext, useForm } from 'react-hook-form';\nexport type { Control, RegisterOptions, UseFormProps } from 'react-hook-form';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_hook_form from 'react-hook-form';
2
- import { FieldValues, UseFormReturn, RegisterOptions, Control } from 'react-hook-form';
2
+ import { FieldValues, UseFormReturn, Control } from 'react-hook-form';
3
3
  export { Control, FormProvider, RegisterOptions, UseFormProps, useForm, useFormContext } from 'react-hook-form';
4
4
  import * as _form_os_core from '@form-os/core';
5
5
  import { FieldConfig, FormConfig } from '@form-os/core';
6
- export { a as Field, F as FieldProps } from './Field-BZNec30e.cjs';
6
+ export { a as Field, F as FieldProps } from './Field-5cPJnVTb.cjs';
7
7
  import * as react from 'react';
8
8
  import { ComponentType, ReactNode } from 'react';
9
9
 
@@ -11,11 +11,7 @@ declare function useFormConfig<TFieldValues extends FieldValues = FieldValues>(c
11
11
  fields: FieldConfig[];
12
12
  };
13
13
 
14
- interface UseFieldOptions {
15
- rules?: RegisterOptions;
16
- defaultValue?: any;
17
- }
18
- declare function useField<TFieldValues extends FieldValues = FieldValues>(field: FieldConfig, control: Control<TFieldValues>, options?: UseFieldOptions): {
14
+ declare function useField<TFieldValues extends FieldValues = FieldValues>(field: FieldConfig, control: Control<TFieldValues>): {
19
15
  field: react_hook_form.ControllerRenderProps<TFieldValues, react_hook_form.Path<TFieldValues>>;
20
16
  fieldState: react_hook_form.ControllerFieldState;
21
17
  state: _form_os_core.FieldState;
@@ -29,4 +25,4 @@ interface FormFieldsProviderProps {
29
25
  declare function FormFieldsProvider({ components, children }: FormFieldsProviderProps): react.JSX.Element;
30
26
  declare function useFieldComponents(): ComponentsMap;
31
27
 
32
- export { type ComponentsMap, FormFieldsProvider, type FormFieldsProviderProps, type UseFieldOptions, useField, useFieldComponents, useFormConfig };
28
+ export { type ComponentsMap, FormFieldsProvider, type FormFieldsProviderProps, useField, useFieldComponents, useFormConfig };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_hook_form from 'react-hook-form';
2
- import { FieldValues, UseFormReturn, RegisterOptions, Control } from 'react-hook-form';
2
+ import { FieldValues, UseFormReturn, Control } from 'react-hook-form';
3
3
  export { Control, FormProvider, RegisterOptions, UseFormProps, useForm, useFormContext } from 'react-hook-form';
4
4
  import * as _form_os_core from '@form-os/core';
5
5
  import { FieldConfig, FormConfig } from '@form-os/core';
6
- export { a as Field, F as FieldProps } from './Field-BZNec30e.js';
6
+ export { a as Field, F as FieldProps } from './Field-5cPJnVTb.js';
7
7
  import * as react from 'react';
8
8
  import { ComponentType, ReactNode } from 'react';
9
9
 
@@ -11,11 +11,7 @@ declare function useFormConfig<TFieldValues extends FieldValues = FieldValues>(c
11
11
  fields: FieldConfig[];
12
12
  };
13
13
 
14
- interface UseFieldOptions {
15
- rules?: RegisterOptions;
16
- defaultValue?: any;
17
- }
18
- declare function useField<TFieldValues extends FieldValues = FieldValues>(field: FieldConfig, control: Control<TFieldValues>, options?: UseFieldOptions): {
14
+ declare function useField<TFieldValues extends FieldValues = FieldValues>(field: FieldConfig, control: Control<TFieldValues>): {
19
15
  field: react_hook_form.ControllerRenderProps<TFieldValues, react_hook_form.Path<TFieldValues>>;
20
16
  fieldState: react_hook_form.ControllerFieldState;
21
17
  state: _form_os_core.FieldState;
@@ -29,4 +25,4 @@ interface FormFieldsProviderProps {
29
25
  declare function FormFieldsProvider({ components, children }: FormFieldsProviderProps): react.JSX.Element;
30
26
  declare function useFieldComponents(): ComponentsMap;
31
27
 
32
- export { type ComponentsMap, FormFieldsProvider, type FormFieldsProviderProps, type UseFieldOptions, useField, useFieldComponents, useFormConfig };
28
+ export { type ComponentsMap, FormFieldsProvider, type FormFieldsProviderProps, useField, useFieldComponents, useFormConfig };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  FormFieldsProvider,
4
4
  useField,
5
5
  useFieldComponents
6
- } from "./chunk-IHVV2WZM.js";
6
+ } from "./chunk-V2X6FW6I.js";
7
7
 
8
8
  // src/useFormConfig.ts
9
9
  import { useMemo } from "react";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/useFormConfig.ts","../src/index.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n useForm,\n type DefaultValues,\n type FieldValues,\n type UseFormReturn,\n} from 'react-hook-form';\nimport { normalizeConfig, type FieldConfig, type FormConfig } from '@form-os/core';\n\nexport function useFormConfig<TFieldValues extends FieldValues = FieldValues>(\n config: FieldConfig[] | FormConfig\n): UseFormReturn<TFieldValues> & { fields: FieldConfig[] } {\n const normalized = useMemo(() => normalizeConfig(config), [config]);\n\n const defaultValues = useMemo(\n () =>\n Object.fromEntries(\n normalized.fields\n .filter((f) => f.defaultValue !== undefined)\n .map((f) => [f.name, f.defaultValue])\n ),\n [normalized.fields]\n );\n\n const form = useForm<TFieldValues>({\n defaultValues: defaultValues as DefaultValues<TFieldValues>,\n mode: normalized.validationMode,\n reValidateMode: normalized.reValidateMode,\n });\n\n return { ...form, fields: normalized.fields };\n}\n","export { useFormConfig } from './useFormConfig';\nexport { Field } from './Field';\nexport type { FieldProps } from './Field';\nexport { useField } from './useField';\nexport type { UseFieldOptions } from './useField';\nexport { FormFieldsProvider, useFieldComponents } from './FormFieldsContext';\nexport type { ComponentsMap, FormFieldsProviderProps } from './FormFieldsContext';\nexport { FormProvider, useFormContext, useForm } from 'react-hook-form';\nexport type { Control, RegisterOptions, UseFormProps } from 'react-hook-form';\n"],"mappings":";;;;;;;;AAAA,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,OAIK;AACP,SAAS,uBAA0D;AAE5D,SAAS,cACd,QACyD;AACzD,QAAM,aAAa,QAAQ,MAAM,gBAAgB,MAAM,GAAG,CAAC,MAAM,CAAC;AAElE,QAAM,gBAAgB;AAAA,IACpB,MACE,OAAO;AAAA,MACL,WAAW,OACR,OAAO,CAAC,MAAM,EAAE,iBAAiB,MAAS,EAC1C,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC;AAAA,IACxC;AAAA,IACF,CAAC,WAAW,MAAM;AAAA,EACpB;AAEA,QAAM,OAAO,QAAsB;AAAA,IACjC;AAAA,IACA,MAAM,WAAW;AAAA,IACjB,gBAAgB,WAAW;AAAA,EAC7B,CAAC;AAED,SAAO,EAAE,GAAG,MAAM,QAAQ,WAAW,OAAO;AAC9C;;;ACxBA,SAAS,cAAc,gBAAgB,WAAAA,gBAAe;","names":["useForm"]}
1
+ {"version":3,"sources":["../src/useFormConfig.ts","../src/index.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n useForm,\n type DefaultValues,\n type FieldValues,\n type UseFormReturn,\n} from 'react-hook-form';\nimport { normalizeConfig, type FieldConfig, type FormConfig } from '@form-os/core';\n\nexport function useFormConfig<TFieldValues extends FieldValues = FieldValues>(\n config: FieldConfig[] | FormConfig\n): UseFormReturn<TFieldValues> & { fields: FieldConfig[] } {\n const normalized = useMemo(() => normalizeConfig(config), [config]);\n\n const defaultValues = useMemo(\n () =>\n Object.fromEntries(\n normalized.fields\n .filter((f) => f.defaultValue !== undefined)\n .map((f) => [f.name, f.defaultValue])\n ),\n [normalized.fields]\n );\n\n const form = useForm<TFieldValues>({\n defaultValues: defaultValues as DefaultValues<TFieldValues>,\n mode: normalized.validationMode,\n reValidateMode: normalized.reValidateMode,\n });\n\n return { ...form, fields: normalized.fields };\n}\n","export { useFormConfig } from './useFormConfig';\nexport { Field } from './Field';\nexport type { FieldProps } from './Field';\nexport { useField } from './useField';\nexport { FormFieldsProvider, useFieldComponents } from './FormFieldsContext';\nexport type { ComponentsMap, FormFieldsProviderProps } from './FormFieldsContext';\nexport { FormProvider, useFormContext, useForm } from 'react-hook-form';\nexport type { Control, RegisterOptions, UseFormProps } from 'react-hook-form';\n"],"mappings":";;;;;;;;AAAA,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,OAIK;AACP,SAAS,uBAA0D;AAE5D,SAAS,cACd,QACyD;AACzD,QAAM,aAAa,QAAQ,MAAM,gBAAgB,MAAM,GAAG,CAAC,MAAM,CAAC;AAElE,QAAM,gBAAgB;AAAA,IACpB,MACE,OAAO;AAAA,MACL,WAAW,OACR,OAAO,CAAC,MAAM,EAAE,iBAAiB,MAAS,EAC1C,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC;AAAA,IACxC;AAAA,IACF,CAAC,WAAW,MAAM;AAAA,EACpB;AAEA,QAAM,OAAO,QAAsB;AAAA,IACjC;AAAA,IACA,MAAM,WAAW;AAAA,IACjB,gBAAgB,WAAW;AAAA,EAC7B,CAAC;AAED,SAAO,EAAE,GAAG,MAAM,QAAQ,WAAW,OAAO;AAC9C;;;ACzBA,SAAS,cAAc,gBAAgB,WAAAA,gBAAe;","names":["useForm"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-os/react",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -30,7 +30,7 @@
30
30
  "react-hook-form": ">=7.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "@form-os/core": "0.4.0"
33
+ "@form-os/core": "0.5.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/react": "^18.2.0",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/abeleko/Documents/larven/formjs/packages/react/dist/chunk-3PMQZRSQ.cjs","../src/useField.ts","../src/FormFieldsContext.tsx","../src/Field.tsx"],"names":["jsx"],"mappings":"AAAA;ACAA,8BAAwB;AACxB,gDAAwC;AAExC,qCAAgD;AAOzC,SAAS,QAAA,CACd,KAAA,EACA,OAAA,EACA,QAAA,EAA2B,CAAC,CAAA,EAC5B;AACA,EAAA,MAAM,OAAA,EAAS,qCAAA,EAAW,QAAQ,CAAC,CAAA;AAEnC,EAAA,MAAM,MAAA,EAAQ,4BAAA;AAAA,IACZ,CAAA,EAAA,GAAM,iCAAA,KAAc,mBAAO,MAAA,UAAU,CAAC,GAAC,CAAA;AAAA,IACvC,CAAC,KAAA,EAAO,MAAM;AAAA,EAChB,CAAA;AAEA,EAAA,MAAM,EAAE,KAAA,EAAO,CAAA,EAAG,WAAW,EAAA,EAAI,0CAAA;AAA4B,IAC3D,IAAA,EAAM,KAAA,CAAM,IAAA;AAAA,IACZ,OAAA;AAAA,IACA,KAAA,mBAAQ,OAAA,CAAQ,KAAA,UAAS,KAAA,CAAM,OAAA;AAAA,IAC/B,YAAA,mBAAc,OAAA,CAAQ,YAAA,UAAgB,KAAA,CAAM,cAAA;AAAA,IAC5C,QAAA,EAAU,KAAA,CAAM;AAAA,EAClB,CAAC,CAAA;AAED,EAAA,OAAO,EAAE,KAAA,EAAO,CAAA,EAAG,UAAA,EAAY,MAAM,CAAA;AACvC;ADZA;AACA;AEpBA;AAcI,+CAAA;AATJ,IAAM,kBAAA,EAAoB,kCAAA,CAA8B,CAAC,CAAA;AAOlD,SAAS,kBAAA,CAAmB,EAAE,UAAA,EAAY,SAAS,CAAA,EAA4B;AACpF,EAAA,uBACE,6BAAA,iBAAC,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,UAAA,EAChC,SAAA,CACH,CAAA;AAEJ;AAEO,SAAS,kBAAA,CAAA,EAAoC;AAClD,EAAA,OAAO,+BAAA,iBAA4B,CAAA;AACrC;AFQA;AACA;AGDI;AAhBG,SAAS,KAAA,CAAsD;AAAA,EACpE,KAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAG;AACL,CAAA,EAA6B;AAC3B,EAAA,MAAM,kBAAA,EAAoB,kBAAA,CAAmB,CAAA;AAC7C,EAAA,MAAM,UAAA,oCAAY,SAAA,UAAa,iBAAA,CAAkB,KAAA,CAAM,IAAI,GAAA,UAAK,iBAAA,CAAkB,MAAM,GAAA;AACxF,EAAA,MAAM,EAAE,KAAA,EAAO,CAAA,EAAG,UAAA,EAAY,MAAM,EAAA,EAAI,QAAA,CAAS,KAAA,EAAO,OAAA,EAAS,EAAE,MAAM,CAAC,CAAA;AAE1E,EAAA,GAAA,CAAI,CAAC,KAAA,CAAM,OAAA,EAAS;AAClB,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,uBACEA,6BAAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,CAAA;AAAA,MACX,WAAA,EAAa,KAAA;AAAA,MACb,UAAA,EAAY,KAAA;AAAA,MACZ,KAAA,EAAO,UAAA,CAAW,KAAA;AAAA,MAClB,QAAA,EAAU,KAAA,CAAM,QAAA;AAAA,MAChB,QAAA,EAAU,KAAA,CAAM,QAAA;AAAA,MACf,GAAG;AAAA,IAAA;AAAA,EACN,CAAA;AAEJ;AHmBA;AACA;AACE;AACA;AACA;AACA;AACF,qJAAC","file":"/Users/abeleko/Documents/larven/formjs/packages/react/dist/chunk-3PMQZRSQ.cjs","sourcesContent":[null,"import { useMemo } from 'react';\nimport { useController, useWatch } from 'react-hook-form';\nimport type { Control, FieldPath, FieldValues, RegisterOptions } from 'react-hook-form';\nimport { getFieldState, type FieldConfig } from '@form-os/core';\n\nexport interface UseFieldOptions {\n rules?: RegisterOptions;\n defaultValue?: any;\n}\n\nexport function useField<TFieldValues extends FieldValues = FieldValues>(\n field: FieldConfig,\n control: Control<TFieldValues>,\n options: UseFieldOptions = {}\n) {\n const values = useWatch({ control }) as Record<string, any>;\n\n const state = useMemo(\n () => getFieldState(field, values ?? {}),\n [field, values]\n );\n\n const { field: f, fieldState } = useController<TFieldValues>({\n name: field.name as FieldPath<TFieldValues>,\n control,\n rules: (options.rules ?? field.rules) as RegisterOptions<TFieldValues> | undefined,\n defaultValue: options.defaultValue ?? field.defaultValue,\n disabled: state.disabled,\n });\n\n return { field: f, fieldState, state };\n}\n","import { createContext, useContext } from 'react';\nimport type { ComponentType, ReactNode } from 'react';\n\nexport type ComponentsMap = Record<string, ComponentType<any>>;\n\nconst FormFieldsContext = createContext<ComponentsMap>({});\n\nexport interface FormFieldsProviderProps {\n components: ComponentsMap;\n children: ReactNode;\n}\n\nexport function FormFieldsProvider({ components, children }: FormFieldsProviderProps) {\n return (\n <FormFieldsContext.Provider value={components}>\n {children}\n </FormFieldsContext.Provider>\n );\n}\n\nexport function useFieldComponents(): ComponentsMap {\n return useContext(FormFieldsContext);\n}\n","import type { ComponentType } from 'react';\nimport type { Control, FieldValues, RegisterOptions } from 'react-hook-form';\nimport type { FieldConfig } from '@form-os/core';\nimport { useField } from './useField';\nimport { useFieldComponents } from './FormFieldsContext';\n\nexport interface FieldProps<TFieldValues extends FieldValues = FieldValues> {\n field: FieldConfig;\n control: Control<TFieldValues>;\n component?: ComponentType<any>;\n rules?: RegisterOptions;\n [key: string]: any;\n}\n\nexport function Field<TFieldValues extends FieldValues = FieldValues>({\n field,\n control,\n component,\n rules,\n ...rest\n}: FieldProps<TFieldValues>) {\n const contextComponents = useFieldComponents();\n const Component = component ?? contextComponents[field.type] ?? contextComponents['text'];\n const { field: f, fieldState, state } = useField(field, control, { rules });\n\n if (!state.visible) {\n return null;\n }\n\n return (\n <Component\n formField={f}\n fieldConfig={field}\n fieldState={state}\n error={fieldState.error}\n disabled={state.disabled}\n readonly={state.readonly}\n {...rest}\n />\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/useField.ts","../src/FormFieldsContext.tsx","../src/Field.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { useController, useWatch } from 'react-hook-form';\nimport type { Control, FieldPath, FieldValues, RegisterOptions } from 'react-hook-form';\nimport { getFieldState, type FieldConfig } from '@form-os/core';\n\nexport interface UseFieldOptions {\n rules?: RegisterOptions;\n defaultValue?: any;\n}\n\nexport function useField<TFieldValues extends FieldValues = FieldValues>(\n field: FieldConfig,\n control: Control<TFieldValues>,\n options: UseFieldOptions = {}\n) {\n const values = useWatch({ control }) as Record<string, any>;\n\n const state = useMemo(\n () => getFieldState(field, values ?? {}),\n [field, values]\n );\n\n const { field: f, fieldState } = useController<TFieldValues>({\n name: field.name as FieldPath<TFieldValues>,\n control,\n rules: (options.rules ?? field.rules) as RegisterOptions<TFieldValues> | undefined,\n defaultValue: options.defaultValue ?? field.defaultValue,\n disabled: state.disabled,\n });\n\n return { field: f, fieldState, state };\n}\n","import { createContext, useContext } from 'react';\nimport type { ComponentType, ReactNode } from 'react';\n\nexport type ComponentsMap = Record<string, ComponentType<any>>;\n\nconst FormFieldsContext = createContext<ComponentsMap>({});\n\nexport interface FormFieldsProviderProps {\n components: ComponentsMap;\n children: ReactNode;\n}\n\nexport function FormFieldsProvider({ components, children }: FormFieldsProviderProps) {\n return (\n <FormFieldsContext.Provider value={components}>\n {children}\n </FormFieldsContext.Provider>\n );\n}\n\nexport function useFieldComponents(): ComponentsMap {\n return useContext(FormFieldsContext);\n}\n","import type { ComponentType } from 'react';\nimport type { Control, FieldValues, RegisterOptions } from 'react-hook-form';\nimport type { FieldConfig } from '@form-os/core';\nimport { useField } from './useField';\nimport { useFieldComponents } from './FormFieldsContext';\n\nexport interface FieldProps<TFieldValues extends FieldValues = FieldValues> {\n field: FieldConfig;\n control: Control<TFieldValues>;\n component?: ComponentType<any>;\n rules?: RegisterOptions;\n [key: string]: any;\n}\n\nexport function Field<TFieldValues extends FieldValues = FieldValues>({\n field,\n control,\n component,\n rules,\n ...rest\n}: FieldProps<TFieldValues>) {\n const contextComponents = useFieldComponents();\n const Component = component ?? contextComponents[field.type] ?? contextComponents['text'];\n const { field: f, fieldState, state } = useField(field, control, { rules });\n\n if (!state.visible) {\n return null;\n }\n\n return (\n <Component\n formField={f}\n fieldConfig={field}\n fieldState={state}\n error={fieldState.error}\n disabled={state.disabled}\n readonly={state.readonly}\n {...rest}\n />\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,eAAe,gBAAgB;AAExC,SAAS,qBAAuC;AAOzC,SAAS,SACd,OACA,SACA,UAA2B,CAAC,GAC5B;AACA,QAAM,SAAS,SAAS,EAAE,QAAQ,CAAC;AAEnC,QAAM,QAAQ;AAAA,IACZ,MAAM,cAAc,OAAO,UAAU,CAAC,CAAC;AAAA,IACvC,CAAC,OAAO,MAAM;AAAA,EAChB;AAEA,QAAM,EAAE,OAAO,GAAG,WAAW,IAAI,cAA4B;AAAA,IAC3D,MAAM,MAAM;AAAA,IACZ;AAAA,IACA,OAAQ,QAAQ,SAAS,MAAM;AAAA,IAC/B,cAAc,QAAQ,gBAAgB,MAAM;AAAA,IAC5C,UAAU,MAAM;AAAA,EAClB,CAAC;AAED,SAAO,EAAE,OAAO,GAAG,YAAY,MAAM;AACvC;;;AC/BA,SAAS,eAAe,kBAAkB;AActC;AATJ,IAAM,oBAAoB,cAA6B,CAAC,CAAC;AAOlD,SAAS,mBAAmB,EAAE,YAAY,SAAS,GAA4B;AACpF,SACE,oBAAC,kBAAkB,UAAlB,EAA2B,OAAO,YAChC,UACH;AAEJ;AAEO,SAAS,qBAAoC;AAClD,SAAO,WAAW,iBAAiB;AACrC;;;ACQI,gBAAAA,YAAA;AAhBG,SAAS,MAAsD;AAAA,EACpE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA6B;AAC3B,QAAM,oBAAoB,mBAAmB;AAC7C,QAAM,YAAY,aAAa,kBAAkB,MAAM,IAAI,KAAK,kBAAkB,MAAM;AACxF,QAAM,EAAE,OAAO,GAAG,YAAY,MAAM,IAAI,SAAS,OAAO,SAAS,EAAE,MAAM,CAAC;AAE1E,MAAI,CAAC,MAAM,SAAS;AAClB,WAAO;AAAA,EACT;AAEA,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,MACX,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,OAAO,WAAW;AAAA,MAClB,UAAU,MAAM;AAAA,MAChB,UAAU,MAAM;AAAA,MACf,GAAG;AAAA;AAAA,EACN;AAEJ;","names":["jsx"]}