Skip to content

Commit

Permalink
fix regression when refactoring to context api (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolm-kee authored Nov 9, 2021
1 parent fe311e1 commit 3ac2fe5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
27 changes: 16 additions & 11 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const config = {
placeholder: "Welcome to Mobiledoc!",
willCreateEditor:() => { console.log('creating editor...'); },
didCreateEditor:(e) => { console.log('created editor:', e); },
onChange:(doc) => { console.log(doc); }
};

const imgPayload = { caption: "Edit this right meow!", src: "http://www.placekitten.com/200/200" };
Expand All @@ -33,16 +32,22 @@ const ClickCounterButton = () => {
return <button onClick={onClick}>Click Counter Atom</button>;
};

const App = () => {
const [state, setState] = React.useState(undefined);

return (
<div>
<ReactMobiledoc.Container {...config} mobiledoc={state} onChange={setState}>
<ReactMobiledoc.Toolbar />
<ImageButton />
<ClickCounterButton />
<ReactMobiledoc.Editor />
</ReactMobiledoc.Container>
<pre>{JSON.stringify(state, null, 2)}</pre>
</div>
);
};


ReactDOM.render(
<ReactMobiledoc.Container {...config}>
<ReactMobiledoc.Toolbar />
<ImageButton />
<ClickCounterButton />
<ReactMobiledoc.Editor />
</ReactMobiledoc.Container>,
document.getElementById('root')
);
ReactDOM.render(<App />, document.getElementById('root'));

require("!style-loader!css-loader!../node_modules/mobiledoc-kit/dist/mobiledoc.css");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-mobiledoc-editor",
"version": "0.12.1",
"version": "0.12.2",
"description": "A Mobiledoc editor for React apps",
"repository": "joshfrench/react-mobiledoc-editor",
"homepage": "https://github.com/joshfrench/react-mobiledoc-editor",
Expand Down
19 changes: 11 additions & 8 deletions src/components/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ class Container extends React.Component {
this.editor = new Mobiledoc.Editor(editorOptions);

this.editor.inputModeDidChange(this.setActiveTags);

if (typeof this.props.onChange === 'function') {
this.editor.postDidChange(() => {
const mobiledoc = this.editor.serialize(this.props.serializeVersion);
this.props.onChange(mobiledoc);
});
}
this.editor.postDidChange(() => {
this.handleChange();
});

if (typeof this.props.didCreateEditor === 'function') {
this.props.didCreateEditor(this.editor);
Expand All @@ -56,7 +52,7 @@ class Container extends React.Component {
/* eslint-disable no-unused-vars */
/* deconstruct out non-React props before passing to children */
const { atoms, autofocus, cardProps, cards, children, didCreateEditor, html, mobiledoc, options,
placeholder, serializeVersion, spellcheck, willCreateEditor, ...componentProps } = this.props;
placeholder, serializeVersion, spellcheck, willCreateEditor, onChange, ...componentProps } = this.props;
/* eslint-enable no-unused-vars */
return <div {...componentProps}>
<ReactMobileDocContext.Provider
Expand Down Expand Up @@ -85,6 +81,13 @@ class Container extends React.Component {
})
});
}

handleChange = () => {
if (typeof this.props.onChange === 'function') {
const mobiledoc = this.editor.serialize(this.props.serializeVersion);
this.props.onChange(mobiledoc);
}
};
}

Container.propTypes = {
Expand Down
5 changes: 0 additions & 5 deletions src/components/SectionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@ SectionButton.propTypes = {
children: PropTypes.node
};

SectionButton.contextTypes = {
editor: PropTypes.object,
activeSectionTags: PropTypes.array
};

export default SectionButton;

0 comments on commit 3ac2fe5

Please sign in to comment.