@node-projects/web-component-designer 0.0.271 → 0.0.273
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/controls/MetricsEditor.js +1 -0
- package/dist/elements/helper/GridHelper.d.ts +4 -0
- package/dist/elements/helper/GridHelper.js +14 -0
- package/dist/elements/helper/Helper.js +2 -2
- package/dist/elements/helper/NpmPackageLoader.js +4 -2
- package/dist/elements/item/DesignItem.d.ts +3 -0
- package/dist/elements/item/DesignItem.js +10 -1
- package/dist/elements/services/eventsService/IEvent.d.ts +1 -1
- package/dist/elements/services/htmlWriterService/HtmlWriterService.js +7 -3
- package/dist/elements/services/placementService/GridPlacementService.js +22 -24
- package/dist/elements/services/propertiesService/ValueType.d.ts +2 -1
- package/dist/elements/services/propertiesService/ValueType.js +1 -0
- package/dist/elements/services/propertiesService/services/AbstractPropertiesService.d.ts +3 -0
- package/dist/elements/services/propertiesService/services/AbstractPropertiesService.js +19 -3
- package/dist/elements/widgets/propertyGrid/PropertyGridPropertyList.js +4 -0
- package/package.json +10 -10
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { IDesignItem } from "../item/IDesignItem.js";
|
|
2
|
+
export declare function GetElementGridInformation(element: HTMLElement): {
|
|
3
|
+
colSpan: number;
|
|
4
|
+
rowSpan: number;
|
|
5
|
+
};
|
|
2
6
|
export declare function CalculateGridInformation(designItem: IDesignItem): {
|
|
3
7
|
cells?: {
|
|
4
8
|
x: number;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { getDesignerCanvasNormalizedTransformedCornerDOMPoints } from "./TransformHelper.js";
|
|
2
|
+
export function GetElementGridInformation(element) {
|
|
3
|
+
let cs = getComputedStyle(element);
|
|
4
|
+
let rowSpan = 1;
|
|
5
|
+
let colSpan = 1;
|
|
6
|
+
if (cs.gridRowEnd.startsWith('span'))
|
|
7
|
+
rowSpan = parseInt(cs.gridRowEnd.substring(4));
|
|
8
|
+
else
|
|
9
|
+
rowSpan = parseInt(cs.gridRowEnd) - parseInt(cs.gridRowStart);
|
|
10
|
+
if (cs.gridColumnEnd.startsWith('span'))
|
|
11
|
+
colSpan = parseInt(cs.gridColumnEnd.substring(4));
|
|
12
|
+
else
|
|
13
|
+
colSpan = parseInt(cs.gridColumnEnd) - parseInt(cs.gridColumnStart);
|
|
14
|
+
return { colSpan, rowSpan };
|
|
15
|
+
}
|
|
2
16
|
export function CalculateGridInformation(designItem) {
|
|
3
17
|
//todo:
|
|
4
18
|
//same name should combine columns/rows
|
|
@@ -25,12 +25,12 @@ export function pointInRect(point, rect) {
|
|
|
25
25
|
return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
|
|
26
26
|
}
|
|
27
27
|
export function removeTrailing(text, char) {
|
|
28
|
-
if (text.endsWith('/'))
|
|
28
|
+
if (text.endsWith(char ?? '/'))
|
|
29
29
|
return text.substring(0, text.length - 1);
|
|
30
30
|
return text;
|
|
31
31
|
}
|
|
32
32
|
export function removeLeading(text, char) {
|
|
33
|
-
if (text.startsWith('/'))
|
|
33
|
+
if (text.startsWith(char ?? '/'))
|
|
34
34
|
return text.substring(1);
|
|
35
35
|
return text;
|
|
36
36
|
}
|
|
@@ -288,15 +288,17 @@ export class NpmPackageLoader {
|
|
|
288
288
|
i = getImport(i);
|
|
289
289
|
if (!(typeof i == 'string'))
|
|
290
290
|
i = getImport(i);
|
|
291
|
+
if (!(typeof i == 'string'))
|
|
292
|
+
i = null;
|
|
291
293
|
return i;
|
|
292
294
|
};
|
|
293
295
|
//Names to use: browser, import, default, node
|
|
294
296
|
let imp = getImportFlat(packageJsonObj.exports);
|
|
295
297
|
if (imp) {
|
|
296
|
-
importMap.imports[packageJsonObj.name] = baseUrl + removeTrailing(imp, '/');
|
|
298
|
+
importMap.imports[packageJsonObj.name] = baseUrl + removeLeading(removeTrailing(imp, '/'), '.');
|
|
297
299
|
}
|
|
298
300
|
else if (imp = getImportFlat(packageJsonObj.exports?.['.'])) {
|
|
299
|
-
importMap.imports[packageJsonObj.name] = baseUrl + removeTrailing(imp, '/');
|
|
301
|
+
importMap.imports[packageJsonObj.name] = baseUrl + removeLeading(removeTrailing(imp, '/'), '.');
|
|
300
302
|
}
|
|
301
303
|
}
|
|
302
304
|
let mainImport = packageJsonObj.main;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ServiceContainer } from '../services/ServiceContainer.js';
|
|
2
3
|
import { IDesignItem } from './IDesignItem.js';
|
|
3
4
|
import { InstanceServiceContainer } from '../services/InstanceServiceContainer.js';
|
|
@@ -80,6 +81,8 @@ export declare class DesignItem implements IDesignItem {
|
|
|
80
81
|
getStyleFromSheetOrLocal(name: string, fallback?: string): string;
|
|
81
82
|
getStyleFromSheetOrLocalOrComputed(name: string, fallback?: string): string;
|
|
82
83
|
getComputedStyle(name: string, fallback?: string): string;
|
|
84
|
+
_stylesCache: IStyleRule[];
|
|
85
|
+
_cacheClearTimer: NodeJS.Timeout;
|
|
83
86
|
getAllStyles(): IStyleRule[];
|
|
84
87
|
setAttribute(name: string, value?: string | null): void;
|
|
85
88
|
removeAttribute(name: string): void;
|
|
@@ -399,7 +399,12 @@ export class DesignItem {
|
|
|
399
399
|
}
|
|
400
400
|
return value ?? fallback;
|
|
401
401
|
}
|
|
402
|
+
_stylesCache = null;
|
|
403
|
+
_cacheClearTimer;
|
|
402
404
|
getAllStyles() {
|
|
405
|
+
let styles = this._stylesCache;
|
|
406
|
+
if (styles)
|
|
407
|
+
return styles;
|
|
403
408
|
if (this.nodeType != NodeType.Element)
|
|
404
409
|
return [];
|
|
405
410
|
const localStyles = [...this._styles.entries()].map(x => ({ name: x[0], value: x[1], important: false, parent: null }));
|
|
@@ -412,7 +417,11 @@ export class DesignItem {
|
|
|
412
417
|
}
|
|
413
418
|
catch (err) { }
|
|
414
419
|
}
|
|
415
|
-
|
|
420
|
+
styles = [{ selector: null, declarations: localStyles, specificity: -1 }];
|
|
421
|
+
this._stylesCache = styles;
|
|
422
|
+
clearTimeout(this._cacheClearTimer);
|
|
423
|
+
this._cacheClearTimer = setTimeout(() => this._stylesCache = null, 30);
|
|
424
|
+
return styles;
|
|
416
425
|
}
|
|
417
426
|
setAttribute(name, value) {
|
|
418
427
|
if (this.isRootItem)
|
|
@@ -30,6 +30,7 @@ export class HtmlWriterService extends AbstractHtmlWriterService {
|
|
|
30
30
|
this.internalWrite(indentedTextWriter, d, updatePositions);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
//todo special case for style/script nodes, keep whitespace
|
|
33
34
|
internalWrite(indentedTextWriter, designItem, updatePositions) {
|
|
34
35
|
let start = indentedTextWriter.position;
|
|
35
36
|
let end = indentedTextWriter.position;
|
|
@@ -61,7 +62,8 @@ export class HtmlWriterService extends AbstractHtmlWriterService {
|
|
|
61
62
|
const children = designItem.children();
|
|
62
63
|
contentSingleTextNode = designItem.childCount === 1 && designItem.firstChild.nodeType === NodeType.TextNode;
|
|
63
64
|
if (contentSingleTextNode) {
|
|
64
|
-
|
|
65
|
+
const notrim = designItem.name == 'script' || designItem.name == 'style' || designItem.name == 'pre';
|
|
66
|
+
this.writeTextNode(indentedTextWriter, designItem, false, !notrim);
|
|
65
67
|
}
|
|
66
68
|
else {
|
|
67
69
|
if (designItem.element instanceof HTMLElement && !isInlineAfter(designItem.element) || (designItem.element instanceof SVGElement)) {
|
|
@@ -99,8 +101,10 @@ export class HtmlWriterService extends AbstractHtmlWriterService {
|
|
|
99
101
|
designItem.instanceServiceContainer.designItemDocumentPositionService.setPosition(designItem, { start: start, length: end - start });
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
|
-
writeTextNode(indentedTextWriter, designItem, indentAndNewline) {
|
|
103
|
-
let content = DomConverter.normalizeContentValue(designItem.content)
|
|
104
|
+
writeTextNode(indentedTextWriter, designItem, indentAndNewline, trim = true) {
|
|
105
|
+
let content = DomConverter.normalizeContentValue(designItem.content);
|
|
106
|
+
if (trim)
|
|
107
|
+
content = content.trim();
|
|
104
108
|
if (content) {
|
|
105
109
|
if (indentAndNewline)
|
|
106
110
|
this._conditionalyWriteIndent(indentedTextWriter, designItem);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CalculateGridInformation } from '../../helper/GridHelper.js';
|
|
1
|
+
import { CalculateGridInformation, GetElementGridInformation } from '../../helper/GridHelper.js';
|
|
2
2
|
import { pointInRect } from '../../helper/Helper.js';
|
|
3
3
|
import { DefaultPlacementService } from './DefaultPlacementService.js';
|
|
4
4
|
export class GridPlacementService {
|
|
@@ -51,30 +51,27 @@ export class GridPlacementService {
|
|
|
51
51
|
place(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
52
52
|
const gridInformation = CalculateGridInformation(container);
|
|
53
53
|
const pos = placementView.getNormalizedEventCoordinates(event);
|
|
54
|
-
const posElement = placementView.getNormalizedElementCoordinates(items[0].element);
|
|
55
54
|
let row = 0;
|
|
56
55
|
let column = 0;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for (let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
items[0].element.style.gridRow = row + 1;
|
|
72
|
-
}
|
|
56
|
+
for (let cellRow of gridInformation.cells) {
|
|
57
|
+
column = 0;
|
|
58
|
+
for (let cell of cellRow) {
|
|
59
|
+
if (pointInRect(pos, cell)) {
|
|
60
|
+
let info = GetElementGridInformation(items[0].element);
|
|
61
|
+
if (cell.name) {
|
|
62
|
+
items[0].element.style.gridColumn = '';
|
|
63
|
+
items[0].element.style.gridRow = '';
|
|
64
|
+
items[0].element.style.gridArea = cell.name;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
items[0].element.style.gridArea = '';
|
|
68
|
+
items[0].element.style.gridColumn = (column + 1) + (info.colSpan > 1 ? ' / span ' + info.colSpan : '');
|
|
69
|
+
items[0].element.style.gridRow = (row + 1) + (info.rowSpan > 1 ? ' / span ' + info.rowSpan : '');
|
|
73
70
|
}
|
|
74
|
-
column++;
|
|
75
71
|
}
|
|
76
|
-
|
|
72
|
+
column++;
|
|
77
73
|
}
|
|
74
|
+
row++;
|
|
78
75
|
}
|
|
79
76
|
placementView.extensionManager.refreshAllExtensions([container]);
|
|
80
77
|
}
|
|
@@ -88,6 +85,7 @@ export class GridPlacementService {
|
|
|
88
85
|
column = 0;
|
|
89
86
|
for (let cell of cellRow) {
|
|
90
87
|
if (pointInRect(pos, cell)) {
|
|
88
|
+
let info = GetElementGridInformation(items[0].element);
|
|
91
89
|
//Grid Area is shorthand for grid row/column, to make undo work correctly we need to set befor and after clear
|
|
92
90
|
if (cell.name) {
|
|
93
91
|
items[0].setStyle('grid-area', cell.name);
|
|
@@ -96,11 +94,11 @@ export class GridPlacementService {
|
|
|
96
94
|
items[0].setStyle('grid-area', cell.name);
|
|
97
95
|
}
|
|
98
96
|
else {
|
|
99
|
-
items[0].setStyle('grid-column', column + 1);
|
|
100
|
-
items[0].setStyle('grid-row', row + 1);
|
|
97
|
+
items[0].setStyle('grid-column', (column + 1) + (info.colSpan > 1 ? ' / span ' + info.colSpan : ''));
|
|
98
|
+
items[0].setStyle('grid-row', (row + 1) + (info.rowSpan > 1 ? ' / span ' + info.rowSpan : ''));
|
|
101
99
|
items[0].removeStyle('grid-area');
|
|
102
|
-
items[0].setStyle('grid-column', column + 1);
|
|
103
|
-
items[0].setStyle('grid-row', row + 1);
|
|
100
|
+
items[0].setStyle('grid-column', (column + 1) + (info.colSpan > 1 ? ' / span ' + info.colSpan : ''));
|
|
101
|
+
items[0].setStyle('grid-row', (row + 1) + (info.rowSpan > 1 ? ' / span ' + info.rowSpan : ''));
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
column++;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { IPropertiesService, RefreshMode } from '../IPropertiesService.js';
|
|
2
3
|
import { IProperty } from '../IProperty.js';
|
|
3
4
|
import { IDesignItem } from '../../../item/IDesignItem.js';
|
|
@@ -6,6 +7,8 @@ import { BindingTarget } from '../../../item/BindingTarget.js';
|
|
|
6
7
|
import { IBinding } from '../../../item/IBinding.js';
|
|
7
8
|
import { IPropertyGroup } from '../IPropertyGroup.js';
|
|
8
9
|
export declare abstract class AbstractPropertiesService implements IPropertiesService {
|
|
10
|
+
_stylesCache: Map<IDesignItem, Set<string>>;
|
|
11
|
+
_cacheClearTimer: NodeJS.Timeout;
|
|
9
12
|
abstract getRefreshMode(designItem: IDesignItem): RefreshMode;
|
|
10
13
|
abstract isHandledElement(designItem: IDesignItem): boolean;
|
|
11
14
|
protected _notifyChangedProperty(designItem: IDesignItem, property: IProperty, value: any): void;
|
|
@@ -4,6 +4,8 @@ import { BindingTarget } from '../../../item/BindingTarget.js';
|
|
|
4
4
|
import { PropertyType } from '../PropertyType.js';
|
|
5
5
|
import { NodeType } from '../../../item/NodeType.js';
|
|
6
6
|
export class AbstractPropertiesService {
|
|
7
|
+
_stylesCache = new Map;
|
|
8
|
+
_cacheClearTimer;
|
|
7
9
|
_notifyChangedProperty(designItem, property, value) {
|
|
8
10
|
}
|
|
9
11
|
getProperty(designItem, name) {
|
|
@@ -90,7 +92,7 @@ export class AbstractPropertiesService {
|
|
|
90
92
|
let attributeName = property.attributeName;
|
|
91
93
|
if (!attributeName)
|
|
92
94
|
attributeName = PropertiesHelper.camelToDashCase(property.name);
|
|
93
|
-
|
|
95
|
+
for (let x of designItems) {
|
|
94
96
|
let has = false;
|
|
95
97
|
if (property.propertyType == PropertyType.cssValue)
|
|
96
98
|
has = x.hasStyle(property.name);
|
|
@@ -98,7 +100,10 @@ export class AbstractPropertiesService {
|
|
|
98
100
|
has = x.hasAttribute(attributeName);
|
|
99
101
|
all = all && has;
|
|
100
102
|
some = some || has;
|
|
101
|
-
|
|
103
|
+
if (!all && some)
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
;
|
|
102
107
|
//todo: optimize perf, do not call bindings service for each property.
|
|
103
108
|
const bindings = designItems[0].serviceContainer.forSomeServicesTillResult('bindingService', (s) => {
|
|
104
109
|
return s.getBindings(designItems[0]);
|
|
@@ -111,6 +116,18 @@ export class AbstractPropertiesService {
|
|
|
111
116
|
if (bindings && bindings.find(x => x.target == BindingTarget.property && x.targetName == property.name))
|
|
112
117
|
return ValueType.bound;
|
|
113
118
|
}
|
|
119
|
+
if (!all && property.propertyType == PropertyType.cssValue) {
|
|
120
|
+
let styles = this._stylesCache.get(designItems[0]);
|
|
121
|
+
if (!styles) {
|
|
122
|
+
styles = new Set(designItems[0].getAllStyles().filter(x => x.selector != null).flatMap(x => x.declarations).map(x => x.name));
|
|
123
|
+
this._stylesCache.set(designItems[0], styles);
|
|
124
|
+
clearTimeout(this._cacheClearTimer);
|
|
125
|
+
this._cacheClearTimer = setTimeout(() => this._stylesCache.clear(), 30);
|
|
126
|
+
}
|
|
127
|
+
let cssValue = styles.has(property.name);
|
|
128
|
+
if (cssValue)
|
|
129
|
+
return ValueType.fromStylesheet;
|
|
130
|
+
}
|
|
114
131
|
}
|
|
115
132
|
else
|
|
116
133
|
return ValueType.none;
|
|
@@ -162,7 +179,6 @@ export class AbstractPropertiesService {
|
|
|
162
179
|
return bindings.find(x => (x.target == BindingTarget.property || x.target == BindingTarget.attribute) && x.targetName == property.name);
|
|
163
180
|
}
|
|
164
181
|
}
|
|
165
|
-
//todo: optimize perf, call window.getComputedStyle only once per item, and not per property
|
|
166
182
|
getUnsetValue(designItems, property) {
|
|
167
183
|
if (property.propertyType == PropertyType.cssValue) {
|
|
168
184
|
if (designItems != null && designItems.length !== 0) {
|
|
@@ -306,6 +306,10 @@ export class PropertyGridPropertyList extends BaseCustomWebComponentLazyAppend {
|
|
|
306
306
|
isSetElement.style.background = 'gray';
|
|
307
307
|
else if (s == ValueType.bound)
|
|
308
308
|
isSetElement.style.background = 'orange';
|
|
309
|
+
else if (s == ValueType.fromStylesheet) {
|
|
310
|
+
v = propertiesService.getUnsetValue(items, property);
|
|
311
|
+
isSetElement.style.background = 'yellow';
|
|
312
|
+
}
|
|
309
313
|
editor?.refreshValueWithoutNotification(s, v);
|
|
310
314
|
}
|
|
311
315
|
else {
|
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.
|
|
4
|
+
"version": "0.0.273",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "",
|
|
@@ -13,30 +13,30 @@
|
|
|
13
13
|
"prepublishOnly": "npm run build"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@node-projects/base-custom-webcomponent": "^0.
|
|
16
|
+
"@node-projects/base-custom-webcomponent": "^0.15.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@adobe/css-tools": "4.3.
|
|
19
|
+
"@adobe/css-tools": "4.3.1",
|
|
20
20
|
"@node-projects/lean-he-esm": "^3.3.0",
|
|
21
21
|
"@node-projects/node-html-parser-esm": "^6.1.5",
|
|
22
22
|
"@papyrs/stylo": "^0.0.45",
|
|
23
|
-
"@types/codemirror": "^5.60.
|
|
23
|
+
"@types/codemirror": "^5.60.9",
|
|
24
24
|
"@types/css-tree": "^2.3.1",
|
|
25
|
-
"@types/jquery": "^3.5.
|
|
25
|
+
"@types/jquery": "^3.5.17",
|
|
26
26
|
"@types/jquery.fancytree": "0.0.7",
|
|
27
|
-
"@types/node": "^20.
|
|
28
|
-
"ace-builds": "^1.24.
|
|
27
|
+
"@types/node": "^20.5.6",
|
|
28
|
+
"ace-builds": "^1.24.1",
|
|
29
29
|
"codemirror": "^5.0.0",
|
|
30
30
|
"css-tree": "^2.3.1",
|
|
31
31
|
"esprima-next": "^5.8.4",
|
|
32
32
|
"html2canvas": "*",
|
|
33
|
-
"jest": "^29.6.
|
|
33
|
+
"jest": "^29.6.4",
|
|
34
34
|
"jquery": "^3.7.0",
|
|
35
35
|
"jquery.fancytree": "^2.38.3",
|
|
36
|
-
"mdn-data": "^2.0.
|
|
36
|
+
"mdn-data": "^2.0.33",
|
|
37
37
|
"monaco-editor": "^0.41.0",
|
|
38
38
|
"ts-jest": "^29.1.1",
|
|
39
|
-
"typescript": "^5.
|
|
39
|
+
"typescript": "^5.2.2",
|
|
40
40
|
"typescript-lit-html-plugin": "^0.9.0"
|
|
41
41
|
},
|
|
42
42
|
"repository": {
|