@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
@@ -2,10 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
3
  var _excluded = ["prefixCls", "className", "onScroll", "renderTextarea"];
4
4
  import React, { useEffect, Fragment, useContext } from 'react';
5
- import { EditorContext } from '../../Context';
6
- import shortcuts from './shortcuts';
7
- import Textarea from './Textarea';
8
- import { TextAreaCommandOrchestrator } from '../../commands';
5
+ import { EditorContext } from "../../Context.js";
6
+ import shortcuts from "./shortcuts.js";
7
+ import Textarea from "./Textarea.js";
8
+ import { TextAreaCommandOrchestrator } from "../../commands/index.js";
9
9
  import "./index.css";
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  export default function TextArea(props) {
@@ -1,3 +1,3 @@
1
- import { ICommand, TextAreaCommandOrchestrator } from '../../commands';
1
+ import { ICommand, TextAreaCommandOrchestrator } from '../../commands/';
2
2
  import { ContextStore, ExecuteCommandState } from '../../Context';
3
3
  export default function shortcutsHandle(e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands?: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState): void;
@@ -1,8 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useContext, useMemo } from 'react';
3
3
  import "./Child.css";
4
- import Toolbar from './';
5
- import { EditorContext } from '../../Context';
4
+ import Toolbar from "./index.js";
5
+ import { EditorContext } from "../../Context.js";
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  export default function Child(props) {
8
8
  var {
@@ -1,5 +1,5 @@
1
1
  import { IProps } from '../../Types';
2
- import { ICommand } from '../../commands';
2
+ import { ICommand } from '../../commands/';
3
3
  import './index.less';
4
4
  export interface IToolbarProps extends IProps {
5
5
  overflow?: boolean;
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { Fragment, useContext, useEffect, useRef } from 'react';
3
- import { EditorContext } from '../../Context';
4
- import Child from './Child';
3
+ import { EditorContext } from "../../Context.js";
4
+ import Child from "./Child.js";
5
5
  import "./index.css";
6
6
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
7
  export function ToolbarItems(props) {
package/esm/index.d.ts CHANGED
@@ -1,8 +1,8 @@
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
- export * from './commands';
5
+ export * from './commands/';
6
6
  export * from './commands/group';
7
7
  export * from './utils/markdownUtils';
8
8
  export * from './utils/InsertTextAtPosition';
package/esm/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import MDEditor from './Editor';
2
- import * as commands from './commands';
3
- import * as MarkdownUtil from './utils/markdownUtils';
1
+ import MDEditor from "./Editor.js";
2
+ import * as commands from "./commands/index.js";
3
+ import * as MarkdownUtil from "./utils/markdownUtils.js";
4
4
  import "./index.css";
5
- export * from './commands';
6
- export * from './commands/group';
7
- export * from './utils/markdownUtils';
8
- export * from './utils/InsertTextAtPosition';
9
- export * from './Editor';
10
- export * from './Context';
11
- export * from './Types';
5
+ export * from "./commands/index.js";
6
+ export * from "./commands/group.js";
7
+ export * from "./utils/markdownUtils.js";
8
+ export * from "./utils/InsertTextAtPosition.js";
9
+ export * from "./Editor.js";
10
+ export * from "./Context.js";
11
+ export * from "./Types.js";
12
12
  export { MarkdownUtil, commands };
13
13
  export default MDEditor;
@@ -1,8 +1,8 @@
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
- export * from './commands';
5
+ export * from './commands/';
6
6
  export * from './commands/group';
7
7
  export * from './utils/markdownUtils';
8
8
  export * from './utils/InsertTextAtPosition';
@@ -1,13 +1,13 @@
1
1
  import MDEditor from './Editor.nohighlight';
2
- import * as commands from './commands';
3
- import * as MarkdownUtil from './utils/markdownUtils';
2
+ import * as commands from "./commands/index.js";
3
+ import * as MarkdownUtil from "./utils/markdownUtils.js";
4
4
  import "./index.css";
5
- export * from './commands';
6
- export * from './commands/group';
7
- export * from './utils/markdownUtils';
8
- export * from './utils/InsertTextAtPosition';
5
+ export * from "./commands/index.js";
6
+ export * from "./commands/group.js";
7
+ export * from "./utils/markdownUtils.js";
8
+ export * from "./utils/InsertTextAtPosition.js";
9
9
  export * from './Editor.nohighlight';
10
- export * from './Context';
11
- export * from './Types';
10
+ export * from "./Context.js";
11
+ export * from "./Types.js";
12
12
  export { MarkdownUtil, commands };
13
13
  export default MDEditor;
@@ -1,5 +1,4 @@
1
- import { TextRange } from '../commands';
2
- import { TextAreaTextApi } from '../commands';
1
+ import { TextAreaTextApi, type TextRange } from '../commands';
3
2
  export interface TextSection {
4
3
  text: string;
5
4
  selection: TextRange;
package/lib/Context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, TextAreaCommandOrchestrator } from './commands';
2
+ import { ICommand, TextAreaCommandOrchestrator } from './commands/';
3
3
  import { MDEditorProps } from './Types';
4
4
  export type PreviewType = 'live' | 'edit' | 'preview';
5
5
  export interface ContextStore {
@@ -12,6 +12,7 @@ export interface ContextStore {
12
12
  fullscreen?: boolean;
13
13
  highlightEnable?: boolean;
14
14
  autoFocus?: boolean;
15
+ autoFocusEnd?: boolean;
15
16
  textarea?: HTMLTextAreaElement;
16
17
  commandOrchestrator?: TextAreaCommandOrchestrator;
17
18
  textareaWarp?: HTMLDivElement;
@@ -37,6 +38,7 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
37
38
  fullscreen?: boolean;
38
39
  highlightEnable?: boolean;
39
40
  autoFocus?: boolean;
41
+ autoFocusEnd?: boolean;
40
42
  textarea?: HTMLTextAreaElement;
41
43
  commandOrchestrator?: TextAreaCommandOrchestrator;
42
44
  textareaWarp?: HTMLDivElement;
package/lib/Editor.js CHANGED
@@ -11,13 +11,13 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
11
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
  var _reactMarkdownPreview = _interopRequireDefault(require("@uiw/react-markdown-preview"));
14
- var _TextArea = _interopRequireDefault(require("./components/TextArea"));
15
- var _Toolbar = require("./components/Toolbar");
16
- var _DragBar = _interopRequireDefault(require("./components/DragBar"));
17
- var _commands = require("./commands");
14
+ var _Toolbar = require("./components/Toolbar/");
15
+ var _TextArea = _interopRequireDefault(require("./components/TextArea/"));
16
+ var _DragBar = _interopRequireDefault(require("./components/DragBar/"));
17
+ var _commands = require("./commands/");
18
18
  var _Context = require("./Context");
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
- var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
20
+ var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "autoFocusEnd", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
21
21
  function setGroupPopFalse() {
22
22
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
23
  Object.keys(data).forEach(function (keyname) {
@@ -59,6 +59,8 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
59
59
  _ref$minHeight = _ref.minHeight,
60
60
  minHeight = _ref$minHeight === void 0 ? 100 : _ref$minHeight,
61
61
  autoFocus = _ref.autoFocus,
62
+ _ref$autoFocusEnd = _ref.autoFocusEnd,
63
+ autoFocusEnd = _ref$autoFocusEnd === void 0 ? false : _ref$autoFocusEnd,
62
64
  _ref$tabSize = _ref.tabSize,
63
65
  tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
64
66
  _ref$defaultTabEnable = _ref.defaultTabEnable,
@@ -152,6 +154,11 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
152
154
  autoFocus: autoFocus
153
155
  });
154
156
  }, [autoFocus]);
157
+ (0, _react.useMemo)(function () {
158
+ return autoFocusEnd !== state.autoFocusEnd && dispatch({
159
+ autoFocusEnd: autoFocusEnd
160
+ });
161
+ }, [autoFocusEnd]);
155
162
  (0, _react.useMemo)(function () {
156
163
  return fullscreen !== state.fullscreen && dispatch({
157
164
  fullscreen: fullscreen
@@ -12,12 +12,12 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
  var _nohighlight = _interopRequireDefault(require("@uiw/react-markdown-preview/nohighlight"));
14
14
  var _index = _interopRequireDefault(require("./components/TextArea/index.nohighlight"));
15
- var _Toolbar = require("./components/Toolbar");
16
- var _DragBar = _interopRequireDefault(require("./components/DragBar"));
17
- var _commands = require("./commands");
15
+ var _Toolbar = require("./components/Toolbar/");
16
+ var _DragBar = _interopRequireDefault(require("./components/DragBar/"));
17
+ var _commands = require("./commands/");
18
18
  var _Context = require("./Context");
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
- var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
20
+ var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "autoFocusEnd", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
21
21
  function setGroupPopFalse() {
22
22
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
23
  Object.keys(data).forEach(function (keyname) {
@@ -59,6 +59,8 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
59
59
  _ref$minHeight = _ref.minHeight,
60
60
  minHeight = _ref$minHeight === void 0 ? 100 : _ref$minHeight,
61
61
  autoFocus = _ref.autoFocus,
62
+ _ref$autoFocusEnd = _ref.autoFocusEnd,
63
+ autoFocusEnd = _ref$autoFocusEnd === void 0 ? false : _ref$autoFocusEnd,
62
64
  _ref$tabSize = _ref.tabSize,
63
65
  tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
64
66
  _ref$defaultTabEnable = _ref.defaultTabEnable,
@@ -152,6 +154,11 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
152
154
  autoFocus: autoFocus
153
155
  });
154
156
  }, [autoFocus]);
157
+ (0, _react.useMemo)(function () {
158
+ return autoFocusEnd !== state.autoFocusEnd && dispatch({
159
+ autoFocusEnd: autoFocusEnd
160
+ });
161
+ }, [autoFocusEnd]);
155
162
  (0, _react.useMemo)(function () {
156
163
  return fullscreen !== state.fullscreen && dispatch({
157
164
  fullscreen: fullscreen
package/lib/Types.d.ts CHANGED
@@ -34,6 +34,10 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
34
34
  * or it has an `autofocus` attribute and no other element is focused.
35
35
  */
36
36
  autoFocus?: ITextAreaProps['autoFocus'];
37
+ /**
38
+ * Can be used to make `Markdown Editor` focus on the end of text on initialization.
39
+ */
40
+ autoFocusEnd?: boolean;
37
41
  /**
38
42
  * The height of the editor.
39
43
  * ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
@@ -52,7 +56,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
52
56
  */
53
57
  visibleDragbar?: boolean;
54
58
  /**
55
- * @deprecated use `visibleDragbar`
59
+ * @deprecated use {@link MDEditorProps.visibleDragbar}
56
60
  */
57
61
  visiableDragbar?: boolean;
58
62
  /**
@@ -85,7 +89,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
85
89
  textareaProps?: ITextAreaProps;
86
90
  /**
87
91
  * Use div to replace TextArea or re-render TextArea
88
- * @deprecated Please use ~~`renderTextarea`~~ -> `components`
92
+ * @deprecated Please use {@link components}
89
93
  */
90
94
  renderTextarea?: ITextAreaProps['renderTextarea'];
91
95
  /**
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const bold: ICommand;
@@ -1,3 +1,3 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const codeBlock: ICommand;
3
3
  export declare const code: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const comment: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const divider: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const fullscreen: ICommand;
@@ -1,4 +1,4 @@
1
- import { ICommand, ICommandChildCommands, ICommandChildHandle } from './';
1
+ import { type ICommand, type ICommandChildCommands, type ICommandChildHandle } from './';
2
2
  export type GroupOptions = Omit<ICommand<string>, 'children'> & {
3
3
  children?: ICommandChildHandle['children'];
4
4
  };
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const help: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const hr: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare 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 { bold } from './bold';
4
4
  import { code, codeBlock } from './code';
5
5
  import { comment } from './comment';
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const issue: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const italic: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const link: ICommand;
@@ -1,4 +1,4 @@
1
- import { ICommand, ExecuteState, TextAreaTextApi } from './';
1
+ import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
2
2
  import { AlterLineFunction } from '../utils/markdownUtils';
3
3
  export declare const makeList: (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction) => void;
4
4
  export declare const unorderedListCommand: ICommand;
@@ -1,4 +1,4 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const codePreview: ICommand;
3
3
  export declare const codeEdit: ICommand;
4
4
  export declare const codeLive: ICommand;
@@ -1,2 +1,2 @@
1
- import { ICommand } from './';
1
+ import { type ICommand } from './';
2
2
  export declare const quote: ICommand;
@@ -11,12 +11,12 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
11
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
  var _Context = require("../../Context");
14
- var _commands = require("../../commands");
14
+ var _commands = require("../../commands/");
15
15
  var _handleKeyDown = _interopRequireDefault(require("./handleKeyDown"));
16
16
  var _shortcuts = _interopRequireDefault(require("./shortcuts"));
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
18
  var _excluded = ["prefixCls", "onChange"],
19
- _excluded2 = ["markdown", "commands", "fullscreen", "preview", "highlightEnable", "extraCommands", "tabSize", "defaultTabEnable", "dispatch"];
19
+ _excluded2 = ["markdown", "commands", "fullscreen", "preview", "highlightEnable", "extraCommands", "tabSize", "defaultTabEnable", "autoFocusEnd", "textareaWarp", "dispatch"];
20
20
  function Textarea(props) {
21
21
  var prefixCls = props.prefixCls,
22
22
  _onChange = props.onChange,
@@ -30,6 +30,8 @@ function Textarea(props) {
30
30
  extraCommands = _useContext.extraCommands,
31
31
  tabSize = _useContext.tabSize,
32
32
  defaultTabEnable = _useContext.defaultTabEnable,
33
+ autoFocusEnd = _useContext.autoFocusEnd,
34
+ textareaWarp = _useContext.textareaWarp,
33
35
  dispatch = _useContext.dispatch,
34
36
  otherStore = (0, _objectWithoutProperties2["default"])(_useContext, _excluded2);
35
37
  var textRef = _react["default"].useRef(null);
@@ -56,6 +58,21 @@ function Textarea(props) {
56
58
  }
57
59
  // eslint-disable-next-line react-hooks/exhaustive-deps
58
60
  }, []);
61
+ (0, _react.useEffect)(function () {
62
+ if (autoFocusEnd && textRef.current && textareaWarp) {
63
+ textRef.current.focus();
64
+ var length = textRef.current.value.length;
65
+ textRef.current.setSelectionRange(length, length);
66
+ setTimeout(function () {
67
+ if (textareaWarp) {
68
+ textareaWarp.scrollTop = textareaWarp.scrollHeight;
69
+ }
70
+ if (textRef.current) {
71
+ textRef.current.scrollTop = textRef.current.scrollHeight;
72
+ }
73
+ }, 0);
74
+ }
75
+ }, [textareaWarp]);
59
76
  var onKeyDown = function onKeyDown(e) {
60
77
  (0, _handleKeyDown["default"])(e, tabSize, defaultTabEnable);
61
78
  (0, _shortcuts["default"])(e, [].concat((0, _toConsumableArray2["default"])(commands || []), (0, _toConsumableArray2["default"])(extraCommands || [])), executeRef.current, dispatch, statesRef.current);
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports["default"] = handleKeyDown;
7
7
  var _InsertTextAtPosition = require("../../utils/InsertTextAtPosition");
8
8
  var _markdownUtils = require("../../utils/markdownUtils");
9
- var _commands = require("../../commands");
9
+ var _commands = require("../../commands/");
10
10
  /**
11
11
  * - `13` - `Enter`
12
12
  * - `9` - `Tab`
@@ -2,7 +2,7 @@ import React, { JSX } from 'react';
2
2
  import { ContextStore, ExecuteCommandState } from '../../Context';
3
3
  import { TextAreaProps } from './Textarea';
4
4
  import { IProps } from '../../Types';
5
- import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
5
+ import { TextAreaCommandOrchestrator, ICommand } from '../../commands/';
6
6
  import './index.less';
7
7
  type RenderTextareaHandle = {
8
8
  dispatch: ContextStore['dispatch'];
@@ -13,7 +13,7 @@ var _Context = require("../../Context");
13
13
  var _shortcuts = _interopRequireDefault(require("./shortcuts"));
14
14
  var _Markdown = _interopRequireDefault(require("./Markdown"));
15
15
  var _Textarea = _interopRequireDefault(require("./Textarea"));
16
- var _commands = require("../../commands");
16
+ var _commands = require("../../commands/");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
18
  var _excluded = ["prefixCls", "className", "onScroll", "renderTextarea"];
19
19
  function TextArea(props) {
@@ -2,7 +2,7 @@ import React, { JSX } from 'react';
2
2
  import { ContextStore, ExecuteCommandState } from '../../Context';
3
3
  import { TextAreaProps } from './Textarea';
4
4
  import { IProps } from '../../Types';
5
- import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
5
+ import { TextAreaCommandOrchestrator, ICommand } from '../../commands/';
6
6
  import './index.less';
7
7
  type RenderTextareaHandle = {
8
8
  dispatch: ContextStore['dispatch'];
@@ -12,7 +12,7 @@ var _react = _interopRequireWildcard(require("react"));
12
12
  var _Context = require("../../Context");
13
13
  var _shortcuts = _interopRequireDefault(require("./shortcuts"));
14
14
  var _Textarea = _interopRequireDefault(require("./Textarea"));
15
- var _commands = require("../../commands");
15
+ var _commands = require("../../commands/");
16
16
  var _jsxRuntime = require("react/jsx-runtime");
17
17
  var _excluded = ["prefixCls", "className", "onScroll", "renderTextarea"];
18
18
  function TextArea(props) {
@@ -1,3 +1,3 @@
1
- import { ICommand, TextAreaCommandOrchestrator } from '../../commands';
1
+ import { ICommand, TextAreaCommandOrchestrator } from '../../commands/';
2
2
  import { ContextStore, ExecuteCommandState } from '../../Context';
3
3
  export default function shortcutsHandle(e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands?: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState): void;
@@ -1,5 +1,5 @@
1
1
  import { IProps } from '../../Types';
2
- import { ICommand } from '../../commands';
2
+ import { ICommand } from '../../commands/';
3
3
  import './index.less';
4
4
  export interface IToolbarProps extends IProps {
5
5
  overflow?: boolean;
package/lib/index.d.ts CHANGED
@@ -1,8 +1,8 @@
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
- export * from './commands';
5
+ export * from './commands/';
6
6
  export * from './commands/group';
7
7
  export * from './utils/markdownUtils';
8
8
  export * from './utils/InsertTextAtPosition';
package/lib/index.js CHANGED
@@ -21,7 +21,7 @@ Object.keys(_Editor).forEach(function (key) {
21
21
  }
22
22
  });
23
23
  });
24
- var commands = _interopRequireWildcard(require("./commands"));
24
+ var commands = _interopRequireWildcard(require("./commands/"));
25
25
  exports.commands = commands;
26
26
  Object.keys(commands).forEach(function (key) {
27
27
  if (key === "default" || key === "__esModule") return;
@@ -1,8 +1,8 @@
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
- export * from './commands';
5
+ export * from './commands/';
6
6
  export * from './commands/group';
7
7
  export * from './utils/markdownUtils';
8
8
  export * from './utils/InsertTextAtPosition';
@@ -21,7 +21,7 @@ Object.keys(_Editor).forEach(function (key) {
21
21
  }
22
22
  });
23
23
  });
24
- var commands = _interopRequireWildcard(require("./commands"));
24
+ var commands = _interopRequireWildcard(require("./commands/"));
25
25
  exports.commands = commands;
26
26
  Object.keys(commands).forEach(function (key) {
27
27
  if (key === "default" || key === "__esModule") return;
@@ -1,5 +1,4 @@
1
- import { TextRange } from '../commands';
2
- import { TextAreaTextApi } from '../commands';
1
+ import { TextAreaTextApi, type TextRange } from '../commands';
3
2
  export interface TextSection {
4
3
  text: string;
5
4
  selection: TextRange;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "A markdown editor with preview, implemented with React.js and TypeScript.",
5
5
  "homepage": "https://uiwjs.github.io/react-md-editor/",
6
6
  "funding": "https://jaywcjlove.github.io/#/sponsor",
package/src/Context.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ICommand, TextAreaCommandOrchestrator } from './commands';
2
+ import { ICommand, TextAreaCommandOrchestrator } from './commands/';
3
3
  import { MDEditorProps } from './Types';
4
4
 
5
5
  export type PreviewType = 'live' | 'edit' | 'preview';
@@ -14,6 +14,7 @@ export interface ContextStore {
14
14
  fullscreen?: boolean;
15
15
  highlightEnable?: boolean;
16
16
  autoFocus?: boolean;
17
+ autoFocusEnd?: boolean;
17
18
  textarea?: HTMLTextAreaElement;
18
19
  commandOrchestrator?: TextAreaCommandOrchestrator;
19
20
  textareaWarp?: HTMLDivElement;
@@ -1,9 +1,9 @@
1
1
  import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
2
2
  import MarkdownPreview from '@uiw/react-markdown-preview/nohighlight';
3
3
  import TextArea from './components/TextArea/index.nohighlight';
4
- import { ToolbarVisibility } from './components/Toolbar';
5
- import DragBar from './components/DragBar';
6
- import { getCommands, getExtraCommands, ICommand, TextState, TextAreaCommandOrchestrator } from './commands';
4
+ import { ToolbarVisibility } from './components/Toolbar/';
5
+ import DragBar from './components/DragBar/';
6
+ import { getCommands, getExtraCommands, ICommand, TextState, TextAreaCommandOrchestrator } from './commands/';
7
7
  import { reducer, EditorContext, ContextStore } from './Context';
8
8
  import type { MDEditorProps } from './Types';
9
9
 
@@ -38,6 +38,7 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
38
38
  maxHeight = 1200,
39
39
  minHeight = 100,
40
40
  autoFocus,
41
+ autoFocusEnd = false,
41
42
  tabSize = 2,
42
43
  defaultTabEnable = false,
43
44
  onChange,
@@ -117,6 +118,7 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
117
118
  );
118
119
  // eslint-disable-next-line react-hooks/exhaustive-deps
119
120
  useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);
121
+ useMemo(() => autoFocusEnd !== state.autoFocusEnd && dispatch({ autoFocusEnd: autoFocusEnd }), [autoFocusEnd]);
120
122
  useMemo(
121
123
  () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),
122
124
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/src/Editor.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, Fragment } from 'react';
2
2
  import MarkdownPreview from '@uiw/react-markdown-preview';
3
- import TextArea from './components/TextArea';
4
- import { ToolbarVisibility } from './components/Toolbar';
5
- import DragBar from './components/DragBar';
6
- import { getCommands, getExtraCommands, ICommand, TextState, TextAreaCommandOrchestrator } from './commands';
3
+ import { ToolbarVisibility } from './components/Toolbar/';
4
+ import TextArea from './components/TextArea/';
5
+ import DragBar from './components/DragBar/';
6
+ import { getCommands, getExtraCommands, ICommand, TextState, TextAreaCommandOrchestrator } from './commands/';
7
7
  import { reducer, EditorContext, ContextStore } from './Context';
8
8
  import type { MDEditorProps } from './Types';
9
9
 
@@ -38,6 +38,7 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
38
38
  maxHeight = 1200,
39
39
  minHeight = 100,
40
40
  autoFocus,
41
+ autoFocusEnd = false,
41
42
  tabSize = 2,
42
43
  defaultTabEnable = false,
43
44
  onChange,
@@ -117,6 +118,7 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
117
118
  );
118
119
  // eslint-disable-next-line react-hooks/exhaustive-deps
119
120
  useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);
121
+ useMemo(() => autoFocusEnd !== state.autoFocusEnd && dispatch({ autoFocusEnd: autoFocusEnd }), [autoFocusEnd]);
120
122
  useMemo(
121
123
  () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),
122
124
  // eslint-disable-next-line react-hooks/exhaustive-deps