@flowgram.ai/renderer 0.5.1 → 0.5.3
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 +68 -42
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +30 -15
- package/dist/index.d.ts +30 -15
- package/dist/index.js +68 -42
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/esm/index.js
CHANGED
|
@@ -339,7 +339,6 @@ var FlowDragEntity = class extends ConfigEntity {
|
|
|
339
339
|
} else {
|
|
340
340
|
this.containerX -= SCROLL_DELTA;
|
|
341
341
|
}
|
|
342
|
-
this.setDomStyle();
|
|
343
342
|
}
|
|
344
343
|
}, SCROLL_INTERVAL);
|
|
345
344
|
this._scrollXInterval = { interval, origin };
|
|
@@ -368,7 +367,6 @@ var FlowDragEntity = class extends ConfigEntity {
|
|
|
368
367
|
} else {
|
|
369
368
|
this.containerY -= SCROLL_DELTA;
|
|
370
369
|
}
|
|
371
|
-
this.setDomStyle();
|
|
372
370
|
}
|
|
373
371
|
}, SCROLL_INTERVAL);
|
|
374
372
|
this._scrollYInterval = { interval, origin };
|
|
@@ -383,15 +381,10 @@ var FlowDragEntity = class extends ConfigEntity {
|
|
|
383
381
|
this._stopScrollX();
|
|
384
382
|
this._stopScrollY();
|
|
385
383
|
}
|
|
386
|
-
|
|
387
|
-
this.containerDom.style.left = `${this.containerX}px`;
|
|
388
|
-
this.containerDom.style.top = `${this.containerY}px`;
|
|
389
|
-
}
|
|
390
|
-
scrollDirection(e, containerDom, x, y) {
|
|
384
|
+
scrollDirection(e, x, y) {
|
|
391
385
|
const playgroundConfig = this.playgroundConfigEntity.config;
|
|
392
386
|
const currentScrollX = playgroundConfig.scrollX;
|
|
393
387
|
const currentScrollY = playgroundConfig.scrollY;
|
|
394
|
-
this.containerDom = containerDom;
|
|
395
388
|
this.containerX = x;
|
|
396
389
|
this.containerY = y;
|
|
397
390
|
const clientRect = this.playgroundConfigEntity.playgroundDomNode.getBoundingClientRect();
|
|
@@ -2332,6 +2325,7 @@ FlowScrollBarLayer = __decorateClass([
|
|
|
2332
2325
|
], FlowScrollBarLayer);
|
|
2333
2326
|
|
|
2334
2327
|
// src/layers/flow-drag-layer.tsx
|
|
2328
|
+
import ReactDOM2 from "react-dom";
|
|
2335
2329
|
import React15 from "react";
|
|
2336
2330
|
import { inject as inject8, injectable as injectable9 } from "inversify";
|
|
2337
2331
|
import { Rectangle as Rectangle8 } from "@flowgram.ai/utils";
|
|
@@ -2360,6 +2354,7 @@ var DEFAULT_DRAG_OFFSET_Y = 8;
|
|
|
2360
2354
|
var FlowDragLayer = class extends Layer7 {
|
|
2361
2355
|
constructor() {
|
|
2362
2356
|
super(...arguments);
|
|
2357
|
+
this.disableDragScroll = false;
|
|
2363
2358
|
this.dragOffset = {
|
|
2364
2359
|
x: DEFAULT_DRAG_OFFSET_X,
|
|
2365
2360
|
y: DEFAULT_DRAG_OFFSET_Y
|
|
@@ -2400,19 +2395,20 @@ var FlowDragLayer = class extends Layer7 {
|
|
|
2400
2395
|
return currentState === EditorState.STATE_GRAB;
|
|
2401
2396
|
}
|
|
2402
2397
|
setDraggingStatus(status) {
|
|
2403
|
-
if (this.
|
|
2404
|
-
this.
|
|
2398
|
+
if (this.flowDragService.nodeDragIdsWithChildren.length) {
|
|
2399
|
+
this.flowDragService.nodeDragIdsWithChildren.forEach((_id) => {
|
|
2405
2400
|
const node = this.entityManager.getEntityById(_id);
|
|
2406
2401
|
const data = node?.getData(FlowNodeRenderData5);
|
|
2407
2402
|
data.dragging = status;
|
|
2408
2403
|
});
|
|
2409
2404
|
}
|
|
2405
|
+
this.flowRenderStateEntity.setDragging(status);
|
|
2410
2406
|
}
|
|
2411
2407
|
dragEnable(e) {
|
|
2412
2408
|
return Math.abs(e.clientX - this.initialPosition.x) > DRAG_OFFSET || Math.abs(e.clientY - this.initialPosition.y) > DRAG_OFFSET;
|
|
2413
2409
|
}
|
|
2414
2410
|
handleMouseMove(event) {
|
|
2415
|
-
if (this.dragStartEntity && this.dragEnable(event)) {
|
|
2411
|
+
if ((this.dragJSON || this.dragStartEntity) && this.dragEnable(event)) {
|
|
2416
2412
|
this.setDraggingStatus(true);
|
|
2417
2413
|
const scale = this.playgroundConfigEntity.finalScale;
|
|
2418
2414
|
if (this.containerRef.current) {
|
|
@@ -2420,7 +2416,7 @@ var FlowDragLayer = class extends Layer7 {
|
|
|
2420
2416
|
const clientBounds = this.playgroundConfigEntity.getClientBounds();
|
|
2421
2417
|
const dragBlockX = event.clientX - (this.pipelineNode.offsetLeft || 0) - clientBounds.x - (dragNode.clientWidth - this.dragOffset.x) * scale;
|
|
2422
2418
|
const dragBlockY = event.clientY - (this.pipelineNode.offsetTop || 0) - clientBounds.y - (dragNode.clientHeight - this.dragOffset.y) * scale;
|
|
2423
|
-
const isBranch = this.
|
|
2419
|
+
const isBranch = this.flowDragService.isDragBranch;
|
|
2424
2420
|
const draggingRect = new Rectangle8(
|
|
2425
2421
|
dragBlockX,
|
|
2426
2422
|
dragBlockY,
|
|
@@ -2440,7 +2436,7 @@ var FlowDragLayer = class extends Layer7 {
|
|
|
2440
2436
|
side = labelOffsetType;
|
|
2441
2437
|
return hasCollision;
|
|
2442
2438
|
});
|
|
2443
|
-
if (collisionTransition && (isBranch ? this.
|
|
2439
|
+
if (collisionTransition && (isBranch ? this.flowDragService.isDroppableBranch(collisionTransition.entity, side) : this.flowDragService.isDroppableNode(collisionTransition.entity)) && (!this.options.canDrop || this.options.canDrop({
|
|
2444
2440
|
dragNodes: this.dragEntities,
|
|
2445
2441
|
dropNode: collisionTransition.entity,
|
|
2446
2442
|
isBranch
|
|
@@ -2452,37 +2448,45 @@ var FlowDragLayer = class extends Layer7 {
|
|
|
2452
2448
|
this.flowRenderStateEntity.setDragLabelSide(side);
|
|
2453
2449
|
this.containerRef.current.style.visibility = "visible";
|
|
2454
2450
|
this.pipelineNode.parentElement.appendChild(this.draggingNodeMask);
|
|
2455
|
-
this.containerRef.current.style.left = `${dragBlockX}px`;
|
|
2456
|
-
this.containerRef.current.style.top = `${dragBlockY}px`;
|
|
2451
|
+
this.containerRef.current.style.left = `${dragBlockX + this.pipelineNode.offsetLeft + clientBounds.x + window.scrollX}px`;
|
|
2452
|
+
this.containerRef.current.style.top = `${dragBlockY + this.pipelineNode.offsetTop + clientBounds.y + window.scrollY}px`;
|
|
2457
2453
|
this.containerRef.current.style.transformOrigin = "top left";
|
|
2458
2454
|
this.containerRef.current.style.transform = `scale(${scale})`;
|
|
2459
|
-
this.
|
|
2460
|
-
event,
|
|
2461
|
-
|
|
2462
|
-
dragBlockX,
|
|
2463
|
-
dragBlockY
|
|
2464
|
-
);
|
|
2455
|
+
if (!this.disableDragScroll) {
|
|
2456
|
+
this.flowDragConfigEntity.scrollDirection(event, dragBlockX, dragBlockY);
|
|
2457
|
+
}
|
|
2465
2458
|
}
|
|
2466
2459
|
}
|
|
2467
2460
|
}
|
|
2468
|
-
handleMouseUp() {
|
|
2461
|
+
async handleMouseUp() {
|
|
2469
2462
|
this.setDraggingStatus(false);
|
|
2470
|
-
if (this.dragStartEntity) {
|
|
2471
|
-
const activatedNodeId = this.
|
|
2463
|
+
if (this.dragStartEntity || this.dragJSON) {
|
|
2464
|
+
const activatedNodeId = this.flowDragService.dropNodeId;
|
|
2472
2465
|
if (activatedNodeId) {
|
|
2473
|
-
if (this.
|
|
2474
|
-
this.
|
|
2466
|
+
if (this.flowDragService.isDragBranch) {
|
|
2467
|
+
if (this.dragJSON) {
|
|
2468
|
+
await this.flowDragService.dropCreateNode(this.dragJSON, this.onCreateNode);
|
|
2469
|
+
} else {
|
|
2470
|
+
this.flowDragService.dropBranch();
|
|
2471
|
+
}
|
|
2475
2472
|
} else {
|
|
2476
|
-
this.
|
|
2473
|
+
if (this.dragJSON) {
|
|
2474
|
+
await this.flowDragService.dropCreateNode(this.dragJSON, this.onCreateNode);
|
|
2475
|
+
} else {
|
|
2476
|
+
this.flowDragService.dropNode();
|
|
2477
|
+
}
|
|
2477
2478
|
this.selectConfigEntity.clearSelectedNodes();
|
|
2478
2479
|
}
|
|
2479
2480
|
}
|
|
2480
2481
|
this.flowRenderStateEntity.setNodeDroppingId("");
|
|
2481
2482
|
this.flowRenderStateEntity.setDragLabelSide();
|
|
2483
|
+
this.flowRenderStateEntity.setIsBranch(false);
|
|
2482
2484
|
this.dragStartEntity = void 0;
|
|
2483
2485
|
this.dragEntities = [];
|
|
2484
2486
|
this.flowDragConfigEntity.stopAllScroll();
|
|
2485
2487
|
}
|
|
2488
|
+
this.disableDragScroll = false;
|
|
2489
|
+
this.dragJSON = void 0;
|
|
2486
2490
|
if (this.containerRef.current) {
|
|
2487
2491
|
this.containerRef.current.style.visibility = "hidden";
|
|
2488
2492
|
if (this.pipelineNode.parentElement.contains(this.draggingNodeMask)) {
|
|
@@ -2496,17 +2500,25 @@ var FlowDragLayer = class extends Layer7 {
|
|
|
2496
2500
|
*/
|
|
2497
2501
|
async startDrag(e, {
|
|
2498
2502
|
dragStartEntity: startEntityFromProps,
|
|
2499
|
-
dragEntities
|
|
2503
|
+
dragEntities,
|
|
2504
|
+
dragJSON,
|
|
2505
|
+
isBranch,
|
|
2506
|
+
onCreateNode
|
|
2500
2507
|
}, options) {
|
|
2501
2508
|
if (this.isGrab() || this.config.disabled || this.config.readonly) {
|
|
2502
2509
|
return;
|
|
2503
2510
|
}
|
|
2511
|
+
this.disableDragScroll = Boolean(options?.disableDragScroll);
|
|
2512
|
+
this.dragJSON = dragJSON;
|
|
2513
|
+
this.onCreateNode = onCreateNode;
|
|
2514
|
+
this.flowRenderStateEntity.setIsBranch(Boolean(isBranch));
|
|
2504
2515
|
this.dragOffset.x = options?.dragOffsetX || DEFAULT_DRAG_OFFSET_X;
|
|
2505
2516
|
this.dragOffset.y = options?.dragOffsetY || DEFAULT_DRAG_OFFSET_Y;
|
|
2506
|
-
const
|
|
2507
|
-
const
|
|
2517
|
+
const type = startEntityFromProps?.flowNodeType || dragJSON?.type;
|
|
2518
|
+
const isIcon = type === FlowNodeBaseType.BLOCK_ICON;
|
|
2519
|
+
const isOrderIcon = type === FlowNodeBaseType.BLOCK_ORDER_ICON;
|
|
2508
2520
|
const dragStartEntity = isIcon || isOrderIcon ? startEntityFromProps.parent : startEntityFromProps;
|
|
2509
|
-
if (!dragStartEntity.getData(FlowNodeRenderData5).draggable) {
|
|
2521
|
+
if (dragStartEntity && !dragStartEntity.getData(FlowNodeRenderData5).draggable) {
|
|
2510
2522
|
return;
|
|
2511
2523
|
}
|
|
2512
2524
|
this.initialPosition = {
|
|
@@ -2514,7 +2526,7 @@ var FlowDragLayer = class extends Layer7 {
|
|
|
2514
2526
|
y: e.clientY
|
|
2515
2527
|
};
|
|
2516
2528
|
this.dragStartEntity = dragStartEntity;
|
|
2517
|
-
this.dragEntities = dragEntities || [this.dragStartEntity];
|
|
2529
|
+
this.dragEntities = dragEntities || (this.dragStartEntity ? [this.dragStartEntity] : []);
|
|
2518
2530
|
return this._dragger.start(e.clientX, e.clientY);
|
|
2519
2531
|
}
|
|
2520
2532
|
onReady() {
|
|
@@ -2526,19 +2538,33 @@ var FlowDragLayer = class extends Layer7 {
|
|
|
2526
2538
|
this.draggingNodeMask.style.cursor = "pointer";
|
|
2527
2539
|
this.dragNodeComp = this.rendererRegistry.getRendererComponent("drag-node" /* DRAG_NODE */);
|
|
2528
2540
|
if (this.options.onDrop) {
|
|
2529
|
-
this.toDispose.push(this.
|
|
2541
|
+
this.toDispose.push(this.flowDragService.onDrop(this.options.onDrop));
|
|
2530
2542
|
}
|
|
2531
2543
|
}
|
|
2544
|
+
dispose() {
|
|
2545
|
+
this._dragger.dispose();
|
|
2546
|
+
super.dispose();
|
|
2547
|
+
}
|
|
2532
2548
|
render() {
|
|
2533
2549
|
const DragComp = this.dragNodeComp.renderer;
|
|
2534
|
-
return
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2550
|
+
return ReactDOM2.createPortal(
|
|
2551
|
+
/* @__PURE__ */ React15.createElement(
|
|
2552
|
+
"div",
|
|
2553
|
+
{
|
|
2554
|
+
ref: this.containerRef,
|
|
2555
|
+
style: { position: "absolute", zIndex: 99999, visibility: "hidden" },
|
|
2556
|
+
onMouseEnter: (e) => e.stopPropagation()
|
|
2557
|
+
},
|
|
2558
|
+
/* @__PURE__ */ React15.createElement(
|
|
2559
|
+
DragComp,
|
|
2560
|
+
{
|
|
2561
|
+
dragJSON: this.dragJSON,
|
|
2562
|
+
dragStart: this.dragStartEntity,
|
|
2563
|
+
dragNodes: this.dragEntities
|
|
2564
|
+
}
|
|
2565
|
+
)
|
|
2566
|
+
),
|
|
2567
|
+
document.body
|
|
2542
2568
|
);
|
|
2543
2569
|
}
|
|
2544
2570
|
};
|
|
@@ -2547,7 +2573,7 @@ __decorateClass([
|
|
|
2547
2573
|
], FlowDragLayer.prototype, "document", 2);
|
|
2548
2574
|
__decorateClass([
|
|
2549
2575
|
inject8(FlowDragService5)
|
|
2550
|
-
], FlowDragLayer.prototype, "
|
|
2576
|
+
], FlowDragLayer.prototype, "flowDragService", 2);
|
|
2551
2577
|
__decorateClass([
|
|
2552
2578
|
observeEntityDatas6(FlowNodeEntity6, FlowNodeTransformData7)
|
|
2553
2579
|
], FlowDragLayer.prototype, "transforms", 2);
|