@@ -136,6 +136,8 @@ export const useProject = () => {
136
136
137
137
if ( ! breakpoints . isMobile ( ) . value ) ABSOLUTE . aside = true
138
138
139
+ ABSOLUTE . project . blocked = false
140
+
139
141
const editor = document . querySelector ( '#edit' )
140
142
141
143
if ( editor ) editor . scrollTop = PROJECT . scrollLoaded
@@ -191,7 +193,7 @@ export const useProject = () => {
191
193
. finally ( ( ) => { } )
192
194
}
193
195
194
- const onLoadImporter = async ( content : ImporterData , fileName : string ) => {
196
+ const onLoadDOCX = async ( content : ImporterData , fileName : string ) => {
195
197
const entities : Entities = [ ]
196
198
197
199
content . entities . forEach ( ( { type, raw } ) => {
@@ -290,20 +292,115 @@ export const useProject = () => {
290
292
if ( ! breakpoints . isMobile ( ) . value && PROJECT . type === 'creative' )
291
293
ABSOLUTE . aside = true
292
294
295
+ ABSOLUTE . project . blocked = false
296
+
297
+ toast . success ( t ( 'toast.project.create' ) )
298
+ }
299
+
300
+ const onLoadTXT = async ( data : string , filename : string ) => {
301
+ const content = data . split ( '\n' )
302
+ const entities : Entities = [ ]
303
+ let __FIRST_ROW__ = true
304
+
305
+ content . forEach ( ( row ) => {
306
+ if ( __FIRST_ROW__ && row ) {
307
+ entities . push ( factory . entity ( ) . create ( 'heading-one' , row ) )
308
+ __FIRST_ROW__ = false
309
+
310
+ return
311
+ }
312
+
313
+ if ( ! row ) {
314
+ entities . push ( factory . entity ( ) . create ( 'line-break' ) )
315
+
316
+ return
317
+ }
318
+
319
+ entities . push ( factory . entity ( ) . create ( 'paragraph' , row ) )
320
+ } )
321
+
322
+ PROJECT . createExternal ( {
323
+ name : ut . text ( ) . kebab ( filename ) ,
324
+ nameRaw : filename ,
325
+ version : '0.1.0' ,
326
+ creator : 'betterwrite' ,
327
+ producer : 'betterwrite' ,
328
+ keywords : 'docx,project' ,
329
+ subject : 'betterwrite' ,
330
+ type : 'creative' ,
331
+ totalPagesCreated : 1 ,
332
+ main : { } ,
333
+ summary : { } ,
334
+ pageLoaded : 1 ,
335
+ scrollLoaded : 0 ,
336
+ offsetLoaded : 0 ,
337
+ pages : [
338
+ {
339
+ id : 1 ,
340
+ title : entities [ 0 ] . raw ,
341
+ entities,
342
+ createdAt : format . actually ( ) ,
343
+ updatedAt : format . actually ( ) ,
344
+ } ,
345
+ ] ,
346
+ bw : {
347
+ platform : 'web' ,
348
+ version : useEnv ( ) . packageVersion ( ) as string ,
349
+ } ,
350
+ pdf : {
351
+ encryption : {
352
+ userPassword : '' ,
353
+ ownerPassword : '' ,
354
+ } ,
355
+ permissions : {
356
+ printing : 'highResolution' ,
357
+ modifying : false ,
358
+ copying : false ,
359
+ annotating : true ,
360
+ fillingForms : true ,
361
+ contentAccessibility : true ,
362
+ documentAssembly : true ,
363
+ } ,
364
+ } ,
365
+ creative : {
366
+ drafts : [ ] ,
367
+ } ,
368
+ templates : {
369
+ generator : [ ] ,
370
+ substitutions : {
371
+ text : defines . generator ( ) . substitutions ( ) . text ( ) ,
372
+ italic : defines . generator ( ) . substitutions ( ) . italic ( ) ,
373
+ bold : defines . generator ( ) . substitutions ( ) . bold ( ) ,
374
+ } ,
375
+ } ,
376
+ } )
377
+
378
+ await nextTick
379
+
380
+ CONTEXT . load ( PROJECT . pages [ 0 ] )
381
+
382
+ await nextTick
383
+
384
+ if ( ! breakpoints . isMobile ( ) . value && PROJECT . type === 'creative' )
385
+ ABSOLUTE . aside = true
386
+
387
+ ABSOLUTE . project . blocked = false
388
+
293
389
toast . success ( t ( 'toast.project.create' ) )
294
390
}
295
391
296
392
const onImportProject = ( ) => {
297
393
const _ = document . createElement ( 'input' )
298
394
_ . type = 'file'
299
- _ . accept = '.doc,.docx,.bw'
395
+ _ . accept = '.doc,.docx,.bw,.txt '
300
396
_ . addEventListener ( 'change' , function ( ) {
301
397
const file : File = ( this . files as any ) [ 0 ]
302
398
303
399
if ( ! file ) return
304
400
305
401
const isDoc = file . name . endsWith ( '.doc' ) || file . name . endsWith ( '.docx' )
306
402
const isBW = file . name . endsWith ( '.bw' )
403
+ const isTXT = file . name . endsWith ( '.txt' )
307
404
308
405
const reader = new FileReader ( )
309
406
isDoc ? reader . readAsDataURL ( file ) : reader . readAsText ( file )
@@ -316,19 +413,23 @@ export const useProject = () => {
316
413
return
317
414
}
318
415
416
+ const filename = file . name
417
+ . replace ( '.bw' , '' )
418
+ . replace ( '.docx' , '' )
419
+ . replace ( '.doc' , '' )
420
+ . replace ( '.txt' , '' )
421
+
319
422
if ( isDoc ) {
320
423
const importers = await DocxToJson ( reader . result as string )
321
424
322
- onLoadImporter (
323
- importers ,
324
- file . name
325
- . replace ( '.bw' , '' )
326
- . replace ( '.docx' , '' )
327
- . replace ( '.doc' , '' )
328
- )
425
+ onLoadDOCX ( importers , filename )
329
426
330
427
return
331
428
}
429
+
430
+ if ( isTXT ) {
431
+ await onLoadTXT ( reader . result as string , filename )
432
+ }
332
433
}
333
434
reader . onerror = function ( err ) { }
334
435
} )
0 commit comments