@node-projects/web-component-designer 0.1.85 → 0.1.87

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.
@@ -75,6 +75,21 @@ export function getElementsWindowOffsetWithoutSelfAndParentTransformations(eleme
75
75
  lst.forEach(x => { x.offsetLeft += cachedObj.offsetLeft; x.offsetTop += cachedObj.offsetTop; });
76
76
  break;
77
77
  }
78
+ let nextParent = element.offsetParent ? element.offsetParent : element.getRootNode().host;
79
+ if (element instanceof SVGGraphicsElement) {
80
+ nextParent = element.ownerSVGElement;
81
+ }
82
+ else if (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {
83
+ nextParent = element.parentElement ? element.parentElement : element.getRootNode().host;
84
+ }
85
+ let scrollLeft = 0;
86
+ let scrollTop = 0;
87
+ if (nextParent) {
88
+ scrollLeft = nextParent.scrollLeft ?? 0;
89
+ scrollTop = nextParent.scrollTop ?? 0;
90
+ }
91
+ let currLeft = 0;
92
+ let currTop = 0;
78
93
  if (element instanceof SVGSVGElement) {
79
94
  //TODO: !huge Perf impact! - fix without transformation
80
95
  let t = element.style.transform;
@@ -82,43 +97,25 @@ export function getElementsWindowOffsetWithoutSelfAndParentTransformations(eleme
82
97
  const bcEl = element.getBoundingClientRect();
83
98
  const bcPar = element.parentElement ? element.parentElement.getBoundingClientRect() : element.getRootNode().host.getBoundingClientRect();
84
99
  element.style.transform = t;
85
- const currLeft = (bcEl.left - bcPar.left) / zoom;
86
- const currTop = (bcEl.top - bcPar.top) / zoom;
87
- offsetLeft += currLeft;
88
- offsetTop += currTop;
89
- lst.forEach(x => { x.offsetLeft += currLeft; x.offsetTop += currTop; });
90
- const cacheEntry = { offsetLeft: currLeft, offsetTop: currTop };
91
- lst.push(cacheEntry);
92
- ch.set(element, cacheEntry);
93
- element = element.parentElement ? element.parentElement : element.getRootNode().host;
100
+ currLeft = (bcEl.left - bcPar.left) / zoom;
101
+ currTop = (bcEl.top - bcPar.top) / zoom;
94
102
  }
95
103
  else if (element instanceof SVGGraphicsElement) {
96
104
  let bbox = element.getBBox();
97
- offsetLeft += bbox.x;
98
- offsetTop += bbox.y;
99
- lst.forEach(x => { x.offsetLeft += bbox.x; x.offsetTop += bbox.y; });
100
- const cacheEntry = { offsetLeft: bbox.x, offsetTop: bbox.y };
101
- lst.push(cacheEntry);
102
- ch.set(element, cacheEntry);
103
- element = element.ownerSVGElement;
104
- }
105
- else if (element instanceof HTMLBodyElement) {
106
- element = element.parentElement ? element.parentElement : element.getRootNode().host;
107
- }
108
- else if (element instanceof HTMLHtmlElement) {
109
- element = element.parentElement ? element.parentElement : element.getRootNode().host;
105
+ currLeft = bbox.x;
106
+ currTop = bbox.y;
110
107
  }
111
108
  else {
112
- const currLeft = element.offsetLeft;
113
- const currTop = element.offsetTop;
114
- lst.forEach(x => { x.offsetLeft += currLeft; x.offsetTop += currTop; });
115
- const cacheEntry = { offsetLeft: currLeft, offsetTop: currTop };
116
- lst.push(cacheEntry);
117
- ch.set(element, cacheEntry);
118
- offsetLeft += element.offsetLeft;
119
- offsetTop += element.offsetTop;
120
- element = element.offsetParent ? element.offsetParent : element.getRootNode().host;
109
+ currLeft = element.offsetLeft - scrollLeft;
110
+ currTop = element.offsetTop - scrollTop;
121
111
  }
112
+ lst.forEach(x => { x.offsetLeft += currLeft; x.offsetTop += currTop; });
113
+ const cacheEntry = { offsetLeft: currLeft, offsetTop: currTop };
114
+ lst.push(cacheEntry);
115
+ ch.set(element, cacheEntry);
116
+ offsetLeft += currLeft;
117
+ offsetTop += currTop;
118
+ element = nextParent;
122
119
  }
123
120
  return { offsetLeft: offsetLeft, offsetTop: offsetTop };
124
121
  }
