@plait/core 0.1.9 → 0.2.0-next.0
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 +4 -3
- package/core/children/children.component.d.ts +17 -0
- package/core/children/effect.d.ts +2 -0
- package/core/element/context-change.d.ts +10 -0
- package/core/element/context.d.ts +4 -2
- package/core/element/element.component.d.ts +10 -13
- package/core/element/plugin-element.d.ts +5 -4
- package/esm2020/board/board.component.mjs +15 -23
- package/esm2020/core/children/children.component.mjs +58 -0
- package/esm2020/core/children/effect.mjs +2 -0
- package/esm2020/core/element/context-change.mjs +13 -0
- package/esm2020/core/element/context.mjs +1 -1
- package/esm2020/core/element/element.component.mjs +47 -37
- package/esm2020/core/element/plugin-element.mjs +36 -27
- package/esm2020/interfaces/board.mjs +33 -2
- package/esm2020/interfaces/element.mjs +15 -4
- package/esm2020/interfaces/node.mjs +23 -3
- package/esm2020/interfaces/operation.mjs +1 -1
- package/esm2020/interfaces/path.mjs +36 -1
- package/esm2020/interfaces/rectangle-client.mjs +9 -1
- package/esm2020/plait.module.mjs +4 -3
- package/esm2020/plugins/create-board.mjs +2 -1
- package/esm2020/plugins/with-moving.mjs +4 -4
- package/esm2020/plugins/with-selection.mjs +4 -4
- package/esm2020/public-api.mjs +3 -3
- package/esm2020/utils/draw/circle.mjs +4 -0
- package/esm2020/utils/draw/line.mjs +4 -0
- package/esm2020/utils/draw/rectangle.mjs +43 -1
- package/esm2020/utils/element.mjs +2 -2
- package/esm2020/utils/index.mjs +3 -1
- package/esm2020/utils/selected-element.mjs +11 -4
- package/esm2020/utils/tree.mjs +7 -5
- package/esm2020/utils/weak-maps.mjs +4 -1
- package/fesm2015/plait-core.mjs +417 -187
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +416 -185
- package/fesm2020/plait-core.mjs.map +1 -1
- package/interfaces/board.d.ts +5 -0
- package/interfaces/element.d.ts +6 -3
- package/interfaces/node.d.ts +17 -9
- package/interfaces/operation.d.ts +1 -1
- package/interfaces/path.d.ts +18 -0
- package/interfaces/rectangle-client.d.ts +6 -0
- package/package.json +1 -1
- package/plait.module.d.ts +5 -4
- package/public-api.d.ts +2 -2
- package/styles/styles.scss +4 -0
- package/utils/draw/circle.d.ts +4 -0
- package/utils/draw/line.d.ts +4 -0
- package/utils/draw/rectangle.d.ts +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/selected-element.d.ts +2 -2
- package/utils/tree.d.ts +1 -1
- package/utils/weak-maps.d.ts +4 -0
- package/core/base/detector.d.ts +0 -7
- package/core/element/before-context-change.d.ts +0 -6
- package/esm2020/core/base/detector.mjs +0 -2
- package/esm2020/core/element/before-context-change.mjs +0 -7
package/fesm2020/plait-core.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Component, ChangeDetectionStrategy,
|
|
2
|
+
import { Directive, Input, Component, ChangeDetectionStrategy, EventEmitter, HostBinding, Output, ElementRef, ViewChild, ContentChild, NgModule } from '@angular/core';
|
|
3
3
|
import rough from 'roughjs/bin/rough';
|
|
4
4
|
import { timer, Subject, fromEvent } from 'rxjs';
|
|
5
5
|
import { takeUntil, filter } from 'rxjs/operators';
|
|
@@ -9,7 +9,10 @@ import * as i1 from '@angular/common';
|
|
|
9
9
|
import { BrowserModule } from '@angular/platform-browser';
|
|
10
10
|
|
|
11
11
|
// record richtext type status
|
|
12
|
+
const IS_BOARD_CACHE = new WeakMap();
|
|
12
13
|
const FLUSHING = new WeakMap();
|
|
14
|
+
const NODE_TO_INDEX = new WeakMap();
|
|
15
|
+
const NODE_TO_PARENT = new WeakMap();
|
|
13
16
|
const IS_TEXT_EDITABLE = new WeakMap();
|
|
14
17
|
const BOARD_TO_ON_CHANGE = new WeakMap();
|
|
15
18
|
const BOARD_TO_COMPONENT = new WeakMap();
|
|
@@ -24,10 +27,12 @@ const BOARD_TO_IS_SELECTION_MOVING = new WeakMap();
|
|
|
24
27
|
const BOARD_TO_TEMPORARY_ELEMENTS = new WeakMap();
|
|
25
28
|
const BOARD_TO_MOVING_ELEMENT = new WeakMap();
|
|
26
29
|
|
|
27
|
-
function depthFirstRecursion(node, callback) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
function depthFirstRecursion(node, callback, recursion) {
|
|
31
|
+
if (!recursion || recursion(node)) {
|
|
32
|
+
node.children?.forEach(child => {
|
|
33
|
+
depthFirstRecursion(child, callback, recursion);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
31
36
|
callback(node);
|
|
32
37
|
}
|
|
33
38
|
|
|
@@ -49,7 +54,7 @@ function getRectangleByElements(board, elements, recursion) {
|
|
|
49
54
|
};
|
|
50
55
|
elements.forEach(element => {
|
|
51
56
|
if (recursion) {
|
|
52
|
-
depthFirstRecursion(element, node => calcRectangleClient(node));
|
|
57
|
+
depthFirstRecursion(element, node => calcRectangleClient(node), node => board.isRecursion(node));
|
|
53
58
|
}
|
|
54
59
|
else {
|
|
55
60
|
calcRectangleClient(element);
|
|
@@ -67,6 +72,37 @@ function getBoardRectangle(board) {
|
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
const PlaitBoard = {
|
|
75
|
+
isBoard(value) {
|
|
76
|
+
const cachedIsBoard = IS_BOARD_CACHE.get(value);
|
|
77
|
+
if (cachedIsBoard !== undefined) {
|
|
78
|
+
return cachedIsBoard;
|
|
79
|
+
}
|
|
80
|
+
const isBoard = typeof value.onChange === 'function' && typeof value.apply === 'function';
|
|
81
|
+
IS_BOARD_CACHE.set(value, isBoard);
|
|
82
|
+
return isBoard;
|
|
83
|
+
},
|
|
84
|
+
findPath(board, node) {
|
|
85
|
+
const path = [];
|
|
86
|
+
let child = node;
|
|
87
|
+
while (true) {
|
|
88
|
+
const parent = NODE_TO_PARENT.get(child);
|
|
89
|
+
if (parent == null) {
|
|
90
|
+
if (PlaitBoard.isBoard(child)) {
|
|
91
|
+
return path;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const i = NODE_TO_INDEX.get(child);
|
|
98
|
+
if (i == null) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
path.unshift(i);
|
|
102
|
+
child = parent;
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`Unable to find the path for Plait node: ${JSON.stringify(node)}`);
|
|
105
|
+
},
|
|
70
106
|
getHost(board) {
|
|
71
107
|
return BOARD_TO_HOST.get(board);
|
|
72
108
|
},
|
|
@@ -129,6 +165,41 @@ const Viewport = {
|
|
|
129
165
|
};
|
|
130
166
|
|
|
131
167
|
const Path = {
|
|
168
|
+
/**
|
|
169
|
+
* Get a list of ancestor paths for a given path.
|
|
170
|
+
*
|
|
171
|
+
* The paths are sorted from shallowest to deepest ancestor. However, if the
|
|
172
|
+
* `reverse: true` option is passed, they are reversed.
|
|
173
|
+
*/
|
|
174
|
+
ancestors(path, options = {}) {
|
|
175
|
+
const { reverse = false } = options;
|
|
176
|
+
let paths = Path.levels(path, options);
|
|
177
|
+
if (reverse) {
|
|
178
|
+
paths = paths.slice(1);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
paths = paths.slice(0, -1);
|
|
182
|
+
}
|
|
183
|
+
return paths;
|
|
184
|
+
},
|
|
185
|
+
/**
|
|
186
|
+
* Get a list of paths at every level down to a path. Note: this is the same
|
|
187
|
+
* as `Path.ancestors`, but including the path itself.
|
|
188
|
+
*
|
|
189
|
+
* The paths are sorted from shallowest to deepest. However, if the `reverse:
|
|
190
|
+
* true` option is passed, they are reversed.
|
|
191
|
+
*/
|
|
192
|
+
levels(path, options = {}) {
|
|
193
|
+
const { reverse = false } = options;
|
|
194
|
+
const list = [];
|
|
195
|
+
for (let i = 0; i <= path.length; i++) {
|
|
196
|
+
list.push(path.slice(0, i));
|
|
197
|
+
}
|
|
198
|
+
if (reverse) {
|
|
199
|
+
list.reverse();
|
|
200
|
+
}
|
|
201
|
+
return list;
|
|
202
|
+
},
|
|
132
203
|
parent(path) {
|
|
133
204
|
if (path.length === 0) {
|
|
134
205
|
throw new Error(`Cannot get the parent path of the root path [${path}].`);
|
|
@@ -272,8 +343,20 @@ const PlaitNode = {
|
|
|
272
343
|
const p = PlaitNode.get(board, parentPath);
|
|
273
344
|
return p;
|
|
274
345
|
},
|
|
275
|
-
|
|
276
|
-
|
|
346
|
+
/**
|
|
347
|
+
* Return a generator of all the ancestor nodes above a specific path.
|
|
348
|
+
*
|
|
349
|
+
* By default the order is top-down, from highest to lowest ancestor in
|
|
350
|
+
* the tree, but you can pass the `reverse: true` option to go bottom-up.
|
|
351
|
+
*/
|
|
352
|
+
*parents(root, path, options = {}) {
|
|
353
|
+
for (const p of Path.ancestors(path, options)) {
|
|
354
|
+
const n = PlaitNode.get(root, p);
|
|
355
|
+
yield n;
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
get(root, path) {
|
|
359
|
+
let node = root;
|
|
277
360
|
for (let i = 0; i < path.length; i++) {
|
|
278
361
|
const p = path[i];
|
|
279
362
|
if (!node || !node.children || !node.children[p]) {
|
|
@@ -282,6 +365,14 @@ const PlaitNode = {
|
|
|
282
365
|
node = node.children[p];
|
|
283
366
|
}
|
|
284
367
|
return node;
|
|
368
|
+
},
|
|
369
|
+
last(board, path) {
|
|
370
|
+
let n = PlaitNode.get(board, path);
|
|
371
|
+
while (n && n.children) {
|
|
372
|
+
const i = n.children.length - 1;
|
|
373
|
+
n = n.children[i];
|
|
374
|
+
}
|
|
375
|
+
return n;
|
|
285
376
|
}
|
|
286
377
|
};
|
|
287
378
|
|
|
@@ -586,10 +677,152 @@ const IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /Chrome?\/(?:[0-7][
|
|
|
586
677
|
* Extendable Custom Types Interface
|
|
587
678
|
*/
|
|
588
679
|
|
|
680
|
+
const getHitElements = (board) => {
|
|
681
|
+
const selectedElements = [];
|
|
682
|
+
depthFirstRecursion(board, node => {
|
|
683
|
+
if (!PlaitBoard.isBoard(node) &&
|
|
684
|
+
board.selection?.ranges.some(range => {
|
|
685
|
+
return board.isHitSelection(node, range);
|
|
686
|
+
})) {
|
|
687
|
+
selectedElements.push(node);
|
|
688
|
+
}
|
|
689
|
+
}, node => {
|
|
690
|
+
if (PlaitBoard.isBoard(node) || board.isRecursion(node)) {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
return selectedElements;
|
|
698
|
+
};
|
|
699
|
+
const isIntersectionElements = (board, elements, ranges) => {
|
|
700
|
+
let isIntersectionElements = false;
|
|
701
|
+
if (elements.length) {
|
|
702
|
+
elements.map(item => {
|
|
703
|
+
if (!isIntersectionElements) {
|
|
704
|
+
isIntersectionElements = ranges.some(range => {
|
|
705
|
+
return board.isHitSelection(item, range);
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
return isIntersectionElements;
|
|
711
|
+
};
|
|
712
|
+
const cacheSelectedElements = (board, selectedElements) => {
|
|
713
|
+
BOARD_TO_SELECTED_ELEMENT.set(board, selectedElements);
|
|
714
|
+
};
|
|
715
|
+
const getSelectedElements = (board) => {
|
|
716
|
+
return BOARD_TO_SELECTED_ELEMENT.get(board) || [];
|
|
717
|
+
};
|
|
718
|
+
const addSelectedElement = (board, element) => {
|
|
719
|
+
const selectedElements = getSelectedElements(board);
|
|
720
|
+
cacheSelectedElements(board, [...selectedElements, element]);
|
|
721
|
+
};
|
|
722
|
+
const removeSelectedElement = (board, element) => {
|
|
723
|
+
const selectedElements = getSelectedElements(board);
|
|
724
|
+
const newSelectedElements = selectedElements.filter(value => value !== element);
|
|
725
|
+
cacheSelectedElements(board, newSelectedElements);
|
|
726
|
+
};
|
|
727
|
+
const isSelectedElement = (board, element) => {
|
|
728
|
+
const selectedElements = getSelectedElements(board);
|
|
729
|
+
return !!selectedElements.find(value => value === element);
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
function hasBeforeContextChange(value) {
|
|
733
|
+
if (value.beforeContextChange) {
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
function hasOnContextChanged(value) {
|
|
739
|
+
if (value.onContextChanged) {
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
class PlaitPluginElementComponent {
|
|
746
|
+
set context(value) {
|
|
747
|
+
if (hasBeforeContextChange(this)) {
|
|
748
|
+
this.beforeContextChange(value);
|
|
749
|
+
}
|
|
750
|
+
const previousContext = this._context;
|
|
751
|
+
this._context = value;
|
|
752
|
+
if (this.element) {
|
|
753
|
+
ELEMENT_TO_COMPONENT.set(this.element, this);
|
|
754
|
+
}
|
|
755
|
+
if (this.initialized) {
|
|
756
|
+
this.cdr.markForCheck();
|
|
757
|
+
if (hasOnContextChanged(this)) {
|
|
758
|
+
this.onContextChanged(value, previousContext);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
if (PlaitElement.isRootElement(this.element) && this.element.children && this.element.children.length > 0) {
|
|
763
|
+
this.g = createG();
|
|
764
|
+
this.rootG = createG();
|
|
765
|
+
this.rootG.append(this.g);
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
this.g = createG();
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
get context() {
|
|
773
|
+
return this._context;
|
|
774
|
+
}
|
|
775
|
+
get element() {
|
|
776
|
+
return this.context && this.context.element;
|
|
777
|
+
}
|
|
778
|
+
get board() {
|
|
779
|
+
return this.context && this.context.board;
|
|
780
|
+
}
|
|
781
|
+
get selected() {
|
|
782
|
+
return this.context && this.context.selected;
|
|
783
|
+
}
|
|
784
|
+
get effect() {
|
|
785
|
+
return this.context && this.context.effect;
|
|
786
|
+
}
|
|
787
|
+
constructor(cdr) {
|
|
788
|
+
this.cdr = cdr;
|
|
789
|
+
this.initialized = false;
|
|
790
|
+
}
|
|
791
|
+
ngOnInit() {
|
|
792
|
+
if (this.element.type) {
|
|
793
|
+
(this.rootG || this.g).setAttribute(`plait-${this.element.type}`, 'true');
|
|
794
|
+
}
|
|
795
|
+
this.initialized = true;
|
|
796
|
+
}
|
|
797
|
+
ngOnDestroy() {
|
|
798
|
+
if (ELEMENT_TO_COMPONENT.get(this.element) === this) {
|
|
799
|
+
ELEMENT_TO_COMPONENT.delete(this.element);
|
|
800
|
+
}
|
|
801
|
+
removeSelectedElement(this.board, this.element);
|
|
802
|
+
(this.rootG || this.g).remove();
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
PlaitPluginElementComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitPluginElementComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
806
|
+
PlaitPluginElementComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.5", type: PlaitPluginElementComponent, inputs: { context: "context" }, ngImport: i0 });
|
|
807
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitPluginElementComponent, decorators: [{
|
|
808
|
+
type: Directive
|
|
809
|
+
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { context: [{
|
|
810
|
+
type: Input
|
|
811
|
+
}] } });
|
|
812
|
+
const ELEMENT_TO_COMPONENT = new WeakMap();
|
|
813
|
+
|
|
589
814
|
const PlaitElement = {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
815
|
+
isRootElement(value) {
|
|
816
|
+
const parent = NODE_TO_PARENT.get(value);
|
|
817
|
+
if (parent && PlaitBoard.isBoard(parent)) {
|
|
818
|
+
return true;
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
getComponent(value) {
|
|
825
|
+
return ELEMENT_TO_COMPONENT.get(value);
|
|
593
826
|
}
|
|
594
827
|
};
|
|
595
828
|
|
|
@@ -615,6 +848,14 @@ const RectangleClient = {
|
|
|
615
848
|
const yMax = Math.max(...yArray);
|
|
616
849
|
const rect = { x: xMin, y: yMin, width: xMax - xMin, height: yMax - yMin };
|
|
617
850
|
return rect;
|
|
851
|
+
},
|
|
852
|
+
getOutlineRectangle: (rectangle, offset) => {
|
|
853
|
+
return {
|
|
854
|
+
x: rectangle.x + offset,
|
|
855
|
+
y: rectangle.y + offset,
|
|
856
|
+
width: rectangle.width + Math.abs(offset) * 2,
|
|
857
|
+
height: rectangle.height + Math.abs(offset) * 2
|
|
858
|
+
};
|
|
618
859
|
}
|
|
619
860
|
};
|
|
620
861
|
|
|
@@ -891,51 +1132,6 @@ function idCreator(length = 5) {
|
|
|
891
1132
|
return key;
|
|
892
1133
|
}
|
|
893
1134
|
|
|
894
|
-
const calcElementIntersectionSelection = (board) => {
|
|
895
|
-
const selectedElements = [];
|
|
896
|
-
depthFirstRecursion(board, node => {
|
|
897
|
-
if (PlaitElement.isElement(node) &&
|
|
898
|
-
board.selection?.ranges.some(range => {
|
|
899
|
-
return board.isHitSelection(node, range);
|
|
900
|
-
})) {
|
|
901
|
-
selectedElements.push(node);
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
return selectedElements;
|
|
905
|
-
};
|
|
906
|
-
const isIntersectionElements = (board, elements, ranges) => {
|
|
907
|
-
let isIntersectionElements = false;
|
|
908
|
-
if (elements.length) {
|
|
909
|
-
elements.map(item => {
|
|
910
|
-
if (!isIntersectionElements) {
|
|
911
|
-
isIntersectionElements = ranges.some(range => {
|
|
912
|
-
return board.isHitSelection(item, range);
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
return isIntersectionElements;
|
|
918
|
-
};
|
|
919
|
-
const cacheSelectedElements = (board, selectedElements) => {
|
|
920
|
-
BOARD_TO_SELECTED_ELEMENT.set(board, selectedElements);
|
|
921
|
-
};
|
|
922
|
-
const getSelectedElements = (board) => {
|
|
923
|
-
return BOARD_TO_SELECTED_ELEMENT.get(board) || [];
|
|
924
|
-
};
|
|
925
|
-
const addSelectedElement = (board, element) => {
|
|
926
|
-
const selectedElements = getSelectedElements(board);
|
|
927
|
-
cacheSelectedElements(board, [...selectedElements, element]);
|
|
928
|
-
};
|
|
929
|
-
const removeSelectedElement = (board, element) => {
|
|
930
|
-
const selectedElements = getSelectedElements(board);
|
|
931
|
-
const newSelectedElements = selectedElements.filter(value => value !== element);
|
|
932
|
-
cacheSelectedElements(board, newSelectedElements);
|
|
933
|
-
};
|
|
934
|
-
const isSelectedElement = (board, element) => {
|
|
935
|
-
const selectedElements = getSelectedElements(board);
|
|
936
|
-
return !!selectedElements.find(value => value === element);
|
|
937
|
-
};
|
|
938
|
-
|
|
939
1135
|
const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
|
|
940
1136
|
const SCROLL_BAR_WIDTH = 20;
|
|
941
1137
|
const MAX_RADIUS = 16;
|
|
@@ -961,6 +1157,48 @@ function drawRoundRectangle(rs, x1, y1, x2, y2, options, outline = false, border
|
|
|
961
1157
|
const point8 = [x1, y1 + radius];
|
|
962
1158
|
return rs.path(`M${point2[0]} ${point2[1]} A ${radius} ${radius}, 0, 0, 1, ${point3[0]} ${point3[1]} L ${point4[0]} ${point4[1]} A ${radius} ${radius}, 0, 0, 1, ${point5[0]} ${point5[1]} L ${point6[0]} ${point6[1]} A ${radius} ${radius}, 0, 0, 1, ${point7[0]} ${point7[1]} L ${point8[0]} ${point8[1]} A ${radius} ${radius}, 0, 0, 1, ${point1[0]} ${point1[1]} Z`, options);
|
|
963
1159
|
}
|
|
1160
|
+
function drawAbstractRoundRectangle(rs, x1, y1, x2, y2, isHorizontal, options) {
|
|
1161
|
+
const width = Math.abs(x1 - x2);
|
|
1162
|
+
const height = Math.abs(y1 - y2);
|
|
1163
|
+
const radius = 3;
|
|
1164
|
+
const handleGap = 4;
|
|
1165
|
+
const handleLength = 10;
|
|
1166
|
+
const handleSpace = handleLength + handleGap * 2;
|
|
1167
|
+
if (isHorizontal) {
|
|
1168
|
+
const handleSideLine = (width - handleSpace - radius * 2) / 2;
|
|
1169
|
+
const sideLine = height - radius * 2;
|
|
1170
|
+
return rs.path(`M${x1 + radius},${y1}
|
|
1171
|
+
l${handleSideLine},0
|
|
1172
|
+
m${handleSpace},0
|
|
1173
|
+
l${handleSideLine},0
|
|
1174
|
+
a${radius},${radius},0,0,1,${radius},${radius}
|
|
1175
|
+
l0,${sideLine}
|
|
1176
|
+
a${radius},${radius},0,0,1,-${radius},${radius}
|
|
1177
|
+
l-${handleSideLine},0
|
|
1178
|
+
m-${handleSpace},0
|
|
1179
|
+
l-${handleSideLine},0
|
|
1180
|
+
a${radius},${radius},0,0,1,-${radius},-${radius}
|
|
1181
|
+
l0,-${sideLine}
|
|
1182
|
+
a${radius},${radius},0,0,1,${radius},-${radius}`, options);
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
const handleSideLine = (height - handleSpace - radius * 2) / 2;
|
|
1186
|
+
const sideLine = width - radius * 2;
|
|
1187
|
+
return rs.path(`M${x1 + radius},${y1}
|
|
1188
|
+
l${sideLine},0
|
|
1189
|
+
a${radius},${radius},0,0,1,${radius},${radius}
|
|
1190
|
+
l0,${handleSideLine}
|
|
1191
|
+
m0,${handleSpace}
|
|
1192
|
+
l0,${handleSideLine}
|
|
1193
|
+
a${radius},${radius},0,0,1,-${radius},${radius}
|
|
1194
|
+
l-${sideLine},0
|
|
1195
|
+
a${radius},${radius},0,0,1,-${radius},-${radius}
|
|
1196
|
+
l0,-${handleSideLine}
|
|
1197
|
+
m0,-${handleSpace}
|
|
1198
|
+
l0,-${handleSideLine}
|
|
1199
|
+
a${radius},${radius},0,0,1,${radius},-${radius}`, options);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
964
1202
|
|
|
965
1203
|
function arrowPoints(start, end, maxHypotenuseLength = 10, degree = 40) {
|
|
966
1204
|
const width = Math.abs(start[0] - end[0]);
|
|
@@ -984,6 +1222,14 @@ function drawArrow(rs, start, end, options, maxHypotenuseLength = 10, degree = 4
|
|
|
984
1222
|
return [arrowLineLeft, arrowLineRight];
|
|
985
1223
|
}
|
|
986
1224
|
|
|
1225
|
+
function drawCircle(roughSVG, point, diameter, options) {
|
|
1226
|
+
return roughSVG.circle(point[0], point[1], diameter, options);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
function drawLine(rs, start, end, options) {
|
|
1230
|
+
return rs.linearPath([start, end], options);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
987
1233
|
const IS_FROM_SCROLLING = new WeakMap();
|
|
988
1234
|
const IS_FROM_VIEWPORT_CHANGE = new WeakMap();
|
|
989
1235
|
function getViewportContainerRect(board) {
|
|
@@ -1302,6 +1548,7 @@ function createBoard(children, options) {
|
|
|
1302
1548
|
destroyElement: (context) => { },
|
|
1303
1549
|
isWithinSelection: element => false,
|
|
1304
1550
|
isHitSelection: element => false,
|
|
1551
|
+
isRecursion: element => true,
|
|
1305
1552
|
isMovable: element => false,
|
|
1306
1553
|
getRectangle: element => null
|
|
1307
1554
|
};
|
|
@@ -1486,7 +1733,7 @@ function withSelection(board) {
|
|
|
1486
1733
|
return;
|
|
1487
1734
|
}
|
|
1488
1735
|
Transforms.setSelection(board, { ranges: ranges });
|
|
1489
|
-
if (
|
|
1736
|
+
if (getHitElements(board).length || board.pointer === PlaitPointerType.hand) {
|
|
1490
1737
|
start = null;
|
|
1491
1738
|
}
|
|
1492
1739
|
}
|
|
@@ -1540,7 +1787,7 @@ function withSelection(board) {
|
|
|
1540
1787
|
if (board.operations.find(value => value.type === 'set_selection')) {
|
|
1541
1788
|
selectionOuterG?.remove();
|
|
1542
1789
|
const temporaryElements = getTemporaryElements(board);
|
|
1543
|
-
const elements = temporaryElements ? temporaryElements :
|
|
1790
|
+
const elements = temporaryElements ? temporaryElements : getHitElements(board);
|
|
1544
1791
|
cacheSelectedElements(board, elements);
|
|
1545
1792
|
previousSelectedElements = elements;
|
|
1546
1793
|
const { width, height } = getRectangleByElements(board, elements, false);
|
|
@@ -1644,7 +1891,7 @@ function withMoving(board) {
|
|
|
1644
1891
|
const host = BOARD_TO_HOST.get(board);
|
|
1645
1892
|
const point = transformPoint(board, toPoint(event.x, event.y, host));
|
|
1646
1893
|
const ranges = [{ anchor: point, focus: point }];
|
|
1647
|
-
let movableElements = board.children.filter(item =>
|
|
1894
|
+
let movableElements = board.children.filter(item => board.isMovable(item));
|
|
1648
1895
|
if (movableElements.length) {
|
|
1649
1896
|
startPoint = point;
|
|
1650
1897
|
const selectedRootElements = getSelectedElements(board).filter(item => movableElements.includes(item));
|
|
@@ -1722,71 +1969,76 @@ class PlaitElementComponent {
|
|
|
1722
1969
|
this.renderer2 = renderer2;
|
|
1723
1970
|
this.viewContainerRef = viewContainerRef;
|
|
1724
1971
|
this.initialized = false;
|
|
1725
|
-
this.selection = null;
|
|
1726
1972
|
}
|
|
1727
1973
|
ngOnInit() {
|
|
1728
1974
|
this.initialize();
|
|
1729
1975
|
this.drawElement();
|
|
1730
1976
|
}
|
|
1731
1977
|
initialize() {
|
|
1978
|
+
NODE_TO_INDEX.set(this.element, this.index);
|
|
1979
|
+
NODE_TO_PARENT.set(this.element, this.parent);
|
|
1732
1980
|
this.initialized = true;
|
|
1733
|
-
this.gGroup = createG();
|
|
1734
|
-
this.renderer2.setAttribute(this.gGroup, 'plait-element-group', this.index.toString());
|
|
1735
|
-
PlaitBoard.getElementHost(this.board).append(this.gGroup);
|
|
1736
1981
|
}
|
|
1737
1982
|
drawElement() {
|
|
1738
1983
|
const context = this.getContext();
|
|
1739
|
-
const result = this.board.drawElement(context
|
|
1984
|
+
const result = this.board.drawElement(context);
|
|
1740
1985
|
if (Array.isArray(result)) {
|
|
1741
|
-
result.forEach(g => {
|
|
1742
|
-
this.gGroup.appendChild(g);
|
|
1743
|
-
});
|
|
1744
1986
|
}
|
|
1745
1987
|
else {
|
|
1746
1988
|
const componentRef = this.viewContainerRef.createComponent(result);
|
|
1747
1989
|
const instance = componentRef.instance;
|
|
1748
|
-
instance.context = context
|
|
1749
|
-
this.
|
|
1990
|
+
instance.context = context;
|
|
1991
|
+
this.insertG(instance.rootG ? instance.rootG : instance.g);
|
|
1750
1992
|
this.instance = instance;
|
|
1751
1993
|
}
|
|
1752
1994
|
}
|
|
1753
|
-
|
|
1995
|
+
insertG(g) {
|
|
1996
|
+
if (PlaitBoard.isBoard(this.parent)) {
|
|
1997
|
+
this.parentG.prepend(g);
|
|
1998
|
+
}
|
|
1999
|
+
else {
|
|
2000
|
+
let siblingG = PlaitElement.getComponent(this.parent).g;
|
|
2001
|
+
if (this.index > 0) {
|
|
2002
|
+
const brotherElement = this.parent.children[this.index - 1];
|
|
2003
|
+
const lastElement = PlaitNode.last(this.board, PlaitBoard.findPath(this.board, brotherElement));
|
|
2004
|
+
const siblingElement = lastElement || brotherElement;
|
|
2005
|
+
siblingG = PlaitElement.getComponent(siblingElement).g;
|
|
2006
|
+
}
|
|
2007
|
+
this.parentG.insertBefore(g, siblingG);
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
ngOnChanges(simpleChanges) {
|
|
1754
2011
|
if (this.initialized) {
|
|
2012
|
+
NODE_TO_INDEX.set(this.element, this.index);
|
|
2013
|
+
NODE_TO_PARENT.set(this.element, this.parent);
|
|
2014
|
+
const elementChanged = simpleChanges['element'];
|
|
1755
2015
|
const context = this.getContext();
|
|
1756
|
-
if (this.
|
|
1757
|
-
|
|
2016
|
+
if (elementChanged && isSelectedElement(this.board, elementChanged.previousValue)) {
|
|
2017
|
+
context.selected = true;
|
|
2018
|
+
removeSelectedElement(this.board, elementChanged.previousValue);
|
|
2019
|
+
addSelectedElement(this.board, this.element);
|
|
1758
2020
|
}
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
this.gGroup.childNodes.forEach(g => g.remove());
|
|
1762
|
-
result.forEach(g => {
|
|
1763
|
-
this.gGroup.appendChild(g);
|
|
1764
|
-
});
|
|
2021
|
+
if (this.instance) {
|
|
2022
|
+
this.instance.context = context;
|
|
1765
2023
|
}
|
|
1766
2024
|
}
|
|
1767
2025
|
}
|
|
1768
2026
|
getContext() {
|
|
1769
|
-
const
|
|
2027
|
+
const isSelected = isSelectedElement(this.board, this.element);
|
|
2028
|
+
const context = {
|
|
1770
2029
|
element: this.element,
|
|
1771
|
-
|
|
1772
|
-
|
|
2030
|
+
board: this.board,
|
|
2031
|
+
selected: isSelected,
|
|
2032
|
+
effect: this.effect
|
|
1773
2033
|
};
|
|
1774
|
-
|
|
1775
|
-
const previous = { ...this.context };
|
|
1776
|
-
this.context = current;
|
|
1777
|
-
return { current, previous };
|
|
1778
|
-
}
|
|
1779
|
-
else {
|
|
1780
|
-
return { current };
|
|
1781
|
-
}
|
|
2034
|
+
return context;
|
|
1782
2035
|
}
|
|
1783
2036
|
ngOnDestroy() {
|
|
1784
|
-
this.
|
|
1785
|
-
this.board.destroyElement(this.getContext().current);
|
|
2037
|
+
this.board.destroyElement(this.getContext());
|
|
1786
2038
|
}
|
|
1787
2039
|
}
|
|
1788
2040
|
PlaitElementComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitElementComponent, deps: [{ token: i0.Renderer2 }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
1789
|
-
PlaitElementComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", type: PlaitElementComponent, selector: "plait-element", inputs: { index: "index", element: "element", board: "board",
|
|
2041
|
+
PlaitElementComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", type: PlaitElementComponent, selector: "plait-element", inputs: { index: "index", element: "element", parent: "parent", board: "board", effect: "effect", parentG: "parentG" }, usesOnChanges: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1790
2042
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitElementComponent, decorators: [{
|
|
1791
2043
|
type: Component,
|
|
1792
2044
|
args: [{
|
|
@@ -1798,11 +2050,66 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
|
|
|
1798
2050
|
type: Input
|
|
1799
2051
|
}], element: [{
|
|
1800
2052
|
type: Input
|
|
2053
|
+
}], parent: [{
|
|
2054
|
+
type: Input
|
|
1801
2055
|
}], board: [{
|
|
1802
2056
|
type: Input
|
|
1803
|
-
}],
|
|
2057
|
+
}], effect: [{
|
|
1804
2058
|
type: Input
|
|
1805
|
-
}],
|
|
2059
|
+
}], parentG: [{
|
|
2060
|
+
type: Input
|
|
2061
|
+
}] } });
|
|
2062
|
+
|
|
2063
|
+
class PlaitChildrenElement {
|
|
2064
|
+
constructor() {
|
|
2065
|
+
this.trackBy = (index, element) => {
|
|
2066
|
+
return element.id;
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
ngOnInit() {
|
|
2070
|
+
if (!this.parent) {
|
|
2071
|
+
this.parent = this.board;
|
|
2072
|
+
}
|
|
2073
|
+
if (!this.parentG) {
|
|
2074
|
+
this.parentG = PlaitBoard.getElementHost(this.board);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
PlaitChildrenElement.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitChildrenElement, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2079
|
+
PlaitChildrenElement.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", type: PlaitChildrenElement, selector: "plait-children", inputs: { board: "board", parent: "parent", effect: "effect", parentG: "parentG" }, ngImport: i0, template: `
|
|
2080
|
+
<plait-element
|
|
2081
|
+
*ngFor="let item of parent.children; let index = index; trackBy: trackBy"
|
|
2082
|
+
[index]="index"
|
|
2083
|
+
[element]="item"
|
|
2084
|
+
[parent]="parent"
|
|
2085
|
+
[board]="board"
|
|
2086
|
+
[effect]="effect"
|
|
2087
|
+
[parentG]="parentG"
|
|
2088
|
+
></plait-element>
|
|
2089
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: PlaitElementComponent, selector: "plait-element", inputs: ["index", "element", "parent", "board", "effect", "parentG"] }] });
|
|
2090
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitChildrenElement, decorators: [{
|
|
2091
|
+
type: Component,
|
|
2092
|
+
args: [{
|
|
2093
|
+
selector: 'plait-children',
|
|
2094
|
+
template: `
|
|
2095
|
+
<plait-element
|
|
2096
|
+
*ngFor="let item of parent.children; let index = index; trackBy: trackBy"
|
|
2097
|
+
[index]="index"
|
|
2098
|
+
[element]="item"
|
|
2099
|
+
[parent]="parent"
|
|
2100
|
+
[board]="board"
|
|
2101
|
+
[effect]="effect"
|
|
2102
|
+
[parentG]="parentG"
|
|
2103
|
+
></plait-element>
|
|
2104
|
+
`
|
|
2105
|
+
}]
|
|
2106
|
+
}], ctorParameters: function () { return []; }, propDecorators: { board: [{
|
|
2107
|
+
type: Input
|
|
2108
|
+
}], parent: [{
|
|
2109
|
+
type: Input
|
|
2110
|
+
}], effect: [{
|
|
2111
|
+
type: Input
|
|
2112
|
+
}], parentG: [{
|
|
1806
2113
|
type: Input
|
|
1807
2114
|
}] } });
|
|
1808
2115
|
|
|
@@ -1878,12 +2185,12 @@ class PlaitBoardComponent {
|
|
|
1878
2185
|
get nativeElement() {
|
|
1879
2186
|
return this.elementRef.nativeElement;
|
|
1880
2187
|
}
|
|
1881
|
-
constructor(cdr,
|
|
2188
|
+
constructor(cdr, elementRef, ngZone) {
|
|
1882
2189
|
this.cdr = cdr;
|
|
1883
|
-
this.renderer2 = renderer2;
|
|
1884
2190
|
this.elementRef = elementRef;
|
|
1885
2191
|
this.ngZone = ngZone;
|
|
1886
2192
|
this.hasInitialized = false;
|
|
2193
|
+
this.effect = {};
|
|
1887
2194
|
this.destroy$ = new Subject();
|
|
1888
2195
|
this.plaitValue = [];
|
|
1889
2196
|
this.plaitPlugins = [];
|
|
@@ -1909,7 +2216,7 @@ class PlaitBoardComponent {
|
|
|
1909
2216
|
BOARD_TO_HOST.set(this.board, this.host);
|
|
1910
2217
|
BOARD_TO_ELEMENT_HOST.set(this.board, elementHost);
|
|
1911
2218
|
BOARD_TO_ON_CHANGE.set(this.board, () => {
|
|
1912
|
-
this.
|
|
2219
|
+
this.detect();
|
|
1913
2220
|
const changeEvent = {
|
|
1914
2221
|
children: this.board.children,
|
|
1915
2222
|
operations: this.board.operations,
|
|
@@ -1920,6 +2227,10 @@ class PlaitBoardComponent {
|
|
|
1920
2227
|
});
|
|
1921
2228
|
this.hasInitialized = true;
|
|
1922
2229
|
}
|
|
2230
|
+
detect() {
|
|
2231
|
+
this.effect = {};
|
|
2232
|
+
this.cdr.detectChanges();
|
|
2233
|
+
}
|
|
1923
2234
|
mouseLeaveListener() {
|
|
1924
2235
|
fromEvent(this.host, 'mouseleave')
|
|
1925
2236
|
.pipe(takeUntil(this.destroy$))
|
|
@@ -2086,17 +2397,11 @@ class PlaitBoardComponent {
|
|
|
2086
2397
|
this.cdr.markForCheck();
|
|
2087
2398
|
}
|
|
2088
2399
|
}
|
|
2089
|
-
PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.
|
|
2400
|
+
PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
|
|
2090
2401
|
PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins", plaitOptions: "plaitOptions" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass", "class.readonly": "this.readonly", "class.focused": "this.isFocused" } }, queries: [{ propertyName: "toolbarTemplateRef", first: true, predicate: ["plaitToolbar"], descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }, { propertyName: "viewportContainer", first: true, predicate: ["viewportContainer"], descendants: true, read: ElementRef, static: true }], usesOnChanges: true, ngImport: i0, template: `
|
|
2091
2402
|
<div class="viewport-container" #viewportContainer>
|
|
2092
2403
|
<svg #svg width="100%" height="100%" style="position: relative;"><g class="element-host"></g></svg>
|
|
2093
|
-
<plait-
|
|
2094
|
-
*ngFor="let item of board.children; let index = index; trackBy: trackBy"
|
|
2095
|
-
[index]="index"
|
|
2096
|
-
[element]="item"
|
|
2097
|
-
[board]="board"
|
|
2098
|
-
[selection]="board.selection"
|
|
2099
|
-
></plait-element>
|
|
2404
|
+
<plait-children [board]="board" [effect]="effect"></plait-children>
|
|
2100
2405
|
</div>
|
|
2101
2406
|
<plait-toolbar
|
|
2102
2407
|
*ngIf="isFocused && !toolbarTemplateRef"
|
|
@@ -2107,7 +2412,7 @@ PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", ve
|
|
|
2107
2412
|
(resetZoomHandel)="resetZoomHandel()"
|
|
2108
2413
|
></plait-toolbar>
|
|
2109
2414
|
<ng-content></ng-content>
|
|
2110
|
-
`, isInline: true, dependencies: [{ kind: "directive", type: i1.
|
|
2415
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: PlaitChildrenElement, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }, { kind: "component", type: PlaitToolbarComponent, selector: "plait-toolbar", inputs: ["board"], outputs: ["adaptHandle", "zoomInHandle", "zoomOutHandle", "resetZoomHandel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
2111
2416
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitBoardComponent, decorators: [{
|
|
2112
2417
|
type: Component,
|
|
2113
2418
|
args: [{
|
|
@@ -2115,13 +2420,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
|
|
|
2115
2420
|
template: `
|
|
2116
2421
|
<div class="viewport-container" #viewportContainer>
|
|
2117
2422
|
<svg #svg width="100%" height="100%" style="position: relative;"><g class="element-host"></g></svg>
|
|
2118
|
-
<plait-
|
|
2119
|
-
*ngFor="let item of board.children; let index = index; trackBy: trackBy"
|
|
2120
|
-
[index]="index"
|
|
2121
|
-
[element]="item"
|
|
2122
|
-
[board]="board"
|
|
2123
|
-
[selection]="board.selection"
|
|
2124
|
-
></plait-element>
|
|
2423
|
+
<plait-children [board]="board" [effect]="effect"></plait-children>
|
|
2125
2424
|
</div>
|
|
2126
2425
|
<plait-toolbar
|
|
2127
2426
|
*ngIf="isFocused && !toolbarTemplateRef"
|
|
@@ -2135,7 +2434,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
|
|
|
2135
2434
|
`,
|
|
2136
2435
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
2137
2436
|
}]
|
|
2138
|
-
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.
|
|
2437
|
+
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.NgZone }]; }, propDecorators: { plaitValue: [{
|
|
2139
2438
|
type: Input
|
|
2140
2439
|
}], plaitViewport: [{
|
|
2141
2440
|
type: Input
|
|
@@ -2167,79 +2466,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
|
|
|
2167
2466
|
args: ['viewportContainer', { read: ElementRef, static: true }]
|
|
2168
2467
|
}] } });
|
|
2169
2468
|
|
|
2170
|
-
|
|
2171
|
-
if (value.beforeContextChange) {
|
|
2172
|
-
return true;
|
|
2173
|
-
}
|
|
2174
|
-
return false;
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
class PlaitPluginElementComponent {
|
|
2178
|
-
set context(value) {
|
|
2179
|
-
if (hasBeforeContextChange(this)) {
|
|
2180
|
-
this.beforeContextChange(value);
|
|
2181
|
-
}
|
|
2182
|
-
const elementChanged = this.element && this.element !== value.element;
|
|
2183
|
-
if (elementChanged) {
|
|
2184
|
-
if (isSelectedElement(this.board, this.element)) {
|
|
2185
|
-
removeSelectedElement(this.board, this.element);
|
|
2186
|
-
addSelectedElement(this.board, value.element);
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
this._context = value;
|
|
2190
|
-
if (this.element) {
|
|
2191
|
-
ELEMENT_TO_PLUGIN_COMPONENT.set(this.element, this);
|
|
2192
|
-
}
|
|
2193
|
-
this.onContextChange();
|
|
2194
|
-
}
|
|
2195
|
-
get context() {
|
|
2196
|
-
return this._context;
|
|
2197
|
-
}
|
|
2198
|
-
get element() {
|
|
2199
|
-
return this.context && this.context.element;
|
|
2200
|
-
}
|
|
2201
|
-
get selection() {
|
|
2202
|
-
return this.context && this.context.selection;
|
|
2203
|
-
}
|
|
2204
|
-
get board() {
|
|
2205
|
-
return this.context && this.context.board;
|
|
2206
|
-
}
|
|
2207
|
-
constructor(cdr) {
|
|
2208
|
-
this.cdr = cdr;
|
|
2209
|
-
this.initialized = false;
|
|
2210
|
-
this.g = createG();
|
|
2211
|
-
}
|
|
2212
|
-
onContextChange() {
|
|
2213
|
-
if (!this.initialized) {
|
|
2214
|
-
return;
|
|
2215
|
-
}
|
|
2216
|
-
this.cdr.markForCheck();
|
|
2217
|
-
}
|
|
2218
|
-
ngOnInit() {
|
|
2219
|
-
const type = this.element?.type || 'default-plugin-element';
|
|
2220
|
-
this.g.setAttribute(`plait-${type}`, 'true');
|
|
2221
|
-
this.initialized = true;
|
|
2222
|
-
}
|
|
2223
|
-
ngOnDestroy() {
|
|
2224
|
-
ELEMENT_TO_PLUGIN_COMPONENT.delete(this.element);
|
|
2225
|
-
removeSelectedElement(this.board, this.element);
|
|
2226
|
-
this.g.remove();
|
|
2227
|
-
}
|
|
2228
|
-
}
|
|
2229
|
-
PlaitPluginElementComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitPluginElementComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
2230
|
-
PlaitPluginElementComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.5", type: PlaitPluginElementComponent, inputs: { context: "context" }, ngImport: i0 });
|
|
2231
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitPluginElementComponent, decorators: [{
|
|
2232
|
-
type: Directive
|
|
2233
|
-
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { context: [{
|
|
2234
|
-
type: Input
|
|
2235
|
-
}] } });
|
|
2236
|
-
const ELEMENT_TO_PLUGIN_COMPONENT = new WeakMap();
|
|
2237
|
-
|
|
2238
|
-
const COMPONENTS = [PlaitBoardComponent, PlaitElementComponent, PlaitToolbarComponent];
|
|
2469
|
+
const COMPONENTS = [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent, PlaitToolbarComponent];
|
|
2239
2470
|
class PlaitModule {
|
|
2240
2471
|
}
|
|
2241
2472
|
PlaitModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2242
|
-
PlaitModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, declarations: [PlaitBoardComponent, PlaitElementComponent, PlaitToolbarComponent], imports: [BrowserModule], exports: [PlaitBoardComponent, PlaitElementComponent, PlaitToolbarComponent] });
|
|
2473
|
+
PlaitModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, declarations: [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent, PlaitToolbarComponent], imports: [BrowserModule], exports: [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent, PlaitToolbarComponent] });
|
|
2243
2474
|
PlaitModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, imports: [BrowserModule] });
|
|
2244
2475
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, decorators: [{
|
|
2245
2476
|
type: NgModule,
|
|
@@ -2258,5 +2489,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
|
|
|
2258
2489
|
* Generated bundle index. Do not edit.
|
|
2259
2490
|
*/
|
|
2260
2491
|
|
|
2261
|
-
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY,
|
|
2492
|
+
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ELEMENT_TO_COMPONENT, FLUSHING, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NODE_TO_INDEX, NODE_TO_PARENT, NS, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPointerType, PlaitToolbarComponent, Point, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, changeZoom, clampZoomLevel, clearSelectionMoving, clearViewportOrigination, createG, createSVG, createSelectionOuterG, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawAbstractRoundRectangle, drawArrow, drawCircle, drawLine, drawRoundRectangle, fitViewport, getBoardRectangle, getElementHostBBox, getHitElements, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isFromScrolling, isFromViewportChange, isInPlaitBoard, isIntersectionElements, isNullOrUndefined, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, setViewport, shouldClear, shouldMerge, shouldSave, throttleRAF, toPoint, transformPoint, transformPoints, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withSelection };
|
|
2262
2493
|
//# sourceMappingURL=plait-core.mjs.map
|