@annotorious/react-manifold 0.0.7 → 0.0.9
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/package.json +2 -12
- package/src/Annotorious.tsx +48 -0
- package/src/AnnotoriousManifold.tsx +141 -0
- package/src/AnnotoriousManifoldInstance.ts +106 -0
- package/src/index.ts +3 -0
- package/src/synchronizeInstances.tsx +11 -0
- package/test/33054-000002-0001.jpg +0 -0
- package/test/App.tsx +50 -0
- package/test/index.css +18 -0
- package/test/index.html +12 -0
- package/test/index.tsx +13 -0
- package/tsconfig.json +26 -0
- package/tsconfig.node.json +10 -0
- package/vite.config.js +40 -0
- package/dist/Annotorious.d.ts +0 -13
- package/dist/Annotorious.d.ts.map +0 -1
- package/dist/AnnotoriousManifold.d.ts +0 -26
- package/dist/AnnotoriousManifold.d.ts.map +0 -1
- package/dist/AnnotoriousManifoldInstance.d.ts +0 -16
- package/dist/AnnotoriousManifoldInstance.d.ts.map +0 -1
- package/dist/annotorious-react-manifold.es.js +0 -13
- package/dist/annotorious-react-manifold.es.js.map +0 -1
- package/dist/annotorious-react-manifold.es10.js +0 -5
- package/dist/annotorious-react-manifold.es10.js.map +0 -1
- package/dist/annotorious-react-manifold.es2.js +0 -15
- package/dist/annotorious-react-manifold.es2.js.map +0 -1
- package/dist/annotorious-react-manifold.es3.js +0 -58
- package/dist/annotorious-react-manifold.es3.js.map +0 -1
- package/dist/annotorious-react-manifold.es4.js +0 -31
- package/dist/annotorious-react-manifold.es4.js.map +0 -1
- package/dist/annotorious-react-manifold.es5.js +0 -9
- package/dist/annotorious-react-manifold.es5.js.map +0 -1
- package/dist/annotorious-react-manifold.es6.js +0 -5
- package/dist/annotorious-react-manifold.es6.js.map +0 -1
- package/dist/annotorious-react-manifold.es7.js +0 -33
- package/dist/annotorious-react-manifold.es7.js.map +0 -1
- package/dist/annotorious-react-manifold.es8.js +0 -602
- package/dist/annotorious-react-manifold.es8.js.map +0 -1
- package/dist/annotorious-react-manifold.es9.js +0 -5
- package/dist/annotorious-react-manifold.es9.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/synchronizeInstances.d.ts +0 -3
- package/dist/synchronizeInstances.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@annotorious/react-manifold",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A utility to manage multiple parallel Annotorious instances more efficiently",
|
|
5
5
|
"author": "Rainer Simon",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -13,21 +13,11 @@
|
|
|
13
13
|
"url": "https://github.com/annotorious/annotorious-react-manifold/issues"
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
|
+
"main": "./src/index.ts",
|
|
16
17
|
"scripts": {
|
|
17
18
|
"start": "vite",
|
|
18
19
|
"build": "tsc && vite build"
|
|
19
20
|
},
|
|
20
|
-
"module": "./dist/annotorious-react-manifold.es.js",
|
|
21
|
-
"types": "./dist/index.d.ts",
|
|
22
|
-
"files": [
|
|
23
|
-
"dist"
|
|
24
|
-
],
|
|
25
|
-
"exports": {
|
|
26
|
-
".": {
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"import": "./dist/annotorious-react-manifold.es.js"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
21
|
"devDependencies": {
|
|
32
22
|
"@types/react": "^18.2.35",
|
|
33
23
|
"@types/react-dom": "^18.2.14",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ReactNode, useContext, useEffect } from 'react';
|
|
2
|
+
import { Annotation, Annotator, useAnnotator } from '@annotorious/react';
|
|
3
|
+
import { Annotorious as AnnotoriousInstance } from '@annotorious/react';
|
|
4
|
+
import { AnnotoriousManifoldContext } from './AnnotoriousManifold';
|
|
5
|
+
|
|
6
|
+
interface AnnotoriousProps {
|
|
7
|
+
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
|
|
10
|
+
source: string;
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Consumes the standard Annotorious context, and passes the Annotator
|
|
16
|
+
* upwards to the manifold.
|
|
17
|
+
*/
|
|
18
|
+
const AnnotoriousInstanceShim = <I extends Annotation = Annotation, E extends unknown = Annotation>(props: AnnotoriousProps) => {
|
|
19
|
+
|
|
20
|
+
const anno = useAnnotator<Annotator<I, E>>();
|
|
21
|
+
|
|
22
|
+
const { connectAnnotator } = useContext(AnnotoriousManifoldContext);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (anno)
|
|
26
|
+
return connectAnnotator(props.source, anno);
|
|
27
|
+
}, [anno]);
|
|
28
|
+
|
|
29
|
+
return <>{props.children}</>;
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An alternative <Annotorious /> component that mimicks the original
|
|
35
|
+
* from @annotorious/react, but injects the shim component, which connects
|
|
36
|
+
* the Annotator to the Manifold.
|
|
37
|
+
*/
|
|
38
|
+
export const Annotorious = (props: AnnotoriousProps) => {
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<AnnotoriousInstance>
|
|
42
|
+
<AnnotoriousInstanceShim source={props.source}>
|
|
43
|
+
{props.children}
|
|
44
|
+
</AnnotoriousInstanceShim>
|
|
45
|
+
</AnnotoriousInstance>
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ReactNode, createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { Annotation, Annotator } from '@annotorious/react';
|
|
3
|
+
import type { StoreChangeEvent } from '@annotorious/react';
|
|
4
|
+
import { AnnotoriousManifoldInstance, createManifoldInstance } from './AnnotoriousManifoldInstance';
|
|
5
|
+
|
|
6
|
+
interface AnnotoriousManifoldContextValue {
|
|
7
|
+
|
|
8
|
+
annotators: Map<string, Annotator<any, unknown>>;
|
|
9
|
+
|
|
10
|
+
annotations: Map<string, Annotation[]>;
|
|
11
|
+
|
|
12
|
+
selection: ManifoldSelection;
|
|
13
|
+
|
|
14
|
+
connectAnnotator(source: string, anno: Annotator<any, unknown>): () => void;
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ManifoldSelection<T extends Annotation = Annotation> {
|
|
19
|
+
|
|
20
|
+
source?: string;
|
|
21
|
+
|
|
22
|
+
selected: { annotation: T, editable?: boolean }[],
|
|
23
|
+
|
|
24
|
+
pointerEvent?: PointerEvent;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
export const AnnotoriousManifoldContext = createContext<AnnotoriousManifoldContextValue>();
|
|
30
|
+
|
|
31
|
+
export const AnnotoriousManifold = (props: { children: ReactNode }) => {
|
|
32
|
+
|
|
33
|
+
const [annotators, setAnnotators] = useState<Map<string, Annotator<any, unknown>>>(new Map());
|
|
34
|
+
|
|
35
|
+
const [annotations, setAnnotations] = useState<Map<string, Annotation[]>>(new Map());
|
|
36
|
+
|
|
37
|
+
const [selection, setSelection] =
|
|
38
|
+
useState<ManifoldSelection>({ selected: [] });
|
|
39
|
+
|
|
40
|
+
// To prevent selection state updates when de-selecting other annotators
|
|
41
|
+
const muteSelectionEvents = useRef<boolean>(false);
|
|
42
|
+
|
|
43
|
+
const connectAnnotator = (source: string, anno: Annotator<any, unknown>) => {
|
|
44
|
+
// Add the annotator to the state
|
|
45
|
+
setAnnotators(m => new Map(m.entries()).set(source, anno))
|
|
46
|
+
|
|
47
|
+
const { store } = anno.state;
|
|
48
|
+
const selectionState = anno.state.selection;
|
|
49
|
+
|
|
50
|
+
// Add the annotations to the state
|
|
51
|
+
setAnnotations(m => new Map(m.entries()).set(source, store.all()));
|
|
52
|
+
|
|
53
|
+
const onStoreChange = () =>
|
|
54
|
+
setAnnotations(m => new Map(m.entries()).set(source, store.all()));
|
|
55
|
+
|
|
56
|
+
store.observe(onStoreChange);
|
|
57
|
+
|
|
58
|
+
// Track selection
|
|
59
|
+
let selectionStoreObserver: (event: StoreChangeEvent<Annotation>) => void;
|
|
60
|
+
|
|
61
|
+
const unsubscribeSelection = selectionState.subscribe(({ selected, pointerEvent }) => {
|
|
62
|
+
if (selectionStoreObserver)
|
|
63
|
+
store.unobserve(selectionStoreObserver);
|
|
64
|
+
|
|
65
|
+
const resolved = (selected || [])
|
|
66
|
+
.map(({ id, editable }) => ({ annotation: store.getAnnotation(id), editable }));
|
|
67
|
+
|
|
68
|
+
// Set the new selection
|
|
69
|
+
if (!muteSelectionEvents.current)
|
|
70
|
+
setSelection({ source, selected: resolved, pointerEvent });
|
|
71
|
+
|
|
72
|
+
// Track the state of the selected annotations in the store
|
|
73
|
+
selectionStoreObserver = event => {
|
|
74
|
+
const { updated } = event.changes;
|
|
75
|
+
|
|
76
|
+
setSelection(({ source, selected }) => ({
|
|
77
|
+
source,
|
|
78
|
+
selected: selected.map(({ annotation, editable }) => {
|
|
79
|
+
const next = updated.find(u => u.oldValue.id === annotation.id);
|
|
80
|
+
return next ? { annotation: next.newValue, editable } : { annotation, editable };
|
|
81
|
+
}),
|
|
82
|
+
pointerEvent
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
store.observe(selectionStoreObserver, { annotations: selected.map(({ id }) => id) });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return () => {
|
|
90
|
+
// Remove annotator
|
|
91
|
+
setAnnotators(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== source)));
|
|
92
|
+
|
|
93
|
+
// Remove & untrack annotations
|
|
94
|
+
setAnnotations(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== source)));
|
|
95
|
+
store.unobserve(onStoreChange);
|
|
96
|
+
|
|
97
|
+
// Un-track selection
|
|
98
|
+
unsubscribeSelection();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (selection.source) {
|
|
104
|
+
muteSelectionEvents.current = true;
|
|
105
|
+
|
|
106
|
+
Array.from(annotators.entries()).forEach(([source, anno]) => {
|
|
107
|
+
if (source !== selection.source)
|
|
108
|
+
anno.setSelected();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
muteSelectionEvents.current = false;
|
|
112
|
+
}
|
|
113
|
+
}, [selection, annotators]);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<AnnotoriousManifoldContext.Provider value={{
|
|
117
|
+
annotators,
|
|
118
|
+
annotations,
|
|
119
|
+
selection,
|
|
120
|
+
connectAnnotator
|
|
121
|
+
}}>
|
|
122
|
+
{props.children}
|
|
123
|
+
</AnnotoriousManifoldContext.Provider>
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const useAnnotoriousManifold = <I extends Annotation = Annotation, E extends unknown = Annotation>() => {
|
|
129
|
+
const { annotators } = useContext(AnnotoriousManifoldContext);
|
|
130
|
+
return createManifoldInstance(annotators) as AnnotoriousManifoldInstance<I, E>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const useAnnotations = <T extends Annotation>() => {
|
|
134
|
+
const { annotations } = useContext(AnnotoriousManifoldContext);
|
|
135
|
+
return annotations as Map<string, T[]>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const useSelection = <T extends Annotation>() => {
|
|
139
|
+
const { selection } = useContext(AnnotoriousManifoldContext);
|
|
140
|
+
return selection as ManifoldSelection<T>;
|
|
141
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Origin } from '@annotorious/react';
|
|
2
|
+
import type {
|
|
3
|
+
Annotation,
|
|
4
|
+
AnnotationBody,
|
|
5
|
+
Annotator
|
|
6
|
+
} from '@annotorious/react';
|
|
7
|
+
|
|
8
|
+
export interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends unknown = Annotation> {
|
|
9
|
+
|
|
10
|
+
annotators: Annotator<I, E>[];
|
|
11
|
+
|
|
12
|
+
sources: string[];
|
|
13
|
+
|
|
14
|
+
addBody(body: AnnotationBody, origin?: Origin): void;
|
|
15
|
+
|
|
16
|
+
clear(origin: Origin): void;
|
|
17
|
+
|
|
18
|
+
deleteAnnotation(id: string, origin?: Origin): E | undefined;
|
|
19
|
+
|
|
20
|
+
deleteBody(body: AnnotationBody, origin?: Origin): void;
|
|
21
|
+
|
|
22
|
+
destroy(): void;
|
|
23
|
+
|
|
24
|
+
getAnnotation(id: string): E | undefined;
|
|
25
|
+
|
|
26
|
+
getAnnotations(): E[];
|
|
27
|
+
|
|
28
|
+
updateAnnotation(arg1: string | I, arg2: I | Origin, arg3: Origin): void;
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const createManifoldInstance = <I extends Annotation = Annotation, E extends unknown = Annotation>(
|
|
33
|
+
annotators: Map<string, Annotator<I, E>>
|
|
34
|
+
): AnnotoriousManifoldInstance<I, E> => {
|
|
35
|
+
|
|
36
|
+
const find = (annotationId: string): { annotation?: E, annotator?: Annotator<I, E> } =>
|
|
37
|
+
Array.from(annotators.values()).reduce((found, annotator) => {
|
|
38
|
+
if (found)
|
|
39
|
+
return found;
|
|
40
|
+
|
|
41
|
+
const annotation = annotator.getAnnotationById(annotationId);
|
|
42
|
+
if (annotation)
|
|
43
|
+
return { annotation, annotator };
|
|
44
|
+
}, undefined as { annotation: E, annotator: Annotator<I, E> } | undefined ) ||
|
|
45
|
+
|
|
46
|
+
{ annotation: undefined, annotator: undefined };
|
|
47
|
+
|
|
48
|
+
/*********/
|
|
49
|
+
/** API **/
|
|
50
|
+
/*********/
|
|
51
|
+
|
|
52
|
+
const addBody = (body: AnnotationBody, origin = Origin.LOCAL) => {
|
|
53
|
+
const { annotator } = find(body.annotation);
|
|
54
|
+
if (annotator)
|
|
55
|
+
annotator.state.store.addBody(body, origin);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const clear = (origin = Origin.LOCAL) =>
|
|
59
|
+
Array.from(annotators.values()).forEach(a => a.state.store.clear(origin));
|
|
60
|
+
|
|
61
|
+
const deleteAnnotation = (id: string, origin = Origin.LOCAL) => {
|
|
62
|
+
const { annotation, annotator } = find(id);
|
|
63
|
+
|
|
64
|
+
if (annotator) {
|
|
65
|
+
annotator.state.store.deleteAnnotation(id, origin);
|
|
66
|
+
return annotation;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const deleteBody = (body: AnnotationBody, origin = Origin.LOCAL) => {
|
|
71
|
+
const { annotator } = find(body.annotation);
|
|
72
|
+
if (annotator)
|
|
73
|
+
annotator.state.store.deleteBody(body, origin);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const destroy = () =>
|
|
77
|
+
Array.from(annotators.values()).forEach(a => a.destroy());
|
|
78
|
+
|
|
79
|
+
const getAnnotation = (id: string) =>
|
|
80
|
+
find(id).annotation;
|
|
81
|
+
|
|
82
|
+
const getAnnotations = () =>
|
|
83
|
+
Array.from(annotators.values()).reduce((all, annotator) =>
|
|
84
|
+
[...all, ...annotator.getAnnotations()], [] as E[]);
|
|
85
|
+
|
|
86
|
+
const updateAnnotation = (arg1: string | I, arg2: I | Origin, arg3: Origin) => {
|
|
87
|
+
const oldId: string = typeof arg1 === 'string' ? arg1 : arg1.id;
|
|
88
|
+
const { annotator } = find(oldId);
|
|
89
|
+
if (annotator)
|
|
90
|
+
annotator.state.store.updateAnnotation(arg1, arg2, arg3);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
annotators: [...annotators.values()],
|
|
95
|
+
sources: [...annotators.keys()],
|
|
96
|
+
addBody,
|
|
97
|
+
clear,
|
|
98
|
+
deleteAnnotation,
|
|
99
|
+
deleteBody,
|
|
100
|
+
destroy,
|
|
101
|
+
getAnnotation,
|
|
102
|
+
getAnnotations,
|
|
103
|
+
updateAnnotation
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Annotation, Annotator } from '@annotorious/core/src/model';
|
|
2
|
+
|
|
3
|
+
export const synchronizeInstances = <I extends Annotation = Annotation, E extends unknown = Annotation>(
|
|
4
|
+
instances: Annotator<I, E>[]
|
|
5
|
+
) => {
|
|
6
|
+
|
|
7
|
+
// TODO listen on all instances, broadcast changes on one instance to the others
|
|
8
|
+
|
|
9
|
+
return null;
|
|
10
|
+
|
|
11
|
+
}
|
|
Binary file
|
package/test/App.tsx
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { OpenSeadragonAnnotator, OpenSeadragonViewer } from '@annotorious/react';
|
|
3
|
+
import { Annotorious, useAnnotoriousManifold } from '../src';
|
|
4
|
+
|
|
5
|
+
const ViewerTile = (props: { url: string }) => {
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div className="viewer-tile">
|
|
9
|
+
<Annotorious source={props.url}>
|
|
10
|
+
<OpenSeadragonAnnotator>
|
|
11
|
+
<OpenSeadragonViewer
|
|
12
|
+
className="osd-container"
|
|
13
|
+
options={{
|
|
14
|
+
prefixUrl: 'https://cdn.jsdelivr.net/npm/openseadragon@3.1/build/openseadragon/images/',
|
|
15
|
+
tileSources: {
|
|
16
|
+
type: 'image',
|
|
17
|
+
url: props.url
|
|
18
|
+
},
|
|
19
|
+
gestureSettingsMouse: {
|
|
20
|
+
clickToZoom: false
|
|
21
|
+
},
|
|
22
|
+
showRotationControl: true,
|
|
23
|
+
crossOriginPolicy: 'Anonymous'
|
|
24
|
+
}} />
|
|
25
|
+
</OpenSeadragonAnnotator>
|
|
26
|
+
</Annotorious>
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const App = () => {
|
|
33
|
+
|
|
34
|
+
const manifold = useAnnotoriousManifold();
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
console.log('annotators', manifold.annotators);
|
|
38
|
+
}, [manifold.annotators]);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className="container">
|
|
42
|
+
<ViewerTile url="33054-000002-0001.jpg" />
|
|
43
|
+
<ViewerTile url="33054-000002-0001.jpg" />
|
|
44
|
+
<ViewerTile url="33054-000002-0001.jpg" />
|
|
45
|
+
<ViewerTile url="33054-000002-0001.jpg" />
|
|
46
|
+
</div>
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
package/test/index.css
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
display: grid;
|
|
3
|
+
gap: 1.5vh;
|
|
4
|
+
grid-template-columns: 1fr 1fr;
|
|
5
|
+
height: 100%;
|
|
6
|
+
width: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.viewer-tile {
|
|
10
|
+
background-color: green;
|
|
11
|
+
height: 48vh;
|
|
12
|
+
position: relative;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.osd-container {
|
|
16
|
+
height: 100%;
|
|
17
|
+
width: 100%;
|
|
18
|
+
}
|
package/test/index.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Annotorious React Manifold</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="./index.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
package/test/index.tsx
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { AnnotoriousManifold } from '../src';
|
|
4
|
+
import { App } from './App';
|
|
5
|
+
|
|
6
|
+
import './index.css';
|
|
7
|
+
|
|
8
|
+
const root = createRoot(document.getElementById('app') as Element);
|
|
9
|
+
root.render(
|
|
10
|
+
<AnnotoriousManifold>
|
|
11
|
+
<App />
|
|
12
|
+
</AnnotoriousManifold>
|
|
13
|
+
);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": false,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationDir": "types",
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"isolatedModules": false,
|
|
12
|
+
"jsx": "react-jsx",
|
|
13
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
14
|
+
"module": "ESNext",
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"outDir": "dist",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"sourceMap": true,
|
|
21
|
+
"target": "ESNext",
|
|
22
|
+
"useDefineForClassFields": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["src"],
|
|
25
|
+
"references": [{ "path": "./tsconfig.node.json" }],
|
|
26
|
+
}
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import tsConfigPaths from 'vite-tsconfig-paths';
|
|
4
|
+
import dts from 'vite-plugin-dts';
|
|
5
|
+
|
|
6
|
+
import * as packageJson from './package.json';
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
plugins: [
|
|
10
|
+
react(),
|
|
11
|
+
tsConfigPaths(),
|
|
12
|
+
dts({
|
|
13
|
+
include: ['./src/'],
|
|
14
|
+
entryRoot: './src'
|
|
15
|
+
})
|
|
16
|
+
],
|
|
17
|
+
server: {
|
|
18
|
+
open: '/test/index.html'
|
|
19
|
+
},
|
|
20
|
+
build: {
|
|
21
|
+
lib: {
|
|
22
|
+
entry: './src/index.ts',
|
|
23
|
+
formats: ['es'],
|
|
24
|
+
fileName: (format) => `annotorious-react-manifold.${format}.js`
|
|
25
|
+
},
|
|
26
|
+
rollupOptions: {
|
|
27
|
+
external: [
|
|
28
|
+
...Object.keys(packageJson.peerDependencies)
|
|
29
|
+
],
|
|
30
|
+
output: {
|
|
31
|
+
preserveModules: true,
|
|
32
|
+
assetFileNames: 'annotorious-react-manifold.[ext]',
|
|
33
|
+
globals: {
|
|
34
|
+
react: 'React'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
sourcemap: true
|
|
39
|
+
}
|
|
40
|
+
});
|
package/dist/Annotorious.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
interface AnnotoriousProps {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
source: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* An alternative <Annotorious /> component that mimicks the original
|
|
8
|
-
* from @annotorious/react, but injects the shim component, which connects
|
|
9
|
-
* the Annotator to the Manifold.
|
|
10
|
-
*/
|
|
11
|
-
export declare const Annotorious: (props: AnnotoriousProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=Annotorious.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Annotorious.d.ts","sourceRoot":"","sources":["../src/Annotorious.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,OAAO,CAAC;AAKzD,UAAU,gBAAgB;IAExB,QAAQ,EAAE,SAAS,CAAC;IAEpB,MAAM,EAAE,MAAM,CAAC;CAEhB;AAqBD;;;;GAIG;AACH,eAAO,MAAM,WAAW,UAAW,gBAAgB,4CAUlD,CAAA"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import type { Annotation, Annotator } from '@annotorious/core/src';
|
|
3
|
-
import { AnnotoriousManifoldInstance } from './AnnotoriousManifoldInstance';
|
|
4
|
-
interface AnnotoriousManifoldContextValue {
|
|
5
|
-
annotators: Map<string, Annotator<any, unknown>>;
|
|
6
|
-
annotations: Map<string, Annotation[]>;
|
|
7
|
-
selection: ManifoldSelection;
|
|
8
|
-
connectAnnotator(source: string, anno: Annotator<any, unknown>): () => void;
|
|
9
|
-
}
|
|
10
|
-
interface ManifoldSelection<T extends Annotation = Annotation> {
|
|
11
|
-
source?: string;
|
|
12
|
-
selected: {
|
|
13
|
-
annotation: T;
|
|
14
|
-
editable?: boolean;
|
|
15
|
-
}[];
|
|
16
|
-
pointerEvent?: PointerEvent;
|
|
17
|
-
}
|
|
18
|
-
export declare const AnnotoriousManifoldContext: import("react").Context<AnnotoriousManifoldContextValue>;
|
|
19
|
-
export declare const AnnotoriousManifold: (props: {
|
|
20
|
-
children: ReactNode;
|
|
21
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export declare const useAnnotoriousManifold: <I extends Annotation = Annotation, E extends unknown = Annotation>() => AnnotoriousManifoldInstance<I, E>;
|
|
23
|
-
export declare const useAnnotations: <T extends Annotation>() => Map<string, T[]>;
|
|
24
|
-
export declare const useSelection: <T extends Annotation>() => ManifoldSelection<T>;
|
|
25
|
-
export {};
|
|
26
|
-
//# sourceMappingURL=AnnotoriousManifold.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnnotoriousManifold.d.ts","sourceRoot":"","sources":["../src/AnnotoriousManifold.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA0D,MAAM,OAAO,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAoB,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,2BAA2B,EAA0B,MAAM,+BAA+B,CAAC;AAEpG,UAAU,+BAA+B;IAEvC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IAEjD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAEvC,SAAS,EAAE,iBAAiB,CAAC;IAE7B,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI,CAAC;CAE7E;AAED,UAAU,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAE3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,QAAQ,EAAE;QAAE,UAAU,EAAE,CAAC,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAElD,YAAY,CAAC,EAAE,YAAY,CAAC;CAE7B;AAGD,eAAO,MAAM,0BAA0B,0DAAmD,CAAC;AAE3F,eAAO,MAAM,mBAAmB,UAAW;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4CA+FjE,CAAA;AAED,eAAO,MAAM,sBAAsB,4GAGlC,CAAA;AAED,eAAO,MAAM,cAAc,8CAG1B,CAAA;AAED,eAAO,MAAM,YAAY,kDAGxB,CAAA"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Origin } from '@annotorious/react';
|
|
2
|
-
import type { Annotation, AnnotationBody, Annotator, LifecycleEvents } from '@annotorious/core/src';
|
|
3
|
-
export interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends unknown = Annotation> {
|
|
4
|
-
annotators: Annotator<I, E>[];
|
|
5
|
-
sources: string[];
|
|
6
|
-
addBody(body: AnnotationBody, origin?: Origin): void;
|
|
7
|
-
clear(origin: Origin): void;
|
|
8
|
-
deleteAnnotation(id: string, origin?: Origin): E | undefined;
|
|
9
|
-
destroy(): void;
|
|
10
|
-
getAnnotationById(id: string): E | undefined;
|
|
11
|
-
getAnnotations(): E[];
|
|
12
|
-
on<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;
|
|
13
|
-
off<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;
|
|
14
|
-
}
|
|
15
|
-
export declare const createManifoldInstance: <I extends Annotation = Annotation, E extends unknown = Annotation>(annotators: Map<string, Annotator<I, E>>) => AnnotoriousManifoldInstance<I, E>;
|
|
16
|
-
//# sourceMappingURL=AnnotoriousManifoldInstance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnnotoriousManifoldInstance.d.ts","sourceRoot":"","sources":["../src/AnnotoriousManifoldInstance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,CAAC,SAAS,OAAO,GAAG,UAAU;IAE5G,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAE9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAIlB,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAErD,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAE7D,OAAO,IAAI,IAAI,CAAC;IAEhB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAE7C,cAAc,IAAI,CAAC,EAAE,CAAC;IAEtB,EAAE,CAAC,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAExF,GAAG,CAAC,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAE1F;AAED,eAAO,MAAM,sBAAsB,oJA4DlC,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Annotorious as t } from "./annotorious-react-manifold.es2.js";
|
|
2
|
-
import { AnnotoriousManifold as r, AnnotoriousManifoldContext as i, useAnnotations as s, useAnnotoriousManifold as a, useSelection as f } from "./annotorious-react-manifold.es3.js";
|
|
3
|
-
import { createManifoldInstance as l } from "./annotorious-react-manifold.es4.js";
|
|
4
|
-
export {
|
|
5
|
-
t as Annotorious,
|
|
6
|
-
r as AnnotoriousManifold,
|
|
7
|
-
i as AnnotoriousManifoldContext,
|
|
8
|
-
l as createManifoldInstance,
|
|
9
|
-
s as useAnnotations,
|
|
10
|
-
a as useAnnotoriousManifold,
|
|
11
|
-
f as useSelection
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=annotorious-react-manifold.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-react-manifold.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-react-manifold.es10.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { j as n } from "./annotorious-react-manifold.es5.js";
|
|
2
|
-
import { useContext as e, useEffect as s } from "react";
|
|
3
|
-
import { Annotorious as i, useAnnotator as c } from "@annotorious/react";
|
|
4
|
-
import { AnnotoriousManifoldContext as u } from "./annotorious-react-manifold.es3.js";
|
|
5
|
-
const m = (o) => {
|
|
6
|
-
const t = c(), { connectAnnotator: r } = e(u);
|
|
7
|
-
return s(() => {
|
|
8
|
-
if (t)
|
|
9
|
-
return r(o.source, t);
|
|
10
|
-
}, [t]), /* @__PURE__ */ n.jsx(n.Fragment, { children: o.children });
|
|
11
|
-
}, d = (o) => /* @__PURE__ */ n.jsx(i, { children: /* @__PURE__ */ n.jsx(m, { source: o.source, children: o.children }) });
|
|
12
|
-
export {
|
|
13
|
-
d as Annotorious
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=annotorious-react-manifold.es2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-react-manifold.es2.js","sources":["../src/Annotorious.tsx"],"sourcesContent":["import { ReactNode, useContext, useEffect } from 'react';\nimport { Annotation, Annotator, useAnnotator } from '@annotorious/react';\nimport { Annotorious as AnnotoriousInstance } from '@annotorious/react';\nimport { AnnotoriousManifoldContext } from './AnnotoriousManifold';\n\ninterface AnnotoriousProps {\n\n children: ReactNode;\n\n source: string;\n\n}\n\n/**\n * Consumes the standard Annotorious context, and passes the Annotator\n * upwards to the manifold.\n */\nconst AnnotoriousInstanceShim = <I extends Annotation = Annotation, E extends unknown = Annotation>(props: AnnotoriousProps) => {\n\n const anno = useAnnotator<Annotator<I, E>>();\n\n const { connectAnnotator } = useContext(AnnotoriousManifoldContext);\n\n useEffect(() => {\n if (anno)\n return connectAnnotator(props.source, anno);\n }, [anno]);\n\n return <>{props.children}</>;\n\n}\n\n/**\n * An alternative <Annotorious /> component that mimicks the original\n * from @annotorious/react, but injects the shim component, which connects\n * the Annotator to the Manifold.\n */\nexport const Annotorious = (props: AnnotoriousProps) => {\n\n return (\n <AnnotoriousInstance>\n <AnnotoriousInstanceShim source={props.source}>\n {props.children}\n </AnnotoriousInstanceShim>\n </AnnotoriousInstance>\n )\n\n}"],"names":["AnnotoriousInstanceShim","props","anno","useAnnotator","connectAnnotator","useContext","AnnotoriousManifoldContext","useEffect","jsx","Fragment","Annotorious","AnnotoriousInstance"],"mappings":";;;;AAiBA,MAAMA,IAA0B,CAAoEC,MAA4B;AAE9H,QAAMC,IAAOC,KAEP,EAAE,kBAAAC,EAAA,IAAqBC,EAAWC,CAA0B;AAElE,SAAAC,EAAU,MAAM;AACV,QAAAL;AACK,aAAAE,EAAiBH,EAAM,QAAQC,CAAI;AAAA,EAAA,GAC3C,CAACA,CAAI,CAAC,GAEFM,gBAAAA,EAAAA,IAAAC,EAAAA,UAAA,EAAG,YAAM,SAAS,CAAA;AAE3B,GAOaC,IAAc,CAACT,MAGxBO,gBAAAA,EAAAA,IAACG,KACC,UAACH,gBAAAA,EAAA,IAAAR,GAAA,EAAwB,QAAQC,EAAM,QACpC,UAAMA,EAAA,SACT,CAAA,EACF,CAAA;"}
|