Skip to content

Commit

Permalink
Export HoverTooltipSource type
Browse files Browse the repository at this point in the history
FEATURE: The package now exports the type of hover tooltip sources as
`HoverTooltipSource`.

Closes #66
  • Loading branch information
marijnh committed Jul 24, 2024
1 parent e8d3408 commit 161fba5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ See also the [tooltip example](../../examples/tooltip/).

@hoverTooltip

@HoverTooltipSource

@hasHoverTooltips

@closeHoverTooltips
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export {Rect} from "./dom"
export {layer, LayerMarker, RectangleMarker} from "./layer"
export {MatchDecorator} from "./matchdecorator"
export {rectangularSelection, crosshairCursor} from "./rectangular-selection"
export {showTooltip, Tooltip, TooltipView, tooltips, getTooltip, hoverTooltip, hasHoverTooltips,
export {showTooltip, Tooltip, TooltipView, tooltips, getTooltip, hoverTooltip, HoverTooltipSource, hasHoverTooltips,
closeHoverTooltips, repositionTooltips} from "./tooltip"
export {showPanel, PanelConstructor, Panel, getPanel, panels} from "./panel"
export {lineNumbers, highlightActiveLineGutter, gutter, gutters, GutterMarker,
Expand Down
8 changes: 5 additions & 3 deletions src/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ const showHoverTooltipHost = showTooltip.compute([showHoverTooltip], state => {

const enum Hover { Time = 300, MaxDist = 6 }

type HoverSource = (view: EditorView, pos: number, side: -1 | 1) => Tooltip | readonly Tooltip[] | null | Promise<Tooltip | readonly Tooltip[] | null>
/// The type of function that can be used as a [hover tooltip
/// source](#view.hoverTooltip^source).
export type HoverTooltipSource = (view: EditorView, pos: number, side: -1 | 1) => Tooltip | readonly Tooltip[] | null | Promise<Tooltip | readonly Tooltip[] | null>

class HoverPlugin {
lastMove: {x: number, y: number, target: HTMLElement, time: number}
Expand All @@ -600,7 +602,7 @@ class HoverPlugin {
pending: {pos: number} | null = null

constructor(readonly view: EditorView,
readonly source: HoverSource,
readonly source: HoverTooltipSource,
readonly field: StateField<readonly Tooltip[]>,
readonly setHover: StateEffectType<readonly Tooltip[]>,
readonly hoverTime: number) {
Expand Down Expand Up @@ -746,7 +748,7 @@ function isOverRange(view: EditorView, from: number, to: number, x: number, y: n
/// container element. This allows multiple tooltips over the same
/// range to be "merged" together without overlapping.
export function hoverTooltip(
source: HoverSource,
source: HoverTooltipSource,
options: {
/// Controls whether a transaction hides the tooltip. The default
/// is to not hide.
Expand Down

0 comments on commit 161fba5

Please sign in to comment.