@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.
- package/README.md +19 -0
- package/dist/blockly/BlocklyJavascriptHelper.d.ts +2 -0
- package/dist/blockly/BlocklyJavascriptHelper.js +35 -0
- package/dist/blockly/BlocklyScriptEditor.d.ts +16 -0
- package/dist/blockly/BlocklyScriptEditor.js +106 -0
- package/dist/blockly/BlocklyToolbox.d.ts +1117 -0
- package/dist/blockly/BlocklyToolbox.js +980 -0
- package/dist/blockly/components/Console.d.ts +0 -0
- package/dist/blockly/components/Console.js +26 -0
- package/dist/blockly/components/Debugger.d.ts +0 -0
- package/dist/blockly/components/Debugger.js +15 -0
- package/dist/blockly/components/GetState.d.ts +0 -0
- package/dist/blockly/components/GetState.js +21 -0
- package/dist/blockly/components/GetSubProperty.d.ts +0 -0
- package/dist/blockly/components/GetSubProperty.js +27 -0
- package/dist/blockly/components/OpenScreen.d.ts +0 -0
- package/dist/blockly/components/OpenScreen.js +31 -0
- package/dist/blockly/components/QuerySelector.d.ts +0 -0
- package/dist/blockly/components/QuerySelector.js +30 -0
- package/dist/blockly/components/QuerySelectorAll.d.ts +0 -0
- package/dist/blockly/components/QuerySelectorAll.js +30 -0
- package/dist/blockly/components/Return.d.ts +0 -0
- package/dist/blockly/components/Return.js +21 -0
- package/dist/blockly/components/SetElement.d.ts +0 -0
- package/dist/blockly/components/SetElement.js +44 -0
- package/dist/blockly/components/SetState.d.ts +0 -0
- package/dist/blockly/components/SetState.js +26 -0
- package/dist/blockly/components/StartEvent.d.ts +0 -0
- package/dist/blockly/components/StartEvent.js +23 -0
- package/dist/blockly/components/components.d.ts +11 -0
- package/dist/blockly/components/components.js +11 -0
- package/dist/blockly/components/fields/FieldObjectId.d.ts +1 -0
- package/dist/blockly/components/fields/FieldObjectId.js +6 -0
- package/dist/components/BindingsEditor.d.ts +49 -0
- package/dist/components/BindingsEditor.js +298 -0
- package/dist/components/BindingsEditorHistoric.d.ts +14 -0
- package/dist/components/BindingsEditorHistoric.js +97 -0
- package/dist/components/PropertyGridExt.d.ts +0 -0
- package/dist/components/PropertyGridExt.js +1 -0
- package/dist/components/ScriptEditor.d.ts +28 -0
- package/dist/components/ScriptEditor.js +254 -0
- package/dist/components/VisualizationPropertyGrid.d.ts +12 -0
- package/dist/components/VisualizationPropertyGrid.js +104 -0
- package/dist/helpers/BindingsHelper.d.ts +47 -0
- package/dist/helpers/BindingsHelper.js +642 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +22 -0
- package/dist/interfaces/IScriptMultiplexValue.d.ts +15 -0
- package/dist/interfaces/IScriptMultiplexValue.js +15 -0
- package/dist/interfaces/VisualisationElementScript.d.ts +5 -0
- package/dist/interfaces/VisualisationElementScript.js +1 -0
- package/dist/interfaces/VisualizationBinding.d.ts +20 -0
- package/dist/interfaces/VisualizationBinding.js +4 -0
- package/dist/interfaces/VisualizationHandler.d.ts +24 -0
- package/dist/interfaces/VisualizationHandler.js +2 -0
- package/dist/interfaces/VisualizationShell.d.ts +13 -0
- package/dist/interfaces/VisualizationShell.js +1 -0
- package/dist/interfaces/VisualizationUiHandler.d.ts +5 -0
- package/dist/interfaces/VisualizationUiHandler.js +2 -0
- package/dist/scripting/Script.d.ts +6 -0
- package/dist/scripting/Script.js +5 -0
- package/dist/scripting/ScriptCommands.d.ts +192 -0
- package/dist/scripting/ScriptCommands.js +1 -0
- package/dist/scripting/ScriptSystem.d.ts +23 -0
- package/dist/scripting/ScriptSystem.js +224 -0
- package/dist/services/BindableObjectDragDropService.d.ts +16 -0
- package/dist/services/BindableObjectDragDropService.js +145 -0
- package/dist/services/BindingsService.d.ts +11 -0
- package/dist/services/BindingsService.js +46 -0
- package/dist/services/PropertyGridDragDropService.d.ts +7 -0
- package/dist/services/PropertyGridDragDropService.js +10 -0
- package/dist/services/ScriptRefactorService.d.ts +9 -0
- package/dist/services/ScriptRefactorService.js +79 -0
- package/dist/services/SignalPropertyEditor.d.ts +7 -0
- package/dist/services/SignalPropertyEditor.js +43 -0
- package/dist/setupVisuService.d.ts +0 -0
- package/dist/setupVisuService.js +1 -0
- package/package.json +29 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from './blockly/BlocklyJavascriptHelper.js';
|
|
2
|
+
export * from './blockly/BlocklyScriptEditor.js';
|
|
3
|
+
export * from './blockly/BlocklyToolbox.js';
|
|
4
|
+
export * from './blockly/components/components.js';
|
|
5
|
+
export * from './components/BindingsEditor.js';
|
|
6
|
+
export * from './components/BindingsEditorHistoric.js';
|
|
7
|
+
export * from './helpers/BindingsHelper.js';
|
|
8
|
+
export * from './interfaces/IScriptMultiplexValue.js';
|
|
9
|
+
export * from './interfaces/VisualisationElementScript.js';
|
|
10
|
+
export * from './interfaces/VisualizationBinding.js';
|
|
11
|
+
export * from './interfaces/VisualizationHandler.js';
|
|
12
|
+
export * from './interfaces/VisualizationShell.js';
|
|
13
|
+
export * from './interfaces/VisualizationUiHandler.js';
|
|
14
|
+
export * from './scripting/Script.js';
|
|
15
|
+
export * from './scripting/ScriptCommands.js';
|
|
16
|
+
export * from './scripting/ScriptSystem.js';
|
|
17
|
+
export * from './services/BindableObjectDragDropService.js';
|
|
18
|
+
export * from './services/BindingsService.js';
|
|
19
|
+
export * from './services/PropertyGridDragDropService.js';
|
|
20
|
+
export * from './services/ScriptRefactorService.js';
|
|
21
|
+
export * from './services/SignalPropertyEditor.js';
|
|
22
|
+
//export * from './setupVisuService.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class IScriptMultiplexValue {
|
|
2
|
+
/**
|
|
3
|
+
* signal - read the value from a IOB object
|
|
4
|
+
* property - read the value from a property of the customControl (not usable in screens)
|
|
5
|
+
* event - read the value of a property of the event object
|
|
6
|
+
* @TJS-format signal
|
|
7
|
+
*/
|
|
8
|
+
source: 'signal' | 'property' | 'event';
|
|
9
|
+
/**
|
|
10
|
+
* Name of the ioBroker object or the property of the component
|
|
11
|
+
* or for example in a event : srcElement.value to get the value of a input wich raises the event
|
|
12
|
+
* @TJS-format signal
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class IScriptMultiplexValue {
|
|
2
|
+
/**
|
|
3
|
+
* signal - read the value from a IOB object
|
|
4
|
+
* property - read the value from a property of the customControl (not usable in screens)
|
|
5
|
+
* event - read the value of a property of the event object
|
|
6
|
+
* @TJS-format signal
|
|
7
|
+
*/
|
|
8
|
+
source;
|
|
9
|
+
/**
|
|
10
|
+
* Name of the ioBroker object or the property of the component
|
|
11
|
+
* or for example in a event : srcElement.value to get the value of a input wich raises the event
|
|
12
|
+
* @TJS-format signal
|
|
13
|
+
*/
|
|
14
|
+
name;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BindingTarget } from "@node-projects/web-component-designer";
|
|
2
|
+
export interface VisualizationBinding {
|
|
3
|
+
interval?: number;
|
|
4
|
+
signal: string;
|
|
5
|
+
inverted?: boolean;
|
|
6
|
+
twoWay?: boolean;
|
|
7
|
+
events?: string[];
|
|
8
|
+
target: BindingTarget;
|
|
9
|
+
converter?: Record<string, any>;
|
|
10
|
+
expression?: string;
|
|
11
|
+
expressionTwoWay?: string;
|
|
12
|
+
compiledExpression?: Function;
|
|
13
|
+
compiledExpressionTwoWay?: Function;
|
|
14
|
+
type?: string;
|
|
15
|
+
historic?: {
|
|
16
|
+
reloadInterval?: number;
|
|
17
|
+
};
|
|
18
|
+
maybeLitElement?: boolean;
|
|
19
|
+
litEventNames?: string[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type StateValue = string | number | boolean | null;
|
|
2
|
+
export interface State {
|
|
3
|
+
value: StateValue;
|
|
4
|
+
}
|
|
5
|
+
export interface Signal {
|
|
6
|
+
"$type": 'Signal';
|
|
7
|
+
}
|
|
8
|
+
export interface SignalInformation {
|
|
9
|
+
type: 'string' | 'number' | 'boolean';
|
|
10
|
+
role: 'url' | 'datetime' | 'date' | 'time';
|
|
11
|
+
writeable: boolean;
|
|
12
|
+
}
|
|
13
|
+
type StateChangeHandler = (id: string, state: State) => void;
|
|
14
|
+
export interface VisualizationHandler {
|
|
15
|
+
getState(id: string): Promise<State>;
|
|
16
|
+
setState(id: string, val: State | StateValue, ack?: boolean): Promise<void>;
|
|
17
|
+
subscribeState(id: string, cb: StateChangeHandler): Promise<void>;
|
|
18
|
+
unsubscribeState(id: string, cb: StateChangeHandler): void;
|
|
19
|
+
getObject(id: string): Promise<Signal>;
|
|
20
|
+
getHistoricData(id: string, config: any): any;
|
|
21
|
+
getAllNames(type: string): any;
|
|
22
|
+
getSignalInformation(signal: Signal): SignalInformation;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface VisualizationShell {
|
|
2
|
+
openConfirmation(element: HTMLElement, options: {
|
|
3
|
+
x?: number;
|
|
4
|
+
y?: number;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
parent?: HTMLElement;
|
|
8
|
+
abortSignal?: AbortSignal;
|
|
9
|
+
disableResize?: boolean;
|
|
10
|
+
confirmText?: string;
|
|
11
|
+
cancelText?: string;
|
|
12
|
+
}): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export declare type ScriptCommands = OpenScreen | OpenUrl | OpenDialog | CloseDialog | ToggleSignalValue | SetSignalValue | IncrementSignalValue | DecrementSignalValue | SetBitInSignal | ClearBitInSignal | ToggleBitInSignal | Console | CalculateSignalValue | Javascript | SetElementProperty | Delay | SwitchLanguage | Login | Logout;
|
|
2
|
+
export interface OpenScreen {
|
|
3
|
+
type: 'OpenScreen';
|
|
4
|
+
/**
|
|
5
|
+
* Name of the Screen
|
|
6
|
+
* @TJS-format screen
|
|
7
|
+
*/
|
|
8
|
+
screen: string;
|
|
9
|
+
/**
|
|
10
|
+
* If signals in screen are defined relative (starting with a '.'), this will be prepended
|
|
11
|
+
*/
|
|
12
|
+
relativeSignalsPath?: string;
|
|
13
|
+
noHistory?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface OpenDialog {
|
|
16
|
+
type: 'OpenDialog';
|
|
17
|
+
/**
|
|
18
|
+
* Name of the Screen
|
|
19
|
+
* @TJS-format screen
|
|
20
|
+
*/
|
|
21
|
+
screen: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
/**
|
|
24
|
+
* If signals in screen are defined relative (starting with a '.'), this will be prepended
|
|
25
|
+
*/
|
|
26
|
+
relativeSignalsPath?: string;
|
|
27
|
+
moveable?: boolean;
|
|
28
|
+
closeable?: boolean;
|
|
29
|
+
width?: string;
|
|
30
|
+
height?: string;
|
|
31
|
+
left?: string;
|
|
32
|
+
top?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface CloseDialog {
|
|
35
|
+
type: 'CloseDialog';
|
|
36
|
+
}
|
|
37
|
+
export interface OpenUrl {
|
|
38
|
+
type: 'OpenUrl';
|
|
39
|
+
url: string;
|
|
40
|
+
/**
|
|
41
|
+
* defaults to '_blank'
|
|
42
|
+
*/
|
|
43
|
+
target: string;
|
|
44
|
+
openInDialog: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface SetSignalValue {
|
|
47
|
+
type: 'SetSignalValue';
|
|
48
|
+
/**
|
|
49
|
+
* Name of the signal
|
|
50
|
+
* @TJS-format signal
|
|
51
|
+
*/
|
|
52
|
+
signal: string;
|
|
53
|
+
value: any;
|
|
54
|
+
}
|
|
55
|
+
export interface ToggleSignalValue {
|
|
56
|
+
type: 'ToggleSignalValue';
|
|
57
|
+
/**
|
|
58
|
+
* Name of the signal
|
|
59
|
+
* @TJS-format signal
|
|
60
|
+
*/
|
|
61
|
+
signal: string;
|
|
62
|
+
}
|
|
63
|
+
export interface IncrementSignalValue {
|
|
64
|
+
type: 'IncrementSignalValue';
|
|
65
|
+
/**
|
|
66
|
+
* Name of the signal
|
|
67
|
+
* @TJS-format signal
|
|
68
|
+
*/
|
|
69
|
+
signal: string;
|
|
70
|
+
value: number;
|
|
71
|
+
}
|
|
72
|
+
export interface CalculateSignalValue {
|
|
73
|
+
type: 'CalculateSignalValue';
|
|
74
|
+
/**
|
|
75
|
+
* Name of the signal
|
|
76
|
+
* @TJS-format signal
|
|
77
|
+
*/
|
|
78
|
+
targetSignal: string;
|
|
79
|
+
/**
|
|
80
|
+
* A formula to calculate the new signal value, can contain other signals in angle brackets: {}
|
|
81
|
+
* Example: {adapter.0.level} * 100 + 30
|
|
82
|
+
*/
|
|
83
|
+
formula: string;
|
|
84
|
+
}
|
|
85
|
+
export interface DecrementSignalValue {
|
|
86
|
+
type: 'DecrementSignalValue';
|
|
87
|
+
/**
|
|
88
|
+
* Name of the signal
|
|
89
|
+
* @TJS-format signal
|
|
90
|
+
*/
|
|
91
|
+
signal: string;
|
|
92
|
+
value: number;
|
|
93
|
+
}
|
|
94
|
+
export interface SetBitInSignal {
|
|
95
|
+
type: 'SetBitInSignal';
|
|
96
|
+
/**
|
|
97
|
+
* Name of the signal
|
|
98
|
+
* @TJS-format signal
|
|
99
|
+
*/
|
|
100
|
+
signal: string;
|
|
101
|
+
bitNumber: number;
|
|
102
|
+
}
|
|
103
|
+
export interface ClearBitInSignal {
|
|
104
|
+
type: 'ClearBitInSignal';
|
|
105
|
+
/**
|
|
106
|
+
* Name of the signal
|
|
107
|
+
* @TJS-format signal
|
|
108
|
+
*/
|
|
109
|
+
signal: string;
|
|
110
|
+
bitNumber: number;
|
|
111
|
+
}
|
|
112
|
+
export interface ToggleBitInSignal {
|
|
113
|
+
type: 'ToggleBitInSignal';
|
|
114
|
+
/**
|
|
115
|
+
* Name of the signal
|
|
116
|
+
* @TJS-format signal
|
|
117
|
+
*/
|
|
118
|
+
signal: string;
|
|
119
|
+
bitNumber: number;
|
|
120
|
+
}
|
|
121
|
+
export interface Javascript {
|
|
122
|
+
type: 'Javascript';
|
|
123
|
+
/**
|
|
124
|
+
* Usable objects in Script:
|
|
125
|
+
* context : {event : Event, element: Element, shadowRoot: ShadowRoot, instance: Element }
|
|
126
|
+
* @TJS-format script
|
|
127
|
+
*/
|
|
128
|
+
script: string;
|
|
129
|
+
}
|
|
130
|
+
export interface SetElementProperty {
|
|
131
|
+
type: 'SetElementProperty';
|
|
132
|
+
/**
|
|
133
|
+
* what of the elements do you want to set
|
|
134
|
+
*/
|
|
135
|
+
target: 'property' | 'attribute' | 'css' | 'class';
|
|
136
|
+
/**
|
|
137
|
+
* where to search for the elements
|
|
138
|
+
*/
|
|
139
|
+
targetSelectorTarget: 'currentScreen' | 'parentScreen' | 'currentElement' | 'parentElement';
|
|
140
|
+
/**
|
|
141
|
+
* css selector to find elements, if empty the targetSelectorTarget is used
|
|
142
|
+
*/
|
|
143
|
+
targetSelector: string;
|
|
144
|
+
/**
|
|
145
|
+
* name of property/attribute or css value you want to set
|
|
146
|
+
*/
|
|
147
|
+
name: string;
|
|
148
|
+
/**
|
|
149
|
+
* only for class
|
|
150
|
+
*/
|
|
151
|
+
mode: 'add' | 'remove' | 'toggle';
|
|
152
|
+
/**
|
|
153
|
+
* value you want to set
|
|
154
|
+
*/
|
|
155
|
+
value: any;
|
|
156
|
+
}
|
|
157
|
+
export interface Delay {
|
|
158
|
+
type: 'Delay';
|
|
159
|
+
/**
|
|
160
|
+
* miliseconds to delay
|
|
161
|
+
*/
|
|
162
|
+
value: number;
|
|
163
|
+
}
|
|
164
|
+
export interface Console {
|
|
165
|
+
type: 'Console';
|
|
166
|
+
/**
|
|
167
|
+
* target where to log
|
|
168
|
+
*/
|
|
169
|
+
target: 'log' | 'info' | 'debug' | 'warn' | 'error';
|
|
170
|
+
/**
|
|
171
|
+
* console message
|
|
172
|
+
*/
|
|
173
|
+
message: string;
|
|
174
|
+
}
|
|
175
|
+
export interface SwitchLanguage {
|
|
176
|
+
type: 'SwitchLanguage';
|
|
177
|
+
language: string;
|
|
178
|
+
}
|
|
179
|
+
export interface Logout {
|
|
180
|
+
type: 'Logout';
|
|
181
|
+
}
|
|
182
|
+
export interface Login {
|
|
183
|
+
type: 'Login';
|
|
184
|
+
/**
|
|
185
|
+
* username
|
|
186
|
+
*/
|
|
187
|
+
username: 'string';
|
|
188
|
+
/**
|
|
189
|
+
* password
|
|
190
|
+
*/
|
|
191
|
+
password: string;
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IScriptMultiplexValue } from "../interfaces/IScriptMultiplexValue.js";
|
|
2
|
+
import { VisualisationElementScript } from "../interfaces/VisualisationElementScript.js";
|
|
3
|
+
import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
|
|
4
|
+
import { ScriptCommands } from "./ScriptCommands.js";
|
|
5
|
+
import { VisualizationUiHandler } from "../interfaces/VisualizationUiHandler.js";
|
|
6
|
+
export declare class ScriptSystem {
|
|
7
|
+
_visualizationHandler: VisualizationHandler;
|
|
8
|
+
_visualizationUiHandler: VisualizationUiHandler;
|
|
9
|
+
constructor(visualizationHandler: VisualizationHandler, visualizationUiHandler: VisualizationUiHandler);
|
|
10
|
+
execute(scriptCommands: ScriptCommands[], outerContext: {
|
|
11
|
+
event: Event;
|
|
12
|
+
element: Element;
|
|
13
|
+
root: HTMLElement;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
runScriptCommand<T extends ScriptCommands>(command: T, context: any): Promise<void>;
|
|
16
|
+
getValue<T>(value: string | number | boolean | IScriptMultiplexValue, outerContext: {
|
|
17
|
+
event: Event;
|
|
18
|
+
element: Element;
|
|
19
|
+
root: HTMLElement;
|
|
20
|
+
}): Promise<any>;
|
|
21
|
+
static extractPart(obj: any, propertyPath: string): any;
|
|
22
|
+
assignAllScripts(source: string, javascriptCode: string, shadowRoot: ShadowRoot, instance: HTMLElement): Promise<VisualisationElementScript>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { sleep } from "@node-projects/web-component-designer/src/elements/helper/Helper.js";
|
|
2
|
+
import { generateEventCodeFromBlockly } from "../blockly/BlocklyJavascriptHelper.js";
|
|
3
|
+
import { parseBindingString } from "../helpers/BindingsHelper.js";
|
|
4
|
+
import Long from 'long';
|
|
5
|
+
export class ScriptSystem {
|
|
6
|
+
_visualizationHandler;
|
|
7
|
+
_visualizationUiHandler;
|
|
8
|
+
constructor(visualizationHandler, visualizationUiHandler) {
|
|
9
|
+
this._visualizationHandler = visualizationHandler;
|
|
10
|
+
}
|
|
11
|
+
async execute(scriptCommands, outerContext) {
|
|
12
|
+
for (let c of scriptCommands) {
|
|
13
|
+
this.runScriptCommand(c, outerContext);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async runScriptCommand(command, context) {
|
|
17
|
+
switch (command.type) {
|
|
18
|
+
case 'CloseDialog': {
|
|
19
|
+
//const dialogdId = await this.getValue(c.dialogId, outerContext);
|
|
20
|
+
this._visualizationUiHandler.closeDialog(context.element);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'OpenUrl': {
|
|
24
|
+
window.open(await this.getValue(command.url, context), command.target);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 'Delay': {
|
|
28
|
+
const value = await this.getValue(command.value, context);
|
|
29
|
+
await sleep(value);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case 'Console': {
|
|
33
|
+
const target = await this.getValue(command.target, context);
|
|
34
|
+
const message = await this.getValue(command.message, context);
|
|
35
|
+
console[target](message);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case 'SwitchLanguage': {
|
|
39
|
+
const language = await this.getValue(command.language, context);
|
|
40
|
+
this._visualizationUiHandler.switchLanguage(language);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'ToggleSignalValue': {
|
|
44
|
+
const signal = await this.getValue(command.signal, context);
|
|
45
|
+
let state = await this._visualizationHandler.getState(signal);
|
|
46
|
+
await this._visualizationHandler.setState(signal, !state?.value);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'SetSignalValue': {
|
|
50
|
+
const signal = await this.getValue(command.signal, context);
|
|
51
|
+
await this._visualizationHandler.setState(signal, await this.getValue(command.value, context));
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'IncrementSignalValue': {
|
|
55
|
+
const signal = await this.getValue(command.signal, context);
|
|
56
|
+
let state = await this._visualizationHandler.getState(signal);
|
|
57
|
+
await this._visualizationHandler.setState(signal, state.value + await this.getValue(command.value, context));
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'DecrementSignalValue': {
|
|
61
|
+
const signal = await this.getValue(command.signal, context);
|
|
62
|
+
let state = await this._visualizationHandler.getState(signal);
|
|
63
|
+
await this._visualizationHandler.setState(signal, state.value - await this.getValue(command.value, context));
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case 'CalculateSignalValue': {
|
|
67
|
+
const formula = await this.getValue(command.formula, context);
|
|
68
|
+
const targetSignal = await this.getValue(command.targetSignal, context);
|
|
69
|
+
let parsed = parseBindingString(formula);
|
|
70
|
+
let results = await Promise.all(parsed.signals.map(x => this._visualizationHandler.getState(x)));
|
|
71
|
+
let nm = '';
|
|
72
|
+
for (let i = 0; i < parsed.parts.length - 1; i++) {
|
|
73
|
+
let v = results[i].value;
|
|
74
|
+
if (v == null)
|
|
75
|
+
return;
|
|
76
|
+
nm += v + parsed.parts[i + 1];
|
|
77
|
+
}
|
|
78
|
+
let result = eval(nm);
|
|
79
|
+
await this._visualizationHandler.setState(targetSignal, result);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 'SetBitInSignal': {
|
|
83
|
+
const signal = await this.getValue(command.signal, context);
|
|
84
|
+
let state = await this._visualizationHandler.getState(signal);
|
|
85
|
+
let mask = Long.fromNumber(1).shiftLeft(command.bitNumber);
|
|
86
|
+
const newVal = Long.fromNumber(state.value).or(mask).toNumber();
|
|
87
|
+
await this._visualizationHandler.setState(signal, newVal);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 'ClearBitInSignal': {
|
|
91
|
+
const signal = await this.getValue(command.signal, context);
|
|
92
|
+
let state = await this._visualizationHandler.getState(signal);
|
|
93
|
+
let mask = Long.fromNumber(1).shiftLeft(command.bitNumber);
|
|
94
|
+
mask.negate();
|
|
95
|
+
const newVal = Long.fromNumber(state.value).and(mask).toNumber();
|
|
96
|
+
await this._visualizationHandler.setState(signal, newVal);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 'ToggleBitInSignal': {
|
|
100
|
+
const signal = await this.getValue(command.signal, context);
|
|
101
|
+
let state = await this._visualizationHandler.getState(signal);
|
|
102
|
+
let mask = Long.fromNumber(1).shiftLeft(command.bitNumber);
|
|
103
|
+
const newVal = Long.fromNumber(state.value).xor(mask).toNumber();
|
|
104
|
+
await this._visualizationHandler.setState(signal, newVal);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case 'Javascript': {
|
|
108
|
+
const script = await this.getValue(command.script, context);
|
|
109
|
+
let mycontext = context;
|
|
110
|
+
mycontext.shadowRoot = context.element.getRootNode();
|
|
111
|
+
mycontext.instance = context.shadowRoot.host;
|
|
112
|
+
if (!command.compiledScript)
|
|
113
|
+
command.compiledScript = new Function('context', script);
|
|
114
|
+
command.compiledScript(mycontext);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'SetElementProperty': {
|
|
118
|
+
const name = await this.getValue(command.name, context);
|
|
119
|
+
const value = await this.getValue(command.value, context);
|
|
120
|
+
let host = context.element.getRootNode().host;
|
|
121
|
+
if (command.targetSelectorTarget == 'currentElement')
|
|
122
|
+
host = context.element;
|
|
123
|
+
else if (command.targetSelectorTarget == 'parentElement')
|
|
124
|
+
host = context.element.parentElement;
|
|
125
|
+
else if (command.targetSelectorTarget == 'parentScreen')
|
|
126
|
+
host = host.getRootNode().host;
|
|
127
|
+
let elements = [host];
|
|
128
|
+
if (command.targetSelector)
|
|
129
|
+
elements = host.shadowRoot.querySelectorAll(command.targetSelector);
|
|
130
|
+
for (let e of elements) {
|
|
131
|
+
if (command.target == 'attribute') {
|
|
132
|
+
e.setAttribute(name, value);
|
|
133
|
+
}
|
|
134
|
+
else if (command.target == 'property') {
|
|
135
|
+
e[name] = value;
|
|
136
|
+
}
|
|
137
|
+
else if (command.target == 'css') {
|
|
138
|
+
e.style[name] = value;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async getValue(value, outerContext) {
|
|
146
|
+
if (typeof value === 'object') {
|
|
147
|
+
switch (value.source) {
|
|
148
|
+
case 'property': {
|
|
149
|
+
return outerContext.root[value.name];
|
|
150
|
+
}
|
|
151
|
+
case 'signal': {
|
|
152
|
+
let sng = await this._visualizationHandler.getState(value.name);
|
|
153
|
+
return sng.value;
|
|
154
|
+
}
|
|
155
|
+
case 'event': {
|
|
156
|
+
let obj = outerContext.event;
|
|
157
|
+
if (value.name)
|
|
158
|
+
obj = ScriptSystem.extractPart(obj, value.name);
|
|
159
|
+
return obj;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
static extractPart(obj, propertyPath) {
|
|
166
|
+
let retVal = obj;
|
|
167
|
+
for (let p of propertyPath.split('.')) {
|
|
168
|
+
retVal = retVal?.[p];
|
|
169
|
+
}
|
|
170
|
+
return retVal;
|
|
171
|
+
}
|
|
172
|
+
async assignAllScripts(source, javascriptCode, shadowRoot, instance) {
|
|
173
|
+
const allElements = shadowRoot.querySelectorAll('*');
|
|
174
|
+
let jsObject = null;
|
|
175
|
+
if (javascriptCode) {
|
|
176
|
+
try {
|
|
177
|
+
const scriptUrl = URL.createObjectURL(new Blob([javascriptCode], { type: 'application/javascript' }));
|
|
178
|
+
jsObject = await import(scriptUrl);
|
|
179
|
+
if (jsObject.init) {
|
|
180
|
+
jsObject.init(instance);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
console.error('error parsing javascript - ' + source, err);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (let e of allElements) {
|
|
188
|
+
for (let a of e.attributes) {
|
|
189
|
+
if (a.name[0] == '@') {
|
|
190
|
+
try {
|
|
191
|
+
let evtName = a.name.substring(1);
|
|
192
|
+
let script = a.value.trim();
|
|
193
|
+
if (script[0] == '{') {
|
|
194
|
+
let scriptObj = JSON.parse(script);
|
|
195
|
+
if ('commands' in scriptObj) {
|
|
196
|
+
e.addEventListener(evtName, (evt) => this.execute(scriptObj.commands, { event: evt, element: e, root: instance }));
|
|
197
|
+
}
|
|
198
|
+
else if ('blocks' in scriptObj) {
|
|
199
|
+
let compiledFunc = null;
|
|
200
|
+
e.addEventListener(evtName, async (evt) => {
|
|
201
|
+
if (!compiledFunc)
|
|
202
|
+
compiledFunc = await generateEventCodeFromBlockly(scriptObj);
|
|
203
|
+
compiledFunc(evt, shadowRoot);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
e.addEventListener(evtName, (evt) => {
|
|
209
|
+
if (!jsObject[script])
|
|
210
|
+
console.warn('javascript function named: ' + script + ' not found, maybe missing a "export" ?');
|
|
211
|
+
else
|
|
212
|
+
jsObject[script](evt, e, shadowRoot, instance);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
console.warn('error assigning script', e, a);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return jsObject;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IBindableObject, IBindableObjectDragDropService, IDesignerCanvas, IProperty, IDesignItem } from "@node-projects/web-component-designer";
|
|
2
|
+
import { BindingsHelper } from "../helpers/BindingsHelper.js";
|
|
3
|
+
import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
|
|
4
|
+
export declare class BindableObjectDragDropService implements IBindableObjectDragDropService {
|
|
5
|
+
constructor(bindingsHelper: BindingsHelper, visualizationHandler: VisualizationHandler);
|
|
6
|
+
private _bindingsHelper;
|
|
7
|
+
private _visualizationHandler;
|
|
8
|
+
rectMap: Map<Element, SVGRectElement>;
|
|
9
|
+
rect: SVGRectElement;
|
|
10
|
+
dragEnter(designerCanvas: IDesignerCanvas, event: DragEvent, element: Element): void;
|
|
11
|
+
dragLeave(designerCanvas: IDesignerCanvas, event: DragEvent, element: Element): void;
|
|
12
|
+
dragOver(designerView: IDesignerCanvas, event: DragEvent, element: Element): "none" | "copy" | "link" | "move";
|
|
13
|
+
drop(designerCanvas: IDesignerCanvas, event: DragEvent, bindableObject: IBindableObject<any>, element: Element): Promise<void>;
|
|
14
|
+
dragOverOnProperty?(event: DragEvent, property: IProperty, designItems: IDesignItem[]): 'none' | 'copy' | 'link' | 'move';
|
|
15
|
+
dropOnProperty?(event: DragEvent, property: IProperty, bindableObject: IBindableObject<any>, designItems: IDesignItem[]): void;
|
|
16
|
+
}
|