Skip to content

Commit 58bbb94

Browse files
committed
chore: add preview
1 parent 8e18979 commit 58bbb94

5 files changed

Lines changed: 823 additions & 297 deletions

File tree

demo/basic.md renamed to demo/index.tsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
---
2-
title: Simple Usage
3-
order: 1
4-
---
5-
6-
本 Demo 演示基本用法。
7-
8-
```jsx
91
import React, { Component } from 'react';
10-
import ReactDOM from 'react-dom';
2+
import ReactDOM from 'react-dom/client';
113
import ReactMarkdown from 'react-markdown';
12-
import MdEditor, { Plugins } from 'react-markdown-editor-lite';
4+
import MdEditor, { Plugins } from '../src';
5+
import '../src/index.less';
136

147
const PLUGINS = undefined;
158
// const PLUGINS = ['header', 'divider', 'image', 'divider', 'font-bold', 'full-screen'];
@@ -23,14 +16,18 @@ MdEditor.use(Plugins.TabInsert, {
2316
tabMapValue: 1, // note that 1 means a '\t' instead of ' '.
2417
});
2518

26-
class Demo extends React.Component {
27-
mdEditor = undefined;
19+
interface State {
20+
value: string;
21+
}
22+
23+
class Demo extends Component<{}, State> {
24+
mdEditor: MdEditor | undefined = undefined;
2825

2926
constructor(props) {
3027
super(props);
3128
this.renderHTML = this.renderHTML.bind(this);
3229
this.state = {
33-
value: "# Hello",
30+
value: '# Hello',
3431
};
3532
}
3633

@@ -41,17 +38,17 @@ class Demo extends React.Component {
4138
});
4239
};
4340

44-
handleImageUpload = (file) => {
41+
handleImageUpload = file => {
4542
return new Promise(resolve => {
4643
const reader = new FileReader();
4744
reader.onload = data => {
48-
resolve(data.target.result);
45+
resolve((data.target as any).result);
4946
};
5047
reader.readAsDataURL(file);
5148
});
5249
};
5350

54-
onCustomImageUpload = (event) => {
51+
onCustomImageUpload = event => {
5552
console.log('onCustomImageUpload', event);
5653
return new Promise((resolve, reject) => {
5754
const result = window.prompt('Please enter image url here...');
@@ -82,15 +79,15 @@ class Demo extends React.Component {
8279

8380
handleSetValue = () => {
8481
const text = window.prompt('Content');
85-
this.setState({
86-
value: text,
87-
});
82+
if (text) {
83+
this.setState({
84+
value: text,
85+
});
86+
}
8887
};
8988

9089
renderHTML(text) {
91-
return React.createElement(ReactMarkdown, {
92-
source: text,
93-
});
90+
return <ReactMarkdown>{text}</ReactMarkdown>;
9491
}
9592

9693
render() {
@@ -104,7 +101,9 @@ class Demo extends React.Component {
104101
</nav>
105102
<div className="editor-wrap" style={{ marginTop: '30px' }}>
106103
<MdEditor
107-
ref={node => (this.mdEditor = node || undefined)}
104+
ref={node => {
105+
this.mdEditor = node || undefined;
106+
}}
108107
value={this.state.value}
109108
style={{ height: '500px', width: '100%' }}
110109
renderHTML={this.renderHTML}
@@ -155,7 +154,12 @@ class Demo extends React.Component {
155154
}
156155
}
157156

158-
ReactDOM.render((
159-
<Demo />
160-
), mountNode);
161-
```
157+
const rootEl = document.getElementById('root');
158+
if (rootEl) {
159+
const root = ReactDOM.createRoot(rootEl);
160+
root.render(
161+
<React.StrictMode>
162+
<Demo />
163+
</React.StrictMode>,
164+
);
165+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"scripts": {
1818
"build": "rslib build",
1919
"check": "biome check --write",
20-
"dev": "rslib build --watch",
20+
"build:watch": "rslib build --watch",
21+
"dev": "rsbuild dev",
22+
"build:demo": "rsbuild build",
2123
"format": "biome format --write",
2224
"test": "mocha",
2325
"coverage": "nyc mocha"
@@ -44,6 +46,7 @@
4446
"homepage": "https://unpkg.com/react-markdown-editor-lite@1.2.5-8/build/index.html",
4547
"devDependencies": {
4648
"@biomejs/biome": "2.1.3",
49+
"@rsbuild/core": "^1.5.0",
4750
"@rsbuild/plugin-less": "^1.5.0",
4851
"@rsbuild/plugin-react": "^1.3.5",
4952
"@rslib/core": "^0.12.2",
@@ -67,7 +70,7 @@
6770
"nyc": "^15.1.0",
6871
"react": "^19.1.1",
6972
"react-dom": "^19.1.1",
70-
"react-markdown": "^4.3.1",
73+
"react-markdown": "^10.1.0",
7174
"simple-git-hooks": "^2.13.0",
7275
"source-map-support": "^0.5.21",
7376
"tsx": "^4.20.5",

0 commit comments

Comments
 (0)