@jirkasa/code-box
Version:
Showcase code samples on the web with a container that lets users select and display different samples.
48 lines (47 loc) • 2.2 kB
TypeScript
import CodeViewOptions from "../code-view/CodeViewOptions";
import CodeView from "../code-view/CodeView";
/** Entry for a CodeView created by code view creator along with the dataset of its corresponding HTML pre element. */
export type CodeViewCreatorEntry = {
/** Code view. */
codeView: CodeView;
/** Dataset of HTML pre element used to create the code view. */
preElementDataset: DOMStringMap;
};
/** Manages the creation of code views. */
declare class CodeViewCreator {
/** Created code views stored by pre element. */
private createdCodeViews;
/** Stores created code views by id (code views with no id are not stored). */
private createdCodeViewsById;
/** Default code view options used, when no options are provided to the create method. */
private defaultCodeViewOptions;
/**
* Creates new code view creator.
* @param defaultCodeViewOptions Default code view options to be used, when no options are provided to the create method.
*/
constructor(defaultCodeViewOptions?: CodeViewOptions);
/**
* Creates code views based on the provided selector.
* @param selector Selector used to find HTML pre elements to create code views from.
* @param codeViewOptions The options to be used, when creating code views. Defaults to the internal default options (provided to constructor).
* @returns Number of created code views.
*/
create(selector: string, codeViewOptions?: CodeViewOptions): number;
/**
* Returns created code view by id.
* @param id Id of created code view.
* @returns Code view (or null if code view was not found).
*/
getCreatedCodeViewById(id: string): CodeView | null;
/**
* Returns all created code views along with the dataset of their corresponding HTML `<pre>` elements.
* @returns An array of objects, each containing a created CodeView instance and the dataset of the HTML `<pre>` element.
*/
getCreatedCodeViews(): CodeViewCreatorEntry[];
/**
* Returns the number of created code views.
* @returns The number of created code views.
*/
getCreatedCodeViewsCount(): number;
}
export default CodeViewCreator;