@soomo/react-text-annotator 3.1.0-staging.13 → 3.1.0-staging.15

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.
Files changed (68) hide show
  1. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +1 -11
  2. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -1
  3. package/dist/hooks/index.d.ts +2 -1
  4. package/dist/hooks/index.d.ts.map +1 -1
  5. package/dist/hooks/useAnnotationTargetIdling.d.ts +4 -0
  6. package/dist/hooks/useAnnotationTargetIdling.d.ts.map +1 -0
  7. package/dist/react-text-annotator.es.js +5 -4
  8. package/dist/react-text-annotator.es.js.map +1 -1
  9. package/dist/react-text-annotator.es11.js +483 -78
  10. package/dist/react-text-annotator.es11.js.map +1 -1
  11. package/dist/react-text-annotator.es12.js +77 -40
  12. package/dist/react-text-annotator.es12.js.map +1 -1
  13. package/dist/react-text-annotator.es13.js +45 -9
  14. package/dist/react-text-annotator.es13.js.map +1 -1
  15. package/dist/react-text-annotator.es14.js +45 -10
  16. package/dist/react-text-annotator.es14.js.map +1 -1
  17. package/dist/react-text-annotator.es15.js +12 -0
  18. package/dist/react-text-annotator.es15.js.map +1 -0
  19. package/dist/react-text-annotator.es17.js +215 -554
  20. package/dist/react-text-annotator.es17.js.map +1 -1
  21. package/dist/react-text-annotator.es18.js +585 -2
  22. package/dist/react-text-annotator.es18.js.map +1 -1
  23. package/dist/react-text-annotator.es19.js +2 -31
  24. package/dist/react-text-annotator.es19.js.map +1 -1
  25. package/dist/react-text-annotator.es2.js +2 -2
  26. package/dist/react-text-annotator.es20.js +20 -887
  27. package/dist/react-text-annotator.es20.js.map +1 -1
  28. package/dist/react-text-annotator.es21.js +893 -109
  29. package/dist/react-text-annotator.es21.js.map +1 -1
  30. package/dist/react-text-annotator.es22.js +2 -309
  31. package/dist/react-text-annotator.es22.js.map +1 -1
  32. package/dist/react-text-annotator.es23.js +2 -58
  33. package/dist/react-text-annotator.es23.js.map +1 -1
  34. package/dist/react-text-annotator.es24.js +113 -19
  35. package/dist/react-text-annotator.es24.js.map +1 -1
  36. package/dist/react-text-annotator.es25.js +309 -2
  37. package/dist/react-text-annotator.es25.js.map +1 -1
  38. package/dist/react-text-annotator.es26.js +58 -2
  39. package/dist/react-text-annotator.es26.js.map +1 -1
  40. package/dist/react-text-annotator.es27.js +17 -124
  41. package/dist/react-text-annotator.es27.js.map +1 -1
  42. package/dist/react-text-annotator.es28.js +107 -144
  43. package/dist/react-text-annotator.es28.js.map +1 -1
  44. package/dist/react-text-annotator.es29.js +156 -303
  45. package/dist/react-text-annotator.es29.js.map +1 -1
  46. package/dist/react-text-annotator.es3.js +2 -2
  47. package/dist/react-text-annotator.es30.js +308 -146
  48. package/dist/react-text-annotator.es30.js.map +1 -1
  49. package/dist/react-text-annotator.es31.js +130 -544
  50. package/dist/react-text-annotator.es31.js.map +1 -1
  51. package/dist/react-text-annotator.es32.js +566 -0
  52. package/dist/react-text-annotator.es32.js.map +1 -0
  53. package/dist/react-text-annotator.es4.js +2 -2
  54. package/dist/react-text-annotator.es5.js +28 -24
  55. package/dist/react-text-annotator.es5.js.map +1 -1
  56. package/dist/react-text-annotator.es6.js +23 -124
  57. package/dist/react-text-annotator.es6.js.map +1 -1
  58. package/dist/react-text-annotator.es7.js +121 -538
  59. package/dist/react-text-annotator.es7.js.map +1 -1
  60. package/dist/react-text-annotator.es8.js +545 -10
  61. package/dist/react-text-annotator.es8.js.map +1 -1
  62. package/dist/react-text-annotator.es9.js +13 -0
  63. package/dist/react-text-annotator.es9.js.map +1 -0
  64. package/package.json +11 -11
  65. package/dist/react-text-annotator.es10.js +0 -490
  66. package/dist/react-text-annotator.es10.js.map +0 -1
  67. package/dist/react-text-annotator.es16.js +0 -249
  68. package/dist/react-text-annotator.es16.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useLayoutEffect, useMemo, useRef, useEffect } from "react";
