forked from recogito/text-annotator-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'recogito#172-fix-popup-flickering-selection' into stagi…
…ng-testing # Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup/TextAnnotatorPopup.tsx # packages/text-annotator-react/src/hooks/index.ts # packages/text-annotator/src/SelectionHandler.ts
- Loading branch information
Showing
5 changed files
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './useAnnouncePopupNavigation'; | ||
export { useAnnouncePopupNavigation } from './useAnnouncePopupNavigation'; | ||
export { useAnnotationTargetIdling } from './useAnnotationTargetIdling'; |
40 changes: 40 additions & 0 deletions
40
packages/text-annotator-react/src/hooks/useAnnotationTargetIdling.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Origin, useAnnotationStore } from '@annotorious/react'; | ||
import { useEffect, useState } from 'react'; | ||
import { Ignore } from '@annotorious/core'; | ||
|
||
export const useAnnotationTargetIdling = ( | ||
annotationId: string | undefined, | ||
options: { timeout: number } = { timeout: 500 } | ||
) => { | ||
const store = useAnnotationStore(); | ||
|
||
const [isIdling, setIdling] = useState(true); | ||
|
||
useEffect(() => { | ||
if (!annotationId) return; | ||
|
||
let idlingTimeout: ReturnType<typeof setTimeout>; | ||
|
||
const scheduleSetIdling = () => { | ||
setIdling(false); | ||
|
||
clearTimeout(idlingTimeout); | ||
idlingTimeout = setTimeout(() => setIdling(true), options.timeout); | ||
}; | ||
|
||
store.observe( | ||
scheduleSetIdling, | ||
{ | ||
annotations: annotationId, | ||
ignore: Ignore.BODY_ONLY, | ||
origin: Origin.LOCAL | ||
} | ||
); | ||
return () => { | ||
clearTimeout(idlingTimeout); | ||
store.unobserve(scheduleSetIdling); | ||
}; | ||
}, [annotationId]); | ||
|
||
return isIdling; | ||
}; |
This file contains 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 file contains 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