Skip to content

Autocomplete typeahead for property and type lookups#18

Merged
namedgraph merged 1 commit into
masterfrom
feature/typeahead-ontology-lookups
Jul 14, 2026
Merged

Autocomplete typeahead for property and type lookups#18
namedgraph merged 1 commit into
masterfrom
feature/typeahead-ontology-lookups

Conversation

@namedgraph

Copy link
Copy Markdown
Member

What & why

The annotation overlay exposed ontology terms as two long <select> dropdowns — property (FOAF + DCMI properties) and typeof (classes), 160+ options each. Scanning them to find a term is slow. This replaces them with autocomplete typeaheads.

LinkedDataHub solves this with a typeahead, but its lookups fire debounced SPARQL. RDFa-Editor already prefetches every vocabulary into the SaxonJS document pool (doc() resolves synchronously), so this ports LDH's interaction while filtering a local in-memory list per keystroke — no async, no debounce, no ixsl:schedule-action.

Design

  • New src/typeahead.xsl — a stable wrapper span[@data-field] holds one of two states, swapped via result-document literal result elements (the IXSL-idiomatic DOM build):
    • typing: input.typeahead-input + ul.typeahead-menu
    • committed: button.typeahead-value (label + hidden input carrying the IRI, LDH-style button swap)
  • Options re-render per keystroke from local:vocab-terms (prefix-ranked, capped at 50, matched substring bold-highlighted). Keyboard nav mirrors the slash menu (Arrow/Enter/Escape, first option pre-selected). Options commit on ixsl:onmousedown — before the input's focusout — with option children pointer-events:none so the <li> is always the event target.
  • local:typeahead-value reads the committed hidden IRI, else a free-typed absolute IRI (local:is-absolute-iri), else the untouched button→edit value parked on @data-editing-iri (cleared on the first keystroke — the stale-selection guard). Typing/pasting a full IRI is accepted directly, so the per-field custom-IRI inputs and the urn:rdfa-editor:custom sentinel are dropped for property/type.
  • datatype stays a <select> (short XSD list) with its sentinel + custom-datatype input and the datatype↔lang mutual-exclusion — unchanged.
  • Dead local:vocab-options and local:ontology-label removed from vocab.xsl.

Tests

  • Adapted datatype / features / editor / tables suites to drive the typeahead via a shared tests/browser/typeahead-helper.mjs. The features lint test keeps term-unresolvable coverage by routing the bare term through the retained datatype free-text input.
  • New tests/browser/typeahead.mjs (17 assertions): filter narrows the list, ArrowDown+Enter commits, mouse-select commits, free-IRI entry, non-IRI rejection, edit-prefill renders the committed button, input focuses on re-edit, and stale-selection invalidation.

Verification

  • SEF compiles clean; headless suites all pass (extractor/canonical/lint — untouched).
  • Full browser suite exits 0, zero failures.

🤖 Generated with Claude Code

Replace the long property/type <select> dropdowns in the annotation
overlay with autocomplete typeaheads, porting LinkedDataHub's typeahead
interaction but filtering the already-pooled vocabularies locally and
synchronously per keystroke (no SPARQL, no debounce, no
ixsl:schedule-action).

New src/typeahead.xsl: a stable span[@data-field] wrapper swaps between a
typing state (input + ul.typeahead-menu) and a committed state
(button.typeahead-value + hidden IRI, LDH-style) via result-document
literal result elements. Options are prefix-ranked, capped, and
bold-highlight the match; keyboard nav mirrors the slash menu; options
commit on mousedown (before the input's focusout). local:typeahead-value
reads the committed hidden IRI, else a free-typed absolute IRI, else the
untouched button->edit value parked on @data-editing-iri (cleared on the
first keystroke). Typing a full IRI is accepted directly, so the
per-field custom-IRI inputs and the urn:rdfa-editor:custom sentinel are
dropped for property/type.

The datatype field stays a <select> with its sentinel + custom-datatype
input and the datatype/lang mutual-exclusion, unchanged. Dead
local:vocab-options and local:ontology-label removed from vocab.xsl.

Tests: adapted datatype/features/editor/tables suites to drive the
typeahead via a shared typeahead-helper.mjs; the features lint test keeps
term-unresolvable via the retained datatype free-text input. New
tests/browser/typeahead.mjs covers filter, keyboard/mouse select,
free-IRI entry, non-IRI rejection, edit-prefill button, and
stale-selection invalidation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@namedgraph namedgraph merged commit d979317 into master Jul 14, 2026
2 checks passed
@namedgraph namedgraph deleted the feature/typeahead-ontology-lookups branch July 14, 2026 07:48
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.

1 participant