Skip to content

Commit d087f03

Browse files
committed
Merge branch 'master' of github.com:waoai/react-image-annotate
2 parents a303317 + af7266b commit d087f03

File tree

9 files changed

+22302
-12
lines changed

9 files changed

+22302
-12
lines changed

package-lock.json

Lines changed: 22203 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"react-remove-scroll": "^2.0.4",
1818
"react-select": "^2.2.0",
1919
"react-syntax-highlighter": "^12.2.1",
20+
"react-use": "^13.26.3",
2021
"seamless-immutable": "^7.1.4",
2122
"transformation-matrix-js": "^2.7.6",
2223
"use-key-hook": "^1.3.0"

src/Annotator/index.story.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ storiesOf("Annotator", module)
337337
</div>
338338
))
339339
.add("Annotator should not expand beyond parent", () => (
340-
<div style={{ width: "100vw", height: "100vh", padding: 100 }}>
340+
<div
341+
style={{
342+
width: "100vw",
343+
height: "100vh",
344+
padding: 100,
345+
boxSizing: "border-box"
346+
}}
347+
>
341348
<Annotator
342349
onExit={actionAddon("onExit")}
343350
showTags={false}
@@ -355,6 +362,5 @@ storiesOf("Annotator", module)
355362
}
356363
]}
357364
/>
358-
<div style={{ color: "red" }}>You shouldn't be able to see this</div>
359365
</div>
360366
))

src/Annotator/reducer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ export default (state: MainLayoutState, action: Action) => {
285285
xFree === 0
286286
? ow
287287
: xFree === -1
288-
? ow + (ox - dx)
289-
: Math.max(0, ow + (x - ox - ow))
288+
? ow + (ox - dx)
289+
: Math.max(0, ow + (x - ox - ow))
290290
const dy = yFree === 0 ? oy : yFree === -1 ? Math.min(oy + oh, y) : oy
291291
const dh =
292292
yFree === 0
293293
? oh
294294
: yFree === -1
295-
? oh + (oy - dy)
296-
: Math.max(0, oh + (y - oy - oh))
295+
? oh + (oy - dy)
296+
: Math.max(0, oh + (y - oy - oh))
297297

298298
// determine if we should switch the freedom
299299
if (dw <= 0.001) {

src/Fullscreen/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @flow
2+
3+
import React from "react"
4+
import Fullscreen from "react-full-screen"
5+
6+
export default props => {
7+
if (!props.enabled) return props.children
8+
return <Fullscreen {...props}>{props.children}</Fullscreen>
9+
}

src/ImageCanvas/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// @flow
2-
import React, { Fragment, useRef, useState, useLayoutEffect } from "react"
2+
import React, {
3+
Fragment,
4+
useRef,
5+
useState,
6+
useLayoutEffect,
7+
useEffect
8+
} from "react"
39
import { Matrix } from "transformation-matrix-js"
410
import getImageData from "get-image-data"
511
import Crosshairs from "../Crosshairs"
@@ -21,6 +27,7 @@ import HighlightBox from "../HighlightBox"
2127
// import excludePatternSrc from "./xpattern.png"
2228
import excludePatternSrc from "./xpattern.js"
2329
import PreventScrollToParents from "../PreventScrollToParents"
30+
import useWindowSize from "../hooks/use-window-size.js"
2431

2532
const useStyles = makeStyles(styles)
2633

@@ -30,6 +37,14 @@ const boxCursorMap = [
3037
["sw-resize", "s-resize", "se-resize"]
3138
]
3239

40+
const copyWithout = (obj, ...args) => {
41+
const newObj = { ...obj }
42+
for (const arg of args) {
43+
delete newObj[arg]
44+
}
45+
return newObj
46+
}
47+
3348
type Props = {
3449
regions: Array<Region>,
3550
imageSrc: string,
@@ -106,6 +121,11 @@ export default ({
106121
const prevMousePosition = useRef({ x: 0, y: 0 })
107122
const [mat, changeMat] = useState(getDefaultMat())
108123
const maskImages = useRef({})
124+
const windowSize = useWindowSize()
125+
126+
useLayoutEffect(() => {
127+
changeMat(mat.clone())
128+
}, [windowSize])
109129

110130
const innerMousePos = mat.applyToPoint(
111131
mousePosition.current.x,
@@ -720,7 +740,9 @@ export default ({
720740
left: 0,
721741
...(displayOnTop ? { bottom: 0 } : { top: 0 })
722742
}}
723-
{...(!region.editingLabels ? mouseEvents : {})}
743+
{...(!region.editingLabels
744+
? copyWithout(mouseEvents, "onMouseDown", "onMouseUp")
745+
: {})}
724746
>
725747
<RegionLabel
726748
allowedClasses={regionClsList}

src/MainLayout/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import useKey from "use-key-hook"
1313
import classnames from "classnames"
1414
import { useSettings } from "../SettingsProvider"
1515
import SettingsDialog from "../SettingsDialog"
16-
import Fullscreen from "react-full-screen"
16+
import Fullscreen from "../Fullscreen"
1717

1818
const useStyles = makeStyles(styles)
1919

src/MainLayout/styles.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
display: "flex",
66
flexGrow: 1,
77
flexDirection: "column",
8-
minHeight: "100%",
8+
height: "100%",
99
maxHeight: "100vh",
1010
backgroundColor: "#fff",
1111
overflow: "hidden",
@@ -22,7 +22,9 @@ export default {
2222
backgroundColor: grey[200],
2323
flexGrow: 1,
2424
display: "flex",
25-
flexDirection: "row"
25+
flexDirection: "row",
26+
height: "100%",
27+
overflow: "hidden"
2628
},
2729
iconToolsContainer: { display: "flex" },
2830
imageCanvasContainer: {
@@ -38,11 +40,12 @@ export default {
3840
},
3941
sidebarContainer: {
4042
width: 300,
43+
flexShrink: 0,
4144
overflowY: "auto",
4245
backgroundColor: grey[100],
4346
borderLeft: `1px solid ${grey[300]}`,
4447
zIndex: 9,
45-
maxHeight: "calc(100% - 68px)",
48+
height: "100%",
4649
boxShadow: "0px 0px 5px rgba(0,0,0,0.1)"
4750
}
4851
}

src/hooks/use-window-size.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// @flow
2+
3+
import { useEffect } from "react"
4+
5+
import { useRafState, useInterval } from "react-use"
6+
7+
const useWindowSize = (initialWidth = Infinity, initialHeight = Infinity) => {
8+
const isClient = typeof window !== "undefined"
9+
const [state, setState] = useRafState({
10+
width: isClient ? window.innerWidth : initialWidth,
11+
height: isClient ? window.innerHeight : initialHeight
12+
})
13+
14+
useEffect(() => {
15+
if (!isClient) return
16+
const handler = () => {
17+
setState({
18+
width: window.innerWidth,
19+
height: window.innerHeight
20+
})
21+
}
22+
23+
window.addEventListener("resize", handler)
24+
25+
return () => {
26+
window.removeEventListener("resize", handler)
27+
}
28+
}, [])
29+
30+
useInterval(() => {
31+
if (!isClient) return
32+
if (
33+
window.innerWidth !== state.width ||
34+
window.innerHeight !== state.height
35+
) {
36+
setState({
37+
width: window.innerWidth,
38+
height: window.innerHeight
39+
})
40+
}
41+
}, 100)
42+
43+
return state
44+
}
45+
46+
export default useWindowSize

0 commit comments

Comments
 (0)