@plait/common 0.52.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.
- package/core/group.component.d.ts +18 -0
- package/esm2022/core/group.component.mjs +48 -0
- package/esm2022/core/image-base.component.mjs +2 -2
- package/esm2022/generators/generator.mjs +13 -4
- package/esm2022/generators/group.generator.mjs +21 -0
- package/esm2022/generators/image.generator.mjs +6 -2
- package/esm2022/plugins/index.mjs +2 -1
- package/esm2022/plugins/with-group.mjs +190 -0
- package/esm2022/transforms/align.mjs +21 -13
- package/esm2022/utils/elbow-line-route.mjs +21 -10
- package/esm2022/utils/index.mjs +1 -2
- package/esm2022/utils/resize.mjs +20 -2
- package/esm2022/utils/vector.mjs +11 -1
- package/fesm2022/plait-common.mjs +333 -31
- package/fesm2022/plait-common.mjs.map +1 -1
- package/generators/group.generator.d.ts +6 -0
- package/package.json +1 -1
- package/plugins/index.d.ts +1 -0
- package/plugins/with-group.d.ts +2 -0
- package/utils/elbow-line-route.d.ts +3 -3
- package/utils/index.d.ts +0 -1
- package/utils/resize.d.ts +2 -0
- package/utils/vector.d.ts +1 -0
- package/esm2022/utils/rotate.mjs +0 -7
- package/utils/rotate.d.ts +0 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { setAngleForG, RectangleClient, drawCircle, PlaitBoard, createG, drawRectangle, createForeignObject, updateForeignObject, ResizeCursorClass, setDragging, distanceBetweenPointAndPoint, Point, Direction, hotkeys, PlaitElement, PlaitContextService,
|
|
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';
|
|
5
5
|
import * as i0 from '@angular/core';
|
|
6
|
-
import { Directive, Input } from '@angular/core';
|
|
6
|
+
import { Component, ChangeDetectionStrategy, Directive, Input } from '@angular/core';
|
|
7
7
|
|
|
8
8
|
const BASE = 4;
|
|
9
9
|
const PRIMARY_COLOR = '#6698FF';
|
|
@@ -54,8 +54,17 @@ class Generator {
|
|
|
54
54
|
}
|
|
55
55
|
this.g = g;
|
|
56
56
|
const rect = this.board.getRectangle(element);
|
|
57
|
-
if (rect
|
|
58
|
-
|
|
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 {
|
|
@@ -178,12 +187,16 @@ class ImageGenerator extends Generator {
|
|
|
178
187
|
updateImage(nodeG, previous, current) {
|
|
179
188
|
if (previous !== current && this.componentRef) {
|
|
180
189
|
this.componentRef.instance.imageItem = this.options.getImageItem(current);
|
|
190
|
+
this.componentRef.instance.element = current;
|
|
181
191
|
this.componentRef.instance.getRectangle = () => {
|
|
182
192
|
return this.options.getRectangle(current);
|
|
183
193
|
};
|
|
184
194
|
}
|
|
185
195
|
const currentForeignObject = this.options.getRectangle(current);
|
|
186
196
|
updateForeignObject(this.g, currentForeignObject.width, currentForeignObject.height, currentForeignObject.x, currentForeignObject.y);
|
|
197
|
+
if (currentForeignObject && current.angle) {
|
|
198
|
+
setAngleForG(this.g, RectangleClient.getCenterPoint(currentForeignObject), current.angle);
|
|
199
|
+
}
|
|
187
200
|
// solve image lose on move node
|
|
188
201
|
if (this.foreignObject.children.length === 0) {
|
|
189
202
|
this.foreignObject.append(this.componentRef.instance.nativeElement);
|
|
@@ -228,6 +241,14 @@ const getResizeCursorClassByIndex = (index) => {
|
|
|
228
241
|
return null;
|
|
229
242
|
}
|
|
230
243
|
};
|
|
244
|
+
const getRotatedResizeCursorClassByAngle = (cursor, angle) => {
|
|
245
|
+
const index = RESIZE_CURSORS.indexOf(cursor);
|
|
246
|
+
if (index >= 0) {
|
|
247
|
+
const temp = Math.round(angle / (Math.PI / 4));
|
|
248
|
+
cursor = RESIZE_CURSORS[(index + temp) % RESIZE_CURSORS.length];
|
|
249
|
+
}
|
|
250
|
+
return cursor;
|
|
251
|
+
};
|
|
231
252
|
const getRectangleResizeHandleRefs = (rectangle, diameter) => {
|
|
232
253
|
const corners = RectangleClient.getCornerPoints(rectangle);
|
|
233
254
|
const refs = corners.map((corner, index) => {
|
|
@@ -302,6 +323,16 @@ const isEdgeHandle = (board, handle) => {
|
|
|
302
323
|
const isCornerHandle = (board, handle) => {
|
|
303
324
|
return !isEdgeHandle(board, handle);
|
|
304
325
|
};
|
|
326
|
+
// 处理元素先旋转后resize导致的位置偏移
|
|
327
|
+
const resetPointsAfterResize = (originRectangle, currentRectangle, originSelectionCenterPoint, currentSelectionCenterPoint, angle) => {
|
|
328
|
+
const correctSelectionCenterPoint = rotatePoints([currentSelectionCenterPoint], originSelectionCenterPoint, angle)[0];
|
|
329
|
+
const rotatedElementCenterPoint = rotatePoints([RectangleClient.getCenterPoint(currentRectangle)], originSelectionCenterPoint, angle)[0];
|
|
330
|
+
const currentPoints = RectangleClient.getPoints(currentRectangle);
|
|
331
|
+
const originRectangleCenterPoint = RectangleClient.getCenterPoint(originRectangle);
|
|
332
|
+
const correctElementCenterPoint = rotatePoints([rotatedElementCenterPoint], correctSelectionCenterPoint, -angle)[0];
|
|
333
|
+
const rotatedPoints = rotatePoints(currentPoints, originRectangleCenterPoint, angle);
|
|
334
|
+
return rotatePoints(rotatedPoints, correctElementCenterPoint, -angle);
|
|
335
|
+
};
|
|
305
336
|
|
|
306
337
|
function getUnitVectorByPointAndPoint(point1, point2) {
|
|
307
338
|
const deltaX = point2[0] - point1[0];
|
|
@@ -335,6 +366,16 @@ function rotateVectorAnti90(vector) {
|
|
|
335
366
|
const rotatedY = -x;
|
|
336
367
|
return [rotatedX, rotatedY];
|
|
337
368
|
}
|
|
369
|
+
function rotateVector(vector, angle) {
|
|
370
|
+
if (!angle) {
|
|
371
|
+
return vector;
|
|
372
|
+
}
|
|
373
|
+
const x = vector[0];
|
|
374
|
+
const y = vector[1];
|
|
375
|
+
const rotatedX = x * Math.cos(angle) - y * Math.sin(angle);
|
|
376
|
+
const rotatedY = x * Math.sin(angle) + y * Math.cos(angle);
|
|
377
|
+
return [rotatedX, rotatedY];
|
|
378
|
+
}
|
|
338
379
|
|
|
339
380
|
function isPointOnSegment(point, startPoint, endPoint) {
|
|
340
381
|
const distanceToStart = distanceBetweenPointAndPoint(point[0], point[1], startPoint[0], startPoint[1]);
|
|
@@ -885,7 +926,8 @@ class PointGraph {
|
|
|
885
926
|
}
|
|
886
927
|
}
|
|
887
928
|
|
|
888
|
-
const
|
|
929
|
+
const debugGenerator = createDebugGenerator('debug:plait:elbow-line-routing');
|
|
930
|
+
const generateElbowLineRoute = (options, board) => {
|
|
889
931
|
const { nextSourcePoint, nextTargetPoint } = options;
|
|
890
932
|
const points = getGraphPoints(options);
|
|
891
933
|
const graph = createGraph(points);
|
|
@@ -903,15 +945,18 @@ const generateElbowLineRoute = (options) => {
|
|
|
903
945
|
const isHitY = RectangleClient.isHitY(options.sourceOuterRectangle, options.targetOuterRectangle);
|
|
904
946
|
const centerX = isHitX ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, true);
|
|
905
947
|
const centerY = isHitY ? undefined : RectangleClient.getGapCenter(options.sourceOuterRectangle, options.targetOuterRectangle, false);
|
|
906
|
-
route = routeAdjust(route, { centerX, centerY, sourceRectangle: options.sourceRectangle, targetRectangle: options.targetRectangle });
|
|
948
|
+
route = routeAdjust(route, { centerX, centerY, sourceRectangle: options.sourceRectangle, targetRectangle: options.targetRectangle }, board);
|
|
907
949
|
return route;
|
|
908
950
|
};
|
|
909
|
-
const routeAdjust = (path, options) => {
|
|
951
|
+
const routeAdjust = (path, options, board) => {
|
|
910
952
|
const { sourceRectangle, targetRectangle, centerX, centerY } = options;
|
|
953
|
+
if (board) {
|
|
954
|
+
debugGenerator.clear();
|
|
955
|
+
}
|
|
911
956
|
if (centerX !== undefined) {
|
|
912
957
|
const optionsX = getAdjustOptions(path, centerX, true);
|
|
913
958
|
const resultX = optionsX.pointOfHit &&
|
|
914
|
-
adjust(path, { parallelPaths: optionsX.parallelPaths, pointOfHit: optionsX.pointOfHit, sourceRectangle, targetRectangle });
|
|
959
|
+
adjust(path, { parallelPaths: optionsX.parallelPaths, pointOfHit: optionsX.pointOfHit, sourceRectangle, targetRectangle }, board);
|
|
915
960
|
if (resultX) {
|
|
916
961
|
path = resultX;
|
|
917
962
|
}
|
|
@@ -919,14 +964,14 @@ const routeAdjust = (path, options) => {
|
|
|
919
964
|
if (centerY !== undefined) {
|
|
920
965
|
const optionsY = getAdjustOptions(path, centerY, false);
|
|
921
966
|
const resultY = optionsY.pointOfHit &&
|
|
922
|
-
adjust(path, { parallelPaths: optionsY.parallelPaths, pointOfHit: optionsY.pointOfHit, sourceRectangle, targetRectangle });
|
|
967
|
+
adjust(path, { parallelPaths: optionsY.parallelPaths, pointOfHit: optionsY.pointOfHit, sourceRectangle, targetRectangle }, board);
|
|
923
968
|
if (resultY) {
|
|
924
969
|
path = resultY;
|
|
925
970
|
}
|
|
926
971
|
}
|
|
927
972
|
return path;
|
|
928
973
|
};
|
|
929
|
-
const adjust = (route, options) => {
|
|
974
|
+
const adjust = (route, options, board) => {
|
|
930
975
|
const { parallelPaths, pointOfHit, sourceRectangle, targetRectangle } = options;
|
|
931
976
|
let result = null;
|
|
932
977
|
parallelPaths.forEach(parallelPath => {
|
|
@@ -935,7 +980,10 @@ const adjust = (route, options) => {
|
|
|
935
980
|
// directly use getCornerPoints will bring the precision issue (eg: 263.6923375175286 - 57.130859375)
|
|
936
981
|
const tempRect = RectangleClient.getRectangleByPoints(tempRectPoints);
|
|
937
982
|
if (!RectangleClient.isHit(tempRect, sourceRectangle) && !RectangleClient.isHit(tempRect, targetRectangle)) {
|
|
938
|
-
const tempCorners = RectangleClient.
|
|
983
|
+
const tempCorners = RectangleClient.getCornerPointsByPoints(tempRectPoints);
|
|
984
|
+
if (board) {
|
|
985
|
+
debugGenerator.drawRectangle(board, tempRect);
|
|
986
|
+
}
|
|
939
987
|
const indexRangeInPath = [];
|
|
940
988
|
const indexRangeInCorner = [];
|
|
941
989
|
route.forEach((point, index) => {
|
|
@@ -950,7 +998,11 @@ const adjust = (route, options) => {
|
|
|
950
998
|
const removeLength = Math.abs(indexRangeInPath[0] - indexRangeInPath[indexRangeInPath.length - 1]) + 1;
|
|
951
999
|
newPath.splice(indexRangeInPath[0] + 1, removeLength - 2, missCorner);
|
|
952
1000
|
const turnCount = simplifyOrthogonalPoints([...route]).length - 1;
|
|
953
|
-
const
|
|
1001
|
+
const simplifyPoints = simplifyOrthogonalPoints([...newPath]);
|
|
1002
|
+
// if (board) {
|
|
1003
|
+
// debugGenerator.drawLine(board, simplifyPoints);
|
|
1004
|
+
// }
|
|
1005
|
+
const newTurnCount = simplifyPoints.length - 1;
|
|
954
1006
|
if (newTurnCount <= turnCount) {
|
|
955
1007
|
result = newPath;
|
|
956
1008
|
}
|
|
@@ -1136,12 +1188,6 @@ const getMemorizedLatest = (memorizedKey) => {
|
|
|
1136
1188
|
return map.get(memorizedKey);
|
|
1137
1189
|
};
|
|
1138
1190
|
|
|
1139
|
-
const rotatePoints = (points, centerPoint, angle) => {
|
|
1140
|
-
return points.map(point => {
|
|
1141
|
-
return rotate(point[0], point[1], centerPoint[0], centerPoint[1], angle);
|
|
1142
|
-
});
|
|
1143
|
-
};
|
|
1144
|
-
|
|
1145
1191
|
const setProperty = (board, properties, options) => {
|
|
1146
1192
|
const selectedElements = getSelectedElements(board);
|
|
1147
1193
|
selectedElements.forEach(element => {
|
|
@@ -1221,19 +1267,27 @@ const alignRight = (board) => {
|
|
|
1221
1267
|
setOffset(board, getOffset);
|
|
1222
1268
|
};
|
|
1223
1269
|
function setOffset(board, getOffset) {
|
|
1224
|
-
|
|
1225
|
-
elements = elements.filter(element => board.children.includes(element));
|
|
1270
|
+
const elements = getHighestSelectedElements(board);
|
|
1226
1271
|
const outerRectangle = getRectangleByElements(board, elements, false);
|
|
1227
1272
|
elements.forEach(element => {
|
|
1228
|
-
if (!element.points)
|
|
1273
|
+
if (!element.points && !PlaitGroupElement.isGroup(element))
|
|
1229
1274
|
return;
|
|
1230
|
-
const path = PlaitBoard.findPath(board, element);
|
|
1231
1275
|
const rectangle = board.getRectangle(element);
|
|
1232
1276
|
const offset = getOffset(outerRectangle, rectangle);
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
}
|
|
1277
|
+
let updateElements = [];
|
|
1278
|
+
if (PlaitGroupElement.isGroup(element)) {
|
|
1279
|
+
updateElements = getElementsInGroup(board, element, true, false);
|
|
1280
|
+
}
|
|
1281
|
+
else if (element.points) {
|
|
1282
|
+
updateElements = [element];
|
|
1283
|
+
}
|
|
1284
|
+
updateElements.forEach(item => {
|
|
1285
|
+
const newPoints = item.points.map(p => [p[0] + offset[0], p[1] + offset[1]]);
|
|
1286
|
+
const path = PlaitBoard.findPath(board, item);
|
|
1287
|
+
Transforms.setNode(board, {
|
|
1288
|
+
points: newPoints
|
|
1289
|
+
}, path);
|
|
1290
|
+
});
|
|
1237
1291
|
MERGING.set(board, true);
|
|
1238
1292
|
});
|
|
1239
1293
|
MERGING.set(board, false);
|
|
@@ -1247,11 +1301,11 @@ const distributeVertical = (board) => {
|
|
|
1247
1301
|
const distribute = (board, isHorizontal) => {
|
|
1248
1302
|
const axis = isHorizontal ? 'x' : 'y';
|
|
1249
1303
|
const side = isHorizontal ? 'width' : 'height';
|
|
1250
|
-
const
|
|
1251
|
-
const refs =
|
|
1304
|
+
const highestSelectedElements = getHighestSelectedElements(board);
|
|
1305
|
+
const refs = highestSelectedElements.map(element => {
|
|
1252
1306
|
return { element, rectangle: board.getRectangle(element) };
|
|
1253
1307
|
});
|
|
1254
|
-
const outerRectangle = getRectangleByElements(board,
|
|
1308
|
+
const outerRectangle = getRectangleByElements(board, highestSelectedElements, false);
|
|
1255
1309
|
const minRectangleRef = refs.sort((a, b) => a.rectangle[axis] - b.rectangle[axis])[0];
|
|
1256
1310
|
const maxRectangleRef = refs.sort((a, b) => b.rectangle[axis] + b.rectangle[side] - (a.rectangle[axis] + a.rectangle[side]))[0];
|
|
1257
1311
|
const minIndex = refs.findIndex(ref => ref === minRectangleRef);
|
|
@@ -1470,6 +1524,25 @@ const withResize = (board, options) => {
|
|
|
1470
1524
|
return board;
|
|
1471
1525
|
};
|
|
1472
1526
|
|
|
1527
|
+
class GroupGenerator extends Generator {
|
|
1528
|
+
canDraw(element) {
|
|
1529
|
+
return true;
|
|
1530
|
+
}
|
|
1531
|
+
draw(element, partialSelected) {
|
|
1532
|
+
const options = {
|
|
1533
|
+
stroke: '',
|
|
1534
|
+
strokeWidth: ACTIVE_STROKE_WIDTH,
|
|
1535
|
+
strokeLineDash: [5]
|
|
1536
|
+
};
|
|
1537
|
+
let rectangle = { x: 0, y: 0, width: 0, height: 0 };
|
|
1538
|
+
if (partialSelected) {
|
|
1539
|
+
options.stroke = '#999';
|
|
1540
|
+
rectangle = getRectangleByGroup(this.board, element, true);
|
|
1541
|
+
}
|
|
1542
|
+
return drawRectangle(this.board, rectangle, options);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1473
1546
|
class CommonPluginElement extends PlaitPluginElementComponent {
|
|
1474
1547
|
constructor() {
|
|
1475
1548
|
super(...arguments);
|
|
@@ -1492,6 +1565,235 @@ class CommonPluginElement extends PlaitPluginElementComponent {
|
|
|
1492
1565
|
}
|
|
1493
1566
|
}
|
|
1494
1567
|
|
|
1568
|
+
class GroupComponent extends CommonPluginElement {
|
|
1569
|
+
constructor(viewContainerRef, cdr) {
|
|
1570
|
+
super(cdr);
|
|
1571
|
+
this.viewContainerRef = viewContainerRef;
|
|
1572
|
+
this.cdr = cdr;
|
|
1573
|
+
}
|
|
1574
|
+
initializeGenerator() {
|
|
1575
|
+
this.activeGenerator = new ActiveGenerator(this.board, {
|
|
1576
|
+
getRectangle: (element) => {
|
|
1577
|
+
return getRectangleByGroup(this.board, element);
|
|
1578
|
+
},
|
|
1579
|
+
getStrokeWidth: () => 0,
|
|
1580
|
+
getStrokeOpacity: () => 0,
|
|
1581
|
+
hasResizeHandle: () => {
|
|
1582
|
+
return !isSelectionMoving(this.board);
|
|
1583
|
+
}
|
|
1584
|
+
});
|
|
1585
|
+
this.groupGenerator = new GroupGenerator(this.board);
|
|
1586
|
+
}
|
|
1587
|
+
ngOnInit() {
|
|
1588
|
+
super.ngOnInit();
|
|
1589
|
+
this.initializeGenerator();
|
|
1590
|
+
}
|
|
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 }); }
|
|
1598
|
+
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
|
+
}
|
|
1600
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: GroupComponent, decorators: [{
|
|
1601
|
+
type: Component,
|
|
1602
|
+
args: [{
|
|
1603
|
+
selector: 'plait-group',
|
|
1604
|
+
template: ``,
|
|
1605
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
1606
|
+
standalone: true
|
|
1607
|
+
}]
|
|
1608
|
+
}], ctorParameters: () => [{ type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }] });
|
|
1609
|
+
|
|
1610
|
+
function withGroup(board) {
|
|
1611
|
+
let groupRectangleG;
|
|
1612
|
+
let removeGroups;
|
|
1613
|
+
const { drawElement, pointerMove, globalPointerUp, insertFragment, getDeletedFragment, deleteFragment, getRelatedFragment, getRectangle, keyDown } = board;
|
|
1614
|
+
board.drawElement = (context) => {
|
|
1615
|
+
if (PlaitGroupElement.isGroup(context.element)) {
|
|
1616
|
+
return GroupComponent;
|
|
1617
|
+
}
|
|
1618
|
+
return drawElement(context);
|
|
1619
|
+
};
|
|
1620
|
+
board.pointerMove = (event) => {
|
|
1621
|
+
groupRectangleG?.remove();
|
|
1622
|
+
const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
|
|
1623
|
+
let selection = { anchor: point, focus: point };
|
|
1624
|
+
if (board.selection && !Selection.isCollapsed(board.selection)) {
|
|
1625
|
+
selection = board.selection;
|
|
1626
|
+
}
|
|
1627
|
+
const hitElements = getHitElementsBySelection(board, selection);
|
|
1628
|
+
if (hitElements.length) {
|
|
1629
|
+
groupRectangleG = createGroupRectangleG(board, hitElements);
|
|
1630
|
+
groupRectangleG && PlaitBoard.getElementActiveHost(board).append(groupRectangleG);
|
|
1631
|
+
}
|
|
1632
|
+
pointerMove(event);
|
|
1633
|
+
};
|
|
1634
|
+
board.globalPointerUp = (event) => {
|
|
1635
|
+
groupRectangleG?.remove();
|
|
1636
|
+
groupRectangleG = null;
|
|
1637
|
+
globalPointerUp(event);
|
|
1638
|
+
};
|
|
1639
|
+
board.getRelatedFragment = (elements, originData) => {
|
|
1640
|
+
const groups = getSelectedGroups(board, originData);
|
|
1641
|
+
return getRelatedFragment([...elements, ...groups], originData);
|
|
1642
|
+
};
|
|
1643
|
+
board.insertFragment = (data, clipboardData, targetPoint) => {
|
|
1644
|
+
const elements = [];
|
|
1645
|
+
if (clipboardData?.elements?.length) {
|
|
1646
|
+
const groups = getHighestSelectedGroups(board, clipboardData?.elements);
|
|
1647
|
+
const selectedIsolatedElements = getSelectedIsolatedElements(board, clipboardData?.elements);
|
|
1648
|
+
selectedIsolatedElements.forEach(item => {
|
|
1649
|
+
elements.push(!item.groupId ? item : updateGroupId(item, undefined));
|
|
1650
|
+
});
|
|
1651
|
+
if (groups.length) {
|
|
1652
|
+
groups.forEach(item => {
|
|
1653
|
+
const newGroup = { ...updateGroupId(item, undefined), id: idCreator() };
|
|
1654
|
+
elements.push(newGroup);
|
|
1655
|
+
elements.push(...updateElementsGroupId(item, clipboardData.elements, newGroup.id));
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
clipboardData.elements = elements;
|
|
1659
|
+
}
|
|
1660
|
+
insertFragment(data, clipboardData, targetPoint);
|
|
1661
|
+
const groupElements = elements?.filter(value => PlaitGroupElement.isGroup(value));
|
|
1662
|
+
groupElements.forEach(element => {
|
|
1663
|
+
Transforms.insertNode(board, element, [board.children.length]);
|
|
1664
|
+
});
|
|
1665
|
+
};
|
|
1666
|
+
board.getDeletedFragment = (data) => {
|
|
1667
|
+
removeGroups = getRemoveGroups(board);
|
|
1668
|
+
if (removeGroups && removeGroups.length) {
|
|
1669
|
+
data.push(...removeGroups);
|
|
1670
|
+
}
|
|
1671
|
+
return getDeletedFragment(data);
|
|
1672
|
+
};
|
|
1673
|
+
board.deleteFragment = (elements) => {
|
|
1674
|
+
if (removeGroups?.length) {
|
|
1675
|
+
updateSiblingElementGroupId(board, removeGroups);
|
|
1676
|
+
}
|
|
1677
|
+
deleteFragment(elements);
|
|
1678
|
+
removeGroups = null;
|
|
1679
|
+
};
|
|
1680
|
+
board.getRectangle = (element) => {
|
|
1681
|
+
if (PlaitGroupElement.isGroup(element)) {
|
|
1682
|
+
return getRectangleByGroup(board, element, true);
|
|
1683
|
+
}
|
|
1684
|
+
return getRectangle(element);
|
|
1685
|
+
};
|
|
1686
|
+
board.keyDown = (event) => {
|
|
1687
|
+
if (!PlaitBoard.isReadonly(board)) {
|
|
1688
|
+
if (isKeyHotkey('mod+g', event)) {
|
|
1689
|
+
event.preventDefault();
|
|
1690
|
+
GroupTransforms.addGroup(board);
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
if (isKeyHotkey('mod+shift+g', event)) {
|
|
1694
|
+
event.preventDefault();
|
|
1695
|
+
GroupTransforms.removeGroup(board);
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
keyDown(event);
|
|
1700
|
+
};
|
|
1701
|
+
return board;
|
|
1702
|
+
}
|
|
1703
|
+
const updateGroupId = (element, groupId) => {
|
|
1704
|
+
return {
|
|
1705
|
+
...element,
|
|
1706
|
+
groupId: groupId
|
|
1707
|
+
};
|
|
1708
|
+
};
|
|
1709
|
+
const updateElementsGroupId = (group, clipboardDataElements, newGroupId) => {
|
|
1710
|
+
const elements = [];
|
|
1711
|
+
const elementsInGroup = clipboardDataElements.filter(item => item.groupId === group.id);
|
|
1712
|
+
if (elementsInGroup.length) {
|
|
1713
|
+
elementsInGroup.forEach(item => {
|
|
1714
|
+
if (PlaitGroupElement.isGroup(item)) {
|
|
1715
|
+
const newGroup = { ...updateGroupId(item, newGroupId), id: idCreator() };
|
|
1716
|
+
elements.push(newGroup);
|
|
1717
|
+
elements.push(...updateElementsGroupId(item, clipboardDataElements, newGroup.id));
|
|
1718
|
+
}
|
|
1719
|
+
else {
|
|
1720
|
+
elements.push(updateGroupId(item, newGroupId));
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
return elements;
|
|
1725
|
+
};
|
|
1726
|
+
const getRemoveGroups = (board) => {
|
|
1727
|
+
const selectedElements = getSelectedElements(board);
|
|
1728
|
+
const selectedGroups = board.getRelatedFragment([], selectedElements);
|
|
1729
|
+
const removeGroups = [...selectedGroups];
|
|
1730
|
+
const highestSelectedGroups = getHighestSelectedGroups(board);
|
|
1731
|
+
const selectedIsolatedElements = getSelectedIsolatedElementsCanAddToGroup(board);
|
|
1732
|
+
const removeNodes = [...highestSelectedGroups, ...selectedIsolatedElements];
|
|
1733
|
+
removeNodes.forEach(item => {
|
|
1734
|
+
const hitElementGroups = getGroupByElement(board, item, true);
|
|
1735
|
+
if (hitElementGroups.length) {
|
|
1736
|
+
const elementsInGroup = getElementsInGroup(board, hitElementGroups[0], false, true);
|
|
1737
|
+
const siblingElements = elementsInGroup.filter(element => ![...removeNodes, ...removeGroups].map(item => item.id).includes(element.id));
|
|
1738
|
+
if (siblingElements.length === 1 || siblingElements.length === 0) {
|
|
1739
|
+
if (!removeGroups.includes(hitElementGroups[0])) {
|
|
1740
|
+
removeGroups.push(hitElementGroups[0]);
|
|
1741
|
+
}
|
|
1742
|
+
if (siblingElements.length === 1) {
|
|
1743
|
+
if (hitElementGroups.length > 1) {
|
|
1744
|
+
const aboveGroup = findAboveGroupWithAnotherElement(board, hitElementGroups.slice(1, hitElementGroups.length), [
|
|
1745
|
+
...removeNodes,
|
|
1746
|
+
...removeGroups
|
|
1747
|
+
]);
|
|
1748
|
+
let index = hitElementGroups.length;
|
|
1749
|
+
if (aboveGroup) {
|
|
1750
|
+
index = hitElementGroups.findIndex(item => item.id === aboveGroup.id);
|
|
1751
|
+
}
|
|
1752
|
+
[...hitElementGroups.slice(1, index)].forEach(item => {
|
|
1753
|
+
if (!removeGroups.includes(item)) {
|
|
1754
|
+
removeGroups.push(item);
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
return removeGroups;
|
|
1763
|
+
};
|
|
1764
|
+
const findAboveGroupWithAnotherElement = (board, groups, excludeNodes) => {
|
|
1765
|
+
let group = null;
|
|
1766
|
+
for (let i = 0; i < groups.length; i++) {
|
|
1767
|
+
const elementsInGroup = getElementsInGroup(board, groups[i], false, true);
|
|
1768
|
+
const siblingElements = elementsInGroup.filter(element => !excludeNodes.map(item => item.id).includes(element.id));
|
|
1769
|
+
if (siblingElements.length > 0) {
|
|
1770
|
+
group = groups[i];
|
|
1771
|
+
break;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return group;
|
|
1775
|
+
};
|
|
1776
|
+
const updateSiblingElementGroupId = (board, removeGroups) => {
|
|
1777
|
+
const selectedIsolatedElements = getSelectedIsolatedElementsCanAddToGroup(board);
|
|
1778
|
+
const highestSelectedGroups = getHighestSelectedGroups(board);
|
|
1779
|
+
const isolatedElementsInGroup = selectedIsolatedElements.filter(item => item.groupId);
|
|
1780
|
+
[...highestSelectedGroups, ...isolatedElementsInGroup].forEach(item => {
|
|
1781
|
+
const hitElementGroups = getGroupByElement(board, item, true);
|
|
1782
|
+
if (hitElementGroups.length) {
|
|
1783
|
+
const elementsInGroup = getElementsInGroup(board, hitElementGroups[0], false, true);
|
|
1784
|
+
const siblingElements = elementsInGroup.filter(element => element.id !== item.id);
|
|
1785
|
+
if (siblingElements.length === 1) {
|
|
1786
|
+
const removeGroupIds = removeGroups.map(item => item.id);
|
|
1787
|
+
if (hitElementGroups.some(group => removeGroupIds.includes(group.id))) {
|
|
1788
|
+
const group = hitElementGroups.find(group => !removeGroupIds.includes(group.id));
|
|
1789
|
+
const path = PlaitBoard.findPath(board, siblingElements[0]);
|
|
1790
|
+
Transforms.setNode(board, { groupId: group?.id || undefined }, path);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
};
|
|
1796
|
+
|
|
1495
1797
|
class ImageBaseComponent {
|
|
1496
1798
|
set imageItem(value) {
|
|
1497
1799
|
this.afterImageItemChange(this._imageItem, value);
|
|
@@ -1549,7 +1851,7 @@ class ImageBaseComponent {
|
|
|
1549
1851
|
drawFocus() {
|
|
1550
1852
|
if (this.initialized) {
|
|
1551
1853
|
const activeG = PlaitBoard.getElementActiveHost(this.board);
|
|
1552
|
-
this.activeGenerator.processDrawing(
|
|
1854
|
+
this.activeGenerator.processDrawing(this.element, activeG, { selected: this._isFocus });
|
|
1553
1855
|
}
|
|
1554
1856
|
}
|
|
1555
1857
|
ngOnDestroy() {
|
|
@@ -1589,5 +1891,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImpor
|
|
|
1589
1891
|
* Generated bundle index. Do not edit.
|
|
1590
1892
|
*/
|
|
1591
1893
|
|
|
1592
|
-
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, 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,
|
|
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 };
|
|
1593
1895
|
//# sourceMappingURL=plait-common.mjs.map
|