@uiw/react-md-editor 3.14.1 → 3.14.2
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 +22 -27
- package/dist/mdeditor.css +20 -11
- package/dist/mdeditor.js +774 -913
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/commands/bold.js +1 -1
- package/esm/commands/bold.js.map +2 -2
- package/esm/components/TextArea/Markdown.js +31 -24
- package/esm/components/TextArea/Markdown.js.map +12 -9
- package/esm/components/TextArea/index.js +3 -8
- package/esm/components/TextArea/index.js.map +2 -4
- package/esm/index.css +4 -0
- package/esm/index.less +6 -0
- package/lib/Context.js +3 -3
- package/lib/Context.js.map +1 -1
- package/lib/Editor.js +19 -19
- package/lib/Editor.js.map +1 -1
- package/lib/commands/bold.js +2 -2
- package/lib/commands/bold.js.map +1 -1
- package/lib/commands/code.js +1 -1
- package/lib/commands/fullscreen.js +1 -1
- package/lib/commands/group.js +4 -4
- package/lib/commands/group.js.map +1 -1
- package/lib/commands/hr.js +1 -1
- package/lib/commands/image.js +1 -1
- package/lib/commands/index.js +8 -8
- package/lib/commands/italic.js +1 -1
- package/lib/commands/link.js +1 -1
- package/lib/commands/list.js +1 -1
- package/lib/commands/preview.js +1 -1
- package/lib/commands/quote.js +1 -1
- package/lib/commands/strikeThrough.js +1 -1
- package/lib/commands/title.js +2 -2
- package/lib/commands/title.js.map +1 -1
- package/lib/commands/title1.js +1 -1
- package/lib/commands/title2.js +1 -1
- package/lib/commands/title3.js +1 -1
- package/lib/commands/title4.js +1 -1
- package/lib/commands/title5.js +1 -1
- package/lib/commands/title6.js +1 -1
- package/lib/components/DragBar/index.js +3 -3
- package/lib/components/TextArea/Markdown.js +39 -33
- package/lib/components/TextArea/Markdown.js.map +12 -9
- package/lib/components/TextArea/Textarea.js +10 -10
- package/lib/components/TextArea/Textarea.js.map +1 -1
- package/lib/components/TextArea/handleKeyDown.js +1 -1
- package/lib/components/TextArea/index.js +14 -19
- package/lib/components/TextArea/index.js.map +2 -4
- package/lib/components/TextArea/shortcuts.js +3 -3
- package/lib/components/TextArea/shortcuts.js.map +1 -1
- package/lib/components/Toolbar/Child.js +4 -4
- package/lib/components/Toolbar/Child.js.map +1 -1
- package/lib/components/Toolbar/index.js +11 -11
- package/lib/components/Toolbar/index.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/index.less +6 -0
- package/lib/utils/InsertTextAtPosition.js +2 -2
- package/lib/utils/InsertTextAtPosition.js.map +1 -1
- package/markdown-editor.css +4 -0
- package/package.json +2 -60
- package/src/commands/bold.tsx +1 -1
- package/src/components/TextArea/Markdown.tsx +31 -24
- package/src/components/TextArea/index.tsx +4 -4
- package/src/index.less +6 -0
- package/LICENSE +0 -21
- package/src/tsconfig.json +0 -8
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"markdown",
|
|
14
14
|
"scrollTop",
|
|
15
15
|
"commands",
|
|
16
|
-
"highlightEnable",
|
|
17
16
|
"extraCommands",
|
|
18
17
|
"dispatch",
|
|
19
18
|
"textRef",
|
|
@@ -30,7 +29,6 @@
|
|
|
30
29
|
"commandOrchestrator",
|
|
31
30
|
"TextAreaCommandOrchestrator",
|
|
32
31
|
"textarea",
|
|
33
|
-
"textStyle",
|
|
34
32
|
"cloneElement",
|
|
35
33
|
"value",
|
|
36
34
|
"autoComplete",
|
|
@@ -48,7 +46,7 @@
|
|
|
48
46
|
"../../../src/components/TextArea/index.tsx"
|
|
49
47
|
],
|
|
50
48
|
"sourcesContent": [
|
|
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,
|
|
49
|
+
"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, 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 ? { WebkitTextFillColor: 'transparent' } : { };\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 <Markdown prefixCls={prefixCls} />\n <Textarea prefixCls={prefixCls} {...otherProps} />\n </Fragment>\n )}\n </div>\n </div>\n );\n}\n"
|
|
52
50
|
],
|
|
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,
|
|
51
|
+
"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,kBAAmE,IAAAC,iBAAA,EAAWC,sBAAX,CAAnE;EAAA,IAAQC,QAAR,eAAQA,QAAR;EAAA,IAAkBC,SAAlB,eAAkBA,SAAlB;EAAA,IAA6BC,QAA7B,eAA6BA,QAA7B;EAAA,IAAuCC,aAAvC,eAAuCA,aAAvC;EAAA,IAAsDC,QAAtD,eAAsDA,QAAtD;;EACA,IAAMC,OAAO,GAAGC,iBAAA,CAAMC,MAAN,CAAkC,IAAlC,CAAhB;;EACA,IAAMC,UAAU,GAAGF,iBAAA,CAAMC,MAAN,EAAnB;;EACA,IAAME,IA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AFL;MATG,IAcZ;QACEvB,QAAQ,EAARA,QADF;QAEEwB,QAAQ,EAAE/B,UAAU,CAAC+B,QAFvB;QAGEC,SAAS,EAATA,qBAHF;QAIE/B,UAAU,EAAE;UAAEI,QAAQ,EAARA,QAAF;UAAYC,aAAa,EAAbA,aAAZ;UAA2Ba,mBAAmB,EAAER,UAAU,CAACK;QAA3D;MAJd,CAdY,CADhB,EAsBE;QACEiB,GAAG,EAAEzB;MADP,CAtBF,CADa,gBA4Bb,sBAAC,eAAD;QAAA,wBACE,qBAAC,oBAAD;UAAU,SAAS,EAAEZ;QAArB,EADF,eAEE,qBAAC,oBAAD;UAAU,SAAS,EAAEA;QAArB,GAAoCI,UAApC,EAFF;MAAA;IA7BJ;EADF,EADF;AAuCD"
|
|
54
52
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports
|
|
8
|
+
exports["default"] = shortcutsHandle;
|
|
9
9
|
|
|
10
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ function getCommands() {
|
|
|
14
14
|
var resulte = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
15
|
data.forEach(function (item) {
|
|
16
16
|
if (item.children && Array.isArray(item.children)) {
|
|
17
|
-
resulte = (0, _objectSpread2
|
|
17
|
+
resulte = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, resulte), getCommands(item.children || []));
|
|
18
18
|
} else if (item.keyCommand && item.shortcuts && item.execute) {
|
|
19
19
|
resulte[item.shortcuts.toLocaleLowerCase()] = item;
|
|
20
20
|
}
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"sourcesContent": [
|
|
49
49
|
"import { ICommand, TextAreaCommandOrchestrator } from '../../commands';\nimport { ContextStore, ExecuteCommandState } from '../../Context';\n\nfunction getCommands(data: ICommand[] = [], resulte: Record<string, ICommand> = {}): Record<string, ICommand> {\n data.forEach((item) => {\n if (item.children && Array.isArray(item.children)) {\n resulte = { ...resulte, ...getCommands(item.children || []) };\n } else if (item.keyCommand && item.shortcuts && item.execute) {\n resulte[item.shortcuts.toLocaleLowerCase()] = item;\n }\n });\n return resulte;\n}\n\nexport default function shortcutsHandle(\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n commands: ICommand[] = [],\n commandOrchestrator?: TextAreaCommandOrchestrator,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n) {\n const data = getCommands(commands || []);\n const shortcuts: (string | number)[] = [];\n if (e.altKey) {\n shortcuts.push('alt');\n }\n if (e.shiftKey) {\n shortcuts.push('shift');\n }\n if (e.metaKey) {\n shortcuts.push('cmd');\n }\n if (e.ctrlKey) {\n shortcuts.push('ctrl');\n }\n if (shortcuts.length > 0 && !/(control|alt|meta|shift)/.test(e.key.toLocaleLowerCase())) {\n shortcuts.push(e.key.toLocaleLowerCase());\n }\n if (/escape/.test(e.key.toLocaleLowerCase())) {\n shortcuts.push('escape');\n }\n if (shortcuts.length < 1) {\n return;\n }\n\n let equal = !!data[shortcuts.join('+')];\n let command = equal ? data[shortcuts.join('+')] : undefined;\n\n Object.keys(data).forEach((item) => {\n const isequal = item.split('+').every((v) => {\n if (/ctrlcmd/.test(v)) {\n return shortcuts.includes('ctrl') || shortcuts.includes('cmd');\n }\n return shortcuts.includes(v);\n });\n if (isequal) {\n command = data[item];\n }\n });\n if (command && commandOrchestrator) {\n e.stopPropagation();\n e.preventDefault();\n commandOrchestrator.executeCommand(command, dispatch, state);\n return;\n }\n}\n"
|
|
50
50
|
],
|
|
51
|
-
"mappings": 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AAa;MACXJ,OAAO,GAAG3B,IAAI,CAACG,IAAD,CAAd;IACD;EACF,CAVD;;EAWA,IAAIwB,OAAO,IAAIb,mBAAf,EAAoC;IAClCF,CAAC,CAACwB,eAAF;IACAxB,CAAC,CAACyB,cAAF;IACAvB,mBAAmB,CAACwB,cAApB,CAAmCX,OAAnC,EAA4CZ,QAA5C,EAAsDC,KAAtD;IACA;EACD;AACF"
|
|
52
52
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
4
|
|
|
5
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
exports
|
|
10
|
+
exports["default"] = Child;
|
|
11
11
|
|
|
12
12
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
13
|
|
|
@@ -36,7 +36,7 @@ function Child(props) {
|
|
|
36
36
|
onClick: function onClick(e) {
|
|
37
37
|
return e.stopPropagation();
|
|
38
38
|
},
|
|
39
|
-
children: Array.isArray(commands) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_
|
|
39
|
+
children: Array.isArray(commands) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
40
40
|
commands: commands
|
|
41
41
|
}, props), {}, {
|
|
42
42
|
height: "",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"sourcesContent": [
|
|
23
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"
|
|
24
24
|
],
|
|
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,
|
|
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,YAAD;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"
|
|
26
26
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
4
|
|
|
5
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
10
|
exports.ToolbarItems = ToolbarItems;
|
|
11
|
-
exports
|
|
11
|
+
exports["default"] = Toolbar;
|
|
12
12
|
|
|
13
13
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
14
|
|
|
@@ -37,7 +37,7 @@ function ToolbarItems(props) {
|
|
|
37
37
|
function handleClick(command, name) {
|
|
38
38
|
if (!dispatch) return;
|
|
39
39
|
var state = {
|
|
40
|
-
barPopup: (0, _objectSpread2
|
|
40
|
+
barPopup: (0, _objectSpread2["default"])({}, barPopup)
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
if (command.keyCommand === 'preview') {
|
|
@@ -63,7 +63,7 @@ function ToolbarItems(props) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (Object.keys(state).length) {
|
|
66
|
-
dispatch((0, _objectSpread2
|
|
66
|
+
dispatch((0, _objectSpread2["default"])({}, state));
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
commandOrchestrator && commandOrchestrator.executeCommand(command);
|
|
@@ -88,7 +88,7 @@ function ToolbarItems(props) {
|
|
|
88
88
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
89
89
|
children: (props.commands || []).map(function (item, idx) {
|
|
90
90
|
if (item.keyCommand === 'divider') {
|
|
91
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", (0, _objectSpread2
|
|
91
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item.liProps), {}, {
|
|
92
92
|
className: "".concat(prefixCls, "-toolbar-divider")
|
|
93
93
|
}), idx);
|
|
94
94
|
}
|
|
@@ -110,9 +110,9 @@ function ToolbarItems(props) {
|
|
|
110
110
|
}
|
|
111
111
|
}) : undefined;
|
|
112
112
|
var disabled = barPopup && preview && preview === 'preview' && !/(preview|fullscreen)/.test(item.keyCommand);
|
|
113
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", (0, _objectSpread2
|
|
113
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item.liProps), {}, {
|
|
114
114
|
className: activeBtn ? "active" : '',
|
|
115
|
-
children: [!item.buttonProps && item.icon, item.buttonProps && /*#__PURE__*/_react
|
|
115
|
+
children: [!item.buttonProps && item.icon, item.buttonProps && /*#__PURE__*/_react["default"].createElement('button', (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
116
116
|
type: 'button',
|
|
117
117
|
key: idx,
|
|
118
118
|
disabled: disabled,
|
|
@@ -122,7 +122,7 @@ function ToolbarItems(props) {
|
|
|
122
122
|
evn.stopPropagation();
|
|
123
123
|
handleClick(item, item.groupName);
|
|
124
124
|
}
|
|
125
|
-
}), item.icon), item.children && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Child
|
|
125
|
+
}), item.icon), item.children && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Child["default"], {
|
|
126
126
|
overflow: overflow,
|
|
127
127
|
groupName: item.groupName,
|
|
128
128
|
prefixCls: prefixCls,
|
|
@@ -152,9 +152,9 @@ function Toolbar() {
|
|
|
152
152
|
style: {
|
|
153
153
|
height: height
|
|
154
154
|
},
|
|
155
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarItems, (0, _objectSpread2
|
|
155
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarItems, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), {}, {
|
|
156
156
|
commands: props.commands || commands || []
|
|
157
|
-
})), !isChild && /*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarItems, (0, _objectSpread2
|
|
157
|
+
})), !isChild && /*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarItems, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), {}, {
|
|
158
158
|
commands: extraCommands || []
|
|
159
159
|
}))]
|
|
160
160
|
});
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"sourcesContent": [
|
|
75
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"
|
|
76
76
|
],
|
|
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;EA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9D,KAA3D,CAA+C8D,OAA/C;;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,oEAAkB5D,KAAlB;MAAyB,QAAQ,EAAEA,KAAK,CAACkB,QAAN,IAAkBA,QAAlB,IAA8B;IAAjE,GADF,EAEG,CAAC4C,OAAD,iBAAY,qBAAC,YAAD,oEAAkB9D,KAAlB;MAAyB,QAAQ,EAAE+D,aAAa,IAAI;IAApD,GAFf;EAAA,EADF;AAMD"
|
|
78
78
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -9,7 +9,7 @@ var _exportNames = {
|
|
|
9
9
|
commands: true,
|
|
10
10
|
MarkdownUtil: true
|
|
11
11
|
};
|
|
12
|
-
exports
|
|
12
|
+
exports["default"] = exports.commands = exports.MarkdownUtil = void 0;
|
|
13
13
|
|
|
14
14
|
var _Editor = _interopRequireWildcard(require("./Editor"));
|
|
15
15
|
|
|
@@ -68,6 +68,6 @@ Object.keys(_Context).forEach(function (key) {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
|
-
var _default = _Editor
|
|
72
|
-
exports
|
|
71
|
+
var _default = _Editor["default"];
|
|
72
|
+
exports["default"] = _default;
|
|
73
73
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
"sourcesContent": [
|
|
10
10
|
"import MDEditor from './Editor';\nimport * as commands from './commands';\nimport * as MarkdownUtil from './utils/markdownUtils';\n\nexport * from './commands';\nexport * from './utils/markdownUtils';\nexport * from './Editor';\nexport * from './Context';\n\nexport { MarkdownUtil, commands };\n\nexport default MDEditor;\n"
|
|
11
11
|
],
|
|
12
|
-
"mappings": ";;;;;;;;;;;;;AAAA;;AAMA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AALA;;;AAGA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAFA;;;AAGA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;eAIeA,
|
|
12
|
+
"mappings": ";;;;;;;;;;;;;AAAA;;AAMA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AALA;;;AAGA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAFA;;;AAGA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;eAIeA,kB"
|
|
13
13
|
}
|
package/lib/index.less
CHANGED
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
width: 50%;
|
|
23
23
|
height: 100%;
|
|
24
24
|
}
|
|
25
|
+
&-text-pre > code {
|
|
26
|
+
word-break: break-word !important;
|
|
27
|
+
white-space: pre-wrap !important;
|
|
28
|
+
}
|
|
25
29
|
&-preview {
|
|
26
30
|
width: 50%;
|
|
27
31
|
box-sizing: border-box;
|
|
@@ -35,6 +39,8 @@
|
|
|
35
39
|
border-radius: 0 0 5px 0;
|
|
36
40
|
display: flex;
|
|
37
41
|
flex-direction: column;
|
|
42
|
+
// word-break: break-word !important;
|
|
43
|
+
// white-space: pre-wrap !important;
|
|
38
44
|
.anchor {
|
|
39
45
|
display: none;
|
|
40
46
|
}
|
|
@@ -43,9 +43,9 @@ var insertAtLineStart = function insertAtLineStart(val, cursorIdx, input) {
|
|
|
43
43
|
var startIdx = 0;
|
|
44
44
|
|
|
45
45
|
while (cursorIdx--) {
|
|
46
|
-
var
|
|
46
|
+
var _char = content[cursorIdx];
|
|
47
47
|
|
|
48
|
-
if (
|
|
48
|
+
if (_char === '\n') {
|
|
49
49
|
startIdx = cursorIdx + 1;
|
|
50
50
|
break;
|
|
51
51
|
}
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"sourcesContent": [
|
|
64
64
|
"/**\n * The MIT License\n * Copyright (c) 2018 Dmitriy Kubyshkin\n * Copied from https://github.com/grassator/insert-text-at-cursor\n */\n\nlet browserSupportsTextareaTextNodes: any;\n\n/**\n * @param {HTMLElement} input\n * @return {boolean}\n */\nfunction canManipulateViaTextNodes(input: HTMLTextAreaElement | HTMLInputElement): boolean {\n if (input.nodeName !== 'TEXTAREA') {\n return false;\n }\n if (typeof browserSupportsTextareaTextNodes === 'undefined') {\n const textarea: HTMLTextAreaElement = document.createElement('textarea');\n textarea.value = '1';\n browserSupportsTextareaTextNodes = !!textarea.firstChild;\n }\n return browserSupportsTextareaTextNodes;\n}\n\n/**\n * @param {string} val\n * @param {number} cursorIdx\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @return {void}\n */\nexport const insertAtLineStart = (\n val: string,\n cursorIdx: number,\n input: HTMLTextAreaElement | HTMLInputElement,\n): void => {\n const content = input.value;\n let startIdx = 0;\n\n while (cursorIdx--) {\n let char = content[cursorIdx];\n if (char === '\\n') {\n startIdx = cursorIdx + 1;\n break;\n }\n }\n\n input.focus();\n input.setRangeText(val, startIdx, startIdx);\n input.dispatchEvent(new Event('input', { bubbles: true }));\n};\n\n/**\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @param {string} text\n * @returns {void}\n */\nexport function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string): void {\n // Most of the used APIs only work with the field selected\n input.focus();\n\n // IE 8-10\n if ((document as any).selection) {\n const ieRange = (document as any).selection.createRange();\n ieRange.text = text;\n\n // Move cursor after the inserted text\n ieRange.collapse(false /* to the end */);\n ieRange.select();\n\n return;\n }\n\n // Webkit + Edge\n const isSuccess = document.execCommand && document.execCommand('insertText', false, text);\n if (!isSuccess) {\n const start = input.selectionStart!;\n const end = input.selectionEnd!;\n // Firefox (non-standard method)\n if (typeof input.setRangeText === 'function') {\n input.setRangeText(text);\n } else {\n // To make a change we just need a Range, not a Selection\n const range = document.createRange();\n const textNode = document.createTextNode(text);\n\n if (canManipulateViaTextNodes(input)) {\n let node = input.firstChild;\n\n // If textarea is empty, just insert the text\n if (!node) {\n input.appendChild(textNode);\n } else {\n // Otherwise we need to find a nodes for start and end\n let offset = 0;\n let startNode = null;\n let endNode = null;\n\n while (node && (startNode === null || endNode === null)) {\n const nodeLength = node.nodeValue!.length;\n\n // if start of the selection falls into current node\n if (start >= offset && start <= offset + nodeLength) {\n range.setStart((startNode = node), start - offset);\n }\n\n // if end of the selection falls into current node\n if (end >= offset && end <= offset + nodeLength) {\n range.setEnd((endNode = node), end - offset);\n }\n\n offset += nodeLength;\n node = node.nextSibling;\n }\n\n // If there is some text selected, remove it as we should replace it\n if (start !== end) {\n range.deleteContents();\n }\n }\n }\n\n // If the node is a textarea and the range doesn't span outside the element\n //\n // Get the commonAncestorContainer of the selected range and test its type\n // If the node is of type `#text` it means that we're still working with text nodes within our textarea element\n // otherwise, if it's of type `#document` for example it means our selection spans outside the textarea.\n if (canManipulateViaTextNodes(input) && range.commonAncestorContainer.nodeName === '#text') {\n // Finally insert a new node. The browser will automatically split start and end nodes into two if necessary\n range.insertNode(textNode);\n } else {\n // If the node is not a textarea or the range spans outside a textarea the only way is to replace the whole value\n const value = input.value;\n input.value = value.slice(0, start) + text + value.slice(end);\n }\n }\n\n // Correct the cursor position to be at the end of the insertion\n input.setSelectionRange(start + text.length, start + text.length);\n\n // Notify any possible listeners of the change\n const e = document.createEvent('UIEvent');\n e.initEvent('input', true, false);\n input.dispatchEvent(e);\n }\n}\n"
|
|
65
65
|
],
|
|
66
|
-
"mappings": ";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,IAAIA,gCAAJ;AAEA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAmCC,KAAnC,EAA2F;EACzF,IAAIA,KAAK,CAACC,QAAN,KAAmB,UAAvB,EAAmC;IACjC,OAAO,KAAP;EACD;;EACD,IAAI,OAAOH,gCAAP,KAA4C,WAAhD,EAA6D;IAC3D,IAAMI,QAA6B,GAAGC,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAtC;IACAF,QAAQ,CAACG,KAAT,GAAiB,GAAjB;IACAP,gCAAgC,GAAG,CAAC,CAACI,QAAQ,CAACI,UAA9C;EACD;;EACD,OAAOR,gCAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,IAAMS,iBAAiB,GAAG,SAApBA,iBAAoB,CAC/BC,GAD+B,EAE/BC,SAF+B,EAG/BT,KAH+B,EAItB;EACT,IAAMU,OAAO,GAAGV,KAAK,CAACK,KAAtB;EACA,IAAIM,QAAQ,GAAG,CAAf;;EAEA,OAAOF,SAAS,EAAhB,EAAoB;IAClB,IAAIG,
|
|
66
|
+
"mappings": ";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,IAAIA,gCAAJ;AAEA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAmCC,KAAnC,EAA2F;EACzF,IAAIA,KAAK,CAACC,QAAN,KAAmB,UAAvB,EAAmC;IACjC,OAAO,KAAP;EACD;;E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ArC,EAAiD;cAC/CR,KAAK,CAACY,MAAN,CAAcL,OAAO,GAAGJ,IAAxB,EAA+BL,GAAG,GAAGO,MAArC;YACD;;YAEDA,MAAM,IAAIG,UAAV;YACAL,IAAI,GAAGA,IAAI,CAACU,WAAZ;UACD,CArBI,CAuBL;;;UACA,IAAIjB,KAAK,KAAKE,GAAd,EAAmB;YACjBE,KAAK,CAACc,cAAN;UACD;QACF;MACF,CAvCI,CAyCL;MACA;MACA;MACA;MACA;;;MACA,IAAI9C,yBAAyB,CAACC,KAAD,CAAzB,IAAoC+B,KAAK,CAACe,uBAAN,CAA8B7C,QAA9B,KAA2C,OAAnF,EAA4F;QAC1F;QACA8B,KAAK,CAACgB,UAAN,CAAiBf,QAAjB;MACD,CAHD,MAGO;QACL;QACA,IAAM3B,KAAK,GAAGL,KAAK,CAACK,KAApB;QACAL,KAAK,CAACK,KAAN,GAAcA,KAAK,CAAC2C,KAAN,CAAY,CAAZ,EAAerB,KAAf,IAAwBR,IAAxB,GAA+Bd,KAAK,CAAC2C,KAAN,CAAYnB,GAAZ,CAA7C;MACD;IACF,CA5Da,CA8Dd;;;IACA7B,KAAK,CAACiD,iBAAN,CAAwBtB,KAAK,GAAGR,IAAI,CAACsB,MAArC,EAA6Cd,KAAK,GAAGR,IAAI,CAACsB,MAA1D,EA/Dc,CAiEd;;IACA,IAAMS,CAAC,GAAG/C,QAAQ,CAACgD,WAAT,CAAqB,SAArB,CAAV;IACAD,CAAC,CAACE,SAAF,CAAY,OAAZ,EAAqB,IAArB,EAA2B,KAA3B;IACApD,KAAK,CAACe,aAAN,CAAoBmC,CAApB;EACD;AACF"
|
|
67
67
|
}
|
package/markdown-editor.css
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.2",
|
|
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>",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"module": "esm/index.js",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"prepare": "husky install && npm run build",
|
|
11
|
-
"released": "npm run build && npm run doc",
|
|
12
|
-
"doc": "kkt build --app-src ./website",
|
|
13
|
-
"start": "kkt start --app-src ./website",
|
|
14
10
|
"css:build": "compile-less -d src -o esm",
|
|
15
11
|
"css:watch": "compile-less -d src -o esm --watch",
|
|
16
12
|
"css:build:dist": "compile-less -d src --combine markdown-editor.css --rm-global",
|
|
@@ -20,9 +16,7 @@
|
|
|
20
16
|
"watch": "tsbb watch & npm run css:watch",
|
|
21
17
|
"build": "tsbb build && npm run css:build && npm run css:build:dist",
|
|
22
18
|
"test": "tsbb test --env=jsdom",
|
|
23
|
-
"coverage": "tsbb test --env=jsdom --coverage --bail"
|
|
24
|
-
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
|
|
25
|
-
"map": "source-map-explorer build/static/js/*.js --html build/website-result.html"
|
|
19
|
+
"coverage": "tsbb test --env=jsdom --coverage --bail"
|
|
26
20
|
},
|
|
27
21
|
"repository": {
|
|
28
22
|
"type": "git",
|
|
@@ -40,35 +34,9 @@
|
|
|
40
34
|
"react": ">=16.8.0",
|
|
41
35
|
"react-dom": ">=16.8.0"
|
|
42
36
|
},
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"@kkt/less-modules": "~7.1.1",
|
|
45
|
-
"@kkt/ncc": "~1.0.9",
|
|
46
|
-
"@kkt/raw-modules": "~7.1.1",
|
|
47
|
-
"@kkt/scope-plugin-options": "~7.1.1",
|
|
48
|
-
"@types/katex": "~0.14.0",
|
|
49
|
-
"@types/react": "~18.0.9",
|
|
50
|
-
"@types/react-dom": "~18.0.3",
|
|
51
|
-
"@types/react-test-renderer": "~18.0.0",
|
|
52
|
-
"@uiw/react-github-corners": "~1.5.3",
|
|
53
|
-
"@uiw/react-shields": "~1.1.2",
|
|
54
|
-
"@wcj/dark-mode": "~1.0.9",
|
|
55
|
-
"compile-less-cli": "~1.8.13",
|
|
56
|
-
"katex": "~0.15.2",
|
|
57
|
-
"husky": "~8.0.0",
|
|
58
|
-
"kkt": "~7.1.5",
|
|
59
|
-
"lint-staged": "~12.4.0",
|
|
60
|
-
"mermaid": "~8.14.0",
|
|
61
|
-
"prettier": "~2.6.0",
|
|
62
|
-
"react": "~18.1.0",
|
|
63
|
-
"react-dom": "~18.1.0",
|
|
64
|
-
"react-test-renderer": "~18.1.0",
|
|
65
|
-
"source-map-explorer": "~2.5.2",
|
|
66
|
-
"tsbb": "~3.7.0"
|
|
67
|
-
},
|
|
68
37
|
"dependencies": {
|
|
69
38
|
"@babel/runtime": "^7.14.6",
|
|
70
39
|
"@uiw/react-markdown-preview": "^4.0.10",
|
|
71
|
-
"rehype-sanitize": "~5.0.1",
|
|
72
40
|
"rehype": "~12.0.1"
|
|
73
41
|
},
|
|
74
42
|
"keywords": [
|
|
@@ -89,31 +57,5 @@
|
|
|
89
57
|
"transformIgnorePatterns": [
|
|
90
58
|
"<rootDir>/node_modules/?!(.*)"
|
|
91
59
|
]
|
|
92
|
-
},
|
|
93
|
-
"lint-staged": {
|
|
94
|
-
"*.{js,jsx,less,md,json}": [
|
|
95
|
-
"prettier --write"
|
|
96
|
-
],
|
|
97
|
-
"*.ts?(x)": [
|
|
98
|
-
"prettier --parser=typescript --write"
|
|
99
|
-
]
|
|
100
|
-
},
|
|
101
|
-
"eslintConfig": {
|
|
102
|
-
"extends": [
|
|
103
|
-
"react-app",
|
|
104
|
-
"react-app/jest"
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
"browserslist": {
|
|
108
|
-
"production": [
|
|
109
|
-
">0.2%",
|
|
110
|
-
"not dead",
|
|
111
|
-
"not op_mini all"
|
|
112
|
-
],
|
|
113
|
-
"development": [
|
|
114
|
-
"last 1 chrome version",
|
|
115
|
-
"last 1 firefox version",
|
|
116
|
-
"last 1 safari version"
|
|
117
|
-
]
|
|
118
60
|
}
|
|
119
61
|
}
|
package/src/commands/bold.tsx
CHANGED
|
@@ -4,11 +4,25 @@ import rehypePrism from 'rehype-prism-plus';
|
|
|
4
4
|
import { IProps } from '../../Editor';
|
|
5
5
|
import { EditorContext } from '../../Context';
|
|
6
6
|
|
|
7
|
+
function html2Escape(sHtml: string) {
|
|
8
|
+
return sHtml
|
|
9
|
+
.replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, (str: string) => {
|
|
10
|
+
return str.replace(
|
|
11
|
+
/[<&"]/g,
|
|
12
|
+
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record<string, string>)[c]),
|
|
13
|
+
);
|
|
14
|
+
})
|
|
15
|
+
.replace(
|
|
16
|
+
/[<&"]/g,
|
|
17
|
+
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record<string, string>)[c]),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
7
21
|
export interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}
|
|
8
22
|
|
|
9
23
|
export default function Markdown(props: MarkdownProps) {
|
|
10
24
|
const { prefixCls } = props;
|
|
11
|
-
const { markdown = '', dispatch } = useContext(EditorContext);
|
|
25
|
+
const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);
|
|
12
26
|
const preRef = React.createRef<HTMLPreElement>();
|
|
13
27
|
useEffect(() => {
|
|
14
28
|
if (preRef.current && dispatch) {
|
|
@@ -16,35 +30,28 @@ export default function Markdown(props: MarkdownProps) {
|
|
|
16
30
|
}
|
|
17
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
18
32
|
}, []);
|
|
19
|
-
function html2Escape(sHtml: string) {
|
|
20
|
-
return sHtml
|
|
21
|
-
.replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, (str: string) => {
|
|
22
|
-
return str.replace(
|
|
23
|
-
/[<&"]/g,
|
|
24
|
-
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record<string, string>)[c]),
|
|
25
|
-
);
|
|
26
|
-
})
|
|
27
|
-
.replace(
|
|
28
|
-
/[<&"]/g,
|
|
29
|
-
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record<string, string>)[c]),
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
33
|
|
|
33
34
|
return useMemo(() => {
|
|
34
35
|
if (!markdown) {
|
|
35
|
-
return <pre
|
|
36
|
+
return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
38
|
+
let mdStr = `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
|
|
39
|
+
markdown,
|
|
40
|
+
)}\n</code></pre>`;
|
|
41
|
+
|
|
42
|
+
if (highlightEnable) {
|
|
43
|
+
try {
|
|
44
|
+
mdStr = rehype()
|
|
45
|
+
.data('settings', { fragment: true })
|
|
46
|
+
.use(rehypePrism, { ignoreMissing: false })
|
|
47
|
+
.processSync(mdStr)
|
|
48
|
+
.toString();
|
|
49
|
+
} catch (error) {}
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
return React.createElement('div', {
|
|
46
53
|
className: 'wmde-markdown-color',
|
|
47
|
-
dangerouslySetInnerHTML: { __html:
|
|
54
|
+
dangerouslySetInnerHTML: { __html: mdStr || '' },
|
|
48
55
|
});
|
|
49
56
|
}, [markdown, preRef, prefixCls]);
|
|
50
57
|
}
|
|
@@ -42,7 +42,7 @@ export type TextAreaRef = {
|
|
|
42
42
|
|
|
43
43
|
export default function TextArea(props: ITextAreaProps) {
|
|
44
44
|
const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};
|
|
45
|
-
const { markdown, scrollTop, commands,
|
|
45
|
+
const { markdown, scrollTop, commands, extraCommands, dispatch } = useContext(EditorContext);
|
|
46
46
|
const textRef = React.useRef<HTMLTextAreaElement>(null);
|
|
47
47
|
const executeRef = React.useRef<TextAreaCommandOrchestrator>();
|
|
48
48
|
const warp = React.createRef<HTMLDivElement>();
|
|
@@ -68,7 +68,7 @@ export default function TextArea(props: ITextAreaProps) {
|
|
|
68
68
|
}, []);
|
|
69
69
|
|
|
70
70
|
// @ts-ignore
|
|
71
|
-
const textStyle: React.CSSProperties = highlightEnable ? {
|
|
71
|
+
// const textStyle: React.CSSProperties = highlightEnable ? { WebkitTextFillColor: 'transparent' } : { };
|
|
72
72
|
|
|
73
73
|
return (
|
|
74
74
|
<div ref={warp} className={`${prefixCls}-aree ${className || ''}`} onScroll={onScroll}>
|
|
@@ -102,8 +102,8 @@ export default function TextArea(props: ITextAreaProps) {
|
|
|
102
102
|
)
|
|
103
103
|
) : (
|
|
104
104
|
<Fragment>
|
|
105
|
-
|
|
106
|
-
<Textarea prefixCls={prefixCls} {...otherProps}
|
|
105
|
+
<Markdown prefixCls={prefixCls} />
|
|
106
|
+
<Textarea prefixCls={prefixCls} {...otherProps} />
|
|
107
107
|
</Fragment>
|
|
108
108
|
)}
|
|
109
109
|
</div>
|
package/src/index.less
CHANGED
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
width: 50%;
|
|
23
23
|
height: 100%;
|
|
24
24
|
}
|
|
25
|
+
&-text-pre > code {
|
|
26
|
+
word-break: break-word !important;
|
|
27
|
+
white-space: pre-wrap !important;
|
|
28
|
+
}
|
|
25
29
|
&-preview {
|
|
26
30
|
width: 50%;
|
|
27
31
|
box-sizing: border-box;
|
|
@@ -35,6 +39,8 @@
|
|
|
35
39
|
border-radius: 0 0 5px 0;
|
|
36
40
|
display: flex;
|
|
37
41
|
flex-direction: column;
|
|
42
|
+
// word-break: break-word !important;
|
|
43
|
+
// white-space: pre-wrap !important;
|
|
38
44
|
.anchor {
|
|
39
45
|
display: none;
|
|
40
46
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 uiw
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|