@flowgram.ai/variable-layout 0.1.0-alpha.2
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 +499 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +179 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.js +527 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { Scope, VariableEngine, ASTNodeJSON, ASTNode, ScopeChain } from '@flowgram.ai/variable-core';
|
|
2
|
+
import { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';
|
|
3
|
+
import { EntityData, EntityManager } from '@flowgram.ai/core';
|
|
4
|
+
|
|
5
|
+
declare enum FlowNodeScopeTypeEnum {
|
|
6
|
+
public = "public",
|
|
7
|
+
private = "private"
|
|
8
|
+
}
|
|
9
|
+
interface FlowNodeScopeMeta {
|
|
10
|
+
node?: FlowNodeEntity;
|
|
11
|
+
type?: FlowNodeScopeTypeEnum;
|
|
12
|
+
}
|
|
13
|
+
interface ScopeVirtualNode {
|
|
14
|
+
id: string;
|
|
15
|
+
flowNodeType: 'virtualNode';
|
|
16
|
+
}
|
|
17
|
+
type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;
|
|
18
|
+
type FlowNodeScope = Scope<FlowNodeScopeMeta>;
|
|
19
|
+
|
|
20
|
+
interface Options {
|
|
21
|
+
variableEngine: VariableEngine;
|
|
22
|
+
}
|
|
23
|
+
declare class FlowNodeVariableData extends EntityData {
|
|
24
|
+
readonly opts: Options;
|
|
25
|
+
static type: string;
|
|
26
|
+
entity: FlowNodeEntity;
|
|
27
|
+
readonly variableEngine: VariableEngine;
|
|
28
|
+
/**
|
|
29
|
+
* Private variables can be accessed by public ones, but not the other way around.
|
|
30
|
+
*/
|
|
31
|
+
protected _private?: FlowNodeScope;
|
|
32
|
+
protected _public: FlowNodeScope;
|
|
33
|
+
get private(): FlowNodeScope | undefined;
|
|
34
|
+
get public(): FlowNodeScope;
|
|
35
|
+
/**
|
|
36
|
+
* Sets a variable in the public AST (Abstract Syntax Tree) with the given key and JSON value.
|
|
37
|
+
*
|
|
38
|
+
* @param key - The key under which the variable will be stored.
|
|
39
|
+
* @param json - The JSON value to store.
|
|
40
|
+
* @returns The updated AST node.
|
|
41
|
+
*/
|
|
42
|
+
setVar(key: string, json: ASTNodeJSON): ASTNode;
|
|
43
|
+
/**
|
|
44
|
+
* Sets a variable in the public AST (Abstract Syntax Tree) with the default key 'outputs'.
|
|
45
|
+
*
|
|
46
|
+
* @param json - The JSON value to store.
|
|
47
|
+
* @returns The updated AST node.
|
|
48
|
+
*/
|
|
49
|
+
setVar(json: ASTNodeJSON): ASTNode;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a variable from the public AST (Abstract Syntax Tree) by key.
|
|
52
|
+
*
|
|
53
|
+
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
54
|
+
* @returns The value of the variable, or undefined if not found.
|
|
55
|
+
*/
|
|
56
|
+
getVar(key?: string): ASTNode<any, any> | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Clears a variable from the public AST (Abstract Syntax Tree) by key.
|
|
59
|
+
*
|
|
60
|
+
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
|
61
|
+
* @returns The updated AST node.
|
|
62
|
+
*/
|
|
63
|
+
clearVar(key?: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Sets a variable in the private AST (Abstract Syntax Tree) with the given key and JSON value.
|
|
66
|
+
*
|
|
67
|
+
* @param key - The key under which the variable will be stored.
|
|
68
|
+
* @param json - The JSON value to store.
|
|
69
|
+
* @returns The updated AST node.
|
|
70
|
+
*/
|
|
71
|
+
setPrivateVar(key: string, json: ASTNodeJSON): ASTNode;
|
|
72
|
+
/**
|
|
73
|
+
* Sets a variable in the private AST (Abstract Syntax Tree) with the default key 'outputs'.
|
|
74
|
+
*
|
|
75
|
+
* @param json - The JSON value to store.
|
|
76
|
+
* @returns The updated AST node.
|
|
77
|
+
*/
|
|
78
|
+
setPrivateVar(json: ASTNodeJSON): ASTNode;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves a variable from the private AST (Abstract Syntax Tree) by key.
|
|
81
|
+
*
|
|
82
|
+
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
83
|
+
* @returns The value of the variable, or undefined if not found.
|
|
84
|
+
*/
|
|
85
|
+
getPrivateVar(key?: string): ASTNode<any, any> | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Clears a variable from the private AST (Abstract Syntax Tree) by key.
|
|
88
|
+
*
|
|
89
|
+
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
|
90
|
+
* @returns The updated AST node.
|
|
91
|
+
*/
|
|
92
|
+
clearPrivateVar(key?: string): void | undefined;
|
|
93
|
+
get allScopes(): FlowNodeScope[];
|
|
94
|
+
getDefaultData(): {};
|
|
95
|
+
constructor(entity: FlowNodeEntity, opts: Options);
|
|
96
|
+
initPrivate(): FlowNodeScope;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface TransformerContext {
|
|
100
|
+
scope: FlowNodeScope;
|
|
101
|
+
document: FlowDocument;
|
|
102
|
+
variableEngine: VariableEngine;
|
|
103
|
+
}
|
|
104
|
+
interface VariableLayoutConfig {
|
|
105
|
+
/**
|
|
106
|
+
* 开始节点的节点 Id
|
|
107
|
+
*/
|
|
108
|
+
startNodeId?: string;
|
|
109
|
+
/**
|
|
110
|
+
* 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景
|
|
111
|
+
* @param node
|
|
112
|
+
* @returns
|
|
113
|
+
*/
|
|
114
|
+
isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;
|
|
115
|
+
/**
|
|
116
|
+
* 用于自由画布场景,部分场景通过连线或者其他交互形式来表达节点之间的父子关系,需要可配置化
|
|
117
|
+
*/
|
|
118
|
+
getFreeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];
|
|
119
|
+
getFreeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* 对依赖作用域进行微调
|
|
122
|
+
*/
|
|
123
|
+
transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
124
|
+
/**
|
|
125
|
+
* 对依赖作用域进行微调
|
|
126
|
+
*/
|
|
127
|
+
transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
128
|
+
}
|
|
129
|
+
declare const VariableLayoutConfig: unique symbol;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 自由布局作用域链实现
|
|
133
|
+
*/
|
|
134
|
+
declare class FreeLayoutScopeChain extends ScopeChain {
|
|
135
|
+
entityManager: EntityManager;
|
|
136
|
+
protected flowDocument: FlowDocument;
|
|
137
|
+
protected configs?: VariableLayoutConfig;
|
|
138
|
+
get tree(): FlowVirtualTree<FlowNodeEntity>;
|
|
139
|
+
onInit(): void;
|
|
140
|
+
protected getAllInputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
141
|
+
protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
142
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
143
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
144
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
145
|
+
scope: Scope;
|
|
146
|
+
}): Scope[];
|
|
147
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
148
|
+
scope: Scope;
|
|
149
|
+
}): Scope[];
|
|
150
|
+
getChildren(node: FlowNodeEntity): FlowNodeEntity[];
|
|
151
|
+
getParent(node: FlowNodeEntity): FlowNodeEntity | undefined;
|
|
152
|
+
sortAll(): Scope[];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 基于 FlowVirtualTree 的 ScopeOrder 实现
|
|
157
|
+
*/
|
|
158
|
+
declare class FixedLayoutScopeChain extends ScopeChain {
|
|
159
|
+
protected flowDocument: FlowDocument;
|
|
160
|
+
protected configs?: VariableLayoutConfig | undefined;
|
|
161
|
+
tree: FlowVirtualTree<ScopeChainNode> | undefined;
|
|
162
|
+
constructor(flowDocument: FlowDocument, configs?: VariableLayoutConfig | undefined);
|
|
163
|
+
bindTree(tree: FlowVirtualTree<ScopeChainNode>): void;
|
|
164
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
165
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
166
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
167
|
+
scope: Scope;
|
|
168
|
+
}): Scope[];
|
|
169
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
170
|
+
scope: Scope;
|
|
171
|
+
}): Scope[];
|
|
172
|
+
sortAll(): Scope[];
|
|
173
|
+
private getVariableData;
|
|
174
|
+
private isNodeChildrenPrivate;
|
|
175
|
+
private hasChildren;
|
|
176
|
+
private getAllSortedChildScope;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, VariableLayoutConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { Scope, VariableEngine, ASTNodeJSON, ASTNode, ScopeChain } from '@flowgram.ai/variable-core';
|
|
2
|
+
import { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';
|
|
3
|
+
import { EntityData, EntityManager } from '@flowgram.ai/core';
|
|
4
|
+
|
|
5
|
+
declare enum FlowNodeScopeTypeEnum {
|
|
6
|
+
public = "public",
|
|
7
|
+
private = "private"
|
|
8
|
+
}
|
|
9
|
+
interface FlowNodeScopeMeta {
|
|
10
|
+
node?: FlowNodeEntity;
|
|
11
|
+
type?: FlowNodeScopeTypeEnum;
|
|
12
|
+
}
|
|
13
|
+
interface ScopeVirtualNode {
|
|
14
|
+
id: string;
|
|
15
|
+
flowNodeType: 'virtualNode';
|
|
16
|
+
}
|
|
17
|
+
type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;
|
|
18
|
+
type FlowNodeScope = Scope<FlowNodeScopeMeta>;
|
|
19
|
+
|
|
20
|
+
interface Options {
|
|
21
|
+
variableEngine: VariableEngine;
|
|
22
|
+
}
|
|
23
|
+
declare class FlowNodeVariableData extends EntityData {
|
|
24
|
+
readonly opts: Options;
|
|
25
|
+
static type: string;
|
|
26
|
+
entity: FlowNodeEntity;
|
|
27
|
+
readonly variableEngine: VariableEngine;
|
|
28
|
+
/**
|
|
29
|
+
* Private variables can be accessed by public ones, but not the other way around.
|
|
30
|
+
*/
|
|
31
|
+
protected _private?: FlowNodeScope;
|
|
32
|
+
protected _public: FlowNodeScope;
|
|
33
|
+
get private(): FlowNodeScope | undefined;
|
|
34
|
+
get public(): FlowNodeScope;
|
|
35
|
+
/**
|
|
36
|
+
* Sets a variable in the public AST (Abstract Syntax Tree) with the given key and JSON value.
|
|
37
|
+
*
|
|
38
|
+
* @param key - The key under which the variable will be stored.
|
|
39
|
+
* @param json - The JSON value to store.
|
|
40
|
+
* @returns The updated AST node.
|
|
41
|
+
*/
|
|
42
|
+
setVar(key: string, json: ASTNodeJSON): ASTNode;
|
|
43
|
+
/**
|
|
44
|
+
* Sets a variable in the public AST (Abstract Syntax Tree) with the default key 'outputs'.
|
|
45
|
+
*
|
|
46
|
+
* @param json - The JSON value to store.
|
|
47
|
+
* @returns The updated AST node.
|
|
48
|
+
*/
|
|
49
|
+
setVar(json: ASTNodeJSON): ASTNode;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a variable from the public AST (Abstract Syntax Tree) by key.
|
|
52
|
+
*
|
|
53
|
+
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
54
|
+
* @returns The value of the variable, or undefined if not found.
|
|
55
|
+
*/
|
|
56
|
+
getVar(key?: string): ASTNode<any, any> | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Clears a variable from the public AST (Abstract Syntax Tree) by key.
|
|
59
|
+
*
|
|
60
|
+
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
|
61
|
+
* @returns The updated AST node.
|
|
62
|
+
*/
|
|
63
|
+
clearVar(key?: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Sets a variable in the private AST (Abstract Syntax Tree) with the given key and JSON value.
|
|
66
|
+
*
|
|
67
|
+
* @param key - The key under which the variable will be stored.
|
|
68
|
+
* @param json - The JSON value to store.
|
|
69
|
+
* @returns The updated AST node.
|
|
70
|
+
*/
|
|
71
|
+
setPrivateVar(key: string, json: ASTNodeJSON): ASTNode;
|
|
72
|
+
/**
|
|
73
|
+
* Sets a variable in the private AST (Abstract Syntax Tree) with the default key 'outputs'.
|
|
74
|
+
*
|
|
75
|
+
* @param json - The JSON value to store.
|
|
76
|
+
* @returns The updated AST node.
|
|
77
|
+
*/
|
|
78
|
+
setPrivateVar(json: ASTNodeJSON): ASTNode;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves a variable from the private AST (Abstract Syntax Tree) by key.
|
|
81
|
+
*
|
|
82
|
+
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
83
|
+
* @returns The value of the variable, or undefined if not found.
|
|
84
|
+
*/
|
|
85
|
+
getPrivateVar(key?: string): ASTNode<any, any> | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Clears a variable from the private AST (Abstract Syntax Tree) by key.
|
|
88
|
+
*
|
|
89
|
+
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
|
90
|
+
* @returns The updated AST node.
|
|
91
|
+
*/
|
|
92
|
+
clearPrivateVar(key?: string): void | undefined;
|
|
93
|
+
get allScopes(): FlowNodeScope[];
|
|
94
|
+
getDefaultData(): {};
|
|
95
|
+
constructor(entity: FlowNodeEntity, opts: Options);
|
|
96
|
+
initPrivate(): FlowNodeScope;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface TransformerContext {
|
|
100
|
+
scope: FlowNodeScope;
|
|
101
|
+
document: FlowDocument;
|
|
102
|
+
variableEngine: VariableEngine;
|
|
103
|
+
}
|
|
104
|
+
interface VariableLayoutConfig {
|
|
105
|
+
/**
|
|
106
|
+
* 开始节点的节点 Id
|
|
107
|
+
*/
|
|
108
|
+
startNodeId?: string;
|
|
109
|
+
/**
|
|
110
|
+
* 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景
|
|
111
|
+
* @param node
|
|
112
|
+
* @returns
|
|
113
|
+
*/
|
|
114
|
+
isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;
|
|
115
|
+
/**
|
|
116
|
+
* 用于自由画布场景,部分场景通过连线或者其他交互形式来表达节点之间的父子关系,需要可配置化
|
|
117
|
+
*/
|
|
118
|
+
getFreeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];
|
|
119
|
+
getFreeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* 对依赖作用域进行微调
|
|
122
|
+
*/
|
|
123
|
+
transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
124
|
+
/**
|
|
125
|
+
* 对依赖作用域进行微调
|
|
126
|
+
*/
|
|
127
|
+
transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
128
|
+
}
|
|
129
|
+
declare const VariableLayoutConfig: unique symbol;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 自由布局作用域链实现
|
|
133
|
+
*/
|
|
134
|
+
declare class FreeLayoutScopeChain extends ScopeChain {
|
|
135
|
+
entityManager: EntityManager;
|
|
136
|
+
protected flowDocument: FlowDocument;
|
|
137
|
+
protected configs?: VariableLayoutConfig;
|
|
138
|
+
get tree(): FlowVirtualTree<FlowNodeEntity>;
|
|
139
|
+
onInit(): void;
|
|
140
|
+
protected getAllInputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
141
|
+
protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
142
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
143
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
144
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
145
|
+
scope: Scope;
|
|
146
|
+
}): Scope[];
|
|
147
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
148
|
+
scope: Scope;
|
|
149
|
+
}): Scope[];
|
|
150
|
+
getChildren(node: FlowNodeEntity): FlowNodeEntity[];
|
|
151
|
+
getParent(node: FlowNodeEntity): FlowNodeEntity | undefined;
|
|
152
|
+
sortAll(): Scope[];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 基于 FlowVirtualTree 的 ScopeOrder 实现
|
|
157
|
+
*/
|
|
158
|
+
declare class FixedLayoutScopeChain extends ScopeChain {
|
|
159
|
+
protected flowDocument: FlowDocument;
|
|
160
|
+
protected configs?: VariableLayoutConfig | undefined;
|
|
161
|
+
tree: FlowVirtualTree<ScopeChainNode> | undefined;
|
|
162
|
+
constructor(flowDocument: FlowDocument, configs?: VariableLayoutConfig | undefined);
|
|
163
|
+
bindTree(tree: FlowVirtualTree<ScopeChainNode>): void;
|
|
164
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
165
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
166
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
167
|
+
scope: Scope;
|
|
168
|
+
}): Scope[];
|
|
169
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
170
|
+
scope: Scope;
|
|
171
|
+
}): Scope[];
|
|
172
|
+
sortAll(): Scope[];
|
|
173
|
+
private getVariableData;
|
|
174
|
+
private isNodeChildrenPrivate;
|
|
175
|
+
private hasChildren;
|
|
176
|
+
private getAllSortedChildScope;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, VariableLayoutConfig };
|