@uiw/react-md-editor 3.20.5 → 3.20.6

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 (187) hide show
  1. package/README.md +5 -2
  2. package/dist/mdeditor.css +13 -0
  3. package/dist/mdeditor.js +8985 -914
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/esm/Context.d.ts +3 -3
  7. package/esm/Context.js +1 -2
  8. package/esm/Editor.d.ts +1 -1
  9. package/esm/Editor.js +9 -2
  10. package/esm/commands/bold.js +1 -2
  11. package/esm/commands/code.js +2 -3
  12. package/esm/commands/comment.js +2 -2
  13. package/esm/commands/divider.js +1 -2
  14. package/esm/commands/fullscreen.js +2 -3
  15. package/esm/commands/group.d.ts +1 -1
  16. package/esm/commands/group.js +1 -2
  17. package/esm/commands/hr.js +2 -3
  18. package/esm/commands/image.js +2 -3
  19. package/esm/commands/index.d.ts +2 -2
  20. package/esm/commands/index.js +1 -2
  21. package/esm/commands/italic.js +2 -3
  22. package/esm/commands/link.js +2 -3
  23. package/esm/commands/list.d.ts +1 -1
  24. package/esm/commands/list.js +2 -3
  25. package/esm/commands/preview.js +2 -3
  26. package/esm/commands/quote.js +2 -3
  27. package/esm/commands/strikeThrough.js +2 -3
  28. package/esm/commands/title.js +1 -2
  29. package/esm/commands/title1.js +1 -2
  30. package/esm/commands/title2.js +2 -3
  31. package/esm/commands/title3.js +2 -3
  32. package/esm/commands/title4.js +2 -3
  33. package/esm/commands/title5.js +2 -3
  34. package/esm/commands/title6.js +2 -3
  35. package/esm/components/DragBar/index.js +1 -2
  36. package/esm/components/TextArea/Markdown.js +1 -2
  37. package/esm/components/TextArea/Textarea.js +1 -2
  38. package/esm/components/TextArea/handleKeyDown.d.ts +1 -0
  39. package/esm/components/TextArea/handleKeyDown.js +1 -2
  40. package/esm/components/TextArea/index.d.ts +2 -2
  41. package/esm/components/TextArea/index.js +1 -2
  42. package/esm/components/TextArea/shortcuts.d.ts +1 -0
  43. package/esm/components/TextArea/shortcuts.js +1 -2
  44. package/esm/components/Toolbar/Child.d.ts +2 -1
  45. package/esm/components/Toolbar/Child.js +1 -2
  46. package/esm/components/Toolbar/index.d.ts +1 -0
  47. package/esm/components/Toolbar/index.js +1 -2
  48. package/esm/index.js +1 -2
  49. package/esm/react-app-env.d.ts +1 -0
  50. package/esm/utils/InsertTextAtPosition.js +1 -2
  51. package/esm/utils/markdownUtils.js +1 -2
  52. package/lib/Context.d.ts +3 -3
  53. package/lib/Context.js +1 -2
  54. package/lib/Editor.d.ts +1 -1
  55. package/lib/Editor.js +13 -2
  56. package/lib/commands/bold.js +1 -2
  57. package/lib/commands/code.js +3 -4
  58. package/lib/commands/comment.js +3 -2
  59. package/lib/commands/divider.js +1 -2
  60. package/lib/commands/fullscreen.js +3 -4
  61. package/lib/commands/group.d.ts +1 -1
  62. package/lib/commands/group.js +1 -2
  63. package/lib/commands/hr.js +3 -4
  64. package/lib/commands/image.js +3 -4
  65. package/lib/commands/index.d.ts +2 -2
  66. package/lib/commands/index.js +1 -2
  67. package/lib/commands/italic.js +3 -4
  68. package/lib/commands/link.js +3 -4
  69. package/lib/commands/list.d.ts +1 -1
  70. package/lib/commands/list.js +3 -4
  71. package/lib/commands/preview.js +3 -4
  72. package/lib/commands/quote.js +3 -4
  73. package/lib/commands/strikeThrough.js +3 -4
  74. package/lib/commands/title.js +1 -2
  75. package/lib/commands/title1.js +1 -2
  76. package/lib/commands/title2.js +3 -4
  77. package/lib/commands/title3.js +3 -4
  78. package/lib/commands/title4.js +3 -4
  79. package/lib/commands/title5.js +3 -4
  80. package/lib/commands/title6.js +3 -4
  81. package/lib/components/DragBar/index.js +1 -2
  82. package/lib/components/TextArea/Markdown.js +1 -2
  83. package/lib/components/TextArea/Textarea.js +1 -2
  84. package/lib/components/TextArea/handleKeyDown.d.ts +1 -0
  85. package/lib/components/TextArea/handleKeyDown.js +1 -2
  86. package/lib/components/TextArea/index.d.ts +2 -2
  87. package/lib/components/TextArea/index.js +1 -2
  88. package/lib/components/TextArea/shortcuts.d.ts +1 -0
  89. package/lib/components/TextArea/shortcuts.js +1 -2
  90. package/lib/components/Toolbar/Child.d.ts +2 -1
  91. package/lib/components/Toolbar/Child.js +1 -2
  92. package/lib/components/Toolbar/index.d.ts +1 -0
  93. package/lib/components/Toolbar/index.js +1 -2
  94. package/lib/index.js +1 -2
  95. package/lib/react-app-env.d.ts +1 -0
  96. package/lib/utils/InsertTextAtPosition.js +1 -2
  97. package/lib/utils/markdownUtils.js +1 -2
  98. package/package.json +1 -1
  99. package/src/Editor.tsx +4 -0
  100. package/src/__test__/commands.test.tsx +4 -4
  101. package/src/commands/code.tsx +1 -1
  102. package/src/commands/comment.tsx +1 -0
  103. package/src/commands/divider.tsx +1 -0
  104. package/src/commands/fullscreen.tsx +1 -1
  105. package/src/commands/hr.tsx +1 -1
  106. package/src/commands/image.tsx +1 -1
  107. package/src/commands/italic.tsx +1 -1
  108. package/src/commands/link.tsx +1 -1
  109. package/src/commands/list.tsx +1 -1
  110. package/src/commands/preview.tsx +1 -1
  111. package/src/commands/quote.tsx +1 -1
  112. package/src/commands/strikeThrough.tsx +1 -1
  113. package/src/commands/title2.tsx +1 -1
  114. package/src/commands/title3.tsx +1 -1
  115. package/src/commands/title4.tsx +1 -1
  116. package/src/commands/title5.tsx +1 -1
  117. package/src/commands/title6.tsx +1 -1
  118. package/esm/Context.js.map +0 -19
  119. package/esm/Editor.js.map +0 -116
  120. package/esm/commands/bold.js.map +0 -38
  121. package/esm/commands/code.js.map +0 -47
  122. package/esm/commands/comment.js.map +0 -35
  123. package/esm/commands/divider.js.map +0 -14
  124. package/esm/commands/fullscreen.js.map +0 -28
  125. package/esm/commands/group.js.map +0 -26
  126. package/esm/commands/hr.js.map +0 -27
  127. package/esm/commands/image.js.map +0 -40
  128. package/esm/commands/index.js.map +0 -69
  129. package/esm/commands/italic.js.map +0 -38
  130. package/esm/commands/link.js.map +0 -38
  131. package/esm/commands/list.js.map +0 -61
  132. package/esm/commands/preview.js.map +0 -31
  133. package/esm/commands/quote.js.map +0 -44
  134. package/esm/commands/strikeThrough.js.map +0 -38
  135. package/esm/commands/title.js.map +0 -16
  136. package/esm/commands/title1.js.map +0 -33
  137. package/esm/commands/title2.js.map +0 -33
  138. package/esm/commands/title3.js.map +0 -33
  139. package/esm/commands/title4.js.map +0 -33
  140. package/esm/commands/title5.js.map +0 -33
  141. package/esm/commands/title6.js.map +0 -33
  142. package/esm/components/DragBar/index.js.map +0 -41
  143. package/esm/components/TextArea/Markdown.js.map +0 -47
  144. package/esm/components/TextArea/Textarea.js.map +0 -47
  145. package/esm/components/TextArea/handleKeyDown.js.map +0 -66
  146. package/esm/components/TextArea/index.js.map +0 -57
  147. package/esm/components/TextArea/shortcuts.js.map +0 -52
  148. package/esm/components/Toolbar/Child.js.map +0 -28
  149. package/esm/components/Toolbar/index.js.map +0 -84
  150. package/esm/index.js.map +0 -15
  151. package/esm/utils/InsertTextAtPosition.js.map +0 -67
  152. package/esm/utils/markdownUtils.js.map +0 -31
  153. package/lib/Context.js.map +0 -19
  154. package/lib/Editor.js.map +0 -112
  155. package/lib/commands/bold.js.map +0 -37
  156. package/lib/commands/code.js.map +0 -46
  157. package/lib/commands/comment.js.map +0 -35
  158. package/lib/commands/divider.js.map +0 -14
  159. package/lib/commands/fullscreen.js.map +0 -27
  160. package/lib/commands/group.js.map +0 -25
  161. package/lib/commands/hr.js.map +0 -26
  162. package/lib/commands/image.js.map +0 -39
  163. package/lib/commands/index.js.map +0 -64
  164. package/lib/commands/italic.js.map +0 -37
  165. package/lib/commands/link.js.map +0 -37
  166. package/lib/commands/list.js.map +0 -60
  167. package/lib/commands/preview.js.map +0 -30
  168. package/lib/commands/quote.js.map +0 -43
  169. package/lib/commands/strikeThrough.js.map +0 -37
  170. package/lib/commands/title.js.map +0 -15
  171. package/lib/commands/title1.js.map +0 -32
  172. package/lib/commands/title2.js.map +0 -32
  173. package/lib/commands/title3.js.map +0 -32
  174. package/lib/commands/title4.js.map +0 -32
  175. package/lib/commands/title5.js.map +0 -32
  176. package/lib/commands/title6.js.map +0 -32
  177. package/lib/components/DragBar/index.js.map +0 -40
  178. package/lib/components/TextArea/Markdown.js.map +0 -47
  179. package/lib/components/TextArea/Textarea.js.map +0 -47
  180. package/lib/components/TextArea/handleKeyDown.js.map +0 -66
  181. package/lib/components/TextArea/index.js.map +0 -54
  182. package/lib/components/TextArea/shortcuts.js.map +0 -52
  183. package/lib/components/Toolbar/Child.js.map +0 -26
  184. package/lib/components/Toolbar/index.js.map +0 -82
  185. package/lib/index.js.map +0 -13
  186. package/lib/utils/InsertTextAtPosition.js.map +0 -67
  187. package/lib/utils/markdownUtils.js.map +0 -31
