Skip to content
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

Add recalculation completion listener to the spatialTree #130

Open
oleksandr-danylchenko opened this issue Aug 9, 2024 · 1 comment
Open

Comments

@oleksandr-danylchenko
Copy link
Contributor

oleksandr-danylchenko commented Aug 9, 2024

Issue

In the #123 PR, I introduced annotation popup positioning via reading the cached values from the Spatial Tree.

It works pretty great for the popups or any related elements like notes over the static text. But it starts to become a bit flaky when you introduce dynamic content height updates.

As the popup is referencing a virtual element, the Floating UI doesn't react to the content dimensions updates, and we need to manually call its update method:

useContentContainerResize({ onResize: () => update() });

But there's a catch! The virtual reference element, reading from the spatial tree, might still return obsolete values right upon the resize!

Example

Here's an example of how the positioning works against the spatial tree for the notes in my app:

Screen.Recording.2024-08-09.at.17.37.45.online-video-cutter.com.mp4

Suggestion

The spatialTree module can expose the .on/.off-like handles that will emit events upon the tree recalculation. Then the consumer app will react to them to reposition the required components against the new tree.

It sounds like a much more robust alternative to something like this:

useContentContainerResize({ onResize: () => setTimeout(update, XXX) });

As the timeout cannot be easily predicted and for the large pages with many annotation we might not even fit in the limit.

@oleksandr-danylchenko
Copy link
Contributor Author

I see that the nanoevents lib is already used for the UndoStack in the A9S. And I think that's a nice fit for the spatial tree in terms of practicality.

oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Aug 12, 2024
# Conflicts:
#	package-lock.json
#	packages/text-annotator/package.json
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Aug 30, 2024
# Conflicts:
#	package-lock.json
#	packages/text-annotator/package.json
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Sep 2, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Sep 2, 2024
# Conflicts:
#	package-lock.json
#	packages/text-annotator/package.json
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Sep 10, 2024
# Conflicts:
#	packages/text-annotator/src/state/spatialTree.ts
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Sep 10, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Sep 26, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Sep 26, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Sep 30, 2024
# Conflicts:
#	package-lock.json
#	packages/text-annotator/package.json
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Oct 7, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Oct 7, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Oct 9, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Oct 29, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Oct 29, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Nov 4, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Nov 4, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Nov 11, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Nov 11, 2024
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Dec 16, 2024
# Conflicts:
#	package-lock.json
#	packages/text-annotator/package.json
oleksandr-danylchenko added a commit to oleksandr-danylchenko/text-annotator-js that referenced this issue Dec 16, 2024
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

No branches or pull requests

1 participant