2
2
  import { useAnnotationStore, useSelection, Origin } from "@annotorious/react";
3
- import { announce as $319e236875307eab$export$a9b970dcc4ae71a9, destroyAnnouncer as $319e236875307eab$export$d8686216b8b81b2f } from "./react-text-annotator.es11.js";
4
- import { exhaustiveUniqueRandom } from "./react-text-annotator.es12.js";
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
5
  const useAnnouncePopupNavigation = (args) => {
6
6
  const {
7
7
  message = "Press Tab to move to Notes Dialog",
@@ -1,29 +1,33 @@
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) => {
7
- const el = useRef(null);
8
- const { className, children, ...opts } = props;
9
- const { style, filter, user, annotatingEnabled, userSelectAction } = opts;
10
- const { anno, setAnno } = useContext(AnnotoriousContext);
1
+ import { useAnnotationStore, Origin } from "@annotorious/react";
2
+ import { useState, useEffect } from "react";
3
+ import { Ignore } from "@annotorious/core";
4
+ const useAnnotationTargetIdling = (annotationId, options = { timeout: 500 }) => {
5
+ const store = useAnnotationStore();
6
+ const [isIdling, setIdling] = useState(true);
11
7
  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.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 });
8
+ if (!annotationId) return;
9
+ let idlingTimeout;
10
+ const scheduleSetIdling = () => {
11
+ setIdling(false);
12
+ clearTimeout(idlingTimeout);
13
+ idlingTimeout = setTimeout(() => setIdling(true), options.timeout);
14
+ };
15
+ store.observe(
16
+ scheduleSetIdling,
17
+ {
18
+ annotations: annotationId,
19
+ ignore: Ignore.BODY_ONLY,
20
+ origin: Origin.LOCAL
21
+ }
22
+ );
23
+ return () => {
24
+ clearTimeout(idlingTimeout);
25
+ store.unobserve(scheduleSetIdling);
26
+ };
27
+ }, [annotationId]);
28
+ return isIdling;
25
29
  };
26
30
  export {
27
- TextAnnotator
31
+ useAnnotationTargetIdling
28
32
  };
29
33
  //# sourceMappingURL=react-text-annotator.es5.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"react-text-annotator.es5.js","sources":["../src/hooks/useAnnotationTargetIdling.ts"],"sourcesContent":["import { Origin, useAnnotationStore } from '@annotorious/react';\nimport { useEffect, useState } from 'react';\nimport { Ignore } from '@annotorious/core';\n\nexport const useAnnotationTargetIdling = (\n annotationId: string | undefined,\n options: { timeout: number } = { timeout: 500 }\n) => {\n const store = useAnnotationStore();\n\n const [isIdling, setIdling] = useState(true);\n\n useEffect(() => {\n if (!annotationId) return;\n\n let idlingTimeout: ReturnType<typeof setTimeout>;\n\n const scheduleSetIdling = () => {\n setIdling(false);\n\n clearTimeout(idlingTimeout);\n idlingTimeout = setTimeout(() => setIdling(true), options.timeout);\n };\n\n store.observe(\n scheduleSetIdling,\n {\n annotations: annotationId,\n ignore: Ignore.BODY_ONLY,\n origin: Origin.LOCAL\n }\n );\n return () => {\n clearTimeout(idlingTimeout);\n store.unobserve(scheduleSetIdling);\n };\n }, [annotationId]);\n\n return isIdling;\n};\n"],"names":[],"mappings":";;;AAIO,MAAM,4BAA4B,CACvC,cACA,UAA+B,EAAE,SAAS,UACvC;AACH,QAAM,QAAQ;AAEd,QAAM,CAAC,UAAU,SAAS,IAAI,SAAS,IAAI;AAE3C,YAAU,MAAM;AACd,QAAI,CAAC,aAAc;AAEf,QAAA;AAEJ,UAAM,oBAAoB,MAAM;AAC9B,gBAAU,KAAK;AAEf,mBAAa,aAAa;AAC1B,sBAAgB,WAAW,MAAM,UAAU,IAAI,GAAG,QAAQ,OAAO;AAAA,IAAA;AAG7D,UAAA;AAAA,MACJ;AAAA,MACA;AAAA,QACE,aAAa;AAAA,QACb,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,MACjB;AAAA,IAAA;AAEF,WAAO,MAAM;AACX,mBAAa,aAAa;AAC1B,YAAM,UAAU,iBAAiB;AAAA,IAAA;AAAA,EACnC,GACC,CAAC,YAAY,CAAC;AAEV,SAAA;AACT;"}