package/esm/Context.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { ICommand, TextAreaCommandOrchestrator } from './commands';
3
3
  import { MDEditorProps } from './Editor';
4
- export declare type PreviewType = 'live' | 'edit' | 'preview';
4
+ export type PreviewType = 'live' | 'edit' | 'preview';
5
5
  export interface ContextStore {
6
6
  components?: MDEditorProps['components'];
7
7
  commands?: ICommand<string>[];
@@ -24,7 +24,7 @@ export interface ContextStore {
24
24
  tabSize?: number;
25
25
  defaultTabEnable?: boolean;
26
26
  }
27
- export declare type ExecuteCommandState = Pick<ContextStore, 'fullscreen' | 'preview' | 'highlightEnable'>;
27
+ export type ExecuteCommandState = Pick<ContextStore, 'fullscreen' | 'preview' | 'highlightEnable'>;
28
28
  export declare function reducer(state: ContextStore, action: ContextStore): {
29
29
  components?: {
30
30
  textarea?: ((props: React.HTMLAttributes<HTMLDivElement> | React.TextareaHTMLAttributes<HTMLTextAreaElement>, opts: {
@@ -35,7 +35,7 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
35
35
  extraCommands: ICommand<string>[] | undefined;
36
36
  commandOrchestrator?: TextAreaCommandOrchestrator | undefined;
37
37
  } | undefined;
38
- shortcuts?: ((e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand<string>[], commandOrchestrator?: TextAreaCommandOrchestrator | undefined, dispatch?: React.Dispatch<ContextStore> | undefined, state?: ExecuteCommandState | undefined) => void) | undefined;
38
+ shortcuts?: ((e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator | undefined, dispatch?: React.Dispatch<ContextStore> | undefined, state?: ExecuteCommandState | undefined) => void) | undefined;
39
39
  }) => JSX.Element) | undefined;
40
40
  toolbar?: ((command: ICommand<string>, disabled: boolean, executeCommand: (command: ICommand<string>, name?: string | undefined) => void, index: number) => void | React.ReactElement<any, string | React.JSXElementConstructor<any>> | null | undefined) | undefined;
41
41
  preview?: ((source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element) | undefined;
package/esm/Context.js CHANGED
@@ -5,5 +5,4 @@ export function reducer(state, action) {
5
5
  }
6
6
  export var EditorContext = /*#__PURE__*/React.createContext({
7
7
  markdown: ''
8
- });
9
- //# sourceMappingURL=Context.js.map
8
+ });
package/esm/Editor.d.ts CHANGED
@@ -141,7 +141,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
141
141
  }
