@annotorious/react-manifold 3.7.16 → 3.7.17

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.
@@ -16,7 +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
- setSelected(annotationId: string, editable?: boolean): void;
19
+ setSelected(annotationId: string | string[], editable?: boolean): void;
20
20
  updateAnnotation(arg1: string | I, arg2?: I | Origin, arg3?: Origin): void;
21
21
  }
22
22
  export declare const createManifoldInstance: <I extends Annotation = Annotation, E extends {
@@ -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;AAEhF,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU;IAEnH,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAE9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAErD,qBAAqB,CAAC,gBAAgB,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/E,qBAAqB,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/D,KAAK,CAAC,MAAM,EA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AC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEtD,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,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,CA0JlC,CAAA"}
@@ -1,74 +1,80 @@
1
- import { Origin as u } from "@annotorious/react";
2
- const j = (c) => {
3
- const a = (t) => Array.from(c.entries()).reduce((o, [n, r]) => {
4
- if (o)
5
- return o;
6
- const e = r.state.store.getAnnotation(t);
1
+ import { Origin as d } from "@annotorious/react";
2
+ const k = (c) => {
3
+ const i = (t) => Array.from(c.entries()).reduce((e, [n, r]) => {
7
4
  if (e)
8
- return { annotation: e, annotator: r, source: n };
9
- }, void 0) || { annotation: void 0, annotator: void 0, source: void 0 }, l = (t, o = u.LOCAL) => {
10
- const { annotator: n } = a(t.annotation);
11
- n && n.state.store.addBody(t, o);
12
- }, A = (t = u.LOCAL) => Array.from(c.values()).forEach((o) => o.state.store.clear(t)), p = (t, o = u.LOCAL) => {
13
- const r = t.map((s) => typeof s == "string" ? s : s.id).map((s) => {
14
- const { source: i } = a(s);
15
- return { source: i, id: s };
16
- }).filter((s) => s.source), e = Object.groupBy(r, (s) => s.source);
17
- Object.entries(e).forEach(([s, i]) => {
18
- const d = c.get(s);
19
- d && d.state.store.bulkDeleteAnnotations(i.map((f) => f.id), o);
5
+ return e;
6
+ const s = r.state.store.getAnnotation(t);
7
+ if (s)
8
+ return { annotation: s, annotator: r, source: n };
9
+ }, void 0) || { annotation: void 0, annotator: void 0, source: void 0 }, f = (t, e = d.LOCAL) => {
10
+ const { annotator: n } = i(t.annotation);
11
+ n && n.state.store.addBody(t, e);
12
+ }, A = (t = d.LOCAL) => Array.from(c.values()).forEach((e) => e.state.store.clear(t)), p = (t, e = d.LOCAL) => {
13
+ const r = 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), s = Object.groupBy(r, (o) => o.source);
17
+ Object.entries(s).forEach(([o, a]) => {
18
+ const u = c.get(o);
19
+ u && u.state.store.bulkDeleteAnnotations(a.map((l) => l.id), e);
20
20
  });
21
- }, y = (t, o = u.LOCAL) => {
22
- const n = t.map((e) => {
23
- const { source: s } = a(e.id);
24
- return { source: s, annotation: e };
25
- }).filter((e) => e.source), r = Object.groupBy(n, (e) => e.source);
26
- Object.entries(r).forEach(([e, s]) => {
27
- const i = c.get(e);
28
- if (!i) return;
29
- const d = s.map((f) => f.annotation).filter(Boolean);
30
- i.state.store.bulkUpdateAnnotations(d, o);
21
+ }, y = (t, e = d.LOCAL) => {
22
+ const n = t.map((s) => {
23
+ const { source: o } = i(s.id);
24
+ return { source: o, annotation: s };
25
+ }).filter((s) => s.source), r = Object.groupBy(n, (s) => s.source);
26
+ Object.entries(r).forEach(([s, o]) => {
27
+ const a = c.get(s);
28
+ if (!a) return;
29
+ const u = o.map((l) => l.annotation).filter(Boolean);
30
+ a.state.store.bulkUpdateAnnotations(u, e);
31
31
  });
32
- }, L = (t, o = u.LOCAL) => {
33
- const { annotation: n, annotator: r } = a(t);
32
+ }, m = (t, e = d.LOCAL) => {
33
+ const { annotation: n, annotator: r } = i(t);
34
34
  if (r)
35
- return r.state.store.deleteAnnotation(t, o), n;
36
- }, m = (t, o = u.LOCAL) => {
37
- const { annotator: n } = a(t.annotation);
38
- n && n.state.store.deleteBody(t, o);
39
- }, O = () => Array.from(c.values()).forEach((t) => t.destroy()), b = (t) => {
40
- const { annotator: o } = a(t);
41
- return o;
42
- }, v = (t) => {
43
- const { source: o } = a(t);
44
- return o;
45
- }, g = (t) => a(t).annotation, B = () => Array.from(c.values()).reduce((t, o) => [...t, ...o.state.store.all()], []), h = (t) => c.get(t), C = (t, o, n) => {
46
- const r = typeof t == "string" ? t : t.id, { annotator: e } = a(r);
47
- e && e.state.store.updateAnnotation(t, o, n);
48
- }, k = (t, o) => {
49
- const { annotator: n } = a(t);
50
- n && n.setSelected(t, o);
35
+ return r.state.store.deleteAnnotation(t, e), n;
36
+ }, L = (t, e = d.LOCAL) => {
37
+ const { annotator: n } = i(t.annotation);
38
+ n && n.state.store.deleteBody(t, e);
39
+ }, h = () => Array.from(c.values()).forEach((t) => t.destroy()), O = (t) => {
40
+ const { annotator: e } = i(t);
41
+ return e;
42
+ }, b = (t) => {
43
+ const { source: e } = i(t);
44
+ return e;
45
+ }, g = (t) => i(t).annotation, v = () => Array.from(c.values()).reduce((t, e) => [...t, ...e.state.store.all()], []), C = (t) => c.get(t), B = (t, e, n) => {
46
+ const r = typeof t == "string" ? t : t.id, { annotator: s } = i(r);
47
+ s && s.state.store.updateAnnotation(t, e, n);
48
+ }, E = (t, e) => {
49
+ const n = /* @__PURE__ */ new Map();
50
+ (Array.isArray(t) ? t : [t]).forEach((o) => {
51
+ const { source: a } = i(o), u = [...n.get(a) || [], o];
52
+ n.set(a, u);
53
+ }), c.entries().filter(([o, a]) => !n.has(o)).map((o) => o[1]).forEach((o) => o.cancelSelected()), n.entries().forEach(([o, a]) => {
54
+ const u = c.get(o);
55
+ u && u.setSelected(t, e);
56
+ });
51
57
  };
52
58
  return {
53
59
  annotators: [...c.values()],
54
60
  sources: [...c.keys()],
55
- addBody: l,
61
+ addBody: f,
56
62
  bulkDeleteAnnotations: p,
57
63
  bulkUpdateAnnotations: y,
58
64
  clear: A,
59
- deleteAnnotation: L,
60
- deleteBody: m,
61
- destroy: O,
62
- findAnnotator: b,
63
- findSource: v,
65
+ deleteAnnotation: m,
66
+ deleteBody: L,
67
+ destroy: h,
68
+ findAnnotator: O,
69
+ findSource: b,
64
70
  getAnnotation: g,
65
- getAnnotations: B,
66
- getAnnotator: h,
67
- setSelected: k,
68
- updateAnnotation: C
71
+ getAnnotations: v,
72
+ getAnnotator: C,
73
+ setSelected: E,
74
+ updateAnnotation: B
69
75
  };
70
76
  };
71
77
  export {
72
- j as createManifoldInstance
78
+ k as createManifoldInstance
73
79
  };
74
80
  //# 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, 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, editable?: boolean) => {\n const { annotator } = find(id);\n if (annotator)\n annotator.setSelected(id, editable);\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"],"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,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ACrBD,EAAKC,CAAY,EAAE,YAEf6B,IAAiB,MACrB,MAAM,KAAK/B,EAAW,OAAA,CAAQ,EAAE,OAAO,CAACgC,GAAK3B,MAC3C,CAAC,GAAG2B,GAAK,GAAG3B,EAAU,MAAM,MAAM,KAAK,GAAG,EAAS,GAEjD4B,IAAe,CAAChB,MAAejB,EAAW,IAAIiB,CAAE,GAEhDiB,IAAmB,CAACC,GAAkBC,GAAmBC,MAAkB;AAC/E,UAAMC,IAAgB,OAAOH,KAAS,WAAWA,IAAOA,EAAK,IAEvD,EAAE,WAAA9B,EAAA,IAAcJ,EAAKqC,CAAK;AAChC,IAAIjC,KACFA,EAAU,MAAM,MAAM,iBAAiB8B,GAAMC,GAAMC,CAAI;AAAA,EAC3D,GAEME,IAAc,CAACtB,GAAYuB,MAAuB;AACtD,UAAM,EAAE,WAAAnC,EAAA,IAAcJ,EAAKgB,CAAE;AAC7B,IAAIZ,KACFA,EAAU,YAAYY,GAAIuB,CAAQ;AAAA,EACtC;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 } 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(id, 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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AA,IACA,cAAAE;AAAA,IACA,aAAAM;AAAA,IACA,kBAAAL;AAAA,EAAA;AAGJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/react-manifold",
3
- "version": "3.7.16",
3
+ "version": "3.7.17",
4
4
  "description": "A utility to manage multiple parallel Annotorious instances more efficiently",
5
5
  "author": "Rainer Simon",
6
6
  "license": "BSD-3-Clause",
@@ -40,7 +40,7 @@
40
40
  "vite-tsconfig-paths": "^5.1.4"
41
41
  },
42
42
  "peerDependencies": {
43
- "@annotorious/react": "3.7.16",
43
+ "@annotorious/react": "3.7.17",
44
44
  "openseadragon": ">= ^4.0.0 || >= ^5.0.0",
45
45
  "react": "^16.8.0 || >= ^17.x || >= ^18.x || >= ^19.x",
46
46
  "react-dom": "^16.8.0 || >= ^17.x || >= ^18.x|| >= ^19.x"