@node-projects/web-component-designer 0.0.286 → 0.0.288

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.
@@ -2,6 +2,7 @@ import { AttachedPropertiesService } from './services/AttachedPropertiesService.
2
2
  import { AttributesPropertiesService } from './services/AttributesPropertiesService.js';
3
3
  import { CommonPropertiesService } from './services/CommonPropertiesService.js';
4
4
  import { CssCurrentPropertiesService } from './services/CssCurrentPropertiesService.js';
5
+ import { CssCustomPropertiesService } from './services/CssCustomPropertiesService.js';
5
6
  import { CssPropertiesService } from './services/CssPropertiesService.js';
6
7
  export class PropertyTabsService {
7
8
  _attachedPropertiesService = new AttachedPropertiesService();
@@ -11,6 +12,7 @@ export class PropertyTabsService {
11
12
  { name: 'attributes', propertiesService: new AttributesPropertiesService() },
12
13
  { name: 'common', propertiesService: new CommonPropertiesService() },
13
14
  { name: 'styles', propertiesService: new CssCurrentPropertiesService() },
15
+ { name: 'css vars', propertiesService: new CssCustomPropertiesService() },
14
16
  { name: 'layout', propertiesService: new CssPropertiesService("layout") },
15
17
  { name: 'flex', propertiesService: new CssPropertiesService("flex") },
16
18
  { name: 'grid', propertiesService: new CssPropertiesService("grid") },
@@ -20,6 +22,7 @@ export class PropertyTabsService {
20
22
  { name: 'attached', propertiesService: this._attachedPropertiesService },
21
23
  { name: 'attributes', propertiesService: new AttributesPropertiesService() },
22
24
  { name: 'styles', propertiesService: new CssCurrentPropertiesService() },
25
+ { name: 'css vars', propertiesService: new CssCustomPropertiesService() },
23
26
  { name: 'layout', propertiesService: new CssPropertiesService("layout") },
24
27
  { name: 'svg', propertiesService: new CssPropertiesService("svg") },
25
28
  ];
@@ -0,0 +1,34 @@
1
+ import { IProperty } from '../IProperty.js';
2
+ import { IDesignItem } from '../../../item/IDesignItem.js';
3
+ import { RefreshMode } from '../IPropertiesService.js';
4
+ import { IPropertyGroup } from '../IPropertyGroup.js';
5
+ import { IStyleDeclaration, IStyleRule } from '../../stylesheetService/IStylesheetService.js';
6
+ import { CommonPropertiesService } from './CommonPropertiesService.js';
7
+ import { ValueType } from '../ValueType.js';
8
+ export declare class CssCurrentPropertiesService extends CommonPropertiesService {
9
+ getRefreshMode(designItem: IDesignItem): RefreshMode;
10
+ constructor();
11
+ isHandledElement(designItem: IDesignItem): boolean;
12
+ getProperty(designItem: IDesignItem, name: string): IProperty;
13
+ getProperties(designItem: IDesignItem): IProperty[] | IPropertyGroup[];
14
+ setValue(designItems: IDesignItem[], property: (IProperty & {
15
+ styleRule: IStyleRule;
16
+ styleDeclaration: IStyleDeclaration;
17
+ }), value: any): void;
18
+ clearValue(designItems: IDesignItem[], property: IProperty & {
19
+ styleRule: IStyleRule;
20
+ styleDeclaration: IStyleDeclaration;
21
+ }, clearType: 'all' | 'binding' | 'value'): void;
22
+ getValue(designItems: IDesignItem[], property: IProperty & {
23
+ styleRule: IStyleRule;
24
+ styleDeclaration: IStyleDeclaration;
25
+ }): string | boolean;
26
+ getUnsetValue(designItems: IDesignItem[], property: IProperty & {
27
+ styleRule: IStyleRule;
28
+ styleDeclaration: IStyleDeclaration;
29
+ }): any;
30
+ isSet(designItems: IDesignItem[], property: IProperty & {
31
+ styleRule: IStyleRule;
32
+ styleDeclaration: IStyleDeclaration;
33
+ }): ValueType;
34
+ }
@@ -0,0 +1,105 @@
1
+ import { PropertyType } from '../PropertyType.js';
2
+ import { RefreshMode } from '../IPropertiesService.js';
3
+ import { CommonPropertiesService } from './CommonPropertiesService.js';
4
+ import { ValueType } from '../ValueType.js';
5
+ import { NodeType } from '../../../item/NodeType.js';
6
+ //TODO: remove this code when import asserts are supported
7
+ let cssProperties;
8
+ //@ts-ignore
9
+ if (window.importShim) {
10
+ const cssPropertiesUrl = import.meta.resolve('./CssProperties.json');
11
+ //@ts-ignore
12
+ cssProperties = await importShim(cssPropertiesUrl, { assert: { type: 'json' } });
13
+ }
14
+ else
15
+ //@ts-ignore
16
+ cssProperties = await import("./CssProperties.json", { assert: { type: 'json' } });
17
+ if (cssProperties.default)
18
+ cssProperties = cssProperties.default;
19
+ const localName = '<local>';
20
+ export class CssCurrentPropertiesService extends CommonPropertiesService {
21
+ getRefreshMode(designItem) {
22
+ return RefreshMode.fullOnValueChange;
23
+ }
24
+ constructor() {
25
+ super();
26
+ this.name = 'styles';
27
+ }
28
+ isHandledElement(designItem) {
29
+ return true;
30
+ }
31
+ getProperty(designItem, name) {
32
+ return { name: name, type: 'string', service: this, propertyType: PropertyType.cssValue };
33
+ }
34
+ getProperties(designItem) {
35
+ if (!designItem || designItem.nodeType != NodeType.Element)
36
+ return [];
37
+ let styles = designItem.getAllStyles();
38
+ let arr = styles.map(x => ({
39
+ name: x.selector ?? localName, description: x.stylesheetName ?? '', properties: [
40
+ ...x.declarations.map(y => ({
41
+ name: y.name,
42
+ renamable: true,
43
+ type: cssProperties[y.name]?.type ?? 'string',
44
+ values: cssProperties[y.name]?.values ? [...cssProperties[y.name]?.values, 'initial', 'inherit', 'unset'] : ['initial', 'inherit', 'unset'],
45
+ service: this,
46
+ propertyType: PropertyType.cssValue,
47
+ styleRule: x,
48
+ styleDeclaration: y
49
+ })),
50
+ { name: '', type: 'addNew', service: this, propertyType: PropertyType.complex, styleRule: x }
51
+ ]
52
+ }));
53
+ return arr;
54
+ }
55
+ setValue(designItems, property, value) {
56
+ // No selector means local style, styleDeclaration is null means new property
57
+ if (property.styleRule?.selector !== null && property.styleDeclaration) {
58
+ // styleDeclaration stored Propertygrid is not refreshed after entering a new value, so we need to reload
59
+ // TODO: we do not respect if a same style is found in a media query or another @rule, maybe we need a refresh in the stylesheet parser
60
+ const decls = designItems[0].instanceServiceContainer.stylesheetService?.getDeclarations(designItems[0], property.styleDeclaration.name);
61
+ const currentDecl = decls.find(x => x.parent.selector == property.styleDeclaration.parent.selector && x.parent.stylesheetName == property.styleDeclaration.parent.stylesheetName);
62
+ designItems[0].instanceServiceContainer.stylesheetService.updateDeclarationValue(currentDecl, value, false);
63
+ this._notifyChangedProperty(designItems[0], property, value);
64
+ return;
65
+ }
66
+ if (property.styleRule?.selector !== null && !property.styleDeclaration) {
67
+ designItems[0].instanceServiceContainer.stylesheetService.insertDeclarationIntoRule(property.styleRule, property.name, value, false);
68
+ this._notifyChangedProperty(designItems[0], property, value);
69
+ return;
70
+ }
71
+ for (const d of designItems) {
72
+ // Local style
73
+ d.setStyle(property.name, value);
74
+ //unkown css property names do not trigger the mutation observer of property grid,
75
+ //fixed by assinging stle again to the attribute
76
+ d.element.setAttribute('style', d.element.getAttribute('style'));
77
+ }
78
+ }
79
+ clearValue(designItems, property, clearType) {
80
+ if (property.styleRule?.selector !== null && property.styleDeclaration) {
81
+ designItems[0].instanceServiceContainer.stylesheetService.removeDeclarationFromRule(property.styleRule, property.styleDeclaration.name);
82
+ return;
83
+ }
84
+ super.clearValue(designItems, property, clearType);
85
+ }
86
+ getValue(designItems, property) {
87
+ if (property.styleRule?.selector && property.styleDeclaration)
88
+ return property.styleDeclaration.value;
89
+ return super.getValue(designItems, property);
90
+ }
91
+ getUnsetValue(designItems, property) {
92
+ if (property.styleRule?.selector && property.styleDeclaration)
93
+ return property.styleDeclaration.value;
94
+ return super.getUnsetValue(designItems, property);
95
+ }
96
+ isSet(designItems, property) {
97
+ if (property.styleRule?.selector && property.styleDeclaration) {
98
+ if (designItems[0].hasStyle(property.name))
99
+ return ValueType.none;
100
+ //TODO: we need to check if this is the dec. with the highest specifity
101
+ return ValueType.all;
102
+ }
103
+ return super.isSet(designItems, property);
104
+ }
105
+ }
@@ -0,0 +1,17 @@
1
+ import { IProperty } from '../IProperty.js';
2
+ import { IDesignItem } from '../../../item/IDesignItem.js';
3
+ import { RefreshMode } from '../IPropertiesService.js';
4
+ import { IPropertyGroup } from '../IPropertyGroup.js';
5
+ import { CommonPropertiesService } from './CommonPropertiesService.js';
6
+ import { ValueType } from '../ValueType.js';
7
+ export declare class CssCustomPropertiesService extends CommonPropertiesService {
8
+ getRefreshMode(designItem: IDesignItem): RefreshMode;
9
+ constructor();
10
+ isHandledElement(designItem: IDesignItem): boolean;
11
+ getProperty(designItem: IDesignItem, name: string): IProperty;
12
+ getProperties(designItem: IDesignItem): IProperty[] | IPropertyGroup[];
13
+ clearValue(designItems: IDesignItem[], property: IProperty, clearType: 'all' | 'binding' | 'value'): void;
14
+ getValue(designItems: IDesignItem[], property: IProperty): string;
15
+ getUnsetValue(designItems: IDesignItem[], property: IProperty): any;
16
+ isSet(designItems: IDesignItem[], property: IProperty): ValueType;
17
+ }
@@ -0,0 +1,43 @@
1
+ import { PropertyType } from '../PropertyType.js';
2
+ import { RefreshMode } from '../IPropertiesService.js';
3
+ import { CommonPropertiesService } from './CommonPropertiesService.js';
4
+ import { ValueType } from '../ValueType.js';
5
+ export class CssCustomPropertiesService extends CommonPropertiesService {
6
+ getRefreshMode(designItem) {
7
+ return RefreshMode.fullOnValueChange;
8
+ }
9
+ constructor() {
10
+ super();
11
+ this.name = 'customProperties';
12
+ }
13
+ isHandledElement(designItem) {
14
+ return true;
15
+ }
16
+ getProperty(designItem, name) {
17
+ return { name: name, type: 'string', service: this, propertyType: PropertyType.cssValue };
18
+ }
19
+ getProperties(designItem) {
20
+ if (!designItem.element.computedStyleMap)
21
+ return null;
22
+ let rootMap = Array.from(designItem.instanceServiceContainer.designerCanvas.rootDesignItem.element.computedStyleMap()).map(x => x[0]).filter(key => key.startsWith("--"));
23
+ let props = Array.from(designItem.element.computedStyleMap()).map(x => x[0]).filter(key => key.startsWith("--"));
24
+ let arr = props.filter(x => !rootMap.includes(x)).map(x => ({
25
+ name: x,
26
+ service: this,
27
+ propertyType: PropertyType.cssValue
28
+ }));
29
+ return arr;
30
+ }
31
+ clearValue(designItems, property, clearType) {
32
+ super.clearValue(designItems, property, clearType);
33
+ }
34
+ getValue(designItems, property) {
35
+ return getComputedStyle(designItems[0].element).getPropertyValue(property.name);
36
+ }
37
+ getUnsetValue(designItems, property) {
38
+ return super.getUnsetValue(designItems, property);
39
+ }
40
+ isSet(designItems, property) {
41
+ return designItems[0].hasStyle(property.name) ? ValueType.all : ValueType.none;
42
+ }
43
+ }
@@ -13,21 +13,43 @@ export class CssStyleChangeAction {
13
13
  undo() {
14
14
  if (this.oldValue === '' || this.oldValue == null) {
15
15
  this.designItem._withoutUndoRemoveStyle(this.name);
16
- this.designItem.element.style[this.name] = '';
16
+ if (this.name.startsWith('--')) {
17
+ this.designItem.element.style.removeProperty(this.name);
18
+ }
19
+ else {
20
+ this.designItem.element.style[this.name] = '';
21
+ }
22
+ ;
17
23
  }
18
24
  else {
19
25
  this.designItem._withoutUndoSetStyle(this.name, this.oldValue);
20
- this.designItem.element.style[this.name] = this.oldValue;
26
+ if (this.name.startsWith('--')) {
27
+ this.designItem.element.style.setProperty(this.name, this.oldValue);
28
+ }
29
+ else {
30
+ this.designItem.element.style[this.name] = this.oldValue;
31
+ }
21
32
  }
22
33
  }
23
34
  do() {
24
35
  if (this.newValue === '' || this.newValue == null) {
25
36
  this.designItem._withoutUndoRemoveStyle(this.name);
26
- this.designItem.element.style[this.name] = '';
37
+ if (this.name.startsWith('--')) {
38
+ this.designItem.element.style.removeProperty(this.name);
39
+ }
40
+ else {
41
+ this.designItem.element.style[this.name] = '';
42
+ }
43
+ ;
27
44
  }
28
45
  else {
29
46
  this.designItem._withoutUndoSetStyle(this.name, this.newValue);
30
- this.designItem.element.style[this.name] = this.newValue;
47
+ if (this.name.startsWith('--')) {
48
+ this.designItem.element.style.setProperty(this.name, this.newValue);
49
+ }
50
+ else {
51
+ this.designItem.element.style[this.name] = this.newValue;
52
+ }
31
53
  }
32
54
  }
33
55
  designItem;
@@ -19,5 +19,6 @@ export declare class PropertyGrid extends BaseCustomWebComponentLazyAppend {
19
19
  set instanceServiceContainer(value: InstanceServiceContainer);
20
20
  get selectedItems(): IDesignItem[];
21
21
  set selectedItems(items: IDesignItem[]);
22
+ _mutationOccured(): void;
22
23
  private _observePrimarySelectionForChanges;
23
24
  }
@@ -35,15 +35,7 @@ export class PropertyGrid extends BaseCustomWebComponentLazyAppend {
35
35
  if (e.composedPath()[0].localName != 'input')
36
36
  e.preventDefault();
37
37
  });
38
- this._itemsObserver = new MutationObserver((m) => {
39
- for (const a of this._propertyGridPropertyLists) {
40
- if (a.propertiesService?.getRefreshMode(this._selectedItems[0]) == RefreshMode.fullOnValueChange) {
41
- a.createElements(this._selectedItems[0]);
42
- a.designItemsChanged(this._selectedItems);
43
- }
44
- a.refreshForDesignItems(this._selectedItems);
45
- }
46
- });
38
+ this._itemsObserver = new MutationObserver((m) => this._mutationOccured());
47
39
  }
48
40
  set serviceContainer(value) {
49
41
  this._serviceContainer = value;
@@ -111,11 +103,23 @@ export class PropertyGrid extends BaseCustomWebComponentLazyAppend {
111
103
  }
112
104
  }
113
105
  }
