Made plugin events work
This commit is contained in:
parent
64aa253a5e
commit
1cde3d866d
|
@ -1,41 +1,31 @@
|
||||||
import React from 'preact/compat';
|
import React, { Component } from 'preact/compat';
|
||||||
import { useRef, useEffect } from 'preact/hooks';
|
|
||||||
|
|
||||||
const DOMWidget = props => {
|
export default class DOMWidget extends Component {
|
||||||
|
|
||||||
const element = useRef();
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.element = React.createRef();
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
componentDidMount() {
|
||||||
annotation,
|
if (this.element.current) {
|
||||||
readOnly,
|
const widgetEl = this.props.widget({
|
||||||
onAppendBody,
|
annotation: this.props.annotation,
|
||||||
onUpdateBody,
|
readOnly: this.props.readOnly,
|
||||||
onRemoveBody,
|
onAppendBody: body => this.props.onAppendBody(body),
|
||||||
onSaveAndClose
|
onUpdateBody: (previous, updated) => this.props.onUpdateBody(previous, updated),
|
||||||
} = props;
|
onRemoveBody: body => this.props.onRemoveBody(body),
|
||||||
|
onSaveAndClose: () => this.props.onSaveAndClose()
|
||||||
useEffect(() => {
|
|
||||||
if (element.current) {
|
|
||||||
|
|
||||||
// Instantiate the widget...
|
|
||||||
const widgetEl = props.widget({
|
|
||||||
annotation,
|
|
||||||
readOnly,
|
|
||||||
onAppendBody,
|
|
||||||
onUpdateBody,
|
|
||||||
onRemoveBody,
|
|
||||||
onSaveAndClose
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ...and append to JSX wrapper
|
this.element.current.appendChild(widgetEl);
|
||||||
element.current.appendChild(widgetEl);
|
|
||||||
}
|
}
|
||||||
}, []);
|
}
|
||||||
|
|
||||||
return (
|
render() {
|
||||||
<div ref={element} class="widget"></div>
|
return (
|
||||||
)
|
<div ref={this.element} className="widget"></div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DOMWidget;
|
|
Loading…
Reference in New Issue