@node-projects/web-component-designer-visualization-addons 0.1.20 → 0.1.21
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/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 +2 -0
- package/dist/scripting/ScriptSystem.js +37 -9
- package/package.json +1 -1
|
@@ -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
|
/**
|
|
@@ -15,6 +15,8 @@ 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>;
|
|
@@ -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;
|
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.21",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|