@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,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 link = {
5
5
  name: 'link',
6
6
  keyCommand: 'link',
7
7
  shortcuts: 'ctrlcmd+l',
8
- value: '[{{text}}](URL Here)',
8
+ prefix: '[',
9
+ suffix: '](url)',
9
10
  buttonProps: {
10
11
  'aria-label': 'Add a link (ctrl + l)',
11
12
  title: 'Add a link (ctrl + l)'
@@ -22,21 +23,46 @@ export var link = {
22
23
  })
23
24
  }),
24
25
  execute: (state, api) => {
25
- // Adjust the selection to encompass the whole word if the caret is inside one
26
26
  var newSelectionRange = selectWord({
27
27
  text: state.text,
28
- selection: state.selection
28
+ selection: state.selection,
29
+ prefix: state.command.prefix,
30
+ suffix: state.command.suffix
29
31
  });
30
32
  var state1 = api.setSelectionRange(newSelectionRange);
31
- var val = state.command.value || '';
32
- // Replaces the current selection with the bold mark up
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
40
- });
33
+ if (state1.selectedText.includes('http') || state1.selectedText.includes('www')) {
34
+ newSelectionRange = selectWord({
35
+ text: state.text,
36
+ selection: state.selection,
37
+ prefix: '[](',
38
+ suffix: ')'
39
+ });
40
+ state1 = api.setSelectionRange(newSelectionRange);
41
+ executeCommand({
42
+ api,
43
+ selectedText: state1.selectedText,
44
+ selection: state.selection,
45
+ prefix: '[](',
46
+ suffix: ')'
47
+ });
48
+ } else {
49
+ if (state1.selectedText.length === 0) {
50
+ executeCommand({
51
+ api,
52
+ selectedText: state1.selectedText,
53
+ selection: state.selection,
54
+ prefix: '[title',
55
+ suffix: '](url)'
56
+ });
57
+ } else {
58
+ executeCommand({
59
+ api,
60
+ selectedText: state1.selectedText,
61
+ selection: state.selection,
62
+ prefix: state.command.prefix,
63
+ suffix: state.command.suffix
64
+ });
65
+ }
66
+ }
41
67
  }
42
68
  };
@@ -1,13 +1,6 @@
1
- import { ICommand, TextState, TextAreaTextApi } from './';
2
- export type AlterLineFunction = (line: string, index: number) => string;
3
- /**
4
- * Inserts insertionString before each line
5
- */
6
- export declare function insertBeforeEachLine(selectedText: string, insertBefore: string | AlterLineFunction): {
7
- modifiedText: string;
8
- insertionLength: number;
9
- };
10
- export declare const makeList: (state: TextState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction) => void;
1
+ import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { AlterLineFunction } from '../utils/markdownUtils';
3
+ export declare const makeList: (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction) => void;
11
4
  export declare const unorderedListCommand: ICommand;
12
5
  export declare const orderedListCommand: ICommand;
13
6
  export declare const checkedListCommand: ICommand;
@@ -1,58 +1,56 @@
1
1
  import React from 'react';
