|
1 | | -import { ExecCommandAction, ExecCommandStyle } from "../interfaces/interfaces"; |
| 1 | +import { ExecCommandAction, ExecCommandList, ExecCommandStyle } from "../interfaces/interfaces"; |
2 | 2 | import { FontSize } from "../types/enums"; |
3 | 3 |
|
4 | 4 | export const execCommandNative = (action: ExecCommandAction) => { |
5 | 5 | 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 | +} |
7 | 39 |
|
8 | | - // @ts-ignore |
9 | | - document.execCommand("styleWithCSS", false, true); |
| 40 | +const execCommandNativeList = (action: ExecCommandAction) => { |
| 41 | + const detail: ExecCommandList = action.detail as ExecCommandList; |
10 | 42 |
|
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; |
31 | 50 | } |
32 | 51 | } |
0 commit comments