@node-projects/web-component-designer-visualization-addons 0.1.14 → 0.1.17
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 +4 -2
- package/dist/blockly/components/GetParameter.js +1 -1
- package/dist/components/EventAssignment.d.ts +3 -2
- package/dist/components/EventAssignment.js +22 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/scripting/ScriptSystem.js +13 -1
- package/dist/services/ScriptRefactorService.js +7 -0
- 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) => void>;
|
|
2
|
+
export declare function generateEventCodeFromBlockly(data: any): Promise<(event: Event, shadowRoot: ShadowRoot, parameters: Record<string, any>) => void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//import Blockly from 'blockly';
|
|
2
2
|
import './components/components.js';
|
|
3
3
|
//TODO: remove imports, only leave Runtime
|
|
4
|
-
const prefix = `function extractPart(obj
|
|
4
|
+
const prefix = `function extractPart(obj, propertyPath) {
|
|
5
5
|
let retVal = obj;
|
|
6
6
|
for (let p of propertyPath.split('.')) {
|
|
7
7
|
retVal = retVal?.[p];
|
|
@@ -9,7 +9,7 @@ const prefix = `function extractPart(obj: any, propertyPath: string) {
|
|
|
9
9
|
return retVal;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export async function run(eventData, shadowRoot) {
|
|
12
|
+
export async function run(eventData, shadowRoot, parameters) {
|
|
13
13
|
`;
|
|
14
14
|
const postfix = `}`;
|
|
15
15
|
export async function generateEventCodeFromBlockly(data) {
|
|
@@ -24,6 +24,8 @@ export async function generateEventCodeFromBlockly(data) {
|
|
|
24
24
|
//@ts-ignore
|
|
25
25
|
Blockly.JavaScript.addReservedWords('extractPart');
|
|
26
26
|
//@ts-ignore
|
|
27
|
+
Blockly.JavaScript.addReservedWords('parameters');
|
|
28
|
+
//@ts-ignore
|
|
27
29
|
Blockly.JavaScript.addReservedWords('IOB');
|
|
28
30
|
//@ts-ignore
|
|
29
31
|
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 =
|
|
18
|
+
const code = `parameters[${name}]`;
|
|
19
19
|
//@ts-ignore
|
|
20
20
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
|
21
21
|
};
|
|
@@ -6,7 +6,7 @@ type scriptType = 'jsdirect' | 'js' | 'script' | 'blockly' | 'none';
|
|
|
6
6
|
export declare class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
7
7
|
static style: CSSStyleSheet;
|
|
8
8
|
static template: HTMLTemplateElement;
|
|
9
|
-
static
|
|
9
|
+
static editRowTemplate: HTMLTemplateElement;
|
|
10
10
|
static scriptTypeColors: {
|
|
11
11
|
js: string;
|
|
12
12
|
blockly: string;
|
|
@@ -25,7 +25,8 @@ export declare class EventAssignment extends BaseCustomWebComponentConstructorAp
|
|
|
25
25
|
events: IEvent[];
|
|
26
26
|
initialize(visualizationHandler: VisualizationHandler, visualizationShell: VisualizationShell, scriptCommandsTypeInfo: any, propertiesTypeInfo: any): void;
|
|
27
27
|
set instanceServiceContainer(value: InstanceServiceContainer);
|
|
28
|
-
protected _createControlsForScript(eventItem: IEvent):
|
|
28
|
+
protected _createControlsForScript(eventItem: IEvent): any;
|
|
29
|
+
protected _hasParameters(eventItem: IEvent): boolean;
|
|
29
30
|
protected _getScriptTypeColor(eventItem: IEvent): any;
|
|
30
31
|
protected _getScriptType(eventItem: IEvent): scriptType;
|
|
31
32
|
protected _getEventMethodname(eventItem: IEvent): string;
|
|
@@ -25,6 +25,9 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
25
25
|
width: 100%;
|
|
26
26
|
box-sizing: border-box;
|
|
27
27
|
}
|
|
28
|
+
input::placeholder {
|
|
29
|
+
font-size: 8px;
|
|
30
|
+
}
|
|
28
31
|
a {
|
|
29
32
|
cursor: pointer;
|
|
30
33
|
}
|
|
@@ -38,17 +41,17 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
38
41
|
static template = html `
|
|
39
42
|
<template repeat:item="[[this.events]]">
|
|
40
43
|
<div @click="[[this._ctxMenu(event, item)]]" @contextmenu="[[this._ctxMenu(event, item)]]" class="rect" css:background-color="[[this._getScriptTypeColor(item)]]"></div>
|
|
41
|
-
<a @click="[[this._showContextMenuAssignScript(event, item, false)]]" title="[[item.name]]">[[item.name]]</a>
|
|
44
|
+
<a @click="[[this._showContextMenuAssignScript(event, item, false)]]" @contextmenu="[[this._ctxMenu(event, item)]]" title="[[item.name]]">[[item.name]]</a>
|
|
42
45
|
<div>[[this._createControlsForScript(item)]]</div>
|
|
43
46
|
</template>
|
|
44
47
|
<span style="grid-column: 1 / span 3; margin-top: 8px; margin-left: 3px;">add event:</span>
|
|
45
48
|
<input id="addEventInput" style="grid-column: 1 / span 3; margin: 5px;" @keypress=[[this._addEvent(event)]] type="text">`;
|
|
46
|
-
static
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
static editRowTemplate = html `
|
|
50
|
+
<div style="display: flex; justify-content: flex-end;">
|
|
51
|
+
<input hidden="[[this._getScriptType(item) !== 'js']]" placeholder="name" title="name" style="min-width: 50px; flex-basis: 30px; flex-grow: 2;" class="mth" type="text">
|
|
52
|
+
<input placeholder="relative signals path" title="relative signals path" style="min-width: 50px; flex-basis: 20px; flex-grow: 1;" class="mth" type="text">
|
|
53
|
+
<button css:background="[[this._hasParameters(item) ? 'lime' : '']]" style="display: flex; padding: 0; flex-grow: 0;" title="parameter" @click="[[this._editParameter(event, item)]]">p</button>
|
|
54
|
+
</div>`;
|
|
52
55
|
static scriptTypeColors = {
|
|
53
56
|
'js': 'purple',
|
|
54
57
|
'blockly': 'yellow',
|
|
@@ -90,9 +93,17 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
90
93
|
case 'none':
|
|
91
94
|
return '';
|
|
92
95
|
}
|
|
93
|
-
|
|
96
|
+
//@ts-ignore
|
|
97
|
+
const ctl = this.constructor.editRowTemplate.content.cloneNode(true);
|
|
94
98
|
return ctl;
|
|
95
99
|
}
|
|
100
|
+
_hasParameters(eventItem) {
|
|
101
|
+
if (this.selectedItems[0].hasAttribute('@' + eventItem.name)) {
|
|
102
|
+
const val = this.selectedItems[0].getAttribute('@' + eventItem.name);
|
|
103
|
+
return val.includes('parameters');
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
96
107
|
_getScriptTypeColor(eventItem) {
|
|
97
108
|
const st = this._getScriptType(eventItem);
|
|
98
109
|
const color = EventAssignment.scriptTypeColors[st];
|
|
@@ -215,8 +226,11 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
|
215
226
|
newObj = JSON.parse(data);
|
|
216
227
|
newObj.parameters = par;
|
|
217
228
|
}
|
|
229
|
+
if (par == null)
|
|
230
|
+
delete newObj.parameters;
|
|
218
231
|
const newData = JSON.stringify(newObj);
|
|
219
232
|
this._selectedItems[0].setAttribute('@' + eventItem.name, newData);
|
|
233
|
+
this._bindingsRefresh();
|
|
220
234
|
}
|
|
221
235
|
}
|
|
222
236
|
async _editBlockly(e, eventItem) {
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './components/BindingsEditorHistoric.js';
|
|
|
7
7
|
export * from './components/SimpleScriptEditor.js';
|
|
8
8
|
export * from './components/VisualizationPropertyGrid.js';
|
|
9
9
|
export * from './components/ParameterEditor.js';
|
|
10
|
+
export * from './components/EventAssignment.js';
|
|
10
11
|
export * from './helpers/BindingsHelper.js';
|
|
11
12
|
export * from './interfaces/IScriptMultiplexValue.js';
|
|
12
13
|
export * from './interfaces/VisualisationElementScript.js';
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from './components/BindingsEditorHistoric.js';
|
|
|
7
7
|
export * from './components/SimpleScriptEditor.js';
|
|
8
8
|
export * from './components/VisualizationPropertyGrid.js';
|
|
9
9
|
export * from './components/ParameterEditor.js';
|
|
10
|
+
export * from './components/EventAssignment.js';
|
|
10
11
|
export * from './helpers/BindingsHelper.js';
|
|
11
12
|
export * from './interfaces/IScriptMultiplexValue.js';
|
|
12
13
|
export * from './interfaces/VisualisationElementScript.js';
|
|
@@ -192,12 +192,24 @@ export class ScriptSystem {
|
|
|
192
192
|
e.addEventListener(evtName, async (evt) => {
|
|
193
193
|
if (!compiledFunc)
|
|
194
194
|
compiledFunc = await generateEventCodeFromBlockly(scriptObj);
|
|
195
|
-
compiledFunc(evt, shadowRoot);
|
|
195
|
+
compiledFunc(evt, shadowRoot, scriptObj.parameters);
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
else {
|
|
199
199
|
if (assignExternalScript)
|
|
200
200
|
assignExternalScript(e, evtName, scriptObj);
|
|
201
|
+
else {
|
|
202
|
+
if ('name' in scriptObj) {
|
|
203
|
+
//@ts-ignore
|
|
204
|
+
const nm = scriptObj.name;
|
|
205
|
+
e.addEventListener(evtName, (evt) => {
|
|
206
|
+
if (!jsObject[nm])
|
|
207
|
+
console.warn('javascript function named: ' + nm + ' not found, maybe missing a "export" ?');
|
|
208
|
+
else
|
|
209
|
+
jsObject[nm](evt, e, shadowRoot, instance, scriptObj.parameters);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
201
213
|
}
|
|
202
214
|
}
|
|
203
215
|
else {
|
|
@@ -65,6 +65,13 @@ export class ScriptRefactorService {
|
|
|
65
65
|
}
|
|
66
66
|
else if ('blocks' in script) {
|
|
67
67
|
}
|
|
68
|
+
if ('parameters' in script) {
|
|
69
|
+
for (let p in script.parameters) {
|
|
70
|
+
if (typeof script.parameters[p] === 'string') {
|
|
71
|
+
refactorings.push({ name: script.parameters[p], itemType: 'parameter', target: BindingTarget.event, targetName: a[0], service: this, designItem: d, type: 'script', sourceObject: script, display: 'parameters/' + p, refactor: newValue => script.parameters[p] = newValue });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
77
|
}
|
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.17",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|