@node-projects/web-component-designer-visualization-addons 0.1.12 → 0.1.14

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.
@@ -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
- PROPERTYPATH: {
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
- SELECTOR: {
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
- NAME: {
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
+ };
@@ -1,6 +1,7 @@
1
1
  import './fields/FieldObjectId.js';
2
2
  import './Console.js';
3
3
  import './Debugger.js';
4
+ import './GetParameter.js';
4
5
  import './GetState.js';
5
6
  import './GetSubProperty.js';
6
7
  import './OpenScreen.js';
@@ -1,6 +1,7 @@
1
1
  import './fields/FieldObjectId.js';
2
2
  import './Console.js';
3
3
  import './Debugger.js';
4
+ import './GetParameter.js';
4
5
  import './GetState.js';
5
6
  import './GetSubProperty.js';
6
7
  import './OpenScreen.js';
@@ -0,0 +1,46 @@
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 evtEdit: 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): Node | "";
29
+ protected _getScriptTypeColor(eventItem: IEvent): any;
30
+ protected _getScriptType(eventItem: IEvent): scriptType;
31
+ protected _getEventMethodname(eventItem: IEvent): string;
32
+ protected _inputMthName(event: InputEvent, eventItem: IEvent): void;
33
+ protected _ctxMenu(e: MouseEvent, eventItem: IEvent): void;
34
+ protected _addEvent(e: KeyboardEvent): Promise<void>;
35
+ protected _createAssignScriptContextMenu(event: MouseEvent, eventItem: IEvent): IContextMenuItem[];
36
+ protected _showContextMenuAssignScript(event: MouseEvent, eventItem: IEvent, isCtxMenu: boolean): Promise<void>;
37
+ protected _editParameter(e: MouseEvent, eventItem: IEvent): Promise<void>;
38
+ protected _editBlockly(e: MouseEvent, eventItem: IEvent): Promise<void>;
39
+ protected _editJavascript(e: MouseEvent, eventItem: IEvent): Promise<void>;
40
+ protected _editSimpleScript(e: MouseEvent, eventItem: IEvent): Promise<void>;
41
+ _editEvent(evtType: scriptType, e: MouseEvent, eventItem: IEvent): Promise<void>;
42
+ refresh(): void;
43
+ get selectedItems(): IDesignItem[];
44
+ set selectedItems(items: IDesignItem[]);
45
+ }
46
+ export {};
@@ -0,0 +1,309 @@
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
+ a {
29
+ cursor: pointer;
30
+ }
31
+ a:hover {
32
+ cursor: pointer;
33
+ text-decoration: underline;
34
+ }
35
+ button {
36
+ cursor: pointer;
37
+ }`;
38
+ static template = html `
39
+ <template repeat:item="[[this.events]]">
40
+ <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>
42
+ <div>[[this._createControlsForScript(item)]]</div>
43
+ </template>
44
+ <span style="grid-column: 1 / span 3; margin-top: 8px; margin-left: 3px;">add event:</span>
45
+ <input id="addEventInput" style="grid-column: 1 / span 3; margin: 5px;" @keypress=[[this._addEvent(event)]] type="text">`;
46
+ static evtEdit = html `
47
+ <div style="display: flex; justify-content: flex-end;">
48
+ <input title="name" style="min-width: 30px; flex-basis: 30px; flex-grow: 2;" class="mth" type="text">
49
+ <input title="relative signals path" style="min-width: 20px; flex-basis: 20px; flex-grow: 1;" class="mth" type="text">
50
+ <button style="display: flex; padding: 0; flex-grow: 0;" title="parameter" @click="[[this._editParameter(event, item)]]">p</button>
51
+ </div>`;
52
+ static scriptTypeColors = {
53
+ 'js': 'purple',
54
+ 'blockly': 'yellow',
55
+ 'script': 'lightgreen'
56
+ };
57
+ static is = 'node-projects-visualization-event-assignment';
58
+ constructor() {
59
+ super();
60
+ this._restoreCachedInititalValues();
61
+ }
62
+ ready() {
63
+ this._bindingsParse();
64
+ }
65
+ _instanceServiceContainer;
66
+ _selectionChangedHandler;
67
+ _selectedItems;
68
+ _visualizationHandler;
69
+ _visualizationShell;
70
+ _scriptCommandsTypeInfo;
71
+ _propertiesTypeInfo;
72
+ events;
73
+ initialize(visualizationHandler, visualizationShell, scriptCommandsTypeInfo, propertiesTypeInfo) {
74
+ this._visualizationHandler = visualizationHandler;
75
+ this._visualizationShell = visualizationShell;
76
+ this._scriptCommandsTypeInfo = scriptCommandsTypeInfo;
77
+ this._propertiesTypeInfo = propertiesTypeInfo;
78
+ }
79
+ set instanceServiceContainer(value) {
80
+ this._instanceServiceContainer = value;
81
+ this._selectionChangedHandler?.dispose();
82
+ this._selectionChangedHandler = this._instanceServiceContainer.selectionService.onSelectionChanged.on(e => {
83
+ this.selectedItems = e.selectedElements;
84
+ });
85
+ this.selectedItems = this._instanceServiceContainer.selectionService.selectedElements;
86
+ }
87
+ _createControlsForScript(eventItem) {
88
+ const st = this._getScriptType(eventItem);
89
+ switch (st) {
90
+ case 'none':
91
+ return '';
92
+ }
93
+ const ctl = EventAssignment.evtEdit.content.cloneNode(true);
94
+ return ctl;
95
+ }
96
+ _getScriptTypeColor(eventItem) {
97
+ const st = this._getScriptType(eventItem);
98
+ const color = EventAssignment.scriptTypeColors[st];
99
+ return color ?? 'white';
100
+ }
101
+ _getScriptType(eventItem) {
102
+ if (this.selectedItems && this.selectedItems.length) {
103
+ if (this.selectedItems[0].hasAttribute('@' + eventItem.name)) {
104
+ const val = this.selectedItems[0].getAttribute('@' + eventItem.name);
105
+ if (val.startsWith('{')) {
106
+ const parsed = JSON.parse(val);
107
+ if ('blocks' in parsed)
108
+ return 'blockly';
109
+ if ('commands' in parsed)
110
+ return 'script';
111
+ return 'js';
112
+ }
113
+ else
114
+ return 'js';
115
+ }
116
+ }
117
+ return 'none';
118
+ }
119
+ _getEventMethodname(eventItem) {
120
+ if (this.selectedItems.length)
121
+ return this.selectedItems[0].getAttribute('@' + eventItem.name);
122
+ return '';
123
+ }
124
+ _inputMthName(event, eventItem) {
125
+ let el = event.target;
126
+ this.selectedItems[0].setAttribute('@' + eventItem.name, el.value);
127
+ }
128
+ _ctxMenu(e, eventItem) {
129
+ e.preventDefault();
130
+ const evtType = this._getScriptType(eventItem);
131
+ if (evtType != 'none')
132
+ ContextMenu.show([{ title: 'remove', action: () => { this.selectedItems[0].removeAttribute('@' + eventItem.name); this._bindingsRefresh(); } }], e);
133
+ else
134
+ this._showContextMenuAssignScript(e, eventItem, true);
135
+ }
136
+ async _addEvent(e) {
137
+ if (e.key == 'Enter') {
138
+ let ip = this._getDomElement('addEventInput');
139
+ this._selectedItems[0].setAttribute('@' + PropertiesHelper.camelToDashCase(ip.value.replaceAll(' ', '-')), '');
140
+ ip.value = '';
141
+ this.scrollTop = 0;
142
+ this.refresh();
143
+ }
144
+ }
145
+ _createAssignScriptContextMenu(event, eventItem) {
146
+ let ctxMenu = [
147
+ {
148
+ title: 'Simple Script',
149
+ action: () => {
150
+ this._editEvent('script', event, eventItem);
151
+ }
152
+ },
153
+ {
154
+ title: 'Javascript',
155
+ action: () => {
156
+ let nm = prompt('name of function ?');
157
+ if (nm) {
158
+ this._selectedItems[0].setAttribute('@' + eventItem.name, nm);
159
+ this.refresh();
160
+ this._editEvent('js', null, eventItem);
161
+ }
162
+ }
163
+ },
164
+ {
165
+ title: 'Blockly',
166
+ action: () => {
167
+ this._editBlockly(null, eventItem);
168
+ }
169
+ }
170
+ ];
171
+ const evtType = this._getScriptType(eventItem);
172
+ if (evtType != 'none') {
173
+ ctxMenu.push({
174
+ title: '-'
175
+ });
176
+ ctxMenu.push({
177
+ title: 'remove',
178
+ action: () => { this.selectedItems[0].removeAttribute('@' + eventItem.name); this._bindingsRefresh(); }
179
+ });
180
+ }
181
+ return ctxMenu;
182
+ }
183
+ async _showContextMenuAssignScript(event, eventItem, isCtxMenu) {
184
+ event.preventDefault();
185
+ const evtType = this._getScriptType(eventItem);
186
+ if (evtType != 'none' && !isCtxMenu) {
187
+ this._editEvent(evtType, event, eventItem);
188
+ }
189
+ else {
190
+ const ctxMenu = this._createAssignScriptContextMenu(event, eventItem);
191
+ ContextMenu.show(ctxMenu, event);
192
+ }
193
+ }
194
+ async _editParameter(e, eventItem) {
195
+ const edt = new ParameterEditor();
196
+ let existingParameter = {};
197
+ edt.title = "ParameterEditor for '" + eventItem.name + "' of '" + this._selectedItems[0].name + "'";
198
+ let data = this._selectedItems[0].getAttribute('@' + eventItem.name);
199
+ if (data && data[0] == '{') {
200
+ try {
201
+ const parsed = JSON.parse(data);
202
+ existingParameter = parsed.parameters;
203
+ }
204
+ catch { }
205
+ }
206
+ edt.setParametersObject(existingParameter);
207
+ const result = await this._visualizationShell.openConfirmation(edt, { x: 100, y: 100, width: 700, height: 500 });
208
+ if (result) {
209
+ const par = edt.getParametersObject();
210
+ let newObj = {
211
+ name: data,
212
+ parameters: par
213
+ };
214
+ if (data && data[0] == '{') {
215
+ newObj = JSON.parse(data);
216
+ newObj.parameters = par;
217
+ }
218
+ const newData = JSON.stringify(newObj);
219
+ this._selectedItems[0].setAttribute('@' + eventItem.name, newData);
220
+ }
221
+ }
222
+ async _editBlockly(e, eventItem) {
223
+ const edt = new BlocklyScriptEditor();
224
+ edt.title = "Blockly Script for '" + eventItem.name + "' of '" + this._selectedItems[0].name + "'";
225
+ let data = this._selectedItems[0].getAttribute('@' + eventItem.name);
226
+ let parameters = null;
227
+ if (data) {
228
+ const parsed = JSON.parse(data);
229
+ parameters = parsed.parameters;
230
+ edt.load(parsed);
231
+ }
232
+ const result = await this._visualizationShell.openConfirmation(edt, { x: 100, y: 100, width: 700, height: 500 });
233
+ if (result) {
234
+ const blockObj = edt.save();
235
+ if (parameters) {
236
+ blockObj.parameters = parameters;
237
+ }
238
+ this._selectedItems[0].setAttribute('@' + eventItem.name, JSON.stringify(blockObj));
239
+ this._bindingsRefresh();
240
+ }
241
+ }
242
+ async _editJavascript(e, eventItem) {
243
+ // todo ?
244
+ }
245
+ async _editSimpleScript(e, eventItem) {
246
+ let scriptString = this.selectedItems[0].getAttribute('@' + eventItem.name);
247
+ if (!scriptString || scriptString.startsWith('{')) {
248
+ let script = { commands: [] };
249
+ let parameters = null;
250
+ if (scriptString) {
251
+ script = JSON.parse(scriptString);
252
+ //@ts-ignore
253
+ parameters = script.parameters;
254
+ }
255
+ let sc = new SimpleScriptEditor();
256
+ sc.serviceContainer = this.selectedItems[0].serviceContainer;
257
+ sc.scriptCommandsTypeInfo = this._scriptCommandsTypeInfo;
258
+ sc.propertiesTypeInfo = this._propertiesTypeInfo;
259
+ sc.visualizationShell = this._visualizationShell;
260
+ sc.visualizationHandler = this._visualizationHandler;
261
+ sc.loadScript(script);
262
+ sc.title = "Script '" + eventItem.name + "' on " + this.selectedItems[0].name;
263
+ let res = await this._visualizationShell.openConfirmation(sc, { x: 100, y: 100, width: 600, height: 500 });
264
+ if (res) {
265
+ let scriptCommands = sc.getScriptCommands();
266
+ if (scriptCommands && scriptCommands.length) {
267
+ const sc = { commands: scriptCommands };
268
+ if (parameters) {
269
+ //@ts-ignore
270
+ sc.parameters = parameters;
271
+ }
272
+ let json = JSON.stringify(sc);
273
+ this.selectedItems[0].setAttribute('@' + eventItem.name, json);
274
+ this._bindingsRefresh();
275
+ }
276
+ }
277
+ }
278
+ }
279
+ async _editEvent(evtType, e, eventItem) {
280
+ if (evtType == 'js') {
281
+ this._editJavascript(e, eventItem);
282
+ }
283
+ else if (evtType == 'blockly') {
284
+ this._editBlockly(e, eventItem);
285
+ }
286
+ else {
287
+ this._editSimpleScript(e, eventItem);
288
+ }
289
+ }
290
+ refresh() {
291
+ if (this._selectedItems != null && this._selectedItems.length) {
292
+ this.events = this._selectedItems[0].serviceContainer.getLastServiceWhere('eventsService', x => x.isHandledElement(this._selectedItems[0])).getPossibleEvents(this._selectedItems[0]);
293
+ }
294
+ else {
295
+ this.events = [];
296
+ }
297
+ this._bindingsRefresh();
298
+ }
299
+ get selectedItems() {
300
+ return this._selectedItems;
301
+ }
302
+ set selectedItems(items) {
303
+ if (this._selectedItems != items) {
304
+ this._selectedItems = items;
305
+ this.refresh();
306
+ }
307
+ }
308
+ }
309
+ 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,7 @@ 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';
9
10
  export * from './helpers/BindingsHelper.js';
10
11
  export * from './interfaces/IScriptMultiplexValue.js';
11
12
  export * from './interfaces/VisualisationElementScript.js';
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ 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';
9
10
  export * from './helpers/BindingsHelper.js';
10
11
  export * from './interfaces/IScriptMultiplexValue.js';
11
12
  export * from './interfaces/VisualisationElementScript.js';
@@ -1,12 +1,13 @@
1
1
  export declare class IScriptMultiplexValue {
2
2
  /**
3
- * signal - read the value from a IOB object
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 IOB object
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
  */
@@ -1,6 +1,7 @@
1
1
  import { ScriptCommands } from "./ScriptCommands.js";
2
2
  export declare class Script {
3
3
  name?: string;
4
+ relativeSignalsPath?: string;
4
5
  commands: ScriptCommands[];
5
6
  parameters?: Record<string, any>;
6
7
  }
@@ -1,5 +1,6 @@
1
1
  export class Script {
2
2
  name;
3
+ relativeSignalsPath;
3
4
  commands;
4
5
  parameters;
5
6
  }
@@ -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
- event: Event;
10
- element: Element;
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
- assignAllScripts(source: string, javascriptCode: string, shadowRoot: ShadowRoot, instance: HTMLElement): Promise<VisualisationElementScript>;
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;
@@ -158,7 +161,7 @@ export class ScriptSystem {
158
161
  }
159
162
  return retVal;
160
163
  }
161
- async assignAllScripts(source, javascriptCode, shadowRoot, instance) {
164
+ async assignAllScripts(source, javascriptCode, shadowRoot, instance, assignExternalScript) {
162
165
  const allElements = shadowRoot.querySelectorAll('*');
163
166
  let jsObject = null;
164
167
  if (javascriptCode) {
@@ -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;
@@ -192,6 +195,10 @@ export class ScriptSystem {
192
195
  compiledFunc(evt, shadowRoot);
193
196
  });
194
197
  }
198
+ else {
199
+ if (assignExternalScript)
200
+ assignExternalScript(e, evtName, scriptObj);
201
+ }
195
202
  }
196
203
  else {
197
204
  e.addEventListener(evtName, (evt) => {
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.12",
4
+ "version": "0.1.14",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",