@node-projects/web-component-designer-visualization-addons 0.1.117 → 0.1.119
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.
|
@@ -8,7 +8,7 @@ export class BindingsEditor extends BaseCustomWebComponentConstructorAppend {
|
|
|
8
8
|
<div style="grid-column: 1/3">
|
|
9
9
|
<div style="display: flex; flex-direction: column;">
|
|
10
10
|
<div class="row">
|
|
11
|
-
<span style="cursor: pointer;" title="to use multiple objects, seprate them with semicolon (;).
Access signal objects in properties via ?propertyName, access the propertyValue via ??propertyName.
Access signal objects in properties of the target via #propertyName, access
|
|
11
|
+
<span style="cursor: pointer;" title="to use multiple objects, seprate them with semicolon (;).
Access signal objects in properties via ?propertyName, access the propertyValue via ??propertyName.
Access signal objects in properties of the target via #propertyName, access a propertyValue of the target via ##propertyName.
Bind to signal configurations via $objectId.
You could also use signals inside of a Signal Name via {name}">objects</span>
|
|
12
12
|
</div>
|
|
13
13
|
<div id="groupObjectName" style="display:flex;align-items: flex-end;">
|
|
14
14
|
<input id="objectName" class="row" value="{{?this.objectNames::change}}" style="flex-grow: 1;">
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VisualizationBinding } from "../interfaces/VisualizationBinding.js";
|
|
2
|
-
import {
|
|
2
|
+
import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
|
|
3
3
|
import { BindingTarget } from "@node-projects/web-component-designer/dist/elements/item/BindingTarget.js";
|
|
4
4
|
export type SpecialValueHandler = {
|
|
5
5
|
valueProvider: (propertyName: string, context: {
|
|
@@ -23,33 +23,15 @@ export declare const bindingPrefixInsideCssVarName = "--tmpBinding_";
|
|
|
23
23
|
export declare const bindingsInCssRegex: RegExp;
|
|
24
24
|
export type namedBinding = [name: string, binding: VisualizationBinding];
|
|
25
25
|
export declare function isLit(element: Element): boolean;
|
|
26
|
-
export declare function getChangeEventName(element: Element, propertyName: string): string;
|
|
27
26
|
export declare function parseBindingString(id: string): {
|
|
28
27
|
parts: string[];
|
|
29
28
|
signals: string[];
|
|
30
29
|
};
|
|
31
|
-
export declare class IndirectSignal {
|
|
32
|
-
private parts;
|
|
33
|
-
private signals;
|
|
34
|
-
private values;
|
|
35
|
-
private unsubscribeList;
|
|
36
|
-
private unsubscribeTargetValue;
|
|
37
|
-
private combinedName;
|
|
38
|
-
private disposed;
|
|
39
|
-
private valueChangedCb;
|
|
40
|
-
private visualizationHandler;
|
|
41
|
-
private element;
|
|
42
|
-
private relativeSignalPath;
|
|
43
|
-
constructor(visualizationHandler: VisualizationHandler, id: string, valueChangedCb: (value: State) => void, element: Element, relativeSignalPath: string, root: HTMLElement);
|
|
44
|
-
private parseIndirectBinding;
|
|
45
|
-
handleValueChanged(value: any, index: number): void;
|
|
46
|
-
dispose(): void;
|
|
47
|
-
setState(value: any): void;
|
|
48
|
-
}
|
|
49
30
|
export declare class BindingsHelper {
|
|
50
31
|
#private;
|
|
51
32
|
_visualizationHandler: VisualizationHandler;
|
|
52
33
|
constructor(visualizationHandler: VisualizationHandler);
|
|
34
|
+
getChangedEventName(element: Element, propertyName: string): string;
|
|
53
35
|
parseBinding(element: Element, name: string, value: string, bindingTarget: BindingTarget, prefix: string): namedBinding;
|
|
54
36
|
serializeBinding(element: Element, targetName: string, binding: VisualizationBinding): [name: string, value: string];
|
|
55
37
|
getBindingAttributeName(element: Element, propertyName: string, propertyTarget: BindingTarget): string;
|
|
@@ -15,11 +15,6 @@ export function isLit(element) {
|
|
|
15
15
|
//@ts-ignore
|
|
16
16
|
return element.constructor?.elementProperties != null;
|
|
17
17
|
}
|
|
18
|
-
export function getChangeEventName(element, propertyName) {
|
|
19
|
-
if (isLit(element))
|
|
20
|
-
return propertyName;
|
|
21
|
-
return propertyName + '-changed';
|
|
22
|
-
}
|
|
23
18
|
export function parseBindingString(id) {
|
|
24
19
|
let parts = [];
|
|
25
20
|
let signals = [];
|
|
@@ -40,19 +35,19 @@ export function parseBindingString(id) {
|
|
|
40
35
|
parts.push(tx);
|
|
41
36
|
return { parts, signals };
|
|
42
37
|
}
|
|
43
|
-
|
|
38
|
+
class IndirectSignal {
|
|
44
39
|
parts;
|
|
45
40
|
signals;
|
|
46
41
|
values;
|
|
47
|
-
unsubscribeList = [];
|
|
48
42
|
unsubscribeTargetValue;
|
|
43
|
+
cleanupCalls = [];
|
|
49
44
|
combinedName;
|
|
50
45
|
disposed;
|
|
51
46
|
valueChangedCb;
|
|
52
47
|
visualizationHandler;
|
|
53
48
|
element;
|
|
54
49
|
relativeSignalPath;
|
|
55
|
-
constructor(visualizationHandler, id, valueChangedCb, element, relativeSignalPath, root) {
|
|
50
|
+
constructor(bindingsHelper, visualizationHandler, id, valueChangedCb, element, relativeSignalPath, root) {
|
|
56
51
|
this.visualizationHandler = visualizationHandler;
|
|
57
52
|
this.valueChangedCb = valueChangedCb;
|
|
58
53
|
this.element = element;
|
|
@@ -62,21 +57,34 @@ export class IndirectSignal {
|
|
|
62
57
|
for (let i = 0; i < this.signals.length; i++) {
|
|
63
58
|
let nm = this.signals[i];
|
|
64
59
|
if (nm[0] === '?' && nm[1] === '?') {
|
|
65
|
-
|
|
60
|
+
const propNm = nm.substring(2);
|
|
61
|
+
this.handleValueChanged(root[propNm], i);
|
|
62
|
+
const evtCallback = () => this.handleValueChanged(root[propNm], i);
|
|
63
|
+
const evtName = bindingsHelper.getChangedEventName(root, propNm);
|
|
64
|
+
root.addEventListener(evtName, (evtCallback));
|
|
65
|
+
this.cleanupCalls.push(() => root.removeEventListener(evtName, evtCallback));
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
68
|
else if (nm[0] === '#' && nm[1] === '#') {
|
|
69
|
-
|
|
69
|
+
const propNm = nm.substring(2);
|
|
70
|
+
this.handleValueChanged(element[propNm], i);
|
|
71
|
+
const evtCallback = () => this.handleValueChanged(element[propNm], i);
|
|
72
|
+
const evtName = bindingsHelper.getChangedEventName(element, propNm);
|
|
73
|
+
element.addEventListener(evtName, (evtCallback));
|
|
74
|
+
this.cleanupCalls.push(() => element.removeEventListener(evtName, evtCallback));
|
|
70
75
|
continue;
|
|
71
76
|
}
|
|
72
77
|
else if (nm[0] === '?') {
|
|
78
|
+
//TODO: react to changes of signal name in prop
|
|
73
79
|
nm = root[nm.substring(1)];
|
|
74
80
|
}
|
|
75
81
|
else if (nm[0] === '#') {
|
|
82
|
+
//TODO: react to changes of signal name in prop
|
|
76
83
|
nm = element[nm.substring(1)];
|
|
77
84
|
}
|
|
78
85
|
let cb = (id, value) => this.handleValueChanged(value.val, i);
|
|
79
|
-
|
|
86
|
+
const subscr = this.visualizationHandler.subscribeState(nm, cb);
|
|
87
|
+
this.cleanupCalls.push(() => this.visualizationHandler.unsubscribeState(this.signals[i], cb, subscr));
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
90
|
parseIndirectBinding(id) {
|
|
@@ -117,7 +125,7 @@ export class IndirectSignal {
|
|
|
117
125
|
this.unsubscribeTargetValue = null;
|
|
118
126
|
}
|
|
119
127
|
for (let i = 0; i < this.signals.length; i++) {
|
|
120
|
-
this.
|
|
128
|
+
this.cleanupCalls[i]();
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
131
|
setState(value) {
|
|
@@ -131,6 +139,18 @@ export class BindingsHelper {
|
|
|
131
139
|
constructor(visualizationHandler) {
|
|
132
140
|
this._visualizationHandler = visualizationHandler;
|
|
133
141
|
}
|
|
142
|
+
getChangedEventName(element, propertyName) {
|
|
143
|
+
const posColon = propertyName.indexOf('::');
|
|
144
|
+
if (posColon >= 0)
|
|
145
|
+
return propertyName.substring(posColon + 2);
|
|
146
|
+
if (element instanceof HTMLInputElement)
|
|
147
|
+
return 'change';
|
|
148
|
+
if (element instanceof HTMLSelectElement)
|
|
149
|
+
return 'change';
|
|
150
|
+
if (isLit(element))
|
|
151
|
+
return PropertiesHelper.camelToDashCase(propertyName);
|
|
152
|
+
return PropertiesHelper.camelToDashCase(propertyName) + '-changed';
|
|
153
|
+
}
|
|
134
154
|
//Not allowed chars in Var Names: |{}(),;:[]
|
|
135
155
|
parseBinding(element, name, value, bindingTarget, prefix) {
|
|
136
156
|
//Loooks like:
|
|
@@ -158,18 +178,18 @@ export class BindingsHelper {
|
|
|
158
178
|
binding.twoWay = true;
|
|
159
179
|
if (!binding.events) {
|
|
160
180
|
if (element instanceof HTMLInputElement)
|
|
161
|
-
binding.events = [
|
|
181
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
162
182
|
else if (element instanceof HTMLSelectElement)
|
|
163
|
-
binding.events = [
|
|
183
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
164
184
|
else {
|
|
165
185
|
if (isLit(element)) {
|
|
166
|
-
binding.events = [propname];
|
|
186
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
167
187
|
}
|
|
168
188
|
else {
|
|
169
|
-
binding.events = [propname
|
|
189
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
170
190
|
//Binding could be a lit elemnt but not yet loaded
|
|
171
191
|
binding.maybeLitElement = true;
|
|
172
|
-
binding.litEventNames = [propname];
|
|
192
|
+
binding.litEventNames = [this.getChangedEventName(element, propname)];
|
|
173
193
|
}
|
|
174
194
|
}
|
|
175
195
|
}
|
|
@@ -197,7 +217,7 @@ export class BindingsHelper {
|
|
|
197
217
|
else if (element instanceof HTMLSelectElement)
|
|
198
218
|
binding.events = ['change'];
|
|
199
219
|
else {
|
|
200
|
-
binding.events = [
|
|
220
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
201
221
|
}
|
|
202
222
|
}
|
|
203
223
|
if (bindingTarget === BindingTarget.cssvar || bindingTarget === BindingTarget.class)
|
|
@@ -577,7 +597,7 @@ export class BindingsHelper {
|
|
|
577
597
|
cleanUp();
|
|
578
598
|
this.applyBinding(element, binding, relativeSignalPath, root, specialValueHandler);
|
|
579
599
|
};
|
|
580
|
-
const evtNm =
|
|
600
|
+
const evtNm = this.getChangedEventName(root, s);
|
|
581
601
|
root.addEventListener(evtNm, evtCallback);
|
|
582
602
|
if (!cleanupCalls)
|
|
583
603
|
cleanupCalls = [];
|
|
@@ -600,7 +620,7 @@ export class BindingsHelper {
|
|
|
600
620
|
cleanUp();
|
|
601
621
|
this.applyBinding(element, binding, relativeSignalPath, root, specialValueHandler);
|
|
602
622
|
};
|
|
603
|
-
const evtNm =
|
|
623
|
+
const evtNm = this.getChangedEventName(element, s);
|
|
604
624
|
root.addEventListener(evtNm, evtCallback);
|
|
605
625
|
if (!cleanupCalls)
|
|
606
626
|
cleanupCalls = [];
|
|
@@ -691,7 +711,7 @@ export class BindingsHelper {
|
|
|
691
711
|
}
|
|
692
712
|
else {
|
|
693
713
|
if (s.includes('{')) {
|
|
694
|
-
let indirectSignal = new IndirectSignal(this._visualizationHandler, s, (value) => this.handleValueChanged(element, binding, value.val, valuesObject, i, signalVars, false, relativeSignalPath), element, relativeSignalPath, root);
|
|
714
|
+
let indirectSignal = new IndirectSignal(this, this._visualizationHandler, s, (value) => this.handleValueChanged(element, binding, value.val, valuesObject, i, signalVars, false, relativeSignalPath), element, relativeSignalPath, root);
|
|
695
715
|
if (!cleanupCalls)
|
|
696
716
|
cleanupCalls = [];
|
|
697
717
|
cleanupCalls.push(() => indirectSignal.dispose());
|
|
@@ -16,7 +16,10 @@ export interface VisualizationHandler {
|
|
|
16
16
|
getState(id: string): Promise<State>;
|
|
17
17
|
setState(id: string, val: State | StateValue, ack?: boolean): Promise<void>;
|
|
18
18
|
subscribeState(id: string, cb: StateChangeHandler): any;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @param {any} subscriptionResult - the result of the subscribe call
|
|
21
|
+
*/
|
|
22
|
+
unsubscribeState(id: string, cb: StateChangeHandler, subscriptionResult: any): void;
|
|
20
23
|
getHistoricData(id: string, config: any): any;
|
|
21
24
|
getObject(id: string): Promise<Signal>;
|
|
22
25
|
writeSignalsInGroup?(group: string): Promise<void>;
|
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.
|
|
4
|
+
"version": "0.1.119",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|