@uiw/react-md-editor 3.23.6 → 3.24.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 (105) hide show
  1. package/README.md +29 -4
  2. package/dist/mdeditor.css +2 -0
  3. package/dist/mdeditor.js +234 -237
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/dist/mdeditor.min.js.LICENSE.txt +1 -1
  7. package/esm/commands/bold.js +9 -13
  8. package/esm/commands/code.d.ts +1 -1
  9. package/esm/commands/code.js +75 -68
  10. package/esm/commands/comment.js +20 -18
  11. package/esm/commands/help.d.ts +2 -0
  12. package/esm/commands/help.js +22 -0
  13. package/esm/commands/hr.js +33 -2
  14. package/esm/commands/image.js +39 -16
  15. package/esm/commands/index.d.ts +7 -2
  16. package/esm/commands/index.js +5 -2
  17. package/esm/commands/issue.d.ts +2 -0
  18. package/esm/commands/issue.js +41 -0
  19. package/esm/commands/italic.js +9 -13
  20. package/esm/commands/link.js +40 -14
  21. package/esm/commands/list.d.ts +3 -10
  22. package/esm/commands/list.js +39 -41
  23. package/esm/commands/quote.js +8 -8
  24. package/esm/commands/strikeThrough.js +9 -13
  25. package/esm/commands/table.d.ts +2 -0
  26. package/esm/commands/table.js +57 -0
  27. package/esm/commands/title.d.ts +7 -1
  28. package/esm/commands/title.js +21 -0
  29. package/esm/commands/title1.js +9 -7
  30. package/esm/commands/title2.js +9 -7
  31. package/esm/commands/title3.js +9 -7
  32. package/esm/commands/title4.js +9 -7
  33. package/esm/commands/title5.js +9 -7
  34. package/esm/commands/title6.js +9 -7
  35. package/esm/components/TextArea/handleKeyDown.js +83 -5
  36. package/esm/utils/InsertTextAtPosition.d.ts +0 -7
  37. package/esm/utils/InsertTextAtPosition.js +6 -24
  38. package/esm/utils/markdownUtils.d.ts +23 -1
  39. package/esm/utils/markdownUtils.js +83 -4
  40. package/lib/Context.js +2 -3
  41. package/lib/Editor.js +1 -2
  42. package/lib/commands/bold.js +10 -15
  43. package/lib/commands/code.d.ts +1 -1
  44. package/lib/commands/code.js +75 -70
  45. package/lib/commands/comment.js +21 -20
  46. package/lib/commands/divider.js +2 -3
  47. package/lib/commands/fullscreen.js +2 -3
  48. package/lib/commands/group.js +2 -3
  49. package/lib/commands/help.d.ts +2 -0
  50. package/lib/commands/help.js +29 -0
  51. package/lib/commands/hr.js +35 -5
  52. package/lib/commands/image.js +40 -18
  53. package/lib/commands/index.d.ts +7 -2
  54. package/lib/commands/index.js +27 -10
  55. package/lib/commands/issue.d.ts +2 -0
  56. package/lib/commands/issue.js +48 -0
  57. package/lib/commands/italic.js +10 -15
  58. package/lib/commands/link.js +41 -16
  59. package/lib/commands/list.d.ts +3 -10
  60. package/lib/commands/list.js +43 -52
  61. package/lib/commands/preview.js +4 -7
  62. package/lib/commands/quote.js +9 -10
  63. package/lib/commands/strikeThrough.js +10 -15
  64. package/lib/commands/table.d.ts +2 -0
  65. package/lib/commands/table.js +64 -0
  66. package/lib/commands/title.d.ts +7 -1
  67. package/lib/commands/title.js +23 -3
  68. package/lib/commands/title1.js +11 -10
  69. package/lib/commands/title2.js +11 -10
  70. package/lib/commands/title3.js +11 -10
  71. package/lib/commands/title4.js +11 -10
  72. package/lib/commands/title5.js +11 -10
  73. package/lib/commands/title6.js +11 -10
  74. package/lib/components/DragBar/index.js +1 -2
  75. package/lib/components/TextArea/handleKeyDown.js +84 -6
  76. package/lib/index.js +1 -2
  77. package/lib/utils/InsertTextAtPosition.d.ts +0 -7
  78. package/lib/utils/InsertTextAtPosition.js +6 -26
  79. package/lib/utils/markdownUtils.d.ts +23 -1
  80. package/lib/utils/markdownUtils.js +84 -4
  81. package/package.json +4 -1
  82. package/src/commands/bold.tsx +13 -12
  83. package/src/commands/code.tsx +72 -71
  84. package/src/commands/comment.tsx +20 -15
  85. package/src/commands/help.tsx +19 -0
  86. package/src/commands/hr.tsx +33 -2
  87. package/src/commands/image.tsx +38 -15
  88. package/src/commands/index.ts +12 -1
  89. package/src/commands/issue.tsx +36 -0
  90. package/src/commands/italic.tsx +13 -12
  91. package/src/commands/link.tsx +39 -12
  92. package/src/commands/list.tsx +35 -53
  93. package/src/commands/quote.tsx +14 -13
  94. package/src/commands/strikeThrough.tsx +13 -12
  95. package/src/commands/table.tsx +52 -0
  96. package/src/commands/title.tsx +18 -1
  97. package/src/commands/title1.tsx +6 -9
  98. package/src/commands/title2.tsx +6 -9
  99. package/src/commands/title3.tsx +6 -9
  100. package/src/commands/title4.tsx +6 -9
  101. package/src/commands/title5.tsx +6 -9
  102. package/src/commands/title6.tsx +6 -9
  103. package/src/components/TextArea/handleKeyDown.tsx +54 -5
  104. package/src/utils/InsertTextAtPosition.ts +7 -28
  105. package/src/utils/markdownUtils.ts +94 -4
