UNPKG

lost-sia

Version:

Single Image Annotation Tool

2 lines (1 loc) 1.57 kB
import{jsx as e}from"react/jsx-runtime";import i,{Component as p}from"react";import l from"./LabelInput.js";import{allowedToLabel as n}from"./utils/constraints.js";import{CHANGED as r,NEW as o}from"./types/annoStatus.js";class c extends p{constructor(s){super(s),this.state={top:400,left:100,label:void 0,visibility:"hidden",possibleLabels:[]},this.inputGroupRef=i.createRef()}componentWillMount(){this.setPosition()}componentDidUpdate(s){this.props.visible&&this.setPosition()}setPosition(){if(this.props.mousePos){const s=this.props.mousePos.y+this.props.svg.top-10,t=this.props.mousePos.x+this.props.svg.left-10;(this.state.top!==s||this.state.left!==t)&&this.setState({top:s,left:t})}}onClose(){this.props.onClose&&this.props.onClose()}annoLabelUpdate(s){this.props.onLabelUpdate&&this.props.onLabelUpdate(s)}updateAnnoLabel(s){n(this.props.allowedActions,this.props.selectedAnno)&&this.annoLabelUpdate({...this.props.selectedAnno,labelIds:s,status:this.props.selectedAnno.status!==o?r:o})}render(){return this.props.visible?e("div",{ref:this.inputGroupRef,style:{position:"fixed",top:this.state.top,left:this.state.left},children:e(l,{svg:this.props.svg,onClose:()=>this.onClose(),initLabelIds:this.props.selectedAnno.labelIds,relatedId:this.props.selectedAnno.id,visible:this.props.visible,onLabelUpdate:s=>this.updateAnnoLabel(s),possibleLabelsProp:this.props.possibleLabels,multilabels:this.props.multilabels,disabled:!this.props.allowedActions.label,renderPopup:!0,focusOnRender:!0,open:!0,defaultLabel:this.props.defaultLabel})}):null}}export{c as default};