@annotorious/core 3.0.0-rc.2 → 3.0.0-rc.20

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.
Files changed (89) hide show
  1. package/dist/annotorious-core.es.js +776 -0
  2. package/dist/annotorious-core.es.js.map +1 -0
  3. package/{src/index.ts → dist/index.d.ts} +1 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/lifecycle/Lifecycle.d.ts +10 -0
  6. package/dist/lifecycle/Lifecycle.d.ts.map +1 -0
  7. package/dist/lifecycle/LifecycleEvents.d.ts +12 -0
  8. package/dist/lifecycle/LifecycleEvents.d.ts.map +1 -0
  9. package/dist/lifecycle/index.d.ts +3 -0
  10. package/dist/lifecycle/index.d.ts.map +1 -0
  11. package/dist/model/Annotation.d.ts +32 -0
  12. package/dist/model/Annotation.d.ts.map +1 -0
  13. package/dist/model/Annotator.d.ts +63 -0
  14. package/dist/model/Annotator.d.ts.map +1 -0
  15. package/{src/model/DrawingStyle.ts → dist/model/DrawingStyle.d.ts} +8 -14
  16. package/dist/model/DrawingStyle.d.ts.map +1 -0
  17. package/{src/model/Filter.ts → dist/model/Filter.d.ts} +2 -2
  18. package/dist/model/Filter.d.ts.map +1 -0
  19. package/dist/model/FormatAdapter.d.ts +15 -0
  20. package/dist/model/FormatAdapter.d.ts.map +1 -0
  21. package/dist/model/User.d.ts +11 -0
  22. package/dist/model/User.d.ts.map +1 -0
  23. package/dist/model/W3CAnnotation.d.ts +41 -0
  24. package/dist/model/W3CAnnotation.d.ts.map +1 -0
  25. package/{src/model/index.ts → dist/model/index.d.ts} +2 -1
  26. package/dist/model/index.d.ts.map +1 -0
  27. package/dist/presence/Appearance.d.ts +6 -0
  28. package/dist/presence/Appearance.d.ts.map +1 -0
  29. package/dist/presence/AppearanceProvider.d.ts +16 -0
  30. package/dist/presence/AppearanceProvider.d.ts.map +1 -0
  31. package/dist/presence/ColorPalette.d.ts +3 -0
  32. package/dist/presence/ColorPalette.d.ts.map +1 -0
  33. package/dist/presence/PresenceEvents.d.ts +6 -0
  34. package/dist/presence/PresenceEvents.d.ts.map +1 -0
  35. package/dist/presence/PresenceProvider.d.ts +5 -0
  36. package/dist/presence/PresenceProvider.d.ts.map +1 -0
  37. package/dist/presence/PresenceState.d.ts +18 -0
  38. package/dist/presence/PresenceState.d.ts.map +1 -0
  39. package/dist/presence/PresentUser.d.ts +7 -0
  40. package/dist/presence/PresentUser.d.ts.map +1 -0
  41. package/{src/presence/index.ts → dist/presence/index.d.ts} +2 -1
  42. package/dist/presence/index.d.ts.map +1 -0
  43. package/dist/state/Hover.d.ts +10 -0
  44. package/dist/state/Hover.d.ts.map +1 -0
  45. package/dist/state/Selection.d.ts +31 -0
  46. package/dist/state/Selection.d.ts.map +1 -0
  47. package/dist/state/Store.d.ts +30 -0
  48. package/dist/state/Store.d.ts.map +1 -0
  49. package/dist/state/StoreObserver.d.ts +57 -0
  50. package/dist/state/StoreObserver.d.ts.map +1 -0
  51. package/dist/state/SvelteStore.d.ts +22 -0
  52. package/dist/state/SvelteStore.d.ts.map +1 -0
  53. package/dist/state/UndoStack.d.ts +18 -0
  54. package/dist/state/UndoStack.d.ts.map +1 -0
  55. package/dist/state/Viewport.d.ts +7 -0
  56. package/dist/state/Viewport.d.ts.map +1 -0
  57. package/{src/state/index.ts → dist/state/index.d.ts} +3 -1
  58. package/dist/state/index.d.ts.map +1 -0
  59. package/dist/utils/annotationUtils.d.ts +11 -0
  60. package/dist/utils/annotationUtils.d.ts.map +1 -0
  61. package/dist/utils/diffAnnotations.d.ts +4 -0
  62. package/dist/utils/diffAnnotations.d.ts.map +1 -0
  63. package/{src/utils/index.ts → dist/utils/index.d.ts} +1 -1
  64. package/dist/utils/index.d.ts.map +1 -0
  65. package/package.json +18 -15
  66. package/src/lifecycle/Lifecycle.ts +0 -197
  67. package/src/lifecycle/LifecycleEvents.ts +0 -21
  68. package/src/lifecycle/index.ts +0 -2
  69. package/src/model/Annotation.ts +0 -57
  70. package/src/model/Annotator.ts +0 -154
  71. package/src/model/FormatAdapter.ts +0 -36
  72. package/src/model/User.ts +0 -19
  73. package/src/model/W3CAnnotation.ts +0 -118
  74. package/src/presence/Appearance.ts +0 -9
  75. package/src/presence/AppearanceProvider.ts +0 -53
  76. package/src/presence/ColorPalette.ts +0 -14
  77. package/src/presence/PresenceEvents.ts +0 -9
  78. package/src/presence/PresenceProvider.ts +0 -7
  79. package/src/presence/PresenceState.ts +0 -145
  80. package/src/presence/PresentUser.ts +0 -10
  81. package/src/state/Hover.ts +0 -34
  82. package/src/state/Selection.ts +0 -113
  83. package/src/state/Store.ts +0 -327
  84. package/src/state/StoreObserver.ts +0 -149
  85. package/src/state/SvelteStore.ts +0 -54
  86. package/src/state/Viewport.ts +0 -14
  87. package/src/utils/annotationUtils.ts +0 -33
  88. package/src/utils/diffAnnotations.ts +0 -33
  89. package/src/vite-env.d.ts +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppearanceProvider.d.ts","sourceRoot":"","sources":["../../src/presence/AppearanceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,WAAW,kBAAkB;IAEjC,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,UAAU,CAAC;IAErD,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;CAErC;AAED,eAAO,MAAM,oBAAoB;;0BAaF,MAAM;CAKpC,CAAA;AAED,eAAO,MAAM,+BAA+B;2BAIZ,MAAM,QAAQ,IAAI,KAAG,UAAU;uBAUnC,WAAW;CAKtC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_PALETTE: Palette;
