@plait/common 0.53.0 → 0.54.0

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.
@@ -1,4 +1,4 @@
1
- import { setAngleForG, RectangleClient, drawCircle, PlaitBoard, createG, drawRectangle, createForeignObject, updateForeignObject, ResizeCursorClass, RESIZE_CURSORS, setDragging, rotatePoints, distanceBetweenPointAndPoint, Point, Direction, hotkeys, PlaitElement, PlaitContextService, getSelectedElements, Transforms, getHighestSelectedElements, getRectangleByElements, PlaitGroupElement, getElementsInGroup, MERGING, PlaitPointerType, isMainPointer, toViewBoxPoint, toHostPoint, preventTouchMove, PRESS_AND_MOVE_BUFFER, isDragging, throttleRAF, handleTouchTarget, ACTIVE_STROKE_WIDTH, getRectangleByGroup, PlaitPluginElementComponent, isSelectionMoving, isSelectedElementOrGroup, Selection, getHitElementsBySelection, createGroupRectangleG, getSelectedGroups, getHighestSelectedGroups, getSelectedIsolatedElements, idCreator, GroupTransforms, getSelectedIsolatedElementsCanAddToGroup, getGroupByElement } from '@plait/core';
1
+ import { PlaitGroupElement, getSelectionAngle, getElementsInGroup, setAngleForG, RectangleClient, drawCircle, PlaitBoard, createG, drawRectangle, createForeignObject, updateForeignObject, ResizeCursorClass, RESIZE_CURSORS, setDragging, rotatePoints, distanceBetweenPointAndPoint, Point, Direction, hotkeys, PlaitElement, PlaitContextService, createDebugGenerator, getSelectedElements, Transforms, getHighestSelectedElements, getRectangleByElements, MERGING, PlaitPointerType, isMainPointer, toViewBoxPoint, toHostPoint, preventTouchMove, PRESS_AND_MOVE_BUFFER, isDragging, throttleRAF, handleTouchTarget, ACTIVE_STROKE_WIDTH, getRectangleByGroup, PlaitPluginElementComponent, isSelectionMoving, isSelectedElementOrGroup, Selection, getHitElementsBySelection, createGroupRectangleG, getSelectedGroups, getHighestSelectedGroups, getSelectedIsolatedElements, idCreator, GroupTransforms, getSelectedIsolatedElementsCanAddToGroup, getGroupByElement } from '@plait/core';
2
2
  import { isKeyHotkey } from 'is-hotkey';
3
3
  import { PlaitMarkEditor, MarkTypes, AlignEditor } from '@plait/text';
4
4
  import { Node, Transforms as Transforms$1, Editor } from 'slate';
@@ -54,8 +54,17 @@ class Generator {
54
54
  }
55
55
  this.g = g;
56
56
  const rect = this.board.getRectangle(element);
57
- if (rect && element.angle) {
58
- setAngleForG(g, RectangleClient.getCenterPoint(rect), element.angle);
57
+ if (rect) {
58
+ let angle;
59
+ if (PlaitGroupElement.isGroup(element)) {
60
+ angle = getSelectionAngle(getElementsInGroup(this.board, element, true));
61
+ }
62
+ else {
63
+ angle = element.angle;
64
+ }
65
+ if (angle) {
66
+ setAngleForG(g, RectangleClient.getCenterPoint(rect), angle);
67
+ }
59
68
  }
60
69
  }
61
70
  else {
@@ -240,7 +249,7 @@ const getRotatedResizeCursorClassByAngle = (cursor, angle) => {
240
249
  }
241
250
  return cursor;
242
251
  };
