-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenhancer.ts
More file actions
52 lines (47 loc) · 1.51 KB
/
enhancer.ts
File metadata and controls
52 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { OverTypeInstance } from "overtype"
import type { ReactNode } from "react"
/**
* Stores enough info about the location of a draft to:
* - display it in a table
* - reopen the draft in-context
*/
export interface CommentSpot {
unique_key: string
type: string
}
export type CommentEventType = "ENHANCED" | "LOST_FOCUS" | "DESTROYED"
export interface CommentEvent {
type: CommentEventType
spot: CommentSpot
draft?: string
}
/**
* Minimal location information that enhancers need for routing decisions.
* Avoids dependency on global window/location objects for better testability.
*/
export interface StrippedLocation {
host: string
pathname: string
search: string
}
/** Wraps the textareas of a given platform with Gitcasso's enhancements. */
export interface CommentEnhancer<Spot extends CommentSpot = CommentSpot> {
/** Guarantees to only return a type within this list. */
forSpotTypes(): string[]
/**
* Whenever a new `textarea` is added to any webpage, this method is called.
* If we return non-null, then we become the handler for that text area.
*/
tryToEnhance(
textarea: HTMLTextAreaElement,
location: StrippedLocation
): Spot | null
/**
* If `tryToEnhance` returns non-null, then this gets called.
*/
enhance(textarea: HTMLTextAreaElement, spot: Spot): OverTypeInstance
/** Returns a ReactNode which will be displayed in the table row. */
tableUpperDecoration(spot: Spot): ReactNode
/** The default title of a row */
tableTitle(spot: Spot): string
}