@okyiww/form 0.0.1
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/LICENSE +21 -0
- package/dist/index.js +5442 -0
- package/dist/types/core/adapter/ArcoVueAdapter.d.ts +9 -0
- package/dist/types/core/adapter/NaiveUIAdapter.d.ts +9 -0
- package/dist/types/core/adapter/NutUIAdapter.d.ts +9 -0
- package/dist/types/core/adapter/index.d.ts +9 -0
- package/dist/types/core/context/index.d.ts +9 -0
- package/dist/types/core/context/types.d.ts +25 -0
- package/dist/types/core/lifecycle/Model/index.d.ts +31 -0
- package/dist/types/core/lifecycle/Render/index.d.ts +54 -0
- package/dist/types/core/lifecycle/Schema/index.d.ts +48 -0
- package/dist/types/core/lifecycle/Schema/types.d.ts +8 -0
- package/dist/types/core/lifecycle/Update/index.d.ts +9 -0
- package/dist/types/core/lifecycle/Update/types.d.ts +1 -0
- package/dist/types/core/lifecycle/hooks/useBaseStyle.d.ts +1 -0
- package/dist/types/core/lifecycle/hooks/useDispatchHandler/index.d.ts +6 -0
- package/dist/types/core/lifecycle/hooks/useDispatchHandler/is.d.ts +8 -0
- package/dist/types/core/lifecycle/hooks/useDispatchHandler/processCompare.d.ts +7 -0
- package/dist/types/core/lifecycle/hooks/useDispatchHandler/processDynamicValue.d.ts +7 -0
- package/dist/types/core/lifecycle/hooks/useDispatchHandler/processRequests.d.ts +2 -0
- package/dist/types/core/lifecycle/hooks/useDispatchHandler/processTransform.d.ts +1 -0
- package/dist/types/core/lifecycle/hooks/useFormItemProps.d.ts +2 -0
- package/dist/types/core/lifecycle/hooks/useFormProps.d.ts +2 -0
- package/dist/types/core/lifecycle/hooks/useLabel.d.ts +1 -0
- package/dist/types/core/lifecycle/hooks/useLayout.d.ts +2 -0
- package/dist/types/core/lifecycle/hooks/useLayoutStyle.d.ts +15 -0
- package/dist/types/core/lifecycle/hooks/usePathTracker.d.ts +1 -0
- package/dist/types/core/lifecycle/hooks/usePlaceholder.d.ts +1 -0
- package/dist/types/core/lifecycle/hooks/useRules.d.ts +1 -0
- package/dist/types/core/lifecycle/hooks/useSSRComponent.d.ts +2 -0
- package/dist/types/core/lifecycle/types.d.ts +4 -0
- package/dist/types/core/runtime/index.d.ts +37 -0
- package/dist/types/core/services/checkPath.d.ts +10 -0
- package/dist/types/core/services/deepTraverse.d.ts +35 -0
- package/dist/types/core/services/index.d.ts +5 -0
- package/dist/types/core/services/isNumericLike.d.ts +1 -0
- package/dist/types/core/services/isPromise.d.ts +1 -0
- package/dist/types/core/services/isValidComponent.d.ts +1 -0
- package/dist/types/core/services/traverse.d.ts +2 -0
- package/dist/types/helpers/defineFormSchema/index.d.ts +2 -0
- package/dist/types/helpers/defineFormSchema/types.d.ts +6 -0
- package/dist/types/helpers/defineFormSetup/index.d.ts +2 -0
- package/dist/types/helpers/defineFormSetup/types.d.ts +54 -0
- package/dist/types/helpers/index.d.ts +6 -0
- package/dist/types/helpers/initForm/index.d.ts +4 -0
- package/dist/types/helpers/initForm/types.d.ts +5 -0
- package/dist/types/helpers/once/index.d.ts +2 -0
- package/dist/types/helpers/raw/index.d.ts +9 -0
- package/dist/types/helpers/useForm/index.d.ts +5 -0
- package/dist/types/helpers/useForm/types.d.ts +10 -0
- package/dist/types/index.d.ts +4 -0
- package/package.json +54 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as Runtime } from '../runtime';
|
|
2
|
+
import { CustomAdapter } from '../../helpers/defineFormSetup/types';
|
|
3
|
+
export declare class ArcoVueAdapter implements CustomAdapter {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
constructor(runtime: Runtime);
|
|
6
|
+
formModelName: string;
|
|
7
|
+
formModelKey: string;
|
|
8
|
+
validate(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as Runtime } from '../runtime';
|
|
2
|
+
import { CustomAdapter } from '../../helpers/defineFormSetup/types';
|
|
3
|
+
export declare class NaiveUIAdapter implements CustomAdapter {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
constructor(runtime: Runtime);
|
|
6
|
+
formModelName: string;
|
|
7
|
+
formModelKey: string;
|
|
8
|
+
validate(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as Runtime } from '../runtime';
|
|
2
|
+
import { CustomAdapter } from '../../helpers/defineFormSetup/types';
|
|
3
|
+
export declare class NutUIAdapter implements CustomAdapter {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
constructor(runtime: Runtime);
|
|
6
|
+
formModelName: string;
|
|
7
|
+
formModelKey: string;
|
|
8
|
+
validate(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as Runtime } from '../runtime';
|
|
2
|
+
import { CustomAdapter } from '../../helpers/defineFormSetup/types';
|
|
3
|
+
export default class Adapter {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
presetAdapters: Record<string, any>;
|
|
6
|
+
adaptee: CustomAdapter;
|
|
7
|
+
constructor(runtime: Runtime);
|
|
8
|
+
initAdapters(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DefineFormSetupOptions, Template } from '../../helpers/defineFormSetup/types';
|
|
2
|
+
import { FormSetupLoader } from '../lifecycle/types';
|
|
3
|
+
export declare class FormContext {
|
|
4
|
+
static context: DefineFormSetupOptions;
|
|
5
|
+
static templateById: Record<string, DefineFormSetupOptions["templates"][number]>;
|
|
6
|
+
static processContext(): void;
|
|
7
|
+
static parseLoader(loader: FormSetupLoader): Promise<void>;
|
|
8
|
+
static getTemplate(templateId?: string): Template;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface SSR {
|
|
2
|
+
renderComponent: (componentName: string) => any;
|
|
3
|
+
definitions?: {
|
|
4
|
+
dispatch?: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
shared?: string;
|
|
7
|
+
res?: string;
|
|
8
|
+
err?: string;
|
|
9
|
+
args?: string;
|
|
10
|
+
};
|
|
11
|
+
actions: {
|
|
12
|
+
GET?: (params: AnyObject) => Promise<any>;
|
|
13
|
+
POST?: (params: AnyObject) => Promise<any>;
|
|
14
|
+
PUT?: (params: AnyObject) => Promise<any>;
|
|
15
|
+
DELETE?: (params: AnyObject) => Promise<any>;
|
|
16
|
+
PATCH?: (params: AnyObject) => Promise<any>;
|
|
17
|
+
CONDITION?: (params: AnyObject) => Promise<any>;
|
|
18
|
+
EVENT_HANDLER?: (params: AnyObject) => Promise<any>;
|
|
19
|
+
SET_MODEL?: (params: AnyObject) => Promise<any>;
|
|
20
|
+
SET_SHARED?: (params: AnyObject) => Promise<any>;
|
|
21
|
+
GET_MODEL?: (params: AnyObject) => Promise<any>;
|
|
22
|
+
GET_SHARED?: (params: AnyObject) => Promise<any>;
|
|
23
|
+
REFS?: (params: AnyObject) => Promise<any>;
|
|
24
|
+
} & AnyObject;
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Metadata } from '../Schema/types';
|
|
2
|
+
import { default as Runtime } from '../../runtime';
|
|
3
|
+
export default class Model {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
constructor(runtime: Runtime);
|
|
6
|
+
/**
|
|
7
|
+
* 我们知道 model 的关键是 field 和 defaultValue, 由于我们根本不知道这个过程什么时候
|
|
8
|
+
* 会触发到谁,有可能都是异步,我们也不知道谁先执行,但是对于初始化 model 来说,我们知道,一定有
|
|
9
|
+
* 一个同 path 的 field 对应一个同 path 的 defaultValue,如果处理完都还没有结束,那么剩下的
|
|
10
|
+
* 就是没有提供 defaultValue 的 field,那么我们再给他设置为 undefined
|
|
11
|
+
*/
|
|
12
|
+
relationMap: Map<string, any>;
|
|
13
|
+
model: import('vue').Ref<Record<string, any>, Record<string, any>>;
|
|
14
|
+
immutableModel: {};
|
|
15
|
+
allConsumed: import('vue').Ref<boolean, boolean>;
|
|
16
|
+
processRelation(metadata: Metadata, value: any): void;
|
|
17
|
+
consumeRelation(path: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* 让我们先来明确一些现状
|
|
20
|
+
* 由于整个解析过程是无状态无依赖无顺序的,所以我们并不清楚谁先来后到,所以在这种场景下,数据一定要非常的干净有逻辑
|
|
21
|
+
* 1、无 field 的类型不会被计入 ralationMap
|
|
22
|
+
* 2、如果一个消费关系的 path 包含了 children,那么它可能是在 group 里,也可能是在 list 里
|
|
23
|
+
* 3、如果一个消费关系的 path 包含了 children,并且 relationMap 中存在 path 是当前 path 的前缀,那么它一定是在 list 里
|
|
24
|
+
* 4、同理,如果找不到这样的前缀,那么它一定是在 group 里
|
|
25
|
+
*/
|
|
26
|
+
consume(relation: Record<string, any>): void;
|
|
27
|
+
defaultValueCalcByType(type: string): never[] | undefined;
|
|
28
|
+
resolveRelations(relations: Record<string, any>[], basePath?: string): void;
|
|
29
|
+
isAllConsumed(): boolean;
|
|
30
|
+
checkingConsume(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ParsedSchema } from '../Schema/types';
|
|
2
|
+
import { default as Runtime } from '../../runtime';
|
|
3
|
+
export default class Render {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
meta: {
|
|
6
|
+
Form: any;
|
|
7
|
+
FormItem: any;
|
|
8
|
+
layouts: ({
|
|
9
|
+
Item: import('../../../helpers/defineFormSetup/types').Component;
|
|
10
|
+
Group: import('../../../helpers/defineFormSetup/types').Component;
|
|
11
|
+
List: import('../../../helpers/defineFormSetup/types').Component;
|
|
12
|
+
ListItem: import('../../../helpers/defineFormSetup/types').Component;
|
|
13
|
+
} & Record<string, any>) | ({
|
|
14
|
+
Item: import('../../../helpers/defineFormSetup/types').Component;
|
|
15
|
+
Group: import('../../../helpers/defineFormSetup/types').Component;
|
|
16
|
+
List: import('../../../helpers/defineFormSetup/types').Component;
|
|
17
|
+
ListItem: import('../../../helpers/defineFormSetup/types').Component;
|
|
18
|
+
} & Record<string, any>) | ({
|
|
19
|
+
Item: import('../../../helpers/defineFormSetup/types').Component;
|
|
20
|
+
Group: import('../../../helpers/defineFormSetup/types').Component;
|
|
21
|
+
List: import('../../../helpers/defineFormSetup/types').Component;
|
|
22
|
+
ListItem: import('../../../helpers/defineFormSetup/types').Component;
|
|
23
|
+
} & Record<string, any>);
|
|
24
|
+
adapters: {};
|
|
25
|
+
};
|
|
26
|
+
formRef: import('vue').Ref<any, any>;
|
|
27
|
+
constructor(runtime: Runtime);
|
|
28
|
+
getRenderMeta(): {
|
|
29
|
+
Form: any;
|
|
30
|
+
FormItem: any;
|
|
31
|
+
layouts: ({
|
|
32
|
+
Item: import('../../../helpers/defineFormSetup/types').Component;
|
|
33
|
+
Group: import('../../../helpers/defineFormSetup/types').Component;
|
|
34
|
+
List: import('../../../helpers/defineFormSetup/types').Component;
|
|
35
|
+
ListItem: import('../../../helpers/defineFormSetup/types').Component;
|
|
36
|
+
} & Record<string, any>) | ({
|
|
37
|
+
Item: import('../../../helpers/defineFormSetup/types').Component;
|
|
38
|
+
Group: import('../../../helpers/defineFormSetup/types').Component;
|
|
39
|
+
List: import('../../../helpers/defineFormSetup/types').Component;
|
|
40
|
+
ListItem: import('../../../helpers/defineFormSetup/types').Component;
|
|
41
|
+
} & Record<string, any>) | ({
|
|
42
|
+
Item: import('../../../helpers/defineFormSetup/types').Component;
|
|
43
|
+
Group: import('../../../helpers/defineFormSetup/types').Component;
|
|
44
|
+
List: import('../../../helpers/defineFormSetup/types').Component;
|
|
45
|
+
ListItem: import('../../../helpers/defineFormSetup/types').Component;
|
|
46
|
+
} & Record<string, any>);
|
|
47
|
+
adapters: {};
|
|
48
|
+
};
|
|
49
|
+
renderItemSchema(schema: ParsedSchema, modelSource?: Record<string, any>, baseFieldPath?: string, Layout?: any): false | import("vue/jsx-runtime").JSX.Element | undefined;
|
|
50
|
+
renderListSchema(schema: ParsedSchema, modelSource?: Record<string, any>, baseFieldPath?: string, baseModelPath?: string, Layout?: any): import("vue/jsx-runtime").JSX.Element;
|
|
51
|
+
renderGroupSchema(schema: ParsedSchema, modelSource?: Record<string, any>, baseFieldPath?: string, Layout?: any): import("vue/jsx-runtime").JSX.Element;
|
|
52
|
+
renderParsedSchema(schema: ParsedSchema, modelSource?: Record<string, any>, baseFieldPath?: string, baseModelPath?: string): false | import("vue/jsx-runtime").JSX.Element | undefined;
|
|
53
|
+
render(): import('vue').DefineComponent<{}, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Metadata, ParsedSchemas } from './types';
|
|
2
|
+
import { default as Runtime } from '../../runtime';
|
|
3
|
+
import { RawSchemas } from '../../../helpers/defineFormSchema/types';
|
|
4
|
+
import { Ref } from 'vue';
|
|
5
|
+
export default class Schema {
|
|
6
|
+
runtime: Runtime;
|
|
7
|
+
rawSchemas: RawSchemas | undefined;
|
|
8
|
+
parsedSchemas: Ref<ParsedSchemas>;
|
|
9
|
+
refs: Map<string, any>;
|
|
10
|
+
constructor(runtime: Runtime);
|
|
11
|
+
processSSR(schemas: RawSchemas): RawSchemas;
|
|
12
|
+
processSchemas(): void;
|
|
13
|
+
traverseSchemas(schemas: RawSchemas): void;
|
|
14
|
+
/**
|
|
15
|
+
* 需要注意的是,当我在实现这个的时候,我的 happy path 其实是过分关注于 input => renderable 的,这
|
|
16
|
+
* 其实很大程度上存在风险,稍有不慎就会带来不可避免的重构难度,对此,除了谨慎考虑引入之外,我还建议在设计之初
|
|
17
|
+
* 就引入足够复杂的场景,避免过于 happy path 导致复用性差并且代码复杂的问题
|
|
18
|
+
*/
|
|
19
|
+
parseSchema(schema: any, metadata: Metadata): void;
|
|
20
|
+
/**
|
|
21
|
+
* 先说说这个函数做什么,防止后续误用,乱用
|
|
22
|
+
* 这个函数并不是只用来处理 schema 的第一层遍历,而是一个通用型的函数,他的目的是用来处理任意键值对
|
|
23
|
+
* 并且将处理的结果妥善的根据 metadata 设定到应该去的地方,那么可以想象到的是
|
|
24
|
+
* 这个函数的出口是固定的,但是入口是不固定的,所以我会约束这个函数的出口返回的参数,但需要入口来适配这些参数才能正常使用它
|
|
25
|
+
*
|
|
26
|
+
* 那么这个函数的目的也就明了了,
|
|
27
|
+
* 1、得到处理完成的值
|
|
28
|
+
* 1、什么是处理完成?
|
|
29
|
+
* 2、什么该处理,什么不该处理?
|
|
30
|
+
* 3、怎么处理?
|
|
31
|
+
* 2、调用 metadata 里的 setter,并且将处理完成的值和 metadata 传入
|
|
32
|
+
*/
|
|
33
|
+
parseProperty(propertyKey: string, propertyValue: any, metadata: Metadata): void;
|
|
34
|
+
usageTracker: Map<string, Set<string>>;
|
|
35
|
+
/**
|
|
36
|
+
* 处理器
|
|
37
|
+
* 1、返回值是什么
|
|
38
|
+
* 2、什么该处理,什么不处理
|
|
39
|
+
*
|
|
40
|
+
* 处理器需要跟 Update 打通,留存记录
|
|
41
|
+
*
|
|
42
|
+
* 思路
|
|
43
|
+
* 对于函数而言,将所有同步或异步的函数都处理成结果后,再进入 processNonFunction 函数进行处理,而对于其他数据,则直接进入
|
|
44
|
+
* processNonFunction 函数进行处理
|
|
45
|
+
*/
|
|
46
|
+
processing(value: any, metadata: Metadata): void;
|
|
47
|
+
processingNonFunction(value: any, metadata: Metadata, jumpConsume?: boolean): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ParsedSchema = Record<string, any>;
|
|
2
|
+
export type ParsedSchemas = ParsedSchema[];
|
|
3
|
+
export type Metadata = {
|
|
4
|
+
path: string;
|
|
5
|
+
setter: (...args: any[]) => any;
|
|
6
|
+
propertyKey?: string;
|
|
7
|
+
processedSetter?: (processedValue: any, jumpConsume?: boolean) => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TriggerType } from './types';
|
|
2
|
+
import { default as Runtime } from '../../runtime';
|
|
3
|
+
export default class Update {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
effects: Map<any, any>;
|
|
6
|
+
constructor(runtime: Runtime);
|
|
7
|
+
track(key: string, effect: any): void;
|
|
8
|
+
trigger(type?: TriggerType, path?: string): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TriggerType = "model" | "share";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useBaseStyle(value?: number): AnyObject;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as Runtime } from '../../../runtime';
|
|
2
|
+
export declare const requestResSymbol: unique symbol;
|
|
3
|
+
export declare const requestErrSymbol: unique symbol;
|
|
4
|
+
export declare const eventArgsSymbol: unique symbol;
|
|
5
|
+
export declare function processDispatch(data: AnyObject, utils: AnyObject, runtime: Runtime, runtimeInfo?: AnyObject): Promise<any>;
|
|
6
|
+
export declare function useDispatchHandler(data: any, runtime: Runtime): (utils: AnyObject) => Promise<any>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function isRequestDispatch(dispatch: string): boolean;
|
|
2
|
+
export declare function isConditionDispatch(dispatch: string): boolean;
|
|
3
|
+
export declare function isEventHandlerDispatch(dispatch: string): boolean;
|
|
4
|
+
export declare function isSetModelDispatch(dispatch: string): boolean;
|
|
5
|
+
export declare function isSetSharedDispatch(dispatch: string): boolean;
|
|
6
|
+
export declare function isGetModelDispatch(dispatch: string): boolean;
|
|
7
|
+
export declare function isGetSharedDispatch(dispatch: string): boolean;
|
|
8
|
+
export declare function isRefsDispatch(dispatch: string): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { default as Runtime } from '../../../runtime';
|
|
2
|
+
/**
|
|
3
|
+
* skipProcess 的引入是为了支持 left 和 right 以及 rightValues 都是 dispatch 的情况
|
|
4
|
+
* 但由于不推荐进行超级定制的 dispatch,因为数据本身就已经在后端了,能够尽可能拼好的不需要太动态的可以略过
|
|
5
|
+
* 所以这里不做深度的处理,只处理第一层的情况
|
|
6
|
+
*/
|
|
7
|
+
export declare function processCompare(data: AnyObject, utils: AnyObject, runtime: Runtime, runtimeInfo?: AnyObject, skipProcess?: boolean): Promise<boolean>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { default as Runtime } from '../../../runtime';
|
|
2
|
+
export declare function isDynamicValue(value: string, runtime: Runtime): boolean;
|
|
3
|
+
export declare function processDynamicValue(value: string | AnyObject | AnyArray, { model, shared }: AnyObject, runtime: Runtime, runtimeInfo?: AnyObject): any;
|
|
4
|
+
export declare function processArrayDynamic(value: any[], { model, shared }: AnyObject, runtime: Runtime, runtimeInfo?: AnyObject): any[];
|
|
5
|
+
export declare function processPlainObjectDynamic(value: Record<string, any>, { model, shared }: AnyObject, runtime: Runtime, runtimeInfo?: AnyObject): {
|
|
6
|
+
[k: string]: any;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function processTransform(data: any, transform: AnyObject): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLabel(label: string | AnyFunction, baseFieldPath?: string): any;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO:一种简单的布局计算,可能带来的问题是在存在 px 转换的情况下,这个布局不会很精准,16px 和实际的项目 px 可能存在差异
|
|
3
|
+
* 后续有需要的话可以提供一个 px 的定义器,毕竟移动端上需要这种布局的场景也不多
|
|
4
|
+
*/
|
|
5
|
+
export declare function useLayoutStyle(schema: AnyObject, layoutGap?: number): {
|
|
6
|
+
width: string;
|
|
7
|
+
display?: undefined;
|
|
8
|
+
boxSizing?: undefined;
|
|
9
|
+
verticalAlign?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
width: string;
|
|
12
|
+
display: string;
|
|
13
|
+
boxSizing: string;
|
|
14
|
+
verticalAlign: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function usePathTracker<T extends object>(target: T, onAccess: (path: string) => void): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function usePlaceholder(label: string, componentName?: string): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useRules(schema: AnyObject): any;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { default as Adapter } from '../adapter';
|
|
2
|
+
import { FormContext } from '../context';
|
|
3
|
+
import { SSR } from '../context/types';
|
|
4
|
+
import { default as Model } from '../lifecycle/Model';
|
|
5
|
+
import { default as Render } from '../lifecycle/Render';
|
|
6
|
+
import { default as Schema } from '../lifecycle/Schema';
|
|
7
|
+
import { default as Update } from '../lifecycle/Update';
|
|
8
|
+
import { Component } from '../../helpers/defineFormSetup/types';
|
|
9
|
+
import { UseFormOptions } from '../../helpers/useForm/types';
|
|
10
|
+
export default class Runtime {
|
|
11
|
+
_schema: Schema;
|
|
12
|
+
_model: Model;
|
|
13
|
+
_render: Render;
|
|
14
|
+
_update: Update;
|
|
15
|
+
_options: UseFormOptions;
|
|
16
|
+
_context: FormContext;
|
|
17
|
+
_adapter: Adapter;
|
|
18
|
+
shared: {};
|
|
19
|
+
isSsr: boolean;
|
|
20
|
+
ssr: SSR;
|
|
21
|
+
defaultSSRDefinitions: {
|
|
22
|
+
dispatch: string;
|
|
23
|
+
model: string;
|
|
24
|
+
shared: string;
|
|
25
|
+
res: string;
|
|
26
|
+
err: string;
|
|
27
|
+
args: string;
|
|
28
|
+
};
|
|
29
|
+
constructor(options: UseFormOptions);
|
|
30
|
+
processSSR(options: UseFormOptions): void;
|
|
31
|
+
render(): Component;
|
|
32
|
+
submit(): Promise<Record<string, any>>;
|
|
33
|
+
share(shared: AnyObject): void;
|
|
34
|
+
isReady(handler: AnyFunction): void;
|
|
35
|
+
hydrate(model: AnyObject): void;
|
|
36
|
+
getFormRef(): import('vue').Ref<any, any>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function getParentPaths(path: string): string[];
|
|
2
|
+
export declare function getDirectParent(path: string): string | null;
|
|
3
|
+
export declare function checkParentExists(map: Map<string, any>, childPath: string): boolean;
|
|
4
|
+
export declare function checkRelations(map: Map<string, any>, childPath: string): {
|
|
5
|
+
isListChild: boolean;
|
|
6
|
+
existingRelations: {
|
|
7
|
+
current: any;
|
|
8
|
+
parent: any;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface TraverseContext {
|
|
2
|
+
/**
|
|
3
|
+
* 当前节点在父节点中的 key(如果是数组,则为索引)
|
|
4
|
+
*/
|
|
5
|
+
key: string | number;
|
|
6
|
+
/**
|
|
7
|
+
* 从根到当前节点的路径数组
|
|
8
|
+
*/
|
|
9
|
+
path: (string | number)[];
|
|
10
|
+
/**
|
|
11
|
+
* 当前节点的父节点(对象或数组)
|
|
12
|
+
*/
|
|
13
|
+
parent: any;
|
|
14
|
+
/**
|
|
15
|
+
* 检查当前节点是否为叶子节点(没有子节点)
|
|
16
|
+
*/
|
|
17
|
+
isLeaf: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 遍历处理函数
|
|
21
|
+
* @param value 当前节点的值
|
|
22
|
+
* @param context 当前节点的上下文
|
|
23
|
+
* @returns 返回新值。
|
|
24
|
+
* - 返回 `SKIP`:跳过子节点遍历。
|
|
25
|
+
* - 返回 `DELETE`:删除此节点。
|
|
26
|
+
* - 返回其他值:用该值替换当前节点。
|
|
27
|
+
*/
|
|
28
|
+
export type TraverseHandler = (value: any, context: TraverseContext) => any;
|
|
29
|
+
/**
|
|
30
|
+
* 深度遍历一个对象或数组,并允许通过 handler "原地" 修改、跳过或删除节点。
|
|
31
|
+
* @param target 要遍历的对象或数组
|
|
32
|
+
* @param handler 在每个节点上调用的处理函数
|
|
33
|
+
* @returns 经过 handler 修改后的原始对象 (in-place)
|
|
34
|
+
*/
|
|
35
|
+
export declare function deepTraverse<T extends object>(target: T, handler: TraverseHandler): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNumericLike(value: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isPromise(value: any): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidComponent(propertyKey: string | undefined, value: any): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type Component = any;
|
|
2
|
+
export type BuiltInAdapter = "ArcoVue" | (string & {});
|
|
3
|
+
export type CustomAdapter = {
|
|
4
|
+
formModelName: string;
|
|
5
|
+
formModelKey: string;
|
|
6
|
+
validate: () => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export type Template = {
|
|
9
|
+
id: string;
|
|
10
|
+
adapter: BuiltInAdapter;
|
|
11
|
+
providers: {
|
|
12
|
+
Form: Component;
|
|
13
|
+
FormItem: Component;
|
|
14
|
+
layouts: {
|
|
15
|
+
Item: Component;
|
|
16
|
+
Group: Component;
|
|
17
|
+
List: Component;
|
|
18
|
+
ListItem: Component;
|
|
19
|
+
} & Record<string, Component>;
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
id: string;
|
|
23
|
+
customAdapter: CustomAdapter;
|
|
24
|
+
providers: {
|
|
25
|
+
Form: Component;
|
|
26
|
+
FormItem: Component;
|
|
27
|
+
layouts: {
|
|
28
|
+
Item: Component;
|
|
29
|
+
Group: Component;
|
|
30
|
+
List: Component;
|
|
31
|
+
ListItem: Component;
|
|
32
|
+
} & Record<string, Component>;
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
id: string;
|
|
36
|
+
adapter: BuiltInAdapter;
|
|
37
|
+
customAdapter: Partial<CustomAdapter>;
|
|
38
|
+
providers: {
|
|
39
|
+
Form: Component;
|
|
40
|
+
FormItem: Component;
|
|
41
|
+
layouts: {
|
|
42
|
+
Item: Component;
|
|
43
|
+
Group: Component;
|
|
44
|
+
List: Component;
|
|
45
|
+
ListItem: Component;
|
|
46
|
+
} & Record<string, Component>;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export type DefineFormSetupOptions = {
|
|
50
|
+
templates: Template[];
|
|
51
|
+
default: {
|
|
52
|
+
templateId: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SSR } from '../../core/context/types';
|
|
2
|
+
import { RawSchemas } from '../defineFormSchema/types';
|
|
3
|
+
export type UseFormOptions = {
|
|
4
|
+
templateId?: string;
|
|
5
|
+
schemas: RawSchemas | ((...args: any[]) => RawSchemas) | ((...args: any[]) => Promise<RawSchemas>);
|
|
6
|
+
layoutGap?: number;
|
|
7
|
+
formProps?: any;
|
|
8
|
+
formSlots?: any;
|
|
9
|
+
ssr?: SSR;
|
|
10
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@okyiww/form",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/"
|
|
18
|
+
],
|
|
19
|
+
"author": "okyiww <okyiww@gmail.com>",
|
|
20
|
+
"repository": "okyiww/form",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"form builder",
|
|
23
|
+
"vue",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/lodash": "^4.17.20",
|
|
29
|
+
"@vitejs/plugin-vue-jsx": "^4.1.2",
|
|
30
|
+
"nodemon": "^3.1.9",
|
|
31
|
+
"vite": "^6.2.2",
|
|
32
|
+
"vite-plugin-dts": "^4.5.3",
|
|
33
|
+
"vue": "^3.5.13",
|
|
34
|
+
"vue-tsc": "^2.2.4",
|
|
35
|
+
"@okyiww/nexus": "0.0.0"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"vue": "^3.5.13"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@changesets/changelog-git": "^0.2.1",
|
|
45
|
+
"@vue/reactivity": "^3.5.22",
|
|
46
|
+
"lodash": "^4.17.21",
|
|
47
|
+
"on-change": "^6.0.1"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"dev": "nodemon -e .ts,.tsx --ignore dist --exec 'vite build --mode development'",
|
|
51
|
+
"build": "vue-tsc && vite build",
|
|
52
|
+
"release": "pnpm build --mode production && pnpm changeset publish"
|
|
53
|
+
}
|
|
54
|
+
}
|