@plait/core 0.1.7 → 0.1.9
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/board/board.component.d.ts +1 -1
- package/esm2020/board/board.component.mjs +2 -2
- package/esm2020/plugins/with-hand.mjs +2 -2
- package/esm2020/plugins/with-selection.mjs +40 -37
- package/esm2020/plugins/with-viewport.mjs +7 -10
- package/esm2020/utils/common.mjs +19 -1
- package/esm2020/utils/moving-element.mjs +3 -3
- package/esm2020/utils/selected-element.mjs +3 -3
- package/esm2020/utils/viewport.mjs +6 -6
- package/fesm2015/plait-core.mjs +73 -56
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +73 -56
- package/fesm2020/plait-core.mjs.map +1 -1
- package/package.json +1 -1
- package/styles/styles.scss +1 -1
- package/utils/common.d.ts +3 -0
- package/utils/viewport.d.ts +1 -1
package/fesm2020/plait-core.mjs
CHANGED
|
@@ -928,8 +928,8 @@ const addSelectedElement = (board, element) => {
|
|
|
928
928
|
};
|
|
929
929
|
const removeSelectedElement = (board, element) => {
|
|
930
930
|
const selectedElements = getSelectedElements(board);
|
|
931
|
-
const
|
|
932
|
-
cacheSelectedElements(board,
|
|
931
|
+
const newSelectedElements = selectedElements.filter(value => value !== element);
|
|
932
|
+
cacheSelectedElements(board, newSelectedElements);
|
|
933
933
|
};
|
|
934
934
|
const isSelectedElement = (board, element) => {
|
|
935
935
|
const selectedElements = getSelectedElements(board);
|
|
@@ -997,7 +997,7 @@ function getViewportContainerRect(board) {
|
|
|
997
997
|
}
|
|
998
998
|
function getElementHostBBox(board, zoom) {
|
|
999
999
|
const childrenRect = getRectangleByElements(board, board.children, true);
|
|
1000
|
-
const viewportContainerRect =
|
|
1000
|
+
const viewportContainerRect = PlaitBoard.getBoardNativeElement(board).getBoundingClientRect();
|
|
1001
1001
|
const containerWidth = viewportContainerRect.width / zoom;
|
|
1002
1002
|
const containerHeight = viewportContainerRect.height / zoom;
|
|
1003
1003
|
let left;
|
|
@@ -1044,7 +1044,7 @@ function clampZoomLevel(zoom, minZoom = 0.2, maxZoom = 4) {
|
|
|
1044
1044
|
function getViewBox(board, zoom) {
|
|
1045
1045
|
const { hideScrollbar } = board.options;
|
|
1046
1046
|
const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
|
|
1047
|
-
const viewportContainerRect =
|
|
1047
|
+
const viewportContainerRect = PlaitBoard.getBoardNativeElement(board).getBoundingClientRect();
|
|
1048
1048
|
const elementHostBBox = getElementHostBBox(board, zoom);
|
|
1049
1049
|
const horizontalPadding = viewportContainerRect.width / 2;
|
|
1050
1050
|
const verticalPadding = viewportContainerRect.height / 2;
|
|
@@ -1078,12 +1078,12 @@ function updateViewportOffset(board) {
|
|
|
1078
1078
|
const scrollTop = (origination[1] - viewBox[1]) * zoom;
|
|
1079
1079
|
updateViewportContainerScroll(board, scrollLeft, scrollTop);
|
|
1080
1080
|
}
|
|
1081
|
-
function updateViewportContainerScroll(board, left, top) {
|
|
1081
|
+
function updateViewportContainerScroll(board, left, top, isFromViewportChange = true) {
|
|
1082
1082
|
const viewportContainer = PlaitBoard.getViewportContainer(board);
|
|
1083
1083
|
if (viewportContainer.scrollLeft !== left || viewportContainer.scrollTop !== top) {
|
|
1084
1084
|
viewportContainer.scrollLeft = left;
|
|
1085
1085
|
viewportContainer.scrollTop = top;
|
|
1086
|
-
setIsFromViewportChange(board, true);
|
|
1086
|
+
isFromViewportChange && setIsFromViewportChange(board, true);
|
|
1087
1087
|
}
|
|
1088
1088
|
}
|
|
1089
1089
|
function initializeViewportContainer(board) {
|
|
@@ -1142,7 +1142,7 @@ function fitViewport(board) {
|
|
|
1142
1142
|
const viewportContainerRect = getViewportContainerRect(board);
|
|
1143
1143
|
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
1144
1144
|
const zoom = board.viewport.zoom;
|
|
1145
|
-
const autoFitPadding =
|
|
1145
|
+
const autoFitPadding = 16;
|
|
1146
1146
|
const viewportWidth = nativeElementRect.width - 2 * autoFitPadding;
|
|
1147
1147
|
const viewportHeight = nativeElementRect.height - 2 * autoFitPadding;
|
|
1148
1148
|
let newZoom = zoom;
|
|
@@ -1204,14 +1204,31 @@ const throttleRAF = (fn) => {
|
|
|
1204
1204
|
}
|
|
1205
1205
|
scheduleFunc();
|
|
1206
1206
|
};
|
|
1207
|
+
const debounce = (func, wait, options) => {
|
|
1208
|
+
let timerSubscription = null;
|
|
1209
|
+
return () => {
|
|
1210
|
+
if (timerSubscription && !timerSubscription.closed) {
|
|
1211
|
+
timerSubscription.unsubscribe();
|
|
1212
|
+
timerSubscription = timer(wait).subscribe(() => {
|
|
1213
|
+
func();
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
if (options?.leading) {
|
|
1218
|
+
func();
|
|
1219
|
+
}
|
|
1220
|
+
timerSubscription = timer(wait).subscribe();
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
};
|
|
1207
1224
|
|
|
1208
1225
|
const getMovingElements = (board) => {
|
|
1209
1226
|
return BOARD_TO_MOVING_ELEMENT.get(board) || [];
|
|
1210
1227
|
};
|
|
1211
1228
|
const addMovingElements = (board, elements) => {
|
|
1212
1229
|
const movingElements = getMovingElements(board);
|
|
1213
|
-
const
|
|
1214
|
-
cacheMovingElements(board, [...movingElements, ...
|
|
1230
|
+
const newElements = elements.filter(item => !movingElements.find(movingElement => movingElement.key === item.key));
|
|
1231
|
+
cacheMovingElements(board, [...movingElements, ...newElements]);
|
|
1215
1232
|
};
|
|
1216
1233
|
const removeMovingElements = (board) => {
|
|
1217
1234
|
BOARD_TO_MOVING_ELEMENT.delete(board);
|
|
@@ -1414,7 +1431,7 @@ function withHandPointer(board) {
|
|
|
1414
1431
|
const viewportContainer = PlaitBoard.getViewportContainer(board);
|
|
1415
1432
|
const left = viewportContainer.scrollLeft - (event.x - plaitBoardMove.x);
|
|
1416
1433
|
const top = viewportContainer.scrollTop - (event.y - plaitBoardMove.y);
|
|
1417
|
-
updateViewportContainerScroll(board, left, top);
|
|
1434
|
+
updateViewportContainerScroll(board, left, top, false);
|
|
1418
1435
|
plaitBoardMove.x = event.x;
|
|
1419
1436
|
plaitBoardMove.y = event.y;
|
|
1420
1437
|
}
|
|
@@ -1457,25 +1474,20 @@ function withSelection(board) {
|
|
|
1457
1474
|
let selectionOuterG;
|
|
1458
1475
|
let previousSelectedElements;
|
|
1459
1476
|
board.mousedown = (event) => {
|
|
1460
|
-
if (board.pointer === PlaitPointerType.hand && board.selection) {
|
|
1461
|
-
mousedown(event);
|
|
1462
|
-
return;
|
|
1463
|
-
}
|
|
1464
1477
|
if (event.button === 0) {
|
|
1465
1478
|
start = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1466
1479
|
}
|
|
1467
1480
|
if (start) {
|
|
1468
1481
|
const ranges = [{ anchor: start, focus: start }];
|
|
1469
1482
|
const selectedElements = getSelectedElements(board);
|
|
1470
|
-
|
|
1471
|
-
if (intersectionSelectedElement) {
|
|
1483
|
+
if (isIntersectionElements(board, selectedElements, ranges)) {
|
|
1472
1484
|
start = null;
|
|
1485
|
+
mousedown(event);
|
|
1486
|
+
return;
|
|
1473
1487
|
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
start = null;
|
|
1478
|
-
}
|
|
1488
|
+
Transforms.setSelection(board, { ranges: ranges });
|
|
1489
|
+
if (calcElementIntersectionSelection(board).length || board.pointer === PlaitPointerType.hand) {
|
|
1490
|
+
start = null;
|
|
1479
1491
|
}
|
|
1480
1492
|
}
|
|
1481
1493
|
mousedown(event);
|
|
@@ -1523,36 +1535,44 @@ function withSelection(board) {
|
|
|
1523
1535
|
};
|
|
1524
1536
|
board.onChange = () => {
|
|
1525
1537
|
// calc selected elements entry
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
PlaitBoard.getHost(board).append(selectionOuterG);
|
|
1538
|
-
}
|
|
1539
|
-
deleteTemporaryElements(board);
|
|
1540
|
-
}
|
|
1541
|
-
else {
|
|
1542
|
-
const currentSelectedElements = getSelectedElements(board);
|
|
1543
|
-
if (currentSelectedElements.length && currentSelectedElements.length > 1) {
|
|
1544
|
-
const selectedElementChange = currentSelectedElements.some(item => !previousSelectedElements.includes(item));
|
|
1545
|
-
if (selectedElementChange) {
|
|
1546
|
-
selectionOuterG?.remove();
|
|
1547
|
-
selectionOuterG = createSelectionOuterG(board, currentSelectedElements);
|
|
1538
|
+
if (board.pointer !== PlaitPointerType.hand) {
|
|
1539
|
+
try {
|
|
1540
|
+
if (board.operations.find(value => value.type === 'set_selection')) {
|
|
1541
|
+
selectionOuterG?.remove();
|
|
1542
|
+
const temporaryElements = getTemporaryElements(board);
|
|
1543
|
+
const elements = temporaryElements ? temporaryElements : calcElementIntersectionSelection(board);
|
|
1544
|
+
cacheSelectedElements(board, elements);
|
|
1545
|
+
previousSelectedElements = elements;
|
|
1546
|
+
const { width, height } = getRectangleByElements(board, elements, false);
|
|
1547
|
+
if (width > 0 && height > 0 && elements.length > 1) {
|
|
1548
|
+
selectionOuterG = createSelectionOuterG(board, elements);
|
|
1548
1549
|
selectionOuterG.classList.add('selection-outer');
|
|
1549
1550
|
PlaitBoard.getHost(board).append(selectionOuterG);
|
|
1550
1551
|
}
|
|
1552
|
+
deleteTemporaryElements(board);
|
|
1553
|
+
}
|
|
1554
|
+
else {
|
|
1555
|
+
// wait node destroy and remove selected element state
|
|
1556
|
+
setTimeout(() => {
|
|
1557
|
+
const currentSelectedElements = getSelectedElements(board);
|
|
1558
|
+
if (currentSelectedElements.length && currentSelectedElements.length > 1) {
|
|
1559
|
+
const selectedElementChange = currentSelectedElements.some(item => !previousSelectedElements.includes(item));
|
|
1560
|
+
if (selectedElementChange) {
|
|
1561
|
+
selectionOuterG?.remove();
|
|
1562
|
+
selectionOuterG = createSelectionOuterG(board, currentSelectedElements);
|
|
1563
|
+
selectionOuterG.classList.add('selection-outer');
|
|
1564
|
+
PlaitBoard.getHost(board).append(selectionOuterG);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
selectionOuterG?.remove();
|
|
1569
|
+
}
|
|
1570
|
+
});
|
|
1551
1571
|
}
|
|
1552
1572
|
}
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1573
|
+
catch (error) {
|
|
1574
|
+
console.error(error);
|
|
1575
|
+
}
|
|
1556
1576
|
}
|
|
1557
1577
|
onChange();
|
|
1558
1578
|
};
|
|
@@ -1587,7 +1607,10 @@ function createSelectionOuterG(board, selectElements) {
|
|
|
1587
1607
|
|
|
1588
1608
|
function withViewport(board) {
|
|
1589
1609
|
const { onChange } = board;
|
|
1590
|
-
|
|
1610
|
+
const throttleUpdate = debounce(() => {
|
|
1611
|
+
initializeViewBox(board);
|
|
1612
|
+
updateViewportOffset(board);
|
|
1613
|
+
}, 500, { leading: true });
|
|
1591
1614
|
board.onChange = () => {
|
|
1592
1615
|
const isSetViewport = board.operations.some(op => op.type === 'set_viewport');
|
|
1593
1616
|
const isOnlySetSelection = board.operations.some(op => op.type === 'set_selection');
|
|
@@ -1603,13 +1626,7 @@ function withViewport(board) {
|
|
|
1603
1626
|
updateViewportOffset(board);
|
|
1604
1627
|
}
|
|
1605
1628
|
else {
|
|
1606
|
-
|
|
1607
|
-
timerSubscription.unsubscribe();
|
|
1608
|
-
}
|
|
1609
|
-
timerSubscription = timer(500).subscribe(() => {
|
|
1610
|
-
initializeViewBox(board);
|
|
1611
|
-
updateViewportOffset(board);
|
|
1612
|
-
});
|
|
1629
|
+
throttleUpdate();
|
|
1613
1630
|
}
|
|
1614
1631
|
onChange();
|
|
1615
1632
|
};
|
|
@@ -1873,7 +1890,7 @@ class PlaitBoardComponent {
|
|
|
1873
1890
|
this.plaitChange = new EventEmitter();
|
|
1874
1891
|
this.plaitBoardInitialized = new EventEmitter();
|
|
1875
1892
|
this.trackBy = (index, element) => {
|
|
1876
|
-
return
|
|
1893
|
+
return element.id;
|
|
1877
1894
|
};
|
|
1878
1895
|
}
|
|
1879
1896
|
ngOnInit() {
|
|
@@ -2241,5 +2258,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
|
|
|
2241
2258
|
* Generated bundle index. Do not edit.
|
|
2242
2259
|
*/
|
|
2243
2260
|
|
|
2244
|
-
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ELEMENT_TO_PLUGIN_COMPONENT, FLUSHING, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NS, Path, PlaitBoard, PlaitBoardComponent, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPointerType, PlaitToolbarComponent, Point, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, calcElementIntersectionSelection, changeZoom, clampZoomLevel, clearSelectionMoving, clearViewportOrigination, createG, createSVG, createSelectionOuterG, createText, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawArrow, drawRoundRectangle, fitViewport, getBoardRectangle, getElementHostBBox, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isFromScrolling, isFromViewportChange, isInPlaitBoard, isIntersectionElements, isNullOrUndefined, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, setViewport, shouldClear, shouldMerge, shouldSave, throttleRAF, toPoint, transformPoint, transformPoints, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withSelection };
|
|
2261
|
+
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ELEMENT_TO_PLUGIN_COMPONENT, FLUSHING, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NS, Path, PlaitBoard, PlaitBoardComponent, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPointerType, PlaitToolbarComponent, Point, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, calcElementIntersectionSelection, changeZoom, clampZoomLevel, clearSelectionMoving, clearViewportOrigination, createG, createSVG, createSelectionOuterG, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawArrow, drawRoundRectangle, fitViewport, getBoardRectangle, getElementHostBBox, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isFromScrolling, isFromViewportChange, isInPlaitBoard, isIntersectionElements, isNullOrUndefined, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, setViewport, shouldClear, shouldMerge, shouldSave, throttleRAF, toPoint, transformPoint, transformPoints, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withSelection };
|
|
2245
2262
|
//# sourceMappingURL=plait-core.mjs.map
|