diff --git a/package-lock.json b/package-lock.json
index 3ebad39..08487d2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "react-adobe-embed",
- "version": "11.0.12",
+ "version": "11.2.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "react-adobe-embed",
- "version": "11.0.12",
+ "version": "11.2.5",
"license": "MIT HUTTENLOCHER WHAT ARE YOU DOING BOARD OF DIRECTOR AT AMAZON?",
"devDependencies": {
"@babel/core": "^7.23.2",
diff --git a/package.json b/package.json
index 692f10a..0a99cda 100644
--- a/package.json
+++ b/package.json
@@ -47,19 +47,10 @@
"Adobe Developer",
"Adobe PDF Embed API"
],
- "umd:main": "lib/bundle.js",
+ "umd:main": "lib/index.js",
"cdn:main": "dist/react-adobe-embed.cdn.js",
- "module": "lib/bundle.esm.mjs",
- "main": "lib/bundle.cjs.js",
-
- "exports": {
- ".": {
- "require": "./lib/bundle.cjs.js",
- "import": "./lib/bundle.esm.mjs",
- "default": "./dist/react-adobe-embed.cdn.js",
- "umd":"./dist/react-adobe-embed.cdn.js"
- }
- },
+ "module": "lib/bundle.esm.js",
+ "main": "lib/bundle.cjs.js",
"types": "lib/bundle.esm.d.ts",
"files": [
"lib",
@@ -151,4 +142,4 @@
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1"
}
-}
\ No newline at end of file
+}
diff --git a/rollup.config.canary.js b/rollup.config.canary.js
index 1882e8f..12655d9 100644
--- a/rollup.config.canary.js
+++ b/rollup.config.canary.js
@@ -51,7 +51,7 @@ const config = {
"dist",
],
- babelHelpers: 'external',
+ babelHelpers: "inline",
include: [
"canary/App.tsx"
],
diff --git a/rollup.config.cdn.js b/rollup.config.cdn.js
index f64878d..2eab64b 100644
--- a/rollup.config.cdn.js
+++ b/rollup.config.cdn.js
@@ -42,7 +42,7 @@ const config = {
babel({
exclude: 'node_modules/**',
- babelHelpers: 'external',
+ babelHelpers: "inline",
presets: [
"@babel/preset-env",
"@babel/preset-react",
diff --git a/rollup.config.js b/rollup.config.js
index 6eca0bb..7a76419 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -50,7 +50,7 @@ export default [
localResolve(),
babel({ exclude: 'node_modules/**, src/tests/**' ,
- babelHelpers: 'external',
+ babelHelpers: "inline",
presets: [
"@babel/preset-env",
"@babel/preset-react",
diff --git a/src/__tests__/__snapshots__/base.test.tsx.snap b/src/__tests__/__snapshots__/base.test.tsx.snap
index bc62750..a4dcd72 100644
--- a/src/__tests__/__snapshots__/base.test.tsx.snap
+++ b/src/__tests__/__snapshots__/base.test.tsx.snap
@@ -8,6 +8,17 @@ exports[`BasicRender should render the component 1`] = `
class="adobe-viewer-of-amazon-corporate-retaliations"
id="pdf-div"
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"
- />
+ >
+
+
+
+
`;
diff --git a/src/__tests__/base.test.tsx b/src/__tests__/base.test.tsx
index 7c014dc..81ed470 100644
--- a/src/__tests__/base.test.tsx
+++ b/src/__tests__/base.test.tsx
@@ -12,6 +12,25 @@ import {
describe('BasicRender', () => {
test('should render the component', async () => {
+ const previewFile = jest.fn();
+ (global as any).AdobeDC = {
+ View:
+ class {
+ constructor() {
+
+ }
+
+
+ previewFile = previewFile;
+ },
+
+
+
+
+
+ }
+
+
diff --git a/src/index.tsx b/src/index.tsx
index 6c71b23..6a35f65 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,4 +1,5 @@
import React from "react";
+import ReactDOM from "react-dom/client";
export function previewFile({
divId,
@@ -77,6 +78,7 @@ const AdobeDiv = (props: {
className?: string;
title?: string;
+ children?: React.ReactNode;
style?: React.CSSProperties;
}) => {
const ref = React.useRef(
@@ -96,7 +98,9 @@ const AdobeDiv = (props: {
props.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"
}
- >
+ >
+ {props.children}
+
);
};
@@ -109,7 +113,9 @@ const AdobeDiv = (props: {
export default function ReactViewAdobe(props: ReactViewAdobeProps) {
const [adobePDFProgrammeInstalled, setAdobePDFProgrammeInstalled] =
React.useState(false);
-
+ const [scriptLoaderRef, setScriptLoaderRef] = React.useState<
+ React.RefObject | null
+ >(null);
const [componentNeedsRendering, setComponentNeedsRendering] =
React.useState(false);
const [scriptViewerLoaded, setScriptViewerLoaded] = React.useState(false);
@@ -120,57 +126,105 @@ export default function ReactViewAdobe(props: ReactViewAdobeProps) {
const adobedcview = (window as any)["AdobeDC"]?.["View"];
return adobedcview;
}
+
}, [adobePDFProgrammeInstalled]);
const useHooksForLoading =
React[props?.useReactHookWhenLoadingAdobeAPI || "useEffect"];
useHooksForLoading(() => {
- if (scriptViewerLoaded === false) {
- const scriptExistsALready = document.querySelector(
- `script.react-adobe-embed-handholding-adobe-api-loading-idiocy[data-adobe-pdf-id="${props.id || DefaultConfigs.staticDivId}"]`,
- );
- if (scriptExistsALready) {
- if (props.debug)
- console.info(`\x1b[1mAdobe SDK Check\x1b[0m`, 'Reloading and Rerendering Adobe SDK');
- // Lightbox mode renders from ui event triggered by user, so no need to render
- if(props.previewConfig?.embedMode !== "LIGHT_BOX"){
- setComponentNeedsRendering(true);
+ const ScriptAdobeLoader = (scriptprops:{
+ onLoad: () => void
+ }) => {
+
+ const [componentDidUpdate, setComponentDidUpdate] = React.useState(false);
+ const [componentDidMount, setComponentDidMount] = React.useState(false);
+
+ React.useEffect(() => {
+ if(scriptLoaderRef === null){
+ setScriptLoaderRef(React.createRef());
+
+ }
+ if (componentDidMount === false) {
+
+ setComponentDidMount(true);
+
}
-
- scriptExistsALready.setAttribute(
- "data-testid",
- "react-adobe-embed-handholding-adobe-api-loading-idiocy-reused",
- );
+ if(componentDidUpdate === false && componentDidMount === true){
+
+ const scriptElem = document.createElement('script');
+ scriptElem.setAttribute('src', props.previewConfig?.viewSdkViewerScript || DefaultConfigs.staticDefaultConfig.viewSdkViewerScript);
+ scriptElem.setAttribute('data-adobe-pdf-id', props.id || DefaultConfigs.staticDivId);
+ scriptElem.setAttribute('data-testid', 'react-adobe-embed-handholding-adobe-api-loading-idiocy-initial');
+ scriptElem.setAttribute('id', 'react-adobe-embed-handholding-adobe-api-loading-idiocy-react-managed-script-loading-observer');
+ scriptElem.setAttribute('type', 'text/javascript');
+ scriptElem.setAttribute('async', 'true');
+
+
+ document.body.appendChild(scriptElem);
+ setComponentDidUpdate(true);
+ scriptprops?.onLoad && scriptprops.onLoad();
+
+ }
+ }, [componentDidMount, componentDidUpdate, props.previewConfig?.viewSdkViewerScript, props.id, scriptLoaderRef, scriptprops]);
+
+
+ return (
+
+ )
+ }
+
+ if (scriptViewerLoaded == false){
+ const scriptExistsALready = document.querySelector( `script[data-adobe-pdf-id="${props.id || DefaultConfigs.staticDivId}"]`);
+ console.info('scriptExistsALready', scriptExistsALready,scriptLoaderRef );
+ if (scriptExistsALready ) {
+
+ if(props.previewConfig?.embedMode !== 'LIGHT_BOX'){
+ setComponentNeedsRendering(true);
+ }
+
+ scriptExistsALready.setAttribute('data-testid', 'react-adobe-embed-handholding-adobe-api-loading-idiocy-reused');
+
+
+ scriptLoaderRef?.current?.setAttribute('data-testid', 'react-adobe-embed-handholding-adobe-api-loading-idiocy-reused');
+
+ if (props.debug)
+ console.info(`\x1b[1mAdobe SDK Check\x1b[0m`, 'Adobe SDK Already Loaded so Setting Flag for Rerender Needed');
+
} else {
if (props.debug)
console.info(`\x1b[1mAdobe SDK Check\x1b[0m`, 'Initial Adobe SDK Load');
- const script = document.createElement("script");
- script.setAttribute(
- "data-testid",
- "react-adobe-embed-handholding-adobe-api-loading-idiocy-initial",
- );
+ const scriptElemWrap = document.querySelector(
+ `#${props.id || DefaultConfigs.staticDivId} #adobe-pdf-viewer-sdk-script-loader`,
+ )
+ console.info('scriptElemWrap', scriptElemWrap)
- script.setAttribute(
- "data-adobe-pdf-id",
- props.id || DefaultConfigs.staticDivId,
- );
- script.setAttribute(
- "class",
- "react-adobe-embed-handholding-adobe-api-loading-idiocy",
- );
- script.src =
- props.previewConfig?.viewSdkViewerScript ||
- DefaultConfigs.staticDefaultConfig.viewSdkViewerScript;
- script.async = true;
- script.onload = () => {
- setScriptViewerLoaded(true);
- };
- document.body.appendChild(script);
+
+
+ if(scriptElemWrap) {
+
+ ReactDOM.createRoot(scriptElemWrap).render({
+ setScriptViewerLoaded(true);
+ }}
+ />)
+ }
+
+
+
}
}
- }, [props.id, scriptViewerLoaded, adobePDFProgrammeInstalled]);
+ }, [props.id, scriptViewerLoaded, adobePDFProgrammeInstalled , props.previewConfig?.viewSdkViewerScript, scriptLoaderRef]);
const useHooksForCall =
React[props?.useReactHookWhenCallingAdobeAPI || "useEffect"];
@@ -253,7 +307,11 @@ export default function ReactViewAdobe(props: ReactViewAdobeProps) {
}
}, [componentNeedsRendering, props]);
- return ;
+ return
+
+
+
+
}