@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.
- package/README.md +47 -2
- package/dist/mdeditor.js +4114 -4095
- 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/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/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/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/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/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/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
|
@@ -0,0 +1,93 @@
|
|
|
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';
|
|
6
|
+
import shortcuts from './shortcuts';
|
|
7
|
+
import Textarea from './Textarea';
|
|
8
|
+
import { TextAreaCommandOrchestrator } from '../../commands';
|
|
9
|
+
import "./index.css";
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
export default function TextArea(props) {
|
|
12
|
+
var _ref = props || {},
|
|
13
|
+
{
|
|
14
|
+
prefixCls,
|
|
15
|
+
className,
|
|
16
|
+
onScroll,
|
|
17
|
+
renderTextarea
|
|
18
|
+
} = _ref,
|
|
19
|
+
otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
20
|
+
var {
|
|
21
|
+
markdown,
|
|
22
|
+
scrollTop,
|
|
23
|
+
commands,
|
|
24
|
+
extraCommands,
|
|
25
|
+
dispatch
|
|
26
|
+
} = useContext(EditorContext);
|
|
27
|
+
var textRef = React.useRef(null);
|
|
28
|
+
var executeRef = React.useRef();
|
|
29
|
+
var warp = /*#__PURE__*/React.createRef();
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
var state = {};
|
|
32
|
+
if (warp.current) {
|
|
33
|
+
state.textareaWarp = warp.current || undefined;
|
|
34
|
+
warp.current.scrollTop = scrollTop || 0;
|
|
35
|
+
}
|
|
36
|
+
if (dispatch) {
|
|
37
|
+
dispatch(_extends({}, state));
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, []);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (textRef.current && dispatch) {
|
|
43
|
+
var _commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);
|
|
44
|
+
executeRef.current = _commandOrchestrator;
|
|
45
|
+
dispatch({
|
|
46
|
+
textarea: textRef.current,
|
|
47
|
+
commandOrchestrator: _commandOrchestrator
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
+
}, []);
|
|
52
|
+
var textStyle = {
|
|
53
|
+
WebkitTextFillColor: 'initial',
|
|
54
|
+
overflow: 'auto'
|
|
55
|
+
};
|
|
56
|
+
return /*#__PURE__*/_jsx("div", {
|
|
57
|
+
ref: warp,
|
|
58
|
+
className: prefixCls + "-area " + (className || ''),
|
|
59
|
+
onScroll: onScroll,
|
|
60
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
61
|
+
className: prefixCls + "-text",
|
|
62
|
+
children: renderTextarea ? /*#__PURE__*/React.cloneElement(renderTextarea(_extends({}, otherProps, {
|
|
63
|
+
value: markdown,
|
|
64
|
+
autoComplete: 'off',
|
|
65
|
+
autoCorrect: 'off',
|
|
66
|
+
spellCheck: 'false',
|
|
67
|
+
autoCapitalize: 'off',
|
|
68
|
+
className: prefixCls + "-text-input",
|
|
69
|
+
style: {
|
|
70
|
+
WebkitTextFillColor: 'inherit',
|
|
71
|
+
overflow: 'auto'
|
|
72
|
+
}
|
|
73
|
+
}), {
|
|
74
|
+
dispatch,
|
|
75
|
+
onChange: otherProps.onChange,
|
|
76
|
+
shortcuts,
|
|
77
|
+
useContext: {
|
|
78
|
+
commands,
|
|
79
|
+
extraCommands,
|
|
80
|
+
commandOrchestrator: executeRef.current
|
|
81
|
+
}
|
|
82
|
+
}), {
|
|
83
|
+
ref: textRef
|
|
84
|
+
}) : /*#__PURE__*/_jsx(Fragment, {
|
|
85
|
+
children: /*#__PURE__*/_jsx(Textarea, _extends({
|
|
86
|
+
prefixCls: prefixCls
|
|
87
|
+
}, otherProps, {
|
|
88
|
+
style: textStyle
|
|
89
|
+
}))
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
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
|
export * from './commands';
|
|
5
6
|
export * from './commands/group';
|
|
6
7
|
export * from './utils/markdownUtils';
|
|
7
8
|
export * from './utils/InsertTextAtPosition';
|
|
8
9
|
export * from './Editor';
|
|
9
10
|
export * from './Context';
|
|
11
|
+
export * from './Types';
|
|
10
12
|
export { MarkdownUtil, commands };
|
|
11
13
|
export default MDEditor;
|
package/esm/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import MDEditor from './Editor';
|
|
2
2
|
import * as commands from './commands';
|
|
3
3
|
import * as MarkdownUtil from './utils/markdownUtils';
|
|
4
|
+
import "./index.css";
|
|
4
5
|
export * from './commands';
|
|
5
6
|
export * from './commands/group';
|
|
6
7
|
export * from './utils/markdownUtils';
|
|
7
8
|
export * from './utils/InsertTextAtPosition';
|
|
8
9
|
export * from './Editor';
|
|
9
10
|
export * from './Context';
|
|
11
|
+
export * from './Types';
|
|
10
12
|
export { MarkdownUtil, commands };
|
|
11
13
|
export default MDEditor;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import MDEditor from './Editor.nohighlight';
|
|
2
|
+
import * as commands from './commands';
|
|
3
|
+
import * as MarkdownUtil from './utils/markdownUtils';
|
|
4
|
+
import './index.less';
|
|
5
|
+
export * from './commands';
|
|
6
|
+
export * from './commands/group';
|
|
7
|
+
export * from './utils/markdownUtils';
|
|
8
|
+
export * from './utils/InsertTextAtPosition';
|
|
9
|
+
export * from './Editor.nohighlight';
|
|
10
|
+
export * from './Context';
|
|
11
|
+
export * from './Types';
|
|
12
|
+
export { MarkdownUtil, commands };
|
|
13
|
+
export default MDEditor;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import MDEditor from './Editor.nohighlight';
|
|
2
|
+
import * as commands from './commands';
|
|
3
|
+
import * as MarkdownUtil from './utils/markdownUtils';
|
|
4
|
+
import "./index.css";
|
|
5
|
+
export * from './commands';
|
|
6
|
+
export * from './commands/group';
|
|
7
|
+
export * from './utils/markdownUtils';
|
|
8
|
+
export * from './utils/InsertTextAtPosition';
|
|
9
|
+
export * from './Editor.nohighlight';
|
|
10
|
+
export * from './Context';
|
|
11
|
+
export * from './Types';
|
|
12
|
+
export { MarkdownUtil, commands };
|
|
13
|
+
export default MDEditor;
|
package/lib/Context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ICommand, TextAreaCommandOrchestrator } from './commands';
|
|
3
|
-
import { MDEditorProps } from './
|
|
3
|
+
import { MDEditorProps } from './Types';
|
|
4
4
|
export type PreviewType = 'live' | 'edit' | 'preview';
|
|
5
5
|
export interface ContextStore {
|
|
6
6
|
components?: MDEditorProps['components'];
|
package/lib/Editor.d.ts
CHANGED
|
@@ -1,152 +1,7 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import MarkdownPreview
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ContextStore, PreviewType } from './Context';
|
|
6
|
-
import './index.less';
|
|
7
|
-
export interface IProps {
|
|
8
|
-
prefixCls?: string;
|
|
9
|
-
className?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface Statistics extends TextState {
|
|
12
|
-
/** total length of the document */
|
|
13
|
-
length: number;
|
|
14
|
-
/** Get the number of lines in the editor. */
|
|
15
|
-
lineCount: number;
|
|
16
|
-
}
|
|
17
|
-
export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {
|
|
18
|
-
/**
|
|
19
|
-
* The Markdown value.
|
|
20
|
-
*/
|
|
21
|
-
value?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Event handler for the `onChange` event.
|
|
24
|
-
*/
|
|
25
|
-
onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;
|
|
26
|
-
/**
|
|
27
|
-
* editor height change listener
|
|
28
|
-
*/
|
|
29
|
-
onHeightChange?: (value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore) => void;
|
|
30
|
-
/** Some data on the statistics editor. */
|
|
31
|
-
onStatistics?: (data: Statistics) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.
|
|
34
|
-
* it will be set to true when either the source `textarea` is focused,
|
|
35
|
-
* or it has an `autofocus` attribute and no other element is focused.
|
|
36
|
-
*/
|
|
37
|
-
autoFocus?: ITextAreaProps['autoFocus'];
|
|
38
|
-
/**
|
|
39
|
-
* The height of the editor.
|
|
40
|
-
* ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
|
|
41
|
-
*/
|
|
42
|
-
height?: CSSProperties['height'];
|
|
43
|
-
/**
|
|
44
|
-
* Custom toolbar heigth
|
|
45
|
-
* @default 29px
|
|
46
|
-
*
|
|
47
|
-
* @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
toolbarHeight?: number;
|
|
51
|
-
/**
|
|
52
|
-
* Show drag and drop tool. Set the height of the editor.
|
|
53
|
-
*/
|
|
54
|
-
visibleDragbar?: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* @deprecated use `visibleDragbar`
|
|
57
|
-
*/
|
|
58
|
-
visiableDragbar?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Show markdown preview.
|
|
61
|
-
*/
|
|
62
|
-
preview?: PreviewType;
|
|
63
|
-
/**
|
|
64
|
-
* Full screen display editor.
|
|
65
|
-
*/
|
|
66
|
-
fullscreen?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Disable `fullscreen` setting body styles
|
|
69
|
-
*/
|
|
70
|
-
overflow?: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Maximum drag height. `visibleDragbar=true`
|
|
73
|
-
*/
|
|
74
|
-
maxHeight?: number;
|
|
75
|
-
/**
|
|
76
|
-
* Minimum drag height. `visibleDragbar=true`
|
|
77
|
-
*/
|
|
78
|
-
minHeight?: number;
|
|
79
|
-
/**
|
|
80
|
-
* This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.
|
|
81
|
-
*/
|
|
82
|
-
previewOptions?: Omit<MarkdownPreviewProps, 'source'>;
|
|
83
|
-
/**
|
|
84
|
-
* Set the `textarea` related props.
|
|
85
|
-
*/
|
|
86
|
-
textareaProps?: ITextAreaProps;
|
|
87
|
-
/**
|
|
88
|
-
* Use div to replace TextArea or re-render TextArea
|
|
89
|
-
* @deprecated Please use ~~`renderTextarea`~~ -> `components`
|
|
90
|
-
*/
|
|
91
|
-
renderTextarea?: ITextAreaProps['renderTextarea'];
|
|
92
|
-
/**
|
|
93
|
-
* re-render element
|
|
94
|
-
*/
|
|
95
|
-
components?: {
|
|
96
|
-
/** Use div to replace TextArea or re-render TextArea */
|
|
97
|
-
textarea?: ITextAreaProps['renderTextarea'];
|
|
98
|
-
/**
|
|
99
|
-
* Override the default command element
|
|
100
|
-
* _`toolbar`_ < _`command[].render`_
|
|
101
|
-
*/
|
|
102
|
-
toolbar?: ICommand['render'];
|
|
103
|
-
/** Custom markdown preview */
|
|
104
|
-
preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;
|
|
105
|
-
};
|
|
106
|
-
/** Theme configuration */
|
|
107
|
-
'data-color-mode'?: 'light' | 'dark';
|
|
108
|
-
/**
|
|
109
|
-
* Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
|
110
|
-
* @default true
|
|
111
|
-
*/
|
|
112
|
-
highlightEnable?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* The number of characters to insert when pressing tab key.
|
|
115
|
-
* Default `2` spaces.
|
|
116
|
-
*/
|
|
117
|
-
tabSize?: number;
|
|
118
|
-
/**
|
|
119
|
-
* 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.
|
|
120
|
-
*/
|
|
121
|
-
defaultTabEnable?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* You can create your own commands or reuse existing commands.
|
|
124
|
-
*/
|
|
125
|
-
commands?: ICommand[];
|
|
126
|
-
/**
|
|
127
|
-
* Filter or modify your commands.
|
|
128
|
-
* https://github.com/uiwjs/react-md-editor/issues/296
|
|
129
|
-
*/
|
|
130
|
-
commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;
|
|
131
|
-
/**
|
|
132
|
-
* You can create your own commands or reuse existing commands.
|
|
133
|
-
*/
|
|
134
|
-
extraCommands?: ICommand[];
|
|
135
|
-
/**
|
|
136
|
-
* Hide the tool bar
|
|
137
|
-
*/
|
|
138
|
-
hideToolbar?: boolean;
|
|
139
|
-
/** Whether to enable scrolling */
|
|
140
|
-
enableScroll?: boolean;
|
|
141
|
-
/** Toolbar on bottom */
|
|
142
|
-
toolbarBottom?: boolean;
|
|
143
|
-
/**
|
|
144
|
-
* 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).
|
|
145
|
-
*
|
|
146
|
-
* https://github.com/uiwjs/react-md-editor/issues/462
|
|
147
|
-
*/
|
|
148
|
-
direction?: CSSProperties['direction'];
|
|
149
|
-
}
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import MarkdownPreview from '@uiw/react-markdown-preview';
|
|
3
|
+
import { ContextStore } from './Context';
|
|
4
|
+
import type { MDEditorProps } from './Types';
|
|
150
5
|
export interface RefMDEditor extends ContextStore {
|
|
151
6
|
}
|
|
152
7
|
declare const InternalMDEditor: React.ForwardRefExoticComponent<MDEditorProps & React.RefAttributes<RefMDEditor>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import MarkdownPreview from '@uiw/react-markdown-preview/nohighlight';
|
|
3
|
+
import { ContextStore } from './Context';
|
|
4
|
+
import type { MDEditorProps } from './Types';
|
|
5
|
+
export interface RefMDEditor extends ContextStore {
|
|
6
|
+
}
|
|
7
|
+
declare const InternalMDEditor: React.ForwardRefExoticComponent<MDEditorProps & React.RefAttributes<RefMDEditor>>;
|
|
8
|
+
type EditorComponent = typeof InternalMDEditor & {
|
|
9
|
+
Markdown: typeof MarkdownPreview;
|
|
10
|
+
};
|
|
11
|
+
declare const Editor: EditorComponent;
|
|
12
|
+
export default Editor;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _nohighlight = _interopRequireDefault(require("@uiw/react-markdown-preview/nohighlight"));
|
|
14
|
+
var _index = _interopRequireDefault(require("./components/TextArea/index.nohighlight"));
|
|
15
|
+
var _Toolbar = _interopRequireDefault(require("./components/Toolbar"));
|
|
16
|
+
var _DragBar = _interopRequireDefault(require("./components/DragBar"));
|
|
17
|
+
var _commands = require("./commands");
|
|
18
|
+
var _Context = require("./Context");
|
|
19
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
+
var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
|
|
21
|
+
function setGroupPopFalse() {
|
|
22
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
23
|
+
Object.keys(data).forEach(function (keyname) {
|
|
24
|
+
data[keyname] = false;
|
|
25
|
+
});
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) {
|
|
29
|
+
var _ref = props || {},
|
|
30
|
+
_ref$prefixCls = _ref.prefixCls,
|
|
31
|
+
prefixCls = _ref$prefixCls === void 0 ? 'w-md-editor' : _ref$prefixCls,
|
|
32
|
+
className = _ref.className,
|
|
33
|
+
propsValue = _ref.value,
|
|
34
|
+
_ref$commands = _ref.commands,
|
|
35
|
+
commands = _ref$commands === void 0 ? (0, _commands.getCommands)() : _ref$commands,
|
|
36
|
+
commandsFilter = _ref.commandsFilter,
|
|
37
|
+
direction = _ref.direction,
|
|
38
|
+
_ref$extraCommands = _ref.extraCommands,
|
|
39
|
+
extraCommands = _ref$extraCommands === void 0 ? (0, _commands.getExtraCommands)() : _ref$extraCommands,
|
|
40
|
+
_ref$height = _ref.height,
|
|
41
|
+
height = _ref$height === void 0 ? 200 : _ref$height,
|
|
42
|
+
_ref$enableScroll = _ref.enableScroll,
|
|
43
|
+
enableScroll = _ref$enableScroll === void 0 ? true : _ref$enableScroll,
|
|
44
|
+
_ref$visibleDragbar = _ref.visibleDragbar,
|
|
45
|
+
visibleDragbar = _ref$visibleDragbar === void 0 ? typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true : _ref$visibleDragbar,
|
|
46
|
+
_ref$highlightEnable = _ref.highlightEnable,
|
|
47
|
+
highlightEnable = _ref$highlightEnable === void 0 ? true : _ref$highlightEnable,
|
|
48
|
+
_ref$preview = _ref.preview,
|
|
49
|
+
previewType = _ref$preview === void 0 ? 'live' : _ref$preview,
|
|
50
|
+
_ref$fullscreen = _ref.fullscreen,
|
|
51
|
+
fullscreen = _ref$fullscreen === void 0 ? false : _ref$fullscreen,
|
|
52
|
+
_ref$overflow = _ref.overflow,
|
|
53
|
+
overflow = _ref$overflow === void 0 ? true : _ref$overflow,
|
|
54
|
+
_ref$previewOptions = _ref.previewOptions,
|
|
55
|
+
previewOptions = _ref$previewOptions === void 0 ? {} : _ref$previewOptions,
|
|
56
|
+
textareaProps = _ref.textareaProps,
|
|
57
|
+
_ref$maxHeight = _ref.maxHeight,
|
|
58
|
+
maxHeight = _ref$maxHeight === void 0 ? 1200 : _ref$maxHeight,
|
|
59
|
+
_ref$minHeight = _ref.minHeight,
|
|
60
|
+
minHeight = _ref$minHeight === void 0 ? 100 : _ref$minHeight,
|
|
61
|
+
autoFocus = _ref.autoFocus,
|
|
62
|
+
_ref$tabSize = _ref.tabSize,
|
|
63
|
+
tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
|
|
64
|
+
_ref$defaultTabEnable = _ref.defaultTabEnable,
|
|
65
|
+
defaultTabEnable = _ref$defaultTabEnable === void 0 ? false : _ref$defaultTabEnable,
|
|
66
|
+
onChange = _ref.onChange,
|
|
67
|
+
onStatistics = _ref.onStatistics,
|
|
68
|
+
onHeightChange = _ref.onHeightChange,
|
|
69
|
+
hideToolbar = _ref.hideToolbar,
|
|
70
|
+
_ref$toolbarBottom = _ref.toolbarBottom,
|
|
71
|
+
toolbarBottom = _ref$toolbarBottom === void 0 ? false : _ref$toolbarBottom,
|
|
72
|
+
components = _ref.components,
|
|
73
|
+
renderTextarea = _ref.renderTextarea,
|
|
74
|
+
other = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
75
|
+
var cmds = commands.map(function (item) {
|
|
76
|
+
return commandsFilter ? commandsFilter(item, false) : item;
|
|
77
|
+
}).filter(Boolean);
|
|
78
|
+
var extraCmds = extraCommands.map(function (item) {
|
|
79
|
+
return commandsFilter ? commandsFilter(item, true) : item;
|
|
80
|
+
}).filter(Boolean);
|
|
81
|
+
var _useReducer = (0, _react.useReducer)(_Context.reducer, {
|
|
82
|
+
markdown: propsValue,
|
|
83
|
+
preview: previewType,
|
|
84
|
+
components: components,
|
|
85
|
+
height: height,
|
|
86
|
+
highlightEnable: highlightEnable,
|
|
87
|
+
tabSize: tabSize,
|
|
88
|
+
defaultTabEnable: defaultTabEnable,
|
|
89
|
+
scrollTop: 0,
|
|
90
|
+
scrollTopPreview: 0,
|
|
91
|
+
commands: cmds,
|
|
92
|
+
extraCommands: extraCmds,
|
|
93
|
+
fullscreen: fullscreen,
|
|
94
|
+
barPopup: {}
|
|
95
|
+
}),
|
|
96
|
+
_useReducer2 = (0, _slicedToArray2["default"])(_useReducer, 2),
|
|
97
|
+
state = _useReducer2[0],
|
|
98
|
+
dispatch = _useReducer2[1];
|
|
99
|
+
var container = (0, _react.useRef)(null);
|
|
100
|
+
var previewRef = (0, _react.useRef)(null);
|
|
101
|
+
var enableScrollRef = (0, _react.useRef)(enableScroll);
|
|
102
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
103
|
+
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
|
104
|
+
container: container.current,
|
|
105
|
+
dispatch: dispatch
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
(0, _react.useMemo)(function () {
|
|
109
|
+
return enableScrollRef.current = enableScroll;
|
|
110
|
+
}, [enableScroll]);
|
|
111
|
+
(0, _react.useEffect)(function () {
|
|
112
|
+
var stateInit = {};
|
|
113
|
+
if (container.current) {
|
|
114
|
+
stateInit.container = container.current || undefined;
|
|
115
|
+
}
|
|
116
|
+
stateInit.markdown = propsValue || '';
|
|
117
|
+
stateInit.barPopup = {};
|
|
118
|
+
if (dispatch) {
|
|
119
|
+
dispatch((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), stateInit));
|
|
120
|
+
}
|
|
121
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
122
|
+
}, []);
|
|
123
|
+
var cls = [className, 'wmde-markdown-var', direction ? "".concat(prefixCls, "-").concat(direction) : null, prefixCls, state.preview ? "".concat(prefixCls, "-show-").concat(state.preview) : null, state.fullscreen ? "".concat(prefixCls, "-fullscreen") : null].filter(Boolean).join(' ').trim();
|
|
124
|
+
(0, _react.useMemo)(function () {
|
|
125
|
+
return propsValue !== state.markdown && dispatch({
|
|
126
|
+
markdown: propsValue || ''
|
|
127
|
+
});
|
|
128
|
+
}, [propsValue, state.markdown]);
|
|
129
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
|
+
(0, _react.useMemo)(function () {
|
|
131
|
+
return previewType !== state.preview && dispatch({
|
|
132
|
+
preview: previewType
|
|
133
|
+
});
|
|
134
|
+
}, [previewType]);
|
|
135
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
|
+
(0, _react.useMemo)(function () {
|
|
137
|
+
return tabSize !== state.tabSize && dispatch({
|
|
138
|
+
tabSize: tabSize
|
|
139
|
+
});
|
|
140
|
+
}, [tabSize]);
|
|
141
|
+
(0, _react.useMemo)(function () {
|
|
142
|
+
return highlightEnable !== state.highlightEnable && dispatch({
|
|
143
|
+
highlightEnable: highlightEnable
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
147
|
+
[highlightEnable]);
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
|
+
(0, _react.useMemo)(function () {
|
|
150
|
+
return autoFocus !== state.autoFocus && dispatch({
|
|
151
|
+
autoFocus: autoFocus
|
|
152
|
+
});
|
|
153
|
+
}, [autoFocus]);
|
|
154
|
+
(0, _react.useMemo)(function () {
|
|
155
|
+
return fullscreen !== state.fullscreen && dispatch({
|
|
156
|
+
fullscreen: fullscreen
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
160
|
+
[fullscreen]);
|
|
161
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
162
|
+
(0, _react.useMemo)(function () {
|
|
163
|
+
return height !== state.height && dispatch({
|
|
164
|
+
height: height
|
|
165
|
+
});
|
|
166
|
+
}, [height]);
|
|
167
|
+
(0, _react.useMemo)(function () {
|
|
168
|
+
return height !== state.height && onHeightChange && onHeightChange(state.height, height, state);
|
|
169
|
+
}, [height, onHeightChange, state]);
|
|
170
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
171
|
+
(0, _react.useMemo)(function () {
|
|
172
|
+
return commands !== state.commands && dispatch({
|
|
173
|
+
commands: cmds
|
|
174
|
+
});
|
|
175
|
+
}, [props.commands]);
|
|
176
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
|
+
(0, _react.useMemo)(function () {
|
|
178
|
+
return extraCommands !== state.extraCommands && dispatch({
|
|
179
|
+
extraCommands: extraCmds
|
|
180
|
+
});
|
|
181
|
+
}, [props.extraCommands]);
|
|
182
|
+
var textareaDomRef = (0, _react.useRef)();
|
|
183
|
+
var active = (0, _react.useRef)('preview');
|
|
184
|
+
var initScroll = (0, _react.useRef)(false);
|
|
185
|
+
(0, _react.useMemo)(function () {
|
|
186
|
+
textareaDomRef.current = state.textareaWarp;
|
|
187
|
+
if (state.textareaWarp) {
|
|
188
|
+
state.textareaWarp.addEventListener('mouseover', function () {
|
|
189
|
+
active.current = 'text';
|
|
190
|
+
});
|
|
191
|
+
state.textareaWarp.addEventListener('mouseleave', function () {
|
|
192
|
+
active.current = 'preview';
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}, [state.textareaWarp]);
|
|
196
|
+
var handleScroll = function handleScroll(e, type) {
|
|
197
|
+
if (!enableScrollRef.current) return;
|
|
198
|
+
var textareaDom = textareaDomRef.current;
|
|
199
|
+
var previewDom = previewRef.current ? previewRef.current : undefined;
|
|
200
|
+
if (!initScroll.current) {
|
|
201
|
+
active.current = type;
|
|
202
|
+
initScroll.current = true;
|
|
203
|
+
}
|
|
204
|
+
if (textareaDom && previewDom) {
|
|
205
|
+
var scale = (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);
|
|
206
|
+
if (e.target === textareaDom && active.current === 'text') {
|
|
207
|
+
previewDom.scrollTop = textareaDom.scrollTop / scale;
|
|
208
|
+
}
|
|
209
|
+
if (e.target === previewDom && active.current === 'preview') {
|
|
210
|
+
textareaDom.scrollTop = previewDom.scrollTop * scale;
|
|
211
|
+
}
|
|
212
|
+
var scrollTop = 0;
|
|
213
|
+
if (active.current === 'text') {
|
|
214
|
+
scrollTop = textareaDom.scrollTop || 0;
|
|
215
|
+
} else if (active.current === 'preview') {
|
|
216
|
+
scrollTop = previewDom.scrollTop || 0;
|
|
217
|
+
}
|
|
218
|
+
dispatch({
|
|
219
|
+
scrollTop: scrollTop
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var previewClassName = "".concat(prefixCls, "-preview ").concat(previewOptions.className || '');
|
|
224
|
+
var handlePreviewScroll = function handlePreviewScroll(e) {
|
|
225
|
+
return handleScroll(e, 'preview');
|
|
226
|
+
};
|
|
227
|
+
var mdPreview = (0, _react.useMemo)(function () {
|
|
228
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
229
|
+
ref: previewRef,
|
|
230
|
+
className: previewClassName,
|
|
231
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_nohighlight["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, previewOptions), {}, {
|
|
232
|
+
onScroll: handlePreviewScroll,
|
|
233
|
+
source: state.markdown || ''
|
|
234
|
+
}))
|
|
235
|
+
});
|
|
236
|
+
}, [previewClassName, previewOptions, state.markdown]);
|
|
237
|
+
var preview = (components === null || components === void 0 ? void 0 : components.preview) && (components === null || components === void 0 ? void 0 : components.preview(state.markdown || '', state, dispatch));
|
|
238
|
+
if (preview && /*#__PURE__*/_react["default"].isValidElement(preview)) {
|
|
239
|
+
mdPreview = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
240
|
+
className: previewClassName,
|
|
241
|
+
ref: previewRef,
|
|
242
|
+
onScroll: handlePreviewScroll,
|
|
243
|
+
children: preview
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
var containerStyle = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other.style), {}, {
|
|
247
|
+
height: state.height || '100%'
|
|
248
|
+
});
|
|
249
|
+
var containerClick = function containerClick() {
|
|
250
|
+
return dispatch({
|
|
251
|
+
barPopup: (0, _objectSpread2["default"])({}, setGroupPopFalse(state.barPopup))
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
var dragBarChange = function dragBarChange(newHeight) {
|
|
255
|
+
return dispatch({
|
|
256
|
+
height: newHeight
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
var changeHandle = function changeHandle(evn) {
|
|
260
|
+
onChange && onChange(evn.target.value, evn, state);
|
|
261
|
+
if (textareaProps && textareaProps.onChange) {
|
|
262
|
+
textareaProps.onChange(evn);
|
|
263
|
+
}
|
|
264
|
+
if (state.textarea && state.textarea instanceof HTMLTextAreaElement && onStatistics) {
|
|
265
|
+
var obj = new _commands.TextAreaCommandOrchestrator(state.textarea);
|
|
266
|
+
var objState = obj.getState() || {};
|
|
267
|
+
onStatistics((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, objState), {}, {
|
|
268
|
+
lineCount: evn.target.value.split('\n').length,
|
|
269
|
+
length: evn.target.value.length
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Context.EditorContext.Provider, {
|
|
274
|
+
value: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
|
275
|
+
dispatch: dispatch
|
|
276
|
+
}),
|
|
277
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
278
|
+
ref: container,
|
|
279
|
+
className: cls
|
|
280
|
+
}, other), {}, {
|
|
281
|
+
onClick: containerClick,
|
|
282
|
+
style: containerStyle,
|
|
283
|
+
children: [!hideToolbar && !toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
|
|
284
|
+
prefixCls: prefixCls,
|
|
285
|
+
overflow: overflow,
|
|
286
|
+
toolbarBottom: toolbarBottom
|
|
287
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
288
|
+
className: "".concat(prefixCls, "-content"),
|
|
289
|
+
children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
290
|
+
className: "".concat(prefixCls, "-input"),
|
|
291
|
+
prefixCls: prefixCls,
|
|
292
|
+
autoFocus: autoFocus
|
|
293
|
+
}, textareaProps), {}, {
|
|
294
|
+
onChange: changeHandle,
|
|
295
|
+
renderTextarea: (components === null || components === void 0 ? void 0 : components.textarea) || renderTextarea,
|
|
296
|
+
onScroll: function onScroll(e) {
|
|
297
|
+
return handleScroll(e, 'text');
|
|
298
|
+
}
|
|
299
|
+
})), /(live|preview)/.test(state.preview || '') && mdPreview]
|
|
300
|
+
}), visibleDragbar && !state.fullscreen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_DragBar["default"], {
|
|
301
|
+
prefixCls: prefixCls,
|
|
302
|
+
height: state.height,
|
|
303
|
+
maxHeight: maxHeight,
|
|
304
|
+
minHeight: minHeight,
|
|
305
|
+
onChange: dragBarChange
|
|
306
|
+
}), !hideToolbar && toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
|
|
307
|
+
prefixCls: prefixCls,
|
|
308
|
+
overflow: overflow,
|
|
309
|
+
toolbarBottom: toolbarBottom
|
|
310
|
+
})]
|
|
311
|
+
}))
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
var Editor = InternalMDEditor;
|
|
315
|
+
Editor.Markdown = _nohighlight["default"];
|
|
316
|
+
var _default = exports["default"] = Editor;
|
|
317
|
+
module.exports = exports.default;
|