@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
@@ -26,7 +26,7 @@
26
26
  */
27
27
 
28
28
  /**!
29
- * @uiw/copy-to-clipboard v1.0.15
29
+ * @uiw/copy-to-clipboard v1.0.16
30
30
  * Copy to clipboard.
31
31
  *
32
32
  * Copyright (c) 2023 Kenny Wang
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
- import { selectWord } from '../utils/markdownUtils';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var bold = {
5
5
  name: 'bold',
6
6
  keyCommand: 'bold',
7
7
  shortcuts: 'ctrlcmd+b',
8
- value: '**{{text}}**',
8
+ prefix: '**',
9
9
  buttonProps: {
10
10
  'aria-label': 'Add bold text (ctrl + b)',
11
11
  title: 'Add bold text (ctrl + b)'
@@ -21,21 +21,17 @@ export var bold = {
21
21
  })
22
22
  }),
23
23
  execute: (state, api) => {
24
- // Adjust the selection to encompass the whole word if the caret is inside one
25
24
  var newSelectionRange = selectWord({
26
25
  text: state.text,
27
- selection: state.selection
26
+ selection: state.selection,
27
+ prefix: state.command.prefix
28
28
  });
29
29
  var state1 = api.setSelectionRange(newSelectionRange);
30
- // Replaces the current selection with the bold mark up
31
- var val = state.command.value || '';
32
- api.replaceSelection(val.replace(/({{text}})/gi, state1.selectedText));
33
- var start = state1.selection.start + val.indexOf('{{text}}');
34
- var end = state1.selection.start + val.indexOf('{{text}}') + (state1.selection.end - state1.selection.start);
35
- // Adjust the selection to not contain the **
36
- api.setSelectionRange({
37
- start,
38
- end
30
+ executeCommand({
31
+ api,
32
+ selectedText: state1.selectedText,
33
+ selection: state.selection,
34
+ prefix: state.command.prefix
39
35
  });
40
36
  }
41
37
  };
@@ -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;
@@ -1,94 +1,101 @@
1
1
  import React from 'react';
2
- import { selectWord, getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter } from '../utils/markdownUtils';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
- export var code = {
5
- name: 'code',
6
- keyCommand: 'code',
7
- shortcuts: 'ctrlcmd+j',
8
- value: '``',
4
+ export var codeBlock = {
5
+ name: 'codeBlock',
6
+ keyCommand: 'codeBlock',
7
+ shortcuts: 'ctrlcmd+shift+j',
8
+ prefix: '```',
9
9
  buttonProps: {
10
- 'aria-label': 'Insert code (ctrl + j)',
11
- title: 'Insert code (ctrl + j)'
10
+ 'aria-label': 'Insert Code Block (ctrl + shift + j)',
11
+ title: 'Insert Code Block (ctrl + shift +j)'
12
12
  },
13
13
  icon: /*#__PURE__*/_jsx("svg", {
14
- width: "14",
15
- height: "14",
14
+ width: "13",
15
+ height: "13",
16
16
  role: "img",
17
- viewBox: "0 0 640 512",
17
+ viewBox: "0 0 156 156",
18
18
  children: /*#__PURE__*/_jsx("path", {
19
19
  fill: "currentColor",
20
- 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"
20
+ 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"
21
21
  })
22
22
  }),
