Skip to content

Commit a3301d0

Browse files
committed
add icons
1 parent 97e587d commit a3301d0

37 files changed

+111
-41
lines changed

ACKNOWLEDGMENTS

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
- Domi for text-width code
1313
https://stackoverflow.com/a/21015393
1414
- gwwar for getClosestStackingContext
15-
https://github.com/gwwar/z-context
15+
https://github.com/gwwar/z-context
16+
- google icons
17+
https://fonts.google.com/icons
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

packages/web-component-designer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"description": "A WYSIWYG designer webcomponent for html components",
33
"name": "@node-projects/web-component-designer",
4-
"version": "0.1.134",
4+
"version": "0.1.135",
55
"type": "module",
66
"main": "./dist/index.js",
77
"author": "[email protected]",

packages/web-component-designer/src/elements/helper/contextMenu/ContextMenu.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class ContextMenu implements IContextMenu {
5050
padding-right: 1.7em;
5151
cursor: pointer;
5252
white-space: nowrap;
53+
display: flex;
54+
align-items: center;
5355
}
5456
5557
.context_menu li:hover {
@@ -58,10 +60,16 @@ export class ContextMenu implements IContextMenu {
5860
5961
.context_menu li .context_menu_icon_span {
6062
width: 28px;
61-
display: inline-block;
63+
display: inline-flex;
64+
align-items: center;
65+
justify-content: center;
6266
border-right: 1px solid #aaa;
6367
}
6468
69+
.context_menu li .context_menu_icon_span img {
70+
height: 18px;
71+
}
72+
6573
.context_menu li .context_menu_text {
6674
padding-left: 2px;
6775
vertical-align: middle;

packages/web-component-designer/src/elements/services/DefaultServiceBootstrap.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { GridChildToolbarExtensionProvider } from '../widgets/designerView/exten
9494
import { ToolbarExtensionsDesignViewConfigButtons } from '../widgets/designerView/extensions/buttons/ToolbarExtensionsDesignViewConfigButtons.js';
9595
import { PaddingExtensionProvider } from '../widgets/designerView/extensions/PaddingExtensionProvider.js';
9696
import { GridChildResizeExtensionProvider } from '../widgets/designerView/extensions/grid/GridChildResizeExtensionProvider.js';
97+
import { AlignItemsContextMenu } from '../widgets/designerView/extensions/contextMenu/AlignItemsContextMenu.js';
9798

9899
export function createDefaultServiceContainer() {
99100
let serviceContainer = new ServiceContainer();
@@ -237,7 +238,7 @@ export function createDefaultServiceContainer() {
237238
serviceContainer.designerContextMenuExtensions = [
238239
new ChildContextMenu('edit', new CopyPasteContextMenu()),
239240
new SeperatorContextMenu(),
240-
new ChildContextMenu('modify', new RotateLeftAndRight(), new SeperatorContextMenu(), new ZMoveContextMenu()),
241+
new ChildContextMenu('modify', new RotateLeftAndRight(), new SeperatorContextMenu(), new ZMoveContextMenu(), new SeperatorContextMenu(), new AlignItemsContextMenu()),
241242
new SeperatorContextMenu(),
242243
new ChildContextMenu('view', new JumpToElementContextMenu(), new ZoomToElementContextMenu()),
243244
new SeperatorContextMenu(),

packages/web-component-designer/src/elements/services/modelCommandService/DefaultModelCommandService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class DefaultModelCommandService implements IModelCommandService {
1212
command.type == CommandType.moveForward ||
1313
command.type == CommandType.moveToBack ||
1414
command.type == CommandType.moveToFront)
15-
return designerCanvas.instanceServiceContainer.selectionService.primarySelection != null;
15+
return designerCanvas.instanceServiceContainer.selectionService.primarySelection != null && !designerCanvas.instanceServiceContainer.selectionService.primarySelection.isRootItem;
1616
if (command.type == CommandType.arrangeBottom ||
1717
command.type == CommandType.arrangeCenter ||
1818
command.type == CommandType.arrangeLeft ||
@@ -26,7 +26,7 @@ export class DefaultModelCommandService implements IModelCommandService {
2626
command.type == CommandType.rotateClockwise ||
2727
command.type == CommandType.mirrorHorizontal ||
2828
command.type == CommandType.mirrorVertical)
29-
return designerCanvas.instanceServiceContainer.selectionService.selectedElements.length > 0;
29+
return designerCanvas.instanceServiceContainer.selectionService.selectedElements.length > 0 && !designerCanvas.instanceServiceContainer.selectionService.primarySelection.isRootItem;
3030
return null;
3131
}
3232

packages/web-component-designer/src/elements/widgets/designerView/designerCanvas.ts

+28-23
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,34 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend implements
397397

398398
/* --- start IUiCommandHandler --- */
399399

400+
canExecuteCommand(command: IUiCommand) {
401+
const modelCommandService = this.serviceContainer.modelCommandService;
402+
if (modelCommandService) {
403+
let handeled = modelCommandService.canExecuteCommand(this, command)
404+
if (handeled !== null)
405+
return handeled;
406+
}
407+
408+
if (command.type === CommandType.undo) {
409+
return this.instanceServiceContainer.undoService.canUndo();
410+
}
411+
if (command.type === CommandType.redo) {
412+
return this.instanceServiceContainer.undoService.canRedo();
413+
}
414+
if (command.type === CommandType.setTool) {
415+
return this.serviceContainer.designerTools.has(command.parameter);
416+
}
417+
418+
if (command.type === CommandType.paste) {
419+
return true;
420+
}
421+
if (command.type === CommandType.copy || command.type === CommandType.cut || command.type === CommandType.delete) {
422+
return this.instanceServiceContainer.selectionService.primarySelection != null && !this.instanceServiceContainer.selectionService.primarySelection.isRootItem;
423+
}
424+
425+
return true;
426+
}
427+
400428
async executeCommand(command: IUiCommand) {
401429
const modelCommandService = this.serviceContainer.modelCommandService;
402430
if (modelCommandService) {
@@ -527,29 +555,6 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend implements
527555
//this._zoomInput.value = Math.round(this.zoomFactor * 100) + '%';
528556
}
529557

530-
531-
canExecuteCommand(command: IUiCommand) {
532-
const modelCommandService = this.serviceContainer.modelCommandService;
533-
if (modelCommandService) {
534-
let handeled = modelCommandService.canExecuteCommand(this, command)
535-
if (handeled !== null)
536-
return handeled;
537-
}
538-
539-
if (command.type === CommandType.undo) {
540-
return this.instanceServiceContainer.undoService.canUndo();
541-
}
542-
if (command.type === CommandType.redo) {
543-
return this.instanceServiceContainer.undoService.canRedo();
544-
}
545-
if (command.type === CommandType.setTool) {
546-
return this.serviceContainer.designerTools.has(command.parameter);
547-
}
548-
549-
550-
return true;
551-
}
552-
553558
/* --- end IUiCommandHandler --- */
554559

555560
handleSelectAll() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { CommandType } from '../../../../../commandHandling/CommandType.js';
2+
import { IContextMenuItem } from '../../../../helper/contextMenu/IContextMenuItem.js';
3+
import { IDesignItem } from '../../../../item/IDesignItem.js';
4+
import { NodeType } from '../../../../item/NodeType.js';
5+
import { IDesignerCanvas } from '../../IDesignerCanvas.js';
6+
import { ContextmenuInitiator, IContextMenuExtension } from './IContextMenuExtension.js';
7+
8+
export class AlignItemsContextMenu implements IContextMenuExtension {
9+
10+
public shouldProvideContextmenu(event: MouseEvent, designerView: IDesignerCanvas, designItem: IDesignItem, initiator: ContextmenuInitiator) {
11+
return !designItem?.isRootItem && designItem?.nodeType == NodeType.Element;
12+
}
13+
14+
public provideContextMenuItems(event: MouseEvent, designerView: IDesignerCanvas, designItem: IDesignItem): IContextMenuItem[] {
15+
return [
16+
{ title: 'align left', icon: `<img src="${new URL('../../../../../../assets/icons/alignHorizontalLeft.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.arrangeLeft }); } },
17+
{ title: 'align center', icon: `<img src="${new URL('../../../../../../assets/icons/alignHorizontalCenter.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.arrangeCenter }); } },
18+
{ title: 'align right', icon: `<img src="${new URL('../../../../../../assets/icons/alignHorizontalRight.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.arrangeRight }); } },
19+
{ title: 'distribute horizontal', icon: `<img src="${new URL('../../../../../../assets/icons/horizontalDistribute.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.distributeHorizontal }); } },
20+
{ title: 'align top', icon: `<img src="${new URL('../../../../../../assets/icons/alignVerticalTop.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.arrangeTop }); } },
21+
{ title: 'align middle', icon: `<img src="${new URL('../../../../../../assets/icons/alignVerticalCenter.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.arrangeMiddle }); } },
22+
{ title: 'align bottom', icon: `<img src="${new URL('../../../../../../assets/icons/alignVerticalBottom.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.arrangeBottom }); } },
23+
{ title: 'distribute vertical', icon: `<img src="${new URL('../../../../../../assets/icons/verticalDistribute.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.distributeVertical }); } },
24+
]
25+
}
26+
}

packages/web-component-designer/src/elements/widgets/designerView/extensions/contextMenu/CopyPasteContextMenu.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export class CopyPasteContextMenu implements IContextMenuExtension {
1111

1212
public provideContextMenuItems(event: MouseEvent, designerView: IDesignerCanvas, designItem: IDesignItem): IContextMenuItem[] {
1313
return [
14-
{ title: 'copy', action: () => { designerView.executeCommand({ type: CommandType.copy }); }, shortCut: 'Ctrl + C', disabled: designItem === null },
15-
{ title: 'cut', action: () => { designerView.executeCommand({ type: CommandType.cut }); }, shortCut: 'Ctrl + X', disabled: designItem === null },
16-
{ title: 'paste', action: () => { designerView.executeCommand({ type: CommandType.paste }); }, shortCut: 'Ctrl + V' },
17-
{ title: 'delete', action: () => { designerView.executeCommand({ type: CommandType.delete }); }, shortCut: 'Del', disabled: designItem === null },
14+
{ title: 'copy', icon: `<img src="${new URL('../../../../../../assets/icons/copy.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.copy }); }, shortCut: 'Ctrl + C', disabled: designItem === null },
15+
{ title: 'cut', icon: `<img src="${new URL('../../../../../../assets/icons/cut.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.cut }); }, shortCut: 'Ctrl + X', disabled: designItem === null },
16+
{ title: 'paste', icon: `<img src="${new URL('../../../../../../assets/icons/paste.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.paste }); }, shortCut: 'Ctrl + V' },
17+
{ title: 'delete', icon: `<img src="${new URL('../../../../../../assets/icons/delete.svg', import.meta.url)}">`, action: () => { designerView.executeCommand({ type: CommandType.delete }); }, shortCut: 'Del', disabled: designItem === null },
1818
]
1919
}
2020
}

0 commit comments

Comments
 (0)