@node-projects/web-component-designer 0.1.82 → 0.1.84

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.
@@ -22,7 +22,7 @@ export function convertCssUnitToPixel(cssValue, target, percentTarget) {
22
22
  'vmax': value => value / 100 * (window.innerHeight > window.innerWidth ? window.innerHeight : window.innerWidth),
23
23
  'lh': value => value * parseFloat(getComputedStyle(target).lineHeight),
24
24
  'rlh': value => value * parseFloat(getComputedStyle(document.documentElement).lineHeight),
25
- '%': value => value / 100 * (percentTarget == 'height' ? target.getBoundingClientRect().height : target.getBoundingClientRect().width),
25
+ '%': value => value / 100 * (percentTarget == 'height' ? getOriginalSizeBeforeTransformation(target).height : getOriginalSizeBeforeTransformation(target).width),
26
26
  /*TODO: container units
27
27
  //find parent with computed style where container-type is inline-size or size (regarding to query type)
28
28
  //use this size for calculation
@@ -82,7 +82,7 @@ export function convertCssUnit(cssValue, target, percentTarget, unit) {
82
82
  'vmax': value => value * 100 / (window.innerHeight > window.innerWidth ? window.innerHeight : window.innerWidth),
83
83
  'lh': value => value / parseFloat(getComputedStyle(target).lineHeight),
84
84
  'rlh': value => value / parseFloat(getComputedStyle(document.documentElement).lineHeight),
85
- '%': value => value * 100 / (percentTarget == 'height' ? target.getBoundingClientRect().height : target.getBoundingClientRect().width),
85
+ '%': value => value * 100 / (percentTarget == 'height' ? getOriginalSizeBeforeTransformation(target).height : getOriginalSizeBeforeTransformation(target).width),
86
86
  // Times
87
87
  'ms': value => value,
88
88
  's': value => value / 1000,
@@ -99,3 +99,6 @@ export function convertCssUnit(cssValue, target, percentTarget, unit) {
99
99
  }
100
100
  return cssValue;
101
101
  }
102
+ function getOriginalSizeBeforeTransformation(element) {
103
+ return { width: element.offsetWidth, height: element.offsetHeight };
104
+ }
@@ -61,7 +61,11 @@ const windowOffsetsCacheKey = Symbol('windowOffsetsCacheKey');
61
61
  export function getElementsWindowOffsetWithoutSelfAndParentTransformations(element, zoom, cache = {}) {
62
62
  let offsetLeft = 0;
63
63
  let offsetTop = 0;
64
- let ch = cache[windowOffsetsCacheKey] ??= new Map();
64
+ let ch;
65
+ if (cache)
66
+ ch = cache[windowOffsetsCacheKey] ??= new Map();
67
+ else
68
+ ch = new Map();
65
69
  let lst = [];
66
70
  while (element) {
67
71
  let cachedObj = ch.get(element);
@@ -113,24 +113,28 @@ export function getDesignerCanvasNormalizedTransformedOriginWithoutParentTransfo
113
113
  const designerCanvasNormalizedTransformedOrigin = new DOMPoint(transformOriginAbsolutRelatedToWindowWithoutAnyTransformation.x - designerCanvas.containerBoundingRect.x, transformOriginAbsolutRelatedToWindowWithoutAnyTransformation.y - designerCanvas.containerBoundingRect.y);
114
114
  return designerCanvasNormalizedTransformedOrigin;
115
115
  }
116
- const elemntMatrixCacheKey = Symbol('windowOffsetsCacheKey');
116
+ //const elementMatrixCacheKey = Symbol('windowOffsetsCacheKey');
117
117
  export function getResultingTransformationBetweenElementAndAllAncestors(element, ancestor, excludeAncestor, cache = {}) {
118
- let ch = cache[elemntMatrixCacheKey] ??= new Map();
118
+ /*let ch: Map<any, [DOMMatrix]>;
119
+ if (cache)
120
+ ch = cache[elementMatrixCacheKey] ??= new Map<any, [DOMMatrix]>();
121
+ else
122
+ ch = new Map<any, [DOMMatrix]>();*/
119
123
  let lst = [];
120
124
  let actualElement = element;
121
125
  let actualElementMatrix;
122
126
  let newElementMatrix;
123
127
  let originalElementAndAllParentsMultipliedMatrix;
124
128
  while (actualElement != ancestor && actualElement != null) {
125
- let cachedObj = ch.get(actualElement);
129
+ /*let cachedObj = ch.get(actualElement);
126
130
  if (cachedObj) {
127
- if (originalElementAndAllParentsMultipliedMatrix)
128
- originalElementAndAllParentsMultipliedMatrix = cachedObj[0].multiply(originalElementAndAllParentsMultipliedMatrix);
129
- else
130
- originalElementAndAllParentsMultipliedMatrix = cachedObj[0];
131
- lst.forEach(x => x[0] = x[0].multiply(originalElementAndAllParentsMultipliedMatrix));
132
- break;
133
- }
131
+ if (originalElementAndAllParentsMultipliedMatrix)
132
+ originalElementAndAllParentsMultipliedMatrix = cachedObj[0].multiply(originalElementAndAllParentsMultipliedMatrix);
133
+ else
134
+ originalElementAndAllParentsMultipliedMatrix = cachedObj[0];
135
+ lst.forEach(x => x[0] = x[0].multiply(originalElementAndAllParentsMultipliedMatrix));
136
+ break;
137
+ }*/
134
138
  const newElement = getParentElementIncludingSlots(actualElement);
135
139
  if (newElement) {
136
140
  actualElementMatrix = getElementCombinedTransform(actualElement);
@@ -145,7 +149,7 @@ export function getResultingTransformationBetweenElementAndAllAncestors(element,
145
149
  lst.forEach(x => x[0] = x[0].multiply(originalElementAndAllParentsMultipliedMatrix));
146
150
  const cacheEntry = [originalElementAndAllParentsMultipliedMatrix];
147
151
  lst.push(cacheEntry);
148
- ch.set(actualElement, cacheEntry);
152
+ //ch.set(actualElement, cacheEntry);
149
153
  }
150
154
  actualElement = newElement;
151
155
  }
@@ -9,9 +9,15 @@ export interface IBinding {
9
9
  expression?: string;
10
10
  expressionTwoWay?: string;
11
11
  bindableObjectNames?: string[];
12
+ bindableObjects?: IBindableObject[];
12
13
  converters?: any;
13
14
  mode?: BindingMode;
14
15
  invert?: boolean;
15
16
  changedEvents?: string[];
16
17
  nullSafe?: boolean;
17
18
  }
19
+ export interface IBindableObject {
20
+ name?: string;
21
+ alias?: string;
22
+ modificator?: string;
23
+ }
@@ -97,8 +97,8 @@ export class DefaultPlacementService {
97
97
  }
98
98
  let filteredItems = filterChildPlaceItems(items);
99
99
  for (const designItem of filteredItems) {
100
- const canvas = designItem.element.closest('#node-projects-designer-canvas-canvas');
101
- let originalElementAndAllAncestorsMultipliedMatrix = getResultingTransformationBetweenElementAndAllAncestors(designItem.element.parentElement, canvas, true);
100
+ const canvas = designItem.instanceServiceContainer.designerCanvas.rootDesignItem.element;
101
+ let originalElementAndAllAncestorsMultipliedMatrix = getResultingTransformationBetweenElementAndAllAncestors(designItem.parent.element, canvas, true);
102
102
  let transformMatrixParentTransformsCompensated = null;
103
103
  if (originalElementAndAllAncestorsMultipliedMatrix) {
104
104
  transformMatrixParentTransformsCompensated = new DOMPoint(track.x, track.y, 0, 0).matrixTransform(originalElementAndAllAncestorsMultipliedMatrix.inverse());
@@ -12,8 +12,13 @@ export class SnaplinesProviderService {
12
12
  const positionsMiddleH = [];
13
13
  const positionsV = [];
14
14
  const positionsMiddleV = [];
15
- for (let n of containerItem.querySelectorAll('*')) {
16
- if (!ignMap.has(n)) {
15
+ const tw = document.createTreeWalker(containerItem.isRootItem ? containerItem.element.shadowRoot : containerItem.element, NodeFilter.SHOW_ELEMENT);
16
+ let n = tw.nextNode();
17
+ while (n != null) {
18
+ if (ignMap.has(n)) {
19
+ n = tw.nextSibling();
20
+ }
21
+ else {
17
22
  const p = n.getBoundingClientRect();
18
23
  const pLeft = (p.x - outerRect.x) / canvas.scaleFactor;
19
24
  const pMidH = (p.x - outerRect.x + p.width / 2) / canvas.scaleFactor;
@@ -36,6 +41,7 @@ export class SnaplinesProviderService {
36
41
  positionsV.push([pBottom, transformedP]);
37
42
  if (provideWithDist)
38
43
  positionsV.push([pBottom + provideWithDistDist, transformedP]);
44
+ n = tw.nextNode();
39
45
  }
40
46
  }
41
47
  positionsH.push([0, { x: 0, y: 0, width: 0, height: 0 }]);
@@ -23,6 +23,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
23
23
  clickOverlay: HTMLDivElement;
24
24
  private _activeTool;
25
25
  private _gridSize;
26
+ private _moveGroup;
26
27
  get gridSize(): number;
27
28
  set gridSize(value: number);
28
29
  pasteOffset: number;
@@ -128,7 +129,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
128
129
  private _pointerEventHandler;
129
130
  captureActiveTool(tool: ITool): void;
130
131
  releaseActiveTool(): void;
131
- private _fillCalculationrects;
132
+ fillCalculationrects(): void;
132
133
  removeOverlay(element: SVGGraphicsElement): void;
133
134
  zoomOntoRectangle(startPoint: IPoint, endPoint: IPoint): void;
134
135
  zoomPoint(canvasPoint: IPoint, newZoom: number): void;
@@ -29,6 +29,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
29
29
  _activeTool;
30
30
  // IPlacementView
31
31
  _gridSize = 10;
32
+ _moveGroup;
32
33
  get gridSize() {
33
34
  return this._gridSize;
34
35
  }
@@ -638,7 +639,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
638
639
  this._canvasContainer.style.bottom = this._outercanvas2.offsetHeight >= this._canvasContainer.offsetHeight ? '0' : '';
639
640
  this._canvasContainer.style.right = this._outercanvas2.offsetWidth >= this._canvasContainer.offsetWidth ? '0' : '';
640
641
  this._updateTransform();
641
- this._fillCalculationrects();
642
+ this.fillCalculationrects();
642
643
  this.onZoomFactorChanged.emit(this._zoomFactor);
643
644
  if (refreshExtensions) {
644
645
  this.extensionManager.refreshAllAppliedExtentions();
@@ -668,7 +669,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
668
669
  this.instanceServiceContainer.undoService.execute(setItemsAction);
669
670
  }
670
671
  _internalSetDesignItems(designItems) {
671
- this._fillCalculationrects();
672
+ this.fillCalculationrects();
672
673
  this.overlayLayer.removeAllOverlays();
673
674
  DomHelper.removeAllChildnodes(this.overlayLayer);
674
675
  for (let i of [...this.rootDesignItem.children()])
@@ -711,7 +712,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
711
712
  this.snapLines.clearSnaplines();
712
713
  }
713
714
  _onDragEnter(event) {
714
- this._fillCalculationrects();
715
+ this.fillCalculationrects();
715
716
  event.preventDefault();
716
717
  const hasTransferDataBindingObject = event.dataTransfer.types.indexOf(dragDropFormatNameBindingObject) >= 0;
717
718
  if (hasTransferDataBindingObject) {
@@ -737,7 +738,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
737
738
  }
738
739
  }
739
740
  _onDragLeave(event) {
740
- this._fillCalculationrects();
741
+ this.fillCalculationrects();
741
742
  event.preventDefault();
742
743
  this._canvas.classList.remove('dragFileActive');
743
744
  const dragDropService = this.serviceContainer.dragDropService;
@@ -748,14 +749,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
748
749
  _lastDdElement = null;
749
750
  _onDragOver(event) {
750
751
  event.preventDefault();
751
- /*if (this.alignOnSnap) {
752
- this.snapLines.calculateSnaplines(this.instanceServiceContainer.selectionService.selectedElements);
753
- //TODO: fix this following code...
754
- const currentPoint = this.getDesignerMousepoint(event);
755
- let containerService = this.serviceContainer.getLastServiceWhere('containerService', x => x.serviceForContainer(this.rootDesignItem))
756
- containerService.finishPlace(this, this.rootDesignItem, this._initialPoint, currentPoint, this.instanceServiceContainer.selectionService.selectedElements);
757
- }*/
758
- this._fillCalculationrects();
752
+ this.fillCalculationrects();
759
753
  if (event.dataTransfer.types.length > 0 && event.dataTransfer.types[0] == 'Files') {
760
754
  const ddService = this.serviceContainer.externalDragDropService;
761
755
  if (ddService) {
@@ -793,7 +787,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
793
787
  this._lastDdElement = null;
794
788
  event.preventDefault();
795
789
  this._canvas.classList.remove('dragFileActive');
796
- this._fillCalculationrects();
790
+ this.fillCalculationrects();
797
791
  if (event.dataTransfer.files?.length > 0) {
798
792
  const ddService = this.serviceContainer.externalDragDropService;
799
793
  if (ddService) {
@@ -813,7 +807,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
813
807
  else {
814
808
  const dragDropService = this.serviceContainer.dragDropService;
815
809
  if (dragDropService) {
816
- this._fillCalculationrects();
810
+ this.fillCalculationrects();
817
811
  dragDropService.drop(this, event);
818
812
  }
819
813
  }
@@ -863,6 +857,10 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
863
857
  onKeyUp(event) {
864
858
  if (event.composedPath().indexOf(this.eatEvents) >= 0)
865
859
  return;
860
+ if (this._moveGroup) {
861
+ this._moveGroup.commit();
862
+ this._moveGroup = null;
863
+ }
866
864
  event.preventDefault();
867
865
  }
868
866
  onKeyDown(event) {
@@ -902,6 +900,8 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
902
900
  case 'ArrowLeft':
903
901
  case 'ArrowRight':
904
902
  {
903
+ if (!this._moveGroup)
904
+ this._moveGroup = this.rootDesignItem.openGroup("move items");
905
905
  let offset = { x: 0, y: 0 };
906
906
  if (event.key == 'ArrowDown')
907
907
  offset.y = -moveOffset;
@@ -1018,7 +1018,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
1018
1018
  _pointerEventHandler(event, forceElement = null) {
1019
1019
  if (!this.serviceContainer)
1020
1020
  return;
1021
- this._fillCalculationrects();
1021
+ this.fillCalculationrects();
1022
1022
  if (this._pointerextensions) {
1023
1023
  for (let pe of this._pointerextensions)
1024
1024
  pe.refresh(event);
@@ -1069,7 +1069,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
1069
1069
  releaseActiveTool() {
1070
1070
  this._activeTool = null;
1071
1071
  }
1072
- _fillCalculationrects() {
1072
+ fillCalculationrects() {
1073
1073
  this.containerBoundingRect = this._canvasContainer.getBoundingClientRect();
1074
1074
  this.outerRect = this._outercanvas2.getBoundingClientRect();
1075
1075
  }
@@ -358,6 +358,7 @@ export class ExtensionManager {
358
358
  this.designerCanvas.overlayLayer.endBatch();
359
359
  }
360
360
  refreshAllAppliedExtentions() {
361
+ this.designerCanvas.fillCalculationrects();
361
362
  this.refreshAllExtensions([...this.designItemsWithExtentions]);
362
363
  }
363
364
  //TODO: does not work with permanant, when not applied... maybe we need to do in another way
@@ -31,33 +31,34 @@ export class DrawElementTool {
31
31
  }
32
32
  keyboardEventHandler(designerCanvas, event, currentElement) { }
33
33
  sizeOverlapThreshold = false;
34
- async _onPointerDown(designerView, event) {
34
+ async _onPointerDown(designerCanvas, event) {
35
+ const evPos = designerCanvas.getNormalizedEventCoordinates(event);
35
36
  event.preventDefault();
36
- this._startPosition = { x: event.x, y: event.y };
37
- this._changeGroup = designerView.rootDesignItem.openGroup("Insert Item");
38
- this._createdItem = await designerView.serviceContainer.forSomeServicesTillResult("instanceService", (service) => service.getElement(this._elementDefinition, designerView.serviceContainer, designerView.instanceServiceContainer));
39
- const targetRect = event.target.getBoundingClientRect();
37
+ this._startPosition = { x: evPos.x, y: evPos.y };
38
+ this._changeGroup = designerCanvas.rootDesignItem.openGroup("Insert Item");
39
+ this._createdItem = await designerCanvas.serviceContainer.forSomeServicesTillResult("instanceService", (service) => service.getElement(this._elementDefinition, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer));
40
40
  this._createdItem.setStyle('position', 'absolute');
41
- this._createdItem.setStyle('left', event.offsetX + targetRect.left - designerView.containerBoundingRect.x + 'px');
42
- this._createdItem.setStyle('top', event.offsetY + targetRect.top - designerView.containerBoundingRect.y + 'px');
41
+ this._createdItem.setStyle('left', evPos.x + 'px');
42
+ this._createdItem.setStyle('top', evPos.y + 'px');
43
43
  this._createdItem.setStyle('width', '0');
44
44
  this._createdItem.setStyle('height', '0');
45
45
  this._createdItem.element.style.overflow = 'hidden';
46
- designerView.rootDesignItem.insertChild(this._createdItem);
46
+ designerCanvas.rootDesignItem.insertChild(this._createdItem);
47
47
  //draw via containerService??? how to draw into a grid, a stackpanel???
48
- designerView.instanceServiceContainer.selectionService.clearSelectedElements();
48
+ designerCanvas.instanceServiceContainer.selectionService.clearSelectedElements();
49
49
  }
50
50
  async _onPointerMove(designerCanvas, event) {
51
+ const evPos = designerCanvas.getNormalizedEventCoordinates(event);
51
52
  if (this._createdItem) {
52
53
  if (!this._rect) {
53
54
  this._rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
54
55
  designerCanvas.overlayLayer.addOverlay(this.constructor.name, this._rect, OverlayLayer.Foreground);
55
56
  this._rect.setAttribute('class', 'svg-draw-new-element');
56
- this._rect.setAttribute('x', (this._startPosition.x - designerCanvas.containerBoundingRect.x));
57
- this._rect.setAttribute('y', (this._startPosition.y - designerCanvas.containerBoundingRect.y));
57
+ this._rect.setAttribute('x', (this._startPosition.x));
58
+ this._rect.setAttribute('y', (this._startPosition.y));
58
59
  }
59
- const w = event.x - this._startPosition.x;
60
- const h = event.y - this._startPosition.y;
60
+ const w = evPos.x - this._startPosition.x;
61
+ const h = evPos.y - this._startPosition.y;
61
62
  if (w >= 0) {
62
63
  this._rect.setAttribute('width', w);
63
64
  this._createdItem.setStyle('width', w + 'px');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "A UI designer for Polymer apps",
3
3
  "name": "@node-projects/web-component-designer",
4
- "version": "0.1.82",
4
+ "version": "0.1.84",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",