@node-projects/web-component-designer-visualization-addons 0.1.127 → 0.1.129

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.
@@ -8,7 +8,7 @@ export class BindingsEditor extends BaseCustomWebComponentConstructorAppend {
8
8
  <div style="grid-column: 1/3">
9
9
  <div style="display: flex; flex-direction: column;">
10
10
  <div class="row">
11
- <span style="cursor: pointer;" title="to use multiple objects, seprate them with semicolon (;).&#010;Access signal objects in properties via ?propertyName, access the propertyValue via ??propertyName.&#010;Access signal objects in properties of the target via #propertyName, access a propertyValue of the target via ##propertyName.&#010;Bind to signal configurations via $objectId.&#010;You could also use signals inside of a Signal Name via {name}">objects</span>
11
+ <span style="cursor: pointer;" title="to use multiple objects, seprate them with semicolon (;).&#010;Access signal objects in properties via ?propertyName, access the propertyValue via ??propertyName.&#010;Access signal objects in properties of the target via #propertyName, access a propertyValue of the target via ##propertyName.&#010;Bind to signal configurations via $objectId.&#010;Bind to special values via §name (if supported by your framework).&#010;You could also use signals inside of a Signal Name via {name}">objects</span>
12
12
  </div>
13
13
  <div id="groupObjectName" style="display:flex;align-items: flex-end;">
14
14
  <input id="objectName" class="row" value="{{?this.objectNames::change}}" style="flex-grow: 1;">
@@ -207,7 +207,7 @@ export class SimpleScriptEditor extends BaseCustomWebComponentConstructorAppend
207
207
  }
208
208
  //Converter from TypscriptJsonSchema to our Property list...
209
209
  async addPossibleCommands() {
210
- let commands = Object.keys(this.scriptCommandsTypeInfo.definitions);
210
+ let commands = Object.keys(this.scriptCommandsTypeInfo.definitions).filter(x => this.scriptCommandsTypeInfo.definitions[x].type == 'object');
211
211
  for (let c of commands) {
212
212
  if (c == 'ScriptCommands')
213
213
  continue;
@@ -4,11 +4,11 @@ import { BindingTarget } from "@node-projects/web-component-designer/dist/elemen
4
4
  export type SpecialValueHandler = {
5
5
  valueProvider: (propertyName: string, context: {
6
6
  element: Element;
7
- binding: namedBinding;
7
+ binding?: namedBinding;
8
8
  relativeSignalPath: string;
9
9
  root: HTMLElement;
10
10
  [key: string]: any;
11
- }) => any;
11
+ }) => Promise<any> | any;
12
12
  valueChangedCallbacks: Map<string, (() => void)[]>;
13
13
  };
14
14
  export declare const bindingPrefixProperty = "bind-prop:";
