@uiw/react-md-editor 3.18.3 → 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.
Files changed (140) hide show
  1. package/dist/mdeditor.js +1564 -1583
  2. package/dist/mdeditor.min.js +1 -1
  3. package/esm/Context.js.map +1 -1
  4. package/esm/Editor.js +43 -67
  5. package/esm/Editor.js.map +1 -1
  6. package/esm/commands/bold.js +4 -4
  7. package/esm/commands/bold.js.map +1 -1
  8. package/esm/commands/code.js +8 -10
  9. package/esm/commands/code.js.map +2 -2
  10. package/esm/commands/comment.js +27 -16
  11. package/esm/commands/comment.js.map +2 -2
  12. package/esm/commands/divider.js.map +1 -1
  13. package/esm/commands/fullscreen.js +3 -4
  14. package/esm/commands/fullscreen.js.map +2 -2
  15. package/esm/commands/group.js +2 -4
  16. package/esm/commands/group.js.map +1 -1
  17. package/esm/commands/hr.js.map +1 -1
  18. package/esm/commands/image.js +6 -6
  19. package/esm/commands/image.js.map +2 -2
  20. package/esm/commands/index.d.ts +2 -2
  21. package/esm/commands/index.js +12 -23
  22. package/esm/commands/index.js.map +3 -2
  23. package/esm/commands/italic.js +4 -4
  24. package/esm/commands/italic.js.map +1 -1
  25. package/esm/commands/link.js +4 -4
  26. package/esm/commands/link.js.map +1 -1
  27. package/esm/commands/list.js +4 -4
  28. package/esm/commands/list.js.map +1 -1
  29. package/esm/commands/preview.js +21 -3
  30. package/esm/commands/preview.js.map +7 -2
  31. package/esm/commands/quote.js +2 -1
  32. package/esm/commands/quote.js.map +1 -1
  33. package/esm/commands/strikeThrough.js +4 -4
  34. package/esm/commands/strikeThrough.js.map +1 -1
  35. package/esm/commands/title.js.map +1 -1
  36. package/esm/commands/title1.js.map +1 -1
  37. package/esm/commands/title2.js.map +1 -1
  38. package/esm/commands/title3.js.map +1 -1
  39. package/esm/commands/title4.js.map +1 -1
  40. package/esm/commands/title5.js.map +1 -1
  41. package/esm/commands/title6.js.map +1 -1
  42. package/esm/components/DragBar/index.js +2 -9
  43. package/esm/components/DragBar/index.js.map +1 -1
  44. package/esm/components/TextArea/Markdown.js +2 -7
  45. package/esm/components/TextArea/Markdown.js.map +1 -1
  46. package/esm/components/TextArea/Textarea.js +8 -11
  47. package/esm/components/TextArea/Textarea.js.map +1 -1
  48. package/esm/components/TextArea/handleKeyDown.js +2 -16
  49. package/esm/components/TextArea/handleKeyDown.js.map +1 -1
  50. package/esm/components/TextArea/index.js +11 -15
  51. package/esm/components/TextArea/index.js.map +1 -1
  52. package/esm/components/TextArea/shortcuts.js +1 -17
  53. package/esm/components/TextArea/shortcuts.js.map +2 -2
  54. package/esm/components/Toolbar/Child.js +2 -1
  55. package/esm/components/Toolbar/Child.js.map +1 -1
  56. package/esm/components/Toolbar/index.js +2 -12
  57. package/esm/components/Toolbar/index.js.map +1 -1
  58. package/esm/index.js.map +1 -1
  59. package/esm/utils/InsertTextAtPosition.js +28 -34
  60. package/esm/utils/InsertTextAtPosition.js.map +1 -1
  61. package/esm/utils/markdownUtils.js +14 -23
  62. package/esm/utils/markdownUtils.js.map +1 -1
  63. package/lib/Context.js +0 -6
  64. package/lib/Context.js.map +1 -1
  65. package/lib/Editor.js +74 -114
  66. package/lib/Editor.js.map +1 -1
  67. package/lib/commands/bold.js +4 -9
  68. package/lib/commands/bold.js.map +1 -1
  69. package/lib/commands/code.js +8 -15
  70. package/lib/commands/code.js.map +2 -2
  71. package/lib/commands/comment.js +27 -19
  72. package/lib/commands/comment.js.map +2 -2
  73. package/lib/commands/divider.js.map +1 -1
  74. package/lib/commands/fullscreen.js +3 -8
  75. package/lib/commands/fullscreen.js.map +2 -2
  76. package/lib/commands/group.js +2 -10
  77. package/lib/commands/group.js.map +1 -1
  78. package/lib/commands/hr.js +0 -4
  79. package/lib/commands/hr.js.map +1 -1
  80. package/lib/commands/image.js +6 -11
  81. package/lib/commands/image.js.map +2 -2
  82. package/lib/commands/index.d.ts +2 -2
  83. package/lib/commands/index.js +10 -47
  84. package/lib/commands/index.js.map +4 -3
  85. package/lib/commands/italic.js +4 -9
  86. package/lib/commands/italic.js.map +1 -1
  87. package/lib/commands/link.js +4 -9
  88. package/lib/commands/link.js.map +1 -1
  89. package/lib/commands/list.js +4 -10
  90. package/lib/commands/list.js.map +1 -1
  91. package/lib/commands/preview.js +21 -7
  92. package/lib/commands/preview.js.map +7 -2
  93. package/lib/commands/quote.js +2 -6
  94. package/lib/commands/quote.js.map +1 -1
  95. package/lib/commands/strikeThrough.js +4 -9
  96. package/lib/commands/strikeThrough.js.map +1 -1
  97. package/lib/commands/title.js +0 -6
  98. package/lib/commands/title.js.map +1 -1
  99. package/lib/commands/title1.js +0 -5
  100. package/lib/commands/title1.js.map +1 -1
  101. package/lib/commands/title2.js +0 -5
  102. package/lib/commands/title2.js.map +1 -1
  103. package/lib/commands/title3.js +0 -5
  104. package/lib/commands/title3.js.map +1 -1
  105. package/lib/commands/title4.js +0 -5
  106. package/lib/commands/title4.js.map +1 -1
  107. package/lib/commands/title5.js +0 -5
  108. package/lib/commands/title5.js.map +1 -1
  109. package/lib/commands/title6.js +0 -5
  110. package/lib/commands/title6.js.map +1 -1
  111. package/lib/components/DragBar/index.js +4 -15
  112. package/lib/components/DragBar/index.js.map +1 -1
  113. package/lib/components/TextArea/Markdown.js +6 -22
  114. package/lib/components/TextArea/Markdown.js.map +1 -1
  115. package/lib/components/TextArea/Textarea.js +15 -36
  116. package/lib/components/TextArea/Textarea.js.map +1 -1
  117. package/lib/components/TextArea/handleKeyDown.js +1 -18
  118. package/lib/components/TextArea/handleKeyDown.js.map +1 -1
  119. package/lib/components/TextArea/index.js +15 -37
  120. package/lib/components/TextArea/index.js.map +1 -1
  121. package/lib/components/TextArea/shortcuts.js +1 -17
  122. package/lib/components/TextArea/shortcuts.js.map +2 -2
  123. package/lib/components/Toolbar/Child.js +8 -18
  124. package/lib/components/Toolbar/Child.js.map +1 -1
  125. package/lib/components/Toolbar/index.js +14 -36
  126. package/lib/components/Toolbar/index.js.map +1 -1
  127. package/lib/index.js +0 -9
  128. package/lib/index.js.map +1 -1
  129. package/lib/utils/InsertTextAtPosition.js +28 -37
  130. package/lib/utils/InsertTextAtPosition.js.map +1 -1
  131. package/lib/utils/markdownUtils.js +17 -28
  132. package/lib/utils/markdownUtils.js.map +1 -1
  133. package/package.json +1 -1
  134. package/src/commands/code.tsx +2 -2
  135. package/src/commands/comment.tsx +19 -4
  136. package/src/commands/fullscreen.tsx +3 -2
  137. package/src/commands/image.tsx +1 -1
  138. package/src/commands/index.ts +8 -7
  139. package/src/commands/preview.tsx +35 -4
  140. package/src/components/TextArea/shortcuts.ts +2 -2
