@@ -20,17 +20,28 @@ import getFullTreeByParentUid from "roamjs-components/queries/getFullTreeByParen
20
20
import { addCommand } from "./workBench" ;
21
21
import getParentUidByBlockUid from "roamjs-components/queries/getParentUidByBlockUid" ;
22
22
23
- const OPTIONS : Record < string , string > = {
24
- puretext_Space : "Text with space indentation" ,
25
- puretext_Tab : "Text with tab indentation" ,
26
- pureText_NoIndentation : "Text with no indentation" ,
27
- markdown_Github : "GitHub Flavored Markdown" ,
28
- markdown_Github_flatten : "GitHub Flavored Markdown - flatten" ,
29
- html_Simple : "HTML" ,
30
- html_Markdown_Github_flatten : "HTML after Markdown Flattening" ,
31
- json_Simple : "JSON in simple format" ,
32
- json_Simple_withIndentation :
33
- "JSON in simple format with Indentation in text string" ,
23
+ const OPTIONS : Record < string , { label : string ; fileFormat : string } > = {
24
+ puretext_Space : { label : "Text with space indentation" , fileFormat : ".txt" } ,
25
+ puretext_Tab : { label : "Text with tab indentation" , fileFormat : ".txt" } ,
26
+ pureText_NoIndentation : {
27
+ label : "Text with no indentation" ,
28
+ fileFormat : ".txt" ,
29
+ } ,
30
+ markdown_Github : { label : "GitHub Flavored Markdown" , fileFormat : ".md" } ,
31
+ markdown_Github_flatten : {
32
+ label : "GitHub Flavored Markdown - flatten" ,
33
+ fileFormat : ".md" ,
34
+ } ,
35
+ html_Simple : { label : "HTML" , fileFormat : ".html" } ,
36
+ html_Markdown_Github_flatten : {
37
+ label : "HTML after Markdown Flattening" ,
38
+ fileFormat : ".html" ,
39
+ } ,
40
+ json_Simple : { label : "JSON in simple format" , fileFormat : ".json" } ,
41
+ json_Simple_withIndentation : {
42
+ label : "JSON in simple format with Indentation in text string" ,
43
+ fileFormat : ".json" ,
44
+ } ,
34
45
} ;
35
46
36
47
const sortObjectsByOrder = ( o : TreeNode [ ] ) => {
@@ -397,11 +408,14 @@ const FormatConverterUI = ({
397
408
( ) => localStorage . getItem ( "formatConverterUI_lastFormat" ) as string ,
398
409
[ ]
399
410
) ;
400
- const [ value , setValue ] = useState ( lastValue || "puretext_Space" ) ;
411
+ const [ selectedFormat , setSelectedFormat ] = useState (
412
+ lastValue || "puretext_Space"
413
+ ) ;
414
+ const [ drawerSize , setDrawerSize ] = useState ( "50%" ) ;
401
415
const [ displayValue , setDisplayValue ] = useState ( "" ) ;
402
416
const changeFormat = useCallback ( async ( ) => {
403
- localStorage . setItem ( "formatConverterUI_lastFormat" , value ) ;
404
- switch ( value ) {
417
+ localStorage . setItem ( "formatConverterUI_lastFormat" , selectedFormat ) ;
418
+ switch ( selectedFormat ) {
405
419
case "puretext_Tab" :
406
420
setDisplayValue (
407
421
await iterateThroughTree ( uid , formatter . pureText_TabIndented )
@@ -442,22 +456,24 @@ const FormatConverterUI = ({
442
456
setDisplayValue ( ( await flatJson ( uid , true ) ) as string ) ;
443
457
break ;
444
458
}
445
- } , [ value , uid ] ) ;
459
+ } , [ selectedFormat , uid ] ) ;
446
460
useEffect ( ( ) => {
447
461
changeFormat ( ) ;
448
462
} , [ changeFormat ] ) ;
449
463
return (
450
464
< Drawer
465
+ title = { "WorkBench Format Converter" }
466
+ className = { "workbench-format-converter pointer-events-auto" }
467
+ portalClassName = { "pointer-events-none" }
451
468
isOpen = { isOpen }
452
469
onClose = { onClose }
453
- title = { "WorkBench Format Converter" }
454
470
position = { "bottom" }
455
471
hasBackdrop = { false }
456
472
canOutsideClickClose = { false }
457
- portalClassName = { "pointer-events-none" }
458
- className = { "pointer-events-auto" }
459
473
enforceFocus = { false }
460
474
autoFocus = { false }
475
+ size = { drawerSize }
476
+ canEscapeKeyClose = { true }
461
477
>
462
478
< div
463
479
className = { Classes . DRAWER_BODY }
@@ -467,18 +483,20 @@ const FormatConverterUI = ({
467
483
overflow : "hidden" ,
468
484
} }
469
485
>
470
- < div >
471
- < div className = "flex items-center justify-between" >
472
- < Label style = { { padding : 10 , flexGrow : 1 } } >
486
+ < div style = { { height : "calc(100% - 100px)" } } >
487
+ < div className = "flex flex-col md:flex-row items-center mb-2" >
488
+ { /* Output format select */ }
489
+ < Label className = "p-3" style = { { marginBottom : 0 } } >
473
490
Output format:
474
491
< MenuItemSelect
475
- activeItem = { value }
476
- onItemSelect = { ( item ) => setValue ( item ) }
492
+ activeItem = { selectedFormat }
493
+ onItemSelect = { ( item ) => setSelectedFormat ( item ) }
477
494
items = { Object . keys ( OPTIONS ) }
478
- transformItem = { ( k ) => OPTIONS [ k ] }
495
+ transformItem = { ( k ) => OPTIONS [ k ] . label }
479
496
/>
480
497
</ Label >
481
- < div className = "flex gap-4 items-center" >
498
+ { /* Middle Buttons */ }
499
+ < div className = "flex p-3 gap-4 items-center justify-center" >
482
500
< Button
483
501
icon = { "refresh" }
484
502
small
@@ -500,11 +518,12 @@ const FormatConverterUI = ({
500
518
title = "Save to a file"
501
519
onClick = { ( ) => {
502
520
const currentPageName = getPageTitleByPageUid ( uid ) ;
521
+ const extension = OPTIONS [ selectedFormat ] . fileFormat ;
503
522
const filename =
504
523
( currentPageName + "-" + new Date ( ) . toISOString ( ) ) . replace (
505
524
/ ( \W + ) / gi,
506
525
"-"
507
- ) + ".txt" ;
526
+ ) + extension ;
508
527
const element = document . createElement ( "a" ) ;
509
528
element . setAttribute (
510
529
"href" ,
@@ -525,15 +544,20 @@ const FormatConverterUI = ({
525
544
} }
526
545
/>
527
546
</ div >
547
+ { /* Draw Size Buttons */ }
548
+ < div className = "p-3" >
549
+ { [ "25%" , "50%" , "75%" , "100%" ] . map ( ( size ) => (
550
+ < Button
551
+ text = { size }
552
+ minimal = { drawerSize !== size }
553
+ onClick = { ( ) => setDrawerSize ( size ) }
554
+ />
555
+ ) ) }
556
+ </ div >
528
557
</ div >
529
- < div style = { { marginLeft : 10 , marginRight : 10 } } >
558
+ < div className = "mx-3 h-full" >
530
559
< textarea
531
- style = { {
532
- fontFamily : "monospace" ,
533
- width : "100%" ,
534
- height : "300px" ,
535
- overflow : "auto" ,
536
- } }
560
+ className = "p-2 w-full h-full overflow-auto font-mono"
537
561
value = { displayValue }
538
562
onChange = { ( e ) => setDisplayValue ( e . target . value ) }
539
563
/>
0 commit comments