Skip to content

Commit

Permalink
feat: update tips
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Feb 3, 2021
1 parent d6a3859 commit 0270d77
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
7 changes: 5 additions & 2 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from 'react';
import ReactDOM from 'react-dom';
import ReactRteSlate from '../src/main';
import { Toolbar, ButtonGroup, Button } from '@jswork/react-rte-ui';
import Bold from './plugins/bold';
import Italic from './plugins/italic';
import './assets/style.scss';

class App extends React.Component {
Expand All @@ -29,11 +31,11 @@ class App extends React.Component {

constructor(inProps) {
super(inProps);
this.state = { value: '<p>aaa</p>' };
this.state = { value: '<p>hello world</p>' };
}

handleClick1 = (e) => {
this.setState({ value: '<p>abcd</p>' });
this.setState({ value: '<p>Are you ok?</p>' });
};

render() {
Expand All @@ -47,6 +49,7 @@ class App extends React.Component {
<ReactRteSlate
placeholder="type your text."
header={this.headerView}
plugins={[Bold, Italic]}
value={this.state.value}
onChange={(e) => {
this.setState({ value: e.target.value });
Expand Down
2 changes: 2 additions & 0 deletions public/plugins/bold.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

export default {
name: 'bold',
hooks: {
Expand Down
2 changes: 2 additions & 0 deletions public/plugins/italic.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

export default {
name: 'italic',
hooks: {
Expand Down
29 changes: 26 additions & 3 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ export default class ReactRteSlate extends Component {
this.editor = composite(createEditor());
this.state = { value: this.initialValue };
onInit({ target: { value: this.editor } });
// window.editor = this.editor;
// window.Editor = Editor;

window.editor = this.editor;
window.Editor = Editor;
}

shouldComponentUpdate(inProps) {
Expand All @@ -119,7 +120,29 @@ export default class ReactRteSlate extends Component {
};

renderLeaf = (inProps) => {
return this.renderHooks('leaf', inProps);
const { plugins } = this.props;
const { attributes, children, leaf } = inProps;

let formatArr = [];

for (let key in inProps.leaf) {
if (key !== 'text') {
let plugin = plugins.find((v) => v.name === key);
if (plugin) {
formatArr.push(plugin.hooks.leaf);
}
}
}

console.log('ActiveFormats:', formatArr);

return (
<span {...attributes}>
{formatArr.reduce((child, handler) => {
return handler(this, { children: child, leaf, attributes });
}, children)}
</span>
);
};

handleSerialize(inRole, inValue) {
Expand Down

0 comments on commit 0270d77

Please sign in to comment.