@plait/core 0.1.0 → 0.1.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.
@@ -355,13 +355,33 @@ const NodeTransforms = {
355
355
  moveNode
356
356
  };
357
357
 
358
+ // record richtext type status
359
+ const FLUSHING = new WeakMap();
360
+ const IS_TEXT_EDITABLE = new WeakMap();
361
+ const BOARD_TO_ON_CHANGE = new WeakMap();
362
+ const BOARD_TO_COMPONENT = new WeakMap();
363
+ const BOARD_TO_ROUGH_SVG = new WeakMap();
364
+ const BOARD_TO_HOST = new WeakMap();
365
+ const BOARD_TO_ELEMENT_HOST = new WeakMap();
366
+ const BOARD_TO_SELECTED_ELEMENT = new WeakMap();
367
+ const BOARD_TO_MOVING_POINT = new WeakMap();
368
+ // save no standard selected elements
369
+ const BOARD_TO_TEMPORARY_ELEMENTS = new WeakMap();
370
+
358
371
  function setSelection(board, selection) {
359
372
  const operation = { type: 'set_selection', properties: board.selection, newProperties: selection };
360
373
  board.apply(operation);
361
374
  }
362
375
  const SelectionTransforms = {
363
- setSelection
376
+ setSelection,
377
+ setSelectionWithTemporaryElements
364
378
  };
379
+ function setSelectionWithTemporaryElements(board, elements) {
380
+ setTimeout(() => {
381
+ BOARD_TO_TEMPORARY_ELEMENTS.set(board, elements);
382
+ setSelection(board, { ranges: [] });
383
+ });
384
+ }
365
385
 
366
386
  function setViewport(board, viewport) {
367
387
  const operation = { type: 'set_viewport', properties: board.viewport, newProperties: viewport };
@@ -371,17 +391,6 @@ const ViewportTransforms = {
371
391
  setViewport
372
392
  };
373
393
 
374
- // record richtext type status
375
- const FLUSHING = new WeakMap();
376
- const IS_TEXT_EDITABLE = new WeakMap();
377
- const BOARD_TO_ON_CHANGE = new WeakMap();
378
- const BOARD_TO_COMPONENT = new WeakMap();
379
- const BOARD_TO_ROUGH_SVG = new WeakMap();
380
- const BOARD_TO_HOST = new WeakMap();
381
- const BOARD_TO_ELEMENT_HOST = new WeakMap();
382
- const BOARD_TO_SELECTED_ELEMENT = new WeakMap();
383
- const BOARD_TO_MOVING_POINT = new WeakMap();
384
-
385
394
  function depthFirstRecursion(node, callback) {
386
395
  node.children?.forEach(child => {
387
396
  depthFirstRecursion(child, callback);
@@ -1353,8 +1362,8 @@ function withSelection(board) {
1353
1362
  const { x, y, width, height } = RectangleClient.toRectangleClient([start, movedTarget]);
1354
1363
  if (Math.hypot(width, height) > 5) {
1355
1364
  end = movedTarget;
1356
- if (movedTarget) {
1357
- Transforms.setSelection(board, { ranges: [{ anchor: start, focus: start }] });
1365
+ if (end) {
1366
+ Transforms.setSelection(board, { ranges: [{ anchor: start, focus: end }] });
1358
1367
  }
1359
1368
  PlaitBoard.getBoardNativeElement(board).classList.add('selection-moving');
1360
1369
  selectionMovingG?.remove();
@@ -1383,11 +1392,13 @@ function withSelection(board) {
1383
1392
  // calc selected elements entry
1384
1393
  try {
1385
1394
  if (board.operations.find(value => value.type === 'set_selection')) {
1386
- const elementIds = calcElementIntersectionSelection(board);
1387
- cacheSelectedElements(board, elementIds);
1388
- const { x, y, width, height } = getRectangleByElements(board, elementIds, false);
1395
+ const temporaryElements = getTemporaryElements(board);
1396
+ const elements = temporaryElements ? temporaryElements : calcElementIntersectionSelection(board);
1397
+ cacheSelectedElements(board, elements);
1398
+ const { x, y, width, height } = getRectangleByElements(board, elements, false);
1389
1399
  if (width > 0 && height > 0) {
1390
1400
  const rough = PlaitBoard.getRoughSVG(board);
1401
+ selectionOuterG?.remove();
1391
1402
  selectionOuterG = rough.rectangle(x - 2, y - 2, width + 4, height + 4, {
1392
1403
  stroke: SELECTION_BORDER_COLOR,
1393
1404
  strokeWidth: 1,
@@ -1396,6 +1407,7 @@ function withSelection(board) {
1396
1407
  PlaitBoard.getHost(board).append(selectionOuterG);
1397
1408
  }
1398
1409
  }
1410
+ deleteTemporaryElements(board);
1399
1411
  }
1400
1412
  catch (error) {
1401
1413
  console.error(error);
@@ -1404,6 +1416,12 @@ function withSelection(board) {
1404
1416
  };
1405
1417
  return board;
1406
1418
  }
1419
+ function getTemporaryElements(board) {
1420
+ return BOARD_TO_TEMPORARY_ELEMENTS.get(board);
1421
+ }
1422
+ function deleteTemporaryElements(board) {
1423
+ BOARD_TO_TEMPORARY_ELEMENTS.delete(board);
1424
+ }
1407
1425
 
1408
1426
  class PlaitElementComponent {
1409
1427
  constructor(renderer2, viewContainerRef) {
@@ -2137,5 +2155,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
2137
2155
  * Generated bundle index. Do not edit.
2138
2156
  */
2139
2157
 
2140
- export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, 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, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addSelectedElement, arrowPoints, cacheSelectedElements, calcElementIntersectionSelection, clampZoomLevel, convertToViewportCoordinates, createG, createSVG, createText, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawArrow, drawRoundRectangle, getBoardClientBox, getBoardRectangle, getRectangleByElements, getRootGroupBBox, getSelectedElements, getViewportContainerBox, hasBeforeContextChange, hotkeys, idCreator, inverse, invertMatrix, invertViewportCoordinates, isNoSelectionElement, isNullOrUndefined, isSelectedElement, isSetViewportOperation, normalizePoint, removeSelectedElement, rotate, shouldClear, shouldMerge, shouldSave, toPoint, transformMat3, transformPoint, transformPoints };
2158
+ export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, 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, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addSelectedElement, arrowPoints, cacheSelectedElements, calcElementIntersectionSelection, clampZoomLevel, convertToViewportCoordinates, createG, createSVG, createText, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawArrow, drawRoundRectangle, getBoardClientBox, getBoardRectangle, getRectangleByElements, getRootGroupBBox, getSelectedElements, getTemporaryElements, getViewportContainerBox, hasBeforeContextChange, hotkeys, idCreator, inverse, invertMatrix, invertViewportCoordinates, isNoSelectionElement, isNullOrUndefined, isSelectedElement, isSetViewportOperation, normalizePoint, removeSelectedElement, rotate, shouldClear, shouldMerge, shouldSave, toPoint, transformMat3, transformPoint, transformPoints, withSelection };
2141
2159
  //# sourceMappingURL=plait-core.mjs.map