@uiw/react-md-editor 3.8.1 → 3.8.5

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.
Files changed (68) hide show
  1. package/README.md +1 -1
  2. package/esm/Context.d.ts +0 -2
  3. package/esm/Context.js.map +2 -2
  4. package/esm/Editor.d.ts +1 -1
  5. package/esm/Editor.js +11 -4
  6. package/esm/Editor.js.map +4 -2
  7. package/esm/commands/title1.js +5 -6
  8. package/esm/commands/title1.js.map +9 -5
  9. package/esm/commands/title2.js +5 -6
  10. package/esm/commands/title2.js.map +9 -5
  11. package/esm/commands/title3.js +5 -6
  12. package/esm/commands/title3.js.map +9 -5
  13. package/esm/commands/title4.js +5 -6
  14. package/esm/commands/title4.js.map +9 -5
  15. package/esm/commands/title5.js +5 -6
  16. package/esm/commands/title5.js.map +9 -5
  17. package/esm/commands/title6.js +5 -6
  18. package/esm/commands/title6.js.map +9 -5
  19. package/esm/components/TextArea/Markdown.js +1 -1
  20. package/esm/components/TextArea/Markdown.js.map +2 -2
  21. package/esm/components/TextArea/Textarea.js +2 -4
  22. package/esm/components/TextArea/Textarea.js.map +2 -3
  23. package/esm/components/TextArea/index.d.ts +3 -2
  24. package/esm/components/TextArea/index.js +1 -2
  25. package/esm/components/TextArea/index.js.map +3 -3
  26. package/esm/utils/InsertTextAtPosition.d.ts +7 -0
  27. package/esm/utils/InsertTextAtPosition.js +27 -1
  28. package/esm/utils/InsertTextAtPosition.js.map +14 -6
  29. package/lib/Context.d.ts +0 -2
  30. package/lib/Context.js.map +2 -2
  31. package/lib/Editor.d.ts +1 -1
  32. package/lib/Editor.js +13 -4
  33. package/lib/Editor.js.map +4 -2
  34. package/lib/commands/title1.js +6 -6
  35. package/lib/commands/title1.js.map +8 -5
  36. package/lib/commands/title2.js +6 -6
  37. package/lib/commands/title2.js.map +8 -5
  38. package/lib/commands/title3.js +6 -6
  39. package/lib/commands/title3.js.map +8 -5
  40. package/lib/commands/title4.js +6 -6
  41. package/lib/commands/title4.js.map +8 -5
  42. package/lib/commands/title5.js +6 -6
  43. package/lib/commands/title5.js.map +8 -5
  44. package/lib/commands/title6.js +6 -6
  45. package/lib/commands/title6.js.map +8 -5
  46. package/lib/components/TextArea/Markdown.js +1 -1
  47. package/lib/components/TextArea/Markdown.js.map +2 -2
  48. package/lib/components/TextArea/Textarea.js +2 -4
  49. package/lib/components/TextArea/Textarea.js.map +2 -3
  50. package/lib/components/TextArea/index.d.ts +3 -2
  51. package/lib/components/TextArea/index.js +1 -2
  52. package/lib/components/TextArea/index.js.map +3 -3
  53. package/lib/utils/InsertTextAtPosition.d.ts +7 -0
  54. package/lib/utils/InsertTextAtPosition.js +30 -0
  55. package/lib/utils/InsertTextAtPosition.js.map +14 -6
  56. package/package.json +8 -7
  57. package/src/Context.tsx +0 -1
  58. package/src/Editor.tsx +14 -4
  59. package/src/commands/title1.tsx +5 -4
  60. package/src/commands/title2.tsx +5 -4
  61. package/src/commands/title3.tsx +5 -4
  62. package/src/commands/title4.tsx +5 -4
  63. package/src/commands/title5.tsx +5 -4
  64. package/src/commands/title6.tsx +5 -4
  65. package/src/components/TextArea/Markdown.tsx +1 -1
  66. package/src/components/TextArea/Textarea.tsx +3 -4
  67. package/src/components/TextArea/index.tsx +5 -5
  68. package/src/utils/InsertTextAtPosition.ts +29 -2
@@ -9,6 +9,8 @@ exports.title3 = void 0;
9
9
 
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
 
12
+ var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
13
+
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
 
14
16
  var title3 = {
@@ -27,13 +29,11 @@ var title3 = {
27
29
  children: "Title 3"
28
30
  }),
29
31
  execute: function execute(state, api) {
30
- var modifyText = "### ".concat(state.selectedText, "\n");
31
-
32
- if (!state.selectedText) {
33
- modifyText = "### ";
32
+ if (state.selection.start === 0 || /\n$/.test(state.text)) {
33
+ api.replaceSelection('### ');
34
+ } else {
35
+ (0, _InsertTextAtPosition.insertAtLineStart)('### ', state.selection.start, api.textArea);
34
36
  }
35
-
36
- api.replaceSelection(modifyText);
37
37
  }
38
38
  };
39
39
  exports.title3 = title3;
@@ -16,12 +16,15 @@
16
16
  "execute",
17
17
  "state",
18
18
  "api",
19
- "modifyText",
20
- "selectedText",
21
- "replaceSelection"
19
+ "selection",
20
+ "start",
21
+ "test",
22
+ "text",
23
+ "replaceSelection",
24
+ "textArea"
22
25
  ],
23
- "mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAIC,UAAU,iBAAUF,KAAK,CAACG,YAAhB,OAAd;;AACA,QAAI,CAACH,KAAK,CAACG,YAAX,EAAyB;AACvBD,MAAAA,UAAU,SAAV;AACD;;AACDD,IAAAA,GAAG,CAACG,gBAAJ,CAAqBF,UAArB;AACD;AAZ6B,CAAzB",
26
+ "mappings": ";;;;;;;;;AAAA;;AACA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAID,KAAK,CAACE,SAAN,CAAgBC,KAAhB,KAA0B,CAA1B,IAA+B,MAAMC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,MAArB;AACD,KAFD,MAEO;AACL,mDAAkB,MAAlB,EAA0BN,KAAK,CAACE,SAAN,CAAgBC,KAA1C,EAAiDF,GAAG,CAACM,QAArD;AACD;AACF;AAZ6B,CAAzB",
24
27
  "sourcesContent": [
25
- "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title3: ICommand = {\n name: 'title3',\n keyCommand: 'title3',\n shortcuts: 'ctrlcmd+3',\n buttonProps: { 'aria-label': 'Insert title3', title: 'Insert title 3' },\n icon: <div style={{ fontSize: 15, textAlign: 'left' }}>Title 3</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n let modifyText = `### ${state.selectedText}\\n`;\n if (!state.selectedText) {\n modifyText = `### `;\n }\n api.replaceSelection(modifyText);\n },\n};\n"
28
+ "import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title3: ICommand = {\n name: 'title3',\n keyCommand: 'title3',\n shortcuts: 'ctrlcmd+3',\n buttonProps: { 'aria-label': 'Insert title3', title: 'Insert title 3' },\n icon: <div style={{ fontSize: 15, textAlign: 'left' }}>Title 3</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('### ');\n } else {\n insertAtLineStart('### ', state.selection.start, api.textArea);\n }\n },\n};\n"
26
29
  ]
