@@ -6,33 +6,36 @@ import * as Common from '../../../core/common/common.js';
66import * as Root from '../../../core/root/root.js' ;
77import type * as SDK from '../../../core/sdk/sdk.js' ;
88
9- import type { AnnotationType } from './AnnotationType.js' ;
9+ import { AnnotationType } from './AnnotationType.js' ;
1010
11- interface AnnotationData {
11+ interface BaseAnnotationData {
1212 id : number ;
1313 type : AnnotationType ;
1414 message : string ;
1515 // Sometimes the anchor for an annotation is not known, but is provided using a
1616 // string id instead (which can be converted to an `anchor` later).
1717 lookupId : string ;
18- // What to anchor the annotation to.
19- anchor ?: SDK . DOMModel . DOMNode | SDK . NetworkRequest . NetworkRequest | null ;
2018 // Sometimes we want annotations to anchor to a particular string on the page.
2119 anchorToString ?: string ;
2220}
2321
22+ interface ElementsAnnotationData extends BaseAnnotationData {
23+ type : AnnotationType . ELEMENT_NODE ;
24+ anchor ?: SDK . DOMModel . DOMNode ;
25+ }
26+
2427export const enum Events {
2528 ANNOTATION_ADDED = 'AnnotationAdded' ,
2629}
2730
2831export interface EventTypes {
29- [ Events . ANNOTATION_ADDED ] : AnnotationData ;
32+ [ Events . ANNOTATION_ADDED ] : BaseAnnotationData ;
3033}
3134
3235export class AnnotationRepository {
3336 static #instance: AnnotationRepository | null = null ;
3437 #events = new Common . ObjectWrapper . ObjectWrapper < EventTypes > ( ) ;
35- #annotations: AnnotationData [ ] = [ ] ;
38+ #annotations: BaseAnnotationData [ ] = [ ] ;
3639 #nextId = 0 ;
3740
3841 static instance ( ) : AnnotationRepository {
@@ -55,7 +58,7 @@ export class AnnotationRepository {
5558 return this . #events. addEventListener ( eventType , listener , thisObject ) ;
5659 }
5760
58- getAnnotationsByType ( type : AnnotationType ) : AnnotationData [ ] {
61+ getAnnotationsByType ( type : AnnotationType ) : BaseAnnotationData [ ] {
5962 if ( ! AnnotationRepository . annotationsEnabled ( ) ) {
6063 console . warn ( 'Received query for annotation types with annotations disabled' ) ;
6164 return [ ] ;
@@ -65,23 +68,23 @@ export class AnnotationRepository {
6568 return annotations ;
6669 }
6770
68- addAnnotationWithAnchor (
71+ addElementsAnnotation (
6972 label : string ,
70- anchor : SDK . DOMModel . DOMNode | SDK . NetworkRequest . NetworkRequest | string | null ,
71- type : AnnotationType ,
72- anchorToString = '' ,
73+ lookupId ?: string ,
74+ anchor ?: SDK . DOMModel . DOMNode ,
75+ anchorToString ?: string ,
7376 ) : void {
7477 if ( ! AnnotationRepository . annotationsEnabled ( ) ) {
7578 console . warn ( 'Received annotation registration with annotations disabled' ) ;
7679 return ;
7780 }
7881
79- const annotationData = {
82+ const annotationData : ElementsAnnotationData = {
8083 id : this . #nextId++ ,
81- type,
84+ type : AnnotationType . ELEMENT_NODE ,
8285 message : label ,
83- lookupId : typeof anchor === 'string' ? anchor : 'None ',
84- anchor : typeof anchor === 'string' ? null : anchor ,
86+ lookupId : lookupId || ' ',
87+ anchor,
8588 anchorToString
8689 } ;
8790 this . #annotations. push ( annotationData ) ;
0 commit comments