Commit 725f2c09 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate shadow-root module to TS

parent 702100ee
/** /**
* Load stylesheets for annotator UI components into the shadow DOM root. * Load stylesheets for annotator UI components into the shadow DOM root.
*
* @param {ShadowRoot} shadowRoot
*/ */
function loadStyles(shadowRoot) { function loadStyles(shadowRoot: ShadowRoot) {
// Find the preloaded stylesheet added by the boot script. // Find the preloaded stylesheet added by the boot script.
const url = /** @type {HTMLLinkElement|undefined} */ ( const url = (
document.querySelector( document.querySelector(
'link[rel="preload"][href*="/build/styles/annotator.css"]' 'link[rel="preload"][href*="/build/styles/annotator.css"]'
) ) as HTMLLinkElement | undefined
)?.href; )?.href;
if (!url) { if (!url) {
...@@ -25,10 +23,9 @@ function loadStyles(shadowRoot) { ...@@ -25,10 +23,9 @@ function loadStyles(shadowRoot) {
* Create the shadow root for an annotator UI component and load the annotator * Create the shadow root for an annotator UI component and load the annotator
* CSS styles into it. * CSS styles into it.
* *
* @param {HTMLElement} container - Container element to render the UI into * @param container - Container element to render the UI into
* @return {ShadowRoot}
*/ */
export function createShadowRoot(container) { export function createShadowRoot(container: HTMLElement): ShadowRoot {
const shadowRoot = container.attachShadow({ mode: 'open' }); const shadowRoot = container.attachShadow({ mode: 'open' });
loadStyles(shadowRoot); loadStyles(shadowRoot);
...@@ -53,10 +50,8 @@ export function createShadowRoot(container) { ...@@ -53,10 +50,8 @@ export function createShadowRoot(container) {
* Another benefit is that click and touchstart typically causes the sidebar to close. * Another benefit is that click and touchstart typically causes the sidebar to close.
* By preventing the bubble up of these events, we don't have to individually stop * By preventing the bubble up of these events, we don't have to individually stop
* the propagation. * the propagation.
*
* @param {HTMLElement|ShadowRoot} element
*/ */
function stopEventPropagation(element) { function stopEventPropagation(element: HTMLElement | ShadowRoot) {
element.addEventListener('mouseup', event => event.stopPropagation()); element.addEventListener('mouseup', event => event.stopPropagation());
element.addEventListener('mousedown', event => event.stopPropagation()); element.addEventListener('mousedown', event => event.stopPropagation());
element.addEventListener('touchstart', event => event.stopPropagation(), { element.addEventListener('touchstart', event => event.stopPropagation(), {
......
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