@flowgram.ai/variable-core 0.2.15 → 0.2.17

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/dist/index.d.ts CHANGED
@@ -5,8 +5,18 @@ import { Subject, Observable, BehaviorSubject, Observer as Observer$1 } from 'rx
5
5
  export { Observer } from 'rxjs';
6
6
  import * as react from 'react';
7
7
 
8
+ /**
9
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
10
+ * SPDX-License-Identifier: MIT
11
+ */
12
+
8
13
  declare const VariableContainerModule: ContainerModule;
9
14
 
15
+ /**
16
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
17
+ * SPDX-License-Identifier: MIT
18
+ */
19
+
10
20
  declare const VariableEngineProvider: unique symbol;
11
21
  type VariableEngineProvider = () => VariableEngine;
12
22
 
@@ -22,8 +32,22 @@ declare class ScopeOutputData {
22
32
  };
23
33
  get variableEngine(): VariableEngine;
24
34
  get globalVariableTable(): IVariableTable;
35
+ /**
36
+ * @deprecated use onListOrAnyVarChange instead
37
+ */
25
38
  get onDataChange(): _flowgram_ai_utils.Event<void>;
39
+ /**
40
+ * listen to variable list change
41
+ */
42
+ get onVariableListChange(): (observer: (variables: VariableDeclaration<any>[]) => void) => _flowgram_ai_utils.Disposable;
43
+ /**
44
+ * listen to any variable update in list
45
+ */
26
46
  get onAnyVariableChange(): (observer: (changedVariable: VariableDeclaration<any>) => void) => _flowgram_ai_utils.Disposable;
47
+ /**
48
+ * listen to variable list change + any variable update in list
49
+ */
50
+ get onListOrAnyVarChange(): (observer: () => void) => _flowgram_ai_utils.Disposable;
27
51
  protected _hasChanges: boolean;
28
52
  constructor(scope: Scope);
29
53
  /**
@@ -62,22 +86,30 @@ declare class ScopeAvailableData {
62
86
  protected variables$: Observable<VariableDeclaration[]>;
63
87
  protected anyVariableChange$: Observable<VariableDeclaration>;
64
88
  /**
65
- * 监听任意变量变化
66
- * @param observer 监听器,变量变化时会吐出值
89
+ * listen to any variable update in list
90
+ * @param observer
67
91
  * @returns
68
92
  */
69
93
  onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
70
94
  /**
71
- * 监听变量列表变化
95
+ * listen to variable list change
72
96
  * @param observer
73
97
  * @returns
74
98
  */
75
99
  onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
100
+ /**
101
+ * @deprecated
102
+ */
76
103
  protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
104
+ protected onListOrAnyVarChangeEmitter: Emitter<VariableDeclaration<any>[]>;
77
105
  /**
78
- * 监听变量列表变化 + 任意子变量变化
106
+ * @deprecated use available.onListOrAnyVarChange instead
79
107
  */
80
108
  onDataChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
109
+ /**
110
+ * listen to variable list change + any variable drilldown change
111
+ */
112
+ onListOrAnyVarChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
81
113
  constructor(scope: Scope);
82
114
  /**
83
115
  * 获取可消费变量
@@ -96,9 +128,21 @@ declare class ScopeAvailableData {
96
128
  * @param keyPath
97
129
  * @returns
98
130
  */
99
- getByKeyPath(keyPath?: string[]): VariableDeclaration | Property | undefined;
131
+ getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
132
+ /**
133
+ * Track Variable Change (Includes type update and children update) By KeyPath
134
+ * @returns
135
+ */
136
+ trackByKeyPath(keyPath: string[] | undefined, cb: (variable?: BaseVariableField | undefined) => void, opts?: {
137
+ triggerOnInit?: boolean;
138
+ }): Disposable;
100
139
  }
101
140
 
141
+ /**
142
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
143
+ * SPDX-License-Identifier: MIT
144
+ */
145
+
102
146
  type Observer<ActionType extends GlobalEventActionType = GlobalEventActionType> = (action: ActionType) => void;
