@uiw/react-md-editor 3.12.3 → 3.14.1
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 +9 -7
- package/dist/mdeditor.css +5 -10
- package/dist/mdeditor.js +1316 -1617
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/dist/mdeditor.min.js.LICENSE.txt +0 -9
- package/esm/Editor.d.ts +8 -2
- package/esm/Editor.js +12 -5
- package/esm/Editor.js.map +4 -2
- package/esm/components/Toolbar/index.css +5 -0
- package/esm/components/Toolbar/index.d.ts +1 -0
- package/esm/components/Toolbar/index.js +3 -1
- package/esm/components/Toolbar/index.js.map +5 -3
- package/esm/components/Toolbar/index.less +5 -0
- package/lib/Context.js.map +1 -1
- package/lib/Editor.d.ts +8 -2
- package/lib/Editor.js +14 -6
- package/lib/Editor.js.map +11 -2
- package/lib/commands/bold.js.map +2 -1
- package/lib/commands/code.js.map +4 -1
- package/lib/commands/comment.js.map +2 -1
- package/lib/commands/image.js.map +2 -1
- package/lib/commands/index.js.map +2 -1
- package/lib/commands/italic.js.map +2 -1
- package/lib/commands/link.js.map +2 -1
- package/lib/commands/list.js.map +4 -1
- package/lib/commands/quote.js.map +4 -1
- package/lib/commands/strikeThrough.js.map +2 -1
- package/lib/commands/title1.js.map +2 -1
- package/lib/commands/title2.js.map +2 -1
- package/lib/commands/title3.js.map +2 -1
- package/lib/commands/title4.js.map +2 -1
- package/lib/commands/title5.js.map +2 -1
- package/lib/commands/title6.js.map +2 -1
- package/lib/components/DragBar/index.js.map +5 -2
- package/lib/components/TextArea/Markdown.js.map +5 -1
- package/lib/components/TextArea/Textarea.js.map +5 -1
- package/lib/components/TextArea/handleKeyDown.js.map +3 -1
- package/lib/components/TextArea/index.js.map +3 -2
- package/lib/components/Toolbar/Child.js.map +3 -1
- package/lib/components/Toolbar/index.d.ts +1 -0
- package/lib/components/Toolbar/index.js +3 -1
- package/lib/components/Toolbar/index.js.map +8 -3
- package/lib/components/Toolbar/index.less +5 -0
- package/markdown-editor.css +5 -0
- package/package.json +2 -2
- package/src/Editor.tsx +17 -5
- package/src/components/Toolbar/index.less +5 -0
- package/src/components/Toolbar/index.tsx +4 -2
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"indexOf",
|
|
41
41
|
"end",
|
|
42
42
|
"modifiedTextObj",
|
|
43
|
+
"insertBeforeEachLine",
|
|
43
44
|
"shiftKey",
|
|
44
45
|
"text",
|
|
45
46
|
"map",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"replaceSelection",
|
|
49
50
|
"startTabSize",
|
|
50
51
|
"endTabSize",
|
|
52
|
+
"insertTextAtPosition",
|
|
51
53
|
"test",
|
|
52
54
|
"startStr",
|
|
53
55
|
"startsWith",
|
|
@@ -59,5 +61,5 @@
|
|
|
59
61
|
"sourcesContent": [
|
|
60
62
|
"import { insertTextAtPosition } from '../../utils/InsertTextAtPosition';\nimport { TextAreaTextApi } from '../../commands';\nimport { insertBeforeEachLine } from '../../commands/list';\n\n/**\n * - `13` - `Enter`\n * - `9` - `Tab`\n */\nfunction stopPropagation(e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>) {\n e.stopPropagation();\n e.preventDefault();\n}\n\nexport default function handleKeyDown(\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n tabSize: number = 2,\n defaultTabEnable: boolean = false,\n) {\n const target = e.target as HTMLTextAreaElement;\n const starVal = target.value.substr(0, target.selectionStart);\n const valArr = starVal.split('\\n');\n const currentLineStr = valArr[valArr.length - 1];\n const textArea = new TextAreaTextApi(target);\n\n /**\n * `9` - `Tab`\n */\n if (!defaultTabEnable && e.code && e.code.toLowerCase() === 'tab') {\n stopPropagation(e);\n const space = new Array(tabSize + 1).join(' ');\n if (target.selectionStart !== target.selectionEnd) {\n const _star = target.value.substring(0, target.selectionStart).split('\\n');\n const _end = target.value.substring(0, target.selectionEnd).split('\\n');\n const modifiedTextLine: string[] = [];\n _end.forEach((item, idx) => {\n if (item !== _star[idx]) {\n modifiedTextLine.push(item);\n }\n });\n const modifiedText = modifiedTextLine.join('\\n');\n const oldSelectText = target.value.substring(target.selectionStart, target.selectionEnd);\n const newStarNum = target.value.substring(0, target.selectionStart).length;\n\n textArea.setSelectionRange({\n start: target.value.indexOf(modifiedText),\n end: target.selectionEnd,\n });\n\n const modifiedTextObj = insertBeforeEachLine(modifiedText, e.shiftKey ? '' : space);\n\n let text = modifiedTextObj.modifiedText;\n if (e.shiftKey) {\n text = text\n .split('\\n')\n .map((item) => item.replace(new RegExp(`^${space}`), ''))\n .join('\\n');\n }\n textArea.replaceSelection(text);\n\n let startTabSize = e.shiftKey ? -tabSize : tabSize;\n let endTabSize = e.shiftKey ? -modifiedTextLine.length * tabSize : modifiedTextLine.length * tabSize;\n\n textArea.setSelectionRange({\n start: newStarNum + startTabSize,\n end: newStarNum + oldSelectText.length + endTabSize,\n });\n } else {\n return insertTextAtPosition(target, space);\n }\n } else if (\n e.code &&\n e.code.toLowerCase() === 'enter' &&\n (/^(-|\\*)\\s/.test(currentLineStr) || /^\\d+.\\s/.test(currentLineStr))\n ) {\n /**\n * `13` - `Enter`\n */\n stopPropagation(e);\n let startStr = '\\n- ';\n\n if (currentLineStr.startsWith('*')) {\n startStr = '\\n* ';\n }\n\n if (currentLineStr.startsWith('- [ ]')) {\n startStr = '\\n- [ ] ';\n } else if (currentLineStr.startsWith('- [X]')) {\n startStr = '\\n- [X] ';\n }\n\n if (/^\\d+.\\s/.test(currentLineStr)) {\n startStr = `\\n${parseInt(currentLineStr) + 1}. `;\n }\n return insertTextAtPosition(target, startStr);\n }\n}\n"
|
|
61
63
|
],
|
|
62
|
-
"mappings": ";;;;;;;AAAA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA,SAASA,eAAT,CAAyBC,CAAzB,EAAsF;EACpFA,CAAC,CAACD,eAAF;EACAC,CAAC,CAACC,cAAF;AACD;;AAEc,SAASC,aAAT,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,GAA1B,CAAJ,EAAoC;MAClCD,QAAQ,GAAG,MAAX;IACD;;IAED,IAAIrC,cAAc,CAACsC,UAAf,CAA0B,OAA1B,CAAJ,EAAwC;MACtCD,QAAQ,GAAG,UAAX;IACD,CAFD,MAEO,IAAIrC,cAAc,CAACsC,UAAf,CAA0B,OAA1B,CAAJ,EAAwC;MAC7CD,QAAQ,GAAG,UAAX;IACD;;IAED,IAAI,UAAUD,IAAV,CAAepC,cAAf,CAAJ,EAAoC;MAClCqC,QAAQ,eAAQE,QAAQ,CAACvC,cAAD,CAAR,GAA2B,CAAnC,OAAR;IACD;;IACD,OAAO,IAAAmC,0CAAA,EAAqB1C,MAArB,EAA6B4C,QAA7B,CAAP;EACD;AACF"
|
|
63
65
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"onScroll",
|
|
9
9
|
"renderTextarea",
|
|
10
10
|
"otherProps",
|
|
11
|
+
"useContext",
|
|
11
12
|
"EditorContext",
|
|
12
13
|
"markdown",
|
|
13
14
|
"scrollTop",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"executeRef",
|
|
22
23
|
"warp",
|
|
23
24
|
"createRef",
|
|
25
|
+
"useEffect",
|
|
24
26
|
"state",
|
|
25
27
|
"current",
|
|
26
28
|
"textareaWarp",
|
|
@@ -40,7 +42,6 @@
|
|
|
40
42
|
"overflow",
|
|
41
43
|
"onChange",
|
|
42
44
|
"shortcuts",
|
|
43
|
-
"useContext",
|
|
44
45
|
"ref"
|
|
45
46
|
],
|
|
46
47
|
"sources": [
|
|
@@ -49,5 +50,5 @@
|
|
|
49
50
|
"sourcesContent": [
|
|
50
51
|
"import React, { useEffect, Fragment, useContext } from 'react';\nimport { EditorContext, ContextStore, ExecuteCommandState } from '../../Context';\nimport shortcuts from './shortcuts';\nimport Markdown from './Markdown';\nimport Textarea, { TextAreaProps } from './Textarea';\nimport { IProps } from '../../Editor';\nimport { TextAreaCommandOrchestrator, ICommand } from '../../commands';\nimport './index.less';\n\ntype RenderTextareaHandle = {\n dispatch: ContextStore['dispatch'];\n onChange?: TextAreaProps['onChange'];\n useContext?: {\n commands: ContextStore['commands'];\n extraCommands: ContextStore['extraCommands'];\n commandOrchestrator?: TextAreaCommandOrchestrator;\n };\n shortcuts?: (\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n commands: ICommand[],\n commandOrchestrator?: TextAreaCommandOrchestrator,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n ) => void;\n};\n\nexport interface ITextAreaProps\n extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>,\n IProps {\n value?: string;\n onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;\n renderTextarea?: (\n props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>,\n opts: RenderTextareaHandle,\n ) => JSX.Element;\n}\n\nexport type TextAreaRef = {\n text?: HTMLTextAreaElement;\n warp?: HTMLDivElement;\n};\n\nexport default function TextArea(props: ITextAreaProps) {\n const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};\n const { markdown, scrollTop, commands, highlightEnable, extraCommands, dispatch } = useContext(EditorContext);\n const textRef = React.useRef<HTMLTextAreaElement>(null);\n const executeRef = React.useRef<TextAreaCommandOrchestrator>();\n const warp = React.createRef<HTMLDivElement>();\n useEffect(() => {\n const state: ContextStore = {};\n if (warp.current) {\n state.textareaWarp = warp.current || undefined;\n warp.current.scrollTop = scrollTop || 0;\n }\n if (dispatch) {\n dispatch({ ...state });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (textRef.current && dispatch) {\n const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);\n executeRef.current = commandOrchestrator;\n dispatch({ textarea: textRef.current, commandOrchestrator });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // @ts-ignore\n const textStyle: React.CSSProperties = highlightEnable ? {} : { '-webkit-text-fill-color': 'inherit' };\n\n return (\n <div ref={warp} className={`${prefixCls}-aree ${className || ''}`} onScroll={onScroll}>\n <div className={`${prefixCls}-text`}>\n {renderTextarea ? (\n React.cloneElement(\n renderTextarea(\n {\n ...otherProps,\n value: markdown,\n autoComplete: 'off',\n autoCorrect: 'off',\n spellCheck: 'false',\n autoCapitalize: 'off',\n className: `${prefixCls}-text-input`,\n style: {\n WebkitTextFillColor: 'inherit',\n overflow: 'auto',\n },\n },\n {\n dispatch,\n onChange: otherProps.onChange,\n shortcuts,\n useContext: { commands, extraCommands, commandOrchestrator: executeRef.current },\n },\n ),\n {\n ref: textRef,\n },\n )\n ) : (\n <Fragment>\n {highlightEnable && <Markdown prefixCls={prefixCls} />}\n <Textarea prefixCls={prefixCls} {...otherProps} style={textStyle} />\n </Fragment>\n )}\n </div>\n </div>\n );\n}\n"
|
|
51
52
|
],
|
|
52
|
-
"mappings": ";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAoCe,SAASA,QAAT,CAAkBC,KAAlB,EAAyC;EACtD,WAA0EA,KAAK,IAAI,EAAnF;EAAA,IAAQC,SAAR,QAAQA,SAAR;EAAA,IAAmBC,SAAnB,QAAmBA,SAAnB;EAAA,IAA8BC,QAA9B,QAA8BA,QAA9B;EAAA,IAAwCC,cAAxC,QAAwCA,cAAxC;EAAA,IAA2DC,UAA3D;;EACA,kBAAoF,
|
|
53
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAoCe,SAASA,QAAT,CAAkBC,KAAlB,EAAyC;EACtD,WAA0EA,KAAK,IAAI,EAAnF;EAAA,IAAQC,SAAR,QAAQA,SAAR;EAAA,IAAmBC,SAAnB,QAAmBA,SAAnB;EAAA,IAA8BC,QAA9B,QAA8BA,QAA9B;EAAA,IAAwCC,cAAxC,QAAwCA,cAAxC;EAAA,IAA2DC,UAA3D;;EACA,kBAAoF,I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|
|
|
20
22
|
"sourcesContent": [
|
|
21
23
|
"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} height=\"\" isChild /> : children}\n </div>\n ),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [commands, barPopup, groupName, prefixCls],\n );\n}\n"
|
|
22
24
|
],
|
|
23
|
-
"mappings": ";;;;;;;;;;;;;AAAA;;AAEA;;AACA;;;;AAOe,SAASA,KAAT,CAAeC,KAAf,EAAkC;EAC/C,WAAqDA,KAAK,IAAI,EAA9D;EAAA,IAAQC,SAAR,QAAQA,SAAR;EAAA,IAAmBC,SAAnB,QAAmBA,SAAnB;EAAA,IAA8BC,QAA9B,QAA8BA,QAA9B;EAAA,IAAwCC,QAAxC,QAAwCA,QAAxC;;EACA,kBAA0B,
|
|
25
|
+
"mappings": ";;;;;;;;;;;;;AAAA;;AAEA;;AACA;;;;AAOe,SAASA,KAAT,CAAeC,KAAf,EAAkC;EAC/C,WAAqDA,KAAK,IAAI,EAA9D;EAAA,IAAQC,SAAR,QAAQA,SAAR;EAAA,IAAmBC,SAAnB,QAAmBA,SAAnB;EAAA,IAA8BC,QAA9B,QAA8BA,QAA9B;EAAA,IAAwCC,QAAxC,QAAwCA,QAAxC;;EACA,kBAA0B,IAAAC,iBAAA,EAAWC,sBAAX,CAA1B;EAAA,uCAAQC,QAAR;EAAA,IAAQA,QAAR,qCAAmB,EAAnB;;EACA,OAAO,IAAAC,cAAA,EACL;IAAA,oBACE;MACE,SAAS,YAAKP,SAAL,4BAAgCC,SAAS,IAAIK,QAAQ,CAACL,SAAD,CAArB,GAAmC,QAAnC,GAA8C,EAA9E,CADX;MAEE,OAAO,EAAE,iBAACO,CAAD;QAAA,OAAOA,CAAC,CAACC,eAAF,EAAP;MAAA,CAFX;MAAA,UAIGC,KAAK,CAACC,OAAN,CAAcT,QAAd,iBAA0B,qBAAC,SAAD;QAAS,QAAQ,EAAEA;MAAnB,GAAiCH,KAAjC;QAAwC,MAAM,EAAC,EAA/C;QAAkD,OAAO;MAAzD,GAA1B,GAAyFI;IAJ5F,EADF;EAAA,CADK,EASL;EACA,CAACD,QAAD,EAAWI,QAAX,EAAqBL,SAArB,EAAgCD,SAAhC,CAVK,CAAP;AAYD"
|
|
24
26
|
}
|
|
@@ -5,6 +5,7 @@ import './index.less';
|
|
|
5
5
|
export interface IToolbarProps extends IProps {
|
|
6
6
|
overflow?: boolean;
|
|
7
7
|
height?: React.CSSProperties['height'];
|
|
8
|
+
toolbarBottom?: boolean;
|
|
8
9
|
onCommand?: (command: ICommand<string>, groupName?: string) => void;
|
|
9
10
|
commands?: ICommand<string>[];
|
|
10
11
|
isChild?: boolean;
|
|
@@ -139,14 +139,16 @@ function Toolbar() {
|
|
|
139
139
|
var prefixCls = props.prefixCls,
|
|
140
140
|
_props$height = props.height,
|
|
141
141
|
height = _props$height === void 0 ? 29 : _props$height,
|
|
142
|
+
toolbarBottom = props.toolbarBottom,
|
|
142
143
|
isChild = props.isChild;
|
|
143
144
|
|
|
144
145
|
var _useContext2 = (0, _react.useContext)(_Context.EditorContext),
|
|
145
146
|
commands = _useContext2.commands,
|
|
146
147
|
extraCommands = _useContext2.extraCommands;
|
|
147
148
|
|
|
149
|
+
var bottomClassName = toolbarBottom ? 'bottom' : '';
|
|
148
150
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
149
|
-
className: "".concat(prefixCls, "-toolbar"),
|
|
151
|
+
className: "".concat(prefixCls, "-toolbar ").concat(bottomClassName),
|
|
150
152
|
style: {
|
|
151
153
|
height: height
|
|
152
154
|
},
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"props",
|
|
6
6
|
"prefixCls",
|
|
7
7
|
"overflow",
|
|
8
|
+
"useContext",
|
|
8
9
|
"EditorContext",
|
|
9
10
|
"fullscreen",
|
|
10
11
|
"preview",
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
"commandOrchestrator",
|
|
13
14
|
"dispatch",
|
|
14
15
|
"originalOverflow",
|
|
16
|
+
"useRef",
|
|
15
17
|
"handleClick",
|
|
16
18
|
"command",
|
|
17
19
|
"name",
|
|
@@ -28,6 +30,7 @@
|
|
|
28
30
|
"keyName",
|
|
29
31
|
"length",
|
|
30
32
|
"executeCommand",
|
|
33
|
+
"useEffect",
|
|
31
34
|
"document",
|
|
32
35
|
"body",
|
|
33
36
|
"style",
|
|
@@ -60,14 +63,16 @@
|
|
|
60
63
|
"isArray",
|
|
61
64
|
"Toolbar",
|
|
62
65
|
"height",
|
|
66
|
+
"toolbarBottom",
|
|
63
67
|
"isChild",
|
|
64
|
-
"extraCommands"
|
|
68
|
+
"extraCommands",
|
|
69
|
+
"bottomClassName"
|
|
65
70
|
],
|
|
66
71
|
"sources": [
|
|
67
72
|
"../../../src/components/Toolbar/index.tsx"
|
|
68
73
|
],
|
|
69
74
|
"sourcesContent": [
|
|
70
|
-
"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 height?: React.CSSProperties['height'];\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 = {}, 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 return (\n <li key={idx} {...item.liProps} className={activeBtn ? `active` : ''}>\n {!item.buttonProps && item.icon}\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, height = 29, isChild } = props;\n const { commands, extraCommands } = useContext(EditorContext);\n return (\n <div className={`${prefixCls}-toolbar`} style={{ height }}>\n <ToolbarItems {...props} commands={props.commands || commands || []} />\n {!isChild && <ToolbarItems {...props} commands={extraCommands || []} />}\n </div>\n );\n}\n"
|
|
75
|
+
"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 height?: React.CSSProperties['height'];\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 = {}, 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 return (\n <li key={idx} {...item.liProps} className={activeBtn ? `active` : ''}>\n {!item.buttonProps && item.icon}\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, height = 29, toolbarBottom, isChild } = props;\n const { commands, extraCommands } = useContext(EditorContext);\n const bottomClassName = toolbarBottom ? 'bottom' : '';\n return (\n <div className={`${prefixCls}-toolbar ${bottomClassName}`} style={{ height }}>\n <ToolbarItems {...props} commands={props.commands || commands || []} />\n {!isChild && <ToolbarItems {...props} commands={extraCommands || []} />}\n </div>\n );\n}\n"
|
|
71
76
|
],
|
|
72
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;;AAEA;;AAEA;;;;
|
|
77
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;;AAEA;;AAEA;;;;AAYO,SAASA,YAAT,CAAsBC,KAAtB,EAA4C;EACjD,IAAQC,SAAR,GAAgCD,KAAhC,CAAQC,SAAR;EAAA,IAAmBC,QAAnB,GAAgCF,KAAhC,CAAmBE,QAAnB;;EACA,kBAA8E,IAAAC,iBAAA,EAAWC,sBAAX,CAA9E;EAAA,IAAQC,UAAR,eAAQA,UAAR;EAAA,IAAoBC,OAApB,eAAoBA,OAApB;EAAA,uCAA6BC,QAA7B;EAAA,IAA6BA,QAA7B,qCAAwC,EAAxC;EAAA,IAA4CC,mBAA5C,eAA4CA,mBAA5C;EAAA,IAAiEC,QAAjE,eAAiEA,QAAjE;;EACA,IAAMC,gBAAgB,GAAG,IAAAC,aAAA,EAAO,EAAP,CAAzB;;EAEA,SAASC,WAAT,CAAqBC,OAArB,EAAgDC,IAAhD,EAA+D;IAC7D,IAAI,CAACL,QAAL,EAAe;IACf,IAAMM,KAAmB,GAAG;MAAER,QAAQ,kCAAOA,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,IAAIL,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;;EACA,mBAAoC,IAAA3D,iBAAA,EAAWC,sBAAX,CAApC;EAAA,IAAQc,QAAR,gBAAQA,QAAR;EAAA,IAAkB6C,aAAlB,gBAAkBA,aAAlB;;EACA,IAAMC,eAAe,GAAGH,aAAa,GAAG,QAAH,GAAc,EAAnD;EACA,oBACE;IAAK,SAAS,YAAK5D,SAAL,sBAA0B+D,eAA1B,CAAd;IAA2D,KAAK,EAAE;MAAEJ,MAAM,EAANA;IAAF,CAAlE;IAAA,wBACE,qBAAC,YAAD,8DAAkB5D,KAAlB;MAAyB,QAAQ,EAAEA,KAAK,CAACkB,QAAN,IAAkBA,QAAlB,IAA8B;IAAjE,GADF,EAEG,CAAC4C,OAAD,iBAAY,qBAAC,YAAD,8DAAkB9D,KAAlB;MAAyB,QAAQ,EAAE+D,aAAa,IAAI;IAApD,GAFf;EAAA,EADF;AAMD"
|
|
73
78
|
}
|
package/markdown-editor.css
CHANGED
|
@@ -182,6 +182,11 @@
|
|
|
182
182
|
-webkit-user-select: none;
|
|
183
183
|
user-select: none;
|
|
184
184
|
}
|
|
185
|
+
.w-md-editor-toolbar.bottom {
|
|
186
|
+
border-bottom: 0px;
|
|
187
|
+
border-top: 1px solid var(--color-border-default);
|
|
188
|
+
border-radius: 0 0 3px 3px;
|
|
189
|
+
}
|
|
185
190
|
.w-md-editor-toolbar ul,
|
|
186
191
|
.w-md-editor-toolbar li {
|
|
187
192
|
margin: 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.1",
|
|
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>",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@babel/runtime": "^7.14.6",
|
|
70
|
-
"@uiw/react-markdown-preview": "
|
|
70
|
+
"@uiw/react-markdown-preview": "^4.0.10",
|
|
71
71
|
"rehype-sanitize": "~5.0.1",
|
|
72
72
|
"rehype": "~12.0.1"
|
|
73
73
|
},
|
package/src/Editor.tsx
CHANGED
|
@@ -43,6 +43,10 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
43
43
|
/**
|
|
44
44
|
* Show drag and drop tool. Set the height of the editor.
|
|
45
45
|
*/
|
|
46
|
+
visibleDragbar?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated use `visibleDragbar`
|
|
49
|
+
*/
|
|
46
50
|
visiableDragbar?: boolean;
|
|
47
51
|
/**
|
|
48
52
|
* Show markdown preview.
|
|
@@ -57,11 +61,11 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
57
61
|
*/
|
|
58
62
|
overflow?: boolean;
|
|
59
63
|
/**
|
|
60
|
-
* Maximum drag height. `
|
|
64
|
+
* Maximum drag height. `visibleDragbar=true`
|
|
61
65
|
*/
|
|
62
66
|
maxHeight?: number;
|
|
63
67
|
/**
|
|
64
|
-
* Minimum drag height. `
|
|
68
|
+
* Minimum drag height. `visibleDragbar=true`
|
|
65
69
|
*/
|
|
66
70
|
minHeight?: number;
|
|
67
71
|
/**
|
|
@@ -107,6 +111,8 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
107
111
|
hideToolbar?: boolean;
|
|
108
112
|
/** Whether to enable scrolling */
|
|
109
113
|
enableScroll?: boolean;
|
|
114
|
+
/** Toolbar on bottom */
|
|
115
|
+
toolbarBottom?: boolean;
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
function setGroupPopFalse(data: Record<string, boolean> = {}) {
|
|
@@ -130,7 +136,7 @@ const InternalMDEditor = (
|
|
|
130
136
|
height = 200,
|
|
131
137
|
toolbarHeight = 29,
|
|
132
138
|
enableScroll = true,
|
|
133
|
-
|
|
139
|
+
visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,
|
|
134
140
|
highlightEnable = true,
|
|
135
141
|
preview: previewType = 'live',
|
|
136
142
|
fullscreen = false,
|
|
@@ -145,6 +151,7 @@ const InternalMDEditor = (
|
|
|
145
151
|
onChange,
|
|
146
152
|
onHeightChange,
|
|
147
153
|
hideToolbar,
|
|
154
|
+
toolbarBottom = false,
|
|
148
155
|
renderTextarea,
|
|
149
156
|
...other
|
|
150
157
|
} = props || {};
|
|
@@ -295,7 +302,9 @@ const InternalMDEditor = (
|
|
|
295
302
|
height: state.fullscreen ? '100%' : hideToolbar ? Number(state.height) - toolbarHeight : state.height,
|
|
296
303
|
}}
|
|
297
304
|
>
|
|
298
|
-
{!hideToolbar &&
|
|
305
|
+
{!hideToolbar && !toolbarBottom && (
|
|
306
|
+
<Toolbar prefixCls={prefixCls} height={toolbarHeight} overflow={overflow} toolbarBottom={toolbarBottom} />
|
|
307
|
+
)}
|
|
299
308
|
<div
|
|
300
309
|
className={`${prefixCls}-content`}
|
|
301
310
|
style={{
|
|
@@ -320,7 +329,7 @@ const InternalMDEditor = (
|
|
|
320
329
|
)}
|
|
321
330
|
{/(live|preview)/.test(state.preview || '') && mdPreview}
|
|
322
331
|
</div>
|
|
323
|
-
{
|
|
332
|
+
{visibleDragbar && !state.fullscreen && (
|
|
324
333
|
<DragBar
|
|
325
334
|
prefixCls={prefixCls}
|
|
326
335
|
height={state.height as number}
|
|
@@ -331,6 +340,9 @@ const InternalMDEditor = (
|
|
|
331
340
|
}}
|
|
332
341
|
/>
|
|
333
342
|
)}
|
|
343
|
+
{!hideToolbar && toolbarBottom && (
|
|
344
|
+
<Toolbar prefixCls={prefixCls} height={toolbarHeight} overflow={overflow} toolbarBottom={toolbarBottom} />
|
|
345
|
+
)}
|
|
334
346
|
</div>
|
|
335
347
|
</EditorContext.Provider>
|
|
336
348
|
);
|
|
@@ -8,6 +8,7 @@ import './index.less';
|
|
|
8
8
|
export interface IToolbarProps extends IProps {
|
|
9
9
|
overflow?: boolean;
|
|
10
10
|
height?: React.CSSProperties['height'];
|
|
11
|
+
toolbarBottom?: boolean;
|
|
11
12
|
onCommand?: (command: ICommand<string>, groupName?: string) => void;
|
|
12
13
|
commands?: ICommand<string>[];
|
|
13
14
|
isChild?: boolean;
|
|
@@ -118,10 +119,11 @@ export function ToolbarItems(props: IToolbarProps) {
|
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
export default function Toolbar(props: IToolbarProps = {}) {
|
|
121
|
-
const { prefixCls, height = 29, isChild } = props;
|
|
122
|
+
const { prefixCls, height = 29, toolbarBottom, isChild } = props;
|
|
122
123
|
const { commands, extraCommands } = useContext(EditorContext);
|
|
124
|
+
const bottomClassName = toolbarBottom ? 'bottom' : '';
|
|
123
125
|
return (
|
|
124
|
-
<div className={`${prefixCls}-toolbar`} style={{ height }}>
|
|
126
|
+
<div className={`${prefixCls}-toolbar ${bottomClassName}`} style={{ height }}>
|
|
125
127
|
<ToolbarItems {...props} commands={props.commands || commands || []} />
|
|
126
128
|
{!isChild && <ToolbarItems {...props} commands={extraCommands || []} />}
|
|
127
129
|
</div>
|