@labelbee/lb-components 1.2.1 → 1.2.2-alpha.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/App.js +1 -1
- package/dist/components/AnnotationView/index.js +1 -1
- package/dist/components/customResizeHook/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/store/annotation/reducer.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/store/annotation/types.d.ts +1 -1
- package/dist/types/views/MainView/annotationOperation/index.d.ts +1 -1
- package/dist/types/views/MainView/sidebar/TagSidebar/index.d.ts +1 -1
- package/dist/types/views/MainView/sidebar/TextToolSidebar/index.d.ts +1 -1
- package/dist/types/views/MainView/toolHeader/index.d.ts +1 -1
- package/dist/utils/AnnotationDataUtils.js +1 -1
- package/dist/views/MainView/annotationOperation/index.js +1 -1
- package/dist/views/MainView/sidebar/TagSidebar/index.js +1 -1
- package/dist/views/MainView/sidebar/TextToolSidebar/index.js +1 -1
- package/dist/views/MainView/toolHeader/index.js +1 -1
- package/es/App.js +1 -1
- package/es/App.js.map +1 -1
- package/es/components/AnnotationView/index.js +1 -1
- package/es/components/AnnotationView/index.js.map +1 -1
- package/es/components/customResizeHook/index.js +1 -1
- package/es/components/customResizeHook/index.js.map +1 -1
- package/es/constant/index.js.map +1 -1
- package/es/hooks/useRafState.js.map +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/store/annotation/reducer.js +1 -1
- package/es/store/annotation/reducer.js.map +1 -1
- package/es/utils/AnnotationDataUtils.js +1 -1
- package/es/utils/AnnotationDataUtils.js.map +1 -1
- package/es/views/MainView/annotationOperation/index.js +1 -1
- package/es/views/MainView/annotationOperation/index.js.map +1 -1
- package/es/views/MainView/sidebar/TagSidebar/index.js +1 -1
- package/es/views/MainView/sidebar/TagSidebar/index.js.map +1 -1
- package/es/views/MainView/sidebar/TextToolSidebar/index.js +1 -1
- package/es/views/MainView/sidebar/TextToolSidebar/index.js.map +1 -1
- package/es/views/MainView/toolHeader/index.js +1 -1
- package/es/views/MainView/toolHeader/index.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[English](./README_en-US.md) | 简体中文
|
|
2
|
+
|
|
1
3
|
# `LB-Components`
|
|
2
4
|
|
|
3
5
|
基于 LB-Annotation 开发,即插即用的标注组件库。支持拉框、标签、多边形、线条、点、文本标注工具。开发者可根据需求配置,快速实现多种标注功能。
|
|
@@ -11,6 +13,14 @@ $ npm install @labelbee/lb-components
|
|
|
11
13
|
# YARN
|
|
12
14
|
$ yarn add @labelbee/lb-components
|
|
13
15
|
```
|
|
16
|
+
|
|
17
|
+
## 🪵 Requirements
|
|
18
|
+
|
|
19
|
+
| PureDependencies | Version |
|
|
20
|
+
| ---------------- | -------- |
|
|
21
|
+
| react | >=16.9.0 |
|
|
22
|
+
| antd | >=4.15.0 |
|
|
23
|
+
|
|
14
24
|
## 🔨 Usage
|
|
15
25
|
|
|
16
26
|
- [AnnotationOperation - 标注操作组件](./docs/annotation.md)
|
|
@@ -19,7 +29,7 @@ $ yarn add @labelbee/lb-components
|
|
|
19
29
|
## 🔗 Examples
|
|
20
30
|
|
|
21
31
|
- [Get Started](../lb-demo/README.md)
|
|
22
|
-
- [客户端下载链接]()
|
|
32
|
+
- [客户端下载链接](https://github.com/open-mmlab/labelbee-client)
|
|
23
33
|
|
|
24
34
|
## ToolLists
|
|
25
35
|
|
package/dist/App.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),reactRedux=require("react-redux"),index=require("./index.js"),actionCreators=require("./store/annotation/actionCreators.js"),index$1=require("./views/MainView/index.js"),lbUtils=require("@
|
|
1
|
+
"use strict";var React=require("react"),reactRedux=require("react-redux"),index=require("./index.js"),actionCreators=require("./store/annotation/actionCreators.js"),index$1=require("./views/MainView/index.js"),lbUtils=require("@labelbee/lb-utils");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e};const App=e=>{const{imgList:t,step:r,stepList:o,onSubmit:i,onSave:l,initialIndex:s=0,toolInstance:a,setToolInstance:n,getFileData:u,defaultLang:c="cn"}=e;return React.useEffect(()=>{index.store.dispatch(actionCreators.InitTaskData({imgList:t,onSubmit:i,stepList:o,step:r,initialIndex:s,getFileData:u,onSave:l})),lbUtils.i18n.changeLanguage(c)},[]),React.useEffect(()=>{n==null||n(a)},[a]),React__default.default.createElement("div",null,React__default.default.createElement(index$1,__spreadValues({},e)))},mapStateToProps=e=>({toolInstance:e.annotation.toolInstance});var App$1=reactRedux.connect(mapStateToProps)(App);module.exports=App$1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),
|
|
1
|
+
"use strict";var React=require("react"),lbAnnotation=require("@labelbee/lb-annotation"),es=require("antd/es");function _interopDefaultLegacy(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var React__default=_interopDefaultLegacy(React),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(t,o,e)=>o in t?__defProp(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,__spreadValues=(t,o)=>{for(var e in o||(o={}))__hasOwnProp.call(o,e)&&__defNormalProp(t,e,o[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(o))__propIsEnum.call(o,e)&&__defNormalProp(t,e,o[e]);return t};const DEFAULT_SIZE={width:1280,height:720},AnnotationView=(t,o)=>{const{size:e=DEFAULT_SIZE,src:v,annotations:i=[],style:g={color:"blue",thickness:5},zoomChange:c,backgroundStyle:p={},onChange:s,showLoading:_=!1}=t,[m,d]=React.useState(!1),f=React.useRef(null),n=React.useRef();React.useImperativeHandle(o,()=>{const r=n.current;return r?{zoomIn:()=>r.zoomChanged(!0),zoomOut:()=>r.zoomChanged(!1),initImgPos:()=>r.initImgPos(),toolInstance:r}:{}},[n.current]),React.useEffect(()=>(f.current&&(n.current=new lbAnnotation.ViewOperation({container:f.current,size:e,style:g,annotations:i,config:"{}"}),n.current.init()),()=>{var r;(r=n.current)==null||r.destroy()}),[]),React.useEffect(()=>{var r;n.current&&(d(!0),(r=n.current)==null||r.setLoading(!0),lbAnnotation.ImgUtils.load(v).then(u=>{var a,l;(a=n.current)==null||a.setLoading(!1),d(!1),(l=n.current)==null||l.setImgNode(u)}).catch(()=>{var u;(u=n.current)==null||u.setLoading(!1),d(!1)}))},[v]),React.useEffect(()=>{n.current&&n.current.updateData(i)},[i]),React.useEffect(()=>{const r=n.current;(r==null?void 0:r.setSize)&&r.setSize(e)},[e==null?void 0:e.width,e==null?void 0:e.height]),React.useEffect(()=>{var r,u;return n.current&&((r=n.current)==null||r.on("onChange",(...a)=>{s==null||s.apply(null,a)}),(u=n.current)==null||u.on("renderZoom",a=>{c&&c(a)})),()=>{var a,l;(a=n.current)==null||a.unbindAll("onChange"),(l=n.current)==null||l.unbindAll("renderZoom")}},[c,s]);const h=React__default.default.createElement("div",{ref:f,style:__spreadValues(__spreadValues({},e),p)});return React__default.default.createElement(es.Spin,{spinning:_||m,delay:300},h)};var index=React__default.default.forwardRef(AnnotationView);module.exports=index;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var AnnotationSize=require("../../data/enums/AnnotationSize.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var AnnotationSize=require("../../data/enums/AnnotationSize.js"),lbAnnotation=require("@labelbee/lb-annotation"),React=require("react"),reactRedux=require("react-redux"),actionCreators=require("../../store/annotation/actionCreators.js");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React);const EKeyCode=lbAnnotation.cKeyCode.default,viewportContext=React__default.default.createContext({width:window.innerWidth,height:window.innerHeight}),ViewportProviderComponent=e=>{const{children:a,dispatch:o}=e,[n]=React.useState(window.innerWidth),[i]=React.useState(window.innerHeight),r=t=>{!lbAnnotation.toolUtils.hotkeyFilter(t)||(t.keyCode===EKeyCode.A&&o(actionCreators.PageBackward()),t.keyCode===EKeyCode.D&&o(actionCreators.PageForward()),t.keyCode===EKeyCode.R&&o(actionCreators.UpdateRotate()))};React.useEffect(()=>(window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}),[]);const d=React.useMemo(()=>({width:n,height:i}),[n,i]);return React__default.default.createElement(viewportContext.Provider,{value:d},a)},ViewportProvider=reactRedux.connect(e=>({annotation:e.annotation}))(ViewportProviderComponent),getFormatSize=(e,a=!1,o=!1)=>{const{width:n,height:i}=e,r=AnnotationSize.headerHeight+AnnotationSize.footerHeight,d=o?40+r+40:r,t=a?AnnotationSize.editStepWidth+AnnotationSize.sidebarWidth:AnnotationSize.sidebarWidth;return{width:n-t,height:i-d}};exports.ViewportProvider=ViewportProvider,exports.ViewportProviderComponent=ViewportProviderComponent,exports.getFormatSize=getFormatSize,exports.viewportContext=viewportContext;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),reactRedux=require("react-redux"),configureStore=require("./configureStore.js"),App=require("./App.js"),actionCreators=require("./store/annotation/actionCreators.js"),lbUtils=require("@
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),reactRedux=require("react-redux"),configureStore=require("./configureStore.js"),App=require("./App.js"),actionCreators=require("./store/annotation/actionCreators.js"),lbUtils=require("@labelbee/lb-utils"),reactI18next=require("react-i18next"),index$1=require("./components/AnnotationView/index.js"),ssrWindow=require("ssr-window");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,r,t)=>r in e?__defProp(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,__spreadValues=(e,r)=>{for(var t in r||(r={}))__hasOwnProp.call(r,t)&&__defNormalProp(e,t,r[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(r))__propIsEnum.call(r,t)&&__defNormalProp(e,t,r[t]);return e},__spreadProps=(e,r)=>__defProps(e,__getOwnPropDescs(r));window=ssrWindow.getWindow();const store=configureStore(),OutputApp=(e,r)=>{const[t,a]=React.useState();return React.useImperativeHandle(r,()=>({toolInstance:t,pageBackwardActions:()=>store.dispatch(actionCreators.PageBackward()),pageForwardActions:()=>store.dispatch(actionCreators.PageForward()),pageJump:o=>{const n=~~o-1;store.dispatch(actionCreators.PageJump(n))},hello:()=>alert("hello labelBee!!!")}),[t]),React__default.default.createElement(reactRedux.Provider,{store},React__default.default.createElement(reactI18next.I18nextProvider,{i18n:lbUtils.i18n},React__default.default.createElement(App,__spreadProps(__spreadValues({},e),{setToolInstance:a}))))};var index=React__default.default.forwardRef(OutputApp);Object.defineProperty(exports,"i18n",{enumerable:!0,get:function(){return lbUtils.i18n}}),exports.AnnotationView=index$1,exports.default=index,exports.store=store;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Actions=require("../Actions.js"),_=require("lodash"),data=require("../../utils/data.js"),index=require("../../utils/index.js"),StepUtils=require("../../utils/StepUtils.js"),AnnotationDataUtils=require("../../utils/AnnotationDataUtils.js"),ConfigUtils=require("../../utils/ConfigUtils.js"),styleString=require("../../constant/styleString.js"),index$1=require("../../components/customResizeHook/index.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Actions=require("../Actions.js"),_=require("lodash"),data=require("../../utils/data.js"),index=require("../../utils/index.js"),StepUtils=require("../../utils/StepUtils.js"),AnnotationDataUtils=require("../../utils/AnnotationDataUtils.js"),ConfigUtils=require("../../utils/ConfigUtils.js"),styleString=require("../../constant/styleString.js"),index$1=require("../../components/customResizeHook/index.js"),lbAnnotation=require("@labelbee/lb-annotation"),es=require("antd/es"),actionCreators=require("./actionCreators.js");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t)),__async=(e,t,o)=>new Promise((T,c)=>{var p=l=>{try{N(o.next(l))}catch(E){c(E)}},g=l=>{try{N(o.throw(l))}catch(E){c(E)}},N=l=>l.done?T(l.value):Promise.resolve(l.value).then(p,g);N((o=o.apply(e,t)).next())});const getStepConfig=(e,t)=>e.find(o=>o.step===t),initialState={annotationEngine:null,toolInstance:null,imgList:[],config:"{}",imgIndex:-1,basicIndex:0,imgPageSize:1,step:1,stepList:[],imgNode:new Image,basicResultList:[],resultList:[],stepProgress:0,loading:!1,triggerEventAfterIndexChanged:!1},getTotalPage=e=>{const{imgList:t,imgPageSize:o}=e;return Math.ceil(t.length/o)},calcStepProgress=(e,t)=>e.reduce((o,T)=>{const c=T.result;return index.jsonParser(c)[`step_${t}`]?o+1:o},0)/e.length,updateToolInstance=(e,t)=>{const{step:o,stepList:T}=e,c=StepUtils.getCurrentStepInfo(o,T),p=ConfigUtils.ConfigUtils.jsonParser(c.config),g=document.getElementById("toolContainer");if(!g)throw"Not exist dom named id-toolContainer";const N=index$1.getFormatSize({width:window.innerWidth,height:window.innerHeight}),l=new lbAnnotation.AnnotationEngine({container:g,toolName:c.tool,size:N,imgNode:t,config:p,style:JSON.parse(styleString)});return{toolInstance:l.toolInstance,annotationEngine:l}},LoadImageAndFileData=(e,t)=>(o,T)=>__async(void 0,null,function*(){const{getFileData:c,imgList:p,toolInstance:g}=T().annotation;if(actionCreators.SetAnnotationLoading(o,!0),c){const l=yield c(p[e],e);o({type:Actions.ANNOTATION_ACTIONS.SET_FILE_DATA,payload:{fileData:l,index:e}})}const{url:N}=p[e];return lbAnnotation.ImgUtils.load(N).then(l=>{actionCreators.SetAnnotationLoading(o,!1),o({type:Actions.ANNOTATION_ACTIONS.LOAD_FILE_DATA,payload:{imgNode:l,nextIndex:e,nextBasicIndex:t}})}).catch(()=>{actionCreators.SetAnnotationLoading(o,!1),g.setErrorImg(),o({type:Actions.ANNOTATION_ACTIONS.LOAD_FILE_DATA,payload:{nextIndex:e,nextBasicIndex:t}})})}),annotationReducer=(e=initialState,t)=>{var o,T,c,p,g,N,l,E,h,b,x,F,j,w,U;switch(t.type){case Actions.ANNOTATION_ACTIONS.UPDATE_TOOL_INSTANCE:return __spreadProps(__spreadValues({},e),{toolInstance:t.payload.toolInstance});case Actions.ANNOTATION_ACTIONS.UPDATE_IMG_LIST:return __spreadProps(__spreadValues({},e),{imgList:t.payload.imgList});case Actions.ANNOTATION_ACTIONS.CALC_STEP_PROGRESS:{const{imgList:n,step:s}=e,r=calcStepProgress(n,s);return __spreadProps(__spreadValues({},e),{stepProgress:r})}case Actions.ANNOTATION_ACTIONS.SUBMIT_FILE_DATA:{const{imgList:n,imgIndex:s,step:r,stepList:i,toolInstance:a,onSubmit:u,resultList:A}=e;if(!a)return e;const I=((o=n[s])==null?void 0:o.result)||"",[,d]=a.exportData(),O=data.composeResultWithBasicImgInfo(I,d),m=data.composeResult(O,{step:r,stepList:i},{rect:A});n[s].result=AnnotationDataUtils.dataCorrection(m,I,r,i),u&&u([n[s]],(T=t.payload)==null?void 0:T.submitType,s);const f=calcStepProgress(n,r);return __spreadProps(__spreadValues({},e),{stepProgress:f,imgList:n})}case Actions.ANNOTATION_ACTIONS.SAVE_RESULT:{const{imgList:n,imgIndex:s,onSave:r}=e;return r==null||r(n[s],s,n),__spreadValues({},e)}case Actions.ANNOTATION_ACTIONS.SUBMIT_RESULT:{const{imgList:n,basicIndex:s,resultList:r,annotationEngine:i,basicResultList:a}=e;if(!i)return e;const[u]=i.toolInstance.exportData();let A=u;if((a==null?void 0:a.length)>0){const I=(c=a[s])==null?void 0:c.id,d=u.map(O=>__spreadProps(__spreadValues({},O),{sourceID:I}));A=___default.default.cloneDeep(r).filter(O=>O.sourceID!==I),A.push(...d)}return __spreadProps(__spreadValues({},e),{resultList:A,imgList:n})}case Actions.ANNOTATION_ACTIONS.SET_BASIC_INDEX:{const{toolInstance:n,step:s,imgList:r,imgIndex:i,stepList:a,annotationEngine:u,resultList:A,basicResultList:I}=e;if(!n||!u)return e;const d=t.payload.basicIndex,O=(p=I[d])==null?void 0:p.id,m=index.jsonParser((g=r[i])==null?void 0:g.result),f=(A||[]).filter(P=>P.sourceID===O),L=getStepConfig(a,s),{dataSourceStep:C,tool:R}=L,D=getStepConfig(a,C);let S=[];return C&&R&&(S=(N=m[`step_${C}`])==null?void 0:N.result,(S==null?void 0:S.length)>0?(u.setBasicInfo(D.tool,S[d]),u.launchOperation()):(u.setBasicInfo(D.tool),u.forbidOperation(),es.message.info("\u5F53\u524D\u6587\u4EF6\u4E0D\u5B58\u5728\u4F9D\u8D56\u6570\u636E"))),n.setResult(f),n.history.initRecord(f,!0),__spreadProps(__spreadValues({},e),{basicIndex:d})}case Actions.ANNOTATION_ACTIONS.SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED:{const{triggerEventAfterIndexChanged:n}=t.payload;return __spreadProps(__spreadValues({},e),{triggerEventAfterIndexChanged:!!n})}case Actions.ANNOTATION_ACTIONS.LOAD_FILE_DATA:{const{imgList:n,step:s,toolInstance:r,annotationEngine:i,stepList:a}=e;if(!r||!i)return e;const u=StepUtils.getCurrentStepInfo(s,a),{nextIndex:A,imgNode:I,nextBasicIndex:d,imgError:O}=t.payload,m=d!=null?d:0,f=index.jsonParser((l=n[A])==null?void 0:l.result),L=f[`step_${s}`],C=!L,R={rotate:(E=f.rotate)!=null?E:0,valid:(h=f.valid)!=null?h:!0};I&&O!==!0&&i.setImgNode(I,R);const D=getStepConfig(a,s),{dataSourceStep:S,tool:P}=D,B=getStepConfig(a,S),q=S&&P,v=(x=(b=f[`step_${S}`])==null?void 0:b.result)!=null?x:[],y=AnnotationDataUtils.getInitialResultList(L==null?void 0:L.result,r,D,v,C);if(i.launchOperation(),q&&((v==null?void 0:v.length)>0?i.setBasicInfo(B.tool,v[m]):(i.setBasicInfo(B.tool),i.forbidOperation(),es.message.info("\u5F53\u524D\u6587\u4EF6\u4E0D\u5B58\u5728\u4F9D\u8D56\u6570\u636E"))),u.tool!=="check"){const G=(j=(F=v[m])==null?void 0:F.id)!=null?j:"",z=q?y.filter(M=>lbAnnotation.CommonToolUtils.isSameSourceID(M.sourceID,G)):y;r.setResult(z),r.history.initRecord(y,!0)}return __spreadProps(__spreadValues({},e),{imgIndex:A,basicIndex:m,basicResultList:v,resultList:y})}case Actions.ANNOTATION_ACTIONS.UPDATE_ANNOTATION_CONFIG:return __spreadProps(__spreadValues({},e),{config:(w=t.payload.config)!=null?w:"{}"});case Actions.ANNOTATION_ACTIONS.SET_TASK_CONFIG:{const{stepList:n,step:s}=t.payload;return __spreadProps(__spreadValues({},e),{stepList:n,step:s})}case Actions.ANNOTATION_ACTIONS.INIT_TOOL:{const{imgNode:n}=e,{toolInstance:s,annotationEngine:r}=updateToolInstance(e,n);return __spreadProps(__spreadValues({},e),{toolInstance:s,annotationEngine:r})}case Actions.ANNOTATION_ACTIONS.UPDATE_ON_SUBMIT:return __spreadProps(__spreadValues({},e),{onSubmit:t.payload.onSubmit});case Actions.ANNOTATION_ACTIONS.UPDATE_ON_SAVE:return __spreadProps(__spreadValues({},e),{onSave:t.payload.onSave});case Actions.ANNOTATION_ACTIONS.UPDATE_GET_FILE_DATA:return __spreadProps(__spreadValues({},e),{getFileData:t.payload.getFileData});case Actions.ANNOTATION_ACTIONS.SET_FILE_DATA:{const{fileData:n,index:s}=t.payload,{imgList:r}=e;return r[s]=__spreadValues(__spreadValues({},r[s]),n),__spreadProps(__spreadValues({},e),{imgList:r})}case Actions.ANNOTATION_ACTIONS.UPDATE_ROTATE:{const{toolInstance:n}=e;return n==null||n.updateRotate(),e}case Actions.ANNOTATION_ACTIONS.COPY_BACKWARD_RESULT:{const{toolInstance:n,imgIndex:s,imgList:r,step:i}=e;if(!n)return e;if(s===0||s>=r.length)return console.error("\u65E0\u6CD5\u590D\u5236\u8FB9\u754C\u5916\u7684\u5185\u5BB9"),e;const a=r[s-1].result;if(!a)return e;const u=AnnotationDataUtils.copyResultChange(a,i,(U=r[s].result)!=null?U:"");r[s].result=u;const I=index.jsonParser(u)[`step_${i}`],d=(I==null?void 0:I.result)||[];return n.setResult(d),n.history.pushHistory(d),__spreadProps(__spreadValues({},e),{imgList:[...r]})}case Actions.ANNOTATION_ACTIONS.SET_STEP:{const{stepList:n,annotationEngine:s}=e,{toStep:r}=t.payload;if(!s)return e;if(r<=n.length){const i=getStepConfig(n,r);return s.setToolName(i.tool,i.config),__spreadProps(__spreadValues({},e),{step:r,toolInstance:s.toolInstance})}break}case Actions.ANNOTATION_ACTIONS.SET_LOADING:{const{loading:n}=t.payload;return __spreadProps(__spreadValues({},e),{loading:!!n})}default:return e}return e};exports.LoadImageAndFileData=LoadImageAndFileData,exports.annotationReducer=annotationReducer,exports.getStepConfig=getStepConfig,exports.getTotalPage=getTotalPage;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { i18n } from '@
|
|
2
|
+
import { i18n } from '@labelbee/lb-utils';
|
|
3
3
|
import AnnotationView from '@/components/AnnotationView';
|
|
4
4
|
export declare const store: import("redux").Store<{}, import("redux").Action<any>> & {
|
|
5
5
|
dispatch: unknown;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnnotationEngine, RectOperation, TagOperation, TextToolOperation, PointOperation, PolygonOperation, LineToolOperation } from '@
|
|
1
|
+
import { AnnotationEngine, RectOperation, TagOperation, TextToolOperation, PointOperation, PolygonOperation, LineToolOperation } from '@labelbee/lb-annotation';
|
|
2
2
|
import { ANNOTATION_ACTIONS } from '@/store/Actions';
|
|
3
3
|
import { IStepInfo } from '@/types/step';
|
|
4
4
|
import { OnSubmit, IFileItem, GetFileData, OnSave } from '@/types/data';
|
|
@@ -3,7 +3,7 @@ import { AppState } from 'src/store';
|
|
|
3
3
|
import { ImgAttributeState } from 'src/store/imgAttribute/types';
|
|
4
4
|
import { IFileItem } from '@/types/data';
|
|
5
5
|
import { IStepInfo } from '@/types/step';
|
|
6
|
-
import { AnnotationEngine } from '@
|
|
6
|
+
import { AnnotationEngine } from '@labelbee/lb-annotation';
|
|
7
7
|
interface IProps extends AppState {
|
|
8
8
|
imgAttribute: ImgAttributeState;
|
|
9
9
|
imgList: IFileItem[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { IStepInfo } from '@/types/step';
|
|
3
|
-
import TextToolOperation from '@
|
|
3
|
+
import TextToolOperation from '@labelbee/lb-annotation/dist/types/core/toolOperation/TextToolOperation';
|
|
4
4
|
interface ITextareaWithFooterProps {
|
|
5
5
|
textareaProps?: any;
|
|
6
6
|
footer?: any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { IFileItem } from '@/types/data';
|
|
3
|
-
import { AnnotationEngine } from '@
|
|
3
|
+
import { AnnotationEngine } from '@labelbee/lb-annotation';
|
|
4
4
|
import { EToolName } from '@/data/enums/ToolType';
|
|
5
5
|
import { IStepInfo } from '@/types/step';
|
|
6
6
|
interface IToolHeaderProps {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var lbAnnotation=require("@labelbee/lb-annotation"),index=require("./index.js"),ToolType=require("../data/enums/ToolType.js"),_=require("lodash"),StepUtils=require("./StepUtils.js");function _interopDefaultLegacy(i){return i&&typeof i=="object"&&"default"in i?i:{default:i}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(i,e,t)=>e in i?__defProp(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,__spreadValues=(i,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(i,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(i,t,e[t]);return i},__spreadProps=(i,e)=>__defProps(i,__getOwnPropDescs(e));class AnnotationDataUtils{static copyResultChange(e,t,r){try{const s=index.jsonParser(e),n=index.jsonParser(r),o=`step_${t}`;if(s[o]){const a=s[o];if(a.result)return a.result=a.result.map(u=>__spreadProps(__spreadValues({},u),{id:lbAnnotation.uuid(8,62)})),n[o]=a,JSON.stringify(n)}return e}catch(s){return e}}static isResultSourceMatchedDependence(e,t){const r=e==null?void 0:e.map(n=>n.sourceID).sort(),s=t==null?void 0:t.map(n=>n.id).sort();return ___default.default.isEqual(r,s)}static deltaUpdateBasicResultList(e,t){const r=e==null?void 0:e.map(s=>s.sourceID).sort();return t.filter(s=>!r.includes(s.id))}static getInitialResultList(e,t,r,s,n){const o=e!=null?e:[];switch(r.tool){case ToolType.EToolName.Tag:case ToolType.EToolName.Text:{if(r.dataSourceStep>0){const a=this.deltaUpdateBasicResultList(o,s);if(a.length>0)return o.concat(t.getInitResultList(r.dataSourceStep,a))}return n!==!0?o:t.getInitResultList(r.dataSourceStep,s)}default:return o}}static dataCorrection(e,t,r,s){var n,o;try{const u=`step_${StepUtils.getStepInfo(r,s).step}`,l=index.jsonParser(e),f=index.jsonParser(t),d=(n=l[u])==null?void 0:n.result,c=(o=f[u])==null?void 0:o.result;if(!c||___default.default.isEqual(d.sort(this.idCmp),c.sort(this.idCmp)))return e;const p=this.findDeletedIds(d,c);if(p.length===0)return e;const m=r,h=this.getStepKeys(l).sort();return this.deleteRes(l,m,p,h),JSON.stringify(l)}catch(a){return console.error(a),e}}static idCmp(e,t){const r=e.id,s=t.id;return r<s?-1:r>s?1:0}static findDeletedIds(e,t){return this.findDeletedItems(t,e).map(r=>r.id)}static findDeletedItems(e,t){const r=[];return e.forEach(s=>{t.some(o=>o.id===s.id)||r.push(s)}),r}static getStepKeys(e){return Object.keys(e).map(t=>parseInt(t.replace("step_",""),10)).filter(t=>!isNaN(t))}static deleteRes(e,t,r,s){s.forEach(n=>{if(n>t){const o=e[`step_${n}`];if([ToolType.EToolName.FolderTag,ToolType.EToolName.Segmentation].includes(o.tool))return;if(o.dataSourceStep===t){const a=[];o.result=o.result.filter(u=>r.includes(u.sourceID)?(a.push(u.id),!1):!0),this.deleteRes(e,n,a,s)}else o.result=o.result.filter(a=>!r.includes(a.sourceID))}})}}module.exports=AnnotationDataUtils;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),es=require("antd/es"),reactRedux=require("react-redux"),_=require("lodash"),index=require("../../../index.js"),useSize=require("../../../hooks/useSize.js"),actionCreators=require("../../../store/toolStyle/actionCreators.js"),
|
|
1
|
+
"use strict";var React=require("react"),es=require("antd/es"),reactRedux=require("react-redux"),_=require("lodash"),index=require("../../../index.js"),useSize=require("../../../hooks/useSize.js"),actionCreators=require("../../../store/toolStyle/actionCreators.js"),lbAnnotation=require("@labelbee/lb-annotation"),index$1=require("../../../components/ImageError/index.js"),lbUtils=require("@labelbee/lb-utils");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React),___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));const AnnotationOperation=e=>{const[,t]=React.useState(0),{imgAttribute:r,toolStyle:i,toolInstance:n,annotationEngine:o,loading:u,imgList:c,imgIndex:f}=e,l=React.useRef(null),d=React.useRef(null),s=useSize(l);React.useEffect(()=>{index.store.dispatch(actionCreators.InitToolStyleConfig())},[]),React.useEffect(()=>{if(!!o)switch(lbUtils.i18n.language){case"cn":case"en":o.setLang(lbUtils.i18n.language);break}},[o]),React.useEffect(()=>{n&&(n.singleOn("messageError",a=>{es.message.error(a)}),n.singleOn("messageInfo",a=>{es.message.info(a)}),n.singleOn("changeAnnotationShow",()=>{t(a=>a+1)}))},[n]),React.useEffect(()=>{n&&n.setImgAttribute(r)},[r]),React.useEffect(()=>{n&&n.setStyle(i),o&&o.setStyle(i)},[i]),React.useEffect(()=>{(n==null?void 0:n.setSize)&&n.setSize(s),o&&o.setSize(s)},[s]);const g=()=>{const a=c[f];!a.url||lbAnnotation.ImgUtils.load(a.url).then(p=>{o.setImgNode(p)})};return React__default.default.createElement("div",{ref:l,className:"annotationOperation"},React__default.default.createElement(es.Spin,{spinning:u,delay:500},React__default.default.createElement("div",{className:"canvas",ref:d,style:s,id:"toolContainer"})),(n==null?void 0:n.isImgError)===!0&&React__default.default.createElement(index$1,__spreadProps(__spreadValues({},s),{reloadImage:g,backgroundColor:"#e2e2e2",ignoreOffsetY:!0})))},mapStateToProps=e=>{const t=___default.default.pickBy(e.annotation,(r,i)=>["imgList","imgIndex","stepList","step","toolInstance","annotationEngine","loading"].includes(i));return __spreadValues({imgAttribute:e.imgAttribute,toolStyle:e.toolStyle},t)};var AnnotationOperation$1=reactRedux.connect(mapStateToProps)(AnnotationOperation);module.exports=AnnotationOperation$1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var index$1=require("../../../../components/attributeList/index.js"),index=require("../../../../components/checkboxList/index.js"),icons=require("@ant-design/icons"),es=require("antd/es"),_=require("lodash"),React=require("react"),icon_clearSmall=require("../../../../assets/annotation/common/icon_clearSmall.svg.js"),icon_clearSmall_a=require("../../../../assets/annotation/common/icon_clearSmall_a.svg.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var index$1=require("../../../../components/attributeList/index.js"),index=require("../../../../components/checkboxList/index.js"),icons=require("@ant-design/icons"),es=require("antd/es"),_=require("lodash"),React=require("react"),icon_clearSmall=require("../../../../assets/annotation/common/icon_clearSmall.svg.js"),icon_clearSmall_a=require("../../../../assets/annotation/common/icon_clearSmall_a.svg.js"),lbAnnotation=require("@labelbee/lb-annotation"),reactRedux=require("react-redux"),reactI18next=require("react-i18next");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React);const{Panel}=es.Collapse,expandIconFuc=({isActive:e})=>React__default.default.createElement(icons.CaretRightOutlined,{rotate:e?90:0}),TagSidebar=({toolInstance:e,imgIndex:C})=>{const[u,v]=React.useState([]),s=React.useRef(null),[,R]=React.useState(0),[q,m]=React.useState(-1),{t:f}=reactI18next.useTranslation();React.useEffect(()=>{e&&(v(e.config.inputList.map(t=>t.value)),e.singleOn("render",()=>{R(t=>t+1)}))},[e]),React.useEffect(()=>{if(e&&(e.singleOn("expend",T),e.labelSelectedList.length===1)){let t=0;for(let a=0;a<e.labelSelectedList[0];a++)t+=46,n[a]&&u[a]!==""&&n[a].subSelected.forEach(r=>{t+=40});s.current&&(s.current.children[0].scrollTop=t)}}),React.useEffect(()=>{s.current&&(s.current.children[0].scrollTop=0)},[C]);const T=()=>{var t;const a=e.labelSelectedList[0],r=(t=n.filter((l,o)=>o===a)[0])==null?void 0:t.value;p(a,r,!0)},p=React.useCallback((t,a,r)=>{const l=_.cloneDeep(u);l[t]===""||r===!0?l[t]=a:l[t]="",v(l)},[u]);if(!e)return null;const{labelSelectedList:c,config:{inputList:n},currentTagResult:i,setLabel:g}=e,j=t=>c.length>0&&c[0]===t?React__default.default.createElement("span",{className:"keyDownIconActive"},t+1):React__default.default.createElement("span",{className:"keyDownIcon"},t+1),b=(t,a=-1)=>t?t.map((r,l)=>{var o,y,E,h,L;if(r.subSelected){const k=lbAnnotation.TagUtils.judgeResultIsInInputList(r.value,(o=i==null?void 0:i.result)==null?void 0:o[r.value],n);return React__default.default.createElement(es.Collapse,{bordered:!1,expandIcon:expandIconFuc,key:`collapse_${l}_${a+1}`,onChange:()=>p(l,r.value),activeKey:[u[l]]},React__default.default.createElement(Panel,{header:React__default.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"}},React__default.default.createElement("span",null,r.key,React__default.default.createElement(es.Tooltip,{placement:"bottom",title:f("ClearThisOption")},React__default.default.createElement("img",{style:{marginLeft:5,cursor:"pointer"},onClick:O=>{O.stopPropagation(),e.clearResult(!0,r.value)},src:q===l||k?icon_clearSmall_a:icon_clearSmall,onMouseEnter:()=>{m(l)},onMouseLeave:()=>{m(-1)}})),k&&u[l]===""&&React__default.default.createElement(es.Badge,{color:"#87d068"})),(n==null?void 0:n.length)>1&&j(l)),key:r.value},React__default.default.createElement("div",{className:"level",style:{backgroundColor:c.length>0&&c[0]===l?"rgba(158, 158, 158, 0.18)":""}},b(r.subSelected,l))))}const d=(n==null?void 0:n[a])?n==null?void 0:n[a].value:0,S=((h=(E=(y=i==null?void 0:i.result)==null?void 0:y[d])==null?void 0:E.split(";"))==null?void 0:h.indexOf(r.value))>-1?r.value:"";return((L=n==null?void 0:n[a])==null?void 0:L.isMulti)===!0?React__default.default.createElement("div",{className:"singleBar",key:`${d}_${a}_${l}`},React__default.default.createElement(index,{attributeChanged:()=>g(a,l),selectedAttribute:[S],list:[{value:r.value,label:r.key}],num:l+1})):React__default.default.createElement("div",{className:"singleBar",key:`${d}_${a}_${l}`},React__default.default.createElement(index$1.default,{forbidColor:!0,attributeChanged:()=>g(a,l),selectedAttribute:S,list:[{value:r.value,label:r.key}],num:l+1}))}):null,N=window.innerHeight-61-80;return React__default.default.createElement("div",{className:"tagOperationMenu",ref:s},(n==null?void 0:n.length)===0?React__default.default.createElement("div",{style:{padding:20,textAlign:"center"}},f("NoConfiguration")):React__default.default.createElement("div",{className:"main",style:{height:N}},b(n)))};function mapStateToProps(e){return{toolInstance:e.annotation.toolInstance,imgIndex:e.annotation.imgIndex}}var TagSidebar$1=reactRedux.connect(mapStateToProps)(TagSidebar);exports.default=TagSidebar$1,exports.expandIconFuc=expandIconFuc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),reactRedux=require("react-redux"),_=require("lodash"),index=require("../../../../utils/index.js"),es=require("antd/es"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),reactRedux=require("react-redux"),_=require("lodash"),index=require("../../../../utils/index.js"),es=require("antd/es"),lbAnnotation=require("@labelbee/lb-annotation"),actionCreators=require("../../../../store/annotation/actionCreators.js"),ConfigUtils=require("../../../../utils/ConfigUtils.js"),reactI18next=require("react-i18next");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,a)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,__spreadValues=(e,t)=>{for(var a in t||(t={}))__hasOwnProp.call(t,a)&&__defNormalProp(e,a,t[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(t))__propIsEnum.call(t,a)&&__defNormalProp(e,a,t[a]);return e};const EKeyCode=lbAnnotation.cKeyCode.default,syntheticEventStopPagination=e=>{e.stopPropagation(),e.nativeEvent.stopPropagation(),e.nativeEvent.stopImmediatePropagation()},TextareaWithFooter=e=>{const{textareaProps:t,footer:a}=e;return React__default.default.createElement(React__default.default.Fragment,null,React__default.default.createElement(es.Input.TextArea,__spreadValues({bordered:!1,rows:6,onKeyDown:syntheticEventStopPagination,onKeyUp:syntheticEventStopPagination},t)),React__default.default.createElement("div",{className:index.classnames({textAreaLength:!0})},a))},SingleTextInput=e=>{var t;const a=React.useRef(null),[p,i]=React.useState(!1),[y,m]=React.useState(!1),{t:u}=reactI18next.useTranslation(),{disabled:l,config:s,result:x,updateText:v,index:g,switchToNextTextarea:E,hasMultiple:b,onNext:c}=e,{maxLength:d}=s,f=x?x[s.key]:"",T=(t=f==null?void 0:f.length)!=null?t:0,C=n=>{v&&(v(n,s.key),s.required&&m(!n))},h=b&&E,r={id:`textInput-${g}`,ref:a,disabled:l,value:f,maxLength:d,autoSize:{minRows:2,maxRows:6},onChange:n=>{const P=n.target.value;C(P)},onFocus:()=>{i(!0)},onBlur:n=>{i(!1),s.required&&m(!n.target.value)},style:{resize:"none",wordBreak:"break-all"},onKeyDownCapture:n=>{n.ctrlKey&&n.keyCode===EKeyCode.Enter&&(c&&c(),n.preventDefault()),n.keyCode===EKeyCode.Tab&&h&&(n.preventDefault(),n.nativeEvent.stopImmediatePropagation(),E(g)),n.nativeEvent.stopPropagation()}},o=React__default.default.createElement("div",{className:"textAreaFooter"},React__default.default.createElement("div",{className:"hotkeyTip"},h&&React__default.default.createElement("span",null,`[${u("Switch")}]Tab`),React__default.default.createElement("span",null,`[${u("TurnPage")}]Ctrl+Enter`)),React__default.default.createElement("div",{className:"wordCount"},React__default.default.createElement("span",{className:T>=d?"warning":""},T),"/",React__default.default.createElement("span",null,d)));return React.useEffect(()=>{l&&i(!1)},[l]),React__default.default.createElement("div",{className:"textField"},React__default.default.createElement("div",{className:"label"},React__default.default.createElement("span",{className:index.classnames({required:s.required})},s.label),React__default.default.createElement("i",{className:index.classnames({clearText:!0,disabled:l}),onClick:()=>{l||C("")}})),React__default.default.createElement("div",{className:index.classnames({disabled:l,"textarea-outline":!0,"ant-input-focused":p,textareaContainer:!0,focus:p,invalid:y})},React__default.default.createElement(TextareaWithFooter,{footer:o,textareaProps:r})))},TextToolSidebar=({toolInstance:e,imgIndex:t,dispatch:a,triggerEventAfterIndexChanged:p,step:i,stepList:y,basicResultList:m})=>{var u,l;const[s,x]=React.useState([]),[v,g]=React.useState(0),[,E]=React.useState(0),b=r=>{const o=(r+1)%s.length;c(o)},c=r=>{setTimeout(()=>{const o=document.getElementById(`textInput-${r}`);o&&(g(r),o.focus(),o.select(),o.scrollIntoView({behavior:"smooth",block:"center"}))})};React.useEffect(()=>{e&&(x(_.cloneDeep(e.config.configList)),e.singleOn("valueUpdated",()=>{E(r=>r+1)}))},[e]);const d=(r,o)=>{e.updateTextValue(o,r)};React.useEffect(()=>{t>-1&&p&&c(0)},[t]);const f=(l=(u=e.textList[0])==null?void 0:u.value)!=null?l:{},T=()=>{a(actionCreators.PageForward(!0))},h=ConfigUtils.ConfigUtils.getStepConfig(y,i).dataSourceStep>0&&m.length===0;return React__default.default.createElement("div",{className:"textToolOperationMenu"},s.map((r,o)=>React__default.default.createElement(SingleTextInput,{config:r,key:r.key,index:o,result:f,updateText:d,switchToNextTextarea:b,hasMultiple:s.length>1,focus:v===o,onNext:T,disabled:h})))};function mapStateToProps(e){return{toolInstance:e.annotation.toolInstance,imgIndex:e.annotation.imgIndex,step:e.annotation.step,basicResultList:e.annotation.basicResultList,stepList:e.annotation.stepList,triggerEventAfterIndexChanged:e.annotation.triggerEventAfterIndexChanged}}var TextToolSidebar$1=reactRedux.connect(mapStateToProps)(TextToolSidebar);exports.SingleTextInput=SingleTextInput,exports.TextareaWithFooter=TextareaWithFooter,exports.default=TextToolSidebar$1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),icons=require("@ant-design/icons"),reactRedux=require("react-redux"),index$4=require("../../../index.js"),classNames=require("classnames"),index=require("../../../constant/index.js"),index$3=require("./ExportData/index.js"),index$2=require("./headerOption/index.js"),es=require("antd/es"),actionCreators=require("../../../store/annotation/actionCreators.js"),index$1=require("./StepSwitch/index.js"),lbUtils=require("@
|
|
1
|
+
"use strict";var React=require("react"),icons=require("@ant-design/icons"),reactRedux=require("react-redux"),index$4=require("../../../index.js"),classNames=require("classnames"),index=require("../../../constant/index.js"),index$3=require("./ExportData/index.js"),index$2=require("./headerOption/index.js"),es=require("antd/es"),actionCreators=require("../../../store/annotation/actionCreators.js"),index$1=require("./StepSwitch/index.js"),lbUtils=require("@labelbee/lb-utils"),reactI18next=require("react-i18next"),useSize=require("../../../hooks/useSize.js");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React),classNames__default=_interopDefaultLegacy(classNames);const NextButton=({disabled:e})=>{const{t}=reactI18next.useTranslation();return React__default.default.createElement(es.Button,{type:"primary",style:{marginLeft:10},onClick:()=>{index$4.store.dispatch(actionCreators.ToNextStep(0))},disabled:e},t("NextStep"))},NextStep=({step:e,stepProgress:t,stepList:n})=>{const{t:i}=reactI18next.useTranslation();if(n.length<2||e===n.length)return null;const a=t<1;return a?React__default.default.createElement(es.Tooltip,{title:i("StepNotFinishedNotify")},React__default.default.createElement("span",null,React__default.default.createElement(NextButton,{disabled:a}))):React__default.default.createElement(NextButton,{disabled:a})},ToolHeader=({goBack:e,exportData:t,headerName:n,imgList:i,stepProgress:a,stepInfo:f,stepList:l,step:p,annotationEngine:m})=>{var o;const x=reactRedux.useDispatch(),[,v]=React.useReducer(r=>r+1,0),s=React.useRef(null),c=useSize(s),E=React__default.default.createElement(index$3,{exportData:t}),g=()=>{x(actionCreators.ToSubmitFileData(index.ESubmitType.Quit)),e&&e(i)},u=r=>{lbUtils.i18n.changeLanguage(r),m.setLang(r),v()},d=lbUtils.i18n.language,h=(o=c==null?void 0:c.width)!=null?o:window.innerWidth;return React__default.default.createElement("div",{className:classNames__default.default(`${index.prefix}-header`),ref:s},React__default.default.createElement("div",{className:`${index.prefix}-header__title`},React__default.default.createElement(icons.LeftOutlined,{className:`${index.prefix}-header__icon`,onClick:g}),n?React__default.default.createElement("span",{className:`${index.prefix}-header__name`},n):"",l.length>1&&React__default.default.createElement(React__default.default.Fragment,null,React__default.default.createElement(index$1,{stepProgress:a}),React__default.default.createElement(NextStep,{step:p,stepProgress:a,stepList:l})),E,React__default.default.createElement("div",{id:"operationNode",className:`${index.prefix}-header__operationNode`,style:{left:h/2-174/2}},React__default.default.createElement(index$2,{stepInfo:f})),React__default.default.createElement("div",{className:`${index.prefix}-header__titlePlacement`}),React__default.default.createElement("div",{className:`${index.prefix}-header__lang`},React__default.default.createElement("span",{className:`${index.prefix}-langCN ${d==="cn"?"active":""}`,onClick:()=>u("cn")},"\u4E2D\u6587")," / ",React__default.default.createElement("span",{className:`${index.prefix}-langEN ${d==="en"?"active":""}`,onClick:()=>u("en")},"En"))))},mapStateToProps=e=>{var t;return{imgList:e.annotation.imgList,annotationEngine:e.annotation.annotationEngine,stepProgress:e.annotation.stepProgress,toolName:(t=e.annotation.stepList[e.annotation.step-1])==null?void 0:t.tool,stepList:e.annotation.stepList,stepInfo:e.annotation.stepList[e.annotation.step-1],step:e.annotation.step}};var ToolHeader$1=reactRedux.connect(mapStateToProps)(ToolHeader);module.exports=ToolHeader$1;
|
package/es/App.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import n,{useEffect as i}from"react";import{connect as v}from"react-redux";import{store as _}from"./index.js";import{InitTaskData as g}from"./store/annotation/actionCreators.js";import w from"./views/MainView/index.js";import{i18n as I}from"@labelbee/lb-utils";var O=Object.defineProperty,s=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,l=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,y=(e,t)=>{for(var r in t||(t={}))P.call(t,r)&&l(e,r,t[r]);if(s)for(var r of s(t))b.call(t,r)&&l(e,r,t[r]);return e};const j=e=>{const{imgList:t,step:r,stepList:p,onSubmit:c,onSave:m,initialIndex:f=0,toolInstance:o,setToolInstance:a,getFileData:u,defaultLang:d="cn"}=e;return i(()=>{_.dispatch(g({imgList:t,onSubmit:c,stepList:p,step:r,initialIndex:f,getFileData:u,onSave:m})),I.changeLanguage(d)},[]),i(()=>{a==null||a(o)},[o]),n.createElement("div",null,n.createElement(w,y({},e)))},x=e=>({toolInstance:e.annotation.toolInstance});var E=v(x)(j);export{E as default};
|
package/es/App.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.js","sources":["../src/App.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { connect } from 'react-redux';\nimport { store } from '.';\nimport { AppState } from './store';\nimport { InitTaskData } from './store/annotation/actionCreators';\nimport MainView from '@/views/MainView';\nimport { IStepInfo } from './types/step';\nimport { OnSubmit, GetFileData, OnSave } from './types/data';\nimport { ToolInstance } from './store/annotation/types';\nimport { i18n } from '@
|
|
1
|
+
{"version":3,"file":"App.js","sources":["../src/App.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { connect } from 'react-redux';\nimport { store } from '.';\nimport { AppState } from './store';\nimport { InitTaskData } from './store/annotation/actionCreators';\nimport MainView from '@/views/MainView';\nimport { IStepInfo } from './types/step';\nimport { OnSubmit, GetFileData, OnSave } from './types/data';\nimport { ToolInstance } from './store/annotation/types';\nimport { i18n } from '@labelbee/lb-utils';\n\nexport interface AppProps {\n exportData?: (data: any[]) => void;\n goBack?: () => void;\n imgList: string[];\n config: string;\n stepList: IStepInfo[];\n step: number;\n onSubmit?: OnSubmit;\n onSave?: OnSave;\n getFileData?: GetFileData;\n headerName?: string;\n initialIndex?: number;\n className?: string;\n toolInstance: ToolInstance;\n header?: React.ReactNode;\n footer?: React.ReactNode;\n sider?: React.ReactNode;\n style?: {\n layout?: { [key: string]: any };\n header?: { [key: string]: any };\n sider?: { [key: string]: any };\n footer?: { [key: string]: any };\n };\n setToolInstance?: (tool: ToolInstance) => void;\n mode?: 'light' | 'dark'; // 临时需求应用于 toolFooter 的操作\n defaultLang: 'en' | 'cn'; // 国际化设置\n}\n\nconst App: React.FC<AppProps> = (props) => {\n const {\n imgList,\n step,\n stepList,\n onSubmit,\n onSave,\n initialIndex = 0,\n toolInstance,\n setToolInstance,\n getFileData,\n defaultLang = 'cn',\n } = props;\n useEffect(() => {\n store.dispatch(\n InitTaskData({ imgList, onSubmit, stepList, step, initialIndex, getFileData, onSave }),\n );\n\n // 初始化国际化语言\n i18n.changeLanguage(defaultLang);\n }, []);\n\n useEffect(() => {\n setToolInstance?.(toolInstance);\n }, [toolInstance]);\n\n return (\n <div>\n <MainView {...props} />\n </div>\n );\n};\n\nconst mapStateToProps = (state: AppState) => ({\n toolInstance: state.annotation.toolInstance,\n});\n\nexport default connect(mapStateToProps)(App);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,MAA0B,CAAC,UAAU;AACzC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,MACZ;AACJ,YAAU,MAAM;AACd,UAAM,SACJ,aAAa,CAAE,SAAS,UAAU,UAAU,MAAM,cAAc,aAAa;AAI/E,SAAK,eAAe;AAAA,KACnB;AAEH,YAAU,MAAM;AACd,uDAAkB;AAAA,KACjB,CAAC;AAEJ,6CACG,OAAD,0CACG,UAAD,mBAAc;AAAA;AAKpB,MAAM,kBAAkB,CAAC;AAAqB,EAC5C,cAAc,MAAM,WAAW;AAAA;AAGjC,YAAe,QAAQ,iBAAiB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import m,{useState as z,useRef as g,useImperativeHandle as S,useEffect as u}from"react";import{ViewOperation as E,ImgUtils as C}from"@
|
|
1
|
+
import m,{useState as z,useRef as g,useImperativeHandle as S,useEffect as u}from"react";import{ViewOperation as E,ImgUtils as C}from"@labelbee/lb-annotation";import{Spin as L}from"antd/es";var R=Object.defineProperty,_=Object.getOwnPropertySymbols,A=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,h=(o,t,e)=>t in o?R(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,w=(o,t)=>{for(var e in t||(t={}))A.call(t,e)&&h(o,e,t[e]);if(_)for(var e of _(t))V.call(t,e)&&h(o,e,t[e]);return o};const Z={width:1280,height:720},j=(o,t)=>{const{size:e=Z,src:p,annotations:s=[],style:b={color:"blue",thickness:5},zoomChange:c,backgroundStyle:y={},onChange:d,showLoading:I=!1}=o,[O,f]=z(!1),v=g(null),n=g();S(t,()=>{const r=n.current;return r?{zoomIn:()=>r.zoomChanged(!0),zoomOut:()=>r.zoomChanged(!1),initImgPos:()=>r.initImgPos(),toolInstance:r}:{}},[n.current]),u(()=>(v.current&&(n.current=new E({container:v.current,size:e,style:b,annotations:s,config:"{}"}),n.current.init()),()=>{var r;(r=n.current)==null||r.destroy()}),[]),u(()=>{var r;n.current&&(f(!0),(r=n.current)==null||r.setLoading(!0),C.load(p).then(i=>{var a,l;(a=n.current)==null||a.setLoading(!1),f(!1),(l=n.current)==null||l.setImgNode(i)}).catch(()=>{var i;(i=n.current)==null||i.setLoading(!1),f(!1)}))},[p]),u(()=>{n.current&&n.current.updateData(s)},[s]),u(()=>{const r=n.current;(r==null?void 0:r.setSize)&&r.setSize(e)},[e==null?void 0:e.width,e==null?void 0:e.height]),u(()=>{var r,i;return n.current&&((r=n.current)==null||r.on("onChange",(...a)=>{d==null||d.apply(null,a)}),(i=n.current)==null||i.on("renderZoom",a=>{c&&c(a)})),()=>{var a,l;(a=n.current)==null||a.unbindAll("onChange"),(l=n.current)==null||l.unbindAll("renderZoom")}},[c,d]);const P=m.createElement("div",{ref:v,style:w(w({},e),y)});return m.createElement(L,{spinning:I||O,delay:300},P)};var x=m.forwardRef(j);export{x as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/AnnotationView/index.tsx"],"sourcesContent":["/**\n * 用于标注查看模式\n * @author laoluo\n */\n\nimport React, { useEffect, useRef, useImperativeHandle, useState } from 'react';\nimport { ViewOperation, ImgUtils } from '@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/AnnotationView/index.tsx"],"sourcesContent":["/**\n * 用于标注查看模式\n * @author laoluo\n */\n\nimport React, { useEffect, useRef, useImperativeHandle, useState } from 'react';\nimport { ViewOperation, ImgUtils } from '@labelbee/lb-annotation';\nimport { Spin } from 'antd/es';\n\ninterface IProps {\n src: string; // 图片路径\n size: {\n width: number;\n height: number;\n };\n style: {\n color?: string;\n fill?: string;\n thickness?: number;\n };\n annotations: any[]; // TODO\n zoomChange?: (zoom: number) => void;\n backgroundStyle: React.CSSProperties;\n onChange?: (type: 'hover' | 'selected', ids: string[]) => void;\n\n showLoading?: boolean;\n}\n\nconst DEFAULT_SIZE = {\n width: 1280,\n height: 720,\n};\n\nconst AnnotationView = (props: IProps, ref: any) => {\n const {\n size = DEFAULT_SIZE,\n src,\n annotations = [],\n style = {\n color: 'blue',\n thickness: 5,\n },\n zoomChange,\n backgroundStyle = {},\n onChange,\n showLoading = false,\n } = props;\n const [loading, setLoading] = useState(false);\n const annotationRef = useRef<HTMLDivElement>(null);\n const viewOperation = useRef<ViewOperation>();\n\n useImperativeHandle(\n ref,\n () => {\n const toolInstance = viewOperation.current;\n if (!toolInstance) {\n return {};\n }\n\n return {\n zoomIn: () => toolInstance.zoomChanged(true), // 放大\n zoomOut: () => toolInstance.zoomChanged(false), // 缩小\n initImgPos: () => toolInstance.initImgPos(),\n toolInstance,\n };\n },\n [viewOperation.current],\n );\n\n useEffect(() => {\n if (annotationRef.current) {\n viewOperation.current = new ViewOperation({\n container: annotationRef.current,\n size,\n style,\n annotations,\n config: '{}', // TODO,暂时不需要\n });\n\n viewOperation.current.init();\n }\n\n return () => {\n viewOperation.current?.destroy();\n };\n }, []);\n\n useEffect(() => {\n if (viewOperation.current) {\n setLoading(true);\n viewOperation.current?.setLoading(true);\n ImgUtils.load(src)\n .then((imgNode: HTMLImageElement) => {\n viewOperation.current?.setLoading(false);\n setLoading(false);\n\n viewOperation.current?.setImgNode(imgNode);\n })\n .catch(() => {\n viewOperation.current?.setLoading(false);\n setLoading(false);\n });\n }\n }, [src]);\n\n /**\n * 基础数据绘制监听\n */\n useEffect(() => {\n if (viewOperation.current) {\n viewOperation.current.updateData(annotations);\n }\n }, [annotations]);\n\n /** 窗口大小监听 */\n useEffect(() => {\n const toolInstance = viewOperation.current;\n\n if (toolInstance?.setSize) {\n toolInstance.setSize(size);\n }\n }, [size?.width, size?.height]);\n\n useEffect(() => {\n if (viewOperation.current) {\n viewOperation.current?.on('onChange', (...args: any) => {\n onChange?.apply(null, args);\n });\n\n viewOperation.current?.on('renderZoom', (zoom: number) => {\n if (zoomChange) {\n zoomChange(zoom);\n }\n });\n }\n return () => {\n viewOperation.current?.unbindAll('onChange');\n viewOperation.current?.unbindAll('renderZoom');\n };\n }, [zoomChange, onChange]);\n\n const mainRender = <div ref={annotationRef} style={{ ...size, ...backgroundStyle }} />;\n\n return (\n <Spin spinning={showLoading || loading} delay={300}>\n {mainRender}\n </Spin>\n );\n\n // return mainRender;\n};\n\nexport default React.forwardRef(AnnotationView);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,QAAQ;AAAA;AAGV,MAAM,iBAAiB,CAAC,OAAe,QAAa;AAClD,QAAM;AAAA,IACJ,OAAO;AAAA,IACP;AAAA,IACA,cAAc;AAAA,IACd,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,WAAW;AAAA;AAAA,IAEb;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA,cAAc;AAAA,MACZ;AACJ,QAAM,CAAC,SAAS,cAAc,SAAS;AACvC,QAAM,gBAAgB,OAAuB;AAC7C,QAAM,gBAAgB;AAEtB,sBACE,KACA,MAAM;AACJ,UAAM,eAAe,cAAc;AACnC,QAAI,CAAC,cAAc;AACjB,aAAO;AAAA;AAGT,WAAO;AAAA,MACL,QAAQ,MAAM,aAAa,YAAY;AAAA,MACvC,SAAS,MAAM,aAAa,YAAY;AAAA,MACxC,YAAY,MAAM,aAAa;AAAA,MAC/B;AAAA;AAAA,KAGJ,CAAC,cAAc;AAGjB,YAAU,MAAM;AACd,QAAI,cAAc,SAAS;AACzB,oBAAc,UAAU,IAAI,cAAc;AAAA,QACxC,WAAW,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AAS,OAAO;AAAA,KAC5C;AAAA;AAOP,YAAe,MAAM,WAAW;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{editStepWidth as
|
|
1
|
+
import{editStepWidth as f,sidebarWidth as s,headerHeight as p,footerHeight as g}from"../../data/enums/AnnotationSize.js";import{cKeyCode as u,toolUtils as y}from"@labelbee/lb-annotation";import c,{useState as w,useEffect as C,useMemo as k}from"react";import{connect as v}from"react-redux";import{PageBackward as H,PageForward as E,UpdateRotate as P}from"../../store/annotation/actionCreators.js";const h=u.default,l=c.createContext({width:window.innerWidth,height:window.innerHeight}),m=t=>{const{children:d,dispatch:o}=t,[i]=w(window.innerWidth),[r]=w(window.innerHeight),n=e=>{!y.hotkeyFilter(e)||(e.keyCode===h.A&&o(H()),e.keyCode===h.D&&o(E()),e.keyCode===h.R&&o(P()))};C(()=>(window.addEventListener("keydown",n),()=>{window.removeEventListener("keydown",n)}),[]);const a=k(()=>({width:i,height:r}),[i,r]);return c.createElement(l.Provider,{value:a},d)},W=v(t=>({annotation:t.annotation}))(m),b=(t,d=!1,o=!1)=>{const{width:i,height:r}=t,n=p+g,a=o?40+n+40:n,e=d?f+s:s;return{width:i-e,height:r-a}};export{W as ViewportProvider,m as ViewportProviderComponent,b as getFormatSize,l as viewportContext};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/customResizeHook/index.tsx"],"sourcesContent":["import {\n editStepWidth,\n footerHeight,\n headerHeight,\n sidebarWidth,\n} from '@/data/enums/AnnotationSize';\nimport { cKeyCode, toolUtils } from '@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/customResizeHook/index.tsx"],"sourcesContent":["import {\n editStepWidth,\n footerHeight,\n headerHeight,\n sidebarWidth,\n} from '@/data/enums/AnnotationSize';\nimport { cKeyCode, toolUtils } from '@labelbee/lb-annotation';\n\nimport React, { useContext, useEffect, useMemo, useState } from 'react';\nimport { connect } from 'react-redux';\nimport { AppState } from '@/store';\nimport { UpdateRotate, PageBackward, PageForward } from '@/store/annotation/actionCreators';\nimport { ISize } from '@/types/main';\nimport { DEFAULT_CANVAS_SIZE } from '@/constant';\n\nconst EKeyCode = cKeyCode.default;\n\nexport const viewportContext = React.createContext<{\n width: number;\n height: number;\n}>({\n width: window ? window?.innerWidth ?? DEFAULT_CANVAS_SIZE.width : 0,\n height: window ? window?.innerHeight ?? DEFAULT_CANVAS_SIZE.height : 0,\n});\n\nexport const ViewportProviderComponent = (props: any) => {\n const { children, dispatch } = props;\n const [width] = useState(window ? window?.innerWidth ?? DEFAULT_CANVAS_SIZE.width : 0);\n const [height] = useState(window ? window?.innerHeight ?? DEFAULT_CANVAS_SIZE.height : 0);\n\n const keydown = (e: KeyboardEvent) => {\n if (!toolUtils.hotkeyFilter(e)) {\n return;\n }\n if (e.keyCode === EKeyCode.A) {\n dispatch(PageBackward());\n }\n\n if (e.keyCode === EKeyCode.D) {\n dispatch(PageForward());\n }\n if (e.keyCode === EKeyCode.R) {\n dispatch(UpdateRotate());\n }\n };\n\n useEffect(() => {\n if (!window) {\n return;\n }\n\n window?.addEventListener('keydown', keydown);\n\n return () => {\n if (!window) {\n return;\n }\n window?.removeEventListener('keydown', keydown);\n };\n }, []);\n\n const size = useMemo(() => ({ width, height }), [width, height]);\n\n return <viewportContext.Provider value={size}>{children}</viewportContext.Provider>;\n};\n\nexport const ViewportProvider = connect((state: AppState) => ({\n annotation: state.annotation,\n}))(ViewportProviderComponent);\n\nexport const useViewport = () => {\n const { width, height } = useContext(viewportContext);\n return { width, height };\n};\n\n/**\n * 获取当前 canvas 的大小\n * @param isEdit 是否为编辑模式\n * @param isTips 是否有 tips\n */\nexport const useCanvasViewPort = (isEdit = false, isTips = false) => {\n const { width, height } = useContext(viewportContext);\n const otherHeight = headerHeight + footerHeight;\n const placeholderHeight = isTips ? 40 + otherHeight + 40 : otherHeight;\n const placeholderWidth = isEdit ? editStepWidth + sidebarWidth : sidebarWidth;\n\n return {\n width: width - placeholderWidth,\n height: height - placeholderHeight,\n };\n};\n\n/**\n * 解析当前 windowSize 下的 canvasSize\n * @param size\n * @param isEdit\n * @param isTips\n */\nexport const getFormatSize = (windowSize: ISize, isEdit = false, isTips = false) => {\n const { width, height } = windowSize;\n const otherHeight = headerHeight + footerHeight;\n const placeholderHeight = isTips ? 40 + otherHeight + 40 : otherHeight;\n const placeholderWidth = isEdit ? editStepWidth + sidebarWidth : sidebarWidth;\n\n return {\n width: width - placeholderWidth,\n height: height - placeholderHeight,\n };\n};\n"],"names":[],"mappings":";;;;;;;AAAA;AAeA,MAAM,WAAW,SAAS;MAEb,kBAAkB,MAAM,cAGlC;AAAA,EACD,OAAO,SAAS,uCAAQ,eAAR,YAAsB,oBAAoB,QAAQ;AAAA,EAClE,QAAQ,SAAS,uCAAQ,gBAAR,YAAuB,oBAAoB,SAAS;AAAA;MAG1D,4BAA4B,CAAC,UAAe;AAzBzD;AA0BE,QAAM,CAAE,UAAU,YAAa;AAC/B,QAAM,CAAC,SAAS,SAAS,SAAS,wCAAQ,eAAR,aAAsB,oBAAoB,QAAQ;AACpF,QAAM,CAAC,UAAU,SAAS,SAAS,wCAAQ,gBAAR,aAAuB,oBAAoB,SAAS;AAEvF,QAAM,UAAU,CAAC,MAAqB;AACpC,QAAI,CAAC,UAAU,aAAa,IAAI;AAC9B;AAAA;AAEF,QAAI,EAAE,YAAY,SAAS,GAAG;AAC5B,eAAS;AAAA;AAGX,QAAI,EAAE,YAAY,SAAS,GAAG;AAC5B,eAAS;AAAA;AAEX,QAAI,EAAE,YAAY,SAAS,GAAG;AAC5B,eAAS;AAAA;AAAA;AAIb,YAAU,MAAM;AACd,QAAI,CAAC,QAAQ;AACX;AAAA;AAGF,qCAAQ,iBAAiB,WAAW;AAEpC,WAAO,MAAM;AACX,UAAI,CAAC,QAAQ;AACX;AAAA;AAEF,uCAAQ,oBAAoB,WAAW;AAAA;AAAA,KAExC;AAEH,QAAM,OAAO,QAAQ,QAAS,OAAO,UAAW,CAAC,OAAO;AAExD,6CAAQ,gBAAgB,UAAjB;AAAA,IAA0B,OAAO;AAAA,KAAO;AAAA;MAGpC,mBAAmB,QAAQ,CAAC;AAAqB,EAC5D,YAAY,MAAM;AAAA,IAChB;MA8BS,gBAAgB,CAAC,YAAmB,SAAS,OAAO,SAAS,UAAU;AAClF,QAAM,CAAE,OAAO,UAAW;AAC1B,QAAM,cAAc,eAAe;AACnC,QAAM,oBAAoB,SAAS,KAAK,cAAc,KAAK;AAC3D,QAAM,mBAAmB,SAAS,gBAAgB,eAAe;AAEjE,SAAO;AAAA,IACL,OAAO,QAAQ;AAAA,IACf,QAAQ,SAAS;AAAA;AAAA;;;;"}
|
package/es/constant/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/constant/index.tsx"],"sourcesContent":["export enum EStepType {\n Check = 0, // 查看模式\n ANNOTATION = 1, // 正常标注\n QUALITY_INSPECTION, // 标注质检\n PRE_ANNOTATION, // 预标注\n MANUAL_CORRECTION, // 人工修正\n}\n\nexport enum ESubmitType {\n Backward = 1, // 向前翻页\n Forward = 2, // 向后翻页\n Jump = 3, // 分页器的跳页翻页\n Quit = 4, // 左上角后退触发\n Export = 5, // 数据导出时\n StepChanged = 6, // 切换步骤\n Save = 7, // 点击保存\n}\n// css 命名前缀\nexport const prefix = 'bee';\nexport const componentCls = `${prefix}-component`;\n"],"names":[],"mappings":"IAAY;AAAL,UAAK,YAAL;AACL,mCAAQ,KAAR;AACA,wCAAa,KAAb;AACA;AACA;AACA;AAAA,GALU;IAQA;AAAL,UAAK,cAAL;AACL,0CAAW,KAAX;AACA,yCAAU,KAAV;AACA,sCAAO,KAAP;AACA,sCAAO,KAAP;AACA,wCAAS,KAAT;AACA,6CAAc,KAAd;AACA,sCAAO,KAAP;AAAA,GAPU;MAUC,SAAS;MACT,eAAe,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/constant/index.tsx"],"sourcesContent":["export enum EStepType {\n Check = 0, // 查看模式\n ANNOTATION = 1, // 正常标注\n QUALITY_INSPECTION, // 标注质检\n PRE_ANNOTATION, // 预标注\n MANUAL_CORRECTION, // 人工修正\n}\n\nexport enum ESubmitType {\n Backward = 1, // 向前翻页\n Forward = 2, // 向后翻页\n Jump = 3, // 分页器的跳页翻页\n Quit = 4, // 左上角后退触发\n Export = 5, // 数据导出时\n StepChanged = 6, // 切换步骤\n Save = 7, // 点击保存\n}\n// css 命名前缀\nexport const prefix = 'bee';\nexport const componentCls = `${prefix}-component`;\n\nexport const DEFAULT_CANVAS_SIZE = {\n width: 500,\n height: 300,\n};\n"],"names":[],"mappings":"IAAY;AAAL,UAAK,YAAL;AACL,mCAAQ,KAAR;AACA,wCAAa,KAAb;AACA;AACA;AACA;AAAA,GALU;IAQA;AAAL,UAAK,cAAL;AACL,0CAAW,KAAX;AACA,yCAAU,KAAV;AACA,sCAAO,KAAP;AACA,sCAAO,KAAP;AACA,wCAAS,KAAT;AACA,6CAAc,KAAd;AACA,sCAAO,KAAP;AAAA,GAPU;MAUC,SAAS;MACT,eAAe,GAAG;MAElB,sBAAsB;AAAA,EACjC,OAAO;AAAA,EACP,QAAQ;AAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRafState.js","sources":["../../src/hooks/useRafState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from 'react';\nimport { useCallback, useRef, useState, useEffect } from 'react';\n\nconst useRafState = <S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>] => {\n const frame = useRef(0);\n const [state, setState] = useState(initialState);\n\n const setRafState = useCallback((value: S | ((prevState: S) => S)) => {\n cancelAnimationFrame(frame.current);\n\n frame.current = requestAnimationFrame(() => {\n setState(value);\n });\n }, []);\n\n useEffect(() => {\n return () => cancelAnimationFrame(frame.current);\n }, [])
|
|
1
|
+
{"version":3,"file":"useRafState.js","sources":["../../src/hooks/useRafState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from 'react';\nimport { useCallback, useRef, useState, useEffect } from 'react';\n\nconst useRafState = <S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>] => {\n const frame = useRef(0);\n const [state, setState] = useState(initialState);\n\n const setRafState = useCallback((value: S | ((prevState: S) => S)) => {\n if (!cancelAnimationFrame || !requestAnimationFrame) {\n return;\n }\n\n cancelAnimationFrame(frame.current);\n\n frame.current = requestAnimationFrame(() => {\n setState(value);\n });\n }, []);\n\n useEffect(() => {\n if (!cancelAnimationFrame) {\n return;\n }\n\n return () => cancelAnimationFrame(frame.current);\n }, []);\n\n return [state, setRafState];\n};\n\nexport default useRafState;\n"],"names":[],"mappings":";;MAGM,cAAc,CAAI,iBAAkE;AACxF,QAAM,QAAQ,OAAO;AACrB,QAAM,CAAC,OAAO,YAAY,SAAS;AAEnC,QAAM,cAAc,YAAY,CAAC,UAAqC;AACpE,QAAI,CAAC,wBAAwB,CAAC,uBAAuB;AACnD;AAAA;AAGF,yBAAqB,MAAM;AAE3B,UAAM,UAAU,sBAAsB,MAAM;AAC1C,eAAS;AAAA;AAAA,KAEV;AAEH,YAAU,MAAM;AACd,QAAI,CAAC,sBAAsB;AACzB;AAAA;AAGF,WAAO,MAAM,qBAAqB,MAAM;AAAA,KACvC;AAEH,SAAO,CAAC,OAAO;AAAA;;;;"}
|
package/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import a,{useState as
|
|
1
|
+
import a,{useState as l,useImperativeHandle as m}from"react";import{Provider as f}from"react-redux";import d from"./configureStore.js";import u from"./App.js";import{PageBackward as w,PageForward as _,PageJump as P}from"./store/annotation/actionCreators.js";import{i18n as g}from"@labelbee/lb-utils";export{i18n}from"@labelbee/lb-utils";import{I18nextProvider as v}from"react-i18next";export{default as AnnotationView}from"./components/AnnotationView/index.js";import{getWindow as O}from"ssr-window";var b=Object.defineProperty,x=Object.defineProperties,j=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,p=(t,e,r)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,A=(t,e)=>{for(var r in e||(e={}))h.call(e,r)&&p(t,r,e[r]);if(n)for(var r of n(e))y.call(e,r)&&p(t,r,e[r]);return t},I=(t,e)=>x(t,j(e));window=O();const o=d(),E=(t,e)=>{const[r,i]=l();return m(e,()=>({toolInstance:r,pageBackwardActions:()=>o.dispatch(w()),pageForwardActions:()=>o.dispatch(_()),pageJump:s=>{const c=~~s-1;o.dispatch(P(c))},hello:()=>alert("hello labelBee!!!")}),[r]),a.createElement(f,{store:o},a.createElement(v,{i18n:g},a.createElement(u,I(A({},t),{setToolInstance:i}))))};var S=a.forwardRef(E);export{S as default,o as store};
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import React, { useImperativeHandle, useState } from 'react';\nimport { Provider } from 'react-redux';\nimport { AnyAction } from 'redux';\nimport configureStore from './configureStore';\nimport { ToolInstance } from './store/annotation/types';\nimport App from './App';\nimport { PageBackward, PageForward, PageJump } from './store/annotation/actionCreators';\nimport { i18n } from '@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import React, { useImperativeHandle, useState } from 'react';\nimport { Provider } from 'react-redux';\nimport { AnyAction } from 'redux';\nimport configureStore from './configureStore';\nimport { ToolInstance } from './store/annotation/types';\nimport App from './App';\nimport { PageBackward, PageForward, PageJump } from './store/annotation/actionCreators';\nimport { i18n } from '@labelbee/lb-utils';\nimport { I18nextProvider } from 'react-i18next';\nimport AnnotationView from '@/components/AnnotationView';\n\nexport const store = configureStore();\n\nconst OutputApp = (props: any, ref: any) => {\n const [toolInstance, setToolInstance] = useState<ToolInstance>();\n // 暴露给 ref 的一些方法\n useImperativeHandle(\n ref,\n () => {\n return {\n toolInstance,\n pageBackwardActions: () => store.dispatch(PageBackward() as unknown as AnyAction),\n pageForwardActions: () => store.dispatch(PageForward() as unknown as AnyAction),\n pageJump: (page: string) => {\n const imgIndex = ~~page - 1;\n store.dispatch(PageJump(imgIndex) as unknown as AnyAction);\n },\n hello: () => alert(`hello labelBee!!!`),\n };\n },\n [toolInstance],\n );\n\n return (\n <Provider store={store}>\n <I18nextProvider i18n={i18n}>\n <App {...props} setToolInstance={setToolInstance} />\n </I18nextProvider>\n </Provider>\n );\n};\n\nexport default React.forwardRef(OutputApp);\n\nexport { AnnotationView, i18n };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAWa,QAAQ;AAErB,MAAM,YAAY,CAAC,OAAY,QAAa;AAC1C,QAAM,CAAC,cAAc,mBAAmB;AAExC,sBACE,KACA,MAAM;AACJ,WAAO;AAAA,MACL;AAAA,MACA,qBAAqB,MAAM,MAAM,SAAS;AAAA,MAC1C,oBAAoB,MAAM,MAAM,SAAS;AAAA,MACzC,UAAU,CAAC,SAAiB;AAC1B,cAAM,WAAW,CAAC,CAAC,OAAO;AAC1B,cAAM,SAAS,SAAS;AAAA;AAAA,MAE1B,OAAO,MAAM,MAAM;AAAA;AAAA,KAGvB,CAAC;AAGH,6CACG,UAAD;AAAA,IAAU;AAAA,yCACP,iBAAD;AAAA,IAAiB;AAAA,yCACd,KAAD,iCAAS,QAAT;AAAA,IAAgB;AAAA;AAAA;AAMxB,YAAe,MAAM,WAAW;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ANNOTATION_ACTIONS as i}from"../Actions.js";import tt from"lodash";import{composeResultWithBasicImgInfo as et,composeResult as nt}from"../../utils/data.js";import{jsonParser as
|
|
1
|
+
import{ANNOTATION_ACTIONS as i}from"../Actions.js";import tt from"lodash";import{composeResultWithBasicImgInfo as et,composeResult as nt}from"../../utils/data.js";import{jsonParser as N}from"../../utils/index.js";import k from"../../utils/StepUtils.js";import B from"../../utils/AnnotationDataUtils.js";import{ConfigUtils as ot}from"../../utils/ConfigUtils.js";import st from"../../constant/styleString.js";import{getFormatSize as rt}from"../../components/customResizeHook/index.js";import{CommonToolUtils as it,AnnotationEngine as lt,ImgUtils as ut}from"@labelbee/lb-annotation";import{message as K}from"antd/es";import{SetAnnotationLoading as U}from"./actionCreators.js";var at=Object.defineProperty,ct=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,X=Object.getOwnPropertySymbols,dt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,J=(t,e,o)=>e in t?at(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,l=(t,e)=>{for(var o in e||(e={}))dt.call(e,o)&&J(t,o,e[o]);if(X)for(var o of X(e))gt.call(e,o)&&J(t,o,e[o]);return t},a=(t,e)=>ct(t,pt(e)),ft=(t,e,o)=>new Promise((I,g)=>{var E=c=>{try{S(o.next(c))}catch(y){g(y)}},D=c=>{try{S(o.throw(c))}catch(y){g(y)}},S=c=>c.done?I(c.value):Promise.resolve(c.value).then(E,D);S((o=o.apply(t,e)).next())});const O=(t,e)=>t.find(o=>o.step===e),mt={annotationEngine:null,toolInstance:null,imgList:[],config:"{}",imgIndex:-1,basicIndex:0,imgPageSize:1,step:1,stepList:[],imgNode:new Image,basicResultList:[],resultList:[],stepProgress:0,loading:!1,triggerEventAfterIndexChanged:!1},_t=t=>{const{imgList:e,imgPageSize:o}=t;return Math.ceil(e.length/o)},Y=(t,e)=>t.reduce((o,I)=>{const g=I.result;return N(g)[`step_${e}`]?o+1:o},0)/t.length,It=(t,e)=>{const{step:o,stepList:I}=t,g=k.getCurrentStepInfo(o,I),E=ot.jsonParser(g.config),D=document.getElementById("toolContainer");if(!D)throw"Not exist dom named id-toolContainer";const S=rt({width:window.innerWidth,height:window.innerHeight}),c=new lt({container:D,toolName:g.tool,size:S,imgNode:e,config:E,style:JSON.parse(st)});return{toolInstance:c.toolInstance,annotationEngine:c}},Et=(t,e)=>(o,I)=>ft(void 0,null,function*(){const{getFileData:g,imgList:E,toolInstance:D}=I().annotation;if(U(o,!0),g){const c=yield g(E[t],t);o({type:i.SET_FILE_DATA,payload:{fileData:c,index:t}})}const{url:S}=E[t];return ut.load(S).then(c=>{U(o,!1),o({type:i.LOAD_FILE_DATA,payload:{imgNode:c,nextIndex:t,nextBasicIndex:e}})}).catch(()=>{U(o,!1),D.setErrorImg(),o({type:i.LOAD_FILE_DATA,payload:{nextIndex:t,nextBasicIndex:e}})})}),St=(t=mt,e)=>{var o,I,g,E,D,S,c,y,j,x,G,z,M,$,H;switch(e.type){case i.UPDATE_TOOL_INSTANCE:return a(l({},t),{toolInstance:e.payload.toolInstance});case i.UPDATE_IMG_LIST:return a(l({},t),{imgList:e.payload.imgList});case i.CALC_STEP_PROGRESS:{const{imgList:n,step:s}=t,r=Y(n,s);return a(l({},t),{stepProgress:r})}case i.SUBMIT_FILE_DATA:{const{imgList:n,imgIndex:s,step:r,stepList:u,toolInstance:p,onSubmit:d,resultList:_}=t;if(!p)return t;const f=((o=n[s])==null?void 0:o.result)||"",[,m]=p.exportData(),L=et(f,m),v=nt(L,{step:r,stepList:u},{rect:_});n[s].result=B.dataCorrection(v,f,r,u),d&&d([n[s]],(I=e.payload)==null?void 0:I.submitType,s);const T=Y(n,r);return a(l({},t),{stepProgress:T,imgList:n})}case i.SAVE_RESULT:{const{imgList:n,imgIndex:s,onSave:r}=t;return r==null||r(n[s],s,n),l({},t)}case i.SUBMIT_RESULT:{const{imgList:n,basicIndex:s,resultList:r,annotationEngine:u,basicResultList:p}=t;if(!u)return t;const[d]=u.toolInstance.exportData();let _=d;if((p==null?void 0:p.length)>0){const f=(g=p[s])==null?void 0:g.id,m=d.map(L=>a(l({},L),{sourceID:f}));_=tt.cloneDeep(r).filter(L=>L.sourceID!==f),_.push(...m)}return a(l({},t),{resultList:_,imgList:n})}case i.SET_BASIC_INDEX:{const{toolInstance:n,step:s,imgList:r,imgIndex:u,stepList:p,annotationEngine:d,resultList:_,basicResultList:f}=t;if(!n||!d)return t;const m=e.payload.basicIndex,L=(E=f[m])==null?void 0:E.id,v=N((D=r[u])==null?void 0:D.result),T=(_||[]).filter(w=>w.sourceID===L),h=O(p,s),{dataSourceStep:P,tool:F}=h,C=O(p,P);let A=[];return P&&F&&(A=(S=v[`step_${P}`])==null?void 0:S.result,(A==null?void 0:A.length)>0?(d.setBasicInfo(C.tool,A[m]),d.launchOperation()):(d.setBasicInfo(C.tool),d.forbidOperation(),K.info("\u5F53\u524D\u6587\u4EF6\u4E0D\u5B58\u5728\u4F9D\u8D56\u6570\u636E"))),n.setResult(T),n.history.initRecord(T,!0),a(l({},t),{basicIndex:m})}case i.SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED:{const{triggerEventAfterIndexChanged:n}=e.payload;return a(l({},t),{triggerEventAfterIndexChanged:!!n})}case i.LOAD_FILE_DATA:{const{imgList:n,step:s,toolInstance:r,annotationEngine:u,stepList:p}=t;if(!r||!u)return t;const d=k.getCurrentStepInfo(s,p),{nextIndex:_,imgNode:f,nextBasicIndex:m,imgError:L}=e.payload,v=m!=null?m:0,T=N((c=n[_])==null?void 0:c.result),h=T[`step_${s}`],P=!h,F={rotate:(y=T.rotate)!=null?y:0,valid:(j=T.valid)!=null?j:!0};f&&L!==!0&&u.setImgNode(f,F);const C=O(p,s),{dataSourceStep:A,tool:w}=C,V=O(p,A),W=A&&w,R=(G=(x=T[`step_${A}`])==null?void 0:x.result)!=null?G:[],b=B.getInitialResultList(h==null?void 0:h.result,r,C,R,P);if(u.launchOperation(),W&&((R==null?void 0:R.length)>0?u.setBasicInfo(V.tool,R[v]):(u.setBasicInfo(V.tool),u.forbidOperation(),K.info("\u5F53\u524D\u6587\u4EF6\u4E0D\u5B58\u5728\u4F9D\u8D56\u6570\u636E"))),d.tool!=="check"){const q=(M=(z=R[v])==null?void 0:z.id)!=null?M:"",Q=W?b.filter(Z=>it.isSameSourceID(Z.sourceID,q)):b;r.setResult(Q),r.history.initRecord(b,!0)}return a(l({},t),{imgIndex:_,basicIndex:v,basicResultList:R,resultList:b})}case i.UPDATE_ANNOTATION_CONFIG:return a(l({},t),{config:($=e.payload.config)!=null?$:"{}"});case i.SET_TASK_CONFIG:{const{stepList:n,step:s}=e.payload;return a(l({},t),{stepList:n,step:s})}case i.INIT_TOOL:{const{imgNode:n}=t,{toolInstance:s,annotationEngine:r}=It(t,n);return a(l({},t),{toolInstance:s,annotationEngine:r})}case i.UPDATE_ON_SUBMIT:return a(l({},t),{onSubmit:e.payload.onSubmit});case i.UPDATE_ON_SAVE:return a(l({},t),{onSave:e.payload.onSave});case i.UPDATE_GET_FILE_DATA:return a(l({},t),{getFileData:e.payload.getFileData});case i.SET_FILE_DATA:{const{fileData:n,index:s}=e.payload,{imgList:r}=t;return r[s]=l(l({},r[s]),n),a(l({},t),{imgList:r})}case i.UPDATE_ROTATE:{const{toolInstance:n}=t;return n==null||n.updateRotate(),t}case i.COPY_BACKWARD_RESULT:{const{toolInstance:n,imgIndex:s,imgList:r,step:u}=t;if(!n)return t;if(s===0||s>=r.length)return console.error("\u65E0\u6CD5\u590D\u5236\u8FB9\u754C\u5916\u7684\u5185\u5BB9"),t;const p=r[s-1].result;if(!p)return t;const d=B.copyResultChange(p,u,(H=r[s].result)!=null?H:"");r[s].result=d;const f=N(d)[`step_${u}`],m=(f==null?void 0:f.result)||[];return n.setResult(m),n.history.pushHistory(m),a(l({},t),{imgList:[...r]})}case i.SET_STEP:{const{stepList:n,annotationEngine:s}=t,{toStep:r}=e.payload;if(!s)return t;if(r<=n.length){const u=O(n,r);return s.setToolName(u.tool,u.config),a(l({},t),{step:r,toolInstance:s.toolInstance})}break}case i.SET_LOADING:{const{loading:n}=e.payload;return a(l({},t),{loading:!!n})}default:return t}return t};export{Et as LoadImageAndFileData,St as annotationReducer,O as getStepConfig,_t as getTotalPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.js","sources":["../../../src/store/annotation/reducer.ts"],"sourcesContent":["import { ANNOTATION_ACTIONS } from '@/store/Actions';\nimport _ from 'lodash';\nimport { composeResultWithBasicImgInfo, composeResult } from '@/utils/data';\nimport { jsonParser } from '@/utils';\nimport StepUtils from '@/utils/StepUtils';\nimport AnnotationDataUtils from '@/utils/AnnotationDataUtils';\nimport { ConfigUtils } from '@/utils/ConfigUtils';\nimport styleString from '@/constant/styleString';\nimport { getFormatSize } from '@/components/customResizeHook';\nimport { AnnotationEngine, CommonToolUtils, ImgUtils } from '@sensetime/annotation';\nimport { AnnotationState, AnnotationActionTypes } from './types';\nimport { message } from 'antd/es';\nimport { SetAnnotationLoading } from './actionCreators';\n\nexport const getStepConfig = (stepList: any[], step: number) =>\n stepList.find((i) => i.step === step);\n\nconst initialState: AnnotationState = {\n annotationEngine: null,\n toolInstance: null,\n imgList: [],\n config: '{}',\n imgIndex: -1,\n basicIndex: 0,\n imgPageSize: 1,\n step: 1,\n stepList: [],\n imgNode: new Image(),\n basicResultList: [],\n resultList: [],\n stepProgress: 0,\n loading: false,\n triggerEventAfterIndexChanged: false,\n};\n\n/**\n * 获取当前文件列表的总页数\n * @param state\n */\nexport const getTotalPage = (state: AnnotationState) => {\n const { imgList, imgPageSize } = state;\n return Math.ceil(imgList.length / imgPageSize);\n};\n\nconst calcStepProgress = (fileList: any[], step: number) =>\n fileList.reduce((pre, i) => {\n const resultStr = i.result;\n const resultObject = jsonParser(resultStr);\n if (resultObject[`step_${step}`]) {\n return pre + 1;\n }\n return pre;\n }, 0) / fileList.length;\n\nconst updateToolInstance = (annotation: AnnotationState, imgNode: HTMLImageElement) => {\n const { step, stepList } = annotation;\n const stepConfig = StepUtils.getCurrentStepInfo(step, stepList);\n const config = ConfigUtils.jsonParser(stepConfig.config);\n\n const container = document.getElementById('toolContainer');\n\n if (!container) {\n throw `Not exist dom named id-toolContainer`;\n }\n\n const canvasSize = getFormatSize({ width: window.innerWidth, height: window.innerHeight });\n const annotationEngine = new AnnotationEngine({\n container,\n toolName: stepConfig.tool,\n size: canvasSize,\n imgNode,\n config,\n style: JSON.parse(styleString),\n });\n\n return { toolInstance: annotationEngine.toolInstance, annotationEngine };\n};\n\n/**\n * 初始化imgNode并加载数据\n * @param nextIndex\n * @param nextBasicIndex\n */\nexport const LoadImageAndFileData =\n (nextIndex: number, nextBasicIndex?: number) => async (dispatch: any, getState: any) => {\n const { getFileData, imgList, toolInstance } = getState().annotation;\n SetAnnotationLoading(dispatch, true);\n\n /** 支持外部传入获取文件接口 */\n if (getFileData) {\n const fileData = await getFileData(imgList[nextIndex], nextIndex);\n dispatch({\n type: ANNOTATION_ACTIONS.SET_FILE_DATA,\n payload: {\n fileData,\n index: nextIndex,\n },\n });\n }\n\n const { url } = imgList[nextIndex];\n\n return ImgUtils.load(url)\n .then((imgNode) => {\n SetAnnotationLoading(dispatch, false);\n\n dispatch({\n type: ANNOTATION_ACTIONS.LOAD_FILE_DATA,\n payload: {\n imgNode,\n nextIndex,\n nextBasicIndex,\n },\n });\n })\n .catch(() => {\n SetAnnotationLoading(dispatch, false);\n toolInstance.setErrorImg();\n dispatch({\n type: ANNOTATION_ACTIONS.LOAD_FILE_DATA,\n payload: {\n nextIndex,\n nextBasicIndex,\n },\n });\n });\n };\n\nexport const annotationReducer = (\n state = initialState,\n action: AnnotationActionTypes,\n): AnnotationState => {\n switch (action.type) {\n case ANNOTATION_ACTIONS.UPDATE_TOOL_INSTANCE: {\n return {\n ...state,\n toolInstance: action.payload.toolInstance,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_IMG_LIST: {\n return {\n ...state,\n imgList: action.payload.imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.CALC_STEP_PROGRESS: {\n const { imgList, step } = state;\n\n const stepProgress = calcStepProgress(imgList, step);\n\n return {\n ...state,\n stepProgress,\n };\n }\n\n case ANNOTATION_ACTIONS.SUBMIT_FILE_DATA: {\n const { imgList, imgIndex, step, stepList, toolInstance, onSubmit, resultList } = state;\n if (!toolInstance) {\n return state;\n }\n\n const oldResultString = imgList[imgIndex]?.result || '';\n const [, basicImgInfo] = toolInstance.exportData();\n\n const resultWithBasicInfo = composeResultWithBasicImgInfo(oldResultString, basicImgInfo);\n const newResultString = composeResult(\n resultWithBasicInfo,\n { step, stepList },\n { rect: resultList },\n );\n\n imgList[imgIndex].result = AnnotationDataUtils.dataCorrection(\n newResultString,\n oldResultString,\n step,\n stepList,\n );\n\n if (onSubmit) {\n onSubmit([imgList[imgIndex]], action.payload?.submitType, imgIndex);\n }\n\n const stepProgress = calcStepProgress(imgList, step);\n return {\n ...state,\n stepProgress,\n imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.SAVE_RESULT: {\n const { imgList, imgIndex, onSave } = state;\n onSave?.(imgList[imgIndex], imgIndex, imgList);\n return {\n ...state,\n };\n }\n\n case ANNOTATION_ACTIONS.SUBMIT_RESULT: {\n const { imgList, basicIndex, resultList, annotationEngine, basicResultList } = state;\n if (!annotationEngine) {\n return state;\n }\n\n const [exportResult] = annotationEngine.toolInstance.exportData();\n\n let previousResultList = exportResult;\n\n if (basicResultList?.length > 0) {\n const sourceID = basicResultList[basicIndex]?.id;\n const newResultData = exportResult.map((i: any) => ({ ...i, sourceID }));\n previousResultList = _.cloneDeep(resultList).filter((i: any) => i.sourceID !== sourceID);\n previousResultList.push(...newResultData);\n }\n\n return {\n ...state,\n resultList: previousResultList,\n imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.SET_BASIC_INDEX: {\n const {\n toolInstance,\n step,\n imgList,\n imgIndex,\n stepList,\n annotationEngine,\n resultList,\n basicResultList,\n } = state;\n\n if (!toolInstance || !annotationEngine) {\n return state;\n }\n\n const nextBasicIndex = action.payload.basicIndex;\n const sourceID = basicResultList[nextBasicIndex]?.id;\n\n const fileResult = jsonParser(imgList[imgIndex]?.result);\n const result = (resultList || []).filter((i) => i.sourceID === sourceID);\n\n const stepConfig = getStepConfig(stepList, step);\n\n const { dataSourceStep, tool } = stepConfig;\n const dependStepConfig = getStepConfig(stepList, dataSourceStep);\n let stepBasicResultList = [];\n\n if (dataSourceStep && tool) {\n stepBasicResultList = fileResult[`step_${dataSourceStep}`]?.result;\n\n if (stepBasicResultList?.length > 0) {\n annotationEngine.setBasicInfo(dependStepConfig.tool, stepBasicResultList[nextBasicIndex]);\n annotationEngine.launchOperation();\n } else {\n annotationEngine.setBasicInfo(dependStepConfig.tool);\n annotationEngine.forbidOperation();\n message.info('当前文件不存在依赖数据');\n }\n }\n\n toolInstance.setResult(result);\n toolInstance.history.initRecord(result, true);\n\n return {\n ...state,\n basicIndex: nextBasicIndex,\n };\n }\n\n case ANNOTATION_ACTIONS.SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED: {\n const { triggerEventAfterIndexChanged } = action.payload;\n return {\n ...state,\n triggerEventAfterIndexChanged: !!triggerEventAfterIndexChanged,\n };\n }\n\n case ANNOTATION_ACTIONS.LOAD_FILE_DATA: {\n const { imgList, step, toolInstance, annotationEngine, stepList } = state;\n if (!toolInstance || !annotationEngine) {\n return state;\n }\n\n const currentStepInfo = StepUtils.getCurrentStepInfo(step, stepList);\n\n const { nextIndex, imgNode, nextBasicIndex, imgError } = action.payload;\n const basicIndex = nextBasicIndex ?? 0;\n\n const fileResult = jsonParser(imgList[nextIndex]?.result);\n\n const stepResult = fileResult[`step_${step}`];\n\n const isInitData = !stepResult; // 是否为初始化数据\n\n const basicImgInfo = {\n rotate: fileResult.rotate ?? 0,\n valid: fileResult.valid ?? true,\n };\n\n if (imgNode && imgError !== true) {\n annotationEngine.setImgNode(imgNode, basicImgInfo);\n }\n\n const stepConfig = getStepConfig(stepList, step);\n\n const { dataSourceStep, tool } = stepConfig;\n const dependStepConfig = getStepConfig(stepList, dataSourceStep);\n const hasDataSourceStep = dataSourceStep && tool;\n const stepBasicResultList = fileResult[`step_${dataSourceStep}`]?.result ?? [];\n\n const result = AnnotationDataUtils.getInitialResultList(\n stepResult?.result,\n toolInstance,\n stepConfig,\n stepBasicResultList,\n isInitData,\n );\n\n annotationEngine.launchOperation();\n\n if (hasDataSourceStep) {\n if (stepBasicResultList?.length > 0) {\n annotationEngine.setBasicInfo(dependStepConfig.tool, stepBasicResultList[basicIndex]);\n } else {\n // TODO: 禁用绘制交互,有无依赖之间的操作切换\n annotationEngine.setBasicInfo(dependStepConfig.tool);\n annotationEngine.forbidOperation();\n message.info('当前文件不存在依赖数据');\n }\n }\n\n // TODO,非查看模式才允许添加数据\n if (currentStepInfo.tool !== 'check') {\n const sourceID = stepBasicResultList[basicIndex]?.id ?? '';\n const resultForBasicIndex = hasDataSourceStep\n ? result.filter((i: { sourceID: string | number }) =>\n CommonToolUtils.isSameSourceID(i.sourceID, sourceID),\n )\n : result;\n toolInstance.setResult(resultForBasicIndex);\n toolInstance.history.initRecord(result, true);\n }\n\n return {\n ...state,\n imgIndex: nextIndex,\n basicIndex,\n basicResultList: stepBasicResultList,\n resultList: result,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ANNOTATION_CONFIG: {\n return {\n ...state,\n config: action.payload.config ?? '{}',\n };\n }\n\n case ANNOTATION_ACTIONS.SET_TASK_CONFIG: {\n const { stepList, step } = action.payload;\n return {\n ...state,\n stepList,\n step,\n };\n }\n\n case ANNOTATION_ACTIONS.INIT_TOOL: {\n const { imgNode } = state;\n const { toolInstance, annotationEngine } = updateToolInstance(state, imgNode);\n return {\n ...state,\n toolInstance,\n annotationEngine,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ON_SUBMIT: {\n return {\n ...state,\n onSubmit: action.payload.onSubmit,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ON_SAVE: {\n return {\n ...state,\n onSave: action.payload.onSave,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_GET_FILE_DATA: {\n return {\n ...state,\n getFileData: action.payload.getFileData,\n };\n }\n\n case ANNOTATION_ACTIONS.SET_FILE_DATA: {\n const { fileData, index } = action.payload;\n const { imgList } = state;\n imgList[index] = { ...imgList[index], ...fileData };\n\n return {\n ...state,\n imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ROTATE: {\n const { toolInstance } = state;\n toolInstance?.updateRotate();\n\n return state;\n }\n\n case ANNOTATION_ACTIONS.COPY_BACKWARD_RESULT: {\n const { toolInstance, imgIndex, imgList, step } = state;\n if (!toolInstance) {\n return state;\n }\n\n if (imgIndex === 0 || imgIndex >= imgList.length) {\n console.error('无法复制边界外的内容');\n return state;\n }\n const backwardResult = imgList[imgIndex - 1].result;\n if (!backwardResult) {\n return state;\n }\n\n const newResult = AnnotationDataUtils.copyResultChange(\n backwardResult,\n step,\n imgList[imgIndex].result ?? '',\n );\n imgList[imgIndex].result = newResult;\n\n // 更新当前的结果\n const fileResult = jsonParser(newResult);\n const stepResult = fileResult[`step_${step}`];\n const result = stepResult?.result || [];\n\n toolInstance.setResult(result);\n toolInstance.history.pushHistory(result);\n\n return {\n ...state,\n imgList: [...imgList],\n };\n }\n\n case ANNOTATION_ACTIONS.SET_STEP: {\n const { stepList, annotationEngine } = state;\n const { toStep } = action.payload;\n\n if (!annotationEngine) {\n return state;\n }\n\n if (toStep <= stepList.length) {\n const stepConfig = getStepConfig(stepList, toStep);\n annotationEngine.setToolName(stepConfig.tool, stepConfig.config);\n\n return {\n ...state,\n step: toStep,\n toolInstance: annotationEngine.toolInstance,\n };\n }\n break;\n }\n\n case ANNOTATION_ACTIONS.SET_LOADING: {\n const { loading } = action.payload;\n\n return {\n ...state,\n loading: !!loading,\n };\n }\n\n // eslint-disable-next-line no-fallthrough\n default:\n return state;\n }\n\n return state;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAca,gBAAgB,CAAC,UAAiB,SAC7C,SAAS,KAAK,CAAC,MAAM,EAAE,SAAS;AAElC,MAAM,eAAgC;AAAA,EACpC,kBAAkB;AAAA,EAClB,cAAc;AAAA,EACd,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,MAAM;AAAA,EACN,UAAU;AAAA,EACV,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A;AAMb,aAAO;AAAA;AAGX,SAAO;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"reducer.js","sources":["../../../src/store/annotation/reducer.ts"],"sourcesContent":["import { ANNOTATION_ACTIONS } from '@/store/Actions';\nimport _ from 'lodash';\nimport { composeResultWithBasicImgInfo, composeResult } from '@/utils/data';\nimport { jsonParser } from '@/utils';\nimport StepUtils from '@/utils/StepUtils';\nimport AnnotationDataUtils from '@/utils/AnnotationDataUtils';\nimport { ConfigUtils } from '@/utils/ConfigUtils';\nimport styleString from '@/constant/styleString';\nimport { getFormatSize } from '@/components/customResizeHook';\nimport { AnnotationEngine, CommonToolUtils, ImgUtils } from '@labelbee/lb-annotation';\nimport { AnnotationState, AnnotationActionTypes } from './types';\nimport { message } from 'antd/es';\nimport { SetAnnotationLoading } from './actionCreators';\nimport { DEFAULT_CANVAS_SIZE } from '@/constant';\n\nexport const getStepConfig = (stepList: any[], step: number) =>\n stepList.find((i) => i.step === step);\n\nconst initialState: AnnotationState = {\n annotationEngine: null,\n toolInstance: null,\n imgList: [],\n config: '{}',\n imgIndex: -1,\n basicIndex: 0,\n imgPageSize: 1,\n step: 1,\n stepList: [],\n imgNode: new Image(),\n basicResultList: [],\n resultList: [],\n stepProgress: 0,\n loading: false,\n triggerEventAfterIndexChanged: false,\n};\n\n/**\n * 获取当前文件列表的总页数\n * @param state\n */\nexport const getTotalPage = (state: AnnotationState) => {\n const { imgList, imgPageSize } = state;\n return Math.ceil(imgList.length / imgPageSize);\n};\n\nconst calcStepProgress = (fileList: any[], step: number) =>\n fileList.reduce((pre, i) => {\n const resultStr = i.result;\n const resultObject = jsonParser(resultStr);\n if (resultObject[`step_${step}`]) {\n return pre + 1;\n }\n return pre;\n }, 0) / fileList.length;\n\nconst updateToolInstance = (annotation: AnnotationState, imgNode: HTMLImageElement) => {\n const { step, stepList } = annotation;\n const stepConfig = StepUtils.getCurrentStepInfo(step, stepList);\n const config = ConfigUtils.jsonParser(stepConfig.config);\n\n const container = document.getElementById('toolContainer');\n\n if (!container) {\n throw `Not exist dom named id-toolContainer`;\n }\n\n const canvasSize = getFormatSize({\n width: window ? window?.innerWidth ?? DEFAULT_CANVAS_SIZE.width : 0,\n height: window ? window?.innerHeight ?? DEFAULT_CANVAS_SIZE.height : 0,\n });\n const annotationEngine = new AnnotationEngine({\n container,\n toolName: stepConfig.tool,\n size: canvasSize,\n imgNode,\n config,\n style: JSON.parse(styleString),\n });\n\n return { toolInstance: annotationEngine.toolInstance, annotationEngine };\n};\n\n/**\n * 初始化imgNode并加载数据\n * @param nextIndex\n * @param nextBasicIndex\n */\nexport const LoadImageAndFileData =\n (nextIndex: number, nextBasicIndex?: number) => async (dispatch: any, getState: any) => {\n const { getFileData, imgList, toolInstance } = getState().annotation;\n SetAnnotationLoading(dispatch, true);\n\n /** 支持外部传入获取文件接口 */\n if (getFileData) {\n const fileData = await getFileData(imgList[nextIndex], nextIndex);\n dispatch({\n type: ANNOTATION_ACTIONS.SET_FILE_DATA,\n payload: {\n fileData,\n index: nextIndex,\n },\n });\n }\n\n const { url } = imgList[nextIndex];\n\n return ImgUtils.load(url)\n .then((imgNode) => {\n SetAnnotationLoading(dispatch, false);\n\n dispatch({\n type: ANNOTATION_ACTIONS.LOAD_FILE_DATA,\n payload: {\n imgNode,\n nextIndex,\n nextBasicIndex,\n },\n });\n })\n .catch(() => {\n SetAnnotationLoading(dispatch, false);\n toolInstance.setErrorImg();\n dispatch({\n type: ANNOTATION_ACTIONS.LOAD_FILE_DATA,\n payload: {\n nextIndex,\n nextBasicIndex,\n },\n });\n });\n };\n\nexport const annotationReducer = (\n state = initialState,\n action: AnnotationActionTypes,\n): AnnotationState => {\n switch (action.type) {\n case ANNOTATION_ACTIONS.UPDATE_TOOL_INSTANCE: {\n return {\n ...state,\n toolInstance: action.payload.toolInstance,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_IMG_LIST: {\n return {\n ...state,\n imgList: action.payload.imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.CALC_STEP_PROGRESS: {\n const { imgList, step } = state;\n\n const stepProgress = calcStepProgress(imgList, step);\n\n return {\n ...state,\n stepProgress,\n };\n }\n\n case ANNOTATION_ACTIONS.SUBMIT_FILE_DATA: {\n const { imgList, imgIndex, step, stepList, toolInstance, onSubmit, resultList } = state;\n if (!toolInstance) {\n return state;\n }\n\n const oldResultString = imgList[imgIndex]?.result || '';\n const [, basicImgInfo] = toolInstance.exportData();\n\n const resultWithBasicInfo = composeResultWithBasicImgInfo(oldResultString, basicImgInfo);\n const newResultString = composeResult(\n resultWithBasicInfo,\n { step, stepList },\n { rect: resultList },\n );\n\n imgList[imgIndex].result = AnnotationDataUtils.dataCorrection(\n newResultString,\n oldResultString,\n step,\n stepList,\n );\n\n if (onSubmit) {\n onSubmit([imgList[imgIndex]], action.payload?.submitType, imgIndex);\n }\n\n const stepProgress = calcStepProgress(imgList, step);\n return {\n ...state,\n stepProgress,\n imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.SAVE_RESULT: {\n const { imgList, imgIndex, onSave } = state;\n onSave?.(imgList[imgIndex], imgIndex, imgList);\n return {\n ...state,\n };\n }\n\n case ANNOTATION_ACTIONS.SUBMIT_RESULT: {\n const { imgList, basicIndex, resultList, annotationEngine, basicResultList } = state;\n if (!annotationEngine) {\n return state;\n }\n\n const [exportResult] = annotationEngine.toolInstance.exportData();\n\n let previousResultList = exportResult;\n\n if (basicResultList?.length > 0) {\n const sourceID = basicResultList[basicIndex]?.id;\n const newResultData = exportResult.map((i: any) => ({ ...i, sourceID }));\n previousResultList = _.cloneDeep(resultList).filter((i: any) => i.sourceID !== sourceID);\n previousResultList.push(...newResultData);\n }\n\n return {\n ...state,\n resultList: previousResultList,\n imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.SET_BASIC_INDEX: {\n const {\n toolInstance,\n step,\n imgList,\n imgIndex,\n stepList,\n annotationEngine,\n resultList,\n basicResultList,\n } = state;\n\n if (!toolInstance || !annotationEngine) {\n return state;\n }\n\n const nextBasicIndex = action.payload.basicIndex;\n const sourceID = basicResultList[nextBasicIndex]?.id;\n\n const fileResult = jsonParser(imgList[imgIndex]?.result);\n const result = (resultList || []).filter((i) => i.sourceID === sourceID);\n\n const stepConfig = getStepConfig(stepList, step);\n\n const { dataSourceStep, tool } = stepConfig;\n const dependStepConfig = getStepConfig(stepList, dataSourceStep);\n let stepBasicResultList = [];\n\n if (dataSourceStep && tool) {\n stepBasicResultList = fileResult[`step_${dataSourceStep}`]?.result;\n\n if (stepBasicResultList?.length > 0) {\n annotationEngine.setBasicInfo(dependStepConfig.tool, stepBasicResultList[nextBasicIndex]);\n annotationEngine.launchOperation();\n } else {\n annotationEngine.setBasicInfo(dependStepConfig.tool);\n annotationEngine.forbidOperation();\n message.info('当前文件不存在依赖数据');\n }\n }\n\n toolInstance.setResult(result);\n toolInstance.history.initRecord(result, true);\n\n return {\n ...state,\n basicIndex: nextBasicIndex,\n };\n }\n\n case ANNOTATION_ACTIONS.SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED: {\n const { triggerEventAfterIndexChanged } = action.payload;\n return {\n ...state,\n triggerEventAfterIndexChanged: !!triggerEventAfterIndexChanged,\n };\n }\n\n case ANNOTATION_ACTIONS.LOAD_FILE_DATA: {\n const { imgList, step, toolInstance, annotationEngine, stepList } = state;\n if (!toolInstance || !annotationEngine) {\n return state;\n }\n\n const currentStepInfo = StepUtils.getCurrentStepInfo(step, stepList);\n\n const { nextIndex, imgNode, nextBasicIndex, imgError } = action.payload;\n const basicIndex = nextBasicIndex ?? 0;\n\n const fileResult = jsonParser(imgList[nextIndex]?.result);\n\n const stepResult = fileResult[`step_${step}`];\n\n const isInitData = !stepResult; // 是否为初始化数据\n\n const basicImgInfo = {\n rotate: fileResult.rotate ?? 0,\n valid: fileResult.valid ?? true,\n };\n\n if (imgNode && imgError !== true) {\n annotationEngine.setImgNode(imgNode, basicImgInfo);\n }\n\n const stepConfig = getStepConfig(stepList, step);\n\n const { dataSourceStep, tool } = stepConfig;\n const dependStepConfig = getStepConfig(stepList, dataSourceStep);\n const hasDataSourceStep = dataSourceStep && tool;\n const stepBasicResultList = fileResult[`step_${dataSourceStep}`]?.result ?? [];\n\n const result = AnnotationDataUtils.getInitialResultList(\n stepResult?.result,\n toolInstance,\n stepConfig,\n stepBasicResultList,\n isInitData,\n );\n\n annotationEngine.launchOperation();\n\n if (hasDataSourceStep) {\n if (stepBasicResultList?.length > 0) {\n annotationEngine.setBasicInfo(dependStepConfig.tool, stepBasicResultList[basicIndex]);\n } else {\n // TODO: 禁用绘制交互,有无依赖之间的操作切换\n annotationEngine.setBasicInfo(dependStepConfig.tool);\n annotationEngine.forbidOperation();\n message.info('当前文件不存在依赖数据');\n }\n }\n\n // TODO,非查看模式才允许添加数据\n if (currentStepInfo.tool !== 'check') {\n const sourceID = stepBasicResultList[basicIndex]?.id ?? '';\n const resultForBasicIndex = hasDataSourceStep\n ? result.filter((i: { sourceID: string | number }) =>\n CommonToolUtils.isSameSourceID(i.sourceID, sourceID),\n )\n : result;\n toolInstance.setResult(resultForBasicIndex);\n toolInstance.history.initRecord(result, true);\n }\n\n return {\n ...state,\n imgIndex: nextIndex,\n basicIndex,\n basicResultList: stepBasicResultList,\n resultList: result,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ANNOTATION_CONFIG: {\n return {\n ...state,\n config: action.payload.config ?? '{}',\n };\n }\n\n case ANNOTATION_ACTIONS.SET_TASK_CONFIG: {\n const { stepList, step } = action.payload;\n return {\n ...state,\n stepList,\n step,\n };\n }\n\n case ANNOTATION_ACTIONS.INIT_TOOL: {\n const { imgNode } = state;\n const { toolInstance, annotationEngine } = updateToolInstance(state, imgNode);\n return {\n ...state,\n toolInstance,\n annotationEngine,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ON_SUBMIT: {\n return {\n ...state,\n onSubmit: action.payload.onSubmit,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ON_SAVE: {\n return {\n ...state,\n onSave: action.payload.onSave,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_GET_FILE_DATA: {\n return {\n ...state,\n getFileData: action.payload.getFileData,\n };\n }\n\n case ANNOTATION_ACTIONS.SET_FILE_DATA: {\n const { fileData, index } = action.payload;\n const { imgList } = state;\n imgList[index] = { ...imgList[index], ...fileData };\n\n return {\n ...state,\n imgList,\n };\n }\n\n case ANNOTATION_ACTIONS.UPDATE_ROTATE: {\n const { toolInstance } = state;\n toolInstance?.updateRotate();\n\n return state;\n }\n\n case ANNOTATION_ACTIONS.COPY_BACKWARD_RESULT: {\n const { toolInstance, imgIndex, imgList, step } = state;\n if (!toolInstance) {\n return state;\n }\n\n if (imgIndex === 0 || imgIndex >= imgList.length) {\n console.error('无法复制边界外的内容');\n return state;\n }\n const backwardResult = imgList[imgIndex - 1].result;\n if (!backwardResult) {\n return state;\n }\n\n const newResult = AnnotationDataUtils.copyResultChange(\n backwardResult,\n step,\n imgList[imgIndex].result ?? '',\n );\n imgList[imgIndex].result = newResult;\n\n // 更新当前的结果\n const fileResult = jsonParser(newResult);\n const stepResult = fileResult[`step_${step}`];\n const result = stepResult?.result || [];\n\n toolInstance.setResult(result);\n toolInstance.history.pushHistory(result);\n\n return {\n ...state,\n imgList: [...imgList],\n };\n }\n\n case ANNOTATION_ACTIONS.SET_STEP: {\n const { stepList, annotationEngine } = state;\n const { toStep } = action.payload;\n\n if (!annotationEngine) {\n return state;\n }\n\n if (toStep <= stepList.length) {\n const stepConfig = getStepConfig(stepList, toStep);\n annotationEngine.setToolName(stepConfig.tool, stepConfig.config);\n\n return {\n ...state,\n step: toStep,\n toolInstance: annotationEngine.toolInstance,\n };\n }\n break;\n }\n\n case ANNOTATION_ACTIONS.SET_LOADING: {\n const { loading } = action.payload;\n\n return {\n ...state,\n loading: !!loading,\n };\n }\n\n // eslint-disable-next-line no-fallthrough\n default:\n return state;\n }\n\n return state;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAW,OAAO;AAE1B,UAAI,CAAC,kBAAkB;AACrB,eAAO;AAAA;AAGT,UAAI,UAAU,SAAS,QAAQ;AAC7B,cAAM,aAAa,cAAc,UAAU;AAC3C,yBAAiB,YAAY,WAAW,MAAM,WAAW;AAEzD,eAAO,iCACF,QADE;AAAA,UAEL,MAAM;AAAA,UACN,cAAc,iBAAiB;AAAA;AAAA;AAGnC;AAAA;AAAA,SAGG,mBAAmB,aAAa;AACnC,YAAM,CAAE,WAAY,OAAO;AAE3B,aAAO,iCACF,QADE;AAAA,QAEL,SAAS,CAAC,CAAC;AAAA;AAAA;AAAA;AAMb,aAAO;AAAA;AAGX,SAAO;AAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{uuid as v}from"@
|
|
1
|
+
import{uuid as v}from"@labelbee/lb-annotation";import{jsonParser as l}from"./index.js";import{EToolName as d}from"../data/enums/ToolType.js";import _ from"lodash";import y from"./StepUtils.js";var O=Object.defineProperty,P=Object.defineProperties,j=Object.getOwnPropertyDescriptors,h=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,S=(a,t,e)=>t in a?O(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,E=(a,t)=>{for(var e in t||(t={}))w.call(t,e)&&S(a,e,t[e]);if(h)for(var e of h(t))x.call(t,e)&&S(a,e,t[e]);return a},N=(a,t)=>P(a,j(t));class R{static copyResultChange(t,e,r){try{const s=l(t),i=l(r),o=`step_${e}`;if(s[o]){const n=s[o];if(n.result)return n.result=n.result.map(u=>N(E({},u),{id:v(8,62)})),i[o]=n,JSON.stringify(i)}return t}catch(s){return t}}static isResultSourceMatchedDependence(t,e){const r=t==null?void 0:t.map(i=>i.sourceID).sort(),s=e==null?void 0:e.map(i=>i.id).sort();return _.isEqual(r,s)}static deltaUpdateBasicResultList(t,e){const r=t==null?void 0:t.map(s=>s.sourceID).sort();return e.filter(s=>!r.includes(s.id))}static getInitialResultList(t,e,r,s,i){const o=t!=null?t:[];switch(r.tool){case d.Tag:case d.Text:{if(r.dataSourceStep>0){const n=this.deltaUpdateBasicResultList(o,s);if(n.length>0)return o.concat(e.getInitResultList(r.dataSourceStep,n))}return i!==!0?o:e.getInitResultList(r.dataSourceStep,s)}default:return o}}static dataCorrection(t,e,r,s){var i,o;try{const u=`step_${y.getStepInfo(r,s).step}`,c=l(t),I=l(e),f=(i=c[u])==null?void 0:i.result,p=(o=I[u])==null?void 0:o.result;if(!p||_.isEqual(f.sort(this.idCmp),p.sort(this.idCmp)))return t;const m=this.findDeletedIds(f,p);if(m.length===0)return t;const D=r,g=this.getStepKeys(c).sort();return this.deleteRes(c,D,m,g),JSON.stringify(c)}catch(n){return console.error(n),t}}static idCmp(t,e){const r=t.id,s=e.id;return r<s?-1:r>s?1:0}static findDeletedIds(t,e){return this.findDeletedItems(e,t).map(r=>r.id)}static findDeletedItems(t,e){const r=[];return t.forEach(s=>{e.some(o=>o.id===s.id)||r.push(s)}),r}static getStepKeys(t){return Object.keys(t).map(e=>parseInt(e.replace("step_",""),10)).filter(e=>!isNaN(e))}static deleteRes(t,e,r,s){s.forEach(i=>{if(i>e){const o=t[`step_${i}`];if([d.FolderTag,d.Segmentation].includes(o.tool))return;if(o.dataSourceStep===e){const n=[];o.result=o.result.filter(u=>r.includes(u.sourceID)?(n.push(u.id),!1):!0),this.deleteRes(t,i,n,s)}else o.result=o.result.filter(n=>!r.includes(n.sourceID))}})}}export{R as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnnotationDataUtils.js","sources":["../../src/utils/AnnotationDataUtils.ts"],"sourcesContent":["import { uuid } from '@sensetime/annotation';\nimport { jsonParser } from '.';\nimport { EToolName } from '@/data/enums/ToolType';\nimport _ from 'lodash';\nimport StepUtils from './StepUtils';\nimport { IStepInfo } from '@/types/step';\n\nexport default class AnnotationDataUtils {\n /**\n * 复制上一张图片结果\n * @param copyResult 复制的结果\n * @param step 复制的步骤\n * @param currentResult 当前的步骤\n * @returns\n */\n public static copyResultChange(copyResult: string, step: number, currentResult: string) {\n // 其实其限定的范围一般都在单图的情况\n try {\n const copyData = jsonParser(copyResult);\n const currentData = jsonParser(currentResult);\n const stepName = `step_${step}`;\n if (copyData[stepName]) {\n // 这层可能还要处理 dataSource 依赖问题\n const info = copyData[stepName];\n if (info.result) {\n info.result = info.result.map((info: any) => ({\n ...info,\n // @ts-ignore\n id: uuid(8, 62),\n }));\n currentData[stepName] = info;\n return JSON.stringify(currentData);\n }\n }\n return copyResult;\n } catch {\n return copyResult;\n }\n }\n\n /**\n * 判断结果sourceID与依赖数据的id是否能对应\n * @param result\n * @param basicResultList\n */\n public static isResultSourceMatchedDependence(result: any, basicResultList: any[]) {\n const sourceIDForCurStep = result?.map((i: { sourceID: string }) => i.sourceID).sort();\n const sourceIDForDependStep = basicResultList?.map((i) => i.id).sort();\n\n return _.isEqual(sourceIDForCurStep, sourceIDForDependStep);\n }\n\n /**\n * 获取依赖增量更新的内容\n * @param result\n * @param basicResultList\n * @returns\n */\n public static deltaUpdateBasicResultList(result: any, basicResultList: any[]) {\n const sourceIDForCurStep = result?.map((i: { sourceID: string }) => i.sourceID).sort();\n\n return basicResultList.filter((v) => !sourceIDForCurStep.includes(v.id));\n }\n\n /**\n *\n * @param stepResult\n * @param toolInstance\n * @param stepConfig\n * @param basicResultList 获取初始化数据 该部分默认输入需要为空数组\n * @param isInitData\n * @returns\n */\n public static getInitialResultList(\n stepResult: any[] | undefined,\n toolInstance: any,\n stepConfig: any,\n basicResultList: any[],\n isInitData: boolean,\n ) {\n const resultList = stepResult ?? [];\n\n switch (stepConfig.tool) {\n case EToolName.Tag:\n case EToolName.Text: {\n /**\n * 在依赖的情况下,检查的是否需要增量更新前面新增的结果\n */\n if (stepConfig.dataSourceStep > 0) {\n const deltaResultList = this.deltaUpdateBasicResultList(resultList, basicResultList);\n if (deltaResultList.length > 0) {\n return resultList.concat(\n toolInstance.getInitResultList(stepConfig.dataSourceStep, deltaResultList),\n );\n }\n }\n\n if (isInitData !== true) {\n return resultList;\n }\n\n return toolInstance.getInitResultList(stepConfig.dataSourceStep, basicResultList);\n }\n\n default: {\n return resultList;\n }\n }\n }\n\n /**\n * 修正数据,找到被删除的数据,并将依赖该数据的结果全部删除\n * @param newResStr 新提交的数据\n * @param oldResStr 当前的数据\n * @param step 当前操作的步骤\n * @param stepList 步骤列表\n */\n public static dataCorrection(\n newResStr: string,\n oldResStr: string,\n step: number,\n stepList: IStepInfo[],\n ) {\n try {\n const curStep = StepUtils.getStepInfo(step, stepList);\n const stepKey = `step_${curStep.step}`;\n const newRes = jsonParser(newResStr);\n const oldRes = jsonParser(oldResStr);\n const newResForCurStep = newRes[stepKey]?.result;\n const oldResForCurStep = oldRes[stepKey]?.result;\n\n /** 没有旧数据时不处理 */\n if (!oldResForCurStep) {\n return newResStr;\n }\n\n if (_.isEqual(newResForCurStep.sort(this.idCmp), oldResForCurStep.sort(this.idCmp))) {\n return newResStr;\n }\n\n const deletedIds = this.findDeletedIds(newResForCurStep, oldResForCurStep);\n\n if (deletedIds.length === 0) {\n return newResStr;\n }\n\n const dataSourceStep = step;\n const stepKeys = this.getStepKeys(newRes).sort();\n this.deleteRes(newRes, dataSourceStep, deletedIds, stepKeys);\n\n return JSON.stringify(newRes);\n } catch (error) {\n console.error(error);\n return newResStr;\n }\n }\n\n /**\n * id sort 规则\n * @param a\n * @param b\n * @returns\n */\n public static idCmp(a: any, b: any) {\n const idA = a.id;\n const idB = b.id;\n if (idA < idB) {\n return -1;\n }\n if (idA > idB) {\n return 1;\n }\n\n return 0;\n }\n\n /**\n * 找到结果被删除的id\n * @param newResForCurStep\n * @param oldResForCurStep\n * @returns {Array<string>}\n */\n public static findDeletedIds(newResForCurStep: any[], oldResForCurStep: any[]) {\n return this.findDeletedItems(oldResForCurStep, newResForCurStep).map((i) => i.id);\n }\n\n /**\n * 找到被删除的结果\n * @param oldResForCurStep\n * @param newResForCurStep\n * @returns {Array<any>}\n */\n public static findDeletedItems(oldResForCurStep: any[], newResForCurStep: any[]) {\n const deletedItems: any[] = [];\n oldResForCurStep.forEach((i: any) => {\n const isNewResExisted = newResForCurStep.some((r: any) => r.id === i.id);\n if (!isNewResExisted) {\n deletedItems.push(i);\n }\n });\n return deletedItems;\n }\n\n /**\n * 根据结果找到所有的步骤\n * @param res\n * @returns {Array<number>} 结果步骤列表\n */\n public static getStepKeys(res: any) {\n return Object.keys(res)\n .map((i) => parseInt(i.replace('step_', ''), 10))\n .filter((i) => !isNaN(i));\n }\n\n /**\n * 删除依赖数据的结果\n * @param resData 当前文件的结果\n * @param dataSourceStep 依赖步骤\n * @param deletedIds 需要删除的sourceID\n * @param stepKeys 结果的步骤\n */\n public static deleteRes(\n resData: any,\n dataSourceStep: number,\n deletedIds: string[],\n stepKeys: number[],\n ) {\n stepKeys.forEach((s) => {\n if (s > dataSourceStep) {\n const stepRes = resData[`step_${s}`];\n // 文件夹标签, 分割工具 没有依赖, 不进行判断\n if ([EToolName.FolderTag, EToolName.Segmentation].includes(stepRes.tool)) {\n return;\n }\n if (stepRes.dataSourceStep === dataSourceStep) {\n const newDeletedIds: string[] = [];\n stepRes.result = stepRes.result.filter((i: any) => {\n const exist = deletedIds.includes(i.sourceID);\n if (exist) {\n newDeletedIds.push(i.id);\n return false;\n }\n\n return true;\n });\n this.deleteRes(resData, s, newDeletedIds, stepKeys);\n } else {\n // 非直接依赖关系下,也同样过滤删除了对应框的数据(注意: 该场景不包含 filterData 过滤属性下,更改框的属性来删除对应的框体)\n stepRes.result = stepRes.result.filter((i: any) => {\n const exist = deletedIds.includes(i.sourceID);\n if (exist) {\n return false;\n }\n\n return true;\n });\n }\n }\n });\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;0BAOyC;AAAA,SAQzB,iBAAiB,YAAoB,MAAc,eAAuB;AAEtF,QAAI;AACF,YAAM,WAAW,WAAW;AAC5B,YAAM,cAAc,WAAW;AAC/B,YAAM,WAAW,QAAQ;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AACA,aAAS,QAAQ,CAAC,MAAM;AACtB,UAAI,IAAI,gBAAgB;AACtB,cAAM,UAAU,QAAQ,QAAQ;AAEhC,YAAI,CAAC,UAAU,WAAW,UAAU,cAAc,SAAS,QAAQ,OAAO;AACxE;AAAA;AAEF,YAAI,QAAQ,mBAAmB,gBAAgB;AAC7C,gBAAM,gBAA0B;AAChC,kBAAQ,SAAS,QAAQ,OAAO,OAAO,CAAC,MAAW;AACjD,kBAAM,QAAQ,WAAW,SAAS,EAAE;AACpC,gBAAI,OAAO;AACT,4BAAc,KAAK,EAAE;AACrB,qBAAO;AAAA;AAGT,mBAAO;AAAA;AAET,eAAK,UAAU,SAAS,GAAG,eAAe;AAAA,eACrC;AAEL,kBAAQ,SAAS,QAAQ,OAAO,OAAO,CAAC,MAAW;AACjD,kBAAM,QAAQ,WAAW,SAAS,EAAE;AACpC,gBAAI,OAAO;AACT,qBAAO;AAAA;AAGT,mBAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"AnnotationDataUtils.js","sources":["../../src/utils/AnnotationDataUtils.ts"],"sourcesContent":["import { uuid } from '@labelbee/lb-annotation';\nimport { jsonParser } from '.';\nimport { EToolName } from '@/data/enums/ToolType';\nimport _ from 'lodash';\nimport StepUtils from './StepUtils';\nimport { IStepInfo } from '@/types/step';\n\nexport default class AnnotationDataUtils {\n /**\n * 复制上一张图片结果\n * @param copyResult 复制的结果\n * @param step 复制的步骤\n * @param currentResult 当前的步骤\n * @returns\n */\n public static copyResultChange(copyResult: string, step: number, currentResult: string) {\n // 其实其限定的范围一般都在单图的情况\n try {\n const copyData = jsonParser(copyResult);\n const currentData = jsonParser(currentResult);\n const stepName = `step_${step}`;\n if (copyData[stepName]) {\n // 这层可能还要处理 dataSource 依赖问题\n const info = copyData[stepName];\n if (info.result) {\n info.result = info.result.map((info: any) => ({\n ...info,\n // @ts-ignore\n id: uuid(8, 62),\n }));\n currentData[stepName] = info;\n return JSON.stringify(currentData);\n }\n }\n return copyResult;\n } catch {\n return copyResult;\n }\n }\n\n /**\n * 判断结果sourceID与依赖数据的id是否能对应\n * @param result\n * @param basicResultList\n */\n public static isResultSourceMatchedDependence(result: any, basicResultList: any[]) {\n const sourceIDForCurStep = result?.map((i: { sourceID: string }) => i.sourceID).sort();\n const sourceIDForDependStep = basicResultList?.map((i) => i.id).sort();\n\n return _.isEqual(sourceIDForCurStep, sourceIDForDependStep);\n }\n\n /**\n * 获取依赖增量更新的内容\n * @param result\n * @param basicResultList\n * @returns\n */\n public static deltaUpdateBasicResultList(result: any, basicResultList: any[]) {\n const sourceIDForCurStep = result?.map((i: { sourceID: string }) => i.sourceID).sort();\n\n return basicResultList.filter((v) => !sourceIDForCurStep.includes(v.id));\n }\n\n /**\n *\n * @param stepResult\n * @param toolInstance\n * @param stepConfig\n * @param basicResultList 获取初始化数据 该部分默认输入需要为空数组\n * @param isInitData\n * @returns\n */\n public static getInitialResultList(\n stepResult: any[] | undefined,\n toolInstance: any,\n stepConfig: any,\n basicResultList: any[],\n isInitData: boolean,\n ) {\n const resultList = stepResult ?? [];\n\n switch (stepConfig.tool) {\n case EToolName.Tag:\n case EToolName.Text: {\n /**\n * 在依赖的情况下,检查的是否需要增量更新前面新增的结果\n */\n if (stepConfig.dataSourceStep > 0) {\n const deltaResultList = this.deltaUpdateBasicResultList(resultList, basicResultList);\n if (deltaResultList.length > 0) {\n return resultList.concat(\n toolInstance.getInitResultList(stepConfig.dataSourceStep, deltaResultList),\n );\n }\n }\n\n if (isInitData !== true) {\n return resultList;\n }\n\n return toolInstance.getInitResultList(stepConfig.dataSourceStep, basicResultList);\n }\n\n default: {\n return resultList;\n }\n }\n }\n\n /**\n * 修正数据,找到被删除的数据,并将依赖该数据的结果全部删除\n * @param newResStr 新提交的数据\n * @param oldResStr 当前的数据\n * @param step 当前操作的步骤\n * @param stepList 步骤列表\n */\n public static dataCorrection(\n newResStr: string,\n oldResStr: string,\n step: number,\n stepList: IStepInfo[],\n ) {\n try {\n const curStep = StepUtils.getStepInfo(step, stepList);\n const stepKey = `step_${curStep.step}`;\n const newRes = jsonParser(newResStr);\n const oldRes = jsonParser(oldResStr);\n const newResForCurStep = newRes[stepKey]?.result;\n const oldResForCurStep = oldRes[stepKey]?.result;\n\n /** 没有旧数据时不处理 */\n if (!oldResForCurStep) {\n return newResStr;\n }\n\n if (_.isEqual(newResForCurStep.sort(this.idCmp), oldResForCurStep.sort(this.idCmp))) {\n return newResStr;\n }\n\n const deletedIds = this.findDeletedIds(newResForCurStep, oldResForCurStep);\n\n if (deletedIds.length === 0) {\n return newResStr;\n }\n\n const dataSourceStep = step;\n const stepKeys = this.getStepKeys(newRes).sort();\n this.deleteRes(newRes, dataSourceStep, deletedIds, stepKeys);\n\n return JSON.stringify(newRes);\n } catch (error) {\n console.error(error);\n return newResStr;\n }\n }\n\n /**\n * id sort 规则\n * @param a\n * @param b\n * @returns\n */\n public static idCmp(a: any, b: any) {\n const idA = a.id;\n const idB = b.id;\n if (idA < idB) {\n return -1;\n }\n if (idA > idB) {\n return 1;\n }\n\n return 0;\n }\n\n /**\n * 找到结果被删除的id\n * @param newResForCurStep\n * @param oldResForCurStep\n * @returns {Array<string>}\n */\n public static findDeletedIds(newResForCurStep: any[], oldResForCurStep: any[]) {\n return this.findDeletedItems(oldResForCurStep, newResForCurStep).map((i) => i.id);\n }\n\n /**\n * 找到被删除的结果\n * @param oldResForCurStep\n * @param newResForCurStep\n * @returns {Array<any>}\n */\n public static findDeletedItems(oldResForCurStep: any[], newResForCurStep: any[]) {\n const deletedItems: any[] = [];\n oldResForCurStep.forEach((i: any) => {\n const isNewResExisted = newResForCurStep.some((r: any) => r.id === i.id);\n if (!isNewResExisted) {\n deletedItems.push(i);\n }\n });\n return deletedItems;\n }\n\n /**\n * 根据结果找到所有的步骤\n * @param res\n * @returns {Array<number>} 结果步骤列表\n */\n public static getStepKeys(res: any) {\n return Object.keys(res)\n .map((i) => parseInt(i.replace('step_', ''), 10))\n .filter((i) => !isNaN(i));\n }\n\n /**\n * 删除依赖数据的结果\n * @param resData 当前文件的结果\n * @param dataSourceStep 依赖步骤\n * @param deletedIds 需要删除的sourceID\n * @param stepKeys 结果的步骤\n */\n public static deleteRes(\n resData: any,\n dataSourceStep: number,\n deletedIds: string[],\n stepKeys: number[],\n ) {\n stepKeys.forEach((s) => {\n if (s > dataSourceStep) {\n const stepRes = resData[`step_${s}`];\n // 文件夹标签, 分割工具 没有依赖, 不进行判断\n if ([EToolName.FolderTag, EToolName.Segmentation].includes(stepRes.tool)) {\n return;\n }\n if (stepRes.dataSourceStep === dataSourceStep) {\n const newDeletedIds: string[] = [];\n stepRes.result = stepRes.result.filter((i: any) => {\n const exist = deletedIds.includes(i.sourceID);\n if (exist) {\n newDeletedIds.push(i.id);\n return false;\n }\n\n return true;\n });\n this.deleteRes(resData, s, newDeletedIds, stepKeys);\n } else {\n // 非直接依赖关系下,也同样过滤删除了对应框的数据(注意: 该场景不包含 filterData 过滤属性下,更改框的属性来删除对应的框体)\n stepRes.result = stepRes.result.filter((i: any) => {\n const exist = deletedIds.includes(i.sourceID);\n if (exist) {\n return false;\n }\n\n return true;\n });\n }\n }\n });\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;0BAOyC;AAAA,SAQzB,iBAAiB,YAAoB,MAAc,eAAuB;AAEtF,QAAI;AACF,YAAM,WAAW,WAAW;AAC5B,YAAM,cAAc,WAAW;AAC/B,YAAM,WAAW,QAAQ;AACzB,UAAI,SAAS,WAAW;AAEtB,cAAM,OAAO,SAAS;AACtB,YAAI,KAAK,QAAQ;AACf,eAAK,SAAS,KAAK,OAAO,IAAI,CAAC,UAAe,iCACzC,QADyC;AAAA,YAG5C,IAAI,KAAK,GAAG;AAAA;AAEd,sBAAY,YAAY;AACxB,iBAAO,KAAK,UAAU;AAAA;AAAA;AAG1B,aAAO;AAAA,aACD,GAAN;AACA,aAAO;AAAA;AAAA;AAAA,SASG,gCAAgC,QAAa,i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AAE;AACpC,gBAAI,OAAO;AACT,4BAAc,KAAK,EAAE;AACrB,qBAAO;AAAA;AAGT,mBAAO;AAAA;AAET,eAAK,UAAU,SAAS,GAAG,eAAe;AAAA,eACrC;AAEL,kBAAQ,SAAS,QAAQ,OAAO,OAAO,CAAC,MAAW;AACjD,kBAAM,QAAQ,WAAW,SAAS,EAAE;AACpC,gBAAI,OAAO;AACT,qBAAO;AAAA;AAGT,mBAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import m,{useState as
|
|
1
|
+
import m,{useState as E,useRef as f,useEffect as a}from"react";import{message as p,Spin as P}from"antd/es";import{connect as h}from"react-redux";import w from"lodash";import{store as j}from"../../../index.js";import A from"../../../hooks/useSize.js";import{InitToolStyleConfig as x}from"../../../store/toolStyle/actionCreators.js";import{ImgUtils as z}from"@labelbee/lb-annotation";import R from"../../../components/ImageError/index.js";import{i18n as g}from"@labelbee/lb-utils";var C=Object.defineProperty,L=Object.defineProperties,N=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,d=(t,e,o)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,O=(t,e)=>{for(var o in e||(e={}))k.call(e,o)&&d(t,o,e[o]);if(u)for(var o of u(e))D.call(e,o)&&d(t,o,e[o]);return t},T=(t,e)=>L(t,N(e));const B=t=>{const[,e]=E(0),{imgAttribute:o,toolStyle:s,toolInstance:r,annotationEngine:n,loading:S,imgList:_,imgIndex:v}=t,c=f(null),y=f(null),l=A(c);a(()=>{j.dispatch(x())},[]),a(()=>{if(!!n)switch(g.language){case"cn":case"en":n.setLang(g.language);break}},[n]),a(()=>{r&&(r.singleOn("messageError",i=>{p.error(i)}),r.singleOn("messageInfo",i=>{p.info(i)}),r.singleOn("changeAnnotationShow",()=>{e(i=>i+1)}))},[r]),a(()=>{r&&r.setImgAttribute(o)},[o]),a(()=>{r&&r.setStyle(s),n&&n.setStyle(s)},[s]),a(()=>{(r==null?void 0:r.setSize)&&r.setSize(l),n&&n.setSize(l)},[l]);const I=()=>{const i=_[v];!i.url||z.load(i.url).then(b=>{n.setImgNode(b)})};return m.createElement("div",{ref:c,className:"annotationOperation"},m.createElement(P,{spinning:S,delay:500},m.createElement("div",{className:"canvas",ref:y,style:l,id:"toolContainer"})),(r==null?void 0:r.isImgError)===!0&&m.createElement(R,T(O({},l),{reloadImage:I,backgroundColor:"#e2e2e2",ignoreOffsetY:!0})))},U=t=>{const e=w.pickBy(t.annotation,(o,s)=>["imgList","imgIndex","stepList","step","toolInstance","annotationEngine","loading"].includes(s));return O({imgAttribute:t.imgAttribute,toolStyle:t.toolStyle},e)};var V=h(U)(B);export{V as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/views/MainView/annotationOperation/index.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { Spin, message } from 'antd/es';\nimport { AppState } from 'src/store';\nimport { connect } from 'react-redux';\nimport { ImgAttributeState } from 'src/store/imgAttribute/types';\nimport _ from 'lodash';\nimport { store } from '@/index';\n\nimport useSize from '@/hooks/useSize';\nimport { IFileItem } from '@/types/data';\nimport { IStepInfo } from '@/types/step';\nimport { InitToolStyleConfig } from '@/store/toolStyle/actionCreators';\nimport { AnnotationEngine, ImgUtils } from '@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/views/MainView/annotationOperation/index.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { Spin, message } from 'antd/es';\nimport { AppState } from 'src/store';\nimport { connect } from 'react-redux';\nimport { ImgAttributeState } from 'src/store/imgAttribute/types';\nimport _ from 'lodash';\nimport { store } from '@/index';\n\nimport useSize from '@/hooks/useSize';\nimport { IFileItem } from '@/types/data';\nimport { IStepInfo } from '@/types/step';\nimport { InitToolStyleConfig } from '@/store/toolStyle/actionCreators';\nimport { AnnotationEngine, ImgUtils } from '@labelbee/lb-annotation';\nimport ImageError from '@/components/ImageError';\nimport { i18n } from '@labelbee/lb-utils';\n\ninterface IProps extends AppState {\n imgAttribute: ImgAttributeState;\n imgList: IFileItem[];\n exportData: any[];\n config: string;\n stepList: IStepInfo[];\n step: number;\n imgIndex: number;\n annotationEngine: AnnotationEngine;\n loading: boolean;\n}\n\nconst AnnotationOperation: React.FC<IProps> = (props: IProps) => {\n const [, forceRender] = useState<number>(0);\n\n const { imgAttribute, toolStyle, toolInstance, annotationEngine, loading, imgList, imgIndex } =\n props;\n const annotationRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n // const windowSize = useContext(viewportContext);\n // const canvasSize = getFormatSize(windowSize);\n const size = useSize(annotationRef);\n\n useEffect(() => {\n store.dispatch(InitToolStyleConfig());\n }, []);\n\n useEffect(() => {\n if (!annotationEngine) {\n return;\n }\n\n // 更改 toolInstance 内部国际化语言\n switch (i18n.language) {\n case 'cn':\n case 'en':\n annotationEngine.setLang(i18n.language);\n break;\n default: {\n //\n break;\n }\n }\n }, [annotationEngine]);\n\n useEffect(() => {\n if (toolInstance) {\n toolInstance.singleOn('messageError', (error: string) => {\n message.error(error);\n });\n\n toolInstance.singleOn('messageInfo', (info: string) => {\n message.info(info);\n });\n\n toolInstance.singleOn('changeAnnotationShow', () => {\n forceRender((s) => s + 1);\n });\n }\n }, [toolInstance]);\n\n useEffect(() => {\n if (toolInstance) {\n toolInstance.setImgAttribute(imgAttribute);\n }\n }, [imgAttribute]);\n\n /** 样式同步 */\n useEffect(() => {\n if (toolInstance) {\n toolInstance.setStyle(toolStyle);\n }\n if (annotationEngine) {\n annotationEngine.setStyle(toolStyle);\n }\n }, [toolStyle]);\n\n /** 窗口大小监听 */\n useEffect(() => {\n if (toolInstance?.setSize) {\n toolInstance.setSize(size);\n }\n\n if (annotationEngine) {\n annotationEngine.setSize(size);\n }\n }, [size]);\n\n /**\n * 重新加载图片,避免网络问题导致的图片无法加载\n * @returns\n */\n const reloadImg = () => {\n const imgInfo = imgList[imgIndex];\n if (!imgInfo.url) {\n return;\n }\n\n ImgUtils.load(imgInfo.url).then((imgNode) => {\n annotationEngine.setImgNode(imgNode as HTMLImageElement);\n });\n };\n\n return (\n <div ref={annotationRef} className='annotationOperation'>\n <Spin spinning={loading} delay={500}>\n <div className='canvas' ref={containerRef} style={size} id='toolContainer' />\n </Spin>\n {toolInstance?.isImgError === true && (\n <ImageError\n {...size}\n reloadImage={reloadImg}\n backgroundColor='#e2e2e2'\n ignoreOffsetY={true}\n />\n )}\n </div>\n );\n};\n\nconst mapStateToProps = (state: AppState) => {\n const annotationState = _.pickBy(state.annotation, (v, k) =>\n [\n 'imgList',\n 'imgIndex',\n 'stepList',\n 'step',\n 'toolInstance',\n 'annotationEngine',\n 'loading',\n ].includes(k),\n );\n return {\n imgAttribute: state.imgAttribute,\n toolStyle: state.toolStyle,\n ...annotationState,\n };\n};\n\nexport default connect(mapStateToProps)(AnnotationOperation);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,sBAAwC,CAAC,UAAkB;AAC/D,QAAM,GAAG,eAAe,SAAiB;AAEzC,QAAM,CAAE,cAAc,WAAW,cAAc,kBAAkB,SAAS,SAAS,YACjF;AACF,QAAM,gBAAgB,OAAuB;AAC7C,QAAM,eAAe,OAAuB;AAG5C,QAAM,OAAO,QAAQ;AAErB,YAAU,MAAM;AACd,UAAM,SAAS;AAAA,KACd;AAEH,YAAU,MAAM;AACd,QAAI,CAAC,kBAAkB;AACrB;AAAA;AAIF,YAAQ,KAAK;AAAA,WACN;AAAA,WACA;AACH,yBAAiB,QAAQ,KAAK;AAC9B;AAGA;AAAA,KAGH,CAAC;AAEJ,YAAU,MAAM;AACd,QAAI,cAAc;AAChB,mBAAa,SAAS,gBAAgB,CAAC,UAAkB;AACvD,gBAAQ,MAAM;AAAA;AAGhB,mBAAa,SAAS,eAAe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AAM;AAAA,KACd;AAAA;AAIP,4BAAe,QAAQ,iBAAiB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import B from"../../../../components/attributeList/index.js";import M from"../../../../components/checkboxList/index.js";import{CaretRightOutlined as P}from"@ant-design/icons";import{Collapse as T,Tooltip as H,Badge as F}from"antd/es";import{cloneDeep as U}from"lodash";import n,{useState as p,useRef as q,useEffect as v,useCallback as z}from"react";import G from"../../../../assets/annotation/common/icon_clearSmall.svg.js";import J from"../../../../assets/annotation/common/icon_clearSmall_a.svg.js";import{TagUtils as Q}from"@
|
|
1
|
+
import B from"../../../../components/attributeList/index.js";import M from"../../../../components/checkboxList/index.js";import{CaretRightOutlined as P}from"@ant-design/icons";import{Collapse as T,Tooltip as H,Badge as F}from"antd/es";import{cloneDeep as U}from"lodash";import n,{useState as p,useRef as q,useEffect as v,useCallback as z}from"react";import G from"../../../../assets/annotation/common/icon_clearSmall.svg.js";import J from"../../../../assets/annotation/common/icon_clearSmall_a.svg.js";import{TagUtils as Q}from"@labelbee/lb-annotation";import{connect as V}from"react-redux";import{useTranslation as W}from"react-i18next";const{Panel:X}=T,$=({isActive:a})=>n.createElement(P,{rotate:a?90:0}),Y=({toolInstance:a,imgIndex:N})=>{const[o,g]=p([]),i=q(null),[,j]=p(0),[w,f]=p(-1),{t:b}=W();v(()=>{a&&(g(a.config.inputList.map(e=>e.value)),a.singleOn("render",()=>{j(e=>e+1)}))},[a]),v(()=>{if(a&&(a.singleOn("expend",O),a.labelSelectedList.length===1)){let e=0;for(let l=0;l<a.labelSelectedList[0];l++)e+=46,s[l]&&o[l]!==""&&s[l].subSelected.forEach(r=>{e+=40});i.current&&(i.current.children[0].scrollTop=e)}}),v(()=>{i.current&&(i.current.children[0].scrollTop=0)},[N]);const O=()=>{var e;const l=a.labelSelectedList[0],r=(e=s.filter((t,m)=>m===l)[0])==null?void 0:e.value;h(l,r,!0)},h=z((e,l,r)=>{const t=U(o);t[e]===""||r===!0?t[e]=l:t[e]="",g(t)},[o]);if(!a)return null;const{labelSelectedList:c,config:{inputList:s},currentTagResult:u,setLabel:E}=a,A=e=>c.length>0&&c[0]===e?n.createElement("span",{className:"keyDownIconActive"},e+1):n.createElement("span",{className:"keyDownIcon"},e+1),y=(e,l=-1)=>e?e.map((r,t)=>{var m,L,k,_,C;if(r.subSelected){const R=Q.judgeResultIsInInputList(r.value,(m=u==null?void 0:u.result)==null?void 0:m[r.value],s);return n.createElement(T,{bordered:!1,expandIcon:$,key:`collapse_${t}_${l+1}`,onChange:()=>h(t,r.value),activeKey:[o[t]]},n.createElement(X,{header:n.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"}},n.createElement("span",null,r.key,n.createElement(H,{placement:"bottom",title:b("ClearThisOption")},n.createElement("img",{style:{marginLeft:5,cursor:"pointer"},onClick:K=>{K.stopPropagation(),a.clearResult(!0,r.value)},src:w===t||R?J:G,onMouseEnter:()=>{f(t)},onMouseLeave:()=>{f(-1)}})),R&&o[t]===""&&n.createElement(F,{color:"#87d068"})),(s==null?void 0:s.length)>1&&A(t)),key:r.value},n.createElement("div",{className:"level",style:{backgroundColor:c.length>0&&c[0]===t?"rgba(158, 158, 158, 0.18)":""}},y(r.subSelected,t))))}const d=(s==null?void 0:s[l])?s==null?void 0:s[l].value:0,S=((_=(k=(L=u==null?void 0:u.result)==null?void 0:L[d])==null?void 0:k.split(";"))==null?void 0:_.indexOf(r.value))>-1?r.value:"";return((C=s==null?void 0:s[l])==null?void 0:C.isMulti)===!0?n.createElement("div",{className:"singleBar",key:`${d}_${l}_${t}`},n.createElement(M,{attributeChanged:()=>E(l,t),selectedAttribute:[S],list:[{value:r.value,label:r.key}],num:t+1})):n.createElement("div",{className:"singleBar",key:`${d}_${l}_${t}`},n.createElement(B,{forbidColor:!0,attributeChanged:()=>E(l,t),selectedAttribute:S,list:[{value:r.value,label:r.key}],num:t+1}))}):null,D=window.innerHeight-61-80;return n.createElement("div",{className:"tagOperationMenu",ref:i},(s==null?void 0:s.length)===0?n.createElement("div",{style:{padding:20,textAlign:"center"}},b("NoConfiguration")):n.createElement("div",{className:"main",style:{height:D}},y(s)))};function Z(a){return{toolInstance:a.annotation.toolInstance,imgIndex:a.annotation.imgIndex}}var x=V(Z)(Y);export{x as default,$ as expandIconFuc};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/views/MainView/sidebar/TagSidebar/index.tsx"],"sourcesContent":["import RadioList from '@/components/attributeList';\nimport CheckBoxList from '@/components/checkboxList';\nimport { CaretRightOutlined } from '@ant-design/icons';\nimport { Badge, Collapse, Tooltip } from 'antd/es';\nimport { cloneDeep } from 'lodash';\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\nimport clearSmall from '@/assets/annotation/common/icon_clearSmall.svg';\nimport clearSmallA from '@/assets/annotation/common/icon_clearSmall_a.svg';\nimport { TagOperation, TagUtils } from '@sensetime/annotation';\nimport { connect } from 'react-redux';\nimport { AppState } from '@/store';\nimport { IInputList } from '@/types/main';\nimport { useTranslation } from 'react-i18next';\n\ninterface IProps {\n imgIndex: number;\n toolInstance: TagOperation;\n}\n\nconst { Panel } = Collapse;\n\nexport const expandIconFuc = ({ isActive }: any) => (\n <CaretRightOutlined rotate={isActive ? 90 : 0} />\n);\n\nconst TagSidebar: React.FC<IProps> = ({ toolInstance, imgIndex }) => {\n const [expandKeyList, setExpandKeyList] = useState<string[]>([]);\n\n const sidebarRef = useRef<HTMLDivElement>(null);\n const [, forceRender] = useState<number>(0);\n const [hoverDeleteIndex, setHoverDeleteIndex] = useState(-1);\n const { t } = useTranslation();\n\n useEffect(() => {\n if (toolInstance) {\n // 用于配置的初始化\n setExpandKeyList(toolInstance.config.inputList.map((v: IInputList) => v.value));\n\n // 进行实时渲染\n toolInstance.singleOn('render', () => {\n forceRender((s) => s + 1);\n });\n }\n }, [toolInstance]);\n\n useEffect(() => {\n if (toolInstance) {\n // 该写法会不断的重复绑定,后续写法上可以更改(如果将 singleOn 改为 on 会有很大问题)\n toolInstance.singleOn('expend', expendRender);\n\n if (toolInstance.labelSelectedList.length === 1) {\n let height = 0;\n for (let i = 0; i < toolInstance.labelSelectedList[0]; i++) {\n height += 46;\n inputList[i] &&\n expandKeyList[i] !== '' &&\n inputList[i].subSelected.forEach((i: any) => {\n height += 40;\n });\n }\n if (sidebarRef.current) {\n sidebarRef.current.children[0].scrollTop = height;\n }\n }\n }\n });\n\n useEffect(() => {\n // 翻页侧边栏跳到最上\n if (sidebarRef.current) {\n sidebarRef.current.children[0].scrollTop = 0;\n }\n }, [imgIndex]);\n\n const expendRender = () => {\n const index = toolInstance.labelSelectedList[0];\n const value = inputList.filter((v: IInputList, i: number) => i === index)[0]?.value;\n setExpendKeyList(index, value, true);\n };\n\n const setExpendKeyList = useCallback(\n (index: number, value: string, expend?: boolean) => {\n const newKeyList = cloneDeep(expandKeyList);\n if (newKeyList[index] === '' || expend === true) {\n newKeyList[index] = value;\n } else {\n newKeyList[index] = '';\n }\n setExpandKeyList(newKeyList);\n },\n [expandKeyList],\n );\n\n if (!toolInstance) return null;\n\n const {\n labelSelectedList,\n config: { inputList },\n currentTagResult,\n setLabel,\n } = toolInstance;\n\n const selectedButton = (index: number) => {\n if (labelSelectedList.length > 0 && labelSelectedList[0] === index) {\n return <span className='keyDownIconActive'>{index + 1}</span>;\n }\n return <span className='keyDownIcon'>{index + 1}</span>;\n };\n\n // basicIndex 到底是那一层\n const labelPanel = (labelInfoSet: IInputList[], basicIndex = -1) => {\n if (!labelInfoSet) {\n return null;\n }\n\n return labelInfoSet.map((info: IInputList, index: number) => {\n if (info.subSelected) {\n // 判断是否有数据\n const isResult = TagUtils.judgeResultIsInInputList(\n info.value,\n currentTagResult?.result?.[info.value],\n inputList,\n );\n\n return (\n <Collapse\n bordered={false}\n expandIcon={expandIconFuc}\n key={`collapse_${index}_${basicIndex + 1}`}\n onChange={() => setExpendKeyList(index, info.value)}\n activeKey={[expandKeyList[index]]}\n >\n <Panel\n header={\n <div\n style={{\n display: 'flex',\n justifyContent: 'space-between',\n alignItems: 'center',\n }}\n >\n <span>\n {info.key}\n <Tooltip placement='bottom' title={t('ClearThisOption')}>\n <img\n style={{ marginLeft: 5, cursor: 'pointer' }}\n onClick={(e) => {\n e.stopPropagation();\n toolInstance.clearResult(true, info.value);\n }}\n src={hoverDeleteIndex === index || isResult ? clearSmallA : clearSmall}\n onMouseEnter={() => {\n setHoverDeleteIndex(index);\n }}\n onMouseLeave={() => {\n setHoverDeleteIndex(-1);\n }}\n />\n </Tooltip>\n {isResult && expandKeyList[index] === '' && <Badge color='#87d068' />}\n </span>\n\n {inputList?.length > 1 && selectedButton(index)}\n </div>\n }\n key={info.value}\n >\n <div\n className='level'\n style={{\n backgroundColor:\n labelSelectedList.length > 0 && labelSelectedList[0] === index\n ? 'rgba(158, 158, 158, 0.18)'\n : '',\n }}\n >\n {labelPanel(info.subSelected, index)}\n </div>\n </Panel>\n </Collapse>\n );\n }\n const key = inputList?.[basicIndex] ? inputList?.[basicIndex].value : 0;\n const selectedAttribute =\n currentTagResult?.result?.[key]?.split(';')?.indexOf(info.value) > -1 ? info.value : '';\n\n if (inputList?.[basicIndex]?.isMulti === true) {\n return (\n <div className='singleBar' key={`${key}_${basicIndex}_${index}`}>\n <CheckBoxList\n attributeChanged={() => setLabel(basicIndex, index)}\n selectedAttribute={[selectedAttribute]}\n list={[{ value: info.value, label: info.key }]}\n num={index + 1}\n />\n </div>\n );\n }\n return (\n <div className='singleBar' key={`${key}_${basicIndex}_${index}`}>\n <RadioList\n forbidColor\n attributeChanged={() => setLabel(basicIndex, index)}\n selectedAttribute={selectedAttribute}\n list={[{ value: info.value, label: info.key }]}\n num={index + 1}\n />\n </div>\n );\n });\n };\n const height = window.innerHeight - 61 - 80;\n\n return (\n <div className='tagOperationMenu' ref={sidebarRef}>\n {inputList?.length === 0 ? (\n <div style={{ padding: 20, textAlign: 'center' }}>{t('NoConfiguration')}</div>\n ) : (\n <div className='main' style={{ height }}>\n {labelPanel(inputList)}\n </div>\n )}\n </div>\n );\n};\n\nfunction mapStateToProps(state: AppState) {\n return { toolInstance: state.annotation.toolInstance, imgIndex: state.annotation.imgIndex };\n}\n\nexport default connect(mapStateToProps)(TagSidebar);\n"],"names":["clearSmallA","clearSmall","CheckBoxList","RadioList"],"mappings":";;;;;;;;;;;;AAmBA,MAAM,CAAE,SAAU;MAEL,gBAAgB,CAAC,CAAE,kDAC7B,oBAAD;AAAA,EAAoB,QAAQ,WAAW,KAAK;AAAA;AAG9C,MAAM,aAA+B,CAAC,CAAE,cAAc,cAAe;AACnE,QAAM,CAAC,eAAe,oBAAoB,SAAmB;AAE7D,QAAM,aAAa,OAAuB;AAC1C,QAAM,GAAG,eAAe,SAAiB;AACzC,QAAM,CAAC,kBAAkB,uBAAuB,SAAS;AACzD,QAAM,CAAE,KAAM;AAEd,YAAU,MAAM;AACd,QAAI,cAAc;AAEhB,uBAAiB,aAAa,OAAO,UAAU,IAAI,CAAC,MAAkB,EAAE;AAGxE,mBAAa,SAAS,UAAU,MAAM;AACpC,oBAAY,CAAC,MAAM,IAAI;AAAA;AAAA;AAAA,KAG1B,CAAC;AAEJ,YAAU,MAAM;AACd,QAAI,cAAc;AAEhB,mBAAa,SAAS,UAAU;AAEhC,UAAI,aAAa,kBAAkB,WAAW,GAAG;AAC/C,YAAI,UAAS;AACb,iBAAS,IAAI,GAAG,IAAI,aAAa,kBAAkB,IAAI,KAAK;AAC1D,qBAAU;AACV,oBAAU,MACR,cAAc,OAAO,MACrB,UAAU,GAAG,YAAY,QAAQ,CAAC,OAAW;AAC3C,uBAAU;AAAA;AAAA;AAGhB,YAAI,WAAW,SAAS;AACtB,qBAAW,QAAQ,SAAS,GAAG,YAAY;AAAA;AAAA;AAAA;AAAA;AAMnD,YAAU,MAAM;AAEd,QAAI,WAAW,SAAS;AACtB,iBAAW,QAAQ,SAAS,GAAG,YAAY;AAAA;AAAA,KAE5C,CAAC;AAEJ,QAAM,eAAe,MAAM;AA1E7B;AA2EI,UA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AM,SAAS,YAAY;AAAA,QAC7C;AAAA,QACA,MAAM,CAAC,CAAE,OAAO,KAAK,OAAO,OAAO,KAAK;AAAA,QACxC,KAAK,QAAQ;AAAA;AAAA;AAAA;AAMvB,QAAM,SAAS,OAAO,cAAc,KAAK;AAEzC,6CACG,OAAD;AAAA,IAAK,WAAU;AAAA,IAAmB,KAAK;AAAA,KACpC,wCAAW,YAAW,wCACpB,OAAD;AAAA,IAAK,OAAO,CAAE,SAAS,IAAI,WAAW;AAAA,KAAa,EAAE,0DAEpD,OAAD;AAAA,IAAK,WAAU;AAAA,IAAO,OAAO,CAAE;AAAA,KAC5B,WAAW;AAAA;AAOtB,yBAAyB,OAAiB;AACxC,SAAO,CAAE,cAAc,MAAM,WAAW,cAAc,UAAU,MAAM,WAAW;AAAA;AAGnF,mBAAe,QAAQ,iBAAiB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/views/MainView/sidebar/TagSidebar/index.tsx"],"sourcesContent":["import RadioList from '@/components/attributeList';\nimport CheckBoxList from '@/components/checkboxList';\nimport { CaretRightOutlined } from '@ant-design/icons';\nimport { Badge, Collapse, Tooltip } from 'antd/es';\nimport { cloneDeep } from 'lodash';\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\nimport clearSmall from '@/assets/annotation/common/icon_clearSmall.svg';\nimport clearSmallA from '@/assets/annotation/common/icon_clearSmall_a.svg';\nimport { TagOperation, TagUtils } from '@labelbee/lb-annotation';\nimport { connect } from 'react-redux';\nimport { AppState } from '@/store';\nimport { IInputList } from '@/types/main';\nimport { useTranslation } from 'react-i18next';\nimport { DEFAULT_CANVAS_SIZE } from '@/constant';\n\ninterface IProps {\n imgIndex: number;\n toolInstance: TagOperation;\n}\n\nconst { Panel } = Collapse;\n\nexport const expandIconFuc = ({ isActive }: any) => (\n <CaretRightOutlined rotate={isActive ? 90 : 0} />\n);\n\nconst TagSidebar: React.FC<IProps> = ({ toolInstance, imgIndex }) => {\n const [expandKeyList, setExpandKeyList] = useState<string[]>([]);\n\n const sidebarRef = useRef<HTMLDivElement>(null);\n const [, forceRender] = useState<number>(0);\n const [hoverDeleteIndex, setHoverDeleteIndex] = useState(-1);\n const { t } = useTranslation();\n\n useEffect(() => {\n if (toolInstance) {\n // 用于配置的初始化\n setExpandKeyList(toolInstance.config.inputList.map((v: IInputList) => v.value));\n\n // 进行实时渲染\n toolInstance.singleOn('render', () => {\n forceRender((s) => s + 1);\n });\n }\n }, [toolInstance]);\n\n useEffect(() => {\n if (toolInstance) {\n // 该写法会不断的重复绑定,后续写法上可以更改(如果将 singleOn 改为 on 会有很大问题)\n toolInstance.singleOn('expend', expendRender);\n\n if (toolInstance.labelSelectedList.length === 1) {\n let height = 0;\n for (let i = 0; i < toolInstance.labelSelectedList[0]; i++) {\n height += 46;\n inputList[i] &&\n expandKeyList[i] !== '' &&\n inputList[i].subSelected.forEach((i: any) => {\n height += 40;\n });\n }\n if (sidebarRef.current) {\n sidebarRef.current.children[0].scrollTop = height;\n }\n }\n }\n });\n\n useEffect(() => {\n // 翻页侧边栏跳到最上\n if (sidebarRef.current) {\n sidebarRef.current.children[0].scrollTop = 0;\n }\n }, [imgIndex]);\n\n const expendRender = () => {\n const index = toolInstance.labelSelectedList[0];\n const value = inputList.filter((v: IInputList, i: number) => i === index)[0]?.value;\n setExpendKeyList(index, value, true);\n };\n\n const setExpendKeyList = useCallback(\n (index: number, value: string, expend?: boolean) => {\n const newKeyList = cloneDeep(expandKeyList);\n if (newKeyList[index] === '' || expend === true) {\n newKeyList[index] = value;\n } else {\n newKeyList[index] = '';\n }\n setExpandKeyList(newKeyList);\n },\n [expandKeyList],\n );\n\n if (!toolInstance) return null;\n\n const {\n labelSelectedList,\n config: { inputList },\n currentTagResult,\n setLabel,\n } = toolInstance;\n\n const selectedButton = (index: number) => {\n if (labelSelectedList.length > 0 && labelSelectedList[0] === index) {\n return <span className='keyDownIconActive'>{index + 1}</span>;\n }\n return <span className='keyDownIcon'>{index + 1}</span>;\n };\n\n // basicIndex 到底是那一层\n const labelPanel = (labelInfoSet: IInputList[], basicIndex = -1) => {\n if (!labelInfoSet) {\n return null;\n }\n\n return labelInfoSet.map((info: IInputList, index: number) => {\n if (info.subSelected) {\n // 判断是否有数据\n const isResult = TagUtils.judgeResultIsInInputList(\n info.value,\n currentTagResult?.result?.[info.value],\n inputList,\n );\n\n return (\n <Collapse\n bordered={false}\n expandIcon={expandIconFuc}\n key={`collapse_${index}_${basicIndex + 1}`}\n onChange={() => setExpendKeyList(index, info.value)}\n activeKey={[expandKeyList[index]]}\n >\n <Panel\n header={\n <div\n style={{\n display: 'flex',\n justifyContent: 'space-between',\n alignItems: 'center',\n }}\n >\n <span>\n {info.key}\n <Tooltip placement='bottom' title={t('ClearThisOption')}>\n <img\n style={{ marginLeft: 5, cursor: 'pointer' }}\n onClick={(e) => {\n e.stopPropagation();\n toolInstance.clearResult(true, info.value);\n }}\n src={hoverDeleteIndex === index || isResult ? clearSmallA : clearSmall}\n onMouseEnter={() => {\n setHoverDeleteIndex(index);\n }}\n onMouseLeave={() => {\n setHoverDeleteIndex(-1);\n }}\n />\n </Tooltip>\n {isResult && expandKeyList[index] === '' && <Badge color='#87d068' />}\n </span>\n\n {inputList?.length > 1 && selectedButton(index)}\n </div>\n }\n key={info.value}\n >\n <div\n className='level'\n style={{\n backgroundColor:\n labelSelectedList.length > 0 && labelSelectedList[0] === index\n ? 'rgba(158, 158, 158, 0.18)'\n : '',\n }}\n >\n {labelPanel(info.subSelected, index)}\n </div>\n </Panel>\n </Collapse>\n );\n }\n const key = inputList?.[basicIndex] ? inputList?.[basicIndex].value : 0;\n const selectedAttribute =\n currentTagResult?.result?.[key]?.split(';')?.indexOf(info.value) > -1 ? info.value : '';\n\n if (inputList?.[basicIndex]?.isMulti === true) {\n return (\n <div className='singleBar' key={`${key}_${basicIndex}_${index}`}>\n <CheckBoxList\n attributeChanged={() => setLabel(basicIndex, index)}\n selectedAttribute={[selectedAttribute]}\n list={[{ value: info.value, label: info.key }]}\n num={index + 1}\n />\n </div>\n );\n }\n return (\n <div className='singleBar' key={`${key}_${basicIndex}_${index}`}>\n <RadioList\n forbidColor\n attributeChanged={() => setLabel(basicIndex, index)}\n selectedAttribute={selectedAttribute}\n list={[{ value: info.value, label: info.key }]}\n num={index + 1}\n />\n </div>\n );\n });\n };\n const height = window ? (window?.innerHeight ?? DEFAULT_CANVAS_SIZE.height) - 61 - 80 : 0;\n\n return (\n <div className='tagOperationMenu' ref={sidebarRef}>\n {inputList?.length === 0 ? (\n <div style={{ padding: 20, textAlign: 'center' }}>{t('NoConfiguration')}</div>\n ) : (\n <div className='main' style={{ height }}>\n {labelPanel(inputList)}\n </div>\n )}\n </div>\n );\n};\n\nfunction mapStateToProps(state: AppState) {\n return { toolInstance: state.annotation.toolInstance, imgIndex: state.annotation.imgIndex };\n}\n\nexport default connect(mapStateToProps)(TagSidebar);\n"],"names":["clearSmallA","clearSmall","CheckBoxList","RadioList"],"mappings":";;;;;;;;;;;;;AAoBA,MAAM,CAAE,SAAU;MAEL,gBAAgB,CAAC,CAAE,kDAC7B,oBAAD;AAAA,EAAoB,QAAQ,WAAW,KAAK;AAAA;AAG9C,MAAM,aAA+B,CAAC,CAAE,cAAc,cAAe;AA1BrE;AA2BE,QAAM,CAAC,eAAe,oBAAoB,SAAmB;AAE7D,QAAM,aAAa,OAAuB;AAC1C,QAAM,GAAG,eAAe,SAAiB;AACzC,QAAM,CAAC,kBAAkB,uBAAuB,SAAS;AACzD,QAAM,CAAE,KAAM;AAEd,YAAU,MAAM;AACd,QAAI,cAAc;AAEhB,uBAAiB,aAAa,OAAO,UAAU,IAAI,CAAC,MAAkB,EAAE;AAGxE,mBAAa,SAAS,UAAU,MAAM;AACpC,oBAAY,CAAC,MAAM,IAAI;AAAA;AAAA;AAAA,KAG1B,CAAC;AAEJ,YAAU,MAAM;AACd,QAAI,cAAc;AAEhB,mBAAa,SAAS,UAAU;AAEhC,UAAI,aAAa,kBAAkB,WAAW,GAAG;AAC/C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Y,gBAAZ,mBAAyB,aAAY,MAAM;AAC7C,mDACG,OAAD;AAAA,UAAK,WAAU;AAAA,UAAY,KAAK,GAAG,OAAO,cAAc;AAAA,+CACrDC,cAAD;AAAA,UACE,kBAAkB,MAAM,SAAS,YAAY;AAAA,UAC7C,mBAAmB,CAAC;AAAA,UACpB,MAAM,CAAC,CAAE,OAAO,KAAK,OAAO,OAAO,KAAK;AAAA,UACxC,KAAK,QAAQ;AAAA;AAAA;AAKrB,iDACG,OAAD;AAAA,QAAK,WAAU;AAAA,QAAY,KAAK,GAAG,OAAO,cAAc;AAAA,6CACrDC,eAAD;AAAA,QACE,aAAW;AAAA,QACX,kBAAkB,MAAM,SAAS,YAAY;AAAA,QAC7C;AAAA,QACA,MAAM,CAAC,CAAE,OAAO,KAAK,OAAO,OAAO,KAAK;AAAA,QACxC,KAAK,QAAQ;AAAA;AAAA;AAAA;AAMvB,QAAM,SAAS,SAAU,wCAAQ,gBAAR,YAAuB,oBAAoB,UAAU,KAAK,KAAK;AAExF,6CACG,OAAD;AAAA,IAAK,WAAU;AAAA,IAAmB,KAAK;AAAA,KACpC,wCAAW,YAAW,wCACpB,OAAD;AAAA,IAAK,OAAO,CAAE,SAAS,IAAI,WAAW;AAAA,KAAa,EAAE,0DAEpD,OAAD;AAAA,IAAK,WAAU;AAAA,IAAO,OAAO,CAAE;AAAA,KAC5B,WAAW;AAAA;AAOtB,yBAAyB,OAAiB;AACxC,SAAO,CAAE,cAAc,MAAM,WAAW,cAAc,UAAU,MAAM,WAAW;AAAA;AAGnF,mBAAe,QAAQ,iBAAiB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import n,{useState as d,useEffect as _,useRef as K}from"react";import{connect as R}from"react-redux";import{cloneDeep as j}from"lodash";import{classnames as C}from"../../../../utils/index.js";import{Input as D}from"antd/es";import{cKeyCode as $}from"@
|
|
1
|
+
import n,{useState as d,useEffect as _,useRef as K}from"react";import{connect as R}from"react-redux";import{cloneDeep as j}from"lodash";import{classnames as C}from"../../../../utils/index.js";import{Input as D}from"antd/es";import{cKeyCode as $}from"@labelbee/lb-annotation";import{PageForward as q}from"../../../../store/annotation/actionCreators.js";import{ConfigUtils as U}from"../../../../utils/ConfigUtils.js";import{useTranslation as B}from"react-i18next";var M=Object.defineProperty,I=Object.getOwnPropertySymbols,z=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,S=(e,t,a)=>t in e?M(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,W=(e,t)=>{for(var a in t||(t={}))z.call(t,a)&&S(e,a,t[a]);if(I)for(var a of I(t))V.call(t,a)&&S(e,a,t[a]);return e};const F=$.default,L=e=>{e.stopPropagation(),e.nativeEvent.stopPropagation(),e.nativeEvent.stopImmediatePropagation()},O=e=>{const{textareaProps:t,footer:a}=e;return n.createElement(n.Fragment,null,n.createElement(D.TextArea,W({bordered:!1,rows:6,onKeyDown:L,onKeyUp:L},t)),n.createElement("div",{className:C({textAreaLength:!0})},a))},k=e=>{var t;const a=K(null),[g,c]=d(!1),[w,x]=d(!1),{t:u}=B(),{disabled:l,config:i,result:v,updateText:E,index:T,switchToNextTextarea:h,hasMultiple:P,onNext:p}=e,{maxLength:m}=i,f=v?v[i.key]:"",y=(t=f==null?void 0:f.length)!=null?t:0,N=o=>{E&&(E(o,i.key),i.required&&x(!o))},b=P&&h,r={id:`textInput-${T}`,ref:a,disabled:l,value:f,maxLength:m,autoSize:{minRows:2,maxRows:6},onChange:o=>{const A=o.target.value;N(A)},onFocus:()=>{c(!0)},onBlur:o=>{c(!1),i.required&&x(!o.target.value)},style:{resize:"none",wordBreak:"break-all"},onKeyDownCapture:o=>{o.ctrlKey&&o.keyCode===F.Enter&&(p&&p(),o.preventDefault()),o.keyCode===F.Tab&&b&&(o.preventDefault(),o.nativeEvent.stopImmediatePropagation(),h(T)),o.nativeEvent.stopPropagation()}},s=n.createElement("div",{className:"textAreaFooter"},n.createElement("div",{className:"hotkeyTip"},b&&n.createElement("span",null,`[${u("Switch")}]Tab`),n.createElement("span",null,`[${u("TurnPage")}]Ctrl+Enter`)),n.createElement("div",{className:"wordCount"},n.createElement("span",{className:y>=m?"warning":""},y),"/",n.createElement("span",null,m)));return _(()=>{l&&c(!1)},[l]),n.createElement("div",{className:"textField"},n.createElement("div",{className:"label"},n.createElement("span",{className:C({required:i.required})},i.label),n.createElement("i",{className:C({clearText:!0,disabled:l}),onClick:()=>{l||N("")}})),n.createElement("div",{className:C({disabled:l,"textarea-outline":!0,"ant-input-focused":g,textareaContainer:!0,focus:g,invalid:w})},n.createElement(O,{footer:s,textareaProps:r})))},G=({toolInstance:e,imgIndex:t,dispatch:a,triggerEventAfterIndexChanged:g,step:c,stepList:w,basicResultList:x})=>{var u,l;const[i,v]=d([]),[E,T]=d(0),[,h]=d(0),P=r=>{const s=(r+1)%i.length;p(s)},p=r=>{setTimeout(()=>{const s=document.getElementById(`textInput-${r}`);s&&(T(r),s.focus(),s.select(),s.scrollIntoView({behavior:"smooth",block:"center"}))})};_(()=>{e&&(v(j(e.config.configList)),e.singleOn("valueUpdated",()=>{h(r=>r+1)}))},[e]);const m=(r,s)=>{e.updateTextValue(s,r)};_(()=>{t>-1&&g&&p(0)},[t]);const f=(l=(u=e.textList[0])==null?void 0:u.value)!=null?l:{},y=()=>{a(q(!0))},b=U.getStepConfig(w,c).dataSourceStep>0&&x.length===0;return n.createElement("div",{className:"textToolOperationMenu"},i.map((r,s)=>n.createElement(k,{config:r,key:r.key,index:s,result:f,updateText:m,switchToNextTextarea:P,hasMultiple:i.length>1,focus:E===s,onNext:y,disabled:b})))};function H(e){return{toolInstance:e.annotation.toolInstance,imgIndex:e.annotation.imgIndex,step:e.annotation.step,basicResultList:e.annotation.basicResultList,stepList:e.annotation.stepList,triggerEventAfterIndexChanged:e.annotation.triggerEventAfterIndexChanged}}var J=R(H)(G);export{k as SingleTextInput,O as TextareaWithFooter,J as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/views/MainView/sidebar/TextToolSidebar/index.tsx"],"sourcesContent":["import React, { useEffect, useState, useRef, FocusEvent } from 'react';\nimport { connect } from 'react-redux';\nimport { AppState } from '@/store';\nimport { cloneDeep } from 'lodash';\nimport { classnames } from '@/utils';\nimport { Input } from 'antd/es';\nimport { cKeyCode } from '@sensetime/annotation';\nimport { PageForward } from '@/store/annotation/actionCreators';\nimport { ConfigUtils } from '@/utils/ConfigUtils';\nimport { IStepInfo } from '@/types/step';\nimport TextToolOperation from '@sensetime/annotation/dist/types/core/toolOperation/TextToolOperation';\nimport { useTranslation } from 'react-i18next';\n\nconst EKeyCode = cKeyCode.default;\n\nconst syntheticEventStopPagination = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n e.stopPropagation();\n e.nativeEvent.stopPropagation();\n e.nativeEvent.stopImmediatePropagation();\n};\n\ninterface ITextareaWithFooterProps {\n textareaProps?: any;\n footer?: any;\n}\n\nexport const TextareaWithFooter = (props: ITextareaWithFooterProps) => {\n const { textareaProps, footer } = props;\n\n return (\n <>\n <Input.TextArea\n bordered={false}\n rows={6}\n onKeyDown={syntheticEventStopPagination}\n onKeyUp={syntheticEventStopPagination}\n {...textareaProps}\n />\n <div\n className={classnames({\n textAreaLength: true,\n })}\n >\n {footer}\n </div>\n </>\n );\n};\n\ninterface IProps {\n dispatch: Function;\n toolInstance: TextToolOperation;\n imgIndex: number;\n triggerEventAfterIndexChanged: boolean;\n step: number;\n stepList: IStepInfo[];\n basicResultList: any[];\n}\n\ninterface IConfigListItem {\n label: string;\n key: string;\n required: boolean;\n default: string;\n maxLength: number;\n}\n\nexport const SingleTextInput = (props: any) => {\n const ref = useRef(null);\n const [textAreaFocus, setTextAreaFocus] = useState(false);\n const [invalid, setInvalid] = useState(false);\n const { t } = useTranslation();\n\n const { disabled, config, result, updateText, index, switchToNextTextarea, hasMultiple, onNext } =\n props;\n const { maxLength } = config;\n\n const value = result ? result[config.key] : '';\n const textLength = value?.length ?? 0;\n\n const updateTextWithKey = (newVal: string) => {\n if (updateText) {\n updateText(newVal, config.key);\n if (config.required) {\n setInvalid(!newVal);\n }\n }\n };\n\n const tabToSwitchEnabled = hasMultiple && switchToNextTextarea;\n\n const textareaProps = {\n id: `textInput-${index}`,\n ref,\n disabled,\n value,\n maxLength,\n autoSize: { minRows: 2, maxRows: 6 },\n onChange: (e: FocusEvent<HTMLTextAreaElement>) => {\n const value = e.target.value;\n updateTextWithKey(value);\n },\n onFocus: () => {\n setTextAreaFocus(true);\n },\n onBlur: (e: FocusEvent<HTMLTextAreaElement>) => {\n setTextAreaFocus(false);\n if (config.required) {\n setInvalid(!e.target.value);\n }\n },\n style: {\n resize: 'none',\n wordBreak: 'break-all',\n },\n onKeyDownCapture: (e: React.KeyboardEvent) => {\n if (e.ctrlKey && e.keyCode === EKeyCode.Enter) {\n if (onNext) {\n onNext();\n }\n e.preventDefault();\n }\n\n if (e.keyCode === EKeyCode.Tab && tabToSwitchEnabled) {\n e.preventDefault();\n e.nativeEvent.stopImmediatePropagation();\n switchToNextTextarea(index);\n }\n\n e.nativeEvent.stopPropagation();\n },\n };\n\n const TextareaFooter = (\n <div className='textAreaFooter'>\n <div className='hotkeyTip'>\n {tabToSwitchEnabled && <span>{`[${t('Switch')}]Tab`}</span>}\n <span>{`[${t('TurnPage')}]Ctrl+Enter`}</span>\n </div>\n <div className='wordCount'>\n <span className={textLength >= maxLength ? 'warning' : ''}>{textLength}</span>/\n <span>{maxLength}</span>\n </div>\n </div>\n );\n\n useEffect(() => {\n if (disabled) {\n setTextAreaFocus(false);\n }\n }, [disabled]);\n\n return (\n <div className='textField'>\n <div className='label'>\n <span className={classnames({ required: config.required })}>{config.label}</span>\n <i\n className={classnames({ clearText: true, disabled: disabled })}\n onClick={() => {\n if (disabled) {\n return;\n }\n updateTextWithKey('');\n }}\n />\n </div>\n <div\n className={classnames({\n disabled,\n 'textarea-outline': true,\n 'ant-input-focused': textAreaFocus,\n textareaContainer: true,\n focus: textAreaFocus,\n invalid: invalid,\n })}\n >\n <TextareaWithFooter footer={TextareaFooter} textareaProps={textareaProps} />\n </div>\n </div>\n );\n};\n\nconst TextToolSidebar: React.FC<IProps> = ({\n toolInstance,\n imgIndex,\n dispatch,\n triggerEventAfterIndexChanged,\n step,\n stepList,\n basicResultList,\n}) => {\n const [configList, setConfigList] = useState<IConfigListItem[]>([]);\n const [focusIndex, setFocusIndex] = useState(0);\n const [, forceRender] = useState(0);\n\n const switchToNextTextarea = (currentIndex: number) => {\n const nextIndex = (currentIndex + 1) % configList.length;\n textareaFocus(nextIndex);\n };\n\n const textareaFocus = (index: number) => {\n setTimeout(() => {\n const textarea = document.getElementById(`textInput-${index}`) as HTMLTextAreaElement;\n if (textarea) {\n setFocusIndex(index);\n textarea.focus();\n textarea.select();\n textarea.scrollIntoView({ behavior: 'smooth', block: 'center' });\n }\n });\n };\n\n useEffect(() => {\n if (toolInstance) {\n setConfigList(cloneDeep(toolInstance.config.configList));\n toolInstance.singleOn('valueUpdated', () => {\n forceRender((s) => s + 1);\n });\n }\n }, [toolInstance]);\n\n const updateText = (v: string, k: string) => {\n toolInstance.updateTextValue(k, v);\n };\n\n useEffect(() => {\n if (imgIndex > -1 && triggerEventAfterIndexChanged) {\n textareaFocus(0);\n }\n }, [imgIndex]);\n\n const result = toolInstance.textList[0]?.value ?? {};\n\n const onNext = () => {\n dispatch(PageForward(true));\n };\n\n const stepConfig = ConfigUtils.getStepConfig(stepList, step);\n const disabled = stepConfig.dataSourceStep > 0 && basicResultList.length === 0;\n\n return (\n <div className='textToolOperationMenu'>\n {configList.map((i, index) => (\n <SingleTextInput\n config={i}\n key={i.key}\n index={index}\n result={result}\n updateText={updateText}\n switchToNextTextarea={switchToNextTextarea}\n hasMultiple={configList.length > 1}\n focus={focusIndex === index}\n onNext={onNext}\n disabled={disabled}\n />\n ))}\n </div>\n );\n};\n\nfunction mapStateToProps(state: AppState) {\n return {\n toolInstance: state.annotation.toolInstance,\n imgIndex: state.annotation.imgIndex,\n step: state.annotation.step,\n basicResultList: state.annotation.basicResultList,\n stepList: state.annotation.stepList,\n triggerEventAfterIndexChanged: state.annotation.triggerEventAfterIndexChanged,\n };\n}\n\nexport default connect(mapStateToProps)(TextToolSidebar);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,WAAW,SAAS;AAE1B,MAAM,+BAA+B,CAAC,MAAgD;AACpF,IAAE;AACF,IAAE,YAAY;AACd,IAAE,YAAY;AAAA;MAQH,qBAAqB,CAAC,UAAoC;AACrE,QAAM,CAAE,eAAe,UAAW;AAElC,uGAEK,MAAM,UAAP;AAAA,IACE,UAAU;AAAA,IACV,MAAM;AAAA,IACN,WAAW;AAAA,IACX,SAAS;AAAA,KACL,qDAEL,OAAD;AAAA,IACE,WAAW,WAAW;AAAA,MACpB,gBAAgB;AAAA;AAAA,KAGjB;AAAA;MAwBI,kBAAkB,CAAC,UAAe;AAnE/C;AAoEE,QAAM,MAAM,OAAO;AACnB,QAAM,CAAC,eAAe,oBAAoB,SAAS;AACnD,QAAM,CAAC,SAAS,cAAc,SAAS;AACvC,QAAM,CAAE,KAAM;AAEd,QAAM,CAAE,UAAU,QAAQ,QAAQ,YAAY,OAAO,sBAAsB,aAAa,UACtF;AACF,QAAM,CAAE,aAAc;AAEtB,QAAM,QAAQ,SAAS,OAAO,OAAO,OAAO;AAC5C,QAAM,aAAa,qCAAO,WAAP,YAAiB;AAEpC,QAAM,oBAAoB,CAAC,WAAmB;AAC5C,QAAI,YAAY;AACd,iBAAW,QAAQ,OAAO;AAC1B,UAAI,OAAO,UAAU;AACnB,mBAAW,CAAC;AAAA;AAAA;AAAA;AAKlB,QAAM,qBAAqB,eAAe;AAE1C,QAAM,gBAAgB;AAAA,IACpB,IAAI,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAE,SAAS,GAAG,SAAS;AAAA,IACjC,UAAU,CAAC,MAAuC;AAChD,YAAM,SAAQ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A,KACZ,WAAW,IAAI,CAAC,GAAG,8CACjB,iBAAD;AAAA,IACE,QAAQ;AAAA,IACR,KAAK,EAAE;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,WAAW,SAAS;AAAA,IACjC,OAAO,eAAe;AAAA,IACtB;AAAA,IACA;AAAA;AAAA;AAOV,yBAAyB,OAAiB;AACxC,SAAO;AAAA,IACL,cAAc,MAAM,WAAW;AAAA,IAC/B,UAAU,MAAM,WAAW;AAAA,IAC3B,MAAM,MAAM,WAAW;AAAA,IACvB,iBAAiB,MAAM,WAAW;AAAA,IAClC,UAAU,MAAM,WAAW;AAAA,IAC3B,+BAA+B,MAAM,WAAW;AAAA;AAAA;AAIpD,wBAAe,QAAQ,iBAAiB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/views/MainView/sidebar/TextToolSidebar/index.tsx"],"sourcesContent":["import React, { useEffect, useState, useRef, FocusEvent } from 'react';\nimport { connect } from 'react-redux';\nimport { AppState } from '@/store';\nimport { cloneDeep } from 'lodash';\nimport { classnames } from '@/utils';\nimport { Input } from 'antd/es';\nimport { cKeyCode } from '@labelbee/lb-annotation';\nimport { PageForward } from '@/store/annotation/actionCreators';\nimport { ConfigUtils } from '@/utils/ConfigUtils';\nimport { IStepInfo } from '@/types/step';\nimport TextToolOperation from '@labelbee/lb-annotation/dist/types/core/toolOperation/TextToolOperation';\nimport { useTranslation } from 'react-i18next';\n\nconst EKeyCode = cKeyCode.default;\n\nconst syntheticEventStopPagination = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n e.stopPropagation();\n e.nativeEvent.stopPropagation();\n e.nativeEvent.stopImmediatePropagation();\n};\n\ninterface ITextareaWithFooterProps {\n textareaProps?: any;\n footer?: any;\n}\n\nexport const TextareaWithFooter = (props: ITextareaWithFooterProps) => {\n const { textareaProps, footer } = props;\n\n return (\n <>\n <Input.TextArea\n bordered={false}\n rows={6}\n onKeyDown={syntheticEventStopPagination}\n onKeyUp={syntheticEventStopPagination}\n {...textareaProps}\n />\n <div\n className={classnames({\n textAreaLength: true,\n })}\n >\n {footer}\n </div>\n </>\n );\n};\n\ninterface IProps {\n dispatch: Function;\n toolInstance: TextToolOperation;\n imgIndex: number;\n triggerEventAfterIndexChanged: boolean;\n step: number;\n stepList: IStepInfo[];\n basicResultList: any[];\n}\n\ninterface IConfigListItem {\n label: string;\n key: string;\n required: boolean;\n default: string;\n maxLength: number;\n}\n\nexport const SingleTextInput = (props: any) => {\n const ref = useRef(null);\n const [textAreaFocus, setTextAreaFocus] = useState(false);\n const [invalid, setInvalid] = useState(false);\n const { t } = useTranslation();\n\n const { disabled, config, result, updateText, index, switchToNextTextarea, hasMultiple, onNext } =\n props;\n const { maxLength } = config;\n\n const value = result ? result[config.key] : '';\n const textLength = value?.length ?? 0;\n\n const updateTextWithKey = (newVal: string) => {\n if (updateText) {\n updateText(newVal, config.key);\n if (config.required) {\n setInvalid(!newVal);\n }\n }\n };\n\n const tabToSwitchEnabled = hasMultiple && switchToNextTextarea;\n\n const textareaProps = {\n id: `textInput-${index}`,\n ref,\n disabled,\n value,\n maxLength,\n autoSize: { minRows: 2, maxRows: 6 },\n onChange: (e: FocusEvent<HTMLTextAreaElement>) => {\n const value = e.target.value;\n updateTextWithKey(value);\n },\n onFocus: () => {\n setTextAreaFocus(true);\n },\n onBlur: (e: FocusEvent<HTMLTextAreaElement>) => {\n setTextAreaFocus(false);\n if (config.required) {\n setInvalid(!e.target.value);\n }\n },\n style: {\n resize: 'none',\n wordBreak: 'break-all',\n },\n onKeyDownCapture: (e: React.KeyboardEvent) => {\n if (e.ctrlKey && e.keyCode === EKeyCode.Enter) {\n if (onNext) {\n onNext();\n }\n e.preventDefault();\n }\n\n if (e.keyCode === EKeyCode.Tab && tabToSwitchEnabled) {\n e.preventDefault();\n e.nativeEvent.stopImmediatePropagation();\n switchToNextTextarea(index);\n }\n\n e.nativeEvent.stopPropagation();\n },\n };\n\n const TextareaFooter = (\n <div className='textAreaFooter'>\n <div className='hotkeyTip'>\n {tabToSwitchEnabled && <span>{`[${t('Switch')}]Tab`}</span>}\n <span>{`[${t('TurnPage')}]Ctrl+Enter`}</span>\n </div>\n <div className='wordCount'>\n <span className={textLength >= maxLength ? 'warning' : ''}>{textLength}</span>/\n <span>{maxLength}</span>\n </div>\n </div>\n );\n\n useEffect(() => {\n if (disabled) {\n setTextAreaFocus(false);\n }\n }, [disabled]);\n\n return (\n <div className='textField'>\n <div className='label'>\n <span className={classnames({ required: config.required })}>{config.label}</span>\n <i\n className={classnames({ clearText: true, disabled: disabled })}\n onClick={() => {\n if (disabled) {\n return;\n }\n updateTextWithKey('');\n }}\n />\n </div>\n <div\n className={classnames({\n disabled,\n 'textarea-outline': true,\n 'ant-input-focused': textAreaFocus,\n textareaContainer: true,\n focus: textAreaFocus,\n invalid: invalid,\n })}\n >\n <TextareaWithFooter footer={TextareaFooter} textareaProps={textareaProps} />\n </div>\n </div>\n );\n};\n\nconst TextToolSidebar: React.FC<IProps> = ({\n toolInstance,\n imgIndex,\n dispatch,\n triggerEventAfterIndexChanged,\n step,\n stepList,\n basicResultList,\n}) => {\n const [configList, setConfigList] = useState<IConfigListItem[]>([]);\n const [focusIndex, setFocusIndex] = useState(0);\n const [, forceRender] = useState(0);\n\n const switchToNextTextarea = (currentIndex: number) => {\n const nextIndex = (currentIndex + 1) % configList.length;\n textareaFocus(nextIndex);\n };\n\n const textareaFocus = (index: number) => {\n if (!window) {\n return;\n }\n\n setTimeout(() => {\n const textarea = document.getElementById(`textInput-${index}`) as HTMLTextAreaElement;\n if (textarea) {\n setFocusIndex(index);\n textarea.focus();\n textarea.select();\n textarea.scrollIntoView({ behavior: 'smooth', block: 'center' });\n }\n });\n };\n\n useEffect(() => {\n if (toolInstance) {\n setConfigList(cloneDeep(toolInstance.config.configList));\n toolInstance.singleOn('valueUpdated', () => {\n forceRender((s) => s + 1);\n });\n }\n }, [toolInstance]);\n\n const updateText = (v: string, k: string) => {\n toolInstance.updateTextValue(k, v);\n };\n\n useEffect(() => {\n if (imgIndex > -1 && triggerEventAfterIndexChanged) {\n textareaFocus(0);\n }\n }, [imgIndex]);\n\n const result = toolInstance.textList[0]?.value ?? {};\n\n const onNext = () => {\n dispatch(PageForward(true));\n };\n\n const stepConfig = ConfigUtils.getStepConfig(stepList, step);\n const disabled = stepConfig.dataSourceStep > 0 && basicResultList.length === 0;\n\n return (\n <div className='textToolOperationMenu'>\n {configList.map((i, index) => (\n <SingleTextInput\n config={i}\n key={i.key}\n index={index}\n result={result}\n updateText={updateText}\n switchToNextTextarea={switchToNextTextarea}\n hasMultiple={configList.length > 1}\n focus={focusIndex === index}\n onNext={onNext}\n disabled={disabled}\n />\n ))}\n </div>\n );\n};\n\nfunction mapStateToProps(state: AppState) {\n return {\n toolInstance: state.annotation.toolInstance,\n imgIndex: state.annotation.imgIndex,\n step: state.annotation.step,\n basicResultList: state.annotation.basicResultList,\n stepList: state.annotation.stepList,\n triggerEventAfterIndexChanged: state.annotation.triggerEventAfterIndexChanged,\n };\n}\n\nexport default connect(mapStateToProps)(TextToolSidebar);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,WAAW,SAAS;AAE1B,MAAM,+BAA+B,CAAC,MAAgD;AACpF,IAAE;AACF,IAAE,YAAY;AACd,IAAE,YAAY;AAAA;MAQH,qBAAqB,CAAC,UAAoC;AACrE,QAAM,CAAE,eAAe,UAAW;AAElC,uGAEK,MAAM,UAAP;AAAA,IACE,UAAU;AAAA,IACV,MAAM;AAAA,IACN,WAAW;AAAA,IACX,SAAS;AAAA,KACL,qDAEL,OAAD;AAAA,IACE,WAAW,WAAW;AAAA,MACpB,gBAAgB;AAAA;AAAA,KAGjB;AAAA;MAwBI,kBAAkB,CAAC,UAAe;AAnE/C;AAoEE,QAAM,MAAM,OAAO;AACnB,QAAM,CAAC,eAAe,oBAAoB,SAAS;AACnD,QAAM,CAAC,SAAS,cAAc,SAAS;AACvC,Q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;AAAA;AAAA;AAK3D,YAAU,MAAM;AACd,QAAI,cAAc;AAChB,oBAAc,UAAU,aAAa,OAAO;AAC5C,mBAAa,SAAS,gBAAgB,MAAM;AAC1C,oBAAY,CAAC,MAAM,IAAI;AAAA;AAAA;AAAA,KAG1B,CAAC;AAEJ,QAAM,aAAa,CAAC,GAAW,MAAc;AAC3C,iBAAa,gBAAgB,GAAG;AAAA;AAGlC,YAAU,MAAM;AACd,QAAI,WAAW,MAAM,+BAA+B;AAClD,oBAAc;AAAA;AAAA,KAEf,CAAC;AAEJ,QAAM,SAAS,yBAAa,SAAS,OAAtB,mBAA0B,UAA1B,YAAmC;AAElD,QAAM,SAAS,MAAM;AACnB,aAAS,YAAY;AAAA;AAGvB,QAAM,aAAa,YAAY,cAAc,UAAU;AACvD,QAAM,WAAW,WAAW,iBAAiB,KAAK,gBAAgB,WAAW;AAE7E,6CACG,OAAD;AAAA,IAAK,WAAU;AAAA,KACZ,WAAW,IAAI,CAAC,GAAG,8CACjB,iBAAD;AAAA,IACE,QAAQ;AAAA,IACR,KAAK,EAAE;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,WAAW,SAAS;AAAA,IACjC,OAAO,eAAe;AAAA,IACtB;AAAA,IACA;AAAA;AAAA;AAOV,yBAAyB,OAAiB;AACxC,SAAO;AAAA,IACL,cAAc,MAAM,WAAW;AAAA,IAC/B,UAAU,MAAM,WAAW;AAAA,IAC3B,MAAM,MAAM,WAAW;AAAA,IACvB,iBAAiB,MAAM,WAAW;AAAA,IAClC,UAAU,MAAM,WAAW;AAAA,IAC3B,+BAA+B,MAAM,WAAW;AAAA;AAAA;AAIpD,wBAAe,QAAQ,iBAAiB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useReducer as T,useRef as j}from"react";import{LeftOutlined as
|
|
1
|
+
import e,{useReducer as T,useRef as j}from"react";import{LeftOutlined as b}from"@ant-design/icons";import{connect as w,useDispatch as y}from"react-redux";import{store as C}from"../../../index.js";import D from"classnames";import{prefix as n,ESubmitType as k}from"../../../constant/index.js";import O from"./ExportData/index.js";import z from"./headerOption/index.js";import{Tooltip as F,Button as H}from"antd/es";import{ToSubmitFileData as P,ToNextStep as R}from"../../../store/annotation/actionCreators.js";import A from"./StepSwitch/index.js";import{i18n as f}from"@labelbee/lb-utils";import{useTranslation as E}from"react-i18next";import B from"../../../hooks/useSize.js";const g=({disabled:t})=>{const{t:a}=E();return e.createElement(H,{type:"primary",style:{marginLeft:10},onClick:()=>{C.dispatch(R(0))},disabled:t},a("NextStep"))},I=({step:t,stepProgress:a,stepList:r})=>{const{t:s}=E();if(r.length<2||t===r.length)return null;const o=a<1;return o?e.createElement(F,{title:s("StepNotFinishedNotify")},e.createElement("span",null,e.createElement(g,{disabled:o}))):e.createElement(g,{disabled:o})},Q=({goBack:t,exportData:a,headerName:r,imgList:s,stepProgress:o,stepInfo:h,stepList:c,step:N,annotationEngine:x})=>{var l;const _=y(),[,S]=T(i=>i+1,0),m=j(null),p=B(m),v=e.createElement(O,{exportData:a}),$=()=>{_(P(k.Quit)),t&&t(s)},d=i=>{f.changeLanguage(i),x.setLang(i),S()},u=f.language,L=(l=p==null?void 0:p.width)!=null?l:window.innerWidth;return e.createElement("div",{className:D(`${n}-header`),ref:m},e.createElement("div",{className:`${n}-header__title`},e.createElement(b,{className:`${n}-header__icon`,onClick:$}),r?e.createElement("span",{className:`${n}-header__name`},r):"",c.length>1&&e.createElement(e.Fragment,null,e.createElement(A,{stepProgress:o}),e.createElement(I,{step:N,stepProgress:o,stepList:c})),v,e.createElement("div",{id:"operationNode",className:`${n}-header__operationNode`,style:{left:L/2-174/2}},e.createElement(z,{stepInfo:h})),e.createElement("div",{className:`${n}-header__titlePlacement`}),e.createElement("div",{className:`${n}-header__lang`},e.createElement("span",{className:`${n}-langCN ${u==="cn"?"active":""}`,onClick:()=>d("cn")},"\u4E2D\u6587")," / ",e.createElement("span",{className:`${n}-langEN ${u==="en"?"active":""}`,onClick:()=>d("en")},"En"))))},U=t=>{var a;return{imgList:t.annotation.imgList,annotationEngine:t.annotation.annotationEngine,stepProgress:t.annotation.stepProgress,toolName:(a=t.annotation.stepList[t.annotation.step-1])==null?void 0:a.tool,stepList:t.annotation.stepList,stepInfo:t.annotation.stepList[t.annotation.step-1],step:t.annotation.step}};var W=w(U)(Q);export{W as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/views/MainView/toolHeader/index.tsx"],"sourcesContent":["import React, { useReducer, useRef } from 'react';\nimport { LeftOutlined } from '@ant-design/icons';\nimport { connect, useDispatch } from 'react-redux';\nimport { store } from 'src';\nimport { IFileItem } from '@/types/data';\nimport { AppState } from '@/store';\nimport classNames from 'classnames';\nimport { ESubmitType, prefix } from '@/constant';\nimport ExportData from './ExportData';\nimport HeaderOption from './headerOption';\nimport { AnnotationEngine } from '@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/views/MainView/toolHeader/index.tsx"],"sourcesContent":["import React, { useReducer, useRef } from 'react';\nimport { LeftOutlined } from '@ant-design/icons';\nimport { connect, useDispatch } from 'react-redux';\nimport { store } from 'src';\nimport { IFileItem } from '@/types/data';\nimport { AppState } from '@/store';\nimport classNames from 'classnames';\nimport { ESubmitType, prefix } from '@/constant';\nimport ExportData from './ExportData';\nimport HeaderOption from './headerOption';\nimport { AnnotationEngine } from '@labelbee/lb-annotation';\nimport { Button, Tooltip } from 'antd/es';\nimport { ToNextStep, ToSubmitFileData } from '@/store/annotation/actionCreators';\nimport StepSwitch from './StepSwitch';\nimport { EToolName } from '@/data/enums/ToolType';\nimport { IStepInfo } from '@/types/step';\nimport { i18n } from '@labelbee/lb-utils';\nimport { useTranslation } from 'react-i18next';\nimport useSize from '@/hooks/useSize';\n\ninterface INextStep {\n stepProgress: number;\n stepList: IStepInfo[];\n step: number; // 当前步骤\n}\n\nconst NextButton: React.FC<{ disabled: boolean }> = ({ disabled }) => {\n const { t } = useTranslation();\n return (\n <Button\n type='primary'\n style={{\n marginLeft: 10,\n }}\n onClick={() => {\n store.dispatch(ToNextStep(0) as any);\n }}\n disabled={disabled}\n >\n {t('NextStep')}\n </Button>\n );\n};\n\nconst NextStep: React.FC<INextStep> = ({ step, stepProgress, stepList }) => {\n const { t } = useTranslation();\n\n if (stepList.length < 2 || step === stepList.length) {\n return null;\n }\n\n const disabled = stepProgress < 1;\n\n if (disabled) {\n return (\n <Tooltip title={t('StepNotFinishedNotify')}>\n <span>\n <NextButton disabled={disabled} />\n </span>\n </Tooltip>\n );\n }\n\n return <NextButton disabled={disabled} />;\n};\n\ninterface IToolHeaderProps {\n goBack?: (imgList?: IFileItem[]) => void;\n exportData?: (data: any[]) => void;\n headerName?: string;\n imgList: IFileItem[];\n annotationEngine: AnnotationEngine;\n stepProgress: number;\n toolName: EToolName;\n stepInfo: IStepInfo;\n stepList: IStepInfo[];\n step: number;\n}\n\nconst ToolHeader: React.FC<IToolHeaderProps> = ({\n goBack,\n exportData,\n headerName,\n imgList,\n stepProgress,\n stepInfo,\n stepList,\n step,\n annotationEngine,\n}) => {\n const dispatch = useDispatch();\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n const ref = useRef(null);\n\n const size = useSize(ref);\n\n // render 数据展示\n const currentOption = <ExportData exportData={exportData} />;\n\n const closeAnnotation = () => {\n dispatch(ToSubmitFileData(ESubmitType.Quit));\n\n if (goBack) {\n goBack(imgList);\n }\n };\n\n const changeLanguage = (lang: 'en' | 'cn') => {\n i18n.changeLanguage(lang);\n annotationEngine.setLang(lang);\n forceUpdate();\n };\n\n const curLang = i18n.language;\n\n const width = size?.width ?? window ? window?.innerWidth ?? 0 : 0;\n\n return (\n <div className={classNames(`${prefix}-header`)} ref={ref}>\n <div className={`${prefix}-header__title`}>\n <LeftOutlined className={`${prefix}-header__icon`} onClick={closeAnnotation} />\n {headerName ? <span className={`${prefix}-header__name`}>{headerName}</span> : ''}\n {stepList.length > 1 && (\n <>\n <StepSwitch stepProgress={stepProgress} />\n <NextStep step={step} stepProgress={stepProgress} stepList={stepList} />\n </>\n )}\n\n {currentOption}\n <div\n id='operationNode'\n className={`${prefix}-header__operationNode`}\n style={{ left: width / 2 - 174 / 2 }}\n >\n <HeaderOption stepInfo={stepInfo} />\n </div>\n\n <div className={`${prefix}-header__titlePlacement`} />\n\n <div className={`${prefix}-header__lang`}>\n <span\n className={`${prefix}-langCN ${curLang === 'cn' ? 'active' : ''}`}\n onClick={() => changeLanguage('cn')}\n >\n 中文\n </span>\n {` / `}\n <span\n className={`${prefix}-langEN ${curLang === 'en' ? 'active' : ''}`}\n onClick={() => changeLanguage('en')}\n >\n En\n </span>\n </div>\n </div>\n </div>\n );\n};\n\nconst mapStateToProps = (state: AppState) => ({\n imgList: state.annotation.imgList,\n annotationEngine: state.annotation.annotationEngine,\n stepProgress: state.annotation.stepProgress,\n toolName: state.annotation.stepList[state.annotation.step - 1]?.tool,\n stepList: state.annotation.stepList,\n stepInfo: state.annotation.stepList[state.annotation.step - 1],\n step: state.annotation.step,\n});\n\nexport default connect(mapStateToProps)(ToolHeader);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,aAA8C,CAAC,CAAE,cAAe;AACpE,QAAM,CAAE,KAAM;AACd,6CACG,QAAD;AAAA,IACE,MAAK;AAAA,IACL,OAAO;AAAA,MACL,YAAY;AAAA;AAAA,IAEd,SAAS,MAAM;AACb,YAAM,SAAS,WAAW;AAAA;AAAA,IAE5B;AAAA,KAEC,EAAE;AAAA;AAKT,MAAM,WAAgC,CAAC,CAAE,MAAM,cAAc,cAAe;AAC1E,QAAM,CAAE,KAAM;AAEd,MAAI,SAAS,SAAS,KAAK,SAAS,SAAS,QAAQ;AACnD,WAAO;AAAA;AAGT,QAAM,WAAW,eAAe;AAEhC,MAAI,UAAU;AACZ,+CACG,SAAD;AAAA,MAAS,OAAO,EAAE;AAAA,2CACf,QAAD,0CACG,YAAD;AAAA,MAAY;AAAA;AAAA;AAMpB,6C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E,WAAW,GAAG,iBAAiB,YAAY,OAAO,WAAW;AAAA,IAC7D,SAAS,MAAM,eAAe;AAAA,KAC/B,iBAGA,2CACA,QAAD;AAAA,IACE,WAAW,GAAG,iBAAiB,YAAY,OAAO,WAAW;AAAA,IAC7D,SAAS,MAAM,eAAe;AAAA,KAC/B;AAAA;AASX,MAAM,kBAAkB,CAAC,UAAiB;AAhK1C;AAgK8C;AAAA,IAC5C,SAAS,MAAM,WAAW;AAAA,IAC1B,kBAAkB,MAAM,WAAW;AAAA,IACnC,cAAc,MAAM,WAAW;AAAA,IAC/B,UAAU,YAAM,WAAW,SAAS,MAAM,WAAW,OAAO,OAAlD,mBAAsD;AAAA,IAChE,UAAU,MAAM,WAAW;AAAA,IAC3B,UAAU,MAAM,WAAW,SAAS,MAAM,WAAW,OAAO;AAAA,IAC5D,MAAM,MAAM,WAAW;AAAA;AAAA;AAGzB,mBAAe,QAAQ,iBAAiB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2-alpha.123",
|
|
4
4
|
"description": "Provide a complete library of annotation components",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"es": "./es/index.js",
|
|
@@ -42,17 +42,18 @@
|
|
|
42
42
|
"email": "brady_luo.sz@foxmail.com"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@labelbee/lb-annotation": "1.5.2",
|
|
46
45
|
"@ant-design/icons": "^4.6.2",
|
|
47
|
-
"
|
|
46
|
+
"@labelbee/lb-annotation": "1.5.3",
|
|
48
47
|
"@labelbee/lb-utils": "^1.0.3",
|
|
48
|
+
"classnames": "^2.3.0",
|
|
49
49
|
"lodash": "^4.17.21",
|
|
50
50
|
"react-i18next": "^11.12.0",
|
|
51
51
|
"react-redux": "^7.2.3",
|
|
52
52
|
"redux": "^4.0.5",
|
|
53
53
|
"redux-actions": "^2.6.5",
|
|
54
54
|
"redux-thunk": "^2.3.0",
|
|
55
|
-
"resize-observer-polyfill": "^1.5.1"
|
|
55
|
+
"resize-observer-polyfill": "^1.5.1",
|
|
56
|
+
"ssr-window": "^4.0.2"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
59
|
"react": ">=16.9.0",
|