@uiw/react-md-editor 4.0.11 → 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 (63) 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 +3256 -4363
  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/package.json +8 -2
  53. package/src/Editor.common.tsx +7 -0
  54. package/src/Editor.factory.tsx +286 -0
  55. package/src/Editor.nohighlight.tsx +3 -271
  56. package/src/Editor.tsx +3 -271
  57. package/src/components/TextArea/Markdown.common.tsx +49 -0
  58. package/src/components/TextArea/factory.tsx +120 -0
  59. package/src/components/TextArea/index.common.tsx +6 -0
  60. package/src/components/TextArea/index.nohighlight.tsx +3 -108
  61. package/src/components/TextArea/index.tsx +3 -110
  62. package/src/index.common.tsx +19 -0
  63. package/src/react-markdown-preview.common.d.ts +4 -0
@@ -1,263 +1,7 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- 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"];
4
- import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
5
1
  import MarkdownPreview from '@uiw/react-markdown-preview/nohighlight';
6
2
  import TextArea from './components/TextArea/index.nohighlight';
7
- import { ToolbarVisibility } from "./components/Toolbar/index.js";
8
- import DragBar from "./components/DragBar/index.js";
9
- import { getCommands, getExtraCommands, TextAreaCommandOrchestrator } from "./commands/index.js";
10
- import { reducer, EditorContext } from "./Context.js";
11
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
- function setGroupPopFalse(data) {
13
- if (data === void 0) {
14
- data = {};
15
- }
16
- Object.keys(data).forEach(keyname => {
17
- data[keyname] = false;
18
- });
19
- return data;
20
- }
21
- var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
22
- var _ref = props || {},
23
- {
24
- prefixCls = 'w-md-editor',
25
- className,
26
- value: propsValue,
27
- commands = getCommands(),
28
- commandsFilter,
29
- direction,
30
- extraCommands = getExtraCommands(),
31
- height = 200,
32
- enableScroll = true,
33
- visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,
34
- highlightEnable = true,
35
- preview: previewType = 'live',
36
- fullscreen = false,
37
- overflow = true,
38
- previewOptions = {},
39
- textareaProps,
40
- maxHeight = 1200,
41
- minHeight = 100,
42
- autoFocus,
43
- autoFocusEnd = false,
44
- tabSize = 2,
45
- defaultTabEnable = false,
46
- onChange,
47
- onStatistics,
48
- onHeightChange,
49
- hideToolbar,
50
- toolbarBottom = false,
51
- components,
52
- renderTextarea
53
- } = _ref,
54
- other = _objectWithoutPropertiesLoose(_ref, _excluded);
55
- var cmds = commands.map(item => commandsFilter ? commandsFilter(item, false) : item).filter(Boolean);
56
- var extraCmds = extraCommands.map(item => commandsFilter ? commandsFilter(item, true) : item).filter(Boolean);
57
- var [state, dispatch] = useReducer(reducer, {
58
- markdown: propsValue,
59
- preview: previewType,
60
- components,
61
- height,
62
- minHeight,
63
- highlightEnable,
64
- tabSize,
65
- defaultTabEnable,
66
- scrollTop: 0,
67
- scrollTopPreview: 0,
68
- commands: cmds,
69
- extraCommands: extraCmds,
70
- fullscreen,
71
- barPopup: {}
72
- });
73
- var container = useRef(null);
74
- var previewRef = useRef(null);
75
- var enableScrollRef = useRef(enableScroll);
76
- useImperativeHandle(ref, () => _extends({}, state, {
77
- container: container.current,
78
- dispatch
79
- }));
80
- useMemo(() => enableScrollRef.current = enableScroll, [enableScroll]);
81
- useEffect(() => {
82
- var stateInit = {};
83
- if (container.current) {
84
- stateInit.container = container.current || undefined;
85
- }
86
- stateInit.markdown = propsValue || '';
87
- stateInit.barPopup = {};
88
- if (dispatch) {
89
- dispatch(_extends({}, state, stateInit));
90
- }
91
- // eslint-disable-next-line react-hooks/exhaustive-deps
92
- }, []);
93
- var cls = [className, 'wmde-markdown-var', direction ? prefixCls + "-" + direction : null, prefixCls, state.preview ? prefixCls + "-show-" + state.preview : null, state.fullscreen ? prefixCls + "-fullscreen" : null].filter(Boolean).join(' ').trim();
94
- useMemo(() => propsValue !== state.markdown && dispatch({
95
- markdown: propsValue || ''
96
- }), [propsValue, state.markdown]);
97
- // eslint-disable-next-line react-hooks/exhaustive-deps
98
- useMemo(() => previewType !== state.preview && dispatch({
99
- preview: previewType
100
- }), [previewType]);
101
- // eslint-disable-next-line react-hooks/exhaustive-deps
102
- useMemo(() => tabSize !== state.tabSize && dispatch({
103
- tabSize
104
- }), [tabSize]);
105
- useMemo(() => highlightEnable !== state.highlightEnable && dispatch({
106
- highlightEnable
107
- }),
108
- // eslint-disable-next-line react-hooks/exhaustive-deps
109
- [highlightEnable]);
110
- // eslint-disable-next-line react-hooks/exhaustive-deps
111
- useMemo(() => autoFocus !== state.autoFocus && dispatch({
112
- autoFocus: autoFocus
113
- }), [autoFocus]);
114
- useMemo(() => autoFocusEnd !== state.autoFocusEnd && dispatch({
115
- autoFocusEnd: autoFocusEnd
116
- }), [autoFocusEnd]);
117
- useMemo(() => fullscreen !== state.fullscreen && dispatch({
118
- fullscreen: fullscreen
119
- }),
120
- // eslint-disable-next-line react-hooks/exhaustive-deps
121
- [fullscreen]);
122
- // eslint-disable-next-line react-hooks/exhaustive-deps
123
- useMemo(() => height !== state.height && dispatch({
124
- height: height
125
- }), [height]);
126
- useMemo(() => height !== state.height && onHeightChange && onHeightChange(state.height, height, state), [height, onHeightChange, state]);
127
- // eslint-disable-next-line react-hooks/exhaustive-deps
128
- useMemo(() => commands !== state.commands && dispatch({
129
- commands: cmds
130
- }), [props.commands]);
131
- // eslint-disable-next-line react-hooks/exhaustive-deps
132
- useMemo(() => extraCommands !== state.extraCommands && dispatch({
133
- extraCommands: extraCmds
134
- }), [props.extraCommands]);
135
- var textareaDomRef = useRef();
136
- var active = useRef('preview');
137
- var initScroll = useRef(false);
138
- useMemo(() => {
139
- textareaDomRef.current = state.textareaWarp;
140
- if (state.textareaWarp) {
141
- state.textareaWarp.addEventListener('mouseover', () => {
142
- active.current = 'text';
143
- });
144
- state.textareaWarp.addEventListener('mouseleave', () => {
145
- active.current = 'preview';
146
- });
147
- }
148
- }, [state.textareaWarp]);
149
- var handleScroll = (e, type) => {
150
- if (!enableScrollRef.current) return;
151
- var textareaDom = textareaDomRef.current;
152
- var previewDom = previewRef.current ? previewRef.current : undefined;
153
- if (!initScroll.current) {
154
- active.current = type;
155
- initScroll.current = true;
156
- }
157
- if (textareaDom && previewDom) {
158
- var scale = (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);
159
- if (e.target === textareaDom && active.current === 'text') {
160
- previewDom.scrollTop = textareaDom.scrollTop / scale;
161
- }
162
- if (e.target === previewDom && active.current === 'preview') {
163
- textareaDom.scrollTop = previewDom.scrollTop * scale;
164
- }
165
- var scrollTop = 0;
166
- if (active.current === 'text') {
167
- scrollTop = textareaDom.scrollTop || 0;
168
- } else if (active.current === 'preview') {
169
- scrollTop = previewDom.scrollTop || 0;
170
- }
171
- dispatch({
172
- scrollTop
173
- });
174
- }
175
- };
176
- var previewClassName = prefixCls + "-preview " + (previewOptions.className || '');
177
- var handlePreviewScroll = e => handleScroll(e, 'preview');
178
- var mdPreview = useMemo(() => /*#__PURE__*/_jsx("div", {
179
- ref: previewRef,
180
- className: previewClassName,
181
- children: /*#__PURE__*/_jsx(MarkdownPreview, _extends({}, previewOptions, {
182
- onScroll: handlePreviewScroll,
183
- source: state.markdown || ''
184
- }))
185
- }), [previewClassName, previewOptions, state.markdown]);
186
- var preview = (components == null ? void 0 : components.preview) && (components == null ? void 0 : components.preview(state.markdown || '', state, dispatch));
187
- if (preview && /*#__PURE__*/React.isValidElement(preview)) {
188
- mdPreview = /*#__PURE__*/_jsx("div", {
189
- className: previewClassName,
190
- ref: previewRef,
191
- onScroll: handlePreviewScroll,
192
- children: preview
193
- });
194
- }
195
- var containerStyle = _extends({}, other.style, {
196
- height: state.height || '100%'
197
- });
198
- var containerClick = () => dispatch({
199
- barPopup: _extends({}, setGroupPopFalse(state.barPopup))
200
- });
201
- var dragBarChange = newHeight => dispatch({
202
- height: newHeight
203
- });
204
- var changeHandle = evn => {
205
- onChange && onChange(evn.target.value, evn, state);
206
- if (textareaProps && textareaProps.onChange) {
207
- textareaProps.onChange(evn);
208
- }
209
- if (state.textarea && state.textarea instanceof HTMLTextAreaElement && onStatistics) {
210
- var obj = new TextAreaCommandOrchestrator(state.textarea);
211
- var objState = obj.getState() || {};
212
- onStatistics(_extends({}, objState, {
213
- lineCount: evn.target.value.split('\n').length,
214
- length: evn.target.value.length
215
- }));
216
- }
217
- };
218
- return /*#__PURE__*/_jsx(EditorContext.Provider, {
219
- value: _extends({}, state, {
220
- dispatch
221
- }),
222
- children: /*#__PURE__*/_jsxs("div", _extends({
223
- ref: container,
224
- className: cls
225
- }, other, {
226
- onClick: containerClick,
227
- style: containerStyle,
228
- children: [/*#__PURE__*/_jsx(ToolbarVisibility, {
229
- hideToolbar: hideToolbar,
230
- toolbarBottom: toolbarBottom,
231
- prefixCls: prefixCls,
232
- overflow: overflow,
233
- placement: "top"
234
- }), /*#__PURE__*/_jsxs("div", {
235
- className: prefixCls + "-content",
236
- children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/_jsx(TextArea, _extends({
237
- className: prefixCls + "-input",
238
- prefixCls: prefixCls,
239
- autoFocus: autoFocus
240
- }, textareaProps, {
241
- onChange: changeHandle,
242
- renderTextarea: (components == null ? void 0 : components.textarea) || renderTextarea,
243
- onScroll: e => handleScroll(e, 'text')
244
- })), /(live|preview)/.test(state.preview || '') && mdPreview]
245
- }), visibleDragbar && !state.fullscreen && /*#__PURE__*/_jsx(DragBar, {
246
- prefixCls: prefixCls,
247
- height: state.height,
248
- maxHeight: maxHeight,
249
- minHeight: minHeight,
250
- onChange: dragBarChange
251
- }), /*#__PURE__*/_jsx(ToolbarVisibility, {
252
- hideToolbar: hideToolbar,
253
- toolbarBottom: toolbarBottom,
254
- prefixCls: prefixCls,
255
- overflow: overflow,
256
- placement: "bottom"
257
- })]
258
- }))
259
- });
260
- });
261
- var Editor = InternalMDEditor;
262
- Editor.Markdown = MarkdownPreview;
263
- export default Editor;
3
+ import { createMDEditor } from './Editor.factory';
4
+ export default createMDEditor({
5
+ MarkdownPreview,
6
+ TextArea
7
+ });
@@ -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,59 @@
1
+ import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/taggedTemplateLiteralLoose";
2
+ var _templateObject;
3
+ import React, { useContext, useEffect } from 'react';
4
+ import { rehype } from 'rehype';
5
+ import rehypePrism from 'rehype-prism-plus/common';
6
+ import { EditorContext } from "../../Context.js";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ function html2Escape(sHtml) {
9
+ return sHtml.replace(/[<&"]/g, c => ({
10
+ '<': '&lt;',
11
+ '>': '&gt;',
12
+ '&': '&amp;',
13
+ '"': '&quot;'
14
+ })[c]);
15
+ }
16
+ export default function Markdown(props) {
17
+ var {
18
+ prefixCls
19
+ } = props;
20
+ var {
21
+ markdown = '',
22
+ highlightEnable,
23
+ dispatch
24
+ } = useContext(EditorContext);
25
+ var preRef = /*#__PURE__*/React.createRef();
26
+ useEffect(() => {
27
+ if (preRef.current && dispatch) {
28
+ dispatch({
29
+ textareaPre: preRef.current
30
+ });
31
+ }
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, []);
34
+ if (!markdown) {
35
+ return /*#__PURE__*/_jsx("pre", {
36
+ ref: preRef,
37
+ className: prefixCls + "-text-pre wmde-markdown-color"
38
+ });
39
+ }
40
+ var mdStr = "<pre class=\"language-markdown " + prefixCls + "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">" + html2Escape(String.raw(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["", ""])), markdown)) + "\n</code></pre>";
41
+ if (highlightEnable) {
42
+ try {
43
+ mdStr = rehype().data('settings', {
44
+ fragment: true
45
+ })
46
+ // https://github.com/uiwjs/react-md-editor/issues/593
47
+ // @ts-ignore
48
+ .use(rehypePrism, {
49
+ ignoreMissing: true
50
+ }).processSync(mdStr).toString();
51
+ } catch (error) {}
52
+ }
53
+ return /*#__PURE__*/React.createElement('div', {
54
+ className: 'wmde-markdown-color',
55
+ dangerouslySetInnerHTML: {
56
+ __html: mdStr || ''
57
+ }
58
+ });
59
+ }
@@ -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,105 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["prefixCls", "className", "onScroll", "renderTextarea"];
4
+ import React, { useEffect, Fragment, useContext } from 'react';
5
+ import { EditorContext } from "../../Context.js";
6
+ import shortcuts from "./shortcuts.js";
7
+ import Textarea from "./Textarea.js";
8
+ import { TextAreaCommandOrchestrator } from "../../commands/index.js";
9
+ import "./index.css";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ export function createTextArea(options) {
12
+ var _options$useMinHeight;
13
+ var MarkdownComponent = options == null ? void 0 : options.Markdown;
14
+ var useMinHeight = (_options$useMinHeight = options == null ? void 0 : options.useMinHeight) != null ? _options$useMinHeight : false;
15
+ return function TextArea(props) {
16
+ var _ref = props || {},
17
+ {
18
+ prefixCls,
19
+ className,
20
+ onScroll,
21
+ renderTextarea
22
+ } = _ref,
23
+ otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
24
+ var {
25
+ markdown,
26
+ scrollTop,
27
+ commands,
28
+ minHeight,
29
+ highlightEnable,
30
+ extraCommands,
31
+ dispatch
32
+ } = useContext(EditorContext);
33
+ var textRef = React.useRef(null);
34
+ var executeRef = React.useRef();
35
+ var warp = /*#__PURE__*/React.createRef();
36
+ useEffect(() => {
37
+ var state = {};
38
+ if (warp.current) {
39
+ state.textareaWarp = warp.current || undefined;
40
+ warp.current.scrollTop = scrollTop || 0;
41
+ }
42
+ if (dispatch) {
43
+ dispatch(_extends({}, state));
44
+ }
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ }, []);
47
+ useEffect(() => {
48
+ if (textRef.current && dispatch) {
49
+ var commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);
50
+ executeRef.current = commandOrchestrator;
51
+ dispatch({
52
+ textarea: textRef.current,
53
+ commandOrchestrator
54
+ });
55
+ }
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ }, []);
58
+ var textStyle = MarkdownComponent && highlightEnable ? {} : {
59
+ WebkitTextFillColor: 'initial',
60
+ overflow: 'auto'
61
+ };
62
+ return /*#__PURE__*/_jsx("div", {
63
+ ref: warp,
64
+ className: prefixCls + "-area " + (className || ''),
65
+ onScroll: onScroll,
66
+ children: /*#__PURE__*/_jsx("div", {
67
+ className: prefixCls + "-text",
68
+ style: useMinHeight ? {
69
+ minHeight
70
+ } : undefined,
71
+ children: renderTextarea ? (/*#__PURE__*/React.cloneElement(renderTextarea(_extends({}, otherProps, {
72
+ value: markdown,
73
+ autoComplete: 'off',
74
+ autoCorrect: 'off',
75
+ spellCheck: 'false',
76
+ autoCapitalize: 'off',
77
+ className: prefixCls + "-text-input",
78
+ style: {
79
+ WebkitTextFillColor: 'inherit',
80
+ overflow: 'auto'
81
+ }
82
+ }), {
83
+ dispatch,
84
+ onChange: otherProps.onChange,
85
+ shortcuts,
86
+ useContext: {
87
+ commands,
88
+ extraCommands,
89
+ commandOrchestrator: executeRef.current
90
+ }
91
+ }), {
92
+ ref: textRef
93
+ })) : /*#__PURE__*/_jsxs(Fragment, {
94
+ children: [MarkdownComponent && highlightEnable && /*#__PURE__*/_jsx(MarkdownComponent, {
95
+ prefixCls: prefixCls
96
+ }), /*#__PURE__*/_jsx(Textarea, _extends({
97
+ prefixCls: prefixCls
98
+ }, otherProps, {
99
+ style: textStyle
100
+ }))]
101
+ })
102
+ })
103
+ });
104
+ };
105
+ }
@@ -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,6 @@
1
+ import Markdown from './Markdown.common';
2
+ import { createTextArea } from "./factory.js";
3
+ export default createTextArea({
4
+ Markdown,
5
+ useMinHeight: true
6
+ });
@@ -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;
@@ -1,101 +1,6 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["prefixCls", "className", "onScroll", "renderTextarea"];
4
- import React, { useEffect, Fragment, useContext } from 'react';
5
- import { EditorContext } from "../../Context.js";
6
- import shortcuts from "./shortcuts.js";
7
1
  import Markdown from "./Markdown.js";