@@ -47,6 +47,7 @@ export class DemoView extends BaseCustomWebComponentLazyAppend {
47
47
  super();
48
48
  this._placeholder = document.createElement('div');
49
49
  this._placeholder.id = 'placeholder';
50
+ this._placeholder.style.transform = 'scale(1)'; //to fix position: static alignment
50
51
  this.shadowRoot.appendChild(this._placeholder);
51
52
  this._loading = document.createElement('div');
52
53
  this._loading.id = 'loading';
@@ -26,8 +26,9 @@ export declare class EllipsisExtension extends AbstractExtension {
26
26
  private _offsetSvg;
27
27
  constructor(extensionManager: IExtensionManager, designerView: IDesignerCanvas, extendedItem: IDesignItem);
28
28
  extend(): void;
29
+ refresh(): void;
29
30
  pointerEvent(event: PointerEvent, circle: SVGCircleElement, e: SVGEllipseElement, index: number): void;
30
- _drawPathCircle(x: number, y: number, e: SVGEllipseElement, index: number): SVGCircleElement;
31
+ _drawPathCircle(x: number, y: number, e: SVGEllipseElement, index: number, circle: SVGCircleElement): SVGCircleElement;
31
32
  _redrawPathCircle(x: number, y: number, oldCircle: SVGCircleElement): SVGCircleElement;
32
33
  _getPointsFromEllipse(elementCoords: IRect): number[];
33
34
  _getMinMaxValues(coords: any): {
@@ -38,6 +39,5 @@ export declare class EllipsisExtension extends AbstractExtension {
38
39
  };
39
40
  _rearrangeSvgParent(newEllipseExtrema: any): void;
40
41
  _rearrangePointsFromElement(oldParentCoords: IRect): void;
41
- refresh(): void;
42
42
  dispose(): void;
43
43
  }
@@ -25,6 +25,9 @@ export class EllipsisExtension extends AbstractExtension {
25
25
  super(extensionManager, designerView, extendedItem);
26
26
  }
27
27
  extend() {
28
+ this.refresh();
29
+ }
30
+ refresh() {
28
31
  this._parentRect = this.extendedItem.element.parentElement.getBoundingClientRect();
29
32
  this._ellipseElement = this.extendedItem.node;
30
33
  this._startScrollOffset = this.designerCanvas.canvasOffset;
@@ -32,10 +35,12 @@ export class EllipsisExtension extends AbstractExtension {
32
35
  this._cy = this._ellipseElement.cy.baseVal.value;
33
36
  this._rx = this._ellipseElement.rx.baseVal.value;
34
37
  this._ry = this._ellipseElement.ry.baseVal.value;
35
- this._circle1 = this._drawPathCircle(this._cx, this._cy - this._ry, this._ellipseElement, 0);
36
- this._circle2 = this._drawPathCircle(this._cx + this._rx, this._cy, this._ellipseElement, 1);
37
- this._circle3 = this._drawPathCircle(this._cx, this._cy + this._ry, this._ellipseElement, 2);
38
- this._circle4 = this._drawPathCircle(this._cx - this._rx, this._cy, this._ellipseElement, 3);
38
+ if (this._valuesHaveChanges(this.designerCanvas.zoomFactor, this._cx, this._cy, this._rx, this._ry)) {
39
+ this._circle1 = this._drawPathCircle(this._cx, this._cy - this._ry, this._ellipseElement, 0, this._circle1);
40
+ this._circle2 = this._drawPathCircle(this._cx + this._rx, this._cy, this._ellipseElement, 1, this._circle2);
41
+ this._circle3 = this._drawPathCircle(this._cx, this._cy + this._ry, this._ellipseElement, 2, this._circle3);
42
+ this._circle4 = this._drawPathCircle(this._cx - this._rx, this._cy, this._ellipseElement, 3, this._circle4);
43
+ }
39
44
  }
40
45
  pointerEvent(event, circle, e, index) {
41
46
  event.stopPropagation();
@@ -111,8 +116,8 @@ export class EllipsisExtension extends AbstractExtension {
111
116
  break;
112
117
  }
113
118
  }
114
- _drawPathCircle(x, y, e, index) {
115
- let circle = this._drawCircle((this._parentRect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor + x, (this._parentRect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor + y, 5 / this.designerCanvas.scaleFactor, 'svg-path');
119
+ _drawPathCircle(x, y, e, index, circle) {
120
+ circle = this._drawCircle((this._parentRect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor + x, (this._parentRect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor + y, 5 / this.designerCanvas.scaleFactor, 'svg-path', circle);
116
121
  circle.style.strokeWidth = (1 / this.designerCanvas.zoomFactor).toString();
117
122
  circle.addEventListener(EventNames.PointerDown, event => this.pointerEvent(event, circle, e, index));
118
123
  circle.addEventListener(EventNames.PointerMove, event => this.pointerEvent(event, circle, e, index));
@@ -173,10 +178,6 @@ export class EllipsisExtension extends AbstractExtension {
173
178
  this.extendedItem.setAttribute('cx', (this._ellipseElement.cx.baseVal.value + diffX).toString());
174
179
  this.extendedItem.setAttribute('cy', (this._ellipseElement.cy.baseVal.value + diffY).toString());
175
180
  }
176
- refresh() {
177
- this._removeAllOverlays();
178
- this.extend();
179
- }
180
181
  dispose() {
181
182
  this._removeAllOverlays();
182
183
  }
@@ -11,6 +11,7 @@ export declare class DesignerToolbarButton extends BaseCustomWebComponentConstru
11
11
  currentToolOnButton: string;
12
12
  private _img;
13
13
  private _div;
14
+ private _longPress;
14
15
  constructor(designerCanvas: IDesignerCanvas, tools: Record<string | NamedTools, {
15
16
  icon: string;
16
17
  }>);
@@ -17,6 +17,7 @@ export class DesignerToolbarButton extends BaseCustomWebComponentConstructorAppe
17
17
  img {
18
18
  width: calc(100% - 4px);
19
19
  height: calc(100% - 4px);
20
+ -webkit-user-drag: none;
20
21
  }
21
22
  `;
22
23
  static template = html `<div id="div"><img id="img"></div>`;
@@ -25,17 +26,29 @@ export class DesignerToolbarButton extends BaseCustomWebComponentConstructorAppe
25
26
  currentToolOnButton;
26
27
  _img;
27
28
  _div;
29
+ _longPress;
28
30
  constructor(designerCanvas, tools) {
29
31
  super();
30
32
  this.tools = tools;
31
33
  this._img = this._getDomElement('img');
32
34
  this._div = this._getDomElement('div');
33
- this._div.onclick = () => {
34
- if (this.popup) {
35
- this.getRootNode().host.showPopup(this);
36
- }
37
- else {
35
+ this._div.onpointerdown = () => {
36
+ if (this.currentToolOnButton) {
38
37
  this.getRootNode().host.setTool(this.currentToolOnButton);
38
+ if (this.popup) {
39
+ this._longPress = setTimeout(() => {
40
+ this._longPress = null;
41
+ this.getRootNode().host.showPopup(this);
42
+ }, 200);
43
+ }
44
+ }
45
+ else if (this.popup)
46
+ this.getRootNode().host.showPopup(this);
47
+ };
48
+ this._div.onpointerup = () => {
49
+ if (this._longPress) {
50
+ clearTimeout(this._longPress);
51
+ this._longPress = null;
39
52
  }
40
53
  };
41
54
  this.showTool(Object.getOwnPropertyNames(tools)[0]);
@@ -3,7 +3,7 @@ import { assetsPath } from "../../../../../../Constants.js";
3
3
  import { TransformToolPopup } from "../popups/TransformToolPopup.js";
4
4
  export class TransformToolButtonProvider {
5
5
  provideButton(designerCanvas) {
6
- const button = new DesignerToolbarButton(designerCanvas, { 'TransformTool': { icon: assetsPath + 'images/layout/TransformTool.svg' } });
6
+ const button = new DesignerToolbarButton(designerCanvas, { '': { icon: assetsPath + 'images/layout/TransformTool.svg' } });
7
7
  button.popup = TransformToolPopup;
8
8
  return button;
9
9
  }
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
- {
2
- "description": "A UI designer for Polymer apps",
3
- "name": "@node-projects/web-component-designer",
4
- "version": "0.1.85",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "author": "jochen.kuehner@gmx.de",
8
- "license": "MIT",
9
- "scripts": {
10
- "tsc": "tsc",
11
- "build": "tsc",
12
- "prepublishOnly": "npm run build"
13
- },
14
- "dependencies": {
15
- "@node-projects/base-custom-webcomponent": ">=0.21.2"
16
- },
17
- "devDependencies": {
18
- "mdn-data": "^2.3.0"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/node-projects/web-component-designer.git"
23
- }
24
- }
1
+ {
2
+ "description": "A UI designer for Polymer apps",
3
+ "name": "@node-projects/web-component-designer",
4
+ "version": "0.1.87",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "author": "jochen.kuehner@gmx.de",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "tsc": "tsc",
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "dependencies": {
15
+ "@node-projects/base-custom-webcomponent": ">=0.21.2"
16
+ },
17
+ "devDependencies": {
18
+ "mdn-data": "^2.3.0"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/node-projects/web-component-designer.git"
23
+ }
24
+ }