@meshflow/core 0.1.2 → 0.1.3
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/index.d.mts +111 -224
- package/index.d.ts +111 -224
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -3,6 +3,48 @@ interface MeshErrorContext {
|
|
|
3
3
|
info: any;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
interface MeshEvents {
|
|
7
|
+
'node:start': {
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
'node:success': {
|
|
11
|
+
path: string;
|
|
12
|
+
};
|
|
13
|
+
'node:bucket:success': {
|
|
14
|
+
path: string;
|
|
15
|
+
key: string;
|
|
16
|
+
value: any;
|
|
17
|
+
};
|
|
18
|
+
'node:error': {
|
|
19
|
+
path: string;
|
|
20
|
+
error: any;
|
|
21
|
+
};
|
|
22
|
+
'node:intercept': {
|
|
23
|
+
path: string;
|
|
24
|
+
reason: string;
|
|
25
|
+
detail?: any;
|
|
26
|
+
};
|
|
27
|
+
'node:release': {
|
|
28
|
+
path: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
};
|
|
31
|
+
'node:stagnate': {
|
|
32
|
+
path: string;
|
|
33
|
+
reason: string;
|
|
34
|
+
};
|
|
35
|
+
'node:processing': {
|
|
36
|
+
path: string;
|
|
37
|
+
};
|
|
38
|
+
'flow:wait': {
|
|
39
|
+
reason: string;
|
|
40
|
+
};
|
|
41
|
+
'flow:fire': {
|
|
42
|
+
path: string;
|
|
43
|
+
reason: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
type MeshEventName = keyof MeshEvents;
|
|
47
|
+
|
|
6
48
|
type ContractType = 'boolean' | 'scalar' | 'array' | 'object';
|
|
7
49
|
declare enum DefaultStarategy {
|
|
8
50
|
OR = "OR",
|
|
@@ -38,167 +80,8 @@ declare class SchemaBucket<P> {
|
|
|
38
80
|
type FinalFlatten<T> = T extends infer O ? {
|
|
39
81
|
[K in keyof O]: O[K];
|
|
40
82
|
} : never;
|
|
41
|
-
type GetAllPath<T, Path = ''> = T extends object ? {
|
|
42
|
-
[K in keyof T]: GetAllPath<T[K], Path extends "" ? K : `${Path & string}.${K & string}`>;
|
|
43
|
-
}[keyof T] : Path;
|
|
44
83
|
type KeysOfUnion<T> = T extends any ? keyof T : never;
|
|
45
84
|
|
|
46
|
-
declare const clonedschema: {
|
|
47
|
-
readonly type: "group";
|
|
48
|
-
readonly name: "cloudConsole";
|
|
49
|
-
readonly label: "云资源采购中心 (专家版)";
|
|
50
|
-
readonly children: readonly [{
|
|
51
|
-
readonly type: "group";
|
|
52
|
-
readonly name: "environment";
|
|
53
|
-
readonly label: "环境与合规策略";
|
|
54
|
-
readonly children: readonly [{
|
|
55
|
-
readonly type: "select";
|
|
56
|
-
readonly name: "region";
|
|
57
|
-
readonly label: "部署地域";
|
|
58
|
-
readonly defaultValue: "china";
|
|
59
|
-
readonly required: true;
|
|
60
|
-
readonly options: readonly [{
|
|
61
|
-
readonly label: "中国大陆 (华北、华东、华南)";
|
|
62
|
-
readonly value: "china";
|
|
63
|
-
}, {
|
|
64
|
-
readonly label: "全球海外 (香港、新加坡、美国)";
|
|
65
|
-
readonly value: "global";
|
|
66
|
-
}];
|
|
67
|
-
}, {
|
|
68
|
-
readonly type: "select";
|
|
69
|
-
readonly name: "compliance";
|
|
70
|
-
readonly label: "合规性分级";
|
|
71
|
-
readonly defaultValue: "standard";
|
|
72
|
-
readonly required: true;
|
|
73
|
-
readonly options: readonly [{
|
|
74
|
-
readonly label: "Level 1: 标准合规 (Standard)";
|
|
75
|
-
readonly value: "standard";
|
|
76
|
-
}, {
|
|
77
|
-
readonly label: "Level 2: 高安全性 (High Security)";
|
|
78
|
-
readonly value: "high_security";
|
|
79
|
-
}, {
|
|
80
|
-
readonly label: "Level 3: 金融级监管 (Financial)";
|
|
81
|
-
readonly value: "financial";
|
|
82
|
-
}];
|
|
83
|
-
readonly description: "合规等级越高,可选资源规格越严格";
|
|
84
|
-
}];
|
|
85
|
-
}, {
|
|
86
|
-
readonly type: "group";
|
|
87
|
-
readonly name: "specs";
|
|
88
|
-
readonly label: "核心资源配置";
|
|
89
|
-
readonly children: readonly [{
|
|
90
|
-
readonly type: "select";
|
|
91
|
-
readonly name: "instanceFamily";
|
|
92
|
-
readonly label: "实例家族";
|
|
93
|
-
readonly defaultValue: "general";
|
|
94
|
-
readonly required: true;
|
|
95
|
-
readonly options: readonly [{
|
|
96
|
-
readonly label: "通用型 (g6)";
|
|
97
|
-
readonly value: "general";
|
|
98
|
-
}, {
|
|
99
|
-
readonly label: "计算型 (c6)";
|
|
100
|
-
readonly value: "compute";
|
|
101
|
-
}, {
|
|
102
|
-
readonly label: "GPU 训练型 (gn7)";
|
|
103
|
-
readonly value: "gpu";
|
|
104
|
-
}, {
|
|
105
|
-
readonly label: "高 IO 型 (i3)";
|
|
106
|
-
readonly value: "high_io";
|
|
107
|
-
}];
|
|
108
|
-
readonly message: "";
|
|
109
|
-
}, {
|
|
110
|
-
readonly type: "group";
|
|
111
|
-
readonly name: "storage";
|
|
112
|
-
readonly label: "存储方案";
|
|
113
|
-
readonly children: readonly [{
|
|
114
|
-
readonly type: "select";
|
|
115
|
-
readonly name: "diskType";
|
|
116
|
-
readonly label: "系统盘类型";
|
|
117
|
-
readonly defaultValue: "ssd";
|
|
118
|
-
readonly required: true;
|
|
119
|
-
readonly options: readonly [{
|
|
120
|
-
readonly label: "ESSD 增强型 SSD";
|
|
121
|
-
readonly value: "essd";
|
|
122
|
-
}, {
|
|
123
|
-
readonly label: "标准 SSD";
|
|
124
|
-
readonly value: "ssd";
|
|
125
|
-
}, {
|
|
126
|
-
readonly label: "高效云盘 (HDD)";
|
|
127
|
-
readonly value: "hdd";
|
|
128
|
-
}];
|
|
129
|
-
}, {
|
|
130
|
-
readonly type: "number";
|
|
131
|
-
readonly name: "capacity";
|
|
132
|
-
readonly label: "系统盘容量 (GB)";
|
|
133
|
-
readonly defaultValue: 40;
|
|
134
|
-
readonly min: 20;
|
|
135
|
-
readonly max: 32768;
|
|
136
|
-
readonly step: 10;
|
|
137
|
-
readonly required: true;
|
|
138
|
-
readonly message: "";
|
|
139
|
-
}];
|
|
140
|
-
}];
|
|
141
|
-
}, {
|
|
142
|
-
readonly type: "group";
|
|
143
|
-
readonly name: "security";
|
|
144
|
-
readonly label: "安全加固选项";
|
|
145
|
-
readonly children: readonly [{
|
|
146
|
-
readonly type: "select";
|
|
147
|
-
readonly name: "encryption";
|
|
148
|
-
readonly label: "数据盘加密";
|
|
149
|
-
readonly defaultValue: "no";
|
|
150
|
-
readonly required: true;
|
|
151
|
-
readonly options: readonly [{
|
|
152
|
-
readonly label: "开启落盘加密 (KMS)";
|
|
153
|
-
readonly value: "yes";
|
|
154
|
-
}, {
|
|
155
|
-
readonly label: "暂不开启";
|
|
156
|
-
readonly value: "no";
|
|
157
|
-
}];
|
|
158
|
-
}, {
|
|
159
|
-
readonly type: "input";
|
|
160
|
-
readonly name: "kmsKey";
|
|
161
|
-
readonly label: "KMS 密钥 ID";
|
|
162
|
-
readonly defaultValue: "";
|
|
163
|
-
readonly maxLength: 8;
|
|
164
|
-
readonly hidden: true;
|
|
165
|
-
readonly required: false;
|
|
166
|
-
readonly placeholder: "请输入云平台提供的密钥 UUID";
|
|
167
|
-
}];
|
|
168
|
-
}, {
|
|
169
|
-
readonly type: "group";
|
|
170
|
-
readonly name: "billing";
|
|
171
|
-
readonly label: "计费与汇总";
|
|
172
|
-
readonly children: readonly [{
|
|
173
|
-
readonly type: "number";
|
|
174
|
-
readonly name: "totalPrice";
|
|
175
|
-
readonly label: "预估月度总价";
|
|
176
|
-
readonly defaultValue: 0;
|
|
177
|
-
readonly readonly: true;
|
|
178
|
-
readonly required: true;
|
|
179
|
-
readonly prefix: "¥";
|
|
180
|
-
}, {
|
|
181
|
-
readonly type: "input";
|
|
182
|
-
readonly name: "priceDetail";
|
|
183
|
-
readonly label: "计费项说明";
|
|
184
|
-
readonly defaultValue: "基础配置费用";
|
|
185
|
-
readonly readonly: true;
|
|
186
|
-
readonly required: false;
|
|
187
|
-
readonly hidden: false;
|
|
188
|
-
}, {
|
|
189
|
-
readonly type: "checkbox";
|
|
190
|
-
readonly name: "autoRenew";
|
|
191
|
-
readonly label: "开启自动续费";
|
|
192
|
-
readonly defaultValue: false;
|
|
193
|
-
readonly disabled: false;
|
|
194
|
-
readonly description: "暂不支持自动续费";
|
|
195
|
-
}];
|
|
196
|
-
}];
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
type FormDataModel = FormResultType<typeof clonedschema>;
|
|
200
|
-
type AllPath = GetAllPath<FormDataModel> | (string & {});
|
|
201
|
-
|
|
202
85
|
type BaseField = {
|
|
203
86
|
label: string;
|
|
204
87
|
name: string;
|
|
@@ -238,7 +121,7 @@ type GroupField = Omit<BaseField, "label" | "name" | "placeholder" | "validators
|
|
|
238
121
|
};
|
|
239
122
|
type FormFieldSchema = InputField | CheckboxField | SelectField | GroupField;
|
|
240
123
|
type RenderSchemaExtraCommonType<P = any> = {
|
|
241
|
-
path:
|
|
124
|
+
path: P;
|
|
242
125
|
dirtySignal: any;
|
|
243
126
|
uid: number;
|
|
244
127
|
nodeBucket: Record<string, SchemaBucket<P>>;
|
|
@@ -248,19 +131,6 @@ type RenderSchemaFn<T> = FinalFlatten<T extends GroupField ? Omit<T, "children">
|
|
|
248
131
|
children: Array<RenderSchemaFn<FormFieldSchema>>;
|
|
249
132
|
} : T & RenderSchemaExtraCommonType>;
|
|
250
133
|
type RenderSchema = RenderSchemaFn<FormFieldSchema>;
|
|
251
|
-
type CollapseChildren<T> = T extends readonly [infer First, ...infer Rest] ? FormResultType<First> & CollapseChildren<Rest> : {};
|
|
252
|
-
type FormResultType<T> = T extends any ? T extends {
|
|
253
|
-
readonly type: "group";
|
|
254
|
-
readonly name: infer N;
|
|
255
|
-
readonly children: infer C;
|
|
256
|
-
} ? N extends string ? N extends "" ? FinalFlatten<CollapseChildren<C>> : {
|
|
257
|
-
[K in N]: FinalFlatten<CollapseChildren<C>>;
|
|
258
|
-
} : FinalFlatten<CollapseChildren<C>> : T extends {
|
|
259
|
-
readonly name: infer N;
|
|
260
|
-
readonly defaultValue: infer V;
|
|
261
|
-
} ? N extends string ? {
|
|
262
|
-
[K in N]: FinalFlatten<V>;
|
|
263
|
-
} : never : {} : {};
|
|
264
134
|
|
|
265
135
|
interface logicApi {
|
|
266
136
|
slot: {
|
|
@@ -275,7 +145,7 @@ type Engine<T> = {
|
|
|
275
145
|
[K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue']: GetType<T, K>;
|
|
276
146
|
};
|
|
277
147
|
config: {
|
|
278
|
-
[K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace"]: GetType<T, K>;
|
|
148
|
+
[K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
|
|
279
149
|
};
|
|
280
150
|
dependency: {
|
|
281
151
|
[K in 'GetAllDependency' | 'GetDependencyOrder']: GetType<T, K>;
|
|
@@ -284,9 +154,10 @@ type Engine<T> = {
|
|
|
284
154
|
[K in "Undo" | "Redo" | "initCanUndo" | "initCanRedo"]: GetType<T, K>;
|
|
285
155
|
};
|
|
286
156
|
hooks: {
|
|
287
|
-
[K in "onError"]: GetType<T, K>;
|
|
157
|
+
[K in "onError" | "onSuccess" | "onStart"]: GetType<T, K>;
|
|
288
158
|
};
|
|
289
159
|
};
|
|
160
|
+
/** @deprecated 请使用新的 useMeshFlow 别名 */
|
|
290
161
|
declare const useEngineManager: <T, P extends string>(id: string | symbol, Schema: any, UITrigger: {
|
|
291
162
|
signalCreateor: () => T;
|
|
292
163
|
signalTrigger: (signal: T) => void;
|
|
@@ -310,31 +181,13 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
|
|
|
310
181
|
condition: (data: any) => boolean;
|
|
311
182
|
}) => void;
|
|
312
183
|
SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
|
|
184
|
+
usePlugin: (plugin: {
|
|
185
|
+
apply: (api: {
|
|
186
|
+
on: (event: MeshEventName, cb: Function) => () => boolean;
|
|
187
|
+
}) => void;
|
|
188
|
+
}) => () => void;
|
|
313
189
|
SetValue: (path: P, value: any) => void;
|
|
314
|
-
GetFormData: () =>
|
|
315
|
-
cloudConsole: {
|
|
316
|
-
environment: {
|
|
317
|
-
region: "china";
|
|
318
|
-
compliance: "standard";
|
|
319
|
-
};
|
|
320
|
-
specs: {
|
|
321
|
-
instanceFamily: "general";
|
|
322
|
-
storage: {
|
|
323
|
-
diskType: "ssd";
|
|
324
|
-
capacity: 40;
|
|
325
|
-
};
|
|
326
|
-
};
|
|
327
|
-
security: {
|
|
328
|
-
encryption: "no";
|
|
329
|
-
kmsKey: "";
|
|
330
|
-
};
|
|
331
|
-
billing: {
|
|
332
|
-
totalPrice: 0;
|
|
333
|
-
priceDetail: "基础配置费用";
|
|
334
|
-
autoRenew: false;
|
|
335
|
-
};
|
|
336
|
-
};
|
|
337
|
-
};
|
|
190
|
+
GetFormData: () => any;
|
|
338
191
|
notifyAll: () => void;
|
|
339
192
|
AddNewSchema: (path: string, data: any) => RenderSchema;
|
|
340
193
|
GetAllDependency: () => Map<P, Set<P>>;
|
|
@@ -344,6 +197,10 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
|
|
|
344
197
|
initCanUndo: (cb: (newVal: number) => any) => void;
|
|
345
198
|
initCanRedo: (cb: (newVal: number) => any) => void;
|
|
346
199
|
onError: (cb: (error: MeshErrorContext) => void) => () => void;
|
|
200
|
+
onSuccess: (cb: (data: unknown) => void) => () => void;
|
|
201
|
+
onStart: (cb: (data: {
|
|
202
|
+
path: P;
|
|
203
|
+
}) => void) => () => void;
|
|
347
204
|
}>;
|
|
348
205
|
declare const useEngine: <T = any, P extends string = string>(id: string | symbol) => Engine<{
|
|
349
206
|
schema: RenderSchema;
|
|
@@ -365,31 +222,13 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
|
|
|
365
222
|
condition: (data: any) => boolean;
|
|
366
223
|
}) => void;
|
|
367
224
|
SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
|
|
225
|
+
usePlugin: (plugin: {
|
|
226
|
+
apply: (api: {
|
|
227
|
+
on: (event: MeshEventName, cb: Function) => () => boolean;
|
|
228
|
+
}) => void;
|
|
229
|
+
}) => () => void;
|
|
368
230
|
SetValue: (path: P, value: any) => void;
|
|
369
|
-
GetFormData: () =>
|
|
370
|
-
cloudConsole: {
|
|
371
|
-
environment: {
|
|
372
|
-
region: "china";
|
|
373
|
-
compliance: "standard";
|
|
374
|
-
};
|
|
375
|
-
specs: {
|
|
376
|
-
instanceFamily: "general";
|
|
377
|
-
storage: {
|
|
378
|
-
diskType: "ssd";
|
|
379
|
-
capacity: 40;
|
|
380
|
-
};
|
|
381
|
-
};
|
|
382
|
-
security: {
|
|
383
|
-
encryption: "no";
|
|
384
|
-
kmsKey: "";
|
|
385
|
-
};
|
|
386
|
-
billing: {
|
|
387
|
-
totalPrice: 0;
|
|
388
|
-
priceDetail: "基础配置费用";
|
|
389
|
-
autoRenew: false;
|
|
390
|
-
};
|
|
391
|
-
};
|
|
392
|
-
};
|
|
231
|
+
GetFormData: () => any;
|
|
393
232
|
notifyAll: () => void;
|
|
394
233
|
AddNewSchema: (path: string, data: any) => RenderSchema;
|
|
395
234
|
GetAllDependency: () => Map<P, Set<P>>;
|
|
@@ -399,7 +238,55 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
|
|
|
399
238
|
initCanUndo: (cb: (newVal: number) => any) => void;
|
|
400
239
|
initCanRedo: (cb: (newVal: number) => any) => void;
|
|
401
240
|
onError: (cb: (error: MeshErrorContext) => void) => () => void;
|
|
241
|
+
onSuccess: (cb: (data: unknown) => void) => () => void;
|
|
242
|
+
onStart: (cb: (data: {
|
|
243
|
+
path: P;
|
|
244
|
+
}) => void) => () => void;
|
|
402
245
|
}>;
|
|
403
246
|
declare const deleteEngine: (id: string | symbol) => void;
|
|
247
|
+
declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: any, UITrigger: {
|
|
248
|
+
signalCreateor: () => T;
|
|
249
|
+
signalTrigger: (signal: T) => void;
|
|
250
|
+
}) => Engine<{
|
|
251
|
+
schema: RenderSchema;
|
|
252
|
+
SetRule: (outDegreePath: P, inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
|
|
253
|
+
value?: any;
|
|
254
|
+
priority?: number;
|
|
255
|
+
forceNotify?: boolean;
|
|
256
|
+
logic: (api: logicApi) => any;
|
|
257
|
+
} | undefined) => void;
|
|
258
|
+
SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
|
|
259
|
+
value?: any;
|
|
260
|
+
priority?: number;
|
|
261
|
+
forceNotify?: boolean;
|
|
262
|
+
logic: (api: logicApi) => any;
|
|
263
|
+
} | undefined) => void;
|
|
264
|
+
SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
|
|
265
|
+
SetValidators: (path: P, options: {
|
|
266
|
+
logic: (val: any, GetByPath: any) => any;
|
|
267
|
+
condition: (data: any) => boolean;
|
|
268
|
+
}) => void;
|
|
269
|
+
SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
|
|
270
|
+
usePlugin: (plugin: {
|
|
271
|
+
apply: (api: {
|
|
272
|
+
on: (event: MeshEventName, cb: Function) => () => boolean;
|
|
273
|
+
}) => void;
|
|
274
|
+
}) => () => void;
|
|
275
|
+
SetValue: (path: P, value: any) => void;
|
|
276
|
+
GetFormData: () => any;
|
|
277
|
+
notifyAll: () => void;
|
|
278
|
+
AddNewSchema: (path: string, data: any) => RenderSchema;
|
|
279
|
+
GetAllDependency: () => Map<P, Set<P>>;
|
|
280
|
+
GetDependencyOrder: () => P[][];
|
|
281
|
+
Undo: () => void;
|
|
282
|
+
Redo: () => void;
|
|
283
|
+
initCanUndo: (cb: (newVal: number) => any) => void;
|
|
284
|
+
initCanRedo: (cb: (newVal: number) => any) => void;
|
|
285
|
+
onError: (cb: (error: MeshErrorContext) => void) => () => void;
|
|
286
|
+
onSuccess: (cb: (data: unknown) => void) => () => void;
|
|
287
|
+
onStart: (cb: (data: {
|
|
288
|
+
path: P;
|
|
289
|
+
}) => void) => () => void;
|
|
290
|
+
}>;
|
|
404
291
|
|
|
405
|
-
export { deleteEngine, useEngine, useEngineManager };
|
|
292
|
+
export { deleteEngine, useEngine, useEngineManager, useMeshFlow };
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,48 @@ interface MeshErrorContext {
|
|
|
3
3
|
info: any;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
interface MeshEvents {
|
|
7
|
+
'node:start': {
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
'node:success': {
|
|
11
|
+
path: string;
|
|
12
|
+
};
|
|
13
|
+
'node:bucket:success': {
|
|
14
|
+
path: string;
|
|
15
|
+
key: string;
|
|
16
|
+
value: any;
|
|
17
|
+
};
|
|
18
|
+
'node:error': {
|
|
19
|
+
path: string;
|
|
20
|
+
error: any;
|
|
21
|
+
};
|
|
22
|
+
'node:intercept': {
|
|
23
|
+
path: string;
|
|
24
|
+
reason: string;
|
|
25
|
+
detail?: any;
|
|
26
|
+
};
|
|
27
|
+
'node:release': {
|
|
28
|
+
path: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
};
|
|
31
|
+
'node:stagnate': {
|
|
32
|
+
path: string;
|
|
33
|
+
reason: string;
|
|
34
|
+
};
|
|
35
|
+
'node:processing': {
|
|
36
|
+
path: string;
|
|
37
|
+
};
|
|
38
|
+
'flow:wait': {
|
|
39
|
+
reason: string;
|
|
40
|
+
};
|
|
41
|
+
'flow:fire': {
|
|
42
|
+
path: string;
|
|
43
|
+
reason: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
type MeshEventName = keyof MeshEvents;
|
|
47
|
+
|
|
6
48
|
type ContractType = 'boolean' | 'scalar' | 'array' | 'object';
|
|
7
49
|
declare enum DefaultStarategy {
|
|
8
50
|
OR = "OR",
|
|
@@ -38,167 +80,8 @@ declare class SchemaBucket<P> {
|
|
|
38
80
|
type FinalFlatten<T> = T extends infer O ? {
|
|
39
81
|
[K in keyof O]: O[K];
|
|
40
82
|
} : never;
|
|
41
|
-
type GetAllPath<T, Path = ''> = T extends object ? {
|
|
42
|
-
[K in keyof T]: GetAllPath<T[K], Path extends "" ? K : `${Path & string}.${K & string}`>;
|
|
43
|
-
}[keyof T] : Path;
|
|
44
83
|
type KeysOfUnion<T> = T extends any ? keyof T : never;
|
|
45
84
|
|
|
46
|
-
declare const clonedschema: {
|
|
47
|
-
readonly type: "group";
|
|
48
|
-
readonly name: "cloudConsole";
|
|
49
|
-
readonly label: "云资源采购中心 (专家版)";
|
|
50
|
-
readonly children: readonly [{
|
|
51
|
-
readonly type: "group";
|
|
52
|
-
readonly name: "environment";
|
|
53
|
-
readonly label: "环境与合规策略";
|
|
54
|
-
readonly children: readonly [{
|
|
55
|
-
readonly type: "select";
|
|
56
|
-
readonly name: "region";
|
|
57
|
-
readonly label: "部署地域";
|
|
58
|
-
readonly defaultValue: "china";
|
|
59
|
-
readonly required: true;
|
|
60
|
-
readonly options: readonly [{
|
|
61
|
-
readonly label: "中国大陆 (华北、华东、华南)";
|
|
62
|
-
readonly value: "china";
|
|
63
|
-
}, {
|
|
64
|
-
readonly label: "全球海外 (香港、新加坡、美国)";
|
|
65
|
-
readonly value: "global";
|
|
66
|
-
}];
|
|
67
|
-
}, {
|
|
68
|
-
readonly type: "select";
|
|
69
|
-
readonly name: "compliance";
|
|
70
|
-
readonly label: "合规性分级";
|
|
71
|
-
readonly defaultValue: "standard";
|
|
72
|
-
readonly required: true;
|
|
73
|
-
readonly options: readonly [{
|
|
74
|
-
readonly label: "Level 1: 标准合规 (Standard)";
|
|
75
|
-
readonly value: "standard";
|
|
76
|
-
}, {
|
|
77
|
-
readonly label: "Level 2: 高安全性 (High Security)";
|
|
78
|
-
readonly value: "high_security";
|
|
79
|
-
}, {
|
|
80
|
-
readonly label: "Level 3: 金融级监管 (Financial)";
|
|
81
|
-
readonly value: "financial";
|
|
82
|
-
}];
|
|
83
|
-
readonly description: "合规等级越高,可选资源规格越严格";
|
|
84
|
-
}];
|
|
85
|
-
}, {
|
|
86
|
-
readonly type: "group";
|
|
87
|
-
readonly name: "specs";
|
|
88
|
-
readonly label: "核心资源配置";
|
|
89
|
-
readonly children: readonly [{
|
|
90
|
-
readonly type: "select";
|
|
91
|
-
readonly name: "instanceFamily";
|
|
92
|
-
readonly label: "实例家族";
|
|
93
|
-
readonly defaultValue: "general";
|
|
94
|
-
readonly required: true;
|
|
95
|
-
readonly options: readonly [{
|
|
96
|
-
readonly label: "通用型 (g6)";
|
|
97
|
-
readonly value: "general";
|
|
98
|
-
}, {
|
|
99
|
-
readonly label: "计算型 (c6)";
|
|
100
|
-
readonly value: "compute";
|
|
101
|
-
}, {
|
|
102
|
-
readonly label: "GPU 训练型 (gn7)";
|
|
103
|
-
readonly value: "gpu";
|
|
104
|
-
}, {
|
|
105
|
-
readonly label: "高 IO 型 (i3)";
|
|
106
|
-
readonly value: "high_io";
|
|
107
|
-
}];
|
|
108
|
-
readonly message: "";
|
|
109
|
-
}, {
|
|
110
|
-
readonly type: "group";
|
|
111
|
-
readonly name: "storage";
|
|
112
|
-
readonly label: "存储方案";
|
|
113
|
-
readonly children: readonly [{
|
|
114
|
-
readonly type: "select";
|
|
115
|
-
readonly name: "diskType";
|
|
116
|
-
readonly label: "系统盘类型";
|
|
117
|
-
readonly defaultValue: "ssd";
|
|
118
|
-
readonly required: true;
|
|
119
|
-
readonly options: readonly [{
|
|
120
|
-
readonly label: "ESSD 增强型 SSD";
|
|
121
|
-
readonly value: "essd";
|
|
122
|
-
}, {
|
|
123
|
-
readonly label: "标准 SSD";
|
|
124
|
-
readonly value: "ssd";
|
|
125
|
-
}, {
|
|
126
|
-
readonly label: "高效云盘 (HDD)";
|
|
127
|
-
readonly value: "hdd";
|
|
128
|
-
}];
|
|
129
|
-
}, {
|
|
130
|
-
readonly type: "number";
|
|
131
|
-
readonly name: "capacity";
|
|
132
|
-
readonly label: "系统盘容量 (GB)";
|
|
133
|
-
readonly defaultValue: 40;
|
|
134
|
-
readonly min: 20;
|
|
135
|
-
readonly max: 32768;
|
|
136
|
-
readonly step: 10;
|
|
137
|
-
readonly required: true;
|
|
138
|
-
readonly message: "";
|
|
139
|
-
}];
|
|
140
|
-
}];
|
|
141
|
-
}, {
|
|
142
|
-
readonly type: "group";
|
|
143
|
-
readonly name: "security";
|
|
144
|
-
readonly label: "安全加固选项";
|
|
145
|
-
readonly children: readonly [{
|
|
146
|
-
readonly type: "select";
|
|
147
|
-
readonly name: "encryption";
|
|
148
|
-
readonly label: "数据盘加密";
|
|
149
|
-
readonly defaultValue: "no";
|
|
150
|
-
readonly required: true;
|
|
151
|
-
readonly options: readonly [{
|
|
152
|
-
readonly label: "开启落盘加密 (KMS)";
|
|
153
|
-
readonly value: "yes";
|
|
154
|
-
}, {
|
|
155
|
-
readonly label: "暂不开启";
|
|
156
|
-
readonly value: "no";
|
|
157
|
-
}];
|
|
158
|
-
}, {
|
|
159
|
-
readonly type: "input";
|
|
160
|
-
readonly name: "kmsKey";
|
|
161
|
-
readonly label: "KMS 密钥 ID";
|
|
162
|
-
readonly defaultValue: "";
|
|
163
|
-
readonly maxLength: 8;
|
|
164
|
-
readonly hidden: true;
|
|
165
|
-
readonly required: false;
|
|
166
|
-
readonly placeholder: "请输入云平台提供的密钥 UUID";
|
|
167
|
-
}];
|
|
168
|
-
}, {
|
|
169
|
-
readonly type: "group";
|
|
170
|
-
readonly name: "billing";
|
|
171
|
-
readonly label: "计费与汇总";
|
|
172
|
-
readonly children: readonly [{
|
|
173
|
-
readonly type: "number";
|
|
174
|
-
readonly name: "totalPrice";
|
|
175
|
-
readonly label: "预估月度总价";
|
|
176
|
-
readonly defaultValue: 0;
|
|
177
|
-
readonly readonly: true;
|
|
178
|
-
readonly required: true;
|
|
179
|
-
readonly prefix: "¥";
|
|
180
|
-
}, {
|
|
181
|
-
readonly type: "input";
|
|
182
|
-
readonly name: "priceDetail";
|
|
183
|
-
readonly label: "计费项说明";
|
|
184
|
-
readonly defaultValue: "基础配置费用";
|
|
185
|
-
readonly readonly: true;
|
|
186
|
-
readonly required: false;
|
|
187
|
-
readonly hidden: false;
|
|
188
|
-
}, {
|
|
189
|
-
readonly type: "checkbox";
|
|
190
|
-
readonly name: "autoRenew";
|
|
191
|
-
readonly label: "开启自动续费";
|
|
192
|
-
readonly defaultValue: false;
|
|
193
|
-
readonly disabled: false;
|
|
194
|
-
readonly description: "暂不支持自动续费";
|
|
195
|
-
}];
|
|
196
|
-
}];
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
type FormDataModel = FormResultType<typeof clonedschema>;
|
|
200
|
-
type AllPath = GetAllPath<FormDataModel> | (string & {});
|
|
201
|
-
|
|
202
85
|
type BaseField = {
|
|
203
86
|
label: string;
|
|
204
87
|
name: string;
|
|
@@ -238,7 +121,7 @@ type GroupField = Omit<BaseField, "label" | "name" | "placeholder" | "validators
|
|
|
238
121
|
};
|
|
239
122
|
type FormFieldSchema = InputField | CheckboxField | SelectField | GroupField;
|
|
240
123
|
type RenderSchemaExtraCommonType<P = any> = {
|
|
241
|
-
path:
|
|
124
|
+
path: P;
|
|
242
125
|
dirtySignal: any;
|
|
243
126
|
uid: number;
|
|
244
127
|
nodeBucket: Record<string, SchemaBucket<P>>;
|
|
@@ -248,19 +131,6 @@ type RenderSchemaFn<T> = FinalFlatten<T extends GroupField ? Omit<T, "children">
|
|
|
248
131
|
children: Array<RenderSchemaFn<FormFieldSchema>>;
|
|
249
132
|
} : T & RenderSchemaExtraCommonType>;
|
|
250
133
|
type RenderSchema = RenderSchemaFn<FormFieldSchema>;
|
|
251
|
-
type CollapseChildren<T> = T extends readonly [infer First, ...infer Rest] ? FormResultType<First> & CollapseChildren<Rest> : {};
|
|
252
|
-
type FormResultType<T> = T extends any ? T extends {
|
|
253
|
-
readonly type: "group";
|
|
254
|
-
readonly name: infer N;
|
|
255
|
-
readonly children: infer C;
|
|
256
|
-
} ? N extends string ? N extends "" ? FinalFlatten<CollapseChildren<C>> : {
|
|
257
|
-
[K in N]: FinalFlatten<CollapseChildren<C>>;
|
|
258
|
-
} : FinalFlatten<CollapseChildren<C>> : T extends {
|
|
259
|
-
readonly name: infer N;
|
|
260
|
-
readonly defaultValue: infer V;
|
|
261
|
-
} ? N extends string ? {
|
|
262
|
-
[K in N]: FinalFlatten<V>;
|
|
263
|
-
} : never : {} : {};
|
|
264
134
|
|
|
265
135
|
interface logicApi {
|
|
266
136
|
slot: {
|
|
@@ -275,7 +145,7 @@ type Engine<T> = {
|
|
|
275
145
|
[K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue']: GetType<T, K>;
|
|
276
146
|
};
|
|
277
147
|
config: {
|
|
278
|
-
[K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace"]: GetType<T, K>;
|
|
148
|
+
[K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
|
|
279
149
|
};
|
|
280
150
|
dependency: {
|
|
281
151
|
[K in 'GetAllDependency' | 'GetDependencyOrder']: GetType<T, K>;
|
|
@@ -284,9 +154,10 @@ type Engine<T> = {
|
|
|
284
154
|
[K in "Undo" | "Redo" | "initCanUndo" | "initCanRedo"]: GetType<T, K>;
|
|
285
155
|
};
|
|
286
156
|
hooks: {
|
|
287
|
-
[K in "onError"]: GetType<T, K>;
|
|
157
|
+
[K in "onError" | "onSuccess" | "onStart"]: GetType<T, K>;
|
|
288
158
|
};
|
|
289
159
|
};
|
|
160
|
+
/** @deprecated 请使用新的 useMeshFlow 别名 */
|
|
290
161
|
declare const useEngineManager: <T, P extends string>(id: string | symbol, Schema: any, UITrigger: {
|
|
291
162
|
signalCreateor: () => T;
|
|
292
163
|
signalTrigger: (signal: T) => void;
|
|
@@ -310,31 +181,13 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
|
|
|
310
181
|
condition: (data: any) => boolean;
|
|
311
182
|
}) => void;
|
|
312
183
|
SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
|
|
184
|
+
usePlugin: (plugin: {
|
|
185
|
+
apply: (api: {
|
|
186
|
+
on: (event: MeshEventName, cb: Function) => () => boolean;
|
|
187
|
+
}) => void;
|
|
188
|
+
}) => () => void;
|
|
313
189
|
SetValue: (path: P, value: any) => void;
|
|
314
|
-
GetFormData: () =>
|
|
315
|
-
cloudConsole: {
|
|
316
|
-
environment: {
|
|
317
|
-
region: "china";
|
|
318
|
-
compliance: "standard";
|
|
319
|
-
};
|
|
320
|
-
specs: {
|
|
321
|
-
instanceFamily: "general";
|
|
322
|
-
storage: {
|
|
323
|
-
diskType: "ssd";
|
|
324
|
-
capacity: 40;
|
|
325
|
-
};
|
|
326
|
-
};
|
|
327
|
-
security: {
|
|
328
|
-
encryption: "no";
|
|
329
|
-
kmsKey: "";
|
|
330
|
-
};
|
|
331
|
-
billing: {
|
|
332
|
-
totalPrice: 0;
|
|
333
|
-
priceDetail: "基础配置费用";
|
|
334
|
-
autoRenew: false;
|
|
335
|
-
};
|
|
336
|
-
};
|
|
337
|
-
};
|
|
190
|
+
GetFormData: () => any;
|
|
338
191
|
notifyAll: () => void;
|
|
339
192
|
AddNewSchema: (path: string, data: any) => RenderSchema;
|
|
340
193
|
GetAllDependency: () => Map<P, Set<P>>;
|
|
@@ -344,6 +197,10 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
|
|
|
344
197
|
initCanUndo: (cb: (newVal: number) => any) => void;
|
|
345
198
|
initCanRedo: (cb: (newVal: number) => any) => void;
|
|
346
199
|
onError: (cb: (error: MeshErrorContext) => void) => () => void;
|
|
200
|
+
onSuccess: (cb: (data: unknown) => void) => () => void;
|
|
201
|
+
onStart: (cb: (data: {
|
|
202
|
+
path: P;
|
|
203
|
+
}) => void) => () => void;
|
|
347
204
|
}>;
|
|
348
205
|
declare const useEngine: <T = any, P extends string = string>(id: string | symbol) => Engine<{
|
|
349
206
|
schema: RenderSchema;
|
|
@@ -365,31 +222,13 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
|
|
|
365
222
|
condition: (data: any) => boolean;
|
|
366
223
|
}) => void;
|
|
367
224
|
SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
|
|
225
|
+
usePlugin: (plugin: {
|
|
226
|
+
apply: (api: {
|
|
227
|
+
on: (event: MeshEventName, cb: Function) => () => boolean;
|
|
228
|
+
}) => void;
|
|
229
|
+
}) => () => void;
|
|
368
230
|
SetValue: (path: P, value: any) => void;
|
|
369
|
-
GetFormData: () =>
|
|
370
|
-
cloudConsole: {
|
|
371
|
-
environment: {
|
|
372
|
-
region: "china";
|
|
373
|
-
compliance: "standard";
|
|
374
|
-
};
|
|
375
|
-
specs: {
|
|
376
|
-
instanceFamily: "general";
|
|
377
|
-
storage: {
|
|
378
|
-
diskType: "ssd";
|
|
379
|
-
capacity: 40;
|
|
380
|
-
};
|
|
381
|
-
};
|
|
382
|
-
security: {
|
|
383
|
-
encryption: "no";
|
|
384
|
-
kmsKey: "";
|
|
385
|
-
};
|
|
386
|
-
billing: {
|
|
387
|
-
totalPrice: 0;
|
|
388
|
-
priceDetail: "基础配置费用";
|
|
389
|
-
autoRenew: false;
|
|
390
|
-
};
|
|
391
|
-
};
|
|
392
|
-
};
|
|
231
|
+
GetFormData: () => any;
|
|
393
232
|
notifyAll: () => void;
|
|
394
233
|
AddNewSchema: (path: string, data: any) => RenderSchema;
|
|
395
234
|
GetAllDependency: () => Map<P, Set<P>>;
|
|
@@ -399,7 +238,55 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
|
|
|
399
238
|
initCanUndo: (cb: (newVal: number) => any) => void;
|
|
400
239
|
initCanRedo: (cb: (newVal: number) => any) => void;
|
|
401
240
|
onError: (cb: (error: MeshErrorContext) => void) => () => void;
|
|
241
|
+
onSuccess: (cb: (data: unknown) => void) => () => void;
|
|
242
|
+
onStart: (cb: (data: {
|
|
243
|
+
path: P;
|
|
244
|
+
}) => void) => () => void;
|
|
402
245
|
}>;
|
|
403
246
|
declare const deleteEngine: (id: string | symbol) => void;
|
|
247
|
+
declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: any, UITrigger: {
|
|
248
|
+
signalCreateor: () => T;
|
|
249
|
+
signalTrigger: (signal: T) => void;
|
|
250
|
+
}) => Engine<{
|
|
251
|
+
schema: RenderSchema;
|
|
252
|
+
SetRule: (outDegreePath: P, inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
|
|
253
|
+
value?: any;
|
|
254
|
+
priority?: number;
|
|
255
|
+
forceNotify?: boolean;
|
|
256
|
+
logic: (api: logicApi) => any;
|
|
257
|
+
} | undefined) => void;
|
|
258
|
+
SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
|
|
259
|
+
value?: any;
|
|
260
|
+
priority?: number;
|
|
261
|
+
forceNotify?: boolean;
|
|
262
|
+
logic: (api: logicApi) => any;
|
|
263
|
+
} | undefined) => void;
|
|
264
|
+
SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
|
|
265
|
+
SetValidators: (path: P, options: {
|
|
266
|
+
logic: (val: any, GetByPath: any) => any;
|
|
267
|
+
condition: (data: any) => boolean;
|
|
268
|
+
}) => void;
|
|
269
|
+
SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
|
|
270
|
+
usePlugin: (plugin: {
|
|
271
|
+
apply: (api: {
|
|
272
|
+
on: (event: MeshEventName, cb: Function) => () => boolean;
|
|
273
|
+
}) => void;
|
|
274
|
+
}) => () => void;
|
|
275
|
+
SetValue: (path: P, value: any) => void;
|
|
276
|
+
GetFormData: () => any;
|
|
277
|
+
notifyAll: () => void;
|
|
278
|
+
AddNewSchema: (path: string, data: any) => RenderSchema;
|
|
279
|
+
GetAllDependency: () => Map<P, Set<P>>;
|
|
280
|
+
GetDependencyOrder: () => P[][];
|
|
281
|
+
Undo: () => void;
|
|
282
|
+
Redo: () => void;
|
|
283
|
+
initCanUndo: (cb: (newVal: number) => any) => void;
|
|
284
|
+
initCanRedo: (cb: (newVal: number) => any) => void;
|
|
285
|
+
onError: (cb: (error: MeshErrorContext) => void) => () => void;
|
|
286
|
+
onSuccess: (cb: (data: unknown) => void) => () => void;
|
|
287
|
+
onStart: (cb: (data: {
|
|
288
|
+
path: P;
|
|
289
|
+
}) => void) => () => void;
|
|
290
|
+
}>;
|
|
404
291
|
|
|
405
|
-
export { deleteEngine, useEngine, useEngineManager };
|
|
292
|
+
export { deleteEngine, useEngine, useEngineManager, useMeshFlow };
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var j=class{computedRules=[];store={OR:async(e,o)=>{let t,s,n=this.computedRules;for(let u of n){let a=await u.logic(e);if(u.entityId==="__base__"){s=a;continue}if(a){t=u.value;break}}return typeof t>"u"&&(t=s),{res:t,version:o}},PRIORITY:async(e,o)=>{let t=null,s=this.computedRules;try{for(let n of s){let u=await n.logic(e);if(u!==void 0){t=u;break}}}catch(n){throw n}return {res:t,version:o}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(e.values()).map(o=>Array.from(o)).flat().sort((o,t)=>t.priority-o.priority):this.computedRules=Array.from(e.values()).map(o=>Array.from(o)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,o){return this.CurrentStrategy(e,o)}},K=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,o,t){let s=()=>this.rules;this.strategy=new j(s),this.path=t,this.isDefaultValue=o==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let o=new Set;o.add(e),this.rules.set(e.id,o);}setRules(e,o){o&&this.updateDeps(o);let t=++this.id,s={...e,entityId:t};for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(s);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let u=this.rules.get(n);u&&(u.delete(s),u.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[o,t]of e)this.deps.set(o,t);}setRule(e,o){if(o&&this.updateDeps(o),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,s={...e,entityId:t};if(e)for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(s);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let u=this.rules.get(n);u&&(u.delete(s),u.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}async evaluate(e){let o=null;if(e.GetToken&&(o=e.GetToken()),this.pendingPromise&&this.promiseToken!==o&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=o;let t=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let s=!1;if(typeof e.triggerPath=="string"){s=!0;let a=this.deps.get(e.triggerPath),p=e.GetValueByPath(e.triggerPath);if(`${e.triggerPath}`,typeof a=="object"||typeof p=="object")s=!1;else {let c=Array.from(this.deps.keys());for(let i of c){let r=this.deps.get(i),h=e.GetValueByPath(i);if(r!==h){`${i}${r}${h}`,s=!1;break}}}}if(s)return `${this.path}`,this.cache,this.cache;let{res:n,version:u}=await this.strategy.evaluate(e,t);if(o!==this.promiseToken)return `${this.version}${u}`,this.cache,this.cache;if(u<this.version)return this.cache;if(this.inferType(n)!==this.contract&&`${this.contract}`,this.cache=n,o===this.promiseToken){`${this.path}`;let a=Array.from(this.deps.keys());for(let p of a){let c=e.GetValueByPath(p);this.deps.set(p,c);}}return n}catch(s){throw {path:this.path,info:s}}finally{this.promiseToken===o&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},z=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:t=>t||typeof t=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:t=>!!t.required},o={logic:function(t){return t.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(o.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(o);}evaluate(e,o){let t=true,s=[...this.defaultValidators,...this.validators];for(let n of s){if(!n.condition(o))continue;let a=n.logic(e);if(typeof a!="boolean"){t=a;break}}return t}};function Q(l,e,o,t,s){let n=new Map;return (a,p)=>{let i=Symbol("token");n.set(a,i);let r=false,h=new Set,y=new Set,m=new Set(l.GetAllNextDependency(a));m.add(a);let x=new Map,R=new Map,M=performance.now(),w=l.GetPathToLevelMap(),A=w.get(a)??0;m.forEach(v=>{if(v===a||p.includes(v))return;let d=l.GetPrevDependency(v).filter(f=>m.has(f)).length;d>0&&R.set(v,d);}),h.add(a);let E=Array.from(p).map(v=>(x.set(v,(x.get(v)||0)+1),{target:v,trigger:a,isReleased:false}));e.pushExecution([...Array.from(p),a],true),`${a}${i.description}`;let $=async v=>{let{target:S,trigger:d}=v;try{if(n.get(a)!==i)return;let f=!1,T=!1,g=o.GetRenderSchemaByPath(S);`${S}`,g.defaultValue;for(let F in g.nodeBucket){let b=g.nodeBucket[F],V=await b.evaluate({affectKey:F,triggerPath:d,GetRenderSchemaByPath:o.GetRenderSchemaByPath,GetValueByPath:P=>o.GetRenderSchemaByPath(P).defaultValue,GetToken:()=>i});if(n.get(a)!==i){`${S}`;return}F==="options"&&(V.some(G=>G.value==g.defaultValue)||(g.defaultValue=void 0,f=!0)),V!==g[F]&&(g[F]=V,f=!0),b.isForceNotify()&&(T=!0),f&&s.flushPathSet.add(S),h.add(S);let B=l.GetNextDependency(S);(f||T)&&l.GetAllNextDependency(S).forEach(G=>m.add(G));for(let P of B){if(h.has(P)){`${P}`;continue}if(f||T){if(!R.has(P)&&!h.has(P)&&!x.has(P)){let L=l.GetPrevDependency(P).filter(U=>m.has(U)).length;R.set(P,L);}let G=R.get(P)??0,C=Math.max(0,G-1);C<=0?(R.delete(P),E.push({target:P,trigger:S,isReleased:!0}),x.set(P,1),e.pushExecution([P]),`${S}${P}`):R.set(P,C);}else `${S}${P}`;}}if(performance.now()-M>16&&(await new Promise(F=>requestAnimationFrame(F)),M=performance.now(),n.get(a)!==i))return;n.get(a)===i&&s.requestUpdate();}catch(f){let T=Symbol("abort");n.set(a,T),E.length=0,R.clear(),y.clear(),e.markError(S),t.callOnError(f);}finally{n.get(a)===i&&(y.size-1,y.delete(S),e.popExecution([S]),r||O());}},O=async()=>{if(n.get(a)!==i){r=false;return}r=true;try{for(;(E.length>0||R.size>0)&&n.get(a)===i;){if(E.length>0){if(y.size>=20){r=!1;return}let v=E.shift(),{target:S}=v;if(h.has(S)){`${S}`;continue}`${S}`,v.isReleased,`${E.length}`;let d=x.get(S)||0;d<=1?x.delete(S):x.set(S,d-1);let f=w.get(S)??0;if(f>A+1&&!v.isReleased){`${S}${f}${A}`,R.set(S,1);continue}y.add(S),`${S}${y.size}${Array.from(y).join(",")}`,e.pushExecution([S]),$(v);continue}if(y.size>0){`${Array.from(y).join(",")}`,r=!1;return}if(R.size>0){`${A}`;let v=!1,S=[];for(let[d]of R)l.GetPrevDependency(d).some(g=>h.has(g)?!1:y.has(g)||x.has(g)||m.has(g)?!0:(w.get(g)??0)>A)||S.push(d);if(S.length>0&&(S.forEach(d=>{R.delete(d),E.push({target:d,trigger:a,isReleased:!0}),x.set(d,1),e.pushExecution([d]);}),v=!0,`${S.join(",")}`),v)continue;if(Array.from(R.keys()).some(f=>l.GetPrevDependency(f).some(g=>m.has(g)&&!h.has(g)))){`${A}`,r=!1;return}if(A++,`${A}`,A>2e3)break;continue}}}finally{r=false;}};O();}}function X(l,e,o,t,s,n){let u=le(l),a=0,p=new Map,c=new Map,i=new Map,r=false,h=new Set,y=d=>{let f=p.get(d);return c.get(f)},m=d=>i.get(d),x=async()=>{let d=Array.from(h);h.clear();for(let f of d){let T=y(f);n.signalTrigger(T.dirtySignal);}},R=()=>{r||(r=true,Promise.resolve().then(()=>{try{for(;h.size>0;)x();}finally{r=false;}}));},M=()=>{let d=(f,T,g)=>{if(typeof f!="object"||f===null||Array.isArray(f)){if(g.length>0){let b=g[g.length-1];T[b]=y(g.join(".")).defaultValue;}return}let F=Object.getOwnPropertyNames(f);for(let b of F)g.push(b),d(f[b],f,g),g.pop();};return d(u,null,[]),u},w=Q(e,o,{GetRenderSchemaByPath:y},s,{requestUpdate:R,flushPathSet:h}),I=async()=>{let d=e.GetDependencyOrder().flat();try{for(let f of d){let T=y(f);for(let g in T.nodeBucket){let F=await T.nodeBucket[g].evaluate({affectKey:g,triggerPath:void 0,GetRenderSchemaByPath:y,GetValueByPath:b=>y(b).defaultValue,isSameToken:()=>!1});if(g==="options"){let b=!1,V=T.defaultValue;for(let B of F)B.value==V&&(b=!0);b||(T.defaultValue=void 0,R());}F!==T[g]&&(T[g]=F,h.add(f),R());}}}catch(f){s.callOnError(f);}},A=async d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!y(d))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");h.add(d),R();let T=e.GetNextDependency(d);E(T,d),o.popExecution([d],true);};async function E(d,f){w(f,d);}let $=d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");let f=y(d);f.nodeBucket.defaultValue&&f.nodeBucket.defaultValue.updateInputValueRule(f.defaultValue);},O=(d,f="")=>{let T="name"in d?d.name:void 0,g=T?f===""?T:`${f}.${T}`:f,F=n.signalCreateor(),b=a++,V={getRenderSchema:G=>y(G)},B=async(G,C)=>{let L=G(C),U=y(C.path),H=t.createHistoryAction([{path:C.path,value:U.defaultValue},{path:C.path,value:L}],async _=>{let W=y(_.path);W.defaultValue=_.value,$(_.path),await A(_.path);});U.defaultValue=L,t.pushIntoHistory(H),$(C.path),await A(C.path);},P={...d,disabled:!!d.disabled,hidden:"hidden"in d?d.hidden:false,readonly:"readonly"in d?d.readonly:false,required:"required"in d?d.required:false,path:g,dirtySignal:F,uid:b,nodeBucket:{},validators:new z(g),theme:"secondary",dependOn:async G=>await B(G,{...V,path:g})};return d.type==="group"&&(delete P.nodeBucket,delete P.validators,P.children=d.children.map(G=>O(G,g)),i.set(P.path,P)),p.set(P.path,P.uid),c.set(P.uid,P),P};return {schema:O(l),GetFormData:()=>M(),GetRenderSchemaByPath:y,GetGroupByPath:m,notifyAll:I,convertToRenderSchema:O}}function le(l,e={}){let o=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((u,a)=>[...u,o(a)],[])};if(n.type=="input"||n.type=="number"||n.type=="select"||n.type=="checkbox")return {key:n.name,isGroup:false,val:n.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${n.type}`)},t=(n,u)=>{if(u.isGroup){let a={};u.key===""?a=n:n[u.key]=a,u.val.forEach(p=>{t(a,p);});}else n[u.key]=u.val;},s=o(l);return t(e,s),e}var J=(l,e,o)=>{let s=n=>{let u=o.triggerPaths.map(c=>n.GetValueByPath(c)),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>u}),Object.defineProperty(a,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(l)[e]}),o.logic({slot:a})};return {value:o.value,targetPath:l,triggerPaths:o.triggerPaths,priority:o.priority??10,logic:s}},Z=(l,e,o)=>{if(!l)throw Error("");let t=l,s=(a,p)=>{e.has(a)||e.set(a,new Set),e.get(a).add(p),o.has(p)||o.set(p,new Set),o.get(p).add(a);};return {SetRule:(a,p,c,i={logic:r=>{}})=>{let r=t(p),h=J(p,c,{...i,triggerPaths:[a]}),y=[a].map(m=>[m,t(m).defaultValue]);if(s(a,p),r.nodeBucket[c])r.nodeBucket[c].setRule(h,y);else {let m=new K(r[c],c,p);m.setRule(h,y),r.nodeBucket[c]=m;}i.forceNotify&&r.nodeBucket[c].forceNotify();},SetRules:(a,p,c,i={logic:r=>{}})=>{let r=t(p);for(let m of a)s(m,p);let h=J(p,c,{...i,triggerPaths:a}),y=a.map(m=>[m,t(m).defaultValue]);if(r.nodeBucket[c])r.nodeBucket[c].setRules(h,y);else {let m=new K(r[c],c,p);m.setRules(h,y),r.nodeBucket[c]=m;}i.forceNotify&&r.nodeBucket[c].forceNotify();}}},ee=l=>{let e=l||void 0;if(!e)throw Error("");return {SetStrategy:(t,s,n)=>{e(t).nodeBucket[s].setStrategy(n);}}};var te=l=>{let e=l||void 0;return {SetValidators:(t,s)=>{let n=e(t),u=(p,c,i)=>p(c,i),a=(p,c,i)=>p(c,i);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:p=>u(s.logic,p,e),condition:typeof s.condition=="function"?p=>a(s.condition,p,e):()=>true});}}};function ne(l){let e=new Map,o=new Map,t=new Set,s=(c,i)=>{if(e.get(c)===i)return;e.set(c,i);let r=o.get(c);r&&r(i);};return {pushExecution:(c,i)=>{i&&(t.forEach(r=>s(r,"idle")),t.clear(),e.clear()),c.length!==0&&c.forEach(r=>{t.has(r)||t.add(r),s(r,"calculating"),l(r).forEach(y=>{t.has(y)||(t.add(y),e.has(y)||s(y,"pending"));});});},popExecution:c=>{c.forEach(i=>{s(i,"calculated");});},markError:c=>{s(c,"error"),t.forEach(i=>{let r=e.get(i);i!==c&&(r==="pending"||r==="calculating")&&s(i,"canceled");});},SetTrace:(c,i,r)=>{o.set(c,i);let h=e.get(c)||"idle";return i(h),()=>{o.delete(c);}}}}function re(l,e,o,t){let s=i=>{let r=l(),h=e(),y=new Set;return r.get(i)?.forEach(m=>y.add(m)),y.size===0?[]:Array.from(y).filter(m=>{let x=h.get(m)||new Set;return !Array.from(x).some(w=>y.has(w))})};return {GetNextDependency:i=>{let r=t();return Array.from(r.get(i)||[])},GetPrevDependency:i=>{let r=o();return Array.from(r.get(i)||[])},GetAllPrevDependency:i=>{let r=e();return Array.from(r.get(i)||[])},GetAllNextDependency:i=>{let r=l();return Array.from(r.get(i)||[])},rebuildDirectDependencyMaps:i=>{let r=new Map,h=new Map;for(let y of i){let m=s(y);r.set(y,new Set(m));for(let x of m)h.has(x)||h.set(x,new Set),h.get(x).add(y);}return {directNextMap:r,directPrevMap:h}}}}function oe(l){let e=t=>{let s=[],n=[],u=new Map,a=t.size,p=0,c=0;for(let[i,r]of t)r===0&&n.push(i);if(n.length===0&&a>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;n.length>0;){s.push([...n]);let i=[];for(let r of n){p++,u.set(r,c);let h=l.get(r);if(h)for(let y of h){let m=t.get(y)-1;t.set(y,m),m===0&&i.push(y);}}n=i,c++;}if(p<a)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:s,levelMap:u}};return ()=>{let t=new Map;for(let s of l.keys()){let n=Array.from(l.get(s)||[]);t.has(s)||t.set(s,0);for(let u of n){let a=t.get(u)||0;t.set(u,++a);}}return e(t)}}function ae(){let l=[],e=[],t={canRedo:()=>{},canUndo:()=>{}},s=()=>{if(!l.length)return;let r=l.pop();r?.undoAction(),p(r);},n=()=>{if(!e.length)return;let r=e.pop();r?.redoAction(),c(r,false);},u=r=>{t.canUndo=()=>r(l.length);},a=r=>{t.canRedo=()=>r(e.length);},p=r=>{e.push(r),e.length>100&&e.shift(),t.canRedo(),t.canUndo();},c=(r,h=true)=>{h&&(e.length=0),l.push(r),l.length>100&&l.shift(),t.canUndo(),t.canRedo();};return {Undo:s,Redo:n,PushIntoHistory:c,CreateHistoryAction:(r,h)=>{let[y,m]=r;return {undoAction:()=>h(y),redoAction:()=>h(m)}},initCanUndo:u,initCanRedo:a}}function se(){let l=[];return {onError:t=>{let s=n=>t(n);return l.push(s),()=>{let n=l.findIndex(u=>u===s);l.splice(n,1);}},callOnError:t=>{for(let s of l)s(t);}}}function ie(l,e){let o=false,t=false,s=new Map,n=new Map,u=new Map,a=new Map,p=[],c=new Map,{GetNextDependency:i,GetPrevDependency:r,GetAllPrevDependency:h,GetAllNextDependency:y,rebuildDirectDependencyMaps:m}=re(()=>s,()=>n,()=>a,()=>u),{SetTrace:x,pushExecution:R,popExecution:M,markError:w}=ne(i),{Undo:I,Redo:A,PushIntoHistory:E,CreateHistoryAction:$,initCanUndo:O,initCanRedo:v}=ae(),{onError:S,callOnError:d}=se(),{schema:f,GetFormData:T,GetRenderSchemaByPath:g,GetGroupByPath:F,notifyAll:b,convertToRenderSchema:V}=X(l,{GetDependencyOrder:()=>p,GetAllNextDependency:y,GetNextDependency:i,GetPrevDependency:r,GetAllPrevDependency:h,GetPathToLevelMap:()=>c},{pushExecution:R,popExecution:M,markError:w},{pushIntoHistory:E,createHistoryAction:$},{callOnError:d},e),B=(k,D)=>{let N=F(k),Y=V(D,k);return N.children.push(Y),N.dirtySignal.value++,Y},{SetRule:P,SetRules:G}=Z(g,s,n),{SetStrategy:C}=ee(g),{SetValidators:L}=te(g),U=oe(s),H=()=>{let k=U();p=k.steps,c=k.levelMap;};return {schema:f,SetRule:(...k)=>{P.apply(null,k),o=true,!t&&new Promise((D,N)=>{t=true,D();}).then(()=>{if(H(),o){let{directNextMap:D,directPrevMap:N}=m(p.flat());u=D,a=N;}}).finally(()=>{t=false,o=false;});},SetRules:(...k)=>{G.apply(null,k),o=true,!t&&new Promise((D,N)=>{t=true,D();}).then(()=>{if(H(),o){let{directNextMap:D,directPrevMap:N}=m(p.flat());u=D,a=N;}}).finally(()=>{t=false,o=false;});},SetStrategy:C,SetValidators:L,SetTrace:x,SetValue:(k,D)=>{g(k).dependOn(()=>D);},GetFormData:T,notifyAll:()=>{H(),b();},AddNewSchema:B,GetAllDependency:()=>s,GetDependencyOrder:()=>p,Undo:I,Redo:A,initCanUndo:O,initCanRedo:v,onError:S}}var q=new Map,$e=(l,e,o)=>{try{if(typeof o.signalCreateor!="function"||typeof o.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(q.has(l))throw Error("engineID\u91CD\u590D\uFF0C\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let t=ie(e,o),{schema:s,GetFormData:n,SetRule:u,SetRules:a,SetStrategy:p,SetValidators:c,SetValue:i,notifyAll:r,SetTrace:h,GetAllDependency:y,GetDependencyOrder:m,AddNewSchema:x,Undo:R,Redo:M,initCanUndo:w,initCanRedo:I,onError:A}=t,E={config:{SetRule:u,SetRules:a,SetStrategy:p,SetValidators:c,notifyAll:r,SetTrace:h},data:{schema:s,GetFormData:n,AddNewSchema:x,SetValue:i},history:{Undo:R,Redo:M,initCanUndo:w,initCanRedo:I},dependency:{GetAllDependency:y,GetDependencyOrder:m},hooks:{onError:A}};return q.set(l,E),E}catch(t){throw Error(t)}},Le=l=>{if(q.has(l))return q.get(l);throw Error("\u4E0D\u5B58\u5728\u7684id")},Ue=l=>{q.delete(l);};exports.deleteEngine=Ue;exports.useEngine=Le;exports.useEngineManager=$e;
|
|
1
|
+
'use strict';var Q=class{computedRules=[];store={OR:async(e,r)=>{let t,i,n=this.computedRules;for(let c of n){let o=await c.logic(e);if(c.entityId==="__base__"){i=o;continue}if(o){t=c.value;break}}return typeof t>"u"&&(t=i),{res:t,version:r}},PRIORITY:async(e,r)=>{let t=null,i=this.computedRules;try{for(let n of i){let c=await n.logic(e);if(c!==void 0){t=c;break}}}catch(n){throw n}return {res:t,version:r}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat().sort((r,t)=>t.priority-r.priority):this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,r){return this.CurrentStrategy(e,r)}},$=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,r,t){let i=()=>this.rules;this.strategy=new Q(i),this.path=t,this.isDefaultValue=r==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let r=new Set;r.add(e),this.rules.set(e.id,r);}setRules(e,r){r&&this.updateDeps(r);let t=++this.id,i={...e,entityId:t};for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[r,t]of e)this.deps.set(r,t);}setRule(e,r){if(r&&this.updateDeps(r),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,i={...e,entityId:t};if(e)for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}async evaluate(e){let r=null;if(e.GetToken&&(r=e.GetToken()),this.pendingPromise&&this.promiseToken!==r&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=r;let t=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let i=!1;if(typeof e.triggerPath=="string"){i=!0;let o=this.deps.get(e.triggerPath),p=e.GetValueByPath(e.triggerPath);if(typeof o=="object"||typeof p=="object")i=!1;else {let u=Array.from(this.deps.keys());for(let l of u){let a=this.deps.get(l),h=e.GetValueByPath(l);if(a!==h){i=!1;break}}}}if(i)return this.cache;let{res:n,version:c}=await this.strategy.evaluate(e,t);if(r!==this.promiseToken)return this.cache;if(c<this.version)return this.cache;if(this.inferType(n)!==this.contract&&`${this.contract}`,this.cache=n,r===this.promiseToken){let o=Array.from(this.deps.keys());for(let p of o){let u=e.GetValueByPath(p);this.deps.set(p,u);}}return n}catch(i){throw {path:this.path,info:i}}finally{this.promiseToken===r&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},z=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:t=>t||typeof t=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:t=>!!t.required},r={logic:function(t){return t.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(r.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(r);}evaluate(e,r){let t=true,i=[...this.defaultValidators,...this.validators];for(let n of i){if(!n.condition(r))continue;let o=n.logic(e);if(typeof o!="boolean"){t=o;break}}return t}};function J(s,e,r,t,i){let n=new Map;return (o,p)=>{let l=Symbol("token");n.set(o,l);let a=false,h=new Set,y=new Set,m=new Set(s.GetAllNextDependency(o));m.add(o);let x=new Map,R=new Map,O=performance.now(),A=s.GetPathToLevelMap(),E=A.get(o)??0;m.forEach(v=>{if(v===o||p.includes(v))return;let d=s.GetPrevDependency(v).filter(f=>m.has(f)).length;d>0&&R.set(v,d);}),h.add(o);let G=Array.from(p).map(v=>(x.set(v,(x.get(v)||0)+1),{target:v,trigger:o,isReleased:false}));e.pushExecution([...Array.from(p),o],true),`${o}${l.description}`,t.callOnStart({path:o});let B=async v=>{let{target:g,trigger:d}=v;try{if(n.get(o)!==l)return;let f=!1,T=!1,S=r.GetRenderSchemaByPath(g);t.emit("node:start",{path:g});for(let F in S.nodeBucket){let w=S.nodeBucket[F],V=await w.evaluate({affectKey:F,triggerPath:d,GetRenderSchemaByPath:r.GetRenderSchemaByPath,GetValueByPath:P=>r.GetRenderSchemaByPath(P).defaultValue,GetToken:()=>l});if(n.get(o)!==l){t.emit("node:intercept",{path:g,reason:`\u4EE4\u724C\u8FC7\u671F\uFF0C\u4E22\u5F03${g}\u65E7\u4EFB\u52A1\u8BA1\u7B97\u7ED3\u679C`});return}F==="options"&&(V.some(b=>b.value==S.defaultValue)||(S.defaultValue=void 0,f=!0)),V!==S[F]&&(S[F]=V,f=!0,t.emit("node:bucket:success",{path:g,key:F,value:V})),w.isForceNotify()&&(T=!0),f&&i.flushPathSet.add(g);let I=s.GetNextDependency(g);(f||T)&&s.GetAllNextDependency(g).forEach(b=>m.add(b));for(let P of I){if(h.has(P)){t.emit("node:intercept",{path:P,reason:` \u4E0B\u6E38 ${P} \u5DF2\u7531\u5176\u4ED6\u8DEF\u5F84\u5904\u7406`});continue}if(f||T){if(!R.has(P)&&!h.has(P)&&!x.has(P)){let H=s.GetPrevDependency(P).filter(U=>m.has(U)).length;R.set(P,H);}let b=R.get(P)??0,C=Math.max(0,b-1);C<=0?(R.delete(P),G.push({target:P,trigger:g,isReleased:!0}),x.set(P,1),e.pushExecution([P]),t.emit("node:release",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u53D8\u4E86`})):R.set(P,C);}else t.emit("node:stagnate",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u672A\u53D8`});}}if(t.emit("node:success",{path:g}),h.add(g),performance.now()-O>16&&(await new Promise(F=>requestAnimationFrame(F)),O=performance.now(),n.get(o)!==l))return;n.get(o)===l&&i.requestUpdate();}catch(f){t.emit("node:error",{path:g,error:f});let T=Symbol("abort");n.set(o,T),G.length=0,R.clear(),y.clear(),e.markError(g),t.callOnError(f);}finally{n.get(o)===l&&(y.delete(g),e.popExecution([g]),a||(t.emit("flow:fire",{path:g,reason:"\u4EFB\u52A1\u5F52\u822A"}),D()));}},D=async()=>{if(n.get(o)!==l){a=false;return}a=true;try{for(;(G.length>0||R.size>0)&&n.get(o)===l;){if(G.length>0){if(y.size>=20){a=!1;return}let v=G.shift(),{target:g}=v;if(h.has(g)){t.emit("node:intercept",{path:g,reason:` \u62D2\u7EDD\u91CD\u5165${g},\u5DF2\u8BA1\u7B97\u5B8C\u6210`});continue}let d=x.get(g)||0;d<=1?x.delete(g):x.set(g,d-1);let f=A.get(g)??0;if(f>E+1&&!v.isReleased){t.emit("node:intercept",{path:g,reason:` ${g} \u5C42\u7EA7\u592A\u6DF1(${f})\uFF0C\u5F53\u524D\u6C34\u4F4D(${E})`}),R.set(g,1);continue}y.add(g),t.emit("node:processing",{path:g}),e.pushExecution([g]),B(v);continue}if(y.size>0){t.emit("flow:wait",{reason:`\u961F\u5217\u5DF2\u7A7A,\u7184\u706B\u7B49\u5F85\uFF0C\u7B49\u5F85\u5F02\u6B65\u4EFB\u52A1\u5F52\u822A | \u98DE\u884C\u4E2D: ${Array.from(y).join(",")} | `}),a=!1;return}if(R.size>0){let v=!1,g=[];for(let[d]of R)s.GetPrevDependency(d).some(S=>h.has(S)?!1:y.has(S)||x.has(S)||m.has(S)?!0:(A.get(S)??0)>E)||g.push(d);if(g.length>0&&(g.forEach(d=>{R.delete(d),G.push({target:d,trigger:o,isReleased:!0}),x.set(d,1),e.pushExecution([d]);}),v=!0),v)continue;if(Array.from(R.keys()).some(f=>s.GetPrevDependency(f).some(S=>m.has(S)&&!h.has(S)))){t.emit("flow:wait",{reason:"\u5C1A\u6709\u6D3B\u8DC3\u4F9D\u8D56 \u672A\u5B8C\u6210,\u7184\u706B\u7B49\u5F85"}),a=!1;return}if(E++,E>2e3)break;continue}}}finally{R.size,y.size,G.length,a=false,t.emit("flow:wait",{reason:"\u7184\u706B\u9759\u9ED8"}),Promise.resolve().then(()=>{R.size===0&&y.size===0&&G.length===0&&t.callOnSuccess();});}};D();}}function Z(s,e,r,t,i,n){let c=me(s),o=0,p=new Map,u=new Map,l=new Map,a=false,h=new Set,y=d=>{let f=p.get(d);return u.get(f)},m=d=>l.get(d),x=async()=>{let d=Array.from(h);h.clear();for(let f of d){let T=y(f);n.signalTrigger(T.dirtySignal);}},R=()=>{a||(a=true,Promise.resolve().then(()=>{try{for(;h.size>0;)x();}finally{a=false;}}));},O=()=>{let d=(f,T,S)=>{if(typeof f!="object"||f===null||Array.isArray(f)){if(S.length>0){let w=S[S.length-1];T[w]=y(S.join(".")).defaultValue;}return}let F=Object.getOwnPropertyNames(f);for(let w of F)S.push(w),d(f[w],f,S),S.pop();};return d(c,null,[]),c},A=J(e,r,{GetRenderSchemaByPath:y},i,{requestUpdate:R,flushPathSet:h}),L=async()=>{let d=e.GetDependencyOrder().flat();try{for(let f of d){let T=y(f);for(let S in T.nodeBucket){let F=await T.nodeBucket[S].evaluate({affectKey:S,triggerPath:void 0,GetRenderSchemaByPath:y,GetValueByPath:w=>y(w).defaultValue,isSameToken:()=>!1});if(S==="options"){let w=!1,V=T.defaultValue;for(let I of F)I.value==V&&(w=!0);w||(T.defaultValue=void 0,R());}F!==T[S]&&(T[S]=F,h.add(f),R());}}}catch(f){i.callOnError(f);}},E=async d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!y(d))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");h.add(d),R();let T=e.GetNextDependency(d);G(T,d),r.popExecution([d],true);};async function G(d,f){A(f,d);}let B=d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");let f=y(d);f.nodeBucket.defaultValue&&f.nodeBucket.defaultValue.updateInputValueRule(f.defaultValue);},D=(d,f="")=>{let T="name"in d?d.name:void 0,S=T?f===""?T:`${f}.${T}`:f,F=n.signalCreateor(),w=o++,V={getRenderSchema:b=>y(b)},I=async(b,C)=>{let H=b(C),U=y(C.path),W=t.createHistoryAction([{path:C.path,value:U.defaultValue},{path:C.path,value:H}],async K=>{let j=y(K.path);j.defaultValue=K.value,B(K.path),await E(K.path);});U.defaultValue=H,t.pushIntoHistory(W),B(C.path),await E(C.path);},P={...d,disabled:!!d.disabled,hidden:"hidden"in d?d.hidden:false,readonly:"readonly"in d?d.readonly:false,required:"required"in d?d.required:false,path:S,dirtySignal:F,uid:w,nodeBucket:{},validators:new z(S),theme:"secondary",dependOn:async b=>await I(b,{...V,path:S})};return d.type==="group"&&(delete P.nodeBucket,delete P.validators,P.children=d.children.map(b=>D(b,S)),l.set(P.path,P)),p.set(P.path,P.uid),u.set(P.uid,P),P};return {schema:D(s),GetFormData:()=>O(),GetRenderSchemaByPath:y,GetGroupByPath:m,notifyAll:L,convertToRenderSchema:D}}function me(s,e={}){let r=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((c,o)=>[...c,r(o)],[])};if(n.type=="input"||n.type=="number"||n.type=="select"||n.type=="checkbox")return {key:n.name,isGroup:false,val:n.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${n.type}`)},t=(n,c)=>{if(c.isGroup){let o={};c.key===""?o=n:n[c.key]=o,c.val.forEach(p=>{t(o,p);});}else n[c.key]=c.val;},i=r(s);return t(e,i),e}var ee=(s,e,r)=>{let i=n=>{let c=r.triggerPaths.map(u=>n.GetValueByPath(u)),o=Object.create(null);return Object.defineProperty(o,"triggerTargets",{get:()=>c}),Object.defineProperty(o,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(s)[e]}),r.logic({slot:o})};return {value:r.value,targetPath:s,triggerPaths:r.triggerPaths,priority:r.priority??10,logic:i}},te=(s,e,r)=>{if(!s)throw Error("");let t=s,i=(o,p)=>{e.has(o)||e.set(o,new Set),e.get(o).add(p),r.has(p)||r.set(p,new Set),r.get(p).add(o);};return {SetRule:(o,p,u,l={logic:a=>{}})=>{let a=t(p),h=ee(p,u,{...l,triggerPaths:[o]}),y=[o].map(m=>[m,t(m).defaultValue]);if(i(o,p),a.nodeBucket[u])a.nodeBucket[u].setRule(h,y);else {let m=new $(a[u],u,p);m.setRule(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();},SetRules:(o,p,u,l={logic:a=>{}})=>{let a=t(p);for(let m of o)i(m,p);let h=ee(p,u,{...l,triggerPaths:o}),y=o.map(m=>[m,t(m).defaultValue]);if(a.nodeBucket[u])a.nodeBucket[u].setRules(h,y);else {let m=new $(a[u],u,p);m.setRules(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();}}},ne=s=>{let e=s||void 0;if(!e)throw Error("");return {SetStrategy:(t,i,n)=>{e(t).nodeBucket[i].setStrategy(n);}}};var re=s=>{let e=s||void 0;return {SetValidators:(t,i)=>{let n=e(t),c=(p,u,l)=>p(u,l),o=(p,u,l)=>p(u,l);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:p=>c(i.logic,p,e),condition:typeof i.condition=="function"?p=>o(i.condition,p,e):()=>true});}}};function ae(s){let e=new Map,r=new Map,t=new Set,i=(u,l)=>{if(e.get(u)===l)return;e.set(u,l);let a=r.get(u);a&&a(l);};return {pushExecution:(u,l)=>{l&&(t.forEach(a=>i(a,"idle")),t.clear(),e.clear()),u.length!==0&&u.forEach(a=>{t.has(a)||t.add(a),i(a,"calculating"),s(a).forEach(y=>{t.has(y)||(t.add(y),e.has(y)||i(y,"pending"));});});},popExecution:u=>{u.forEach(l=>{i(l,"calculated");});},markError:u=>{i(u,"error"),t.forEach(l=>{let a=e.get(l);l!==u&&(a==="pending"||a==="calculating")&&i(l,"canceled");});},SetTrace:(u,l,a)=>{r.set(u,l);let h=e.get(u)||"idle";return l(h),()=>{r.delete(u);}}}}function oe(s,e,r,t){let i=l=>{let a=s(),h=e(),y=new Set;return a.get(l)?.forEach(m=>y.add(m)),y.size===0?[]:Array.from(y).filter(m=>{let x=h.get(m)||new Set;return !Array.from(x).some(A=>y.has(A))})};return {GetNextDependency:l=>{let a=t();return Array.from(a.get(l)||[])},GetPrevDependency:l=>{let a=r();return Array.from(a.get(l)||[])},GetAllPrevDependency:l=>{let a=e();return Array.from(a.get(l)||[])},GetAllNextDependency:l=>{let a=s();return Array.from(a.get(l)||[])},rebuildDirectDependencyMaps:l=>{let a=new Map,h=new Map;for(let y of l){let m=i(y);a.set(y,new Set(m));for(let x of m)h.has(x)||h.set(x,new Set),h.get(x).add(y);}return {directNextMap:a,directPrevMap:h}}}}function se(s){let e=t=>{let i=[],n=[],c=new Map,o=t.size,p=0,u=0;for(let[l,a]of t)a===0&&n.push(l);if(n.length===0&&o>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;n.length>0;){i.push([...n]);let l=[];for(let a of n){p++,c.set(a,u);let h=s.get(a);if(h)for(let y of h){let m=t.get(y)-1;t.set(y,m),m===0&&l.push(y);}}n=l,u++;}if(p<o)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:i,levelMap:c}};return ()=>{let t=new Map;for(let i of s.keys()){let n=Array.from(s.get(i)||[]);t.has(i)||t.set(i,0);for(let c of n){let o=t.get(c)||0;t.set(c,++o);}}return e(t)}}function ie(){let s=[],e=[],t={canRedo:()=>{},canUndo:()=>{}},i=()=>{if(!s.length)return;let a=s.pop();a?.undoAction(),p(a);},n=()=>{if(!e.length)return;let a=e.pop();a?.redoAction(),u(a,false);},c=a=>{t.canUndo=()=>a(s.length);},o=a=>{t.canRedo=()=>a(e.length);},p=a=>{e.push(a),e.length>100&&e.shift(),t.canRedo(),t.canUndo();},u=(a,h=true)=>{h&&(e.length=0),s.push(a),s.length>100&&s.shift(),t.canUndo(),t.canRedo();};return {Undo:i,Redo:n,PushIntoHistory:u,CreateHistoryAction:(a,h)=>{let[y,m]=a;return {undoAction:()=>h(y),redoAction:()=>h(m)}},initCanUndo:c,initCanRedo:o}}var _=()=>{let s=[];return {on:e=>(s.push(e),()=>{let r=s.indexOf(e);r>-1&&s.splice(r,1);}),call:e=>s.forEach(r=>r(e))}};function le(){let{on:s,call:e}=_();return {onError:s,callOnError:e}}function ce(){let{on:s,call:e}=_();return {onSuccess:s,callOnSuccess:e}}var ue=()=>{let s=new Set,e=new Map,r=(n,c)=>{e.get(n)?.forEach(o=>o(c));},t=(n,c)=>(e.has(n)||e.set(n,new Set),e.get(n).add(c),()=>e.get(n).delete(c));return {usePlugin:n=>(n.apply({on:t}),()=>{s.delete(n);}),emit:r}};function de(){let{on:s,call:e}=_();return {onStart:s,callOnStart:e}}function pe(s,e){let r=false,t=false,i=new Map,n=new Map,c=new Map,o=new Map,p=[],u=new Map,{GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetAllNextDependency:y,rebuildDirectDependencyMaps:m}=oe(()=>i,()=>n,()=>o,()=>c),{SetTrace:x,pushExecution:R,popExecution:O,markError:A}=ae(l),{Undo:L,Redo:E,PushIntoHistory:G,CreateHistoryAction:B,initCanUndo:D,initCanRedo:v}=ie(),{onError:g,callOnError:d}=le(),{onSuccess:f,callOnSuccess:T}=ce(),{onStart:S,callOnStart:F}=de(),{emit:w,usePlugin:V}=ue(),{schema:I,GetFormData:P,GetRenderSchemaByPath:b,GetGroupByPath:C,notifyAll:H,convertToRenderSchema:U}=Z(s,{GetDependencyOrder:()=>p,GetAllNextDependency:y,GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetPathToLevelMap:()=>u},{pushExecution:R,popExecution:O,markError:A},{pushIntoHistory:G,createHistoryAction:B},{callOnError:d,callOnSuccess:T,callOnStart:F,emit:w},e),W=(M,k)=>{let N=C(M),X=U(k,M);return N.children.push(X),N.dirtySignal.value++,X},{SetRule:K,SetRules:j}=te(b,i,n),{SetStrategy:ye}=ne(b),{SetValidators:fe}=re(b),he=se(i),Y=()=>{let M=he();p=M.steps,u=M.levelMap;};return {schema:I,SetRule:(...M)=>{K.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetRules:(...M)=>{j.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetStrategy:ye,SetValidators:fe,SetTrace:x,usePlugin:V,SetValue:(M,k)=>{b(M).dependOn(()=>k);},GetFormData:P,notifyAll:()=>{Y(),H();},AddNewSchema:W,GetAllDependency:()=>i,GetDependencyOrder:()=>p,Undo:L,Redo:E,initCanUndo:D,initCanRedo:v,onError:g,onSuccess:f,onStart:S}}var q=new Map,ge=(s,e,r)=>{try{if(typeof r.signalCreateor!="function"||typeof r.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(q.has(s))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let t=pe(e,r),{schema:i,GetFormData:n,SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,SetValue:l,usePlugin:a,notifyAll:h,SetTrace:y,GetAllDependency:m,GetDependencyOrder:x,AddNewSchema:R,Undo:O,Redo:A,initCanUndo:L,initCanRedo:E,onError:G,onSuccess:B,onStart:D}=t,v={config:{SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,notifyAll:h,SetTrace:y,usePlugin:a},data:{schema:i,GetFormData:n,AddNewSchema:R,SetValue:l},history:{Undo:O,Redo:A,initCanUndo:L,initCanRedo:E},dependency:{GetAllDependency:m,GetDependencyOrder:x},hooks:{onError:G,onSuccess:B,onStart:D}};return q.set(s,v),v}catch(t){throw Error(t)}},st=s=>{if(q.has(s))return q.get(s);throw Error("\u4E0D\u5B58\u5728\u7684id")},it=s=>{q.delete(s);},lt=ge;exports.deleteEngine=it;exports.useEngine=st;exports.useEngineManager=ge;exports.useMeshFlow=lt;
|
package/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var j=class{computedRules=[];store={OR:async(e,o)=>{let t,s,n=this.computedRules;for(let u of n){let a=await u.logic(e);if(u.entityId==="__base__"){s=a;continue}if(a){t=u.value;break}}return typeof t>"u"&&(t=s),{res:t,version:o}},PRIORITY:async(e,o)=>{let t=null,s=this.computedRules;try{for(let n of s){let u=await n.logic(e);if(u!==void 0){t=u;break}}}catch(n){throw n}return {res:t,version:o}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(e.values()).map(o=>Array.from(o)).flat().sort((o,t)=>t.priority-o.priority):this.computedRules=Array.from(e.values()).map(o=>Array.from(o)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,o){return this.CurrentStrategy(e,o)}},K=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,o,t){let s=()=>this.rules;this.strategy=new j(s),this.path=t,this.isDefaultValue=o==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let o=new Set;o.add(e),this.rules.set(e.id,o);}setRules(e,o){o&&this.updateDeps(o);let t=++this.id,s={...e,entityId:t};for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(s);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let u=this.rules.get(n);u&&(u.delete(s),u.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[o,t]of e)this.deps.set(o,t);}setRule(e,o){if(o&&this.updateDeps(o),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,s={...e,entityId:t};if(e)for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(s);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let u=this.rules.get(n);u&&(u.delete(s),u.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}async evaluate(e){let o=null;if(e.GetToken&&(o=e.GetToken()),this.pendingPromise&&this.promiseToken!==o&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=o;let t=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let s=!1;if(typeof e.triggerPath=="string"){s=!0;let a=this.deps.get(e.triggerPath),p=e.GetValueByPath(e.triggerPath);if(`${e.triggerPath}`,typeof a=="object"||typeof p=="object")s=!1;else {let c=Array.from(this.deps.keys());for(let i of c){let r=this.deps.get(i),h=e.GetValueByPath(i);if(r!==h){`${i}${r}${h}`,s=!1;break}}}}if(s)return `${this.path}`,this.cache,this.cache;let{res:n,version:u}=await this.strategy.evaluate(e,t);if(o!==this.promiseToken)return `${this.version}${u}`,this.cache,this.cache;if(u<this.version)return this.cache;if(this.inferType(n)!==this.contract&&`${this.contract}`,this.cache=n,o===this.promiseToken){`${this.path}`;let a=Array.from(this.deps.keys());for(let p of a){let c=e.GetValueByPath(p);this.deps.set(p,c);}}return n}catch(s){throw {path:this.path,info:s}}finally{this.promiseToken===o&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},z=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:t=>t||typeof t=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:t=>!!t.required},o={logic:function(t){return t.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(o.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(o);}evaluate(e,o){let t=true,s=[...this.defaultValidators,...this.validators];for(let n of s){if(!n.condition(o))continue;let a=n.logic(e);if(typeof a!="boolean"){t=a;break}}return t}};function Q(l,e,o,t,s){let n=new Map;return (a,p)=>{let i=Symbol("token");n.set(a,i);let r=false,h=new Set,y=new Set,m=new Set(l.GetAllNextDependency(a));m.add(a);let x=new Map,R=new Map,M=performance.now(),w=l.GetPathToLevelMap(),A=w.get(a)??0;m.forEach(v=>{if(v===a||p.includes(v))return;let d=l.GetPrevDependency(v).filter(f=>m.has(f)).length;d>0&&R.set(v,d);}),h.add(a);let E=Array.from(p).map(v=>(x.set(v,(x.get(v)||0)+1),{target:v,trigger:a,isReleased:false}));e.pushExecution([...Array.from(p),a],true),`${a}${i.description}`;let $=async v=>{let{target:S,trigger:d}=v;try{if(n.get(a)!==i)return;let f=!1,T=!1,g=o.GetRenderSchemaByPath(S);`${S}`,g.defaultValue;for(let F in g.nodeBucket){let b=g.nodeBucket[F],V=await b.evaluate({affectKey:F,triggerPath:d,GetRenderSchemaByPath:o.GetRenderSchemaByPath,GetValueByPath:P=>o.GetRenderSchemaByPath(P).defaultValue,GetToken:()=>i});if(n.get(a)!==i){`${S}`;return}F==="options"&&(V.some(G=>G.value==g.defaultValue)||(g.defaultValue=void 0,f=!0)),V!==g[F]&&(g[F]=V,f=!0),b.isForceNotify()&&(T=!0),f&&s.flushPathSet.add(S),h.add(S);let B=l.GetNextDependency(S);(f||T)&&l.GetAllNextDependency(S).forEach(G=>m.add(G));for(let P of B){if(h.has(P)){`${P}`;continue}if(f||T){if(!R.has(P)&&!h.has(P)&&!x.has(P)){let L=l.GetPrevDependency(P).filter(U=>m.has(U)).length;R.set(P,L);}let G=R.get(P)??0,C=Math.max(0,G-1);C<=0?(R.delete(P),E.push({target:P,trigger:S,isReleased:!0}),x.set(P,1),e.pushExecution([P]),`${S}${P}`):R.set(P,C);}else `${S}${P}`;}}if(performance.now()-M>16&&(await new Promise(F=>requestAnimationFrame(F)),M=performance.now(),n.get(a)!==i))return;n.get(a)===i&&s.requestUpdate();}catch(f){let T=Symbol("abort");n.set(a,T),E.length=0,R.clear(),y.clear(),e.markError(S),t.callOnError(f);}finally{n.get(a)===i&&(y.size-1,y.delete(S),e.popExecution([S]),r||O());}},O=async()=>{if(n.get(a)!==i){r=false;return}r=true;try{for(;(E.length>0||R.size>0)&&n.get(a)===i;){if(E.length>0){if(y.size>=20){r=!1;return}let v=E.shift(),{target:S}=v;if(h.has(S)){`${S}`;continue}`${S}`,v.isReleased,`${E.length}`;let d=x.get(S)||0;d<=1?x.delete(S):x.set(S,d-1);let f=w.get(S)??0;if(f>A+1&&!v.isReleased){`${S}${f}${A}`,R.set(S,1);continue}y.add(S),`${S}${y.size}${Array.from(y).join(",")}`,e.pushExecution([S]),$(v);continue}if(y.size>0){`${Array.from(y).join(",")}`,r=!1;return}if(R.size>0){`${A}`;let v=!1,S=[];for(let[d]of R)l.GetPrevDependency(d).some(g=>h.has(g)?!1:y.has(g)||x.has(g)||m.has(g)?!0:(w.get(g)??0)>A)||S.push(d);if(S.length>0&&(S.forEach(d=>{R.delete(d),E.push({target:d,trigger:a,isReleased:!0}),x.set(d,1),e.pushExecution([d]);}),v=!0,`${S.join(",")}`),v)continue;if(Array.from(R.keys()).some(f=>l.GetPrevDependency(f).some(g=>m.has(g)&&!h.has(g)))){`${A}`,r=!1;return}if(A++,`${A}`,A>2e3)break;continue}}}finally{r=false;}};O();}}function X(l,e,o,t,s,n){let u=le(l),a=0,p=new Map,c=new Map,i=new Map,r=false,h=new Set,y=d=>{let f=p.get(d);return c.get(f)},m=d=>i.get(d),x=async()=>{let d=Array.from(h);h.clear();for(let f of d){let T=y(f);n.signalTrigger(T.dirtySignal);}},R=()=>{r||(r=true,Promise.resolve().then(()=>{try{for(;h.size>0;)x();}finally{r=false;}}));},M=()=>{let d=(f,T,g)=>{if(typeof f!="object"||f===null||Array.isArray(f)){if(g.length>0){let b=g[g.length-1];T[b]=y(g.join(".")).defaultValue;}return}let F=Object.getOwnPropertyNames(f);for(let b of F)g.push(b),d(f[b],f,g),g.pop();};return d(u,null,[]),u},w=Q(e,o,{GetRenderSchemaByPath:y},s,{requestUpdate:R,flushPathSet:h}),I=async()=>{let d=e.GetDependencyOrder().flat();try{for(let f of d){let T=y(f);for(let g in T.nodeBucket){let F=await T.nodeBucket[g].evaluate({affectKey:g,triggerPath:void 0,GetRenderSchemaByPath:y,GetValueByPath:b=>y(b).defaultValue,isSameToken:()=>!1});if(g==="options"){let b=!1,V=T.defaultValue;for(let B of F)B.value==V&&(b=!0);b||(T.defaultValue=void 0,R());}F!==T[g]&&(T[g]=F,h.add(f),R());}}}catch(f){s.callOnError(f);}},A=async d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!y(d))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");h.add(d),R();let T=e.GetNextDependency(d);E(T,d),o.popExecution([d],true);};async function E(d,f){w(f,d);}let $=d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");let f=y(d);f.nodeBucket.defaultValue&&f.nodeBucket.defaultValue.updateInputValueRule(f.defaultValue);},O=(d,f="")=>{let T="name"in d?d.name:void 0,g=T?f===""?T:`${f}.${T}`:f,F=n.signalCreateor(),b=a++,V={getRenderSchema:G=>y(G)},B=async(G,C)=>{let L=G(C),U=y(C.path),H=t.createHistoryAction([{path:C.path,value:U.defaultValue},{path:C.path,value:L}],async _=>{let W=y(_.path);W.defaultValue=_.value,$(_.path),await A(_.path);});U.defaultValue=L,t.pushIntoHistory(H),$(C.path),await A(C.path);},P={...d,disabled:!!d.disabled,hidden:"hidden"in d?d.hidden:false,readonly:"readonly"in d?d.readonly:false,required:"required"in d?d.required:false,path:g,dirtySignal:F,uid:b,nodeBucket:{},validators:new z(g),theme:"secondary",dependOn:async G=>await B(G,{...V,path:g})};return d.type==="group"&&(delete P.nodeBucket,delete P.validators,P.children=d.children.map(G=>O(G,g)),i.set(P.path,P)),p.set(P.path,P.uid),c.set(P.uid,P),P};return {schema:O(l),GetFormData:()=>M(),GetRenderSchemaByPath:y,GetGroupByPath:m,notifyAll:I,convertToRenderSchema:O}}function le(l,e={}){let o=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((u,a)=>[...u,o(a)],[])};if(n.type=="input"||n.type=="number"||n.type=="select"||n.type=="checkbox")return {key:n.name,isGroup:false,val:n.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${n.type}`)},t=(n,u)=>{if(u.isGroup){let a={};u.key===""?a=n:n[u.key]=a,u.val.forEach(p=>{t(a,p);});}else n[u.key]=u.val;},s=o(l);return t(e,s),e}var J=(l,e,o)=>{let s=n=>{let u=o.triggerPaths.map(c=>n.GetValueByPath(c)),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>u}),Object.defineProperty(a,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(l)[e]}),o.logic({slot:a})};return {value:o.value,targetPath:l,triggerPaths:o.triggerPaths,priority:o.priority??10,logic:s}},Z=(l,e,o)=>{if(!l)throw Error("");let t=l,s=(a,p)=>{e.has(a)||e.set(a,new Set),e.get(a).add(p),o.has(p)||o.set(p,new Set),o.get(p).add(a);};return {SetRule:(a,p,c,i={logic:r=>{}})=>{let r=t(p),h=J(p,c,{...i,triggerPaths:[a]}),y=[a].map(m=>[m,t(m).defaultValue]);if(s(a,p),r.nodeBucket[c])r.nodeBucket[c].setRule(h,y);else {let m=new K(r[c],c,p);m.setRule(h,y),r.nodeBucket[c]=m;}i.forceNotify&&r.nodeBucket[c].forceNotify();},SetRules:(a,p,c,i={logic:r=>{}})=>{let r=t(p);for(let m of a)s(m,p);let h=J(p,c,{...i,triggerPaths:a}),y=a.map(m=>[m,t(m).defaultValue]);if(r.nodeBucket[c])r.nodeBucket[c].setRules(h,y);else {let m=new K(r[c],c,p);m.setRules(h,y),r.nodeBucket[c]=m;}i.forceNotify&&r.nodeBucket[c].forceNotify();}}},ee=l=>{let e=l||void 0;if(!e)throw Error("");return {SetStrategy:(t,s,n)=>{e(t).nodeBucket[s].setStrategy(n);}}};var te=l=>{let e=l||void 0;return {SetValidators:(t,s)=>{let n=e(t),u=(p,c,i)=>p(c,i),a=(p,c,i)=>p(c,i);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:p=>u(s.logic,p,e),condition:typeof s.condition=="function"?p=>a(s.condition,p,e):()=>true});}}};function ne(l){let e=new Map,o=new Map,t=new Set,s=(c,i)=>{if(e.get(c)===i)return;e.set(c,i);let r=o.get(c);r&&r(i);};return {pushExecution:(c,i)=>{i&&(t.forEach(r=>s(r,"idle")),t.clear(),e.clear()),c.length!==0&&c.forEach(r=>{t.has(r)||t.add(r),s(r,"calculating"),l(r).forEach(y=>{t.has(y)||(t.add(y),e.has(y)||s(y,"pending"));});});},popExecution:c=>{c.forEach(i=>{s(i,"calculated");});},markError:c=>{s(c,"error"),t.forEach(i=>{let r=e.get(i);i!==c&&(r==="pending"||r==="calculating")&&s(i,"canceled");});},SetTrace:(c,i,r)=>{o.set(c,i);let h=e.get(c)||"idle";return i(h),()=>{o.delete(c);}}}}function re(l,e,o,t){let s=i=>{let r=l(),h=e(),y=new Set;return r.get(i)?.forEach(m=>y.add(m)),y.size===0?[]:Array.from(y).filter(m=>{let x=h.get(m)||new Set;return !Array.from(x).some(w=>y.has(w))})};return {GetNextDependency:i=>{let r=t();return Array.from(r.get(i)||[])},GetPrevDependency:i=>{let r=o();return Array.from(r.get(i)||[])},GetAllPrevDependency:i=>{let r=e();return Array.from(r.get(i)||[])},GetAllNextDependency:i=>{let r=l();return Array.from(r.get(i)||[])},rebuildDirectDependencyMaps:i=>{let r=new Map,h=new Map;for(let y of i){let m=s(y);r.set(y,new Set(m));for(let x of m)h.has(x)||h.set(x,new Set),h.get(x).add(y);}return {directNextMap:r,directPrevMap:h}}}}function oe(l){let e=t=>{let s=[],n=[],u=new Map,a=t.size,p=0,c=0;for(let[i,r]of t)r===0&&n.push(i);if(n.length===0&&a>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;n.length>0;){s.push([...n]);let i=[];for(let r of n){p++,u.set(r,c);let h=l.get(r);if(h)for(let y of h){let m=t.get(y)-1;t.set(y,m),m===0&&i.push(y);}}n=i,c++;}if(p<a)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:s,levelMap:u}};return ()=>{let t=new Map;for(let s of l.keys()){let n=Array.from(l.get(s)||[]);t.has(s)||t.set(s,0);for(let u of n){let a=t.get(u)||0;t.set(u,++a);}}return e(t)}}function ae(){let l=[],e=[],t={canRedo:()=>{},canUndo:()=>{}},s=()=>{if(!l.length)return;let r=l.pop();r?.undoAction(),p(r);},n=()=>{if(!e.length)return;let r=e.pop();r?.redoAction(),c(r,false);},u=r=>{t.canUndo=()=>r(l.length);},a=r=>{t.canRedo=()=>r(e.length);},p=r=>{e.push(r),e.length>100&&e.shift(),t.canRedo(),t.canUndo();},c=(r,h=true)=>{h&&(e.length=0),l.push(r),l.length>100&&l.shift(),t.canUndo(),t.canRedo();};return {Undo:s,Redo:n,PushIntoHistory:c,CreateHistoryAction:(r,h)=>{let[y,m]=r;return {undoAction:()=>h(y),redoAction:()=>h(m)}},initCanUndo:u,initCanRedo:a}}function se(){let l=[];return {onError:t=>{let s=n=>t(n);return l.push(s),()=>{let n=l.findIndex(u=>u===s);l.splice(n,1);}},callOnError:t=>{for(let s of l)s(t);}}}function ie(l,e){let o=false,t=false,s=new Map,n=new Map,u=new Map,a=new Map,p=[],c=new Map,{GetNextDependency:i,GetPrevDependency:r,GetAllPrevDependency:h,GetAllNextDependency:y,rebuildDirectDependencyMaps:m}=re(()=>s,()=>n,()=>a,()=>u),{SetTrace:x,pushExecution:R,popExecution:M,markError:w}=ne(i),{Undo:I,Redo:A,PushIntoHistory:E,CreateHistoryAction:$,initCanUndo:O,initCanRedo:v}=ae(),{onError:S,callOnError:d}=se(),{schema:f,GetFormData:T,GetRenderSchemaByPath:g,GetGroupByPath:F,notifyAll:b,convertToRenderSchema:V}=X(l,{GetDependencyOrder:()=>p,GetAllNextDependency:y,GetNextDependency:i,GetPrevDependency:r,GetAllPrevDependency:h,GetPathToLevelMap:()=>c},{pushExecution:R,popExecution:M,markError:w},{pushIntoHistory:E,createHistoryAction:$},{callOnError:d},e),B=(k,D)=>{let N=F(k),Y=V(D,k);return N.children.push(Y),N.dirtySignal.value++,Y},{SetRule:P,SetRules:G}=Z(g,s,n),{SetStrategy:C}=ee(g),{SetValidators:L}=te(g),U=oe(s),H=()=>{let k=U();p=k.steps,c=k.levelMap;};return {schema:f,SetRule:(...k)=>{P.apply(null,k),o=true,!t&&new Promise((D,N)=>{t=true,D();}).then(()=>{if(H(),o){let{directNextMap:D,directPrevMap:N}=m(p.flat());u=D,a=N;}}).finally(()=>{t=false,o=false;});},SetRules:(...k)=>{G.apply(null,k),o=true,!t&&new Promise((D,N)=>{t=true,D();}).then(()=>{if(H(),o){let{directNextMap:D,directPrevMap:N}=m(p.flat());u=D,a=N;}}).finally(()=>{t=false,o=false;});},SetStrategy:C,SetValidators:L,SetTrace:x,SetValue:(k,D)=>{g(k).dependOn(()=>D);},GetFormData:T,notifyAll:()=>{H(),b();},AddNewSchema:B,GetAllDependency:()=>s,GetDependencyOrder:()=>p,Undo:I,Redo:A,initCanUndo:O,initCanRedo:v,onError:S}}var q=new Map,$e=(l,e,o)=>{try{if(typeof o.signalCreateor!="function"||typeof o.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(q.has(l))throw Error("engineID\u91CD\u590D\uFF0C\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let t=ie(e,o),{schema:s,GetFormData:n,SetRule:u,SetRules:a,SetStrategy:p,SetValidators:c,SetValue:i,notifyAll:r,SetTrace:h,GetAllDependency:y,GetDependencyOrder:m,AddNewSchema:x,Undo:R,Redo:M,initCanUndo:w,initCanRedo:I,onError:A}=t,E={config:{SetRule:u,SetRules:a,SetStrategy:p,SetValidators:c,notifyAll:r,SetTrace:h},data:{schema:s,GetFormData:n,AddNewSchema:x,SetValue:i},history:{Undo:R,Redo:M,initCanUndo:w,initCanRedo:I},dependency:{GetAllDependency:y,GetDependencyOrder:m},hooks:{onError:A}};return q.set(l,E),E}catch(t){throw Error(t)}},Le=l=>{if(q.has(l))return q.get(l);throw Error("\u4E0D\u5B58\u5728\u7684id")},Ue=l=>{q.delete(l);};export{Ue as deleteEngine,Le as useEngine,$e as useEngineManager};
|
|
1
|
+
var Q=class{computedRules=[];store={OR:async(e,r)=>{let t,i,n=this.computedRules;for(let c of n){let o=await c.logic(e);if(c.entityId==="__base__"){i=o;continue}if(o){t=c.value;break}}return typeof t>"u"&&(t=i),{res:t,version:r}},PRIORITY:async(e,r)=>{let t=null,i=this.computedRules;try{for(let n of i){let c=await n.logic(e);if(c!==void 0){t=c;break}}}catch(n){throw n}return {res:t,version:r}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat().sort((r,t)=>t.priority-r.priority):this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,r){return this.CurrentStrategy(e,r)}},$=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,r,t){let i=()=>this.rules;this.strategy=new Q(i),this.path=t,this.isDefaultValue=r==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let r=new Set;r.add(e),this.rules.set(e.id,r);}setRules(e,r){r&&this.updateDeps(r);let t=++this.id,i={...e,entityId:t};for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[r,t]of e)this.deps.set(r,t);}setRule(e,r){if(r&&this.updateDeps(r),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,i={...e,entityId:t};if(e)for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}async evaluate(e){let r=null;if(e.GetToken&&(r=e.GetToken()),this.pendingPromise&&this.promiseToken!==r&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=r;let t=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let i=!1;if(typeof e.triggerPath=="string"){i=!0;let o=this.deps.get(e.triggerPath),p=e.GetValueByPath(e.triggerPath);if(typeof o=="object"||typeof p=="object")i=!1;else {let u=Array.from(this.deps.keys());for(let l of u){let a=this.deps.get(l),h=e.GetValueByPath(l);if(a!==h){i=!1;break}}}}if(i)return this.cache;let{res:n,version:c}=await this.strategy.evaluate(e,t);if(r!==this.promiseToken)return this.cache;if(c<this.version)return this.cache;if(this.inferType(n)!==this.contract&&`${this.contract}`,this.cache=n,r===this.promiseToken){let o=Array.from(this.deps.keys());for(let p of o){let u=e.GetValueByPath(p);this.deps.set(p,u);}}return n}catch(i){throw {path:this.path,info:i}}finally{this.promiseToken===r&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},z=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:t=>t||typeof t=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:t=>!!t.required},r={logic:function(t){return t.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(r.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(r);}evaluate(e,r){let t=true,i=[...this.defaultValidators,...this.validators];for(let n of i){if(!n.condition(r))continue;let o=n.logic(e);if(typeof o!="boolean"){t=o;break}}return t}};function J(s,e,r,t,i){let n=new Map;return (o,p)=>{let l=Symbol("token");n.set(o,l);let a=false,h=new Set,y=new Set,m=new Set(s.GetAllNextDependency(o));m.add(o);let x=new Map,R=new Map,O=performance.now(),A=s.GetPathToLevelMap(),E=A.get(o)??0;m.forEach(v=>{if(v===o||p.includes(v))return;let d=s.GetPrevDependency(v).filter(f=>m.has(f)).length;d>0&&R.set(v,d);}),h.add(o);let G=Array.from(p).map(v=>(x.set(v,(x.get(v)||0)+1),{target:v,trigger:o,isReleased:false}));e.pushExecution([...Array.from(p),o],true),`${o}${l.description}`,t.callOnStart({path:o});let B=async v=>{let{target:g,trigger:d}=v;try{if(n.get(o)!==l)return;let f=!1,T=!1,S=r.GetRenderSchemaByPath(g);t.emit("node:start",{path:g});for(let F in S.nodeBucket){let w=S.nodeBucket[F],V=await w.evaluate({affectKey:F,triggerPath:d,GetRenderSchemaByPath:r.GetRenderSchemaByPath,GetValueByPath:P=>r.GetRenderSchemaByPath(P).defaultValue,GetToken:()=>l});if(n.get(o)!==l){t.emit("node:intercept",{path:g,reason:`\u4EE4\u724C\u8FC7\u671F\uFF0C\u4E22\u5F03${g}\u65E7\u4EFB\u52A1\u8BA1\u7B97\u7ED3\u679C`});return}F==="options"&&(V.some(b=>b.value==S.defaultValue)||(S.defaultValue=void 0,f=!0)),V!==S[F]&&(S[F]=V,f=!0,t.emit("node:bucket:success",{path:g,key:F,value:V})),w.isForceNotify()&&(T=!0),f&&i.flushPathSet.add(g);let I=s.GetNextDependency(g);(f||T)&&s.GetAllNextDependency(g).forEach(b=>m.add(b));for(let P of I){if(h.has(P)){t.emit("node:intercept",{path:P,reason:` \u4E0B\u6E38 ${P} \u5DF2\u7531\u5176\u4ED6\u8DEF\u5F84\u5904\u7406`});continue}if(f||T){if(!R.has(P)&&!h.has(P)&&!x.has(P)){let H=s.GetPrevDependency(P).filter(U=>m.has(U)).length;R.set(P,H);}let b=R.get(P)??0,C=Math.max(0,b-1);C<=0?(R.delete(P),G.push({target:P,trigger:g,isReleased:!0}),x.set(P,1),e.pushExecution([P]),t.emit("node:release",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u53D8\u4E86`})):R.set(P,C);}else t.emit("node:stagnate",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u672A\u53D8`});}}if(t.emit("node:success",{path:g}),h.add(g),performance.now()-O>16&&(await new Promise(F=>requestAnimationFrame(F)),O=performance.now(),n.get(o)!==l))return;n.get(o)===l&&i.requestUpdate();}catch(f){t.emit("node:error",{path:g,error:f});let T=Symbol("abort");n.set(o,T),G.length=0,R.clear(),y.clear(),e.markError(g),t.callOnError(f);}finally{n.get(o)===l&&(y.delete(g),e.popExecution([g]),a||(t.emit("flow:fire",{path:g,reason:"\u4EFB\u52A1\u5F52\u822A"}),D()));}},D=async()=>{if(n.get(o)!==l){a=false;return}a=true;try{for(;(G.length>0||R.size>0)&&n.get(o)===l;){if(G.length>0){if(y.size>=20){a=!1;return}let v=G.shift(),{target:g}=v;if(h.has(g)){t.emit("node:intercept",{path:g,reason:` \u62D2\u7EDD\u91CD\u5165${g},\u5DF2\u8BA1\u7B97\u5B8C\u6210`});continue}let d=x.get(g)||0;d<=1?x.delete(g):x.set(g,d-1);let f=A.get(g)??0;if(f>E+1&&!v.isReleased){t.emit("node:intercept",{path:g,reason:` ${g} \u5C42\u7EA7\u592A\u6DF1(${f})\uFF0C\u5F53\u524D\u6C34\u4F4D(${E})`}),R.set(g,1);continue}y.add(g),t.emit("node:processing",{path:g}),e.pushExecution([g]),B(v);continue}if(y.size>0){t.emit("flow:wait",{reason:`\u961F\u5217\u5DF2\u7A7A,\u7184\u706B\u7B49\u5F85\uFF0C\u7B49\u5F85\u5F02\u6B65\u4EFB\u52A1\u5F52\u822A | \u98DE\u884C\u4E2D: ${Array.from(y).join(",")} | `}),a=!1;return}if(R.size>0){let v=!1,g=[];for(let[d]of R)s.GetPrevDependency(d).some(S=>h.has(S)?!1:y.has(S)||x.has(S)||m.has(S)?!0:(A.get(S)??0)>E)||g.push(d);if(g.length>0&&(g.forEach(d=>{R.delete(d),G.push({target:d,trigger:o,isReleased:!0}),x.set(d,1),e.pushExecution([d]);}),v=!0),v)continue;if(Array.from(R.keys()).some(f=>s.GetPrevDependency(f).some(S=>m.has(S)&&!h.has(S)))){t.emit("flow:wait",{reason:"\u5C1A\u6709\u6D3B\u8DC3\u4F9D\u8D56 \u672A\u5B8C\u6210,\u7184\u706B\u7B49\u5F85"}),a=!1;return}if(E++,E>2e3)break;continue}}}finally{R.size,y.size,G.length,a=false,t.emit("flow:wait",{reason:"\u7184\u706B\u9759\u9ED8"}),Promise.resolve().then(()=>{R.size===0&&y.size===0&&G.length===0&&t.callOnSuccess();});}};D();}}function Z(s,e,r,t,i,n){let c=me(s),o=0,p=new Map,u=new Map,l=new Map,a=false,h=new Set,y=d=>{let f=p.get(d);return u.get(f)},m=d=>l.get(d),x=async()=>{let d=Array.from(h);h.clear();for(let f of d){let T=y(f);n.signalTrigger(T.dirtySignal);}},R=()=>{a||(a=true,Promise.resolve().then(()=>{try{for(;h.size>0;)x();}finally{a=false;}}));},O=()=>{let d=(f,T,S)=>{if(typeof f!="object"||f===null||Array.isArray(f)){if(S.length>0){let w=S[S.length-1];T[w]=y(S.join(".")).defaultValue;}return}let F=Object.getOwnPropertyNames(f);for(let w of F)S.push(w),d(f[w],f,S),S.pop();};return d(c,null,[]),c},A=J(e,r,{GetRenderSchemaByPath:y},i,{requestUpdate:R,flushPathSet:h}),L=async()=>{let d=e.GetDependencyOrder().flat();try{for(let f of d){let T=y(f);for(let S in T.nodeBucket){let F=await T.nodeBucket[S].evaluate({affectKey:S,triggerPath:void 0,GetRenderSchemaByPath:y,GetValueByPath:w=>y(w).defaultValue,isSameToken:()=>!1});if(S==="options"){let w=!1,V=T.defaultValue;for(let I of F)I.value==V&&(w=!0);w||(T.defaultValue=void 0,R());}F!==T[S]&&(T[S]=F,h.add(f),R());}}}catch(f){i.callOnError(f);}},E=async d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!y(d))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");h.add(d),R();let T=e.GetNextDependency(d);G(T,d),r.popExecution([d],true);};async function G(d,f){A(f,d);}let B=d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");let f=y(d);f.nodeBucket.defaultValue&&f.nodeBucket.defaultValue.updateInputValueRule(f.defaultValue);},D=(d,f="")=>{let T="name"in d?d.name:void 0,S=T?f===""?T:`${f}.${T}`:f,F=n.signalCreateor(),w=o++,V={getRenderSchema:b=>y(b)},I=async(b,C)=>{let H=b(C),U=y(C.path),W=t.createHistoryAction([{path:C.path,value:U.defaultValue},{path:C.path,value:H}],async K=>{let j=y(K.path);j.defaultValue=K.value,B(K.path),await E(K.path);});U.defaultValue=H,t.pushIntoHistory(W),B(C.path),await E(C.path);},P={...d,disabled:!!d.disabled,hidden:"hidden"in d?d.hidden:false,readonly:"readonly"in d?d.readonly:false,required:"required"in d?d.required:false,path:S,dirtySignal:F,uid:w,nodeBucket:{},validators:new z(S),theme:"secondary",dependOn:async b=>await I(b,{...V,path:S})};return d.type==="group"&&(delete P.nodeBucket,delete P.validators,P.children=d.children.map(b=>D(b,S)),l.set(P.path,P)),p.set(P.path,P.uid),u.set(P.uid,P),P};return {schema:D(s),GetFormData:()=>O(),GetRenderSchemaByPath:y,GetGroupByPath:m,notifyAll:L,convertToRenderSchema:D}}function me(s,e={}){let r=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((c,o)=>[...c,r(o)],[])};if(n.type=="input"||n.type=="number"||n.type=="select"||n.type=="checkbox")return {key:n.name,isGroup:false,val:n.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${n.type}`)},t=(n,c)=>{if(c.isGroup){let o={};c.key===""?o=n:n[c.key]=o,c.val.forEach(p=>{t(o,p);});}else n[c.key]=c.val;},i=r(s);return t(e,i),e}var ee=(s,e,r)=>{let i=n=>{let c=r.triggerPaths.map(u=>n.GetValueByPath(u)),o=Object.create(null);return Object.defineProperty(o,"triggerTargets",{get:()=>c}),Object.defineProperty(o,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(s)[e]}),r.logic({slot:o})};return {value:r.value,targetPath:s,triggerPaths:r.triggerPaths,priority:r.priority??10,logic:i}},te=(s,e,r)=>{if(!s)throw Error("");let t=s,i=(o,p)=>{e.has(o)||e.set(o,new Set),e.get(o).add(p),r.has(p)||r.set(p,new Set),r.get(p).add(o);};return {SetRule:(o,p,u,l={logic:a=>{}})=>{let a=t(p),h=ee(p,u,{...l,triggerPaths:[o]}),y=[o].map(m=>[m,t(m).defaultValue]);if(i(o,p),a.nodeBucket[u])a.nodeBucket[u].setRule(h,y);else {let m=new $(a[u],u,p);m.setRule(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();},SetRules:(o,p,u,l={logic:a=>{}})=>{let a=t(p);for(let m of o)i(m,p);let h=ee(p,u,{...l,triggerPaths:o}),y=o.map(m=>[m,t(m).defaultValue]);if(a.nodeBucket[u])a.nodeBucket[u].setRules(h,y);else {let m=new $(a[u],u,p);m.setRules(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();}}},ne=s=>{let e=s||void 0;if(!e)throw Error("");return {SetStrategy:(t,i,n)=>{e(t).nodeBucket[i].setStrategy(n);}}};var re=s=>{let e=s||void 0;return {SetValidators:(t,i)=>{let n=e(t),c=(p,u,l)=>p(u,l),o=(p,u,l)=>p(u,l);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:p=>c(i.logic,p,e),condition:typeof i.condition=="function"?p=>o(i.condition,p,e):()=>true});}}};function ae(s){let e=new Map,r=new Map,t=new Set,i=(u,l)=>{if(e.get(u)===l)return;e.set(u,l);let a=r.get(u);a&&a(l);};return {pushExecution:(u,l)=>{l&&(t.forEach(a=>i(a,"idle")),t.clear(),e.clear()),u.length!==0&&u.forEach(a=>{t.has(a)||t.add(a),i(a,"calculating"),s(a).forEach(y=>{t.has(y)||(t.add(y),e.has(y)||i(y,"pending"));});});},popExecution:u=>{u.forEach(l=>{i(l,"calculated");});},markError:u=>{i(u,"error"),t.forEach(l=>{let a=e.get(l);l!==u&&(a==="pending"||a==="calculating")&&i(l,"canceled");});},SetTrace:(u,l,a)=>{r.set(u,l);let h=e.get(u)||"idle";return l(h),()=>{r.delete(u);}}}}function oe(s,e,r,t){let i=l=>{let a=s(),h=e(),y=new Set;return a.get(l)?.forEach(m=>y.add(m)),y.size===0?[]:Array.from(y).filter(m=>{let x=h.get(m)||new Set;return !Array.from(x).some(A=>y.has(A))})};return {GetNextDependency:l=>{let a=t();return Array.from(a.get(l)||[])},GetPrevDependency:l=>{let a=r();return Array.from(a.get(l)||[])},GetAllPrevDependency:l=>{let a=e();return Array.from(a.get(l)||[])},GetAllNextDependency:l=>{let a=s();return Array.from(a.get(l)||[])},rebuildDirectDependencyMaps:l=>{let a=new Map,h=new Map;for(let y of l){let m=i(y);a.set(y,new Set(m));for(let x of m)h.has(x)||h.set(x,new Set),h.get(x).add(y);}return {directNextMap:a,directPrevMap:h}}}}function se(s){let e=t=>{let i=[],n=[],c=new Map,o=t.size,p=0,u=0;for(let[l,a]of t)a===0&&n.push(l);if(n.length===0&&o>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;n.length>0;){i.push([...n]);let l=[];for(let a of n){p++,c.set(a,u);let h=s.get(a);if(h)for(let y of h){let m=t.get(y)-1;t.set(y,m),m===0&&l.push(y);}}n=l,u++;}if(p<o)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:i,levelMap:c}};return ()=>{let t=new Map;for(let i of s.keys()){let n=Array.from(s.get(i)||[]);t.has(i)||t.set(i,0);for(let c of n){let o=t.get(c)||0;t.set(c,++o);}}return e(t)}}function ie(){let s=[],e=[],t={canRedo:()=>{},canUndo:()=>{}},i=()=>{if(!s.length)return;let a=s.pop();a?.undoAction(),p(a);},n=()=>{if(!e.length)return;let a=e.pop();a?.redoAction(),u(a,false);},c=a=>{t.canUndo=()=>a(s.length);},o=a=>{t.canRedo=()=>a(e.length);},p=a=>{e.push(a),e.length>100&&e.shift(),t.canRedo(),t.canUndo();},u=(a,h=true)=>{h&&(e.length=0),s.push(a),s.length>100&&s.shift(),t.canUndo(),t.canRedo();};return {Undo:i,Redo:n,PushIntoHistory:u,CreateHistoryAction:(a,h)=>{let[y,m]=a;return {undoAction:()=>h(y),redoAction:()=>h(m)}},initCanUndo:c,initCanRedo:o}}var _=()=>{let s=[];return {on:e=>(s.push(e),()=>{let r=s.indexOf(e);r>-1&&s.splice(r,1);}),call:e=>s.forEach(r=>r(e))}};function le(){let{on:s,call:e}=_();return {onError:s,callOnError:e}}function ce(){let{on:s,call:e}=_();return {onSuccess:s,callOnSuccess:e}}var ue=()=>{let s=new Set,e=new Map,r=(n,c)=>{e.get(n)?.forEach(o=>o(c));},t=(n,c)=>(e.has(n)||e.set(n,new Set),e.get(n).add(c),()=>e.get(n).delete(c));return {usePlugin:n=>(n.apply({on:t}),()=>{s.delete(n);}),emit:r}};function de(){let{on:s,call:e}=_();return {onStart:s,callOnStart:e}}function pe(s,e){let r=false,t=false,i=new Map,n=new Map,c=new Map,o=new Map,p=[],u=new Map,{GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetAllNextDependency:y,rebuildDirectDependencyMaps:m}=oe(()=>i,()=>n,()=>o,()=>c),{SetTrace:x,pushExecution:R,popExecution:O,markError:A}=ae(l),{Undo:L,Redo:E,PushIntoHistory:G,CreateHistoryAction:B,initCanUndo:D,initCanRedo:v}=ie(),{onError:g,callOnError:d}=le(),{onSuccess:f,callOnSuccess:T}=ce(),{onStart:S,callOnStart:F}=de(),{emit:w,usePlugin:V}=ue(),{schema:I,GetFormData:P,GetRenderSchemaByPath:b,GetGroupByPath:C,notifyAll:H,convertToRenderSchema:U}=Z(s,{GetDependencyOrder:()=>p,GetAllNextDependency:y,GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetPathToLevelMap:()=>u},{pushExecution:R,popExecution:O,markError:A},{pushIntoHistory:G,createHistoryAction:B},{callOnError:d,callOnSuccess:T,callOnStart:F,emit:w},e),W=(M,k)=>{let N=C(M),X=U(k,M);return N.children.push(X),N.dirtySignal.value++,X},{SetRule:K,SetRules:j}=te(b,i,n),{SetStrategy:ye}=ne(b),{SetValidators:fe}=re(b),he=se(i),Y=()=>{let M=he();p=M.steps,u=M.levelMap;};return {schema:I,SetRule:(...M)=>{K.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetRules:(...M)=>{j.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetStrategy:ye,SetValidators:fe,SetTrace:x,usePlugin:V,SetValue:(M,k)=>{b(M).dependOn(()=>k);},GetFormData:P,notifyAll:()=>{Y(),H();},AddNewSchema:W,GetAllDependency:()=>i,GetDependencyOrder:()=>p,Undo:L,Redo:E,initCanUndo:D,initCanRedo:v,onError:g,onSuccess:f,onStart:S}}var q=new Map,ge=(s,e,r)=>{try{if(typeof r.signalCreateor!="function"||typeof r.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(q.has(s))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let t=pe(e,r),{schema:i,GetFormData:n,SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,SetValue:l,usePlugin:a,notifyAll:h,SetTrace:y,GetAllDependency:m,GetDependencyOrder:x,AddNewSchema:R,Undo:O,Redo:A,initCanUndo:L,initCanRedo:E,onError:G,onSuccess:B,onStart:D}=t,v={config:{SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,notifyAll:h,SetTrace:y,usePlugin:a},data:{schema:i,GetFormData:n,AddNewSchema:R,SetValue:l},history:{Undo:O,Redo:A,initCanUndo:L,initCanRedo:E},dependency:{GetAllDependency:m,GetDependencyOrder:x},hooks:{onError:G,onSuccess:B,onStart:D}};return q.set(s,v),v}catch(t){throw Error(t)}},st=s=>{if(q.has(s))return q.get(s);throw Error("\u4E0D\u5B58\u5728\u7684id")},it=s=>{q.delete(s);},lt=ge;export{it as deleteEngine,st as useEngine,ge as useEngineManager,lt as useMeshFlow};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshflow/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A logic orchestration engine utilizing topological scheduling and watermark control to resolve asynchronous race conditions in complex dependency linkages.”",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|