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