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