Added experimental 'autoApply' feature
This commit is contained in:
parent
944f7cadfe
commit
3918785cf4
|
@ -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}
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in New Issue