23
- execute: (tate, api) => {
24
- // Adjust the selection to encompass the whole word if the caret is inside one
23
+ execute: (state, api) => {
25
24
  var newSelectionRange = selectWord({
26
- text: tate.text,
27
- selection: tate.selection
25
+ text: state.text,
26
+ selection: state.selection,
27
+ prefix: '```\n',
28
+ suffix: '\n```'
28
29
  });
29
30
  var state1 = api.setSelectionRange(newSelectionRange);
30
- // when there's no breaking line
31
- if (state1.selectedText.indexOf('\n') === -1) {
32
- api.replaceSelection("`" + state1.selectedText + "`");
33
- // Adjust the selection to not contain the **
34
31
 
35
- var _selectionStart = state1.selection.start + 1;
36
- var _selectionEnd = _selectionStart + state1.selectedText.length;
37
- api.setSelectionRange({
38
- start: _selectionStart,
39
- end: _selectionEnd
40
- });
41
- return;
32
+ // Based on context determine if new line is needed or not
33
+ var prefix = '\n```\n';
34
+ var suffix = '\n```\n';
35
+ if (state1.selectedText.length >= prefix.length + suffix.length - 2 && state1.selectedText.startsWith(prefix) && state1.selectedText.endsWith(suffix)) {
36
+ // Remove code block
37
+ prefix = '```\n';
38
+ suffix = '\n```';
39
+ } else {
40
+ // Add code block
41
+ if (state1.selection.start >= 1 && state.text.slice(state1.selection.start - 1, state1.selection.start) === '\n' || state1.selection.start === 0) {
42
+ prefix = '```\n';
43
+ }
44
+ 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) {
45
+ suffix = '\n```';
46
+ }
42
47
  }
43
- var breaksBeforeCount = getBreaksNeededForEmptyLineBefore(state1.text, state1.selection.start);
44
- var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
45
- var breaksAfterCount = getBreaksNeededForEmptyLineAfter(state1.text, state1.selection.end);
46
- var breaksAfter = Array(breaksAfterCount + 1).join('\n');
47
- api.replaceSelection(breaksBefore + "```\n" + state1.selectedText + "\n```" + breaksAfter);
48
- var selectionStart = state1.selection.start + breaksBeforeCount + 4;
49
- var selectionEnd = selectionStart + state1.selectedText.length;
50
- api.setSelectionRange({
51
- start: selectionStart,
52
- end: selectionEnd
48
+ var newSelectionRange2 = selectWord({
49
+ text: state.text,
50
+ selection: state.selection,
51
+ prefix,
52
+ suffix
53
+ });
54
+ var state2 = api.setSelectionRange(newSelectionRange2);
55
+ executeCommand({
56
+ api,
57
+ selectedText: state2.selectedText,
58
+ selection: state.selection,
59
+ prefix,
60
+ suffix
53
61
  });
54
62
  }
55
63
  };
56
- export var codeBlock = {
57
- name: 'codeBlock',
58
- keyCommand: 'codeBlock',
59
- shortcuts: 'ctrlcmd+shift+j',
60
- value: '```\n```',
64
+ export var code = {
65
+ name: 'code',
66
+ keyCommand: 'code',
67
+ shortcuts: 'ctrlcmd+j',
68
+ prefix: '`',
69
+ buttonProps: {
70
+ 'aria-label': 'Insert code (ctrl + j)',
71
+ title: 'Insert code (ctrl + j)'
72
+ },
61
73
  icon: /*#__PURE__*/_jsx("svg", {
62
- width: "13",
63
- height: "13",
74
+ width: "14",
75
+ height: "14",
64
76
  role: "img",
65
- viewBox: "0 0 156 156",
77
+ viewBox: "0 0 640 512",
66
78
  children: /*#__PURE__*/_jsx("path", {
67
79
  fill: "currentColor",
68
- 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"
80
+ 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"
69
81
  })
70
82
  }),
71
- buttonProps: {
72
- 'aria-label': 'Insert Code Block (ctrl + shift + j)',
73
- title: 'Insert Code Block (ctrl + shift +j)'
74
- },
75
- execute: (tate, api) => {
76
- // Adjust the selection to encompass the whole word if the caret is inside one
77
- var newSelectionRange = selectWord({
78
- text: tate.text,
79
- selection: tate.selection
80
- });
81
- var state1 = api.setSelectionRange(newSelectionRange);
82
- var breaksBeforeCount = getBreaksNeededForEmptyLineBefore(state1.text, state1.selection.start);
83
- var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
84
- var breaksAfterCount = getBreaksNeededForEmptyLineAfter(state1.text, state1.selection.end);
85
- var breaksAfter = Array(breaksAfterCount + 1).join('\n');
86
- api.replaceSelection(breaksBefore + "```\n" + state1.selectedText + "\n```" + breaksAfter);
87
- var selectionStart = state1.selection.start + breaksBeforeCount + 4;
88
- var selectionEnd = selectionStart + state1.selectedText.length;
89
- api.setSelectionRange({
90
- start: selectionStart,
91
- end: selectionEnd
92
- });
83
+ execute: (state, api) => {
84
+ if (state.selectedText.indexOf('\n') === -1) {
85
+ var newSelectionRange = selectWord({
86
+ text: state.text,
87
+ selection: state.selection,
88
+ prefix: state.command.prefix
89
+ });
90
+ var state1 = api.setSelectionRange(newSelectionRange);
91
+ executeCommand({
92
+ api,
93
+ selectedText: state1.selectedText,
94
+ selection: state.selection,
95
+ prefix: state.command.prefix
96
+ });
97
+ } else {
98
+ codeBlock.execute(state, api);
99
+ }
93
100
  }
94
101
  };
@@ -1,31 +1,17 @@
1
1
  import React from 'react';
2
- import { selectWord } from '../utils/markdownUtils';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  import { jsxs as _jsxs } from "react/jsx-runtime";
5
5
  export var comment = {
6
6
  name: 'comment',
7
7
  keyCommand: 'comment',
8
8
  shortcuts: 'ctrlcmd+/',
9
- value: '<!-- -->',
9
+ prefix: '<!-- ',
10
+ suffix: ' -->',
10
11
  buttonProps: {
11
12
  'aria-label': 'Insert comment (ctrl + /)',
12
13
  title: 'Insert comment (ctrl + /)'
13
14
  },
14
- execute: (state, api) => {
15
- // Adjust the selection to encompass the whole word if the caret is inside one
16
- var newSelectionRange = selectWord({
17
- text: state.text,
18
- selection: state.selection
19
- });
20
- var state1 = api.setSelectionRange(newSelectionRange);
21
- // Replaces the current selection with the bold mark up
22
- var state2 = api.replaceSelection("<!-- " + state1.selectedText + " -->");
23
- // Adjust the selection to not contain the **
24
- api.setSelectionRange({
25
- start: state2.selection.end - 4 - state1.selectedText.length,
26
- end: state2.selection.end - 4
27
- });
28
- },
29
15
  icon: /*#__PURE__*/_jsx("svg", {
30
16
  height: "1em",
31
17
  width: "1em",
@@ -49,5 +35,21 @@ export var comment = {
49
35
  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"
50
36
  })]
51
37
  })
52
- })
38
+ }),
39
+ execute: (state, api) => {
40
+ var newSelectionRange = selectWord({
41
+ text: state.text,
42
+ selection: state.selection,
43
+ prefix: state.command.prefix,
44
+ suffix: state.command.suffix
45
+ });
46
+ var state1 = api.setSelectionRange(newSelectionRange);
47
+ executeCommand({
48
+ api,
49
+ selectedText: state1.selectedText,
50
+ selection: state.selection,
51
+ prefix: state.command.prefix,
52
+ suffix: state.command.suffix
53
+ });
54
+ }
53
55
  };
