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