8
- import Textarea from "./Textarea.js";
9
- import { TextAreaCommandOrchestrator } from "../../commands/index.js";
10
- import "./index.css";
11
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
- export default function TextArea(props) {
13
- var _ref = props || {},
14
- {
15
- prefixCls,
16
- className,
17
- onScroll,
18
- renderTextarea
19
- } = _ref,
20
- otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
21
- var {
22
- markdown,
23
- scrollTop,
24
- commands,
25
- minHeight,
26
- highlightEnable,
27
- extraCommands,
28
- dispatch
29
- } = useContext(EditorContext);
30
- var textRef = React.useRef(null);
31
- var executeRef = React.useRef();
32
- var warp = /*#__PURE__*/React.createRef();
33
- useEffect(() => {
34
- var state = {};
35
- if (warp.current) {
36
- state.textareaWarp = warp.current || undefined;
37
- warp.current.scrollTop = scrollTop || 0;
38
- }
39
- if (dispatch) {
40
- dispatch(_extends({}, state));
41
- }
42
- // eslint-disable-next-line react-hooks/exhaustive-deps
43
- }, []);
44
- useEffect(() => {
45
- if (textRef.current && dispatch) {
46
- var commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);
47
- executeRef.current = commandOrchestrator;
48
- dispatch({
49
- textarea: textRef.current,
50
- commandOrchestrator
51
- });
52
- }
53
- // eslint-disable-next-line react-hooks/exhaustive-deps
54
- }, []);
55
- var textStyle = highlightEnable ? {} : {
56
- WebkitTextFillColor: 'initial',
57
- overflow: 'auto'
58
- };
59
- return /*#__PURE__*/_jsx("div", {
60
- ref: warp,
61
- className: prefixCls + "-area " + (className || ''),
62
- onScroll: onScroll,
63
- children: /*#__PURE__*/_jsx("div", {
64
- className: prefixCls + "-text",
65
- style: {
66
- minHeight
67
- },
68
- children: renderTextarea ? (/*#__PURE__*/React.cloneElement(renderTextarea(_extends({}, otherProps, {
69
- value: markdown,
70
- autoComplete: 'off',
71
- autoCorrect: 'off',
72
- spellCheck: 'false',
73
- autoCapitalize: 'off',
74
- className: prefixCls + "-text-input",
75
- style: {
76
- WebkitTextFillColor: 'inherit',
77
- overflow: 'auto'
78
- }
79
- }), {
80
- dispatch,
81
- onChange: otherProps.onChange,
82
- shortcuts,
83
- useContext: {
84
- commands,
85
- extraCommands,
86
- commandOrchestrator: executeRef.current
87
- }
88
- }), {
89
- ref: textRef
90
- })) : /*#__PURE__*/_jsxs(Fragment, {
91
- children: [highlightEnable && /*#__PURE__*/_jsx(Markdown, {
92
- prefixCls: prefixCls
93
- }), /*#__PURE__*/_jsx(Textarea, _extends({
94
- prefixCls: prefixCls
95
- }, otherProps, {
96
- style: textStyle
97
- }))]
98
- })
99
- })
100
- });
101
- }
2
+ import { createTextArea } from "./factory.js";
3
+ export default createTextArea({
4
+ Markdown,
5
+ useMinHeight: true
6
+ });
@@ -1,27 +1,3 @@
1
- import React, { JSX } from 'react';
2
- import { type ContextStore, ExecuteCommandState } from '../../Context';
3
- import { 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;