@flowgram.ai/variable-core 0.1.24 → 0.1.25

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.js CHANGED
@@ -64,7 +64,6 @@ __export(src_exports, {
64
64
  VariableEngine: () => VariableEngine,
65
65
  VariableEngineProvider: () => VariableEngineProvider,
66
66
  VariableFieldKeyRenameService: () => VariableFieldKeyRenameService,
67
- VariableTable: () => VariableTable,
68
67
  injectToAST: () => injectToAST,
69
68
  isMatchAST: () => isMatchAST,
70
69
  postConstructAST: () => postConstructAST,
@@ -81,8 +80,8 @@ var import_inversify7 = require("inversify");
81
80
  // src/variable-engine.ts
82
81
  var import_rxjs6 = require("rxjs");
83
82
  var import_inversify5 = require("inversify");
84
- var import_utils10 = require("@flowgram.ai/utils");
85
- var import_utils11 = require("@flowgram.ai/utils");
83
+ var import_utils8 = require("@flowgram.ai/utils");
84
+ var import_utils9 = require("@flowgram.ai/utils");
86
85
 
87
86
  // src/utils/toDisposable.tsx
88
87
  var import_utils = require("@flowgram.ai/utils");
@@ -112,9 +111,117 @@ var createMemo = () => {
112
111
  return memo;
113
112
  };
114
113
 
114
+ // src/scope/variable-table.ts
115
+ var import_rxjs = require("rxjs");
116
+ var import_utils2 = require("@flowgram.ai/utils");
117
+ var VariableTable = class {
118
+ constructor(parentTable) {
119
+ this.parentTable = parentTable;
120
+ this.table = /* @__PURE__ */ new Map();
121
+ this.onDataChangeEmitter = new import_utils2.Emitter();
122
+ this.variables$ = new import_rxjs.Subject();
123
+ // 监听变量列表中的单个变量变化
124
+ this.anyVariableChange$ = this.variables$.pipe(
125
+ (0, import_rxjs.switchMap)(
126
+ (_variables) => (0, import_rxjs.merge)(
127
+ ..._variables.map(
128
+ (_v) => _v.value$.pipe(
129
+ // 跳过 BehaviorSubject 第一个
130
+ (0, import_rxjs.skip)(1)
131
+ )
132
+ )
133
+ )
134
+ ),
135
+ (0, import_rxjs.share)()
136
+ );
137
+ this.onDataChange = this.onDataChangeEmitter.event;
138
+ this._version = 0;
139
+ }
140
+ /**
141
+ * 监听任意变量变化
142
+ * @param observer 监听器,变量变化时会吐出值
143
+ * @returns
144
+ */
145
+ onAnyVariableChange(observer) {
146
+ return subsToDisposable(this.anyVariableChange$.subscribe(observer));
147
+ }
148
+ /**
149
+ * 列表或者任意变量变化
150
+ * @param observer
151
+ */
152
+ onAnyChange(observer) {
153
+ const disposables = new import_utils2.DisposableCollection();
154
+ disposables.pushAll([this.onDataChange(observer), this.onAnyVariableChange(observer)]);
155
+ return disposables;
156
+ }
157
+ fireChange() {
158
+ this._version++;
159
+ this.onDataChangeEmitter.fire();
160
+ this.parentTable?.fireChange();
161
+ }
162
+ get version() {
163
+ return this._version;
164
+ }
165
+ get variables() {
166
+ return Array.from(this.table.values());
167
+ }
168
+ get variableKeys() {
169
+ return Array.from(this.table.keys());
170
+ }
171
+ /**
172
+ * 根据 keyPath 找到对应的变量,或 Property 节点
173
+ * @param keyPath
174
+ * @returns
175
+ */
176
+ getByKeyPath(keyPath) {
177
+ const [variableKey, ...propertyKeys] = keyPath || [];
178
+ if (!variableKey) {
179
+ return;
180
+ }
181
+ const variable = this.getVariableByKey(variableKey);
182
+ return propertyKeys.length ? variable?.getByKeyPath(propertyKeys) : variable;
183
+ }
184
+ /**
185
+ * 根据 key 值找到相应的变量
186
+ * @param key
187
+ * @returns
188
+ */
189
+ getVariableByKey(key) {
190
+ return this.table.get(key);
191
+ }
192
+ /**
193
+ * 往 variableTable 添加输出变量
194
+ * @param variable
195
+ */
196
+ addVariableToTable(variable) {
197
+ this.table.set(variable.key, variable);
198
+ if (this.parentTable) {
199
+ this.parentTable.addVariableToTable(variable);
200
+ }
201
+ this.variables$.next(this.variables);
202
+ }
203
+ /**
204
+ * 从 variableTable 中移除变量
205
+ * @param key
206
+ */
207
+ removeVariableFromTable(key) {
208
+ this.table.delete(key);
209
+ if (this.parentTable) {
210
+ this.parentTable.removeVariableFromTable(key);
211
+ }
212
+ this.variables$.next(this.variables);
213
+ }
214
+ dispose() {
215
+ this.variableKeys.forEach(
216
+ (_key) => this.parentTable?.removeVariableFromTable(_key)
217
+ );
218
+ this.onDataChangeEmitter.dispose();
219
+ }
220
+ };
221
+
115
222
  // src/scope/scope-chain.ts
116
223
  var import_inversify = require("inversify");
117
- var import_utils2 = require("@flowgram.ai/utils");
224
+ var import_utils3 = require("@flowgram.ai/utils");
118
225
 
119
226
  // src/providers.ts
120
227
  var VariableEngineProvider = Symbol("DynamicVariableEngine");
@@ -123,7 +230,7 @@ var ContainerProvider = Symbol("ContainerProvider");
123
230
  // src/scope/scope-chain.ts
124
231
  var ScopeChain = class {
125
232
  constructor() {
126
- this.toDispose = new import_utils2.DisposableCollection();
233
+ this.toDispose = new import_utils3.DisposableCollection();
127
234
  }
128
235
  get variableEngine() {
129
236
  return this.variableEngineProvider();
@@ -155,7 +262,7 @@ ScopeChain = __decorateClass([
155
262
  ], ScopeChain);
156
263
 
157
264
  // src/scope/scope.ts
158
- var import_utils9 = require("@flowgram.ai/utils");
265
+ var import_utils7 = require("@flowgram.ai/utils");
159
266
 
160
267
  // src/ast/types.ts
161
268
  var ASTKind = /* @__PURE__ */ ((ASTKind2) => {
@@ -287,10 +394,10 @@ var ASTNodeFlags = /* @__PURE__ */ ((ASTNodeFlags2) => {
287
394
  })(ASTNodeFlags || {});
288
395
 
289
396
  // src/ast/ast-node.ts
290
- var import_rxjs = require("rxjs");
397
+ var import_rxjs2 = require("rxjs");
291
398
  var import_nanoid = require("nanoid");
292
399
  var import_fast_equals = require("fast-equals");
293
- var import_utils3 = require("@flowgram.ai/utils");
400
+ var import_utils4 = require("@flowgram.ai/utils");
294
401
  var ASTNode = class _ASTNode {
295
402
  /**
296
403
  * 构造函数
@@ -321,7 +428,7 @@ var ASTNode = class _ASTNode {
321
428
  * AST 节点变化事件,基于 Rxjs 实现
322
429
  * - 使用了 BehaviorSubject, 在订阅时会自动触发一次事件,事件为当前值
323
430
  */
324
- this.value$ = new import_rxjs.BehaviorSubject(this);
431
+ this.value$ = new import_rxjs2.BehaviorSubject(this);
325
432
  /**
326
433
  * 子节点
327
434
  */
@@ -329,8 +436,8 @@ var ASTNode = class _ASTNode {
329
436
  /**
330
437
  * 删除节点处理事件列表
331
438
  */
332
- this.toDispose = new import_utils3.DisposableCollection(
333
- import_utils3.Disposable.create(() => {
439
+ this.toDispose = new import_utils4.DisposableCollection(
440
+ import_utils4.Disposable.create(() => {
334
441
  this.parent?.fireChange();
335
442
  this.children.forEach((child) => child.dispose());
336
443
  })
@@ -384,7 +491,7 @@ var ASTNode = class _ASTNode {
384
491
  });
385
492
  this._children.add(child);
386
493
  child.toDispose.push(
387
- import_utils3.Disposable.create(() => {
494
+ import_utils4.Disposable.create(() => {
388
495
  this._children.delete(child);
389
496
  })
390
497
  );
@@ -461,8 +568,8 @@ var ASTNode = class _ASTNode {
461
568
  subscribe(observer, { selector, debounceAnimation, triggerOnInit } = {}) {
462
569
  return subsToDisposable(
463
570
  this.value$.pipe(
464
- (0, import_rxjs.map)(() => selector ? selector(this) : this),
465
- (0, import_rxjs.distinctUntilChanged)(
571
+ (0, import_rxjs2.map)(() => selector ? selector(this) : this),
572
+ (0, import_rxjs2.distinctUntilChanged)(
466
573
  (a, b) => (0, import_fast_equals.shallowEqual)(a, b),
467
574
  (value) => {
468
575
  if (value instanceof _ASTNode) {
@@ -472,9 +579,9 @@ var ASTNode = class _ASTNode {
472
579
  }
473
580
  ),
474
581
  // 默认跳过 BehaviorSubject 第一次触发
475
- triggerOnInit ? (0, import_rxjs.tap)(() => null) : (0, import_rxjs.skip)(1),
582
+ triggerOnInit ? (0, import_rxjs2.tap)(() => null) : (0, import_rxjs2.skip)(1),
476
583
  // 每个 animationFrame 内所有更新合并成一个
477
- debounceAnimation ? (0, import_rxjs.debounceTime)(0, import_rxjs.animationFrameScheduler) : (0, import_rxjs.tap)(() => null)
584
+ debounceAnimation ? (0, import_rxjs2.debounceTime)(0, import_rxjs2.animationFrameScheduler) : (0, import_rxjs2.tap)(() => null)
478
585
  ).subscribe(observer)
479
586
  );
480
587
  }
@@ -780,7 +887,7 @@ var CustomType = class extends BaseType {
780
887
  CustomType.kind = "CustomType" /* CustomType */;
781
888
 
782
889
  // src/ast/expression/base-expression.ts
783
- var import_rxjs2 = require("rxjs");
890
+ var import_rxjs3 = require("rxjs");
784
891
  var import_fast_equals2 = require("fast-equals");
785
892
 
786
893
  // src/ast/utils/variable-field.ts
@@ -805,22 +912,22 @@ var BaseExpression = class extends ASTNode {
805
912
  * 引用变量
806
913
  */
807
914
  this._refs = [];
808
- this.refreshRefs$ = new import_rxjs2.Subject();
915
+ this.refreshRefs$ = new import_rxjs3.Subject();
809
916
  /**
810
917
  * 监听引用变量变化
811
918
  * 监听 [a.b.c] -> [a.b]
812
919
  */
813
920
  this.refs$ = this.refreshRefs$.pipe(
814
- (0, import_rxjs2.map)(() => this.getRefFields()),
815
- (0, import_rxjs2.distinctUntilChanged)(import_fast_equals2.shallowEqual),
816
- (0, import_rxjs2.switchMap)(
817
- (refs) => !refs?.length ? (0, import_rxjs2.of)([]) : (0, import_rxjs2.combineLatest)(
921
+ (0, import_rxjs3.map)(() => this.getRefFields()),
922
+ (0, import_rxjs3.distinctUntilChanged)(import_fast_equals2.shallowEqual),
923
+ (0, import_rxjs3.switchMap)(
924
+ (refs) => !refs?.length ? (0, import_rxjs3.of)([]) : (0, import_rxjs3.combineLatest)(
818
925
  refs.map(
819
- (ref) => ref ? ref.value$ : (0, import_rxjs2.of)(void 0)
926
+ (ref) => ref ? ref.value$ : (0, import_rxjs3.of)(void 0)
820
927
  )
821
928
  )
822
929
  ),
823
- (0, import_rxjs2.share)()
930
+ (0, import_rxjs3.share)()
824
931
  );
825
932
  this.toDispose.push(
826
933
  subsToDisposable(
@@ -1058,9 +1165,6 @@ var KeyPathExpressionV2 = class extends BaseExpression {
1058
1165
  };
1059
1166
  KeyPathExpressionV2.kind = "KeyPathExpression" /* KeyPathExpression */;
1060
1167
 
1061
- // src/ast/declaration/variable-declaration.ts
1062
- var import_utils4 = require("@flowgram.ai/utils");
1063
-
1064
1168
  // src/ast/declaration/base-variable-field.ts
1065
1169
  var import_fast_equals5 = require("fast-equals");
1066
1170
  var BaseVariableField = class extends ASTNode {
@@ -1144,13 +1248,6 @@ var VariableDeclaration = class extends BaseVariableField {
1144
1248
  constructor(params) {
1145
1249
  super(params);
1146
1250
  this._order = 0;
1147
- this.scope.output.addVariableToTable(this);
1148
- this.toDispose.push(
1149
- import_utils4.Disposable.create(() => {
1150
- this.scope.output.setHasChanges();
1151
- this.scope.output.removeVariableFromTable(this.key);
1152
- })
1153
- );
1154
1251
  }
1155
1252
  get order() {
1156
1253
  return this._order;
@@ -1165,7 +1262,9 @@ var VariableDeclaration = class extends BaseVariableField {
1165
1262
  updateOrder(order = 0) {
1166
1263
  if (order !== this._order) {
1167
1264
  this._order = order;
1168
- this.scope.output.setHasChanges();
1265
+ this.dispatchGlobalEvent({
1266
+ type: "ReSortVariableDeclarations"
1267
+ });
1169
1268
  this.fireChange();
1170
1269
  }
1171
1270
  }
@@ -1478,113 +1577,6 @@ var ASTFactory;
1478
1577
  ASTFactory2.create = (targetType, json) => ({ kind: targetType.kind, ...json });
1479
1578
  })(ASTFactory || (ASTFactory = {}));
1480
1579
 
1481
- // src/scope/variable-table.ts
1482
- var import_rxjs3 = require("rxjs");
1483
- var import_utils5 = require("@flowgram.ai/utils");
1484
- var import_utils6 = require("@flowgram.ai/utils");
1485
- var VariableTable = class {
1486
- constructor(parentTable) {
1487
- this.parentTable = parentTable;
1488
- this.table = /* @__PURE__ */ new Map();
1489
- this.onDataChangeEmitter = new import_utils5.Emitter();
1490
- this.variables$ = new import_rxjs3.Subject();
1491
- // 监听变量列表中的单个变量变化
1492
- this.anyVariableChange$ = this.variables$.pipe(
1493
- (0, import_rxjs3.switchMap)(
1494
- (_variables) => (0, import_rxjs3.merge)(
1495
- ..._variables.map(
1496
- (_v) => _v.value$.pipe(
1497
- // 跳过 BehaviorSubject 第一个
1498
- (0, import_rxjs3.skip)(1)
1499
- )
1500
- )
1501
- )
1502
- ),
1503
- (0, import_rxjs3.share)()
1504
- );
1505
- this.onDataChange = this.onDataChangeEmitter.event;
1506
- this._version = 0;
1507
- }
1508
- /**
1509
- * 监听任意变量变化
1510
- * @param observer 监听器,变量变化时会吐出值
1511
- * @returns
1512
- */
1513
- onAnyVariableChange(observer) {
1514
- return subsToDisposable(this.anyVariableChange$.subscribe(observer));
1515
- }
1516
- /**
1517
- * 列表或者任意变量变化
1518
- * @param observer
1519
- */
1520
- onAnyChange(observer) {
1521
- const disposables = new import_utils6.DisposableCollection();
1522
- disposables.pushAll([this.onDataChange(observer), this.onAnyVariableChange(observer)]);
1523
- return disposables;
1524
- }
1525
- fireChange() {
1526
- this._version++;
1527
- this.onDataChangeEmitter.fire();
1528
- this.parentTable?.fireChange();
1529
- }
1530
- get version() {
1531
- return this._version;
1532
- }
1533
- get variables() {
1534
- return Array.from(this.table.values());
1535
- }
1536
- get variableKeys() {
1537
- return Array.from(this.table.keys());
1538
- }
1539
- /**
1540
- * 根据 keyPath 找到对应的变量,或 Property 节点
1541
- * @param keyPath
1542
- * @returns
1543
- */
1544
- getByKeyPath(keyPath) {
1545
- const [variableKey, ...propertyKeys] = keyPath || [];
1546
- if (!variableKey) {
1547
- return;
1548
- }
1549
- const variable = this.getVariableByKey(variableKey);
1550
- return propertyKeys.length ? variable?.getByKeyPath(propertyKeys) : variable;
1551
- }
1552
- /**
1553
- * 根据 key 值找到相应的变量
1554
- * @param key
1555
- * @returns
1556
- */
1557
- getVariableByKey(key) {
1558
- return this.table.get(key);
1559
- }
1560
- /**
1561
- * 往 variableTable 添加输出变量
1562
- * @param variable
1563
- */
1564
- addVariableToTable(variable) {
1565
- this.table.set(variable.key, variable);
1566
- if (this.parentTable) {
1567
- this.parentTable.addVariableToTable(variable);
1568
- }
1569
- this.variables$.next(this.variables);
1570
- }
1571
- /**
1572
- * 从 variableTable 中移除变量
1573
- * @param key
1574
- */
1575
- removeVariableFromTable(key) {
1576
- this.table.delete(key);
1577
- if (this.parentTable) {
1578
- this.parentTable.removeVariableFromTable(key);
1579
- }
1580
- this.variables$.next(this.variables);
1581
- }
1582
- dispose() {
1583
- this.variableKeys.forEach((_key) => this.parentTable?.removeVariableFromTable(_key));
1584
- this.onDataChangeEmitter.dispose();
1585
- }
1586
- };
1587
-
1588
1580
  // src/scope/datas/scope-output-data.ts
1589
1581
  var ScopeOutputData = class {
1590
1582
  constructor(scope) {
@@ -1593,7 +1585,7 @@ var ScopeOutputData = class {
1593
1585
  this._hasChanges = false;
1594
1586
  this.variableTable = new VariableTable(scope.variableEngine.globalVariableTable);
1595
1587
  this.scope.toDispose.pushAll([
1596
- // AST 根节点更新时,检查在这次 AST 变化期间节点是否有变化
1588
+ // When root AST node is updated, check if there are any changes during this AST change
1597
1589
  this.scope.ast.subscribe(() => {
1598
1590
  if (this._hasChanges) {
1599
1591
  this.memo.clear();
@@ -1602,6 +1594,19 @@ var ScopeOutputData = class {
1602
1594
  this._hasChanges = false;
1603
1595
  }
1604
1596
  }),
1597
+ this.scope.event.on("DisposeAST", (_action) => {
1598
+ if (_action.ast?.kind === "VariableDeclaration" /* VariableDeclaration */) {
1599
+ this.removeVariableFromTable(_action.ast.key);
1600
+ }
1601
+ }),
1602
+ this.scope.event.on("NewAST", (_action) => {
1603
+ if (_action.ast?.kind === "VariableDeclaration" /* VariableDeclaration */) {
1604
+ this.addVariableToTable(_action.ast);
1605
+ }
1606
+ }),
1607
+ this.scope.event.on("ReSortVariableDeclarations", () => {
1608
+ this._hasChanges = true;
1609
+ }),
1605
1610
  this.variableTable
1606
1611
  ]);
1607
1612
  }
@@ -1618,7 +1623,7 @@ var ScopeOutputData = class {
1618
1623
  return this.variableTable.onAnyVariableChange.bind(this.variableTable);
1619
1624
  }
1620
1625
  /**
1621
- * 作用域输出变量
1626
+ * Scope Output Variable Declarations
1622
1627
  */
1623
1628
  get variables() {
1624
1629
  return this.memo(
@@ -1627,7 +1632,7 @@ var ScopeOutputData = class {
1627
1632
  );
1628
1633
  }
1629
1634
  /**
1630
- * 输出的变量 keys
1635
+ * Output Variable Keys
1631
1636
  */
1632
1637
  get variableKeys() {
1633
1638
  return this.memo("variableKeys", () => this.variableTable.variableKeys);
@@ -1639,10 +1644,6 @@ var ScopeOutputData = class {
1639
1644
  this.variableTable.addVariableToTable(variable);
1640
1645
  this._hasChanges = true;
1641
1646
  }
1642
- // 标记为发生了变化,用于变量排序变化的场景
1643
- setHasChanges() {
1644
- this._hasChanges = true;
1645
- }
1646
1647
  removeVariableFromTable(key) {
1647
1648
  this.variableTable.removeVariableFromTable(key);
1648
1649
  this._hasChanges = true;
@@ -1650,7 +1651,9 @@ var ScopeOutputData = class {
1650
1651
  getVariableByKey(key) {
1651
1652
  return this.variableTable.getVariableByKey(key);
1652
1653
  }
1653
- // 通知覆盖作用域更新可用变量
1654
+ /**
1655
+ *
1656
+ */
1654
1657
  notifyCoversChange() {
1655
1658
  this.scope.coverScopes.forEach((scope) => scope.available.refresh());
1656
1659
  }
@@ -1660,8 +1663,8 @@ var ScopeOutputData = class {
1660
1663
  var import_rxjs4 = require("rxjs");
1661
1664
  var import_lodash4 = require("lodash");
1662
1665
  var import_fast_equals7 = require("fast-equals");
1663
- var import_utils7 = require("@flowgram.ai/utils");
1664
- var import_utils8 = require("@flowgram.ai/utils");
1666
+ var import_utils5 = require("@flowgram.ai/utils");
1667
+ var import_utils6 = require("@flowgram.ai/utils");
1665
1668
  var ScopeAvailableData = class {
1666
1669
  constructor(scope) {
1667
1670
  this.scope = scope;
@@ -1692,7 +1695,7 @@ var ScopeAvailableData = class {
1692
1695
  ),
1693
1696
  (0, import_rxjs4.share)()
1694
1697
  );
1695
- this.onDataChangeEmitter = new import_utils8.Emitter();
1698
+ this.onDataChangeEmitter = new import_utils6.Emitter();
1696
1699
  /**
1697
1700
  * 监听变量列表变化 + 任意子变量变化
1698
1701
  */
@@ -1706,7 +1709,7 @@ var ScopeAvailableData = class {
1706
1709
  this.onAnyVariableChange(() => {
1707
1710
  this.onDataChangeEmitter.fire(this._variables);
1708
1711
  }),
1709
- import_utils7.Disposable.create(() => {
1712
+ import_utils5.Disposable.create(() => {
1710
1713
  this.refresh$.complete();
1711
1714
  this.refresh$.unsubscribe();
1712
1715
  })
@@ -1804,7 +1807,7 @@ var Scope = class {
1804
1807
  * 数据缓存
1805
1808
  */
1806
1809
  this.memo = createMemo();
1807
- this.toDispose = new import_utils9.DisposableCollection();
1810
+ this.toDispose = new import_utils7.DisposableCollection();
1808
1811
  this.onDispose = this.toDispose.onDispose;
1809
1812
  this.id = options.id;
1810
1813
  this.meta = options.meta || {};
@@ -1813,7 +1816,7 @@ var Scope = class {
1813
1816
  this.ast = this.variableEngine.astRegisters.createAST(
1814
1817
  {
1815
1818
  kind: "MapNode" /* MapNode */,
1816
- key: this.id
1819
+ key: String(this.id)
1817
1820
  },
1818
1821
  {
1819
1822
  scope: this
@@ -1857,16 +1860,16 @@ var VariableEngine = class {
1857
1860
  constructor(chain, astRegisters) {
1858
1861
  this.chain = chain;
1859
1862
  this.astRegisters = astRegisters;
1860
- this.toDispose = new import_utils10.DisposableCollection();
1863
+ this.toDispose = new import_utils8.DisposableCollection();
1861
1864
  this.memo = createMemo();
1862
1865
  this.scopeMap = /* @__PURE__ */ new Map();
1863
1866
  this.globalEvent$ = new import_rxjs6.Subject();
1864
- this.onScopeChangeEmitter = new import_utils11.Emitter();
1867
+ this.onScopeChangeEmitter = new import_utils9.Emitter();
1865
1868
  this.globalVariableTable = new VariableTable();
1866
1869
  this.onScopeChange = this.onScopeChangeEmitter.event;
1867
1870
  this.toDispose.pushAll([
1868
1871
  chain,
1869
- import_utils10.Disposable.create(() => {
1872
+ import_utils8.Disposable.create(() => {
1870
1873
  this.getAllScopes().forEach((scope) => scope.dispose());
1871
1874
  this.globalVariableTable.dispose();
1872
1875
  })
@@ -1886,11 +1889,18 @@ var VariableEngine = class {
1886
1889
  removeScopeById(scopeId) {
1887
1890
  this.getScopeById(scopeId)?.dispose();
1888
1891
  }
1889
- // 获取 Scope,如果 Scope 存在且类型相同,则会直接使用
1890
- createScope(id, meta) {
1892
+ /**
1893
+ * Get Scope, if Scope exists and type is same, will use it directly
1894
+ * @param id scope id
1895
+ * @param meta scope meta, defined by user
1896
+ * @param ScopeConstructor scope constructor, default is Scope. you can extends Scope to create your own scope
1897
+ * @returns
1898
+ */
1899
+ createScope(id, meta, options = {}) {
1900
+ const { ScopeConstructor = Scope } = options;
1891
1901
  let scope = this.getScopeById(id);
1892
1902
  if (!scope) {
1893
- scope = new Scope({ variableEngine: this, meta, id });
1903
+ scope = new ScopeConstructor({ variableEngine: this, meta, id });
1894
1904
  this.scopeMap.set(id, scope);
1895
1905
  this.onScopeChangeEmitter.fire({ type: "add", scope });
1896
1906
  scope.toDispose.pushAll([
@@ -1950,13 +1960,13 @@ VariableEngine = __decorateClass([
1950
1960
  // src/services/variable-field-key-rename-service.ts
1951
1961
  var import_lodash5 = require("lodash");
1952
1962
  var import_inversify6 = require("inversify");
1953
- var import_utils12 = require("@flowgram.ai/utils");
1963
+ var import_utils10 = require("@flowgram.ai/utils");
1954
1964
  var VariableFieldKeyRenameService = class {
1955
1965
  constructor() {
1956
- this.toDispose = new import_utils12.DisposableCollection();
1957
- this.renameEmitter = new import_utils12.Emitter();
1966
+ this.toDispose = new import_utils10.DisposableCollection();
1967
+ this.renameEmitter = new import_utils10.Emitter();
1958
1968
  // 没有被 rename 的字段通过 disposeInList 透出,让业务区分变量是 rename 删除的,还是真正从列表中删除的
1959
- this.disposeInListEmitter = new import_utils12.Emitter();
1969
+ this.disposeInListEmitter = new import_utils10.Emitter();
1960
1970
  this.onRename = this.renameEmitter.event;
1961
1971
  this.onDisposeInList = this.disposeInListEmitter.event;
1962
1972
  }
@@ -2116,7 +2126,6 @@ function useAvailableVariables() {
2116
2126
  VariableEngine,
2117
2127
  VariableEngineProvider,
2118
2128
  VariableFieldKeyRenameService,
2119
- VariableTable,
2120
2129
  injectToAST,
2121
2130
  isMatchAST,
2122
2131
  postConstructAST,