103
147
  declare class ScopeEventData {
104
148
  readonly scope: Scope;
@@ -166,6 +210,27 @@ declare class Scope<ScopeMeta extends Record<string, any> = Record<string, any>>
166
210
  dispose(): void;
167
211
  onDispose: _flowgram_ai_utils.Event<void>;
168
212
  get disposed(): boolean;
213
+ /**
214
+ * Sets a variable in the Scope with the default key 'outputs'.
215
+ *
216
+ * @param json - The JSON value to store.
217
+ * @returns The updated AST node.
218
+ */
219
+ setVar(json: ASTNodeJSON): ASTNode;
220
+ /**
221
+ * Retrieves a variable from the Scope by key.
222
+ *
223
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
224
+ * @returns The value of the variable, or undefined if not found.
225
+ */
226
+ getVar(key?: string): ASTNode<any, any> | undefined;
227
+ /**
228
+ * Clears a variable from the Scope by key.
229
+ *
230
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
231
+ * @returns The updated AST node.
232
+ */
233
+ clearVar(key?: string): void;
169
234
  }
170
235
 
171
236
  /**
@@ -225,7 +290,7 @@ declare abstract class ASTNode<JSON extends ASTNodeJSON = any, InjectOpts = any>
225
290
  /**
226
291
  * 节点的版本号,每 fireChange 一次 version + 1
227
292
  */
228
- private _version;
293
+ protected _version: number;
229
294
  /**
230
295
  * 更新锁
231
296
  */
@@ -324,6 +389,11 @@ declare abstract class ASTNode<JSON extends ASTNodeJSON = any, InjectOpts = any>
324
389
  [key: string]: unknown;
325
390
  }
326
391
 
392
+ /**
393
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
394
+ * SPDX-License-Identifier: MIT
395
+ */
396
+
327
397
  type ASTKindType = string;
328
398
  type Identifier = string;
329
399
  interface ASTNodeJSON {
@@ -394,6 +464,11 @@ interface GlobalEventActionType<Type = string, Payload = any, AST extends ASTNod
394
464
  ast?: AST;
395
465
  }
396
466
 
467
+ /**
468
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
469
+ * SPDX-License-Identifier: MIT
470
+ */
471
+
397
472
  type DataInjector = () => Record<string, any>;
