Skip to content

Align with TPEN messaging contract — accept TPEN_CONTEXT, emit NAVIGATE_TO_LINE#14

Merged
thehabes merged 3 commits into
mainfrom
5-2-tools-align
May 8, 2026
Merged

Align with TPEN messaging contract — accept TPEN_CONTEXT, emit NAVIGATE_TO_LINE#14
thehabes merged 3 commits into
mainfrom
5-2-tools-align

Conversation

@thehabes
Copy link
Copy Markdown
Member

@thehabes thehabes commented May 8, 2026

Summary

Align Page-Viewer with the canonical TPEN messaging contract. Replace the alias-soup switch (MANIFEST_CANVAS_*, CANVAS_*, SELECT_ANNOTATION, CURRENT_LINE_INDEX, RETURN_LINE_ID) with the two messages we actually use: TPEN_CONTEXT (boot) and UPDATE_CURRENT_LINE (line-nav delta). Outbound, replace RETURN_LINE_ID with NAVIGATE_TO_LINE. The full contract is defined in CenterForDigitalHumanities/TPEN-interfaces#564.

Changes

  • message-handler.js
    • handleMessage switch reduced to two cases: TPEN_CONTEXT, UPDATE_CURRENT_LINE. Unknown types now silently ignored (was a console.warn).
    • #handleTPENContext calls loadPage(canvas, manifest, annotationPage, currentLineId) — the existing 4-arg signature highlights the matching overlay box internally once annotations render.
    • Race fix (commit ff25235): removed the redundant highlightAnnotation(currentLineId) follow-up. loadPage is async and the sync follow-up hit an empty DOM, so the highlight wasn't reliably applied on boot.
    • #handleLineNavigation simplified to a single param (the new contract carries currentLineId, no alias hunting).
  • ui-manager.js
    • Outbound message renamed RETURN_LINE_IDNAVIGATE_TO_LINE; field lineidlineId. Dropped the redundant lineIndex field — the parent matches by id.

Coordinated cut

Hard cut, all PRs must merge together. Full contract and other PRs:

Test plan

Developer-validated locally on 2026-05-08 against CenterForDigitalHumanities/TPEN-interfaces#564 + CenterForDigitalHumanities/TPEN-services#519 on :4000 / :3012:

  • In TPEN-interfaces (jekyll s), add Page-Viewer to a project's tools. Open /transcribe.
  • Iframe loads → canvas image renders, all overlay boxes draw, the active line is highlighted on first paint without a click. Race fix ff25235 confirmed.
  • Click a line in the parent transcription block → Page-Viewer highlights the matching overlay box (UPDATE_CURRENT_LINE).
  • Click a box in Page-Viewer → parent transcription advances to that line (NAVIGATE_TO_LINE { lineId }).
  • DevTools: exactly one inbound TPEN_CONTEXT per iframe load, one inbound UPDATE_CURRENT_LINE per parent-side line nav, one outbound NAVIGATE_TO_LINE per click. No legacy aliases observed.

Drop the legacy MANIFEST_CANVAS_* and line-nav alias soup
(SELECT_ANNOTATION / NAVIGATE_TO_LINE inbound / CURRENT_LINE_INDEX /
RETURN_LINE_ID) and accept only the canonical pair: TPEN_CONTEXT for
boot (canvas/manifest/annotationPage URIs + currentLineId) and
UPDATE_CURRENT_LINE for line deltas.

Outbound RETURN_LINE_ID renamed to NAVIGATE_TO_LINE — the canonical
tool→parent line-selection name.
loadPage is async and already highlights the active line via its 4th
argument once annotations have rendered (viewer.js:90-95). Calling
highlightAnnotation synchronously right after kicked off a no-op against
an empty DOM and was redundant with loadPage's own behavior. Pass
currentLineId through loadPage and drop the duplicate call.
@thehabes thehabes changed the title Align with TPEN messaging contract — TPEN_CONTEXT + UPDATE_CURRENT_LINE Align with TPEN messaging contract — accept TPEN_CONTEXT, emit NAVIGATE_TO_LINE May 8, 2026
@thehabes thehabes marked this pull request as ready for review May 8, 2026 17:53
@thehabes thehabes requested a review from cubap May 8, 2026 17:53
Comment thread message-handler.js Outdated
this.pageViewer.uiManager?.highlightAnnotation?.(lineRef)
#handleLineNavigation(currentLineId) {
if (!currentLineId) return
this.pageViewer.uiManager?.highlightAnnotation?.(currentLineId)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We control the pageViewer so these optional checks all look a bit odd.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped both ?. chains in 008bd4f. Agreed — uiManager is unconditionally assigned in viewer.js:23 and highlightAnnotation is always a method on UIManager, so the optionals were just hiding regressions.

Comment thread message-handler.js
// Standard navigation message - extract line ID and navigate
this.#handleLineNavigation(event.data)
case "UPDATE_CURRENT_LINE":
this.#handleLineNavigation(event.data.currentLineId)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail silently if event.data is malformed or currentLineId is somehow falsey.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a console.warn for UPDATE_CURRENT_LINE messages missing the currentLineId field in 008bd4f. A null/empty value still flows through (treated as the parent's 'no active line' signal); only true contract violations now surface.

…ATE_CURRENT_LINE

`uiManager` is unconditionally assigned in viewer.js; `highlightAnnotation`
is unconditionally a method on UIManager. The optional chains in this file
were treating internals like untrusted data and would silently swallow a
regression. Drop them.

Also surface a malformed UPDATE_CURRENT_LINE message (no `currentLineId`
field at all) with a console.warn instead of silently no-oping. A null
value still flows through as the parent's "no active line" signal.

Addresses cubap's review on PR #14.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@thehabes thehabes merged commit 0969b8a into main May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants