@annotorious/react-manifold 3.7.5 → 3.7.7

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 +1 @@
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,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,2BAA2B,EAA0B,MAAM,+BAA+B,CAAC;AAEpG,UAAU,+BAA+B;IAEvC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IAExD,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;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,MAAM,IAAI,CAAC;CAEpF;AAED,UAAU,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAE3D,QAAQ,EAAE;QAAE,UAAU,EAAE,CAAC,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAEvE,KAAK,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;CAEtC;AAGD,eAAO,MAAM,0BAA0B,0DAAmD,CAAC;AAE3F,MAAM,WAAW,wBAAwB;IAEvC,oBAAoB,CAAC,EAAE,IAAI,CAAC;IAE5B,QAAQ,EAAE,SAAS,CAAC;CAErB;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO,wBAAwB,4CA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,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAEvE,KAAK,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;CAEtC;AAGD,eAAO,MAAM,0BAA0B,0DAAmD,CAAC;AAE3F,MAAM,WAAW,wBAAwB;IAEvC,oBAAoB,CAAC,EAAE,IAAI,CAAC;IAE5B,QAAQ,EAAE,SAAS,CAAC;CAErB;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO,wBAAwB,4CAwKlE,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,wCAI9G,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,EAAE,IAAI,MAAM,KAE5E,SAAS,CAAC,CAAC,EAAE,CAAC,CAClD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,UAAU,uBAIlD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,UAAU,2BAIhD,CAAA"}
@@ -1,76 +1,73 @@
1
1
  import { jsx as q } from "react/jsx-runtime";
2
- import { createContext as z, useState as h, useRef as V, useEffect as _, useContext as m } from "react";
2
+ import { createContext as z, useState as y, useRef as V, useEffect as _, useContext as b } from "react";
3
3
  import { createManifoldInstance as j } from "./annotorious-react-manifold.es8.js";
