@node-projects/web-component-designer 0.1.16 → 0.1.17
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/Constants.js +0 -1
- package/dist/elements/helper/LayoutHelper.d.ts +1 -0
- package/dist/elements/helper/LayoutHelper.js +11 -2
- package/dist/elements/services/placementService/DefaultPlacementService.js +6 -3
- package/dist/elements/widgets/designerView/designerCanvas.d.ts +3 -1
- package/dist/elements/widgets/designerView/designerCanvas.js +22 -1
- package/dist/elements/widgets/designerView/designerView.js +10 -0
- package/package.json +1 -1
package/dist/Constants.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export const dragDropFormatNameElementDefinition = 'text/json/elementdefintion';
|
|
2
2
|
export const dragDropFormatNameBindingObject = 'text/json/bindingobject';
|
|
3
3
|
export const dragDropFormatNamePropertyGrid = 'text/json/propertydrop';
|
|
4
|
-
//export const assetsPath = './node_modules/@node-projects/web-component-designer/assets/';
|
|
5
4
|
let imporUrl = new URL((import.meta.url));
|
|
6
5
|
export var assetsPath = imporUrl.origin + imporUrl.pathname.split('/').slice(0, -1).join('/') + '/../assets/';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IPoint } from "../../interfaces/IPoint.js";
|
|
2
2
|
import { IDesignItem } from "../item/IDesignItem.js";
|
|
3
3
|
export declare function filterChildPlaceItems(items: IDesignItem[]): IDesignItem[];
|
|
4
|
+
export declare function getDesignItemCurrentPos(designItem: IDesignItem, mode: 'position' | 'transform' | 'margin' | 'padding'): IPoint;
|
|
4
5
|
export declare function placeDesignItem(container: IDesignItem, designItem: IDesignItem, offset: IPoint, mode: 'position' | 'transform' | 'margin' | 'padding'): void;
|
|
@@ -14,6 +14,17 @@ export function filterChildPlaceItems(items) {
|
|
|
14
14
|
}
|
|
15
15
|
return filterdPlaceItems;
|
|
16
16
|
}
|
|
17
|
+
export function getDesignItemCurrentPos(designItem, mode) {
|
|
18
|
+
if (mode === 'position') {
|
|
19
|
+
const computedStyleMovedElement = getComputedStyle(designItem.element);
|
|
20
|
+
let oldLeft = parseFloat(computedStyleMovedElement.left);
|
|
21
|
+
oldLeft = Number.isNaN(oldLeft) ? null : oldLeft;
|
|
22
|
+
let oldTop = parseFloat(computedStyleMovedElement.top);
|
|
23
|
+
oldTop = Number.isNaN(oldTop) ? null : oldTop;
|
|
24
|
+
return { x: oldLeft, y: oldTop };
|
|
25
|
+
}
|
|
26
|
+
return { x: 0, y: 0 };
|
|
27
|
+
}
|
|
17
28
|
export function placeDesignItem(container, designItem, offset, mode) {
|
|
18
29
|
const movedElement = designItem.element;
|
|
19
30
|
const computedStyleMovedElement = getComputedStyle(movedElement);
|
|
@@ -29,10 +40,8 @@ export function placeDesignItem(container, designItem, offset, mode) {
|
|
|
29
40
|
let oldTop = null;
|
|
30
41
|
let oldBottom = null;
|
|
31
42
|
let containerLeft = 0;
|
|
32
|
-
//@ts-ignore
|
|
33
43
|
let containerRight = 0;
|
|
34
44
|
let containerTop = 0;
|
|
35
|
-
//@ts-ignore
|
|
36
45
|
let containerBottom = 0;
|
|
37
46
|
let hasPositionedLayout = false;
|
|
38
47
|
if (computedStyleMovedElement.position === 'relative' || computedStyleMovedElement.position === 'absolute') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DomConverter } from '../../widgets/designerView/DomConverter.js';
|
|
2
2
|
import { combineTransforms, extractTranslationFromDOMMatrix, getResultingTransformationBetweenElementAndAllAncestors } from '../../helper/TransformHelper.js';
|
|
3
|
-
import { filterChildPlaceItems, placeDesignItem } from '../../helper/LayoutHelper.js';
|
|
3
|
+
import { filterChildPlaceItems, getDesignItemCurrentPos, placeDesignItem } from '../../helper/LayoutHelper.js';
|
|
4
4
|
import { ExtensionType } from '../../widgets/designerView/extensions/ExtensionType.js';
|
|
5
5
|
import { straightenLine } from '../../helper/PathDataPolyfill.js';
|
|
6
6
|
export class DefaultPlacementService {
|
|
@@ -35,8 +35,11 @@ export class DefaultPlacementService {
|
|
|
35
35
|
let trackY = newPoint.y - startPoint.y;
|
|
36
36
|
if (!event.ctrlKey) {
|
|
37
37
|
if (placementView.alignOnGrid) {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
let p = getDesignItemCurrentPos(item, 'position');
|
|
39
|
+
p.x = p.x % placementView.gridSize;
|
|
40
|
+
p.y = p.y % placementView.gridSize;
|
|
41
|
+
trackX = Math.round(trackX / placementView.gridSize) * placementView.gridSize - p.x;
|
|
42
|
+
trackY = Math.round(trackY / placementView.gridSize) * placementView.gridSize - p.y;
|
|
40
43
|
}
|
|
41
44
|
else if (placementView.alignOnSnap) {
|
|
42
45
|
let rect = item.element.getBoundingClientRect();
|
|
@@ -22,7 +22,9 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
|
|
|
22
22
|
outerRect: DOMRect;
|
|
23
23
|
clickOverlay: HTMLDivElement;
|
|
24
24
|
private _activeTool;
|
|
25
|
-
|
|
25
|
+
private _gridSize;
|
|
26
|
+
get gridSize(): number;
|
|
27
|
+
set gridSize(value: number);
|
|
26
28
|
pasteOffset: number;
|
|
27
29
|
alignOnGrid: boolean;
|
|
28
30
|
alignOnSnap: boolean;
|
|
@@ -29,7 +29,28 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
29
29
|
clickOverlay;
|
|
30
30
|
_activeTool;
|
|
31
31
|
// IPlacementView
|
|
32
|
-
|
|
32
|
+
_gridSize = 10;
|
|
33
|
+
get gridSize() {
|
|
34
|
+
return this._gridSize;
|
|
35
|
+
}
|
|
36
|
+
set gridSize(value) {
|
|
37
|
+
this._gridSize = value;
|
|
38
|
+
const canvas = document.createElement("canvas");
|
|
39
|
+
const context = canvas.getContext("2d");
|
|
40
|
+
canvas.width = value * 2;
|
|
41
|
+
canvas.height = value * 2;
|
|
42
|
+
const patternSize = value;
|
|
43
|
+
for (let x = 0; x < canvas.width; x += patternSize) {
|
|
44
|
+
for (let y = 0; y < canvas.height; y += patternSize) {
|
|
45
|
+
context.fillStyle = (x + y) % (patternSize * 2) === 0 ? "#e5e5e5" : "white";
|
|
46
|
+
context.fillRect(x, y, patternSize, patternSize);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const dataURL = canvas.toDataURL();
|
|
50
|
+
this._backgroundImage = 'url(' + dataURL + ')';
|
|
51
|
+
if (this._canvas.style.backgroundImage != 'none')
|
|
52
|
+
this._canvas.style.backgroundImage = this._backgroundImage;
|
|
53
|
+
}
|
|
33
54
|
pasteOffset = 10;
|
|
34
55
|
alignOnGrid = false;
|
|
35
56
|
alignOnSnap = true;
|
|
@@ -212,9 +212,19 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
212
212
|
let alignSnap = this._getDomElement('alignSnap');
|
|
213
213
|
alignSnap.onclick = () => { this._designerCanvas.alignOnSnap = !this._designerCanvas.alignOnSnap; alignSnap.style.backgroundColor = this._designerCanvas.alignOnSnap ? 'deepskyblue' : ''; };
|
|
214
214
|
alignSnap.style.backgroundColor = this._designerCanvas.alignOnSnap ? 'deepskyblue' : '';
|
|
215
|
+
alignSnap.oncontextmenu = e => { e.preventDefault(); };
|
|
215
216
|
let alignGrid = this._getDomElement('alignGrid');
|
|
216
217
|
alignGrid.onclick = () => { this._designerCanvas.alignOnGrid = !this._designerCanvas.alignOnGrid; alignGrid.style.backgroundColor = this._designerCanvas.alignOnGrid ? 'deepskyblue' : ''; };
|
|
217
218
|
alignGrid.style.backgroundColor = this._designerCanvas.alignOnGrid ? 'deepskyblue' : '';
|
|
219
|
+
alignGrid.oncontextmenu = e => {
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
let res = prompt("raster size", this.designerCanvas.gridSize.toString());
|
|
222
|
+
if (res) {
|
|
223
|
+
let r = parseInt(res);
|
|
224
|
+
if (r > 0)
|
|
225
|
+
this.designerCanvas.gridSize = r;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
218
228
|
this._lowertoolbar = this._getDomElement('lowertoolbar');
|
|
219
229
|
this._sVert.addEventListener('scrollbar-input', (e) => this._onScrollbar(e));
|
|
220
230
|
this._sHor.addEventListener('scrollbar-input', (e) => this._onScrollbar(e));
|