@uiw/react-md-editor 3.12.1 → 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/dist/mdeditor.css +10 -15
- package/dist/mdeditor.js +1339 -162
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.js.map +5 -5
- package/esm/Editor.js.map +5 -5
- 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.js.map +5 -5
- 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/commands/code.tsx +2 -2
|
@@ -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,kBAA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
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,CAAC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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
|
}
|
|
@@ -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/BO,aAA+B;EAC1F,IAAIA,aAAa,KAAK,CAAtB,EAAyB,OAAO,CAAP,CADiE,CAG1F;EACA;EACA;EACA;;EAEA,IAAIC,YAAY,GAAG,CAAnB;EACA,IAAIC,aAAa,GAAG,IAApB;;EACA,KAAK,IAAIC,CAAC,GAAGH,aAAa,GAAG,CAA7B,EAAgCG,CAAC,IAAI,CAAL,IAAUF,YAAY,IAAI,CAA1D,EAA6DE,CAAC,EAA9D,EAAkE;IAChE,QAAQV,IAAI,CAACW,UAAL,CAAgBD,CAAhB,CAAR;MACE,KAAK,EAAL;QAAS;QACP;;MACF,KAAK,EAAL;QAAS;QACPF,YAAY;QACZC,aAAa,GAAG,KAAhB;QACA;;MACF;QACE,OAAOD,YAAP;IARJ;EAUD;;EACD,OAAOC,aAAa,GAAG,CAAH,GAAOD,YAA3B;AACD;AAED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CP,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.12.
|
|
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/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 });
|