Fixes wrapped widgets not being created on editor instanciation.
This commit is contained in:
parent
a335f51b17
commit
8937019f2b
|
@ -1,32 +1,38 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
export default class WrappedWidget extends Component {
|
export default class WrappedWidget extends Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.element = React.createRef();
|
this.element = React.createRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateWidget(props) {
|
||||||
|
const widgetEl = this.props.widget({
|
||||||
|
annotation: props.annotation,
|
||||||
|
readOnly: props.readOnly,
|
||||||
|
...this.props.config,
|
||||||
|
onAppendBody: body => props.onAppendBody(body),
|
||||||
|
onUpdateBody: (previous, updated) => props.onUpdateBody(previous, updated),
|
||||||
|
onRemoveBody: body => props.onRemoveBody(body),
|
||||||
|
onSaveAndClose: () => props.onSaveAndClose()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete previous rendered state
|
||||||
|
while (this.element.current.firstChild)
|
||||||
|
this.element.current.removeChild(this.element.current.lastChild);
|
||||||
|
|
||||||
|
this.element.current.appendChild(widgetEl);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.updateWidget(this.props);
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(next) {
|
componentWillReceiveProps(next) {
|
||||||
if (this.element.current) {
|
if (this.element.current) {
|
||||||
if (this.props.annotation !== next.annotation) {
|
if (this.props.annotation !== next.annotation) {
|
||||||
|
this.updateWidget(next);
|
||||||
const widgetEl = this.props.widget({
|
|
||||||
annotation: next.annotation,
|
|
||||||
readOnly: next.readOnly,
|
|
||||||
...this.props.config,
|
|
||||||
onAppendBody: body => next.onAppendBody(body),
|
|
||||||
onUpdateBody: (previous, updated) => next.onUpdateBody(previous, updated),
|
|
||||||
onRemoveBody: body => next.onRemoveBody(body),
|
|
||||||
onSaveAndClose: () => next.onSaveAndClose()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Delete previous rendered state
|
|
||||||
while (this.element.current.firstChild)
|
|
||||||
this.element.current.removeChild(this.element.current.lastChild);
|
|
||||||
|
|
||||||
this.element.current.appendChild(widgetEl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue