@searpent/react-image-annotate 2.0.2 → 2.0.5

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.
Files changed (186) hide show
  1. package/.babelrc +6 -0
  2. package/.env +1 -0
  3. package/.flowconfig +2 -0
  4. package/.github/workflows/release-on-master.yml +32 -0
  5. package/.github/workflows/test.yml +16 -0
  6. package/.prettierrc +3 -0
  7. package/.releaserc.js +18 -0
  8. package/.storybook/addons.js +2 -0
  9. package/.storybook/config.js +16 -0
  10. package/LICENSE +21 -0
  11. package/package.json +4 -1
  12. package/public/favicon.ico +0 -0
  13. package/public/index.html +38 -0
  14. package/src/Annotator/bike-pic.png +0 -0
  15. package/src/Annotator/bike-pic2.png +0 -0
  16. package/src/Annotator/dab-keyframes.story.json +1 -0
  17. package/src/Annotator/examplePhotos.js +7601 -0
  18. package/src/Annotator/index.js +291 -0
  19. package/src/Annotator/index.story.js +807 -0
  20. package/src/Annotator/poses.story.js +150 -0
  21. package/src/Annotator/reducers/combine-reducers.js +7 -0
  22. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +53 -0
  23. package/{Annotator → src/Annotator}/reducers/fix-twisted.js +5 -3
  24. package/src/Annotator/reducers/general-reducer.js +996 -0
  25. package/src/Annotator/reducers/get-active-image.js +21 -0
  26. package/src/Annotator/reducers/get-implied-video-regions.js +115 -0
  27. package/src/Annotator/reducers/history-handler.js +60 -0
  28. package/src/Annotator/reducers/image-reducer.js +23 -0
  29. package/src/Annotator/reducers/video-reducer.js +85 -0
  30. package/src/Annotator/video.story.js +51 -0
  31. package/src/ClassSelectionMenu/index.js +108 -0
  32. package/src/Crosshairs/index.js +64 -0
  33. package/src/DebugSidebarBox/index.js +36 -0
  34. package/src/DemoSite/Editor.js +235 -0
  35. package/src/DemoSite/ErrorBoundaryDialog.js +34 -0
  36. package/src/DemoSite/index.js +41 -0
  37. package/src/DemoSite/index.story.js +10 -0
  38. package/src/DemoSite/simple-segmentation-example.json +572 -0
  39. package/src/Editor/annotation-plugin/annotation.css +46 -0
  40. package/src/Editor/annotation-plugin/annotation.js +515 -0
  41. package/src/Editor/index.js +24 -0
  42. package/src/Editor/tools.js +6 -0
  43. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  44. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  45. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  46. package/src/FullImageSegmentationAnnotator/index.js +7 -0
  47. package/src/FullImageSegmentationAnnotator/index.story.js +177 -0
  48. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  49. package/src/GroupSelectorSidebarBox/index.js +48 -0
  50. package/src/HighlightBox/index.js +143 -0
  51. package/src/HistorySidebarBox/index.js +78 -0
  52. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  53. package/src/ImageCanvas/index.js +494 -0
  54. package/src/ImageCanvas/index.story.js +314 -0
  55. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  56. package/src/ImageCanvas/region-tools.js +171 -0
  57. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  58. package/{ImageCanvas → src/ImageCanvas}/styles.js +8 -12
  59. package/src/ImageCanvas/use-mouse.js +168 -0
  60. package/src/ImageCanvas/use-project-box.js +23 -0
  61. package/src/ImageCanvas/use-wasd-mode.js +50 -0
  62. package/src/ImageMask/index.js +127 -0
  63. package/src/ImageMask/load-image.js +32 -0
  64. package/src/ImageSelectorSidebarBox/index.js +54 -0
  65. package/src/KeyframeTimeline/get-time-string.js +25 -0
  66. package/src/KeyframeTimeline/index.js +223 -0
  67. package/src/KeyframesSelectorSidebarBox/index.js +93 -0
  68. package/src/LandingPage/content.md +57 -0
  69. package/src/LandingPage/github-markdown.css +964 -0
  70. package/src/LandingPage/index.js +147 -0
  71. package/src/MainLayout/icon-dictionary.js +79 -0
  72. package/src/MainLayout/index.js +510 -0
  73. package/src/MainLayout/index.story.js +240 -0
  74. package/{MainLayout → src/MainLayout}/styles.js +7 -6
  75. package/src/MainLayout/types.js +164 -0
  76. package/src/MainLayout/use-implied-video-regions.js +17 -0
  77. package/src/MetadataEditorSidebarBox/index.js +98 -0
  78. package/src/PageSelector/index.js +76 -0
  79. package/src/PageSelector/page-selector.css +69 -0
  80. package/src/PointDistances/index.js +90 -0
  81. package/src/PreventScrollToParents/index.js +48 -0
  82. package/src/PreventScrollToParents/index.story.js +23 -0
  83. package/src/RegionLabel/index.js +222 -0
  84. package/{RegionLabel → src/RegionLabel}/styles.js +15 -12
  85. package/src/RegionSelectAndTransformBoxes/index.js +234 -0
  86. package/src/RegionSelectorSidebarBox/index.js +216 -0
  87. package/{RegionSelectorSidebarBox → src/RegionSelectorSidebarBox}/styles.js +14 -13
  88. package/src/RegionShapes/index.js +254 -0
  89. package/src/RegionTags/index.js +134 -0
  90. package/src/SettingsDialog/index.js +58 -0
  91. package/src/SettingsProvider/index.js +48 -0
  92. package/src/Shortcuts/ShortcutField.js +44 -0
  93. package/src/Shortcuts/index.js +129 -0
  94. package/src/ShortcutsManager/index.js +162 -0
  95. package/src/Sidebar/index.js +117 -0
  96. package/src/SidebarBoxContainer/index.js +93 -0
  97. package/src/SmallToolButton/index.js +57 -0
  98. package/src/TagsSidebarBox/index.js +93 -0
  99. package/src/TaskDescriptionSidebarBox/index.js +43 -0
  100. package/src/Theme/index.js +36 -0
  101. package/src/VideoOrImageCanvasBackground/index.js +170 -0
  102. package/src/colors.js +32 -0
  103. package/src/hooks/use-colors.js +74 -0
  104. package/src/hooks/use-event-callback.js +11 -0
  105. package/src/hooks/use-exclude-pattern.js +27 -0
  106. package/src/hooks/use-load-image.js +21 -0
  107. package/src/hooks/use-window-size.js +46 -0
  108. package/{hooks → src/hooks}/xpattern.js +1 -1
  109. package/src/hooks/xpattern.png +0 -0
  110. package/src/index.js +18 -0
  111. package/src/lib.js +7 -0
  112. package/src/screenshot.png +0 -0
  113. package/src/site.css +5 -0
  114. package/src/stories.js +2 -0
  115. package/src/utils/filter-only-unique.js +5 -0
  116. package/src/utils/get-from-local-storage.js +7 -0
  117. package/src/utils/get-hotkey-help-text.js +11 -0
  118. package/src/utils/get-landmarks-with-transform.js +23 -0
  119. package/src/utils/photosToImages.js +40 -0
  120. package/src/utils/regions-to-blocks.js +14 -0
  121. package/src/utils/set-in-local-storage.js +6 -0
  122. package/Annotator/index.js +0 -161
  123. package/Annotator/reducers/combine-reducers.js +0 -14
  124. package/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -73
  125. package/Annotator/reducers/general-reducer.js +0 -1058
  126. package/Annotator/reducers/get-active-image.js +0 -27
  127. package/Annotator/reducers/get-implied-video-regions.js +0 -180
  128. package/Annotator/reducers/history-handler.js +0 -38
  129. package/Annotator/reducers/image-reducer.js +0 -20
  130. package/Annotator/reducers/video-reducer.js +0 -88
  131. package/ClassSelectionMenu/index.js +0 -135
  132. package/Crosshairs/index.js +0 -53
  133. package/DebugSidebarBox/index.js +0 -20
  134. package/DemoSite/Editor.js +0 -194
  135. package/DemoSite/ErrorBoundaryDialog.js +0 -64
  136. package/DemoSite/index.js +0 -40
  137. package/FullImageSegmentationAnnotator/index.js +0 -7
  138. package/HighlightBox/index.js +0 -99
  139. package/HistorySidebarBox/index.js +0 -71
  140. package/ImageCanvas/index.js +0 -424
  141. package/ImageCanvas/region-tools.js +0 -165
  142. package/ImageCanvas/use-mouse.js +0 -180
  143. package/ImageCanvas/use-project-box.js +0 -27
  144. package/ImageCanvas/use-wasd-mode.js +0 -62
  145. package/ImageMask/index.js +0 -133
  146. package/ImageMask/load-image.js +0 -25
  147. package/ImageSelectorSidebarBox/index.js +0 -60
  148. package/KeyframeTimeline/get-time-string.js +0 -27
  149. package/KeyframeTimeline/index.js +0 -233
  150. package/KeyframesSelectorSidebarBox/index.js +0 -93
  151. package/LandingPage/index.js +0 -159
  152. package/MainLayout/icon-dictionary.js +0 -104
  153. package/MainLayout/index.js +0 -352
  154. package/MainLayout/types.js +0 -0
  155. package/MainLayout/use-implied-video-regions.js +0 -13
  156. package/PointDistances/index.js +0 -73
  157. package/PreventScrollToParents/index.js +0 -51
  158. package/RegionLabel/index.js +0 -191
  159. package/RegionSelectAndTransformBoxes/index.js +0 -167
  160. package/RegionSelectorSidebarBox/index.js +0 -248
  161. package/RegionShapes/index.js +0 -274
  162. package/RegionTags/index.js +0 -138
  163. package/SettingsDialog/index.js +0 -52
  164. package/SettingsProvider/index.js +0 -53
  165. package/Shortcuts/ShortcutField.js +0 -46
  166. package/Shortcuts/index.js +0 -133
  167. package/ShortcutsManager/index.js +0 -155
  168. package/Sidebar/index.js +0 -69
  169. package/SidebarBoxContainer/index.js +0 -93
  170. package/SmallToolButton/index.js +0 -42
  171. package/TagsSidebarBox/index.js +0 -105
  172. package/TaskDescriptionSidebarBox/index.js +0 -58
  173. package/Theme/index.js +0 -30
  174. package/VideoOrImageCanvasBackground/index.js +0 -151
  175. package/colors.js +0 -14
  176. package/hooks/use-event-callback.js +0 -10
  177. package/hooks/use-exclude-pattern.js +0 -24
  178. package/hooks/use-load-image.js +0 -26
  179. package/hooks/use-window-size.js +0 -46
  180. package/index.js +0 -3
  181. package/lib.js +0 -3
  182. package/stories.js +0 -5
  183. package/utils/get-from-local-storage.js +0 -7
  184. package/utils/get-hotkey-help-text.js +0 -9
  185. package/utils/get-landmarks-with-transform.js +0 -40
  186. package/utils/set-in-local-storage.js +0 -3
