@meshflow/core 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  **基于水位线调度(Watermark Scheduling)的轻量级拓扑逻辑引擎。**
4
4
 
5
+ [![Documentation](https://img.shields.io/badge/docs-VitePress-blue.svg)](https://meshflow-docs.vercel.app/)
6
+ [![Demo](https://img.shields.io/badge/demo-Vercel-orange.svg)](https://meshflow-factory-demo.vercel.app/)
7
+
5
8
  ## 🎯 它解决了什么问题?
6
9
 
7
10
  在复杂的**中后台表单**或**大型配置系统**中,数据的联动关系往往错综复杂。`@meshflow/core` 专门解决以下痛点:
@@ -29,7 +32,7 @@
29
32
  * **⚡ 惰性求值与记忆化**:引入“桶计算”缓存机制,在拓扑传播过程中自动比对输入特征,仅在依赖项发生实质性变更时才触发逻辑重算。
30
33
  * **⚡ 变更剪枝**:即使节点处于受影响路径上,若输入状态未通过有效性检查,引擎将自动截断该路径的后续传播,实现真正的计算最小化。
31
34
  * **🚨 循环依赖检测**:在节点定义阶段实时进行 $O(V+E)$ 的环检测,提前发现逻辑死循环。
32
- * **📦 极简轻量**:零依赖,体积仅 ~7kB(zipped),适配任何 JavaScript 运行时。
35
+ * **📦 极简轻量**:零依赖,体积仅 ~8kB(zipped),适配任何 JavaScript 运行时。
33
36
  * **🔌 插件化架构 (New)**:支持生命周期拦截与监听(如官方调试插件 `@meshflow/logger`)。
34
37
  ---
35
38
 
@@ -40,7 +43,7 @@
40
43
  ```bash
41
44
  npm install @meshflow/core
42
45
  ```
43
- #### 定义节点
46
+ #### 初始化引擎
44
47
  ```typescript
45
48
  import { useMeshFlow } from "@meshflow/core";
46
49
  const schema = {
@@ -48,8 +51,8 @@ const schema = {
48
51
  name: 'billing',
49
52
  label: '计费与汇总',
50
53
  children: [
51
- { type: 'number', name: 'totalPrice', label: '预估月度总价', defaultValue: 0, },
52
- { type: 'input', name: 'priceDetail', label: '计费项说明', defaultValue: '基础配置费用'}
54
+ { type: 'number', name: 'totalPrice', label: '预估月度总价', value: 0, },
55
+ { type: 'input', name: 'priceDetail', label: '计费项说明', value: '基础配置费用'}
53
56
  ]
54
57
  };
55
58
 
@@ -68,7 +71,7 @@ const engine = useMeshFlow<Ref<number,number>,AllPath>('main',schema, {
68
71
  #### 添加联动依赖
69
72
  ```typescript
70
73
  //声明联动规则:当总价 > 2000 时,自动修改描述与主题
71
- engine.config.SetRule("billing.totalPrice", "billing.priceDetail", "defaultValue", {
74
+ engine.config.SetRule("billing.totalPrice", "billing.priceDetail", "value", {
72
75
  logic: ({ slot }) => {
73
76
  const [total] = slot.triggerTargets; // 从触发目标中解构出 totalPrice
74
77
  return total > 2000 ? "大客户折扣" : undefined;
@@ -93,4 +96,5 @@ engine.config.notifyAll();
93
96
  `@meshflow/core` 通过内部的 **DAG(有向无环图)** 和 **Watermark** 机制,确保:
94
97
 
95
98
  * **确定性**:无论异步耗时多久,最终状态始终保持一致。
96
- * **原子性**:一次输入变化,仅触发一次拓扑链路的完整更新。
99
+ * **原子性**:一次输入变化,仅触发一次拓扑链路的完整更新。
100
+
package/index.d.mts CHANGED
@@ -5,48 +5,48 @@ interface MeshErrorContext {
5
5
 
6
6
  interface MeshEvents {
7
7
  'node:start': {
8
- path: string;
8
+ path: MeshPath;
9
9
  };
10
10
  'node:success': {
11
- path: string;
11
+ path: MeshPath;
12
12
  };
13
13
  'node:bucket:success': {
14
- path: string;
14
+ path: MeshPath;
15
15
  key: string;
16
16
  value: any;
17
17
  };
18
18
  'node:error': {
19
- path: string;
19
+ path: MeshPath;
20
20
  error: any;
21
21
  };
22
22
  'node:intercept': {
23
- path: string;
23
+ path: MeshPath;
24
24
  type: number;
25
25
  detail?: any;
26
26
  };
27
27
  'node:release': {
28
- path: string;
28
+ path: MeshPath;
29
29
  type: number;
30
30
  detail?: any;
31
31
  };
32
32
  'node:stagnate': {
33
- path: string;
33
+ path: MeshPath;
34
34
  type: number;
35
35
  };
36
36
  'node:processing': {
37
- path: string;
37
+ path: MeshPath;
38
38
  };
39
39
  'flow:wait': {
40
40
  type: number;
41
41
  detail?: any;
42
42
  };
43
43
  'flow:fire': {
44
- path: string;
44
+ path: MeshPath;
45
45
  type: number;
46
46
  detail?: any;
47
47
  };
48
48
  'flow:start': {
49
- path: string;
49
+ path: MeshPath;
50
50
  };
51
51
  'flow:success': {
52
52
  duration: string;
@@ -55,10 +55,66 @@ interface MeshEvents {
55
55
  type: number;
56
56
  };
57
57
  'node:pending': {
58
- path: string;
58
+ path: MeshPath;
59
59
  };
60
60
  }
61
61
  type MeshEventName = keyof MeshEvents;
62
+ type MeshEmit = <K extends MeshEventName>(event: K, data: MeshEvents[K]) => void;
63
+ type HistoryActionItem = {
64
+ undoAction: () => void;
65
+ redoAction: () => void;
66
+ };
67
+ type MeshFlowHistory = {
68
+ Undo: () => void;
69
+ Redo: () => void;
70
+ initCanUndo: any;
71
+ initCanRedo: any;
72
+ PushIntoHistory: (action: HistoryActionItem, cleanRedo?: boolean) => void;
73
+ CreateHistoryAction: (metadata: [
74
+ {
75
+ path: string;
76
+ value: any;
77
+ },
78
+ {
79
+ path: string;
80
+ value: any;
81
+ }
82
+ ], cb: any) => {
83
+ undoAction: () => any;
84
+ redoAction: () => any;
85
+ };
86
+ };
87
+ interface MeshFlowEngineMap {
88
+ }
89
+ type MeshPath = string | number | symbol;
90
+ interface MeshBucket<P> {
91
+ evaluate: (context: any) => Promise<any> | any;
92
+ [key: string]: any;
93
+ }
94
+ interface MeshFlowTaskNode<P extends MeshPath = MeshPath, S = any, V = any> {
95
+ path: P;
96
+ uid: number;
97
+ type: string;
98
+ state: {
99
+ value: V;
100
+ };
101
+ buckets: Record<string, MeshBucket<P>>;
102
+ notifyKeys: Set<keyof S>;
103
+ dirtySignal: any;
104
+ meta: S;
105
+ dependOn: (cb: (val: V) => V) => void;
106
+ }
107
+ interface MeshFlowGroupNode<P extends MeshPath = MeshPath> {
108
+ path: P;
109
+ uid: number;
110
+ type: 'group';
111
+ children: Array<P>;
112
+ meta: Record<string, any>;
113
+ }
114
+ interface DependOnContext<P extends MeshPath> {
115
+ path: P;
116
+ getNode: (path: P) => MeshFlowTaskNode<P>;
117
+ }
62
118
 
63
119
  type ContractType = 'boolean' | 'scalar' | 'array' | 'object';
64
120
  declare enum DefaultStarategy {
@@ -70,7 +126,7 @@ declare class SchemaBucket<P> {
70
126
  private strategy;
71
127
  contract: ContractType;
72
128
  private rules;
73
- private isDefaultValue;
129
+ private isValue;
74
130
  private id;
75
131
  private cache;
76
132
  private pendingPromise;
@@ -78,16 +134,23 @@ declare class SchemaBucket<P> {
78
134
  private deps;
79
135
  private _forceNotify;
80
136
  promiseToken: any;
81
- globalCalcCount: number;
137
+ private effectArray;
82
138
  constructor(baseValue: any, key: string, path: P);
83
139
  forceNotify(): void;
84
140
  isForceNotify(): boolean;
85
141
  setStrategy(type: DefaultStarategy): void;
86
- updateInputValueRule(newVal: any): void;
87
142
  setDefaultRule(value: any): void;
88
143
  setRules(value: any, DepsArray?: Array<[P, any]>): () => void;
89
144
  updateDeps(DepsArray: Array<[P, any]>): void;
90
145
  setRule(value: any, DepsArray?: Array<[P, any]>): (() => void) | undefined;
146
+ setSideEffect(data: {
147
+ fn: (args: any[]) => any;
148
+ args: any[];
149
+ }): void;
150
+ getSideEffect(): {
151
+ fn: (args: any) => any;
152
+ args: any[];
153
+ }[];
91
154
  evaluate(api: any): any;
92
155
  private finalizeSync;
93
156
  private inferType;
@@ -96,6 +159,16 @@ declare class SchemaBucket<P> {
96
159
  type FinalFlatten<T> = T extends infer O ? {
97
160
  [K in keyof O]: O[K];
98
161
  } : never;
162
+ type Unwrap<T> = T extends ReadonlyArray<infer U> ? U : T;
163
+ type InferLeafPath<T, Prefix extends string = ""> = Unwrap<T> extends infer Node ? Node extends {
164
+ readonly name: infer N;
165
+ } ? N extends string ? N extends "" ? Node extends {
166
+ readonly children: infer C;
167
+ } ? InferLeafPath<C, Prefix> : never : (Node extends {
168
+ readonly children: infer C;
169
+ } ? InferLeafPath<C, Prefix extends "" ? N : `${Prefix}.${N}`> : (Prefix extends "" ? N : `${Prefix}.${N}`)) : N extends number | symbol ? Node extends {
170
+ readonly children: infer C;
171
+ } ? InferLeafPath<C, Prefix> : N : never : never : never;
99
172
  type KeysOfUnion<T> = T extends any ? keyof T : never;
100
173
 
101
174
  type BaseField = {
@@ -113,13 +186,13 @@ type InputField = BaseField & {
113
186
  required: boolean;
114
187
  min?: number;
115
188
  maxLength: number;
116
- defaultValue: string | number;
189
+ value: string | number;
117
190
  };
118
191
  type CheckboxField = BaseField & {
119
192
  type: "checkbox";
120
193
  description?: string;
121
194
  required: boolean;
122
- defaultValue: boolean;
195
+ value: boolean;
123
196
  };
124
197
  type SelectField = BaseField & {
125
198
  type: "select";
@@ -128,7 +201,7 @@ type SelectField = BaseField & {
128
201
  label: string;
129
202
  value: any;
130
203
  }[];
131
- defaultValue: any;
204
+ value: any;
132
205
  };
133
206
  type GroupField = Omit<BaseField, "label" | "name" | "placeholder" | "validators"> & {
134
207
  type: "group";
@@ -155,46 +228,35 @@ interface logicApi {
155
228
  };
156
229
  }
157
230
 
158
- type GetType<T, P> = P extends keyof T ? T[P] : never;
159
- type Engine<T> = {
160
- data: {
161
- [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue' | 'GetValue' | 'GetGroupByPath']: GetType<T, K>;
162
- };
231
+ declare function useEngineInstance<T, P extends MeshPath>(data: any, options: {
163
232
  config: {
164
- [K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
165
- };
166
- dependency: {
167
- [K in 'GetAllDependency' | 'GetDependencyOrder']: GetType<T, K>;
168
- };
169
- history: {
170
- [K in "Undo" | "Redo" | "initCanUndo" | "initCanRedo"]: GetType<T, K>;
171
- };
172
- hooks: {
173
- [K in "onError" | "onSuccess" | "onStart"]: GetType<T, K>;
174
- };
175
- };
176
- /** @deprecated 请使用新的 useMeshFlow 别名 */
177
- declare const useEngineManager: <T, P extends string>(id: string | symbol, Schema: any, options: {
178
- config?: {
179
233
  useGreedy: boolean;
180
234
  };
181
235
  UITrigger: {
182
236
  signalCreateor: () => T;
183
237
  signalTrigger: (signal: T) => void;
184
238
  };
185
- }) => Engine<{
239
+ modules: {
240
+ useHistory?: () => MeshFlowHistory;
241
+ };
242
+ plugins: {};
243
+ }): {
186
244
  schema: RenderSchema;
187
245
  SetRule: (outDegreePath: P, inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
188
246
  value?: any;
189
247
  priority?: number;
190
248
  forceNotify?: boolean;
191
249
  logic: (api: logicApi) => any;
250
+ effect?: ((args: any) => any) | undefined;
251
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
192
252
  } | undefined) => void;
193
253
  SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
194
254
  value?: any;
195
255
  priority?: number;
196
256
  forceNotify?: boolean;
197
257
  logic: (api: logicApi) => any;
258
+ effect?: ((args: any) => any) | undefined;
259
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
198
260
  } | undefined) => void;
199
261
  SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
200
262
  SetValidators: (path: P, options: {
@@ -210,34 +272,68 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
210
272
  SetValue: (path: P, value: any) => void;
211
273
  GetValue: (path: P, key?: string) => any;
212
274
  GetFormData: () => any;
213
- GetGroupByPath: (path: string) => RenderSchema | undefined;
275
+ GetGroupByPath: (path: MeshPath) => RenderSchema | undefined;
214
276
  notifyAll: () => Promise<void>;
215
277
  AddNewSchema: (path: string, data: any) => RenderSchema;
216
278
  GetAllDependency: () => Map<P, Set<P>>;
217
279
  GetDependencyOrder: () => P[][];
218
- Undo: () => void;
219
- Redo: () => void;
220
- initCanUndo: (cb: (newVal: number) => any) => void;
221
- initCanRedo: (cb: (newVal: number) => any) => void;
280
+ historyExports: Partial<MeshFlowHistory>;
222
281
  onError: (cb: (error: MeshErrorContext) => void) => () => void;
223
282
  onSuccess: (cb: (data: unknown) => void) => () => void;
224
283
  onStart: (cb: (data: {
225
284
  path: P;
226
285
  }) => void) => () => void;
227
- }>;
228
- declare const useEngine: <T = any, P extends string = string>(id: string | symbol) => Engine<{
286
+ };
287
+
288
+ type SchedulerType<T, P extends MeshPath> = ReturnType<typeof useEngineInstance<T, P>>;
289
+ type GetType<T, P> = P extends keyof T ? T[P] : never;
290
+ type BaseEngine<T> = {
291
+ data: {
292
+ [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue' | 'GetValue' | 'GetGroupByPath']: GetType<T, K>;
293
+ };
294
+ config: {
295
+ [K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
296
+ };
297
+ dependency: {
298
+ [K in 'GetAllDependency' | 'GetDependencyOrder']: GetType<T, K>;
299
+ };
300
+ hooks: {
301
+ [K in "onError" | "onSuccess" | "onStart"]: GetType<T, K>;
302
+ };
303
+ };
304
+ type TransformKey<T> = T extends `use${infer Rest}` ? Uncapitalize<Rest> : T;
305
+ type EngineModules<M> = {
306
+ [K in keyof M as TransformKey<string & K>]: M[K] extends (...args: any) => infer R ? R : never;
307
+ };
308
+ type Engine<T, M> = BaseEngine<T> & EngineModules<M>;
309
+ /** @deprecated 请使用新的 useMeshFlow 别名 */
310
+ declare const useEngineManager: <const S extends Record<string, any>, T, //UITrigger的类型
311
+ M extends Record<string, any>, P extends MeshPath = [InferLeafPath<S>] extends [never] ? MeshPath : InferLeafPath<S> | (string & {})>(id: MeshPath, Schema: S, options: {
312
+ config?: {
313
+ useGreedy: boolean;
314
+ };
315
+ modules?: M;
316
+ UITrigger: {
317
+ signalCreateor: () => T;
318
+ signalTrigger: (signal: T) => void;
319
+ };
320
+ }) => Engine<{
229
321
  schema: RenderSchema;
230
322
  SetRule: (outDegreePath: P, inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
231
323
  value?: any;
232
324
  priority?: number;
233
325
  forceNotify?: boolean;
234
326
  logic: (api: logicApi) => any;
327
+ effect?: ((args: any) => any) | undefined;
328
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
235
329
  } | undefined) => void;
236
330
  SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
237
331
  value?: any;
238
332
  priority?: number;
239
333
  forceNotify?: boolean;
240
334
  logic: (api: logicApi) => any;
335
+ effect?: ((args: any) => any) | undefined;
336
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
241
337
  } | undefined) => void;
242
338
  SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
243
339
  SetValidators: (path: P, options: {
@@ -253,26 +349,38 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
253
349
  SetValue: (path: P, value: any) => void;
254
350
  GetValue: (path: P, key?: string) => any;
255
351
  GetFormData: () => any;
256
- GetGroupByPath: (path: string) => RenderSchema | undefined;
352
+ GetGroupByPath: (path: MeshPath) => RenderSchema | undefined;
257
353
  notifyAll: () => Promise<void>;
258
354
  AddNewSchema: (path: string, data: any) => RenderSchema;
259
355
  GetAllDependency: () => Map<P, Set<P>>;
260
356
  GetDependencyOrder: () => P[][];
261
- Undo: () => void;
262
- Redo: () => void;
263
- initCanUndo: (cb: (newVal: number) => any) => void;
264
- initCanRedo: (cb: (newVal: number) => any) => void;
357
+ historyExports: Partial<MeshFlowHistory>;
265
358
  onError: (cb: (error: MeshErrorContext) => void) => () => void;
266
359
  onSuccess: (cb: (data: unknown) => void) => () => void;
267
360
  onStart: (cb: (data: {
268
361
  path: P;
269
362
  }) => void) => () => void;
270
- }>;
271
- declare const deleteEngine: (id: string | symbol) => void;
272
- declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: any, options: {
363
+ }, M>;
364
+ declare const useMeshFlowDefiner: <P extends string>() => <T, M extends Record<string, any>>(id: MeshPath, schema: any, options: {
365
+ UITrigger: {
366
+ signalCreateor: () => T;
367
+ signalTrigger: (s: T) => void;
368
+ };
369
+ modules?: M;
370
+ config?: any;
371
+ }) => Engine<ReturnType<typeof useEngineInstance<T, P>>, M>;
372
+ /**
373
+ * 获取 Engine 实例
374
+ * @template M 手动注入的模块映射 (例如 { useHistory: typeof useHistory })
375
+ * @template K ID 类型 (支持 string | number | symbol)
376
+ */
377
+ declare const useEngine: <M, ID extends keyof MeshFlowEngineMap | (MeshPath & {}) = MeshPath>(id: ID) => [M] extends [never] ? (ID extends keyof MeshFlowEngineMap ? MeshFlowEngineMap[ID] : Engine<SchedulerType<any, any>, {}>) : Engine<SchedulerType<any, any>, M>;
378
+ declare const deleteEngine: (id: MeshPath) => void;
379
+ declare const useMeshFlow: <const S extends Record<string, any>, T, M extends Record<string, any>, P extends MeshPath = [InferLeafPath<S>] extends [never] ? MeshPath : InferLeafPath<S> | (string & {})>(id: MeshPath, Schema: S, options: {
273
380
  config?: {
274
381
  useGreedy: boolean;
275
382
  };
383
+ modules?: M;
276
384
  UITrigger: {
277
385
  signalCreateor: () => T;
278
386
  signalTrigger: (signal: T) => void;
@@ -284,12 +392,16 @@ declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: an
284
392
  priority?: number;
285
393
  forceNotify?: boolean;
286
394
  logic: (api: logicApi) => any;
395
+ effect?: ((args: any) => any) | undefined;
396
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
287
397
  } | undefined) => void;
288
398
  SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
289
399
  value?: any;
290
400
  priority?: number;
291
401
  forceNotify?: boolean;
292
402
  logic: (api: logicApi) => any;
403
+ effect?: ((args: any) => any) | undefined;
404
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
293
405
  } | undefined) => void;
294
406
  SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
295
407
  SetValidators: (path: P, options: {
@@ -305,20 +417,17 @@ declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: an
305
417
  SetValue: (path: P, value: any) => void;
306
418
  GetValue: (path: P, key?: string) => any;
307
419
  GetFormData: () => any;
308
- GetGroupByPath: (path: string) => RenderSchema | undefined;
420
+ GetGroupByPath: (path: MeshPath) => RenderSchema | undefined;
309
421
  notifyAll: () => Promise<void>;
310
422
  AddNewSchema: (path: string, data: any) => RenderSchema;
311
423
  GetAllDependency: () => Map<P, Set<P>>;
312
424
  GetDependencyOrder: () => P[][];
313
- Undo: () => void;
314
- Redo: () => void;
315
- initCanUndo: (cb: (newVal: number) => any) => void;
316
- initCanRedo: (cb: (newVal: number) => any) => void;
425
+ historyExports: Partial<MeshFlowHistory>;
317
426
  onError: (cb: (error: MeshErrorContext) => void) => () => void;
318
427
  onSuccess: (cb: (data: unknown) => void) => () => void;
319
428
  onStart: (cb: (data: {
320
429
  path: P;
321
430
  }) => void) => () => void;
322
- }>;
431
+ }, M>;
323
432
 
324
- export { deleteEngine, useEngine, useEngineManager, useMeshFlow };
433
+ export { type DependOnContext, type HistoryActionItem, type MeshBucket, type MeshEmit, type MeshEventName, type MeshEvents, type MeshFlowEngineMap, type MeshFlowGroupNode, type MeshFlowHistory, type MeshFlowTaskNode, type MeshPath, deleteEngine, useEngine, useEngineManager, useMeshFlow, useMeshFlowDefiner };
package/index.d.ts CHANGED
@@ -5,48 +5,48 @@ interface MeshErrorContext {
5
5
 
6
6
  interface MeshEvents {
7
7
  'node:start': {
8
- path: string;
8
+ path: MeshPath;
9
9
  };
10
10
  'node:success': {
11
- path: string;
11
+ path: MeshPath;
12
12
  };
13
13
  'node:bucket:success': {
14
- path: string;
14
+ path: MeshPath;
15
15
  key: string;
16
16
  value: any;
17
17
  };
18
18
  'node:error': {
19
- path: string;
19
+ path: MeshPath;
20
20
  error: any;
21
21
  };
22
22
  'node:intercept': {
23
- path: string;
23
+ path: MeshPath;
24
24
  type: number;
25
25
  detail?: any;
26
26
  };
27
27
  'node:release': {
28
- path: string;
28
+ path: MeshPath;
29
29
  type: number;
30
30
  detail?: any;
31
31
  };
32
32
  'node:stagnate': {
33
- path: string;
33
+ path: MeshPath;
34
34
  type: number;
35
35
  };
36
36
  'node:processing': {
37
- path: string;
37
+ path: MeshPath;
38
38
  };
39
39
  'flow:wait': {
40
40
  type: number;
41
41
  detail?: any;
42
42
  };
43
43
  'flow:fire': {
44
- path: string;
44
+ path: MeshPath;
45
45
  type: number;
46
46
  detail?: any;
47
47
  };
48
48
  'flow:start': {
49
- path: string;
49
+ path: MeshPath;
50
50
  };
51
51
  'flow:success': {
52
52
  duration: string;
@@ -55,10 +55,66 @@ interface MeshEvents {
55
55
  type: number;
56
56
  };
57
57
  'node:pending': {
58
- path: string;
58
+ path: MeshPath;
59
59
  };
60
60
  }
61
61
  type MeshEventName = keyof MeshEvents;
62
+ type MeshEmit = <K extends MeshEventName>(event: K, data: MeshEvents[K]) => void;
63
+ type HistoryActionItem = {
64
+ undoAction: () => void;
65
+ redoAction: () => void;
66
+ };
67
+ type MeshFlowHistory = {
68
+ Undo: () => void;
69
+ Redo: () => void;
70
+ initCanUndo: any;
71
+ initCanRedo: any;
72
+ PushIntoHistory: (action: HistoryActionItem, cleanRedo?: boolean) => void;
73
+ CreateHistoryAction: (metadata: [
74
+ {
75
+ path: string;
76
+ value: any;
77
+ },
78
+ {
79
+ path: string;
80
+ value: any;
81
+ }
82
+ ], cb: any) => {
83
+ undoAction: () => any;
84
+ redoAction: () => any;
85
+ };
86
+ };
87
+ interface MeshFlowEngineMap {
88
+ }
89
+ type MeshPath = string | number | symbol;
90
+ interface MeshBucket<P> {
91
+ evaluate: (context: any) => Promise<any> | any;
92
+ [key: string]: any;
93
+ }
94
+ interface MeshFlowTaskNode<P extends MeshPath = MeshPath, S = any, V = any> {
95
+ path: P;
96
+ uid: number;
97
+ type: string;
98
+ state: {
99
+ value: V;
100
+ };
101
+ buckets: Record<string, MeshBucket<P>>;
102
+ notifyKeys: Set<keyof S>;
103
+ dirtySignal: any;
104
+ meta: S;
105
+ dependOn: (cb: (val: V) => V) => void;
106
+ }
107
+ interface MeshFlowGroupNode<P extends MeshPath = MeshPath> {
108
+ path: P;
109
+ uid: number;
110
+ type: 'group';
111
+ children: Array<P>;
112
+ meta: Record<string, any>;
113
+ }
114
+ interface DependOnContext<P extends MeshPath> {
115
+ path: P;
116
+ getNode: (path: P) => MeshFlowTaskNode<P>;
117
+ }
62
118
 
63
119
  type ContractType = 'boolean' | 'scalar' | 'array' | 'object';
64
120
  declare enum DefaultStarategy {
@@ -70,7 +126,7 @@ declare class SchemaBucket<P> {
70
126
  private strategy;
71
127
  contract: ContractType;
72
128
  private rules;
73
- private isDefaultValue;
129
+ private isValue;
74
130
  private id;
75
131
  private cache;
76
132
  private pendingPromise;
@@ -78,16 +134,23 @@ declare class SchemaBucket<P> {
78
134
  private deps;
79
135
  private _forceNotify;
80
136
  promiseToken: any;
81
- globalCalcCount: number;
137
+ private effectArray;
82
138
  constructor(baseValue: any, key: string, path: P);
83
139
  forceNotify(): void;
84
140
  isForceNotify(): boolean;
85
141
  setStrategy(type: DefaultStarategy): void;
86
- updateInputValueRule(newVal: any): void;
87
142
  setDefaultRule(value: any): void;
88
143
  setRules(value: any, DepsArray?: Array<[P, any]>): () => void;
89
144
  updateDeps(DepsArray: Array<[P, any]>): void;
90
145
  setRule(value: any, DepsArray?: Array<[P, any]>): (() => void) | undefined;
146
+ setSideEffect(data: {
147
+ fn: (args: any[]) => any;
148
+ args: any[];
149
+ }): void;
150
+ getSideEffect(): {
151
+ fn: (args: any) => any;
152
+ args: any[];
153
+ }[];
91
154
  evaluate(api: any): any;
92
155
  private finalizeSync;
93
156
  private inferType;
@@ -96,6 +159,16 @@ declare class SchemaBucket<P> {
96
159
  type FinalFlatten<T> = T extends infer O ? {
97
160
  [K in keyof O]: O[K];
98
161
  } : never;
162
+ type Unwrap<T> = T extends ReadonlyArray<infer U> ? U : T;
163
+ type InferLeafPath<T, Prefix extends string = ""> = Unwrap<T> extends infer Node ? Node extends {
164
+ readonly name: infer N;
165
+ } ? N extends string ? N extends "" ? Node extends {
166
+ readonly children: infer C;
167
+ } ? InferLeafPath<C, Prefix> : never : (Node extends {
168
+ readonly children: infer C;
169
+ } ? InferLeafPath<C, Prefix extends "" ? N : `${Prefix}.${N}`> : (Prefix extends "" ? N : `${Prefix}.${N}`)) : N extends number | symbol ? Node extends {
170
+ readonly children: infer C;
171
+ } ? InferLeafPath<C, Prefix> : N : never : never : never;
99
172
  type KeysOfUnion<T> = T extends any ? keyof T : never;
100
173
 
101
174
  type BaseField = {
@@ -113,13 +186,13 @@ type InputField = BaseField & {
113
186
  required: boolean;
114
187
  min?: number;
115
188
  maxLength: number;
116
- defaultValue: string | number;
189
+ value: string | number;
117
190
  };
118
191
  type CheckboxField = BaseField & {
119
192
  type: "checkbox";
120
193
  description?: string;
121
194
  required: boolean;
122
- defaultValue: boolean;
195
+ value: boolean;
123
196
  };
124
197
  type SelectField = BaseField & {
125
198
  type: "select";
@@ -128,7 +201,7 @@ type SelectField = BaseField & {
128
201
  label: string;
129
202
  value: any;
130
203
  }[];
131
- defaultValue: any;
204
+ value: any;
132
205
  };
133
206
  type GroupField = Omit<BaseField, "label" | "name" | "placeholder" | "validators"> & {
134
207
  type: "group";
@@ -155,46 +228,35 @@ interface logicApi {
155
228
  };
156
229
  }
157
230
 
158
- type GetType<T, P> = P extends keyof T ? T[P] : never;
159
- type Engine<T> = {
160
- data: {
161
- [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue' | 'GetValue' | 'GetGroupByPath']: GetType<T, K>;
162
- };
231
+ declare function useEngineInstance<T, P extends MeshPath>(data: any, options: {
163
232
  config: {
164
- [K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
165
- };
166
- dependency: {
167
- [K in 'GetAllDependency' | 'GetDependencyOrder']: GetType<T, K>;
168
- };
169
- history: {
170
- [K in "Undo" | "Redo" | "initCanUndo" | "initCanRedo"]: GetType<T, K>;
171
- };
172
- hooks: {
173
- [K in "onError" | "onSuccess" | "onStart"]: GetType<T, K>;
174
- };
175
- };
176
- /** @deprecated 请使用新的 useMeshFlow 别名 */
177
- declare const useEngineManager: <T, P extends string>(id: string | symbol, Schema: any, options: {
178
- config?: {
179
233
  useGreedy: boolean;
180
234
  };
181
235
  UITrigger: {
182
236
  signalCreateor: () => T;
183
237
  signalTrigger: (signal: T) => void;
184
238
  };
185
- }) => Engine<{
239
+ modules: {
240
+ useHistory?: () => MeshFlowHistory;
241
+ };
242
+ plugins: {};
243
+ }): {
186
244
  schema: RenderSchema;
187
245
  SetRule: (outDegreePath: P, inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
188
246
  value?: any;
189
247
  priority?: number;
190
248
  forceNotify?: boolean;
191
249
  logic: (api: logicApi) => any;
250
+ effect?: ((args: any) => any) | undefined;
251
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
192
252
  } | undefined) => void;
193
253
  SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
194
254
  value?: any;
195
255
  priority?: number;
196
256
  forceNotify?: boolean;
197
257
  logic: (api: logicApi) => any;
258
+ effect?: ((args: any) => any) | undefined;
259
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
198
260
  } | undefined) => void;
199
261
  SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
200
262
  SetValidators: (path: P, options: {
@@ -210,34 +272,68 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
210
272
  SetValue: (path: P, value: any) => void;
211
273
  GetValue: (path: P, key?: string) => any;
212
274
  GetFormData: () => any;
213
- GetGroupByPath: (path: string) => RenderSchema | undefined;
275
+ GetGroupByPath: (path: MeshPath) => RenderSchema | undefined;
214
276
  notifyAll: () => Promise<void>;
215
277
  AddNewSchema: (path: string, data: any) => RenderSchema;
216
278
  GetAllDependency: () => Map<P, Set<P>>;
217
279
  GetDependencyOrder: () => P[][];
218
- Undo: () => void;
219
- Redo: () => void;
220
- initCanUndo: (cb: (newVal: number) => any) => void;
221
- initCanRedo: (cb: (newVal: number) => any) => void;
280
+ historyExports: Partial<MeshFlowHistory>;
222
281
  onError: (cb: (error: MeshErrorContext) => void) => () => void;
223
282
  onSuccess: (cb: (data: unknown) => void) => () => void;
224
283
  onStart: (cb: (data: {
225
284
  path: P;
226
285
  }) => void) => () => void;
227
- }>;
228
- declare const useEngine: <T = any, P extends string = string>(id: string | symbol) => Engine<{
286
+ };
287
+
288
+ type SchedulerType<T, P extends MeshPath> = ReturnType<typeof useEngineInstance<T, P>>;
289
+ type GetType<T, P> = P extends keyof T ? T[P] : never;
290
+ type BaseEngine<T> = {
291
+ data: {
292
+ [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue' | 'GetValue' | 'GetGroupByPath']: GetType<T, K>;
293
+ };
294
+ config: {
295
+ [K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
296
+ };
297
+ dependency: {
298
+ [K in 'GetAllDependency' | 'GetDependencyOrder']: GetType<T, K>;
299
+ };
300
+ hooks: {
301
+ [K in "onError" | "onSuccess" | "onStart"]: GetType<T, K>;
302
+ };
303
+ };
304
+ type TransformKey<T> = T extends `use${infer Rest}` ? Uncapitalize<Rest> : T;
305
+ type EngineModules<M> = {
306
+ [K in keyof M as TransformKey<string & K>]: M[K] extends (...args: any) => infer R ? R : never;
307
+ };
308
+ type Engine<T, M> = BaseEngine<T> & EngineModules<M>;
309
+ /** @deprecated 请使用新的 useMeshFlow 别名 */
310
+ declare const useEngineManager: <const S extends Record<string, any>, T, //UITrigger的类型
311
+ M extends Record<string, any>, P extends MeshPath = [InferLeafPath<S>] extends [never] ? MeshPath : InferLeafPath<S> | (string & {})>(id: MeshPath, Schema: S, options: {
312
+ config?: {
313
+ useGreedy: boolean;
314
+ };
315
+ modules?: M;
316
+ UITrigger: {
317
+ signalCreateor: () => T;
318
+ signalTrigger: (signal: T) => void;
319
+ };
320
+ }) => Engine<{
229
321
  schema: RenderSchema;
230
322
  SetRule: (outDegreePath: P, inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
231
323
  value?: any;
232
324
  priority?: number;
233
325
  forceNotify?: boolean;
234
326
  logic: (api: logicApi) => any;
327
+ effect?: ((args: any) => any) | undefined;
328
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
235
329
  } | undefined) => void;
236
330
  SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
237
331
  value?: any;
238
332
  priority?: number;
239
333
  forceNotify?: boolean;
240
334
  logic: (api: logicApi) => any;
335
+ effect?: ((args: any) => any) | undefined;
336
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
241
337
  } | undefined) => void;
242
338
  SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
243
339
  SetValidators: (path: P, options: {
@@ -253,26 +349,38 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
253
349
  SetValue: (path: P, value: any) => void;
254
350
  GetValue: (path: P, key?: string) => any;
255
351
  GetFormData: () => any;
256
- GetGroupByPath: (path: string) => RenderSchema | undefined;
352
+ GetGroupByPath: (path: MeshPath) => RenderSchema | undefined;
257
353
  notifyAll: () => Promise<void>;
258
354
  AddNewSchema: (path: string, data: any) => RenderSchema;
259
355
  GetAllDependency: () => Map<P, Set<P>>;
260
356
  GetDependencyOrder: () => P[][];
261
- Undo: () => void;
262
- Redo: () => void;
263
- initCanUndo: (cb: (newVal: number) => any) => void;
264
- initCanRedo: (cb: (newVal: number) => any) => void;
357
+ historyExports: Partial<MeshFlowHistory>;
265
358
  onError: (cb: (error: MeshErrorContext) => void) => () => void;
266
359
  onSuccess: (cb: (data: unknown) => void) => () => void;
267
360
  onStart: (cb: (data: {
268
361
  path: P;
269
362
  }) => void) => () => void;
270
- }>;
271
- declare const deleteEngine: (id: string | symbol) => void;
272
- declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: any, options: {
363
+ }, M>;
364
+ declare const useMeshFlowDefiner: <P extends string>() => <T, M extends Record<string, any>>(id: MeshPath, schema: any, options: {
365
+ UITrigger: {
366
+ signalCreateor: () => T;
367
+ signalTrigger: (s: T) => void;
368
+ };
369
+ modules?: M;
370
+ config?: any;
371
+ }) => Engine<ReturnType<typeof useEngineInstance<T, P>>, M>;
372
+ /**
373
+ * 获取 Engine 实例
374
+ * @template M 手动注入的模块映射 (例如 { useHistory: typeof useHistory })
375
+ * @template K ID 类型 (支持 string | number | symbol)
376
+ */
377
+ declare const useEngine: <M, ID extends keyof MeshFlowEngineMap | (MeshPath & {}) = MeshPath>(id: ID) => [M] extends [never] ? (ID extends keyof MeshFlowEngineMap ? MeshFlowEngineMap[ID] : Engine<SchedulerType<any, any>, {}>) : Engine<SchedulerType<any, any>, M>;
378
+ declare const deleteEngine: (id: MeshPath) => void;
379
+ declare const useMeshFlow: <const S extends Record<string, any>, T, M extends Record<string, any>, P extends MeshPath = [InferLeafPath<S>] extends [never] ? MeshPath : InferLeafPath<S> | (string & {})>(id: MeshPath, Schema: S, options: {
273
380
  config?: {
274
381
  useGreedy: boolean;
275
382
  };
383
+ modules?: M;
276
384
  UITrigger: {
277
385
  signalCreateor: () => T;
278
386
  signalTrigger: (signal: T) => void;
@@ -284,12 +392,16 @@ declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: an
284
392
  priority?: number;
285
393
  forceNotify?: boolean;
286
394
  logic: (api: logicApi) => any;
395
+ effect?: ((args: any) => any) | undefined;
396
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
287
397
  } | undefined) => void;
288
398
  SetRules: (outDegreePaths: P[], inDegreePath: P, key: KeysOfUnion<InputField | CheckboxField | SelectField>, options?: {
289
399
  value?: any;
290
400
  priority?: number;
291
401
  forceNotify?: boolean;
292
402
  logic: (api: logicApi) => any;
403
+ effect?: ((args: any) => any) | undefined;
404
+ effectArgs?: Array<KeysOfUnion<Exclude<FormFieldSchema, GroupField>>>;
293
405
  } | undefined) => void;
294
406
  SetStrategy: (path: unknown, key: KeysOfUnion<Exclude<FormFieldSchema, GroupField>>, strategy: DefaultStarategy) => void;
295
407
  SetValidators: (path: P, options: {
@@ -305,20 +417,17 @@ declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: an
305
417
  SetValue: (path: P, value: any) => void;
306
418
  GetValue: (path: P, key?: string) => any;
307
419
  GetFormData: () => any;
308
- GetGroupByPath: (path: string) => RenderSchema | undefined;
420
+ GetGroupByPath: (path: MeshPath) => RenderSchema | undefined;
309
421
  notifyAll: () => Promise<void>;
310
422
  AddNewSchema: (path: string, data: any) => RenderSchema;
311
423
  GetAllDependency: () => Map<P, Set<P>>;
312
424
  GetDependencyOrder: () => P[][];
313
- Undo: () => void;
314
- Redo: () => void;
315
- initCanUndo: (cb: (newVal: number) => any) => void;
316
- initCanRedo: (cb: (newVal: number) => any) => void;
425
+ historyExports: Partial<MeshFlowHistory>;
317
426
  onError: (cb: (error: MeshErrorContext) => void) => () => void;
318
427
  onSuccess: (cb: (data: unknown) => void) => () => void;
319
428
  onStart: (cb: (data: {
320
429
  path: P;
321
430
  }) => void) => () => void;
322
- }>;
431
+ }, M>;
323
432
 
324
- export { deleteEngine, useEngine, useEngineManager, useMeshFlow };
433
+ export { type DependOnContext, type HistoryActionItem, type MeshBucket, type MeshEmit, type MeshEventName, type MeshEvents, type MeshFlowEngineMap, type MeshFlowGroupNode, type MeshFlowHistory, type MeshFlowTaskNode, type MeshPath, deleteEngine, useEngine, useEngineManager, useMeshFlow, useMeshFlowDefiner };
package/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var te=class{computedRules=[];store={OR:(t,r)=>{let e,l,n=this.computedRules;for(let s=0;s<n.length;s++){let a=n[s],o=a.logic(t);if(o instanceof Promise)return (async()=>{let p=await o;if(a.entityId==="__base__"?l=p:p&&(e=a.value),typeof e>"u")for(let u=s+1;u<n.length;u++){let y=n[u],T=y.logic(t),f=T instanceof Promise?await T:T;if(y.entityId==="__base__"){l=f;continue}if(f){e=y.value;break}}return typeof e>"u"&&(e=l),{res:e,version:r}})();let i=o;if(a.entityId==="__base__"){l=i;continue}if(i){e=a.value;break}}return typeof e>"u"&&(e=l),{res:e,version:r}},PRIORITY:(t,r)=>{let e=null,l=this.computedRules;for(let n=0;n<l.length;n++){let a=l[n].logic(t);if(a instanceof Promise)return (async()=>{let o=await a;if(o!==void 0)return {res:o,version:r};for(let i=n+1;i<l.length;i++){let p=l[i].logic(t),u=p instanceof Promise?await p:p;if(u!==void 0)return {res:u,version:r}}return {res:void 0,version:r}})();if(a!==void 0)return {res:a,version:r}}return {res:e,version:r}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(t){this.getRules=t,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let t=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(t.values()).map(r=>Array.from(r)).flat().sort((r,e)=>e.priority-r.priority):this.computedRules=Array.from(t.values()).map(r=>Array.from(r)).flat();}setStrategy(t){this.CurrentStrategy=this.store[t],this.updateComputedRules();}evaluate(t,r){return this.CurrentStrategy(t,r)}},Q=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(t,r,e){let l=()=>this.rules;this.strategy=new te(l),this.path=e,this.isDefaultValue=r==="defaultValue",this.contract=this.inferType(t),this.cache=t,this.setRule({priority:0,entityId:"__base__",logic:()=>t});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(t){this.strategy.setStrategy(t);}updateInputValueRule(t){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>t});}setDefaultRule(t){let r=new Set;r.add(t),this.rules.set(t.id,r);}setRules(t,r){r&&this.updateDeps(r);let e=++this.id,l={...t,entityId:e};for(let n of t.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(l);return this.strategy.updateComputedRules(),()=>{for(let n of t.triggerPaths){let s=this.rules.get(n);s&&(s.delete(l),s.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(t){for(let[r,e]of t)this.deps.set(r,e);}setRule(t,r){if(r&&this.updateDeps(r),typeof t.entityId=="string"){this.setDefaultRule(t);return}let e=++this.id,l={...t,entityId:e};if(t)for(let n of t.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(l);return this.strategy.updateComputedRules(),()=>{for(let n of t.triggerPaths){let s=this.rules.get(n);s&&(s.delete(l),s.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}evaluate(t){let r=null;if(t.GetToken&&(r=t.GetToken()),this.pendingPromise&&this.promiseToken!==r&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let e=false;if(typeof t.triggerPath=="string"){e=true;let s=this.deps.get(t.triggerPath),a=t.GetValueByPath(t.triggerPath);if(typeof s=="object"||typeof a=="object")e=false;else {let o=Array.from(this.deps.keys());for(let i of o){let p=this.deps.get(i),u=t.GetValueByPath(i);if(p!==u){e=false;break}}}}if(e)return this.cache;this.promiseToken=r;let l=++this.version,n=this.strategy.evaluate(t,l);if(!(n instanceof Promise)){let{res:s,version:a}=n;return this.finalizeSync(s,a,t,r)}return this.pendingPromise=(async()=>{try{let{res:s,version:a}=await n;return this.finalizeSync(s,a,t,r)}catch(s){throw {path:this.path,error:s}}finally{this.promiseToken===r&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(t,r,e,l){return l!==this.promiseToken||r<this.version?this.cache:(this.cache=t,this.deps.forEach((n,s)=>{this.deps.set(s,e.GetValueByPath(s));}),t)}inferType(t){return Array.isArray(t)?"array":typeof t}},Z=class{validators=[];defaultValidators=[];path="";constructor(t){this.path=t,this.SetDefaultValidators();}setValidators(t){this.validators.push(t);}SetDefaultValidators(){let t={logic:e=>e||typeof e=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:e=>!!e.required},r={logic:function(e){return e.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(e){return typeof e.maxLength!="number"?false:(r.options={maxLength:e.maxLength},e.type==="input"&&e.hidden===false)},options:{}};this.defaultValidators.push(t),this.defaultValidators.push(r);}evaluate(t,r){let e=true,l=[...this.defaultValidators,...this.validators];for(let n of l){if(!n.condition(r))continue;let a=n.logic(t);if(typeof a!="boolean"){e=a;break}}return e}};var re=(c={frameQuota:12})=>{let t=performance.now(),r=0,e=false,l=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>e,reset(){t=performance.now(),r=0,e=true;},shouldYield(){let n=performance.now();return r++,!!((r>=5||e)&&(r=0,n-t>c.frameQuota||l()))},async yieldToMain(){return new Promise(n=>{Pe(()=>{t=performance.now(),r=0,e&&(e=false),n();});})}}},Pe=c=>{let{port1:t,port2:r}=new MessageChannel;t.onmessage=c,r.postMessage(null);};function ae(c,t,r,e,l){let n=new Map,s=c.useGreedy,a=re();return async(i,p)=>{let y=Symbol("token");n.set(i,y);let T=false;a.reset();let f=new Set,x=new Set,M=new Set(t.GetAllNextDependency(i));M.add(i);let A=new Map,O=new Map,G=new Set,I=t.GetPathToLevelMap(),B=I.get(i)??0,L=0,q=S=>{t.GetAllNextDependency(S).forEach(F=>{let E=I.get(F)||0;E>L&&(L=E);});};q(i),p.forEach(S=>{G.add(S);}),f.add(i);let j=performance.now();e.emit("flow:start",{path:i}),e.callOnStart({path:i});let z=false,X=30,J=S=>{let{target:b,trigger:F}=S,E=(d,R)=>{if(f.has(d)||x.has(d)||G.has(d))return;let g=0,k=I.get(d)??0;if(A.has(d))g=A.get(d)-1;else {if(k>B&&A.size>X){O.has(k)||O.set(k,new Set),O.get(k).add(d),e.emit("node:intercept",{path:d,type:7});return}let U=t.GetPrevDependency(d),N=0;for(let ee of U){if(f.has(ee))continue;(I.get(ee)??0)>B&&N++;}g=N;}if(g<=0){let U=G.has(d),N=x.has(d);if(U||N){e.emit("node:intercept",{path:d,type:N?3:3.1});return}A.delete(d),G.add(d),e.emit("node:release",{path:d,type:R,detail:{path:b}});}else A.set(d,g);},D=()=>{if(n.get(i)!==y)return;C&&l.flushPathSet.add(b),e.emit("node:success",{path:b}),f.add(b);let d=t.GetNextDependency(b);(C||h)&&t.GetAllNextDependency(b).forEach(k=>M.add(k));for(let g of d){if(f.has(g)){e.emit("node:intercept",{path:g,type:2});continue}if(x.has(g)||G.has(g)){e.emit("node:intercept",{path:g,type:x.has(g)?3:3.1});continue}if(C||h)E(g,1);else if(A.has(g))E(g,2);else {let U=I.get(g);O.has(U)||O.set(U,new Set);let N=O.get(U);N.has(g)||(N.add(g),e.emit("node:stagnate",{path:g,type:1}));}}x.delete(b),(async()=>{if(!T){let g=x.size,k=G.size;e.emit("flow:fire",{path:b,type:1,detail:{active:g,pending:k,blocked:A.size}}),m();}})();},V=d=>{e.emit("node:error",{path:b,error:d});let R=Symbol("abort");n.set(i,R),G.clear(),A.clear(),x.clear(),e.callOnError(d),D();},C=false,h=false,P=r.GetRenderSchemaByPath(b),w=[],v=(d,R)=>{let g=false;R==="options"&&(d.some(N=>N.value==P.defaultValue)||(P.defaultValue=void 0,C=true,g=true)),d!==P[R]&&(P[R]=d,C=true,e.emit("node:bucket:success",{path:b,key:R,value:d}),R==="defaultValue"&&(g=true)),P.nodeBucket[R].isForceNotify()&&(h=true),(g||h)&&q(b);};e.emit("node:start",{path:b});try{for(let d in P.nodeBucket){let g=P.nodeBucket[d].evaluate({affectKey:d,triggerPath:F,GetRenderSchemaByPath:r.GetRenderSchemaByPath,GetValueByPath:k=>r.GetRenderSchemaByPath(k).defaultValue,GetToken:()=>y});if(g instanceof Promise){let k=g.then(U=>{n.get(i)===y&&v(U,d);});w.push(k);}else v(g,d);}if(w.length>0)return Promise.all(w).then(()=>{D();}).catch(V);D();return}catch(d){V(d);}},m=async()=>{if(n.get(i)!==y){T=false;return}T=true;let S=a.getIsFirstFrame(),b=0,F=()=>s&&S?30:1/0,E=0,D=F();try{for(;n.get(i)===y;){let V=E>=D,C=a.shouldYield();if(V||C){if(E>0&&(b++,(S||b%2===0)&&l.requestUpdate()),await a.yieldToMain(),n.get(i)!==y)break;E=0,S=a.getIsFirstFrame();}if(G.size>0&&x.size<5){for(let h of G){if(x.size>=5||E>=D)break;let P=I.get(h)??0,w=t.GetPrevDependency(h),v=w.length>1;if((!s||v)&&P>B){G.delete(h);let R=w.filter(g=>M.has(g)&&!f.has(g)).length;A.set(h,R||0),e.emit("node:intercept",{path:h,type:R>0?4:5,detail:{targetLevel:P,currentLevel:B,pendingParentsCount:R}});continue}if(G.delete(h),x.add(h),e.emit("node:processing",{path:h}),J({target:h,trigger:i}),E++,E>=D||a.shouldYield())break}if(G.size>0)continue}if(E<D&&s&&A.size>0&&x.size<5){let h=!1,P=0;for(let[w,v]of A)if(v<=0){let d=I.get(w)??0,R=t.GetPrevDependency(w);if(d>B&&R.length>1)continue;if(A.delete(w),G.add(w),P++,h=!0,e.emit("node:release",{path:w,type:4}),P>=D)break}if(P>0)continue;if(h){if(a.shouldYield()&&(await a.yieldToMain(),n.get(i)!==y))break;continue}}if(x.size===0&&G.size===0){let h=new Set;for(let v of O.keys())h.add(v);for(let[v]of A){let d=I.get(v)??0;d>B&&h.add(d);}let P=Array.from(h).sort((v,d)=>v-d),w=P[0];if(P.length>0&&w<=L){let v=P[0];if(v<=L){B=v;let d=O.get(v);d&&(d.forEach(R=>G.add(R)),O.delete(v));for(let[R]of A)(I.get(R)??0)===v&&(A.delete(R),G.add(R),e.emit("node:release",{path:R,type:3,detail:{level:v}}));continue}}else {O.forEach((v,d)=>{v.forEach(R=>{f.add(R),e.emit("node:intercept",{path:R,type:6});});}),O.clear();for(let[v]of A)f.add(v),e.emit("node:intercept",{path:v,type:6});A.clear();break}}G.size>0&&x.size>=5&&e.emit("flow:wait",{type:2});break}}finally{if(T=false,x.size+A.size+G.size===0){if(n.get(i)===y&&!z){z=true,e.emit("flow:end",{type:1}),l.requestUpdate();let C=performance.now();e.emit("flow:success",{duration:(C-j).toFixed(2)+"ms"}),Promise.resolve().then(()=>{e.callOnSuccess();});}}else e.emit("flow:wait",{type:1,detail:{nums:x.size}});}};m();}}function oe(c,t,r,e,l,n){let s=ve(c),a=0,o=new Map,i=new Map,p=new Map,u=false,y=new Set,T=false,f=true,x=null,M=m=>{let S=o.get(m);return i.get(S)},A=m=>p.get(m),O=async()=>{let m=Array.from(y);y.clear();for(let S of m){let b=M(S);n.signalTrigger(b.dirtySignal);}},G=()=>{u||(u=true,requestAnimationFrame(()=>{try{for(;y.size>0;)O();}finally{u=false;}}));},I=()=>{let m=(S,b,F)=>{if(typeof S!="object"||S===null||Array.isArray(S)){if(F.length>0){let D=F[F.length-1];b[D]=M(F.join(".")).defaultValue;}return}let E=Object.getOwnPropertyNames(S);for(let D of E)F.push(D),m(S[D],S,F),F.pop();};return m(s,null,[]),s},W=ae({useGreedy:t.useGreedy},r,{GetRenderSchemaByPath:M},l,{requestUpdate:G,flushPathSet:y}),B=async()=>(T&&x||(T=true,x=(async()=>{let m=r.GetDependencyOrder(),S=performance.now(),b=performance.now();try{for(let E=0;E<m.length;E++){let D=m[E];await Promise.all(D.map(async V=>{let C=M(V),h=!1;for(let P in C.nodeBucket){let w=await C.nodeBucket[P].evaluate({affectKey:P,triggerPath:void 0,GetRenderSchemaByPath:M,GetValueByPath:v=>M(v).defaultValue,isSameToken:()=>!0});if(P==="options"){let v=!1,d=C.defaultValue;for(let R of w)if(R.value==d){v=!0;break}v||(C.defaultValue=void 0,h=!0);}w!==C[P]&&(C[P]=w,h=!0);}h&&y.add(V);})),performance.now()-b>12&&(await new Promise(V=>requestAnimationFrame(V)),b=performance.now());}y.size>0&&G(),f=!1;let F=performance.now();l.emit("flow:success",{duration:(F-S).toFixed(2)+"ms"}),l.callOnSuccess();}catch(F){throw l.emit("node:error",{path:F.path,error:F.error}),l.callOnError(F),F}finally{T=false,x=null,f=false;}})()),x),L=m=>{if(f)return;if(!M(m))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");performance.now();y.add(m),G();let F=r.GetNextDependency(m);q(F,m);};function q(m,S){W(S,m);}let j=m=>{if(!m)throw Error("\u6CA1\u6709\u8DEF\u5F84");let S=M(m);S.nodeBucket.defaultValue&&S.nodeBucket.defaultValue.updateInputValueRule(S.defaultValue);},z=(m,S="")=>{let b="name"in m?m.name:void 0,F=b?S===""?b:`${S}.${b}`:S,E=n.signalCreateor(),D=a++,V={getRenderSchema:P=>M(P)},C=(P,w)=>{let v=P(w),d=M(w.path),R=e.createHistoryAction([{path:w.path,value:d.defaultValue},{path:w.path,value:v}],g=>{let k=M(g.path);k.defaultValue=g.value,j(g.path),L(g.path);});d.defaultValue=v,e.pushIntoHistory(R),j(w.path),L(w.path);},h={...m,disabled:!!m.disabled,hidden:"hidden"in m?m.hidden:false,readonly:"readonly"in m?m.readonly:false,required:"required"in m?m.required:false,path:F,dirtySignal:E,uid:D,nodeBucket:{},validators:new Z(F),theme:"secondary",dependOn:P=>C(P,{...V,path:F})};return m.type==="group"&&(delete h.nodeBucket,delete h.validators,h.children=m.children.map(P=>z(P,F)),p.set(h.path,h)),o.set(h.path,h.uid),i.set(h.uid,h),h};return {schema:z(c),GetFormData:()=>I(),GetRenderSchemaByPath:M,GetGroupByPath:A,notifyAll:B,convertToRenderSchema:z}}function ve(c,t={}){let r=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((s,a)=>[...s,r(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}`)},e=(n,s)=>{if(s.isGroup){let a={};s.key===""?a=n:n[s.key]=a,s.val.forEach(o=>{e(a,o);});}else n[s.key]=s.val;},l=r(c);return e(t,l),t}var se=(c,t,r)=>{let l=n=>{let s=r.triggerPaths.map(i=>n.GetValueByPath(i)),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>s}),Object.defineProperty(a,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(c)[t]}),r.logic({slot:a})};return {value:r.value,targetPath:c,triggerPaths:r.triggerPaths,priority:r.priority??10,logic:l}},ie=(c,t,r)=>{if(!c)throw Error("");let e=c,l=(a,o)=>{t.has(a)||t.set(a,new Set),t.get(a).add(o),r.has(o)||r.set(o,new Set),r.get(o).add(a);};return {SetRule:(a,o,i,p={logic:u=>{}})=>{let u=e(o),y=se(o,i,{...p,triggerPaths:[a]}),T=[a].map(f=>[f,e(f).defaultValue]);if(l(a,o),u.nodeBucket[i])u.nodeBucket[i].setRule(y,T);else {let f=new Q(u[i],i,o);f.setRule(y,T),u.nodeBucket[i]=f;}p.forceNotify&&u.nodeBucket[i].forceNotify();},SetRules:(a,o,i,p={logic:u=>{}})=>{let u=e(o);for(let f of a)l(f,o);let y=se(o,i,{...p,triggerPaths:a}),T=a.map(f=>[f,e(f).defaultValue]);if(u.nodeBucket[i])u.nodeBucket[i].setRules(y,T);else {let f=new Q(u[i],i,o);f.setRules(y,T),u.nodeBucket[i]=f;}p.forceNotify&&u.nodeBucket[i].forceNotify();}}},le=c=>{let t=c||void 0;if(!t)throw Error("");return {SetStrategy:(e,l,n)=>{t(e).nodeBucket[l].setStrategy(n);}}};var ce=c=>{let t=c||void 0;return {SetValidators:(e,l)=>{let n=t(e),s=(o,i,p)=>o(i,p),a=(o,i,p)=>o(i,p);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:o=>s(l.logic,o,t),condition:typeof l.condition=="function"?o=>a(l.condition,o,t):()=>true});}}};function ue(){let c=new Map,t=new Map,r=new Set,e=(s,a)=>{c.set(s,a);let o=t.get(s);o&&o(a);};return {SetTrace:(s,a)=>{t.set(s,a);let o=c.get(s)||"idle";return a(o),()=>{t.delete(s);}},useTrace:()=>({apply:a=>{a.on("flow:start",()=>{r.forEach(o=>e(o,"idle")),r.clear(),c.clear();}),a.on("node:release",({path:o,type:i})=>{(i==1||i==2)&&(r.add(o),e(o,"pending"));}),a.on("node:pending",({path:o})=>{r.add(o),(!c.has(o)||c.get(o)==="idle")&&e(o,"pending");}),a.on("node:start",({path:o})=>{r.add(o),e(o,"calculating");}),a.on("node:success",({path:o})=>{e(o,"calculated");}),a.on("node:intercept",({path:o,type:i})=>{i==3&&e(o,"calculating"),i==6&&e(o,"idle");}),a.on("node:stagnate",({path:o})=>{e(o,"pending");}),a.on("node:error",({path:o})=>e(o,"error"));}})}}function de(c,t,r,e){let l=p=>{let u=c(),y=t(),T=new Set;return u.get(p)?.forEach(f=>T.add(f)),T.size===0?[]:Array.from(T).filter(f=>{let x=y.get(f)||new Set;return !Array.from(x).some(O=>T.has(O))})};return {GetNextDependency:p=>{let u=e();return Array.from(u.get(p)||[])},GetPrevDependency:p=>{let u=r();return Array.from(u.get(p)||[])},GetAllPrevDependency:p=>{let u=t();return Array.from(u.get(p)||[])},GetAllNextDependency:p=>{let u=c();return Array.from(u.get(p)||[])},rebuildDirectDependencyMaps:p=>{let u=new Map,y=new Map;for(let T of p){let f=l(T);u.set(T,new Set(f));for(let x of f)y.has(x)||y.set(x,new Set),y.get(x).add(T);}return {directNextMap:u,directPrevMap:y}}}}function pe(c){let t=e=>{let l=[],n=[],s=new Map,a=e.size,o=0,i=0;for(let[p,u]of e)u===0&&n.push(p);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;){l.push([...n]);let p=[];for(let u of n){o++,s.set(u,i);let y=c.get(u);if(y)for(let T of y){let f=e.get(T)-1;e.set(T,f),f===0&&p.push(T);}}n=p,i++;}if(o<a)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:l,levelMap:s}};return ()=>{let e=new Map;for(let l of c.keys()){let n=Array.from(c.get(l)||[]);e.has(l)||e.set(l,0);for(let s of n){let a=e.get(s)||0;e.set(s,++a);}}return t(e)}}function ye(){let c=[],t=[],e={canRedo:()=>{},canUndo:()=>{}},l=()=>{if(!c.length)return;let u=c.pop();u?.undoAction(),o(u);},n=()=>{if(!t.length)return;let u=t.pop();u?.redoAction(),i(u,false);},s=u=>{e.canUndo=()=>u(c.length);},a=u=>{e.canRedo=()=>u(t.length);},o=u=>{t.push(u),t.length>100&&t.shift(),e.canRedo(),e.canUndo();},i=(u,y=true)=>{y&&(t.length=0),c.push(u),c.length>100&&c.shift(),e.canUndo(),e.canRedo();};return {Undo:l,Redo:n,PushIntoHistory:i,CreateHistoryAction:(u,y)=>{let[T,f]=u;return {undoAction:()=>y(T),redoAction:()=>y(f)}},initCanUndo:s,initCanRedo:a}}var Y=()=>{let c=[];return {on:t=>(c.push(t),()=>{let r=c.indexOf(t);r>-1&&c.splice(r,1);}),call:t=>c.forEach(r=>r(t))}};function fe(){let{on:c,call:t}=Y();return {onError:c,callOnError:t}}function he(){let{on:c,call:t}=Y();return {onSuccess:c,callOnSuccess:t}}var me=()=>{let c=new Set,t=new Map,r=(n,s)=>{t.get(n)?.forEach(a=>a(s));},e=(n,s)=>(t.has(n)||t.set(n,new Set),t.get(n).add(s),()=>t.get(n).delete(s));return {usePlugin:n=>{let s=new Set,a=(o,i)=>{let p=e(o,i);return s.add(p),p};return n.apply({on:a}),c.add(n),()=>{s.forEach(o=>o()),s.clear(),c.delete(n);}},emit:r}};function ge(){let{on:c,call:t}=Y();return {onStart:c,callOnStart:t}}function Te(c,t,r){let e=false,l=false,n=new Map,s=new Map,a=new Map,o=new Map,i=[],p=new Map,{GetNextDependency:y,GetPrevDependency:T,GetAllPrevDependency:f,GetAllNextDependency:x,rebuildDirectDependencyMaps:M}=de(()=>n,()=>s,()=>o,()=>a),{Undo:A,Redo:O,PushIntoHistory:G,CreateHistoryAction:I,initCanUndo:W,initCanRedo:B}=ye(),{onError:L,callOnError:q}=fe(),{onSuccess:j,callOnSuccess:z}=he(),{onStart:X,callOnStart:J}=ge(),{emit:m,usePlugin:S}=me(),{SetTrace:b,useTrace:F}=ue(),E=F();S(E);let{schema:D,GetFormData:V,GetRenderSchemaByPath:C,GetGroupByPath:h,notifyAll:P,convertToRenderSchema:w}=oe(c,{useGreedy:t.useGreedy},{GetDependencyOrder:()=>i,GetAllNextDependency:x,GetNextDependency:y,GetPrevDependency:T,GetAllPrevDependency:f,GetPathToLevelMap:()=>p},{pushIntoHistory:G,createHistoryAction:I},{callOnError:q,callOnSuccess:z,callOnStart:J,emit:m},r),v=(_,K)=>{let H=h(_),ne=w(K,_);return H.children.push(ne),H.dirtySignal.value++,ne},{SetRule:d,SetRules:R}=ie(C,n,s),{SetStrategy:g}=le(C),{SetValidators:k}=ce(C),U=pe(n),N=()=>{let _=U();i=_.steps,p=_.levelMap;};return {schema:D,SetRule:(..._)=>{d.apply(null,_),e=true,!l&&new Promise((K,H)=>{l=true,K();}).then(()=>{if(N(),e){let{directNextMap:K,directPrevMap:H}=M(i.flat());a=K,o=H;}}).finally(()=>{l=false,e=false;});},SetRules:(..._)=>{R.apply(null,_),e=true,!l&&new Promise((K,H)=>{l=true,K();}).then(()=>{if(N(),e){let{directNextMap:K,directPrevMap:H}=M(i.flat());a=K,o=H;}}).finally(()=>{l=false,e=false;});},SetStrategy:g,SetValidators:k,SetTrace:b,usePlugin:S,SetValue:(_,K)=>{C(_).dependOn(()=>K);},GetValue:(_,K="defaultValue")=>C(_)[K],GetFormData:V,GetGroupByPath:h,notifyAll:async()=>{N(),await P();},AddNewSchema:v,GetAllDependency:()=>n,GetDependencyOrder:()=>i,Undo:A,Redo:O,initCanUndo:W,initCanRedo:B,onError:L,onSuccess:j,onStart:X}}var $=new Map,Re=(c,t,r)=>{try{if(typeof r.UITrigger.signalCreateor!="function"||typeof r.UITrigger.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if($.has(c))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let e=Te(t,r.config||{useGreedy:!1},r.UITrigger),{schema:l,GetFormData:n,SetRule:s,SetRules:a,SetStrategy:o,SetValidators:i,SetValue:p,GetValue:u,usePlugin:y,GetGroupByPath:T,notifyAll:f,SetTrace:x,GetAllDependency:M,GetDependencyOrder:A,AddNewSchema:O,Undo:G,Redo:I,initCanUndo:W,initCanRedo:B,onError:L,onSuccess:q,onStart:j}=e,z={config:{SetRule:s,SetRules:a,SetStrategy:o,SetValidators:i,notifyAll:f,SetTrace:x,usePlugin:y},data:{schema:l,GetFormData:n,AddNewSchema:O,SetValue:p,GetValue:u,GetGroupByPath:T},history:{Undo:G,Redo:I,initCanUndo:W,initCanRedo:B},dependency:{GetAllDependency:M,GetDependencyOrder:A},hooks:{onError:L,onSuccess:q,onStart:j}};return $.set(c,z),z}catch(e){throw Error(e)}},pt=c=>{if($.has(c))return $.get(c);throw Error("\u4E0D\u5B58\u5728\u7684id")},yt=c=>{$.delete(c);},ft=Re;exports.deleteEngine=yt;exports.useEngine=pt;exports.useEngineManager=Re;exports.useMeshFlow=ft;
1
+ 'use strict';var ne=class{computedRules=[];store={OR:(e,n)=>{let t,l,r=this.computedRules;for(let o=0;o<r.length;o++){let a=r[o],s=a.logic(e);if(s instanceof Promise)return (async()=>{let c=await s;if(a.entityId==="__base__"?l=c:c&&(t=c),typeof t>"u")for(let u=o+1;u<r.length;u++){let h=r[u],S=h.logic(e),p=S instanceof Promise?await S:S;if(h.entityId==="__base__"){l=p;continue}if(p){t=h.value;break}}return typeof t>"u"&&(t=l),{res:t,version:n}})();let i=s;if(a.entityId==="__base__"){l=i;continue}if(i){t=a.value;break}}return typeof t>"u"&&(t=l),{res:t,version:n}},PRIORITY:(e,n)=>{let t,l=this.computedRules;for(let r=0;r<l.length;r++){let a=l[r].logic(e);if(a instanceof Promise)return (async()=>{let s=await a;if(s!==void 0)return {res:s,version:n};for(let i=r+1;i<l.length;i++){let c=l[i].logic(e),u=c instanceof Promise?await c:c;if(u!==void 0)return {res:u,version:n}}return {res:void 0,version:n}})();if(a!==void 0)return {res:a,version:n}}return {res:t,version:n}}};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(n=>Array.from(n)).flat().sort((n,t)=>t.priority-n.priority):this.computedRules=Array.from(e.values()).map(n=>Array.from(n)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,n){return this.CurrentStrategy(e,n)}},J=class{path;strategy;contract;rules=new Map;isValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;effectArray=[];constructor(e,n,t){let l=()=>this.rules;this.strategy=new ne(l),this.path=t,this.isValue=n==="value",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);}setDefaultRule(e){let n=new Set;n.add(e),this.rules.set(e.id,n);}setRules(e,n){n&&this.updateDeps(n);let t=++this.id,l={...e,entityId:t};for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(l);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let o=this.rules.get(r);o&&(o.delete(l),o.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[n,t]of e)this.deps.set(n,t);}setRule(e,n){if(n&&this.updateDeps(n),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,l={...e,entityId:t};if(e)for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(l);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let o=this.rules.get(r);o&&(o.delete(l),o.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}setSideEffect(e){this.effectArray.push(e);}getSideEffect(){return [...this.effectArray]}evaluate(e){let n=null;if(e.GetToken&&(n=e.GetToken()),this.pendingPromise&&this.promiseToken!==n&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let t=false;if(typeof e.triggerPath=="string"){t=true;let o=this.deps.get(e.triggerPath),a=e.GetValueByPath(e.triggerPath);if(typeof o=="object"||typeof a=="object")t=false;else {let s=Array.from(this.deps.keys());for(let i of s){let c=this.deps.get(i),u=e.GetValueByPath(i);if(c!==u){t=false;break}}}}if(t)return this.cache;this.promiseToken=n;let l=++this.version,r=this.strategy.evaluate(e,l);if(!(r instanceof Promise)){let{res:o,version:a}=r;return this.finalizeSync(o,a,e,n)}return this.pendingPromise=(async()=>{try{let{res:o,version:a}=await r;return this.finalizeSync(o,a,e,n)}catch(o){throw {path:this.path,error:o}}finally{this.promiseToken===n&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(e,n,t,l){return l!==this.promiseToken||n<this.version?this.cache:(this.cache=e,this.deps.forEach((r,o)=>{this.deps.set(o,t.GetValueByPath(o));}),e)}inferType(e){return Array.isArray(e)?"array":typeof e}},ee=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} undefined`,condition:t=>!!t.required},n={logic:function(t){return t.length>this.options.maxLength?`Too long:${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(n.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(n);}evaluate(e,n){let t=true,l=[...this.defaultValidators,...this.validators];for(let r of l){if(!r.condition(n))continue;let a=r.logic(e);if(typeof a!="boolean"){t=a;break}}return t}};var re=(d={frameQuota:12})=>{let e=performance.now(),n=0,t=false,l=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>t,reset(){e=performance.now(),n=0,t=true;},shouldYield(){let r=performance.now();return n++,!!((n>=5||t)&&(n=0,r-e>d.frameQuota||l()))},async yieldToMain(){return new Promise(r=>{Te(()=>{e=performance.now(),n=0,t&&(t=false),r();});})}}},Te=d=>{let{port1:e,port2:n}=new MessageChannel;e.onmessage=d,n.postMessage(null);};function ae(d,e,n,t,l){let r=new Map,o=d.useGreedy,a=re();return async(i,c)=>{let h=Symbol("token");r.set(i,h);let S=false;a.reset();let p=new Set,T=new Set,N=new Set(e.GetAllNextDependency(i));N.add(i);let M=new Map,D=new Map,F=new Set,V=e.GetPathToLevelMap(),_=V.get(i)??0,H=0,q=G=>{e.GetAllNextDependency(G).forEach(U=>{let R=V.get(U)||0;R>H&&(H=R);});};q(i),c.forEach(G=>{F.add(G);}),p.add(i);let z=performance.now();t.emit("flow:start",{path:i}),t.callOnStart({path:i});let W=false,$=30,g=G=>{let{target:y,trigger:U}=G,R=false,k=false,C=n.GetNodeByPath(y),E=[],P=(f,m)=>{if(p.has(f)||T.has(f)||F.has(f))return;let B=0,v=V.get(f)??0;if(M.has(f))B=M.get(f)-1;else {if(v>_&&M.size>$){D.has(v)||D.set(v,new Set),D.get(v).add(f),t.emit("node:intercept",{path:f,type:7});return}let O=e.GetPrevDependency(f),L=0;for(let K of O){if(p.has(K))continue;(V.get(K)??0)>_&&L++;}B=L;}if(B<=0){let O=F.has(f),L=T.has(f);if(O||L){t.emit("node:intercept",{path:f,type:L?3:3.1});return}M.delete(f),F.add(f),t.emit("node:release",{path:f,type:m,detail:{path:y}});}else M.set(f,B);},b=(f=[])=>{if(r.get(i)!==h)return;if(f.length){let v={};for(let O of f){let L=(O.args||[]).reduce((K,I)=>(K[I]=C[I],K),{});try{let K=O.fn(L);K&&typeof K=="object"&&Object.assign(v,K);}catch(K){}}for(let O in v)C[O]=v[O];R=true;}R&&l.flushPathSet.add(y),t.emit("node:success",{path:y}),p.add(y);let m=e.GetNextDependency(y);(R||k)&&e.GetAllNextDependency(y).forEach(O=>N.add(O));for(let v of m){if(p.has(v)){t.emit("node:intercept",{path:v,type:2});continue}if(T.has(v)||F.has(v)){t.emit("node:intercept",{path:v,type:T.has(v)?3:3.1});continue}if(R||k)P(v,1);else if(M.has(v))P(v,2);else {let L=V.get(v);D.has(L)||D.set(L,new Set);let K=D.get(L);K.has(v)||(K.add(v),t.emit("node:stagnate",{path:v,type:1}));}}T.delete(y),(async()=>{if(!S){let v=T.size,O=F.size;t.emit("flow:fire",{path:y,type:1,detail:{active:v,pending:O,blocked:M.size}}),w();}})();},A=f=>{t.emit("node:error",{path:y,error:f});let m=Symbol("abort");r.set(i,m),F.clear(),M.clear(),T.clear(),t.callOnError(f);},x=(f,m)=>{let B=false;f!==C[m]&&(C[m]=f,R=true,t.emit("node:bucket:success",{path:y,key:m,value:f}),m==="value"&&(B=true)),C.nodeBucket[m].isForceNotify()&&(k=true),(B||k)&&q(y);};t.emit("node:start",{path:y});try{let f=[];for(let m in C.nodeBucket){let B=C.nodeBucket[m];f.push(...B.getSideEffect());let v=B.evaluate({affectKey:m,triggerPath:U,GetRenderSchemaByPath:n.GetNodeByPath,GetValueByPath:O=>n.GetNodeByPath(O).value,GetToken:()=>h});if(v instanceof Promise){let O=v.then(L=>{r.get(i)===h&&x(L,m);});E.push(O);}else x(v,m);}if(E.length>0)return Promise.all(E).then(()=>{b(f);}).catch(A);b(f);return}catch(f){A(f);}},w=async()=>{if(r.get(i)!==h){S=false;return}S=true;let G=a.getIsFirstFrame(),y=0,U=()=>o&&G?30:1/0,R=0,k=U();try{for(;r.get(i)===h;){let C=R>=k,E=a.shouldYield();if(C||E){if(R>0&&(y++,(G||y%2===0)&&l.requestUpdate()),await a.yieldToMain(),r.get(i)!==h)break;R=0,G=a.getIsFirstFrame();}if(F.size>0&&T.size<5){for(let P of F){if(T.size>=5||R>=k)break;let b=V.get(P)??0,A=e.GetPrevDependency(P),x=A.length>1;if((!o||x)&&b>_){F.delete(P);let m=A.filter(B=>N.has(B)&&!p.has(B)).length;M.set(P,m||0),t.emit("node:intercept",{path:P,type:m>0?4:5,detail:{targetLevel:b,currentLevel:_,pendingParentsCount:m}});continue}if(F.delete(P),T.add(P),t.emit("node:processing",{path:P}),g({target:P,trigger:i}),R++,R>=k||a.shouldYield())break}if(F.size>0)continue}if(R<k&&o&&M.size>0&&T.size<5){let P=!1,b=0;for(let[A,x]of M)if(x<=0){let f=V.get(A)??0,m=e.GetPrevDependency(A);if(f>_&&m.length>1)continue;if(M.delete(A),F.add(A),b++,P=!0,t.emit("node:release",{path:A,type:4}),b>=k)break}if(b>0)continue;if(P){if(a.shouldYield()&&(await a.yieldToMain(),r.get(i)!==h))break;continue}}if(T.size===0&&F.size===0){let P=new Set;for(let x of D.keys())P.add(x);for(let[x]of M){let f=V.get(x)??0;f>_&&P.add(f);}let b=Array.from(P).sort((x,f)=>x-f),A=b[0];if(b.length>0&&A<=H){let x=b[0];if(x<=H){_=x;let f=D.get(x);f&&(f.forEach(m=>F.add(m)),D.delete(x));for(let[m]of M)(V.get(m)??0)===x&&(M.delete(m),F.add(m),t.emit("node:release",{path:m,type:3,detail:{level:x}}));continue}}else {D.forEach((x,f)=>{x.forEach(m=>{p.add(m),t.emit("node:intercept",{path:m,type:6});});}),D.clear();for(let[x]of M)p.add(x),t.emit("node:intercept",{path:x,type:6});M.clear();break}}F.size>0&&T.size>=5&&t.emit("flow:wait",{type:2});break}}finally{if(S=false,T.size+M.size+F.size===0){if(r.get(i)===h&&!W){W=true,t.emit("flow:end",{type:1}),l.requestUpdate();let E=performance.now();t.emit("flow:success",{duration:(E-z).toFixed(2)+"ms"}),Promise.resolve().then(()=>{t.callOnSuccess();});}}else t.emit("flow:wait",{type:1,detail:{nums:T.size}});}};w();}}function se(d,e,n,t,l,r){let o=xe(d),a=0,s=new Map,i=new Map,c=new Map,u=false,h=new Set,S=false,p=true,T=null,N=g=>{let w=s.get(g);return i.get(w)},M=g=>c.get(g),D=async()=>{let g=Array.from(h);h.clear();for(let w of g){let G=N(w);r.signalTrigger(G.dirtySignal);}},F=()=>{u||(u=true,requestAnimationFrame(()=>{try{for(;h.size>0;)D();}finally{u=false;}}));},V=()=>{let g=(w,G,y)=>{if(typeof w!="object"||w===null||Array.isArray(w)){if(y.length>0){let R=y[y.length-1];G[R]=N(y.join(".")).value;}return}let U=Object.getOwnPropertyNames(w);for(let R of U)y.push(R),g(w[R],w,y),y.pop();};return g(o,null,[]),o},Y=ae({useGreedy:e.useGreedy},n,{GetNodeByPath:N},l,{requestUpdate:F,flushPathSet:h}),_=async()=>(S&&T||(S=true,T=(async()=>{let g=n.GetDependencyOrder(),w=performance.now(),G=performance.now();try{for(let U=0;U<g.length;U++){let R=g[U];await Promise.all(R.map(async k=>{let C=N(k),E=!1;for(let P in C.nodeBucket){let b=await C.nodeBucket[P].evaluate({affectKey:P,triggerPath:void 0,GetRenderSchemaByPath:N,GetValueByPath:A=>N(A).value,isSameToken:()=>!0});if(P==="options"){let A=!1,x=C.value;for(let f of b)if(f.value==x){A=!0;break}A||(C.value=void 0,E=!0);}b!==C[P]&&(C[P]=b,E=!0);}E&&h.add(k);})),performance.now()-G>12&&(await new Promise(k=>requestAnimationFrame(k)),G=performance.now());}h.size>0&&F(),p=!1;let y=performance.now();l.emit("flow:success",{duration:(y-w).toFixed(2)+"ms"}),l.callOnSuccess();}catch(y){throw l.emit("node:error",{path:y.path,error:y.error}),l.callOnError(y),y}finally{S=false,T=null,p=false;}})()),T),H=g=>{if(p)return;if(!N(g))throw Error("Node undefined");performance.now();h.add(g),F();let y=n.GetNextDependency(g);q(y,g);};function q(g,w){Y(w,g);}let z=(g,w="")=>{let G="name"in g?g.name:void 0,y=G?w===""?G:`${w}.${G}`:w,U=r.signalCreateor(),R=a++,k={getRenderSchema:P=>N(P)},C=(P,b)=>{let A=P(b),x=N(b.path),f=t.createHistoryAction([{path:b.path,value:x.value},{path:b.path,value:A}],m=>{let B=N(m.path);B.value=m.value,H(m.path);});x.value=A,t.pushIntoHistory(f),H(b.path);},E={...g,disabled:!!g.disabled,hidden:"hidden"in g?g.hidden:false,readonly:"readonly"in g?g.readonly:false,required:"required"in g?g.required:false,path:y,dirtySignal:U,uid:R,nodeBucket:{},validators:new ee(y),theme:"secondary",dependOn:P=>C(P,{...k,path:y})};return g.type==="group"&&(delete E.nodeBucket,delete E.validators,E.children=g.children.map(P=>z(P,y)),c.set(E.path,E)),s.set(E.path,E.uid),i.set(E.uid,E),E};return {schema:z(d),GetFormData:()=>V(),GetRenderSchemaByPath:N,GetGroupByPath:M,notifyAll:_,convertToRenderSchema:z}}function xe(d,e={}){let n=r=>{if(r.type=="group")return {key:r.name||"",isGroup:true,val:r.children.reduce((o,a)=>[...o,n(a)],[])};if(r.type=="input"||r.type=="number"||r.type=="select"||r.type=="checkbox")return {key:r.name,isGroup:false,val:r.value};throw Error(`undefined type:${r.type}`)},t=(r,o)=>{if(o.isGroup){let a={};o.key===""?a=r:r[o.key]=a,o.val.forEach(s=>{t(a,s);});}else r[o.key]=o.val;},l=n(d);return t(e,l),e}var oe=(d,e,n)=>{let l=r=>{let o=n.triggerPaths.map(i=>r.GetValueByPath(i)),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>o}),Object.defineProperty(a,"affectedTatget",{get:()=>r.GetRenderSchemaByPath(d)[e]}),n.logic({slot:a})};return {value:n.value,targetPath:d,triggerPaths:n.triggerPaths,priority:n.priority??10,logic:l}},ie=(d,e,n)=>{if(!d)throw Error("");let t=d,l=(a,s)=>{e.has(a)||e.set(a,new Set),e.get(a).add(s),n.has(s)||n.set(s,new Set),n.get(s).add(a);};return {SetRule:(a,s,i,c={logic:u=>{}})=>{let u=t(s),h=oe(s,i,{...c,triggerPaths:[a]}),S=[a].map(p=>[p,t(p).value]);if(l(a,s),u.nodeBucket[i])u.nodeBucket[i].setRule(h,S),c.effect&&u.nodeBucket[i].setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]});else {let p=new J(u[i],i,s);p.setRule(h,S),c.effect&&p.setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]}),u.nodeBucket[i]=p;}c.forceNotify&&u.nodeBucket[i].forceNotify();},SetRules:(a,s,i,c={logic:u=>{}})=>{let u=t(s);for(let p of a)l(p,s);let h=oe(s,i,{...c,triggerPaths:a}),S=a.map(p=>[p,t(p).value]);if(u.nodeBucket[i])u.nodeBucket[i].setRules(h,S),c.effect&&u.nodeBucket[i].setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]});else {let p=new J(u[i],i,s);p.setRules(h,S),c.effect&&p.setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]}),u.nodeBucket[i]=p;}c.forceNotify&&u.nodeBucket[i].forceNotify();}}};var le=d=>{let e=d||void 0;if(!e)throw Error("");return {SetStrategy:(t,l,r)=>{e(t).nodeBucket[l].setStrategy(r);}}};var ce=d=>{let e=d||void 0;return {SetValidators:(t,l)=>{let r=e(t),o=(s,i,c)=>s(i,c),a=(s,i,c)=>s(i,c);if(!r.validators)throw Error("validator init error");r.validators.setValidators({logic:s=>o(l.logic,s,e),condition:typeof l.condition=="function"?s=>a(l.condition,s,e):()=>true});}}};function de(){let d=new Map,e=new Map,n=new Set,t=(o,a)=>{d.set(o,a);let s=e.get(o);s&&s(a);};return {SetTrace:(o,a)=>{e.set(o,a);let s=d.get(o)||"idle";return a(s),()=>{e.delete(o);}},useTrace:()=>({apply:a=>{a.on("flow:start",()=>{n.forEach(s=>t(s,"idle")),n.clear(),d.clear();}),a.on("node:release",({path:s,type:i})=>{(i==1||i==2)&&(n.add(s),t(s,"pending"));}),a.on("node:pending",({path:s})=>{n.add(s),(!d.has(s)||d.get(s)==="idle")&&t(s,"pending");}),a.on("node:start",({path:s})=>{n.add(s),t(s,"calculating");}),a.on("node:success",({path:s})=>{t(s,"calculated");}),a.on("node:intercept",({path:s,type:i})=>{i==3&&t(s,"calculating"),i==6&&t(s,"idle");}),a.on("node:stagnate",({path:s})=>{t(s,"pending");}),a.on("node:error",({path:s})=>t(s,"error"));}})}}function ue(d,e,n,t){let l=c=>{let u=d(),h=e(),S=new Set;return u.get(c)?.forEach(p=>S.add(p)),S.size===0?[]:Array.from(S).filter(p=>{let T=h.get(p)||new Set;return !Array.from(T).some(D=>S.has(D))})};return {GetNextDependency:c=>{let u=t();return Array.from(u.get(c)||[])},GetPrevDependency:c=>{let u=n();return Array.from(u.get(c)||[])},GetAllPrevDependency:c=>{let u=e();return Array.from(u.get(c)||[])},GetAllNextDependency:c=>{let u=d();return Array.from(u.get(c)||[])},rebuildDirectDependencyMaps:c=>{let u=new Map,h=new Map;for(let S of c){let p=l(S);u.set(S,new Set(p));for(let T of p)h.has(T)||h.set(T,new Set),h.get(T).add(S);}return {directNextMap:u,directPrevMap:h}}}}function fe(d){let e=t=>{let l=[],r=[],o=new Map,a=t.size,s=0,i=0;for(let[c,u]of t)u===0&&r.push(c);if(r.length===0&&a>0)throw Error("Circular dependency detected");for(;r.length>0;){l.push([...r]);let c=[];for(let u of r){s++,o.set(u,i);let h=d.get(u);if(h)for(let S of h){let p=t.get(S)-1;t.set(S,p),p===0&&c.push(S);}}r=c,i++;}if(s<a)throw Error("Circular dependency detected");return {steps:l,levelMap:o}};return ()=>{let t=new Map;for(let l of d.keys()){let r=Array.from(d.get(l)||[]);t.has(l)||t.set(l,0);for(let o of r){let a=t.get(o)||0;t.set(o,++a);}}return e(t)}}var X=()=>{let d=[];return {on:e=>(d.push(e),()=>{let n=d.indexOf(e);n>-1&&d.splice(n,1);}),call:e=>d.forEach(n=>n(e))}};function pe(){let{on:d,call:e}=X();return {onError:d,callOnError:e}}function ye(){let{on:d,call:e}=X();return {onSuccess:d,callOnSuccess:e}}var he=()=>{let d=new Set,e=new Map,n=(r,o)=>{e.get(r)?.forEach(a=>a(o));},t=(r,o)=>(e.has(r)||e.set(r,new Set),e.get(r).add(o),()=>e.get(r).delete(o));return {usePlugin:r=>{let o=new Set,a=(s,i)=>{let c=t(s,i);return o.add(c),c};return r.apply({on:a}),d.add(r),()=>{o.forEach(s=>s()),o.clear(),d.delete(r);}},emit:n}};function me(){let{on:d,call:e}=X();return {onStart:d,callOnStart:e}}function ge(d,e){let n=false,t=false,l=new Map,r=new Map,o=new Map,a=new Map,s=[],i=new Map,{GetNextDependency:u,GetPrevDependency:h,GetAllPrevDependency:S,GetAllNextDependency:p,rebuildDirectDependencyMaps:T}=ue(()=>l,()=>r,()=>a,()=>o),N={},M={};if(e.modules.useHistory){let{Undo:I,Redo:j,PushIntoHistory:Q,CreateHistoryAction:Z,initCanUndo:Pe,initCanRedo:Se}=e.modules.useHistory();N.pushIntoHistory=Q,N.createHistoryAction=Z,M={Undo:I,Redo:j,initCanUndo:Pe,initCanRedo:Se};}let{onError:D,callOnError:F}=pe(),{onSuccess:V,callOnSuccess:Y}=ye(),{onStart:_,callOnStart:H}=me(),{emit:q,usePlugin:z}=he(),{SetTrace:W,useTrace:$}=de(),g=$();z(g);let{schema:w,GetFormData:G,GetRenderSchemaByPath:y,GetGroupByPath:U,notifyAll:R,convertToRenderSchema:k}=se(d,{useGreedy:e.config.useGreedy},{GetDependencyOrder:()=>s,GetAllNextDependency:p,GetNextDependency:u,GetPrevDependency:h,GetAllPrevDependency:S,GetPathToLevelMap:()=>i},N,{callOnError:F,callOnSuccess:Y,callOnStart:H,emit:q},e.UITrigger),C=(I,j)=>{let Q=U(I),Z=k(j,I);return Q.children.push(Z),Q.dirtySignal.value++,Z},{SetRule:E,SetRules:P}=ie(y,l,r),{SetStrategy:b}=le(y),{SetValidators:A}=ce(y),x=fe(l),f=()=>{let I=x();s=I.steps,i=I.levelMap;},m=()=>{t||(t=true,Promise.resolve().then(()=>{if(f(),n){let{directNextMap:I,directPrevMap:j}=T(s.flat());o=I,a=j;}}).finally(()=>{t=false,n=false;}));};return {schema:w,SetRule:(...I)=>{E.apply(null,I),n=true,m();},SetRules:(...I)=>{P.apply(null,I),n=true,m();},SetStrategy:b,SetValidators:A,SetTrace:W,usePlugin:z,SetValue:(I,j)=>{y(I).dependOn(()=>j);},GetValue:(I,j="value")=>y(I)[j],GetFormData:G,GetGroupByPath:U,notifyAll:async()=>{f(),await R();},AddNewSchema:C,GetAllDependency:()=>l,GetDependencyOrder:()=>s,historyExports:M,onError:D,onSuccess:V,onStart:_}}var te=new Map,ve=(d,e,n)=>{try{if(typeof n.UITrigger.signalCreateor!="function"||typeof n.UITrigger.signalTrigger!="function")throw Error("ui trigger undefined");if(te.has(d))throw Error("engineID repeated");let t=ge(e,{config:n.config||{useGreedy:!1},UITrigger:n.UITrigger,modules:n.modules||{},plugins:{}}),{schema:l,GetFormData:r,SetRule:o,SetRules:a,SetStrategy:s,SetValidators:i,SetValue:c,GetValue:u,usePlugin:h,GetGroupByPath:S,notifyAll:p,SetTrace:T,GetAllDependency:N,GetDependencyOrder:M,AddNewSchema:D,historyExports:F,onError:V,onSuccess:Y,onStart:_}=t,q={...{config:{SetRule:o,SetRules:a,SetStrategy:s,SetValidators:i,notifyAll:p,SetTrace:T,usePlugin:h},data:{schema:l,GetFormData:r,AddNewSchema:D,SetValue:c,GetValue:u,GetGroupByPath:S},dependency:{GetAllDependency:N,GetDependencyOrder:M},hooks:{onError:V,onSuccess:Y,onStart:_}}},z=n.modules;return z&&Object.keys(z).forEach(W=>{let $=W;if($.startsWith("use")){let g=$.slice(3);$=g.charAt(0).toLowerCase()+g.slice(1);}W==="useHistory"&&F&&Object.keys(F).length>0&&(q[$]=F);}),te.set(d,q),q}catch(t){throw Error(t)}},dt=()=>(d,e,n)=>Fe(d,e,n),ut=d=>{let e=te.get(d);if(e)return e;throw Error("[MeshFlow] Engine ID not found.")},ft=d=>{te.delete(d);},Fe=ve;exports.deleteEngine=ft;exports.useEngine=ut;exports.useEngineManager=ve;exports.useMeshFlow=Fe;exports.useMeshFlowDefiner=dt;
package/index.mjs CHANGED
@@ -1 +1 @@
1
- var te=class{computedRules=[];store={OR:(t,r)=>{let e,l,n=this.computedRules;for(let s=0;s<n.length;s++){let a=n[s],o=a.logic(t);if(o instanceof Promise)return (async()=>{let p=await o;if(a.entityId==="__base__"?l=p:p&&(e=a.value),typeof e>"u")for(let u=s+1;u<n.length;u++){let y=n[u],T=y.logic(t),f=T instanceof Promise?await T:T;if(y.entityId==="__base__"){l=f;continue}if(f){e=y.value;break}}return typeof e>"u"&&(e=l),{res:e,version:r}})();let i=o;if(a.entityId==="__base__"){l=i;continue}if(i){e=a.value;break}}return typeof e>"u"&&(e=l),{res:e,version:r}},PRIORITY:(t,r)=>{let e=null,l=this.computedRules;for(let n=0;n<l.length;n++){let a=l[n].logic(t);if(a instanceof Promise)return (async()=>{let o=await a;if(o!==void 0)return {res:o,version:r};for(let i=n+1;i<l.length;i++){let p=l[i].logic(t),u=p instanceof Promise?await p:p;if(u!==void 0)return {res:u,version:r}}return {res:void 0,version:r}})();if(a!==void 0)return {res:a,version:r}}return {res:e,version:r}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(t){this.getRules=t,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let t=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(t.values()).map(r=>Array.from(r)).flat().sort((r,e)=>e.priority-r.priority):this.computedRules=Array.from(t.values()).map(r=>Array.from(r)).flat();}setStrategy(t){this.CurrentStrategy=this.store[t],this.updateComputedRules();}evaluate(t,r){return this.CurrentStrategy(t,r)}},Q=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(t,r,e){let l=()=>this.rules;this.strategy=new te(l),this.path=e,this.isDefaultValue=r==="defaultValue",this.contract=this.inferType(t),this.cache=t,this.setRule({priority:0,entityId:"__base__",logic:()=>t});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(t){this.strategy.setStrategy(t);}updateInputValueRule(t){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>t});}setDefaultRule(t){let r=new Set;r.add(t),this.rules.set(t.id,r);}setRules(t,r){r&&this.updateDeps(r);let e=++this.id,l={...t,entityId:e};for(let n of t.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(l);return this.strategy.updateComputedRules(),()=>{for(let n of t.triggerPaths){let s=this.rules.get(n);s&&(s.delete(l),s.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(t){for(let[r,e]of t)this.deps.set(r,e);}setRule(t,r){if(r&&this.updateDeps(r),typeof t.entityId=="string"){this.setDefaultRule(t);return}let e=++this.id,l={...t,entityId:e};if(t)for(let n of t.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(l);return this.strategy.updateComputedRules(),()=>{for(let n of t.triggerPaths){let s=this.rules.get(n);s&&(s.delete(l),s.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}evaluate(t){let r=null;if(t.GetToken&&(r=t.GetToken()),this.pendingPromise&&this.promiseToken!==r&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let e=false;if(typeof t.triggerPath=="string"){e=true;let s=this.deps.get(t.triggerPath),a=t.GetValueByPath(t.triggerPath);if(typeof s=="object"||typeof a=="object")e=false;else {let o=Array.from(this.deps.keys());for(let i of o){let p=this.deps.get(i),u=t.GetValueByPath(i);if(p!==u){e=false;break}}}}if(e)return this.cache;this.promiseToken=r;let l=++this.version,n=this.strategy.evaluate(t,l);if(!(n instanceof Promise)){let{res:s,version:a}=n;return this.finalizeSync(s,a,t,r)}return this.pendingPromise=(async()=>{try{let{res:s,version:a}=await n;return this.finalizeSync(s,a,t,r)}catch(s){throw {path:this.path,error:s}}finally{this.promiseToken===r&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(t,r,e,l){return l!==this.promiseToken||r<this.version?this.cache:(this.cache=t,this.deps.forEach((n,s)=>{this.deps.set(s,e.GetValueByPath(s));}),t)}inferType(t){return Array.isArray(t)?"array":typeof t}},Z=class{validators=[];defaultValidators=[];path="";constructor(t){this.path=t,this.SetDefaultValidators();}setValidators(t){this.validators.push(t);}SetDefaultValidators(){let t={logic:e=>e||typeof e=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:e=>!!e.required},r={logic:function(e){return e.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(e){return typeof e.maxLength!="number"?false:(r.options={maxLength:e.maxLength},e.type==="input"&&e.hidden===false)},options:{}};this.defaultValidators.push(t),this.defaultValidators.push(r);}evaluate(t,r){let e=true,l=[...this.defaultValidators,...this.validators];for(let n of l){if(!n.condition(r))continue;let a=n.logic(t);if(typeof a!="boolean"){e=a;break}}return e}};var re=(c={frameQuota:12})=>{let t=performance.now(),r=0,e=false,l=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>e,reset(){t=performance.now(),r=0,e=true;},shouldYield(){let n=performance.now();return r++,!!((r>=5||e)&&(r=0,n-t>c.frameQuota||l()))},async yieldToMain(){return new Promise(n=>{Pe(()=>{t=performance.now(),r=0,e&&(e=false),n();});})}}},Pe=c=>{let{port1:t,port2:r}=new MessageChannel;t.onmessage=c,r.postMessage(null);};function ae(c,t,r,e,l){let n=new Map,s=c.useGreedy,a=re();return async(i,p)=>{let y=Symbol("token");n.set(i,y);let T=false;a.reset();let f=new Set,x=new Set,M=new Set(t.GetAllNextDependency(i));M.add(i);let A=new Map,O=new Map,G=new Set,I=t.GetPathToLevelMap(),B=I.get(i)??0,L=0,q=S=>{t.GetAllNextDependency(S).forEach(F=>{let E=I.get(F)||0;E>L&&(L=E);});};q(i),p.forEach(S=>{G.add(S);}),f.add(i);let j=performance.now();e.emit("flow:start",{path:i}),e.callOnStart({path:i});let z=false,X=30,J=S=>{let{target:b,trigger:F}=S,E=(d,R)=>{if(f.has(d)||x.has(d)||G.has(d))return;let g=0,k=I.get(d)??0;if(A.has(d))g=A.get(d)-1;else {if(k>B&&A.size>X){O.has(k)||O.set(k,new Set),O.get(k).add(d),e.emit("node:intercept",{path:d,type:7});return}let U=t.GetPrevDependency(d),N=0;for(let ee of U){if(f.has(ee))continue;(I.get(ee)??0)>B&&N++;}g=N;}if(g<=0){let U=G.has(d),N=x.has(d);if(U||N){e.emit("node:intercept",{path:d,type:N?3:3.1});return}A.delete(d),G.add(d),e.emit("node:release",{path:d,type:R,detail:{path:b}});}else A.set(d,g);},D=()=>{if(n.get(i)!==y)return;C&&l.flushPathSet.add(b),e.emit("node:success",{path:b}),f.add(b);let d=t.GetNextDependency(b);(C||h)&&t.GetAllNextDependency(b).forEach(k=>M.add(k));for(let g of d){if(f.has(g)){e.emit("node:intercept",{path:g,type:2});continue}if(x.has(g)||G.has(g)){e.emit("node:intercept",{path:g,type:x.has(g)?3:3.1});continue}if(C||h)E(g,1);else if(A.has(g))E(g,2);else {let U=I.get(g);O.has(U)||O.set(U,new Set);let N=O.get(U);N.has(g)||(N.add(g),e.emit("node:stagnate",{path:g,type:1}));}}x.delete(b),(async()=>{if(!T){let g=x.size,k=G.size;e.emit("flow:fire",{path:b,type:1,detail:{active:g,pending:k,blocked:A.size}}),m();}})();},V=d=>{e.emit("node:error",{path:b,error:d});let R=Symbol("abort");n.set(i,R),G.clear(),A.clear(),x.clear(),e.callOnError(d),D();},C=false,h=false,P=r.GetRenderSchemaByPath(b),w=[],v=(d,R)=>{let g=false;R==="options"&&(d.some(N=>N.value==P.defaultValue)||(P.defaultValue=void 0,C=true,g=true)),d!==P[R]&&(P[R]=d,C=true,e.emit("node:bucket:success",{path:b,key:R,value:d}),R==="defaultValue"&&(g=true)),P.nodeBucket[R].isForceNotify()&&(h=true),(g||h)&&q(b);};e.emit("node:start",{path:b});try{for(let d in P.nodeBucket){let g=P.nodeBucket[d].evaluate({affectKey:d,triggerPath:F,GetRenderSchemaByPath:r.GetRenderSchemaByPath,GetValueByPath:k=>r.GetRenderSchemaByPath(k).defaultValue,GetToken:()=>y});if(g instanceof Promise){let k=g.then(U=>{n.get(i)===y&&v(U,d);});w.push(k);}else v(g,d);}if(w.length>0)return Promise.all(w).then(()=>{D();}).catch(V);D();return}catch(d){V(d);}},m=async()=>{if(n.get(i)!==y){T=false;return}T=true;let S=a.getIsFirstFrame(),b=0,F=()=>s&&S?30:1/0,E=0,D=F();try{for(;n.get(i)===y;){let V=E>=D,C=a.shouldYield();if(V||C){if(E>0&&(b++,(S||b%2===0)&&l.requestUpdate()),await a.yieldToMain(),n.get(i)!==y)break;E=0,S=a.getIsFirstFrame();}if(G.size>0&&x.size<5){for(let h of G){if(x.size>=5||E>=D)break;let P=I.get(h)??0,w=t.GetPrevDependency(h),v=w.length>1;if((!s||v)&&P>B){G.delete(h);let R=w.filter(g=>M.has(g)&&!f.has(g)).length;A.set(h,R||0),e.emit("node:intercept",{path:h,type:R>0?4:5,detail:{targetLevel:P,currentLevel:B,pendingParentsCount:R}});continue}if(G.delete(h),x.add(h),e.emit("node:processing",{path:h}),J({target:h,trigger:i}),E++,E>=D||a.shouldYield())break}if(G.size>0)continue}if(E<D&&s&&A.size>0&&x.size<5){let h=!1,P=0;for(let[w,v]of A)if(v<=0){let d=I.get(w)??0,R=t.GetPrevDependency(w);if(d>B&&R.length>1)continue;if(A.delete(w),G.add(w),P++,h=!0,e.emit("node:release",{path:w,type:4}),P>=D)break}if(P>0)continue;if(h){if(a.shouldYield()&&(await a.yieldToMain(),n.get(i)!==y))break;continue}}if(x.size===0&&G.size===0){let h=new Set;for(let v of O.keys())h.add(v);for(let[v]of A){let d=I.get(v)??0;d>B&&h.add(d);}let P=Array.from(h).sort((v,d)=>v-d),w=P[0];if(P.length>0&&w<=L){let v=P[0];if(v<=L){B=v;let d=O.get(v);d&&(d.forEach(R=>G.add(R)),O.delete(v));for(let[R]of A)(I.get(R)??0)===v&&(A.delete(R),G.add(R),e.emit("node:release",{path:R,type:3,detail:{level:v}}));continue}}else {O.forEach((v,d)=>{v.forEach(R=>{f.add(R),e.emit("node:intercept",{path:R,type:6});});}),O.clear();for(let[v]of A)f.add(v),e.emit("node:intercept",{path:v,type:6});A.clear();break}}G.size>0&&x.size>=5&&e.emit("flow:wait",{type:2});break}}finally{if(T=false,x.size+A.size+G.size===0){if(n.get(i)===y&&!z){z=true,e.emit("flow:end",{type:1}),l.requestUpdate();let C=performance.now();e.emit("flow:success",{duration:(C-j).toFixed(2)+"ms"}),Promise.resolve().then(()=>{e.callOnSuccess();});}}else e.emit("flow:wait",{type:1,detail:{nums:x.size}});}};m();}}function oe(c,t,r,e,l,n){let s=ve(c),a=0,o=new Map,i=new Map,p=new Map,u=false,y=new Set,T=false,f=true,x=null,M=m=>{let S=o.get(m);return i.get(S)},A=m=>p.get(m),O=async()=>{let m=Array.from(y);y.clear();for(let S of m){let b=M(S);n.signalTrigger(b.dirtySignal);}},G=()=>{u||(u=true,requestAnimationFrame(()=>{try{for(;y.size>0;)O();}finally{u=false;}}));},I=()=>{let m=(S,b,F)=>{if(typeof S!="object"||S===null||Array.isArray(S)){if(F.length>0){let D=F[F.length-1];b[D]=M(F.join(".")).defaultValue;}return}let E=Object.getOwnPropertyNames(S);for(let D of E)F.push(D),m(S[D],S,F),F.pop();};return m(s,null,[]),s},W=ae({useGreedy:t.useGreedy},r,{GetRenderSchemaByPath:M},l,{requestUpdate:G,flushPathSet:y}),B=async()=>(T&&x||(T=true,x=(async()=>{let m=r.GetDependencyOrder(),S=performance.now(),b=performance.now();try{for(let E=0;E<m.length;E++){let D=m[E];await Promise.all(D.map(async V=>{let C=M(V),h=!1;for(let P in C.nodeBucket){let w=await C.nodeBucket[P].evaluate({affectKey:P,triggerPath:void 0,GetRenderSchemaByPath:M,GetValueByPath:v=>M(v).defaultValue,isSameToken:()=>!0});if(P==="options"){let v=!1,d=C.defaultValue;for(let R of w)if(R.value==d){v=!0;break}v||(C.defaultValue=void 0,h=!0);}w!==C[P]&&(C[P]=w,h=!0);}h&&y.add(V);})),performance.now()-b>12&&(await new Promise(V=>requestAnimationFrame(V)),b=performance.now());}y.size>0&&G(),f=!1;let F=performance.now();l.emit("flow:success",{duration:(F-S).toFixed(2)+"ms"}),l.callOnSuccess();}catch(F){throw l.emit("node:error",{path:F.path,error:F.error}),l.callOnError(F),F}finally{T=false,x=null,f=false;}})()),x),L=m=>{if(f)return;if(!M(m))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");performance.now();y.add(m),G();let F=r.GetNextDependency(m);q(F,m);};function q(m,S){W(S,m);}let j=m=>{if(!m)throw Error("\u6CA1\u6709\u8DEF\u5F84");let S=M(m);S.nodeBucket.defaultValue&&S.nodeBucket.defaultValue.updateInputValueRule(S.defaultValue);},z=(m,S="")=>{let b="name"in m?m.name:void 0,F=b?S===""?b:`${S}.${b}`:S,E=n.signalCreateor(),D=a++,V={getRenderSchema:P=>M(P)},C=(P,w)=>{let v=P(w),d=M(w.path),R=e.createHistoryAction([{path:w.path,value:d.defaultValue},{path:w.path,value:v}],g=>{let k=M(g.path);k.defaultValue=g.value,j(g.path),L(g.path);});d.defaultValue=v,e.pushIntoHistory(R),j(w.path),L(w.path);},h={...m,disabled:!!m.disabled,hidden:"hidden"in m?m.hidden:false,readonly:"readonly"in m?m.readonly:false,required:"required"in m?m.required:false,path:F,dirtySignal:E,uid:D,nodeBucket:{},validators:new Z(F),theme:"secondary",dependOn:P=>C(P,{...V,path:F})};return m.type==="group"&&(delete h.nodeBucket,delete h.validators,h.children=m.children.map(P=>z(P,F)),p.set(h.path,h)),o.set(h.path,h.uid),i.set(h.uid,h),h};return {schema:z(c),GetFormData:()=>I(),GetRenderSchemaByPath:M,GetGroupByPath:A,notifyAll:B,convertToRenderSchema:z}}function ve(c,t={}){let r=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((s,a)=>[...s,r(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}`)},e=(n,s)=>{if(s.isGroup){let a={};s.key===""?a=n:n[s.key]=a,s.val.forEach(o=>{e(a,o);});}else n[s.key]=s.val;},l=r(c);return e(t,l),t}var se=(c,t,r)=>{let l=n=>{let s=r.triggerPaths.map(i=>n.GetValueByPath(i)),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>s}),Object.defineProperty(a,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(c)[t]}),r.logic({slot:a})};return {value:r.value,targetPath:c,triggerPaths:r.triggerPaths,priority:r.priority??10,logic:l}},ie=(c,t,r)=>{if(!c)throw Error("");let e=c,l=(a,o)=>{t.has(a)||t.set(a,new Set),t.get(a).add(o),r.has(o)||r.set(o,new Set),r.get(o).add(a);};return {SetRule:(a,o,i,p={logic:u=>{}})=>{let u=e(o),y=se(o,i,{...p,triggerPaths:[a]}),T=[a].map(f=>[f,e(f).defaultValue]);if(l(a,o),u.nodeBucket[i])u.nodeBucket[i].setRule(y,T);else {let f=new Q(u[i],i,o);f.setRule(y,T),u.nodeBucket[i]=f;}p.forceNotify&&u.nodeBucket[i].forceNotify();},SetRules:(a,o,i,p={logic:u=>{}})=>{let u=e(o);for(let f of a)l(f,o);let y=se(o,i,{...p,triggerPaths:a}),T=a.map(f=>[f,e(f).defaultValue]);if(u.nodeBucket[i])u.nodeBucket[i].setRules(y,T);else {let f=new Q(u[i],i,o);f.setRules(y,T),u.nodeBucket[i]=f;}p.forceNotify&&u.nodeBucket[i].forceNotify();}}},le=c=>{let t=c||void 0;if(!t)throw Error("");return {SetStrategy:(e,l,n)=>{t(e).nodeBucket[l].setStrategy(n);}}};var ce=c=>{let t=c||void 0;return {SetValidators:(e,l)=>{let n=t(e),s=(o,i,p)=>o(i,p),a=(o,i,p)=>o(i,p);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:o=>s(l.logic,o,t),condition:typeof l.condition=="function"?o=>a(l.condition,o,t):()=>true});}}};function ue(){let c=new Map,t=new Map,r=new Set,e=(s,a)=>{c.set(s,a);let o=t.get(s);o&&o(a);};return {SetTrace:(s,a)=>{t.set(s,a);let o=c.get(s)||"idle";return a(o),()=>{t.delete(s);}},useTrace:()=>({apply:a=>{a.on("flow:start",()=>{r.forEach(o=>e(o,"idle")),r.clear(),c.clear();}),a.on("node:release",({path:o,type:i})=>{(i==1||i==2)&&(r.add(o),e(o,"pending"));}),a.on("node:pending",({path:o})=>{r.add(o),(!c.has(o)||c.get(o)==="idle")&&e(o,"pending");}),a.on("node:start",({path:o})=>{r.add(o),e(o,"calculating");}),a.on("node:success",({path:o})=>{e(o,"calculated");}),a.on("node:intercept",({path:o,type:i})=>{i==3&&e(o,"calculating"),i==6&&e(o,"idle");}),a.on("node:stagnate",({path:o})=>{e(o,"pending");}),a.on("node:error",({path:o})=>e(o,"error"));}})}}function de(c,t,r,e){let l=p=>{let u=c(),y=t(),T=new Set;return u.get(p)?.forEach(f=>T.add(f)),T.size===0?[]:Array.from(T).filter(f=>{let x=y.get(f)||new Set;return !Array.from(x).some(O=>T.has(O))})};return {GetNextDependency:p=>{let u=e();return Array.from(u.get(p)||[])},GetPrevDependency:p=>{let u=r();return Array.from(u.get(p)||[])},GetAllPrevDependency:p=>{let u=t();return Array.from(u.get(p)||[])},GetAllNextDependency:p=>{let u=c();return Array.from(u.get(p)||[])},rebuildDirectDependencyMaps:p=>{let u=new Map,y=new Map;for(let T of p){let f=l(T);u.set(T,new Set(f));for(let x of f)y.has(x)||y.set(x,new Set),y.get(x).add(T);}return {directNextMap:u,directPrevMap:y}}}}function pe(c){let t=e=>{let l=[],n=[],s=new Map,a=e.size,o=0,i=0;for(let[p,u]of e)u===0&&n.push(p);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;){l.push([...n]);let p=[];for(let u of n){o++,s.set(u,i);let y=c.get(u);if(y)for(let T of y){let f=e.get(T)-1;e.set(T,f),f===0&&p.push(T);}}n=p,i++;}if(o<a)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:l,levelMap:s}};return ()=>{let e=new Map;for(let l of c.keys()){let n=Array.from(c.get(l)||[]);e.has(l)||e.set(l,0);for(let s of n){let a=e.get(s)||0;e.set(s,++a);}}return t(e)}}function ye(){let c=[],t=[],e={canRedo:()=>{},canUndo:()=>{}},l=()=>{if(!c.length)return;let u=c.pop();u?.undoAction(),o(u);},n=()=>{if(!t.length)return;let u=t.pop();u?.redoAction(),i(u,false);},s=u=>{e.canUndo=()=>u(c.length);},a=u=>{e.canRedo=()=>u(t.length);},o=u=>{t.push(u),t.length>100&&t.shift(),e.canRedo(),e.canUndo();},i=(u,y=true)=>{y&&(t.length=0),c.push(u),c.length>100&&c.shift(),e.canUndo(),e.canRedo();};return {Undo:l,Redo:n,PushIntoHistory:i,CreateHistoryAction:(u,y)=>{let[T,f]=u;return {undoAction:()=>y(T),redoAction:()=>y(f)}},initCanUndo:s,initCanRedo:a}}var Y=()=>{let c=[];return {on:t=>(c.push(t),()=>{let r=c.indexOf(t);r>-1&&c.splice(r,1);}),call:t=>c.forEach(r=>r(t))}};function fe(){let{on:c,call:t}=Y();return {onError:c,callOnError:t}}function he(){let{on:c,call:t}=Y();return {onSuccess:c,callOnSuccess:t}}var me=()=>{let c=new Set,t=new Map,r=(n,s)=>{t.get(n)?.forEach(a=>a(s));},e=(n,s)=>(t.has(n)||t.set(n,new Set),t.get(n).add(s),()=>t.get(n).delete(s));return {usePlugin:n=>{let s=new Set,a=(o,i)=>{let p=e(o,i);return s.add(p),p};return n.apply({on:a}),c.add(n),()=>{s.forEach(o=>o()),s.clear(),c.delete(n);}},emit:r}};function ge(){let{on:c,call:t}=Y();return {onStart:c,callOnStart:t}}function Te(c,t,r){let e=false,l=false,n=new Map,s=new Map,a=new Map,o=new Map,i=[],p=new Map,{GetNextDependency:y,GetPrevDependency:T,GetAllPrevDependency:f,GetAllNextDependency:x,rebuildDirectDependencyMaps:M}=de(()=>n,()=>s,()=>o,()=>a),{Undo:A,Redo:O,PushIntoHistory:G,CreateHistoryAction:I,initCanUndo:W,initCanRedo:B}=ye(),{onError:L,callOnError:q}=fe(),{onSuccess:j,callOnSuccess:z}=he(),{onStart:X,callOnStart:J}=ge(),{emit:m,usePlugin:S}=me(),{SetTrace:b,useTrace:F}=ue(),E=F();S(E);let{schema:D,GetFormData:V,GetRenderSchemaByPath:C,GetGroupByPath:h,notifyAll:P,convertToRenderSchema:w}=oe(c,{useGreedy:t.useGreedy},{GetDependencyOrder:()=>i,GetAllNextDependency:x,GetNextDependency:y,GetPrevDependency:T,GetAllPrevDependency:f,GetPathToLevelMap:()=>p},{pushIntoHistory:G,createHistoryAction:I},{callOnError:q,callOnSuccess:z,callOnStart:J,emit:m},r),v=(_,K)=>{let H=h(_),ne=w(K,_);return H.children.push(ne),H.dirtySignal.value++,ne},{SetRule:d,SetRules:R}=ie(C,n,s),{SetStrategy:g}=le(C),{SetValidators:k}=ce(C),U=pe(n),N=()=>{let _=U();i=_.steps,p=_.levelMap;};return {schema:D,SetRule:(..._)=>{d.apply(null,_),e=true,!l&&new Promise((K,H)=>{l=true,K();}).then(()=>{if(N(),e){let{directNextMap:K,directPrevMap:H}=M(i.flat());a=K,o=H;}}).finally(()=>{l=false,e=false;});},SetRules:(..._)=>{R.apply(null,_),e=true,!l&&new Promise((K,H)=>{l=true,K();}).then(()=>{if(N(),e){let{directNextMap:K,directPrevMap:H}=M(i.flat());a=K,o=H;}}).finally(()=>{l=false,e=false;});},SetStrategy:g,SetValidators:k,SetTrace:b,usePlugin:S,SetValue:(_,K)=>{C(_).dependOn(()=>K);},GetValue:(_,K="defaultValue")=>C(_)[K],GetFormData:V,GetGroupByPath:h,notifyAll:async()=>{N(),await P();},AddNewSchema:v,GetAllDependency:()=>n,GetDependencyOrder:()=>i,Undo:A,Redo:O,initCanUndo:W,initCanRedo:B,onError:L,onSuccess:j,onStart:X}}var $=new Map,Re=(c,t,r)=>{try{if(typeof r.UITrigger.signalCreateor!="function"||typeof r.UITrigger.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if($.has(c))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let e=Te(t,r.config||{useGreedy:!1},r.UITrigger),{schema:l,GetFormData:n,SetRule:s,SetRules:a,SetStrategy:o,SetValidators:i,SetValue:p,GetValue:u,usePlugin:y,GetGroupByPath:T,notifyAll:f,SetTrace:x,GetAllDependency:M,GetDependencyOrder:A,AddNewSchema:O,Undo:G,Redo:I,initCanUndo:W,initCanRedo:B,onError:L,onSuccess:q,onStart:j}=e,z={config:{SetRule:s,SetRules:a,SetStrategy:o,SetValidators:i,notifyAll:f,SetTrace:x,usePlugin:y},data:{schema:l,GetFormData:n,AddNewSchema:O,SetValue:p,GetValue:u,GetGroupByPath:T},history:{Undo:G,Redo:I,initCanUndo:W,initCanRedo:B},dependency:{GetAllDependency:M,GetDependencyOrder:A},hooks:{onError:L,onSuccess:q,onStart:j}};return $.set(c,z),z}catch(e){throw Error(e)}},pt=c=>{if($.has(c))return $.get(c);throw Error("\u4E0D\u5B58\u5728\u7684id")},yt=c=>{$.delete(c);},ft=Re;export{yt as deleteEngine,pt as useEngine,Re as useEngineManager,ft as useMeshFlow};
1
+ var ne=class{computedRules=[];store={OR:(e,n)=>{let t,l,r=this.computedRules;for(let o=0;o<r.length;o++){let a=r[o],s=a.logic(e);if(s instanceof Promise)return (async()=>{let c=await s;if(a.entityId==="__base__"?l=c:c&&(t=c),typeof t>"u")for(let u=o+1;u<r.length;u++){let h=r[u],S=h.logic(e),p=S instanceof Promise?await S:S;if(h.entityId==="__base__"){l=p;continue}if(p){t=h.value;break}}return typeof t>"u"&&(t=l),{res:t,version:n}})();let i=s;if(a.entityId==="__base__"){l=i;continue}if(i){t=a.value;break}}return typeof t>"u"&&(t=l),{res:t,version:n}},PRIORITY:(e,n)=>{let t,l=this.computedRules;for(let r=0;r<l.length;r++){let a=l[r].logic(e);if(a instanceof Promise)return (async()=>{let s=await a;if(s!==void 0)return {res:s,version:n};for(let i=r+1;i<l.length;i++){let c=l[i].logic(e),u=c instanceof Promise?await c:c;if(u!==void 0)return {res:u,version:n}}return {res:void 0,version:n}})();if(a!==void 0)return {res:a,version:n}}return {res:t,version:n}}};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(n=>Array.from(n)).flat().sort((n,t)=>t.priority-n.priority):this.computedRules=Array.from(e.values()).map(n=>Array.from(n)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,n){return this.CurrentStrategy(e,n)}},J=class{path;strategy;contract;rules=new Map;isValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;effectArray=[];constructor(e,n,t){let l=()=>this.rules;this.strategy=new ne(l),this.path=t,this.isValue=n==="value",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);}setDefaultRule(e){let n=new Set;n.add(e),this.rules.set(e.id,n);}setRules(e,n){n&&this.updateDeps(n);let t=++this.id,l={...e,entityId:t};for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(l);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let o=this.rules.get(r);o&&(o.delete(l),o.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[n,t]of e)this.deps.set(n,t);}setRule(e,n){if(n&&this.updateDeps(n),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,l={...e,entityId:t};if(e)for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(l);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let o=this.rules.get(r);o&&(o.delete(l),o.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}setSideEffect(e){this.effectArray.push(e);}getSideEffect(){return [...this.effectArray]}evaluate(e){let n=null;if(e.GetToken&&(n=e.GetToken()),this.pendingPromise&&this.promiseToken!==n&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let t=false;if(typeof e.triggerPath=="string"){t=true;let o=this.deps.get(e.triggerPath),a=e.GetValueByPath(e.triggerPath);if(typeof o=="object"||typeof a=="object")t=false;else {let s=Array.from(this.deps.keys());for(let i of s){let c=this.deps.get(i),u=e.GetValueByPath(i);if(c!==u){t=false;break}}}}if(t)return this.cache;this.promiseToken=n;let l=++this.version,r=this.strategy.evaluate(e,l);if(!(r instanceof Promise)){let{res:o,version:a}=r;return this.finalizeSync(o,a,e,n)}return this.pendingPromise=(async()=>{try{let{res:o,version:a}=await r;return this.finalizeSync(o,a,e,n)}catch(o){throw {path:this.path,error:o}}finally{this.promiseToken===n&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(e,n,t,l){return l!==this.promiseToken||n<this.version?this.cache:(this.cache=e,this.deps.forEach((r,o)=>{this.deps.set(o,t.GetValueByPath(o));}),e)}inferType(e){return Array.isArray(e)?"array":typeof e}},ee=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} undefined`,condition:t=>!!t.required},n={logic:function(t){return t.length>this.options.maxLength?`Too long:${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(n.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(n);}evaluate(e,n){let t=true,l=[...this.defaultValidators,...this.validators];for(let r of l){if(!r.condition(n))continue;let a=r.logic(e);if(typeof a!="boolean"){t=a;break}}return t}};var re=(d={frameQuota:12})=>{let e=performance.now(),n=0,t=false,l=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>t,reset(){e=performance.now(),n=0,t=true;},shouldYield(){let r=performance.now();return n++,!!((n>=5||t)&&(n=0,r-e>d.frameQuota||l()))},async yieldToMain(){return new Promise(r=>{Te(()=>{e=performance.now(),n=0,t&&(t=false),r();});})}}},Te=d=>{let{port1:e,port2:n}=new MessageChannel;e.onmessage=d,n.postMessage(null);};function ae(d,e,n,t,l){let r=new Map,o=d.useGreedy,a=re();return async(i,c)=>{let h=Symbol("token");r.set(i,h);let S=false;a.reset();let p=new Set,T=new Set,N=new Set(e.GetAllNextDependency(i));N.add(i);let M=new Map,D=new Map,F=new Set,V=e.GetPathToLevelMap(),_=V.get(i)??0,H=0,q=G=>{e.GetAllNextDependency(G).forEach(U=>{let R=V.get(U)||0;R>H&&(H=R);});};q(i),c.forEach(G=>{F.add(G);}),p.add(i);let z=performance.now();t.emit("flow:start",{path:i}),t.callOnStart({path:i});let W=false,$=30,g=G=>{let{target:y,trigger:U}=G,R=false,k=false,C=n.GetNodeByPath(y),E=[],P=(f,m)=>{if(p.has(f)||T.has(f)||F.has(f))return;let B=0,v=V.get(f)??0;if(M.has(f))B=M.get(f)-1;else {if(v>_&&M.size>$){D.has(v)||D.set(v,new Set),D.get(v).add(f),t.emit("node:intercept",{path:f,type:7});return}let O=e.GetPrevDependency(f),L=0;for(let K of O){if(p.has(K))continue;(V.get(K)??0)>_&&L++;}B=L;}if(B<=0){let O=F.has(f),L=T.has(f);if(O||L){t.emit("node:intercept",{path:f,type:L?3:3.1});return}M.delete(f),F.add(f),t.emit("node:release",{path:f,type:m,detail:{path:y}});}else M.set(f,B);},b=(f=[])=>{if(r.get(i)!==h)return;if(f.length){let v={};for(let O of f){let L=(O.args||[]).reduce((K,I)=>(K[I]=C[I],K),{});try{let K=O.fn(L);K&&typeof K=="object"&&Object.assign(v,K);}catch(K){}}for(let O in v)C[O]=v[O];R=true;}R&&l.flushPathSet.add(y),t.emit("node:success",{path:y}),p.add(y);let m=e.GetNextDependency(y);(R||k)&&e.GetAllNextDependency(y).forEach(O=>N.add(O));for(let v of m){if(p.has(v)){t.emit("node:intercept",{path:v,type:2});continue}if(T.has(v)||F.has(v)){t.emit("node:intercept",{path:v,type:T.has(v)?3:3.1});continue}if(R||k)P(v,1);else if(M.has(v))P(v,2);else {let L=V.get(v);D.has(L)||D.set(L,new Set);let K=D.get(L);K.has(v)||(K.add(v),t.emit("node:stagnate",{path:v,type:1}));}}T.delete(y),(async()=>{if(!S){let v=T.size,O=F.size;t.emit("flow:fire",{path:y,type:1,detail:{active:v,pending:O,blocked:M.size}}),w();}})();},A=f=>{t.emit("node:error",{path:y,error:f});let m=Symbol("abort");r.set(i,m),F.clear(),M.clear(),T.clear(),t.callOnError(f);},x=(f,m)=>{let B=false;f!==C[m]&&(C[m]=f,R=true,t.emit("node:bucket:success",{path:y,key:m,value:f}),m==="value"&&(B=true)),C.nodeBucket[m].isForceNotify()&&(k=true),(B||k)&&q(y);};t.emit("node:start",{path:y});try{let f=[];for(let m in C.nodeBucket){let B=C.nodeBucket[m];f.push(...B.getSideEffect());let v=B.evaluate({affectKey:m,triggerPath:U,GetRenderSchemaByPath:n.GetNodeByPath,GetValueByPath:O=>n.GetNodeByPath(O).value,GetToken:()=>h});if(v instanceof Promise){let O=v.then(L=>{r.get(i)===h&&x(L,m);});E.push(O);}else x(v,m);}if(E.length>0)return Promise.all(E).then(()=>{b(f);}).catch(A);b(f);return}catch(f){A(f);}},w=async()=>{if(r.get(i)!==h){S=false;return}S=true;let G=a.getIsFirstFrame(),y=0,U=()=>o&&G?30:1/0,R=0,k=U();try{for(;r.get(i)===h;){let C=R>=k,E=a.shouldYield();if(C||E){if(R>0&&(y++,(G||y%2===0)&&l.requestUpdate()),await a.yieldToMain(),r.get(i)!==h)break;R=0,G=a.getIsFirstFrame();}if(F.size>0&&T.size<5){for(let P of F){if(T.size>=5||R>=k)break;let b=V.get(P)??0,A=e.GetPrevDependency(P),x=A.length>1;if((!o||x)&&b>_){F.delete(P);let m=A.filter(B=>N.has(B)&&!p.has(B)).length;M.set(P,m||0),t.emit("node:intercept",{path:P,type:m>0?4:5,detail:{targetLevel:b,currentLevel:_,pendingParentsCount:m}});continue}if(F.delete(P),T.add(P),t.emit("node:processing",{path:P}),g({target:P,trigger:i}),R++,R>=k||a.shouldYield())break}if(F.size>0)continue}if(R<k&&o&&M.size>0&&T.size<5){let P=!1,b=0;for(let[A,x]of M)if(x<=0){let f=V.get(A)??0,m=e.GetPrevDependency(A);if(f>_&&m.length>1)continue;if(M.delete(A),F.add(A),b++,P=!0,t.emit("node:release",{path:A,type:4}),b>=k)break}if(b>0)continue;if(P){if(a.shouldYield()&&(await a.yieldToMain(),r.get(i)!==h))break;continue}}if(T.size===0&&F.size===0){let P=new Set;for(let x of D.keys())P.add(x);for(let[x]of M){let f=V.get(x)??0;f>_&&P.add(f);}let b=Array.from(P).sort((x,f)=>x-f),A=b[0];if(b.length>0&&A<=H){let x=b[0];if(x<=H){_=x;let f=D.get(x);f&&(f.forEach(m=>F.add(m)),D.delete(x));for(let[m]of M)(V.get(m)??0)===x&&(M.delete(m),F.add(m),t.emit("node:release",{path:m,type:3,detail:{level:x}}));continue}}else {D.forEach((x,f)=>{x.forEach(m=>{p.add(m),t.emit("node:intercept",{path:m,type:6});});}),D.clear();for(let[x]of M)p.add(x),t.emit("node:intercept",{path:x,type:6});M.clear();break}}F.size>0&&T.size>=5&&t.emit("flow:wait",{type:2});break}}finally{if(S=false,T.size+M.size+F.size===0){if(r.get(i)===h&&!W){W=true,t.emit("flow:end",{type:1}),l.requestUpdate();let E=performance.now();t.emit("flow:success",{duration:(E-z).toFixed(2)+"ms"}),Promise.resolve().then(()=>{t.callOnSuccess();});}}else t.emit("flow:wait",{type:1,detail:{nums:T.size}});}};w();}}function se(d,e,n,t,l,r){let o=xe(d),a=0,s=new Map,i=new Map,c=new Map,u=false,h=new Set,S=false,p=true,T=null,N=g=>{let w=s.get(g);return i.get(w)},M=g=>c.get(g),D=async()=>{let g=Array.from(h);h.clear();for(let w of g){let G=N(w);r.signalTrigger(G.dirtySignal);}},F=()=>{u||(u=true,requestAnimationFrame(()=>{try{for(;h.size>0;)D();}finally{u=false;}}));},V=()=>{let g=(w,G,y)=>{if(typeof w!="object"||w===null||Array.isArray(w)){if(y.length>0){let R=y[y.length-1];G[R]=N(y.join(".")).value;}return}let U=Object.getOwnPropertyNames(w);for(let R of U)y.push(R),g(w[R],w,y),y.pop();};return g(o,null,[]),o},Y=ae({useGreedy:e.useGreedy},n,{GetNodeByPath:N},l,{requestUpdate:F,flushPathSet:h}),_=async()=>(S&&T||(S=true,T=(async()=>{let g=n.GetDependencyOrder(),w=performance.now(),G=performance.now();try{for(let U=0;U<g.length;U++){let R=g[U];await Promise.all(R.map(async k=>{let C=N(k),E=!1;for(let P in C.nodeBucket){let b=await C.nodeBucket[P].evaluate({affectKey:P,triggerPath:void 0,GetRenderSchemaByPath:N,GetValueByPath:A=>N(A).value,isSameToken:()=>!0});if(P==="options"){let A=!1,x=C.value;for(let f of b)if(f.value==x){A=!0;break}A||(C.value=void 0,E=!0);}b!==C[P]&&(C[P]=b,E=!0);}E&&h.add(k);})),performance.now()-G>12&&(await new Promise(k=>requestAnimationFrame(k)),G=performance.now());}h.size>0&&F(),p=!1;let y=performance.now();l.emit("flow:success",{duration:(y-w).toFixed(2)+"ms"}),l.callOnSuccess();}catch(y){throw l.emit("node:error",{path:y.path,error:y.error}),l.callOnError(y),y}finally{S=false,T=null,p=false;}})()),T),H=g=>{if(p)return;if(!N(g))throw Error("Node undefined");performance.now();h.add(g),F();let y=n.GetNextDependency(g);q(y,g);};function q(g,w){Y(w,g);}let z=(g,w="")=>{let G="name"in g?g.name:void 0,y=G?w===""?G:`${w}.${G}`:w,U=r.signalCreateor(),R=a++,k={getRenderSchema:P=>N(P)},C=(P,b)=>{let A=P(b),x=N(b.path),f=t.createHistoryAction([{path:b.path,value:x.value},{path:b.path,value:A}],m=>{let B=N(m.path);B.value=m.value,H(m.path);});x.value=A,t.pushIntoHistory(f),H(b.path);},E={...g,disabled:!!g.disabled,hidden:"hidden"in g?g.hidden:false,readonly:"readonly"in g?g.readonly:false,required:"required"in g?g.required:false,path:y,dirtySignal:U,uid:R,nodeBucket:{},validators:new ee(y),theme:"secondary",dependOn:P=>C(P,{...k,path:y})};return g.type==="group"&&(delete E.nodeBucket,delete E.validators,E.children=g.children.map(P=>z(P,y)),c.set(E.path,E)),s.set(E.path,E.uid),i.set(E.uid,E),E};return {schema:z(d),GetFormData:()=>V(),GetRenderSchemaByPath:N,GetGroupByPath:M,notifyAll:_,convertToRenderSchema:z}}function xe(d,e={}){let n=r=>{if(r.type=="group")return {key:r.name||"",isGroup:true,val:r.children.reduce((o,a)=>[...o,n(a)],[])};if(r.type=="input"||r.type=="number"||r.type=="select"||r.type=="checkbox")return {key:r.name,isGroup:false,val:r.value};throw Error(`undefined type:${r.type}`)},t=(r,o)=>{if(o.isGroup){let a={};o.key===""?a=r:r[o.key]=a,o.val.forEach(s=>{t(a,s);});}else r[o.key]=o.val;},l=n(d);return t(e,l),e}var oe=(d,e,n)=>{let l=r=>{let o=n.triggerPaths.map(i=>r.GetValueByPath(i)),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>o}),Object.defineProperty(a,"affectedTatget",{get:()=>r.GetRenderSchemaByPath(d)[e]}),n.logic({slot:a})};return {value:n.value,targetPath:d,triggerPaths:n.triggerPaths,priority:n.priority??10,logic:l}},ie=(d,e,n)=>{if(!d)throw Error("");let t=d,l=(a,s)=>{e.has(a)||e.set(a,new Set),e.get(a).add(s),n.has(s)||n.set(s,new Set),n.get(s).add(a);};return {SetRule:(a,s,i,c={logic:u=>{}})=>{let u=t(s),h=oe(s,i,{...c,triggerPaths:[a]}),S=[a].map(p=>[p,t(p).value]);if(l(a,s),u.nodeBucket[i])u.nodeBucket[i].setRule(h,S),c.effect&&u.nodeBucket[i].setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]});else {let p=new J(u[i],i,s);p.setRule(h,S),c.effect&&p.setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]}),u.nodeBucket[i]=p;}c.forceNotify&&u.nodeBucket[i].forceNotify();},SetRules:(a,s,i,c={logic:u=>{}})=>{let u=t(s);for(let p of a)l(p,s);let h=oe(s,i,{...c,triggerPaths:a}),S=a.map(p=>[p,t(p).value]);if(u.nodeBucket[i])u.nodeBucket[i].setRules(h,S),c.effect&&u.nodeBucket[i].setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]});else {let p=new J(u[i],i,s);p.setRules(h,S),c.effect&&p.setSideEffect({fn:c.effect,args:c.effectArgs?c.effectArgs:[i]}),u.nodeBucket[i]=p;}c.forceNotify&&u.nodeBucket[i].forceNotify();}}};var le=d=>{let e=d||void 0;if(!e)throw Error("");return {SetStrategy:(t,l,r)=>{e(t).nodeBucket[l].setStrategy(r);}}};var ce=d=>{let e=d||void 0;return {SetValidators:(t,l)=>{let r=e(t),o=(s,i,c)=>s(i,c),a=(s,i,c)=>s(i,c);if(!r.validators)throw Error("validator init error");r.validators.setValidators({logic:s=>o(l.logic,s,e),condition:typeof l.condition=="function"?s=>a(l.condition,s,e):()=>true});}}};function de(){let d=new Map,e=new Map,n=new Set,t=(o,a)=>{d.set(o,a);let s=e.get(o);s&&s(a);};return {SetTrace:(o,a)=>{e.set(o,a);let s=d.get(o)||"idle";return a(s),()=>{e.delete(o);}},useTrace:()=>({apply:a=>{a.on("flow:start",()=>{n.forEach(s=>t(s,"idle")),n.clear(),d.clear();}),a.on("node:release",({path:s,type:i})=>{(i==1||i==2)&&(n.add(s),t(s,"pending"));}),a.on("node:pending",({path:s})=>{n.add(s),(!d.has(s)||d.get(s)==="idle")&&t(s,"pending");}),a.on("node:start",({path:s})=>{n.add(s),t(s,"calculating");}),a.on("node:success",({path:s})=>{t(s,"calculated");}),a.on("node:intercept",({path:s,type:i})=>{i==3&&t(s,"calculating"),i==6&&t(s,"idle");}),a.on("node:stagnate",({path:s})=>{t(s,"pending");}),a.on("node:error",({path:s})=>t(s,"error"));}})}}function ue(d,e,n,t){let l=c=>{let u=d(),h=e(),S=new Set;return u.get(c)?.forEach(p=>S.add(p)),S.size===0?[]:Array.from(S).filter(p=>{let T=h.get(p)||new Set;return !Array.from(T).some(D=>S.has(D))})};return {GetNextDependency:c=>{let u=t();return Array.from(u.get(c)||[])},GetPrevDependency:c=>{let u=n();return Array.from(u.get(c)||[])},GetAllPrevDependency:c=>{let u=e();return Array.from(u.get(c)||[])},GetAllNextDependency:c=>{let u=d();return Array.from(u.get(c)||[])},rebuildDirectDependencyMaps:c=>{let u=new Map,h=new Map;for(let S of c){let p=l(S);u.set(S,new Set(p));for(let T of p)h.has(T)||h.set(T,new Set),h.get(T).add(S);}return {directNextMap:u,directPrevMap:h}}}}function fe(d){let e=t=>{let l=[],r=[],o=new Map,a=t.size,s=0,i=0;for(let[c,u]of t)u===0&&r.push(c);if(r.length===0&&a>0)throw Error("Circular dependency detected");for(;r.length>0;){l.push([...r]);let c=[];for(let u of r){s++,o.set(u,i);let h=d.get(u);if(h)for(let S of h){let p=t.get(S)-1;t.set(S,p),p===0&&c.push(S);}}r=c,i++;}if(s<a)throw Error("Circular dependency detected");return {steps:l,levelMap:o}};return ()=>{let t=new Map;for(let l of d.keys()){let r=Array.from(d.get(l)||[]);t.has(l)||t.set(l,0);for(let o of r){let a=t.get(o)||0;t.set(o,++a);}}return e(t)}}var X=()=>{let d=[];return {on:e=>(d.push(e),()=>{let n=d.indexOf(e);n>-1&&d.splice(n,1);}),call:e=>d.forEach(n=>n(e))}};function pe(){let{on:d,call:e}=X();return {onError:d,callOnError:e}}function ye(){let{on:d,call:e}=X();return {onSuccess:d,callOnSuccess:e}}var he=()=>{let d=new Set,e=new Map,n=(r,o)=>{e.get(r)?.forEach(a=>a(o));},t=(r,o)=>(e.has(r)||e.set(r,new Set),e.get(r).add(o),()=>e.get(r).delete(o));return {usePlugin:r=>{let o=new Set,a=(s,i)=>{let c=t(s,i);return o.add(c),c};return r.apply({on:a}),d.add(r),()=>{o.forEach(s=>s()),o.clear(),d.delete(r);}},emit:n}};function me(){let{on:d,call:e}=X();return {onStart:d,callOnStart:e}}function ge(d,e){let n=false,t=false,l=new Map,r=new Map,o=new Map,a=new Map,s=[],i=new Map,{GetNextDependency:u,GetPrevDependency:h,GetAllPrevDependency:S,GetAllNextDependency:p,rebuildDirectDependencyMaps:T}=ue(()=>l,()=>r,()=>a,()=>o),N={},M={};if(e.modules.useHistory){let{Undo:I,Redo:j,PushIntoHistory:Q,CreateHistoryAction:Z,initCanUndo:Pe,initCanRedo:Se}=e.modules.useHistory();N.pushIntoHistory=Q,N.createHistoryAction=Z,M={Undo:I,Redo:j,initCanUndo:Pe,initCanRedo:Se};}let{onError:D,callOnError:F}=pe(),{onSuccess:V,callOnSuccess:Y}=ye(),{onStart:_,callOnStart:H}=me(),{emit:q,usePlugin:z}=he(),{SetTrace:W,useTrace:$}=de(),g=$();z(g);let{schema:w,GetFormData:G,GetRenderSchemaByPath:y,GetGroupByPath:U,notifyAll:R,convertToRenderSchema:k}=se(d,{useGreedy:e.config.useGreedy},{GetDependencyOrder:()=>s,GetAllNextDependency:p,GetNextDependency:u,GetPrevDependency:h,GetAllPrevDependency:S,GetPathToLevelMap:()=>i},N,{callOnError:F,callOnSuccess:Y,callOnStart:H,emit:q},e.UITrigger),C=(I,j)=>{let Q=U(I),Z=k(j,I);return Q.children.push(Z),Q.dirtySignal.value++,Z},{SetRule:E,SetRules:P}=ie(y,l,r),{SetStrategy:b}=le(y),{SetValidators:A}=ce(y),x=fe(l),f=()=>{let I=x();s=I.steps,i=I.levelMap;},m=()=>{t||(t=true,Promise.resolve().then(()=>{if(f(),n){let{directNextMap:I,directPrevMap:j}=T(s.flat());o=I,a=j;}}).finally(()=>{t=false,n=false;}));};return {schema:w,SetRule:(...I)=>{E.apply(null,I),n=true,m();},SetRules:(...I)=>{P.apply(null,I),n=true,m();},SetStrategy:b,SetValidators:A,SetTrace:W,usePlugin:z,SetValue:(I,j)=>{y(I).dependOn(()=>j);},GetValue:(I,j="value")=>y(I)[j],GetFormData:G,GetGroupByPath:U,notifyAll:async()=>{f(),await R();},AddNewSchema:C,GetAllDependency:()=>l,GetDependencyOrder:()=>s,historyExports:M,onError:D,onSuccess:V,onStart:_}}var te=new Map,ve=(d,e,n)=>{try{if(typeof n.UITrigger.signalCreateor!="function"||typeof n.UITrigger.signalTrigger!="function")throw Error("ui trigger undefined");if(te.has(d))throw Error("engineID repeated");let t=ge(e,{config:n.config||{useGreedy:!1},UITrigger:n.UITrigger,modules:n.modules||{},plugins:{}}),{schema:l,GetFormData:r,SetRule:o,SetRules:a,SetStrategy:s,SetValidators:i,SetValue:c,GetValue:u,usePlugin:h,GetGroupByPath:S,notifyAll:p,SetTrace:T,GetAllDependency:N,GetDependencyOrder:M,AddNewSchema:D,historyExports:F,onError:V,onSuccess:Y,onStart:_}=t,q={...{config:{SetRule:o,SetRules:a,SetStrategy:s,SetValidators:i,notifyAll:p,SetTrace:T,usePlugin:h},data:{schema:l,GetFormData:r,AddNewSchema:D,SetValue:c,GetValue:u,GetGroupByPath:S},dependency:{GetAllDependency:N,GetDependencyOrder:M},hooks:{onError:V,onSuccess:Y,onStart:_}}},z=n.modules;return z&&Object.keys(z).forEach(W=>{let $=W;if($.startsWith("use")){let g=$.slice(3);$=g.charAt(0).toLowerCase()+g.slice(1);}W==="useHistory"&&F&&Object.keys(F).length>0&&(q[$]=F);}),te.set(d,q),q}catch(t){throw Error(t)}},dt=()=>(d,e,n)=>Fe(d,e,n),ut=d=>{let e=te.get(d);if(e)return e;throw Error("[MeshFlow] Engine ID not found.")},ft=d=>{te.delete(d);},Fe=ve;export{ft as deleteEngine,ut as useEngine,ve as useEngineManager,Fe as useMeshFlow,dt as useMeshFlowDefiner};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshflow/core",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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",