@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.
- package/README.md +29 -4
- package/dist/mdeditor.css +2 -0
- package/dist/mdeditor.js +234 -237
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/dist/mdeditor.min.js.LICENSE.txt +1 -1
- package/esm/commands/bold.js +9 -13
- package/esm/commands/code.d.ts +1 -1
- package/esm/commands/code.js +75 -68
- package/esm/commands/comment.js +20 -18
- package/esm/commands/help.d.ts +2 -0
- package/esm/commands/help.js +22 -0
- package/esm/commands/hr.js +33 -2
- package/esm/commands/image.js +39 -16
- package/esm/commands/index.d.ts +7 -2
- package/esm/commands/index.js +5 -2
- package/esm/commands/issue.d.ts +2 -0
- package/esm/commands/issue.js +41 -0
- package/esm/commands/italic.js +9 -13
- package/esm/commands/link.js +40 -14
- package/esm/commands/list.d.ts +3 -10
- package/esm/commands/list.js +39 -41
- package/esm/commands/quote.js +8 -8
- package/esm/commands/strikeThrough.js +9 -13
- package/esm/commands/table.d.ts +2 -0
- package/esm/commands/table.js +57 -0
- package/esm/commands/title.d.ts +7 -1
- package/esm/commands/title.js +21 -0
- package/esm/commands/title1.js +9 -7
- package/esm/commands/title2.js +9 -7
- package/esm/commands/title3.js +9 -7
- package/esm/commands/title4.js +9 -7
- package/esm/commands/title5.js +9 -7
- package/esm/commands/title6.js +9 -7
- package/esm/components/TextArea/handleKeyDown.js +83 -5
- package/esm/utils/InsertTextAtPosition.d.ts +0 -7
- package/esm/utils/InsertTextAtPosition.js +6 -24
- package/esm/utils/markdownUtils.d.ts +23 -1
- package/esm/utils/markdownUtils.js +83 -4
- package/lib/Context.js +2 -3
- package/lib/Editor.js +1 -2
- package/lib/commands/bold.js +10 -15
- package/lib/commands/code.d.ts +1 -1
- package/lib/commands/code.js +75 -70
- package/lib/commands/comment.js +21 -20
- package/lib/commands/divider.js +2 -3
- package/lib/commands/fullscreen.js +2 -3
- package/lib/commands/group.js +2 -3
- package/lib/commands/help.d.ts +2 -0
- package/lib/commands/help.js +29 -0
- package/lib/commands/hr.js +35 -5
- package/lib/commands/image.js +40 -18
- package/lib/commands/index.d.ts +7 -2
- package/lib/commands/index.js +27 -10
- package/lib/commands/issue.d.ts +2 -0
- package/lib/commands/issue.js +48 -0
- package/lib/commands/italic.js +10 -15
- package/lib/commands/link.js +41 -16
- package/lib/commands/list.d.ts +3 -10
- package/lib/commands/list.js +43 -52
- package/lib/commands/preview.js +4 -7
- package/lib/commands/quote.js +9 -10
- package/lib/commands/strikeThrough.js +10 -15
- package/lib/commands/table.d.ts +2 -0
- package/lib/commands/table.js +64 -0
- package/lib/commands/title.d.ts +7 -1
- package/lib/commands/title.js +23 -3
- package/lib/commands/title1.js +11 -10
- package/lib/commands/title2.js +11 -10
- package/lib/commands/title3.js +11 -10
- package/lib/commands/title4.js +11 -10
- package/lib/commands/title5.js +11 -10
- package/lib/commands/title6.js +11 -10
- package/lib/components/DragBar/index.js +1 -2
- package/lib/components/TextArea/handleKeyDown.js +84 -6
- package/lib/index.js +1 -2
- package/lib/utils/InsertTextAtPosition.d.ts +0 -7
- package/lib/utils/InsertTextAtPosition.js +6 -26
- package/lib/utils/markdownUtils.d.ts +23 -1
- package/lib/utils/markdownUtils.js +84 -4
- package/package.json +4 -1
- package/src/commands/bold.tsx +13 -12
- package/src/commands/code.tsx +72 -71
- package/src/commands/comment.tsx +20 -15
- package/src/commands/help.tsx +19 -0
- package/src/commands/hr.tsx +33 -2
- package/src/commands/image.tsx +38 -15
- package/src/commands/index.ts +12 -1
- package/src/commands/issue.tsx +36 -0
- package/src/commands/italic.tsx +13 -12
- package/src/commands/link.tsx +39 -12
- package/src/commands/list.tsx +35 -53
- package/src/commands/quote.tsx +14 -13
- package/src/commands/strikeThrough.tsx +13 -12
- package/src/commands/table.tsx +52 -0
- package/src/commands/title.tsx +18 -1
- package/src/commands/title1.tsx +6 -9
- package/src/commands/title2.tsx +6 -9
- package/src/commands/title3.tsx +6 -9
- package/src/commands/title4.tsx +6 -9
- package/src/commands/title5.tsx +6 -9
- package/src/commands/title6.tsx +6 -9
- package/src/components/TextArea/handleKeyDown.tsx +54 -5
- package/src/utils/InsertTextAtPosition.ts +7 -28
- package/src/utils/markdownUtils.ts +94 -4
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.fullscreen = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
var fullscreen = {
|
|
10
|
+
var fullscreen = exports.fullscreen = {
|
|
11
11
|
name: 'fullscreen',
|
|
12
12
|
keyCommand: 'fullscreen',
|
|
13
13
|
shortcuts: 'ctrlcmd+0',
|
|
@@ -33,5 +33,4 @@ var fullscreen = {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
};
|
|
37
|
-
exports.fullscreen = fullscreen;
|
|
36
|
+
};
|
package/lib/commands/group.js
CHANGED
|
@@ -10,7 +10,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
10
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
var _react = _interopRequireDefault(require("react"));
|
|
12
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
var group = function group(arr, options) {
|
|
13
|
+
var group = exports.group = function group(arr, options) {
|
|
14
14
|
var data = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
15
15
|
children: arr,
|
|
16
16
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
|
|
@@ -34,5 +34,4 @@ var group = function group(arr, options) {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
return data;
|
|
37
|
-
};
|
|
38
|
-
exports.group = group;
|
|
37
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.help = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
var help = exports.help = {
|
|
11
|
+
name: 'help',
|
|
12
|
+
keyCommand: 'help',
|
|
13
|
+
buttonProps: {
|
|
14
|
+
'aria-label': 'Open help',
|
|
15
|
+
title: 'Open help'
|
|
16
|
+
},
|
|
17
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
|
|
18
|
+
viewBox: "0 0 16 16",
|
|
19
|
+
width: "12px",
|
|
20
|
+
height: "12px",
|
|
21
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
|
22
|
+
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",
|
|
23
|
+
fill: "currentColor"
|
|
24
|
+
})
|
|
25
|
+
}),
|
|
26
|
+
execute: function execute() {
|
|
27
|
+
window.open('https://www.markdownguide.org/basic-syntax/', '_blank', 'noreferrer');
|
|
28
|
+
}
|
|
29
|
+
};
|
package/lib/commands/hr.js
CHANGED
|
@@ -6,12 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.hr = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _markdownUtils = require("../utils/markdownUtils");
|
|
9
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
var hr = {
|
|
11
|
+
var hr = exports.hr = {
|
|
11
12
|
name: 'hr',
|
|
12
13
|
keyCommand: 'hr',
|
|
13
14
|
shortcuts: 'ctrlcmd+h',
|
|
14
|
-
|
|
15
|
+
prefix: '\n\n---\n',
|
|
16
|
+
suffix: '',
|
|
15
17
|
buttonProps: {
|
|
16
18
|
'aria-label': 'Insert HR (ctrl + h)',
|
|
17
19
|
title: 'Insert HR (ctrl + h)'
|
|
@@ -27,7 +29,35 @@ var hr = {
|
|
|
27
29
|
})
|
|
28
30
|
}),
|
|
29
31
|
execute: function execute(state, api) {
|
|
30
|
-
|
|
32
|
+
var newSelectionRange = (0, _markdownUtils.selectWord)({
|
|
33
|
+
text: state.text,
|
|
34
|
+
selection: state.selection,
|
|
35
|
+
prefix: state.command.prefix,
|
|
36
|
+
suffix: state.command.suffix
|
|
37
|
+
});
|
|
38
|
+
var state1 = api.setSelectionRange(newSelectionRange);
|
|
39
|
+
if (state1.selectedText.length >= state.command.prefix.length && state1.selectedText.startsWith(state.command.prefix)) {
|
|
40
|
+
// Remove
|
|
41
|
+
(0, _markdownUtils.executeCommand)({
|
|
42
|
+
api: api,
|
|
43
|
+
selectedText: state1.selectedText,
|
|
44
|
+
selection: state.selection,
|
|
45
|
+
prefix: state.command.prefix,
|
|
46
|
+
suffix: state.command.suffix
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
// Add
|
|
50
|
+
state1 = api.setSelectionRange({
|
|
51
|
+
start: state.selection.start,
|
|
52
|
+
end: state.selection.start
|
|
53
|
+
});
|
|
54
|
+
(0, _markdownUtils.executeCommand)({
|
|
55
|
+
api: api,
|
|
56
|
+
selectedText: state1.selectedText,
|
|
57
|
+
selection: state.selection,
|
|
58
|
+
prefix: state.command.prefix,
|
|
59
|
+
suffix: state.command.suffix
|
|
60
|
+
});
|
|
61
|
+
}
|
|
31
62
|
}
|
|
32
|
-
};
|
|
33
|
-
exports.hr = hr;
|
|
63
|
+
};
|
package/lib/commands/image.js
CHANGED
|
@@ -8,11 +8,12 @@ exports.image = 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 image = {
|
|
11
|
+
var image = exports.image = {
|
|
12
12
|
name: 'image',
|
|
13
13
|
keyCommand: 'image',
|
|
14
14
|
shortcuts: 'ctrlcmd+k',
|
|
15
|
-
|
|
15
|
+
prefix: '',
|
|
16
17
|
buttonProps: {
|
|
17
18
|
'aria-label': 'Add image (ctrl + k)',
|
|
18
19
|
title: 'Add image (ctrl + k)'
|
|
@@ -27,25 +28,46 @@ var image = {
|
|
|
27
28
|
})
|
|
28
29
|
}),
|
|
29
30
|
execute: function execute(state, api) {
|
|
30
|
-
// Select everything
|
|
31
31
|
var newSelectionRange = (0, _markdownUtils.selectWord)({
|
|
32
32
|
text: state.text,
|
|
33
|
-
selection: state.selection
|
|
33
|
+
selection: state.selection,
|
|
34
|
+
prefix: state.command.prefix,
|
|
35
|
+
suffix: state.command.suffix
|
|
34
36
|
});
|
|
35
37
|
var state1 = api.setSelectionRange(newSelectionRange);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
if (state1.selectedText.includes('http') || state1.selectedText.includes('www')) {
|
|
39
|
+
(0, _markdownUtils.executeCommand)({
|
|
40
|
+
api: api,
|
|
41
|
+
selectedText: state1.selectedText,
|
|
42
|
+
selection: state.selection,
|
|
43
|
+
prefix: state.command.prefix,
|
|
44
|
+
suffix: state.command.suffix
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
newSelectionRange = (0, _markdownUtils.selectWord)({
|
|
48
|
+
text: state.text,
|
|
49
|
+
selection: state.selection,
|
|
50
|
+
prefix: '![',
|
|
51
|
+
suffix: ']()'
|
|
52
|
+
});
|
|
53
|
+
state1 = api.setSelectionRange(newSelectionRange);
|
|
54
|
+
if (state1.selectedText.length === 0) {
|
|
55
|
+
(0, _markdownUtils.executeCommand)({
|
|
56
|
+
api: api,
|
|
57
|
+
selectedText: state1.selectedText,
|
|
58
|
+
selection: state.selection,
|
|
59
|
+
prefix: ''
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
(0, _markdownUtils.executeCommand)({
|
|
64
|
+
api: api,
|
|
65
|
+
selectedText: state1.selectedText,
|
|
66
|
+
selection: state.selection,
|
|
67
|
+
prefix: '![',
|
|
68
|
+
suffix: ']()'
|
|
69
|
+
});
|
|
70
|
+
}
|
|
44
71
|
}
|
|
45
|
-
api.setSelectionRange({
|
|
46
|
-
start: start,
|
|
47
|
-
end: end
|
|
48
|
-
});
|
|
49
72
|
}
|
|
50
|
-
};
|
|
51
|
-
exports.image = image;
|
|
73
|
+
};
|
package/lib/commands/index.d.ts
CHANGED
|
@@ -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?:
|
|
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, };
|
package/lib/commands/index.js
CHANGED
|
@@ -73,6 +73,12 @@ Object.defineProperty(exports, "group", {
|
|
|
73
73
|
return _group.group;
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
+
Object.defineProperty(exports, "help", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function get() {
|
|
79
|
+
return _help.help;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
76
82
|
Object.defineProperty(exports, "hr", {
|
|
77
83
|
enumerable: true,
|
|
78
84
|
get: function get() {
|
|
@@ -85,6 +91,12 @@ Object.defineProperty(exports, "image", {
|
|
|
85
91
|
return _image.image;
|
|
86
92
|
}
|
|
87
93
|
});
|
|
94
|
+
Object.defineProperty(exports, "issue", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function get() {
|
|
97
|
+
return _issue.issue;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
88
100
|
Object.defineProperty(exports, "italic", {
|
|
89
101
|
enumerable: true,
|
|
90
102
|
get: function get() {
|
|
@@ -115,6 +127,12 @@ Object.defineProperty(exports, "strikethrough", {
|
|
|
115
127
|
return _strikeThrough.strikethrough;
|
|
116
128
|
}
|
|
117
129
|
});
|
|
130
|
+
Object.defineProperty(exports, "table", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function get() {
|
|
133
|
+
return _table.table;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
118
136
|
Object.defineProperty(exports, "title", {
|
|
119
137
|
enumerable: true,
|
|
120
138
|
get: function get() {
|
|
@@ -189,7 +207,10 @@ var _title4 = require("./title3");
|
|
|
189
207
|
var _title5 = require("./title4");
|
|
190
208
|
var _title6 = require("./title5");
|
|
191
209
|
var _title7 = require("./title6");
|
|
192
|
-
var
|
|
210
|
+
var _table = require("./table");
|
|
211
|
+
var _issue = require("./issue");
|
|
212
|
+
var _help = require("./help");
|
|
213
|
+
var getCommands = exports.getCommands = function getCommands() {
|
|
193
214
|
return [_bold.bold, _italic.italic, _strikeThrough.strikethrough, _hr.hr, (0, _group.group)([_title2.title1, _title3.title2, _title4.title3, _title5.title4, _title6.title5, _title7.title6], {
|
|
194
215
|
name: 'title',
|
|
195
216
|
groupName: 'title',
|
|
@@ -197,13 +218,11 @@ var getCommands = function getCommands() {
|
|
|
197
218
|
'aria-label': 'Insert title',
|
|
198
219
|
title: 'Insert title'
|
|
199
220
|
}
|
|
200
|
-
}), _divider.divider, _link.link, _quote.quote, _code.code, _code.codeBlock, _comment.comment, _image.image, _divider.divider, _list.unorderedListCommand, _list.orderedListCommand, _list.checkedListCommand];
|
|
221
|
+
}), _divider.divider, _link.link, _quote.quote, _code.code, _code.codeBlock, _comment.comment, _image.image, _table.table, _divider.divider, _list.unorderedListCommand, _list.orderedListCommand, _list.checkedListCommand, _divider.divider, _help.help];
|
|
201
222
|
};
|
|
202
|
-
exports.
|
|
203
|
-
var getExtraCommands = function getExtraCommands() {
|
|
223
|
+
var getExtraCommands = exports.getExtraCommands = function getExtraCommands() {
|
|
204
224
|
return [_preview.codeEdit, _preview.codeLive, _preview.codePreview, _divider.divider, _fullscreen.fullscreen];
|
|
205
225
|
};
|
|
206
|
-
exports.getExtraCommands = getExtraCommands;
|
|
207
226
|
function getStateFromTextArea(textArea) {
|
|
208
227
|
var _textArea$value;
|
|
209
228
|
return {
|
|
@@ -215,7 +234,7 @@ function getStateFromTextArea(textArea) {
|
|
|
215
234
|
selectedText: (_textArea$value = textArea.value) === null || _textArea$value === void 0 ? void 0 : _textArea$value.slice(textArea.selectionStart, textArea.selectionEnd)
|
|
216
235
|
};
|
|
217
236
|
}
|
|
218
|
-
var TextAreaTextApi = /*#__PURE__*/function () {
|
|
237
|
+
var TextAreaTextApi = exports.TextAreaTextApi = /*#__PURE__*/function () {
|
|
219
238
|
function TextAreaTextApi(textArea) {
|
|
220
239
|
(0, _classCallCheck2["default"])(this, TextAreaTextApi);
|
|
221
240
|
(0, _defineProperty2["default"])(this, "textArea", void 0);
|
|
@@ -249,8 +268,7 @@ var TextAreaTextApi = /*#__PURE__*/function () {
|
|
|
249
268
|
}]);
|
|
250
269
|
return TextAreaTextApi;
|
|
251
270
|
}();
|
|
252
|
-
exports.
|
|
253
|
-
var TextAreaCommandOrchestrator = /*#__PURE__*/function () {
|
|
271
|
+
var TextAreaCommandOrchestrator = exports.TextAreaCommandOrchestrator = /*#__PURE__*/function () {
|
|
254
272
|
function TextAreaCommandOrchestrator(textArea) {
|
|
255
273
|
(0, _classCallCheck2["default"])(this, TextAreaCommandOrchestrator);
|
|
256
274
|
(0, _defineProperty2["default"])(this, "textArea", void 0);
|
|
@@ -273,5 +291,4 @@ var TextAreaCommandOrchestrator = /*#__PURE__*/function () {
|
|
|
273
291
|
}
|
|
274
292
|
}]);
|
|
275
293
|
return TextAreaCommandOrchestrator;
|
|
276
|
-
}();
|
|
277
|
-
exports.TextAreaCommandOrchestrator = TextAreaCommandOrchestrator;
|
|
294
|
+
}();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.issue = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _markdownUtils = require("../utils/markdownUtils");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
var issue = exports.issue = {
|
|
12
|
+
name: 'issue',
|
|
13
|
+
keyCommand: 'issue',
|
|
14
|
+
prefix: '#',
|
|
15
|
+
suffix: '',
|
|
16
|
+
buttonProps: {
|
|
17
|
+
'aria-label': 'Add issue',
|
|
18
|
+
title: 'Add issue'
|
|
19
|
+
},
|
|
20
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
|
|
21
|
+
role: "img",
|
|
22
|
+
width: "12",
|
|
23
|
+
height: "12",
|
|
24
|
+
viewBox: "0 0 448 512",
|
|
25
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
|
26
|
+
fill: "currentColor",
|
|
27
|
+
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"
|
|
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
|
+
(0, _markdownUtils.executeCommand)({
|
|
41
|
+
api: api,
|
|
42
|
+
selectedText: state1.selectedText,
|
|
43
|
+
selection: state.selection,
|
|
44
|
+
prefix: state.command.prefix,
|
|
45
|
+
suffix: state.command.suffix
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
package/lib/commands/italic.js
CHANGED
|
@@ -8,11 +8,11 @@ exports.italic = 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 italic = {
|
|
11
|
+
var italic = exports.italic = {
|
|
12
12
|
name: 'italic',
|
|
13
13
|
keyCommand: 'italic',
|
|
14
14
|
shortcuts: 'ctrlcmd+i',
|
|
15
|
-
|
|
15
|
+
prefix: '*',
|
|
16
16
|
buttonProps: {
|
|
17
17
|
'aria-label': 'Add italic text (ctrl + i)',
|
|
18
18
|
title: 'Add italic text (ctrl + i)'
|
|
@@ -29,22 +29,17 @@ var italic = {
|
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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.italic = italic;
|
|
45
|
+
};
|
package/lib/commands/link.js
CHANGED
|
@@ -8,11 +8,12 @@ exports.link = 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 link = {
|
|
11
|
+
var link = exports.link = {
|
|
12
12
|
name: 'link',
|
|
13
13
|
keyCommand: 'link',
|
|
14
14
|
shortcuts: 'ctrlcmd+l',
|
|
15
|
-
|
|
15
|
+
prefix: '[',
|
|
16
|
+
suffix: '](url)',
|
|
16
17
|
buttonProps: {
|
|
17
18
|
'aria-label': 'Add a link (ctrl + l)',
|
|
18
19
|
title: 'Add a link (ctrl + l)'
|
|
@@ -29,22 +30,46 @@ var link = {
|
|
|
29
30
|
})
|
|
30
31
|
}),
|
|
31
32
|
execute: function execute(state, api) {
|
|
32
|
-
// Adjust the selection to encompass the whole word if the caret is inside one
|
|
33
33
|
var newSelectionRange = (0, _markdownUtils.selectWord)({
|
|
34
34
|
text: state.text,
|
|
35
|
-
selection: state.selection
|
|
35
|
+
selection: state.selection,
|
|
36
|
+
prefix: state.command.prefix,
|
|
37
|
+
suffix: state.command.suffix
|
|
36
38
|
});
|
|
37
39
|
var state1 = api.setSelectionRange(newSelectionRange);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
if (state1.selectedText.includes('http') || state1.selectedText.includes('www')) {
|
|
41
|
+
newSelectionRange = (0, _markdownUtils.selectWord)({
|
|
42
|
+
text: state.text,
|
|
43
|
+
selection: state.selection,
|
|
44
|
+
prefix: '[](',
|
|
45
|
+
suffix: ')'
|
|
46
|
+
});
|
|
47
|
+
state1 = api.setSelectionRange(newSelectionRange);
|
|
48
|
+
(0, _markdownUtils.executeCommand)({
|
|
49
|
+
api: api,
|
|
50
|
+
selectedText: state1.selectedText,
|
|
51
|
+
selection: state.selection,
|
|
52
|
+
prefix: '[](',
|
|
53
|
+
suffix: ')'
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
if (state1.selectedText.length === 0) {
|
|
57
|
+
(0, _markdownUtils.executeCommand)({
|
|
58
|
+
api: api,
|
|
59
|
+
selectedText: state1.selectedText,
|
|
60
|
+
selection: state.selection,
|
|
61
|
+
prefix: '[title',
|
|
62
|
+
suffix: '](url)'
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
(0, _markdownUtils.executeCommand)({
|
|
66
|
+
api: api,
|
|
67
|
+
selectedText: state1.selectedText,
|
|
68
|
+
selection: state.selection,
|
|
69
|
+
prefix: state.command.prefix,
|
|
70
|
+
suffix: state.command.suffix
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
48
74
|
}
|
|
49
|
-
};
|
|
50
|
-
exports.link = link;
|
|
75
|
+
};
|
package/lib/commands/list.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { ICommand,
|
|
2
|
-
|
|
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;
|
package/lib/commands/list.js
CHANGED
|
@@ -4,65 +4,59 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.checkedListCommand = void 0;
|
|
8
|
-
exports.insertBeforeEachLine = insertBeforeEachLine;
|
|
9
|
-
exports.unorderedListCommand = exports.orderedListCommand = exports.makeList = void 0;
|
|
7
|
+
exports.unorderedListCommand = exports.orderedListCommand = exports.makeList = exports.checkedListCommand = void 0;
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
9
|
var _markdownUtils = require("../utils/markdownUtils");
|
|
12
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
|
|
14
|
-
* Inserts insertionString before each line
|
|
15
|
-
*/
|
|
16
|
-
function insertBeforeEachLine(selectedText, insertBefore) {
|
|
17
|
-
var lines = selectedText.split(/\n/);
|
|
18
|
-
var insertionLength = 0;
|
|
19
|
-
var modifiedText = lines.map(function (item, index) {
|
|
20
|
-
if (typeof insertBefore === 'string') {
|
|
21
|
-
insertionLength += insertBefore.length;
|
|
22
|
-
return insertBefore + item;
|
|
23
|
-
} else if (typeof insertBefore === 'function') {
|
|
24
|
-
var insertionResult = insertBefore(item, index);
|
|
25
|
-
insertionLength += insertionResult.length;
|
|
26
|
-
return insertBefore(item, index) + item;
|
|
27
|
-
}
|
|
28
|
-
throw Error('insertion is expected to be either a string or a function');
|
|
29
|
-
}).join('\n');
|
|
30
|
-
return {
|
|
31
|
-
modifiedText: modifiedText,
|
|
32
|
-
insertionLength: insertionLength
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
var makeList = function makeList(state, api, insertBefore) {
|
|
36
|
-
// Adjust the selection to encompass the whole word if the caret is inside one
|
|
11
|
+
var makeList = exports.makeList = function makeList(state, api, insertBefore) {
|
|
37
12
|
var newSelectionRange = (0, _markdownUtils.selectWord)({
|
|
38
13
|
text: state.text,
|
|
39
|
-
selection: state.selection
|
|
14
|
+
selection: state.selection,
|
|
15
|
+
prefix: state.command.prefix
|
|
40
16
|
});
|
|
41
17
|
var state1 = api.setSelectionRange(newSelectionRange);
|
|
42
18
|
var breaksBeforeCount = (0, _markdownUtils.getBreaksNeededForEmptyLineBefore)(state1.text, state1.selection.start);
|
|
43
19
|
var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
|
|
44
20
|
var breaksAfterCount = (0, _markdownUtils.getBreaksNeededForEmptyLineAfter)(state1.text, state1.selection.end);
|
|
45
21
|
var breaksAfter = Array(breaksAfterCount + 1).join('\n');
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
22
|
+
var _insertBeforeEachLine = (0, _markdownUtils.insertBeforeEachLine)(state1.selectedText, insertBefore),
|
|
23
|
+
modifiedText = _insertBeforeEachLine.modifiedText,
|
|
24
|
+
insertionLength = _insertBeforeEachLine.insertionLength;
|
|
25
|
+
if (insertionLength < 0) {
|
|
26
|
+
// Remove
|
|
27
|
+
var selectionStart = state1.selection.start;
|
|
28
|
+
var selectionEnd = state1.selection.end;
|
|
29
|
+
if (state1.selection.start > 0 && state.text.slice(state1.selection.start - 1, state1.selection.start) === '\n') {
|
|
30
|
+
selectionStart -= 1;
|
|
31
|
+
}
|
|
32
|
+
if (state1.selection.end < state.text.length - 1 && state.text.slice(state1.selection.end, state1.selection.end + 1) === '\n') {
|
|
33
|
+
selectionEnd += 1;
|
|
34
|
+
}
|
|
35
|
+
api.setSelectionRange({
|
|
36
|
+
start: selectionStart,
|
|
37
|
+
end: selectionEnd
|
|
38
|
+
});
|
|
39
|
+
api.replaceSelection("".concat(modifiedText));
|
|
40
|
+
api.setSelectionRange({
|
|
41
|
+
start: selectionStart,
|
|
42
|
+
end: selectionStart + modifiedText.length
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
// Add
|
|
46
|
+
api.replaceSelection("".concat(breaksBefore).concat(modifiedText).concat(breaksAfter));
|
|
47
|
+
var _selectionStart = state1.selection.start + breaksBeforeCount;
|
|
48
|
+
var _selectionEnd = _selectionStart + modifiedText.length;
|
|
49
|
+
api.setSelectionRange({
|
|
50
|
+
start: _selectionStart,
|
|
51
|
+
end: _selectionEnd
|
|
52
|
+
});
|
|
53
|
+
}
|
|
59
54
|
};
|
|
60
|
-
exports.
|
|
61
|
-
var unorderedListCommand = {
|
|
55
|
+
var unorderedListCommand = exports.unorderedListCommand = {
|
|
62
56
|
name: 'unordered-list',
|
|
63
57
|
keyCommand: 'list',
|
|
64
58
|
shortcuts: 'ctrl+shift+u',
|
|
65
|
-
|
|
59
|
+
prefix: '- ',
|
|
66
60
|
buttonProps: {
|
|
67
61
|
'aria-label': 'Add unordered list (ctrl + shift + u)',
|
|
68
62
|
title: 'Add unordered list (ctrl + shift + u)'
|
|
@@ -81,12 +75,11 @@ var unorderedListCommand = {
|
|
|
81
75
|
makeList(state, api, '- ');
|
|
82
76
|
}
|
|
83
77
|
};
|
|
84
|
-
exports.
|
|
85
|
-
var orderedListCommand = {
|
|
78
|
+
var orderedListCommand = exports.orderedListCommand = {
|
|
86
79
|
name: 'ordered-list',
|
|
87
80
|
keyCommand: 'list',
|
|
88
81
|
shortcuts: 'ctrl+shift+o',
|
|
89
|
-
|
|
82
|
+
prefix: '1. ',
|
|
90
83
|
buttonProps: {
|
|
91
84
|
'aria-label': 'Add ordered list (ctrl + shift + o)',
|
|
92
85
|
title: 'Add ordered list (ctrl + shift + o)'
|
|
@@ -108,12 +101,11 @@ var orderedListCommand = {
|
|
|
108
101
|
});
|
|
109
102
|
}
|
|
110
103
|
};
|
|
111
|
-
exports.
|
|
112
|
-
var checkedListCommand = {
|
|
104
|
+
var checkedListCommand = exports.checkedListCommand = {
|
|
113
105
|
name: 'checked-list',
|
|
114
106
|
keyCommand: 'list',
|
|
115
107
|
shortcuts: 'ctrl+shift+c',
|
|
116
|
-
|
|
108
|
+
prefix: '- [ ] ',
|
|
117
109
|
buttonProps: {
|
|
118
110
|
'aria-label': 'Add checked list (ctrl + shift + c)',
|
|
119
111
|
title: 'Add checked list (ctrl + shift + c)'
|
|
@@ -134,5 +126,4 @@ var checkedListCommand = {
|
|
|
134
126
|
return "- [ ] ";
|
|
135
127
|
});
|
|
136
128
|
}
|
|
137
|
-
};
|
|
138
|
-
exports.checkedListCommand = checkedListCommand;
|
|
129
|
+
};
|