@annotorious/core
Advanced tools
Comparing version 3.0.0-pre-alpha-47 to 3.0.0-pre-alpha-48
{ | ||
"name": "@annotorious/core", | ||
"version": "3.0.0-pre-alpha-47", | ||
"version": "3.0.0-pre-alpha-48", | ||
"description": "Annotorious core types and functions", | ||
@@ -28,16 +28,16 @@ "author": "Rainer Simon", | ||
"@tsconfig/svelte": "^3.0.0", | ||
"@types/deep-equal": "^1.0.1", | ||
"@types/uuid": "^9.0.1", | ||
"svelte": "^3.58.0", | ||
"@types/deep-equal": "^1.0.2", | ||
"@types/uuid": "^9.0.4", | ||
"svelte": "^3.59.2", | ||
"typescript": "^4.9.5", | ||
"vite": "^4.2.1", | ||
"vite-plugin-dts": "^2.3.0", | ||
"vitest": "^0.29.3" | ||
"vite": "^4.4.9", | ||
"vite-plugin-dts": "^3.6.0", | ||
"vitest": "^0.34.6" | ||
}, | ||
"dependencies": { | ||
"dequal": "^2.0.3", | ||
"nanoevents": "^7.0.1", | ||
"nanoid": "^4.0.1", | ||
"uuid": "^9.0.0" | ||
"nanoevents": "^8.0.0", | ||
"nanoid": "^5.0.1", | ||
"uuid": "^9.0.1" | ||
} | ||
} |
import { dequal } from 'dequal/lite'; | ||
import type { Annotation, FormatAdapter, W3CAnnotation } from '../model'; | ||
import type { Annotation, FormatAdapter } from '../model'; | ||
import { Origin } from '../state'; | ||
@@ -7,15 +7,16 @@ import type { HoverState, SelectionState, Store, ViewportState } from '../state'; | ||
export type Lifecycle<T extends Annotation> = ReturnType<typeof createLifecyleObserver<T>>; | ||
export type Lifecycle<I extends Annotation, E extends unknown> = | ||
ReturnType<typeof createLifecyleObserver<I, E>>; | ||
export const createLifecyleObserver = <T extends Annotation, A extends unknown = W3CAnnotation>( | ||
store: Store<T>, | ||
selectionState: SelectionState<T>, | ||
hoverState: HoverState<T>, | ||
export const createLifecyleObserver = <I extends Annotation, E extends unknown>( | ||
store: Store<I>, | ||
selectionState: SelectionState<I>, | ||
hoverState: HoverState<I>, | ||
viewportState?: ViewportState, | ||
adapter?: FormatAdapter<T, A> | ||
adapter?: FormatAdapter<I, E> | ||
) => { | ||
const observers = new Map<string, LifecycleEvents<A>[keyof LifecycleEvents<T>][]>(); | ||
const observers = new Map<string, LifecycleEvents<E>[keyof LifecycleEvents<E>][]>(); | ||
// The currently selected annotations, in the state when they were selected | ||
let initialSelection: T[] = []; | ||
let initialSelection: I[] = []; | ||
@@ -26,3 +27,3 @@ let currentHover: string | undefined; | ||
const on = <E extends keyof LifecycleEvents<T>>(event: E, callback: LifecycleEvents<A>[E]) => { | ||
const on = <T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]) => { | ||
if (observers.has(event)) { | ||
@@ -35,3 +36,3 @@ observers.get(event).push(callback); | ||
const off = <E extends keyof LifecycleEvents<T>>(event: E, callback: LifecycleEvents<A>[E]) => { | ||
const off = <T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]) => { | ||
const callbacks = observers.get(event); | ||
@@ -45,3 +46,3 @@ if (callbacks) { | ||
const emit = (event: keyof LifecycleEvents<T>, arg0: T | T[], arg1: T = null) => { | ||
const emit = (event: keyof LifecycleEvents<E>, arg0: I | I[], arg1: I = null) => { | ||
if (observers.has(event)) { | ||
@@ -56,5 +57,5 @@ setTimeout(() => { | ||
callback(serialized0 as A & A[], serialized1); | ||
callback(serialized0 as E & E[], serialized1); | ||
} else { | ||
callback(arg0 as A & A[], arg1 as unknown as A); | ||
callback(arg0 as E & E[], arg1 as unknown as E); | ||
} | ||
@@ -61,0 +62,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import type { Annotation } from './core/Annotation'; | ||
import type { Annotation } from './Annotation'; | ||
@@ -3,0 +3,0 @@ export interface FormatAdapter<A extends Annotation, T extends unknown> { |
@@ -1,3 +0,6 @@ | ||
export * from './core'; | ||
export * from './w3c'; | ||
export * from './FormatAdapter'; | ||
export * from './Annotation'; | ||
export * from './Annotator'; | ||
export * from './FormatAdapter'; | ||
export * from './Formatter'; | ||
export * from './User'; |
import { v4 as uuidv4 } from 'uuid'; | ||
import type { AnnotationBody } from '../core'; | ||
import type { AnnotationBody } from '../Annotation'; | ||
@@ -4,0 +4,0 @@ export interface W3CAnnotation { |
@@ -1,7 +0,25 @@ | ||
import type { Annotation } from '../model'; | ||
import { createStore } from './Store'; | ||
import type { Annotation, Annotator, AnnotatorState } from '../model'; | ||
import type { Store } from './Store'; | ||
import type { StoreChangeEvent } from './StoreObserver'; | ||
type Subscriber = <T extends Annotation>(annotation: T[]) => void; | ||
type Subscriber<T extends Annotation> = (annotation: T[]) => void; | ||
export interface SvelteStore<T extends Annotation> extends Store<T> { | ||
subscribe(onChange: Subscriber<T>): void; | ||
} | ||
export interface SvelteAnnotatorState<T extends Annotation> extends AnnotatorState<T> { | ||
store: SvelteStore<T> | ||
} | ||
export interface SvelteAnnotator<T extends Annotation> extends Annotator<T> { | ||
state: SvelteAnnotatorState<T> | ||
} | ||
/** | ||
@@ -14,8 +32,6 @@ * A simple wrapper around the event-based store implementation | ||
*/ | ||
export const createSvelteStore = <T extends Annotation>() => { | ||
export const toSvelteStore = <T extends Annotation>(store: Store<T>): SvelteStore<T> => { | ||
const store = createStore<T>(); | ||
const subscribe = (onChange: Subscriber<T>) => { | ||
const subscribe = (onChange: Subscriber) => { | ||
// Register a store observer on behalf of the subscriber | ||
@@ -22,0 +38,0 @@ const shim = (event: StoreChangeEvent<T>) => onChange(event.state); |
@@ -1,4 +0,3 @@ | ||
export * from './bodyUtils'; | ||
export * from './collaboratorUtils'; | ||
export * from './annotationUtils'; | ||
export * from './diffAnnotations'; | ||
42274
1043
33
+ Addednanoevents@8.0.0(transitive)
+ Addednanoid@5.0.9(transitive)
- Removednanoevents@7.0.1(transitive)
- Removednanoid@4.0.2(transitive)
Updatednanoevents@^8.0.0
Updatednanoid@^5.0.1
Updateduuid@^9.0.1