@@ -1,6 +1,6 @@
1
1
  import { insertTextAtPosition } from '../../utils/InsertTextAtPosition';
2
+ import { insertBeforeEachLine, selectLine } from '../../utils/markdownUtils';
2
3
  import { TextAreaTextApi } from '../../commands';
3
- import { insertBeforeEachLine } from '../../commands/list';
4
4
 
5
5
  /**
6
6
  * - `13` - `Enter`
@@ -10,6 +10,60 @@ function stopPropagation(e) {
10
10
  e.stopPropagation();
11
11
  e.preventDefault();
12
12
  }
13
+ function handleLineMove(e, direction) {
14
+ stopPropagation(e);
15
+ var target = e.target;
16
+ var textArea = new TextAreaTextApi(target);
17
+ var selection = {
18
+ start: target.selectionStart,
19
+ end: target.selectionEnd
20
+ };
21
+ selection = selectLine({
22
+ text: target.value,
23
+ selection
24
+ });
25
+ if (direction < 0 && selection.start <= 0 || direction > 0 && selection.end >= target.value.length) {
26
+ return;
27
+ }
28
+ var blockText = target.value.slice(selection.start, selection.end);
29
+ if (direction < 0) {
30
+ var prevLineSelection = selectLine({
31
+ text: target.value,
32
+ selection: {
33
+ start: selection.start - 1,
34
+ end: selection.start - 1
35
+ }
36
+ });
37
+ var prevLineText = target.value.slice(prevLineSelection.start, prevLineSelection.end);
38
+ textArea.setSelectionRange({
39
+ start: prevLineSelection.start,
40
+ end: selection.end
41
+ });
42
+ insertTextAtPosition(target, blockText + "\n" + prevLineText);
43
+ textArea.setSelectionRange({
44
+ start: prevLineSelection.start,
45
+ end: prevLineSelection.start + blockText.length
46
+ });
47
+ } else {
48
+ var nextLineSelection = selectLine({
49
+ text: target.value,
50
+ selection: {
51
+ start: selection.end + 1,
52
+ end: selection.end + 1
53
+ }
54
+ });
55
+ var nextLineText = target.value.slice(nextLineSelection.start, nextLineSelection.end);
56
+ textArea.setSelectionRange({
57
+ start: selection.start,
58
+ end: nextLineSelection.end
59
+ });
60
+ insertTextAtPosition(target, nextLineText + "\n" + blockText);
61
+ textArea.setSelectionRange({
62
+ start: nextLineSelection.end - blockText.length,
63
+ end: nextLineSelection.end
64
+ });
65
+ }
66
+ }
13
67
  export default function handleKeyDown(e, tabSize, defaultTabEnable) {
14
68
  if (tabSize === void 0) {
15
69
  tabSize = 2;
@@ -60,7 +114,7 @@ export default function handleKeyDown(e, tabSize, defaultTabEnable) {
60
114
  } else {
61
115
  return insertTextAtPosition(target, space);
62
116
  }
63
- } else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d+.\s/.test(currentLineStr))) {
117
+ } else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d+.\s/.test(currentLineStr)) && !e.shiftKey) {
64
118
  /**
65
119
  * `13` - `Enter`
66
120
  */