27
30
  }
@@ -9,6 +9,8 @@ exports.title4 = void 0;
9
9
 
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
 
12
+ var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
13
+
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
 
14
16
  var title4 = {
@@ -27,13 +29,11 @@ var title4 = {
27
29
  children: "Title 4"
28
30
  }),
29
31
  execute: function execute(state, api) {
30
- var modifyText = "#### ".concat(state.selectedText, "\n");
31
-
32
- if (!state.selectedText) {
33
- modifyText = "#### ";
32
+ if (state.selection.start === 0 || /\n$/.test(state.text)) {
33
+ api.replaceSelection('#### ');
34
+ } else {
35
+ (0, _InsertTextAtPosition.insertAtLineStart)('#### ', state.selection.start, api.textArea);
34
36
  }
35
-
36
- api.replaceSelection(modifyText);
37
37
  }
38
38
  };
39
39
  exports.title4 = title4;
@@ -16,12 +16,15 @@
16
16
  "execute",
17
17
  "state",
18
18
  "api",
19
- "modifyText",
20
- "selectedText",
21
- "replaceSelection"
19
+ "selection",
20
+ "start",
21
+ "test",
22
+ "text",
23
+ "replaceSelection",
24
+ "textArea"
22
25
  ],
23
- "mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAIC,UAAU,kBAAWF,KAAK,CAACG,YAAjB,OAAd;;AACA,QAAI,CAACH,KAAK,CAACG,YAAX,EAAyB;AACvBD,MAAAA,UAAU,UAAV;AACD;;AACDD,IAAAA,GAAG,CAACG,gBAAJ,CAAqBF,UAArB;AACD;AAZ6B,CAAzB",
26
+ "mappings": ";;;;;;;;;AAAA;;AACA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAID,KAAK,CAACE,SAAN,CAAgBC,KAAhB,KAA0B,CAA1B,IAA+B,MAAMC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,OAArB;AACD,KAFD,MAEO;AACL,mDAAkB,OAAlB,EAA2BN,KAAK,CAACE,SAAN,CAAgBC,KAA3C,EAAkDF,GAAG,CAACM,QAAtD;AACD;AACF;AAZ6B,CAAzB",
24
27
  "sourcesContent": [
25
- "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title4: ICommand = {\n name: 'title4',\n keyCommand: 'title4',\n shortcuts: 'ctrlcmd+4',\n buttonProps: { 'aria-label': 'Insert title4', title: 'Insert title 4' },\n icon: <div style={{ fontSize: 14, textAlign: 'left' }}>Title 4</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n let modifyText = `#### ${state.selectedText}\\n`;\n if (!state.selectedText) {\n modifyText = `#### `;\n }\n api.replaceSelection(modifyText);\n },\n};\n"
28
+ "import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title4: ICommand = {\n name: 'title4',\n keyCommand: 'title4',\n shortcuts: 'ctrlcmd+4',\n buttonProps: { 'aria-label': 'Insert title4', title: 'Insert title 4' },\n icon: <div style={{ fontSize: 14, textAlign: 'left' }}>Title 4</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('#### ');\n } else {\n insertAtLineStart('#### ', state.selection.start, api.textArea);\n }\n },\n};\n"
26
29
  ]
27
30
  }
@@ -9,6 +9,8 @@ exports.title5 = void 0;
9
9
 
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
 
12
+ var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
13
+
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
 
14
16
  var title5 = {
@@ -27,13 +29,11 @@ var title5 = {
27
29
  children: "Title 5"
28
30
  }),
29
31
  execute: function execute(state, api) {
30
- var modifyText = "##### ".concat(state.selectedText, "\n");
31
-
32
- if (!state.selectedText) {
33
- modifyText = "##### ";
32
+ if (state.selection.start === 0 || /\n$/.test(state.text)) {
33
+ api.replaceSelection('##### ');
34
+ } else {
35
+ (0, _InsertTextAtPosition.insertAtLineStart)('##### ', state.selection.start, api.textArea);
34
36
  }
35
-
36
- api.replaceSelection(modifyText);
37
37
  }
38
38
  };
39
39
  exports.title5 = title5;
@@ -16,12 +16,15 @@
16
16
  "execute",
17
17
  "state",
18
18
  "api",
19
- "modifyText",
20
- "selectedText",
21
- "replaceSelection"
19
+ "selection",
20
+ "start",
21
+ "test",
22
+ "text",
23
+ "replaceSelection",
24
+ "textArea"
22
25
  ],
23
- "mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,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QAAlB,EAA4BN,KAAK,CAACE,SAAN,CAAgBC,KAA5C,EAAmDF,GAAG,CAACM,QAAvD;AACD;AACF;AAZ6B,CAAzB",
24
27
  "sourcesContent": [
25
- "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title5: ICommand = {\n name: 'title5',\n keyCommand: 'title5',\n shortcuts: 'ctrlcmd+5',\n buttonProps: { 'aria-label': 'Insert title5', title: 'Insert title 5' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 5</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n let modifyText = `##### ${state.selectedText}\\n`;\n if (!state.selectedText) {\n modifyText = `##### `;\n }\n api.replaceSelection(modifyText);\n },\n};\n"
28
+ "import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title5: ICommand = {\n name: 'title5',\n keyCommand: 'title5',\n shortcuts: 'ctrlcmd+5',\n buttonProps: { 'aria-label': 'Insert title5', title: 'Insert title 5' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 5</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('##### ');\n } else {\n insertAtLineStart('##### ', state.selection.start, api.textArea);\n }\n },\n};\n"
26
29
  ]
27
30
  }
@@ -9,6 +9,8 @@ exports.title6 = void 0;
9
9
 
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
 
12
+ var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
13
+
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
 
14
16
  var title6 = {
@@ -27,13 +29,11 @@ var title6 = {
27
29
  children: "Title 6"
28
30
  }),
29
31
  execute: function execute(state, api) {
30
- var modifyText = "###### ".concat(state.selectedText, "\n");
31
-
32
- if (!state.selectedText) {
33
- modifyText = "###### ";
32
+ if (state.selection.start === 0 || /\n$/.test(state.text)) {
33
+ api.replaceSelection('###### ');
34
+ } else {
35
+ (0, _InsertTextAtPosition.insertAtLineStart)('###### ', state.selection.start, api.textArea);
34
36
  }
35
-
36
- api.replaceSelection(modifyText);
37
37
  }
38
38
  };
39
39
  exports.title6 = title6;
@@ -16,12 +16,15 @@
16
16
  "execute",
