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

#127 Made annotatingEnabled property reactive #128

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

oleksandr-danylchenko
Copy link
Contributor

@oleksandr-danylchenko oleksandr-danylchenko commented Aug 1, 2024

Issue - #127

Changes Made

I made the annotatingEnabled a dynamic property that can receive values from the external sources via the setAnnotatingEnabled (following the "API addition: method to change userSelectAction" example)

@oleksandr-danylchenko oleksandr-danylchenko force-pushed the #127-annotating-enabled-reactive branch from dae32c7 to da40d2c Compare August 28, 2024 16:08
Comment on lines 30 to 38
const setAnnotatingEnabled = (enabled: boolean) => {
currentAnnotatingEnabled = enabled;
onSelectionChange.clear();

if (!enabled) {
currentTarget = undefined;
lastPointerDown = undefined;
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We must clean the onSelectionChange debounced call to prevent it from running on obsolete values from the closure. Otherwise, the selectionchange event will still get processed in the deferred call, even though the currentAnnotatingEnabled became false.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder how crucial that is though. Would annotatingEnabled get called during a selection in practice? The normal use cases I would see is:

  • Setting it once on page init (because the user is getting a page served in "read-only mode")
  • "Locking a page" interactively, by the user clicking a "Lock" button. (In which case there wouldn't be a selection.)

# Conflicts:
#	packages/text-annotator-react/src/TextAnnotator.tsx
#	packages/text-annotator/src/SelectionHandler.ts
# See - sindresorhus/debounce#8. The debounced function has a strict context comparison that breaks when applied in the resize listener
@oleksandr-danylchenko oleksandr-danylchenko marked this pull request as draft August 30, 2024 12:59
@oleksandr-danylchenko oleksandr-danylchenko marked this pull request as ready for review August 30, 2024 14:04
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/TextAnnotator.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
#	packages/text-annotator/src/TextAnnotator.ts
#	packages/text-annotator/src/highlight/baseRenderer.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
#	packages/text-annotator/src/utils/index.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/utils/index.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
#	packages/text-annotator/src/TextAnnotator.ts
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