Skip to content

Commit f5efbac

Browse files
committed
Create new annotation - add textarea box
1 parent 4a23700 commit f5efbac

File tree

6 files changed

+247
-251
lines changed

6 files changed

+247
-251
lines changed

src/components/pdf-highlighter/PDFHighlighter.jsx

+13-44
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { cloneElement } from 'react'
22
import ReactDom from 'react-dom'
3-
import throttle from 'utils/throttle'
43
import { getPageFromRange } from 'components/pdf-highlighter/utils/utils'
54
import { groupRectsByPage } from 'components/pdf-highlighter/utils/rects'
65
import withAppContext from 'store/withAppContext'
@@ -17,33 +16,20 @@ class PDFHighlighter extends React.Component {
1716
position: {
1817
left: null,
1918
top: null,
19+
height: null,
2020
},
2121
annotationId: null,
2222
selectedText: '',
2323
}
2424

2525
componentDidMount() {
26-
document.addEventListener('selectionchange', this.onSelectionChange)
27-
document.addEventListener('mouseup', this.onAfterSelection.bind(this))
26+
window.addEventListener('mouseup', this.onAfterSelection.bind(this))
2827
}
2928

3029
componentWillUnmount() {
31-
document.removeEventListener('mouseup', this.onAfterSelection)
30+
window.removeEventListener('mouseup', this.onAfterSelection)
3231
}
3332

34-
onSelectionChange = () => {
35-
const selection = window.getSelection()
36-
37-
// no text was selected
38-
// https://developer.mozilla.org/en-US/docs/Web/API/Selection/isCollapsed
39-
if (selection.isCollapsed) {
40-
this.setState({
41-
isVisible: false,
42-
})
43-
}
44-
}
45-
46-
@throttle(250)
4733
onAfterSelection() {
4834
const {
4935
state: {
@@ -97,32 +83,11 @@ class PDFHighlighter extends React.Component {
9783
})
9884
}
9985

100-
onUpdateContextMenu = ({
101-
isVisible,
102-
left,
103-
top,
104-
annotationId,
105-
contextRoot,
106-
width,
107-
height,
108-
}) => {
109-
if (!isVisible) {
110-
this.setState({ isVisible })
111-
return
112-
}
113-
114-
const pdfRect = contextRoot.getBoundingClientRect()
115-
116-
this.setState({
117-
isVisible,
118-
position: {
119-
left: `${((left + width / 2) * 100) / pdfRect.width}%`,
120-
top: `${(top * 100) / pdfRect.height}%`,
121-
height: `${height}px`,
122-
},
123-
annotationId,
124-
contextRoot,
125-
})
86+
onUpdateContextMenu = partialUpdate => {
87+
this.setState(state => ({
88+
...state,
89+
...partialUpdate,
90+
}))
12691
}
12792

12893
render() {
@@ -151,14 +116,18 @@ class PDFHighlighter extends React.Component {
151116
height={height}
152117
selectedText={selectedText}
153118
annotationId={annotationId}
119+
updateContextMenu={this.onUpdateContextMenu}
154120
/>,
155121
contextRoot
156122
)
157123

158124
return (
159125
<>
160126
{contextRoot && contextMenu}
161-
<Highlights updateContextMenu={this.onUpdateContextMenu} />
127+
<Highlights
128+
updateContextMenu={this.onUpdateContextMenu}
129+
currentAnnotationId={annotationId}
130+
/>
162131
{children}
163132
</>
164133
)

src/components/pdf-highlighter/PDFHighlighter.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ $HIGHLIGHT_COLORS: (
6464
}
6565

6666
.highlights-layer {
67-
> span {
67+
> button {
6868
position: absolute;
69+
border-radius: 0;
6970
}
7071

7172
.highlight {

0 commit comments

Comments
 (0)