@pdftron/webviewer-react-toolkit
Version:
A React component library for integrating with PDFTron WebViewer API.
199 lines (198 loc) • 7.7 kB
TypeScript
import { Core } from '@pdftron/webviewer';
import { FuturableOrLazy } from './futurable';
import { MemoizedPromise } from './memoizedPromise';
export interface FileDetails {
/**
* The name of the file.
*/
name: string;
/**
* Optional ID for file. If falsy, will generate a unique ID.
*/
id?: string;
/**
* The original name of the file.
* @default name
*/
originalName?: string;
/**
* File extension. For example, `'pdf'`. If not provided, will be parsed from
* `name`.
*/
extension?: string;
/**
* File object, or function to get it. One of `fileObj` or `documentObj` must
* be given.
*/
fileObj?: MemoizedPromise<Blob> | FuturableOrLazy<Blob>;
/**
* Document object, or function to get it. One of `fileObj` or `documentObj`
* must be given.
*/
documentObj?: MemoizedPromise<Core.Document | undefined> | FuturableOrLazy<Core.Document | undefined>;
/**
* Thumbnail data URL string, or function to get it.
*/
thumbnail?: MemoizedPromise<string> | FuturableOrLazy<string>;
/**
* Set the WebViewer license key for only this file. If you wish to set for
* all files, use the static `File.setGlobalLicense` method. This local
* license will take priority over the global license.
*/
license?: string;
/**
* A reference to the document that was used to create this File class. Used
* as an optimization where applicable. If passed, `pageNumber` must also be
* passed.
*/
fullDocumentObj?: Core.Document;
/**
* Used in conjunction with `fullDocumentObj`. Represents the page number of
* `fullDocumentObj` that this file belongs too.
*/
pageNumber?: number;
}
export interface FileLike {
id: string;
name: string;
originalName: string;
extension: string;
thumbnail: MemoizedPromise<string>;
fileObj: MemoizedPromise<Blob>;
documentObj: MemoizedPromise<Core.Document | undefined>;
subscribe: (...args: any) => () => void;
fullDocumentObj?: Core.Document;
pageNumber?: number;
}
export declare type FileEventType =
/** Triggered when the documentObj is updated. */
'onrotate'
/** Triggered when the documentObj is updated. */
| 'ondocumentobjchange'
/** Triggered when the fileObj is updated. */
| 'onfileobjchange'
/** Triggered when the thumbnail is updated. */
| 'onthumbnailchange'
/** Triggered when the name is updated. */
| 'onnamechange'
/** Triggered when the thumbnail is frozen. */
| 'onfreezethumbnail'
/** Triggered when the thumbnail is unfrozen. */
| 'onunfreezethumbnail'
/** Change is always fired after every other event, unless stopPropagation was called. */
| 'onchange';
export declare type FileEventListener = () => void;
export declare type FileEventListenersObj = Partial<{
[type in FileEventType]: FileEventListener[];
}>;
/** A representation of the data within a file. */
export declare class File implements FileLike {
private _id;
private _name;
private _originalName;
private _extension;
private _fileObj;
private _documentObj;
private _thumbnail;
private _freezeThumbnail;
private _subscribers;
private _license?;
private _fullDocumentObj?;
private _pageNumber?;
/**
* Initialize the `File`.
* @param fileDetails The file details object or file-like class to initialize
* this `File` with.
*/
constructor(fileDetails: FileDetails);
/**
* Set the license key in order to use full WebViewer features. This only
* needs to be done once, and will be used globally by all files.
* @param license The license key for WebViewer.
*/
static setGlobalLicense(license: string): void;
/** A unique ID generated for the file. */
get id(): string;
/** The original name of the file. */
get originalName(): string;
/** The extension of the file (for example `'pdf'`). */
get extension(): string;
/** A memoized promise for the thumbnail. */
get thumbnail(): MemoizedPromise<string>;
/** A memoized promise for the fileObj. */
get fileObj(): MemoizedPromise<Blob>;
/** A memoized promise for the documentObj. */
get documentObj(): MemoizedPromise<Core.Document | undefined>;
/** Gets the full document object if provided during initialization. */
get fullDocumentObj(): Core.Document | undefined;
/** Gets the page index if provided during initialization. */
get pageNumber(): number | undefined;
/** The name of the file. */
get name(): string;
set name(name: string);
/** Freeze to prevent thumbnail from changing. */
get freezeThumbnail(): boolean;
set freezeThumbnail(freezeThumbnail: boolean);
/**
* Set the thumbnail or give a futurable or getter.
* @param thumbnail The thumbnail, promise, or getter for the thumbnail.
*/
setThumbnail(thumbnail?: FuturableOrLazy<string>): void;
/**
* Set the fileObj or give a futurable or getter.
* @param fileObj The fileObj, promise, or getter for the fileObj.
*/
setFileObj(fileObj?: FuturableOrLazy<Blob>): void;
/**
* Set the documentObj or give a futurable or getter.
* @param documentObj The documentObj, promise, or getter for the documentObj.
*/
setDocumentObj(documentObj?: FuturableOrLazy<Core.Document | undefined>): void;
/**
* Use this file to make updates to `documentObj` that you want reflected in
* `fileObj` and `thumbnail`. Since mutations directly to `documentObj` will
* not be detected, using this function tells `File` to trigger an update.
*/
updateDocumentObj(updater: (documentObj: Core.Document | undefined) => Promise<void>): Promise<void>;
/**
* Rotate 90 degrees clockwise unless `counterclockwise` is true.
* @param counterclockwise Rotate 90 degrees counterclockwise.
*/
rotate(counterclockwise?: boolean): Promise<void>;
/**
* Creates a clone of the file with a new `documentObj`. This is the
* recommended way of duplicating files, as it will prevent them both
* referencing the same documentObj.
* @param overrides Override any of the `FileDetails` that initialize `File`.
* Note that `fileObj` will be overridden by the `documentObj` in overrides,
* or cloned from this file.
*/
clone(overrides?: Partial<FileDetails>): File;
/**
* Appends an subscriber for events whose type attribute value is type.
* The callback argument sets the callback that will be invoked when the event
* is dispatched.
* @param type The event type that will invoke the listener.
* @param subscriber The listener function that will be invoked.
*/
subscribe(type: FileEventType, subscriber: FileEventListener): () => FileEventListener[] | undefined;
/**
* Dispatch an event for this file. Once all subscribers have been called for
* the dispatched type, it will complete by calling all onchange subscribers.
* @param type The file event type to dispatch.
*/
dispatchEvent(type: FileEventType): void;
/**
* Removes the event listener in target's event listener list with the same
* type and callback.
* @param type The event type that the listener is registered for.
* @param subscriber The listener to remove.
*/
private _unsubscribe;
/** Generate a thumbnail from document object. */
private _generateThumbnail;
/** Generate a file object from document object. */
private _generateFileObj;
/** Generate a document object from file object and extension. */
private _generateDocumentObj;
}