@@ -5,99 +5,90 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.insertAtLineStart = void 0;
7
7
  exports.insertTextAtPosition = insertTextAtPosition;
8
-
9
8
  /**
10
9
  * The MIT License
11
10
  * Copyright (c) 2018 Dmitriy Kubyshkin
12
11
  * Copied from https://github.com/grassator/insert-text-at-cursor
13
12
  */
13
+
14
14
  var browserSupportsTextareaTextNodes;
15
+
15
16
  /**
16
17
  * @param {HTMLElement} input
17
18
  * @return {boolean}
18
19
  */
19
-
20
20
  function canManipulateViaTextNodes(input) {
21
21
  if (input.nodeName !== 'TEXTAREA') {
22
22
  return false;
23
23
  }
24
-
25
24
  if (typeof browserSupportsTextareaTextNodes === 'undefined') {
26
25
  var textarea = document.createElement('textarea');
27
26
  textarea.value = '1';
28
27
  browserSupportsTextareaTextNodes = !!textarea.firstChild;
29
28
  }
30
-
31
29
  return browserSupportsTextareaTextNodes;
32
30
  }
31
+
33
32
  /**
34
33
  * @param {string} val
35
34
  * @param {number} cursorIdx
36
35
  * @param {HTMLTextAreaElement|HTMLInputElement} input
37
36
  * @return {void}
38
37
  */
