import { Observable , fromEvent , merge } from 'rxjs' ; import { distinct , map , pluck , scan , take } from 'rxjs/operators' ; import type { Datatable , ExpressionFunctionDefinition } from 'src/plugins/expressions' ; const EVENTS = [ 'mousedown' , 'mouseup' , 'click' , 'keydown' , 'keyup' , 'keypress' , ] ; export const getEvents = { name : 'getEvents' , type : 'datatable' , help : 'Listens for the window events and returns a table with the triggered ones.' , args : { } , fn ( ) { return merge ( ... EVENTS . map ( ( event ) => fromEvent ( window , event ) ) ) . pipe ( pluck ( 'type' ) , distinct ( ) , take ( EVENTS . length ) , scan ( ( events , event ) => [ ... events , event ] , [ ] as string [ ] ) , map ( ( events ) => ( { type : 'datatable' , columns : [ { id : 'event' , meta : { type : 'string' } , name : 'Event' , } , ] , rows : Array . from ( events ) . map ( ( event ) => ( { event } ) ) , } ) ) ) ; } , } ;