@node-projects/web-component-designer-visualization-addons 0.1.67 → 0.1.69

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.
@@ -7,6 +7,7 @@ import { Wunderbaum } from 'wunderbaum';
7
7
  import wunderbaumStyle from 'wunderbaum/dist/wunderbaum.css' with { type: 'css' };
8
8
  import { VisualizationPropertyGrid } from "./VisualizationPropertyGrid.js";
9
9
  import '@node-projects/splitview.webcomponent';
10
+ import { ScriptUpgrades } from "../scripting/ScriptUpgrader.js";
10
11
  export class SimpleScriptEditor extends BaseCustomWebComponentConstructorAppend {
11
12
  static style = css `
12
13
  :host {
@@ -191,6 +192,7 @@ export class SimpleScriptEditor extends BaseCustomWebComponentConstructorAppend
191
192
  this._script = script;
192
193
  let commandListTreeItems = [];
193
194
  for (let c of this._script.commands) {
195
+ c = ScriptUpgrades.upgradeScriptCommand(c);
194
196
  commandListTreeItems.push(this.createTreeItem(c));
195
197
  }
196
198
  ;
@@ -4,11 +4,12 @@ export declare class IScriptMultiplexValue {
4
4
  * property - read the value from a property of the customControl (not usable in screens)
5
5
  * event - read the value of a property of the event object
6
6
  * parameter - a parameter you hand over
7
+ * context - a value of the context
7
8
  * complexString - a string with signals (contained in {})
8
9
  * complexSignal - read the value from a signal wich name is build here (it can contain other signals in {})
9
10
  * expression - js expression, 'ctx' is context object
10
11
  */
11
- source: 'signal' | 'property' | 'event' | 'parameter' | 'complexString' | 'complexSignal' | 'expression';
12
+ source: 'signal' | 'property' | 'event' | 'parameter' | 'complexString' | 'complexSignal' | 'expression' | 'context';
12
13
  /**
13
14
  * Name of the signal, the property of the component or the parameter of the script
14
15
  * or for example in a event : srcElement.value to get the value of a input wich raises the event
@@ -4,6 +4,7 @@ export class IScriptMultiplexValue {
4
4
  * property - read the value from a property of the customControl (not usable in screens)
5
5
  * event - read the value of a property of the event object
6
6
  * parameter - a parameter you hand over
7
+ * context - a value of the context
7
8
  * complexString - a string with signals (contained in {})
8
9
  * complexSignal - read the value from a signal wich name is build here (it can contain other signals in {})
9
10
  * expression - js expression, 'ctx' is context object
@@ -17,6 +17,7 @@ export interface OpenScreen {
17
17
  relativeSignalsPath?: string;
18
18
  noHistory?: boolean;
19
19
  closeable?: boolean;
20
+ additionalData?: string;
20
21
  }
21
22
  export interface OpenDialog {
22
23
  type: 'OpenDialog';
@@ -36,6 +37,7 @@ export interface OpenDialog {
36
37
  height?: string;
37
38
  left?: string;
38
39
  top?: string;
40
+ additionalData?: string;
39
41
  }
40
42
  export interface ShowMessageBox {
41
43
  type: 'ShowMessageBox';
@@ -62,9 +64,15 @@ export interface ShowMessageBox {
62
64
  resultSignal: string;
63
65
  width?: string;
64
66
  height?: string;
67
+ additionalData?: string;
65
68
  }
66
69
  export interface CloseDialog {
67
70
  type: 'CloseDialog';
71
+ /**
72
+ * A dialogId. If empty the parent dialog will be closed
73
+ * @TJS-format signal
74
+ */
75
+ additionalData?: string;
68
76
  }
69
77
  export interface OpenUrl {
70
78
  type: 'OpenUrl';
@@ -74,6 +82,7 @@ export interface OpenUrl {
74
82
  */
75
83
  target: string;
76
84
  openInDialog: boolean;
85
+ additionalData?: string;
77
86
  }
78
87
  export interface SetSignalValue {
79
88
  type: 'SetSignalValue';
@@ -83,6 +92,7 @@ export interface SetSignalValue {
83
92
  */
84
93
  signal: string;
85
94
  value: any;
95
+ additionalData?: string;
86
96
  }
87
97
  export interface ToggleSignalValue {
88
98
  type: 'ToggleSignalValue';
@@ -91,6 +101,7 @@ export interface ToggleSignalValue {
91
101
  * @TJS-format signal
92
102
  */
93
103
  signal: string;
104
+ additionalData?: string;
94
105
  }
95
106
  export interface IncrementSignalValue {
96
107
  type: 'IncrementSignalValue';
@@ -100,6 +111,7 @@ export interface IncrementSignalValue {
100
111
  */
101
112
  signal: string;
102
113
  value: number;
114
+ additionalData?: string;
103
115
  }
104
116
  export interface CalculateSignalValue {
105
117
  type: 'CalculateSignalValue';
@@ -113,6 +125,7 @@ export interface CalculateSignalValue {
113
125
  * Example: {adapter.0.level} * 100 + 30
114
126
  */
115
127
  formula: string;
128
+ additionalData?: string;
116
129
  }
117
130
  export interface DecrementSignalValue {
118
131
  type: 'DecrementSignalValue';
@@ -122,6 +135,7 @@ export interface DecrementSignalValue {
122
135
  */
123
136
  signal: string;
124
137
  value: number;
138
+ additionalData?: string;
125
139
  }
126
140
  export interface SetBitInSignal {
127
141
  type: 'SetBitInSignal';
@@ -131,6 +145,7 @@ export interface SetBitInSignal {
131
145
  */
132
146
  signal: string;
133
147
  bitNumber: number;
148
+ additionalData?: string;
134
149
  }
135
150
  export interface ClearBitInSignal {
136
151
  type: 'ClearBitInSignal';
@@ -140,6 +155,7 @@ export interface ClearBitInSignal {
140
155
  */
141
156
  signal: string;
142
157
  bitNumber: number;
158
+ additionalData?: string;
143
159
  }
144
160
  export interface ToggleBitInSignal {
145
161
  type: 'ToggleBitInSignal';
@@ -149,6 +165,7 @@ export interface ToggleBitInSignal {
149
165
  */
150
166
  signal: string;
151
167
  bitNumber: number;
168
+ additionalData?: string;
152
169
  }
153
170
  export interface Javascript {
154
171
  type: 'Javascript';
@@ -158,6 +175,7 @@ export interface Javascript {
158
175
  * @TJS-format script
159
176
  */
160
177
  script: string;
178
+ additionalData?: string;
161
179
  }
162
180
  export interface SetElementProperty {
163
181
  type: 'SetElementProperty';
@@ -166,9 +184,15 @@ export interface SetElementProperty {
166
184
  */
167
185
  target: 'property' | 'attribute' | 'css' | 'class';
168
186
  /**
169
- * where to search for the elements
187
+ * where to search for the elements.
188
+ * element
189
+ * container = screen or customControl
170
190
  */
171
- targetSelectorTarget: 'currentScreen' | 'parentScreen' | 'currentElement' | 'parentElement';
191
+ targetSelectorTarget: 'element' | 'container';
192
+ /**
193
+ * wich parent, 0 = current, 1 = first parent, 2 = ...
194
+ */
195
+ parentIndex: number;
172
196
  /**
173
197
  * css selector to find elements, if empty the targetSelectorTarget is used
174
198
  */
@@ -178,13 +202,14 @@ export interface SetElementProperty {
178
202
  */
179
203
  name: string;
180
204
  /**
181
- * only for class
182
- */
205
+ * only for target: class
206
+ */
183
207
  mode: 'add' | 'remove' | 'toggle';
184
208
  /**
185
209
  * value you want to set
186
210
  */
187
211
  value: any;
212
+ additionalData?: string;
188
213
  }
189
214
  export interface Delay {
190
215
  type: 'Delay';
@@ -192,6 +217,7 @@ export interface Delay {
192
217
  * miliseconds to delay
193
218
  */
194
219
  value: number;
220
+ additionalData?: string;
195
221
  }
196
222
  export interface Console {
197
223
  type: 'Console';
@@ -203,13 +229,16 @@ export interface Console {
203
229
  * console message
204
230
  */
205
231
  message: string;
232
+ additionalData?: string;
206
233
  }
207
234
  export interface SwitchLanguage {
208
235
  type: 'SwitchLanguage';
209
236
  language: string;
237
+ additionalData?: string;
210
238
  }
211
239
  export interface Logout {
212
240
  type: 'Logout';
241
+ additionalData?: string;
213
242
  }
214
243
  export interface Login {
215
244
  type: 'Login';
@@ -221,6 +250,7 @@ export interface Login {
221
250
  * password
222
251
  */
223
252
  password: string;
253
+ additionalData?: string;
224
254
  }
225
255
  export interface SubscribeSignal {
226
256
  type: 'SubscribeSignal';
@@ -230,6 +260,7 @@ export interface SubscribeSignal {
230
260
  */
231
261
  signal: string;
232
262
  oneTime: boolean;
263
+ additionalData?: string;
233
264
  }
234
265
  export interface UnsubscribeSignal {
235
266
  type: 'UnsubscribeSignal';
@@ -238,6 +269,7 @@ export interface UnsubscribeSignal {
238
269
  * @TJS-format signal
239
270
  */
240
271
  signal: string;
272
+ additionalData?: string;
241
273
  }
242
274
  export interface WriteSignalsInGroup {
243
275
  type: 'WriteSignalsInGroup';
@@ -245,6 +277,7 @@ export interface WriteSignalsInGroup {
245
277
  * Name of the Group
246
278
  */
247
279
  group: string;
280
+ additionalData?: string;
248
281
  }
249
282
  export interface ClearSiganlsInGroup {
250
283
  type: 'ClearSiganlsInGroup';
@@ -252,6 +285,7 @@ export interface ClearSiganlsInGroup {
252
285
  * Name of the Group
253
286
  */
254
287
  group: string;
288
+ additionalData?: string;
255
289
  }
256
290
  export interface CopySignalValuesFromFolder {
257
291
  type: 'CopySignalValuesFromFolder';
@@ -263,6 +297,7 @@ export interface CopySignalValuesFromFolder {
263
297
  * name of destination folder
264
298
  */
265
299
  destinationFolder?: number;
300
+ additionalData?: string;
266
301
  }
267
302
  export interface ExportSignalValuesAsJson {
268
303
  type: 'ExportSignalValuesAsJson';
@@ -278,6 +313,7 @@ export interface ExportSignalValuesAsJson {
278
313
  * download filename
279
314
  */
280
315
  fileName?: string;
316
+ additionalData?: string;
281
317
  }
282
318
  export interface ImportSignalValuesFromJson {
283
319
  type: 'ImportSignalValuesFromJson';
@@ -285,6 +321,7 @@ export interface ImportSignalValuesFromJson {
285
321
  * json data with the values
286
322
  */
287
323
  data: string;
324
+ additionalData?: string;
288
325
  }
289
326
  export interface Condition {
290
327
  type: 'Condition';
@@ -304,17 +341,21 @@ export interface Condition {
304
341
  falseGotoLabel?: string;
305
342
  falseScriptName?: string;
306
343
  falseScriptType?: string;
344
+ additionalData?: string;
307
345
  }
308
346
  export interface Exit {
309
347
  type: 'Exit';
348
+ additionalData?: string;
310
349
  }
311
350
  export interface Label {
312
351
  type: 'Label';
313
352
  label: string;
353
+ additionalData?: string;
314
354
  }
315
355
  export interface Goto {
316
356
  type: 'Goto';
317
357
  label: string;
358
+ additionalData?: string;
318
359
  }
319
360
  export interface RunScript {
320
361
  type: 'RunScript';
@@ -326,4 +367,5 @@ export interface RunScript {
326
367
  * Type of the Script
327
368
  */
328
369
  scriptType: 'string';
370
+ additionalData?: string;
329
371
  }
@@ -15,7 +15,8 @@ export declare class ScriptSystem {
15
15
  execute(scriptCommands: ScriptCommands[], outerContext: contextType): Promise<void>;
16
16
  runExternalScript(name: string, type: string): Promise<void>;
17
17
  runScriptCommand<T extends ScriptCommands>(command: T, context: contextType): Promise<void>;
18
- getTargetFromTargetSelector(context: contextType, targetSelectorTarget: 'currentScreen' | 'parentScreen' | 'currentElement' | 'parentElement', targetSelector: string): Iterable<Element>;
18
+ getTarget(context: contextType, targetSelectorTarget: 'element' | 'container', parentLevel: number): Element;
19
+ getTargetFromTargetSelector(context: contextType, targetSelectorTarget: 'element' | 'container', parentLevel: number, targetSelector: string): Iterable<Element>;
19
20
  getValue<T>(value: T, outerContext: contextType): Promise<T>;
20
21
  getStateOrFieldOrParameter(name: string, context: contextType): Promise<any>;
21
22
  parseStringWithValues(text: string, context: contextType): Promise<string>;
@@ -2,6 +2,7 @@ import { sleep } from "@node-projects/web-component-designer/dist/elements/helpe
2
2
  import { generateEventCodeFromBlockly } from "../blockly/BlocklyJavascriptHelper.js";
3
3
  import { parseBindingString } from "../helpers/BindingsHelper.js";
4
4
  import Long from 'long';
5
+ import { ScriptUpgrades } from "./ScriptUpgrader.js";
5
6
  export class ScriptSystem {
6
7
  _visualizationHandler;
7
8
  _subscriptionCallback = () => { };
@@ -176,9 +177,12 @@ export class ScriptSystem {
176
177
  break;
177
178
  }
178
179
  case 'SetElementProperty': {
180
+ //@ts-ignore
181
+ command = ScriptUpgrades.upgradeSetElementProperty(command);
179
182
  const name = await this.getValue(command.name, context);
180
183
  const value = await this.getValue(command.value, context);
181
- let elements = this.getTargetFromTargetSelector(context, command.targetSelectorTarget, command.targetSelector);
184
+ const parentIndex = await this.getValue(command.parentIndex, context);
185
+ let elements = this.getTargetFromTargetSelector(context, command.targetSelectorTarget, parentIndex, command.targetSelector);
182
186
  for (let e of elements) {
183
187
  if (command.target == 'attribute') {
184
188
  e.setAttribute(name, value);
@@ -239,17 +243,30 @@ export class ScriptSystem {
239
243
  }
240
244
  }
241
245
  }
242
- getTargetFromTargetSelector(context, targetSelectorTarget, targetSelector) {
243
- let host = context.element.getRootNode().host;
244
- if (targetSelector == 'currentElement')
245
- host = context.element;
246
- else if (targetSelector == 'parentElement')
247
- host = context.element.parentElement;
248
- else if (targetSelector == 'parentScreen')
249
- host = host.getRootNode().host;
250
- let elements = [host];
251
- if (targetSelector)
252
- elements = host.shadowRoot.querySelectorAll(targetSelector);
246
+ getTarget(context, targetSelectorTarget, parentLevel) {
247
+ if (targetSelectorTarget == 'element') {
248
+ let el = context.element.getRootNode().host;
249
+ for (let i = 0; i < (parentLevel ?? 0); i++)
250
+ el = el.getRootNode().host;
251
+ return el;
252
+ }
253
+ else if (targetSelectorTarget == "container") {
254
+ let el = context.element;
255
+ for (let i = 0; i < (parentLevel ?? 0); i++)
256
+ el = el.parentElement;
257
+ return el;
258
+ }
259
+ return null;
260
+ }
261
+ getTargetFromTargetSelector(context, targetSelectorTarget, parentLevel, targetSelector) {
262
+ const target = this.getTarget(context, targetSelectorTarget, parentLevel);
263
+ let elements = [target];
264
+ if (targetSelector) {
265
+ if (targetSelectorTarget === 'container')
266
+ elements = target.shadowRoot.querySelectorAll(targetSelector);
267
+ else
268
+ elements = target.querySelectorAll(targetSelector);
269
+ }
253
270
  return elements;
254
271
  }
255
272
  async getValue(value, outerContext) {
@@ -271,6 +288,10 @@ export class ScriptSystem {
271
288
  case 'parameter': {
272
289
  return outerContext.parameters[value.name];
273
290
  }
291
+ case 'context': {
292
+ const obj = ScriptSystem.extractPart(outerContext, value.name);
293
+ return obj;
294
+ }
274
295
  case 'complexString': {
275
296
  let text = value.name;
276
297
  if (text != null) {
@@ -0,0 +1,5 @@
1
+ import { ScriptCommands, SetElementProperty } from "./ScriptCommands";
2
+ export declare class ScriptUpgrades {
3
+ static upgradeScriptCommand(scriptCommand: ScriptCommands): import("./ScriptCommands").Comment | import("./ScriptCommands").OpenScreen | import("./ScriptCommands").OpenUrl | import("./ScriptCommands").OpenDialog | import("./ScriptCommands").CloseDialog | import("./ScriptCommands").ToggleSignalValue | import("./ScriptCommands").SetSignalValue | import("./ScriptCommands").IncrementSignalValue | import("./ScriptCommands").DecrementSignalValue | import("./ScriptCommands").SetBitInSignal | import("./ScriptCommands").ClearBitInSignal | import("./ScriptCommands").ToggleBitInSignal | import("./ScriptCommands").Console | import("./ScriptCommands").CalculateSignalValue | import("./ScriptCommands").Javascript | SetElementProperty | import("./ScriptCommands").Delay | import("./ScriptCommands").SwitchLanguage | import("./ScriptCommands").Login | import("./ScriptCommands").Logout | import("./ScriptCommands").SubscribeSignal | import("./ScriptCommands").UnsubscribeSignal | import("./ScriptCommands").WriteSignalsInGroup | import("./ScriptCommands").ClearSiganlsInGroup | import("./ScriptCommands").Condition | import("./ScriptCommands").Exit | import("./ScriptCommands").Label | import("./ScriptCommands").RunScript | import("./ScriptCommands").Goto | import("./ScriptCommands").CopySignalValuesFromFolder | import("./ScriptCommands").ShowMessageBox | import("./ScriptCommands").ExportSignalValuesAsJson | import("./ScriptCommands").ImportSignalValuesFromJson;
4
+ static upgradeSetElementProperty(scriptCommand: SetElementProperty): SetElementProperty;
5
+ }
@@ -0,0 +1,26 @@
1
+ //For upgradeing changed script commands
2
+ export class ScriptUpgrades {
3
+ static upgradeScriptCommand(scriptCommand) {
4
+ if (scriptCommand.type === 'SetElementProperty') {
5
+ return ScriptUpgrades.upgradeSetElementProperty(scriptCommand);
6
+ }
7
+ return scriptCommand;
8
+ }
9
+ static upgradeSetElementProperty(scriptCommand) {
10
+ if (scriptCommand.targetSelectorTarget === 'currentScreen') {
11
+ scriptCommand.targetSelector = 'container';
12
+ }
13
+ else if (scriptCommand.targetSelectorTarget === 'parentScreen') {
14
+ scriptCommand.targetSelector = 'container';
15
+ scriptCommand.parentIndex = 1;
16
+ }
17
+ else if (scriptCommand.targetSelectorTarget === 'currentElement') {
18
+ scriptCommand.targetSelector = 'element';
19
+ }
20
+ else if (scriptCommand.targetSelectorTarget === 'parentElement') {
21
+ scriptCommand.targetSelector = 'element';
22
+ scriptCommand.parentIndex = 1;
23
+ }
24
+ return scriptCommand;
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "web-component-designer addon for visualizations",
3
3
  "name": "@node-projects/web-component-designer-visualization-addons",
4
- "version": "0.1.67",
4
+ "version": "0.1.69",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- //@ts-ignore
2
- class FieldObjectId extends Blockly.FieldTextInput {
3
- }
4
- //@ts-ignore
5
- Blockly.FieldObjectId = FieldObjectId;
6
- export {};