123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- import {
- JSONValue
- } from '@phosphor/coreutils';
- import {
- Widget
- } from '@phosphor/widgets';
- /**
- * A namespace for rendermime associated interfaces.
- */
- export
- namespace IRenderMime {
- /**
- * An observable model for mime data.
- */
- export
- interface IMimeModel {
- /**
- * The data associated with the model.
- */
- readonly data: IBundle;
- /**
- * The metadata associated with the model.
- */
- readonly metadata: IBundle;
- }
- /**
- * A bundle for mime data.
- */
- export
- interface IBundle {
- /**
- * Get a value for a given key.
- *
- * @param key - the key.
- *
- * @returns the value for that key.
- */
- get(key: string): JSONValue;
- /**
- * Set a key-value pair in the bundle.
- *
- * @param key - The key to set.
- *
- * @param value - The value for the key.
- *
- * @returns the old value for the key, or undefined
- * if that did not exist.
- */
- set(key: string, value: JSONValue): JSONValue;
- /**
- * Check whether the bundle has a key.
- *
- * @param key - the key to check.
- *
- * @returns `true` if the bundle has the key, `false` otherwise.
- */
- has(key: string): boolean;
- /**
- * Get a list of the keys in the bundle.
- *
- * @returns - a list of keys.
- */
- keys(): string[];
- /**
- * Remove a key from the bundle.
- *
- * @param key - the key to remove.
- *
- * @returns the value of the given key,
- * or undefined if that does not exist.
- */
- delete(key: string): JSONValue;
- }
- /**
- * The options used to initialize a document widget factory.
- */
- export
- interface IDocumentWidgetFactoryOptions {
- /**
- * The file extensions the widget can view.
- *
- * #### Notes
- * Use "*" to denote all files. Specific file extensions must be preceded
- * with '.', like '.png', '.txt', etc. They may themselves contain a
- * period (e.g. .table.json).
- */
- readonly fileExtensions: string[];
- /**
- * The name of the widget to display in dialogs.
- */
- readonly name: string;
- /**
- * The file extensions for which the factory should be the default.
- *
- * #### Notes
- * Use "*" to denote all files. Specific file extensions must be preceded
- * with '.', like '.png', '.txt', etc. Entries in this attribute must also
- * be included in the fileExtensions attribute.
- * The default is an empty array.
- *
- * **See also:** [[fileExtensions]].
- */
- readonly defaultFor?: string[];
- /**
- * Whether the widget factory is read only.
- */
- readonly readOnly?: boolean;
- /**
- * The registered name of the model type used to create the widgets.
- */
- readonly modelName?: string;
- /**
- * Whether the widgets prefer having a kernel started.
- */
- readonly preferKernel?: boolean;
- /**
- * Whether the widgets can start a kernel when opened.
- */
- readonly canStartKernel?: boolean;
- }
- /**
- * An interface for using a RenderMime.IRenderer for output and read-only documents.
- */
- export
- interface IExtension {
- /**
- * The MIME type for the renderer, which is the output MIME type it will handle.
- */
- mimeType: string;
- /**
- * A renderer factory to be registered to render the MIME type.
- */
- rendererFactory: IRendererFactory;
- /**
- * The index passed to `RenderMime.addRenderer`.
- */
- rendererIndex?: number;
- /**
- * The timeout after user activity to re-render the data.
- */
- renderTimeout?: number;
- /**
- * Preferred data type from the model. Defaults to `string`.
- */
- dataType?: 'string' | 'json';
- /**
- * The icon class name for the widget.
- */
- iconClass?: string;
- /**
- * The icon label for the widget.
- */
- iconLabel?: string;
- /**
- * The options used for using the renderer for documents.
- */
- documentWidgetFactoryOptions?: IDocumentWidgetFactoryOptions;
- }
- /**
- * The interface for a module that exports an extension or extensions as
- * the default value.
- */
- export
- interface IExtensionModule {
- /**
- * The default export.
- */
- default: IExtension | IExtension[];
- }
- /**
- * A widget that provides a ready promise.
- */
- export
- interface IRendererWidget extends Widget {
- /**
- * Render a mime model.
- */
- render(model: IMimeModel): Promise<void>;
- }
- /**
- * The interface for a renderer factory.
- */
- export
- interface IRendererFactory {
- /**
- * The mimeTypes this renderer accepts.
- */
- readonly mimeTypes: string[];
- /**
- * Whether the renderer can render given the render options.
- *
- * @param options - The options that would be used to render the data.
- */
- canCreateRenderer(options: IRendererOptions): boolean;
- /**
- * Create a renderer the transformed mime data.
- *
- * @param options - The options used to render the data.
- */
- createRenderer(options: IRendererOptions): IRendererWidget;
- /**
- * Whether the renderer will sanitize the data given the render options.
- *
- * @param options - The options that would be used to render the data.
- */
- wouldSanitize(options: IRendererOptions): boolean;
- }
- /**
- * The options used to create a renderer.
- */
- export
- interface IRendererOptions {
- /**
- * The preferred mimeType to render.
- */
- mimeType: string;
- /**
- * Whether the data is trusted.
- */
- trusted: boolean;
- /**
- * The html sanitizer.
- */
- sanitizer: ISanitizer;
- /**
- * An optional url resolver.
- */
- resolver?: IResolver;
- /**
- * An optional link handler.
- */
- linkHandler?: ILinkHandler;
- }
- /**
- * An object that handles html sanitization.
- */
- export
- interface ISanitizer {
- /**
- * Sanitize an HTML string.
- */
- sanitize(dirty: string): string;
- }
- /**
- * An object that handles links on a node.
- */
- export
- interface ILinkHandler {
- /**
- * Add the link handler to the node.
- */
- handleLink(node: HTMLElement, url: string): void;
- }
- /**
- * An object that resolves relative URLs.
- */
- export
- interface IResolver {
- /**
- * Resolve a relative url to a correct server path.
- */
- resolveUrl(url: string): Promise<string>;
- /**
- * Get the download url of a given absolute server path.
- */
- getDownloadUrl(path: string): Promise<string>;
- }
- }
|