thebe-react
Version:
React providers and components for thebe-core
85 lines (84 loc) • 3.74 kB
TypeScript
/// <reference types="react" />
import type { ThebeNotebook, ThebeSession, IThebeCell, IThebeCellExecuteReturn } from 'thebe-core';
import type { INotebookContent } from '@jupyterlab/nbformat';
export interface NotebookExecuteOptions {
stopOnError?: boolean;
before?: () => void;
after?: () => void;
preprocessor?: (s: string) => string;
}
export type IThebeNotebookError = IThebeCellExecuteReturn & {
index: number;
};
export declare function findErrors(execReturns: (IThebeCellExecuteReturn | null)[]): IThebeNotebookError[] | null;
export declare function useNotebookBase(): {
ready: boolean;
attached: boolean;
executing: boolean;
executed: boolean;
errors: IThebeNotebookError[] | null;
notebook: ThebeNotebook | undefined;
setNotebook: import("react").Dispatch<import("react").SetStateAction<ThebeNotebook | undefined>>;
refs: ((node: HTMLDivElement) => void)[];
setRefs: import("react").Dispatch<import("react").SetStateAction<((node: HTMLDivElement) => void)[]>>;
executeAll: (options?: NotebookExecuteOptions) => Promise<(IThebeCellExecuteReturn | null)[]>;
executeSome: (predicate: (cell: IThebeCell) => boolean, options?: NotebookExecuteOptions) => Promise<(IThebeCellExecuteReturn | null)[]>;
clear: () => void;
session: ThebeSession | undefined;
};
/**
* @param name - provided to the fetcher function
* @param fetchNotebook - an async function, that given a name, can return a JSON representation of an ipynb file (INotebookContent)
* @param opts - options.refsForWidgetsOnly=false allows refs to be generated for all notebook cells, rather than onlythose with widget tags
* @returns
*/
export declare function useNotebook(name: string, fetchNotebook: (name: string) => Promise<INotebookContent>, opts?: {
refsForWidgetsOnly: boolean;
}): {
ready: boolean;
loading: boolean;
attached: boolean;
executing: boolean;
executed: boolean;
errors: IThebeNotebookError[] | null;
notebook: ThebeNotebook | undefined;
cellRefs: ((node: HTMLDivElement) => void)[];
cellIds: string[];
executeAll: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
executeSome: (predicate: (cell: IThebeCell) => boolean, options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
clear: () => void;
session: ThebeSession | undefined;
};
/**
* @param sourceCode - just an array of valid code blocks as single line strings
* @param opts - options.refsForWidgetsOnly=false allows refs to be generated for all notebook cells, rather than onlythose with widget tags
* @returns
*/
export declare function useNotebookFromSource(sourceCode: string[], opts?: {
refsForWidgetsOnly: boolean;
}): {
ready: boolean;
loading: boolean;
attached: boolean;
executing: boolean;
executed: boolean;
errors: IThebeNotebookError[] | null;
notebook: ThebeNotebook | undefined;
cellRefs: ((node: HTMLDivElement) => void)[];
cellIds: string[];
executeAll: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
executeSome: (predicate: (cell: IThebeCell) => boolean, options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
clear: () => void;
session: ThebeSession | undefined;
};
/**
* DEPRECATED - migrate to useNotebookFromSource
*/
export declare function useNotebookfromSourceLegacy(sourceCode: string[]): {
notebook: ThebeNotebook | undefined;
busy: boolean;
execute: () => void;
attach: (session: ThebeSession) => void;
cellRefs: import("react").RefObject<HTMLDivElement>[];
rerender: () => void;
};