@plait/core 0.0.4 → 0.0.7
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 +3 -1
- package/esm2020/board/board.component.mjs +35 -20
- package/esm2020/interfaces/board.mjs +1 -1
- package/esm2020/plugins/create-board.mjs +4 -3
- package/esm2020/plugins/with-selection.mjs +10 -3
- package/esm2020/utils/board.mjs +4 -1
- package/fesm2015/plait-core.mjs +71 -44
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +73 -48
- package/fesm2020/plait-core.mjs.map +1 -1
- package/interfaces/board.d.ts +4 -0
- package/package.json +1 -1
- package/plugins/create-board.d.ts +2 -2
- package/utils/board.d.ts +1 -0
package/fesm2020/plait-core.mjs
CHANGED
|
@@ -383,7 +383,7 @@ var BaseCursorStatus;
|
|
|
383
383
|
BaseCursorStatus["select"] = "select";
|
|
384
384
|
})(BaseCursorStatus || (BaseCursorStatus = {}));
|
|
385
385
|
|
|
386
|
-
function createBoard(host, children) {
|
|
386
|
+
function createBoard(host, children, options) {
|
|
387
387
|
const board = {
|
|
388
388
|
host,
|
|
389
389
|
viewport: {
|
|
@@ -394,8 +394,9 @@ function createBoard(host, children) {
|
|
|
394
394
|
},
|
|
395
395
|
children,
|
|
396
396
|
operations: [],
|
|
397
|
-
selection:
|
|
397
|
+
selection: null,
|
|
398
398
|
cursor: BaseCursorStatus.select,
|
|
399
|
+
readonly: options.readonly,
|
|
399
400
|
apply: (operation) => {
|
|
400
401
|
board.operations.push(operation);
|
|
401
402
|
Transforms.transform(board, operation);
|
|
@@ -467,16 +468,44 @@ function toRectangleClient(points) {
|
|
|
467
468
|
return rect;
|
|
468
469
|
}
|
|
469
470
|
|
|
471
|
+
function transformPoints(board, points) {
|
|
472
|
+
const newPoints = points.map(point => {
|
|
473
|
+
return transformPoint(board, point);
|
|
474
|
+
});
|
|
475
|
+
return newPoints;
|
|
476
|
+
}
|
|
477
|
+
function transformPoint(board, point) {
|
|
478
|
+
const { width, height } = board.host.getBoundingClientRect();
|
|
479
|
+
const viewBox = getViewBox(board);
|
|
480
|
+
let x = (point[0] / width) * viewBox.width + viewBox.minX;
|
|
481
|
+
let y = (point[1] / height) * viewBox.height + viewBox.minY;
|
|
482
|
+
const newPoint = [x - board.viewport.offsetX, y - board.viewport.offsetY];
|
|
483
|
+
return newPoint;
|
|
484
|
+
}
|
|
485
|
+
function getViewBox(board) {
|
|
486
|
+
const { width, height } = board.host.getBoundingClientRect();
|
|
487
|
+
const scaleWidth = (board.viewport.zoom - 1) * width;
|
|
488
|
+
const scaleHeight = (board.viewport.zoom - 1) * height;
|
|
489
|
+
const viewBoxWidth = width - scaleWidth;
|
|
490
|
+
const viewBoxHeight = height - scaleHeight;
|
|
491
|
+
const minX = scaleWidth / 2;
|
|
492
|
+
const minY = scaleHeight / 2;
|
|
493
|
+
return { minX, minY: minY, width: viewBoxWidth, height: viewBoxHeight };
|
|
494
|
+
}
|
|
495
|
+
function isNoSelectionElement(e) {
|
|
496
|
+
return e.target instanceof HTMLElement && e.target?.closest('.plait-board-attached');
|
|
497
|
+
}
|
|
498
|
+
|
|
470
499
|
function withSelection(board) {
|
|
471
500
|
const { mousedown, mousemove, mouseup } = board;
|
|
472
501
|
let start = null;
|
|
473
502
|
let end = null;
|
|
474
503
|
board.mousedown = (event) => {
|
|
475
504
|
// avoid select text when double click svg
|
|
476
|
-
if (!(event.target instanceof HTMLElement && event.target.closest('.richtext'))) {
|
|
505
|
+
if (!(event.target instanceof HTMLElement && event.target.closest('.richtext')) || isNoSelectionElement(event)) {
|
|
477
506
|
event.preventDefault();
|
|
478
507
|
}
|
|
479
|
-
if (board.cursor === BaseCursorStatus.select) {
|
|
508
|
+
if (!isNoSelectionElement(event) && board.cursor === BaseCursorStatus.select) {
|
|
480
509
|
start = toPoint(event.x, event.y, board.host);
|
|
481
510
|
}
|
|
482
511
|
mousedown(event);
|
|
@@ -492,9 +521,15 @@ function withSelection(board) {
|
|
|
492
521
|
mousemove(event);
|
|
493
522
|
};
|
|
494
523
|
board.mouseup = (event) => {
|
|
524
|
+
if (isNoSelectionElement(event)) {
|
|
525
|
+
return mouseup(event);
|
|
526
|
+
}
|
|
495
527
|
if (start) {
|
|
496
528
|
Transforms.setSelection(board, { anchor: start, focus: start });
|
|
497
529
|
}
|
|
530
|
+
else {
|
|
531
|
+
Transforms.setSelection(board, null);
|
|
532
|
+
}
|
|
498
533
|
start = null;
|
|
499
534
|
end = null;
|
|
500
535
|
mouseup(event);
|
|
@@ -509,31 +544,6 @@ const PlaitOperation = {
|
|
|
509
544
|
isSetViewportOperation
|
|
510
545
|
};
|
|
511
546
|
|
|
512
|
-
function transformPoints(board, points) {
|
|
513
|
-
const newPoints = points.map(point => {
|
|
514
|
-
return transformPoint(board, point);
|
|
515
|
-
});
|
|
516
|
-
return newPoints;
|
|
517
|
-
}
|
|
518
|
-
function transformPoint(board, point) {
|
|
519
|
-
const { width, height } = board.host.getBoundingClientRect();
|
|
520
|
-
const viewBox = getViewBox(board);
|
|
521
|
-
let x = (point[0] / width) * viewBox.width + viewBox.minX;
|
|
522
|
-
let y = (point[1] / height) * viewBox.height + viewBox.minY;
|
|
523
|
-
const newPoint = [x - board.viewport.offsetX, y - board.viewport.offsetY];
|
|
524
|
-
return newPoint;
|
|
525
|
-
}
|
|
526
|
-
function getViewBox(board) {
|
|
527
|
-
const { width, height } = board.host.getBoundingClientRect();
|
|
528
|
-
const scaleWidth = (board.viewport.zoom - 1) * width;
|
|
529
|
-
const scaleHeight = (board.viewport.zoom - 1) * height;
|
|
530
|
-
const viewBoxWidth = width - scaleWidth;
|
|
531
|
-
const viewBoxHeight = height - scaleHeight;
|
|
532
|
-
const minX = scaleWidth / 2;
|
|
533
|
-
const minY = scaleHeight / 2;
|
|
534
|
-
return { minX, minY: minY, width: viewBoxWidth, height: viewBoxHeight };
|
|
535
|
-
}
|
|
536
|
-
|
|
537
547
|
class PlaitElementComponent {
|
|
538
548
|
constructor(renderer2, viewContainerRef) {
|
|
539
549
|
this.renderer2 = renderer2;
|
|
@@ -610,6 +620,7 @@ class PlaitBoardComponent {
|
|
|
610
620
|
this.destroy$ = new Subject();
|
|
611
621
|
this.plaitValue = [];
|
|
612
622
|
this.plaitPlugins = [];
|
|
623
|
+
this.plaitReadonly = false;
|
|
613
624
|
this.plaitChange = new EventEmitter();
|
|
614
625
|
this.plaitBoardInitialized = new EventEmitter();
|
|
615
626
|
this.trackBy = (index, element) => {
|
|
@@ -619,6 +630,9 @@ class PlaitBoardComponent {
|
|
|
619
630
|
get host() {
|
|
620
631
|
return this.svg.nativeElement;
|
|
621
632
|
}
|
|
633
|
+
get isFocused() {
|
|
634
|
+
return this.board?.selection;
|
|
635
|
+
}
|
|
622
636
|
ngOnInit() {
|
|
623
637
|
const roughSVG = rough.svg(this.host, { options: { roughness: 0, strokeWidth: 1 } });
|
|
624
638
|
HOST_TO_ROUGH_SVG.set(this.host, roughSVG);
|
|
@@ -644,7 +658,8 @@ class PlaitBoardComponent {
|
|
|
644
658
|
this.plaitBoardInitialized.emit(this.board);
|
|
645
659
|
}
|
|
646
660
|
initializePlugins() {
|
|
647
|
-
|
|
661
|
+
const options = { readonly: this.plaitReadonly };
|
|
662
|
+
let board = withSelection(withBoard(createBoard(this.host, this.plaitValue, options)));
|
|
648
663
|
this.plaitPlugins.forEach(plugin => {
|
|
649
664
|
board = plugin(board);
|
|
650
665
|
});
|
|
@@ -657,7 +672,9 @@ class PlaitBoardComponent {
|
|
|
657
672
|
fromEvent(this.host, 'mousedown')
|
|
658
673
|
.pipe(takeUntil(this.destroy$))
|
|
659
674
|
.subscribe((event) => {
|
|
660
|
-
|
|
675
|
+
if (!isNoSelectionElement(event)) {
|
|
676
|
+
this.board.mousedown(event);
|
|
677
|
+
}
|
|
661
678
|
});
|
|
662
679
|
fromEvent(this.host, 'mousemove')
|
|
663
680
|
.pipe(takeUntil(this.destroy$))
|
|
@@ -667,7 +684,9 @@ class PlaitBoardComponent {
|
|
|
667
684
|
fromEvent(document, 'mouseup')
|
|
668
685
|
.pipe(takeUntil(this.destroy$))
|
|
669
686
|
.subscribe((event) => {
|
|
670
|
-
|
|
687
|
+
if (!isNoSelectionElement(event)) {
|
|
688
|
+
this.board.mouseup(event);
|
|
689
|
+
}
|
|
671
690
|
});
|
|
672
691
|
fromEvent(this.host, 'dblclick')
|
|
673
692
|
.pipe(takeUntil(this.destroy$))
|
|
@@ -677,23 +696,27 @@ class PlaitBoardComponent {
|
|
|
677
696
|
fromEvent(this.host, 'wheel')
|
|
678
697
|
.pipe(takeUntil(this.destroy$))
|
|
679
698
|
.subscribe((event) => {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
699
|
+
if (this.isFocused) {
|
|
700
|
+
event.preventDefault();
|
|
701
|
+
const viewport = this.board.viewport;
|
|
702
|
+
Transforms.setViewport(this.board, {
|
|
703
|
+
...viewport,
|
|
704
|
+
offsetX: viewport?.offsetX - event.deltaX,
|
|
705
|
+
offsetY: viewport?.offsetY - event.deltaY
|
|
706
|
+
});
|
|
707
|
+
}
|
|
687
708
|
});
|
|
688
709
|
fromEvent(document, 'keydown')
|
|
689
710
|
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
690
|
-
return !IS_TEXT_EDITABLE.get(this.board);
|
|
711
|
+
return !IS_TEXT_EDITABLE.get(this.board) && !!this.board.selection;
|
|
691
712
|
}))
|
|
692
713
|
.subscribe((event) => {
|
|
693
714
|
this.board?.keydown(event);
|
|
694
715
|
});
|
|
695
716
|
fromEvent(document, 'keyup')
|
|
696
|
-
.pipe(takeUntil(this.destroy$))
|
|
717
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
718
|
+
return !IS_TEXT_EDITABLE.get(this.board) && !!this.board.selection;
|
|
719
|
+
}))
|
|
697
720
|
.subscribe((event) => {
|
|
698
721
|
this.board?.keyup(event);
|
|
699
722
|
});
|
|
@@ -738,9 +761,9 @@ class PlaitBoardComponent {
|
|
|
738
761
|
}
|
|
739
762
|
}
|
|
740
763
|
PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
|
|
741
|
-
PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass" } }, viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }], ngImport: i0, template: `
|
|
742
|
-
<svg #svg width="100%" height="100%"></svg>
|
|
743
|
-
<div class="plait-toolbar island zoom-toolbar">
|
|
764
|
+
PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins", plaitReadonly: "plaitReadonly" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass" } }, viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }], ngImport: i0, template: `
|
|
765
|
+
<svg #svg width="100%" height="100%" style="position: relative"></svg>
|
|
766
|
+
<div *ngIf="isFocused" class="plait-toolbar island zoom-toolbar plait-board-attached">
|
|
744
767
|
<button class="item" (mousedown)="zoomOut($event)">-</button>
|
|
745
768
|
<button class="item zoom-value" (mousedown)="resetZoom($event)">{{ zoom }}%</button>
|
|
746
769
|
<button class="item" (mousedown)="zoomIn($event)">+</button>
|
|
@@ -755,14 +778,14 @@ PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", ve
|
|
|
755
778
|
[host]="host"
|
|
756
779
|
></plait-element>
|
|
757
780
|
<ng-content></ng-content>
|
|
758
|
-
`, isInline: true, components: [{ type: PlaitElementComponent, selector: "plait-element", inputs: ["index", "element", "board", "viewport", "selection", "host"] }], directives: [{ type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
781
|
+
`, isInline: true, components: [{ type: PlaitElementComponent, selector: "plait-element", inputs: ["index", "element", "board", "viewport", "selection", "host"] }], directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
759
782
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaitBoardComponent, decorators: [{
|
|
760
783
|
type: Component,
|
|
761
784
|
args: [{
|
|
762
785
|
selector: 'plait-board',
|
|
763
786
|
template: `
|
|
764
|
-
<svg #svg width="100%" height="100%"></svg>
|
|
765
|
-
<div class="plait-toolbar island zoom-toolbar">
|
|
787
|
+
<svg #svg width="100%" height="100%" style="position: relative"></svg>
|
|
788
|
+
<div *ngIf="isFocused" class="plait-toolbar island zoom-toolbar plait-board-attached">
|
|
766
789
|
<button class="item" (mousedown)="zoomOut($event)">-</button>
|
|
767
790
|
<button class="item zoom-value" (mousedown)="resetZoom($event)">{{ zoom }}%</button>
|
|
768
791
|
<button class="item" (mousedown)="zoomIn($event)">+</button>
|
|
@@ -792,6 +815,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
792
815
|
type: Input
|
|
793
816
|
}], plaitPlugins: [{
|
|
794
817
|
type: Input
|
|
818
|
+
}], plaitReadonly: [{
|
|
819
|
+
type: Input
|
|
795
820
|
}], plaitChange: [{
|
|
796
821
|
type: Output
|
|
797
822
|
}], plaitBoardInitialized: [{
|
|
@@ -980,5 +1005,5 @@ function rotate(x1, y1, x2, y2, angle) {
|
|
|
980
1005
|
* Generated bundle index. Do not edit.
|
|
981
1006
|
*/
|
|
982
1007
|
|
|
983
|
-
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, isNullOrUndefined, isSetViewportOperation, rotate, toPoint, toRectangleClient, transformPoint, transformPoints };
|
|
1008
|
+
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, isNoSelectionElement, isNullOrUndefined, isSetViewportOperation, rotate, toPoint, toRectangleClient, transformPoint, transformPoints };
|
|
984
1009
|
//# sourceMappingURL=plait-core.mjs.map
|