Skip to content

Commit a8e7adb

Browse files
authored
Merge pull request #178 from recogito/selection-mode
New `selectionMode` init prop
2 parents 22b45f0 + ee757d1 commit a8e7adb

File tree

16 files changed

+229
-205
lines changed

16 files changed

+229
-205
lines changed

package-lock.json

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

packages/extension-tei/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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",
35+
"@annotorious/core": "^3.0.12",
3636
"@recogito/text-annotator": "3.0.0-rc.51"
3737
}
3838
}

packages/text-annotator-react/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.1.0"
34+
"vite-tsconfig-paths": "^5.1.2"
3535
},
3636
"peerDependencies": {
3737
"openseadragon": "^3.0.0 || ^4.0.0 || ^5.0.0",
@@ -44,8 +44,8 @@
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",
5050
"@recogito/text-annotator": "3.0.0-rc.51",
5151
"@recogito/text-annotator-tei": "3.0.0-rc.51",

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

File renamed without changes.

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
useRole
2020
} from '@floating-ui/react';
2121

22-
import './TextAnnotatorPopup.css';
22+
import './TextAnnotationPopup.css';
2323

2424
interface TextAnnotationPopupProps {
2525

@@ -39,11 +39,11 @@ export interface TextAnnotationPopupContentProps {
3939

4040
editable?: boolean;
4141

42-
event?: PointerEvent;
42+
event?: PointerEvent | KeyboardEvent;
4343

4444
}
4545

46-
export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
46+
export const TextAnnotationPopup = (props: TextAnnotationPopupProps) => {
4747

4848
const r = useAnnotator<TextAnnotator>();
4949

@@ -177,3 +177,14 @@ const getStopEventsPropagationProps = <T extends HTMLElement = HTMLElement>() =>
177177
onMouseDown: (event: React.MouseEvent<T>) => event.stopPropagation(),
178178
onMouseUp: (event: React.MouseEvent<T>) => event.stopPropagation()
179179
});
180+
181+
/** For backwards compatibility **/
182+
/** @deprecated Use TextAnnotationPopup instead */
183+
export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
184+
185+
useEffect(() => {
186+
console.warn('TextAnnotatorPopup is deprecated and will be removed in a future version. Please use TextAnnotationPopup instead.');
187+
}, []);
188+
189+
return <TextAnnotationPopup {...props} />;
190+
};
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/isMobile.ts renamed to packages/text-annotator-react/src/TextAnnotationPopup/isMobile.ts

File renamed without changes.

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

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

packages/text-annotator/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030
"@types/rbush": "^4.0.0",
3131
"jsdom": "^25.0.1",
3232
"typescript": "5.6.3",
33-
"vite": "^5.4.10",
33+
"vite": "^5.4.11",
3434
"vite-plugin-dts": "^4.3.0",
3535
"vitest": "^2.1.4"
3636
},
3737
"dependencies": {
38-
"@annotorious/core": "^3.0.11",
38+
"@annotorious/core": "^3.0.12",
3939
"colord": "^2.9.3",
4040
"dequal": "^2.0.3",
4141
"hotkeys-js": "^3.13.7",
4242
"rbush": "^4.0.1",
43-
"uuid": "^11.0.2"
43+
"uuid": "^11.0.3"
4444
}
4545
}

packages/text-annotator/src/SelectionHandler.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
trimRangeToContainer,
1616
isNotAnnotatable
1717
} from './utils';
18+
import type { TextAnnotatorOptions } from './TextAnnotatorOptions';
1819

1920
const CLICK_TIMEOUT = 300;
2021

@@ -30,12 +31,13 @@ const SELECTION_KEYS = [
3031
export const SelectionHandler = (
3132
container: HTMLElement,
3233
state: TextAnnotatorState<TextAnnotation, unknown>,
33-
annotatingEnabled: boolean,
34-
offsetReferenceSelector?: string
34+
options: TextAnnotatorOptions<TextAnnotation, unknown>
3535
) => {
3636

3737
let currentUser: User | undefined;
3838

39+
const { annotatingEnabled, offsetReferenceSelector, selectionMode } = options;
40+
3941
const setUser = (user?: User) => currentUser = user;
4042

4143
let currentFilter: Filter | undefined;
@@ -179,14 +181,20 @@ export const SelectionHandler = (
179181
const hovered =
180182
evt.target instanceof Node &&
181183
container.contains(evt.target) &&
182-
store.getAt(evt.clientX - x, evt.clientY - y, currentFilter);
184+
store.getAt(evt.clientX - x, evt.clientY - y, selectionMode === 'all', currentFilter);
183185

184186
if (hovered) {
185187
const { selected } = selection;
186188

187-
if (selected.length !== 1 || selected[0].id !== hovered.id) {
188-
selection.userSelect(hovered.id, evt);
189-
}
189+
const currentIds = new Set(selected.map(s => s.id));
190+
const nextIds = Array.isArray(hovered) ? hovered.map(a => a.id) : [hovered.id];
191+
192+
const hasChanged =
193+
currentIds.size !== nextIds.length ||
194+
!nextIds.every(id => currentIds.has(id));
195+
196+
if (hasChanged)
197+
selection.userSelect(nextIds, evt);
190198
} else {
191199
selection.clear();
192200
}

0 commit comments

Comments
 (0)