@@ -57,7 +57,7 @@ class IndirectSignal {
57
57
  visualizationHandler;
58
58
  element;
59
59
  relativeSignalPath;
60
- constructor(bindingsHelper, visualizationHandler, id, valueChangedCb, element, relativeSignalPath, root) {
60
+ constructor(bindingsHelper, visualizationHandler, id, valueChangedCb, element, relativeSignalPath, root, specialValueHandler) {
61
61
  this.visualizationHandler = visualizationHandler;
62
62
  this.valueChangedCb = valueChangedCb;
63
63
  this.element = element;
@@ -96,6 +96,28 @@ class IndirectSignal {
96
96
  }
97
97
  continue;
98
98
  }
99
+ else if (nm[0] === '§') {
100
+ const mS = nm.substring(1);
101
+ const value = specialValueHandler.valueProvider(mS, { element, relativeSignalPath, root });
102
+ if (value instanceof Promise)
103
+ value.then(v => this.handleValueChanged(v, i));
104
+ else
105
+ this.handleValueChanged(value, i);
106
+ if (!specialValueHandler.valueChangedCallbacks)
107
+ specialValueHandler.valueChangedCallbacks = new Map();
108
+ let changeList = specialValueHandler.valueChangedCallbacks.get(mS);
109
+ if (changeList == null) {
110
+ changeList = [];
111
+ specialValueHandler.valueChangedCallbacks.set(mS, changeList);
112
+ }
113
+ changeList.push(() => {
114
+ const value = specialValueHandler.valueProvider(mS, { element, relativeSignalPath, root });
115
+ if (value instanceof Promise)
116
+ value.then(v => this.handleValueChanged(v, i));
117
+ else
118
+ this.handleValueChanged(value, i);
119
+ });
120
+ }
99
121
  else if (nm[0] === '?') {
100
122
  //TODO: react to changes of signal name in prop
101
123
  if (!nm.includes('.')) {
@@ -731,7 +753,10 @@ export class BindingsHelper {
731
753
  else if (s[0] === '§') {
732
754
  const mS = s.substring(1);
733
755
  const value = specialValueHandler.valueProvider(mS, { element, binding, relativeSignalPath, root });
734
- this.handleValueChanged(element, binding, value, valuesObject, i, signalVars, true, relativeSignalPath);
756
+ if (value instanceof Promise)
757
+ value.then(v => this.handleValueChanged(element, binding, v, valuesObject, i, signalVars, true, relativeSignalPath));
758
+ else
759
+ this.handleValueChanged(element, binding, value, valuesObject, i, signalVars, true, relativeSignalPath);
735
760
  if (!specialValueHandler.valueChangedCallbacks)
736
761
  specialValueHandler.valueChangedCallbacks = new Map();
737
762
  let changeList = specialValueHandler.valueChangedCallbacks.get(mS);
@@ -741,12 +766,15 @@ export class BindingsHelper {
741
766
  }
742
767
  changeList.push(() => {
743
768
  const value = specialValueHandler.valueProvider(mS, { element, binding, relativeSignalPath, root });
744
- this.handleValueChanged(element, binding, value, valuesObject, i, signalVars, true, relativeSignalPath);
769
+ if (value instanceof Promise)
770
+ value.then(v => this.handleValueChanged(element, binding, v, valuesObject, i, signalVars, true, relativeSignalPath));
771
+ else
772
+ this.handleValueChanged(element, binding, value, valuesObject, i, signalVars, true, relativeSignalPath);
745
773
  });
746
774
  }
747
775
  else {
748
776
  if (s.includes('{')) {
749
- let indirectSignal = new IndirectSignal(this, this._visualizationHandler, s, (value) => this.handleValueChanged(element, binding, value.val, valuesObject, i, signalVars, false, relativeSignalPath), element, relativeSignalPath, root);
777
+ let indirectSignal = new IndirectSignal(this, this._visualizationHandler, s, (value) => this.handleValueChanged(element, binding, value.val, valuesObject, i, signalVars, false, relativeSignalPath), element, relativeSignalPath, root, specialValueHandler);
750
778
  if (!cleanupCalls)
751
779
  cleanupCalls = [];
752
780
  cleanupCalls.push(() => indirectSignal.dispose());
package/dist/index.d.ts CHANGED
@@ -9,11 +9,11 @@ export * from './components/VisualizationPropertyGrid.js';
9
9
  export * from './components/ParameterEditor.js';
10
10
  export * from './components/EventAssignment.js';
11
11
  export * from './helpers/BindingsHelper.js';
12
- export * from './interfaces/IScriptMultiplexValue.js';
13
- export * from './interfaces/VisualisationElementScript.js';
14
- export * from './interfaces/VisualizationBinding.js';
15
- export * from './interfaces/VisualizationHandler.js';
16
- export * from './interfaces/VisualizationShell.js';
12
+ export type * from './interfaces/IScriptMultiplexValue.js';
13
+ export type * from './interfaces/VisualisationElementScript.js';
14
+ export type * from './interfaces/VisualizationBinding.js';
15
+ export type * from './interfaces/VisualizationHandler.js';
16
+ export type * from './interfaces/VisualizationShell.js';
17
17
  export * from './scripting/Script.js';
18
18
  export * from './scripting/ScriptCommands.js';
19
19
  export * from './scripting/ScriptSystem.js';
package/dist/index.js CHANGED
@@ -9,11 +9,6 @@ export * from './components/VisualizationPropertyGrid.js';
9
9
  export * from './components/ParameterEditor.js';
10
10
  export * from './components/EventAssignment.js';
11
11
  export * from './helpers/BindingsHelper.js';
12
- export * from './interfaces/IScriptMultiplexValue.js';
13
- export * from './interfaces/VisualisationElementScript.js';
14
- export * from './interfaces/VisualizationBinding.js';
15
- export * from './interfaces/VisualizationHandler.js';
16
- export * from './interfaces/VisualizationShell.js';
17
12
  export * from './scripting/Script.js';
18
13
  export * from './scripting/ScriptCommands.js';
19
14
  export * from './scripting/ScriptSystem.js';
@@ -1,4 +1,4 @@
1
- export declare class IScriptMultiplexValue {
1
+ export interface IScriptMultiplexValue {
2
2
  /**
3
3
  * signal - read the value from a Signal
4
4
  * property - read the value from a property of the customControl (not usable in screens)
@@ -8,8 +8,9 @@ export declare class IScriptMultiplexValue {
8
8
  * complexString - a string with signals (contained in {})
9
9
  * complexSignal - read the value from a signal wich name is build here (it can contain other signals in {})
10
10
  * expression - js expression, 'ctx' is context object
11
+ * elementProperty - a property defined on the element raising the event
11
12
  */
12
- source: 'signal' | 'property' | 'event' | 'parameter' | 'complexString' | 'complexSignal' | 'expression' | 'context';
13
+ source: 'signal' | 'property' | 'event' | 'parameter' | 'complexString' | 'complexSignal' | 'expression' | 'context' | 'elementProperty';
13
14
  /**
14
15
  * Name of the signal, the property of the component or the parameter of the script
15
16
  * or for example in a event : srcElement.value to get the value of a input wich raises the event
@@ -1,19 +1 @@
1
- export class IScriptMultiplexValue {
2
- /**
3
- * signal - read the value from a Signal
4
- * property - read the value from a property of the customControl (not usable in screens)
5
- * event - read the value of a property of the event object
6
- * parameter - a parameter you hand over
7
- * context - a value of the context
8
- * complexString - a string with signals (contained in {})
9
- * complexSignal - read the value from a signal wich name is build here (it can contain other signals in {})
10
- * expression - js expression, 'ctx' is context object
11
- */
12
- source;
13
- /**
14
- * Name of the signal, the property of the component or the parameter of the script
15
- * or for example in a event : srcElement.value to get the value of a input wich raises the event
16
- * @TJS-format signal
17
- */
18
- name;
19
- }
1
+ export {};
@@ -5,7 +5,7 @@ export declare type RunnableScriptCommands = OpenScreen | OpenUrl | OpenDialog |
5
5
  * property - a property defined in the current screen/control
6
6
  * elementProperty - a property defined on the element raising the event
7
7
  */
8
- export type signalTarget = 'signal' | 'property' | 'elementProperty';
8
+ export declare type signalTarget = 'signal' | 'property' | 'elementProperty';
9
9
  export interface Comment {
10
10
  type: 'Comment';
11
11
  comment: string;
@@ -364,7 +364,7 @@ export interface Condition {
364
364
  */
365
365
  value1: any;
366
366
  value2?: any;
367
- comparisonType: '==null' | '!=null' | '==true' | '==false' | '==' | '!=' | '>' | '<' | '>=' | '<=';
367
+ comparisonType: '==null' | '!=null' | '==true' | '==false' | '==' | '!=' | '>' | '<' | '>=' | '<=' | '&&' | '||';
368
368
  /**
369
369
  * Name of the label to jumpe to when condition is true
370
370
  */
@@ -23,7 +23,6 @@ export declare class ScriptSystem {
23
23
  getStateOrFieldOrParameter(name: string, context: contextType): Promise<any>;
24
24
  parseStringWithValues(text: string, context: contextType): Promise<string>;
25
25
  getSignalName(name: string, outerContext: contextType): string;
26
- static extractPart(obj: any, propertyPath: string): any;
27
26
  createScriptContext(root: HTMLElement, event: Event, element: Element, parameters: Record<string, any>, relativeSignalsPath: string): any;
28
27
  assignAllScripts(source: string, javascriptCode: string, shadowRoot: ShadowRoot, instance: HTMLElement, visualizationHandler: VisualizationHandler, contextCreator?: (root: HTMLElement, event: Event, element: Element, parameters: Record<string, any>, relativeSignalsPath: string) => any, assignExternalScript?: (element: Element, event: string, scriptData: any) => void, runInitalization?: (jsObject: VisualisationElementScript) => void): Promise<VisualisationElementScript>;
29
28
  }
@@ -1,4 +1,4 @@
1
- import { sleep } from "@node-projects/web-component-designer/dist/elements/helper/Helper.js";
1
+ import { deepValue, setDeepValue, sleep } from "@node-projects/web-component-designer/dist/elements/helper/Helper.js";
2
2
  import { generateEventCodeFromBlockly } from "../blockly/BlocklyJavascriptHelper.js";
3
3
  import { parseBindingString } from "../helpers/BindingsHelper.js";
4
4
  import Long from 'long';
@@ -57,6 +57,12 @@ export class ScriptSystem {
57
57
  case '<=':
58
58
  res = value1 <= value2;
59
59
  break;
60
+ case '&&':
61
+ res = value1 && value2;
62
+ break;
63
+ case '||':
64
+ res = value1 || value2;
65
+ break;
60
66
  }
61
67
  if (res) {
62
68
  await this.runExternalScript(await this.getValue(c.trueScriptName, outerContext), await this.getValue(c.trueScriptType, outerContext));
@@ -83,10 +89,10 @@ export class ScriptSystem {
83
89
  }
84
90
  async getValueFromTarget(target, name, context) {
85
91
  if (target === 'property') {
86
- return context.root[name];
92
+ return deepValue(context.root, name);
87
93
  }
88
94
  else if (target === 'elementProperty') {
89
- return context.element[name];
95
+ return deepValue(context.element, name);
90
96
  }
91
97
  else {
92
98
  return (await this._visualizationHandler.getState(this.getSignalName(name, context)))?.val;
@@ -94,10 +100,10 @@ export class ScriptSystem {
94
100
  }
95
101
  async setValueOnTarget(target, name, context, value) {
96
102
  if (target === 'property') {
97
- context.root[name] = value;
103
+ setDeepValue(context.root, name, value);
98
104
  }
99
105
  else if (target === 'elementProperty') {
100
- context.element[name] = value;
106
+ setDeepValue(context.element, name, value);
101
107
  }
102
108
  else {
103
109
  await this._visualizationHandler.setState(this.getSignalName(name, context), value);
@@ -349,7 +355,10 @@ export class ScriptSystem {
349
355
  if (typeof value === 'object') {
350
356
  switch (value.source) {
351
357
  case 'property': {
352
- return outerContext.root[value.name];
358
+ return deepValue(outerContext.root, value.name);
359
+ }
360
+ case 'elementProperty': {
361
+ return deepValue(outerContext.element, value.name);
353
362
  }
354
363
  case 'signal': {
355
364
  let sng = await this._visualizationHandler.getState(this.getSignalName(value.name, outerContext));
@@ -358,15 +367,14 @@ export class ScriptSystem {
358
367
  case 'event': {
359
368
  let obj = outerContext.event;
360
369
  if (value.name)
361
- obj = ScriptSystem.extractPart(obj, value.name);
370
+ obj = deepValue(obj, value.name);
362
371
  return obj;
363
372
  }
364
373
  case 'parameter': {
365
374
  return outerContext.parameters[value.name];
366
375
  }
367
376
  case 'context': {
368
- const obj = ScriptSystem.extractPart(outerContext, value.name);
369
- return obj;
377
+ return deepValue(outerContext, value.name);
370
378
  }
371
379
  case 'complexString': {
372
380
  let text = value.name;
@@ -427,13 +435,6 @@ export class ScriptSystem {
427
435
  return outerContext.relativeSignalsPath + name;
428
436
  return name;
429
437
  }
430
- static extractPart(obj, propertyPath) {
431
- let retVal = obj;
432
- for (let p of propertyPath.split('.')) {
433
- retVal = retVal?.[p];
434
- }
435
- return retVal;
436
- }
437
438
  createScriptContext(root, event, element, parameters, relativeSignalsPath) {
438
439
  return { root, event, element, parameters, relativeSignalsPath };
439
440
  }
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.127",
4
+ "version": "0.1.129",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",