@@ -1,130 +1,29 @@
1
- import { j as jsxRuntimeExports } from "./react-text-annotator.es8.js";
2
- import { useState, useCallback, useEffect, useMemo } from "react";
3
- import { isMobile } from "./react-text-annotator.es13.js";
4
- import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager } from "./react-text-annotator.es14.js";
5
- import { useAnnotator, useSelection } from "@annotorious/react";
6
- import { isRevived, denormalizeRectWithOffset, toDomRectList } from "@soomo/text-annotator";
7
- import { useAnnouncePopupNavigation } from "./react-text-annotator.es4.js";
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";
8
5
  /* empty css */
9
- import { offset, inline, flip, shift } from "./react-text-annotator.es16.js";
10
- import { autoUpdate } from "./react-text-annotator.es17.js";
11
- const TextAnnotatorPopup = (props) => {
12
- var _a;
13
- const { popup, ariaNavigationMessage } = props;
14
- const r = useAnnotator();
15
- const { selected, event } = useSelection();
16
- const annotation = (_a = selected[0]) == null ? void 0 : _a.annotation;
17
- const [isOpen, setOpen] = useState((selected == null ? void 0 : selected.length) > 0);
18
- const handleClose = () => r == null ? void 0 : r.cancelSelected();
19
- const [isFocused, setFocused] = useState(false);
20
- const handleFocus = useCallback(() => setFocused(true), []);
21
- const handleBlur = useCallback(() => setFocused(false), []);
6
+ const TextAnnotator = (props) => {
7
+ const el = useRef(null);
8
+ const { className, children, ...opts } = props;
9
+ const { style, filter, user, annotatingEnabled, userSelectAction } = opts;
10
+ const { anno, setAnno } = useContext(AnnotoriousContext);
22
11
  useEffect(() => {
23
- if (!isOpen) handleBlur();
24
- }, [isOpen, handleBlur]);
25
- const { refs, floatingStyles, update, context } = useFloating({
26
- placement: isMobile() ? "bottom" : "top",
27
- open: isOpen,
28
- onOpenChange: (open, _event, reason) => {
29
- if (!open && (reason === "escape-key" || reason === "focus-out")) {
30
- setOpen(open);
31
- handleClose();
32
- }
33
- },
34
- middleware: [
35
- offset(10),
36
- inline(),
37
- flip(),
38
- shift({ mainAxis: false, crossAxis: true, padding: 10 })
39
- ],
40
- whileElementsMounted: autoUpdate
41
- });
42
- const dismiss = useDismiss(context);
43
- const role = useRole(context, { role: "dialog" });
44
- const { getFloatingProps } = useInteractions([dismiss, role]);
45
- useEffect(() => {
46
- const annotationSelector = annotation == null ? void 0 : annotation.target.selector;
47
- if (!annotationSelector) return;
48
- setOpen(isRevived(annotationSelector));
49
- }, [annotation]);
50
- useEffect(() => {
51
- if (!r) return;
52
- if (isOpen && (annotation == null ? void 0 : annotation.id)) {
53
- refs.setPositionReference({
54
- getBoundingClientRect: () => {
55
- const bounds = r.state.store.getAnnotationBounds(annotation.id);
56
- return bounds ? denormalizeRectWithOffset(bounds, r.element.getBoundingClientRect()) : new DOMRect();
57
- },
58
- getClientRects: () => {
59
- const rects = r.state.store.getAnnotationRects(annotation.id);
60
- const denormalizedRects = rects.map(
61
- (rect) => denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())
62
- );
63
- return toDomRectList(denormalizedRects);
64
- }
65
- });
66
- } else {
67
- refs.setPositionReference(null);
68
- }
69
- }, [isOpen, annotation == null ? void 0 : annotation.id, annotation == null ? void 0 : annotation.target, r]);
70
- useEffect(() => {
71
- const config = { attributes: true, childList: true, subtree: true };
72
- const mutationObserver = new MutationObserver(() => update());
73
- mutationObserver.observe(document.body, config);
74
- window.document.addEventListener("scroll", update, true);
75
- return () => {
76
- mutationObserver.disconnect();
77
- window.document.removeEventListener("scroll", update, true);
78
- };
79
- }, [update]);
80
- const initialFocus = useMemo(() => {
81
- return (event == null ? void 0 : event.type) === "keyup" || (event == null ? void 0 : event.type) === "contextmenu" || isMobile() ? -1 : 0;
82
- }, [event]);
83
- useAnnouncePopupNavigation({
84
- disabled: isFocused,
85
- floatingOpen: isOpen,
86
- message: ariaNavigationMessage
87
- });
88
- return isOpen && annotation ? /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingPortal, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
89
- FloatingFocusManager,
90
- {
91
- context,
92
- modal: false,
93
- closeOnFocusOut: true,
94
- returnFocus: false,
95
- initialFocus,
96
- children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
97
- "div",
98
- {
99
- className: "a9s-popup r6o-popup annotation-popup r6o-text-popup not-annotatable",
100
- ref: refs.setFloating,
101
- style: floatingStyles,
102
- ...getFloatingProps({
103
- onFocus: handleFocus,
104
- onBlur: handleBlur,
105
- ...getStopEventsPropagationProps()
106
- }),
107
- children: [
108
- popup({
109
- annotation: selected[0].annotation,
110
- editable: selected[0].editable,
111
- event
112
- }),
113
- /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "r6o-popup-sr-only", "aria-live": "assertive", onClick: handleClose, children: props.ariaCloseWarning || "Click or leave this dialog to close it." })
114
- ]
115
- }
116
- )
117
- }
118
- ) }) : 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 });
119
25
  };
