@uiw/react-md-editor 3.24.1 → 3.25.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 (54) hide show
  1. package/README.md +47 -2
  2. package/dist/mdeditor.js +4114 -4095
  3. package/dist/mdeditor.min.js +1 -1
  4. package/esm/Context.d.ts +1 -1
  5. package/esm/Editor.d.ts +4 -149
  6. package/esm/Editor.js +0 -1
  7. package/esm/Editor.nohighlight.d.ts +12 -0
  8. package/esm/Editor.nohighlight.js +255 -0
  9. package/esm/Types.d.ts +148 -0
  10. package/esm/Types.js +1 -0
  11. package/esm/components/DragBar/index.d.ts +1 -1
  12. package/esm/components/TextArea/Markdown.d.ts +1 -1
  13. package/esm/components/TextArea/Textarea.d.ts +1 -1
  14. package/esm/components/TextArea/index.d.ts +1 -1
  15. package/esm/components/TextArea/index.nohighlight.d.ts +27 -0
  16. package/esm/components/TextArea/index.nohighlight.js +93 -0
  17. package/esm/components/Toolbar/Child.d.ts +1 -1
  18. package/esm/components/Toolbar/index.d.ts +1 -1
  19. package/esm/index.d.ts +2 -0
  20. package/esm/index.js +2 -0
  21. package/esm/index.nohighlight.d.ts +13 -0
  22. package/esm/index.nohighlight.js +13 -0
  23. package/lib/Context.d.ts +1 -1
  24. package/lib/Editor.d.ts +4 -149
  25. package/lib/Editor.nohighlight.d.ts +12 -0
  26. package/lib/Editor.nohighlight.js +317 -0
  27. package/lib/Types.d.ts +148 -0
  28. package/lib/Types.js +1 -0
  29. package/lib/components/DragBar/index.d.ts +1 -1
  30. package/lib/components/TextArea/Markdown.d.ts +1 -1
  31. package/lib/components/TextArea/Textarea.d.ts +1 -1
  32. package/lib/components/TextArea/index.d.ts +1 -1
  33. package/lib/components/TextArea/index.nohighlight.d.ts +27 -0
  34. package/lib/components/TextArea/index.nohighlight.js +98 -0
  35. package/lib/components/Toolbar/Child.d.ts +1 -1
  36. package/lib/components/Toolbar/index.d.ts +1 -1
  37. package/lib/index.d.ts +2 -0
  38. package/lib/index.js +12 -0
  39. package/lib/index.nohighlight.d.ts +13 -0
  40. package/lib/index.nohighlight.js +98 -0
  41. package/package.json +16 -2
  42. package/src/Context.tsx +1 -1
  43. package/src/Editor.nohighlight.tsx +264 -0
  44. package/src/Editor.tsx +5 -151
  45. package/src/Types.ts +151 -0
  46. package/src/components/DragBar/index.tsx +1 -1
  47. package/src/components/TextArea/Markdown.tsx +2 -2
  48. package/src/components/TextArea/Textarea.tsx +1 -1
  49. package/src/components/TextArea/index.nohighlight.tsx +109 -0
  50. package/src/components/TextArea/index.tsx +1 -1
  51. package/src/components/Toolbar/Child.tsx +1 -1
  52. package/src/components/Toolbar/index.tsx +1 -1
  53. package/src/index.nohighlight.tsx +16 -0
  54. package/src/index.tsx +2 -0
