@searpent/react-image-annotate 2.0.0 → 2.0.1
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/package.json +1 -1
- package/src/Annotator/index.js +24 -19
- package/src/Annotator/index.story.js +31 -0
package/package.json
CHANGED
package/src/Annotator/index.js
CHANGED
|
@@ -45,16 +45,17 @@ type Props = {
|
|
|
45
45
|
keypointDefinitions: KeypointsDefinition,
|
|
46
46
|
fullImageSegmentationMode?: boolean,
|
|
47
47
|
autoSegmentationOptions?:
|
|
48
|
-
|
|
49
|
-
| {| type: "autoseg", maxClusters?: number, slicWeightFactor?: number |},
|
|
50
|
-
|
|
51
|
-
hideHeaderText?: boolean,
|
|
52
|
-
hideNext?: boolean,
|
|
53
|
-
hidePrev?: boolean,
|
|
54
|
-
hideClone?: boolean,
|
|
55
|
-
hideSettings?: boolean,
|
|
56
|
-
hideFullScreen?: boolean,
|
|
57
|
-
hideSave?: boolean,
|
|
48
|
+
| {| type: "simple" |}
|
|
49
|
+
| {| type: "autoseg", maxClusters ?: number, slicWeightFactor ?: number |},
|
|
50
|
+
hideHeader ?: boolean,
|
|
51
|
+
hideHeaderText ?: boolean,
|
|
52
|
+
hideNext ?: boolean,
|
|
53
|
+
hidePrev ?: boolean,
|
|
54
|
+
hideClone ?: boolean,
|
|
55
|
+
hideSettings ?: boolean,
|
|
56
|
+
hideFullScreen ?: boolean,
|
|
57
|
+
hideSave ?: boolean,
|
|
58
|
+
onImagesChange ?: (any) => any,
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
export const Annotator = ({
|
|
@@ -99,6 +100,7 @@ export const Annotator = ({
|
|
|
99
100
|
hideFullScreen,
|
|
100
101
|
hideSave,
|
|
101
102
|
allowComments,
|
|
103
|
+
onImagesChange,
|
|
102
104
|
}: Props) => {
|
|
103
105
|
if (typeof selectedImage === "string") {
|
|
104
106
|
selectedImage = (images || []).findIndex((img) => img.src === selectedImage)
|
|
@@ -137,15 +139,15 @@ export const Annotator = ({
|
|
|
137
139
|
allowComments,
|
|
138
140
|
...(annotationType === "image"
|
|
139
141
|
? {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
selectedImage,
|
|
143
|
+
images,
|
|
144
|
+
selectedImageFrameTime:
|
|
145
|
+
images && images.length > 0 ? images[0].frameTime : undefined,
|
|
146
|
+
}
|
|
145
147
|
: {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
videoSrc,
|
|
149
|
+
keyframes,
|
|
150
|
+
}),
|
|
149
151
|
})
|
|
150
152
|
)
|
|
151
153
|
|
|
@@ -170,13 +172,16 @@ export const Annotator = ({
|
|
|
170
172
|
})
|
|
171
173
|
|
|
172
174
|
useEffect(() => {
|
|
175
|
+
if (onImagesChange) {
|
|
176
|
+
onImagesChange({ selectedImage, images: state.images })
|
|
177
|
+
}
|
|
173
178
|
if (selectedImage === undefined) return
|
|
174
179
|
dispatchToReducer({
|
|
175
180
|
type: "SELECT_IMAGE",
|
|
176
181
|
imageIndex: selectedImage,
|
|
177
182
|
image: state.images[selectedImage],
|
|
178
183
|
})
|
|
179
|
-
}, [selectedImage, state.images])
|
|
184
|
+
}, [onImagesChange, selectedImage, state.images])
|
|
180
185
|
|
|
181
186
|
if (!images && !videoSrc)
|
|
182
187
|
return 'Missing required prop "images" or "videoSrc"'
|
|
@@ -52,6 +52,37 @@ storiesOf("Annotator", module)
|
|
|
52
52
|
]}
|
|
53
53
|
/>
|
|
54
54
|
))
|
|
55
|
+
.add("Basic with onImagesChange", () => (
|
|
56
|
+
<Annotator
|
|
57
|
+
onExit={actionAddon("onExit")}
|
|
58
|
+
middlewares={middlewares}
|
|
59
|
+
labelImages
|
|
60
|
+
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
|
|
61
|
+
regionTagList={["tag1", "tag2", "tag3"]}
|
|
62
|
+
imageClsList={["Alpha", "Beta", "Charlie", "Delta"]}
|
|
63
|
+
imageTagList={["tag1", "tag2", "tag3"]}
|
|
64
|
+
onImagesChange={(images) => console.log("images changed to:", images)}
|
|
65
|
+
images={[
|
|
66
|
+
{
|
|
67
|
+
src: exampleImage,
|
|
68
|
+
name: "Seve's Desk",
|
|
69
|
+
regions: testRegions,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
src: "https://loremflickr.com/100/100/cars?lock=1",
|
|
73
|
+
name: "Frame 0036",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
src: "https://loremflickr.com/100/100/cars?lock=2",
|
|
77
|
+
name: "Frame 0037",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
src: "https://loremflickr.com/100/100/cars?lock=3",
|
|
81
|
+
name: "Frame 0038",
|
|
82
|
+
},
|
|
83
|
+
]}
|
|
84
|
+
/>
|
|
85
|
+
))
|
|
55
86
|
.add("Basic - Allow Comments", () => (
|
|
56
87
|
<Annotator
|
|
57
88
|
onExit={actionAddon("onExit")}
|