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

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
@@ -15,5 +15,6 @@ It is used for example by the iobroker.webui.
15
15
 
16
16
  - long
17
17
  - blockly
18
+ - @adobe/css-tools ( only if you use Bindingshelper.parseCssBindings() )
18
19
 
19
20
  ## Usage
@@ -42,8 +42,8 @@ export declare class BindingsHelper {
42
42
  getBindingAttributeName(element: Element, propertyName: string, propertyTarget: BindingTarget): string;
43
43
  getBindings(element: Element): Generator<namedBinding, void, unknown>;
44
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;
45
+ parseCssBindings(sheet: string, element: Element, root: HTMLElement): Promise<[stylesheet: CSSStyleSheet, unsub: (() => void)[]]>;
46
+ parseCssBinding(value: string, element: Element, root: HTMLElement): [name: string, unsub: (() => void)[]];
47
47
  applyBinding(element: Element, binding: namedBinding, relativeSignalPath: string, root: HTMLElement): () => void;
48
48
  private addTwoWayBinding;
49
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...
@@ -392,18 +392,30 @@ export class BindingsHelper {
392
392
  return retVal;
393
393
  }
394
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);
395
+ async parseCssBindings(sheet, element, root) {
396
+ const parser = (await import("@adobe/css-tools"));
397
+ const ast = parser.parse(sheet);
398
+ let unsub;
399
+ for (let r of ast.stylesheet.rules) {
400
+ if (r.type === parser.CssTypes.rule) {
401
+ for (const d of r.declarations) {
402
+ if (d.type === parser.CssTypes.declaration) {
403
+ if (d.value.includes(bindingPrefixInsideCss)) {
404
+ const newValue = this.parseCssBinding(d.value, element, root);
405
+ d.value = newValue[0];
406
+ if (unsub) {
407
+ unsub.push(...newValue[1]);
408
+ }
409
+ else {
410
+ unsub = newValue[1];
411
+ }
412
+ }
403
413
  }
404
414
  }
405
415
  }
406
416
  }
417
+ const newStyle = parser.stringify(ast, { indent: '', compress: true });
418
+ return [cssFromString(newStyle), unsub];
407
419
  }
408
420
  parseCssBinding(value, element, root) {
409
421
  value = value.trim();
@@ -413,6 +425,7 @@ export class BindingsHelper {
413
425
  let binding = '';
414
426
  let escape = false;
415
427
  let quote = null;
428
+ let unsub = [];
416
429
  for (let n = 0; n < value.length; n++) {
417
430
  const c = value[n];
418
431
  if (inBind) {
@@ -429,9 +442,10 @@ export class BindingsHelper {
429
442
  if (binding.startsWith('{')) {
430
443
  bnd = JSON.parse(binding);
431
444
  }
432
- this.applyBinding(element, bnd, '', root);
445
+ unsub.push(this.applyBinding(element, bnd, '', root));
433
446
  res += 'var(' + varName + ')';
434
447
  inBind = false;
448
+ binding = '';
435
449
  }
436
450
  else
437
451
  binding += c;
@@ -461,7 +475,7 @@ export class BindingsHelper {
461
475
  tmp += c;
462
476
  }
463
477
  }
464
- return res + tmp;
478
+ return [res + tmp, unsub];
465
479
  }
466
480
  applyBinding(element, binding, relativeSignalPath, root) {
467
481
  let unsubscribeList = [];
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.28",
4
+ "version": "0.1.30",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -13,15 +13,16 @@
13
13
  "prepublishOnly": "npm run build"
14
14
  },
15
15
  "dependencies": {
16
+ "@adobe/css-tools": "^4.3.3",
17
+ "@blockly/zoom-to-fit": "^5.0.11",
16
18
  "@node-projects/base-custom-webcomponent": ">=0.19.0",
17
- "@node-projects/web-component-designer": ">=0.1.1",
18
- "@node-projects/web-component-designer-widgets-wunderbaum": ">=0.1.12",
19
- "@node-projects/web-component-designer-codeview-monaco": ">=0.1.18",
20
19
  "@node-projects/propertygrid.webcomponent": ">=1.0.2",
21
20
  "@node-projects/splitview.webcomponent": ">=1.0.1",
22
- "@blockly/zoom-to-fit": "^5.0.11",
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",
23
24
  "blockly": "^10.4.2",
24
- "long": "^5.2.3"
25
+ "long": "^5.2.3"
25
26
  },
26
27
  "repository": {
27
28
  "type": "git",