2
+ export type Palette = string[];
3
+ //# sourceMappingURL=ColorPalette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPalette.d.ts","sourceRoot":"","sources":["../../src/presence/ColorPalette.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,EAAE,OAU7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { PresentUser } from './PresentUser';
2
+ export interface PresenceEvents {
3
+ presence: (users: PresentUser[]) => void;
4
+ selectionChange: (from: PresentUser, selection: string[] | null) => void;
5
+ }
6
+ //# sourceMappingURL=PresenceEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PresenceEvents.d.ts","sourceRoot":"","sources":["../../src/presence/PresenceEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,WAAW,cAAc;IAE7B,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IAEzC,eAAe,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,IAAI,CAAC;CAE1E"}
@@ -0,0 +1,5 @@
1
+ import type { PresenceEvents } from './PresenceEvents';
2
+ export interface PresenceProvider {
3
+ on<E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]): void;
4
+ }
5
+ //# sourceMappingURL=PresenceProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PresenceProvider.d.ts","sourceRoot":"","sources":["../../src/presence/PresenceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAE/B,EAAE,CAAC,CAAC,SAAS,MAAM,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAEjF"}
@@ -0,0 +1,18 @@
1
+ import { type Unsubscribe } from 'nanoevents';
2
+ import type { User } from '../model/User';
3
+ import type { PresentUser } from './PresentUser';
4
+ import type { PresenceEvents } from './PresenceEvents';
5
+ import type { AppearanceProvider } from './AppearanceProvider';
6
+ export interface PresenceState {
7
+ getPresentUsers(): PresentUser[];
8
+ notifyActivity(presenceKey: string, annotationIds: string[]): void;
9
+ on<E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]): Unsubscribe;
10
+ syncUsers(state: {
11
+ presenceKey: string;
12
+ user: User;
13
+ }[]): void;
14
+ updateSelection(presenceKey: string, selection: string[] | null): void;
15
+ }
16
+ export declare const PRESENCE_KEY: string;
17
+ export declare const createPresenceState: (appearanceProvider?: AppearanceProvider) => PresenceState;
18
+ //# sourceMappingURL=PresenceState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PresenceState.d.ts","sourceRoot":"","sources":["../../src/presence/PresenceState.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,MAAM,WAAW,aAAa;IAG5B,eAAe,IAAI,WAAW,EAAE,CAAC;IAGjC,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAGnE,EAAE,CAAC,CAAC,SAAS,MAAM,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IAGvF,SAAS,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,EAAE,GAAG,IAAI,CAAC;IAG9D,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;CAExE;AAMD,eAAO,MAAM,YAAY,QAAW,CAAC;AAErC,eAAO,MAAM,mBAAmB,wBACV,kBAAkB,KACrC,aA6GF,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { User } from '../model/User';
2
+ import type { Appearance } from './Appearance';
3
+ export interface PresentUser extends User {
4
+ presenceKey: string;
5
+ appearance: Appearance;
6
+ }
7
+ //# sourceMappingURL=PresentUser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PresentUser.d.ts","sourceRoot":"","sources":["../../src/presence/PresentUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,WAAY,SAAQ,IAAI;IAEvC,WAAW,EAAE,MAAM,CAAC;IAEpB,UAAU,EAAE,UAAU,CAAA;CAEvB"}
@@ -3,4 +3,5 @@ export * from './AppearanceProvider';
3
3
  export * from './PresenceEvents';