106
+ _mutationOccured() {
107
+ for (const a of this._propertyGridPropertyLists) {
108
+ if (a.propertiesService?.getRefreshMode(this._selectedItems[0]) == RefreshMode.fullOnValueChange) {
109
+ a.createElements(this._selectedItems[0]);
110
+ a.designItemsChanged(this._selectedItems);
111
+ }
112
+ a.refreshForDesignItems(this._selectedItems);
113
+ }
114
+ }
114
115
  _observePrimarySelectionForChanges() {
115
116
  this._nodeReplacedCb?.dispose();
116
117
  this._itemsObserver.disconnect();
117
118
  this._itemsObserver.observe(this._selectedItems[0].element, { attributes: true, childList: false, characterData: false });
118
- this._nodeReplacedCb = this._selectedItems[0].nodeReplaced.on(() => this._observePrimarySelectionForChanges());
119
+ this._nodeReplacedCb = this._selectedItems[0].nodeReplaced.on(() => {
120
+ this._observePrimarySelectionForChanges();
121
+ this._mutationOccured();
122
+ });
119
123
  }
120
124
  }
121
125
  customElements.define('node-projects-property-grid', PropertyGrid);
package/dist/index.d.ts CHANGED
@@ -118,6 +118,7 @@ export * from "./elements/services/propertiesService/services/PolymerPropertiesS
118
118
  export * from "./elements/services/propertiesService/services/AbstractPropertiesService.js";
