Skip to content

Commit 2e8e166

Browse files
committed
feat: add react wrapper
1 parent d103bad commit 2e8e166

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

packages/react/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@bytemd/react",
3+
"version": "0.0.1",
4+
"description": "Full-featured markdown editor and viewer",
5+
"main": "dist/bytemd-react.cjs.js",
6+
"module": "dist/bytemd-react.esm.js",
7+
"keywords": [],
8+
"files": [
9+
"dist"
10+
],
11+
"author": "Rongjian Zhang <pd4d10@gmail.com>",
12+
"license": "MIT",
13+
"dependencies": {
14+
"@bytemd/core": "0.0.1"
15+
},
16+
"devDependencies": {
17+
"@types/react": "^16.9.23",
18+
"react": "^16.13.0"
19+
},
20+
"peerDependencies": {
21+
"react": "^16.0.0"
22+
}
23+
}

packages/react/src/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createElement, Component } from 'react';
2+
import * as bytemd from '@bytemd/core';
3+
4+
export class Viewer extends Component {
5+
constructor() {
6+
this.container = null;
7+
this.setContainer = e => {
8+
this.container = e;
9+
};
10+
}
11+
componentDidMount() {
12+
new bytemd.Viewer({
13+
target: this.container,
14+
props: this.props
15+
});
16+
}
17+
render() {
18+
return createElement('div', {
19+
ref: this.setContainer
20+
});
21+
}
22+
}
23+
24+
export class Editor extends Component {
25+
constructor() {
26+
this.container = null;
27+
this.setContainer = e => {
28+
this.container = e;
29+
};
30+
}
31+
componentDidMount() {
32+
new bytemd.Editor({
33+
target: this.container,
34+
props: this.props
35+
});
36+
}
37+
render() {
38+
return createElement('div', {
39+
ref: this.setContainer
40+
});
41+
}
42+
}

rollup.config.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,24 @@ const core = {
9393
}
9494
};
9595

96-
export default [core];
96+
const reactPkg = require('./packages/react/package.json');
97+
98+
/** @type {import('rollup').RollupOptions} */
99+
const react = {
100+
input: 'packages/react/src/index.js',
101+
output: [
102+
{
103+
...outputConfig,
104+
format: 'es',
105+
file: 'packages/react/' + reactPkg.module
106+
},
107+
{
108+
...outputConfig,
109+
format: 'cjs',
110+
file: 'packages/react/' + reactPkg.main
111+
}
112+
],
113+
plugins: [production && terser()]
114+
};
115+
116+
export default [core, react];

0 commit comments

Comments
 (0)