@node-projects/web-component-designer-visualization-addons 0.1.0

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.
Files changed (78) hide show
  1. package/README.md +19 -0
  2. package/dist/blockly/BlocklyJavascriptHelper.d.ts +2 -0
  3. package/dist/blockly/BlocklyJavascriptHelper.js +35 -0
  4. package/dist/blockly/BlocklyScriptEditor.d.ts +16 -0
  5. package/dist/blockly/BlocklyScriptEditor.js +106 -0
  6. package/dist/blockly/BlocklyToolbox.d.ts +1117 -0
  7. package/dist/blockly/BlocklyToolbox.js +980 -0
  8. package/dist/blockly/components/Console.d.ts +0 -0
  9. package/dist/blockly/components/Console.js +26 -0
  10. package/dist/blockly/components/Debugger.d.ts +0 -0
  11. package/dist/blockly/components/Debugger.js +15 -0
  12. package/dist/blockly/components/GetState.d.ts +0 -0
  13. package/dist/blockly/components/GetState.js +21 -0
  14. package/dist/blockly/components/GetSubProperty.d.ts +0 -0
  15. package/dist/blockly/components/GetSubProperty.js +27 -0
  16. package/dist/blockly/components/OpenScreen.d.ts +0 -0
  17. package/dist/blockly/components/OpenScreen.js +31 -0
  18. package/dist/blockly/components/QuerySelector.d.ts +0 -0
  19. package/dist/blockly/components/QuerySelector.js +30 -0
  20. package/dist/blockly/components/QuerySelectorAll.d.ts +0 -0
  21. package/dist/blockly/components/QuerySelectorAll.js +30 -0
  22. package/dist/blockly/components/Return.d.ts +0 -0
  23. package/dist/blockly/components/Return.js +21 -0
  24. package/dist/blockly/components/SetElement.d.ts +0 -0
  25. package/dist/blockly/components/SetElement.js +44 -0
  26. package/dist/blockly/components/SetState.d.ts +0 -0
  27. package/dist/blockly/components/SetState.js +26 -0
  28. package/dist/blockly/components/StartEvent.d.ts +0 -0
  29. package/dist/blockly/components/StartEvent.js +23 -0
  30. package/dist/blockly/components/components.d.ts +11 -0
  31. package/dist/blockly/components/components.js +11 -0
  32. package/dist/blockly/components/fields/FieldObjectId.d.ts +1 -0
  33. package/dist/blockly/components/fields/FieldObjectId.js +6 -0
  34. package/dist/components/BindingsEditor.d.ts +49 -0
  35. package/dist/components/BindingsEditor.js +298 -0
  36. package/dist/components/BindingsEditorHistoric.d.ts +14 -0
  37. package/dist/components/BindingsEditorHistoric.js +97 -0
  38. package/dist/components/PropertyGridExt.d.ts +0 -0
  39. package/dist/components/PropertyGridExt.js +1 -0
  40. package/dist/components/ScriptEditor.d.ts +28 -0
  41. package/dist/components/ScriptEditor.js +254 -0
  42. package/dist/components/VisualizationPropertyGrid.d.ts +12 -0
  43. package/dist/components/VisualizationPropertyGrid.js +104 -0
  44. package/dist/helpers/BindingsHelper.d.ts +47 -0
  45. package/dist/helpers/BindingsHelper.js +642 -0
  46. package/dist/index.d.ts +21 -0
  47. package/dist/index.js +22 -0
  48. package/dist/interfaces/IScriptMultiplexValue.d.ts +15 -0
  49. package/dist/interfaces/IScriptMultiplexValue.js +15 -0
  50. package/dist/interfaces/VisualisationElementScript.d.ts +5 -0
  51. package/dist/interfaces/VisualisationElementScript.js +1 -0
  52. package/dist/interfaces/VisualizationBinding.d.ts +20 -0
  53. package/dist/interfaces/VisualizationBinding.js +4 -0
  54. package/dist/interfaces/VisualizationHandler.d.ts +24 -0
  55. package/dist/interfaces/VisualizationHandler.js +2 -0
  56. package/dist/interfaces/VisualizationShell.d.ts +13 -0
  57. package/dist/interfaces/VisualizationShell.js +1 -0
  58. package/dist/interfaces/VisualizationUiHandler.d.ts +5 -0
  59. package/dist/interfaces/VisualizationUiHandler.js +2 -0
  60. package/dist/scripting/Script.d.ts +6 -0
  61. package/dist/scripting/Script.js +5 -0
  62. package/dist/scripting/ScriptCommands.d.ts +192 -0
  63. package/dist/scripting/ScriptCommands.js +1 -0
  64. package/dist/scripting/ScriptSystem.d.ts +23 -0
  65. package/dist/scripting/ScriptSystem.js +224 -0
  66. package/dist/services/BindableObjectDragDropService.d.ts +16 -0
  67. package/dist/services/BindableObjectDragDropService.js +145 -0
  68. package/dist/services/BindingsService.d.ts +11 -0
  69. package/dist/services/BindingsService.js +46 -0
  70. package/dist/services/PropertyGridDragDropService.d.ts +7 -0
  71. package/dist/services/PropertyGridDragDropService.js +10 -0
  72. package/dist/services/ScriptRefactorService.d.ts +9 -0
  73. package/dist/services/ScriptRefactorService.js +79 -0
  74. package/dist/services/SignalPropertyEditor.d.ts +7 -0
  75. package/dist/services/SignalPropertyEditor.js +43 -0
  76. package/dist/setupVisuService.d.ts +0 -0
  77. package/dist/setupVisuService.js +1 -0
  78. package/package.json +29 -0
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # web-component-designer-visualization-addons
2
+
3
+ ## NPM Package
4
+
5
+ https://www.npmjs.com/package/@node-projects/web-component-designer-visualization-addons
6
+
7
+ npm i @node-projects/web-component-designer-visualization-addons
8
+
9
+ ## Description
10
+
11
+ This package contains basic elements for a custom visualization, like a script system, a bindings system, ...
12
+ It is used for example by the iobroker.webui.
13
+
14
+ ## Dependencies
15
+
16
+ - long
17
+ - blockly
18
+
19
+ ## Usage
@@ -0,0 +1,2 @@
1
+ import './components/components.js';
2
+ export declare function generateEventCodeFromBlockly(data: any): Promise<(event: Event, shadowRoot: ShadowRoot) => void>;
@@ -0,0 +1,35 @@
1
+ //import Blockly from 'blockly';
2
+ import './components/components.js';
3
+ //TODO: remove imports, only leave Runtime
4
+ const prefix = `function extractPart(obj: any, propertyPath: string) {
5
+ let retVal = obj;
6
+ for (let p of propertyPath.split('.')) {
7
+ retVal = retVal?.[p];
8
+ }
9
+ return retVal;
10
+ }
11
+
12
+ export async function run(eventData, shadowRoot) {
13
+ `;
14
+ const postfix = `}`;
15
+ export async function generateEventCodeFromBlockly(data) {
16
+ //@ts-ignore
17
+ const workspace = new Blockly.Workspace();
18
+ //@ts-ignore
19
+ Blockly.serialization.workspaces.load(data, workspace);
20
+ //@ts-ignore
21
+ Blockly.JavaScript.addReservedWords('eventData');
22
+ //@ts-ignore
23
+ Blockly.JavaScript.addReservedWords('shadowRoot');
24
+ //@ts-ignore
25
+ Blockly.JavaScript.addReservedWords('extractPart');
26
+ //@ts-ignore
27
+ Blockly.JavaScript.addReservedWords('IOB');
28
+ //@ts-ignore
29
+ Blockly.JavaScript.addReservedWords('RUNTIME');
30
+ //@ts-ignore
31
+ let code = Blockly.JavaScript.workspaceToCode(workspace);
32
+ const scriptUrl = URL.createObjectURL(new Blob([prefix + code + postfix], { type: 'application/javascript' }));
33
+ const scripObj = await import(scriptUrl);
34
+ return scripObj.run;
35
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseCustomWebComponentConstructorAppend } from '@node-projects/base-custom-webcomponent';
2
+ export declare class BlocklyScriptEditor extends BaseCustomWebComponentConstructorAppend {
3
+ static readonly template: HTMLTemplateElement;
4
+ static readonly style: CSSStyleSheet;
5
+ static readonly is = "node-projects-blockly-script-editor";
6
+ blocklyDiv: HTMLDivElement;
7
+ workspace: any;
8
+ static blocklyStyle1: CSSStyleSheet;
9
+ static blocklyStyle2: CSSStyleSheet;
10
+ resizeObserver: ResizeObserver;
11
+ constructor();
12
+ createBlockly(): void;
13
+ ready(): void;
14
+ save(): any;
15
+ load(data: any): void;
16
+ }
@@ -0,0 +1,106 @@
1
+ import { BaseCustomWebComponentConstructorAppend, html, css } from '@node-projects/base-custom-webcomponent';
2
+ import toolbox from './BlocklyToolbox.js';
3
+ //import Blockly from 'blockly';
4
+ export class BlocklyScriptEditor extends BaseCustomWebComponentConstructorAppend {
5
+ static template = html `
6
+ <div id="blocklyDiv" style="position: absolute; width: 100%; height: 100%;"></div>
7
+ `;
8
+ static style = css `
9
+ :host {
10
+ box-sizing: border-box;
11
+ position: absolute;
12
+ height: 100%;
13
+ width: 100%;
14
+ }`;
15
+ static is = 'node-projects-blockly-script-editor';
16
+ blocklyDiv;
17
+ workspace;
18
+ static blocklyStyle1;
19
+ static blocklyStyle2;
20
+ resizeObserver;
21
+ constructor() {
22
+ super();
23
+ super._restoreCachedInititalValues();
24
+ this.blocklyDiv = this._getDomElement('blocklyDiv');
25
+ this._assignEvents();
26
+ this.createBlockly();
27
+ }
28
+ createBlockly() {
29
+ const renderer = 'zelos';
30
+ const themename = 'webui';
31
+ //@ts-ignore
32
+ const theme = Blockly.Theme.defineTheme(themename, {
33
+ //@ts-ignore
34
+ 'base': Blockly.Themes.Classic,
35
+ 'blockStyles': {
36
+ "hat_blocks": {
37
+ "colourPrimary": "#4a148c"
38
+ }
39
+ },
40
+ 'categoryStyles': {
41
+ 'start_category': {
42
+ colour: '#4a148c'
43
+ },
44
+ 'system_category': {
45
+ colour: '#01579b',
46
+ }
47
+ },
48
+ });
49
+ //@ts-ignore
50
+ this.workspace = Blockly.inject(this.blocklyDiv, {
51
+ theme: theme,
52
+ toolbox: toolbox,
53
+ renderer: renderer,
54
+ trashcan: true,
55
+ zoom: {
56
+ controls: true,
57
+ wheel: false,
58
+ startScale: 0.7,
59
+ maxScale: 3,
60
+ minScale: 0.3,
61
+ scaleSpeed: 1.2,
62
+ pinch: false
63
+ },
64
+ move: {
65
+ scrollbars: {
66
+ horizontal: true,
67
+ vertical: true
68
+ },
69
+ drag: true,
70
+ wheel: true
71
+ },
72
+ maxInstances: { 'start_event': 1 },
73
+ });
74
+ if (!BlocklyScriptEditor.blocklyStyle1) {
75
+ BlocklyScriptEditor.blocklyStyle1 = new CSSStyleSheet();
76
+ //@ts-ignore
77
+ BlocklyScriptEditor.blocklyStyle1.replaceSync(document.getElementById('blockly-renderer-style-' + renderer + '-' + themename).innerText);
78
+ BlocklyScriptEditor.blocklyStyle2 = new CSSStyleSheet();
79
+ //@ts-ignore
80
+ BlocklyScriptEditor.blocklyStyle2.replaceSync(document.getElementById('blockly-common-style').innerText);
81
+ }
82
+ this.shadowRoot.adoptedStyleSheets = [BlocklyScriptEditor.blocklyStyle1, BlocklyScriptEditor.blocklyStyle2, BlocklyScriptEditor.style];
83
+ //@ts-ignore
84
+ const zoomToFit = new ZoomToFitControl(this.workspace);
85
+ zoomToFit.init();
86
+ }
87
+ ready() {
88
+ //@ts-ignore
89
+ Blockly.svgResize(this.workspace);
90
+ this.resizeObserver = new ResizeObserver((entries) => {
91
+ //@ts-ignore
92
+ Blockly.svgResize(this.workspace);
93
+ });
94
+ this.resizeObserver.observe(this);
95
+ }
96
+ save() {
97
+ //@ts-ignore
98
+ const state = Blockly.serialization.workspaces.save(this.workspace);
99
+ return state;
100
+ }
101
+ load(data) {
102
+ //@ts-ignore
103
+ Blockly.serialization.workspaces.load(data, this.workspace);
104
+ }
105
+ }
106
+ customElements.define(BlocklyScriptEditor.is, BlocklyScriptEditor);