@node-projects/web-component-designer-visualization-addons 0.1.146 → 0.1.147
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.
- package/dist/components/SimpleScriptEditor.d.ts +6 -1
- package/dist/components/SimpleScriptEditor.js +380 -42
- package/dist/components/VisualizationPropertyGrid.d.ts +2 -0
- package/dist/components/VisualizationPropertyGrid.js +8 -0
- package/dist/index-min.js +54 -46
- package/dist/scripting/ScriptCommands.d.ts +34 -1
- package/dist/scripting/ScriptCommandsDescriptions.js +5 -0
- package/dist/scripting/ScriptSystem.d.ts +3 -2
- package/dist/scripting/ScriptSystem.js +25 -0
- package/dist/scripting/ScriptUpgrader.d.ts +1 -1
- package/dist/scripting/ScriptUpgrader.js +4 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { IScriptMultiplexValue } from "../interfaces/IScriptMultiplexValue.js";
|
|
2
|
+
export declare type ScriptCommands = RunnableScriptCommands | Comment | Condition | If | Exit | Label | Goto;
|
|
2
3
|
export declare type RunnableScriptCommands = OpenScreen | OpenUrl | OpenDialog | CloseDialog | ToggleSignalValue | ToggleSignalValueThroughList | SetSignalValue | IncrementSignalValue | DecrementSignalValue | SetBitInSignal | ClearBitInSignal | ToggleBitInSignal | Console | CalculateSignalValue | Javascript | SetElementProperty | Delay | SwitchLanguage | Login | Logout | SubscribeSignal | UnsubscribeSignal | WriteSignalsInGroup | ClearSignalsInGroup | RunScript | CopySignalValuesFromFolder | ShowMessageBox | ShowPrompt | ExportSignalValuesAsJson | ImportSignalValuesFromJson | Repeat;
|
|
3
4
|
/**
|
|
4
5
|
* signal - a signal (the default)
|
|
@@ -419,6 +420,38 @@ export interface Condition {
|
|
|
419
420
|
falseScriptType?: string;
|
|
420
421
|
additionalData?: string;
|
|
421
422
|
}
|
|
423
|
+
export interface IfSignal extends IScriptMultiplexValue {
|
|
424
|
+
/**
|
|
425
|
+
* Optional variable name to reference this value in the formula (e.g. "isOn").
|
|
426
|
+
* If empty, the value is referenced positionally as __0, __1, __2, ... (in listed order).
|
|
427
|
+
*/
|
|
428
|
+
varName?: string;
|
|
429
|
+
}
|
|
430
|
+
export interface If {
|
|
431
|
+
type: 'If';
|
|
432
|
+
/**
|
|
433
|
+
* Values referenced in the formula, either positionally as __0, __1, __2, ... (in listed
|
|
434
|
+
* order) or, if varName is set, by that name. Each entry works like Condition.value1
|
|
435
|
+
* (source: signal/property/elementProperty/signalInProperty/event/parameter/context/
|
|
436
|
+
* complexString/complexSignal/expression)
|
|
437
|
+
* @TJS-format signalList
|
|
438
|
+
*/
|
|
439
|
+
signals: IfSignal[];
|
|
440
|
+
/**
|
|
441
|
+
* Boolean formula, e.g. (__0 == true || __1 == true) && __2 == false
|
|
442
|
+
* @TJS-format formula
|
|
443
|
+
*/
|
|
444
|
+
formula: string;
|
|
445
|
+
/**
|
|
446
|
+
* Commands executed when the formula evaluates to true
|
|
447
|
+
*/
|
|
448
|
+
trueCommands: ScriptCommands[];
|
|
449
|
+
/**
|
|
450
|
+
* Commands executed when the formula evaluates to false
|
|
451
|
+
*/
|
|
452
|
+
elseCommands: ScriptCommands[];
|
|
453
|
+
additionalData?: string;
|
|
454
|
+
}
|
|
422
455
|
export interface Exit {
|
|
423
456
|
type: 'Exit';
|
|
424
457
|
additionalData?: string;
|
|
@@ -139,6 +139,11 @@ export const nativeScriptCommandDescriptions = {
|
|
|
139
139
|
example: '{ "type": "Condition", "value1": {"source":"signal","name":".Is.On"}, "value2": true,\n "comparisonType": "==", "trueGotoLabel": "lbl_off", "falseGotoLabel": "lbl_on" }',
|
|
140
140
|
note: 'comparisonType: ==null | !=null | ==true | ==false | == | != | > | < | >= | <= | && | ||.',
|
|
141
141
|
},
|
|
142
|
+
If: {
|
|
143
|
+
description: 'evaluate a formula and run nested commands depending on the result',
|
|
144
|
+
example: '{ "type": "If",\n "signals": [{"source":"signal","name":".Is.On"}, {"varName":"ready","source":"signal","name":".Is.Ready"}],\n "formula": "__0 == true && ready == false", "trueCommands": [], "elseCommands": [] }',
|
|
145
|
+
note: 'signals is a list of values (like Condition.value1). Each is referenced in the formula either positionally as __0, __1, ... or, if varName is set, by that name. trueCommands/elseCommands are edited as nested commands in the tree, not as JSON here.',
|
|
146
|
+
},
|
|
142
147
|
Exit: {
|
|
143
148
|
description: 'stop executing the current script chain',
|
|
144
149
|
example: '{ "type": "Exit" }',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VisualisationElementScript } from "../interfaces/VisualisationElementScript.js";
|
|
2
2
|
import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
|
|
3
|
-
import { ScriptCommands, signalTarget } from "./ScriptCommands.js";
|
|
3
|
+
import { If, ScriptCommands, signalTarget } from "./ScriptCommands.js";
|
|
4
4
|
export declare const cyclicAttributeName = "cyclic";
|
|
5
5
|
export type contextType = {
|
|
6
6
|
event: Event;
|
|
@@ -13,7 +13,7 @@ export declare class ScriptSystem {
|
|
|
13
13
|
_visualizationHandler: VisualizationHandler;
|
|
14
14
|
_subscriptionCallback: () => void;
|
|
15
15
|
constructor(visualizationHandler: VisualizationHandler);
|
|
16
|
-
execute(scriptCommands: ScriptCommands[], outerContext: contextType): Promise<
|
|
16
|
+
execute(scriptCommands: ScriptCommands[], outerContext: contextType): Promise<boolean>;
|
|
17
17
|
getValueFromTarget(target: signalTarget, name: string, context: contextType): Promise<any>;
|
|
18
18
|
setValueOnTarget(target: signalTarget, name: string, context: contextType, value: any): Promise<void>;
|
|
19
19
|
runExternalScript(name: string, type: string): Promise<void>;
|
|
@@ -23,6 +23,7 @@ export declare class ScriptSystem {
|
|
|
23
23
|
getValue<T>(value: T, outerContext: contextType): Promise<T>;
|
|
24
24
|
getStateOrFieldOrParameter(name: string, context: contextType): Promise<any>;
|
|
25
25
|
parseStringWithValues(text: string, context: contextType): Promise<string>;
|
|
26
|
+
evaluateIfFormula(command: If, outerContext: contextType): Promise<boolean>;
|
|
26
27
|
getSignalName(name: string, outerContext: contextType): string;
|
|
27
28
|
createScriptContext(root: HTMLElement, event: Event, element: Element, parameters: Record<string, any>, relativeSignalsPath: string): any;
|
|
28
29
|
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>;
|
|
@@ -22,6 +22,7 @@ export class ScriptSystem {
|
|
|
22
22
|
async execute(scriptCommands, outerContext) {
|
|
23
23
|
let repeatCount = -1;
|
|
24
24
|
let eventNotValid = false;
|
|
25
|
+
let stopped = false;
|
|
25
26
|
const triggerEvent = outerContext.event?.type;
|
|
26
27
|
const cancelEvent = triggerEvent ? eventOpposites[triggerEvent] : null;
|
|
27
28
|
if (cancelEvent) {
|
|
@@ -36,8 +37,18 @@ export class ScriptSystem {
|
|
|
36
37
|
for (let i = 0; i < scriptCommands.length; i++) {
|
|
37
38
|
let c = scriptCommands[i];
|
|
38
39
|
if (c.type == "Exit") {
|
|
40
|
+
stopped = true;
|
|
39
41
|
break;
|
|
40
42
|
}
|
|
43
|
+
else if (c.type == "If") {
|
|
44
|
+
const res = await this.evaluateIfFormula(c, outerContext);
|
|
45
|
+
const branchCommands = (res ? c.trueCommands : c.elseCommands) ?? [];
|
|
46
|
+
const shouldContinue = await this.execute(branchCommands, outerContext);
|
|
47
|
+
if (!shouldContinue) {
|
|
48
|
+
stopped = true;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
41
52
|
else if (c.type == "Goto") {
|
|
42
53
|
const label = await this.getValue(c.label, outerContext);
|
|
43
54
|
i = scriptCommands.findIndex(x => x.type == "Label" && x.label == label);
|
|
@@ -133,10 +144,12 @@ export class ScriptSystem {
|
|
|
133
144
|
else {
|
|
134
145
|
const continueScript = await this.runScriptCommand(c, outerContext);
|
|
135
146
|
if (!continueScript) {
|
|
147
|
+
stopped = true;
|
|
136
148
|
break;
|
|
137
149
|
}
|
|
138
150
|
}
|
|
139
151
|
}
|
|
152
|
+
return !stopped;
|
|
140
153
|
}
|
|
141
154
|
async getValueFromTarget(target, name, context) {
|
|
142
155
|
if (target === 'property') {
|
|
@@ -168,6 +181,7 @@ export class ScriptSystem {
|
|
|
168
181
|
case 'Comment':
|
|
169
182
|
case 'Label':
|
|
170
183
|
case 'Condition':
|
|
184
|
+
case 'If':
|
|
171
185
|
case 'Goto':
|
|
172
186
|
case 'Exit':
|
|
173
187
|
case 'Repeat':
|
|
@@ -514,6 +528,17 @@ export class ScriptSystem {
|
|
|
514
528
|
}
|
|
515
529
|
return nm;
|
|
516
530
|
}
|
|
531
|
+
async evaluateIfFormula(command, outerContext) {
|
|
532
|
+
const entries = command.signals ?? [];
|
|
533
|
+
const varNames = entries.map((e, i) => e.varName?.trim() || '__' + i);
|
|
534
|
+
const values = await Promise.all(entries.map(e => this.getValue(e, outerContext)));
|
|
535
|
+
const formula = await this.getValue(command.formula, outerContext);
|
|
536
|
+
if (!command.compiledFormula || command._compiledFormulaSrc !== formula) {
|
|
537
|
+
command.compiledFormula = new Function(...varNames, 'return (' + formula + ');');
|
|
538
|
+
command._compiledFormulaSrc = formula;
|
|
539
|
+
}
|
|
540
|
+
return !!command.compiledFormula(...values);
|
|
541
|
+
}
|
|
517
542
|
getSignalName(name, outerContext) {
|
|
518
543
|
if (name[0] === '.')
|
|
519
544
|
return outerContext.relativeSignalsPath + name;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ScriptCommands, SetElementProperty } from "./ScriptCommands";
|
|
2
2
|
export declare class ScriptUpgrades {
|
|
3
|
-
static upgradeScriptCommand(scriptCommand: ScriptCommands): import("./ScriptCommands").OpenScreen | import("./ScriptCommands").OpenUrl | import("./ScriptCommands").OpenDialog | import("./ScriptCommands").CloseDialog | import("./ScriptCommands").ToggleSignalValue | import("./ScriptCommands").ToggleSignalValueThroughList | 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").ClearSignalsInGroup | import("./ScriptCommands").RunScript | import("./ScriptCommands").CopySignalValuesFromFolder | import("./ScriptCommands").ShowMessageBox | import("./ScriptCommands").ShowPrompt | import("./ScriptCommands").ExportSignalValuesAsJson | import("./ScriptCommands").ImportSignalValuesFromJson | import("./ScriptCommands").Repeat | import("./ScriptCommands").Comment | import("./ScriptCommands").Condition | import("./ScriptCommands").Exit | import("./ScriptCommands").Label | import("./ScriptCommands").Goto;
|
|
3
|
+
static upgradeScriptCommand(scriptCommand: ScriptCommands): import("./ScriptCommands").OpenScreen | import("./ScriptCommands").OpenUrl | import("./ScriptCommands").OpenDialog | import("./ScriptCommands").CloseDialog | import("./ScriptCommands").ToggleSignalValue | import("./ScriptCommands").ToggleSignalValueThroughList | 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").ClearSignalsInGroup | import("./ScriptCommands").RunScript | import("./ScriptCommands").CopySignalValuesFromFolder | import("./ScriptCommands").ShowMessageBox | import("./ScriptCommands").ShowPrompt | import("./ScriptCommands").ExportSignalValuesAsJson | import("./ScriptCommands").ImportSignalValuesFromJson | import("./ScriptCommands").Repeat | import("./ScriptCommands").Comment | import("./ScriptCommands").Condition | import("./ScriptCommands").If | import("./ScriptCommands").Exit | import("./ScriptCommands").Label | import("./ScriptCommands").Goto;
|
|
4
4
|
static upgradeSetElementProperty(scriptCommand: SetElementProperty): SetElementProperty;
|
|
5
5
|
}
|
|
@@ -4,6 +4,10 @@ export class ScriptUpgrades {
|
|
|
4
4
|
if (scriptCommand.type === 'SetElementProperty') {
|
|
5
5
|
return ScriptUpgrades.upgradeSetElementProperty(scriptCommand);
|
|
6
6
|
}
|
|
7
|
+
if (scriptCommand.type === 'If') {
|
|
8
|
+
scriptCommand.trueCommands = (scriptCommand.trueCommands ?? []).map(c => ScriptUpgrades.upgradeScriptCommand(c));
|
|
9
|
+
scriptCommand.elseCommands = (scriptCommand.elseCommands ?? []).map(c => ScriptUpgrades.upgradeScriptCommand(c));
|
|
10
|
+
}
|
|
7
11
|
return scriptCommand;
|
|
8
12
|
}
|
|
9
13
|
static upgradeSetElementProperty(scriptCommand) {
|
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.
|
|
4
|
+
"version": "0.1.147",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|