39
-
40
-
41
38
  var insertAtLineStart = function insertAtLineStart(val, cursorIdx, input) {
42
39
  var content = input.value;
43
40
  var startIdx = 0;
44
-
45
41
  while (cursorIdx--) {
46
42
  var _char = content[cursorIdx];
47
-
48
43
  if (_char === '\n') {
49
44
  startIdx = cursorIdx + 1;
50
45
  break;
51
46
  }
52
47
  }
53
-
54
48
  input.focus();
55
49
  input.setRangeText(val, startIdx, startIdx);
56
50
  input.dispatchEvent(new Event('input', {
57
51
  bubbles: true
58
52
  }));
59
53
  };
54
+
60
55
  /**
61
56
  * @param {HTMLTextAreaElement|HTMLInputElement} input
62
57
  * @param {string} text
63
58
  * @returns {void}
64
59
  */
65
-
66
-
67
60
  exports.insertAtLineStart = insertAtLineStart;
68
-
69
61
  function insertTextAtPosition(input, text) {
70
62
  // Most of the used APIs only work with the field selected
71
- input.focus(); // IE 8-10
63
+ input.focus();
72
64
 
65
+ // IE 8-10
73
66
  if (document.selection) {
74
67
  var ieRange = document.selection.createRange();
75
- ieRange.text = text; // Move cursor after the inserted text
68
+ ieRange.text = text;
76
69
 
77
- ieRange.collapse(false
78
- /* to the end */
79
- );
70
+ // Move cursor after the inserted text
71
+ ieRange.collapse(false /* to the end */);
80
72
  ieRange.select();
81
73
  return;
82
- } // Webkit + Edge
83
-
74
+ }
84
75
 
76
+ // Webkit + Edge
85
77
  var isSuccess = document.execCommand && document.execCommand('insertText', false, text);
