@uiw/react-md-editor 4.1.1 → 4.1.3

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.
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  /**!
12
- * @uiw/copy-to-clipboard v1.0.20
12
+ * @uiw/copy-to-clipboard v1.0.21
13
13
  * Copy to clipboard.
14
14
  *
15
15
  * Copyright (c) 2026 Kenny Wang
@@ -113,7 +113,7 @@ 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+.\s/.test(currentLineStr)) && !e.shiftKey) {
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
  */
@@ -125,7 +125,7 @@ export default function handleKeyDown(e, tabSize, defaultTabEnable) {
125
125
  if (currentLineStr.startsWith('- [ ]') || currentLineStr.startsWith('- [X]') || currentLineStr.startsWith('- [x]')) {
126
126
  startStr = '\n- [ ] ';
127
127
  }
128
- if (/^\d+.\s/.test(currentLineStr)) {
128
+ if (/^\d+\.\s/.test(currentLineStr)) {
129
129
  startStr = "\n" + (parseInt(currentLineStr) + 1) + ". ";
130
130
  }
131
131
  return insertTextAtPosition(target, startStr);
@@ -1,8 +1,11 @@
1
1
  .w-md-editor-area {
2
+ display: flex;
3
+ flex-direction: column;
2
4
  overflow: auto;
3
5
  border-radius: 5px;
4
6
  }
5
7
  .w-md-editor-text {
8
+ flex: 1 0 auto;
6
9
  min-height: 100%;
7
10
  position: relative;
8
11
  text-align: left;
@@ -1,11 +1,14 @@
1
- @md-editor:~ "w-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/esm/index.css CHANGED
@@ -27,7 +27,6 @@
27
27
  text-align: right !important;
28
28
  }
29
29
  .w-md-editor-toolbar {
30
- height: -webkit-fit-content;
31
30
  height: fit-content;
32
31
  }
33
32
  .w-md-editor-content {
@@ -1,3 +1,25 @@
1
+ // `*` is a prefix of `**`, so `**text**` is bold-only and `***text***` is bold+italic.
2
+ function isItalicInsideBoldOnly(text, start, end) {
3
+ var insideBold = start >= 2 && end + 2 <= text.length && text.slice(start - 2, start) === '**' && text.slice(end, end + 2) === '**';
4
+ if (!insideBold) {
5
+ return false;
6
+ }
7
+ var insideBoldItalic = start >= 3 && end + 3 <= text.length && text.slice(start - 3, start) === '***' && text.slice(end, end + 3) === '***';
8
+ return !insideBoldItalic;
9
+ }
10
+ function isAlreadyWrapped(selectedText, prefix, suffix) {
11
+ if (selectedText.length < prefix.length + suffix.length || !selectedText.startsWith(prefix) || !selectedText.endsWith(suffix)) {
12
+ return false;
13
+ }
14
+ if (prefix === '*' && suffix === '*') {
15
+ var isBold = selectedText.startsWith('**') && selectedText.endsWith('**');
16
+ var isBoldItalic = selectedText.startsWith('***') && selectedText.endsWith('***');
17
+ if (isBold && !isBoldItalic) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ }
1
23
  export function selectWord(_ref) {
2
24
  var text = _ref.text,
3
25
  selection = _ref.selection,
@@ -11,6 +33,9 @@ export function selectWord(_ref) {
11
33
  if (result.start >= prefix.length && result.end <= text.length - suffix.length) {
12
34
  var selectedTextContext = text.slice(result.start - prefix.length, result.end + suffix.length);
13
35
  if (selectedTextContext.startsWith(prefix) && selectedTextContext.endsWith(suffix)) {
36
+ if (prefix === '*' && suffix === '*' && isItalicInsideBoldOnly(text, result.start, result.end)) {
37
+ return result;
38
+ }
14
39
  return {
15
40
  start: result.start - prefix.length,
16
41
  end: result.end + suffix.length
@@ -136,7 +161,7 @@ export function executeCommand(_ref3) {
136
161
  prefix = _ref3.prefix,
137
162
  _ref3$suffix = _ref3.suffix,
138
163
  suffix = _ref3$suffix === void 0 ? prefix : _ref3$suffix;
139
- if (selectedText.length >= prefix.length + suffix.length && selectedText.startsWith(prefix) && selectedText.endsWith(suffix)) {
164
+ if (isAlreadyWrapped(selectedText, prefix, suffix)) {
140
165
  api.replaceSelection(selectedText.slice(prefix.length, suffix.length ? -suffix.length : undefined));
141
166
  api.setSelectionRange({
142
167
  start: selection.start - prefix.length,
@@ -117,7 +117,7 @@ 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+.\s/.test(currentLineStr)) && !e.shiftKey) {
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
  */
@@ -129,7 +129,7 @@ function handleKeyDown(e) {
129
129
  if (currentLineStr.startsWith('- [ ]') || currentLineStr.startsWith('- [X]') || currentLineStr.startsWith('- [x]')) {
130
130
  startStr = '\n- [ ] ';
131
131
  }
132
- if (/^\d+.\s/.test(currentLineStr)) {
132
+ if (/^\d+\.\s/.test(currentLineStr)) {
133
133
  startStr = "\n".concat(parseInt(currentLineStr) + 1, ". ");
134
134
  }
135
135
  return (0, _InsertTextAtPosition.insertTextAtPosition)(target, startStr);
@@ -1,11 +1,14 @@
1
- @md-editor:~ "w-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;
@@ -10,6 +10,28 @@ exports.getSurroundingWord = getSurroundingWord;
10
10
  exports.insertBeforeEachLine = insertBeforeEachLine;
11
11
  exports.selectLine = selectLine;
12
12
  exports.selectWord = selectWord;
13
+ // `*` is a prefix of `**`, so `**text**` is bold-only and `***text***` is bold+italic.
14
+ function isItalicInsideBoldOnly(text, start, end) {
15
+ var insideBold = start >= 2 && end + 2 <= text.length && text.slice(start - 2, start) === '**' && text.slice(end, end + 2) === '**';
16
+ if (!insideBold) {
17
+ return false;
18
+ }
19
+ var insideBoldItalic = start >= 3 && end + 3 <= text.length && text.slice(start - 3, start) === '***' && text.slice(end, end + 3) === '***';
20
+ return !insideBoldItalic;
21
+ }
22
+ function isAlreadyWrapped(selectedText, prefix, suffix) {
23
+ if (selectedText.length < prefix.length + suffix.length || !selectedText.startsWith(prefix) || !selectedText.endsWith(suffix)) {
24
+ return false;
25
+ }
26
+ if (prefix === '*' && suffix === '*') {
27
+ var isBold = selectedText.startsWith('**') && selectedText.endsWith('**');
28
+ var isBoldItalic = selectedText.startsWith('***') && selectedText.endsWith('***');
29
+ if (isBold && !isBoldItalic) {
30
+ return false;
31
+ }
32
+ }
33
+ return true;
34
+ }
13
35
  function selectWord(_ref) {
14
36
  var text = _ref.text,
15
37
  selection = _ref.selection,
@@ -23,6 +45,9 @@ function selectWord(_ref) {
23
45
  if (result.start >= prefix.length && result.end <= text.length - suffix.length) {
24
46
  var selectedTextContext = text.slice(result.start - prefix.length, result.end + suffix.length);
25
47
  if (selectedTextContext.startsWith(prefix) && selectedTextContext.endsWith(suffix)) {
48
+ if (prefix === '*' && suffix === '*' && isItalicInsideBoldOnly(text, result.start, result.end)) {
49
+ return result;
50
+ }
26
51
  return {
27
52
  start: result.start - prefix.length,
28
53
  end: result.end + suffix.length
@@ -148,7 +173,7 @@ function executeCommand(_ref3) {
148
173
  prefix = _ref3.prefix,
149
174
  _ref3$suffix = _ref3.suffix,
150
175
  suffix = _ref3$suffix === void 0 ? prefix : _ref3$suffix;
151
- if (selectedText.length >= prefix.length + suffix.length && selectedText.startsWith(prefix) && selectedText.endsWith(suffix)) {
176
+ if (isAlreadyWrapped(selectedText, prefix, suffix)) {
152
177
  api.replaceSelection(selectedText.slice(prefix.length, suffix.length ? -suffix.length : undefined));
153
178
  api.setSelectionRange({
154
179
  start: selection.start - prefix.length,
@@ -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;
@@ -271,7 +274,6 @@
271
274
  text-align: right !important;
272
275
  }
273
276
  .w-md-editor-toolbar {
274
- height: -webkit-fit-content;
275
277
  height: fit-content;
276
278
  }
277
279
  .w-md-editor-content {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
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,7 +102,7 @@ export default function handleKeyDown(
102
102
  } else if (
103
103
  e.keyCode === 13 &&
104
104
  e.code.toLowerCase() === 'enter' &&
105
- (/^(-|\*)\s/.test(currentLineStr) || /^\d+.\s/.test(currentLineStr)) &&
105
+ (/^(-|\*)\s/.test(currentLineStr) || /^\d+\.\s/.test(currentLineStr)) &&
106
106
  !e.shiftKey
107
107
  ) {
108
108
  /**
@@ -123,7 +123,7 @@ export default function handleKeyDown(
123
123
  startStr = '\n- [ ] ';
124
124
  }
125
125
 
126
- if (/^\d+.\s/.test(currentLineStr)) {
126
+ if (/^\d+\.\s/.test(currentLineStr)) {
127
127
  startStr = `\n${parseInt(currentLineStr) + 1}. `;
128
128
  }
129
129
  return insertTextAtPosition(target, startStr);
@@ -1,11 +1,14 @@
1
- @md-editor:~ "w-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;
@@ -5,6 +5,39 @@ export interface TextSection {
5
5
  selection: TextRange;
6
6
  }
7
7
 
8
+ // `*` is a prefix of `**`, so `**text**` is bold-only and `***text***` is bold+italic.
9
+ function isItalicInsideBoldOnly(text: string, start: number, end: number): boolean {
10
+ const insideBold =
11
+ start >= 2 && end + 2 <= text.length && text.slice(start - 2, start) === '**' && text.slice(end, end + 2) === '**';
12
+ if (!insideBold) {
13
+ return false;
14
+ }
15
+ const insideBoldItalic =
16
+ start >= 3 &&
17
+ end + 3 <= text.length &&
18
+ text.slice(start - 3, start) === '***' &&
19
+ text.slice(end, end + 3) === '***';
20
+ return !insideBoldItalic;
21
+ }
22
+
23
+ function isAlreadyWrapped(selectedText: string, prefix: string, suffix: string): boolean {
24
+ if (
25
+ selectedText.length < prefix.length + suffix.length ||
26
+ !selectedText.startsWith(prefix) ||
27
+ !selectedText.endsWith(suffix)
28
+ ) {
29
+ return false;
30
+ }
31
+ if (prefix === '*' && suffix === '*') {
32
+ const isBold = selectedText.startsWith('**') && selectedText.endsWith('**');
33
+ const isBoldItalic = selectedText.startsWith('***') && selectedText.endsWith('***');
34
+ if (isBold && !isBoldItalic) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ }
40
+
8
41
  export function selectWord({
9
42
  text,
10
43
  selection,
@@ -23,6 +56,9 @@ export function selectWord({
23
56
  if (result.start >= prefix.length && result.end <= text.length - suffix.length) {
24
57
  const selectedTextContext = text.slice(result.start - prefix.length, result.end + suffix.length);
25
58
  if (selectedTextContext.startsWith(prefix) && selectedTextContext.endsWith(suffix)) {
59
+ if (prefix === '*' && suffix === '*' && isItalicInsideBoldOnly(text, result.start, result.end)) {
60
+ return result;
61
+ }
26
62
  return { start: result.start - prefix.length, end: result.end + suffix.length };
27
63
  }
28
64
  }
@@ -139,11 +175,7 @@ export function executeCommand({
139
175
  prefix: string;
140
176
  suffix?: string;
141
177
  }) {
142
- if (
143
- selectedText.length >= prefix.length + suffix.length &&
144
- selectedText.startsWith(prefix) &&
145
- selectedText.endsWith(suffix)
146
- ) {
178
+ if (isAlreadyWrapped(selectedText, prefix, suffix)) {
147
179
  api.replaceSelection(selectedText.slice(prefix.length, suffix.length ? -suffix.length : undefined));
148
180
  api.setSelectionRange({ start: selection.start - prefix.length, end: selection.end - prefix.length });
149
181
  } else {