@node-projects/web-component-designer-visualization-addons 0.1.27 → 0.1.28

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.
@@ -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: CSSStyleSheet, element: Element, root: HTMLElement): void;
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;
@@ -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,78 @@ export class BindingsHelper {
389
391
  }
390
392
  return retVal;
391
393
  }
394
+ static #cssBindingsVarId = 0;
395
+ parseCssBindings(sheet, element, root) {
396
+ for (let r of sheet.cssRules) {
397
+ if (r instanceof CSSStyleRule) {
398
+ for (const s of r.style) {
399
+ const v = r.style.getPropertyValue(s);
400
+ if (v.includes(bindingPrefixInsideCss)) {
401
+ const newValue = this.parseCssBinding(v, element, root);
402
+ r.style.setProperty(s, newValue);
403
+ }
404
+ }
405
+ }
406
+ }
407
+ }
408
+ parseCssBinding(value, element, root) {
409
+ value = value.trim();
410
+ let res = '';
411
+ let tmp = '';
412
+ let inBind = false;
413
+ let binding = '';
414
+ let escape = false;
415
+ let quote = null;
416
+ for (let n = 0; n < value.length; n++) {
417
+ const c = value[n];
418
+ if (inBind) {
419
+ if (escape)
420
+ binding += c;
421
+ else if (quote && c === '\\')
422
+ escape = true;
423
+ else if (c === quote)
424
+ quote = null;
425
+ else if (quote === null && c === ')') {
426
+ const id = BindingsHelper.#cssBindingsVarId++;
427
+ const varName = bindingPrefixInsideCssVarName + id;
428
+ let bnd = [varName, { signal: binding, target: BindingTarget.cssvar }];
429
+ if (binding.startsWith('{')) {
430
+ bnd = JSON.parse(binding);
431
+ }
432
+ this.applyBinding(element, bnd, '', root);
433
+ res += 'var(' + varName + ')';
434
+ inBind = false;
435
+ }
436
+ else
437
+ binding += c;
438
+ }
439
+ else if (c === '(') {
440
+ if (tmp !== 'bind') {
441
+ res += tmp;
442
+ res += c;
443
+ }
444
+ else {
445
+ inBind = true;
446
+ if (value[n + 1] === '\'' || value[n + 1] === '"') {
447
+ n++;
448
+ quote = value[n];
449
+ }
450
+ else {
451
+ quote = null;
452
+ }
453
+ }
454
+ tmp = '';
455
+ }
456
+ else if (c === ' ' || c === ',' || c === '(' || c === '+' || c === '-' || c === '*' || c === '/') {
457
+ res += tmp + c;
458
+ tmp = '';
459
+ }
460
+ else {
461
+ tmp += c;
462
+ }
463
+ }
464
+ return res + tmp;
465
+ }
392
466
  applyBinding(element, binding, relativeSignalPath, root) {
393
467
  let unsubscribeList = [];
394
468
  let cleanupCalls;
@@ -447,7 +521,14 @@ export class BindingsHelper {
447
521
  if (s[0] == '?') {
448
522
  if (root) {
449
523
  const nm = s.substring(1);
450
- let evtCallback = () => this.handleValueChanged(element, binding, root[nm], valuesObject, i, signalVars, false);
524
+ let evtCallback = () => {
525
+ let disableValueChanged = false;
526
+ if (disableValueChanged) {
527
+ disableValueChanged = true;
528
+ this.handleValueChanged(element, binding, root[nm], valuesObject, i, signalVars, false);
529
+ disableValueChanged = false;
530
+ }
531
+ };
451
532
  root.addEventListener(PropertiesHelper.camelToDashCase(nm) + '-changed', evtCallback);
452
533
  if (!cleanupCalls)
453
534
  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.27",
4
+ "version": "0.1.28",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -9,6 +9,7 @@
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": {