@annotorious/react-manifold 3.7.22 → 3.8.1
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Origin, Annotation, AnnotationBody, Annotator } from '@annotorious/react';
|
|
1
|
+
import { Origin, Annotation, AnnotationBody, Annotator, Filter } from '@annotorious/react';
|
|
2
2
|
export interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends {
|
|
3
3
|
id: string;
|
|
4
4
|
} = Annotation> {
|
|
@@ -16,6 +16,7 @@ export interface AnnotoriousManifoldInstance<I extends Annotation = Annotation,
|
|
|
16
16
|
getAnnotation(id: string): I | undefined;
|
|
17
17
|
getAnnotations(): I[];
|
|
18
18
|
getAnnotator(id: string): Annotator<I, E> | undefined;
|
|
19
|
+
setFilter(filter?: Filter<I>): void;
|
|
19
20
|
setSelected(annotationId: string | string[], editable?: boolean): void;
|
|
20
21
|
updateAnnotation(arg1: string | I, arg2?: I | Origin, arg3?: Origin): void;
|
|
21
22
|
}
|
|
@@ -1 +1 @@
|
|
|
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,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
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,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAExF,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,UAAU,GAAG,U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MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvE,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAE5E;AAED,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,EAC7G,YAAY,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KACvC,2BAA2B,CAAC,CAAC,EAAE,CAAC,CA8JlC,CAAA"}
|
|
@@ -1,80 +1,81 @@
|
|
|
1
1
|
import { Origin as d } from "@annotorious/react";
|
|
2
|
-
const
|
|
3
|
-
const i = (t) => Array.from(
|
|
2
|
+
const j = (s) => {
|
|
3
|
+
const i = (t) => Array.from(s.entries()).reduce((e, [n, c]) => {
|
|
4
4
|
if (e)
|
|
5
5
|
return e;
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
return { annotation:
|
|
6
|
+
const r = c.state.store.getAnnotation(t);
|
|
7
|
+
if (r)
|
|
8
|
+
return { annotation: r, annotator: c, source: n };
|
|
9
9
|
}, void 0) || { annotation: void 0, annotator: void 0, source: void 0 }, f = (t, e = d.LOCAL) => {
|
|
10
10
|
const { annotator: n } = i(t.annotation);
|
|
11
11
|
n && n.state.store.addBody(t, e);
|
|
12
|
-
}, A = (t = d.LOCAL) => Array.from(
|
|
13
|
-
const
|
|
14
|
-
const { source:
|
|
15
|
-
return { source:
|
|
16
|
-
}).filter((o) => o.source),
|
|
17
|
-
Object.entries(
|
|
18
|
-
const u =
|
|
19
|
-
u && u.state.store.bulkDeleteAnnotations(
|
|
12
|
+
}, A = (t = d.LOCAL) => Array.from(s.values()).forEach((e) => e.state.store.clear(t)), y = (t, e = d.LOCAL) => {
|
|
13
|
+
const c = t.map((o) => typeof o == "string" ? o : o.id).map((o) => {
|
|
14
|
+
const { source: a } = i(o);
|
|
15
|
+
return { source: a, id: o };
|
|
16
|
+
}).filter((o) => o.source), r = Object.groupBy(c, (o) => o.source);
|
|
17
|
+
Object.entries(r).forEach(([o, a]) => {
|
|
18
|
+
const u = s.get(o);
|
|
19
|
+
u && u.state.store.bulkDeleteAnnotations(a.map((l) => l.id), e);
|
|
20
20
|
});
|
|
21
|
-
},
|
|
22
|
-
const n = t.map((
|
|
23
|
-
const { source: o } = i(
|
|
24
|
-
return { source: o, annotation:
|
|
25
|
-
}).filter((
|
|
26
|
-
Object.entries(
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
21
|
+
}, p = (t, e = d.LOCAL) => {
|
|
22
|
+
const n = t.map((r) => {
|
|
23
|
+
const { source: o } = i(r.id);
|
|
24
|
+
return { source: o, annotation: r };
|
|
25
|
+
}).filter((r) => r.source), c = Object.groupBy(n, (r) => r.source);
|
|
26
|
+
Object.entries(c).forEach(([r, o]) => {
|
|
27
|
+
const a = s.get(r);
|
|
28
|
+
if (!a) return;
|
|
29
29
|
const u = o.map((l) => l.annotation).filter(Boolean);
|
|
30
|
-
|
|
30
|
+
a.state.store.bulkUpdateAnnotations(u, e);
|
|
31
31
|
});
|
|
32
32
|
}, m = (t, e = d.LOCAL) => {
|
|
33
|
-
const { annotation: n, annotator:
|
|
34
|
-
if (
|
|
35
|
-
return
|
|
36
|
-
},
|
|
33
|
+
const { annotation: n, annotator: c } = i(t);
|
|
34
|
+
if (c)
|
|
35
|
+
return c.state.store.deleteAnnotation(t, e), n;
|
|
36
|
+
}, h = (t, e = d.LOCAL) => {
|
|
37
37
|
const { annotator: n } = i(t.annotation);
|
|
38
38
|
n && n.state.store.deleteBody(t, e);
|
|
39
|
-
},
|
|
39
|
+
}, L = () => Array.from(s.values()).forEach((t) => t.destroy()), O = (t) => {
|
|
40
40
|
const { annotator: e } = i(t);
|
|
41
41
|
return e;
|
|
42
42
|
}, b = (t) => {
|
|
43
43
|
const { source: e } = i(t);
|
|
44
44
|
return e;
|
|
45
|
-
}, g = (t) => i(t).annotation, v = () => Array.from(
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
},
|
|
45
|
+
}, g = (t) => i(t).annotation, v = () => Array.from(s.values()).reduce((t, e) => [...t, ...e.state.store.all()], []), C = (t) => s.get(t), E = (t, e, n) => {
|
|
46
|
+
const c = typeof t == "string" ? t : t.id, { annotator: r } = i(c);
|
|
47
|
+
r && r.state.store.updateAnnotation(t, e, n);
|
|
48
|
+
}, B = (t) => Array.from(s.values()).forEach((e) => e.setFilter(t)), S = (t, e) => {
|
|
49
49
|
const n = /* @__PURE__ */ new Map();
|
|
50
50
|
(Array.isArray(t) ? t : [t]).forEach((o) => {
|
|
51
|
-
const { source:
|
|
52
|
-
n.set(
|
|
53
|
-
}),
|
|
54
|
-
const u =
|
|
55
|
-
u && u.setSelected(
|
|
51
|
+
const { source: a } = i(o), u = [...n.get(a) || [], o];
|
|
52
|
+
n.set(a, u);
|
|
53
|
+
}), s.entries().filter(([o, a]) => !n.has(o)).map((o) => o[1]).forEach((o) => o.cancelSelected()), n.entries().forEach(([o, a]) => {
|
|
54
|
+
const u = s.get(o);
|
|
55
|
+
u && u.setSelected(a, e);
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
return {
|
|
59
|
-
annotators: [...
|
|
60
|
-
sources: [...
|
|
59
|
+
annotators: [...s.values()],
|
|
60
|
+
sources: [...s.keys()],
|
|
61
61
|
addBody: f,
|
|
62
|
-
bulkDeleteAnnotations:
|
|
63
|
-
bulkUpdateAnnotations:
|
|
62
|
+
bulkDeleteAnnotations: y,
|
|
63
|
+
bulkUpdateAnnotations: p,
|
|
64
64
|
clear: A,
|
|
65
65
|
deleteAnnotation: m,
|
|
66
|
-
deleteBody:
|
|
67
|
-
destroy:
|
|
66
|
+
deleteBody: h,
|
|
67
|
+
destroy: L,
|
|
68
68
|
findAnnotator: O,
|
|
69
69
|
findSource: b,
|
|
70
70
|
getAnnotation: g,
|
|
71
71
|
getAnnotations: v,
|
|
72
72
|
getAnnotator: C,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
setFilter: B,
|
|
74
|
+
setSelected: S,
|
|
75
|
+
updateAnnotation: E
|
|
75
76
|
};
|
|
76
77
|
};
|
|
77
78
|
export {
|
|
78
|
-
|
|
79
|
+
j as createManifoldInstance
|
|
79
80
|
};
|
|
80
81
|
//# sourceMappingURL=annotorious-react-manifold.es8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-react-manifold.es8.js","sources":["../src/AnnotoriousManifoldInstance.ts"],"sourcesContent":["import { Origin } from '@annotorious/react';\nimport type { Annotation, AnnotationBody, Annotator } from '@annotorious/react';\n\nexport interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends { id: string } = Annotation> {\n\n annotators: Annotator<I, E>[];\n\n sources: string[];\n\n addBody(body: AnnotationBody, origin?: Origin): void;\n\n bulkDeleteAnnotations(annotationsOrIds: (I | string)[], origin?: Origin): void;\n\n bulkUpdateAnnotations(annotations: I[], origin?: Origin): void; \n\n clear(origin: Origin): void;\n\n deleteAnnotation(id: string, origin?: Origin): I | undefined;\n\n deleteBody(body: AnnotationBody, origin?: Origin): void;\n\n destroy(): void;\n\n findAnnotator(annotationId: string): Annotator<I, E> | undefined;\n\n findSource(annotationId: string): string | undefined;\n\n getAnnotation(id: string): I | undefined;\n \n getAnnotations(): I[];\n\n getAnnotator(id: string): Annotator<I, E> | undefined;\n \n setSelected(annotationId: string | string[], editable?: boolean): void;\n\n updateAnnotation(arg1: string | I, arg2?: I | Origin, arg3?: Origin): void;\n\n}\n\nexport const createManifoldInstance = <I extends Annotation = Annotation, E extends { id: string } = Annotation>(\n annotators: Map<string, Annotator<I, E>>\n): AnnotoriousManifoldInstance<I, E> => {\n\n const find = (annotationId: string): { annotation?: I, source?: string, annotator?: Annotator<I, E> } =>\n Array.from(annotators.entries()).reduce((found, [source, annotator]) => {\n if (found)\n return found;\n\n const annotation = annotator.state.store.getAnnotation(annotationId);\n if (annotation) \n return { annotation, annotator, source };\n }, undefined as { annotation: I, annotator: Annotator<I, E> } | undefined ) || \n\n { annotation: undefined, annotator: undefined, source: undefined };\n\n /*********/\n /** API **/\n /*********/\n\n const addBody = (body: AnnotationBody, origin = Origin.LOCAL) => {\n const { annotator } = find(body.annotation);\n if (annotator)\n annotator.state.store.addBody(body, origin);\n }\n\n const clear = (origin = Origin.LOCAL) =>\n Array.from(annotators.values()).forEach(a => a.state.store.clear(origin));\n\n const bulkDeleteAnnotations = (annotationsOrIds: (I | string)[], origin = Origin.LOCAL) => {\n const ids = annotationsOrIds.map(arg => typeof arg === 'string' ? arg : arg.id);\n\n const withAnnotator = ids.map(id => {\n const { source } = find(id);\n return { source, id };\n }).filter(t => t.source);\n\n const bySource = Object.groupBy(withAnnotator, t => t.source);\n\n Object.entries(bySource).forEach(([source, data]) => {\n const annotator = annotators.get(source);\n if (annotator)\n annotator.state.store.bulkDeleteAnnotations(data.map(d => d.id), origin);\n });\n }\n\n const bulkUpdateAnnotations = (annotations: I[], origin = Origin.LOCAL) => {\n const withAnnotator = annotations.map(annotation => {\n // Keep source and annotator, but replace annotation\n const { source } = find(annotation.id);\n return { source, annotation };\n }).filter(t => t.source);\n\n const bySource = Object.groupBy(withAnnotator, t => t.source);\n\n Object.entries(bySource).forEach(([source, data]) => {\n const annotator = annotators.get(source);\n if (!annotator) return;\n\n const toUpdate: I[] = data.map(d => d.annotation).filter(Boolean);\n annotator.state.store.bulkUpdateAnnotations(toUpdate, origin);\n })\n }\n\n const deleteAnnotation = (id: string, origin = Origin.LOCAL) => {\n const { annotation, annotator } = find(id);\n\n if (annotator) {\n annotator.state.store.deleteAnnotation(id, origin);\n return annotation;\n }\n }\n\n const deleteBody = (body: AnnotationBody, origin = Origin.LOCAL) => {\n const { annotator } = find(body.annotation);\n if (annotator)\n annotator.state.store.deleteBody(body, origin);\n }\n\n const destroy = () =>\n Array.from(annotators.values()).forEach(a => a.destroy());\n\n const findAnnotator = (annotationId: string) => {\n const { annotator } = find(annotationId);\n return annotator;\n }\n\n const findSource = (annotationId: string) => {\n const { source } = find(annotationId);\n return source;\n }\n\n const getAnnotation = (annotationId: string) => \n find(annotationId).annotation;\n\n const getAnnotations = () => \n Array.from(annotators.values()).reduce((all, annotator) =>\n [...all, ...annotator.state.store.all()], [] as I[]);\n\n const getAnnotator = (id: string) => annotators.get(id);\n\n const updateAnnotation = (arg1: string | I, arg2?: I | Origin, arg3?: Origin) => {\n const oldId: string = typeof arg1 === 'string' ? arg1 : arg1.id;\n\n const { annotator } = find(oldId);\n if (annotator)\n annotator.state.store.updateAnnotation(arg1, arg2, arg3);\n }\n\n const setSelected = (id: string | string[], editable?: boolean) => {\n const byAnnotator = new Map<string, string[]>();\n\n // Group annotations by annotator source\n const ids = Array.isArray(id) ? id : [id];\n ids.forEach(id => {\n const { source } = find(id);\n const atThisSource = [...(byAnnotator.get(source) || []), id];\n byAnnotator.set(source, atThisSource);\n });\n\n // byAnnotator will now include all annotators that have selected\n // annotations. But there may be an existing selection on annotators\n // that are not in byAnnotator. We need to clear it.\n const toClear = annotators\n .entries()\n .filter(([source, _]) => !byAnnotator.has(source))\n .map(t => t[1]);\n\n toClear.forEach(annotator => annotator.cancelSelected());\n\n byAnnotator.entries().forEach(([source, ids]) => {\n const annotator = annotators.get(source);\n if (annotator)\n annotator.setSelected(ids, editable);\n });\n }\n\n return {\n annotators: [...annotators.values()],\n sources: [...annotators.keys()],\n addBody,\n bulkDeleteAnnotations,\n bulkUpdateAnnotations,\n clear,\n deleteAnnotation,\n deleteBody,\n destroy,\n findAnnotator,\n findSource,\n getAnnotation,\n getAnnotations,\n getAnnotator,\n setSelected,\n updateAnnotation\n }\n\n}"],"names":["createManifoldInstance","annotators","find","annotationId","found","source","annotator","annotation","addBody","body","origin","Origin","clear","a","bulkDeleteAnnotations","annotationsOrIds","withAnnotator","arg","id","t","bySource","data","d","bulkUpdateAnnotations","annotations","toUpdate","deleteAnnotation","deleteBody","destroy","findAnnotator","findSource","getAnnotation","getAnnotations","all","getAnnotator","updateAnnotation","arg1","arg2","arg3","oldId","setSelected","editable","byAnnotator","atThisSource","_","ids"],"mappings":";AAuCO,MAAMA,IAAyB,CACpCC,MACsC;AAEtC,QAAMC,IAAO,CAACC,MACZ,MAAM,KAAKF,EAAW,SAAS,EAAE,OAAO,CAACG,GAAO,CAACC,GAAQC,CAAS,MAAM;AACtE,QAAIF;AACF,aAAOA;AAET,UAAMG,IAAaD,EAAU,MAAM,MAAM,cAAcH,CAAY;AACnE,QAAII;AACF,aAAO,EAAE,YAAAA,GAAY,WAAAD,GAAW,QAAAD,EAAA;AAAA,EACpC,GAAG,MAAuE,KAE1E,EAAE,YAAY,QAAW,WAAW,QAAW,QAAQ,OAAA,GAMnDG,IAAU,CAACC,GAAsBC,IAASC,EAAO,UAAU;AAC/D,UAAM,EAAE,WAAAL,EAAA,IAAcJ,EAAKO,EAAK,UAAU;AAC1C,IAAIH,KACFA,EAAU,MAAM,MAAM,QAAQG,GAAMC,CAAM;AAAA,EAC9C,GAEME,IAAQ,CAACF,IAASC,EAAO,UAC7B,MAAM,KAAKV,EAAW,OAAA,CAAQ,EAAE,QAAQ,CAAAY,MAAKA,EAAE,MAAM,MAAM,MAAMH,CAAM,CAAC,GAEpEI,IAAwB,CAACC,GAAkCL,IAASC,EAAO,UAAU;AAGzF,UAAMK,IAFMD,EAAiB,IAAI,CAAAE,MAAO,OAAOA,KAAQ,WAAWA,IAAMA,EAAI,EAAE,EAEpD,IAAI,CAAAC,MAAM;AAClC,YAAM,EAAE,QAAAb,EAAA,IAAWH,EAAKgB,CAAE;AAC1B,aAAO,EAAE,QAAAb,GAAQ,IAAAa,EAAA;AAAA,IACnB,CAAC,EAAE,OAAO,CAAAC,MAAKA,EAAE,MAAM,GAEjBC,IAAW,OAAO,QAAQJ,GAAe,CAAAG,MAAKA,EAA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AIrC,CAAM,CAAC,EAChD,IAAI,CAAAc,MAAKA,EAAE,CAAC,CAAC,EAER,QAAQ,CAAAb,MAAaA,EAAU,eAAA,CAAgB,GAEvDoC,EAAY,UAAU,QAAQ,CAAC,CAACrC,GAAQwC,CAAG,MAAM;AAC/C,YAAMvC,IAAYL,EAAW,IAAII,CAAM;AACvC,MAAIC,KACFA,EAAU,YAAYuC,GAAKJ,CAAQ;AAAA,IACvC,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,YAAY,CAAC,GAAGxC,EAAW,QAAQ;AAAA,IACnC,SAAS,CAAC,GAAGA,EAAW,MAAM;AAAA,IAC9B,SAAAO;AAAA,IACA,uBAAAM;AAAA,IACA,uBAAAS;AAAA,IACA,OAAAX;AAAA,IACA,kBAAAc;AAAA,IACA,YAAAC;AAAA,IACA,SAAAC;AAAA,IACA,eAAAC;AAAA,IACA,YAAAC;AAAA,IACA,eAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,cAAAE;AAAA,IACA,aAAAM;AAAA,IACA,kBAAAL;AAAA,EAAA;AAGJ;"}
|
|
1
|
+
{"version":3,"file":"annotorious-react-manifold.es8.js","sources":["../src/AnnotoriousManifoldInstance.ts"],"sourcesContent":["import { Origin } from '@annotorious/react';\nimport type { Annotation, AnnotationBody, Annotator, Filter } from '@annotorious/react';\n\nexport interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends { id: string } = Annotation> {\n\n annotators: Annotator<I, E>[];\n\n sources: string[];\n\n addBody(body: AnnotationBody, origin?: Origin): void;\n\n bulkDeleteAnnotations(annotationsOrIds: (I | string)[], origin?: Origin): void;\n\n bulkUpdateAnnotations(annotations: I[], origin?: Origin): void; \n\n clear(origin: Origin): void;\n\n deleteAnnotation(id: string, origin?: Origin): I | undefined;\n\n deleteBody(body: AnnotationBody, origin?: Origin): void;\n\n destroy(): void;\n\n findAnnotator(annotationId: string): Annotator<I, E> | undefined;\n\n findSource(annotationId: string): string | undefined;\n\n getAnnotation(id: string): I | undefined;\n \n getAnnotations(): I[];\n\n getAnnotator(id: string): Annotator<I, E> | undefined;\n\n setFilter(filter?: Filter<I>): void;\n \n setSelected(annotationId: string | string[], editable?: boolean): void;\n\n updateAnnotation(arg1: string | I, arg2?: I | Origin, arg3?: Origin): void;\n\n}\n\nexport const createManifoldInstance = <I extends Annotation = Annotation, E extends { id: string } = Annotation>(\n annotators: Map<string, Annotator<I, E>>\n): AnnotoriousManifoldInstance<I, E> => {\n\n const find = (annotationId: string): { annotation?: I, source?: string, annotator?: Annotator<I, E> } =>\n Array.from(annotators.entries()).reduce((found, [source, annotator]) => {\n if (found)\n return found;\n\n const annotation = annotator.state.store.getAnnotation(annotationId);\n if (annotation) \n return { annotation, annotator, source };\n }, undefined as { annotation: I, annotator: Annotator<I, E> } | undefined ) || \n\n { annotation: undefined, annotator: undefined, source: undefined };\n\n /*********/\n /** API **/\n /*********/\n\n const addBody = (body: AnnotationBody, origin = Origin.LOCAL) => {\n const { annotator } = find(body.annotation);\n if (annotator)\n annotator.state.store.addBody(body, origin);\n }\n\n const clear = (origin = Origin.LOCAL) =>\n Array.from(annotators.values()).forEach(a => a.state.store.clear(origin));\n\n const bulkDeleteAnnotations = (annotationsOrIds: (I | string)[], origin = Origin.LOCAL) => {\n const ids = annotationsOrIds.map(arg => typeof arg === 'string' ? arg : arg.id);\n\n const withAnnotator = ids.map(id => {\n const { source } = find(id);\n return { source, id };\n }).filter(t => t.source);\n\n const bySource = Object.groupBy(withAnnotator, t => t.source);\n\n Object.entries(bySource).forEach(([source, data]) => {\n const annotator = annotators.get(source);\n if (annotator)\n annotator.state.store.bulkDeleteAnnotations(data.map(d => d.id), origin);\n });\n }\n\n const bulkUpdateAnnotations = (annotations: I[], origin = Origin.LOCAL) => {\n const withAnnotator = annotations.map(annotation => {\n // Keep source and annotator, but replace annotation\n const { source } = find(annotation.id);\n return { source, annotation };\n }).filter(t => t.source);\n\n const bySource = Object.groupBy(withAnnotator, t => t.source);\n\n Object.entries(bySource).forEach(([source, data]) => {\n const annotator = annotators.get(source);\n if (!annotator) return;\n\n const toUpdate: I[] = data.map(d => d.annotation).filter(Boolean);\n annotator.state.store.bulkUpdateAnnotations(toUpdate, origin);\n })\n }\n\n const deleteAnnotation = (id: string, origin = Origin.LOCAL) => {\n const { annotation, annotator } = find(id);\n\n if (annotator) {\n annotator.state.store.deleteAnnotation(id, origin);\n return annotation;\n }\n }\n\n const deleteBody = (body: AnnotationBody, origin = Origin.LOCAL) => {\n const { annotator } = find(body.annotation);\n if (annotator)\n annotator.state.store.deleteBody(body, origin);\n }\n\n const destroy = () =>\n Array.from(annotators.values()).forEach(a => a.destroy());\n\n const findAnnotator = (annotationId: string) => {\n const { annotator } = find(annotationId);\n return annotator;\n }\n\n const findSource = (annotationId: string) => {\n const { source } = find(annotationId);\n return source;\n }\n\n const getAnnotation = (annotationId: string) => \n find(annotationId).annotation;\n\n const getAnnotations = () => \n Array.from(annotators.values()).reduce((all, annotator) =>\n [...all, ...annotator.state.store.all()], [] as I[]);\n\n const getAnnotator = (id: string) => annotators.get(id);\n\n const updateAnnotation = (arg1: string | I, arg2?: I | Origin, arg3?: Origin) => {\n const oldId: string = typeof arg1 === 'string' ? arg1 : arg1.id;\n\n const { annotator } = find(oldId);\n if (annotator)\n annotator.state.store.updateAnnotation(arg1, arg2, arg3);\n }\n\n const setFilter = (filter?: Filter<I>) =>\n Array.from(annotators.values()).forEach(a => a.setFilter(filter));\n\n const setSelected = (id: string | string[], editable?: boolean) => {\n const byAnnotator = new Map<string, string[]>();\n\n // Group annotations by annotator source\n const ids = Array.isArray(id) ? id : [id];\n ids.forEach(id => {\n const { source } = find(id);\n const atThisSource = [...(byAnnotator.get(source) || []), id];\n byAnnotator.set(source, atThisSource);\n });\n\n // byAnnotator will now include all annotators that have selected\n // annotations. But there may be an existing selection on annotators\n // that are not in byAnnotator. We need to clear it.\n const toClear = annotators\n .entries()\n .filter(([source, _]) => !byAnnotator.has(source))\n .map(t => t[1]);\n\n toClear.forEach(annotator => annotator.cancelSelected());\n\n byAnnotator.entries().forEach(([source, ids]) => {\n const annotator = annotators.get(source);\n if (annotator)\n annotator.setSelected(ids, editable);\n });\n }\n\n return {\n annotators: [...annotators.values()],\n sources: [...annotators.keys()],\n addBody,\n bulkDeleteAnnotations,\n bulkUpdateAnnotations,\n clear,\n deleteAnnotation,\n deleteBody,\n destroy,\n findAnnotator,\n findSource,\n getAnnotation,\n getAnnotations,\n getAnnotator,\n setFilter,\n setSelected,\n updateAnnotation\n }\n\n}"],"names":["createManifoldInstance","annotators","find","annotationId","found","source","annotator","annotation","addBody","body","origin","Origin","clear","a","bulkDeleteAnnotations","annotationsOrIds","withAnnotator","arg","id","t","bySource","data","d","bulkUpdateAnnotations","annotations","toUpdate","deleteAnnotation","deleteBody","destroy","findAnnotator","findSource","getAnnotation","getAnnotations","all","getAnnotator","updateAnnotation","arg1","arg2","arg3","oldId","setFilter","filter","setSelected","editable","byAnnotator","atThisSource","_","ids"],"mappings":";AAyCO,MAAMA,IAAyB,CACpCC,MACsC;AAEtC,QAAMC,IAAO,CAACC,MACZ,MAAM,KAAKF,EAAW,SAAS,EAAE,OAAO,CAACG,GAAO,CAACC,GAAQC,CAAS,MAAM;AACtE,QAAIF;AACF,aAAOA;AAET,UAAMG,IAAaD,EAAU,MAAM,MAAM,cAAcH,CAAY;AACnE,QAAII;AACF,aAAO,EAAE,YAAAA,GAAY,WAAAD,GAAW,QAAAD,EAAA;AAAA,EACpC,GAAG,MAAuE,KAE1E,EAAE,YAAY,QAAW,WAAW,QAAW,QAAQ,OAAA,GAMnDG,IAAU,CAACC,GAAsBC,IAASC,EAAO,UAAU;AAC/D,UAAM,EAAE,WAAAL,EAAA,IAAcJ,EAAKO,EAAK,UAAU;AAC1C,IAAIH,KACFA,EAAU,MAAM,MAAM,QAAQG,GAAMC,CAAM;AAAA,EAC9C,GAEME,IAAQ,CAACF,IAASC,EAAO,UAC7B,MAAM,KAAKV,EAAW,OAAA,CAAQ,EAAE,QAA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;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@annotorious/react-manifold",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "A utility to manage multiple parallel Annotorious instances more efficiently",
|
|
5
5
|
"author": "Rainer Simon",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"vite-tsconfig-paths": "^5.1.4"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@annotorious/react": "3.
|
|
53
|
+
"@annotorious/react": "3.8.1",
|
|
54
54
|
"openseadragon": ">= ^4.0.0 || >= ^5.0.0 || >= ^6.0.0",
|
|
55
55
|
"react": "^16.8.0 || >= ^17.x || >= ^18.x || >= ^19.x",
|
|
56
56
|
"react-dom": "^16.8.0 || >= ^17.x || >= ^18.x|| >= ^19.x"
|