UNPKG

@jirkasa/code-box

Version:

Showcase code samples on the web with a container that lets users select and display different samples.

129 lines (128 loc) 4.18 kB
import CodeViewMemento from "../code-view/CodeViewMemento"; import HighlightBox from "../code-view/HighlightBox"; import CodeView from "../code-view/CodeView"; import CodeBox from "./CodeBox"; import CodeBoxCodeViewManager from "./CodeBoxCodeViewManager"; /** Represents code view of code box. */ declare class CodeBoxCodeView<T extends CodeBox = CodeBox> { /** Identifier of code view. */ protected identifier: string; /** Code view. */ protected codeView: CodeView; /** Code box to which code view belongs. */ protected codeBox: T | null; /** Line height of code. */ readonly lineHeight: number; /** Line height unit of code. */ readonly lineHeightUnit: string; /** Number of lines of code. */ readonly linesCount: number; /** * Creates new code box code view. * @param identifier Identifier. * @param codeView Code view. * @param codeBox Code box to which code view belongs. * @param manager Manager of code box code view. */ constructor(identifier: string, codeView: CodeView, codeBox: T, manager: CodeBoxCodeViewManager); /** * Returns identifier of code view. * @returns Identifier. */ getIdentifier(): string | null; /** * Changes identifier of code view. * @param newIdentifier New identifier. * @returns Indicates whether change has been successfully completed (if passed new identifier already belongs to some other code view in code box, it returns false). */ changeIdentifier(newIdentifier: string): boolean; /** * Sets code view as active (displays it in code box). */ setAsActive(): void; /** * Removes code view from code box. */ remove(): void; /** * Resets code view to its initial state. */ reset(): void; /** * Creates memento. * @returns Memento. */ createMemento(): CodeViewMemento; /** * Applies memento. * @param memento Memento. */ applyMemento(memento: CodeViewMemento): void; /** * Returns copy of code view. * @returns Copy of code view. */ clone(): CodeView; /** * Adds new highlight. * @param start Start line of highlight. * @param end End line of highlight (default is the same as start line). * @param customCssClass Custom CSS class(es) to be added to highlight element. * @returns Created highlight box. */ addHighlight(start: number, end?: number, customCssClass?: string | string[] | null): HighlightBox; /** * Removes highlights based on passed range (all intersecting highlights are removed). * @param start Start line. * @param end End line (default is the same as start line). */ removeHighlights(start?: number | null, end?: number | null): void; /** * Returns all highlight boxes in passed range (if no parameters are passed or null is passed, all highlight boxes are returned). * @param start Start line. * @param end End line (default is the same as start line). * @returns Highlight boxes. */ getHighlightBoxes(start?: number | null, end?: number | null): Array<HighlightBox>; /** * Shows gutter. */ showGutter(): void; /** * Hides gutter. */ hideGutter(): void; /** * Checks whether gutter is visible. * @returns Indicates whether gutter is visible. */ isGutterVisible(): boolean; /** * Shows line numbers. */ showLineNumbers(): void; /** * Hides line numbers. */ hideLineNumbers(): void; /** * Checks whether line numbers are visible. * @returns Indicates whether line numbers are visible. */ areLineNumbersVisible(): boolean; /** * Returns displayed code. * @returns Displayed code. */ getCode(): string; /** * Called by code view manager when identifier should be changed. * @param newIdentifier New identifier. */ private onIdentifierChange; /** * Called by code view manager when code view should be unlinked from code box. */ private onUnlinkCodeBox; } export default CodeBoxCodeView;