86
-
87
78
  if (!isSuccess) {
88
79
  var start = input.selectionStart;
89
- var end = input.selectionEnd; // Firefox (non-standard method)
90
-
80
+ var end = input.selectionEnd;
81
+ // Firefox (non-standard method)
91
82
  if (typeof input.setRangeText === 'function') {
92
83
  input.setRangeText(text);
93
84
  } else {
94
85
  // To make a change we just need a Range, not a Selection
95
86
  var range = document.createRange();
96
87
  var textNode = document.createTextNode(text);
97
-
98
88
  if (canManipulateViaTextNodes(input)) {
99
- var node = input.firstChild; // If textarea is empty, just insert the text
89
+ var node = input.firstChild;
100
90
 
91
+ // If textarea is empty, just insert the text
101
92
  if (!node) {
102
93
  input.appendChild(textNode);
103
94
  } else {
@@ -105,35 +96,34 @@ function insertTextAtPosition(input, text) {
105
96
  var offset = 0;
106
97
  var startNode = null;
107
98
  var endNode = null;
108
-
109
99
  while (node && (startNode === null || endNode === null)) {
110
- var nodeLength = node.nodeValue.length; // if start of the selection falls into current node
100
+ var nodeLength = node.nodeValue.length;
111
101
 
102
+ // if start of the selection falls into current node
112
103
  if (start >= offset && start <= offset + nodeLength) {
113
104
  range.setStart(startNode = node, start - offset);
114
- } // if end of the selection falls into current node
115
-
105
+ }
116
106
 
107
+ // if end of the selection falls into current node
117
108
  if (end >= offset && end <= offset + nodeLength) {
118
109
  range.setEnd(endNode = node, end - offset);
119
110
  }
120
-
121
111
  offset += nodeLength;
122
112
  node = node.nextSibling;
123
- } // If there is some text selected, remove it as we should replace it
124
-
113
+ }
125
114
 
115
+ // If there is some text selected, remove it as we should replace it
126
116
  if (start !== end) {
127
117
  range.deleteContents();
128
118
  }
129
119
  }
130
- } // If the node is a textarea and the range doesn't span outside the element
120
+ }
121
+
122
+ // If the node is a textarea and the range doesn't span outside the element
131
123
  //
132
124
  // Get the commonAncestorContainer of the selected range and test its type
133
125
  // If the node is of type `#text` it means that we're still working with text nodes within our textarea element
134
126
  // otherwise, if it's of type `#document` for example it means our selection spans outside the textarea.
135
-
136
-
137
127
  if (canManipulateViaTextNodes(input) && range.commonAncestorContainer.nodeName === '#text') {
138
128
  // Finally insert a new node. The browser will automatically split start and end nodes into two if necessary
139
129
  range.insertNode(textNode);
@@ -142,11 +132,12 @@ function insertTextAtPosition(input, text) {
142
132
  var value = input.value;
143
133
  input.value = value.slice(0, start) + text + value.slice(end);
144
134
  }
145
- } // Correct the cursor position to be at the end of the insertion
146
-
135
+ }
147
136
 
148
- input.setSelectionRange(start + text.length, start + text.length); // Notify any possible listeners of the change
137
+ // Correct the cursor position to be at the end of the insertion
138
+ input.setSelectionRange(start + text.length, start + text.length);
149
139
 
140
+ // Notify any possible listeners of the change
150
141
  var e = document.createEvent('UIEvent');
151
142
  e.initEvent('input', true, false);
152
143
  input.dispatchEvent(e);
