@flowgram.ai/variable-core 0.1.0-alpha.7 → 0.1.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +315 -241
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +546 -547
- package/dist/index.d.ts +546 -547
- package/dist/index.js +349 -276
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/esm/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { ContainerModule } from "inversify";
|
|
|
16
16
|
// src/variable-engine.ts
|
|
17
17
|
import { Subject as Subject5 } from "rxjs";
|
|
18
18
|
import { inject as inject2, injectable as injectable3, preDestroy } from "inversify";
|
|
19
|
-
import { Disposable as
|
|
19
|
+
import { Disposable as Disposable4, DisposableCollection as DisposableCollection5 } from "@flowgram.ai/utils";
|
|
20
20
|
import { Emitter as Emitter3 } from "@flowgram.ai/utils";
|
|
21
21
|
|
|
22
22
|
// src/utils/toDisposable.tsx
|
|
@@ -47,9 +47,121 @@ var createMemo = () => {
|
|
|
47
47
|
return memo;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
// src/scope/variable-table.ts
|
|
51
|
+
import { Subject, merge, share, skip, switchMap } from "rxjs";
|
|
52
|
+
import { DisposableCollection, Emitter } from "@flowgram.ai/utils";
|
|
53
|
+
var VariableTable = class {
|
|
54
|
+
constructor(parentTable) {
|
|
55
|
+
this.parentTable = parentTable;
|
|
56
|
+
this.table = /* @__PURE__ */ new Map();
|
|
57
|
+
this.onDataChangeEmitter = new Emitter();
|
|
58
|
+
this.variables$ = new Subject();
|
|
59
|
+
// 监听变量列表中的单个变量变化
|
|
60
|
+
this.anyVariableChange$ = this.variables$.pipe(
|
|
61
|
+
switchMap(
|
|
62
|
+
(_variables) => merge(
|
|
63
|
+
..._variables.map(
|
|
64
|
+
(_v) => _v.value$.pipe(
|
|
65
|
+
// 跳过 BehaviorSubject 第一个
|
|
66
|
+
skip(1)
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
),
|
|
71
|
+
share()
|
|
72
|
+
);
|
|
73
|
+
this.onDataChange = this.onDataChangeEmitter.event;
|
|
74
|
+
this._version = 0;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 监听任意变量变化
|
|
78
|
+
* @param observer 监听器,变量变化时会吐出值
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
onAnyVariableChange(observer) {
|
|
82
|
+
return subsToDisposable(this.anyVariableChange$.subscribe(observer));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 列表或者任意变量变化
|
|
86
|
+
* @param observer
|
|
87
|
+
*/
|
|
88
|
+
onAnyChange(observer) {
|
|
89
|
+
const disposables = new DisposableCollection();
|
|
90
|
+
disposables.pushAll([this.onDataChange(observer), this.onAnyVariableChange(observer)]);
|
|
91
|
+
return disposables;
|
|
92
|
+
}
|
|
93
|
+
fireChange() {
|
|
94
|
+
var _a;
|
|
95
|
+
this._version++;
|
|
96
|
+
this.onDataChangeEmitter.fire();
|
|
97
|
+
(_a = this.parentTable) == null ? void 0 : _a.fireChange();
|
|
98
|
+
}
|
|
99
|
+
get version() {
|
|
100
|
+
return this._version;
|
|
101
|
+
}
|
|
102
|
+
get variables() {
|
|
103
|
+
return Array.from(this.table.values());
|
|
104
|
+
}
|
|
105
|
+
get variableKeys() {
|
|
106
|
+
return Array.from(this.table.keys());
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 根据 keyPath 找到对应的变量,或 Property 节点
|
|
110
|
+
* @param keyPath
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
getByKeyPath(keyPath) {
|
|
114
|
+
const [variableKey, ...propertyKeys] = keyPath || [];
|
|
115
|
+
if (!variableKey) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const variable = this.getVariableByKey(variableKey);
|
|
119
|
+
return propertyKeys.length ? variable == null ? void 0 : variable.getByKeyPath(propertyKeys) : variable;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 根据 key 值找到相应的变量
|
|
123
|
+
* @param key
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
getVariableByKey(key) {
|
|
127
|
+
return this.table.get(key);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 往 variableTable 添加输出变量
|
|
131
|
+
* @param variable
|
|
132
|
+
*/
|
|
133
|
+
addVariableToTable(variable) {
|
|
134
|
+
this.table.set(variable.key, variable);
|
|
135
|
+
if (this.parentTable) {
|
|
136
|
+
this.parentTable.addVariableToTable(variable);
|
|
137
|
+
}
|
|
138
|
+
this.variables$.next(this.variables);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 从 variableTable 中移除变量
|
|
142
|
+
* @param key
|
|
143
|
+
*/
|
|
144
|
+
removeVariableFromTable(key) {
|
|
145
|
+
this.table.delete(key);
|
|
146
|
+
if (this.parentTable) {
|
|
147
|
+
this.parentTable.removeVariableFromTable(key);
|
|
148
|
+
}
|
|
149
|
+
this.variables$.next(this.variables);
|
|
150
|
+
}
|
|
151
|
+
dispose() {
|
|
152
|
+
this.variableKeys.forEach(
|
|
153
|
+
(_key) => {
|
|
154
|
+
var _a;
|
|
155
|
+
return (_a = this.parentTable) == null ? void 0 : _a.removeVariableFromTable(_key);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
this.onDataChangeEmitter.dispose();
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
50
162
|
// src/scope/scope-chain.ts
|
|
51
163
|
import { inject, injectable } from "inversify";
|
|
52
|
-
import { DisposableCollection } from "@flowgram.ai/utils";
|
|
164
|
+
import { DisposableCollection as DisposableCollection2 } from "@flowgram.ai/utils";
|
|
53
165
|
|
|
54
166
|
// src/providers.ts
|
|
55
167
|
var VariableEngineProvider = Symbol("DynamicVariableEngine");
|
|
@@ -58,7 +170,7 @@ var ContainerProvider = Symbol("ContainerProvider");
|
|
|
58
170
|
// src/scope/scope-chain.ts
|
|
59
171
|
var ScopeChain = class {
|
|
60
172
|
constructor() {
|
|
61
|
-
this.toDispose = new
|
|
173
|
+
this.toDispose = new DisposableCollection2();
|
|
62
174
|
}
|
|
63
175
|
get variableEngine() {
|
|
64
176
|
return this.variableEngineProvider();
|
|
@@ -109,7 +221,7 @@ var ASTKind = /* @__PURE__ */ ((ASTKind2) => {
|
|
|
109
221
|
ASTKind2["VariableDeclarationList"] = "VariableDeclarationList";
|
|
110
222
|
ASTKind2["KeyPathExpression"] = "KeyPathExpression";
|
|
111
223
|
ASTKind2["EnumerateExpression"] = "EnumerateExpression";
|
|
112
|
-
ASTKind2["
|
|
224
|
+
ASTKind2["WrapArrayExpression"] = "WrapArrayExpression";
|
|
113
225
|
ASTKind2["ListNode"] = "ListNode";
|
|
114
226
|
ASTKind2["DataNode"] = "DataNode";
|
|
115
227
|
ASTKind2["MapNode"] = "MapNode";
|
|
@@ -151,21 +263,21 @@ var postConstructAST = () => (target, propertyKey) => {
|
|
|
151
263
|
// src/ast/match.ts
|
|
152
264
|
var ASTMatch;
|
|
153
265
|
((ASTMatch2) => {
|
|
154
|
-
ASTMatch2.isString = (node) => node
|
|
155
|
-
ASTMatch2.isNumber = (node) => node
|
|
156
|
-
ASTMatch2.isBoolean = (node) => node
|
|
157
|
-
ASTMatch2.isInteger = (node) => node
|
|
158
|
-
ASTMatch2.isObject = (node) => node
|
|
159
|
-
ASTMatch2.isArray = (node) => node
|
|
160
|
-
ASTMatch2.isMap = (node) => node
|
|
161
|
-
ASTMatch2.isCustomType = (node) => node
|
|
162
|
-
ASTMatch2.isVariableDeclaration = (node) => node
|
|
163
|
-
ASTMatch2.isProperty = (node) => node
|
|
164
|
-
ASTMatch2.isVariableDeclarationList = (node) => node
|
|
165
|
-
ASTMatch2.isEnumerateExpression = (node) => node
|
|
166
|
-
ASTMatch2.isKeyPathExpression = (node) => node
|
|
266
|
+
ASTMatch2.isString = (node) => (node == null ? void 0 : node.kind) === "String" /* String */;
|
|
267
|
+
ASTMatch2.isNumber = (node) => (node == null ? void 0 : node.kind) === "Number" /* Number */;
|
|
268
|
+
ASTMatch2.isBoolean = (node) => (node == null ? void 0 : node.kind) === "Boolean" /* Boolean */;
|
|
269
|
+
ASTMatch2.isInteger = (node) => (node == null ? void 0 : node.kind) === "Integer" /* Integer */;
|
|
270
|
+
ASTMatch2.isObject = (node) => (node == null ? void 0 : node.kind) === "Object" /* Object */;
|
|
271
|
+
ASTMatch2.isArray = (node) => (node == null ? void 0 : node.kind) === "Array" /* Array */;
|
|
272
|
+
ASTMatch2.isMap = (node) => (node == null ? void 0 : node.kind) === "Map" /* Map */;
|
|
273
|
+
ASTMatch2.isCustomType = (node) => (node == null ? void 0 : node.kind) === "CustomType" /* CustomType */;
|
|
274
|
+
ASTMatch2.isVariableDeclaration = (node) => (node == null ? void 0 : node.kind) === "VariableDeclaration" /* VariableDeclaration */;
|
|
275
|
+
ASTMatch2.isProperty = (node) => (node == null ? void 0 : node.kind) === "Property" /* Property */;
|
|
276
|
+
ASTMatch2.isVariableDeclarationList = (node) => (node == null ? void 0 : node.kind) === "VariableDeclarationList" /* VariableDeclarationList */;
|
|
277
|
+
ASTMatch2.isEnumerateExpression = (node) => (node == null ? void 0 : node.kind) === "EnumerateExpression" /* EnumerateExpression */;
|
|
278
|
+
ASTMatch2.isKeyPathExpression = (node) => (node == null ? void 0 : node.kind) === "KeyPathExpression" /* KeyPathExpression */;
|
|
167
279
|
function is(node, targetType) {
|
|
168
|
-
return node
|
|
280
|
+
return (node == null ? void 0 : node.kind) === (targetType == null ? void 0 : targetType.kind);
|
|
169
281
|
}
|
|
170
282
|
ASTMatch2.is = is;
|
|
171
283
|
})(ASTMatch || (ASTMatch = {}));
|
|
@@ -178,8 +290,8 @@ function updateChildNodeHelper({
|
|
|
178
290
|
nextJSON
|
|
179
291
|
}) {
|
|
180
292
|
const currNode = getChildNode();
|
|
181
|
-
const isNewKind = currNode
|
|
182
|
-
const isNewKey = nextJSON
|
|
293
|
+
const isNewKind = (currNode == null ? void 0 : currNode.kind) !== (nextJSON == null ? void 0 : nextJSON.kind);
|
|
294
|
+
const isNewKey = (nextJSON == null ? void 0 : nextJSON.key) && (nextJSON == null ? void 0 : nextJSON.key) !== (currNode == null ? void 0 : currNode.key);
|
|
183
295
|
if (isNewKind || isNewKey) {
|
|
184
296
|
if (currNode) {
|
|
185
297
|
currNode.dispose();
|
|
@@ -194,7 +306,7 @@ function updateChildNodeHelper({
|
|
|
194
306
|
this.fireChange();
|
|
195
307
|
}
|
|
196
308
|
} else if (nextJSON) {
|
|
197
|
-
currNode
|
|
309
|
+
currNode == null ? void 0 : currNode.fromJSON(nextJSON);
|
|
198
310
|
}
|
|
199
311
|
return currNode;
|
|
200
312
|
}
|
|
@@ -228,12 +340,12 @@ import {
|
|
|
228
340
|
debounceTime,
|
|
229
341
|
distinctUntilChanged,
|
|
230
342
|
map,
|
|
231
|
-
skip,
|
|
343
|
+
skip as skip2,
|
|
232
344
|
tap
|
|
233
345
|
} from "rxjs";
|
|
234
346
|
import { nanoid } from "nanoid";
|
|
235
347
|
import { shallowEqual } from "fast-equals";
|
|
236
|
-
import { Disposable as Disposable2, DisposableCollection as
|
|
348
|
+
import { Disposable as Disposable2, DisposableCollection as DisposableCollection3 } from "@flowgram.ai/utils";
|
|
237
349
|
var ASTNode = class _ASTNode {
|
|
238
350
|
/**
|
|
239
351
|
* 构造函数
|
|
@@ -272,9 +384,10 @@ var ASTNode = class _ASTNode {
|
|
|
272
384
|
/**
|
|
273
385
|
* 删除节点处理事件列表
|
|
274
386
|
*/
|
|
275
|
-
this.toDispose = new
|
|
387
|
+
this.toDispose = new DisposableCollection3(
|
|
276
388
|
Disposable2.create(() => {
|
|
277
|
-
|
|
389
|
+
var _a;
|
|
390
|
+
(_a = this.parent) == null ? void 0 : _a.fireChange();
|
|
278
391
|
this.children.forEach((child) => child.dispose());
|
|
279
392
|
})
|
|
280
393
|
);
|
|
@@ -370,6 +483,7 @@ var ASTNode = class _ASTNode {
|
|
|
370
483
|
* 触发当前节点更新
|
|
371
484
|
*/
|
|
372
485
|
fireChange() {
|
|
486
|
+
var _a;
|
|
373
487
|
if (this.changeLocked || this.disposed) {
|
|
374
488
|
return;
|
|
375
489
|
}
|
|
@@ -380,7 +494,7 @@ var ASTNode = class _ASTNode {
|
|
|
380
494
|
this._version++;
|
|
381
495
|
this.value$.next(this);
|
|
382
496
|
this.dispatchGlobalEvent({ type: "UpdateAST" });
|
|
383
|
-
this.parent
|
|
497
|
+
(_a = this.parent) == null ? void 0 : _a.fireChange();
|
|
384
498
|
}
|
|
385
499
|
/**
|
|
386
500
|
* 节点的版本值
|
|
@@ -415,7 +529,7 @@ var ASTNode = class _ASTNode {
|
|
|
415
529
|
}
|
|
416
530
|
),
|
|
417
531
|
// 默认跳过 BehaviorSubject 第一次触发
|
|
418
|
-
triggerOnInit ? tap(() => null) :
|
|
532
|
+
triggerOnInit ? tap(() => null) : skip2(1),
|
|
419
533
|
// 每个 animationFrame 内所有更新合并成一个
|
|
420
534
|
debounceAnimation ? debounceTime(0, animationFrameScheduler) : tap(() => null)
|
|
421
535
|
).subscribe(observer)
|
|
@@ -451,17 +565,18 @@ var BaseType = class extends ASTNode {
|
|
|
451
565
|
this.flags = 8 /* BasicType */;
|
|
452
566
|
}
|
|
453
567
|
/**
|
|
454
|
-
*
|
|
568
|
+
* 类型是否一致
|
|
455
569
|
* @param targetTypeJSON
|
|
456
570
|
*/
|
|
457
571
|
isTypeEqual(targetTypeJSONOrKind) {
|
|
572
|
+
var _a;
|
|
458
573
|
const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
|
|
459
|
-
if (targetTypeJSON
|
|
460
|
-
return (targetTypeJSON
|
|
574
|
+
if ((targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
|
|
575
|
+
return (_a = (targetTypeJSON == null ? void 0 : targetTypeJSON.types) || []) == null ? void 0 : _a.some(
|
|
461
576
|
(_subType) => this.isTypeEqual(_subType)
|
|
462
577
|
);
|
|
463
578
|
}
|
|
464
|
-
return this.kind === targetTypeJSON
|
|
579
|
+
return this.kind === (targetTypeJSON == null ? void 0 : targetTypeJSON.kind);
|
|
465
580
|
}
|
|
466
581
|
/**
|
|
467
582
|
* 可下钻类型需实现
|
|
@@ -470,6 +585,10 @@ var BaseType = class extends ASTNode {
|
|
|
470
585
|
getByKeyPath(keyPath = []) {
|
|
471
586
|
throw new Error(`Get By Key Path is not implemented for Type: ${this.kind}`);
|
|
472
587
|
}
|
|
588
|
+
/**
|
|
589
|
+
* Get AST JSON for current base type
|
|
590
|
+
* @returns
|
|
591
|
+
*/
|
|
473
592
|
toJSON() {
|
|
474
593
|
return {
|
|
475
594
|
kind: this.kind
|
|
@@ -488,7 +607,8 @@ var ArrayType = class extends BaseType {
|
|
|
488
607
|
}
|
|
489
608
|
// items 类型是否可下钻
|
|
490
609
|
get canDrilldownItems() {
|
|
491
|
-
|
|
610
|
+
var _a;
|
|
611
|
+
return !!(((_a = this.items) == null ? void 0 : _a.flags) & 16 /* DrilldownType */);
|
|
492
612
|
}
|
|
493
613
|
getByKeyPath(keyPath) {
|
|
494
614
|
const [curr, ...rest] = keyPath || [];
|
|
@@ -500,11 +620,11 @@ var ArrayType = class extends BaseType {
|
|
|
500
620
|
isTypeEqual(targetTypeJSONOrKind) {
|
|
501
621
|
const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
|
|
502
622
|
const isSuperEqual = super.isTypeEqual(targetTypeJSONOrKind);
|
|
503
|
-
if (targetTypeJSON
|
|
623
|
+
if ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
|
|
504
624
|
return isSuperEqual;
|
|
505
625
|
}
|
|
506
626
|
return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
|
|
507
|
-
(targetTypeJSON
|
|
627
|
+
((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || this.customStrongEqual(targetTypeJSON));
|
|
508
628
|
}
|
|
509
629
|
/**
|
|
510
630
|
* Array 强比较
|
|
@@ -512,15 +632,17 @@ var ArrayType = class extends BaseType {
|
|
|
512
632
|
* @returns
|
|
513
633
|
*/
|
|
514
634
|
customStrongEqual(targetTypeJSON) {
|
|
635
|
+
var _a;
|
|
515
636
|
if (!this.items) {
|
|
516
|
-
return !targetTypeJSON
|
|
637
|
+
return !(targetTypeJSON == null ? void 0 : targetTypeJSON.items);
|
|
517
638
|
}
|
|
518
|
-
return this.items
|
|
639
|
+
return (_a = this.items) == null ? void 0 : _a.isTypeEqual(targetTypeJSON.items);
|
|
519
640
|
}
|
|
520
641
|
toJSON() {
|
|
642
|
+
var _a;
|
|
521
643
|
return {
|
|
522
644
|
kind: "Array" /* Array */,
|
|
523
|
-
items: this.items
|
|
645
|
+
items: (_a = this.items) == null ? void 0 : _a.toJSON()
|
|
524
646
|
};
|
|
525
647
|
}
|
|
526
648
|
};
|
|
@@ -582,11 +704,11 @@ var MapType = class extends BaseType {
|
|
|
582
704
|
isTypeEqual(targetTypeJSONOrKind) {
|
|
583
705
|
const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
|
|
584
706
|
const isSuperEqual = super.isTypeEqual(targetTypeJSONOrKind);
|
|
585
|
-
if (targetTypeJSON
|
|
707
|
+
if ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
|
|
586
708
|
return isSuperEqual;
|
|
587
709
|
}
|
|
588
710
|
return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
|
|
589
|
-
(targetTypeJSON
|
|
711
|
+
((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || this.customStrongEqual(targetTypeJSON));
|
|
590
712
|
}
|
|
591
713
|
/**
|
|
592
714
|
* Map 强比较
|
|
@@ -594,15 +716,17 @@ var MapType = class extends BaseType {
|
|
|
594
716
|
* @returns
|
|
595
717
|
*/
|
|
596
718
|
customStrongEqual(targetTypeJSON) {
|
|
719
|
+
var _a, _b;
|
|
597
720
|
const { keyType = "String" /* String */, valueType } = targetTypeJSON;
|
|
598
|
-
const isValueTypeEqual = !valueType && !this.valueType || this.valueType
|
|
599
|
-
return isValueTypeEqual && this.keyType
|
|
721
|
+
const isValueTypeEqual = !valueType && !this.valueType || ((_a = this.valueType) == null ? void 0 : _a.isTypeEqual(valueType));
|
|
722
|
+
return isValueTypeEqual && ((_b = this.keyType) == null ? void 0 : _b.isTypeEqual(keyType));
|
|
600
723
|
}
|
|
601
724
|
toJSON() {
|
|
725
|
+
var _a, _b;
|
|
602
726
|
return {
|
|
603
727
|
kind: "Map" /* Map */,
|
|
604
|
-
keyType: this.keyType
|
|
605
|
-
valueType: this.valueType
|
|
728
|
+
keyType: (_a = this.keyType) == null ? void 0 : _a.toJSON(),
|
|
729
|
+
valueType: (_b = this.valueType) == null ? void 0 : _b.toJSON()
|
|
606
730
|
};
|
|
607
731
|
}
|
|
608
732
|
};
|
|
@@ -638,7 +762,7 @@ var ObjectType = class extends BaseType {
|
|
|
638
762
|
});
|
|
639
763
|
removedKeys.forEach((key) => {
|
|
640
764
|
const property = this.propertyTable.get(key);
|
|
641
|
-
property
|
|
765
|
+
property == null ? void 0 : property.dispose();
|
|
642
766
|
this.propertyTable.delete(key);
|
|
643
767
|
this.fireChange();
|
|
644
768
|
});
|
|
@@ -662,12 +786,13 @@ var ObjectType = class extends BaseType {
|
|
|
662
786
|
* @returns
|
|
663
787
|
*/
|
|
664
788
|
getByKeyPath(keyPath) {
|
|
789
|
+
var _a;
|
|
665
790
|
const [curr, ...restKeyPath] = keyPath;
|
|
666
791
|
const property = this.propertyTable.get(curr);
|
|
667
792
|
if (!restKeyPath.length) {
|
|
668
793
|
return property;
|
|
669
794
|
}
|
|
670
|
-
if (property
|
|
795
|
+
if ((property == null ? void 0 : property.type) && ((_a = property == null ? void 0 : property.type) == null ? void 0 : _a.flags) & 16 /* DrilldownType */) {
|
|
671
796
|
return property.type.getByKeyPath(restKeyPath);
|
|
672
797
|
}
|
|
673
798
|
return void 0;
|
|
@@ -675,11 +800,11 @@ var ObjectType = class extends BaseType {
|
|
|
675
800
|
isTypeEqual(targetTypeJSONOrKind) {
|
|
676
801
|
const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
|
|
677
802
|
const isSuperEqual = super.isTypeEqual(targetTypeJSONOrKind);
|
|
678
|
-
if (targetTypeJSON
|
|
803
|
+
if ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
|
|
679
804
|
return isSuperEqual;
|
|
680
805
|
}
|
|
681
806
|
return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
|
|
682
|
-
(targetTypeJSON
|
|
807
|
+
((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || this.customStrongEqual(targetTypeJSON));
|
|
683
808
|
}
|
|
684
809
|
/**
|
|
685
810
|
* Object 类型强比较
|
|
@@ -692,8 +817,9 @@ var ObjectType = class extends BaseType {
|
|
|
692
817
|
const targetPropertyKeys = targetProperties.map((_target) => _target.key);
|
|
693
818
|
const isKeyStrongEqual = !xor(sourcePropertyKeys, targetPropertyKeys).length;
|
|
694
819
|
return isKeyStrongEqual && targetProperties.every((targetProperty) => {
|
|
820
|
+
var _a;
|
|
695
821
|
const sourceProperty = this.propertyTable.get(targetProperty.key);
|
|
696
|
-
return sourceProperty && sourceProperty.key === targetProperty.key && sourceProperty.type
|
|
822
|
+
return sourceProperty && sourceProperty.key === targetProperty.key && ((_a = sourceProperty.type) == null ? void 0 : _a.isTypeEqual(targetProperty == null ? void 0 : targetProperty.type));
|
|
697
823
|
});
|
|
698
824
|
}
|
|
699
825
|
};
|
|
@@ -711,13 +837,14 @@ var CustomType = class extends BaseType {
|
|
|
711
837
|
}
|
|
712
838
|
}
|
|
713
839
|
isTypeEqual(targetTypeJSONOrKind) {
|
|
840
|
+
var _a;
|
|
714
841
|
const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
|
|
715
|
-
if (targetTypeJSON
|
|
716
|
-
return (targetTypeJSON
|
|
842
|
+
if ((targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
|
|
843
|
+
return (_a = (targetTypeJSON == null ? void 0 : targetTypeJSON.types) || []) == null ? void 0 : _a.some(
|
|
717
844
|
(_subType) => this.isTypeEqual(_subType)
|
|
718
845
|
);
|
|
719
846
|
}
|
|
720
|
-
return targetTypeJSON
|
|
847
|
+
return (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === this.kind && (targetTypeJSON == null ? void 0 : targetTypeJSON.typeName) === this.typeName;
|
|
721
848
|
}
|
|
722
849
|
};
|
|
723
850
|
CustomType.kind = "CustomType" /* CustomType */;
|
|
@@ -726,11 +853,11 @@ CustomType.kind = "CustomType" /* CustomType */;
|
|
|
726
853
|
import {
|
|
727
854
|
distinctUntilChanged as distinctUntilChanged2,
|
|
728
855
|
map as map2,
|
|
729
|
-
switchMap,
|
|
856
|
+
switchMap as switchMap2,
|
|
730
857
|
combineLatest,
|
|
731
858
|
of,
|
|
732
|
-
Subject,
|
|
733
|
-
share
|
|
859
|
+
Subject as Subject2,
|
|
860
|
+
share as share2
|
|
734
861
|
} from "rxjs";
|
|
735
862
|
import { shallowEqual as shallowEqual2 } from "fast-equals";
|
|
736
863
|
|
|
@@ -756,7 +883,7 @@ var BaseExpression = class extends ASTNode {
|
|
|
756
883
|
* 引用变量
|
|
757
884
|
*/
|
|
758
885
|
this._refs = [];
|
|
759
|
-
this.refreshRefs$ = new
|
|
886
|
+
this.refreshRefs$ = new Subject2();
|
|
760
887
|
/**
|
|
761
888
|
* 监听引用变量变化
|
|
762
889
|
* 监听 [a.b.c] -> [a.b]
|
|
@@ -764,14 +891,14 @@ var BaseExpression = class extends ASTNode {
|
|
|
764
891
|
this.refs$ = this.refreshRefs$.pipe(
|
|
765
892
|
map2(() => this.getRefFields()),
|
|
766
893
|
distinctUntilChanged2(shallowEqual2),
|
|
767
|
-
|
|
768
|
-
(refs) => !refs
|
|
894
|
+
switchMap2(
|
|
895
|
+
(refs) => !(refs == null ? void 0 : refs.length) ? of([]) : combineLatest(
|
|
769
896
|
refs.map(
|
|
770
897
|
(ref) => ref ? ref.value$ : of(void 0)
|
|
771
898
|
)
|
|
772
899
|
)
|
|
773
900
|
),
|
|
774
|
-
|
|
901
|
+
share2()
|
|
775
902
|
);
|
|
776
903
|
this.toDispose.push(
|
|
777
904
|
subsToDisposable(
|
|
@@ -805,29 +932,6 @@ var BaseExpression = class extends ASTNode {
|
|
|
805
932
|
}
|
|
806
933
|
};
|
|
807
934
|
|
|
808
|
-
// src/ast/expression/expression-list.ts
|
|
809
|
-
var ExpressionList = class extends ASTNode {
|
|
810
|
-
fromJSON({ expressions }) {
|
|
811
|
-
this.expressions = expressions.map((_expression, idx) => {
|
|
812
|
-
const prevExpression = this.expressions[idx];
|
|
813
|
-
if (prevExpression.kind !== _expression.kind) {
|
|
814
|
-
prevExpression.dispose();
|
|
815
|
-
this.fireChange();
|
|
816
|
-
return this.createChildNode(_expression);
|
|
817
|
-
}
|
|
818
|
-
prevExpression.fromJSON(_expression);
|
|
819
|
-
return prevExpression;
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
toJSON() {
|
|
823
|
-
return {
|
|
824
|
-
kind: "ExpressionList" /* ExpressionList */,
|
|
825
|
-
properties: this.expressions.map((_expression) => _expression.toJSON())
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
ExpressionList.kind = "ExpressionList" /* ExpressionList */;
|
|
830
|
-
|
|
831
935
|
// src/ast/expression/keypath-expression.ts
|
|
832
936
|
import { shallowEqual as shallowEqual3 } from "fast-equals";
|
|
833
937
|
var KeyPathExpression = class extends BaseExpression {
|
|
@@ -892,8 +996,9 @@ var EnumerateExpression = class extends BaseExpression {
|
|
|
892
996
|
return this._enumerateFor;
|
|
893
997
|
}
|
|
894
998
|
get returnType() {
|
|
895
|
-
|
|
896
|
-
|
|
999
|
+
var _a;
|
|
1000
|
+
const childReturnType = (_a = this.enumerateFor) == null ? void 0 : _a.returnType;
|
|
1001
|
+
if ((childReturnType == null ? void 0 : childReturnType.kind) === "Array" /* Array */) {
|
|
897
1002
|
return childReturnType.items;
|
|
898
1003
|
}
|
|
899
1004
|
return void 0;
|
|
@@ -905,9 +1010,10 @@ var EnumerateExpression = class extends BaseExpression {
|
|
|
905
1010
|
this.updateChildNodeByKey("_enumerateFor", expression);
|
|
906
1011
|
}
|
|
907
1012
|
toJSON() {
|
|
1013
|
+
var _a;
|
|
908
1014
|
return {
|
|
909
1015
|
kind: "EnumerateExpression" /* EnumerateExpression */,
|
|
910
|
-
enumerateFor: this.enumerateFor
|
|
1016
|
+
enumerateFor: (_a = this.enumerateFor) == null ? void 0 : _a.toJSON()
|
|
911
1017
|
};
|
|
912
1018
|
}
|
|
913
1019
|
};
|
|
@@ -922,7 +1028,7 @@ function getAllRefs(ast) {
|
|
|
922
1028
|
return getAllChildren(ast).filter((_child) => _child.flags & 4 /* Expression */).map((_child) => _child.refs).flat().filter(Boolean);
|
|
923
1029
|
}
|
|
924
1030
|
function checkRefCycle(curr, refNodes) {
|
|
925
|
-
if (intersection(curr.scope.coverScopes, refNodes.map((_ref) => _ref
|
|
1031
|
+
if (intersection(curr.scope.coverScopes, refNodes.map((_ref) => _ref == null ? void 0 : _ref.scope).filter(Boolean)).length === 0) {
|
|
926
1032
|
return false;
|
|
927
1033
|
}
|
|
928
1034
|
const visited = /* @__PURE__ */ new Set();
|
|
@@ -955,9 +1061,10 @@ var KeyPathExpressionV2 = class extends BaseExpression {
|
|
|
955
1061
|
}),
|
|
956
1062
|
subsToDisposable(
|
|
957
1063
|
this.refs$.subscribe((_type) => {
|
|
1064
|
+
var _a, _b;
|
|
958
1065
|
const [ref] = this._refs;
|
|
959
|
-
if (this.prevRefTypeHash !== ref
|
|
960
|
-
this.prevRefTypeHash = ref
|
|
1066
|
+
if (this.prevRefTypeHash !== ((_a = ref == null ? void 0 : ref.type) == null ? void 0 : _a.hash)) {
|
|
1067
|
+
this.prevRefTypeHash = (_b = ref == null ? void 0 : ref.type) == null ? void 0 : _b.hash;
|
|
961
1068
|
this.updateChildNodeByKey("_returnType", this.getReturnTypeJSONByRef(ref));
|
|
962
1069
|
}
|
|
963
1070
|
})
|
|
@@ -998,7 +1105,8 @@ var KeyPathExpressionV2 = class extends BaseExpression {
|
|
|
998
1105
|
}
|
|
999
1106
|
}
|
|
1000
1107
|
getReturnTypeJSONByRef(_ref) {
|
|
1001
|
-
|
|
1108
|
+
var _a;
|
|
1109
|
+
return (_a = _ref == null ? void 0 : _ref.type) == null ? void 0 : _a.toJSON();
|
|
1002
1110
|
}
|
|
1003
1111
|
toJSON() {
|
|
1004
1112
|
return {
|
|
@@ -1009,8 +1117,50 @@ var KeyPathExpressionV2 = class extends BaseExpression {
|
|
|
1009
1117
|
};
|
|
1010
1118
|
KeyPathExpressionV2.kind = "KeyPathExpression" /* KeyPathExpression */;
|
|
1011
1119
|
|
|
1012
|
-
// src/ast/
|
|
1013
|
-
|
|
1120
|
+
// src/ast/expression/wrap-array-expression.ts
|
|
1121
|
+
var WrapArrayExpression = class extends BaseExpression {
|
|
1122
|
+
get wrapFor() {
|
|
1123
|
+
return this._wrapFor;
|
|
1124
|
+
}
|
|
1125
|
+
get returnType() {
|
|
1126
|
+
return this._returnType;
|
|
1127
|
+
}
|
|
1128
|
+
refreshReturnType() {
|
|
1129
|
+
var _a, _b;
|
|
1130
|
+
const childReturnTypeJSON = (_b = (_a = this.wrapFor) == null ? void 0 : _a.returnType) == null ? void 0 : _b.toJSON();
|
|
1131
|
+
this.updateChildNodeByKey("_returnType", {
|
|
1132
|
+
kind: "Array" /* Array */,
|
|
1133
|
+
items: childReturnTypeJSON
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
getRefFields() {
|
|
1137
|
+
return [];
|
|
1138
|
+
}
|
|
1139
|
+
fromJSON({ wrapFor: expression }) {
|
|
1140
|
+
this.updateChildNodeByKey("_wrapFor", expression);
|
|
1141
|
+
}
|
|
1142
|
+
toJSON() {
|
|
1143
|
+
var _a;
|
|
1144
|
+
return {
|
|
1145
|
+
kind: "WrapArrayExpression" /* WrapArrayExpression */,
|
|
1146
|
+
wrapFor: (_a = this.wrapFor) == null ? void 0 : _a.toJSON()
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
init() {
|
|
1150
|
+
this.toDispose.push(
|
|
1151
|
+
this.subscribe(this.refreshReturnType, {
|
|
1152
|
+
selector: (curr) => {
|
|
1153
|
+
var _a;
|
|
1154
|
+
return (_a = curr.wrapFor) == null ? void 0 : _a.returnType;
|
|
1155
|
+
}
|
|
1156
|
+
})
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
WrapArrayExpression.kind = "WrapArrayExpression" /* WrapArrayExpression */;
|
|
1161
|
+
__decorateClass([
|
|
1162
|
+
postConstructAST()
|
|
1163
|
+
], WrapArrayExpression.prototype, "init", 1);
|
|
1014
1164
|
|
|
1015
1165
|
// src/ast/declaration/base-variable-field.ts
|
|
1016
1166
|
import { shallowEqual as shallowEqual5 } from "fast-equals";
|
|
@@ -1030,7 +1180,8 @@ var BaseVariableField = class extends ASTNode {
|
|
|
1030
1180
|
return this._meta;
|
|
1031
1181
|
}
|
|
1032
1182
|
get type() {
|
|
1033
|
-
|
|
1183
|
+
var _a;
|
|
1184
|
+
return ((_a = this._initializer) == null ? void 0 : _a.returnType) || this._type;
|
|
1034
1185
|
}
|
|
1035
1186
|
get initializer() {
|
|
1036
1187
|
return this._initializer;
|
|
@@ -1062,7 +1213,8 @@ var BaseVariableField = class extends ASTNode {
|
|
|
1062
1213
|
* @returns
|
|
1063
1214
|
*/
|
|
1064
1215
|
getByKeyPath(keyPath) {
|
|
1065
|
-
|
|
1216
|
+
var _a;
|
|
1217
|
+
if (((_a = this.type) == null ? void 0 : _a.flags) & 16 /* DrilldownType */) {
|
|
1066
1218
|
return this.type.getByKeyPath(keyPath);
|
|
1067
1219
|
}
|
|
1068
1220
|
return void 0;
|
|
@@ -1080,11 +1232,12 @@ var BaseVariableField = class extends ASTNode {
|
|
|
1080
1232
|
* @returns
|
|
1081
1233
|
*/
|
|
1082
1234
|
toJSON() {
|
|
1235
|
+
var _a, _b;
|
|
1083
1236
|
return {
|
|
1084
1237
|
kind: this.kind,
|
|
1085
1238
|
key: this.key,
|
|
1086
|
-
type: this.type
|
|
1087
|
-
initializer: this.initializer
|
|
1239
|
+
type: (_a = this.type) == null ? void 0 : _a.toJSON(),
|
|
1240
|
+
initializer: (_b = this.initializer) == null ? void 0 : _b.toJSON(),
|
|
1088
1241
|
meta: this._meta
|
|
1089
1242
|
};
|
|
1090
1243
|
}
|
|
@@ -1095,13 +1248,6 @@ var VariableDeclaration = class extends BaseVariableField {
|
|
|
1095
1248
|
constructor(params) {
|
|
1096
1249
|
super(params);
|
|
1097
1250
|
this._order = 0;
|
|
1098
|
-
this.scope.output.addVariableToTable(this);
|
|
1099
|
-
this.toDispose.push(
|
|
1100
|
-
Disposable3.create(() => {
|
|
1101
|
-
this.scope.output.setHasChanges();
|
|
1102
|
-
this.scope.output.removeVariableFromTable(this.key);
|
|
1103
|
-
})
|
|
1104
|
-
);
|
|
1105
1251
|
}
|
|
1106
1252
|
get order() {
|
|
1107
1253
|
return this._order;
|
|
@@ -1116,7 +1262,9 @@ var VariableDeclaration = class extends BaseVariableField {
|
|
|
1116
1262
|
updateOrder(order = 0) {
|
|
1117
1263
|
if (order !== this._order) {
|
|
1118
1264
|
this._order = order;
|
|
1119
|
-
this.
|
|
1265
|
+
this.dispatchGlobalEvent({
|
|
1266
|
+
type: "ReSortVariableDeclarations"
|
|
1267
|
+
});
|
|
1120
1268
|
this.fireChange();
|
|
1121
1269
|
}
|
|
1122
1270
|
}
|
|
@@ -1138,8 +1286,9 @@ var VariableDeclarationList = class extends ASTNode {
|
|
|
1138
1286
|
const prev = [...this.declarations || []];
|
|
1139
1287
|
this.declarations = (declarations || []).map(
|
|
1140
1288
|
(declaration, idx) => {
|
|
1289
|
+
var _a, _b;
|
|
1141
1290
|
const order = (startOrder || 0) + idx;
|
|
1142
|
-
const declarationKey = declaration.key || this.declarations
|
|
1291
|
+
const declarationKey = declaration.key || ((_b = (_a = this.declarations) == null ? void 0 : _a[idx]) == null ? void 0 : _b.key);
|
|
1143
1292
|
const existDeclaration = this.declarationTable.get(declarationKey);
|
|
1144
1293
|
if (declarationKey) {
|
|
1145
1294
|
removedKeys.delete(declarationKey);
|
|
@@ -1161,7 +1310,7 @@ var VariableDeclarationList = class extends ASTNode {
|
|
|
1161
1310
|
);
|
|
1162
1311
|
removedKeys.forEach((key) => {
|
|
1163
1312
|
const declaration = this.declarationTable.get(key);
|
|
1164
|
-
declaration
|
|
1313
|
+
declaration == null ? void 0 : declaration.dispose();
|
|
1165
1314
|
this.declarationTable.delete(key);
|
|
1166
1315
|
});
|
|
1167
1316
|
this.dispatchGlobalEvent({
|
|
@@ -1287,7 +1436,8 @@ var MapNode = class extends ASTNode {
|
|
|
1287
1436
|
* @param key
|
|
1288
1437
|
*/
|
|
1289
1438
|
remove(key) {
|
|
1290
|
-
|
|
1439
|
+
var _a;
|
|
1440
|
+
(_a = this.get(key)) == null ? void 0 : _a.dispose();
|
|
1291
1441
|
this.map.delete(key);
|
|
1292
1442
|
this.fireChange();
|
|
1293
1443
|
}
|
|
@@ -1321,9 +1471,9 @@ var ASTRegisters = class {
|
|
|
1321
1471
|
this.registerAST(Property);
|
|
1322
1472
|
this.registerAST(VariableDeclaration);
|
|
1323
1473
|
this.registerAST(VariableDeclarationList);
|
|
1324
|
-
this.registerAST(
|
|
1474
|
+
this.registerAST(KeyPathExpressionV2);
|
|
1325
1475
|
this.registerAST(EnumerateExpression);
|
|
1326
|
-
this.registerAST(
|
|
1476
|
+
this.registerAST(WrapArrayExpression);
|
|
1327
1477
|
this.registerAST(MapNode);
|
|
1328
1478
|
this.registerAST(DataNode);
|
|
1329
1479
|
}
|
|
@@ -1333,6 +1483,7 @@ var ASTRegisters = class {
|
|
|
1333
1483
|
* @returns
|
|
1334
1484
|
*/
|
|
1335
1485
|
createAST(json, { parent, scope }) {
|
|
1486
|
+
var _a;
|
|
1336
1487
|
const Registry = this.astMap.get(json.kind);
|
|
1337
1488
|
if (!Registry) {
|
|
1338
1489
|
throw Error(`ASTKind: ${String(json.kind)} can not find its ASTNode Registry`);
|
|
@@ -1344,14 +1495,14 @@ var ASTRegisters = class {
|
|
|
1344
1495
|
scope,
|
|
1345
1496
|
parent
|
|
1346
1497
|
},
|
|
1347
|
-
injector
|
|
1498
|
+
(injector == null ? void 0 : injector()) || {}
|
|
1348
1499
|
);
|
|
1349
1500
|
node.changeLocked = true;
|
|
1350
1501
|
node.fromJSON(omit(json, ["key", "kind"]));
|
|
1351
1502
|
node.changeLocked = false;
|
|
1352
1503
|
if (Reflect.hasMetadata(POST_CONSTRUCT_AST_SYMBOL, node)) {
|
|
1353
1504
|
const postConstructKey = Reflect.getMetadata(POST_CONSTRUCT_AST_SYMBOL, node);
|
|
1354
|
-
node[postConstructKey]
|
|
1505
|
+
(_a = node[postConstructKey]) == null ? void 0 : _a.call(node);
|
|
1355
1506
|
}
|
|
1356
1507
|
return node;
|
|
1357
1508
|
}
|
|
@@ -1426,116 +1577,13 @@ var ASTFactory;
|
|
|
1426
1577
|
kind: "KeyPathExpression" /* KeyPathExpression */,
|
|
1427
1578
|
...json
|
|
1428
1579
|
});
|
|
1580
|
+
ASTFactory2.createWrapArrayExpression = (json) => ({
|
|
1581
|
+
kind: "WrapArrayExpression" /* WrapArrayExpression */,
|
|
1582
|
+
...json
|
|
1583
|
+
});
|
|
1429
1584
|
ASTFactory2.create = (targetType, json) => ({ kind: targetType.kind, ...json });
|
|
1430
1585
|
})(ASTFactory || (ASTFactory = {}));
|
|
1431
1586
|
|
|
1432
|
-
// src/scope/variable-table.ts
|
|
1433
|
-
import { Subject as Subject2, merge, share as share2, skip as skip2, switchMap as switchMap2 } from "rxjs";
|
|
1434
|
-
import { Emitter } from "@flowgram.ai/utils";
|
|
1435
|
-
import { DisposableCollection as DisposableCollection3 } from "@flowgram.ai/utils";
|
|
1436
|
-
var VariableTable = class {
|
|
1437
|
-
constructor(parentTable) {
|
|
1438
|
-
this.parentTable = parentTable;
|
|
1439
|
-
this.table = /* @__PURE__ */ new Map();
|
|
1440
|
-
this.onDataChangeEmitter = new Emitter();
|
|
1441
|
-
this.variables$ = new Subject2();
|
|
1442
|
-
// 监听变量列表中的单个变量变化
|
|
1443
|
-
this.anyVariableChange$ = this.variables$.pipe(
|
|
1444
|
-
switchMap2(
|
|
1445
|
-
(_variables) => merge(
|
|
1446
|
-
..._variables.map(
|
|
1447
|
-
(_v) => _v.value$.pipe(
|
|
1448
|
-
// 跳过 BehaviorSubject 第一个
|
|
1449
|
-
skip2(1)
|
|
1450
|
-
)
|
|
1451
|
-
)
|
|
1452
|
-
)
|
|
1453
|
-
),
|
|
1454
|
-
share2()
|
|
1455
|
-
);
|
|
1456
|
-
this.onDataChange = this.onDataChangeEmitter.event;
|
|
1457
|
-
this._version = 0;
|
|
1458
|
-
}
|
|
1459
|
-
/**
|
|
1460
|
-
* 监听任意变量变化
|
|
1461
|
-
* @param observer 监听器,变量变化时会吐出值
|
|
1462
|
-
* @returns
|
|
1463
|
-
*/
|
|
1464
|
-
onAnyVariableChange(observer) {
|
|
1465
|
-
return subsToDisposable(this.anyVariableChange$.subscribe(observer));
|
|
1466
|
-
}
|
|
1467
|
-
/**
|
|
1468
|
-
* 列表或者任意变量变化
|
|
1469
|
-
* @param observer
|
|
1470
|
-
*/
|
|
1471
|
-
onAnyChange(observer) {
|
|
1472
|
-
const disposables = new DisposableCollection3();
|
|
1473
|
-
disposables.pushAll([this.onDataChange(observer), this.onAnyVariableChange(observer)]);
|
|
1474
|
-
return disposables;
|
|
1475
|
-
}
|
|
1476
|
-
fireChange() {
|
|
1477
|
-
this._version++;
|
|
1478
|
-
this.onDataChangeEmitter.fire();
|
|
1479
|
-
this.parentTable?.fireChange();
|
|
1480
|
-
}
|
|
1481
|
-
get version() {
|
|
1482
|
-
return this._version;
|
|
1483
|
-
}
|
|
1484
|
-
get variables() {
|
|
1485
|
-
return Array.from(this.table.values());
|
|
1486
|
-
}
|
|
1487
|
-
get variableKeys() {
|
|
1488
|
-
return Array.from(this.table.keys());
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* 根据 keyPath 找到对应的变量,或 Property 节点
|
|
1492
|
-
* @param keyPath
|
|
1493
|
-
* @returns
|
|
1494
|
-
*/
|
|
1495
|
-
getByKeyPath(keyPath) {
|
|
1496
|
-
const [variableKey, ...propertyKeys] = keyPath || [];
|
|
1497
|
-
if (!variableKey) {
|
|
1498
|
-
return;
|
|
1499
|
-
}
|
|
1500
|
-
const variable = this.getVariableByKey(variableKey);
|
|
1501
|
-
return propertyKeys.length ? variable?.getByKeyPath(propertyKeys) : variable;
|
|
1502
|
-
}
|
|
1503
|
-
/**
|
|
1504
|
-
* 根据 key 值找到相应的变量
|
|
1505
|
-
* @param key
|
|
1506
|
-
* @returns
|
|
1507
|
-
*/
|
|
1508
|
-
getVariableByKey(key) {
|
|
1509
|
-
return this.table.get(key);
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* 往 variableTable 添加输出变量
|
|
1513
|
-
* @param variable
|
|
1514
|
-
*/
|
|
1515
|
-
addVariableToTable(variable) {
|
|
1516
|
-
this.table.set(variable.key, variable);
|
|
1517
|
-
if (this.parentTable) {
|
|
1518
|
-
this.parentTable.addVariableToTable(variable);
|
|
1519
|
-
}
|
|
1520
|
-
this.variables$.next(this.variables);
|
|
1521
|
-
}
|
|
1522
|
-
/**
|
|
1523
|
-
* 从 variableTable 中移除变量
|
|
1524
|
-
* @param key
|
|
1525
|
-
*/
|
|
1526
|
-
removeVariableFromTable(key) {
|
|
1527
|
-
this.table.delete(key);
|
|
1528
|
-
if (this.parentTable) {
|
|
1529
|
-
this.parentTable.removeVariableFromTable(key);
|
|
1530
|
-
}
|
|
1531
|
-
this.variables$.next(this.variables);
|
|
1532
|
-
}
|
|
1533
|
-
dispose() {
|
|
1534
|
-
this.variableKeys.forEach((_key) => this.parentTable?.removeVariableFromTable(_key));
|
|
1535
|
-
this.onDataChangeEmitter.dispose();
|
|
1536
|
-
}
|
|
1537
|
-
};
|
|
1538
|
-
|
|
1539
1587
|
// src/scope/datas/scope-output-data.ts
|
|
1540
1588
|
var ScopeOutputData = class {
|
|
1541
1589
|
constructor(scope) {
|
|
@@ -1544,7 +1592,7 @@ var ScopeOutputData = class {
|
|
|
1544
1592
|
this._hasChanges = false;
|
|
1545
1593
|
this.variableTable = new VariableTable(scope.variableEngine.globalVariableTable);
|
|
1546
1594
|
this.scope.toDispose.pushAll([
|
|
1547
|
-
// AST
|
|
1595
|
+
// When root AST node is updated, check if there are any changes during this AST change
|
|
1548
1596
|
this.scope.ast.subscribe(() => {
|
|
1549
1597
|
if (this._hasChanges) {
|
|
1550
1598
|
this.memo.clear();
|
|
@@ -1553,6 +1601,21 @@ var ScopeOutputData = class {
|
|
|
1553
1601
|
this._hasChanges = false;
|
|
1554
1602
|
}
|
|
1555
1603
|
}),
|
|
1604
|
+
this.scope.event.on("DisposeAST", (_action) => {
|
|
1605
|
+
var _a;
|
|
1606
|
+
if (((_a = _action.ast) == null ? void 0 : _a.kind) === "VariableDeclaration" /* VariableDeclaration */) {
|
|
1607
|
+
this.removeVariableFromTable(_action.ast.key);
|
|
1608
|
+
}
|
|
1609
|
+
}),
|
|
1610
|
+
this.scope.event.on("NewAST", (_action) => {
|
|
1611
|
+
var _a;
|
|
1612
|
+
if (((_a = _action.ast) == null ? void 0 : _a.kind) === "VariableDeclaration" /* VariableDeclaration */) {
|
|
1613
|
+
this.addVariableToTable(_action.ast);
|
|
1614
|
+
}
|
|
1615
|
+
}),
|
|
1616
|
+
this.scope.event.on("ReSortVariableDeclarations", () => {
|
|
1617
|
+
this._hasChanges = true;
|
|
1618
|
+
}),
|
|
1556
1619
|
this.variableTable
|
|
1557
1620
|
]);
|
|
1558
1621
|
}
|
|
@@ -1569,7 +1632,7 @@ var ScopeOutputData = class {
|
|
|
1569
1632
|
return this.variableTable.onAnyVariableChange.bind(this.variableTable);
|
|
1570
1633
|
}
|
|
1571
1634
|
/**
|
|
1572
|
-
*
|
|
1635
|
+
* Scope Output Variable Declarations
|
|
1573
1636
|
*/
|
|
1574
1637
|
get variables() {
|
|
1575
1638
|
return this.memo(
|
|
@@ -1578,7 +1641,7 @@ var ScopeOutputData = class {
|
|
|
1578
1641
|
);
|
|
1579
1642
|
}
|
|
1580
1643
|
/**
|
|
1581
|
-
*
|
|
1644
|
+
* Output Variable Keys
|
|
1582
1645
|
*/
|
|
1583
1646
|
get variableKeys() {
|
|
1584
1647
|
return this.memo("variableKeys", () => this.variableTable.variableKeys);
|
|
@@ -1590,10 +1653,6 @@ var ScopeOutputData = class {
|
|
|
1590
1653
|
this.variableTable.addVariableToTable(variable);
|
|
1591
1654
|
this._hasChanges = true;
|
|
1592
1655
|
}
|
|
1593
|
-
// 标记为发生了变化,用于变量排序变化的场景
|
|
1594
|
-
setHasChanges() {
|
|
1595
|
-
this._hasChanges = true;
|
|
1596
|
-
}
|
|
1597
1656
|
removeVariableFromTable(key) {
|
|
1598
1657
|
this.variableTable.removeVariableFromTable(key);
|
|
1599
1658
|
this._hasChanges = true;
|
|
@@ -1601,7 +1660,9 @@ var ScopeOutputData = class {
|
|
|
1601
1660
|
getVariableByKey(key) {
|
|
1602
1661
|
return this.variableTable.getVariableByKey(key);
|
|
1603
1662
|
}
|
|
1604
|
-
|
|
1663
|
+
/**
|
|
1664
|
+
*
|
|
1665
|
+
*/
|
|
1605
1666
|
notifyCoversChange() {
|
|
1606
1667
|
this.scope.coverScopes.forEach((scope) => scope.available.refresh());
|
|
1607
1668
|
}
|
|
@@ -1619,7 +1680,7 @@ import {
|
|
|
1619
1680
|
} from "rxjs";
|
|
1620
1681
|
import { flatten } from "lodash";
|
|
1621
1682
|
import { shallowEqual as shallowEqual7 } from "fast-equals";
|
|
1622
|
-
import { Disposable as
|
|
1683
|
+
import { Disposable as Disposable3 } from "@flowgram.ai/utils";
|
|
1623
1684
|
import { Emitter as Emitter2 } from "@flowgram.ai/utils";
|
|
1624
1685
|
var ScopeAvailableData = class {
|
|
1625
1686
|
constructor(scope) {
|
|
@@ -1665,7 +1726,7 @@ var ScopeAvailableData = class {
|
|
|
1665
1726
|
this.onAnyVariableChange(() => {
|
|
1666
1727
|
this.onDataChangeEmitter.fire(this._variables);
|
|
1667
1728
|
}),
|
|
1668
|
-
|
|
1729
|
+
Disposable3.create(() => {
|
|
1669
1730
|
this.refresh$.complete();
|
|
1670
1731
|
this.refresh$.unsubscribe();
|
|
1671
1732
|
})
|
|
@@ -1772,7 +1833,7 @@ var Scope = class {
|
|
|
1772
1833
|
this.ast = this.variableEngine.astRegisters.createAST(
|
|
1773
1834
|
{
|
|
1774
1835
|
kind: "MapNode" /* MapNode */,
|
|
1775
|
-
key: this.id
|
|
1836
|
+
key: String(this.id)
|
|
1776
1837
|
},
|
|
1777
1838
|
{
|
|
1778
1839
|
scope: this
|
|
@@ -1791,13 +1852,13 @@ var Scope = class {
|
|
|
1791
1852
|
get depScopes() {
|
|
1792
1853
|
return this.memo(
|
|
1793
1854
|
"deps",
|
|
1794
|
-
() => this.variableEngine.chain.getDeps(this).filter((_scope) => Boolean(_scope) && !_scope
|
|
1855
|
+
() => this.variableEngine.chain.getDeps(this).filter((_scope) => Boolean(_scope) && !(_scope == null ? void 0 : _scope.disposed))
|
|
1795
1856
|
);
|
|
1796
1857
|
}
|
|
1797
1858
|
get coverScopes() {
|
|
1798
1859
|
return this.memo(
|
|
1799
1860
|
"covers",
|
|
1800
|
-
() => this.variableEngine.chain.getCovers(this).filter((_scope) => Boolean(_scope) && !_scope
|
|
1861
|
+
() => this.variableEngine.chain.getCovers(this).filter((_scope) => Boolean(_scope) && !(_scope == null ? void 0 : _scope.disposed))
|
|
1801
1862
|
);
|
|
1802
1863
|
}
|
|
1803
1864
|
dispose() {
|
|
@@ -1825,7 +1886,7 @@ var VariableEngine = class {
|
|
|
1825
1886
|
this.onScopeChange = this.onScopeChangeEmitter.event;
|
|
1826
1887
|
this.toDispose.pushAll([
|
|
1827
1888
|
chain,
|
|
1828
|
-
|
|
1889
|
+
Disposable4.create(() => {
|
|
1829
1890
|
this.getAllScopes().forEach((scope) => scope.dispose());
|
|
1830
1891
|
this.globalVariableTable.dispose();
|
|
1831
1892
|
})
|
|
@@ -1843,13 +1904,21 @@ var VariableEngine = class {
|
|
|
1843
1904
|
}
|
|
1844
1905
|
// 移除作用域
|
|
1845
1906
|
removeScopeById(scopeId) {
|
|
1846
|
-
|
|
1907
|
+
var _a;
|
|
1908
|
+
(_a = this.getScopeById(scopeId)) == null ? void 0 : _a.dispose();
|
|
1847
1909
|
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1910
|
+
/**
|
|
1911
|
+
* Get Scope, if Scope exists and type is same, will use it directly
|
|
1912
|
+
* @param id scope id
|
|
1913
|
+
* @param meta scope meta, defined by user
|
|
1914
|
+
* @param ScopeConstructor scope constructor, default is Scope. you can extends Scope to create your own scope
|
|
1915
|
+
* @returns
|
|
1916
|
+
*/
|
|
1917
|
+
createScope(id, meta, options = {}) {
|
|
1918
|
+
const { ScopeConstructor = Scope } = options;
|
|
1850
1919
|
let scope = this.getScopeById(id);
|
|
1851
1920
|
if (!scope) {
|
|
1852
|
-
scope = new
|
|
1921
|
+
scope = new ScopeConstructor({ variableEngine: this, meta, id });
|
|
1853
1922
|
this.scopeMap.set(id, scope);
|
|
1854
1923
|
this.onScopeChangeEmitter.fire({ type: "add", scope });
|
|
1855
1924
|
scope.toDispose.pushAll([
|
|
@@ -1920,7 +1989,8 @@ var VariableFieldKeyRenameService = class {
|
|
|
1920
1989
|
this.onDisposeInList = this.disposeInListEmitter.event;
|
|
1921
1990
|
}
|
|
1922
1991
|
handleFieldListChange(ast, prev, next) {
|
|
1923
|
-
|
|
1992
|
+
var _a, _b;
|
|
1993
|
+
if (!ast || !(prev == null ? void 0 : prev.length) || !(next == null ? void 0 : next.length)) {
|
|
1924
1994
|
this.notifyFieldsDispose(prev, next);
|
|
1925
1995
|
return;
|
|
1926
1996
|
}
|
|
@@ -1938,7 +2008,7 @@ var VariableFieldKeyRenameService = class {
|
|
|
1938
2008
|
return;
|
|
1939
2009
|
}
|
|
1940
2010
|
existFieldChanged = true;
|
|
1941
|
-
if (prevField.type
|
|
2011
|
+
if (((_a = prevField.type) == null ? void 0 : _a.kind) === ((_b = nextField.type) == null ? void 0 : _b.kind)) {
|
|
1942
2012
|
renameNodeInfo = { before: prevField, after: nextField };
|
|
1943
2013
|
}
|
|
1944
2014
|
}
|
|
@@ -1958,13 +2028,15 @@ var VariableFieldKeyRenameService = class {
|
|
|
1958
2028
|
this.variableEngine.onGlobalEvent(
|
|
1959
2029
|
"VariableListChange",
|
|
1960
2030
|
(_action) => {
|
|
1961
|
-
|
|
2031
|
+
var _a, _b;
|
|
2032
|
+
this.handleFieldListChange(_action.ast, (_a = _action.payload) == null ? void 0 : _a.prev, (_b = _action.payload) == null ? void 0 : _b.next);
|
|
1962
2033
|
}
|
|
1963
2034
|
),
|
|
1964
2035
|
this.variableEngine.onGlobalEvent(
|
|
1965
2036
|
"ObjectPropertiesChange",
|
|
1966
2037
|
(_action) => {
|
|
1967
|
-
|
|
2038
|
+
var _a, _b;
|
|
2039
|
+
this.handleFieldListChange(_action.ast, (_a = _action.payload) == null ? void 0 : _a.prev, (_b = _action.payload) == null ? void 0 : _b.next);
|
|
1968
2040
|
}
|
|
1969
2041
|
)
|
|
1970
2042
|
]);
|
|
@@ -2000,7 +2072,10 @@ import { createContext, useContext } from "react";
|
|
|
2000
2072
|
var ScopeContext = createContext(null);
|
|
2001
2073
|
var ScopeProvider = ScopeContext.Provider;
|
|
2002
2074
|
var useScopeContext = () => useContext(ScopeContext);
|
|
2003
|
-
var useCurrentScope = () =>
|
|
2075
|
+
var useCurrentScope = () => {
|
|
2076
|
+
var _a;
|
|
2077
|
+
return (_a = useContext(ScopeContext)) == null ? void 0 : _a.scope;
|
|
2078
|
+
};
|
|
2004
2079
|
|
|
2005
2080
|
// src/react/hooks/useScopeAvailable.ts
|
|
2006
2081
|
import { useEffect } from "react";
|
|
@@ -2053,7 +2128,6 @@ export {
|
|
|
2053
2128
|
CustomType,
|
|
2054
2129
|
DataNode,
|
|
2055
2130
|
EnumerateExpression,
|
|
2056
|
-
ExpressionList,
|
|
2057
2131
|
IntegerType,
|
|
2058
2132
|
KeyPathExpression,
|
|
2059
2133
|
KeyPathExpressionV2,
|
|
@@ -2074,7 +2148,7 @@ export {
|
|
|
2074
2148
|
VariableEngine,
|
|
2075
2149
|
VariableEngineProvider,
|
|
2076
2150
|
VariableFieldKeyRenameService,
|
|
2077
|
-
|
|
2151
|
+
WrapArrayExpression,
|
|
2078
2152
|
injectToAST,
|
|
2079
2153
|
isMatchAST,
|
|
2080
2154
|
postConstructAST,
|