@node-projects/web-component-designer 0.0.52 → 0.0.56

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.
@@ -1,3 +1,4 @@
1
1
  import { IPoint } from "../../interfaces/IPoint.js";
2
2
  import { IDesignItem } from "../item/IDesignItem.js";
3
+ export declare function filterChildPlaceItems(items: IDesignItem[]): IDesignItem[];
3
4
  export declare function placeDesignItem(container: IDesignItem, designItem: IDesignItem, offset: IPoint, mode: 'position' | 'transform' | 'margin' | 'padding'): void;
@@ -1,6 +1,19 @@
1
1
  //todo
2
2
  //this function should return the correct property to change a layout, for example left/right when left or right is used,
3
3
  //maybe margin on grid? or transform??
4
+ export function filterChildPlaceItems(items) {
5
+ const filterdPlaceItems = [];
6
+ next: for (let i of items) {
7
+ let par = i.parent;
8
+ while (par != null && !par.isRootItem) {
9
+ if (items.indexOf(par) >= 0)
10
+ continue next;
11
+ par = par.parent;
12
+ }
13
+ filterdPlaceItems.push(i);
14
+ }
15
+ return filterdPlaceItems;
16
+ }
4
17
  export function placeDesignItem(container, designItem, offset, mode) {
5
18
  const movedElement = designItem.element;
6
19
  const computedStyleMovedElement = getComputedStyle(movedElement);
@@ -16,9 +29,12 @@ export function placeDesignItem(container, designItem, offset, mode) {
16
29
  let oldTop = null;
17
30
  let oldBottom = null;
18
31
  let containerLeft = 0;
32
+ //@ts-ignore
19
33
  let containerRight = 0;
20
34
  let containerTop = 0;
35
+ //@ts-ignore
21
36
  let containerBottom = 0;
37
+ let hasPositionedLayout = false;
22
38
  if (computedStyleMovedElement.position === 'relative' || computedStyleMovedElement.position === 'absolute') {
23
39
  oldLeft = parseFloat(movedElement.style.left);
24
40
  oldLeft = Number.isNaN(oldLeft) ? null : oldLeft;
@@ -28,6 +44,7 @@ export function placeDesignItem(container, designItem, offset, mode) {
28
44
  oldRight = Number.isNaN(oldRight) ? null : oldRight;
29
45
  oldBottom = parseFloat(movedElement.style.bottom);
30
46
  oldBottom = Number.isNaN(oldBottom) ? null : oldBottom;
47
+ hasPositionedLayout = true;
31
48
  }
32
49
  else {
33
50
  if (positionedContainerElement !== container.element) {
@@ -39,10 +56,10 @@ export function placeDesignItem(container, designItem, offset, mode) {
39
56
  containerBottom = elementRect.bottom - posContainerRect.bottom;
40
57
  }
41
58
  }
42
- designItem.element.style.transform = designItem.styles.get('transform') ?? '';
43
- designItem.setStyle('position', 'absolute');
44
- designItem.setStyle('left', (offset.x + oldLeft + containerLeft) + "px");
45
- designItem.setStyle('top', (offset.y + oldTop + containerTop) + "px");
59
+ if (!hasPositionedLayout)
60
+ designItem.setStyle('position', 'absolute');
61
+ designItem.setStyle('left', (offset.x + (oldLeft ?? 0) + containerLeft) + "px");
62
+ designItem.setStyle('top', (offset.y + (oldTop ?? 0) + containerTop) + "px");
46
63
  }
47
64
  }
48
65
  /*function placeViaPosition(container: IDesignItem, designItem: IDesignItem, offset: IPoint, mode: 'position' | 'transform' | 'margin' | 'padding') {
@@ -1,6 +1,6 @@
1
1
  import { DomConverter } from '../../widgets/designerView/DomConverter.js';
2
2
  import { combineTransforms } from '../../helper/TransformHelper.js';
3
- import { placeDesignItem } from '../../helper/LayoutHelper.js';
3
+ import { filterChildPlaceItems, placeDesignItem } from '../../helper/LayoutHelper.js';
4
4
  export class DefaultPlacementService {
5
5
  serviceForContainer(container) {
6
6
  if (container.element.style.display === 'grid' || container.element.style.display === 'inline-grid' ||
@@ -78,14 +78,16 @@ export class DefaultPlacementService {
78
78
  //TODO:, this should revert all undo actions while active
79
79
  //maybe a undo actions returns itself or an id so it could be changed?
80
80
  let track = this.calculateTrack(event, placementView, startPoint, offsetInControl, newPoint, items[0]);
81
+ let filterdItems = filterChildPlaceItems(items);
81
82
  //TODO: -> what is if a transform already exists -> backup existing style.?
82
- for (const designItem of items) {
83
+ for (const designItem of filterdItems) {
83
84
  const newTransform = 'translate(' + track.x + 'px, ' + track.y + 'px)';
84
85
  combineTransforms(designItem.element, designItem.styles.get('transform'), newTransform);
85
86
  }
86
87
  }
87
88
  enterContainer(container, items) {
88
- for (let i of items) {
89
+ let filterdItems = filterChildPlaceItems(items);
90
+ for (let i of filterdItems) {
89
91
  if (i.lastContainerSize) {
90
92
  if (!i.styles.has('width'))
91
93
  i.setStyle('width', i.lastContainerSize.width + 'px');
@@ -98,18 +100,10 @@ export class DefaultPlacementService {
98
100
  }
99
101
  finishPlace(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
100
102
  let track = this.calculateTrack(event, placementView, startPoint, offsetInControl, newPoint, items[0]);
101
- for (const designItem of items) {
102
- /*let movedElement = designItem.element;
103
- let oldLeft = parseFloat((<HTMLElement>movedElement).style.left);
104
- oldLeft = Number.isNaN(oldLeft) ? 0 : oldLeft;
105
- let oldTop = parseFloat((<HTMLElement>movedElement).style.top);
106
- oldTop = Number.isNaN(oldTop) ? 0 : oldTop;*/
107
- //let oldPosition = movedElement.style.position;
103
+ let filterdItems = filterChildPlaceItems(items);
104
+ for (const designItem of filterdItems) {
108
105
  designItem.element.style.transform = designItem.styles.get('transform') ?? '';
109
106
  placeDesignItem(container, designItem, track, 'position');
110
- /*designItem.setStyle('position', 'absolute');
111
- designItem.setStyle('left', (track.x + oldLeft) + "px");
112
- designItem.setStyle('top', (track.y + oldTop) + "px");*/
113
107
  }
114
108
  }
115
109
  }
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.0.52",
4
+ "version": "0.0.56",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",