@node-projects/web-component-designer 0.0.51 → 0.0.52
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/helper/LayoutHelper.d.ts +3 -0
- package/dist/elements/helper/LayoutHelper.js +47 -1
- package/dist/elements/helper/TransformHelper.d.ts +1 -0
- package/dist/elements/helper/TransformHelper.js +12 -0
- package/dist/elements/services/placementService/DefaultPlacementService.js +16 -10
- package/dist/elements/services/placementService/FlexBoxPlacementService.js +15 -1
- package/package.json +1 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IPoint } from "../../interfaces/IPoint.js";
|
|
2
|
+
import { IDesignItem } from "../item/IDesignItem.js";
|
|
3
|
+
export declare function placeDesignItem(container: IDesignItem, designItem: IDesignItem, offset: IPoint, mode: 'position' | 'transform' | 'margin' | 'padding'): void;
|
|
@@ -1,4 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//todo
|
|
3
2
|
//this function should return the correct property to change a layout, for example left/right when left or right is used,
|
|
4
3
|
//maybe margin on grid? or transform??
|
|
4
|
+
export function placeDesignItem(container, designItem, offset, mode) {
|
|
5
|
+
const movedElement = designItem.element;
|
|
6
|
+
const computedStyleMovedElement = getComputedStyle(movedElement);
|
|
7
|
+
if (mode === 'position') {
|
|
8
|
+
let positionedContainerElement = container.element;
|
|
9
|
+
let computedStylePositionedContainer = getComputedStyle(container.element);
|
|
10
|
+
while (computedStylePositionedContainer.position !== 'relative' && computedStylePositionedContainer.position !== 'absolute') {
|
|
11
|
+
positionedContainerElement = positionedContainerElement.parentElement;
|
|
12
|
+
computedStylePositionedContainer = getComputedStyle(positionedContainerElement);
|
|
13
|
+
}
|
|
14
|
+
let oldLeft = null;
|
|
15
|
+
let oldRight = null;
|
|
16
|
+
let oldTop = null;
|
|
17
|
+
let oldBottom = null;
|
|
18
|
+
let containerLeft = 0;
|
|
19
|
+
let containerRight = 0;
|
|
20
|
+
let containerTop = 0;
|
|
21
|
+
let containerBottom = 0;
|
|
22
|
+
if (computedStyleMovedElement.position === 'relative' || computedStyleMovedElement.position === 'absolute') {
|
|
23
|
+
oldLeft = parseFloat(movedElement.style.left);
|
|
24
|
+
oldLeft = Number.isNaN(oldLeft) ? null : oldLeft;
|
|
25
|
+
oldTop = parseFloat(movedElement.style.top);
|
|
26
|
+
oldTop = Number.isNaN(oldTop) ? null : oldTop;
|
|
27
|
+
oldRight = parseFloat(movedElement.style.right);
|
|
28
|
+
oldRight = Number.isNaN(oldRight) ? null : oldRight;
|
|
29
|
+
oldBottom = parseFloat(movedElement.style.bottom);
|
|
30
|
+
oldBottom = Number.isNaN(oldBottom) ? null : oldBottom;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (positionedContainerElement !== container.element) {
|
|
34
|
+
let posContainerRect = positionedContainerElement.getBoundingClientRect();
|
|
35
|
+
let elementRect = designItem.element.getBoundingClientRect();
|
|
36
|
+
containerLeft = elementRect.left - posContainerRect.left;
|
|
37
|
+
containerRight = elementRect.right - posContainerRect.right;
|
|
38
|
+
containerTop = elementRect.top - posContainerRect.top;
|
|
39
|
+
containerBottom = elementRect.bottom - posContainerRect.bottom;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
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");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/*function placeViaPosition(container: IDesignItem, designItem: IDesignItem, offset: IPoint, mode: 'position' | 'transform' | 'margin' | 'padding') {
|
|
49
|
+
|
|
50
|
+
}*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function combineTransforms(element: HTMLElement, transform1: string, transform2: string): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function combineTransforms(element, transform1, transform2) {
|
|
2
|
+
if (transform1 == null || transform1 == '') {
|
|
3
|
+
element.style.transform = transform2;
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
element.style.transform = transform1;
|
|
7
|
+
const matrix1 = new DOMMatrix(window.getComputedStyle(element).transform);
|
|
8
|
+
element.style.transform = transform2;
|
|
9
|
+
const matrix2 = new DOMMatrix(window.getComputedStyle(element).transform);
|
|
10
|
+
const result = matrix2.multiply(matrix1);
|
|
11
|
+
element.style.transform = result.toString();
|
|
12
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DomConverter } from '../../widgets/designerView/DomConverter.js';
|
|
2
|
+
import { combineTransforms } from '../../helper/TransformHelper.js';
|
|
3
|
+
import { placeDesignItem } from '../../helper/LayoutHelper.js';
|
|
2
4
|
export class DefaultPlacementService {
|
|
3
5
|
serviceForContainer(container) {
|
|
4
6
|
if (container.element.style.display === 'grid' || container.element.style.display === 'inline-grid' ||
|
|
@@ -78,14 +80,17 @@ export class DefaultPlacementService {
|
|
|
78
80
|
let track = this.calculateTrack(event, placementView, startPoint, offsetInControl, newPoint, items[0]);
|
|
79
81
|
//TODO: -> what is if a transform already exists -> backup existing style.?
|
|
80
82
|
for (const designItem of items) {
|
|
81
|
-
|
|
83
|
+
const newTransform = 'translate(' + track.x + 'px, ' + track.y + 'px)';
|
|
84
|
+
combineTransforms(designItem.element, designItem.styles.get('transform'), newTransform);
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
enterContainer(container, items) {
|
|
85
88
|
for (let i of items) {
|
|
86
89
|
if (i.lastContainerSize) {
|
|
87
|
-
i.
|
|
88
|
-
|
|
90
|
+
if (!i.styles.has('width'))
|
|
91
|
+
i.setStyle('width', i.lastContainerSize.width + 'px');
|
|
92
|
+
if (!i.styles.has('height'))
|
|
93
|
+
i.setStyle('height', i.lastContainerSize.height + 'px');
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
}
|
|
@@ -94,16 +99,17 @@ export class DefaultPlacementService {
|
|
|
94
99
|
finishPlace(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
95
100
|
let track = this.calculateTrack(event, placementView, startPoint, offsetInControl, newPoint, items[0]);
|
|
96
101
|
for (const designItem of items) {
|
|
97
|
-
let movedElement = designItem.element;
|
|
98
|
-
let oldLeft = parseFloat(movedElement.style.left);
|
|
102
|
+
/*let movedElement = designItem.element;
|
|
103
|
+
let oldLeft = parseFloat((<HTMLElement>movedElement).style.left);
|
|
99
104
|
oldLeft = Number.isNaN(oldLeft) ? 0 : oldLeft;
|
|
100
|
-
let oldTop = parseFloat(movedElement.style.top);
|
|
101
|
-
oldTop = Number.isNaN(oldTop) ? 0 : oldTop
|
|
105
|
+
let oldTop = parseFloat((<HTMLElement>movedElement).style.top);
|
|
106
|
+
oldTop = Number.isNaN(oldTop) ? 0 : oldTop;*/
|
|
102
107
|
//let oldPosition = movedElement.style.position;
|
|
103
|
-
designItem.element.style.transform =
|
|
104
|
-
|
|
108
|
+
designItem.element.style.transform = designItem.styles.get('transform') ?? '';
|
|
109
|
+
placeDesignItem(container, designItem, track, 'position');
|
|
110
|
+
/*designItem.setStyle('position', 'absolute');
|
|
105
111
|
designItem.setStyle('left', (track.x + oldLeft) + "px");
|
|
106
|
-
designItem.setStyle('top', (track.y + oldTop) + "px")
|
|
112
|
+
designItem.setStyle('top', (track.y + oldTop) + "px");*/
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
115
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export class FlexBoxPlacementService {
|
|
2
2
|
enterContainer(container, items) {
|
|
3
|
+
for (let i of items) {
|
|
4
|
+
i.removeStyle("position");
|
|
5
|
+
i.removeStyle("left");
|
|
6
|
+
i.removeStyle("top");
|
|
7
|
+
i.removeStyle("right");
|
|
8
|
+
i.removeStyle("transform");
|
|
9
|
+
}
|
|
3
10
|
}
|
|
4
11
|
leaveContainer(container, items) {
|
|
5
12
|
}
|
|
@@ -15,13 +22,20 @@ export class FlexBoxPlacementService {
|
|
|
15
22
|
return true;
|
|
16
23
|
}
|
|
17
24
|
getElementOffset(container, designItem) {
|
|
18
|
-
//TODO: offset could be bigger, when it was in a other cell???
|
|
19
25
|
return container.element.getBoundingClientRect();
|
|
20
26
|
}
|
|
21
27
|
placePoint(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
22
28
|
return null;
|
|
23
29
|
}
|
|
24
30
|
place(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
31
|
+
/*let direction = getComputedStyle(container.element).flexDirection;
|
|
32
|
+
|
|
33
|
+
const pos = (<IDesignerCanvas><unknown>placementView).getNormalizedEventCoordinates(event);
|
|
34
|
+
const posElement = (<IDesignerCanvas><unknown>placementView).getNormalizedElementCoordinates(items[0].element)
|
|
35
|
+
|
|
36
|
+
for (let e of container.element.children) {
|
|
37
|
+
|
|
38
|
+
}*/
|
|
25
39
|
}
|
|
26
40
|
finishPlace(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
27
41
|
}
|