-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
index.ts
128 lines (106 loc) · 3.72 KB
/
index.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { Remote } from 'comlink'
import { Observable } from 'rxjs'
import { HighlightRange } from '@sourcegraph/search-ui'
import { FlatExtensionHostAPI } from '@sourcegraph/shared/src/api/contract'
import { FetchFileParameters } from '@sourcegraph/shared/src/backend/file'
import { AggregateStreamingSearchResults } from '@sourcegraph/shared/src/search/stream'
import { UIRangeSpec } from '@sourcegraph/shared/src/util/url'
import { HighlightLineRange, SymbolKind } from '../graphql-operations'
// When adding a new block type, make sure to track its usage in internal/usagestats/notebooks.go.
export type BlockType = 'md' | 'query' | 'file' | 'compute' | 'symbol'
interface BaseBlock<I, O> {
id: string
type: BlockType
input: I
output: O | null
}
export interface QueryBlockInput {
query: string
initialFocusInput?: boolean
}
export interface QueryBlock extends BaseBlock<QueryBlockInput, Observable<AggregateStreamingSearchResults>> {
type: 'query'
}
export interface MarkdownBlockInput {
text: string
initialFocusInput?: boolean
}
export interface MarkdownBlock extends BaseBlock<MarkdownBlockInput, string> {
type: 'md'
}
export interface FileBlockInput {
repositoryName: string
revision: string
filePath: string
lineRange: HighlightLineRange | null
initialQueryInput?: string
}
export interface FileBlock extends BaseBlock<FileBlockInput, Observable<string[] | Error>> {
type: 'file'
}
export interface ComputeBlock extends BaseBlock<string, string> {
type: 'compute'
}
export interface SymbolBlockInput {
repositoryName: string
revision: string
filePath: string
symbolName: string
symbolKind: SymbolKind
symbolContainerName: string
lineContext: number
initialQueryInput?: string
}
export interface SymbolBlockOutput {
symbolFoundAtLatestRevision: boolean
effectiveRevision: string
symbolRange: UIRangeSpec['range']
highlightLineRange: HighlightLineRange
highlightedLines: string[]
highlightSymbolRange: HighlightRange
}
export interface SymbolBlock extends BaseBlock<SymbolBlockInput, Observable<SymbolBlockOutput | Error>> {
type: 'symbol'
}
export type Block = QueryBlock | MarkdownBlock | FileBlock | ComputeBlock | SymbolBlock
export type BlockInput =
| Pick<FileBlock, 'type' | 'input'>
| Pick<MarkdownBlock, 'type' | 'input'>
| Pick<QueryBlock, 'type' | 'input'>
| Pick<ComputeBlock, 'type' | 'input'>
| Pick<SymbolBlock, 'type' | 'input'>
export type BlockInit =
| Omit<FileBlock, 'output'>
| Omit<MarkdownBlock, 'output'>
| Omit<QueryBlock, 'output'>
| Omit<ComputeBlock, 'output'>
| Omit<SymbolBlock, 'output'>
export type SerializableBlock =
| Pick<FileBlock, 'type' | 'input'>
| Pick<MarkdownBlock, 'type' | 'input'>
| Pick<QueryBlock, 'type' | 'input'>
| Pick<ComputeBlock, 'type' | 'input'>
| Pick<SymbolBlock, 'type' | 'input' | 'output'>
export type BlockDirection = 'up' | 'down'
export interface BlockProps<T extends Block = Block> {
isReadOnly: boolean
isSelected: boolean
showMenu: boolean
id: T['id']
input: T['input']
output: T['output']
onRunBlock(id: string): void
onDeleteBlock(id: string): void
onBlockInputChange(id: string, blockInput: BlockInput): void
onMoveBlock(id: string, direction: BlockDirection): void
onDuplicateBlock(id: string): void
onNewBlock(id: string): void
}
export interface BlockDependencies {
extensionHostAPI: Promise<Remote<FlatExtensionHostAPI>> | null
enableGoImportsSearchQueryTransform: undefined | boolean
fetchHighlightedFileLineRanges: (parameters: FetchFileParameters, force?: boolean) => Observable<string[][]>
}
export interface NotebookProps {
notebooksEnabled: boolean
}