398
473
  declare class ASTRegisters {
399
474
  protected injectors: Map<ASTKindType, DataInjector>;
@@ -422,6 +497,10 @@ declare class ASTRegisters {
422
497
  registerAST(ASTNode: ASTNodeRegistry, injector?: DataInjector): void;
423
498
  }
424
499
 
500
+ /**
501
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
502
+ * SPDX-License-Identifier: MIT
503
+ */
425
504
  declare enum ASTNodeFlags {
426
505
  None = 0,
427
506
  /**
@@ -442,6 +521,11 @@ declare enum ASTNodeFlags {
442
521
  VariableType = 120
443
522
  }
444
523
 
524
+ /**
525
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
526
+ * SPDX-License-Identifier: MIT
527
+ */
528
+
445
529
  /**
446
530
  * 通用数据 AST 节点,无子节点
447
531
  */
@@ -456,6 +540,11 @@ declare class DataNode<Data = any> extends ASTNode {
456
540
  partialUpdate(nextData: Data): void;
457
541
  }
458
542
 
543
+ /**
544
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
545
+ * SPDX-License-Identifier: MIT
546
+ */
547
+
459
548
  interface ListNodeJSON {
460
549
  list: ASTNodeJSON[];
461
550
  }
@@ -467,6 +556,11 @@ declare class ListNode extends ASTNode<ListNodeJSON> {
467
556
  toJSON(): ASTNodeJSON;
468
557
  }
469
558
 
559
+ /**
560
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
561
+ * SPDX-License-Identifier: MIT
562
+ */
563
+
470
564
  interface MapNodeJSON {
471
565
  map: [string, ASTNodeJSON][];
472
566
  }
@@ -494,6 +588,11 @@ declare class MapNode extends ASTNode<MapNodeJSON> {
494
588
  get(key: string): ASTNode | undefined;
495
589
  }
496
590
 
591
+ /**
592
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
593
+ * SPDX-License-Identifier: MIT
594
+ */
595
+
497
596
  declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
498
597
  flags: number;
499
598
  /**
@@ -513,28 +612,53 @@ declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any
513
612
  toJSON(): ASTNodeJSON;
514
613
  }
515
614
 
615
+ /**
616
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
617
+ * SPDX-License-Identifier: MIT
618
+ */
619
+
516
620
  declare class StringType extends BaseType {
517
621
  flags: ASTNodeFlags;
518
622
  static kind: string;
519
623
  fromJSON(): void;
520
624
  }
521
625
 
626
+ /**
627
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
628
+ * SPDX-License-Identifier: MIT
629
+ */
630
+
522
631
  declare class IntegerType extends BaseType {
523
632
  flags: ASTNodeFlags;
524
633
  static kind: string;
525
634
  fromJSON(): void;
526
635
  }
527
636
 
637
+ /**
638
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
639
+ * SPDX-License-Identifier: MIT
640
+ */
641
+
528
642
  declare class BooleanType extends BaseType {
529
643
  static kind: string;
530
644
  fromJSON(): void;
531
645
  }
532
646
 
647
+ /**
648
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
649
+ * SPDX-License-Identifier: MIT
650
+ */
651
+
533
652
  declare class NumberType extends BaseType {
534
653
  static kind: string;
535
654
  fromJSON(): void;
536
655
  }
537
656
 
657
+ /**
658
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
659
+ * SPDX-License-Identifier: MIT
660
+ */
661
+
538
662
  interface ArrayJSON {
539
663
  items?: ASTNodeJSONOrKind;
540
664
  }
@@ -555,6 +679,11 @@ declare class ArrayType extends BaseType<ArrayJSON> {
555
679
  toJSON(): ASTNodeJSON;
556
680
  }
557
681
 
682
+ /**
683
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
684
+ * SPDX-License-Identifier: MIT
685
+ */
686
+
558
687
  interface MapJSON {
559
688
  keyType?: ASTNodeJSONOrKind;
560
689
  valueType?: ASTNodeJSONOrKind;
@@ -574,6 +703,11 @@ declare class MapType extends BaseType<MapJSON> {
574
703
  toJSON(): ASTNodeJSON;
575
704
  }
576
705
 
706
+ /**
707
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
708
+ * SPDX-License-Identifier: MIT
709
+ */
710
+
577
711
  type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
578
712
  key: string;
579
713
  };
@@ -581,6 +715,11 @@ declare class Property<VariableMeta = any> extends BaseVariableField<VariableMet
581
715
  static kind: string;
582
716
  }
583
717
 
718
+ /**
719
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
720
+ * SPDX-License-Identifier: MIT
721
+ */
722
+
584
723
  interface ObjectJSON<VariableMeta = any> {
585
724
  /**
586
725
  * Object 的 properties 一定是 Property 类型,因此业务可以不用填 kind
@@ -613,10 +752,20 @@ declare class ObjectType extends BaseType<ObjectJSON> {
613
752
  protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
614
753
  }
615
754
 
755
+ /**
756
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
757
+ * SPDX-License-Identifier: MIT
758
+ */
759
+
616
760
  interface UnionJSON {
617
761
  types?: ASTNodeJSONOrKind[];
618
762
  }
619
763
 
764
+ /**
765
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
766
+ * SPDX-License-Identifier: MIT
767
+ */
768
+
620
769
  interface CustomTypeJSON {
621
770
  typeName: string;
622
771
  }
@@ -628,6 +777,11 @@ declare class CustomType extends BaseType<CustomTypeJSON> {
628
777
  isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
629
778
  }
630
779
 
780
+ /**
781
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
782
+ * SPDX-License-Identifier: MIT
783
+ */
784
+
631
785
  type ExpressionRefs = (BaseVariableField | undefined)[];
632
786
  declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
633
787
  flags: ASTNodeFlags;
@@ -666,6 +820,11 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
666
820
  constructor(params: CreateASTParams, opts?: InjectOpts);
667
821
  }
668
822
 
823
+ /**
824
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
825
+ * SPDX-License-Identifier: MIT
826
+ */
827
+
669
828
  interface KeyPathExpressionJSON$1 {
670
829
  keyPath: string[];
671
830
  }
@@ -687,6 +846,11 @@ declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpr
687
846
  toJSON(): ASTNodeJSON;
688
847
  }
