Skip to content

Commit e427223

Browse files
Merge branch 'main' into spatial-tree-positioning
# Conflicts: # packages/text-annotator-react/src/TextAnnotationPopup/TextAnnotationPopup.tsx
2 parents 81c76c2 + 2b00afd commit e427223

File tree

21 files changed

+371
-305
lines changed

21 files changed

+371
-305
lines changed

package-lock.json

Lines changed: 195 additions & 204 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@recogito/text-annotator-monorepo",
3-
"version": "3.0.0-rc.50",
3+
"version": "3.0.0-rc.52",
44
"description": "Recogito Text Annotator monorepo",
55
"author": "Rainer Simon",
66
"repository": {

packages/extension-tei/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@recogito/text-annotator-tei",
3-
"version": "3.0.0-rc.50",
3+
"version": "3.0.0-rc.52",
44
"description": "Recogito Text Annotator TEI extension",
55
"author": "Rainer Simon",
66
"license": "BSD-3-Clause",
@@ -28,11 +28,11 @@
2828
"devDependencies": {
2929
"CETEIcean": "^1.9.3",
3030
"typescript": "5.6.3",
31-
"vite": "^5.4.10",
31+
"vite": "^5.4.11",
3232
"vite-plugin-dts": "^4.3.0"
3333
},
3434
"peerDependencies": {
35-
"@annotorious/core": "^3.0.11",
36-
"@recogito/text-annotator": "3.0.0-rc.50"
35+
"@annotorious/core": "^3.0.12",
36+
"@recogito/text-annotator": "3.0.0-rc.52"
3737
}
3838
}

packages/text-annotator-react/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@recogito/react-text-annotator",
3-
"version": "3.0.0-rc.50",
3+
"version": "3.0.0-rc.52",
44
"description": "Recogito Text Annotator React bindings",
55
"author": "Rainer Simon",
66
"license": "BSD-3-Clause",
@@ -29,9 +29,9 @@
2929
"react": "^18.3.1",
3030
"react-dom": "^18.3.1",
3131
"typescript": "5.6.3",
32-
"vite": "^5.4.10",
32+
"vite": "^5.4.11",
3333
"vite-plugin-dts": "^4.3.0",
34-
"vite-tsconfig-paths": "^5.0.1"
34+
"vite-tsconfig-paths": "^5.1.2"
3535
},
3636
"peerDependencies": {
3737
"openseadragon": "^3.0.0 || ^4.0.0 || ^5.0.0",
@@ -44,11 +44,11 @@
4444
}
4545
},
4646
"dependencies": {
47-
"@annotorious/core": "^3.0.11",
48-
"@annotorious/react": "^3.0.11",
47+
"@annotorious/core": "^3.0.12",
48+
"@annotorious/react": "^3.0.12",
4949
"@floating-ui/react": "^0.26.27",
50-
"@recogito/text-annotator": "3.0.0-rc.50",
51-
"@recogito/text-annotator-tei": "3.0.0-rc.50",
50+
"@recogito/text-annotator": "3.0.0-rc.52",
51+
"@recogito/text-annotator-tei": "3.0.0-rc.52",
5252
"CETEIcean": "^1.9.3"
5353
}
5454
}

packages/text-annotator-react/src/TextAnnotatorPopup/TextAnnotatorPopup.tsx renamed to packages/text-annotator-react/src/TextAnnotationPopup/TextAnnotationPopup.tsx

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { PointerEvent, ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
2-
1+
import { ReactNode, useEffect, useMemo, useRef, useState } from 'react';
32
import { useAnnotator, useSelection } from '@annotorious/react';
43
import {
54
isRevived,
5+
NOT_ANNOTATABLE_CLASS,
66
denormalizeRectWithOffset,
77
toDomRectList,
88
type TextAnnotation,
@@ -11,8 +11,11 @@ import {
1111

1212
import { isMobile } from './isMobile';
1313
import {
14+
arrow,
1415
autoUpdate,
1516
flip,
17+
FloatingArrow,
18+
FloatingArrowProps,
1619
FloatingFocusManager,
1720
FloatingPortal,
1821
inline,
@@ -24,12 +27,16 @@ import {
2427
useRole
2528
} from '@floating-ui/react';
2629

27-
import './TextAnnotatorPopup.css';
30+
import './TextAnnotationPopup.css';
2831

2932
interface TextAnnotationPopupProps {
3033

3134
ariaCloseWarning?: string;
3235

36+
arrow?: boolean;
37+
38+
arrowProps?: Omit<FloatingArrowProps, 'context' | 'ref'>;
39+
3340
popup(props: TextAnnotationPopupContentProps): ReactNode;
3441

3542
}
@@ -40,11 +47,11 @@ export interface TextAnnotationPopupContentProps {
4047

4148
editable?: boolean;
4249

43-
event?: PointerEvent;
50+
event?: PointerEvent | KeyboardEvent;
4451

4552
}
4653

47-
export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
54+
export const TextAnnotationPopup = (props: TextAnnotationPopupProps) => {
4855

4956
const r = useAnnotator<TextAnnotator>();
5057

@@ -54,6 +61,22 @@ export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
5461

5562
const [isOpen, setOpen] = useState(selected?.length > 0);
5663

64+
const arrowRef = useRef(null);
65+
66+
// Conditional floating-ui middleware
67+
const middleware = useMemo(() => {
68+
const m = [
69+
inline(),
70+
offset(10),
71+
flip({ crossAxis: true }),
72+
shift({ crossAxis: true, padding: 10 })
73+
];
74+
75+
return props.arrow
76+
? [...m, arrow({ element: arrowRef }) ]
77+
: m;
78+
}, [props.arrow]);
79+
5780
const { refs, floatingStyles, update, context } = useFloating({
5881
placement: isMobile() ? 'bottom' : 'top',
5982
open: isOpen,
@@ -63,12 +86,7 @@ export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
6386
r?.cancelSelected();
6487
}
6588
},
66-
middleware: [
67-
offset(10),
68-
inline(),
69-
flip(),
70-
shift({ mainAxis: false, crossAxis: true, padding: 10 })
71-
],
89+
middleware,
7290
whileElementsMounted: autoUpdate
7391
});
7492

@@ -121,12 +139,6 @@ export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
121139
};
122140
}, [update]);
123141

