Skip to content

Commit 0ab1452

Browse files
committed
Updates according to latest Annotorious API changes, plumbing for annotation filters
1 parent 2412459 commit 0ab1452

File tree

8 files changed

+104
-85
lines changed

8 files changed

+104
-85
lines changed

package-lock.json

Lines changed: 61 additions & 61 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
"vite-plugin-dts": "^2.3.0"
3232
},
3333
"dependencies": {
34-
"@annotorious/core": "^3.0.0-rc.1"
34+
"@annotorious/core": "^3.0.0-rc.2"
3535
}
3636
}

packages/extension-tei/src/TEIPlugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ export const TEIPlugin = (anno: TextAnnotator): RecogitoTEIAnnotator => {
7878
...anno.state,
7979
// @ts-ignore
8080
store
81-
},
82-
get style() { return anno.style },
83-
set style(s: DrawingStyle | ((annotation: TextAnnotation) => DrawingStyle) | undefined) { anno.style = s }
81+
}
8482
}
8583

8684
}

packages/text-annotator-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"vite-tsconfig-paths": "^4.2.0"
3535
},
3636
"peerDependencies": {
37-
"@annotorious/react": "^3.0.0-rc.1",
37+
"@annotorious/react": "^3.0.0-rc.2",
3838
"react": "16.8.0 || >=17.x || >=18.x",
3939
"react-dom": "16.8.0 || >=17.x || >=18.x"
4040
},

packages/text-annotator-react/src/TextAnnotator.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { ReactNode, useContext, useEffect, useRef } from 'react';
22
import { AnnotoriousContext, DrawingStyle } from '@annotorious/react';
3-
import { TextAnnotator as RecogitoTextAnnotator } from '@recogito/text-annotator';
4-
import { TextAnnotation, TextAnnotatorOptions, createTextAnnotator } from '@recogito/text-annotator';
3+
import { createTextAnnotator } from '@recogito/text-annotator';
4+
import type { Filter, TextAnnotation, TextAnnotatorOptions } from '@recogito/text-annotator';
55

66
import '@recogito/text-annotator/dist/text-annotator.css';
77

88
export type TextAnnotatorProps<E extends unknown> = TextAnnotatorOptions<E> & {
99

1010
children?: ReactNode | JSX.Element;
1111

12+
filter?: Filter;
13+
1214
style?: DrawingStyle | ((annotation: TextAnnotation) => DrawingStyle);
1315

1416
}
@@ -24,7 +26,7 @@ export const TextAnnotator = <E extends unknown>(props: TextAnnotatorProps<E>) =
2426
useEffect(() => {
2527
if (setAnno) {
2628
const anno = createTextAnnotator(el.current, opts);
27-
anno.style = props.style;
29+
anno.setStyle(props.style);
2830
setAnno(anno);
2931
}
3032
}, [setAnno]);
@@ -33,9 +35,16 @@ export const TextAnnotator = <E extends unknown>(props: TextAnnotatorProps<E>) =
3335
if (!anno)
3436
return;
3537

36-
(anno as unknown as RecogitoTextAnnotator<TextAnnotation>).style = props.style;
38+
anno.setStyle(props.style);
3739
}, [props.style]);
3840

41+
useEffect(() => {
42+
if (!anno)
43+
return;
44+
45+
anno.setFilter(props.filter);
46+
}, [props.filter]);
47+
3948
return (
4049
<div ref={el}>
4150
{children}

packages/text-annotator-react/src/tei/TEIAnnotator.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { Children, ReactElement, ReactNode, cloneElement, useContext, useEffect } from 'react';
22
import { AnnotoriousContext, DrawingStyle } from '@annotorious/react';
3-
import { TextAnnotatorOptions, createTextAnnotator, TextAnnotation } from '@recogito/text-annotator';
4-
import { RecogitoTEIAnnotator, TEIPlugin } from '@recogito/text-annotator-tei';
3+
import { TEIPlugin } from '@recogito/text-annotator-tei';
4+
import { createTextAnnotator } from '@recogito/text-annotator';
5+
import type { Filter, TextAnnotatorOptions, TextAnnotation } from '@recogito/text-annotator';
56

67
import '@recogito/text-annotator/dist/text-annotator.css';
78

89
export type TEIAnnotatorProps = TextAnnotatorOptions & {
910

1011
children?: ReactNode | JSX.Element;
1112

13+
filter?: Filter;
14+
1215
style?: DrawingStyle | ((annotation: TextAnnotation) => DrawingStyle);
1316

1417
}
@@ -19,17 +22,24 @@ export const TEIAnnotator = (props: TEIAnnotatorProps) => {
1922

2023
const onLoad = (element: HTMLElement) => {
2124
const anno = TEIPlugin(createTextAnnotator(element));
22-
anno.style = props.style;
25+
anno.setStyle(props.style);
2326
setAnno(anno);
2427
}
2528

2629
useEffect(() => {
2730
if (!anno)
2831
return;
2932

30-
(anno as RecogitoTEIAnnotator).style = props.style;
33+
anno.setStyle(props.style);
3134
}, [props.style]);
3235

36+
useEffect(() => {
37+
if (!anno)
38+
return;
39+
40+
anno.setFilter(props.filter);
41+
}, [props.filter]);
42+
3343
return props.children ?
3444
Children.toArray(props.children).map(child =>
3545
cloneElement(child as ReactElement, { onLoad })) : null;

packages/text-annotator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"vite-plugin-dts": "^2.3.0"
3434
},
3535
"dependencies": {
36-
"@annotorious/core": "^3.0.0-rc.1",
36+
"@annotorious/core": "^3.0.0-rc.2",
3737
"rbush": "^3.0.1",
3838
"uuid": "^9.0.0"
3939
}

0 commit comments

Comments
 (0)