@@ -63,5 +63,5 @@
63
63
  "sourcesContent": [
64
64
  "/**\n * The MIT License\n * Copyright (c) 2018 Dmitriy Kubyshkin\n * Copied from https://github.com/grassator/insert-text-at-cursor\n */\n\nlet browserSupportsTextareaTextNodes: any;\n\n/**\n * @param {HTMLElement} input\n * @return {boolean}\n */\nfunction canManipulateViaTextNodes(input: HTMLTextAreaElement | HTMLInputElement): boolean {\n if (input.nodeName !== 'TEXTAREA') {\n return false;\n }\n if (typeof browserSupportsTextareaTextNodes === 'undefined') {\n const textarea: HTMLTextAreaElement = document.createElement('textarea');\n textarea.value = '1';\n browserSupportsTextareaTextNodes = !!textarea.firstChild;\n }\n return browserSupportsTextareaTextNodes;\n}\n\n/**\n * @param {string} val\n * @param {number} cursorIdx\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @return {void}\n */\nexport const insertAtLineStart = (\n val: string,\n cursorIdx: number,\n input: HTMLTextAreaElement | HTMLInputElement,\n): void => {\n const content = input.value;\n let startIdx = 0;\n\n while (cursorIdx--) {\n let char = content[cursorIdx];\n if (char === '\\n') {\n startIdx = cursorIdx + 1;\n break;\n }\n }\n\n input.focus();\n input.setRangeText(val, startIdx, startIdx);\n input.dispatchEvent(new Event('input', { bubbles: true }));\n};\n\n/**\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @param {string} text\n * @returns {void}\n */\nexport function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string): void {\n // Most of the used APIs only work with the field selected\n input.focus();\n\n // IE 8-10\n if ((document as any).selection) {\n const ieRange = (document as any).selection.createRange();\n ieRange.text = text;\n\n // Move cursor after the inserted text\n ieRange.collapse(false /* to the end */);\n ieRange.select();\n\n return;\n }\n\n // Webkit + Edge\n const isSuccess = document.execCommand && document.execCommand('insertText', false, text);\n if (!isSuccess) {\n const start = input.selectionStart!;\n const end = input.selectionEnd!;\n // Firefox (non-standard method)\n if (typeof input.setRangeText === 'function') {\n input.setRangeText(text);\n } else {\n // To make a change we just need a Range, not a Selection\n const range = document.createRange();\n const textNode = document.createTextNode(text);\n\n if (canManipulateViaTextNodes(input)) {\n let node = input.firstChild;\n\n // If textarea is empty, just insert the text\n if (!node) {\n input.appendChild(textNode);\n } else {\n // Otherwise we need to find a nodes for start and end\n let offset = 0;\n let startNode = null;\n let endNode = null;\n\n while (node && (startNode === null || endNode === null)) {\n const nodeLength = node.nodeValue!.length;\n\n // if start of the selection falls into current node\n if (start >= offset && start <= offset + nodeLength) {\n range.setStart((startNode = node), start - offset);\n }\n\n // if end of the selection falls into current node\n if (end >= offset && end <= offset + nodeLength) {\n range.setEnd((endNode = node), end - offset);\n }\n\n offset += nodeLength;\n node = node.nextSibling;\n }\n\n // If there is some text selected, remove it as we should replace it\n if (start !== end) {\n range.deleteContents();\n }\n }\n }\n\n // If the node is a textarea and the range doesn't span outside the element\n //\n // Get the commonAncestorContainer of the selected range and test its type\n // If the node is of type `#text` it means that we're still working with text nodes within our textarea element\n // otherwise, if it's of type `#document` for example it means our selection spans outside the textarea.\n if (canManipulateViaTextNodes(input) && range.commonAncestorContainer.nodeName === '#text') {\n // Finally insert a new node. The browser will automatically split start and end nodes into two if necessary\n range.insertNode(textNode);\n } else {\n // If the node is not a textarea or the range spans outside a textarea the only way is to replace the whole value\n const value = input.value;\n input.value = value.slice(0, start) + text + value.slice(end);\n }\n }\n\n // Correct the cursor position to be at the end of the insertion\n input.setSelectionRange(start + text.length, start + text.length);\n\n // Notify any possible listeners of the change\n const e = document.createEvent('UIEvent');\n e.initEvent('input', true, false);\n input.dispatchEvent(e);\n }\n}\n"
65
65
  ],
