CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jupyterlab--rendermime-interfaces

TypeScript interfaces for implementing MIME renderer extensions in JupyterLab

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

data-models.mddocs/

Data Models

Core interfaces for handling MIME data, metadata, and toolbar components within the JupyterLab rendering system.

Capabilities

IMimeModel Interface

Represents a model for MIME data that can be rendered by MIME renderers. Contains the actual data, metadata, and trust information.

/**
 * A model for mime data containing trusted data, metadata, and data modification capabilities
 */
interface IMimeModel {
  /** Whether the data in the model is trusted */
  readonly trusted: boolean;
  /** The data associated with the model */
  readonly data: ReadonlyPartialJSONObject;
  /** 
   * The metadata associated with the model.
   * Among others, it can include an attribute named `fragment`
   * that stores a URI fragment identifier for the MIME resource.
   */
  readonly metadata: ReadonlyPartialJSONObject;
  /**
   * Set the data associated with the model.
   * Calling this function may trigger an asynchronous operation
   * that could cause the renderer to be rendered with a new model
   * containing the new data.
   */
  setData(options: IMimeModel.ISetDataOptions): void;
}

Usage Example:

import { IRenderMime } from "@jupyterlab/rendermime-interfaces";

// Implementing a custom mime model
class MyMimeModel implements IRenderMime.IMimeModel {
  constructor(
    private _trusted: boolean,
    private _data: ReadonlyPartialJSONObject,
    private _metadata: ReadonlyPartialJSONObject = {}
  ) {}

  get trusted(): boolean {
    return this._trusted;
  }

  get data(): ReadonlyPartialJSONObject {
    return this._data;
  }

  get metadata(): ReadonlyPartialJSONObject {
    return this._metadata;
  }

  setData(options: IRenderMime.IMimeModel.ISetDataOptions): void {
    if (options.data !== undefined) {
      this._data = options.data;
    }
    if (options.metadata !== undefined) {
      this._metadata = options.metadata;
    }
    // Trigger re-rendering logic here
  }
}

IMimeModel.ISetDataOptions Interface

Options for updating the data and metadata in a MIME model.

/**
 * The options used to update a mime model
 */
interface ISetDataOptions {
  /** The new data object */
  data?: ReadonlyPartialJSONObject;
  /** The new metadata object */
  metadata?: ReadonlyPartialJSONObject;
}

IToolbarItem Interface

Represents a toolbar item that can be displayed in a renderer's toolbar.

/**
 * A toolbar item with a unique name and associated widget
 */
interface IToolbarItem {
  /** Unique item name */
  name: string;
  /** Toolbar widget */
  widget: Widget;
}

Usage Example:

import { IRenderMime } from "@jupyterlab/rendermime-interfaces";
import { Widget } from "@lumino/widgets";

// Creating toolbar items
function createToolbarItems(): IRenderMime.IToolbarItem[] {
  const button = new Widget();
  button.node.innerHTML = '<button>Custom Action</button>';

  return [
    {
      name: "custom-action",
      widget: button
    }
  ];
}

// Using in document widget factory options
const factoryOptions: IRenderMime.IDocumentWidgetFactoryOptions = {
  name: "My Renderer",
  primaryFileType: "my-format",
  fileTypes: ["my-format"],
  toolbarFactory: () => createToolbarItems()
};

Types

External Dependencies

These interfaces depend on types from external packages. See the main documentation for complete type definitions.

docs

data-models.md

document-system.md

extension-system.md

icon-system.md

index.md

renderer-system.md

translation-system.md

utility-services.md

tile.json