@uiw/react-md-editor 4.0.10 → 4.1.0

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 (64) hide show
  1. package/README.md +39 -4
  2. package/common.d.ts +17 -0
  3. package/dist/mdeditor.css +105 -110
  4. package/dist/mdeditor.js +7122 -9557
  5. package/dist/mdeditor.min.css +1 -1
  6. package/dist/mdeditor.min.js +1 -1
  7. package/dist/mdeditor.min.js.LICENSE.txt +2 -2
  8. package/esm/Editor.common.d.ts +5 -0
  9. package/esm/Editor.common.js +7 -0
  10. package/esm/Editor.d.ts +4 -11
  11. package/esm/Editor.factory.d.ts +14 -0
  12. package/esm/Editor.factory.js +270 -0
  13. package/esm/Editor.js +5 -261
  14. package/esm/Editor.nohighlight.d.ts +4 -11
  15. package/esm/Editor.nohighlight.js +5 -261
  16. package/esm/components/TextArea/Markdown.common.d.ts +5 -0
  17. package/esm/components/TextArea/Markdown.common.js +59 -0
  18. package/esm/components/TextArea/factory.d.ts +33 -0
  19. package/esm/components/TextArea/factory.js +105 -0
  20. package/esm/components/TextArea/index.common.d.ts +3 -0
  21. package/esm/components/TextArea/index.common.js +6 -0
  22. package/esm/components/TextArea/index.d.ts +3 -27
  23. package/esm/components/TextArea/index.js +5 -100
  24. package/esm/components/TextArea/index.nohighlight.d.ts +3 -27
  25. package/esm/components/TextArea/index.nohighlight.js +2 -93
  26. package/esm/index.common.d.ts +16 -0
  27. package/esm/index.common.js +16 -0
  28. package/esm/index.css +0 -1
  29. package/esm/react-markdown-preview.common.d.ts +4 -0
  30. package/lib/Editor.common.d.ts +5 -0
  31. package/lib/Editor.common.js +15 -0
  32. package/lib/Editor.d.ts +4 -11
  33. package/lib/Editor.factory.d.ts +14 -0
  34. package/lib/Editor.factory.js +333 -0
  35. package/lib/Editor.js +4 -318
  36. package/lib/Editor.nohighlight.d.ts +4 -11
  37. package/lib/Editor.nohighlight.js +4 -318
  38. package/lib/components/TextArea/Markdown.common.d.ts +5 -0
  39. package/lib/components/TextArea/Markdown.common.js +68 -0
  40. package/lib/components/TextArea/factory.d.ts +33 -0
  41. package/lib/components/TextArea/factory.js +109 -0
  42. package/lib/components/TextArea/index.common.d.ts +3 -0
  43. package/lib/components/TextArea/index.common.js +14 -0
  44. package/lib/components/TextArea/index.d.ts +3 -27
  45. package/lib/components/TextArea/index.js +6 -98
  46. package/lib/components/TextArea/index.nohighlight.d.ts +3 -27
  47. package/lib/components/TextArea/index.nohighlight.js +3 -92
  48. package/lib/index.common.d.ts +16 -0
  49. package/lib/index.common.js +123 -0
  50. package/lib/react-markdown-preview.common.d.ts +4 -0
  51. package/markdown-editor.css +0 -1
  52. package/nohighlight.d.ts +2 -0
  53. package/package.json +8 -2
  54. package/src/Editor.common.tsx +7 -0
  55. package/src/Editor.factory.tsx +286 -0
  56. package/src/Editor.nohighlight.tsx +3 -271
  57. package/src/Editor.tsx +3 -271
  58. package/src/components/TextArea/Markdown.common.tsx +49 -0
  59. package/src/components/TextArea/factory.tsx +120 -0
  60. package/src/components/TextArea/index.common.tsx +6 -0
  61. package/src/components/TextArea/index.nohighlight.tsx +3 -108
  62. package/src/components/TextArea/index.tsx +3 -110
  63. package/src/index.common.tsx +19 -0
  64. package/src/react-markdown-preview.common.d.ts +4 -0
