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

Commit 957c244

Browse files
feat: native list
1 parent ad2f28d commit 957c244

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed
Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,51 @@
1-
import { ExecCommandAction, ExecCommandStyle } from "../interfaces/interfaces";
1+
import { ExecCommandAction, ExecCommandList, ExecCommandStyle } from "../interfaces/interfaces";
22
import { FontSize } from "../types/enums";
33

44
export const execCommandNative = (action: ExecCommandAction) => {
55
if (action.cmd === 'style') {
6-
const detail: ExecCommandStyle = action.detail as ExecCommandStyle;
6+
execCommandNativeStyle(action);
7+
} else if (action.cmd === 'list') {
8+
execCommandNativeList(action);
9+
}
10+
}
11+
12+
const execCommandNativeStyle = (action: ExecCommandAction) => {
13+
const detail: ExecCommandStyle = action.detail as ExecCommandStyle;
14+
15+
// @ts-ignore
16+
document.execCommand("styleWithCSS", false, true);
17+
18+
switch (detail.style) {
19+
case 'color':
20+
document.execCommand('foreColor', false, detail.value);
21+
break;
22+
case 'background-color' :
23+
document.execCommand('backColor', false, detail.value);
24+
break;
25+
case 'font-size':
26+
document.execCommand('fontSize', false, FontSize[detail.value.replace('-', '_').toUpperCase()]);
27+
break;
28+
case 'font-weight':
29+
document.execCommand('bold', false, null);
30+
break;
31+
case 'font-style':
32+
document.execCommand('italic', false, null);
33+
break;
34+
case 'text-decoration':
35+
document.execCommand(detail.value === 'line-through' ? 'strikeThrough' : 'underline', false, null);
36+
break;
37+
}
38+
}
739

8-
// @ts-ignore
9-
document.execCommand("styleWithCSS", false, true);
40+
const execCommandNativeList = (action: ExecCommandAction) => {
41+
const detail: ExecCommandList = action.detail as ExecCommandList;
1042

11-
switch (detail.style) {
12-
case 'color':
13-
document.execCommand('foreColor', false, detail.value);
14-
break;
15-
case 'background-color' :
16-
document.execCommand('backColor', false, detail.value);
17-
break;
18-
case 'font-size':
19-
document.execCommand('fontSize', false, FontSize[detail.value.replace('-', '_').toUpperCase()]);
20-
break;
21-
case 'font-weight':
22-
document.execCommand('bold', false, null);
23-
break;
24-
case 'font-style':
25-
document.execCommand('italic', false, null);
26-
break;
27-
case 'text-decoration':
28-
document.execCommand(detail.value === 'line-through' ? 'strikeThrough' : 'underline', false, null);
29-
break;
30-
}
43+
switch (detail.type) {
44+
case 'ol':
45+
document.execCommand('insertOrderedList', false, null);
46+
break;
47+
case 'ul' :
48+
document.execCommand('insertUnorderedList', false, null);
49+
break;
3150
}
3251
}

0 commit comments

Comments
 (0)