4
- const f = z(), k = (e) => {
5
- const [S, y] = h(/* @__PURE__ */ new Map()), [I, A] = h(/* @__PURE__ */ new Map()), [b, u] = h({ selected: [] }), p = V(!1), E = (s, c) => {
6
- y((o) => new Map(o.entries()).set(s, c));
7
- const { store: r } = c.state, d = c.state.selection;
8
- A((o) => new Map(o.entries()).set(s, r.all()));
9
- const x = () => A((o) => new Map(o.entries()).set(s, r.all()));
10
- r.observe(x);
4
+ const m = z(), R = (e) => {
5
+ const [A, g] = y(/* @__PURE__ */ new Map()), [E, w] = y(/* @__PURE__ */ new Map()), [x, u] = y({ selected: [] }), f = V(!1), K = (s, c) => {
6
+ g((o) => new Map(o.entries()).set(s, c));
7
+ const { store: i } = c.state, a = c.state.selection;
8
+ w((o) => new Map(o.entries()).set(s, i.all()));
9
+ const h = () => w((o) => new Map(o.entries()).set(s, i.all()));
10
+ i.observe(h);
11
11
  let n;
12
- const C = d.subscribe(({ selected: o, event: t }) => {
13
- n && r.unobserve(n);
14
- const i = (o || []).map((a) => ({ annotation: r.getAnnotation(a.id), editable: a.editable, annotatorId: s }));
15
- if (!p.current)
16
- if (e.crossAnnotatorSelect)
17
- if (i.length === 0)
18
- u({ selected: [], event: t });
19
- else {
20
- const a = (t == null ? void 0 : t.ctrlKey) || (t == null ? void 0 : t.metaKey) || (t == null ? void 0 : t.shiftKey);
21
- u(a ? (M) => {
22
- const w = M.selected.filter((l) => l.annotatorId !== s);
23
- return {
24
- selected: [...i, ...w],
25
- event: t
26
- };
27
- } : { selected: i, event: t });
28
- }
29
- else
30
- u({ selected: i, event: t });
31
- n = (a) => {
32
- const { updated: M } = a.changes;
33
- u(({ selected: w }) => ({
12
+ const C = a.subscribe(({ selected: o, event: t }) => {
13
+ n && i.unobserve(n);
14
+ const l = (o || []).map((r) => ({ annotation: i.getAnnotation(r.id), editable: r.editable, annotatorId: s }));
15
+ if (!f.current) {
16
+ const r = (t == null ? void 0 : t.ctrlKey) || (t == null ? void 0 : t.metaKey) || (t == null ? void 0 : t.shiftKey);
17
+ e.crossAnnotatorSelect ? l.length === 0 && !r ? u({ selected: [], event: t }) : u(r ? (S) => {
18
+ const p = S.selected.filter((d) => d.annotatorId !== s);
19
+ return {
20
+ selected: [...l, ...p],
21
+ event: t
22
+ };
23
+ } : { selected: l, event: t }) : u({ selected: l, event: t });
24
+ }
25
+ n = (r) => {
26
+ const { updated: S } = r.changes;
27
+ u(({ selected: p }) => ({
34
28
  id: e.crossAnnotatorSelect ? void 0 : s,
35
- selected: w.map((l) => {
36
- const g = M.find((K) => K.oldValue.id === l.annotation.id);
37
- return g ? { annotation: g.newValue, editable: l.editable, annotatorId: l.annotatorId } : l;
29
+ selected: p.map((d) => {
30
+ const I = S.find((k) => k.oldValue.id === d.annotation.id);
31
+ return I ? { annotation: I.newValue, editable: d.editable, annotatorId: d.annotatorId } : d;
38
32
  }),
39
33
  event: t
40
34
  }));
41
- }, r.observe(n, { annotations: o.map(({ id: a }) => a) });
35
+ }, i.observe(n, { annotations: o.map(({ id: r }) => r) });
42
36
  });
43
- return () => {
44
- y((o) => new Map(Array.from(o.entries()).filter(([t, i]) => t !== s))), A((o) => new Map(Array.from(o.entries()).filter(([t, i]) => t !== s))), r.unobserve(x), C();
37
+ let M;
38
+ return e.crossAnnotatorSelect && (M = (o, t) => {
39
+ (t != null && t.ctrlKey || t != null && t.metaKey || t != null && t.shiftKey) && a.selected.length === 1 && a.selected[0].id === o.id && (f.current = !0, a.clear(), u((r) => ({ selected: r.selected.filter((S) => S.annotatorId !== s), event: t })), f.current = !1, "viewer" in c && c.viewer.setMouseNavEnabled(!0));
40
+ }, c.on("clickAnnotation", M)), () => {
41
+ g((o) => new Map(Array.from(o.entries()).filter(([t, l]) => t !== s))), w((o) => new Map(Array.from(o.entries()).filter(([t, l]) => t !== s))), i.unobserve(h), C(), M && c.off("clickAnnotation", M);
45
42
  };
46
43
  };
47
44
  return _(() => {
48
- p.current = !0, Array.from(S.entries()).forEach(([s, c]) => {
49
- const r = new Set(c.getSelected().map((n) => n.id)), d = new Set(b.selected.filter((n) => n.annotatorId === s).map((n) => n.annotation.id));
50
- r.size === d.size && [...r].every((n) => d.has(n)) || c.setSelected([...d]);
51
- }), p.current = !1;
52
- }, [b, S]), /* @__PURE__ */ q(f.Provider, { value: {
53
- annotators: S,
54
- annotations: I,
55
- selection: b,
56
- connectAnnotator: E
45
+ f.current || (f.current = !0, Array.from(A.entries()).forEach(([s, c]) => {
46
+ const i = new Set(c.getSelected().map((n) => n.id)), a = new Set(x.selected.filter((n) => n.annotatorId === s).map((n) => n.annotation.id));
47
+ i.size === a.size && [...i].every((n) => a.has(n)) || c.setSelected([...a]);
48
+ }), f.current = !1);
49
+ }, [x, A]), /* @__PURE__ */ q(m.Provider, { value: {
50
+ annotators: A,
51
+ annotations: E,
52
+ selection: x,
53
+ connectAnnotator: K
57
54
  }, children: e.children });
58
55
  }, B = () => {
59
- const e = m(f);
56
+ const e = b(m);
60
57
  if (e)
61
58
  return j(e.annotators);
62
- }, D = (e) => m(f).annotators.get(e), F = () => {
63
- const e = m(f);
59
+ }, D = (e) => b(m).annotators.get(e), F = () => {
60
+ const e = b(m);
64
61
  if (e)
65
62
  return e.annotations;
66
63
  }, G = () => {
67
- const e = m(f);
64
+ const e = b(m);
68
65
  if (e)
69
66
  return e.selection;
70
67
  };
71
68
  export {
72
- k as AnnotoriousManifold,
73
- f as AnnotoriousManifoldContext,
69
+ R as AnnotoriousManifold,
70
+ m as AnnotoriousManifoldContext,
74
71
  F as useAnnotations,
75
72
  D as useAnnotator,
76
73
  B as useAnnotoriousManifold,
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react-manifold.es7.js","sources":["../src/AnnotoriousManifold.tsx"],"sourcesContent":["import { ReactNode, createContext, useContext, useEffect, useRef, useState } from 'react';\nimport type { Annotation, Annotator } from '@annotorious/react';\nimport type { StoreChangeEvent } from '@annotorious/react';\nimport { AnnotoriousManifoldInstance, createManifoldInstance } from './AnnotoriousManifoldInstance';\n\ninterface AnnotoriousManifoldContextValue {\n\n annotators: Map<string, Annotator<any, { id: string }>>;\n\n annotations: Map<string, Annotation[]>;\n\n selection: ManifoldSelection;\n\n connectAnnotator(source: string, anno: Annotator<any, { id: string }>): () => void;\n\n}\n\ninterface ManifoldSelection<T extends Annotation = Annotation> {\n\n selected: { annotation: T, editable?: boolean, annotatorId: string }[],\n\n event?: PointerEvent | KeyboardEvent;\n\n}\n\n// @ts-ignore\nexport const AnnotoriousManifoldContext = createContext<AnnotoriousManifoldContextValue>();\n\nexport interface AnnotoriousManifoldProps {\n\n crossAnnotatorSelect?: true;\n\n children: ReactNode;\n\n}\n\nexport const AnnotoriousManifold = (props: AnnotoriousManifoldProps) => {\n\n const [annotators, setAnnotators] = useState<Map<string, Annotator<any, { id: string }>>>(new Map());\n\n const [annotations, setAnnotations] = useState<Map<string, Annotation[]>>(new Map());\n\n const [selection, setSelection] = \n useState<ManifoldSelection>({ selected: [] });\n\n // To prevent selection state updates when de-selecting other annotators\n const muteSelectionEvents = useRef<boolean>(false);\n\n const connectAnnotator = (id: string, anno: Annotator<any, { id: string }>) => {\n // Add the annotator to the state\n setAnnotators(m => new Map(m.entries()).set(id, anno))\n\n const { store } = anno.state;\n\n const selectionState = anno.state.selection;\n\n // Add the annotations to the state\n setAnnotations(m => new Map(m.entries()).set(id, store.all()));\n\n const onStoreChange = () =>\n setAnnotations(m => new Map(m.entries()).set(id, store.all()));\n\n store.observe(onStoreChange);\n\n // Track selection\n let selectionStoreObserver: (event: StoreChangeEvent<Annotation>) => void;\n\n const unsubscribeSelection = selectionState.subscribe(({ selected, event }) => {\n if (selectionStoreObserver) \n store.unobserve(selectionStoreObserver);\n\n const resolved = (selected || [])\n .map(t => ({ annotation: store.getAnnotation(t.id), editable: t.editable, annotatorId: id }));\n\n // Set the new selection\n if (!muteSelectionEvents.current) {\n if (props.crossAnnotatorSelect) {\n if (resolved.length === 0) {\n setSelection({ selected: [], event });\n } else {\n const isMultiSelect = event?.ctrlKey || event?.metaKey || event?.shiftKey;\n if (isMultiSelect) {\n setSelection(current => {\n const other = current.selected.filter(s => s.annotatorId !== id);\n return {\n selected: [...resolved, ...other],\n event\n };\n })\n } else {\n setSelection({ selected: resolved, event });\n }\n }\n } else {\n setSelection({ selected: resolved, event });\n }\n }\n\n // Track the state of the selected annotations in the store\n selectionStoreObserver = e => {\n const { updated } = e.changes;\n\n setSelection(({ selected }) => ({\n id: props.crossAnnotatorSelect ? undefined : id,\n selected: selected.map(s => {\n const next = updated.find(u => u.oldValue.id === s.annotation.id);\n return next ? { annotation: next.newValue, editable: s.editable, annotatorId: s.annotatorId } : s; \n }),\n event\n }));\n }\n\n store.observe(selectionStoreObserver, { annotations: selected.map(({ id }) => id) });\n });\n\n return () => {\n // Remove annotator\n setAnnotators(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== id)));\n\n // Remove & untrack annotations\n setAnnotations(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== id)));\n store.unobserve(onStoreChange);\n\n // Un-track selection\n unsubscribeSelection();\n }\n }\n\n useEffect(() => {\n muteSelectionEvents.current = true;\n\n Array.from(annotators.entries()).forEach(([source, anno]) => {\n const currentSelection = new Set(anno.getSelected().map(s => s.id));\n\n const nextSelection = new Set(selection.selected\n .filter(s => s.annotatorId === source)\n .map(s => s.annotation.id));\n\n const isEqual = currentSelection.size === nextSelection.size &&\n [...currentSelection].every(id => nextSelection.has(id));\n\n if (!isEqual)\n anno.setSelected([...nextSelection]);\n });\n\n muteSelectionEvents.current = false;\n }, [selection, annotators]);\n\n return (\n <AnnotoriousManifoldContext.Provider value={{ \n annotators, \n annotations,\n selection,\n connectAnnotator \n }}>\n {props.children}\n </AnnotoriousManifoldContext.Provider>\n )\n\n}\n\nexport const useAnnotoriousManifold = <I extends Annotation = Annotation, E extends { id: string } = Annotation>() => {\n const ctx = useContext(AnnotoriousManifoldContext);\n if (ctx)\n return createManifoldInstance(ctx.annotators) as AnnotoriousManifoldInstance<I, E>;\n}\n\nexport const useAnnotator = <I extends Annotation = Annotation, E extends { id: string } = Annotation>(id: string) => {\n const ctx = useContext(AnnotoriousManifoldContext);\n return ctx.annotators.get(id) as Annotator<I, E>;\n}\n\nexport const useAnnotations = <T extends Annotation>() => {\n const ctx = useContext(AnnotoriousManifoldContext);\n if (ctx)\n return ctx.annotations as Map<string, T[]>;\n}\n\nexport const useSelection = <T extends Annotation>() => {\n const ctx = useContext(AnnotoriousManifoldContext);\n if (ctx)\n return ctx.selection as ManifoldSelection<T>;\n}\n"],"names":["AnnotoriousManifoldContext","createContext","AnnotoriousManifold","props","annotators","setAnnotators","useState","annotations","setAnnotations","selection","setSelection","muteSelectionEvents","useRef","connectAnnotator","id","anno","m","store","selectionState","onStoreChange","selectionStoreObserver","unsubscribeSelection","selected","event","resolved","t","isMultiSelect","current","other","s","e","updated","next","u","key","_","useEffect","source","currentSelection","nextSelection","jsx","useAnnotoriousManifold","ctx","useContext","createManifoldInstance","useAnnotator","useAnnotations","useSelection"],"mappings":";;;AA0BO,MAAMA,IAA6BC,EAAA,GAU7BC,IAAsB,CAACC,MAAoC;AAEtE,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAsD,oBAAI,KAAK,GAE7F,CAACC,GAAaC,CAAc,IAAIF,EAAoC,oBAAI,KAAK,GAE7E,CAACG,GAAWC,CAAY,IAC5BJ,EAA4B,EAAE,UAAU,CAAA,GAAI,GAGxCK,IAAsBC,EAAgB,EAAK,GAE3CC,IAAmB,CAACC,GAAYC,MAAyC;AAE7E,IAAAV,EAAc,CAAAW,MAAK,IAAI,IAAIA,EAAE,QAAA,CAAS,EAAE,IAAIF,GAAIC,CAAI,CAAC;AAErD,UAAM,EAAE,OAAAE,MAAUF,EAAK,OAEjBG,IAAiBH,EAAK,MAAM;AAGlC,IAAAP,EAAe,CAAAQ,MAAK,IAAI,IAAIA,EAAE,SAAS,EAAE,IAAIF,GAAIG,EAAM,IAAA,CAAK,CAAC;AAE7D,UAAME,IAAgB,MACpBX,EAAe,CAAAQ,MAAK,IAAI,IAAIA,EAAE,QAAA,CAAS,EAAE,IAAIF,GAAIG,EAAM,IAAA,CAAK,CAAC;AAE/D,IAAAA,EAAM,QAAQE,CAAa;AAG3B,QAAIC;AAEJ,UAAMC,IAAuBH,EAAe,UAAU,CAAC,EAAE,UAAAI,GAAU,OAAAC,QAAY;AAC7E,MAAIH,KACFH,EAAM,U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C,EAAW3C,CAA0B;AACjD,MAAI0C;AACF,WAAOE,EAAuBF,EAAI,UAAU;AAChD,GAEaG,IAAe,CAA2E/B,MACzF6B,EAAW3C,CAA0B,EACpC,WAAW,IAAIc,CAAE,GAGnBgC,IAAiB,MAA4B;AACxD,QAAMJ,IAAMC,EAAW3C,CAA0B;AACjD,MAAI0C;AACF,WAAOA,EAAI;AACf,GAEaK,IAAe,MAA4B;AACtD,QAAML,IAAMC,EAAW3C,CAA0B;AACjD,MAAI0C;AACF,WAAOA,EAAI;AACf;"}
1
+ {"version":3,"file":"annotorious-react-manifold.es7.js","sources":["../src/AnnotoriousManifold.tsx"],"sourcesContent":["import { ReactNode, createContext, useContext, useEffect, useRef, useState } from 'react';\nimport type { Annotation, Annotator, AnnotoriousOpenSeadragonAnnotator } from '@annotorious/react';\nimport type { StoreChangeEvent } from '@annotorious/react';\nimport { AnnotoriousManifoldInstance, createManifoldInstance } from './AnnotoriousManifoldInstance';\n\ninterface AnnotoriousManifoldContextValue {\n\n annotators: Map<string, Annotator<any, { id: string }>>;\n\n annotations: Map<string, Annotation[]>;\n\n selection: ManifoldSelection;\n\n connectAnnotator(source: string, anno: Annotator<any, { id: string }>): () => void;\n\n}\n\ninterface ManifoldSelection<T extends Annotation = Annotation> {\n\n selected: { annotation: T, editable?: boolean, annotatorId: string }[],\n\n event?: PointerEvent | KeyboardEvent;\n\n}\n\n// @ts-ignore\nexport const AnnotoriousManifoldContext = createContext<AnnotoriousManifoldContextValue>();\n\nexport interface AnnotoriousManifoldProps {\n\n crossAnnotatorSelect?: true;\n\n children: ReactNode;\n\n}\n\nexport const AnnotoriousManifold = (props: AnnotoriousManifoldProps) => {\n\n const [annotators, setAnnotators] = useState<Map<string, Annotator<any, { id: string }>>>(new Map());\n\n const [annotations, setAnnotations] = useState<Map<string, Annotation[]>>(new Map());\n\n const [selection, setSelection] = \n useState<ManifoldSelection>({ selected: [] });\n\n // To prevent selection state updates when de-selecting other annotators\n const muteSelectionEvents = useRef<boolean>(false);\n\n const connectAnnotator = (id: string, anno: Annotator<any, { id: string }>) => {\n // Add the annotator to the state\n setAnnotators(m => new Map(m.entries()).set(id, anno))\n\n const { store } = anno.state;\n\n const selectionState = anno.state.selection;\n\n // Add the annotations to the state\n setAnnotations(m => new Map(m.entries()).set(id, store.all()));\n\n const onStoreChange = () =>\n setAnnotations(m => new Map(m.entries()).set(id, store.all()));\n\n store.observe(onStoreChange);\n\n // Track selection\n let selectionStoreObserver: (event: StoreChangeEvent<Annotation>) => void;\n\n const unsubscribeSelection = selectionState.subscribe(({ selected, event }) => {\n if (selectionStoreObserver) \n store.unobserve(selectionStoreObserver);\n\n const resolved = (selected || [])\n .map(t => ({ annotation: store.getAnnotation(t.id), editable: t.editable, annotatorId: id }));\n\n // Set the new selection\n if (!muteSelectionEvents.current) {\n const isMultiSelect = event?.ctrlKey || event?.metaKey || event?.shiftKey; \n if (props.crossAnnotatorSelect) {\n if (resolved.length === 0 && !isMultiSelect) {\n // When crossAnnotatorSelect is enabled, clearing the selection in one image\n // clears everything\n setSelection({ selected: [], event });\n } else {\n // If this is CMD/CTRL/SHIFT-select, modify the global selection instead\n // of replacing it.\n if (isMultiSelect) {\n setSelection(current => {\n const other = current.selected.filter(s => s.annotatorId !== id);\n return {\n selected: [...resolved, ...other],\n event\n };\n });\n } else {\n setSelection({ selected: resolved, event });\n }\n }\n } else {\n setSelection({ selected: resolved, event });\n }\n }\n\n // Track the state of the selected annotations in the store\n selectionStoreObserver = e => {\n const { updated } = e.changes;\n\n setSelection(({ selected }) => ({\n id: props.crossAnnotatorSelect ? undefined : id,\n selected: selected.map(s => {\n const next = updated.find(u => u.oldValue.id === s.annotation.id);\n return next ? { annotation: next.newValue, editable: s.editable, annotatorId: s.annotatorId } : s; \n }),\n event\n }));\n }\n\n store.observe(selectionStoreObserver, { annotations: selected.map(({ id }) => id) });\n });\n\n // Edge case: if crossAnnotatorSelect is enabled, track the click event, so we can\n // toggle a single selected shape.\n let onClick: (annotation: { id: string}, event: PointerEvent) => void;\n\n if (props.crossAnnotatorSelect) {\n onClick = (annotation, event) => {\n // Nothing to do unless this is a CMD + click\n const isMultiSelect = event?.ctrlKey || event?.metaKey || event?.shiftKey;\n if (!isMultiSelect) return;\n\n // Nothing to do if there is no selection, or more than 1 – default\n // annotator selection behavior will handle everything correctly.\n if (selectionState.selected.length !== 1) return;\n\n // Only a single annotation selected? Nothing to do if it's not the selected one.\n if (selectionState.selected[0].id !== annotation.id) return;\n\n // Edge case: one selected annotation and the user CMD + clicked it - deselect!\n muteSelectionEvents.current = true;\n selectionState.clear();\n setSelection(current => ({ selected: current.selected.filter(t => t.annotatorId !== id), event }));\n muteSelectionEvents.current = false;\n\n // Special patching required for OSD: the click will have triggered a 'grab' event on the \n // shape in SVGDrawingLayer. This disables the OSD viewer navigation. (Because otherwise the \n // viewer would move along with the shape!) Normally, releasing the shape will re-enable viewer \n // navigation. HOWEVER: in this case, we clear the selection programmatically, which destroys \n // the editor shape before the 'release' event can trigger.\n // Therefore, we're re-enabling the viewer nav manually here!\n if ('viewer' in anno)\n (anno as AnnotoriousOpenSeadragonAnnotator).viewer.setMouseNavEnabled(true)\n }\n\n anno.on('clickAnnotation', onClick);\n }\n\n return () => {\n // Remove annotator\n setAnnotators(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== id)));\n\n // Remove & untrack annotations\n setAnnotations(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== id)));\n store.unobserve(onStoreChange);\n\n // Un-track selection\n unsubscribeSelection();\n\n // Un-track click\n if (onClick)\n anno.off('clickAnnotation', onClick);\n }\n }\n\n useEffect(() => {\n if (muteSelectionEvents.current) return;\n muteSelectionEvents.current = true;\n\n Array.from(annotators.entries()).forEach(([source, anno]) => {\n const currentSelection = new Set(anno.getSelected().map(s => s.id));\n\n const nextSelection = new Set(selection.selected\n .filter(s => s.annotatorId === source)\n .map(s => s.annotation.id));\n\n const isEqual = currentSelection.size === nextSelection.size &&\n [...currentSelection].every(id => nextSelection.has(id));\n\n if (!isEqual)\n anno.setSelected([...nextSelection]);\n });\n\n muteSelectionEvents.current = false;\n }, [selection, annotators]);\n\n return (\n <AnnotoriousManifoldContext.Provider value={{ \n annotators, \n annotations,\n selection,\n connectAnnotator \n }}>\n {props.children}\n </AnnotoriousManifoldContext.Provider>\n )\n\n}\n\nexport const useAnnotoriousManifold = <I extends Annotation = Annotation, E extends { id: string } = Annotation>() => {\n const ctx = useContext(AnnotoriousManifoldContext);\n if (ctx)\n return createManifoldInstance(ctx.annotators) as AnnotoriousManifoldInstance<I, E>;\n}\n\nexport const useAnnotator = <I extends Annotation = Annotation, E extends { id: string } = Annotation>(id: string) => {\n const ctx = useContext(AnnotoriousManifoldContext);\n return ctx.annotators.get(id) as Annotator<I, E>;\n}\n\nexport const useAnnotations = <T extends Annotation>() => {\n const ctx = useContext(AnnotoriousManifoldContext);\n if (ctx)\n return ctx.annotations as Map<string, T[]>;\n}\n\nexport const useSelection = <T extends Annotation>() => {\n const ctx = useContext(AnnotoriousManifoldContext);\n if (ctx)\n return ctx.selection as ManifoldSelection<T>;\n}\n"],"names":["AnnotoriousManifoldContext","createContext","AnnotoriousManifold","props","annotators","setAnnotators","useState","annotations","setAnnotations","selection","setSelection","muteSelectionEvents","useRef","connectAnnotator","id","anno","m","store","selectionState","onStoreChange","selectionStoreObserver","unsubscribeSelection","selected","event","resolved","t","isMultiSelect","current","other","s","e","updated","next","u","onClick","annotation","key","_","useEffect","source","currentSelection","nextSelection","jsx","useAnnotoriousManifold","ctx","useContext","createManifoldInstance","useAnnotator","useAnnotations","useSelection"],"mappings":";;;AA0BO,MAAMA,IAA6BC,EAAA,GAU7BC,IAAsB,CAACC,MAAoC;AAEtE,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAsD,oBAAI,KAAK,GAE7F,CAACC,GAAaC,CAAc,IAAIF,EAAoC,oBAAI,KAAK,GAE7E,CAACG,GAAWC,CAAY,IAC5BJ,EAA4B,EAAE,UAAU,CAAA,GAAI,GAG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G,IAAe,CAA2EjC,MACzF+B,EAAW7C,CAA0B,EACpC,WAAW,IAAIc,CAAE,GAGnBkC,IAAiB,MAA4B;AACxD,QAAMJ,IAAMC,EAAW7C,CAA0B;AACjD,MAAI4C;AACF,WAAOA,EAAI;AACf,GAEaK,IAAe,MAA4B;AACtD,QAAML,IAAMC,EAAW7C,CAA0B;AACjD,MAAI4C;AACF,WAAOA,EAAI;AACf;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/react-manifold",
3
- "version": "3.7.5",
3
+ "version": "3.7.7",
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.5",
43
+ "@annotorious/react": "3.7.7",
44
44
  "openseadragon": "^5.0.1",
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"