@@ -69,14 +123,38 @@ export default function handleKeyDown(e, tabSize, defaultTabEnable) {
69
123
  if (currentLineStr.startsWith('*')) {
70
124
  startStr = '\n* ';
71
125
  }
72
- if (currentLineStr.startsWith('- [ ]')) {
126
+ if (currentLineStr.startsWith('- [ ]') || currentLineStr.startsWith('- [X]') || currentLineStr.startsWith('- [x]')) {
73
127
  startStr = '\n- [ ] ';
74
- } else if (currentLineStr.startsWith('- [X]')) {
75
- startStr = '\n- [X] ';
76
128
  }
77
129
  if (/^\d+.\s/.test(currentLineStr)) {
78
130
  startStr = "\n" + (parseInt(currentLineStr) + 1) + ". ";
79
131
  }
80
132
  return insertTextAtPosition(target, startStr);
133
+ } else if (e.code && e.code.toLowerCase() === 'keyd' && e.ctrlKey) {
134
+ // Duplicate lines
135
+ stopPropagation(e);
136
+ var selection = {
137
+ start: target.selectionStart,
138
+ end: target.selectionEnd
139
+ };
140
+ var savedSelection = selection;
141
+ selection = selectLine({
142
+ text: target.value,
143
+ selection
144
+ });
145
+ var textToDuplicate = target.value.slice(selection.start, selection.end);
146
+ textArea.setSelectionRange({
147
+ start: selection.end,
148
+ end: selection.end
149
+ });
150
+ insertTextAtPosition(target, "\n" + textToDuplicate);
151
+ textArea.setSelectionRange({
152
+ start: savedSelection.start,
153
+ end: savedSelection.end
154
+ });
155
+ } else if (e.code && e.code.toLowerCase() === 'arrowup' && e.altKey) {
156
+ handleLineMove(e, -1);
157
+ } else if (e.code && e.code.toLowerCase() === 'arrowdown' && e.altKey) {
158
+ handleLineMove(e, 1);
81
159
  }
82
160
  }
@@ -3,13 +3,6 @@
3
3
  * Copyright (c) 2018 Dmitriy Kubyshkin
4
4
  * Copied from https://github.com/grassator/insert-text-at-cursor
5
5
  */
