@uiw/react-md-editor 3.11.3 → 3.12.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 +2 -1
- package/dist/mdeditor.css +10 -15
- package/dist/mdeditor.js +1342 -165
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.js.map +5 -5
- package/esm/Editor.d.ts +5 -1
- package/esm/Editor.js +9 -7
- package/esm/Editor.js.map +7 -6
- package/esm/commands/bold.js.map +5 -5
- package/esm/commands/code.js +4 -2
- package/esm/commands/code.js.map +7 -6
- package/esm/commands/comment.js.map +5 -5
- package/esm/commands/divider.js.map +5 -5
- package/esm/commands/fullscreen.js.map +5 -5
- package/esm/commands/group.js.map +5 -5
- package/esm/commands/hr.js.map +5 -5
- package/esm/commands/image.js.map +5 -5
- package/esm/commands/index.js.map +5 -5
- package/esm/commands/italic.js.map +5 -5
- package/esm/commands/link.js.map +5 -5
- package/esm/commands/list.js.map +5 -5
- package/esm/commands/preview.js.map +5 -5
- package/esm/commands/quote.js.map +5 -5
- package/esm/commands/strikeThrough.js.map +5 -5
- package/esm/commands/title.js.map +5 -5
- package/esm/commands/title1.js.map +5 -5
- package/esm/commands/title2.js.map +5 -5
- package/esm/commands/title3.js.map +5 -5
- package/esm/commands/title4.js.map +5 -5
- package/esm/commands/title5.js.map +5 -5
- package/esm/commands/title6.js.map +5 -5
- package/esm/components/DragBar/index.js.map +5 -5
- package/esm/components/TextArea/Markdown.js.map +5 -5
- package/esm/components/TextArea/Textarea.js.map +5 -5
- package/esm/components/TextArea/handleKeyDown.js.map +5 -5
- package/esm/components/TextArea/index.js.map +5 -5
- package/esm/components/TextArea/shortcuts.js.map +5 -5
- package/esm/components/Toolbar/Child.js.map +5 -5
- package/esm/components/Toolbar/index.js.map +5 -5
- package/esm/index.js.map +5 -5
- package/esm/utils/InsertTextAtPosition.js.map +5 -5
- package/esm/utils/markdownUtils.js.map +5 -5
- package/lib/Context.js.map +5 -5
- package/lib/Editor.d.ts +5 -1
- package/lib/Editor.js +13 -9
- package/lib/Editor.js.map +7 -6
- package/lib/commands/bold.js.map +5 -5
- package/lib/commands/code.js +4 -2
- package/lib/commands/code.js.map +7 -6
- package/lib/commands/comment.js.map +5 -5
- package/lib/commands/divider.js.map +5 -5
- package/lib/commands/fullscreen.js.map +5 -5
- package/lib/commands/group.js.map +5 -5
- package/lib/commands/hr.js.map +5 -5
- package/lib/commands/image.js.map +5 -5
- package/lib/commands/index.js.map +5 -5
- package/lib/commands/italic.js.map +5 -5
- package/lib/commands/link.js.map +5 -5
- package/lib/commands/list.js.map +5 -5
- package/lib/commands/preview.js.map +5 -5
- package/lib/commands/quote.js.map +5 -5
- package/lib/commands/strikeThrough.js.map +5 -5
- package/lib/commands/title.js.map +5 -5
- package/lib/commands/title1.js.map +5 -5
- package/lib/commands/title2.js.map +5 -5
- package/lib/commands/title3.js.map +5 -5
- package/lib/commands/title4.js.map +5 -5
- package/lib/commands/title5.js.map +5 -5
- package/lib/commands/title6.js.map +5 -5
- package/lib/components/DragBar/index.js.map +5 -5
- package/lib/components/TextArea/Markdown.js.map +5 -5
- package/lib/components/TextArea/Textarea.js.map +5 -5
- package/lib/components/TextArea/handleKeyDown.js.map +5 -5
- package/lib/components/TextArea/index.js.map +5 -5
- package/lib/components/TextArea/shortcuts.js.map +5 -5
- package/lib/components/Toolbar/Child.js.map +5 -5
- package/lib/components/Toolbar/index.js.map +5 -5
- package/lib/index.js.map +5 -5
- package/lib/utils/InsertTextAtPosition.js.map +5 -5
- package/lib/utils/markdownUtils.js.map +5 -5
- package/package.json +1 -1
- package/src/Editor.tsx +13 -4
- package/src/__test__/editor.test.tsx +28 -3
- package/src/commands/code.tsx +2 -2
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../../../src/components/TextArea/handleKeyDown.tsx"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"stopPropagation",
|
|
8
5
|
"e",
|
|
@@ -56,8 +53,11 @@
|
|
|
56
53
|
"startsWith",
|
|
57
54
|
"parseInt"
|
|
58
55
|
],
|
|
59
|
-
"
|
|
56
|
+
"sources": [
|
|
57
|
+
"../../../src/components/TextArea/handleKeyDown.tsx"
|
|
58
|
+
],
|
|
60
59
|
"sourcesContent": [
|
|
61
60
|
"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"
|
|
62
|
-
]
|
|
61
|
+
],
|
|
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,CACbF,CADa,EAIb;EAAA,IAFAG,OAEA,uEAFkB,CAElB;EAAA,IADAC,gBACA,uEAD4B,KAC5B;EACA,IAAMC,MAAM,GAAGL,CAAC,CAACK,MAAjB;EACA,IAAMC,OAAO,GAAGD,MAAM,CAACE,KAAP,CAAaC,MAAb,CAAoB,CAApB,EAAuBH,MAAM,CAACI,cAA9B,CAAhB;EACA,IAAMC,MAAM,GAAGJ,OAAO,CAACK,KAAR,CAAc,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,KAEC,YAAY6B,IAAZ,CAAiBlC,cAAjB,KAAoC,UAAUkC,IAAV,CAAelC,cAAf,CAFrC,CADK,EAIL;IACA;AACJ;AACA;IACIb,eAAe,CAACC,CAAD,CAAf;IACA,IAAI+C,QAAQ,GAAG,MAAf;;IAEA,IAAInC,cAAc,CAACoC,UAAf,CAA0B,GAA1B,CAAJ,EAAoC;MAClCD,QAAQ,GAAG,MAAX;IACD;;IAED,IAAInC,cAAc,CAACoC,UAAf,CAA0B,OAA1B,CAAJ,EAAwC;MACtCD,QAAQ,GAAG,UAAX;IACD,CAFD,MAEO,IAAInC,cAAc,CAACoC,UAAf,CAA0B,OAA1B,CAAJ,EAAwC;MAC7CD,QAAQ,GAAG,UAAX;IACD;;IAED,IAAI,UAAUD,IAAV,CAAelC,cAAf,CAAJ,EAAoC;MAClCmC,QAAQ,eAAQE,QAAQ,CAACrC,cAAD,CAAR,GAA2B,CAAnC,OAAR;IACD;;IACD,OAAO,gDAAqBP,MAArB,EAA6B0C,QAA7B,CAAP;EACD;AACF"
|
|
63
63
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../../../src/components/TextArea/index.tsx"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"TextArea",
|
|
8
5
|
"props",
|
|
@@ -46,8 +43,11 @@
|
|
|
46
43
|
"useContext",
|
|
47
44
|
"ref"
|
|
48
45
|
],
|
|
49
|
-
"
|
|
46
|
+
"sources": [
|
|
47
|
+
"../../../src/components/TextArea/index.tsx"
|
|
48
|
+
],
|
|
50
49
|
"sourcesContent": [
|
|
51
50
|
"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"
|
|
52
|
-
]
|
|
51
|
+
],
|
|
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,uBAAWC,sBAAX,CAApF;EAAA,IAAQC,QAAR,eAAQA,QAAR;EAAA,IAAkBC,SAAlB,eAAkBA,SAAlB;EAAA,IAA6BC,QAA7B,eAA6BA,QAA7B;EAAA,IAAuCC,eAAvC,eAAuCA,eAAvC;EAAA,IAAwDC,aAAxD,eAAwDA,aAAxD;EAAA,IAAuEC,QAAvE,eAAuEA,QAAvE;;EACA,IAAMC,OAAO,GAAGC,eAAMC,MAAN,CAAkC,IAAlC,CAAhB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,SAAS,YAAKD,SAAL,gBARC;QASVgC,KAAK,EAAE;UACLC,mBAAmB,EAAE,SADhB;UAELC,QAAQ,EAAE;QAFL;MATG,IAcZ;QACEvB,QAAQ,EAARA,QADF;QAEEwB,QAAQ,EAAE/B,UAAU,CAAC+B,QAFvB;QAGEC,SAAS,EAATA,kBAHF;QAIEC,UAAU,EAAE;UAAE7B,QAAQ,EAARA,QAAF;UAAYE,aAAa,EAAbA,aAAZ;UAA2BY,mBAAmB,EAAEP,UAAU,CAACI;QAA3D;MAJd,CAdY,CADhB,EAsBE;QACEmB,GAAG,EAAE1B;MADP,CAtBF,CADa,gBA4Bb,sBAAC,eAAD;QAAA,WACGH,eAAe,iBAAI,qBAAC,iBAAD;UAAU,SAAS,EAAET;QAArB,EADtB,eAEE,qBAAC,iBAAD;UAAU,SAAS,EAAEA;QAArB,GAAoCI,UAApC;UAAgD,KAAK,EAAEqB;QAAvD,GAFF;MAAA;IA7BJ;EADF,EADF;AAuCD"
|
|
53
53
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../../../src/components/TextArea/shortcuts.ts"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"getCommands",
|
|
8
5
|
"data",
|
|
@@ -45,8 +42,11 @@
|
|
|
45
42
|
"preventDefault",
|
|
46
43
|
"executeCommand"
|
|
47
44
|
],
|
|
48
|
-
"
|
|
45
|
+
"sources": [
|
|
46
|
+
"../../../src/components/TextArea/shortcuts.ts"
|
|
47
|
+
],
|
|
49
48
|
"sourcesContent": [
|
|
50
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"
|
|
51
|
-
]
|
|
50
|
+
],
|
|
51
|
+
"mappings": ";;;;;;;;;;;AAGA,SAASA,WAAT,GAA8G;EAAA,IAAzFC,IAAyF,uEAAtE,EAAsE;EAAA,IAAlEC,OAAkE,uEAA9B,EAA8B;EAC5GD,IAAI,CAACE,OAAL,CAAa,UAACC,IAAD,EAAU;IACrB,IAAIA,IAAI,CAACC,QAAL,IAAiBC,KAAK,CAACC,OAAN,CAAcH,IAAI,CAACC,QAAnB,CAArB,EAAmD;MACjDH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"sources": [
|
|
18
|
+
"../../../src/components/Toolbar/Child.tsx"
|
|
19
|
+
],
|
|
21
20
|
"sourcesContent": [
|
|
22
21
|
"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"
|
|
23
|
-
]
|
|
22
|
+
],
|
|
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,uBAAWC,sBAAX,CAA1B;EAAA,uCAAQC,QAAR;EAAA,IAAQA,QAAR,qCAAmB,EAAnB;;EACA,OAAO,oBACL;IAAA,oBACE;MACE,SAAS,YAAKL,SAAL,4BAAgCC,SAAS,IAAII,QAAQ,CAACJ,SAAD,CAArB,GAAmC,QAAnC,GAA8C,EAA9E,CADX;MAEE,OAAO,EAAE,iBAACK,CAAD;QAAA,OAAOA,CAAC,CAACC,eAAF,EAAP;MAAA,CAFX;MAAA,UAIGC,KAAK,CAACC,OAAN,CAAcP,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,EAAWG,QAAX,EAAqBJ,SAArB,EAAgCD,SAAhC,CAVK,CAAP;AAYD"
|
|
24
24
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../../../src/components/Toolbar/index.tsx"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"ToolbarItems",
|
|
8
5
|
"props",
|
|
@@ -66,8 +63,11 @@
|
|
|
66
63
|
"isChild",
|
|
67
64
|
"extraCommands"
|
|
68
65
|
],
|
|
69
|
-
"
|
|
66
|
+
"sources": [
|
|
67
|
+
"../../../src/components/Toolbar/index.tsx"
|
|
68
|
+
],
|
|
70
69
|
"sourcesContent": [
|
|
71
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"
|
|
72
|
-
]
|
|
71
|
+
],
|
|
72
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;;AAEA;;AAEA;;;;AAWO,SAASA,YAAT,CAAsBC,KAAtB,EAA4C;EACjD,IAAQC,SAAR,GAAgCD,KAAhC,CAAQC,SAAR;EAAA,IAAmBC,QAAnB,GAAgCF,KAAhC,CAAmBE,QAAnB;;EACA,kBAA8E,uBAAWC,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,mBAAO,EAAP,CAAzB;;EAEA,SAASC,WAAT,CAAqBC,OAArB,EAAgDC,IAAhD,EAA+D;IAC7D,IAAI,CAACJ,QAAL,EAAe;IACf,IAAMK,KAAmB,GAAG;MAAEP,QAAQ,kCAAOA,QAAP;IAAV,CAA5B;;IACA,IAAIK,OAAO,CAACG,UAAR,KAAuB,SAA3B,EAAsC;MACpCD,KAAK,CAACR,OAAN,GAAgBM,OAAO,CAACI,KAAxB;IACD;;IACD,IAAIJ,OAAO,CAACG,UAAR,KAAuB,YAA3B,EAAyC;MACvCD,KAAK,CAACT,UAAN,GAAmB,CAACA,UAApB;IACD;;IACD,IAAIJ,KAAK,CAACgB,QAAN,IAAkBL,OAAO,CAACG,UA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K,SAAS,YAAK1D,SAAL,aAAd;IAAwC,KAAK,EAAE;MAAEwD,MAAM,EAANA;IAAF,CAA/C;IAAA,wBACE,qBAAC,YAAD,8DAAkBzD,KAAlB;MAAyB,QAAQ,EAAEA,KAAK,CAACgB,QAAN,IAAkBA,QAAlB,IAA8B;IAAjE,GADF,EAEG,CAAC0C,OAAD,iBAAY,qBAAC,YAAD,8DAAkB1D,KAAlB;MAAyB,QAAQ,EAAE2D,aAAa,IAAI;IAApD,GAFf;EAAA,EADF;AAMD"
|
|
73
73
|
}
|
package/lib/index.js.map
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../src/index.tsx"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"MDEditor"
|
|
8
5
|
],
|
|
9
|
-
"
|
|
6
|
+
"sources": [
|
|
7
|
+
"../src/index.tsx"
|
|
8
|
+
],
|
|
10
9
|
"sourcesContent": [
|
|
11
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"
|
|
12
|
-
]
|
|
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,e"
|
|
13
13
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../../src/utils/InsertTextAtPosition.ts"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"browserSupportsTextareaTextNodes",
|
|
8
5
|
"canManipulateViaTextNodes",
|
|
@@ -60,8 +57,11 @@
|
|
|
60
57
|
"createEvent",
|
|
61
58
|
"initEvent"
|
|
62
59
|
],
|
|
63
|
-
"
|
|
60
|
+
"sources": [
|
|
61
|
+
"../../src/utils/InsertTextAtPosition.ts"
|
|
62
|
+
],
|
|
64
63
|
"sourcesContent": [
|
|
65
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"
|
|
66
|
-
]
|
|
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,IAAI,GAAGF,OAAO,CAACD,SAAD,CAAlB;;IACA,IAAIG,IAAI,KAAK,IAAb,EAAmB;MACjBD,QAAQ,GAAGF,SAAS,GAAG,CAAvB;MACA;IACD;EACF;;EAEDT,KAAK,CAACa,KAAN;EACAb,KAAK,CAACc,YAAN,CAAmBN,GAAnB,EAAwBG,QAAxB,EAAkCA,QAAlC;EACAX,KAAK,CAACe,aAAN,CAAoB,IAAIC,KAAJ,CAAU,OAAV,EAAmB;IAAEC,OAAO,EAAE;EAAX,CAAnB,CAApB;AACD,CAnBM;AAqBP;AACA;AACA;AACA;AACA;;;;;AACO,SAASC,oBAAT,CAA8BlB,KAA9B,EAA6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C,CAACE,SAAF,CAAY,OAAZ,EAAqB,IAArB,EAA2B,KAA3B;IACApD,KAAK,CAACe,aAAN,CAAoBmC,CAApB;EACD;AACF"
|
|
67
67
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../../src/utils/markdownUtils.ts"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"selectWord",
|
|
8
5
|
"text",
|
|
@@ -24,8 +21,11 @@
|
|
|
24
21
|
"isWordDelimiter",
|
|
25
22
|
"c"
|
|
26
23
|
],
|
|
27
|
-
"
|
|
24
|
+
"sources": [
|
|
25
|
+
"../../src/utils/markdownUtils.ts"
|
|
26
|
+
],
|
|
28
27
|
"sourcesContent": [
|
|
29
28
|
"import { TextRange } from '../commands';\n\nexport interface TextSection {\n text: string;\n selection: TextRange;\n}\n\nexport function selectWord({ text, selection }: TextSection): TextRange {\n if (text && text.length && selection.start === selection.end) {\n // the user is pointing to a word\n return getSurroundingWord(text, selection.start);\n }\n return selection;\n}\n\n/**\n * Gets the number of line-breaks that would have to be inserted before the given 'startPosition'\n * to make sure there's an empty line between 'startPosition' and the previous text\n */\nexport function getBreaksNeededForEmptyLineBefore(text = '', startPosition: number): number {\n if (startPosition === 0) return 0;\n\n // rules:\n // - If we're in the first line, no breaks are needed\n // - Otherwise there must be 2 breaks before the previous character. Depending on how many breaks exist already, we\n // may need to insert 0, 1 or 2 breaks\n\n let neededBreaks = 2;\n let isInFirstLine = true;\n for (let i = startPosition - 1; i >= 0 && neededBreaks >= 0; i--) {\n switch (text.charCodeAt(i)) {\n case 32: // blank space\n continue;\n case 10: // line break\n neededBreaks--;\n isInFirstLine = false;\n break;\n default:\n return neededBreaks;\n }\n }\n return isInFirstLine ? 0 : neededBreaks;\n}\n\n/**\n * Gets the number of line-breaks that would have to be inserted after the given 'startPosition'\n * to make sure there's an empty line between 'startPosition' and the next text\n */\nexport function getBreaksNeededForEmptyLineAfter(text = '', startPosition: number): number {\n if (startPosition === text.length - 1) return 0;\n\n // rules:\n // - If we're in the first line, no breaks are needed\n // - Otherwise there must be 2 breaks before the previous character. Depending on how many breaks exist already, we\n // may need to insert 0, 1 or 2 breaks\n\n let neededBreaks = 2;\n let isInLastLine = true;\n for (let i = startPosition; i < text.length && neededBreaks >= 0; i++) {\n switch (text.charCodeAt(i)) {\n case 32:\n continue;\n case 10: {\n neededBreaks--;\n isInLastLine = false;\n break;\n }\n default:\n return neededBreaks;\n }\n }\n return isInLastLine ? 0 : neededBreaks;\n}\n\nexport function getSurroundingWord(text: string, position: number): TextRange {\n if (!text) throw Error(\"Argument 'text' should be truthy\");\n\n const isWordDelimiter = (c: string) => c === ' ' || c.charCodeAt(0) === 10;\n\n // leftIndex is initialized to 0 because if selection is 0, it won't even enter the iteration\n let start = 0;\n // rightIndex is initialized to text.length because if selection is equal to text.length it won't even enter the interation\n let end = text.length;\n\n // iterate to the left\n for (let i = position; i - 1 > -1; i--) {\n if (isWordDelimiter(text[i - 1])) {\n start = i;\n break;\n }\n }\n\n // iterate to the right\n for (let i = position; i < text.length; i++) {\n if (isWordDelimiter(text[i])) {\n end = i;\n break;\n }\n }\n\n return { start, end };\n}\n"
|
|
30
|
-
]
|
|
29
|
+
],
|
|
30
|
+
"mappings": ";;;;;;;;;;AAOO,SAASA,UAAT,OAAiE;EAAA,IAA3CC,IAA2C,QAA3CA,IAA2C;EAAA,IAArCC,SAAqC,QAArCA,SAAqC;;EACtE,IAAID,IAAI,IAAIA,IAAI,CAACE,MAAb,IAAuBD,SAAS,CAACE,KAAV,KAAoBF,SAAS,CAACG,GAAzD,EAA8D;IAC5D;IACA,OAAOC,kBAAkB,CAACL,IAAD,EAAOC,SAAS,CAACE,KAAjB,CAAzB;EACD;;EACD,OAAOF,SAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASK,iCAAT,GAAqF;EAAA,IAA1CN,IAA0C,uEAAnC,EAAmC;EAAA,IAA/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AAI,CAACd,IAAL,EAAW,MAAMe,KAAK,CAAC,kCAAD,CAAX;;EAEX,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAACC,CAAD;IAAA,OAAeA,CAAC,KAAK,GAAN,IAAaA,CAAC,CAACN,UAAF,CAAa,CAAb,MAAoB,EAAhD;EAAA,CAAxB,CAH4E,CAK5E;;;EACA,IAAIR,KAAK,GAAG,CAAZ,CAN4E,CAO5E;;EACA,IAAIC,GAAG,GAAGJ,IAAI,CAACE,MAAf,CAR4E,CAU5E;;EACA,KAAK,IAAIQ,CAAC,GAAGI,QAAb,EAAuBJ,CAAC,GAAG,CAAJ,GAAQ,CAAC,CAAhC,EAAmCA,CAAC,EAApC,EAAwC;IACtC,IAAIM,eAAe,CAAChB,IAAI,CAACU,CAAC,GAAG,CAAL,CAAL,CAAnB,EAAkC;MAChCP,KAAK,GAAGO,CAAR;MACA;IACD;EACF,CAhB2E,CAkB5E;;;EACA,KAAK,IAAIA,EAAC,GAAGI,QAAb,EAAuBJ,EAAC,GAAGV,IAAI,CAACE,MAAhC,EAAwCQ,EAAC,EAAzC,EAA6C;IAC3C,IAAIM,eAAe,CAAChB,IAAI,CAACU,EAAD,CAAL,CAAnB,EAA8B;MAC5BN,GAAG,GAAGM,EAAN;MACA;IACD;EACF;;EAED,OAAO;IAAEP,KAAK,EAALA,KAAF;IAASC,GAAG,EAAHA;EAAT,CAAP;AACD"
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.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>",
|
package/src/Editor.tsx
CHANGED
|
@@ -20,7 +20,11 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
20
20
|
/**
|
|
21
21
|
* Event handler for the `onChange` event.
|
|
22
22
|
*/
|
|
23
|
-
onChange?: (value?: string) => void;
|
|
23
|
+
onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;
|
|
24
|
+
/**
|
|
25
|
+
* editor height change listener
|
|
26
|
+
*/
|
|
27
|
+
onHeightChange?: (value?: number, oldValue?: number, state?: ContextStore) => void;
|
|
24
28
|
/**
|
|
25
29
|
* Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.
|
|
26
30
|
* it will be set to true when either the source `textarea` is focused,
|
|
@@ -139,6 +143,7 @@ const InternalMDEditor = (
|
|
|
139
143
|
tabSize = 2,
|
|
140
144
|
defaultTabEnable = false,
|
|
141
145
|
onChange,
|
|
146
|
+
onHeightChange,
|
|
142
147
|
hideToolbar,
|
|
143
148
|
renderTextarea,
|
|
144
149
|
...other
|
|
@@ -200,8 +205,6 @@ const InternalMDEditor = (
|
|
|
200
205
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
201
206
|
useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);
|
|
202
207
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
203
|
-
useMemo(() => height !== state.height && dispatch({ height: height }), [height]);
|
|
204
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
205
208
|
useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);
|
|
206
209
|
useMemo(
|
|
207
210
|
() => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),
|
|
@@ -215,6 +218,12 @@ const InternalMDEditor = (
|
|
|
215
218
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
216
219
|
[fullscreen],
|
|
217
220
|
);
|
|
221
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
222
|
+
useMemo(() => height !== state.height && dispatch({ height: height }), [height]);
|
|
223
|
+
useMemo(
|
|
224
|
+
() => height !== state.height && onHeightChange && onHeightChange(state.height, height, state),
|
|
225
|
+
[height, onHeightChange, state],
|
|
226
|
+
);
|
|
218
227
|
|
|
219
228
|
const textareaDomRef = useRef<HTMLDivElement>();
|
|
220
229
|
const active = useRef<'text' | 'preview'>('preview');
|
|
@@ -300,7 +309,7 @@ const InternalMDEditor = (
|
|
|
300
309
|
autoFocus={autoFocus}
|
|
301
310
|
{...textareaProps}
|
|
302
311
|
onChange={(evn) => {
|
|
303
|
-
onChange && onChange(evn.target.value);
|
|
312
|
+
onChange && onChange(evn.target.value, evn, state);
|
|
304
313
|
if (textareaProps && textareaProps.onChange) {
|
|
305
314
|
textareaProps.onChange(evn);
|
|
306
315
|
}
|
|
@@ -45,7 +45,7 @@ it('MDEditor onChange', async () => {
|
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it('MDEditor KeyboardEvent onChange', async () => {
|
|
48
|
-
const handleChange = jest.fn((value) => value);
|
|
48
|
+
const handleChange = jest.fn((value, evn, state) => value);
|
|
49
49
|
render(
|
|
50
50
|
<MDEditor
|
|
51
51
|
value=""
|
|
@@ -57,7 +57,32 @@ it('MDEditor KeyboardEvent onChange', async () => {
|
|
|
57
57
|
);
|
|
58
58
|
const input = screen.getByTitle('test');
|
|
59
59
|
userEvent.type(input, 'Hello,{enter}World!');
|
|
60
|
-
expect(handleChange).toHaveLength(
|
|
60
|
+
expect(handleChange).toHaveLength(3);
|
|
61
61
|
expect(handleChange).lastReturnedWith('!');
|
|
62
|
-
expect(handleChange).nthCalledWith(7, '\n');
|
|
62
|
+
// expect(handleChange).nthCalledWith(7, '\n');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('MDEditor KeyboardEvent onHeightChange', async () => {
|
|
66
|
+
const handleChange = jest.fn((value, propsValue, state) => {
|
|
67
|
+
return propsValue;
|
|
68
|
+
});
|
|
69
|
+
const MyComponent = () => {
|
|
70
|
+
const [height, setHeight] = React.useState(300);
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
setHeight(500);
|
|
73
|
+
}, []);
|
|
74
|
+
return (
|
|
75
|
+
<MDEditor
|
|
76
|
+
value=""
|
|
77
|
+
height={height}
|
|
78
|
+
textareaProps={{
|
|
79
|
+
title: 'test',
|
|
80
|
+
}}
|
|
81
|
+
onHeightChange={handleChange}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
render(<MyComponent />);
|
|
86
|
+
expect(handleChange).lastReturnedWith(500);
|
|
87
|
+
expect(handleChange).toHaveLength(3);
|
|
63
88
|
});
|
package/src/commands/code.tsx
CHANGED
|
@@ -10,7 +10,7 @@ export const code: ICommand = {
|
|
|
10
10
|
name: 'code',
|
|
11
11
|
keyCommand: 'code',
|
|
12
12
|
shortcuts: 'ctrlcmd+j',
|
|
13
|
-
buttonProps: { 'aria-label': 'Insert code' },
|
|
13
|
+
buttonProps: { 'aria-label': 'Insert code', title: 'Insert code' },
|
|
14
14
|
icon: (
|
|
15
15
|
<svg width="12" height="12" role="img" viewBox="0 0 640 512">
|
|
16
16
|
<path
|
|
@@ -68,7 +68,7 @@ export const codeBlock: ICommand = {
|
|
|
68
68
|
/>
|
|
69
69
|
</svg>
|
|
70
70
|
),
|
|
71
|
-
buttonProps: { 'aria-label': 'Insert Code Block' },
|
|
71
|
+
buttonProps: { 'aria-label': 'Insert Code Block', title: 'Insert Code Block' },
|
|
72
72
|
execute: (tate: TextState, api: TextAreaTextApi) => {
|
|
73
73
|
// Adjust the selection to encompass the whole word if the caret is inside one
|
|
74
74
|
const newSelectionRange = selectWord({ text: tate.text, selection: tate.selection });
|