@jirkasa/code-box
Version:
Showcase code samples on the web with a container that lets users select and display different samples.
106 lines (105 loc) • 4.76 kB
TypeScript
import CodeView from "../../code-view/CodeView";
import CodeBox, { CodeBoxItemInfo } from "../CodeBox";
import CodeBoxMemento from "../CodeBoxMemento";
import TabCodeBoxCodeView from "./TabCodeBoxCodeView";
import TabCodeBoxFile from "./TabCodeBoxFile";
import TabCodeBoxOptions from "./TabCodeBoxOptions";
/** Tab code box. */
declare class TabCodeBox extends CodeBox {
/** Path to SVG sprite. */
private readonly svgSpritePath;
/** Name of icon for code view buttons. */
private readonly codeFileIconName;
/** Name of icon for file buttons. */
private readonly fileIconName;
/** Name of download icon for file buttons. */
private readonly downloadIconName;
/** Container for code view and file buttons. */
private tabsContainer;
/** Event source to set active code view of code box. */
private showCodeViewEventSource;
/** Memento created after initialization of code box. */
private initialMemento;
/** Code views stored by identifiers. */
private codeViews;
/** Code view entries stored by code views. */
private codeViewEntries;
/** File entries stored by identifiers. */
private fileEntries;
/**
* Creates new tab code box.
* @param element Code box root element.
* @param options Code box options.
*/
constructor(element: HTMLElement, options?: TabCodeBoxOptions);
addCodeView(identifier: string, codeView: CodeView): boolean;
/**
* Adds new code view to code box without making copy of code view.
* @param identifier Identifier under which the code view should be added to code box.
* @param codeView Code view.
* @returns Indicates whether code view has been successfully added.
*/
private _addCodeView;
getCodeViews(): TabCodeBoxCodeView[];
getCodeView(identifier: string): TabCodeBoxCodeView | null;
removeCodeView(identifier: string): boolean;
removeAllCodeViews(): void;
changeCodeViewIdentifier(identifier: string, newIdentifier: string): boolean;
/**
* Returns position of code view button.
* @param identifier Identifier of code view.
* @returns Position of code view button starting from 0 (or null if code view does not exist).
*/
getCodeViewButtonPosition(identifier: string): number | null;
/**
* Changes position of code view button by swapping it with different code view or file button.
* @param identifier Identifier of code view.
* @param position Position of code view or file button (starting from 0) with which should be code view button swapped.
* @returns Indicates whether the position has been successfully changed.
*/
setCodeViewButtonPosition(identifier: string, position: number): boolean;
setActiveCodeView(identifier: string): boolean;
setNoActiveCodeView(): void;
getActiveCodeView(): TabCodeBoxCodeView | null;
addFile(identifier: string, downloadLink?: string | null): boolean;
getFiles(): TabCodeBoxFile[];
getFile(identifier: string): TabCodeBoxFile | null;
removeFile(identifier: string): boolean;
removeAllFiles(): void;
changeFileIdentifier(identifier: string, newIdentifier: string): boolean;
changeFileDownloadLink(identifier: string, newDownloadLink: string | null): boolean;
/**
* Returns position of file button.
* @param identifier Identifier of file.
* @returns Position of file button starting from 0 (or null if file does not exist).
*/
getFileButtonPosition(identifier: string): number | null;
/**
* Changes position of file button by swapping it with different code view or file button.
* @param identifier Identifier of file.
* @param position Position of code view or file button (starting from 0) with which should be file button swapped.
* @returns Indicates whether the position has been successfully changed.
*/
setFileButtonPosition(identifier: string, position: number): boolean;
reset(): void;
createMemento(): CodeBoxMemento;
applyMemento(memento: CodeBoxMemento): void;
protected onInit(codeBoxItemInfos: CodeBoxItemInfo[]): void;
protected onAfterInit(): void;
/**
* Called by code view buttons when they are clicked.
* @param codeViewButton Code view button that requested change of active code view.
* @param codeView Code view that should be set as active.
*/
private onShowCodeView;
/**
* Decrements positions of all code views and files that have position after passed position.
* @param position Position.
*/
private decrementItemPositionsAfterPosition;
/**
* Updates code view and file buttons based on positions.
*/
private updateButtonsOrder;
}
export default TabCodeBox;