@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/fesm2015/plait-core.mjs
CHANGED
|
@@ -379,7 +379,7 @@ var BaseCursorStatus;
|
|
|
379
379
|
BaseCursorStatus["select"] = "select";
|
|
380
380
|
})(BaseCursorStatus || (BaseCursorStatus = {}));
|
|
381
381
|
|
|
382
|
-
function createBoard(host, children) {
|
|
382
|
+
function createBoard(host, children, options) {
|
|
383
383
|
const board = {
|
|
384
384
|
host,
|
|
385
385
|
viewport: {
|
|
@@ -390,8 +390,9 @@ function createBoard(host, children) {
|
|
|
390
390
|
},
|
|
391
391
|
children,
|
|
392
392
|
operations: [],
|
|
393
|
-
selection:
|
|
393
|
+
selection: null,
|
|
394
394
|
cursor: BaseCursorStatus.select,
|
|
395
|
+
readonly: options.readonly,
|
|
395
396
|
apply: (operation) => {
|
|
396
397
|
board.operations.push(operation);
|
|
397
398
|
Transforms.transform(board, operation);
|
|
@@ -463,16 +464,45 @@ function toRectangleClient(points) {
|
|
|
463
464
|
return rect;
|
|
464
465
|
}
|
|
465
466
|
|
|
467
|
+
function transformPoints(board, points) {
|
|
468
|
+
const newPoints = points.map(point => {
|
|
469
|
+
return transformPoint(board, point);
|
|
470
|
+
});
|
|
471
|
+
return newPoints;
|
|
472
|
+
}
|
|
473
|
+
function transformPoint(board, point) {
|
|
474
|
+
const { width, height } = board.host.getBoundingClientRect();
|
|
475
|
+
const viewBox = getViewBox(board);
|
|
476
|
+
let x = (point[0] / width) * viewBox.width + viewBox.minX;
|
|
477
|
+
let y = (point[1] / height) * viewBox.height + viewBox.minY;
|
|
478
|
+
const newPoint = [x - board.viewport.offsetX, y - board.viewport.offsetY];
|
|
479
|
+
return newPoint;
|
|
480
|
+
}
|
|
481
|
+
function getViewBox(board) {
|
|
482
|
+
const { width, height } = board.host.getBoundingClientRect();
|
|
483
|
+
const scaleWidth = (board.viewport.zoom - 1) * width;
|
|
484
|
+
const scaleHeight = (board.viewport.zoom - 1) * height;
|
|
485
|
+
const viewBoxWidth = width - scaleWidth;
|
|
486
|
+
const viewBoxHeight = height - scaleHeight;
|
|
487
|
+
const minX = scaleWidth / 2;
|
|
488
|
+
const minY = scaleHeight / 2;
|
|
489
|
+
return { minX, minY: minY, width: viewBoxWidth, height: viewBoxHeight };
|
|
490
|
+
}
|
|
491
|
+
function isNoSelectionElement(e) {
|
|
492
|
+
var _a;
|
|
493
|
+
return e.target instanceof HTMLElement && ((_a = e.target) === null || _a === void 0 ? void 0 : _a.closest('.plait-board-attached'));
|
|
494
|
+
}
|
|
495
|
+
|
|
466
496
|
function withSelection(board) {
|
|
467
497
|
const { mousedown, mousemove, mouseup } = board;
|
|
468
498
|
let start = null;
|
|
469
499
|
let end = null;
|
|
470
500
|
board.mousedown = (event) => {
|
|
471
501
|
// avoid select text when double click svg
|
|
472
|
-
if (!(event.target instanceof HTMLElement && event.target.closest('.richtext'))) {
|
|
502
|
+
if (!(event.target instanceof HTMLElement && event.target.closest('.richtext')) || isNoSelectionElement(event)) {
|
|
473
503
|
event.preventDefault();
|
|
474
504
|
}
|
|
475
|
-
if (board.cursor === BaseCursorStatus.select) {
|
|
505
|
+
if (!isNoSelectionElement(event) && board.cursor === BaseCursorStatus.select) {
|
|
476
506
|
start = toPoint(event.x, event.y, board.host);
|
|
477
507
|
}
|
|
478
508
|
mousedown(event);
|
|
@@ -488,9 +518,15 @@ function withSelection(board) {
|
|
|
488
518
|
mousemove(event);
|
|
489
519
|
};
|
|
490
520
|
board.mouseup = (event) => {
|
|
521
|
+
if (isNoSelectionElement(event)) {
|
|
522
|
+
return mouseup(event);
|
|
523
|
+
}
|
|
491
524
|
if (start) {
|
|
492
525
|
Transforms.setSelection(board, { anchor: start, focus: start });
|
|
493
526
|
}
|
|
527
|
+
else {
|
|
528
|
+
Transforms.setSelection(board, null);
|
|
529
|
+
}
|
|
494
530
|
start = null;
|
|
495
531
|
end = null;
|
|
496
532
|
mouseup(event);
|
|
@@ -505,31 +541,6 @@ const PlaitOperation = {
|
|
|
505
541
|
isSetViewportOperation
|
|
506
542
|
};
|
|
507
543
|
|
|
508
|
-
function transformPoints(board, points) {
|
|
509
|
-
const newPoints = points.map(point => {
|
|
510
|
-
return transformPoint(board, point);
|
|
511
|
-
});
|
|
512
|
-
return newPoints;
|
|
513
|
-
}
|
|
514
|
-
function transformPoint(board, point) {
|
|
515
|
-
const { width, height } = board.host.getBoundingClientRect();
|
|
516
|
-
const viewBox = getViewBox(board);
|
|
517
|
-
let x = (point[0] / width) * viewBox.width + viewBox.minX;
|
|
518
|
-
let y = (point[1] / height) * viewBox.height + viewBox.minY;
|
|
519
|
-
const newPoint = [x - board.viewport.offsetX, y - board.viewport.offsetY];
|
|
520
|
-
return newPoint;
|
|
521
|
-
}
|
|
522
|
-
function getViewBox(board) {
|
|
523
|
-
const { width, height } = board.host.getBoundingClientRect();
|
|
524
|
-
const scaleWidth = (board.viewport.zoom - 1) * width;
|
|
525
|
-
const scaleHeight = (board.viewport.zoom - 1) * height;
|
|
526
|
-
const viewBoxWidth = width - scaleWidth;
|
|
527
|
-
const viewBoxHeight = height - scaleHeight;
|
|
528
|
-
const minX = scaleWidth / 2;
|
|
529
|
-
const minY = scaleHeight / 2;
|
|
530
|
-
return { minX, minY: minY, width: viewBoxWidth, height: viewBoxHeight };
|
|
531
|
-
}
|
|
532
|
-
|
|
533
544
|
class PlaitElementComponent {
|
|
534
545
|
constructor(renderer2, viewContainerRef) {
|
|
535
546
|
this.renderer2 = renderer2;
|
|
@@ -606,6 +617,7 @@ class PlaitBoardComponent {
|
|
|
606
617
|
this.destroy$ = new Subject();
|
|
607
618
|
this.plaitValue = [];
|
|
608
619
|
this.plaitPlugins = [];
|
|
620
|
+
this.plaitReadonly = false;
|
|
609
621
|
this.plaitChange = new EventEmitter();
|
|
610
622
|
this.plaitBoardInitialized = new EventEmitter();
|
|
611
623
|
this.trackBy = (index, element) => {
|
|
@@ -615,6 +627,10 @@ class PlaitBoardComponent {
|
|
|
615
627
|
get host() {
|
|
616
628
|
return this.svg.nativeElement;
|
|
617
629
|
}
|
|
630
|
+
get isFocused() {
|
|
631
|
+
var _a;
|
|
632
|
+
return (_a = this.board) === null || _a === void 0 ? void 0 : _a.selection;
|
|
633
|
+
}
|
|
618
634
|
ngOnInit() {
|
|
619
635
|
const roughSVG = rough.svg(this.host, { options: { roughness: 0, strokeWidth: 1 } });
|
|
620
636
|
HOST_TO_ROUGH_SVG.set(this.host, roughSVG);
|
|
@@ -640,7 +656,8 @@ class PlaitBoardComponent {
|
|
|
640
656
|
this.plaitBoardInitialized.emit(this.board);
|
|
641
657
|
}
|
|
642
658
|
initializePlugins() {
|
|
643
|
-
|
|
659
|
+
const options = { readonly: this.plaitReadonly };
|
|
660
|
+
let board = withSelection(withBoard(createBoard(this.host, this.plaitValue, options)));
|
|
644
661
|
this.plaitPlugins.forEach(plugin => {
|
|
645
662
|
board = plugin(board);
|
|
646
663
|
});
|
|
@@ -653,7 +670,9 @@ class PlaitBoardComponent {
|
|
|
653
670
|
fromEvent(this.host, 'mousedown')
|
|
654
671
|
.pipe(takeUntil(this.destroy$))
|
|
655
672
|
.subscribe((event) => {
|
|
656
|
-
|
|
673
|
+
if (!isNoSelectionElement(event)) {
|
|
674
|
+
this.board.mousedown(event);
|
|
675
|
+
}
|
|
657
676
|
});
|
|
658
677
|
fromEvent(this.host, 'mousemove')
|
|
659
678
|
.pipe(takeUntil(this.destroy$))
|
|
@@ -663,7 +682,9 @@ class PlaitBoardComponent {
|
|
|
663
682
|
fromEvent(document, 'mouseup')
|
|
664
683
|
.pipe(takeUntil(this.destroy$))
|
|
665
684
|
.subscribe((event) => {
|
|
666
|
-
|
|
685
|
+
if (!isNoSelectionElement(event)) {
|
|
686
|
+
this.board.mouseup(event);
|
|
687
|
+
}
|
|
667
688
|
});
|
|
668
689
|
fromEvent(this.host, 'dblclick')
|
|
669
690
|
.pipe(takeUntil(this.destroy$))
|
|
@@ -673,20 +694,24 @@ class PlaitBoardComponent {
|
|
|
673
694
|
fromEvent(this.host, 'wheel')
|
|
674
695
|
.pipe(takeUntil(this.destroy$))
|
|
675
696
|
.subscribe((event) => {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
697
|
+
if (this.isFocused) {
|
|
698
|
+
event.preventDefault();
|
|
699
|
+
const viewport = this.board.viewport;
|
|
700
|
+
Transforms.setViewport(this.board, Object.assign(Object.assign({}, viewport), { offsetX: (viewport === null || viewport === void 0 ? void 0 : viewport.offsetX) - event.deltaX, offsetY: (viewport === null || viewport === void 0 ? void 0 : viewport.offsetY) - event.deltaY }));
|
|
701
|
+
}
|
|
679
702
|
});
|
|
680
703
|
fromEvent(document, 'keydown')
|
|
681
704
|
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
682
|
-
return !IS_TEXT_EDITABLE.get(this.board);
|
|
705
|
+
return !IS_TEXT_EDITABLE.get(this.board) && !!this.board.selection;
|
|
683
706
|
}))
|
|
684
707
|
.subscribe((event) => {
|
|
685
708
|
var _a;
|
|
686
709
|
(_a = this.board) === null || _a === void 0 ? void 0 : _a.keydown(event);
|
|
687
710
|
});
|
|
688
711
|
fromEvent(document, 'keyup')
|
|
689
|
-
.pipe(takeUntil(this.destroy$))
|
|
712
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
713
|
+
return !IS_TEXT_EDITABLE.get(this.board) && !!this.board.selection;
|
|
714
|
+
}))
|
|
690
715
|
.subscribe((event) => {
|
|
691
716
|
var _a;
|
|
692
717
|
(_a = this.board) === null || _a === void 0 ? void 0 : _a.keyup(event);
|
|
@@ -727,9 +752,9 @@ class PlaitBoardComponent {
|
|
|
727
752
|
}
|
|
728
753
|
}
|
|
729
754
|
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 });
|
|
730
|
-
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: `
|
|
731
|
-
<svg #svg width="100%" height="100%"></svg>
|
|
732
|
-
<div class="plait-toolbar island zoom-toolbar">
|
|
755
|
+
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: `
|
|
756
|
+
<svg #svg width="100%" height="100%" style="position: relative"></svg>
|
|
757
|
+
<div *ngIf="isFocused" class="plait-toolbar island zoom-toolbar plait-board-attached">
|
|
733
758
|
<button class="item" (mousedown)="zoomOut($event)">-</button>
|
|
734
759
|
<button class="item zoom-value" (mousedown)="resetZoom($event)">{{ zoom }}%</button>
|
|
735
760
|
<button class="item" (mousedown)="zoomIn($event)">+</button>
|
|
@@ -744,14 +769,14 @@ PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", ve
|
|
|
744
769
|
[host]="host"
|
|
745
770
|
></plait-element>
|
|
746
771
|
<ng-content></ng-content>
|
|
747
|
-
`, 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 });
|
|
772
|
+
`, 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 });
|
|
748
773
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaitBoardComponent, decorators: [{
|
|
749
774
|
type: Component,
|
|
750
775
|
args: [{
|
|
751
776
|
selector: 'plait-board',
|
|
752
777
|
template: `
|
|
753
|
-
<svg #svg width="100%" height="100%"></svg>
|
|
754
|
-
<div class="plait-toolbar island zoom-toolbar">
|
|
778
|
+
<svg #svg width="100%" height="100%" style="position: relative"></svg>
|
|
779
|
+
<div *ngIf="isFocused" class="plait-toolbar island zoom-toolbar plait-board-attached">
|
|
755
780
|
<button class="item" (mousedown)="zoomOut($event)">-</button>
|
|
756
781
|
<button class="item zoom-value" (mousedown)="resetZoom($event)">{{ zoom }}%</button>
|
|
757
782
|
<button class="item" (mousedown)="zoomIn($event)">+</button>
|
|
@@ -781,6 +806,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
781
806
|
type: Input
|
|
782
807
|
}], plaitPlugins: [{
|
|
783
808
|
type: Input
|
|
809
|
+
}], plaitReadonly: [{
|
|
810
|
+
type: Input
|
|
784
811
|
}], plaitChange: [{
|
|
785
812
|
type: Output
|
|
786
813
|
}], plaitBoardInitialized: [{
|
|
@@ -965,5 +992,5 @@ function rotate(x1, y1, x2, y2, angle) {
|
|
|
965
992
|
* Generated bundle index. Do not edit.
|
|
966
993
|
*/
|
|
967
994
|
|
|
968
|
-
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 };
|
|
995
|
+
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 };
|
|
969
996
|
//# sourceMappingURL=plait-core.mjs.map
|