@grapecity/gcpdfviewer
Version:
GcDocs PDF Viewer
247 lines (246 loc) • 10.3 kB
TypeScript
/** @hidden */ /** */
/// <reference path="../../../vendor/react/react.d.ts" />
//@ts-ignore
import { MouseEvent } from 'react';
//@ts-ignore
import { Icon } from '@grapecity/core-ui';
import { CancellationToken, SessionState } from '../control';
import { ReportViewerCmd, ReportViewerCommandStatus, DocumentMoniker } from './ReportViewerCmd';
import { FindOptions, SearchResult } from '../features/search';
import { PageDecoration } from '../components/DocumentViewer';
export declare type ChangeHandler<TState> = (state: TState) => void;
declare type UnsubscribeFn = () => void;
/** Provides the read/write access to state store, similar to redux store */
export interface IStore<TState, TMsg> {
dispatch(msg: TMsg): void;
readonly state: TState;
subscribe(onUpdate: ChangeHandler<TState>): UnsubscribeFn;
}
/**
* Interface to state binder component which purpose is to allow one UI control to handle several documents.
*/
export interface IStateBinder<TState> {
/** binds component to a new state */
bind(store: IStore<TState, any>): void;
}
export declare type PanelHandle = {
id: string;
};
/** Long running tasks API */
export declare type TaskCallbacks = {
onProgress: (message: any) => void;
isCancelRequested: () => boolean;
};
export declare type TaskSettings = {
title?: string;
supportCancel?: boolean;
};
/** End of long running tasks API */
/** Error reporting */
export declare type ErrorSeverity = "error" | "warn" | "info" | "debug";
export declare type ErrorMessage = {
severity: ErrorSeverity;
message: string;
details: string;
};
export declare type ErrorHandler = (error: ErrorMessage) => boolean;
/** Defines a parameter for reportError method */
export interface IErrorParams {
readonly severity?: ErrorSeverity;
readonly message: string;
readonly details?: string;
}
/** History API */
export interface IViewerEvent {
readonly type: string;
}
export declare type ViewerEvent = IViewerEvent & {
type: "jumpedToPage";
fromPage: number | null;
to: {
pageIndex: number;
selector?: string;
};
} | {
type: "drilledToDocument";
fromDoc: SessionState;
target: DocumentMoniker;
};
/** Action (for interactive documents) handler context */
export declare type ActionContext<TEvent extends IViewerEvent> = {
readonly document: IDocument;
readonly view: IDocumentView | null;
processCommand(cmd: ReportViewerCmd): void;
processAction(action: ViewerAction): void;
pushEvent(event: TEvent): void;
};
/** Standard viewer actions */
export declare type ViewerAction = {
Type: "goBookmark";
Target: {
pageNumber: number;
selector?: string;
};
} | {
Type: "goHyperlink";
Target: string;
} | {
Type: "drillDocument";
Target: DocumentMoniker;
};
/** end of History API */
export interface IReportError {
/** Reports the error to user/UI. */
reportError(params: IErrorParams): void;
}
/** Defines the generic for processing error. */
export declare class PluginError extends Error {
readonly text: string;
readonly details: string;
constructor(title: string, text: string, details: string);
}
/** Defines the document processing error. */
export declare class DocumentError extends PluginError {
constructor(text: string, details: string);
}
export declare type PanelLocation = 'top' | 'bottom' | 'default';
/** Main component API */
export declare type PanelSettings = {
label: string;
icon: string | Icon;
description: string;
visible: boolean;
enabled: boolean;
/**Define this property to show this panel: 'top' - on top document view, 'bottom' - on bottom document view, 'default' - in sidebar/menu
* This panel will be shown in sidebar/menu by default, if this property is undefined */
location?: PanelLocation;
};
/** Represents API to access main (host) viewer components. */
export interface IViewerHost extends IReportError {
/** Creates a new UI panel
* @param render renders DOM for the panel UI to a specified container element. Must be instance of React.ReactChild
* @param binder instance of Binder that connects state to panel UI.
*/
createPanel<T>(component: any, binder: IStateBinder<T>, key: string, settings: Partial<PanelSettings>): PanelHandle;
/** Shows or hides the panel button in sidebar. */
showPanel(panelKey: PanelHandle, visible?: boolean): void;
/** Updates sidebar panel status. */
updatePanel(panelKey: PanelHandle, settings: Partial<PanelSettings>): void;
/** Ensures the panel is visible to user. */
bringPanelToFront(panel: PanelHandle): void;
/** Binds panel to a new document/state. */
bindPanel<TState, TMsg>(panel: PanelHandle, store: IStore<TState, TMsg>): void;
/** Instructs viewer that after particular action (such as clicking link or button) it should close panel when in mobile mode. */
closePanelOnNarrowScreen(panel?: PanelHandle): void;
/** Allows plugin to send a command to viewer window */
processCommand(cmd: ReportViewerCmd): void;
/** Redirects action processing to plugin */
processAction(action: ViewerAction): void;
/** Gets commands status */
readonly commandStatus: ReportViewerCommandStatus;
/** Sets viewer background color, default value = 'transparent'.
* @obsolete Use backgroundColor property instead.
*/
setBackgroundColor(backgroundColor?: string): void;
/** Gets or ets page decoration, default value = 'shadow' */
pageDecoration: PageDecoration;
/** Gets or sets viewer background color, default value = 'transparent' */
backgroundColor: string;
/** Allows to show sidebar in fullscreen mode */
enableSidebarInFullscreen: boolean;
}
export declare enum TimeDirection {
Backward = "backward",
Forward = "forward"
}
/** Interface to plugin module to implement support for particular document types. */
export interface IPluginModule<TEvent extends IViewerEvent, TAction> {
/** Gets unique plugin identifier */
readonly pluginKey: string;
/** Opens a new document by URI */
openDocument(location: DocumentMoniker, token?: CancellationToken): Promise<IDocument | null>;
/** Renders page to a page view */
renderPage(page: IPageData): PageView;
/** Renders the page with highlighted results */
renderHighlightPage?(page: IPageData, results: SearchResult[]): PageView;
/** Fires when user switches to a new document (opens a new report) */
onOpenDocument?(view: IDocument | null): void;
/** Fires when user switches to a new document view */
onOpenDocumentView(view: IDocumentView | null): void;
/** Given the mouse event attempts to resolve the action for the viewer/plugin. */
resolveAction(context: ActionContext<TEvent>, event: MouseEvent): TAction | ViewerAction | null;
/** Processes the action resolved on prior step */
processAction(context: ActionContext<TEvent>, action: TAction, processCommand: (cmd: ReportViewerCmd) => void): boolean;
/** Translates event to a viewer commands (provides implementation for the events) */
processEvent(context: ActionContext<TEvent>, event: TEvent, direction: TimeDirection): void;
}
export declare type PageCountResult = {
totalPageCount: number | null;
renderedSoFar: number;
};
/** Defines a progress message for IRunEventSink.progress() method. */
export declare type ProgressMessage = {
phase: "starting";
message: string;
} | {
phase: "run";
document?: IDocumentView;
count: PageCountResult;
} | {
phase: "complete";
document?: IDocumentView;
pageCount: number;
} | {
phase: "cancelled";
};
/** Interface for communicating viewer when document rendering is in progress. */
export interface IRunEventsSink extends IReportError {
/** Changes current status and provides additional progress info. */
progress(message: ProgressMessage): Promise<void>;
/** Instruct viewer to reset cached page data for particular page or range of pages */
invalidatePage(index: number, count?: number): void;
/** Provides cancellation token for rendering routine. The latter should check cancellation status and cancel rendering as soon as possible. */
readonly cancel: CancellationToken;
}
/** Internal document representation */
export interface IDocument {
/** Indicates whether the view can be created immediately after document is loaded. Primarily for AutoRun. */
canView(): boolean;
/** Creates a new document view (runs the reports or renders the document).
* @param baseView the view to inherit settings or parameters from. Consider "refresh" behavior in report viewer.
* @param sink the interface to communicate progress into to a viewer.
*/
createView(baseView: IDocumentView | null, sink: IRunEventsSink): Promise<IDocumentView | undefined>;
/** Updates the document view without data retrieval. Usually is called when view settings are changed. */
updateView(view: IDocumentView, sink: IRunEventsSink): Promise<IDocumentView | undefined>;
}
/** Visual representation of the document. */
export interface IDocumentView {
/** Gets the number of pages within a document. */
readonly pageCount: PageCountResult;
/** Gets the document page. */
awaitPage(index: number): Promise<IPageData | null>;
/** Override to provide fulltext search implementation */
//@ts-ignore
search?(options: FindOptions, startFrom: SearchResult): AsyncIterableIterator<SearchResult>;
}
export declare type PageSize = {
/** Page width in html units. E.g. "13cm", "5in" */
width: string;
/** Page height. */
height: string;
};
/** Marker interface for page data */
export interface IPageData {
/** Gets the page size */
readonly pageSize: PageSize;
}
/** Rendering friendly page representation. */
export declare type PageView = {
kind: 'html';
html: string;
} | {
kind: 'dom';
dom: Element;
};
export type { PageDecoration };