@pierre/diffs
Version:
235 lines (234 loc) • 11.5 kB
TypeScript
import { AppliedThemeStyleCache, BaseCodeOptions, DiffLineAnnotation, FileContents, HighlightedToken, LineAnnotation, PostRenderPhase, PrePropertiesConfig, RenderFileMetadata, RenderRange, SelectedLineRange, ThemeTypes } from "../types.js";
import { EditCompletionDecision, EditorActiveLineOptions, EditorChangeEvent, FileEditCompleteEvent } from "../editor/types.js";
import { TextDocument } from "../editor/textDocument.js";
import { GetHoveredLineResult, InteractionManager, InteractionManagerBaseOptions, SelectionWriteOptions } from "../managers/InteractionManager.js";
import { ResizeManager } from "../managers/ResizeManager.js";
import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
import { FileRenderer } from "../renderers/FileRenderer.js";
import { Editor } from "../editor/editor.js";
//#region src/components/File.d.ts
interface FileRenderProps<LAnnotation> {
file: FileContents;
fileContainer?: HTMLElement;
containerWrapper?: HTMLElement;
deferManagers?: boolean;
forceRender?: boolean;
preventEmit?: boolean;
lineAnnotations?: LineAnnotation<LAnnotation>[];
renderRange?: RenderRange;
}
interface FileHydrateProps<LAnnotation> extends Omit<FileRenderProps<LAnnotation>, 'fileContainer'> {
fileContainer: HTMLElement;
prerenderedHTML?: string;
}
type FileEditChangeHandler<LAnnotation, Caret> = (event: EditorChangeEvent<'file', LAnnotation, Caret>) => void;
/**
* Decides a completed edit synchronously: return `'accept'` to install the
* event's `file` and annotations, or `'reject'` to restore the original values.
* The event is frozen, so re-key the accepted file in place
* (`event.file.cacheKey = '…'`) before accepting. The event's editor is
* detached and returns its final state from `getViewState()`. A missing handler
* rejects.
*/
type FileEditCompleteHandler<LAnnotation, Caret> = (event: FileEditCompleteEvent<LAnnotation, Caret>) => EditCompletionDecision;
interface FileOptions<LAnnotation, Caret> extends BaseCodeOptions, InteractionManagerBaseOptions<'file'> {
disableFileHeader?: boolean;
renderHeaderPrefix?: RenderFileMetadata;
renderHeaderFilenameSuffix?: RenderFileMetadata;
renderHeaderMetadata?: RenderFileMetadata;
renderCustomHeader?: RenderFileMetadata;
/**
* When true, errors during rendering are rethrown instead of being caught
* and displayed in the DOM. Useful for testing or when you want to handle
* errors yourself.
*/
disableErrorHandling?: boolean;
renderAnnotation?(annotation: LineAnnotation<LAnnotation>): HTMLElement | undefined;
renderGutterUtility?(getHoveredRow: () => GetHoveredLineResult<'file'> | undefined): HTMLElement | null | undefined;
onPostRender?(node: HTMLElement, instance: File<LAnnotation, Caret>, phase: PostRenderPhase): unknown;
/**
* Fired for every document change of an active edit session on this
* component, with the same `EditorChangeEvent` the editor reports through
* its own `onChange`. Do not feed the event's file back into the component
* while the session is active.
*/
onEditChange?: FileEditChangeHandler<LAnnotation, Caret>;
/**
* Fired when `edit` toggles false or a component unmounts, including when the
* final contents are unchanged. If no callback is provided, the component
* reverts to the last `file` and annotations passed into it. The callback
* receives the detached editor with its final pre-detach state.
*/
onEditComplete?: FileEditCompleteHandler<LAnnotation, Caret>;
}
interface AnnotationElementCache<LAnnotation> {
element: HTMLElement;
annotation: LineAnnotation<LAnnotation>;
}
interface HydrationSetup<LAnnotation> {
file: FileContents;
lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;
}
declare class File<LAnnotation = undefined, Caret = undefined> {
options: FileOptions<LAnnotation, Caret>;
private workerManager?;
private isContainerManaged;
static LoadedCustomComponent: boolean;
readonly __id: string;
readonly type = "file";
protected fileContainer: HTMLElement | undefined;
protected spriteSVG: SVGElement | undefined;
protected pre: HTMLPreElement | undefined;
protected code: HTMLElement | undefined;
protected bufferBefore: HTMLElement | undefined;
protected bufferAfter: HTMLElement | undefined;
protected themeCSSStyle: HTMLStyleElement | undefined;
protected appliedThemeCSS: AppliedThemeStyleCache | undefined;
protected hasAdoptedThemeCSS: boolean;
protected unsafeCSSStyle: HTMLStyleElement | undefined;
protected appliedUnsafeCSS: string | undefined;
protected gutterUtilityContent: HTMLElement | undefined;
protected errorWrapper: HTMLElement | undefined;
protected placeHolder: HTMLElement | undefined;
protected lastRenderedHeaderHTML: string | undefined;
protected cachedHeaderHTML: string | undefined;
protected appliedPreAttributes: PrePropertiesConfig | undefined;
protected lastRowCount: number | undefined;
private mounted;
protected headerElement: HTMLElement | undefined;
protected headerCustom: HTMLElement | undefined;
protected headerPrefix: HTMLElement | undefined;
protected headerFilenameSuffix: HTMLElement | undefined;
protected headerMetadata: HTMLElement | undefined;
protected fileRenderer: FileRenderer<LAnnotation>;
protected resizeManager: ResizeManager;
protected interactionManager: InteractionManager<'file'>;
protected annotationCache: Map<string, AnnotationElementCache<LAnnotation>>;
protected lineAnnotations: LineAnnotation<LAnnotation>[];
protected managersDirty: boolean;
file: FileContents | undefined;
private editSession;
protected renderedFile: FileContents | undefined;
protected renderRange: RenderRange | undefined;
protected enabled: boolean;
protected editor: Editor<'file', LAnnotation, Caret> | undefined;
constructor(options?: FileOptions<LAnnotation, Caret>, workerManager?: WorkerPoolManager | undefined, isContainerManaged?: boolean);
getAnnotationSlotName: (annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>) => string;
private handleHighlightRender;
rerender(): void;
private getTheme;
protected getLatestFile(file?: FileContents | undefined): FileContents | undefined;
protected getRenderedFile(): FileContents | undefined;
protected getLatestAnnotations(): LineAnnotation<LAnnotation>[];
protected isNewAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): boolean;
protected updateExternalFile(incomingFile: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]): boolean;
private installEditSession;
onThemeChange(): void;
setOptions(options: FileOptions<LAnnotation, Caret> | undefined): void;
protected syncInteractionOptions(): void;
private mergeOptions;
setThemeType(themeType: ThemeTypes): void;
private applyCachedThemeState;
private hasThemeChanged;
getHoveredLine: () => GetHoveredLineResult<'file'> | undefined;
setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void;
protected syncEditSessionAnnotationsFromEditor(lineAnnotations: LineAnnotation<LAnnotation>[]): boolean;
setSelectedLines(range: SelectedLineRange | null, options?: SelectionWriteOptions): void;
setEditorActiveLine(lineNumber: number | null, options?: EditorActiveLineOptions): void;
getCodeScrollLeft(): number;
setCodeScrollLeft(position: number): void;
__getEffectiveCodeOptions(): BaseCodeOptions;
flushManagers(): void;
protected shouldApplyColumnVariables(overflow: 'scroll' | 'wrap'): boolean;
cleanUp(recycle?: boolean): void;
virtualizedSetup(): void;
hydrate(props: FileHydrateProps<LAnnotation>): void;
protected hydrateElements(fileContainer: HTMLElement, prerenderedHTML: string | undefined): void;
protected hydrationSetup({
file,
lineAnnotations
}: HydrationSetup<LAnnotation>): void;
getOrCreateLineCache(file?: FileContents | undefined): string[];
protected updateBuffers(renderRange: RenderRange): void;
private syncRenderViewToEditor;
/** @internal The editor applied or edited past the pending external replacement. */
__acknowledgeDocumentUpdate(): void;
/** @internal Settle annotations */
__acceptEditorChange(event: EditorChangeEvent<'file', LAnnotation, Caret>): void;
emitEditChange(event: EditorChangeEvent<'file', LAnnotation, Caret>): void;
/** @internal Plain files have no component-owned diff session state. */
__captureDocumentSessionState(): undefined;
/** @internal Associate this component with its editor for a render lifecycle. */
__attachEditor(editor: Editor<'file', LAnnotation, Caret>): () => void;
/** @internal Resume rendering for the editor already associated with this component. */
__resumeEditor(editor: Editor<'file', LAnnotation, Caret>): void;
private resumeEditorRendering;
/**
* @internal
*
* Ends the edit session and settles which file this component renders.
* Requires the editor to be detached first. Does nothing when no session
* exists, so callers can invoke it again safely after it has settled.
*
* `onEditComplete` receives the completed file, current external file, and
* both annotation collections even when the final text is unchanged. In
* `install` mode, accepting installs the completed file and its annotations;
* rejecting or having no handler restores the external values. `discard`
* mode always restores the external values. An accepted file cannot reuse
* the replaced file's `cacheKey`.
*/
__completeEditSession(editor: Editor<'file', LAnnotation, Caret>, mode: 'install' | 'discard'): void;
private settleEditSession;
applyDocumentChange(textDocument: TextDocument<'file', LAnnotation>, newLineAnnotations?: LineAnnotation<LAnnotation>[]): void;
updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', options?: {
lineCountChangeInFlight?: boolean;
}): void;
render({
file,
fileContainer,
forceRender,
preventEmit,
containerWrapper,
deferManagers,
lineAnnotations,
renderRange
}: FileRenderProps<LAnnotation>): boolean;
protected finalizeRender(): void;
private emitPostRender;
private removeRenderedCode;
private clearAuxiliaryNodes;
private canPartiallyRender;
renderPlaceholder(height: number): boolean;
primeHighlightCache(file?: FileContents | undefined): Promise<void>;
private cleanChildNodes;
private renderAnnotations;
private renderGutterUtility;
private injectUnsafeCSS;
private applyThemeState;
private hydrateMeasuredScrollbar;
protected shouldGuardRebuildScroll(): boolean;
private applyFullRender;
private applyPartialRender;
private getColumns;
private trimDOMToOverlap;
private getDOMBoundaryIndices;
private getLineIndexFromDOMNode;
private applyBuffers;
protected shouldDisableVirtualizationBuffers(): boolean;
private applyHeaderToDOM;
private clearHeaderSlots;
private upsertHeaderSlotElement;
private replaceHeaderSlotContent;
private createHeaderSlotElement;
protected getOrCreateFileContainerNode(fileContainer?: HTMLElement, parentNode?: HTMLElement): HTMLElement;
private adoptReusableShellElements;
private ensureSpriteSVG;
private getOrCreatePreNode;
private syncCodeNodeFromPre;
private applyPreNodeAttributes;
private applyErrorToDOM;
private cleanupErrorWrapper;
}
//#endregion
export { File, FileEditChangeHandler, type FileEditCompleteEvent, FileEditCompleteHandler, FileHydrateProps, FileOptions, FileRenderProps };
//# sourceMappingURL=File.d.ts.map