243
- const getRectangleResizeHandleRefs = (rectangle, diameter, angle = 0) => {
252
+ const getRectangleResizeHandleRefs = (rectangle, diameter) => {
244
253
  const corners = RectangleClient.getCornerPoints(rectangle);
245
254
  const refs = corners.map((corner, index) => {
246
255
  return {
@@ -251,7 +260,7 @@ const getRectangleResizeHandleRefs = (rectangle, diameter, angle = 0) => {
251
260
  height: diameter
252
261
  },
253
262
  handle: getResizeHandleByIndex(index),
254
- cursorClass: getRotatedResizeCursorClassByAngle(getResizeCursorClassByIndex(index), angle)
263
+ cursorClass: getResizeCursorClassByIndex(index)
255
264
  };
256
265
  });
257
266
  const rectangles = getResizeSideRectangles(corners, diameter / 2);
@@ -259,7 +268,7 @@ const getRectangleResizeHandleRefs = (rectangle, diameter, angle = 0) => {
259
268
  return {
260
269
  rectangle,
261
270
  handle: getResizeHandleByIndex(index + 4),
262
- cursorClass: getRotatedResizeCursorClassByAngle(getResizeCursorClassByIndex(index + 4), angle)
271
+ cursorClass: getResizeCursorClassByIndex(index + 4)
263
272
  };
264
273
  }));
265
274
  return refs;
@@ -917,7 +926,8 @@ class PointGraph {
917
926
  }
918
927
  }
919
928
 
920
- const generateElbowLineRoute = (options) => {
929
+ const debugGenerator = createDebugGenerator('debug:plait:elbow-line-routing');
930
+ const generateElbowLineRoute = (options, board) => {
921
931
  const { nextSourcePoint, nextTargetPoint } = options;
922
932
  const points = getGraphPoints(options);
923
933
  const graph = createGraph(points);
@@ -935,15 +945,18 @@ const generateElbowLineRoute = (options) => {
935
945
  const isHitY = RectangleClient.isHitY(options.sourceOuterRectangle, options.targetOuterRectangle);
936
946
  const centerX = isHitX ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, true);
937
947
  const centerY = isHitY ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, false);
938
- route = routeAdjust(route, { centerX, centerY, sourceRectangle: options.sourceRectangle, targetRectangle: options.targetRectangle });
948
+ route = routeAdjust(route, { centerX, centerY, sourceRectangle: options.sourceRectangle, targetRectangle: options.targetRectangle }, board);
939
949
  return route;
940
950
  };
