@node-projects/web-component-designer-visualization-addons 0.1.20 → 0.1.22
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/blockly/BlocklyJavascriptHelper.d.ts +1 -1
- package/dist/blockly/BlocklyJavascriptHelper.js +3 -1
- package/dist/blockly/components/GetParameter.js +1 -1
- package/dist/blockly/components/GetState.js +1 -1
- package/dist/blockly/components/SetState.js +1 -1
- package/dist/blockly/components/components.d.ts +0 -1
- package/dist/blockly/components/components.js +0 -1
- package/dist/components/EventAssignment.js +12 -0
- package/dist/interfaces/IScriptMultiplexValue.d.ts +3 -1
- package/dist/interfaces/IScriptMultiplexValue.js +2 -0
- package/dist/scripting/ScriptSystem.d.ts +3 -2
- package/dist/scripting/ScriptSystem.js +38 -10
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './components/components.js';
|
|
2
|
-
export declare function generateEventCodeFromBlockly(data: any): Promise<(event: Event, shadowRoot: ShadowRoot, parameters: Record<string, any
|
|
2
|
+
export declare function generateEventCodeFromBlockly(data: any): Promise<(event: Event, shadowRoot: ShadowRoot, parameters: Record<string, any>, relativeSignalsPath: string) => void>;
|
|
@@ -9,7 +9,7 @@ const prefix = `function extractPart(obj, propertyPath) {
|
|
|
9
9
|
return retVal;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export async function run(eventData, shadowRoot, parameters) {
|
|
12
|
+
export async function run(eventData, shadowRoot, parameters, relativeSignalsPath) {
|
|
13
13
|
`;
|
|
14
14
|
const postfix = `}`;
|
|
15
15
|
export async function generateEventCodeFromBlockly(data) {
|
|
@@ -26,6 +26,8 @@ export async function generateEventCodeFromBlockly(data) {
|
|
|
26
26
|
//@ts-ignore
|
|
27
27
|
Blockly.JavaScript.addReservedWords('parameters');
|
|
28
28
|
//@ts-ignore
|
|
29
|
+
Blockly.JavaScript.addReservedWords('relativeSignalsPath');
|
|
30
|
+
//@ts-ignore
|
|
29
31
|
Blockly.JavaScript.addReservedWords('IOB');
|
|
30
32
|
//@ts-ignore
|
|
31
33
|
Blockly.JavaScript.addReservedWords('RUNTIME');
|
|
@@ -15,7 +15,7 @@ Blockly.Blocks['get_parameter'] = {
|
|
|
15
15
|
Blockly.JavaScript['get_parameter'] = function (block, generator) {
|
|
16
16
|
//@ts-ignore
|
|
17
17
|
const name = Blockly.JavaScript.valueToCode(block, 'NAME', Blockly.JavaScript.ORDER_ATOMIC);
|
|
18
|
-
const code = `parameters[${name}]`;
|
|
18
|
+
const code = `context.parameters[${name}]`;
|
|
19
19
|
//@ts-ignore
|
|
20
20
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
|
21
21
|
};
|
|
@@ -15,7 +15,7 @@ Blockly.Blocks['get_state'] = {
|
|
|
15
15
|
Blockly.JavaScript['get_state'] = function (block, generator) {
|
|
16
16
|
//@ts-ignore
|
|
17
17
|
const id = Blockly.JavaScript.valueToCode(block, 'OID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
18
|
-
const code = `(await IOB.getState(${id})).val`;
|
|
18
|
+
const code = `(await IOB.getState((${id}[0] === '.' ? relativeSignalsPath : '') + ${id})).val`;
|
|
19
19
|
//@ts-ignore
|
|
20
20
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
|
21
21
|
};
|
|
@@ -21,6 +21,6 @@ Blockly.JavaScript['set_state'] = function (block) {
|
|
|
21
21
|
const id = Blockly.JavaScript.valueToCode(block, 'OID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
22
22
|
//@ts-ignore
|
|
23
23
|
const value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_ATOMIC);
|
|
24
|
-
const code = `await IOB.setState(${id}, ${value});\n`;
|
|
24
|
+
const code = `await IOB.setState((${id}[0] === '.' ? relativeSignalsPath : '') + ${id}, ${value});\n`;
|
|
25
25
|
return code;
|
|
26
26
|
};
|
|
@@ -300,9 +300,11 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
300
300
|
edt.title = "Blockly Script for '" + eventItem.name + "' of '" + this._selectedItems[0].name + "'";
|
|
301
301
|
let data = this._selectedItems[0].getAttribute('@' + eventItem.name);
|
|
302
302
|
let parameters = null;
|
|
303
|
+
let relativeSignalsPath = null;
|
|
303
304
|
if (data) {
|
|
304
305
|
const parsed = JSON.parse(data);
|
|
305
306
|
parameters = parsed.parameters;
|
|
307
|
+
relativeSignalsPath = parsed.relativeSignalsPath;
|
|
306
308
|
edt.load(parsed);
|
|
307
309
|
}
|
|
308
310
|
const result = await this._visualizationShell.openConfirmation(edt, { x: 100, y: 100, width: 700, height: 500 });
|
|
@@ -311,6 +313,9 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
311
313
|
if (parameters) {
|
|
312
314
|
blockObj.parameters = parameters;
|
|
313
315
|
}
|
|
316
|
+
if (relativeSignalsPath) {
|
|
317
|
+
blockObj.relativeSignalsPath = relativeSignalsPath;
|
|
318
|
+
}
|
|
314
319
|
this._selectedItems[0].setAttribute('@' + eventItem.name, JSON.stringify(blockObj));
|
|
315
320
|
this._bindingsRefresh();
|
|
316
321
|
}
|
|
@@ -323,10 +328,13 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
323
328
|
if (!scriptString || scriptString.startsWith('{')) {
|
|
324
329
|
let script = { commands: [] };
|
|
325
330
|
let parameters = null;
|
|
331
|
+
let relativeSignalsPath = null;
|
|
326
332
|
if (scriptString) {
|
|
327
333
|
script = JSON.parse(scriptString);
|
|
328
334
|
//@ts-ignore
|
|
329
335
|
parameters = script.parameters;
|
|
336
|
+
//@ts-ignore
|
|
337
|
+
relativeSignalsPath = script.relativeSignalsPath;
|
|
330
338
|
}
|
|
331
339
|
let sc = new SimpleScriptEditor();
|
|
332
340
|
sc.serviceContainer = this.selectedItems[0].serviceContainer;
|
|
@@ -345,6 +353,10 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
345
353
|
//@ts-ignore
|
|
346
354
|
sc.parameters = parameters;
|
|
347
355
|
}
|
|
356
|
+
if (relativeSignalsPath) {
|
|
357
|
+
//@ts-ignore
|
|
358
|
+
sc.relativeSignalsPath = relativeSignalsPath;
|
|
359
|
+
}
|
|
348
360
|
let json = JSON.stringify(sc);
|
|
349
361
|
this.selectedItems[0].setAttribute('@' + eventItem.name, json);
|
|
350
362
|
this._bindingsRefresh();
|
|
@@ -4,8 +4,10 @@ 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
|
+
* complexString - a string with signals (contained in {})
|
|
8
|
+
* complexSignal - read the value from a signal wich name is build here (it can contain other signals in {})
|
|
7
9
|
*/
|
|
8
|
-
source: 'signal' | 'property' | 'event' | 'parameter';
|
|
10
|
+
source: 'signal' | 'property' | 'event' | 'parameter' | 'complexString' | 'complexSignal';
|
|
9
11
|
/**
|
|
10
12
|
* Name of the ioBroker object or the property of the component or the parameter of the script
|
|
11
13
|
* or for example in a event : srcElement.value to get the value of a input wich raises the event
|
|
@@ -4,6 +4,8 @@ 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
|
+
* complexString - a string with signals (contained in {})
|
|
8
|
+
* complexSignal - read the value from a signal wich name is build here (it can contain other signals in {})
|
|
7
9
|
*/
|
|
8
10
|
source;
|
|
9
11
|
/**
|
|
@@ -2,7 +2,7 @@ import { IScriptMultiplexValue } from "../interfaces/IScriptMultiplexValue.js";
|
|
|
2
2
|
import { VisualisationElementScript } from "../interfaces/VisualisationElementScript.js";
|
|
3
3
|
import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
|
|
4
4
|
import { ScriptCommands } from "./ScriptCommands.js";
|
|
5
|
-
type contextType = {
|
|
5
|
+
export type contextType = {
|
|
6
6
|
event: Event;
|
|
7
7
|
element: Element;
|
|
8
8
|
root: HTMLElement;
|
|
@@ -15,8 +15,9 @@ export declare class ScriptSystem {
|
|
|
15
15
|
execute(scriptCommands: ScriptCommands[], outerContext: contextType): Promise<void>;
|
|
16
16
|
runScriptCommand<T extends ScriptCommands>(command: T, context: contextType): Promise<void>;
|
|
17
17
|
getValue<T>(value: string | number | boolean | IScriptMultiplexValue, outerContext: contextType): Promise<any>;
|
|
18
|
+
getStateOrFieldOrParameter(name: string, context: contextType): Promise<any>;
|
|
19
|
+
parseStringWithValues(text: string, context: contextType): Promise<string>;
|
|
18
20
|
getSignaName(name: string, outerContext: contextType): string;
|
|
19
21
|
static extractPart(obj: any, propertyPath: string): any;
|
|
20
22
|
assignAllScripts(source: string, javascriptCode: string, shadowRoot: ShadowRoot, instance: HTMLElement, assignExternalScript?: (element: Element, event: string, scriptData: any) => void): Promise<VisualisationElementScript>;
|
|
21
23
|
}
|
|
22
|
-
export {};
|
|
@@ -55,15 +55,7 @@ export class ScriptSystem {
|
|
|
55
55
|
case 'CalculateSignalValue': {
|
|
56
56
|
const formula = await this.getValue(command.formula, context);
|
|
57
57
|
const targetSignal = await this.getValue(command.targetSignal, context);
|
|
58
|
-
let
|
|
59
|
-
let results = await Promise.all(parsed.signals.map(x => this._visualizationHandler.getState(this.getSignaName(x, context))));
|
|
60
|
-
let nm = '';
|
|
61
|
-
for (let i = 0; i < parsed.parts.length - 1; i++) {
|
|
62
|
-
let v = results[i].val;
|
|
63
|
-
if (v == null)
|
|
64
|
-
return;
|
|
65
|
-
nm += v + parsed.parts[i + 1];
|
|
66
|
-
}
|
|
58
|
+
let nm = await this.parseStringWithValues(formula, context);
|
|
67
59
|
let result = eval(nm);
|
|
68
60
|
await this._visualizationHandler.setState(this.getSignaName(targetSignal, context), result);
|
|
69
61
|
break;
|
|
@@ -150,10 +142,46 @@ export class ScriptSystem {
|
|
|
150
142
|
case 'parameter': {
|
|
151
143
|
return outerContext.parameters[value.name];
|
|
152
144
|
}
|
|
145
|
+
case 'complexString': {
|
|
146
|
+
let text = value.name;
|
|
147
|
+
if (text != null) {
|
|
148
|
+
return await this.parseStringWithValues(text, outerContext);
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
case 'complexSignal': {
|
|
153
|
+
let text = value.name;
|
|
154
|
+
if (text != null) {
|
|
155
|
+
const signal = await this.parseStringWithValues(text, outerContext);
|
|
156
|
+
return await this._visualizationHandler.getState(this.getSignaName(signal, outerContext));
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
return value;
|
|
156
163
|
}
|
|
164
|
+
async getStateOrFieldOrParameter(name, context) {
|
|
165
|
+
//use same shortcuts as in bindings. $ = signals object, § = access context
|
|
166
|
+
if (name[0] === '§') {
|
|
167
|
+
//@ts-ignore
|
|
168
|
+
var ctx = context;
|
|
169
|
+
return eval('ctx.' + name.substring(1));
|
|
170
|
+
}
|
|
171
|
+
return await this._visualizationHandler.getState(this.getSignaName(name, context));
|
|
172
|
+
}
|
|
173
|
+
async parseStringWithValues(text, context) {
|
|
174
|
+
const parsed = parseBindingString(text);
|
|
175
|
+
let results = await Promise.all(parsed.signals.map(x => this.getStateOrFieldOrParameter(this.getSignaName(x, context), context)));
|
|
176
|
+
let nm = '';
|
|
177
|
+
for (let i = 0; i < parsed.parts.length - 1; i++) {
|
|
178
|
+
let v = results[i].val;
|
|
179
|
+
if (v == null)
|
|
180
|
+
v = '';
|
|
181
|
+
nm += v + parsed.parts[i + 1];
|
|
182
|
+
}
|
|
183
|
+
return nm;
|
|
184
|
+
}
|
|
157
185
|
getSignaName(name, outerContext) {
|
|
158
186
|
if (name[0] === '.')
|
|
159
187
|
return outerContext.relativeSignalsPath + name;
|
|
@@ -197,7 +225,7 @@ export class ScriptSystem {
|
|
|
197
225
|
e.addEventListener(evtName, async (evt) => {
|
|
198
226
|
if (!compiledFunc)
|
|
199
227
|
compiledFunc = await generateEventCodeFromBlockly(scriptObj);
|
|
200
|
-
compiledFunc(evt, shadowRoot, scriptObj.parameters);
|
|
228
|
+
compiledFunc(evt, shadowRoot, scriptObj.parameters, scriptObj.relativeSignalsPath ?? '');
|
|
201
229
|
});
|
|
202
230
|
}
|
|
203
231
|
else {
|
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.22",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|