120
- const getStopEventsPropagationProps = () => ({
121
- onPointerUp: (event) => event.stopPropagation(),
122
- onPointerDown: (event) => event.stopPropagation(),
123
- onMouseDown: (event) => event.stopPropagation(),
124
- onMouseUp: (event) => event.stopPropagation()
125
- });
126
26
  export {
127
- TextAnnotatorPopup,
128
- getStopEventsPropagationProps
27
+ TextAnnotator
129
28
  };
130
29
  //# sourceMappingURL=react-text-annotator.es6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-text-annotator.es6.js","sources":["../src/TextAnnotatorPopup/TextAnnotatorPopup.tsx"],"sourcesContent":["import { FC, PointerEvent, MouseEvent, ReactNode, useCallback, useEffect, useMemo, useState } from 'react';\nimport { isMobile } from './isMobile';\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 isRevived,\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 ariaNavigationMessage?: string;\n\n ariaCloseWarning?: 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, ariaNavigationMessage } = props;\n\n const r = useAnnotator<TextAnnotator>();\n\n const { selected, event } = useSelection<TextAnnotation>();\n\n const annotation = selected[0]?.annotation;\n\n const [isOpen, setOpen] = useState(selected?.length > 0);\n const handleClose = () => r?.cancelSelected();\n\n const [isFocused, setFocused] = useState(false);\n const handleFocus = useCallback(() => setFocused(true), []);\n const handleBlur = useCallback(() => setFocused(false), []);\n useEffect(() => {\n if (!isOpen) handleBlur();\n }, [isOpen, handleBlur]);\n\n const { refs, floatingStyles, update, context } = useFloating({\n placement: isMobile() ? 'bottom' : 'top',\n open: isOpen,\n onOpenChange: (open, _event, reason) => {\n if (!open && (reason === 'escape-key' || reason === 'focus-out')) {\n setOpen(open);\n handleClose();\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\n const role = useRole(context, { role: 'dialog' });\n\n const { getFloatingProps } = useInteractions([dismiss, role]);\n\n useEffect(() => {\n const annotationSelector = annotation?.target.selector;\n if (!annotationSelector) return;\n\n setOpen(isRevived(annotationSelector));\n }, [annotation]);\n\n useEffect(() => {\n if (!r) return;\n\n if (isOpen && annotation?.id) {\n refs.setPositionReference({\n getBoundingClientRect: () => {\n const bounds = r.state.store.getAnnotationBounds(annotation.id);\n return bounds\n ? denormalizeRectWithOffset(bounds, r.element.getBoundingClientRect())\n : new DOMRect();\n },\n getClientRects: () => {\n const rects = r.state.store.getAnnotationRects(annotation.id);\n const denormalizedRects = rects.map((rect) =>\n denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())\n );\n return toDomRectList(denormalizedRects);\n }\n });\n } else {\n refs.setPositionReference(null);\n }\n }, [isOpen, annotation?.id, annotation?.target, r]);\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 // Don't shift focus to the floating element if selected via keyboard or on mobile.\n const initialFocus = useMemo(() => {\n return (event?.type === 'keyup' || event?.type === 'contextmenu' || isMobile()) ? -1 : 0;\n }, [event]);\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: isFocused,\n floatingOpen: isOpen,\n message: ariaNavigationMessage,\n });\n\n return isOpen && annotation ? (\n <FloatingPortal>\n <FloatingFocusManager\n context={context}\n modal={false}\n closeOnFocusOut={true}\n returnFocus={false}\n initialFocus={initialFocus}>\n <div\n className=\"a9s-popup r6o-popup annotation-popup r6o-text-popup not-annotatable\"\n ref={refs.setFloating}\n style={floatingStyles}\n {...getFloatingProps({\n onFocus: handleFocus,\n onBlur: handleBlur,\n ...getStopEventsPropagationProps()\n })}>\n {popup({\n annotation: selected[0].annotation,\n editable: selected[0].editable,\n event\n })}\n <button className=\"r6o-popup-sr-only\" aria-live=\"assertive\" onClick={handleClose}>\n {props.ariaCloseWarning || 'Click or leave this dialog to close it.'}\n </button>\n </div>\n </FloatingFocusManager>\n </FloatingPortal>\n ) : null;\n\n}\n\n/**\n * Prevent text-annotator from handling the irrelevant events\n * triggered from the popup/toolbar/dialog\n */\nexport const getStopEventsPropagationProps = <T extends HTMLElement = HTMLElement>() => ({\n onPointerUp: (event: PointerEvent<T>) => event.stopPropagation(),\n onPointerDown: (event: PointerEvent<T>) => event.stopPropagation(),\n onMouseDown: (event: MouseEvent<T>) => event.stopPropagation(),\n onMouseUp: (event: MouseEvent<T>) => event.stopPropagation()\n});\n"],"names":["jsx","jsxs"],"mappings":";;;;;;;;;;AAgDa,MAAA,qBAAmD,CAAC,UAAU;;AAEnE,QAAA,EAAE,OAAO,sBAA0B,IAAA;AAEzC,QAAM,IAAI;AAEV,QAAM,EAAE,UAAU,MAAM,IAAI,aAA6B;AAEnD,QAAA,cAAa,cAAS,CAAC,MAAV,mBA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A,QAAA;AAAA,UACC,WAAU;AAAA,UACV,KAAK,KAAK;AAAA,UACV,OAAO;AAAA,UACN,GAAG,iBAAiB;AAAA,YACnB,SAAS;AAAA,YACT,QAAQ;AAAA,YACR,GAAG,8BAA8B;AAAA,UAAA,CAClC;AAAA,UACA,UAAA;AAAA,YAAM,MAAA;AAAA,cACL,YAAY,SAAS,CAAC,EAAE;AAAA,cACxB,UAAU,SAAS,CAAC,EAAE;AAAA,cACtB;AAAA,YAAA,CACD;AAAA,YACDD,kCAAAA,IAAC,UAAO,EAAA,WAAU,qBAAoB,aAAU,aAAY,SAAS,aAClE,UAAM,MAAA,oBAAoB,0CAC7B,CAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA,EAEJ,CAAA,IACE;AAEN;AAMO,MAAM,gCAAgC,OAA4C;AAAA,EACvF,aAAa,CAAC,UAA2B,MAAM,gBAAgB;AAAA,EAC/D,eAAe,CAAC,UAA2B,MAAM,gBAAgB;AAAA,EACjE,aAAa,CAAC,UAAyB,MAAM,gBAAgB;AAAA,EAC7D,WAAW,CAAC,UAAyB,MAAM,gBAAgB;AAC7D;"}
1
+ {"version":3,"file":"react-text-annotator.es6.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;"}