@soomo/react-text-annotator 3.0.0-staging.38 → 3.0.0-staging.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{TextAnnotatorPopup.d.ts → TextAnnotatorPopup/TextAnnotatorPopup.d.ts} +3 -2
- package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -0
- package/dist/TextAnnotatorPopup/index.d.ts +2 -0
- package/dist/TextAnnotatorPopup/index.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts +8 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
- package/dist/hooks/useRestoreSelectionCaret.d.ts +13 -0
- package/dist/hooks/useRestoreSelectionCaret.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/react-text-annotator.css +30 -0
- package/dist/react-text-annotator.es.js +8 -4
- package/dist/react-text-annotator.es.js.map +1 -1
- package/dist/react-text-annotator.es11.js +445 -527
- package/dist/react-text-annotator.es11.js.map +1 -1
- package/dist/react-text-annotator.es12.js +60 -483
- package/dist/react-text-annotator.es12.js.map +1 -1
- package/dist/react-text-annotator.es13.js +38 -44
- package/dist/react-text-annotator.es13.js.map +1 -1
- package/dist/react-text-annotator.es14.js +1422 -118
- package/dist/react-text-annotator.es14.js.map +1 -1
- package/dist/react-text-annotator.es16.js +239 -29
- package/dist/react-text-annotator.es16.js.map +1 -1
- package/dist/react-text-annotator.es17.js +568 -897
- package/dist/react-text-annotator.es17.js.map +1 -1
- package/dist/react-text-annotator.es18.js +2 -2
- package/dist/react-text-annotator.es19.js +31 -2
- package/dist/react-text-annotator.es19.js.map +1 -1
- package/dist/react-text-annotator.es2.js +2 -2
- package/dist/react-text-annotator.es20.js +893 -109
- package/dist/react-text-annotator.es20.js.map +1 -1
- package/dist/react-text-annotator.es21.js +2 -309
- package/dist/react-text-annotator.es21.js.map +1 -1
- package/dist/react-text-annotator.es22.js +2 -58
- package/dist/react-text-annotator.es22.js.map +1 -1
- package/dist/react-text-annotator.es23.js +113 -19
- package/dist/react-text-annotator.es23.js.map +1 -1
- package/dist/react-text-annotator.es24.js +290 -130
- package/dist/react-text-annotator.es24.js.map +1 -1
- package/dist/react-text-annotator.es25.js +43 -545
- package/dist/react-text-annotator.es25.js.map +1 -1
- package/dist/react-text-annotator.es26.js +23 -0
- package/dist/react-text-annotator.es26.js.map +1 -0
- package/dist/react-text-annotator.es27.js +130 -0
- package/dist/react-text-annotator.es27.js.map +1 -0
- package/dist/react-text-annotator.es28.js +155 -0
- package/dist/react-text-annotator.es28.js.map +1 -0
- package/dist/react-text-annotator.es29.js +314 -0
- package/dist/react-text-annotator.es29.js.map +1 -0
- package/dist/react-text-annotator.es3.js +2 -2
- package/dist/react-text-annotator.es30.js +152 -0
- package/dist/react-text-annotator.es30.js.map +1 -0
- package/dist/react-text-annotator.es31.js +563 -0
- package/dist/react-text-annotator.es31.js.map +1 -0
- package/dist/react-text-annotator.es4.js +30 -23
- package/dist/react-text-annotator.es4.js.map +1 -1
- package/dist/react-text-annotator.es5.js +36 -78
- package/dist/react-text-annotator.es5.js.map +1 -1
- package/dist/react-text-annotator.es6.js +24 -178
- package/dist/react-text-annotator.es6.js.map +1 -1
- package/dist/react-text-annotator.es7.js +126 -10
- package/dist/react-text-annotator.es7.js.map +1 -1
- package/dist/react-text-annotator.es8.js +182 -0
- package/dist/react-text-annotator.es8.js.map +1 -0
- package/dist/react-text-annotator.es9.js +10 -670
- package/dist/react-text-annotator.es9.js.map +1 -1
- package/package.json +5 -3
- package/dist/TextAnnotatorPopup.d.ts.map +0 -1
- package/dist/react-text-annotator.es10.js +0 -244
- package/dist/react-text-annotator.es10.js.map +0 -1
- package/dist/react-text-annotator.es15.js +0 -5
- package/dist/react-text-annotator.es15.js.map +0 -1
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const { annotatingEnabled, style, filter, userSelectAction, user } = opts;
|
|
10
|
-
const { anno, setAnno } = useContext(AnnotoriousContext);
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import { useSelection } from "@annotorious/react";
|
|
3
|
+
const useRestoreSelectionCaret = (args) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const { floatingOpen } = args;
|
|
6
|
+
const { selected } = useSelection();
|
|
7
|
+
const annotation = (_a = selected[0]) == null ? void 0 : _a.annotation;
|
|
8
|
+
const selectionRangeRef = useRef(null);
|
|
11
9
|
useEffect(() => {
|
|
12
|
-
if (!
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}, [
|
|
18
|
-
useEffect(() =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
if (!floatingOpen || !annotation) return;
|
|
11
|
+
const sel = document.getSelection();
|
|
12
|
+
if (sel) {
|
|
13
|
+
selectionRangeRef.current = sel.getRangeAt(0).cloneRange();
|
|
14
|
+
}
|
|
15
|
+
}, [floatingOpen, annotation]);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (floatingOpen) return;
|
|
18
|
+
const { current: selectionRange } = selectionRangeRef;
|
|
19
|
+
if (!selectionRange) return;
|
|
20
|
+
const { startContainer, startOffset } = selectionRange;
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
const sel = document.getSelection();
|
|
23
|
+
if (sel && sel.isCollapsed && sel.anchorNode === document.body) {
|
|
24
|
+
sel.removeAllRanges();
|
|
25
|
+
sel.setPosition(startContainer, startOffset);
|
|
26
|
+
const startContainerElement = startContainer instanceof HTMLElement ? startContainer : startContainer.parentElement;
|
|
27
|
+
startContainerElement.focus({ preventScroll: true });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}, [floatingOpen]);
|
|
24
31
|
};
|
|
25
32
|
export {
|
|
26
|
-
|
|
33
|
+
useRestoreSelectionCaret
|
|
27
34
|
};
|
|
28
35
|
//# sourceMappingURL=react-text-annotator.es4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-text-annotator.es4.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es4.js","sources":["../src/hooks/useRestoreSelectionCaret.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport { useSelection } from '@annotorious/react';\nimport type { TextAnnotation } from '@recogito/text-annotator';\n\n/**\n * Restores the caret position after the floating element gets closed\n * and the selection is lost and moved to the `body`.\n * The caret is placed at the start of the previous selection range.\n *\n * However, when the floating element is dismissed with intentional\n * caret repositioning via the mouse click or arrow key navigation ->\n * we shouldn't restore its position to the previous selection.\n */\nexport const useRestoreSelectionCaret = (args: { floatingOpen: boolean }) => {\n const { floatingOpen } = args;\n\n const { selected } = useSelection<TextAnnotation>();\n const annotation = selected[0]?.annotation;\n\n const selectionRangeRef = useRef<Range | null>(null);\n\n useEffect(() => {\n if (!floatingOpen || !annotation) return;\n\n const sel = document.getSelection();\n if (sel) {\n selectionRangeRef.current = sel.getRangeAt(0).cloneRange();\n }\n }, [floatingOpen, annotation]);\n\n useEffect(() => {\n if (floatingOpen) return;\n\n const { current: selectionRange } = selectionRangeRef;\n if (!selectionRange) return;\n\n const { startContainer, startOffset } = selectionRange;\n\n setTimeout(() => {\n const sel = document.getSelection();\n if (sel && sel.isCollapsed && sel.anchorNode === document.body) {\n sel.removeAllRanges();\n sel.setPosition(startContainer, startOffset);\n\n const startContainerElement = startContainer instanceof HTMLElement\n ? startContainer\n : startContainer.parentElement;\n startContainerElement.focus({ preventScroll: true });\n }\n });\n }, [floatingOpen]);\n};\n"],"names":[],"mappings":";;AAca,MAAA,2BAA2B,CAAC,SAAoC;;AACrE,QAAA,EAAE,aAAiB,IAAA;AAEnB,QAAA,EAAE,aAAa;AACf,QAAA,cAAa,cAAS,CAAC,MAAV,mBAAa;AAE1B,QAAA,oBAAoB,OAAqB,IAAI;AAEnD,YAAU,MAAM;AACV,QAAA,CAAC,gBAAgB,CAAC,WAAY;AAE5B,UAAA,MAAM,SAAS;AACrB,QAAI,KAAK;AACP,wBAAkB,UAAU,IAAI,WAAW,CAAC,EAAE;IAChD;AAAA,EAAA,GACC,CAAC,cAAc,UAAU,CAAC;AAE7B,YAAU,MAAM;AACd,QAAI,aAAc;AAEZ,UAAA,EAAE,SAAS,eAAmB,IAAA;AACpC,QAAI,CAAC,eAAgB;AAEf,UAAA,EAAE,gBAAgB,YAAgB,IAAA;AAExC,eAAW,MAAM;AACT,YAAA,MAAM,SAAS;AACrB,UAAI,OAAO,IAAI,eAAe,IAAI,eAAe,SAAS,MAAM;AAC9D,YAAI,gBAAgB;AAChB,YAAA,YAAY,gBAAgB,WAAW;AAE3C,cAAM,wBAAwB,0BAA0B,cACpD,iBACA,eAAe;AACnB,8BAAsB,MAAM,EAAE,eAAe,KAAM,CAAA;AAAA,MACrD;AAAA,IAAA,CACD;AAAA,EAAA,GACA,CAAC,YAAY,CAAC;AACnB;"}
|
|
@@ -1,85 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
flip(),
|
|
27
|
-
shift({ mainAxis: false, crossAxis: true, padding: 10 })
|
|
28
|
-
],
|
|
29
|
-
whileElementsMounted: autoUpdate
|
|
30
|
-
});
|
|
31
|
-
const dismiss = useDismiss(context);
|
|
32
|
-
const role = useRole(context, { role: "tooltip" });
|
|
33
|
-
const { getFloatingProps } = useInteractions([dismiss, role]);
|
|
34
|
-
const selectedKey = selected.map((a) => a.annotation.id).join("-");
|
|
1
|
+
import { useCallback, useLayoutEffect, useMemo, useRef, useEffect } from "react";
|
|
2
|
+
import { useAnnotationStore, useSelection, Origin } from "@annotorious/react";
|
|
3
|
+
import { announce as $319e236875307eab$export$a9b970dcc4ae71a9, destroyAnnouncer as $319e236875307eab$export$d8686216b8b81b2f } from "./react-text-annotator.es12.js";
|
|
4
|
+
import { exhaustiveUniqueRandom } from "./react-text-annotator.es13.js";
|
|
5
|
+
const useAnnouncePopupNavigation = (args) => {
|
|
6
|
+
const {
|
|
7
|
+
message = "Press Tab to move to Notes Dialog",
|
|
8
|
+
floatingOpen,
|
|
9
|
+
disabled = false
|
|
10
|
+
} = args;
|
|
11
|
+
const store = useAnnotationStore();
|
|
12
|
+
const { event } = useSelection();
|
|
13
|
+
const uniqueRandom = useCallback(exhaustiveUniqueRandom(1, 1e4), []);
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
if (!message) return;
|
|
16
|
+
$319e236875307eab$export$a9b970dcc4ae71a9("", "polite");
|
|
17
|
+
return () => $319e236875307eab$export$d8686216b8b81b2f();
|
|
18
|
+
}, [message]);
|
|
19
|
+
const announcementSeed = useMemo(() => floatingOpen ? uniqueRandom() : 0, [floatingOpen]);
|
|
20
|
+
const announcePopupNavigation = useCallback(() => {
|
|
21
|
+
const uniqueSpaces = Array.from({ length: announcementSeed }).map(() => " ").join("");
|
|
22
|
+
$319e236875307eab$export$a9b970dcc4ae71a9(`${message} ${uniqueSpaces}`, "polite");
|
|
23
|
+
}, [message, announcementSeed]);
|
|
24
|
+
const idleTimeoutMs = 700;
|
|
25
|
+
const idleTimeoutRef = useRef(null);
|
|
35
26
|
useEffect(() => {
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
getBoundingClientRect: () => denormalizeRectWithOffset(
|
|
44
|
-
r.state.store.getAnnotationBounds(annotation.id),
|
|
45
|
-
r.element.getBoundingClientRect()
|
|
46
|
-
),
|
|
47
|
-
getClientRects: () => {
|
|
48
|
-
const rects = r.state.store.getAnnotationRects(annotation.id);
|
|
49
|
-
const denormalizedRects = rects.map(
|
|
50
|
-
(rect) => denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())
|
|
51
|
-
);
|
|
52
|
-
return toDomRectList(denormalizedRects);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}, [isOpen, annotation == null ? void 0 : annotation.id, r]);
|
|
56
|
-
const getStopEventsPropagationProps = useCallback(
|
|
57
|
-
() => ({ onPointerUp: (event2) => event2.stopPropagation() }),
|
|
58
|
-
[]
|
|
59
|
-
);
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
const config = { attributes: true, childList: true, subtree: true };
|
|
62
|
-
const mutationObserver = new MutationObserver(() => update());
|
|
63
|
-
mutationObserver.observe(document.body, config);
|
|
64
|
-
window.document.addEventListener("scroll", update, true);
|
|
27
|
+
if (disabled || !floatingOpen || !message) return;
|
|
28
|
+
const scheduleIdleAnnouncement = () => {
|
|
29
|
+
clearTimeout(idleTimeoutRef.current);
|
|
30
|
+
idleTimeoutRef.current = setTimeout(announcePopupNavigation, idleTimeoutMs);
|
|
31
|
+
};
|
|
32
|
+
scheduleIdleAnnouncement();
|
|
33
|
+
store.observe(scheduleIdleAnnouncement, { origin: Origin.LOCAL });
|
|
65
34
|
return () => {
|
|
66
|
-
|
|
67
|
-
|
|
35
|
+
clearTimeout(idleTimeoutRef.current);
|
|
36
|
+
store.unobserve(scheduleIdleAnnouncement);
|
|
68
37
|
};
|
|
69
|
-
}, [
|
|
70
|
-
return isOpen && selected.length > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
71
|
-
"div",
|
|
72
|
-
{
|
|
73
|
-
className: "annotation-popup text-annotation-popup not-annotatable",
|
|
74
|
-
ref: refs.setFloating,
|
|
75
|
-
style: floatingStyles,
|
|
76
|
-
...getFloatingProps(),
|
|
77
|
-
...getStopEventsPropagationProps(),
|
|
78
|
-
children: props.popup({ selected })
|
|
79
|
-
}
|
|
80
|
-
) : null;
|
|
38
|
+
}, [floatingOpen, event == null ? void 0 : event.type, message, announcePopupNavigation, store]);
|
|
81
39
|
};
|
|
82
40
|
export {
|
|
83
|
-
|
|
41
|
+
useAnnouncePopupNavigation
|
|
84
42
|
};
|
|
85
43
|
//# sourceMappingURL=react-text-annotator.es5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-text-annotator.es5.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es5.js","sources":["../src/hooks/useAnnouncePopupNavigation.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react';\n\nimport { Origin, useAnnotationStore, useSelection } from '@annotorious/react';\nimport type { TextAnnotation } from '@recogito/text-annotator';\nimport { announce, destroyAnnouncer } from '@react-aria/live-announcer';\nimport { exhaustiveUniqueRandom } from 'unique-random';\n\ninterface AnnouncePopupOpeningArgs {\n message?: string;\n floatingOpen: boolean;\n disabled?: boolean;\n}\n\nexport const useAnnouncePopupNavigation = (args: AnnouncePopupOpeningArgs) => {\n const {\n message = 'Press Tab to move to Notes Dialog',\n floatingOpen,\n disabled = false\n } = args;\n\n const store = useAnnotationStore();\n const { event } = useSelection<TextAnnotation>();\n\n // Generate random numbers that do not repeat until the entire 1-10000 range has appeared\n const uniqueRandom = useCallback(exhaustiveUniqueRandom(1, 10000), []);\n\n /**\n * Initialize the `LiveAnnouncer` class and\n * its `polite` announcements live area\n */\n useLayoutEffect(() => {\n if (!message) return;\n\n announce('', 'polite');\n return () => destroyAnnouncer();\n }, [message]);\n\n /**\n * Screen reader requires messages to always be unique!\n * Otherwise, the hint will be announced once per page.\n */\n const announcementSeed = useMemo(() => floatingOpen ? uniqueRandom() : 0, [floatingOpen]);\n\n const announcePopupNavigation = useCallback(() => {\n /**\n * To imitate the uniqueness of the announced message\n * w/o mutating it - we can append spaces at the end.\n */\n const uniqueSpaces = Array.from({ length: announcementSeed }).map(() => ' ').join('');\n announce(`${message} ${uniqueSpaces}`, 'polite');\n }, [message, announcementSeed]);\n\n const idleTimeoutMs = 700;\n const idleTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n useEffect(() => {\n if (disabled || !floatingOpen || !message) return;\n\n const scheduleIdleAnnouncement = () => {\n clearTimeout(idleTimeoutRef.current);\n idleTimeoutRef.current = setTimeout(announcePopupNavigation, idleTimeoutMs);\n };\n\n scheduleIdleAnnouncement();\n store.observe(scheduleIdleAnnouncement, { origin: Origin.LOCAL });\n\n return () => {\n clearTimeout(idleTimeoutRef.current);\n store.unobserve(scheduleIdleAnnouncement);\n };\n }, [floatingOpen, event?.type, message, announcePopupNavigation, store]);\n};\n"],"names":["announce","destroyAnnouncer"],"mappings":";;;;AAaa,MAAA,6BAA6B,CAAC,SAAmC;AACtE,QAAA;AAAA,IACJ,UAAU;AAAA,IACV;AAAA,IACA,WAAW;AAAA,EACT,IAAA;AAEJ,QAAM,QAAQ;AACR,QAAA,EAAE,UAAU;AAGlB,QAAM,eAAe,YAAY,uBAAuB,GAAG,GAAK,GAAG,CAAA,CAAE;AAMrE,kBAAgB,MAAM;AACpB,QAAI,CAAC,QAAS;AAEdA,8CAAS,IAAI,QAAQ;AACrB,WAAO,MAAMC,0CAAiB;AAAA,EAAA,GAC7B,CAAC,OAAO,CAAC;AAMN,QAAA,mBAAmB,QAAQ,MAAM,eAAe,iBAAiB,GAAG,CAAC,YAAY,CAAC;AAElF,QAAA,0BAA0B,YAAY,MAAM;AAKhD,UAAM,eAAe,MAAM,KAAK,EAAE,QAAQ,iBAAA,CAAkB,EAAE,IAAI,MAAM,GAAG,EAAE,KAAK,EAAE;AACpFD,8CAAS,GAAG,OAAO,IAAI,YAAY,IAAI,QAAQ;AAAA,EAAA,GAC9C,CAAC,SAAS,gBAAgB,CAAC;AAE9B,QAAM,gBAAgB;AAChB,QAAA,iBAAiB,OAA6C,IAAI;AAExE,YAAU,MAAM;AACd,QAAI,YAAY,CAAC,gBAAgB,CAAC,QAAS;AAE3C,UAAM,2BAA2B,MAAM;AACrC,mBAAa,eAAe,OAAO;AACpB,qBAAA,UAAU,WAAW,yBAAyB,aAAa;AAAA,IAAA;AAGnD;AACzB,UAAM,QAAQ,0BAA0B,EAAE,QAAQ,OAAO,OAAO;AAEhE,WAAO,MAAM;AACX,mBAAa,eAAe,OAAO;AACnC,YAAM,UAAU,wBAAwB;AAAA,IAAA;AAAA,EAC1C,GACC,CAAC,cAAc,+BAAO,MAAM,SAAS,yBAAyB,KAAK,CAAC;AACzE;"}
|
|
@@ -1,182 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
25
|
-
return Z(Ne);
|
|
26
|
-
}
|
|
27
|
-
var Oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
28
|
-
const Mt = {
|
|
29
|
-
randomUUID: Oe
|
|
30
|
-
};
|
|
31
|
-
function Ht(t, e, n) {
|
|
32
|
-
if (Mt.randomUUID && !e && !t)
|
|
33
|
-
return Mt.randomUUID();
|
|
34
|
-
t = t || {};
|
|
35
|
-
var o = t.random || (t.rng || Me)();
|
|
36
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Re(o);
|
|
37
|
-
}
|
|
38
|
-
var V = [];
|
|
39
|
-
for (var ht = 0; ht < 256; ++ht)
|
|
40
|
-
V.push((ht + 256).toString(16).slice(1));
|
|
41
|
-
typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
42
|
-
const on = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
43
|
-
let cn = (t = 21) => {
|
|
44
|
-
let e = "", n = crypto.getRandomValues(new Uint8Array(t));
|
|
45
|
-
for (; t--; )
|
|
46
|
-
e += on[n[t] & 63];
|
|
47
|
-
return e;
|
|
48
|
-
};
|
|
49
|
-
const dn = (t) => {
|
|
50
|
-
const e = JSON.stringify(t);
|
|
51
|
-
let n = 0;
|
|
52
|
-
for (let o = 0, r = e.length; o < r; o++) {
|
|
53
|
-
let i = e.charCodeAt(o);
|
|
54
|
-
n = (n << 5) - n + i, n |= 0;
|
|
55
|
-
}
|
|
56
|
-
return `${n}`;
|
|
57
|
-
}, Ft = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, un = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
58
|
-
const { id: o, type: r, purpose: i, value: s, created: a, modified: u, creator: f, ...g } = n;
|
|
59
|
-
return {
|
|
60
|
-
id: o || `temp-${dn(n)}`,
|
|
61
|
-
annotation: e,
|
|
62
|
-
type: r,
|
|
63
|
-
purpose: i,
|
|
64
|
-
value: s,
|
|
65
|
-
creator: Ft(f),
|
|
66
|
-
created: a ? new Date(a) : void 0,
|
|
67
|
-
updated: u ? new Date(u) : void 0,
|
|
68
|
-
...g
|
|
69
|
-
};
|
|
70
|
-
}), hn = (t) => t.map((e) => {
|
|
71
|
-
var n;
|
|
72
|
-
const { annotation: o, created: r, updated: i, ...s } = e, a = {
|
|
73
|
-
...s,
|
|
74
|
-
created: r == null ? void 0 : r.toISOString(),
|
|
75
|
-
modified: i == null ? void 0 : i.toISOString()
|
|
76
|
-
};
|
|
77
|
-
return (n = a.id) != null && n.startsWith("temp-") && delete a.id, a;
|
|
78
|
-
});
|
|
79
|
-
cn();
|
|
80
|
-
const Vn = (t, e) => ({
|
|
81
|
-
parse: (n) => pn(n),
|
|
82
|
-
serialize: (n) => mn(n, t, e)
|
|
83
|
-
}), fn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, gn = (t) => {
|
|
84
|
-
const {
|
|
85
|
-
id: e,
|
|
86
|
-
creator: n,
|
|
87
|
-
created: o,
|
|
88
|
-
modified: r,
|
|
89
|
-
target: i
|
|
90
|
-
} = t, s = Array.isArray(i) ? i : [i], a = {
|
|
91
|
-
creator: Ft(n),
|
|
92
|
-
created: o ? new Date(o) : void 0,
|
|
93
|
-
updated: r ? new Date(r) : void 0,
|
|
94
|
-
annotation: e,
|
|
95
|
-
selector: []
|
|
96
|
-
};
|
|
97
|
-
for (const u of s) {
|
|
98
|
-
const g = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((d, m) => {
|
|
99
|
-
switch (m.type) {
|
|
100
|
-
case "TextQuoteSelector":
|
|
101
|
-
d.quote = m.exact;
|
|
102
|
-
break;
|
|
103
|
-
case "TextPositionSelector":
|
|
104
|
-
d.start = m.start, d.end = m.end;
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
return d;
|
|
108
|
-
}, {});
|
|
109
|
-
if (fn(g))
|
|
110
|
-
a.selector.push({ id: u.id, ...g });
|
|
111
|
-
else {
|
|
112
|
-
const d = [
|
|
113
|
-
g.start ? void 0 : "TextPositionSelector",
|
|
114
|
-
g.quote ? void 0 : "TextQuoteSelector"
|
|
115
|
-
].filter(Boolean);
|
|
116
|
-
return { error: Error(`Missing selector types: ${d.join(" and ")} for annotation: ${t.id}`) };
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return { parsed: a };
|
|
120
|
-
}, pn = (t) => {
|
|
121
|
-
const e = t.id || Ht(), {
|
|
122
|
-
creator: n,
|
|
123
|
-
created: o,
|
|
124
|
-
modified: r,
|
|
125
|
-
body: i,
|
|
126
|
-
...s
|
|
127
|
-
} = t, a = un(i, e), u = gn(t);
|
|
128
|
-
return "error" in u ? { error: u.error } : {
|
|
129
|
-
parsed: {
|
|
130
|
-
...s,
|
|
131
|
-
id: e,
|
|
132
|
-
bodies: a,
|
|
133
|
-
target: u.parsed
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}, mn = (t, e, n) => {
|
|
137
|
-
const { bodies: o, target: r, ...i } = t, {
|
|
138
|
-
selector: s,
|
|
139
|
-
creator: a,
|
|
140
|
-
created: u,
|
|
141
|
-
updated: f,
|
|
142
|
-
...g
|
|
143
|
-
} = r, d = s.map((m) => {
|
|
144
|
-
const { quote: h, start: w, end: y, range: p } = m, { prefix: l, suffix: c } = oe(p, n), b = [{
|
|
145
|
-
type: "TextQuoteSelector",
|
|
146
|
-
exact: h,
|
|
147
|
-
prefix: l,
|
|
148
|
-
suffix: c
|
|
149
|
-
}, {
|
|
150
|
-
type: "TextPositionSelector",
|
|
151
|
-
start: w,
|
|
152
|
-
end: y
|
|
153
|
-
}];
|
|
154
|
-
return {
|
|
155
|
-
...g,
|
|
156
|
-
id: m.id,
|
|
157
|
-
source: e,
|
|
158
|
-
selector: b
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
return {
|
|
162
|
-
...i,
|
|
163
|
-
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
164
|
-
id: t.id,
|
|
165
|
-
type: "Annotation",
|
|
166
|
-
body: hn(t.bodies),
|
|
167
|
-
creator: a,
|
|
168
|
-
created: u == null ? void 0 : u.toISOString(),
|
|
169
|
-
modified: f == null ? void 0 : f.toISOString(),
|
|
170
|
-
target: d
|
|
171
|
-
};
|
|
1
|
+
import { j as jsxRuntimeExports } from "./react-text-annotator.es9.js";
|
|
2
|
+
import { useRef, useContext, useEffect } from "react";
|
|
3
|
+
import { AnnotoriousContext } from "@annotorious/react";
|
|
4
|
+
import { createTextAnnotator } from "@soomo/text-annotator";
|
|
5
|
+
/* empty css */
|
|
6
|
+
const TextAnnotator = (props) => {
|
|
7
|
+
const el = useRef(null);
|
|
8
|
+
const { className, children, ...opts } = props;
|
|
9
|
+
const { annotatingEnabled, style, filter, userSelectAction, user } = opts;
|
|
10
|
+
const { anno, setAnno } = useContext(AnnotoriousContext);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!setAnno) return;
|
|
13
|
+
const adapter = typeof opts.adapter === "function" ? opts.adapter(el.current) : opts.adapter;
|
|
14
|
+
const anno2 = createTextAnnotator(el.current, { ...opts, adapter });
|
|
15
|
+
setAnno(anno2);
|
|
16
|
+
return () => anno2.destroy();
|
|
17
|
+
}, [setAnno]);
|
|
18
|
+
useEffect(() => anno == null ? void 0 : anno.setStyle(style), [anno, style]);
|
|
19
|
+
useEffect(() => anno == null ? void 0 : anno.setFilter(filter), [anno, filter]);
|
|
20
|
+
useEffect(() => anno == null ? void 0 : anno.setUserSelectAction(userSelectAction), [anno, userSelectAction]);
|
|
21
|
+
useEffect(() => anno == null ? void 0 : anno.setUser(user), [anno, user]);
|
|
22
|
+
useEffect(() => anno == null ? void 0 : anno.setAnnotatingEnabled(annotatingEnabled), [anno, annotatingEnabled]);
|
|
23
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: el, className, children });
|
|
172
24
|
};
|
|
173
25
|
export {
|
|
174
|
-
|
|
175
|
-
D as NOT_ANNOTATABLE_SELECTOR,
|
|
176
|
-
Vn as W3CTextFormat,
|
|
177
|
-
oe as getQuoteContext,
|
|
178
|
-
pt as getRangeAnnotatableContents,
|
|
179
|
-
pn as parseW3CTextAnnotation,
|
|
180
|
-
mn as serializeW3CTextAnnotation
|
|
26
|
+
TextAnnotator
|
|
181
27
|
};
|
|
182
28
|
//# sourceMappingURL=react-text-annotator.es6.js.map
|