@@ -1,329 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
- var _react = _interopRequireWildcard(require("react"));
13
8
  var _nohighlight = _interopRequireDefault(require("@uiw/react-markdown-preview/nohighlight"));
14
9
  var _index = _interopRequireDefault(require("./components/TextArea/index.nohighlight"));
15
- var _Toolbar = require("./components/Toolbar/");
16
- var _DragBar = _interopRequireDefault(require("./components/DragBar/"));
17
- var _commands = require("./commands/");
18
- var _Context = require("./Context");
19
- var _jsxRuntime = require("react/jsx-runtime");
20
- var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "autoFocusEnd", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
21
- function setGroupPopFalse() {
22
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
- Object.keys(data).forEach(function (keyname) {
24
- data[keyname] = false;
25
- });
26
- return data;
27
- }
28
- var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) {
29
- var _ref = props || {},
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
- direction = _ref.direction,
38
- _ref$extraCommands = _ref.extraCommands,
39
- extraCommands = _ref$extraCommands === void 0 ? (0, _commands.getExtraCommands)() : _ref$extraCommands,
40
- _ref$height = _ref.height,
41
- height = _ref$height === void 0 ? 200 : _ref$height,
42
- _ref$enableScroll = _ref.enableScroll,
43
- enableScroll = _ref$enableScroll === void 0 ? true : _ref$enableScroll,
44
- _ref$visibleDragbar = _ref.visibleDragbar,
45
- visibleDragbar = _ref$visibleDragbar === void 0 ? typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true : _ref$visibleDragbar,
46
- _ref$highlightEnable = _ref.highlightEnable,
47
- highlightEnable = _ref$highlightEnable === void 0 ? true : _ref$highlightEnable,
48
- _ref$preview = _ref.preview,
49
- previewType = _ref$preview === void 0 ? 'live' : _ref$preview,
50
- _ref$fullscreen = _ref.fullscreen,
51
- fullscreen = _ref$fullscreen === void 0 ? false : _ref$fullscreen,
52
- _ref$overflow = _ref.overflow,
53
- overflow = _ref$overflow === void 0 ? true : _ref$overflow,
54
- _ref$previewOptions = _ref.previewOptions,
55
- previewOptions = _ref$previewOptions === void 0 ? {} : _ref$previewOptions,
56
- textareaProps = _ref.textareaProps,
57
- _ref$maxHeight = _ref.maxHeight,
58
- maxHeight = _ref$maxHeight === void 0 ? 1200 : _ref$maxHeight,
59
- _ref$minHeight = _ref.minHeight,
60
- minHeight = _ref$minHeight === void 0 ? 100 : _ref$minHeight,
61
- autoFocus = _ref.autoFocus,
62
- _ref$autoFocusEnd = _ref.autoFocusEnd,
63
- autoFocusEnd = _ref$autoFocusEnd === void 0 ? false : _ref$autoFocusEnd,
64
- _ref$tabSize = _ref.tabSize,
65
- tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
66
- _ref$defaultTabEnable = _ref.defaultTabEnable,
67
- defaultTabEnable = _ref$defaultTabEnable === void 0 ? false : _ref$defaultTabEnable,
68
- onChange = _ref.onChange,
69
- onStatistics = _ref.onStatistics,
70
- onHeightChange = _ref.onHeightChange,
71
- hideToolbar = _ref.hideToolbar,
72
- _ref$toolbarBottom = _ref.toolbarBottom,
73
- toolbarBottom = _ref$toolbarBottom === void 0 ? false : _ref$toolbarBottom,
74
- components = _ref.components,
75
- renderTextarea = _ref.renderTextarea,
76
- other = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
77
- var cmds = commands.map(function (item) {
78
- return commandsFilter ? commandsFilter(item, false) : item;
79
- }).filter(Boolean);
80
- var extraCmds = extraCommands.map(function (item) {
81
- return commandsFilter ? commandsFilter(item, true) : item;
82
- }).filter(Boolean);
83
- var _useReducer = (0, _react.useReducer)(_Context.reducer, {
84
- markdown: propsValue,
85
- preview: previewType,
86
- components: components,
87
- height: height,
88
- minHeight: minHeight,
89
- highlightEnable: highlightEnable,
90
- tabSize: tabSize,
91
- defaultTabEnable: defaultTabEnable,
92
- scrollTop: 0,
93
- scrollTopPreview: 0,
94
- commands: cmds,
95
- extraCommands: extraCmds,
96
- fullscreen: fullscreen,
97
- barPopup: {}
98
- }),
99
- _useReducer2 = (0, _slicedToArray2["default"])(_useReducer, 2),
100
- state = _useReducer2[0],
101
- dispatch = _useReducer2[1];
102
- var container = (0, _react.useRef)(null);
103
- var previewRef = (0, _react.useRef)(null);
104
- var enableScrollRef = (0, _react.useRef)(enableScroll);
105
- (0, _react.useImperativeHandle)(ref, function () {
106
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
107
- container: container.current,
108
- dispatch: dispatch
109
- });
110
- });
111
- (0, _react.useMemo)(function () {
112
- return enableScrollRef.current = enableScroll;
113
- }, [enableScroll]);
114
- (0, _react.useEffect)(function () {
115
- var stateInit = {};
116
- if (container.current) {
117
- stateInit.container = container.current || undefined;
118
- }
119
- stateInit.markdown = propsValue || '';
120
- stateInit.barPopup = {};
121
- if (dispatch) {
122
- dispatch((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), stateInit));
123
- }
124
- // eslint-disable-next-line react-hooks/exhaustive-deps
125
- }, []);
126
- var cls = [className, 'wmde-markdown-var', direction ? "".concat(prefixCls, "-").concat(direction) : null, prefixCls, state.preview ? "".concat(prefixCls, "-show-").concat(state.preview) : null, state.fullscreen ? "".concat(prefixCls, "-fullscreen") : null].filter(Boolean).join(' ').trim();
127
- (0, _react.useMemo)(function () {
128
- return propsValue !== state.markdown && dispatch({
129
- markdown: propsValue || ''
130
- });
131
- }, [propsValue, state.markdown]);
132
- // eslint-disable-next-line react-hooks/exhaustive-deps
133
- (0, _react.useMemo)(function () {
134
- return previewType !== state.preview && dispatch({
135
- preview: previewType
136
- });
137
- }, [previewType]);
138
- // eslint-disable-next-line react-hooks/exhaustive-deps
139
- (0, _react.useMemo)(function () {
140
- return tabSize !== state.tabSize && dispatch({
141
- tabSize: tabSize
142
- });
143
- }, [tabSize]);
144
- (0, _react.useMemo)(function () {
145
- return highlightEnable !== state.highlightEnable && dispatch({
146
- highlightEnable: highlightEnable
147
- });
148
- },
149
- // eslint-disable-next-line react-hooks/exhaustive-deps
150
- [highlightEnable]);
151
- // eslint-disable-next-line react-hooks/exhaustive-deps
152
- (0, _react.useMemo)(function () {
153
- return autoFocus !== state.autoFocus && dispatch({
154
- autoFocus: autoFocus
155
- });
156
- }, [autoFocus]);
157
- (0, _react.useMemo)(function () {
158
- return autoFocusEnd !== state.autoFocusEnd && dispatch({
159
- autoFocusEnd: autoFocusEnd
160
- });
161
- }, [autoFocusEnd]);
162
- (0, _react.useMemo)(function () {
163
- return fullscreen !== state.fullscreen && dispatch({
164
- fullscreen: fullscreen
165
- });
166
- },
167
- // eslint-disable-next-line react-hooks/exhaustive-deps
168
- [fullscreen]);
169
- // eslint-disable-next-line react-hooks/exhaustive-deps
170
- (0, _react.useMemo)(function () {
171
- return height !== state.height && dispatch({
172
- height: height
173
- });
174
- }, [height]);
175
- (0, _react.useMemo)(function () {
176
- return height !== state.height && onHeightChange && onHeightChange(state.height, height, state);
177
- }, [height, onHeightChange, state]);
178
- // eslint-disable-next-line react-hooks/exhaustive-deps
179
- (0, _react.useMemo)(function () {
180
- return commands !== state.commands && dispatch({
181
- commands: cmds
182
- });
183
- }, [props.commands]);
184
- // eslint-disable-next-line react-hooks/exhaustive-deps
185
- (0, _react.useMemo)(function () {
186
- return extraCommands !== state.extraCommands && dispatch({
187
- extraCommands: extraCmds
188
- });
189
- }, [props.extraCommands]);
190
- var textareaDomRef = (0, _react.useRef)();
191
- var active = (0, _react.useRef)('preview');
192
- var initScroll = (0, _react.useRef)(false);
193
- (0, _react.useMemo)(function () {
194
- textareaDomRef.current = state.textareaWarp;
195
- if (state.textareaWarp) {
196
- state.textareaWarp.addEventListener('mouseover', function () {
197
- active.current = 'text';
198
- });
199
- state.textareaWarp.addEventListener('mouseleave', function () {
200
- active.current = 'preview';
201
- });
202
- }
203
- }, [state.textareaWarp]);
204
- var handleScroll = function handleScroll(e, type) {
205
- if (!enableScrollRef.current) return;
206
- var textareaDom = textareaDomRef.current;
207
- var previewDom = previewRef.current ? previewRef.current : undefined;
208
- if (!initScroll.current) {
209
- active.current = type;
210
- initScroll.current = true;
211
- }
212
- if (textareaDom && previewDom) {
213
- var scale = (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);
214
- if (e.target === textareaDom && active.current === 'text') {
215
- previewDom.scrollTop = textareaDom.scrollTop / scale;
216
- }
217
- if (e.target === previewDom && active.current === 'preview') {
218
- textareaDom.scrollTop = previewDom.scrollTop * scale;
219
- }
220
- var scrollTop = 0;
221
- if (active.current === 'text') {
222
- scrollTop = textareaDom.scrollTop || 0;
223
- } else if (active.current === 'preview') {
224
- scrollTop = previewDom.scrollTop || 0;
225
- }
226
- dispatch({
227
- scrollTop: scrollTop
228
- });
229
- }
230
- };
231
- var previewClassName = "".concat(prefixCls, "-preview ").concat(previewOptions.className || '');
232
- var handlePreviewScroll = function handlePreviewScroll(e) {
233
- return handleScroll(e, 'preview');
234
- };
235
- var mdPreview = (0, _react.useMemo)(function () {
236
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
237
- ref: previewRef,
238
- className: previewClassName,
239
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_nohighlight["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, previewOptions), {}, {
240
- onScroll: handlePreviewScroll,
241
- source: state.markdown || ''
242
- }))
243
- });
244
- }, [previewClassName, previewOptions, state.markdown]);
245
- var preview = (components === null || components === void 0 ? void 0 : components.preview) && (components === null || components === void 0 ? void 0 : components.preview(state.markdown || '', state, dispatch));
246
- if (preview && /*#__PURE__*/_react["default"].isValidElement(preview)) {
247
- mdPreview = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
248
- className: previewClassName,
249
- ref: previewRef,
250
- onScroll: handlePreviewScroll,
251
- children: preview
252
- });
253
- }
254
- var containerStyle = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other.style), {}, {
255
- height: state.height || '100%'
256
- });
257
- var containerClick = function containerClick() {
258
- return dispatch({
259
- barPopup: (0, _objectSpread2["default"])({}, setGroupPopFalse(state.barPopup))
260
- });
261
- };
262
- var dragBarChange = function dragBarChange(newHeight) {
263
- return dispatch({
264
- height: newHeight
265
- });
266
- };
267
- var changeHandle = function changeHandle(evn) {
268
- onChange && onChange(evn.target.value, evn, state);
269
- if (textareaProps && textareaProps.onChange) {
270
- textareaProps.onChange(evn);
271
- }
272
- if (state.textarea && state.textarea instanceof HTMLTextAreaElement && onStatistics) {
273
- var obj = new _commands.TextAreaCommandOrchestrator(state.textarea);
274
- var objState = obj.getState() || {};
275
- onStatistics((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, objState), {}, {
276
- lineCount: evn.target.value.split('\n').length,
277
- length: evn.target.value.length
278
- }));
279
- }
280
- };
281
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Context.EditorContext.Provider, {
282
- value: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
283
- dispatch: dispatch
284
- }),
285
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
286
- ref: container,
287
- className: cls
288
- }, other), {}, {
289
- onClick: containerClick,
290
- style: containerStyle,
291
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
292
- hideToolbar: hideToolbar,
293
- toolbarBottom: toolbarBottom,
294
- prefixCls: prefixCls,
295
- overflow: overflow,
296
- placement: "top"
297
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
298
- className: "".concat(prefixCls, "-content"),
299
- children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
300
- className: "".concat(prefixCls, "-input"),
301
- prefixCls: prefixCls,
302
- autoFocus: autoFocus
303
- }, textareaProps), {}, {
304
- onChange: changeHandle,
305
- renderTextarea: (components === null || components === void 0 ? void 0 : components.textarea) || renderTextarea,
306
- onScroll: function onScroll(e) {
307
- return handleScroll(e, 'text');
308
- }
309
- })), /(live|preview)/.test(state.preview || '') && mdPreview]
310
- }), visibleDragbar && !state.fullscreen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_DragBar["default"], {
311
- prefixCls: prefixCls,
312
- height: state.height,
313
- maxHeight: maxHeight,
314
- minHeight: minHeight,
315
- onChange: dragBarChange
316
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
317
- hideToolbar: hideToolbar,
318
- toolbarBottom: toolbarBottom,
319
- prefixCls: prefixCls,
320
- overflow: overflow,
321
- placement: "bottom"
322
- })]
323
- }))
324
- });
10
+ var _Editor = require("./Editor.factory");
11
+ var _default = exports["default"] = (0, _Editor.createMDEditor)({
12
+ MarkdownPreview: _nohighlight["default"],
13
+ TextArea: _index["default"]
325
14
  });
