@node-projects/web-component-designer-visualization-addons 0.1.7 → 0.1.9
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VisualizationBinding } from "../interfaces/VisualizationBinding.js";
|
|
2
|
-
import { BindingTarget } from "@node-projects/web-component-designer";
|
|
3
2
|
import { State, VisualizationHandler } from "../interfaces/VisualizationHandler.js";
|
|
3
|
+
import { BindingTarget } from "@node-projects/web-component-designer/dist/elements/item/BindingTarget.js";
|
|
4
4
|
export declare const bindingPrefixProperty = "bind-prop:";
|
|
5
5
|
export declare const bindingPrefixAttribute = "bind-attr:";
|
|
6
6
|
export declare const bindingPrefixClass = "bind-class:";
|
|
@@ -10,6 +10,7 @@ export declare const bindingPrefixContent = "bind-content:";
|
|
|
10
10
|
export declare const bindingsInCssRegex: RegExp;
|
|
11
11
|
export type namedBinding = [name: string, binding: VisualizationBinding];
|
|
12
12
|
export declare function isLit(element: Element): boolean;
|
|
13
|
+
export declare function getChangeEventName(element: Element, propertyName: string): string;
|
|
13
14
|
export declare function parseBindingString(id: string): {
|
|
14
15
|
parts: string[];
|
|
15
16
|
signals: string[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TypedEvent } from "@node-projects/base-custom-webcomponent";
|
|
2
|
-
import {
|
|
2
|
+
import { BindingTarget } from "@node-projects/web-component-designer/dist/elements/item/BindingTarget.js";
|
|
3
|
+
import { PropertiesHelper } from "@node-projects/web-component-designer/dist/elements/services/propertiesService/services/PropertiesHelper.js";
|
|
3
4
|
//;,[ are not allowed in bindings, so they could be used for a short form...
|
|
4
5
|
export const bindingPrefixProperty = 'bind-prop:';
|
|
5
6
|
export const bindingPrefixAttribute = 'bind-attr:';
|
|
@@ -12,6 +13,11 @@ export function isLit(element) {
|
|
|
12
13
|
//@ts-ignore
|
|
13
14
|
return element.constructor?.elementProperties != null;
|
|
14
15
|
}
|
|
16
|
+
export function getChangeEventName(element, propertyName) {
|
|
17
|
+
if (isLit(element))
|
|
18
|
+
return propertyName;
|
|
19
|
+
return propertyName + '-changed';
|
|
20
|
+
}
|
|
15
21
|
export function parseBindingString(id) {
|
|
16
22
|
let parts = [];
|
|
17
23
|
let signals = [];
|
|
@@ -156,12 +162,7 @@ export class BindingsHelper {
|
|
|
156
162
|
else if (element instanceof HTMLSelectElement)
|
|
157
163
|
binding.events = ['change'];
|
|
158
164
|
else {
|
|
159
|
-
|
|
160
|
-
binding.events = [propname];
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
binding.events = [propname + '-changed'];
|
|
164
|
-
}
|
|
165
|
+
binding.events = [getChangeEventName(element, propname)];
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
if (bindingTarget === BindingTarget.cssvar || bindingTarget === BindingTarget.class)
|
|
@@ -392,6 +393,18 @@ export class BindingsHelper {
|
|
|
392
393
|
return retVal;
|
|
393
394
|
}
|
|
394
395
|
applyBinding(element, binding, relativeSignalPath, root) {
|
|
396
|
+
let unsubscribeList = [];
|
|
397
|
+
let cleanupCalls;
|
|
398
|
+
const cleanUp = () => {
|
|
399
|
+
for (const u of unsubscribeList) {
|
|
400
|
+
this._visualizationHandler.unsubscribeState(u[0], u[1]);
|
|
401
|
+
}
|
|
402
|
+
if (cleanupCalls) {
|
|
403
|
+
for (let e of cleanupCalls) {
|
|
404
|
+
e();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
};
|
|
395
408
|
const signals = binding[1].signal.split(';');
|
|
396
409
|
const signalVars = new Array(signals.length);
|
|
397
410
|
for (let i = 0; i < signals.length; i++) {
|
|
@@ -411,6 +424,15 @@ export class BindingsHelper {
|
|
|
411
424
|
}
|
|
412
425
|
else {
|
|
413
426
|
signals[i] = root[s];
|
|
427
|
+
let evtCallback = () => {
|
|
428
|
+
cleanUp();
|
|
429
|
+
this.applyBinding(element, binding, relativeSignalPath, root);
|
|
430
|
+
};
|
|
431
|
+
const evtNm = getChangeEventName(element, PropertiesHelper.camelToDashCase(s));
|
|
432
|
+
root.addEventListener(evtNm, evtCallback);
|
|
433
|
+
if (!cleanupCalls)
|
|
434
|
+
cleanupCalls = [];
|
|
435
|
+
cleanupCalls.push(() => root.removeEventListener(evtNm, evtCallback));
|
|
414
436
|
}
|
|
415
437
|
}
|
|
416
438
|
}
|
|
@@ -418,8 +440,6 @@ export class BindingsHelper {
|
|
|
418
440
|
signals[i] = relativeSignalPath + sng;
|
|
419
441
|
}
|
|
420
442
|
}
|
|
421
|
-
let unsubscribeList = [];
|
|
422
|
-
let cleanupCalls;
|
|
423
443
|
let valuesObject = new Array(signals.length);
|
|
424
444
|
for (let i = 0; i < signals.length; i++) {
|
|
425
445
|
const s = signals[i];
|
|
@@ -490,16 +510,7 @@ export class BindingsHelper {
|
|
|
490
510
|
}
|
|
491
511
|
}
|
|
492
512
|
}
|
|
493
|
-
return
|
|
494
|
-
for (const u of unsubscribeList) {
|
|
495
|
-
this._visualizationHandler.unsubscribeState(u[0], u[1]);
|
|
496
|
-
}
|
|
497
|
-
if (cleanupCalls) {
|
|
498
|
-
for (let e of cleanupCalls) {
|
|
499
|
-
e();
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
};
|
|
513
|
+
return cleanUp;
|
|
503
514
|
}
|
|
504
515
|
addTwoWayBinding(binding, element, setter) {
|
|
505
516
|
if (binding[1].expressionTwoWay) {
|
|
@@ -3,7 +3,6 @@ export declare class IScriptMultiplexValue {
|
|
|
3
3
|
* signal - read the value from a IOB object
|
|
4
4
|
* property - read the value from a property of the customControl (not usable in screens)
|
|
5
5
|
* event - read the value of a property of the event object
|
|
6
|
-
* @TJS-format signal
|
|
7
6
|
*/
|
|
8
7
|
source: 'signal' | 'property' | 'event';
|
|
9
8
|
/**
|
|
@@ -3,7 +3,6 @@ export class IScriptMultiplexValue {
|
|
|
3
3
|
* signal - read the value from a IOB object
|
|
4
4
|
* property - read the value from a property of the customControl (not usable in screens)
|
|
5
5
|
* event - read the value of a property of the event object
|
|
6
|
-
* @TJS-format signal
|
|
7
6
|
*/
|
|
8
7
|
source;
|
|
9
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sleep } from "@node-projects/web-component-designer";
|
|
1
|
+
import { sleep } from "@node-projects/web-component-designer/dist/elements/helper/Helper.js";
|
|
2
2
|
import { generateEventCodeFromBlockly } from "../blockly/BlocklyJavascriptHelper.js";
|
|
3
3
|
import { parseBindingString } from "../helpers/BindingsHelper.js";
|
|
4
4
|
import Long from 'long';
|
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.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|