@@ -0,0 +1,2 @@
1
+ import { ICommand } from './';
2
+ export declare const help: ICommand;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var help = {
4
+ name: 'help',
5
+ keyCommand: 'help',
6
+ buttonProps: {
7
+ 'aria-label': 'Open help',
8
+ title: 'Open help'
9
+ },
10
+ icon: /*#__PURE__*/_jsx("svg", {
11
+ viewBox: "0 0 16 16",
12
+ width: "12px",
13
+ height: "12px",
14
+ children: /*#__PURE__*/_jsx("path", {
15
+ d: "M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8Zm.9 13H7v-1.8h1.9V13Zm-.1-3.6v.5H7.1v-.6c.2-2.1 2-1.9 1.9-3.2.1-.7-.3-1.1-1-1.1-.8 0-1.2.7-1.2 1.6H5c0-1.7 1.2-3 2.9-3 2.3 0 3 1.4 3 2.3.1 2.3-1.9 2-2.1 3.5Z",
16
+ fill: "currentColor"
17
+ })
18
+ }),
19
+ execute: () => {
20
+ window.open('https://www.markdownguide.org/basic-syntax/', '_blank', 'noreferrer');
21
+ }
22
+ };
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
2
3
  import { jsx as _jsx } from "react/jsx-runtime";
