diff --git a/components/check-permissions/checkPermissions.js b/components/check-permissions/checkPermissions.js index 56f00575..c7469f3a 100644 --- a/components/check-permissions/checkPermissions.js +++ b/components/check-permissions/checkPermissions.js @@ -17,13 +17,14 @@ import TPEN from '../../api/TPEN.js' import { getUserFromToken } from '../../components/iiif-tools/index.js' import { permissionMatch } from "../../components/check-permissions/permission-match.js" +import { whenProjectReady } from "../../utilities/projectReady.js" class checkPermissions { #project #userId constructor() { - TPEN.eventDispatcher.on('tpen-project-loaded', (ev) => { + whenProjectReady((ev) => { this.#project = ev.detail this.#userId = getUserFromToken(TPEN.getAuthorization()) }) diff --git a/components/check-permissions/permission-match.js b/components/check-permissions/permission-match.js index cf967c4b..037dc26f 100644 --- a/components/check-permissions/permission-match.js +++ b/components/check-permissions/permission-match.js @@ -26,6 +26,7 @@ import TPEN from '../../api/TPEN.js' import { getUserFromToken } from "../../components/iiif-tools/index.js" +import { whenProjectReady } from "../../utilities/projectReady.js" // TODO use these from a central location, such as a Permission Class. const ENTITIES = [ "PROJECT", @@ -39,7 +40,10 @@ const ENTITIES = [ "*", "ANY" ] -TPEN.eventDispatcher.on("tpen-project-loaded", ev => checkElements(ev.detail)) +// Defer one microtask so any tpen-view/tpen-edit elements added by +// sibling modules during their own evaluation are present in the DOM +// before checkElements scans for them. +queueMicrotask(() => whenProjectReady(ev => checkElements(ev.detail))) /** * Gather all elements with the tpen-view or tpen-edit attributes. diff --git a/components/update-metadata/index.html b/components/update-metadata/index.html index 6dc7455a..304b70de 100644 --- a/components/update-metadata/index.html +++ b/components/update-metadata/index.html @@ -40,9 +40,9 @@