6
- /**
7
- * @param {string} val
8
- * @param {number} cursorIdx
9
- * @param {HTMLTextAreaElement|HTMLInputElement} input
10
- * @return {void}
11
- */
12
- export declare const insertAtLineStart: (val: string, cursorIdx: number, input: HTMLTextAreaElement | HTMLInputElement) => void;
13
6
  /**
14
7
  * @param {HTMLTextAreaElement|HTMLInputElement} input
15
8
  * @param {string} text
@@ -22,29 +22,6 @@ function canManipulateViaTextNodes(input) {
22
22
  return browserSupportsTextareaTextNodes;
23
23
  }
24
24
 
25
- /**
26
- * @param {string} val
27
- * @param {number} cursorIdx
28
- * @param {HTMLTextAreaElement|HTMLInputElement} input
29
- * @return {void}
30
- */
31
- export var insertAtLineStart = (val, cursorIdx, input) => {
32
- var content = input.value;
33
- var startIdx = 0;
34
- while (cursorIdx--) {
35
- var char = content[cursorIdx];
36
- if (char === '\n') {
37
- startIdx = cursorIdx + 1;
38
- break;
39
- }
40
- }
41
- input.focus();
42
- input.setRangeText(val, startIdx, startIdx);
43
- input.dispatchEvent(new Event('input', {
44
- bubbles: true
45
- }));
46
- };
47
-
48
25
  /**
49
26
  * @param {HTMLTextAreaElement|HTMLInputElement} input
50
27
  * @param {string} text
@@ -66,7 +43,12 @@ export function insertTextAtPosition(input, text) {
66
43
  }
67
44
 
68
45
  // Webkit + Edge
69
- var isSuccess = document.execCommand && document.execCommand('insertText', false, text);
46
+ var isSuccess = false;
47
+ if (text !== '') {
48
+ isSuccess = document.execCommand && document.execCommand('insertText', false, text);
49
+ } else {
50
+ isSuccess = document.execCommand && document.execCommand('delete', false);
51
+ }
70
52
  if (!isSuccess) {
71
53
  var start = input.selectionStart;
72
54
  var end = input.selectionEnd;
@@ -1,9 +1,16 @@
1
1
  import { TextRange } from '../commands';
2
+ import { TextAreaTextApi } from '../commands';
2
3
  export interface TextSection {
3
4
  text: string;
4
5
  selection: TextRange;
5
6
  }
6
- export declare function selectWord({ text, selection }: TextSection): TextRange;
7
+ export declare function selectWord({ text, selection, prefix, suffix, }: {
8
+ text: string;
9
+ selection: TextRange;
10
+ prefix: string;
11
+ suffix?: string;
12
+ }): TextRange;
13
+ export declare function selectLine({ text, selection }: TextSection): TextRange;
7
14
  /**
8
15
  * Gets the number of line-breaks that would have to be inserted before the given 'startPosition'
9
16
  * to make sure there's an empty line between 'startPosition' and the previous text
@@ -15,3 +22,18 @@ export declare function getBreaksNeededForEmptyLineBefore(text: string | undefin
15
22
  */
16
23
  export declare function getBreaksNeededForEmptyLineAfter(text: string | undefined, startPosition: number): number;
17
24
  export declare function getSurroundingWord(text: string, position: number): TextRange;
25
+ export declare function executeCommand({ api, selectedText, selection, prefix, suffix, }: {
26
+ api: TextAreaTextApi;
27
+ selectedText: string;
28
+ selection: TextRange;
29
+ prefix: string;
30
+ suffix?: string;
31
+ }): void;
32
+ export type AlterLineFunction = (line: string, index: number) => string;
33
+ /**
34
+ * Inserts insertionString before each line
35
+ */
36
+ export declare function insertBeforeEachLine(selectedText: string, insertBefore: string | AlterLineFunction): {
37
+ modifiedText: string;
38
+ insertionLength: number;
39
+ };
@@ -1,13 +1,39 @@
1
1
  export function selectWord(_ref) {
2
2
  var {
3
3
  text,
4
- selection
4
+ selection,
5
+ prefix,
6
+ suffix = prefix
5
7
  } = _ref;
8
+ var result = selection;
6
9
  if (text && text.length && selection.start === selection.end) {
7
- // the user is pointing to a word
8
- return getSurroundingWord(text, selection.start);
10
+ result = getSurroundingWord(text, selection.start);
11
+ }
12
+ if (result.start >= prefix.length && result.end <= text.length - suffix.length) {
13
+ var selectedTextContext = text.slice(result.start - prefix.length, result.end + suffix.length);
14
+ if (selectedTextContext.startsWith(prefix) && selectedTextContext.endsWith(suffix)) {
15
+ return {
16
+ start: result.start - prefix.length,
17
+ end: result.end + suffix.length
18
+ };
19
+ }
9
20
  }
10
- return selection;
21
+ return result;
22
+ }
23
+ export function selectLine(_ref2) {
24
+ var {
25
+ text,
26
+ selection
27
+ } = _ref2;
28
+ var start = text.slice(0, selection.start).lastIndexOf('\n') + 1;
29
+ var end = text.slice(selection.end).indexOf('\n') + selection.end;
30
+ if (end === selection.end - 1) {
31
+ end = text.length;
32
+ }
33
+ return {
34
+ start,
35
+ end
36
+ };
11
37
  }
