@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
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.codePreview = exports.codeLive = exports.codeEdit = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _jsxRuntime = require("react/jsx-runtime");
10
- var codePreview = {
10
+ var codePreview = exports.codePreview = {
11
11
  name: 'preview',
12
12
  keyCommand: 'preview',
13
13
  value: 'preview',
@@ -37,8 +37,7 @@ var codePreview = {
37
37
  }
38
38
  }
39
39
  };
40
- exports.codePreview = codePreview;
41
- var codeEdit = {
40
+ var codeEdit = exports.codeEdit = {
42
41
  name: 'edit',
43
42
  keyCommand: 'preview',
44
43
  value: 'edit',
@@ -68,8 +67,7 @@ var codeEdit = {
68
67
  }
69
68
  }
70
69
  };
71
- exports.codeEdit = codeEdit;
72
- var codeLive = {
70
+ var codeLive = exports.codeLive = {
73
71
  name: 'live',
74
72
  keyCommand: 'preview',
75
73
  value: 'live',
@@ -98,5 +96,4 @@ var codeLive = {
98
96
  });
99
97
  }
100
98
  }
101
- };
102
- exports.codeLive = codeLive;
99
+ };
@@ -8,10 +8,11 @@ exports.quote = 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 quote = {
11
+ var quote = exports.quote = {
12
12
  name: 'quote',
13
13
  keyCommand: 'quote',
14
14
  shortcuts: 'ctrlcmd+q',
15
+ prefix: '> ',
15
16
  buttonProps: {
16
17
  'aria-label': 'Insert a quote (ctrl + q)',
17
18
  title: 'Insert a quote (ctrl + q)'
@@ -26,25 +27,23 @@ var quote = {
26
27
  })
27
28
  }),
28
29
  execute: function execute(state, api) {
29
- // Adjust the selection to encompass the whole word if the caret is inside one
30
30
  var newSelectionRange = (0, _markdownUtils.selectWord)({
31
31
  text: state.text,
32
- selection: state.selection
32
+ selection: state.selection,
33
+ prefix: state.command.prefix
33
34
  });
34
35
  var state1 = api.setSelectionRange(newSelectionRange);
35
36
  var breaksBeforeCount = (0, _markdownUtils.getBreaksNeededForEmptyLineBefore)(state1.text, state1.selection.start);
36
37
  var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
37
38
  var breaksAfterCount = (0, _markdownUtils.getBreaksNeededForEmptyLineAfter)(state1.text, state1.selection.end);
38
39
  var breaksAfter = Array(breaksAfterCount + 1).join('\n');
39
-
40
- // Replaces the current selection with the quote mark up
41
- api.replaceSelection("".concat(breaksBefore, "> ").concat(state1.selectedText).concat(breaksAfter));
42
- var selectionStart = state1.selection.start + breaksBeforeCount + 2;
43
- var selectionEnd = selectionStart + state1.selectedText.length;
40
+ var modifiedText = (0, _markdownUtils.insertBeforeEachLine)(state1.selectedText, state.command.prefix);
41
+ api.replaceSelection("".concat(breaksBefore).concat(modifiedText.modifiedText).concat(breaksAfter));
42
+ var selectionStart = state1.selection.start + breaksBeforeCount;
43
+ var selectionEnd = selectionStart + modifiedText.modifiedText.length;
44
44
  api.setSelectionRange({
45
45
  start: selectionStart,
46
46
  end: selectionEnd
47
47
  });
48
48
  }
49
- };
50
- exports.quote = quote;
49
+ };
@@ -8,7 +8,7 @@ exports.strikethrough = 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 strikethrough = {
11
+ var strikethrough = exports.strikethrough = {
12
12
  name: 'strikethrough',
13
13
  keyCommand: 'strikethrough',
14
14
  shortcuts: 'ctrl+shift+x',
@@ -16,7 +16,7 @@ var strikethrough = {
16
16
  'aria-label': 'Add strikethrough text (ctrl + shift + x)',
17
17
  title: 'Add strikethrough text (ctrl + shift + x)'
18
18
  },
19
- value: '~~{{text}}~~',
19
+ prefix: '~~',
20
20
  icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
21
21
  "data-name": "strikethrough",
22
22
  width: "12",
@@ -29,22 +29,17 @@ var strikethrough = {
29
29
  })
30
30
  }),
