@node-projects/web-component-designer 0.1.81 → 0.1.83

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
+ }
@@ -66,6 +66,10 @@ export class AbstractPropertiesService {
66
66
  cg.commit();
67
67
  }
68
68
  getPropertyTarget(designItem, property) {
69
+ if (property.propertyType == PropertyType.attribute)
70
+ return BindingTarget.attribute;
71
+ if (property.propertyType == PropertyType.cssValue)
72
+ return BindingTarget.css;
69
73
  return BindingTarget.property;
70
74
  }
71
75
  clearValue(designItems, property, clearType) {
@@ -122,8 +126,18 @@ export class AbstractPropertiesService {
122
126
  return ValueType.bound;
123
127
  }
124
128
  else {
125
- if (bindings && bindings.find(x => x.target == BindingTarget.property && x.targetName == property.name))
126
- return ValueType.bound;
129
+ if (property.propertyType == PropertyType.attribute) {
130
+ if (bindings && bindings.find(x => x.target == BindingTarget.attribute && x.targetName == property.name))
131
+ return ValueType.bound;
132
+ }
133
+ else if (property.propertyType == PropertyType.property) {
134
+ if (bindings && bindings.find(x => x.target == BindingTarget.property && x.targetName == property.name))
135
+ return ValueType.bound;
136
+ }
137
+ else {
138
+ if (bindings && bindings.find(x => (x.target == BindingTarget.property || x.target == BindingTarget.attribute) && x.targetName == property.name))
139
+ return ValueType.bound;
140
+ }
127
141
  }
128
142
  if (!all && property.propertyType == PropertyType.cssValue) {
129
143
  let styles = AbstractPropertiesService._stylesCache.get(designItems[0]);
@@ -193,7 +207,15 @@ export class AbstractPropertiesService {
193
207
  return bindings.find(x => (x.target == BindingTarget.css || x.target == BindingTarget.cssvar) && x.targetName == property.name);
194
208
  }
195
209
  else {
196
- return bindings.find(x => (x.target == BindingTarget.property || x.target == BindingTarget.attribute) && x.targetName == property.name);
210
+ if (property.propertyType == PropertyType.attribute) {
211
+ return bindings.find(x => x.target == BindingTarget.attribute && x.targetName == property.name);
212
+ }
213
+ else if (property.propertyType == PropertyType.property) {
214
+ return bindings.find(x => x.target == BindingTarget.property && x.targetName == property.name);
215
+ }
216
+ else {
217
+ return bindings.find(x => (x.target == BindingTarget.property || x.target == BindingTarget.attribute) && x.targetName == property.name);
218
+ }
197
219
  }
198
220
  }
199
221
  return null;
@@ -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;
@@ -755,7 +756,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
755
756
  let containerService = this.serviceContainer.getLastServiceWhere('containerService', x => x.serviceForContainer(this.rootDesignItem))
756
757
  containerService.finishPlace(this, this.rootDesignItem, this._initialPoint, currentPoint, this.instanceServiceContainer.selectionService.selectedElements);
757
758
  }*/
758
- this._fillCalculationrects();
759
+ this.fillCalculationrects();
759
760
  if (event.dataTransfer.types.length > 0 && event.dataTransfer.types[0] == 'Files') {
760
761
  const ddService = this.serviceContainer.externalDragDropService;
761
762
  if (ddService) {
@@ -793,7 +794,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
793
794
  this._lastDdElement = null;
794
795
  event.preventDefault();
795
796
  this._canvas.classList.remove('dragFileActive');
796
- this._fillCalculationrects();
797
+ this.fillCalculationrects();
797
798
  if (event.dataTransfer.files?.length > 0) {
798
799
  const ddService = this.serviceContainer.externalDragDropService;
799
800
  if (ddService) {
@@ -813,7 +814,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
813
814
  else {
814
815
  const dragDropService = this.serviceContainer.dragDropService;
815
816
  if (dragDropService) {
816
- this._fillCalculationrects();
817
+ this.fillCalculationrects();
817
818
  dragDropService.drop(this, event);
818
819
  }
819
820
  }
@@ -863,6 +864,10 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
863
864
  onKeyUp(event) {
864
865
  if (event.composedPath().indexOf(this.eatEvents) >= 0)
865
866
  return;
867
+ if (this._moveGroup) {
868
+ this._moveGroup.commit();
869
+ this._moveGroup = null;
870
+ }
866
871
  event.preventDefault();
867
872
  }
868
873
  onKeyDown(event) {
@@ -902,6 +907,8 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
902
907
  case 'ArrowLeft':
903
908
  case 'ArrowRight':
904
909
  {
910
+ if (!this._moveGroup)
911
+ this._moveGroup = this.rootDesignItem.openGroup("move items");
905
912
  let offset = { x: 0, y: 0 };
906
913
  if (event.key == 'ArrowDown')
907
914
  offset.y = -moveOffset;
@@ -1018,7 +1025,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
1018
1025
  _pointerEventHandler(event, forceElement = null) {
1019
1026
  if (!this.serviceContainer)
1020
1027
  return;
1021
- this._fillCalculationrects();
1028
+ this.fillCalculationrects();
1022
1029
  if (this._pointerextensions) {
1023
1030
  for (let pe of this._pointerextensions)
1024
1031
  pe.refresh(event);
@@ -1069,7 +1076,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
1069
1076
  releaseActiveTool() {
1070
1077
  this._activeTool = null;
1071
1078
  }
1072
- _fillCalculationrects() {
1079
+ fillCalculationrects() {
1073
1080
  this.containerBoundingRect = this._canvasContainer.getBoundingClientRect();
1074
1081
  this.outerRect = this._outercanvas2.getBoundingClientRect();
1075
1082
  }
@@ -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.81",
4
+ "version": "0.1.83",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",