@uiw/react-md-editor 3.23.2 → 3.23.4

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.
@@ -26,7 +26,7 @@
26
26
  */
27
27
 
28
28
  /**!
29
- * @uiw/copy-to-clipboard v1.0.14
29
+ * @uiw/copy-to-clipboard v1.0.15
30
30
  * Copy to clipboard.
31
31
  *
32
32
  * Copyright (c) 2023 Kenny Wang
package/esm/Context.d.ts CHANGED
@@ -46,7 +46,7 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
46
46
  extraCommands?: ICommand<string>[] | undefined;
47
47
  markdown?: string | undefined;
48
48
  preview?: PreviewType | undefined;
49
- height?: string | number | undefined;
49
+ height?: import("csstype").Property.Height<string | number> | undefined;
50
50
  fullscreen?: boolean | undefined;
51
51
  highlightEnable?: boolean | undefined;
52
52
  autoFocus?: boolean | undefined;
package/esm/Editor.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { CSSProperties, PropsWithRef } from 'react';
1
+ import React, { CSSProperties } from 'react';
2
2
  import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
3
3
  import { ITextAreaProps } from './components/TextArea';
4
4
  import { ICommand, TextState } from './commands';
@@ -149,8 +149,9 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
149
149
  }
150
150
  export interface RefMDEditor extends ContextStore {
151
151
  }
152
- type Editor = React.FC<PropsWithRef<MDEditorProps>> & {
152
+ declare const InternalMDEditor: React.ForwardRefExoticComponent<MDEditorProps & React.RefAttributes<RefMDEditor>>;
153
+ type EditorComponent = typeof InternalMDEditor & {
153
154
  Markdown: typeof MarkdownPreview;
154
155
  };
155
- declare const mdEditor: Editor;
156
- export default mdEditor;
156
+ declare const Editor: EditorComponent;
157
+ export default Editor;
package/esm/Editor.js CHANGED
@@ -20,7 +20,7 @@ function setGroupPopFalse(data) {
20
20
  });
21
21
  return data;
22
22
  }
23
- var InternalMDEditor = (props, ref) => {
23
+ var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
24
24
  var _ref = props || {},
25
25
  {
26
26
  prefixCls = 'w-md-editor',
@@ -250,7 +250,7 @@ var InternalMDEditor = (props, ref) => {
250
250
  })]
251
251
  }))
252
252
  });
253
- };
254
- var mdEditor = /*#__PURE__*/React.forwardRef(InternalMDEditor);
255
- mdEditor.Markdown = MarkdownPreview;
256
- export default mdEditor;
253
+ });
254
+ var Editor = InternalMDEditor;
255
+ Editor.Markdown = MarkdownPreview;
256
+ export default Editor;
package/lib/Context.d.ts CHANGED
@@ -46,7 +46,7 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
46
46
  extraCommands?: ICommand<string>[] | undefined;
47
47
  markdown?: string | undefined;
48
48
  preview?: PreviewType | undefined;
49
- height?: string | number | undefined;
49
+ height?: import("csstype").Property.Height<string | number> | undefined;
50
50
  fullscreen?: boolean | undefined;
51
51
  highlightEnable?: boolean | undefined;
52
52
  autoFocus?: boolean | undefined;
package/lib/Editor.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { CSSProperties, PropsWithRef } from 'react';
1
+ import React, { CSSProperties } from 'react';
2
2
  import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
3
3
  import { ITextAreaProps } from './components/TextArea';
4
4
  import { ICommand, TextState } from './commands';
@@ -149,8 +149,9 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
149
149
  }
150
150
  export interface RefMDEditor extends ContextStore {
151
151
  }
152
- type Editor = React.FC<PropsWithRef<MDEditorProps>> & {
152
+ declare const InternalMDEditor: React.ForwardRefExoticComponent<MDEditorProps & React.RefAttributes<RefMDEditor>>;
153
+ type EditorComponent = typeof InternalMDEditor & {
153
154
  Markdown: typeof MarkdownPreview;
154
155
  };
155
- declare const mdEditor: Editor;
156
- export default mdEditor;
156
+ declare const Editor: EditorComponent;
157
+ export default Editor;
package/lib/Editor.js CHANGED
@@ -25,7 +25,7 @@ function setGroupPopFalse() {
25
25
  });
26
26
  return data;
27
27
  }
