@plait/common 0.54.0 → 0.55.1

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,9 +1,10 @@
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';
5
5
  import * as i0 from '@angular/core';
6
- import { Component, ChangeDetectionStrategy, Directive, Input } from '@angular/core';
6
+ import { inject, Component, ChangeDetectionStrategy, Directive, Input } from '@angular/core';
7
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
7
8
 
8
9
  const BASE = 4;
9
10
  const PRIMARY_COLOR = '#6698FF';
@@ -11,6 +12,8 @@ const RESIZE_HANDLE_DIAMETER = 9;
11
12
  const WithTextPluginKey = 'plait-text-plugin-key';
12
13
  const DEFAULT_ROUTE_MARGIN = 30;
13
14
  const TRANSPARENT = 'transparent';
15
+ const ROTATE_HANDLE_DISTANCE_TO_ELEMENT = 20;
16
+ const ROTATE_HANDLE_SIZE = 18;
14
17
 
15
18
  var MediaKeys;
16
19
  (function (MediaKeys) {
@@ -94,7 +97,9 @@ function hasAfterDraw(value) {
94
97
 
95
98
  const drawHandle = (board, centerPoint) => {
96
99
  const options = { stroke: '#99999995', strokeWidth: 2, fill: '#FFF', fillStyle: 'solid' };
97
- return drawCircle(PlaitBoard.getRoughSVG(board), centerPoint, RESIZE_HANDLE_DIAMETER, options);
100
+ const handleG = drawCircle(PlaitBoard.getRoughSVG(board), centerPoint, RESIZE_HANDLE_DIAMETER, options);
101
+ handleG.classList.add(RESIZE_HANDLE_CLASS_NAME);
102
+ return handleG;
98
103
  };
99
104
  function drawFillPrimaryHandle(board, point) {
100
105
  return drawCircle(PlaitBoard.getRoughSVG(board), point, RESIZE_HANDLE_DIAMETER, {
@@ -113,6 +118,26 @@ function drawPrimaryHandle(board, point) {
113
118
  });
114
119
  }
115
120
 
121
+ const rotateHandleRadius = 6;
122
+ const drawRotateHandle = (board, rectangle) => {
123
+ const options = { stroke: '#333', strokeWidth: 1, fillStyle: 'solid' };
124
+ const handleCenterPoint = [
125
+ rectangle.x - ROTATE_HANDLE_DISTANCE_TO_ELEMENT - ROTATE_HANDLE_SIZE / 2,
126
+ rectangle.y + rectangle.height + ROTATE_HANDLE_DISTANCE_TO_ELEMENT + ROTATE_HANDLE_SIZE / 2
127
+ ];
128
+ const rs = PlaitBoard.getRoughSVG(board);
129
+ const handleG = createG();
130
+ const line = rs.path(`M ${handleCenterPoint[0] + rotateHandleRadius} ${handleCenterPoint[1]} A ${rotateHandleRadius} ${rotateHandleRadius}, 0, 1, 0, ${handleCenterPoint[0]} ${handleCenterPoint[1] + rotateHandleRadius}`, options);
131
+ const arrow = rs.polygon([
132
+ [handleCenterPoint[0], handleCenterPoint[1] + rotateHandleRadius - 2],
133
+ [handleCenterPoint[0], handleCenterPoint[1] + rotateHandleRadius + 2],
134
+ [handleCenterPoint[0] + 4.5, handleCenterPoint[1] + rotateHandleRadius]
135
+ ], { ...options, fill: '#333' });
136
+ setStrokeLinecap(arrow, 'round');
137
+ handleG.append(line, arrow);
138
+ return handleG;
139
+ };
140
+
116
141
  class ActiveGenerator extends Generator {
117
142
  constructor(board, options) {
118
143
  super(board, options);
@@ -138,6 +163,7 @@ class ActiveGenerator extends Generator {
138
163
  strokeWidth: delta
139
164
  });
140
165
  activeG.append(strokeG);
166
+ strokeG.classList.add(SELECTION_RECTANGLE_CLASS_NAME);
141
167
  strokeG.style.opacity = `${this.options.getStrokeOpacity()}`;
142
168
  if (this.options.hasResizeHandle()) {
143
169
  this.hasResizeHandle = true;
@@ -1188,6 +1214,21 @@ const getMemorizedLatest = (memorizedKey) => {
1188
1214
  return map.get(memorizedKey);
1189
1215
  };
1190
1216
 
1217
+ const IS_ROTATING = new WeakMap();
1218
+ const isRotating = (board) => {
1219
+ return !!IS_ROTATING.get(board);
1220
+ };
1221
+ const addRotating = (board, rotateRef) => {
1222
+ PlaitBoard.getBoardContainer(board).classList.add(`draw-elements-rotating`);
1223
+ IS_ROTATING.set(board, rotateRef);
1224
+ setDragging(board, true);
1225
+ };
1226
+ const removeRotating = (board) => {
1227
+ PlaitBoard.getBoardContainer(board).classList.remove(`draw-elements-rotating`);
1228
+ IS_ROTATING.delete(board);
1229
+ setDragging(board, false);
1230
+ };
1231
+
1191
1232
  const setProperty = (board, properties, options) => {
1192
1233
  const selectedElements = getSelectedElements(board);
1193
1234
  selectedElements.forEach(element => {
@@ -1566,10 +1607,11 @@ class CommonPluginElement extends PlaitPluginElementComponent {
1566
1607
  }
1567
1608
 
1568
1609
  class GroupComponent extends CommonPluginElement {
1569
- constructor(viewContainerRef, cdr) {
1610
+ constructor(cdr, destroyRef) {
1570
1611
  super(cdr);
1571
- this.viewContainerRef = viewContainerRef;
1572
1612
  this.cdr = cdr;
1613
+ this.destroyRef = destroyRef;
1614
+ this.contextService = inject(PlaitContextService);
1573
1615
  }
1574
1616
  initializeGenerator() {
1575
1617
  this.activeGenerator = new ActiveGenerator(this.board, {
@@ -1587,14 +1629,18 @@ class GroupComponent extends CommonPluginElement {
1587
1629
  ngOnInit() {
1588
1630
  super.ngOnInit();
1589
1631
  this.initializeGenerator();
1632
+ this.contextService
1633
+ .onStable()
1634
+ .pipe(takeUntilDestroyed(this.destroyRef))
1635
+ .subscribe(() => {
1636
+ const elementsInGroup = getElementsInGroup(this.board, this.element, false, true);
1637
+ const isPartialSelectGroup = elementsInGroup.some(item => isSelectedElementOrGroup(this.board, item)) &&
1638
+ !elementsInGroup.every(item => isSelectedElementOrGroup(this.board, item));
1639
+ this.groupGenerator.processDrawing(this.element, this.getElementG(), isPartialSelectGroup);
1640
+ });
1590
1641
  }
1591
- onContextChanged(value, previous) {
1592
- const elementsInGroup = getElementsInGroup(this.board, value.element, false, true);
1593
- const isPartialSelectGroup = elementsInGroup.some(item => isSelectedElementOrGroup(this.board, item)) &&
1594
- !elementsInGroup.every(item => isSelectedElementOrGroup(this.board, item));
1595
- this.groupGenerator.processDrawing(value.element, this.g, isPartialSelectGroup);
1596
- }
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 }); }
1642
+ onContextChanged(value, previous) { }
1643
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: GroupComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.DestroyRef }], target: i0.ɵɵFactoryTarget.Component }); }
1598
1644
  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
1645
  }
1600
1646
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: GroupComponent, decorators: [{
@@ -1605,7 +1651,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImpor
1605
1651
  changeDetection: ChangeDetectionStrategy.OnPush,
1606
1652
  standalone: true
1607
1653
  }]
1608
- }], ctorParameters: () => [{ type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }] });
1654
+ }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.DestroyRef }] });
1609
1655
 
