@uiw/react-md-editor 3.19.0 → 3.19.1
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.
- package/dist/mdeditor.js +1559 -1578
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.js.map +1 -1
- package/esm/Editor.js +43 -67
- package/esm/Editor.js.map +1 -1
- package/esm/commands/bold.js +4 -4
- package/esm/commands/bold.js.map +1 -1
- package/esm/commands/code.js +4 -6
- package/esm/commands/code.js.map +1 -1
- package/esm/commands/comment.js +4 -4
- package/esm/commands/comment.js.map +1 -1
- package/esm/commands/divider.js.map +1 -1
- package/esm/commands/fullscreen.js +3 -4
- package/esm/commands/fullscreen.js.map +2 -2
- package/esm/commands/group.js +2 -4
- package/esm/commands/group.js.map +1 -1
- package/esm/commands/hr.js.map +1 -1
- package/esm/commands/image.js +4 -4
- package/esm/commands/image.js.map +1 -1
- package/esm/commands/index.d.ts +2 -2
- package/esm/commands/index.js +6 -17
- package/esm/commands/index.js.map +3 -2
- package/esm/commands/italic.js +4 -4
- package/esm/commands/italic.js.map +1 -1
- package/esm/commands/link.js +4 -4
- package/esm/commands/link.js.map +1 -1
- package/esm/commands/list.js +4 -4
- package/esm/commands/list.js.map +1 -1
- package/esm/commands/preview.js +21 -3
- package/esm/commands/preview.js.map +7 -2
- package/esm/commands/quote.js +2 -1
- package/esm/commands/quote.js.map +1 -1
- package/esm/commands/strikeThrough.js +4 -4
- package/esm/commands/strikeThrough.js.map +1 -1
- package/esm/commands/title.js.map +1 -1
- package/esm/commands/title1.js.map +1 -1
- package/esm/commands/title2.js.map +1 -1
- package/esm/commands/title3.js.map +1 -1
- package/esm/commands/title4.js.map +1 -1
- package/esm/commands/title5.js.map +1 -1
- package/esm/commands/title6.js.map +1 -1
- package/esm/components/DragBar/index.js +2 -9
- package/esm/components/DragBar/index.js.map +1 -1
- package/esm/components/TextArea/Markdown.js +2 -7
- package/esm/components/TextArea/Markdown.js.map +1 -1
- package/esm/components/TextArea/Textarea.js +8 -11
- package/esm/components/TextArea/Textarea.js.map +1 -1
- package/esm/components/TextArea/handleKeyDown.js +2 -16
- package/esm/components/TextArea/handleKeyDown.js.map +1 -1
- package/esm/components/TextArea/index.js +11 -15
- package/esm/components/TextArea/index.js.map +1 -1
- package/esm/components/TextArea/shortcuts.js +1 -17
- package/esm/components/TextArea/shortcuts.js.map +2 -2
- package/esm/components/Toolbar/Child.js +2 -1
- package/esm/components/Toolbar/Child.js.map +1 -1
- package/esm/components/Toolbar/index.js +2 -12
- package/esm/components/Toolbar/index.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/utils/InsertTextAtPosition.js +28 -34
- package/esm/utils/InsertTextAtPosition.js.map +1 -1
- package/esm/utils/markdownUtils.js +14 -23
- package/esm/utils/markdownUtils.js.map +1 -1
- package/lib/Context.js +0 -6
- package/lib/Context.js.map +1 -1
- package/lib/Editor.js +74 -114
- package/lib/Editor.js.map +1 -1
- package/lib/commands/bold.js +4 -9
- package/lib/commands/bold.js.map +1 -1
- package/lib/commands/code.js +4 -11
- package/lib/commands/code.js.map +1 -1
- package/lib/commands/comment.js +4 -7
- package/lib/commands/comment.js.map +1 -1
- package/lib/commands/divider.js.map +1 -1
- package/lib/commands/fullscreen.js +3 -8
- package/lib/commands/fullscreen.js.map +2 -2
- package/lib/commands/group.js +2 -10
- package/lib/commands/group.js.map +1 -1
- package/lib/commands/hr.js +0 -4
- package/lib/commands/hr.js.map +1 -1
- package/lib/commands/image.js +4 -9
- package/lib/commands/image.js.map +1 -1
- package/lib/commands/index.d.ts +2 -2
- package/lib/commands/index.js +4 -41
- package/lib/commands/index.js.map +3 -2
- package/lib/commands/italic.js +4 -9
- package/lib/commands/italic.js.map +1 -1
- package/lib/commands/link.js +4 -9
- package/lib/commands/link.js.map +1 -1
- package/lib/commands/list.js +4 -10
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/preview.js +21 -7
- package/lib/commands/preview.js.map +7 -2
- package/lib/commands/quote.js +2 -6
- package/lib/commands/quote.js.map +1 -1
- package/lib/commands/strikeThrough.js +4 -9
- package/lib/commands/strikeThrough.js.map +1 -1
- package/lib/commands/title.js +0 -6
- package/lib/commands/title.js.map +1 -1
- package/lib/commands/title1.js +0 -5
- package/lib/commands/title1.js.map +1 -1
- package/lib/commands/title2.js +0 -5
- package/lib/commands/title2.js.map +1 -1
- package/lib/commands/title3.js +0 -5
- package/lib/commands/title3.js.map +1 -1
- package/lib/commands/title4.js +0 -5
- package/lib/commands/title4.js.map +1 -1
- package/lib/commands/title5.js +0 -5
- package/lib/commands/title5.js.map +1 -1
- package/lib/commands/title6.js +0 -5
- package/lib/commands/title6.js.map +1 -1
- package/lib/components/DragBar/index.js +4 -15
- package/lib/components/DragBar/index.js.map +1 -1
- package/lib/components/TextArea/Markdown.js +6 -22
- package/lib/components/TextArea/Markdown.js.map +1 -1
- package/lib/components/TextArea/Textarea.js +15 -36
- package/lib/components/TextArea/Textarea.js.map +1 -1
- package/lib/components/TextArea/handleKeyDown.js +1 -18
- package/lib/components/TextArea/handleKeyDown.js.map +1 -1
- package/lib/components/TextArea/index.js +15 -37
- package/lib/components/TextArea/index.js.map +1 -1
- package/lib/components/TextArea/shortcuts.js +1 -17
- package/lib/components/TextArea/shortcuts.js.map +2 -2
- package/lib/components/Toolbar/Child.js +8 -18
- package/lib/components/Toolbar/Child.js.map +1 -1
- package/lib/components/Toolbar/index.js +14 -36
- package/lib/components/Toolbar/index.js.map +1 -1
- package/lib/index.js +0 -9
- package/lib/index.js.map +1 -1
- package/lib/utils/InsertTextAtPosition.js +28 -37
- package/lib/utils/InsertTextAtPosition.js.map +1 -1
- package/lib/utils/markdownUtils.js +17 -28
- package/lib/utils/markdownUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/fullscreen.tsx +3 -2
- package/src/commands/index.ts +3 -1
- package/src/commands/preview.tsx +35 -4
- package/src/components/TextArea/shortcuts.ts +2 -2
|
@@ -7,118 +7,107 @@ exports.getBreaksNeededForEmptyLineAfter = getBreaksNeededForEmptyLineAfter;
|
|
|
7
7
|
exports.getBreaksNeededForEmptyLineBefore = getBreaksNeededForEmptyLineBefore;
|
|
8
8
|
exports.getSurroundingWord = getSurroundingWord;
|
|
9
9
|
exports.selectWord = selectWord;
|
|
10
|
-
|
|
11
10
|
function selectWord(_ref) {
|
|
12
11
|
var text = _ref.text,
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
selection = _ref.selection;
|
|
15
13
|
if (text && text.length && selection.start === selection.end) {
|
|
16
14
|
// the user is pointing to a word
|
|
17
15
|
return getSurroundingWord(text, selection.start);
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
return selection;
|
|
21
18
|
}
|
|
19
|
+
|
|
22
20
|
/**
|
|
23
21
|
* Gets the number of line-breaks that would have to be inserted before the given 'startPosition'
|
|
24
22
|
* to make sure there's an empty line between 'startPosition' and the previous text
|
|
25
23
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
24
|
function getBreaksNeededForEmptyLineBefore() {
|
|
29
25
|
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
30
26
|
var startPosition = arguments.length > 1 ? arguments[1] : undefined;
|
|
31
|
-
if (startPosition === 0) return 0;
|
|
27
|
+
if (startPosition === 0) return 0;
|
|
28
|
+
|
|
29
|
+
// rules:
|
|
32
30
|
// - If we're in the first line, no breaks are needed
|
|
33
31
|
// - Otherwise there must be 2 breaks before the previous character. Depending on how many breaks exist already, we
|
|
34
32
|
// may need to insert 0, 1 or 2 breaks
|
|
35
33
|
|
|
36
34
|
var neededBreaks = 2;
|
|
37
35
|
var isInFirstLine = true;
|
|
38
|
-
|
|
39
36
|
for (var i = startPosition - 1; i >= 0 && neededBreaks >= 0; i--) {
|
|
40
37
|
switch (text.charCodeAt(i)) {
|
|
41
38
|
case 32:
|
|
42
39
|
// blank space
|
|
43
40
|
continue;
|
|
44
|
-
|
|
45
41
|
case 10:
|
|
46
42
|
// line break
|
|
47
43
|
neededBreaks--;
|
|
48
44
|
isInFirstLine = false;
|
|
49
45
|
break;
|
|
50
|
-
|
|
51
46
|
default:
|
|
52
47
|
return neededBreaks;
|
|
53
48
|
}
|
|
54
49
|
}
|
|
55
|
-
|
|
56
50
|
return isInFirstLine ? 0 : neededBreaks;
|
|
57
51
|
}
|
|
52
|
+
|
|
58
53
|
/**
|
|
59
54
|
* Gets the number of line-breaks that would have to be inserted after the given 'startPosition'
|
|
60
55
|
* to make sure there's an empty line between 'startPosition' and the next text
|
|
61
56
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
57
|
function getBreaksNeededForEmptyLineAfter() {
|
|
65
58
|
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
66
59
|
var startPosition = arguments.length > 1 ? arguments[1] : undefined;
|
|
67
|
-
if (startPosition === text.length - 1) return 0;
|
|
60
|
+
if (startPosition === text.length - 1) return 0;
|
|
61
|
+
|
|
62
|
+
// rules:
|
|
68
63
|
// - If we're in the first line, no breaks are needed
|
|
69
64
|
// - Otherwise there must be 2 breaks before the previous character. Depending on how many breaks exist already, we
|
|
70
65
|
// may need to insert 0, 1 or 2 breaks
|
|
71
66
|
|
|
72
67
|
var neededBreaks = 2;
|
|
73
68
|
var isInLastLine = true;
|
|
74
|
-
|
|
75
69
|
for (var i = startPosition; i < text.length && neededBreaks >= 0; i++) {
|
|
76
70
|
switch (text.charCodeAt(i)) {
|
|
77
71
|
case 32:
|
|
78
72
|
continue;
|
|
79
|
-
|
|
80
73
|
case 10:
|
|
81
74
|
{
|
|
82
75
|
neededBreaks--;
|
|
83
76
|
isInLastLine = false;
|
|
84
77
|
break;
|
|
85
78
|
}
|
|
86
|
-
|
|
87
79
|
default:
|
|
88
80
|
return neededBreaks;
|
|
89
81
|
}
|
|
90
82
|
}
|
|
91
|
-
|
|
92
83
|
return isInLastLine ? 0 : neededBreaks;
|
|
93
84
|
}
|
|
94
|
-
|
|
95
85
|
function getSurroundingWord(text, position) {
|
|
96
86
|
if (!text) throw Error("Argument 'text' should be truthy");
|
|
97
|
-
|
|
98
87
|
var isWordDelimiter = function isWordDelimiter(c) {
|
|
99
88
|
return c === ' ' || c.charCodeAt(0) === 10;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
var start = 0; // rightIndex is initialized to text.length because if selection is equal to text.length it won't even enter the interation
|
|
89
|
+
};
|
|
104
90
|
|
|
105
|
-
|
|
91
|
+
// leftIndex is initialized to 0 because if selection is 0, it won't even enter the iteration
|
|
92
|
+
var start = 0;
|
|
93
|
+
// rightIndex is initialized to text.length because if selection is equal to text.length it won't even enter the interation
|
|
94
|
+
var end = text.length;
|
|
106
95
|
|
|
96
|
+
// iterate to the left
|
|
107
97
|
for (var i = position; i - 1 > -1; i--) {
|
|
108
98
|
if (isWordDelimiter(text[i - 1])) {
|
|
109
99
|
start = i;
|
|
110
100
|
break;
|
|
111
101
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
102
|
+
}
|
|
114
103
|
|
|
104
|
+
// iterate to the right
|
|
115
105
|
for (var _i = position; _i < text.length; _i++) {
|
|
116
106
|
if (isWordDelimiter(text[_i])) {
|
|
117
107
|
end = _i;
|
|
118
108
|
break;
|
|
119
109
|
}
|
|
120
110
|
}
|
|
121
|
-
|
|
122
111
|
return {
|
|
123
112
|
start: start,
|
|
124
113
|
end: end
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"sourcesContent": [
|
|
28
28
|
"import { TextRange } from '../commands';\n\nexport interface TextSection {\n text: string;\n selection: TextRange;\n}\n\nexport function selectWord({ text, selection }: TextSection): TextRange {\n if (text && text.length && selection.start === selection.end) {\n // the user is pointing to a word\n return getSurroundingWord(text, selection.start);\n }\n return selection;\n}\n\n/**\n * Gets the number of line-breaks that would have to be inserted before the given 'startPosition'\n * to make sure there's an empty line between 'startPosition' and the previous text\n */\nexport function getBreaksNeededForEmptyLineBefore(text = '', startPosition: number): number {\n if (startPosition === 0) return 0;\n\n // rules:\n // - If we're in the first line, no breaks are needed\n // - Otherwise there must be 2 breaks before the previous character. Depending on how many breaks exist already, we\n // may need to insert 0, 1 or 2 breaks\n\n let neededBreaks = 2;\n let isInFirstLine = true;\n for (let i = startPosition - 1; i >= 0 && neededBreaks >= 0; i--) {\n switch (text.charCodeAt(i)) {\n case 32: // blank space\n continue;\n case 10: // line break\n neededBreaks--;\n isInFirstLine = false;\n break;\n default:\n return neededBreaks;\n }\n }\n return isInFirstLine ? 0 : neededBreaks;\n}\n\n/**\n * Gets the number of line-breaks that would have to be inserted after the given 'startPosition'\n * to make sure there's an empty line between 'startPosition' and the next text\n */\nexport function getBreaksNeededForEmptyLineAfter(text = '', startPosition: number): number {\n if (startPosition === text.length - 1) return 0;\n\n // rules:\n // - If we're in the first line, no breaks are needed\n // - Otherwise there must be 2 breaks before the previous character. Depending on how many breaks exist already, we\n // may need to insert 0, 1 or 2 breaks\n\n let neededBreaks = 2;\n let isInLastLine = true;\n for (let i = startPosition; i < text.length && neededBreaks >= 0; i++) {\n switch (text.charCodeAt(i)) {\n case 32:\n continue;\n case 10: {\n neededBreaks--;\n isInLastLine = false;\n break;\n }\n default:\n return neededBreaks;\n }\n }\n return isInLastLine ? 0 : neededBreaks;\n}\n\nexport function getSurroundingWord(text: string, position: number): TextRange {\n if (!text) throw Error(\"Argument 'text' should be truthy\");\n\n const isWordDelimiter = (c: string) => c === ' ' || c.charCodeAt(0) === 10;\n\n // leftIndex is initialized to 0 because if selection is 0, it won't even enter the iteration\n let start = 0;\n // rightIndex is initialized to text.length because if selection is equal to text.length it won't even enter the interation\n let end = text.length;\n\n // iterate to the left\n for (let i = position; i - 1 > -1; i--) {\n if (isWordDelimiter(text[i - 1])) {\n start = i;\n break;\n }\n }\n\n // iterate to the right\n for (let i = position; i < text.length; i++) {\n if (isWordDelimiter(text[i])) {\n end = i;\n break;\n }\n }\n\n return { start, end };\n}\n"
|
|
29
29
|
],
|
|
30
|
-
"mappings": "
|
|
30
|
+
"mappings": ";;;;;;;;;AAOO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
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.1",
|
|
4
4
|
"description": "A markdown editor with preview, implemented with React.js and TypeScript.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-md-editor/",
|
|
6
6
|
"author": "kenny wang <wowohoo@qq.com>",
|
|
@@ -21,10 +21,11 @@ export const fullscreen: ICommand = {
|
|
|
21
21
|
api: TextAreaTextApi,
|
|
22
22
|
dispatch?: React.Dispatch<ContextStore>,
|
|
23
23
|
executeCommandState?: ExecuteCommandState,
|
|
24
|
+
shortcuts?: string[],
|
|
24
25
|
) => {
|
|
25
26
|
api.textArea.focus();
|
|
26
|
-
if (
|
|
27
|
-
dispatch({ fullscreen:
|
|
27
|
+
if (shortcuts && dispatch && executeCommandState) {
|
|
28
|
+
dispatch({ fullscreen: !executeCommandState.fullscreen });
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
};
|
package/src/commands/index.ts
CHANGED
|
@@ -62,6 +62,7 @@ export interface ICommandBase<T> {
|
|
|
62
62
|
api: TextAreaTextApi,
|
|
63
63
|
dispatch?: React.Dispatch<ContextStore>,
|
|
64
64
|
executeCommandState?: ExecuteCommandState,
|
|
65
|
+
shortcuts?: string[],
|
|
65
66
|
) => void;
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -161,8 +162,9 @@ class TextAreaCommandOrchestrator implements CommandOrchestrator {
|
|
|
161
162
|
command: ICommand<string>,
|
|
162
163
|
dispatch?: React.Dispatch<ContextStore>,
|
|
163
164
|
state?: ExecuteCommandState,
|
|
165
|
+
shortcuts?: string[],
|
|
164
166
|
): void {
|
|
165
|
-
command.execute && command.execute(getStateFromTextArea(this.textArea), this.textApi, dispatch, state);
|
|
167
|
+
command.execute && command.execute(getStateFromTextArea(this.textArea), this.textApi, dispatch, state, shortcuts);
|
|
166
168
|
}
|
|
167
169
|
}
|
|
168
170
|
|
package/src/commands/preview.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ICommand } from './';
|
|
2
|
+
import { ICommand, TextState, TextAreaTextApi } from './';
|
|
3
|
+
import { ContextStore, ExecuteCommandState } from '../Context';
|
|
3
4
|
|
|
4
5
|
export const codePreview: ICommand = {
|
|
5
6
|
name: 'preview',
|
|
@@ -19,7 +20,17 @@ export const codePreview: ICommand = {
|
|
|
19
20
|
/>
|
|
20
21
|
</svg>
|
|
21
22
|
),
|
|
22
|
-
execute: (
|
|
23
|
+
execute: (
|
|
24
|
+
state: TextState,
|
|
25
|
+
api: TextAreaTextApi,
|
|
26
|
+
dispatch?: React.Dispatch<ContextStore>,
|
|
27
|
+
executeCommandState?: ExecuteCommandState,
|
|
28
|
+
shortcuts?: string[],
|
|
29
|
+
) => {
|
|
30
|
+
if (shortcuts && dispatch && executeCommandState) {
|
|
31
|
+
dispatch({ preview: 'preview' });
|
|
32
|
+
}
|
|
33
|
+
},
|
|
23
34
|
};
|
|
24
35
|
|
|
25
36
|
export const codeEdit: ICommand = {
|
|
@@ -37,7 +48,17 @@ export const codeEdit: ICommand = {
|
|
|
37
48
|
/>
|
|
38
49
|
</svg>
|
|
39
50
|
),
|
|
40
|
-
execute: (
|
|
51
|
+
execute: (
|
|
52
|
+
state: TextState,
|
|
53
|
+
api: TextAreaTextApi,
|
|
54
|
+
dispatch?: React.Dispatch<ContextStore>,
|
|
55
|
+
executeCommandState?: ExecuteCommandState,
|
|
56
|
+
shortcuts?: string[],
|
|
57
|
+
) => {
|
|
58
|
+
if (shortcuts && dispatch && executeCommandState) {
|
|
59
|
+
dispatch({ preview: 'edit' });
|
|
60
|
+
}
|
|
61
|
+
},
|
|
41
62
|
};
|
|
42
63
|
|
|
43
64
|
export const codeLive: ICommand = {
|
|
@@ -55,5 +76,15 @@ export const codeLive: ICommand = {
|
|
|
55
76
|
/>
|
|
56
77
|
</svg>
|
|
57
78
|
),
|
|
58
|
-
execute: (
|
|
79
|
+
execute: (
|
|
80
|
+
state: TextState,
|
|
81
|
+
api: TextAreaTextApi,
|
|
82
|
+
dispatch?: React.Dispatch<ContextStore>,
|
|
83
|
+
executeCommandState?: ExecuteCommandState,
|
|
84
|
+
shortcuts?: string[],
|
|
85
|
+
) => {
|
|
86
|
+
if (shortcuts && dispatch && executeCommandState) {
|
|
87
|
+
dispatch({ preview: 'live' });
|
|
88
|
+
}
|
|
89
|
+
},
|
|
59
90
|
};
|
|
@@ -20,7 +20,7 @@ export default function shortcutsHandle(
|
|
|
20
20
|
state?: ExecuteCommandState,
|
|
21
21
|
) {
|
|
22
22
|
const data = getCommands(commands || []);
|
|
23
|
-
const shortcuts:
|
|
23
|
+
const shortcuts: string[] = [];
|
|
24
24
|
if (e.altKey) {
|
|
25
25
|
shortcuts.push('alt');
|
|
26
26
|
}
|
|
@@ -60,7 +60,7 @@ export default function shortcutsHandle(
|
|
|
60
60
|
if (command && commandOrchestrator) {
|
|
61
61
|
e.stopPropagation();
|
|
62
62
|
e.preventDefault();
|
|
63
|
-
commandOrchestrator.executeCommand(command, dispatch, state);
|
|
63
|
+
commandOrchestrator.executeCommand(command, dispatch, state, shortcuts);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
}
|