3
4
  export var hr = {
4
5
  name: 'hr',
5
6
  keyCommand: 'hr',
6
7
  shortcuts: 'ctrlcmd+h',
7
- value: '----------',
8
+ prefix: '\n\n---\n',
9
+ suffix: '',
8
10
  buttonProps: {
9
11
  'aria-label': 'Insert HR (ctrl + h)',
10
12
  title: 'Insert HR (ctrl + h)'
@@ -20,6 +22,35 @@ export var hr = {
20
22
  })
21
23
  }),
22
24
  execute: (state, api) => {
23
- api.replaceSelection(state.selectedText + "\n\n" + (state.command.value || '') + "-\n\n");
25
+ var newSelectionRange = selectWord({
26
+ text: state.text,
27
+ selection: state.selection,
28
+ prefix: state.command.prefix,
29
+ suffix: state.command.suffix
30
+ });
31
+ var state1 = api.setSelectionRange(newSelectionRange);
32
+ if (state1.selectedText.length >= state.command.prefix.length && state1.selectedText.startsWith(state.command.prefix)) {
33
+ // Remove
34
+ executeCommand({
35
+ api,
36
+ selectedText: state1.selectedText,
37
+ selection: state.selection,
38
+ prefix: state.command.prefix,
39
+ suffix: state.command.suffix
40
+ });
41
+ } else {
42
+ // Add
43
+ state1 = api.setSelectionRange({
44
+ start: state.selection.start,
45
+ end: state.selection.start
46
+ });
47
+ executeCommand({
48
+ api,
49
+ selectedText: state1.selectedText,
50
+ selection: state.selection,
51
+ prefix: state.command.prefix,
52
+ suffix: state.command.suffix
53
+ });
54
+ }
24
55
  }
25
56
  };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
- import { selectWord } from '../utils/markdownUtils';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var image = {
5
5
  name: 'image',
6
6
  keyCommand: 'image',
7
7
  shortcuts: 'ctrlcmd+k',
8
- value: '![image]({{text}})',
8
+ prefix: '![image](',
9
+ suffix: ')',
9
10
  buttonProps: {
10
11
  'aria-label': 'Add image (ctrl + k)',
11
12
  title: 'Add image (ctrl + k)'
@@ -20,24 +21,46 @@ export var image = {
20
21
  })
21
22
  }),
