react-adobe-embed
Version:
React Adobe Embed Custom Component for Adobe PDF Embed API allows you to embed a PDF viewer in your web applications with only a few lines of code. With options for controlling how a PDF appears and functions, your applications can deliver the rich and co
3 lines (2 loc) • 3.75 kB
JavaScript
/* react-adobe-embed */
import e from"react";const t={demoUrl:"https://acrobatservices.adobe.com/view-sdk-demo/PDFs/Bodea%20Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,embedMode:void 0,showPageControls:!1,viewSdkViewerScript:"https://acrobatservices.adobe.com/view-sdk/viewer.js",showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Adobe Example Pdf.pdf",id:"6d07d124 - ac85–43b3 - a867–36930f502ac6"}},i=i=>{const d=e.useRef(document.getElementById(i.id||t.staticDivId));return e.createElement("div",{ref:d,id:i.id||t.staticDivId,className:i.className||"adobe-viewer-of-amazon-corporate-retaliations",style:i.style,title:i.title||"entity-existent-on-frameworks-of-state-regulations-as-defined-by-the-state-and-may-try-to-destroy-your-life-and-control-the-fbi-of-the-state-such-as-amazon-legal-idiots"})};function d({divId:e,viewerConfig:i,url:d,clientID:o,_fileMeta:a,_dcView:n}){const s={clientId:o,divId:e};return(n||new window.AdobeDC.View(s)).previewFile({content:{location:{url:d}},metaData:a||t.demoMetaData},i)}function o({message:e,prefix:t="ReactViewAdobe",type:i="info"}){const d=`[1m${t}[0m: ${e}`;console[i](d)}function a(a){const[n,s]=e.useState(!1),[c,r]=e.useState(!1),[l,f]=e.useState(!1),b=e[a?.useReactHookForAdobeAPIConfigs||"useMemo"],u=e.useCallback((()=>{const e=a.id||t.staticDivId,i=a.previewConfig||t.staticDefaultConfig,o=a.url||t.demoUrl;if("LIGHT_BOX"===i?.embedMode)a.triggerAdobeDCViewRender&&d({divId:e,viewerConfig:i,url:o,clientID:a.clientId,_fileMeta:a.fileMeta});else{document.getElementById(e)&&(a.debug&&console.info("Adobe PDF Viewer: Attempting to preview the file"),d({divId:e,viewerConfig:i,url:o,clientID:a.clientId,_fileMeta:a.fileMeta}))}}),[a.id,a.url,a.clientId,a.fileMeta,a.debug,a.triggerAdobeDCViewRender,a.previewConfig]),w=b((()=>{if(a.debug&&o({message:"At hooks to check if Adobe DC View is available",prefix:"ReactViewAdobe:adobeDCView",type:"info"}),!0===n){const e=window.AdobeDC?.View;return a.debug&&o({message:"Adobe DC View is available",prefix:"ReactViewAdobe:adobeDCView",type:"info"}),e}}),[n]);(0,e[a?.useReactHookWhenLoadingAdobeAPI||"useEffect"])((()=>{if(!1===l){const e=document.querySelector(`script.react-adobe-embed-handholding-adobe-api-loading-idiocy[data-adobe-pdf-id="${a.id||t.staticDivId}"]`);if(e)a.debug&&o({message:"Reloading and Rerendering Adobe SDK",prefix:"ReactViewAdobe:AdobeSDK",type:"info"}),"LIGHT_BOX"!==a.previewConfig?.embedMode&&r(!0),e.setAttribute("data-testid","react-adobe-embed-handholding-adobe-api-loading-idiocy-reused");else{a.debug&&o({message:"Initial Adobe SDK Load",prefix:"ReactViewAdobe:AdobeSDK",type:"info"});const e=document.createElement("script");e.setAttribute("data-testid","react-adobe-embed-handholding-adobe-api-loading-idiocy-initial"),e.setAttribute("data-adobe-pdf-id",a.id||t.staticDivId),e.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),e.src=a.previewConfig?.viewSdkViewerScript||t.staticDefaultConfig.viewSdkViewerScript,e.async=!0,e.onload=()=>{f(!0)},document.body.appendChild(e)}}}),[a.id,l,n]);(0,e[a?.useReactHookWhenCallingAdobeAPI||"useEffect"])((()=>{!1===n&&!0===l&&document.addEventListener("adobe_dc_view_sdk.ready",(()=>{s(!0)}));!0===l&&!0===n&&(e=>{e.debug&&o({message:"At Calling Adobe API to render PDF - window.adobe_dc_view_sdk:"+window.adobe_dc_view_sdk,prefix:"ReactViewAdobe:callAdobeApi",type:"info"}),u()})(a)}),[n,l,a,w]);return(0,e[a?.useReactHookForComponentDidUpdate||"useEffect"])((()=>{if(!0===c){const e=a.id||t.staticDivId;document.getElementById(e)&&u(),r(!1)}}),[c,a]),e.createElement(i,{...a})}export{t as DefaultConfigs,a as ReactViewAdobe,a as default,o as log,d as previewFile};