66
- "mappings": ";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,IAAIA,gCAAJ;AAEA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAmCC,KAAnC,EAA2F;EACzF,IAAIA,KAAK,CAACC,QAAN,KAAmB,UAAvB,EAAmC;IACjC,OAAO,KAAP;EACD;;EACD,IAAI,OAAOH,gCAAP,KAA4C,WAAhD,EAA6D;IAC3D,IAAMI,QAA6B,GAAGC,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAtC;IACA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AK,KAAKE,GAAG,EAAE;YACjBE,KAAK,CAACc,cAAc,EAAE;UACxB;QACF;MACF;;MAEA;MACA;MACA;MACA;MACA;MACA,IAAI9C,yBAAyB,CAACC,KAAK,CAAC,IAAI+B,KAAK,CAACe,uBAAuB,CAAC7C,QAAQ,KAAK,OAAO,EAAE;QAC1F;QACA8B,KAAK,CAACgB,UAAU,CAACf,QAAQ,CAAC;MAC5B,CAAC,MAAM;QACL;QACA,IAAM3B,KAAK,GAAGL,KAAK,CAACK,KAAK;QACzBL,KAAK,CAACK,KAAK,GAAGA,KAAK,CAAC2C,KAAK,CAAC,CAAC,EAAErB,KAAK,CAAC,GAAGR,IAAI,GAAGd,KAAK,CAAC2C,KAAK,CAACnB,GAAG,CAAC;MAC/D;IACF;;IAEA;IACA7B,KAAK,CAACiD,iBAAiB,CAACtB,KAAK,GAAGR,IAAI,CAACsB,MAAM,EAAEd,KAAK,GAAGR,IAAI,CAACsB,MAAM,CAAC;;IAEjE;IACA,IAAMS,CAAC,GAAG/C,QAAQ,CAACgD,WAAW,CAAC,SAAS,CAAC;IACzCD,CAAC,CAACE,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC;IACjCpD,KAAK,CAACe,aAAa,CAACmC,CAAC,CAAC;EACxB;AACF"
67
67
  }
