@uiw/react-md-editor 3.19.5 → 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.
@@ -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
  }
@@ -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.length,\n end: state2.selection.end - 2,\n });\n },\n};\n"
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,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;EAC1qB,EAEL;EACDC,OAAO,EAAE,CAACC,KAAgB,EAAEC,GAAoB,KAAK;IACnD;IACA,IAAMC,iBAAiB,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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ACJ;AACF,CAAC"
36
36
  }
@@ -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.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"
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,oBA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AI,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
  }
@@ -23,6 +23,7 @@ export var codePreview = {
23
23
  })]
24
24
  }),
25
25
  execute: (state, api, dispatch, executeCommandState, shortcuts) => {
26
+ api.textArea.focus();
26
27
  if (shortcuts && dispatch && executeCommandState) {
27
28
  dispatch({
28
29
  preview: 'preview'
@@ -52,6 +53,7 @@ export var codeEdit = {
52
53
  })]
53
54
  }),
54
55
  execute: (state, api, dispatch, executeCommandState, shortcuts) => {
56
+ api.textArea.focus();
55
57
  if (shortcuts && dispatch && executeCommandState) {
56
58
  dispatch({
57
59
  preview: 'edit'
@@ -81,6 +83,7 @@ export var codeLive = {
81
83
  })]
82
84
  }),
