@formvk/react 0.0.0-stage → 0.1.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.
@@ -0,0 +1,231 @@
1
+ import { AnyComponent } from '@formvk/schema';
2
+ import { ComponentProps as ComponentProps_2 } from 'react';
3
+ import { ComponentType } from 'react';
4
+ import { Form } from '@formvk/core';
5
+ import { FormPathPattern } from '@formvk/shared';
6
+ import { Fragment } from '@formvk/schema';
7
+ import { GeneralField } from '@formvk/core';
8
+ import { IFieldFactoryProps } from '@formvk/core';
9
+ import { IFormProps } from '@formvk/core';
10
+ import { ISchema } from '@formvk/schema';
11
+ import { JSX } from 'react';
12
+ import { NamedExoticComponent } from 'react';
13
+ import { ObjectField } from '@formvk/core';
14
+ import { PropsWithChildren } from 'react';
15
+ import { ReactFC } from '@formvk/reactive-react';
16
+ import { ReactNode } from 'react';
17
+ import { Schema } from '@formvk/schema';
18
+ import { SchemaKey } from '@formvk/schema';
19
+ import { SchemaPatchInput } from '@formvk/schema';
20
+ import { TPropsOfComponent } from '@formvk/schema';
21
+
22
+ /** 提取 React 组件定义的 props 类型;非组件类型退化为 never。 */
23
+ export declare type ComponentProps<T> = T extends ReactComponent ? ComponentProps_2<T> : never;
24
+
25
+ export declare function connect<T extends ReactComponent>(target: T, ...args: IComponentMapper[]): T;
26
+
27
+ /**
28
+ * React 侧表单工厂:core 的 Form 自身管理响应式状态,
29
+ * React 不会自动代理普通对象,无需 Vue 侧的 markRaw 处理。
30
+ */
31
+ export declare function createForm<T extends object = any>(options?: IFormProps<T>): Form<T>;
32
+
33
+ /**
34
+ * 基于扁平组件映射与分类组件 map 创建 SchemaField + fragment:
35
+ * - voidComponents / arrayComponents 只接收组件 map,分类名由工厂内部提取后传给 fragment
36
+ * - 分类组件会自动合并进运行时组件映射,无需在 components 中重复注册
37
+ * - 返回的 SchemaField 已预绑定拍平后的组件与 scope,props 仍可传扁平 map 覆盖同名组件
38
+ * - fragment 包含 Field / Object / Array / Void / transform 与按组件名生成的动态构造器
39
+ * 组件 props、字段值与 scope 类型全部自动推断,无需手写类型参数。
40
+ */
41
+ export declare function createSchemaField<F extends SchemaReactComponents = SchemaReactComponents, V extends SchemaReactComponents = {}, A extends SchemaReactComponents = {}, Scope extends object = Record<string, any>, Decorator extends AnyComponent<InferVoidProps<V, A>> = AnyComponent<InferVoidProps<V, A>>>(factoryOptions?: ISchemaFieldFactoryOptions<F, V, A, Scope, Decorator>): SchemaFieldFactoryResult<F, V, A, Scope, Decorator>;
42
+
43
+ /** 表达式作用域:与外层 scope 惰性合并,内层同名变量优先,Provider 天然隔离兄弟分支。 */
44
+ export declare function ExpressionScope(props: PropsWithChildren<IExpressionScopeProps>): JSX.Element;
45
+
46
+ export declare namespace ExpressionScope {
47
+ var displayName: string;
48
+ }
49
+
50
+ /** render props 形式读取 form,内部由 observer 追踪响应式状态,form 变化后自动刷新。 */
51
+ export declare const FormConsumer: NamedExoticComponent<Omit<{
52
+ children?: ReactNode | undefined;
53
+ }, "children"> & IFormConsumerProps> & {
54
+ readonly type: ReactFC<IFormConsumerProps>;
55
+ };
56
+
57
+ /**
58
+ * 挂载表单生命周期并注入 FormContext。
59
+ * 同时把字段 / schema / scope / options 四个上下文重置为空,
60
+ * 等价于 Vue 侧 useInjectionCleaner 的隔离效果,嵌套 FormProvider 不会串层。
61
+ */
62
+ export declare function FormProvider(props: PropsWithChildren<IProviderProps>): JSX.Element;
63
+
64
+ export declare namespace FormProvider {
65
+ var displayName: string;
66
+ }
67
+
68
+ export declare type IComponentMapper<T extends ReactComponent = ReactComponent> = (target: T) => ReactComponent;
69
+
70
+ export declare interface IExpressionScopeProps {
71
+ value: any;
72
+ }
73
+
74
+ export declare interface IFormConsumerProps {
75
+ children?: (renderProps: IFormConsumerRenderProps) => ReactNode;
76
+ }
77
+
78
+ export declare interface IFormConsumerRenderProps {
79
+ form: Form;
80
+ }
81
+
82
+ export declare type InferArrayProps<A extends SchemaReactComponents> = {
83
+ [K in keyof A]: TPropsOfComponent<A[K]>;
84
+ };
85
+
86
+ /**
87
+ * 从扁平 components 与两个分类组件 map 分别推断 fragment 的三个 props map,组件 props 自动提取。
88
+ * 分类优先级与运行时递归渲染一致:array > void > field,已分类的名字不会出现在 field 映射中,
89
+ * 避免同一组件名同时命中 field / void / array 多个动态构造器重载。
90
+ * 分类泛型默认空 map,keyof 结果为 never,省略分类时不会污染 field 推断。
91
+ */
92
+ export declare type InferFieldProps<F extends SchemaReactComponents, V extends SchemaReactComponents, A extends SchemaReactComponents> = {
93
+ [K in keyof F as K extends keyof V | keyof A ? never : K]: TPropsOfComponent<F[K]>;
94
+ };
95
+
96
+ export declare type InferVoidProps<V extends SchemaReactComponents, A extends SchemaReactComponents> = {
97
+ [K in keyof V as K extends keyof A ? never : K]: TPropsOfComponent<V[K]>;
98
+ };
99
+
100
+ export declare interface IProviderProps {
101
+ form: Form;
102
+ }
103
+
104
+ export declare interface IReactiveFieldProps {
105
+ fieldType?: ReactiveFieldType;
106
+ fieldProps?: IFieldFactoryProps<any, any>;
107
+ /** RecursionField 按 schema.slot 分组生成的具名插槽节点 */
108
+ slots?: Record<string, React.ReactNode>;
109
+ children?: React.ReactNode;
110
+ }
111
+
112
+ export declare interface IRecursionFieldProps {
113
+ schema: ISchema | Schema;
114
+ name?: SchemaKey;
115
+ basePath?: FormPathPattern;
116
+ onlyRenderProperties?: boolean;
117
+ onlyRenderSelf?: boolean;
118
+ mapProperties?: ISchemaMapper;
119
+ filterProperties?: ISchemaFilter;
120
+ }
121
+
122
+ declare interface IRecycleTarget {
123
+ onMount: () => void;
124
+ onUnmount: () => void;
125
+ }
126
+
127
+ export declare interface ISchemaFieldFactoryOptions<F extends SchemaReactComponents = SchemaReactComponents, V extends SchemaReactComponents = {}, A extends SchemaReactComponents = {}, Scope extends object = Record<string, any>, Decorator extends AnyComponent<InferVoidProps<V, A>> = AnyComponent<InferVoidProps<V, A>>> {
128
+ /** 扁平 name → component 映射,未声明分类的组件默认按 field 处理 */
129
+ components?: F;
130
+ /** void / 布局分类组件 map,自动合并进运行时组件映射 */
131
+ voidComponents?: V;
132
+ /** array 分类组件 map,自动合并进运行时组件映射 */
133
+ arrayComponents?: A;
134
+ /** 表达式与 reactions 的自定义 scope,传入后类型自动推断,无需手写泛型 */
135
+ scope?: Scope;
136
+ /** 默认装饰器,行为同 createFragment 的 defaultDecorator */
137
+ defaultDecorator?: Decorator;
138
+ /** 应用到 fragment 产出的每个 schema 上的 patch */
139
+ patches?: SchemaPatchInput | SchemaPatchInput[];
140
+ }
141
+
142
+ declare interface ISchemaFieldInnerProps extends ISchemaFieldProps {
143
+ /** createSchemaField 预绑定的 components 与 scope,直接使用 SchemaField 时不存在 */
144
+ prebound?: ISchemaFieldRuntimeOptions;
145
+ }
146
+
147
+ export declare interface ISchemaFieldProps extends IRecursionFieldProps {
148
+ /** 扁平 name → component 映射 */
149
+ components?: SchemaReactComponents;
150
+ scope?: Record<string, any>;
151
+ /**
152
+ * schema 引用变化时重建字段,默认关闭。
153
+ * 仅建议在开发环境开启,且 schema 需要保持稳定引用。
154
+ */
155
+ hotReload?: boolean;
156
+ }
157
+
158
+ /** 注入后代组件的运行时选项,components 始终是扁平 name → component。 */
159
+ export declare interface ISchemaFieldRuntimeOptions {
160
+ components?: SchemaReactComponents;
161
+ scope?: Record<string, any>;
162
+ }
163
+
164
+ export declare interface ISchemaFilter {
165
+ (schema: Schema, name: SchemaKey): boolean;
166
+ }
167
+
168
+ export declare interface ISchemaMapper {
169
+ (schema: Schema, name: SchemaKey): ISchema | Schema | void;
170
+ }
171
+
172
+ export declare type IStateMapper<Props = Record<string, any>> = Record<string, string | boolean> | ((props: Props, field: GeneralField) => Props);
173
+
174
+ export declare function mapProps<T extends ReactComponent = ReactComponent>(...args: IStateMapper[]): (target: T) => T;
175
+
176
+ export declare function mapReadPretty(component: ReactComponent, readPrettyProps?: Record<string, any>): <T extends ReactComponent>(target: T) => T;
177
+
178
+ export declare type ReactComponent = ComponentType<any>;
179
+
180
+ export declare const ReactiveField: NamedExoticComponent<Omit<{
181
+ children?: ReactNode | undefined;
182
+ }, keyof IReactiveFieldProps> & IReactiveFieldProps> & {
183
+ readonly type: ReactFC<IReactiveFieldProps>;
184
+ };
185
+
186
+ export declare type ReactiveFieldType = 'Field' | 'ObjectField' | 'ArrayField' | 'VoidField';
187
+
188
+ export declare function RecursionField(props: IRecursionFieldProps): JSX.Element;
189
+
190
+ export declare namespace RecursionField {
191
+ var displayName: string;
192
+ }
193
+
194
+ export declare function SchemaField(props: ISchemaFieldInnerProps): JSX.Element;
195
+
196
+ export declare namespace SchemaField {
197
+ var displayName: string;
198
+ }
199
+
200
+ /**
201
+ * createSchemaField 的返回值:
202
+ * - SchemaField:预绑定 components 与 scope 的渲染组件
203
+ * - fragment:同配置的 fragment 构造器集合(Field / Object / Array / Void / transform 与动态构造器)
204
+ */
205
+ export declare type SchemaFieldFactoryResult<F extends SchemaReactComponents, V extends SchemaReactComponents, A extends SchemaReactComponents, Scope extends object, Decorator extends AnyComponent<InferVoidProps<V, A>>> = {
206
+ SchemaField: typeof SchemaField;
207
+ fragment: Fragment<InferFieldProps<F, V, A>, InferVoidProps<V, A>, InferArrayProps<A>, Scope, Decorator>;
208
+ };
209
+
210
+ export declare type SchemaReactComponents = Record<string, ReactComponent>;
211
+
212
+ /**
213
+ * 把字段生命周期挂到 React 组件生命周期上:
214
+ * target 变化时旧实例 onUnmount、新实例 onMount,组件卸载时清理当前实例。
215
+ */
216
+ export declare function useAttach<T extends IRecycleTarget>(target: T | undefined): T | undefined;
217
+
218
+ export declare function useField<T = GeneralField>(): T | undefined;
219
+
220
+ export declare function useFieldSchema(): Schema | undefined;
221
+
222
+ export declare function useForm(): Form | undefined;
223
+
224
+ export declare function useFormEffects(effects?: (form: Form) => void): void;
225
+
226
+ export declare function useParentForm(): Form | ObjectField | undefined;
227
+
228
+
229
+ export * from "@formvk/schema";
230
+
231
+ export { }