@uiw/react-md-editor 3.24.0 → 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.
- package/README.md +50 -5
- package/dist/mdeditor.js +1835 -1807
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.d.ts +1 -1
- package/esm/Editor.d.ts +4 -149
- package/esm/Editor.js +0 -1
- package/esm/Editor.nohighlight.d.ts +12 -0
- package/esm/Editor.nohighlight.js +255 -0
- package/esm/Types.d.ts +148 -0
- package/esm/Types.js +1 -0
- package/esm/commands/index.d.ts +4 -1
- package/esm/commands/index.js +2 -1
- package/esm/components/DragBar/index.d.ts +1 -1
- package/esm/components/TextArea/Markdown.d.ts +1 -1
- package/esm/components/TextArea/Textarea.d.ts +1 -1
- package/esm/components/TextArea/handleKeyDown.js +1 -3
- package/esm/components/TextArea/index.d.ts +1 -1
- package/esm/components/TextArea/index.nohighlight.d.ts +27 -0
- package/esm/components/TextArea/index.nohighlight.js +93 -0
- package/esm/components/Toolbar/Child.d.ts +1 -1
- package/esm/components/Toolbar/index.d.ts +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/index.nohighlight.d.ts +13 -0
- package/esm/index.nohighlight.js +13 -0
- package/lib/Context.d.ts +1 -1
- package/lib/Editor.d.ts +4 -149
- package/lib/Editor.nohighlight.d.ts +12 -0
- package/lib/Editor.nohighlight.js +317 -0
- package/lib/Types.d.ts +148 -0
- package/lib/Types.js +1 -0
- package/lib/commands/index.d.ts +4 -1
- package/lib/commands/index.js +19 -0
- package/lib/components/DragBar/index.d.ts +1 -1
- package/lib/components/TextArea/Markdown.d.ts +1 -1
- package/lib/components/TextArea/Textarea.d.ts +1 -1
- package/lib/components/TextArea/handleKeyDown.js +1 -3
- package/lib/components/TextArea/index.d.ts +1 -1
- package/lib/components/TextArea/index.nohighlight.d.ts +27 -0
- package/lib/components/TextArea/index.nohighlight.js +98 -0
- package/lib/components/Toolbar/Child.d.ts +1 -1
- package/lib/components/Toolbar/index.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +12 -0
- package/lib/index.nohighlight.d.ts +13 -0
- package/lib/index.nohighlight.js +98 -0
- package/package.json +16 -2
- package/src/Context.tsx +1 -1
- package/src/Editor.nohighlight.tsx +264 -0
- package/src/Editor.tsx +5 -151
- package/src/Types.ts +151 -0
- package/src/commands/index.ts +4 -0
- package/src/components/DragBar/index.tsx +1 -1
- package/src/components/TextArea/Markdown.tsx +2 -2
- package/src/components/TextArea/Textarea.tsx +1 -1
- package/src/components/TextArea/handleKeyDown.tsx +5 -3
- package/src/components/TextArea/index.nohighlight.tsx +109 -0
- package/src/components/TextArea/index.tsx +1 -1
- package/src/components/Toolbar/Child.tsx +1 -1
- package/src/components/Toolbar/index.tsx +1 -1
- package/src/index.nohighlight.tsx +16 -0
- package/src/index.tsx +2 -0
package/src/Editor.tsx
CHANGED
|
@@ -1,157 +1,11 @@
|
|
|
1
|
-
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle
|
|
2
|
-
import MarkdownPreview
|
|
3
|
-
import TextArea
|
|
1
|
+
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
|
|
2
|
+
import MarkdownPreview from '@uiw/react-markdown-preview';
|
|
3
|
+
import TextArea from './components/TextArea';
|
|
4
4
|
import Toolbar from './components/Toolbar';
|
|
5
5
|
import DragBar from './components/DragBar';
|
|
6
6
|
import { getCommands, getExtraCommands, ICommand, TextState, TextAreaCommandOrchestrator } from './commands';
|
|
7
|
-
import { reducer, EditorContext, ContextStore
|
|
8
|
-
import './
|
|
9
|
-
|
|
10
|
-
export interface IProps {
|
|
11
|
-
prefixCls?: string;
|
|
12
|
-
className?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Statistics extends TextState {
|
|
16
|
-
/** total length of the document */
|
|
17
|
-
length: number;
|
|
18
|
-
/** Get the number of lines in the editor. */
|
|
19
|
-
lineCount: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {
|
|
23
|
-
/**
|
|
24
|
-
* The Markdown value.
|
|
25
|
-
*/
|
|
26
|
-
value?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Event handler for the `onChange` event.
|
|
29
|
-
*/
|
|
30
|
-
onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;
|
|
31
|
-
/**
|
|
32
|
-
* editor height change listener
|
|
33
|
-
*/
|
|
34
|
-
onHeightChange?: (value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore) => void;
|
|
35
|
-
/** Some data on the statistics editor. */
|
|
36
|
-
onStatistics?: (data: Statistics) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.
|
|
39
|
-
* it will be set to true when either the source `textarea` is focused,
|
|
40
|
-
* or it has an `autofocus` attribute and no other element is focused.
|
|
41
|
-
*/
|
|
42
|
-
autoFocus?: ITextAreaProps['autoFocus'];
|
|
43
|
-
/**
|
|
44
|
-
* The height of the editor.
|
|
45
|
-
* ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
|
|
46
|
-
*/
|
|
47
|
-
height?: CSSProperties['height'];
|
|
48
|
-
/**
|
|
49
|
-
* Custom toolbar heigth
|
|
50
|
-
* @default 29px
|
|
51
|
-
*
|
|
52
|
-
* @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
toolbarHeight?: number;
|
|
56
|
-
/**
|
|
57
|
-
* Show drag and drop tool. Set the height of the editor.
|
|
58
|
-
*/
|
|
59
|
-
visibleDragbar?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated use `visibleDragbar`
|
|
62
|
-
*/
|
|
63
|
-
visiableDragbar?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Show markdown preview.
|
|
66
|
-
*/
|
|
67
|
-
preview?: PreviewType;
|
|
68
|
-
/**
|
|
69
|
-
* Full screen display editor.
|
|
70
|
-
*/
|
|
71
|
-
fullscreen?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Disable `fullscreen` setting body styles
|
|
74
|
-
*/
|
|
75
|
-
overflow?: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Maximum drag height. `visibleDragbar=true`
|
|
78
|
-
*/
|
|
79
|
-
maxHeight?: number;
|
|
80
|
-
/**
|
|
81
|
-
* Minimum drag height. `visibleDragbar=true`
|
|
82
|
-
*/
|
|
83
|
-
minHeight?: number;
|
|
84
|
-
/**
|
|
85
|
-
* This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.
|
|
86
|
-
*/
|
|
87
|
-
previewOptions?: Omit<MarkdownPreviewProps, 'source'>;
|
|
88
|
-
/**
|
|
89
|
-
* Set the `textarea` related props.
|
|
90
|
-
*/
|
|
91
|
-
textareaProps?: ITextAreaProps;
|
|
92
|
-
/**
|
|
93
|
-
* Use div to replace TextArea or re-render TextArea
|
|
94
|
-
* @deprecated Please use ~~`renderTextarea`~~ -> `components`
|
|
95
|
-
*/
|
|
96
|
-
renderTextarea?: ITextAreaProps['renderTextarea'];
|
|
97
|
-
/**
|
|
98
|
-
* re-render element
|
|
99
|
-
*/
|
|
100
|
-
components?: {
|
|
101
|
-
/** Use div to replace TextArea or re-render TextArea */
|
|
102
|
-
textarea?: ITextAreaProps['renderTextarea'];
|
|
103
|
-
/**
|
|
104
|
-
* Override the default command element
|
|
105
|
-
* _`toolbar`_ < _`command[].render`_
|
|
106
|
-
*/
|
|
107
|
-
toolbar?: ICommand['render'];
|
|
108
|
-
/** Custom markdown preview */
|
|
109
|
-
preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;
|
|
110
|
-
};
|
|
111
|
-
/** Theme configuration */
|
|
112
|
-
'data-color-mode'?: 'light' | 'dark';
|
|
113
|
-
/**
|
|
114
|
-
* Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
|
115
|
-
* @default true
|
|
116
|
-
*/
|
|
117
|
-
highlightEnable?: boolean;
|
|
118
|
-
/**
|
|
119
|
-
* The number of characters to insert when pressing tab key.
|
|
120
|
-
* Default `2` spaces.
|
|
121
|
-
*/
|
|
122
|
-
tabSize?: number;
|
|
123
|
-
/**
|
|
124
|
-
* If `false`, the `tab` key inserts a tab character into the textarea. If `true`, the `tab` key executes default behavior e.g. focus shifts to next element.
|
|
125
|
-
*/
|
|
126
|
-
defaultTabEnable?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* You can create your own commands or reuse existing commands.
|
|
129
|
-
*/
|
|
130
|
-
commands?: ICommand[];
|
|
131
|
-
/**
|
|
132
|
-
* Filter or modify your commands.
|
|
133
|
-
* https://github.com/uiwjs/react-md-editor/issues/296
|
|
134
|
-
*/
|
|
135
|
-
commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;
|
|
136
|
-
/**
|
|
137
|
-
* You can create your own commands or reuse existing commands.
|
|
138
|
-
*/
|
|
139
|
-
extraCommands?: ICommand[];
|
|
140
|
-
/**
|
|
141
|
-
* Hide the tool bar
|
|
142
|
-
*/
|
|
143
|
-
hideToolbar?: boolean;
|
|
144
|
-
/** Whether to enable scrolling */
|
|
145
|
-
enableScroll?: boolean;
|
|
146
|
-
/** Toolbar on bottom */
|
|
147
|
-
toolbarBottom?: boolean;
|
|
148
|
-
/**
|
|
149
|
-
* The **`direction`** property sets the direction of text, table columns, and horizontal overflow. Use `rtl` for languages written from right to left (like Hebrew or Arabic), and `ltr` for those written from left to right (like English and most other languages).
|
|
150
|
-
*
|
|
151
|
-
* https://github.com/uiwjs/react-md-editor/issues/462
|
|
152
|
-
*/
|
|
153
|
-
direction?: CSSProperties['direction'];
|
|
154
|
-
}
|
|
7
|
+
import { reducer, EditorContext, ContextStore } from './Context';
|
|
8
|
+
import type { MDEditorProps } from './Types';
|
|
155
9
|
|
|
156
10
|
function setGroupPopFalse(data: Record<string, boolean> = {}) {
|
|
157
11
|
Object.keys(data).forEach((keyname) => {
|
package/src/Types.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
import type { MarkdownPreviewProps } from '@uiw/react-markdown-preview/nohighlight';
|
|
3
|
+
import type { ITextAreaProps } from './components/TextArea/index.nohighlight';
|
|
4
|
+
import type { ICommand, TextState } from './commands';
|
|
5
|
+
import type { ContextStore, PreviewType } from './Context';
|
|
6
|
+
|
|
7
|
+
export interface IProps {
|
|
8
|
+
prefixCls?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Statistics extends TextState {
|
|
13
|
+
/** total length of the document */
|
|
14
|
+
length: number;
|
|
15
|
+
/** Get the number of lines in the editor. */
|
|
16
|
+
lineCount: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {
|
|
20
|
+
/**
|
|
21
|
+
* The Markdown value.
|
|
22
|
+
*/
|
|
23
|
+
value?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Event handler for the `onChange` event.
|
|
26
|
+
*/
|
|
27
|
+
onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;
|
|
28
|
+
/**
|
|
29
|
+
* editor height change listener
|
|
30
|
+
*/
|
|
31
|
+
onHeightChange?: (value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore) => void;
|
|
32
|
+
/** Some data on the statistics editor. */
|
|
33
|
+
onStatistics?: (data: Statistics) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.
|
|
36
|
+
* it will be set to true when either the source `textarea` is focused,
|
|
37
|
+
* or it has an `autofocus` attribute and no other element is focused.
|
|
38
|
+
*/
|
|
39
|
+
autoFocus?: ITextAreaProps['autoFocus'];
|
|
40
|
+
/**
|
|
41
|
+
* The height of the editor.
|
|
42
|
+
* ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
|
|
43
|
+
*/
|
|
44
|
+
height?: CSSProperties['height'];
|
|
45
|
+
/**
|
|
46
|
+
* Custom toolbar heigth
|
|
47
|
+
* @default 29px
|
|
48
|
+
*
|
|
49
|
+
* @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
toolbarHeight?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Show drag and drop tool. Set the height of the editor.
|
|
55
|
+
*/
|
|
56
|
+
visibleDragbar?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated use `visibleDragbar`
|
|
59
|
+
*/
|
|
60
|
+
visiableDragbar?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Show markdown preview.
|
|
63
|
+
*/
|
|
64
|
+
preview?: PreviewType;
|
|
65
|
+
/**
|
|
66
|
+
* Full screen display editor.
|
|
67
|
+
*/
|
|
68
|
+
fullscreen?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Disable `fullscreen` setting body styles
|
|
71
|
+
*/
|
|
72
|
+
overflow?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Maximum drag height. `visibleDragbar=true`
|
|
75
|
+
*/
|
|
76
|
+
maxHeight?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Minimum drag height. `visibleDragbar=true`
|
|
79
|
+
*/
|
|
80
|
+
minHeight?: number;
|
|
81
|
+
/**
|
|
82
|
+
* This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.
|
|
83
|
+
*/
|
|
84
|
+
previewOptions?: Omit<MarkdownPreviewProps, 'source'>;
|
|
85
|
+
/**
|
|
86
|
+
* Set the `textarea` related props.
|
|
87
|
+
*/
|
|
88
|
+
textareaProps?: ITextAreaProps;
|
|
89
|
+
/**
|
|
90
|
+
* Use div to replace TextArea or re-render TextArea
|
|
91
|
+
* @deprecated Please use ~~`renderTextarea`~~ -> `components`
|
|
92
|
+
*/
|
|
93
|
+
renderTextarea?: ITextAreaProps['renderTextarea'];
|
|
94
|
+
/**
|
|
95
|
+
* re-render element
|
|
96
|
+
*/
|
|
97
|
+
components?: {
|
|
98
|
+
/** Use div to replace TextArea or re-render TextArea */
|
|
99
|
+
textarea?: ITextAreaProps['renderTextarea'];
|
|
100
|
+
/**
|
|
101
|
+
* Override the default command element
|
|
102
|
+
* _`toolbar`_ < _`command[].render`_
|
|
103
|
+
*/
|
|
104
|
+
toolbar?: ICommand['render'];
|
|
105
|
+
/** Custom markdown preview */
|
|
106
|
+
preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;
|
|
107
|
+
};
|
|
108
|
+
/** Theme configuration */
|
|
109
|
+
'data-color-mode'?: 'light' | 'dark';
|
|
110
|
+
/**
|
|
111
|
+
* Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
|
112
|
+
* @default true
|
|
113
|
+
*/
|
|
114
|
+
highlightEnable?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The number of characters to insert when pressing tab key.
|
|
117
|
+
* Default `2` spaces.
|
|
118
|
+
*/
|
|
119
|
+
tabSize?: number;
|
|
120
|
+
/**
|
|
121
|
+
* If `false`, the `tab` key inserts a tab character into the textarea. If `true`, the `tab` key executes default behavior e.g. focus shifts to next element.
|
|
122
|
+
*/
|
|
123
|
+
defaultTabEnable?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* You can create your own commands or reuse existing commands.
|
|
126
|
+
*/
|
|
127
|
+
commands?: ICommand[];
|
|
128
|
+
/**
|
|
129
|
+
* Filter or modify your commands.
|
|
130
|
+
* https://github.com/uiwjs/react-md-editor/issues/296
|
|
131
|
+
*/
|
|
132
|
+
commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;
|
|
133
|
+
/**
|
|
134
|
+
* You can create your own commands or reuse existing commands.
|
|
135
|
+
*/
|
|
136
|
+
extraCommands?: ICommand[];
|
|
137
|
+
/**
|
|
138
|
+
* Hide the tool bar
|
|
139
|
+
*/
|
|
140
|
+
hideToolbar?: boolean;
|
|
141
|
+
/** Whether to enable scrolling */
|
|
142
|
+
enableScroll?: boolean;
|
|
143
|
+
/** Toolbar on bottom */
|
|
144
|
+
toolbarBottom?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* The **`direction`** property sets the direction of text, table columns, and horizontal overflow. Use `rtl` for languages written from right to left (like Hebrew or Arabic), and `ltr` for those written from left to right (like English and most other languages).
|
|
147
|
+
*
|
|
148
|
+
* https://github.com/uiwjs/react-md-editor/issues/462
|
|
149
|
+
*/
|
|
150
|
+
direction?: CSSProperties['direction'];
|
|
151
|
+
}
|
package/src/commands/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { title4 } from './title4';
|
|
|
23
23
|
import { title5 } from './title5';
|
|
24
24
|
import { title6 } from './title6';
|
|
25
25
|
import { table } from './table';
|
|
26
|
+
import { issue } from './issue';
|
|
26
27
|
import { help } from './help';
|
|
27
28
|
|
|
28
29
|
export interface CommandOrchestrator {
|
|
@@ -202,6 +203,9 @@ export {
|
|
|
202
203
|
unorderedListCommand,
|
|
203
204
|
orderedListCommand,
|
|
204
205
|
checkedListCommand,
|
|
206
|
+
table,
|
|
207
|
+
issue,
|
|
208
|
+
help,
|
|
205
209
|
codeEdit,
|
|
206
210
|
codeLive,
|
|
207
211
|
codePreview,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useContext, useEffect } from 'react';
|
|
2
2
|
import { rehype } from 'rehype';
|
|
3
3
|
import rehypePrism from 'rehype-prism-plus';
|
|
4
|
-
import { IProps } from '../../
|
|
4
|
+
import { IProps } from '../../Types';
|
|
5
5
|
import { EditorContext } from '../../Context';
|
|
6
6
|
|
|
7
7
|
function html2Escape(sHtml: string) {
|
|
@@ -15,7 +15,7 @@ function html2Escape(sHtml: string) {
|
|
|
15
15
|
// })
|
|
16
16
|
.replace(
|
|
17
17
|
/[<&"]/g,
|
|
18
|
-
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record<string, string>)[c]
|
|
18
|
+
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' }) as Record<string, string>)[c],
|
|
19
19
|
)
|
|
20
20
|
);
|
|
21
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext, useEffect } from 'react';
|
|
2
|
-
import { IProps } from '../../
|
|
2
|
+
import { IProps } from '../../Types';
|
|
3
3
|
import { EditorContext, ExecuteCommandState } from '../../Context';
|
|
4
4
|
import { TextAreaCommandOrchestrator } from '../../commands';
|
|
5
5
|
import handleKeyDown from './handleKeyDown';
|
|
@@ -115,10 +115,12 @@ export default function handleKeyDown(
|
|
|
115
115
|
startStr = '\n* ';
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
if (
|
|
118
|
+
if (
|
|
119
|
+
currentLineStr.startsWith('- [ ]') ||
|
|
120
|
+
currentLineStr.startsWith('- [X]') ||
|
|
121
|
+
currentLineStr.startsWith('- [x]')
|
|
122
|
+
) {
|
|
119
123
|
startStr = '\n- [ ] ';
|
|
120
|
-
} else if (currentLineStr.startsWith('- [X]') || currentLineStr.startsWith('- [x]')) {
|
|
121
|
-
startStr = '\n- [X] ';
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
if (/^\d+.\s/.test(currentLineStr)) {
|
|
@@ -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 '../../
|
|
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 '../../
|
|
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
|
|