689
848
 
849
+ /**
850
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
851
+ * SPDX-License-Identifier: MIT
852
+ */
853
+
690
854
  interface EnumerateExpressionJSON {
691
855
  enumerateFor: ASTNodeJSON;
692
856
  }
@@ -703,6 +867,11 @@ declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON
703
867
  toJSON(): ASTNodeJSON;
704
868
  }
705
869
 
870
+ /**
871
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
872
+ * SPDX-License-Identifier: MIT
873
+ */
874
+
706
875
  interface KeyPathExpressionJSON {
707
876
  keyPath: string[];
708
877
  }
@@ -732,6 +901,11 @@ declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathEx
732
901
  toJSON(): ASTNodeJSON;
733
902
  }
734
903
 
904
+ /**
905
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
906
+ * SPDX-License-Identifier: MIT
907
+ */
908
+
735
909
  interface WrapArrayExpressionJSON {
736
910
  wrapFor: ASTNodeJSON;
737
911
  }
@@ -769,9 +943,11 @@ declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<Bas
769
943
  * 父变量字段,通过由近而远的方式进行排序
770
944
  */
771
945
  get parentFields(): BaseVariableField[];
946
+ get keyPath(): string[];
772
947
  get meta(): VariableMeta;
773
948
  get type(): BaseType;
774
949
  get initializer(): BaseExpression | undefined;
950
+ get hash(): string;
775
951
  /**
776
952
  * 解析 VariableDeclarationJSON 从而生成变量声明节点
777
953
  */
@@ -819,6 +995,11 @@ declare class VariableDeclaration<VariableMeta = any> extends BaseVariableField<
819
995
  onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
820
996
  }
821
997
 