@@ -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
- selection = _ref.selection;
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; // rules:
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; // rules:
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
- }; // leftIndex is initialized to 0 because if selection is 0, it won't even enter the iteration
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
- var end = text.length; // iterate to the left
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
- } // iterate to the right
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": ";;;;;;;;;;AA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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "3.18.3",
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>",
@@ -13,7 +13,7 @@ export const code: ICommand = {
13
13
  value: '``',
14
14
  buttonProps: { 'aria-label': 'Insert code (ctrl + j)', title: 'Insert code (ctrl + j)' },
15
15
  icon: (
16
- <svg width="12" height="12" role="img" viewBox="0 0 640 512">
16
+ <svg width="14" height="14" role="img" viewBox="0 0 640 512">
17
17
  <path
18
18
  fill="currentColor"
19
19
  d="M278.9 511.5l-61-17.7c-6.4-1.8-10-8.5-8.2-14.9L346.2 8.7c1.8-6.4 8.5-10 14.9-8.2l61 17.7c6.4 1.8 10 8.5 8.2 14.9L293.8 503.3c-1.9 6.4-8.5 10.1-14.9 8.2zm-114-112.2l43.5-46.4c4.6-4.9 4.3-12.7-.8-17.2L117 256l90.6-79.7c5.1-4.5 5.5-12.3.8-17.2l-43.5-46.4c-4.5-4.8-12.1-5.1-17-.5L3.8 247.2c-5.1 4.7-5.1 12.8 0 17.5l144.1 135.1c4.9 4.6 12.5 4.4 17-.5zm327.2.6l144.1-135.1c5.1-4.7 5.1-12.8 0-17.5L492.1 112.1c-4.8-4.5-12.4-4.3-17 .5L431.6 159c-4.6 4.9-4.3 12.7.8 17.2L523 256l-90.6 79.7c-5.1 4.5-5.5 12.3-.8 17.2l43.5 46.4c4.5 4.9 12.1 5.1 17 .6z"
@@ -63,7 +63,7 @@ export const codeBlock: ICommand = {
63
63
  shortcuts: 'ctrlcmd+shift+j',
64
64
  value: '```\n```',
65
65
  icon: (
66
- <svg width="12" height="12" role="img" viewBox="0 0 156 156">
66
+ <svg width="13" height="13" role="img" viewBox="0 0 156 156">
67
67
  <path
68
68
  fill="currentColor"
69
69
  d="M110.85 120.575 43.7 120.483333 43.7083334 110.091667 110.85 110.191667 110.841667 120.583333 110.85 120.575ZM85.1333334 87.1916666 43.625 86.7083332 43.7083334 76.3166666 85.2083334 76.7916666 85.1333334 87.1916666 85.1333334 87.1916666ZM110.841667 53.4166666 43.7 53.3166666 43.7083334 42.925 110.85 43.025 110.841667 53.4166666ZM36 138C27.2916666 138 20.75 136.216667 16.4 132.666667 12.1333334 129.2 10 124.308333 10 118L10 95.3333332C10 91.0666666 9.25 88.1333332 7.7333334 86.5333332 6.3166668 84.8416666 3.7333334 84 0 84L0 72C3.7333334 72 6.3083334 71.2 7.7333334 69.6 9.2416668 67.9083334 10 64.9333334 10 60.6666666L10 38C10 31.775 12.1333334 26.8833334 16.4 23.3333332 20.7583334 19.7749998 27.2916666 18 36 18L40.6666668 18 40.6666668 30 36 30C34.0212222 29.9719277 32.1263151 30.7979128 30.8 32.2666666 29.3605875 33.8216362 28.5938182 35.8823287 28.6666668 38L28.6666668 60.6666666C28.6666668 67.5083332 26.6666668 72.4 22.6666668 75.3333332 20.9317416 76.7274684 18.8640675 77.6464347 16.6666668 78 18.8916668 78.35 20.8916668 79.2416666 22.6666668 80.6666666 26.6666668 83.95 28.6666668 88.8416666 28.6666668 95.3333332L28.6666668 118C28.6666668 120.308333 29.3750002 122.216667 30.8 123.733333 32.2166666 125.241667 33.9583334 126 36 126L40.6666668 126 40.6666668 138 36 138 36 138ZM114.116667 126 118.783333 126C120.833333 126 122.566667 125.241667 123.983333 123.733333 125.422746 122.178364 126.189515 120.117671 126.116667 118L126.116667 95.3333332C126.116667 88.8333332 128.116667 83.9499998 132.116667 80.6666666 133.9 79.2416666 135.9 78.35 138.116667 78 135.919156 77.6468047 133.851391 76.7277979 132.116667 75.3333332 128.116667 72.3999998 126.116667 67.5 126.116667 60.6666666L126.116667 38C126.189515 35.8823287 125.422746 33.8216361 123.983333 32.2666666 122.657018 30.7979128 120.762111 29.9719277 118.783333 30L114.116667 30 114.116667 18 118.783333 18C127.5 18 133.983333 19.775 138.25 23.3333332 142.608333 26.8833332 144.783333 31.7749998 144.783333 38L144.783333 60.6666666C144.783333 64.9333332 145.5 67.9083332 146.916667 69.6 148.433333 71.2 151.05 72 154.783333 72L154.783333 84C151.05 84 148.433333 84.8333334 146.916667 86.5333332 145.5 88.1333332 144.783333 91.0666666 144.783333 95.3333332L144.783333 118C144.783333 124.308333 142.616667 129.2 138.25 132.666667 133.983333 136.216667 127.5 138 118.783333 138L114.116667 138 114.116667 126 114.116667 126Z"
@@ -20,9 +20,24 @@ export const comment: ICommand = {
20
20
  });
21
21
  },
22
22
  icon: (
23
- <svg role="img" viewBox="0 0 512 512" width="12" height="12">
24
- <path fill="currentColor" d="M281 72H231oLuLFozwYpLrBi5VTa8sg7fDqKkeyD81V172H281V72Z" />
25
- <path fill="currentColor" d="M287.817 501H213.333L298.667 334H438.857C438.857 334 438.857 333.021 438.857 308.308V187.875V74.6028C438.857 64.3818 438.857 67.2814 438.857 62.625C438.857 61.7594 439.31 62.625 426.667 62.625H256H73.1429C73.1429 65.4903 73.1429 77.3378 73.1429 79.8845V187.875V308.308C73.1429 311.005 73.1429 334 73.1429 334C73.1429 334 113.826 334 106.667 334H149.333H237.714V385.385H73.1429C53.7442 385.385 35.14 377.264 21.423 362.809C7.7061 348.355 0 328.75 0 308.308V77.0769C0 56.6349 7.7061 37.03 21.423 22.5753C35.14 8.12058 53.7442 0 73.1429 0H438.857C458.256 0 476.86 8.12058 490.577 22.5753C504.294 37.03 512 56.6349 512 77.0769V308.308C512 328.75 504.294 348.355 490.577 362.809C476.86 377.264 458.256 385.385 438.857 385.385H350.354L287.817 501Z" />
23
+ <svg height="1em" width="1em" viewBox="0 0 25 25">
24
+ <g fill="none" fillRule="evenodd">
25
+ <polygon points=".769 .727 24.981 .727 24.981 24.727 .769 24.727" />
26
+ <path
27
+ stroke="currentColor"
28
+ strokeLinecap="round"
29
+ strokeLinejoin="round"
30
+ strokeWidth="3"
31
+ d="M12.625,23.8787879 L8.125,19.6969697 L5.125,19.6969697 C2.63971863,19.6969697 0.625,17.8247059 0.625,15.5151515 L0.625,7.15151515 C0.625,4.84196074 2.63971863,2.96969697 5.125,2.96969697 L20.125,2.96969697 C22.6102814,2.96969697 24.625,4.84196074 24.625,7.15151515 L24.625,15.5151515 C24.625,17.8247059 22.6102814,19.6969697 20.125,19.6969697 L17.125,19.6969697 L12.625,23.8787879"
32
+ />
33
+ <path
34
+ stroke="currentColor"
35
+ strokeLinecap="round"
36
+ strokeLinejoin="round"
37
+ strokeWidth="3"
38
+ d="M10.625,8.54545455 L7.25,11.3333333 L10.625,14.1212121 M15.6875,8.54545455 L19.0625,11.3333333 L15.6875,14.1212121"
39
+ />
40
+ </g>
26
41
  </svg>
27
- )
42
+ ),
28
43
  };
