@node-projects/web-component-designer 0.0.170 → 0.0.172

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.
Files changed (32) hide show
  1. package/dist/elements/helper/CssUnitConverter.d.ts +2 -2
  2. package/dist/elements/helper/CssUnitConverter.js +3 -3
  3. package/dist/elements/helper/GridHelper.d.ts +2 -0
  4. package/dist/elements/helper/GridHelper.js +16 -1
  5. package/dist/elements/item/DesignItem.d.ts +1 -0
  6. package/dist/elements/item/DesignItem.js +19 -7
  7. package/dist/elements/item/IDesignItem.d.ts +1 -0
  8. package/dist/elements/services/copyPasteService/CopyPasteService.js +2 -2
  9. package/dist/elements/services/propertiesService/PropertyGroupsService.d.ts +2 -2
  10. package/dist/elements/services/propertiesService/services/AbstractPropertiesService.js +2 -2
  11. package/dist/elements/services/propertiesService/services/CssCurrentPropertiesService.d.ts +6 -2
  12. package/dist/elements/services/propertiesService/services/CssCurrentPropertiesService.js +31 -7
  13. package/dist/elements/services/propertiesService/services/CssProperties.json +541 -0
  14. package/dist/elements/services/propertiesService/services/CssPropertiesService.d.ts +4 -4
  15. package/dist/elements/services/propertiesService/services/CssPropertiesService.js +42 -167
  16. package/dist/elements/services/propertiesService/services/NativeElementsPropertiesService.js +6 -0
  17. package/dist/elements/services/stylesheetService/CssToolsStylesheetService.d.ts +17 -0
  18. package/dist/elements/services/stylesheetService/CssToolsStylesheetService.js +45 -0
  19. package/dist/elements/services/stylesheetService/CssTreeStylesheetService copy.d.ts +48 -0
  20. package/dist/elements/services/stylesheetService/CssTreeStylesheetService copy.js +185 -0
  21. package/dist/elements/services/stylesheetService/CssTreeStylesheetService.d.ts +3 -3
  22. package/dist/elements/services/stylesheetService/CssTreeStylesheetService.js +41 -22
  23. package/dist/elements/services/stylesheetService/IStylesheetService.d.ts +5 -5
  24. package/dist/elements/widgets/designerView/designerCanvas.d.ts +1 -0
  25. package/dist/elements/widgets/designerView/designerCanvas.js +9 -3
  26. package/dist/elements/widgets/designerView/extensions/GridExtension.d.ts +35 -4
  27. package/dist/elements/widgets/designerView/extensions/GridExtension.js +277 -90
  28. package/dist/elements/widgets/designerView/extensions/GridExtensionProvider.js +3 -1
  29. package/dist/elements/widgets/designerView/extensions/TransformOriginExtension.js +7 -6
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +1 -0
  32. package/package.json +2 -1
@@ -1,3 +1,3 @@
1
- export declare function convertCssUnitToPixel(cssValue: string, target: HTMLElement, percentTarget: 'width' | 'heigth'): number;
1
+ export declare function convertCssUnitToPixel(cssValue: string, target: HTMLElement, percentTarget: 'width' | 'height'): number;
2
2
  export declare function getCssUnit(cssValue: string): string;
3
- export declare function convertCssUnit(cssValue: string | number, target: HTMLElement, percentTarget: 'width' | 'heigth', unit: string): string | number;
3
+ export declare function convertCssUnit(cssValue: string | number, target: HTMLElement, percentTarget: 'width' | 'height', unit: string): string | number;
@@ -1,5 +1,5 @@
1
1
  //unsupported: ex, ch, svw, svh, vw, lvh, dvw, dvh
2
- const units = ['px', 'cm', 'mm', 'q', 'in', 'pc', 'pt', 'rem', 'em', 'vw', 'vh', 'vmin', 'vmax', 'lh', 'rlh', '%', 'ms', 's', 'deg', 'rad', 'grad', 'turn', 'cqw', 'cqh', 'cqi', 'cqb', 'cqmin', 'cqmax'];
2
+ const units = ['px', 'cm', 'mm', 'q', 'in', 'pc', 'pt', 'rem', 'em', 'vw', 'vh', 'vmin', 'vmax', 'lh', 'rlh', '%', 'ms', 's', 'deg', 'rad', 'grad', 'turn', 'cqw', 'cqh', 'cqi', 'cqb', 'cqmin', 'cqmax', 'fr'];
3
3
  const pattern = new RegExp(`^([\-\+]?(?:\\d+(?:\\.\\d+)?))(${units.join('|')})$`, 'i');