31
31
  execute: function execute(state, api) {
32
- // Adjust the selection to encompass the whole word if the caret is inside one
33
32
  var newSelectionRange = (0, _markdownUtils.selectWord)({
34
33
  text: state.text,
35
- selection: state.selection
34
+ selection: state.selection,
35
+ prefix: state.command.prefix
36
36
  });
37
37
  var state1 = api.setSelectionRange(newSelectionRange);
38
- // Replaces the current selection with the bold mark up
39
- var val = state.command.value || '';
40
- api.replaceSelection(val.replace(/({{text}})/gi, state1.selectedText));
41
- var start = state1.selection.start + val.indexOf('{{text}}');
42
- var end = state1.selection.start + val.indexOf('{{text}}') + (state1.selection.end - state1.selection.start);
43
- // Adjust the selection to not contain the **
44
- api.setSelectionRange({
45
- start: start,
46
- end: end
38
+ (0, _markdownUtils.executeCommand)({
39
+ api: api,
40
+ selectedText: state1.selectedText,
41
+ selection: state.selection,
42
+ prefix: state.command.prefix
47
43
  });
48
44
  }
49
- };
50
- exports.strikethrough = strikethrough;
45
+ };
@@ -0,0 +1,2 @@
1
+ import { ICommand } from './';
2
+ export declare const table: ICommand;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.table = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _markdownUtils = require("../utils/markdownUtils");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ var table = exports.table = {
12
+ name: 'table',
13
+ keyCommand: 'table',
14
+ prefix: '\n| Header | Header |\n|--------|--------|\n| Cell | Cell |\n| Cell | Cell |\n| Cell | Cell |\n\n',
15
+ suffix: '',
16
+ buttonProps: {
17
+ 'aria-label': 'Add table',
18
+ title: 'Add table'
19
+ },
20
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
21
+ role: "img",
22
+ width: "12",
23
+ height: "12",
24
+ viewBox: "0 0 512 512",
25
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
26
+ fill: "currentColor",
27
+ d: "M64 256V160H224v96H64zm0 64H224v96H64V320zm224 96V320H448v96H288zM448 256H288V160H448v96zM64 32C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H64z"
28
+ //Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com
29
+ })
30
+ }),
31
+
32
+ execute: function execute(state, api) {
33
+ var newSelectionRange = (0, _markdownUtils.selectWord)({
34
+ text: state.text,
35
+ selection: state.selection,
36
+ prefix: state.command.prefix,
37
+ suffix: state.command.suffix
38
+ });
39
+ var state1 = api.setSelectionRange(newSelectionRange);
40
+ if (state1.selectedText.length >= state.command.prefix.length + state.command.suffix.length && state1.selectedText.startsWith(state.command.prefix)) {
41
+ // Remove
42
+ (0, _markdownUtils.executeCommand)({
43
+ api: api,
44
+ selectedText: state1.selectedText,
45
+ selection: state.selection,
46
+ prefix: state.command.prefix,
47
+ suffix: state.command.suffix
48
+ });
49
+ } else {
50
+ // Add
51
+ state1 = api.setSelectionRange({
52
+ start: state.selection.start,
53
+ end: state.selection.start
54
+ });
55
+ (0, _markdownUtils.executeCommand)({
56
+ api: api,
57
+ selectedText: state1.selectedText,
58
+ selection: state.selection,
59
+ prefix: state.command.prefix,
60
+ suffix: state.command.suffix
61
+ });
62
+ }
63
+ }
64
+ };
@@ -1,2 +1,8 @@
1
- import { ICommand } from './';
1
+ import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ export declare function titleExecute({ state, api, prefix, suffix, }: {
3
+ state: ExecuteState;
4
+ api: TextAreaTextApi;
5
+ prefix: string;
6
+ suffix?: string;
7
+ }): void;
2
8
  export declare const title: ICommand;