12
38
 
13
39
  /**
@@ -105,4 +131,57 @@ export function getSurroundingWord(text, position) {
105
131
  start,
106
132
  end
107
133
  };
134
+ }
135
+ export function executeCommand(_ref3) {
136
+ var {
137
+ api,
138
+ selectedText,
139
+ selection,
140
+ prefix,
141
+ suffix = prefix
142
+ } = _ref3;
143
+ if (selectedText.length >= prefix.length + suffix.length && selectedText.startsWith(prefix) && selectedText.endsWith(suffix)) {
144
+ api.replaceSelection(selectedText.slice(prefix.length, suffix.length ? -suffix.length : undefined));
145
+ api.setSelectionRange({
146
+ start: selection.start - prefix.length,
147
+ end: selection.end - prefix.length
148
+ });
149
+ } else {
150
+ api.replaceSelection("" + prefix + selectedText + suffix);
151
+ api.setSelectionRange({
152
+ start: selection.start + prefix.length,
153
+ end: selection.end + prefix.length
154
+ });
155
+ }
156
+ }
157
+ /**
158
+ * Inserts insertionString before each line
159
+ */
160
+ export function insertBeforeEachLine(selectedText, insertBefore) {
161
+ var lines = selectedText.split(/\n/);
162
+ var insertionLength = 0;
163
+ var modifiedText = lines.map((item, index) => {
164
+ if (typeof insertBefore === 'string') {
165
+ if (item.startsWith(insertBefore)) {
166
+ insertionLength -= insertBefore.length;
167
+ return item.slice(insertBefore.length);
168
+ }
169
+ insertionLength += insertBefore.length;
170
+ return insertBefore + item;
171
+ }
172
+ if (typeof insertBefore === 'function') {
173
+ if (item.startsWith(insertBefore(item, index))) {
174
+ insertionLength -= insertBefore(item, index).length;
175
+ return item.slice(insertBefore(item, index).length);
176
+ }
177
+ var insertionResult = insertBefore(item, index);
178
+ insertionLength += insertionResult.length;
179
+ return insertBefore(item, index) + item;
180
+ }
181
+ throw Error('insertion is expected to be either a string or a function');
182
+ }).join('\n');
183
+ return {
184
+ modifiedText,
185
+ insertionLength
186
+ };
108
187
  }
package/lib/Context.js CHANGED
@@ -11,7 +11,6 @@ var _react = _interopRequireDefault(require("react"));
11
11
  function reducer(state, action) {
12
12
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), action);
13
13
  }
14
- var EditorContext = /*#__PURE__*/_react["default"].createContext({
14
+ var EditorContext = exports.EditorContext = /*#__PURE__*/_react["default"].createContext({
15
15
  markdown: ''
16
- });
17
- exports.EditorContext = EditorContext;
16
+ });
package/lib/Editor.js CHANGED
@@ -313,6 +313,5 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
313
313
  });
314
314
  var Editor = InternalMDEditor;
315
315
  Editor.Markdown = _reactMarkdownPreview["default"];
316
- var _default = Editor;
317
- exports["default"] = _default;
316
+ var _default = exports["default"] = Editor;
318
317
  module.exports = exports.default;
