@plait/core 0.1.7 → 0.1.8

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.
@@ -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 = 8;
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,6 +1204,23 @@ 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) || [];
@@ -1539,16 +1556,22 @@ function withSelection(board) {
1539
1556
  deleteTemporaryElements(board);
1540
1557
  }
1541
1558
  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) {
1559
+ // wait node destroy and remove selected element state
1560
+ setTimeout(() => {
1561
+ const currentSelectedElements = getSelectedElements(board);
1562
+ if (currentSelectedElements.length && currentSelectedElements.length > 1) {
1563
+ const selectedElementChange = currentSelectedElements.some(item => !previousSelectedElements.includes(item));
1564
+ if (selectedElementChange) {
1565
+ selectionOuterG?.remove();
1566
+ selectionOuterG = createSelectionOuterG(board, currentSelectedElements);
1567
+ selectionOuterG.classList.add('selection-outer');
1568
+ PlaitBoard.getHost(board).append(selectionOuterG);
1569
+ }
1570
+ }
1571
+ else {
1546
1572
  selectionOuterG?.remove();
1547
- selectionOuterG = createSelectionOuterG(board, currentSelectedElements);
1548
- selectionOuterG.classList.add('selection-outer');
1549
- PlaitBoard.getHost(board).append(selectionOuterG);
1550
1573
  }
1551
- }
1574
+ });
1552
1575
  }
1553
1576
  }
1554
1577
  catch (error) {
@@ -1587,7 +1610,10 @@ function createSelectionOuterG(board, selectElements) {
1587
1610
 
1588
1611
  function withViewport(board) {
1589
1612
  const { onChange } = board;
1590
- let timerSubscription;
1613
+ const throttleUpdate = () => debounce(() => {
1614
+ initializeViewBox(board);
1615
+ updateViewportOffset(board);
1616
+ }, 500, { leading: true });
1591
1617
  board.onChange = () => {
1592
1618
  const isSetViewport = board.operations.some(op => op.type === 'set_viewport');
1593
1619
  const isOnlySetSelection = board.operations.some(op => op.type === 'set_selection');
@@ -1603,13 +1629,7 @@ function withViewport(board) {
1603
1629
  updateViewportOffset(board);
1604
1630
  }
1605
1631
  else {
1606
- if (timerSubscription) {
1607
- timerSubscription.unsubscribe();
1608
- }
1609
- timerSubscription = timer(500).subscribe(() => {
1610
- initializeViewBox(board);
1611
- updateViewportOffset(board);
1612
- });
1632
+ throttleUpdate();
1613
1633
  }
1614
1634
  onChange();
1615
1635
  };
@@ -2241,5 +2261,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2241
2261
  * Generated bundle index. Do not edit.
2242
2262
  */
2243
2263
 
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 };
2264
+ 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
2265
  //# sourceMappingURL=plait-core.mjs.map