@@ -5,11 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.title = void 0;
8
+ exports.titleExecute = titleExecute;
8
9
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
10
  var _react = _interopRequireDefault(require("react"));
10
11
  var _title = require("./title1");
12
+ var _markdownUtils = require("../utils/markdownUtils");
11
13
  var _jsxRuntime = require("react/jsx-runtime");
12
- var title = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _title.title1), {}, {
14
+ function titleExecute(_ref) {
15
+ var state = _ref.state,
16
+ api = _ref.api,
17
+ prefix = _ref.prefix,
18
+ _ref$suffix = _ref.suffix,
19
+ suffix = _ref$suffix === void 0 ? prefix : _ref$suffix;
20
+ var newSelectionRange = (0, _markdownUtils.selectLine)({
21
+ text: state.text,
22
+ selection: state.selection
23
+ });
24
+ var state1 = api.setSelectionRange(newSelectionRange);
25
+ (0, _markdownUtils.executeCommand)({
26
+ api: api,
27
+ selectedText: state1.selectedText,
28
+ selection: state.selection,
29
+ prefix: prefix,
30
+ suffix: suffix
31
+ });
32
+ }
33
+ var title = exports.title = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _title.title1), {}, {
13
34
  icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
14
35
  width: "12",
15
36
  height: "12",
@@ -19,5 +40,4 @@ var title = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _t
19
40
  d: "M15.7083333,468 C7.03242448,468 0,462.030833 0,454.666667 L0,421.333333 C0,413.969167 7.03242448,408 15.7083333,408 L361.291667,408 C369.967576,408 377,413.969167 377,421.333333 L377,454.666667 C377,462.030833 369.967576,468 361.291667,468 L15.7083333,468 Z M21.6666667,366 C9.69989583,366 0,359.831861 0,352.222222 L0,317.777778 C0,310.168139 9.69989583,304 21.6666667,304 L498.333333,304 C510.300104,304 520,310.168139 520,317.777778 L520,352.222222 C520,359.831861 510.300104,366 498.333333,366 L21.6666667,366 Z M136.835938,64 L136.835937,126 L107.25,126 L107.25,251 L40.75,251 L40.75,126 L-5.68434189e-14,126 L-5.68434189e-14,64 L136.835938,64 Z M212,64 L212,251 L161.648438,251 L161.648438,64 L212,64 Z M378,64 L378,126 L343.25,126 L343.25,251 L281.75,251 L281.75,126 L238,126 L238,64 L378,64 Z M449.047619,189.550781 L520,189.550781 L520,251 L405,251 L405,64 L449.047619,64 L449.047619,189.550781 Z"
20
41
  })
21
42
  })
