import * as React from 'react'; import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import type { TranslationBundle } from '@jupyterlab/translation'; import { type FileDiffMetadata } from '@pierre/diffs'; /** * Minimal slice of nbformat 4.x that the diff inspects. Fields we don't * read (attachments, e.g.) are intentionally not narrowed — we still pass * them around as part of the cell, but we never project them into the diff. */ interface INotebookCell { cell_type: string; id?: string; source: string | string[]; outputs?: INotebookOutput[]; metadata?: Record; execution_count?: number | null; attachments?: Record; } interface INotebookOutput { output_type: string; data?: Record; text?: string | string[]; name?: string; ename?: string; evalue?: string; traceback?: string[]; execution_count?: number | null; metadata?: Record; } interface INotebook { cells: INotebookCell[]; metadata: Record; nbformat: number; nbformat_minor: number; } /** * One entry in the per-cell diff. `unchanged` cells are rendered as a * collapsed summary; the other variants render their source / outputs / * metadata via {@link FileDiff}. The `modified` and `unchanged` branches * carry the same payload but live on separate union members so `Extract` * narrowing works on `kind` literals downstream. */ type NotebookCellDiff = { kind: 'modified'; oldCell: INotebookCell; newCell: INotebookCell; newIndex: number; oldIndex: number; } | { kind: 'unchanged'; oldCell: INotebookCell; newCell: INotebookCell; newIndex: number; oldIndex: number; } | { kind: 'added'; newCell: INotebookCell; newIndex: number; } | { kind: 'removed'; oldCell: INotebookCell; oldIndex: number; }; /** * Notebook-level diff result returned by {@link buildNotebookDiff}. Returns * `null` from the builder when either side fails to parse — the caller then * falls back to a raw JSON file diff. */ export interface INotebookDiffResult { oldNotebook: INotebook; newNotebook: INotebook; cells: NotebookCellDiff[]; /** * Kernel language pulled from `metadata.language_info.name`, used to pick * a syntax-highlighting filename for code cells. */ language: string | undefined; /** * Pre-computed diff for notebook-level metadata (kernelspec, language_info, * nbformat) when it differs between revisions; `null` otherwise so the * section can be hidden without further checks. */ notebookMetadataDiff: FileDiffMetadata | null; } interface IBuildNotebookDiffOptions { oldText: string; newText: string; } /** * Build a complete notebook diff from the textual contents of two * revisions. Returns `null` if either side fails to parse as a notebook; * the caller is expected to fall back to a raw text diff in that case. * * An empty string on either side is treated as an empty notebook (no * cells, default metadata) so a freshly-added or deleted notebook still * produces a sensible cell-by-cell diff. */ export declare function buildNotebookDiff(options: IBuildNotebookDiffOptions): INotebookDiffResult | null; interface INotebookDiffViewProps { diff: INotebookDiffResult; dark: boolean; /** * Whether a Pierre JupyterLab theme is active; selects Pierre's rich * highlighting vs the CSS-variable theme (see {@link resolveDiffTheme}). */ pierreTheme: boolean; rendermime: IRenderMimeRegistry | null; /** * Translation bundle for user-facing strings. */ trans: TranslationBundle; } /** * The notebook-level diff view. Lays out cells in a 2-column grid where * the left column tracks the *old* notebook and the right column tracks * the *new* one — modified and unchanged cells span both columns (their * internal split-mode FileDiff aligns with the outer columns), added * cells live in the right column with an empty placeholder on the left, * and removed cells live in the left column with an empty placeholder on * the right. The diff library's red/green tint within each cell makes * the orientation clear without a separate column header. */ export declare function NotebookDiffView(props: INotebookDiffViewProps): React.ReactElement; export {};