@uiw/react-md-editor 3.18.3 → 3.19.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/dist/mdeditor.js +1564 -1583
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.js.map +1 -1
- package/esm/Editor.js +43 -67
- package/esm/Editor.js.map +1 -1
- package/esm/commands/bold.js +4 -4
- package/esm/commands/bold.js.map +1 -1
- package/esm/commands/code.js +8 -10
- package/esm/commands/code.js.map +2 -2
- package/esm/commands/comment.js +27 -16
- package/esm/commands/comment.js.map +2 -2
- package/esm/commands/divider.js.map +1 -1
- package/esm/commands/fullscreen.js +3 -4
- package/esm/commands/fullscreen.js.map +2 -2
- package/esm/commands/group.js +2 -4
- package/esm/commands/group.js.map +1 -1
- package/esm/commands/hr.js.map +1 -1
- package/esm/commands/image.js +6 -6
- package/esm/commands/image.js.map +2 -2
- package/esm/commands/index.d.ts +2 -2
- package/esm/commands/index.js +12 -23
- package/esm/commands/index.js.map +3 -2
- package/esm/commands/italic.js +4 -4
- package/esm/commands/italic.js.map +1 -1
- package/esm/commands/link.js +4 -4
- package/esm/commands/link.js.map +1 -1
- package/esm/commands/list.js +4 -4
- package/esm/commands/list.js.map +1 -1
- package/esm/commands/preview.js +21 -3
- package/esm/commands/preview.js.map +7 -2
- package/esm/commands/quote.js +2 -1
- package/esm/commands/quote.js.map +1 -1
- package/esm/commands/strikeThrough.js +4 -4
- package/esm/commands/strikeThrough.js.map +1 -1
- package/esm/commands/title.js.map +1 -1
- package/esm/commands/title1.js.map +1 -1
- package/esm/commands/title2.js.map +1 -1
- package/esm/commands/title3.js.map +1 -1
- package/esm/commands/title4.js.map +1 -1
- package/esm/commands/title5.js.map +1 -1
- package/esm/commands/title6.js.map +1 -1
- package/esm/components/DragBar/index.js +2 -9
- package/esm/components/DragBar/index.js.map +1 -1
- package/esm/components/TextArea/Markdown.js +2 -7
- package/esm/components/TextArea/Markdown.js.map +1 -1
- package/esm/components/TextArea/Textarea.js +8 -11
- package/esm/components/TextArea/Textarea.js.map +1 -1
- package/esm/components/TextArea/handleKeyDown.js +2 -16
- package/esm/components/TextArea/handleKeyDown.js.map +1 -1
- package/esm/components/TextArea/index.js +11 -15
- package/esm/components/TextArea/index.js.map +1 -1
- package/esm/components/TextArea/shortcuts.js +1 -17
- package/esm/components/TextArea/shortcuts.js.map +2 -2
- package/esm/components/Toolbar/Child.js +2 -1
- package/esm/components/Toolbar/Child.js.map +1 -1
- package/esm/components/Toolbar/index.js +2 -12
- package/esm/components/Toolbar/index.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/utils/InsertTextAtPosition.js +28 -34
- package/esm/utils/InsertTextAtPosition.js.map +1 -1
- package/esm/utils/markdownUtils.js +14 -23
- package/esm/utils/markdownUtils.js.map +1 -1
- package/lib/Context.js +0 -6
- package/lib/Context.js.map +1 -1
- package/lib/Editor.js +74 -114
- package/lib/Editor.js.map +1 -1
- package/lib/commands/bold.js +4 -9
- package/lib/commands/bold.js.map +1 -1
- package/lib/commands/code.js +8 -15
- package/lib/commands/code.js.map +2 -2
- package/lib/commands/comment.js +27 -19
- package/lib/commands/comment.js.map +2 -2
- package/lib/commands/divider.js.map +1 -1
- package/lib/commands/fullscreen.js +3 -8
- package/lib/commands/fullscreen.js.map +2 -2
- package/lib/commands/group.js +2 -10
- package/lib/commands/group.js.map +1 -1
- package/lib/commands/hr.js +0 -4
- package/lib/commands/hr.js.map +1 -1
- package/lib/commands/image.js +6 -11
- package/lib/commands/image.js.map +2 -2
- package/lib/commands/index.d.ts +2 -2
- package/lib/commands/index.js +10 -47
- package/lib/commands/index.js.map +4 -3
- package/lib/commands/italic.js +4 -9
- package/lib/commands/italic.js.map +1 -1
- package/lib/commands/link.js +4 -9
- package/lib/commands/link.js.map +1 -1
- package/lib/commands/list.js +4 -10
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/preview.js +21 -7
- package/lib/commands/preview.js.map +7 -2
- package/lib/commands/quote.js +2 -6
- package/lib/commands/quote.js.map +1 -1
- package/lib/commands/strikeThrough.js +4 -9
- package/lib/commands/strikeThrough.js.map +1 -1
- package/lib/commands/title.js +0 -6
- package/lib/commands/title.js.map +1 -1
- package/lib/commands/title1.js +0 -5
- package/lib/commands/title1.js.map +1 -1
- package/lib/commands/title2.js +0 -5
- package/lib/commands/title2.js.map +1 -1
- package/lib/commands/title3.js +0 -5
- package/lib/commands/title3.js.map +1 -1
- package/lib/commands/title4.js +0 -5
- package/lib/commands/title4.js.map +1 -1
- package/lib/commands/title5.js +0 -5
- package/lib/commands/title5.js.map +1 -1
- package/lib/commands/title6.js +0 -5
- package/lib/commands/title6.js.map +1 -1
- package/lib/components/DragBar/index.js +4 -15
- package/lib/components/DragBar/index.js.map +1 -1
- package/lib/components/TextArea/Markdown.js +6 -22
- package/lib/components/TextArea/Markdown.js.map +1 -1
- package/lib/components/TextArea/Textarea.js +15 -36
- package/lib/components/TextArea/Textarea.js.map +1 -1
- package/lib/components/TextArea/handleKeyDown.js +1 -18
- package/lib/components/TextArea/handleKeyDown.js.map +1 -1
- package/lib/components/TextArea/index.js +15 -37
- package/lib/components/TextArea/index.js.map +1 -1
- package/lib/components/TextArea/shortcuts.js +1 -17
- package/lib/components/TextArea/shortcuts.js.map +2 -2
- package/lib/components/Toolbar/Child.js +8 -18
- package/lib/components/Toolbar/Child.js.map +1 -1
- package/lib/components/Toolbar/index.js +14 -36
- package/lib/components/Toolbar/index.js.map +1 -1
- package/lib/index.js +0 -9
- package/lib/index.js.map +1 -1
- package/lib/utils/InsertTextAtPosition.js +28 -37
- package/lib/utils/InsertTextAtPosition.js.map +1 -1
- package/lib/utils/markdownUtils.js +17 -28
- package/lib/utils/markdownUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/code.tsx +2 -2
- package/src/commands/comment.tsx +19 -4
- package/src/commands/fullscreen.tsx +3 -2
- package/src/commands/image.tsx +1 -1
- package/src/commands/index.ts +8 -7
- package/src/commands/preview.tsx +35 -4
- package/src/components/TextArea/shortcuts.ts +2 -2
package/lib/Context.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.EditorContext = void 0;
|
|
9
8
|
exports.reducer = reducer;
|
|
10
|
-
|
|
11
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
|
-
|
|
13
10
|
var _react = _interopRequireDefault(require("react"));
|
|
14
|
-
|
|
15
11
|
function reducer(state, action) {
|
|
16
12
|
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), action);
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
var EditorContext = /*#__PURE__*/_react["default"].createContext({
|
|
20
15
|
markdown: ''
|
|
21
16
|
});
|
|
22
|
-
|
|
23
17
|
exports.EditorContext = EditorContext;
|
|
24
18
|
//# sourceMappingURL=Context.js.map
|
package/lib/Context.js.map
CHANGED
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
"sourcesContent": [
|
|
16
16
|
"import React from 'react';\nimport { ICommand, TextAreaCommandOrchestrator } from './commands';\nimport { MDEditorProps } from './Editor';\n\nexport type PreviewType = 'live' | 'edit' | 'preview';\n\nexport type ContextStore = {\n components?: MDEditorProps['components'];\n commands?: ICommand<string>[];\n extraCommands?: ICommand<string>[];\n markdown?: string;\n preview?: PreviewType;\n height?: React.CSSProperties['height'];\n fullscreen?: boolean;\n highlightEnable?: boolean;\n autoFocus?: boolean;\n textarea?: HTMLTextAreaElement;\n commandOrchestrator?: TextAreaCommandOrchestrator;\n textareaWarp?: HTMLDivElement;\n textareaPre?: HTMLPreElement;\n container?: HTMLDivElement | null;\n dispatch?: React.Dispatch<ContextStore>;\n barPopup?: Record<string, boolean>;\n scrollTop?: number;\n scrollTopPreview?: number;\n tabSize?: number;\n defaultTabEnable?: boolean;\n};\n\nexport type ExecuteCommandState = Pick<ContextStore, 'fullscreen' | 'preview' | 'highlightEnable'>;\n\nexport function reducer(state: ContextStore, action: ContextStore) {\n return { ...state, ...action };\n}\n\nexport const EditorContext = React.createContext<ContextStore>({ markdown: '' });\n"
|
|
17
17
|
],
|
|
18
|
-
"mappings": "
|
|
18
|
+
"mappings": ";;;;;;;;;AAAA;AA+BO,SAASA,OAAO,CAACC,KAAmB,EAAEC,MAAoB,EAAE;EACjE,yEAAYD,KAAK,GAAKC,MAAM;AAC9B;AAEO,IAAMC,aAAa,gBAAGC,iBAAK,CAACC,aAAa,CAAe;EAAEC,QAAQ,EAAE;AAAG,CAAC,CAAC;AAAC"
|
|
19
19
|
}
|
package/lib/Editor.js
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
|
|
5
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports["default"] = void 0;
|
|
11
|
-
|
|
12
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
-
|
|
14
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
-
|
|
16
11
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
17
|
-
|
|
18
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
19
|
-
|
|
20
13
|
var _reactMarkdownPreview = _interopRequireDefault(require("@uiw/react-markdown-preview"));
|
|
21
|
-
|
|
22
14
|
var _TextArea = _interopRequireDefault(require("./components/TextArea"));
|
|
23
|
-
|
|
24
15
|
var _Toolbar = _interopRequireDefault(require("./components/Toolbar"));
|
|
25
|
-
|
|
26
16
|
var _DragBar = _interopRequireDefault(require("./components/DragBar"));
|
|
27
|
-
|
|
28
17
|
var _commands = require("./commands");
|
|
29
|
-
|
|
30
18
|
var _Context = require("./Context");
|
|
31
|
-
|
|
32
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
|
-
|
|
34
20
|
var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "tabSize", "defaultTabEnable", "onChange", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
|
|
35
|
-
|
|
36
21
|
function setGroupPopFalse() {
|
|
37
22
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
23
|
Object.keys(data).forEach(function (keyname) {
|
|
@@ -40,79 +25,75 @@ function setGroupPopFalse() {
|
|
|
40
25
|
});
|
|
41
26
|
return data;
|
|
42
27
|
}
|
|
43
|
-
|
|
44
28
|
var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
45
29
|
var _ref = props || {},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
30
|
+
_ref$prefixCls = _ref.prefixCls,
|
|
31
|
+
prefixCls = _ref$prefixCls === void 0 ? 'w-md-editor' : _ref$prefixCls,
|
|
32
|
+
className = _ref.className,
|
|
33
|
+
propsValue = _ref.value,
|
|
34
|
+
_ref$commands = _ref.commands,
|
|
35
|
+
commands = _ref$commands === void 0 ? (0, _commands.getCommands)() : _ref$commands,
|
|
36
|
+
commandsFilter = _ref.commandsFilter,
|
|
37
|
+
_ref$extraCommands = _ref.extraCommands,
|
|
38
|
+
extraCommands = _ref$extraCommands === void 0 ? (0, _commands.getExtraCommands)() : _ref$extraCommands,
|
|
39
|
+
_ref$height = _ref.height,
|
|
40
|
+
height = _ref$height === void 0 ? 200 : _ref$height,
|
|
41
|
+
_ref$enableScroll = _ref.enableScroll,
|
|
42
|
+
enableScroll = _ref$enableScroll === void 0 ? true : _ref$enableScroll,
|
|
43
|
+
_ref$visibleDragbar = _ref.visibleDragbar,
|
|
44
|
+
visibleDragbar = _ref$visibleDragbar === void 0 ? typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true : _ref$visibleDragbar,
|
|
45
|
+
_ref$highlightEnable = _ref.highlightEnable,
|
|
46
|
+
highlightEnable = _ref$highlightEnable === void 0 ? true : _ref$highlightEnable,
|
|
47
|
+
_ref$preview = _ref.preview,
|
|
48
|
+
previewType = _ref$preview === void 0 ? 'live' : _ref$preview,
|
|
49
|
+
_ref$fullscreen = _ref.fullscreen,
|
|
50
|
+
fullscreen = _ref$fullscreen === void 0 ? false : _ref$fullscreen,
|
|
51
|
+
_ref$overflow = _ref.overflow,
|
|
52
|
+
overflow = _ref$overflow === void 0 ? true : _ref$overflow,
|
|
53
|
+
_ref$previewOptions = _ref.previewOptions,
|
|
54
|
+
previewOptions = _ref$previewOptions === void 0 ? {} : _ref$previewOptions,
|
|
55
|
+
textareaProps = _ref.textareaProps,
|
|
56
|
+
_ref$maxHeight = _ref.maxHeight,
|
|
57
|
+
maxHeight = _ref$maxHeight === void 0 ? 1200 : _ref$maxHeight,
|
|
58
|
+
_ref$minHeight = _ref.minHeight,
|
|
59
|
+
minHeight = _ref$minHeight === void 0 ? 100 : _ref$minHeight,
|
|
60
|
+
autoFocus = _ref.autoFocus,
|
|
61
|
+
_ref$tabSize = _ref.tabSize,
|
|
62
|
+
tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
|
|
63
|
+
_ref$defaultTabEnable = _ref.defaultTabEnable,
|
|
64
|
+
defaultTabEnable = _ref$defaultTabEnable === void 0 ? false : _ref$defaultTabEnable,
|
|
65
|
+
_onChange = _ref.onChange,
|
|
66
|
+
onHeightChange = _ref.onHeightChange,
|
|
67
|
+
hideToolbar = _ref.hideToolbar,
|
|
68
|
+
_ref$toolbarBottom = _ref.toolbarBottom,
|
|
69
|
+
toolbarBottom = _ref$toolbarBottom === void 0 ? false : _ref$toolbarBottom,
|
|
70
|
+
components = _ref.components,
|
|
71
|
+
renderTextarea = _ref.renderTextarea,
|
|
72
|
+
other = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
90
73
|
var cmds = commands.map(function (item) {
|
|
91
74
|
return commandsFilter ? commandsFilter(item, false) : item;
|
|
92
75
|
}).filter(Boolean);
|
|
93
76
|
var extraCmds = extraCommands.map(function (item) {
|
|
94
77
|
return commandsFilter ? commandsFilter(item, true) : item;
|
|
95
78
|
}).filter(Boolean);
|
|
96
|
-
|
|
97
79
|
var _useReducer = (0, _react.useReducer)(_Context.reducer, {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
80
|
+
markdown: propsValue,
|
|
81
|
+
preview: previewType,
|
|
82
|
+
components: components,
|
|
83
|
+
height: height,
|
|
84
|
+
highlightEnable: highlightEnable,
|
|
85
|
+
tabSize: tabSize,
|
|
86
|
+
defaultTabEnable: defaultTabEnable,
|
|
87
|
+
scrollTop: 0,
|
|
88
|
+
scrollTopPreview: 0,
|
|
89
|
+
commands: cmds,
|
|
90
|
+
extraCommands: extraCmds,
|
|
91
|
+
fullscreen: fullscreen,
|
|
92
|
+
barPopup: {}
|
|
93
|
+
}),
|
|
94
|
+
_useReducer2 = (0, _slicedToArray2["default"])(_useReducer, 2),
|
|
95
|
+
state = _useReducer2[0],
|
|
96
|
+
dispatch = _useReducer2[1];
|
|
116
97
|
var container = (0, _react.useRef)(null);
|
|
117
98
|
var previewRef = (0, _react.useRef)(null);
|
|
118
99
|
var enableScrollRef = (0, _react.useRef)(enableScroll);
|
|
@@ -124,32 +105,29 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
124
105
|
}, [enableScroll]);
|
|
125
106
|
(0, _react.useEffect)(function () {
|
|
126
107
|
var stateInit = {};
|
|
127
|
-
|
|
128
108
|
if (container.current) {
|
|
129
109
|
stateInit.container = container.current || undefined;
|
|
130
110
|
}
|
|
131
|
-
|
|
132
111
|
stateInit.markdown = propsValue || '';
|
|
133
112
|
stateInit.barPopup = {};
|
|
134
|
-
|
|
135
113
|
if (dispatch) {
|
|
136
114
|
dispatch((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), stateInit));
|
|
137
|
-
}
|
|
138
|
-
|
|
115
|
+
}
|
|
116
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
139
117
|
}, []);
|
|
140
118
|
var cls = [className, 'wmde-markdown-var', prefixCls, state.preview ? "".concat(prefixCls, "-show-").concat(state.preview) : null, state.fullscreen ? "".concat(prefixCls, "-fullscreen") : null].filter(Boolean).join(' ').trim();
|
|
141
119
|
(0, _react.useMemo)(function () {
|
|
142
120
|
return propsValue !== state.markdown && dispatch({
|
|
143
121
|
markdown: propsValue || ''
|
|
144
122
|
});
|
|
145
|
-
}, [propsValue, state.markdown]);
|
|
146
|
-
|
|
123
|
+
}, [propsValue, state.markdown]);
|
|
124
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
147
125
|
(0, _react.useMemo)(function () {
|
|
148
126
|
return previewType !== state.preview && dispatch({
|
|
149
127
|
preview: previewType
|
|
150
128
|
});
|
|
151
|
-
}, [previewType]);
|
|
152
|
-
|
|
129
|
+
}, [previewType]);
|
|
130
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
153
131
|
(0, _react.useMemo)(function () {
|
|
154
132
|
return tabSize !== state.tabSize && dispatch({
|
|
155
133
|
tabSize: tabSize
|
|
@@ -159,9 +137,10 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
159
137
|
return highlightEnable !== state.highlightEnable && dispatch({
|
|
160
138
|
highlightEnable: highlightEnable
|
|
161
139
|
});
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
|
|
140
|
+
},
|
|
141
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
142
|
+
[highlightEnable]);
|
|
143
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
165
144
|
(0, _react.useMemo)(function () {
|
|
166
145
|
return autoFocus !== state.autoFocus && dispatch({
|
|
167
146
|
autoFocus: autoFocus
|
|
@@ -171,9 +150,10 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
171
150
|
return fullscreen !== state.fullscreen && dispatch({
|
|
172
151
|
fullscreen: fullscreen
|
|
173
152
|
});
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
|
|
153
|
+
},
|
|
154
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
155
|
+
[fullscreen]);
|
|
156
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
157
|
(0, _react.useMemo)(function () {
|
|
178
158
|
return height !== state.height && dispatch({
|
|
179
159
|
height: height
|
|
@@ -187,7 +167,6 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
187
167
|
var initScroll = (0, _react.useRef)(false);
|
|
188
168
|
(0, _react.useMemo)(function () {
|
|
189
169
|
textareaDomRef.current = state.textareaWarp;
|
|
190
|
-
|
|
191
170
|
if (state.textareaWarp) {
|
|
192
171
|
state.textareaWarp.addEventListener('mouseover', function () {
|
|
193
172
|
active.current = 'text';
|
|
@@ -197,48 +176,37 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
197
176
|
});
|
|
198
177
|
}
|
|
199
178
|
}, [state.textareaWarp]);
|
|
200
|
-
|
|
201
179
|
var handleScroll = function handleScroll(e, type) {
|
|
202
180
|
if (!enableScrollRef.current) return;
|
|
203
181
|
var textareaDom = textareaDomRef.current;
|
|
204
182
|
var previewDom = previewRef.current ? previewRef.current : undefined;
|
|
205
|
-
|
|
206
183
|
if (!initScroll.current) {
|
|
207
184
|
active.current = type;
|
|
208
185
|
initScroll.current = true;
|
|
209
186
|
}
|
|
210
|
-
|
|
211
187
|
if (textareaDom && previewDom) {
|
|
212
188
|
var scale = (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);
|
|
213
|
-
|
|
214
189
|
if (e.target === textareaDom && active.current === 'text') {
|
|
215
190
|
previewDom.scrollTop = textareaDom.scrollTop / scale;
|
|
216
191
|
}
|
|
217
|
-
|
|
218
192
|
if (e.target === previewDom && active.current === 'preview') {
|
|
219
193
|
textareaDom.scrollTop = previewDom.scrollTop * scale;
|
|
220
194
|
}
|
|
221
|
-
|
|
222
195
|
var scrollTop = 0;
|
|
223
|
-
|
|
224
196
|
if (active.current === 'text') {
|
|
225
197
|
scrollTop = textareaDom.scrollTop || 0;
|
|
226
198
|
} else if (active.current === 'preview') {
|
|
227
199
|
scrollTop = previewDom.scrollTop || 0;
|
|
228
200
|
}
|
|
229
|
-
|
|
230
201
|
dispatch({
|
|
231
202
|
scrollTop: scrollTop
|
|
232
203
|
});
|
|
233
204
|
}
|
|
234
205
|
};
|
|
235
|
-
|
|
236
206
|
var previewClassName = "".concat(prefixCls, "-preview ").concat(previewOptions.className || '');
|
|
237
|
-
|
|
238
207
|
var handlePreviewScroll = function handlePreviewScroll(e) {
|
|
239
208
|
return handleScroll(e, 'preview');
|
|
240
209
|
};
|
|
241
|
-
|
|
242
210
|
var mdPreview = (0, _react.useMemo)(function () {
|
|
243
211
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
244
212
|
ref: previewRef,
|
|
@@ -250,7 +218,6 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
250
218
|
});
|
|
251
219
|
}, [previewClassName, previewOptions, state.markdown]);
|
|
252
220
|
var preview = (components === null || components === void 0 ? void 0 : components.preview) && (components === null || components === void 0 ? void 0 : components.preview(state.markdown || '', state, dispatch));
|
|
253
|
-
|
|
254
221
|
if (preview && /*#__PURE__*/_react["default"].isValidElement(preview)) {
|
|
255
222
|
mdPreview = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
256
223
|
className: previewClassName,
|
|
@@ -259,23 +226,19 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
259
226
|
children: preview
|
|
260
227
|
});
|
|
261
228
|
}
|
|
262
|
-
|
|
263
229
|
var containerStyle = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other.style), {}, {
|
|
264
230
|
height: state.height || '100%'
|
|
265
231
|
});
|
|
266
|
-
|
|
267
232
|
var containerClick = function containerClick() {
|
|
268
233
|
return dispatch({
|
|
269
234
|
barPopup: (0, _objectSpread2["default"])({}, setGroupPopFalse(state.barPopup))
|
|
270
235
|
});
|
|
271
236
|
};
|
|
272
|
-
|
|
273
237
|
var dragBarChange = function dragBarChange(newHeight) {
|
|
274
238
|
return dispatch({
|
|
275
239
|
height: newHeight
|
|
276
240
|
});
|
|
277
241
|
};
|
|
278
|
-
|
|
279
242
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Context.EditorContext.Provider, {
|
|
280
243
|
value: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
|
281
244
|
dispatch: dispatch
|
|
@@ -299,7 +262,6 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
299
262
|
}, textareaProps), {}, {
|
|
300
263
|
onChange: function onChange(evn) {
|
|
301
264
|
_onChange && _onChange(evn.target.value, evn, state);
|
|
302
|
-
|
|
303
265
|
if (textareaProps && textareaProps.onChange) {
|
|
304
266
|
textareaProps.onChange(evn);
|
|
305
267
|
}
|
|
@@ -323,9 +285,7 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
323
285
|
}))
|
|
324
286
|
});
|
|
325
287
|
};
|
|
326
|
-
|
|
327
288
|
var mdEditor = /*#__PURE__*/_react["default"].forwardRef(InternalMDEditor);
|
|
328
|
-
|
|
329
289
|
mdEditor.Markdown = _reactMarkdownPreview["default"];
|
|
330
290
|
var _default = mdEditor;
|
|
331
291
|
exports["default"] = _default;
|
package/lib/Editor.js.map
CHANGED
|
@@ -107,5 +107,5 @@
|
|
|
107
107
|
"sourcesContent": [
|
|
108
108
|
"import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties, PropsWithRef } from 'react';\nimport MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';\nimport TextArea, { ITextAreaProps } from './components/TextArea';\nimport Toolbar from './components/Toolbar';\nimport DragBar from './components/DragBar';\nimport { getCommands, getExtraCommands, ICommand } from './commands';\nimport { reducer, EditorContext, ContextStore, PreviewType } from './Context';\nimport './index.less';\n\nexport interface IProps {\n prefixCls?: string;\n className?: string;\n}\n\nexport interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {\n /**\n * The Markdown value.\n */\n value?: string;\n /**\n * Event handler for the `onChange` event.\n */\n onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;\n /**\n * editor height change listener\n */\n onHeightChange?: (value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore) => void;\n /**\n * Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.\n * it will be set to true when either the source `textarea` is focused,\n * or it has an `autofocus` attribute and no other element is focused.\n */\n autoFocus?: ITextAreaProps['autoFocus'];\n /**\n * The height of the editor.\n * ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.\n */\n height?: CSSProperties['height'];\n /**\n * Custom toolbar heigth\n * @default 29px\n *\n * @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427\n *\n */\n toolbarHeight?: number;\n /**\n * Show drag and drop tool. Set the height of the editor.\n */\n visibleDragbar?: boolean;\n /**\n * @deprecated use `visibleDragbar`\n */\n visiableDragbar?: boolean;\n /**\n * Show markdown preview.\n */\n preview?: PreviewType;\n /**\n * Full screen display editor.\n */\n fullscreen?: boolean;\n /**\n * Disable `fullscreen` setting body styles\n */\n overflow?: boolean;\n /**\n * Maximum drag height. `visibleDragbar=true`\n */\n maxHeight?: number;\n /**\n * Minimum drag height. `visibleDragbar=true`\n */\n minHeight?: number;\n /**\n * This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.\n */\n previewOptions?: Omit<MarkdownPreviewProps, 'source'>;\n /**\n * Set the `textarea` related props.\n */\n textareaProps?: ITextAreaProps;\n /**\n * Use div to replace TextArea or re-render TextArea\n * @deprecated Please use ~~`renderTextarea`~~ -> `components`\n */\n renderTextarea?: ITextAreaProps['renderTextarea'];\n /**\n * re-render element\n */\n components?: {\n /** Use div to replace TextArea or re-render TextArea */\n textarea?: ITextAreaProps['renderTextarea'];\n /**\n * Override the default command element\n * _`toolbar`_ < _`command[].render`_\n */\n toolbar?: ICommand['render'];\n /** Custom markdown preview */\n preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;\n };\n /**\n * Disable editing area code highlighting. The value is `false`, which increases the editing speed.\n * @default true\n */\n highlightEnable?: boolean;\n /**\n * The number of characters to insert when pressing tab key.\n * Default `2` spaces.\n */\n tabSize?: number;\n /**\n * If `false`, the `tab` key inserts a tab character into the textarea. If `true`, the `tab` key executes default behavior e.g. focus shifts to next element.\n */\n defaultTabEnable?: boolean;\n /**\n * You can create your own commands or reuse existing commands.\n */\n commands?: ICommand[];\n /**\n * Filter or modify your commands.\n * https://github.com/uiwjs/react-md-editor/issues/296\n */\n commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;\n /**\n * You can create your own commands or reuse existing commands.\n */\n extraCommands?: ICommand[];\n /**\n * Hide the tool bar\n */\n hideToolbar?: boolean;\n /** Whether to enable scrolling */\n enableScroll?: boolean;\n /** Toolbar on bottom */\n toolbarBottom?: boolean;\n}\n\nfunction setGroupPopFalse(data: Record<string, boolean> = {}) {\n Object.keys(data).forEach((keyname) => {\n data[keyname] = false;\n });\n return data;\n}\n\nconst InternalMDEditor = (\n props: MDEditorProps,\n ref?: ((instance: ContextStore) => void) | React.RefObject<ContextStore> | null,\n) => {\n const {\n prefixCls = 'w-md-editor',\n className,\n value: propsValue,\n commands = getCommands(),\n commandsFilter,\n extraCommands = getExtraCommands(),\n height = 200,\n enableScroll = true,\n visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,\n highlightEnable = true,\n preview: previewType = 'live',\n fullscreen = false,\n overflow = true,\n previewOptions = {},\n textareaProps,\n maxHeight = 1200,\n minHeight = 100,\n autoFocus,\n tabSize = 2,\n defaultTabEnable = false,\n onChange,\n onHeightChange,\n hideToolbar,\n toolbarBottom = false,\n components,\n renderTextarea,\n ...other\n } = props || {};\n const cmds = commands\n .map((item) => (commandsFilter ? commandsFilter(item, false) : item))\n .filter(Boolean) as ICommand[];\n const extraCmds = extraCommands\n .map((item) => (commandsFilter ? commandsFilter(item, true) : item))\n .filter(Boolean) as ICommand[];\n let [state, dispatch] = useReducer(reducer, {\n markdown: propsValue,\n preview: previewType,\n components,\n height,\n highlightEnable,\n tabSize,\n defaultTabEnable,\n scrollTop: 0,\n scrollTopPreview: 0,\n commands: cmds,\n extraCommands: extraCmds,\n fullscreen,\n barPopup: {},\n });\n const container = useRef<HTMLDivElement>(null);\n const previewRef = useRef<HTMLDivElement>(null);\n const enableScrollRef = useRef(enableScroll);\n\n useImperativeHandle(ref, () => ({ ...state }));\n useMemo(() => (enableScrollRef.current = enableScroll), [enableScroll]);\n useEffect(() => {\n const stateInit: ContextStore = {};\n if (container.current) {\n stateInit.container = container.current || undefined;\n }\n stateInit.markdown = propsValue || '';\n stateInit.barPopup = {};\n if (dispatch) {\n dispatch({ ...state, ...stateInit });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const cls = [\n className,\n 'wmde-markdown-var',\n prefixCls,\n state.preview ? `${prefixCls}-show-${state.preview}` : null,\n state.fullscreen ? `${prefixCls}-fullscreen` : null,\n ]\n .filter(Boolean)\n .join(' ')\n .trim();\n\n useMemo(\n () => propsValue !== state.markdown && dispatch({ markdown: propsValue || '' }),\n [propsValue, state.markdown],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);\n useMemo(\n () => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [highlightEnable],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);\n useMemo(\n () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [fullscreen],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => height !== state.height && dispatch({ height: height }), [height]);\n useMemo(\n () => height !== state.height && onHeightChange && onHeightChange(state.height, height, state),\n [height, onHeightChange, state],\n );\n\n const textareaDomRef = useRef<HTMLDivElement>();\n const active = useRef<'text' | 'preview'>('preview');\n const initScroll = useRef(false);\n\n useMemo(() => {\n textareaDomRef.current = state.textareaWarp;\n if (state.textareaWarp) {\n state.textareaWarp.addEventListener('mouseover', () => {\n active.current = 'text';\n });\n state.textareaWarp.addEventListener('mouseleave', () => {\n active.current = 'preview';\n });\n }\n }, [state.textareaWarp]);\n\n const handleScroll = (e: React.UIEvent<HTMLDivElement>, type: 'text' | 'preview') => {\n if (!enableScrollRef.current) return;\n const textareaDom = textareaDomRef.current;\n const previewDom = previewRef.current ? previewRef.current : undefined;\n if (!initScroll.current) {\n active.current = type;\n initScroll.current = true;\n }\n if (textareaDom && previewDom) {\n const scale =\n (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);\n if (e.target === textareaDom && active.current === 'text') {\n previewDom.scrollTop = textareaDom.scrollTop / scale;\n }\n if (e.target === previewDom && active.current === 'preview') {\n textareaDom.scrollTop = previewDom.scrollTop * scale;\n }\n let scrollTop = 0;\n if (active.current === 'text') {\n scrollTop = textareaDom.scrollTop || 0;\n } else if (active.current === 'preview') {\n scrollTop = previewDom.scrollTop || 0;\n }\n dispatch({ scrollTop });\n }\n };\n\n const previewClassName = `${prefixCls}-preview ${previewOptions.className || ''}`;\n const handlePreviewScroll = (e: React.UIEvent<HTMLDivElement, UIEvent>) => handleScroll(e, 'preview');\n let mdPreview = useMemo(\n () => (\n <div ref={previewRef} className={previewClassName}>\n <MarkdownPreview {...previewOptions} onScroll={handlePreviewScroll} source={state.markdown || ''} />\n </div>\n ),\n [previewClassName, previewOptions, state.markdown],\n );\n const preview = components?.preview && components?.preview(state.markdown || '', state, dispatch);\n if (preview && React.isValidElement(preview)) {\n mdPreview = (\n <div className={previewClassName} ref={previewRef} onScroll={handlePreviewScroll}>\n {preview}\n </div>\n );\n }\n\n const containerStyle = { ...other.style, height: state.height || '100%' };\n const containerClick = () => dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });\n const dragBarChange = (newHeight: number) => dispatch({ height: newHeight });\n\n return (\n <EditorContext.Provider value={{ ...state, dispatch }}>\n <div ref={container} className={cls} {...other} onClick={containerClick} style={containerStyle}>\n {!hideToolbar && !toolbarBottom && (\n <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />\n )}\n <div className={`${prefixCls}-content`}>\n {/(edit|live)/.test(state.preview || '') && (\n <TextArea\n className={`${prefixCls}-input`}\n prefixCls={prefixCls}\n autoFocus={autoFocus}\n {...textareaProps}\n onChange={(evn) => {\n onChange && onChange(evn.target.value, evn, state);\n if (textareaProps && textareaProps.onChange) {\n textareaProps.onChange(evn);\n }\n }}\n renderTextarea={components?.textarea || renderTextarea}\n onScroll={(e) => handleScroll(e, 'text')}\n />\n )}\n {/(live|preview)/.test(state.preview || '') && mdPreview}\n </div>\n {visibleDragbar && !state.fullscreen && (\n <DragBar\n prefixCls={prefixCls}\n height={state.height as number}\n maxHeight={maxHeight!}\n minHeight={minHeight!}\n onChange={dragBarChange}\n />\n )}\n {!hideToolbar && toolbarBottom && (\n <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />\n )}\n </div>\n </EditorContext.Provider>\n );\n};\n\ntype Editor = React.FC<PropsWithRef<MDEditorProps>> & { Markdown: typeof MarkdownPreview };\n\nconst mdEditor: Editor = React.forwardRef(InternalMDEditor) as unknown as Editor;\n\nmdEditor.Markdown = MarkdownPreview;\n\nexport default mdEditor;\n"
|
|
109
109
|
],
|
|
110
|
-
"mappings": "
|
|
110
|
+
"mappings": ";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAA8E;AAAA;AAoI9E,SAASA,gBAAgB,GAAqC;EAAA,IAApCC,IAA6B,uEAAG,CAAC,CAAC;EAC1DC,MAAM,CAACC,IAAI,CAACF,IAAI,CAAC,CAACG,OAAO,CAAC,UAACC,OAAO,EAAK;IACrCJ,IAAI,CAACI,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YAClD,IAAIzB,aAAa,IAAIA,aAAa,CAACM,QAAQ,EAAE;cAC3CN,aAAa,CAACM,QAAQ,CAAC2D,GAAG,CAAC;YAC7B;UACF,CAAE;UACF,cAAc,EAAE,CAAAvD,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEwD,QAAQ,KAAIvD,cAAe;UACvD,QAAQ,EAAE,kBAACmC,CAAC;YAAA,OAAKD,YAAY,CAACC,CAAC,EAAE,MAAM,CAAC;UAAA;QAAC,GAE5C,EACA,gBAAgB,CAACkB,IAAI,CAACvC,KAAK,CAAC9B,OAAO,IAAI,EAAE,CAAC,IAAI6D,SAAS;MAAA,EACpD,EACLhE,cAAc,IAAI,CAACiC,KAAK,CAAC5B,UAAU,iBAClC,qBAAC,mBAAO;QACN,SAAS,EAAEhB,SAAU;QACrB,MAAM,EAAE4C,KAAK,CAACnC,MAAiB;QAC/B,SAAS,EAAEW,SAAW;QACtB,SAAS,EAAEC,SAAW;QACtB,QAAQ,EAAE4D;MAAc,EAE3B,EACA,CAACtD,WAAW,IAAIC,aAAa,iBAC5B,qBAAC,mBAAO;QAAC,SAAS,EAAE5B,SAAU;QAAC,QAAQ,EAAEiB,QAAS;QAAC,aAAa,EAAEW;MAAc,EACjF;IAAA;EACG,EACiB;AAE7B,CAAC;AAID,IAAM0D,QAAgB,gBAAGV,iBAAK,CAACW,UAAU,CAAC1F,gBAAgB,CAAsB;AAEhFyF,QAAQ,CAACE,QAAQ,GAAGC,gCAAe;AAAC,eAErBH,QAAQ;AAAA;AAAA"
|
|
111
111
|
}
|
package/lib/commands/bold.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.bold = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _markdownUtils = require("../utils/markdownUtils");
|
|
13
|
-
|
|
14
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
-
|
|
16
11
|
var bold = {
|
|
17
12
|
name: 'bold',
|
|
18
13
|
keyCommand: 'bold',
|
|
@@ -38,10 +33,10 @@ var bold = {
|
|
|
38
33
|
text: state.text,
|
|
39
34
|
selection: state.selection
|
|
40
35
|
});
|
|
41
|
-
var state1 = api.setSelectionRange(newSelectionRange);
|
|
42
|
-
|
|
43
|
-
var state2 = api.replaceSelection("**".concat(state1.selectedText, "**"));
|
|
44
|
-
|
|
36
|
+
var state1 = api.setSelectionRange(newSelectionRange);
|
|
37
|
+
// Replaces the current selection with the bold mark up
|
|
38
|
+
var state2 = api.replaceSelection("**".concat(state1.selectedText, "**"));
|
|
39
|
+
// Adjust the selection to not contain the **
|
|
45
40
|
api.setSelectionRange({
|
|
46
41
|
start: state2.selection.end - 2 - state1.selectedText.length,
|
|
47
42
|
end: state2.selection.end - 2
|
package/lib/commands/bold.js.map
CHANGED
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"sourcesContent": [
|
|
32
32
|
"import React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { selectWord } from '../utils/markdownUtils';\n\nexport const bold: ICommand = {\n name: 'bold',\n keyCommand: 'bold',\n shortcuts: 'ctrlcmd+b',\n value: '**',\n buttonProps: { 'aria-label': 'Add bold text (ctrl + b)', title: 'Add bold text (ctrl + b)' },\n icon: (\n <svg role=\"img\" width=\"12\" height=\"12\" viewBox=\"0 0 384 512\">\n <path\n fill=\"currentColor\"\n d=\"M304.793 243.891c33.639-18.537 53.657-54.16 53.657-95.693 0-48.236-26.25-87.626-68.626-104.179C265.138 34.01 240.849 32 209.661 32H24c-8.837 0-16 7.163-16 16v33.049c0 8.837 7.163 16 16 16h33.113v318.53H24c-8.837 0-16 7.163-16 16V464c0 8.837 7.163 16 16 16h195.69c24.203 0 44.834-1.289 66.866-7.584C337.52 457.193 376 410.647 376 350.014c0-52.168-26.573-91.684-71.207-106.123zM142.217 100.809h67.444c16.294 0 27.536 2.019 37.525 6.717 15.828 8.479 24.906 26.502 24.906 49.446 0 35.029-20.32 56.79-53.029 56.79h-76.846V100.809zm112.642 305.475c-10.14 4.056-22.677 4.907-31.409 4.907h-81.233V281.943h84.367c39.645 0 63.057 25.38 63.057 63.057.001 28.425-13.66 52.483-34.782 61.284z\"\n />\n </svg>\n ),\n execute: (state: TextState, api: TextAreaTextApi) => {\n // Adjust the selection to encompass the whole word if the caret is inside one\n const newSelectionRange = selectWord({ text: state.text, selection: state.selection });\n const state1 = api.setSelectionRange(newSelectionRange);\n // Replaces the current selection with the bold mark up\n const state2 = api.replaceSelection(`**${state1.selectedText}**`);\n // Adjust the selection to not contain the **\n api.setSelectionRange({\n start: state2.selection.end - 2 - state1.selectedText.length,\n end: state2.selection.end - 2,\n });\n },\n};\n"
|
|
33
33
|
],
|
|
34
|
-
"mappings": "
|
|
34
|
+
"mappings": ";;;;;;;AAAA;AAEA;AAAoD;AAE7C,IAAMA,IAAc,GAAG;EAC5BC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,MAAM;EAClBC,SAAS,EAAE,WAAW;EACtBC,KAAK,EAAE,IAAI;EACXC,WAAW,EAAE;IAAE,YAAY,EAAE,0BAA0B;IAAEC,KAAK,EAAE;EAA2B,CAAC;EAC5FC,IAAI,eACF;IAAK,IAAI,EAAC,KAAK;IAAC,KAAK,EAAC,IAAI;IAAC,MAAM,EAAC,IAAI;IAAC,OAAO,EAAC,aAAa;IAAA,uBAC1D;MACE,IAAI,EAAC,cAAc;MACnB,CAAC,EAAC;IAAwqB;EAC1qB,EAEL;EACDC,OAAO,EAAE,iBAACC,KAAgB,EAAEC,GAAoB,EAAK;IACnD;IACA,IAAMC,iBAAiB,GAAG,IAAAC,yBAAU,EAAC;MAAEC,IAAI,EAAEJ,KAAK,CAACI,IAAI;MAAEC,SAAS,EAAEL,KAAK,CAACK;IAAU,CAAC,CAAC;IACtF,IAAMC,MAAM,GAAGL,GAAG,CAACM,iBAAiB,CAACL,iBAAiB,CAAC;IACvD;IACA,IAAMM,MAAM,GAAGP,GAAG,CAACQ,gBAAgB,aAAMH,MAAM,CAACI,YAAY,QAAK;IACjE;IACAT,GAAG,CAACM,iBAAiB,CAAC;MACpBI,KAAK,EAAEH,MAAM,CAACH,SAAS,CAACO,GAAG,GAAG,CAAC,GAAGN,MAAM,CAACI,YAAY,CAACG,MAAM;MAC5DD,GAAG,EAAEJ,MAAM,CAACH,SAAS,CAACO,GAAG,GAAG;IAC9B,CAAC,CAAC;EACJ;AACF,CAAC;AAAC"
|
|
35
35
|
}
|
package/lib/commands/code.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.codeBlock = exports.code = void 0;
|
|
9
|
-
|
|
10
8
|
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
9
|
var _markdownUtils = require("../utils/markdownUtils");
|
|
13
|
-
|
|
14
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
-
|
|
16
11
|
var code = {
|
|
17
12
|
name: 'code',
|
|
18
13
|
keyCommand: 'code',
|
|
@@ -23,8 +18,8 @@ var code = {
|
|
|
23
18
|
title: 'Insert code (ctrl + j)'
|
|
24
19
|
},
|
|
25
20
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
|
|
26
|
-
width: "
|
|
27
|
-
height: "
|
|
21
|
+
width: "14",
|
|
22
|
+
height: "14",
|
|
28
23
|
role: "img",
|
|
29
24
|
viewBox: "0 0 640 512",
|
|
30
25
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
|
@@ -38,22 +33,20 @@ var code = {
|
|
|
38
33
|
text: tate.text,
|
|
39
34
|
selection: tate.selection
|
|
40
35
|
});
|
|
41
|
-
var state1 = api.setSelectionRange(newSelectionRange);
|
|
42
|
-
|
|
36
|
+
var state1 = api.setSelectionRange(newSelectionRange);
|
|
37
|
+
// when there's no breaking line
|
|
43
38
|
if (state1.selectedText.indexOf('\n') === -1) {
|
|
44
|
-
api.replaceSelection("`".concat(state1.selectedText, "`"));
|
|
39
|
+
api.replaceSelection("`".concat(state1.selectedText, "`"));
|
|
40
|
+
// Adjust the selection to not contain the **
|
|
45
41
|
|
|
46
42
|
var _selectionStart = state1.selection.start + 1;
|
|
47
|
-
|
|
48
43
|
var _selectionEnd = _selectionStart + state1.selectedText.length;
|
|
49
|
-
|
|
50
44
|
api.setSelectionRange({
|
|
51
45
|
start: _selectionStart,
|
|
52
46
|
end: _selectionEnd
|
|
53
47
|
});
|
|
54
48
|
return;
|
|
55
49
|
}
|
|
56
|
-
|
|
57
50
|
var breaksBeforeCount = (0, _markdownUtils.getBreaksNeededForEmptyLineBefore)(state1.text, state1.selection.start);
|
|
58
51
|
var breaksBefore = Array(breaksBeforeCount + 1).join('\n');
|
|
59
52
|
var breaksAfterCount = (0, _markdownUtils.getBreaksNeededForEmptyLineAfter)(state1.text, state1.selection.end);
|
|
@@ -74,8 +67,8 @@ var codeBlock = {
|
|
|
74
67
|
shortcuts: 'ctrlcmd+shift+j',
|
|
75
68
|
value: '```\n```',
|
|
76
69
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
|
|
77
|
-
width: "
|
|
78
|
-
height: "
|
|
70
|
+
width: "13",
|
|
71
|
+
height: "13",
|
|
79
72
|
role: "img",
|
|
80
73
|
viewBox: "0 0 156 156",
|
|
81
74
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|