28
- var InternalMDEditor = function InternalMDEditor(props, ref) {
28
+ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) {
29
29
  var _ref = props || {},
30
30
  _ref$prefixCls = _ref.prefixCls,
31
31
  prefixCls = _ref$prefixCls === void 0 ? 'w-md-editor' : _ref$prefixCls,
@@ -310,9 +310,9 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
310
310
  })]
311
311
  }))
312
312
  });
313
- };
314
- var mdEditor = /*#__PURE__*/_react["default"].forwardRef(InternalMDEditor);
315
- mdEditor.Markdown = _reactMarkdownPreview["default"];
316
- var _default = mdEditor;
313
+ });
314
+ var Editor = InternalMDEditor;
315
+ Editor.Markdown = _reactMarkdownPreview["default"];
316
+ var _default = Editor;
317
317
  exports["default"] = _default;
318
318
  module.exports = exports.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "3.23.2",
3
+ "version": "3.23.4",
4
4
  "description": "A markdown editor with preview, implemented with React.js and TypeScript.",
5
5
  "homepage": "https://uiwjs.github.io/react-md-editor/",
6
6
  "author": "kenny wang <wowohoo@qq.com>",
@@ -25,7 +25,8 @@
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.14.6",
27
27
  "@uiw/react-markdown-preview": "^4.1.5",
28
- "rehype": "~12.0.1"
28
+ "rehype": "~12.0.1",
29
+ "rehype-prism-plus": "~1.6.1"
29
30
  },
30
31
  "keywords": [
31
32
  "react",
package/src/Editor.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties, PropsWithRef } from 'react';
1
+ import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties } from 'react';
2
2
  import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
3
3
  import TextArea, { ITextAreaProps } from './components/TextArea';
4
4
  import Toolbar from './components/Toolbar';
