@meshflow/core 0.1.3 → 0.1.5

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
@@ -30,17 +30,53 @@
30
30
  * **⚡ 最小受影响路径**:触发变更时无需遍历全局,仅针对受影响的“下游子图”进行动态增量计算。
31
31
  * **🚨 循环依赖检测**:在节点定义阶段实时进行 $O(V+E)$ 的环检测,提前发现逻辑死循环。
32
32
  * **📦 极简轻量**:零依赖,体积仅 ~7kB(zipped),适配任何 JavaScript 运行时。
33
-
33
+ * **🔌 插件化架构 (New)**:支持生命周期拦截与监听(如官方调试插件 `@meshflow/logger`)。
34
34
  ---
35
35
 
36
36
  ## 🚀 快速上手
37
37
 
38
- ### 安装
38
+ #### 安装
39
39
 
40
40
  ```bash
41
41
  npm install @meshflow/core
42
42
  ```
43
-
43
+ #### 定义节点
44
+ ```typescript
45
+ import { useMeshFlow } from "@meshflow/core";
46
+ const schema = {
47
+ type: 'group',
48
+ name: 'billing',
49
+ label: '计费与汇总',
50
+ children: [
51
+ { type: 'number', name: 'totalPrice', label: '预估月度总价', defaultValue: 0, },
52
+ { type: 'input', name: 'priceDetail', label: '计费项说明', defaultValue: '基础配置费用'}
53
+ ]
54
+ };
55
+ const engine = useMeshFlow<Ref<number,number>,AllPath>('main',schema, {
56
+ signalCreateor: () => ref(0),
57
+ signalTrigger(signal) {
58
+ signal.value++;
59
+ },
60
+ });
61
+ ```
62
+ #### 添加联动依赖
63
+ ```typescript
64
+ //声明联动规则:当总价 > 2000 时,自动修改描述与主题
65
+ engine.config.SetRule("billing.totalPrice", "billing.priceDetail", "defaultValue", {
66
+ logic: ({ slot }) => {
67
+ const [total] = slot.triggerTargets; // 从触发目标中解构出 totalPrice
68
+ return total > 2000 ? "大客户折扣" : undefined;
69
+ }
70
+ });
71
+ engine.config.SetRule( "billing.totalPrice", "billing.priceDetail", "theme", {
72
+ logic: (api) => {
73
+ const [value] = api.slot.triggerTargets;
74
+ return total > 2000 ? "warning" : undefined;
75
+ },
76
+ });
77
+ //触发首屏计算
78
+ engine.config.notifyAll();
79
+ ```
44
80
 
45
81
  ## 🛠️ 为什么选择 MeshFlow?
46
82
 
package/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  interface MeshErrorContext {
2
2
  path: string;
3
- info: any;
3
+ error: any;
4
4
  }
5
5
 
6
6
  interface MeshEvents {
@@ -21,26 +21,38 @@ interface MeshEvents {
21
21
  };
22
22
  'node:intercept': {
23
23
  path: string;
24
- reason: string;
24
+ type: number;
25
25
  detail?: any;
26
26
  };
27
27
  'node:release': {
28
28
  path: string;
29
- reason: string;
29
+ type: number;
30
+ detail?: any;
30
31
  };
31
32
  'node:stagnate': {
32
33
  path: string;
33
- reason: string;
34
+ type: number;
34
35
  };
35
36
  'node:processing': {
36
37
  path: string;
37
38
  };
38
39
  'flow:wait': {
39
- reason: string;
40
+ type: number;
41
+ detail?: any;
40
42
  };
41
43
  'flow:fire': {
42
44
  path: string;
43
- reason: string;
45
+ type: number;
46
+ detail?: any;
47
+ };
48
+ 'flow:start': {
49
+ path: string;
50
+ };
51
+ 'flow:success': {
52
+ duration: string;
53
+ };
54
+ 'node:pending': {
55
+ path: string;
44
56
  };
45
57
  }
46
58
  type MeshEventName = keyof MeshEvents;
@@ -142,7 +154,7 @@ interface logicApi {
142
154
  type GetType<T, P> = P extends keyof T ? T[P] : never;
143
155
  type Engine<T> = {
144
156
  data: {
145
- [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue']: GetType<T, K>;
157
+ [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue' | 'GetValue' | 'GetGroupByPath']: GetType<T, K>;
146
158
  };
147
159
  config: {
148
160
  [K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
@@ -180,15 +192,17 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
180
192
  logic: (val: any, GetByPath: any) => any;
181
193
  condition: (data: any) => boolean;
182
194
  }) => void;
183
- SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
195
+ SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void) => () => void;
184
196
  usePlugin: (plugin: {
185
197
  apply: (api: {
186
198
  on: (event: MeshEventName, cb: Function) => () => boolean;
187
199
  }) => void;
188
200
  }) => () => void;
189
201
  SetValue: (path: P, value: any) => void;
202
+ GetValue: (path: P, key?: string) => any;
190
203
  GetFormData: () => any;
191
- notifyAll: () => void;
204
+ GetGroupByPath: (path: string) => RenderSchema | undefined;
205
+ notifyAll: () => Promise<void>;
192
206
  AddNewSchema: (path: string, data: any) => RenderSchema;
193
207
  GetAllDependency: () => Map<P, Set<P>>;
194
208
  GetDependencyOrder: () => P[][];
@@ -221,15 +235,17 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
221
235
  logic: (val: any, GetByPath: any) => any;
222
236
  condition: (data: any) => boolean;
223
237
  }) => void;
224
- SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
238
+ SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void) => () => void;
225
239
  usePlugin: (plugin: {
226
240
  apply: (api: {
227
241
  on: (event: MeshEventName, cb: Function) => () => boolean;
228
242
  }) => void;
229
243
  }) => () => void;
230
244
  SetValue: (path: P, value: any) => void;
245
+ GetValue: (path: P, key?: string) => any;
231
246
  GetFormData: () => any;
232
- notifyAll: () => void;
247
+ GetGroupByPath: (path: string) => RenderSchema | undefined;
248
+ notifyAll: () => Promise<void>;
233
249
  AddNewSchema: (path: string, data: any) => RenderSchema;
234
250
  GetAllDependency: () => Map<P, Set<P>>;
235
251
  GetDependencyOrder: () => P[][];
@@ -266,15 +282,17 @@ declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: an
266
282
  logic: (val: any, GetByPath: any) => any;
267
283
  condition: (data: any) => boolean;
268
284
  }) => void;
269
- SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
285
+ SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void) => () => void;
270
286
  usePlugin: (plugin: {
271
287
  apply: (api: {
272
288
  on: (event: MeshEventName, cb: Function) => () => boolean;
273
289
  }) => void;
274
290
  }) => () => void;
275
291
  SetValue: (path: P, value: any) => void;
292
+ GetValue: (path: P, key?: string) => any;
276
293
  GetFormData: () => any;
277
- notifyAll: () => void;
294
+ GetGroupByPath: (path: string) => RenderSchema | undefined;
295
+ notifyAll: () => Promise<void>;
278
296
  AddNewSchema: (path: string, data: any) => RenderSchema;
279
297
  GetAllDependency: () => Map<P, Set<P>>;
280
298
  GetDependencyOrder: () => P[][];
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  interface MeshErrorContext {
2
2
  path: string;
3
- info: any;
3
+ error: any;
4
4
  }
5
5
 
6
6
  interface MeshEvents {
@@ -21,26 +21,38 @@ interface MeshEvents {
21
21
  };
22
22
  'node:intercept': {
23
23
  path: string;
24
- reason: string;
24
+ type: number;
25
25
  detail?: any;
26
26
  };
27
27
  'node:release': {
28
28
  path: string;
29
- reason: string;
29
+ type: number;
30
+ detail?: any;
30
31
  };
31
32
  'node:stagnate': {
32
33
  path: string;
33
- reason: string;
34
+ type: number;
34
35
  };
35
36
  'node:processing': {
36
37
  path: string;
37
38
  };
38
39
  'flow:wait': {
39
- reason: string;
40
+ type: number;
41
+ detail?: any;
40
42
  };
41
43
  'flow:fire': {
42
44
  path: string;
43
- reason: string;
45
+ type: number;
46
+ detail?: any;
47
+ };
48
+ 'flow:start': {
49
+ path: string;
50
+ };
51
+ 'flow:success': {
52
+ duration: string;
53
+ };
54
+ 'node:pending': {
55
+ path: string;
44
56
  };
45
57
  }
46
58
  type MeshEventName = keyof MeshEvents;
@@ -142,7 +154,7 @@ interface logicApi {
142
154
  type GetType<T, P> = P extends keyof T ? T[P] : never;
143
155
  type Engine<T> = {
144
156
  data: {
145
- [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue']: GetType<T, K>;
157
+ [K in "schema" | "GetFormData" | "AddNewSchema" | 'SetValue' | 'GetValue' | 'GetGroupByPath']: GetType<T, K>;
146
158
  };
147
159
  config: {
148
160
  [K in "SetRule" | "SetRules" | "SetStrategy" | "SetValidators" | "notifyAll" | "SetTrace" | "usePlugin"]: GetType<T, K>;
@@ -180,15 +192,17 @@ declare const useEngineManager: <T, P extends string>(id: string | symbol, Schem
180
192
  logic: (val: any, GetByPath: any) => any;
181
193
  condition: (data: any) => boolean;
182
194
  }) => void;
183
- SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
195
+ SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void) => () => void;
184
196
  usePlugin: (plugin: {
185
197
  apply: (api: {
186
198
  on: (event: MeshEventName, cb: Function) => () => boolean;
187
199
  }) => void;
188
200
  }) => () => void;
189
201
  SetValue: (path: P, value: any) => void;
202
+ GetValue: (path: P, key?: string) => any;
190
203
  GetFormData: () => any;
191
- notifyAll: () => void;
204
+ GetGroupByPath: (path: string) => RenderSchema | undefined;
205
+ notifyAll: () => Promise<void>;
192
206
  AddNewSchema: (path: string, data: any) => RenderSchema;
193
207
  GetAllDependency: () => Map<P, Set<P>>;
194
208
  GetDependencyOrder: () => P[][];
@@ -221,15 +235,17 @@ declare const useEngine: <T = any, P extends string = string>(id: string | symbo
221
235
  logic: (val: any, GetByPath: any) => any;
222
236
  condition: (data: any) => boolean;
223
237
  }) => void;
224
- SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
238
+ SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void) => () => void;
225
239
  usePlugin: (plugin: {
226
240
  apply: (api: {
227
241
  on: (event: MeshEventName, cb: Function) => () => boolean;
228
242
  }) => void;
229
243
  }) => () => void;
230
244
  SetValue: (path: P, value: any) => void;
245
+ GetValue: (path: P, key?: string) => any;
231
246
  GetFormData: () => any;
232
- notifyAll: () => void;
247
+ GetGroupByPath: (path: string) => RenderSchema | undefined;
248
+ notifyAll: () => Promise<void>;
233
249
  AddNewSchema: (path: string, data: any) => RenderSchema;
234
250
  GetAllDependency: () => Map<P, Set<P>>;
235
251
  GetDependencyOrder: () => P[][];
@@ -266,15 +282,17 @@ declare const useMeshFlow: <T, P extends string>(id: string | symbol, Schema: an
266
282
  logic: (val: any, GetByPath: any) => any;
267
283
  condition: (data: any) => boolean;
268
284
  }) => void;
269
- SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void, context: any) => () => void;
285
+ SetTrace: (myPath: P, onUpdate: (newStatus: "idle" | "pending" | "calculating" | "calculated" | "error" | "canceled") => void) => () => void;
270
286
  usePlugin: (plugin: {
271
287
  apply: (api: {
272
288
  on: (event: MeshEventName, cb: Function) => () => boolean;
273
289
  }) => void;
274
290
  }) => () => void;
275
291
  SetValue: (path: P, value: any) => void;
292
+ GetValue: (path: P, key?: string) => any;
276
293
  GetFormData: () => any;
277
- notifyAll: () => void;
294
+ GetGroupByPath: (path: string) => RenderSchema | undefined;
295
+ notifyAll: () => Promise<void>;
278
296
  AddNewSchema: (path: string, data: any) => RenderSchema;
279
297
  GetAllDependency: () => Map<P, Set<P>>;
280
298
  GetDependencyOrder: () => P[][];
