@@ -8,7 +8,13 @@ import { ForesightManager } from "js.foresight"
88import { css , html , LitElement } from "lit"
99import { customElement , state } from "lit/decorators.js"
1010
11- import type { Corner , DevtoolsSettings } from "../../../types/types"
11+ import {
12+ SHOW_KEYS ,
13+ type Corner ,
14+ type DevtoolsSettings ,
15+ type ShowKey ,
16+ type ShowSettings ,
17+ } from "../../../types/types"
1218import {
1319 MAX_POSITION_HISTORY_SIZE ,
1420 MAX_SCROLL_MARGIN ,
@@ -36,12 +42,12 @@ import { ForesightDevtools } from "../../foresight-devtools"
3642
3743// A helper type to represent a change in a Devtools setting
3844type UpdatedDevtoolsSetting = {
39- [ K in keyof DevtoolsSettings ] : {
40- setting : K
41- newValue : DevtoolsSettings [ K ]
42- oldValue : DevtoolsSettings [ K ]
45+ [ K in ShowKey ] : {
46+ setting : `show.${ K } `
47+ newValue : ShowSettings [ K ]
48+ oldValue : ShowSettings [ K ]
4349 }
44- } [ keyof DevtoolsSettings ]
50+ } [ ShowKey ]
4551
4652@customElement ( "settings-tab" )
4753export class SettingsTab extends LitElement {
@@ -168,13 +174,20 @@ export class SettingsTab extends LitElement {
168174 const currentDevtoolsSettings = ForesightDevtools . instance . devtoolsSettings
169175 const currentManagerSettings = ForesightManager . instance . getManagerData . globalSettings
170176
171- // Shallow copy is sufficient for settings objects
172- this . devtoolsSettings = Object . assign ( { } , currentDevtoolsSettings )
177+ // Shallow copy is sufficient except for `show`, which we deep-copy so
178+ // the live and initial snapshots can diverge as the user toggles flags.
179+ this . devtoolsSettings = {
180+ ...currentDevtoolsSettings ,
181+ show : { ...currentDevtoolsSettings . show } ,
182+ }
173183 this . managerSettings = Object . assign ( { } , currentManagerSettings )
174184 this . currentCorner = this . getCurrentCorner ( )
175185
176186 this . initialSettings = {
177- devtools : Object . assign ( { } , currentDevtoolsSettings ) ,
187+ devtools : {
188+ ...currentDevtoolsSettings ,
189+ show : { ...currentDevtoolsSettings . show } ,
190+ } ,
178191 manager : Object . assign ( { } , currentManagerSettings ) ,
179192 }
180193 }
@@ -239,14 +252,12 @@ export class SettingsTab extends LitElement {
239252 private _checkDevtoolsSettingsChanges (
240253 changes : ( UpdatedManagerSetting | UpdatedDevtoolsSetting ) [ ]
241254 ) : void {
242- const devtoolsKeys : ( keyof DevtoolsSettings ) [ ] = [ "showNameTags" ]
243-
244- for ( const key of devtoolsKeys ) {
245- const oldValue = this . initialSettings . devtools [ key ]
246- const newValue = this . devtoolsSettings [ key ]
255+ for ( const key of SHOW_KEYS ) {
256+ const oldValue = this . initialSettings . devtools . show [ key ]
257+ const newValue = this . devtoolsSettings . show [ key ]
247258 if ( oldValue !== newValue ) {
248259 changes . push ( {
249- setting : key ,
260+ setting : `show. ${ key } ` ,
250261 oldValue,
251262 newValue,
252263 } as UpdatedDevtoolsSetting )
@@ -257,14 +268,16 @@ export class SettingsTab extends LitElement {
257268 private _handleDevtoolsSettingChange ( e : CustomEvent < { setting : string ; value : boolean } > ) : void {
258269 const { setting, value } = e . detail
259270
260- if ( setting === "showNameTags" ) {
261- this . devtoolsSettings = {
262- ... this . devtoolsSettings ,
263- showNameTags : value ,
264- }
265- ForesightDevtools . instance . alterDevtoolsSettings ( { showNameTags : value } )
266- this . _updateChangedSettings ( )
271+ if ( ! setting . startsWith ( "show." ) ) return
272+ const key = setting . slice ( "show." . length ) as ShowKey
273+ if ( ! SHOW_KEYS . includes ( key ) ) return
274+
275+ this . devtoolsSettings = {
276+ ... this . devtoolsSettings ,
277+ show : { ... this . devtoolsSettings . show , [ key ] : value } ,
267278 }
279+ ForesightDevtools . instance . alterDevtoolsSettings ( { show : { [ key ] : value } } )
280+ this . _updateChangedSettings ( )
268281 }
269282
270283 private _handleTouchDeviceStrategyChange = ( value : string ) : void => {
@@ -475,10 +488,31 @@ export class SettingsTab extends LitElement {
475488 < div class ="settings-group ">
476489 < h4 > Developer Tools</ h4 >
477490 < setting-item-checkbox
478- .isChecked =${ this . devtoolsSettings . showNameTags }
491+ .isChecked =${ this . devtoolsSettings . show . nameTags }
479492 header ="Show Name Tags"
480493 description="Display name tags over each registered element in the debugger"
481- setting="showNameTags"
494+ setting="show.nameTags"
495+ @setting-changed=${ this . _handleDevtoolsSettingChange }
496+ > </ setting-item-checkbox >
497+ < setting-item-checkbox
498+ .isChecked =${ this . devtoolsSettings . show . elementOverlays }
499+ header ="Show Element Overlays"
500+ description="Render hit-slop boundary overlays around registered elements. Note: turning this off also hides name tags."
501+ setting="show.elementOverlays"
502+ @setting-changed=${ this . _handleDevtoolsSettingChange }
503+ > </ setting-item-checkbox >
504+ < setting-item-checkbox
505+ .isChecked =${ this . devtoolsSettings . show . mouseTrajectory }
506+ header ="Show Mouse Trajectory"
507+ description="Render the predicted mouse trajectory line"
508+ setting="show.mouseTrajectory"
509+ @setting-changed=${ this . _handleDevtoolsSettingChange }
510+ > </ setting-item-checkbox >
511+ < setting-item-checkbox
512+ .isChecked =${ this . devtoolsSettings . show . scrollTrajectory }
513+ header ="Show Scroll Trajectory"
514+ description="Render the predicted scroll trajectory line"
515+ setting="show.scrollTrajectory"
482516 @setting-changed=${ this . _handleDevtoolsSettingChange }
483517 > </ setting-item-checkbox >
484518 < setting-item
0 commit comments