2
- import { selectWord, getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter } from '../utils/markdownUtils';
2
+ import { selectWord, getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter, insertBeforeEachLine } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
- /**
5
- * Inserts insertionString before each line
6
- */
7
- export function insertBeforeEachLine(selectedText, insertBefore) {
8
- var lines = selectedText.split(/\n/);
9
- var insertionLength = 0;
10
- var modifiedText = lines.map((item, index) => {
11
- if (typeof insertBefore === 'string') {
12
- insertionLength += insertBefore.length;
13
- return insertBefore + item;
14
- } else if (typeof insertBefore === 'function') {
15
- var insertionResult = insertBefore(item, index);
16
- insertionLength += insertionResult.length;
17
- return insertBefore(item, index) + item;
18
- }
19
- throw Error('insertion is expected to be either a string or a function');
20
- }).join('\n');
21
- return {
22
- modifiedText,
23
- insertionLength
24
- };
25
- }
26
4
  export var makeList = (state, api, insertBefore) => {
27
- // Adjust the selection to encompass the whole word if the caret is inside one
28
5
  var newSelectionRange = selectWord({
29
6
  text: state.text,
30
- selection: state.selection
7
+ selection: state.selection,
8
+ prefix: state.command.prefix
31
9
  });
32
10
  var state1 = api.setSelectionRange(newSelectionRange);
33
11
  var breaksBeforeCount = getBreaksNeededForEmptyLineBefore(state1.text, state1.selection.start);
34
12
  var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
35
13
  var breaksAfterCount = getBreaksNeededForEmptyLineAfter(state1.text, state1.selection.end);
36
14
  var breaksAfter = Array(breaksAfterCount + 1).join('\n');
37
- var modifiedText = insertBeforeEachLine(state1.selectedText, insertBefore);
38
- api.replaceSelection("" + breaksBefore + modifiedText.modifiedText + breaksAfter);
39
-
40
- // Specifically when the text has only one line, we can exclude the "- ", for example, from the selection
41
- var oneLinerOffset = state1.selectedText.indexOf('\n') === -1 ? modifiedText.insertionLength : 0;
42
- var selectionStart = state1.selection.start + breaksBeforeCount + oneLinerOffset;
43
- var selectionEnd = selectionStart + modifiedText.modifiedText.length - oneLinerOffset;
44
-
45
- // Adjust the selection to not contain the **
46
- api.setSelectionRange({
47
- start: selectionStart,
48
- end: selectionEnd
49
- });
15
+ var {
16
+ modifiedText,
17
+ insertionLength
18
+ } = insertBeforeEachLine(state1.selectedText, insertBefore);
19
+ if (insertionLength < 0) {
20
+ // Remove
21
+ var selectionStart = state1.selection.start;
22
+ var selectionEnd = state1.selection.end;
23
+ if (state1.selection.start > 0 && state.text.slice(state1.selection.start - 1, state1.selection.start) === '\n') {
24
+ selectionStart -= 1;
25
+ }
26
+ if (state1.selection.end < state.text.length - 1 && state.text.slice(state1.selection.end, state1.selection.end + 1) === '\n') {
27
+ selectionEnd += 1;
28
+ }
29
+ api.setSelectionRange({
30
+ start: selectionStart,
31
+ end: selectionEnd
32
+ });
33
+ api.replaceSelection("" + modifiedText);
34
+ api.setSelectionRange({
35
+ start: selectionStart,
36
+ end: selectionStart + modifiedText.length
37
+ });
38
+ } else {
39
+ // Add
40
+ api.replaceSelection("" + breaksBefore + modifiedText + breaksAfter);
41
+ var _selectionStart = state1.selection.start + breaksBeforeCount;
42
+ var _selectionEnd = _selectionStart + modifiedText.length;
43
+ api.setSelectionRange({
44
+ start: _selectionStart,
45
+ end: _selectionEnd
46
+ });
47
+ }
50
48
  };
