autoforma 2.9.9 → 2.9.92

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,9 +1,9 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { Layout, UiConfig, UpdateFieldSchema } from '../types';
3
- export interface AutoFormRenderContextProps<TCustom extends string = never> {
3
+ export interface AutoFormRenderContextProps {
4
4
  layout?: Layout;
5
- uiConfig?: UiConfig<TCustom>;
6
- updateFieldSchema?: UpdateFieldSchema<TCustom>;
5
+ uiConfig?: UiConfig;
6
+ updateFieldSchema?: UpdateFieldSchema;
7
7
  }
8
- export declare const AutoFormRenderContext: import('react').Context<AutoFormRenderContextProps<any> | null>;
9
- export declare const AutoFormRenderContextProvider: <TCustom extends string = never>({ children, layout, uiConfig, updateFieldSchema, }: PropsWithChildren<AutoFormRenderContextProps<TCustom>>) => import("react/jsx-runtime").JSX.Element;
8
+ export declare const AutoFormRenderContext: import('react').Context<AutoFormRenderContextProps | null>;
9
+ export declare const AutoFormRenderContextProvider: ({ children, layout, uiConfig, updateFieldSchema, }: PropsWithChildren<AutoFormRenderContextProps>) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { AutoFormRenderContextProps } from './AutoFormRenderContext';
2
- export declare const useAutoFormRenderContext: <TCustom extends string = never>() => AutoFormRenderContextProps<TCustom>;
2
+ export declare const useAutoFormRenderContext: () => AutoFormRenderContextProps;
@@ -1,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { FormProps, FormRef } from '../types';
3
- type AutoFormComponent = <TCustom extends string = never>(props: FormProps<TCustom> & React.RefAttributes<FormRef>) => React.ReactElement;
3
+ type AutoFormComponent = (props: FormProps & React.RefAttributes<FormRef>) => React.ReactElement;
4
4
  declare const AutoForm: AutoFormComponent;
5
5
  export default AutoForm;
@@ -1,3 +1,3 @@
1
1
  import { FieldProps } from '../types';
2
- declare const DefaultInput: <TCustom extends string = never>(props: FieldProps<TCustom>) => import("react/jsx-runtime").JSX.Element;
2
+ declare const DefaultInput: (props: FieldProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default DefaultInput;
@@ -1,3 +1,3 @@
1
1
  import { FieldProps } from '../types';
2
- declare const DefaultSelect: <TCustom extends string = never>(props: FieldProps<TCustom>) => import("react/jsx-runtime").JSX.Element;
2
+ declare const DefaultSelect: <TCustom extends string = never>(props: FieldProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default DefaultSelect;
@@ -1,3 +1,3 @@
1
1
  import { FieldProps } from '../types';
2
- declare const FieldLayout: <TCustom extends string = never>(props: FieldProps<TCustom>) => import("react/jsx-runtime").JSX.Element;
2
+ declare const FieldLayout: (props: FieldProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default FieldLayout;
@@ -1,3 +1,3 @@
1
1
  import { FieldProps } from '../types';
2
- declare const FieldRenderer: <TCustom extends string = never>({ fieldSchema }: FieldProps<TCustom>) => import("react/jsx-runtime").JSX.Element | null;
2
+ declare const FieldRenderer: <TCustom extends string = never>({ fieldSchema }: FieldProps) => import("react/jsx-runtime").JSX.Element | null;
3
3
  export default FieldRenderer;
@@ -1,7 +1,7 @@
1
1
  import { default as React } from 'react';
2
2
  import { Schema } from '../types';
3
- interface SchemaRendererProps<TCustom extends string = never> {
4
- schema: Schema<TCustom>;
3
+ interface SchemaRendererProps {
4
+ schema: Schema;
5
5
  }
6
- declare const SchemaRenderer: React.MemoExoticComponent<(<TCustom extends string = never>(props: SchemaRendererProps<TCustom>) => import("react/jsx-runtime").JSX.Element[])>;
6
+ declare const SchemaRenderer: React.MemoExoticComponent<(props: SchemaRendererProps) => import("react/jsx-runtime").JSX.Element[]>;
7
7
  export default SchemaRenderer;
@@ -1,3 +1,3 @@
1
1
  import { FieldProps } from '../types';
2
- declare const UnWatchedField: <TCustom extends string = never>({ fieldSchema }: FieldProps<TCustom>) => import("react/jsx-runtime").JSX.Element;
2
+ declare const UnWatchedField: ({ fieldSchema }: FieldProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default UnWatchedField;
@@ -1,3 +1,3 @@
1
1
  import { FieldProps } from '../types';
2
- declare const WatchedField: <TCustom extends string = never>({ fieldSchema }: FieldProps<TCustom>) => import("react/jsx-runtime").JSX.Element;
2
+ declare const WatchedField: ({ fieldSchema }: FieldProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default WatchedField;
@@ -1,3 +1,3 @@
1
1
  import { FieldProps } from '../types';
2
- declare const Watcher: <TCustom extends string = never>(props: FieldProps<TCustom>) => import("react/jsx-runtime").JSX.Element;
2
+ declare const Watcher: (props: FieldProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Watcher;
@@ -1,10 +1,8 @@
1
1
  import { default as React } from 'react';
2
2
  import { Control, Resolver, UseFormRegisterReturn } from 'react-hook-form';
3
3
  export type FormValues = Record<string, any>;
4
- export type BuiltInFieldType = 'text' | 'number' | 'checkbox' | 'select' | 'date' | 'datetime-local' | 'time' | 'array' | 'object';
5
- export type FieldType<TCustom extends string = never> = BuiltInFieldType | TCustom;
6
- export interface BaseFieldSchema<TCustom extends string = never> {
7
- type: FieldType<TCustom>;
4
+ export interface BaseFieldSchema {
5
+ type: string;
8
6
  name: string;
9
7
  label: string;
10
8
  dependsOn?: string[];
@@ -13,51 +11,73 @@ export interface BaseFieldSchema<TCustom extends string = never> {
13
11
  readonly?: boolean;
14
12
  meta?: Record<string, any>;
15
13
  }
16
- export interface HasFields<TCustom extends string = never> extends BaseFieldSchema<TCustom> {
17
- fields: FieldSchema<TCustom>[];
14
+ export type BuiltInFieldType = 'text' | 'number' | 'checkbox' | 'select' | 'date' | 'datetime-local' | 'time' | 'array' | 'object';
15
+ export interface TextFieldSchema extends BaseFieldSchema {
16
+ type: 'text';
18
17
  }
19
- export interface ArrayFieldSchema<TCustom extends string = never> extends HasFields<TCustom> {
20
- type: 'array';
18
+ export interface NumberFieldSchema extends BaseFieldSchema {
19
+ type: 'number';
21
20
  }
22
- export interface ObjectFieldSchema<TCustom extends string = never> extends HasFields<TCustom> {
23
- type: 'object';
21
+ export interface CheckboxFieldSchema extends BaseFieldSchema {
22
+ type: 'checkbox';
23
+ }
24
+ export interface DateFieldSchema extends BaseFieldSchema {
25
+ type: 'date';
26
+ }
27
+ export interface DateTimeLocalFieldSchema extends BaseFieldSchema {
28
+ type: 'datetime-local';
24
29
  }
25
- export interface SelectFieldSchema<TCustom extends string = never> extends BaseFieldSchema<TCustom> {
30
+ export interface TimeFieldSchema extends BaseFieldSchema {
31
+ type: 'time';
32
+ }
33
+ export interface SelectFieldSchema extends BaseFieldSchema {
26
34
  type: 'select';
27
35
  options: {
28
36
  label: string;
29
37
  value: string;
30
38
  }[];
31
39
  }
40
+ export interface ArrayFieldSchema extends BaseFieldSchema {
41
+ type: 'array';
42
+ fields: FieldSchema[];
43
+ }
44
+ export interface ObjectFieldSchema extends BaseFieldSchema {
45
+ type: 'object';
46
+ fields: FieldSchema[];
47
+ }
32
48
  export interface FieldSchemaRegistry {
33
- base: BaseFieldSchema<never>;
34
- select: SelectFieldSchema<never>;
35
- hasFields: HasFields<never>;
36
- array: ArrayFieldSchema<never>;
37
- object: ObjectFieldSchema<never>;
49
+ text: TextFieldSchema;
50
+ number: NumberFieldSchema;
51
+ checkbox: CheckboxFieldSchema;
52
+ select: SelectFieldSchema;
53
+ date: DateFieldSchema;
54
+ 'datetime-local': DateTimeLocalFieldSchema;
55
+ time: TimeFieldSchema;
56
+ array: ArrayFieldSchema;
57
+ object: ObjectFieldSchema;
38
58
  }
39
- export type FieldSchema<TCustom extends string = never> = FieldSchemaRegistry[keyof FieldSchemaRegistry];
40
- export type Schema<TCustom extends string = never> = FieldSchema<TCustom>[];
41
- export type UpdateFieldSchema<TCustom extends string = never> = {
42
- [key: string]: (path: string, fieldSchema: FieldSchema<TCustom>, values: FormValues) => FieldSchema<TCustom> | Promise<FieldSchema<TCustom>>;
59
+ export type FieldSchema = FieldSchemaRegistry[keyof FieldSchemaRegistry];
60
+ export type Schema = FieldSchema[];
61
+ export type UpdateFieldSchema = {
62
+ [key: string]: (path: string, fieldSchema: FieldSchema, values: FormValues) => FieldSchema | Promise<FieldSchema>;
43
63
  };
44
- export type CustomFieldRendererProps<TCustom extends string = never> = {
45
- fieldSchema: FieldSchema<TCustom>;
64
+ export type CustomFieldRendererProps = {
65
+ fieldSchema: FieldSchema;
46
66
  register: UseFormRegisterReturn<string>;
47
67
  control: Control<FormValues>;
48
68
  };
49
- export type CustomRender<TCustom extends string = never> = Record<string, React.ComponentType<CustomFieldRendererProps<TCustom>>>;
50
- export type UiConfig<TCustom extends string = never> = {
51
- renderersByName?: CustomRender<TCustom>;
52
- renderersByType?: CustomRender<TCustom>;
69
+ export type CustomRender = Record<string, React.ComponentType<CustomFieldRendererProps>>;
70
+ export type UiConfig = {
71
+ renderersByName?: CustomRender;
72
+ renderersByType?: CustomRender;
53
73
  };
54
74
  export type Layout = 'vertical' | 'horizontal' | 'custom';
55
- export interface FormProps<TCustom extends string = never> {
56
- schema: Schema<TCustom>;
75
+ export interface FormProps {
76
+ schema: Schema;
57
77
  onSubmit: (values: FormValues) => void;
58
78
  layout?: Layout;
59
- uiConfig?: UiConfig<TCustom>;
60
- updateFieldSchema?: UpdateFieldSchema<TCustom>;
79
+ uiConfig?: UiConfig;
80
+ updateFieldSchema?: UpdateFieldSchema;
61
81
  values?: () => FormValues | Promise<FormValues>;
62
82
  hideSubmit?: boolean;
63
83
  onDirtyChange?: (isDirty: boolean) => void;
@@ -73,6 +93,6 @@ export interface FormRef {
73
93
  getValues: () => FormValues;
74
94
  reset: (values: FormValues) => void;
75
95
  }
76
- export interface FieldProps<TCustom extends string = never> {
77
- fieldSchema: FieldSchema<TCustom>;
96
+ export interface FieldProps {
97
+ fieldSchema: FieldSchema;
78
98
  }
@@ -1,2 +1,2 @@
1
1
  import { FormValues, Schema } from '../types';
2
- export declare function generateInitialValues<TValues extends FormValues = Record<string, any>, TCustom extends string = never>(schema: Schema<TCustom>, initialValues?: Partial<TValues>): TValues;
2
+ export declare function generateInitialValues<TValues extends FormValues = Record<string, any>, TCustom extends string = never>(schema: Schema, initialValues?: Partial<TValues>): TValues;
@@ -1,2 +1,2 @@
1
- import { FieldType } from '../types';
2
- export declare function getDefaultValueForField<TCustom extends string = never>(type: FieldType<TCustom>): any;
1
+ import { BuiltInFieldType } from '../types';
2
+ export declare function getDefaultValueForField<TCustom extends string = never>(type: BuiltInFieldType): any;
@@ -1,2 +1,2 @@
1
1
  import { Schema } from '../types';
2
- export declare function makeSchemaReadOnly<TCustom extends string = never>(schema: Schema<TCustom>): Schema<TCustom>;
2
+ export declare function makeSchemaReadOnly<TCustom extends string = never>(schema: Schema): Schema;
package/dist/index.es.js CHANGED
@@ -1513,12 +1513,10 @@ const Vr = R.memo((e) => {
1513
1513
  }, Sr = (e) => {
1514
1514
  const { fieldSchema: r } = e;
1515
1515
  return /* @__PURE__ */ V.jsx(kr, { fieldSchema: r });
1516
- }, Le = R.memo(
1517
- (e) => {
1518
- const { schema: r } = e;
1519
- return r.map((t) => /* @__PURE__ */ V.jsx(Sr, { fieldSchema: t }, t.name));
1520
- }
1521
- );
1516
+ }, Le = R.memo((e) => {
1517
+ const { schema: r } = e;
1518
+ return r.map((t) => /* @__PURE__ */ V.jsx(Sr, { fieldSchema: t }, t.name));
1519
+ });
1522
1520
  function Tr(e, r) {
1523
1521
  const t = (i) => /^\d+$/.test(i), n = e.split(".");
1524
1522
  let o = r;
@@ -1554,115 +1552,113 @@ const Or = (e) => {
1554
1552
  onDirtyChange: r,
1555
1553
  onValuesChange: e,
1556
1554
  onFieldChange: t
1557
- }), null), Pr = R.forwardRef(
1558
- (e, r) => {
1559
- const {
1560
- schema: t,
1561
- onSubmit: n,
1562
- uiConfig: o = {
1563
- renderersByName: {},
1564
- renderersByType: {}
1565
- },
1566
- updateFieldSchema: i = {},
1567
- layout: u = "vertical",
1568
- values: f = () => ({}),
1569
- hideSubmit: F = !1,
1570
- onDirtyChange: A = () => {
1571
- },
1572
- onValuesChange: T = () => {
1573
- },
1574
- resolver: x,
1575
- readonly: p,
1576
- onFieldChange: b = {},
1577
- loadingComponent: B
1578
- } = e, O = hr({
1579
- reValidateMode: "onSubmit",
1580
- criteriaMode: "all",
1581
- resolver: x
1582
- }), W = Et(!1), [$, E] = xt(!1), G = O.handleSubmit(n), C = ve(() => {
1583
- let N = t;
1584
- return p && (N = Ct(N)), N;
1585
- }, [p, t]);
1586
- Ce(() => {
1587
- if (!f) return;
1588
- let N = !1;
1589
- return (async () => {
1590
- if (W.current) return;
1591
- E(!1);
1592
- const fe = await f();
1593
- N || (O.reset(Ne(t, fe), {
1594
- keepErrors: !0,
1595
- keepDirty: !1,
1596
- keepTouched: !1
1597
- }), W.current = !0, E(!0));
1598
- })(), () => {
1599
- N = !0;
1600
- };
1601
- }, [t, f]), Yt(r, () => ({
1602
- submit: async () => {
1603
- await O.handleSubmit(n)();
1604
- },
1605
- reset: (N) => {
1606
- O.reset(N ? Ne(t, N) : void 0);
1607
- },
1608
- getValues: () => O.getValues(),
1609
- setValue: (N, J) => {
1610
- O.setValue(N, J);
1555
+ }), null), Pr = R.forwardRef((e, r) => {
1556
+ const {
1557
+ schema: t,
1558
+ onSubmit: n,
1559
+ uiConfig: o = {
1560
+ renderersByName: {},
1561
+ renderersByType: {}
1562
+ },
1563
+ updateFieldSchema: i = {},
1564
+ layout: u = "vertical",
1565
+ values: f = () => ({}),
1566
+ hideSubmit: F = !1,
1567
+ onDirtyChange: A = () => {
1568
+ },
1569
+ onValuesChange: T = () => {
1570
+ },
1571
+ resolver: x,
1572
+ readonly: p,
1573
+ onFieldChange: b = {},
1574
+ loadingComponent: B
1575
+ } = e, O = hr({
1576
+ reValidateMode: "onSubmit",
1577
+ criteriaMode: "all",
1578
+ resolver: x
1579
+ }), W = Et(!1), [$, E] = xt(!1), G = O.handleSubmit(n), C = ve(() => {
1580
+ let N = t;
1581
+ return p && (N = Ct(N)), N;
1582
+ }, [p, t]);
1583
+ Ce(() => {
1584
+ if (!f) return;
1585
+ let N = !1;
1586
+ return (async () => {
1587
+ if (W.current) return;
1588
+ E(!1);
1589
+ const fe = await f();
1590
+ N || (O.reset(Ne(t, fe), {
1591
+ keepErrors: !0,
1592
+ keepDirty: !1,
1593
+ keepTouched: !1
1594
+ }), W.current = !0, E(!0));
1595
+ })(), () => {
1596
+ N = !0;
1597
+ };
1598
+ }, [t, f]), Yt(r, () => ({
1599
+ submit: async () => {
1600
+ await O.handleSubmit(n)();
1601
+ },
1602
+ reset: (N) => {
1603
+ O.reset(N ? Ne(t, N) : void 0);
1604
+ },
1605
+ getValues: () => O.getValues(),
1606
+ setValue: (N, J) => {
1607
+ O.setValue(N, J);
1608
+ }
1609
+ }));
1610
+ const k = F || p, ee = ve(() => o, [o]), ce = ve(() => i, [i]), se = ve(
1611
+ () => ({
1612
+ layout: u,
1613
+ uiConfig: o,
1614
+ updateFieldSchema: i
1615
+ }),
1616
+ [u, o, i]
1617
+ );
1618
+ return $ ? /* @__PURE__ */ V.jsxs(Qt, { ...O, children: [
1619
+ /* @__PURE__ */ V.jsx(
1620
+ Dr,
1621
+ {
1622
+ onDirtyChange: A,
1623
+ onValuesChange: T,
1624
+ onFieldChange: b
1611
1625
  }
1612
- }));
1613
- const k = F || p, ee = ve(() => o, [o]), ce = ve(() => i, [i]), se = ve(
1614
- () => ({
1615
- layout: u,
1616
- uiConfig: o,
1617
- updateFieldSchema: i
1618
- }),
1619
- [u, o, i]
1620
- );
1621
- return $ ? /* @__PURE__ */ V.jsxs(Qt, { ...O, children: [
1622
- /* @__PURE__ */ V.jsx(
1623
- Dr,
1624
- {
1625
- onDirtyChange: A,
1626
- onValuesChange: T,
1627
- onFieldChange: b
1628
- }
1629
- ),
1630
- /* @__PURE__ */ V.jsxs(
1631
- vr,
1632
- {
1633
- layout: se.layout,
1634
- uiConfig: ee,
1635
- updateFieldSchema: ce,
1636
- children: [
1637
- ["vertical", "horizontal"].includes(u) && /* @__PURE__ */ V.jsx(
1638
- "div",
1639
- {
1640
- style: {
1641
- display: "flex",
1642
- flexDirection: u === "vertical" ? "column" : "row"
1643
- },
1644
- children: /* @__PURE__ */ V.jsx(Le, { schema: C })
1645
- }
1646
- ),
1647
- u === "custom" && /* @__PURE__ */ V.jsx(Le, { schema: C }),
1648
- !k && /* @__PURE__ */ V.jsx("button", { style: { marginTop: "1rem" }, onClick: G, children: "Submit" })
1649
- ]
1650
- }
1651
- )
1652
- ] }) : /* @__PURE__ */ V.jsx(V.Fragment, { children: B ?? /* @__PURE__ */ V.jsx(
1653
- "div",
1626
+ ),
1627
+ /* @__PURE__ */ V.jsxs(
1628
+ vr,
1654
1629
  {
1655
- style: {
1656
- padding: "2rem",
1657
- textAlign: "center",
1658
- color: "#666",
1659
- fontSize: "0.9rem"
1660
- },
1661
- children: "Loading form..."
1630
+ layout: se.layout,
1631
+ uiConfig: ee,
1632
+ updateFieldSchema: ce,
1633
+ children: [
1634
+ ["vertical", "horizontal"].includes(u) && /* @__PURE__ */ V.jsx(
1635
+ "div",
1636
+ {
1637
+ style: {
1638
+ display: "flex",
1639
+ flexDirection: u === "vertical" ? "column" : "row"
1640
+ },
1641
+ children: /* @__PURE__ */ V.jsx(Le, { schema: C })
1642
+ }
1643
+ ),
1644
+ u === "custom" && /* @__PURE__ */ V.jsx(Le, { schema: C }),
1645
+ !k && /* @__PURE__ */ V.jsx("button", { style: { marginTop: "1rem" }, onClick: G, children: "Submit" })
1646
+ ]
1662
1647
  }
1663
- ) });
1664
- }
1665
- );
1648
+ )
1649
+ ] }) : /* @__PURE__ */ V.jsx(V.Fragment, { children: B ?? /* @__PURE__ */ V.jsx(
1650
+ "div",
1651
+ {
1652
+ style: {
1653
+ padding: "2rem",
1654
+ textAlign: "center",
1655
+ color: "#666",
1656
+ fontSize: "0.9rem"
1657
+ },
1658
+ children: "Loading form..."
1659
+ }
1660
+ ) });
1661
+ });
1666
1662
  export {
1667
1663
  Pr as AutoForm,
1668
1664
  Le as SchemaRenderer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoforma",
3
- "version": "2.9.9",
3
+ "version": "2.9.92",
4
4
  "description": "AutoForma is a headless dynamic form builder based on React Hook Form",
5
5
  "type": "module",
6
6
  "sideEffects": false,