type ExhibitionOptions = {}; type ExhibitionInitOptions = { init?: boolean; updatePreview?: boolean; }; type MapConfiguration = { editors: { selector?: string; Class: Constructable; args?: unknown[]; }; preview: { selector?: string; Class: Constructable; args?: unknown[]; }; updaters: { selector?: string; Class: Constructable; args?: unknown[]; }; }; type DefaultMapConfiguration = { editors: { selector?: string; options: ExhibitionMonacoEditorOptions; optionsStorage?: KeyValueStorage>; }; preview?: { selector?: string; options?: ExhibitionPreviewOptions; optionsStorage?: KeyValueStorage; }; updaters?: { selector?: string; }; }; type DisabledEditorsDefaultMapConfiguration = Omit, "editors">; type GetMapArgs = { configuration: DefaultMapConfiguration; deferEditors?: false; } | { configuration?: DisabledEditorsDefaultMapConfiguration; deferEditors: true; }; /** * This is a factory function that creates a new map each time it's run. */ function createMap(configuration: MapConfiguration): { editors: { selector: string | undefined; multiple: true; required: false; Class: Constructable; args: unknown[]; }; preview: { selector: string | undefined; multiple: false; required: true; Class: Constructable; args: unknown[]; }; updaters: { selector: string | undefined; Class: Constructable; multiple: true; required: false; args: unknown[]; }; }; class Exhibition extends AbstractDependentWraplet> { protected supportedNodeTypes(): readonly Constructable[]; initialize(): Promise; destroy(): Promise; protected onInitialize(): Promise; /** * Adds DocumentAltererProviderWraplet instance to the list of editors. */ addEditor(editor: DocumentAltererProviderWraplet): void; /** * Removes DocumentAltererProviderWraplet instance from the list of editors. */ removeEditor(editor: DocumentAltererProviderWraplet): void; /** * Checks if the given editor is present in the list of editors. */ hasEditor(editor: DocumentAltererProviderWraplet): boolean; /** * Adds a simple DocumentAlterer to the preview. */ private addPreviewAlterer; getPreview(): PreviewWraplet; /** * If Preview becomes unresponsive, you can replace it with a new one. * * Remember to destroy the old one afterward. */ replacePreview(preview: PreviewWraplet): void; updatePreview(): Promise; /** * Create multiple Exhibitions. * * @param node Node to create Exhibitions on. * @param map Map of dependencies for each Exhibition instance. * @param options Options for Exhibition instances. * @param initOptions Options related to the creation process of the Exhibitions. * @param attribute Attribute to use for Exhibition instances. * * @returns Array of Exhibition instances. */ static createMultiple = ReturnType>(node: ParentNode, map: M, options?: ExhibitionOptions, initOptions?: ExhibitionInitOptions, attribute?: string): Promise; /** * Create a single Exhibition instance wrapping a given element. * * @param element Element to wrap. * @param map Map of dependencies for the Exhibition instance. * @param initOptions Options related to the creation process of the Exhibitions. */ static create = ReturnType>(element: HTMLElement, map: M, initOptions?: ExhibitionInitOptions): Promise; private static fillCreateOptionsWithDefaults; /** * Validate create options. */ private static validateInitOptions; /** * Create options. */ private static applyCreateOptions; /** * Creates a default, preconfigured, map for Exhibition. */ static getMap(args: GetMapArgs): ReturnType; static getCustomizedMap(configuration: MapConfiguration): ReturnType; } type EditorCreator = (options: monaco.editor.IStandaloneEditorConstructionOptions, node: HTMLElement, monaco: MonacoInstance) => Promise; type ExhibitionMonacoEditorOptions = { /** * Monaco instance. */ monaco: MonacoInstance; /** * Instead of depending on this class for editor instantiation, you can provide your own editor instance here. */ monacoEditorCreator?: EditorCreator; /** * Monaco options for the editor. */ monacoEditorOptions?: monaco.editor.IStandaloneEditorConstructionOptions; /** * Location where the editor should be inserted. */ location?: "head" | "body"; /** * Priority of the editor's document alterer. Higher priority means it will be executed first. */ priority?: number; /** * Trim the default value of the editor. */ trimDefaultValue?: boolean; /** * This option applies to single tag languages only (typescript, javascript and css). It * determines the attributes that will be added to the generated tag. */ tagAttributes?: Record; }; type MonacoInstance = typeof monaco; class ExhibitionMonacoEditor extends AbstractWraplet implements DocumentAltererProviderWraplet { private monaco; private editor; private options; private priority; private monacoEditorOptions; constructor(node: HTMLElement, options: ExhibitionMonacoEditorOptions, optionsStorage?: KeyValueStorage>); protected supportedNodeTypes(): readonly Constructable[]; initialize(): Promise; destroy(): Promise; protected onInitialize(): Promise; getPriority(): number; private getMonacoInstance; /** * Returns the current value of the editor. */ private getValue; private alterDocument; getDocumentAlterer(): DocumentAlterer; /** * Additional validation. */ private validateOptions; private getEditor; private getTSValueAsJS; private getLanguage; static trimDefaultValue(content: string): string; protected onDestroy(): Promise; /** * Helper method creating a new monaco editor instance. */ static createMonacoEditor(editorOptions: monaco.editor.IStandaloneEditorConstructionOptions | undefined, node: HTMLElement, monaco: MonacoInstance): monaco.editor.IStandaloneCodeEditor; /** * Helper method creating a new monaco model instance. */ static createMonacoModel(monaco: MonacoInstance, language: string, value: string): monaco.editor.ITextModel; /** * Create a single ExhibitionMonacoEditor instance wrapping a given element. */ static create(element: HTMLElement, options: ExhibitionMonacoEditorOptions): ExhibitionMonacoEditor; } type ExhibitionPreviewOptions = { updateHeight?: boolean; updateHeightCallback?: (preview: ExhibitionPreview) => Promise; }; class ExhibitionPreview extends AbstractWraplet implements PreviewWraplet { private alterers; private currentBlobUrl; private options; constructor(element: HTMLIFrameElement, options?: ExhibitionPreviewOptions, optionsStorage?: KeyValueStorage>); protected supportedNodeTypes(): readonly Constructable[]; /** * Adds a DocumentAlterer to the preview. * @param alterer * @param priority * Priority of the alterer. Higher priority alterers are executed first. */ addDocumentAlterer(alterer: DocumentAlterer, priority?: number): void; /** * Checks if alterer is already registered. * @param alterer */ hasDocumentAlterer(alterer: DocumentAlterer): boolean; removeDocumentAlterer(alterer: DocumentAlterer): void; update(): Promise; removeIFrame(): void; /** * Updates preview's height to match its content. */ updateHeight(): void; private getIFrameDocument; private getIFrameWindow; } class ExhibitionUpdater extends AbstractWraplet { addClickListener(callback: () => void): void; } const typeMap: { readonly html: { readonly languages: readonly ["html"]; readonly tag: undefined; }; readonly js: { readonly languages: readonly ["javascript", "typescript"]; readonly tag: "script"; }; readonly css: { readonly languages: readonly ["css"]; readonly tag: "style"; }; }; type TypeFromLanguage = { [K in ValueTypes]: L extends (typeof typeMap)[K]["languages"][number] ? K : never; }[ValueTypes]; type ValueTypes = keyof typeof typeMap; type MonacoEditorLanguages = (typeof typeMap)[ValueTypes]["languages"][number]; function getTypeFromLanguage(language: T): TypeFromLanguage; function getTagFromType(type: T): (typeof typeMap)[T]["tag"]; function isSingleTagType(type: ValueTypes): type is Extract["type"]; const exhibitionDefaultAttribute = "data-js-exhibition"; type DocumentAlterer = (document: Document) => Promise; interface DocumentAltererProvider { /** * Returns a function that can be used to alter the document. */ getDocumentAlterer(): DocumentAlterer; /** * Returns the priority of the alterer, determining the order in which it is executed. */ getPriority(): number; } interface DocumentAltererProviderWraplet extends DocumentAltererProvider, Wraplet { } type PreviewBaseValue = { type: ValueTypes; content: string; location: "head" | "body"; priority: number; }; type IsSingleTag = { tagAttributes: Record; tag: string; }; type PreviewHTMLValue = PreviewBaseValue & { type: "html"; }; type PreviewJSValue = PreviewBaseValue & { type: "js"; } & IsSingleTag; type PreviewCSSValue = PreviewBaseValue & { type: "css"; } & IsSingleTag; type PreviewValue = PreviewCSSValue | PreviewJSValue | PreviewHTMLValue; interface PreviewWraplet extends Wraplet { addDocumentAlterer(alterer: DocumentAlterer, priority?: number): void; hasDocumentAlterer(alterer: DocumentAlterer): boolean; removeDocumentAlterer(alterer: DocumentAlterer): void; removeIFrame(): void; update(): Promise; }