22
- });
23
- exports.title = title;
43
+ });
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.title1 = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
9
+ var _title = require("../commands/title");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var title1 = {
11
+ var title1 = exports.title1 = {
12
12
  name: 'title1',
13
13
  keyCommand: 'title1',
14
14
  shortcuts: 'ctrlcmd+1',
15
- value: 'title1',
15
+ prefix: '# ',
16
+ suffix: '',
16
17
  buttonProps: {
17
18
  'aria-label': 'Insert title1 (ctrl + 1)',
18
19
  title: 'Insert title1 (ctrl + 1)'
@@ -25,11 +26,11 @@ var title1 = {
25
26
  children: "Title 1"
26
27
  }),
27
28
  execute: function execute(state, api) {
28
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
29
- api.replaceSelection('# ');
30
- } else {
31
- (0, _InsertTextAtPosition.insertAtLineStart)('# ', state.selection.start, api.textArea);
32
- }
29
+ (0, _title.titleExecute)({
30
+ state: state,
31
+ api: api,
32
+ prefix: state.command.prefix,
33
+ suffix: state.command.suffix
34
+ });
33
35
  }
34
- };
35
- exports.title1 = title1;
36
+ };
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.title2 = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
9
+ var _title = require("../commands/title");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var title2 = {
11
+ var title2 = exports.title2 = {
12
12
  name: 'title2',
13
13
  keyCommand: 'title2',
14
14
  shortcuts: 'ctrlcmd+2',
15
- value: 'title2',
15
+ prefix: '## ',
16
+ suffix: '',
16
17
  buttonProps: {
17
18
  'aria-label': 'Insert title2 (ctrl + 2)',
18
19
  title: 'Insert title2 (ctrl + 2)'
@@ -25,11 +26,11 @@ var title2 = {
25
26
  children: "Title 2"
26
27
  }),
27
28
  execute: function execute(state, api) {
28
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
29
- api.replaceSelection('## ');
30
- } else {
31
- (0, _InsertTextAtPosition.insertAtLineStart)('## ', state.selection.start, api.textArea);
32
- }
29
+ (0, _title.titleExecute)({
30
+ state: state,
31
+ api: api,
32
+ prefix: state.command.prefix,
33
+ suffix: state.command.suffix
34
+ });
33
35
  }
34
- };
35
- exports.title2 = title2;
36
+ };
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.title3 = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
9
+ var _title = require("../commands/title");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var title3 = {
11
+ var title3 = exports.title3 = {
12
12
  name: 'title3',
13
13
  keyCommand: 'title3',
14
14
  shortcuts: 'ctrlcmd+3',
15
- value: 'title3',
15
+ prefix: '### ',
16
+ suffix: '',
16
17
  buttonProps: {
17
18
  'aria-label': 'Insert title3 (ctrl + 3)',
18
19
  title: 'Insert title3 (ctrl + 3)'
@@ -25,11 +26,11 @@ var title3 = {
25
26
  children: "Title 3"
26
27
  }),
27
28
  execute: function execute(state, api) {
28
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
29
- api.replaceSelection('### ');
30
- } else {
31
- (0, _InsertTextAtPosition.insertAtLineStart)('### ', state.selection.start, api.textArea);
32
- }
29
+ (0, _title.titleExecute)({
30
+ state: state,
31
+ api: api,
32
+ prefix: state.command.prefix,
33
+ suffix: state.command.suffix
34
+ });
33
35
  }
34
- };
35
- exports.title3 = title3;
36
+ };
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.title4 = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
9
+ var _title = require("../commands/title");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var title4 = {
11
+ var title4 = exports.title4 = {
12
12
  name: 'title4',
13
13
  keyCommand: 'title4',
14
14
  shortcuts: 'ctrlcmd+4',
15
- value: 'title4',
15
+ prefix: '#### ',
16
+ suffix: '',
16
17
  buttonProps: {
17
18
  'aria-label': 'Insert title4 (ctrl + 4)',
18
19
  title: 'Insert title4 (ctrl + 4)'
@@ -25,11 +26,11 @@ var title4 = {
25
26
  children: "Title 4"
26
27
  }),
27
28
  execute: function execute(state, api) {
28
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
29
- api.replaceSelection('#### ');
30
- } else {
31
- (0, _InsertTextAtPosition.insertAtLineStart)('#### ', state.selection.start, api.textArea);
32
- }
29
+ (0, _title.titleExecute)({
30
+ state: state,
31
+ api: api,
32
+ prefix: state.command.prefix,
33
+ suffix: state.command.suffix
34
+ });
33
35
  }
34
- };
35
- exports.title4 = title4;
36
+ };
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.title5 = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
9
+ var _title = require("../commands/title");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var title5 = {
11
+ var title5 = exports.title5 = {
12
12
  name: 'title5',
13
13
  keyCommand: 'title5',
14
14
  shortcuts: 'ctrlcmd+5',
15
- value: 'title5',
15
+ prefix: '##### ',
16
+ suffix: '',
16
17
  buttonProps: {
17
18
  'aria-label': 'Insert title5 (ctrl + 5)',
18
19
  title: 'Insert title5 (ctrl + 5)'
@@ -25,11 +26,11 @@ var title5 = {
25
26
  children: "Title 5"
26
27
  }),
27
28
  execute: function execute(state, api) {
28
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
29
- api.replaceSelection('##### ');
30
- } else {
31
- (0, _InsertTextAtPosition.insertAtLineStart)('##### ', state.selection.start, api.textArea);
32
- }
29
+ (0, _title.titleExecute)({
30
+ state: state,
31
+ api: api,
32
+ prefix: state.command.prefix,
33
+ suffix: state.command.suffix
34
+ });
33
35
  }
34
- };
35
- exports.title5 = title5;
36
+ };
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.title6 = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
9
+ var _title = require("../commands/title");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var title6 = {
11
+ var title6 = exports.title6 = {
12
12
  name: 'title6',
13
13
  keyCommand: 'title6',
14
14
  shortcuts: 'ctrlcmd+6',
15
- value: 'title6',
15
+ prefix: '###### ',
16
+ suffix: '',
16
17
  buttonProps: {
17
18
  'aria-label': 'Insert title6 (ctrl + 6)',
18
19
  title: 'Insert title6 (ctrl + 6)'
@@ -25,11 +26,11 @@ var title6 = {
25
26
  children: "Title 6"
26
27
  }),
27
28
  execute: function execute(state, api) {
28
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
29
- api.replaceSelection('###### ');
30
- } else {
31
- (0, _InsertTextAtPosition.insertAtLineStart)('###### ', state.selection.start, api.textArea);
32
- }
29
+ (0, _title.titleExecute)({
30
+ state: state,
31
+ api: api,
32
+ prefix: state.command.prefix,
33
+ suffix: state.command.suffix
34
+ });
33
35
  }
34
- };
35
- exports.title6 = title6;
36
+ };
@@ -87,6 +87,5 @@ var DragBar = function DragBar(props) {
87
87
  children: svg
88
88
  });
