@@ -11,6 +11,7 @@ import type * as Platform from '../../core/platform/platform.js';
1111import * as Buttons from '../../ui/components/buttons/buttons.js' ;
1212import { Link } from '../../ui/kit/kit.js' ;
1313import * as UI from '../../ui/legacy/legacy.js' ;
14+ import { Directives , html , render } from '../../ui/lit/lit.js' ;
1415
1516import { type LighthouseController , type Preset , Presets , RuntimeSettings } from './LighthouseController.js' ;
1617import type { LighthousePanel } from './LighthousePanel.js' ;
@@ -55,6 +56,78 @@ const UIStrings = {
5556const str_ = i18n . i18n . registerUIStrings ( 'panels/lighthouse/LighthouseStartView.ts' , UIStrings ) ;
5657const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
5758
59+ const renderStartView = (
60+ _input : Record < string , never > ,
61+ output : {
62+ helpText ?: HTMLElement ,
63+ warningText ?: HTMLElement ,
64+ modeFormElements ?: HTMLElement ,
65+ deviceTypeFormElements ?: HTMLElement ,
66+ categoriesFormElements ?: HTMLElement ,
67+ } ,
68+ target : HTMLElement ,
69+ ) : void => {
70+ // clang-format off
71+ render (
72+ html `
73+ < form class ="lighthouse-start-view ">
74+ < header class ="hbox ">
75+ < div class ="lighthouse-logo "> </ div >
76+ < div class ="lighthouse-title ">
77+ ${ i18nString ( UIStrings . generateLighthouseReport ) }
78+ </ div >
79+ < div class ="lighthouse-start-button-container "> </ div >
80+ </ header >
81+ < div
82+ ${ Directives . ref ( e => {
83+ output . helpText = e as HTMLElement ;
84+ } ) }
85+ class ="lighthouse-help-text hidden "
86+ > </ div >
87+ < div class ="lighthouse-options hbox ">
88+ < div class ="lighthouse-form-section ">
89+ < div
90+ class ="lighthouse-form-elements "
91+ ${ Directives . ref ( e => {
92+ output . modeFormElements = e as HTMLElement ;
93+ } ) }
94+ > </ div >
95+ </ div >
96+ < div class ="lighthouse-form-section ">
97+ < div
98+ class ="lighthouse-form-elements "
99+ ${ Directives . ref ( e => {
100+ output . deviceTypeFormElements = e as HTMLElement ;
101+ } ) }
102+ > </ div >
103+ </ div >
104+ < div class ="lighthouse-form-categories ">
105+ < fieldset class ="lighthouse-form-section lighthouse-form-categories-fieldset ">
106+ < legend class ="lighthouse-form-section-label ">
107+ ${ i18nString ( UIStrings . categories ) }
108+ </ legend >
109+ < div
110+ class ="lighthouse-form-elements "
111+ ${ Directives . ref ( e => {
112+ output . categoriesFormElements = e as HTMLElement ;
113+ } ) }
114+ > </ div >
115+ </ fieldset >
116+ </ div >
117+ </ div >
118+ < div
119+ ${ Directives . ref ( e => {
120+ output . warningText = e as HTMLElement ;
121+ } ) }
122+ class ="lighthouse-warning-text hidden "
123+ > </ div >
124+ </ form >
125+ ` ,
126+ target ,
127+ ) ;
128+ // clang-format on
129+ } ;
130+
58131export class StartView extends UI . Widget . Widget {
59132 private controller : LighthouseController ;
60133 private panel : LighthousePanel ;
@@ -145,13 +218,11 @@ export class StartView extends UI.Widget.Widget {
145218 }
146219 }
147220
148- private populateFormControls ( fragment : UI . Fragment . Fragment , mode ?: string ) : void {
221+ private populateFormControls ( deviceTypeFormElements : Element , categoryFormElements : Element , mode ?: string ) : void {
149222 // Populate the device type
150- const deviceTypeFormElements = fragment . $ ( 'device-type-form-elements' ) ;
151223 this . populateRuntimeSettingAsRadio ( 'lighthouse.device-type' , i18nString ( UIStrings . device ) , deviceTypeFormElements ) ;
152224
153225 // Populate the categories
154- const categoryFormElements = fragment . $ ( 'categories-form-elements' ) as HTMLElement ;
155226
156227 this . checkboxes = [ ] ;
157228 for ( const preset of Presets ) {
@@ -174,44 +245,34 @@ export class StartView extends UI.Widget.Widget {
174245 this . populateRuntimeSettingAsToolbarDropdown ( 'lighthouse.throttling' , this . #settingsToolbar) ;
175246
176247 const { mode} = this . controller . getFlags ( ) ;
177- this . populateStartButton ( mode ) ;
178248
179- const fragment = UI . Fragment . Fragment . build `
180- <form class="lighthouse-start-view">
181- <header class="hbox">
182- <div class="lighthouse-logo"></div>
183- <h1 class="lighthouse-title">${ i18nString ( UIStrings . generateLighthouseReport ) } </h1>
184- <div class="lighthouse-start-button-container" $="start-button-container">${ this . startButton } </div>
185- </header>
186- <div $="help-text" class="lighthouse-help-text hidden"></div>
187- <div class="lighthouse-options hbox">
188- <div class="lighthouse-form-section">
189- <div class="lighthouse-form-elements" $="mode-form-elements"></div>
190- </div>
191- <div class="lighthouse-form-section">
192- <div class="lighthouse-form-elements" $="device-type-form-elements"></div>
193- </div>
194- <div class="lighthouse-form-categories">
195- <fieldset class="lighthouse-form-section lighthouse-form-categories-fieldset">
196- <legend class="lighthouse-form-section-label">${ i18nString ( UIStrings . categories ) } </legend>
197- <div class="lighthouse-form-elements" $="categories-form-elements"></div>
198- </fieldset>
199- </div>
200- </div>
201- <div $="warning-text" class="lighthouse-warning-text hidden"></div>
202- </form>
203- ` ;
204-
205- this . helpText = fragment . $ ( 'help-text' ) ;
206- this . warningText = fragment . $ ( 'warning-text' ) ;
207-
208- const modeFormElements = fragment . $ ( 'mode-form-elements' ) ;
209- this . populateRuntimeSettingAsRadio ( 'lighthouse.mode' , i18nString ( UIStrings . mode ) , modeFormElements ) ;
249+ const output = {
250+ helpText : undefined as HTMLElement | undefined ,
251+ warningText : undefined as HTMLElement | undefined ,
252+ modeFormElements : undefined as HTMLElement | undefined ,
253+ deviceTypeFormElements : undefined as HTMLElement | undefined ,
254+ categoriesFormElements : undefined as HTMLElement | undefined ,
255+ } ;
256+
257+ renderStartView (
258+ { } ,
259+ output ,
260+ this . contentElement ,
261+ ) ;
210262
211- this . populateFormControls ( fragment , mode ) ;
263+ this . helpText = output . helpText ;
264+ this . warningText = output . warningText ;
212265
213- this . contentElement . textContent = '' ;
214- this . contentElement . append ( fragment . element ( ) ) ;
266+ const modeFormElements = output . modeFormElements ;
267+ const deviceTypeFormElements = output . deviceTypeFormElements ;
268+ const categoriesFormElements = output . categoriesFormElements ;
269+
270+ if ( ! modeFormElements || ! deviceTypeFormElements || ! categoriesFormElements ) {
271+ throw new Error ( 'Required elements not found in template' ) ;
272+ }
273+
274+ this . populateRuntimeSettingAsRadio ( 'lighthouse.mode' , i18nString ( UIStrings . mode ) , modeFormElements ) ;
275+ this . populateFormControls ( deviceTypeFormElements , categoriesFormElements , mode ) ;
215276
216277 this . refresh ( ) ;
217278 }
0 commit comments