142
142
  export interface RefMDEditor extends ContextStore {
143
143
  }
144
- declare type Editor = React.FC<PropsWithRef<MDEditorProps>> & {
144
+ type Editor = React.FC<PropsWithRef<MDEditorProps>> & {
145
145
  Markdown: typeof MarkdownPreview;
146
146
  };
147
147
  declare const mdEditor: Editor;
package/esm/Editor.js CHANGED
@@ -120,6 +120,14 @@ var InternalMDEditor = (props, ref) => {
120
120
  height: height
121
121
  }), [height]);
122
122
  useMemo(() => height !== state.height && onHeightChange && onHeightChange(state.height, height, state), [height, onHeightChange, state]);
123
+ // eslint-disable-next-line react-hooks/exhaustive-deps
124
+ useMemo(() => commands !== state.commands && dispatch({
125
+ commands: cmds
126
+ }), [props.commands]);
127
+ // eslint-disable-next-line react-hooks/exhaustive-deps
128
+ useMemo(() => extraCommands !== state.extraCommands && dispatch({
129
+ extraCommands: extraCmds
130
+ }), [props.extraCommands]);
123
131
  var textareaDomRef = useRef();
124
132
  var active = useRef('preview');
125
133
  var initScroll = useRef(false);
@@ -235,5 +243,4 @@ var InternalMDEditor = (props, ref) => {
235
243
  };
