@uiw/react-md-editor 4.0.5 → 4.0.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.
Files changed (125) hide show
  1. package/README.md +57 -3
  2. package/dist/mdeditor.css +107 -107
  3. package/dist/mdeditor.js +7866 -3903
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/esm/Context.d.ts +3 -1
  7. package/esm/Editor.js +10 -6
  8. package/esm/Editor.nohighlight.js +9 -5
  9. package/esm/Types.d.ts +6 -2
  10. package/esm/commands/bold.d.ts +1 -1
  11. package/esm/commands/bold.js +1 -1
  12. package/esm/commands/code.d.ts +1 -1
  13. package/esm/commands/code.js +1 -1
  14. package/esm/commands/comment.d.ts +1 -1
  15. package/esm/commands/comment.js +1 -1
  16. package/esm/commands/divider.d.ts +1 -1
  17. package/esm/commands/fullscreen.d.ts +1 -1
  18. package/esm/commands/group.d.ts +1 -1
  19. package/esm/commands/help.d.ts +1 -1
  20. package/esm/commands/hr.d.ts +1 -1
  21. package/esm/commands/hr.js +1 -1
  22. package/esm/commands/image.d.ts +1 -1
  23. package/esm/commands/image.js +1 -1
  24. package/esm/commands/index.cn.js +24 -24
  25. package/esm/commands/index.d.ts +1 -1
  26. package/esm/commands/index.js +25 -25
  27. package/esm/commands/issue.d.ts +1 -1
  28. package/esm/commands/issue.js +1 -1
  29. package/esm/commands/italic.d.ts +1 -1
  30. package/esm/commands/italic.js +1 -1
  31. package/esm/commands/link.d.ts +1 -1
  32. package/esm/commands/link.js +1 -1
  33. package/esm/commands/list.d.ts +1 -1
  34. package/esm/commands/list.js +1 -1
  35. package/esm/commands/preview.d.ts +1 -1
  36. package/esm/commands/quote.d.ts +1 -1
  37. package/esm/commands/quote.js +1 -1
  38. package/esm/commands/strikeThrough.js +1 -1
  39. package/esm/commands/table.js +1 -1
  40. package/esm/commands/title.js +2 -2
  41. package/esm/commands/title1.js +1 -1
  42. package/esm/commands/title2.js +1 -1
  43. package/esm/commands/title3.js +1 -1
  44. package/esm/commands/title4.js +1 -1
  45. package/esm/commands/title5.js +1 -1
  46. package/esm/commands/title6.js +1 -1
  47. package/esm/components/TextArea/Markdown.js +1 -1
  48. package/esm/components/TextArea/Textarea.js +22 -5
  49. package/esm/components/TextArea/handleKeyDown.js +3 -4
  50. package/esm/components/TextArea/index.d.ts +1 -1
  51. package/esm/components/TextArea/index.js +5 -5
  52. package/esm/components/TextArea/index.nohighlight.d.ts +1 -1
  53. package/esm/components/TextArea/index.nohighlight.js +4 -4
  54. package/esm/components/TextArea/shortcuts.d.ts +1 -1
  55. package/esm/components/Toolbar/Child.js +2 -2
  56. package/esm/components/Toolbar/index.d.ts +1 -1
  57. package/esm/components/Toolbar/index.js +2 -2
  58. package/esm/index.d.ts +2 -2
  59. package/esm/index.js +10 -10
  60. package/esm/index.nohighlight.d.ts +2 -2
  61. package/esm/index.nohighlight.js +8 -8
  62. package/esm/utils/markdownUtils.d.ts +1 -2
  63. package/lib/Context.d.ts +3 -1
  64. package/lib/Editor.js +12 -5
  65. package/lib/Editor.nohighlight.js +11 -4
  66. package/lib/Types.d.ts +6 -2
  67. package/lib/commands/bold.d.ts +1 -1
  68. package/lib/commands/code.d.ts +1 -1
  69. package/lib/commands/comment.d.ts +1 -1
  70. package/lib/commands/divider.d.ts +1 -1
  71. package/lib/commands/fullscreen.d.ts +1 -1
  72. package/lib/commands/group.d.ts +1 -1
  73. package/lib/commands/help.d.ts +1 -1
  74. package/lib/commands/hr.d.ts +1 -1
  75. package/lib/commands/image.d.ts +1 -1
  76. package/lib/commands/index.d.ts +1 -1
  77. package/lib/commands/issue.d.ts +1 -1
  78. package/lib/commands/italic.d.ts +1 -1
  79. package/lib/commands/link.d.ts +1 -1
  80. package/lib/commands/list.d.ts +1 -1
  81. package/lib/commands/preview.d.ts +1 -1
  82. package/lib/commands/quote.d.ts +1 -1
  83. package/lib/components/TextArea/Textarea.js +19 -2
  84. package/lib/components/TextArea/handleKeyDown.js +1 -1
  85. package/lib/components/TextArea/index.d.ts +1 -1
  86. package/lib/components/TextArea/index.js +1 -1
  87. package/lib/components/TextArea/index.nohighlight.d.ts +1 -1
  88. package/lib/components/TextArea/index.nohighlight.js +1 -1
  89. package/lib/components/TextArea/shortcuts.d.ts +1 -1
  90. package/lib/components/Toolbar/index.d.ts +1 -1
  91. package/lib/index.d.ts +2 -2
  92. package/lib/index.js +1 -1
  93. package/lib/index.nohighlight.d.ts +2 -2
  94. package/lib/index.nohighlight.js +1 -1
  95. package/lib/utils/markdownUtils.d.ts +1 -2
  96. package/package.json +1 -1
  97. package/src/Context.tsx +2 -1
  98. package/src/Editor.nohighlight.tsx +5 -3
  99. package/src/Editor.tsx +6 -4
  100. package/src/Types.ts +6 -2
  101. package/src/commands/bold.tsx +1 -1
  102. package/src/commands/code.tsx +1 -1
  103. package/src/commands/comment.tsx +1 -1
  104. package/src/commands/divider.tsx +1 -1
  105. package/src/commands/fullscreen.tsx +2 -2
  106. package/src/commands/group.tsx +1 -1
  107. package/src/commands/help.tsx +1 -1
  108. package/src/commands/hr.tsx +1 -1
  109. package/src/commands/image.tsx +1 -1
  110. package/src/commands/index.ts +1 -1
  111. package/src/commands/issue.tsx +1 -1
  112. package/src/commands/italic.tsx +1 -1
  113. package/src/commands/link.tsx +1 -1
  114. package/src/commands/list.tsx +1 -1
  115. package/src/commands/preview.tsx +2 -2
  116. package/src/commands/quote.tsx +1 -1
  117. package/src/components/TextArea/Textarea.tsx +19 -1
  118. package/src/components/TextArea/handleKeyDown.tsx +1 -1
  119. package/src/components/TextArea/index.nohighlight.tsx +1 -1
  120. package/src/components/TextArea/index.tsx +1 -1
  121. package/src/components/TextArea/shortcuts.ts +1 -1
  122. package/src/components/Toolbar/index.tsx +1 -1
  123. package/src/index.nohighlight.tsx +2 -2
  124. package/src/index.tsx +2 -2
  125. package/src/utils/markdownUtils.ts +1 -2
