Skip to content

Commit 1a3f793

Browse files
committed
Refactoring
1 parent af8b0c5 commit 1a3f793

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

packages/text-annotator/src/utils/cancelSingleClickEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NOT_ANNOTATABLE_SELECTOR } from './splitAnnotatableRanges';
1+
import { NOT_ANNOTATABLE_SELECTOR } from './isNotAnnotatable';
22

33
/**
44
* Calls .preventDefault() on click events in annotable areas, in order
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
export * from './cancelSingleClickEvents';
2+
export * from './cloneEvents';
23
export * from './device';
34
export * from './programmaticallyFocusable';
45
export * from './debounce';
56
export * from './getQuoteContext';
6-
export * from './isWhitespaceOrEmpty';
7+
export * from './isNotAnnotatable';
78
export * from './isRevived';
9+
export * from './isWhitespaceOrEmpty';
810
export * from './mergeClientRects';
911
export * from './rangeToSelector';
1012
export * from './reviveAnnotation';
1113
export * from './reviveSelector';
1214
export * from './reviveTarget';
1315
export * from './splitAnnotatableRanges';
1416
export * from './trimRangeToContainer';
15-
export * from './cloneEvents';
17+
1618

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const NOT_ANNOTATABLE_CLASS = 'not-annotatable';
2+
3+
export const NOT_ANNOTATABLE_SELECTOR = `.${NOT_ANNOTATABLE_CLASS}`;
4+
5+
export const isNotAnnotatable = (node: Node): boolean => {
6+
const closestNotAnnotatable = node instanceof HTMLElement
7+
? node.closest(NOT_ANNOTATABLE_SELECTOR)
8+
: node.parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
9+
return Boolean(closestNotAnnotatable);
10+
}
11+
12+
export const isRangeAnnotatable = (range: Range): boolean => {
13+
const ancestor = range.commonAncestorContainer;
14+
return !isNotAnnotatable(ancestor);
15+
}

packages/text-annotator/src/utils/reviveSelector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TextSelector } from '../model';
2-
import { NOT_ANNOTATABLE_SELECTOR } from './splitAnnotatableRanges';
2+
import { NOT_ANNOTATABLE_SELECTOR } from './isNotAnnotatable';
33

44
/**
55
* Creates a new selector object with the revived DOM range from the given text annotation position

packages/text-annotator/src/utils/splitAnnotatableRanges.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
export const NOT_ANNOTATABLE_CLASS = 'not-annotatable';
2-
3-
export const NOT_ANNOTATABLE_SELECTOR = `.${NOT_ANNOTATABLE_CLASS}`;
4-
5-
export const isNotAnnotatable = (node: Node): boolean => {
6-
const closestNotAnnotatable = node instanceof HTMLElement
7-
? node.closest(NOT_ANNOTATABLE_SELECTOR)
8-
: node.parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
9-
return Boolean(closestNotAnnotatable);
10-
}
11-
12-
export const isRangeAnnotatable = (range: Range): boolean => {
13-
const ancestor = range.commonAncestorContainer;
14-
return !isNotAnnotatable(ancestor);
15-
}
1+
import { isRangeAnnotatable, NOT_ANNOTATABLE_CLASS, NOT_ANNOTATABLE_SELECTOR } from './isNotAnnotatable';
162

173
const iterateNotAnnotatableElements = function*(range: Range): Generator<HTMLElement> {
184
const notAnnotatableIterator = document.createNodeIterator(

0 commit comments

Comments
 (0)