Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 5d821f1

Browse files
feat: align native or custom
1 parent 957c244 commit 5d821f1

File tree

6 files changed

+42
-12
lines changed

6 files changed

+42
-12
lines changed

webcomponents/inline-editor/src/components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export namespace Components {
2121
}
2222
interface DeckgoIeAlignActions {
2323
"anchorEvent": MouseEvent | TouchEvent;
24+
"command": 'native' | 'custom';
2425
"containers": string;
2526
"contentAlign": ContentAlign;
2627
"mobile": boolean;
@@ -251,6 +252,7 @@ declare namespace LocalJSX {
251252
}
252253
interface DeckgoIeAlignActions {
253254
"anchorEvent"?: MouseEvent | TouchEvent;
255+
"command"?: 'native' | 'custom';
254256
"containers"?: string;
255257
"contentAlign"?: ContentAlign;
256258
"mobile"?: boolean;

webcomponents/inline-editor/src/components/actions/align-actions/align-actions.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {Component, EventEmitter, h, Prop, Event, Host} from '@stencil/core';
22

33
import {ContentAlign} from '../../../types/enums';
44

5-
import {DeckdeckgoInlineEditorUtils} from '../../../utils/utils';
5+
import { execCommandAlign } from "../../../utils/execcommand-align.utils";
6+
import { execCommandNativeAlign } from "../../../utils/execcommnad-native.utils";
67

78
@Component({
89
tag: 'deckgo-ie-align-actions',
@@ -25,23 +26,22 @@ export class AlignActions {
2526
@Prop()
2627
containers: string;
2728

29+
@Prop()
30+
command: 'native' | 'custom' = 'native';
31+
2832
@Event()
2933
private alignModified: EventEmitter;
3034

31-
private justifyContent(e: UIEvent, align: ContentAlign): Promise<void> {
35+
private justifyContent($event: UIEvent, align: ContentAlign): Promise<void> {
3236
return new Promise<void>(async (resolve) => {
33-
e.stopPropagation();
37+
$event.stopPropagation();
3438

35-
const anchorElement: HTMLElement = this.anchorEvent.target as HTMLElement;
36-
const container: HTMLElement | undefined = await DeckdeckgoInlineEditorUtils.findContainer(this.containers, anchorElement);
37-
38-
if (!container) {
39-
resolve();
40-
return;
39+
if (this.command === 'native') {
40+
execCommandNativeAlign(align);
41+
} else {
42+
await execCommandAlign(this.anchorEvent, this.containers, align);
4143
}
4244

43-
container.style.textAlign = container?.style.textAlign === align ? '' : align;
44-
4545
await this.alignModified.emit();
4646

4747
resolve();

webcomponents/inline-editor/src/components/actions/align-actions/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| Property | Attribute | Description | Type | Default |
1111
| -------------- | --------------- | ----------- | ---------------------------------------------------------------- | ----------- |
1212
| `anchorEvent` | -- | | `MouseEvent \| TouchEvent` | `undefined` |
13+
| `command` | `command` | | `"custom" \| "native"` | `'native'` |
1314
| `containers` | `containers` | | `string` | `undefined` |
1415
| `contentAlign` | `content-align` | | `ContentAlign.CENTER \| ContentAlign.LEFT \| ContentAlign.RIGHT` | `undefined` |
1516
| `mobile` | `mobile` | | `boolean` | `undefined` |

webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ export class DeckdeckgoInlineEditor {
909909
mobile={this.mobile}
910910
sticky={sticky}
911911
contentAlign={this.contentAlign}
912+
command={this.command}
912913
onAlignModified={() => this.reset(true)}></deckgo-ie-align-actions>
913914
);
914915
} else if (this.toolbarActions === ToolbarActions.LIST) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { DeckdeckgoInlineEditorUtils } from "./utils";
2+
import { ContentAlign } from "../types/enums";
3+
4+
export const execCommandAlign = async (anchorEvent: MouseEvent | TouchEvent, containers: string, align: ContentAlign) => {
5+
const anchorElement: HTMLElement = anchorEvent.target as HTMLElement;
6+
const container: HTMLElement | undefined = await DeckdeckgoInlineEditorUtils.findContainer(containers, anchorElement);
7+
8+
if (!container) {
9+
return;
10+
}
11+
12+
container.style.textAlign = container?.style.textAlign === align ? '' : align;
13+
}

webcomponents/inline-editor/src/utils/execcommnad-native.utils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ExecCommandAction, ExecCommandList, ExecCommandStyle } from "../interfaces/interfaces";
2-
import { FontSize } from "../types/enums";
2+
import { ContentAlign, FontSize } from "../types/enums";
33

44
export const execCommandNative = (action: ExecCommandAction) => {
55
if (action.cmd === 'style') {
@@ -49,3 +49,16 @@ const execCommandNativeList = (action: ExecCommandAction) => {
4949
break;
5050
}
5151
}
52+
53+
export const execCommandNativeAlign = (align: ContentAlign) => {
54+
switch (align) {
55+
case ContentAlign.CENTER:
56+
document.execCommand('justifyCenter', false, null);
57+
break;
58+
case ContentAlign.RIGHT:
59+
document.execCommand('justifyRight', false, null);
60+
break;
61+
default:
62+
document.execCommand('justifyLeft', false, null);
63+
}
64+
}

0 commit comments

Comments
 (0)