236
244
  var mdEditor = /*#__PURE__*/React.forwardRef(InternalMDEditor);
237
245
  mdEditor.Markdown = MarkdownPreview;
238
- export default mdEditor;
239
- //# sourceMappingURL=Editor.js.map
246
+ export default mdEditor;
@@ -38,5 +38,4 @@ export var bold = {
38
38
  end
39
39
  });
40
40
  }
41
- };
42
- //# sourceMappingURL=bold.js.map
41
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { selectWord, getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var code = {
@@ -91,5 +91,4 @@ export var codeBlock = {
91
91
  end: selectionEnd
92
92
  });
93
93
  }
94
- };
95
- //# sourceMappingURL=code.js.map
94
+ };
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import { selectWord } from '../utils/markdownUtils';
2
3
  import { jsx as _jsx } from "react/jsx-runtime";
3
4
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -49,5 +50,4 @@ export var comment = {
49
50
  })]
50
51
  })
51
52
  })
52
- };
53
- //# sourceMappingURL=comment.js.map
53
+ };
@@ -1,4 +1,3 @@
1
1
  export var divider = {
2
2
  keyCommand: 'divider'
3
- };
4
- //# sourceMappingURL=divider.js.map
3
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  export var fullscreen = {
4
4
  name: 'fullscreen',
@@ -26,5 +26,4 @@ export var fullscreen = {
26
26
  });
27
27
  }
28
28
  }
29
- };
30
- //# sourceMappingURL=fullscreen.js.map
29
+ };
@@ -1,5 +1,5 @@
1
1
  import { ICommand, ICommandChildCommands, ICommandChildHandle } from './';
2
- export declare type GroupOptions = Omit<ICommand<string>, 'children'> & {
2
+ export type GroupOptions = Omit<ICommand<string>, 'children'> & {
3
3
  children?: ICommandChildHandle['children'];
4
4
  };
5
5
  export declare const group: (arr: ICommandChildCommands['children'], options?: GroupOptions) => ICommand<string>;
@@ -26,5 +26,4 @@ export var group = (arr, options) => {
26
26
  });
27
27
  }
28
28
  return data;
29
- };
30
- //# sourceMappingURL=group.js.map
29
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  export var hr = {
4
4
  name: 'hr',
@@ -22,5 +22,4 @@ export var hr = {
22
22
  execute: (state, api) => {
23
23
  api.replaceSelection(state.selectedText + "\n\n" + (state.command.value || '') + "-\n\n");
24
24
  }
25
- };
26
- //# sourceMappingURL=hr.js.map
25
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { selectWord } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var image = {
@@ -40,5 +40,4 @@ export var image = {
40
40
  end
41
41
  });
42
42
  }
