@compdfkit_pdf_sdk/react_native
Version:
ComPDFKit for React Native is a comprehensive SDK that allows you to quickly add PDF functionality to Android, iOS, and React Native applications.
136 lines • 4.92 kB
JavaScript
;
/**
* Copyright © 2014-2026 PDF Technologies, Inc. All Rights Reserved.
*
* THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
* AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
* UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
* This notice may not be removed from this file.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CPDFEditorHistoryManager = void 0;
const react_native_1 = require("react-native");
const CPDFHistoryManagerBase_1 = require("./CPDFHistoryManagerBase");
const { CPDFViewManager } = react_native_1.NativeModules;
/**
* Manages the history of editing actions within a PDF document, allowing for undo and redo operations.
* This class extends the `CPDFHistoryManagerBase` and provides methods to interact with the native PDF view.
* @example
* ```typescript
* const manager = pdfReaderRef.current._editManager;
* const historyManager = manager.historyManager;
* ```
*/
class CPDFEditorHistoryManager extends CPDFHistoryManagerBase_1.CPDFHistoryManagerBase {
_viewerRef;
_onHistoryStateChanged;
constructor(viewerRef) {
super();
this._viewerRef = viewerRef;
}
handle(event) {
const { pageIndex, canUndo, canRedo } = event.nativeEvent.onContentEditorHistoryChanged;
if (this._onHistoryStateChanged) {
this._onHistoryStateChanged(pageIndex, canUndo, canRedo);
}
}
/**
* Sets a listener that is invoked when the history state changes.
* @param listener A callback function that is invoked when the history state changes. The function receives three parameters: `pageIndex` (the current page index), `canUndo` (a boolean indicating if an undo operation is possible), and `canRedo` (a boolean indicating if a redo operation is possible).
*/
setOnHistoryStateChangedListener(listener) {
this._onHistoryStateChanged = listener;
}
/**
* Checks if an undo operation is possible.
*
* @example
* ```typescript
* const manager = pdfReader._editorHistoryManager
* await manager.canUndo();
* ```
* @returns {Promise<boolean>} A promise that resolves to `true` if an undo operation is possible, otherwise `false`.
*/
async canUndo() {
const tag = (0, react_native_1.findNodeHandle)(this._viewerRef);
if (tag) {
try {
return await CPDFViewManager.editorCanUndo(tag);
}
catch (e) {
return false;
}
}
return false;
}
/**
* Checks if an undo operation is possible.
*
* @example
* ```typescript
* const manager = pdfReader._editorHistoryManager
* await manager.canRedo();
* ```
* @returns {Promise<boolean>} A promise that resolves to `true` if a redo operation is possible, otherwise `false`.
*/
async canRedo() {
const tag = (0, react_native_1.findNodeHandle)(this._viewerRef);
if (tag) {
try {
return await CPDFViewManager.editorCanRedo(tag);
}
catch (e) {
return false;
}
}
return false;
}
/**
* Checks if a redo operation is possible.
*
* @example
* ```typescript
* const manager = pdfReader._editorHistoryManager
* await manager.redo();
* ```
*
* @returns {Promise<void>} A promise that resolves when the undo operation is complete.
*/
async undo() {
const tag = (0, react_native_1.findNodeHandle)(this._viewerRef);
if (tag) {
try {
return await CPDFViewManager.editorUndo(tag);
}
catch (e) {
return Promise.reject(new Error('Unable to undo the editor action'));
}
}
return Promise.reject(new Error('Unable to find the native view reference'));
}
/**
* Performs a redo operation on the editor history.
*
* @example
* ```typescript
* const manager = pdfReader._editorHistoryManager
* await manager.redo();
* ```
*
* @returns {Promise<void>} A promise that resolves when the redo operation is complete.
*/
async redo() {
const tag = (0, react_native_1.findNodeHandle)(this._viewerRef);
if (tag) {
try {
return await CPDFViewManager.editorRedo(tag);
}
catch (e) {
return Promise.reject(new Error('Unable to redo the editor action'));
}
}
return Promise.reject(new Error('Unable to find the native view reference'));
}
}
exports.CPDFEditorHistoryManager = CPDFEditorHistoryManager;
//# sourceMappingURL=CPDFEditorHistoryManager.js.map