@@ -0,0 +1,109 @@
1
+ import React, { useEffect, Fragment, useContext } from 'react';
2
+ import { EditorContext, ContextStore, ExecuteCommandState } from '../../Context';
3
+ import shortcuts from './shortcuts';
4
+ import Textarea, { TextAreaProps } from './Textarea';
5
+ import { IProps } from '../../Types';
6
+ import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
7
+ import './index.less';
8
+
9
+ type RenderTextareaHandle = {
10
+ dispatch: ContextStore['dispatch'];
11
+ onChange?: TextAreaProps['onChange'];
12
+ useContext?: {
13
+ commands: ContextStore['commands'];
14
+ extraCommands: ContextStore['extraCommands'];
15
+ commandOrchestrator?: TextAreaCommandOrchestrator;
16
+ };
17
+ shortcuts?: (
18
+ e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,
19
+ commands: ICommand[],
20
+ commandOrchestrator?: TextAreaCommandOrchestrator,
21
+ dispatch?: React.Dispatch<ContextStore>,
22
+ state?: ExecuteCommandState,
23
+ ) => void;
24
+ };
25
+
26
+ export interface ITextAreaProps
27
+ extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>,
28
+ IProps {
29
+ value?: string;
30
+ onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
31
+ renderTextarea?: (
32
+ props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>,
33
+ opts: RenderTextareaHandle,
34
+ ) => JSX.Element;
35
+ }
36
+
37
+ export type TextAreaRef = {
38
+ text?: HTMLTextAreaElement;
39
+ warp?: HTMLDivElement;
40
+ };
41
+
42
+ export default function TextArea(props: ITextAreaProps) {
43
+ const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};
44
+ const { markdown, scrollTop, commands, extraCommands, dispatch } = useContext(EditorContext);
45
+ const textRef = React.useRef<HTMLTextAreaElement>(null);
46
+ const executeRef = React.useRef<TextAreaCommandOrchestrator>();
47
+ const warp = React.createRef<HTMLDivElement>();
48
+ useEffect(() => {
49
+ const state: ContextStore = {};
50
+ if (warp.current) {
51
+ state.textareaWarp = warp.current || undefined;
52
+ warp.current.scrollTop = scrollTop || 0;
53
+ }
54
+ if (dispatch) {
55
+ dispatch({ ...state });
56
+ }
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
+ }, []);
59
+
60
+ useEffect(() => {
61
+ if (textRef.current && dispatch) {
62
+ const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);
63
+ executeRef.current = commandOrchestrator;
64
+ dispatch({ textarea: textRef.current, commandOrchestrator });
65
+ }
66
+ // eslint-disable-next-line react-hooks/exhaustive-deps
67
+ }, []);
68
+
69
+ const textStyle: React.CSSProperties = { WebkitTextFillColor: 'initial', overflow: 'auto' };
70
+
71
+ return (
72
+ <div ref={warp} className={`${prefixCls}-area ${className || ''}`} onScroll={onScroll}>
73
+ <div className={`${prefixCls}-text`}>
74
+ {renderTextarea ? (
75
+ React.cloneElement(
76
+ renderTextarea(
77
+ {
78
+ ...otherProps,
79
+ value: markdown,
80
+ autoComplete: 'off',
81
+ autoCorrect: 'off',
82
+ spellCheck: 'false',
83
+ autoCapitalize: 'off',
84
+ className: `${prefixCls}-text-input`,
85
+ style: {
86
+ WebkitTextFillColor: 'inherit',
87
+ overflow: 'auto',
88
+ },
89
+ },
90
+ {
91
+ dispatch,
92
+ onChange: otherProps.onChange,
93
+ shortcuts,
94
+ useContext: { commands, extraCommands, commandOrchestrator: executeRef.current },
95
+ },
96
+ ),
97
+ {
98
+ ref: textRef,
99
+ },
100
+ )
101
+ ) : (
102
+ <Fragment>
103
+ <Textarea prefixCls={prefixCls} {...otherProps} style={textStyle} />
104
+ </Fragment>
105
+ )}
106
+ </div>
107
+ </div>
108
+ );
109
+ }
@@ -3,7 +3,7 @@ import { EditorContext, ContextStore, ExecuteCommandState } from '../../Context'
3
3
  import shortcuts from './shortcuts';
4
4
  import Markdown from './Markdown';
5
5
  import Textarea, { TextAreaProps } from './Textarea';
6
- import { IProps } from '../../Editor';
6
+ import { IProps } from '../../Types';
7
7
  import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
8
8
  import './index.less';
9
9
 
@@ -1,6 +1,6 @@
1
1
  import React, { useContext, useMemo } from 'react';
2
2
  import './Child.less';
3
- import Toolbar, { IToolbarProps } from './';
3
+ import Toolbar, { type IToolbarProps } from './';
4
4
  import { EditorContext } from '../../Context';
5
5
 
6
6
  export type ChildProps = IToolbarProps & {
@@ -1,5 +1,5 @@
1
1
  import React, { Fragment, useContext, useEffect, useRef } from 'react';
2
- import { IProps } from '../../Editor';
2
+ import { IProps } from '../../Types';
3
3
  import { EditorContext, PreviewType, ContextStore } from '../../Context';
4
4
  import { ICommand } from '../../commands';
5
5
  import Child from './Child';
@@ -0,0 +1,16 @@
1
+ import MDEditor from './Editor.nohighlight';
2
+ import * as commands from './commands';
3
+ import * as MarkdownUtil from './utils/markdownUtils';
4
+ import './index.less';
5
+
6
+ export * from './commands';
7
+ export * from './commands/group';
8
+ export * from './utils/markdownUtils';
9
+ export * from './utils/InsertTextAtPosition';
10
+ export * from './Editor.nohighlight';
11
+ export * from './Context';
12
+ export * from './Types';
13
+
14
+ export { MarkdownUtil, commands };
15
+
16
+ export default MDEditor;
package/src/index.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import MDEditor from './Editor';
2
2
  import * as commands from './commands';
3
3
  import * as MarkdownUtil from './utils/markdownUtils';
4
+ import './index.less';
4
5
 
5
6
  export * from './commands';
6
7
  export * from './commands/group';
@@ -8,6 +9,7 @@ export * from './utils/markdownUtils';
8
9
  export * from './utils/InsertTextAtPosition';
9
10
  export * from './Editor';
10
11
  export * from './Context';
12
+ export * from './Types';
11
13
 
12
14
  export { MarkdownUtil, commands };
13
15