Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions dist/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ var ReactMediumEditor = function (_React$Component) {
function ReactMediumEditor(props) {
_classCallCheck(this, ReactMediumEditor);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ReactMediumEditor).call(this, props));
var _this = _possibleConstructorReturn(this, (ReactMediumEditor.__proto__ || Object.getPrototypeOf(ReactMediumEditor)).call(this, props));

_this.state = {
text: _this.props.text
};
_this.text = _this.props.text;
return _this;
}

Expand All @@ -58,27 +56,30 @@ var ReactMediumEditor = function (_React$Component) {
this.medium = new MediumEditor(dom, this.props.options);
this.medium.subscribe('editableInput', function (e) {
_this2._updated = true;
_this2.text = dom.innerHTML;
_this2.change(dom.innerHTML);
});
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
this.medium.restoreSelection();
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.medium.destroy();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (nextProps.text !== this.state.text && !this._updated) {
this.setState({ text: nextProps.text });
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps) {
//inside update: received old text
if (this._updated && nextProps.text != this.text) return false;

//ignore same text
if (nextProps.text == this.text) {
this._updated = false;
return false;
}

if (this._updated) this._updated = false;
//outside update
this.text = nextProps.text;
return true;
}
}, {
key: 'render',
Expand All @@ -87,13 +88,9 @@ var ReactMediumEditor = function (_React$Component) {
var props = (0, _blacklist2.default)(this.props, 'options', 'text', 'tag', 'contentEditable', 'dangerouslySetInnerHTML');

(0, _objectAssign2.default)(props, {
dangerouslySetInnerHTML: { __html: this.state.text }
dangerouslySetInnerHTML: { __html: this.text }
});

if (this.medium) {
this.medium.saveSelection();
}

return _react2.default.createElement(tag, props);
}
}, {
Expand Down
4 changes: 4 additions & 0 deletions example/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ body {
border-radius: 4px;
outline: 0;
}

p {
margin: 0;
}
32 changes: 16 additions & 16 deletions lib/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export default class ReactMediumEditor extends React.Component {
constructor(props) {
super(props);

this.state = {
text: this.props.text
};
this.text = this.props.text;
}

componentDidMount() {
Expand All @@ -26,38 +24,40 @@ export default class ReactMediumEditor extends React.Component {
this.medium = new MediumEditor(dom, this.props.options);
this.medium.subscribe('editableInput', (e) => {
this._updated = true;
this.text = dom.innerHTML;
this.change(dom.innerHTML);
});
}

componentDidUpdate() {
this.medium.restoreSelection();
}

componentWillUnmount() {
this.medium.destroy();
}

componentWillReceiveProps(nextProps) {
if (nextProps.text !== this.state.text && !this._updated) {
this.setState({ text: nextProps.text });
shouldComponentUpdate(nextProps) {
//inside update: received old text
if (this._updated && nextProps.text != this.text)
return false;

//ignore same text
if (nextProps.text == this.text) {
this._updated = false;
return false;
}

if (this._updated) this._updated = false;
//outside update
this.text = nextProps.text;
return true;
}


render() {
const tag = this.props.tag;
const props = blacklist(this.props, 'options', 'text', 'tag', 'contentEditable', 'dangerouslySetInnerHTML');

assign(props, {
dangerouslySetInnerHTML: { __html: this.state.text }
dangerouslySetInnerHTML: { __html: this.text }
});

if (this.medium) {
this.medium.saveSelection();
}

return React.createElement(tag, props);
}

Expand Down
Loading