applyTemplate API method
This commit is contained in:
parent
f245fd2ed9
commit
59b7517414
|
@ -16,7 +16,10 @@ export default class TextAnnotator extends Component {
|
|||
selectedAnnotation: null,
|
||||
|
||||
showRelationEditor: false,
|
||||
selectedRelation: null
|
||||
selectedRelation: null,
|
||||
|
||||
applyTemplate: null,
|
||||
headless: false
|
||||
}
|
||||
|
||||
/** Shorthand **/
|
||||
|
@ -178,6 +181,9 @@ export default class TextAnnotator extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
applyTemplate = (bodies, headless) =>
|
||||
this.setState({ applyTemplate: bodies, headless })
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
|
@ -187,7 +193,8 @@ export default class TextAnnotator extends Component {
|
|||
bounds={this.state.selectionBounds}
|
||||
annotation={this.state.selectedAnnotation}
|
||||
readOnly={this.props.readOnly}
|
||||
autoApply={this.props.autoApply}
|
||||
headless={this.state.headless}
|
||||
applyTemplate={this.state.applyTemplate}
|
||||
onAnnotationCreated={this.onCreateOrUpdateAnnotation('onAnnotationCreated')}
|
||||
onAnnotationUpdated={this.onCreateOrUpdateAnnotation('onAnnotationUpdated')}
|
||||
onAnnotationDeleted={this.onDeleteAnnotation}
|
||||
|
|
|
@ -23,18 +23,21 @@ const Editor = props => {
|
|||
|
||||
// Re-render: set derived annotation state & position the editor
|
||||
useEffect(() => {
|
||||
if (!currentAnnotation?.isEqual(props.annotation))
|
||||
setCurrentAnnotation(props.annotation);
|
||||
// Shorthand: user wants a template applied and this is a selection
|
||||
const shouldApplyTemplate = props.applyTemplate && props.annotation?.isSelection
|
||||
|
||||
// Apply template if needed
|
||||
const annotation = shouldApplyTemplate ?
|
||||
props.annotation.clone({ body: [ ...props.applyTemplate ]}) :
|
||||
props.annotation;
|
||||
|
||||
if (!currentAnnotation?.isEqual(annotation))
|
||||
setCurrentAnnotation(annotation);
|
||||
|
||||
/** Experimental **/
|
||||
if (props.autoApply && props.annotation?.isSelection)
|
||||
props.onAnnotationCreated(autoApply(props));
|
||||
/** Experimental **/
|
||||
// In headless mode, create immediately
|
||||
if (shouldApplyTemplate && props.headless)
|
||||
props.onAnnotationCreated(annotation.toAnnotation());
|
||||
|
||||
|
||||
|
||||
if (element.current)
|
||||
setPosition(props.wrapperEl, element.current, props.bounds);
|
||||
}, [ props.bounds ]);
|
||||
|
|
Loading…
Reference in New Issue