1
1
import * as React from 'react' ;
2
+ import { useState } from 'react'
2
3
import { Viewer , Worker , Popover , Position , Tooltip } from '@react-pdf-viewer/core' ;
3
4
import { defaultLayoutPlugin } from '@react-pdf-viewer/default-layout' ;
4
5
import { searchPlugin } from '@react-pdf-viewer/search' ;
6
+ import SelectionHandler from './SelectionHandler' ;
7
+ import PhraseForm from './PhraseForm'
5
8
6
9
// Import styles
7
10
import '@react-pdf-viewer/search/lib/styles/index.css' ;
@@ -10,6 +13,19 @@ import '@react-pdf-viewer/core/lib/styles/index.css';
10
13
import '@react-pdf-viewer/default-layout/lib/styles/index.css' ;
11
14
12
15
const App = ( ) => {
16
+ const [ phrase , setPhrase ] = useState ( '' )
17
+ const [ context , setContext ] = useState ( '' )
18
+
19
+ const onSelectionChange = ( selection ) => {
20
+ setContext ( selection . anchorNode . data )
21
+ setPhrase ( selection . toString ( ) )
22
+ console . log ( selection ) ;
23
+ }
24
+
25
+ const onSavePhrase = ( phrase , context , meaning ) => {
26
+ console . log ( "here: " + phrase ) ;
27
+ setData ( [ ...data , phrase ] )
28
+ }
13
29
14
30
const renderHighlights = React . useCallback (
15
31
( renderProps ) => {
@@ -70,7 +86,7 @@ const App = () => {
70
86
71
87
72
88
73
- const data = [ 'Liberation' , 'National Security' , 'throughout' , 'Cybersecurity was by then already a hot topic' , 'conference' , 'This project' , 'should' , 'States' , 'Group' , 'Opening' , 'pdf' , 'example' , 'File' , 'includes' , 'content' , 'could' , 'new work' , 'Parameters' , 'agreement' ]
89
+ const [ data , setData ] = useState ( [ 'Liberation' , 'National Security' , 'throughout' , 'Cybersecurity was by then already a hot topic' , 'conference' , 'This project' , 'should' , 'States' , 'Group' , 'Opening' , 'pdf' , 'example' , 'File' , 'includes' , 'content' , 'could' , 'new work' , 'Parameters' , 'agreement' ] )
74
90
const searchPluginInstance = searchPlugin ( {
75
91
keyword : [
76
92
...data . map ( text => new RegExp ( text ) )
@@ -84,22 +100,46 @@ const App = () => {
84
100
85
101
const defaultLayoutPluginInstance = defaultLayoutPlugin ( ) ;
86
102
103
+
104
+ const styles = {
105
+ splitScreen : {
106
+ display : 'flex' ,
107
+ flexDirection : 'row' ,
108
+ } ,
109
+ topPane : {
110
+ width : '60%' ,
111
+ } ,
112
+ bottomPane : {
113
+ width : '40%' ,
114
+ } ,
115
+ }
116
+
117
+
87
118
return (
88
119
< Worker workerUrl = "https://unpkg.com/[email protected] /build/pdf.worker.js" >
89
- < div
90
- style = { {
91
- height : '750px' ,
92
- width : '900px' ,
93
- marginLeft : 'auto' ,
94
- marginRight : 'auto' ,
95
- } }
96
- >
97
- < Viewer
98
- fileUrl = { `${ process . env . PUBLIC_URL } /pdf-open-parameters.pdf` }
99
- plugins = { [ defaultLayoutPluginInstance , searchPluginInstance ] }
100
- />
120
+ < div style = { styles . splitScreen } >
121
+ < div style = { styles . topPane } >
122
+ < div
123
+ style = { {
124
+ height : '100vh' ,
125
+ // width: '900px',
126
+ marginLeft : 'auto' ,
127
+ marginRight : 'auto' ,
128
+ } }
129
+ >
130
+ < Viewer
131
+ fileUrl = { `${ process . env . PUBLIC_URL } /pdf-open-parameters.pdf` }
132
+ plugins = { [ defaultLayoutPluginInstance , searchPluginInstance ] }
133
+ />
134
+ < SelectionHandler phrase = { phrase } onSelectionChange = { onSelectionChange } />
135
+ </ div >
136
+ </ div >
137
+ < div style = { styles . bottomPane } >
138
+ < PhraseForm phrase = { phrase } context = { context } onSavePhrase = { onSavePhrase } />
139
+ </ div >
101
140
</ div >
102
141
</ Worker >
142
+
103
143
) ;
104
144
} ;
105
145
0 commit comments