@node-projects/web-component-designer 0.0.89 → 0.0.90

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.
@@ -0,0 +1,7 @@
1
+ import { IDesignerCanvas } from "../..";
2
+ import { Orientation } from "../../enums/Orientation";
3
+ export declare abstract class ArrangeHelper {
4
+ static arrangeElements(orientation: Orientation, designerCanvas: IDesignerCanvas): void;
5
+ private static arrange;
6
+ private static formGroup;
7
+ }
@@ -0,0 +1,79 @@
1
+ import { Orientation } from "../../enums/Orientation";
2
+ export class ArrangeHelper {
3
+ static arrangeElements(orientation, designerCanvas) {
4
+ switch (orientation) {
5
+ case Orientation.TOP: {
6
+ const grp = this.formGroup(ArrangeDirection.TOP, designerCanvas);
7
+ const top = designerCanvas.instanceServiceContainer.selectionService.primarySelection.styles.get('top');
8
+ for (let elem of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
9
+ this.arrange(elem, 'top', top);
10
+ }
11
+ grp.commit();
12
+ break;
13
+ }
14
+ case Orientation.RIGHT: {
15
+ const grp = this.formGroup(ArrangeDirection.RIGHT, designerCanvas);
16
+ const arrElement = designerCanvas.getNormalizedElementCoordinates(designerCanvas.instanceServiceContainer.selectionService.primarySelection.element);
17
+ const right = Math.floor(arrElement.x + arrElement.width);
18
+ for (let elem of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
19
+ this.arrange(elem, 'left', (right - Math.floor(designerCanvas.getNormalizedElementCoordinates(elem.element).width)) + "px");
20
+ }
21
+ grp.commit();
22
+ break;
23
+ }
24
+ case Orientation.BOTTOM:
25
+ const grp = this.formGroup(ArrangeDirection.BOTTOM, designerCanvas);
26
+ const arrElement = designerCanvas.getNormalizedElementCoordinates(designerCanvas.instanceServiceContainer.selectionService.primarySelection.element);
27
+ const top = Math.floor(arrElement.y + arrElement.height);
28
+ for (let elem of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
29
+ this.arrange(elem, 'top', (top - Math.floor(designerCanvas.getNormalizedElementCoordinates(elem.element).height)) + "px");
30
+ }
31
+ grp.commit();
32
+ break;
33
+ case Orientation.LEFT: {
34
+ const grp = this.formGroup(ArrangeDirection.LEFT, designerCanvas);
35
+ const left = designerCanvas.instanceServiceContainer.selectionService.primarySelection.styles.get('left');
36
+ for (let elem of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
37
+ this.arrange(elem, 'left', left);
38
+ }
39
+ grp.commit();
40
+ break;
41
+ }
42
+ case Orientation.VERTICAL_CENTER: {
43
+ const grp = this.formGroup(ArrangeDirection.VERTICAL_CENTER, designerCanvas);
44
+ const arrElement = designerCanvas.getNormalizedElementCoordinates(designerCanvas.instanceServiceContainer.selectionService.primarySelection.element);
45
+ const ver_center = arrElement.y + arrElement.height / 2;
46
+ for (let elem of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
47
+ this.arrange(elem, 'top', (ver_center - Math.floor(designerCanvas.getNormalizedElementCoordinates(elem.element).height) / 2) + "px");
48
+ }
49
+ grp.commit();
50
+ break;
51
+ }
52
+ case Orientation.HORIZONTAL_CENTER: {
53
+ const grp = this.formGroup(ArrangeDirection.HORIZONTAL_CENTER, designerCanvas);
54
+ const arrElement = designerCanvas.getNormalizedElementCoordinates(designerCanvas.instanceServiceContainer.selectionService.primarySelection.element);
55
+ const hor_center = arrElement.x + (arrElement.width / 2);
56
+ for (let elem of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
57
+ this.arrange(elem, 'left', (hor_center - Math.floor(designerCanvas.getNormalizedElementCoordinates(elem.element).width) / 2) + "px");
58
+ }
59
+ grp.commit();
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ static arrange(element, attribut, value) {
65
+ element.setStyle(attribut, value);
66
+ }
67
+ static formGroup(name, designerCanvas) {
68
+ return designerCanvas.instanceServiceContainer.selectionService.primarySelection.openGroup(name);
69
+ }
70
+ }
71
+ var ArrangeDirection;
72
+ (function (ArrangeDirection) {
73
+ ArrangeDirection["TOP"] = "arrangeTop";
74
+ ArrangeDirection["RIGHT"] = "arrangeRight";
75
+ ArrangeDirection["BOTTOM"] = "arrangeBottom";
76
+ ArrangeDirection["LEFT"] = "arrangeLeft";
77
+ ArrangeDirection["HORIZONTAL_CENTER"] = "arrangeHorizontalCenter";
78
+ ArrangeDirection["VERTICAL_CENTER"] = "arrangeVerticalCenter";
79
+ })(ArrangeDirection || (ArrangeDirection = {}));
@@ -1,4 +1,6 @@
1
1
  import { CommandType } from "../../../commandHandling/CommandType.js";
2
+ import { ArrangeHelper } from "../../helper/ArrangeHelper.js";
3
+ import { Orientation } from "../../../enums/Orientation.js";
2
4
  export class DefaultModelCommandService {
3
5
  canExecuteCommand(designerCanvas, command) {
4
6
  if (command.type == CommandType.moveBackward ||
@@ -33,21 +35,23 @@ export class DefaultModelCommandService {
33
35
  sel.parent.insertChild(sel, 0);
34
36
  else if (command.type == CommandType.moveToFront)
35
37
  sel.parent.insertChild(sel);
38
+ else if (command.type == CommandType.arrangeTop) {
39
+ ArrangeHelper.arrangeElements(Orientation.TOP, designerCanvas);
40
+ }
41
+ else if (command.type == CommandType.arrangeRight) {
42
+ ArrangeHelper.arrangeElements(Orientation.RIGHT, designerCanvas);
43
+ }
36
44
  else if (command.type == CommandType.arrangeLeft) {
37
- const grp = designerCanvas.instanceServiceContainer.selectionService.primarySelection.openGroup('arrangeLeft');
38
- const left = designerCanvas.instanceServiceContainer.selectionService.primarySelection.styles.get('left');
39
- for (let s of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
40
- s.setStyle('left', left);
41
- }
42
- grp.commit();
45
+ ArrangeHelper.arrangeElements(Orientation.LEFT, designerCanvas);
43
46
  }
44
- else if (command.type == CommandType.arrangeTop) {
45
- const grp = designerCanvas.instanceServiceContainer.selectionService.primarySelection.openGroup('arrangeTop');
46
- const top = designerCanvas.instanceServiceContainer.selectionService.primarySelection.styles.get('top');
47
- for (let s of designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
48
- s.setStyle('top', top);
49
- }
50
- grp.commit();
47
+ else if (command.type == CommandType.arrangeBottom) {
48
+ ArrangeHelper.arrangeElements(Orientation.BOTTOM, designerCanvas);
49
+ }
50
+ else if (command.type == CommandType.arrangeCenter) {
51
+ ArrangeHelper.arrangeElements(Orientation.HORIZONTAL_CENTER, designerCanvas);
52
+ }
53
+ else if (command.type == CommandType.arrangeMiddle) {
54
+ ArrangeHelper.arrangeElements(Orientation.VERTICAL_CENTER, designerCanvas);
51
55
  }
52
56
  else if (command.type == CommandType.unifyHeight) {
53
57
  const grp = designerCanvas.instanceServiceContainer.selectionService.primarySelection.openGroup('unifyHeight');
@@ -40,4 +40,5 @@ export interface IDesignerCanvas extends IPlacementView, IUiCommandHandler {
40
40
  getItemsBelowMouse(event: MouseEvent): Element[];
41
41
  zoomTowardsPoint(point: IPoint, scalechange: number): void;
42
42
  zoomOntoRectangle(startPoint: IPoint, endPoint: IPoint): void;
43
+ showDesignItemContextMenu(designItem: IDesignItem, event: MouseEvent): void;
43
44
  }
@@ -31,6 +31,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
31
31
  private _zoomFactor;
32
32
  private _scaleFactor;
33
33
  private _canvasOffset;
34
+ private _currentContextMenu;
34
35
  private _lastPointerDownHandler;
35
36
  get zoomFactor(): number;
36
37
  set zoomFactor(value: number);
@@ -45,7 +46,6 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
45
46
  private _canvasContainer;
46
47
  private _outercanvas2;
47
48
  private _lastHoverDesignItem;
48
- private _onContextMenuBound;
49
49
  private _pointerEventHandlerBound;
50
50
  private _firstConnect;
51
51
  private _onKeyDownBound;
@@ -81,7 +81,6 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
81
81
  private _onDragLeave;
82
82
  private _onDragOver;
83
83
  private _onDrop;
84
- private _onContextMenu;
85
84
  showDesignItemContextMenu(designItem: IDesignItem, event: MouseEvent): ContextMenuHelper;
86
85
  private _onDblClick;
87
86
  private onKeyUp;
@@ -39,6 +39,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
39
39
  _zoomFactor = 1; //if scale or zoom css property is used this needs to be the value
40
40
  _scaleFactor = 1; //if scale css property is used this need to be the scale value
41
41
  _canvasOffset = { x: 0, y: 0 };
42
+ _currentContextMenu;
42
43
  _lastPointerDownHandler;
43
44
  get zoomFactor() {
44
45
  return this._zoomFactor;
@@ -70,7 +71,6 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
70
71
  _canvasContainer;
71
72
  _outercanvas2;
72
73
  _lastHoverDesignItem;
73
- _onContextMenuBound;
74
74
  _pointerEventHandlerBound;
75
75
  _firstConnect;
76
76
  _onKeyDownBound;
@@ -166,9 +166,8 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
166
166
  this._onKeyDownBound = this.onKeyDown.bind(this);
167
167
  this._onKeyUpBound = this.onKeyUp.bind(this);
168
168
  this._onDblClickBound = this._onDblClick.bind(this);
169
- this._onContextMenuBound = this._onContextMenu.bind(this);
170
169
  this._pointerEventHandlerBound = this._pointerEventHandler.bind(this);
171
- this.clickOverlay.oncontextmenu = this._onContextMenuBound;
170
+ this.clickOverlay.oncontextmenu = (e) => e.preventDefault();
172
171
  }
173
172
  get designerWidth() {
174
173
  return this._canvasContainer.style.width;
@@ -514,30 +513,16 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
514
513
  }
515
514
  }
516
515
  }
517
- _onContextMenu(event) {
518
- event.preventDefault();
519
- if (!event.shiftKey) {
520
- let items = this.getItemsBelowMouse(event);
521
- if (items.indexOf(this.instanceServiceContainer.selectionService.primarySelection.element) >= 0)
522
- this.showDesignItemContextMenu(this.instanceServiceContainer.selectionService.primarySelection, event);
523
- else {
524
- const designItem = DesignItem.GetOrCreateDesignItem(event.target, this.serviceContainer, this.instanceServiceContainer);
525
- if (!this.instanceServiceContainer.selectionService.isSelected(designItem)) {
526
- this.instanceServiceContainer.selectionService.setSelectedElements([designItem]);
527
- }
528
- this.showDesignItemContextMenu(designItem, event);
529
- }
530
- }
531
- }
532
516
  showDesignItemContextMenu(designItem, event) {
517
+ this._currentContextMenu?.close();
533
518
  const mnuItems = [];
534
519
  for (let cme of this.serviceContainer.designerContextMenuExtensions) {
535
520
  if (cme.shouldProvideContextmenu(event, this, designItem, 'designer')) {
536
521
  mnuItems.push(...cme.provideContextMenuItems(event, this, designItem));
537
522
  }
538
523
  }
539
- let ctxMnu = ContextMenuHelper.showContextMenu(null, event, null, mnuItems);
540
- return ctxMnu;
524
+ this._currentContextMenu = ContextMenuHelper.showContextMenu(null, event, null, mnuItems);
525
+ return this._currentContextMenu;
541
526
  }
542
527
  _onDblClick(event) {
543
528
  event.preventDefault();
@@ -692,8 +677,6 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
692
677
  }
693
678
  if (event.composedPath().indexOf(this.eatEvents) >= 0)
694
679
  return;
695
- if (event.buttons == 2)
696
- return;
697
680
  let currentElement;
698
681
  if (forceElement)
699
682
  currentElement = forceElement;
@@ -16,6 +16,7 @@ export declare class PointerTool implements ITool {
16
16
  constructor();
17
17
  activated(serviceContainer: ServiceContainer): void;
18
18
  dispose(): void;
19
+ private _showContextMenu;
19
20
  pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element): void;
20
21
  private _pointerActionTypeDrawSelection;
21
22
  private _resetPointerEventsForClickThrough;
@@ -22,7 +22,26 @@ export class PointerTool {
22
22
  }
23
23
  dispose() {
24
24
  }
25
+ _showContextMenu(event, designerCanvas) {
26
+ event.preventDefault();
27
+ if (!event.shiftKey) {
28
+ let items = designerCanvas.getItemsBelowMouse(event);
29
+ if (items.indexOf(designerCanvas.instanceServiceContainer.selectionService.primarySelection?.element) >= 0)
30
+ designerCanvas.showDesignItemContextMenu(designerCanvas.instanceServiceContainer.selectionService.primarySelection, event);
31
+ else {
32
+ const designItem = DesignItem.GetOrCreateDesignItem(event.target, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
33
+ if (!designerCanvas.instanceServiceContainer.selectionService.isSelected(designItem)) {
34
+ designerCanvas.instanceServiceContainer.selectionService.setSelectedElements([designItem]);
35
+ }
36
+ designerCanvas.showDesignItemContextMenu(designItem, event);
37
+ }
38
+ }
39
+ }
25
40
  pointerEventHandler(designerCanvas, event, currentElement) {
41
+ if (event.button == 2) {
42
+ this._showContextMenu(event, designerCanvas);
43
+ return;
44
+ }
26
45
  if (((event.ctrlKey || event.metaKey) && event.shiftKey) || event.buttons == 4) {
27
46
  const panTool = designerCanvas.serviceContainer.designerTools.get(NamedTools.Pan);
28
47
  if (panTool) {
@@ -0,0 +1,8 @@
1
+ export declare enum Orientation {
2
+ TOP = 0,
3
+ RIGHT = 1,
4
+ BOTTOM = 2,
5
+ LEFT = 3,
6
+ VERTICAL_CENTER = 4,
7
+ HORIZONTAL_CENTER = 5
8
+ }
@@ -0,0 +1,9 @@
1
+ export var Orientation;
2
+ (function (Orientation) {
3
+ Orientation[Orientation["TOP"] = 0] = "TOP";
4
+ Orientation[Orientation["RIGHT"] = 1] = "RIGHT";
5
+ Orientation[Orientation["BOTTOM"] = 2] = "BOTTOM";
6
+ Orientation[Orientation["LEFT"] = 3] = "LEFT";
7
+ Orientation[Orientation["VERTICAL_CENTER"] = 4] = "VERTICAL_CENTER";
8
+ Orientation[Orientation["HORIZONTAL_CENTER"] = 5] = "HORIZONTAL_CENTER";
9
+ })(Orientation || (Orientation = {}));
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.89",
4
+ "version": "0.0.90",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",