@searpent/react-image-annotate 2.0.3 → 2.0.4

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 (187) 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 -169
  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/GroupSelectorSidebarBox/index.js +0 -63
  139. package/HighlightBox/index.js +0 -99
  140. package/HistorySidebarBox/index.js +0 -71
  141. package/ImageCanvas/index.js +0 -424
  142. package/ImageCanvas/region-tools.js +0 -165
  143. package/ImageCanvas/use-mouse.js +0 -180
  144. package/ImageCanvas/use-project-box.js +0 -27
  145. package/ImageCanvas/use-wasd-mode.js +0 -62
  146. package/ImageMask/index.js +0 -133
  147. package/ImageMask/load-image.js +0 -25
  148. package/ImageSelectorSidebarBox/index.js +0 -60
  149. package/KeyframeTimeline/get-time-string.js +0 -27
  150. package/KeyframeTimeline/index.js +0 -233
  151. package/KeyframesSelectorSidebarBox/index.js +0 -93
  152. package/LandingPage/index.js +0 -159
  153. package/MainLayout/icon-dictionary.js +0 -104
  154. package/MainLayout/index.js +0 -366
  155. package/MainLayout/types.js +0 -0
  156. package/MainLayout/use-implied-video-regions.js +0 -13
  157. package/PointDistances/index.js +0 -73
  158. package/PreventScrollToParents/index.js +0 -51
  159. package/RegionLabel/index.js +0 -191
  160. package/RegionSelectAndTransformBoxes/index.js +0 -167
  161. package/RegionSelectorSidebarBox/index.js +0 -248
  162. package/RegionShapes/index.js +0 -274
  163. package/RegionTags/index.js +0 -138
  164. package/SettingsDialog/index.js +0 -52
  165. package/SettingsProvider/index.js +0 -53
  166. package/Shortcuts/ShortcutField.js +0 -46
  167. package/Shortcuts/index.js +0 -133
  168. package/ShortcutsManager/index.js +0 -155
  169. package/Sidebar/index.js +0 -69
  170. package/SidebarBoxContainer/index.js +0 -93
  171. package/SmallToolButton/index.js +0 -42
  172. package/TagsSidebarBox/index.js +0 -105
  173. package/TaskDescriptionSidebarBox/index.js +0 -58
  174. package/Theme/index.js +0 -30
  175. package/VideoOrImageCanvasBackground/index.js +0 -151
  176. package/colors.js +0 -14
  177. package/hooks/use-event-callback.js +0 -10
  178. package/hooks/use-exclude-pattern.js +0 -24
  179. package/hooks/use-load-image.js +0 -26
  180. package/hooks/use-window-size.js +0 -46
  181. package/index.js +0 -3
  182. package/lib.js +0 -3
  183. package/stories.js +0 -5
  184. package/utils/get-from-local-storage.js +0 -7
  185. package/utils/get-hotkey-help-text.js +0 -9
  186. package/utils/get-landmarks-with-transform.js +0 -40
  187. package/utils/set-in-local-storage.js +0 -3
