/** * The cards a block document's writer chose, drawn after the line that holds * each reference — SPEC §13.3, "A reference's card". * * The choice is `embed` on the `reference` node (`ReferenceNode`), so the card * moves and goes with its chip. What a card looks like is the app's — it knows * how to resolve an object and draw its row or its card — so this extension * draws nothing itself: after every textblock whose chips ask for a card it * places one empty, non-editable slot, and `useReferenceCards` hands the app * those slots to portal its cards into. A portal, rather than a React root per * slot, keeps the app's providers around the card. * * **A slot keeps its element while its block lives.** It is keyed by the * nearest block id (the `blockId` attribute), so typing above a card does not * re-make its element, and the card does not reload on every keystroke. * * The slot sits at the end of the textblock, inside it: a paragraph's card is * under the paragraph, a list item's under the item at its indent, a table * cell's in the cell. */ import { Extension, type Editor } from '@tiptap/core'; import type { Node as PmNode } from '@tiptap/pm/model'; import { type EditorState } from '@tiptap/pm/state'; /** A layout a writer can choose; `none` is no card. */ export type ReferenceCardLayout = 'none' | 'compact' | 'detailed'; /** One card to draw: the reference's `nostr:` URI and how much to show. */ export interface ReferenceCard { uri: string; layout: Exclude; } /** One slot: where an app draws the cards of one line. */ export interface ReferenceCardSlot { key: string; element: HTMLElement; cards: ReferenceCard[]; } interface Placement { key: string; /** The end of the textblock's content, where the slot goes. */ pos: number; cards: ReferenceCard[]; } /** Every line that asks for a card, in document order. */ export declare function referenceCardPlacements(doc: PmNode): Placement[]; interface ReferenceCardsStorage { /** One element per slot key, made once and reused, so the app's portal stays put. */ elements: Map; } /** * Places a slot after each line whose chips ask for a card. Pair it with * `ReferenceNode`, and draw the cards with `useReferenceCards`. */ export declare const ReferenceCards: Extension, ReferenceCardsStorage>; /** * The slots to draw cards into, kept current as the document changes. Draw * each with `createPortal(, slot.element)`, keyed by `slot.key`. */ export declare function useReferenceCards(editor: Editor | null): ReferenceCardSlot[]; /** * The chip the person has selected, with what it names and its card — or null. * * Selected as a node (a click, where a click on the chip does not follow its * link), or inside a selected range that holds that one chip and nothing but * spaces besides (Shift+arrow over it, or a drag across it): an app whose chip * is a link has no other way to select it. */ export declare function referenceAtSelection(state: EditorState): { pos: number; uri: string; layout: ReferenceCardLayout; } | null; /** Sets the card of the selected chip. `none` removes it. The selection stays as it was. */ export declare function setReferenceCard(editor: Editor, layout: ReferenceCardLayout): boolean; /** Sets the card of the chip at `pos` — one that names something. `none` removes it. The selection stays as it was. */ export declare function setReferenceCardAt(editor: Editor, pos: number, layout: ReferenceCardLayout): boolean; export {}; //# sourceMappingURL=ReferenceCards.d.ts.map