@@ -162,246 +162,249 @@ function setGroupPopFalse(data: Record<string, boolean> = {}) {
162
162
 
163
163
  export interface RefMDEditor extends ContextStore {}
164
164
 
165
- const InternalMDEditor = (
166
- props: MDEditorProps,
167
- ref?: ((instance: RefMDEditor) => void) | React.RefObject<RefMDEditor> | null,
168
- ) => {
169
- const {
170
- prefixCls = 'w-md-editor',
171
- className,
172
- value: propsValue,
173
- commands = getCommands(),
174
- commandsFilter,
175
- direction,
176
- extraCommands = getExtraCommands(),
177
- height = 200,
178
- enableScroll = true,
179
- visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,
180
- highlightEnable = true,
181
- preview: previewType = 'live',
182
- fullscreen = false,
183
- overflow = true,
184
- previewOptions = {},
185
- textareaProps,
186
- maxHeight = 1200,
187
- minHeight = 100,
188
- autoFocus,
189
- tabSize = 2,
190
- defaultTabEnable = false,
191
- onChange,
192
- onStatistics,
193
- onHeightChange,
194
- hideToolbar,
195
- toolbarBottom = false,
196
- components,
197
- renderTextarea,
198
- ...other
199
- } = props || {};
200
- const cmds = commands
201
- .map((item) => (commandsFilter ? commandsFilter(item, false) : item))
202
- .filter(Boolean) as ICommand[];
203
- const extraCmds = extraCommands
204
- .map((item) => (commandsFilter ? commandsFilter(item, true) : item))
205
- .filter(Boolean) as ICommand[];
206
- let [state, dispatch] = useReducer(reducer, {
207
- markdown: propsValue,
208
- preview: previewType,
209
- components,
210
- height,
211
- highlightEnable,
212
- tabSize,
213
- defaultTabEnable,
214
- scrollTop: 0,
215
- scrollTopPreview: 0,
216
- commands: cmds,
217
- extraCommands: extraCmds,
218
- fullscreen,
219
- barPopup: {},
220
- });
221
- const container = useRef<HTMLDivElement>(null);
222
- const previewRef = useRef<HTMLDivElement>(null);
223
- const enableScrollRef = useRef(enableScroll);
165
+ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
166
+ (props: MDEditorProps, ref: React.ForwardedRef<RefMDEditor>) => {
167
+ const {
168
+ prefixCls = 'w-md-editor',
169
+ className,
170
+ value: propsValue,
171
+ commands = getCommands(),
172
+ commandsFilter,
173
+ direction,
174
+ extraCommands = getExtraCommands(),
175
+ height = 200,
176
+ enableScroll = true,
177
+ visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,
178
+ highlightEnable = true,
179
+ preview: previewType = 'live',
180
+ fullscreen = false,
181
+ overflow = true,
182
+ previewOptions = {},
183
+ textareaProps,
184
+ maxHeight = 1200,
185
+ minHeight = 100,
186
+ autoFocus,
187
+ tabSize = 2,
188
+ defaultTabEnable = false,
189
+ onChange,
190
+ onStatistics,
191
+ onHeightChange,
192
+ hideToolbar,
193
+ toolbarBottom = false,
194
+ components,
195
+ renderTextarea,
196
+ ...other
197
+ } = props || {};
198
+ const cmds = commands
199
+ .map((item) => (commandsFilter ? commandsFilter(item, false) : item))
200
+ .filter(Boolean) as ICommand[];
201
+ const extraCmds = extraCommands
202
+ .map((item) => (commandsFilter ? commandsFilter(item, true) : item))
203
+ .filter(Boolean) as ICommand[];
204
+ let [state, dispatch] = useReducer(reducer, {
205
+ markdown: propsValue,
206
+ preview: previewType,
207
+ components,
208
+ height,
209
+ highlightEnable,
210
+ tabSize,
211
+ defaultTabEnable,
212
+ scrollTop: 0,
213
+ scrollTopPreview: 0,
214
+ commands: cmds,
215
+ extraCommands: extraCmds,
216
+ fullscreen,
217
+ barPopup: {},
218
+ });
219
+ const container = useRef<HTMLDivElement>(null);
220
+ const previewRef = useRef<HTMLDivElement>(null);
221
+ const enableScrollRef = useRef(enableScroll);
224
222
 
225
- useImperativeHandle(ref, () => ({ ...state, container: container.current, dispatch }));
226
- useMemo(() => (enableScrollRef.current = enableScroll), [enableScroll]);
227
- useEffect(() => {
228
- const stateInit: ContextStore = {};
229
- if (container.current) {
230
- stateInit.container = container.current || undefined;
231
- }
232
- stateInit.markdown = propsValue || '';
233
- stateInit.barPopup = {};
234
- if (dispatch) {
235
- dispatch({ ...state, ...stateInit });
236
- }
237
- // eslint-disable-next-line react-hooks/exhaustive-deps
238
- }, []);
223
+ useImperativeHandle(ref, () => ({ ...state, container: container.current, dispatch }));
224
+ useMemo(() => (enableScrollRef.current = enableScroll), [enableScroll]);
225
+ useEffect(() => {
226
+ const stateInit: ContextStore = {};
227
+ if (container.current) {
228
+ stateInit.container = container.current || undefined;
229
+ }
230
+ stateInit.markdown = propsValue || '';
231
+ stateInit.barPopup = {};
232
+ if (dispatch) {
233
+ dispatch({ ...state, ...stateInit });
234
+ }
235
+ // eslint-disable-next-line react-hooks/exhaustive-deps
236
+ }, []);
239
237
 
240
- const cls = [
241
- className,
242
- 'wmde-markdown-var',
243
- direction ? `${prefixCls}-${direction}` : null,
244
- prefixCls,
245
- state.preview ? `${prefixCls}-show-${state.preview}` : null,
246
- state.fullscreen ? `${prefixCls}-fullscreen` : null,
247
- ]
248
- .filter(Boolean)
249
- .join(' ')
250
- .trim();
238
+ const cls = [
239
+ className,
240
+ 'wmde-markdown-var',
241
+ direction ? `${prefixCls}-${direction}` : null,
242
+ prefixCls,
243
+ state.preview ? `${prefixCls}-show-${state.preview}` : null,
244
+ state.fullscreen ? `${prefixCls}-fullscreen` : null,
245
+ ]
246
+ .filter(Boolean)
247
+ .join(' ')
248
+ .trim();
251
249
 
252
- useMemo(
253
- () => propsValue !== state.markdown && dispatch({ markdown: propsValue || '' }),
254
- [propsValue, state.markdown],
255
- );
256
- // eslint-disable-next-line react-hooks/exhaustive-deps
257
- useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);
258
- // eslint-disable-next-line react-hooks/exhaustive-deps
259
- useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);
260
- useMemo(
261
- () => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),
250
+ useMemo(
251
+ () => propsValue !== state.markdown && dispatch({ markdown: propsValue || '' }),
252
+ [propsValue, state.markdown],
253
+ );
262
254
  // eslint-disable-next-line react-hooks/exhaustive-deps
263
- [highlightEnable],
264
- );
265
- // eslint-disable-next-line react-hooks/exhaustive-deps
266
- useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);
267
- useMemo(
268
- () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),
255
+ useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);
269
256
  // eslint-disable-next-line react-hooks/exhaustive-deps
