Added experimental 'autoApply' feature

This commit is contained in:
Rainer Simon 2020-04-20 19:04:53 +02:00
parent 944f7cadfe
commit 3918785cf4
2 changed files with 18 additions and 3 deletions

View File

@ -183,10 +183,11 @@ export default class TextAnnotator extends Component {
<>
{ this.state.selectedAnnotation &&
<Editor
readOnly={this.props.readOnly}
bounds={this.state.selectionBounds}
wrapperEl={this.props.wrapperEl}
bounds={this.state.selectionBounds}
annotation={this.state.selectedAnnotation}
readOnly={this.props.readOnly}
autoApply={this.props.autoApply}
onAnnotationCreated={this.onCreateOrUpdateAnnotation('onAnnotationCreated')}
onAnnotationUpdated={this.onCreateOrUpdateAnnotation('onAnnotationUpdated')}
onAnnotationDeleted={this.onDeleteAnnotation}

View File

@ -1,6 +1,11 @@
import React, { useState, useRef, useEffect } from 'react';
import setPosition from './setPosition';
const autoApply = props => {
const applied = props.annotation.clone({ body: [{ ...props.autoApply }]});
return applied.toAnnotation();
}
/**
* The popup editor component.
*
@ -21,6 +26,15 @@ const Editor = props => {
if (!currentAnnotation?.isEqual(props.annotation))
setCurrentAnnotation(props.annotation);
/** Experimental **/
if (props.autoApply && props.annotation?.isSelection)
props.onAnnotationCreated(autoApply(props));
/** Experimental **/
if (element.current)
setPosition(props.wrapperEl, element.current, props.bounds);
}, [ props.bounds ]);
@ -63,7 +77,7 @@ const Editor = props => {
else
props.onAnnotationUpdated(undraft(currentAnnotation), props.annotation);
}
};
};
return (
<div ref={element} className="r6o-editor">