@searpent/react-image-annotate 2.0.5 → 2.0.8

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 (195) hide show
  1. package/Annotator/examplePhotos.js +6976 -0
  2. package/Annotator/index.js +268 -0
  3. package/Annotator/reducers/combine-reducers.js +14 -0
  4. package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
  5. package/{src/Annotator → Annotator}/reducers/fix-twisted.js +3 -5
  6. package/Annotator/reducers/general-reducer.js +1152 -0
  7. package/Annotator/reducers/get-active-image.js +27 -0
  8. package/Annotator/reducers/get-implied-video-regions.js +180 -0
  9. package/Annotator/reducers/history-handler.js +38 -0
  10. package/Annotator/reducers/image-reducer.js +20 -0
  11. package/Annotator/reducers/video-reducer.js +88 -0
  12. package/ClassSelectionMenu/index.js +135 -0
  13. package/Crosshairs/index.js +53 -0
  14. package/DebugSidebarBox/index.js +20 -0
  15. package/DemoSite/Editor.js +194 -0
  16. package/DemoSite/ErrorBoundaryDialog.js +64 -0
  17. package/DemoSite/index.js +40 -0
  18. package/{src/Editor → Editor}/annotation-plugin/annotation.css +0 -0
  19. package/Editor/annotation-plugin/annotation.js +613 -0
  20. package/Editor/index.js +57 -0
  21. package/{src/Editor → Editor}/tools.js +2 -3
  22. package/FullImageSegmentationAnnotator/index.js +7 -0
  23. package/GroupSelectorSidebarBox/index.js +63 -0
  24. package/HighlightBox/index.js +99 -0
  25. package/HistorySidebarBox/index.js +71 -0
  26. package/ImageCanvas/index.js +429 -0
  27. package/ImageCanvas/region-tools.js +165 -0
  28. package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
  29. package/ImageCanvas/use-mouse.js +180 -0
  30. package/ImageCanvas/use-project-box.js +27 -0
  31. package/ImageCanvas/use-wasd-mode.js +62 -0
  32. package/ImageMask/index.js +133 -0
  33. package/ImageMask/load-image.js +25 -0
  34. package/ImageSelectorSidebarBox/index.js +60 -0
  35. package/KeyframeTimeline/get-time-string.js +27 -0
  36. package/KeyframeTimeline/index.js +233 -0
  37. package/KeyframesSelectorSidebarBox/index.js +93 -0
  38. package/LandingPage/index.js +159 -0
  39. package/MainLayout/icon-dictionary.js +104 -0
  40. package/MainLayout/index.js +469 -0
  41. package/{src/MainLayout → MainLayout}/styles.js +6 -7
  42. package/MainLayout/types.js +0 -0
  43. package/MainLayout/use-implied-video-regions.js +13 -0
  44. package/MetadataEditorSidebarBox/index.js +126 -0
  45. package/PageSelector/index.js +69 -0
  46. package/{src/PageSelector → PageSelector}/page-selector.css +18 -0
  47. package/PointDistances/index.js +73 -0
  48. package/PreventScrollToParents/index.js +51 -0
  49. package/RegionLabel/index.js +205 -0
  50. package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
  51. package/RegionSelectAndTransformBoxes/index.js +167 -0
  52. package/RegionSelectorSidebarBox/index.js +248 -0
  53. package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
  54. package/RegionShapes/index.js +294 -0
  55. package/RegionTags/index.js +142 -0
  56. package/SettingsDialog/index.js +52 -0
  57. package/SettingsProvider/index.js +58 -0
  58. package/Shortcuts/ShortcutField.js +46 -0
  59. package/Shortcuts/index.js +133 -0
  60. package/ShortcutsManager/index.js +155 -0
  61. package/Sidebar/index.js +69 -0
  62. package/SidebarBoxContainer/index.js +93 -0
  63. package/SmallToolButton/index.js +42 -0
  64. package/TagsSidebarBox/index.js +105 -0
  65. package/TaskDescriptionSidebarBox/index.js +58 -0
  66. package/Theme/index.js +30 -0
  67. package/VideoOrImageCanvasBackground/index.js +151 -0
  68. package/colors.js +14 -0
  69. package/hooks/use-colors.js +101 -0
  70. package/hooks/use-event-callback.js +10 -0
  71. package/hooks/use-exclude-pattern.js +24 -0
  72. package/hooks/use-load-image.js +26 -0
  73. package/hooks/use-window-size.js +46 -0
  74. package/{src/hooks → hooks}/xpattern.js +1 -1
  75. package/index.js +3 -0
  76. package/lib.js +3 -0
  77. package/package.json +1 -1
  78. package/stories.js +5 -0
  79. package/{src/utils → utils}/filter-only-unique.js +1 -1
  80. package/utils/get-from-local-storage.js +7 -0
  81. package/utils/get-hotkey-help-text.js +9 -0
  82. package/utils/get-landmarks-with-transform.js +40 -0
  83. package/utils/photosToImages.js +53 -0
  84. package/utils/regions-to-blocks.js +16 -0
  85. package/utils/set-in-local-storage.js +3 -0
  86. package/.babelrc +0 -6
  87. package/.env +0 -1
  88. package/.flowconfig +0 -2
  89. package/.github/workflows/release-on-master.yml +0 -32
  90. package/.github/workflows/test.yml +0 -16
  91. package/.prettierrc +0 -3
  92. package/.releaserc.js +0 -18
  93. package/.storybook/addons.js +0 -2
  94. package/.storybook/config.js +0 -16
  95. package/LICENSE +0 -21
  96. package/public/favicon.ico +0 -0
  97. package/public/index.html +0 -38
  98. package/src/Annotator/bike-pic.png +0 -0
  99. package/src/Annotator/bike-pic2.png +0 -0
  100. package/src/Annotator/dab-keyframes.story.json +0 -1
  101. package/src/Annotator/examplePhotos.js +0 -7601
  102. package/src/Annotator/index.js +0 -291
  103. package/src/Annotator/index.story.js +0 -807
  104. package/src/Annotator/poses.story.js +0 -150
  105. package/src/Annotator/reducers/combine-reducers.js +0 -7
  106. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
  107. package/src/Annotator/reducers/general-reducer.js +0 -996
  108. package/src/Annotator/reducers/get-active-image.js +0 -21
  109. package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
  110. package/src/Annotator/reducers/history-handler.js +0 -60
  111. package/src/Annotator/reducers/image-reducer.js +0 -23
  112. package/src/Annotator/reducers/video-reducer.js +0 -85
  113. package/src/Annotator/video.story.js +0 -51
  114. package/src/ClassSelectionMenu/index.js +0 -108
  115. package/src/Crosshairs/index.js +0 -64
  116. package/src/DebugSidebarBox/index.js +0 -36
  117. package/src/DemoSite/Editor.js +0 -235
  118. package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
  119. package/src/DemoSite/index.js +0 -41
  120. package/src/DemoSite/index.story.js +0 -10
  121. package/src/DemoSite/simple-segmentation-example.json +0 -572
  122. package/src/Editor/annotation-plugin/annotation.js +0 -515
  123. package/src/Editor/index.js +0 -24
  124. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  125. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  126. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  127. package/src/FullImageSegmentationAnnotator/index.js +0 -7
  128. package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
  129. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  130. package/src/GroupSelectorSidebarBox/index.js +0 -48
  131. package/src/HighlightBox/index.js +0 -143
  132. package/src/HistorySidebarBox/index.js +0 -78
  133. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  134. package/src/ImageCanvas/index.js +0 -494
  135. package/src/ImageCanvas/index.story.js +0 -314
  136. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  137. package/src/ImageCanvas/region-tools.js +0 -171
  138. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  139. package/src/ImageCanvas/use-mouse.js +0 -168
  140. package/src/ImageCanvas/use-project-box.js +0 -23
  141. package/src/ImageCanvas/use-wasd-mode.js +0 -50
  142. package/src/ImageMask/index.js +0 -127
  143. package/src/ImageMask/load-image.js +0 -32
  144. package/src/ImageSelectorSidebarBox/index.js +0 -54
  145. package/src/KeyframeTimeline/get-time-string.js +0 -25
  146. package/src/KeyframeTimeline/index.js +0 -223
  147. package/src/KeyframesSelectorSidebarBox/index.js +0 -93
  148. package/src/LandingPage/content.md +0 -57
  149. package/src/LandingPage/github-markdown.css +0 -964
  150. package/src/LandingPage/index.js +0 -147
  151. package/src/MainLayout/icon-dictionary.js +0 -79
  152. package/src/MainLayout/index.js +0 -510
  153. package/src/MainLayout/index.story.js +0 -240
  154. package/src/MainLayout/types.js +0 -164
  155. package/src/MainLayout/use-implied-video-regions.js +0 -17
  156. package/src/MetadataEditorSidebarBox/index.js +0 -98
  157. package/src/PageSelector/index.js +0 -76
  158. package/src/PointDistances/index.js +0 -90
  159. package/src/PreventScrollToParents/index.js +0 -48
  160. package/src/PreventScrollToParents/index.story.js +0 -23
  161. package/src/RegionLabel/index.js +0 -222
  162. package/src/RegionSelectAndTransformBoxes/index.js +0 -234
  163. package/src/RegionSelectorSidebarBox/index.js +0 -216
  164. package/src/RegionShapes/index.js +0 -254
  165. package/src/RegionTags/index.js +0 -134
  166. package/src/SettingsDialog/index.js +0 -58
  167. package/src/SettingsProvider/index.js +0 -48
  168. package/src/Shortcuts/ShortcutField.js +0 -44
  169. package/src/Shortcuts/index.js +0 -129
  170. package/src/ShortcutsManager/index.js +0 -162
  171. package/src/Sidebar/index.js +0 -117
  172. package/src/SidebarBoxContainer/index.js +0 -93
  173. package/src/SmallToolButton/index.js +0 -57
  174. package/src/TagsSidebarBox/index.js +0 -93
  175. package/src/TaskDescriptionSidebarBox/index.js +0 -43
  176. package/src/Theme/index.js +0 -36
  177. package/src/VideoOrImageCanvasBackground/index.js +0 -170
  178. package/src/colors.js +0 -32
  179. package/src/hooks/use-colors.js +0 -74
  180. package/src/hooks/use-event-callback.js +0 -11
  181. package/src/hooks/use-exclude-pattern.js +0 -27
  182. package/src/hooks/use-load-image.js +0 -21
  183. package/src/hooks/use-window-size.js +0 -46
  184. package/src/hooks/xpattern.png +0 -0
  185. package/src/index.js +0 -18
  186. package/src/lib.js +0 -7
  187. package/src/screenshot.png +0 -0
  188. package/src/site.css +0 -5
  189. package/src/stories.js +0 -2
  190. package/src/utils/get-from-local-storage.js +0 -7
  191. package/src/utils/get-hotkey-help-text.js +0 -11
  192. package/src/utils/get-landmarks-with-transform.js +0 -23
  193. package/src/utils/photosToImages.js +0 -40
  194. package/src/utils/regions-to-blocks.js +0 -14
  195. package/src/utils/set-in-local-storage.js +0 -6