17
17
  "state",
18
18
  "api",
19
- "modifyText",
20
- "selectedText",
21
- "replaceSelection"
19
+ "selection",
20
+ "start",
21
+ "test",
22
+ "text",
23
+ "replaceSelection",
24
+ "textArea"
22
25
  ],
23
- "mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAIC,UAAU,oBAAaF,KAAK,CAACG,YAAnB,OAAd;;AACA,QAAI,CAACH,KAAK,CAACG,YAAX,EAAyB;AACvBD,MAAAA,UAAU,YAAV;AACD;;AACDD,IAAAA,GAAG,CAACG,gBAAJ,CAAqBF,UAArB;AACD;AAZ6B,CAAzB",
26
+ "mappings": ";;;;;;;;;AAAA;;AACA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAID,KAAK,CAACE,SAAN,CAAgBC,KAAhB,KAA0B,CAA1B,IAA+B,MAAMC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,SAArB;AACD,KAFD,MAEO;AACL,mDAAkB,SAAlB,EAA6BN,KAAK,CAACE,SAAN,CAAgBC,KAA7C,EAAoDF,GAAG,CAACM,QAAxD;AACD;AACF;AAZ6B,CAAzB",
24
27
  "sourcesContent": [
25
- "import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title6: ICommand = {\n name: 'title6',\n keyCommand: 'title6',\n shortcuts: 'ctrlcmd+6',\n buttonProps: { 'aria-label': 'Insert title6', title: 'Insert title 6' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 6</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n let modifyText = `###### ${state.selectedText}\\n`;\n if (!state.selectedText) {\n modifyText = `###### `;\n }\n api.replaceSelection(modifyText);\n },\n};\n"
28
+ "import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title6: ICommand = {\n name: 'title6',\n keyCommand: 'title6',\n shortcuts: 'ctrlcmd+6',\n buttonProps: { 'aria-label': 'Insert title6', title: 'Insert title 6' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 6</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('###### ');\n } else {\n insertAtLineStart('###### ', state.selection.start, api.textArea);\n }\n },\n};\n"
26
29
  ]
27
30
  }
@@ -73,7 +73,7 @@ function Markdown(props) {
73
73
  fragment: true
74
74
  }).use(_rehypePrism.default, {
75
75
  ignoreMissing: true
76
- }).processSync("<pre class=\"language-markdown ".concat(prefixCls, "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">").concat(html2Escape(markdown), "</code></pre>"));
76
+ }).processSync("<pre class=\"language-markdown ".concat(prefixCls, "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">").concat(html2Escape(markdown), "\n</code></pre>"));
77
77
  return /*#__PURE__*/_react.default.createElement('div', {
78
78
  className: 'wmde-markdown-color',
79
79
  dangerouslySetInnerHTML: {
@@ -33,8 +33,8 @@
33
33
  "__html",
34
34
  "value"
35
35
  ],
36
- "mappings": ";;;;;;;;;;;AAAA;;AACA;;AAEA;;AAEA;;;;AAHA;AAOe,SAASA,QAAT,CAAkBC,KAAlB,EAAwC;AACrD,MAAQC,SAAR,GAAsBD,KAAtB,CAAQC,SAAR;;AACA,oBAAqD,uBAAWC,sBAAX,CAArD;AAAA,yCAAQC,QAAR;AAAA,MAAQA,QAAR,qCAAmB,EAAnB;AAAA,MAAuBC,eAAvB,eAAuBA,eAAvB;AAAA,MAAwCC,QAAxC,eAAwCA,QAAxC;;AACA,MAAMC,MAAM,gBAAGC,eAAMC,SAAN,EAAf;;AACA,wBAAU,YAAM;AACd,QAAIF,MAAM,CAACG,OAAP,IAAkBJ,QAAtB,EAAgC;AAC9BA,MAAAA,QAAQ,CAAC;AAAEK,QAAAA,WAAW,EAAEJ,MAAM,CAACG;AAAtB,OAAD,CAAR;AACD,KAHa,CAId;;AACD,GALD,EAKG,EALH;;AAMA,WAASE,WAAT,CAAqBC,KAArB,EAAoC;AAClC,WAAOA,KAAK,CACTC,OADI,CACI,iCADJ,EACuC,UAACC,GAAD,EAAiB;AAC3D,aAAOA,GAAG,CAACD,OAAJ,CACL,SADK,EAEL,UAACE,CAAD;AAAA,eAAi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EQ;AAAEC,MAAAA,aAAa,EAAE;AAAjB,KAFR,EAGTC,WAHS,0CAIyBpB,SAJzB,+EAIoGU,WAAW,CACrHR,QADqH,CAJ/G,qBAAZ;AAQA,wBAAOI,eAAMe,aAAN,CAAoB,KAApB,EAA2B;AAChCC,MAAAA,SAAS,EAAE,qBADqB;AAEhCC,MAAAA,uBAAuB,EAAE;AAAEC,QAAAA,MAAM,EAAEX,GAAG,CAACY;AAAd;AAFO,KAA3B,CAAP;AAID,GAhBM,EAgBJ,CAACtB,eAAD,EAAkBD,QAAlB,EAA4BG,MAA5B,EAAoCL,SAApC,CAhBI,CAAP;AAiBD",
37
37
  "sourcesContent": [
38
- "import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\n// @ts-ignore\nimport rehypePrism from '@mapbox/rehype-prism';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\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 function html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(.*)\\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\n return useMemo(() => {\n if (!highlightEnable || !markdown) {\n return <pre children={markdown || ''} ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n const str = rehype()\n .data('settings', { fragment: true })\n .use(rehypePrism, { ignoreMissing: true })\n .processSync(\n `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n markdown,\n )}</code></pre>`,\n );\n return React.createElement('div', {\n className: 'wmde-markdown-color',\n dangerouslySetInnerHTML: { __html: str.value as string },\n });\n }, [highlightEnable, markdown, preRef, prefixCls]);\n}\n"
38
+ "import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\n// @ts-ignore\nimport rehypePrism from '@mapbox/rehype-prism';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\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 function html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(.*)\\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\n return useMemo(() => {\n if (!highlightEnable || !markdown) {\n return <pre children={markdown || ''} ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n const str = rehype()\n .data('settings', { fragment: true })\n .use(rehypePrism, { ignoreMissing: true })\n .processSync(\n `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n markdown,\n )}\\n</code></pre>`,\n );\n return React.createElement('div', {\n className: 'wmde-markdown-color',\n dangerouslySetInnerHTML: { __html: str.value as string },\n });\n }, [highlightEnable, markdown, preRef, prefixCls]);\n}\n"
39
39
  ]
40
40
  }
@@ -31,7 +31,7 @@ var _excluded = ["prefixCls", "onChange"];
31
31
 
32
32
  function Textarea(props) {
33
33
  var prefixCls = props.prefixCls,
34
- onChangeFromProps = props.onChange,
34
+ _onChange = props.onChange,
35
35
  other = (0, _objectWithoutProperties2.default)(props, _excluded);
36
36
 
37
37
  var _useContext = (0, _react.useContext)(_Context.EditorContext),
@@ -42,7 +42,6 @@ function Textarea(props) {
42
42
  highlightEnable = _useContext.highlightEnable,
43
43
  extraCommands = _useContext.extraCommands,
44
44
  tabSize = _useContext.tabSize,
45
- _onChange = _useContext.onChange,
46
45
  dispatch = _useContext.dispatch;
47
46
 
48
47
  var textRef = _react.default.useRef(null);
@@ -103,8 +102,7 @@ function Textarea(props) {
103
102
  dispatch && dispatch({
104
103
  markdown: e.target.value
105
104
  });
106
- _onChange && _onChange(e.target.value);
107
- onChangeFromProps && onChangeFromProps(e);
105
+ _onChange && _onChange(e);
108
106
  }
109
107
  }));
110
108
  }
@@ -7,7 +7,6 @@
7
7
  "Textarea",
8
8
  "props",
9
9
  "prefixCls",
10
- "onChangeFromProps",
11
10
  "onChange",
12
11
  "other",
13
12
  "EditorContext",
@@ -36,8 +35,8 @@
36
35
  "target",
37
36
  "value"
38
37
  ],
