blob: 5617130990cbdb19d37eecf4035f4ae9bd9426ef [file] [log] [blame]
Adrià Vilanova Martínezf92172f2024-10-19 15:55:15 +02001import {
2 NodeMutation,
3 NodeMutationType,
4 NodeWatcherHandler,
5} from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
6
7export default abstract class CssSelectorNodeWatcherHandler
8 implements NodeWatcherHandler
9{
10 readonly mutationTypesProcessed: NodeMutationType[] = [
11 NodeMutationType.InitialDiscovery,
12 NodeMutationType.NewNode,
13 ];
14
15 abstract readonly cssSelector: string;
16
17 nodeFilter(nodeMutation: NodeMutation): boolean {
18 if (
19 !this.mutationTypesProcessed.includes(nodeMutation.type) ||
20 !(nodeMutation.node instanceof Element)
21 ) {
22 return false;
23 }
24 return nodeMutation.node.matches(this.cssSelector);
25 }
26
27 get initialDiscoverySelector() {
28 return this.cssSelector;
29 }
30
Adrià Vilanova Martínez3c13a762024-11-09 23:03:32 +010031 abstract onMutatedNode(nodeMutation: NodeMutation<HTMLElement>): void;
Adrià Vilanova Martínezf92172f2024-10-19 15:55:15 +020032}