diff --git a/packages/text-annotator/src/utils/cancelSingleClickEvents.ts b/packages/text-annotator/src/utils/cancelSingleClickEvents.ts index 7d671988..acc4943d 100644 --- a/packages/text-annotator/src/utils/cancelSingleClickEvents.ts +++ b/packages/text-annotator/src/utils/cancelSingleClickEvents.ts @@ -1,4 +1,4 @@ -import { NOT_ANNOTATABLE_SELECTOR } from './splitAnnotatableRanges'; +import { NOT_ANNOTATABLE_SELECTOR } from './isNotAnnotatable'; /** * Calls .preventDefault() on click events in annotable areas, in order diff --git a/packages/text-annotator/src/utils/index.ts b/packages/text-annotator/src/utils/index.ts index 56bdaeda..526885ab 100644 --- a/packages/text-annotator/src/utils/index.ts +++ b/packages/text-annotator/src/utils/index.ts @@ -2,8 +2,9 @@ export * from './cancelSingleClickEvents'; export * from './device'; export * from './programmaticallyFocusable'; export * from './getQuoteContext'; -export * from './isWhitespaceOrEmpty'; +export * from './isNotAnnotatable'; export * from './isRevived'; +export * from './isWhitespaceOrEmpty'; export * from './mergeClientRects'; export * from './rangeToSelector'; export * from './reviveAnnotation'; @@ -14,4 +15,3 @@ export * from './trimRangeToContainer'; export * from './cloneEvents'; export * from './rangeContains'; export * from './normalizeRects'; - diff --git a/packages/text-annotator/src/utils/isNotAnnotatable.ts b/packages/text-annotator/src/utils/isNotAnnotatable.ts new file mode 100644 index 00000000..ece9d7bd --- /dev/null +++ b/packages/text-annotator/src/utils/isNotAnnotatable.ts @@ -0,0 +1,15 @@ +export const NOT_ANNOTATABLE_CLASS = 'not-annotatable'; + +export const NOT_ANNOTATABLE_SELECTOR = `.${NOT_ANNOTATABLE_CLASS}`; + +export const isNotAnnotatable = (node: Node): boolean => { + const closestNotAnnotatable = node instanceof HTMLElement + ? node.closest(NOT_ANNOTATABLE_SELECTOR) + : node.parentElement?.closest(NOT_ANNOTATABLE_SELECTOR); + return Boolean(closestNotAnnotatable); +} + +export const isRangeAnnotatable = (range: Range): boolean => { + const ancestor = range.commonAncestorContainer; + return !isNotAnnotatable(ancestor); +} \ No newline at end of file diff --git a/packages/text-annotator/src/utils/reviveSelector.ts b/packages/text-annotator/src/utils/reviveSelector.ts index b3990053..c0ee7756 100644 --- a/packages/text-annotator/src/utils/reviveSelector.ts +++ b/packages/text-annotator/src/utils/reviveSelector.ts @@ -1,5 +1,5 @@ import type { TextSelector } from '../model'; -import { NOT_ANNOTATABLE_SELECTOR } from './splitAnnotatableRanges'; +import { NOT_ANNOTATABLE_SELECTOR } from './isNotAnnotatable'; /** * Creates a new selector object with the revived DOM range from the given text annotation position diff --git a/packages/text-annotator/src/utils/splitAnnotatableRanges.ts b/packages/text-annotator/src/utils/splitAnnotatableRanges.ts index d66aefd0..4269b9e0 100644 --- a/packages/text-annotator/src/utils/splitAnnotatableRanges.ts +++ b/packages/text-annotator/src/utils/splitAnnotatableRanges.ts @@ -1,18 +1,4 @@ -export const NOT_ANNOTATABLE_CLASS = 'not-annotatable'; - -export const NOT_ANNOTATABLE_SELECTOR = `.${NOT_ANNOTATABLE_CLASS}`; - -export const isNotAnnotatable = (node: Node): boolean => { - const closestNotAnnotatable = node instanceof HTMLElement - ? node.closest(NOT_ANNOTATABLE_SELECTOR) - : node.parentElement?.closest(NOT_ANNOTATABLE_SELECTOR); - return Boolean(closestNotAnnotatable); -} - -export const isRangeAnnotatable = (range: Range): boolean => { - const ancestor = range.commonAncestorContainer; - return !isNotAnnotatable(ancestor); -} +import { isRangeAnnotatable, NOT_ANNOTATABLE_CLASS, NOT_ANNOTATABLE_SELECTOR } from './isNotAnnotatable'; const iterateNotAnnotatableElements = function*(range: Range): Generator { const notAnnotatableIterator = document.createNodeIterator( diff --git a/packages/text-annotator/test/model/w3c/fixtures.ts b/packages/text-annotator/test/model/w3c/fixtures.ts index 7ce75045..142fb168 100644 --- a/packages/text-annotator/test/model/w3c/fixtures.ts +++ b/packages/text-annotator/test/model/w3c/fixtures.ts @@ -28,8 +28,8 @@ export const textAnnotation: W3CTextAnnotation = { }, { type: 'TextPositionSelector', - start: 986, - end: 998 + start: 958, + end: 970 }, ] }