Files
Zef Hemel 09059aa18a Lint: support rich HTML tooltips
LintDiagnostic adds `messageHtml` (rendered into the hover
  tooltip) and `markClass` (added to the inline range mark)
2026-05-09 12:29:19 +02:00

144 lines
3.1 KiB
TypeScript

import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree";
import type { PageMeta } from "@silverbulletmd/silverbullet/type/index";
export type FilterOption = {
name: string;
description?: string;
orderId?: number;
hint?: string;
hintInactive?: boolean;
classes?: string;
prefix?: string;
} & Record<string, any>;
export type NotificationType = "info" | "error" | "warning";
export const notificationDismissTimeouts: Record<NotificationType, number> = {
info: 4000,
error: 5000,
warning: 8000,
};
export type NotificationAction = {
name: string;
run: () => void;
};
export type Notification = {
id: number;
message: string;
type: NotificationType;
date: Date;
actions?: NotificationAction[];
persistent?: boolean;
};
export type PanelMode = number;
export type CodeWidgetContent = {
html?: string;
script?: string;
width?: number;
height?: number;
url?: string;
};
// Document editors stuff
export type DocumentEditorCallback = () => Promise<DocumentEditorContent>;
export type DocumentEditorContent = {
html: string;
};
export type LintDiagnostic = {
from: number;
to: number;
severity: "error" | "warning" | "info" | "hint";
message: string;
/**
* Optional HTML rendered into the hover tooltip for this diagnostic.
* When present, takes precedence over `message` for tooltip display.
* `message` is still used as a plain-text fallback (e.g. in the lint
* panel) and as the diagnostic's accessible label.
*/
messageHtml?: string;
/**
* Optional CSS class added to the inline range mark for this diagnostic,
* in addition to CodeMirror's default `.cm-lintRange-<severity>` class.
*/
markClass?: string;
};
export type UploadFile = {
name: string;
contentType: string;
content: Uint8Array;
};
export type AppEvent =
| "page:click"
| "slash:complete"
| "editor:complete"
| "editor:lint"
| "editor:init"
| "editor:pageLoaded" // args: pageName, previousPage, isSynced
| "editor:pageReloaded"
| "editor:pageSaving"
| "editor:pageSaved"
| "editor:pageCreating"
| "editor:pageModified"
| "editor:documentSaving"
| "editor:documentSaved"
| "editor:modeswitch"
| "editor:fold"
| "editor:unfold"
| "plugs:loaded"
| "cron:secondPassed"
| "hooks:renderTopWidgets"
| "hooks:renderBottomWidgets";
export type ClickEvent = {
page: string;
pos: number;
metaKey: boolean;
ctrlKey: boolean;
altKey: boolean;
};
export type EnrichedClickEvent = ClickEvent & {
parentNodes: string[];
};
export type LintEvent = {
name: string;
pageMeta: PageMeta;
tree: ParseTree;
text: string;
};
export type CompleteEvent = {
pageName: string;
linePrefix: string;
pos: number;
parentNodes: string[];
};
export type SlashCompletionOption = {
label: string;
detail?: string;
invoke: string;
order?: number;
} & Record<string, any>;
export type SlashCompletions = {
// Ignore this one, only for compatibility with regular completions
from?: number;
// The actual completions
options: SlashCompletionOption[];
};
// Code widget stuff
export type CodeWidgetCallback = (
bodyText: string,
pageName: string,
) => Promise<CodeWidgetContent | null>;