@node-projects/web-component-designer 0.1.28 → 0.1.30

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.
@@ -661,7 +661,26 @@
661
661
  "system": {},
662
662
  "tabSize": {},
663
663
  "tableLayout": {},
664
- "textAlign": {},
664
+ "textAlign": {
665
+ "type": "list",
666
+ "values": [
667
+ "start",
668
+ "end",
669
+ "left",
670
+ "right",
671
+ "center",
672
+ "justify",
673
+ "justify-all",
674
+ "match-parent",
675
+ "\".\"",
676
+ "\".\" center",
677
+ "inherit",
678
+ "initial",
679
+ "revert",
680
+ "revert-layer",
681
+ "unset"
682
+ ]
683
+ },
665
684
  "textAlignLast": {},
666
685
  "textAnchor": {},
667
686
  "textCombineUpright": {},
@@ -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
+ }
@@ -10,11 +10,15 @@ export declare class RefactorView extends BaseCustomWebComponentConstructorAppen
10
10
  private _instanceServiceContainer;
11
11
  private _selectionChangedHandler;
12
12
  private _selectedItems;
13
+ searchText: string;
14
+ replaceText: string;
13
15
  refactorings: Map<string, IRefactoring[]>;
14
16
  ready(): void;
15
17
  set instanceServiceContainer(value: InstanceServiceContainer);
16
18
  get selectedItems(): IDesignItem[];
17
19
  set selectedItems(items: IDesignItem[]);
20
+ replace(): void;
18
21
  _refactor(refactoring: [string, IRefactoring[]], event: KeyboardEvent): void;
22
+ applyRefactoring(refactoring: [string, IRefactoring[]], newValue: string): void;
19
23
  updateRefactorlist(designItems: IDesignItem[]): void;
20
24
  }
@@ -2,10 +2,18 @@ import { BaseCustomWebComponentConstructorAppend, css, html } from '@node-projec
2
2
  export class RefactorView extends BaseCustomWebComponentConstructorAppend {
3
3
  static template = html `
4
4
  <div id="root">
5
+ <div class="search">
6
+ <span>search</span>
7
+ <input style="flex-grow: 1; min-width: 0" value="{{this.searchText}}">
8
+ <span>replace</span>
9
+ <input style="flex-grow: 1; min-width: 0"value="{{this.replaceText}}">
10
+ <button @click="[[this.replace()]]" style="grid-column: 2;">replace</button>
11
+ </div>
12
+ <hr>
5
13
  <template repeat:item="[[this.refactorings]]">
6
14
  <details open>
7
15
  <summary>
8
- name:<input value="[[item[0]]]" @keydown="[[this._refactor(item, event)]]" style="flex-grow: 1; min-width: 0">
16
+ name:<input value="[[item[1][0].name]]" @keydown="[[this._refactor(item, event)]]" style="flex-grow: 1; min-width: 0">
9
17
  </summary>
10
18
  <ul>
11
19
  <template repeat:reft="[[item[1]]]">
@@ -25,6 +33,16 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
25
33
  overflow: hidden;
26
34
  }
27
35
 
36
+ .search {
37
+ display: grid;
38
+ grid-template-columns: 40px 1fr;
39
+ align-items: center;
40
+ }
41
+
42
+ span {
43
+ font-size: 10px;
44
+ }
45
+
28
46
  summary {
29
47
  cursor: pointer;
30
48
  font-size: 10px;
@@ -51,6 +69,8 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
51
69
  _instanceServiceContainer;
52
70
  _selectionChangedHandler;
53
71
  _selectedItems;
72
+ searchText = "(.*)";
73
+ replaceText = "$1";
54
74
  refactorings = new Map();
55
75
  ;
56
76
  ready() {
@@ -73,13 +93,36 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
73
93
  this.updateRefactorlist(this._selectedItems);
74
94
  }
75
95
  }
96
+ replace() {
97
+ let grp = null;
98
+ for (let r of this.refactorings) {
99
+ let n = r[1][0].name;
100
+ const regex = new RegExp(this.searchText);
101
+ const found = n.match(regex);
102
+ if (found) {
103
+ if (!grp)
104
+ grp = r[1][0].designItem.openGroup('refactor with regex ' + this.searchText + " -> " + this.replaceText);
105
+ const newText = n.replace(regex, this.replaceText);
106
+ if (newText != n) {
107
+ this.applyRefactoring(r, newText);
108
+ }
109
+ }
110
+ }
111
+ if (!grp)
112
+ grp.commit();
113
+ }
76
114
  _refactor(refactoring, event) {
77
115
  const ip = event.target;
78
116
  if (event.key == 'Enter') {
79
- for (let r of refactoring[1]) {
80
- r.service.refactor(r, r.name, ip.value);
81
- }
117
+ this.applyRefactoring(refactoring, ip.value);
118
+ }
119
+ }
120
+ applyRefactoring(refactoring, newValue) {
121
+ const grp = refactoring[1][0].designItem.openGroup('refactor ' + refactoring[1][0].name + ' to ' + newValue);
122
+ for (let r of refactoring[1]) {
123
+ r.service.refactor(r, r.name, newValue);
82
124
  }
125
+ grp.commit();
83
126
  }
84
127
  updateRefactorlist(designItems) {
85
128
  this.refactorings.clear();
@@ -91,11 +134,12 @@ export class RefactorView extends BaseCustomWebComponentConstructorAppend {
91
134
  refactorings.push(...rfs);
92
135
  }
93
136
  //Group refactorings by name
137
+ //TODO: group also by itemType, cause different item types (for example screen and signal name) could have the same string
94
138
  for (const r of refactorings) {
95
- let thisList = this.refactorings.get(r.name);
139
+ let thisList = this.refactorings.get(r.itemType + '|' + r.name);
96
140
  if (thisList === undefined) {
97
141
  thisList = [];
98
- this.refactorings.set(r.name, thisList);
142
+ this.refactorings.set(r.itemType + '|' + r.name, thisList);
99
143
  }
100
144
  thisList.push(r);
101
145
  }
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.30",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",