@node-projects/web-component-designer 0.0.171 → 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.
@@ -76,7 +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): void;
79
+ getStyleFromSheetOrLocal(name: string): string;
80
80
  getAllStyles(): IStyleRule[];
81
81
  setAttribute(name: string, value?: string | null): void;
82
82
  removeAttribute(name: string): void;
@@ -304,7 +304,7 @@ export class DesignItem {
304
304
  }
305
305
  updateStyleInSheetOrLocal(name, value, important) {
306
306
  let nm = PropertiesHelper.camelToDashCase(name);
307
- // Pre-sorted by priority
307
+ // Pre-sorted by specificity
308
308
  let declerations = this.instanceServiceContainer.stylesheetService?.getDeclarations(this, nm);
309
309
  if (this.hasStyle(name) || !declerations) {
310
310
  // Set style locally
@@ -321,6 +321,15 @@ export class DesignItem {
321
321
  }
322
322
  }
323
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;
324
333
  }
325
334
  getAllStyles() {
326
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) {
@@ -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;
@@ -14,4 +14,8 @@ export declare class CssCurrentPropertiesService extends CommonPropertiesService
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
  }
@@ -50,4 +50,11 @@ export class CssCurrentPropertiesService extends CommonPropertiesService {
50
50
  // Local style
51
51
  super.setValue(designItems, { ...property, propertyType: PropertyType.cssValue }, value);
52
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);
59
+ }
53
60
  }
