@uiw/react-md-editor 3.23.1 → 3.23.3
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 +38 -0
- package/dist/mdeditor.css +1 -1
- package/dist/mdeditor.js +3964 -1720
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Editor.d.ts +5 -4
- package/esm/Editor.js +5 -5
- package/esm/index.css +1 -1
- package/esm/index.less +1 -1
- package/lib/Editor.d.ts +5 -4
- package/lib/Editor.js +5 -5
- package/lib/index.less +1 -1
- package/markdown-editor.css +1 -1
- package/package.json +1 -1
- package/src/Editor.tsx +226 -223
- package/src/index.less +1 -1
package/esm/Editor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { CSSProperties
|
|
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
|
-
|
|
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
|
|
156
|
-
export default
|
|
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
|
|
255
|
-
|
|
256
|
-
export default
|
|
253
|
+
});
|
|
254
|
+
var Editor = InternalMDEditor;
|
|
255
|
+
Editor.Markdown = MarkdownPreview;
|
|
256
|
+
export default Editor;
|
package/esm/index.css
CHANGED
package/esm/index.less
CHANGED
package/lib/Editor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { CSSProperties
|
|
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
|
-
|
|
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
|
|
156
|
-
export default
|
|
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
|
|
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
|
|
315
|
-
|
|
316
|
-
var _default =
|
|
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/lib/index.less
CHANGED
package/markdown-editor.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.23.
|
|
3
|
+
"version": "3.23.3",
|
|
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>",
|
package/src/Editor.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
[
|
|
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
|
-
[
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
314
|
-
|
|
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
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
+
};
|
|
325
326
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
376
|
-
{
|
|
377
|
-
|
|
378
|
-
|
|
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
|
-
{
|
|
394
|
+
{!hideToolbar && toolbarBottom && (
|
|
395
|
+
<Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
|
|
396
|
+
)}
|
|
383
397
|
</div>
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
403
|
+
type EditorComponent = typeof InternalMDEditor & {
|
|
404
|
+
Markdown: typeof MarkdownPreview;
|
|
405
|
+
};
|
|
404
406
|
|
|
405
|
-
|
|
407
|
+
const Editor = InternalMDEditor as EditorComponent;
|
|
408
|
+
Editor.Markdown = MarkdownPreview;
|
|
406
409
|
|
|
407
|
-
export default
|
|
410
|
+
export default Editor;
|