@@ -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 (dispatch && executeCommandState && executeCommandState.fullscreen) {
27
- dispatch({ fullscreen: false });
27
+ if (shortcuts && dispatch && executeCommandState) {
28
+ dispatch({ fullscreen: !executeCommandState.fullscreen });
28
29
  }
29
30
  },
30
31
  };
@@ -9,7 +9,7 @@ export const image: ICommand = {
9
9
  value: '![image]()',
10
10
  buttonProps: { 'aria-label': 'Add image (ctrl + k)', title: 'Add image (ctrl + k)' },
11
11
  icon: (
12
- <svg width="12" height="12" viewBox="0 0 20 20">
12
+ <svg width="13" height="13" viewBox="0 0 20 20">
13
13
  <path
14
14
  fill="currentColor"
15
15
  d="M15 9c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm4-7H1c-.55 0-1 .45-1 1v14c0 .55.45 1 1 1h18c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 13l-6-5-2 2-4-5-4 8V4h16v11z"
@@ -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
 
@@ -79,21 +80,21 @@ export interface TextState {
79
80
  }
80
81
 
81
82
  const getCommands: () => ICommand[] = () => [
82
- comment,
83
83
  bold,
84
84
  italic,
85
85
  strikethrough,
86
86
  hr,
87
87
  group([title1, title2, title3, title4, title5, title6], {
88
- name: "title",
89
- groupName: "title",
90
- buttonProps: { "aria-label": "Insert title", title: "Insert title" },
91
- }),
88
+ name: 'title',
89
+ groupName: 'title',
90
+ buttonProps: { 'aria-label': 'Insert title', title: 'Insert title' },
91
+ }),
92
92
  divider,
93
93
  link,
94
94
  quote,
95
95
  code,
96
96
  codeBlock,
97
+ comment,
97
98
  image,
98
99
  divider,
99
100
  unorderedListCommand,
@@ -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
 
@@ -199,4 +201,3 @@ export {
199
201
  TextAreaCommandOrchestrator,
200
202
  TextAreaTextApi,
201
203
  };
202
-
@@ -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: (string | number)[] = [];
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
  }