@annotorious/react-manifold 3.7.3 → 3.7.5

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.
@@ -12,17 +12,19 @@ interface AnnotoriousManifoldContextValue {
12
12
  }>): () => void;
13
13
  }
14
14
  interface ManifoldSelection<T extends Annotation = Annotation> {
15
- id?: string;
16
15
  selected: {
17
16
  annotation: T;
18
17
  editable?: boolean;
18
+ annotatorId: string;
19
19
  }[];
20
20
  event?: PointerEvent | KeyboardEvent;
21
21
  }
22
22
  export declare const AnnotoriousManifoldContext: import('react').Context<AnnotoriousManifoldContextValue>;
23
- export declare const AnnotoriousManifold: (props: {
23
+ export interface AnnotoriousManifoldProps {
24
+ crossAnnotatorSelect?: true;
24
25
  children: ReactNode;
25
- }) => import("react/jsx-runtime").JSX.Element;
26
+ }
27
+ export declare const AnnotoriousManifold: (props: AnnotoriousManifoldProps) => import("react/jsx-runtime").JSX.Element;
26
28
  export declare const useAnnotoriousManifold: <I extends Annotation = Annotation, E extends {
27
29
  id: string;
28
30
  } = Annotation>() => AnnotoriousManifoldInstance<I, E>;
@@ -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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AI,CAAC,SAAS,UAAU,uBAIlD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,UAAU,2BAIhD,CAAA"}
@@ -1,62 +1,79 @@
1
- import { jsx as I } from "react/jsx-runtime";
2
- import { createContext as O, useState as x, useRef as P, useEffect as R, useContext as f } from "react";
3
- import { createManifoldInstance as k } from "./annotorious-react-manifold.es8.js";
4
- const a = O(), D = (t) => {
5
- const [i, M] = x(/* @__PURE__ */ new Map()), [g, d] = x(/* @__PURE__ */ new Map()), [l, S] = x({ selected: [] }), p = P(!1), C = (n, r) => {
6
- M((e) => new Map(e.entries()).set(n, r));
7
- const { store: o } = r.state, y = r.state.selection;
8
- d((e) => new Map(e.entries()).set(n, o.all()));
9
- const b = () => d((e) => new Map(e.entries()).set(n, o.all()));
10
- o.observe(b);
11
- let u;
12
- const E = y.subscribe(({ selected: e, event: s }) => {
13
- u && o.unobserve(u);
14
- const m = (e || []).map(({ id: c, editable: A }) => ({ annotation: o.getAnnotation(c), editable: A }));
15
- p.current || S({ id: n, selected: m, event: s }), u = (c) => {
16
- const { updated: A } = c.changes;
17
- S(({ id: V, selected: _ }) => ({
18
- id: V,
19
- selected: _.map(({ annotation: v, editable: w }) => {
20
- const h = A.find((j) => j.oldValue.id === v.id);
21
- return h ? { annotation: h.newValue, editable: w } : { annotation: v, editable: w };
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";
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);
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 }) => ({
34
+ 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;
22
38
  }),
23
- event: s
39
+ event: t
24
40
  }));
25
- }, o.observe(u, { annotations: e.map(({ id: c }) => c) });
41
+ }, r.observe(n, { annotations: o.map(({ id: a }) => a) });
26
42
  });
27
43
  return () => {
28
- M((e) => new Map(Array.from(e.entries()).filter(([s, m]) => s !== n))), d((e) => new Map(Array.from(e.entries()).filter(([s, m]) => s !== n))), o.unobserve(b), E();
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();
29
45
  };
30
46
  };
31
- return R(() => {
32
- l.id && (p.current = !0, Array.from(i.entries()).forEach(([n, r]) => {
33
- n !== l.id && r.setSelected();
34
- }), p.current = !1);
35
- }, [l, i]), /* @__PURE__ */ I(a.Provider, { value: {
36
- annotators: i,
37
- annotations: g,
38
- selection: l,
39
- connectAnnotator: C
40
- }, children: t.children });
41
- }, F = () => {
42
- const t = f(a);
43
- if (t)
44
- return k(t.annotators);
45
- }, G = (t) => f(a).annotators.get(t), H = () => {
46
- const t = f(a);
47
- if (t)
48
- return t.annotations;
49
- }, J = () => {
50
- const t = f(a);
51
- if (t)
52
- return t.selection;
47
+ 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
57
+ }, children: e.children });
58
+ }, B = () => {
59
+ const e = m(f);
60
+ if (e)
61
+ return j(e.annotators);
62
+ }, D = (e) => m(f).annotators.get(e), F = () => {
63
+ const e = m(f);
64
+ if (e)
65
+ return e.annotations;
66
+ }, G = () => {
67
+ const e = m(f);
68
+ if (e)
69
+ return e.selection;
53
70
  };
