Commit efcb285a authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate notebook.js module to TypeScript

parent 6de1f58a
import { render } from 'preact'; import { render } from 'preact';
import type { Destroyable } from '../types/annotator';
import NotebookModal from './components/NotebookModal'; import NotebookModal from './components/NotebookModal';
import type { NotebookConfig } from './components/NotebookModal';
import type { EventBus } from './util/emitter';
import { createShadowRoot } from './util/shadow-root'; import { createShadowRoot } from './util/shadow-root';
/** export class Notebook implements Destroyable {
* @typedef {import('../types/annotator').Destroyable} Destroyable private _outerContainer: HTMLElement;
* @typedef {import('./components/NotebookModal').NotebookConfig} NotebookConfig private _shadowRoot: ShadowRoot;
*/
/** @implements {Destroyable} */
export class Notebook {
/** /**
* @param {HTMLElement} element * @param eventBus - Enables communication between components sharing the
* @param {import('./util/emitter').EventBus} eventBus - * same eventBus
* Enables communication between components sharing the same eventBus
* @param {NotebookConfig} config
*/ */
constructor(element, eventBus, config) { constructor(
element: HTMLElement,
eventBus: EventBus,
config: NotebookConfig
) {
/** /**
* Un-styled shadow host for the notebook content. * Un-styled shadow host for the notebook content.
* This isolates the notebook from the page's styles. * This isolates the notebook from the page's styles.
*/ */
this._outerContainer = document.createElement('hypothesis-notebook'); this._outerContainer = document.createElement('hypothesis-notebook');
element.appendChild(this._outerContainer); element.appendChild(this._outerContainer);
this.shadowRoot = createShadowRoot(this._outerContainer); this._shadowRoot = createShadowRoot(this._outerContainer);
render( render(
<NotebookModal eventBus={eventBus} config={config} />, <NotebookModal eventBus={eventBus} config={config} />,
this.shadowRoot this._shadowRoot
); );
} }
destroy() { destroy() {
render(null, this.shadowRoot); render(null, this._shadowRoot);
this._outerContainer.remove(); this._outerContainer.remove();
} }
} }
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