testdrive-jsui/types/index.d.ts

70 lines
1.9 KiB
TypeScript
Raw Normal View History

/**
* Hand-written type declarations for testdrive-jsui (public API of the
* TestDriveJSUI class). Kept in types/ (tracked) because dist/ is generated
* and git-ignored. Update together with js/testdrive-jsui.js.
*/
export type Mode = 'edit' | 'view';
export type ControlPosition = 'nw' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w';
export interface TestDriveJSUIControls {
editControl?: boolean;
statusControl?: boolean;
contentsControl?: boolean;
debugControl?: boolean;
simpleControls?: boolean;
}
export interface TestDriveJSUIControlPositions {
editControl?: ControlPosition;
statusControl?: ControlPosition;
contentsControl?: ControlPosition;
debugControl?: ControlPosition;
}
export interface TestDriveJSUIOptions {
/** CSS selector or element that hosts the editor (required). */
container: string | HTMLElement;
markdown?: string;
mode?: Mode;
theme?: string;
autosave?: boolean;
shortcuts?: boolean;
sections?: boolean;
debug?: boolean;
controls?: TestDriveJSUIControls;
controlPositions?: TestDriveJSUIControlPositions;
[key: string]: unknown;
}
export interface TestDriveJSUIStatus {
mode: Mode;
totalSections?: number;
editingSections?: number;
modifiedSections?: number;
wordCount: number;
characterCount: number;
}
export class TestDriveJSUI {
constructor(options: TestDriveJSUIOptions);
readonly config: TestDriveJSUIOptions;
readonly isInitialized: boolean;
getMarkdown(): string;
setMarkdown(markdown: string): void;
getStatus(): TestDriveJSUIStatus;
getWordCount(): number;
applyTheme(themeName: string): void;
save(): void;
download(filename?: string): void;
resetAll(): void;
toggleDebug(): void;
on(event: string, callback: (data?: any) => void): void;
off(event: string, callback: (data?: any) => void): void;
emit(event: string, data?: unknown): void;
destroy(): void;
}
export const version: string;
export default TestDriveJSUI;