@node-projects/web-component-designer-visualization-addons 0.1.118 → 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,25 +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
|
-
|
|
66
|
-
this.handleValueChanged(root[
|
|
67
|
-
this.
|
|
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));
|
|
68
66
|
continue;
|
|
69
67
|
}
|
|
70
68
|
else if (nm[0] === '#' && nm[1] === '#') {
|
|
71
|
-
|
|
72
|
-
this.handleValueChanged(element[
|
|
73
|
-
this.
|
|
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));
|
|
74
75
|
continue;
|
|
75
76
|
}
|
|
76
77
|
else if (nm[0] === '?') {
|
|
78
|
+
//TODO: react to changes of signal name in prop
|
|
77
79
|
nm = root[nm.substring(1)];
|
|
78
80
|
}
|
|
79
81
|
else if (nm[0] === '#') {
|
|
82
|
+
//TODO: react to changes of signal name in prop
|
|
80
83
|
nm = element[nm.substring(1)];
|
|
81
84
|
}
|
|
82
85
|
let cb = (id, value) => this.handleValueChanged(value.val, i);
|
|
83
|
-
|
|
86
|
+
const subscr = this.visualizationHandler.subscribeState(nm, cb);
|
|
87
|
+
this.cleanupCalls.push(() => this.visualizationHandler.unsubscribeState(this.signals[i], cb, subscr));
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
parseIndirectBinding(id) {
|
|
@@ -121,9 +125,7 @@ export class IndirectSignal {
|
|
|
121
125
|
this.unsubscribeTargetValue = null;
|
|
122
126
|
}
|
|
123
127
|
for (let i = 0; i < this.signals.length; i++) {
|
|
124
|
-
|
|
125
|
-
this.visualizationHandler.unsubscribeState(this.signals[i], this.unsubscribeList[i][0], this.unsubscribeList[i][1]);
|
|
126
|
-
}
|
|
128
|
+
this.cleanupCalls[i]();
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
setState(value) {
|
|
@@ -137,6 +139,18 @@ export class BindingsHelper {
|
|
|
137
139
|
constructor(visualizationHandler) {
|
|
138
140
|
this._visualizationHandler = visualizationHandler;
|
|
139
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
|
+
}
|
|
140
154
|
//Not allowed chars in Var Names: |{}(),;:[]
|
|
141
155
|
parseBinding(element, name, value, bindingTarget, prefix) {
|
|
142
156
|
//Loooks like:
|
|
@@ -164,18 +178,18 @@ export class BindingsHelper {
|
|
|
164
178
|
binding.twoWay = true;
|
|
165
179
|
if (!binding.events) {
|
|
166
180
|
if (element instanceof HTMLInputElement)
|
|
167
|
-
binding.events = [
|
|
181
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
168
182
|
else if (element instanceof HTMLSelectElement)
|
|
169
|
-
binding.events = [
|
|
183
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
170
184
|
else {
|
|
171
185
|
if (isLit(element)) {
|
|
172
|
-
binding.events = [propname];
|
|
186
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
173
187
|
}
|
|
174
188
|
else {
|
|
175
|
-
binding.events = [propname
|
|
189
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
176
190
|
//Binding could be a lit elemnt but not yet loaded
|
|
177
191
|
binding.maybeLitElement = true;
|
|
178
|
-
binding.litEventNames = [propname];
|
|
192
|
+
binding.litEventNames = [this.getChangedEventName(element, propname)];
|
|
179
193
|
}
|
|
180
194
|
}
|
|
181
195
|
}
|
|
@@ -203,7 +217,7 @@ export class BindingsHelper {
|
|
|
203
217
|
else if (element instanceof HTMLSelectElement)
|
|
204
218
|
binding.events = ['change'];
|
|
205
219
|
else {
|
|
206
|
-
binding.events = [
|
|
220
|
+
binding.events = [this.getChangedEventName(element, propname)];
|
|
207
221
|
}
|
|
208
222
|
}
|
|
209
223
|
if (bindingTarget === BindingTarget.cssvar || bindingTarget === BindingTarget.class)
|
|
@@ -583,7 +597,7 @@ export class BindingsHelper {
|
|
|
583
597
|
cleanUp();
|
|
584
598
|
this.applyBinding(element, binding, relativeSignalPath, root, specialValueHandler);
|
|
585
599
|
};
|
|
586
|
-
const evtNm =
|
|
600
|
+
const evtNm = this.getChangedEventName(root, s);
|
|
587
601
|
root.addEventListener(evtNm, evtCallback);
|
|
588
602
|
if (!cleanupCalls)
|
|
589
603
|
cleanupCalls = [];
|
|
@@ -606,7 +620,7 @@ export class BindingsHelper {
|
|
|
606
620
|
cleanUp();
|
|
607
621
|
this.applyBinding(element, binding, relativeSignalPath, root, specialValueHandler);
|
|
608
622
|
};
|
|
609
|
-
const evtNm =
|
|
623
|
+
const evtNm = this.getChangedEventName(element, s);
|
|
610
624
|
root.addEventListener(evtNm, evtCallback);
|
|
611
625
|
if (!cleanupCalls)
|
|
612
626
|
cleanupCalls = [];
|
|
@@ -697,7 +711,7 @@ export class BindingsHelper {
|
|
|
697
711
|
}
|
|
698
712
|
else {
|
|
699
713
|
if (s.includes('{')) {
|
|
700
|
-
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);
|
|
701
715
|
if (!cleanupCalls)
|
|
702
716
|
cleanupCalls = [];
|
|
703
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",
|