22
23
  execute: (state, api) => {
23
- // Select everything
24
24
  var newSelectionRange = selectWord({
25
25
  text: state.text,
26
- selection: state.selection
26
+ selection: state.selection,
27
+ prefix: state.command.prefix,
28
+ suffix: state.command.suffix
27
29
  });
28
30
  var state1 = api.setSelectionRange(newSelectionRange);
29
- // Replaces the current selection with the image
30
- var imageTemplate = state1.selectedText || 'https://example.com/your-image.png';
31
- var val = state.command.value || '';
32
- api.replaceSelection(val.replace(/({{text}})/gi, imageTemplate));
33
- var start = state1.selection.start + val.indexOf('{{text}}');
34
- var end = state1.selection.start + val.indexOf('{{text}}') + (state1.selection.end - state1.selection.start);
35
- if (!state1.selectedText) {
36
- end = end + imageTemplate.length;
31
+ if (state1.selectedText.includes('http') || state1.selectedText.includes('www')) {
32
+ executeCommand({
33
+ api,
34
+ selectedText: state1.selectedText,
35
+ selection: state.selection,
36
+ prefix: state.command.prefix,
37
+ suffix: state.command.suffix
38
+ });
39
+ } else {
40
+ newSelectionRange = selectWord({
41
+ text: state.text,
42
+ selection: state.selection,
43
+ prefix: '![',
44
+ suffix: ']()'
45
+ });
46
+ state1 = api.setSelectionRange(newSelectionRange);
47
+ if (state1.selectedText.length === 0) {
48
+ executeCommand({
49
+ api,
50
+ selectedText: state1.selectedText,
51
+ selection: state.selection,
52
+ prefix: '![image',
53
+ suffix: '](url)'
54
+ });
55
+ } else {
56
+ executeCommand({
57
+ api,
58
+ selectedText: state1.selectedText,
59
+ selection: state.selection,
60
+ prefix: '![',
61
+ suffix: ']()'
62
+ });
63
+ }
37
64
  }
38
- api.setSelectionRange({
39
- start,
40
- end
41
- });
42
65
  }
43
66
  };
@@ -21,6 +21,9 @@ import { title3 } from './title3';
21
21
  import { title4 } from './title4';
22
22
  import { title5 } from './title5';
23
23
  import { title6 } from './title6';
24
+ import { table } from './table';
25
+ import { issue } from './issue';
26
+ import { help } from './help';
24
27
  export interface CommandOrchestrator {
25
28
  executeCommand(command: ICommand): void;
26
29
  }
@@ -43,7 +46,9 @@ export interface ICommandBase<T> {
43
46
  shortcuts?: string;
44
47
  groupName?: string;
45
48
  icon?: React.ReactElement;
46
- value?: T;
49
+ value?: string;
50
+ prefix?: string;
51
+ suffix?: string;
47
52
  position?: 'right';
48
53
  liProps?: React.LiHTMLAttributes<HTMLLIElement>;
49
54
  buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | null;
@@ -88,4 +93,4 @@ declare class TextAreaCommandOrchestrator implements CommandOrchestrator {
88
93
  getState(): false | TextState;
89
94
  executeCommand(command: ICommand<string>, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState, shortcuts?: string[]): void;
90
95
  }
91
- export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, codeEdit, codeLive, codePreview, fullscreen, getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi, };
96
+ export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi, };
@@ -21,6 +21,9 @@ import { title3 } from './title3';
21
21
  import { title4 } from './title4';
22
22
  import { title5 } from './title5';
23
23
  import { title6 } from './title6';
24
+ import { table } from './table';
25
+ import { issue } from './issue';
26
+ import { help } from './help';
24
27
  var getCommands = () => [bold, italic, strikethrough, hr, group([title1, title2, title3, title4, title5, title6], {
25
28
  name: 'title',
26
29
  groupName: 'title',
@@ -28,7 +31,7 @@ var getCommands = () => [bold, italic, strikethrough, hr, group([title1, title2,
28
31
  'aria-label': 'Insert title',
29
32
  title: 'Insert title'
30
33
  }
31
- }), divider, link, quote, code, codeBlock, comment, image, divider, unorderedListCommand, orderedListCommand, checkedListCommand];
34
+ }), divider, link, quote, code, codeBlock, comment, image, table, divider, unorderedListCommand, orderedListCommand, checkedListCommand, divider, help];
32
35
  var getExtraCommands = () => [codeEdit, codeLive, codePreview, divider, fullscreen];
33
36
  function getStateFromTextArea(textArea) {
34
37
  var _textArea$value;
@@ -85,6 +88,6 @@ class TextAreaCommandOrchestrator {
85
88
  }, getStateFromTextArea(this.textArea)), this.textApi, dispatch, state, shortcuts);
86
89
  }
87
90
  }
88
- export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, codeEdit, codeLive, codePreview, fullscreen,
91
+ export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen,
89
92
  // Tool method.
90
93
  getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi };
