@plait/core 0.0.18 → 0.0.22
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/esm2020/board/board.component.mjs +23 -2
- package/esm2020/interfaces/board.mjs +1 -1
- package/esm2020/interfaces/history.mjs +3 -2
- package/esm2020/plugins/create-board.mjs +5 -2
- package/esm2020/plugins/with-board.mjs +2 -2
- package/esm2020/plugins/with-history.mjs +3 -39
- package/esm2020/plugins/with-selection.mjs +10 -9
- package/esm2020/utils/history.mjs +37 -2
- package/fesm2015/plait-core.mjs +79 -49
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +76 -49
- package/fesm2020/plait-core.mjs.map +1 -1
- package/interfaces/board.d.ts +4 -1
- package/interfaces/history.d.ts +3 -0
- package/package.json +1 -1
- package/plugins/with-history.d.ts +0 -22
- package/utils/history.d.ts +21 -1
package/fesm2020/plait-core.mjs
CHANGED
|
@@ -419,11 +419,14 @@ function createBoard(host, children, options) {
|
|
|
419
419
|
},
|
|
420
420
|
onChange: () => { },
|
|
421
421
|
mousedown: (event) => { },
|
|
422
|
-
|
|
422
|
+
globalMouseup: (event) => { },
|
|
423
423
|
mousemove: (event) => { },
|
|
424
424
|
keydown: (event) => { },
|
|
425
425
|
keyup: (event) => { },
|
|
426
426
|
dblclick: (event) => { },
|
|
427
|
+
setFragment: (data) => { },
|
|
428
|
+
insertFragment: (data) => { },
|
|
429
|
+
deleteFragment: (data) => { },
|
|
427
430
|
drawElement: (context) => [],
|
|
428
431
|
redrawElement: (context, changes) => [],
|
|
429
432
|
destroyElement: () => { }
|
|
@@ -432,7 +435,7 @@ function createBoard(host, children, options) {
|
|
|
432
435
|
}
|
|
433
436
|
|
|
434
437
|
function withBoard(board) {
|
|
435
|
-
const { onChange
|
|
438
|
+
const { onChange } = board;
|
|
436
439
|
board.onChange = () => {
|
|
437
440
|
const onContextChange = BOARD_TO_ON_CHANGE.get(board);
|
|
438
441
|
if (onContextChange) {
|
|
@@ -505,13 +508,10 @@ function isNoSelectionElement(e) {
|
|
|
505
508
|
}
|
|
506
509
|
|
|
507
510
|
function withSelection(board) {
|
|
508
|
-
const { mousedown, mousemove,
|
|
511
|
+
const { mousedown, mousemove, globalMouseup } = board;
|
|
509
512
|
let start = null;
|
|
510
513
|
let end = null;
|
|
511
514
|
board.mousedown = (event) => {
|
|
512
|
-
if (!isNoSelectionElement(event) && board.cursor === BaseCursorStatus.select) {
|
|
513
|
-
start = toPoint(event.x, event.y, board.host);
|
|
514
|
-
}
|
|
515
515
|
mousedown(event);
|
|
516
516
|
};
|
|
517
517
|
board.mousemove = (event) => {
|
|
@@ -524,9 +524,14 @@ function withSelection(board) {
|
|
|
524
524
|
}
|
|
525
525
|
mousemove(event);
|
|
526
526
|
};
|
|
527
|
-
board.
|
|
527
|
+
board.globalMouseup = (event) => {
|
|
528
528
|
if (isNoSelectionElement(event)) {
|
|
529
|
-
return
|
|
529
|
+
return globalMouseup(event);
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
if (!start && event.target instanceof Node && board.host.contains(event.target)) {
|
|
533
|
+
start = toPoint(event.x, event.y, board.host);
|
|
534
|
+
}
|
|
530
535
|
}
|
|
531
536
|
if (start) {
|
|
532
537
|
Transforms.setSelection(board, { anchor: start, focus: start });
|
|
@@ -536,7 +541,7 @@ function withSelection(board) {
|
|
|
536
541
|
}
|
|
537
542
|
start = null;
|
|
538
543
|
end = null;
|
|
539
|
-
|
|
544
|
+
globalMouseup(event);
|
|
540
545
|
};
|
|
541
546
|
return board;
|
|
542
547
|
}
|
|
@@ -628,6 +633,9 @@ const PlaitOperation = {
|
|
|
628
633
|
* Extendable Custom Types Interface
|
|
629
634
|
*/
|
|
630
635
|
|
|
636
|
+
const SAVING = new WeakMap();
|
|
637
|
+
const MERGING = new WeakMap();
|
|
638
|
+
|
|
631
639
|
const IS_IOS = typeof navigator !== 'undefined' &&
|
|
632
640
|
typeof window !== 'undefined' &&
|
|
633
641
|
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
@@ -788,7 +796,7 @@ function rotate(x1, y1, x2, y2, angle) {
|
|
|
788
796
|
* Check whether to merge an operation into the previous operation.
|
|
789
797
|
*/
|
|
790
798
|
const shouldMerge = (op, prev) => {
|
|
791
|
-
if (op.type === 'set_viewport') {
|
|
799
|
+
if (op.type === 'set_viewport' && op.type === prev?.type) {
|
|
792
800
|
return true;
|
|
793
801
|
}
|
|
794
802
|
return false;
|
|
@@ -811,6 +819,40 @@ const shouldClear = (op) => {
|
|
|
811
819
|
}
|
|
812
820
|
return true;
|
|
813
821
|
};
|
|
822
|
+
const PlaitHistoryBoard = {
|
|
823
|
+
/**
|
|
824
|
+
* Get the saving flag's current value.
|
|
825
|
+
*/
|
|
826
|
+
isSaving(board) {
|
|
827
|
+
return SAVING.get(board);
|
|
828
|
+
},
|
|
829
|
+
/**
|
|
830
|
+
* Get the merge flag's current value.
|
|
831
|
+
*/
|
|
832
|
+
isMerging(board) {
|
|
833
|
+
return MERGING.get(board);
|
|
834
|
+
},
|
|
835
|
+
/**
|
|
836
|
+
* Apply a series of changes inside a synchronous `fn`, without merging any of
|
|
837
|
+
* the new operations into previous save point in the history.
|
|
838
|
+
*/
|
|
839
|
+
withoutMerging(board, fn) {
|
|
840
|
+
const prev = PlaitHistoryBoard.isMerging(board);
|
|
841
|
+
MERGING.set(board, false);
|
|
842
|
+
fn();
|
|
843
|
+
MERGING.set(board, prev);
|
|
844
|
+
},
|
|
845
|
+
/**
|
|
846
|
+
* Apply a series of changes inside a synchronous `fn`, without saving any of
|
|
847
|
+
* their operations into the history.
|
|
848
|
+
*/
|
|
849
|
+
withoutSaving(board, fn) {
|
|
850
|
+
const prev = PlaitHistoryBoard.isSaving(board);
|
|
851
|
+
SAVING.set(board, false);
|
|
852
|
+
fn();
|
|
853
|
+
SAVING.set(board, prev);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
814
856
|
|
|
815
857
|
function withHistroy(board) {
|
|
816
858
|
const { apply, keydown } = board;
|
|
@@ -855,7 +897,7 @@ function withHistroy(board) {
|
|
|
855
897
|
save = shouldSave(op, lastOp);
|
|
856
898
|
}
|
|
857
899
|
if (save) {
|
|
858
|
-
if (merge
|
|
900
|
+
if (!merge) {
|
|
859
901
|
if (lastBatch == null) {
|
|
860
902
|
merge = false;
|
|
861
903
|
}
|
|
@@ -895,42 +937,6 @@ function withHistroy(board) {
|
|
|
895
937
|
};
|
|
896
938
|
return board;
|
|
897
939
|
}
|
|
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
940
|
|
|
935
941
|
class PlaitElementComponent {
|
|
936
942
|
constructor(renderer2, viewContainerRef) {
|
|
@@ -1071,7 +1077,7 @@ class PlaitBoardComponent {
|
|
|
1071
1077
|
fromEvent(document, 'mouseup')
|
|
1072
1078
|
.pipe(takeUntil(this.destroy$))
|
|
1073
1079
|
.subscribe((event) => {
|
|
1074
|
-
this.board.
|
|
1080
|
+
this.board.globalMouseup(event);
|
|
1075
1081
|
});
|
|
1076
1082
|
fromEvent(this.host, 'dblclick')
|
|
1077
1083
|
.pipe(takeUntil(this.destroy$))
|
|
@@ -1105,6 +1111,27 @@ class PlaitBoardComponent {
|
|
|
1105
1111
|
.subscribe((event) => {
|
|
1106
1112
|
this.board?.keyup(event);
|
|
1107
1113
|
});
|
|
1114
|
+
fromEvent(this.host, 'copy')
|
|
1115
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
1116
|
+
return !IS_TEXT_EDITABLE.get(this.board) && !!this.board.selection;
|
|
1117
|
+
}))
|
|
1118
|
+
.subscribe((event) => {
|
|
1119
|
+
this.board?.setFragment(event.clipboardData);
|
|
1120
|
+
});
|
|
1121
|
+
fromEvent(this.host, 'paste')
|
|
1122
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
1123
|
+
return !IS_TEXT_EDITABLE.get(this.board) && !!this.board.selection;
|
|
1124
|
+
}))
|
|
1125
|
+
.subscribe((event) => {
|
|
1126
|
+
this.board?.insertFragment(event.clipboardData);
|
|
1127
|
+
});
|
|
1128
|
+
fromEvent(this.host, 'cut')
|
|
1129
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
1130
|
+
return !IS_TEXT_EDITABLE.get(this.board) && !!this.board.selection;
|
|
1131
|
+
}))
|
|
1132
|
+
.subscribe((event) => {
|
|
1133
|
+
this.board?.deleteFragment(event.clipboardData);
|
|
1134
|
+
});
|
|
1108
1135
|
window.onresize = () => {
|
|
1109
1136
|
this.refreshViewport();
|
|
1110
1137
|
};
|
|
@@ -1235,5 +1262,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
1235
1262
|
* Generated bundle index. Do not edit.
|
|
1236
1263
|
*/
|
|
1237
1264
|
|
|
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 };
|
|
1265
|
+
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
1266
|
//# sourceMappingURL=plait-core.mjs.map
|