@uiw/react-md-editor 3.24.0 → 3.25.0

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 (62) hide show
  1. package/README.md +50 -5
  2. package/dist/mdeditor.js +1835 -1807
  3. package/dist/mdeditor.min.js +1 -1
  4. package/esm/Context.d.ts +1 -1
  5. package/esm/Editor.d.ts +4 -149
  6. package/esm/Editor.js +0 -1
  7. package/esm/Editor.nohighlight.d.ts +12 -0
  8. package/esm/Editor.nohighlight.js +255 -0
  9. package/esm/Types.d.ts +148 -0
  10. package/esm/Types.js +1 -0
  11. package/esm/commands/index.d.ts +4 -1
  12. package/esm/commands/index.js +2 -1
  13. package/esm/components/DragBar/index.d.ts +1 -1
  14. package/esm/components/TextArea/Markdown.d.ts +1 -1
  15. package/esm/components/TextArea/Textarea.d.ts +1 -1
  16. package/esm/components/TextArea/handleKeyDown.js +1 -3
  17. package/esm/components/TextArea/index.d.ts +1 -1
  18. package/esm/components/TextArea/index.nohighlight.d.ts +27 -0
  19. package/esm/components/TextArea/index.nohighlight.js +93 -0
  20. package/esm/components/Toolbar/Child.d.ts +1 -1
  21. package/esm/components/Toolbar/index.d.ts +1 -1
  22. package/esm/index.d.ts +2 -0
  23. package/esm/index.js +2 -0
  24. package/esm/index.nohighlight.d.ts +13 -0
  25. package/esm/index.nohighlight.js +13 -0
  26. package/lib/Context.d.ts +1 -1
  27. package/lib/Editor.d.ts +4 -149
  28. package/lib/Editor.nohighlight.d.ts +12 -0
  29. package/lib/Editor.nohighlight.js +317 -0
  30. package/lib/Types.d.ts +148 -0
  31. package/lib/Types.js +1 -0
  32. package/lib/commands/index.d.ts +4 -1
  33. package/lib/commands/index.js +19 -0
  34. package/lib/components/DragBar/index.d.ts +1 -1
  35. package/lib/components/TextArea/Markdown.d.ts +1 -1
  36. package/lib/components/TextArea/Textarea.d.ts +1 -1
  37. package/lib/components/TextArea/handleKeyDown.js +1 -3
  38. package/lib/components/TextArea/index.d.ts +1 -1
  39. package/lib/components/TextArea/index.nohighlight.d.ts +27 -0
  40. package/lib/components/TextArea/index.nohighlight.js +98 -0
  41. package/lib/components/Toolbar/Child.d.ts +1 -1
  42. package/lib/components/Toolbar/index.d.ts +1 -1
  43. package/lib/index.d.ts +2 -0
  44. package/lib/index.js +12 -0
  45. package/lib/index.nohighlight.d.ts +13 -0
  46. package/lib/index.nohighlight.js +98 -0
  47. package/package.json +16 -2
  48. package/src/Context.tsx +1 -1
  49. package/src/Editor.nohighlight.tsx +264 -0
  50. package/src/Editor.tsx +5 -151
  51. package/src/Types.ts +151 -0
  52. package/src/commands/index.ts +4 -0
  53. package/src/components/DragBar/index.tsx +1 -1
  54. package/src/components/TextArea/Markdown.tsx +2 -2
  55. package/src/components/TextArea/Textarea.tsx +1 -1
  56. package/src/components/TextArea/handleKeyDown.tsx +5 -3
  57. package/src/components/TextArea/index.nohighlight.tsx +109 -0
  58. package/src/components/TextArea/index.tsx +1 -1
  59. package/src/components/Toolbar/Child.tsx +1 -1
  60. package/src/components/Toolbar/index.tsx +1 -1
  61. package/src/index.nohighlight.tsx +16 -0
  62. package/src/index.tsx +2 -0
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { ContextStore, ExecuteCommandState } from '../../Context';
3
+ import { TextAreaProps } from './Textarea';
4
+ import { IProps } from '../../Types';
5
+ import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
6
+ import './index.less';
7
+ type RenderTextareaHandle = {
8
+ dispatch: ContextStore['dispatch'];
9
+ onChange?: TextAreaProps['onChange'];
10
+ useContext?: {
11
+ commands: ContextStore['commands'];
12
+ extraCommands: ContextStore['extraCommands'];
13
+ commandOrchestrator?: TextAreaCommandOrchestrator;
14
+ };
15
+ shortcuts?: (e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>, commands: ICommand[], commandOrchestrator?: TextAreaCommandOrchestrator, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState) => void;
16
+ };
17
+ export interface ITextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>, IProps {
18
+ value?: string;
19
+ onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
20
+ renderTextarea?: (props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>, opts: RenderTextareaHandle) => JSX.Element;
21
+ }
22
+ export type TextAreaRef = {
23
+ text?: HTMLTextAreaElement;
24
+ warp?: HTMLDivElement;
25
+ };
26
+ export default function TextArea(props: ITextAreaProps): import("react/jsx-runtime").JSX.Element;
27
+ export {};
@@ -0,0 +1,93 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["prefixCls", "className", "onScroll", "renderTextarea"];
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';
9
+ import "./index.css";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ export default function TextArea(props) {
12
+ var _ref = props || {},
13
+ {
14
+ prefixCls,
15
+ className,
16
+ onScroll,
17
+ renderTextarea
18
+ } = _ref,
19
+ otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
20
+ var {
21
+ markdown,
22
+ scrollTop,
23
+ commands,
24
+ extraCommands,
25
+ dispatch
26
+ } = useContext(EditorContext);
27
+ var textRef = React.useRef(null);
28
+ var executeRef = React.useRef();
29
+ var warp = /*#__PURE__*/React.createRef();
30
+ useEffect(() => {
31
+ var state = {};
32
+ if (warp.current) {
33
+ state.textareaWarp = warp.current || undefined;
34
+ warp.current.scrollTop = scrollTop || 0;
35
+ }
36
+ if (dispatch) {
37
+ dispatch(_extends({}, state));
38
+ }
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, []);
41
+ useEffect(() => {
42
+ if (textRef.current && dispatch) {
43
+ var _commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);
44
+ executeRef.current = _commandOrchestrator;
45
+ dispatch({
46
+ textarea: textRef.current,
47
+ commandOrchestrator: _commandOrchestrator
48
+ });
49
+ }
50
+ // eslint-disable-next-line react-hooks/exhaustive-deps
51
+ }, []);
52
+ var textStyle = {
53
+ WebkitTextFillColor: 'initial',
54
+ overflow: 'auto'
55
+ };
56
+ return /*#__PURE__*/_jsx("div", {
57
+ ref: warp,
58
+ className: prefixCls + "-area " + (className || ''),
59
+ onScroll: onScroll,
60
+ children: /*#__PURE__*/_jsx("div", {
61
+ className: prefixCls + "-text",
62
+ children: renderTextarea ? /*#__PURE__*/React.cloneElement(renderTextarea(_extends({}, otherProps, {
63
+ value: markdown,
64
+ autoComplete: 'off',
65
+ autoCorrect: 'off',
66
+ spellCheck: 'false',
67
+ autoCapitalize: 'off',
68
+ className: prefixCls + "-text-input",
69
+ style: {
70
+ WebkitTextFillColor: 'inherit',
71
+ overflow: 'auto'
72
+ }
73
+ }), {
74
+ dispatch,
75
+ onChange: otherProps.onChange,
76
+ shortcuts,
77
+ useContext: {
78
+ commands,
79
+ extraCommands,
80
+ commandOrchestrator: executeRef.current
81
+ }
82
+ }), {
83
+ ref: textRef
84
+ }) : /*#__PURE__*/_jsx(Fragment, {
85
+ children: /*#__PURE__*/_jsx(Textarea, _extends({
86
+ prefixCls: prefixCls
87
+ }, otherProps, {
88
+ style: textStyle
89
+ }))
90
+ })
91
+ })
92
+ });
93
+ }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import './Child.less';
3
- import { IToolbarProps } from './';
3
+ import { type IToolbarProps } from './';
4
4
  export type ChildProps = IToolbarProps & {
5
5
  children?: JSX.Element;
6
6
  groupName?: string;
@@ -1,4 +1,4 @@
1
- import { IProps } from '../../Editor';
1
+ import { IProps } from '../../Types';
2
2
  import { ICommand } from '../../commands';
3
3
  import './index.less';
4
4
  export interface IToolbarProps extends IProps {
package/esm/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import MDEditor from './Editor';
2
2
  import * as commands from './commands';
3
3
  import * as MarkdownUtil from './utils/markdownUtils';
4
+ import './index.less';
4
5
  export * from './commands';
5
6
  export * from './commands/group';
6
7
  export * from './utils/markdownUtils';
7
8
  export * from './utils/InsertTextAtPosition';
8
9
  export * from './Editor';
9
10
  export * from './Context';
11
+ export * from './Types';
10
12
  export { MarkdownUtil, commands };
11
13
  export default MDEditor;
package/esm/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import MDEditor from './Editor';
2
2
  import * as commands from './commands';
3
3
  import * as MarkdownUtil from './utils/markdownUtils';
4
+ import "./index.css";
4
5
  export * from './commands';
5
6
  export * from './commands/group';
6
7
  export * from './utils/markdownUtils';
7
8
  export * from './utils/InsertTextAtPosition';
8
9
  export * from './Editor';
9
10
  export * from './Context';
11
+ export * from './Types';
10
12
  export { MarkdownUtil, commands };
11
13
  export default MDEditor;
@@ -0,0 +1,13 @@
1
+ import MDEditor from './Editor.nohighlight';
2
+ import * as commands from './commands';
3
+ import * as MarkdownUtil from './utils/markdownUtils';
4
+ import './index.less';
5
+ export * from './commands';
6
+ export * from './commands/group';
7
+ export * from './utils/markdownUtils';
8
+ export * from './utils/InsertTextAtPosition';
9
+ export * from './Editor.nohighlight';
10
+ export * from './Context';
11
+ export * from './Types';
12
+ export { MarkdownUtil, commands };
13
+ export default MDEditor;
@@ -0,0 +1,13 @@
1
+ import MDEditor from './Editor.nohighlight';
2
+ import * as commands from './commands';
3
+ import * as MarkdownUtil from './utils/markdownUtils';
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.nohighlight';
10
+ export * from './Context';
11
+ export * from './Types';
12
+ export { MarkdownUtil, commands };
13
+ export default MDEditor;
package/lib/Context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ICommand, TextAreaCommandOrchestrator } from './commands';
3
- import { MDEditorProps } from './Editor';
3
+ import { MDEditorProps } from './Types';
4
4
  export type PreviewType = 'live' | 'edit' | 'preview';
5
5
  export interface ContextStore {
6
6
  components?: MDEditorProps['components'];
package/lib/Editor.d.ts CHANGED
@@ -1,152 +1,7 @@
1
- import React, { CSSProperties } from 'react';
2
- import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
3
- import { ITextAreaProps } from './components/TextArea';
4
- import { ICommand, TextState } from './commands';
5
- import { ContextStore, PreviewType } from './Context';
6
- import './index.less';
7
- export interface IProps {
8
- prefixCls?: string;
9
- className?: string;
10
- }
11
- export interface Statistics extends TextState {
12
- /** total length of the document */
13
- length: number;
14
- /** Get the number of lines in the editor. */
15
- lineCount: number;
16
- }
17
- export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {
18
- /**
19
- * The Markdown value.
20
- */
21
- value?: string;
22
- /**
23
- * Event handler for the `onChange` event.
24
- */
25
- onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;
26
- /**
27
- * editor height change listener
28
- */
29
- onHeightChange?: (value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore) => void;
30
- /** Some data on the statistics editor. */
31
- onStatistics?: (data: Statistics) => void;
32
- /**
33
- * Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.
34
- * it will be set to true when either the source `textarea` is focused,
35
- * or it has an `autofocus` attribute and no other element is focused.
36
- */
37
- autoFocus?: ITextAreaProps['autoFocus'];
38
- /**
39
- * The height of the editor.
40
- * ⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
41
- */
42
- height?: CSSProperties['height'];
43
- /**
44
- * Custom toolbar heigth
45
- * @default 29px
46
- *
47
- * @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427
48
- *
49
- */
50
- toolbarHeight?: number;
51
- /**
52
- * Show drag and drop tool. Set the height of the editor.
53
- */
54
- visibleDragbar?: boolean;
55
- /**
56
- * @deprecated use `visibleDragbar`
57
- */
58
- visiableDragbar?: boolean;
59
- /**
60
- * Show markdown preview.
61
- */
62
- preview?: PreviewType;
63
- /**
64
- * Full screen display editor.
65
- */
66
- fullscreen?: boolean;
67
- /**
68
- * Disable `fullscreen` setting body styles
69
- */
70
- overflow?: boolean;
71
- /**
72
- * Maximum drag height. `visibleDragbar=true`
73
- */
74
- maxHeight?: number;
75
- /**
76
- * Minimum drag height. `visibleDragbar=true`
77
- */
78
- minHeight?: number;
79
- /**
80
- * This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.
81
- */
82
- previewOptions?: Omit<MarkdownPreviewProps, 'source'>;
83
- /**
84
- * Set the `textarea` related props.
85
- */
86
- textareaProps?: ITextAreaProps;
87
- /**
88
- * Use div to replace TextArea or re-render TextArea
89
- * @deprecated Please use ~~`renderTextarea`~~ -> `components`
90
- */
91
- renderTextarea?: ITextAreaProps['renderTextarea'];
92
- /**
93
- * re-render element
94
- */
95
- components?: {
96
- /** Use div to replace TextArea or re-render TextArea */
97
- textarea?: ITextAreaProps['renderTextarea'];
98
- /**
99
- * Override the default command element
100
- * _`toolbar`_ < _`command[].render`_
101
- */
102
- toolbar?: ICommand['render'];
103
- /** Custom markdown preview */
104
- preview?: (source: string, state: ContextStore, dispath: React.Dispatch<ContextStore>) => JSX.Element;
105
- };
106
- /** Theme configuration */
107
- 'data-color-mode'?: 'light' | 'dark';
108
- /**
109
- * Disable editing area code highlighting. The value is `false`, which increases the editing speed.
110
- * @default true
111
- */
112
- highlightEnable?: boolean;
113
- /**
114
- * The number of characters to insert when pressing tab key.
115
- * Default `2` spaces.
116
- */
117
- tabSize?: number;
118
- /**
119
- * If `false`, the `tab` key inserts a tab character into the textarea. If `true`, the `tab` key executes default behavior e.g. focus shifts to next element.
120
- */
121
- defaultTabEnable?: boolean;
122
- /**
123
- * You can create your own commands or reuse existing commands.
124
- */
125
- commands?: ICommand[];
126
- /**
127
- * Filter or modify your commands.
128
- * https://github.com/uiwjs/react-md-editor/issues/296
129
- */
130
- commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;
131
- /**
132
- * You can create your own commands or reuse existing commands.
133
- */
134
- extraCommands?: ICommand[];
135
- /**
136
- * Hide the tool bar
137
- */
138
- hideToolbar?: boolean;
139
- /** Whether to enable scrolling */
140
- enableScroll?: boolean;
141
- /** Toolbar on bottom */
142
- toolbarBottom?: boolean;
143
- /**
144
- * The **`direction`** property sets the direction of text, table columns, and horizontal overflow. Use `rtl` for languages written from right to left (like Hebrew or Arabic), and `ltr` for those written from left to right (like English and most other languages).
145
- *
146
- * https://github.com/uiwjs/react-md-editor/issues/462
147
- */
148
- direction?: CSSProperties['direction'];
149
- }
1
+ import React from 'react';
2
+ import MarkdownPreview from '@uiw/react-markdown-preview';
3
+ import { ContextStore } from './Context';
4
+ import type { MDEditorProps } from './Types';
150
5
  export interface RefMDEditor extends ContextStore {
151
6
  }
152
7
  declare const InternalMDEditor: React.ForwardRefExoticComponent<MDEditorProps & React.RefAttributes<RefMDEditor>>;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import MarkdownPreview from '@uiw/react-markdown-preview/nohighlight';
3
+ import { ContextStore } from './Context';
4
+ import type { MDEditorProps } from './Types';
5
+ export interface RefMDEditor extends ContextStore {
6
+ }
7
+ declare const InternalMDEditor: React.ForwardRefExoticComponent<MDEditorProps & React.RefAttributes<RefMDEditor>>;
8
+ type EditorComponent = typeof InternalMDEditor & {
9
+ Markdown: typeof MarkdownPreview;
10
+ };
11
+ declare const Editor: EditorComponent;
12
+ export default Editor;