@node-projects/web-component-designer 0.0.49 → 0.0.50
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/GridHelper.d.ts +16 -0
- package/dist/elements/helper/GridHelper.js +107 -0
- package/dist/elements/helper/Helper.d.ts +3 -0
- package/dist/elements/helper/Helper.js +3 -0
- package/dist/elements/item/DesignItem.d.ts +4 -2
- package/dist/elements/item/DesignItem.js +6 -3
- package/dist/elements/item/IDesignItem.d.ts +2 -0
- package/dist/elements/services/htmlWriterService/HtmlWriterService.js +1 -6
- package/dist/elements/services/placementService/DefaultPlacementService.js +6 -0
- package/dist/elements/services/placementService/GridPlacementService.js +52 -1
- package/dist/elements/services/undoService/transactionItems/CssStyleChangeAction.d.ts +2 -2
- package/dist/elements/widgets/designerView/DomConverter.d.ts +1 -1
- package/dist/elements/widgets/designerView/DomConverter.js +2 -0
- package/dist/elements/widgets/designerView/IDesignerCanvas.d.ts +2 -0
- package/dist/elements/widgets/designerView/designerCanvas.d.ts +2 -1
- package/dist/elements/widgets/designerView/designerCanvas.js +1 -1
- package/dist/elements/widgets/designerView/extensions/GridExtension.js +11 -97
- package/dist/elements/widgets/designerView/extensions/TransformOriginExtension.js +2 -2
- package/dist/elements/widgets/propertyGrid/PropertyGridWithHeader.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IDesignItem } from "../item/IDesignItem.js";
|
|
2
|
+
export declare function CalculateGridInformation(designItem: IDesignItem): {
|
|
3
|
+
cells?: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
name: string;
|
|
9
|
+
}[][];
|
|
10
|
+
gaps?: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export function CalculateGridInformation(designItem) {
|
|
2
|
+
let itemRect = designItem.element.getBoundingClientRect();
|
|
3
|
+
const computedStyle = getComputedStyle(designItem.element);
|
|
4
|
+
const rows = computedStyle.gridTemplateRows.split(' ');
|
|
5
|
+
const columns = computedStyle.gridTemplateColumns.split(' ');
|
|
6
|
+
let y = 0;
|
|
7
|
+
let xGap = 0;
|
|
8
|
+
let yGap = 0;
|
|
9
|
+
let rw = 0;
|
|
10
|
+
let xOffset = itemRect.x - designItem.instanceServiceContainer.designerCanvas.containerBoundingRect.x;
|
|
11
|
+
let yOffset = itemRect.y - designItem.instanceServiceContainer.designerCanvas.containerBoundingRect.y;
|
|
12
|
+
let gridA = null;
|
|
13
|
+
if (computedStyle.gridTemplateAreas && computedStyle.gridTemplateAreas !== 'none')
|
|
14
|
+
gridA = computedStyle.gridTemplateAreas.split('\"');
|
|
15
|
+
if (computedStyle.columnGap && computedStyle.columnGap != 'normal')
|
|
16
|
+
xGap = Number.parseFloat(computedStyle.columnGap.replace('px', ''));
|
|
17
|
+
if (computedStyle.rowGap && computedStyle.rowGap != 'normal')
|
|
18
|
+
yGap = Number.parseFloat(computedStyle.rowGap.replace('px', ''));
|
|
19
|
+
let gesX = 0;
|
|
20
|
+
let gesY = 0;
|
|
21
|
+
for (let c of columns) {
|
|
22
|
+
const currX = Number.parseFloat(c.replace('px', ''));
|
|
23
|
+
gesX += currX + xGap;
|
|
24
|
+
}
|
|
25
|
+
gesX -= xGap;
|
|
26
|
+
for (let r of rows) {
|
|
27
|
+
const currY = Number.parseFloat(r.replace('px', ''));
|
|
28
|
+
gesY += currY + yGap;
|
|
29
|
+
}
|
|
30
|
+
gesY -= yGap;
|
|
31
|
+
if (computedStyle.justifyContent == 'center') {
|
|
32
|
+
xOffset += (itemRect.width - gesX) / 2;
|
|
33
|
+
}
|
|
34
|
+
else if (computedStyle.justifyContent == 'end') {
|
|
35
|
+
xOffset += itemRect.width - gesX;
|
|
36
|
+
}
|
|
37
|
+
else if (computedStyle.justifyContent == 'space-between') {
|
|
38
|
+
xGap += (itemRect.width - gesX) / (columns.length - 1);
|
|
39
|
+
}
|
|
40
|
+
else if (computedStyle.justifyContent == 'space-around') {
|
|
41
|
+
let gp = (itemRect.width - gesX) / (columns.length * 2);
|
|
42
|
+
xGap += gp * 2;
|
|
43
|
+
xOffset += gp;
|
|
44
|
+
}
|
|
45
|
+
else if (computedStyle.justifyContent == 'space-evenly') {
|
|
46
|
+
let gp = (itemRect.width - gesX) / (columns.length + 1);
|
|
47
|
+
xGap += gp;
|
|
48
|
+
xOffset += gp;
|
|
49
|
+
}
|
|
50
|
+
if (computedStyle.alignContent == 'center') {
|
|
51
|
+
xOffset += (itemRect.height - gesY) / 2;
|
|
52
|
+
}
|
|
53
|
+
else if (computedStyle.alignContent == 'end') {
|
|
54
|
+
xOffset += itemRect.height - gesY;
|
|
55
|
+
}
|
|
56
|
+
else if (computedStyle.alignContent == 'space-between') {
|
|
57
|
+
yGap += (itemRect.height - gesY) / (rows.length - 1);
|
|
58
|
+
}
|
|
59
|
+
else if (computedStyle.alignContent == 'space-around') {
|
|
60
|
+
let gp = (itemRect.height - gesY) / (rows.length * 2);
|
|
61
|
+
yGap += gp * 2;
|
|
62
|
+
yOffset += gp;
|
|
63
|
+
}
|
|
64
|
+
else if (computedStyle.alignContent == 'space-evenly') {
|
|
65
|
+
let gp = (itemRect.height - gesY) / (rows.length + 1);
|
|
66
|
+
yGap += gp;
|
|
67
|
+
yOffset += gp;
|
|
68
|
+
}
|
|
69
|
+
const retVal = { cells: [], gaps: [] };
|
|
70
|
+
for (let xIdx = 0; xIdx < rows.length; xIdx++) {
|
|
71
|
+
const r = rows[xIdx];
|
|
72
|
+
let areas = null;
|
|
73
|
+
if (gridA) {
|
|
74
|
+
areas = gridA[rw + 1].split(' ');
|
|
75
|
+
}
|
|
76
|
+
let x = 0;
|
|
77
|
+
let cl = 0;
|
|
78
|
+
const currY = Number.parseFloat(r.replace('px', ''));
|
|
79
|
+
let cellList = [];
|
|
80
|
+
retVal.cells.push(cellList);
|
|
81
|
+
for (let yIdx = 0; yIdx < columns.length; yIdx++) {
|
|
82
|
+
const c = columns[yIdx];
|
|
83
|
+
if (x > 0 && xGap) {
|
|
84
|
+
retVal.gaps.push({ x: x + xOffset, y: y + yOffset, width: xGap, height: currY });
|
|
85
|
+
x += xGap;
|
|
86
|
+
}
|
|
87
|
+
const currX = Number.parseFloat(c.replace('px', ''));
|
|
88
|
+
if (y > 0 && yGap) {
|
|
89
|
+
retVal.gaps.push({ x: x + xOffset, y: y + yOffset - yGap, width: currX, height: yGap });
|
|
90
|
+
}
|
|
91
|
+
let name = null;
|
|
92
|
+
if (areas) {
|
|
93
|
+
const nm = areas[cl].trim();
|
|
94
|
+
if (nm != '.') {
|
|
95
|
+
name = nm;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const cell = { x: x + xOffset, y: y + yOffset, width: currX, height: currY, name: name };
|
|
99
|
+
cellList.push(cell);
|
|
100
|
+
x += currX;
|
|
101
|
+
cl++;
|
|
102
|
+
}
|
|
103
|
+
y += currY + yGap;
|
|
104
|
+
rw += 2;
|
|
105
|
+
}
|
|
106
|
+
return retVal;
|
|
107
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { IPoint } from "../../interfaces/IPoint.js";
|
|
2
|
+
import { IRect } from "../../interfaces/IRect.js";
|
|
1
3
|
export declare function sleep(ms: any): Promise<unknown>;
|
|
2
4
|
export declare function exportData(blob: Blob, fileName: string): Promise<void>;
|
|
3
5
|
export declare function dataURItoBlob(dataURI: any): Blob;
|
|
6
|
+
export declare function pointInRect(point: IPoint, rect: IRect): boolean;
|
|
@@ -21,3 +21,6 @@ export function dataURItoBlob(dataURI) {
|
|
|
21
21
|
}
|
|
22
22
|
return new Blob([new Uint8Array(array)], { type: mime });
|
|
23
23
|
}
|
|
24
|
+
export function pointInRect(point, rect) {
|
|
25
|
+
return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
|
|
26
|
+
}
|
|
@@ -5,7 +5,9 @@ import { ChangeGroup } from '../services/undoService/ChangeGroup';
|
|
|
5
5
|
import { NodeType } from './NodeType';
|
|
6
6
|
import { ExtensionType } from '../widgets/designerView/extensions/ExtensionType';
|
|
7
7
|
import { IDesignerExtension } from '../widgets/designerView/extensions/IDesignerExtension';
|
|
8
|
+
import { ISize } from '../../interfaces/ISize.js';
|
|
8
9
|
export declare class DesignItem implements IDesignItem {
|
|
10
|
+
lastContainerSize: ISize;
|
|
9
11
|
node: Node;
|
|
10
12
|
serviceContainer: ServiceContainer;
|
|
11
13
|
instanceServiceContainer: InstanceServiceContainer;
|
|
@@ -51,8 +53,8 @@ export declare class DesignItem implements IDesignItem {
|
|
|
51
53
|
getOrCreateDesignItem(node: Node): IDesignItem;
|
|
52
54
|
static GetOrCreateDesignItem(node: Node, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer): IDesignItem;
|
|
53
55
|
static GetDesignItem(node: Node): IDesignItem;
|
|
54
|
-
setStyle(name:
|
|
55
|
-
removeStyle(name:
|
|
56
|
+
setStyle(name: string, value?: string | null): void;
|
|
57
|
+
removeStyle(name: string): void;
|
|
56
58
|
setAttribute(name: string, value?: string | null): void;
|
|
57
59
|
removeAttribute(name: string): void;
|
|
58
60
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { CssStyleChangeAction } from '../services/undoService/transactionItems/CssStyleChangeAction';
|
|
2
2
|
import { NodeType } from './NodeType';
|
|
3
3
|
import { AttributeChangeAction } from '../services/undoService/transactionItems/AttributeChangeAction';
|
|
4
|
-
//import { PropertyChangeAction } from '../services/undoService/transactionItems/PropertyChangeAction';
|
|
5
4
|
import { ExtensionType } from '../widgets/designerView/extensions/ExtensionType';
|
|
6
5
|
import { DomHelper } from '@node-projects/base-custom-webcomponent/dist/DomHelper';
|
|
7
6
|
import { CssAttributeParser } from '../helper/CssAttributeParser.js';
|
|
7
|
+
import { PropertiesHelper } from '../services/propertiesService/services/PropertiesHelper.js';
|
|
8
8
|
const hideAtDesignTimeAttributeName = 'node-projects-hide-at-design-time';
|
|
9
9
|
const hideAtRunTimeAttributeName = 'node-projects-hide-at-run-time';
|
|
10
10
|
const lockAtDesignTimeAttributeName = 'node-projects-lock-at-design-time';
|
|
11
11
|
export class DesignItem {
|
|
12
|
+
lastContainerSize;
|
|
12
13
|
node;
|
|
13
14
|
serviceContainer;
|
|
14
15
|
instanceServiceContainer;
|
|
@@ -241,11 +242,13 @@ export class DesignItem {
|
|
|
241
242
|
return designItem;
|
|
242
243
|
}
|
|
243
244
|
setStyle(name, value) {
|
|
244
|
-
|
|
245
|
+
let nm = PropertiesHelper.camelToDashCase(name);
|
|
246
|
+
const action = new CssStyleChangeAction(this, nm, value, this.styles.get(nm));
|
|
245
247
|
this.instanceServiceContainer.undoService.execute(action);
|
|
246
248
|
}
|
|
247
249
|
removeStyle(name) {
|
|
248
|
-
|
|
250
|
+
let nm = PropertiesHelper.camelToDashCase(name);
|
|
251
|
+
const action = new CssStyleChangeAction(this, nm, '', this.styles.get(nm));
|
|
249
252
|
this.instanceServiceContainer.undoService.execute(action);
|
|
250
253
|
}
|
|
251
254
|
setAttribute(name, value) {
|
|
@@ -4,7 +4,9 @@ import { ChangeGroup } from "../services/undoService/ChangeGroup";
|
|
|
4
4
|
import { NodeType } from './NodeType';
|
|
5
5
|
import { ExtensionType } from "../widgets/designerView/extensions/ExtensionType";
|
|
6
6
|
import { IDesignerExtension } from "../widgets/designerView/extensions/IDesignerExtension";
|
|
7
|
+
import { ISize } from "../../interfaces/ISize.js";
|
|
7
8
|
export interface IDesignItem {
|
|
9
|
+
lastContainerSize: ISize;
|
|
8
10
|
replaceNode(newNode: Node): any;
|
|
9
11
|
readonly nodeType: NodeType;
|
|
10
12
|
readonly name: string;
|
|
@@ -53,12 +53,7 @@ export class HtmlWriterService {
|
|
|
53
53
|
styles = CssCombiner.combine(styles);
|
|
54
54
|
for (const s of styles) {
|
|
55
55
|
if (s[0]) {
|
|
56
|
-
|
|
57
|
-
indentedTextWriter.write(PropertiesHelper.camelToDashCase(s[0]) + ':' + DomConverter.normalizeAttributeValue(s[1]) + ';');
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
//TODO: writing of bindings
|
|
61
|
-
}
|
|
56
|
+
indentedTextWriter.write(PropertiesHelper.camelToDashCase(s[0]) + ':' + DomConverter.normalizeAttributeValue(s[1]) + ';');
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
59
|
indentedTextWriter.write('"');
|
|
@@ -82,6 +82,12 @@ export class DefaultPlacementService {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
enterContainer(container, items) {
|
|
85
|
+
for (let i of items) {
|
|
86
|
+
if (i.lastContainerSize) {
|
|
87
|
+
i.setStyle('width', i.lastContainerSize.width + 'px');
|
|
88
|
+
i.setStyle('height', i.lastContainerSize.height + 'px');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
85
91
|
}
|
|
86
92
|
leaveContainer(container, items) {
|
|
87
93
|
}
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
import { CalculateGridInformation } from '../../helper/GridHelper.js';
|
|
2
|
+
import { pointInRect } from '../../helper/Helper.js';
|
|
1
3
|
export class GridPlacementService {
|
|
2
4
|
enterContainer(container, items) {
|
|
5
|
+
for (let i of items) {
|
|
6
|
+
i.removeStyle("position");
|
|
7
|
+
i.removeStyle("left");
|
|
8
|
+
i.removeStyle("top");
|
|
9
|
+
i.removeStyle("right");
|
|
10
|
+
i.removeStyle("width");
|
|
11
|
+
i.removeStyle("height");
|
|
12
|
+
i.removeStyle("transform");
|
|
13
|
+
}
|
|
3
14
|
}
|
|
4
15
|
leaveContainer(container, items) {
|
|
16
|
+
for (let i of items) {
|
|
17
|
+
if (!i.lastContainerSize) {
|
|
18
|
+
const rect = i.element.getBoundingClientRect();
|
|
19
|
+
i.lastContainerSize = { width: rect.width, height: rect.height };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
5
22
|
}
|
|
6
23
|
serviceForContainer(container) {
|
|
7
24
|
if (container.element.style.display == 'grid' || container.element.style.display == 'inline-grid')
|
|
@@ -15,14 +32,48 @@ export class GridPlacementService {
|
|
|
15
32
|
return true;
|
|
16
33
|
}
|
|
17
34
|
getElementOffset(container, designItem) {
|
|
18
|
-
//TODO: offset could be bigger, when it was in a other cell???
|
|
19
35
|
return container.element.getBoundingClientRect();
|
|
20
36
|
}
|
|
21
37
|
placePoint(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
22
38
|
return null;
|
|
23
39
|
}
|
|
24
40
|
place(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
41
|
+
const gridInformation = CalculateGridInformation(container);
|
|
42
|
+
const pos = placementView.getNormalizedEventCoordinates(event);
|
|
43
|
+
const posElement = placementView.getNormalizedElementCoordinates(items[0].element);
|
|
44
|
+
let row = 0;
|
|
45
|
+
let column = 0;
|
|
46
|
+
if (!pointInRect(pos, posElement)) {
|
|
47
|
+
row = 0;
|
|
48
|
+
for (let cellRow of gridInformation.cells) {
|
|
49
|
+
column = 0;
|
|
50
|
+
for (let cell of cellRow) {
|
|
51
|
+
if (pointInRect(pos, cell)) {
|
|
52
|
+
items[0].element.style.gridColumn = column + 1;
|
|
53
|
+
items[0].element.style.gridRow = row + 1;
|
|
54
|
+
}
|
|
55
|
+
column++;
|
|
56
|
+
}
|
|
57
|
+
row++;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
25
60
|
}
|
|
26
61
|
finishPlace(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
62
|
+
const gridInformation = CalculateGridInformation(container);
|
|
63
|
+
const pos = placementView.getNormalizedEventCoordinates(event);
|
|
64
|
+
let row = 0;
|
|
65
|
+
let column = 0;
|
|
66
|
+
row = 0;
|
|
67
|
+
for (let cellRow of gridInformation.cells) {
|
|
68
|
+
column = 0;
|
|
69
|
+
for (let cell of cellRow) {
|
|
70
|
+
if (pointInRect(pos, cell)) {
|
|
71
|
+
items[0].setStyle('grid-column', column + 1);
|
|
72
|
+
items[0].setStyle('grid-row', row + 1);
|
|
73
|
+
}
|
|
74
|
+
column++;
|
|
75
|
+
}
|
|
76
|
+
row++;
|
|
77
|
+
}
|
|
27
78
|
}
|
|
28
79
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ITransactionItem } from '../ITransactionItem';
|
|
2
2
|
import { IDesignItem } from '../../../item/IDesignItem';
|
|
3
3
|
export declare class CssStyleChangeAction implements ITransactionItem {
|
|
4
|
-
constructor(designItem: IDesignItem, name:
|
|
4
|
+
constructor(designItem: IDesignItem, name: string, newValue: any, oldValue: any);
|
|
5
5
|
title?: string;
|
|
6
6
|
get affectedItems(): IDesignItem[];
|
|
7
7
|
undo(): void;
|
|
8
8
|
do(): void;
|
|
9
9
|
designItem: IDesignItem;
|
|
10
|
-
name:
|
|
10
|
+
name: string;
|
|
11
11
|
newValue: any;
|
|
12
12
|
oldValue: any;
|
|
13
13
|
mergeWith(other: ITransactionItem): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IDesignItem } from "../../item/IDesignItem";
|
|
2
2
|
import { IStringPosition } from "../../services/htmlWriterService/IStringPosition";
|
|
3
3
|
export declare class DomConverter {
|
|
4
|
-
static normalizeAttributeValue(value: string): string;
|
|
4
|
+
static normalizeAttributeValue(value: string | number): string;
|
|
5
5
|
static normalizeContentValue(value: string): string;
|
|
6
6
|
static IsSelfClosingElement(tag: string): boolean;
|
|
7
7
|
static ConvertToString(designItems: IDesignItem[], designItemsAssignmentList?: Map<IDesignItem, IStringPosition>): string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { IndentedTextWriter } from "../../helper/IndentedTextWriter";
|
|
2
2
|
export class DomConverter {
|
|
3
3
|
static normalizeAttributeValue(value) {
|
|
4
|
+
if (typeof value === 'number')
|
|
5
|
+
value = value.toString();
|
|
4
6
|
if (value)
|
|
5
7
|
return value.replaceAll('"', '"');
|
|
6
8
|
return value;
|
|
@@ -7,6 +7,7 @@ import { IExtensionManager } from "./extensions/IExtensionManger";
|
|
|
7
7
|
import { IUiCommandHandler } from "../../../commandHandling/IUiCommandHandler";
|
|
8
8
|
import { IPoint } from "../../../interfaces/IPoint";
|
|
9
9
|
import { OverlayLayerView } from "./overlayLayerView";
|
|
10
|
+
import { IRect } from "../../../interfaces/IRect.js";
|
|
10
11
|
export interface IDesignerCanvas extends IPlacementView, IUiCommandHandler {
|
|
11
12
|
readonly serviceContainer: ServiceContainer;
|
|
12
13
|
readonly instanceServiceContainer: InstanceServiceContainer;
|
|
@@ -22,6 +23,7 @@ export interface IDesignerCanvas extends IPlacementView, IUiCommandHandler {
|
|
|
22
23
|
eatEvents: Element;
|
|
23
24
|
initialize(serviceContainer: ServiceContainer): any;
|
|
24
25
|
getNormalizedEventCoordinates(event: MouseEvent): IPoint;
|
|
26
|
+
getNormalizedElementCoordinates(element: Element): IRect;
|
|
25
27
|
getNormalizedOffsetInElement(event: MouseEvent, element: Element): IPoint;
|
|
26
28
|
getElementAtPoint(point: IPoint, ignoreElementCallback?: (element: HTMLElement) => boolean): any;
|
|
27
29
|
elementFromPoint(x: number, y: number): Element;
|
|
@@ -12,6 +12,7 @@ import { IExtensionManager } from "./extensions/IExtensionManger";
|
|
|
12
12
|
import { IPoint } from "../../../interfaces/IPoint";
|
|
13
13
|
import { OverlayLayer } from "./extensions/OverlayLayer";
|
|
14
14
|
import { OverlayLayerView } from './overlayLayerView';
|
|
15
|
+
import { IRect } from "../../../interfaces/IRect.js";
|
|
15
16
|
export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend implements IDesignerCanvas, IPlacementView, IUiCommandHandler {
|
|
16
17
|
serviceContainer: ServiceContainer;
|
|
17
18
|
instanceServiceContainer: InstanceServiceContainer;
|
|
@@ -69,7 +70,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
|
|
|
69
70
|
private onKeyUp;
|
|
70
71
|
private onKeyDown;
|
|
71
72
|
getNormalizedEventCoordinates(event: MouseEvent): IPoint;
|
|
72
|
-
getNormalizedElementCoordinates(element: Element):
|
|
73
|
+
getNormalizedElementCoordinates(element: Element): IRect;
|
|
73
74
|
getNormalizedOffsetInElement(event: MouseEvent, element: Element): IPoint;
|
|
74
75
|
static getHost(node: Node): Element;
|
|
75
76
|
getElementAtPoint(point: IPoint, ignoreElementCallback?: (element: HTMLElement) => boolean): HTMLElement;
|
|
@@ -489,7 +489,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
489
489
|
}
|
|
490
490
|
getNormalizedElementCoordinates(element) {
|
|
491
491
|
const targetRect = element.getBoundingClientRect();
|
|
492
|
-
return { x: targetRect.x - this.containerBoundingRect.x, y: targetRect.y - this.containerBoundingRect.y };
|
|
492
|
+
return { x: targetRect.x - this.containerBoundingRect.x, y: targetRect.y - this.containerBoundingRect.y, width: targetRect.width, height: targetRect.height };
|
|
493
493
|
}
|
|
494
494
|
getNormalizedOffsetInElement(event, element) {
|
|
495
495
|
const normEvt = this.getNormalizedEventCoordinates(event);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CalculateGridInformation } from "../../../helper/GridHelper.js";
|
|
1
2
|
import { AbstractExtension } from "./AbstractExtension";
|
|
2
3
|
import { OverlayLayer } from "./OverlayLayer.js";
|
|
3
4
|
export class GridExtension extends AbstractExtension {
|
|
@@ -5,105 +6,18 @@ export class GridExtension extends AbstractExtension {
|
|
|
5
6
|
super(extensionManager, designerView, extendedItem);
|
|
6
7
|
}
|
|
7
8
|
extend() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let gridA = null;
|
|
19
|
-
if (computedStyle.gridTemplateAreas && computedStyle.gridTemplateAreas !== 'none')
|
|
20
|
-
gridA = computedStyle.gridTemplateAreas.split('\"');
|
|
21
|
-
if (computedStyle.columnGap && computedStyle.columnGap != 'normal')
|
|
22
|
-
xGap = Number.parseFloat(computedStyle.columnGap.replace('px', ''));
|
|
23
|
-
if (computedStyle.rowGap && computedStyle.rowGap != 'normal')
|
|
24
|
-
yGap = Number.parseFloat(computedStyle.rowGap.replace('px', ''));
|
|
25
|
-
let gesX = 0;
|
|
26
|
-
let gesY = 0;
|
|
27
|
-
for (let c of columns) {
|
|
28
|
-
const currX = Number.parseFloat(c.replace('px', ''));
|
|
29
|
-
gesX += currX + xGap;
|
|
30
|
-
}
|
|
31
|
-
gesX -= xGap;
|
|
32
|
-
for (let r of rows) {
|
|
33
|
-
const currY = Number.parseFloat(r.replace('px', ''));
|
|
34
|
-
gesY += currY + yGap;
|
|
35
|
-
}
|
|
36
|
-
gesY -= yGap;
|
|
37
|
-
if (computedStyle.justifyContent == 'center') {
|
|
38
|
-
xOffset += (itemRect.width - gesX) / 2;
|
|
39
|
-
}
|
|
40
|
-
else if (computedStyle.justifyContent == 'end') {
|
|
41
|
-
xOffset += itemRect.width - gesX;
|
|
42
|
-
}
|
|
43
|
-
else if (computedStyle.justifyContent == 'space-between') {
|
|
44
|
-
xGap += (itemRect.width - gesX) / (columns.length - 1);
|
|
45
|
-
}
|
|
46
|
-
else if (computedStyle.justifyContent == 'space-around') {
|
|
47
|
-
let gp = (itemRect.width - gesX) / (columns.length * 2);
|
|
48
|
-
xGap += gp * 2;
|
|
49
|
-
xOffset += gp;
|
|
50
|
-
}
|
|
51
|
-
else if (computedStyle.justifyContent == 'space-evenly') {
|
|
52
|
-
let gp = (itemRect.width - gesX) / (columns.length + 1);
|
|
53
|
-
xGap += gp;
|
|
54
|
-
xOffset += gp;
|
|
55
|
-
}
|
|
56
|
-
if (computedStyle.alignContent == 'center') {
|
|
57
|
-
xOffset += (itemRect.height - gesY) / 2;
|
|
58
|
-
}
|
|
59
|
-
else if (computedStyle.alignContent == 'end') {
|
|
60
|
-
xOffset += itemRect.height - gesY;
|
|
61
|
-
}
|
|
62
|
-
else if (computedStyle.alignContent == 'space-between') {
|
|
63
|
-
yGap += (itemRect.height - gesY) / (rows.length - 1);
|
|
64
|
-
}
|
|
65
|
-
else if (computedStyle.alignContent == 'space-around') {
|
|
66
|
-
let gp = (itemRect.height - gesY) / (rows.length * 2);
|
|
67
|
-
yGap += gp * 2;
|
|
68
|
-
yOffset += gp;
|
|
69
|
-
}
|
|
70
|
-
else if (computedStyle.alignContent == 'space-evenly') {
|
|
71
|
-
let gp = (itemRect.height - gesY) / (rows.length + 1);
|
|
72
|
-
yGap += gp;
|
|
73
|
-
yOffset += gp;
|
|
74
|
-
}
|
|
75
|
-
for (let xIdx = 0; xIdx < rows.length; xIdx++) {
|
|
76
|
-
const r = rows[xIdx];
|
|
77
|
-
let areas = null;
|
|
78
|
-
if (gridA) {
|
|
79
|
-
areas = gridA[rw + 1].split(' ');
|
|
80
|
-
}
|
|
81
|
-
let x = 0;
|
|
82
|
-
let cl = 0;
|
|
83
|
-
const currY = Number.parseFloat(r.replace('px', ''));
|
|
84
|
-
for (let yIdx = 0; yIdx < columns.length; yIdx++) {
|
|
85
|
-
const c = columns[yIdx];
|
|
86
|
-
if (x > 0 && xGap) {
|
|
87
|
-
this._drawRect(x + xOffset, y + yOffset, xGap, currY, 'svg-grid-gap', null, OverlayLayer.Background);
|
|
88
|
-
x += xGap;
|
|
89
|
-
}
|
|
90
|
-
const currX = Number.parseFloat(c.replace('px', ''));
|
|
91
|
-
if (y > 0 && yGap) {
|
|
92
|
-
this._drawRect(x + xOffset, y + yOffset - yGap, currX, yGap, 'svg-grid-gap', null, OverlayLayer.Background);
|
|
93
|
-
}
|
|
94
|
-
if (areas) {
|
|
95
|
-
const nm = areas[cl].trim();
|
|
96
|
-
if (nm != '.') {
|
|
97
|
-
const text = this._drawText(nm, x + xOffset, y + yOffset, 'svg-grid-area', null, OverlayLayer.Background);
|
|
98
|
-
text.setAttribute("dominant-baseline", "hanging");
|
|
99
|
-
}
|
|
9
|
+
const gridInformation = CalculateGridInformation(this.extendedItem);
|
|
10
|
+
for (let gap of gridInformation.gaps) {
|
|
11
|
+
this._drawRect(gap.x, gap.y, gap.width, gap.height, 'svg-grid-gap', null, OverlayLayer.Background);
|
|
12
|
+
}
|
|
13
|
+
for (let cellRow of gridInformation.cells) {
|
|
14
|
+
for (let cell of cellRow) {
|
|
15
|
+
this._drawRect(cell.x, cell.y, cell.width, cell.height, 'svg-grid', null, OverlayLayer.Background);
|
|
16
|
+
if (cell.name) {
|
|
17
|
+
const text = this._drawText(cell.name, cell.x, cell.y, 'svg-grid-area', null, OverlayLayer.Background);
|
|
18
|
+
text.setAttribute("dominant-baseline", "hanging");
|
|
100
19
|
}
|
|
101
|
-
this._drawRect(x + xOffset, y + yOffset, currX, currY, 'svg-grid', null, OverlayLayer.Background);
|
|
102
|
-
x += currX;
|
|
103
|
-
cl++;
|
|
104
20
|
}
|
|
105
|
-
y += currY + yGap;
|
|
106
|
-
rw += 2;
|
|
107
21
|
}
|
|
108
22
|
}
|
|
109
23
|
refresh() {
|
|
@@ -50,8 +50,8 @@ export class TransformOriginExtension extends AbstractExtension {
|
|
|
50
50
|
const newY = (dy + y);
|
|
51
51
|
const przX = Math.round(newX / rect.width * 10000) / 100; //round to 2 decimal places
|
|
52
52
|
const przY = Math.round(newY / rect.height * 10000) / 100;
|
|
53
|
-
//this.extendedItem.setStyle('
|
|
54
|
-
this.extendedItem.setStyle('
|
|
53
|
+
//this.extendedItem.setStyle('transform-origin',newX + 'px ' + newY + 'px');
|
|
54
|
+
this.extendedItem.setStyle('transform-origin', przX + '% ' + przY + '%');
|
|
55
55
|
this.refresh();
|
|
56
56
|
this._startPos = null;
|
|
57
57
|
}
|