@@ -8,11 +8,11 @@ exports.bold = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _markdownUtils = require("../utils/markdownUtils");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var bold = {
11
+ var bold = exports.bold = {
12
12
  name: 'bold',
13
13
  keyCommand: 'bold',
14
14
  shortcuts: 'ctrlcmd+b',
15
- value: '**{{text}}**',
15
+ prefix: '**',
16
16
  buttonProps: {
17
17
  'aria-label': 'Add bold text (ctrl + b)',
18
18
  title: 'Add bold text (ctrl + b)'
@@ -28,22 +28,17 @@ var bold = {
28
28
  })
29
29
  }),
30
30
  execute: function execute(state, api) {
31
- // Adjust the selection to encompass the whole word if the caret is inside one
32
31
  var newSelectionRange = (0, _markdownUtils.selectWord)({
33
32
  text: state.text,
34
- selection: state.selection
33
+ selection: state.selection,
34
+ prefix: state.command.prefix
35
35
  });
36
36
  var state1 = api.setSelectionRange(newSelectionRange);
37
- // Replaces the current selection with the bold mark up
38
- var val = state.command.value || '';
39
- api.replaceSelection(val.replace(/({{text}})/gi, state1.selectedText));
40
- var start = state1.selection.start + val.indexOf('{{text}}');
41
- var end = state1.selection.start + val.indexOf('{{text}}') + (state1.selection.end - state1.selection.start);
42
- // Adjust the selection to not contain the **
43
- api.setSelectionRange({
44
- start: start,
45
- end: end
37
+ (0, _markdownUtils.executeCommand)({
38
+ api: api,
39
+ selectedText: state1.selectedText,
40
+ selection: state.selection,
41
+ prefix: state.command.prefix
46
42
  });
47
43
  }
48
- };
49
- exports.bold = bold;
44
+ };
@@ -1,3 +1,3 @@
1
1
  import { ICommand } from './';
2
- export declare const code: ICommand;
3
2
  export declare const codeBlock: ICommand;
3
+ export declare const code: ICommand;
@@ -8,96 +8,101 @@ exports.codeBlock = exports.code = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _markdownUtils = require("../utils/markdownUtils");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var code = {
12
- name: 'code',
13
- keyCommand: 'code',
14
- shortcuts: 'ctrlcmd+j',
15
- value: '``',
11
+ var codeBlock = exports.codeBlock = {
12
+ name: 'codeBlock',
13
+ keyCommand: 'codeBlock',
14
+ shortcuts: 'ctrlcmd+shift+j',
15
+ prefix: '```',
16
16
  buttonProps: {
17
- 'aria-label': 'Insert code (ctrl + j)',
18
- title: 'Insert code (ctrl + j)'
17
+ 'aria-label': 'Insert Code Block (ctrl + shift + j)',
18
+ title: 'Insert Code Block (ctrl + shift +j)'
19
19
  },
20
20
  icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
21
- width: "14",
22
- height: "14",
21
+ width: "13",
22
+ height: "13",
23
23
  role: "img",
24
- viewBox: "0 0 640 512",
24
+ viewBox: "0 0 156 156",
25
25
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
26
26
  fill: "currentColor",
27
- 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"
27
+ 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"
28
28
  })
29
29
  }),