270
- [fullscreen],
271
- );
272
- // eslint-disable-next-line react-hooks/exhaustive-deps
273
- useMemo(() => height !== state.height && dispatch({ height: height }), [height]);
274
- useMemo(
275
- () => height !== state.height && onHeightChange && onHeightChange(state.height, height, state),
276
- [height, onHeightChange, state],
277
- );
278
- // eslint-disable-next-line react-hooks/exhaustive-deps
279
- useMemo(() => commands !== state.commands && dispatch({ commands: cmds }), [props.commands]);
280
- // eslint-disable-next-line react-hooks/exhaustive-deps
281
- useMemo(() => extraCommands !== state.extraCommands && dispatch({ extraCommands: extraCmds }), [props.extraCommands]);
282
-
283
- const textareaDomRef = useRef<HTMLDivElement>();
284
- const active = useRef<'text' | 'preview'>('preview');
285
- const initScroll = useRef(false);
257
+ useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);
258
+ useMemo(
259
+ () => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),
260
+ // eslint-disable-next-line react-hooks/exhaustive-deps
261
+ [highlightEnable],
262
+ );
263
+ // eslint-disable-next-line react-hooks/exhaustive-deps
264
+ useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);
265
+ useMemo(
266
+ () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),
267
+ // eslint-disable-next-line react-hooks/exhaustive-deps
268
+ [fullscreen],
269
+ );
270
+ // eslint-disable-next-line react-hooks/exhaustive-deps
271
+ useMemo(() => height !== state.height && dispatch({ height: height }), [height]);
272
+ useMemo(
273
+ () => height !== state.height && onHeightChange && onHeightChange(state.height, height, state),
274
+ [height, onHeightChange, state],
275
+ );
276
+ // eslint-disable-next-line react-hooks/exhaustive-deps
277
+ useMemo(() => commands !== state.commands && dispatch({ commands: cmds }), [props.commands]);
278
+ // eslint-disable-next-line react-hooks/exhaustive-deps
279
+ useMemo(
280
+ () => extraCommands !== state.extraCommands && dispatch({ extraCommands: extraCmds }),
281
+ [props.extraCommands],
282
+ );
286
283
 
287
- useMemo(() => {
288
- textareaDomRef.current = state.textareaWarp;
289
- if (state.textareaWarp) {
290
- state.textareaWarp.addEventListener('mouseover', () => {
291
- active.current = 'text';
292
- });
293
- state.textareaWarp.addEventListener('mouseleave', () => {
294
- active.current = 'preview';
295
- });
296
- }
297
- }, [state.textareaWarp]);
284
+ const textareaDomRef = useRef<HTMLDivElement>();
285
+ const active = useRef<'text' | 'preview'>('preview');
286
+ const initScroll = useRef(false);
298
287
 
