import { Node } from '@tiptap/core'; import { GeneralOptions } from '../../types'; export * from './components/RichTextPoll'; export interface PollOption { id: string; label: string; votes: number; } export interface PollCreateInput { question: string; options: string[]; } export interface PollCreateResult { pollId: string; question?: string; options?: PollOption[]; totalVotes?: number; viewerVoteOptionId?: string | null; closed?: boolean; } export interface PollVoteInput { pollId: string; optionId: string; } export interface PollUpdateOptionInput { id?: string; label: string; } export interface PollUpdateInput { pollId: string; question: string; options: PollUpdateOptionInput[]; } export interface PollResults { pollId: string; question?: string; options: PollOption[]; totalVotes?: number; viewerVoteOptionId?: string | null; closed?: boolean; } export interface SetPollAttrsOptions { pollId: string; question: string; options: PollOption[]; totalVotes?: number; viewerVoteOptionId?: string | null; closed?: boolean; } export interface PollOptions extends GeneralOptions { HTMLAttributes: Record; /** * Called when a creator inserts a poll. Return the DB id and normalized * option ids that should be stored in the editor document. */ createPoll?: (input: PollCreateInput) => Promise; /** * Called when a creator edits a poll. Existing option ids should be * preserved so prior votes remain attached to the same choice. */ updatePoll?: (input: PollUpdateInput) => Promise; /** * Called when a reader votes. The host app should persist the vote and * return the latest result distribution for the authenticated viewer. */ votePoll?: (input: PollVoteInput) => Promise; /** * Called when a poll node mounts so the viewer sees fresh DB-backed results. */ getPollResults?: (pollId: string) => Promise; /** * Optional host-side guard for voting. Useful for auth, memberships, or * feature gates that live outside the editor package. */ canVote?: (attrs: SetPollAttrsOptions) => boolean; /** * Optional host-side guard for creator edits. Use this to lock live polls * after publish, after votes arrive, or after a poll closes. */ canEditPoll?: (attrs: SetPollAttrsOptions) => boolean; /** * Show the distribution before the viewer has voted. */ showResultsBeforeVote?: boolean; /** * Allow clicking a different option after voting. */ allowRevote?: boolean; /** * Fetch live results when the node view mounts. */ refreshOnMount?: boolean; /** * Called when create, refresh, or vote callbacks throw. */ onError?: (error: Error) => void; } declare module "@tiptap/core" { interface Commands { poll: { /** * Insert a poll node with a backend poll id and option ids. */ setPoll: (options: SetPollAttrsOptions) => ReturnType; /** * Update the selected poll's persisted metadata. */ updatePoll: (options: Partial) => ReturnType; }; } } export declare const Poll: Node;