83
85
  execute: (state, api, dispatch, executeCommandState, shortcuts) => {
86
+ api.textArea.focus();
84
87
  if (shortcuts && dispatch && executeCommandState) {
85
88
  dispatch({
86
89
  preview: 'live'
@@ -15,6 +15,8 @@
15
15
  "api",
16
16
  "dispatch",
17
17
  "executeCommandState",
18
+ "textArea",
19
+ "focus",
18
20
  "preview",
19
21
  "codeEdit",
20
22
  "codeLive"
@@ -23,7 +25,7 @@
23
25
  "../../src/commands/preview.tsx"
24
26
  ],
25
27
  "sourcesContent": [
26
- "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
28
+ "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
27
29
  ],
28
- "mappings": "AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAAC;AAAA;AAI/B,OAAO,IAAMC,WAAqB,GAAG;EACnCC,IAAI,EAAE,SAAS;EACfC,UAAU,EAAE,SAAS;EACrBC,KAAK,EAAE,SAAS;EAChBC,SAAS,EAAE,WAAW;EACtBC,WAAW,EAAE;IAAE,YAAY,EAAE,yBAAyB;IAAEC,KAAK,EAAE;EAA0B,CAAC;EAC1FC,IAAI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AM,EAAC;IAA+E,EACtF;EAAA,EAEL;EACDC,OAAO,EAAE,CACPC,KAAgB,EAChBC,GAAoB,EACpBC,QAAuC,EACvCC,mBAAyC,EACzCR,SAAoB,KACjB;IACHM,GAAG,CAACG,QAAQ,CAACC,KAAK,EAAE;IACpB,IAAIV,SAAS,IAAIO,QAAQ,IAAIC,mBAAmB,EAAE;MAChDD,QAAQ,CAAC;QAAEI,OAAO,EAAE;MAAO,CAAC,CAAC;IAC/B;EACF;AACF,CAAC"
29
31
  }
@@ -1,10 +1,12 @@
1
- import React, { useContext, useEffect, useMemo } from 'react';
1
+ import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/taggedTemplateLiteralLoose";
2
+ var _templateObject;
3
+ import React, { useContext, useEffect } from 'react';
2
4
  import { rehype } from 'rehype';
3
5
  import rehypePrism from 'rehype-prism-plus';
4
6
  import { EditorContext } from '../../Context';
5
7
  import { jsx as _jsx } from "react/jsx-runtime";
6
8
  function html2Escape(sHtml) {
7
- return sHtml.replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, str => {
9
+ return sHtml.replace(/```(\w+)?([\s\S]*?)(\s.+)?```/g, str => {
8
10
  return str.replace(/[<&"]/g, c => ({
9
11
  '<': '&lt;',
10
12
  '>': '&gt;',
@@ -36,29 +38,27 @@ export default function Markdown(props) {
36
38
  }
37
39
  // eslint-disable-next-line react-hooks/exhaustive-deps
38
40
  }, []);
39
- return useMemo(() => {
40
- if (!markdown) {
41
- return /*#__PURE__*/_jsx("pre", {
42
- ref: preRef,
43
- className: prefixCls + "-text-pre wmde-markdown-color"
44
- });
45
- }
46
- var mdStr = "<pre class=\"language-markdown " + prefixCls + "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">" + html2Escape(markdown) + "\n</code></pre>";
47
- if (highlightEnable) {
48
- try {
49
- mdStr = rehype().data('settings', {
50
- fragment: true
51
- }).use(rehypePrism, {
52
- ignoreMissing: true
53
- }).processSync(mdStr).toString();
54
- } catch (error) {}
55
- }
56
- return /*#__PURE__*/React.createElement('div', {
57
- className: 'wmde-markdown-color',
58
- dangerouslySetInnerHTML: {
59
- __html: mdStr || ''
60
- }
41
+ if (!markdown) {
42
+ return /*#__PURE__*/_jsx("pre", {
43
+ ref: preRef,
44
+ className: prefixCls + "-text-pre wmde-markdown-color"
61
45
  });
62
- }, [markdown, preRef, prefixCls]);
46
+ }
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
+ if (highlightEnable) {
49
+ try {
50
+ mdStr = rehype().data('settings', {
51
+ fragment: true
52
+ }).use(rehypePrism, {
53
+ ignoreMissing: true
54
+ }).processSync(mdStr).toString();
55
+ } catch (error) {}
56
+ }
57
+ return /*#__PURE__*/React.createElement('div', {
58
+ className: 'wmde-markdown-color',
59
+ dangerouslySetInnerHTML: {
60
+ __html: mdStr || ''
61
+ }
62
+ });
63
63
  }
64
64
  //# sourceMappingURL=Markdown.js.map
@@ -4,7 +4,6 @@
4
4
  "React",
5
5
  "useContext",
6
6
  "useEffect",
7
- "useMemo",
8
7
  "rehype",
9
8
  "rehypePrism",
10
9
  "EditorContext",
@@ -24,6 +23,8 @@
24
23
  "current",
25
24
  "textareaPre",
26
25
  "mdStr",
26
+ "String",
27
+ "raw",
27
28
  "data",
28
29
  "fragment",
29
30
  "use",
@@ -40,7 +41,7 @@
40
41
  "../../../src/components/TextArea/Markdown.tsx"
41
42
  ],
42
43
  "sourcesContent": [
43
- "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(/```(tsx?|jsx?|html|xml)(.*)\\s+([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } 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\n return useMemo(() => {\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 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 }, [markdown, preRef, prefixCls]);\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) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } 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"
44
45
  ],
45
- "mappings": "AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,SAAS,EAAEC,OAAO,QAAQ,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,qDAAqD,EAAGC,GAAW,IAAK;IAC/E,OAAOA,GAAG,CAACD,OAAO,CAChB,QAAQ,EACPE,CAAS,IAAM,CAAC;MAAE,GAAG,EAAE,MAAM;MAAE,GAAG,EAAE,MAAM;MAAE,GAAG,EAAE,OAAO;MAAE,GAAG,EAAE;IAAS,CAAC,EAA4BA,CAAC,CAAE,CAC1G;EACH,CAAC,CAAC,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AAQ,CAAC,CAAC;IAC3C;IACA;EACF,CAAC,EAAE,EAAE,CAAC;EACN,IAAI,CAACL,QAAQ,EAAE;IACb,oBAAO;MAAK,GAAG,EAAEG,MAAO;MAAC,SAAS,EAAKJ,SAAS;IAAgC,EAAG;EACrF;EACA,IAAIQ,KAAK,uCAAoCR,SAAS,0EAAkEP,WAAW,CACjIgB,MAAM,CAACC,GAAG,+EAAGT,QAAQ,EACtB,oBAAiB;EAElB,IAAIC,eAAe,EAAE;IACnB,IAAI;MACFM,KAAK,GAAGlB,MAAM,EAAE,CACbqB,IAAI,CAAC,UAAU,EAAE;QAAEC,QAAQ,EAAE;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"
46
47
  }
@@ -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
  }
@@ -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.length,\n end: state2.selection.end - 2,\n });\n },\n};\n"
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;I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wqB;EAC1qB,EAEL;EACDC,OAAO,EAAE,iBAACC,KAAgB,EAAEC,GAAoB,EAAK;IAAA;IACnD;IACA,IAAMC,iBAAiB,GAAG,IAAAC,yBAAU,EAAC;MAAEC,IAAI,EAAEJ,KAAK,CAACI,IAAI;MAAEC,SAAS,EAAEL,KAAK,CAACK;IAAU,CAAC,CAAC;IACtF,IAAMC,MAAM,GAAGL,GAAG,CAACM,iBAAiB,CAACL,iBAAiB,CAAC;IACvD;IACA,IAAMM,MAAM,GAAGP,GAAG,CAACQ,gBAAgB,aAAMH,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
  }