124-
// Prevent text-annotator from handling the irrelevant events triggered from the popup
125-
const getStopEventsPropagationProps = useCallback(
126-
() => ({ onPointerUp: (event: PointerEvent<HTMLDivElement>) => event.stopPropagation() }),
127-
[]
128-
);
129-
130142
// Don't shift focus to the floating element if selected via keyboard or on mobile.
131143
const initialFocus = useMemo(() => {
132144
return (event?.type === 'keyup' || event?.type === 'contextmenu' || isMobile()) ? -1 : 0;
@@ -143,17 +155,23 @@ export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
143155
returnFocus={false}
144156
initialFocus={initialFocus}>
145157
<div
146-
className="a9s-popup r6o-popup annotation-popup r6o-text-popup not-annotatable"
158+
className={`a9s-popup r6o-popup annotation-popup r6o-text-popup ${NOT_ANNOTATABLE_CLASS}`}
147159
ref={refs.setFloating}
148160
style={floatingStyles}
149-
{...getFloatingProps()}
150-
{...getStopEventsPropagationProps()}>
161+
{...getFloatingProps(getStopEventsPropagationProps())}>
151162
{props.popup({
152163
annotation: selected[0].annotation,
153164
editable: selected[0].editable,
154165
event
155166
})}
156167

168+
{props.arrow && (
169+
<FloatingArrow
170+
ref={arrowRef}
171+
context={context}
172+
{...(props.arrowProps || {})} />
173+
)}
174+
157175
<button className="r6o-popup-sr-only" aria-live="assertive" onClick={onClose}>
158176
{props.ariaCloseWarning || 'Click or leave this dialog to close it.'}
159177
</button>
@@ -163,3 +181,25 @@ export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
163181
) : null;
164182

165183
}
184+
185+
/**
186+
* Prevent text-annotator from handling the irrelevant events
187+
* triggered from the popup/toolbar/dialog
188+
*/
189+
const getStopEventsPropagationProps = <T extends HTMLElement = HTMLElement>() => ({
190+
onPointerUp: (event: React.PointerEvent<T>) => event.stopPropagation(),
191+
onPointerDown: (event: React.PointerEvent<T>) => event.stopPropagation(),
192+
onMouseDown: (event: React.MouseEvent<T>) => event.stopPropagation(),
193+
onMouseUp: (event: React.MouseEvent<T>) => event.stopPropagation()
194+
});
195+
196+
/** For backwards compatibility **/
197+
/** @deprecated Use TextAnnotationPopup instead */
198+
export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
199+
200+
useEffect(() => {
201+
console.warn('TextAnnotatorPopup is deprecated and will be removed in a future version. Please use TextAnnotationPopup instead.');
202+
}, []);
203+
204+
return <TextAnnotationPopup {...props} />;
205+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './TextAnnotationPopup';

packages/text-annotator-react/src/TextAnnotatorPopup/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/text-annotator-react/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export * from './tei';
22
export * from './TextAnnotator';
3-
export * from './TextAnnotatorPopup';
3+
export * from './TextAnnotationPopup';
44
export * from './TextAnnotatorPlugin';
55

66
// Essential re-exports from @annotorious/core

0 commit comments

Comments
 (0)