@@ -10,7 +10,7 @@ export class CssToolsStylesheetService {
10
10
  for (let stylesheet of stylesheets) {
11
11
  this._stylesheets.set(stylesheet.name, {
12
12
  stylesheet: stylesheet,
13
- ast: tools.parse(stylesheet.stylesheet)
13
+ ast: tools.parse(stylesheet.content)
14
14
  });
15
15
  }
16
16
  this.stylesheetsChanged.emit();
@@ -11,7 +11,7 @@ export class CssTreeStylesheetService {
11
11
  for (let stylesheet of stylesheets) {
12
12
  this._stylesheets.set(stylesheet.name, {
13
13
  stylesheet: stylesheet,
14
- ast: window.csstree.toPlainObject((window.csstree.parse(stylesheet.stylesheet, { positions: true, parseValue: false })))
14
+ ast: window.csstree.toPlainObject((window.csstree.parse(stylesheet.content, { positions: true, parseValue: false })))
15
15
  });
16
16
  }
17
17
  this.stylesheetsChanged.emit();
@@ -34,7 +34,7 @@ export class CssTreeStylesheetService {
34
34
  for (let item of this._stylesheets) {
35
35
  if (!item[1].ast || !this.astHasChildren(item[1].ast))
36
36
  continue;
37
- styles = styles.concat(Array.from(this.rulesFromAST(item[1].ast, item[1].stylesheet.stylesheet, item[0], designItem)));
37
+ styles = styles.concat(Array.from(this.rulesFromAST(item[1].ast, item[1].stylesheet.content, item[0], designItem)));
38
38
  }
39
39
  ;
40
40
  return styles;
@@ -89,17 +89,21 @@ export class CssTreeStylesheetService {
89
89
  }
90
90
  /* Section covers the update of rules and declarations */
91
91
  updateDeclarationWithDeclaration(declaration, value, important) {
92
- declaration.ast.value = window.csstree.toPlainObject(window.csstree.parse(declaration.name + ": " + value, { context: 'declaration', parseValue: false })).value;
93
- this._stylesheets.get(declaration.parent.stylesheetName).stylesheet.stylesheet = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(declaration.parent.stylesheetName).ast));
94
- this._stylesheets.get(declaration.parent.stylesheetName).ast = window.csstree.toPlainObject(window.csstree.fromPlainObject(this._stylesheets.get(declaration.parent.stylesheetName).ast));
95
- this.stylesheetChanged.emit({ stylesheet: this._stylesheets.get(declaration.parent.stylesheetName).stylesheet });
92
+ let sourceNode = this._stylesheets.get(declaration.parent.stylesheetName);
93
+ declaration.ast.value = window.csstree.toPlainObject(window.csstree.parse(declaration.name + ": " + value + (important ? " !important" : ""), { context: 'declaration', parseValue: false })).value;
94
+ sourceNode.stylesheet.content = window.csstree.generate(window.csstree.fromPlainObject(sourceNode.ast));
95
+ // After generating the stylesheet, the AST has to be transformed back into a plain object
96
+ sourceNode.ast = window.csstree.toPlainObject(sourceNode.ast);
97
+ this.stylesheetChanged.emit({ stylesheet: sourceNode.stylesheet });
96
98
  return true;
97
99
  }
98
100
  insertDeclarationIntoRule(rule, declaration, important) {
99
- rule.ast.block.children.push(window.csstree.toPlainObject(window.csstree.parse(declaration.name + ": " + declaration.value + (declaration.important ? "!important" : ""), { context: 'declaration', parseValue: false })));
100
- this._stylesheets.get(rule.stylesheetName).stylesheet.stylesheet = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
101
- this._stylesheets.get(rule.stylesheetName).ast = window.csstree.toPlainObject(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
102
- this.stylesheetChanged.emit({ stylesheet: this._stylesheets.get(rule.stylesheetName).stylesheet });
101
+ let sourceNode = this._stylesheets.get(rule.stylesheetName);
102
+ rule.ast.block.children.push(window.csstree.toPlainObject(window.csstree.parse(declaration.name + ": " + declaration.value + (declaration.important ? " !important" : ""), { context: 'declaration', parseValue: false })));
103
+ sourceNode.stylesheet.content = window.csstree.generate(window.csstree.fromPlainObject(sourceNode.ast));
104
+ // After generating the stylesheet, the AST has to be transformed back into a plain object
105
+ sourceNode.ast = window.csstree.toPlainObject(sourceNode.ast);
106
+ this.stylesheetChanged.emit({ stylesheet: sourceNode.stylesheet });
103
107
  return true;
104
108
  }
105
109
  removeDeclarationFromRule(rule, declaration) {
@@ -107,7 +111,7 @@ export class CssTreeStylesheetService {
107
111
  if (index == -1)
108
112
  return false;
109
113
  rule.ast.block.children.splice(index, 1);
110
- this._stylesheets.get(rule.stylesheetName).stylesheet.stylesheet = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
114
+ this._stylesheets.get(rule.stylesheetName).stylesheet.content = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
111
115
  this._stylesheets.get(rule.stylesheetName).ast = window.csstree.toPlainObject(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
112
116
  this.stylesheetChanged.emit({ stylesheet: this._stylesheets.get(rule.stylesheetName).stylesheet });
113
117
  return true;
@@ -12,7 +12,7 @@ export interface IStyleDeclaration {
12
12
  important: boolean;
13
13
  }
14
14
  export interface IStylesheet {
15
- stylesheet: string;
15
+ content: string;
16
16
  name: string;
17
17
  }
18
18
  export interface IStylesheetService {
@@ -59,6 +59,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
59
59
  extensionManager: IExtensionManager;
60
60
  private _pointerextensions;
61
61
  private _onDblClickBound;
62
+ private _lastCopiedPrimaryItem;
62
63
  constructor();
63
64
  get designerWidth(): string;
64
65
  set designerWidth(value: string);
@@ -163,6 +163,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
163
163
  extensionManager;
164
164
  _pointerextensions;
165
165
  _onDblClickBound;
166
+ _lastCopiedPrimaryItem;
166
167
  constructor() {
167
168
  super();
168
169
  this._restoreCachedInititalValues();
@@ -219,7 +220,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
219
220
  if (this.instanceServiceContainer.stylesheetService) {
220
221
  styles.push(...this.instanceServiceContainer.stylesheetService
221
222
  .getStylesheets()
222
- .map(x => cssFromString(this.buildPatchedStyleSheet([cssFromString(x.stylesheet)]))));
223
+ .map(x => cssFromString(this.buildPatchedStyleSheet([cssFromString(x.content)]))));
223
224
  }
224
225
  this.shadowRoot.adoptedStyleSheets = styles;
225
226
  }
@@ -365,13 +366,14 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
365
366
  this.instanceServiceContainer.selectionService.setSelectedElements(Array.from(this.rootDesignItem.children()));
366
367
  }
367
368
  async handleCopyCommand() {
369
+ this._lastCopiedPrimaryItem = this.instanceServiceContainer.selectionService.primarySelection;
368
370
  await this.serviceContainer.copyPasteService.copyItems(this.instanceServiceContainer.selectionService.selectedElements);
369
371
  }
370
372
  async handlePasteCommand(disableRestoreOfPositions) {
371
373
  const [designItems, positions] = await this.serviceContainer.copyPasteService.getPasteItems(this.serviceContainer, this.instanceServiceContainer);
372
374
  let grp = this.rootDesignItem.openGroup("Insert");
373
375
  let pasteContainer = this.rootDesignItem;
374
- let pCon = this.instanceServiceContainer.selectionService.primarySelection;
376
+ let pCon = this._lastCopiedPrimaryItem?.parent ?? this.instanceServiceContainer.selectionService.primarySelection;
375
377
  while (pCon != null) {
376
378
  const containerStyle = getComputedStyle(pCon.element);
377
379
  let newContainerService;
@@ -420,8 +422,12 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
420
422
  if (undoService)
421
423
  this.instanceServiceContainer.register("undoService", undoService(this));
422
424
  const selectionService = this.serviceContainer.getLastService('selectionService');
423
- if (selectionService)
425
+ if (selectionService) {
424
426
  this.instanceServiceContainer.register("selectionService", selectionService(this));
427
+ this.instanceServiceContainer.selectionService.onSelectionChanged.on(() => {
428
+ this._lastCopiedPrimaryItem = null;
429
+ });
430
+ }
425
431
  this.rootDesignItem = DesignItem.GetOrCreateDesignItem(this._canvas, this.serviceContainer, this.instanceServiceContainer);
426
432
  const contentService = this.serviceContainer.getLastService('contentService');
427
433
  if (contentService)
@@ -23,8 +23,9 @@ export class TransformOriginExtension extends AbstractExtension {
23
23
  this._circle.addEventListener(EventNames.PointerDown, event => this.pointerEvent(event));
24
24
  this._circle.addEventListener(EventNames.PointerMove, event => this.pointerEvent(event));
25
25
  this._circle.addEventListener(EventNames.PointerUp, event => this.pointerEvent(event)); //TODO: -> assign to window
26
- if (this.extendedItem.getStyle('transform-origin')) {
27
- this._oldValue = this.extendedItem.getStyle('transform-origin');
26
+ let old = this.extendedItem.getStyleFromSheetOrLocal('transform-origin');
27
+ if (old) {
28
+ this._oldValue = old;
28
29
  }
29
30
  }
30
31
  pointerEvent(event) {
@@ -69,14 +70,14 @@ export class TransformOriginExtension extends AbstractExtension {
69
70
  if (oldSplit.length > 1) {
70
71
  newYs = convertCssUnit(newY, this.extendedItem.element, 'height', getCssUnit(oldSplit[1]));
71
72
  }
72
- this.extendedItem.setStyle('transform-origin', newXs + ' ' + newYs);
73
+ this.extendedItem.updateStyleInSheetOrLocal('transform-origin', newXs + ' ' + newYs);
73
74
  }
74
75
  catch (err) {
75
- this.extendedItem.setStyle('transform-origin', newX + 'px' + ' ' + newY + 'px');
76
+ this.extendedItem.updateStyleInSheetOrLocal('transform-origin', newX + 'px' + ' ' + newY + 'px');
76
77
  }
77
78
  }
78
79
  else
79
- this.extendedItem.setStyle('transform-origin', newX + 'px' + ' ' + newY + 'px');
80
+ this.extendedItem.updateStyleInSheetOrLocal('transform-origin', newX + 'px' + ' ' + newY + 'px');
80
81
  this.refresh();
81
82
  this._startPos = null;
82
83
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "A UI designer for Polymer apps",
3
3
  "name": "@node-projects/web-component-designer",
4
- "version": "0.0.171",
4
+ "version": "0.0.172",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",