1- import React , { useState , useRef , useCallback , useMemo } from " react" ;
2- import SuperDocTemplateBuilder from " @superdoc-dev/template-builder" ;
1+ import React , { useState , useRef , useCallback , useMemo } from ' react' ;
2+ import SuperDocTemplateBuilder from ' @superdoc-dev/template-builder' ;
33import type {
44 SuperDocTemplateBuilderHandle ,
55 TemplateField ,
66 FieldDefinition ,
77 ExportEvent ,
8- } from " @superdoc-dev/template-builder" ;
9- import " superdoc/style.css" ;
10- import " ./App.css" ;
8+ } from ' @superdoc-dev/template-builder' ;
9+ import ' superdoc/style.css' ;
10+ import ' ./App.css' ;
1111
1212const availableFields : FieldDefinition [ ] = [
13- { id : " 1242142770" , label : " Agreement Date" } ,
14- { id : " 1242142771" , label : " User Name" } ,
15- { id : " 1242142772" , label : " Company Name" } ,
16- { id : " 1242142773" , label : " Service Type" } ,
17- { id : " 1242142774" , label : " Agreement Jurisdiction" } ,
18- { id : " 1242142775" , label : " Company Address" } ,
19- { id : " 1242142776" , label : " Signature" } ,
13+ { id : ' 1242142770' , label : ' Agreement Date' } ,
14+ { id : ' 1242142771' , label : ' User Name' } ,
15+ { id : ' 1242142772' , label : ' Company Name' } ,
16+ { id : ' 1242142773' , label : ' Service Type' } ,
17+ { id : ' 1242142774' , label : ' Agreement Jurisdiction' } ,
18+ { id : ' 1242142775' , label : ' Company Address' } ,
19+ { id : ' 1242142776' , label : ' Signature' } ,
2020] ;
2121
2222export function App ( ) {
23- const [ fields , setFields ] = useState < TemplateField [ ] > ( [ ] ) ;
23+ const [ , setFields ] = useState < TemplateField [ ] > ( [ ] ) ;
2424 const [ events , setEvents ] = useState < string [ ] > ( [ ] ) ;
2525 const [ isDownloading , setIsDownloading ] = useState ( false ) ;
2626 const [ isImporting , setIsImporting ] = useState ( false ) ;
2727 const [ importError , setImportError ] = useState < string | null > ( null ) ;
2828 const [ documentSource , setDocumentSource ] = useState < string | File > (
29- " https://storage.googleapis.com/public_static_hosting/public_demo_docs/new_service_agreement.docx" ,
29+ ' https://storage.googleapis.com/public_static_hosting/public_demo_docs/new_service_agreement.docx' ,
3030 ) ;
3131 const builderRef = useRef < SuperDocTemplateBuilderHandle > ( null ) ;
3232 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
@@ -70,28 +70,26 @@ export function App() {
7070 ) ;
7171
7272 const handleReady = useCallback ( ( ) => {
73- log ( " ✓ Template builder ready" ) ;
73+ log ( ' ✓ Template builder ready' ) ;
7474 if ( importingRef . current ) {
75- log ( " 📄 Document imported" ) ;
75+ log ( ' 📄 Document imported' ) ;
7676 importingRef . current = false ;
7777 setImportError ( null ) ;
7878 setIsImporting ( false ) ;
7979 }
8080 } , [ log ] ) ;
8181
8282 const handleTrigger = useCallback ( ( ) => {
83- log ( " ⌨ Trigger detected" ) ;
83+ log ( ' ⌨ Trigger detected' ) ;
8484 } , [ log ] ) ;
8585
8686 const handleExport = useCallback (
8787 ( event : ExportEvent ) => {
88- console . log ( " Export Event:" , event ) ;
89- console . log ( " Fields:" , JSON . stringify ( event . fields , null , 2 ) ) ;
88+ console . log ( ' Export Event:' , event ) ;
89+ console . log ( ' Fields:' , JSON . stringify ( event . fields , null , 2 ) ) ;
9090 log ( `Exported ${ event . fields . length } fields` ) ;
9191 event . fields . forEach ( ( f ) => {
92- console . log (
93- ` - ${ f . alias } (id: ${ f . id } , mode: ${ f . mode } , group: ${ f . group || "none" } )` ,
94- ) ;
92+ console . log ( ` - ${ f . alias } (id: ${ f . id } , mode: ${ f . mode } , group: ${ f . group || 'none' } )` ) ;
9593 } ) ;
9694 } ,
9795 [ log ] ,
@@ -106,20 +104,20 @@ export function App() {
106104 setIsDownloading ( true ) ;
107105
108106 await builderRef . current . exportTemplate ( {
109- fileName : " template.docx" ,
107+ fileName : ' template.docx' ,
110108 } ) ;
111109
112- log ( " 📤 Template exported" ) ;
110+ log ( ' 📤 Template exported' ) ;
113111 } catch ( error ) {
114- log ( " ⚠️ Export failed" ) ;
115- console . error ( " Failed to export template" , error ) ;
112+ log ( ' ⚠️ Export failed' ) ;
113+ console . error ( ' Failed to export template' , error ) ;
116114 } finally {
117115 setIsDownloading ( false ) ;
118116 }
119117 } , [ log ] ) ;
120118
121119 const handleKeyDown = ( e : React . KeyboardEvent ) => {
122- if ( e . key === " Tab" ) {
120+ if ( e . key === ' Tab' ) {
123121 e . preventDefault ( ) ;
124122 if ( e . shiftKey ) {
125123 builderRef . current ?. previousField ( ) ;
@@ -132,7 +130,7 @@ export function App() {
132130 const documentConfig = useMemo (
133131 ( ) => ( {
134132 source : documentSource ,
135- mode : " editing" as const ,
133+ mode : ' editing' as const ,
136134 } ) ,
137135 [ documentSource ] ,
138136 ) ;
@@ -145,15 +143,15 @@ export function App() {
145143 const handleFileInputChange = useCallback (
146144 ( event : React . ChangeEvent < HTMLInputElement > ) => {
147145 const file = event . target . files ?. [ 0 ] ;
148- event . target . value = "" ;
146+ event . target . value = '' ;
149147
150148 if ( ! file ) return ;
151149
152- const extension = file . name . split ( "." ) . pop ( ) ?. toLowerCase ( ) ;
153- if ( extension !== " docx" ) {
154- const message = " Invalid file type. Please choose a .docx file." ;
150+ const extension = file . name . split ( '.' ) . pop ( ) ?. toLowerCase ( ) ;
151+ if ( extension !== ' docx' ) {
152+ const message = ' Invalid file type. Please choose a .docx file.' ;
155153 setImportError ( message ) ;
156- log ( " ⚠️ " + message ) ;
154+ log ( ' ⚠️ ' + message ) ;
157155 return ;
158156 }
159157
@@ -176,7 +174,7 @@ export function App() {
176174
177175 const listConfig = useMemo (
178176 ( ) => ( {
179- position : " right" as const ,
177+ position : ' right' as const ,
180178 } ) ,
181179 [ ] ,
182180 ) ;
@@ -196,7 +194,7 @@ export function App() {
196194 </ a >
197195 </ h1 >
198196 < p >
199- React template builder from{ " " }
197+ React template builder from{ ' ' }
200198 < a href = "https://superdoc.dev" target = "_blank" rel = "noopener" >
201199 SuperDoc
202200 </ a >
@@ -220,7 +218,7 @@ export function App() {
220218 < div className = "container" >
221219 < div className = "toolbar" >
222220 < div className = "toolbar-left" >
223- < span className = "hint" > Type { "{{" } to insert a field</ span >
221+ < span className = "hint" > Type { '{{' } to insert a field</ span >
224222 < span className = "divider" > |</ span >
225223 < span className = "hint" > Tab/Shift+Tab to navigate</ span >
226224 </ div >
@@ -229,22 +227,22 @@ export function App() {
229227 type = "file"
230228 accept = ".docx"
231229 ref = { fileInputRef }
232- style = { { display : " none" } }
230+ style = { { display : ' none' } }
233231 onChange = { handleFileInputChange }
234232 />
235233 < button
236234 onClick = { handleImportButtonClick }
237235 className = "import-button"
238236 disabled = { isImporting || isDownloading }
239237 >
240- { isImporting ? " Importing…" : " Import File" }
238+ { isImporting ? ' Importing…' : ' Import File' }
241239 </ button >
242240 < button
243241 onClick = { handleExportTemplate }
244242 className = "export-button"
245243 disabled = { isDownloading || isImporting }
246244 >
247- { isDownloading ? " Exporting..." : " Export Template" }
245+ { isDownloading ? ' Exporting...' : ' Export Template' }
248246 </ button >
249247 </ div >
250248 </ div >
0 commit comments