@node-projects/web-component-designer-visualization-addons 0.1.97 → 0.1.99

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.
@@ -23,5 +23,5 @@ export declare class ScriptSystem {
23
23
  getSignaName(name: string, outerContext: contextType): string;
24
24
  static extractPart(obj: any, propertyPath: string): any;
25
25
  createScriptContext(root: HTMLElement, event: Event, element: Element, parameters: Record<string, any>, relativeSignalsPath: string): any;
26
- assignAllScripts(source: string, javascriptCode: string, shadowRoot: ShadowRoot, instance: HTMLElement, visualizationHandler: VisualizationHandler, assignExternalScript?: (element: Element, event: string, scriptData: any) => void): Promise<VisualisationElementScript>;
26
+ assignAllScripts(source: string, javascriptCode: string, shadowRoot: ShadowRoot, instance: HTMLElement, visualizationHandler: VisualizationHandler, contextCreator?: (root: HTMLElement, event: Event, element: Element, parameters: Record<string, any>, relativeSignalsPath: string) => any, assignExternalScript?: (element: Element, event: string, scriptData: any) => void): Promise<VisualisationElementScript>;
27
27
  }
@@ -401,8 +401,9 @@ export class ScriptSystem {
401
401
  createScriptContext(root, event, element, parameters, relativeSignalsPath) {
402
402
  return { root, event, element, parameters, relativeSignalsPath };
403
403
  }
404
- async assignAllScripts(source, javascriptCode, shadowRoot, instance, visualizationHandler, assignExternalScript) {
404
+ async assignAllScripts(source, javascriptCode, shadowRoot, instance, visualizationHandler, contextCreator, assignExternalScript) {
405
405
  const allElements = shadowRoot.querySelectorAll('*');
406
+ contextCreator ??= this.createScriptContext;
406
407
  let jsObject = null;
407
408
  if (javascriptCode) {
408
409
  try {
@@ -425,14 +426,14 @@ export class ScriptSystem {
425
426
  if (script[0] == '{') {
426
427
  let scriptObj = JSON.parse(script);
427
428
  if ('commands' in scriptObj) {
428
- e.addEventListener(evtName, (evt) => this.execute(scriptObj.commands, this.createScriptContext(instance, evt, e, scriptObj.parameters, scriptObj.relativeSignalsPath)));
429
+ e.addEventListener(evtName, (evt) => this.execute(scriptObj.commands, contextCreator(instance, evt, e, scriptObj.parameters, scriptObj.relativeSignalsPath)));
429
430
  }
430
431
  else if ('blocks' in scriptObj) {
431
432
  let compiledFunc = null;
432
433
  e.addEventListener(evtName, async (evt) => {
433
434
  if (!compiledFunc)
434
435
  compiledFunc = await generateEventCodeFromBlockly(scriptObj);
435
- compiledFunc(evt, shadowRoot, scriptObj.parameters, scriptObj.relativeSignalsPath ?? '', visualizationHandler, this.createScriptContext(instance, evt, e, scriptObj.parameters, scriptObj.relativeSignalsPath));
436
+ compiledFunc(evt, shadowRoot, scriptObj.parameters, scriptObj.relativeSignalsPath ?? '', visualizationHandler, contextCreator(instance, evt, e, scriptObj.parameters, scriptObj.relativeSignalsPath));
436
437
  });
437
438
  }
438
439
  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.97",
4
+ "version": "0.1.99",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",