299
- const handleScroll = (e: React.UIEvent<HTMLDivElement>, type: 'text' | 'preview') => {
300
- if (!enableScrollRef.current) return;
301
- const textareaDom = textareaDomRef.current;
302
- const previewDom = previewRef.current ? previewRef.current : undefined;
303
- if (!initScroll.current) {
304
- active.current = type;
305
- initScroll.current = true;
306
- }
307
- if (textareaDom && previewDom) {
308
- const scale =
309
- (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);
310
- if (e.target === textareaDom && active.current === 'text') {
311
- previewDom.scrollTop = textareaDom.scrollTop / scale;
288
+ useMemo(() => {
289
+ textareaDomRef.current = state.textareaWarp;
290
+ if (state.textareaWarp) {
291
+ state.textareaWarp.addEventListener('mouseover', () => {
292
+ active.current = 'text';
293
+ });
294
+ state.textareaWarp.addEventListener('mouseleave', () => {
295
+ active.current = 'preview';
296
+ });
312
297
  }
313
- if (e.target === previewDom && active.current === 'preview') {
314
- textareaDom.scrollTop = previewDom.scrollTop * scale;
298
+ }, [state.textareaWarp]);
299
+
300
+ const handleScroll = (e: React.UIEvent<HTMLDivElement>, type: 'text' | 'preview') => {
301
+ if (!enableScrollRef.current) return;
302
+ const textareaDom = textareaDomRef.current;
303
+ const previewDom = previewRef.current ? previewRef.current : undefined;
304
+ if (!initScroll.current) {
305
+ active.current = type;
306
+ initScroll.current = true;
315
307
  }
316
- let scrollTop = 0;
317
- if (active.current === 'text') {
318
- scrollTop = textareaDom.scrollTop || 0;
319
- } else if (active.current === 'preview') {
320
- scrollTop = previewDom.scrollTop || 0;
308
+ if (textareaDom && previewDom) {
309
+ const scale =
310
+ (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);
311
+ if (e.target === textareaDom && active.current === 'text') {
312
+ previewDom.scrollTop = textareaDom.scrollTop / scale;
313
+ }
314
+ if (e.target === previewDom && active.current === 'preview') {
315
+ textareaDom.scrollTop = previewDom.scrollTop * scale;
316
+ }
317
+ let scrollTop = 0;
318
+ if (active.current === 'text') {
319
+ scrollTop = textareaDom.scrollTop || 0;
320
+ } else if (active.current === 'preview') {
321
+ scrollTop = previewDom.scrollTop || 0;
322
+ }
323
+ dispatch({ scrollTop });
321
324
  }
322
- dispatch({ scrollTop });
323
- }
324
- };
325
+ };
325
326
 
326
- const previewClassName = `${prefixCls}-preview ${previewOptions.className || ''}`;
327
- const handlePreviewScroll = (e: React.UIEvent<HTMLDivElement, UIEvent>) => handleScroll(e, 'preview');
328
- let mdPreview = useMemo(
329
- () => (
330
- <div ref={previewRef} className={previewClassName}>
331
- <MarkdownPreview {...previewOptions} onScroll={handlePreviewScroll} source={state.markdown || ''} />
332
- </div>
333
- ),
334
- [previewClassName, previewOptions, state.markdown],
335
- );
336
- const preview = components?.preview && components?.preview(state.markdown || '', state, dispatch);
337
- if (preview && React.isValidElement(preview)) {
338
- mdPreview = (
339
- <div className={previewClassName} ref={previewRef} onScroll={handlePreviewScroll}>
340
- {preview}
341
- </div>
327
+ const previewClassName = `${prefixCls}-preview ${previewOptions.className || ''}`;
328
+ const handlePreviewScroll = (e: React.UIEvent<HTMLDivElement, UIEvent>) => handleScroll(e, 'preview');
329
+ let mdPreview = useMemo(
330
+ () => (
331
+ <div ref={previewRef} className={previewClassName}>
332
+ <MarkdownPreview {...previewOptions} onScroll={handlePreviewScroll} source={state.markdown || ''} />
333
+ </div>
334
+ ),
335
+ [previewClassName, previewOptions, state.markdown],
342
336
  );
343
- }
337
+ const preview = components?.preview && components?.preview(state.markdown || '', state, dispatch);
338
+ if (preview && React.isValidElement(preview)) {
339
+ mdPreview = (
340
+ <div className={previewClassName} ref={previewRef} onScroll={handlePreviewScroll}>
341
+ {preview}
342
+ </div>
343
+ );
344
+ }
344
345
 
345
- const containerStyle = { ...other.style, height: state.height || '100%' };
346
- const containerClick = () => dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });
347
- const dragBarChange = (newHeight: number) => dispatch({ height: newHeight });
346
+ const containerStyle = { ...other.style, height: state.height || '100%' };
347
+ const containerClick = () => dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });
348
+ const dragBarChange = (newHeight: number) => dispatch({ height: newHeight });
348
349
 