89
89
  };
90
- var _default = DragBar;
91
- exports["default"] = _default;
90
+ var _default = exports["default"] = DragBar;
92
91
  module.exports = exports.default;
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = handleKeyDown;
7
7
  var _InsertTextAtPosition = require("../../utils/InsertTextAtPosition");
8
+ var _markdownUtils = require("../../utils/markdownUtils");
8
9
  var _commands = require("../../commands");
9
- var _list = require("../../commands/list");
10
10
  /**
11
11
  * - `13` - `Enter`
12
12
  * - `9` - `Tab`
@@ -15,6 +15,60 @@ function stopPropagation(e) {
15
15
  e.stopPropagation();
16
16
  e.preventDefault();
17
17
  }
18
+ function handleLineMove(e, direction) {
19
+ stopPropagation(e);
20
+ var target = e.target;
21
+ var textArea = new _commands.TextAreaTextApi(target);
22
+ var selection = {
23
+ start: target.selectionStart,
24
+ end: target.selectionEnd
25
+ };
26
+ selection = (0, _markdownUtils.selectLine)({
27
+ text: target.value,
28
+ selection: selection
29
+ });
30
+ if (direction < 0 && selection.start <= 0 || direction > 0 && selection.end >= target.value.length) {
31
+ return;
32
+ }
33
+ var blockText = target.value.slice(selection.start, selection.end);
34
+ if (direction < 0) {
35
+ var prevLineSelection = (0, _markdownUtils.selectLine)({
36
+ text: target.value,
37
+ selection: {
38
+ start: selection.start - 1,
39
+ end: selection.start - 1
40
+ }
41
+ });
42
+ var prevLineText = target.value.slice(prevLineSelection.start, prevLineSelection.end);
43
+ textArea.setSelectionRange({
44
+ start: prevLineSelection.start,
45
+ end: selection.end
46
+ });
47
+ (0, _InsertTextAtPosition.insertTextAtPosition)(target, "".concat(blockText, "\n").concat(prevLineText));
48
+ textArea.setSelectionRange({
49
+ start: prevLineSelection.start,
50
+ end: prevLineSelection.start + blockText.length
51
+ });
52
+ } else {
53
+ var nextLineSelection = (0, _markdownUtils.selectLine)({
54
+ text: target.value,
55
+ selection: {
56
+ start: selection.end + 1,
57
+ end: selection.end + 1
58
+ }
59
+ });
60
+ var nextLineText = target.value.slice(nextLineSelection.start, nextLineSelection.end);
61
+ textArea.setSelectionRange({
62
+ start: selection.start,
63
+ end: nextLineSelection.end
64
+ });
65
+ (0, _InsertTextAtPosition.insertTextAtPosition)(target, "".concat(nextLineText, "\n").concat(blockText));
66
+ textArea.setSelectionRange({
67
+ start: nextLineSelection.end - blockText.length,
68
+ end: nextLineSelection.end
69
+ });
70
+ }
71
+ }
18
72
  function handleKeyDown(e) {
19
73
  var tabSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
20
74
  var defaultTabEnable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -46,7 +100,7 @@ function handleKeyDown(e) {
46
100
  start: target.value.indexOf(modifiedText),
47
101
  end: target.selectionEnd
48
102
  });
49
- var modifiedTextObj = (0, _list.insertBeforeEachLine)(modifiedText, e.shiftKey ? '' : space);
103
+ var modifiedTextObj = (0, _markdownUtils.insertBeforeEachLine)(modifiedText, e.shiftKey ? '' : space);
50
104
  var text = modifiedTextObj.modifiedText;
51
105
  if (e.shiftKey) {
52
106
  text = text.split('\n').map(function (item) {
@@ -63,7 +117,7 @@ function handleKeyDown(e) {
63
117
  } else {
64
118
  return (0, _InsertTextAtPosition.insertTextAtPosition)(target, space);
65
119
  }
66
- } else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d+.\s/.test(currentLineStr))) {
120
+ } else if (e.keyCode === 13 && e.code.toLowerCase() === 'enter' && (/^(-|\*)\s/.test(currentLineStr) || /^\d+.\s/.test(currentLineStr)) && !e.shiftKey) {
67
121
  /**
68
122
  * `13` - `Enter`
69
123
  */
