@@ -7,12 +7,28 @@ import Settings from '../settings';
7
7
import Shortcuts from '../keyboard-shortcuts' ;
8
8
import { secondsToTimecode } from '../../util/timecode-converter' ;
9
9
import Header from './src/Header.js' ;
10
-
10
+ import ExportOptions from './src/ExportOptions.js' ;
11
11
import style from './index.module.css' ;
12
12
13
13
// TODO: move to another file with tooltip - rename HowDoesThisWork or HelpMessage
14
14
import HowDoesThisWork from './src/HowDoesThisWork.js' ;
15
15
16
+ const exportOptionsList = [
17
+ { value : 'txt' , label : 'Text file' } ,
18
+ { value : 'txtspeakertimecodes' , label : 'Text file - with Speakers and Timecodes' } ,
19
+ { value : 'docx' , label : 'MS Word' } ,
20
+ { value : 'srt' , label : 'Srt - Captions' } ,
21
+ { value : 'ttml' , label : 'TTML - Captions' } ,
22
+ { value : 'premiereTTML' , label : 'TTML for Adobe Premiere - Captions' } ,
23
+ { value : 'itt' , label : 'iTT - Captions' } ,
24
+ { value : 'csv' , label : 'CSV - Captions' } ,
25
+ { value : 'vtt' , label : 'VTT - Captions' } ,
26
+ { value : 'pre-segment-txt' , label : 'Pre segmented txt - Captions' } ,
27
+ { value : 'json-captions' , label : 'Json - Captions' } ,
28
+ { value : 'draftjs' , label : 'Draft Js - json' } ,
29
+ { value : 'digitalpaperedit' , label : 'Digital Paper Edit - Json' }
30
+ ] ;
31
+
16
32
class TranscriptEditor extends React . Component {
17
33
constructor ( props ) {
18
34
super ( props ) ;
@@ -24,6 +40,7 @@ class TranscriptEditor extends React.Component {
24
40
isScrollIntoViewOn : false ,
25
41
showSettings : false ,
26
42
showShortcuts : false ,
43
+ showExportOptions : false ,
27
44
isPauseWhileTypingOn : true ,
28
45
rollBackValueInSeconds : 15 ,
29
46
timecodeOffset : 0 ,
@@ -72,6 +89,9 @@ class TranscriptEditor extends React.Component {
72
89
if ( nextState . showShortcuts !== this . state . showShortcuts ) {
73
90
return true ;
74
91
}
92
+ if ( nextState . showExportOptions !== this . state . showExportOptions ) {
93
+ return true ;
94
+ }
75
95
76
96
if ( nextState . isPauseWhileTypingOn !== this . state . isPauseWhileTypingOn ) {
77
97
return true ;
@@ -280,6 +300,55 @@ class TranscriptEditor extends React.Component {
280
300
}
281
301
} ;
282
302
303
+ handleExportToggle = ( ) => {
304
+ console . log ( 'handleExportToggle' , this . state . showExportOptions ) ;
305
+ this . setState ( prevState => ( {
306
+ showExportOptions : ! prevState . showExportOptions
307
+ } ) ) ;
308
+
309
+ if ( this . props . handleAnalyticsEvents ) {
310
+ this . props . handleAnalyticsEvents ( {
311
+ category : 'TranscriptEditor' ,
312
+ action : 'handleExportToggle' ,
313
+ name : 'showExportOptions' ,
314
+ value : ! this . state . showExportOptions
315
+ } ) ;
316
+ }
317
+ }
318
+
319
+ handleExportOptionsChange = ( e ) => {
320
+ const exportFormat = e . target . value ;
321
+ console . log ( exportFormat ) ;
322
+ if ( exportFormat !== 'instructions' ) {
323
+
324
+ const fileName = this . props . title ? this . props . title : this . props . mediaUrl ;
325
+
326
+ const { data, ext } = this . getEditorContent ( exportFormat ) ;
327
+ let tmpData = data ;
328
+ if ( ext === 'json' ) {
329
+ tmpData = JSON . stringify ( data , null , 2 ) ;
330
+ }
331
+ if ( ext !== 'docx' ) {
332
+ this . download ( tmpData , `${ fileName } .${ ext } ` ) ;
333
+ }
334
+ }
335
+ }
336
+
337
+ // https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file
338
+ download = ( content , filename , contentType ) => {
339
+ const type = contentType || 'application/octet-stream' ;
340
+ const link = document . createElement ( 'a' ) ;
341
+ const blob = new Blob ( [ content ] , { type : type } ) ;
342
+
343
+ link . href = window . URL . createObjectURL ( blob ) ;
344
+ link . download = filename ;
345
+ // Firefox fix - cannot do link.click() if it's not attached to DOM in firefox
346
+ // https://stackoverflow.com/questions/32225904/programmatical-click-on-a-tag-not-working-in-firefox
347
+ document . body . appendChild ( link ) ;
348
+ link . click ( ) ;
349
+ document . body . removeChild ( link ) ;
350
+ } ;
351
+
283
352
getEditorContent = exportFormat => {
284
353
const title = this . props . title ? this . props . title : '' ;
285
354
@@ -381,6 +450,13 @@ class TranscriptEditor extends React.Component {
381
450
/>
382
451
) ;
383
452
453
+ const exportOptions = (
454
+ < ExportOptions
455
+ exportOptionsList = { exportOptionsList }
456
+ handleExportOptionsChange = { this . handleExportOptionsChange }
457
+ handleExportToggle = { this . handleExportToggle }
458
+ /> ) ;
459
+
384
460
const shortcuts = (
385
461
< Shortcuts handleShortcutsToggle = { this . handleShortcutsToggle } />
386
462
) ;
@@ -407,18 +483,23 @@ class TranscriptEditor extends React.Component {
407
483
/>
408
484
) ;
409
485
486
+ // const export = (<h1>Export</h1>)
487
+
410
488
return (
411
489
< div className = { style . container } >
412
490
{ this . props . mediaUrl === null ? null : < Header
413
491
showSettings = { this . state . showSettings }
414
492
showShortcuts = { this . state . showShortcuts }
493
+ showExportOptions = { this . state . showExportOptions }
415
494
settings = { settings }
416
495
shortcuts = { shortcuts }
496
+ exportOptions = { exportOptions }
417
497
tooltip = { HowDoesThisWork }
418
498
mediaUrl = { this . props . mediaUrl }
419
499
mediaControls = { mediaControls }
420
500
handleSettingsToggle = { this . handleSettingsToggle }
421
501
handleShortcutsToggle = { this . handleShortcutsToggle }
502
+ handleExportToggle = { this . handleExportToggle }
422
503
/> }
423
504
424
505
< div className = { style . grid } >
0 commit comments