@plait/core 0.0.17 → 0.0.21

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.
@@ -419,7 +419,7 @@ function createBoard(host, children, options) {
419
419
  },
420
420
  onChange: () => { },
421
421
  mousedown: (event) => { },
422
- mouseup: (event) => { },
422
+ globalMouseup: (event) => { },
423
423
  mousemove: (event) => { },
424
424
  keydown: (event) => { },
425
425
  keyup: (event) => { },
@@ -432,7 +432,7 @@ function createBoard(host, children, options) {
432
432
  }
433
433
 
434
434
  function withBoard(board) {
435
- const { onChange, mouseup } = board;
435
+ const { onChange } = board;
436
436
  board.onChange = () => {
437
437
  const onContextChange = BOARD_TO_ON_CHANGE.get(board);
438
438
  if (onContextChange) {
@@ -505,13 +505,10 @@ function isNoSelectionElement(e) {
505
505
  }
506
506
 
507
507
  function withSelection(board) {
508
- const { mousedown, mousemove, mouseup } = board;
508
+ const { mousedown, mousemove, globalMouseup } = board;
509
509
  let start = null;
510
510
  let end = null;
511
511
  board.mousedown = (event) => {
512
- if (!isNoSelectionElement(event) && board.cursor === BaseCursorStatus.select) {
513
- start = toPoint(event.x, event.y, board.host);
514
- }
515
512
  mousedown(event);
516
513
  };
517
514
  board.mousemove = (event) => {
@@ -524,9 +521,14 @@ function withSelection(board) {
524
521
  }
525
522
  mousemove(event);
526
523
  };
527
- board.mouseup = (event) => {
524
+ board.globalMouseup = (event) => {
528
525
  if (isNoSelectionElement(event)) {
529
- return mouseup(event);
526
+ return globalMouseup(event);
527
+ }
528
+ else {
529
+ if (!start && event.target instanceof Node && board.host.contains(event.target)) {
530
+ start = toPoint(event.x, event.y, board.host);
531
+ }
530
532
  }
531
533
  if (start) {
532
534
  Transforms.setSelection(board, { anchor: start, focus: start });
@@ -536,7 +538,7 @@ function withSelection(board) {
536
538
  }
537
539
  start = null;
538
540
  end = null;
539
- mouseup(event);
541
+ globalMouseup(event);
540
542
  };
541
543
  return board;
542
544
  }
@@ -628,6 +630,9 @@ const PlaitOperation = {
628
630
  * Extendable Custom Types Interface
629
631
  */
630
632
 
633
+ const SAVING = new WeakMap();
634
+ const MERGING = new WeakMap();
635
+
631
636
  const IS_IOS = typeof navigator !== 'undefined' &&
632
637
  typeof window !== 'undefined' &&
633
638
  /iPad|iPhone|iPod/.test(navigator.userAgent) &&
@@ -788,7 +793,7 @@ function rotate(x1, y1, x2, y2, angle) {
788
793
  * Check whether to merge an operation into the previous operation.
789
794
  */
790
795
  const shouldMerge = (op, prev) => {
791
- if (op.type === 'set_viewport') {
796
+ if (op.type === 'set_viewport' && op.type === prev?.type) {
792
797
  return true;
793
798
  }
794
799
  return false;
@@ -811,6 +816,40 @@ const shouldClear = (op) => {
811
816
  }
812
817
  return true;
813
818
  };
819
+ const PlaitHistoryBoard = {
820
+ /**
821
+ * Get the saving flag's current value.
822
+ */
823
+ isSaving(board) {
824
+ return SAVING.get(board);
825
+ },
826
+ /**
827
+ * Get the merge flag's current value.
828
+ */
829
+ isMerging(board) {
830
+ return MERGING.get(board);
831
+ },
832
+ /**
833
+ * Apply a series of changes inside a synchronous `fn`, without merging any of
834
+ * the new operations into previous save point in the history.
835
+ */
836
+ withoutMerging(board, fn) {
837
+ const prev = PlaitHistoryBoard.isMerging(board);
838
+ MERGING.set(board, false);
839
+ fn();
840
+ MERGING.set(board, prev);
841
+ },
842
+ /**
843
+ * Apply a series of changes inside a synchronous `fn`, without saving any of
844
+ * their operations into the history.
845
+ */
846
+ withoutSaving(board, fn) {
847
+ const prev = PlaitHistoryBoard.isSaving(board);
848
+ SAVING.set(board, false);
849
+ fn();
850
+ SAVING.set(board, prev);
851
+ }
852
+ };
814
853
 
815
854
  function withHistroy(board) {
816
855
  const { apply, keydown } = board;
@@ -855,7 +894,7 @@ function withHistroy(board) {
855
894
  save = shouldSave(op, lastOp);
856
895
  }
857
896
  if (save) {
858
- if (merge == null) {
897
+ if (!merge) {
859
898
  if (lastBatch == null) {
860
899
  merge = false;
861
900
  }
@@ -895,42 +934,6 @@ function withHistroy(board) {
895
934
  };
896
935
  return board;
897
936
  }
898
- const SAVING = new WeakMap();
899
- const MERGING = new WeakMap();
900
- const PlaitHistoryBoard = {
901
- /**
902
- * Get the saving flag's current value.
903
- */
904
- isSaving(board) {
905
- return SAVING.get(board);
906
- },
907
- /**
908
- * Get the merge flag's current value.
909
- */
910
- isMerging(board) {
911
- return MERGING.get(board);
912
- },
913
- /**
914
- * Apply a series of changes inside a synchronous `fn`, without merging any of
915
- * the new operations into previous save point in the history.
916
- */
917
- withoutMerging(editor, fn) {
918
- const prev = PlaitHistoryBoard.isMerging(editor);
919
- MERGING.set(editor, false);
920
- fn();
921
- MERGING.set(editor, prev);
922
- },
923
- /**
924
- * Apply a series of changes inside a synchronous `fn`, without saving any of
925
- * their operations into the history.
926
- */
927
- withoutSaving(editor, fn) {
928
- const prev = PlaitHistoryBoard.isSaving(editor);
929
- SAVING.set(editor, false);
930
- fn();
931
- SAVING.set(editor, prev);
932
- }
933
- };
934
937
 
935
938
  class PlaitElementComponent {
936
939
  constructor(renderer2, viewContainerRef) {
@@ -1071,7 +1074,7 @@ class PlaitBoardComponent {
1071
1074
  fromEvent(document, 'mouseup')
1072
1075
  .pipe(takeUntil(this.destroy$))
1073
1076
  .subscribe((event) => {
1074
- this.board.mouseup(event);
1077
+ this.board.globalMouseup(event);
1075
1078
  });
1076
1079
  fromEvent(this.host, 'dblclick')
1077
1080
  .pipe(takeUntil(this.destroy$))
@@ -1235,5 +1238,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1235
1238
  * Generated bundle index. Do not edit.
1236
1239
  */
1237
1240
 
1238
- export { BOARD_TO_ON_CHANGE, BaseCursorStatus, FLUSHING, HOST_TO_ROUGH_SVG, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, NS, Path, PlaitBoardComponent, PlaitElementComponent, PlaitModule, PlaitNode, PlaitOperation, Transforms, Viewport, createG, createSVG, createText, distanceBetweenPointAndSegment, getViewBox, hotkeys, idCreator, inverse, isNoSelectionElement, isNullOrUndefined, isSetViewportOperation, rotate, shouldClear, shouldMerge, shouldSave, toPoint, toRectangleClient, transformPoint, transformPoints };
1241
+ export { BOARD_TO_ON_CHANGE, BaseCursorStatus, FLUSHING, HOST_TO_ROUGH_SVG, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MERGING, NS, Path, PlaitBoardComponent, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, SAVING, Transforms, Viewport, createG, createSVG, createText, distanceBetweenPointAndSegment, getViewBox, hotkeys, idCreator, inverse, isNoSelectionElement, isNullOrUndefined, isSetViewportOperation, rotate, shouldClear, shouldMerge, shouldSave, toPoint, toRectangleClient, transformPoint, transformPoints };
1239
1242
  //# sourceMappingURL=plait-core.mjs.map