glossaryMark.ts

glossaryMark.ts

ProseMirror plugin providing hover tooltips and click-to-navigate behavior for glossaryLink marks. Includes caching and event-driven cache invalidation.

Source: src/lib/components/editor/proseMirror/plugins/glossaryMark.ts

Exports

Export Kind Description
createGlossaryMarkPlugin function Factory function — creates a ProseMirror plugin instance from a GlossaryMarkProvider
GlossaryMarkProvider interface Contract defining term info retrieval and navigation callbacks

GlossaryMarkProvider Interface

interface GlossaryMarkProvider {
    getTermInfo(termId: string): Promise<{
        term: string;
        shortDefinition: string;
        enableHyperlink: boolean;
        enableTooltip: boolean;
    } | null>;
    navigateToTerm(termId: string, termSlug: string): void;
}

TooltipManager (Internal)

The TooltipManager class is an internal implementation detail that manages the tooltip DOM element and its lifecycle:

Defined in the ProseMirror schema (src/lib/components/editor/proseMirror/schema.ts):

Attribute Type Default Description
termId string required Glossary entry UUID
termSlug string '' URL-safe slug for the term
color string '' CSS color for the dotted underline
hoverColor string '' CSS color for the hover background
enableHyperlink boolean false Whether clicking the mark navigates to the entry

Rendered DOM

When a glossaryLink mark is rendered in the editor, it produces the following HTML structure:

<span class="glossary-mark [glossary-mark-hyperlink]"
      data-glossary-term="{termId}" data-glossary-slug="{termSlug}"
      data-glossary-color="{color}" data-glossary-hover-color="{hoverColor}"
      data-enable-hyperlink="true|false"
      style="border-bottom-color: {color}; --glossary-mark-hover-bg: {hoverColor}">

CSS

Provider Wiring

The provider is wired in TextEditor.svelte when the ProseMirror editor is initialized:

Dependencies

Dependency Type Purpose
ProseMirror external Editor framework — Plugin, PluginKey, EditorView
glossaryApi internal Fetch term info for tooltips (via provider)
moduleEventBus internal Subscribe to entry-saved/deleted events for cache invalidation

Side Effects