@node-projects/web-component-designer 0.0.98 → 0.0.101

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.
@@ -10,7 +10,7 @@ export class DocumentContainer extends BaseCustomWebComponentLazyAppend {
10
10
  _additionalStyle;
11
11
  set additionalStyleString(style) {
12
12
  this._additionalStyle = style;
13
- this.designerView.additionalStyle = cssFromString(style);
13
+ this.designerView.additionalStyles = [cssFromString(style)];
14
14
  }
15
15
  ;
16
16
  get additionalStyleString() {
@@ -135,7 +135,11 @@ export class CssCombiner {
135
135
  styles.delete('margin-right');
136
136
  styles.delete('margin-bottom');
137
137
  styles.delete('margin-left');
138
- styles.set('margin', e.style.marginTop + ' ' + e.style.marginRight + ' ' + e.style.marginBottom + ' ' + e.style.marginLeft);
138
+ if (e.style.marginTop == e.style.marginRight && e.style.marginTop == e.style.marginBottom && e.style.marginTop == e.style.marginLeft) {
139
+ styles.set('margin', e.style.marginTop);
140
+ }
141
+ else
142
+ styles.set('margin', e.style.marginTop + ' ' + e.style.marginRight + ' ' + e.style.marginBottom + ' ' + e.style.marginLeft);
139
143
  }
140
144
  }
141
145
  static combinePadding(styles) {
@@ -155,7 +159,11 @@ export class CssCombiner {
155
159
  styles.delete('padding-right');
156
160
  styles.delete('padding-bottom');
157
161
  styles.delete('padding-left');
158
- styles.set('padding', e.style.paddingTop + ' ' + e.style.paddingRight + ' ' + e.style.paddingBottom + ' ' + e.style.paddingLeft);
162
+ if (e.style.paddingTop == e.style.paddingRight && e.style.paddingTop == e.style.paddingBottom && e.style.paddingTop == e.style.paddingLeft) {
163
+ styles.set('padding', e.style.paddingTop);
164
+ }
165
+ else
166
+ styles.set('padding', e.style.paddingTop + ' ' + e.style.paddingRight + ' ' + e.style.paddingBottom + ' ' + e.style.paddingLeft);
159
167
  }
160
168
  }
161
169
  static combineInset(styles) {
@@ -1,7 +1,8 @@
1
1
  export function CalculateGridInformation(designItem) {
2
2
  //todo:
3
3
  //same name should combine columns/rows
4
- let itemRect = designItem.element.getBoundingClientRect();
4
+ let itemRect = designItem.instanceServiceContainer.designerCanvas.getNormalizedElementCoordinates(designItem.element);
5
+ //let itemRect = designItem.element.getBoundingClientRect();
5
6
  const computedStyle = getComputedStyle(designItem.element);
6
7
  const rows = computedStyle.gridTemplateRows.split(' ');
7
8
  const columns = computedStyle.gridTemplateColumns.split(' ');
@@ -11,8 +12,8 @@ export function CalculateGridInformation(designItem) {
11
12
  let xGap = 0;
12
13
  let yGap = 0;
13
14
  let rw = 0;
14
- let xOffset = itemRect.x - designItem.instanceServiceContainer.designerCanvas.containerBoundingRect.x;
15
- let yOffset = itemRect.y - designItem.instanceServiceContainer.designerCanvas.containerBoundingRect.y;
15
+ let xOffset = itemRect.x; // - designItem.instanceServiceContainer.designerCanvas.containerBoundingRect.x;
16
+ let yOffset = itemRect.y; // - designItem.instanceServiceContainer.designerCanvas.containerBoundingRect.y;
16
17
  let gridA = null;
17
18
  if (computedStyle.gridTemplateAreas && computedStyle.gridTemplateAreas !== 'none')
18
19
  gridA = computedStyle.gridTemplateAreas.split('\"');
@@ -13,6 +13,8 @@ export class DefaultPlacementService {
13
13
  return false;
14
14
  if (container.element.shadowRoot && container.element.shadowRoot.querySelector('slot') == null)
15
15
  return false;
16
+ if (!items.every(x => !x.element.contains(container.element)))
17
+ return false;
16
18
  return true;
17
19
  }
18
20
  canLeave(container, items) {
@@ -64,7 +64,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
64
64
  getDesignSurfaceDimensions(): ISize;
65
65
  get designerOffsetWidth(): number;
66
66
  get designerOffsetHeight(): number;
67
- set additionalStyle(value: CSSStyleSheet);
67
+ set additionalStyles(value: CSSStyleSheet[]);
68
68
  executeCommand(command: IUiCommand): Promise<void>;
69
69
  canExecuteCommand(command: IUiCommand): boolean;
70
70
  handleSelectAll(): void;
@@ -3,7 +3,7 @@ import { InstanceServiceContainer } from '../../services/InstanceServiceContaine
3
3
  import { UndoService } from '../../services/undoService/UndoService';
4
4
  import { SelectionService } from '../../services/selectionService/SelectionService';
5
5
  import { DesignItem } from '../../item/DesignItem';
6
- import { BaseCustomWebComponentLazyAppend, css, html, TypedEvent } from '@node-projects/base-custom-webcomponent';
6
+ import { BaseCustomWebComponentLazyAppend, css, html, TypedEvent, cssFromString } from '@node-projects/base-custom-webcomponent';
7
7
  import { dragDropFormatNameElementDefinition, dragDropFormatNameBindingObject } from '../../../Constants';
8
8
  import { ContentService } from '../../services/contentService/ContentService';
9
9
  import { InsertAction } from '../../services/undoService/transactionItems/InsertAction';
@@ -199,21 +199,24 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
199
199
  get designerOffsetHeight() {
200
200
  return this._canvasContainer.offsetHeight;
201
201
  }
202
- set additionalStyle(value) {
202
+ set additionalStyles(value) {
203
203
  if (value) {
204
- for (let r of value.rules) {
205
- if (r instanceof CSSStyleRule) {
206
- let parts = r.selectorText.split(',');
207
- let t = '';
208
- for (let p of parts) {
209
- if (r.selectorText)
210
- t += ',';
211
- t += '#canvas ' + p;
204
+ let style = '';
205
+ for (let s of value) {
206
+ for (let r of s.cssRules) {
207
+ if (r instanceof CSSStyleRule) {
208
+ let parts = r.selectorText.split(',');
209
+ let t = '';
210
+ for (let p of parts) {
211
+ if (t)
212
+ t += ',';
213
+ t += '#node-projects-designer-canvas-canvas ' + p;
214
+ }
215
+ style += t + '{' + r.style.cssText + '}';
212
216
  }
213
- r.selectorText = t;
214
217
  }
215
218
  }
216
- this.shadowRoot.adoptedStyleSheets = [this.constructor.style, value];
219
+ this.shadowRoot.adoptedStyleSheets = [this.constructor.style, cssFromString(style)];
217
220
  }
218
221
  else
219
222
  this.shadowRoot.adoptedStyleSheets = [this.constructor.style];
@@ -29,7 +29,7 @@ export declare class DesignerView extends BaseCustomWebComponentConstructorAppen
29
29
  set designerWidth(value: string);
30
30
  get designerHeight(): string;
31
31
  set designerHeight(value: string);
32
- set additionalStyle(value: CSSStyleSheet);
32
+ set additionalStyles(value: CSSStyleSheet[]);
33
33
  setDesignItems(designItems: IDesignItem[]): void;
34
34
  executeCommand(command: IUiCommand): Promise<void>;
35
35
  canExecuteCommand(command: IUiCommand): boolean;
@@ -243,7 +243,9 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
243
243
  scaleX = cvRect.width / dimensions.width;
244
244
  if (dimensions.height)
245
245
  scaleY = cvRect.height / dimensions.height;
246
- this._designerCanvas.zoomFactor = scaleX < scaleY ? scaleX : scaleY;
246
+ let fak = scaleX < scaleY ? scaleX : scaleY;
247
+ if (!isNaN(fak))
248
+ this._designerCanvas.zoomFactor = fak;
247
249
  this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
248
250
  }
249
251
  _onScrollbar(e) {
@@ -295,8 +297,8 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
295
297
  set designerHeight(value) {
296
298
  this._designerCanvas.designerHeight = value;
297
299
  }
298
- set additionalStyle(value) {
299
- this._designerCanvas.additionalStyle = value;
300
+ set additionalStyles(value) {
301
+ this._designerCanvas.additionalStyles = value;
300
302
  }
301
303
  setDesignItems(designItems) {
302
304
  this._designerCanvas.setDesignItems(designItems);
@@ -4,19 +4,17 @@ export class CanvasExtension extends AbstractExtension {
4
4
  super(extensionManager, designerView, extendedItem);
5
5
  }
6
6
  extend() {
7
- let itemRect = this.extendedItem.element.getBoundingClientRect();
7
+ let itemRect = this.designerCanvas.getNormalizedElementCoordinates(this.extendedItem.element);
8
8
  const computedStyle = getComputedStyle(this.extendedItem.element);
9
9
  if (computedStyle.margin !== '0px') {
10
- const xOffset = itemRect.x - this.designerCanvas.containerBoundingRect.x;
11
- const yOffset = itemRect.y - this.designerCanvas.containerBoundingRect.y;
12
10
  const left = Number.parseFloat(computedStyle.marginLeft.replace('px', ''));
13
11
  const top = Number.parseFloat(computedStyle.marginTop.replace('px', ''));
14
12
  const right = Number.parseFloat(computedStyle.marginRight.replace('px', ''));
15
13
  const bottom = Number.parseFloat(computedStyle.marginBottom.replace('px', ''));
16
- this._drawRect(xOffset - left, yOffset - top, left + itemRect.width + right, top, 'svg-margin');
17
- this._drawRect(xOffset - left, yOffset, left, itemRect.height, 'svg-margin');
18
- this._drawRect(xOffset + itemRect.width, yOffset, right, itemRect.height, 'svg-margin');
19
- this._drawRect(xOffset - left, yOffset + itemRect.height, left + itemRect.width + right, bottom, 'svg-margin');
14
+ this._drawRect(itemRect.x - left, itemRect.y - top, left + itemRect.width + right, top, 'svg-margin');
15
+ this._drawRect(itemRect.x - left, itemRect.y, left, itemRect.height, 'svg-margin');
16
+ this._drawRect(itemRect.x + itemRect.width, itemRect.y, right, itemRect.height, 'svg-margin');
17
+ this._drawRect(itemRect.x - left, itemRect.y + itemRect.height, left + itemRect.width + right, bottom, 'svg-margin');
20
18
  }
21
19
  }
22
20
  refresh() {
@@ -10,6 +10,9 @@ export class ElementDragTitleExtension extends AbstractExtension {
10
10
  const boundRect = this.extendedItem.element.getBoundingClientRect();
11
11
  this._rect = this._drawRect((boundRect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (boundRect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor - 16, 60, 15, 'svg-primary-selection-move', this._rect);
12
12
  this._text = this._drawText(this.extendedItem.name.substring(0, 10) + '…', (boundRect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (boundRect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor - 5, 'svg-text-primary', this._text);
13
+ const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
14
+ title.textContent = this.extendedItem.name;
15
+ this._text.appendChild(title);
13
16
  this._rect.addEventListener('pointerdown', (e) => this._pointerEvent(e));
14
17
  this._rect.addEventListener('pointermove', (e) => this._pointerEvent(e));
15
18
  this._rect.addEventListener('pointerup', (e) => this._pointerEvent(e));
@@ -1,4 +1,5 @@
1
1
  import { AbstractExtension } from "./AbstractExtension";
2
+ import { OverlayLayer } from "./OverlayLayer.js";
2
3
  export class GrayOutExtension extends AbstractExtension {
3
4
  _path;
4
5
  constructor(extensionManager, designerView, extendedItem) {
@@ -11,7 +12,7 @@ export class GrayOutExtension extends AbstractExtension {
11
12
  if (!this._path) {
12
13
  this._path = document.createElementNS("http://www.w3.org/2000/svg", "path");
13
14
  this._path.setAttribute('class', 'svg-gray-out');
14
- this.overlayLayerView.appendChild(this._path);
15
+ this.overlayLayerView.addOverlay(this._path, OverlayLayer.Background);
15
16
  this.overlays.push(this._path);
16
17
  }
17
18
  let itemRect = this.extendedItem.element.getBoundingClientRect();
@@ -7,6 +7,7 @@ export declare class PointerTool implements ITool {
7
7
  private _initialPoint;
8
8
  private _actionType?;
9
9
  private _actionStartedDesignItem?;
10
+ private _actionStartedDesignItems?;
10
11
  private _previousEventName;
11
12
  private _dragOverExtensionItem;
12
13
  private _dragExtensionItem;
@@ -9,6 +9,7 @@ export class PointerTool {
9
9
  _initialPoint;
10
10
  _actionType;
11
11
  _actionStartedDesignItem;
12
+ _actionStartedDesignItems;
12
13
  _previousEventName;
13
14
  _dragOverExtensionItem;
14
15
  _dragExtensionItem;
@@ -69,6 +70,7 @@ export class PointerTool {
69
70
  this._initialOffset = designerCanvas.getNormalizedOffsetInElement(event, currentElement);
70
71
  if (event.type == EventNames.PointerDown) {
71
72
  this._actionStartedDesignItem = currentDesignItem;
73
+ this._actionStartedDesignItems = [...designerCanvas.instanceServiceContainer.selectionService.selectedElements];
72
74
  designerCanvas.snapLines.clearSnaplines();
73
75
  if (currentDesignItem !== designerCanvas.rootDesignItem) {
74
76
  this._actionType = PointerActionType.Drag;
@@ -106,6 +108,7 @@ export class PointerTool {
106
108
  _resetTool() {
107
109
  this._actionType = null;
108
110
  this._actionStartedDesignItem = null;
111
+ this._actionStartedDesignItems = null;
109
112
  this._movedSinceStartedAction = false;
110
113
  this._initialPoint = null;
111
114
  }
@@ -154,6 +157,7 @@ export class PointerTool {
154
157
  if (designerCanvas.instanceServiceContainer.selectionService.selectedElements.indexOf(currentDesignItem) < 0)
155
158
  designerCanvas.instanceServiceContainer.selectionService.setSelectedElements([currentDesignItem]);
156
159
  }
160
+ this._actionStartedDesignItems = [...designerCanvas.instanceServiceContainer.selectionService.selectedElements];
157
161
  if (designerCanvas.alignOnSnap)
158
162
  designerCanvas.snapLines.calculateSnaplines(designerCanvas.instanceServiceContainer.selectionService.selectedElements);
159
163
  break;
@@ -177,7 +181,7 @@ export class PointerTool {
177
181
  else {
178
182
  designerCanvas.extensionManager.refreshExtension(dragItem, ExtensionType.ContainerDrag);
179
183
  }
180
- const canLeave = currentContainerService.canLeave(this._actionStartedDesignItem.parent, [this._actionStartedDesignItem]);
184
+ const canLeave = currentContainerService.canLeave(this._actionStartedDesignItem.parent, this._actionStartedDesignItems);
181
185
  let newContainerElementDesignItem = null;
182
186
  let newContainerService = null;
183
187
  if (canLeave) {
@@ -203,7 +207,7 @@ export class PointerTool {
203
207
  const containerStyle = getComputedStyle(newContainerElementDesignItem.element);
204
208
  newContainerService = designerCanvas.serviceContainer.getLastServiceWhere('containerService', x => x.serviceForContainer(newContainerElementDesignItem, containerStyle));
205
209
  if (newContainerService) {
206
- if (newContainerService.canEnter(newContainerElementDesignItem, [this._actionStartedDesignItem])) {
210
+ if (newContainerService.canEnter(newContainerElementDesignItem, this._actionStartedDesignItems)) {
207
211
  break;
208
212
  }
209
213
  else {
@@ -237,17 +241,18 @@ export class PointerTool {
237
241
  const oldOffset = currentContainerService.getElementOffset(this._actionStartedDesignItem.parent, this._actionStartedDesignItem);
238
242
  const newOffset = newContainerService.getElementOffset(newContainerElementDesignItem, this._actionStartedDesignItem);
239
243
  this._moveItemsOffset = { x: newOffset.x - oldOffset.x + this._moveItemsOffset.x, y: newOffset.y - oldOffset.y + this._moveItemsOffset.y };
240
- currentContainerService.leaveContainer(this._actionStartedDesignItem.parent, [this._actionStartedDesignItem]);
241
- newContainerElementDesignItem._insertChildInternal(this._actionStartedDesignItem);
244
+ currentContainerService.leaveContainer(this._actionStartedDesignItem.parent, this._actionStartedDesignItems);
245
+ for (let di of this._actionStartedDesignItems)
246
+ newContainerElementDesignItem._insertChildInternal(di); //todo -> maybe in enter container???
242
247
  const cp = { x: currentPoint.x - this._moveItemsOffset.x, y: currentPoint.y - this._moveItemsOffset.y };
243
- newContainerService.enterContainer(newContainerElementDesignItem, [this._actionStartedDesignItem]);
244
- newContainerService.place(event, designerCanvas, this._actionStartedDesignItem.parent, this._initialPoint, this._initialOffset, cp, designerCanvas.instanceServiceContainer.selectionService.selectedElements);
248
+ newContainerService.enterContainer(newContainerElementDesignItem, this._actionStartedDesignItems);
249
+ newContainerService.place(event, designerCanvas, this._actionStartedDesignItem.parent, this._initialPoint, this._initialOffset, cp, this._actionStartedDesignItems);
245
250
  }
246
251
  else {
247
252
  const cp = { x: currentPoint.x - this._moveItemsOffset.x, y: currentPoint.y - this._moveItemsOffset.y };
248
- currentContainerService.place(event, designerCanvas, this._actionStartedDesignItem.parent, this._initialPoint, this._initialOffset, cp, designerCanvas.instanceServiceContainer.selectionService.selectedElements);
253
+ currentContainerService.place(event, designerCanvas, this._actionStartedDesignItem.parent, this._initialPoint, this._initialOffset, cp, this._actionStartedDesignItems);
249
254
  }
250
- designerCanvas.extensionManager.refreshExtensions(designerCanvas.instanceServiceContainer.selectionService.selectedElements);
255
+ designerCanvas.extensionManager.refreshExtensions(this._actionStartedDesignItems);
251
256
  }
252
257
  }
253
258
  break;
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "description": "A UI designer for Polymer apps",
3
- "name": "@node-projects/web-component-designer",
4
- "version": "0.0.98",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "author": "",
8
- "license": "MIT",
9
- "scripts": {
10
- "tsc": "tsc",
11
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
12
- "build": "tsc",
13
- "prepublishOnly": "npm run build"
14
- },
15
- "dependencies": {
16
- "@node-projects/base-custom-webcomponent": "^0.9.1",
17
- "construct-style-sheets-polyfill": "^3.1.0"
18
- },
19
- "devDependencies": {
20
- "@node-projects/lean-he-esm": "^3.3.0",
21
- "@node-projects/node-html-parser-esm": "^2.4.1",
22
- "@papyrs/stylo": "^0.0.15",
23
- "@types/codemirror": "^5.60.5",
24
- "@types/jquery": "^3.5.14",
25
- "@types/jquery.fancytree": "0.0.7",
26
- "ace-builds": "^1.4.14",
27
- "codemirror": "^5.65.3",
28
- "esprima-next": "^5.8.1",
29
- "html2canvas": "*",
30
- "jest": "^27.5.1",
31
- "jquery": "^3.6.0",
32
- "jquery.fancytree": "^2.38.1",
33
- "monaco-editor": "^0.33.0",
34
- "ts-jest": "^27.1.4",
35
- "typescript": "^4.6.3",
36
- "typescript-lit-html-plugin": "^0.9.0"
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/node-projects/web-component-designer.git"
41
- }
42
- }
1
+ {
2
+ "description": "A UI designer for Polymer apps",
3
+ "name": "@node-projects/web-component-designer",
4
+ "version": "0.0.101",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "author": "",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "tsc": "tsc",
11
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
12
+ "build": "tsc",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "dependencies": {
16
+ "@node-projects/base-custom-webcomponent": "^0.9.1",
17
+ "construct-style-sheets-polyfill": "^3.1.0"
18
+ },
19
+ "devDependencies": {
20
+ "@node-projects/lean-he-esm": "^3.3.0",
21
+ "@node-projects/node-html-parser-esm": "^2.4.1",
22
+ "@papyrs/stylo": "^0.0.30",
23
+ "@types/codemirror": "^5.60.5",
24
+ "@types/jquery": "^3.5.14",
25
+ "@types/jquery.fancytree": "0.0.7",
26
+ "ace-builds": "^1.7.1",
27
+ "codemirror": "^6.0.1",
28
+ "esprima-next": "^5.8.3",
29
+ "html2canvas": "*",
30
+ "jest": "^28.1.2",
31
+ "jquery": "^3.6.0",
32
+ "jquery.fancytree": "^2.38.2",
33
+ "monaco-editor": "^0.33.0",
34
+ "ts-jest": "^28.0.5",
35
+ "typescript": "^4.7.4",
36
+ "typescript-lit-html-plugin": "^0.9.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/node-projects/web-component-designer.git"
41
+ }
42
+ }