Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit a11d2d7

Browse files
ijsnowfelixfbecker
authored andcommitted
feat: wip browser ext support
1 parent deea250 commit a11d2d7

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.0-DEVELOPMENT",
44
"description": "Adds code intelligence to code views on the web",
55
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
67
"files": [
78
"lib"
89
],

src/HoverOverlay.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.hover-overlay {
2+
$color-border: #2b3750;
3+
$color-light-border: #cad2e2;
4+
25
position: absolute;
36
width: 30rem;
47
max-height: 15rem;

src/HoverOverlay.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import InformationOutlineIcon from 'mdi-react/InformationOutlineIcon'
66
import * as React from 'react'
77
import { MarkedString, MarkupContent, MarkupKind } from 'vscode-languageserver-types'
88
import { asError, ErrorLike, isErrorLike } from './errors'
9-
import { highlightCodeSafe, renderMarkdown } from './helpers'
9+
import { highlightCodeSafe, renderMarkdown, toNativeEvent } from './helpers'
1010
import { HoveredTokenContext } from './hoverifier'
1111
import { HoveredToken } from './token_position'
1212
import { HoverMerged, LOADING } from './types'
@@ -59,10 +59,10 @@ export interface HoverOverlayProps {
5959
linkComponent: React.ComponentType<{ to: string }>
6060

6161
/** Called when the Go-to-definition button was clicked */
62-
onGoToDefinitionClick?: (event: React.MouseEvent<HTMLElement>) => void
62+
onGoToDefinitionClick?: (event: MouseEvent) => void
6363

6464
/** Called when the close button is clicked */
65-
onCloseButtonClick?: (event: React.MouseEvent<HTMLElement>) => void
65+
onCloseButtonClick?: (event: MouseEvent) => void
6666

6767
logTelemetryEvent: (event: string, data?: any) => void
6868
}
@@ -71,6 +71,9 @@ export interface HoverOverlayProps {
7171
export const isJumpURL = (val: any): val is { jumpURL: string } =>
7272
val !== null && typeof val === 'object' && typeof val.jumpURL === 'string'
7373

74+
const transformMouseEvent = (handler: (event: MouseEvent) => void) => (event: React.MouseEvent<HTMLElement>) =>
75+
handler(toNativeEvent(event))
76+
7477
export const HoverOverlay: React.StatelessComponent<HoverOverlayProps> = props => (
7578
<div
7679
className="hover-overlay card"
@@ -91,10 +94,14 @@ export const HoverOverlay: React.StatelessComponent<HoverOverlayProps> = props =
9194
}
9295
>
9396
{props.showCloseButton && (
94-
<button className="hover-overlay__close-button btn btn-icon" onClick={props.onCloseButtonClick}>
97+
<button
98+
className="hover-overlay__close-button btn btn-icon"
99+
onClick={props.onCloseButtonClick ? transformMouseEvent(props.onCloseButtonClick) : undefined}
100+
>
95101
<CloseIcon className="icon-inline" />
96102
</button>
97103
)}
104+
98105
{props.hoverOrError && (
99106
<div className="hover-overlay__contents">
100107
{props.hoverOrError === LOADING ? (
@@ -157,7 +164,7 @@ export const HoverOverlay: React.StatelessComponent<HoverOverlayProps> = props =
157164
linkComponent={props.linkComponent}
158165
to={isJumpURL(props.definitionURLOrError) ? props.definitionURLOrError.jumpURL : undefined}
159166
className="btn btn-secondary hover-overlay__action e2e-tooltip-j2d"
160-
onClick={props.onGoToDefinitionClick}
167+
onClick={props.onGoToDefinitionClick ? transformMouseEvent(props.onGoToDefinitionClick) : undefined}
161168
>
162169
Go to definition {props.definitionURLOrError === LOADING && <Loader className="icon-inline" />}
163170
</ButtonOrLink>

src/helpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { highlight, highlightAuto } from 'highlight.js/lib/highlight'
22
import marked from 'marked'
3+
import * as React from 'react'
34
import sanitize from 'sanitize-html'
45
import { MarkupContent } from 'vscode-languageserver-types'
56
import { HoverOverlayProps, isJumpURL } from './HoverOverlay'
@@ -87,3 +88,13 @@ export const renderMarkdown = (markdown: string): string =>
8788
highlight: (code, language) => '<code>' + highlightCodeSafe(code, language) + '</code>',
8889
})
8990
)
91+
92+
/**
93+
* Converts a synthetic React event to a persisted, native Event object.
94+
*
95+
* @param event The synthetic React event object
96+
*/
97+
export const toNativeEvent = <E extends React.SyntheticEvent<T>, T>(event: E): E['nativeEvent'] => {
98+
event.persist()
99+
return event.nativeEvent
100+
}

0 commit comments

Comments
 (0)