326
- var Editor = InternalMDEditor;
327
- Editor.Markdown = _nohighlight["default"];
328
- var _default = exports["default"] = Editor;
329
15
  module.exports = exports.default;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { type IProps } from '../../Types';
3
+ export interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {
4
+ }
5
+ export default function Markdown(props: MarkdownProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = Markdown;
9
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _rehype = require("rehype");
12
+ var _common = _interopRequireDefault(require("rehype-prism-plus/common"));
13
+ var _Context = require("../../Context");
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ var _templateObject;
16
+ function html2Escape(sHtml) {
17
+ return sHtml.replace(/[<&"]/g, function (c) {
18
+ return {
19
+ '<': '&lt;',
20
+ '>': '&gt;',
21
+ '&': '&amp;',
22
+ '"': '&quot;'
23
+ }[c];
24
+ });
25
+ }
26
+ function Markdown(props) {
27
+ var prefixCls = props.prefixCls;
28
+ var _useContext = (0, _react.useContext)(_Context.EditorContext),
29
+ _useContext$markdown = _useContext.markdown,
30
+ markdown = _useContext$markdown === void 0 ? '' : _useContext$markdown,
31
+ highlightEnable = _useContext.highlightEnable,
32
+ dispatch = _useContext.dispatch;
33
+ var preRef = /*#__PURE__*/_react["default"].createRef();
34
+ (0, _react.useEffect)(function () {
35
+ if (preRef.current && dispatch) {
36
+ dispatch({
37
+ textareaPre: preRef.current
38
+ });
39
+ }
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ }, []);
42
+ if (!markdown) {
43
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("pre", {
44
+ ref: preRef,
45
+ className: "".concat(prefixCls, "-text-pre wmde-markdown-color")
46
+ });
47
+ }
48
+ var mdStr = "<pre class=\"language-markdown ".concat(prefixCls, "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">").concat(html2Escape(String.raw(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["", ""])), markdown)), "\n</code></pre>");
49
+ if (highlightEnable) {
50
+ try {
51
+ mdStr = (0, _rehype.rehype)().data('settings', {
52
+ fragment: true
53
+ })
54
+ // https://github.com/uiwjs/react-md-editor/issues/593
55
+ // @ts-ignore
56
+ .use(_common["default"], {
57
+ ignoreMissing: true
58
+ }).processSync(mdStr).toString();
59
+ } catch (error) {}
60
+ }
61
+ return /*#__PURE__*/_react["default"].createElement('div', {
62
+ className: 'wmde-markdown-color',
63
+ dangerouslySetInnerHTML: {
64
+ __html: mdStr || ''
65
+ }
66
+ });
67
+ }
68
+ module.exports = exports.default;
@@ -0,0 +1,33 @@
1
+ import React, { JSX } from 'react';
2
+ import { type ContextStore, type ExecuteCommandState } from '../../Context';
3
+ import { type TextAreaProps } from './Textarea';
4
+ import { type IProps } from '../../Types';
5
+ import { TextAreaCommandOrchestrator, type ICommand } from '../../commands/';
6
+ import './index.less';
7
+ export type RenderTextareaHandle = {
8
+ dispatch: ContextStore['dispatch'];
9
+ onChange?: TextAreaProps['onChange'];
10
+ useContext?: {
11
+ commands: ContextStore['commands'];
12
+ extraCommands: ContextStore['extraCommands'];
13
+ commandOrchestrator?: TextAreaCommandOrchestrator;
14
+ };
15
+ shortcuts?: (e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState) => void;
16
+ };
17
+ export interface ITextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>, IProps {
18
+ value?: string;
19
+ onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
20
+ renderTextarea?: (props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>, opts: RenderTextareaHandle) => JSX.Element;
21
+ }
22
+ export type TextAreaRef = {
23
+ text?: HTMLTextAreaElement;
24
+ warp?: HTMLDivElement;
25
+ };
26
+ type MarkdownComponent = React.ComponentType<{
27
+ prefixCls?: string;
28
+ }>;
29
+ export declare function createTextArea(options?: {
30
+ Markdown?: MarkdownComponent;
31
+ useMinHeight?: boolean;
32
+ }): (props: ITextAreaProps) => import("react/jsx-runtime").JSX.Element;
33
+ export {};
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createTextArea = createTextArea;
9
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var _Context = require("../../Context");
13
+ var _shortcuts = _interopRequireDefault(require("./shortcuts"));
14
+ var _Textarea = _interopRequireDefault(require("./Textarea"));
15
+ var _commands = require("../../commands/");
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ var _excluded = ["prefixCls", "className", "onScroll", "renderTextarea"];
18
+ function createTextArea(options) {
19
+ var _options$useMinHeight;
20
+ var MarkdownComponent = options === null || options === void 0 ? void 0 : options.Markdown;
21
+ var useMinHeight = (_options$useMinHeight = options === null || options === void 0 ? void 0 : options.useMinHeight) !== null && _options$useMinHeight !== void 0 ? _options$useMinHeight : false;
22
+ return function TextArea(props) {
23
+ var _ref = props || {},
24
+ prefixCls = _ref.prefixCls,
25
+ className = _ref.className,
26
+ onScroll = _ref.onScroll,
27
+ renderTextarea = _ref.renderTextarea,
28
+ otherProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
29
+ var _useContext = (0, _react.useContext)(_Context.EditorContext),
30
+ markdown = _useContext.markdown,
31
+ scrollTop = _useContext.scrollTop,
32
+ commands = _useContext.commands,
33
+ minHeight = _useContext.minHeight,
34
+ highlightEnable = _useContext.highlightEnable,
35
+ extraCommands = _useContext.extraCommands,
36
+ dispatch = _useContext.dispatch;
37
+ var textRef = _react["default"].useRef(null);
38
+ var executeRef = _react["default"].useRef();
39
+ var warp = /*#__PURE__*/_react["default"].createRef();
40
+ (0, _react.useEffect)(function () {
41
+ var state = {};
42
+ if (warp.current) {
43
+ state.textareaWarp = warp.current || undefined;
44
+ warp.current.scrollTop = scrollTop || 0;
45
+ }
46
+ if (dispatch) {
47
+ dispatch((0, _objectSpread2["default"])({}, state));
48
+ }
49
+ // eslint-disable-next-line react-hooks/exhaustive-deps
50
+ }, []);
51
+ (0, _react.useEffect)(function () {
52
+ if (textRef.current && dispatch) {
53
+ var commandOrchestrator = new _commands.TextAreaCommandOrchestrator(textRef.current);
54
+ executeRef.current = commandOrchestrator;
55
+ dispatch({
56
+ textarea: textRef.current,
57
+ commandOrchestrator: commandOrchestrator
58
+ });
59
+ }
60
+ // eslint-disable-next-line react-hooks/exhaustive-deps
61
+ }, []);
62
+ var textStyle = MarkdownComponent && highlightEnable ? {} : {
63
+ WebkitTextFillColor: 'initial',
64
+ overflow: 'auto'
65
+ };
66
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
67
+ ref: warp,
68
+ className: "".concat(prefixCls, "-area ").concat(className || ''),
69
+ onScroll: onScroll,
70
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
71
+ className: "".concat(prefixCls, "-text"),
72
+ style: useMinHeight ? {
73
+ minHeight: minHeight
74
+ } : undefined,
75
+ children: renderTextarea ? (/*#__PURE__*/_react["default"].cloneElement(renderTextarea((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, otherProps), {}, {
76
+ value: markdown,
77
+ autoComplete: 'off',
78
+ autoCorrect: 'off',
79
+ spellCheck: 'false',
80
+ autoCapitalize: 'off',
81
+ className: "".concat(prefixCls, "-text-input"),
82
+ style: {
83
+ WebkitTextFillColor: 'inherit',
84
+ overflow: 'auto'
85
+ }
86
+ }), {
87
+ dispatch: dispatch,
88
+ onChange: otherProps.onChange,
89
+ shortcuts: _shortcuts["default"],
90
+ useContext: {
91
+ commands: commands,
92
+ extraCommands: extraCommands,
93
+ commandOrchestrator: executeRef.current
94
+ }
95
+ }), {
96
+ ref: textRef
97
+ })) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
98
+ children: [MarkdownComponent && highlightEnable && /*#__PURE__*/(0, _jsxRuntime.jsx)(MarkdownComponent, {
99
+ prefixCls: prefixCls
100
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Textarea["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
101
+ prefixCls: prefixCls
102
+ }, otherProps), {}, {
103
+ style: textStyle
104
+ }))]
105
+ })
106
+ })
107
+ });
108
+ };
109
+ }
@@ -0,0 +1,3 @@
1
+ export type { ITextAreaProps, RenderTextareaHandle, TextAreaRef } from './factory';
2
+ declare const _default: (props: import("./factory").ITextAreaProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _Markdown = _interopRequireDefault(require("./Markdown.common"));
9
+ var _factory = require("./factory");
10
+ var _default = exports["default"] = (0, _factory.createTextArea)({
11
+ Markdown: _Markdown["default"],
12
+ useMinHeight: true
13
+ });
14
+ module.exports = exports.default;
@@ -1,27 +1,3 @@
1
- import React, { JSX } from 'react';
2
- import { type ContextStore, type ExecuteCommandState } from '../../Context';
3
- import { type TextAreaProps } from './Textarea';
4
- import { type IProps } from '../../Types';
5
- import { TextAreaCommandOrchestrator, type ICommand } from '../../commands/';
6
- import './index.less';
7
- type RenderTextareaHandle = {
8
- dispatch: ContextStore['dispatch'];
9
- onChange?: TextAreaProps['onChange'];
10
- useContext?: {
11
- commands: ContextStore['commands'];
12
- extraCommands: ContextStore['extraCommands'];
13
- commandOrchestrator?: TextAreaCommandOrchestrator;
14
- };
15
- shortcuts?: (e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState) => void;
16
- };
17
- export interface ITextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>, IProps {
18
- value?: string;
19
- onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
20
- renderTextarea?: (props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>, opts: RenderTextareaHandle) => JSX.Element;
21
- }
22
- export type TextAreaRef = {
23
- text?: HTMLTextAreaElement;
24
- warp?: HTMLDivElement;
25
- };
26
- export default function TextArea(props: ITextAreaProps): import("react/jsx-runtime").JSX.Element;
27
- export {};
1
+ export type { ITextAreaProps, RenderTextareaHandle, TextAreaRef } from './factory';
2
+ declare const _default: (props: import("./factory").ITextAreaProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default _default;