@@ -0,0 +1,58 @@
1
+ // @flow
2
+
3
+ import React from "react"
4
+ import Dialog from "@mui/material/Dialog"
5
+ import DialogTitle from "@mui/material/DialogTitle"
6
+ import DialogContent from "@mui/material/DialogContent"
7
+ import DialogActions from "@mui/material/DialogActions"
8
+ import Button from "@mui/material/Button"
9
+ import Survey from "material-survey/components/Survey"
10
+ import { useSettings } from "../SettingsProvider"
11
+
12
+ export const SettingsDialog = ({ open, onClose }) => {
13
+ const settings = useSettings()
14
+ return (
15
+ <Dialog open={open || false} onClose={onClose}>
16
+ <DialogTitle>Settings</DialogTitle>
17
+ <DialogContent style={{ minWidth: 400 }}>
18
+ <Survey
19
+ variant="flat"
20
+ noActions
21
+ defaultAnswers={settings}
22
+ onQuestionChange={(q, a, answers) => settings.changeSetting(q, a)}
23
+ form={{
24
+ questions: [
25
+ {
26
+ type: "boolean",
27
+ title: "Show Crosshairs",
28
+ name: "showCrosshairs",
29
+ },
30
+ {
31
+ type: "boolean",
32
+ title: "Show Highlight Box",
33
+ name: "showHighlightBox",
34
+ },
35
+ {
36
+ type: "boolean",
37
+ title: "WASD Mode",
38
+ name: "wasdMode",
39
+ },
40
+ {
41
+ type: "dropdown",
42
+ title: "Video Playback Speed",
43
+ name: "videoPlaybackSpeed",
44
+ defaultValue: "1x",
45
+ choices: ["0.25x", "0.5x", "1x", "2x"],
46
+ },
47
+ ],
48
+ }}
49
+ />
50
+ </DialogContent>
51
+ <DialogActions>
52
+ <Button onClick={onClose}>Close</Button>
53
+ </DialogActions>
54
+ </Dialog>
55
+ )
56
+ }
57
+
58
+ export default SettingsDialog
@@ -0,0 +1,48 @@
1
+ // @flow
2
+
3
+ import React, { createContext, useContext, useState } from "react"
4
+
5
+ const defaultSettings = {
6
+ showCrosshairs: false,
7
+ showHighlightBox: true,
8
+ wasdMode: true,
9
+ }
10
+
11
+ export const SettingsContext = createContext(defaultSettings)
12
+
13
+ const pullSettingsFromLocalStorage = () => {
14
+ if (!window || !window.localStorage) return {}
15
+ let settings = {}
16
+ for (let i = 0; i < window.localStorage.length; i++) {
17
+ const key = window.localStorage.key(i)
18
+ if (key.startsWith("settings_")) {
19
+ try {
20
+ settings[key.replace("settings_", "")] = JSON.parse(
21
+ window.localStorage.getItem(key)
22
+ )
23
+ } catch (e) { }
24
+ }
25
+ }
26
+ return settings
27
+ }
28
+
29
+ export const useSettings = () => useContext(SettingsContext)
30
+
31
+ export const SettingsProvider = ({ children, clsColors, groupColors }) => {
32
+ const [state, changeState] = useState({
33
+ ...() => pullSettingsFromLocalStorage(),
34
+ clsColors,
35
+ groupColors,
36
+ })
37
+ const changeSetting = (setting: string, value: any) => {
38
+ changeState({ ...state, [setting]: value })
39
+ window.localStorage.setItem(`settings_${setting}`, JSON.stringify(value))
40
+ }
41
+ return (
42
+ <SettingsContext.Provider value={{ ...state, changeSetting }}>
43
+ {children}
44
+ </SettingsContext.Provider>
45
+ )
46
+ }
47
+
48
+ export default SettingsProvider
@@ -0,0 +1,44 @@
1
+ import React from "react"
2
+ import TextField from "@mui/material/TextField"
3
+ import { makeStyles } from "@mui/styles"
4
+ import { createTheme, ThemeProvider } from "@mui/material/styles"
5
+
6
+ const theme = createTheme()
7
+ const useStyles = makeStyles((theme) => ({
8
+ shortcutKeyFieldWrapper: {
9
+ paddingTop: 8,
10
+ display: "inline-flex",
11
+ width: "100%",
12
+ },
13
+ shortcutKeyText: {
14
+ lineHeight: 0,
15
+ },
16
+ shortcutTextfield: {
17
+ width: "100%",
18
+ boxSizing: "border-box",
19
+ textAlign: "center",
20
+ },
21
+ }))
22
+
23
+ const ShortcutField = ({ actionId, actionName, keyName, onChangeShortcut }) => {
24
+ const classes = useStyles()
25
+
26
+ return (
27
+ <ThemeProvider theme={theme}>
28
+ <div className={classes.shortcutKeyFieldWrapper}>
29
+ <TextField
30
+ variant="outlined"
31
+ label={actionName}
32
+ className={classes.shortcutTextfield}
33
+ value={keyName}
34
+ onKeyPress={(e) => {
35
+ onChangeShortcut(actionId, e.key)
36
+ e.stopPropagation()
37
+ }}
38
+ />
39
+ </div>
40
+ </ThemeProvider>
41
+ )
42
+ }
43
+
44
+ export default ShortcutField
@@ -0,0 +1,129 @@
1
+ import React, { useState, useEffect } from "react"
2
+ import SidebarBoxContainer from "../SidebarBoxContainer"
3
+ import { setIn } from "seamless-immutable"
4
+ import ShortcutField from "./ShortcutField"
5
+
6
+ const defaultShortcuts = {
7
+ select: {
8
+ action: {
9
+ type: "SELECT_TOOL",
10
+ },
11
+ name: "Select Region",
12
+ key: "Escape",
13
+ },
14
+ zoom: {
15
+ action: {
16
+ type: "SELECT_TOOL",
17
+ },
18
+ name: "Zoom In/Out",
19
+ key: "z",
20
+ },
21
+ "create-point": {
22
+ action: {
23
+ type: "SELECT_TOOL",
24
+ },
25
+ name: "Create Point",
26
+ },
27
+ "create-box": {
28
+ action: {
29
+ type: "SELECT_TOOL",
30
+ },
31
+ name: "Add Bounding Box",
32
+ key: "b",
33
+ },
34
+ pan: {
35
+ action: {
36
+ type: "SELECT_TOOL",
37
+ },
38
+ name: "Pan",
39
+ },
40
+ "create-polygon": {
41
+ action: {
42
+ type: "SELECT_TOOL",
43
+ },
44
+ name: "Create Polygon",
45
+ },
46
+ "create-pixel": {
47
+ action: {
48
+ type: "SELECT_TOOL",
49
+ },
50
+ name: "Create Pixel",
51
+ },
52
+ "prev-image": {
53
+ action: {
54
+ type: "HEADER_BUTTON_CLICKED",
55
+ buttonName: "Prev",
56
+ },
57
+ name: "Previous Image",
58
+ key: "a",
59
+ },
60
+ "next-image": {
61
+ action: {
62
+ type: "HEADER_BUTTON_CLICKED",
63
+ buttonName: "Next",
64
+ },
65
+ name: "Next Image",
66
+ key: "d", //"ArrowRight"
67
+ },
68
+ }
69
+
70
+ export default ({ onShortcutActionDispatched }) => {
71
+ const [shortcuts, setShortcuts] = useState({}) // useLocalStorage
72
+
73
+ useEffect(() => {
74
+ const newShortcuts = { ...shortcuts }
75
+ for (const actionId of Object.keys(defaultShortcuts)) {
76
+ if (!newShortcuts[actionId]) {
77
+ newShortcuts[actionId] = defaultShortcuts[actionId]
78
+ }
79
+ }
80
+ setShortcuts(newShortcuts)
81
+ }, [])
82
+
83
+ const onChangeShortcut = (actionId, keyName) => {
84
+ setShortcuts(setIn(shortcuts, [actionId, "key"], keyName))
85
+ }
86
+
87
+ useEffect(() => {
88
+ const handleKeyPress = (e) => {
89
+ for (const actionId in shortcuts) {
90
+ const shortcut = shortcuts[actionId]
91
+ if (!shortcut || !shortcut.key) {
92
+ continue
93
+ }
94
+ if (e.key === shortcut.key) {
95
+ onShortcutActionDispatched({
96
+ ...shortcut.action,
97
+ selectedTool: actionId,
98
+ })
99
+ }
100
+ }
101
+ }
102
+
103
+ window.addEventListener("keypress", handleKeyPress)
104
+
105
+ return () => {
106
+ window.removeEventListener("keypress", handleKeyPress)
107
+ document.activeElement.blur()
108
+ }
109
+ }, [shortcuts])
110
+
111
+ return (
112
+ <SidebarBoxContainer title="Shortcuts">
113
+ {Object.keys(shortcuts)
114
+ .map((actionId, index) => {
115
+ if (!shortcuts[actionId]) return null
116
+ return (
117
+ <ShortcutField
118
+ key={actionId}
119
+ actionId={actionId}
120
+ actionName={shortcuts[actionId].name}
121
+ keyName={shortcuts[actionId].key || ""}
122
+ onChangeShortcut={onChangeShortcut}
123
+ />
124
+ )
125
+ })
126
+ .filter(Boolean)}
127
+ </SidebarBoxContainer>
128
+ )
129
+ }
@@ -0,0 +1,162 @@
1
+ import React, { useMemo } from "react"
2
+ import { HotKeys } from "react-hotkeys"
3
+
4
+ export const defaultHotkeys = [
5
+ {
6
+ id: "select_tool",
7
+ description: "Switch to the Select Tool",
8
+ binding: "escape",
9
+ },
10
+ {
11
+ id: "zoom_tool",
12
+ description: "Select the Zoom Tool",
13
+ binding: "z",
14
+ },
15
+ {
16
+ id: "create_point",
17
+ description: "Create a point",
18
+ },
19
+ {
20
+ id: "create_bounding_box",
21
+ description: "Create a bounding box",
22
+ binding: "b",
23
+ },
24
+ {
25
+ id: "pan_tool",
26
+ description: "Select the Pan Tool",
27
+ binding: "m",
28
+ },
29
+ {
30
+ id: "create_polygon",
31
+ description: "Create a Polygon",
32
+ binding: "p",
33
+ },
34
+ {
35
+ id: "create_pixel",
36
+ description: "Create a Pixel Mask",
37
+ },
38
+ {
39
+ id: "save_and_previous_sample",
40
+ description: "Save and go to previous sample",
41
+ binding: "ArrowLeft",
42
+ },
43
+ {
44
+ id: "save_and_next_sample",
45
+ description: "Save and go to next sample",
46
+ binding: "ArrowRight",
47
+ },
48
+ {
49
+ id: "save_and_exit_sample",
50
+ description: "Save and exit current sample",
51
+ },
52
+ {
53
+ id: "exit_sample",
54
+ description: "Exit sample without saving",
55
+ },
56
+ {
57
+ id: "delete_region",
58
+ description: "Delete selected region",
59
+ binding: "d",
60
+ },
61
+ {
62
+ id: "undo",
63
+ description: "Undo latest change",
64
+ binding: "Ctrl+z",
65
+ },
66
+ ]
67
+ export const defaultKeyMap = {}
68
+ for (const { id, binding } of defaultHotkeys) defaultKeyMap[id] = binding
69
+
70
+ export const useDispatchHotkeyHandlers = ({ dispatch }) => {
71
+ const handlers = useMemo(
72
+ () => ({
73
+ select_tool: () => {
74
+ dispatch({
75
+ type: "SELECT_TOOL",
76
+ selectedTool: "select",
77
+ })
78
+ },
79
+ zoom_tool: () => {
80
+ dispatch({
81
+ type: "SELECT_TOOL",
82
+ selectedTool: "zoom",
83
+ })
84
+ },
85
+ create_point: () => {
86
+ dispatch({
87
+ type: "SELECT_TOOL",
88
+ selectedTool: "create-point",
89
+ })
90
+ },
91
+ create_bounding_box: () => {
92
+ dispatch({
93
+ type: "SELECT_TOOL",
94
+ selectedTool: "create-box",
95
+ })
96
+ },
97
+ pan_tool: () => {
98
+ dispatch({
99
+ type: "SELECT_TOOL",
100
+ selectedTool: "pan",
101
+ })
102
+ },
103
+ create_polygon: () => {
104
+ dispatch({
105
+ type: "SELECT_TOOL",
106
+ selectedTool: "create-polygon",
107
+ })
108
+ },
109
+ create_pixel: () => {
110
+ dispatch({
111
+ type: "SELECT_TOOL",
112
+ selectedTool: "create-pixel",
113
+ })
114
+ },
115
+ save_and_previous_sample: () => {
116
+ dispatch({
117
+ type: "HEADER_BUTTON_CLICKED",
118
+ buttonName: "Prev",
119
+ })
120
+ },
121
+ save_and_next_sample: () => {
122
+ dispatch({
123
+ type: "HEADER_BUTTON_CLICKED",
124
+ buttonName: "Next",
125
+ })
126
+ },
127
+ save_and_exit_sample: () => {
128
+ dispatch({
129
+ type: "HEADER_BUTTON_CLICKED",
130
+ buttonName: "Save",
131
+ })
132
+ },
133
+ delete_region: () => {
134
+ dispatch({
135
+ type: "DELETE_SELECTED_REGION",
136
+ })
137
+ },
138
+ undo: () => {
139
+ dispatch({
140
+ type: "RESTORE_HISTORY",
141
+ })
142
+ },
143
+ // TODO
144
+ // exit_sample: () => {
145
+ // dispatch({
146
+ // type: "",
147
+ // })
148
+ // }
149
+ }),
150
+ [dispatch]
151
+ )
152
+ return handlers
153
+ }
154
+
155
+ export default ({ children, dispatch }) => {
156
+ const handlers = useDispatchHotkeyHandlers({ dispatch })
157
+ return (
158
+ <HotKeys allowChanges handlers={handlers}>
159
+ {children}
160
+ </HotKeys>
161
+ )
162
+ }
@@ -0,0 +1,117 @@
1
+ // @flow
2
+
3
+ import React from "react"
4
+ import { styled } from "@mui/styles"
5
+ import { createTheme, ThemeProvider } from "@mui/material/styles"
6
+ import TaskDescription from "../TaskDescriptionSidebarBox"
7
+ import ImageSelector from "../ImageSelectorSidebarBox"
8
+ import RegionSelector from "../RegionSelectorSidebarBox"
9
+ import History from "../HistorySidebarBox"
10
+ import DebugBox from "../DebugSidebarBox"
11
+ import TagsSidebarBox from "../TagsSidebarBox"
12
+ import KeyframesSelector from "../KeyframesSelectorSidebarBox"
13
+ import type { Region } from "../ImageCanvas/region-tools.js"
14
+
15
+ const theme = createTheme()
16
+ const Container = styled("div")(({ theme }) => ({}))
17
+
18
+ type Image = {
19
+ name: string,
20
+ src: string,
21
+ cls?: string,
22
+ tags?: Array<string>,
23
+ thumbnailSrc?: string,
24
+ regions?: Array<Region>,
25
+ }
26
+
27
+ type Props = {
28
+ debug: any,
29
+ taskDescription: string,
30
+ images?: Array<Image>,
31
+ regions: Array<Region>,
32
+ history: Array<{ state: Object, name: string, time: Date }>,
33
+
34
+ labelImages?: boolean,
35
+ currentImage?: Image,
36
+ imageClsList?: Array<string>,
37
+ imageTagList?: Array<string>,
38
+
39
+ onChangeImage: (Image) => any,
40
+ onSelectRegion: (Region) => any,
41
+ onSelectImage: (Image) => any,
42
+ onChangeRegion: (Region) => any,
43
+ onDeleteRegion: (Region) => any,
44
+ onRestoreHistory: () => any,
45
+ onShortcutActionDispatched: (action: any) => any,
46
+ }
47
+
48
+ const emptyArr = []
49
+
50
+ export const Sidebar = ({
51
+ debug,
52
+ taskDescription,
53
+ keyframes,
54
+ images,
55
+ regions,
56
+ history,
57
+ labelImages,
58
+ currentImage,
59
+ currentVideoTime,
60
+ imageClsList,
61
+ imageTagList,
62
+ onChangeImage,
63
+ onSelectRegion,
64
+ onSelectImage,
65
+ onChangeRegion,
66
+ onDeleteRegion,
67
+ onRestoreHistory,
68
+ onChangeVideoTime,
69
+ onDeleteKeyframe,
70
+ onShortcutActionDispatched,
71
+ }: Props) => {
72
+ if (!regions) regions = emptyArr
73
+
74
+ return (
75
+ <ThemeProvider theme={theme}>
76
+ <Container>
77
+ {debug && <DebugBox state={debug} lastAction={debug.lastAction} />}
78
+ {taskDescription && (taskDescription || "").length > 1 && (
79
+ <TaskDescription description={taskDescription} />
80
+ )}
81
+ {labelImages && (
82
+ <TagsSidebarBox
83
+ currentImage={currentImage}
84
+ imageClsList={imageClsList}
85
+ imageTagList={imageTagList}
86
+ onChangeImage={onChangeImage}
87
+ expandedByDefault
88
+ />
89
+ )}
90
+ {/* {images && images.length > 1 && (
91
+ <ImageSelector onSelect={onSelectImage} images={images} />
92
+ )} */}
93
+ <RegionSelector
94
+ regions={regions}
95
+ onSelectRegion={onSelectRegion}
96
+ onChangeRegion={onChangeRegion}
97
+ onDeleteRegion={onDeleteRegion}
98
+ />
99
+ {keyframes && (
100
+ <KeyframesSelector
101
+ currentVideoTime={currentVideoTime}
102
+ keyframes={keyframes}
103
+ onChangeVideoTime={onChangeVideoTime}
104
+ onDeleteKeyframe={onDeleteKeyframe}
105
+ />
106
+ )}
107
+ <History
108
+ history={history}
109
+ onRestoreHistory={() => onRestoreHistory()}
110
+ />
111
+ {/* <Shortcuts onShortcutActionDispatched={onShortcutActionDispatched} /> */}
112
+ </Container>
113
+ </ThemeProvider>
114
+ )
115
+ }
116
+
117
+ export default Sidebar
@@ -0,0 +1,93 @@
1
+ // @flow
2
+
3
+ import React, { useState, memo } from "react"
4
+ import Paper from "@mui/material/Paper"
5
+ import { makeStyles } from "@mui/styles"
6
+ import { createTheme, ThemeProvider } from "@mui/material/styles"
7
+ import ExpandIcon from "@mui/icons-material/ExpandMore"
8
+ import IconButton from "@mui/material/IconButton"
9
+ import Collapse from "@mui/material/Collapse"
10
+ import { grey } from "@mui/material/colors"
11
+ import classnames from "classnames"
12
+ import useEventCallback from "use-event-callback"
13
+ import SidebarBox from "react-material-workspace-layout/SidebarBox"
14
+
15
+ const theme = createTheme()
16
+ const useStyles = makeStyles((theme) => ({
17
+ container: { margin: 8 },
18
+ header: {
19
+ display: "flex",
20
+ flexDirection: "row",
21
+ alignItems: "center",
22
+ padding: 8,
23
+ paddingLeft: 16,
24
+ paddingRight: 16,
25
+ },
26
+ title: {
27
+ fontSize: 14,
28
+ fontWeight: "bold",
29
+ flexGrow: 1,
30
+ paddingLeft: 8,
31
+ color: grey[800],
32
+ "& span": {
33
+ color: grey[600],
34
+ fontSize: 12,
35
+ },
36
+ },
37
+ expandButton: {
38
+ padding: 0,
39
+ width: 30,
40
+ height: 30,
41
+ "& .icon": {
42
+ marginTop: -6,
43
+ width: 20,
44
+ height: 20,
45
+ transition: "500ms transform",
46
+ "&.expanded": {
47
+ transform: "rotate(180deg)",
48
+ },
49
+ },
50
+ },
51
+ expandedContent: {
52
+ maxHeight: 300,
53
+ overflowY: "auto",
54
+ "&.noScroll": {
55
+ overflowY: "visible",
56
+ overflow: "visible",
57
+ },
58
+ },
59
+ }))
60
+
61
+ export const SidebarBoxContainer = ({
62
+ icon,
63
+ title,
64
+ subTitle,
65
+ children,
66
+ noScroll = false,
67
+ expandedByDefault = false,
68
+ }) => {
69
+ const classes = useStyles()
70
+ const content = (
71
+ <div
72
+ className={classnames(classes.expandedContent, noScroll && "noScroll")}
73
+ >
74
+ {children}
75
+ </div>
76
+ )
77
+
78
+ const [expanded, changeExpanded] = useState(expandedByDefault)
79
+ const toggleExpanded = useEventCallback(() => changeExpanded(!expanded))
80
+
81
+ return (
82
+ <ThemeProvider theme={theme}>
83
+ <SidebarBox icon={icon} title={title}>
84
+ {children}
85
+ </SidebarBox>
86
+ </ThemeProvider>
87
+ )
88
+ }
89
+
90
+ export default memo(
91
+ SidebarBoxContainer,
92
+ (prev, next) => prev.title === next.title && prev.children === next.children
93
+ )
@@ -0,0 +1,57 @@
1
+ // @flow
2
+
3
+ import React, { createContext, useContext, memo } from "react"
4
+ import IconButton from "@mui/material/IconButton"
5
+ import Tooltip from "@mui/material/Tooltip"
6
+ import { blue } from "@mui/material/colors"
7
+
8
+ export const SelectedTool = createContext()
9
+
10
+ export const SmallToolButton = ({
11
+ id,
12
+ name,
13
+ icon,
14
+ selected,
15
+ togglable,
16
+ alwaysShowing = false,
17
+ }: {
18
+ id: string,
19
+ name: string,
20
+ icon: any,
21
+ alwaysShowing?: boolean,
22
+ selected?: boolean,
23
+ togglable?: boolean,
24
+ }) => {
25
+ const { enabledTools, selectedTool, onClickTool } = useContext(SelectedTool)
26
+ if (!enabledTools.includes(id) && !alwaysShowing) return null
27
+ selected = selected || selectedTool === id
28
+ return (
29
+ <Tooltip placement="right" title={name}>
30
+ <div>
31
+ <IconButton
32
+ disabled={!togglable ? selected : undefined}
33
+ aria-label={name}
34
+ onClick={() => onClickTool(id)}
35
+ size="small"
36
+ style={{
37
+ width: 50,
38
+ height: 50,
39
+ margin: 1,
40
+ color: selected ? blue[500] : undefined,
41
+ }}
42
+ >
43
+ {icon}
44
+ </IconButton>
45
+ </div>
46
+ </Tooltip>
47
+ )
48
+ }
49
+
50
+ export default memo(
51
+ SmallToolButton,
52
+ (prevProps, nextProps) =>
53
+ prevProps.togglable === nextProps.togglable &&
54
+ prevProps.selected === nextProps.selected &&
55
+ prevProps.name === nextProps.name &&
56
+ prevProps.id === nextProps.id
57
+ )