349
- const changeHandle = (evn: React.ChangeEvent<HTMLTextAreaElement>) => {
350
- onChange && onChange(evn.target.value, evn, state);
351
- if (textareaProps && textareaProps.onChange) {
352
- textareaProps.onChange(evn);
353
- }
354
- if (state.textarea && state.textarea instanceof HTMLTextAreaElement && onStatistics) {
355
- const obj = new TextAreaCommandOrchestrator(state.textarea!);
356
- const objState = (obj.getState() || {}) as TextState;
357
- onStatistics({
358
- ...objState,
359
- lineCount: evn.target.value.split('\n').length,
360
- length: evn.target.value.length,
361
- });
362
- }
363
- };
364
- return (
365
- <EditorContext.Provider value={{ ...state, dispatch }}>
366
- <div ref={container} className={cls} {...other} onClick={containerClick} style={containerStyle}>
367
- {!hideToolbar && !toolbarBottom && (
368
- <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
369
- )}
370
- <div className={`${prefixCls}-content`}>
371
- {/(edit|live)/.test(state.preview || '') && (
372
- <TextArea
373
- className={`${prefixCls}-input`}
350
+ const changeHandle = (evn: React.ChangeEvent<HTMLTextAreaElement>) => {
351
+ onChange && onChange(evn.target.value, evn, state);
352
+ if (textareaProps && textareaProps.onChange) {
353
+ textareaProps.onChange(evn);
354
+ }
355
+ if (state.textarea && state.textarea instanceof HTMLTextAreaElement && onStatistics) {
356
+ const obj = new TextAreaCommandOrchestrator(state.textarea!);
357
+ const objState = (obj.getState() || {}) as TextState;
358
+ onStatistics({
359
+ ...objState,
360
+ lineCount: evn.target.value.split('\n').length,
361
+ length: evn.target.value.length,
362
+ });
363
+ }
364
+ };
365
+ return (
366
+ <EditorContext.Provider value={{ ...state, dispatch }}>
367
+ <div ref={container} className={cls} {...other} onClick={containerClick} style={containerStyle}>
368
+ {!hideToolbar && !toolbarBottom && (
369
+ <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
370
+ )}
371
+ <div className={`${prefixCls}-content`}>
372
+ {/(edit|live)/.test(state.preview || '') && (
373
+ <TextArea
374
+ className={`${prefixCls}-input`}
375
+ prefixCls={prefixCls}
376
+ autoFocus={autoFocus}
377
+ {...textareaProps}
378
+ onChange={changeHandle}
379
+ renderTextarea={components?.textarea || renderTextarea}
380
+ onScroll={(e) => handleScroll(e, 'text')}
381
+ />
382
+ )}
383
+ {/(live|preview)/.test(state.preview || '') && mdPreview}
384
+ </div>
385
+ {visibleDragbar && !state.fullscreen && (
386
+ <DragBar
374
387
  prefixCls={prefixCls}
375
- autoFocus={autoFocus}
376
- {...textareaProps}
377
- onChange={changeHandle}
378
- renderTextarea={components?.textarea || renderTextarea}
379
- onScroll={(e) => handleScroll(e, 'text')}
388
+ height={state.height as number}
389
+ maxHeight={maxHeight!}
390
+ minHeight={minHeight!}
391
+ onChange={dragBarChange}
380
392
  />
381
393
  )}
382
- {/(live|preview)/.test(state.preview || '') && mdPreview}
394
+ {!hideToolbar && toolbarBottom && (
395
+ <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
396
+ )}
383
397
  </div>
384
- {visibleDragbar && !state.fullscreen && (
385
- <DragBar
386
- prefixCls={prefixCls}
387
- height={state.height as number}
388
- maxHeight={maxHeight!}
389
- minHeight={minHeight!}
390
- onChange={dragBarChange}
391
- />
392
- )}
393
- {!hideToolbar && toolbarBottom && (
394
- <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
395
- )}
396
- </div>
397
- </EditorContext.Provider>
398
- );
399
- };
400
-
401
- type Editor = React.FC<PropsWithRef<MDEditorProps>> & { Markdown: typeof MarkdownPreview };
398
+ </EditorContext.Provider>
399
+ );
400
+ },
401
+ );
402
402
 
403
- const mdEditor: Editor = React.forwardRef(InternalMDEditor) as unknown as Editor;
403
+ type EditorComponent = typeof InternalMDEditor & {
404
+ Markdown: typeof MarkdownPreview;
405
+ };
404
406
 
405
- mdEditor.Markdown = MarkdownPreview;
407
+ const Editor = InternalMDEditor as EditorComponent;
408
+ Editor.Markdown = MarkdownPreview;
406
409
 
407
- export default mdEditor;
410
+ export default Editor;
@@ -1,4 +1,4 @@
1
- import React, { useContext, useEffect, useMemo } from 'react';
1
+ import React, { useContext, useEffect } from 'react';
2
2
  import { rehype } from 'rehype';
3
3
  import rehypePrism from 'rehype-prism-plus';
4
4
  import { IProps } from '../../Editor';