@node-projects/web-component-designer-visualization-addons 0.1.27 → 0.1.29
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
CHANGED
|
@@ -34,6 +34,7 @@ export declare class BindingsEditor extends BaseCustomWebComponentConstructorApp
|
|
|
34
34
|
private _serviceContainer;
|
|
35
35
|
private _shell;
|
|
36
36
|
private _activeRow;
|
|
37
|
+
private _objNmInput;
|
|
37
38
|
constructor(property: IProperty, binding: IBinding & {
|
|
38
39
|
converter: Record<string, any>;
|
|
39
40
|
}, bindingTarget: BindingTarget, serviceContainer: ServiceContainer, shell: VisualizationShell);
|
|
@@ -12,7 +12,7 @@ export class BindingsEditor extends BaseCustomWebComponentConstructorAppend {
|
|
|
12
12
|
<span style="cursor: pointer;" title="to use multiple objects, seprate them with semicolon (;). access iobroker objects in properties via ?propertyName, access the propertyValue via ??propertyName. Bind to ioBroker object via $objectId. You could also use ioBroker signals inside of a Signal Name via {name}">objects</span>
|
|
13
13
|
</div>
|
|
14
14
|
<div style="display:flex;align-items: flex-end;">
|
|
15
|
-
<input class="row" value="{{?this.objectNames::change}}" style="flex-grow: 1;">
|
|
15
|
+
<input id="objnm" class="row" value="{{?this.objectNames::change}}" style="flex-grow: 1;">
|
|
16
16
|
<button @click="_clear" style="height: 22px">X</button>
|
|
17
17
|
<button @click="_select" style="height: 22px">...</button>
|
|
18
18
|
</div>
|
|
@@ -184,9 +184,11 @@ export class BindingsEditor extends BaseCustomWebComponentConstructorAppend {
|
|
|
184
184
|
_serviceContainer;
|
|
185
185
|
_shell;
|
|
186
186
|
_activeRow = -1;
|
|
187
|
+
_objNmInput;
|
|
187
188
|
constructor(property, binding, bindingTarget, serviceContainer, shell) {
|
|
188
189
|
super();
|
|
189
190
|
super._restoreCachedInititalValues();
|
|
191
|
+
this._objNmInput = this._getDomElement('objnm');
|
|
190
192
|
this._property = property;
|
|
191
193
|
this._binding = binding;
|
|
192
194
|
this._bindingTarget = bindingTarget;
|
|
@@ -229,6 +231,7 @@ export class BindingsEditor extends BaseCustomWebComponentConstructorAppend {
|
|
|
229
231
|
}
|
|
230
232
|
}
|
|
231
233
|
this._bindingsParse();
|
|
234
|
+
this._objNmInput.focus();
|
|
232
235
|
}
|
|
233
236
|
_focusRow(index) {
|
|
234
237
|
this._activeRow = index;
|
|
@@ -7,6 +7,8 @@ export declare const bindingPrefixClass = "bind-class:";
|
|
|
7
7
|
export declare const bindingPrefixCss = "bind-css:";
|
|
8
8
|
export declare const bindingPrefixCssVar = "bind-cssvar:";
|
|
9
9
|
export declare const bindingPrefixContent = "bind-content:";
|
|
10
|
+
export declare const bindingPrefixInsideCss = "bind(";
|
|
11
|
+
export declare const bindingPrefixInsideCssVarName = "--tmpBinding_";
|
|
10
12
|
export declare const bindingsInCssRegex: RegExp;
|
|
11
13
|
export type namedBinding = [name: string, binding: VisualizationBinding];
|
|
12
14
|
export declare function isLit(element: Element): boolean;
|
|
@@ -32,6 +34,7 @@ export declare class IndirectSignal {
|
|
|
32
34
|
setState(value: any): void;
|
|
33
35
|
}
|
|
34
36
|
export declare class BindingsHelper {
|
|
37
|
+
#private;
|
|
35
38
|
_visualizationHandler: VisualizationHandler;
|
|
36
39
|
constructor(visualizationHandler: VisualizationHandler);
|
|
37
40
|
parseBinding(element: Element, name: string, value: string, bindingTarget: BindingTarget, prefix: string): namedBinding;
|
|
@@ -39,6 +42,8 @@ export declare class BindingsHelper {
|
|
|
39
42
|
getBindingAttributeName(element: Element, propertyName: string, propertyTarget: BindingTarget): string;
|
|
40
43
|
getBindings(element: Element): Generator<namedBinding, void, unknown>;
|
|
41
44
|
applyAllBindings(rootElement: ParentNode, relativeSignalPath: string, root: HTMLElement): (() => void)[];
|
|
45
|
+
parseCssBindings(sheet: string, element: Element, root: HTMLElement): Promise<CSSStyleSheet>;
|
|
46
|
+
parseCssBinding(value: string, element: Element, root: HTMLElement): string;
|
|
42
47
|
applyBinding(element: Element, binding: namedBinding, relativeSignalPath: string, root: HTMLElement): () => void;
|
|
43
48
|
private addTwoWayBinding;
|
|
44
49
|
private static parseValueWithType;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypedEvent } from "@node-projects/base-custom-webcomponent";
|
|
1
|
+
import { TypedEvent, cssFromString } from "@node-projects/base-custom-webcomponent";
|
|
2
2
|
import { BindingTarget } from "@node-projects/web-component-designer/dist/elements/item/BindingTarget.js";
|
|
3
3
|
import { PropertiesHelper } from "@node-projects/web-component-designer/dist/elements/services/propertiesService/services/PropertiesHelper.js";
|
|
4
4
|
//;,[ are not allowed in bindings, so they could be used for a short form...
|
|
@@ -8,6 +8,8 @@ export const bindingPrefixClass = 'bind-class:';
|
|
|
8
8
|
export const bindingPrefixCss = 'bind-css:';
|
|
9
9
|
export const bindingPrefixCssVar = 'bind-cssvar:';
|
|
10
10
|
export const bindingPrefixContent = 'bind-content:';
|
|
11
|
+
export const bindingPrefixInsideCss = 'bind(';
|
|
12
|
+
export const bindingPrefixInsideCssVarName = '--tmpBinding_';
|
|
11
13
|
export const bindingsInCssRegex = /{{(.*)}}/;
|
|
12
14
|
export function isLit(element) {
|
|
13
15
|
//@ts-ignore
|
|
@@ -389,6 +391,83 @@ export class BindingsHelper {
|
|
|
389
391
|
}
|
|
390
392
|
return retVal;
|
|
391
393
|
}
|
|
394
|
+
static #cssBindingsVarId = 0;
|
|
395
|
+
async parseCssBindings(sheet, element, root) {
|
|
396
|
+
const parser = (await import("@adobe/css-tools"));
|
|
397
|
+
const ast = parser.parse(sheet);
|
|
398
|
+
for (let r of ast.stylesheet.rules) {
|
|
399
|
+
if (r.type === parser.CssTypes.rule) {
|
|
400
|
+
for (const d of r.declarations) {
|
|
401
|
+
if (d.type === parser.CssTypes.declaration) {
|
|
402
|
+
if (d.value.includes(bindingPrefixInsideCss)) {
|
|
403
|
+
const newValue = this.parseCssBinding(d.value, element, root);
|
|
404
|
+
d.value = newValue;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const newStyle = parser.stringify(ast, { indent: '', compress: true });
|
|
411
|
+
return cssFromString(newStyle);
|
|
412
|
+
}
|
|
413
|
+
parseCssBinding(value, element, root) {
|
|
414
|
+
value = value.trim();
|
|
415
|
+
let res = '';
|
|
416
|
+
let tmp = '';
|
|
417
|
+
let inBind = false;
|
|
418
|
+
let binding = '';
|
|
419
|
+
let escape = false;
|
|
420
|
+
let quote = null;
|
|
421
|
+
for (let n = 0; n < value.length; n++) {
|
|
422
|
+
const c = value[n];
|
|
423
|
+
if (inBind) {
|
|
424
|
+
if (escape)
|
|
425
|
+
binding += c;
|
|
426
|
+
else if (quote && c === '\\')
|
|
427
|
+
escape = true;
|
|
428
|
+
else if (c === quote)
|
|
429
|
+
quote = null;
|
|
430
|
+
else if (quote === null && c === ')') {
|
|
431
|
+
const id = BindingsHelper.#cssBindingsVarId++;
|
|
432
|
+
const varName = bindingPrefixInsideCssVarName + id;
|
|
433
|
+
let bnd = [varName, { signal: binding, target: BindingTarget.cssvar }];
|
|
434
|
+
if (binding.startsWith('{')) {
|
|
435
|
+
bnd = JSON.parse(binding);
|
|
436
|
+
}
|
|
437
|
+
this.applyBinding(element, bnd, '', root);
|
|
438
|
+
res += 'var(' + varName + ')';
|
|
439
|
+
inBind = false;
|
|
440
|
+
}
|
|
441
|
+
else
|
|
442
|
+
binding += c;
|
|
443
|
+
}
|
|
444
|
+
else if (c === '(') {
|
|
445
|
+
if (tmp !== 'bind') {
|
|
446
|
+
res += tmp;
|
|
447
|
+
res += c;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
inBind = true;
|
|
451
|
+
if (value[n + 1] === '\'' || value[n + 1] === '"') {
|
|
452
|
+
n++;
|
|
453
|
+
quote = value[n];
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
quote = null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
tmp = '';
|
|
460
|
+
}
|
|
461
|
+
else if (c === ' ' || c === ',' || c === '(' || c === '+' || c === '-' || c === '*' || c === '/') {
|
|
462
|
+
res += tmp + c;
|
|
463
|
+
tmp = '';
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
tmp += c;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return res + tmp;
|
|
470
|
+
}
|
|
392
471
|
applyBinding(element, binding, relativeSignalPath, root) {
|
|
393
472
|
let unsubscribeList = [];
|
|
394
473
|
let cleanupCalls;
|
|
@@ -447,7 +526,14 @@ export class BindingsHelper {
|
|
|
447
526
|
if (s[0] == '?') {
|
|
448
527
|
if (root) {
|
|
449
528
|
const nm = s.substring(1);
|
|
450
|
-
let evtCallback = () =>
|
|
529
|
+
let evtCallback = () => {
|
|
530
|
+
let disableValueChanged = false;
|
|
531
|
+
if (disableValueChanged) {
|
|
532
|
+
disableValueChanged = true;
|
|
533
|
+
this.handleValueChanged(element, binding, root[nm], valuesObject, i, signalVars, false);
|
|
534
|
+
disableValueChanged = false;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
451
537
|
root.addEventListener(PropertiesHelper.camelToDashCase(nm) + '-changed', evtCallback);
|
|
452
538
|
if (!cleanupCalls)
|
|
453
539
|
cleanupCalls = [];
|
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.29",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|
|
@@ -9,18 +9,20 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"tsc": "tsc",
|
|
11
11
|
"build": "tsc",
|
|
12
|
+
"link": "npm link",
|
|
12
13
|
"prepublishOnly": "npm run build"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
16
|
+
"@adobe/css-tools": "^4.3.3",
|
|
17
|
+
"@blockly/zoom-to-fit": "^5.0.11",
|
|
15
18
|
"@node-projects/base-custom-webcomponent": ">=0.19.0",
|
|
16
|
-
"@node-projects/web-component-designer": ">=0.1.1",
|
|
17
|
-
"@node-projects/web-component-designer-widgets-wunderbaum": ">=0.1.12",
|
|
18
|
-
"@node-projects/web-component-designer-codeview-monaco": ">=0.1.18",
|
|
19
19
|
"@node-projects/propertygrid.webcomponent": ">=1.0.2",
|
|
20
20
|
"@node-projects/splitview.webcomponent": ">=1.0.1",
|
|
21
|
-
"@
|
|
21
|
+
"@node-projects/web-component-designer": ">=0.1.1",
|
|
22
|
+
"@node-projects/web-component-designer-codeview-monaco": ">=0.1.18",
|
|
23
|
+
"@node-projects/web-component-designer-widgets-wunderbaum": ">=0.1.12",
|
|
22
24
|
"blockly": "^10.4.2",
|
|
23
|
-
"long": "^5.2.3"
|
|
25
|
+
"long": "^5.2.3"
|
|
24
26
|
},
|
|
25
27
|
"repository": {
|
|
26
28
|
"type": "git",
|