54
71
  export {
55
- D as AnnotoriousManifold,
56
- a as AnnotoriousManifoldContext,
57
- H as useAnnotations,
58
- G as useAnnotator,
59
- F as useAnnotoriousManifold,
60
- J as useSelection
72
+ k as AnnotoriousManifold,
73
+ f as AnnotoriousManifoldContext,
74
+ F as useAnnotations,
75
+ D as useAnnotator,
76
+ B as useAnnotoriousManifold,
77
+ G as useSelection
61
78
  };
62
79
  //# sourceMappingURL=annotorious-react-manifold.es7.js.map
@@ -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 id?: string;\n\n selected: { annotation: T, editable?: boolean }[],\n\n event?: PointerEvent | KeyboardEvent;\n\n}\n\n// @ts-ignore\nexport const AnnotoriousManifoldContext = createContext<AnnotoriousManifoldContextValue>();\n\nexport const AnnotoriousManifold = (props: { children: ReactNode }) => {\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(({ id, editable }) => ({ annotation: store.getAnnotation(id), editable }));\n\n // Set the new selection\n if (!muteSelectionEvents.current)\n setSelection({ id, selected: resolved, event });\n\n // Track the state of the selected annotations in the store\n selectionStoreObserver = e => {\n const { updated } = e.changes;\n\n setSelection(({ id, selected }) => ({\n id,\n selected: selected.map(({ annotation, editable }) => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? { annotation: next.newValue, editable } : { annotation, editable };\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 if (selection.id) {\n muteSelectionEvents.current = true;\n\n Array.from(annotators.entries()).forEach(([source, anno]) => {\n if (source !== selection.id)\n anno.setSelected();\n });\n\n muteSelectionEvents.current = false;\n }\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","editable","e","updated","annotation","next","u","key","_","useEffect","source","jsx","useAnnotoriousMan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AI;AAAA,EAAA,GAEC,YAAM,UACT;AAGJ,GAEauB,IAAyB,MAAgF;AACpH,QAAMC,IAAMC,EAAWtC,CAA0B;AACjD,MAAIqC;AACF,WAAOE,EAAuBF,EAAI,UAAU;AAChD,GAEaG,IAAe,CAA2E1B,MACzFwB,EAAWtC,CAA0B,EACpC,WAAW,IAAIc,CAAE,GAGnB2B,IAAiB,MAA4B;AACxD,QAAMJ,IAAMC,EAAWtC,CAA0B;AACjD,MAAIqC;AACF,WAAOA,EAAI;AACf,GAEaK,IAAe,MAA4B;AACtD,QAAML,IAAMC,EAAWtC,CAA0B;AACjD,MAAIqC;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 } 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","createManifo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CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/react-manifold",
3
- "version": "3.7.3",
3
+ "version": "3.7.5",
4
4
  "description": "A utility to manage multiple parallel Annotorious instances more efficiently",
5
5
  "author": "Rainer Simon",
6
6
  "license": "BSD-3-Clause",
@@ -31,16 +31,16 @@
31
31
  "test": "echo 'Skipping tests in @annotorious/annotorious-react-manifold package'"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/react": "^19.1.10",
35
- "@types/react-dom": "^19.1.7",
34
+ "@types/react": "^19.1.12",
35
+ "@types/react-dom": "^19.1.9",
36
36
  "@vitejs/plugin-react": "^4.7.0",
37
37
  "typescript": "^5.9.2",
38
- "vite": "^5.4.19",
38
+ "vite": "^5.4.20",
39
39
  "vite-plugin-dts": "^4.5.4",
40
40
  "vite-tsconfig-paths": "^5.1.4"
41
41
  },
42
42
  "peerDependencies": {
43
- "@annotorious/react": "3.7.3",
43
+ "@annotorious/react": "3.7.5",
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"