@uiw/react-md-editor 3.17.0 → 3.18.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 +19 -1
- package/dist/mdeditor.css +22 -6
- package/dist/mdeditor.js +944 -698
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.d.ts +1 -0
- package/esm/Editor.d.ts +5 -0
- package/esm/Editor.js +21 -13
- package/esm/Editor.js.map +4 -4
- package/esm/components/DragBar/index.css +1 -0
- package/esm/components/DragBar/index.less +1 -0
- package/esm/components/Toolbar/Child.js +0 -1
- package/esm/components/Toolbar/Child.js.map +2 -2
- package/esm/components/Toolbar/index.css +6 -1
- package/esm/components/Toolbar/index.d.ts +0 -2
- package/esm/components/Toolbar/index.js +0 -4
- package/esm/components/Toolbar/index.js.map +2 -3
- package/esm/components/Toolbar/index.less +6 -1
- package/esm/index.css +10 -3
- package/esm/index.less +9 -3
- package/lib/Context.d.ts +1 -0
- package/lib/Editor.d.ts +5 -0
- package/lib/Editor.js +24 -15
- package/lib/Editor.js.map +5 -5
- package/lib/components/DragBar/index.less +1 -0
- package/lib/components/Toolbar/Child.js +0 -1
- package/lib/components/Toolbar/Child.js.map +2 -2
- package/lib/components/Toolbar/index.d.ts +0 -2
- package/lib/components/Toolbar/index.js +0 -5
- package/lib/components/Toolbar/index.js.map +2 -3
- package/lib/components/Toolbar/index.less +6 -1
- package/lib/index.less +9 -3
- package/markdown-editor.css +17 -4
- package/package.json +2 -2
- package/src/Editor.tsx +30 -21
- package/src/components/DragBar/index.less +1 -0
- package/src/components/Toolbar/Child.tsx +1 -1
- package/src/components/Toolbar/index.less +6 -1
- package/src/components/Toolbar/index.tsx +2 -3
- package/src/index.less +9 -3
package/esm/Context.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
|
|
|
38
38
|
shortcuts?: ((e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand<string>[], commandOrchestrator?: TextAreaCommandOrchestrator | undefined, dispatch?: React.Dispatch<ContextStore> | undefined, state?: ExecuteCommandState | undefined) => void) | undefined;
|
|
39
39
|
}) => JSX.Element) | undefined;
|
|
40
40
|
toolbar?: ((command: ICommand<string>, disabled: boolean, executeCommand: (command: ICommand<string>, name?: string | undefined) => void, index: number) => void | React.ReactElement<any, string | React.JSXElementConstructor<any>> | null | undefined) | undefined;
|
|
41
|
+
preview?: ((source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element) | undefined;
|
|
41
42
|
} | undefined;
|
|
42
43
|
commands?: ICommand<string>[] | undefined;
|
|
43
44
|
extraCommands?: ICommand<string>[] | undefined;
|
package/esm/Editor.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
35
35
|
/**
|
|
36
36
|
* Custom toolbar heigth
|
|
37
37
|
* @default 29px
|
|
38
|
+
*
|
|
39
|
+
* @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427
|
|
40
|
+
*
|
|
38
41
|
*/
|
|
39
42
|
toolbarHeight?: number;
|
|
40
43
|
/**
|
|
@@ -89,6 +92,8 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
89
92
|
* _`toolbar`_ < _`command[].render`_
|
|
90
93
|
*/
|
|
91
94
|
toolbar?: ICommand['render'];
|
|
95
|
+
/** Custom markdown preview */
|
|
96
|
+
preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;
|
|
92
97
|
};
|
|
93
98
|
/**
|
|
94
99
|
* Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
package/esm/Editor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "extraCommands", "height", "
|
|
3
|
+
var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "tabSize", "defaultTabEnable", "onChange", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
|
|
4
4
|
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
|
|
5
5
|
import MarkdownPreview from '@uiw/react-markdown-preview';
|
|
6
6
|
import TextArea from './components/TextArea';
|
|
@@ -33,7 +33,6 @@ var InternalMDEditor = (props, ref) => {
|
|
|
33
33
|
commandsFilter,
|
|
34
34
|
extraCommands = getExtraCommands(),
|
|
35
35
|
height = 200,
|
|
36
|
-
toolbarHeight = 29,
|
|
37
36
|
enableScroll = true,
|
|
38
37
|
visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,
|
|
39
38
|
highlightEnable = true,
|
|
@@ -141,7 +140,7 @@ var InternalMDEditor = (props, ref) => {
|
|
|
141
140
|
var handleScroll = (e, type) => {
|
|
142
141
|
if (!enableScrollRef.current) return;
|
|
143
142
|
var textareaDom = textareaDomRef.current;
|
|
144
|
-
var previewDom = previewRef.current ? previewRef.current
|
|
143
|
+
var previewDom = previewRef.current ? previewRef.current : undefined;
|
|
145
144
|
|
|
146
145
|
if (!initScroll.current) {
|
|
147
146
|
active.current = type;
|
|
@@ -173,12 +172,26 @@ var InternalMDEditor = (props, ref) => {
|
|
|
173
172
|
}
|
|
174
173
|
};
|
|
175
174
|
|
|
176
|
-
var
|
|
177
|
-
|
|
175
|
+
var previewClassName = prefixCls + "-preview " + (previewOptions.className || '');
|
|
176
|
+
var mdPreview = useMemo(() => /*#__PURE__*/_jsx("div", {
|
|
178
177
|
ref: previewRef,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
className: previewClassName,
|
|
179
|
+
children: /*#__PURE__*/_jsx(MarkdownPreview, _extends({}, previewOptions, {
|
|
180
|
+
onScroll: e => handleScroll(e, 'preview'),
|
|
181
|
+
source: state.markdown || ''
|
|
182
|
+
}))
|
|
183
|
+
}), [previewClassName, previewOptions, state.markdown]);
|
|
184
|
+
var preview = (components == null ? void 0 : components.preview) && (components == null ? void 0 : components.preview(state.markdown || '', state, dispatch));
|
|
185
|
+
|
|
186
|
+
if (preview && /*#__PURE__*/React.isValidElement(preview)) {
|
|
187
|
+
mdPreview = /*#__PURE__*/_jsx("div", {
|
|
188
|
+
className: previewClassName,
|
|
189
|
+
ref: previewRef,
|
|
190
|
+
onScroll: e => handleScroll(e, 'preview'),
|
|
191
|
+
children: preview
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
182
195
|
return /*#__PURE__*/_jsx(EditorContext.Provider, {
|
|
183
196
|
value: _extends({}, state, {
|
|
184
197
|
dispatch
|
|
@@ -197,14 +210,10 @@ var InternalMDEditor = (props, ref) => {
|
|
|
197
210
|
}),
|
|
198
211
|
children: [!hideToolbar && !toolbarBottom && /*#__PURE__*/_jsx(Toolbar, {
|
|
199
212
|
prefixCls: prefixCls,
|
|
200
|
-
height: toolbarHeight,
|
|
201
213
|
overflow: overflow,
|
|
202
214
|
toolbarBottom: toolbarBottom
|
|
203
215
|
}), /*#__PURE__*/_jsxs("div", {
|
|
204
216
|
className: prefixCls + "-content",
|
|
205
|
-
style: {
|
|
206
|
-
height: "calc(100% - " + toolbarHeight + "px)"
|
|
207
|
-
},
|
|
208
217
|
children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/_jsx(TextArea, _extends({
|
|
209
218
|
className: prefixCls + "-input",
|
|
210
219
|
prefixCls: prefixCls,
|
|
@@ -232,7 +241,6 @@ var InternalMDEditor = (props, ref) => {
|
|
|
232
241
|
}
|
|
233
242
|
}), !hideToolbar && toolbarBottom && /*#__PURE__*/_jsx(Toolbar, {
|
|
234
243
|
prefixCls: prefixCls,
|
|
235
|
-
height: toolbarHeight,
|
|
236
244
|
overflow: overflow,
|
|
237
245
|
toolbarBottom: toolbarBottom
|
|
238
246
|
})]
|
package/esm/Editor.js.map
CHANGED
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"commandsFilter",
|
|
33
33
|
"extraCommands",
|
|
34
34
|
"height",
|
|
35
|
-
"toolbarHeight",
|
|
36
35
|
"enableScroll",
|
|
37
36
|
"visibleDragbar",
|
|
38
37
|
"visiableDragbar",
|
|
@@ -86,12 +85,13 @@
|
|
|
86
85
|
"type",
|
|
87
86
|
"textareaDom",
|
|
88
87
|
"previewDom",
|
|
89
|
-
"mdp",
|
|
90
88
|
"scale",
|
|
91
89
|
"scrollHeight",
|
|
92
90
|
"offsetHeight",
|
|
93
91
|
"target",
|
|
92
|
+
"previewClassName",
|
|
94
93
|
"mdPreview",
|
|
94
|
+
"isValidElement",
|
|
95
95
|
"style",
|
|
96
96
|
"test",
|
|
97
97
|
"evn",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"../src/Editor.tsx"
|
|
106
106
|
],
|
|
107
107
|
"sourcesContent": [
|
|
108
|
-
"import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties } from 'react';\nimport MarkdownPreview, { MarkdownPreviewProps, MarkdownPreviewRef } from '@uiw/react-markdown-preview';\nimport TextArea, { ITextAreaProps } from './components/TextArea';\nimport Toolbar from './components/Toolbar';\nimport DragBar from './components/DragBar';\nimport { getCommands, getExtraCommands, ICommand } from './commands';\nimport { reducer, EditorContext, ContextStore, PreviewType } from './Context';\nimport './index.less';\n\nexport interface IProps {\n prefixCls?: string;\n className?: string;\n}\n\nexport interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {\n /**\n * The Markdown value.\n */\n value?: string;\n /**\n * Event handler for the `onChange` event.\n */\n onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;\n /**\n * editor height change listener\n */\n onHeightChange?: (value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore) => void;\n /**\n * Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.\n * it will be set to true when either the source `textarea` is focused,\n * or it has an `autofocus` attribute and no other element is focused.\n */\n autoFocus?: ITextAreaProps['autoFocus'];\n /**\n * The height of the editor.\n * ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.\n */\n height?: CSSProperties['height'];\n /**\n * Custom toolbar heigth\n * @default 29px\n */\n toolbarHeight?: number;\n /**\n * Show drag and drop tool. Set the height of the editor.\n */\n visibleDragbar?: boolean;\n /**\n * @deprecated use `visibleDragbar`\n */\n visiableDragbar?: boolean;\n /**\n * Show markdown preview.\n */\n preview?: PreviewType;\n /**\n * Full screen display editor.\n */\n fullscreen?: boolean;\n /**\n * Disable `fullscreen` setting body styles\n */\n overflow?: boolean;\n /**\n * Maximum drag height. `visibleDragbar=true`\n */\n maxHeight?: number;\n /**\n * Minimum drag height. `visibleDragbar=true`\n */\n minHeight?: number;\n /**\n * This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.\n */\n previewOptions?: Omit<MarkdownPreviewProps, 'source'>;\n /**\n * Set the `textarea` related props.\n */\n textareaProps?: ITextAreaProps;\n /**\n * Use div to replace TextArea or re-render TextArea\n * @deprecated Please use ~~`renderTextarea`~~ -> `components`\n */\n renderTextarea?: ITextAreaProps['renderTextarea'];\n /**\n * re-render element\n */\n components?: {\n /** Use div to replace TextArea or re-render TextArea */\n textarea?: ITextAreaProps['renderTextarea'];\n /**\n * Override the default command element\n * _`toolbar`_ < _`command[].render`_\n */\n toolbar?: ICommand['render'];\n };\n /**\n * Disable editing area code highlighting. The value is `false`, which increases the editing speed.\n * @default true\n */\n highlightEnable?: boolean;\n /**\n * The number of characters to insert when pressing tab key.\n * Default `2` spaces.\n */\n tabSize?: number;\n /**\n * 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.\n */\n defaultTabEnable?: boolean;\n /**\n * You can create your own commands or reuse existing commands.\n */\n commands?: ICommand[];\n /**\n * Filter or modify your commands.\n * https://github.com/uiwjs/react-md-editor/issues/296\n */\n commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;\n /**\n * You can create your own commands or reuse existing commands.\n */\n extraCommands?: ICommand[];\n /**\n * Hide the tool bar\n */\n hideToolbar?: boolean;\n /** Whether to enable scrolling */\n enableScroll?: boolean;\n /** Toolbar on bottom */\n toolbarBottom?: boolean;\n}\n\nfunction setGroupPopFalse(data: Record<string, boolean> = {}) {\n Object.keys(data).forEach((keyname) => {\n data[keyname] = false;\n });\n return data;\n}\n\nconst InternalMDEditor = (\n props: MDEditorProps,\n ref?: ((instance: ContextStore) => void) | React.RefObject<ContextStore> | null,\n) => {\n const {\n prefixCls = 'w-md-editor',\n className,\n value: propsValue,\n commands = getCommands(),\n commandsFilter,\n extraCommands = getExtraCommands(),\n height = 200,\n toolbarHeight = 29,\n enableScroll = true,\n visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,\n highlightEnable = true,\n preview: previewType = 'live',\n fullscreen = false,\n overflow = true,\n previewOptions = {},\n textareaProps,\n maxHeight = 1200,\n minHeight = 100,\n autoFocus,\n tabSize = 2,\n defaultTabEnable = false,\n onChange,\n onHeightChange,\n hideToolbar,\n toolbarBottom = false,\n components,\n renderTextarea,\n ...other\n } = props || {};\n const cmds = commands\n .map((item) => (commandsFilter ? commandsFilter(item, false) : item))\n .filter(Boolean) as ICommand[];\n const extraCmds = extraCommands\n .map((item) => (commandsFilter ? commandsFilter(item, true) : item))\n .filter(Boolean) as ICommand[];\n let [state, dispatch] = useReducer(reducer, {\n markdown: propsValue,\n preview: previewType,\n components,\n height,\n highlightEnable,\n tabSize,\n defaultTabEnable,\n scrollTop: 0,\n scrollTopPreview: 0,\n commands: cmds,\n extraCommands: extraCmds,\n fullscreen,\n barPopup: {},\n });\n const container = useRef<HTMLDivElement>(null);\n const previewRef = useRef<MarkdownPreviewRef>(null);\n const enableScrollRef = useRef(enableScroll);\n\n useImperativeHandle(ref, () => ({ ...state }));\n useMemo(() => (enableScrollRef.current = enableScroll), [enableScroll]);\n useEffect(() => {\n const stateInit: ContextStore = {};\n if (container.current) {\n stateInit.container = container.current || undefined;\n }\n stateInit.markdown = propsValue || '';\n stateInit.barPopup = {};\n if (dispatch) {\n dispatch({ ...state, ...stateInit });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const cls = [\n className,\n 'wmde-markdown-var',\n prefixCls,\n state.preview ? `${prefixCls}-show-${state.preview}` : null,\n state.fullscreen ? `${prefixCls}-fullscreen` : null,\n ]\n .filter(Boolean)\n .join(' ')\n .trim();\n\n useMemo(\n () => propsValue !== state.markdown && dispatch({ markdown: propsValue || '' }),\n [propsValue, state.markdown],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);\n useMemo(\n () => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [highlightEnable],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);\n useMemo(\n () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [fullscreen],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => height !== state.height && dispatch({ height: height }), [height]);\n useMemo(\n () => height !== state.height && onHeightChange && onHeightChange(state.height, height, state),\n [height, onHeightChange, state],\n );\n\n const textareaDomRef = useRef<HTMLDivElement>();\n const active = useRef<'text' | 'preview'>('preview');\n const initScroll = useRef(false);\n\n useMemo(() => {\n textareaDomRef.current = state.textareaWarp;\n if (state.textareaWarp) {\n state.textareaWarp.addEventListener('mouseover', () => {\n active.current = 'text';\n });\n state.textareaWarp.addEventListener('mouseleave', () => {\n active.current = 'preview';\n });\n }\n }, [state.textareaWarp]);\n\n const handleScroll = (e: React.UIEvent<HTMLDivElement>, type: 'text' | 'preview') => {\n if (!enableScrollRef.current) return;\n const textareaDom = textareaDomRef.current;\n const previewDom = previewRef.current ? previewRef.current.mdp.current : undefined;\n if (!initScroll.current) {\n active.current = type;\n initScroll.current = true;\n }\n if (textareaDom && previewDom) {\n const scale =\n (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);\n if (e.target === textareaDom && active.current === 'text') {\n previewDom.scrollTop = textareaDom.scrollTop / scale;\n }\n if (e.target === previewDom && active.current === 'preview') {\n textareaDom.scrollTop = previewDom.scrollTop * scale;\n }\n let scrollTop = 0;\n if (active.current === 'text') {\n scrollTop = textareaDom.scrollTop || 0;\n } else if (active.current === 'preview') {\n scrollTop = previewDom.scrollTop || 0;\n }\n dispatch({ scrollTop });\n }\n };\n\n const mdPreview = useMemo(\n () => (\n <MarkdownPreview\n {...previewOptions}\n onScroll={(e) => handleScroll(e, 'preview')}\n ref={previewRef}\n source={state.markdown || ''}\n className={`${prefixCls}-preview ${previewOptions.className || ''}`}\n />\n ),\n [prefixCls, previewOptions, state.markdown],\n );\n return (\n <EditorContext.Provider value={{ ...state, dispatch }}>\n <div\n ref={container}\n className={cls}\n {...other}\n onClick={() => {\n dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });\n }}\n style={{\n ...other.style,\n height: state.height || '100%',\n }}\n >\n {!hideToolbar && !toolbarBottom && (\n <Toolbar prefixCls={prefixCls} height={toolbarHeight} overflow={overflow} toolbarBottom={toolbarBottom} />\n )}\n <div\n className={`${prefixCls}-content`}\n style={{\n height: `calc(100% - ${toolbarHeight}px)`,\n }}\n >\n {/(edit|live)/.test(state.preview || '') && (\n <TextArea\n className={`${prefixCls}-input`}\n prefixCls={prefixCls}\n autoFocus={autoFocus}\n {...textareaProps}\n onChange={(evn) => {\n onChange && onChange(evn.target.value, evn, state);\n if (textareaProps && textareaProps.onChange) {\n textareaProps.onChange(evn);\n }\n }}\n renderTextarea={components?.textarea || renderTextarea}\n onScroll={(e) => handleScroll(e, 'text')}\n />\n )}\n {/(live|preview)/.test(state.preview || '') && mdPreview}\n </div>\n {visibleDragbar && !state.fullscreen && (\n <DragBar\n prefixCls={prefixCls}\n height={state.height as number}\n maxHeight={maxHeight!}\n minHeight={minHeight!}\n onChange={(newHeight) => {\n dispatch({ height: newHeight });\n }}\n />\n )}\n {!hideToolbar && toolbarBottom && (\n <Toolbar prefixCls={prefixCls} height={toolbarHeight} overflow={overflow} toolbarBottom={toolbarBottom} />\n )}\n </div>\n </EditorContext.Provider>\n );\n};\n\nconst mdEditor = React.forwardRef<ContextStore, MDEditorProps>(InternalMDEditor);\n\ntype MDEditor = typeof mdEditor & {\n Markdown: typeof MarkdownPreview;\n};\n\n(mdEditor as MDEditor).Markdown = MarkdownPreview;\n\nexport default mdEditor as MDEditor;\n"
|
|
108
|
+
"import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, CSSProperties } from 'react';\nimport MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';\nimport TextArea, { ITextAreaProps } from './components/TextArea';\nimport Toolbar from './components/Toolbar';\nimport DragBar from './components/DragBar';\nimport { getCommands, getExtraCommands, ICommand } from './commands';\nimport { reducer, EditorContext, ContextStore, PreviewType } from './Context';\nimport './index.less';\n\nexport interface IProps {\n prefixCls?: string;\n className?: string;\n}\n\nexport interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {\n /**\n * The Markdown value.\n */\n value?: string;\n /**\n * Event handler for the `onChange` event.\n */\n onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;\n /**\n * editor height change listener\n */\n onHeightChange?: (value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore) => void;\n /**\n * Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.\n * it will be set to true when either the source `textarea` is focused,\n * or it has an `autofocus` attribute and no other element is focused.\n */\n autoFocus?: ITextAreaProps['autoFocus'];\n /**\n * The height of the editor.\n * ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.\n */\n height?: CSSProperties['height'];\n /**\n * Custom toolbar heigth\n * @default 29px\n *\n * @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427\n *\n */\n toolbarHeight?: number;\n /**\n * Show drag and drop tool. Set the height of the editor.\n */\n visibleDragbar?: boolean;\n /**\n * @deprecated use `visibleDragbar`\n */\n visiableDragbar?: boolean;\n /**\n * Show markdown preview.\n */\n preview?: PreviewType;\n /**\n * Full screen display editor.\n */\n fullscreen?: boolean;\n /**\n * Disable `fullscreen` setting body styles\n */\n overflow?: boolean;\n /**\n * Maximum drag height. `visibleDragbar=true`\n */\n maxHeight?: number;\n /**\n * Minimum drag height. `visibleDragbar=true`\n */\n minHeight?: number;\n /**\n * This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.\n */\n previewOptions?: Omit<MarkdownPreviewProps, 'source'>;\n /**\n * Set the `textarea` related props.\n */\n textareaProps?: ITextAreaProps;\n /**\n * Use div to replace TextArea or re-render TextArea\n * @deprecated Please use ~~`renderTextarea`~~ -> `components`\n */\n renderTextarea?: ITextAreaProps['renderTextarea'];\n /**\n * re-render element\n */\n components?: {\n /** Use div to replace TextArea or re-render TextArea */\n textarea?: ITextAreaProps['renderTextarea'];\n /**\n * Override the default command element\n * _`toolbar`_ < _`command[].render`_\n */\n toolbar?: ICommand['render'];\n /** Custom markdown preview */\n preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;\n };\n /**\n * Disable editing area code highlighting. The value is `false`, which increases the editing speed.\n * @default true\n */\n highlightEnable?: boolean;\n /**\n * The number of characters to insert when pressing tab key.\n * Default `2` spaces.\n */\n tabSize?: number;\n /**\n * 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.\n */\n defaultTabEnable?: boolean;\n /**\n * You can create your own commands or reuse existing commands.\n */\n commands?: ICommand[];\n /**\n * Filter or modify your commands.\n * https://github.com/uiwjs/react-md-editor/issues/296\n */\n commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;\n /**\n * You can create your own commands or reuse existing commands.\n */\n extraCommands?: ICommand[];\n /**\n * Hide the tool bar\n */\n hideToolbar?: boolean;\n /** Whether to enable scrolling */\n enableScroll?: boolean;\n /** Toolbar on bottom */\n toolbarBottom?: boolean;\n}\n\nfunction setGroupPopFalse(data: Record<string, boolean> = {}) {\n Object.keys(data).forEach((keyname) => {\n data[keyname] = false;\n });\n return data;\n}\n\nconst InternalMDEditor = (\n props: MDEditorProps,\n ref?: ((instance: ContextStore) => void) | React.RefObject<ContextStore> | null,\n) => {\n const {\n prefixCls = 'w-md-editor',\n className,\n value: propsValue,\n commands = getCommands(),\n commandsFilter,\n extraCommands = getExtraCommands(),\n height = 200,\n enableScroll = true,\n visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,\n highlightEnable = true,\n preview: previewType = 'live',\n fullscreen = false,\n overflow = true,\n previewOptions = {},\n textareaProps,\n maxHeight = 1200,\n minHeight = 100,\n autoFocus,\n tabSize = 2,\n defaultTabEnable = false,\n onChange,\n onHeightChange,\n hideToolbar,\n toolbarBottom = false,\n components,\n renderTextarea,\n ...other\n } = props || {};\n const cmds = commands\n .map((item) => (commandsFilter ? commandsFilter(item, false) : item))\n .filter(Boolean) as ICommand[];\n const extraCmds = extraCommands\n .map((item) => (commandsFilter ? commandsFilter(item, true) : item))\n .filter(Boolean) as ICommand[];\n let [state, dispatch] = useReducer(reducer, {\n markdown: propsValue,\n preview: previewType,\n components,\n height,\n highlightEnable,\n tabSize,\n defaultTabEnable,\n scrollTop: 0,\n scrollTopPreview: 0,\n commands: cmds,\n extraCommands: extraCmds,\n fullscreen,\n barPopup: {},\n });\n const container = useRef<HTMLDivElement>(null);\n const previewRef = useRef<HTMLDivElement>(null);\n const enableScrollRef = useRef(enableScroll);\n\n useImperativeHandle(ref, () => ({ ...state }));\n useMemo(() => (enableScrollRef.current = enableScroll), [enableScroll]);\n useEffect(() => {\n const stateInit: ContextStore = {};\n if (container.current) {\n stateInit.container = container.current || undefined;\n }\n stateInit.markdown = propsValue || '';\n stateInit.barPopup = {};\n if (dispatch) {\n dispatch({ ...state, ...stateInit });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const cls = [\n className,\n 'wmde-markdown-var',\n prefixCls,\n state.preview ? `${prefixCls}-show-${state.preview}` : null,\n state.fullscreen ? `${prefixCls}-fullscreen` : null,\n ]\n .filter(Boolean)\n .join(' ')\n .trim();\n\n useMemo(\n () => propsValue !== state.markdown && dispatch({ markdown: propsValue || '' }),\n [propsValue, state.markdown],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);\n useMemo(\n () => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [highlightEnable],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);\n useMemo(\n () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [fullscreen],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => height !== state.height && dispatch({ height: height }), [height]);\n useMemo(\n () => height !== state.height && onHeightChange && onHeightChange(state.height, height, state),\n [height, onHeightChange, state],\n );\n\n const textareaDomRef = useRef<HTMLDivElement>();\n const active = useRef<'text' | 'preview'>('preview');\n const initScroll = useRef(false);\n\n useMemo(() => {\n textareaDomRef.current = state.textareaWarp;\n if (state.textareaWarp) {\n state.textareaWarp.addEventListener('mouseover', () => {\n active.current = 'text';\n });\n state.textareaWarp.addEventListener('mouseleave', () => {\n active.current = 'preview';\n });\n }\n }, [state.textareaWarp]);\n\n const handleScroll = (e: React.UIEvent<HTMLDivElement>, type: 'text' | 'preview') => {\n if (!enableScrollRef.current) return;\n const textareaDom = textareaDomRef.current;\n const previewDom = previewRef.current ? previewRef.current : undefined;\n if (!initScroll.current) {\n active.current = type;\n initScroll.current = true;\n }\n if (textareaDom && previewDom) {\n const scale =\n (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);\n if (e.target === textareaDom && active.current === 'text') {\n previewDom.scrollTop = textareaDom.scrollTop / scale;\n }\n if (e.target === previewDom && active.current === 'preview') {\n textareaDom.scrollTop = previewDom.scrollTop * scale;\n }\n let scrollTop = 0;\n if (active.current === 'text') {\n scrollTop = textareaDom.scrollTop || 0;\n } else if (active.current === 'preview') {\n scrollTop = previewDom.scrollTop || 0;\n }\n dispatch({ scrollTop });\n }\n };\n\n const previewClassName = `${prefixCls}-preview ${previewOptions.className || ''}`;\n let mdPreview = useMemo(\n () => (\n <div ref={previewRef} className={previewClassName}>\n <MarkdownPreview\n {...previewOptions}\n onScroll={(e) => handleScroll(e, 'preview')}\n source={state.markdown || ''}\n />\n </div>\n ),\n [previewClassName, previewOptions, state.markdown],\n );\n const preview = components?.preview && components?.preview(state.markdown || '', state, dispatch);\n if (preview && React.isValidElement(preview)) {\n mdPreview = (\n <div className={previewClassName} ref={previewRef} onScroll={(e) => handleScroll(e, 'preview')}>\n {preview}\n </div>\n );\n }\n\n return (\n <EditorContext.Provider value={{ ...state, dispatch }}>\n <div\n ref={container}\n className={cls}\n {...other}\n onClick={() => {\n dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });\n }}\n style={{\n ...other.style,\n height: state.height || '100%',\n }}\n >\n {!hideToolbar && !toolbarBottom && (\n <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />\n )}\n <div className={`${prefixCls}-content`}>\n {/(edit|live)/.test(state.preview || '') && (\n <TextArea\n className={`${prefixCls}-input`}\n prefixCls={prefixCls}\n autoFocus={autoFocus}\n {...textareaProps}\n onChange={(evn) => {\n onChange && onChange(evn.target.value, evn, state);\n if (textareaProps && textareaProps.onChange) {\n textareaProps.onChange(evn);\n }\n }}\n renderTextarea={components?.textarea || renderTextarea}\n onScroll={(e) => handleScroll(e, 'text')}\n />\n )}\n {/(live|preview)/.test(state.preview || '') && mdPreview}\n </div>\n {visibleDragbar && !state.fullscreen && (\n <DragBar\n prefixCls={prefixCls}\n height={state.height as number}\n maxHeight={maxHeight!}\n minHeight={minHeight!}\n onChange={(newHeight) => {\n dispatch({ height: newHeight });\n }}\n />\n )}\n {!hideToolbar && toolbarBottom && (\n <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />\n )}\n </div>\n </EditorContext.Provider>\n );\n};\n\nconst mdEditor = React.forwardRef<ContextStore, MDEditorProps>(InternalMDEditor);\n\ntype MDEditor = typeof mdEditor & {\n Markdown: typeof MarkdownPreview;\n};\n\n(mdEditor as MDEditor).Markdown = MarkdownPreview;\n\nexport default mdEditor as MDEditor;\n"
|
|
109
109
|
],
|
|
110
|
-
"mappings": ";;;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,UAA3B,EAAuCC,OAAvC,EAAgDC,MAAhD,EAAwDC,mBAAxD,QAAkG,OAAlG;AACA,OAAOC,eAAP,
|
|
110
|
+
"mappings": ";;;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,UAA3B,EAAuCC,OAAvC,EAAgDC,MAAhD,EAAwDC,mBAAxD,QAAkG,OAAlG;AACA,OAAOC,eAAP,MAAsD,6BAAtD;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Q,EAAGqD,SAAD,IAAe;UACvBnC,QAAQ,CAAC;YAAE9B,MAAM,EAAEiE;UAAV,CAAD,CAAR;QACD;MAPH,EAnCJ,EA6CG,CAAC/C,WAAD,IAAgBC,aAAhB,iBACC,KAAC,OAAD;QAAS,SAAS,EAAE1B,SAApB;QAA+B,QAAQ,EAAEe,QAAzC;QAAmD,aAAa,EAAEW;MAAlE,EA9CJ;IAAA;EADF,EADF;AAqDD,CArOD;;AAuOA,IAAM+C,QAAQ,gBAAGhG,KAAK,CAACiG,UAAN,CAA8C7E,gBAA9C,CAAjB;AAMC4E,QAAD,CAAuBE,QAAvB,GAAkC5F,eAAlC;AAEA,eAAe0F,QAAf"
|
|
111
111
|
}
|
|
@@ -20,7 +20,6 @@ export default function Child(props) {
|
|
|
20
20
|
children: Array.isArray(commands) ? /*#__PURE__*/_jsx(Toolbar, _extends({
|
|
21
21
|
commands: commands
|
|
22
22
|
}, props, {
|
|
23
|
-
height: "",
|
|
24
23
|
isChild: true
|
|
25
24
|
})) : children
|
|
26
25
|
}), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"../../../src/components/Toolbar/Child.tsx"
|
|
23
23
|
],
|
|
24
24
|
"sourcesContent": [
|
|
25
|
-
"import React, { useContext, useMemo } from 'react';\nimport './Child.less';\nimport Toolbar, { IToolbarProps } from './';\nimport { EditorContext } from '../../Context';\n\nexport type ChildProps = IToolbarProps & {\n children?: JSX.Element;\n groupName?: string;\n};\n\nexport default function Child(props: ChildProps) {\n const { prefixCls, groupName, commands, children } = props || {};\n const { barPopup = {} } = useContext(EditorContext);\n return useMemo(\n () => (\n <div\n className={`${prefixCls}-toolbar-child ${groupName && barPopup[groupName] ? 'active' : ''}`}\n onClick={(e) => e.stopPropagation()}\n >\n {Array.isArray(commands) ? <Toolbar commands={commands} {...props}
|
|
25
|
+
"import React, { useContext, useMemo } from 'react';\nimport './Child.less';\nimport Toolbar, { IToolbarProps } from './';\nimport { EditorContext } from '../../Context';\n\nexport type ChildProps = IToolbarProps & {\n children?: JSX.Element;\n groupName?: string;\n};\n\nexport default function Child(props: ChildProps) {\n const { prefixCls, groupName, commands, children } = props || {};\n const { barPopup = {} } = useContext(EditorContext);\n return useMemo(\n () => (\n <div\n className={`${prefixCls}-toolbar-child ${groupName && barPopup[groupName] ? 'active' : ''}`}\n onClick={(e) => e.stopPropagation()}\n >\n {Array.isArray(commands) ? <Toolbar commands={commands} {...props} isChild /> : children}\n </div>\n ),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [commands, barPopup, groupName, prefixCls],\n );\n}\n"
|
|
26
26
|
],
|
|
27
|
-
"mappings": ";AAAA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,OAA5B,QAA2C,OAA3C;AACA;AACA,OAAOC,OAAP,MAAuC,IAAvC;AACA,SAASC,aAAT,QAA8B,eAA9B;;AAOA,eAAe,SAASC,KAAT,CAAeC,KAAf,EAAkC;EAC/C,IAAM;IAAEC,SAAF;IAAaC,SAAb;IAAwBC,QAAxB;IAAkCC;EAAlC,IAA+CJ,KAAK,IAAI,EAA9D;EACA,IAAM;IAAEK,QAAQ,GAAG;EAAb,IAAoBV,UAAU,CAACG,aAAD,CAApC;EACA,OAAOF,OAAO,CACZ,mBACE;IACE,SAAS,EAAKK,SAAL,wBAAgCC,SAAS,IAAIG,QAAQ,CAACH,SAAD,CAArB,GAAmC,QAAnC,GAA8C,EAA9E,CADX;IAEE,OAAO,EAAGI,CAAD,IAAOA,CAAC,CAACC,eAAF,EAFlB;IAAA,UAIGC,KAAK,CAACC,OAAN,CAAcN,QAAd,iBAA0B,KAAC,OAAD;MAAS,QAAQ,EAAEA;IAAnB,GAAiCH,KAAjC;MAAwC,
|
|
27
|
+
"mappings": ";AAAA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,OAA5B,QAA2C,OAA3C;AACA;AACA,OAAOC,OAAP,MAAuC,IAAvC;AACA,SAASC,aAAT,QAA8B,eAA9B;;AAOA,eAAe,SAASC,KAAT,CAAeC,KAAf,EAAkC;EAC/C,IAAM;IAAEC,SAAF;IAAaC,SAAb;IAAwBC,QAAxB;IAAkCC;EAAlC,IAA+CJ,KAAK,IAAI,EAA9D;EACA,IAAM;IAAEK,QAAQ,GAAG;EAAb,IAAoBV,UAAU,CAACG,aAAD,CAApC;EACA,OAAOF,OAAO,CACZ,mBACE;IACE,SAAS,EAAKK,SAAL,wBAAgCC,SAAS,IAAIG,QAAQ,CAACH,SAAD,CAArB,GAAmC,QAAnC,GAA8C,EAA9E,CADX;IAEE,OAAO,EAAGI,CAAD,IAAOA,CAAC,CAACC,eAAF,EAFlB;IAAA,UAIGC,KAAK,CAACC,OAAN,CAAcN,QAAd,iBAA0B,KAAC,OAAD;MAAS,QAAQ,EAAEA;IAAnB,GAAiCH,KAAjC;MAAwC,OAAO;IAA/C,GAA1B,GAA+EI;EAJlF,EAFU,EASZ;EACA,CAACD,QAAD,EAAWE,QAAX,EAAqBH,SAArB,EAAgCD,SAAhC,CAVY,CAAd;AAYD"
|
|
28
28
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
.w-md-editor-toolbar {
|
|
2
2
|
border-bottom: 1px solid var(--color-border-default);
|
|
3
3
|
background-color: var(--color-canvas-default);
|
|
4
|
-
padding:
|
|
4
|
+
padding: 5px 5px;
|
|
5
5
|
display: flex;
|
|
6
6
|
justify-content: space-between;
|
|
7
7
|
align-items: center;
|
|
8
8
|
border-radius: 3px 3px 0 0;
|
|
9
9
|
-webkit-user-select: none;
|
|
10
10
|
user-select: none;
|
|
11
|
+
flex-wrap: wrap;
|
|
11
12
|
}
|
|
12
13
|
.w-md-editor-toolbar.bottom {
|
|
13
14
|
border-bottom: 0px;
|
|
@@ -19,11 +20,15 @@
|
|
|
19
20
|
margin: 0;
|
|
20
21
|
padding: 0;
|
|
21
22
|
list-style: none;
|
|
23
|
+
line-height: initial;
|
|
22
24
|
}
|
|
23
25
|
.w-md-editor-toolbar li {
|
|
24
26
|
display: inline-block;
|
|
25
27
|
font-size: 14px;
|
|
26
28
|
}
|
|
29
|
+
.w-md-editor-toolbar li + li {
|
|
30
|
+
margin: 0;
|
|
31
|
+
}
|
|
27
32
|
.w-md-editor-toolbar li > button {
|
|
28
33
|
border: none;
|
|
29
34
|
height: 20px;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { IProps } from '../../Editor';
|
|
3
2
|
import { ICommand } from '../../commands';
|
|
4
3
|
import './index.less';
|
|
5
4
|
export interface IToolbarProps extends IProps {
|
|
6
5
|
overflow?: boolean;
|
|
7
|
-
height?: React.CSSProperties['height'];
|
|
8
6
|
toolbarBottom?: boolean;
|
|
9
7
|
onCommand?: (command: ICommand<string>, groupName?: string) => void;
|
|
10
8
|
commands?: ICommand<string>[];
|
|
@@ -122,7 +122,6 @@ export default function Toolbar(props) {
|
|
|
122
122
|
|
|
123
123
|
var {
|
|
124
124
|
prefixCls,
|
|
125
|
-
height = 29,
|
|
126
125
|
toolbarBottom,
|
|
127
126
|
isChild
|
|
128
127
|
} = props;
|
|
@@ -133,9 +132,6 @@ export default function Toolbar(props) {
|
|
|
133
132
|
var bottomClassName = toolbarBottom ? 'bottom' : '';
|
|
134
133
|
return /*#__PURE__*/_jsxs("div", {
|
|
135
134
|
className: prefixCls + "-toolbar " + bottomClassName,
|
|
136
|
-
style: {
|
|
137
|
-
height
|
|
138
|
-
},
|
|
139
135
|
children: [/*#__PURE__*/_jsx(ToolbarItems, _extends({}, props, {
|
|
140
136
|
commands: props.commands || commands || []
|
|
141
137
|
})), !isChild && /*#__PURE__*/_jsx(ToolbarItems, _extends({}, props, {
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
"Array",
|
|
70
70
|
"isArray",
|
|
71
71
|
"Toolbar",
|
|
72
|
-
"height",
|
|
73
72
|
"toolbarBottom",
|
|
74
73
|
"isChild",
|
|
75
74
|
"extraCommands",
|
|
@@ -79,7 +78,7 @@
|
|
|
79
78
|
"../../../src/components/Toolbar/index.tsx"
|
|
80
79
|
],
|
|
81
80
|
"sourcesContent": [
|
|
82
|
-
"import React, { Fragment, useContext, useEffect, useRef } from 'react';\nimport { IProps } from '../../Editor';\nimport { EditorContext, PreviewType, ContextStore } from '../../Context';\nimport { ICommand } from '../../commands';\nimport Child from './Child';\nimport './index.less';\n\nexport interface IToolbarProps extends IProps {\n overflow?: boolean;\n
|
|
81
|
+
"import React, { Fragment, useContext, useEffect, useRef } from 'react';\nimport { IProps } from '../../Editor';\nimport { EditorContext, PreviewType, ContextStore } from '../../Context';\nimport { ICommand } from '../../commands';\nimport Child from './Child';\nimport './index.less';\n\nexport interface IToolbarProps extends IProps {\n overflow?: boolean;\n toolbarBottom?: boolean;\n onCommand?: (command: ICommand<string>, groupName?: string) => void;\n commands?: ICommand<string>[];\n isChild?: boolean;\n}\n\nexport function ToolbarItems(props: IToolbarProps) {\n const { prefixCls, overflow } = props;\n const { fullscreen, preview, barPopup = {}, components, commandOrchestrator, dispatch } = useContext(EditorContext);\n const originalOverflow = useRef('');\n\n function handleClick(command: ICommand<string>, name?: string) {\n if (!dispatch) return;\n const state: ContextStore = { barPopup: { ...barPopup } };\n if (command.keyCommand === 'preview') {\n state.preview = command.value as PreviewType;\n }\n if (command.keyCommand === 'fullscreen') {\n state.fullscreen = !fullscreen;\n }\n if (props.commands && command.keyCommand === 'group') {\n props.commands.forEach((item) => {\n if (name === item.groupName) {\n state.barPopup![name!] = true;\n } else if (item.keyCommand) {\n state.barPopup![item.groupName!] = false;\n }\n });\n } else if (name || command.parent) {\n Object.keys(state.barPopup || {}).forEach((keyName) => {\n state.barPopup![keyName] = false;\n });\n }\n\n if (Object.keys(state).length) {\n dispatch({ ...state });\n }\n commandOrchestrator && commandOrchestrator.executeCommand(command);\n }\n\n useEffect(() => {\n if (document && overflow) {\n if (fullscreen) {\n // prevent scroll on fullscreen\n document.body.style.overflow = 'hidden';\n } else {\n // get the original overflow only the first time\n if (!originalOverflow.current) {\n originalOverflow.current = window.getComputedStyle(document.body, null).overflow;\n }\n // reset to the original overflow\n document.body.style.overflow = originalOverflow.current;\n }\n }\n }, [fullscreen, originalOverflow, overflow]);\n\n return (\n <ul>\n {(props.commands || []).map((item, idx) => {\n if (item.keyCommand === 'divider') {\n return <li key={idx} {...item.liProps} className={`${prefixCls}-toolbar-divider`} />;\n }\n if (!item.keyCommand) return <Fragment key={idx} />;\n const activeBtn =\n (fullscreen && item.keyCommand === 'fullscreen') || (item.keyCommand === 'preview' && preview === item.value);\n const childNode =\n item.children && typeof item.children === 'function'\n ? item.children({\n getState: () => commandOrchestrator!.getState(),\n textApi: commandOrchestrator ? commandOrchestrator!.textApi : undefined,\n close: () => handleClick({}, item.groupName),\n execute: () => handleClick({ execute: item.execute }),\n })\n : undefined;\n const disabled = barPopup && preview && preview === 'preview' && !/(preview|fullscreen)/.test(item.keyCommand);\n const render = components?.toolbar || item.render;\n const com = (\n render && typeof render === 'function' ? render(item, !!disabled, handleClick, idx) : null\n ) as React.ReactElement;\n return (\n <li key={idx} {...item.liProps} className={activeBtn ? `active` : ''}>\n {com && React.isValidElement(com) && com}\n {!com && !item.buttonProps && item.icon}\n {!com &&\n item.buttonProps &&\n React.createElement(\n 'button',\n {\n type: 'button',\n key: idx,\n disabled,\n 'data-name': item.name,\n ...item.buttonProps,\n onClick: (evn: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n evn.stopPropagation();\n handleClick(item, item.groupName);\n },\n },\n item.icon,\n )}\n {item.children && (\n <Child\n overflow={overflow}\n groupName={item.groupName}\n prefixCls={prefixCls}\n children={childNode}\n commands={Array.isArray(item.children) ? item.children : undefined}\n />\n )}\n </li>\n );\n })}\n </ul>\n );\n}\n\nexport default function Toolbar(props: IToolbarProps = {}) {\n const { prefixCls, toolbarBottom, isChild } = props;\n const { commands, extraCommands } = useContext(EditorContext);\n const bottomClassName = toolbarBottom ? 'bottom' : '';\n return (\n <div className={`${prefixCls}-toolbar ${bottomClassName}`}>\n <ToolbarItems {...props} commands={props.commands || commands || []} />\n {!isChild && <ToolbarItems {...props} commands={extraCommands || []} />}\n </div>\n );\n}\n"
|
|
83
82
|
],
|
|
84
|
-
"mappings": ";AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,SAAtC,EAAiDC,MAAjD,QAA+D,OAA/D;AAEA,SAASC,aAAT,QAAyD,eAAzD;AAEA,OAAOC,KAAP,MAAkB,SAAlB;AACA;;;
|
|
83
|
+
"mappings": ";AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,UAA1B,EAAsCC,SAAtC,EAAiDC,MAAjD,QAA+D,OAA/D;AAEA,SAASC,aAAT,QAAyD,eAAzD;AAEA,OAAOC,KAAP,MAAkB,SAAlB;AACA;;;AAUA,OAAO,SAASC,YAAT,CAAsBC,KAAtB,EAA4C;EACjD,IAAM;IAAEC,SAAF;IAAaC;EAAb,IAA0BF,KAAhC;EACA,IAAM;IAAEG,UAAF;IAAcC,OAAd;IAAuBC,QAAQ,GAAG,EAAlC;IAAsCC,UAAtC;IAAkDC,mBAAlD;IAAuEC;EAAvE,IAAoFd,UAAU,CAACG,aAAD,CAApG;EACA,IAAMY,gBAAgB,GAAGb,MAAM,CAAC,EAAD,CAA/B;;EAEA,SAASc,WAAT,CAAqBC,OAArB,EAAgDC,IAAhD,EAA+D;IAC7D,IAAI,CAACJ,QAAL,EAAe;IACf,IAAMK,KAAmB,GAAG;MAAER,QAAQ,eAAOA,QAAP;IAAV,CAA5B;;IACA,IAAIM,OAAO,CAACG,UAAR,KAAuB,SAA3B,EAAsC;MACpCD,KAAK,CAACT,OAAN,GAAgBO,OAAO,CAACI,KAAxB;IACD;;IACD,IAAIJ,OAAO,CAACG,UAAR,KAAuB,YAA3B,EAAyC;MACvCD,KAAK,CAACV,UAAN,GAAmB,CAACA,UAApB;IACD;;IACD,IAAIH,KAAK,CAACgB,QAAN,IAAkBL,OAAO,CAACG,UAAR,KAAuB,OAA7C,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AA2B;IAA3BA,KAA2B,GAAJ,EAAI;EAAA;;EACzD,IAAM;IAAEC,SAAF;IAAa2D,aAAb;IAA4BC;EAA5B,IAAwC7D,KAA9C;EACA,IAAM;IAAEgB,QAAF;IAAY8C;EAAZ,IAA8BpE,UAAU,CAACG,aAAD,CAA9C;EACA,IAAMkE,eAAe,GAAGH,aAAa,GAAG,QAAH,GAAc,EAAnD;EACA,oBACE;IAAK,SAAS,EAAK3D,SAAL,iBAA0B8D,eAAxC;IAAA,wBACE,KAAC,YAAD,eAAkB/D,KAAlB;MAAyB,QAAQ,EAAEA,KAAK,CAACgB,QAAN,IAAkBA,QAAlB,IAA8B;IAAjE,GADF,EAEG,CAAC6C,OAAD,iBAAY,KAAC,YAAD,eAAkB7D,KAAlB;MAAyB,QAAQ,EAAE8D,aAAa,IAAI;IAApD,GAFf;EAAA,EADF;AAMD"
|
|
85
84
|
}
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
&-toolbar {
|
|
5
5
|
border-bottom: 1px solid var(--color-border-default);
|
|
6
6
|
background-color: var(--color-canvas-default);
|
|
7
|
-
padding:
|
|
7
|
+
padding: 5px 5px;
|
|
8
8
|
display: flex;
|
|
9
9
|
justify-content: space-between;
|
|
10
10
|
align-items: center;
|
|
11
11
|
border-radius: 3px 3px 0 0;
|
|
12
12
|
user-select: none;
|
|
13
|
+
flex-wrap: wrap;
|
|
13
14
|
&.bottom {
|
|
14
15
|
border-bottom: 0px;
|
|
15
16
|
border-top: 1px solid var(--color-border-default);
|
|
@@ -20,10 +21,14 @@
|
|
|
20
21
|
margin: 0;
|
|
21
22
|
padding: 0;
|
|
22
23
|
list-style: none;
|
|
24
|
+
line-height: initial;
|
|
23
25
|
}
|
|
24
26
|
li {
|
|
25
27
|
display: inline-block;
|
|
26
28
|
font-size: 14px;
|
|
29
|
+
& + li {
|
|
30
|
+
margin: 0;
|
|
31
|
+
}
|
|
27
32
|
> button {
|
|
28
33
|
border: none;
|
|
29
34
|
height: 20px;
|
package/esm/index.css
CHANGED
|
@@ -7,14 +7,21 @@
|
|
|
7
7
|
box-shadow: 0 0 0 1px var(--color-border-default), 0 0 0 var(--color-border-default), 0 1px 1px var(--color-border-default);
|
|
8
8
|
background-color: var(--color-canvas-default);
|
|
9
9
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
10
12
|
}
|
|
11
|
-
.w-md-editor
|
|
12
|
-
|
|
13
|
+
.w-md-editor-toolbar {
|
|
14
|
+
height: -webkit-fit-content;
|
|
15
|
+
height: fit-content;
|
|
13
16
|
}
|
|
14
17
|
.w-md-editor-content {
|
|
18
|
+
height: 100%;
|
|
19
|
+
overflow: auto;
|
|
15
20
|
position: relative;
|
|
16
21
|
border-radius: 0 0 3px 0;
|
|
17
|
-
|
|
22
|
+
}
|
|
23
|
+
.w-md-editor .copied {
|
|
24
|
+
display: none !important;
|
|
18
25
|
}
|
|
19
26
|
.w-md-editor-input {
|
|
20
27
|
width: 50%;
|
package/esm/index.less
CHANGED
|
@@ -10,13 +10,19 @@
|
|
|
10
10
|
0 1px 1px var(--color-border-default);
|
|
11
11
|
background-color: var(--color-canvas-default);
|
|
12
12
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
&-toolbar {
|
|
16
|
+
height: fit-content;
|
|
15
17
|
}
|
|
16
18
|
&-content {
|
|
19
|
+
height: 100%;
|
|
20
|
+
overflow: auto;
|
|
17
21
|
position: relative;
|
|
18
22
|
border-radius: 0 0 3px 0;
|
|
19
|
-
|
|
23
|
+
}
|
|
24
|
+
.copied {
|
|
25
|
+
display: none !important;
|
|
20
26
|
}
|
|
21
27
|
&-input {
|
|
22
28
|
width: 50%;
|
package/lib/Context.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
|
|
|
38
38
|
shortcuts?: ((e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand<string>[], commandOrchestrator?: TextAreaCommandOrchestrator | undefined, dispatch?: React.Dispatch<ContextStore> | undefined, state?: ExecuteCommandState | undefined) => void) | undefined;
|
|
39
39
|
}) => JSX.Element) | undefined;
|
|
40
40
|
toolbar?: ((command: ICommand<string>, disabled: boolean, executeCommand: (command: ICommand<string>, name?: string | undefined) => void, index: number) => void | React.ReactElement<any, string | React.JSXElementConstructor<any>> | null | undefined) | undefined;
|
|
41
|
+
preview?: ((source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element) | undefined;
|
|
41
42
|
} | undefined;
|
|
42
43
|
commands?: ICommand<string>[] | undefined;
|
|
43
44
|
extraCommands?: ICommand<string>[] | undefined;
|
package/lib/Editor.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
35
35
|
/**
|
|
36
36
|
* Custom toolbar heigth
|
|
37
37
|
* @default 29px
|
|
38
|
+
*
|
|
39
|
+
* @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427
|
|
40
|
+
*
|
|
38
41
|
*/
|
|
39
42
|
toolbarHeight?: number;
|
|
40
43
|
/**
|
|
@@ -89,6 +92,8 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
89
92
|
* _`toolbar`_ < _`command[].render`_
|
|
90
93
|
*/
|
|
91
94
|
toolbar?: ICommand['render'];
|
|
95
|
+
/** Custom markdown preview */
|
|
96
|
+
preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;
|
|
92
97
|
};
|
|
93
98
|
/**
|
|
94
99
|
* Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
package/lib/Editor.js
CHANGED
|
@@ -31,7 +31,7 @@ var _Context = require("./Context");
|
|
|
31
31
|
|
|
32
32
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
33
|
|
|
34
|
-
var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "extraCommands", "height", "
|
|
34
|
+
var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "tabSize", "defaultTabEnable", "onChange", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
|
|
35
35
|
|
|
36
36
|
function setGroupPopFalse() {
|
|
37
37
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -54,8 +54,6 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
54
54
|
extraCommands = _ref$extraCommands === void 0 ? (0, _commands.getExtraCommands)() : _ref$extraCommands,
|
|
55
55
|
_ref$height = _ref.height,
|
|
56
56
|
height = _ref$height === void 0 ? 200 : _ref$height,
|
|
57
|
-
_ref$toolbarHeight = _ref.toolbarHeight,
|
|
58
|
-
toolbarHeight = _ref$toolbarHeight === void 0 ? 29 : _ref$toolbarHeight,
|
|
59
57
|
_ref$enableScroll = _ref.enableScroll,
|
|
60
58
|
enableScroll = _ref$enableScroll === void 0 ? true : _ref$enableScroll,
|
|
61
59
|
_ref$visibleDragbar = _ref.visibleDragbar,
|
|
@@ -203,7 +201,7 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
203
201
|
var handleScroll = function handleScroll(e, type) {
|
|
204
202
|
if (!enableScrollRef.current) return;
|
|
205
203
|
var textareaDom = textareaDomRef.current;
|
|
206
|
-
var previewDom = previewRef.current ? previewRef.current
|
|
204
|
+
var previewDom = previewRef.current ? previewRef.current : undefined;
|
|
207
205
|
|
|
208
206
|
if (!initScroll.current) {
|
|
209
207
|
active.current = type;
|
|
@@ -235,16 +233,32 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
235
233
|
}
|
|
236
234
|
};
|
|
237
235
|
|
|
236
|
+
var previewClassName = "".concat(prefixCls, "-preview ").concat(previewOptions.className || '');
|
|
238
237
|
var mdPreview = (0, _react.useMemo)(function () {
|
|
239
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
238
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
239
|
+
ref: previewRef,
|
|
240
|
+
className: previewClassName,
|
|
241
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactMarkdownPreview["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, previewOptions), {}, {
|
|
242
|
+
onScroll: function onScroll(e) {
|
|
243
|
+
return handleScroll(e, 'preview');
|
|
244
|
+
},
|
|
245
|
+
source: state.markdown || ''
|
|
246
|
+
}))
|
|
247
|
+
});
|
|
248
|
+
}, [previewClassName, previewOptions, state.markdown]);
|
|
249
|
+
var preview = (components === null || components === void 0 ? void 0 : components.preview) && (components === null || components === void 0 ? void 0 : components.preview(state.markdown || '', state, dispatch));
|
|
250
|
+
|
|
251
|
+
if (preview && /*#__PURE__*/_react["default"].isValidElement(preview)) {
|
|
252
|
+
mdPreview = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
253
|
+
className: previewClassName,
|
|
254
|
+
ref: previewRef,
|
|
240
255
|
onScroll: function onScroll(e) {
|
|
241
256
|
return handleScroll(e, 'preview');
|
|
242
257
|
},
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}, [prefixCls, previewOptions, state.markdown]);
|
|
258
|
+
children: preview
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
248
262
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Context.EditorContext.Provider, {
|
|
249
263
|
value: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
|
250
264
|
dispatch: dispatch
|
|
@@ -263,14 +277,10 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
263
277
|
}),
|
|
264
278
|
children: [!hideToolbar && !toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
|
|
265
279
|
prefixCls: prefixCls,
|
|
266
|
-
height: toolbarHeight,
|
|
267
280
|
overflow: overflow,
|
|
268
281
|
toolbarBottom: toolbarBottom
|
|
269
282
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
270
283
|
className: "".concat(prefixCls, "-content"),
|
|
271
|
-
style: {
|
|
272
|
-
height: "calc(100% - ".concat(toolbarHeight, "px)")
|
|
273
|
-
},
|
|
274
284
|
children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextArea["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
275
285
|
className: "".concat(prefixCls, "-input"),
|
|
276
286
|
prefixCls: prefixCls,
|
|
@@ -300,7 +310,6 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
|
|
|
300
310
|
}
|
|
301
311
|
}), !hideToolbar && toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
|
|
302
312
|
prefixCls: prefixCls,
|
|
303
|
-
height: toolbarHeight,
|
|
304
313
|
overflow: overflow,
|
|
305
314
|
toolbarBottom: toolbarBottom
|
|
306
315
|
})]
|