51
49
  export var unorderedListCommand = {
52
50
  name: 'unordered-list',
53
51
  keyCommand: 'list',
54
52
  shortcuts: 'ctrl+shift+u',
55
- value: '- ',
53
+ prefix: '- ',
56
54
  buttonProps: {
57
55
  'aria-label': 'Add unordered list (ctrl + shift + u)',
58
56
  title: 'Add unordered list (ctrl + shift + u)'
@@ -75,7 +73,7 @@ export var orderedListCommand = {
75
73
  name: 'ordered-list',
76
74
  keyCommand: 'list',
77
75
  shortcuts: 'ctrl+shift+o',
78
- value: '1. ',
76
+ prefix: '1. ',
79
77
  buttonProps: {
80
78
  'aria-label': 'Add ordered list (ctrl + shift + o)',
81
79
  title: 'Add ordered list (ctrl + shift + o)'
@@ -99,7 +97,7 @@ export var checkedListCommand = {
99
97
  name: 'checked-list',
100
98
  keyCommand: 'list',
101
99
  shortcuts: 'ctrl+shift+c',
102
- value: '- [x] ',
100
+ prefix: '- [ ] ',
103
101
  buttonProps: {
104
102
  'aria-label': 'Add checked list (ctrl + shift + c)',
105
103
  title: 'Add checked list (ctrl + shift + c)'
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
- import { getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter, selectWord } from '../utils/markdownUtils';
2
+ import { getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter, selectWord, insertBeforeEachLine } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var quote = {
5
5
  name: 'quote',
6
6
  keyCommand: 'quote',
7
7
  shortcuts: 'ctrlcmd+q',
8
+ prefix: '> ',
8
9
  buttonProps: {
9
10
  'aria-label': 'Insert a quote (ctrl + q)',
10
11
  title: 'Insert a quote (ctrl + q)'
@@ -19,21 +20,20 @@ export var quote = {
19
20
  })
20
21
  }),
21
22
  execute: (state, api) => {
22
- // Adjust the selection to encompass the whole word if the caret is inside one
23
23
  var newSelectionRange = selectWord({
24
24
  text: state.text,
25
- selection: state.selection
25
+ selection: state.selection,
26
+ prefix: state.command.prefix
26
27
  });
27
28
  var state1 = api.setSelectionRange(newSelectionRange);
28
29
  var breaksBeforeCount = getBreaksNeededForEmptyLineBefore(state1.text, state1.selection.start);
29
30
  var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
30
31
  var breaksAfterCount = getBreaksNeededForEmptyLineAfter(state1.text, state1.selection.end);
31
32
  var breaksAfter = Array(breaksAfterCount + 1).join('\n');
32
-
33
- // Replaces the current selection with the quote mark up
34
- api.replaceSelection(breaksBefore + "> " + state1.selectedText + breaksAfter);
35
- var selectionStart = state1.selection.start + breaksBeforeCount + 2;
36
- var selectionEnd = selectionStart + state1.selectedText.length;
33
+ var modifiedText = insertBeforeEachLine(state1.selectedText, state.command.prefix);
34
+ api.replaceSelection("" + breaksBefore + modifiedText.modifiedText + breaksAfter);
35
+ var selectionStart = state1.selection.start + breaksBeforeCount;
36
+ var selectionEnd = selectionStart + modifiedText.modifiedText.length;
37
37
  api.setSelectionRange({
38
38
  start: selectionStart,
39
39
  end: selectionEnd
@@ -1,5 +1,5 @@
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 strikethrough = {
5
5
  name: 'strikethrough',
@@ -9,7 +9,7 @@ export var strikethrough = {
9
9
  'aria-label': 'Add strikethrough text (ctrl + shift + x)',
10
10
  title: 'Add strikethrough text (ctrl + shift + x)'
11
11
  },
12
- value: '~~{{text}}~~',
12
+ prefix: '~~',
13
13
  icon: /*#__PURE__*/_jsx("svg", {
14
14
  "data-name": "strikethrough",
15
15
  width: "12",
@@ -22,21 +22,17 @@ export var strikethrough = {
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
  };
@@ -0,0 +1,2 @@
1
+ import { ICommand } from './';
2
+ export declare const table: ICommand;
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { selectWord, executeCommand } from '../utils/markdownUtils';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export var table = {
5
+ name: 'table',
6
+ keyCommand: 'table',
7
+ prefix: '\n| Header | Header |\n|--------|--------|\n| Cell | Cell |\n| Cell | Cell |\n| Cell | Cell |\n\n',
8
+ suffix: '',
9
+ buttonProps: {
10
+ 'aria-label': 'Add table',
11
+ title: 'Add table'
12
+ },
13
+ icon: /*#__PURE__*/_jsx("svg", {
14
+ role: "img",
15
+ width: "12",
16
+ height: "12",
17
+ viewBox: "0 0 512 512",
18
+ children: /*#__PURE__*/_jsx("path", {
19
+ fill: "currentColor",
20
+ 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"
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
+ if (state1.selectedText.length >= state.command.prefix.length + state.command.suffix.length && state1.selectedText.startsWith(state.command.prefix)) {
34
+ // Remove
35
+ executeCommand({
36
+ api,
37
+ selectedText: state1.selectedText,
38
+ selection: state.selection,
39
+ prefix: state.command.prefix,
40
+ suffix: state.command.suffix
41
+ });
42
+ } else {
43
+ // Add
44
+ state1 = api.setSelectionRange({
45
+ start: state.selection.start,
46
+ end: state.selection.start
47
+ });
48
+ executeCommand({
49
+ api,
50
+ selectedText: state1.selectedText,
51
+ selection: state.selection,
52
+ prefix: state.command.prefix,
53
+ suffix: state.command.suffix
54
+ });
55
+ }
56
+ }
57
+ };
@@ -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;
@@ -1,7 +1,28 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
3
  import { title1 } from './title1';
4
+ import { selectLine, executeCommand } from '../utils/markdownUtils';
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
+ export function titleExecute(_ref) {
7
+ var {
8
+ state,
9
+ api,
10
+ prefix,
11
+ suffix = prefix
12
+ } = _ref;
13
+ var newSelectionRange = selectLine({
14
+ text: state.text,
15
+ selection: state.selection
16
+ });
17
+ var state1 = api.setSelectionRange(newSelectionRange);
18
+ executeCommand({
19
+ api,
20
+ selectedText: state1.selectedText,
21
+ selection: state.selection,
22
+ prefix,
23
+ suffix
24
+ });
25
+ }
5
26
  export var title = _extends({}, title1, {
6
27
  icon: /*#__PURE__*/_jsx("svg", {
7
28
  width: "12",
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
- import { insertAtLineStart } from '../utils/InsertTextAtPosition';
2
+ import { titleExecute } from '../commands/title';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title1 = {
5
5
  name: 'title1',
6
6
  keyCommand: 'title1',
7
7
  shortcuts: 'ctrlcmd+1',
8
- value: 'title1',
8
+ prefix: '# ',
9
+ suffix: '',
9
10
  buttonProps: {
10
11
  'aria-label': 'Insert title1 (ctrl + 1)',
11
12
  title: 'Insert title1 (ctrl + 1)'
@@ -18,10 +19,11 @@ export var title1 = {
18
19
  children: "Title 1"
19
20
  }),
20
21
  execute: (state, api) => {
21
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
22
- api.replaceSelection('# ');
23
- } else {
24
- insertAtLineStart('# ', state.selection.start, api.textArea);
25
- }
22
+ titleExecute({
23
+ state,
24
+ api,
25
+ prefix: state.command.prefix,
26
+ suffix: state.command.suffix
27
+ });
26
28
  }
27
29
  };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
- import { insertAtLineStart } from '../utils/InsertTextAtPosition';
2
+ import { titleExecute } from '../commands/title';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title2 = {
5
5
  name: 'title2',
6
6
  keyCommand: 'title2',
7
7
  shortcuts: 'ctrlcmd+2',
8
- value: 'title2',
8
+ prefix: '## ',
9
+ suffix: '',
9
10
  buttonProps: {
10
11
  'aria-label': 'Insert title2 (ctrl + 2)',
11
12
  title: 'Insert title2 (ctrl + 2)'
@@ -18,10 +19,11 @@ export var title2 = {
18
19
  children: "Title 2"
19
20
  }),
20
21
  execute: (state, api) => {
21
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
22
- api.replaceSelection('## ');
23
- } else {
24
- insertAtLineStart('## ', state.selection.start, api.textArea);
25
- }
22
+ titleExecute({
23
+ state,
24
+ api,
25
+ prefix: state.command.prefix,
26
+ suffix: state.command.suffix
27
+ });
26
28
  }
27
29
  };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
- import { insertAtLineStart } from '../utils/InsertTextAtPosition';
2
+ import { titleExecute } from '../commands/title';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title3 = {
5
5
  name: 'title3',
6
6
  keyCommand: 'title3',
7
7
  shortcuts: 'ctrlcmd+3',
8
- value: 'title3',
8
+ prefix: '### ',
9
+ suffix: '',
9
10
  buttonProps: {
10
11
  'aria-label': 'Insert title3 (ctrl + 3)',
11
12
  title: 'Insert title3 (ctrl + 3)'
@@ -18,10 +19,11 @@ export var title3 = {
18
19
  children: "Title 3"
19
20
  }),
20
21
  execute: (state, api) => {
21
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
22
- api.replaceSelection('### ');
23
- } else {
24
- insertAtLineStart('### ', state.selection.start, api.textArea);
25
- }
22
+ titleExecute({
23
+ state,
24
+ api,
25
+ prefix: state.command.prefix,
26
+ suffix: state.command.suffix
27
+ });
26
28
  }
27
29
  };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
- import { insertAtLineStart } from '../utils/InsertTextAtPosition';
2
+ import { titleExecute } from '../commands/title';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title4 = {
5
5
  name: 'title4',
6
6
  keyCommand: 'title4',
7
7
  shortcuts: 'ctrlcmd+4',
8
- value: 'title4',
8
+ prefix: '#### ',
9
+ suffix: '',
9
10
  buttonProps: {
10
11
  'aria-label': 'Insert title4 (ctrl + 4)',
11
12
  title: 'Insert title4 (ctrl + 4)'
@@ -18,10 +19,11 @@ export var title4 = {
18
19
  children: "Title 4"
19
20
  }),
20
21
  execute: (state, api) => {
21
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
22
- api.replaceSelection('#### ');
23
- } else {
24
- insertAtLineStart('#### ', state.selection.start, api.textArea);
25
- }
22
+ titleExecute({
23
+ state,
24
+ api,
25
+ prefix: state.command.prefix,
26
+ suffix: state.command.suffix
27
+ });
26
28
  }
27
29
  };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
- import { insertAtLineStart } from '../utils/InsertTextAtPosition';
2
+ import { titleExecute } from '../commands/title';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title5 = {
5
5
  name: 'title5',
6
6
  keyCommand: 'title5',
7
7
  shortcuts: 'ctrlcmd+5',
8
- value: 'title5',
8
+ prefix: '##### ',
9
+ suffix: '',
9
10
  buttonProps: {
10
11
  'aria-label': 'Insert title5 (ctrl + 5)',
11
12
  title: 'Insert title5 (ctrl + 5)'
@@ -18,10 +19,11 @@ export var title5 = {
18
19
  children: "Title 5"
19
20
  }),
20
21
  execute: (state, api) => {
21
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
22
- api.replaceSelection('##### ');
23
- } else {
24
- insertAtLineStart('##### ', state.selection.start, api.textArea);
25
- }
22
+ titleExecute({
23
+ state,
24
+ api,
25
+ prefix: state.command.prefix,
26
+ suffix: state.command.suffix
27
+ });
26
28
  }
27
29
  };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
- import { insertAtLineStart } from '../utils/InsertTextAtPosition';
2
+ import { titleExecute } from '../commands/title';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title6 = {
5
5
  name: 'title6',
6
6
  keyCommand: 'title6',
7
7
  shortcuts: 'ctrlcmd+6',
8
- value: 'title6',
8
+ prefix: '###### ',
9
+ suffix: '',
9
10
  buttonProps: {
10
11
  'aria-label': 'Insert title6 (ctrl + 6)',
11
12
  title: 'Insert title6 (ctrl + 6)'
@@ -18,10 +19,11 @@ export var title6 = {
18
19
  children: "Title 6"
19
20
  }),
20
21
  execute: (state, api) => {
21
- if (state.selection.start === 0 || /\n$/.test(state.text)) {
22
- api.replaceSelection('###### ');
23
- } else {
24
- insertAtLineStart('###### ', state.selection.start, api.textArea);
25
- }
22
+ titleExecute({
23
+ state,
24
+ api,
25
+ prefix: state.command.prefix,
26
+ suffix: state.command.suffix
27
+ });
26
28
  }
27
29
  };