@searpent/react-image-annotate 2.0.77 → 2.0.79
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/Annotator/exampleImages.js +41 -0
- package/Annotator/examplePhotos.js +6980 -0
- package/Annotator/index.js +417 -0
- package/Annotator/reducers/combine-reducers.js +14 -0
- package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
- package/{src/Annotator → Annotator}/reducers/fix-twisted.js +3 -5
- package/Annotator/reducers/general-reducer.js +1430 -0
- package/Annotator/reducers/get-active-image.js +27 -0
- package/Annotator/reducers/get-implied-video-regions.js +180 -0
- package/Annotator/reducers/history-handler.js +38 -0
- package/Annotator/reducers/image-reducer.js +20 -0
- package/Annotator/reducers/video-reducer.js +88 -0
- package/ClassSelectionMenu/index.js +140 -0
- package/Crosshairs/index.js +53 -0
- package/DebugSidebarBox/index.js +20 -0
- package/DemoSite/Editor.js +194 -0
- package/DemoSite/ErrorBoundaryDialog.js +64 -0
- package/DemoSite/index.js +40 -0
- package/Editor/annotation-plugin/annotation.js +702 -0
- package/Editor/index.js +93 -0
- package/Editor/readOnly.js +123 -0
- package/{src/Editor → Editor}/tools.js +2 -3
- package/Errorer/index.js +11 -0
- package/FullImageSegmentationAnnotator/index.js +7 -0
- package/GroupSelectorSidebarBox/index.js +63 -0
- package/GroupsEditorSidebarBox/index.js +138 -0
- package/HelpSidebarBox/index.js +58 -0
- package/HighlightBox/index.js +102 -0
- package/HistorySidebarBox/index.js +71 -0
- package/ImageCanvas/index.js +441 -0
- package/ImageCanvas/region-tools.js +165 -0
- package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
- package/ImageCanvas/use-mouse.js +180 -0
- package/ImageCanvas/use-project-box.js +27 -0
- package/ImageCanvas/use-wasd-mode.js +62 -0
- package/ImageMask/index.js +133 -0
- package/ImageMask/load-image.js +25 -0
- package/ImageSelectorSidebarBox/index.js +60 -0
- package/KeyframeTimeline/get-time-string.js +27 -0
- package/KeyframeTimeline/index.js +233 -0
- package/KeyframesSelectorSidebarBox/index.js +93 -0
- package/LandingPage/index.js +159 -0
- package/Locker/index.js +11 -0
- package/MainLayout/RightSidebarItemsWrapper.js +19 -0
- package/MainLayout/icon-dictionary.js +104 -0
- package/MainLayout/index.js +526 -0
- package/{src/MainLayout → MainLayout}/styles.js +6 -7
- package/MainLayout/types.js +0 -0
- package/MainLayout/use-implied-video-regions.js +13 -0
- package/MetadataEditorSidebarBox/index.js +231 -0
- package/PageSelector/index.js +180 -0
- package/PointDistances/index.js +73 -0
- package/PreventScrollToParents/index.js +51 -0
- package/RegionLabel/index.js +232 -0
- package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
- package/RegionSelectAndTransformBoxes/index.js +169 -0
- package/RegionSelectorSidebarBox/index.js +254 -0
- package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
- package/RegionShapes/index.js +294 -0
- package/RegionTags/index.js +144 -0
- package/SettingsDialog/index.js +52 -0
- package/SettingsProvider/index.js +60 -0
- package/Shortcuts/ShortcutField.js +46 -0
- package/Shortcuts/index.js +133 -0
- package/ShortcutsManager/index.js +155 -0
- package/Sidebar/index.js +69 -0
- package/SidebarBoxContainer/index.js +93 -0
- package/SmallToolButton/index.js +42 -0
- package/TagsSidebarBox/index.js +105 -0
- package/TaskDescriptionSidebarBox/index.js +58 -0
- package/Theme/index.js +30 -0
- package/VideoOrImageCanvasBackground/index.js +151 -0
- package/colors.js +14 -0
- package/hooks/use-colors.js +127 -0
- package/hooks/use-event-callback.js +10 -0
- package/hooks/use-exclude-pattern.js +24 -0
- package/hooks/use-load-image.js +26 -0
- package/hooks/use-window-size.js +46 -0
- package/{src/hooks → hooks}/xpattern.js +1 -1
- package/index.js +3 -0
- package/lib.js +3 -0
- package/package.json +1 -1
- package/stories.js +5 -0
- package/utils/blocks-to-article.js +60 -0
- package/{src/utils → utils}/blocks-to-article.test.js +5 -8
- package/{src/utils → utils}/default-locked-until.js +2 -1
- package/{src/utils → utils}/filter-only-unique.js +1 -1
- package/utils/get-from-local-storage.js +7 -0
- package/utils/get-hotkey-help-text.js +9 -0
- package/utils/get-landmarks-with-transform.js +40 -0
- package/utils/photosToImages.js +85 -0
- package/utils/regions-groups.js +28 -0
- package/utils/regions-to-blocks.js +18 -0
- package/utils/saveable-actions-enum.js +3 -0
- package/utils/set-in-local-storage.js +3 -0
- package/utils/sleep.js +7 -0
- package/utils/uuid-to-hash.js +5 -0
- package/.babelrc +0 -6
- package/.env +0 -1
- package/.flowconfig +0 -2
- package/.github/workflows/release-on-master.yml +0 -32
- package/.github/workflows/test.yml +0 -16
- package/.prettierrc +0 -3
- package/.releaserc.js +0 -18
- package/.storybook/addons.js +0 -2
- package/.storybook/config.js +0 -16
- package/LICENSE +0 -21
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -38
- package/src/Annotator/bike-pic.png +0 -0
- package/src/Annotator/bike-pic2.png +0 -0
- package/src/Annotator/dab-keyframes.story.json +0 -1
- package/src/Annotator/exampleImages.js +0 -48
- package/src/Annotator/examplePhotos.js +0 -7603
- package/src/Annotator/index.js +0 -380
- package/src/Annotator/index.story.js +0 -899
- package/src/Annotator/poses.story.js +0 -150
- package/src/Annotator/reducers/combine-reducers.js +0 -7
- package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
- package/src/Annotator/reducers/general-reducer.js +0 -1228
- package/src/Annotator/reducers/get-active-image.js +0 -21
- package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
- package/src/Annotator/reducers/history-handler.js +0 -60
- package/src/Annotator/reducers/image-reducer.js +0 -23
- package/src/Annotator/reducers/video-reducer.js +0 -85
- package/src/Annotator/video.story.js +0 -51
- package/src/ClassSelectionMenu/index.js +0 -112
- package/src/Crosshairs/index.js +0 -64
- package/src/DebugSidebarBox/index.js +0 -36
- package/src/DemoSite/Editor.js +0 -235
- package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
- package/src/DemoSite/index.js +0 -41
- package/src/DemoSite/index.story.js +0 -10
- package/src/DemoSite/simple-segmentation-example.json +0 -572
- package/src/Editor/annotation-plugin/annotation.js +0 -546
- package/src/Editor/index.js +0 -50
- package/src/Editor/readOnly.js +0 -31
- package/src/Errorer/index.js +0 -13
- package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
- package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
- package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
- package/src/FullImageSegmentationAnnotator/index.js +0 -7
- package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
- package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
- package/src/GroupSelectorSidebarBox/index.js +0 -48
- package/src/GroupsEditorSidebarBox/index.js +0 -108
- package/src/HelpSidebarBox/index.js +0 -43
- package/src/HighlightBox/index.js +0 -143
- package/src/HistorySidebarBox/index.js +0 -78
- package/src/ImageCanvas/dancing-man.story.jpg +0 -0
- package/src/ImageCanvas/index.js +0 -515
- package/src/ImageCanvas/index.story.js +0 -314
- package/src/ImageCanvas/mouse_mask.story.png +0 -0
- package/src/ImageCanvas/region-tools.js +0 -171
- package/src/ImageCanvas/seves_desk.story.jpg +0 -0
- package/src/ImageCanvas/use-mouse.js +0 -168
- package/src/ImageCanvas/use-project-box.js +0 -23
- package/src/ImageCanvas/use-wasd-mode.js +0 -50
- package/src/ImageMask/index.js +0 -127
- package/src/ImageMask/load-image.js +0 -32
- package/src/ImageSelectorSidebarBox/index.js +0 -54
- package/src/KeyframeTimeline/get-time-string.js +0 -25
- package/src/KeyframeTimeline/index.js +0 -223
- package/src/KeyframesSelectorSidebarBox/index.js +0 -93
- package/src/LandingPage/content.md +0 -57
- package/src/LandingPage/github-markdown.css +0 -964
- package/src/LandingPage/index.js +0 -147
- package/src/Locker/index.js +0 -13
- package/src/MainLayout/RightSidebarItemsWrapper.js +0 -21
- package/src/MainLayout/icon-dictionary.js +0 -79
- package/src/MainLayout/index.js +0 -564
- package/src/MainLayout/index.story.js +0 -240
- package/src/MainLayout/types.js +0 -171
- package/src/MainLayout/use-implied-video-regions.js +0 -17
- package/src/MetadataEditorSidebarBox/index.js +0 -160
- package/src/PageSelector/index.js +0 -159
- package/src/PointDistances/index.js +0 -90
- package/src/PreventScrollToParents/index.js +0 -48
- package/src/PreventScrollToParents/index.story.js +0 -23
- package/src/RegionLabel/index.js +0 -236
- package/src/RegionSelectAndTransformBoxes/index.js +0 -236
- package/src/RegionSelectorSidebarBox/index.js +0 -220
- package/src/RegionShapes/index.js +0 -254
- package/src/RegionTags/index.js +0 -136
- package/src/SettingsDialog/index.js +0 -58
- package/src/SettingsProvider/index.js +0 -57
- package/src/Shortcuts/ShortcutField.js +0 -44
- package/src/Shortcuts/index.js +0 -129
- package/src/ShortcutsManager/index.js +0 -162
- package/src/Sidebar/index.js +0 -117
- package/src/SidebarBoxContainer/index.js +0 -93
- package/src/SmallToolButton/index.js +0 -57
- package/src/TagsSidebarBox/index.js +0 -93
- package/src/TaskDescriptionSidebarBox/index.js +0 -43
- package/src/Theme/index.js +0 -36
- package/src/VideoOrImageCanvasBackground/index.js +0 -170
- package/src/colors.js +0 -32
- package/src/hooks/use-colors.js +0 -95
- package/src/hooks/use-event-callback.js +0 -11
- package/src/hooks/use-exclude-pattern.js +0 -27
- package/src/hooks/use-load-image.js +0 -21
- package/src/hooks/use-window-size.js +0 -46
- package/src/hooks/xpattern.png +0 -0
- package/src/index.js +0 -18
- package/src/lib.js +0 -7
- package/src/screenshot.png +0 -0
- package/src/site.css +0 -5
- package/src/stories.js +0 -2
- package/src/utils/blocks-to-article.js +0 -61
- package/src/utils/get-from-local-storage.js +0 -7
- package/src/utils/get-hotkey-help-text.js +0 -11
- package/src/utils/get-landmarks-with-transform.js +0 -23
- package/src/utils/photosToImages.js +0 -67
- package/src/utils/regions-groups.js +0 -19
- package/src/utils/regions-to-blocks.js +0 -16
- package/src/utils/saveable-actions-enum.js +0 -5
- package/src/utils/set-in-local-storage.js +0 -6
- package/src/utils/sleep.js +0 -3
- package/src/utils/uuid-to-hash.js +0 -5
- /package/{src/Editor → Editor}/annotation-plugin/annotation.css +0 -0
- /package/{src/Errorer → Errorer}/errorer.css +0 -0
- /package/{src/Locker → Locker}/locker.css +0 -0
- /package/{src/PageSelector → PageSelector}/page-selector.css +0 -0
- /package/{src/utils → utils}/next-group-id.js +0 -0
package/src/Annotator/index.js
DELETED
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
Action,
|
|
5
|
-
Image,
|
|
6
|
-
MainLayoutState,
|
|
7
|
-
Mode,
|
|
8
|
-
ToolEnum,
|
|
9
|
-
Metadata,
|
|
10
|
-
MetadataConfig
|
|
11
|
-
} from "../MainLayout/types"
|
|
12
|
-
import React, { useCallback, useEffect, useReducer } from "react"
|
|
13
|
-
import makeImmutable, { without } from "seamless-immutable"
|
|
14
|
-
import intersection from "lodash/intersection"
|
|
15
|
-
import type { KeypointsDefinition } from "../ImageCanvas/region-tools"
|
|
16
|
-
import MainLayout from "../MainLayout"
|
|
17
|
-
import type { Node } from "react"
|
|
18
|
-
import SettingsProvider from "../SettingsProvider"
|
|
19
|
-
import combineReducers from "./reducers/combine-reducers.js"
|
|
20
|
-
import generalReducer from "./reducers/general-reducer.js"
|
|
21
|
-
import getFromLocalStorage from "../utils/get-from-local-storage"
|
|
22
|
-
import historyHandler from "./reducers/history-handler.js"
|
|
23
|
-
import imageReducer from "./reducers/image-reducer.js"
|
|
24
|
-
import useEventCallback from "use-event-callback"
|
|
25
|
-
import videoReducer from "./reducers/video-reducer.js"
|
|
26
|
-
import { reacalcActionsEnum } from "../utils/saveable-actions-enum"
|
|
27
|
-
import sleep from '../utils/sleep';
|
|
28
|
-
|
|
29
|
-
type Props = {
|
|
30
|
-
taskDescription?: string,
|
|
31
|
-
help?: string,
|
|
32
|
-
allowedArea?: { x: number, y: number, w: number, h: number },
|
|
33
|
-
regionTagList?: Array<string>,
|
|
34
|
-
regionClsList?: Array<string>,
|
|
35
|
-
imageTagList?: Array<string>,
|
|
36
|
-
imageClsList?: Array<string>,
|
|
37
|
-
enabledTools?: Array<string>,
|
|
38
|
-
selectedTool?: String,
|
|
39
|
-
showTags?: boolean,
|
|
40
|
-
selectedImage?: string | number,
|
|
41
|
-
images?: Array<Image>,
|
|
42
|
-
showPointDistances?: boolean,
|
|
43
|
-
pointDistancePrecision?: number,
|
|
44
|
-
RegionEditLabel?: Node,
|
|
45
|
-
onExit: (MainLayoutState) => any,
|
|
46
|
-
videoTime?: number,
|
|
47
|
-
videoSrc?: string,
|
|
48
|
-
keyframes?: Object,
|
|
49
|
-
videoName?: string,
|
|
50
|
-
keypointDefinitions: KeypointsDefinition,
|
|
51
|
-
fullImageSegmentationMode?: boolean,
|
|
52
|
-
autoSegmentationOptions?:
|
|
53
|
-
| {| type: "simple" |}
|
|
54
|
-
| {| type: "autoseg", maxClusters ?: number, slicWeightFactor ?: number |},
|
|
55
|
-
hideHeader ?: boolean,
|
|
56
|
-
hideHeaderText ?: boolean,
|
|
57
|
-
hideNext ?: boolean,
|
|
58
|
-
hidePrev ?: boolean,
|
|
59
|
-
hideClone ?: boolean,
|
|
60
|
-
hideSettings ?: boolean,
|
|
61
|
-
hideFullScreen ?: boolean,
|
|
62
|
-
hideSave ?: boolean,
|
|
63
|
-
onImagesChange ?: (any) => any,
|
|
64
|
-
groups ?: Array < any >,
|
|
65
|
-
onGroupSelect ?: (any) => any,
|
|
66
|
-
hideHistory ?: boolean,
|
|
67
|
-
hideNotEditingLabel ?: boolean,
|
|
68
|
-
showEditor ?: boolean,
|
|
69
|
-
showPageSelector ?: boolean,
|
|
70
|
-
clsColors ?: Object,
|
|
71
|
-
groupColors ?: Array < string >,
|
|
72
|
-
onSelectedImageChange ?: (any) => any,
|
|
73
|
-
albumMetadata ?: Array < Metadata >,
|
|
74
|
-
metadataConfigs ? : Array < MetadataConfig >,
|
|
75
|
-
save : (any) => any,
|
|
76
|
-
fetchImage : (any) => any,
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const Annotator = ({
|
|
80
|
-
images,
|
|
81
|
-
allowedArea,
|
|
82
|
-
selectedImage = images && images.length > 0 ? 0 : undefined,
|
|
83
|
-
showPointDistances,
|
|
84
|
-
pointDistancePrecision,
|
|
85
|
-
showTags = getFromLocalStorage("showTags", true),
|
|
86
|
-
enabledTools = [
|
|
87
|
-
"select",
|
|
88
|
-
"create-point",
|
|
89
|
-
"create-box",
|
|
90
|
-
"create-polygon",
|
|
91
|
-
"create-line",
|
|
92
|
-
"create-expanding-line",
|
|
93
|
-
"show-mask",
|
|
94
|
-
],
|
|
95
|
-
selectedTool = "select",
|
|
96
|
-
regionTagList = [],
|
|
97
|
-
regionClsList = [],
|
|
98
|
-
imageTagList = [],
|
|
99
|
-
imageClsList = [],
|
|
100
|
-
keyframes = {},
|
|
101
|
-
taskDescription = "",
|
|
102
|
-
help = "",
|
|
103
|
-
fullImageSegmentationMode = false,
|
|
104
|
-
RegionEditLabel,
|
|
105
|
-
videoSrc,
|
|
106
|
-
videoTime = 0,
|
|
107
|
-
videoName,
|
|
108
|
-
onExit,
|
|
109
|
-
onNextImage,
|
|
110
|
-
onPrevImage,
|
|
111
|
-
keypointDefinitions,
|
|
112
|
-
autoSegmentationOptions = { type: "autoseg" },
|
|
113
|
-
hideHeader,
|
|
114
|
-
hideHeaderText,
|
|
115
|
-
hideNext,
|
|
116
|
-
hidePrev,
|
|
117
|
-
hideClone,
|
|
118
|
-
hideSettings,
|
|
119
|
-
hideFullScreen,
|
|
120
|
-
hideSave,
|
|
121
|
-
allowComments,
|
|
122
|
-
onImagesChange,
|
|
123
|
-
groups,
|
|
124
|
-
onGroupSelect,
|
|
125
|
-
hideHistory,
|
|
126
|
-
hideNotEditingLabel,
|
|
127
|
-
showEditor,
|
|
128
|
-
showPageSelector,
|
|
129
|
-
clsColors = {},
|
|
130
|
-
groupColors,
|
|
131
|
-
onSelectedImageChange,
|
|
132
|
-
albumMetadata,
|
|
133
|
-
metadataConfigs,
|
|
134
|
-
save = () => { },
|
|
135
|
-
fetchImage = () => { },
|
|
136
|
-
}: Props) => {
|
|
137
|
-
if (typeof selectedImage === "string") {
|
|
138
|
-
selectedImage = (images || []).findIndex((img) => img.src === selectedImage)
|
|
139
|
-
if (selectedImage === -1) selectedImage = undefined
|
|
140
|
-
}
|
|
141
|
-
const annotationType = images ? "image" : "video"
|
|
142
|
-
const [state, dispatchToReducer] = useReducer(
|
|
143
|
-
historyHandler(
|
|
144
|
-
combineReducers(
|
|
145
|
-
annotationType === "image" ? imageReducer : videoReducer,
|
|
146
|
-
generalReducer
|
|
147
|
-
)
|
|
148
|
-
),
|
|
149
|
-
makeImmutable({
|
|
150
|
-
annotationType,
|
|
151
|
-
showTags,
|
|
152
|
-
allowedArea,
|
|
153
|
-
showPointDistances,
|
|
154
|
-
pointDistancePrecision,
|
|
155
|
-
selectedTool,
|
|
156
|
-
fullImageSegmentationMode: fullImageSegmentationMode,
|
|
157
|
-
autoSegmentationOptions,
|
|
158
|
-
mode: null,
|
|
159
|
-
taskDescription,
|
|
160
|
-
help,
|
|
161
|
-
showMask: true,
|
|
162
|
-
labelImages: imageClsList.length > 0 || imageTagList.length > 0,
|
|
163
|
-
regionClsList,
|
|
164
|
-
regionTagList,
|
|
165
|
-
imageClsList,
|
|
166
|
-
imageTagList,
|
|
167
|
-
currentVideoTime: videoTime,
|
|
168
|
-
enabledTools,
|
|
169
|
-
history: [],
|
|
170
|
-
videoName,
|
|
171
|
-
keypointDefinitions,
|
|
172
|
-
allowComments,
|
|
173
|
-
...(annotationType === "image"
|
|
174
|
-
? {
|
|
175
|
-
selectedImage,
|
|
176
|
-
images,
|
|
177
|
-
selectedImageFrameTime:
|
|
178
|
-
images && images.length > 0 ? images[0].frameTime : undefined,
|
|
179
|
-
}
|
|
180
|
-
: {
|
|
181
|
-
videoSrc,
|
|
182
|
-
keyframes,
|
|
183
|
-
}),
|
|
184
|
-
imagesUpdatedAt: null,
|
|
185
|
-
imagesSavedAt: null,
|
|
186
|
-
albumMetadata,
|
|
187
|
-
metadataConfigs,
|
|
188
|
-
toPollImages: [...images.filter(i => i.lockedUntil).map(i => i.id)],
|
|
189
|
-
toSaveImage: null,
|
|
190
|
-
})
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
const dispatch = useEventCallback((action: Action) => {
|
|
194
|
-
if (action.type === "HEADER_BUTTON_CLICKED") {
|
|
195
|
-
if (["Exit", "Done", "Save", "Complete"].includes(action.buttonName)) {
|
|
196
|
-
return onExit(without(state, "history"))
|
|
197
|
-
} else if (action.buttonName === "Next" && onNextImage) {
|
|
198
|
-
return onNextImage(without(state, "history"))
|
|
199
|
-
} else if (action.buttonName === "Prev" && onPrevImage) {
|
|
200
|
-
return onPrevImage(without(state, "history"))
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
dispatchToReducer(action)
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
const onRegionClassAdded = useEventCallback((cls) => {
|
|
207
|
-
dispatchToReducer({
|
|
208
|
-
type: "ON_CLS_ADDED",
|
|
209
|
-
cls: cls,
|
|
210
|
-
})
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
const handleMetadataChange = (params) => {
|
|
214
|
-
dispatchToReducer({
|
|
215
|
-
type: "UPDATE_METADATA",
|
|
216
|
-
...params
|
|
217
|
-
})
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const handleAddGroup = (group) => {
|
|
221
|
-
dispatchToReducer({
|
|
222
|
-
type: "ADD_GROUP",
|
|
223
|
-
group
|
|
224
|
-
})
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const handleRecalcClicked = useCallback(({ imageId }) => {
|
|
228
|
-
dispatchToReducer({
|
|
229
|
-
type: "RECALC_CLICKED",
|
|
230
|
-
imageId
|
|
231
|
-
})
|
|
232
|
-
}, [dispatchToReducer])
|
|
233
|
-
|
|
234
|
-
// detect on page change if anything changed, if so trigger save and recalc
|
|
235
|
-
useEffect(() => {
|
|
236
|
-
const { selectedImage, previouslySelectedImage, lastAction } = state;
|
|
237
|
-
if (lastAction?.type === 'SELECT_IMAGE' && selectedImage !== previouslySelectedImage) {
|
|
238
|
-
// save if previously selected image has any changes
|
|
239
|
-
if (state.images[previouslySelectedImage]?.saveableActions?.length > 0) {
|
|
240
|
-
// decide wheather recalc is needed
|
|
241
|
-
const triggerRecalc = intersection(reacalcActionsEnum, state.images[previouslySelectedImage].saveableActions).length > 0;
|
|
242
|
-
|
|
243
|
-
// decide whether album metadata should be updated
|
|
244
|
-
let toSaveMetadata = [];
|
|
245
|
-
if (state.images[previouslySelectedImage]?.saveableActions?.includes("UPDATE_ALBUM_METADATA")) {
|
|
246
|
-
toSaveMetadata = state.albumMetadata
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// set this image to be saved
|
|
250
|
-
dispatchToReducer({
|
|
251
|
-
type: "SAVE_IMAGE",
|
|
252
|
-
image: { ...state.images[previouslySelectedImage] },
|
|
253
|
-
triggerRecalc,
|
|
254
|
-
toSaveMetadata
|
|
255
|
-
})
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}, [state.previouslySelectedImage, state.selectedImage, state.images, state, save])
|
|
259
|
-
|
|
260
|
-
// handle save of image
|
|
261
|
-
useEffect(() => {
|
|
262
|
-
if (state.toSaveImage !== null) {
|
|
263
|
-
// metadata on album level
|
|
264
|
-
const saveHandler = async (image, triggerRecalc, albumMetadata) => {
|
|
265
|
-
dispatchToReducer({
|
|
266
|
-
type: "IMAGE_UPDATE_INIT",
|
|
267
|
-
imageId: image.id
|
|
268
|
-
})
|
|
269
|
-
|
|
270
|
-
try {
|
|
271
|
-
const { lockedUntil } = await save({ image, triggerRecalc, albumMetadata });
|
|
272
|
-
dispatchToReducer({
|
|
273
|
-
type: "IMAGE_UPDATE_SUCCESS",
|
|
274
|
-
imageId: image.id,
|
|
275
|
-
lockedUntil,
|
|
276
|
-
})
|
|
277
|
-
} catch (error) {
|
|
278
|
-
dispatchToReducer({
|
|
279
|
-
type: "IMAGE_UPDATE_FAIL",
|
|
280
|
-
imageId: image.id,
|
|
281
|
-
error,
|
|
282
|
-
})
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const { image, triggerRecalc, toSaveMetadata } = state.toSaveImage;
|
|
287
|
-
saveHandler(image, triggerRecalc, toSaveMetadata);
|
|
288
|
-
}
|
|
289
|
-
}, [save, state.toSaveImage])
|
|
290
|
-
|
|
291
|
-
// polling of images
|
|
292
|
-
useEffect(() => {
|
|
293
|
-
if (state.toPollImages.length > 0) {
|
|
294
|
-
const polledImages = state.toPollImages.reduce((acc, imageId) => {
|
|
295
|
-
|
|
296
|
-
async function pollImage(fetchImage, imageId, tries = 5) {
|
|
297
|
-
if (tries === 0) {
|
|
298
|
-
dispatchToReducer({
|
|
299
|
-
type: "IMAGE_POLL_TIMEOUT",
|
|
300
|
-
imageId,
|
|
301
|
-
})
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const { image } = await fetchImage({ imageId });
|
|
306
|
-
if (!image.lockedUntil) {
|
|
307
|
-
dispatchToReducer({
|
|
308
|
-
type: "IMAGE_POLL_SUCCESS",
|
|
309
|
-
image,
|
|
310
|
-
})
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
await sleep(5000);
|
|
315
|
-
|
|
316
|
-
return await pollImage(fetchImage, imageId, tries - 1);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// make recursive calling of polling function
|
|
320
|
-
pollImage(fetchImage, imageId, 10);
|
|
321
|
-
|
|
322
|
-
return imageId;
|
|
323
|
-
}, [])
|
|
324
|
-
|
|
325
|
-
dispatchToReducer({
|
|
326
|
-
type: "IMAGE_POLL_INIT",
|
|
327
|
-
imageIds: polledImages
|
|
328
|
-
})
|
|
329
|
-
}
|
|
330
|
-
}, [fetchImage, state.toPollImages])
|
|
331
|
-
|
|
332
|
-
useEffect(() => {
|
|
333
|
-
if (selectedImage === undefined) return
|
|
334
|
-
dispatchToReducer({
|
|
335
|
-
type: "SELECT_IMAGE",
|
|
336
|
-
imageIndex: selectedImage,
|
|
337
|
-
image: state.images[selectedImage],
|
|
338
|
-
})
|
|
339
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
340
|
-
}, [onImagesChange, selectedImage])
|
|
341
|
-
|
|
342
|
-
if (!images && !videoSrc)
|
|
343
|
-
return 'Missing required prop "images" or "videoSrc"'
|
|
344
|
-
|
|
345
|
-
const [recalcActive, saveActive] = state.imagesSavedAt < state.imagesUpdatedAt ? [true, true] : [false, false];
|
|
346
|
-
|
|
347
|
-
return (
|
|
348
|
-
<SettingsProvider clsColors={clsColors} groupColors={groupColors}>
|
|
349
|
-
<MainLayout
|
|
350
|
-
RegionEditLabel={RegionEditLabel}
|
|
351
|
-
alwaysShowNextButton={Boolean(onNextImage)}
|
|
352
|
-
alwaysShowPrevButton={Boolean(onPrevImage)}
|
|
353
|
-
state={state}
|
|
354
|
-
dispatch={dispatch}
|
|
355
|
-
onRegionClassAdded={onRegionClassAdded}
|
|
356
|
-
hideHeader={hideHeader}
|
|
357
|
-
hideHeaderText={hideHeaderText}
|
|
358
|
-
hideNext={hideNext}
|
|
359
|
-
hidePrev={hidePrev}
|
|
360
|
-
hideClone={hideClone}
|
|
361
|
-
hideSettings={hideSettings}
|
|
362
|
-
hideFullScreen={hideFullScreen}
|
|
363
|
-
hideSave={hideSave}
|
|
364
|
-
groups={groups}
|
|
365
|
-
onGroupSelect={onGroupSelect}
|
|
366
|
-
hideHistory={hideHistory}
|
|
367
|
-
hideNotEditingLabel={hideNotEditingLabel}
|
|
368
|
-
showEditor={showEditor}
|
|
369
|
-
showPageSelector={showPageSelector}
|
|
370
|
-
saveActive={recalcActive}
|
|
371
|
-
recalcActive={saveActive}
|
|
372
|
-
onMetadataChange={handleMetadataChange}
|
|
373
|
-
onAddGroup={handleAddGroup}
|
|
374
|
-
onRecalcClick={handleRecalcClicked}
|
|
375
|
-
/>
|
|
376
|
-
</SettingsProvider>
|
|
377
|
-
)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export default Annotator
|