941
- const routeAdjust = (path, options) => {
951
+ const routeAdjust = (path, options, board) => {
942
952
  const { sourceRectangle, targetRectangle, centerX, centerY } = options;
953
+ if (board) {
954
+ debugGenerator.clear();
955
+ }
943
956
  if (centerX !== undefined) {
944
957
  const optionsX = getAdjustOptions(path, centerX, true);
945
958
  const resultX = optionsX.pointOfHit &&
946
- adjust(path, { parallelPaths: optionsX.parallelPaths, pointOfHit: optionsX.pointOfHit, sourceRectangle, targetRectangle });
959
+ adjust(path, { parallelPaths: optionsX.parallelPaths, pointOfHit: optionsX.pointOfHit, sourceRectangle, targetRectangle }, board);
947
960
  if (resultX) {
948
961
  path = resultX;
949
962
  }
@@ -951,14 +964,14 @@ const routeAdjust = (path, options) => {
951
964
  if (centerY !== undefined) {
952
965
  const optionsY = getAdjustOptions(path, centerY, false);
953
966
  const resultY = optionsY.pointOfHit &&
954
- adjust(path, { parallelPaths: optionsY.parallelPaths, pointOfHit: optionsY.pointOfHit, sourceRectangle, targetRectangle });
967
+ adjust(path, { parallelPaths: optionsY.parallelPaths, pointOfHit: optionsY.pointOfHit, sourceRectangle, targetRectangle }, board);
955
968
  if (resultY) {
956
969
  path = resultY;
957
970
  }
958
971
  }
959
972
  return path;
960
973
  };
961
- const adjust = (route, options) => {
974
+ const adjust = (route, options, board) => {
962
975
  const { parallelPaths, pointOfHit, sourceRectangle, targetRectangle } = options;
963
976
  let result = null;
964
977
  parallelPaths.forEach(parallelPath => {
@@ -967,7 +980,10 @@ const adjust = (route, options) => {
967
980
  // directly use getCornerPoints will bring the precision issue (eg: 263.6923375175286 - 57.130859375)
968
981
  const tempRect = RectangleClient.getRectangleByPoints(tempRectPoints);
969
982
  if (!RectangleClient.isHit(tempRect, sourceRectangle) && !RectangleClient.isHit(tempRect, targetRectangle)) {
970
- const tempCorners = RectangleClient.getCornerPoints(tempRect);
983
+ const tempCorners = RectangleClient.getCornerPointsByPoints(tempRectPoints);
984
+ if (board) {
985
+ debugGenerator.drawRectangle(board, tempRect);
986
+ }
971
987
  const indexRangeInPath = [];
972
988
  const indexRangeInCorner = [];
973
989
  route.forEach((point, index) => {
@@ -982,7 +998,11 @@ const adjust = (route, options) => {
982
998
  const removeLength = Math.abs(indexRangeInPath[0] - indexRangeInPath[indexRangeInPath.length - 1]) + 1;
983
999
  newPath.splice(indexRangeInPath[0] + 1, removeLength - 2, missCorner);
984
1000
  const turnCount = simplifyOrthogonalPoints([...route]).length - 1;
985
- const newTurnCount = simplifyOrthogonalPoints([...newPath]).length - 1;
1001
+ const simplifyPoints = simplifyOrthogonalPoints([...newPath]);
1002
+ // if (board) {
1003
+ // debugGenerator.drawLine(board, simplifyPoints);
1004
+ // }
1005
+ const newTurnCount = simplifyPoints.length - 1;
986
1006
  if (newTurnCount <= turnCount) {
987
1007
  result = newPath;
988
1008
  }
@@ -1616,9 +1636,9 @@ function withGroup(board) {
1616
1636
  groupRectangleG = null;
1617
1637
  globalPointerUp(event);
1618
1638
  };
1619
- board.getRelatedFragment = (elements) => {
1620
- const groups = getSelectedGroups(board);
1621
- return getRelatedFragment([...elements, ...groups]);
1639
+ board.getRelatedFragment = (elements, originData) => {
1640
+ const groups = getSelectedGroups(board, originData);
1641
+ return getRelatedFragment([...elements, ...groups], originData);
1622
1642
  };
1623
1643
  board.insertFragment = (data, clipboardData, targetPoint) => {
1624
1644
  const elements = [];
@@ -1644,22 +1664,22 @@ function withGroup(board) {
1644
1664
  });
1645
1665
  };
1646
1666
  board.getDeletedFragment = (data) => {
1667
+ removeGroups = getRemoveGroups(board);
1647
1668
  if (removeGroups && removeGroups.length) {
1648
1669
  data.push(...removeGroups);
1649
1670
  }
1650
1671
  return getDeletedFragment(data);
1651
1672
  };
1652
- board.deleteFragment = (data) => {
1653
- removeGroups = getRemoveGroups(board);
1673
+ board.deleteFragment = (elements) => {
1654
1674
  if (removeGroups?.length) {
1655
1675
  updateSiblingElementGroupId(board, removeGroups);
1656
1676
  }
1657
- deleteFragment(data);
1677
+ deleteFragment(elements);
1658
1678
  removeGroups = null;
1659
1679
  };
1660
1680
  board.getRectangle = (element) => {
1661
1681
  if (PlaitGroupElement.isGroup(element)) {
1662
- return getRectangleByGroup(board, element);
1682
+ return getRectangleByGroup(board, element, true);
1663
1683
  }
1664
1684
  return getRectangle(element);
1665
1685
  };
@@ -1704,7 +1724,8 @@ const updateElementsGroupId = (group, clipboardDataElements, newGroupId) => {
1704
1724
  return elements;
1705
1725
  };
1706
1726
  const getRemoveGroups = (board) => {
1707
- const selectedGroups = board.getRelatedFragment([]);
1727
+ const selectedElements = getSelectedElements(board);
1728
+ const selectedGroups = board.getRelatedFragment([], selectedElements);
1708
1729
  const removeGroups = [...selectedGroups];
1709
1730
  const highestSelectedGroups = getHighestSelectedGroups(board);
1710
1731
  const selectedIsolatedElements = getSelectedIsolatedElementsCanAddToGroup(board);