package/src/Types.ts CHANGED
@@ -37,6 +37,10 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
37
37
  * or it has an `autofocus` attribute and no other element is focused.
38
38
  */
39
39
  autoFocus?: ITextAreaProps['autoFocus'];
40
+ /**
41
+ * Can be used to make `Markdown Editor` focus on the end of text on initialization.
42
+ */
43
+ autoFocusEnd?: boolean;
40
44
  /**
41
45
  * The height of the editor.
42
46
  * ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
@@ -55,7 +59,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
55
59
  */
56
60
  visibleDragbar?: boolean;
57
61
  /**
58
- * @deprecated use `visibleDragbar`
62
+ * @deprecated use {@link MDEditorProps.visibleDragbar}
59
63
  */
60
64
  visiableDragbar?: boolean;
61
65
  /**
@@ -88,7 +92,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
88
92
  textareaProps?: ITextAreaProps;
89
93
  /**
90
94
  * Use div to replace TextArea or re-render TextArea
91
- * @deprecated Please use ~~`renderTextarea`~~ -> `components`
95
+ * @deprecated Please use {@link components}
92
96
  */
93
97
  renderTextarea?: ITextAreaProps['renderTextarea'];
94
98
  /**
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const bold: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const codeBlock: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const comment: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand } from './';
2
+ import { type ICommand } from './';
3
3
 
4
4
  export const divider: ICommand = {
5
5
  keyCommand: 'divider',
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { ICommand, TextState, TextAreaTextApi } from './';
3
- import { ContextStore, ExecuteCommandState } from '../Context';
2
+ import { type ICommand, TextState, type TextAreaTextApi } from './';
3
+ import { type ContextStore, type ExecuteCommandState } from '../Context';
4
4
 
5
5
  export const fullscreen: ICommand = {
6
6
  name: 'fullscreen',
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ICommandChildCommands, ICommandChildHandle } from './';
2
+ import { type ICommand, type ICommandChildCommands, type ICommandChildHandle } from './';
3
3
 
4
4
  export type GroupOptions = Omit<ICommand<string>, 'children'> & {
5
5
  children?: ICommandChildHandle['children'];
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand } from './';
3
3
 
4
4
  export const help: ICommand = {
5
5
  name: 'help',
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const hr: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const image: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ContextStore, ExecuteCommandState } from '../Context';
2
+ import { type ContextStore, ExecuteCommandState } from '../Context';
3
3
  import { insertTextAtPosition } from '../utils/InsertTextAtPosition';
4
4
  import { bold } from './bold';
5
5
  import { code, codeBlock } from './code';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const issue: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const italic: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import { selectWord, executeCommand } from '../utils/markdownUtils';
4
4
 
5
5
  export const link: ICommand = {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import {
4
4
  selectWord,
5
5
  getBreaksNeededForEmptyLineBefore,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { ICommand, TextState, TextAreaTextApi } from './';
3
- import { ContextStore, ExecuteCommandState } from '../Context';
2
+ import { type ICommand, type TextState, TextAreaTextApi } from './';
3
+ import { type ContextStore, type ExecuteCommandState } from '../Context';
4
4
 
5
5
  export const codePreview: ICommand = {
6
6
  name: 'preview',
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
2
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import {
4
4
  getBreaksNeededForEmptyLineBefore,
5
5
  getBreaksNeededForEmptyLineAfter,
@@ -1,7 +1,7 @@
1
1
  import React, { useContext, useEffect } from 'react';
2
2
  import { IProps } from '../../Types';
3
3
  import { EditorContext, ExecuteCommandState } from '../../Context';
4
- import { TextAreaCommandOrchestrator } from '../../commands';
4
+ import { TextAreaCommandOrchestrator } from '../../commands/';
5
5
  import handleKeyDown from './handleKeyDown';
6
6
  import shortcuts from './shortcuts';
7
7
  import './index.less';
@@ -19,6 +19,8 @@ export default function Textarea(props: TextAreaProps) {
19
19
  extraCommands,
20
20
  tabSize,
21
21
  defaultTabEnable,
22
+ autoFocusEnd,
23
+ textareaWarp,
22
24
  dispatch,
23
25
  ...otherStore
24
26
  } = useContext(EditorContext);
@@ -39,6 +41,22 @@ export default function Textarea(props: TextAreaProps) {
39
41
  // eslint-disable-next-line react-hooks/exhaustive-deps
40
42
  }, []);
41
43
 
44
+ useEffect(() => {
45
+ if (autoFocusEnd && textRef.current && textareaWarp) {
46
+ textRef.current.focus();
47
+ const length = textRef.current.value.length;
48
+ textRef.current.setSelectionRange(length, length);
49
+ setTimeout(() => {
50
+ if (textareaWarp) {
51
+ textareaWarp.scrollTop = textareaWarp.scrollHeight;
52
+ }
53
+ if (textRef.current) {
54
+ textRef.current.scrollTop = textRef.current.scrollHeight;
55
+ }
56
+ }, 0);
57
+ }
58
+ }, [textareaWarp]);
59
+
42
60
  const onKeyDown = (e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>) => {
43
61
  handleKeyDown(e, tabSize, defaultTabEnable);
44
62
  shortcuts(e, [...(commands || []), ...(extraCommands || [])], executeRef.current, dispatch, statesRef.current);
@@ -1,6 +1,6 @@
1
1
  import { insertTextAtPosition } from '../../utils/InsertTextAtPosition';
2
2
  import { insertBeforeEachLine, selectLine } from '../../utils/markdownUtils';
3
- import { TextAreaTextApi } from '../../commands';
3
+ import { TextAreaTextApi } from '../../commands/';
4
4
 
5
5
  /**
6
6
  * - `13` - `Enter`
@@ -3,7 +3,7 @@ import { EditorContext, ContextStore, ExecuteCommandState } from '../../Context'
3
3
  import shortcuts from './shortcuts';
4
4
  import Textarea, { TextAreaProps } from './Textarea';
5
5
  import { IProps } from '../../Types';
6
- import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
6
+ import { TextAreaCommandOrchestrator, ICommand } from '../../commands/';
7
7
  import './index.less';
8
8
 
9
9
  type RenderTextareaHandle = {
@@ -4,7 +4,7 @@ import shortcuts from './shortcuts';
4
4
  import Markdown from './Markdown';
5
5
  import Textarea, { TextAreaProps } from './Textarea';
6
6
  import { IProps } from '../../Types';
7
- import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
7
+ import { TextAreaCommandOrchestrator, ICommand } from '../../commands/';
8
8
  import './index.less';
9
9
 
10
10
  type RenderTextareaHandle = {
@@ -1,4 +1,4 @@
1
- import { ICommand, TextAreaCommandOrchestrator } from '../../commands';
1
+ import { ICommand, TextAreaCommandOrchestrator } from '../../commands/';
2
2
  import { ContextStore, ExecuteCommandState } from '../../Context';
3
3
 
4
4
  function getCommands(data: ICommand[] = [], resulte: Record<string, ICommand> = {}): Record<string, ICommand> {
@@ -1,7 +1,7 @@
1
1
  import React, { Fragment, useContext, useEffect, useRef } from 'react';
2
2
  import { IProps } from '../../Types';
3
3
  import { EditorContext, PreviewType, ContextStore } from '../../Context';
4
- import { ICommand } from '../../commands';
4
+ import { ICommand } from '../../commands/';
5
5
  import Child from './Child';
6
6
  import './index.less';
7
7
 
@@ -1,9 +1,9 @@
1
1
  import MDEditor from './Editor.nohighlight';
2
- import * as commands from './commands';
2
+ import * as commands from './commands/';
3
3
  import * as MarkdownUtil from './utils/markdownUtils';
4
4
  import './index.less';
5
5
 
6
- export * from './commands';
6
+ export * from './commands/';
7
7
  export * from './commands/group';
8
8
  export * from './utils/markdownUtils';
9
9
  export * from './utils/InsertTextAtPosition';
package/src/index.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import MDEditor from './Editor';
2
- import * as commands from './commands';
2
+ import * as commands from './commands/';
3
3
  import * as MarkdownUtil from './utils/markdownUtils';
4
4
  import './index.less';
5
5
 
6
- export * from './commands';
6
+ export * from './commands/';
7
7
  export * from './commands/group';
8
8
  export * from './utils/markdownUtils';
9
9
  export * from './utils/InsertTextAtPosition';
@@ -1,5 +1,4 @@
1
- import { TextRange } from '../commands';
2
- import { TextAreaTextApi, ExecuteState } from '../commands';
1
+ import { TextAreaTextApi, type TextRange } from '../commands';
3
2
 
4
3
  export interface TextSection {
5
4
  text: string;