@@ -31,7 +31,6 @@ import {
3131 StylesDialog ,
3232} from '@syncfusion/ej2-react-documenteditor' ;
3333import { DropDownButtonComponent , ItemModel } from '@syncfusion/ej2-react-splitbuttons' ;
34-
3534DocumentEditorComponent . Inject (
3635 Print ,
3736 SfdtExport ,
@@ -60,16 +59,14 @@ DocumentEditorComponent.Inject(
6059 CellOptionsDialog ,
6160 StylesDialog
6261) ;
63-
6462function App ( ) {
65- const documentEditorRef : DocumentEditorComponent = React . useRef ( null ) ;
66- const pageCountRef : any = React . useRef ( null ) ;
67- const editablePageNumberRef : any = React . useRef ( null ) ;
68- const pageNumberLabelRef : any = React . useRef ( null ) ;
69- const zoomRef : any = React . useRef ( null ) ;
63+ const documentEditorRef = React . useRef < DocumentEditorComponent | null > ( null ) ;
64+ const pageCountRef = React . useRef < HTMLLabelElement | null > ( null ) ;
65+ const editablePageNumberRef = React . useRef < HTMLDivElement | null > ( null ) ;
66+ const pageNumberLabelRef = React . useRef < HTMLLabelElement | null > ( null ) ;
67+ const zoomRef = React . useRef < DropDownButtonComponent | null > ( null ) ;
7068 let startPage = 1 ;
71- let editorPageCount : any ;
72-
69+ let editorPageCount : number ;
7370 const items : ItemModel [ ] = [
7471 { text : '200%' } ,
7572 { text : '175%' } ,
@@ -83,29 +80,24 @@ function App() {
8380 { text : 'Fit one page' } ,
8481 { text : 'Fit page width' } ,
8582 ] ;
86-
8783 React . useEffect ( ( ) => {
8884 const documenteditor = documentEditorRef . current ;
89-
9085 if ( documenteditor ) {
91- documenteditor . viewChange = ( e ) => updatePageNumberOnViewChange ( e ) ;
86+ documenteditor . viewChange = ( e : any ) => updatePageNumberOnViewChange ( e ) ;
9287 documenteditor . contentChange = ( ) => updatePageCount ( ) ;
93-
9488 if ( editablePageNumberRef . current ) {
9589 editablePageNumberRef . current . onclick = ( ) => updateDocumentEditorPageNumber ( ) ;
96- editablePageNumberRef . current . onkeydown = ( e ) => onKeyDown ( e ) ;
90+ editablePageNumberRef . current . onkeydown = ( e : any ) => onKeyDown ( e ) ;
9791 editablePageNumberRef . current . onblur = ( ) => onBlur ( ) ;
9892 }
99-
10093 updatePageCount ( ) ;
10194 updatePageNumber ( ) ;
10295 }
10396 } , [ ] ) ;
104-
10597 function updatePageNumberOnViewChange ( args : any ) {
10698 const documenteditor = documentEditorRef . current ;
10799 if (
108- documenteditor ? .selection &&
100+ documenteditor && documenteditor . selection &&
109101 documenteditor . selection . startPage >= args . startPage &&
110102 documenteditor . selection . startPage <= args . endPage
111103 ) {
@@ -115,93 +107,93 @@ function App() {
115107 }
116108 updatePageNumber ( ) ;
117109 }
118-
110+
119111 function onBlur ( ) {
120112 const editablePageNumber = editablePageNumberRef . current ;
121113 if (
122- editablePageNumber ?. textContent === '' ||
123- parseInt ( editablePageNumber . textContent , 0 ) > editorPageCount
114+ editablePageNumber &&
115+ (
116+ editablePageNumber . textContent === '' ||
117+ parseInt ( editablePageNumber . textContent || '0' , 10 ) > editorPageCount
118+ )
124119 ) {
125120 updatePageNumber ( ) ;
126121 }
127- if ( editablePageNumber ) editablePageNumber . contentEditable = 'false' ;
122+ if ( editablePageNumber ) {
123+ editablePageNumber . contentEditable = 'false' ;
124+ }
128125 }
129126
130127 function onKeyDown ( e : any ) {
131128 const documenteditor = documentEditorRef . current ;
132129 const editablePageNumber = editablePageNumberRef . current ;
133130 if ( e . which === 13 ) {
134131 e . preventDefault ( ) ;
135- const pageNumber = parseInt ( editablePageNumber ? .textContent || '0' , 0 ) ;
132+ const pageNumber = parseInt ( editablePageNumber ? ( editablePageNumber . textContent || '0' ) : '0' , 0 ) ;
136133 if ( pageNumber > editorPageCount ) {
137134 updatePageNumber ( ) ;
138135 } else {
139- if ( documenteditor ? .selection ) {
136+ if ( documenteditor && documenteditor . selection ) {
140137 documenteditor . selection . goToPage ( pageNumber ) ;
141138 } else {
142- documenteditor ? .scrollToPage ( pageNumber ) ;
139+ if ( documenteditor ) { documenteditor . scrollToPage ( pageNumber ) ; }
143140 }
144141 }
145142 if ( editablePageNumber ) editablePageNumber . contentEditable = 'false' ;
146- if ( editablePageNumber ? .textContent === '' ) {
143+ if ( editablePageNumber && editablePageNumber . textContent === '' ) {
147144 updatePageNumber ( ) ;
148145 }
149146 }
150147 if ( e . which > 64 ) {
151148 e . preventDefault ( ) ;
152149 }
153150 }
154-
155151 function onZoom ( args : any ) {
156152 setZoomValue ( args . item . text ) ;
157153 updateZoomContent ( ) ;
158154 }
159-
160155 function setZoomValue ( text : string ) {
161156 const documenteditor = documentEditorRef . current ;
162157 if ( text . match ( 'Fit one page' ) ) {
163- documenteditor ? .fitPage ( 'FitOnePage' ) ;
158+ if ( documenteditor ) { documenteditor . fitPage ( 'FitOnePage' ) ; }
164159 } else if ( text . match ( 'Fit page width' ) ) {
165- documenteditor ? .fitPage ( 'FitPageWidth' ) ;
166- } else {
160+ if ( documenteditor ) { documenteditor . fitPage ( 'FitPageWidth' ) ; }
161+ } else if ( documenteditor ) {
167162 documenteditor . zoomFactor = parseInt ( text , 0 ) / 100 ;
168163 }
169164 }
170-
171165 function updateZoomContent ( ) {
172- if ( zoomRef . current ) {
173- zoomRef . current . content = Math . round ( documentEditorRef . current ?. zoomFactor * 100 ) + '%' ;
166+ if ( zoomRef . current && documentEditorRef . current ) {
167+ zoomRef . current . content =
168+ Math . round ( documentEditorRef . current . zoomFactor * 100 ) + '%' ;
174169 }
175170 }
176-
177171 function updatePageNumber ( ) {
178172 if ( pageNumberLabelRef . current ) {
179173 pageNumberLabelRef . current . textContent = startPage . toString ( ) ;
180174 }
181175 }
182-
183176 function updatePageCount ( ) {
184177 const documenteditor = documentEditorRef . current ;
185- editorPageCount = documenteditor ? .pageCount || 0 ;
178+ editorPageCount = documenteditor ? documenteditor . pageCount : 0 ;
186179 if ( pageCountRef . current ) {
187180 pageCountRef . current . textContent = editorPageCount . toString ( ) ;
188181 }
189182 }
190-
191183 function updateDocumentEditorPageNumber ( ) {
192184 const editPageNumber = editablePageNumberRef . current ;
193185 if ( editPageNumber ) {
194186 editPageNumber . contentEditable = 'true' ;
195187 editPageNumber . focus ( ) ;
196- window . getSelection ( ) ?. selectAllChildren ( editPageNumber ) ;
188+ const selection = window . getSelection ( ) ;
189+ if ( selection ) { selection . selectAllChildren ( editPageNumber ) ; }
197190 }
198191 }
199-
200192 return (
201193 < div >
202194 < DocumentEditorComponent
203195 id = "container"
204- height = { ' 330px' }
196+ height = " 330px"
205197 ref = { documentEditorRef }
206198 isReadOnly = { false }
207199 enablePrint = { true }
@@ -229,7 +221,7 @@ function App() {
229221 enableWordExport = { true }
230222 />
231223 < div id = "page-fit-type-div" >
232- < label id = "page" > Page </ label >
224+ < label id = "page" > Page </ label >
233225 < div id = "editablePageNumber" ref = { editablePageNumberRef } >
234226 < label id = "documenteditor_page_no" ref = { pageNumberLabelRef } />
235227 </ div >
@@ -247,9 +239,5 @@ function App() {
247239 </ div >
248240 ) ;
249241}
250-
251242export default App ;
252-
253243ReactDOM . render ( < App /> , document . getElementById ( 'sample' ) ) ;
254-
255-
0 commit comments