@connect-soft/form-generator 1.0.0-alpha → 1.1.0-alpha10
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/README.md +1102 -28
- package/dist/index.js +1184 -391
- package/dist/index.js.map +1 -1
- package/dist/{index.m.js → index.mjs} +1163 -389
- package/dist/index.mjs.map +1 -0
- package/dist/types/components/form/array-field-renderer.d.ts +39 -0
- package/dist/types/components/form/array-field-renderer.d.ts.map +1 -0
- package/dist/types/components/form/create-template-fields.d.ts +3 -0
- package/dist/types/components/form/create-template-fields.d.ts.map +1 -0
- package/dist/types/components/form/field-renderer.d.ts +1 -6
- package/dist/types/components/form/field-renderer.d.ts.map +1 -1
- package/dist/types/components/form/fields-context.d.ts +26 -0
- package/dist/types/components/form/fields-context.d.ts.map +1 -0
- package/dist/types/components/form/form-generator-typed.d.ts +47 -0
- package/dist/types/components/form/form-generator-typed.d.ts.map +1 -0
- package/dist/types/components/form/form-generator.d.ts +43 -6
- package/dist/types/components/form/form-generator.d.ts.map +1 -1
- package/dist/types/components/form/form-utils.d.ts +47 -0
- package/dist/types/components/form/form-utils.d.ts.map +1 -0
- package/dist/types/components/form/index.d.ts +5 -3
- package/dist/types/components/form/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +13 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/field-registry.d.ts +19 -59
- package/dist/types/lib/field-registry.d.ts.map +1 -1
- package/dist/types/lib/field-types.d.ts +127 -26
- package/dist/types/lib/field-types.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +3 -4
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/template-types.d.ts +55 -0
- package/dist/types/lib/template-types.d.ts.map +1 -0
- package/package.json +11 -25
- package/MIGRATION.md +0 -503
- package/dist/index.m.js.map +0 -1
- package/dist/styles/globals.css +0 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { UseFieldArrayReturn, FieldValues } from 'react-hook-form';
|
|
3
|
+
import type { ArrayField } from '@/lib/field-types';
|
|
4
|
+
export interface ArrayFieldItemProps {
|
|
5
|
+
index: number;
|
|
6
|
+
id: string;
|
|
7
|
+
remove: () => void;
|
|
8
|
+
move: (toIndex: number) => void;
|
|
9
|
+
fields: Record<string, ReactElement>;
|
|
10
|
+
fieldNames: string[];
|
|
11
|
+
namePrefix: string;
|
|
12
|
+
}
|
|
13
|
+
export type ArrayFieldItemRenderFn = (props: ArrayFieldItemProps) => ReactElement;
|
|
14
|
+
export interface ArrayFieldRendererProps {
|
|
15
|
+
field: ArrayField;
|
|
16
|
+
children?: ArrayFieldItemRenderFn;
|
|
17
|
+
}
|
|
18
|
+
export interface UseArrayFieldReturn {
|
|
19
|
+
fieldArray: UseFieldArrayReturn<FieldValues, string>;
|
|
20
|
+
append: () => void;
|
|
21
|
+
appendWith: (values: Record<string, unknown>) => void;
|
|
22
|
+
prepend: () => void;
|
|
23
|
+
remove: (index: number) => void;
|
|
24
|
+
move: (from: number, to: number) => void;
|
|
25
|
+
swap: (indexA: number, indexB: number) => void;
|
|
26
|
+
insert: (index: number, values?: Record<string, unknown>) => void;
|
|
27
|
+
field: ArrayField;
|
|
28
|
+
items: Array<{
|
|
29
|
+
id: string;
|
|
30
|
+
index: number;
|
|
31
|
+
}>;
|
|
32
|
+
canAppend: boolean;
|
|
33
|
+
canRemove: boolean;
|
|
34
|
+
renderField: (index: number, fieldName: string) => ReactElement;
|
|
35
|
+
renderItem: (index: number) => Record<string, ReactElement>;
|
|
36
|
+
}
|
|
37
|
+
export declare function useArrayField(field: ArrayField): UseArrayFieldReturn;
|
|
38
|
+
export declare const ArrayFieldRenderer: import("react").MemoExoticComponent<({ field, children }: ArrayFieldRendererProps) => import("react/jsx-runtime").JSX.Element | null>;
|
|
39
|
+
//# sourceMappingURL=array-field-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-field-render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C,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAElE,KAAK,EAAE,UAAU,CAAC;IAElB,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE5C,SAAS,EAAE,OAAO,CAAC;IAEnB,SAAS,EAAE,OAAO,CAAC;IAEnB,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC;IAEhE,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC/D;AAMD,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,mBAAmB,CAwGpE;AA0BD,eAAO,MAAM,kBAAkB,4DAA8B,uBAAuB,oDA6ClF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-template-fields.d.ts","sourceRoot":"","sources":["../../../../src/components/form/create-template-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAWvE,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,cAAc,CAoF1F"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { BaseField
|
|
1
|
+
import { BaseField } from '@/lib';
|
|
2
2
|
export interface FieldRendererProps {
|
|
3
3
|
field: BaseField;
|
|
4
4
|
namePrefix?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare const FieldRenderer: import("react").MemoExoticComponent<({ field, namePrefix }: FieldRendererProps) => import("react/jsx-runtime").JSX.Element | null>;
|
|
7
|
-
export interface FormItemRendererProps {
|
|
8
|
-
item: FormItem;
|
|
9
|
-
namePrefix?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare const FormItemRenderer: import("react").MemoExoticComponent<({ item, namePrefix }: FormItemRendererProps) => import("react/jsx-runtime").JSX.Element | null>;
|
|
12
7
|
//# sourceMappingURL=field-renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-renderer.d.ts","sourceRoot":"","sources":["../../../../src/components/form/field-renderer.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"field-renderer.d.ts","sourceRoot":"","sources":["../../../../src/components/form/field-renderer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AAMrD,MAAM,WAAW,kBAAkB;IAC/B,KAAK,EAAE,SAAS,CAAC;IAEjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,aAAa,8DAAgC,kBAAkB,oDAiD1E,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode, Ref } from 'react';
|
|
2
|
+
import type { FieldState } from '@/lib/field-registry';
|
|
3
|
+
import type { BaseField, FormItem } from '@/lib/field-types';
|
|
4
|
+
export interface FieldProps<TValue = unknown> {
|
|
5
|
+
name: string;
|
|
6
|
+
value: TValue;
|
|
7
|
+
onChange: (value: TValue) => void;
|
|
8
|
+
onBlur: () => void;
|
|
9
|
+
ref: Ref<any>;
|
|
10
|
+
field: BaseField;
|
|
11
|
+
fieldState: FieldState;
|
|
12
|
+
}
|
|
13
|
+
interface FieldsContextValue {
|
|
14
|
+
fields: Map<string, BaseField>;
|
|
15
|
+
namePrefix?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface FieldsProviderProps {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
fields: readonly FormItem[];
|
|
20
|
+
namePrefix?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function FieldsProvider({ children, fields, namePrefix }: FieldsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare function useFieldProps<TValue = unknown>(name: string): FieldProps<TValue>;
|
|
24
|
+
export declare function useFieldsContext(): FieldsContextValue | null;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=fields-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields-context.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEhF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAK7D,MAAM,WAAW,UAAU,CAAC,MAAM,GAAG,OAAO;IAExC,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE,MAAM,CAAC;IAEd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAElC,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEd,KAAK,EAAE,SAAS,CAAC;IAEjB,UAAU,EAAE,UAAU,CAAC;CAC1B;AAKD,UAAU,kBAAkB;IAExB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE/B,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAOD,MAAM,WAAW,mBAAmB;IAChC,QAAQ,EAAE,SAAS,CAAC;IAEpB,MAAM,EAAE,SAAS,QAAQ,EAAE,CAAC;IAE5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAKD,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,mBAAmB,2CAsCnF;AA8BD,wBAAgB,aAAa,CAAC,MAAM,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CA6ChF;AAKD,wBAAgB,gBAAgB,IAAI,kBAAkB,GAAG,IAAI,CAE5D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FieldValues } from 'react-hook-form';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { BaseField } from '@/lib';
|
|
5
|
+
import type { RegisteredFieldType } from '@/lib/field-types';
|
|
6
|
+
import type { TemplateRenderFn } from '@/lib/template-types';
|
|
7
|
+
import type { ValidateTypesOptions, FormGeneratorRef, FormSubmitContext } from './form-generator';
|
|
8
|
+
type FieldTypeForValue<T> = T extends string ? 'text' | 'email' | 'password' | 'tel' | 'url' | 'search' | 'textarea' | 'select' | 'radio' | 'time' | 'month' | 'week' | 'color' | 'hidden' : T extends number ? 'number' | 'range' : T extends boolean ? 'checkbox' | 'switch' : T extends Date ? 'date' | 'datetime' | 'datetime-local' : T extends File | FileList ? 'file' : T extends Array<unknown> ? 'array' : RegisteredFieldType;
|
|
9
|
+
export type TypedField<TSchema extends z.ZodType, TKey extends keyof z.infer<TSchema> & string> = BaseField & {
|
|
10
|
+
name: TKey;
|
|
11
|
+
type: FieldTypeForValue<z.infer<TSchema>[TKey]>;
|
|
12
|
+
} & Record<string, unknown>;
|
|
13
|
+
export declare function typedField<TSchema extends z.ZodType>(): <TKey extends keyof z.infer<TSchema> & string>(field: TypedField<TSchema, TKey>) => TypedField<TSchema, TKey>;
|
|
14
|
+
export declare function typedFields<TSchema extends z.ZodType>(fields: Array<TypedField<TSchema, keyof z.infer<TSchema> & string>>): Array<TypedField<TSchema, keyof z.infer<TSchema> & string>>;
|
|
15
|
+
export interface StrictFormGeneratorProps<TSchema extends z.ZodType<FieldValues>> {
|
|
16
|
+
schema: TSchema;
|
|
17
|
+
fields: Array<TypedField<TSchema, keyof z.infer<TSchema> & string> & Record<string, unknown>>;
|
|
18
|
+
onSubmit: (values: z.infer<TSchema>, context: FormSubmitContext<z.infer<TSchema>>) => void | Promise<void>;
|
|
19
|
+
defaultValues?: Partial<z.infer<TSchema>>;
|
|
20
|
+
className?: string;
|
|
21
|
+
submitText?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
mode?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';
|
|
24
|
+
title?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
showReset?: boolean;
|
|
27
|
+
resetText?: string;
|
|
28
|
+
children?: TemplateRenderFn<z.infer<TSchema>>;
|
|
29
|
+
ref?: React.Ref<FormGeneratorRef<z.infer<TSchema>>>;
|
|
30
|
+
validateTypes?: boolean | ValidateTypesOptions;
|
|
31
|
+
}
|
|
32
|
+
export declare function StrictFormGenerator<TSchema extends z.ZodType<FieldValues>>(props: StrictFormGeneratorProps<TSchema>): React.ReactElement;
|
|
33
|
+
export declare function createFieldFactory<TSchema extends z.ZodType<FieldValues>>(_schema: TSchema): <TKey extends keyof z.infer<TSchema> & string>(field: {
|
|
34
|
+
name: TKey;
|
|
35
|
+
type: FieldTypeForValue<z.infer<TSchema>[TKey]>;
|
|
36
|
+
} & Omit<BaseField, "name" | "type"> & Record<string, unknown>) => {
|
|
37
|
+
name: TKey;
|
|
38
|
+
type: FieldTypeForValue<z.infer<TSchema>[TKey]>;
|
|
39
|
+
} & Omit<BaseField<string, any>, "name" | "type"> & Record<string, unknown>;
|
|
40
|
+
export type InferSchema<TSchema extends z.ZodType> = z.infer<TSchema>;
|
|
41
|
+
export type ValidateFieldsComplete<TSchema extends z.ZodType, TFields extends Array<{
|
|
42
|
+
name: string;
|
|
43
|
+
}>> = Exclude<keyof z.infer<TSchema>, TFields[number]['name']> extends never ? TFields : {
|
|
44
|
+
__error: `Missing fields: ${Exclude<keyof z.infer<TSchema> & string, TFields[number]['name']>}`;
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=form-generator-typed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-generator-typed.d.ts","sourceRoot":"","sources":["../../../../src/components/form/form-generator-typed.tsx"],"names":[],"mappings":"AACA,OAAO,KAA0E,MAAM,OAAO,CAAC;AAC/F,OAAO,EAAwC,WAAW,EAAe,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEH,SAAS,EAMZ,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EACR,gBAAgB,EAKnB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AASlG,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAEhC,MAAM,GACN,OAAO,GACP,UAAU,GACV,KAAK,GACL,KAAK,GACL,QAAQ,GACR,UAAU,GACV,QAAQ,GACR,OAAO,GACP,MAAM,GACN,OAAO,GACP,MAAM,GACN,OAAO,GACP,QAAQ,GACd,CAAC,SAAS,MAAM,GACd,QAAQ,GAAG,OAAO,GAClB,CAAC,SAAS,OAAO,GACf,UAAU,GAAG,QAAQ,GACrB,CAAC,SAAS,IAAI,GACZ,MAAM,GAAG,UAAU,GAAG,gBAAgB,GACtC,CAAC,SAAS,IAAI,GAAG,QAAQ,GACvB,MAAM,GACN,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC,GACtB,OAAO,GACP,mBAAmB,CAAC;AAKpC,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,SAAS,GAAG;IAC1G,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IA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W,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAKtE,MAAM,MAAM,sBAAsB,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,EAAE,OAAO,SAAS,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,IACjG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAChE,OAAO,GACP;IAAE,OAAO,EAAE,mBAAmB,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAA;CAAE,CAAC"}
|
|
@@ -1,14 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UseFormReturn, FieldValues, FieldErrors } from 'react-hook-form';
|
|
3
|
+
import { FormItem, InferFormValues } from '@/lib';
|
|
4
|
+
import type { TemplateRenderFn } from '@/lib/template-types';
|
|
5
|
+
export interface ValidateTypesOptions {
|
|
6
|
+
throwOnError?: boolean;
|
|
7
|
+
warn?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface FormSubmitContext<TValues extends FieldValues = FieldValues> {
|
|
10
|
+
isDirty: boolean;
|
|
11
|
+
dirtyFields: Partial<Record<keyof TValues, boolean>>;
|
|
12
|
+
isValid: boolean;
|
|
13
|
+
errors: FieldErrors<TValues>;
|
|
14
|
+
touchedFields: Partial<Record<keyof TValues, boolean>>;
|
|
15
|
+
isSubmitting: boolean;
|
|
16
|
+
submitCount: number;
|
|
17
|
+
defaultValues: Partial<TValues>;
|
|
18
|
+
form: UseFormReturn<TValues>;
|
|
19
|
+
}
|
|
3
20
|
export interface FormGeneratorProps<TFields extends readonly FormItem[]> {
|
|
4
21
|
fields: TFields;
|
|
5
|
-
onSubmit: (values:
|
|
6
|
-
defaultValues?:
|
|
7
|
-
schema?: z.ZodType<any>;
|
|
22
|
+
onSubmit: (values: InferFormValues<TFields>, context: FormSubmitContext<InferFormValues<TFields>>) => void | Promise<void>;
|
|
23
|
+
defaultValues?: Partial<InferFormValues<TFields>>;
|
|
8
24
|
className?: string;
|
|
9
25
|
submitText?: string;
|
|
10
26
|
disabled?: boolean;
|
|
11
27
|
mode?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';
|
|
28
|
+
title?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
showReset?: boolean;
|
|
31
|
+
resetText?: string;
|
|
32
|
+
children?: TemplateRenderFn<InferFormValues<TFields>>;
|
|
33
|
+
ref?: React.Ref<FormGeneratorRef<InferFormValues<TFields>>>;
|
|
34
|
+
validateTypes?: boolean | ValidateTypesOptions;
|
|
35
|
+
}
|
|
36
|
+
export interface FormGeneratorRef<TValues extends FieldValues = FieldValues> {
|
|
37
|
+
setValues: (values: Partial<TValues>) => void;
|
|
38
|
+
getValues: () => TValues;
|
|
39
|
+
reset: (values?: Partial<TValues>) => void;
|
|
40
|
+
submit: () => Promise<void>;
|
|
41
|
+
clearErrors: () => void;
|
|
42
|
+
setError: (name: keyof TValues, error: {
|
|
43
|
+
type: string;
|
|
44
|
+
message: string;
|
|
45
|
+
}) => void;
|
|
46
|
+
isValid: () => boolean;
|
|
47
|
+
isDirty: () => boolean;
|
|
48
|
+
form: UseFormReturn<TValues>;
|
|
12
49
|
}
|
|
13
|
-
export declare function FormGenerator<TFields extends readonly FormItem[]>(
|
|
50
|
+
export declare function FormGenerator<TFields extends readonly FormItem[]>(props: FormGeneratorProps<TFields>): React.ReactElement;
|
|
14
51
|
//# sourceMappingURL=form-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-generator.d.ts","sourceRoot":"","sources":["../../../../src/components/form/form-generator.tsx"],"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IAEvB,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAChC;AA4CD,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,QAAQ,EAAE,EAC7D,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACnC,KAAK,CAAC,YAAY,CA+PpB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BaseField, FormItem } from '@/lib';
|
|
3
|
+
export declare function isSchemaRequired(schema: z.ZodTypeAny): boolean;
|
|
4
|
+
export declare function unwrapSchema(schema: z.ZodTypeAny): z.ZodTypeAny;
|
|
5
|
+
export declare function getSchemaTypeName(schema: z.ZodTypeAny): string;
|
|
6
|
+
export interface NumberConstraints {
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
step?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface StringConstraints {
|
|
12
|
+
minLength?: number;
|
|
13
|
+
maxLength?: number;
|
|
14
|
+
pattern?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface DateConstraints {
|
|
17
|
+
min?: Date;
|
|
18
|
+
max?: Date;
|
|
19
|
+
}
|
|
20
|
+
export declare function getNumberConstraints(schema: z.ZodTypeAny): NumberConstraints;
|
|
21
|
+
export declare function getStringConstraints(schema: z.ZodTypeAny): StringConstraints;
|
|
22
|
+
export declare function getDateConstraints(schema: z.ZodTypeAny): DateConstraints;
|
|
23
|
+
export declare function getSchemaRequirements<T extends z.ZodRawShape>(schema: z.ZodObject<T>): Record<keyof T, boolean>;
|
|
24
|
+
export interface SchemaFieldInfo {
|
|
25
|
+
name: string;
|
|
26
|
+
required: boolean;
|
|
27
|
+
type: string;
|
|
28
|
+
schema: z.ZodTypeAny;
|
|
29
|
+
min?: number;
|
|
30
|
+
max?: number;
|
|
31
|
+
step?: number;
|
|
32
|
+
minLength?: number;
|
|
33
|
+
maxLength?: number;
|
|
34
|
+
pattern?: string;
|
|
35
|
+
minDate?: Date;
|
|
36
|
+
maxDate?: Date;
|
|
37
|
+
}
|
|
38
|
+
export declare function analyzeSchema<T extends z.ZodRawShape>(schema: z.ZodObject<T>): SchemaFieldInfo[];
|
|
39
|
+
export declare function mergeSchemaRequirements<T extends z.ZodRawShape, F extends BaseField>(schema: z.ZodObject<T>, fields: readonly F[]): F[];
|
|
40
|
+
export declare function mergeSchemaConstraints<T extends z.ZodRawShape, F extends BaseField>(schema: z.ZodObject<T>, fields: readonly F[]): F[];
|
|
41
|
+
export declare function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown>;
|
|
42
|
+
export declare function getValidatorForField(field: BaseField): z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>> | z.ZodAny;
|
|
43
|
+
export declare function buildSchema<Fields extends readonly FormItem[]>(fields: Fields): z.ZodObject<{
|
|
44
|
+
[x: string]: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
export declare function buildDefaultValues(fields: readonly FormItem[]): Record<string, unknown>;
|
|
47
|
+
//# sourceMappingURL=form-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-utils.d.ts","sourceRoot":"","sources":["../../../../src/components/form/form-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,SAAS,EAAE,QAAQ,EAA4B,MAAM,OAAO,CAAC;AASzF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CAE9D;AAKD,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAa/D;AAKD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,CAkB9D;AAKD,MAAM,WAAW,iBAAiB;IAC9B,GAAG,CAAC,EAAE,MAAM,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AS,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,eAAe,EAAE,CAuChG;AAyBD,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC,SAAS,SAAS,EAChF,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,MAAM,EAAE,SAAS,CAAC,EAAE,GACrB,CAAC,EAAE,CAaL;AAiCD,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC,SAAS,SAAS,EAC/E,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,MAAM,EAAE,SAAS,CAAC,EAAE,GACrB,CAAC,EAAE,CA4DL;AAKD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmBnH;AAiDD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,8EAsBpD;AA0BD,wBAAgB,WAAW,CAAC,MAAM,SAAS,SAAS,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM;;kBA0B7E;AAmBD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqBvF"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export { FieldRenderer
|
|
2
|
-
export type { FieldRendererProps
|
|
1
|
+
export { FieldRenderer } from './field-renderer';
|
|
2
|
+
export type { FieldRendererProps } from './field-renderer';
|
|
3
3
|
export { FormGenerator } from './form-generator';
|
|
4
|
-
export type { FormGeneratorProps } from './form-generator';
|
|
4
|
+
export type { FormGeneratorProps, FormGeneratorRef } from './form-generator';
|
|
5
|
+
export { ArrayFieldRenderer, useArrayField } from './array-field-renderer';
|
|
6
|
+
export type { ArrayFieldRendererProps, ArrayFieldItemProps, ArrayFieldItemRenderFn, UseArrayFieldReturn } from './array-field-renderer';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/form/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/form/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC3E,YAAY,EACR,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACtB,MAAM,wBAAwB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
export { FormGenerator } from './components/form/form-generator';
|
|
2
|
-
export type { FormGeneratorProps } from './components/form/form-generator';
|
|
1
|
+
export { FormGenerator, type ValidateTypesOptions } from './components/form/form-generator';
|
|
2
|
+
export type { FormGeneratorProps, FormGeneratorRef, FormSubmitContext } from './components/form/form-generator';
|
|
3
3
|
export { FieldRenderer } from './components/form/field-renderer';
|
|
4
4
|
export type { FieldRendererProps } from './components/form/field-renderer';
|
|
5
|
+
export { StrictFormGenerator, typedField, typedFields, createFieldFactory } from './components/form/form-generator-typed';
|
|
6
|
+
export type { StrictFormGeneratorProps, TypedField, InferSchema, ValidateFieldsComplete } from './components/form/form-generator-typed';
|
|
7
|
+
export { ArrayFieldRenderer, useArrayField } from './components/form/array-field-renderer';
|
|
8
|
+
export type { ArrayFieldRendererProps, ArrayFieldItemProps, ArrayFieldItemRenderFn, UseArrayFieldReturn } from './components/form/array-field-renderer';
|
|
9
|
+
export { useFieldProps, FieldsProvider, useFieldsContext } from './components/form/fields-context';
|
|
10
|
+
export type { FieldProps, FieldsProviderProps } from './components/form/fields-context';
|
|
11
|
+
export { isSchemaRequired, unwrapSchema, getSchemaTypeName, getSchemaRequirements, getNumberConstraints, getStringConstraints, getDateConstraints, analyzeSchema, mergeSchemaRequirements, mergeSchemaConstraints } from './components/form/form-utils';
|
|
12
|
+
export type { SchemaFieldInfo, NumberConstraints, StringConstraints, DateConstraints } from './components/form/form-utils';
|
|
13
|
+
export type { TemplateFields, TemplateButtons, TemplateRenderProps, TemplateRenderFn, TemplateArrayField, TemplateArrayItem } from './lib/template-types';
|
|
5
14
|
export * from './lib/field-types';
|
|
6
15
|
export { registerField, registerFields, getFieldComponent, hasFieldType, unregisterField, getRegisteredFieldTypes, clearFieldRegistry } from './lib/field-registry';
|
|
7
|
-
export type { FieldComponentProps, FieldComponent,
|
|
16
|
+
export type { FieldComponentProps, FieldComponent, FieldDefinition, FieldDefinitionsMap } from './lib/field-registry';
|
|
8
17
|
export { registerFormComponents, registerFormComponent, getFormComponent, hasFormComponent, getFormComponents, clearFormComponentRegistry, resetFormComponentRegistry, clearAllRegistries } from './lib/field-registry';
|
|
9
|
-
export type { FormComponents,
|
|
10
|
-
export { registerLayoutComponents, registerLayoutComponent, getLayoutComponent, hasLayoutComponent, clearLayoutRegistry } from './lib/field-registry';
|
|
11
|
-
export type { LayoutComponents, ColumnsLayoutProps, SectionLayoutProps } from './lib/field-registry';
|
|
18
|
+
export type { FormComponents, SubmitButtonProps, FieldWrapperProps, FieldsWrapperProps } from './lib/field-registry';
|
|
12
19
|
export { useForm, useFormContext, useWatch, useFieldArray, Controller, FormProvider } from 'react-hook-form';
|
|
13
20
|
export type { FieldValues, UseFormReturn, FieldPath, ControllerRenderProps } from 'react-hook-form';
|
|
14
21
|
export { z } from 'zod';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC5F,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAChH,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAG3E,OAAO,EACH,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,kBAAkB,EACrB,MAAM,wCAAwC,CAAC;AAChD,YAAY,EACR,wBAAwB,EACxB,UAAU,EACV,WAAW,EACX,sBAAsB,EACzB,MAAM,wCAAwC,CAAC;AAGhD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAC3F,YAAY,EACR,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACtB,MAAM,wCAAwC,CAAC;AAGhD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACnG,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAGxF,OAAO,EACH,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACzB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACR,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAClB,MAAM,8BAA8B,CAAC;AAGtC,YAAY,EACR,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACpB,MAAM,sBAAsB,CAAC;AAG9B,cAAc,mBAAmB,CAAC;AAGlC,OAAO,EACH,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGtH,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,0BAA0B,EAC1B,0BAA0B,EAC1B,kBAAkB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGrH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC7G,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGpG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { BaseField,
|
|
2
|
+
import type { BaseField, RegisteredFieldType, FieldByType } from './field-types';
|
|
3
3
|
import type { ComponentType, ReactNode, Ref } from 'react';
|
|
4
4
|
export type ValidatorFactory<TField extends BaseField = BaseField> = (field: TField) => z.ZodType<any>;
|
|
5
5
|
export interface FieldState {
|
|
@@ -24,89 +24,49 @@ export interface FieldComponentProps<TField extends BaseField = BaseField> {
|
|
|
24
24
|
}
|
|
25
25
|
export type FieldComponent<TField extends BaseField = BaseField> = ComponentType<FieldComponentProps<TField>>;
|
|
26
26
|
export interface FieldRegistrationOptions {
|
|
27
|
-
className?: string;
|
|
28
|
-
labelClassName?: string;
|
|
29
|
-
inputLabelWrapper?: string;
|
|
30
|
-
inputLabelWrapperOrientation?: FormInputLabelWrapperProps['orientation'];
|
|
31
|
-
descriptionClassName?: string;
|
|
32
|
-
messageClassName?: string;
|
|
33
27
|
validator?: ValidatorFactory<any>;
|
|
34
28
|
}
|
|
35
|
-
export interface
|
|
29
|
+
export interface SubmitButtonProps {
|
|
36
30
|
className?: string;
|
|
37
31
|
children: ReactNode;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
isSubmitting?: boolean;
|
|
38
34
|
}
|
|
39
|
-
export interface
|
|
40
|
-
className?: string;
|
|
41
|
-
orientation?: 'horizontal' | 'vertical';
|
|
35
|
+
export interface FieldWrapperProps {
|
|
42
36
|
children: ReactNode;
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
name: string;
|
|
38
|
+
type: string;
|
|
45
39
|
className?: string;
|
|
46
|
-
children: ReactNode;
|
|
47
|
-
required?: boolean;
|
|
48
|
-
htmlFor?: string;
|
|
49
40
|
}
|
|
50
|
-
export interface
|
|
51
|
-
className?: string;
|
|
41
|
+
export interface FieldsWrapperProps {
|
|
52
42
|
children: ReactNode;
|
|
53
|
-
}
|
|
54
|
-
export interface FormMessageProps {
|
|
55
|
-
className?: string;
|
|
56
|
-
name: string;
|
|
57
|
-
}
|
|
58
|
-
export interface SubmitButtonProps {
|
|
59
43
|
className?: string;
|
|
60
|
-
children: ReactNode;
|
|
61
|
-
disabled?: boolean;
|
|
62
|
-
isSubmitting?: boolean;
|
|
63
44
|
}
|
|
64
45
|
export interface FormComponents {
|
|
65
|
-
FormItem: ComponentType<FormItemProps>;
|
|
66
|
-
FormInputLabelWrapper: ComponentType<FormInputLabelWrapperProps>;
|
|
67
|
-
FormLabel: ComponentType<FormLabelProps>;
|
|
68
|
-
FormDescription: ComponentType<FormDescriptionProps>;
|
|
69
|
-
FormMessage: ComponentType<FormMessageProps>;
|
|
70
46
|
SubmitButton: ComponentType<SubmitButtonProps>;
|
|
47
|
+
FieldWrapper: ComponentType<FieldWrapperProps>;
|
|
48
|
+
FieldsWrapper: ComponentType<FieldsWrapperProps>;
|
|
71
49
|
}
|
|
72
|
-
export
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
export interface SectionLayoutProps {
|
|
77
|
-
layout: SectionLayout;
|
|
78
|
-
renderItem: (item: FormItem, index: number) => ReactNode;
|
|
79
|
-
}
|
|
80
|
-
export interface LayoutComponents {
|
|
81
|
-
Columns: ComponentType<ColumnsLayoutProps>;
|
|
82
|
-
Section: ComponentType<SectionLayoutProps>;
|
|
83
|
-
}
|
|
84
|
-
export interface RegistrationConfig {
|
|
85
|
-
override?: boolean | 'only';
|
|
86
|
-
}
|
|
87
|
-
export declare function registerField<TField extends BaseField>(type: TField['type'], component: FieldComponent<TField>, options?: FieldRegistrationOptions, config?: RegistrationConfig): void;
|
|
88
|
-
export type FieldDefinition = FieldComponent<any> | {
|
|
89
|
-
component: FieldComponent<any>;
|
|
50
|
+
export declare function registerField<TType extends RegisteredFieldType>(type: TType, component: FieldComponent<FieldByType<TType>>, options?: FieldRegistrationOptions): void;
|
|
51
|
+
export type FieldDefinition<TType extends RegisteredFieldType = RegisteredFieldType> = FieldComponent<FieldByType<TType>> | {
|
|
52
|
+
component: FieldComponent<FieldByType<TType>>;
|
|
90
53
|
options?: FieldRegistrationOptions;
|
|
91
54
|
};
|
|
92
|
-
export
|
|
55
|
+
export type FieldDefinitionsMap = {
|
|
56
|
+
[TType in RegisteredFieldType]?: FieldDefinition<TType>;
|
|
57
|
+
};
|
|
58
|
+
export declare function registerFields(fields: FieldDefinitionsMap): void;
|
|
93
59
|
export declare function getFieldComponent<TField extends BaseField>(type: string): FieldComponent<TField>;
|
|
94
|
-
export declare function getFieldClassName(type: string): string | undefined;
|
|
95
60
|
export declare function getFieldOptions(type: string): FieldRegistrationOptions | undefined;
|
|
96
61
|
export declare function getFieldValidator(type: string): ValidatorFactory<any> | undefined;
|
|
97
62
|
export declare function hasFieldType(type: string): boolean;
|
|
98
63
|
export declare function unregisterField(type: string): boolean;
|
|
99
64
|
export declare function getRegisteredFieldTypes(): string[];
|
|
100
|
-
export declare function registerFormComponents(components: Partial<FormComponents
|
|
101
|
-
export declare function registerFormComponent<K extends keyof FormComponents>(name: K, component: FormComponents[K]
|
|
65
|
+
export declare function registerFormComponents(components: Partial<FormComponents>): void;
|
|
66
|
+
export declare function registerFormComponent<K extends keyof FormComponents>(name: K, component: FormComponents[K]): void;
|
|
102
67
|
export declare function getFormComponent<K extends keyof FormComponents>(name: K): FormComponents[K];
|
|
103
68
|
export declare function hasFormComponent(name: keyof FormComponents): boolean;
|
|
104
69
|
export declare function getFormComponents(): Partial<FormComponents>;
|
|
105
|
-
export declare function registerLayoutComponents(components: Partial<LayoutComponents>, config?: RegistrationConfig): void;
|
|
106
|
-
export declare function registerLayoutComponent<K extends keyof LayoutComponents>(name: K, component: LayoutComponents[K], config?: RegistrationConfig): void;
|
|
107
|
-
export declare function getLayoutComponent<K extends keyof LayoutComponents>(name: K): LayoutComponents[K] | undefined;
|
|
108
|
-
export declare function hasLayoutComponent(name: keyof LayoutComponents): boolean;
|
|
109
|
-
export declare function clearLayoutRegistry(): void;
|
|
110
70
|
export declare function clearFieldRegistry(): void;
|
|
111
71
|
export declare function clearFormComponentRegistry(): void;
|
|
112
72
|
export declare function resetFormComponentRegistry(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-registry.d.ts","sourceRoot":"","sources":["../../../src/lib/field-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"field-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