@@ -2,6 +2,7 @@ import { Element } from '@core/element'
22import { html , css } from 'lit'
33import { customElement } from 'lit/decorators.js'
44import { consume } from '@lit/context'
5+ import type { CommandLog } from '@devtools/hook/types'
56
67import { context , type TraceLog } from '../../context.js'
78
@@ -15,8 +16,8 @@ const ICON_CLASS = 'w-[20px] h-[20px] m-1 mr-2 shrink-0'
1516const SOURCE_COMPONENT = 'wdio-devtools-actions'
1617@customElement ( SOURCE_COMPONENT )
1718export class DevtoolsActions extends Element {
18- #mutations: MutationRecord [ ] = [ ]
19- #activeMutation ?: number
19+ #entries: ( TraceMutation | CommandLog ) [ ] = [ ]
20+ #activeEntry ?: number
2021 #highlightedMutation?: number
2122
2223 static styles = [ ...Element . styles , css `
@@ -32,28 +33,35 @@ export class DevtoolsActions extends Element {
3233
3334 connectedCallback ( ) : void {
3435 super . connectedCallback ( )
35- this . #mutations = this . data . mutations
36+ this . #entries = [ ...this . data . mutations , ...this . data . commands ]
37+ . sort ( ( a , b ) => a . timestamp - b . timestamp )
3638 }
3739
3840 render ( ) {
39- if ( ! this . #mutations . length ) {
41+ if ( ! this . #entries . length ) {
4042 return html `< section class ="flex items-center justify-center text-sm w-full h-full "> No events logged!</ section > `
4143 }
4244
43- return this . #mutations. map ( ( mutation , i ) => {
45+ return this . #entries. map ( ( entry , i ) => {
46+ if ( 'command' in entry ) {
47+ return html `
48+ < button > ${ entry . command } </ button >
49+ `
50+ }
51+
4452 return html `
4553 < button
4654 @mousemove ="${ ( ) => this . #showMutationTarget( i ) } "
4755 @click ="${ ( ) => this . #selectMutation( i ) } "
48- class ="flex items-center justify-center text-sm w-full px-4 hover:bg-toolbarHoverBackground ${ this . #activeMutation === i ? 'bg-toolbarHoverBackground' : '' } "
56+ class ="flex items-center justify-center text-sm w-full px-4 hover:bg-toolbarHoverBackground ${ this . #activeEntry === i ? 'bg-toolbarHoverBackground' : '' } "
4957 >
50- ${ this . #getMutationLabel( mutation ) }
58+ ${ this . #getMutationLabel( entry ) }
5159 </ button >
5260 `
5361 } )
5462 }
5563
56- #getMutationLabel( mutation : MutationRecord ) {
64+ #getMutationLabel( mutation : TraceMutation ) {
5765 if ( mutation . type === 'attributes' ) {
5866 return this . #getAttributeMutationLabel( mutation )
5967 } else if ( mutation . type === 'childList' ) {
@@ -62,14 +70,14 @@ export class DevtoolsActions extends Element {
6270 return 'Unknown mutation'
6371 }
6472
65- #getAttributeMutationLabel( mutation : MutationRecord ) {
73+ #getAttributeMutationLabel( mutation : TraceMutation ) {
6674 return html `
6775 < icon-mdi-pencil class ="${ ICON_CLASS } "> </ icon-mdi-pencil >
6876 < span class ="flex-grow "> ${ mutation . target } attribute "< code > ${ mutation . attributeName } </ code > " changed</ span >
6977 `
7078 }
7179
72- #getChildListMutationLabel( mutation : MutationRecord ) {
80+ #getChildListMutationLabel( mutation : TraceMutation ) {
7381 if ( mutation . addedNodes . length === 1 && ( mutation . addedNodes [ 0 ] as any ) . type === 'html' ) {
7482 return html `
7583 < icon-mdi-document class ="${ ICON_CLASS } "> </ icon-mdi-document >
@@ -83,9 +91,9 @@ export class DevtoolsActions extends Element {
8391 }
8492
8593 #selectMutation( i : number ) {
86- this . #activeMutation = i
94+ this . #activeEntry = i
8795 const event = new CustomEvent ( 'app-mutation-select' , {
88- detail : this . #mutations [ this . #activeMutation ]
96+ detail : this . #entries [ this . #activeEntry ]
8997 } )
9098 window . dispatchEvent ( event )
9199 this . requestUpdate ( )
@@ -97,7 +105,7 @@ export class DevtoolsActions extends Element {
97105 }
98106 this . #highlightedMutation = i
99107 const event = new CustomEvent ( 'app-mutation-highlight' , {
100- detail : this . #mutations [ i ]
108+ detail : this . #entries [ i ]
101109 } )
102110 window . dispatchEvent ( event )
103111 }
0 commit comments