Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit bf7f5ec

Browse files
authored
Svelte: implement preview panel (#61013)
This implements the basics of the preview panel in Svelte.
1 parent e66a83c commit bf7f5ec

20 files changed

+607
-295
lines changed

client/web-sveltekit/src/lib/repo/blob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ interface BlobDataHandler extends Readable<CombinedBlobData> {
157157

158158
/**
159159
* This store synchronizes the state of the blob data and the highlights. While new blob data is
160-
* loading, the old blob and highlighs data is still available. Once the blob data is loaded, the
160+
* loading, the old blob and highlights data is still available. Once the blob data is loaded, the
161161
* highlights are updated.
162162
*/
163163
export function createBlobDataHandler(): BlobDataHandler {

client/web-sveltekit/src/lib/search/input/SearchInput.svelte

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
// - History more
44
// - Default context support
55
// - Global keyboard shortcut
6-
import { mdiCodeBrackets, mdiFormatLetterCase, mdiRegex } from '@mdi/js'
7-
8-
import { goto, invalidate } from '$app/navigation'
9-
import { SearchPatternType } from '$lib/graphql-operations'
10-
import Icon from '$lib/Icon.svelte'
11-
import Tooltip from '$lib/Tooltip.svelte'
12-
13-
import { type QueryStateStore, getQueryURL, QueryState } from '../state'
14-
import BaseCodeMirrorQueryInput from '$lib/search/BaseQueryInput.svelte'
15-
import { createSuggestionsSource } from '$lib/web'
16-
import { query, type DocumentInput } from '$lib/graphql'
17-
import Suggestions from './Suggestions.svelte'
18-
import { user } from '$lib/stores'
196
207
import { EditorSelection, EditorState, Prec, type Extension } from '@codemirror/state'
218
import { EditorView } from '@codemirror/view'
9+
import { mdiCodeBrackets, mdiFormatLetterCase, mdiRegex } from '@mdi/js'
10+
11+
import { goto, invalidate } from '$app/navigation'
2212
import {
2313
type Option,
2414
type Action,
@@ -35,7 +25,18 @@
3525
onModeChange,
3626
setMode,
3727
} from '$lib/branded'
28+
import { query, type DocumentInput } from '$lib/graphql'
29+
import { SearchPatternType } from '$lib/graphql-operations'
30+
import Icon from '$lib/Icon.svelte'
31+
import BaseCodeMirrorQueryInput from '$lib/search/BaseQueryInput.svelte'
32+
import { user } from '$lib/stores'
33+
import Tooltip from '$lib/Tooltip.svelte'
34+
import { createSuggestionsSource } from '$lib/web'
35+
36+
import { type QueryStateStore, getQueryURL, QueryState } from '../state'
37+
3838
import { createRecentSearchesStore } from './recentSearches'
39+
import Suggestions from './Suggestions.svelte'
3940
4041
const placeholderText = 'Search for code or files...'
4142
@@ -372,10 +373,6 @@
372373
cursor: pointer;
373374
}
374375
375-
button.mode {
376-
clear: all;
377-
}
378-
379376
.mode-switcher {
380377
display: flex;
381378
align-items: center;

client/web-sveltekit/src/lib/search/state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { writable, type Readable } from 'svelte/store'
22

3-
import { goto } from '$app/navigation'
43
import { SearchPatternType } from '$lib/graphql-operations'
54
import { buildSearchURLQuery, type Settings } from '$lib/shared'
65
import { defaultSearchModeFromSettings, defaultPatternTypeFromSettings } from '$lib/web'

client/web-sveltekit/src/lib/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export {
4848
type Progress,
4949
type Range,
5050
type Filter,
51+
type SearchEvent,
5152
} from '@sourcegraph/shared/src/search/stream'
5253
export {
5354
type MatchItem,

client/web-sveltekit/src/lib/utils/promises.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,19 @@ export function createPromiseStore<D, E = Error>(): PromiseStore<D, E> {
8181
},
8282
}
8383
}
84+
85+
/**
86+
* Returns a store that publishes updates when the promise is resolved or rejected.
87+
*/
88+
export function toReadable<D, E = Error>(promise: PromiseLike<D>): Readable<Result<D, E>> {
89+
const resultStore = writable<Result<D, E>>({ value: null, error: null, pending: true })
90+
promise.then(
91+
result => {
92+
resultStore.set({ value: result, error: null, pending: false })
93+
},
94+
error => {
95+
resultStore.set({ value: null, error: error, pending: false })
96+
}
97+
)
98+
return resultStore
99+
}

client/web-sveltekit/src/lib/wildcard/menu/Menu.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
} = createDropdownMenu({
3535
open,
3636
})
37-
setContext({ item, trigger, separator, builders, open })
37+
setContext({ item, trigger, separator, builders, $open })
3838
</script>
3939

4040
<button {...$trigger} use:trigger class={triggerButtonClass} {...$$restProps}>

client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/-/blob/[...path]/+page.svelte

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22

33
<script lang="ts">
44
import { mdiCodeBracesBox, mdiFileCodeOutline, mdiMapSearch } from '@mdi/js'
5+
import { from } from 'rxjs'
56
7+
import { goto } from '$app/navigation'
68
import { page } from '$app/stores'
79
import CodeMirrorBlob from '$lib/CodeMirrorBlob.svelte'
10+
import { isErrorLike, type LineOrPositionOrRange } from '$lib/common'
11+
import { toGraphQLResult } from '$lib/graphql'
812
import Icon from '$lib/Icon.svelte'
913
import LoadingSpinner from '$lib/LoadingSpinner.svelte'
14+
import { updateSearchParamsWithLineInformation, createBlobDataHandler } from '$lib/repo/blob'
15+
import FileDiff from '$lib/repo/FileDiff.svelte'
1016
import FileHeader from '$lib/repo/FileHeader.svelte'
1117
import Permalink from '$lib/repo/Permalink.svelte'
12-
13-
import FileDiff from '$lib/repo/FileDiff.svelte'
18+
import { createCodeIntelAPI, parseQueryAndHash } from '$lib/shared'
19+
import { Alert } from '$lib/wildcard'
1420
1521
import type { PageData } from './$types'
1622
import FormatAction from './FormatAction.svelte'
1723
import WrapLinesAction, { lineWrap } from './WrapLinesAction.svelte'
18-
import { createCodeIntelAPI, parseQueryAndHash } from '$lib/shared'
19-
import { goto } from '$app/navigation'
20-
import { updateSearchParamsWithLineInformation, createBlobDataHandler } from '$lib/repo/blob'
21-
import { isErrorLike, type LineOrPositionOrRange } from '$lib/common'
22-
import { from } from 'rxjs'
23-
import { toGraphQLResult } from '$lib/graphql'
24-
import { Alert } from '$lib/wildcard'
2524
2625
export let data: PageData
2726

client/web-sveltekit/src/routes/search/FileContentSearchResult.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import { settings } from '$lib/stores'
2626
2727
import FileSearchResultHeader from './FileSearchResultHeader.svelte'
28+
import PreviewButton from './PreviewButton.svelte'
2829
import RepoStars from './RepoStars.svelte'
2930
import SearchResult from './SearchResult.svelte'
3031
import { getSearchResultsContext } from './searchResultsContext'
@@ -97,6 +98,7 @@
9798
{#if result.repoStars}
9899
<RepoStars repoStars={result.repoStars} />
99100
{/if}
101+
<PreviewButton {result} />
100102
</svelte:fragment>
101103

102104
<div bind:this={root} use:observeIntersection on:intersecting={event => (visible = event.detail)} class="matches">

client/web-sveltekit/src/routes/search/FilePathSearchResult.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import type { PathMatch } from '$lib/shared'
66
77
import FileSearchResultHeader from './FileSearchResultHeader.svelte'
8+
import PreviewButton from './PreviewButton.svelte'
89
import RepoStars from './RepoStars.svelte'
910
import SearchResult from './SearchResult.svelte'
1011
@@ -18,5 +19,6 @@
1819
{#if result.repoStars}
1920
<RepoStars repoStars={result.repoStars} />
2021
{/if}
22+
<PreviewButton {result} />
2123
</svelte:fragment>
2224
</SearchResult>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
import type { ContentMatch, PathMatch, SymbolMatch } from '$lib/shared'
3+
import { Button } from '$lib/wildcard'
4+
5+
import { getSearchResultsContext } from './searchResultsContext'
6+
7+
export let result: ContentMatch | SymbolMatch | PathMatch
8+
9+
const searchResultContext = getSearchResultsContext()
10+
</script>
11+
12+
<div class="preview-button">
13+
<Button variant="link" on:click={() => searchResultContext.setPreview(result)}>Preview</Button>
14+
</div>
15+
16+
<style lang="scss">
17+
// Override the padding of the button so it doesn't grow the header.
18+
.preview-button :global(button) {
19+
padding: 0;
20+
}
21+
</style>

0 commit comments

Comments
 (0)