998
+ /**
999
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1000
+ * SPDX-License-Identifier: MIT
1001
+ */
1002
+
822
1003
  interface VariableDeclarationListJSON<VariableMeta = any> {
823
1004
  /**
824
1005
  * declarations 一定是 VariableDeclaration 类型,因此业务可以不用填 kind
@@ -958,9 +1139,19 @@ declare namespace ASTMatch {
958
1139
  }): node is TargetASTNode;
959
1140
  }
960
1141
 
1142
+ /**
1143
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1144
+ * SPDX-License-Identifier: MIT
1145
+ */
1146
+
961
1147
  declare const injectToAST: (serviceIdentifier: interfaces.ServiceIdentifier) => (target: any, propertyKey: string) => any;
962
1148
  declare const postConstructAST: () => (target: any, propertyKey: string) => void;
963
1149
 
1150
+ /**
1151
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1152
+ * SPDX-License-Identifier: MIT
1153
+ */
1154
+
964
1155
  /**
965
1156
  * isMatchAST is same as ASTMatch.is
966
1157
  * @param node
@@ -972,6 +1163,11 @@ declare function isMatchAST<TargetASTNode extends ASTNode>(node?: ASTNode, targe
972
1163
  new (...args: any[]): TargetASTNode;
973
1164
  }): node is TargetASTNode;
974
1165
 
1166
+ /**
1167
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1168
+ * SPDX-License-Identifier: MIT
1169
+ */
1170
+
975
1171
  interface ScopeChangeAction {
976
1172
  type: 'add' | 'delete' | 'update' | 'available';
977
1173
  scope: Scope;
@@ -986,8 +1182,9 @@ interface IVariableTable extends Disposable {
986
1182
  getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
987
1183
  getVariableByKey(key: string): VariableDeclaration | undefined;
988
1184
  dispose(): void;
1185
+ onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
989
1186
  onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
990
- onAnyChange(observer: () => void): Disposable;
1187
+ onListOrAnyVarChange(observer: () => void): Disposable;
991
1188
  }
992
1189
 
993
1190
  declare class VariableEngine implements Disposable {
@@ -1034,11 +1231,21 @@ declare const ScopeProvider: react.Provider<ScopeContextProps>;
1034
1231
  declare const useScopeContext: () => ScopeContextProps | null;
1035
1232
  declare const useCurrentScope: () => Scope<Record<string, any>>;
1036
1233
 
1234
+ /**
1235
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1236
+ * SPDX-License-Identifier: MIT
1237
+ */
1238
+
1037
1239
  /**
1038
1240
  * 获取作用域的可访问变量
1039
1241
  */
1040
1242
  declare function useScopeAvailable(): ScopeAvailableData;
1041
1243
 
1244
+ /**
1245
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1246
+ * SPDX-License-Identifier: MIT
1247
+ */
1248
+
1042
1249
  /**
1043
1250
  * 获取作用域的可访问变量
1044
1251
  */
package/dist/index.js CHANGED
@@ -134,29 +134,41 @@ var VariableTable = class {
134
134
  ),
135
135
  (0, import_rxjs.share)()
136
136
  );
137
+ /**
138
+ * @deprecated use onListOrAnyVarChange instead
139
+ */
137
140
  this.onDataChange = this.onDataChangeEmitter.event;
138
141
  this._version = 0;
139
142
  }
140
143
  /**
141
- * 监听任意变量变化
142
- * @param observer 监听器,变量变化时会吐出值
144
+ * listen to any variable update in list
145
+ * @param observer
143
146
  * @returns
144
147
  */
145
148
  onAnyVariableChange(observer) {
146
149
  return subsToDisposable(this.anyVariableChange$.subscribe(observer));
147
150
  }
148
151
  /**
149
- * 列表或者任意变量变化
152
+ * listen to variable list change
150
153
  * @param observer
154
+ * @returns
151
155
  */
152
- onAnyChange(observer) {
156
+ onVariableListChange(observer) {
157
+ return subsToDisposable(this.variables$.subscribe(observer));
158
+ }
159
+ /**
160
+ * listen to variable list change + any variable update in list
161
+ * @param observer
162
+ */
163
+ onListOrAnyVarChange(observer) {
153
164
  const disposables = new import_utils2.DisposableCollection();
154
- disposables.pushAll([this.onDataChange(observer), this.onAnyVariableChange(observer)]);
165
+ disposables.pushAll([this.onVariableListChange(observer), this.onAnyVariableChange(observer)]);
155
166
  return disposables;
156
167
  }
157
168
  fireChange() {
158
169
  this._version++;
159
170
  this.onDataChangeEmitter.fire();
171
+ this.variables$.next(this.variables);
160
172
  this.parentTable?.fireChange();
161
173
  }
162
174
  get version() {
@@ -198,7 +210,6 @@ var VariableTable = class {
198
210
  if (this.parentTable) {
199
211
  this.parentTable.addVariableToTable(variable);
200
212
  }
201
- this.variables$.next(this.variables);
202
213
  }
203
214
  /**
204
215
  * 从 variableTable 中移除变量
@@ -209,12 +220,14 @@ var VariableTable = class {
209
220
  if (this.parentTable) {
210
221
  this.parentTable.removeVariableFromTable(key);
211
222
  }
212
- this.variables$.next(this.variables);
213
223
  }
214
224
  dispose() {
215
225
  this.variableKeys.forEach(
216
226
  (_key) => this.parentTable?.removeVariableFromTable(_key)
217
227
  );
228
+ this.parentTable?.fireChange();
229
+ this.variables$.complete();
230
+ this.variables$.unsubscribe();
218
231
  this.onDataChangeEmitter.dispose();
219
232
  }
220
233
  };
@@ -1174,9 +1187,11 @@ var WrapArrayExpression = class extends BaseExpression {
1174
1187
  };
1175
1188
  }
1176
1189
  init() {
1190
+ this.refreshReturnType = this.refreshReturnType.bind(this);
1177
1191
  this.toDispose.push(
1178
1192
  this.subscribe(this.refreshReturnType, {
1179
- selector: (curr) => curr.wrapFor?.returnType
1193
+ selector: (curr) => curr.wrapFor?.returnType,
1194
+ triggerOnInit: true
1180
1195
  })
1181
1196
  );
1182
1197
  }
@@ -1200,6 +1215,9 @@ var BaseVariableField = class extends ASTNode {
1200
1215
  get parentFields() {
1201
1216
  return getParentFields(this);
1202
1217
  }
1218
+ get keyPath() {
1219
+ return this.parentFields.reverse().map((_field) => _field.key);
1220
+ }
1203
1221
  get meta() {
1204
1222
  return this._meta;
1205
1223
  }
@@ -1209,6 +1227,9 @@ var BaseVariableField = class extends ASTNode {
1209
1227
  get initializer() {
1210
1228
  return this._initializer;
1211
1229
  }
1230
+ get hash() {
1231
+ return `[${this._version}]${this.keyPath.join(".")}`;
1232
+ }
1212
1233
  /**
1213
1234
  * 解析 VariableDeclarationJSON 从而生成变量声明节点
1214
1235
  */
@@ -1641,12 +1662,30 @@ var ScopeOutputData = class {
1641
1662
  get globalVariableTable() {
1642
1663
  return this.scope.variableEngine.globalVariableTable;
1643
1664
  }
1665
+ /**
1666
+ * @deprecated use onListOrAnyVarChange instead
1667
+ */
1644
1668
  get onDataChange() {
1645
1669
  return this.variableTable.onDataChange.bind(this.variableTable);
1646
1670
  }
1671
+ /**
1672
+ * listen to variable list change
1673
+ */
1674
+ get onVariableListChange() {
1675
+ return this.variableTable.onVariableListChange.bind(this.variableTable);
1676
+ }
1677
+ /**
1678
+ * listen to any variable update in list
1679
+ */
1647
1680
  get onAnyVariableChange() {
1648
1681
  return this.variableTable.onAnyVariableChange.bind(this.variableTable);
1649
1682
  }
1683
+ /**
1684
+ * listen to variable list change + any variable update in list
1685
+ */
1686
+ get onListOrAnyVarChange() {
1687
+ return this.variableTable.onListOrAnyVarChange.bind(this.variableTable);
1688
+ }
1650
1689
  /**
1651
1690
  * Scope Output Variable Declarations
1652
1691
  */
@@ -1720,19 +1759,29 @@ var ScopeAvailableData = class {
1720
1759
  ),
1721
1760
  (0, import_rxjs4.share)()
1722
1761
  );
1762
+ /**
1763
+ * @deprecated
1764
+ */
1723
1765
  this.onDataChangeEmitter = new import_utils6.Emitter();
1766
+ this.onListOrAnyVarChangeEmitter = new import_utils6.Emitter();
1724
1767
  /**
1725
- * 监听变量列表变化 + 任意子变量变化
1768
+ * @deprecated use available.onListOrAnyVarChange instead
1726
1769
  */
1727
1770
  this.onDataChange = this.onDataChangeEmitter.event;
1771
+ /**
1772
+ * listen to variable list change + any variable drilldown change
1773
+ */
1774
+ this.onListOrAnyVarChange = this.onListOrAnyVarChangeEmitter.event;
1728
1775
  this.scope.toDispose.pushAll([
1729
1776
  this.onVariableListChange((_variables) => {
1730
1777
  this._variables = _variables;
1731
1778
  this.memo.clear();
1732
1779
  this.onDataChangeEmitter.fire(this._variables);
1780
+ this.onListOrAnyVarChangeEmitter.fire(this._variables);
1733
1781
  }),
1734
1782
  this.onAnyVariableChange(() => {
1735
1783
  this.onDataChangeEmitter.fire(this._variables);
1784
+ this.onListOrAnyVarChangeEmitter.fire(this._variables);
1736
1785
  }),
1737
1786
  import_utils5.Disposable.create(() => {
1738
1787
  this.refresh$.complete();
@@ -1751,15 +1800,15 @@ var ScopeAvailableData = class {
1751
1800
  this.refresh$.next();
1752
1801
  }
1753
1802
  /**
1754
- * 监听任意变量变化
1755
- * @param observer 监听器,变量变化时会吐出值
1803
+ * listen to any variable update in list
1804
+ * @param observer
1756
1805
  * @returns
1757
1806
  */
1758
1807
  onAnyVariableChange(observer) {
1759
1808
  return subsToDisposable(this.anyVariableChange$.subscribe(observer));
1760
1809
  }
1761
1810
  /**
1762
- * 监听变量列表变化
1811
+ * listen to variable list change
1763
1812
  * @param observer
1764
1813
  * @returns
1765
1814
  */
@@ -1795,6 +1844,20 @@ var ScopeAvailableData = class {
1795
1844
  }
1796
1845
  return this.globalVariableTable.getByKeyPath(keyPath);
1797
1846
  }
1847
+ /**
1848
+ * Track Variable Change (Includes type update and children update) By KeyPath
1849
+ * @returns
1850
+ */
1851
+ trackByKeyPath(keyPath = [], cb, opts) {
1852
+ const { triggerOnInit = true } = opts || {};
1853
+ return subsToDisposable(
1854
+ (0, import_rxjs4.merge)(this.anyVariableChange$, this.variables$).pipe(
1855
+ triggerOnInit ? (0, import_rxjs4.startWith)() : (0, import_rxjs4.tap)(() => null),
1856
+ (0, import_rxjs4.map)(() => this.getByKeyPath(keyPath)),
1857
+ (0, import_rxjs4.distinctUntilChanged)((_prevNode, _node) => _prevNode?.hash !== _node?.hash)
1858
+ ).subscribe(cb)
1859
+ );
1860
+ }
1798
1861
  };
1799
1862
 
1800
1863
  // src/scope/datas/scope-event-data.ts
@@ -1878,6 +1941,33 @@ var Scope = class {
1878
1941
  get disposed() {
1879
1942
  return this.toDispose.disposed;
1880
1943
  }
1944
+ setVar(arg1, arg2) {
1945
+ if (typeof arg1 === "string" && arg2 !== void 0) {
1946
+ return this.ast.set(arg1, arg2);
1947
+ }
1948
+ if (typeof arg1 === "object" && arg2 === void 0) {
1949
+ return this.ast.set("outputs", arg1);
1950
+ }
1951
+ throw new Error("Invalid arguments");
1952
+ }
1953
+ /**
1954
+ * Retrieves a variable from the Scope by key.
1955
+ *
1956
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
1957
+ * @returns The value of the variable, or undefined if not found.
1958
+ */
1959
+ getVar(key = "outputs") {
1960
+ return this.ast.get(key);
1961
+ }
1962
+ /**
1963
+ * Clears a variable from the Scope by key.
1964
+ *
1965
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
1966
+ * @returns The updated AST node.
1967
+ */
1968
+ clearVar(key = "outputs") {
1969
+ return this.ast.remove(key);
1970
+ }
1881
1971
  };
1882
1972
 
1883
1973
  // src/variable-engine.ts
@@ -2102,7 +2192,7 @@ function useAvailableVariables() {
2102
2192
  const refresh = (0, import_core2.useRefresh)();
2103
2193
  (0, import_react3.useEffect)(() => {
2104
2194
  if (!scope) {
2105
- const disposable2 = variableEngine.globalVariableTable.onAnyChange(() => {
2195
+ const disposable2 = variableEngine.globalVariableTable.onListOrAnyVarChange(() => {
2106
2196
  refresh();
2107
2197
  });
2108
2198
  return () => disposable2.dispose();