43
- };
44
- //# sourceMappingURL=image.js.map
43
+ };
@@ -49,10 +49,10 @@ export interface ICommandBase<T> {
49
49
  render?: (command: ICommand<T>, disabled: boolean, executeCommand: (command: ICommand<T>, name?: string) => void, index: number) => void | undefined | null | React.ReactElement;
50
50
  execute?: (state: ExecuteState, api: TextAreaTextApi, dispatch?: React.Dispatch<ContextStore>, executeCommandState?: ExecuteCommandState, shortcuts?: string[]) => void;
51
51
  }
52
- export declare type ExecuteState = TextState & {
52
+ export type ExecuteState = TextState & {
53
53
  command: ICommand;
54
54
  };
55
- export declare type ICommand<T = string> = ICommandChildCommands<T> | ICommandChildHandle<T>;
55
+ export type ICommand<T = string> = ICommandChildCommands<T> | ICommandChildHandle<T>;
56
56
  export interface TextRange {
57
57
  start: number;
58
58
  end: number;
@@ -87,5 +87,4 @@ class TextAreaCommandOrchestrator {
87
87
  }
88
88
  export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, codeEdit, codeLive, codePreview, fullscreen,
89
89
  // Tool method.
90
- getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi };
91
- //# sourceMappingURL=index.js.map
90
+ getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { selectWord } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var italic = {
@@ -39,5 +39,4 @@ export var italic = {
39
39
  end
40
40
  });
41
41
  }
42
- };
43
- //# sourceMappingURL=italic.js.map
42
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { selectWord } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var link = {
@@ -39,5 +39,4 @@ export var link = {
39
39
  end
40
40
  });
41
41
  }
42
- };
43
- //# sourceMappingURL=link.js.map
42
+ };
@@ -1,5 +1,5 @@
1
1
  import { ICommand, TextState, TextAreaTextApi } from './';
