@soomo/react-text-annotator 3.1.0-staging.1 → 3.1.0-staging.11
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/TextAnnotatorPopup.d.ts +11 -1
- package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -1
- package/dist/react-text-annotator.es.js +2 -1
- package/dist/react-text-annotator.es10.js +9 -487
- package/dist/react-text-annotator.es10.js.map +1 -1
- package/dist/react-text-annotator.es11.js +1447 -8
- package/dist/react-text-annotator.es11.js.map +1 -1
- package/dist/react-text-annotator.es13.js +249 -0
- package/dist/react-text-annotator.es13.js.map +1 -0
- package/dist/react-text-annotator.es14.js +554 -215
- package/dist/react-text-annotator.es14.js.map +1 -1
- package/dist/react-text-annotator.es15.js +78 -581
- package/dist/react-text-annotator.es15.js.map +1 -1
- package/dist/react-text-annotator.es16.js +40 -77
- package/dist/react-text-annotator.es16.js.map +1 -1
- package/dist/react-text-annotator.es17.js +482 -40
- package/dist/react-text-annotator.es17.js.map +1 -1
- package/dist/react-text-annotator.es2.js +1 -1
- package/dist/react-text-annotator.es4.js +2 -2
- package/dist/react-text-annotator.es6.js +32 -32
- package/dist/react-text-annotator.es6.js.map +1 -1
- package/package.json +2 -2
- package/dist/react-text-annotator.es12.js +0 -1451
- package/dist/react-text-annotator.es12.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { j as jsxRuntimeExports } from "./react-text-annotator.es8.js";
|
|
2
|
-
import { useState, useEffect, useMemo
|
|
3
|
-
import { isMobile } from "./react-text-annotator.
|
|
4
|
-
import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager } from "./react-text-annotator.
|
|
2
|
+
import { useState, useCallback, useEffect, useMemo } from "react";
|
|
3
|
+
import { isMobile } from "./react-text-annotator.es10.js";
|
|
4
|
+
import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager } from "./react-text-annotator.es11.js";
|
|
5
5
|
import { useAnnotator, useSelection } from "@annotorious/react";
|
|
6
|
-
import { denormalizeRectWithOffset, toDomRectList } from "@soomo/text-annotator";
|
|
6
|
+
import { isRevived, denormalizeRectWithOffset, toDomRectList } from "@soomo/text-annotator";
|
|
7
7
|
import { useAnnouncePopupNavigation } from "./react-text-annotator.es4.js";
|
|
8
8
|
/* empty css */
|
|
9
|
-
import { offset, inline, flip, shift } from "./react-text-annotator.
|
|
10
|
-
import { autoUpdate } from "./react-text-annotator.
|
|
9
|
+
import { offset, inline, flip, shift } from "./react-text-annotator.es13.js";
|
|
10
|
+
import { autoUpdate } from "./react-text-annotator.es14.js";
|
|
11
11
|
const TextAnnotatorPopup = (props) => {
|
|
12
12
|
var _a;
|
|
13
13
|
const { popup, ariaNavigationMessage } = props;
|
|
@@ -16,12 +16,12 @@ const TextAnnotatorPopup = (props) => {
|
|
|
16
16
|
const annotation = (_a = selected[0]) == null ? void 0 : _a.annotation;
|
|
17
17
|
const [isOpen, setOpen] = useState((selected == null ? void 0 : selected.length) > 0);
|
|
18
18
|
const handleClose = () => r == null ? void 0 : r.cancelSelected();
|
|
19
|
-
const [
|
|
20
|
-
const
|
|
21
|
-
const
|
|
19
|
+
const [isFocused, setFocused] = useState(false);
|
|
20
|
+
const handleFocus = useCallback(() => setFocused(true), []);
|
|
21
|
+
const handleBlur = useCallback(() => setFocused(false), []);
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
if (!isOpen)
|
|
24
|
-
}, [isOpen,
|
|
23
|
+
if (!isOpen) handleBlur();
|
|
24
|
+
}, [isOpen, handleBlur]);
|
|
25
25
|
const { refs, floatingStyles, update, context } = useFloating({
|
|
26
26
|
placement: isMobile() ? "bottom" : "top",
|
|
27
27
|
open: isOpen,
|
|
@@ -43,22 +43,18 @@ const TextAnnotatorPopup = (props) => {
|
|
|
43
43
|
const role = useRole(context, { role: "dialog" });
|
|
44
44
|
const { getFloatingProps } = useInteractions([dismiss, role]);
|
|
45
45
|
useEffect(() => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
annotation.target.selector.length > 0 && // Range not collapsed? (E.g. lazy loading PDFs. Note that this will have to
|
|
50
|
-
// change if we switch from ranges to pre-computed bounds!)
|
|
51
|
-
!annotation.target.selector[0].range.collapsed
|
|
52
|
-
);
|
|
46
|
+
const annotationSelector = annotation == null ? void 0 : annotation.target.selector;
|
|
47
|
+
if (!annotationSelector) return;
|
|
48
|
+
setOpen(isRevived(annotationSelector));
|
|
53
49
|
}, [annotation]);
|
|
54
50
|
useEffect(() => {
|
|
55
51
|
if (!r) return;
|
|
56
52
|
if (isOpen && (annotation == null ? void 0 : annotation.id)) {
|
|
57
53
|
refs.setPositionReference({
|
|
58
|
-
getBoundingClientRect: () =>
|
|
59
|
-
r.state.store.getAnnotationBounds(annotation.id)
|
|
60
|
-
r.element.getBoundingClientRect()
|
|
61
|
-
|
|
54
|
+
getBoundingClientRect: () => {
|
|
55
|
+
const bounds = r.state.store.getAnnotationBounds(annotation.id);
|
|
56
|
+
return bounds ? denormalizeRectWithOffset(bounds, r.element.getBoundingClientRect()) : new DOMRect();
|
|
57
|
+
},
|
|
62
58
|
getClientRects: () => {
|
|
63
59
|
const rects = r.state.store.getAnnotationRects(annotation.id);
|
|
64
60
|
const denormalizedRects = rects.map(
|
|
@@ -85,14 +81,10 @@ const TextAnnotatorPopup = (props) => {
|
|
|
85
81
|
return (event == null ? void 0 : event.type) === "keyup" || (event == null ? void 0 : event.type) === "contextmenu" || isMobile() ? -1 : 0;
|
|
86
82
|
}, [event]);
|
|
87
83
|
useAnnouncePopupNavigation({
|
|
88
|
-
disabled:
|
|
84
|
+
disabled: isFocused,
|
|
89
85
|
floatingOpen: isOpen,
|
|
90
86
|
message: ariaNavigationMessage
|
|
91
87
|
});
|
|
92
|
-
const getStopEventsPropagationProps = useCallback(
|
|
93
|
-
() => ({ onPointerUp: (event2) => event2.stopPropagation() }),
|
|
94
|
-
[]
|
|
95
|
-
);
|
|
96
88
|
return isOpen && annotation ? /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingPortal, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
97
89
|
FloatingFocusManager,
|
|
98
90
|
{
|
|
@@ -107,10 +99,11 @@ const TextAnnotatorPopup = (props) => {
|
|
|
107
99
|
className: "a9s-popup r6o-popup annotation-popup r6o-text-popup not-annotatable",
|
|
108
100
|
ref: refs.setFloating,
|
|
109
101
|
style: floatingStyles,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
...getFloatingProps({
|
|
103
|
+
onFocus: handleFocus,
|
|
104
|
+
onBlur: handleBlur,
|
|
105
|
+
...getStopEventsPropagationProps()
|
|
106
|
+
}),
|
|
114
107
|
children: [
|
|
115
108
|
popup({
|
|
116
109
|
annotation: selected[0].annotation,
|
|
@@ -124,7 +117,14 @@ const TextAnnotatorPopup = (props) => {
|
|
|
124
117
|
}
|
|
125
118
|
) }) : null;
|
|
126
119
|
};
|
|
120
|
+
const getStopEventsPropagationProps = () => ({
|
|
121
|
+
onPointerUp: (event) => event.stopPropagation(),
|
|
122
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
123
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
124
|
+
onMouseUp: (event) => event.stopPropagation()
|
|
125
|
+
});
|
|
127
126
|
export {
|
|
128
|
-
TextAnnotatorPopup
|
|
127
|
+
TextAnnotatorPopup,
|
|
128
|
+
getStopEventsPropagationProps
|
|
129
129
|
};
|
|
130
130
|
//# 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, 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 denormalizeRectWithOffset,\n toDomRectList,\n type TextAnnotation,\n type TextAnnotator
|
|
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,mBAAa;AAEhC,QAAM,CAAC,QAAQ,OAAO,IAAI,UAAS,qCAAU,UAAS,CAAC;AACjD,QAAA,cAAc,MAAM,uBAAG;AAE7B,QAAM,CAAC,WAAW,UAAU,IAAI,SAAS,KAAK;AAC9C,QAAM,cAAc,YAAY,MAAM,WAAW,IAAI,GAAG,CAAA,CAAE;AAC1D,QAAM,aAAa,YAAY,MAAM,WAAW,KAAK,GAAG,CAAA,CAAE;AAC1D,YAAU,MAAM;AACV,QAAA,CAAC,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AA,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;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soomo/react-text-annotator",
|
|
3
|
-
"version": "3.1.0-staging.
|
|
3
|
+
"version": "3.1.0-staging.11",
|
|
4
4
|
"description": "Recogito Text Annotator React bindings",
|
|
5
5
|
"author": "Rainer Simon",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@annotorious/react": "^3.0.9",
|
|
49
49
|
"@floating-ui/react": "^0.26.24",
|
|
50
50
|
"@react-aria/live-announcer": "^3.3.4",
|
|
51
|
-
"@soomo/text-annotator": "3.1.0-staging.
|
|
51
|
+
"@soomo/text-annotator": "3.1.0-staging.11",
|
|
52
52
|
"@recogito/text-annotator-tei": "3.0.0-rc.49",
|
|
53
53
|
"CETEIcean": "^1.9.3",
|
|
54
54
|
"unique-random": "^4.0.0"
|