@node-projects/web-component-designer 0.1.27 → 0.1.29

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.
@@ -0,0 +1,6 @@
1
+ import { IDesignItem } from "../../item/IDesignItem.js";
2
+ import { IRefactoring } from "./IRefactoring.js";
3
+ export declare class BindingsRefactorService {
4
+ getRefactorings(designItems: IDesignItem[]): IRefactoring[];
5
+ refactor(refactoring: IRefactoring, oldValue: string, newValue: string): void;
6
+ }
@@ -0,0 +1,21 @@
1
+ export class BindingsRefactorService {
2
+ getRefactorings(designItems) {
3
+ let refactorings = [];
4
+ for (let d of designItems) {
5
+ let bindings = d.serviceContainer.bindingService.getBindings(d);
6
+ if (bindings) {
7
+ for (let b of bindings) {
8
+ for (let s of b.bindableObjectNames) {
9
+ refactorings.push({ service: this, name: s, itemType: 'bindableObject', designItem: d, type: 'binding', sourceObject: b, display: b.target + '/' + b.targetName });
10
+ }
11
+ }
12
+ }
13
+ }
14
+ return refactorings;
15
+ }
16
+ refactor(refactoring, oldValue, newValue) {
17
+ let binding = refactoring.sourceObject;
18
+ binding.bindableObjectNames = binding.bindableObjectNames.map(x => x == oldValue ? newValue : x);
19
+ refactoring.designItem.serviceContainer.bindingService.setBinding(refactoring.designItem, binding);
20
+ }
21
+ }
@@ -6,7 +6,7 @@ export class BindingsRefactorService {
6
6
  if (bindings) {
7
7
  for (let b of bindings) {
8
8
  for (let s of b.bindableObjectNames) {
9
- refactorings.push({ service: this, name: s, designItem: d, type: 'binding', sourceObject: b, display: b.target + '(' + b.targetName + ')' });
9
+ refactorings.push({ service: this, name: s, itemType: 'bindableObject', designItem: d, type: 'binding', sourceObject: b, display: b.target + '/' + b.targetName });
10
10
  }
11
11
  }
12
12
  }
@@ -4,8 +4,9 @@ import { IRefactorService } from "./IRefactorService.js";
4
4
  export interface IRefactoring {
5
5
  service: IRefactorService;
6
6
  name: string;
7
+ itemType: string;
7
8
  designItem: IDesignItem;
8
- type: 'binding' | 'script';
9
+ type: 'binding' | 'script' | 'content' | 'attribute';
9
10
  display?: string;
10
11
  sourceObject: any;
11
12
  target?: BindingTarget;
@@ -0,0 +1,6 @@
1
+ import { IDesignItem } from "../../item/IDesignItem.js";
2
+ import { IRefactoring } from "./IRefactoring.js";
3
+ export declare class TextRefactorService {
4
+ getRefactorings(designItems: IDesignItem[]): IRefactoring[];
5
+ refactor(refactoring: IRefactoring, oldValue: string, newValue: string): void;
6
+ }
@@ -0,0 +1,29 @@
1
+ export class TextRefactorService {
2
+ getRefactorings(designItems) {
3
+ let refactorings = [];
4
+ for (let d of designItems) {
5
+ if (d.element instanceof HTMLInputElement || d.element instanceof HTMLTextAreaElement) {
6
+ if (d.element.value)
7
+ refactorings.push({ service: this, name: d.element.value, itemType: 'text', designItem: d, type: 'attribute', sourceObject: d, display: 'attribute' + '/' + 'value' });
8
+ }
9
+ if (d.childCount > 0 && d.element.textContent) {
10
+ let onlyTextNodes = true;
11
+ for (const n of d.element.childNodes)
12
+ if (n.nodeType != 3) {
13
+ onlyTextNodes = false;
14
+ }
15
+ if (onlyTextNodes)
16
+ refactorings.push({ service: this, name: d.element.textContent, itemType: 'text', designItem: d, type: 'content', sourceObject: d, display: 'textContent' });
17
+ }
18
+ }
19
+ return refactorings;
20
+ }
21
+ refactor(refactoring, oldValue, newValue) {
22
+ if (refactoring.type == 'attribute') {
23
+ refactoring.designItem.setAttribute('value', newValue);
24
+ }
25
+ else if (refactoring.type == 'content') {
26
+ refactoring.designItem.content = newValue;
27
+ }
28
+ }
29
+ }
@@ -3,13 +3,13 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
3
3
  static template = html `
4
4
  <div id="root">
5
5
  <template repeat:item="[[this.refactorings]]">
6
- <details>
7
- <summary style="display: flex;">
8
- name:<input value="[[item[0]]]" @keydown="[[this._refactor(item, event)]]" style="flex-grow: 1; min-width: 0">
6
+ <details open>
7
+ <summary>
8
+ name:<input value="[[item[1][0].name]]" @keydown="[[this._refactor(item, event)]]" style="flex-grow: 1; min-width: 0">
9
9
  </summary>
10
10
  <ul>
11
11
  <template repeat:reft="[[item[1]]]">
12
- <li>[[reft.type]] - [[reft.display]]</li>
12
+ <li>[[reft.type]]/[[reft.display]]</li>
13
13
  </template>
14
14
  </ul>
15
15
  </details>
@@ -24,10 +24,17 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
24
24
  position: absolute;
25
25
  overflow: hidden;
26
26
  }
27
+
28
+ summary {
29
+ cursor: pointer;
30
+ font-size: 10px;
31
+ display: flex;
32
+ align-items: center;
33
+ }
27
34
 
28
35
  ul {
29
36
  margin: 4px;
30
- padding-left: 30px;
37
+ padding-left: 20px;
31
38
  font-size: 10px;
32
39
  }
33
40
 
@@ -84,11 +91,12 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
84
91
  refactorings.push(...rfs);
85
92
  }
86
93
  //Group refactorings by name
94
+ //TODO: group also by itemType, cause different item types (for example screen and signal name) could have the same string
87
95
  for (const r of refactorings) {
88
- let thisList = this.refactorings.get(r.name);
96
+ let thisList = this.refactorings.get(r.itemType + '|' + r.name);
89
97
  if (thisList === undefined) {
90
98
  thisList = [];
91
- this.refactorings.set(r.name, thisList);
99
+ this.refactorings.set(r.itemType + '|' + r.name, thisList);
92
100
  }
93
101
  thisList.push(r);
94
102
  }
package/dist/index.d.ts CHANGED
@@ -121,6 +121,7 @@ export * from "./elements/services/propertiesService/services/UnkownElementsProp
121
121
  export * from "./elements/services/propertiesService/PropertyType.js";
122
122
  export * from "./elements/services/propertiesService/ValueType.js";
123
123
  export * from "./elements/services/refactorService/BindingsRefactorService.js";
124
+ export * from "./elements/services/refactorService/TextRefactorService.js";
124
125
  export type { IRefactorService } from "./elements/services/refactorService/IRefactorService.js";
125
126
  export type { IRefactoring } from "./elements/services/refactorService/IRefactoring.js";
126
127
  export type { ISelectionChangedEvent } from "./elements/services/selectionService/ISelectionChangedEvent.js";
package/dist/index.js CHANGED
@@ -81,6 +81,7 @@ export * from "./elements/services/propertiesService/services/UnkownElementsProp
81
81
  export * from "./elements/services/propertiesService/PropertyType.js";
82
82
  export * from "./elements/services/propertiesService/ValueType.js";
83
83
  export * from "./elements/services/refactorService/BindingsRefactorService.js";
84
+ export * from "./elements/services/refactorService/TextRefactorService.js";
84
85
  export * from "./elements/services/selectionService/SelectionService.js";
85
86
  export * from "./elements/services/stylesheetService/AbstractStylesheetService.js";
86
87
  export * from "./elements/services/undoService/ChangeGroup.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.1.27",
4
+ "version": "0.1.29",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",