@@ -0,0 +1,510 @@
1
+ // @flow
2
+
3
+ import type { Action, MainLayoutState } from "./types"
4
+ import { FullScreen, useFullScreenHandle } from "react-full-screen"
5
+ import React, { useCallback, useRef } from "react"
6
+ import { makeStyles } from "@mui/styles"
7
+ import { createTheme, ThemeProvider } from "@mui/material/styles"
8
+ import { styled } from "@mui/material/styles"
9
+ import ClassSelectionMenu from "../ClassSelectionMenu"
10
+ import DebugBox from "../DebugSidebarBox"
11
+ import HistorySidebarBox from "../HistorySidebarBox"
12
+ import ImageCanvas from "../ImageCanvas"
13
+ import ImageSelector from "../ImageSelectorSidebarBox"
14
+ import GroupSelector from "../GroupSelectorSidebarBox"
15
+ import KeyframeTimeline from "../KeyframeTimeline"
16
+ import KeyframesSelector from "../KeyframesSelectorSidebarBox"
17
+ import type { Node } from "react"
18
+ import RegionSelector from "../RegionSelectorSidebarBox"
19
+ import SettingsDialog from "../SettingsDialog"
20
+ import TagsSidebarBox from "../TagsSidebarBox"
21
+ import TaskDescription from "../TaskDescriptionSidebarBox"
22
+ import MetadataEditor from "../MetadataEditorSidebarBox"
23
+ import Workspace from "react-material-workspace-layout/Workspace"
24
+ import classnames from "classnames"
25
+ import getActiveImage from "../Annotator/reducers/get-active-image"
26
+ import getHotkeyHelpText from "../utils/get-hotkey-help-text"
27
+ import iconDictionary from "./icon-dictionary"
28
+ import styles from "./styles"
29
+ import { useDispatchHotkeyHandlers } from "../ShortcutsManager"
30
+ import useEventCallback from "use-event-callback"
31
+ import useImpliedVideoRegions from "./use-implied-video-regions"
32
+ import useKey from "use-key-hook"
33
+ import { useSettings } from "../SettingsProvider"
34
+ import { withHotKeys } from "react-hotkeys"
35
+ import Editor from "../Editor"
36
+ import regionsToBlocks from '../utils/regions-to-blocks';
37
+ import PagesSelector from "../PageSelector"
38
+
39
+ // import Fullscreen from "../Fullscreen"
40
+
41
+ const emptyArr = []
42
+ const theme = createTheme()
43
+ const useStyles = makeStyles((theme) => styles)
44
+
45
+ const HotkeyDiv = withHotKeys(({ hotKeys, children, divRef, ...props }) => (
46
+ <div {...{ ...hotKeys, ...props }} ref={divRef}>
47
+ {children}
48
+ </div>
49
+ ))
50
+
51
+ const FullScreenContainer = styled("div")(({ theme }) => ({
52
+ width: "100%",
53
+ height: "100%",
54
+ "& .fullscreen": {
55
+ width: "100%",
56
+ height: "100%",
57
+ },
58
+ }))
59
+
60
+ const EditorWrapper = styled("div")(({ theme }) => ({
61
+ width: "45%",
62
+ padding: "1rem",
63
+ paddingLeft: "2rem"
64
+ }))
65
+
66
+ type Props = {
67
+ state: MainLayoutState,
68
+ RegionEditLabel?: Node,
69
+ dispatch: (Action) => any,
70
+ alwaysShowNextButton?: boolean,
71
+ alwaysShowPrevButton?: boolean,
72
+ onRegionClassAdded: () => {},
73
+ hideHeader?: boolean,
74
+ hideHeaderText?: boolean,
75
+ groups?: Array<any>,
76
+ onGroupSelect?: (any) => any,
77
+ hideHistory?: boolean,
78
+ hideNotEditingLabel?: boolean,
79
+ showEditor?: boolean,
80
+ showPageSelector?: boolean,
81
+ onRecalc?: (any) => any,
82
+ onSave?: (any) => any,
83
+ recalcActive?: boolean,
84
+ saveActive?: boolean,
85
+ allowedGroups?: boolean,
86
+ onMetadataChange: (any) => any
87
+ }
88
+
89
+ export const MainLayout = ({
90
+ state,
91
+ dispatch,
92
+ alwaysShowNextButton = false,
93
+ alwaysShowPrevButton = false,
94
+ RegionEditLabel,
95
+ onRegionClassAdded,
96
+ hideHeader,
97
+ hideHeaderText,
98
+ hideNext = false,
99
+ hidePrev = false,
100
+ hideClone = false,
101
+ hideSettings = false,
102
+ hideFullScreen = false,
103
+ hideSave = false,
104
+ groups = [],
105
+ onGroupSelect = () => { },
106
+ hideHistory = false,
107
+ hideNotEditingLabel = false,
108
+ showEditor = false,
109
+ showPageSelector = false,
110
+ onRecalc = () => { },
111
+ onSave = () => { },
112
+ recalcActive = false,
113
+ saveActive = false,
114
+ allowedGroups = {},
115
+ onMetadataChange
116
+ }: Props) => {
117
+ const classes = useStyles()
118
+ const settings = useSettings()
119
+ const fullScreenHandle = useFullScreenHandle()
120
+
121
+ const memoizedActionFns = useRef({})
122
+ const action = (type: string, ...params: Array<string>) => {
123
+ const fnKey = `${type}(${params.join(",")})`
124
+ if (memoizedActionFns.current[fnKey])
125
+ return memoizedActionFns.current[fnKey]
126
+
127
+ const fn = (...args: any) =>
128
+ params.length > 0
129
+ ? dispatch(
130
+ ({
131
+ type,
132
+ ...params.reduce((acc, p, i) => ((acc[p] = args[i]), acc), {}),
133
+ }: any)
134
+ )
135
+ : dispatch({ type, ...args[0] })
136
+ memoizedActionFns.current[fnKey] = fn
137
+ return fn
138
+ }
139
+
140
+ const { currentImageIndex, activeImage } = getActiveImage(state)
141
+ let nextImage
142
+ if (currentImageIndex !== null) {
143
+ nextImage = state.images[currentImageIndex + 1]
144
+ }
145
+
146
+ useKey(() => dispatch({ type: "CANCEL" }), {
147
+ detectKeys: [27],
148
+ })
149
+
150
+ const isAVideoFrame = activeImage && activeImage.frameTime !== undefined
151
+ const innerContainerRef = useRef()
152
+ const hotkeyHandlers = useDispatchHotkeyHandlers({ dispatch })
153
+
154
+ let impliedVideoRegions = useImpliedVideoRegions(state)
155
+
156
+ const refocusOnMouseEvent = useCallback((e) => {
157
+ if (!innerContainerRef.current) return
158
+ if (innerContainerRef.current.contains(document.activeElement)) return
159
+ if (innerContainerRef.current.contains(e.target)) {
160
+ innerContainerRef.current.focus()
161
+ e.target.focus()
162
+ }
163
+ }, [])
164
+
165
+ const canvas = (
166
+ <ImageCanvas
167
+ {...settings}
168
+ showCrosshairs={
169
+ settings.showCrosshairs &&
170
+ !["select", "pan", "zoom"].includes(state.selectedTool)
171
+ }
172
+ key={state.selectedImage}
173
+ showMask={state.showMask}
174
+ fullImageSegmentationMode={state.fullImageSegmentationMode}
175
+ autoSegmentationOptions={state.autoSegmentationOptions}
176
+ showTags={state.showTags}
177
+ allowedArea={state.allowedArea}
178
+ modifyingAllowedArea={state.selectedTool === "modify-allowed-area"}
179
+ regionClsList={state.regionClsList}
180
+ regionTagList={state.regionTagList}
181
+ regions={
182
+ state.annotationType === "image"
183
+ ? activeImage.regions || []
184
+ : impliedVideoRegions
185
+ }
186
+ realSize={activeImage ? activeImage.realSize : undefined}
187
+ videoPlaying={state.videoPlaying}
188
+ imageSrc={state.annotationType === "image" ? activeImage.src : null}
189
+ videoSrc={state.annotationType === "video" ? state.videoSrc : null}
190
+ pointDistancePrecision={state.pointDistancePrecision}
191
+ createWithPrimary={state.selectedTool.includes("create")}
192
+ dragWithPrimary={state.selectedTool === "pan"}
193
+ zoomWithPrimary={state.selectedTool === "zoom"}
194
+ showPointDistances={state.showPointDistances}
195
+ videoTime={
196
+ state.annotationType === "image"
197
+ ? state.selectedImageFrameTime
198
+ : state.currentVideoTime
199
+ }
200
+ keypointDefinitions={state.keypointDefinitions}
201
+ onMouseMove={action("MOUSE_MOVE")}
202
+ onMouseDown={action("MOUSE_DOWN")}
203
+ onMouseUp={action("MOUSE_UP")}
204
+ onChangeRegion={action("CHANGE_REGION", "region")}
205
+ onBeginRegionEdit={action("OPEN_REGION_EDITOR", "region")}
206
+ onCloseRegionEdit={action("CLOSE_REGION_EDITOR", "region")}
207
+ onDeleteRegion={action("DELETE_REGION", "region")}
208
+ onBeginBoxTransform={action("BEGIN_BOX_TRANSFORM", "box", "directions")}
209
+ onBeginMovePolygonPoint={action(
210
+ "BEGIN_MOVE_POLYGON_POINT",
211
+ "polygon",
212
+ "pointIndex"
213
+ )}
214
+ onBeginMoveKeypoint={action(
215
+ "BEGIN_MOVE_KEYPOINT",
216
+ "region",
217
+ "keypointId"
218
+ )}
219
+ onAddPolygonPoint={action(
220
+ "ADD_POLYGON_POINT",
221
+ "polygon",
222
+ "point",
223
+ "pointIndex"
224
+ )}
225
+ onSelectRegion={action("SELECT_REGION", "region")}
226
+ onBeginMovePoint={action("BEGIN_MOVE_POINT", "point")}
227
+ onImageLoaded={action("IMAGE_LOADED", "image")}
228
+ RegionEditLabel={RegionEditLabel}
229
+ onImageOrVideoLoaded={action("IMAGE_OR_VIDEO_LOADED", "metadata")}
230
+ onChangeVideoTime={action("CHANGE_VIDEO_TIME", "newTime")}
231
+ onChangeVideoPlaying={action("CHANGE_VIDEO_PLAYING", "isPlaying")}
232
+ onRegionClassAdded={onRegionClassAdded}
233
+ allowComments={state.allowComments}
234
+ hideNotEditingLabel={hideNotEditingLabel}
235
+ allowedGroups={allowedGroups}
236
+ />
237
+ )
238
+
239
+ const onClickIconSidebarItem = useEventCallback((item) => {
240
+ dispatch({ type: "SELECT_TOOL", selectedTool: item.name })
241
+ })
242
+
243
+ const onClickHeaderItem = useEventCallback((item) => {
244
+ if (item.name === "Fullscreen") {
245
+ fullScreenHandle.enter()
246
+ } else if (item.name === "Window") {
247
+ fullScreenHandle.exit()
248
+ }
249
+ dispatch({ type: "HEADER_BUTTON_CLICKED", buttonName: item.name })
250
+ })
251
+
252
+ const debugModeOn = Boolean(window.localStorage.$ANNOTATE_DEBUG_MODE && state)
253
+ const nextImageHasRegions =
254
+ !nextImage || (nextImage.regions && nextImage.regions.length > 0)
255
+
256
+ // Editor.js blocks
257
+ const selectedGroupId = state.images[state.selectedImage]?.selectedGroupId || null;
258
+ const editorBlocks = regionsToBlocks(state.images[state.selectedImage]?.regions || []);
259
+ const blocks = editorBlocks.filter(i => i?.data?.groupId === selectedGroupId);
260
+
261
+ const handleEditorChange = ({ imageIndex, data }) => {
262
+ const newRegions = data.blocks.map(i => ({
263
+ id: i.id,
264
+ cls: i.data.labelName,
265
+ text: i.data.text
266
+ }))
267
+ dispatch({ type: "UPDATE_REGIONS", regions: newRegions, imageIndex })
268
+ }
269
+
270
+ const pages = state.images.map((i, idx) => ({
271
+ id: idx,
272
+ src: i.src,
273
+ isActive: idx === state.selectedImage,
274
+ pageNumber: i?.metadata?.find(md => md.key === "page").value || null
275
+ }))
276
+
277
+ const handlePageClick = (pageIndex) => {
278
+ dispatch({ type: "SELECT_IMAGE", imageIndex: pageIndex })
279
+ }
280
+
281
+ return (
282
+ <ThemeProvider theme={theme}>
283
+ <FullScreenContainer>
284
+ <FullScreen
285
+ handle={fullScreenHandle}
286
+ onChange={(open) => {
287
+ if (!open) {
288
+ fullScreenHandle.exit()
289
+ action("HEADER_BUTTON_CLICKED", "buttonName")("Window")
290
+ }
291
+ }}
292
+ >
293
+ <HotkeyDiv
294
+ tabIndex={-1}
295
+ divRef={innerContainerRef}
296
+ onMouseDown={refocusOnMouseEvent}
297
+ onMouseOver={refocusOnMouseEvent}
298
+ allowChanges
299
+ handlers={hotkeyHandlers}
300
+ className={classnames(
301
+ classes.container,
302
+ state.fullScreen && "Fullscreen"
303
+ )}
304
+ >
305
+ <div style={{
306
+ display: 'flex',
307
+ flexDirection: 'row'
308
+ }}>
309
+ {
310
+ showPageSelector && (
311
+ <PagesSelector pages={pages} onPageClick={handlePageClick} onRecalc={onRecalc} onSave={onSave} saveActive={saveActive} recalcActive={recalcActive} />
312
+ )
313
+ }
314
+ <Workspace
315
+ allowFullscreen
316
+ iconDictionary={iconDictionary}
317
+ hideHeader={hideHeader}
318
+ hideHeaderText={hideHeaderText}
319
+ headerLeftSide={[
320
+ state.annotationType === "video" ? (
321
+ <KeyframeTimeline
322
+ currentTime={state.currentVideoTime}
323
+ duration={state.videoDuration}
324
+ onChangeCurrentTime={action("CHANGE_VIDEO_TIME", "newTime")}
325
+ keyframes={state.keyframes}
326
+ />
327
+ ) : activeImage ? (
328
+ <div className={classes.headerTitle}>{activeImage.name}</div>
329
+ ) : null,
330
+ ].filter(Boolean)}
331
+ headerItems={[
332
+ !hidePrev && { name: "Prev" },
333
+ !hideNext && { name: "Next" },
334
+ state.annotationType !== "video"
335
+ ? null
336
+ : !state.videoPlaying
337
+ ? { name: "Play" }
338
+ : { name: "Pause" },
339
+ !hideClone &&
340
+ !nextImageHasRegions &&
341
+ activeImage.regions && { name: "Clone" },
342
+ !hideSettings && { name: "Settings" },
343
+ !hideFullScreen &&
344
+ (state.fullScreen
345
+ ? { name: "Window" }
346
+ : { name: "Fullscreen" }),
347
+ !hideSave && { name: "Save" },
348
+ ].filter(Boolean)}
349
+ onClickHeaderItem={onClickHeaderItem}
350
+ onClickIconSidebarItem={onClickIconSidebarItem}
351
+ selectedTools={[
352
+ state.selectedTool,
353
+ state.showTags && "show-tags",
354
+ state.showMask && "show-mask",
355
+ ].filter(Boolean)}
356
+ iconSidebarItems={[
357
+ {
358
+ name: "select",
359
+ helperText: "Select" + getHotkeyHelpText("select_tool"),
360
+ alwaysShowing: true,
361
+ },
362
+ {
363
+ name: "pan",
364
+ helperText:
365
+ "Drag/Pan (right or middle click)" +
366
+ getHotkeyHelpText("pan_tool"),
367
+ alwaysShowing: true,
368
+ },
369
+ {
370
+ name: "zoom",
371
+ helperText:
372
+ "Zoom In/Out (scroll)" + getHotkeyHelpText("zoom_tool"),
373
+ alwaysShowing: true,
374
+ },
375
+ {
376
+ name: "show-tags",
377
+ helperText: "Show / Hide Tags",
378
+ alwaysShowing: true,
379
+ },
380
+ {
381
+ name: "create-point",
382
+ helperText: "Add Point" + getHotkeyHelpText("create_point"),
383
+ },
384
+ {
385
+ name: "create-box",
386
+ helperText:
387
+ "Add Bounding Box" +
388
+ getHotkeyHelpText("create_bounding_box"),
389
+ },
390
+ {
391
+ name: "create-polygon",
392
+ helperText:
393
+ "Add Polygon" + getHotkeyHelpText("create_polygon"),
394
+ },
395
+ {
396
+ name: "create-line",
397
+ helperText: "Add Line",
398
+ },
399
+ {
400
+ name: "create-expanding-line",
401
+ helperText: "Add Expanding Line",
402
+ },
403
+ {
404
+ name: "create-keypoints",
405
+ helperText: "Add Keypoints (Pose)",
406
+ },
407
+ state.fullImageSegmentationMode && {
408
+ name: "show-mask",
409
+ alwaysShowing: true,
410
+ helperText: "Show / Hide Mask",
411
+ },
412
+ {
413
+ name: "modify-allowed-area",
414
+ helperText: "Modify Allowed Area",
415
+ },
416
+ ]
417
+ .filter(Boolean)
418
+ .filter(
419
+ (a) => a.alwaysShowing || state.enabledTools.includes(a.name)
420
+ )}
421
+ rightSidebarItems={[
422
+ debugModeOn && (
423
+ <DebugBox state={debugModeOn} lastAction={state.lastAction} />
424
+ ),
425
+ state.taskDescription && (
426
+ <TaskDescription description={state.taskDescription} />
427
+ ),
428
+ state.regionClsList && (
429
+ <ClassSelectionMenu
430
+ selectedCls={state.selectedCls}
431
+ regionClsList={state.regionClsList}
432
+ onSelectCls={action("SELECT_CLASSIFICATION", "cls")}
433
+ />
434
+ ),
435
+ state.labelImages && (
436
+ <TagsSidebarBox
437
+ currentImage={activeImage}
438
+ imageClsList={state.imageClsList}
439
+ imageTagList={state.imageTagList}
440
+ onChangeImage={action("CHANGE_IMAGE", "delta")}
441
+ expandedByDefault
442
+ />
443
+ ),
444
+ // (state.images?.length || 0) > 1 && (
445
+ // <ImageSelector
446
+ // onSelect={action("SELECT_REGION", "region")}
447
+ // images={state.images}
448
+ // />
449
+ // ),
450
+ // groups && (
451
+ // <GroupSelector
452
+ // title="Articles"
453
+ // groups={groups}
454
+ // selectedGroupId={selectedGroupId}
455
+ // onSelect={onGroupSelect}
456
+ // />
457
+ // )
458
+ ,
459
+ <RegionSelector
460
+ regions={activeImage ? activeImage.regions : emptyArr}
461
+ onSelectRegion={action("SELECT_REGION", "region")}
462
+ onDeleteRegion={action("DELETE_REGION", "region")}
463
+ onChangeRegion={action("CHANGE_REGION", "region")}
464
+ />,
465
+ state.keyframes && (
466
+ <KeyframesSelector
467
+ onChangeVideoTime={action("CHANGE_VIDEO_TIME", "newTime")}
468
+ onDeleteKeyframe={action("DELETE_KEYFRAME", "time")}
469
+ onChangeCurrentTime={action("CHANGE_VIDEO_TIME", "newTime")}
470
+ currentTime={state.currentVideoTime}
471
+ duration={state.videoDuration}
472
+ keyframes={state.keyframes}
473
+ />
474
+ ),
475
+ !hideHistory && (
476
+ <HistorySidebarBox
477
+ history={state.history}
478
+ onRestoreHistory={action("RESTORE_HISTORY")}
479
+ />
480
+ ),
481
+ <MetadataEditor state={state} onMetadataChange={onMetadataChange} />
482
+ ].filter(Boolean)}
483
+ >
484
+ {canvas}
485
+ </Workspace>
486
+ {
487
+ (showEditor) && (
488
+ <EditorWrapper id="editor-wrapper">
489
+ <Editor id="editor" blocks={blocks} imageIndex={state.selectedImage} key={`${state.selectedImage}#${selectedGroupId}`} onChange={handleEditorChange} />
490
+ </EditorWrapper>
491
+ )
492
+ }
493
+ </div>
494
+ <SettingsDialog
495
+ open={state.settingsOpen}
496
+ onClose={() =>
497
+ dispatch({
498
+ type: "HEADER_BUTTON_CLICKED",
499
+ buttonName: "Settings",
500
+ })
501
+ }
502
+ />
503
+ </HotkeyDiv>
504
+ </FullScreen>
505
+ </FullScreenContainer>
506
+ </ThemeProvider >
507
+ )
508
+ }
509
+
510
+ export default MainLayout