@@ -0,0 +1,142 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
2
+ import React from "react";
3
+ import Paper from "@mui/material/Paper";
4
+ import DefaultRegionLabel from "../RegionLabel";
5
+ import LockIcon from "@mui/icons-material/Lock";
6
+
7
+ var copyWithout = function copyWithout(obj) {
8
+ var newObj = _objectSpread({}, obj);
9
+
10
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
11
+ args[_key - 1] = arguments[_key];
12
+ }
13
+
14
+ for (var _i = 0, _args = args; _i < _args.length; _i++) {
15
+ var arg = _args[_i];
16
+ delete newObj[arg];
17
+ }
18
+
19
+ return newObj;
20
+ };
21
+
22
+ export var RegionTags = function RegionTags(_ref) {
23
+ var regions = _ref.regions,
24
+ projectRegionBox = _ref.projectRegionBox,
25
+ mouseEvents = _ref.mouseEvents,
26
+ regionClsList = _ref.regionClsList,
27
+ regionTagList = _ref.regionTagList,
28
+ onBeginRegionEdit = _ref.onBeginRegionEdit,
29
+ onChangeRegion = _ref.onChangeRegion,
30
+ onCloseRegionEdit = _ref.onCloseRegionEdit,
31
+ onDeleteRegion = _ref.onDeleteRegion,
32
+ layoutParams = _ref.layoutParams,
33
+ imageSrc = _ref.imageSrc,
34
+ RegionEditLabel = _ref.RegionEditLabel,
35
+ onRegionClassAdded = _ref.onRegionClassAdded,
36
+ allowComments = _ref.allowComments,
37
+ hideNotEditingLabel = _ref.hideNotEditingLabel,
38
+ allowedGroups = _ref.allowedGroups;
39
+ var RegionLabel = RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel;
40
+ return regions.filter(function (r) {
41
+ return r.visible || r.visible === undefined;
42
+ }).map(function (region) {
43
+ var pbox = projectRegionBox(region);
44
+ var _layoutParams$current = layoutParams.current,
45
+ iw = _layoutParams$current.iw,
46
+ ih = _layoutParams$current.ih;
47
+ var margin = 8;
48
+ if (region.highlighted && region.type === "box") margin += 6;
49
+ var labelBoxHeight = region.editingLabels && !region.locked ? 170 : region.tags ? 60 : 50;
50
+ var displayOnTop = pbox.y > labelBoxHeight;
51
+ var coords = displayOnTop ? {
52
+ left: pbox.x,
53
+ top: pbox.y - margin / 2
54
+ } : {
55
+ left: pbox.x,
56
+ top: pbox.y + pbox.h + margin / 2
57
+ };
58
+
59
+ if (region.locked) {
60
+ return React.createElement("div", {
61
+ key: region.id,
62
+ style: _objectSpread({
63
+ position: "absolute"
64
+ }, coords, {
65
+ zIndex: 10 + (region.editingLabels ? 5 : 0)
66
+ })
67
+ }, React.createElement(Paper, {
68
+ style: _objectSpread({
69
+ position: "absolute",
70
+ left: 0
71
+ }, displayOnTop ? {
72
+ bottom: 0
73
+ } : {
74
+ top: 0
75
+ }, {
76
+ zIndex: 10,
77
+ backgroundColor: "#fff",
78
+ borderRadius: 4,
79
+ padding: 2,
80
+ paddingBottom: 0,
81
+ opacity: 0.5,
82
+ pointerEvents: "none"
83
+ })
84
+ }, React.createElement(LockIcon, {
85
+ style: {
86
+ width: 16,
87
+ height: 16,
88
+ color: "#333"
89
+ }
90
+ })));
91
+ }
92
+
93
+ return React.createElement("div", {
94
+ key: region.id,
95
+ style: _objectSpread({
96
+ position: "absolute"
97
+ }, coords, {
98
+ zIndex: 10 + (region.editingLabels ? 5 : 0),
99
+ width: 200
100
+ }),
101
+ onMouseDown: function onMouseDown(e) {
102
+ return e.preventDefault();
103
+ },
104
+ onMouseUp: function onMouseUp(e) {
105
+ return e.preventDefault();
106
+ },
107
+ onMouseEnter: function onMouseEnter(e) {
108
+ if (region.editingLabels) {
109
+ mouseEvents.onMouseUp(e);
110
+ e.button = 1;
111
+ mouseEvents.onMouseUp(e);
112
+ }
113
+ }
114
+ }, React.createElement("div", Object.assign({
115
+ style: _objectSpread({
116
+ position: "absolute",
117
+ zIndex: 20,
118
+ left: 0
119
+ }, displayOnTop ? {
120
+ bottom: 0
121
+ } : {
122
+ top: 0
123
+ })
124
+ }, !region.editingLabels ? copyWithout(mouseEvents, "onMouseDown", "onMouseUp") : {}), React.createElement(RegionLabel, {
125
+ allowedClasses: regionClsList,
126
+ allowedTags: regionTagList,
127
+ onOpen: onBeginRegionEdit,
128
+ onChange: onChangeRegion,
129
+ onClose: onCloseRegionEdit,
130
+ onDelete: onDeleteRegion,
131
+ editing: region.editingLabels,
132
+ region: region,
133
+ regions: regions,
134
+ imageSrc: imageSrc,
135
+ onRegionClassAdded: onRegionClassAdded,
136
+ allowComments: allowComments,
137
+ hideNotEditingLabel: hideNotEditingLabel,
138
+ allowedGroups: allowedGroups
139
+ })));
140
+ });
141
+ };
142
+ export default RegionTags;
@@ -0,0 +1,52 @@
1
+ import React from "react";
2
+ import Dialog from "@mui/material/Dialog";
3
+ import DialogTitle from "@mui/material/DialogTitle";
4
+ import DialogContent from "@mui/material/DialogContent";
5
+ import DialogActions from "@mui/material/DialogActions";
6
+ import Button from "@mui/material/Button";
7
+ import Survey from "material-survey/components/Survey";
8
+ import { useSettings } from "../SettingsProvider";
9
+ export var SettingsDialog = function SettingsDialog(_ref) {
10
+ var open = _ref.open,
11
+ onClose = _ref.onClose;
12
+ var settings = useSettings();
13
+ return React.createElement(Dialog, {
14
+ open: open || false,
15
+ onClose: onClose
16
+ }, React.createElement(DialogTitle, null, "Settings"), React.createElement(DialogContent, {
17
+ style: {
18
+ minWidth: 400
19
+ }
20
+ }, React.createElement(Survey, {
21
+ variant: "flat",
22
+ noActions: true,
23
+ defaultAnswers: settings,
24
+ onQuestionChange: function onQuestionChange(q, a, answers) {
25
+ return settings.changeSetting(q, a);
26
+ },
27
+ form: {
28
+ questions: [{
29
+ type: "boolean",
30
+ title: "Show Crosshairs",
31
+ name: "showCrosshairs"
32
+ }, {
33
+ type: "boolean",
34
+ title: "Show Highlight Box",
35
+ name: "showHighlightBox"
36
+ }, {
37
+ type: "boolean",
38
+ title: "WASD Mode",
39
+ name: "wasdMode"
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
+ })), React.createElement(DialogActions, null, React.createElement(Button, {
49
+ onClick: onClose
50
+ }, "Close")));
51
+ };
52
+ export default SettingsDialog;
@@ -0,0 +1,58 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import React, { createContext, useContext, useState } from "react";
5
+ var defaultSettings = {
6
+ showCrosshairs: false,
7
+ showHighlightBox: true,
8
+ wasdMode: true
9
+ };
10
+ export var SettingsContext = createContext(defaultSettings);
11
+
12
+ var pullSettingsFromLocalStorage = function pullSettingsFromLocalStorage() {
13
+ if (!window || !window.localStorage) return {};
14
+ var settings = {};
15
+
16
+ for (var i = 0; i < window.localStorage.length; i++) {
17
+ var key = window.localStorage.key(i);
18
+
19
+ if (key.startsWith("settings_")) {
20
+ try {
21
+ settings[key.replace("settings_", "")] = JSON.parse(window.localStorage.getItem(key));
22
+ } catch (e) {}
23
+ }
24
+ }
25
+
26
+ return settings;
27
+ };
28
+
29
+ export var useSettings = function useSettings() {
30
+ return useContext(SettingsContext);
31
+ };
32
+ export var SettingsProvider = function SettingsProvider(_ref) {
33
+ var children = _ref.children,
34
+ clsColors = _ref.clsColors,
35
+ groupColors = _ref.groupColors;
36
+
37
+ var _useState = useState(_objectSpread({}, function () {
38
+ return pullSettingsFromLocalStorage();
39
+ }, {
40
+ clsColors: clsColors,
41
+ groupColors: groupColors
42
+ })),
43
+ _useState2 = _slicedToArray(_useState, 2),
44
+ state = _useState2[0],
45
+ changeState = _useState2[1];
46
+
47
+ var changeSetting = function changeSetting(setting, value) {
48
+ changeState(_objectSpread({}, state, _defineProperty({}, setting, value)));
49
+ window.localStorage.setItem("settings_".concat(setting), JSON.stringify(value));
50
+ };
51
+
52
+ return React.createElement(SettingsContext.Provider, {
53
+ value: _objectSpread({}, state, {
54
+ changeSetting: changeSetting
55
+ })
56
+ }, children);
57
+ };
58
+ export default SettingsProvider;
@@ -0,0 +1,46 @@
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
+ var theme = createTheme();
6
+ var useStyles = makeStyles(function (theme) {
7
+ return {
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
+
24
+ var ShortcutField = function ShortcutField(_ref) {
25
+ var actionId = _ref.actionId,
26
+ actionName = _ref.actionName,
27
+ keyName = _ref.keyName,
28
+ onChangeShortcut = _ref.onChangeShortcut;
29
+ var classes = useStyles();
30
+ return React.createElement(ThemeProvider, {
31
+ theme: theme
32
+ }, React.createElement("div", {
33
+ className: classes.shortcutKeyFieldWrapper
34
+ }, React.createElement(TextField, {
35
+ variant: "outlined",
36
+ label: actionName,
37
+ className: classes.shortcutTextfield,
38
+ value: keyName,
39
+ onKeyPress: function onKeyPress(e) {
40
+ onChangeShortcut(actionId, e.key);
41
+ e.stopPropagation();
42
+ }
43
+ })));
44
+ };
45
+
46
+ export default ShortcutField;
@@ -0,0 +1,133 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import React, { useState, useEffect } from "react";
4
+ import SidebarBoxContainer from "../SidebarBoxContainer";
5
+ import { setIn } from "seamless-immutable";
6
+ import ShortcutField from "./ShortcutField";
7
+ var defaultShortcuts = {
8
+ select: {
9
+ action: {
10
+ type: "SELECT_TOOL"
11
+ },
12
+ name: "Select Region",
13
+ key: "Escape"
14
+ },
15
+ zoom: {
16
+ action: {
17
+ type: "SELECT_TOOL"
18
+ },
19
+ name: "Zoom In/Out",
20
+ key: "z"
21
+ },
22
+ "create-point": {
23
+ action: {
24
+ type: "SELECT_TOOL"
25
+ },
26
+ name: "Create Point"
27
+ },
28
+ "create-box": {
29
+ action: {
30
+ type: "SELECT_TOOL"
31
+ },
32
+ name: "Add Bounding Box",
33
+ key: "b"
34
+ },
35
+ pan: {
36
+ action: {
37
+ type: "SELECT_TOOL"
38
+ },
39
+ name: "Pan"
40
+ },
41
+ "create-polygon": {
42
+ action: {
43
+ type: "SELECT_TOOL"
44
+ },
45
+ name: "Create Polygon"
46
+ },
47
+ "create-pixel": {
48
+ action: {
49
+ type: "SELECT_TOOL"
50
+ },
51
+ name: "Create Pixel"
52
+ },
53
+ "prev-image": {
54
+ action: {
55
+ type: "HEADER_BUTTON_CLICKED",
56
+ buttonName: "Prev"
57
+ },
58
+ name: "Previous Image",
59
+ key: "a"
60
+ },
61
+ "next-image": {
62
+ action: {
63
+ type: "HEADER_BUTTON_CLICKED",
64
+ buttonName: "Next"
65
+ },
66
+ name: "Next Image",
67
+ key: "d" //"ArrowRight"
68
+
69
+ }
70
+ };
71
+ export default (function (_ref) {
72
+ var onShortcutActionDispatched = _ref.onShortcutActionDispatched;
73
+
74
+ var _useState = useState({}),
75
+ _useState2 = _slicedToArray(_useState, 2),
76
+ shortcuts = _useState2[0],
77
+ setShortcuts = _useState2[1]; // useLocalStorage
78
+
79
+
80
+ useEffect(function () {
81
+ var newShortcuts = _objectSpread({}, shortcuts);
82
+
83
+ for (var _i = 0, _Object$keys = Object.keys(defaultShortcuts); _i < _Object$keys.length; _i++) {
84
+ var actionId = _Object$keys[_i];
85
+
86
+ if (!newShortcuts[actionId]) {
87
+ newShortcuts[actionId] = defaultShortcuts[actionId];
88
+ }
89
+ }
90
+
91
+ setShortcuts(newShortcuts);
92
+ }, []);
93
+
94
+ var onChangeShortcut = function onChangeShortcut(actionId, keyName) {
95
+ setShortcuts(setIn(shortcuts, [actionId, "key"], keyName));
96
+ };
97
+
98
+ useEffect(function () {
99
+ var handleKeyPress = function handleKeyPress(e) {
100
+ for (var actionId in shortcuts) {
101
+ var shortcut = shortcuts[actionId];
102
+
103
+ if (!shortcut || !shortcut.key) {
104
+ continue;
105
+ }
106
+
107
+ if (e.key === shortcut.key) {
108
+ onShortcutActionDispatched(_objectSpread({}, shortcut.action, {
109
+ selectedTool: actionId
110
+ }));
111
+ }
112
+ }
113
+ };
114
+
115
+ window.addEventListener("keypress", handleKeyPress);
116
+ return function () {
117
+ window.removeEventListener("keypress", handleKeyPress);
118
+ document.activeElement.blur();
119
+ };
120
+ }, [shortcuts]);
121
+ return React.createElement(SidebarBoxContainer, {
122
+ title: "Shortcuts"
123
+ }, Object.keys(shortcuts).map(function (actionId, index) {
124
+ if (!shortcuts[actionId]) return null;
125
+ return React.createElement(ShortcutField, {
126
+ key: actionId,
127
+ actionId: actionId,
128
+ actionName: shortcuts[actionId].name,
129
+ keyName: shortcuts[actionId].key || "",
130
+ onChangeShortcut: onChangeShortcut
131
+ });
132
+ }).filter(Boolean));
133
+ });
@@ -0,0 +1,155 @@
1
+ import React, { useMemo } from "react";
2
+ import { HotKeys } from "react-hotkeys";
3
+ export var defaultHotkeys = [{
4
+ id: "select_tool",
5
+ description: "Switch to the Select Tool",
6
+ binding: "escape"
7
+ }, {
8
+ id: "zoom_tool",
9
+ description: "Select the Zoom Tool",
10
+ binding: "z"
11
+ }, {
12
+ id: "create_point",
13
+ description: "Create a point"
14
+ }, {
15
+ id: "create_bounding_box",
16
+ description: "Create a bounding box",
17
+ binding: "b"
18
+ }, {
19
+ id: "pan_tool",
20
+ description: "Select the Pan Tool",
21
+ binding: "m"
22
+ }, {
23
+ id: "create_polygon",
24
+ description: "Create a Polygon",
25
+ binding: "p"
26
+ }, {
27
+ id: "create_pixel",
28
+ description: "Create a Pixel Mask"
29
+ }, {
30
+ id: "save_and_previous_sample",
31
+ description: "Save and go to previous sample",
32
+ binding: "ArrowLeft"
33
+ }, {
34
+ id: "save_and_next_sample",
35
+ description: "Save and go to next sample",
36
+ binding: "ArrowRight"
37
+ }, {
38
+ id: "save_and_exit_sample",
39
+ description: "Save and exit current sample"
40
+ }, {
41
+ id: "exit_sample",
42
+ description: "Exit sample without saving"
43
+ }, {
44
+ id: "delete_region",
45
+ description: "Delete selected region",
46
+ binding: "d"
47
+ }, {
48
+ id: "undo",
49
+ description: "Undo latest change",
50
+ binding: "Ctrl+z"
51
+ }];
52
+ export var defaultKeyMap = {};
53
+
54
+ for (var _i = 0, _defaultHotkeys = defaultHotkeys; _i < _defaultHotkeys.length; _i++) {
55
+ var _ref4 = _defaultHotkeys[_i];
56
+ var id = _ref4.id;
57
+ var binding = _ref4.binding;
58
+ defaultKeyMap[id] = binding;
59
+ }
60
+
61
+ export var useDispatchHotkeyHandlers = function useDispatchHotkeyHandlers(_ref2) {
62
+ var dispatch = _ref2.dispatch;
63
+ var handlers = useMemo(function () {
64
+ return {
65
+ select_tool: function select_tool() {
66
+ dispatch({
67
+ type: "SELECT_TOOL",
68
+ selectedTool: "select"
69
+ });
70
+ },
71
+ zoom_tool: function zoom_tool() {
72
+ dispatch({
73
+ type: "SELECT_TOOL",
74
+ selectedTool: "zoom"
75
+ });
76
+ },
77
+ create_point: function create_point() {
78
+ dispatch({
79
+ type: "SELECT_TOOL",
80
+ selectedTool: "create-point"
81
+ });
82
+ },
83
+ create_bounding_box: function create_bounding_box() {
84
+ dispatch({
85
+ type: "SELECT_TOOL",
86
+ selectedTool: "create-box"
87
+ });
88
+ },
89
+ pan_tool: function pan_tool() {
90
+ dispatch({
91
+ type: "SELECT_TOOL",
92
+ selectedTool: "pan"
93
+ });
94
+ },
95
+ create_polygon: function create_polygon() {
96
+ dispatch({
97
+ type: "SELECT_TOOL",
98
+ selectedTool: "create-polygon"
99
+ });
100
+ },
101
+ create_pixel: function create_pixel() {
102
+ dispatch({
103
+ type: "SELECT_TOOL",
104
+ selectedTool: "create-pixel"
105
+ });
106
+ },
107
+ save_and_previous_sample: function save_and_previous_sample() {
108
+ dispatch({
109
+ type: "HEADER_BUTTON_CLICKED",
110
+ buttonName: "Prev"
111
+ });
112
+ },
113
+ save_and_next_sample: function save_and_next_sample() {
114
+ dispatch({
115
+ type: "HEADER_BUTTON_CLICKED",
116
+ buttonName: "Next"
117
+ });
118
+ },
119
+ save_and_exit_sample: function save_and_exit_sample() {
120
+ dispatch({
121
+ type: "HEADER_BUTTON_CLICKED",
122
+ buttonName: "Save"
123
+ });
124
+ },
125
+ delete_region: function delete_region() {
126
+ dispatch({
127
+ type: "DELETE_SELECTED_REGION"
128
+ });
129
+ },
130
+ undo: function undo() {
131
+ dispatch({
132
+ type: "RESTORE_HISTORY"
133
+ });
134
+ } // TODO
135
+ // exit_sample: () => {
136
+ // dispatch({
137
+ // type: "",
138
+ // })
139
+ // }
140
+
141
+ };
142
+ }, [dispatch]);
143
+ return handlers;
144
+ };
145
+ export default (function (_ref3) {
146
+ var children = _ref3.children,
147
+ dispatch = _ref3.dispatch;
148
+ var handlers = useDispatchHotkeyHandlers({
149
+ dispatch: dispatch
150
+ });
151
+ return React.createElement(HotKeys, {
152
+ allowChanges: true,
153
+ handlers: handlers
154
+ }, children);
155
+ });
@@ -0,0 +1,69 @@
1
+ import React from "react";
2
+ import { styled } from "@mui/styles";
3
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
4
+ import TaskDescription from "../TaskDescriptionSidebarBox";
5
+ import ImageSelector from "../ImageSelectorSidebarBox";
6
+ import RegionSelector from "../RegionSelectorSidebarBox";
7
+ import History from "../HistorySidebarBox";
8
+ import DebugBox from "../DebugSidebarBox";
9
+ import TagsSidebarBox from "../TagsSidebarBox";
10
+ import KeyframesSelector from "../KeyframesSelectorSidebarBox";
11
+ var theme = createTheme();
12
+ var Container = styled("div")(function (_ref) {
13
+ var theme = _ref.theme;
14
+ return {};
15
+ });
16
+ var emptyArr = [];
17
+ export var Sidebar = function Sidebar(_ref2) {
18
+ var debug = _ref2.debug,
19
+ taskDescription = _ref2.taskDescription,
20
+ keyframes = _ref2.keyframes,
21
+ images = _ref2.images,
22
+ regions = _ref2.regions,
23
+ history = _ref2.history,
24
+ labelImages = _ref2.labelImages,
25
+ currentImage = _ref2.currentImage,
26
+ currentVideoTime = _ref2.currentVideoTime,
27
+ imageClsList = _ref2.imageClsList,
28
+ imageTagList = _ref2.imageTagList,
29
+ onChangeImage = _ref2.onChangeImage,
30
+ onSelectRegion = _ref2.onSelectRegion,
31
+ onSelectImage = _ref2.onSelectImage,
32
+ onChangeRegion = _ref2.onChangeRegion,
33
+ onDeleteRegion = _ref2.onDeleteRegion,
34
+ _onRestoreHistory = _ref2.onRestoreHistory,
35
+ onChangeVideoTime = _ref2.onChangeVideoTime,
36
+ onDeleteKeyframe = _ref2.onDeleteKeyframe,
37
+ onShortcutActionDispatched = _ref2.onShortcutActionDispatched;
38
+ if (!regions) regions = emptyArr;
39
+ return React.createElement(ThemeProvider, {
40
+ theme: theme
41
+ }, React.createElement(Container, null, debug && React.createElement(DebugBox, {
42
+ state: debug,
43
+ lastAction: debug.lastAction
44
+ }), taskDescription && (taskDescription || "").length > 1 && React.createElement(TaskDescription, {
45
+ description: taskDescription
46
+ }), labelImages && React.createElement(TagsSidebarBox, {
47
+ currentImage: currentImage,
48
+ imageClsList: imageClsList,
49
+ imageTagList: imageTagList,
50
+ onChangeImage: onChangeImage,
51
+ expandedByDefault: true
52
+ }), React.createElement(RegionSelector, {
53
+ regions: regions,
54
+ onSelectRegion: onSelectRegion,
55
+ onChangeRegion: onChangeRegion,
56
+ onDeleteRegion: onDeleteRegion
57
+ }), keyframes && React.createElement(KeyframesSelector, {
58
+ currentVideoTime: currentVideoTime,
59
+ keyframes: keyframes,
60
+ onChangeVideoTime: onChangeVideoTime,
61
+ onDeleteKeyframe: onDeleteKeyframe
62
+ }), React.createElement(History, {
63
+ history: history,
64
+ onRestoreHistory: function onRestoreHistory() {
65
+ return _onRestoreHistory();
66
+ }
67
+ })));
68
+ };
69
+ export default Sidebar;