File size: 1,461 Bytes
9f97180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import DocumentEditor from './components/DocumentEditor'
import { DocAuthEditor, DocAuthSystem } from '@pspdfkit/document-authoring'
import { useCallback, useState } from 'react'
import './App.css'

function App() {
  const [editor,setEditor] = useState<DocAuthEditor|null>(null)

  const clear = async () => {
    if( editor ) {
      const docAuthSystem = editor.docAuthSystem()
      editor.setCurrentDocument(await docAuthSystem.createDocumentFromPlaintext(''))
    }
  }

  const loadDocx = async () => {
    if( editor ) {
      const docAuthSystem = editor.docAuthSystem()
      editor.setCurrentDocument(await docAuthSystem.importDOCX(fetch('./sample.docx')))
    }
  }

  const loadJson = async () => {
    if( editor ) {
      const docAuthSystem = editor.docAuthSystem()
      editor.setCurrentDocument(await docAuthSystem.loadDocument(fetch('./sample.json')))
    }
  }

  const createInitialDocument = useCallback((docAuthSystem:DocAuthSystem) => {
    return docAuthSystem.createDocumentFromPlaintext('Hi there!')
  },[])
  
  return (
    <div className='App'>
        <>
          <div className='Header'>
            <button onClick={clear}>Clear</button>
            <button onClick={loadDocx}>Load example.docx</button>
            <button onClick={loadJson}>Load example.json</button>
          </div>
          <DocumentEditor initialDocument={createInitialDocument} onEditor={setEditor} />
        </>
    </div>
  )
}

export default App