@node-projects/web-component-designer 0.0.51 → 0.0.55
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 +51 -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 +10 -13
- 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,54 @@
|
|
|
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
|
+
//@ts-ignore
|
|
20
|
+
let containerRight = 0;
|
|
21
|
+
let containerTop = 0;
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
let containerBottom = 0;
|
|
24
|
+
let hasPositionedLayout = false;
|
|
25
|
+
if (computedStyleMovedElement.position === 'relative' || computedStyleMovedElement.position === 'absolute') {
|
|
26
|
+
oldLeft = parseFloat(movedElement.style.left);
|
|
27
|
+
oldLeft = Number.isNaN(oldLeft) ? null : oldLeft;
|
|
28
|
+
oldTop = parseFloat(movedElement.style.top);
|
|
29
|
+
oldTop = Number.isNaN(oldTop) ? null : oldTop;
|
|
30
|
+
oldRight = parseFloat(movedElement.style.right);
|
|
31
|
+
oldRight = Number.isNaN(oldRight) ? null : oldRight;
|
|
32
|
+
oldBottom = parseFloat(movedElement.style.bottom);
|
|
33
|
+
oldBottom = Number.isNaN(oldBottom) ? null : oldBottom;
|
|
34
|
+
hasPositionedLayout = true;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (positionedContainerElement !== container.element) {
|
|
38
|
+
let posContainerRect = positionedContainerElement.getBoundingClientRect();
|
|
39
|
+
let elementRect = designItem.element.getBoundingClientRect();
|
|
40
|
+
containerLeft = elementRect.left - posContainerRect.left;
|
|
41
|
+
containerRight = elementRect.right - posContainerRect.right;
|
|
42
|
+
containerTop = elementRect.top - posContainerRect.top;
|
|
43
|
+
containerBottom = elementRect.bottom - posContainerRect.bottom;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!hasPositionedLayout)
|
|
47
|
+
designItem.setStyle('position', 'absolute');
|
|
48
|
+
designItem.setStyle('left', (offset.x + (oldLeft ?? 0) + containerLeft) + "px");
|
|
49
|
+
designItem.setStyle('top', (offset.y + (oldTop ?? 0) + containerTop) + "px");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/*function placeViaPosition(container: IDesignItem, designItem: IDesignItem, offset: IPoint, mode: 'position' | 'transform' | 'margin' | 'padding') {
|
|
53
|
+
|
|
54
|
+
}*/
|
|
@@ -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,8 @@ 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
|
-
|
|
98
|
-
|
|
99
|
-
oldLeft = Number.isNaN(oldLeft) ? 0 : oldLeft;
|
|
100
|
-
let oldTop = parseFloat(movedElement.style.top);
|
|
101
|
-
oldTop = Number.isNaN(oldTop) ? 0 : oldTop;
|
|
102
|
-
//let oldPosition = movedElement.style.position;
|
|
103
|
-
designItem.element.style.transform = null;
|
|
104
|
-
designItem.setStyle('position', 'absolute');
|
|
105
|
-
designItem.setStyle('left', (track.x + oldLeft) + "px");
|
|
106
|
-
designItem.setStyle('top', (track.y + oldTop) + "px");
|
|
102
|
+
designItem.element.style.transform = designItem.styles.get('transform') ?? '';
|
|
103
|
+
placeDesignItem(container, designItem, track, 'position');
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
}
|
|
@@ -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
|
}
|