@flowgram.ai/document 0.1.24 → 0.1.26
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 +399 -398
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +15 -26
- package/dist/index.d.ts +15 -26
- package/dist/index.js +400 -399
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/esm/index.js
CHANGED
|
@@ -2158,20 +2158,312 @@ FlowDocument = __decorateClass([
|
|
|
2158
2158
|
import { ContainerModule } from "inversify";
|
|
2159
2159
|
|
|
2160
2160
|
// src/services/flow-drag-service.ts
|
|
2161
|
-
import { inject as
|
|
2162
|
-
import {
|
|
2163
|
-
import {
|
|
2161
|
+
import { inject as inject3, injectable as injectable3 } from "inversify";
|
|
2162
|
+
import { Emitter as Emitter6 } from "@flowgram.ai/utils";
|
|
2163
|
+
import { EntityManager as EntityManager2 } from "@flowgram.ai/core";
|
|
2164
|
+
|
|
2165
|
+
// src/services/flow-group-service/flow-group-controller.ts
|
|
2166
|
+
var FlowGroupController = class _FlowGroupController {
|
|
2167
|
+
constructor(groupNode) {
|
|
2168
|
+
this.groupNode = groupNode;
|
|
2169
|
+
}
|
|
2170
|
+
get nodes() {
|
|
2171
|
+
return this.groupNode.collapsedChildren || [];
|
|
2172
|
+
}
|
|
2173
|
+
get collapsed() {
|
|
2174
|
+
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2175
|
+
return groupTransformData.collapsed;
|
|
2176
|
+
}
|
|
2177
|
+
collapse() {
|
|
2178
|
+
this.collapsed = true;
|
|
2179
|
+
}
|
|
2180
|
+
expand() {
|
|
2181
|
+
this.collapsed = false;
|
|
2182
|
+
}
|
|
2183
|
+
/** 获取分组外围的最大边框 */
|
|
2184
|
+
get bounds() {
|
|
2185
|
+
const groupNodeBounds = this.groupNode.getData(FlowNodeTransformData).bounds;
|
|
2186
|
+
return groupNodeBounds;
|
|
2187
|
+
}
|
|
2188
|
+
/** 是否是开始节点 */
|
|
2189
|
+
isStartNode(node) {
|
|
2190
|
+
if (!node) {
|
|
2191
|
+
return false;
|
|
2192
|
+
}
|
|
2193
|
+
const nodes = this.nodes;
|
|
2194
|
+
if (!nodes[0]) {
|
|
2195
|
+
return false;
|
|
2196
|
+
}
|
|
2197
|
+
return node.id === nodes[0].id;
|
|
2198
|
+
}
|
|
2199
|
+
/** 是否是结束节点 */
|
|
2200
|
+
isEndNode(node) {
|
|
2201
|
+
if (!node) {
|
|
2202
|
+
return false;
|
|
2203
|
+
}
|
|
2204
|
+
const nodes = this.nodes;
|
|
2205
|
+
if (!nodes[nodes.length - 1]) {
|
|
2206
|
+
return false;
|
|
2207
|
+
}
|
|
2208
|
+
return node.id === nodes[nodes.length - 1].id;
|
|
2209
|
+
}
|
|
2210
|
+
set note(note) {
|
|
2211
|
+
this.groupNode.getNodeMeta().note = note;
|
|
2212
|
+
}
|
|
2213
|
+
get note() {
|
|
2214
|
+
return this.groupNode.getNodeMeta().note || "";
|
|
2215
|
+
}
|
|
2216
|
+
set noteHeight(height) {
|
|
2217
|
+
this.groupNode.getNodeMeta().noteHeight = height;
|
|
2218
|
+
}
|
|
2219
|
+
get noteHeight() {
|
|
2220
|
+
return this.groupNode.getNodeMeta().noteHeight || 0;
|
|
2221
|
+
}
|
|
2222
|
+
get positionConfig() {
|
|
2223
|
+
return this.groupNode.getNodeMeta().positionConfig;
|
|
2224
|
+
}
|
|
2225
|
+
set collapsed(collapsed) {
|
|
2226
|
+
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2227
|
+
groupTransformData.collapsed = collapsed;
|
|
2228
|
+
groupTransformData.localDirty = true;
|
|
2229
|
+
if (groupTransformData.parent) groupTransformData.parent.localDirty = true;
|
|
2230
|
+
if (groupTransformData.parent?.firstChild)
|
|
2231
|
+
groupTransformData.parent.firstChild.localDirty = true;
|
|
2232
|
+
}
|
|
2233
|
+
set hovered(hovered) {
|
|
2234
|
+
const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
|
|
2235
|
+
if (hovered) {
|
|
2236
|
+
groupRenderData.toggleMouseEnter();
|
|
2237
|
+
} else {
|
|
2238
|
+
groupRenderData.toggleMouseLeave();
|
|
2239
|
+
}
|
|
2240
|
+
if (groupRenderData.hovered === hovered) {
|
|
2241
|
+
return;
|
|
2242
|
+
}
|
|
2243
|
+
groupRenderData.hovered = hovered;
|
|
2244
|
+
}
|
|
2245
|
+
get hovered() {
|
|
2246
|
+
const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
|
|
2247
|
+
return groupRenderData.hovered;
|
|
2248
|
+
}
|
|
2249
|
+
static create(groupNode) {
|
|
2250
|
+
if (!groupNode) {
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
if (!FlowGroupUtils.isGroupNode(groupNode)) {
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
return new _FlowGroupController(groupNode);
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
|
|
2260
|
+
// src/services/flow-group-service/flow-group-utils.ts
|
|
2261
|
+
var FlowGroupUtils;
|
|
2262
|
+
((FlowGroupUtils2) => {
|
|
2263
|
+
const findNodeParents = (node) => {
|
|
2264
|
+
const parents = [];
|
|
2265
|
+
let parent = node.parent;
|
|
2266
|
+
while (parent) {
|
|
2267
|
+
parents.push(parent);
|
|
2268
|
+
parent = parent.parent;
|
|
2269
|
+
}
|
|
2270
|
+
return parents;
|
|
2271
|
+
};
|
|
2272
|
+
const isNodeInGroup = (node) => {
|
|
2273
|
+
if (node?.parent?.flowNodeType === "group" /* GROUP */) {
|
|
2274
|
+
return true;
|
|
2275
|
+
}
|
|
2276
|
+
return false;
|
|
2277
|
+
};
|
|
2278
|
+
FlowGroupUtils2.validate = (nodes) => {
|
|
2279
|
+
if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
|
|
2280
|
+
return false;
|
|
2281
|
+
}
|
|
2282
|
+
const isGroupRelatedNode = nodes.some((node) => (0, FlowGroupUtils2.isGroupNode)(node));
|
|
2283
|
+
if (isGroupRelatedNode) return false;
|
|
2284
|
+
const hasGroup = nodes.some((node) => node && isNodeInGroup(node));
|
|
2285
|
+
if (hasGroup) return false;
|
|
2286
|
+
const parent = nodes[0].parent;
|
|
2287
|
+
const isSameParent = nodes.every((node) => node.parent === parent);
|
|
2288
|
+
if (!isSameParent) return false;
|
|
2289
|
+
const indexes = nodes.map((node) => node.index).sort((a, b) => a - b);
|
|
2290
|
+
const isIndexContinuous = indexes.every((index, i, arr) => {
|
|
2291
|
+
if (i === 0) {
|
|
2292
|
+
return true;
|
|
2293
|
+
}
|
|
2294
|
+
return index === arr[i - 1] + 1;
|
|
2295
|
+
});
|
|
2296
|
+
if (!isIndexContinuous) return false;
|
|
2297
|
+
const parents = findNodeParents(nodes[0]);
|
|
2298
|
+
const parentsInGroup = parents.some((parent2) => isNodeInGroup(parent2));
|
|
2299
|
+
if (parentsInGroup) return false;
|
|
2300
|
+
return true;
|
|
2301
|
+
};
|
|
2302
|
+
FlowGroupUtils2.getNodeGroupController = (node) => {
|
|
2303
|
+
if (!node) {
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
if (!isNodeInGroup(node)) {
|
|
2307
|
+
return;
|
|
2308
|
+
}
|
|
2309
|
+
const groupNode = node?.parent;
|
|
2310
|
+
return FlowGroupController.create(groupNode);
|
|
2311
|
+
};
|
|
2312
|
+
FlowGroupUtils2.getNodeRecursionGroupController = (node) => {
|
|
2313
|
+
if (!node) {
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
const group = (0, FlowGroupUtils2.getNodeGroupController)(node);
|
|
2317
|
+
if (group) {
|
|
2318
|
+
return group;
|
|
2319
|
+
}
|
|
2320
|
+
if (node.parent) {
|
|
2321
|
+
return (0, FlowGroupUtils2.getNodeRecursionGroupController)(node.parent);
|
|
2322
|
+
}
|
|
2323
|
+
return;
|
|
2324
|
+
};
|
|
2325
|
+
FlowGroupUtils2.isGroupNode = (group) => group.flowNodeType === "group" /* GROUP */;
|
|
2326
|
+
})(FlowGroupUtils || (FlowGroupUtils = {}));
|
|
2327
|
+
|
|
2328
|
+
// src/services/flow-drag-service.ts
|
|
2329
|
+
var FlowDragService = class {
|
|
2330
|
+
constructor() {
|
|
2331
|
+
this.onDropEmitter = new Emitter6();
|
|
2332
|
+
this.onDrop = this.onDropEmitter.event;
|
|
2333
|
+
}
|
|
2334
|
+
get renderState() {
|
|
2335
|
+
return this.document.renderState;
|
|
2336
|
+
}
|
|
2337
|
+
// 拖拽所有节点中的首个节点
|
|
2338
|
+
get dragStartNode() {
|
|
2339
|
+
return this.renderState.getDragStartEntity();
|
|
2340
|
+
}
|
|
2341
|
+
// 拖拽的所有节点
|
|
2342
|
+
get dragNodes() {
|
|
2343
|
+
return this.renderState.getDragEntities();
|
|
2344
|
+
}
|
|
2345
|
+
// 放置的区域
|
|
2346
|
+
get dropNodeId() {
|
|
2347
|
+
return this.renderState.getNodeDroppingId();
|
|
2348
|
+
}
|
|
2349
|
+
// 是否在拖拽分支
|
|
2350
|
+
get isDragBranch() {
|
|
2351
|
+
return this.dragStartNode?.isInlineBlock;
|
|
2352
|
+
}
|
|
2353
|
+
// 拖拽的所有节点及其自节点
|
|
2354
|
+
get nodeDragIdsWithChildren() {
|
|
2355
|
+
return this.renderState.config.nodeDragIdsWithChildren || [];
|
|
2356
|
+
}
|
|
2357
|
+
get dragging() {
|
|
2358
|
+
const renderData = this.dragStartNode?.getData(FlowNodeRenderData);
|
|
2359
|
+
return !!renderData?.dragging;
|
|
2360
|
+
}
|
|
2361
|
+
get labelSide() {
|
|
2362
|
+
return this.renderState.config.dragLabelSide;
|
|
2363
|
+
}
|
|
2364
|
+
/**
|
|
2365
|
+
* 放置到目标分支
|
|
2366
|
+
*/
|
|
2367
|
+
dropBranch() {
|
|
2368
|
+
this.dropNode();
|
|
2369
|
+
}
|
|
2370
|
+
/**
|
|
2371
|
+
* 移动到目标节点
|
|
2372
|
+
*/
|
|
2373
|
+
dropNode() {
|
|
2374
|
+
const dropEntity = this.document.getNode(this.dropNodeId);
|
|
2375
|
+
if (!dropEntity) {
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
const sortNodes = [];
|
|
2379
|
+
let curr = this.dragStartNode;
|
|
2380
|
+
while (curr && this.dragNodes.includes(curr)) {
|
|
2381
|
+
sortNodes.push(curr);
|
|
2382
|
+
curr = curr.next;
|
|
2383
|
+
}
|
|
2384
|
+
this.operationService.dragNodes({
|
|
2385
|
+
dropNode: dropEntity,
|
|
2386
|
+
nodes: sortNodes
|
|
2387
|
+
});
|
|
2388
|
+
if (sortNodes.length > 0) {
|
|
2389
|
+
this.onDropEmitter.fire({
|
|
2390
|
+
dropNode: dropEntity,
|
|
2391
|
+
dragNodes: sortNodes
|
|
2392
|
+
});
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
/**
|
|
2396
|
+
* 拖拽是否可以释放在该节点后面
|
|
2397
|
+
*/
|
|
2398
|
+
isDroppableNode(node) {
|
|
2399
|
+
if (!this.dragging || this.isDragBranch) {
|
|
2400
|
+
return false;
|
|
2401
|
+
}
|
|
2402
|
+
if (this.nodeDragIdsWithChildren.includes(node.id) || node.next && this.nodeDragIdsWithChildren.includes(node.next.id)) {
|
|
2403
|
+
return false;
|
|
2404
|
+
}
|
|
2405
|
+
if (node.isInlineBlocks || node.isInlineBlock) {
|
|
2406
|
+
return false;
|
|
2407
|
+
}
|
|
2408
|
+
const hasGroupNode = this.dragNodes.some(
|
|
2409
|
+
(node2) => node2.flowNodeType === "group" /* GROUP */
|
|
2410
|
+
);
|
|
2411
|
+
if (hasGroupNode) {
|
|
2412
|
+
const group = FlowGroupUtils.getNodeRecursionGroupController(node);
|
|
2413
|
+
if (group) {
|
|
2414
|
+
return false;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
return true;
|
|
2418
|
+
}
|
|
2419
|
+
/**
|
|
2420
|
+
* 拖拽分支是否可以释放在该分支
|
|
2421
|
+
* @param node 拖拽的分支节点
|
|
2422
|
+
* @param side 分支的前面还是后面
|
|
2423
|
+
*/
|
|
2424
|
+
isDroppableBranch(node, side = "normal_branch" /* NORMAL_BRANCH */) {
|
|
2425
|
+
if (this.isDragBranch) {
|
|
2426
|
+
if (
|
|
2427
|
+
// 拖拽到分支
|
|
2428
|
+
!node.isInlineBlock || // 只能在同一分支条件下
|
|
2429
|
+
node.parent !== this.dragStartNode.parent || // 自己不能拖拽给自己
|
|
2430
|
+
node === this.dragStartNode
|
|
2431
|
+
) {
|
|
2432
|
+
return false;
|
|
2433
|
+
}
|
|
2434
|
+
if (side === "normal_branch" /* NORMAL_BRANCH */ && node.next !== this.dragStartNode) {
|
|
2435
|
+
return true;
|
|
2436
|
+
}
|
|
2437
|
+
if (side === "pre_branch" /* PRE_BRANCH */ && node.pre !== this.dragStartNode) {
|
|
2438
|
+
return true;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
return false;
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
__decorateClass([
|
|
2445
|
+
inject3(FlowDocument)
|
|
2446
|
+
], FlowDragService.prototype, "document", 2);
|
|
2447
|
+
__decorateClass([
|
|
2448
|
+
inject3(FlowOperationBaseService)
|
|
2449
|
+
], FlowDragService.prototype, "operationService", 2);
|
|
2450
|
+
__decorateClass([
|
|
2451
|
+
inject3(EntityManager2)
|
|
2452
|
+
], FlowDragService.prototype, "entityManager", 2);
|
|
2453
|
+
FlowDragService = __decorateClass([
|
|
2454
|
+
injectable3()
|
|
2455
|
+
], FlowDragService);
|
|
2164
2456
|
|
|
2165
2457
|
// src/services/flow-operation-base-service.ts
|
|
2166
|
-
import { inject as
|
|
2167
|
-
import { DisposableCollection, Emitter as
|
|
2168
|
-
import { EntityManager as
|
|
2458
|
+
import { inject as inject4, injectable as injectable4, postConstruct as postConstruct2 } from "inversify";
|
|
2459
|
+
import { DisposableCollection, Emitter as Emitter7 } from "@flowgram.ai/utils";
|
|
2460
|
+
import { EntityManager as EntityManager3 } from "@flowgram.ai/core";
|
|
2169
2461
|
var FlowOperationBaseServiceImpl = class {
|
|
2170
2462
|
constructor() {
|
|
2171
|
-
this.onNodeAddEmitter = new
|
|
2463
|
+
this.onNodeAddEmitter = new Emitter7();
|
|
2172
2464
|
this.onNodeAdd = this.onNodeAddEmitter.event;
|
|
2173
2465
|
this.toDispose = new DisposableCollection();
|
|
2174
|
-
this.onNodeMoveEmitter = new
|
|
2466
|
+
this.onNodeMoveEmitter = new Emitter7();
|
|
2175
2467
|
this.onNodeMove = this.onNodeMoveEmitter.event;
|
|
2176
2468
|
}
|
|
2177
2469
|
init() {
|
|
@@ -2387,425 +2679,134 @@ var FlowOperationBaseServiceImpl = class {
|
|
|
2387
2679
|
const entity = this.toNodeEntity(node);
|
|
2388
2680
|
const parent = entity?.parent;
|
|
2389
2681
|
if (!parent) {
|
|
2390
|
-
return -1;
|
|
2391
|
-
}
|
|
2392
|
-
return parent.children.findIndex((child) => child === entity);
|
|
2393
|
-
}
|
|
2394
|
-
doMoveNode(node, newParent, index) {
|
|
2395
|
-
if (!node.parent) {
|
|
2396
|
-
throw new Error("root node cannot move");
|
|
2397
|
-
}
|
|
2398
|
-
const event = {
|
|
2399
|
-
node,
|
|
2400
|
-
fromParent: node.parent,
|
|
2401
|
-
toParent: newParent,
|
|
2402
|
-
fromIndex: this.getNodeIndex(node),
|
|
2403
|
-
toIndex: index
|
|
2404
|
-
};
|
|
2405
|
-
this.document.moveChildNodes({
|
|
2406
|
-
nodeIds: [this.toId(node)],
|
|
2407
|
-
toParentId: this.toId(newParent),
|
|
2408
|
-
toIndex: index
|
|
2409
|
-
});
|
|
2410
|
-
this.onNodeMoveEmitter.fire(event);
|
|
2411
|
-
}
|
|
2412
|
-
};
|
|
2413
|
-
__decorateClass([
|
|
2414
|
-
inject3(EntityManager2)
|
|
2415
|
-
], FlowOperationBaseServiceImpl.prototype, "entityManager", 2);
|
|
2416
|
-
__decorateClass([
|
|
2417
|
-
inject3(FlowDocument)
|
|
2418
|
-
], FlowOperationBaseServiceImpl.prototype, "document", 2);
|
|
2419
|
-
__decorateClass([
|
|
2420
|
-
postConstruct2()
|
|
2421
|
-
], FlowOperationBaseServiceImpl.prototype, "init", 1);
|
|
2422
|
-
FlowOperationBaseServiceImpl = __decorateClass([
|
|
2423
|
-
injectable3()
|
|
2424
|
-
], FlowOperationBaseServiceImpl);
|
|
2425
|
-
|
|
2426
|
-
// src/services/flow-group-service.ts
|
|
2427
|
-
import { nanoid } from "nanoid";
|
|
2428
|
-
import { inject as inject4, injectable as injectable4 } from "inversify";
|
|
2429
|
-
import { EntityManager as EntityManager3 } from "@flowgram.ai/core";
|
|
2430
|
-
var FlowGroupService = class {
|
|
2431
|
-
/** 创建分组节点 */
|
|
2432
|
-
createGroup(nodes) {
|
|
2433
|
-
if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
|
|
2434
|
-
return;
|
|
2435
|
-
}
|
|
2436
|
-
if (!FlowGroupController.validate(nodes)) {
|
|
2437
|
-
return;
|
|
2438
|
-
}
|
|
2439
|
-
const sortedNodes = nodes.sort((a, b) => a.index - b.index);
|
|
2440
|
-
const fromNode = sortedNodes[0];
|
|
2441
|
-
const groupId = `group_${nanoid(5)}`;
|
|
2442
|
-
this.operationService.apply({
|
|
2443
|
-
type: "createGroup" /* createGroup */,
|
|
2444
|
-
value: {
|
|
2445
|
-
targetId: fromNode.id,
|
|
2446
|
-
groupId,
|
|
2447
|
-
nodeIds: nodes.map((node) => node.id)
|
|
2448
|
-
}
|
|
2449
|
-
});
|
|
2450
|
-
const groupNode = this.entityManager.getEntityById(groupId);
|
|
2451
|
-
if (!groupNode) {
|
|
2452
|
-
return;
|
|
2453
|
-
}
|
|
2454
|
-
const group = this.groupController(groupNode);
|
|
2455
|
-
if (!group) {
|
|
2456
|
-
return;
|
|
2457
|
-
}
|
|
2458
|
-
group.expand();
|
|
2459
|
-
return groupNode;
|
|
2460
|
-
}
|
|
2461
|
-
/** 删除分组 */
|
|
2462
|
-
deleteGroup(groupNode) {
|
|
2463
|
-
const json = groupNode.toJSON();
|
|
2464
|
-
if (!groupNode.pre || !json) {
|
|
2465
|
-
return;
|
|
2466
|
-
}
|
|
2467
|
-
this.operationService.apply({
|
|
2468
|
-
type: "deleteNodes" /* deleteNodes */,
|
|
2469
|
-
value: {
|
|
2470
|
-
fromId: groupNode.pre.id,
|
|
2471
|
-
nodes: [json]
|
|
2472
|
-
}
|
|
2473
|
-
});
|
|
2474
|
-
}
|
|
2475
|
-
/** 取消分组 */
|
|
2476
|
-
ungroup(groupNode) {
|
|
2477
|
-
const group = this.groupController(groupNode);
|
|
2478
|
-
if (!group) {
|
|
2479
|
-
return;
|
|
2480
|
-
}
|
|
2481
|
-
const nodes = group.nodes;
|
|
2482
|
-
if (!groupNode.pre) {
|
|
2483
|
-
return;
|
|
2484
|
-
}
|
|
2485
|
-
group.collapse();
|
|
2486
|
-
this.operationService.apply({
|
|
2487
|
-
type: "ungroup" /* ungroup */,
|
|
2488
|
-
value: {
|
|
2489
|
-
groupId: groupNode.id,
|
|
2490
|
-
targetId: groupNode.pre.id,
|
|
2491
|
-
nodeIds: nodes.map((node) => node.id)
|
|
2492
|
-
}
|
|
2493
|
-
});
|
|
2494
|
-
}
|
|
2495
|
-
/** 返回所有分组节点 */
|
|
2496
|
-
getAllGroups() {
|
|
2497
|
-
const allNodes = this.entityManager.getEntities(FlowNodeEntity);
|
|
2498
|
-
const groupNodes = allNodes.filter((node) => node.flowNodeType === "group" /* GROUP */);
|
|
2499
|
-
return groupNodes.map((node) => this.groupController(node)).filter(Boolean);
|
|
2500
|
-
}
|
|
2501
|
-
/** 获取分组控制器*/
|
|
2502
|
-
groupController(group) {
|
|
2503
|
-
return FlowGroupController.create(group);
|
|
2504
|
-
}
|
|
2505
|
-
static validate(nodes) {
|
|
2506
|
-
return FlowGroupController.validate(nodes);
|
|
2507
|
-
}
|
|
2508
|
-
};
|
|
2509
|
-
__decorateClass([
|
|
2510
|
-
inject4(EntityManager3)
|
|
2511
|
-
], FlowGroupService.prototype, "entityManager", 2);
|
|
2512
|
-
__decorateClass([
|
|
2513
|
-
inject4(FlowOperationBaseService)
|
|
2514
|
-
], FlowGroupService.prototype, "operationService", 2);
|
|
2515
|
-
FlowGroupService = __decorateClass([
|
|
2516
|
-
injectable4()
|
|
2517
|
-
], FlowGroupService);
|
|
2518
|
-
var FlowGroupController = class _FlowGroupController {
|
|
2519
|
-
constructor(groupNode) {
|
|
2520
|
-
this.groupNode = groupNode;
|
|
2521
|
-
}
|
|
2522
|
-
get nodes() {
|
|
2523
|
-
return this.groupNode.collapsedChildren || [];
|
|
2524
|
-
}
|
|
2525
|
-
get collapsed() {
|
|
2526
|
-
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2527
|
-
return groupTransformData.collapsed;
|
|
2528
|
-
}
|
|
2529
|
-
collapse() {
|
|
2530
|
-
this.collapsed = true;
|
|
2531
|
-
}
|
|
2532
|
-
expand() {
|
|
2533
|
-
this.collapsed = false;
|
|
2534
|
-
}
|
|
2535
|
-
/** 获取分组外围的最大边框 */
|
|
2536
|
-
get bounds() {
|
|
2537
|
-
const groupNodeBounds = this.groupNode.getData(FlowNodeTransformData).bounds;
|
|
2538
|
-
return groupNodeBounds;
|
|
2539
|
-
}
|
|
2540
|
-
/** 是否是开始节点 */
|
|
2541
|
-
isStartNode(node) {
|
|
2542
|
-
if (!node) {
|
|
2543
|
-
return false;
|
|
2544
|
-
}
|
|
2545
|
-
const nodes = this.nodes;
|
|
2546
|
-
if (!nodes[0]) {
|
|
2547
|
-
return false;
|
|
2548
|
-
}
|
|
2549
|
-
return node.id === nodes[0].id;
|
|
2550
|
-
}
|
|
2551
|
-
/** 是否是结束节点 */
|
|
2552
|
-
isEndNode(node) {
|
|
2553
|
-
if (!node) {
|
|
2554
|
-
return false;
|
|
2555
|
-
}
|
|
2556
|
-
const nodes = this.nodes;
|
|
2557
|
-
if (!nodes[nodes.length - 1]) {
|
|
2558
|
-
return false;
|
|
2559
|
-
}
|
|
2560
|
-
return node.id === nodes[nodes.length - 1].id;
|
|
2561
|
-
}
|
|
2562
|
-
set note(note) {
|
|
2563
|
-
this.groupNode.getNodeMeta().note = note;
|
|
2564
|
-
}
|
|
2565
|
-
get note() {
|
|
2566
|
-
return this.groupNode.getNodeMeta().note || "";
|
|
2567
|
-
}
|
|
2568
|
-
set noteHeight(height) {
|
|
2569
|
-
this.groupNode.getNodeMeta().noteHeight = height;
|
|
2570
|
-
}
|
|
2571
|
-
get noteHeight() {
|
|
2572
|
-
return this.groupNode.getNodeMeta().noteHeight || 0;
|
|
2573
|
-
}
|
|
2574
|
-
get positionConfig() {
|
|
2575
|
-
return this.groupNode.getNodeMeta().positionConfig;
|
|
2576
|
-
}
|
|
2577
|
-
set collapsed(collapsed) {
|
|
2578
|
-
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2579
|
-
groupTransformData.collapsed = collapsed;
|
|
2580
|
-
groupTransformData.localDirty = true;
|
|
2581
|
-
if (groupTransformData.parent) groupTransformData.parent.localDirty = true;
|
|
2582
|
-
if (groupTransformData.parent?.firstChild)
|
|
2583
|
-
groupTransformData.parent.firstChild.localDirty = true;
|
|
2584
|
-
}
|
|
2585
|
-
set hovered(hovered) {
|
|
2586
|
-
const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
|
|
2587
|
-
if (hovered) {
|
|
2588
|
-
groupRenderData.toggleMouseEnter();
|
|
2589
|
-
} else {
|
|
2590
|
-
groupRenderData.toggleMouseLeave();
|
|
2591
|
-
}
|
|
2592
|
-
if (groupRenderData.hovered === hovered) {
|
|
2593
|
-
return;
|
|
2682
|
+
return -1;
|
|
2594
2683
|
}
|
|
2595
|
-
|
|
2684
|
+
return parent.children.findIndex((child) => child === entity);
|
|
2596
2685
|
}
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2686
|
+
doMoveNode(node, newParent, index) {
|
|
2687
|
+
if (!node.parent) {
|
|
2688
|
+
throw new Error("root node cannot move");
|
|
2689
|
+
}
|
|
2690
|
+
const event = {
|
|
2691
|
+
node,
|
|
2692
|
+
fromParent: node.parent,
|
|
2693
|
+
toParent: newParent,
|
|
2694
|
+
fromIndex: this.getNodeIndex(node),
|
|
2695
|
+
toIndex: index
|
|
2696
|
+
};
|
|
2697
|
+
this.document.moveChildNodes({
|
|
2698
|
+
nodeIds: [this.toId(node)],
|
|
2699
|
+
toParentId: this.toId(newParent),
|
|
2700
|
+
toIndex: index
|
|
2701
|
+
});
|
|
2702
|
+
this.onNodeMoveEmitter.fire(event);
|
|
2600
2703
|
}
|
|
2601
|
-
|
|
2602
|
-
|
|
2704
|
+
};
|
|
2705
|
+
__decorateClass([
|
|
2706
|
+
inject4(EntityManager3)
|
|
2707
|
+
], FlowOperationBaseServiceImpl.prototype, "entityManager", 2);
|
|
2708
|
+
__decorateClass([
|
|
2709
|
+
inject4(FlowDocument)
|
|
2710
|
+
], FlowOperationBaseServiceImpl.prototype, "document", 2);
|
|
2711
|
+
__decorateClass([
|
|
2712
|
+
postConstruct2()
|
|
2713
|
+
], FlowOperationBaseServiceImpl.prototype, "init", 1);
|
|
2714
|
+
FlowOperationBaseServiceImpl = __decorateClass([
|
|
2715
|
+
injectable4()
|
|
2716
|
+
], FlowOperationBaseServiceImpl);
|
|
2717
|
+
|
|
2718
|
+
// src/services/flow-group-service/flow-group-service.ts
|
|
2719
|
+
import { nanoid } from "nanoid";
|
|
2720
|
+
import { inject as inject5, injectable as injectable5 } from "inversify";
|
|
2721
|
+
import { EntityManager as EntityManager4 } from "@flowgram.ai/core";
|
|
2722
|
+
var FlowGroupService = class {
|
|
2723
|
+
/** 创建分组节点 */
|
|
2724
|
+
createGroup(nodes) {
|
|
2725
|
+
if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
|
|
2603
2726
|
return;
|
|
2604
2727
|
}
|
|
2605
|
-
if (!
|
|
2728
|
+
if (!FlowGroupUtils.validate(nodes)) {
|
|
2606
2729
|
return;
|
|
2607
2730
|
}
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
const hasGroup = nodes.some((node) => node && this.isNodeInGroup(node));
|
|
2618
|
-
if (hasGroup) return false;
|
|
2619
|
-
const parent = nodes[0].parent;
|
|
2620
|
-
const isSameParent = nodes.every((node) => node.parent === parent);
|
|
2621
|
-
if (!isSameParent) return false;
|
|
2622
|
-
const indexes = nodes.map((node) => node.index).sort((a, b) => a - b);
|
|
2623
|
-
const isIndexContinuous = indexes.every((index, i, arr) => {
|
|
2624
|
-
if (i === 0) {
|
|
2625
|
-
return true;
|
|
2731
|
+
const sortedNodes = nodes.sort((a, b) => a.index - b.index);
|
|
2732
|
+
const fromNode = sortedNodes[0];
|
|
2733
|
+
const groupId = `group_${nanoid(5)}`;
|
|
2734
|
+
this.operationService.apply({
|
|
2735
|
+
type: "createGroup" /* createGroup */,
|
|
2736
|
+
value: {
|
|
2737
|
+
targetId: fromNode.id,
|
|
2738
|
+
groupId,
|
|
2739
|
+
nodeIds: nodes.map((node) => node.id)
|
|
2626
2740
|
}
|
|
2627
|
-
return index === arr[i - 1] + 1;
|
|
2628
2741
|
});
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
const parentsInGroup = parents.some((parent2) => this.isNodeInGroup(parent2));
|
|
2632
|
-
if (parentsInGroup) return false;
|
|
2633
|
-
return true;
|
|
2634
|
-
}
|
|
2635
|
-
/** 获取节点分组控制 */
|
|
2636
|
-
static getNodeGroupController(node) {
|
|
2637
|
-
if (!node) {
|
|
2742
|
+
const groupNode = this.entityManager.getEntityById(groupId);
|
|
2743
|
+
if (!groupNode) {
|
|
2638
2744
|
return;
|
|
2639
2745
|
}
|
|
2640
|
-
|
|
2746
|
+
const group = this.groupController(groupNode);
|
|
2747
|
+
if (!group) {
|
|
2641
2748
|
return;
|
|
2642
2749
|
}
|
|
2643
|
-
|
|
2644
|
-
return
|
|
2750
|
+
group.expand();
|
|
2751
|
+
return groupNode;
|
|
2645
2752
|
}
|
|
2646
|
-
/**
|
|
2647
|
-
|
|
2648
|
-
|
|
2753
|
+
/** 删除分组 */
|
|
2754
|
+
deleteGroup(groupNode) {
|
|
2755
|
+
const json = groupNode.toJSON();
|
|
2756
|
+
if (!groupNode.pre || !json) {
|
|
2649
2757
|
return;
|
|
2650
2758
|
}
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
}
|
|
2658
|
-
return;
|
|
2659
|
-
}
|
|
2660
|
-
/** 是否分组节点 */
|
|
2661
|
-
static isGroupNode(group) {
|
|
2662
|
-
return group.flowNodeType === "group" /* GROUP */;
|
|
2663
|
-
}
|
|
2664
|
-
/** 找到节点所有上级 */
|
|
2665
|
-
static findNodeParents(node) {
|
|
2666
|
-
const parents = [];
|
|
2667
|
-
let parent = node.parent;
|
|
2668
|
-
while (parent) {
|
|
2669
|
-
parents.push(parent);
|
|
2670
|
-
parent = parent.parent;
|
|
2671
|
-
}
|
|
2672
|
-
return parents;
|
|
2673
|
-
}
|
|
2674
|
-
/** 节点是否处于分组中 */
|
|
2675
|
-
static isNodeInGroup(node) {
|
|
2676
|
-
if (node?.parent?.flowNodeType === "group" /* GROUP */) {
|
|
2677
|
-
return true;
|
|
2678
|
-
}
|
|
2679
|
-
return false;
|
|
2680
|
-
}
|
|
2681
|
-
};
|
|
2682
|
-
|
|
2683
|
-
// src/services/flow-drag-service.ts
|
|
2684
|
-
var FlowDragService = class {
|
|
2685
|
-
constructor() {
|
|
2686
|
-
this.onDropEmitter = new Emitter7();
|
|
2687
|
-
this.onDrop = this.onDropEmitter.event;
|
|
2688
|
-
}
|
|
2689
|
-
get renderState() {
|
|
2690
|
-
return this.document.renderState;
|
|
2691
|
-
}
|
|
2692
|
-
// 拖拽所有节点中的首个节点
|
|
2693
|
-
get dragStartNode() {
|
|
2694
|
-
return this.renderState.getDragStartEntity();
|
|
2695
|
-
}
|
|
2696
|
-
// 拖拽的所有节点
|
|
2697
|
-
get dragNodes() {
|
|
2698
|
-
return this.renderState.getDragEntities();
|
|
2699
|
-
}
|
|
2700
|
-
// 放置的区域
|
|
2701
|
-
get dropNodeId() {
|
|
2702
|
-
return this.renderState.getNodeDroppingId();
|
|
2703
|
-
}
|
|
2704
|
-
// 是否在拖拽分支
|
|
2705
|
-
get isDragBranch() {
|
|
2706
|
-
return this.dragStartNode?.isInlineBlock;
|
|
2707
|
-
}
|
|
2708
|
-
// 拖拽的所有节点及其自节点
|
|
2709
|
-
get nodeDragIdsWithChildren() {
|
|
2710
|
-
return this.renderState.config.nodeDragIdsWithChildren || [];
|
|
2711
|
-
}
|
|
2712
|
-
get dragging() {
|
|
2713
|
-
const renderData = this.dragStartNode?.getData(FlowNodeRenderData);
|
|
2714
|
-
return !!renderData?.dragging;
|
|
2715
|
-
}
|
|
2716
|
-
get labelSide() {
|
|
2717
|
-
return this.renderState.config.dragLabelSide;
|
|
2718
|
-
}
|
|
2719
|
-
/**
|
|
2720
|
-
* 放置到目标分支
|
|
2721
|
-
*/
|
|
2722
|
-
dropBranch() {
|
|
2723
|
-
this.dropNode();
|
|
2759
|
+
this.operationService.apply({
|
|
2760
|
+
type: "deleteNodes" /* deleteNodes */,
|
|
2761
|
+
value: {
|
|
2762
|
+
fromId: groupNode.pre.id,
|
|
2763
|
+
nodes: [json]
|
|
2764
|
+
}
|
|
2765
|
+
});
|
|
2724
2766
|
}
|
|
2725
|
-
/**
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
const dropEntity = this.document.getNode(this.dropNodeId);
|
|
2730
|
-
if (!dropEntity) {
|
|
2767
|
+
/** 取消分组 */
|
|
2768
|
+
ungroup(groupNode) {
|
|
2769
|
+
const group = this.groupController(groupNode);
|
|
2770
|
+
if (!group) {
|
|
2731
2771
|
return;
|
|
2732
2772
|
}
|
|
2733
|
-
const
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
sortNodes.push(curr);
|
|
2737
|
-
curr = curr.next;
|
|
2773
|
+
const nodes = group.nodes;
|
|
2774
|
+
if (!groupNode.pre) {
|
|
2775
|
+
return;
|
|
2738
2776
|
}
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2777
|
+
group.collapse();
|
|
2778
|
+
this.operationService.apply({
|
|
2779
|
+
type: "ungroup" /* ungroup */,
|
|
2780
|
+
value: {
|
|
2781
|
+
groupId: groupNode.id,
|
|
2782
|
+
targetId: groupNode.pre.id,
|
|
2783
|
+
nodeIds: nodes.map((node) => node.id)
|
|
2784
|
+
}
|
|
2742
2785
|
});
|
|
2743
|
-
if (sortNodes.length > 0) {
|
|
2744
|
-
this.onDropEmitter.fire({
|
|
2745
|
-
dropNode: dropEntity,
|
|
2746
|
-
dragNodes: sortNodes
|
|
2747
|
-
});
|
|
2748
|
-
}
|
|
2749
2786
|
}
|
|
2750
|
-
/**
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
return false;
|
|
2756
|
-
}
|
|
2757
|
-
if (this.nodeDragIdsWithChildren.includes(node.id) || node.next && this.nodeDragIdsWithChildren.includes(node.next.id)) {
|
|
2758
|
-
return false;
|
|
2759
|
-
}
|
|
2760
|
-
if (node.isInlineBlocks || node.isInlineBlock) {
|
|
2761
|
-
return false;
|
|
2762
|
-
}
|
|
2763
|
-
const hasGroupNode = this.dragNodes.some((node2) => node2.flowNodeType === "group" /* GROUP */);
|
|
2764
|
-
if (hasGroupNode) {
|
|
2765
|
-
const group = FlowGroupController.getNodeRecursionGroupController(node);
|
|
2766
|
-
if (group) {
|
|
2767
|
-
return false;
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
return true;
|
|
2787
|
+
/** 返回所有分组节点 */
|
|
2788
|
+
getAllGroups() {
|
|
2789
|
+
const allNodes = this.entityManager.getEntities(FlowNodeEntity);
|
|
2790
|
+
const groupNodes = allNodes.filter((node) => node.flowNodeType === "group" /* GROUP */);
|
|
2791
|
+
return groupNodes.map((node) => this.groupController(node)).filter(Boolean);
|
|
2771
2792
|
}
|
|
2772
|
-
/**
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
if (this.isDragBranch) {
|
|
2779
|
-
if (
|
|
2780
|
-
// 拖拽到分支
|
|
2781
|
-
!node.isInlineBlock || // 只能在同一分支条件下
|
|
2782
|
-
node.parent !== this.dragStartNode.parent || // 自己不能拖拽给自己
|
|
2783
|
-
node === this.dragStartNode
|
|
2784
|
-
) {
|
|
2785
|
-
return false;
|
|
2786
|
-
}
|
|
2787
|
-
if (side === "normal_branch" /* NORMAL_BRANCH */ && node.next !== this.dragStartNode) {
|
|
2788
|
-
return true;
|
|
2789
|
-
}
|
|
2790
|
-
if (side === "pre_branch" /* PRE_BRANCH */ && node.pre !== this.dragStartNode) {
|
|
2791
|
-
return true;
|
|
2792
|
-
}
|
|
2793
|
-
}
|
|
2794
|
-
return false;
|
|
2793
|
+
/** 获取分组控制器*/
|
|
2794
|
+
groupController(group) {
|
|
2795
|
+
return FlowGroupController.create(group);
|
|
2796
|
+
}
|
|
2797
|
+
static validate(nodes) {
|
|
2798
|
+
return FlowGroupUtils.validate(nodes);
|
|
2795
2799
|
}
|
|
2796
2800
|
};
|
|
2797
2801
|
__decorateClass([
|
|
2798
|
-
inject5(
|
|
2799
|
-
],
|
|
2802
|
+
inject5(EntityManager4)
|
|
2803
|
+
], FlowGroupService.prototype, "entityManager", 2);
|
|
2800
2804
|
__decorateClass([
|
|
2801
2805
|
inject5(FlowOperationBaseService)
|
|
2802
|
-
],
|
|
2803
|
-
__decorateClass([
|
|
2804
|
-
inject5(EntityManager4)
|
|
2805
|
-
], FlowDragService.prototype, "entityManager", 2);
|
|
2806
|
-
FlowDragService = __decorateClass([
|
|
2806
|
+
], FlowGroupService.prototype, "operationService", 2);
|
|
2807
|
+
FlowGroupService = __decorateClass([
|
|
2807
2808
|
injectable5()
|
|
2808
|
-
],
|
|
2809
|
+
], FlowGroupService);
|
|
2809
2810
|
|
|
2810
2811
|
// src/layout/vertical-fixed-layout.ts
|
|
2811
2812
|
import { injectable as injectable6, inject as inject6, multiInject as multiInject2, optional as optional3 } from "inversify";
|