@node-projects/web-component-designer 0.0.86 → 0.0.89
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/dist/elements/controls/PlainScrollbar.js +122 -116
- package/dist/elements/controls/SimpleSplitView.js +1 -1
- package/dist/elements/documentContainer.js +2 -0
- package/dist/elements/helper/ElementHelper.d.ts +1 -0
- package/dist/elements/helper/ElementHelper.js +10 -0
- package/dist/elements/item/DesignItem.d.ts +2 -0
- package/dist/elements/item/DesignItem.js +7 -0
- package/dist/elements/item/IDesignItem.d.ts +1 -0
- package/dist/elements/services/DefaultServiceBootstrap.js +0 -4
- package/dist/elements/services/ServiceContainer.d.ts +1 -3
- package/dist/elements/services/ServiceContainer.js +8 -3
- package/dist/elements/services/htmlParserService/NodeHtmlParserService.js +8 -0
- package/dist/elements/services/initializationService/DefaultIntializationService.js +12 -12
- package/dist/elements/services/instanceService/PrepareElementsForDesignerService.js +23 -23
- package/dist/elements/services/undoService/UndoService.js +3 -2
- package/dist/elements/services/undoService/transactionItems/InsertAction.js +0 -3
- package/dist/elements/widgets/designerView/IDesignerCanvas.d.ts +8 -0
- package/dist/elements/widgets/designerView/designerCanvas.d.ts +13 -1
- package/dist/elements/widgets/designerView/designerCanvas.js +129 -39
- package/dist/elements/widgets/designerView/designerCanvas.ts.BASE.d.ts +92 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.BASE.js +734 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.LOCAL.d.ts +95 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.LOCAL.js +768 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.REMOTE.d.ts +94 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.REMOTE.js +745 -0
- package/dist/elements/widgets/designerView/designerView.js +19 -15
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextExtension copy.d.ts +17 -0
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextExtension copy.js +80 -0
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextExtension.js +4 -2
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextExtensionProvider copy.d.ts +9 -0
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextExtensionProvider copy.js +11 -0
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextWithStyloExtension.d.ts +20 -0
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextWithStyloExtension.js +83 -0
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextWithStyloExtensionProvider.d.ts +10 -0
- package/dist/elements/widgets/designerView/extensions/EditText/EditTextWithStyloExtensionProvider.js +15 -0
- package/dist/elements/widgets/designerView/extensions/ElementDragTitleExtension.js +2 -2
- package/dist/elements/widgets/designerView/extensions/PathExtension.js +2 -5
- package/dist/elements/widgets/designerView/extensions/ResizeExtension.js +2 -1
- package/dist/elements/widgets/designerView/extensions/TransformOriginExtension.js +1 -0
- package/dist/elements/widgets/designerView/tools/DrawEllipsisTool.js +1 -0
- package/dist/elements/widgets/designerView/tools/DrawLineTool.js +1 -0
- package/dist/elements/widgets/designerView/tools/DrawPathTool.js +1 -0
- package/dist/elements/widgets/designerView/tools/DrawRectTool.js +1 -0
- package/dist/elements/widgets/designerView/tools/MagicWandSelectorTool.js +10 -9
- package/dist/elements/widgets/designerView/tools/PanTool.js +1 -0
- package/dist/elements/widgets/designerView/tools/PointerTool.js +4 -2
- package/dist/elements/widgets/designerView/tools/RectangleSelectorTool.js +10 -9
- package/dist/elements/widgets/designerView/tools/ZoomTool.d.ts +8 -1
- package/dist/elements/widgets/designerView/tools/ZoomTool.js +69 -0
- package/dist/elements/widgets/paletteView/paletteTreeView.js +5 -0
- package/dist/elements/widgets/treeView/treeView.js +1 -0
- package/dist/elements/widgets/treeView/treeViewExtended.js +21 -20
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -3
- package/package.json +5 -4
|
@@ -13,11 +13,13 @@ import { IPoint } from "../../../interfaces/IPoint";
|
|
|
13
13
|
import { OverlayLayer } from "./extensions/OverlayLayer";
|
|
14
14
|
import { OverlayLayerView } from './overlayLayerView';
|
|
15
15
|
import { IRect } from "../../../interfaces/IRect.js";
|
|
16
|
+
import { ISize } from "../../../interfaces/ISize.js";
|
|
16
17
|
export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend implements IDesignerCanvas, IPlacementView, IUiCommandHandler {
|
|
17
18
|
serviceContainer: ServiceContainer;
|
|
18
19
|
instanceServiceContainer: InstanceServiceContainer;
|
|
19
20
|
containerBoundingRect: DOMRect;
|
|
20
21
|
outerRect: DOMRect;
|
|
22
|
+
clickOverlay: HTMLDivElement;
|
|
21
23
|
gridSize: number;
|
|
22
24
|
alignOnGrid: boolean;
|
|
23
25
|
alignOnSnap: boolean;
|
|
@@ -29,12 +31,16 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
|
|
|
29
31
|
private _zoomFactor;
|
|
30
32
|
private _scaleFactor;
|
|
31
33
|
private _canvasOffset;
|
|
34
|
+
private _lastPointerDownHandler;
|
|
32
35
|
get zoomFactor(): number;
|
|
33
36
|
set zoomFactor(value: number);
|
|
34
37
|
get scaleFactor(): number;
|
|
35
38
|
get canvasOffset(): IPoint;
|
|
36
39
|
set canvasOffset(value: IPoint);
|
|
40
|
+
get canvasOffsetUnzoomed(): IPoint;
|
|
41
|
+
set canvasOffsetUnzoomed(value: IPoint);
|
|
37
42
|
onContentChanged: TypedEvent<void>;
|
|
43
|
+
onZoomFactorChanged: TypedEvent<number>;
|
|
38
44
|
private _canvas;
|
|
39
45
|
private _canvasContainer;
|
|
40
46
|
private _outercanvas2;
|
|
@@ -54,6 +60,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
|
|
|
54
60
|
set designerWidth(value: string);
|
|
55
61
|
get designerHeight(): string;
|
|
56
62
|
set designerHeight(value: string);
|
|
63
|
+
getDesignSurfaceDimensions(): ISize;
|
|
57
64
|
get designerOffsetWidth(): number;
|
|
58
65
|
get designerOffsetHeight(): number;
|
|
59
66
|
set additionalStyle(value: CSSStyleSheet);
|
|
@@ -66,7 +73,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
|
|
|
66
73
|
initialize(serviceContainer: ServiceContainer): void;
|
|
67
74
|
elementFromPoint(x: number, y: number): Element;
|
|
68
75
|
connectedCallback(): void;
|
|
69
|
-
|
|
76
|
+
private _zoomFactorChanged;
|
|
70
77
|
_updateTransform(): void;
|
|
71
78
|
setDesignItems(designItems: IDesignItem[]): void;
|
|
72
79
|
addDesignItems(designItems: IDesignItem[]): void;
|
|
@@ -80,13 +87,18 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
|
|
|
80
87
|
private onKeyUp;
|
|
81
88
|
private onKeyDown;
|
|
82
89
|
getNormalizedEventCoordinates(event: MouseEvent): IPoint;
|
|
90
|
+
convertEventToViewPortCoordinates(point: IPoint): IPoint;
|
|
91
|
+
getViewportCoordinates(event: MouseEvent): IPoint;
|
|
83
92
|
getNormalizedElementCoordinates(element: Element): IRect;
|
|
84
93
|
getNormalizedOffsetInElement(event: MouseEvent, element: Element): IPoint;
|
|
85
94
|
getElementAtPoint(point: IPoint, ignoreElementCallback?: (element: HTMLElement) => boolean): HTMLElement;
|
|
86
95
|
_rect: SVGRectElement;
|
|
87
96
|
private _pointerEventHandler;
|
|
97
|
+
removeCurrentPointerEventHandler(): void;
|
|
88
98
|
private _fillCalculationrects;
|
|
89
99
|
addOverlay(element: SVGGraphicsElement, overlayLayer?: OverlayLayer): void;
|
|
90
100
|
removeOverlay(element: SVGGraphicsElement): void;
|
|
91
101
|
getItemsBelowMouse(event: MouseEvent): Element[];
|
|
102
|
+
zoomOntoRectangle(startPoint: IPoint, endPoint: IPoint): void;
|
|
103
|
+
zoomTowardsPoint(canvasPoint: IPoint, newZoom: number): void;
|
|
92
104
|
}
|
|
@@ -26,6 +26,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
26
26
|
instanceServiceContainer;
|
|
27
27
|
containerBoundingRect;
|
|
28
28
|
outerRect;
|
|
29
|
+
clickOverlay;
|
|
29
30
|
// IPlacementView
|
|
30
31
|
gridSize = 10;
|
|
31
32
|
alignOnGrid = false;
|
|
@@ -38,12 +39,13 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
38
39
|
_zoomFactor = 1; //if scale or zoom css property is used this needs to be the value
|
|
39
40
|
_scaleFactor = 1; //if scale css property is used this need to be the scale value
|
|
40
41
|
_canvasOffset = { x: 0, y: 0 };
|
|
42
|
+
_lastPointerDownHandler;
|
|
41
43
|
get zoomFactor() {
|
|
42
44
|
return this._zoomFactor;
|
|
43
45
|
}
|
|
44
46
|
set zoomFactor(value) {
|
|
45
47
|
this._zoomFactor = value;
|
|
46
|
-
this.
|
|
48
|
+
this._zoomFactorChanged();
|
|
47
49
|
}
|
|
48
50
|
get scaleFactor() {
|
|
49
51
|
return this._scaleFactor;
|
|
@@ -53,9 +55,16 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
53
55
|
}
|
|
54
56
|
set canvasOffset(value) {
|
|
55
57
|
this._canvasOffset = value;
|
|
56
|
-
this.
|
|
58
|
+
this._zoomFactorChanged();
|
|
59
|
+
}
|
|
60
|
+
get canvasOffsetUnzoomed() {
|
|
61
|
+
return { x: this._canvasOffset.x * this.zoomFactor, y: this._canvasOffset.y * this.zoomFactor };
|
|
62
|
+
}
|
|
63
|
+
set canvasOffsetUnzoomed(value) {
|
|
64
|
+
this.canvasOffset = { x: value.x / this.zoomFactor, y: value.y / this.zoomFactor };
|
|
57
65
|
}
|
|
58
66
|
onContentChanged = new TypedEvent();
|
|
67
|
+
onZoomFactorChanged = new TypedEvent();
|
|
59
68
|
// Private Variables
|
|
60
69
|
_canvas;
|
|
61
70
|
_canvasContainer;
|
|
@@ -119,23 +128,30 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
119
128
|
user-select: none;
|
|
120
129
|
-webkit-user-select: none;
|
|
121
130
|
}
|
|
131
|
+
|
|
132
|
+
#node-projects-designer-canvas-clickOverlay {
|
|
133
|
+
position: absolute;
|
|
134
|
+
width: 100%;
|
|
135
|
+
height: 100%;
|
|
136
|
+
top: 0;
|
|
137
|
+
}
|
|
122
138
|
|
|
123
|
-
#transformHelper {
|
|
139
|
+
#node-projects-designer-canvas-transformHelper {
|
|
124
140
|
height: 0;
|
|
125
141
|
width: 0;
|
|
126
142
|
}`;
|
|
127
143
|
static template = html `
|
|
128
144
|
<div style="display: flex;flex-direction: column;width: 100%;height: 100%;">
|
|
129
145
|
<div style="width: 100%;height: 100%;">
|
|
130
|
-
<div id="node-projects-designer-canvas-outercanvas2"
|
|
131
|
-
style="width:100%;height:100%;position:relative;">
|
|
146
|
+
<div id="node-projects-designer-canvas-outercanvas2" style="width:100%;height:100%;position:relative;">
|
|
132
147
|
<div id="node-projects-designer-canvas-canvasContainer"
|
|
133
|
-
style="width: 100%;height: 100%;
|
|
134
|
-
<div id="node-projects-designer-canvas-canvas" part="canvas"
|
|
148
|
+
style="width: 100%;height: 100%;position: absolute;top: 0;left: 0;user-select: none;">
|
|
149
|
+
<div id="node-projects-designer-canvas-canvas" part="canvas"></div>
|
|
135
150
|
</div>
|
|
136
151
|
</div>
|
|
152
|
+
<div id="node-projects-designer-canvas-clickOverlay" tabindex="0" style="pointer-events: auto;"></div>
|
|
137
153
|
</div>
|
|
138
|
-
<div id="transformHelper"></div>
|
|
154
|
+
<div id="node-projects-designer-canvas-transformHelper"></div>
|
|
139
155
|
</div>`;
|
|
140
156
|
extensionManager;
|
|
141
157
|
_pointerextensions;
|
|
@@ -145,27 +161,37 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
145
161
|
this._canvas = this._getDomElement('node-projects-designer-canvas-canvas');
|
|
146
162
|
this._canvasContainer = this._getDomElement('node-projects-designer-canvas-canvasContainer');
|
|
147
163
|
this._outercanvas2 = this._getDomElement('node-projects-designer-canvas-outercanvas2');
|
|
148
|
-
this.
|
|
164
|
+
this.clickOverlay = this._getDomElement('node-projects-designer-canvas-clickOverlay');
|
|
165
|
+
this.transformHelperElement = this._getDomElement('node-projects-designer-canvas-transformHelper');
|
|
149
166
|
this._onKeyDownBound = this.onKeyDown.bind(this);
|
|
150
167
|
this._onKeyUpBound = this.onKeyUp.bind(this);
|
|
151
168
|
this._onDblClickBound = this._onDblClick.bind(this);
|
|
152
169
|
this._onContextMenuBound = this._onContextMenu.bind(this);
|
|
153
170
|
this._pointerEventHandlerBound = this._pointerEventHandler.bind(this);
|
|
154
|
-
this.
|
|
171
|
+
this.clickOverlay.oncontextmenu = this._onContextMenuBound;
|
|
155
172
|
}
|
|
156
173
|
get designerWidth() {
|
|
157
174
|
return this._canvasContainer.style.width;
|
|
158
175
|
}
|
|
159
176
|
set designerWidth(value) {
|
|
160
177
|
this._canvasContainer.style.width = value;
|
|
161
|
-
this.
|
|
178
|
+
this._zoomFactorChanged();
|
|
162
179
|
}
|
|
163
180
|
get designerHeight() {
|
|
164
181
|
return this._canvasContainer.style.height;
|
|
165
182
|
}
|
|
166
183
|
set designerHeight(value) {
|
|
167
184
|
this._canvasContainer.style.height = value;
|
|
168
|
-
this.
|
|
185
|
+
this._zoomFactorChanged();
|
|
186
|
+
}
|
|
187
|
+
getDesignSurfaceDimensions() {
|
|
188
|
+
let ret = { width: null, height: null };
|
|
189
|
+
const cs = getComputedStyle(this._canvasContainer);
|
|
190
|
+
if (this._canvasContainer.style.width)
|
|
191
|
+
ret.width = parseFloat(cs.width);
|
|
192
|
+
if (this._canvasContainer.style.height)
|
|
193
|
+
ret.height = parseFloat(cs.height);
|
|
194
|
+
return ret;
|
|
169
195
|
}
|
|
170
196
|
get designerOffsetWidth() {
|
|
171
197
|
return this._canvasContainer.offsetWidth;
|
|
@@ -338,25 +364,30 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
338
364
|
}
|
|
339
365
|
}
|
|
340
366
|
elementFromPoint(x, y) {
|
|
367
|
+
this.clickOverlay.style.pointerEvents = 'none';
|
|
341
368
|
//@ts-ignore
|
|
342
|
-
|
|
369
|
+
let element = this.shadowRoot.elementFromPoint(x, y);
|
|
370
|
+
if (element === this.clickOverlay)
|
|
371
|
+
element = this._canvas;
|
|
372
|
+
this.clickOverlay.style.pointerEvents = 'auto';
|
|
373
|
+
return element;
|
|
343
374
|
}
|
|
344
375
|
connectedCallback() {
|
|
345
376
|
if (!this._firstConnect) {
|
|
346
377
|
this._firstConnect = true;
|
|
347
|
-
this.
|
|
348
|
-
this.
|
|
349
|
-
this.
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
this.
|
|
354
|
-
this.
|
|
355
|
-
this.
|
|
356
|
-
this.
|
|
378
|
+
this.clickOverlay.addEventListener(EventNames.PointerDown, this._pointerEventHandlerBound);
|
|
379
|
+
this.clickOverlay.addEventListener(EventNames.PointerMove, this._pointerEventHandlerBound);
|
|
380
|
+
this.clickOverlay.addEventListener(EventNames.PointerUp, this._pointerEventHandlerBound);
|
|
381
|
+
this.clickOverlay.addEventListener(EventNames.DragEnter, event => this._onDragEnter(event));
|
|
382
|
+
this.clickOverlay.addEventListener(EventNames.DragLeave, event => this._onDragLeave(event));
|
|
383
|
+
this.clickOverlay.addEventListener(EventNames.DragOver, event => this._onDragOver(event));
|
|
384
|
+
this.clickOverlay.addEventListener(EventNames.Drop, event => this._onDrop(event));
|
|
385
|
+
this.clickOverlay.addEventListener(EventNames.KeyDown, this._onKeyDownBound, true);
|
|
386
|
+
this.clickOverlay.addEventListener(EventNames.KeyUp, this._onKeyUpBound, true);
|
|
387
|
+
this.clickOverlay.addEventListener(EventNames.DblClick, this._onDblClickBound, true);
|
|
357
388
|
}
|
|
358
389
|
}
|
|
359
|
-
|
|
390
|
+
_zoomFactorChanged() {
|
|
360
391
|
//a@ts-ignore
|
|
361
392
|
//this._canvasContainer.style.zoom = <any>this._zoomFactor;
|
|
362
393
|
//this._canvasContainer.style.transform = 'scale(' + this._zoomFactor+') translate(' + this._translate.x + ', '+this._translate.y+')';
|
|
@@ -364,10 +395,11 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
364
395
|
this._canvasContainer.style.bottom = this._outercanvas2.offsetHeight >= this._canvasContainer.offsetHeight ? '0' : '';
|
|
365
396
|
this._canvasContainer.style.right = this._outercanvas2.offsetWidth >= this._canvasContainer.offsetWidth ? '0' : '';
|
|
366
397
|
this._updateTransform();
|
|
398
|
+
this.onZoomFactorChanged.emit(this._zoomFactor);
|
|
367
399
|
}
|
|
368
400
|
_updateTransform() {
|
|
369
401
|
this._scaleFactor = this._zoomFactor;
|
|
370
|
-
this._canvasContainer.style.transform = 'scale(' + this._zoomFactor + ') translate(' + this._canvasOffset.x + 'px, ' + this._canvasOffset.y + 'px)';
|
|
402
|
+
this._canvasContainer.style.transform = 'scale(' + this._zoomFactor + ') translate(' + (isNaN(this._canvasOffset.x) ? '0' : this._canvasOffset.x) + 'px, ' + (isNaN(this._canvasOffset.y) ? '0' : this._canvasOffset.y) + 'px)';
|
|
371
403
|
this._canvasContainer.style.transformOrigin = '0 0';
|
|
372
404
|
this.snapLines.clearSnaplines();
|
|
373
405
|
}
|
|
@@ -392,9 +424,6 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
392
424
|
intializationService.init(di);
|
|
393
425
|
}
|
|
394
426
|
this.snapLines.clearSnaplines();
|
|
395
|
-
const prepService = this.serviceContainer.prepareElementsForDesignerService;
|
|
396
|
-
if (prepService)
|
|
397
|
-
requestAnimationFrame(() => prepService.prepareElementsForDesigner(this.rootDesignItem));
|
|
398
427
|
}
|
|
399
428
|
_onDragEnter(event) {
|
|
400
429
|
this._fillCalculationrects();
|
|
@@ -517,17 +546,11 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
517
546
|
onKeyUp(event) {
|
|
518
547
|
if (event.composedPath().indexOf(this.eatEvents) >= 0)
|
|
519
548
|
return;
|
|
520
|
-
switch (event.key) {
|
|
521
|
-
case 'ArrowUp':
|
|
522
|
-
//this._resetPointerEventsForClickThrough();
|
|
523
|
-
break;
|
|
524
|
-
}
|
|
525
549
|
event.preventDefault();
|
|
526
550
|
}
|
|
527
551
|
onKeyDown(event) {
|
|
528
552
|
if (event.composedPath().indexOf(this.eatEvents) >= 0)
|
|
529
553
|
return;
|
|
530
|
-
//TODO: keyboard events maybe should also be handeled by tools
|
|
531
554
|
if ((event.ctrlKey || event.metaKey) && event.key === 'z' && !event.shiftKey)
|
|
532
555
|
this.executeCommand({ type: CommandType.undo });
|
|
533
556
|
else if ((event.ctrlKey || event.metaKey) && event.key === 'z' && event.shiftKey)
|
|
@@ -585,12 +608,26 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
585
608
|
}
|
|
586
609
|
getNormalizedEventCoordinates(event) {
|
|
587
610
|
const offsetOfOuterX = (event.clientX - this.outerRect.x) / this.zoomFactor;
|
|
588
|
-
const offsetOfCanvasX = this.containerBoundingRect.x - this.outerRect.x
|
|
611
|
+
const offsetOfCanvasX = this.containerBoundingRect.x - this.outerRect.x;
|
|
589
612
|
const offsetOfOuterY = (event.clientY - this.outerRect.y) / this.zoomFactor;
|
|
590
|
-
const offsetOfCanvasY = this.containerBoundingRect.y - this.outerRect.y
|
|
613
|
+
const offsetOfCanvasY = this.containerBoundingRect.y - this.outerRect.y;
|
|
591
614
|
return {
|
|
592
|
-
x: offsetOfOuterX - offsetOfCanvasX
|
|
593
|
-
y: offsetOfOuterY - offsetOfCanvasY
|
|
615
|
+
x: offsetOfOuterX - offsetOfCanvasX / this.zoomFactor,
|
|
616
|
+
y: offsetOfOuterY - offsetOfCanvasY / this.zoomFactor
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
convertEventToViewPortCoordinates(point) {
|
|
620
|
+
const offsetOfCanvasX = this.containerBoundingRect.x - this.outerRect.x;
|
|
621
|
+
const offsetOfCanvasY = this.containerBoundingRect.y - this.outerRect.y;
|
|
622
|
+
return {
|
|
623
|
+
x: (point.x + offsetOfCanvasX / this.zoomFactor) * this.zoomFactor,
|
|
624
|
+
y: (point.y + offsetOfCanvasY / this.zoomFactor) * this.zoomFactor
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
getViewportCoordinates(event) {
|
|
628
|
+
return {
|
|
629
|
+
x: (event.clientX - this.outerRect.x),
|
|
630
|
+
y: (event.clientY - this.outerRect.y)
|
|
594
631
|
};
|
|
595
632
|
}
|
|
596
633
|
getNormalizedElementCoordinates(element) {
|
|
@@ -605,6 +642,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
605
642
|
getElementAtPoint(point, ignoreElementCallback) {
|
|
606
643
|
let backupPEventsMap = new Map();
|
|
607
644
|
let currentElement = this.elementFromPoint(point.x, point.y);
|
|
645
|
+
this.clickOverlay.style.pointerEvents = 'none';
|
|
608
646
|
let lastElement = null;
|
|
609
647
|
try {
|
|
610
648
|
while (currentElement != null) {
|
|
@@ -641,6 +679,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
641
679
|
for (let e of backupPEventsMap.entries()) {
|
|
642
680
|
e[0].style.pointerEvents = e[1];
|
|
643
681
|
}
|
|
682
|
+
this.clickOverlay.style.pointerEvents = 'auto';
|
|
644
683
|
}
|
|
645
684
|
return currentElement;
|
|
646
685
|
}
|
|
@@ -667,6 +706,24 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
667
706
|
if (!DesignerCanvas.hasOrIsParent(currentElement, this._canvas))
|
|
668
707
|
return;
|
|
669
708
|
}*/
|
|
709
|
+
if (this._lastPointerDownHandler) {
|
|
710
|
+
try {
|
|
711
|
+
this._lastPointerDownHandler(event);
|
|
712
|
+
}
|
|
713
|
+
catch { }
|
|
714
|
+
if (event.type == EventNames.PointerUp)
|
|
715
|
+
this._lastPointerDownHandler = null;
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if (currentElement instanceof SVGGraphicsElement && currentElement?.ownerSVGElement?.parentNode?.host == this.overlayLayer) {
|
|
719
|
+
this.clickOverlay.style.cursor = getComputedStyle(currentElement).cursor;
|
|
720
|
+
if (event.type == EventNames.PointerDown) {
|
|
721
|
+
this._lastPointerDownHandler = (evt) => currentElement.dispatchEvent(new evt.constructor(evt.type, evt));
|
|
722
|
+
}
|
|
723
|
+
currentElement.dispatchEvent(new event.constructor(event.type, event));
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
this.clickOverlay.style.cursor = this._canvas.style.cursor;
|
|
670
727
|
//TODO: remove duplication when tool refactoring starts
|
|
671
728
|
//this._fillCalculationrects();
|
|
672
729
|
const currentDesignItem = DesignItem.GetOrCreateDesignItem(currentElement, this.serviceContainer, this.instanceServiceContainer);
|
|
@@ -685,8 +742,14 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
685
742
|
this._fillCalculationrects();
|
|
686
743
|
let tool = this.serviceContainer.globalContext.tool ?? this.serviceContainer.designerTools.get(NamedTools.Pointer);
|
|
687
744
|
this._canvas.style.cursor = tool.cursor;
|
|
745
|
+
if (event.type == EventNames.PointerDown) {
|
|
746
|
+
this._lastPointerDownHandler = (evt) => tool.pointerEventHandler(this, evt, currentElement);
|
|
747
|
+
}
|
|
688
748
|
tool.pointerEventHandler(this, event, currentElement);
|
|
689
749
|
}
|
|
750
|
+
removeCurrentPointerEventHandler() {
|
|
751
|
+
this._lastPointerDownHandler = null;
|
|
752
|
+
}
|
|
690
753
|
_fillCalculationrects() {
|
|
691
754
|
this.containerBoundingRect = this._canvasContainer.getBoundingClientRect();
|
|
692
755
|
this.outerRect = this._outercanvas2.getBoundingClientRect();
|
|
@@ -702,12 +765,12 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
702
765
|
//search for containers below mouse cursor.
|
|
703
766
|
//to do this, we need to disable pointer events for each in a loop and search wich element is there
|
|
704
767
|
let backupPEventsMap = new Map();
|
|
768
|
+
this.clickOverlay.style.pointerEvents = 'none';
|
|
705
769
|
try {
|
|
706
770
|
let el = this.elementFromPoint(event.x, event.y);
|
|
707
771
|
backupPEventsMap.set(el, el.style.pointerEvents);
|
|
708
772
|
el.style.pointerEvents = 'none';
|
|
709
773
|
if (el !== this.rootDesignItem.element) {
|
|
710
|
-
el = this.elementFromPoint(event.x, event.y);
|
|
711
774
|
while (el != null) {
|
|
712
775
|
if (el === this.rootDesignItem.element)
|
|
713
776
|
break;
|
|
@@ -727,8 +790,35 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
727
790
|
for (let e of backupPEventsMap.entries()) {
|
|
728
791
|
e[0].style.pointerEvents = e[1];
|
|
729
792
|
}
|
|
793
|
+
this.clickOverlay.style.pointerEvents = 'auto';
|
|
730
794
|
}
|
|
731
795
|
return lstEl;
|
|
732
796
|
}
|
|
797
|
+
zoomOntoRectangle(startPoint, endPoint) {
|
|
798
|
+
let rect = {
|
|
799
|
+
x: startPoint.x < endPoint.x ? startPoint.x : endPoint.x,
|
|
800
|
+
y: startPoint.y < endPoint.y ? startPoint.y : endPoint.y,
|
|
801
|
+
width: Math.abs(startPoint.x - endPoint.x),
|
|
802
|
+
height: Math.abs(startPoint.y - endPoint.y),
|
|
803
|
+
};
|
|
804
|
+
let zFactorWidth = this.outerRect.width / rect.width;
|
|
805
|
+
let zFactorHeight = this.outerRect.height / rect.height;
|
|
806
|
+
let zoomFactor = zFactorWidth >= zFactorHeight ? zFactorHeight : zFactorWidth;
|
|
807
|
+
let rectCenter = {
|
|
808
|
+
x: (rect.width / 2) + rect.x,
|
|
809
|
+
y: (rect.height / 2) + rect.y
|
|
810
|
+
};
|
|
811
|
+
this.zoomTowardsPoint(rectCenter, zoomFactor);
|
|
812
|
+
}
|
|
813
|
+
zoomTowardsPoint(canvasPoint, newZoom) {
|
|
814
|
+
const scaleChange = newZoom / this.zoomFactor;
|
|
815
|
+
const point = this.convertEventToViewPortCoordinates(canvasPoint);
|
|
816
|
+
const newCanvasOffset = {
|
|
817
|
+
x: -(point.x * (scaleChange - 1) + scaleChange * -this.canvasOffsetUnzoomed.x),
|
|
818
|
+
y: -(point.y * (scaleChange - 1) + scaleChange * -this.canvasOffsetUnzoomed.y)
|
|
819
|
+
};
|
|
820
|
+
this.zoomFactor = newZoom;
|
|
821
|
+
this.canvasOffsetUnzoomed = newCanvasOffset;
|
|
822
|
+
}
|
|
733
823
|
}
|
|
734
824
|
customElements.define('node-projects-designer-canvas', DesignerCanvas);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ServiceContainer } from '../../services/ServiceContainer';
|
|
2
|
+
import { InstanceServiceContainer } from '../../services/InstanceServiceContainer';
|
|
3
|
+
import { IDesignItem } from '../../item/IDesignItem';
|
|
4
|
+
import { BaseCustomWebComponentLazyAppend, TypedEvent } from '@node-projects/base-custom-webcomponent';
|
|
5
|
+
import { IDesignerCanvas } from './IDesignerCanvas';
|
|
6
|
+
import { Snaplines } from './Snaplines';
|
|
7
|
+
import { ContextMenuHelper } from '../../helper/contextMenu/ContextMenuHelper';
|
|
8
|
+
import { IPlacementView } from './IPlacementView';
|
|
9
|
+
import { IUiCommandHandler } from '../../../commandHandling/IUiCommandHandler';
|
|
10
|
+
import { IUiCommand } from '../../../commandHandling/IUiCommand';
|
|
11
|
+
import { IExtensionManager } from "./extensions/IExtensionManger";
|
|
12
|
+
import { IPoint } from "../../../interfaces/IPoint";
|
|
13
|
+
import { OverlayLayer } from "./extensions/OverlayLayer";
|
|
14
|
+
import { OverlayLayerView } from './overlayLayerView';
|
|
15
|
+
import { IRect } from "../../../interfaces/IRect.js";
|
|
16
|
+
export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend implements IDesignerCanvas, IPlacementView, IUiCommandHandler {
|
|
17
|
+
serviceContainer: ServiceContainer;
|
|
18
|
+
instanceServiceContainer: InstanceServiceContainer;
|
|
19
|
+
containerBoundingRect: DOMRect;
|
|
20
|
+
outerRect: DOMRect;
|
|
21
|
+
gridSize: number;
|
|
22
|
+
alignOnGrid: boolean;
|
|
23
|
+
alignOnSnap: boolean;
|
|
24
|
+
snapLines: Snaplines;
|
|
25
|
+
overlayLayer: OverlayLayerView;
|
|
26
|
+
rootDesignItem: IDesignItem;
|
|
27
|
+
eatEvents: Element;
|
|
28
|
+
transformHelperElement: HTMLDivElement;
|
|
29
|
+
private _zoomFactor;
|
|
30
|
+
private _scaleFactor;
|
|
31
|
+
private _canvasOffset;
|
|
32
|
+
get zoomFactor(): number;
|
|
33
|
+
set zoomFactor(value: number);
|
|
34
|
+
get scaleFactor(): number;
|
|
35
|
+
get canvasOffset(): IPoint;
|
|
36
|
+
set canvasOffset(value: IPoint);
|
|
37
|
+
onContentChanged: TypedEvent<void>;
|
|
38
|
+
private _canvas;
|
|
39
|
+
private _canvasContainer;
|
|
40
|
+
private _outercanvas2;
|
|
41
|
+
private _lastHoverDesignItem;
|
|
42
|
+
private _onContextMenuBound;
|
|
43
|
+
private _pointerEventHandlerBound;
|
|
44
|
+
private _firstConnect;
|
|
45
|
+
private _onKeyDownBound;
|
|
46
|
+
private _onKeyUpBound;
|
|
47
|
+
static readonly style: CSSStyleSheet;
|
|
48
|
+
static readonly template: HTMLTemplateElement;
|
|
49
|
+
extensionManager: IExtensionManager;
|
|
50
|
+
private _pointerextensions;
|
|
51
|
+
private _onDblClickBound;
|
|
52
|
+
constructor();
|
|
53
|
+
get designerWidth(): string;
|
|
54
|
+
set designerWidth(value: string);
|
|
55
|
+
get designerHeight(): string;
|
|
56
|
+
set designerHeight(value: string);
|
|
57
|
+
get designerOffsetWidth(): number;
|
|
58
|
+
get designerOffsetHeight(): number;
|
|
59
|
+
set additionalStyle(value: CSSStyleSheet);
|
|
60
|
+
executeCommand(command: IUiCommand): Promise<void>;
|
|
61
|
+
canExecuteCommand(command: IUiCommand): boolean;
|
|
62
|
+
handleSelectAll(): void;
|
|
63
|
+
handleCopyCommand(): Promise<void>;
|
|
64
|
+
handlePasteCommand(): Promise<void>;
|
|
65
|
+
handleDeleteCommand(): void;
|
|
66
|
+
initialize(serviceContainer: ServiceContainer): void;
|
|
67
|
+
elementFromPoint(x: number, y: number): Element;
|
|
68
|
+
connectedCallback(): void;
|
|
69
|
+
zoomFactorChanged(): void;
|
|
70
|
+
_updateTransform(): void;
|
|
71
|
+
setDesignItems(designItems: IDesignItem[]): void;
|
|
72
|
+
addDesignItems(designItems: IDesignItem[]): void;
|
|
73
|
+
private _onDragEnter;
|
|
74
|
+
private _onDragLeave;
|
|
75
|
+
private _onDragOver;
|
|
76
|
+
private _onDrop;
|
|
77
|
+
private _onContextMenu;
|
|
78
|
+
showDesignItemContextMenu(designItem: IDesignItem, event: MouseEvent): ContextMenuHelper;
|
|
79
|
+
private _onDblClick;
|
|
80
|
+
private onKeyUp;
|
|
81
|
+
private onKeyDown;
|
|
82
|
+
getNormalizedEventCoordinates(event: MouseEvent): IPoint;
|
|
83
|
+
getNormalizedElementCoordinates(element: Element): IRect;
|
|
84
|
+
getNormalizedOffsetInElement(event: MouseEvent, element: Element): IPoint;
|
|
85
|
+
getElementAtPoint(point: IPoint, ignoreElementCallback?: (element: HTMLElement) => boolean): HTMLElement;
|
|
86
|
+
_rect: SVGRectElement;
|
|
87
|
+
private _pointerEventHandler;
|
|
88
|
+
private _fillCalculationrects;
|
|
89
|
+
addOverlay(element: SVGGraphicsElement, overlayLayer?: OverlayLayer): void;
|
|
90
|
+
removeOverlay(element: SVGGraphicsElement): void;
|
|
91
|
+
getItemsBelowMouse(event: MouseEvent): Element[];
|
|
92
|
+
}
|