package/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var Q=class{computedRules=[];store={OR:async(e,r)=>{let t,i,n=this.computedRules;for(let c of n){let o=await c.logic(e);if(c.entityId==="__base__"){i=o;continue}if(o){t=c.value;break}}return typeof t>"u"&&(t=i),{res:t,version:r}},PRIORITY:async(e,r)=>{let t=null,i=this.computedRules;try{for(let n of i){let c=await n.logic(e);if(c!==void 0){t=c;break}}}catch(n){throw n}return {res:t,version:r}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat().sort((r,t)=>t.priority-r.priority):this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,r){return this.CurrentStrategy(e,r)}},$=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,r,t){let i=()=>this.rules;this.strategy=new Q(i),this.path=t,this.isDefaultValue=r==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let r=new Set;r.add(e),this.rules.set(e.id,r);}setRules(e,r){r&&this.updateDeps(r);let t=++this.id,i={...e,entityId:t};for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[r,t]of e)this.deps.set(r,t);}setRule(e,r){if(r&&this.updateDeps(r),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,i={...e,entityId:t};if(e)for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}async evaluate(e){let r=null;if(e.GetToken&&(r=e.GetToken()),this.pendingPromise&&this.promiseToken!==r&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=r;let t=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let i=!1;if(typeof e.triggerPath=="string"){i=!0;let o=this.deps.get(e.triggerPath),p=e.GetValueByPath(e.triggerPath);if(typeof o=="object"||typeof p=="object")i=!1;else {let u=Array.from(this.deps.keys());for(let l of u){let a=this.deps.get(l),h=e.GetValueByPath(l);if(a!==h){i=!1;break}}}}if(i)return this.cache;let{res:n,version:c}=await this.strategy.evaluate(e,t);if(r!==this.promiseToken)return this.cache;if(c<this.version)return this.cache;if(this.inferType(n)!==this.contract&&`${this.contract}`,this.cache=n,r===this.promiseToken){let o=Array.from(this.deps.keys());for(let p of o){let u=e.GetValueByPath(p);this.deps.set(p,u);}}return n}catch(i){throw {path:this.path,info:i}}finally{this.promiseToken===r&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},z=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:t=>t||typeof t=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:t=>!!t.required},r={logic:function(t){return t.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(r.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(r);}evaluate(e,r){let t=true,i=[...this.defaultValidators,...this.validators];for(let n of i){if(!n.condition(r))continue;let o=n.logic(e);if(typeof o!="boolean"){t=o;break}}return t}};function J(s,e,r,t,i){let n=new Map;return (o,p)=>{let l=Symbol("token");n.set(o,l);let a=false,h=new Set,y=new Set,m=new Set(s.GetAllNextDependency(o));m.add(o);let x=new Map,R=new Map,O=performance.now(),A=s.GetPathToLevelMap(),E=A.get(o)??0;m.forEach(v=>{if(v===o||p.includes(v))return;let d=s.GetPrevDependency(v).filter(f=>m.has(f)).length;d>0&&R.set(v,d);}),h.add(o);let G=Array.from(p).map(v=>(x.set(v,(x.get(v)||0)+1),{target:v,trigger:o,isReleased:false}));e.pushExecution([...Array.from(p),o],true),`${o}${l.description}`,t.callOnStart({path:o});let B=async v=>{let{target:g,trigger:d}=v;try{if(n.get(o)!==l)return;let f=!1,T=!1,S=r.GetRenderSchemaByPath(g);t.emit("node:start",{path:g});for(let F in S.nodeBucket){let w=S.nodeBucket[F],V=await w.evaluate({affectKey:F,triggerPath:d,GetRenderSchemaByPath:r.GetRenderSchemaByPath,GetValueByPath:P=>r.GetRenderSchemaByPath(P).defaultValue,GetToken:()=>l});if(n.get(o)!==l){t.emit("node:intercept",{path:g,reason:`\u4EE4\u724C\u8FC7\u671F\uFF0C\u4E22\u5F03${g}\u65E7\u4EFB\u52A1\u8BA1\u7B97\u7ED3\u679C`});return}F==="options"&&(V.some(b=>b.value==S.defaultValue)||(S.defaultValue=void 0,f=!0)),V!==S[F]&&(S[F]=V,f=!0,t.emit("node:bucket:success",{path:g,key:F,value:V})),w.isForceNotify()&&(T=!0),f&&i.flushPathSet.add(g);let I=s.GetNextDependency(g);(f||T)&&s.GetAllNextDependency(g).forEach(b=>m.add(b));for(let P of I){if(h.has(P)){t.emit("node:intercept",{path:P,reason:` \u4E0B\u6E38 ${P} \u5DF2\u7531\u5176\u4ED6\u8DEF\u5F84\u5904\u7406`});continue}if(f||T){if(!R.has(P)&&!h.has(P)&&!x.has(P)){let H=s.GetPrevDependency(P).filter(U=>m.has(U)).length;R.set(P,H);}let b=R.get(P)??0,C=Math.max(0,b-1);C<=0?(R.delete(P),G.push({target:P,trigger:g,isReleased:!0}),x.set(P,1),e.pushExecution([P]),t.emit("node:release",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u53D8\u4E86`})):R.set(P,C);}else t.emit("node:stagnate",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u672A\u53D8`});}}if(t.emit("node:success",{path:g}),h.add(g),performance.now()-O>16&&(await new Promise(F=>requestAnimationFrame(F)),O=performance.now(),n.get(o)!==l))return;n.get(o)===l&&i.requestUpdate();}catch(f){t.emit("node:error",{path:g,error:f});let T=Symbol("abort");n.set(o,T),G.length=0,R.clear(),y.clear(),e.markError(g),t.callOnError(f);}finally{n.get(o)===l&&(y.delete(g),e.popExecution([g]),a||(t.emit("flow:fire",{path:g,reason:"\u4EFB\u52A1\u5F52\u822A"}),D()));}},D=async()=>{if(n.get(o)!==l){a=false;return}a=true;try{for(;(G.length>0||R.size>0)&&n.get(o)===l;){if(G.length>0){if(y.size>=20){a=!1;return}let v=G.shift(),{target:g}=v;if(h.has(g)){t.emit("node:intercept",{path:g,reason:` \u62D2\u7EDD\u91CD\u5165${g},\u5DF2\u8BA1\u7B97\u5B8C\u6210`});continue}let d=x.get(g)||0;d<=1?x.delete(g):x.set(g,d-1);let f=A.get(g)??0;if(f>E+1&&!v.isReleased){t.emit("node:intercept",{path:g,reason:` ${g} \u5C42\u7EA7\u592A\u6DF1(${f})\uFF0C\u5F53\u524D\u6C34\u4F4D(${E})`}),R.set(g,1);continue}y.add(g),t.emit("node:processing",{path:g}),e.pushExecution([g]),B(v);continue}if(y.size>0){t.emit("flow:wait",{reason:`\u961F\u5217\u5DF2\u7A7A,\u7184\u706B\u7B49\u5F85\uFF0C\u7B49\u5F85\u5F02\u6B65\u4EFB\u52A1\u5F52\u822A | \u98DE\u884C\u4E2D: ${Array.from(y).join(",")} | `}),a=!1;return}if(R.size>0){let v=!1,g=[];for(let[d]of R)s.GetPrevDependency(d).some(S=>h.has(S)?!1:y.has(S)||x.has(S)||m.has(S)?!0:(A.get(S)??0)>E)||g.push(d);if(g.length>0&&(g.forEach(d=>{R.delete(d),G.push({target:d,trigger:o,isReleased:!0}),x.set(d,1),e.pushExecution([d]);}),v=!0),v)continue;if(Array.from(R.keys()).some(f=>s.GetPrevDependency(f).some(S=>m.has(S)&&!h.has(S)))){t.emit("flow:wait",{reason:"\u5C1A\u6709\u6D3B\u8DC3\u4F9D\u8D56 \u672A\u5B8C\u6210,\u7184\u706B\u7B49\u5F85"}),a=!1;return}if(E++,E>2e3)break;continue}}}finally{R.size,y.size,G.length,a=false,t.emit("flow:wait",{reason:"\u7184\u706B\u9759\u9ED8"}),Promise.resolve().then(()=>{R.size===0&&y.size===0&&G.length===0&&t.callOnSuccess();});}};D();}}function Z(s,e,r,t,i,n){let c=me(s),o=0,p=new Map,u=new Map,l=new Map,a=false,h=new Set,y=d=>{let f=p.get(d);return u.get(f)},m=d=>l.get(d),x=async()=>{let d=Array.from(h);h.clear();for(let f of d){let T=y(f);n.signalTrigger(T.dirtySignal);}},R=()=>{a||(a=true,Promise.resolve().then(()=>{try{for(;h.size>0;)x();}finally{a=false;}}));},O=()=>{let d=(f,T,S)=>{if(typeof f!="object"||f===null||Array.isArray(f)){if(S.length>0){let w=S[S.length-1];T[w]=y(S.join(".")).defaultValue;}return}let F=Object.getOwnPropertyNames(f);for(let w of F)S.push(w),d(f[w],f,S),S.pop();};return d(c,null,[]),c},A=J(e,r,{GetRenderSchemaByPath:y},i,{requestUpdate:R,flushPathSet:h}),L=async()=>{let d=e.GetDependencyOrder().flat();try{for(let f of d){let T=y(f);for(let S in T.nodeBucket){let F=await T.nodeBucket[S].evaluate({affectKey:S,triggerPath:void 0,GetRenderSchemaByPath:y,GetValueByPath:w=>y(w).defaultValue,isSameToken:()=>!1});if(S==="options"){let w=!1,V=T.defaultValue;for(let I of F)I.value==V&&(w=!0);w||(T.defaultValue=void 0,R());}F!==T[S]&&(T[S]=F,h.add(f),R());}}}catch(f){i.callOnError(f);}},E=async d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!y(d))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");h.add(d),R();let T=e.GetNextDependency(d);G(T,d),r.popExecution([d],true);};async function G(d,f){A(f,d);}let B=d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");let f=y(d);f.nodeBucket.defaultValue&&f.nodeBucket.defaultValue.updateInputValueRule(f.defaultValue);},D=(d,f="")=>{let T="name"in d?d.name:void 0,S=T?f===""?T:`${f}.${T}`:f,F=n.signalCreateor(),w=o++,V={getRenderSchema:b=>y(b)},I=async(b,C)=>{let H=b(C),U=y(C.path),W=t.createHistoryAction([{path:C.path,value:U.defaultValue},{path:C.path,value:H}],async K=>{let j=y(K.path);j.defaultValue=K.value,B(K.path),await E(K.path);});U.defaultValue=H,t.pushIntoHistory(W),B(C.path),await E(C.path);},P={...d,disabled:!!d.disabled,hidden:"hidden"in d?d.hidden:false,readonly:"readonly"in d?d.readonly:false,required:"required"in d?d.required:false,path:S,dirtySignal:F,uid:w,nodeBucket:{},validators:new z(S),theme:"secondary",dependOn:async b=>await I(b,{...V,path:S})};return d.type==="group"&&(delete P.nodeBucket,delete P.validators,P.children=d.children.map(b=>D(b,S)),l.set(P.path,P)),p.set(P.path,P.uid),u.set(P.uid,P),P};return {schema:D(s),GetFormData:()=>O(),GetRenderSchemaByPath:y,GetGroupByPath:m,notifyAll:L,convertToRenderSchema:D}}function me(s,e={}){let r=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((c,o)=>[...c,r(o)],[])};if(n.type=="input"||n.type=="number"||n.type=="select"||n.type=="checkbox")return {key:n.name,isGroup:false,val:n.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${n.type}`)},t=(n,c)=>{if(c.isGroup){let o={};c.key===""?o=n:n[c.key]=o,c.val.forEach(p=>{t(o,p);});}else n[c.key]=c.val;},i=r(s);return t(e,i),e}var ee=(s,e,r)=>{let i=n=>{let c=r.triggerPaths.map(u=>n.GetValueByPath(u)),o=Object.create(null);return Object.defineProperty(o,"triggerTargets",{get:()=>c}),Object.defineProperty(o,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(s)[e]}),r.logic({slot:o})};return {value:r.value,targetPath:s,triggerPaths:r.triggerPaths,priority:r.priority??10,logic:i}},te=(s,e,r)=>{if(!s)throw Error("");let t=s,i=(o,p)=>{e.has(o)||e.set(o,new Set),e.get(o).add(p),r.has(p)||r.set(p,new Set),r.get(p).add(o);};return {SetRule:(o,p,u,l={logic:a=>{}})=>{let a=t(p),h=ee(p,u,{...l,triggerPaths:[o]}),y=[o].map(m=>[m,t(m).defaultValue]);if(i(o,p),a.nodeBucket[u])a.nodeBucket[u].setRule(h,y);else {let m=new $(a[u],u,p);m.setRule(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();},SetRules:(o,p,u,l={logic:a=>{}})=>{let a=t(p);for(let m of o)i(m,p);let h=ee(p,u,{...l,triggerPaths:o}),y=o.map(m=>[m,t(m).defaultValue]);if(a.nodeBucket[u])a.nodeBucket[u].setRules(h,y);else {let m=new $(a[u],u,p);m.setRules(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();}}},ne=s=>{let e=s||void 0;if(!e)throw Error("");return {SetStrategy:(t,i,n)=>{e(t).nodeBucket[i].setStrategy(n);}}};var re=s=>{let e=s||void 0;return {SetValidators:(t,i)=>{let n=e(t),c=(p,u,l)=>p(u,l),o=(p,u,l)=>p(u,l);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:p=>c(i.logic,p,e),condition:typeof i.condition=="function"?p=>o(i.condition,p,e):()=>true});}}};function ae(s){let e=new Map,r=new Map,t=new Set,i=(u,l)=>{if(e.get(u)===l)return;e.set(u,l);let a=r.get(u);a&&a(l);};return {pushExecution:(u,l)=>{l&&(t.forEach(a=>i(a,"idle")),t.clear(),e.clear()),u.length!==0&&u.forEach(a=>{t.has(a)||t.add(a),i(a,"calculating"),s(a).forEach(y=>{t.has(y)||(t.add(y),e.has(y)||i(y,"pending"));});});},popExecution:u=>{u.forEach(l=>{i(l,"calculated");});},markError:u=>{i(u,"error"),t.forEach(l=>{let a=e.get(l);l!==u&&(a==="pending"||a==="calculating")&&i(l,"canceled");});},SetTrace:(u,l,a)=>{r.set(u,l);let h=e.get(u)||"idle";return l(h),()=>{r.delete(u);}}}}function oe(s,e,r,t){let i=l=>{let a=s(),h=e(),y=new Set;return a.get(l)?.forEach(m=>y.add(m)),y.size===0?[]:Array.from(y).filter(m=>{let x=h.get(m)||new Set;return !Array.from(x).some(A=>y.has(A))})};return {GetNextDependency:l=>{let a=t();return Array.from(a.get(l)||[])},GetPrevDependency:l=>{let a=r();return Array.from(a.get(l)||[])},GetAllPrevDependency:l=>{let a=e();return Array.from(a.get(l)||[])},GetAllNextDependency:l=>{let a=s();return Array.from(a.get(l)||[])},rebuildDirectDependencyMaps:l=>{let a=new Map,h=new Map;for(let y of l){let m=i(y);a.set(y,new Set(m));for(let x of m)h.has(x)||h.set(x,new Set),h.get(x).add(y);}return {directNextMap:a,directPrevMap:h}}}}function se(s){let e=t=>{let i=[],n=[],c=new Map,o=t.size,p=0,u=0;for(let[l,a]of t)a===0&&n.push(l);if(n.length===0&&o>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;n.length>0;){i.push([...n]);let l=[];for(let a of n){p++,c.set(a,u);let h=s.get(a);if(h)for(let y of h){let m=t.get(y)-1;t.set(y,m),m===0&&l.push(y);}}n=l,u++;}if(p<o)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:i,levelMap:c}};return ()=>{let t=new Map;for(let i of s.keys()){let n=Array.from(s.get(i)||[]);t.has(i)||t.set(i,0);for(let c of n){let o=t.get(c)||0;t.set(c,++o);}}return e(t)}}function ie(){let s=[],e=[],t={canRedo:()=>{},canUndo:()=>{}},i=()=>{if(!s.length)return;let a=s.pop();a?.undoAction(),p(a);},n=()=>{if(!e.length)return;let a=e.pop();a?.redoAction(),u(a,false);},c=a=>{t.canUndo=()=>a(s.length);},o=a=>{t.canRedo=()=>a(e.length);},p=a=>{e.push(a),e.length>100&&e.shift(),t.canRedo(),t.canUndo();},u=(a,h=true)=>{h&&(e.length=0),s.push(a),s.length>100&&s.shift(),t.canUndo(),t.canRedo();};return {Undo:i,Redo:n,PushIntoHistory:u,CreateHistoryAction:(a,h)=>{let[y,m]=a;return {undoAction:()=>h(y),redoAction:()=>h(m)}},initCanUndo:c,initCanRedo:o}}var _=()=>{let s=[];return {on:e=>(s.push(e),()=>{let r=s.indexOf(e);r>-1&&s.splice(r,1);}),call:e=>s.forEach(r=>r(e))}};function le(){let{on:s,call:e}=_();return {onError:s,callOnError:e}}function ce(){let{on:s,call:e}=_();return {onSuccess:s,callOnSuccess:e}}var ue=()=>{let s=new Set,e=new Map,r=(n,c)=>{e.get(n)?.forEach(o=>o(c));},t=(n,c)=>(e.has(n)||e.set(n,new Set),e.get(n).add(c),()=>e.get(n).delete(c));return {usePlugin:n=>(n.apply({on:t}),()=>{s.delete(n);}),emit:r}};function de(){let{on:s,call:e}=_();return {onStart:s,callOnStart:e}}function pe(s,e){let r=false,t=false,i=new Map,n=new Map,c=new Map,o=new Map,p=[],u=new Map,{GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetAllNextDependency:y,rebuildDirectDependencyMaps:m}=oe(()=>i,()=>n,()=>o,()=>c),{SetTrace:x,pushExecution:R,popExecution:O,markError:A}=ae(l),{Undo:L,Redo:E,PushIntoHistory:G,CreateHistoryAction:B,initCanUndo:D,initCanRedo:v}=ie(),{onError:g,callOnError:d}=le(),{onSuccess:f,callOnSuccess:T}=ce(),{onStart:S,callOnStart:F}=de(),{emit:w,usePlugin:V}=ue(),{schema:I,GetFormData:P,GetRenderSchemaByPath:b,GetGroupByPath:C,notifyAll:H,convertToRenderSchema:U}=Z(s,{GetDependencyOrder:()=>p,GetAllNextDependency:y,GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetPathToLevelMap:()=>u},{pushExecution:R,popExecution:O,markError:A},{pushIntoHistory:G,createHistoryAction:B},{callOnError:d,callOnSuccess:T,callOnStart:F,emit:w},e),W=(M,k)=>{let N=C(M),X=U(k,M);return N.children.push(X),N.dirtySignal.value++,X},{SetRule:K,SetRules:j}=te(b,i,n),{SetStrategy:ye}=ne(b),{SetValidators:fe}=re(b),he=se(i),Y=()=>{let M=he();p=M.steps,u=M.levelMap;};return {schema:I,SetRule:(...M)=>{K.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetRules:(...M)=>{j.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetStrategy:ye,SetValidators:fe,SetTrace:x,usePlugin:V,SetValue:(M,k)=>{b(M).dependOn(()=>k);},GetFormData:P,notifyAll:()=>{Y(),H();},AddNewSchema:W,GetAllDependency:()=>i,GetDependencyOrder:()=>p,Undo:L,Redo:E,initCanUndo:D,initCanRedo:v,onError:g,onSuccess:f,onStart:S}}var q=new Map,ge=(s,e,r)=>{try{if(typeof r.signalCreateor!="function"||typeof r.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(q.has(s))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let t=pe(e,r),{schema:i,GetFormData:n,SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,SetValue:l,usePlugin:a,notifyAll:h,SetTrace:y,GetAllDependency:m,GetDependencyOrder:x,AddNewSchema:R,Undo:O,Redo:A,initCanUndo:L,initCanRedo:E,onError:G,onSuccess:B,onStart:D}=t,v={config:{SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,notifyAll:h,SetTrace:y,usePlugin:a},data:{schema:i,GetFormData:n,AddNewSchema:R,SetValue:l},history:{Undo:O,Redo:A,initCanUndo:L,initCanRedo:E},dependency:{GetAllDependency:m,GetDependencyOrder:x},hooks:{onError:G,onSuccess:B,onStart:D}};return q.set(s,v),v}catch(t){throw Error(t)}},st=s=>{if(q.has(s))return q.get(s);throw Error("\u4E0D\u5B58\u5728\u7684id")},it=s=>{q.delete(s);},lt=ge;exports.deleteEngine=it;exports.useEngine=st;exports.useEngineManager=ge;exports.useMeshFlow=lt;
1
+ 'use strict';var J=class{computedRules=[];store={OR:async(e,t)=>{let n,u,r=this.computedRules;for(let a of r){let i=await a.logic(e);if(a.entityId==="__base__"){u=i;continue}if(i){n=a.value;break}}return typeof n>"u"&&(n=u),{res:n,version:t}},PRIORITY:async(e,t)=>{let n=null,u=this.computedRules;try{for(let r of u){let a=await r.logic(e);if(a!==void 0){n=a;break}}}catch(r){throw r}return {res:n,version:t}}};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(t=>Array.from(t)).flat().sort((t,n)=>n.priority-t.priority):this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,t){return this.CurrentStrategy(e,t)}},Y=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,t,n){let u=()=>this.rules;this.strategy=new J(u),this.path=n,this.isDefaultValue=t==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let t=new Set;t.add(e),this.rules.set(e.id,t);}setRules(e,t){t&&this.updateDeps(t);let n=++this.id,u={...e,entityId:n};for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(u);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let a=this.rules.get(r);a&&(a.delete(u),a.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[t,n]of e)this.deps.set(t,n);}setRule(e,t){if(t&&this.updateDeps(t),typeof e.entityId=="string"){this.setDefaultRule(e);return}let n=++this.id,u={...e,entityId:n};if(e)for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(u);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let a=this.rules.get(r);a&&(a.delete(u),a.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}async evaluate(e){let t=null;if(e.GetToken&&(t=e.GetToken()),this.pendingPromise&&this.promiseToken!==t&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=t;let n=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let u=!1;if(typeof e.triggerPath=="string"){u=!0;let i=this.deps.get(e.triggerPath),s=e.GetValueByPath(e.triggerPath);if(typeof i=="object"||typeof s=="object")u=!1;else {let d=Array.from(this.deps.keys());for(let f of d){let c=this.deps.get(f),m=e.GetValueByPath(f);if(c!==m){u=!1;break}}}}if(u)return this.cache;let{res:r,version:a}=await this.strategy.evaluate(e,n);if(t!==this.promiseToken)return this.cache;if(a<this.version)return this.cache;if(this.inferType(r)!==this.contract&&`${this.contract}`,this.cache=r,t===this.promiseToken){let i=Array.from(this.deps.keys());for(let s of i){let d=e.GetValueByPath(s);this.deps.set(s,d);}}return r}catch(u){throw {path:this.path,error:u}}finally{this.promiseToken===t&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},$=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:n=>n||typeof n=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:n=>!!n.required},t={logic:function(n){return n.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(n){return typeof n.maxLength!="number"?false:(t.options={maxLength:n.maxLength},n.type==="input"&&n.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(t);}evaluate(e,t){let n=true,u=[...this.defaultValidators,...this.validators];for(let r of u){if(!r.condition(t))continue;let i=r.logic(e);if(typeof i!="boolean"){n=i;break}}return n}};function ee(l,e,t,n){let u=new Map;return (a,i)=>{let d=Symbol("token");u.set(a,d);let f=false,c=new Set,m=new Set,T=new Set(l.GetAllNextDependency(a));T.add(a);let p=new Map,g=new Map,G=new Map,B=performance.now(),A=l.GetPathToLevelMap(),k=A.get(a)??0,L=0,H=C=>{l.GetAllNextDependency(C).forEach(y=>{let P=A.get(y)||0;P>L&&(L=P);});};H(a),c.add(a);let M=Array.from(i).map(C=>(p.set(C,(p.get(C)||0)+1),{target:C,trigger:a,isReleased:false})),K=performance.now();t.emit("flow:start",{path:a}),t.callOnStart({path:a});let U=async C=>{let h=(o,R)=>{let x=g.get(o)??0,w=Math.max(0,x-1);if(w<=0){let F=p.has(o),v=m.has(o);if(F||v){t.emit("node:intercept",{path:o,type:3});return}g.delete(o),M.push({target:o,trigger:y,isReleased:true}),p.set(o,1),t.emit("node:release",{path:o,type:R,detail:{targetPath:y}});}else g.set(o,w);},{target:y,trigger:P}=C;try{if(u.get(a)!==d)return;let o=!1,R=!1,x=e.GetRenderSchemaByPath(y);t.emit("node:start",{path:y});for(let w in x.nodeBucket){let F=x.nodeBucket[w],v=await F.evaluate({affectKey:w,triggerPath:P,GetRenderSchemaByPath:e.GetRenderSchemaByPath,GetValueByPath:S=>e.GetRenderSchemaByPath(S).defaultValue,GetToken:()=>d});if(u.get(a)!==d){t.emit("node:intercept",{path:y,type:1});return}w==="options"&&(v.some(E=>E.value==x.defaultValue)||(x.defaultValue=void 0,o=!0)),v!==x[w]&&(x[w]=v,o=!0,t.emit("node:bucket:success",{path:y,key:w,value:v})),F.isForceNotify()&&(R=!0),o&&n.flushPathSet.add(y);let b=l.GetNextDependency(y);(o||R)&&(l.GetAllNextDependency(y).forEach(E=>T.add(E)),w==="defaultValue"&&H(y));for(let S of b){if(c.has(S)){t.emit("node:intercept",{path:S,type:2});continue}if(m.has(S)||p.has(S)){t.emit("node:intercept",{path:S,type:3});continue}if(o||R){if(!g.has(S)&&!c.has(S)&&!p.has(S)&&!m.has(S)){let O=l.GetPrevDependency(S).filter(N=>T.has(N)).length;g.set(S,O),t.emit("node:pending",{path:S});}h(S,1);}else if(g.has(S))h(S,2);else {let O=A.get(S);G.has(O)||G.set(O,new Set);let N=G.get(O);!N.has(S)&&!c.has(S)&&!p.has(S)&&(N.add(S),t.emit("node:stagnate",{path:S,type:1}));}}}if(t.emit("node:success",{path:y}),c.add(y),performance.now()-B>16&&(await new Promise(w=>requestAnimationFrame(w)),B=performance.now(),u.get(a)!==d))return;u.get(a)===d&&n.requestUpdate();}catch(o){t.emit("node:error",{path:y,error:o});let R=Symbol("abort");u.set(a,R),M.length=0,g.clear(),m.clear(),t.callOnError(o);}finally{if(u.get(a)===d&&(m.delete(y),!f)){let o=m.size||g.size||p.size;t.emit("flow:fire",{path:y,type:o>0?1:2,detail:{remaining:o}}),_();}}},_=async()=>{if(u.get(a)!==d){f=false;return}f=true;try{for(;u.get(a)===d;){if(M.length>0){if(m.size>=20){f=!1;return}let P=M[0],{target:o}=P,R=A.get(o)??0;if(R>k){M.shift();let w=p.get(o)||0;if(w<=1?p.delete(o):p.set(o,w-1),!g.has(o)){let v=l.GetPrevDependency(o).filter(b=>T.has(b)&&!c.has(b)).length;v>0?(g.set(o,v),t.emit("node:intercept",{path:o,type:4,detail:{targetLevel:R,currentLevel:k,pendingParentsCount:v}})):g.set(o,0);}continue}M.shift();let x=p.get(o)||0;if(x<=1?p.delete(o):p.set(o,x-1),c.has(o)){t.emit("node:intercept",{path:o,type:2});continue}m.add(o),t.emit("node:processing",{path:o}),U(P);continue}if(m.size>0){t.emit("flow:wait",{type:1,detail:{nums:m.size}}),f=!1;return}if(g.size>0&&m.size>0)return;let C=new Set;for(let P of G.keys())C.add(P);for(let[P]of g){let o=A.get(P)??0;o>k&&C.add(o);}let h=Array.from(C).sort((P,o)=>P-o);if(h.length===0)break;let y=h[0];if(y<=L){k=y,G.has(y)&&(G.get(y).forEach(R=>{M.push({target:R,trigger:a,isReleased:!0}),p.set(R,(p.get(R)||0)+1);}),G.delete(y));let P=[];for(let[o,R]of g)(A.get(o)??0)===y&&P.push(o);P.forEach(o=>{g.delete(o),M.push({target:o,trigger:a,isReleased:!0}),p.set(o,(p.get(o)||0)+1),t.emit("node:release",{path:o,type:3,detail:{level:y}});});continue}else {G.forEach(P=>P.forEach(o=>c.add(o))),G.clear();break}}}finally{if(f=false,M.length===0&&m.size===0&&G.size===0&&u.get(a)===d){let C=performance.now();t.emit("flow:success",{duration:(C-K).toFixed(2)+"ms"}),Promise.resolve().then(()=>{t.callOnSuccess();});}}};_();}}function te(l,e,t,n,u){let r=me(l),a=0,i=new Map,s=new Map,d=new Map,f=false,c=new Set,m=false,T=true,p=null,g=h=>{let y=i.get(h);return s.get(y)},G=h=>d.get(h),B=async()=>{let h=Array.from(c);c.clear();for(let y of h){let P=g(y);u.signalTrigger(P.dirtySignal);}},A=()=>{f||(f=true,Promise.resolve().then(()=>{try{for(;c.size>0;)B();}finally{f=false;}}));},z=()=>{let h=(y,P,o)=>{if(typeof y!="object"||y===null||Array.isArray(y)){if(o.length>0){let x=o[o.length-1];P[x]=g(o.join(".")).defaultValue;}return}let R=Object.getOwnPropertyNames(y);for(let x of R)o.push(x),h(y[x],y,o),o.pop();};return h(r,null,[]),r},k=ee(e,{GetRenderSchemaByPath:g},n,{requestUpdate:A,flushPathSet:c}),L=async()=>(m&&p||(m=true,p=(async()=>{let h=e.GetDependencyOrder(),y=performance.now(),P=performance.now();try{for(let R=0;R<h.length;R++){let x=h[R];await Promise.all(x.map(async w=>{let F=g(w),v=!1;for(let b in F.nodeBucket){let S=await F.nodeBucket[b].evaluate({affectKey:b,triggerPath:void 0,GetRenderSchemaByPath:g,GetValueByPath:E=>g(E).defaultValue,isSameToken:()=>!0});if(b==="options"){let E=!1,O=F.defaultValue;for(let N of S)if(N.value==O){E=!0;break}E||(F.defaultValue=void 0,v=!0);}S!==F[b]&&(F[b]=S,v=!0);}v&&c.add(w);})),performance.now()-P>12&&(await new Promise(w=>requestAnimationFrame(w)),P=performance.now());}c.size>0&&A(),T=!1;let o=performance.now();n.emit("flow:success",{duration:(o-y).toFixed(2)+"ms"}),n.callOnSuccess();}catch(o){throw n.emit("node:error",{path:o.path,error:o.error}),n.callOnError(o),o}finally{m=false,p=null,T=false;}})()),p),H=async h=>{if(T)return;if(!h)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!g(h))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");c.add(h),A();let P=e.GetNextDependency(h);M(P,h);};async function M(h,y){k(y,h);}let K=h=>{if(!h)throw Error("\u6CA1\u6709\u8DEF\u5F84");let y=g(h);y.nodeBucket.defaultValue&&y.nodeBucket.defaultValue.updateInputValueRule(y.defaultValue);},U=(h,y="")=>{let P="name"in h?h.name:void 0,o=P?y===""?P:`${y}.${P}`:y,R=u.signalCreateor(),x=a++,w={getRenderSchema:b=>g(b)},F=async(b,S)=>{let E=b(S),O=g(S.path),N=t.createHistoryAction([{path:S.path,value:O.defaultValue},{path:S.path,value:E}],async q=>{let Q=g(q.path);Q.defaultValue=q.value,K(q.path),await H(q.path);});O.defaultValue=E,t.pushIntoHistory(N),K(S.path),await H(S.path);},v={...h,disabled:!!h.disabled,hidden:"hidden"in h?h.hidden:false,readonly:"readonly"in h?h.readonly:false,required:"required"in h?h.required:false,path:o,dirtySignal:R,uid:x,nodeBucket:{},validators:new $(o),theme:"secondary",dependOn:async b=>await F(b,{...w,path:o})};return h.type==="group"&&(delete v.nodeBucket,delete v.validators,v.children=h.children.map(b=>U(b,o)),d.set(v.path,v)),i.set(v.path,v.uid),s.set(v.uid,v),v};return {schema:U(l),GetFormData:()=>z(),GetRenderSchemaByPath:g,GetGroupByPath:G,notifyAll:L,convertToRenderSchema:U}}function me(l,e={}){let t=r=>{if(r.type=="group")return {key:r.name||"",isGroup:true,val:r.children.reduce((a,i)=>[...a,t(i)],[])};if(r.type=="input"||r.type=="number"||r.type=="select"||r.type=="checkbox")return {key:r.name,isGroup:false,val:r.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${r.type}`)},n=(r,a)=>{if(a.isGroup){let i={};a.key===""?i=r:r[a.key]=i,a.val.forEach(s=>{n(i,s);});}else r[a.key]=a.val;},u=t(l);return n(e,u),e}var ne=(l,e,t)=>{let u=r=>{let a=t.triggerPaths.map(d=>r.GetValueByPath(d)),i=Object.create(null);return Object.defineProperty(i,"triggerTargets",{get:()=>a}),Object.defineProperty(i,"affectedTatget",{get:()=>r.GetRenderSchemaByPath(l)[e]}),t.logic({slot:i})};return {value:t.value,targetPath:l,triggerPaths:t.triggerPaths,priority:t.priority??10,logic:u}},re=(l,e,t)=>{if(!l)throw Error("");let n=l,u=(i,s)=>{e.has(i)||e.set(i,new Set),e.get(i).add(s),t.has(s)||t.set(s,new Set),t.get(s).add(i);};return {SetRule:(i,s,d,f={logic:c=>{}})=>{let c=n(s),m=ne(s,d,{...f,triggerPaths:[i]}),T=[i].map(p=>[p,n(p).defaultValue]);if(u(i,s),c.nodeBucket[d])c.nodeBucket[d].setRule(m,T);else {let p=new Y(c[d],d,s);p.setRule(m,T),c.nodeBucket[d]=p;}f.forceNotify&&c.nodeBucket[d].forceNotify();},SetRules:(i,s,d,f={logic:c=>{}})=>{let c=n(s);for(let p of i)u(p,s);let m=ne(s,d,{...f,triggerPaths:i}),T=i.map(p=>[p,n(p).defaultValue]);if(c.nodeBucket[d])c.nodeBucket[d].setRules(m,T);else {let p=new Y(c[d],d,s);p.setRules(m,T),c.nodeBucket[d]=p;}f.forceNotify&&c.nodeBucket[d].forceNotify();}}},ae=l=>{let e=l||void 0;if(!e)throw Error("");return {SetStrategy:(n,u,r)=>{e(n).nodeBucket[u].setStrategy(r);}}};var oe=l=>{let e=l||void 0;return {SetValidators:(n,u)=>{let r=e(n),a=(s,d,f)=>s(d,f),i=(s,d,f)=>s(d,f);if(!r.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");r.validators.setValidators({logic:s=>a(u.logic,s,e),condition:typeof u.condition=="function"?s=>i(u.condition,s,e):()=>true});}}};function se(){let l=new Map,e=new Map,t=new Set,n=(a,i)=>{l.set(a,i);let s=e.get(a);s&&s(i);};return {SetTrace:(a,i)=>{e.set(a,i);let s=l.get(a)||"idle";return i(s),()=>{e.delete(a);}},useTrace:()=>({apply:i=>{i.on("flow:start",()=>{t.forEach(s=>n(s,"idle")),t.clear(),l.clear();}),i.on("node:release",({path:s})=>{}),i.on("node:pending",({path:s})=>{t.add(s),(!l.has(s)||l.get(s)==="idle")&&n(s,"pending");}),i.on("node:start",({path:s})=>{t.add(s),n(s,"calculating");}),i.on("node:success",({path:s})=>{n(s,"calculated");}),i.on("node:intercept",({path:s,type:d})=>{}),i.on("node:stagnate",({path:s})=>{n(s,"pending");}),i.on("node:error",({path:s})=>n(s,"error"));}})}}function ie(l,e,t,n){let u=f=>{let c=l(),m=e(),T=new Set;return c.get(f)?.forEach(p=>T.add(p)),T.size===0?[]:Array.from(T).filter(p=>{let g=m.get(p)||new Set;return !Array.from(g).some(A=>T.has(A))})};return {GetNextDependency:f=>{let c=n();return Array.from(c.get(f)||[])},GetPrevDependency:f=>{let c=t();return Array.from(c.get(f)||[])},GetAllPrevDependency:f=>{let c=e();return Array.from(c.get(f)||[])},GetAllNextDependency:f=>{let c=l();return Array.from(c.get(f)||[])},rebuildDirectDependencyMaps:f=>{let c=new Map,m=new Map;for(let T of f){let p=u(T);c.set(T,new Set(p));for(let g of p)m.has(g)||m.set(g,new Set),m.get(g).add(T);}return {directNextMap:c,directPrevMap:m}}}}function le(l){let e=n=>{let u=[],r=[],a=new Map,i=n.size,s=0,d=0;for(let[f,c]of n)c===0&&r.push(f);if(r.length===0&&i>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;r.length>0;){u.push([...r]);let f=[];for(let c of r){s++,a.set(c,d);let m=l.get(c);if(m)for(let T of m){let p=n.get(T)-1;n.set(T,p),p===0&&f.push(T);}}r=f,d++;}if(s<i)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:u,levelMap:a}};return ()=>{let n=new Map;for(let u of l.keys()){let r=Array.from(l.get(u)||[]);n.has(u)||n.set(u,0);for(let a of r){let i=n.get(a)||0;n.set(a,++i);}}return e(n)}}function ce(){let l=[],e=[],n={canRedo:()=>{},canUndo:()=>{}},u=()=>{if(!l.length)return;let c=l.pop();c?.undoAction(),s(c);},r=()=>{if(!e.length)return;let c=e.pop();c?.redoAction(),d(c,false);},a=c=>{n.canUndo=()=>c(l.length);},i=c=>{n.canRedo=()=>c(e.length);},s=c=>{e.push(c),e.length>100&&e.shift(),n.canRedo(),n.canUndo();},d=(c,m=true)=>{m&&(e.length=0),l.push(c),l.length>100&&l.shift(),n.canUndo(),n.canRedo();};return {Undo:u,Redo:r,PushIntoHistory:d,CreateHistoryAction:(c,m)=>{let[T,p]=c;return {undoAction:()=>m(T),redoAction:()=>m(p)}},initCanUndo:a,initCanRedo:i}}var W=()=>{let l=[];return {on:e=>(l.push(e),()=>{let t=l.indexOf(e);t>-1&&l.splice(t,1);}),call:e=>l.forEach(t=>t(e))}};function ue(){let{on:l,call:e}=W();return {onError:l,callOnError:e}}function de(){let{on:l,call:e}=W();return {onSuccess:l,callOnSuccess:e}}var pe=()=>{let l=new Set,e=new Map,t=(r,a)=>{e.get(r)?.forEach(i=>i(a));},n=(r,a)=>(e.has(r)||e.set(r,new Set),e.get(r).add(a),()=>e.get(r).delete(a));return {usePlugin:r=>{let a=new Set,i=(s,d)=>{let f=n(s,d);return a.add(f),f};return r.apply({on:i}),l.add(r),()=>{a.forEach(s=>s()),a.clear(),l.delete(r);}},emit:t}};function ye(){let{on:l,call:e}=W();return {onStart:l,callOnStart:e}}function fe(l,e){let t=false,n=false,u=new Map,r=new Map,a=new Map,i=new Map,s=[],d=new Map,{GetNextDependency:c,GetPrevDependency:m,GetAllPrevDependency:T,GetAllNextDependency:p,rebuildDirectDependencyMaps:g}=ie(()=>u,()=>r,()=>i,()=>a),{Undo:G,Redo:B,PushIntoHistory:A,CreateHistoryAction:z,initCanUndo:k,initCanRedo:L}=ce(),{onError:H,callOnError:M}=ue(),{onSuccess:K,callOnSuccess:U}=de(),{onStart:_,callOnStart:C}=ye(),{emit:h,usePlugin:y}=pe(),{SetTrace:P,useTrace:o}=se(),R=o();y(R);let{schema:x,GetFormData:w,GetRenderSchemaByPath:F,GetGroupByPath:v,notifyAll:b,convertToRenderSchema:S}=te(l,{GetDependencyOrder:()=>s,GetAllNextDependency:p,GetNextDependency:c,GetPrevDependency:m,GetAllPrevDependency:T,GetPathToLevelMap:()=>d},{pushIntoHistory:A,createHistoryAction:z},{callOnError:M,callOnSuccess:U,callOnStart:C,emit:h},e),E=(D,V)=>{let I=v(D),Z=S(V,D);return I.children.push(Z),I.dirtySignal.value++,Z},{SetRule:O,SetRules:N}=re(F,u,r),{SetStrategy:q}=ae(F),{SetValidators:Q}=oe(F),he=le(u),X=()=>{let D=he();s=D.steps,d=D.levelMap;};return {schema:x,SetRule:(...D)=>{O.apply(null,D),t=true,!n&&new Promise((V,I)=>{n=true,V();}).then(()=>{if(X(),t){let{directNextMap:V,directPrevMap:I}=g(s.flat());a=V,i=I;}}).finally(()=>{n=false,t=false;});},SetRules:(...D)=>{N.apply(null,D),t=true,!n&&new Promise((V,I)=>{n=true,V();}).then(()=>{if(X(),t){let{directNextMap:V,directPrevMap:I}=g(s.flat());a=V,i=I;}}).finally(()=>{n=false,t=false;});},SetStrategy:q,SetValidators:Q,SetTrace:P,usePlugin:y,SetValue:(D,V)=>{F(D).dependOn(()=>V);},GetValue:(D,V="defaultValue")=>F(D)[V],GetFormData:w,GetGroupByPath:v,notifyAll:async()=>{X(),await b();},AddNewSchema:E,GetAllDependency:()=>u,GetDependencyOrder:()=>s,Undo:G,Redo:B,initCanUndo:k,initCanRedo:L,onError:H,onSuccess:K,onStart:_}}var j=new Map,ge=(l,e,t)=>{try{if(typeof t.signalCreateor!="function"||typeof t.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(j.has(l))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let n=fe(e,t),{schema:u,GetFormData:r,SetRule:a,SetRules:i,SetStrategy:s,SetValidators:d,SetValue:f,GetValue:c,usePlugin:m,GetGroupByPath:T,notifyAll:p,SetTrace:g,GetAllDependency:G,GetDependencyOrder:B,AddNewSchema:A,Undo:z,Redo:k,initCanUndo:L,initCanRedo:H,onError:M,onSuccess:K,onStart:U}=n,_={config:{SetRule:a,SetRules:i,SetStrategy:s,SetValidators:d,notifyAll:p,SetTrace:g,usePlugin:m},data:{schema:u,GetFormData:r,AddNewSchema:A,SetValue:f,GetValue:c,GetGroupByPath:T},history:{Undo:z,Redo:k,initCanUndo:L,initCanRedo:H},dependency:{GetAllDependency:G,GetDependencyOrder:B},hooks:{onError:M,onSuccess:K,onStart:U}};return j.set(l,_),_}catch(n){throw Error(n)}},it=l=>{if(j.has(l))return j.get(l);throw Error("\u4E0D\u5B58\u5728\u7684id")},lt=l=>{j.delete(l);},ct=ge;exports.deleteEngine=lt;exports.useEngine=it;exports.useEngineManager=ge;exports.useMeshFlow=ct;
package/index.mjs CHANGED
@@ -1 +1 @@
1
- var Q=class{computedRules=[];store={OR:async(e,r)=>{let t,i,n=this.computedRules;for(let c of n){let o=await c.logic(e);if(c.entityId==="__base__"){i=o;continue}if(o){t=c.value;break}}return typeof t>"u"&&(t=i),{res:t,version:r}},PRIORITY:async(e,r)=>{let t=null,i=this.computedRules;try{for(let n of i){let c=await n.logic(e);if(c!==void 0){t=c;break}}}catch(n){throw n}return {res:t,version:r}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"?this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat().sort((r,t)=>t.priority-r.priority):this.computedRules=Array.from(e.values()).map(r=>Array.from(r)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,r){return this.CurrentStrategy(e,r)}},$=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,r,t){let i=()=>this.rules;this.strategy=new Q(i),this.path=t,this.isDefaultValue=r==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let r=new Set;r.add(e),this.rules.set(e.id,r);}setRules(e,r){r&&this.updateDeps(r);let t=++this.id,i={...e,entityId:t};for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[r,t]of e)this.deps.set(r,t);}setRule(e,r){if(r&&this.updateDeps(r),typeof e.entityId=="string"){this.setDefaultRule(e);return}let t=++this.id,i={...e,entityId:t};if(e)for(let n of e.triggerPaths)this.rules.has(n)||this.rules.set(n,new Set),this.rules.get(n).add(i);return this.strategy.updateComputedRules(),()=>{for(let n of e.triggerPaths){let c=this.rules.get(n);c&&(c.delete(i),c.size===0&&(this.rules.delete(n),this.deps.delete(n)));}this.strategy.updateComputedRules();}}async evaluate(e){let r=null;if(e.GetToken&&(r=e.GetToken()),this.pendingPromise&&this.promiseToken!==r&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=r;let t=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let i=!1;if(typeof e.triggerPath=="string"){i=!0;let o=this.deps.get(e.triggerPath),p=e.GetValueByPath(e.triggerPath);if(typeof o=="object"||typeof p=="object")i=!1;else {let u=Array.from(this.deps.keys());for(let l of u){let a=this.deps.get(l),h=e.GetValueByPath(l);if(a!==h){i=!1;break}}}}if(i)return this.cache;let{res:n,version:c}=await this.strategy.evaluate(e,t);if(r!==this.promiseToken)return this.cache;if(c<this.version)return this.cache;if(this.inferType(n)!==this.contract&&`${this.contract}`,this.cache=n,r===this.promiseToken){let o=Array.from(this.deps.keys());for(let p of o){let u=e.GetValueByPath(p);this.deps.set(p,u);}}return n}catch(i){throw {path:this.path,info:i}}finally{this.promiseToken===r&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},z=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:t=>t||typeof t=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:t=>!!t.required},r={logic:function(t){return t.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(t){return typeof t.maxLength!="number"?false:(r.options={maxLength:t.maxLength},t.type==="input"&&t.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(r);}evaluate(e,r){let t=true,i=[...this.defaultValidators,...this.validators];for(let n of i){if(!n.condition(r))continue;let o=n.logic(e);if(typeof o!="boolean"){t=o;break}}return t}};function J(s,e,r,t,i){let n=new Map;return (o,p)=>{let l=Symbol("token");n.set(o,l);let a=false,h=new Set,y=new Set,m=new Set(s.GetAllNextDependency(o));m.add(o);let x=new Map,R=new Map,O=performance.now(),A=s.GetPathToLevelMap(),E=A.get(o)??0;m.forEach(v=>{if(v===o||p.includes(v))return;let d=s.GetPrevDependency(v).filter(f=>m.has(f)).length;d>0&&R.set(v,d);}),h.add(o);let G=Array.from(p).map(v=>(x.set(v,(x.get(v)||0)+1),{target:v,trigger:o,isReleased:false}));e.pushExecution([...Array.from(p),o],true),`${o}${l.description}`,t.callOnStart({path:o});let B=async v=>{let{target:g,trigger:d}=v;try{if(n.get(o)!==l)return;let f=!1,T=!1,S=r.GetRenderSchemaByPath(g);t.emit("node:start",{path:g});for(let F in S.nodeBucket){let w=S.nodeBucket[F],V=await w.evaluate({affectKey:F,triggerPath:d,GetRenderSchemaByPath:r.GetRenderSchemaByPath,GetValueByPath:P=>r.GetRenderSchemaByPath(P).defaultValue,GetToken:()=>l});if(n.get(o)!==l){t.emit("node:intercept",{path:g,reason:`\u4EE4\u724C\u8FC7\u671F\uFF0C\u4E22\u5F03${g}\u65E7\u4EFB\u52A1\u8BA1\u7B97\u7ED3\u679C`});return}F==="options"&&(V.some(b=>b.value==S.defaultValue)||(S.defaultValue=void 0,f=!0)),V!==S[F]&&(S[F]=V,f=!0,t.emit("node:bucket:success",{path:g,key:F,value:V})),w.isForceNotify()&&(T=!0),f&&i.flushPathSet.add(g);let I=s.GetNextDependency(g);(f||T)&&s.GetAllNextDependency(g).forEach(b=>m.add(b));for(let P of I){if(h.has(P)){t.emit("node:intercept",{path:P,reason:` \u4E0B\u6E38 ${P} \u5DF2\u7531\u5176\u4ED6\u8DEF\u5F84\u5904\u7406`});continue}if(f||T){if(!R.has(P)&&!h.has(P)&&!x.has(P)){let H=s.GetPrevDependency(P).filter(U=>m.has(U)).length;R.set(P,H);}let b=R.get(P)??0,C=Math.max(0,b-1);C<=0?(R.delete(P),G.push({target:P,trigger:g,isReleased:!0}),x.set(P,1),e.pushExecution([P]),t.emit("node:release",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u53D8\u4E86`})):R.set(P,C);}else t.emit("node:stagnate",{path:P,reason:` \u4E0A\u6E38${g} \u503C\u672A\u53D8`});}}if(t.emit("node:success",{path:g}),h.add(g),performance.now()-O>16&&(await new Promise(F=>requestAnimationFrame(F)),O=performance.now(),n.get(o)!==l))return;n.get(o)===l&&i.requestUpdate();}catch(f){t.emit("node:error",{path:g,error:f});let T=Symbol("abort");n.set(o,T),G.length=0,R.clear(),y.clear(),e.markError(g),t.callOnError(f);}finally{n.get(o)===l&&(y.delete(g),e.popExecution([g]),a||(t.emit("flow:fire",{path:g,reason:"\u4EFB\u52A1\u5F52\u822A"}),D()));}},D=async()=>{if(n.get(o)!==l){a=false;return}a=true;try{for(;(G.length>0||R.size>0)&&n.get(o)===l;){if(G.length>0){if(y.size>=20){a=!1;return}let v=G.shift(),{target:g}=v;if(h.has(g)){t.emit("node:intercept",{path:g,reason:` \u62D2\u7EDD\u91CD\u5165${g},\u5DF2\u8BA1\u7B97\u5B8C\u6210`});continue}let d=x.get(g)||0;d<=1?x.delete(g):x.set(g,d-1);let f=A.get(g)??0;if(f>E+1&&!v.isReleased){t.emit("node:intercept",{path:g,reason:` ${g} \u5C42\u7EA7\u592A\u6DF1(${f})\uFF0C\u5F53\u524D\u6C34\u4F4D(${E})`}),R.set(g,1);continue}y.add(g),t.emit("node:processing",{path:g}),e.pushExecution([g]),B(v);continue}if(y.size>0){t.emit("flow:wait",{reason:`\u961F\u5217\u5DF2\u7A7A,\u7184\u706B\u7B49\u5F85\uFF0C\u7B49\u5F85\u5F02\u6B65\u4EFB\u52A1\u5F52\u822A | \u98DE\u884C\u4E2D: ${Array.from(y).join(",")} | `}),a=!1;return}if(R.size>0){let v=!1,g=[];for(let[d]of R)s.GetPrevDependency(d).some(S=>h.has(S)?!1:y.has(S)||x.has(S)||m.has(S)?!0:(A.get(S)??0)>E)||g.push(d);if(g.length>0&&(g.forEach(d=>{R.delete(d),G.push({target:d,trigger:o,isReleased:!0}),x.set(d,1),e.pushExecution([d]);}),v=!0),v)continue;if(Array.from(R.keys()).some(f=>s.GetPrevDependency(f).some(S=>m.has(S)&&!h.has(S)))){t.emit("flow:wait",{reason:"\u5C1A\u6709\u6D3B\u8DC3\u4F9D\u8D56 \u672A\u5B8C\u6210,\u7184\u706B\u7B49\u5F85"}),a=!1;return}if(E++,E>2e3)break;continue}}}finally{R.size,y.size,G.length,a=false,t.emit("flow:wait",{reason:"\u7184\u706B\u9759\u9ED8"}),Promise.resolve().then(()=>{R.size===0&&y.size===0&&G.length===0&&t.callOnSuccess();});}};D();}}function Z(s,e,r,t,i,n){let c=me(s),o=0,p=new Map,u=new Map,l=new Map,a=false,h=new Set,y=d=>{let f=p.get(d);return u.get(f)},m=d=>l.get(d),x=async()=>{let d=Array.from(h);h.clear();for(let f of d){let T=y(f);n.signalTrigger(T.dirtySignal);}},R=()=>{a||(a=true,Promise.resolve().then(()=>{try{for(;h.size>0;)x();}finally{a=false;}}));},O=()=>{let d=(f,T,S)=>{if(typeof f!="object"||f===null||Array.isArray(f)){if(S.length>0){let w=S[S.length-1];T[w]=y(S.join(".")).defaultValue;}return}let F=Object.getOwnPropertyNames(f);for(let w of F)S.push(w),d(f[w],f,S),S.pop();};return d(c,null,[]),c},A=J(e,r,{GetRenderSchemaByPath:y},i,{requestUpdate:R,flushPathSet:h}),L=async()=>{let d=e.GetDependencyOrder().flat();try{for(let f of d){let T=y(f);for(let S in T.nodeBucket){let F=await T.nodeBucket[S].evaluate({affectKey:S,triggerPath:void 0,GetRenderSchemaByPath:y,GetValueByPath:w=>y(w).defaultValue,isSameToken:()=>!1});if(S==="options"){let w=!1,V=T.defaultValue;for(let I of F)I.value==V&&(w=!0);w||(T.defaultValue=void 0,R());}F!==T[S]&&(T[S]=F,h.add(f),R());}}}catch(f){i.callOnError(f);}},E=async d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!y(d))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");h.add(d),R();let T=e.GetNextDependency(d);G(T,d),r.popExecution([d],true);};async function G(d,f){A(f,d);}let B=d=>{if(!d)throw Error("\u6CA1\u6709\u8DEF\u5F84");let f=y(d);f.nodeBucket.defaultValue&&f.nodeBucket.defaultValue.updateInputValueRule(f.defaultValue);},D=(d,f="")=>{let T="name"in d?d.name:void 0,S=T?f===""?T:`${f}.${T}`:f,F=n.signalCreateor(),w=o++,V={getRenderSchema:b=>y(b)},I=async(b,C)=>{let H=b(C),U=y(C.path),W=t.createHistoryAction([{path:C.path,value:U.defaultValue},{path:C.path,value:H}],async K=>{let j=y(K.path);j.defaultValue=K.value,B(K.path),await E(K.path);});U.defaultValue=H,t.pushIntoHistory(W),B(C.path),await E(C.path);},P={...d,disabled:!!d.disabled,hidden:"hidden"in d?d.hidden:false,readonly:"readonly"in d?d.readonly:false,required:"required"in d?d.required:false,path:S,dirtySignal:F,uid:w,nodeBucket:{},validators:new z(S),theme:"secondary",dependOn:async b=>await I(b,{...V,path:S})};return d.type==="group"&&(delete P.nodeBucket,delete P.validators,P.children=d.children.map(b=>D(b,S)),l.set(P.path,P)),p.set(P.path,P.uid),u.set(P.uid,P),P};return {schema:D(s),GetFormData:()=>O(),GetRenderSchemaByPath:y,GetGroupByPath:m,notifyAll:L,convertToRenderSchema:D}}function me(s,e={}){let r=n=>{if(n.type=="group")return {key:n.name||"",isGroup:true,val:n.children.reduce((c,o)=>[...c,r(o)],[])};if(n.type=="input"||n.type=="number"||n.type=="select"||n.type=="checkbox")return {key:n.name,isGroup:false,val:n.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${n.type}`)},t=(n,c)=>{if(c.isGroup){let o={};c.key===""?o=n:n[c.key]=o,c.val.forEach(p=>{t(o,p);});}else n[c.key]=c.val;},i=r(s);return t(e,i),e}var ee=(s,e,r)=>{let i=n=>{let c=r.triggerPaths.map(u=>n.GetValueByPath(u)),o=Object.create(null);return Object.defineProperty(o,"triggerTargets",{get:()=>c}),Object.defineProperty(o,"affectedTatget",{get:()=>n.GetRenderSchemaByPath(s)[e]}),r.logic({slot:o})};return {value:r.value,targetPath:s,triggerPaths:r.triggerPaths,priority:r.priority??10,logic:i}},te=(s,e,r)=>{if(!s)throw Error("");let t=s,i=(o,p)=>{e.has(o)||e.set(o,new Set),e.get(o).add(p),r.has(p)||r.set(p,new Set),r.get(p).add(o);};return {SetRule:(o,p,u,l={logic:a=>{}})=>{let a=t(p),h=ee(p,u,{...l,triggerPaths:[o]}),y=[o].map(m=>[m,t(m).defaultValue]);if(i(o,p),a.nodeBucket[u])a.nodeBucket[u].setRule(h,y);else {let m=new $(a[u],u,p);m.setRule(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();},SetRules:(o,p,u,l={logic:a=>{}})=>{let a=t(p);for(let m of o)i(m,p);let h=ee(p,u,{...l,triggerPaths:o}),y=o.map(m=>[m,t(m).defaultValue]);if(a.nodeBucket[u])a.nodeBucket[u].setRules(h,y);else {let m=new $(a[u],u,p);m.setRules(h,y),a.nodeBucket[u]=m;}l.forceNotify&&a.nodeBucket[u].forceNotify();}}},ne=s=>{let e=s||void 0;if(!e)throw Error("");return {SetStrategy:(t,i,n)=>{e(t).nodeBucket[i].setStrategy(n);}}};var re=s=>{let e=s||void 0;return {SetValidators:(t,i)=>{let n=e(t),c=(p,u,l)=>p(u,l),o=(p,u,l)=>p(u,l);if(!n.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");n.validators.setValidators({logic:p=>c(i.logic,p,e),condition:typeof i.condition=="function"?p=>o(i.condition,p,e):()=>true});}}};function ae(s){let e=new Map,r=new Map,t=new Set,i=(u,l)=>{if(e.get(u)===l)return;e.set(u,l);let a=r.get(u);a&&a(l);};return {pushExecution:(u,l)=>{l&&(t.forEach(a=>i(a,"idle")),t.clear(),e.clear()),u.length!==0&&u.forEach(a=>{t.has(a)||t.add(a),i(a,"calculating"),s(a).forEach(y=>{t.has(y)||(t.add(y),e.has(y)||i(y,"pending"));});});},popExecution:u=>{u.forEach(l=>{i(l,"calculated");});},markError:u=>{i(u,"error"),t.forEach(l=>{let a=e.get(l);l!==u&&(a==="pending"||a==="calculating")&&i(l,"canceled");});},SetTrace:(u,l,a)=>{r.set(u,l);let h=e.get(u)||"idle";return l(h),()=>{r.delete(u);}}}}function oe(s,e,r,t){let i=l=>{let a=s(),h=e(),y=new Set;return a.get(l)?.forEach(m=>y.add(m)),y.size===0?[]:Array.from(y).filter(m=>{let x=h.get(m)||new Set;return !Array.from(x).some(A=>y.has(A))})};return {GetNextDependency:l=>{let a=t();return Array.from(a.get(l)||[])},GetPrevDependency:l=>{let a=r();return Array.from(a.get(l)||[])},GetAllPrevDependency:l=>{let a=e();return Array.from(a.get(l)||[])},GetAllNextDependency:l=>{let a=s();return Array.from(a.get(l)||[])},rebuildDirectDependencyMaps:l=>{let a=new Map,h=new Map;for(let y of l){let m=i(y);a.set(y,new Set(m));for(let x of m)h.has(x)||h.set(x,new Set),h.get(x).add(y);}return {directNextMap:a,directPrevMap:h}}}}function se(s){let e=t=>{let i=[],n=[],c=new Map,o=t.size,p=0,u=0;for(let[l,a]of t)a===0&&n.push(l);if(n.length===0&&o>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;n.length>0;){i.push([...n]);let l=[];for(let a of n){p++,c.set(a,u);let h=s.get(a);if(h)for(let y of h){let m=t.get(y)-1;t.set(y,m),m===0&&l.push(y);}}n=l,u++;}if(p<o)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:i,levelMap:c}};return ()=>{let t=new Map;for(let i of s.keys()){let n=Array.from(s.get(i)||[]);t.has(i)||t.set(i,0);for(let c of n){let o=t.get(c)||0;t.set(c,++o);}}return e(t)}}function ie(){let s=[],e=[],t={canRedo:()=>{},canUndo:()=>{}},i=()=>{if(!s.length)return;let a=s.pop();a?.undoAction(),p(a);},n=()=>{if(!e.length)return;let a=e.pop();a?.redoAction(),u(a,false);},c=a=>{t.canUndo=()=>a(s.length);},o=a=>{t.canRedo=()=>a(e.length);},p=a=>{e.push(a),e.length>100&&e.shift(),t.canRedo(),t.canUndo();},u=(a,h=true)=>{h&&(e.length=0),s.push(a),s.length>100&&s.shift(),t.canUndo(),t.canRedo();};return {Undo:i,Redo:n,PushIntoHistory:u,CreateHistoryAction:(a,h)=>{let[y,m]=a;return {undoAction:()=>h(y),redoAction:()=>h(m)}},initCanUndo:c,initCanRedo:o}}var _=()=>{let s=[];return {on:e=>(s.push(e),()=>{let r=s.indexOf(e);r>-1&&s.splice(r,1);}),call:e=>s.forEach(r=>r(e))}};function le(){let{on:s,call:e}=_();return {onError:s,callOnError:e}}function ce(){let{on:s,call:e}=_();return {onSuccess:s,callOnSuccess:e}}var ue=()=>{let s=new Set,e=new Map,r=(n,c)=>{e.get(n)?.forEach(o=>o(c));},t=(n,c)=>(e.has(n)||e.set(n,new Set),e.get(n).add(c),()=>e.get(n).delete(c));return {usePlugin:n=>(n.apply({on:t}),()=>{s.delete(n);}),emit:r}};function de(){let{on:s,call:e}=_();return {onStart:s,callOnStart:e}}function pe(s,e){let r=false,t=false,i=new Map,n=new Map,c=new Map,o=new Map,p=[],u=new Map,{GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetAllNextDependency:y,rebuildDirectDependencyMaps:m}=oe(()=>i,()=>n,()=>o,()=>c),{SetTrace:x,pushExecution:R,popExecution:O,markError:A}=ae(l),{Undo:L,Redo:E,PushIntoHistory:G,CreateHistoryAction:B,initCanUndo:D,initCanRedo:v}=ie(),{onError:g,callOnError:d}=le(),{onSuccess:f,callOnSuccess:T}=ce(),{onStart:S,callOnStart:F}=de(),{emit:w,usePlugin:V}=ue(),{schema:I,GetFormData:P,GetRenderSchemaByPath:b,GetGroupByPath:C,notifyAll:H,convertToRenderSchema:U}=Z(s,{GetDependencyOrder:()=>p,GetAllNextDependency:y,GetNextDependency:l,GetPrevDependency:a,GetAllPrevDependency:h,GetPathToLevelMap:()=>u},{pushExecution:R,popExecution:O,markError:A},{pushIntoHistory:G,createHistoryAction:B},{callOnError:d,callOnSuccess:T,callOnStart:F,emit:w},e),W=(M,k)=>{let N=C(M),X=U(k,M);return N.children.push(X),N.dirtySignal.value++,X},{SetRule:K,SetRules:j}=te(b,i,n),{SetStrategy:ye}=ne(b),{SetValidators:fe}=re(b),he=se(i),Y=()=>{let M=he();p=M.steps,u=M.levelMap;};return {schema:I,SetRule:(...M)=>{K.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetRules:(...M)=>{j.apply(null,M),r=true,!t&&new Promise((k,N)=>{t=true,k();}).then(()=>{if(Y(),r){let{directNextMap:k,directPrevMap:N}=m(p.flat());c=k,o=N;}}).finally(()=>{t=false,r=false;});},SetStrategy:ye,SetValidators:fe,SetTrace:x,usePlugin:V,SetValue:(M,k)=>{b(M).dependOn(()=>k);},GetFormData:P,notifyAll:()=>{Y(),H();},AddNewSchema:W,GetAllDependency:()=>i,GetDependencyOrder:()=>p,Undo:L,Redo:E,initCanUndo:D,initCanRedo:v,onError:g,onSuccess:f,onStart:S}}var q=new Map,ge=(s,e,r)=>{try{if(typeof r.signalCreateor!="function"||typeof r.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(q.has(s))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let t=pe(e,r),{schema:i,GetFormData:n,SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,SetValue:l,usePlugin:a,notifyAll:h,SetTrace:y,GetAllDependency:m,GetDependencyOrder:x,AddNewSchema:R,Undo:O,Redo:A,initCanUndo:L,initCanRedo:E,onError:G,onSuccess:B,onStart:D}=t,v={config:{SetRule:c,SetRules:o,SetStrategy:p,SetValidators:u,notifyAll:h,SetTrace:y,usePlugin:a},data:{schema:i,GetFormData:n,AddNewSchema:R,SetValue:l},history:{Undo:O,Redo:A,initCanUndo:L,initCanRedo:E},dependency:{GetAllDependency:m,GetDependencyOrder:x},hooks:{onError:G,onSuccess:B,onStart:D}};return q.set(s,v),v}catch(t){throw Error(t)}},st=s=>{if(q.has(s))return q.get(s);throw Error("\u4E0D\u5B58\u5728\u7684id")},it=s=>{q.delete(s);},lt=ge;export{it as deleteEngine,st as useEngine,ge as useEngineManager,lt as useMeshFlow};
1
+ var J=class{computedRules=[];store={OR:async(e,t)=>{let n,u,r=this.computedRules;for(let a of r){let i=await a.logic(e);if(a.entityId==="__base__"){u=i;continue}if(i){n=a.value;break}}return typeof n>"u"&&(n=u),{res:n,version:t}},PRIORITY:async(e,t)=>{let n=null,u=this.computedRules;try{for(let r of u){let a=await r.logic(e);if(a!==void 0){n=a;break}}}catch(r){throw r}return {res:n,version:t}}};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(t=>Array.from(t)).flat().sort((t,n)=>n.priority-t.priority):this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat();}setStrategy(e){this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,t){return this.CurrentStrategy(e,t)}},Y=class{path;strategy;contract;rules=new Map;isDefaultValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;globalCalcCount=0;constructor(e,t,n){let u=()=>this.rules;this.strategy=new J(u),this.path=n,this.isDefaultValue=t==="defaultValue",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}updateInputValueRule(e){this.isDefaultValue&&this.setRule({priority:1,entityId:"__input_value__",logic:()=>e});}setDefaultRule(e){let t=new Set;t.add(e),this.rules.set(e.id,t);}setRules(e,t){t&&this.updateDeps(t);let n=++this.id,u={...e,entityId:n};for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(u);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let a=this.rules.get(r);a&&(a.delete(u),a.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[t,n]of e)this.deps.set(t,n);}setRule(e,t){if(t&&this.updateDeps(t),typeof e.entityId=="string"){this.setDefaultRule(e);return}let n=++this.id,u={...e,entityId:n};if(e)for(let r of e.triggerPaths)this.rules.has(r)||this.rules.set(r,new Set),this.rules.get(r).add(u);return this.strategy.updateComputedRules(),()=>{for(let r of e.triggerPaths){let a=this.rules.get(r);a&&(a.delete(u),a.size===0&&(this.rules.delete(r),this.deps.delete(r)));}this.strategy.updateComputedRules();}}async evaluate(e){let t=null;if(e.GetToken&&(t=e.GetToken()),this.pendingPromise&&this.promiseToken!==t&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;this.promiseToken=t;let n=++this.version;return this.pendingPromise=(async()=>{try{await Promise.resolve();let u=!1;if(typeof e.triggerPath=="string"){u=!0;let i=this.deps.get(e.triggerPath),s=e.GetValueByPath(e.triggerPath);if(typeof i=="object"||typeof s=="object")u=!1;else {let d=Array.from(this.deps.keys());for(let f of d){let c=this.deps.get(f),m=e.GetValueByPath(f);if(c!==m){u=!1;break}}}}if(u)return this.cache;let{res:r,version:a}=await this.strategy.evaluate(e,n);if(t!==this.promiseToken)return this.cache;if(a<this.version)return this.cache;if(this.inferType(r)!==this.contract&&`${this.contract}`,this.cache=r,t===this.promiseToken){let i=Array.from(this.deps.keys());for(let s of i){let d=e.GetValueByPath(s);this.deps.set(s,d);}}return r}catch(u){throw {path:this.path,error:u}}finally{this.promiseToken===t&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}inferType(e){return Array.isArray(e)?"array":typeof e}},$=class{validators=[];defaultValidators=[];path="";constructor(e){this.path=e,this.SetDefaultValidators();}setValidators(e){this.validators.push(e);}SetDefaultValidators(){let e={logic:n=>n||typeof n=="number"?true:`${this.path}\u4E0D\u80FD\u4E3A\u7A7A`,condition:n=>!!n.required},t={logic:function(n){return n.length>this.options.maxLength?`\u8D85\u51FA\u6700\u5927\u957F\u5EA6\uFF0C\u6700\u5927\u957F\u5EA6\u4E3A${this.options.maxLength}`:true},condition:function(n){return typeof n.maxLength!="number"?false:(t.options={maxLength:n.maxLength},n.type==="input"&&n.hidden===false)},options:{}};this.defaultValidators.push(e),this.defaultValidators.push(t);}evaluate(e,t){let n=true,u=[...this.defaultValidators,...this.validators];for(let r of u){if(!r.condition(t))continue;let i=r.logic(e);if(typeof i!="boolean"){n=i;break}}return n}};function ee(l,e,t,n){let u=new Map;return (a,i)=>{let d=Symbol("token");u.set(a,d);let f=false,c=new Set,m=new Set,T=new Set(l.GetAllNextDependency(a));T.add(a);let p=new Map,g=new Map,G=new Map,B=performance.now(),A=l.GetPathToLevelMap(),k=A.get(a)??0,L=0,H=C=>{l.GetAllNextDependency(C).forEach(y=>{let P=A.get(y)||0;P>L&&(L=P);});};H(a),c.add(a);let M=Array.from(i).map(C=>(p.set(C,(p.get(C)||0)+1),{target:C,trigger:a,isReleased:false})),K=performance.now();t.emit("flow:start",{path:a}),t.callOnStart({path:a});let U=async C=>{let h=(o,R)=>{let x=g.get(o)??0,w=Math.max(0,x-1);if(w<=0){let F=p.has(o),v=m.has(o);if(F||v){t.emit("node:intercept",{path:o,type:3});return}g.delete(o),M.push({target:o,trigger:y,isReleased:true}),p.set(o,1),t.emit("node:release",{path:o,type:R,detail:{targetPath:y}});}else g.set(o,w);},{target:y,trigger:P}=C;try{if(u.get(a)!==d)return;let o=!1,R=!1,x=e.GetRenderSchemaByPath(y);t.emit("node:start",{path:y});for(let w in x.nodeBucket){let F=x.nodeBucket[w],v=await F.evaluate({affectKey:w,triggerPath:P,GetRenderSchemaByPath:e.GetRenderSchemaByPath,GetValueByPath:S=>e.GetRenderSchemaByPath(S).defaultValue,GetToken:()=>d});if(u.get(a)!==d){t.emit("node:intercept",{path:y,type:1});return}w==="options"&&(v.some(E=>E.value==x.defaultValue)||(x.defaultValue=void 0,o=!0)),v!==x[w]&&(x[w]=v,o=!0,t.emit("node:bucket:success",{path:y,key:w,value:v})),F.isForceNotify()&&(R=!0),o&&n.flushPathSet.add(y);let b=l.GetNextDependency(y);(o||R)&&(l.GetAllNextDependency(y).forEach(E=>T.add(E)),w==="defaultValue"&&H(y));for(let S of b){if(c.has(S)){t.emit("node:intercept",{path:S,type:2});continue}if(m.has(S)||p.has(S)){t.emit("node:intercept",{path:S,type:3});continue}if(o||R){if(!g.has(S)&&!c.has(S)&&!p.has(S)&&!m.has(S)){let O=l.GetPrevDependency(S).filter(N=>T.has(N)).length;g.set(S,O),t.emit("node:pending",{path:S});}h(S,1);}else if(g.has(S))h(S,2);else {let O=A.get(S);G.has(O)||G.set(O,new Set);let N=G.get(O);!N.has(S)&&!c.has(S)&&!p.has(S)&&(N.add(S),t.emit("node:stagnate",{path:S,type:1}));}}}if(t.emit("node:success",{path:y}),c.add(y),performance.now()-B>16&&(await new Promise(w=>requestAnimationFrame(w)),B=performance.now(),u.get(a)!==d))return;u.get(a)===d&&n.requestUpdate();}catch(o){t.emit("node:error",{path:y,error:o});let R=Symbol("abort");u.set(a,R),M.length=0,g.clear(),m.clear(),t.callOnError(o);}finally{if(u.get(a)===d&&(m.delete(y),!f)){let o=m.size||g.size||p.size;t.emit("flow:fire",{path:y,type:o>0?1:2,detail:{remaining:o}}),_();}}},_=async()=>{if(u.get(a)!==d){f=false;return}f=true;try{for(;u.get(a)===d;){if(M.length>0){if(m.size>=20){f=!1;return}let P=M[0],{target:o}=P,R=A.get(o)??0;if(R>k){M.shift();let w=p.get(o)||0;if(w<=1?p.delete(o):p.set(o,w-1),!g.has(o)){let v=l.GetPrevDependency(o).filter(b=>T.has(b)&&!c.has(b)).length;v>0?(g.set(o,v),t.emit("node:intercept",{path:o,type:4,detail:{targetLevel:R,currentLevel:k,pendingParentsCount:v}})):g.set(o,0);}continue}M.shift();let x=p.get(o)||0;if(x<=1?p.delete(o):p.set(o,x-1),c.has(o)){t.emit("node:intercept",{path:o,type:2});continue}m.add(o),t.emit("node:processing",{path:o}),U(P);continue}if(m.size>0){t.emit("flow:wait",{type:1,detail:{nums:m.size}}),f=!1;return}if(g.size>0&&m.size>0)return;let C=new Set;for(let P of G.keys())C.add(P);for(let[P]of g){let o=A.get(P)??0;o>k&&C.add(o);}let h=Array.from(C).sort((P,o)=>P-o);if(h.length===0)break;let y=h[0];if(y<=L){k=y,G.has(y)&&(G.get(y).forEach(R=>{M.push({target:R,trigger:a,isReleased:!0}),p.set(R,(p.get(R)||0)+1);}),G.delete(y));let P=[];for(let[o,R]of g)(A.get(o)??0)===y&&P.push(o);P.forEach(o=>{g.delete(o),M.push({target:o,trigger:a,isReleased:!0}),p.set(o,(p.get(o)||0)+1),t.emit("node:release",{path:o,type:3,detail:{level:y}});});continue}else {G.forEach(P=>P.forEach(o=>c.add(o))),G.clear();break}}}finally{if(f=false,M.length===0&&m.size===0&&G.size===0&&u.get(a)===d){let C=performance.now();t.emit("flow:success",{duration:(C-K).toFixed(2)+"ms"}),Promise.resolve().then(()=>{t.callOnSuccess();});}}};_();}}function te(l,e,t,n,u){let r=me(l),a=0,i=new Map,s=new Map,d=new Map,f=false,c=new Set,m=false,T=true,p=null,g=h=>{let y=i.get(h);return s.get(y)},G=h=>d.get(h),B=async()=>{let h=Array.from(c);c.clear();for(let y of h){let P=g(y);u.signalTrigger(P.dirtySignal);}},A=()=>{f||(f=true,Promise.resolve().then(()=>{try{for(;c.size>0;)B();}finally{f=false;}}));},z=()=>{let h=(y,P,o)=>{if(typeof y!="object"||y===null||Array.isArray(y)){if(o.length>0){let x=o[o.length-1];P[x]=g(o.join(".")).defaultValue;}return}let R=Object.getOwnPropertyNames(y);for(let x of R)o.push(x),h(y[x],y,o),o.pop();};return h(r,null,[]),r},k=ee(e,{GetRenderSchemaByPath:g},n,{requestUpdate:A,flushPathSet:c}),L=async()=>(m&&p||(m=true,p=(async()=>{let h=e.GetDependencyOrder(),y=performance.now(),P=performance.now();try{for(let R=0;R<h.length;R++){let x=h[R];await Promise.all(x.map(async w=>{let F=g(w),v=!1;for(let b in F.nodeBucket){let S=await F.nodeBucket[b].evaluate({affectKey:b,triggerPath:void 0,GetRenderSchemaByPath:g,GetValueByPath:E=>g(E).defaultValue,isSameToken:()=>!0});if(b==="options"){let E=!1,O=F.defaultValue;for(let N of S)if(N.value==O){E=!0;break}E||(F.defaultValue=void 0,v=!0);}S!==F[b]&&(F[b]=S,v=!0);}v&&c.add(w);})),performance.now()-P>12&&(await new Promise(w=>requestAnimationFrame(w)),P=performance.now());}c.size>0&&A(),T=!1;let o=performance.now();n.emit("flow:success",{duration:(o-y).toFixed(2)+"ms"}),n.callOnSuccess();}catch(o){throw n.emit("node:error",{path:o.path,error:o.error}),n.callOnError(o),o}finally{m=false,p=null,T=false;}})()),p),H=async h=>{if(T)return;if(!h)throw Error("\u6CA1\u6709\u8DEF\u5F84");if(!g(h))throw Error("\u8DEF\u5F84\u9519\u8BEF\uFF0C\u6CA1\u6709\u5BF9\u5E94\u7684\u8282\u70B9");c.add(h),A();let P=e.GetNextDependency(h);M(P,h);};async function M(h,y){k(y,h);}let K=h=>{if(!h)throw Error("\u6CA1\u6709\u8DEF\u5F84");let y=g(h);y.nodeBucket.defaultValue&&y.nodeBucket.defaultValue.updateInputValueRule(y.defaultValue);},U=(h,y="")=>{let P="name"in h?h.name:void 0,o=P?y===""?P:`${y}.${P}`:y,R=u.signalCreateor(),x=a++,w={getRenderSchema:b=>g(b)},F=async(b,S)=>{let E=b(S),O=g(S.path),N=t.createHistoryAction([{path:S.path,value:O.defaultValue},{path:S.path,value:E}],async q=>{let Q=g(q.path);Q.defaultValue=q.value,K(q.path),await H(q.path);});O.defaultValue=E,t.pushIntoHistory(N),K(S.path),await H(S.path);},v={...h,disabled:!!h.disabled,hidden:"hidden"in h?h.hidden:false,readonly:"readonly"in h?h.readonly:false,required:"required"in h?h.required:false,path:o,dirtySignal:R,uid:x,nodeBucket:{},validators:new $(o),theme:"secondary",dependOn:async b=>await F(b,{...w,path:o})};return h.type==="group"&&(delete v.nodeBucket,delete v.validators,v.children=h.children.map(b=>U(b,o)),d.set(v.path,v)),i.set(v.path,v.uid),s.set(v.uid,v),v};return {schema:U(l),GetFormData:()=>z(),GetRenderSchemaByPath:g,GetGroupByPath:G,notifyAll:L,convertToRenderSchema:U}}function me(l,e={}){let t=r=>{if(r.type=="group")return {key:r.name||"",isGroup:true,val:r.children.reduce((a,i)=>[...a,t(i)],[])};if(r.type=="input"||r.type=="number"||r.type=="select"||r.type=="checkbox")return {key:r.name,isGroup:false,val:r.defaultValue};throw Error(`\u672A\u5B9A\u4E49\u7684\u7C7B\u578B:${r.type}`)},n=(r,a)=>{if(a.isGroup){let i={};a.key===""?i=r:r[a.key]=i,a.val.forEach(s=>{n(i,s);});}else r[a.key]=a.val;},u=t(l);return n(e,u),e}var ne=(l,e,t)=>{let u=r=>{let a=t.triggerPaths.map(d=>r.GetValueByPath(d)),i=Object.create(null);return Object.defineProperty(i,"triggerTargets",{get:()=>a}),Object.defineProperty(i,"affectedTatget",{get:()=>r.GetRenderSchemaByPath(l)[e]}),t.logic({slot:i})};return {value:t.value,targetPath:l,triggerPaths:t.triggerPaths,priority:t.priority??10,logic:u}},re=(l,e,t)=>{if(!l)throw Error("");let n=l,u=(i,s)=>{e.has(i)||e.set(i,new Set),e.get(i).add(s),t.has(s)||t.set(s,new Set),t.get(s).add(i);};return {SetRule:(i,s,d,f={logic:c=>{}})=>{let c=n(s),m=ne(s,d,{...f,triggerPaths:[i]}),T=[i].map(p=>[p,n(p).defaultValue]);if(u(i,s),c.nodeBucket[d])c.nodeBucket[d].setRule(m,T);else {let p=new Y(c[d],d,s);p.setRule(m,T),c.nodeBucket[d]=p;}f.forceNotify&&c.nodeBucket[d].forceNotify();},SetRules:(i,s,d,f={logic:c=>{}})=>{let c=n(s);for(let p of i)u(p,s);let m=ne(s,d,{...f,triggerPaths:i}),T=i.map(p=>[p,n(p).defaultValue]);if(c.nodeBucket[d])c.nodeBucket[d].setRules(m,T);else {let p=new Y(c[d],d,s);p.setRules(m,T),c.nodeBucket[d]=p;}f.forceNotify&&c.nodeBucket[d].forceNotify();}}},ae=l=>{let e=l||void 0;if(!e)throw Error("");return {SetStrategy:(n,u,r)=>{e(n).nodeBucket[u].setStrategy(r);}}};var oe=l=>{let e=l||void 0;return {SetValidators:(n,u)=>{let r=e(n),a=(s,d,f)=>s(d,f),i=(s,d,f)=>s(d,f);if(!r.validators)throw Error("validator\u6876\u672A\u521D\u59CB\u5316");r.validators.setValidators({logic:s=>a(u.logic,s,e),condition:typeof u.condition=="function"?s=>i(u.condition,s,e):()=>true});}}};function se(){let l=new Map,e=new Map,t=new Set,n=(a,i)=>{l.set(a,i);let s=e.get(a);s&&s(i);};return {SetTrace:(a,i)=>{e.set(a,i);let s=l.get(a)||"idle";return i(s),()=>{e.delete(a);}},useTrace:()=>({apply:i=>{i.on("flow:start",()=>{t.forEach(s=>n(s,"idle")),t.clear(),l.clear();}),i.on("node:release",({path:s})=>{}),i.on("node:pending",({path:s})=>{t.add(s),(!l.has(s)||l.get(s)==="idle")&&n(s,"pending");}),i.on("node:start",({path:s})=>{t.add(s),n(s,"calculating");}),i.on("node:success",({path:s})=>{n(s,"calculated");}),i.on("node:intercept",({path:s,type:d})=>{}),i.on("node:stagnate",({path:s})=>{n(s,"pending");}),i.on("node:error",({path:s})=>n(s,"error"));}})}}function ie(l,e,t,n){let u=f=>{let c=l(),m=e(),T=new Set;return c.get(f)?.forEach(p=>T.add(p)),T.size===0?[]:Array.from(T).filter(p=>{let g=m.get(p)||new Set;return !Array.from(g).some(A=>T.has(A))})};return {GetNextDependency:f=>{let c=n();return Array.from(c.get(f)||[])},GetPrevDependency:f=>{let c=t();return Array.from(c.get(f)||[])},GetAllPrevDependency:f=>{let c=e();return Array.from(c.get(f)||[])},GetAllNextDependency:f=>{let c=l();return Array.from(c.get(f)||[])},rebuildDirectDependencyMaps:f=>{let c=new Map,m=new Map;for(let T of f){let p=u(T);c.set(T,new Set(p));for(let g of p)m.has(g)||m.set(g,new Set),m.get(g).add(T);}return {directNextMap:c,directPrevMap:m}}}}function le(l){let e=n=>{let u=[],r=[],a=new Map,i=n.size,s=0,d=0;for(let[f,c]of n)c===0&&r.push(f);if(r.length===0&&i>0)throw Error("\u521D\u59CB\u5165\u5EA6\u6CA1\u6709\u4E3A0\u7684path, \u4F9D\u8D56\u7EDF\u8BA1\u6709\u8BEF\u6216\u5B58\u5728\u73AF");for(;r.length>0;){u.push([...r]);let f=[];for(let c of r){s++,a.set(c,d);let m=l.get(c);if(m)for(let T of m){let p=n.get(T)-1;n.set(T,p),p===0&&f.push(T);}}r=f,d++;}if(s<i)throw Error("\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF01");return {steps:u,levelMap:a}};return ()=>{let n=new Map;for(let u of l.keys()){let r=Array.from(l.get(u)||[]);n.has(u)||n.set(u,0);for(let a of r){let i=n.get(a)||0;n.set(a,++i);}}return e(n)}}function ce(){let l=[],e=[],n={canRedo:()=>{},canUndo:()=>{}},u=()=>{if(!l.length)return;let c=l.pop();c?.undoAction(),s(c);},r=()=>{if(!e.length)return;let c=e.pop();c?.redoAction(),d(c,false);},a=c=>{n.canUndo=()=>c(l.length);},i=c=>{n.canRedo=()=>c(e.length);},s=c=>{e.push(c),e.length>100&&e.shift(),n.canRedo(),n.canUndo();},d=(c,m=true)=>{m&&(e.length=0),l.push(c),l.length>100&&l.shift(),n.canUndo(),n.canRedo();};return {Undo:u,Redo:r,PushIntoHistory:d,CreateHistoryAction:(c,m)=>{let[T,p]=c;return {undoAction:()=>m(T),redoAction:()=>m(p)}},initCanUndo:a,initCanRedo:i}}var W=()=>{let l=[];return {on:e=>(l.push(e),()=>{let t=l.indexOf(e);t>-1&&l.splice(t,1);}),call:e=>l.forEach(t=>t(e))}};function ue(){let{on:l,call:e}=W();return {onError:l,callOnError:e}}function de(){let{on:l,call:e}=W();return {onSuccess:l,callOnSuccess:e}}var pe=()=>{let l=new Set,e=new Map,t=(r,a)=>{e.get(r)?.forEach(i=>i(a));},n=(r,a)=>(e.has(r)||e.set(r,new Set),e.get(r).add(a),()=>e.get(r).delete(a));return {usePlugin:r=>{let a=new Set,i=(s,d)=>{let f=n(s,d);return a.add(f),f};return r.apply({on:i}),l.add(r),()=>{a.forEach(s=>s()),a.clear(),l.delete(r);}},emit:t}};function ye(){let{on:l,call:e}=W();return {onStart:l,callOnStart:e}}function fe(l,e){let t=false,n=false,u=new Map,r=new Map,a=new Map,i=new Map,s=[],d=new Map,{GetNextDependency:c,GetPrevDependency:m,GetAllPrevDependency:T,GetAllNextDependency:p,rebuildDirectDependencyMaps:g}=ie(()=>u,()=>r,()=>i,()=>a),{Undo:G,Redo:B,PushIntoHistory:A,CreateHistoryAction:z,initCanUndo:k,initCanRedo:L}=ce(),{onError:H,callOnError:M}=ue(),{onSuccess:K,callOnSuccess:U}=de(),{onStart:_,callOnStart:C}=ye(),{emit:h,usePlugin:y}=pe(),{SetTrace:P,useTrace:o}=se(),R=o();y(R);let{schema:x,GetFormData:w,GetRenderSchemaByPath:F,GetGroupByPath:v,notifyAll:b,convertToRenderSchema:S}=te(l,{GetDependencyOrder:()=>s,GetAllNextDependency:p,GetNextDependency:c,GetPrevDependency:m,GetAllPrevDependency:T,GetPathToLevelMap:()=>d},{pushIntoHistory:A,createHistoryAction:z},{callOnError:M,callOnSuccess:U,callOnStart:C,emit:h},e),E=(D,V)=>{let I=v(D),Z=S(V,D);return I.children.push(Z),I.dirtySignal.value++,Z},{SetRule:O,SetRules:N}=re(F,u,r),{SetStrategy:q}=ae(F),{SetValidators:Q}=oe(F),he=le(u),X=()=>{let D=he();s=D.steps,d=D.levelMap;};return {schema:x,SetRule:(...D)=>{O.apply(null,D),t=true,!n&&new Promise((V,I)=>{n=true,V();}).then(()=>{if(X(),t){let{directNextMap:V,directPrevMap:I}=g(s.flat());a=V,i=I;}}).finally(()=>{n=false,t=false;});},SetRules:(...D)=>{N.apply(null,D),t=true,!n&&new Promise((V,I)=>{n=true,V();}).then(()=>{if(X(),t){let{directNextMap:V,directPrevMap:I}=g(s.flat());a=V,i=I;}}).finally(()=>{n=false,t=false;});},SetStrategy:q,SetValidators:Q,SetTrace:P,usePlugin:y,SetValue:(D,V)=>{F(D).dependOn(()=>V);},GetValue:(D,V="defaultValue")=>F(D)[V],GetFormData:w,GetGroupByPath:v,notifyAll:async()=>{X(),await b();},AddNewSchema:E,GetAllDependency:()=>u,GetDependencyOrder:()=>s,Undo:G,Redo:B,initCanUndo:k,initCanRedo:L,onError:H,onSuccess:K,onStart:_}}var j=new Map,ge=(l,e,t)=>{try{if(typeof t.signalCreateor!="function"||typeof t.signalTrigger!="function")throw Error("\u9700\u8981\u5B9A\u4E49signal\u6765\u901A\u77E5ui");if(j.has(l))throw Error("engineID\u91CD\u590D,\u4FEE\u6539id\u6216\u8005\u4F7F\u7528symbol");let n=fe(e,t),{schema:u,GetFormData:r,SetRule:a,SetRules:i,SetStrategy:s,SetValidators:d,SetValue:f,GetValue:c,usePlugin:m,GetGroupByPath:T,notifyAll:p,SetTrace:g,GetAllDependency:G,GetDependencyOrder:B,AddNewSchema:A,Undo:z,Redo:k,initCanUndo:L,initCanRedo:H,onError:M,onSuccess:K,onStart:U}=n,_={config:{SetRule:a,SetRules:i,SetStrategy:s,SetValidators:d,notifyAll:p,SetTrace:g,usePlugin:m},data:{schema:u,GetFormData:r,AddNewSchema:A,SetValue:f,GetValue:c,GetGroupByPath:T},history:{Undo:z,Redo:k,initCanUndo:L,initCanRedo:H},dependency:{GetAllDependency:G,GetDependencyOrder:B},hooks:{onError:M,onSuccess:K,onStart:U}};return j.set(l,_),_}catch(n){throw Error(n)}},it=l=>{if(j.has(l))return j.get(l);throw Error("\u4E0D\u5B58\u5728\u7684id")},lt=l=>{j.delete(l);},ct=ge;export{lt as deleteEngine,it as useEngine,ge as useEngineManager,ct as useMeshFlow};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshflow/core",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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",