@plait/core 0.92.2 → 0.93.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.
@@ -165,7 +165,7 @@ const POINTER_BUTTON = {
165
165
  };
166
166
  const PRESS_AND_MOVE_BUFFER = 3;
167
167
  const DRAG_SELECTION_PRESS_AND_MOVE_BUFFER = 10;
168
- const HIT_DISTANCE_BUFFER = 5;
168
+ const HIT_DISTANCE_BUFFER = 3;
169
169
 
170
170
  function hasBeforeContextChange(value) {
171
171
  if (value.beforeContextChange) {
@@ -231,7 +231,7 @@ function isContextmenu(event) {
231
231
  }
232
232
  function uniqueById(elements) {
233
233
  const uniqueMap = new Map();
234
- elements.forEach(item => {
234
+ elements.forEach((item) => {
235
235
  if (!uniqueMap.has(item.id)) {
236
236
  uniqueMap.set(item.id, item);
237
237
  }
@@ -714,8 +714,8 @@ const RectangleClient = {
714
714
  let xMax = -Infinity;
715
715
  let yMax = -Infinity;
716
716
  for (const point of points) {
717
- const xArray = point.map(ele => ele[0]);
718
- const yArray = point.map(ele => ele[1]);
717
+ const xArray = point.map((ele) => ele[0]);
718
+ const yArray = point.map((ele) => ele[1]);
719
719
  xMin = Math.min(xMin, ...xArray);
720
720
  yMin = Math.min(yMin, ...yArray);
721
721
  xMax = Math.max(xMax, ...xArray);
@@ -726,8 +726,8 @@ const RectangleClient = {
726
726
  return rect;
727
727
  },
728
728
  getCornerPointsByPoints(points) {
729
- const xArray = points.map(ele => ele[0]);
730
- const yArray = points.map(ele => ele[1]);
729
+ const xArray = points.map((ele) => ele[0]);
730
+ const yArray = points.map((ele) => ele[1]);
731
731
  const xMin = Math.min(...xArray);
732
732
  const xMax = Math.max(...xArray);
733
733
  const yMin = Math.min(...yArray);
@@ -814,7 +814,7 @@ const RectangleClient = {
814
814
  let minY = Number.MAX_VALUE;
815
815
  let maxX = Number.NEGATIVE_INFINITY;
816
816
  let maxY = Number.NEGATIVE_INFINITY;
817
- rectangles.forEach(rect => {
817
+ rectangles.forEach((rect) => {
818
818
  minX = Math.min(minX, rect.x);
819
819
  minY = Math.min(minY, rect.y);
820
820
  maxX = Math.max(maxX, rect.x + rect.width);
@@ -830,7 +830,7 @@ const RectangleClient = {
830
830
  };
831
831
  function isPointArray(data) {
832
832
  return (Array.isArray(data) &&
833
- data.every(item => Array.isArray(item) && item.length === 2 && typeof item[0] === 'number' && typeof item[1] === 'number'));
833
+ data.every((item) => Array.isArray(item) && item.length === 2 && typeof item[0] === 'number' && typeof item[1] === 'number'));
834
834
  }
835
835
 
836
836
  // https://stackoverflow.com/a/6853926/232122
@@ -1352,7 +1352,7 @@ const setStrokeLinecap = (g, value) => {
1352
1352
  g.setAttribute('stroke-linecap', value);
1353
1353
  };
1354
1354
  const setPathStrokeLinecap = (g, value) => {
1355
- g.querySelectorAll('path').forEach(path => {
1355
+ g.querySelectorAll('path').forEach((path) => {
1356
1356
  path.setAttribute('stroke-linecap', value);
1357
1357
  });
1358
1358
  };
@@ -1656,7 +1656,7 @@ function depthFirstRecursion(node, callback, recursion, isReverse) {
1656
1656
  if (node.children && (!recursion || recursion(node))) {
1657
1657
  let children = [...node.children];
1658
1658
  children = isReverse ? children.reverse() : children;
1659
- children.forEach(child => {
1659
+ children.forEach((child) => {
1660
1660
  depthFirstRecursion(child, callback, recursion);
1661
1661
  });
1662
1662
  }
@@ -1889,7 +1889,7 @@ const getHitElementsByPoint = (board, point, match = () => true, isStrict = true
1889
1889
  };
1890
1890
  const getHitElementByPoint = (board, point, match = () => true, isStrict = true) => {
1891
1891
  const pointHitElements = getHitElementsByPoint(board, point, match, isStrict);
1892
- const hitElement = board.getOneHitElement(pointHitElements);
1892
+ const hitElement = board.getOneHitElement(pointHitElements, point);
1893
1893
  return hitElement;
1894
1894
  };
1895
1895
  const getHitSelectedElements = (board, point) => {
@@ -2178,7 +2178,7 @@ function fitViewportWidth(board, options) {
2178
2178
  function updateThemeColor(board, mode) {
2179
2179
  mode = mode ?? board.theme.themeColorMode;
2180
2180
  setTheme(board, { themeColorMode: mode });
2181
- depthFirstRecursion(board, element => {
2181
+ depthFirstRecursion(board, (element) => {
2182
2182
  board.applyTheme(element);
2183
2183
  });
2184
2184
  }
@@ -2627,10 +2627,10 @@ const debounce = (func, wait, options) => {
2627
2627
  const getElementsIndices = (board, elements) => {
2628
2628
  sortElements(board, elements);
2629
2629
  return elements
2630
- .map(item => {
2631
- return board.children.map(item => item.id).indexOf(item.id);
2630
+ .map((item) => {
2631
+ return board.children.map((item) => item.id).indexOf(item.id);
2632
2632
  })
2633
- .filter(item => item >= 0);
2633
+ .filter((item) => item >= 0);
2634
2634
  };
2635
2635
  const getHighestIndexOfElement = (board, elements) => {
2636
2636
  const indices = getElementsIndices(board, elements);
@@ -2638,7 +2638,7 @@ const getHighestIndexOfElement = (board, elements) => {
2638
2638
  };
2639
2639
  const moveElementsToNewPath = (board, moveOptions) => {
2640
2640
  moveOptions
2641
- .map(item => {
2641
+ .map((item) => {
2642
2642
  const path = PlaitBoard.findPath(board, item.element);
2643
2643
  const ref = board.pathRef(path);
2644
2644
  return () => {
@@ -2646,7 +2646,7 @@ const moveElementsToNewPath = (board, moveOptions) => {
2646
2646
  ref.unref();
2647
2647
  };
2648
2648
  })
2649
- .forEach(action => {
2649
+ .forEach((action) => {
2650
2650
  action();
2651
2651
  });
2652
2652
  };
@@ -3034,9 +3034,9 @@ const getNavigatorClipboard = async () => {
3034
3034
  if (Array.isArray(clipboardItems) && clipboardItems[0] instanceof ClipboardItem) {
3035
3035
  for (const item of clipboardItems) {
3036
3036
  if (isFile(item)) {
3037
- const clipboardFiles = item.types.filter(type => type.match(/^image\//));
3038
- const fileBlobs = await Promise.all(clipboardFiles.map(type => item.getType(type)));
3039
- const urls = fileBlobs.filter(Boolean).map(blob => URL.createObjectURL(blob));
3037
+ const clipboardFiles = item.types.filter((type) => type.match(/^image\//));
3038
+ const fileBlobs = await Promise.all(clipboardFiles.map((type) => item.getType(type)));
3039
+ const urls = fileBlobs.filter(Boolean).map((blob) => URL.createObjectURL(blob));
3040
3040
  const files = await Promise.all(urls.map(async (url) => {
3041
3041
  const blob = await (await fetch(url)).blob();
3042
3042
  return new File([blob], 'plait-file', { type: blob.type });
@@ -3066,7 +3066,7 @@ const getNavigatorClipboard = async () => {
3066
3066
  return clipboardData;
3067
3067
  };
3068
3068
  const isFile = (item) => {
3069
- return item.types.find(i => i.match(/^image\//));
3069
+ return item.types.find((i) => i.match(/^image\//));
3070
3070
  };
3071
3071
  const blobAsString = (blob) => {
3072
3072
  return new Promise((resolve, reject) => {
@@ -3208,7 +3208,7 @@ function setSelectedElementsWithGroup(board, elements, isShift) {
3208
3208
  cacheSelectedElementsWithGroupOnShift(board, elements, isSelectGroupElement, elementsInHighestGroup);
3209
3209
  }
3210
3210
  else {
3211
- cacheSelectedElementsWithGroup(board, elements, isSelectGroupElement, hitElementGroups);
3211
+ cacheSelectedElementsWithGroup(board, elements, isSelectGroupElement, hitElementGroups, board.selection.anchor);
3212
3212
  }
3213
3213
  }
3214
3214
  }
@@ -3241,7 +3241,7 @@ function cacheSelectedElementsWithGroupOnShift(board, elements, isSelectGroupEle
3241
3241
  }
3242
3242
  cacheSelectedElements(board, uniqueById(newElements));
3243
3243
  }
3244
- function cacheSelectedElementsWithGroup(board, elements, isSelectGroupElement, hitElementGroups) {
3244
+ function cacheSelectedElementsWithGroup(board, elements, isSelectGroupElement, hitElementGroups, hitPoint) {
3245
3245
  let newElements = [...elements];
3246
3246
  const selectedGroups = filterSelectedGroups(board, hitElementGroups);
3247
3247
  if (selectedGroups.length > 0) {
@@ -3249,7 +3249,7 @@ function cacheSelectedElementsWithGroup(board, elements, isSelectGroupElement, h
3249
3249
  newElements = getAllElementsInGroup(board, selectedGroups[selectedGroups.length - 2], true);
3250
3250
  }
3251
3251
  else {
3252
- const element = board.getOneHitElement(elements);
3252
+ const element = board.getOneHitElement(elements, hitPoint);
3253
3253
  if (element) {
3254
3254
  newElements = [element];
3255
3255
  }
@@ -3261,7 +3261,7 @@ function cacheSelectedElementsWithGroup(board, elements, isSelectGroupElement, h
3261
3261
  newElements = elementsInGroup;
3262
3262
  }
3263
3263
  else {
3264
- const element = board.getOneHitElement(elements);
3264
+ const element = board.getOneHitElement(elements, hitPoint);
3265
3265
  if (element) {
3266
3266
  newElements = [element];
3267
3267
  }
@@ -3535,11 +3535,11 @@ const SNAP_TOLERANCE = 2;
3535
3535
  const SNAP_SPACING = 24;
3536
3536
  function getSnapRectangles(board, activeElements) {
3537
3537
  const elements = findElements(board, {
3538
- match: element => board.isAlign(element) && !activeElements.some(item => item.id === element.id),
3538
+ match: (element) => board.isAlign(element) && !activeElements.some((item) => item.id === element.id),
3539
3539
  recursion: () => true,
3540
3540
  isReverse: false
3541
3541
  });
3542
- return elements.map(item => {
3542
+ return elements.map((item) => {
3543
3543
  const rectangle = board.getRectangle(item);
3544
3544
  return getRectangleByAngle(rectangle, item.angle || 0);
3545
3545
  });
@@ -3557,7 +3557,7 @@ function getBarPoint(point, isHorizontal) {
3557
3557
  }
3558
3558
  function getMinPointDelta(pointRectangles, axis, isHorizontal) {
3559
3559
  let delta = SNAP_TOLERANCE;
3560
- pointRectangles.forEach(item => {
3560
+ pointRectangles.forEach((item) => {
3561
3561
  const distance = getNearestDelta(axis, item, isHorizontal);
3562
3562
  if (Math.abs(distance) < Math.abs(delta)) {
3563
3563
  delta = distance;
@@ -3567,8 +3567,8 @@ function getMinPointDelta(pointRectangles, axis, isHorizontal) {
3567
3567
  }
3568
3568
  const getNearestDelta = (axis, rectangle, isHorizontal) => {
3569
3569
  const pointAxis = getTripleAxis(rectangle, isHorizontal);
3570
- const deltas = pointAxis.map(item => item - axis);
3571
- const absDeltas = deltas.map(item => Math.abs(item));
3570
+ const deltas = pointAxis.map((item) => item - axis);
3571
+ const absDeltas = deltas.map((item) => Math.abs(item));
3572
3572
  const index = absDeltas.indexOf(Math.min(...absDeltas));
3573
3573
  return deltas[index];
3574
3574
  };
@@ -3580,7 +3580,7 @@ const getTripleAxis = (rectangle, isHorizontal) => {
3580
3580
  function getNearestPointRectangle(snapRectangles, activeRectangle) {
3581
3581
  let minDistance = Infinity;
3582
3582
  let nearestRectangle = snapRectangles[0];
3583
- snapRectangles.forEach(item => {
3583
+ snapRectangles.forEach((item) => {
3584
3584
  const distance = Math.sqrt(Math.pow(activeRectangle.x - item.x, 2) + Math.pow(activeRectangle.y - item.y, 2));
3585
3585
  if (distance < minDistance) {
3586
3586
  minDistance = distance;
@@ -3703,7 +3703,7 @@ function drawPointSnapLines(board, activeRectangle, snapRectangles, drawHorizont
3703
3703
  }
3704
3704
  function drawDashedLines(board, lines) {
3705
3705
  const g = createG();
3706
- lines.forEach(points => {
3706
+ lines.forEach((points) => {
3707
3707
  if (!points.length)
3708
3708
  return;
3709
3709
  const line = PlaitBoard.getRoughSVG(board).line(points[0][0], points[0][1], points[1][0], points[1][1], {
@@ -3717,7 +3717,7 @@ function drawDashedLines(board, lines) {
3717
3717
  }
3718
3718
  function drawSolidLines(board, lines) {
3719
3719
  const g = createG();
3720
- lines.forEach(points => {
3720
+ lines.forEach((points) => {
3721
3721
  if (!points.length)
3722
3722
  return;
3723
3723
  let isHorizontal = points[0][1] === points[1][1];
@@ -3726,7 +3726,7 @@ function drawSolidLines(board, lines) {
3726
3726
  strokeWidth: 1
3727
3727
  });
3728
3728
  g.appendChild(line);
3729
- points.forEach(point => {
3729
+ points.forEach((point) => {
3730
3730
  const barPoint = getBarPoint(point, isHorizontal);
3731
3731
  const bar = PlaitBoard.getRoughSVG(board).line(barPoint[0][0], barPoint[0][1], barPoint[1][0], barPoint[1][1], {
3732
3732
  stroke: SELECTION_BORDER_COLOR,
@@ -3756,7 +3756,7 @@ const getOneMoveOptions = (board, direction) => {
3756
3756
  if (direction === 'down') {
3757
3757
  indices = indices.reverse();
3758
3758
  }
3759
- moveContents.push(...indices.map(path => {
3759
+ moveContents.push(...indices.map((path) => {
3760
3760
  return {
3761
3761
  element: board.children[path],
3762
3762
  newPath: [targetIndex]
@@ -3772,7 +3772,7 @@ const getAllMoveOptions = (board, direction) => {
3772
3772
  if (direction === 'down') {
3773
3773
  groupedIndices = groupedIndices.reverse();
3774
3774
  }
3775
- groupedIndices.forEach(indices => {
3775
+ groupedIndices.forEach((indices) => {
3776
3776
  const leadingIndex = indices[0];
3777
3777
  const trailingIndex = indices[indices.length - 1];
3778
3778
  const boundaryIndex = direction === 'down' ? leadingIndex : trailingIndex;
@@ -3789,7 +3789,7 @@ const getAllMoveOptions = (board, direction) => {
3789
3789
  if (direction === 'down') {
3790
3790
  indices = indices.reverse();
3791
3791
  }
3792
- moveContents.push(...indices.map(path => {
3792
+ moveContents.push(...indices.map((path) => {
3793
3793
  return {
3794
3794
  element: board.children[path],
3795
3795
  newPath: [targetIndex]
@@ -3799,7 +3799,7 @@ const getAllMoveOptions = (board, direction) => {
3799
3799
  return moveContents;
3800
3800
  };
3801
3801
  const canSetZIndex = (board) => {
3802
- const selectedElements = getSelectedElements(board).filter(item => board.canSetZIndex(item));
3802
+ const selectedElements = getSelectedElements(board).filter((item) => board.canSetZIndex(item));
3803
3803
  return selectedElements.length > 0;
3804
3804
  };
3805
3805
  const toContiguousGroups = (board, array) => {
@@ -3853,8 +3853,8 @@ const getTargetIndex = (board, boundaryIndex, direction) => {
3853
3853
  return true;
3854
3854
  };
3855
3855
  const candidateIndex = direction === 'down'
3856
- ? findLastIndex(board.children, el => indexFilter(el), Math.max(0, boundaryIndex - 1))
3857
- : findIndex(board.children, el => indexFilter(el), boundaryIndex + 1);
3856
+ ? findLastIndex(board.children, (el) => indexFilter(el), Math.max(0, boundaryIndex - 1))
3857
+ : findIndex(board.children, (el) => indexFilter(el), boundaryIndex + 1);
3858
3858
  const nextElement = board.children[candidateIndex];
3859
3859
  if (!nextElement) {
3860
3860
  return -1;
@@ -3866,7 +3866,7 @@ const getTargetIndex = (board, boundaryIndex, direction) => {
3866
3866
  // candidate element is a sibling in current editing group → return
3867
3867
  if (editingGroup && sourceElement?.groupId !== nextElement?.groupId) {
3868
3868
  // candidate element is outside current editing group → prevent
3869
- if (!nextElementGroups.find(item => item.id === editingGroup.id)) {
3869
+ if (!nextElementGroups.find((item) => item.id === editingGroup.id)) {
3870
3870
  return -1;
3871
3871
  }
3872
3872
  }
@@ -3884,8 +3884,8 @@ const getTargetIndex = (board, boundaryIndex, direction) => {
3884
3884
  let elementsInSiblingGroup = getElementsInGroup(board, siblingGroup, true, false);
3885
3885
  if (elementsInSiblingGroup.length) {
3886
3886
  elementsInSiblingGroup.sort((a, b) => {
3887
- const indexA = board.children.findIndex(child => child.id === a.id);
3888
- const indexB = board.children.findIndex(child => child.id === b.id);
3887
+ const indexA = board.children.findIndex((child) => child.id === a.id);
3888
+ const indexB = board.children.findIndex((child) => child.id === b.id);
3889
3889
  return indexA - indexB;
3890
3890
  });
3891
3891
  // assumes getElementsInGroup() returned elements are sorted
@@ -3918,7 +3918,7 @@ const addGroup = (board, elements) => {
3918
3918
  const highestSelectedElements = [...selectedGroups, ...selectedIsolatedElements];
3919
3919
  const group = createGroup();
3920
3920
  if (canAddGroup(board)) {
3921
- highestSelectedElements.forEach(item => {
3921
+ highestSelectedElements.forEach((item) => {
3922
3922
  const path = PlaitBoard.findPath(board, item);
3923
3923
  NodeTransforms.setNode(board, { groupId: group.id }, path);
3924
3924
  });
@@ -3944,18 +3944,18 @@ const addGroup = (board, elements) => {
3944
3944
  const removeGroup = (board, elements) => {
3945
3945
  const selectedGroups = getHighestSelectedGroups(board, elements);
3946
3946
  if (canRemoveGroup(board)) {
3947
- selectedGroups.forEach(group => {
3947
+ selectedGroups.forEach((group) => {
3948
3948
  const elementsInGroup = findElements(board, {
3949
- match: item => item.groupId === group.id,
3949
+ match: (item) => item.groupId === group.id,
3950
3950
  recursion: () => false
3951
3951
  });
3952
- elementsInGroup.forEach(element => {
3952
+ elementsInGroup.forEach((element) => {
3953
3953
  const path = PlaitBoard.findPath(board, element);
3954
3954
  NodeTransforms.setNode(board, { groupId: group.groupId || undefined }, path);
3955
3955
  });
3956
3956
  });
3957
3957
  selectedGroups
3958
- .map(group => {
3958
+ .map((group) => {
3959
3959
  const groupPath = PlaitBoard.findPath(board, group);
3960
3960
  const groupRef = board.pathRef(groupPath);
3961
3961
  return () => {
@@ -3963,7 +3963,7 @@ const removeGroup = (board, elements) => {
3963
3963
  groupRef.unref();
3964
3964
  };
3965
3965
  })
3966
- .forEach(action => {
3966
+ .forEach((action) => {
3967
3967
  action();
3968
3968
  });
3969
3969
  }
@@ -3989,7 +3989,7 @@ function addSelectionWithTemporaryElements(board, elements) {
3989
3989
  if (ref) {
3990
3990
  clearTimeout(ref.timeoutId);
3991
3991
  const currentElements = ref.elements;
3992
- ref.elements.push(...elements.filter(element => !currentElements.includes(element)));
3992
+ ref.elements.push(...elements.filter((element) => !currentElements.includes(element)));
3993
3993
  ref.timeoutId = timeoutId;
3994
3994
  }
3995
3995
  else {
@@ -4017,7 +4017,7 @@ const ZIndexTransforms = { moveUp, moveDown, moveToTop, moveToBottom };
4017
4017
 
4018
4018
  const removeElements = (board, elements) => {
4019
4019
  elements
4020
- .map(element => {
4020
+ .map((element) => {
4021
4021
  const path = PlaitBoard.findPath(board, element);
4022
4022
  const ref = board.pathRef(path);
4023
4023
  return () => {
@@ -4026,7 +4026,7 @@ const removeElements = (board, elements) => {
4026
4026
  removeSelectedElement(board, element, true);
4027
4027
  };
4028
4028
  })
4029
- .forEach(action => {
4029
+ .forEach((action) => {
4030
4030
  action();
4031
4031
  });
4032
4032
  };
@@ -4215,9 +4215,9 @@ function getRectangleByElements(board, elements, recursion) {
4215
4215
  console.error(`can not get rectangle of element:`, node);
4216
4216
  }
4217
4217
  };
4218
- elements.forEach(element => {
4218
+ elements.forEach((element) => {
4219
4219
  if (recursion) {
4220
- depthFirstRecursion(element, node => callback(node), node => board.isRecursion(node));
4220
+ depthFirstRecursion(element, (node) => callback(node), (node) => board.isRecursion(node));
4221
4221
  }
4222
4222
  else {
4223
4223
  callback(element);
@@ -4258,9 +4258,9 @@ function getElementById(board, id, dataSource) {
4258
4258
  return cachedElement;
4259
4259
  }
4260
4260
  if (!dataSource) {
4261
- dataSource = findElements(board, { match: element => true, recursion: element => true });
4261
+ dataSource = findElements(board, { match: (element) => true, recursion: (element) => true });
4262
4262
  }
4263
- let element = dataSource.find(element => element.id === id);
4263
+ let element = dataSource.find((element) => element.id === id);
4264
4264
  return element;
4265
4265
  }
4266
4266
  function getElementMap(board) {
@@ -4273,7 +4273,7 @@ function getElementMap(board) {
4273
4273
  function findElements(board, options) {
4274
4274
  let elements = [];
4275
4275
  const isReverse = options.isReverse ?? true;
4276
- depthFirstRecursion(board, node => {
4276
+ depthFirstRecursion(board, (node) => {
4277
4277
  if (!PlaitBoard.isBoard(node) && options.match(node)) {
4278
4278
  elements.push(node);
4279
4279
  }
@@ -4554,13 +4554,13 @@ const Point = {
4554
4554
  return point && otherPoint && Point.isOverHorizontal([point, otherPoint], tolerance);
4555
4555
  },
4556
4556
  isOverHorizontal(points, tolerance = 0) {
4557
- return points.every(point => Math.abs(point[1] - points[0][1]) <= tolerance);
4557
+ return points.every((point) => Math.abs(point[1] - points[0][1]) <= tolerance);
4558
4558
  },
4559
4559
  isVertical(point, otherPoint, tolerance = 0) {
4560
4560
  return point && otherPoint && Point.isOverVertical([point, otherPoint], tolerance);
4561
4561
  },
4562
4562
  isOverVertical(points, tolerance = 0) {
4563
- return points.every(point => Math.abs(point[0] - points[0][0]) <= tolerance);
4563
+ return points.every((point) => Math.abs(point[0] - points[0][0]) <= tolerance);
4564
4564
  },
4565
4565
  isAlign(points, tolerance = 0) {
4566
4566
  return Point.isOverHorizontal(points, tolerance) || Point.isOverVertical(points, tolerance);
@@ -4673,12 +4673,9 @@ class DefaultIterableDiffer {
4673
4673
  while (nextIt || nextRemove) {
4674
4674
  // Figure out which is the next record to process
4675
4675
  // Order: remove, add, move
4676
- const record = !nextRemove ||
4677
- nextIt &&
4678
- nextIt.currentIndex <
4679
- getPreviousIndex(nextRemove, addRemoveOffset, moveOffsets) ?
4680
- nextIt :
4681
- nextRemove;
4676
+ const record = !nextRemove || (nextIt && nextIt.currentIndex < getPreviousIndex(nextRemove, addRemoveOffset, moveOffsets))
4677
+ ? nextIt
4678
+ : nextRemove;
4682
4679
  const adjPreviousIndex = getPreviousIndex(record, addRemoveOffset, moveOffsets);
4683
4680
  const currentIndex = record.currentIndex;
4684
4681
  // consume the item, and adjust the addRemoveOffset and update moveDistance if necessary
@@ -4813,8 +4810,7 @@ class DefaultIterableDiffer {
4813
4810
  * changes.
4814
4811
  */
4815
4812
  get isDirty() {
4816
- return this._additionsHead !== null || this._movesHead !== null ||
4817
- this._removalsHead !== null || this._identityChangesHead !== null;
4813
+ return (this._additionsHead !== null || this._movesHead !== null || this._removalsHead !== null || this._identityChangesHead !== null);
4818
4814
  }
4819
4815
  /**
4820
4816
  * Reset the state of the change objects to show no changes. This means set previousKey to
@@ -4885,8 +4881,7 @@ class DefaultIterableDiffer {
4885
4881
  }
4886
4882
  else {
4887
4883
  // It is a new item: add it.
4888
- record =
4889
- this._addAfter(new IterableChangeRecord_(item, itemTrackBy), previousRecord, index);
4884
+ record = this._addAfter(new IterableChangeRecord_(item, itemTrackBy), previousRecord, index);
4890
4885
  }
4891
4886
  }
4892
4887
  return record;
@@ -5156,8 +5151,7 @@ class _DuplicateItemRecordList {
5156
5151
  get(trackById, atOrAfterIndex) {
5157
5152
  let record;
5158
5153
  for (record = this._head; record !== null; record = record._nextDup) {
5159
- if ((atOrAfterIndex === null || atOrAfterIndex <= record.currentIndex) &&
5160
- Object.is(record.trackById, trackById)) {
5154
+ if ((atOrAfterIndex === null || atOrAfterIndex <= record.currentIndex) && Object.is(record.trackById, trackById)) {
5161
5155
  return record;
5162
5156
  }
5163
5157
  }
@@ -5304,7 +5298,7 @@ class ListRender {
5304
5298
  currentIndexForFirstElement = record.currentIndex;
5305
5299
  }
5306
5300
  });
5307
- diffResult.forEachOperation(record => {
5301
+ diffResult.forEachOperation((record) => {
5308
5302
  // removed
5309
5303
  if (record.currentIndex === null) {
5310
5304
  const componentRef = this.instances[record.previousIndex];
@@ -5383,7 +5377,7 @@ const getContext = (board, element, index, parent, previousContext) => {
5383
5377
  board: board,
5384
5378
  selected: isSelected,
5385
5379
  index,
5386
- hasThemeChanged: !!board.operations?.find(op => op.type === 'set_theme')
5380
+ hasThemeChanged: !!board.operations?.find((op) => op.type === 'set_theme')
5387
5381
  };
5388
5382
  return context;
5389
5383
  };
@@ -5593,13 +5587,13 @@ class PlaitBoardContext {
5593
5587
  this.uploadingFiles = [];
5594
5588
  }
5595
5589
  getUploadingFile(url) {
5596
- return this.uploadingFiles.find(file => file.url === url);
5590
+ return this.uploadingFiles.find((file) => file.url === url);
5597
5591
  }
5598
5592
  setUploadingFile(file) {
5599
5593
  return this.uploadingFiles.push(file);
5600
5594
  }
5601
5595
  removeUploadingFile(fileEntry) {
5602
- this.uploadingFiles = this.uploadingFiles.filter(file => file.url !== fileEntry.url);
5596
+ this.uploadingFiles = this.uploadingFiles.filter((file) => file.url !== fileEntry.url);
5603
5597
  }
5604
5598
  }
5605
5599
 
@@ -5709,7 +5703,7 @@ function createBoard(children, options) {
5709
5703
  isRectangleHit: (element) => false,
5710
5704
  isHit: (element) => false,
5711
5705
  isInsidePoint: (element) => false,
5712
- getOneHitElement: (data) => data[0],
5706
+ getOneHitElement: (data, hitPoint) => data[0],
5713
5707
  isRecursion: (element) => true,
5714
5708
  isMovable: (element) => false,
5715
5709
  getRectangle: (element) => null,
@@ -5978,12 +5972,12 @@ const withHotkey = (board) => {
5978
5972
  if (!PlaitBoard.isReadonly(board) && options.isMultipleSelection && isHotkey('mod+a', event)) {
5979
5973
  event.preventDefault();
5980
5974
  let elements = [];
5981
- depthFirstRecursion(board, node => {
5975
+ depthFirstRecursion(board, (node) => {
5982
5976
  if (PlaitBoard.isBoard(node)) {
5983
5977
  return;
5984
5978
  }
5985
5979
  elements.push(node);
5986
- }, node => {
5980
+ }, (node) => {
5987
5981
  if (PlaitBoard.isBoard(node) || board.isRecursion(node)) {
5988
5982
  return true;
5989
5983
  }
@@ -6139,7 +6133,7 @@ function getGapLinesAndDelta(activeRectangle, snapRectangles, isHorizontal) {
6139
6133
  const axis = isHorizontal ? 'x' : 'y';
6140
6134
  const side = isHorizontal ? 'width' : 'height';
6141
6135
  const activeRectangleCenter = activeRectangle[axis] + activeRectangle[side] / 2;
6142
- snapRectangles.forEach(rec => {
6136
+ snapRectangles.forEach((rec) => {
6143
6137
  const isCross = isHorizontal ? isHorizontalCross(rec, activeRectangle) : isVerticalCross(rec, activeRectangle);
6144
6138
  if (isCross && !RectangleClient.isHit(rec, activeRectangle)) {
6145
6139
  rectangles.push(rec);
@@ -6309,7 +6303,7 @@ function withMoving(board) {
6309
6303
  hitTargetElement = getHitElementByPoint(board, point, (el) => board.isMovable(el));
6310
6304
  selectedTargetElements = getSelectedTargetElements(board);
6311
6305
  isHitSelectedTarget = hitTargetElement && selectedTargetElements.includes(hitTargetElement);
6312
- if (hitTargetElement && isHitSelectedTarget) {
6306
+ if (hitTargetElement && (isHitSelectedTarget || isHitSelectedRectangle(board, point))) {
6313
6307
  startPoint = point;
6314
6308
  pointerId = event.pointerId;
6315
6309
  activeElements = selectedTargetElements;
@@ -6545,7 +6539,7 @@ function drawPendingNodesG(board, activeElements, offsetX, offsetY) {
6545
6539
  const withOptions = (board) => {
6546
6540
  const pluginOptions = new Map();
6547
6541
  const newBoard = board;
6548
- newBoard.getPluginOptions = key => {
6542
+ newBoard.getPluginOptions = (key) => {
6549
6543
  return pluginOptions.get(key);
6550
6544
  };
6551
6545
  newBoard.setPluginOptions = (key, options) => {
@@ -6561,7 +6555,7 @@ function withRelatedFragment(board) {
6561
6555
  let relatedFragment = board.getRelatedFragment(originData || []);
6562
6556
  if (relatedFragment) {
6563
6557
  if (originData?.length) {
6564
- relatedFragment = relatedFragment.filter(item => !originData.map(element => element.id).includes(item.id));
6558
+ relatedFragment = relatedFragment.filter((item) => !originData.map((element) => element.id).includes(item.id));
6565
6559
  }
6566
6560
  if (relatedFragment.length) {
6567
6561
  const addition = {
@@ -6737,7 +6731,7 @@ function withSelection(board) {
6737
6731
  }
6738
6732
  else {
6739
6733
  if (board.selection && Selection.isCollapsed(board.selection)) {
6740
- const element = board.getOneHitElement(elements);
6734
+ const element = board.getOneHitElement(elements, board.selection.anchor);
6741
6735
  if (element) {
6742
6736
  elements = [element];
6743
6737
  }
@@ -6831,7 +6825,7 @@ const getI18nValue = (board, key, defaultValue = '') => {
6831
6825
  */
6832
6826
  const createTestingBoard = (plugins, children, options = { readonly: false, hideScrollbar: true, disabledScrollOnNonFocus: false }) => {
6833
6827
  let board = createBoard(children, options);
6834
- plugins.forEach(plugin => {
6828
+ plugins.forEach((plugin) => {
6835
6829
  board = plugin(board);
6836
6830
  });
6837
6831
  KEY_TO_ELEMENT_MAP.set(board, new Map());
@@ -6848,7 +6842,7 @@ const fakeNodeWeakMap = (object) => {
6848
6842
  };
6849
6843
  const clearNodeWeakMap = (object) => {
6850
6844
  const children = object.children || [];
6851
- children.forEach(value => {
6845
+ children.forEach((value) => {
6852
6846
  NODE_TO_PARENT.delete(value);
6853
6847
  NODE_TO_INDEX.delete(value);
6854
6848
  clearNodeWeakMap(value);