@node-projects/web-component-designer 0.1.151 → 0.1.153

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/README.md CHANGED
@@ -56,6 +56,15 @@ Your index.html should be extended as follows:
56
56
  <link rel="stylesheet" href="/node_modules/mobile-drag-drop/default.css">
57
57
  <script src="/node_modules/mobile-drag-drop/index.js"></script>
58
58
 
59
+ ## Similar Frameworks
60
+
61
+ | Name | Licence | Edit Source | | |
62
+ |-------------------------|----------|-------------|---|---|
63
+ | web-component-designer | MIT | yes | | |
64
+ | GrapeJS | BSD-3 | yes | | |
65
+ | CraftJS | MIT | no | | |
66
+
67
+
59
68
  ## Copyright notice
60
69
 
61
70
  The Library uses Images from the Chrome Dev Tools, see
@@ -18,7 +18,7 @@ export interface IPropertiesService extends IService {
18
18
  getProperty(designItem: IDesignItem, name: string): IProperty;
19
19
  getBinding(designItems: IDesignItem[], property: IProperty): IBinding;
20
20
  getPropertyTarget(designItem: IDesignItem, property: IProperty): BindingTarget;
21
- setValue(designItems: IDesignItem[], property: IProperty, value: any): any;
21
+ setValue(designItems: IDesignItem[], property: IProperty, value: any): Promise<void>;
22
22
  clearValue(designItems: IDesignItem[], property: IProperty, clearType: 'all' | 'binding' | 'value'): any;
23
23
  isSet(designItems: IDesignItem[], property: IProperty): ValueType;
24
24
  getValue(designItems: IDesignItem[], property: IProperty): any;
@@ -20,10 +20,18 @@ export declare class PropertyGroupsService implements IPropertyGroupsService {
20
20
  name: string;
21
21
  propertiesService: IPropertiesService;
22
22
  }[];
23
+ protected _grid: {
24
+ name: string;
25
+ propertiesService: IPropertiesService;
26
+ }[];
23
27
  protected _flexChild: {
24
28
  name: string;
25
29
  propertiesService: IPropertiesService;
26
30
  }[];
31
+ protected _flex: {
32
+ name: string;
33
+ propertiesService: IPropertiesService;
34
+ }[];
27
35
  getPropertygroups(designItems: IDesignItem[]): {
28
36
  name: string;
29
37
  propertiesService: IPropertiesService;
@@ -11,8 +11,6 @@ export class PropertyGroupsService {
11
11
  { name: 'styles', propertiesService: new CssCurrentPropertiesService() },
12
12
  { name: 'css vars', propertiesService: new CssCustomPropertiesService() },
13
13
  { name: 'layout', propertiesService: new CssPropertiesService("layout") },
14
- { name: 'flex', propertiesService: new CssPropertiesService("flex") },
15
- { name: 'grid', propertiesService: new CssPropertiesService("grid") },
16
14
  ];
17
15
  _pgList = [
18
16
  { name: 'properties', propertiesService: null },
@@ -22,8 +20,6 @@ export class PropertyGroupsService {
22
20
  { name: 'styles', propertiesService: new CssCurrentPropertiesService() },
23
21
  { name: 'css vars', propertiesService: new CssCustomPropertiesService() },
24
22
  { name: 'layout', propertiesService: new CssPropertiesService("layout") },
25
- { name: 'flex', propertiesService: new CssPropertiesService("flex") },
26
- { name: 'grid', propertiesService: new CssPropertiesService("grid") },
27
23
  ];
28
24
  _svgPgList = [
29
25
  { name: 'properties', propertiesService: null },
@@ -38,28 +34,46 @@ export class PropertyGroupsService {
38
34
  _gridChild = [
39
35
  { name: 'gridChild', propertiesService: new CssPropertiesService("gridChild") },
40
36
  ];
37
+ _grid = [
38
+ { name: 'grid', propertiesService: new CssPropertiesService("grid") },
39
+ ];
41
40
  _flexChild = [
42
41
  { name: 'flexChild', propertiesService: new CssPropertiesService("flexChild") },
43
42
  ];
43
+ _flex = [
44
+ { name: 'flex', propertiesService: new CssPropertiesService("flex") },
45
+ ];
44
46
  getPropertygroups(designItems) {
45
47
  if (designItems == null || designItems.length == 0)
46
48
  return [];
47
49
  if (designItems[0].nodeType == NodeType.TextNode || designItems[0].nodeType == NodeType.Comment)
48
50
  return [];
49
- if (designItems[0].isRootItem)
50
- return this._rootPgList;
51
+ if (designItems[0].isRootItem) {
52
+ const style = designItems[0].getComputedStyle();
53
+ let lst = this._rootPgList;
54
+ if (style.display.includes('grid'))
55
+ lst = [...lst, ...this._grid];
56
+ else if (style.display.includes('flex'))
57
+ lst = [...lst, ...this._flex];
58
+ return lst;
59
+ }
51
60
  this._pgList[0].propertiesService = designItems[0].serviceContainer.getLastServiceWhere('propertyService', x => x.isHandledElement(designItems[0]));
52
61
  this._svgPgList[0].propertiesService = designItems[0].serviceContainer.getLastServiceWhere('propertyService', x => x.isHandledElement(designItems[0]));
53
62
  let lst = this._pgList;
54
63
  if (designItems[0].element instanceof SVGElement)
55
64
  lst = this._svgPgList;
65
+ const style = designItems[0].getComputedStyle();
66
+ if (style.display.includes('grid'))
67
+ lst = [...lst, ...this._grid];
68
+ else if (style.display.includes('flex'))
69
+ lst = [...lst, ...this._flex];
56
70
  if (designItems[0].parent) {
57
71
  const parentStyle = designItems[0].parent.getComputedStyle();
58
72
  if (parentStyle.display.includes('grid'))
59
- lst = [...lst, this._gridChild[0]];
73
+ lst = [...lst, ...this._gridChild];
60
74
  else if (parentStyle.display.includes('flex'))
61
- lst = [...lst, this._flexChild[0]];
75
+ lst = [...lst, ...this._flexChild];
62
76
  }
63
- return lst; //.filter(x => x.propertiesService.isHandledElement(designItems[0]));
77
+ return lst;
64
78
  }
65
79
  }
@@ -8,7 +8,7 @@ export declare abstract class BasePropertyEditor<T extends HTMLElement> implemen
8
8
  designItems: IDesignItem[];
9
9
  protected disableChangeNotification: boolean;
10
10
  constructor(property: IProperty);
11
- protected _valueChanged(newValue: any): void;
11
+ protected _valueChanged(newValue: any): Promise<void>;
12
12
  designItemsChanged(designItems: IDesignItem[]): void;
13
13
  abstract refreshValue(valueType: ValueType, value: any): any;
14
14
  refreshValueWithoutNotification(valueType: ValueType, value: any): void;
@@ -7,7 +7,7 @@ export class BasePropertyEditor {
7
7
  constructor(property) {
8
8
  this.property = property;
9
9
  }
10
- _valueChanged(newValue) {
10
+ async _valueChanged(newValue) {
11
11
  if (!this.disableChangeNotification) {
12
12
  if (this.designItems && this.designItems.length) {
13
13
  const cg = this.designItems[0].openGroup("set property: " + this.property.name);
@@ -15,7 +15,7 @@ export class BasePropertyEditor {
15
15
  if (newValue == null)
16
16
  this.property.service.clearValue([d], this.property, 'value');
17
17
  else
18
- this.property.service.setValue([d], this.property, newValue);
18
+ await this.property.service.setValue([d], this.property, newValue);
19
19
  }
20
20
  cg.commit();
21
21
  }
@@ -18,7 +18,7 @@ export declare abstract class AbstractPropertiesService implements IPropertiesSe
18
18
  protected _notifyChangedProperty(designItem: IDesignItem, property: IProperty, value: any): void;
19
19
  getProperty(designItem: IDesignItem, name: string): IProperty;
20
20
  abstract getProperties(designItem: IDesignItem): IProperty[] | IPropertyGroup[];
21
- setValue(designItems: IDesignItem[], property: IProperty, value: any): void;
21
+ setValue(designItems: IDesignItem[], property: IProperty, value: any): Promise<void>;
22
22
  getPropertyTarget(designItem: IDesignItem, property: IProperty): BindingTarget;
23
23
  clearValue(designItems: IDesignItem[], property: IProperty, clearType: 'all' | 'binding' | 'value'): void;
24
24
  isSet(designItems: IDesignItem[], property: IProperty): ValueType;
@@ -23,7 +23,7 @@ export class AbstractPropertiesService {
23
23
  else
24
24
  return properties.find(x => x.name == name);
25
25
  }
26
- setValue(designItems, property, value) {
26
+ async setValue(designItems, property, value) {
27
27
  const cg = designItems[0].openGroup("property changed: " + property.name + " to " + value);
28
28
  for (let d of designItems) {
29
29
  if (!this.isHandledElement(d))
@@ -31,9 +31,10 @@ export class AbstractPropertiesService {
31
31
  if (!this.getProperty(d, property.name))
32
32
  continue;
33
33
  if (property.propertyType == PropertyType.cssValue) {
34
- d.updateStyleInSheetOrLocal(property.name, value);
34
+ //TODO: use async version here, but then everything needs to be async
35
+ await d.updateStyleInSheetOrLocalAsync(property.name, value);
35
36
  //unkown css property names do not trigger the mutation observer of property grid,
36
- //fixed by assinging stle again to the attribute
37
+ //fixed by assinging style again to the attribute
37
38
  d.element.setAttribute('style', d.element.getAttribute('style'));
38
39
  }
39
40
  else {
@@ -282,11 +283,11 @@ export class AbstractPropertiesService {
282
283
  {
283
284
  title: 'edit as text', action: (e, _1, _2, menu) => {
284
285
  menu.close();
285
- setTimeout(() => {
286
+ setTimeout(async () => {
286
287
  const oldValue = property.service.getValue(designItems, property);
287
288
  let value = prompt(`edit value of '${property.name}' as string:`, oldValue);
288
289
  if (value && value != oldValue) {
289
- property.service.setValue(designItems, property, value);
290
+ await property.service.setValue(designItems, property, value);
290
291
  }
291
292
  designItems[0].instanceServiceContainer.designerCanvas.extensionManager.refreshAllExtensions(designItems);
292
293
  }, 10);
@@ -12,7 +12,7 @@ export declare class AttributesPropertiesService extends AbstractPropertiesServi
12
12
  isHandledElement(designItem: IDesignItem): boolean;
13
13
  getProperty(designItem: IDesignItem, name: string): IProperty;
14
14
  getProperties(designItem: IDesignItem): IProperty[] | IPropertyGroup[];
15
- setValue(designItems: IDesignItem[], property: IProperty, value: any): void;
15
+ setValue(designItems: IDesignItem[], property: IProperty, value: any): Promise<void>;
16
16
  getPropertyTarget(designItem: IDesignItem, property: IProperty): BindingTarget;
17
17
  clearValue(designItems: IDesignItem[], property: IProperty): void;
18
18
  isSet(designItems: IDesignItem[], property: IProperty): ValueType;
@@ -26,7 +26,7 @@ export class AttributesPropertiesService extends AbstractPropertiesService {
26
26
  }
27
27
  return null;
28
28
  }
29
- setValue(designItems, property, value) {
29
+ async setValue(designItems, property, value) {
30
30
  const cg = designItems[0].openGroup("properties changed");
31
31
  for (let d of designItems) {
32
32
  d.setAttribute(property.name, value);
@@ -8,11 +8,6 @@ export class CommonPropertiesService extends AbstractPropertiesService {
8
8
  //@ts-ignore
9
9
  commonProperties = [
10
10
  {
11
- name: "id",
12
- type: "string",
13
- service: this,
14
- propertyType: PropertyType.propertyAndAttribute
15
- }, {
16
11
  name: "class",
17
12
  type: "string",
18
13
  service: this,
@@ -15,7 +15,7 @@ export declare class CssCurrentPropertiesService extends AbstractCssPropertiesSe
15
15
  setValue(designItems: IDesignItem[], property: (IProperty & {
16
16
  styleRule: IStyleRule;
17
17
  styleDeclaration: IStyleDeclaration;
18
- }), value: any): void;
18
+ }), value: any): Promise<void>;
19
19
  clearValue(designItems: IDesignItem[], property: IProperty & {
20
20
  styleRule: IStyleRule;
21
21
  styleDeclaration: IStyleDeclaration;
@@ -41,7 +41,7 @@ export class CssCurrentPropertiesService extends AbstractCssPropertiesService {
41
41
  }));
42
42
  return arr;
43
43
  }
44
- setValue(designItems, property, value) {
44
+ async setValue(designItems, property, value) {
45
45
  // No selector means local style, styleDeclaration is null means new property
46
46
  if (property.styleRule?.selector !== null && property.styleDeclaration) {
47
47
  // styleDeclaration stored Propertygrid is not refreshed after entering a new value, so we need to reload
@@ -322,7 +322,6 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
322
322
  async parseHTML(html, disableUndo = false) {
323
323
  const parserService = this.serviceContainer.htmlParserService;
324
324
  if (!html) {
325
- this.instanceServiceContainer.undoService.clear();
326
325
  this._designerCanvas.overlayLayer.removeAllOverlays();
327
326
  DomHelper.removeAllChildnodes(this._designerCanvas.overlayLayer);
328
327
  this._designerCanvas.rootDesignItem.clearChildren();
@@ -88,6 +88,15 @@ export class PropertyGrid extends BaseCustomWebComponentLazyAppend {
88
88
  if (lst.createElements(items[0]))
89
89
  visibleDict.add(p.name);
90
90
  }
91
+ let parentEl = this._designerTabControl;
92
+ for (const v of visibleDict) {
93
+ let el = this._propertyGridPropertyListsDict[v];
94
+ if (parentEl === this._designerTabControl)
95
+ parentEl.insertAdjacentElement('afterbegin', el);
96
+ else
97
+ parentEl.insertAdjacentElement('afterend', el);
98
+ parentEl = el;
99
+ }
91
100
  for (let p of this._propertyGridPropertyLists) {
92
101
  if (visibleDict.has(p.title))
93
102
  p.style.display = 'block';
@@ -238,12 +238,12 @@ export class PropertyGridPropertyList extends BaseCustomWebComponentLazyAppend {
238
238
  let label = document.createElement("input");
239
239
  let input = editor.element;
240
240
  label.value = p.name;
241
- label.onkeyup = e => {
241
+ label.onkeyup = async (e) => {
242
242
  if (e.key == 'Enter' && label.value) {
243
243
  const pg = this._designItems[0].openGroup("rename property name from '" + p.name + "' to '" + label.value + "'");
244
244
  p.service.clearValue(this._designItems, p, 'all');
245
245
  p.name = label.value;
246
- p.service.setValue(this._designItems, p, input.value);
246
+ await p.service.setValue(this._designItems, p, input.value);
247
247
  pg.commit();
248
248
  this._designItems[0].instanceServiceContainer.designerCanvas.extensionManager.refreshAllExtensions(this._designItems);
249
249
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "A WYSIWYG designer webcomponent for html components",
3
3
  "name": "@node-projects/web-component-designer",
4
- "version": "0.1.151",
4
+ "version": "0.1.153",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",