react-adobe-embed
Advanced tools
Comparing version 0.12.69 to 0.27.69
178
lib/index.js
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AdobeReactView = void 0; | ||
exports.AdobeReactView = exports.DefaultConfigs = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
const react_1 = __importStar(require("react")); | ||
class AdobeReactView extends react_1.default.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isReady: props.isReady || false, | ||
adobeMainReady: props.adobeMainReady || false, | ||
previewConfig: props.previewConfig, | ||
}; | ||
this.previewFile = this.previewFile.bind(this); | ||
this.onLoad = this.onLoad.bind(this); | ||
this.onLoaded = this.onLoaded.bind(this); | ||
} | ||
previewFile(divId, viewerConfig, url) { | ||
var _a; | ||
const react_1 = require("react"); | ||
exports.DefaultConfigs = { | ||
demoUrl: "https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf", | ||
staticDefaultConfig: { | ||
showAnnotationTools: false, | ||
showLeftHandPanel: false, | ||
showPageControls: false, | ||
showDownloadPDF: false, | ||
showPrintPDF: false, | ||
}, | ||
staticDivId: "pdf-div", | ||
demoMetaData: { | ||
fileName: "Menu.pdf", | ||
id: "6d07d124 - ac85–43b3 - a867–36930f502ac6", | ||
}, | ||
}; | ||
const AdobeReactView = (props) => { | ||
var _a, _b; | ||
let adobeDCView; | ||
const [adobeMainReady, setAdobeMainReady] = (0, react_1.useState)(props.adobeMainReady || false); | ||
const [isReady, setIsReady] = (0, react_1.useState)(props.isReady || false); | ||
const previewFile = (divId, viewerConfig, url) => { | ||
var _a, _b; | ||
const config = { | ||
clientId: ((_a = this.state.config) === null || _a === void 0 ? void 0 : _a.clientId) || 'c514163c351b4f2082ef01e530840e0b', | ||
clientId: (_a = props.config) === null || _a === void 0 ? void 0 : _a.clientId, | ||
divId, | ||
}; | ||
this.adobeDCView = new window.AdobeDC.View(config); | ||
const previewFilePromise = this.adobeDCView.previewFile({ | ||
adobeDCView = new window.AdobeDC.View(config); | ||
const previewFilePromise = adobeDCView.previewFile({ | ||
content: { | ||
@@ -54,94 +39,30 @@ location: { | ||
}, | ||
metaData: AdobeReactView.demoMetaData, | ||
metaData: ((_b = props.config) === null || _b === void 0 ? void 0 : _b.fileMeta) || exports.DefaultConfigs.demoMetaData, | ||
}, viewerConfig); | ||
return previewFilePromise; | ||
} | ||
onLoaded() { | ||
}; | ||
const onLoaded = () => { | ||
var _a, _b; | ||
this.previewFile(((_a = this.state.config) === null || _a === void 0 ? void 0 : _a.divId) || "pdf-div", this.state.previewConfig || AdobeReactView.staticDefaultCOnfig, ((_b = this.state.config) === null || _b === void 0 ? void 0 : _b.url) || | ||
AdobeReactView.demoUrl); | ||
} | ||
; | ||
onLoad() { | ||
previewFile(((_a = props.config) === null || _a === void 0 ? void 0 : _a.divId) || exports.DefaultConfigs.staticDivId, props.previewConfig || exports.DefaultConfigs.staticDefaultConfig, ((_b = props.config) === null || _b === void 0 ? void 0 : _b.url) || exports.DefaultConfigs.demoUrl); | ||
}; | ||
const onLoad = () => { | ||
var _a; | ||
if (document.getElementById(((_a = this.state.config) === null || _a === void 0 ? void 0 : _a.divId) || AdobeReactView.staticDefaultDivId)) { | ||
if (this.state.isReady === false) { | ||
this.setState({ isReady: true }); | ||
if (document.getElementById(((_a = props.config) === null || _a === void 0 ? void 0 : _a.divId) || exports.DefaultConfigs.staticDivId)) { | ||
if (isReady === false) { | ||
setIsReady(true); | ||
} | ||
} | ||
if (global.adobeDCView) { | ||
if (this.state.adobeMainReady === false) { | ||
this.setState({ adobeMainReady: true }); | ||
if (adobeMainReady === false) { | ||
setAdobeMainReady(true); | ||
} | ||
} | ||
if (this.props.onLoad) { | ||
this.props.onLoad(); | ||
} | ||
}; | ||
if (document.getElementById(((_a = props.config) === null || _a === void 0 ? void 0 : _a.divId) || exports.DefaultConfigs.staticDivId) || | ||
(isReady && adobeMainReady)) { | ||
onLoaded(); | ||
} | ||
previewFileUsingFilePromise(divId, filePromise, fileName) { | ||
var _a; | ||
this.adobeDCView = new window.AdobeDC.View({ | ||
clientId: ((_a = this.state.config) === null || _a === void 0 ? void 0 : _a.clientId) || 'c514163c351b4f2082ef01e530840e0b', | ||
divId, | ||
}); | ||
this.adobeDCView.previewFile({ | ||
content: { | ||
promise: filePromise, | ||
}, | ||
metaData: { | ||
fileName: fileName, | ||
}, | ||
}, {}); | ||
} | ||
registerSaveApiHandler() { | ||
const apiHandler = { | ||
saveApiHandler: (metaData, content, options) => { | ||
console.log(metaData, content, options); | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
const response = { | ||
code: window.AdobeDC.View.Enum.ApiResponseCode.SUCCESS, | ||
data: { | ||
metaData: Object.assign(metaData, { | ||
updatedAt: new Date().getTime(), | ||
}), | ||
}, | ||
}; | ||
resolve(response); | ||
}, 2000); | ||
}); | ||
}, | ||
}; | ||
this.adobeDCView.registerCallback(window.AdobeDC.View.Enum.CallbackType.SAVE_API, apiHandler, {}); | ||
} | ||
registerEventsHandler() { | ||
this.adobeDCView.registerCallback(window.AdobeDC.View.Enum.CallbackType.EVENT_LISTENER, (event) => { | ||
console.log(event); | ||
}, { | ||
enablePDFAnalytics: true, | ||
}); | ||
} | ||
render() { | ||
var _a, _b; | ||
if (document.getElementById(((_a = this.state.config) === null || _a === void 0 ? void 0 : _a.divId) || AdobeReactView.staticDefaultDivId) || | ||
(this.state.isReady && this.state.adobeMainReady)) { | ||
this.onLoaded(); | ||
} | ||
return ((0, jsx_runtime_1.jsx)("div", { onLoad: () => this.onLoad(), id: ((_b = this.state.config) === null || _b === void 0 ? void 0 : _b.divId) || AdobeReactView.staticDefaultDivId, className: "AdobeReactView" })); | ||
} | ||
} | ||
return ((0, jsx_runtime_1.jsx)("div", { onLoad: () => onLoad(), id: ((_b = props.config) === null || _b === void 0 ? void 0 : _b.divId) || exports.DefaultConfigs.staticDivId, className: "AdobeReactView" })); | ||
}; | ||
exports.AdobeReactView = AdobeReactView; | ||
AdobeReactView.demoUrl = 'https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf'; | ||
AdobeReactView.staticDefaultCOnfig = { | ||
showAnnotationTools: false, | ||
showLeftHandPanel: false, | ||
showPageControls: false, | ||
showDownloadPDF: false, | ||
showPrintPDF: false, | ||
}; | ||
AdobeReactView.demoMetaData = { | ||
fileName: "Menu.pdf", | ||
id: "6d07d124 - ac85–43b3 - a867–36930f502ac6", | ||
}; | ||
AdobeReactView.staticDefaultDivId = "pdf-div"; | ||
const ReactViewAdobe = (props) => { | ||
@@ -151,3 +72,3 @@ var _a; | ||
const [isReady, setIsReady] = (0, react_1.useState)(props.isReady || false); | ||
const divID = ((_a = props.config) === null || _a === void 0 ? void 0 : _a.divId) || AdobeReactView.staticDefaultDivId; | ||
const divID = ((_a = props.config) === null || _a === void 0 ? void 0 : _a.divId) || exports.DefaultConfigs.staticDivId; | ||
(0, react_1.useEffect)(() => { | ||
@@ -157,3 +78,3 @@ if (document.getElementById(divID)) { | ||
} | ||
if (global.adobeDCView) { | ||
if (global.AdobeDCView) { | ||
if (adobeMainReady === false) { | ||
@@ -164,9 +85,4 @@ setAdobeMainReady(true); | ||
}, [isReady, adobeMainReady, divID]); | ||
return ((0, jsx_runtime_1.jsx)(AdobeReactView, { props: { | ||
previewConfig: props.previewConfig, | ||
config: props.config, | ||
isReady: isReady, | ||
adobeMainReady: adobeMainReady, | ||
} })); | ||
return ((0, jsx_runtime_1.jsx)(exports.AdobeReactView, { adobeMainReady: adobeMainReady, isReady: isReady, config: props.config, previewConfig: props.previewConfig })); | ||
}; | ||
exports.default = ReactViewAdobe; |
{ | ||
"name": "react-adobe-embed", | ||
"version": "0.12.69", | ||
"version": "0.27.69", | ||
"description": "React Wrapper for Embed Adobe API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,2 @@ | ||
import React from "react"; | ||
/// <reference types="react" /> | ||
export declare type EmbedState = { | ||
@@ -10,12 +10,9 @@ adobeMainReady: boolean; | ||
fileMeta: { | ||
[key: string | 'fileName' | 'id']: any; | ||
[key: string | "fileName" | "id"]: any; | ||
}; | ||
}; | ||
}; | ||
export declare class AdobeReactView extends React.Component<any, { | ||
previewConfig: Partial<PreviewFileConfig>; | ||
} & Partial<EmbedState>> { | ||
private adobeDCView; | ||
static readonly demoUrl = "https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf"; | ||
static readonly staticDefaultCOnfig: { | ||
export declare const DefaultConfigs: { | ||
demoUrl: string; | ||
staticDefaultConfig: { | ||
showAnnotationTools: boolean; | ||
@@ -27,18 +24,11 @@ showLeftHandPanel: boolean; | ||
}; | ||
static readonly demoMetaData: { | ||
staticDivId: string; | ||
demoMetaData: { | ||
fileName: string; | ||
id: string; | ||
}; | ||
static readonly staticDefaultDivId = "pdf-div"; | ||
constructor(props: { | ||
previewConfig: Partial<PreviewFileConfig>; | ||
} & Partial<EmbedState>); | ||
previewFile(divId: string, viewerConfig: Partial<PreviewFileConfig>, url: string): any; | ||
onLoaded(): void; | ||
onLoad(): void; | ||
previewFileUsingFilePromise(divId: string, filePromise: any, fileName: string): void; | ||
registerSaveApiHandler(): void; | ||
registerEventsHandler(): void; | ||
render(): JSX.Element; | ||
} | ||
}; | ||
export declare const AdobeReactView: (props: Partial<EmbedState> & { | ||
previewConfig: Partial<PreviewFileConfig>; | ||
}) => JSX.Element; | ||
declare const ReactViewAdobe: (props: Partial<EmbedState> & { | ||
@@ -45,0 +35,0 @@ previewConfig: Partial<PreviewFileConfig>; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25393
452