4
4
  export * from './PresenceProvider';
5
5
  export * from './PresenceState';
6
- export * from './PresentUser';
6
+ export * from './PresentUser';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presence/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="svelte" />
2
+ import type { Annotation } from '../model';
3
+ import type { Store } from './Store';
4
+ export type HoverState<T extends Annotation> = ReturnType<typeof createHoverState<T>>;
5
+ export declare const createHoverState: <T extends Annotation>(store: Store<T>) => {
6
+ readonly current: string | undefined;
7
+ subscribe: (this: void, run: import("svelte/store").Subscriber<string | undefined>, invalidate?: import("svelte/store").Invalidator<string | undefined> | undefined) => import("svelte/store").Unsubscriber;
8
+ set: (this: void, value: string | undefined) => void;
9
+ };
10
+ //# sourceMappingURL=Hover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Hover.d.ts","sourceRoot":"","sources":["../../src/state/Hover.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtF,eAAO,MAAM,gBAAgB,gCAAiC,MAAM,CAAC,CAAC;;;;CA2BrE,CAAA"}
@@ -0,0 +1,31 @@
1
+ /// <reference types="svelte" />
2
+ import type { Annotation } from '../model';
3
+ import type { Store } from './Store';
4
+ export type Selection = {
5
+ selected: {
6
+ id: string;
7
+ editable?: boolean;
8
+ }[];
9
+ pointerEvent?: PointerEvent;
10
+ };
11
+ export type SelectionState<T extends Annotation> = ReturnType<typeof createSelectionState<T>>;
12
+ export declare enum PointerSelectAction {
13
+ EDIT = "EDIT",// Make annotation target(s) editable on pointer select
14
+ SELECT = "SELECT",// Just select, but don't make editable
15
+ NONE = "NONE"
16
+ }
17
+ export declare const createSelectionState: <T extends Annotation>(store: Store<T>, selectAction?: PointerSelectAction | ((a: T) => PointerSelectAction)) => {
18
+ clear: () => void;
19
+ clickSelect: (id: string, pointerEvent: PointerEvent) => void;
20
+ readonly selected: {
21
+ id: string;
22
+ editable?: boolean | undefined;
23
+ }[] | null;
24
+ readonly pointerEvent: PointerEvent | null | undefined;
25
+ isEmpty: () => boolean;
26
+ isSelected: (annotationOrId: T | string) => boolean;
27
+ setSelected: (idOrIds: string | string[], editable?: boolean) => void;
28
+ subscribe: (this: void, run: import("svelte/store").Subscriber<Selection>, invalidate?: import("svelte/store").Invalidator<Selection> | undefined) => import("svelte/store").Unsubscriber;
29
+ };
30
+ export declare const onPointerSelect: <T extends Annotation>(annotation: T, action?: PointerSelectAction | ((a: T) => PointerSelectAction) | undefined) => PointerSelectAction;
31
+ //# sourceMappingURL=Selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Selection.d.ts","sourceRoot":"","sources":["../../src/state/Selection.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAG,UAAU,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,MAAM,SAAS,GAAG;IAEtB,QAAQ,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAE/C,YAAY,CAAC,EAAE,YAAY,CAAC;CAE7B,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,UAAU,IAAI,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9F,oBAAY,mBAAmB;IAE7B,IAAI,SAAS,CAAE,uDAAuD;IAEtE,MAAM,WAAW,CAAG,uCAAuC;IAE3D,IAAI,SAAS;CAEd;AAID,eAAO,MAAM,oBAAoB,gCACxB,MAAM,CAAC,CAAC,4CAC0B,CAAC,KAAK,mBAAmB;;sBAqBzC,MAAM,gBAAgB,YAAY;;YA3C3C,MAAM;;;;;iCAkCc,CAAC,GAAG,MAAM;2BAwBhB,MAAM,GAAG,MAAM,EAAE,aAAY,OAAO;;CAyCnE,CAAA;AAED,eAAO,MAAM,eAAe,qCACd,CAAC,sCACuB,CAAC,KAAK,mBAAmB,kBAC5D,mBAEqC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { Annotation } from '../model';
2
+ import { Origin } from './StoreObserver';
3
+ import type { StoreChangeEvent, StoreObserveOptions } from './StoreObserver';
4
+ type AnnotationBodyIdentifier = {
5
+ id: string;
6
+ annotation: string;
7
+ };
8
+ export type Store<T extends Annotation> = ReturnType<typeof createStore<T>>;
9
+ export declare const createStore: <T extends Annotation>() => {
10
+ addAnnotation: (annotation: T, origin?: Origin) => void;
11
+ addBody: (body: T['bodies'][number], origin?: Origin) => void;
12
+ all: () => T[];
13
+ bulkAddAnnotation: (annotations: T[], replace?: boolean, origin?: Origin) => void;
14
+ bulkDeleteAnnotation: (annotationsOrIds: (T | string)[], origin?: Origin) => void;
15
+ bulkUpdateAnnotation: (annotations: T[], origin?: Origin) => void;
16
+ bulkUpdateBodies: (bodies: Array<T['bodies'][number]>, origin?: Origin) => void;
17
+ bulkUpdateTargets: (targets: Array<T['target']>, origin?: Origin) => void;
18
+ clear: (origin?: Origin) => void;
19
+ deleteAnnotation: (annotationOrId: T | string, origin?: Origin) => void;
20
+ deleteBody: (body: AnnotationBodyIdentifier, origin?: Origin) => void;
21
+ getAnnotation: (id: string) => T | undefined;
22
+ getBody: (id: string) => T['bodies'][number] | undefined;
23
+ observe: (onChange: (event: StoreChangeEvent<T>) => void, options?: StoreObserveOptions) => number;
24
+ unobserve: (onChange: (event: StoreChangeEvent<T>) => void) => void;
25
+ updateAnnotation: (arg1: string | T, arg2?: T | Origin, arg3?: Origin) => void;
26
+ updateBody: (oldBodyId: AnnotationBodyIdentifier, newBody: T['bodies'][number], origin?: Origin) => void;
27
+ updateTarget: (target: T['target'], origin?: Origin) => void;
28
+ };
29
+ export {};
30
+ //# sourceMappingURL=Store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../../src/state/Store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,MAAM,EAA6C,MAAM,iBAAiB,CAAC;AACpF,OAAO,KAAK,EAAiB,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG5F,KAAK,wBAAwB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,UAAU,IAAI,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAI5E,eAAO,MAAM,WAAW;gCAkCa,CAAC;oBAwDb,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;;qCAiCF,CAAC,EAAE;6CAmDK,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE;wCA9FnB,CAAC,EAAE;+BA6LZ,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;iCAuCxB,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;;uCA5IZ,CAAC,GAAG,MAAM;uBAgB1B,wBAAwB;wBA6BvB,MAAM,KAAG,CAAC,GAAG,SAAS;kBAK5B,MAAM,KAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS;gCAlNxB,iBAAiB,CAAC,CAAC,KAAG,IAAI,YAAa,mBAAmB;kCAGxD,iBAAiB,CAAC,CAAC,KAAG,IAAI;6BA6DjC,MAAM,GAAG,CAAC,SAAQ,CAAC,GAAG,MAAM;4BA+L7B,wBAAwB,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;2BAuCvD,CAAC,CAAC,QAAQ,CAAC;CAkC1C,CAAA"}
@@ -0,0 +1,57 @@
1
+ import type { Annotation, AnnotationBody, AnnotationTarget } from '../model/Annotation';
2
+ /** Interface for listening to changes in the annotation store **/
3
+ export interface StoreObserver<T extends Annotation> {
4
+ onChange: {
5
+ (event: StoreChangeEvent<T>): void;
6
+ };
7
+ options: StoreObserveOptions;
8
+ }
9
+ /** A change event fired when the store state changes **/
10
+ export interface StoreChangeEvent<T extends Annotation> {
11
+ origin: Origin;
12
+ changes: ChangeSet<T>;
13
+ state: T[];
14
+ }
15
+ export interface ChangeSet<T extends Annotation> {
16
+ created?: T[];
17
+ deleted?: T[];
18
+ updated?: Update<T>[];
19
+ }
20
+ export interface Update<T extends Annotation> {
21
+ oldValue: T;
22
+ newValue: T;
23
+ bodiesCreated?: AnnotationBody[];
24
+ bodiesDeleted?: AnnotationBody[];
25
+ bodiesUpdated?: Array<{
26
+ oldBody: AnnotationBody;
27
+ newBody: AnnotationBody;
28
+ }>;
29
+ targetUpdated?: {
30
+ oldTarget: AnnotationTarget;
31
+ newTarget: AnnotationTarget;
32
+ };
33
+ }
34
+ /** Options to control which events the observer wants to get notified about **/
35
+ export interface StoreObserveOptions {
36
+ ignore?: Ignore;
37
+ annotations?: string | string[];
38
+ origin?: Origin;
39
+ }
40
+ /** Allows the observer to ignore certain event types **/
41
+ export declare enum Ignore {
42
+ BODY_ONLY = "BODY_ONLY",
43
+ TARGET_ONLY = "TARGET_ONLY"
44
+ }
45
+ /** Allows the observer to listen only for events that originated locally or from a remote source **/
46
+ export declare enum Origin {
47
+ LOCAL = "LOCAL",
48
+ REMOTE = "REMOTE"
49
+ }
50
+ /** Tests if this observer should be notified about this event **/
51
+ export declare const shouldNotify: <T extends Annotation>(observer: StoreObserver<T>, event: StoreChangeEvent<T>) => boolean;
52
+ export declare const mergeChanges: <T extends Annotation>(changes: ChangeSet<T>, toMerge: ChangeSet<T>) => {
53
+ created: T[];
54
+ deleted: T[];
55
+ updated: Update<T>[];
56
+ };
57
+ //# sourceMappingURL=StoreObserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoreObserver.d.ts","sourceRoot":"","sources":["../../src/state/StoreObserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGxF,kEAAkE;AAClE,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,UAAU;IAEjD,QAAQ,EAAE;QAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;KAAE,CAAC;IAEjD,OAAO,EAAE,mBAAmB,CAAC;CAE9B;AAED,yDAAyD;AACzD,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,UAAU;IAEpD,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAEtB,KAAK,EAAE,CAAC,EAAE,CAAC;CAEZ;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,UAAU;IAE7C,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;IAEd,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;IAEd,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;CAEvB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,UAAU;IAE1C,QAAQ,EAAE,CAAC,CAAC;IAEZ,QAAQ,EAAE,CAAC,CAAC;IAEZ,aAAa,CAAC,EAAE,cAAc,EAAE,CAAC;IAEjC,aAAa,CAAC,EAAE,cAAc,EAAE,CAAC;IAEjC,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,cAAc,CAAA;KAAE,CAAC,CAAC;IAE5E,aAAa,CAAC,EAAE;QAAE,SAAS,EAAE,gBAAgB,CAAC;QAAC,SAAS,EAAE,gBAAgB,CAAA;KAAC,CAAC;CAE7E;AAED,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAGlC,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAGhC,MAAM,CAAC,EAAE,MAAM,CAAA;CAEhB;AAED,yDAAyD;AACzD,oBAAY,MAAM;IAGhB,SAAS,cAAc;IAGvB,WAAW,gBAAgB;CAE5B;AAED,qGAAqG;AACrG,oBAAY,MAAM;IAEhB,KAAK,UAAU;IAEf,MAAM,WAAW;CAElB;AAED,kEAAkE;AAClE,eAAO,MAAM,YAAY,mCAAoC,cAAc,CAAC,CAAC,SAAS,iBAAiB,CAAC,CAAC,YAiDxG,CAAA;AAED,eAAO,MAAM,YAAY,kCAAmC,UAAU,CAAC,CAAC,WAAW,UAAU,CAAC,CAAC;;;;CAyD9F,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { Annotation, Annotator, AnnotatorState } from '../model';
2
+ import type { Store } from './Store';
3
+ type Subscriber<T extends Annotation> = (annotation: T[]) => void;
4
+ export interface SvelteStore<T extends Annotation> extends Store<T> {
5
+ subscribe(onChange: Subscriber<T>): void;
6
+ }
7
+ export interface SvelteAnnotatorState<T extends Annotation> extends AnnotatorState<T> {
8
+ store: SvelteStore<T>;
9
+ }
10
+ export interface SvelteAnnotator<T extends Annotation> extends Annotator<T> {
11
+ state: SvelteAnnotatorState<T>;
12
+ }
13
+ /**
14
+ * A simple wrapper around the event-based store implementation
15
+ * that adds a Svelte shim, for use with the reactive '$' notation.
16
+ * Other frameworks might not actually need this. But it's pretty
17
+ * convenient for everyone using Svelte, as well as for the
18
+ * basic (Svelte-based) Annotorious standard implementation.
19
+ */
20
+ export declare const toSvelteStore: <T extends Annotation>(store: Store<T>) => SvelteStore<T>;
21
+ export {};
22
+ //# sourceMappingURL=SvelteStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SvelteStore.d.ts","sourceRoot":"","sources":["../../src/state/SvelteStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGrC,KAAK,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;AAElE,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IAEjE,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAE1C;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAEnF,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAEtB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAEzE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;CAE/B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,gCAAiC,MAAM,CAAC,CAAC,KAAG,YAAY,CAAC,CAsBlF,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { type Unsubscribe } from 'nanoevents';
2
+ import type { Annotation } from '../model';
3
+ import type { Store } from './Store';
4
+ import { type ChangeSet } from './StoreObserver';
5
+ export interface UndoStack<T extends Annotation> {
6
+ canRedo(): boolean;
7
+ canUndo(): boolean;
8
+ destroy(): void;
9
+ on<E extends keyof UndoStackEvents<T>>(event: E, callback: UndoStackEvents<T>[E]): Unsubscribe;
10
+ undo(): void;
11
+ redo(): void;
12
+ }
13
+ export interface UndoStackEvents<T extends Annotation> {
14
+ redo(change: ChangeSet<T>): void;
15
+ undo(change: ChangeSet<T>): void;
16
+ }
17
+ export declare const createUndoStack: <T extends Annotation>(store: Store<T>) => UndoStack<T>;
18
+ //# sourceMappingURL=UndoStack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UndoStack.d.ts","sourceRoot":"","sources":["../../src/state/UndoStack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAgB,KAAK,SAAS,EAAsC,MAAM,iBAAiB,CAAC;AAOnG,MAAM,WAAW,SAAS,CAAE,CAAC,SAAS,UAAU;IAE9C,OAAO,IAAI,OAAO,CAAC;IAEnB,OAAO,IAAI,OAAO,CAAC;IAEnB,OAAO,IAAI,IAAI,CAAC;IAEhB,EAAE,CAAC,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IAE/F,IAAI,IAAI,IAAI,CAAC;IAEb,IAAI,IAAI,IAAI,CAAC;CAEd;AAED,MAAM,WAAW,eAAe,CAAE,CAAC,SAAS,UAAU;IAEpD,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAEjC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAElC;AAED,eAAO,MAAM,eAAe,gCAAiC,MAAM,CAAC,CAAC,KAAG,UAAU,CAAC,CA2GlF,CAAA"}
@@ -0,0 +1,7 @@
1
+ /// <reference types="svelte" />
2
+ export type ViewportState = ReturnType<typeof createViewportState>;
3
+ export declare const createViewportState: () => {
4
+ subscribe: (this: void, run: import("svelte/store").Subscriber<string[]>, invalidate?: import("svelte/store").Invalidator<string[]> | undefined) => import("svelte/store").Unsubscriber;
5
+ set: (this: void, value: string[]) => void;
6
+ };
7
+ //# sourceMappingURL=Viewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Viewport.d.ts","sourceRoot":"","sources":["../../src/state/Viewport.ts"],"names":[],"mappings":";AAEA,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEnE,eAAO,MAAM,mBAAmB;;;CAS/B,CAAA"}
@@ -3,4 +3,6 @@ export * from './Selection';
3
3
  export * from './Store';
4
4
  export * from './StoreObserver';
5
5
  export * from './SvelteStore';
6
- export * from './Viewport';
6
+ export * from './UndoStack';
7
+ export * from './Viewport';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Annotation, AnnotationBody } from '../model/Annotation';
2
+ import type { User } from '../model/User';
3
+ /**
4
+ * Returns all users listed as creators or updaters in any parts of this
5
+ * annotation.
6
+ */
7
+ export declare const getContributors: (annotation: Annotation) => User[];
8
+ export declare const createBody: (annotation: Annotation, payload: {
9
+ [key: string]: any;
10
+ }, created?: Date, creator?: User) => AnnotationBody;
11
+ //# sourceMappingURL=annotationUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotationUtils.d.ts","sourceRoot":"","sources":["../../src/utils/annotationUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAG,IAAI,EAAE,MAAM,eAAe,CAAC;AAC3C;;;GAGG;AACH,eAAO,MAAM,eAAe,eAAgB,UAAU,KAAG,IAAI,EAY5D,CAAA;AAED,eAAO,MAAM,UAAU,eACT,UAAU;;aAEZ,IAAI,YACJ,IAAI,KACb,cAMD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Update } from '../state/StoreObserver';
2
+ import type { Annotation } from '../model/Annotation';
3
+ export declare const diffAnnotations: <T extends Annotation = Annotation>(oldValue: T, newValue: T) => Update<T>;
4
+ //# sourceMappingURL=diffAnnotations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diffAnnotations.d.ts","sourceRoot":"","sources":["../../src/utils/diffAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAwBtD,eAAO,MAAM,eAAe,gDAAiD,CAAC,YAAY,CAAC,KAAG,OAAO,CAAC,CAarG,CAAA"}
@@ -1,3 +1,3 @@
1
1
  export * from './annotationUtils';
2
2
  export * from './diffAnnotations';
3
-
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/core",
3
- "version": "3.0.0-rc.2",
3
+ "version": "3.0.0-rc.20",
4
4
  "description": "Annotorious core types and functions",
5
5
  "author": "Rainer Simon",
6
6
  "license": "BSD-3-Clause",
@@ -14,29 +14,32 @@
14
14
  "url": "https://github.com/annotorious/annotorious/issues"
15
15
  },
16
16
  "scripts": {
17
- "build": "echo 'Skipping build in @annotorious/core package'",
17
+ "build": "vite build",
18
18
  "test": "vitest",
19
19
  "coverage": "vitest run --coverage"
20
20
  },
21
- "main": "src/index.ts",
22
- "types": "src/index.ts",
21
+ "main": "./dist/annotorious-core.es.js",
22
+ "module": "./dist/annotorious-core.es.js",
23
+ "types": "./dist/index.d.ts",
23
24
  "files": [
24
- "src"
25
+ "dist"
25
26
  ],
26
27
  "devDependencies": {
27
- "@tsconfig/svelte": "^3.0.0",
28
- "@types/deep-equal": "^1.0.2",
29
- "@types/uuid": "^9.0.4",
30
- "svelte": "^3.59.2",
31
- "typescript": "^4.9.5",
32
- "vite": "^4.4.9",
33
- "vite-plugin-dts": "^3.6.0",
34
- "vitest": "^0.34.6"
28
+ "@sveltejs/vite-plugin-svelte": "^3.0.2",
29
+ "@tsconfig/svelte": "^5.0.2",
30
+ "@types/deep-equal": "^1.0.4",
31
+ "@types/uuid": "^9.0.8",
32
+ "svelte": "^4.2.12",
33
+ "svelte-preprocess": "^5.1.3",
34
+ "typescript": "^5.3.3",
35
+ "vite": "^5.2.2",
36
+ "vite-plugin-dts": "^3.7.3",
37
+ "vitest": "^1.4.0"
35
38
  },
36
39
  "dependencies": {
37
40
  "dequal": "^2.0.3",
38
- "nanoevents": "^8.0.0",
39
- "nanoid": "^5.0.1",
41
+ "nanoevents": "^9.0.0",
42
+ "nanoid": "^5.0.6",
40
43
  "uuid": "^9.0.1"
41
44
  }
42
45
  }
@@ -1,197 +0,0 @@
1
- import { dequal } from 'dequal/lite';
2
- import type { Annotation, FormatAdapter } from '../model';
3
- import { Origin } from '../state';
4
- import type { HoverState, SelectionState, Store, ViewportState } from '../state';
5
- import type { LifecycleEvents } from './LifecycleEvents';
6
-
7
- export type Lifecycle<I extends Annotation, E extends unknown> =
8
- ReturnType<typeof createLifecyleObserver<I, E>>;
9
-
10
- export const createLifecyleObserver = <I extends Annotation, E extends unknown>(
11
- store: Store<I>,
12
- selectionState: SelectionState<I>,
13
- hoverState: HoverState<I>,
14
- viewportState?: ViewportState,
15
- adapter?: FormatAdapter<I, E>,
16
- autoSave?: boolean
17
- ) => {
18
- const observers: Map<keyof LifecycleEvents, Function[]> = new Map();
19
-
20
- // The currently selected annotations, in the state when they were selected
21
- let initialSelection: I[] = [];
22
-
23
- let currentHover: string | undefined;
24
-
25
- let idleTimeout: ReturnType<typeof setTimeout>;
26
-
27
- const on = <T extends keyof LifecycleEvents>(event: T, callback: LifecycleEvents<E>[T]) => {
28
- if (observers.has(event)) {
29
- observers.get(event).push(callback);
30
- } else {
31
- observers.set(event, [callback]);
32
- }
33
- }
34
-
35
- const off = <T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]) => {
36
- const callbacks = observers.get(event);
37
- if (callbacks) {
38
- const idx = callbacks.indexOf(callback);
39
- if (idx > 0)
40
- callbacks.splice(callbacks.indexOf(callback), 1);
41
- }
42
- }
43
-
44
- const emit = (event: keyof LifecycleEvents<E>, arg0: I | I[], arg1?: I | PointerEvent) => {
45
- if (observers.has(event)) {
46
- setTimeout(() => {
47
- observers.get(event).forEach(callback => {
48
- if (adapter) {
49
- const serialized0 = Array.isArray(arg0) ?
50
- arg0.map(a => adapter.serialize(a)) : adapter.serialize(arg0);
51
-
52
- const serialized1: E | PointerEvent | undefined =
53
- arg1 ? arg1 instanceof PointerEvent ? arg1 : adapter.serialize(arg1) : undefined;
54
-
55
- callback(serialized0 as E & E[], serialized1);
56
- } else {
57
- callback(arg0 as E & E[], arg1 as unknown as E);
58
- }
59
- });
60
- }, 1);
61
- }
62
- }
63
-
64
- const onIdleUpdate = () => {
65
- const { selected } = selectionState;
66
-
67
- // User idle after activity - fire update events for selected
68
- // annotations that changed
69
- const updatedSelected = selected.map(({ id }) => store.getAnnotation(id));
70
-
71
- updatedSelected.forEach(updated => {
72
- const initial = initialSelection.find(a => a.id === updated.id);
73
- if (!initial || !dequal(initial, updated)) {
74
- emit('updateAnnotation', updated, initial);
75
- }
76
- });
77
-
78
- initialSelection = initialSelection.map(initial => {
79
- const updated = updatedSelected.find(({ id }) => id === initial.id);
80
- return updated ? updated : initial
81
- });
82
- }
83
-
84
- selectionState.subscribe(({ selected })=> {
85
- if (initialSelection.length === 0 && selected.length === 0)
86
- return;
87
-
88
- if (initialSelection.length === 0 && selected.length > 0) {
89
- // A new selection was made - store the editable annotation as initial state
90
- initialSelection = selected.map(({ id }) => store.getAnnotation(id));
91
- } else if (initialSelection.length > 0 && selected.length === 0) {
92
- // Deselect!
93
- initialSelection.forEach(initial => {
94
- const updatedState = store.getAnnotation(initial.id);
95
-
96
- if (updatedState && !dequal(updatedState, initial)) {
97
- emit('updateAnnotation', updatedState, initial);
98
- }
99
- });
100
-
101
- initialSelection = [];
102
- } else {
103
- // Changed selection
104
- const initialIds = new Set(initialSelection.map(a => a.id));
105
- const selectedIds = new Set(selected.map(({ id }) => id));
106
-
107
- // Fire update events for deselected annotations that have changed
108
- const deselected = initialSelection.filter(a => !selectedIds.has(a.id));
109
- deselected.forEach(initial => {
110
- const updatedState = store.getAnnotation(initial.id);
111
-
112
- if (updatedState && !dequal(updatedState, initial))
113
- emit('updateAnnotation', updatedState, initial);
114
- });
115
-
116
- initialSelection = [
117
- // Remove annotations that were deselected
118
- ...initialSelection.filter(a => selectedIds.has(a.id)),
119
- // Add editable annotations that were selected
120
- ...selected.filter(({ id }) => !initialIds.has(id))
121
- .map(({ id }) => store.getAnnotation(id))
122
- ];
123
- }
124
-
125
- emit('selectionChanged', initialSelection);
126
- });
127
-
128
- hoverState.subscribe(id => {
129
- if (!currentHover && id) {
130
- emit('mouseEnterAnnotation', store.getAnnotation(id));
131
- } else if (currentHover && !id) {
132
- emit('mouseLeaveAnnotation', store.getAnnotation(currentHover));
133
- } else if (currentHover && id) {
134
- emit('mouseLeaveAnnotation', store.getAnnotation(currentHover));
135
- emit('mouseEnterAnnotation', store.getAnnotation(id));
136
- }
137
-
138
- currentHover = id;
139
- });
140
-
141
- viewportState?.subscribe(ids =>
142
- emit('viewportIntersect', ids.map(store.getAnnotation)));
143
-
144
- store.observe(event => {
145
- // autoSave option triggers update events on idleness
146
- if (autoSave) {
147
- if (idleTimeout)
148
- clearTimeout(idleTimeout);
149
-
150
- idleTimeout = setTimeout(onIdleUpdate, 1000);
151
- }
152
-
153
- // Local CREATE and DELETE events are applied immediately
154
- const { created, deleted } = event.changes;
155
- created.forEach(a => emit('createAnnotation', a));
156
- deleted.forEach(a => emit('deleteAnnotation', a));
157
-
158
- // Updates are only applied immediately if they involve body changes
159
- const updatesWithBody = event.changes.updated.filter(u => [
160
- ...(u.bodiesCreated || []),
161
- ...(u.bodiesDeleted || []),
162
- ...(u.bodiesUpdated || [])
163
- ].length > 0);
164
-
165
- // Emit an update with the new annototation and the stored initial state
166
- updatesWithBody.forEach(({ oldValue, newValue }) => {
167
- const initial = initialSelection.find(a => a.id === oldValue.id) || oldValue;
168
-
169
- // Record the update as the new last known state
170
- initialSelection = initialSelection
171
- .map(a => a.id === oldValue.id ? newValue : a);
172
-
173
- emit('updateAnnotation', newValue, initial);
174
- });
175
- }, { origin: Origin.LOCAL });
176
-
177
- // Track remote changes - these should update the initial state
178
- store.observe(event => {
179
- if (initialSelection) {
180
- const selectedIds = new Set(initialSelection.map(a => a.id));
181
-
182
- const relevantUpdates = event.changes.updated
183
- .filter(({ newValue }) => selectedIds.has(newValue.id))
184
- .map(({ newValue }) => newValue);
185
-
186
- if (relevantUpdates.length > 0) {
187
- initialSelection = initialSelection.map(selected => {
188
- const updated = relevantUpdates.find(updated => updated.id === selected.id);
189
- return updated ? updated : selected;
190
- })
191
- }
192
- }
193
- }, { origin: Origin.REMOTE });
194
-
195
- return { on, off, emit }
196
-
197
- }
@@ -1,21 +0,0 @@
1
- import type { Annotation } from '../model';
2
-
3
- export interface LifecycleEvents<T extends unknown = Annotation> {
4
-
5
- clickAnnotation: (annotation: T, originalEvent: PointerEvent) => void;
6
-
7
- createAnnotation: (annotation: T) => void;
8
-
9
- deleteAnnotation: (annotation: T) => void;
10
-
11
- mouseEnterAnnotation: (annotation: T) => void;
12
-
13
- mouseLeaveAnnotation: (annotation: T) => void;
14
-
15
- selectionChanged: (annotation: T[]) => void;
16
-
17
- updateAnnotation: (annotation: T, previous: T) => void;
18
-
19
- viewportIntersect: (visible: T[]) => void;
20
-
21
- }
@@ -1,2 +0,0 @@
1
- export * from './Lifecycle';
2
- export * from './LifecycleEvents';