@uiw/react-md-editor 3.19.4 → 3.19.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.
- package/dist/mdeditor.js +86 -652
- package/dist/mdeditor.min.js +1 -1
- package/esm/commands/preview.js +3 -0
- package/esm/commands/preview.js.map +4 -2
- package/esm/components/DragBar/index.js +30 -7
- package/esm/components/DragBar/index.js.map +9 -5
- package/esm/components/TextArea/Markdown.js +26 -25
- package/esm/components/TextArea/Markdown.js.map +6 -3
- package/lib/commands/preview.js +3 -0
- package/lib/commands/preview.js.map +4 -2
- package/lib/components/DragBar/index.js +30 -7
- package/lib/components/DragBar/index.js.map +11 -7
- package/lib/components/TextArea/Markdown.js +25 -24
- package/lib/components/TextArea/Markdown.js.map +6 -3
- package/package.json +1 -1
- package/src/commands/preview.tsx +3 -0
- package/src/components/DragBar/index.tsx +23 -9
- package/src/components/TextArea/Markdown.tsx +21 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.6",
|
|
4
4
|
"description": "A markdown editor with preview, implemented with React.js and TypeScript.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-md-editor/",
|
|
6
6
|
"author": "kenny wang <wowohoo@qq.com>",
|
package/src/commands/preview.tsx
CHANGED
|
@@ -27,6 +27,7 @@ export const codePreview: ICommand = {
|
|
|
27
27
|
executeCommandState?: ExecuteCommandState,
|
|
28
28
|
shortcuts?: string[],
|
|
29
29
|
) => {
|
|
30
|
+
api.textArea.focus();
|
|
30
31
|
if (shortcuts && dispatch && executeCommandState) {
|
|
31
32
|
dispatch({ preview: 'preview' });
|
|
32
33
|
}
|
|
@@ -55,6 +56,7 @@ export const codeEdit: ICommand = {
|
|
|
55
56
|
executeCommandState?: ExecuteCommandState,
|
|
56
57
|
shortcuts?: string[],
|
|
57
58
|
) => {
|
|
59
|
+
api.textArea.focus();
|
|
58
60
|
if (shortcuts && dispatch && executeCommandState) {
|
|
59
61
|
dispatch({ preview: 'edit' });
|
|
60
62
|
}
|
|
@@ -83,6 +85,7 @@ export const codeLive: ICommand = {
|
|
|
83
85
|
executeCommandState?: ExecuteCommandState,
|
|
84
86
|
shortcuts?: string[],
|
|
85
87
|
) => {
|
|
88
|
+
api.textArea.focus();
|
|
86
89
|
if (shortcuts && dispatch && executeCommandState) {
|
|
87
90
|
dispatch({ preview: 'live' });
|
|
88
91
|
}
|
|
@@ -11,34 +11,48 @@ export interface IDragBarProps extends IProps {
|
|
|
11
11
|
|
|
12
12
|
const DragBar: React.FC<IDragBarProps> = (props) => {
|
|
13
13
|
const { prefixCls, onChange } = props || {};
|
|
14
|
+
const $dom = useRef<HTMLDivElement>(null);
|
|
14
15
|
const dragRef = useRef<{ height: number; dragY: number }>();
|
|
15
|
-
function handleMouseMove(event:
|
|
16
|
+
function handleMouseMove(event: Event) {
|
|
16
17
|
if (dragRef.current) {
|
|
17
|
-
const
|
|
18
|
+
const clientY =
|
|
19
|
+
(event as unknown as MouseEvent).clientY || (event as unknown as TouchEvent).changedTouches[0]?.clientY;
|
|
20
|
+
const newHeight = dragRef.current.height + clientY - dragRef.current.dragY;
|
|
18
21
|
if (newHeight >= props.minHeight && newHeight <= props.maxHeight) {
|
|
19
|
-
onChange && onChange(dragRef.current.height + (
|
|
22
|
+
onChange && onChange(dragRef.current.height + (clientY - dragRef.current.dragY));
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
function handleMouseUp() {
|
|
24
27
|
dragRef.current = undefined;
|
|
28
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
29
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
30
|
+
$dom.current?.removeEventListener('touchmove', handleMouseMove);
|
|
31
|
+
$dom.current?.removeEventListener('touchend', handleMouseUp);
|
|
25
32
|
}
|
|
26
|
-
function handleMouseDown(event:
|
|
33
|
+
function handleMouseDown(event: Event) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
const clientY =
|
|
36
|
+
(event as unknown as MouseEvent).clientY || (event as unknown as TouchEvent).changedTouches[0]?.clientY;
|
|
27
37
|
dragRef.current = {
|
|
28
38
|
height: props.height,
|
|
29
|
-
dragY:
|
|
39
|
+
dragY: clientY,
|
|
30
40
|
};
|
|
41
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
42
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
43
|
+
$dom.current?.addEventListener('touchmove', handleMouseMove, { passive: false });
|
|
44
|
+
$dom.current?.addEventListener('touchend', handleMouseUp, { passive: false });
|
|
31
45
|
}
|
|
32
46
|
|
|
33
47
|
useEffect(() => {
|
|
34
48
|
if (document) {
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
$dom.current?.addEventListener('touchstart', handleMouseDown, { passive: false });
|
|
50
|
+
$dom.current?.addEventListener('mousedown', handleMouseDown);
|
|
37
51
|
}
|
|
38
52
|
return () => {
|
|
39
53
|
if (document) {
|
|
54
|
+
$dom.current?.removeEventListener('touchstart', handleMouseDown);
|
|
40
55
|
document.removeEventListener('mousemove', handleMouseMove);
|
|
41
|
-
document.removeEventListener('mouseup', handleMouseUp);
|
|
42
56
|
}
|
|
43
57
|
};
|
|
44
58
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -55,7 +69,7 @@ const DragBar: React.FC<IDragBarProps> = (props) => {
|
|
|
55
69
|
[],
|
|
56
70
|
);
|
|
57
71
|
return (
|
|
58
|
-
<div className={`${prefixCls}-bar`}
|
|
72
|
+
<div className={`${prefixCls}-bar`} ref={$dom}>
|
|
59
73
|
{svg}
|
|
60
74
|
</div>
|
|
61
75
|
);
|
|
@@ -6,7 +6,7 @@ import { EditorContext } from '../../Context';
|
|
|
6
6
|
|
|
7
7
|
function html2Escape(sHtml: string) {
|
|
8
8
|
return sHtml
|
|
9
|
-
.replace(/```(
|
|
9
|
+
.replace(/```(\w+)?([\s\S]*?)(\s.+)?```/g, (str: string) => {
|
|
10
10
|
return str.replace(
|
|
11
11
|
/[<&"]/g,
|
|
12
12
|
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record<string, string>)[c]),
|
|
@@ -30,28 +30,27 @@ export default function Markdown(props: MarkdownProps) {
|
|
|
30
30
|
}
|
|
31
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
32
|
}, []);
|
|
33
|
+
if (!markdown) {
|
|
34
|
+
return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
|
|
35
|
+
}
|
|
36
|
+
let mdStr = `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
|
|
37
|
+
String.raw`${markdown}`,
|
|
38
|
+
)}\n</code></pre>`;
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
if (!markdown) {
|
|
36
|
-
return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
|
|
37
|
-
}
|
|
38
|
-
let mdStr = `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
|
|
39
|
-
markdown,
|
|
40
|
-
)}\n</code></pre>`;
|
|
40
|
+
console.log('markdown::', markdown);
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
if (highlightEnable) {
|
|
43
|
+
try {
|
|
44
|
+
mdStr = rehype()
|
|
45
|
+
.data('settings', { fragment: true })
|
|
46
|
+
.use(rehypePrism, { ignoreMissing: true })
|
|
47
|
+
.processSync(mdStr)
|
|
48
|
+
.toString();
|
|
49
|
+
} catch (error) {}
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}, [markdown, preRef, prefixCls]);
|
|
52
|
+
return React.createElement('div', {
|
|
53
|
+
className: 'wmde-markdown-color',
|
|
54
|
+
dangerouslySetInnerHTML: { __html: mdStr || '' },
|
|
55
|
+
});
|
|
57
56
|
}
|