From a0744d29498cd30a0a2911c6b67044b55a3c9e5a Mon Sep 17 00:00:00 2001 From: Ziping Liu Date: Tue, 26 Sep 2023 09:59:55 -0500 Subject: [PATCH] feat: match code style with adobe pdf api examples when call adobe api --- dist/react-adobe-embed.cdn.js | 2 +- lib/bundle.cjs.js | 2 +- lib/bundle.esm.mjs | 2 +- lib/bundle.js | 2 +- lib/index.js | 57 ++++++++------- package.json | 5 +- src/index.tsx | 126 ++++++++++++++++++++-------------- types/index.d.ts | 16 ++--- 8 files changed, 113 insertions(+), 99 deletions(-) diff --git a/dist/react-adobe-embed.cdn.js b/dist/react-adobe-embed.cdn.js index d084d07..527f420 100644 --- a/dist/react-adobe-embed.cdn.js +++ b/dist/react-adobe-embed.cdn.js @@ -1 +1 @@ -(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(require("react")):"function"==typeof define&&define.amd?define(["react"],b):(a="undefined"==typeof globalThis?a||self:globalThis,b(a.React))})(this,function(a){"use strict";function b(a){return a&&"object"==typeof a&&"default"in a?a:{default:a}}function c({divId:a,viewerConfig:b,url:c,clientID:d,_fileMeta:e,_dcView:g}){const h=g||new window.AdobeDC.View({clientId:d,divId:a}),i=h.previewFile({content:{location:{url:c}},metaData:e||f.demoMetaData},b);return i}function d(a){const[b,d]=e["default"].useState(!1),[h,i]=e["default"].useState(!1),j=e["default"][a?.useReactHookForAdobeAPIConfigs||"useMemo"],k=j(()=>{if(!0===b){const a=window.AdobeDC?.["View"];return a}},[b]),l=e["default"][a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];l(()=>{if(!1===h){const c=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(c)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{d(!0)}),i(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||f.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{i(!0)},document.body.appendChild(b)}}},[a.id,h,b]);const m=e["default"][a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return m(()=>{!1===b&&!0===h&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{d(!0)});!0===h&&!0===b&&(a=>{a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",k,window.adobe_dc_view_sdk);const b=a.id||f.staticDivId,d=document.getElementById(b);d&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),c({divId:b,viewerConfig:a.previewConfig||f.staticDefaultConfig,url:a.url||f.demoUrl,clientID:a.clientId,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&c({divId:a.id||f.staticDivId,viewerConfig:a.previewConfig||f.staticDefaultConfig,url:a.url||f.demoUrl,clientID:a.clientId})})(a)},[b,h,a,k]),e["default"].createElement(g,{...a})}var e=b(a);const f={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}},g=a=>{const b=e["default"].useRef(document.getElementById(a.id||f.staticDivId));return e["default"].createElement("div",{ref:b,id:a.id||f.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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(){window&&window.ReactViewAdobe||(window.ReactViewAdobe=d)})()}); +(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(require("react")):"function"==typeof define&&define.amd?define(["react"],b):(a="undefined"==typeof globalThis?a||self:globalThis,b(a.React))})(this,function(a){"use strict";function b(a){return a&&"object"==typeof a&&"default"in a?a:{default:a}}function c(a){const[b,c]=d["default"].useState(!1),[g,h]=d["default"].useState(!1),i=d["default"].useRef(),j=d["default"][a?.useReactHookForAdobeAPIConfigs||"useEffect"];j(()=>{const c={clientId:a.clientId,divId:a.id||e.staticDivId};b&&g&&(i.current=new window?.AdobeDC?.View(c))},[b,g,a.clientId,a.id]);const k=d["default"][a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];k(()=>{if(!1===g){const d=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(d)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)}),h(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||e.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{h(!0)},document.body.appendChild(b)}}},[a.id,g,b]);const l=d["default"][a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return l(()=>{!1===b&&!0===g&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)});!0===g&&!0===b&&(a=>{const b=({viewerConfig:a,url:b,_headers:c,_fileMeta:d,_dcView:f})=>{const g=f||i.current,h=g.previewFile({content:{location:{url:b}},metaData:d||e.demoMetaData},a);return h};a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",i,window.adobe_dc_view_sdk);const c=a.id||e.staticDivId,d=document.getElementById(c);d&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),b({viewerConfig:a.previewConfig||e.staticDefaultConfig,url:a.url||e.demoUrl,_headers:a.headers,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&b({viewerConfig:a.previewConfig||e.staticDefaultConfig,url:a.url||e.demoUrl,_fileMeta:a.fileMeta,_headers:a.headers})})(a)},[b,g,a,i]),d["default"].createElement(f,{...a})}var d=b(a);const e={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}},f=a=>{const b=d["default"].useRef(document.getElementById(a.id||e.staticDivId));return d["default"].createElement("div",{ref:b,id:a.id||e.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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(){window&&window.ReactViewAdobe||(window.ReactViewAdobe=c)})()}); diff --git a/lib/bundle.cjs.js b/lib/bundle.cjs.js index 508523a..eb45aff 100644 --- a/lib/bundle.cjs.js +++ b/lib/bundle.cjs.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react");function _interopDefaultLegacy(a){return a&&"object"==typeof a&&"default"in a?a:{default:a}}var React__default=_interopDefaultLegacy(React);const DefaultConfigs={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}};function previewFile({divId:a,viewerConfig:b,url:c,clientID:d,_fileMeta:e,_dcView:f}){const g=f||new window.AdobeDC.View({clientId:d,divId:a}),h=g.previewFile({content:{location:{url:c}},metaData:e||DefaultConfigs.demoMetaData},b);return h}const AdobeDiv=a=>{const b=React__default["default"].useRef(document.getElementById(a.id||DefaultConfigs.staticDivId));return React__default["default"].createElement("div",{ref:b,id:a.id||DefaultConfigs.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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 ReactViewAdobe(a){const[b,c]=React__default["default"].useState(!1),[d,e]=React__default["default"].useState(!1),f=React__default["default"][a?.useReactHookForAdobeAPIConfigs||"useMemo"],g=f(()=>{if(!0===b){const a=window.AdobeDC?.["View"];return a}},[b]),h=React__default["default"][a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];h(()=>{if(!1===d){const d=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(d)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)}),e(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||DefaultConfigs.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{e(!0)},document.body.appendChild(b)}}},[a.id,d,b]);const i=React__default["default"][a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return i(()=>{!1===b&&!0===d&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)});!0===d&&!0===b&&(a=>{a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",g,window.adobe_dc_view_sdk);const b=a.id||DefaultConfigs.staticDivId,c=document.getElementById(b);c&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),previewFile({divId:b,viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,clientID:a.clientId,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&previewFile({divId:a.id||DefaultConfigs.staticDivId,viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,clientID:a.clientId})})(a)},[b,d,a,g]),React__default["default"].createElement(AdobeDiv,{...a})}exports["default"]=ReactViewAdobe,exports.previewFile=previewFile; +"use strict";var React=require("react");function _interopDefaultLegacy(a){return a&&"object"==typeof a&&"default"in a?a:{default:a}}var React__default=_interopDefaultLegacy(React);const DefaultConfigs={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}},AdobeDiv=a=>{const b=React__default["default"].useRef(document.getElementById(a.id||DefaultConfigs.staticDivId));return React__default["default"].createElement("div",{ref:b,id:a.id||DefaultConfigs.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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 ReactViewAdobe(a){const[b,c]=React__default["default"].useState(!1),[d,e]=React__default["default"].useState(!1),f=React__default["default"].useRef(),g=React__default["default"][a?.useReactHookForAdobeAPIConfigs||"useEffect"];g(()=>{const c={clientId:a.clientId,divId:a.id||DefaultConfigs.staticDivId};b&&d&&(f.current=new window?.AdobeDC?.View(c))},[b,d,a.clientId,a.id]);const h=React__default["default"][a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];h(()=>{if(!1===d){const d=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(d)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)}),e(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||DefaultConfigs.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{e(!0)},document.body.appendChild(b)}}},[a.id,d,b]);const i=React__default["default"][a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return i(()=>{!1===b&&!0===d&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)});!0===d&&!0===b&&(a=>{const b=({viewerConfig:a,url:b,_headers:c,_fileMeta:d,_dcView:e})=>{const g=e||f.current,h=g.previewFile({content:{location:{url:b}},metaData:d||DefaultConfigs.demoMetaData},a);return h};a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",f,window.adobe_dc_view_sdk);const c=a.id||DefaultConfigs.staticDivId,d=document.getElementById(c);d&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),b({viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,_headers:a.headers,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&b({viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,_fileMeta:a.fileMeta,_headers:a.headers})})(a)},[b,d,a,f]),React__default["default"].createElement(AdobeDiv,{...a})}module.exports=ReactViewAdobe; diff --git a/lib/bundle.esm.mjs b/lib/bundle.esm.mjs index 82ce007..4ec875e 100644 --- a/lib/bundle.esm.mjs +++ b/lib/bundle.esm.mjs @@ -1 +1 @@ -import React from"react";const DefaultConfigs={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}};function previewFile({divId:a,viewerConfig:b,url:c,clientID:d,_fileMeta:e,_dcView:f}){const g=f||new window.AdobeDC.View({clientId:d,divId:a}),h=g.previewFile({content:{location:{url:c}},metaData:e||DefaultConfigs.demoMetaData},b);return h}const AdobeDiv=a=>{const b=React.useRef(document.getElementById(a.id||DefaultConfigs.staticDivId));return React.createElement("div",{ref:b,id:a.id||DefaultConfigs.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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 ReactViewAdobe(a){const[b,c]=React.useState(!1),[d,e]=React.useState(!1),f=React[a?.useReactHookForAdobeAPIConfigs||"useMemo"],g=f(()=>{if(!0===b){const a=window.AdobeDC?.["View"];return a}},[b]),h=React[a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];h(()=>{if(!1===d){const d=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(d)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)}),e(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||DefaultConfigs.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{e(!0)},document.body.appendChild(b)}}},[a.id,d,b]);const i=React[a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return i(()=>{!1===b&&!0===d&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)});!0===d&&!0===b&&(a=>{a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",g,window.adobe_dc_view_sdk);const b=a.id||DefaultConfigs.staticDivId,c=document.getElementById(b);c&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),previewFile({divId:b,viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,clientID:a.clientId,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&previewFile({divId:a.id||DefaultConfigs.staticDivId,viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,clientID:a.clientId})})(a)},[b,d,a,g]),React.createElement(AdobeDiv,{...a})}export{ReactViewAdobe as default,previewFile}; +import React from"react";const DefaultConfigs={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}},AdobeDiv=a=>{const b=React.useRef(document.getElementById(a.id||DefaultConfigs.staticDivId));return React.createElement("div",{ref:b,id:a.id||DefaultConfigs.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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 ReactViewAdobe(a){const[b,c]=React.useState(!1),[d,e]=React.useState(!1),f=React.useRef(),g=React[a?.useReactHookForAdobeAPIConfigs||"useEffect"];g(()=>{const c={clientId:a.clientId,divId:a.id||DefaultConfigs.staticDivId};b&&d&&(f.current=new window?.AdobeDC?.View(c))},[b,d,a.clientId,a.id]);const h=React[a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];h(()=>{if(!1===d){const d=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(d)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)}),e(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||DefaultConfigs.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{e(!0)},document.body.appendChild(b)}}},[a.id,d,b]);const i=React[a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return i(()=>{!1===b&&!0===d&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)});!0===d&&!0===b&&(a=>{const b=({viewerConfig:a,url:b,_headers:c,_fileMeta:d,_dcView:e})=>{const g=e||f.current,h=g.previewFile({content:{location:{url:b}},metaData:d||DefaultConfigs.demoMetaData},a);return h};a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",f,window.adobe_dc_view_sdk);const c=a.id||DefaultConfigs.staticDivId,d=document.getElementById(c);d&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),b({viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,_headers:a.headers,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&b({viewerConfig:a.previewConfig||DefaultConfigs.staticDefaultConfig,url:a.url||DefaultConfigs.demoUrl,_fileMeta:a.fileMeta,_headers:a.headers})})(a)},[b,d,a,f]),React.createElement(AdobeDiv,{...a})}export{ReactViewAdobe as default}; diff --git a/lib/bundle.js b/lib/bundle.js index b175826..1b20b5f 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -1 +1 @@ -(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],b):(a="undefined"==typeof globalThis?a||self:globalThis,b(a.ReactAdobeEmbed={},a.React))})(this,function(a,b){"use strict";function c(a){return a&&"object"==typeof a&&"default"in a?a:{default:a}}function d({divId:a,viewerConfig:b,url:c,clientID:d,_fileMeta:e,_dcView:g}){const h=g||new window.AdobeDC.View({clientId:d,divId:a}),i=h.previewFile({content:{location:{url:c}},metaData:e||f.demoMetaData},b);return i}var e=c(b);const f={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}},g=a=>{const b=e["default"].useRef(document.getElementById(a.id||f.staticDivId));return e["default"].createElement("div",{ref:b,id:a.id||f.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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"})};a["default"]=function(a){const[b,c]=e["default"].useState(!1),[h,i]=e["default"].useState(!1),j=e["default"][a?.useReactHookForAdobeAPIConfigs||"useMemo"],k=j(()=>{if(!0===b){const a=window.AdobeDC?.["View"];return a}},[b]),l=e["default"][a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];l(()=>{if(!1===h){const d=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(d)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)}),i(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||f.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{i(!0)},document.body.appendChild(b)}}},[a.id,h,b]);const m=e["default"][a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return m(()=>{!1===b&&!0===h&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{c(!0)});!0===h&&!0===b&&(a=>{a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",k,window.adobe_dc_view_sdk);const b=a.id||f.staticDivId,c=document.getElementById(b);c&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),d({divId:b,viewerConfig:a.previewConfig||f.staticDefaultConfig,url:a.url||f.demoUrl,clientID:a.clientId,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&d({divId:a.id||f.staticDivId,viewerConfig:a.previewConfig||f.staticDefaultConfig,url:a.url||f.demoUrl,clientID:a.clientId})})(a)},[b,h,a,k]),e["default"].createElement(g,{...a})},a.previewFile=d,Object.defineProperty(a,"__esModule",{value:!0})}); +(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("react")):"function"==typeof define&&define.amd?define(["react"],b):(a="undefined"==typeof globalThis?a||self:globalThis,a.ReactAdobeEmbed=b(a.React))})(this,function(a){"use strict";function b(a){return a&&"object"==typeof a&&"default"in a?a:{default:a}}var c=b(a);const d={demoUrl:"https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,showPageControls:!1,showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Menu.pdf",id:"6d07d124 - ac85\u201343b3 - a867\u201336930f502ac6"}},e=a=>{const b=c["default"].useRef(document.getElementById(a.id||d.staticDivId));return c["default"].createElement("div",{ref:b,id:a.id||d.staticDivId,className:a.className||"adobe-viewer-of-amazon-corporate-retaliations",style:a.style,title:a.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"})};return function(a){const[b,f]=c["default"].useState(!1),[g,h]=c["default"].useState(!1),i=c["default"].useRef(),j=c["default"][a?.useReactHookForAdobeAPIConfigs||"useEffect"];j(()=>{const c={clientId:a.clientId,divId:a.id||d.staticDivId};b&&g&&(i.current=new window?.AdobeDC?.View(c))},[b,g,a.clientId,a.id]);const k=c["default"][a?.useReactHookWhenLoadingAdobeAPI||"useEffect"];k(()=>{if(!1===g){const c=document.querySelector(".react-adobe-embed-handholding-adobe-api-loading-idiocy");if(c)!1===b&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{f(!0)}),h(!0);else{const b=document.createElement("script");b.setAttribute("data-adobe-pdf-id",a.id||d.staticDivId),b.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),b.src="https://documentcloud.adobe.com/view-sdk/viewer.js",b.async=!0,b.onload=()=>{h(!0)},document.body.appendChild(b)}}},[a.id,g,b]);const l=c["default"][a?.useReactHookWhenCallingAdobeAPI||"useEffect"];return l(()=>{!1===b&&!0===g&&document.addEventListener("adobe_dc_view_sdk.ready",()=>{f(!0)});!0===g&&!0===b&&(a=>{const b=({viewerConfig:a,url:b,_headers:c,_fileMeta:e,_dcView:f})=>{const g=f||i.current,h=g.previewFile({content:{location:{url:b}},metaData:e||d.demoMetaData},a);return h};a.debug&&console.info("Adobe PDF Viewer SDK Ready Event",i,window.adobe_dc_view_sdk);const c=a.id||d.staticDivId,e=document.getElementById(c);e&&"LIGHT_BOX"!==a.previewConfig?.embedMode?(a.debug&&console.info("Adobe PDF Viewer SDK Ready Rendering"),b({viewerConfig:a.previewConfig||d.staticDefaultConfig,url:a.url||d.demoUrl,_headers:a.headers,_fileMeta:a.fileMeta})):"LIGHT_BOX"===a.previewConfig?.embedMode&&a?.triggerAdobeDCViewRender&&b({viewerConfig:a.previewConfig||d.staticDefaultConfig,url:a.url||d.demoUrl,_fileMeta:a.fileMeta,_headers:a.headers})})(a)},[b,g,a,i]),c["default"].createElement(e,{...a})}}); diff --git a/lib/index.js b/lib/index.js index e16ed7b..c302e94 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,24 +14,6 @@ const DefaultConfigs = { id: "6d07d124 - ac85–43b3 - a867–36930f502ac6", }, }; -export function previewFile({ divId, viewerConfig, url, clientID, _fileMeta, _dcView, }) { - const config = { - clientId: clientID, - divId, - }; - const dcView = _dcView || new window.AdobeDC.View(config); - { - } - const previewFilePromise = dcView.previewFile({ - content: { - location: { - url: url, - }, - }, - metaData: _fileMeta || DefaultConfigs.demoMetaData, - }, viewerConfig); - return previewFilePromise; -} const AdobeDiv = (props) => { const ref = React.useRef(document.getElementById(props.id || DefaultConfigs.staticDivId)); return (React.createElement("div", { ref: ref, id: props.id || DefaultConfigs.staticDivId, className: props.className || "adobe-viewer-of-amazon-corporate-retaliations", style: props.style, title: props.title || @@ -46,13 +28,17 @@ const AdobeDiv = (props) => { export default function ReactViewAdobe(props) { const [adobePDFProgrammeInstalled, setAdobePDFProgrammeInstalled] = React.useState(false); const [scriptViewerLoaded, setScriptViewerLoaded] = React.useState(false); - const useHooksForConfig = React[props?.useReactHookForAdobeAPIConfigs || "useMemo"]; - const adobeDCView = useHooksForConfig(() => { - if (adobePDFProgrammeInstalled === true) { - const adobedcview = window["AdobeDC"]?.["View"]; - return adobedcview; + const adobeDCViewRef = React.useRef(); + const useHooksForAdobeConfig = React[props?.useReactHookForAdobeAPIConfigs || "useEffect"]; + useHooksForAdobeConfig(() => { + const config = { + clientId: props.clientId, + divId: props.id || DefaultConfigs.staticDivId, + }; + if (adobePDFProgrammeInstalled && scriptViewerLoaded) { + adobeDCViewRef.current = new (window?.AdobeDC?.View)(config); } - }, [adobePDFProgrammeInstalled]); + }, [adobePDFProgrammeInstalled, scriptViewerLoaded, props.clientId, props.id]); const useHooksForLoading = React[props?.useReactHookWhenLoadingAdobeAPI || "useEffect"]; (useHooksForLoading)(() => { if (scriptViewerLoaded === false) { @@ -86,28 +72,39 @@ export default function ReactViewAdobe(props) { }); } const callAdobeApi = (props) => { + const previewFile = ({ viewerConfig, url, _headers, _fileMeta, _dcView, }) => { + const dcView = _dcView || adobeDCViewRef.current; + const previewFilePromise = dcView.previewFile({ + content: { + location: { + url: url, + }, + }, + metaData: _fileMeta || DefaultConfigs.demoMetaData, + }, viewerConfig); + return previewFilePromise; + }; if (props.debug) - console.info("Adobe PDF Viewer SDK Ready Event", adobeDCView, window["adobe_dc_view_sdk"]); + console.info("Adobe PDF Viewer SDK Ready Event", adobeDCViewRef, window["adobe_dc_view_sdk"]); const divId = props.id || DefaultConfigs.staticDivId; const divElm = document.getElementById(divId); if (divElm && props.previewConfig?.embedMode !== "LIGHT_BOX") { if (props.debug) console.info("Adobe PDF Viewer SDK Ready Rendering"); previewFile({ - divId, viewerConfig: props.previewConfig || DefaultConfigs.staticDefaultConfig, url: props.url || DefaultConfigs.demoUrl, - clientID: props.clientId, + _headers: props.headers, _fileMeta: props.fileMeta, }); } else if (props.previewConfig?.embedMode === "LIGHT_BOX") { if (props?.triggerAdobeDCViewRender) { previewFile({ - divId: props.id || DefaultConfigs.staticDivId, viewerConfig: props.previewConfig || DefaultConfigs.staticDefaultConfig, url: props.url || DefaultConfigs.demoUrl, - clientID: props.clientId, + _fileMeta: props.fileMeta, + _headers: props.headers }); } } @@ -115,7 +112,7 @@ export default function ReactViewAdobe(props) { if (scriptViewerLoaded === true && adobePDFProgrammeInstalled === true) { callAdobeApi(props); } - }, [adobePDFProgrammeInstalled, scriptViewerLoaded, props, adobeDCView]); + }, [adobePDFProgrammeInstalled, scriptViewerLoaded, props, adobeDCViewRef]); return React.createElement(AdobeDiv, { ...props }); } ; diff --git a/package.json b/package.json index 3a91415..ea03cf5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-adobe-embed", - "version": "7.0.5", + "version": "8.0.0", "homepage": "https://aboutamazon.me/react-adobe-embed", "repository": { "type": "git", @@ -37,10 +37,11 @@ ], - "main": "lib/bundle.js", + "umd:main": "lib/bundle.js", "module": "lib/bundle.esm.mjs", + "main": "lib/bundle.cjs.js", "exports": { ".": { diff --git a/src/index.tsx b/src/index.tsx index f512d9a..5f6434a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -78,43 +78,6 @@ export type PreviewFileConfig = { focusOnRendering: any; }; -export function previewFile({ - divId, - viewerConfig, - url, - clientID, - _fileMeta, - _dcView, -}: { - divId: string; - viewerConfig: Partial; - url: string; - clientID: string; - _dcView?: any; - _fileMeta?: { [key: string | "fileName" | "id"]: any }; -}) { - const config = { - clientId: clientID, - divId, - }; - - const dcView = _dcView || new (window as any).AdobeDC.View(config); - { - } - const previewFilePromise = dcView.previewFile( - { - content: { - location: { - url: url, - }, - }, - metaData: _fileMeta || DefaultConfigs.demoMetaData, - }, - viewerConfig, - ); - return previewFilePromise; -} - export type ReactHooks = { [key in (Extract @@ -163,6 +126,10 @@ export type ReactViewAdobeProps = { url: string; clientId: string; fileMeta?: { [key: string | "fileName" | "id"]: any }; + headers?:{ + key: string; + value: string; + }[], debug?: boolean; }; @@ -206,14 +173,29 @@ const AdobeDiv = (props: { React.useState(false); const [scriptViewerLoaded, setScriptViewerLoaded] = React.useState(false); - const useHooksForConfig = React[props?.useReactHookForAdobeAPIConfigs || "useMemo"] ; - const adobeDCView = - useHooksForConfig(() => { - if (adobePDFProgrammeInstalled === true) { - const adobedcview = (window as any)["AdobeDC"]?.["View"]; - return adobedcview; + + + + + const adobeDCViewRef = React.useRef<{ previewFile: any }>(); + + const useHooksForAdobeConfig = React[props?.useReactHookForAdobeAPIConfigs || "useEffect"] + + useHooksForAdobeConfig(()=>{ + const config = { + clientId: props.clientId, + divId: props.id || DefaultConfigs.staticDivId, + }; + + if(adobePDFProgrammeInstalled && scriptViewerLoaded){ + adobeDCViewRef.current = new ((window as any)?.AdobeDC?.View)(config); } - }, [adobePDFProgrammeInstalled]); + + + + },[adobePDFProgrammeInstalled, scriptViewerLoaded, props.clientId, props.id]); + + const useHooksForLoading = React[props?.useReactHookWhenLoadingAdobeAPI || "useEffect"] ; @@ -280,14 +262,54 @@ const AdobeDiv = (props: { previewConfig?: Partial; url: string; clientId: string; - + headers?:{ + key: string; + value: string;}[], fileMeta?: { [key: string | "fileName" | "id"]: any }; } ) =>{ + + const previewFile = ({ + + viewerConfig, + url, + _headers, + _fileMeta, + _dcView, +}: { + + viewerConfig: Partial; + url: string; + _headers?: { + key: string; + value: string; + }[]; + _dcView?: any; + _fileMeta?: { [key: string | "fileName" | "id"]: any }; +}) =>{ + + + + const dcView = _dcView || adobeDCViewRef.current; + + const previewFilePromise = dcView.previewFile( + { + content: { + location: { + url: url, + }, + }, + metaData: _fileMeta || DefaultConfigs.demoMetaData, + }, + viewerConfig, + ); + return previewFilePromise; +} + if (props.debug) console.info( "Adobe PDF Viewer SDK Ready Event", - adobeDCView, + adobeDCViewRef, (window as any)["adobe_dc_view_sdk"], ); const divId = props.id || DefaultConfigs.staticDivId; @@ -296,21 +318,22 @@ const AdobeDiv = (props: { if (divElm && props.previewConfig?.embedMode !== "LIGHT_BOX") { if (props.debug) console.info("Adobe PDF Viewer SDK Ready Rendering"); previewFile({ - divId, + viewerConfig: props.previewConfig || DefaultConfigs.staticDefaultConfig, url: props.url || DefaultConfigs.demoUrl, - clientID: props.clientId, + _headers: props.headers, _fileMeta: props.fileMeta, }); } else if (props.previewConfig?.embedMode === "LIGHT_BOX") { if (props?.triggerAdobeDCViewRender) { previewFile({ - divId: props.id || DefaultConfigs.staticDivId, + viewerConfig: props.previewConfig || DefaultConfigs.staticDefaultConfig, url: props.url || DefaultConfigs.demoUrl, - clientID: props.clientId, + _fileMeta: props.fileMeta, + _headers: props.headers }); } } @@ -321,9 +344,8 @@ const AdobeDiv = (props: { ); } - }, [adobePDFProgrammeInstalled, scriptViewerLoaded, props,adobeDCView] ); + }, [adobePDFProgrammeInstalled, scriptViewerLoaded, props,adobeDCViewRef] ); - return ; }; diff --git a/types/index.d.ts b/types/index.d.ts index 3ebab71..bb8a6f1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -52,16 +52,6 @@ export type PreviewFileConfig = { */ focusOnRendering: any; }; -export declare function previewFile({ divId, viewerConfig, url, clientID, _fileMeta, _dcView, }: { - divId: string; - viewerConfig: Partial; - url: string; - clientID: string; - _dcView?: any; - _fileMeta?: { - [key: string | "fileName" | "id"]: any; - }; -}): any; export type ReactHooks = { [key in (Extract)]: [ ] extends Parameters ? never : key extends 'useReducer' ? never : key extends 'useDeferredValue' ? never : typeof React[key] extends (factory: React.EffectCallback, deps?: React.DependencyList | undefined) => void ? key : typeof React[key] extends (factory: () => any, deps: React.DependencyList | undefined) => void ? key : never; @@ -90,6 +80,10 @@ export type ReactViewAdobeProps = { fileMeta?: { [key: string | "fileName" | "id"]: any; }; + headers?: { + key: string; + value: string; + }[]; debug?: boolean; }; /** @@ -98,4 +92,4 @@ export type ReactViewAdobeProps = { * compartmentalized and fully encapsulated and configured within a rendered page. Not sure why Adobe * Embed API does not inherently do this. See ReactViewAdobeProps for more details. */ -export default function ReactViewAdobe(props: ReactViewAdobeProps): JSX.Element; +export default function ReactViewAdobe(props: ReactViewAdobeProps): React.JSX.Element;