@node-projects/web-component-designer-visualization-addons 0.1.68 → 0.1.70

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
@@ -184,9 +184,15 @@ export interface SetElementProperty {
184
184
  */
185
185
  target: 'property' | 'attribute' | 'css' | 'class';
186
186
  /**
187
- * where to search for the elements
187
+ * where to search for the elements.
188
+ * element
189
+ * container = screen or customControl
188
190
  */
189
- targetSelectorTarget: 'currentScreen' | 'parentScreen' | 'currentElement' | 'parentElement';
191
+ targetSelectorTarget: 'element' | 'container';
192
+ /**
193
+ * wich parent, 0 = current, 1 = first parent, 2 = ...
194
+ */
195
+ parentIndex: number;
190
196
  /**
191
197
  * css selector to find elements, if empty the targetSelectorTarget is used
192
198
  */
@@ -196,8 +202,8 @@ export interface SetElementProperty {
196
202
  */
197
203
  name: string;
198
204
  /**
199
- * only for class
200
- */
205
+ * only for target: class
206
+ */
201
207
  mode: 'add' | 'remove' | 'toggle';
202
208
  /**
203
209
  * value you want to set
@@ -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 === 'container') {
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 === "element") {
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.68",
4
+ "version": "0.1.70",
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 {};