Skip to content

Commit 29987e5

Browse files
committed
Add manifest helpers and include manifestUri
Introduce #getProjectManifestUri and #getCanvasManifestUri to consistently resolve a manifest URI (preferring a canvas' partOf manifest reference and falling back to the project manifest). Add manifest, manifestUri and canvasManifestUri to the TPEN context and use the new helper when posting MANIFEST_CANVAS_ANNOTATIONPAGE_ANNOTATION messages so the correct manifest is reported regardless of how it's referenced.
1 parent e6dac05 commit 29987e5

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

components/simple-transcription/index.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,43 @@ export default class SimpleTranscriptionInterface extends HTMLElement {
822822
?? null
823823
}
824824

825+
#getProjectManifestUri() {
826+
const manifest = TPEN.activeProject?.manifest
827+
return Array.isArray(manifest) ? manifest[0] ?? null : manifest ?? null
828+
}
829+
830+
#getCanvasManifestUri() {
831+
const partOf = this.#canvas?.partOf
832+
833+
if (Array.isArray(partOf) && partOf.length > 0) {
834+
const manifestRef = partOf.find(item => {
835+
const type = (item?.type ?? item?.['@type'] ?? '').toString().toLowerCase()
836+
return type.includes('manifest')
837+
}) ?? partOf[0]
838+
839+
return manifestRef?.id ?? manifestRef?.['@id'] ?? manifestRef ?? this.#getProjectManifestUri()
840+
}
841+
842+
if (partOf) {
843+
return partOf?.id ?? partOf?.['@id'] ?? partOf
844+
}
845+
846+
return this.#getProjectManifestUri()
847+
}
848+
825849
#buildTPENContext() {
826850
const currentPageId = TPEN.screen?.pageInQuery
827851
const projectPage = TPEN.activeProject?.layers
828852
?.flatMap(layer => layer.pages || [])
829853
.find(p => p.id.split('/').pop() === currentPageId)
854+
const manifestUri = this.#getCanvasManifestUri()
830855

831856
return {
832857
type: 'TPEN_CONTEXT',
833858
projectId: TPEN.activeProject?.id ?? TPEN.activeProject?._id ?? TPEN.screen?.projectInQuery ?? null,
859+
manifest: manifestUri,
860+
manifestUri,
861+
canvasManifestUri: manifestUri,
834862
pageId: this.fetchCurrentPageId() ?? this.#page?.id ?? currentPageId ?? null,
835863
canvasId: this.#getCanvasId(),
836864
imageUrl: this.#getCanvasImageUrl(),
@@ -922,7 +950,7 @@ export default class SimpleTranscriptionInterface extends HTMLElement {
922950
iframe.contentWindow?.postMessage(
923951
{
924952
type: "MANIFEST_CANVAS_ANNOTATIONPAGE_ANNOTATION",
925-
manifest: TPEN.activeProject?.manifest?.[0] ?? '',
953+
manifest: this.#getCanvasManifestUri() ?? '',
926954
canvas: this.#getCanvasId(),
927955
annotationPage: this.fetchCurrentPageId() ?? this.#page?.id ?? '',
928956
annotation: TPEN.activeLineIndex >= 0 ? this.#getCurrentLineId() : null,

0 commit comments

Comments
 (0)