Commit 5ec46e5e authored by Robert Knight's avatar Robert Knight

Swap `config` and `guest` arguments to Sidebar constructor

The `guest` argument is required but the `config` argument is now
optional. Swap them so that required arguments come before optional
ones and set a default value for `config`.
parent b52f00e0
......@@ -48,7 +48,7 @@ const config = configFrom(window);
function init() {
const isPDF = typeof window_.PDFViewerApplication !== 'undefined';
/** @type {(new (e: HTMLElement, config: any, guest: Guest) => Sidebar)|null} */
/** @type {(new (e: HTMLElement, guest: Guest, config: Record<string,any>) => Sidebar)|null} */
let SidebarClass = isPDF ? PdfSidebar : Sidebar;
if (config.subFrameIdentifier) {
......@@ -68,7 +68,7 @@ function init() {
const guest = new Guest(document.body, config);
const sidebar = SidebarClass
? new SidebarClass(document.body, config, guest)
? new SidebarClass(document.body, guest, config)
: null;
const notebook = new Notebook(document.body, config);
......
......@@ -21,11 +21,11 @@ const MIN_PDF_WIDTH = 680;
export default class PdfSidebar extends Sidebar {
/**
* @param {HTMLElement} element
* @param {Record<string, any>} config
* @param {Guest} guest
* @param {Record<string, any>} [config]
*/
constructor(element, config, guest) {
super(element, { ...defaultConfig, ...config }, guest);
constructor(element, guest, config = {}) {
super(element, guest, { ...defaultConfig, ...config });
this._lastSidebarLayoutState = {
expanded: false,
......
......@@ -62,13 +62,13 @@ export default class Sidebar extends Delegator {
* Create the sidebar iframe, its container and adjacent controls.
*
* @param {HTMLElement} element
* @param {Record<string, any>} config
* @param {Guest} guest -
* The `Guest` instance for the current frame. It is currently assumed that
* it is always possible to annotate in the frame where the sidebar is
* displayed.
* @param {Record<string, any>} [config]
*/
constructor(element, config, guest) {
constructor(element, guest, config = {}) {
super(element, config);
this.iframe = createSidebarIframe(config);
......
......@@ -24,7 +24,7 @@ describe('PdfSidebar', () => {
const createPdfSidebar = config => {
const fakeGuest = {};
const element = document.createElement('div');
return new PdfSidebar(element, config, fakeGuest);
return new PdfSidebar(element, fakeGuest, config);
};
let unmockSidebar;
......
......@@ -41,7 +41,7 @@ describe('Sidebar', () => {
document.body.appendChild(container);
containers.push(container);
const sidebar = new Sidebar(container, config, fakeGuest);
const sidebar = new Sidebar(container, fakeGuest, config);
sidebars.push(sidebar);
return sidebar;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment