@annotorious/react-manifold 0.0.6 → 0.0.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,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import type { Annotation, Annotator } from '@annotorious/core';
2
+ import type { Annotation, Annotator } from '@annotorious/core/src';
3
3
  import { AnnotoriousManifoldInstance } from './AnnotoriousManifoldInstance';
4
4
  interface AnnotoriousManifoldContextValue {
5
5
  annotators: Map<string, Annotator<any, unknown>>;
@@ -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,EAAoB,MAAM,mBAAmB,CAAC;AACjF,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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cAAc,8CAG1B,CAAA;AAED,eAAO,MAAM,YAAY,kDAGxB,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { Origin } from '@annotorious/react';
2
- import type { Annotation, AnnotationBody, Annotator, LifecycleEvents } from '@annotorious/core';
2
+ import type { Annotation, AnnotationBody, Annotator, LifecycleEvents } from '@annotorious/core/src';
3
3
  export interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends unknown = Annotation> {
4
4
  annotators: Annotator<I, E>[];
5
5
  sources: string[];
@@ -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,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAE3B,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,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C,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 +1 @@
1
- {"version":3,"file":"annotorious-react-manifold.es3.js","sources":["../src/AnnotoriousManifold.tsx"],"sourcesContent":["import { ReactNode, createContext, useContext, useEffect, useRef, useState } from 'react';\nimport type { Annotation, Annotator, StoreChangeEvent } from '@annotorious/core';\nimport { AnnotoriousManifoldInstance, createManifoldInstance } from './AnnotoriousManifoldInstance';\n\ninterface AnnotoriousManifoldContextValue {\n\n annotators: Map<string, Annotator<any, unknown>>;\n\n annotations: Map<string, Annotation[]>;\n\n selection: ManifoldSelection;\n\n connectAnnotator(source: string, anno: Annotator<any, unknown>): () => void;\n\n}\n\ninterface ManifoldSelection<T extends Annotation = Annotation> {\n\n source?: string;\n\n selected: { annotation: T, editable?: boolean }[],\n\n pointerEvent?: PointerEvent;\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, unknown>>>(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 = (source: string, anno: Annotator<any, unknown>) => {\n // Add the annotator to the state\n setAnnotators(m => new Map(m.entries()).set(source, anno))\n\n const { store } = anno.state;\n const selectionState = anno.state.selection;\n\n // Add the annotations to the state\n setAnnotations(m => new Map(m.entries()).set(source, store.all()));\n\n const onStoreChange = () =>\n setAnnotations(m => new Map(m.entries()).set(source, 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, pointerEvent }) => {\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({ source, selected: resolved, pointerEvent });\n\n // Track the state of the selected annotations in the store\n selectionStoreObserver = event => {\n const { updated } = event.changes;\n\n setSelection(({ source, selected }) => ({\n source,\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 pointerEvent\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 !== source)));\n\n // Remove & untrack annotations\n setAnnotations(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== source)));\n store.unobserve(onStoreChange);\n\n // Un-track selection\n unsubscribeSelection();\n }\n }\n\n useEffect(() => {\n if (selection.source) {\n muteSelectionEvents.current = true;\n\n Array.from(annotators.entries()).forEach(([source, anno]) => {\n if (source !== selection.source)\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 unknown = Annotation>() => {\n const { annotators } = useContext(AnnotoriousManifoldContext);\n return createManifoldInstance(annotators) as AnnotoriousManifoldInstance<I, E>;\n}\n\nexport const useAnnotations = <T extends Annotation>() => {\n const { annotations } = useContext(AnnotoriousManifoldContext);\n return annotations as Map<string, T[]>;\n}\n\nexport const useSelection = <T extends Annotation>() => {\n const { selection } = useContext(AnnotoriousManifoldContext);\n return selection as ManifoldSelection<T>;\n}\n"],"names":["AnnotoriousManifoldContext","createContext","AnnotoriousManifold","props","annotators","setAnnotators","useState","annotations","setAnnotations","selection","setSelection","muteSelectionEvents","useRef","connectAnnotator","source","anno","m","store","selectionState","onStoreChange","selectionStoreObserver","unsubscribeSelection","selected","pointerEvent","resolved","id","editable","event","updated","annotation","next","u","key","_","useEffect","jsx","useAnnotoriousManifold","useContext","createManifoldInstance","useAnnotations","useSelection"],"mappings":";;;AA2BO,MAAMA,IAA6BC,EAA+C,GAE5EC,IAAsB,CAACC,MAAmC;AAErE,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAA+C,oBAAI,KAAK,GAEtF,CAACC,GAAaC,CAAc,IAAIF,EAAoC,oBAAI,KAAK,GAE7E,CAACG,GAAWC,CAAY,IAC5BJ,EAA4B,EAAE,UAAU,CAAC,EAAA,CAAG,GAGxCK,IAAsBC,EAAgB,EAAK,GAE3CC,IAAmB,CAACC,GAAgBC,MAAkC;AAE5D,IAAAV,EAAA,CAAAW,MAAK,IAAI,IAAIA,EAAE,QAAS,CAAA,EAAE,IAAIF,GAAQC,CAAI,CAAC;AAEnD,UAAA,EAAE,OAAAE,EAAM,IAAIF,EAAK,OACjBG,IAAiBH,EAAK,MAAM;AAGlC,IAAAP,EAAe,CAAKQ,MAAA,IAAI,IAAIA,EAAE,QAAQ,CAAC,EAAE,IAAIF,GAAQG,EAAM,IAAI,CAAC,CAAC;AAEjE,UAAME,IAAgB,MACpBX,EAAe,CAAAQ,MAAK,IAAI,IAAIA,EAAE,QAAQ,CAAC,EAAE,IAAIF,GAAQG,EAAM,IAAA,CAAK,CAAC;AAEnE,IAAAA,EAAM,QAAQE,CAAa;AAGvB,QAAAC;AAEJ,UAAMC,IAAuBH,EAAe,UAAU,CAAC,EAAE,UAAAI,GAAU,cAAAC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B,EAAU,WACZE,EAAoB,UAAU,IAExB,MAAA,KAAKP,EAAW,QAAS,CAAA,EAAE,QAAQ,CAAC,CAACU,GAAQC,CAAI,MAAM;AAC3D,MAAID,MAAWL,EAAU,UACvBM,EAAK,YAAY;AAAA,IAAA,CACpB,GAEDJ,EAAoB,UAAU;AAAA,EAChC,GACC,CAACF,GAAWL,CAAU,CAAC,GAGvB+B,gBAAAA,MAAAnC,EAA2B,UAA3B,EAAoC,OAAO;AAAA,IAC1C,YAAAI;AAAA,IACA,aAAAG;AAAA,IACA,WAAAE;AAAA,IACA,kBAAAI;AAAA,EACF,GACG,YAAM,SACT,CAAA;AAGJ,GAEauB,IAAyB,MAAyE;AAC7G,QAAM,EAAE,YAAAhC,EAAA,IAAeiC,EAAWrC,CAA0B;AAC5D,SAAOsC,EAAuBlC,CAAU;AAC1C,GAEamC,IAAiB,MAA4B;AACxD,QAAM,EAAE,aAAAhC,EAAA,IAAgB8B,EAAWrC,CAA0B;AACtD,SAAAO;AACT,GAEaiC,IAAe,MAA4B;AACtD,QAAM,EAAE,WAAA/B,EAAA,IAAc4B,EAAWrC,CAA0B;AACpD,SAAAS;AACT;"}
1
+ {"version":3,"file":"annotorious-react-manifold.es3.js","sources":["../src/AnnotoriousManifold.tsx"],"sourcesContent":["import { ReactNode, createContext, useContext, useEffect, useRef, useState } from 'react';\nimport type { Annotation, Annotator, StoreChangeEvent } from '@annotorious/core/src';\nimport { AnnotoriousManifoldInstance, createManifoldInstance } from './AnnotoriousManifoldInstance';\n\ninterface AnnotoriousManifoldContextValue {\n\n annotators: Map<string, Annotator<any, unknown>>;\n\n annotations: Map<string, Annotation[]>;\n\n selection: ManifoldSelection;\n\n connectAnnotator(source: string, anno: Annotator<any, unknown>): () => void;\n\n}\n\ninterface ManifoldSelection<T extends Annotation = Annotation> {\n\n source?: string;\n\n selected: { annotation: T, editable?: boolean }[],\n\n pointerEvent?: PointerEvent;\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, unknown>>>(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 = (source: string, anno: Annotator<any, unknown>) => {\n // Add the annotator to the state\n setAnnotators(m => new Map(m.entries()).set(source, anno))\n\n const { store } = anno.state;\n const selectionState = anno.state.selection;\n\n // Add the annotations to the state\n setAnnotations(m => new Map(m.entries()).set(source, store.all()));\n\n const onStoreChange = () =>\n setAnnotations(m => new Map(m.entries()).set(source, 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, pointerEvent }) => {\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({ source, selected: resolved, pointerEvent });\n\n // Track the state of the selected annotations in the store\n selectionStoreObserver = event => {\n const { updated } = event.changes;\n\n setSelection(({ source, selected }) => ({\n source,\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 pointerEvent\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 !== source)));\n\n // Remove & untrack annotations\n setAnnotations(m => new Map(Array.from(m.entries()).filter(([key, _]) => key !== source)));\n store.unobserve(onStoreChange);\n\n // Un-track selection\n unsubscribeSelection();\n }\n }\n\n useEffect(() => {\n if (selection.source) {\n muteSelectionEvents.current = true;\n\n Array.from(annotators.entries()).forEach(([source, anno]) => {\n if (source !== selection.source)\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 unknown = Annotation>() => {\n const { annotators } = useContext(AnnotoriousManifoldContext);\n return createManifoldInstance(annotators) as AnnotoriousManifoldInstance<I, E>;\n}\n\nexport const useAnnotations = <T extends Annotation>() => {\n const { annotations } = useContext(AnnotoriousManifoldContext);\n return annotations as Map<string, T[]>;\n}\n\nexport const useSelection = <T extends Annotation>() => {\n const { selection } = useContext(AnnotoriousManifoldContext);\n return selection as ManifoldSelection<T>;\n}\n"],"names":["AnnotoriousManifoldContext","createContext","AnnotoriousManifold","props","annotators","setAnnotators","useState","annotations","setAnnotations","selection","setSelection","muteSelectionEvents","useRef","connectAnnotator","source","anno","m","store","selectionState","onStoreChange","selectionStoreObserver","unsubscribeSelection","selected","pointerEvent","resolved","id","editable","event","updated","annotation","next","u","key","_","useEffect","jsx","useAnnotoriousManifold","useContext","createManifoldInstance","useAnnotations","useSelection"],"mappings":";;;AA2BO,MAAMA,IAA6BC,EAA+C,GAE5EC,IAAsB,CAACC,MAAmC;AAErE,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAA+C,oBAAI,KAAK,GAEtF,CAACC,GAAaC,CAAc,IAAIF,EAAoC,oBAAI,KAAK,GAE7E,CAACG,GAAWC,CAAY,IAC5BJ,EAA4B,EAAE,UAAU,CAAC,EAAA,CAAG,GAGxCK,IAAsBC,EAAgB,EAAK,GAE3CC,IAAmB,CAACC,GAAgBC,MAAkC;AAE5D,IAAAV,EAAA,CAAAW,MAAK,IAAI,IAAIA,EAAE,QAAS,CAAA,EAAE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AnnotoriousManifoldInstance.ts"],"sourcesContent":["import { Origin } from '@annotorious/react';\nimport type { \n Annotation, \n AnnotationBody, \n Annotator, \n LifecycleEvents\n} from '@annotorious/core';\n\nexport interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends unknown = Annotation> {\n\n annotators: Annotator<I, E>[];\n\n sources: string[];\n\n // style: DrawingStyle | ((annotation: I) => DrawingStyle) | undefined;\n\n addBody(body: AnnotationBody, origin?: Origin): void;\n\n clear(origin: Origin): void;\n\n deleteAnnotation(id: string, origin?: Origin): E | undefined;\n\n destroy(): void;\n\n getAnnotationById(id: string): E | undefined;\n\n getAnnotations(): E[];\n \n on<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n off<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n}\n\nexport const createManifoldInstance = <I extends Annotation = Annotation, E extends unknown = Annotation>(\n annotators: Map<string, Annotator<I, E>>\n): AnnotoriousManifoldInstance<I, E> => {\n\n const find = (annotationId: string): { annotation?: E, annotator?: Annotator<I, E> } =>\n Array.from(annotators.values()).reduce((found, annotator) => {\n if (found)\n return found;\n\n const annotation = annotator.getAnnotationById(annotationId);\n if (annotation) \n return { annotation, annotator };\n }, undefined as { annotation: E, annotator: Annotator<I, E> } | undefined ) || \n\n { annotation: undefined, annotator: 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 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 destroy = () =>\n Array.from(annotators.values()).forEach(a => a.destroy());\n\n const getAnnotationById = (id: string) => \n find(id).annotation;\n\n const getAnnotations = () => \n Array.from(annotators.values()).reduce((all, annotator) =>\n [...all, ...annotator.getAnnotations()], [] as E[])\n\n // @ts-ignore\n return {\n annotators: [...annotators.values()],\n sources: [...annotators.keys()],\n addBody,\n clear,\n deleteAnnotation,\n destroy,\n getAnnotationById,\n getAnnotations\n }\n\n}"],"names":["createManifoldInstance","annotators","find","annotationId","found","annotator","annotation","addBody","body","origin","Origin","clear","a","deleteAnnotation","id","destroy","getAnnotationById","getAnnotations","all"],"mappings":";AAkCa,MAAAA,IAAyB,CACpCC,MACsC;AAEtC,QAAMC,IAAO,CAACC,MACZ,MAAM,KAAKF,EAAW,OAAO,CAAC,EAAE,OAAO,CAACG,GAAOC,MAAc;AACvD,QAAAD;AACK,aAAAA;AAEH,UAAAE,IAAaD,EAAU,kBAAkBF,CAAY;AACvD,QAAAG;AACK,aAAA,EAAE,YAAAA,GAAY,WAAAD;EAAU,GAChC,MAAuE,KAE1E,EAAE,YAAY,QAAW,WAAW,UAMhCE,IAAU,CAACC,GAAsBC,IAASC,EAAO,UAAU;AAC/D,UAAM,EAAE,WAAAL,EAAc,IAAAH,EAAKM,EAAK,UAAU;AACtC,IAAAH,KACFA,EAAU,MAAM,MAAM,QAAQG,GAAMC,CAAM;AAAA,EAAA,GAGxCE,IAAQ,CAACF,IAASC,EAAO,UAC7B,MAAM,KAAKT,EAAW,OAAA,CAAQ,EAAE,QAAQ,CAAKW,MAAAA,EAAE,MAAM,MAAM,MAAMH,CAAM,CAAC,GAEpEI,IAAmB,CAACC,GAAYL,IAASC,EAAO,UAAU;AAC9D,UAAM,EAAE,YAAAJ,GAAY,WAAAD,EAAU,IAAIH,EAAKY,CAAE;AAEzC,QAAIT;AACF,aAAAA,EAAU,MAAM,MAAM,iBAAiBS,GAAIL,CAAM,GAC1CH;AAAA,EACT,GAGIS,IAAU,MACd,MAAM,KAAKd,EAAW,OAAA,CAAQ,EAAE,QAAQ,CAAAW,MAAKA,EAAE,QAAS,CAAA,GAEpDI,IAAoB,CAACF,MACzBZ,EAAKY,CAAE,EAAE,YAELG,IAAiB,MACrB,MAAM,KAAKhB,EAAW,OAAO,CAAC,EAAE,OAAO,CAACiB,GAAKb,MAC3C,CAAC,GAAGa,GAAK,GAAGb,EAAU,eAAgB,CAAA,GAAG,CAAA,CAAS;AAG/C,SAAA;AAAA,IACL,YAAY,CAAC,GAAGJ,EAAW,QAAQ;AAAA,IACnC,SAAS,CAAC,GAAGA,EAAW,MAAM;AAAA,IAC9B,SAAAM;AAAA,IACA,OAAAI;AAAA,IACA,kBAAAE;AAAA,IACA,SAAAE;AAAA,IACA,mBAAAC;AAAA,IACA,gBAAAC;AAAA,EAAA;AAGJ;"}
1
+ {"version":3,"file":"annotorious-react-manifold.es4.js","sources":["../src/AnnotoriousManifoldInstance.ts"],"sourcesContent":["import { Origin } from '@annotorious/react';\nimport type { \n Annotation, \n AnnotationBody, \n Annotator, \n LifecycleEvents\n} from '@annotorious/core/src';\n\nexport interface AnnotoriousManifoldInstance<I extends Annotation = Annotation, E extends unknown = Annotation> {\n\n annotators: Annotator<I, E>[];\n\n sources: string[];\n\n // style: DrawingStyle | ((annotation: I) => DrawingStyle) | undefined;\n\n addBody(body: AnnotationBody, origin?: Origin): void;\n\n clear(origin: Origin): void;\n\n deleteAnnotation(id: string, origin?: Origin): E | undefined;\n\n destroy(): void;\n\n getAnnotationById(id: string): E | undefined;\n\n getAnnotations(): E[];\n \n on<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n off<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n}\n\nexport const createManifoldInstance = <I extends Annotation = Annotation, E extends unknown = Annotation>(\n annotators: Map<string, Annotator<I, E>>\n): AnnotoriousManifoldInstance<I, E> => {\n\n const find = (annotationId: string): { annotation?: E, annotator?: Annotator<I, E> } =>\n Array.from(annotators.values()).reduce((found, annotator) => {\n if (found)\n return found;\n\n const annotation = annotator.getAnnotationById(annotationId);\n if (annotation) \n return { annotation, annotator };\n }, undefined as { annotation: E, annotator: Annotator<I, E> } | undefined ) || \n\n { annotation: undefined, annotator: 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 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 destroy = () =>\n Array.from(annotators.values()).forEach(a => a.destroy());\n\n const getAnnotationById = (id: string) => \n find(id).annotation;\n\n const getAnnotations = () => \n Array.from(annotators.values()).reduce((all, annotator) =>\n [...all, ...annotator.getAnnotations()], [] as E[])\n\n // @ts-ignore\n return {\n annotators: [...annotators.values()],\n sources: [...annotators.keys()],\n addBody,\n clear,\n deleteAnnotation,\n destroy,\n getAnnotationById,\n getAnnotations\n }\n\n}"],"names":["createManifoldInstance","annotators","find","annotationId","found","annotator","annotation","addBody","body","origin","Origin","clear","a","deleteAnnotation","id","destroy","getAnnotationById","getAnnotations","all"],"mappings":";AAkCa,MAAAA,IAAyB,CACpCC,MACsC;AAEtC,QAAMC,IAAO,CAACC,MACZ,MAAM,KAAKF,EAAW,OAAO,CAAC,EAAE,OAAO,CAACG,GAAOC,MAAc;AACvD,QAAAD;AACK,aAAAA;AAEH,UAAAE,IAAaD,EAAU,kBAAkBF,CAAY;AACvD,QAAAG;AACK,aAAA,EAAE,YAAAA,GAAY,WAAAD;EAAU,GAChC,MAAuE,KAE1E,EAAE,YAAY,QAAW,WAAW,UAMhCE,IAAU,CAACC,GAAsBC,IAASC,EAAO,UAAU;AAC/D,UAAM,EAAE,WAAAL,EAAc,IAAAH,EAAKM,EAAK,UAAU;AACtC,IAAAH,KACFA,EAAU,MAAM,MAAM,QAAQG,GAAMC,CAAM;AAAA,EAAA,GAGxCE,IAAQ,CAACF,IAASC,EAAO,UAC7B,MAAM,KAAKT,EAAW,OAAA,CAAQ,EAAE,QAAQ,CAAKW,MAAAA,EAAE,MAAM,MAAM,MAAMH,CAAM,CAAC,GAEpEI,IAAmB,CAACC,GAAYL,IAASC,EAAO,UAAU;AAC9D,UAAM,EAAE,YAAAJ,GAAY,WAAAD,EAAU,IAAIH,EAAKY,CAAE;AAEzC,QAAIT;AACF,aAAAA,EAAU,MAAM,MAAM,iBAAiBS,GAAIL,CAAM,GAC1CH;AAAA,EACT,GAGIS,IAAU,MACd,MAAM,KAAKd,EAAW,OAAA,CAAQ,EAAE,QAAQ,CAAAW,MAAKA,EAAE,QAAS,CAAA,GAEpDI,IAAoB,CAACF,MACzBZ,EAAKY,CAAE,EAAE,YAELG,IAAiB,MACrB,MAAM,KAAKhB,EAAW,OAAO,CAAC,EAAE,OAAO,CAACiB,GAAKb,MAC3C,CAAC,GAAGa,GAAK,GAAGb,EAAU,eAAgB,CAAA,GAAG,CAAA,CAAS;AAG/C,SAAA;AAAA,IACL,YAAY,CAAC,GAAGJ,EAAW,QAAQ;AAAA,IACnC,SAAS,CAAC,GAAGA,EAAW,MAAM;AAAA,IAC9B,SAAAM;AAAA,IACA,OAAAI;AAAA,IACA,kBAAAE;AAAA,IACA,SAAAE;AAAA,IACA,mBAAAC;AAAA,IACA,gBAAAC;AAAA,EAAA;AAGJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/react-manifold",
3
- "version": "0.0.6",
3
+ "version": "0.0.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",