2
- export declare type AlterLineFunction = (line: string, index: number) => string;
2
+ export type AlterLineFunction = (line: string, index: number) => string;
3
3
  /**
4
4
  * Inserts insertionString before each line
5
5
  */
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { selectWord, getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  /**
@@ -118,5 +118,4 @@ export var checkedListCommand = {
118
118
  execute: (state, api) => {
119
119
  makeList(state, api, (item, index) => "- [ ] ");
120
120
  }
121
- };
122
- //# sourceMappingURL=list.js.map
121
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { jsxs as _jsxs } from "react/jsx-runtime";
4
4
  export var codePreview = {
@@ -90,5 +90,4 @@ export var codeLive = {
90
90
  });
91
91
  }
92
92
  }
93
- };
94
- //# sourceMappingURL=preview.js.map
93
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter, selectWord } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var quote = {
@@ -39,5 +39,4 @@ export var quote = {
39
39
  end: selectionEnd
40
40
  });
41
41
  }
42
- };
43
- //# sourceMappingURL=quote.js.map
42
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { selectWord } from '../utils/markdownUtils';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var strikethrough = {
@@ -39,5 +39,4 @@ export var strikethrough = {
39
39
  end
40
40
  });
41
41
  }
42
- };
43
- //# sourceMappingURL=strikeThrough.js.map
42
+ };
@@ -12,5 +12,4 @@ export var title = _extends({}, title1, {
12
12
  d: "M15.7083333,468 C7.03242448,468 0,462.030833 0,454.666667 L0,421.333333 C0,413.969167 7.03242448,408 15.7083333,408 L361.291667,408 C369.967576,408 377,413.969167 377,421.333333 L377,454.666667 C377,462.030833 369.967576,468 361.291667,468 L15.7083333,468 Z M21.6666667,366 C9.69989583,366 0,359.831861 0,352.222222 L0,317.777778 C0,310.168139 9.69989583,304 21.6666667,304 L498.333333,304 C510.300104,304 520,310.168139 520,317.777778 L520,352.222222 C520,359.831861 510.300104,366 498.333333,366 L21.6666667,366 Z M136.835938,64 L136.835937,126 L107.25,126 L107.25,251 L40.75,251 L40.75,126 L-5.68434189e-14,126 L-5.68434189e-14,64 L136.835938,64 Z M212,64 L212,251 L161.648438,251 L161.648438,64 L212,64 Z M378,64 L378,126 L343.25,126 L343.25,251 L281.75,251 L281.75,126 L238,126 L238,64 L378,64 Z M449.047619,189.550781 L520,189.550781 L520,251 L405,251 L405,64 L449.047619,64 L449.047619,189.550781 Z"
13
13
  })
14
14
  })
15
- });
16
- //# sourceMappingURL=title.js.map
15
+ });
@@ -24,5 +24,4 @@ export var title1 = {
24
24
  insertAtLineStart('# ', state.selection.start, api.textArea);
25
25
  }
26
26
  }
27
- };
28
- //# sourceMappingURL=title1.js.map
27
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { insertAtLineStart } from '../utils/InsertTextAtPosition';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title2 = {
@@ -24,5 +24,4 @@ export var title2 = {
24
24
  insertAtLineStart('## ', state.selection.start, api.textArea);
25
25
  }
26
26
  }
27
- };
28
- //# sourceMappingURL=title2.js.map
27
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { insertAtLineStart } from '../utils/InsertTextAtPosition';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title3 = {
@@ -24,5 +24,4 @@ export var title3 = {
24
24
  insertAtLineStart('### ', state.selection.start, api.textArea);
25
25
  }
26
26
  }
27
- };
28
- //# sourceMappingURL=title3.js.map
27
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { insertAtLineStart } from '../utils/InsertTextAtPosition';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title4 = {
@@ -24,5 +24,4 @@ export var title4 = {
24
24
  insertAtLineStart('#### ', state.selection.start, api.textArea);
25
25
  }
26
26
  }
27
- };
28
- //# sourceMappingURL=title4.js.map
27
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { insertAtLineStart } from '../utils/InsertTextAtPosition';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title5 = {
@@ -24,5 +24,4 @@ export var title5 = {
24
24
  insertAtLineStart('##### ', state.selection.start, api.textArea);
25
25
  }
26
26
  }
27
- };
28
- //# sourceMappingURL=title5.js.map
27
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { insertAtLineStart } from '../utils/InsertTextAtPosition';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var title6 = {
@@ -24,5 +24,4 @@ export var title6 = {
24
24
  insertAtLineStart('###### ', state.selection.start, api.textArea);
25
25
  }
26
26
  }
27
- };
28
- //# sourceMappingURL=title6.js.map
27
+ };
@@ -74,5 +74,4 @@ var DragBar = props => {
74
74
  children: svg
75
75
  });
76
76
  };
77
- export default DragBar;
78
- //# sourceMappingURL=index.js.map
77
+ export default DragBar;
@@ -60,5 +60,4 @@ export default function Markdown(props) {
60
60
  __html: mdStr || ''
61
61
  }
62
62
  });
63
- }
64
- //# sourceMappingURL=Markdown.js.map
63
+ }
@@ -81,5 +81,4 @@ export default function Textarea(props) {
81
81
  _onChange && _onChange(e);
82
82
  }
83
83
  }));
84
- }
85
- //# sourceMappingURL=Textarea.js.map
84
+ }
@@ -1 +1,2 @@
1
+ /// <reference types="react" />
1
2
  export default function handleKeyDown(e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, tabSize?: number, defaultTabEnable?: boolean): void;
@@ -79,5 +79,4 @@ export default function handleKeyDown(e, tabSize, defaultTabEnable) {
79
79
  }
80
80
  return insertTextAtPosition(target, startStr);
81
81
  }
82
- }
83
- //# sourceMappingURL=handleKeyDown.js.map
82
+ }
@@ -4,7 +4,7 @@ import { TextAreaProps } from './Textarea';
4
4
  import { IProps } from '../../Editor';
5
5
  import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
6
6
  import './index.less';
7
- declare type RenderTextareaHandle = {
7
+ type RenderTextareaHandle = {
8
8
  dispatch: ContextStore['dispatch'];
9
9
  onChange?: TextAreaProps['onChange'];
10
10
  useContext?: {
@@ -19,7 +19,7 @@ export interface ITextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTe
19
19
  onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
20
20
  renderTextarea?: (props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>, opts: RenderTextareaHandle) => JSX.Element;
21
21
  }
22
- export declare type TextAreaRef = {
22
+ export type TextAreaRef = {
23
23
  text?: HTMLTextAreaElement;
24
24
  warp?: HTMLDivElement;
25
25
  };
@@ -95,5 +95,4 @@ export default function TextArea(props) {
95
95
  })
96
96
  })
97
97
  });
98
- }
99
- //# sourceMappingURL=index.js.map
98
+ }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { ICommand, TextAreaCommandOrchestrator } from '../../commands';
2
3
  import { ContextStore, ExecuteCommandState } from '../../Context';
3
4
  export default function shortcutsHandle(e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands?: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState): void;
@@ -61,5 +61,4 @@ export default function shortcutsHandle(e, commands, commandOrchestrator, dispat
61
61
  commandOrchestrator.executeCommand(command, dispatch, state, shortcuts);
62
62
  return;
63
63
  }
64
- }
65
- //# sourceMappingURL=shortcuts.js.map
64
+ }
@@ -1,6 +1,7 @@
1
+ /// <reference types="react" />
1
2
  import './Child.less';
2
3
  import { IToolbarProps } from './';
3
- export declare type ChildProps = IToolbarProps & {
4
+ export type ChildProps = IToolbarProps & {
4
5
  children?: JSX.Element;
5
6
  groupName?: string;
6
7
  };
@@ -25,5 +25,4 @@ export default function Child(props) {
25
25
  }),
26
26
  // eslint-disable-next-line react-hooks/exhaustive-deps
27
27
  [commands, barPopup, groupName, prefixCls]);
28
- }
29
- //# sourceMappingURL=Child.js.map
28
+ }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { IProps } from '../../Editor';
2
3
  import { ICommand } from '../../commands';
3
4
  import './index.less';
@@ -128,5 +128,4 @@ export default function Toolbar(props) {
128
128
  commands: extraCommands || []
129
129
  }))]
130
130
  });
131
- }
132
- //# sourceMappingURL=index.js.map
131
+ }
package/esm/index.js CHANGED
@@ -6,5 +6,4 @@ export * from './utils/markdownUtils';
6
6
  export * from './Editor';
7
7
  export * from './Context';
8
8
  export { MarkdownUtil, commands };
9
- export default MDEditor;
10
- //# sourceMappingURL=index.js.map
9
+ export default MDEditor;
@@ -0,0 +1 @@
1
+ /// <reference types="react-scripts" />
@@ -134,5 +134,4 @@ export function insertTextAtPosition(input, text) {
134
134
  e.initEvent('input', true, false);
135
135
  input.dispatchEvent(e);
136
136
  }
137
- }
138
- //# sourceMappingURL=InsertTextAtPosition.js.map
137
+ }
@@ -105,5 +105,4 @@ export function getSurroundingWord(text, position) {
105
105
  start,
106
106
  end
107
107
  };
108
- }
109
- //# sourceMappingURL=markdownUtils.js.map
108
+ }
package/lib/Context.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { ICommand, TextAreaCommandOrchestrator } from './commands';
3
3
  import { MDEditorProps } from './Editor';
4
- export declare type PreviewType = 'live' | 'edit' | 'preview';
4
+ export type PreviewType = 'live' | 'edit' | 'preview';
5
5
  export interface ContextStore {
6
6
  components?: MDEditorProps['components'];
7
7
  commands?: ICommand<string>[];
@@ -24,7 +24,7 @@ export interface ContextStore {
24
24
  tabSize?: number;
25
25
  defaultTabEnable?: boolean;
26
26
  }
27
- export declare type ExecuteCommandState = Pick<ContextStore, 'fullscreen' | 'preview' | 'highlightEnable'>;
27
+ export type ExecuteCommandState = Pick<ContextStore, 'fullscreen' | 'preview' | 'highlightEnable'>;
28
28
  export declare function reducer(state: ContextStore, action: ContextStore): {
29
29
  components?: {
30
30
  textarea?: ((props: React.HTMLAttributes<HTMLDivElement> | React.TextareaHTMLAttributes<HTMLTextAreaElement>, opts: {
@@ -35,7 +35,7 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
35
35
  extraCommands: ICommand<string>[] | undefined;
36
36
  commandOrchestrator?: TextAreaCommandOrchestrator | undefined;
37
37
  } | undefined;
38
- shortcuts?: ((e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand<string>[], commandOrchestrator?: TextAreaCommandOrchestrator | undefined, dispatch?: React.Dispatch<ContextStore> | undefined, state?: ExecuteCommandState | undefined) => void) | undefined;
38
+ shortcuts?: ((e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator | undefined, dispatch?: React.Dispatch<ContextStore> | undefined, state?: ExecuteCommandState | undefined) => void) | undefined;
39
39
  }) => JSX.Element) | undefined;
40
40
  toolbar?: ((command: ICommand<string>, disabled: boolean, executeCommand: (command: ICommand<string>, name?: string | undefined) => void, index: number) => void | React.ReactElement<any, string | React.JSXElementConstructor<any>> | null | undefined) | undefined;
41
41
  preview?: ((source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element) | undefined;
package/lib/Context.js CHANGED
@@ -14,5 +14,4 @@ function reducer(state, action) {
14
14
  var EditorContext = /*#__PURE__*/_react["default"].createContext({
15
15
  markdown: ''
16
16
  });
17
- exports.EditorContext = EditorContext;
18
- //# sourceMappingURL=Context.js.map
17
+ exports.EditorContext = EditorContext;
package/lib/Editor.d.ts CHANGED
@@ -141,7 +141,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
141
141
  }
