@soomo/react-text-annotator 3.0.0-staging.6 → 3.0.0-staging.60
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/TextAnnotator.d.ts +4 -5
- package/dist/TextAnnotator.d.ts.map +1 -1
- package/dist/TextAnnotatorPlugin.d.ts +1 -2
- package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +14 -0
- 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 +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts +10 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
- package/dist/index.d.ts +7 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/react-text-annotator.css +31 -1
- package/dist/react-text-annotator.es.js +11 -8
- package/dist/react-text-annotator.es.js.map +1 -1
- package/dist/react-text-annotator.es10.js +486 -34
- package/dist/react-text-annotator.es10.js.map +1 -1
- package/dist/react-text-annotator.es11.js +1387 -823
- package/dist/react-text-annotator.es11.js.map +1 -1
- package/dist/react-text-annotator.es13.js +246 -2
- package/dist/react-text-annotator.es13.js.map +1 -1
- package/dist/react-text-annotator.es14.js +576 -105
- package/dist/react-text-annotator.es14.js.map +1 -1
- package/dist/react-text-annotator.es15.js +54 -299
- package/dist/react-text-annotator.es15.js.map +1 -1
- package/dist/react-text-annotator.es16.js +38 -51
- package/dist/react-text-annotator.es16.js.map +1 -1
- package/dist/react-text-annotator.es17.js +2 -20
- package/dist/react-text-annotator.es17.js.map +1 -1
- package/dist/react-text-annotator.es18.js +34 -0
- package/dist/react-text-annotator.es18.js.map +1 -0
- package/dist/react-text-annotator.es19.js +901 -0
- package/dist/react-text-annotator.es19.js.map +1 -0
- package/dist/react-text-annotator.es2.js +2 -2
- package/dist/{react-text-annotator.es12.js → react-text-annotator.es20.js} +1 -1
- package/dist/react-text-annotator.es20.js.map +1 -0
- package/dist/react-text-annotator.es21.js +5 -0
- package/dist/react-text-annotator.es21.js.map +1 -0
- package/dist/react-text-annotator.es22.js +117 -0
- package/dist/react-text-annotator.es22.js.map +1 -0
- package/dist/react-text-annotator.es23.js +312 -0
- package/dist/react-text-annotator.es23.js.map +1 -0
- package/dist/react-text-annotator.es24.js +61 -0
- package/dist/react-text-annotator.es24.js.map +1 -0
- package/dist/react-text-annotator.es25.js +23 -0
- package/dist/react-text-annotator.es25.js.map +1 -0
- package/dist/react-text-annotator.es26.js +130 -0
- package/dist/react-text-annotator.es26.js.map +1 -0
- package/dist/react-text-annotator.es27.js +167 -0
- package/dist/react-text-annotator.es27.js.map +1 -0
- package/dist/react-text-annotator.es28.js +314 -0
- package/dist/react-text-annotator.es28.js.map +1 -0
- package/dist/react-text-annotator.es29.js +152 -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 +566 -0
- package/dist/react-text-annotator.es30.js.map +1 -0
- package/dist/react-text-annotator.es4.js +38 -28
- package/dist/react-text-annotator.es4.js.map +1 -1
- package/dist/react-text-annotator.es5.js +23 -47
- package/dist/react-text-annotator.es5.js.map +1 -1
- package/dist/react-text-annotator.es6.js +133 -10
- package/dist/react-text-annotator.es6.js.map +1 -1
- package/dist/react-text-annotator.es7.js +181 -1
- package/dist/react-text-annotator.es7.js.map +1 -1
- package/dist/react-text-annotator.es8.js +9 -487
- package/dist/react-text-annotator.es8.js.map +1 -1
- package/dist/tei/TEIAnnotator.d.ts +2 -3
- package/package.json +23 -16
- package/dist/TextAnnotatorPopup.d.ts +0 -14
- package/dist/TextAnnotatorPopup.d.ts.map +0 -1
- package/dist/react-text-annotator.es12.js.map +0 -1
- package/dist/react-text-annotator.es9.js +0 -5
- package/dist/react-text-annotator.es9.js.map +0 -1
|
@@ -1,33 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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.es15.js";
|
|
4
|
+
import { exhaustiveUniqueRandom } from "./react-text-annotator.es16.js";
|
|
5
|
+
const useAnnouncePopupNavigation = (args) => {
|
|
6
|
+
const {
|
|
7
|
+
message = "Press Tab to move to Notes Dialog",
|
|
8
|
+
idle = 700,
|
|
9
|
+
floatingOpen,
|
|
10
|
+
disabled = false
|
|
11
|
+
} = args;
|
|
12
|
+
const store = useAnnotationStore();
|
|
13
|
+
const { event } = useSelection();
|
|
14
|
+
const uniqueRandom = useCallback(exhaustiveUniqueRandom(1, 1e4), []);
|
|
15
|
+
useLayoutEffect(() => {
|
|
16
|
+
if (disabled || !message) return;
|
|
17
|
+
$319e236875307eab$export$a9b970dcc4ae71a9("", "polite");
|
|
18
|
+
return () => $319e236875307eab$export$d8686216b8b81b2f();
|
|
19
|
+
}, [disabled, message]);
|
|
20
|
+
const announcementSeed = useMemo(() => floatingOpen ? uniqueRandom() : 0, [floatingOpen]);
|
|
21
|
+
const announcePopupNavigation = useCallback(() => {
|
|
22
|
+
const uniqueSpaces = Array.from({ length: announcementSeed }).map(() => " ").join("");
|
|
23
|
+
$319e236875307eab$export$a9b970dcc4ae71a9(`${message} ${uniqueSpaces}`, "polite");
|
|
24
|
+
}, [message, announcementSeed]);
|
|
25
|
+
const idleTimeoutRef = useRef(null);
|
|
10
26
|
useEffect(() => {
|
|
11
|
-
if (!
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, [
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (!anno)
|
|
25
|
-
return;
|
|
26
|
-
anno.setFilter(props.filter);
|
|
27
|
-
}, [anno, props.filter]);
|
|
28
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: el, className, children });
|
|
27
|
+
if (disabled || !floatingOpen || !message) return;
|
|
28
|
+
const scheduleIdleAnnouncement = () => {
|
|
29
|
+
clearTimeout(idleTimeoutRef.current);
|
|
30
|
+
idleTimeoutRef.current = setTimeout(announcePopupNavigation, idle);
|
|
31
|
+
};
|
|
32
|
+
scheduleIdleAnnouncement();
|
|
33
|
+
store.observe(scheduleIdleAnnouncement, { origin: Origin.LOCAL });
|
|
34
|
+
return () => {
|
|
35
|
+
clearTimeout(idleTimeoutRef.current);
|
|
36
|
+
store.unobserve(scheduleIdleAnnouncement);
|
|
37
|
+
};
|
|
38
|
+
}, [disabled, floatingOpen, event == null ? void 0 : event.type, message, announcePopupNavigation, store]);
|
|
29
39
|
};
|
|
30
40
|
export {
|
|
31
|
-
|
|
41
|
+
useAnnouncePopupNavigation
|
|
32
42
|
};
|
|
33
43
|
//# 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/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 idle?: number;\n floatingOpen: boolean;\n floatingFocused?: boolean;\n disabled?: boolean;\n}\n\nexport const useAnnouncePopupNavigation = (args: AnnouncePopupOpeningArgs) => {\n const {\n message = 'Press Tab to move to Notes Dialog',\n idle = 700,\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 (disabled || !message) return;\n\n announce('', 'polite');\n return () => destroyAnnouncer();\n }, [disabled, 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 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, idle);\n };\n\n scheduleIdleAnnouncement();\n store.observe(scheduleIdleAnnouncement, { origin: Origin.LOCAL });\n\n return () => {\n clearTimeout(idleTimeoutRef.current);\n store.unobserve(scheduleIdleAnnouncement);\n };\n }, [disabled, floatingOpen, event?.type, message, announcePopupNavigation, store]);\n\n};\n"],"names":["announce","destroyAnnouncer"],"mappings":";;;;AAea,MAAA,6BAA6B,CAAC,SAAmC;AACtE,QAAA;AAAA,IACJ,UAAU;AAAA,IACV,OAAO;AAAA,IACP;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;AAChB,QAAA,YAAY,CAAC,QAAS;AAE1BA,8CAAS,IAAI,QAAQ;AACrB,WAAO,MAAMC,0CAAiB;AAAA,EAAA,GAC7B,CAAC,UAAU,OAAO,CAAC;AAMhB,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;AAExB,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,IAAI;AAAA,IAAA;AAG1C;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,UAAU,cAAc,+BAAO,MAAM,SAAS,yBAAyB,KAAK,CAAC;AAEnF;"}
|
|
@@ -1,53 +1,29 @@
|
|
|
1
|
-
import { j as jsxRuntimeExports } from "./react-text-annotator.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { j as jsxRuntimeExports } from "./react-text-annotator.es8.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) => {
|
|
6
7
|
const el = useRef(null);
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const {
|
|
8
|
+
const { className, children, ...opts } = props;
|
|
9
|
+
const { style, filter, user, annotatingEnabled, userSelectAction } = opts;
|
|
10
|
+
const { anno, setAnno } = useContext(AnnotoriousContext);
|
|
10
11
|
useEffect(() => {
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
useEffect(() =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let y = pointerEvent.clientY - top;
|
|
25
|
-
const { id } = selected[0].annotation;
|
|
26
|
-
const { offsetX, offsetY } = pointerEvent;
|
|
27
|
-
const bounds = r.state.store.getAnnotationBounds(id, offsetX, offsetY);
|
|
28
|
-
if (bounds) {
|
|
29
|
-
x = Math.max(x, bounds.x - left);
|
|
30
|
-
x = Math.min(x, bounds.right - left);
|
|
31
|
-
}
|
|
32
|
-
el.current.style.left = `${x}px`;
|
|
33
|
-
el.current.style.top = `${y}px`;
|
|
34
|
-
}, [open, pointerEvent, r == null ? void 0 : r.element]);
|
|
35
|
-
const onPointerUp = (evt) => evt.stopPropagation();
|
|
36
|
-
return open && selected.length > 0 ? createPortal(
|
|
37
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
38
|
-
"div",
|
|
39
|
-
{
|
|
40
|
-
ref: el,
|
|
41
|
-
className: "a9s-popup r6o-popup not-annotatable",
|
|
42
|
-
style: { position: "absolute" },
|
|
43
|
-
onPointerUp,
|
|
44
|
-
children: props.popup({ selected })
|
|
45
|
-
}
|
|
46
|
-
),
|
|
47
|
-
r.element
|
|
48
|
-
) : null;
|
|
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.setFilter(filter), [anno, filter]);
|
|
21
|
+
useEffect(() => anno == null ? void 0 : anno.setUserSelectAction(userSelectAction), [anno, userSelectAction]);
|
|
22
|
+
useEffect(() => anno == null ? void 0 : anno.setUser(user), [anno, user]);
|
|
23
|
+
useEffect(() => anno == null ? void 0 : anno.setAnnotatingEnabled(annotatingEnabled), [anno, annotatingEnabled]);
|
|
24
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: el, className, children });
|
|
49
25
|
};
|
|
50
26
|
export {
|
|
51
|
-
|
|
27
|
+
TextAnnotator
|
|
52
28
|
};
|
|
53
29
|
//# 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/TextAnnotator.tsx"],"sourcesContent":["import { ReactNode, useContext, useEffect, useRef } from 'react';\nimport { AnnotoriousContext, Filter } from '@annotorious/react';\nimport type { FormatAdapter } from '@annotorious/core';\nimport type { HighlightStyleExpression, TextAnnotation, TextAnnotatorOptions } from '@soomo/text-annotator';\nimport { createTextAnnotator } from '@soomo/text-annotator';\n\nimport '@soomo/text-annotator/dist/text-annotator.css';\n\nexport interface TextAnnotatorProps<E extends unknown> extends Omit<TextAnnotatorOptions<TextAnnotation, E>, 'adapter'> {\n\n children?: ReactNode | JSX.Element;\n\n adapter?: FormatAdapter<TextAnnotation, E> | ((container: HTMLElement) => FormatAdapter<TextAnnotation, E>) | null;\n\n filter?: Filter;\n\n style?: HighlightStyleExpression;\n\n className?: string;\n\n}\n\nexport const TextAnnotator = <E extends unknown>(props: TextAnnotatorProps<E>) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n const { className, children, ...opts } = props;\n const { style, filter, user, annotatingEnabled, userSelectAction } = opts;\n\n const { anno, setAnno } = useContext(AnnotoriousContext);\n\n useEffect(() => {\n if (!setAnno) return;\n\n const adapter = typeof opts.adapter === 'function' ? opts.adapter(el.current) : opts.adapter;\n\n const anno = createTextAnnotator(el.current, { ...opts, adapter });\n setAnno(anno);\n\n return () => anno.destroy();\n }, [setAnno]);\n\n useEffect(() => anno?.setStyle(style), [anno, style]);\n\n useEffect(() => anno?.setFilter(filter), [anno, filter]);\n\n useEffect(() => anno?.setFilter(filter), [anno, filter]);\n\n useEffect(() => anno?.setUserSelectAction(userSelectAction), [anno, userSelectAction]);\n\n useEffect(() => anno?.setUser(user), [anno, user]);\n\n useEffect(() => anno?.setAnnotatingEnabled(annotatingEnabled), [anno, annotatingEnabled]);\n\n return (\n <div ref={el} className={className}>\n {children}\n </div>\n );\n\n};\n"],"names":["anno","jsx"],"mappings":";;;;;AAsBa,MAAA,gBAAgB,CAAoB,UAAiC;AAE1E,QAAA,KAAK,OAAuB,IAAI;AAEtC,QAAM,EAAE,WAAW,UAAU,GAAG,SAAS;AACzC,QAAM,EAAE,OAAO,QAAQ,MAAM,mBAAmB,iBAAqB,IAAA;AAErE,QAAM,EAAE,MAAM,QAAQ,IAAI,WAAW,kBAAkB;AAEvD,YAAU,MAAM;AACd,QAAI,CAAC,QAAS;AAER,UAAA,UAAU,OAAO,KAAK,YAAY,aAAa,KAAK,QAAQ,GAAG,OAAO,IAAI,KAAK;AAE/EA,UAAAA,QAAO,oBAAoB,GAAG,SAAS,EAAE,GAAG,MAAM,SAAS;AACjE,YAAQA,KAAI;AAEL,WAAA,MAAMA,MAAK;EAAQ,GACzB,CAAC,OAAO,CAAC;AAEF,YAAA,MAAM,6BAAM,SAAS,QAAQ,CAAC,MAAM,KAAK,CAAC;AAE1C,YAAA,MAAM,6BAAM,UAAU,SAAS,CAAC,MAAM,MAAM,CAAC;AAE7C,YAAA,MAAM,6BAAM,UAAU,SAAS,CAAC,MAAM,MAAM,CAAC;AAE7C,YAAA,MAAM,6BAAM,oBAAoB,mBAAmB,CAAC,MAAM,gBAAgB,CAAC;AAE3E,YAAA,MAAM,6BAAM,QAAQ,OAAO,CAAC,MAAM,IAAI,CAAC;AAEvC,YAAA,MAAM,6BAAM,qBAAqB,oBAAoB,CAAC,MAAM,iBAAiB,CAAC;AAExF,SACGC,kCAAAA,IAAA,OAAA,EAAI,KAAK,IAAI,WACX,SACH,CAAA;AAGJ;"}
|
|
@@ -1,13 +1,136 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
import { j as jsxRuntimeExports } from "./react-text-annotator.es8.js";
|
|
2
|
+
import { useState, useEffect, useCallback } from "react";
|
|
3
|
+
import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager } from "./react-text-annotator.es11.js";
|
|
4
|
+
import { useAnnotator, useSelection } from "@annotorious/react";
|
|
5
|
+
import { denormalizeRectWithOffset, toDomRectList } from "@soomo/text-annotator";
|
|
6
|
+
import { useAnnouncePopupNavigation } from "./react-text-annotator.es4.js";
|
|
7
|
+
/* empty css */
|
|
8
|
+
import { offset, inline, flip, shift } from "./react-text-annotator.es13.js";
|
|
9
|
+
import { autoUpdate } from "./react-text-annotator.es14.js";
|
|
10
|
+
const TextAnnotatorPopup = (props) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const { popup, popupNavigationMessage } = props;
|
|
13
|
+
const r = useAnnotator();
|
|
14
|
+
const { selected, event } = useSelection();
|
|
15
|
+
const annotation = (_a = selected[0]) == null ? void 0 : _a.annotation;
|
|
16
|
+
const [isOpen, setOpen] = useState((selected == null ? void 0 : selected.length) > 0);
|
|
17
|
+
const handleClose = () => r == null ? void 0 : r.cancelSelected();
|
|
18
|
+
const [isFloatingFocused, setFloatingFocused] = useState(false);
|
|
19
|
+
const handleFloatingFocus = () => setFloatingFocused(true);
|
|
20
|
+
const handleFloatingBlur = () => setFloatingFocused(false);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!isOpen) handleFloatingBlur();
|
|
23
|
+
}, [isOpen, handleFloatingBlur]);
|
|
24
|
+
const { refs, floatingStyles, update, context } = useFloating({
|
|
25
|
+
placement: "top",
|
|
26
|
+
open: isOpen,
|
|
27
|
+
onOpenChange: (open, _event, reason) => {
|
|
28
|
+
setOpen(open);
|
|
29
|
+
if (!open) {
|
|
30
|
+
if (reason === "escape-key" || reason === "focus-out") {
|
|
31
|
+
handleClose();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
middleware: [
|
|
36
|
+
offset(10),
|
|
37
|
+
inline(),
|
|
38
|
+
flip(),
|
|
39
|
+
shift({ mainAxis: false, crossAxis: true, padding: 10 })
|
|
40
|
+
],
|
|
41
|
+
whileElementsMounted: autoUpdate
|
|
42
|
+
});
|
|
43
|
+
const dismiss = useDismiss(context);
|
|
44
|
+
const role = useRole(context, { role: "dialog" });
|
|
45
|
+
const { getFloatingProps } = useInteractions([dismiss, role]);
|
|
46
|
+
const selectedKey = selected.map((a) => a.annotation.id).join("-");
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (selected.length > 0 && event) {
|
|
49
|
+
setOpen(event.type === "pointerup" || event.type === "keydown");
|
|
50
|
+
}
|
|
51
|
+
}, [selectedKey, event]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (selected.length === 0 && isOpen) {
|
|
54
|
+
setOpen(false);
|
|
55
|
+
}
|
|
56
|
+
}, [isOpen, selectedKey]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!r) return;
|
|
59
|
+
if (isOpen && (annotation == null ? void 0 : annotation.id)) {
|
|
60
|
+
refs.setPositionReference({
|
|
61
|
+
getBoundingClientRect: () => denormalizeRectWithOffset(
|
|
62
|
+
r.state.store.getAnnotationBounds(annotation.id),
|
|
63
|
+
r.element.getBoundingClientRect()
|
|
64
|
+
),
|
|
65
|
+
getClientRects: () => {
|
|
66
|
+
const rects = r.state.store.getAnnotationRects(annotation.id);
|
|
67
|
+
const denormalizedRects = rects.map(
|
|
68
|
+
(rect) => denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())
|
|
69
|
+
);
|
|
70
|
+
return toDomRectList(denormalizedRects);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
refs.setPositionReference(null);
|
|
75
|
+
}
|
|
76
|
+
}, [isOpen, annotation == null ? void 0 : annotation.id, annotation == null ? void 0 : annotation.target, r]);
|
|
77
|
+
const getStopEventsPropagationProps = useCallback(
|
|
78
|
+
() => ({ onPointerUp: (event2) => event2.stopPropagation() }),
|
|
79
|
+
[]
|
|
80
|
+
);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const config = { attributes: true, childList: true, subtree: true };
|
|
83
|
+
const mutationObserver = new MutationObserver(() => update());
|
|
84
|
+
mutationObserver.observe(document.body, config);
|
|
85
|
+
window.document.addEventListener("scroll", update, true);
|
|
86
|
+
return () => {
|
|
87
|
+
mutationObserver.disconnect();
|
|
88
|
+
window.document.removeEventListener("scroll", update, true);
|
|
89
|
+
};
|
|
90
|
+
}, [update]);
|
|
91
|
+
useAnnouncePopupNavigation({
|
|
92
|
+
disabled: isFloatingFocused,
|
|
93
|
+
floatingOpen: isOpen,
|
|
94
|
+
message: popupNavigationMessage
|
|
95
|
+
});
|
|
96
|
+
return isOpen && selected.length > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingPortal, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
97
|
+
FloatingFocusManager,
|
|
98
|
+
{
|
|
99
|
+
context,
|
|
100
|
+
modal: false,
|
|
101
|
+
closeOnFocusOut: true,
|
|
102
|
+
initialFocus: (
|
|
103
|
+
/**
|
|
104
|
+
* Don't shift focus to the floating element
|
|
105
|
+
* when the selection performed with the keyboard
|
|
106
|
+
*/
|
|
107
|
+
(event == null ? void 0 : event.type) === "keydown" ? -1 : 0
|
|
108
|
+
),
|
|
109
|
+
returnFocus: false,
|
|
110
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
className: "annotation-popup text-annotation-popup not-annotatable",
|
|
114
|
+
ref: refs.setFloating,
|
|
115
|
+
style: floatingStyles,
|
|
116
|
+
onFocus: handleFloatingFocus,
|
|
117
|
+
onBlur: handleFloatingBlur,
|
|
118
|
+
...getFloatingProps(),
|
|
119
|
+
...getStopEventsPropagationProps(),
|
|
120
|
+
children: [
|
|
121
|
+
popup({
|
|
122
|
+
annotation: selected[0].annotation,
|
|
123
|
+
editable: selected[0].editable,
|
|
124
|
+
event
|
|
125
|
+
}),
|
|
126
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "popup-close-message", onClick: handleClose, children: "This dialog closes when you leave it." })
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
) }) : null;
|
|
132
|
+
};
|
|
10
133
|
export {
|
|
11
|
-
|
|
134
|
+
TextAnnotatorPopup
|
|
12
135
|
};
|
|
13
136
|
//# sourceMappingURL=react-text-annotator.es6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-text-annotator.es6.js","sources":["
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es6.js","sources":["../src/TextAnnotatorPopup/TextAnnotatorPopup.tsx"],"sourcesContent":["import React, { FC, PointerEvent, ReactNode, useCallback, useEffect, useState } from 'react';\nimport {\n autoUpdate,\n flip,\n FloatingFocusManager,\n FloatingPortal,\n inline,\n offset,\n shift,\n useDismiss,\n useFloating,\n useInteractions,\n useRole\n} from '@floating-ui/react';\n\nimport { useAnnotator, useSelection } from '@annotorious/react';\nimport {\n denormalizeRectWithOffset,\n toDomRectList,\n type TextAnnotation,\n type TextAnnotator,\n} from '@soomo/text-annotator';\n\nimport { useAnnouncePopupNavigation } from '../hooks';\nimport './TextAnnotatorPopup.css';\n\ninterface TextAnnotationPopupProps {\n\n popupNavigationMessage?: string;\n\n popup(props: TextAnnotationPopupContentProps): ReactNode;\n\n}\n\nexport interface TextAnnotationPopupContentProps {\n\n annotation: TextAnnotation;\n\n editable?: boolean;\n\n event?: PointerEvent;\n\n}\n\nexport const TextAnnotatorPopup: FC<TextAnnotationPopupProps> = (props) => {\n\n const { popup, popupNavigationMessage } = props;\n\n const r = useAnnotator<TextAnnotator>();\n\n const { selected, event } = useSelection<TextAnnotation>();\n const annotation = selected[0]?.annotation;\n\n const [isOpen, setOpen] = useState(selected?.length > 0);\n const handleClose = () => r?.cancelSelected();\n\n const [isFloatingFocused, setFloatingFocused] = useState(false);\n const handleFloatingFocus = () => setFloatingFocused(true);\n const handleFloatingBlur = () => setFloatingFocused(false);\n useEffect(() => {\n if (!isOpen) handleFloatingBlur();\n }, [isOpen, handleFloatingBlur]);\n\n const { refs, floatingStyles, update, context } = useFloating({\n placement: 'top',\n open: isOpen,\n onOpenChange: (open, _event, reason) => {\n setOpen(open);\n\n if (!open) {\n if (reason === 'escape-key' || reason === 'focus-out') {\n handleClose();\n }\n }\n },\n middleware: [\n offset(10),\n inline(),\n flip(),\n shift({ mainAxis: false, crossAxis: true, padding: 10 })\n ],\n whileElementsMounted: autoUpdate\n });\n\n const dismiss = useDismiss(context);\n const role = useRole(context, { role: 'dialog' });\n const { getFloatingProps } = useInteractions([dismiss, role]);\n\n const selectedKey = selected.map(a => a.annotation.id).join('-');\n useEffect(() => {\n // Ignore all selection changes except those accompanied by a user event.\n if (selected.length > 0 && event) {\n setOpen(event.type === 'pointerup' || event.type === 'keydown');\n }\n }, [selectedKey, event]);\n\n useEffect(() => {\n // Close the popup if the selection is cleared\n if (selected.length === 0 && isOpen) {\n setOpen(false);\n }\n }, [isOpen, selectedKey]);\n\n useEffect(() => {\n if (!r) return;\n\n if (isOpen && annotation?.id) {\n refs.setPositionReference({\n getBoundingClientRect: () => denormalizeRectWithOffset(\n r.state.store.getAnnotationBounds(annotation.id),\n r.element.getBoundingClientRect()\n ),\n getClientRects: () => {\n const rects = r.state.store.getAnnotationRects(annotation.id);\n const denormalizedRects = rects.map(\n rect => denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())\n );\n return toDomRectList(denormalizedRects);\n }\n });\n } else {\n // Don't leave the reference depending on the previously selected annotation\n refs.setPositionReference(null);\n }\n }, [isOpen, annotation?.id, annotation?.target, r]);\n\n // Prevent text-annotator from handling the irrelevant events triggered from the popup\n const getStopEventsPropagationProps = useCallback(\n () => ({ onPointerUp: (event: PointerEvent<HTMLDivElement>) => event.stopPropagation() }),\n []\n );\n\n useEffect(() => {\n const config: MutationObserverInit = { attributes: true, childList: true, subtree: true };\n\n const mutationObserver = new MutationObserver(() => update());\n mutationObserver.observe(document.body, config);\n\n window.document.addEventListener('scroll', update, true);\n\n return () => {\n mutationObserver.disconnect();\n window.document.removeEventListener('scroll', update, true);\n };\n }, [update]);\n\n /**\n * Announce the navigation hint only on the keyboard selection,\n * because the focus isn't shifted to the popup automatically then\n */\n useAnnouncePopupNavigation({\n disabled: isFloatingFocused,\n floatingOpen: isOpen,\n message: popupNavigationMessage,\n });\n\n return isOpen && selected.length > 0 ? (\n <FloatingPortal>\n <FloatingFocusManager\n context={context}\n modal={false}\n closeOnFocusOut={true}\n initialFocus={\n /**\n * Don't shift focus to the floating element\n * when the selection performed with the keyboard\n */\n event?.type === 'keydown' ? -1 : 0\n }\n returnFocus={false}\n >\n <div\n className=\"annotation-popup text-annotation-popup not-annotatable\"\n ref={refs.setFloating}\n style={floatingStyles}\n onFocus={handleFloatingFocus}\n onBlur={handleFloatingBlur}\n {...getFloatingProps()}\n {...getStopEventsPropagationProps()}>\n {popup({\n annotation: selected[0].annotation,\n editable: selected[0].editable,\n event\n })}\n\n {/* It lets keyboard/sr users to know that the dialog closes when they focus out of it */}\n <button className=\"popup-close-message\" onClick={handleClose}>\n This dialog closes when you leave it.\n </button>\n </div>\n </FloatingFocusManager>\n </FloatingPortal>\n ) : null;\n\n};\n"],"names":["event","jsx","jsxs"],"mappings":"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"}
|
|
@@ -1,2 +1,182 @@
|
|
|
1
|
-
|
|
1
|
+
const _t = "not-annotatable", X = `.${_t}`, bt = (t) => {
|
|
2
|
+
const e = t.cloneContents();
|
|
3
|
+
return e.querySelectorAll(X).forEach((n) => n.remove()), e;
|
|
4
|
+
}, ee = (t, e, n = 10, o) => {
|
|
5
|
+
const i = e, s = document.createRange();
|
|
6
|
+
s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
7
|
+
const r = bt(s).textContent, c = document.createRange();
|
|
8
|
+
c.setStart(t.endContainer, t.endOffset), i === document.body ? c.setEnd(i, i.childNodes.length) : c.setEndAfter(i);
|
|
9
|
+
const d = bt(c).textContent;
|
|
10
|
+
return {
|
|
11
|
+
prefix: r.substring(r.length - n),
|
|
12
|
+
suffix: d.substring(0, n)
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var U = [];
|
|
16
|
+
for (var dt = 0; dt < 256; ++dt)
|
|
17
|
+
U.push((dt + 256).toString(16).slice(1));
|
|
18
|
+
function Me(t, e = 0) {
|
|
19
|
+
return (U[t[e + 0]] + U[t[e + 1]] + U[t[e + 2]] + U[t[e + 3]] + "-" + U[t[e + 4]] + U[t[e + 5]] + "-" + U[t[e + 6]] + U[t[e + 7]] + "-" + U[t[e + 8]] + U[t[e + 9]] + "-" + U[t[e + 10]] + U[t[e + 11]] + U[t[e + 12]] + U[t[e + 13]] + U[t[e + 14]] + U[t[e + 15]]).toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
var Z, Oe = new Uint8Array(16);
|
|
22
|
+
function Ie() {
|
|
23
|
+
if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z))
|
|
24
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
25
|
+
return Z(Oe);
|
|
26
|
+
}
|
|
27
|
+
var Ne = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
28
|
+
const Ot = {
|
|
29
|
+
randomUUID: Ne
|
|
30
|
+
};
|
|
31
|
+
function Pt(t, e, n) {
|
|
32
|
+
if (Ot.randomUUID && !e && !t)
|
|
33
|
+
return Ot.randomUUID();
|
|
34
|
+
t = t || {};
|
|
35
|
+
var o = t.random || (t.rng || Ie)();
|
|
36
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Me(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, i = e.length; o < i; o++) {
|
|
53
|
+
let s = e.charCodeAt(o);
|
|
54
|
+
n = (n << 5) - n + s, 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: i, purpose: s, value: r, created: c, modified: d, creator: u, ...f } = n;
|
|
59
|
+
return {
|
|
60
|
+
id: o || `temp-${dn(n)}`,
|
|
61
|
+
annotation: e,
|
|
62
|
+
type: i,
|
|
63
|
+
purpose: s,
|
|
64
|
+
value: r,
|
|
65
|
+
creator: Ft(u),
|
|
66
|
+
created: c ? new Date(c) : void 0,
|
|
67
|
+
updated: d ? new Date(d) : void 0,
|
|
68
|
+
...f
|
|
69
|
+
};
|
|
70
|
+
}), hn = (t) => t.map((e) => {
|
|
71
|
+
var n;
|
|
72
|
+
const { annotation: o, created: i, updated: s, ...r } = e, c = {
|
|
73
|
+
...r,
|
|
74
|
+
created: i == null ? void 0 : i.toISOString(),
|
|
75
|
+
modified: s == null ? void 0 : s.toISOString()
|
|
76
|
+
};
|
|
77
|
+
return (n = c.id) != null && n.startsWith("temp-") && delete c.id, c;
|
|
78
|
+
});
|
|
79
|
+
cn();
|
|
80
|
+
const In = (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: i,
|
|
89
|
+
target: s
|
|
90
|
+
} = t, r = Array.isArray(s) ? s : [s], c = {
|
|
91
|
+
creator: Ft(n),
|
|
92
|
+
created: o ? new Date(o) : void 0,
|
|
93
|
+
updated: i ? new Date(i) : void 0,
|
|
94
|
+
annotation: e,
|
|
95
|
+
selector: []
|
|
96
|
+
};
|
|
97
|
+
for (const d of r) {
|
|
98
|
+
const f = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((h, y) => {
|
|
99
|
+
switch (y.type) {
|
|
100
|
+
case "TextQuoteSelector":
|
|
101
|
+
h.quote = y.exact;
|
|
102
|
+
break;
|
|
103
|
+
case "TextPositionSelector":
|
|
104
|
+
h.start = y.start, h.end = y.end;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
return h;
|
|
108
|
+
}, {});
|
|
109
|
+
if (fn(f))
|
|
110
|
+
c.selector.push({ id: d.id, ...f });
|
|
111
|
+
else {
|
|
112
|
+
const h = [
|
|
113
|
+
f.start ? void 0 : "TextPositionSelector",
|
|
114
|
+
f.quote ? void 0 : "TextQuoteSelector"
|
|
115
|
+
].filter(Boolean);
|
|
116
|
+
return { error: Error(`Missing selector types: ${h.join(" and ")} for annotation: ${t.id}`) };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { parsed: c };
|
|
120
|
+
}, pn = (t) => {
|
|
121
|
+
const e = t.id || Pt(), {
|
|
122
|
+
creator: n,
|
|
123
|
+
created: o,
|
|
124
|
+
modified: i,
|
|
125
|
+
body: s,
|
|
126
|
+
...r
|
|
127
|
+
} = t, c = un(s, e), d = gn(t);
|
|
128
|
+
return "error" in d ? { error: d.error } : {
|
|
129
|
+
parsed: {
|
|
130
|
+
...r,
|
|
131
|
+
id: e,
|
|
132
|
+
bodies: c,
|
|
133
|
+
target: d.parsed
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}, mn = (t, e, n) => {
|
|
137
|
+
const { bodies: o, target: i, ...s } = t, {
|
|
138
|
+
selector: r,
|
|
139
|
+
creator: c,
|
|
140
|
+
created: d,
|
|
141
|
+
updated: u,
|
|
142
|
+
...f
|
|
143
|
+
} = i, h = r.map((y) => {
|
|
144
|
+
const { quote: g, start: x, end: v, range: p } = y, { prefix: l, suffix: a } = ee(p, n), m = [{
|
|
145
|
+
type: "TextQuoteSelector",
|
|
146
|
+
exact: g,
|
|
147
|
+
prefix: l,
|
|
148
|
+
suffix: a
|
|
149
|
+
}, {
|
|
150
|
+
type: "TextPositionSelector",
|
|
151
|
+
start: x,
|
|
152
|
+
end: v
|
|
153
|
+
}];
|
|
154
|
+
return {
|
|
155
|
+
...f,
|
|
156
|
+
id: y.id,
|
|
157
|
+
source: e,
|
|
158
|
+
selector: m
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
...s,
|
|
163
|
+
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
164
|
+
id: t.id,
|
|
165
|
+
type: "Annotation",
|
|
166
|
+
body: hn(t.bodies),
|
|
167
|
+
creator: c,
|
|
168
|
+
created: d == null ? void 0 : d.toISOString(),
|
|
169
|
+
modified: u == null ? void 0 : u.toISOString(),
|
|
170
|
+
target: h
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
export {
|
|
174
|
+
_t as NOT_ANNOTATABLE_CLASS,
|
|
175
|
+
X as NOT_ANNOTATABLE_SELECTOR,
|
|
176
|
+
In as W3CTextFormat,
|
|
177
|
+
ee as getQuoteContext,
|
|
178
|
+
bt as getRangeAnnotatableContents,
|
|
179
|
+
pn as parseW3CTextAnnotation,
|
|
180
|
+
mn as serializeW3CTextAnnotation
|
|
181
|
+
};
|
|
2
182
|
//# sourceMappingURL=react-text-annotator.es7.js.map
|