4
4
  export function convertCssUnitToPixel(cssValue, target, percentTarget) {
5
5
  const supportedUnits = {
@@ -20,7 +20,7 @@ export function convertCssUnitToPixel(cssValue, target, percentTarget) {
20
20
  'vmax': value => value / 100 * (window.innerHeight > window.innerWidth ? window.innerHeight : window.innerWidth),
21
21
  'lh': value => value * parseFloat(getComputedStyle(target).lineHeight),
22
22
  'rlh': value => value * parseFloat(getComputedStyle(document.documentElement).lineHeight),
23
- '%': value => value / 100 * (percentTarget == 'heigth' ? target.getBoundingClientRect().height : target.getBoundingClientRect().width),
23
+ '%': value => value / 100 * (percentTarget == 'height' ? target.getBoundingClientRect().height : target.getBoundingClientRect().width),
24
24
  /* todo
25
25
  //find parent with computed style where contaner-type is inline-size or size (regarding to query type)
26
26
  //use this size for calculation
@@ -76,7 +76,7 @@ export function convertCssUnit(cssValue, target, percentTarget, unit) {
76
76
  'vmax': value => value * 100 / (window.innerHeight > window.innerWidth ? window.innerHeight : window.innerWidth),
77
77
  'lh': value => value / parseFloat(getComputedStyle(target).lineHeight),
78
78
  'rlh': value => value / parseFloat(getComputedStyle(document.documentElement).lineHeight),
79
- '%': value => value * 100 / (percentTarget == 'heigth' ? target.getBoundingClientRect().height : target.getBoundingClientRect().width),
79
+ '%': value => value * 100 / (percentTarget == 'height' ? target.getBoundingClientRect().height : target.getBoundingClientRect().width),
80
80
  // Times
81
81
  'ms': value => value,
82
82
  's': value => value / 1000,
@@ -4,7 +4,9 @@ export declare function CalculateGridInformation(designItem: IDesignItem): {
4
4
  x: number;
5
5
  y: number;
6
6
  width: number;
7
+ initWidthUnit: string;
7
8
  height: number;
9
+ initHeightUnit: string;
8
10
  name: string;
9
11
  }[][];
10
12
  gaps?: {
@@ -1,3 +1,4 @@
1
+ import { getCssUnit } from "./CssUnitConverter.js";
1
2
  export function CalculateGridInformation(designItem) {
2
3
  //todo:
3
4
  //same name should combine columns/rows
@@ -6,6 +7,20 @@ export function CalculateGridInformation(designItem) {
6
7
  const computedStyle = getComputedStyle(designItem.element);
7
8
  const rows = computedStyle.gridTemplateRows.split(' ');
8
9
  const columns = computedStyle.gridTemplateColumns.split(' ');
10
+ const rowUnits = [];
11
+ let tmpStyle = designItem.getStyle("grid-template-rows");
12
+ if (tmpStyle)
13
+ tmpStyle.split(' ').forEach(rowWidth => { if (rowWidth != "")
14
+ rowUnits.push(getCssUnit(rowWidth)); });
15
+ else
16
+ rows.forEach(() => rowUnits.push("px"));
17
+ const columnUnits = [];
18
+ tmpStyle = designItem.getStyle("grid-template-columns");
19
+ if (tmpStyle)
20
+ tmpStyle.split(' ').forEach(columnHeight => { if (columnHeight != "")
21
+ columnUnits.push(getCssUnit(columnHeight)); });
22
+ else
23
+ columns.forEach(() => columnUnits.push("px"));
9
24
  const paddingLeft = Number.parseFloat(computedStyle.paddingLeft);
10
25
  const paddingTop = Number.parseFloat(computedStyle.paddingTop);
11
26
  let y = 0;
@@ -100,7 +115,7 @@ export function CalculateGridInformation(designItem) {
100
115
  name = nm;
101
116
  }
102
117
  }
103
- const cell = { x: x + xOffset + paddingLeft, y: y + yOffset + paddingTop, width: currX, height: currY, name: name };
118
+ const cell = { x: x + xOffset + paddingLeft, y: y + yOffset + paddingTop, width: currX, initWidthUnit: columnUnits[yIdx], height: currY, initHeightUnit: rowUnits[xIdx], name: name };
104
119
  cellList.push(cell);
105
120
  x += currX;
106
121
  cl++;
@@ -76,6 +76,7 @@ export declare class DesignItem implements IDesignItem {
76
76
  setStyle(name: string, value?: string | null, important?: boolean): void;
77
77
  removeStyle(name: string): void;
78
78
  updateStyleInSheetOrLocal(name: string, value?: string | null, important?: boolean): void;
79
+ getStyleFromSheetOrLocal(name: string): string;
79
80
  getAllStyles(): IStyleRule[];
80
81
  setAttribute(name: string, value?: string | null): void;
81
82
  removeAttribute(name: string): void;
@@ -304,10 +304,10 @@ export class DesignItem {
304
304
  }
305
305
  updateStyleInSheetOrLocal(name, value, important) {
306
306
  let nm = PropertiesHelper.camelToDashCase(name);
307
- const declaration = null;
308
- //const declaration = this.serviceContainer.stylesheetService?.getDeclarations(d, property);
309
- //const rules = this.serviceContainer.stylesheetService?.getAppliedRules(d, property);
310
- if (!declaration) {
307
+ // Pre-sorted by specificity
308
+ let declerations = this.instanceServiceContainer.stylesheetService?.getDeclarations(this, nm);
309
+ if (this.hasStyle(name) || !declerations) {
310
+ // Set style locally
311
311
  if (this.getStyle(nm) != value) {
312
312
  this.setStyle(nm, value);
313
313
  }
@@ -315,9 +315,21 @@ export class DesignItem {
315
315
  this.removeStyle(nm);
316
316
  }
317
317
  }
318
- //todo -> modify stylesheet, or local css
319
- //we need undo for modification of stylesheet, look how we do this
320
- //maybe undo in stylsheet service?
318
+ else {
319
+ // Set style in sheet
320
+ this.instanceServiceContainer.stylesheetService.updateDeclarationWithDeclaration(declerations[0], value, important);
321
+ }
322
+ }
323
+ getStyleFromSheetOrLocal(name) {
324
+ let nm = PropertiesHelper.camelToDashCase(name);
325
+ if (this.hasStyle(name))
326
+ // Get style locally
327
+ return this.getStyle(nm);
328
+ // Pre-sorted by specificity
329
+ let decls = this.instanceServiceContainer.stylesheetService?.getDeclarations(this, nm);
330
+ if (decls && decls.length > 0)
331
+ return decls[0].value;
332
+ return null;
321
333
  }
322
334
  getAllStyles() {
323
335
  const localStyles = [...this._styles.entries()].map(x => ({ name: x[0], value: x[1], important: false }));
@@ -55,6 +55,7 @@ export interface IDesignItem {
55
55
  setStyle(name: string, value?: string | null, important?: boolean): any;
56
56
  removeStyle(name: string): any;
57
57
  updateStyleInSheetOrLocal(name: string, value?: string | null, important?: boolean): any;
58
+ getStyleFromSheetOrLocal(name: string): any;
58
59
  getAllStyles(): IStyleRule[];
59
60
  attributes(): Iterable<[name: string, value: string]>;
60
61
  getAttribute(name: string): any;
@@ -3,9 +3,9 @@ export const positionsJsonMime = 'web text/positions';
3
3
  export class CopyPasteService {
4
4
  async copyItems(designItems) {
5
5
  const copyText = DomConverter.ConvertToString(designItems, null, false);
6
- const positions = designItems.map(x => x.instanceServiceContainer.designerCanvas.getNormalizedElementCoordinates(x.element));
7
- const data = [new ClipboardItem({ ["text/html"]: new Blob([copyText], { type: 'text/html' }), [positionsJsonMime]: new Blob([JSON.stringify(positions)], { type: positionsJsonMime }) })];
8
6
  try {
7
+ const positions = designItems.map(x => x.instanceServiceContainer.designerCanvas.getNormalizedElementCoordinates(x.element));
8
+ const data = [new ClipboardItem({ ["text/html"]: new Blob([copyText], { type: 'text/html' }), [positionsJsonMime]: new Blob([JSON.stringify(positions)], { type: positionsJsonMime }) })];
9
9
  await navigator.clipboard.write(data);
10
10
  }
11
11
  catch (err) {
@@ -1,7 +1,7 @@
1
1
  import { IDesignItem } from '../../item/IDesignItem.js';
2
2
  import { IPropertiesService } from './IPropertiesService.js';
3
- import { IPropertyTabsService } from './IPropertyTabsService.js';
4
- export declare class PropertyGroupsService implements IPropertyTabsService {
3
+ import { IPropertyGroupsService } from './IPropertyGroupsService.js';
4
+ export declare class PropertyGroupsService implements IPropertyGroupsService {
5
5
  protected _pgList: {
6
6
  name: string;
7
7
  propertiesService: IPropertiesService;
@@ -116,8 +116,8 @@ export class AbstractPropertiesService {
116
116
  if (designItems != null && designItems.length !== 0) {
117
117
  if (property.propertyType == PropertyType.cssValue) {
118
118
  let lastValue = designItems[0].getStyle(property.name);
119
- for (const x of designItems) {
120
- let value = x.getStyle(property.name);
119
+ for (const d of designItems) {
120
+ let value = d.getStyle(property.name);
121
121
  if (value != lastValue) {
122
122
  lastValue = null;
123
123
  break;
@@ -2,9 +2,9 @@ import { IProperty } from '../IProperty.js';
2
2
  import { IDesignItem } from '../../../item/IDesignItem.js';
3
3
  import { RefreshMode } from '../IPropertiesService.js';
4
4
  import { IPropertyGroup } from '../IPropertyGroup.js';
5
- import { CssPropertiesService } from './CssPropertiesService.js';
6
5
  import { IStyleDeclaration, IStyleRule } from '../../stylesheetService/IStylesheetService.js';
7
- export declare class CssCurrentPropertiesService extends CssPropertiesService {
6
+ import { CommonPropertiesService } from './CommonPropertiesService.js';
7
+ export declare class CssCurrentPropertiesService extends CommonPropertiesService {
8
8
  getRefreshMode(designItem: IDesignItem): RefreshMode;
9
9
  constructor();
10
10
  isHandledElement(designItem: IDesignItem): boolean;
@@ -14,4 +14,8 @@ export declare class CssCurrentPropertiesService extends CssPropertiesService {
14
14
  styleRule: IStyleRule;
15
15
  styleDeclaration: IStyleDeclaration;
16
16
  }), value: any): void;
17
+ clearValue(designItems: IDesignItem[], property: IProperty & {
18
+ styleRule: IStyleRule;
19
+ styleDeclaration: IStyleDeclaration;
20
+ }): void;
17
21
  }
@@ -1,12 +1,14 @@
1
1
  import { PropertyType } from '../PropertyType.js';
2
2
  import { RefreshMode } from '../IPropertiesService.js';
3
- import { CssPropertiesService } from './CssPropertiesService.js';
4
- export class CssCurrentPropertiesService extends CssPropertiesService {
3
+ import { CommonPropertiesService } from './CommonPropertiesService.js';
4
+ import cssProperties from './CssProperties.json' assert { type: 'json' };
5
+ export class CssCurrentPropertiesService extends CommonPropertiesService {
5
6
  getRefreshMode(designItem) {
6
7
  return RefreshMode.fullOnValueChange;
7
8
  }
8
9
  constructor() {
9
- super('styles');
10
+ super();
11
+ this.name = 'styles';
10
12
  }
11
13
  isHandledElement(designItem) {
12
14
  return true;
@@ -20,17 +22,39 @@ export class CssCurrentPropertiesService extends CssPropertiesService {
20
22
  let styles = designItem.getAllStyles();
21
23
  let arr = styles.map(x => ({
22
24
  name: x.selector ?? '&lt;local&gt;', description: x.stylesheetName ?? '', properties: [
23
- ...x.declarations.map(y => ({ name: y.name, renamable: true, type: 'string', service: this, propertyType: PropertyType.cssValue, styleRule: x, styleDeclaration: y })),
25
+ ...x.declarations.map(y => ({
26
+ name: y.name,
27
+ renamable: true,
28
+ type: cssProperties[y.name]?.type ?? 'string',
29
+ values: cssProperties[y.name]?.values ? [...cssProperties[y.name]?.values, 'initial', 'inherit', 'unset'] : ['initial', 'inherit', 'unset'],
30
+ service: this,
31
+ propertyType: PropertyType.cssValue,
32
+ styleRule: x,
33
+ styleDeclaration: y
34
+ })),
24
35
  { name: '', type: 'addNew', service: this, propertyType: PropertyType.complex, styleRule: x }
25
36
  ]
26
37
  }));
27
38
  return arr;
28
39
  }
29
40
  setValue(designItems, property, value) {
30
- if (property.styleDeclaration) {
41
+ // No selector means local style, styleDeclaration is null means new property
42
+ if (property.styleRule?.selector !== null && property.styleDeclaration) {
31
43
  designItems[0].instanceServiceContainer.stylesheetService.updateDeclarationWithDeclaration(property.styleDeclaration, value, false);
44
+ return;
32
45
  }
33
- else
34
- super.setValue(designItems, { ...property, propertyType: PropertyType.cssValue }, value);
46
+ if (property.styleRule?.selector !== null && !property.styleDeclaration) {
47
+ designItems[0].instanceServiceContainer.stylesheetService.insertDeclarationIntoRule(property.styleRule, { name: property.name, value: value, important: false }, false);
48
+ return;
49
+ }
50
+ // Local style
51
+ super.setValue(designItems, { ...property, propertyType: PropertyType.cssValue }, value);
52
+ }
53
+ clearValue(designItems, property) {
54
+ if (property.styleRule?.selector !== null && property.styleDeclaration) {
55
+ designItems[0].instanceServiceContainer.stylesheetService.removeDeclarationFromRule(property.styleRule, property.styleDeclaration);
56
+ return;
57
+ }
58
+ super.clearValue(designItems, property);
35
59
  }
36
60
  }