142
142
  export interface RefMDEditor extends ContextStore {
143
143
  }
144
- declare type Editor = React.FC<PropsWithRef<MDEditorProps>> & {
144
+ type Editor = React.FC<PropsWithRef<MDEditorProps>> & {
145
145
  Markdown: typeof MarkdownPreview;
146
146
  };
147
147
  declare const mdEditor: Editor;
package/lib/Editor.js CHANGED
@@ -166,6 +166,18 @@ var InternalMDEditor = function InternalMDEditor(props, ref) {
166
166
  (0, _react.useMemo)(function () {
167
167
  return height !== state.height && onHeightChange && onHeightChange(state.height, height, state);
168
168
  }, [height, onHeightChange, state]);
169
+ // eslint-disable-next-line react-hooks/exhaustive-deps
170
+ (0, _react.useMemo)(function () {
171
+ return commands !== state.commands && dispatch({
172
+ commands: cmds
173
+ });
174
+ }, [props.commands]);
175
+ // eslint-disable-next-line react-hooks/exhaustive-deps
176
+ (0, _react.useMemo)(function () {
177
+ return extraCommands !== state.extraCommands && dispatch({
178
+ extraCommands: extraCmds
179
+ });
180
+ }, [props.extraCommands]);
169
181
  var textareaDomRef = (0, _react.useRef)();
170
182
  var active = (0, _react.useRef)('preview');
171
183
  var initScroll = (0, _react.useRef)(false);
@@ -293,5 +305,4 @@ var mdEditor = /*#__PURE__*/_react["default"].forwardRef(InternalMDEditor);
293
305
  mdEditor.Markdown = _reactMarkdownPreview["default"];
294
306
  var _default = mdEditor;
295
307
  exports["default"] = _default;
296
- module.exports = exports.default;
297
- //# sourceMappingURL=Editor.js.map
308
+ module.exports = exports.default;
@@ -46,5 +46,4 @@ var bold = {
46
46
  });
47
47
  }
