@plait/common 0.54.0 → 0.55.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 { 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';
1
+ import { PlaitGroupElement, getSelectionAngle, getElementsInGroup, setAngleForG, RectangleClient, drawCircle, PlaitBoard, RESIZE_HANDLE_CLASS_NAME, createG, setStrokeLinecap, drawRectangle, SELECTION_RECTANGLE_CLASS_NAME, 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, 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';
@@ -11,6 +11,8 @@ const RESIZE_HANDLE_DIAMETER = 9;
11
11
  const WithTextPluginKey = 'plait-text-plugin-key';
12
12
  const DEFAULT_ROUTE_MARGIN = 30;
13
13
  const TRANSPARENT = 'transparent';
14
+ const ROTATE_HANDLE_DISTANCE_TO_ELEMENT = 20;
15
+ const ROTATE_HANDLE_SIZE = 18;
14
16
 
15
17
  var MediaKeys;
16
18
  (function (MediaKeys) {
@@ -94,7 +96,9 @@ function hasAfterDraw(value) {
94
96
 
95
97
  const drawHandle = (board, centerPoint) => {
96
98
  const options = { stroke: '#99999995', strokeWidth: 2, fill: '#FFF', fillStyle: 'solid' };
97
- return drawCircle(PlaitBoard.getRoughSVG(board), centerPoint, RESIZE_HANDLE_DIAMETER, options);
99
+ const handleG = drawCircle(PlaitBoard.getRoughSVG(board), centerPoint, RESIZE_HANDLE_DIAMETER, options);
100
+ handleG.classList.add(RESIZE_HANDLE_CLASS_NAME);
101
+ return handleG;
98
102
  };
99
103
  function drawFillPrimaryHandle(board, point) {
100
104
  return drawCircle(PlaitBoard.getRoughSVG(board), point, RESIZE_HANDLE_DIAMETER, {
@@ -113,6 +117,26 @@ function drawPrimaryHandle(board, point) {
113
117
  });
114
118
  }
115
119
 
120
+ const rotateHandleRadius = 6;
121
+ const drawRotateHandle = (board, rectangle) => {
122
+ const options = { stroke: '#333', strokeWidth: 1, fillStyle: 'solid' };
123
+ const handleCenterPoint = [
124
+ rectangle.x - ROTATE_HANDLE_DISTANCE_TO_ELEMENT - ROTATE_HANDLE_SIZE / 2,
125
+ rectangle.y + rectangle.height + ROTATE_HANDLE_DISTANCE_TO_ELEMENT + ROTATE_HANDLE_SIZE / 2
126
+ ];
127
+ const rs = PlaitBoard.getRoughSVG(board);
128
+ const handleG = createG();
129
+ const line = rs.path(`M ${handleCenterPoint[0] + rotateHandleRadius} ${handleCenterPoint[1]} A ${rotateHandleRadius} ${rotateHandleRadius}, 0, 1, 0, ${handleCenterPoint[0]} ${handleCenterPoint[1] + rotateHandleRadius}`, options);
130
+ const arrow = rs.polygon([
131
+ [handleCenterPoint[0], handleCenterPoint[1] + rotateHandleRadius - 2],
132
+ [handleCenterPoint[0], handleCenterPoint[1] + rotateHandleRadius + 2],
133
+ [handleCenterPoint[0] + 4.5, handleCenterPoint[1] + rotateHandleRadius]
134
+ ], { ...options, fill: '#333' });
135
+ setStrokeLinecap(arrow, 'round');
136
+ handleG.append(line, arrow);
137
+ return handleG;
138
+ };
139
+
116
140
  class ActiveGenerator extends Generator {
117
141
  constructor(board, options) {
118
142
  super(board, options);
@@ -138,6 +162,7 @@ class ActiveGenerator extends Generator {
138
162
  strokeWidth: delta
139
163
  });
140
164
  activeG.append(strokeG);
165
+ strokeG.classList.add(SELECTION_RECTANGLE_CLASS_NAME);
141
166
  strokeG.style.opacity = `${this.options.getStrokeOpacity()}`;
142
167
  if (this.options.hasResizeHandle()) {
143
168
  this.hasResizeHandle = true;
@@ -1188,6 +1213,21 @@ const getMemorizedLatest = (memorizedKey) => {
1188
1213
  return map.get(memorizedKey);
1189
1214
  };
1190
1215
 
1216
+ const IS_ROTATING = new WeakMap();
1217
+ const isRotating = (board) => {
1218
+ return !!IS_ROTATING.get(board);
1219
+ };
1220
+ const addRotating = (board, rotateRef) => {
1221
+ PlaitBoard.getBoardContainer(board).classList.add(`draw-elements-rotating`);
1222
+ IS_ROTATING.set(board, rotateRef);
1223
+ setDragging(board, true);
1224
+ };
1225
+ const removeRotating = (board) => {
1226
+ PlaitBoard.getBoardContainer(board).classList.remove(`draw-elements-rotating`);
1227
+ IS_ROTATING.delete(board);
1228
+ setDragging(board, false);
1229
+ };
1230
+
1191
1231
  const setProperty = (board, properties, options) => {
1192
1232
  const selectedElements = getSelectedElements(board);
1193
1233
  selectedElements.forEach(element => {
@@ -1566,9 +1606,8 @@ class CommonPluginElement extends PlaitPluginElementComponent {
1566
1606
  }
1567
1607
 
1568
1608
  class GroupComponent extends CommonPluginElement {
1569
- constructor(viewContainerRef, cdr) {
1609
+ constructor(cdr) {
1570
1610
  super(cdr);
1571
- this.viewContainerRef = viewContainerRef;
1572
1611
  this.cdr = cdr;
1573
1612
  }
1574
1613
  initializeGenerator() {
@@ -1592,9 +1631,9 @@ class GroupComponent extends CommonPluginElement {
1592
1631
  const elementsInGroup = getElementsInGroup(this.board, value.element, false, true);
1593
1632
  const isPartialSelectGroup = elementsInGroup.some(item => isSelectedElementOrGroup(this.board, item)) &&
1594
1633
  !elementsInGroup.every(item => isSelectedElementOrGroup(this.board, item));
1595
- this.groupGenerator.processDrawing(value.element, this.g, isPartialSelectGroup);
1634
+ this.groupGenerator.processDrawing(value.element, this.getElementG(), isPartialSelectGroup);
1596
1635
  }
1597
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: GroupComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
1636
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: GroupComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
1598
1637
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.4", type: GroupComponent, isStandalone: true, selector: "plait-group", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1599
1638
  }
1600
1639
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: GroupComponent, decorators: [{
@@ -1605,7 +1644,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImpor
1605
1644
  changeDetection: ChangeDetectionStrategy.OnPush,
1606
1645
  standalone: true
1607
1646
  }]
1608
- }], ctorParameters: () => [{ type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }] });
1647
+ }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }] });
1609
1648
 
1610
1649
  function withGroup(board) {
1611
1650
  let groupRectangleG;
@@ -1640,24 +1679,27 @@ function withGroup(board) {
1640
1679
  const groups = getSelectedGroups(board, originData);
1641
1680
  return getRelatedFragment([...elements, ...groups], originData);
1642
1681
  };
1643
- board.insertFragment = (data, clipboardData, targetPoint) => {
1644
- const elements = [];
1682
+ board.insertFragment = (clipboardData, targetPoint) => {
1683
+ let elements = [];
1645
1684
  if (clipboardData?.elements?.length) {
1685
+ elements = new Array(clipboardData?.elements?.length);
1646
1686
  const groups = getHighestSelectedGroups(board, clipboardData?.elements);
1647
1687
  const selectedIsolatedElements = getSelectedIsolatedElements(board, clipboardData?.elements);
1648
1688
  selectedIsolatedElements.forEach(item => {
1649
- elements.push(!item.groupId ? item : updateGroupId(item, undefined));
1689
+ const index = clipboardData.elements.map(element => element.id).indexOf(item.id);
1690
+ elements.splice(index, 1, !item.groupId ? item : updateGroupId(item, undefined));
1650
1691
  });
1651
1692
  if (groups.length) {
1652
1693
  groups.forEach(item => {
1694
+ const index = clipboardData.elements.map(element => element.id).indexOf(item.id);
1653
1695
  const newGroup = { ...updateGroupId(item, undefined), id: idCreator() };
1654
- elements.push(newGroup);
1655
- elements.push(...updateElementsGroupId(item, clipboardData.elements, newGroup.id));
1696
+ elements.splice(index, 1, newGroup);
1697
+ updateElementsGroupId(item, clipboardData.elements, newGroup.id, elements);
1656
1698
  });
1657
1699
  }
1658
1700
  clipboardData.elements = elements;
1659
1701
  }
1660
- insertFragment(data, clipboardData, targetPoint);
1702
+ insertFragment(clipboardData, targetPoint);
1661
1703
  const groupElements = elements?.filter(value => PlaitGroupElement.isGroup(value));
1662
1704
  groupElements.forEach(element => {
1663
1705
  Transforms.insertNode(board, element, [board.children.length]);
@@ -1687,12 +1729,12 @@ function withGroup(board) {
1687
1729
  if (!PlaitBoard.isReadonly(board)) {
1688
1730
  if (isKeyHotkey('mod+g', event)) {
1689
1731
  event.preventDefault();
1690
- GroupTransforms.addGroup(board);
1732
+ Transforms.addGroup(board);
1691
1733
  return;
1692
1734
  }
1693
1735
  if (isKeyHotkey('mod+shift+g', event)) {
1694
1736
  event.preventDefault();
1695
- GroupTransforms.removeGroup(board);
1737
+ Transforms.removeGroup(board);
1696
1738
  return;
1697
1739
  }
1698
1740
  }
@@ -1706,26 +1748,25 @@ const updateGroupId = (element, groupId) => {
1706
1748
  groupId: groupId
1707
1749
  };
1708
1750
  };
1709
- const updateElementsGroupId = (group, clipboardDataElements, newGroupId) => {
1710
- const elements = [];
1751
+ const updateElementsGroupId = (group, clipboardDataElements, newGroupId, elements) => {
1711
1752
  const elementsInGroup = clipboardDataElements.filter(item => item.groupId === group.id);
1712
1753
  if (elementsInGroup.length) {
1713
1754
  elementsInGroup.forEach(item => {
1755
+ const index = clipboardDataElements.map(item => item.id).indexOf(item.id);
1714
1756
  if (PlaitGroupElement.isGroup(item)) {
1715
1757
  const newGroup = { ...updateGroupId(item, newGroupId), id: idCreator() };
1716
- elements.push(newGroup);
1717
- elements.push(...updateElementsGroupId(item, clipboardDataElements, newGroup.id));
1758
+ elements.splice(index, 1, newGroup);
1759
+ updateElementsGroupId(item, clipboardDataElements, newGroup.id, elements);
1718
1760
  }
1719
1761
  else {
1720
- elements.push(updateGroupId(item, newGroupId));
1762
+ elements.splice(index, 1, updateGroupId(item, newGroupId));
1721
1763
  }
1722
1764
  });
1723
1765
  }
1724
1766
  return elements;
1725
1767
  };
1726
1768
  const getRemoveGroups = (board) => {
1727
- const selectedElements = getSelectedElements(board);
1728
- const selectedGroups = board.getRelatedFragment([], selectedElements);
1769
+ const selectedGroups = board.getRelatedFragment([]);
1729
1770
  const removeGroups = [...selectedGroups];
1730
1771
  const highestSelectedGroups = getHighestSelectedGroups(board);
1731
1772
  const selectedIsolatedElements = getSelectedIsolatedElementsCanAddToGroup(board);
@@ -1891,5 +1932,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImpor
1891
1932
  * Generated bundle index. Do not edit.
1892
1933
  */
1893
1934
 
1894
- export { AStar, ActiveGenerator, AlignTransform, BASE, BoardCreationMode, CommonPluginElement, DEFAULT_ROUTE_MARGIN, Generator, IS_RESIZING, ImageBaseComponent, ImageGenerator, MediaKeys, PICTURE_ACCEPTED_UPLOAD_SIZE, PRIMARY_COLOR, PointGraph, PointNode, PriorityQueue, PropertyTransforms, RESIZE_HANDLE_DIAMETER, ResizeHandle, TRANSPARENT, TextTransforms, WithCommonPluginKey, WithTextPluginKey, acceptImageTypes, addElementOfFocusedImage, addResizing, alignBottom, alignHorizontalCenter, alignLeft, alignRight, alignTop, alignVerticalCenter, buildImage, calculatePolylineLength, createGraph, distributeHorizontal, distributeVertical, drawFillPrimaryHandle, drawHandle, drawPrimaryHandle, generateElbowLineRoute, getCreationMode, getCrossingPointsBetweenPointAndSegment, getDirectionBetweenPointAndPoint, getDirectionByPointOfRectangle, getDirectionByVector, getDirectionFactor, getDirectionFactorByDirectionComponent, getElementOfFocusedImage, getElementsText, getExtendPoint, getFirstTextEditor, getFirstTextManage, getGraphPoints, getIndexByResizeHandle, getMemorizedLatest, getNextPoint, getOppositeDirection, getPointByVectorComponent, getPointByVectorDirectionComponent, getPointOnPolyline, getPoints, getRatioByPoint, getRectangleResizeHandleRefs, getResizeHandleByIndex, getResizeHandlePointByIndex, getRotatedResizeCursorClassByAngle, getSourceAndTargetOuterRectangle, getSymmetricHandleIndex, getTextEditors, getTextManages, getTextMarksByElement, getUnitVectorByPointAndPoint, hasAfterDraw, isCornerHandle, isDelete, isDndMode, isDrawingMode, isEdgeHandle, isEnterHotkey, isExpandHotkey, isPointOnSegment, isResizing, isResizingByCondition, isSourceAndTargetIntersect, isSpaceHotkey, isTabHotkey, isVirtualKey, memorizeLatest, normalizeShapePoints, reduceRouteMargin, removeDuplicatePoints, removeElementOfFocusedImage, removeResizing, resetPointsAfterResize, rotateVector, rotateVectorAnti90, routeAdjust, selectImage, setCreationMode, setProperty, simplifyOrthogonalPoints, withGroup, withResize };
1935
+ export { AStar, ActiveGenerator, AlignTransform, BASE, BoardCreationMode, CommonPluginElement, DEFAULT_ROUTE_MARGIN, Generator, IS_RESIZING, IS_ROTATING, ImageBaseComponent, ImageGenerator, MediaKeys, PICTURE_ACCEPTED_UPLOAD_SIZE, PRIMARY_COLOR, PointGraph, PointNode, PriorityQueue, PropertyTransforms, RESIZE_HANDLE_DIAMETER, ROTATE_HANDLE_DISTANCE_TO_ELEMENT, ROTATE_HANDLE_SIZE, ResizeHandle, TRANSPARENT, TextTransforms, WithCommonPluginKey, WithTextPluginKey, acceptImageTypes, addElementOfFocusedImage, addResizing, addRotating, alignBottom, alignHorizontalCenter, alignLeft, alignRight, alignTop, alignVerticalCenter, buildImage, calculatePolylineLength, createGraph, distributeHorizontal, distributeVertical, drawFillPrimaryHandle, drawHandle, drawPrimaryHandle, drawRotateHandle, generateElbowLineRoute, getCreationMode, getCrossingPointsBetweenPointAndSegment, getDirectionBetweenPointAndPoint, getDirectionByPointOfRectangle, getDirectionByVector, getDirectionFactor, getDirectionFactorByDirectionComponent, getElementOfFocusedImage, getElementsText, getExtendPoint, getFirstTextEditor, getFirstTextManage, getGraphPoints, getIndexByResizeHandle, getMemorizedLatest, getNextPoint, getOppositeDirection, getPointByVectorComponent, getPointByVectorDirectionComponent, getPointOnPolyline, getPoints, getRatioByPoint, getRectangleResizeHandleRefs, getResizeHandleByIndex, getResizeHandlePointByIndex, getRotatedResizeCursorClassByAngle, getSourceAndTargetOuterRectangle, getSymmetricHandleIndex, getTextEditors, getTextManages, getTextMarksByElement, getUnitVectorByPointAndPoint, hasAfterDraw, isCornerHandle, isDelete, isDndMode, isDrawingMode, isEdgeHandle, isEnterHotkey, isExpandHotkey, isPointOnSegment, isResizing, isResizingByCondition, isRotating, isSourceAndTargetIntersect, isSpaceHotkey, isTabHotkey, isVirtualKey, memorizeLatest, normalizeShapePoints, reduceRouteMargin, removeDuplicatePoints, removeElementOfFocusedImage, removeResizing, removeRotating, resetPointsAfterResize, rotateVector, rotateVectorAnti90, routeAdjust, selectImage, setCreationMode, setProperty, simplifyOrthogonalPoints, withGroup, withResize };
1895
1936
  //# sourceMappingURL=plait-common.mjs.map