Made plugin events work

This commit is contained in:
Rainer Simon 2020-09-11 09:58:55 +02:00
parent 64aa253a5e
commit 1cde3d866d
1 changed files with 22 additions and 32 deletions

View File

@ -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;