2022-08-27 14:32:20 +02:00
|
|
|
import React from 'react';
|
|
|
|
import shim from '@joplin/lib/shim';
|
|
|
|
shim.setReact(React);
|
|
|
|
import { render } from 'react-dom';
|
|
|
|
import * as pdfjsLib from 'pdfjs-dist';
|
|
|
|
import MiniViewerApp from './miniViewer';
|
2022-09-11 15:58:32 +02:00
|
|
|
import MessageService from './messageService';
|
|
|
|
import FullViewer from './FullViewer';
|
2022-08-27 14:32:20 +02:00
|
|
|
|
2022-09-05 13:35:38 +02:00
|
|
|
require('./common.css');
|
2022-08-27 14:32:20 +02:00
|
|
|
|
|
|
|
// Setting worker path to worker bundle.
|
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdf.worker.js';
|
|
|
|
|
|
|
|
const url = window.frameElement.getAttribute('x-url');
|
|
|
|
const type = window.frameElement.getAttribute('x-type');
|
|
|
|
const appearance = window.frameElement.getAttribute('x-appearance');
|
2022-09-05 13:35:38 +02:00
|
|
|
const anchorPage = Number(window.frameElement.getAttribute('x-anchorPage')) || null;
|
2022-08-27 14:32:20 +02:00
|
|
|
const pdfId = window.frameElement.getAttribute('id');
|
2022-09-11 15:58:32 +02:00
|
|
|
const resourceId = window.frameElement.getAttribute('x-resourceid');
|
|
|
|
const title = window.frameElement.getAttribute('x-title');
|
2022-08-27 14:32:20 +02:00
|
|
|
|
|
|
|
document.documentElement.setAttribute('data-theme', appearance);
|
|
|
|
|
2022-09-11 15:58:32 +02:00
|
|
|
const messageService = new MessageService(type);
|
|
|
|
|
2022-08-27 14:32:20 +02:00
|
|
|
function App() {
|
|
|
|
if (type === 'mini') {
|
2022-09-05 13:35:38 +02:00
|
|
|
return <MiniViewerApp pdfPath={url}
|
|
|
|
isDarkTheme={appearance === 'dark'}
|
|
|
|
anchorPage={anchorPage}
|
2022-09-11 15:58:32 +02:00
|
|
|
pdfId={pdfId}
|
|
|
|
resourceId={resourceId}
|
|
|
|
messageService={messageService}/>;
|
|
|
|
} else if (type === 'full') {
|
|
|
|
return <FullViewer pdfPath={url}
|
|
|
|
isDarkTheme={appearance === 'dark'}
|
|
|
|
startPage={anchorPage || 1}
|
|
|
|
title={title}
|
|
|
|
messageService={messageService} />;
|
2022-08-27 14:32:20 +02:00
|
|
|
}
|
|
|
|
return <div>Error: Unknown app type "{type}"</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
render(
|
|
|
|
<App/>,
|
|
|
|
document.getElementById('pdf-root')
|
|
|
|
);
|