@uiw/react-md-editor 3.19.6 → 3.19.7
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.js +4 -4
- package/dist/mdeditor.min.js +1 -1
- package/esm/commands/bold.js +2 -1
- package/esm/commands/bold.js.map +2 -2
- package/esm/commands/index.js +2 -1
- package/esm/commands/index.js.map +2 -2
- package/esm/components/TextArea/Markdown.js +0 -1
- package/esm/components/TextArea/Markdown.js.map +2 -4
- package/lib/commands/bold.js +2 -1
- package/lib/commands/bold.js.map +2 -2
- package/lib/commands/index.js +2 -1
- package/lib/commands/index.js.map +2 -2
- package/lib/components/TextArea/Markdown.js +0 -1
- package/lib/components/TextArea/Markdown.js.map +2 -4
- package/package.json +1 -1
- package/src/commands/bold.tsx +1 -1
- package/src/commands/index.ts +1 -1
- package/src/components/TextArea/Markdown.tsx +0 -2
package/esm/commands/bold.js
CHANGED
|
@@ -21,6 +21,7 @@ export var bold = {
|
|
|
21
21
|
})
|
|
22
22
|
}),
|
|
23
23
|
execute: (state, api) => {
|
|
24
|
+
var _state1$selectedText;
|
|
24
25
|
// Adjust the selection to encompass the whole word if the caret is inside one
|
|
25
26
|
var newSelectionRange = selectWord({
|
|
26
27
|
text: state.text,
|
|
@@ -31,7 +32,7 @@ export var bold = {
|
|
|
31
32
|
var state2 = api.replaceSelection("**" + state1.selectedText + "**");
|
|
32
33
|
// Adjust the selection to not contain the **
|
|
33
34
|
api.setSelectionRange({
|
|
34
|
-
start: state2.selection.end - 2 - state1.selectedText.length,
|
|
35
|
+
start: state2.selection.end - 2 - ((_state1$selectedText = state1.selectedText) == null ? void 0 : _state1$selectedText.length),
|
|
35
36
|
end: state2.selection.end - 2
|
|
36
37
|
});
|
|
37
38
|
}
|
package/esm/commands/bold.js.map
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"../../src/commands/bold.tsx"
|
|
31
31
|
],
|
|
32
32
|
"sourcesContent": [
|
|
33
|
-
"import React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { selectWord } from '../utils/markdownUtils';\n\nexport const bold: ICommand = {\n name: 'bold',\n keyCommand: 'bold',\n shortcuts: 'ctrlcmd+b',\n value: '**',\n buttonProps: { 'aria-label': 'Add bold text (ctrl + b)', title: 'Add bold text (ctrl + b)' },\n icon: (\n <svg role=\"img\" width=\"12\" height=\"12\" viewBox=\"0 0 384 512\">\n <path\n fill=\"currentColor\"\n d=\"M304.793 243.891c33.639-18.537 53.657-54.16 53.657-95.693 0-48.236-26.25-87.626-68.626-104.179C265.138 34.01 240.849 32 209.661 32H24c-8.837 0-16 7.163-16 16v33.049c0 8.837 7.163 16 16 16h33.113v318.53H24c-8.837 0-16 7.163-16 16V464c0 8.837 7.163 16 16 16h195.69c24.203 0 44.834-1.289 66.866-7.584C337.52 457.193 376 410.647 376 350.014c0-52.168-26.573-91.684-71.207-106.123zM142.217 100.809h67.444c16.294 0 27.536 2.019 37.525 6.717 15.828 8.479 24.906 26.502 24.906 49.446 0 35.029-20.32 56.79-53.029 56.79h-76.846V100.809zm112.642 305.475c-10.14 4.056-22.677 4.907-31.409 4.907h-81.233V281.943h84.367c39.645 0 63.057 25.38 63.057 63.057.001 28.425-13.66 52.483-34.782 61.284z\"\n />\n </svg>\n ),\n execute: (state: TextState, api: TextAreaTextApi) => {\n // Adjust the selection to encompass the whole word if the caret is inside one\n const newSelectionRange = selectWord({ text: state.text, selection: state.selection });\n const state1 = api.setSelectionRange(newSelectionRange);\n // Replaces the current selection with the bold mark up\n const state2 = api.replaceSelection(`**${state1.selectedText}**`);\n // Adjust the selection to not contain the **\n api.setSelectionRange({\n start: state2.selection.end - 2 - state1.selectedText
|
|
33
|
+
"import React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { selectWord } from '../utils/markdownUtils';\n\nexport const bold: ICommand = {\n name: 'bold',\n keyCommand: 'bold',\n shortcuts: 'ctrlcmd+b',\n value: '**',\n buttonProps: { 'aria-label': 'Add bold text (ctrl + b)', title: 'Add bold text (ctrl + b)' },\n icon: (\n <svg role=\"img\" width=\"12\" height=\"12\" viewBox=\"0 0 384 512\">\n <path\n fill=\"currentColor\"\n d=\"M304.793 243.891c33.639-18.537 53.657-54.16 53.657-95.693 0-48.236-26.25-87.626-68.626-104.179C265.138 34.01 240.849 32 209.661 32H24c-8.837 0-16 7.163-16 16v33.049c0 8.837 7.163 16 16 16h33.113v318.53H24c-8.837 0-16 7.163-16 16V464c0 8.837 7.163 16 16 16h195.69c24.203 0 44.834-1.289 66.866-7.584C337.52 457.193 376 410.647 376 350.014c0-52.168-26.573-91.684-71.207-106.123zM142.217 100.809h67.444c16.294 0 27.536 2.019 37.525 6.717 15.828 8.479 24.906 26.502 24.906 49.446 0 35.029-20.32 56.79-53.029 56.79h-76.846V100.809zm112.642 305.475c-10.14 4.056-22.677 4.907-31.409 4.907h-81.233V281.943h84.367c39.645 0 63.057 25.38 63.057 63.057.001 28.425-13.66 52.483-34.782 61.284z\"\n />\n </svg>\n ),\n execute: (state: TextState, api: TextAreaTextApi) => {\n // Adjust the selection to encompass the whole word if the caret is inside one\n const newSelectionRange = selectWord({ text: state.text, selection: state.selection });\n const state1 = api.setSelectionRange(newSelectionRange);\n // Replaces the current selection with the bold mark up\n const state2 = api.replaceSelection(`**${state1.selectedText}**`);\n // Adjust the selection to not contain the **\n api.setSelectionRange({\n start: state2.selection.end - 2 - state1.selectedText?.length,\n end: state2.selection.end - 2,\n });\n },\n};\n"
|
|
34
34
|
],
|
|
35
|
-
"mappings": "AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,UAAU,QAAQ,wBAAwB;AAAC;AAEpD,OAAO,IAAMC,IAAc,GAAG;EAC5BC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,MAAM;EAClBC,SAAS,EAAE,WAAW;EACtBC,KAAK,EAAE,IAAI;EACXC,WAAW,EAAE;IAAE,YAAY,EAAE,0BAA0B;IAAEC,KAAK,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AiB,GAAGZ,UAAU,CAAC;MAAEa,IAAI,EAAEH,KAAK,CAACG,IAAI;MAAEC,SAAS,EAAEJ,KAAK,CAACI;IAAU,CAAC,CAAC;IACtF,IAAMC,MAAM,GAAGJ,GAAG,CAACK,iBAAiB,CAACJ,iBAAiB,CAAC;IACvD;IACA,IAAMK,MAAM,GAAGN,GAAG,CAACO,gBAAgB,QAAMH,MAAM,CAACI,YAAY,QAAK;IACjE;IACAR,GAAG,CAACK,iBAAiB,CAAC;MACpBI,KAAK,EAAEH,MAAM,CAACH,SAAS,CAACO,GAAG,GAAG,CAAC,4BAAGN,MAAM,CAACI,YAAY,qBAAnB,qBAAqBG,MAAM;MAC7DD,GAAG,EAAEJ,MAAM,CAACH,SAAS,CAACO,GAAG,GAAG;IAC9B,CAAC,CAAC;EACJ;AACF,CAAC"
|
|
36
36
|
}
|
package/esm/commands/index.js
CHANGED
|
@@ -30,13 +30,14 @@ var getCommands = () => [bold, italic, strikethrough, hr, group([title1, title2,
|
|
|
30
30
|
}), divider, link, quote, code, codeBlock, comment, image, divider, unorderedListCommand, orderedListCommand, checkedListCommand];
|
|
31
31
|
var getExtraCommands = () => [codeEdit, codeLive, codePreview, divider, fullscreen];
|
|
32
32
|
function getStateFromTextArea(textArea) {
|
|
33
|
+
var _textArea$value;
|
|
33
34
|
return {
|
|
34
35
|
selection: {
|
|
35
36
|
start: textArea.selectionStart,
|
|
36
37
|
end: textArea.selectionEnd
|
|
37
38
|
},
|
|
38
39
|
text: textArea.value,
|
|
39
|
-
selectedText: textArea.value.slice(textArea.selectionStart, textArea.selectionEnd)
|
|
40
|
+
selectedText: (_textArea$value = textArea.value) == null ? void 0 : _textArea$value.slice(textArea.selectionStart, textArea.selectionEnd)
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
class TextAreaTextApi {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"../../src/commands/index.ts"
|
|
64
64
|
],
|
|
65
65
|
"sourcesContent": [
|
|
66
|
-
"import React from 'react';\nimport { ContextStore, ExecuteCommandState } from '../Context';\nimport { insertTextAtPosition } from '../utils/InsertTextAtPosition';\nimport { bold } from './bold';\nimport { code, codeBlock } from './code';\nimport { comment } from './comment';\nimport { divider } from './divider';\nimport { fullscreen } from './fullscreen';\nimport { group } from './group';\nimport { hr } from './hr';\nimport { image } from './image';\nimport { italic } from './italic';\nimport { link } from './link';\nimport { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';\nimport { codeEdit, codeLive, codePreview } from './preview';\nimport { quote } from './quote';\nimport { strikethrough } from './strikeThrough';\nimport { title } from './title';\nimport { title1 } from './title1';\nimport { title2 } from './title2';\nimport { title3 } from './title3';\nimport { title4 } from './title4';\nimport { title5 } from './title5';\nimport { title6 } from './title6';\n\nexport interface CommandOrchestrator {\n executeCommand(command: ICommand): void;\n}\n\nexport interface ICommandChildHandle<T = string> extends ICommandBase<T> {\n children?: (handle: {\n close: () => void;\n execute: () => void;\n getState?: TextAreaCommandOrchestrator['getState'];\n textApi?: TextAreaTextApi;\n }) => React.ReactElement;\n}\n\nexport interface ICommandChildCommands<T = string> extends ICommandBase<T> {\n children?: Array<ICommand<T>>;\n}\n\nexport interface ICommandBase<T> {\n parent?: ICommand<any>;\n keyCommand?: string;\n name?: string;\n shortcuts?: string;\n groupName?: string;\n icon?: React.ReactElement;\n value?: T;\n position?: 'right';\n liProps?: React.LiHTMLAttributes<HTMLLIElement>;\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | null;\n render?: (\n command: ICommand<T>,\n disabled: boolean,\n executeCommand: (command: ICommand<T>, name?: string) => void,\n index: number,\n ) => void | undefined | null | React.ReactElement;\n execute?: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => void;\n}\n\nexport type ICommand<T = string> = ICommandChildCommands<T> | ICommandChildHandle<T>;\n\nexport interface TextRange {\n start: number;\n end: number;\n}\n\nexport interface TextState {\n text: string;\n selectedText: string;\n selection: TextRange;\n}\n\nconst getCommands: () => ICommand[] = () => [\n bold,\n italic,\n strikethrough,\n hr,\n group([title1, title2, title3, title4, title5, title6], {\n name: 'title',\n groupName: 'title',\n buttonProps: { 'aria-label': 'Insert title', title: 'Insert title' },\n }),\n divider,\n link,\n quote,\n code,\n codeBlock,\n comment,\n image,\n divider,\n unorderedListCommand,\n orderedListCommand,\n checkedListCommand,\n];\n\nconst getExtraCommands: () => ICommand[] = () => [codeEdit, codeLive, codePreview, divider, fullscreen];\n\nfunction getStateFromTextArea(textArea: HTMLTextAreaElement): TextState {\n return {\n selection: {\n start: textArea.selectionStart,\n end: textArea.selectionEnd,\n },\n text: textArea.value,\n selectedText: textArea.value
|
|
66
|
+
"import React from 'react';\nimport { ContextStore, ExecuteCommandState } from '../Context';\nimport { insertTextAtPosition } from '../utils/InsertTextAtPosition';\nimport { bold } from './bold';\nimport { code, codeBlock } from './code';\nimport { comment } from './comment';\nimport { divider } from './divider';\nimport { fullscreen } from './fullscreen';\nimport { group } from './group';\nimport { hr } from './hr';\nimport { image } from './image';\nimport { italic } from './italic';\nimport { link } from './link';\nimport { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';\nimport { codeEdit, codeLive, codePreview } from './preview';\nimport { quote } from './quote';\nimport { strikethrough } from './strikeThrough';\nimport { title } from './title';\nimport { title1 } from './title1';\nimport { title2 } from './title2';\nimport { title3 } from './title3';\nimport { title4 } from './title4';\nimport { title5 } from './title5';\nimport { title6 } from './title6';\n\nexport interface CommandOrchestrator {\n executeCommand(command: ICommand): void;\n}\n\nexport interface ICommandChildHandle<T = string> extends ICommandBase<T> {\n children?: (handle: {\n close: () => void;\n execute: () => void;\n getState?: TextAreaCommandOrchestrator['getState'];\n textApi?: TextAreaTextApi;\n }) => React.ReactElement;\n}\n\nexport interface ICommandChildCommands<T = string> extends ICommandBase<T> {\n children?: Array<ICommand<T>>;\n}\n\nexport interface ICommandBase<T> {\n parent?: ICommand<any>;\n keyCommand?: string;\n name?: string;\n shortcuts?: string;\n groupName?: string;\n icon?: React.ReactElement;\n value?: T;\n position?: 'right';\n liProps?: React.LiHTMLAttributes<HTMLLIElement>;\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | null;\n render?: (\n command: ICommand<T>,\n disabled: boolean,\n executeCommand: (command: ICommand<T>, name?: string) => void,\n index: number,\n ) => void | undefined | null | React.ReactElement;\n execute?: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => void;\n}\n\nexport type ICommand<T = string> = ICommandChildCommands<T> | ICommandChildHandle<T>;\n\nexport interface TextRange {\n start: number;\n end: number;\n}\n\nexport interface TextState {\n text: string;\n selectedText: string;\n selection: TextRange;\n}\n\nconst getCommands: () => ICommand[] = () => [\n bold,\n italic,\n strikethrough,\n hr,\n group([title1, title2, title3, title4, title5, title6], {\n name: 'title',\n groupName: 'title',\n buttonProps: { 'aria-label': 'Insert title', title: 'Insert title' },\n }),\n divider,\n link,\n quote,\n code,\n codeBlock,\n comment,\n image,\n divider,\n unorderedListCommand,\n orderedListCommand,\n checkedListCommand,\n];\n\nconst getExtraCommands: () => ICommand[] = () => [codeEdit, codeLive, codePreview, divider, fullscreen];\n\nfunction getStateFromTextArea(textArea: HTMLTextAreaElement): TextState {\n return {\n selection: {\n start: textArea.selectionStart,\n end: textArea.selectionEnd,\n },\n text: textArea.value,\n selectedText: textArea.value?.slice(textArea.selectionStart, textArea.selectionEnd),\n };\n}\n\nclass TextAreaTextApi {\n textArea: HTMLTextAreaElement;\n\n constructor(textArea: HTMLTextAreaElement) {\n this.textArea = textArea;\n }\n\n /**\n * Replaces the current selection with the new text. This will make the new selectedText to be empty, the\n * selection start and selection end will be the same and will both point to the end\n * @param text Text that should replace the current selection\n */\n replaceSelection(text: string): TextState {\n insertTextAtPosition(this.textArea, text);\n return getStateFromTextArea(this.textArea);\n }\n\n /**\n * Selects the specified text range\n * @param selection\n */\n setSelectionRange(selection: TextRange): TextState {\n this.textArea.focus();\n this.textArea.selectionStart = selection.start;\n this.textArea.selectionEnd = selection.end;\n return getStateFromTextArea(this.textArea);\n }\n}\n\nclass TextAreaCommandOrchestrator implements CommandOrchestrator {\n textArea: HTMLTextAreaElement;\n textApi: TextAreaTextApi;\n\n constructor(textArea: HTMLTextAreaElement) {\n this.textArea = textArea;\n this.textApi = new TextAreaTextApi(textArea);\n }\n\n getState() {\n if (!this.textArea) return false;\n return getStateFromTextArea(this.textArea);\n }\n\n executeCommand(\n command: ICommand<string>,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n shortcuts?: string[],\n ): void {\n command.execute && command.execute(getStateFromTextArea(this.textArea), this.textApi, dispatch, state, shortcuts);\n }\n}\n\nexport {\n title,\n title1,\n title2,\n title3,\n title4,\n title5,\n title6,\n bold,\n codeBlock,\n italic,\n strikethrough,\n hr,\n group,\n divider,\n link,\n quote,\n code,\n image,\n unorderedListCommand,\n orderedListCommand,\n checkedListCommand,\n codeEdit,\n codeLive,\n codePreview,\n fullscreen,\n // Tool method.\n getCommands,\n getExtraCommands,\n getStateFromTextArea,\n TextAreaCommandOrchestrator,\n TextAreaTextApi,\n};\n"
|
|
67
67
|
],
|
|
68
|
-
"mappings": "AAEA,SAASA,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SAASC,IAAI,EAAEC,SAAS,QAAQ,QAAQ;AACxC,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,KAAK,QAAQ,SAAS;AAC/B,SAASC,EAAE,QAAQ,MAAM;AACzB,SAASC,KAAK,QAAQ,SAAS;AAC/B,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SAASC,kBAAkB,EAAEC,kBAAkB,EAAEC,oB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,CAACV,QAAQ,CAAC;EAC9C;EAEAiB,QAAQ,GAAG;IACT,IAAI,CAAC,IAAI,CAACjB,QAAQ,EAAE,OAAO,KAAK;IAChC,OAAOD,oBAAoB,CAAC,IAAI,CAACC,QAAQ,CAAC;EAC5C;EAEAkB,cAAc,CACZC,OAAyB,EACzBC,QAAuC,EACvCC,KAA2B,EAC3BC,SAAoB,EACd;IACNH,OAAO,CAACI,OAAO,IAAIJ,OAAO,CAACI,OAAO,CAACxB,oBAAoB,CAAC,IAAI,CAACC,QAAQ,CAAC,EAAE,IAAI,CAACgB,OAAO,EAAEI,QAAQ,EAAEC,KAAK,EAAEC,SAAS,CAAC;EACnH;AACF;AAEA,SACEnC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNzB,IAAI,EACJE,SAAS,EACTO,MAAM,EACNS,aAAa,EACbX,EAAE,EACFD,KAAK,EACLF,OAAO,EACPM,IAAI,EACJO,KAAK,EACLhB,IAAI,EACJO,KAAK,EACLK,oBAAoB,EACpBD,kBAAkB,EAClBD,kBAAkB,EAClBG,QAAQ,EACRC,QAAQ,EACRC,WAAW,EACXX,UAAU;AACV;AACAqB,WAAW,EACXI,gBAAgB,EAChBC,oBAAoB,EACpBgB,2BAA2B,EAC3BL,eAAe"
|
|
69
69
|
}
|
|
@@ -45,7 +45,6 @@ export default function Markdown(props) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
var mdStr = "<pre class=\"language-markdown " + prefixCls + "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">" + html2Escape(String.raw(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["", ""])), markdown)) + "\n</code></pre>";
|
|
48
|
-
console.log('markdown::', markdown);
|
|
49
48
|
if (highlightEnable) {
|
|
50
49
|
try {
|
|
51
50
|
mdStr = rehype().data('settings', {
|
|
@@ -25,8 +25,6 @@
|
|
|
25
25
|
"mdStr",
|
|
26
26
|
"String",
|
|
27
27
|
"raw",
|
|
28
|
-
"console",
|
|
29
|
-
"log",
|
|
30
28
|
"data",
|
|
31
29
|
"fragment",
|
|
32
30
|
"use",
|
|
@@ -43,7 +41,7 @@
|
|
|
43
41
|
"../../../src/components/TextArea/Markdown.tsx"
|
|
44
42
|
],
|
|
45
43
|
"sourcesContent": [
|
|
46
|
-
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(\\w+)?([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n}\n\nexport interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}\n\nexport default function Markdown(props: MarkdownProps) {\n const { prefixCls } = props;\n const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);\n const preRef = React.createRef<HTMLPreElement>();\n useEffect(() => {\n if (preRef.current && dispatch) {\n dispatch({ textareaPre: preRef.current });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n if (!markdown) {\n return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n let mdStr = `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n String.raw`${markdown}`,\n )}\\n</code></pre>`;\n\n
|
|
44
|
+
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(\\w+)?([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n}\n\nexport interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}\n\nexport default function Markdown(props: MarkdownProps) {\n const { prefixCls } = props;\n const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);\n const preRef = React.createRef<HTMLPreElement>();\n useEffect(() => {\n if (preRef.current && dispatch) {\n dispatch({ textareaPre: preRef.current });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n if (!markdown) {\n return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n let mdStr = `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n String.raw`${markdown}`,\n )}\\n</code></pre>`;\n\n if (highlightEnable) {\n try {\n mdStr = rehype()\n .data('settings', { fragment: true })\n .use(rehypePrism, { ignoreMissing: true })\n .processSync(mdStr)\n .toString();\n } catch (error) {}\n }\n\n return React.createElement('div', {\n className: 'wmde-markdown-color',\n dangerouslySetInnerHTML: { __html: mdStr || '' },\n });\n}\n"
|
|
47
45
|
],
|
|
48
|
-
"mappings": ";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,SAAS,QAAiB,OAAO;AAC7D,SAASC,MAAM,QAAQ,QAAQ;AAC/B,OAAOC,WAAW,MAAM,mBAAmB;AAE3C,SAASC,aAAa,QAAQ,eAAe;AAAC;AAE9C,SAASC,WAAW,CAACC,KAAa,EAAE;EAClC,OAAOA,KAAK,CACTC,OAAO,CAAC,gCAAgC,EAAGC,GAAW,IAAK;IAC1D,OAAOA,GAAG,CAACD,OAAO,CAChB,QAAQ,EACPE,CAAS,IAAM,C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AE;MAAK,CAAC,CAAC,CACpCC,GAAG,CAACtB,WAAW,EAAE;QAAEuB,aAAa,EAAE;MAAK,CAAC,CAAC,CACzCC,WAAW,CAACP,KAAK,CAAC,CAClBQ,QAAQ,EAAE;IACf,CAAC,CAAC,OAAOC,KAAK,EAAE,CAAC;EACnB;EAEA,oBAAO9B,KAAK,CAAC+B,aAAa,CAAC,KAAK,EAAE;IAChCC,SAAS,EAAE,qBAAqB;IAChCC,uBAAuB,EAAE;MAAEC,MAAM,EAAEb,KAAK,IAAI;IAAG;EACjD,CAAC,CAAC;AACJ"
|
|
49
47
|
}
|
package/lib/commands/bold.js
CHANGED
|
@@ -28,6 +28,7 @@ var bold = {
|
|
|
28
28
|
})
|
|
29
29
|
}),
|
|
30
30
|
execute: function execute(state, api) {
|
|
31
|
+
var _state1$selectedText;
|
|
31
32
|
// Adjust the selection to encompass the whole word if the caret is inside one
|
|
32
33
|
var newSelectionRange = (0, _markdownUtils.selectWord)({
|
|
33
34
|
text: state.text,
|
|
@@ -38,7 +39,7 @@ var bold = {
|
|
|
38
39
|
var state2 = api.replaceSelection("**".concat(state1.selectedText, "**"));
|
|
39
40
|
// Adjust the selection to not contain the **
|
|
40
41
|
api.setSelectionRange({
|
|
41
|
-
start: state2.selection.end - 2 - state1.selectedText.length,
|
|
42
|
+
start: state2.selection.end - 2 - ((_state1$selectedText = state1.selectedText) === null || _state1$selectedText === void 0 ? void 0 : _state1$selectedText.length),
|
|
42
43
|
end: state2.selection.end - 2
|
|
43
44
|
});
|
|
44
45
|
}
|
package/lib/commands/bold.js.map
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"../../src/commands/bold.tsx"
|
|
30
30
|
],
|
|
31
31
|
"sourcesContent": [
|
|
32
|
-
"import React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { selectWord } from '../utils/markdownUtils';\n\nexport const bold: ICommand = {\n name: 'bold',\n keyCommand: 'bold',\n shortcuts: 'ctrlcmd+b',\n value: '**',\n buttonProps: { 'aria-label': 'Add bold text (ctrl + b)', title: 'Add bold text (ctrl + b)' },\n icon: (\n <svg role=\"img\" width=\"12\" height=\"12\" viewBox=\"0 0 384 512\">\n <path\n fill=\"currentColor\"\n d=\"M304.793 243.891c33.639-18.537 53.657-54.16 53.657-95.693 0-48.236-26.25-87.626-68.626-104.179C265.138 34.01 240.849 32 209.661 32H24c-8.837 0-16 7.163-16 16v33.049c0 8.837 7.163 16 16 16h33.113v318.53H24c-8.837 0-16 7.163-16 16V464c0 8.837 7.163 16 16 16h195.69c24.203 0 44.834-1.289 66.866-7.584C337.52 457.193 376 410.647 376 350.014c0-52.168-26.573-91.684-71.207-106.123zM142.217 100.809h67.444c16.294 0 27.536 2.019 37.525 6.717 15.828 8.479 24.906 26.502 24.906 49.446 0 35.029-20.32 56.79-53.029 56.79h-76.846V100.809zm112.642 305.475c-10.14 4.056-22.677 4.907-31.409 4.907h-81.233V281.943h84.367c39.645 0 63.057 25.38 63.057 63.057.001 28.425-13.66 52.483-34.782 61.284z\"\n />\n </svg>\n ),\n execute: (state: TextState, api: TextAreaTextApi) => {\n // Adjust the selection to encompass the whole word if the caret is inside one\n const newSelectionRange = selectWord({ text: state.text, selection: state.selection });\n const state1 = api.setSelectionRange(newSelectionRange);\n // Replaces the current selection with the bold mark up\n const state2 = api.replaceSelection(`**${state1.selectedText}**`);\n // Adjust the selection to not contain the **\n api.setSelectionRange({\n start: state2.selection.end - 2 - state1.selectedText
|
|
32
|
+
"import React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { selectWord } from '../utils/markdownUtils';\n\nexport const bold: ICommand = {\n name: 'bold',\n keyCommand: 'bold',\n shortcuts: 'ctrlcmd+b',\n value: '**',\n buttonProps: { 'aria-label': 'Add bold text (ctrl + b)', title: 'Add bold text (ctrl + b)' },\n icon: (\n <svg role=\"img\" width=\"12\" height=\"12\" viewBox=\"0 0 384 512\">\n <path\n fill=\"currentColor\"\n d=\"M304.793 243.891c33.639-18.537 53.657-54.16 53.657-95.693 0-48.236-26.25-87.626-68.626-104.179C265.138 34.01 240.849 32 209.661 32H24c-8.837 0-16 7.163-16 16v33.049c0 8.837 7.163 16 16 16h33.113v318.53H24c-8.837 0-16 7.163-16 16V464c0 8.837 7.163 16 16 16h195.69c24.203 0 44.834-1.289 66.866-7.584C337.52 457.193 376 410.647 376 350.014c0-52.168-26.573-91.684-71.207-106.123zM142.217 100.809h67.444c16.294 0 27.536 2.019 37.525 6.717 15.828 8.479 24.906 26.502 24.906 49.446 0 35.029-20.32 56.79-53.029 56.79h-76.846V100.809zm112.642 305.475c-10.14 4.056-22.677 4.907-31.409 4.907h-81.233V281.943h84.367c39.645 0 63.057 25.38 63.057 63.057.001 28.425-13.66 52.483-34.782 61.284z\"\n />\n </svg>\n ),\n execute: (state: TextState, api: TextAreaTextApi) => {\n // Adjust the selection to encompass the whole word if the caret is inside one\n const newSelectionRange = selectWord({ text: state.text, selection: state.selection });\n const state1 = api.setSelectionRange(newSelectionRange);\n // Replaces the current selection with the bold mark up\n const state2 = api.replaceSelection(`**${state1.selectedText}**`);\n // Adjust the selection to not contain the **\n api.setSelectionRange({\n start: state2.selection.end - 2 - state1.selectedText?.length,\n end: state2.selection.end - 2,\n });\n },\n};\n"
|
|
33
33
|
],
|
|
34
|
-
"mappings": ";;;;;;;AAAA;AAEA;AAAoD;AAE7C,IAAMA,IAAc,GAAG;EAC5BC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,MAAM;EAClBC,SAAS,EAAE,WAAW;EACtBC,KAAK,EAAE,IAAI;EACXC,WAAW,EAAE;IAAE,YAAY,EAAE,0BAA0B;IAAEC,KAAK,EAAE;EAA2B,CAAC;EAC5FC,IAAI,eACF;IAAK,IAAI,EAAC,KAAK;IAAC,KAAK,EAAC,IAAI;IAAC,MAAM,EAAC,IAAI;IAAC,OAAO,EAAC,aAAa;IAAA,uBAC1D;MACE,IAAI,EAAC,cAAc;MACnB,CAAC,EAAC;IAAwqB;EAC1q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,MAAM,CAACI,YAAY,QAAK;IACjE;IACAT,GAAG,CAACM,iBAAiB,CAAC;MACpBI,KAAK,EAAEH,MAAM,CAACH,SAAS,CAACO,GAAG,GAAG,CAAC,4BAAGN,MAAM,CAACI,YAAY,yDAAnB,qBAAqBG,MAAM;MAC7DD,GAAG,EAAEJ,MAAM,CAACH,SAAS,CAACO,GAAG,GAAG;IAC9B,CAAC,CAAC;EACJ;AACF,CAAC;AAAC"
|
|
35
35
|
}
|
package/lib/commands/index.js
CHANGED
|
@@ -198,13 +198,14 @@ var getExtraCommands = function getExtraCommands() {
|
|
|
198
198
|
};
|
|
199
199
|
exports.getExtraCommands = getExtraCommands;
|
|
200
200
|
function getStateFromTextArea(textArea) {
|
|
201
|
+
var _textArea$value;
|
|
201
202
|
return {
|
|
202
203
|
selection: {
|
|
203
204
|
start: textArea.selectionStart,
|
|
204
205
|
end: textArea.selectionEnd
|
|
205
206
|
},
|
|
206
207
|
text: textArea.value,
|
|
207
|
-
selectedText: textArea.value.slice(textArea.selectionStart, textArea.selectionEnd)
|
|
208
|
+
selectedText: (_textArea$value = textArea.value) === null || _textArea$value === void 0 ? void 0 : _textArea$value.slice(textArea.selectionStart, textArea.selectionEnd)
|
|
208
209
|
};
|
|
209
210
|
}
|
|
210
211
|
var TextAreaTextApi = /*#__PURE__*/function () {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"../../src/commands/index.ts"
|
|
59
59
|
],
|
|
60
60
|
"sourcesContent": [
|
|
61
|
-
"import React from 'react';\nimport { ContextStore, ExecuteCommandState } from '../Context';\nimport { insertTextAtPosition } from '../utils/InsertTextAtPosition';\nimport { bold } from './bold';\nimport { code, codeBlock } from './code';\nimport { comment } from './comment';\nimport { divider } from './divider';\nimport { fullscreen } from './fullscreen';\nimport { group } from './group';\nimport { hr } from './hr';\nimport { image } from './image';\nimport { italic } from './italic';\nimport { link } from './link';\nimport { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';\nimport { codeEdit, codeLive, codePreview } from './preview';\nimport { quote } from './quote';\nimport { strikethrough } from './strikeThrough';\nimport { title } from './title';\nimport { title1 } from './title1';\nimport { title2 } from './title2';\nimport { title3 } from './title3';\nimport { title4 } from './title4';\nimport { title5 } from './title5';\nimport { title6 } from './title6';\n\nexport interface CommandOrchestrator {\n executeCommand(command: ICommand): void;\n}\n\nexport interface ICommandChildHandle<T = string> extends ICommandBase<T> {\n children?: (handle: {\n close: () => void;\n execute: () => void;\n getState?: TextAreaCommandOrchestrator['getState'];\n textApi?: TextAreaTextApi;\n }) => React.ReactElement;\n}\n\nexport interface ICommandChildCommands<T = string> extends ICommandBase<T> {\n children?: Array<ICommand<T>>;\n}\n\nexport interface ICommandBase<T> {\n parent?: ICommand<any>;\n keyCommand?: string;\n name?: string;\n shortcuts?: string;\n groupName?: string;\n icon?: React.ReactElement;\n value?: T;\n position?: 'right';\n liProps?: React.LiHTMLAttributes<HTMLLIElement>;\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | null;\n render?: (\n command: ICommand<T>,\n disabled: boolean,\n executeCommand: (command: ICommand<T>, name?: string) => void,\n index: number,\n ) => void | undefined | null | React.ReactElement;\n execute?: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => void;\n}\n\nexport type ICommand<T = string> = ICommandChildCommands<T> | ICommandChildHandle<T>;\n\nexport interface TextRange {\n start: number;\n end: number;\n}\n\nexport interface TextState {\n text: string;\n selectedText: string;\n selection: TextRange;\n}\n\nconst getCommands: () => ICommand[] = () => [\n bold,\n italic,\n strikethrough,\n hr,\n group([title1, title2, title3, title4, title5, title6], {\n name: 'title',\n groupName: 'title',\n buttonProps: { 'aria-label': 'Insert title', title: 'Insert title' },\n }),\n divider,\n link,\n quote,\n code,\n codeBlock,\n comment,\n image,\n divider,\n unorderedListCommand,\n orderedListCommand,\n checkedListCommand,\n];\n\nconst getExtraCommands: () => ICommand[] = () => [codeEdit, codeLive, codePreview, divider, fullscreen];\n\nfunction getStateFromTextArea(textArea: HTMLTextAreaElement): TextState {\n return {\n selection: {\n start: textArea.selectionStart,\n end: textArea.selectionEnd,\n },\n text: textArea.value,\n selectedText: textArea.value
|
|
61
|
+
"import React from 'react';\nimport { ContextStore, ExecuteCommandState } from '../Context';\nimport { insertTextAtPosition } from '../utils/InsertTextAtPosition';\nimport { bold } from './bold';\nimport { code, codeBlock } from './code';\nimport { comment } from './comment';\nimport { divider } from './divider';\nimport { fullscreen } from './fullscreen';\nimport { group } from './group';\nimport { hr } from './hr';\nimport { image } from './image';\nimport { italic } from './italic';\nimport { link } from './link';\nimport { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';\nimport { codeEdit, codeLive, codePreview } from './preview';\nimport { quote } from './quote';\nimport { strikethrough } from './strikeThrough';\nimport { title } from './title';\nimport { title1 } from './title1';\nimport { title2 } from './title2';\nimport { title3 } from './title3';\nimport { title4 } from './title4';\nimport { title5 } from './title5';\nimport { title6 } from './title6';\n\nexport interface CommandOrchestrator {\n executeCommand(command: ICommand): void;\n}\n\nexport interface ICommandChildHandle<T = string> extends ICommandBase<T> {\n children?: (handle: {\n close: () => void;\n execute: () => void;\n getState?: TextAreaCommandOrchestrator['getState'];\n textApi?: TextAreaTextApi;\n }) => React.ReactElement;\n}\n\nexport interface ICommandChildCommands<T = string> extends ICommandBase<T> {\n children?: Array<ICommand<T>>;\n}\n\nexport interface ICommandBase<T> {\n parent?: ICommand<any>;\n keyCommand?: string;\n name?: string;\n shortcuts?: string;\n groupName?: string;\n icon?: React.ReactElement;\n value?: T;\n position?: 'right';\n liProps?: React.LiHTMLAttributes<HTMLLIElement>;\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | null;\n render?: (\n command: ICommand<T>,\n disabled: boolean,\n executeCommand: (command: ICommand<T>, name?: string) => void,\n index: number,\n ) => void | undefined | null | React.ReactElement;\n execute?: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => void;\n}\n\nexport type ICommand<T = string> = ICommandChildCommands<T> | ICommandChildHandle<T>;\n\nexport interface TextRange {\n start: number;\n end: number;\n}\n\nexport interface TextState {\n text: string;\n selectedText: string;\n selection: TextRange;\n}\n\nconst getCommands: () => ICommand[] = () => [\n bold,\n italic,\n strikethrough,\n hr,\n group([title1, title2, title3, title4, title5, title6], {\n name: 'title',\n groupName: 'title',\n buttonProps: { 'aria-label': 'Insert title', title: 'Insert title' },\n }),\n divider,\n link,\n quote,\n code,\n codeBlock,\n comment,\n image,\n divider,\n unorderedListCommand,\n orderedListCommand,\n checkedListCommand,\n];\n\nconst getExtraCommands: () => ICommand[] = () => [codeEdit, codeLive, codePreview, divider, fullscreen];\n\nfunction getStateFromTextArea(textArea: HTMLTextAreaElement): TextState {\n return {\n selection: {\n start: textArea.selectionStart,\n end: textArea.selectionEnd,\n },\n text: textArea.value,\n selectedText: textArea.value?.slice(textArea.selectionStart, textArea.selectionEnd),\n };\n}\n\nclass TextAreaTextApi {\n textArea: HTMLTextAreaElement;\n\n constructor(textArea: HTMLTextAreaElement) {\n this.textArea = textArea;\n }\n\n /**\n * Replaces the current selection with the new text. This will make the new selectedText to be empty, the\n * selection start and selection end will be the same and will both point to the end\n * @param text Text that should replace the current selection\n */\n replaceSelection(text: string): TextState {\n insertTextAtPosition(this.textArea, text);\n return getStateFromTextArea(this.textArea);\n }\n\n /**\n * Selects the specified text range\n * @param selection\n */\n setSelectionRange(selection: TextRange): TextState {\n this.textArea.focus();\n this.textArea.selectionStart = selection.start;\n this.textArea.selectionEnd = selection.end;\n return getStateFromTextArea(this.textArea);\n }\n}\n\nclass TextAreaCommandOrchestrator implements CommandOrchestrator {\n textArea: HTMLTextAreaElement;\n textApi: TextAreaTextApi;\n\n constructor(textArea: HTMLTextAreaElement) {\n this.textArea = textArea;\n this.textApi = new TextAreaTextApi(textArea);\n }\n\n getState() {\n if (!this.textArea) return false;\n return getStateFromTextArea(this.textArea);\n }\n\n executeCommand(\n command: ICommand<string>,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n shortcuts?: string[],\n ): void {\n command.execute && command.execute(getStateFromTextArea(this.textArea), this.textApi, dispatch, state, shortcuts);\n }\n}\n\nexport {\n title,\n title1,\n title2,\n title3,\n title4,\n title5,\n title6,\n bold,\n codeBlock,\n italic,\n strikethrough,\n hr,\n group,\n divider,\n link,\n quote,\n code,\n image,\n unorderedListCommand,\n orderedListCommand,\n checkedListCommand,\n codeEdit,\n codeLive,\n codePreview,\n fullscreen,\n // Tool method.\n getCommands,\n getExtraCommands,\n getStateFromTextArea,\n TextAreaCommandOrchestrator,\n TextAreaTextApi,\n};\n"
|
|
62
62
|
],
|
|
63
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA0DA,IAAMA,WAA6B,GAAG,SAAhCA,WAA6B;EAAA,OAAS,CAC1CC,UAAI,EACJC,cAAM,EACNC,4BAAa,EACbC,MAAE,EACF,IAAAC,YAAK,EAAC,CAACC,cAAM,EAAEC,cAAM,EAAEC,cAAM,EAAEC,cAAM,EAAEC,cAAM,EAAEC,cAAM,CAAC,EAAE;IACtDC,IAAI,EAAE,OAAO;IACbC,SAAS,EAAE,OAAO;IAClBC,WAAW,EAAE;MAAE,YAAY,EAAE,cAAc;MAAEC,KAAK,EAAE;IAAe;EACrE,CAAC,CAAC,EACFC,gBAAO,EACPC,UAAI,EACJC,YAAK,EACLC,UAAI,EACJC,eAAS,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AA;IAAA;IAAA;IACzC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACc,OAAO,GAAG,IAAIJ,eAAe,CAACV,QAAQ,CAAC;EAC9C;EAAC;IAAA;IAAA,OAED,oBAAW;MACT,IAAI,CAAC,IAAI,CAACA,QAAQ,EAAE,OAAO,KAAK;MAChC,OAAOD,oBAAoB,CAAC,IAAI,CAACC,QAAQ,CAAC;IAC5C;EAAC;IAAA;IAAA,OAED,wBACEe,OAAyB,EACzBC,QAAuC,EACvCC,KAA2B,EAC3BC,SAAoB,EACd;MACNH,OAAO,CAACI,OAAO,IAAIJ,OAAO,CAACI,OAAO,CAACpB,oBAAoB,CAAC,IAAI,CAACC,QAAQ,CAAC,EAAE,IAAI,CAACc,OAAO,EAAEE,QAAQ,EAAEC,KAAK,EAAEC,SAAS,CAAC;IACnH;EAAC;EAAA;AAAA;AAAA"
|
|
64
64
|
}
|
|
@@ -55,7 +55,6 @@ function Markdown(props) {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
var mdStr = "<pre class=\"language-markdown ".concat(prefixCls, "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">").concat(html2Escape(String.raw(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["", ""])), markdown)), "\n</code></pre>");
|
|
58
|
-
console.log('markdown::', markdown);
|
|
59
58
|
if (highlightEnable) {
|
|
60
59
|
try {
|
|
61
60
|
mdStr = (0, _rehype.rehype)().data('settings', {
|
|
@@ -23,8 +23,6 @@
|
|
|
23
23
|
"mdStr",
|
|
24
24
|
"String",
|
|
25
25
|
"raw",
|
|
26
|
-
"console",
|
|
27
|
-
"log",
|
|
28
26
|
"rehype",
|
|
29
27
|
"data",
|
|
30
28
|
"fragment",
|
|
@@ -43,7 +41,7 @@
|
|
|
43
41
|
"../../../src/components/TextArea/Markdown.tsx"
|
|
44
42
|
],
|
|
45
43
|
"sourcesContent": [
|
|
46
|
-
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(\\w+)?([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n}\n\nexport interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}\n\nexport default function Markdown(props: MarkdownProps) {\n const { prefixCls } = props;\n const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);\n const preRef = React.createRef<HTMLPreElement>();\n useEffect(() => {\n if (preRef.current && dispatch) {\n dispatch({ textareaPre: preRef.current });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n if (!markdown) {\n return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n let mdStr = `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n String.raw`${markdown}`,\n )}\\n</code></pre>`;\n\n
|
|
44
|
+
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(\\w+)?([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n}\n\nexport interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}\n\nexport default function Markdown(props: MarkdownProps) {\n const { prefixCls } = props;\n const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);\n const preRef = React.createRef<HTMLPreElement>();\n useEffect(() => {\n if (preRef.current && dispatch) {\n dispatch({ textareaPre: preRef.current });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n if (!markdown) {\n return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n let mdStr = `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n String.raw`${markdown}`,\n )}\\n</code></pre>`;\n\n if (highlightEnable) {\n try {\n mdStr = rehype()\n .data('settings', { fragment: true })\n .use(rehypePrism, { ignoreMissing: true })\n .processSync(mdStr)\n .toString();\n } catch (error) {}\n }\n\n return React.createElement('div', {\n className: 'wmde-markdown-color',\n dangerouslySetInnerHTML: { __html: mdStr || '' },\n });\n}\n"
|
|
47
45
|
],
|
|
48
|
-
"mappings": ";;;;;;;;;AAAA;AACA;AACA;AAEA;AAA8C;AAAA;AAE9C,SAASA,WAAW,CAACC,KAAa,EAAE;EAClC,OAAOA,KAAK,CACTC,OAAO,CAAC,gCAAgC,EAAE,UAACC,GAAW,EAAK;IAC1D,OAAOA,GAAG,CAACD,OAAO,CAChB,QAAQ,EACR,UAACE,CAAS;MAAA,OAAO;QAAE,GAAG,EAAE,MAAM;QAAE,GAAG,EAAE,MAAM;QAAE,GAAG,EAAE,OAAO;QAAE,GAAG,EAAE;MAAS,CAAC,CAA4BA,CAAC,CAAC;IAAA,CAAC,CAC1G;EACH,CAAC,CAAC,CACDF,OAAO,CACN,QAAQ,EACR,UAACE,CAAS;IAAA,OAAO;MAAE,GAAG,EAAE,MAAM;MAAE,GAAG,EAAE,MAAM;MAAE,GAAG,EAAE,OAAO;MAAE,GAAG,EAAE;IAAS,CAAC,CAA4BA,CAAC,CAAC;EAAA,CAAC,CAC1G;AAC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AK,IAAI;IAAG;EACjD,CAAC,CAAC;AACJ;AAAC"
|
|
49
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.7",
|
|
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/bold.tsx
CHANGED
|
@@ -24,7 +24,7 @@ export const bold: ICommand = {
|
|
|
24
24
|
const state2 = api.replaceSelection(`**${state1.selectedText}**`);
|
|
25
25
|
// Adjust the selection to not contain the **
|
|
26
26
|
api.setSelectionRange({
|
|
27
|
-
start: state2.selection.end - 2 - state1.selectedText
|
|
27
|
+
start: state2.selection.end - 2 - state1.selectedText?.length,
|
|
28
28
|
end: state2.selection.end - 2,
|
|
29
29
|
});
|
|
30
30
|
},
|
package/src/commands/index.ts
CHANGED
|
@@ -111,7 +111,7 @@ function getStateFromTextArea(textArea: HTMLTextAreaElement): TextState {
|
|
|
111
111
|
end: textArea.selectionEnd,
|
|
112
112
|
},
|
|
113
113
|
text: textArea.value,
|
|
114
|
-
selectedText: textArea.value
|
|
114
|
+
selectedText: textArea.value?.slice(textArea.selectionStart, textArea.selectionEnd),
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
|