119
119
  export * from "./elements/services/propertiesService/services/WebcomponentManifestPropertiesService.js";
120
120
  export * from "./elements/services/propertiesService/services/AttributesPropertiesService.js";
121
+ export * from "./elements/services/propertiesService/services/CssCustomPropertiesService.js";
121
122
  export * from "./elements/services/propertiesService/PropertyType.js";
122
123
  export * from "./elements/services/propertiesService/ValueType.js";
123
124
  export * from "./elements/services/propertiesService/PropertyTabsService.js";
package/dist/index.js CHANGED
@@ -78,6 +78,7 @@ export * from "./elements/services/propertiesService/services/PolymerPropertiesS
78
78
  export * from "./elements/services/propertiesService/services/AbstractPropertiesService.js";
79
79
  export * from "./elements/services/propertiesService/services/WebcomponentManifestPropertiesService.js";
80
80
  export * from "./elements/services/propertiesService/services/AttributesPropertiesService.js";
81
+ export * from "./elements/services/propertiesService/services/CssCustomPropertiesService.js";
81
82
  export * from "./elements/services/propertiesService/PropertyType.js";
82
83
  export * from "./elements/services/propertiesService/ValueType.js";
83
84
  export * from "./elements/services/propertiesService/PropertyTabsService.js";
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.286",
4
+ "version": "0.0.288",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",