@xyflow/vue 2.0.0-next.2 → 2.0.0-next.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/index.js CHANGED
@@ -645,39 +645,6 @@ function createExtendedEventHook(defaultHandler) {
645
645
  };
646
646
  }
647
647
  //#endregion
648
- //#region src/utils/drag.ts
649
- function getParentExtent(parent) {
650
- if (parent && typeof parent.internals.positionAbsolute.x !== "undefined" && typeof parent.internals.positionAbsolute.y !== "undefined" && typeof parent.measured.width !== "undefined" && typeof parent.measured.height !== "undefined") return [[parent.internals.positionAbsolute.x, parent.internals.positionAbsolute.y], [parent.internals.positionAbsolute.x + parent.measured.width, parent.internals.positionAbsolute.y + parent.measured.height]];
651
- return false;
652
- }
653
- function getExtent(item, triggerError, extent, parent) {
654
- let currentExtent = item.extent || extent;
655
- if (currentExtent === "parent" && !item.expandParent) if (item.parentId && parent && item.measured.width && item.measured.height) {
656
- const parentExtent = getParentExtent(parent);
657
- if (parentExtent) currentExtent = parentExtent;
658
- } else {
659
- triggerError(new VueFlowError("NODE_EXTENT_INVALID", item.id));
660
- currentExtent = extent;
661
- }
662
- else if (Array.isArray(currentExtent)) {
663
- const parentX = parent?.internals.positionAbsolute.x || 0;
664
- const parentY = parent?.internals.positionAbsolute.y || 0;
665
- currentExtent = [[currentExtent[0][0] + parentX, currentExtent[0][1] + parentY], [currentExtent[1][0] + parentX, currentExtent[1][1] + parentY]];
666
- }
667
- return currentExtent === "parent" ? [[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY], [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]] : currentExtent;
668
- }
669
- function calcNextPosition(node, nextPosition, triggerError, nodeExtent, parentNode) {
670
- const measured = (0, _xyflow_system.getNodeDimensions)(node);
671
- const clampedPos = (0, _xyflow_system.clampPosition)(nextPosition, getExtent(node, triggerError, nodeExtent, parentNode), measured);
672
- return {
673
- position: {
674
- x: clampedPos.x - (parentNode?.internals.positionAbsolute.x || 0),
675
- y: clampedPos.y - (parentNode?.internals.positionAbsolute.y || 0)
676
- },
677
- computedPosition: clampedPos
678
- };
679
- }
680
- //#endregion
681
648
  //#region src/utils/edge.ts
682
649
  function getEdgeHandle(bounds, handleId) {
683
650
  if (!bounds) return null;
@@ -1414,7 +1381,7 @@ function useNode(id) {
1414
1381
  * @internal
1415
1382
  */
1416
1383
  function useUpdateNodePositions() {
1417
- const { getSelectedNodes, updateNodePositions, getInternalNode, emits } = useVueFlow();
1384
+ const { getSelectedNodes, updateNodePositions, getInternalNode } = useVueFlow();
1418
1385
  const store = useStore();
1419
1386
  return (positionDiff, isShiftPressed = false) => {
1420
1387
  const xVelo = store.snapToGrid ? store.snapGrid[0] : 5;
@@ -1426,10 +1393,18 @@ function useUpdateNodePositions() {
1426
1393
  for (const node of getSelectedNodes.value) if (node.draggable || store.nodesDraggable && typeof node.draggable === "undefined") {
1427
1394
  const internalNode = getInternalNode(node.id);
1428
1395
  if (!internalNode) continue;
1429
- const { position } = calcNextPosition(internalNode, {
1396
+ let nextPosition = {
1430
1397
  x: internalNode.internals.positionAbsolute.x + positionDiffX,
1431
1398
  y: internalNode.internals.positionAbsolute.y + positionDiffY
1432
- }, emits.error, store.nodeExtent, node.parentId ? getInternalNode(node.parentId) : void 0);
1399
+ };
1400
+ if (store.snapToGrid) nextPosition = (0, _xyflow_system.snapPosition)(nextPosition, store.snapGrid);
1401
+ const { position, positionAbsolute } = (0, _xyflow_system.calculateNodePosition)({
1402
+ nodeId: node.id,
1403
+ nextPosition,
1404
+ nodeLookup: store.nodeLookup,
1405
+ nodeExtent: store.nodeExtent,
1406
+ nodeOrigin: store.nodeOrigin
1407
+ });
1433
1408
  nodeUpdates.push({
1434
1409
  id: node.id,
1435
1410
  position,
@@ -1438,10 +1413,7 @@ function useUpdateNodePositions() {
1438
1413
  y: positionDiff.y
1439
1414
  },
1440
1415
  measured: (0, _xyflow_system.getNodeDimensions)(internalNode),
1441
- internals: { positionAbsolute: {
1442
- x: internalNode.internals.positionAbsolute.x,
1443
- y: internalNode.internals.positionAbsolute.y
1444
- } }
1416
+ internals: { positionAbsolute }
1445
1417
  });
1446
1418
  }
1447
1419
  updateNodePositions(nodeUpdates, true, false);
@@ -4315,7 +4287,7 @@ function useActions(state, nodeLookup, parentLookup, edgeLookup) {
4315
4287
  for (const id of rawEdgeLookup.keys()) if (!nextIds.has(id)) edgeLookup.delete(id);
4316
4288
  }
4317
4289
  state.edges = next;
4318
- updateConnectionLookup(state.connectionLookup, state.edges);
4290
+ updateConnectionLookup(state.connectionLookup, next);
4319
4291
  }
4320
4292
  /**
4321
4293
  * Recompute parent-aware `internals.positionAbsolute` on the system lookup, then mirror into the