@@ -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.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"
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,UA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BAAoB,CAAC,IAAI,CAACC,QAAQ,CAAC;IAC5C;EAAC;EAAA;AAAA;AAAA;AAAA,IAGGa,2BAA2B;EAI/B,qCAAYb,QAA6B,EAAE;IAAA;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
  }
@@ -29,6 +29,7 @@ var codePreview = {
29
29
  })]
30
30
  }),
31
31
  execute: function execute(state, api, dispatch, executeCommandState, shortcuts) {
32
+ api.textArea.focus();
32
33
  if (shortcuts && dispatch && executeCommandState) {
33
34
  dispatch({
34
35
  preview: 'preview'
@@ -59,6 +60,7 @@ var codeEdit = {
59
60
  })]
60
61
  }),
61
62
  execute: function execute(state, api, dispatch, executeCommandState, shortcuts) {
63
+ api.textArea.focus();
62
64
  if (shortcuts && dispatch && executeCommandState) {
63
65
  dispatch({
64
66
  preview: 'edit'
@@ -89,6 +91,7 @@ var codeLive = {
89
91
  })]
90
92
  }),
91
93
  execute: function execute(state, api, dispatch, executeCommandState, shortcuts) {
94
+ api.textArea.focus();
92
95
  if (shortcuts && dispatch && executeCommandState) {
93
96
  dispatch({
94
97
  preview: 'live'
@@ -14,6 +14,8 @@
14
14
  "api",
15
15
  "dispatch",
16
16
  "executeCommandState",
17
+ "textArea",
18
+ "focus",
17
19
  "preview",
18
20
  "codeEdit",
19
21
  "codeLive"
@@ -22,7 +24,7 @@
22
24
  "../../src/commands/preview.tsx"
23
25
  ],
24
26
  "sourcesContent": [
25
- "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
27
+ "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
26
28
  ],
27
- "mappings": ";;;;;;;AAAA;AAA+B;AAIxB,IAAMA,WAAqB,GAAG;EACnCC,IAAI,EAAE,S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AC,MAAM,EAAC,IAAI;IAAC,OAAO,EAAC,aAAa;IAAA,wBAC/C;MAAS,IAAI,EAAC,cAAc;MAAC,MAAM,EAAC;IAAuE,EAAG,eAC9G;MACE,IAAI,EAAC,cAAc;MACnB,MAAM,EAAC;IAA+E,EACtF;EAAA,EAEL;EACDC,OAAO,EAAE,iBACPC,KAAgB,EAChBC,GAAoB,EACpBC,QAAuC,EACvCC,mBAAyC,EACzCR,SAAoB,EACjB;IACHM,GAAG,CAACG,QAAQ,CAACC,KAAK,EAAE;IACpB,IAAIV,SAAS,IAAIO,QAAQ,IAAIC,mBAAmB,EAAE;MAChDD,QAAQ,CAAC;QAAEI,OAAO,EAAE;MAAO,CAAC,CAAC;IAC/B;EACF;AACF,CAAC;AAAC"
28
30
  }
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports["default"] = Markdown;
9
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
10
  var _react = _interopRequireWildcard(require("react"));
10
11
  var _rehype = require("rehype");
11
12
  var _rehypePrismPlus = _interopRequireDefault(require("rehype-prism-plus"));
12
13
  var _Context = require("../../Context");
13
14
  var _jsxRuntime = require("react/jsx-runtime");
15
+ var _templateObject;
14
16
  function html2Escape(sHtml) {
15
- return sHtml.replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, function (str) {
17
+ return sHtml.replace(/```(\w+)?([\s\S]*?)(\s.+)?```/g, function (str) {
16
18
  return str.replace(/[<&"]/g, function (c) {
17
19
  return {
18
20
  '<': '&lt;',
@@ -46,30 +48,28 @@ function Markdown(props) {
46
48
  }
47
49
  // eslint-disable-next-line react-hooks/exhaustive-deps
48
50
  }, []);
49
- return (0, _react.useMemo)(function () {
50
- if (!markdown) {
51
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("pre", {
52
- ref: preRef,
53
- className: "".concat(prefixCls, "-text-pre wmde-markdown-color")
54
- });
55
- }
56
- var mdStr = "<pre class=\"language-markdown ".concat(prefixCls, "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">").concat(html2Escape(markdown), "\n</code></pre>");
57
- if (highlightEnable) {
58
- try {
59
- mdStr = (0, _rehype.rehype)().data('settings', {
60
- fragment: true
61
- }).use(_rehypePrismPlus["default"], {
62
- ignoreMissing: true
63
- }).processSync(mdStr).toString();
64
- } catch (error) {}
65
- }
66
- return /*#__PURE__*/_react["default"].createElement('div', {
67
- className: 'wmde-markdown-color',
68
- dangerouslySetInnerHTML: {
69
- __html: mdStr || ''
70
- }
51
+ if (!markdown) {
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("pre", {
53
+ ref: preRef,
54
+ className: "".concat(prefixCls, "-text-pre wmde-markdown-color")
71
55
  });
72
- }, [markdown, preRef, prefixCls]);
56
+ }
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
+ if (highlightEnable) {
59
+ try {
60
+ mdStr = (0, _rehype.rehype)().data('settings', {
61
+ fragment: true
62
+ }).use(_rehypePrismPlus["default"], {
63
+ ignoreMissing: true
64
+ }).processSync(mdStr).toString();
65
+ } catch (error) {}
66
+ }
67
+ return /*#__PURE__*/_react["default"].createElement('div', {
68
+ className: 'wmde-markdown-color',
69
+ dangerouslySetInnerHTML: {
70
+ __html: mdStr || ''
71
+ }
72
+ });
73
73
  }
74
74
  module.exports = exports.default;
75
75
  //# sourceMappingURL=Markdown.js.map
@@ -20,8 +20,9 @@
20
20
  "useEffect",
21
21
  "current",
22
22
  "textareaPre",
23
- "useMemo",
24
23
  "mdStr",
24
+ "String",
25
+ "raw",
25
26
  "rehype",
26
27
  "data",
27
28
  "fragment",
@@ -40,7 +41,7 @@
40
41
  "../../../src/components/TextArea/Markdown.tsx"
41
42
  ],
42
43
  "sourcesContent": [
43
- "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(/```(tsx?|jsx?|html|xml)(.*)\\s+([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } 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\n return useMemo(() => {\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 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 }, [markdown, preRef, prefixCls]);\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) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;' } 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"
44
45
  ],
45
- "mappings": ";;;;;;;;AAAA;AACA;AACA;AAEA;AAA8C;AAE9C,SAASA,WAAW,CAACC,KAAa,EAAE;EAClC,OAAOA,KAAK,CACTC,OAAO,CAAC,qDAAqD,EAAE,UAACC,GAAW,EAAK;IAC/E,OAAOA,GAAG,CAACD,OAAO,CAChB,QAAQ,EACR,UAACE,CAAS;MAAA,OAAO;QAAE,GAAG,EAAE,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M,gBAAGC,iBAAK,CAACC,SAAS,EAAkB;EAChD,IAAAC,gBAAS,EAAC,YAAM;IACd,IAAIH,MAAM,CAACI,OAAO,IAAIL,QAAQ,EAAE;MAC9BA,QAAQ,CAAC;QAAEM,WAAW,EAAEL,MAAM,CAACI;MAAQ,CAAC,CAAC;IAC3C;IACA;EACF,CAAC,EAAE,EAAE,CAAC;EACN,IAAI,CAACP,QAAQ,EAAE;IACb,oBAAO;MAAK,GAAG,EAAEG,MAAO;MAAC,SAAS,YAAKN,SAAS;IAAgC,EAAG;EACrF;EACA,IAAIY,KAAK,4CAAoCZ,SAAS,+EAAkEP,WAAW,CACjIoB,MAAM,CAACC,GAAG,2FAAGX,QAAQ,EACtB,oBAAiB;EAElB,IAAIC,eAAe,EAAE;IACnB,IAAI;MACFQ,KAAK,GAAG,IAAAG,cAAM,GAAE,CACbC,IAAI,CAAC,UAAU,EAAE;QAAEC,QAAQ,EAAE;MAAK,CAAC,CAAC,CACpCC,GAAG,CAACC,2BAAW,EAAE;QAAEC,aAAa,EAAE;MAAK,CAAC,CAAC,CACzCC,WAAW,CAACT,KAAK,CAAC,CAClBU,QAAQ,EAAE;IACf,CAAC,CAAC,OAAOC,KAAK,EAAE,CAAC;EACnB;EAEA,oBAAOhB,iBAAK,CAACiB,aAAa,CAAC,KAAK,EAAE;IAChCC,SAAS,EAAE,qBAAqB;IAChCC,uBAAuB,EAAE;MAAEC,MAAM,EAAEf,KAAK,IAAI;IAAG;EACjD,CAAC,CAAC;AACJ;AAAC"
46
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "3.19.5",
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>",
@@ -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.length,
27
+ start: state2.selection.end - 2 - state1.selectedText?.length,
28
28
  end: state2.selection.end - 2,
29
29
  });
30
30
  },
@@ -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.slice(textArea.selectionStart, textArea.selectionEnd),
114
+ selectedText: textArea.value?.slice(textArea.selectionStart, textArea.selectionEnd),
115
115
  };
116
116
  }
117
117
 
@@ -27,6 +27,7 @@ export const codePreview: ICommand = {
27
27
  executeCommandState?: ExecuteCommandState,
28
28
  shortcuts?: string[],
29
29
  ) => {
30
+ api.textArea.focus();
30
31
  if (shortcuts && dispatch && executeCommandState) {
31
32
  dispatch({ preview: 'preview' });
32
33
  }
@@ -55,6 +56,7 @@ export const codeEdit: ICommand = {
55
56
  executeCommandState?: ExecuteCommandState,
56
57
  shortcuts?: string[],
57
58
  ) => {
59
+ api.textArea.focus();
58
60
  if (shortcuts && dispatch && executeCommandState) {
59
61
  dispatch({ preview: 'edit' });
60
62
  }
@@ -83,6 +85,7 @@ export const codeLive: ICommand = {
83
85
  executeCommandState?: ExecuteCommandState,
84
86
  shortcuts?: string[],
85
87
  ) => {
88
+ api.textArea.focus();
86
89
  if (shortcuts && dispatch && executeCommandState) {
87
90
  dispatch({ preview: 'live' });
88
91
  }