JupyterLab output area component for rendering notebook execution results with multiple MIME type support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The Output Area Widget provides the visual rendering layer for JupyterLab output areas. It handles MIME type rendering, user input, scroll management, and widget lifecycle for displaying notebook execution results.
Main widget class for rendering output areas with full interaction support.
/**
* Output area widget for rendering notebook outputs with user interaction
*/
class OutputArea extends Widget {
/**
* Create a new output area widget
* @param options - Configuration options for the output area
*/
constructor(options: OutputArea.IOptions);
/** Content factory used by the widget for creating child components */
readonly contentFactory: OutputArea.IContentFactory;
/** The data model used by the widget */
readonly model: IOutputAreaModel;
/** The rendermime registry used for rendering different MIME types */
readonly rendermime: IRenderMimeRegistry;
/** Panel layout containing output widgets */
get layout(): PanelLayout;
/** Read-only array of child widgets in the output area */
get widgets(): ReadonlyArray<Widget>;
/** Signal emitted when the number of displayed outputs changes */
readonly outputLengthChanged: ISignal<this, number>;
/** The kernel future associated with the output area for execution */
get future(): Kernel.IShellFuture<
KernelMessage.IExecuteRequestMsg,
KernelMessage.IExecuteReplyMsg
>;
set future(value: Kernel.IShellFuture<
KernelMessage.IExecuteRequestMsg,
KernelMessage.IExecuteReplyMsg
>);
/** Signal emitted when an input is requested from the kernel */
get inputRequested(): ISignal<OutputArea, IStdin>;
/** Whether the output area has a pending input request */
get pendingInput(): boolean;
/** Maximum number of outputs to display (Infinity for no limit) */
get maxNumberOutputs(): number;
set maxNumberOutputs(limit: number);
/** Signal emitted when user requests toggling output scrolling mode */
get toggleScrolling(): ISignal<OutputArea, void>;
/** Signal emitted during widget initialization */
get initialize(): ISignal<OutputArea, void>;
/** Widget tracker for individual output widgets */
get outputTracker(): WidgetTracker<Widget>;
/**
* Dispose of the widget and clean up resources
*/
dispose(): void;
/**
* Handle changes to the output model
* @param sender - The model that changed
* @param args - Details about the change
*/
protected onModelChanged(
sender: IOutputAreaModel,
args: IOutputAreaModel.ChangedArgs
): void;
/**
* Handle state changes in the output model
* @param sender - The model whose state changed
* @param change - The index that changed, or void for all items
*/
protected onStateChanged(
sender: IOutputAreaModel,
change: number | void
): void;
/**
* Handle an input request from the kernel
* @param msg - The input request message
* @param future - The kernel future for the request
*/
protected onInputRequest(
msg: KernelMessage.IInputRequestMsg,
future: Kernel.IShellFuture
): void;
/**
* Create an output item widget with prompt and content
* @param model - The output model to render
* @returns Widget for the output item, or null if cannot render
*/
protected createOutputItem(model: IOutputModel): Widget | null;
/**
* Create a rendered widget for a specific MIME type
* @param model - The output model to render
* @returns Widget for the rendered content, or null if unsupported
*/
protected createRenderedMimetype(model: IOutputModel): Widget | null;
}Usage Examples:
import {
OutputArea,
OutputAreaModel
} from "@jupyterlab/outputarea";
import { RenderMimeRegistry } from "@jupyterlab/rendermime";
// Basic output area setup
const model = new OutputAreaModel();
const rendermime = new RenderMimeRegistry();
const outputArea = new OutputArea({
model,
rendermime,
maxNumberOutputs: 100
});
// Listen for output length changes
outputArea.outputLengthChanged.connect((sender, count) => {
console.log(`Output count changed to: ${count}`);
});
// Handle input requests
outputArea.inputRequested.connect((sender, stdin) => {
console.log("Input requested from kernel");
});
// Add the widget to a panel
panel.addWidget(outputArea);
// Add some output to see it rendered
model.add({
output_type: "display_data",
data: {
"text/html": ["<h1>Hello World</h1>"],
"text/plain": ["Hello World"]
},
metadata: {}
});Streamlined output area without input handling, ideal for read-only displays.
/**
* Simplified output area that handles no input requests
*/
class SimplifiedOutputArea extends OutputArea {
/**
* Create a simplified output area widget
* @param options - Configuration options (same as OutputArea)
*/
constructor(options: OutputArea.IOptions);
/**
* Handle input requests by doing nothing (no-op implementation)
* @param msg - Input request message (ignored)
* @param future - Kernel future (ignored)
*/
protected onInputRequest(
msg: KernelMessage.IInputRequestMsg,
future: Kernel.IShellFuture
): void;
/**
* Create output items without prompts
* @param model - Output model to render
* @returns Widget without execution count prompt
*/
protected createOutputItem(model: IOutputModel): Widget | null;
}Components for handling kernel input requests with history and validation.
/**
* Interface for standard input widgets
*/
interface IStdin extends Widget {
/** Promise that resolves with the user's input */
readonly value: Promise<string>;
}
/**
* Standard input widget with history and keyboard navigation
*/
class Stdin extends Widget implements IStdin {
/**
* Create a new stdin widget
* @param options - Configuration options for the input
*/
constructor(options: Stdin.IOptions);
/** Promise resolving to the user's input value */
get value(): Promise<string>;
/**
* Handle keyboard events for input navigation and history
* @param event - The keyboard event to handle
*/
handleEvent(event: KeyboardEvent): void;
/**
* Reset the history search state
*
* #### Notes
* This method clears the current search pattern, allowing new history
* navigation to start fresh. Called automatically when using regular
* arrow key navigation or Escape key.
*/
protected resetSearch(): void;
}
/**
* Options for creating stdin widgets
*/
interface Stdin.IOptions {
/** The prompt text to display */
prompt: string;
/** Whether the input should be treated as a password */
password: boolean;
/** The kernel future for sending the input reply */
future: Kernel.IShellFuture;
/** Parent header from the input request message */
parent_header: KernelMessage.IInputReplyMsg['parent_header'];
/** Optional translator for internationalization */
translator?: ITranslator;
/** Whether to use global or session-specific input history */
inputHistoryScope?: 'global' | 'session';
/** Whether to show placeholder text for input help */
showInputPlaceholder?: boolean;
}Component for displaying execution count prompts next to outputs.
/**
* Interface for output prompt widgets
*/
interface IOutputPrompt extends Widget {
/** The execution count to display in the prompt */
executionCount: nbformat.ExecutionCount;
}
/**
* Default output prompt implementation showing execution counts
*/
class OutputPrompt extends Widget implements IOutputPrompt {
/**
* Create a new output prompt widget
*/
constructor();
/** The execution count for this prompt (null for no count) */
get executionCount(): nbformat.ExecutionCount;
set executionCount(value: nbformat.ExecutionCount);
}Factory for creating customizable output area components.
/**
* Interface for output area content factories
*/
interface OutputArea.IContentFactory {
/**
* Create an output prompt widget
* @returns New output prompt instance
*/
createOutputPrompt(): IOutputPrompt;
/**
* Create a stdin widget for input requests
* @param options - Options for the stdin widget
* @returns New stdin widget instance
*/
createStdin(options: Stdin.IOptions): IStdin;
}
/**
* Default content factory implementation
*/
class OutputArea.ContentFactory implements OutputArea.IContentFactory {
/**
* Create the default output prompt
* @returns New OutputPrompt instance
*/
createOutputPrompt(): IOutputPrompt;
/**
* Create the default stdin widget
* @param options - Options for the stdin widget
* @returns New Stdin instance
*/
createStdin(options: Stdin.IOptions): IStdin;
}
/**
* Default content factory instance used when none is provided
*/
namespace OutputArea {
export const defaultContentFactory: OutputArea.ContentFactory;
}/**
* Options for creating output area widgets
*/
interface OutputArea.IOptions {
/** The data model for the output area */
model: IOutputAreaModel;
/** Optional content factory for creating child components */
contentFactory?: OutputArea.IContentFactory;
/** The rendermime registry for rendering different MIME types */
rendermime: IRenderMimeRegistry;
/** Maximum number of outputs to display (default: Infinity) */
maxNumberOutputs?: number;
/** Whether to show a prompt overlay for scrolling toggle */
promptOverlay?: boolean;
/** Optional translator for internationalization */
translator?: ITranslator;
/** Whether to use global or session-specific input history */
inputHistoryScope?: 'global' | 'session';
/** Whether to show placeholder text in input widgets */
showInputPlaceholder?: boolean;
}
/**
* Execute code on an output area widget
* @param code - The code to execute
* @param output - The output area to display results in
* @param sessionContext - The session context for execution
* @param metadata - Optional metadata for the execution
* @returns Promise resolving to the execution reply
*/
async function OutputArea.execute(
code: string,
output: OutputArea,
sessionContext: ISessionContext,
metadata?: JSONObject
): Promise<KernelMessage.IExecuteReplyMsg | undefined>;
/**
* Determine if a MIME type should be rendered in an isolated frame
* @param mimeType - The MIME type to check
* @param metadata - Output metadata containing isolation preferences
* @returns Whether the MIME type should be isolated
*/
function OutputArea.isIsolated(
mimeType: string,
metadata: ReadonlyPartialJSONObject
): boolean;The stdin widget includes sophisticated input history management:
Large outputs are automatically managed:
maxNumberOutputs to limit displayed itemsSecurity and rendering isolation:
Wrapper for rendering untrusted content in isolated iframes for security.
/**
* Renderer that wraps another renderer in an isolated iframe for security
*/
class IsolatedRenderer extends Widget implements IRenderMime.IRenderer {
/**
* Create an isolated renderer wrapping another renderer
* @param wrapped - The renderer to wrap in an iframe
*/
constructor(wrapped: IRenderMime.IRenderer);
/**
* Render a mime model in the isolated iframe
* @param model - The mime model to render
* @returns Promise resolving when rendering is complete
*/
renderModel(model: IRenderMime.IMimeModel): Promise<void>;
}Specialized panel for output items with context menu focus handling.
/**
* Panel widget focused by contextmenu events, used for output items
*/
class OutputPanel extends Panel {
/**
* Create a new output panel widget
* @param options - Panel construction options
*/
constructor(options?: Panel.IOptions);
}Information widget displayed when output count exceeds maxNumberOutputs.
/**
* Widget displaying information about trimmed outputs with expand functionality
*/
class TrimmedOutputs extends Widget {
/**
* Create a trimmed outputs information widget
* @param maxNumberOutputs - Number of outputs currently displayed
* @param onClick - Callback when user clicks to expand outputs
*
* #### Notes
* The widget is disposed after clicking and calling the callback.
*/
constructor(
maxNumberOutputs: number,
onClick: (event: MouseEvent) => void
);
/**
* Handle DOM events for the widget
* @param event - The DOM event to handle
*/
handleEvent(event: Event): void;
}