Check editor value after update
This commit is contained in:
parent
1d08f1a33b
commit
4d2ed6b1ea
@ -105,29 +105,42 @@ export default class Editor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { schema, parser } = this.state;
|
|
||||||
const doc = parser.parse(this.props.value || '');
|
|
||||||
this.view = new EditorView(this.ref, {
|
this.view = new EditorView(this.ref, {
|
||||||
state: EditorState.create({
|
state: this.createEditorState(),
|
||||||
doc,
|
|
||||||
schema,
|
|
||||||
plugins: [
|
|
||||||
inputRules({
|
|
||||||
rules: allInputRules.concat(buildInputRules(schema)),
|
|
||||||
}),
|
|
||||||
keymap(buildKeymap(schema)),
|
|
||||||
keymap(baseKeymap),
|
|
||||||
history.history(),
|
|
||||||
keymap({
|
|
||||||
'Mod-z': history.undo,
|
|
||||||
'Mod-y': history.redo,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
onAction: this.handleAction,
|
onAction: this.handleAction,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createEditorState() {
|
||||||
|
const { schema, parser } = this.state;
|
||||||
|
const doc = parser.parse(this.props.value || '');
|
||||||
|
|
||||||
|
return EditorState.create({
|
||||||
|
doc,
|
||||||
|
schema,
|
||||||
|
plugins: [
|
||||||
|
inputRules({
|
||||||
|
rules: allInputRules.concat(buildInputRules(schema)),
|
||||||
|
}),
|
||||||
|
keymap(buildKeymap(schema)),
|
||||||
|
keymap(baseKeymap),
|
||||||
|
history.history(),
|
||||||
|
keymap({
|
||||||
|
'Mod-z': history.undo,
|
||||||
|
'Mod-y': history.redo,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps, prevState) {
|
||||||
|
const editorValue = this.state.serializer.serialize(this.view.state.doc);
|
||||||
|
|
||||||
|
if (editorValue !== this.props.value && editorValue !== prevProps.value) {
|
||||||
|
this.view.updateState(this.createEditorState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleAction = (action) => {
|
handleAction = (action) => {
|
||||||
const { serializer } = this.state;
|
const { serializer } = this.state;
|
||||||
const newState = this.view.state.applyAction(action);
|
const newState = this.view.state.applyAction(action);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user