@@ -72,15 +126,39 @@ function handleKeyDown(e) {
72
126
  if (currentLineStr.startsWith('*')) {
73
127
  startStr = '\n* ';
74
128
  }
75
- if (currentLineStr.startsWith('- [ ]')) {
129
+ if (currentLineStr.startsWith('- [ ]') || currentLineStr.startsWith('- [X]') || currentLineStr.startsWith('- [x]')) {
76
130
  startStr = '\n- [ ] ';
77
- } else if (currentLineStr.startsWith('- [X]')) {
78
- startStr = '\n- [X] ';
79
131
  }
80
132
  if (/^\d+.\s/.test(currentLineStr)) {
81
133
  startStr = "\n".concat(parseInt(currentLineStr) + 1, ". ");
82
134
  }
83
135
  return (0, _InsertTextAtPosition.insertTextAtPosition)(target, startStr);
136
+ } else if (e.code && e.code.toLowerCase() === 'keyd' && e.ctrlKey) {
137
+ // Duplicate lines
138
+ stopPropagation(e);
139
+ var selection = {
140
+ start: target.selectionStart,
141
+ end: target.selectionEnd
142
+ };
143
+ var savedSelection = selection;
144
+ selection = (0, _markdownUtils.selectLine)({
145
+ text: target.value,
146
+ selection: selection
147
+ });
148
+ var textToDuplicate = target.value.slice(selection.start, selection.end);
149
+ textArea.setSelectionRange({
150
+ start: selection.end,
151
+ end: selection.end
152
+ });
153
+ (0, _InsertTextAtPosition.insertTextAtPosition)(target, "\n".concat(textToDuplicate));
154
+ textArea.setSelectionRange({
155
+ start: savedSelection.start,
156
+ end: savedSelection.end
157
+ });
158
+ } else if (e.code && e.code.toLowerCase() === 'arrowup' && e.altKey) {
159
+ handleLineMove(e, -1);
160
+ } else if (e.code && e.code.toLowerCase() === 'arrowdown' && e.altKey) {
161
+ handleLineMove(e, 1);
84
162
  }
85
163
  }
86
164
  module.exports = exports.default;
package/lib/index.js CHANGED
@@ -83,5 +83,4 @@ Object.keys(_Context).forEach(function (key) {
83
83
  }
84
84
  });
85
85
  });
86
- var _default = _Editor["default"];
87
- exports["default"] = _default;
86
+ var _default = exports["default"] = _Editor["default"];
@@ -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