39
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;;;;;AAKe,SAASA,QAAT,CAAkBC,KAAlB,EAAwC;AACrD,MAAQC,SAAR,GAA6DD,KAA7D,CAAQC,SAAR;AAAA,MAA6BC,iBAA7B,GAA6DF,KAA7D,CAAmBG,QAAnB;AAAA,MAAmDC,KAAnD,0CAA6DJ,KAA7D;;AACA,oBACE,uBAAWK,sBAAX,CADF;AAAA,MAAQC,QAAR,eAAQA,QAAR;AAAA,MAAkBC,QAAlB,eAAkBA,QAAlB;AAAA,M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G,EAPH;;AASA,MAAMG,SAAS,GAAG,SAAZA,SAAY,CAACC,CAAD,EAAiE;AACjF,gCAAcA,CAAd,EAAiBZ,OAAjB;AACA,4BAAUY,CAAV,6CAAkBjB,QAAQ,IAAI,EAA9B,oCAAuCI,aAAa,IAAI,EAAxD,IAA8DM,UAAU,CAACE,OAAzE,EAAkFN,QAAlF,EAA4FK,SAAS,CAACC,OAAtG;AACD,GAHD;;AAIA,wBAAU,YAAM;AACd,QAAIL,OAAO,CAACK,OAAZ,EAAqB;AACnBL,MAAAA,OAAO,CAACK,OAAR,CAAgBM,gBAAhB,CAAiC,SAAjC,EAA4CF,SAA5C;AACD;;AACD,WAAO,YAAM;AACX,UAAIT,OAAO,CAACK,OAAZ,EAAqB;AACnB;AACAL,QAAAA,OAAO,CAACK,OAAR,CAAgBO,mBAAhB,CAAoC,SAApC,EAA+CH,SAA/C;AACD;AACF,KALD,CAJc,CAUd;AACD,GAXD,EAWG,EAXH;AAaA,sBACE;AACE,IAAA,YAAY,EAAC,KADf;AAEE,IAAA,WAAW,EAAC,KAFd;AAGE,IAAA,cAAc,EAAC,KAHjB;AAIE,IAAA,UAAU,EAAE;AAJd,KAKMnB,KALN;AAME,IAAA,GAAG,EAAEU,OANP;AAOE,IAAA,SAAS,YAAKZ,SAAL,yBAA6BE,KAAK,CAACuB,SAAN,GAAkBvB,KAAK,CAACuB,SAAxB,GAAoC,EAAjE,CAPX;AAQE,IAAA,KAAK,EAAErB,QART;AASE,IAAA,QAAQ,EAAE,kBAACkB,CAAD,EAAO;AACfX,MAAAA,QAAQ,IAAIA,QAAQ,CAAC;AAAEP,QAAAA,QAAQ,EAAEkB,CAAC,CAACI,MAAF,CAASC;AAArB,OAAD,CAApB;AACA1B,MAAAA,SAAQ,IAAIA,SAAQ,CAACqB,CAAD,CAApB;AACD;AAZH,KADF;AAgBD",
40
39
  "sourcesContent": [
41
- "import React, { useContext, useEffect } from 'react';\nimport { IProps } from '../../Editor';\nimport { EditorContext, ExecuteCommandState } from '../../Context';\nimport { TextAreaCommandOrchestrator } from '../../commands';\nimport handleKeyDown from './handleKeyDown';\nimport shortcuts from './shortcuts';\nimport './index.less';\n\nexport interface TextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value'>, IProps {}\n\nexport default function Textarea(props: TextAreaProps) {\n const { prefixCls, onChange: onChangeFromProps, ...other } = props;\n const { markdown, commands, fullscreen, preview, highlightEnable, extraCommands, tabSize, onChange, dispatch } =\n useContext(EditorContext);\n const textRef = React.useRef<HTMLTextAreaElement>(null);\n const executeRef = React.useRef<TextAreaCommandOrchestrator>();\n const statesRef = React.useRef<ExecuteCommandState>({ fullscreen, preview });\n\n useEffect(() => {\n statesRef.current = { fullscreen, preview, highlightEnable };\n }, [fullscreen, preview, highlightEnable]);\n\n useEffect(() => {\n if (textRef.current && dispatch) {\n const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);\n executeRef.current = commandOrchestrator;\n dispatch({ textarea: textRef.current, commandOrchestrator });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const onKeyDown = (e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>) => {\n handleKeyDown(e, tabSize);\n shortcuts(e, [...(commands || []), ...(extraCommands || [])], executeRef.current, dispatch, statesRef.current);\n };\n useEffect(() => {\n if (textRef.current) {\n textRef.current.addEventListener('keydown', onKeyDown);\n }\n return () => {\n if (textRef.current) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n textRef.current.removeEventListener('keydown', onKeyDown);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <textarea\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n {...other}\n ref={textRef}\n className={`${prefixCls}-text-input ${other.className ? other.className : ''}`}\n value={markdown}\n onChange={(e) => {\n dispatch && dispatch({ markdown: e.target.value });\n onChange && onChange(e.target.value);\n onChangeFromProps && onChangeFromProps(e);\n }}\n />\n );\n}\n"
40
+ "import React, { useContext, useEffect } from 'react';\nimport { IProps } from '../../Editor';\nimport { EditorContext, ExecuteCommandState } from '../../Context';\nimport { TextAreaCommandOrchestrator } from '../../commands';\nimport handleKeyDown from './handleKeyDown';\nimport shortcuts from './shortcuts';\nimport './index.less';\n\nexport interface TextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value'>, IProps {}\n\nexport default function Textarea(props: TextAreaProps) {\n const { prefixCls, onChange, ...other } = props;\n const { markdown, commands, fullscreen, preview, highlightEnable, extraCommands, tabSize, dispatch } =\n useContext(EditorContext);\n const textRef = React.useRef<HTMLTextAreaElement>(null);\n const executeRef = React.useRef<TextAreaCommandOrchestrator>();\n const statesRef = React.useRef<ExecuteCommandState>({ fullscreen, preview });\n\n useEffect(() => {\n statesRef.current = { fullscreen, preview, highlightEnable };\n }, [fullscreen, preview, highlightEnable]);\n\n useEffect(() => {\n if (textRef.current && dispatch) {\n const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);\n executeRef.current = commandOrchestrator;\n dispatch({ textarea: textRef.current, commandOrchestrator });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const onKeyDown = (e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>) => {\n handleKeyDown(e, tabSize);\n shortcuts(e, [...(commands || []), ...(extraCommands || [])], executeRef.current, dispatch, statesRef.current);\n };\n useEffect(() => {\n if (textRef.current) {\n textRef.current.addEventListener('keydown', onKeyDown);\n }\n return () => {\n if (textRef.current) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n textRef.current.removeEventListener('keydown', onKeyDown);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <textarea\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n {...other}\n ref={textRef}\n className={`${prefixCls}-text-input ${other.className ? other.className : ''}`}\n value={markdown}\n onChange={(e) => {\n dispatch && dispatch({ markdown: e.target.value });\n onChange && onChange(e);\n }}\n />\n );\n}\n"
42
41
  ]
