@uiw/react-md-editor 4.1.2 → 4.1.4
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/README.md +3 -1
- package/dist/mdeditor.css +3 -0
- package/dist/mdeditor.js +2717 -2423
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/components/TextArea/handleKeyDown.js +11 -2
- package/esm/components/TextArea/index.css +3 -0
- package/esm/components/TextArea/index.less +4 -1
- package/lib/components/TextArea/handleKeyDown.js +11 -2
- package/lib/components/TextArea/index.less +4 -1
- package/markdown-editor.css +3 -0
- package/package.json +1 -1
- package/src/components/TextArea/handleKeyDown.tsx +12 -2
- package/src/components/TextArea/index.less +4 -1
|
@@ -113,11 +113,20 @@ export default function handleKeyDown(e, tabSize, defaultTabEnable) {
|
|
|
113
113
|
} else {
|
|
114
114
|
return insertTextAtPosition(target, space);
|
|
115
115
|
}
|
|
116
|
-
} else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d
|
|
116
|
+
} else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d+\.\s/.test(currentLineStr)) && !e.shiftKey) {
|
|
117
117
|
/**
|
|
118
118
|
* `13` - `Enter`
|
|
119
119
|
*/
|
|
120
120
|
stopPropagation(e);
|
|
121
|
+
var atEndOfLine = target.selectionEnd === target.value.length || target.value[target.selectionEnd] === '\n';
|
|
122
|
+
var emptyListItem = /^(?:[-*]|\d+\.)\s+$/.test(currentLineStr) || /^- \[[ xX]\]\s*$/.test(currentLineStr);
|
|
123
|
+
if (target.selectionStart === target.selectionEnd && atEndOfLine && emptyListItem) {
|
|
124
|
+
textArea.setSelectionRange({
|
|
125
|
+
start: target.selectionStart - currentLineStr.length,
|
|
126
|
+
end: target.selectionEnd
|
|
127
|
+
});
|
|
128
|
+
return insertTextAtPosition(target, '');
|
|
129
|
+
}
|
|
121
130
|
var startStr = '\n- ';
|
|
122
131
|
if (currentLineStr.startsWith('*')) {
|
|
123
132
|
startStr = '\n* ';
|
|
@@ -125,7 +134,7 @@ export default function handleKeyDown(e, tabSize, defaultTabEnable) {
|
|
|
125
134
|
if (currentLineStr.startsWith('- [ ]') || currentLineStr.startsWith('- [X]') || currentLineStr.startsWith('- [x]')) {
|
|
126
135
|
startStr = '\n- [ ] ';
|
|
127
136
|
}
|
|
128
|
-
if (/^\d
|
|
137
|
+
if (/^\d+\.\s/.test(currentLineStr)) {
|
|
129
138
|
startStr = "\n" + (parseInt(currentLineStr) + 1) + ". ";
|
|
130
139
|
}
|
|
131
140
|
return insertTextAtPosition(target, startStr);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
@md-editor
|
|
1
|
+
@md-editor: ~'w-md-editor';
|
|
2
2
|
|
|
3
3
|
.@{md-editor} {
|
|
4
4
|
&-area {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
5
7
|
overflow: auto;
|
|
6
8
|
border-radius: 5px;
|
|
7
9
|
}
|
|
8
10
|
&-text {
|
|
11
|
+
flex: 1 0 auto;
|
|
9
12
|
min-height: 100%;
|
|
10
13
|
position: relative;
|
|
11
14
|
text-align: left;
|
|
@@ -117,11 +117,20 @@ function handleKeyDown(e) {
|
|
|
117
117
|
} else {
|
|
118
118
|
return (0, _InsertTextAtPosition.insertTextAtPosition)(target, space);
|
|
119
119
|
}
|
|
120
|
-
} else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d
|
|
120
|
+
} else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d+\.\s/.test(currentLineStr)) && !e.shiftKey) {
|
|
121
121
|
/**
|
|
122
122
|
* `13` - `Enter`
|
|
123
123
|
*/
|
|
124
124
|
stopPropagation(e);
|
|
125
|
+
var atEndOfLine = target.selectionEnd === target.value.length || target.value[target.selectionEnd] === '\n';
|
|
126
|
+
var emptyListItem = /^(?:[-*]|\d+\.)\s+$/.test(currentLineStr) || /^- \[[ xX]\]\s*$/.test(currentLineStr);
|
|
127
|
+
if (target.selectionStart === target.selectionEnd && atEndOfLine && emptyListItem) {
|
|
128
|
+
textArea.setSelectionRange({
|
|
129
|
+
start: target.selectionStart - currentLineStr.length,
|
|
130
|
+
end: target.selectionEnd
|
|
131
|
+
});
|
|
132
|
+
return (0, _InsertTextAtPosition.insertTextAtPosition)(target, '');
|
|
133
|
+
}
|
|
125
134
|
var startStr = '\n- ';
|
|
126
135
|
if (currentLineStr.startsWith('*')) {
|
|
127
136
|
startStr = '\n* ';
|
|
@@ -129,7 +138,7 @@ function handleKeyDown(e) {
|
|
|
129
138
|
if (currentLineStr.startsWith('- [ ]') || currentLineStr.startsWith('- [X]') || currentLineStr.startsWith('- [x]')) {
|
|
130
139
|
startStr = '\n- [ ] ';
|
|
131
140
|
}
|
|
132
|
-
if (/^\d
|
|
141
|
+
if (/^\d+\.\s/.test(currentLineStr)) {
|
|
133
142
|
startStr = "\n".concat(parseInt(currentLineStr) + 1, ". ");
|
|
134
143
|
}
|
|
135
144
|
return (0, _InsertTextAtPosition.insertTextAtPosition)(target, startStr);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
@md-editor
|
|
1
|
+
@md-editor: ~'w-md-editor';
|
|
2
2
|
|
|
3
3
|
.@{md-editor} {
|
|
4
4
|
&-area {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
5
7
|
overflow: auto;
|
|
6
8
|
border-radius: 5px;
|
|
7
9
|
}
|
|
8
10
|
&-text {
|
|
11
|
+
flex: 1 0 auto;
|
|
9
12
|
min-height: 100%;
|
|
10
13
|
position: relative;
|
|
11
14
|
text-align: left;
|
package/markdown-editor.css
CHANGED
|
@@ -17,10 +17,13 @@
|
|
|
17
17
|
margin: 0 auto;
|
|
18
18
|
}
|
|
19
19
|
.w-md-editor-area {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
20
22
|
overflow: auto;
|
|
21
23
|
border-radius: 5px;
|
|
22
24
|
}
|
|
23
25
|
.w-md-editor-text {
|
|
26
|
+
flex: 1 0 auto;
|
|
24
27
|
min-height: 100%;
|
|
25
28
|
position: relative;
|
|
26
29
|
text-align: left;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.4",
|
|
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
|
"funding": "https://jaywcjlove.github.io/#/sponsor",
|
|
@@ -102,13 +102,23 @@ export default function handleKeyDown(
|
|
|
102
102
|
} else if (
|
|
103
103
|
e.keyCode === 13 &&
|
|
104
104
|
e.code.toLowerCase() === 'enter' &&
|
|
105
|
-
(/^(-|\*)\s/.test(currentLineStr) || /^\d
|
|
105
|
+
(/^(-|\*)\s/.test(currentLineStr) || /^\d+\.\s/.test(currentLineStr)) &&
|
|
106
106
|
!e.shiftKey
|
|
107
107
|
) {
|
|
108
108
|
/**
|
|
109
109
|
* `13` - `Enter`
|
|
110
110
|
*/
|
|
111
111
|
stopPropagation(e);
|
|
112
|
+
const atEndOfLine = target.selectionEnd === target.value.length || target.value[target.selectionEnd] === '\n';
|
|
113
|
+
const emptyListItem =
|
|
114
|
+
/^(?:[-*]|\d+\.)\s+$/.test(currentLineStr) || /^- \[[ xX]\]\s*$/.test(currentLineStr);
|
|
115
|
+
if (target.selectionStart === target.selectionEnd && atEndOfLine && emptyListItem) {
|
|
116
|
+
textArea.setSelectionRange({
|
|
117
|
+
start: target.selectionStart - currentLineStr.length,
|
|
118
|
+
end: target.selectionEnd,
|
|
119
|
+
});
|
|
120
|
+
return insertTextAtPosition(target, '');
|
|
121
|
+
}
|
|
112
122
|
let startStr = '\n- ';
|
|
113
123
|
|
|
114
124
|
if (currentLineStr.startsWith('*')) {
|
|
@@ -123,7 +133,7 @@ export default function handleKeyDown(
|
|
|
123
133
|
startStr = '\n- [ ] ';
|
|
124
134
|
}
|
|
125
135
|
|
|
126
|
-
if (/^\d
|
|
136
|
+
if (/^\d+\.\s/.test(currentLineStr)) {
|
|
127
137
|
startStr = `\n${parseInt(currentLineStr) + 1}. `;
|
|
128
138
|
}
|
|
129
139
|
return insertTextAtPosition(target, startStr);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
@md-editor
|
|
1
|
+
@md-editor: ~'w-md-editor';
|
|
2
2
|
|
|
3
3
|
.@{md-editor} {
|
|
4
4
|
&-area {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
5
7
|
overflow: auto;
|
|
6
8
|
border-radius: 5px;
|
|
7
9
|
}
|
|
8
10
|
&-text {
|
|
11
|
+
flex: 1 0 auto;
|
|
9
12
|
min-height: 100%;
|
|
10
13
|
position: relative;
|
|
11
14
|
text-align: left;
|