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); ...@@ -48,7 +48,7 @@ const config = configFrom(window);
function init() { function init() {
const isPDF = typeof window_.PDFViewerApplication !== 'undefined'; 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; let SidebarClass = isPDF ? PdfSidebar : Sidebar;
if (config.subFrameIdentifier) { if (config.subFrameIdentifier) {
...@@ -68,7 +68,7 @@ function init() { ...@@ -68,7 +68,7 @@ function init() {
const guest = new Guest(document.body, config); const guest = new Guest(document.body, config);
const sidebar = SidebarClass const sidebar = SidebarClass
? new SidebarClass(document.body, config, guest) ? new SidebarClass(document.body, guest, config)
: null; : null;
const notebook = new Notebook(document.body, config); const notebook = new Notebook(document.body, config);
......
...@@ -21,11 +21,11 @@ const MIN_PDF_WIDTH = 680; ...@@ -21,11 +21,11 @@ const MIN_PDF_WIDTH = 680;
export default class PdfSidebar extends Sidebar { export default class PdfSidebar extends Sidebar {
/** /**
* @param {HTMLElement} element * @param {HTMLElement} element
* @param {Record<string, any>} config
* @param {Guest} guest * @param {Guest} guest
* @param {Record<string, any>} [config]
*/ */
constructor(element, config, guest) { constructor(element, guest, config = {}) {
super(element, { ...defaultConfig, ...config }, guest); super(element, guest, { ...defaultConfig, ...config });
this._lastSidebarLayoutState = { this._lastSidebarLayoutState = {
expanded: false, expanded: false,
......
...@@ -62,13 +62,13 @@ export default class Sidebar extends Delegator { ...@@ -62,13 +62,13 @@ export default class Sidebar extends Delegator {
* Create the sidebar iframe, its container and adjacent controls. * Create the sidebar iframe, its container and adjacent controls.
* *
* @param {HTMLElement} element * @param {HTMLElement} element
* @param {Record<string, any>} config
* @param {Guest} guest - * @param {Guest} guest -
* The `Guest` instance for the current frame. It is currently assumed that * 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 * it is always possible to annotate in the frame where the sidebar is
* displayed. * displayed.
* @param {Record<string, any>} [config]
*/ */
constructor(element, config, guest) { constructor(element, guest, config = {}) {
super(element, config); super(element, config);
this.iframe = createSidebarIframe(config); this.iframe = createSidebarIframe(config);
......
...@@ -24,7 +24,7 @@ describe('PdfSidebar', () => { ...@@ -24,7 +24,7 @@ describe('PdfSidebar', () => {
const createPdfSidebar = config => { const createPdfSidebar = config => {
const fakeGuest = {}; const fakeGuest = {};
const element = document.createElement('div'); const element = document.createElement('div');
return new PdfSidebar(element, config, fakeGuest); return new PdfSidebar(element, fakeGuest, config);
}; };
let unmockSidebar; let unmockSidebar;
......
...@@ -41,7 +41,7 @@ describe('Sidebar', () => { ...@@ -41,7 +41,7 @@ describe('Sidebar', () => {
document.body.appendChild(container); document.body.appendChild(container);
containers.push(container); containers.push(container);
const sidebar = new Sidebar(container, config, fakeGuest); const sidebar = new Sidebar(container, fakeGuest, config);
sidebars.push(sidebar); sidebars.push(sidebar);
return 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