@node-projects/web-component-designer-visualization-addons 0.1.13 → 0.1.15
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/BlocklyToolbox.d.ts +8 -8
- package/dist/blockly/BlocklyToolbox.js +14 -0
- package/dist/blockly/components/GetParameter.d.ts +0 -0
- package/dist/blockly/components/GetParameter.js +21 -0
- package/dist/blockly/components/components.d.ts +1 -0
- package/dist/blockly/components/components.js +1 -0
- package/dist/components/EventAssignment.d.ts +47 -0
- package/dist/components/EventAssignment.js +323 -0
- package/dist/components/ParameterEditor.d.ts +17 -0
- package/dist/components/ParameterEditor.js +86 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/interfaces/IScriptMultiplexValue.d.ts +4 -3
- package/dist/interfaces/IScriptMultiplexValue.js +3 -2
- package/dist/scripting/Script.d.ts +1 -0
- package/dist/scripting/Script.js +1 -0
- package/dist/scripting/ScriptSystem.d.ts +10 -11
- package/dist/scripting/ScriptSystem.js +4 -1
- package/dist/services/ScriptRefactorService.js +7 -0
- package/package.json +1 -1
|
@@ -22,9 +22,9 @@ declare const _default: {
|
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
OID?: undefined;
|
|
25
|
+
NAME?: undefined;
|
|
25
26
|
PROPERTYPATH?: undefined;
|
|
26
27
|
SELECTOR?: undefined;
|
|
27
|
-
NAME?: undefined;
|
|
28
28
|
};
|
|
29
29
|
} | {
|
|
30
30
|
kind: string;
|
|
@@ -39,15 +39,15 @@ declare const _default: {
|
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
SCREEN?: undefined;
|
|
42
|
+
NAME?: undefined;
|
|
42
43
|
PROPERTYPATH?: undefined;
|
|
43
44
|
SELECTOR?: undefined;
|
|
44
|
-
NAME?: undefined;
|
|
45
45
|
};
|
|
46
46
|
} | {
|
|
47
47
|
kind: string;
|
|
48
48
|
type: string;
|
|
49
49
|
inputs: {
|
|
50
|
-
|
|
50
|
+
NAME: {
|
|
51
51
|
shadow: {
|
|
52
52
|
type: string;
|
|
53
53
|
fields: {
|
|
@@ -57,14 +57,14 @@ declare const _default: {
|
|
|
57
57
|
};
|
|
58
58
|
SCREEN?: undefined;
|
|
59
59
|
OID?: undefined;
|
|
60
|
+
PROPERTYPATH?: undefined;
|
|
60
61
|
SELECTOR?: undefined;
|
|
61
|
-
NAME?: undefined;
|
|
62
62
|
};
|
|
63
63
|
} | {
|
|
64
64
|
kind: string;
|
|
65
65
|
type: string;
|
|
66
66
|
inputs: {
|
|
67
|
-
|
|
67
|
+
PROPERTYPATH: {
|
|
68
68
|
shadow: {
|
|
69
69
|
type: string;
|
|
70
70
|
fields: {
|
|
@@ -74,14 +74,14 @@ declare const _default: {
|
|
|
74
74
|
};
|
|
75
75
|
SCREEN?: undefined;
|
|
76
76
|
OID?: undefined;
|
|
77
|
-
PROPERTYPATH?: undefined;
|
|
78
77
|
NAME?: undefined;
|
|
78
|
+
SELECTOR?: undefined;
|
|
79
79
|
};
|
|
80
80
|
} | {
|
|
81
81
|
kind: string;
|
|
82
82
|
type: string;
|
|
83
83
|
inputs: {
|
|
84
|
-
|
|
84
|
+
SELECTOR: {
|
|
85
85
|
shadow: {
|
|
86
86
|
type: string;
|
|
87
87
|
fields: {
|
|
@@ -91,8 +91,8 @@ declare const _default: {
|
|
|
91
91
|
};
|
|
92
92
|
SCREEN?: undefined;
|
|
93
93
|
OID?: undefined;
|
|
94
|
+
NAME?: undefined;
|
|
94
95
|
PROPERTYPATH?: undefined;
|
|
95
|
-
SELECTOR?: undefined;
|
|
96
96
|
};
|
|
97
97
|
})[];
|
|
98
98
|
custom?: undefined;
|
|
@@ -70,6 +70,20 @@ export default {
|
|
|
70
70
|
},
|
|
71
71
|
},
|
|
72
72
|
},
|
|
73
|
+
{
|
|
74
|
+
kind: 'block',
|
|
75
|
+
type: 'get_parameter',
|
|
76
|
+
inputs: {
|
|
77
|
+
NAME: {
|
|
78
|
+
shadow: {
|
|
79
|
+
type: 'text',
|
|
80
|
+
fields: {
|
|
81
|
+
TEXT: '',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
73
87
|
{
|
|
74
88
|
kind: 'block',
|
|
75
89
|
type: 'get_sub_property',
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//@ts-ignore
|
|
3
|
+
Blockly.Blocks['get_parameter'] = {
|
|
4
|
+
init: function () {
|
|
5
|
+
this.appendValueInput('NAME')
|
|
6
|
+
.setCheck("String")
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
.appendField('get_parameter');
|
|
9
|
+
this.setInputsInline(true);
|
|
10
|
+
this.setOutput(true, null);
|
|
11
|
+
this.setColour(230);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
Blockly.JavaScript['get_parameter'] = function (block, generator) {
|
|
16
|
+
//@ts-ignore
|
|
17
|
+
const name = Blockly.JavaScript.valueToCode(block, 'NAME', Blockly.JavaScript.ORDER_ATOMIC);
|
|
18
|
+
const code = `${name}`;
|
|
19
|
+
//@ts-ignore
|
|
20
|
+
return [code, Blockly.JavaScript.ORDER_NONE];
|
|
21
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
import { IContextMenuItem, IDesignItem, IEvent, InstanceServiceContainer } from "@node-projects/web-component-designer";
|
|
3
|
+
import { VisualizationShell } from "../interfaces/VisualizationShell.js";
|
|
4
|
+
import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
|
|
5
|
+
type scriptType = 'jsdirect' | 'js' | 'script' | 'blockly' | 'none';
|
|
6
|
+
export declare class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
7
|
+
static style: CSSStyleSheet;
|
|
8
|
+
static template: HTMLTemplateElement;
|
|
9
|
+
static editRowTemplate: HTMLTemplateElement;
|
|
10
|
+
static scriptTypeColors: {
|
|
11
|
+
js: string;
|
|
12
|
+
blockly: string;
|
|
13
|
+
script: string;
|
|
14
|
+
};
|
|
15
|
+
static readonly is = "node-projects-visualization-event-assignment";
|
|
16
|
+
constructor();
|
|
17
|
+
ready(): void;
|
|
18
|
+
private _instanceServiceContainer;
|
|
19
|
+
private _selectionChangedHandler;
|
|
20
|
+
private _selectedItems;
|
|
21
|
+
private _visualizationHandler;
|
|
22
|
+
private _visualizationShell;
|
|
23
|
+
private _scriptCommandsTypeInfo;
|
|
24
|
+
private _propertiesTypeInfo;
|
|
25
|
+
events: IEvent[];
|
|
26
|
+
initialize(visualizationHandler: VisualizationHandler, visualizationShell: VisualizationShell, scriptCommandsTypeInfo: any, propertiesTypeInfo: any): void;
|
|
27
|
+
set instanceServiceContainer(value: InstanceServiceContainer);
|
|
28
|
+
protected _createControlsForScript(eventItem: IEvent): any;
|
|
29
|
+
protected _hasParameters(eventItem: IEvent): boolean;
|
|
30
|
+
protected _getScriptTypeColor(eventItem: IEvent): any;
|
|
31
|
+
protected _getScriptType(eventItem: IEvent): scriptType;
|
|
32
|
+
protected _getEventMethodname(eventItem: IEvent): string;
|
|
33
|
+
protected _inputMthName(event: InputEvent, eventItem: IEvent): void;
|
|
34
|
+
protected _ctxMenu(e: MouseEvent, eventItem: IEvent): void;
|
|
35
|
+
protected _addEvent(e: KeyboardEvent): Promise<void>;
|
|
36
|
+
protected _createAssignScriptContextMenu(event: MouseEvent, eventItem: IEvent): IContextMenuItem[];
|
|
37
|
+
protected _showContextMenuAssignScript(event: MouseEvent, eventItem: IEvent, isCtxMenu: boolean): Promise<void>;
|
|
38
|
+
protected _editParameter(e: MouseEvent, eventItem: IEvent): Promise<void>;
|
|
39
|
+
protected _editBlockly(e: MouseEvent, eventItem: IEvent): Promise<void>;
|
|
40
|
+
protected _editJavascript(e: MouseEvent, eventItem: IEvent): Promise<void>;
|
|
41
|
+
protected _editSimpleScript(e: MouseEvent, eventItem: IEvent): Promise<void>;
|
|
42
|
+
_editEvent(evtType: scriptType, e: MouseEvent, eventItem: IEvent): Promise<void>;
|
|
43
|
+
refresh(): void;
|
|
44
|
+
get selectedItems(): IDesignItem[];
|
|
45
|
+
set selectedItems(items: IDesignItem[]);
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
import { ContextMenu, PropertiesHelper } from "@node-projects/web-component-designer";
|
|
3
|
+
import { ParameterEditor } from "./ParameterEditor.js";
|
|
4
|
+
import { BlocklyScriptEditor } from "../blockly/BlocklyScriptEditor.js";
|
|
5
|
+
import { SimpleScriptEditor } from "./SimpleScriptEditor.js";
|
|
6
|
+
export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
|
|
7
|
+
static style = css `
|
|
8
|
+
:host {
|
|
9
|
+
display: grid;
|
|
10
|
+
grid-template-columns: 20px 1fr auto;
|
|
11
|
+
overflow-y: auto;
|
|
12
|
+
align-content: start;
|
|
13
|
+
height: 100%;
|
|
14
|
+
}
|
|
15
|
+
.rect {
|
|
16
|
+
width: 7px;
|
|
17
|
+
height: 7px;
|
|
18
|
+
border: 1px solid black;
|
|
19
|
+
justify-self: center;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
align-self: center;
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
}
|
|
24
|
+
input.mth {
|
|
25
|
+
width: 100%;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
}
|
|
28
|
+
input::placeholder {
|
|
29
|
+
font-size: 8px;
|
|
30
|
+
}
|
|
31
|
+
a {
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
}
|
|
34
|
+
a:hover {
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
text-decoration: underline;
|
|
37
|
+
}
|
|
38
|
+
button {
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
}`;
|
|
41
|
+
static template = html `
|
|
42
|
+
<template repeat:item="[[this.events]]">
|
|
43
|
+
<div @click="[[this._ctxMenu(event, item)]]" @contextmenu="[[this._ctxMenu(event, item)]]" class="rect" css:background-color="[[this._getScriptTypeColor(item)]]"></div>
|
|
44
|
+
<a @click="[[this._showContextMenuAssignScript(event, item, false)]]" title="[[item.name]]">[[item.name]]</a>
|
|
45
|
+
<div>[[this._createControlsForScript(item)]]</div>
|
|
46
|
+
</template>
|
|
47
|
+
<span style="grid-column: 1 / span 3; margin-top: 8px; margin-left: 3px;">add event:</span>
|
|
48
|
+
<input id="addEventInput" style="grid-column: 1 / span 3; margin: 5px;" @keypress=[[this._addEvent(event)]] type="text">`;
|
|
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>`;
|
|
55
|
+
static scriptTypeColors = {
|
|
56
|
+
'js': 'purple',
|
|
57
|
+
'blockly': 'yellow',
|
|
58
|
+
'script': 'lightgreen'
|
|
59
|
+
};
|
|
60
|
+
static is = 'node-projects-visualization-event-assignment';
|
|
61
|
+
constructor() {
|
|
62
|
+
super();
|
|
63
|
+
this._restoreCachedInititalValues();
|
|
64
|
+
}
|
|
65
|
+
ready() {
|
|
66
|
+
this._bindingsParse();
|
|
67
|
+
}
|
|
68
|
+
_instanceServiceContainer;
|
|
69
|
+
_selectionChangedHandler;
|
|
70
|
+
_selectedItems;
|
|
71
|
+
_visualizationHandler;
|
|
72
|
+
_visualizationShell;
|
|
73
|
+
_scriptCommandsTypeInfo;
|
|
74
|
+
_propertiesTypeInfo;
|
|
75
|
+
events;
|
|
76
|
+
initialize(visualizationHandler, visualizationShell, scriptCommandsTypeInfo, propertiesTypeInfo) {
|
|
77
|
+
this._visualizationHandler = visualizationHandler;
|
|
78
|
+
this._visualizationShell = visualizationShell;
|
|
79
|
+
this._scriptCommandsTypeInfo = scriptCommandsTypeInfo;
|
|
80
|
+
this._propertiesTypeInfo = propertiesTypeInfo;
|
|
81
|
+
}
|
|
82
|
+
set instanceServiceContainer(value) {
|
|
83
|
+
this._instanceServiceContainer = value;
|
|
84
|
+
this._selectionChangedHandler?.dispose();
|
|
85
|
+
this._selectionChangedHandler = this._instanceServiceContainer.selectionService.onSelectionChanged.on(e => {
|
|
86
|
+
this.selectedItems = e.selectedElements;
|
|
87
|
+
});
|
|
88
|
+
this.selectedItems = this._instanceServiceContainer.selectionService.selectedElements;
|
|
89
|
+
}
|
|
90
|
+
_createControlsForScript(eventItem) {
|
|
91
|
+
const st = this._getScriptType(eventItem);
|
|
92
|
+
switch (st) {
|
|
93
|
+
case 'none':
|
|
94
|
+
return '';
|
|
95
|
+
}
|
|
96
|
+
//@ts-ignore
|
|
97
|
+
const ctl = this.constructor.editRowTemplate.content.cloneNode(true);
|
|
98
|
+
return ctl;
|
|
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
|
+
}
|
|
107
|
+
_getScriptTypeColor(eventItem) {
|
|
108
|
+
const st = this._getScriptType(eventItem);
|
|
109
|
+
const color = EventAssignment.scriptTypeColors[st];
|
|
110
|
+
return color ?? 'white';
|
|
111
|
+
}
|
|
112
|
+
_getScriptType(eventItem) {
|
|
113
|
+
if (this.selectedItems && this.selectedItems.length) {
|
|
114
|
+
if (this.selectedItems[0].hasAttribute('@' + eventItem.name)) {
|
|
115
|
+
const val = this.selectedItems[0].getAttribute('@' + eventItem.name);
|
|
116
|
+
if (val.startsWith('{')) {
|
|
117
|
+
const parsed = JSON.parse(val);
|
|
118
|
+
if ('blocks' in parsed)
|
|
119
|
+
return 'blockly';
|
|
120
|
+
if ('commands' in parsed)
|
|
121
|
+
return 'script';
|
|
122
|
+
return 'js';
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
return 'js';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return 'none';
|
|
129
|
+
}
|
|
130
|
+
_getEventMethodname(eventItem) {
|
|
131
|
+
if (this.selectedItems.length)
|
|
132
|
+
return this.selectedItems[0].getAttribute('@' + eventItem.name);
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
_inputMthName(event, eventItem) {
|
|
136
|
+
let el = event.target;
|
|
137
|
+
this.selectedItems[0].setAttribute('@' + eventItem.name, el.value);
|
|
138
|
+
}
|
|
139
|
+
_ctxMenu(e, eventItem) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
const evtType = this._getScriptType(eventItem);
|
|
142
|
+
if (evtType != 'none')
|
|
143
|
+
ContextMenu.show([{ title: 'remove', action: () => { this.selectedItems[0].removeAttribute('@' + eventItem.name); this._bindingsRefresh(); } }], e);
|
|
144
|
+
else
|
|
145
|
+
this._showContextMenuAssignScript(e, eventItem, true);
|
|
146
|
+
}
|
|
147
|
+
async _addEvent(e) {
|
|
148
|
+
if (e.key == 'Enter') {
|
|
149
|
+
let ip = this._getDomElement('addEventInput');
|
|
150
|
+
this._selectedItems[0].setAttribute('@' + PropertiesHelper.camelToDashCase(ip.value.replaceAll(' ', '-')), '');
|
|
151
|
+
ip.value = '';
|
|
152
|
+
this.scrollTop = 0;
|
|
153
|
+
this.refresh();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
_createAssignScriptContextMenu(event, eventItem) {
|
|
157
|
+
let ctxMenu = [
|
|
158
|
+
{
|
|
159
|
+
title: 'Simple Script',
|
|
160
|
+
action: () => {
|
|
161
|
+
this._editEvent('script', event, eventItem);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
title: 'Javascript',
|
|
166
|
+
action: () => {
|
|
167
|
+
let nm = prompt('name of function ?');
|
|
168
|
+
if (nm) {
|
|
169
|
+
this._selectedItems[0].setAttribute('@' + eventItem.name, nm);
|
|
170
|
+
this.refresh();
|
|
171
|
+
this._editEvent('js', null, eventItem);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
title: 'Blockly',
|
|
177
|
+
action: () => {
|
|
178
|
+
this._editBlockly(null, eventItem);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
];
|
|
182
|
+
const evtType = this._getScriptType(eventItem);
|
|
183
|
+
if (evtType != 'none') {
|
|
184
|
+
ctxMenu.push({
|
|
185
|
+
title: '-'
|
|
186
|
+
});
|
|
187
|
+
ctxMenu.push({
|
|
188
|
+
title: 'remove',
|
|
189
|
+
action: () => { this.selectedItems[0].removeAttribute('@' + eventItem.name); this._bindingsRefresh(); }
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return ctxMenu;
|
|
193
|
+
}
|
|
194
|
+
async _showContextMenuAssignScript(event, eventItem, isCtxMenu) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
const evtType = this._getScriptType(eventItem);
|
|
197
|
+
if (evtType != 'none' && !isCtxMenu) {
|
|
198
|
+
this._editEvent(evtType, event, eventItem);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const ctxMenu = this._createAssignScriptContextMenu(event, eventItem);
|
|
202
|
+
ContextMenu.show(ctxMenu, event);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async _editParameter(e, eventItem) {
|
|
206
|
+
const edt = new ParameterEditor();
|
|
207
|
+
let existingParameter = {};
|
|
208
|
+
edt.title = "ParameterEditor for '" + eventItem.name + "' of '" + this._selectedItems[0].name + "'";
|
|
209
|
+
let data = this._selectedItems[0].getAttribute('@' + eventItem.name);
|
|
210
|
+
if (data && data[0] == '{') {
|
|
211
|
+
try {
|
|
212
|
+
const parsed = JSON.parse(data);
|
|
213
|
+
existingParameter = parsed.parameters;
|
|
214
|
+
}
|
|
215
|
+
catch { }
|
|
216
|
+
}
|
|
217
|
+
edt.setParametersObject(existingParameter);
|
|
218
|
+
const result = await this._visualizationShell.openConfirmation(edt, { x: 100, y: 100, width: 700, height: 500 });
|
|
219
|
+
if (result) {
|
|
220
|
+
const par = edt.getParametersObject();
|
|
221
|
+
let newObj = {
|
|
222
|
+
name: data,
|
|
223
|
+
parameters: par
|
|
224
|
+
};
|
|
225
|
+
if (data && data[0] == '{') {
|
|
226
|
+
newObj = JSON.parse(data);
|
|
227
|
+
newObj.parameters = par;
|
|
228
|
+
}
|
|
229
|
+
if (par == null)
|
|
230
|
+
delete newObj.parameters;
|
|
231
|
+
const newData = JSON.stringify(newObj);
|
|
232
|
+
this._selectedItems[0].setAttribute('@' + eventItem.name, newData);
|
|
233
|
+
this._bindingsRefresh();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async _editBlockly(e, eventItem) {
|
|
237
|
+
const edt = new BlocklyScriptEditor();
|
|
238
|
+
edt.title = "Blockly Script for '" + eventItem.name + "' of '" + this._selectedItems[0].name + "'";
|
|
239
|
+
let data = this._selectedItems[0].getAttribute('@' + eventItem.name);
|
|
240
|
+
let parameters = null;
|
|
241
|
+
if (data) {
|
|
242
|
+
const parsed = JSON.parse(data);
|
|
243
|
+
parameters = parsed.parameters;
|
|
244
|
+
edt.load(parsed);
|
|
245
|
+
}
|
|
246
|
+
const result = await this._visualizationShell.openConfirmation(edt, { x: 100, y: 100, width: 700, height: 500 });
|
|
247
|
+
if (result) {
|
|
248
|
+
const blockObj = edt.save();
|
|
249
|
+
if (parameters) {
|
|
250
|
+
blockObj.parameters = parameters;
|
|
251
|
+
}
|
|
252
|
+
this._selectedItems[0].setAttribute('@' + eventItem.name, JSON.stringify(blockObj));
|
|
253
|
+
this._bindingsRefresh();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async _editJavascript(e, eventItem) {
|
|
257
|
+
// todo ?
|
|
258
|
+
}
|
|
259
|
+
async _editSimpleScript(e, eventItem) {
|
|
260
|
+
let scriptString = this.selectedItems[0].getAttribute('@' + eventItem.name);
|
|
261
|
+
if (!scriptString || scriptString.startsWith('{')) {
|
|
262
|
+
let script = { commands: [] };
|
|
263
|
+
let parameters = null;
|
|
264
|
+
if (scriptString) {
|
|
265
|
+
script = JSON.parse(scriptString);
|
|
266
|
+
//@ts-ignore
|
|
267
|
+
parameters = script.parameters;
|
|
268
|
+
}
|
|
269
|
+
let sc = new SimpleScriptEditor();
|
|
270
|
+
sc.serviceContainer = this.selectedItems[0].serviceContainer;
|
|
271
|
+
sc.scriptCommandsTypeInfo = this._scriptCommandsTypeInfo;
|
|
272
|
+
sc.propertiesTypeInfo = this._propertiesTypeInfo;
|
|
273
|
+
sc.visualizationShell = this._visualizationShell;
|
|
274
|
+
sc.visualizationHandler = this._visualizationHandler;
|
|
275
|
+
sc.loadScript(script);
|
|
276
|
+
sc.title = "Script '" + eventItem.name + "' on " + this.selectedItems[0].name;
|
|
277
|
+
let res = await this._visualizationShell.openConfirmation(sc, { x: 100, y: 100, width: 600, height: 500 });
|
|
278
|
+
if (res) {
|
|
279
|
+
let scriptCommands = sc.getScriptCommands();
|
|
280
|
+
if (scriptCommands && scriptCommands.length) {
|
|
281
|
+
const sc = { commands: scriptCommands };
|
|
282
|
+
if (parameters) {
|
|
283
|
+
//@ts-ignore
|
|
284
|
+
sc.parameters = parameters;
|
|
285
|
+
}
|
|
286
|
+
let json = JSON.stringify(sc);
|
|
287
|
+
this.selectedItems[0].setAttribute('@' + eventItem.name, json);
|
|
288
|
+
this._bindingsRefresh();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async _editEvent(evtType, e, eventItem) {
|
|
294
|
+
if (evtType == 'js') {
|
|
295
|
+
this._editJavascript(e, eventItem);
|
|
296
|
+
}
|
|
297
|
+
else if (evtType == 'blockly') {
|
|
298
|
+
this._editBlockly(e, eventItem);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
this._editSimpleScript(e, eventItem);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
refresh() {
|
|
305
|
+
if (this._selectedItems != null && this._selectedItems.length) {
|
|
306
|
+
this.events = this._selectedItems[0].serviceContainer.getLastServiceWhere('eventsService', x => x.isHandledElement(this._selectedItems[0])).getPossibleEvents(this._selectedItems[0]);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
this.events = [];
|
|
310
|
+
}
|
|
311
|
+
this._bindingsRefresh();
|
|
312
|
+
}
|
|
313
|
+
get selectedItems() {
|
|
314
|
+
return this._selectedItems;
|
|
315
|
+
}
|
|
316
|
+
set selectedItems(items) {
|
|
317
|
+
if (this._selectedItems != items) {
|
|
318
|
+
this._selectedItems = items;
|
|
319
|
+
this.refresh();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
customElements.define(EventAssignment.is, EventAssignment);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
export declare class ParameterEditor extends BaseCustomWebComponentConstructorAppend {
|
|
3
|
+
static style: CSSStyleSheet;
|
|
4
|
+
static template: HTMLTemplateElement;
|
|
5
|
+
static is: string;
|
|
6
|
+
constructor();
|
|
7
|
+
ready(): void;
|
|
8
|
+
protected _parameterArray: {
|
|
9
|
+
key: string;
|
|
10
|
+
type: string;
|
|
11
|
+
value: any;
|
|
12
|
+
}[];
|
|
13
|
+
setParametersObject(value: Record<string, any>): void;
|
|
14
|
+
getParametersObject(): {};
|
|
15
|
+
_remove(index: number): void;
|
|
16
|
+
_add(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
export class ParameterEditor extends BaseCustomWebComponentConstructorAppend {
|
|
3
|
+
static style = css `
|
|
4
|
+
:host {
|
|
5
|
+
display: grid;
|
|
6
|
+
grid-template-columns: 80px 80px 80px auto;
|
|
7
|
+
overflow-y: auto;
|
|
8
|
+
align-content: start;
|
|
9
|
+
height: 100%;
|
|
10
|
+
padding: 10px;
|
|
11
|
+
gap: 5px;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
span {
|
|
16
|
+
font-size: 10px;
|
|
17
|
+
}`;
|
|
18
|
+
static template = html `
|
|
19
|
+
<span></span>
|
|
20
|
+
<span>name</span>
|
|
21
|
+
<span>type</span>
|
|
22
|
+
<span>value</span>
|
|
23
|
+
<template repeat:item="[[this._parameterArray]]">
|
|
24
|
+
<button @click="[[this._remove(index)]]" style="width: 40px; height: 20px; align-self: center;">del</button>
|
|
25
|
+
<input type="text" value="{{?item.key}}">
|
|
26
|
+
<select value="{{item.type}}" @change="[[this._bindingsRefresh()]]">
|
|
27
|
+
<option>null</string>
|
|
28
|
+
<option>string</string>
|
|
29
|
+
<option>number</string>
|
|
30
|
+
<option>boolean</string>
|
|
31
|
+
</select>
|
|
32
|
+
<input hidden="[[item.type !== 'string']]" type="text" value="{{?item.value}}">
|
|
33
|
+
<input hidden="[[item.type !== 'number']]" type="number" value="{{item.value}}">
|
|
34
|
+
<input hidden="[[item.type !== 'boolean']]" type="checkbox" checked="{{item.value}}">
|
|
35
|
+
<div hidden="[[item.type !== 'null']]">-null-</div>
|
|
36
|
+
</template>
|
|
37
|
+
<button @click="[[this._add()]]" style="width: 40px; height: 20px; align-self: center;">add</button>`;
|
|
38
|
+
static is = 'node-projects-visualization-parameter-editor';
|
|
39
|
+
constructor() {
|
|
40
|
+
super();
|
|
41
|
+
this._restoreCachedInititalValues();
|
|
42
|
+
}
|
|
43
|
+
ready() {
|
|
44
|
+
this._bindingsParse();
|
|
45
|
+
}
|
|
46
|
+
_parameterArray;
|
|
47
|
+
setParametersObject(value) {
|
|
48
|
+
if (value != null)
|
|
49
|
+
this._parameterArray = Object.keys(value).map(x => ({ key: x, type: typeof value[x] === 'object' ? 'null' : typeof value[x], value: value[x] }));
|
|
50
|
+
else
|
|
51
|
+
this._parameterArray = [];
|
|
52
|
+
this._bindingsRefresh();
|
|
53
|
+
}
|
|
54
|
+
getParametersObject() {
|
|
55
|
+
let hasPar = false;
|
|
56
|
+
const obj = {};
|
|
57
|
+
for (const p of this._parameterArray) {
|
|
58
|
+
if (p.key) {
|
|
59
|
+
hasPar = true;
|
|
60
|
+
obj[p.key] = null;
|
|
61
|
+
switch (p.type) {
|
|
62
|
+
case 'string':
|
|
63
|
+
obj[p.key] = p.value.toString();
|
|
64
|
+
break;
|
|
65
|
+
case 'number':
|
|
66
|
+
const f = parseFloat(p.value);
|
|
67
|
+
obj[p.key] = isNaN(f) ? 0 : f;
|
|
68
|
+
break;
|
|
69
|
+
case 'boolean':
|
|
70
|
+
obj[p.key] = !!p.value;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return hasPar ? obj : null;
|
|
76
|
+
}
|
|
77
|
+
_remove(index) {
|
|
78
|
+
this._parameterArray.splice(index, 1);
|
|
79
|
+
this._bindingsRefresh();
|
|
80
|
+
}
|
|
81
|
+
_add() {
|
|
82
|
+
this._parameterArray.push({ type: 'null' });
|
|
83
|
+
this._bindingsRefresh();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
customElements.define(ParameterEditor.is, ParameterEditor);
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from './components/BindingsEditor.js';
|
|
|
6
6
|
export * from './components/BindingsEditorHistoric.js';
|
|
7
7
|
export * from './components/SimpleScriptEditor.js';
|
|
8
8
|
export * from './components/VisualizationPropertyGrid.js';
|
|
9
|
+
export * from './components/ParameterEditor.js';
|
|
10
|
+
export * from './components/EventAssignment.js';
|
|
9
11
|
export * from './helpers/BindingsHelper.js';
|
|
10
12
|
export * from './interfaces/IScriptMultiplexValue.js';
|
|
11
13
|
export * from './interfaces/VisualisationElementScript.js';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export * from './components/BindingsEditor.js';
|
|
|
6
6
|
export * from './components/BindingsEditorHistoric.js';
|
|
7
7
|
export * from './components/SimpleScriptEditor.js';
|
|
8
8
|
export * from './components/VisualizationPropertyGrid.js';
|
|
9
|
+
export * from './components/ParameterEditor.js';
|
|
10
|
+
export * from './components/EventAssignment.js';
|
|
9
11
|
export * from './helpers/BindingsHelper.js';
|
|
10
12
|
export * from './interfaces/IScriptMultiplexValue.js';
|
|
11
13
|
export * from './interfaces/VisualisationElementScript.js';
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export declare class IScriptMultiplexValue {
|
|
2
2
|
/**
|
|
3
|
-
* signal - read the value from a
|
|
3
|
+
* signal - read the value from a Signal
|
|
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
|
+
* parameter - a paremter you hand over
|
|
6
7
|
*/
|
|
7
|
-
source: 'signal' | 'property' | 'event';
|
|
8
|
+
source: 'signal' | 'property' | 'event' | 'parameter';
|
|
8
9
|
/**
|
|
9
|
-
* Name of the ioBroker object or the property of the component
|
|
10
|
+
* Name of the ioBroker object or the property of the component or the parameter of the script
|
|
10
11
|
* or for example in a event : srcElement.value to get the value of a input wich raises the event
|
|
11
12
|
* @TJS-format signal
|
|
12
13
|
*/
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export class IScriptMultiplexValue {
|
|
2
2
|
/**
|
|
3
|
-
* signal - read the value from a
|
|
3
|
+
* signal - read the value from a Signal
|
|
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
|
+
* parameter - a paremter you hand over
|
|
6
7
|
*/
|
|
7
8
|
source;
|
|
8
9
|
/**
|
|
9
|
-
* Name of the ioBroker object or the property of the component
|
|
10
|
+
* Name of the ioBroker object or the property of the component or the parameter of the script
|
|
10
11
|
* or for example in a event : srcElement.value to get the value of a input wich raises the event
|
|
11
12
|
* @TJS-format signal
|
|
12
13
|
*/
|
package/dist/scripting/Script.js
CHANGED
|
@@ -2,20 +2,19 @@ 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 = {
|
|
6
|
+
event: Event;
|
|
7
|
+
element: Element;
|
|
8
|
+
root: HTMLElement;
|
|
9
|
+
parameters?: Record<string, any>;
|
|
10
|
+
};
|
|
5
11
|
export declare class ScriptSystem {
|
|
6
12
|
_visualizationHandler: VisualizationHandler;
|
|
7
13
|
constructor(visualizationHandler: VisualizationHandler);
|
|
8
|
-
execute(scriptCommands: ScriptCommands[], outerContext:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
root: HTMLElement;
|
|
12
|
-
}): Promise<void>;
|
|
13
|
-
runScriptCommand<T extends ScriptCommands>(command: T, context: any): Promise<void>;
|
|
14
|
-
getValue<T>(value: string | number | boolean | IScriptMultiplexValue, outerContext: {
|
|
15
|
-
event: Event;
|
|
16
|
-
element: Element;
|
|
17
|
-
root: HTMLElement;
|
|
18
|
-
}): Promise<any>;
|
|
14
|
+
execute(scriptCommands: ScriptCommands[], outerContext: contextType): Promise<void>;
|
|
15
|
+
runScriptCommand<T extends ScriptCommands>(command: T, context: contextType): Promise<void>;
|
|
16
|
+
getValue<T>(value: string | number | boolean | IScriptMultiplexValue, outerContext: contextType): Promise<any>;
|
|
19
17
|
static extractPart(obj: any, propertyPath: string): any;
|
|
20
18
|
assignAllScripts(source: string, javascriptCode: string, shadowRoot: ShadowRoot, instance: HTMLElement, assignExternalScript?: (element: Element, event: string, scriptData: any) => void): Promise<VisualisationElementScript>;
|
|
21
19
|
}
|
|
20
|
+
export {};
|
|
@@ -147,6 +147,9 @@ export class ScriptSystem {
|
|
|
147
147
|
obj = ScriptSystem.extractPart(obj, value.name);
|
|
148
148
|
return obj;
|
|
149
149
|
}
|
|
150
|
+
case 'parameter': {
|
|
151
|
+
return outerContext.parameters[value.name];
|
|
152
|
+
}
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
return value;
|
|
@@ -182,7 +185,7 @@ export class ScriptSystem {
|
|
|
182
185
|
if (script[0] == '{') {
|
|
183
186
|
let scriptObj = JSON.parse(script);
|
|
184
187
|
if ('commands' in scriptObj) {
|
|
185
|
-
e.addEventListener(evtName, (evt) => this.execute(scriptObj.commands, { event: evt, element: e, root: instance }));
|
|
188
|
+
e.addEventListener(evtName, (evt) => this.execute(scriptObj.commands, { event: evt, element: e, root: instance, parameters: scriptObj.parameters }));
|
|
186
189
|
}
|
|
187
190
|
else if ('blocks' in scriptObj) {
|
|
188
191
|
let compiledFunc = null;
|
|
@@ -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.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|