43
42
  }
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import { ContextStore, ExecuteCommandState } from '../../Context';
3
- import { MDEditorProps, IProps } from '../../Editor';
3
+ import { TextAreaProps } from './Textarea';
4
+ import { IProps } from '../../Editor';
4
5
  import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
5
6
  import './index.less';
6
7
  declare type RenderTextareaHandle = {
7
8
  dispatch: ContextStore['dispatch'];
8
- onChange?: MDEditorProps['onChange'];
9
+ onChange?: TextAreaProps['onChange'];
9
10
  useContext?: {
10
11
  commands: ContextStore['commands'];
11
12
  extraCommands: ContextStore['extraCommands'];
@@ -42,7 +42,6 @@ function TextArea(props) {
42
42
  scrollTop = _useContext.scrollTop,
43
43
  commands = _useContext.commands,
44
44
  extraCommands = _useContext.extraCommands,
45
- onChange = _useContext.onChange,
46
45
  dispatch = _useContext.dispatch;
47
46
 
48
47
  var textRef = _react.default.useRef(null);
@@ -95,7 +94,7 @@ function TextArea(props) {
95
94
  }
96
95
  }), {
97
96
  dispatch: dispatch,
98
- onChange: onChange,
97
+ onChange: otherProps.onChange,
99
98
  shortcuts: _shortcuts.default,
100
99
  useContext: {
101
100
  commands: commands,
@@ -16,7 +16,6 @@
16
16
  "scrollTop",
17
17
  "commands",
18
18
  "extraCommands",
19
- "onChange",
20
19
  "dispatch",
21
20
  "textRef",
22
21
  "React",
@@ -40,12 +39,13 @@
40
39
  "style",
41
40
  "WebkitTextFillColor",
42
41
  "overflow",
42
+ "onChange",
43
43
  "shortcuts",
44
44
  "useContext",
45
45
  "ref"
46
46
  ],
47
- "mappings": ";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAoCe,SAASA,QAAT,CAAkBC,KAAlB,EAAyC;AACtD,aAA0EA,KAAK,IAAI,EAAnF;AAAA,MAAQC,SAAR,QAAQA,SAAR;AAA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AAR;AACD,KALa,CAMd;;AACD,GAPD,EAOG,EAPH;AASA,sBACE;AAAK,IAAA,GAAG,EAAEN,IAAV;AAAgB,IAAA,SAAS,YAAKf,SAAL,mBAAuBC,SAAS,IAAI,EAApC,CAAzB;AAAmE,IAAA,QAAQ,EAAEC,QAA7E;AAAA,2BACE;AAAK,MAAA,SAAS,YAAKF,SAAL,UAAd;AAAA,gBACGG,cAAc,gBACbS,eAAMY,YAAN,CACErB,cAAc,6DAEPC,UAFO;AAGVqB,QAAAA,KAAK,EAAEnB,QAHG;AAIVoB,QAAAA,YAAY,EAAE,KAJJ;AAKVC,QAAAA,WAAW,EAAE,KALH;AAMVC,QAAAA,UAAU,EAAE,OANF;AAOVC,QAAAA,cAAc,EAAE,KAPN;AAQV5B,QAAAA,SAAS,YAAKD,SAAL,gBARC;AASV8B,QAAAA,KAAK,EAAE;AACLC,UAAAA,mBAAmB,EAAE,SADhB;AAELC,UAAAA,QAAQ,EAAE;AAFL;AATG,UAcZ;AACEtB,QAAAA,QAAQ,EAARA,QADF;AAEEuB,QAAAA,QAAQ,EAAE7B,UAAU,CAAC6B,QAFvB;AAGEC,QAAAA,SAAS,EAATA,kBAHF;AAIEC,QAAAA,UAAU,EAAE;AAAE3B,UAAAA,QAAQ,EAARA,QAAF;AAAYC,UAAAA,aAAa,EAAbA,aAAZ;AAA2BY,UAAAA,mBAAmB,EAAEP,UAAU,CAACI;AAA3D;AAJd,OAdY,CADhB,EAsBE;AACEkB,QAAAA,GAAG,EAAEzB;AADP,OAtBF,CADa,gBA4Bb,sBAAC,eAAD;AAAA,gCACE,qBAAC,iBAAD;AAAU,UAAA,SAAS,EAAEX;AAArB,UADF,eAEE,qBAAC,iBAAD;AAAU,UAAA,SAAS,EAAEA;AAArB,WAAoCI,UAApC,EAFF;AAAA;AA7BJ;AADF,IADF;AAuCD",
48
48
  "sourcesContent": [
49
- "import React, { useEffect, Fragment, useContext } from 'react';\nimport { EditorContext, ContextStore, ExecuteCommandState } from '../../Context';\nimport shortcuts from './shortcuts';\nimport Markdown from './Markdown';\nimport Textarea from './Textarea';\nimport { MDEditorProps, IProps } from '../../Editor';\nimport { TextAreaCommandOrchestrator, ICommand } from '../../commands';\nimport './index.less';\n\ntype RenderTextareaHandle = {\n dispatch: ContextStore['dispatch'];\n onChange?: MDEditorProps['onChange'];\n useContext?: {\n commands: ContextStore['commands'];\n extraCommands: ContextStore['extraCommands'];\n commandOrchestrator?: TextAreaCommandOrchestrator;\n };\n shortcuts?: (\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n commands: ICommand[],\n commandOrchestrator?: TextAreaCommandOrchestrator,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n ) => void;\n};\n\nexport interface ITextAreaProps\n extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>,\n IProps {\n value?: string;\n onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;\n renderTextarea?: (\n props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>,\n opts: RenderTextareaHandle,\n ) => JSX.Element;\n}\n\nexport type TextAreaRef = {\n text?: HTMLTextAreaElement;\n warp?: HTMLDivElement;\n};\n\nexport default function TextArea(props: ITextAreaProps) {\n const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};\n const { markdown, scrollTop, commands, extraCommands, onChange, dispatch } = useContext(EditorContext);\n const textRef = React.useRef<HTMLTextAreaElement>(null);\n const executeRef = React.useRef<TextAreaCommandOrchestrator>();\n const warp = React.createRef<HTMLDivElement>();\n useEffect(() => {\n const state: ContextStore = {};\n if (warp.current) {\n state.textareaWarp = warp.current || undefined;\n warp.current.scrollTop = scrollTop || 0;\n }\n if (dispatch) {\n dispatch({ ...state });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (textRef.current && dispatch) {\n const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);\n executeRef.current = commandOrchestrator;\n dispatch({ textarea: textRef.current, commandOrchestrator });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div ref={warp} className={`${prefixCls}-aree ${className || ''}`} onScroll={onScroll}>\n <div className={`${prefixCls}-text`}>\n {renderTextarea ? (\n React.cloneElement(\n renderTextarea(\n {\n ...otherProps,\n value: markdown,\n autoComplete: 'off',\n autoCorrect: 'off',\n spellCheck: 'false',\n autoCapitalize: 'off',\n className: `${prefixCls}-text-input`,\n style: {\n WebkitTextFillColor: 'inherit',\n overflow: 'auto',\n },\n },\n {\n dispatch,\n onChange,\n shortcuts,\n useContext: { commands, extraCommands, commandOrchestrator: executeRef.current },\n },\n ),\n {\n ref: textRef,\n },\n )\n ) : (\n <Fragment>\n <Markdown prefixCls={prefixCls} />\n <Textarea prefixCls={prefixCls} {...otherProps} />\n </Fragment>\n )}\n </div>\n </div>\n );\n}\n"
49
+ "import React, { useEffect, Fragment, useContext } from 'react';\nimport { EditorContext, ContextStore, ExecuteCommandState } from '../../Context';\nimport shortcuts from './shortcuts';\nimport Markdown from './Markdown';\nimport Textarea, { TextAreaProps } from './Textarea';\nimport { IProps } from '../../Editor';\nimport { TextAreaCommandOrchestrator, ICommand } from '../../commands';\nimport './index.less';\n\ntype RenderTextareaHandle = {\n dispatch: ContextStore['dispatch'];\n onChange?: TextAreaProps['onChange'];\n useContext?: {\n commands: ContextStore['commands'];\n extraCommands: ContextStore['extraCommands'];\n commandOrchestrator?: TextAreaCommandOrchestrator;\n };\n shortcuts?: (\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n commands: ICommand[],\n commandOrchestrator?: TextAreaCommandOrchestrator,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n ) => void;\n};\n\nexport interface ITextAreaProps\n extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>,\n IProps {\n value?: string;\n onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;\n renderTextarea?: (\n props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>,\n opts: RenderTextareaHandle,\n ) => JSX.Element;\n}\n\nexport type TextAreaRef = {\n text?: HTMLTextAreaElement;\n warp?: HTMLDivElement;\n};\n\nexport default function TextArea(props: ITextAreaProps) {\n const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};\n const { markdown, scrollTop, commands, extraCommands, dispatch } = useContext(EditorContext);\n const textRef = React.useRef<HTMLTextAreaElement>(null);\n const executeRef = React.useRef<TextAreaCommandOrchestrator>();\n const warp = React.createRef<HTMLDivElement>();\n useEffect(() => {\n const state: ContextStore = {};\n if (warp.current) {\n state.textareaWarp = warp.current || undefined;\n warp.current.scrollTop = scrollTop || 0;\n }\n if (dispatch) {\n dispatch({ ...state });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (textRef.current && dispatch) {\n const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);\n executeRef.current = commandOrchestrator;\n dispatch({ textarea: textRef.current, commandOrchestrator });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div ref={warp} className={`${prefixCls}-aree ${className || ''}`} onScroll={onScroll}>\n <div className={`${prefixCls}-text`}>\n {renderTextarea ? (\n React.cloneElement(\n renderTextarea(\n {\n ...otherProps,\n value: markdown,\n autoComplete: 'off',\n autoCorrect: 'off',\n spellCheck: 'false',\n autoCapitalize: 'off',\n className: `${prefixCls}-text-input`,\n style: {\n WebkitTextFillColor: 'inherit',\n overflow: 'auto',\n },\n },\n {\n dispatch,\n onChange: otherProps.onChange,\n shortcuts,\n useContext: { commands, extraCommands, commandOrchestrator: executeRef.current },\n },\n ),\n {\n ref: textRef,\n },\n )\n ) : (\n <Fragment>\n <Markdown prefixCls={prefixCls} />\n <Textarea prefixCls={prefixCls} {...otherProps} />\n </Fragment>\n )}\n </div>\n </div>\n );\n}\n"
50
50
  ]
51
51
  }
@@ -3,6 +3,13 @@
3
3
  * Copyright (c) 2018 Dmitriy Kubyshkin
4
4
  * Copied from https://github.com/grassator/insert-text-at-cursor
5
5
  */
6
+ /**
7
+ * @param {string} val
8
+ * @param {number} cursorIdx
9
+ * @param {HTMLTextAreaElement|HTMLInputElement} input
10
+ * @return {void}
11
+ */
12
+ export declare const insertAtLineStart: (val: string, cursorIdx: number, input: HTMLTextAreaElement | HTMLInputElement) => void;
6
13
  /**
7
14
  * @param {HTMLTextAreaElement|HTMLInputElement} input
8
15
  * @param {string} text
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.insertAtLineStart = void 0;
6
7
  exports.insertTextAtPosition = insertTextAtPosition;
7
8
 
8
9
  /**
@@ -29,6 +30,33 @@ function canManipulateViaTextNodes(input) {
29
30
 
30
31
  return browserSupportsTextareaTextNodes;
31
32
  }
33
+ /**
34
+ * @param {string} val
35
+ * @param {number} cursorIdx
36
+ * @param {HTMLTextAreaElement|HTMLInputElement} input
37
+ * @return {void}
38
+ */
39
+
40
+
41
+ var insertAtLineStart = function insertAtLineStart(val, cursorIdx, input) {
42
+ var content = input.value;
43
+ var startIdx = 0;
44
+
45
+ while (cursorIdx--) {
46
+ var char = content[cursorIdx];
47
+
48
+ if (char === '\n') {
49
+ startIdx = cursorIdx + 1;
50
+ break;
51
+ }
52
+ }
53
+
54
+ input.focus();
55
+ input.setRangeText(val, startIdx, startIdx);
56
+ input.dispatchEvent(new Event('input', {
57
+ bubbles: true
58
+ }));
59
+ };
32
60
  /**
33
61
  * @param {HTMLTextAreaElement|HTMLInputElement} input
34
62
  * @param {string} text
@@ -36,6 +64,8 @@ function canManipulateViaTextNodes(input) {
36
64
  */
37
65
 
38
66
 
67
+ exports.insertAtLineStart = insertAtLineStart;
68
+
39
69
  function insertTextAtPosition(input, text) {
40
70
  // Most of the used APIs only work with the field selected
41
71
  input.focus(); // IE 8-10
@@ -13,9 +13,19 @@
13
13
  "createElement",
14
14
  "value",
15
15
  "firstChild",
16
+ "insertAtLineStart",
17
+ "val",
18
+ "cursorIdx",
19
+ "content",
20
+ "startIdx",
21
+ "char",
22
+ "focus",
23
+ "setRangeText",
24
+ "dispatchEvent",
25
+ "Event",
26
+ "bubbles",
16
27
  "insertTextAtPosition",
17
28
  "text",
18
- "focus",
19
29
  "selection",
20
30
  "ieRange",
21
31
  "createRange",
@@ -27,7 +37,6 @@
27
37
  "selectionStart",
28
38
  "end",
29
39
  "selectionEnd",
30
- "setRangeText",
31
40
  "range",
32
41
  "textNode",
33
42
  "createTextNode",
@@ -49,11 +58,10 @@
49
58
  "setSelectionRange",
50
59
  "e",
51
60
  "createEvent",
52
- "initEvent",
53
- "dispatchEvent"
61
+ "initEvent"
54
62
  ],
55
- "mappings": ";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,IAAIA,gCAAJ;AAEA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAmCC,KAAnC,EAAkF;AAChF,MAAIA,KAAK,CAACC,QAAN,KAAmB,UAAvB,EAAmC;AACjC,WAAO,KAAP;AACD;;AACD,MAAI,OAAOH,gCAAP,KAA4C,WAAhD,EAA6D;AAC3D,QAAMI,QAA6B,GAAGC,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAtC;AACAF,IAAAA,QAAQ,CAACG,KAAT,GAAiB,GAAjB;AACAP,IAAAA,gCAAgC,GAAG,CAAC,CAACI,QAAQ,CAACI,UAA9C;AACD;;AACD,SAAOR,gCAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASS,oBAAT,CAA8BP,KAA9B,EAA6EQ,IAA7E,EAA2F;AAChG;AACAR,EAAAA,KAAK,CAACS,KAAN,GAFgG,CAIhG;;AACA,MAAKN,QAAD,CAAkBO,SAAtB,EAAiC;AAC/B,QAAMC,OAAO,GAAIR,QAAD,CAAkBO,SAAlB,CAA4BE,WAA5B,EAAhB;AACAD,IAAAA,OAAO,C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/C,QAAQ,CAACgD,WAAT,CAAqB,SAArB,CAAV;AACAD,IAAAA,CAAC,CAACE,SAAF,CAAY,OAAZ,EAAqB,IAArB,EAA2B,KAA3B;AACApD,IAAAA,KAAK,CAACe,aAAN,CAAoBmC,CAApB;AACD;AACF",
56
64
  "sourcesContent": [
57
- "/**\n * The MIT License\n * Copyright (c) 2018 Dmitriy Kubyshkin\n * Copied from https://github.com/grassator/insert-text-at-cursor\n */\n\nlet browserSupportsTextareaTextNodes: any;\n\n/**\n * @param {HTMLElement} input\n * @return {boolean}\n */\nfunction canManipulateViaTextNodes(input: HTMLTextAreaElement | HTMLInputElement) {\n if (input.nodeName !== 'TEXTAREA') {\n return false;\n }\n if (typeof browserSupportsTextareaTextNodes === 'undefined') {\n const textarea: HTMLTextAreaElement = document.createElement('textarea');\n textarea.value = '1';\n browserSupportsTextareaTextNodes = !!textarea.firstChild;\n }\n return browserSupportsTextareaTextNodes;\n}\n\n/**\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @param {string} text\n * @returns {void}\n */\nexport function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string) {\n // Most of the used APIs only work with the field selected\n input.focus();\n\n // IE 8-10\n if ((document as any).selection) {\n const ieRange = (document as any).selection.createRange();\n ieRange.text = text;\n\n // Move cursor after the inserted text\n ieRange.collapse(false /* to the end */);\n ieRange.select();\n\n return;\n }\n\n // Webkit + Edge\n const isSuccess = document.execCommand && document.execCommand('insertText', false, text);\n if (!isSuccess) {\n const start = input.selectionStart!;\n const end = input.selectionEnd!;\n // Firefox (non-standard method)\n if (typeof input.setRangeText === 'function') {\n input.setRangeText(text);\n } else {\n // To make a change we just need a Range, not a Selection\n const range = document.createRange();\n const textNode = document.createTextNode(text);\n\n if (canManipulateViaTextNodes(input)) {\n let node = input.firstChild;\n\n // If textarea is empty, just insert the text\n if (!node) {\n input.appendChild(textNode);\n } else {\n // Otherwise we need to find a nodes for start and end\n let offset = 0;\n let startNode = null;\n let endNode = null;\n\n while (node && (startNode === null || endNode === null)) {\n const nodeLength = node.nodeValue!.length;\n\n // if start of the selection falls into current node\n if (start >= offset && start <= offset + nodeLength) {\n range.setStart((startNode = node), start - offset);\n }\n\n // if end of the selection falls into current node\n if (end >= offset && end <= offset + nodeLength) {\n range.setEnd((endNode = node), end - offset);\n }\n\n offset += nodeLength;\n node = node.nextSibling;\n }\n\n // If there is some text selected, remove it as we should replace it\n if (start !== end) {\n range.deleteContents();\n }\n }\n }\n\n // If the node is a textarea and the range doesn't span outside the element\n //\n // Get the commonAncestorContainer of the selected range and test its type\n // If the node is of type `#text` it means that we're still working with text nodes within our textarea element\n // otherwise, if it's of type `#document` for example it means our selection spans outside the textarea.\n if (canManipulateViaTextNodes(input) && range.commonAncestorContainer.nodeName === '#text') {\n // Finally insert a new node. The browser will automatically split start and end nodes into two if necessary\n range.insertNode(textNode);\n } else {\n // If the node is not a textarea or the range spans outside a textarea the only way is to replace the whole value\n const value = input.value;\n input.value = value.slice(0, start) + text + value.slice(end);\n }\n }\n\n // Correct the cursor position to be at the end of the insertion\n input.setSelectionRange(start + text.length, start + text.length);\n\n // Notify any possible listeners of the change\n const e = document.createEvent('UIEvent');\n e.initEvent('input', true, false);\n input.dispatchEvent(e);\n }\n}\n"
65
+ "/**\n * The MIT License\n * Copyright (c) 2018 Dmitriy Kubyshkin\n * Copied from https://github.com/grassator/insert-text-at-cursor\n */\n\nlet browserSupportsTextareaTextNodes: any;\n\n/**\n * @param {HTMLElement} input\n * @return {boolean}\n */\nfunction canManipulateViaTextNodes(input: HTMLTextAreaElement | HTMLInputElement): boolean {\n if (input.nodeName !== 'TEXTAREA') {\n return false;\n }\n if (typeof browserSupportsTextareaTextNodes === 'undefined') {\n const textarea: HTMLTextAreaElement = document.createElement('textarea');\n textarea.value = '1';\n browserSupportsTextareaTextNodes = !!textarea.firstChild;\n }\n return browserSupportsTextareaTextNodes;\n}\n\n/**\n * @param {string} val\n * @param {number} cursorIdx\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @return {void}\n */\nexport const insertAtLineStart = (\n val: string,\n cursorIdx: number,\n input: HTMLTextAreaElement | HTMLInputElement,\n): void => {\n const content = input.value;\n let startIdx = 0;\n\n while (cursorIdx--) {\n let char = content[cursorIdx];\n if (char === '\\n') {\n startIdx = cursorIdx + 1;\n break;\n }\n }\n\n input.focus();\n input.setRangeText(val, startIdx, startIdx);\n input.dispatchEvent(new Event('input', { bubbles: true }));\n};\n\n/**\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @param {string} text\n * @returns {void}\n */\nexport function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string): void {\n // Most of the used APIs only work with the field selected\n input.focus();\n\n // IE 8-10\n if ((document as any).selection) {\n const ieRange = (document as any).selection.createRange();\n ieRange.text = text;\n\n // Move cursor after the inserted text\n ieRange.collapse(false /* to the end */);\n ieRange.select();\n\n return;\n }\n\n // Webkit + Edge\n const isSuccess = document.execCommand && document.execCommand('insertText', false, text);\n if (!isSuccess) {\n const start = input.selectionStart!;\n const end = input.selectionEnd!;\n // Firefox (non-standard method)\n if (typeof input.setRangeText === 'function') {\n input.setRangeText(text);\n } else {\n // To make a change we just need a Range, not a Selection\n const range = document.createRange();\n const textNode = document.createTextNode(text);\n\n if (canManipulateViaTextNodes(input)) {\n let node = input.firstChild;\n\n // If textarea is empty, just insert the text\n if (!node) {\n input.appendChild(textNode);\n } else {\n // Otherwise we need to find a nodes for start and end\n let offset = 0;\n let startNode = null;\n let endNode = null;\n\n while (node && (startNode === null || endNode === null)) {\n const nodeLength = node.nodeValue!.length;\n\n // if start of the selection falls into current node\n if (start >= offset && start <= offset + nodeLength) {\n range.setStart((startNode = node), start - offset);\n }\n\n // if end of the selection falls into current node\n if (end >= offset && end <= offset + nodeLength) {\n range.setEnd((endNode = node), end - offset);\n }\n\n offset += nodeLength;\n node = node.nextSibling;\n }\n\n // If there is some text selected, remove it as we should replace it\n if (start !== end) {\n range.deleteContents();\n }\n }\n }\n\n // If the node is a textarea and the range doesn't span outside the element\n //\n // Get the commonAncestorContainer of the selected range and test its type\n // If the node is of type `#text` it means that we're still working with text nodes within our textarea element\n // otherwise, if it's of type `#document` for example it means our selection spans outside the textarea.\n if (canManipulateViaTextNodes(input) && range.commonAncestorContainer.nodeName === '#text') {\n // Finally insert a new node. The browser will automatically split start and end nodes into two if necessary\n range.insertNode(textNode);\n } else {\n // If the node is not a textarea or the range spans outside a textarea the only way is to replace the whole value\n const value = input.value;\n input.value = value.slice(0, start) + text + value.slice(end);\n }\n }\n\n // Correct the cursor position to be at the end of the insertion\n input.setSelectionRange(start + text.length, start + text.length);\n\n // Notify any possible listeners of the change\n const e = document.createEvent('UIEvent');\n e.initEvent('input', true, false);\n input.dispatchEvent(e);\n }\n}\n"
58
66
  ]
59
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "3.8.1",
3
+ "version": "3.8.5",
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>",
@@ -44,7 +44,7 @@
44
44
  "@kkt/react-library": "6.11.0",
45
45
  "@kkt/scope-plugin-options": "6.11.0",
46
46
  "@types/katex": "0.11.1",
47
- "@types/react": "17.0.34",
47
+ "@types/react": "17.0.37",
48
48
  "@types/react-dom": "17.0.11",
49
49
  "@types/react-test-renderer": "17.0.1",
50
50
  "@uiw/react-github-corners": "1.5.3",
@@ -53,19 +53,20 @@
53
53
  "compile-less-cli": "1.8.9",
54
54
  "katex": "0.15.1",
55
55
  "husky": "7.0.4",
56
- "jest-environment-jsdom": "27.3.1",
56
+ "jest-environment-jsdom": "27.4.4",
57
57
  "kkt": "6.11.0",
58
- "lint-staged": "11.2.6",
59
- "prettier": "2.4.1",
58
+ "lint-staged": "12.1.2",
59
+ "prettier": "2.5.1",
60
60
  "react": "17.0.2",
61
61
  "react-dom": "17.0.2",
62
62
  "react-test-renderer": "17.0.2",
63
63
  "source-map-explorer": "2.5.2",
64
- "tsbb": "3.4.4"
64
+ "tsbb": "3.5.2"
65
65
  },
66
66
  "dependencies": {
67
67
  "@babel/runtime": "^7.14.6",
68
- "@uiw/react-markdown-preview": "3.4.1",
68
+ "@uiw/react-markdown-preview": "3.4.5",
69
+ "rehype-sanitize": "5.0.1",
69
70
  "rehype": "12.0.0"
70
71
  },
71
72
  "keywords": [
package/src/Context.tsx CHANGED
@@ -12,7 +12,6 @@ export type ContextStore = {
12
12
  fullscreen?: boolean;
13
13
  highlightEnable?: boolean;
14
14
  autoFocus?: boolean;
15
- onChange?: (value?: string) => void;
16
15
  textarea?: HTMLTextAreaElement;
17
16
  commandOrchestrator?: TextAreaCommandOrchestrator;
18
17
  textareaWarp?: HTMLDivElement;