@node-projects/web-component-designer-visualization-addons 0.1.15 → 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.
@@ -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: any, propertyPath: string) {
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 = `${name}`;
18
+ const code = `parameters[${name}]`;
19
19
  //@ts-ignore
20
20
  return [code, Blockly.JavaScript.ORDER_NONE];
21
21
  };
@@ -41,17 +41,17 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
41
41
  static template = html `
42
42
  <template repeat:item="[[this.events]]">
43
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>
44
+ <a @click="[[this._showContextMenuAssignScript(event, item, false)]]" @contextmenu="[[this._ctxMenu(event, item)]]" title="[[item.name]]">[[item.name]]</a>
45
45
  <div>[[this._createControlsForScript(item)]]</div>
46
46
  </template>
47
47
  <span style="grid-column: 1 / span 3; margin-top: 8px; margin-left: 3px;">add event:</span>
48
48
  <input id="addEventInput" style="grid-column: 1 / span 3; margin: 5px;" @keypress=[[this._addEvent(event)]] type="text">`;
49
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>`;
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
55
  static scriptTypeColors = {
56
56
  'js': 'purple',
57
57
  'blockly': 'yellow',
@@ -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 {
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.15",
4
+ "version": "0.1.17",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",