@node-projects/web-component-designer 0.1.28 → 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 interface IRefactoring {
6
6
  name: string;
7
7
  itemType: string;
8
8
  designItem: IDesignItem;
9
- type: 'binding' | 'script';
9
+ type: 'binding' | 'script' | 'content' | 'attribute';
10
10
  display?: string;
11
11
  sourceObject: any;
12
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
+ }
@@ -5,7 +5,7 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
5
5
  <template repeat:item="[[this.refactorings]]">
6
6
  <details open>
7
7
  <summary>
8
- name:<input value="[[item[0]]]" @keydown="[[this._refactor(item, event)]]" style="flex-grow: 1; min-width: 0">
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]]]">
@@ -91,11 +91,12 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
91
91
  refactorings.push(...rfs);
92
92
  }
93
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
94
95
  for (const r of refactorings) {
95
- let thisList = this.refactorings.get(r.name);
96
+ let thisList = this.refactorings.get(r.itemType + '|' + r.name);
96
97
  if (thisList === undefined) {
97
98
  thisList = [];
98
- this.refactorings.set(r.name, thisList);
99
+ this.refactorings.set(r.itemType + '|' + r.name, thisList);
99
100
  }
100
101
  thisList.push(r);
101
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.28",
4
+ "version": "0.1.29",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",