1610
1656
  function withGroup(board) {
1611
1657
  let groupRectangleG;
@@ -1640,24 +1686,27 @@ function withGroup(board) {
1640
1686
  const groups = getSelectedGroups(board, originData);
1641
1687
  return getRelatedFragment([...elements, ...groups], originData);
1642
1688
  };
1643
- board.insertFragment = (data, clipboardData, targetPoint) => {
1644
- const elements = [];
1689
+ board.insertFragment = (clipboardData, targetPoint) => {
1690
+ let elements = [];
1645
1691
  if (clipboardData?.elements?.length) {
1692
+ elements = new Array(clipboardData?.elements?.length);
1646
1693
  const groups = getHighestSelectedGroups(board, clipboardData?.elements);
1647
1694
  const selectedIsolatedElements = getSelectedIsolatedElements(board, clipboardData?.elements);
1648
1695
  selectedIsolatedElements.forEach(item => {
1649
- elements.push(!item.groupId ? item : updateGroupId(item, undefined));
1696
+ const index = clipboardData.elements.map(element => element.id).indexOf(item.id);
1697
+ elements.splice(index, 1, !item.groupId ? item : updateGroupId(item, undefined));
1650
1698
  });
1651
1699
  if (groups.length) {
1652
1700
  groups.forEach(item => {
1701
+ const index = clipboardData.elements.map(element => element.id).indexOf(item.id);
1653
1702
  const newGroup = { ...updateGroupId(item, undefined), id: idCreator() };
1654
- elements.push(newGroup);
1655
- elements.push(...updateElementsGroupId(item, clipboardData.elements, newGroup.id));
1703
+ elements.splice(index, 1, newGroup);
1704
+ updateElementsGroupId(item, clipboardData.elements, newGroup.id, elements);
1656
1705
  });
1657
1706
  }
1658
1707
  clipboardData.elements = elements;
1659
1708
  }
1660
- insertFragment(data, clipboardData, targetPoint);
1709
+ insertFragment(clipboardData, targetPoint);
1661
1710
  const groupElements = elements?.filter(value => PlaitGroupElement.isGroup(value));
1662
1711
  groupElements.forEach(element => {
1663
1712
  Transforms.insertNode(board, element, [board.children.length]);
@@ -1687,12 +1736,12 @@ function withGroup(board) {
1687
1736
  if (!PlaitBoard.isReadonly(board)) {
1688
1737
  if (isKeyHotkey('mod+g', event)) {
1689
1738
  event.preventDefault();
1690
- GroupTransforms.addGroup(board);
1739
+ Transforms.addGroup(board);
1691
1740
  return;
1692
1741
  }
1693
1742
  if (isKeyHotkey('mod+shift+g', event)) {
1694
1743
  event.preventDefault();
1695
- GroupTransforms.removeGroup(board);
1744
+ Transforms.removeGroup(board);
1696
1745
  return;
1697
1746
  }
1698
1747
  }
@@ -1706,26 +1755,25 @@ const updateGroupId = (element, groupId) => {
1706
1755
  groupId: groupId
1707
1756
  };
1708
1757
  };
1709
- const updateElementsGroupId = (group, clipboardDataElements, newGroupId) => {
1710
- const elements = [];
1758
+ const updateElementsGroupId = (group, clipboardDataElements, newGroupId, elements) => {
1711
1759
  const elementsInGroup = clipboardDataElements.filter(item => item.groupId === group.id);
1712
1760
  if (elementsInGroup.length) {
1713
1761
  elementsInGroup.forEach(item => {
1762
+ const index = clipboardDataElements.map(item => item.id).indexOf(item.id);
1714
1763
  if (PlaitGroupElement.isGroup(item)) {
1715
1764
  const newGroup = { ...updateGroupId(item, newGroupId), id: idCreator() };
1716
- elements.push(newGroup);
1717
- elements.push(...updateElementsGroupId(item, clipboardDataElements, newGroup.id));
1765
+ elements.splice(index, 1, newGroup);
1766
+ updateElementsGroupId(item, clipboardDataElements, newGroup.id, elements);
1718
1767
  }
1719
1768
  else {
1720
- elements.push(updateGroupId(item, newGroupId));
1769
+ elements.splice(index, 1, updateGroupId(item, newGroupId));
1721
1770
  }
1722
1771
  });
1723
1772
  }
1724
1773
  return elements;
1725
1774
  };
1726
1775
  const getRemoveGroups = (board) => {
1727
- const selectedElements = getSelectedElements(board);
1728
- const selectedGroups = board.getRelatedFragment([], selectedElements);
1776
+ const selectedGroups = board.getRelatedFragment([]);
1729
1777
  const removeGroups = [...selectedGroups];
1730
1778
  const highestSelectedGroups = getHighestSelectedGroups(board);
1731
1779
  const selectedIsolatedElements = getSelectedIsolatedElementsCanAddToGroup(board);
@@ -1891,5 +1939,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImpor
1891
1939
  * Generated bundle index. Do not edit.
1892
1940
  */
1893
1941
 
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 };
1942
+ 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
1943
  //# sourceMappingURL=plait-common.mjs.map