@uiw/react-md-editor 3.25.5 → 4.0.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.
- package/README.md +23 -11
- package/commands.d.ts +148 -0
- package/dist/mdeditor.css +1 -1
- package/dist/mdeditor.js +33885 -32579
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/dist/mdeditor.min.js.LICENSE.txt +0 -17
- package/esm/components/TextArea/Markdown.js +4 -1
- package/esm/components/TextArea/index.js +2 -2
- package/esm/components/TextArea/index.nohighlight.js +2 -2
- package/esm/components/Toolbar/index.css +1 -1
- package/esm/components/Toolbar/index.less +1 -1
- package/lib/components/TextArea/Markdown.js +4 -1
- package/lib/components/TextArea/index.js +2 -2
- package/lib/components/TextArea/index.nohighlight.js +2 -2
- package/lib/components/Toolbar/index.less +1 -1
- package/markdown-editor.css +1 -1
- package/package.json +4 -3
- package/src/components/TextArea/Markdown.tsx +2 -0
- package/src/components/Toolbar/index.less +1 -1
package/README.md
CHANGED
|
@@ -718,16 +718,26 @@ const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
|
|
|
718
718
|
const Code = ({ inline, children = [], className, ...props }) => {
|
|
719
719
|
const demoid = useRef(`dome${randomid()}`);
|
|
720
720
|
const [container, setContainer] = useState(null);
|
|
721
|
-
const isMermaid =
|
|
722
|
-
|
|
721
|
+
const isMermaid =
|
|
722
|
+
className && /^language-mermaid/.test(className.toLocaleLowerCase());
|
|
723
|
+
const code = children
|
|
724
|
+
? getCodeString(props.node.children)
|
|
725
|
+
: children[0] || "";
|
|
726
|
+
|
|
723
727
|
useEffect(() => {
|
|
724
|
-
if (container && isMermaid) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
728
|
+
if (container && isMermaid && demoid.current && code) {
|
|
729
|
+
mermaid
|
|
730
|
+
.render(demoid.current, code)
|
|
731
|
+
.then(({ svg, bindFunctions }) => {
|
|
732
|
+
console.log("svg:", svg);
|
|
733
|
+
container.innerHTML = svg;
|
|
734
|
+
if (bindFunctions) {
|
|
735
|
+
bindFunctions(container);
|
|
736
|
+
}
|
|
737
|
+
})
|
|
738
|
+
.catch((error) => {
|
|
739
|
+
console.log("error:", error);
|
|
740
|
+
});
|
|
731
741
|
}
|
|
732
742
|
}, [container, isMermaid, code, demoid]);
|
|
733
743
|
|
|
@@ -741,11 +751,11 @@ const Code = ({ inline, children = [], className, ...props }) => {
|
|
|
741
751
|
return (
|
|
742
752
|
<Fragment>
|
|
743
753
|
<code id={demoid.current} style={{ display: "none" }} />
|
|
744
|
-
<code ref={refElement} data-name="mermaid" />
|
|
754
|
+
<code className={className} ref={refElement} data-name="mermaid" />
|
|
745
755
|
</Fragment>
|
|
746
756
|
);
|
|
747
757
|
}
|
|
748
|
-
return <code>{children}</code>;
|
|
758
|
+
return <code className={className}>{children}</code>;
|
|
749
759
|
};
|
|
750
760
|
|
|
751
761
|
export default function App() {
|
|
@@ -794,6 +804,8 @@ import "@uiw/react-markdown-preview/markdown.css";
|
|
|
794
804
|
import dynamic from "next/dynamic";
|
|
795
805
|
import { useState } from "react";
|
|
796
806
|
|
|
807
|
+
import * as commands from "@uiw/react-md-editor/commands"
|
|
808
|
+
|
|
797
809
|
const MDEditor = dynamic(
|
|
798
810
|
() => import("@uiw/react-md-editor"),
|
|
799
811
|
{ ssr: false }
|
package/commands.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
declare module '@uiw/react-md-editor/commands' {
|
|
2
|
+
import { ContextStore, ExecuteCommandState } from '@uiw/react-md-editor/esm/Context';
|
|
3
|
+
import { bold } from '@uiw/react-md-editor/esm/commands/bold';
|
|
4
|
+
import { code, codeBlock } from '@uiw/react-md-editor/esm/commands/code';
|
|
5
|
+
import { comment } from '@uiw/react-md-editor/esm/commands/comment';
|
|
6
|
+
import { divider } from '@uiw/react-md-editor/esm/commands/divider';
|
|
7
|
+
import { fullscreen } from '@uiw/react-md-editor/esm/commands/fullscreen';
|
|
8
|
+
import { group } from '@uiw/react-md-editor/esm/commands/group';
|
|
9
|
+
import { hr } from '@uiw/react-md-editor/esm/commands/hr';
|
|
10
|
+
import { image } from '@uiw/react-md-editor/esm/commands/image';
|
|
11
|
+
import { italic } from '@uiw/react-md-editor/esm/commands/italic';
|
|
12
|
+
import { link } from '@uiw/react-md-editor/esm/commands/link';
|
|
13
|
+
import { checkedListCommand, orderedListCommand, unorderedListCommand } from '@uiw/react-md-editor/esm/commands/list';
|
|
14
|
+
import { codeEdit, codeLive, codePreview } from '@uiw/react-md-editor/esm/commands/preview';
|
|
15
|
+
import { quote } from '@uiw/react-md-editor/esm/commands/quote';
|
|
16
|
+
import { strikethrough } from '@uiw/react-md-editor/esm/commands/strikeThrough';
|
|
17
|
+
import { title } from '@uiw/react-md-editor/esm/commands/title';
|
|
18
|
+
import { title1 } from '@uiw/react-md-editor/esm/commands/title1';
|
|
19
|
+
import { title2 } from '@uiw/react-md-editor/esm/commands/title2';
|
|
20
|
+
import { title3 } from '@uiw/react-md-editor/esm/commands/title3';
|
|
21
|
+
import { title4 } from '@uiw/react-md-editor/esm/commands/title4';
|
|
22
|
+
import { title5 } from '@uiw/react-md-editor/esm/commands/title5';
|
|
23
|
+
import { title6 } from '@uiw/react-md-editor/esm/commands/title6';
|
|
24
|
+
import { table } from '@uiw/react-md-editor/esm/commands/table';
|
|
25
|
+
import { issue } from '@uiw/react-md-editor/esm/commands/issue';
|
|
26
|
+
import { help } from '@uiw/react-md-editor/esm/commands/help';
|
|
27
|
+
export interface CommandOrchestrator {
|
|
28
|
+
executeCommand(command: ICommand): void;
|
|
29
|
+
}
|
|
30
|
+
export interface ICommandChildHandle<T = string> extends ICommandBase<T> {
|
|
31
|
+
children?: (handle: {
|
|
32
|
+
close: () => void;
|
|
33
|
+
execute: () => void;
|
|
34
|
+
getState?: TextAreaCommandOrchestrator['getState'];
|
|
35
|
+
textApi?: TextAreaTextApi;
|
|
36
|
+
dispatch?: React.Dispatch<ContextStore>;
|
|
37
|
+
}) => React.ReactElement;
|
|
38
|
+
}
|
|
39
|
+
export interface ICommandChildCommands<T = string> extends ICommandBase<T> {
|
|
40
|
+
children?: Array<ICommand<T>>;
|
|
41
|
+
}
|
|
42
|
+
export interface ICommandBase<T> {
|
|
43
|
+
parent?: ICommand<any>;
|
|
44
|
+
keyCommand?: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
shortcuts?: string;
|
|
47
|
+
groupName?: string;
|
|
48
|
+
icon?: React.ReactElement;
|
|
49
|
+
value?: string;
|
|
50
|
+
prefix?: string;
|
|
51
|
+
suffix?: string;
|
|
52
|
+
position?: 'right';
|
|
53
|
+
liProps?: React.LiHTMLAttributes<HTMLLIElement>;
|
|
54
|
+
buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | null;
|
|
55
|
+
render?: (
|
|
56
|
+
command: ICommand<T>,
|
|
57
|
+
disabled: boolean,
|
|
58
|
+
executeCommand: (command: ICommand<T>, name?: string) => void,
|
|
59
|
+
index: number,
|
|
60
|
+
) => void | undefined | null | React.ReactElement;
|
|
61
|
+
execute?: (
|
|
62
|
+
state: ExecuteState,
|
|
63
|
+
api: TextAreaTextApi,
|
|
64
|
+
dispatch?: React.Dispatch<ContextStore>,
|
|
65
|
+
executeCommandState?: ExecuteCommandState,
|
|
66
|
+
shortcuts?: string[],
|
|
67
|
+
) => void;
|
|
68
|
+
}
|
|
69
|
+
export type ExecuteState = TextState & {
|
|
70
|
+
command: ICommand;
|
|
71
|
+
};
|
|
72
|
+
export type ICommand<T = string> = ICommandChildCommands<T> | ICommandChildHandle<T>;
|
|
73
|
+
export interface TextRange {
|
|
74
|
+
start: number;
|
|
75
|
+
end: number;
|
|
76
|
+
}
|
|
77
|
+
export interface TextState {
|
|
78
|
+
text: string;
|
|
79
|
+
selectedText: string;
|
|
80
|
+
selection: TextRange;
|
|
81
|
+
}
|
|
82
|
+
const getCommands: () => ICommand[];
|
|
83
|
+
const getExtraCommands: () => ICommand[];
|
|
84
|
+
function getStateFromTextArea(textArea: HTMLTextAreaElement): TextState;
|
|
85
|
+
class TextAreaTextApi {
|
|
86
|
+
textArea: HTMLTextAreaElement;
|
|
87
|
+
constructor(textArea: HTMLTextAreaElement);
|
|
88
|
+
/**
|
|
89
|
+
* Replaces the current selection with the new text. This will make the new selectedText to be empty, the
|
|
90
|
+
* selection start and selection end will be the same and will both point to the end
|
|
91
|
+
* @param text Text that should replace the current selection
|
|
92
|
+
*/
|
|
93
|
+
replaceSelection(text: string): TextState;
|
|
94
|
+
/**
|
|
95
|
+
* Selects the specified text range
|
|
96
|
+
* @param selection
|
|
97
|
+
*/
|
|
98
|
+
setSelectionRange(selection: TextRange): TextState;
|
|
99
|
+
}
|
|
100
|
+
class TextAreaCommandOrchestrator implements CommandOrchestrator {
|
|
101
|
+
textArea: HTMLTextAreaElement;
|
|
102
|
+
textApi: TextAreaTextApi;
|
|
103
|
+
constructor(textArea: HTMLTextAreaElement);
|
|
104
|
+
getState(): false | TextState;
|
|
105
|
+
executeCommand(
|
|
106
|
+
command: ICommand<string>,
|
|
107
|
+
dispatch?: React.Dispatch<ContextStore>,
|
|
108
|
+
state?: ExecuteCommandState,
|
|
109
|
+
shortcuts?: string[],
|
|
110
|
+
): void;
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
title,
|
|
114
|
+
title1,
|
|
115
|
+
title2,
|
|
116
|
+
title3,
|
|
117
|
+
title4,
|
|
118
|
+
title5,
|
|
119
|
+
title6,
|
|
120
|
+
bold,
|
|
121
|
+
codeBlock,
|
|
122
|
+
comment,
|
|
123
|
+
italic,
|
|
124
|
+
strikethrough,
|
|
125
|
+
hr,
|
|
126
|
+
group,
|
|
127
|
+
divider,
|
|
128
|
+
link,
|
|
129
|
+
quote,
|
|
130
|
+
code,
|
|
131
|
+
image,
|
|
132
|
+
unorderedListCommand,
|
|
133
|
+
orderedListCommand,
|
|
134
|
+
checkedListCommand,
|
|
135
|
+
table,
|
|
136
|
+
issue,
|
|
137
|
+
help,
|
|
138
|
+
codeEdit,
|
|
139
|
+
codeLive,
|
|
140
|
+
codePreview,
|
|
141
|
+
fullscreen,
|
|
142
|
+
getCommands,
|
|
143
|
+
getExtraCommands,
|
|
144
|
+
getStateFromTextArea,
|
|
145
|
+
TextAreaCommandOrchestrator,
|
|
146
|
+
TextAreaTextApi,
|
|
147
|
+
};
|
|
148
|
+
}
|
package/dist/mdeditor.css
CHANGED
|
@@ -1183,7 +1183,7 @@ body[data-color-mode*='light'] {
|
|
|
1183
1183
|
.w-md-editor-toolbar {
|
|
1184
1184
|
border-bottom: 1px solid var(--md-editor-box-shadow-color);
|
|
1185
1185
|
background-color: var(--md-editor-background-color);
|
|
1186
|
-
padding:
|
|
1186
|
+
padding: 3px;
|
|
1187
1187
|
display: flex;
|
|
1188
1188
|
justify-content: space-between;
|
|
1189
1189
|
align-items: center;
|