import * as React from 'react'; import { IThemeManager } from '@jupyterlab/apputils'; import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import type { TranslationBundle } from '@jupyterlab/translation'; import { type SelectedLineRange } from '@pierre/diffs'; /** * The CSS class added to the diff main-area widget. The selectors that * style the embedded `@pierre/diffs` viewer hang off this class. */ export declare const DIFF_WIDGET_CSS_CLASS = "jp-xtralab-DiffWidget"; /** * Layout for textual/code diffs, forwarded to `@pierre/diffs` as its * `diffStyle` option. `split` is the side-by-side old|new view; `unified` * is the single-column inline view (what diffs.com calls "stacked"). */ export type DiffStyle = 'split' | 'unified'; export declare function readStoredDiffStyle(): DiffStyle; export declare function writeStoredDiffStyle(style: DiffStyle): void; /** * View modes available for `.ipynb` diffs. `notebook` is the cell-by-cell * rendered view; `json` is the raw nbformat JSON file diff, for inspecting * exactly which bytes changed. */ export type NotebookDiffViewMode = 'notebook' | 'json'; export declare function readStoredNotebookViewMode(): NotebookDiffViewMode; export declare function writeStoredNotebookViewMode(mode: NotebookDiffViewMode): void; /** * Decide whether the active JupyterLab theme is a dark theme. Prefers the * `IThemeManager` token when available, and falls back to sniffing the * `data-jp-theme-light` attribute that JupyterLab sets on `` so the * component still works in stripped-down hosts where the token isn't * provided (lite, certain notebook configurations, …). */ export declare function isDarkTheme(themeManager: IThemeManager | null): boolean; /** * Whether the active JupyterLab theme should keep Pierre diff highlighting. */ export declare function isPierreTheme(themeManager: IThemeManager | null): boolean; /** * Optional per-hunk discard wiring. When supplied and `enabled`, each hunk * in a plain-text/code diff gets an inline "discard" button; clicking it * reverts that hunk and hands the rebuilt full-file text back to the host * via {@link IHunkDiscard.save}. The host owns the actual write (it knows * the on-disk path) and triggers any follow-up refresh in * {@link IHunkDiscard.onAfterSave}. */ interface IHunkDiscard { enabled: boolean; save: (fullText: string) => Promise; onAfterSave: () => void; } interface IDiffSurfaceProps { /** * Whether the host is still resolving the file contents. */ loading: boolean; /** * Fatal error message to show instead of a diff, or `null`. */ error: string | null; /** * Whether the file is binary (no textual diff is rendered). */ isBinary: boolean; /** * Resolved old/reference text. Ignored while loading/binary/errored. */ oldText: string; /** * Resolved new/challenger text. Ignored while loading/binary/errored. */ newText: string; /** * New-side path. Drives notebook detection and the `@pierre/diffs` file * name on the additions side. */ newName: string; /** * Old-side path. Differs from {@link newName} only for renames; defaults * to {@link newName} when the host does not track a previous path. */ oldName?: string; /** * Whether to render with the dark `@pierre/diffs` theme. */ dark: boolean; /** * Whether the diff should keep Pierre's own syntax palette. */ pierreTheme: boolean; /** * Rendermime registry used by the notebook view to render outputs and * markdown cells. May be `null` in stripped-down hosts; the notebook * diff falls back to a textual representation in that case. */ rendermime: IRenderMimeRegistry | null; /** * Current rendered-vs-JSON choice for notebook diffs (host-controlled). */ notebookViewMode: NotebookDiffViewMode; /** * Split vs unified layout for the textual/code file diff (host-controlled). */ diffStyle: DiffStyle; /** * Called whenever the availability of a rendered notebook view changes, * so the host can show/hide its Notebook/JSON toolbar toggle. */ onNotebookAvailabilityChange?: (available: boolean) => void; /** * Called whenever the textual/code file diff (the only view the split vs * unified choice affects) becomes the active view, so the host can * show/hide its Split/Unified toolbar toggle. False for image, binary, * rendered-notebook, loading and error states. */ onFileDiffActiveChange?: (active: boolean) => void; /** * Called after each (re)computation of the diff with the number of hunks * (or `null` when no textual diff exists). Hosts use this to implement * post-discard behaviors such as auto-closing an emptied diff. */ onMetadataChange?: (info: { hunkCount: number | null; }) => void; /** * Optional per-hunk discard wiring; omit for a read-only diff. */ hunkDiscard?: IHunkDiscard; /** * When provided, the textual/code file diff gets line selection: clicking * or dragging over the line numbers selects a range, and a gutter "+" * button appears on the hovered/selected lines. Clicking that button * invokes this callback with the selected range and the button's viewport * rectangle (to anchor a popup to), `null` when it cannot be measured. */ onLineAsk?: (range: SelectedLineRange, anchor: DOMRect | null) => void; /** * Translation bundle for user-facing strings. */ trans: TranslationBundle; } /** * Shared renderer for text, notebook and image diffs. */ export declare function DiffSurface(props: IDiffSurfaceProps): React.ReactElement; /** * Segmented Notebook/JSON selector. Hosts mount this into whatever toolbar * they own (the launcher's `MainAreaWidget` toolbar, or the * `jupyterlab-git`-provided diff toolbar) and drive its value/visibility * from the same state they pass to {@link DiffSurface}. */ export declare function NotebookViewModeControl(props: { mode: NotebookDiffViewMode; available: boolean; onChange: (mode: NotebookDiffViewMode) => void; trans: TranslationBundle; }): React.ReactElement; /** * Segmented Split/Unified selector. Mirrors {@link NotebookViewModeControl}: * hosts mount it into their own toolbar and drive its value/visibility from * the same state they pass to {@link DiffSurface}. Only meaningful while the * textual/code file diff is the active view, so `available` mirrors the * surface's `onFileDiffActiveChange`. */ export declare function DiffStyleControl(props: { diffStyle: DiffStyle; available: boolean; onChange: (style: DiffStyle) => void; trans: TranslationBundle; }): React.ReactElement; export {};