diff --git a/components/annotorious-annotator/line-parser.js b/components/annotorious-annotator/line-parser.js index a4aa897b..5677fac8 100644 --- a/components/annotorious-annotator/line-parser.js +++ b/components/annotorious-annotator/line-parser.js @@ -567,7 +567,7 @@ class AnnotoriousAnnotator extends HTMLElement { let resolvedCanvas = await this.vault.get(uri, 'canvas') if (!resolvedCanvas && TPEN.activeProject?.manifest) { // Canvas not directly resolvable, try to hydrate from all manifests - await this.vault.prefetchDocuments(TPEN.activeProject.manifest) + await this.vault.prefetchManifests(TPEN.activeProject.manifest) // After manifests are cached, try again resolvedCanvas = await this.vault.get(uri, 'canvas') } diff --git a/components/column-selector/index.js b/components/column-selector/index.js index 505c7dd0..0c031634 100644 --- a/components/column-selector/index.js +++ b/components/column-selector/index.js @@ -70,7 +70,7 @@ export default class ColumnSelector extends HTMLElement { this.#page = await vault.get(pageId, 'annotationpage', true) if (!this.#page && TPEN.activeProject?.manifest) { - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) this.#page = await vault.get(pageId, 'annotationpage', true) } if (!this.#page) return diff --git a/components/continue-working/index.js b/components/continue-working/index.js index 67267d7f..74999c38 100644 --- a/components/continue-working/index.js +++ b/components/continue-working/index.js @@ -181,7 +181,7 @@ class ContinueWorking extends HTMLElement { canvas = await vault.get(canvasId, 'canvas') if (!canvas && project.manifest?.[0]) { // Try to hydrate from all manifests - await vault.prefetchDocuments(project.manifest) + await vault.prefetchManifests(project.manifest) // After manifests are cached, try again canvas = await vault.get(canvasId, 'canvas') } diff --git a/components/default-transcribe/index.js b/components/default-transcribe/index.js index ef462da5..2dee4013 100644 --- a/components/default-transcribe/index.js +++ b/components/default-transcribe/index.js @@ -71,7 +71,7 @@ class TpenTranscriptionElement extends HTMLElement { async #loadPage(annotationPageID) { let page = await vault.get(annotationPageID, 'annotationpage') if (!page && TPEN.activeProject?.manifest) { - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) page = await vault.get(annotationPageID, 'annotationpage') } if (!page) { diff --git a/components/legacy-annotator/plain.js b/components/legacy-annotator/plain.js index 8259790b..0d4a24cc 100644 --- a/components/legacy-annotator/plain.js +++ b/components/legacy-annotator/plain.js @@ -314,7 +314,7 @@ class LegacyAnnotator extends HTMLElement { if(!page) return let resolvedPage = await vault.get(page, 'annotationpage') if (!resolvedPage && TPEN.activeProject?.manifest) { - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) resolvedPage = await vault.get(page, 'annotationpage') } if (!resolvedPage) { @@ -400,7 +400,7 @@ class LegacyAnnotator extends HTMLElement { let resolvedCanvas = await vault.get(canvas, 'canvas') if (!resolvedCanvas && TPEN.activeProject?.manifest) { // Try to hydrate from all manifests - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) // After manifests are cached, try again resolvedCanvas = await vault.get(canvas, 'canvas') } diff --git a/components/line-image/index.js b/components/line-image/index.js index ee8d1521..94832933 100644 --- a/components/line-image/index.js +++ b/components/line-image/index.js @@ -208,7 +208,7 @@ class TpenImageFragment extends HTMLElement { this.cleanup.onDocument('canvas-change', async (event) => { let canvas = await vault.get(event.detail.canvasId, 'canvas') if (!canvas && TPEN.activeProject?.manifest) { - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) canvas = await vault.get(event.detail.canvasId, 'canvas') } if (!canvas) { diff --git a/components/simple-transcription/index.js b/components/simple-transcription/index.js index bf6486f6..7c078578 100644 --- a/components/simple-transcription/index.js +++ b/components/simple-transcription/index.js @@ -483,7 +483,7 @@ export default class SimpleTranscriptionInterface extends HTMLElement { // Use vault.get to fetch the page properly let fetchedPage = await vault.get(pageID, 'annotationpage', true) if (!fetchedPage && TPEN.activeProject?.manifest) { - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) fetchedPage = await vault.get(pageID, 'annotationpage', true) } if (!fetchedPage) { @@ -521,7 +521,7 @@ export default class SimpleTranscriptionInterface extends HTMLElement { let fetchedCanvas = await vault.get(canvasID, 'canvas') if (!fetchedCanvas && TPEN.activeProject?.manifest) { - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) fetchedCanvas = await vault.get(canvasID, 'canvas') } if (!fetchedCanvas) { diff --git a/components/transcription-block/index.js b/components/transcription-block/index.js index 0fb34c9a..19ea2f60 100644 --- a/components/transcription-block/index.js +++ b/components/transcription-block/index.js @@ -96,7 +96,7 @@ export default class TranscriptionBlock extends HTMLElement { if (!this.#page && TPEN.activeProject?.manifest) { // Try to hydrate from all manifests const manifestUrls = TPEN.activeProject?.manifest - await vault.prefetchDocuments(manifestUrls) + await vault.prefetchManifests(manifestUrls) // After manifests are cached, try again this.#page = await vault.get(pageID, 'annotationpage', true) } diff --git a/interfaces/transcription/index.js b/interfaces/transcription/index.js index 0e1c8e49..f39c487d 100644 --- a/interfaces/transcription/index.js +++ b/interfaces/transcription/index.js @@ -628,7 +628,7 @@ export default class TranscriptionInterface extends HTMLElement { let canvas = await vault.get(canvasID, 'canvas') if (!canvas && TPEN.activeProject?.manifest) { // Canvas not directly resolvable, try to hydrate from all manifests - await vault.prefetchDocuments(TPEN.activeProject.manifest) + await vault.prefetchManifests(TPEN.activeProject.manifest) // After manifests are cached, try again canvas = await vault.get(canvasID, 'canvas') } @@ -663,7 +663,7 @@ export default class TranscriptionInterface extends HTMLElement { if (!this.#page && TPEN.activeProject?.manifest) { // Try to hydrate from all manifests const manifestUrls = TPEN.activeProject?.manifest - await vault.prefetchDocuments(manifestUrls) + await vault.prefetchManifests(manifestUrls) // After manifests are cached, try again this.#page = await vault.get(pageID, 'annotationpage', true) } diff --git a/js/vault.js b/js/vault.js index 89809aa6..3b6c9e3c 100644 --- a/js/vault.js +++ b/js/vault.js @@ -211,11 +211,12 @@ class Vault { return Object.values(this.store) } - async prefetchDocuments(items) { + async prefetchDocuments(items, docType) { if (!Array.isArray(items)) items = [items] const errors = [] const promises = items.map(item => { - return this.get(item, item?.['@type'] ?? item?.type) + const type = docType ?? item?.['@type'] ?? item?.type + return this.get(item, type) .catch(err => { errors.push({ item, error: err?.message || String(err) }) return null @@ -227,6 +228,14 @@ class Vault { } return errors } + + async prefetchManifests(items) { + return this.prefetchDocuments(items, 'manifest') + } + + async prefetchCollections(items) { + return this.prefetchDocuments(items, 'collection') + } } const vault = new Vault()