@@ -0,0 +1,2 @@
1
+ import { ICommand } from './';
2
+ export declare const issue: ICommand;
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export var issue = {
5
+ name: 'issue',
6
+ keyCommand: 'issue',
7
+ prefix: '#',
8
+ suffix: '',
9
+ buttonProps: {
10
+ 'aria-label': 'Add issue',
11
+ title: 'Add issue'
12
+ },
13
+ icon: /*#__PURE__*/_jsx("svg", {
14
+ role: "img",
15
+ width: "12",
16
+ height: "12",
17
+ viewBox: "0 0 448 512",
18
+ children: /*#__PURE__*/_jsx("path", {
19
+ fill: "currentColor",
20
+ d: "M181.3 32.4c17.4 2.9 29.2 19.4 26.3 36.8L197.8 128h95.1l11.5-69.3c2.9-17.4 19.4-29.2 36.8-26.3s29.2 19.4 26.3 36.8L357.8 128H416c17.7 0 32 14.3 32 32s-14.3 32-32 32H347.1L325.8 320H384c17.7 0 32 14.3 32 32s-14.3 32-32 32H315.1l-11.5 69.3c-2.9 17.4-19.4 29.2-36.826.3s-29.2-19.4-26.3-36.8l9.8-58.7H155.1l-11.5 69.3c-2.9 17.4-19.4 29.2-36.8 26.3s-29.2-19.4-26.3-36.8L90.2 384H32c-17.7 0-32-14.3-32-32s14.3-32 32-32h68.9l21.3-128H64c-17.7 0-32-14.3-32-32s14.3-32 32-32h68.9l11.5-69.3c2.9-17.4 19.4-29.2 36.8-26.3zM187.1 192L165.8320h95.1l21.3-128H187.1z"
21
+ //Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com
22
+ })
23
+ }),
24
+
25
+ execute: (state, api) => {
26
+ var newSelectionRange = selectWord({
27
+ text: state.text,
28
+ selection: state.selection,
29
+ prefix: state.command.prefix,
30
+ suffix: state.command.suffix
31
+ });
32
+ var state1 = api.setSelectionRange(newSelectionRange);
33
+ executeCommand({
34
+ api,
35
+ selectedText: state1.selectedText,
36
+ selection: state.selection,
37
+ prefix: state.command.prefix,
38
+ suffix: state.command.suffix
39
+ });
40
+ }
41
+ };
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
- import { selectWord } from '../utils/markdownUtils';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var italic = {
5
5
  name: 'italic',
6
6
  keyCommand: 'italic',
7
7
  shortcuts: 'ctrlcmd+i',
8
- value: '*{{text}}*',
8
+ prefix: '*',
9
9
  buttonProps: {
10
10
  'aria-label': 'Add italic text (ctrl + i)',
11
11
  title: 'Add italic text (ctrl + i)'
@@ -22,21 +22,17 @@ export var italic = {
22
22
  })
23
23
  }),
24
24
  execute: (state, api) => {
25
- // Adjust the selection to encompass the whole word if the caret is inside one
26
25
  var newSelectionRange = selectWord({
27
26
  text: state.text,
28
- selection: state.selection
27
+ selection: state.selection,
28
+ prefix: state.command.prefix
29
29
  });
30
30
  var state1 = api.setSelectionRange(newSelectionRange);
31
- // Replaces the current selection with the bold mark up
32
- var val = state.command.value || '';
33
- api.replaceSelection(val.replace(/({{text}})/gi, state1.selectedText));
34
- var start = state1.selection.start + val.indexOf('{{text}}');
35
- var end = state1.selection.start + val.indexOf('{{text}}') + (state1.selection.end - state1.selection.start);
36
- // Adjust the selection to not contain the **
37
- api.setSelectionRange({
38
- start,
39
- end
31
+ executeCommand({
32
+ api,
33
+ selectedText: state1.selectedText,
34
+ selection: state.selection,
35
+ prefix: state.command.prefix
40
36
  });
41
37
  }
42
38
  };