@formvk/vue 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,309 @@
1
+ import { AnyComponent } from '@formvk/schema';
2
+ import { Component } from 'vue';
3
+ import { ComponentOptionsMixin } from 'vue';
4
+ import { ComponentProvideOptions } from 'vue';
5
+ import { ComputedRef } from 'vue';
6
+ import { DefineComponent } from 'vue';
7
+ import { ExtractPropTypes } from 'vue';
8
+ import { Form } from '@formvk/core';
9
+ import { FormPathPattern } from '@formvk/shared';
10
+ import { Fragment } from '@formvk/schema';
11
+ import { GeneralField } from '@formvk/core';
12
+ import { IFieldFactoryProps } from '@formvk/core';
13
+ import { IFormProps } from '@formvk/core';
14
+ import { InjectionKey } from 'vue';
15
+ import { ISchema } from '@formvk/schema';
16
+ import { JSX } from 'vue/jsx-runtime';
17
+ import { ObjectField } from '@formvk/core';
18
+ import { PropType } from 'vue';
19
+ import { PublicProps } from 'vue';
20
+ import { Ref } from 'vue';
21
+ import { RendererElement } from 'vue';
22
+ import { RendererNode } from 'vue';
23
+ import { Schema } from '@formvk/schema';
24
+ import { SchemaKey } from '@formvk/schema';
25
+ import { SchemaPatchInput } from '@formvk/schema';
26
+ import { SlotsType } from 'vue';
27
+ import { TPropsOfComponent } from '@formvk/schema';
28
+ import { VNode } from 'vue';
29
+
30
+ /** 提取 Vue 组件定义的 props 类型。 */
31
+ export declare type ComponentProps<T> = T extends abstract new (...args: any) => {
32
+ $props: infer Props;
33
+ } ? Props : never;
34
+
35
+ export declare function connect<T extends VueComponent>(target: T, ...args: IComponentMapper[]): T;
36
+
37
+ export declare function createForm<T extends object = any>(options?: IFormProps<T>): Form<T>;
38
+
39
+ /**
40
+ * 基于扁平组件映射与分类组件 map 创建 SchemaField + fragment:
41
+ * - voidComponents / arrayComponents 只接收组件 map,分类名由工厂内部提取后传给 fragment
42
+ * - 分类组件会自动合并进运行时组件映射,无需在 components 中重复注册
43
+ * - 返回的 SchemaField 已预绑定拍平后的组件与 scope,props 仍可传扁平 map 覆盖同名组件
44
+ * - fragment 包含 Field / Object / Array / Void / transform 与按组件名生成的动态构造器
45
+ * 组件 props、字段值与 scope 类型全部自动推断,无需手写类型参数。
46
+ */
47
+ export declare function createSchemaField<F extends SchemaVueComponents = SchemaVueComponents, V extends SchemaVueComponents = {}, A extends SchemaVueComponents = {}, Scope extends object = Record<string, any>, Decorator extends AnyComponent<InferVoidProps<V, A>> = AnyComponent<InferVoidProps<V, A>>>(options?: ISchemaFieldFactoryOptions<F, V, A, Scope, Decorator>): SchemaFieldFactoryResult<F, V, A, Scope, Decorator>;
48
+
49
+ export declare const ExpressionScope: DefineComponent<{
50
+ value?: any;
51
+ }, () => VNode<RendererNode, RendererElement, {
52
+ [key: string]: any;
53
+ }>[] | undefined, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{
54
+ value?: any;
55
+ }> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
56
+
57
+ export declare const FormConsumer: DefineComponent<{}, () => VNode<RendererNode, RendererElement, {
58
+ [key: string]: any;
59
+ }>[], {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
60
+ default: IFormConsumerSlotProps;
61
+ }>, {}, {}, string, ComponentProvideOptions, true, {}, any>;
62
+
63
+ export declare const FormProvider: DefineComponent<{
64
+ form?: any;
65
+ }, () => VNode<RendererNode, RendererElement, {
66
+ [key: string]: any;
67
+ }>[] | undefined, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{
68
+ form?: any;
69
+ }> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
70
+
71
+ export declare type IComponentMapper<T extends VueComponent = VueComponent> = (target: T) => VueComponent;
72
+
73
+ export declare interface IExpressionScopeProps {
74
+ value: any;
75
+ }
76
+
77
+ export declare interface IFormConsumerSlotProps {
78
+ form: Form;
79
+ }
80
+
81
+ export declare type InferArrayProps<A extends SchemaVueComponents> = {
82
+ [K in keyof A]: TPropsOfComponent<A[K]>;
83
+ };
84
+
85
+ /**
86
+ * 从扁平 components 与两个分类组件 map 分别推断 fragment 的三个 props map,组件 props 自动提取。
87
+ * 分类优先级与运行时 Proxy 一致:array > void > field,已分类的名字不会出现在 field 映射中,
88
+ * 避免同一组件名同时命中 field / void / array 多个动态构造器重载。
89
+ * 分类泛型默认空 map,keyof 结果为 never,省略分类时不会污染 field 推断。
90
+ */
91
+ export declare type InferFieldProps<F extends SchemaVueComponents, V extends SchemaVueComponents, A extends SchemaVueComponents> = {
92
+ [K in keyof F as K extends keyof V | keyof A ? never : K]: TPropsOfComponent<F[K]>;
93
+ };
94
+
95
+ export declare type InferVoidProps<V extends SchemaVueComponents, A extends SchemaVueComponents> = {
96
+ [K in keyof V as K extends keyof A ? never : K]: TPropsOfComponent<V[K]>;
97
+ };
98
+
99
+ export declare interface IProviderProps {
100
+ form: Form;
101
+ }
102
+
103
+ export declare interface IReactiveFieldProps {
104
+ fieldType?: ReactiveFieldType;
105
+ fieldProps?: IFieldFactoryProps<any, any>;
106
+ }
107
+
108
+ export declare interface IRecursionFieldProps {
109
+ schema: ISchema | Schema;
110
+ name?: SchemaKey;
111
+ basePath?: FormPathPattern;
112
+ onlyRenderProperties?: boolean;
113
+ onlyRenderSelf?: boolean;
114
+ mapProperties?: ISchemaMapper;
115
+ filterProperties?: ISchemaFilter;
116
+ }
117
+
118
+ declare interface IRecycleTarget {
119
+ onMount: () => void;
120
+ onUnmount: () => void;
121
+ }
122
+
123
+ export declare interface ISchemaFieldFactoryOptions<F extends SchemaVueComponents = SchemaVueComponents, V extends SchemaVueComponents = {}, A extends SchemaVueComponents = {}, Scope extends object = Record<string, any>, Decorator extends AnyComponent<InferVoidProps<V, A>> = AnyComponent<InferVoidProps<V, A>>> {
124
+ /** 扁平 name → component 映射,未声明分类的组件默认按 field 处理 */
125
+ components?: F;
126
+ /** void / 布局分类组件 map,自动合并进运行时组件映射 */
127
+ voidComponents?: V;
128
+ /** array 分类组件 map,自动合并进运行时组件映射 */
129
+ arrayComponents?: A;
130
+ /** 表达式与 reactions 的自定义 scope,传入后类型自动推断,无需手写泛型 */
131
+ scope?: Scope;
132
+ /** 默认装饰器,行为同 createFragment 的 defaultDecorator */
133
+ defaultDecorator?: Decorator;
134
+ /** 应用到 fragment 产出的每个 schema 上的 patch */
135
+ patches?: SchemaPatchInput | SchemaPatchInput[];
136
+ }
137
+
138
+ export declare interface ISchemaFieldProps extends IRecursionFieldProps {
139
+ /** 扁平 name → component 映射 */
140
+ components?: SchemaVueComponents;
141
+ scope?: Record<string, any>;
142
+ /**
143
+ * schema 引用变化时重建字段,默认关闭。
144
+ * 仅建议在开发环境开启,且 schema 需要保持稳定引用。
145
+ */
146
+ hotReload?: boolean;
147
+ }
148
+
149
+ /** 注入后代组件的运行时选项,components 始终是扁平 name → component。 */
150
+ export declare interface ISchemaFieldRuntimeOptions {
151
+ components?: SchemaVueComponents;
152
+ scope?: Record<string, any>;
153
+ }
154
+
155
+ export declare interface ISchemaFilter {
156
+ (schema: Schema, name: SchemaKey): boolean;
157
+ }
158
+
159
+ export declare interface ISchemaMapper {
160
+ (schema: Schema, name: SchemaKey): ISchema | Schema | void;
161
+ }
162
+
163
+ export declare type IStateMapper<Props = Record<string, any>> = Record<string, string | boolean> | ((props: Props, field: GeneralField) => Props);
164
+
165
+ export declare function mapProps<T extends VueComponent = VueComponent>(...args: IStateMapper[]): (target: T) => T;
166
+
167
+ export declare function mapReadPretty(component: VueComponent, readPrettyProps?: Record<string, any>): <T extends VueComponent>(target: T) => T;
168
+
169
+ export declare type ReactiveFieldType = 'Field' | 'ObjectField' | 'ArrayField' | 'VoidField';
170
+
171
+ export declare const RecursionField: DefineComponent<ExtractPropTypes<{
172
+ schema: {
173
+ required: true;
174
+ };
175
+ name: (StringConstructor | NumberConstructor)[];
176
+ basePath: {};
177
+ onlyRenderProperties: {
178
+ type: BooleanConstructor;
179
+ default: undefined;
180
+ };
181
+ onlyRenderSelf: {
182
+ type: BooleanConstructor;
183
+ default: undefined;
184
+ };
185
+ mapProperties: {};
186
+ filterProperties: {};
187
+ }>, () => VNode<RendererNode, RendererElement, {
188
+ [key: string]: any;
189
+ }> | null, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
190
+ schema: {
191
+ required: true;
192
+ };
193
+ name: (StringConstructor | NumberConstructor)[];
194
+ basePath: {};
195
+ onlyRenderProperties: {
196
+ type: BooleanConstructor;
197
+ default: undefined;
198
+ };
199
+ onlyRenderSelf: {
200
+ type: BooleanConstructor;
201
+ default: undefined;
202
+ };
203
+ mapProperties: {};
204
+ filterProperties: {};
205
+ }>> & Readonly<{}>, {
206
+ onlyRenderProperties: boolean;
207
+ onlyRenderSelf: boolean;
208
+ }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
209
+
210
+ export declare const SchemaField: DefineComponent<ExtractPropTypes<{
211
+ schema: {
212
+ type: PropType<ISchema | Schema>;
213
+ required: true;
214
+ };
215
+ components: {
216
+ type: PropType<SchemaVueComponents>;
217
+ };
218
+ scope: {
219
+ type: PropType<Record<string, any>>;
220
+ };
221
+ name: PropType<SchemaKey>;
222
+ basePath: PropType<FormPathPattern>;
223
+ hotReload: {
224
+ type: BooleanConstructor;
225
+ default: undefined;
226
+ };
227
+ onlyRenderProperties: {
228
+ type: BooleanConstructor;
229
+ default: undefined;
230
+ };
231
+ onlyRenderSelf: {
232
+ type: BooleanConstructor;
233
+ default: undefined;
234
+ };
235
+ mapProperties: {
236
+ type: PropType<ISchemaMapper>;
237
+ };
238
+ filterProperties: {
239
+ type: PropType<ISchemaFilter>;
240
+ };
241
+ }>, () => JSX.Element, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
242
+ schema: {
243
+ type: PropType<ISchema | Schema>;
244
+ required: true;
245
+ };
246
+ components: {
247
+ type: PropType<SchemaVueComponents>;
248
+ };
249
+ scope: {
250
+ type: PropType<Record<string, any>>;
251
+ };
252
+ name: PropType<SchemaKey>;
253
+ basePath: PropType<FormPathPattern>;
254
+ hotReload: {
255
+ type: BooleanConstructor;
256
+ default: undefined;
257
+ };
258
+ onlyRenderProperties: {
259
+ type: BooleanConstructor;
260
+ default: undefined;
261
+ };
262
+ onlyRenderSelf: {
263
+ type: BooleanConstructor;
264
+ default: undefined;
265
+ };
266
+ mapProperties: {
267
+ type: PropType<ISchemaMapper>;
268
+ };
269
+ filterProperties: {
270
+ type: PropType<ISchemaFilter>;
271
+ };
272
+ }>> & Readonly<{}>, {
273
+ onlyRenderProperties: boolean;
274
+ onlyRenderSelf: boolean;
275
+ hotReload: boolean;
276
+ }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
277
+
278
+ /**
279
+ * createSchemaField 的返回值:
280
+ * - SchemaField:预绑定 components 与 scope 的渲染组件
281
+ * - fragment:同配置的 fragment 构造器集合(Field / Object / Array / Void / transform 与动态构造器)
282
+ */
283
+ export declare type SchemaFieldFactoryResult<F extends SchemaVueComponents, V extends SchemaVueComponents, A extends SchemaVueComponents, Scope extends object, Decorator extends AnyComponent<InferVoidProps<V, A>>> = {
284
+ SchemaField: typeof SchemaField;
285
+ fragment: Fragment<InferFieldProps<F, V, A>, InferVoidProps<V, A>, InferArrayProps<A>, Scope, Decorator>;
286
+ };
287
+
288
+ export declare type SchemaVueComponents = Record<string, VueComponent>;
289
+
290
+ export declare function useAttach<T extends IRecycleTarget>(target: Ref<T>): Ref<T>;
291
+
292
+ export declare function useField<T = GeneralField>(): Ref<T>;
293
+
294
+ export declare function useFieldSchema(): Ref<Schema>;
295
+
296
+ export declare function useForm(): Ref<Form>;
297
+
298
+ export declare function useFormEffects(effects?: (form: Form) => void): void;
299
+
300
+ export declare function useInjectionCleaner(injectionKeys: InjectionKey<Ref<unknown>>[]): void;
301
+
302
+ export declare function useParentForm(): ComputedRef<Form | ObjectField>;
303
+
304
+ export declare type VueComponent = Component;
305
+
306
+
307
+ export * from "@formvk/schema";
308
+
309
+ export { }