30
- execute: function execute(tate, api) {
31
- // Adjust the selection to encompass the whole word if the caret is inside one
30
+ execute: function execute(state, api) {
32
31
  var newSelectionRange = (0, _markdownUtils.selectWord)({
33
- text: tate.text,
34
- selection: tate.selection
32
+ text: state.text,
33
+ selection: state.selection,
34
+ prefix: '```\n',
35
+ suffix: '\n```'
35
36
  });
36
37
  var state1 = api.setSelectionRange(newSelectionRange);
37
- // when there's no breaking line
38
- if (state1.selectedText.indexOf('\n') === -1) {
39
- api.replaceSelection("`".concat(state1.selectedText, "`"));
40
- // Adjust the selection to not contain the **
41
38
 
42
- var _selectionStart = state1.selection.start + 1;
43
- var _selectionEnd = _selectionStart + state1.selectedText.length;
44
- api.setSelectionRange({
45
- start: _selectionStart,
46
- end: _selectionEnd
47
- });
48
- return;
39
+ // Based on context determine if new line is needed or not
40
+ var prefix = '\n```\n';
41
+ var suffix = '\n```\n';
42
+ if (state1.selectedText.length >= prefix.length + suffix.length - 2 && state1.selectedText.startsWith(prefix) && state1.selectedText.endsWith(suffix)) {
43
+ // Remove code block
44
+ prefix = '```\n';
45
+ suffix = '\n```';
46
+ } else {
47
+ // Add code block
48
+ if (state1.selection.start >= 1 && state.text.slice(state1.selection.start - 1, state1.selection.start) === '\n' || state1.selection.start === 0) {
49
+ prefix = '```\n';
50
+ }
51
+ if (state1.selection.end <= state.text.length - 1 && state.text.slice(state1.selection.end, state1.selection.end + 1) === '\n' || state1.selection.end === state.text.length) {
52
+ suffix = '\n```';
53
+ }
49
54
  }
50
- var breaksBeforeCount = (0, _markdownUtils.getBreaksNeededForEmptyLineBefore)(state1.text, state1.selection.start);
51
- var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
52
- var breaksAfterCount = (0, _markdownUtils.getBreaksNeededForEmptyLineAfter)(state1.text, state1.selection.end);
53
- var breaksAfter = Array(breaksAfterCount + 1).join('\n');
54
- api.replaceSelection("".concat(breaksBefore, "```\n").concat(state1.selectedText, "\n```").concat(breaksAfter));
55
- var selectionStart = state1.selection.start + breaksBeforeCount + 4;
56
- var selectionEnd = selectionStart + state1.selectedText.length;
57
- api.setSelectionRange({
58
- start: selectionStart,
59
- end: selectionEnd
55
+ var newSelectionRange2 = (0, _markdownUtils.selectWord)({
56
+ text: state.text,
57
+ selection: state.selection,
58
+ prefix: prefix,
59
+ suffix: suffix
60
+ });
61
+ var state2 = api.setSelectionRange(newSelectionRange2);
62
+ (0, _markdownUtils.executeCommand)({
63
+ api: api,
64
+ selectedText: state2.selectedText,
65
+ selection: state.selection,
66
+ prefix: prefix,
67
+ suffix: suffix
60
68
  });
61
69
  }
62
70
  };
63
- exports.code = code;
64
- var codeBlock = {
65
- name: 'codeBlock',
66
- keyCommand: 'codeBlock',
67
- shortcuts: 'ctrlcmd+shift+j',
68
- value: '```\n```',
71
+ var code = exports.code = {
72
+ name: 'code',
73
+ keyCommand: 'code',
74
+ shortcuts: 'ctrlcmd+j',
75
+ prefix: '`',
76
+ buttonProps: {
77
+ 'aria-label': 'Insert code (ctrl + j)',
78
+ title: 'Insert code (ctrl + j)'
79
+ },
69
80
  icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
70
- width: "13",
71
- height: "13",
81
+ width: "14",
82
+ height: "14",
72
83
  role: "img",
73
- viewBox: "0 0 156 156",
84
+ viewBox: "0 0 640 512",
74
85
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
75
86
  fill: "currentColor",
76
- 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"
87
+ 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"
77
88
  })
78
89
  }),
79
- buttonProps: {
80
- 'aria-label': 'Insert Code Block (ctrl + shift + j)',
81
- title: 'Insert Code Block (ctrl + shift +j)'
82
- },
83
- execute: function execute(tate, api) {
84
- // Adjust the selection to encompass the whole word if the caret is inside one
85
- var newSelectionRange = (0, _markdownUtils.selectWord)({
86
- text: tate.text,
87
- selection: tate.selection
88
- });
89
- var state1 = api.setSelectionRange(newSelectionRange);
90
- var breaksBeforeCount = (0, _markdownUtils.getBreaksNeededForEmptyLineBefore)(state1.text, state1.selection.start);
91
- var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
92
- var breaksAfterCount = (0, _markdownUtils.getBreaksNeededForEmptyLineAfter)(state1.text, state1.selection.end);
93
- var breaksAfter = Array(breaksAfterCount + 1).join('\n');
94
- api.replaceSelection("".concat(breaksBefore, "```\n").concat(state1.selectedText, "\n```").concat(breaksAfter));
95
- var selectionStart = state1.selection.start + breaksBeforeCount + 4;
96
- var selectionEnd = selectionStart + state1.selectedText.length;
97
- api.setSelectionRange({
98
- start: selectionStart,
99
- end: selectionEnd
100
- });
90
+ execute: function execute(state, api) {
91
+ if (state.selectedText.indexOf('\n') === -1) {
92
+ var newSelectionRange = (0, _markdownUtils.selectWord)({
93
+ text: state.text,
94
+ selection: state.selection,
95
+ prefix: state.command.prefix
96
+ });
97
+ var state1 = api.setSelectionRange(newSelectionRange);
98
+ (0, _markdownUtils.executeCommand)({
99
+ api: api,
100
+ selectedText: state1.selectedText,
101
+ selection: state.selection,
102
+ prefix: state.command.prefix
103
+ });
104
+ } else {
105
+ codeBlock.execute(state, api);
106
+ }
101
107
  }
102
- };
103
- exports.codeBlock = codeBlock;
108
+ };
@@ -8,30 +8,16 @@ exports.comment = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _markdownUtils = require("../utils/markdownUtils");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var comment = {
11
+ var comment = exports.comment = {
12
12
  name: 'comment',
13
13
  keyCommand: 'comment',
14
14
  shortcuts: 'ctrlcmd+/',
15
- value: '<!-- -->',
15
+ prefix: '<!-- ',
16
+ suffix: ' -->',
16
17
  buttonProps: {
17
18
  'aria-label': 'Insert comment (ctrl + /)',
18
19
  title: 'Insert comment (ctrl + /)'
19
20
  },
20
- execute: function execute(state, api) {
21
- // Adjust the selection to encompass the whole word if the caret is inside one
22
- var newSelectionRange = (0, _markdownUtils.selectWord)({
23
- text: state.text,
24
- selection: state.selection
25
- });
26
- var state1 = api.setSelectionRange(newSelectionRange);
27
- // Replaces the current selection with the bold mark up
28
- var state2 = api.replaceSelection("<!-- ".concat(state1.selectedText, " -->"));
29
- // Adjust the selection to not contain the **
30
- api.setSelectionRange({
31
- start: state2.selection.end - 4 - state1.selectedText.length,
32
- end: state2.selection.end - 4
33
- });
34
- },
35
21
  icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
36
22
  height: "1em",
37
23
  width: "1em",
@@ -55,6 +41,21 @@ var comment = {
55
41
  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"
56
42
  })]
57
43
  })
58
- })
59
- };
60
- exports.comment = comment;
44
+ }),
45
+ execute: function execute(state, api) {
46
+ var newSelectionRange = (0, _markdownUtils.selectWord)({
47
+ text: state.text,
48
+ selection: state.selection,
49
+ prefix: state.command.prefix,
50
+ suffix: state.command.suffix
51
+ });
52
+ var state1 = api.setSelectionRange(newSelectionRange);
53
+ (0, _markdownUtils.executeCommand)({
54
+ api: api,
55
+ selectedText: state1.selectedText,
56
+ selection: state.selection,
57
+ prefix: state.command.prefix,
58
+ suffix: state.command.suffix
59
+ });
60
+ }
61
+ };
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.divider = void 0;
7
- var divider = {
7
+ var divider = exports.divider = {
8
8
  keyCommand: 'divider'
9
- };
10
- exports.divider = divider;
9
+ };