-
Notifications
You must be signed in to change notification settings - Fork 9
Made TextAnnotatorPopup resilient to the underlying DOM mutations
#123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rsimon
merged 28 commits into
recogito:main
from
oleksandr-danylchenko:spatial-tree-positioning
Nov 21, 2024
Merged
Made TextAnnotatorPopup resilient to the underlying DOM mutations
#123
rsimon
merged 28 commits into
recogito:main
from
oleksandr-danylchenko:spatial-tree-positioning
Nov 21, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Aug 9, 2024
# Conflicts: # packages/text-annotator/src/utils/index.ts
# Conflicts: # packages/text-annotator/src/utils/mergeClientRects.ts
# Conflicts: # packages/text-annotator/src/state/spatialTree.ts
# Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup.tsx # packages/text-annotator/src/utils/index.ts
# Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup/TextAnnotatorPopup.tsx
# Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup/TextAnnotatorPopup.tsx # packages/text-annotator/src/utils/index.ts
# Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup/TextAnnotatorPopup.tsx
# Conflicts: # packages/text-annotator-react/src/TextAnnotationPopup/TextAnnotationPopup.tsx
2a54a23 to
2ee2f96
Compare
rsimon
reviewed
Nov 21, 2024
|
Finally got a chance to review & test this, because we ran into a different but connected problem ourselves. This is great, many thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
To position the popup, we used the
range.getBoundingClientRect/getClientRectsmethods, which are performant and correct in cases when the annotatable DOM is stable and static. However, when the DOM elements captured within the range mutate - it collapses and loses its dimensions. That leads to losing the anchoring position for the popup or any other element that depends on that range.Changes Made
As we can't rely on the mutable
rangeinstance, instead we can use the cachedrectspersisted in thespatialTree! They are resilient to the underlying DOM mutations and can be manually recalculated on demand. Also, during the recalculation, the ranges can be automatically revived:text-annotator-js/packages/text-annotator/src/state/spatialTree.ts
Lines 40 to 46 in 7628ac2
Real-life example
I faced that challenge while integrating the annotator alongside the Speechstream library. The latter highlights the text word-by-word and announces it to the users, working as an a11y/convenience tool. However, its highlighting is implemented in a pretty disruptive way, where the announced paragraphs are constantly being mutated!
rangereference is lost, it became collapsed)Because of the mutation, the
rangepersisted by the annotation was constantly getting collapsed, making it impossible to position related elements by it: