11/* eslint-disable lines-between-class-members */
22
3+ import { escape } from 'lodash' ; // eslint-disable-line import/no-extraneous-dependencies
34import { colorizeRegex } from '../utils/colorize-regex' ;
45import { getElement } from '../utils/dom' ;
56
67import './demo-output.scss' ;
78
89export default class DemoOutput {
10+ protected $container : HTMLDivElement ;
911 protected $expansions : HTMLPreElement ;
1012 protected $displayCount : HTMLSpanElement ;
1113 protected $totalCount : HTMLSpanElement ;
1214 protected $optimized : HTMLDivElement ;
1315 protected $optimizedContainer : HTMLDivElement ;
1416
1517 public constructor ( ) {
18+ this . $container = getElement ( '.js-output-container' ) ;
1619 this . $expansions = getElement ( '.js-output' ) ;
1720 this . $displayCount = getElement ( '.js-output-count' ) ;
1821 this . $totalCount = getElement ( '.js-total-count' ) ;
@@ -21,15 +24,27 @@ export default class DemoOutput {
2124 }
2225
2326 public display ( expansions : string [ ] , delimiter : string ) {
24- this . $expansions . classList . toggle ( 'wrap-output' , delimiter !== '\n' ) ;
25- this . $expansions . innerHTML = expansions
26- . map ( string => `<span>${ string } </span>` )
27- . join ( delimiter ) ;
27+ const isBlockOutput = delimiter === 'block' ;
28+ const isWrappingDelimiter = [ '\n' , 'block' ] . includes ( delimiter ) ;
29+
30+ this . $expansions . classList . toggle ( 'plaintext-output' , ! isBlockOutput ) ;
31+ this . $expansions . classList . toggle ( 'wrap-output' , ! isWrappingDelimiter ) ;
32+
33+ if ( isBlockOutput ) {
34+ this . $expansions . innerHTML = expansions
35+ . map ( string => `<div class="alert alert-light">${ escape ( string ) } </div>` )
36+ . join ( '\n' ) ;
37+ } else {
38+ this . $expansions . innerHTML = expansions
39+ . map ( string => `<span>${ escape ( string ) } </span>` )
40+ . join ( delimiter ) ;
41+ }
42+
2843 this . $displayCount . innerText = expansions . length . toLocaleString ( ) ;
2944 }
3045
3146 public hideWaiting ( ) {
32- this . $expansions . classList . remove ( 'is-waiting' ) ;
47+ this . $container . classList . remove ( 'is-waiting' ) ;
3348 }
3449
3550 public setOptimizedPattern ( optimizedPattern : string ) {
@@ -46,9 +61,12 @@ export default class DemoOutput {
4661 }
4762
4863 public showWaiting ( ) {
64+ this . $container . classList . add ( 'is-waiting' ) ;
65+
66+ this . $expansions . classList . remove ( 'plaintext-output' , 'wrap-output' ) ;
4967 this . $expansions . innerHTML = '' ;
50- this . $expansions . classList . add ( 'is-waiting' ) ;
51- this . $optimizedContainer . hidden = true ;
68+
69+ this . $optimized . textContent = '...' ;
5270 this . $displayCount . innerText = '...' ;
5371 this . $totalCount . innerText = '...' ;
5472 }
0 commit comments