48
48
  };
49
- exports.bold = bold;
50
- //# sourceMappingURL=bold.js.map
49
+ exports.bold = bold;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.codeBlock = exports.code = void 0;
8
- var React = _interopRequireWildcard(require("react"));
8
+ var _react = _interopRequireDefault(require("react"));
9
9
  var _markdownUtils = require("../utils/markdownUtils");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
11
  var code = {
@@ -100,5 +100,4 @@ var codeBlock = {
100
100
  });
101
101
  }
102
102
  };
103
- exports.codeBlock = codeBlock;
104
- //# sourceMappingURL=code.js.map
103
+ exports.codeBlock = codeBlock;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.comment = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
7
9
  var _markdownUtils = require("../utils/markdownUtils");
8
10
  var _jsxRuntime = require("react/jsx-runtime");
9
11
  var comment = {
@@ -55,5 +57,4 @@ var comment = {
55
57
  })
56
58
  })
57
59
  };
58
- exports.comment = comment;
59
- //# sourceMappingURL=comment.js.map
60
+ exports.comment = comment;
@@ -7,5 +7,4 @@ exports.divider = void 0;
7
7
  var divider = {
8
8
  keyCommand: 'divider'
9
9
  };
10
- exports.divider = divider;
11
- //# sourceMappingURL=divider.js.map
10
+ exports.divider = divider;