@annotorious/core
Advanced tools
Comparing version 3.0.18 to 3.0.19
@@ -84,5 +84,5 @@ var M = Object.prototype.hasOwnProperty; | ||
return !1; | ||
const y = typeof h == "string" ? h : h.id; | ||
return A.selected.some((D) => D.id === y); | ||
}, U = (h, y) => { | ||
const C = typeof h == "string" ? h : h.id; | ||
return A.selected.some((D) => D.id === C); | ||
}, U = (h, C) => { | ||
let D; | ||
@@ -106,8 +106,8 @@ if (Array.isArray(h)) { | ||
}, []); | ||
s({ selected: a, event: y }); | ||
}, c = (h, y) => { | ||
s({ selected: a, event: C }); | ||
}, c = (h, C) => { | ||
const D = Array.isArray(h) ? h : [h], a = D.map((i) => e.getAnnotation(i)).filter((i) => !!i); | ||
s({ | ||
selected: a.map((i) => { | ||
const p = y === void 0 ? W(i, f, n) === "EDIT" : y; | ||
const p = C === void 0 ? W(i, f, n) === "EDIT" : C; | ||
return { id: i.id, editable: p }; | ||
@@ -119,7 +119,7 @@ }) | ||
return !1; | ||
const { selected: y } = A; | ||
y.some(({ id: a }) => h.includes(a)) && s({ selected: y.filter(({ id: a }) => !h.includes(a)) }); | ||
const { selected: C } = A; | ||
C.some(({ id: a }) => h.includes(a)) && s({ selected: C.filter(({ id: a }) => !h.includes(a)) }); | ||
}, T = (h) => f = h; | ||
return e.observe( | ||
({ changes: h }) => E((h.deleted || []).map((y) => y.id)) | ||
({ changes: h }) => E((h.deleted || []).map((C) => C.id)) | ||
), { | ||
@@ -247,3 +247,3 @@ get event() { | ||
if (A.has(T.id)) { | ||
const h = t.updated.find((y) => y.oldValue.id === T.id).newValue; | ||
const h = t.updated.find((C) => C.oldValue.id === T.id).newValue; | ||
return J(E, h); | ||
@@ -299,4 +299,4 @@ } else | ||
if (S) { | ||
const C = J(S, u); | ||
return g === u.id ? e.set(g, u) : (e.delete(g), e.set(u.id, u)), S.bodies.forEach((x) => t.delete(x.id)), u.bodies.forEach((x) => t.set(x.id, u.id)), C; | ||
const y = J(S, u); | ||
return g === u.id ? e.set(g, u) : (e.delete(g), e.set(u.id, u)), S.bodies.forEach((x) => t.delete(x.id)), u.bodies.forEach((x) => t.set(x.id, u.id)), y; | ||
} else | ||
@@ -309,4 +309,4 @@ console.warn(`Cannot update annotation ${g} - does not exist`); | ||
const u = d.reduce((g, S) => { | ||
const C = b(S); | ||
return C ? [...g, C] : g; | ||
const y = b(S); | ||
return y ? [...g, y] : g; | ||
}, []); | ||
@@ -335,14 +335,14 @@ u.length > 0 && f(l, { updated: u }); | ||
const S = [...e.values()]; | ||
e.clear(), t.clear(), g.forEach((C) => { | ||
e.set(C.id, C), C.bodies.forEach((x) => t.set(x.id, C.id)); | ||
e.clear(), t.clear(), g.forEach((y) => { | ||
e.set(y.id, y), y.bodies.forEach((x) => t.set(x.id, y.id)); | ||
}), f(u, { created: g, deleted: S }); | ||
} else { | ||
const S = d.reduce((C, x) => { | ||
const S = d.reduce((y, x) => { | ||
const H = x.id && e.get(x.id); | ||
return H ? [...C, H] : C; | ||
return H ? [...y, H] : y; | ||
}, []); | ||
if (S.length > 0) | ||
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((C) => C.id).join(", ")}`); | ||
g.forEach((C) => { | ||
e.set(C.id, C), C.bodies.forEach((x) => t.set(x.id, C.id)); | ||
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((y) => y.id).join(", ")}`); | ||
g.forEach((y) => { | ||
e.set(y.id, y), y.bodies.forEach((x) => t.set(x.id, y.id)); | ||
}), f(u, { created: g }); | ||
@@ -355,3 +355,3 @@ } | ||
console.warn(`Attempt to delete missing annotation: ${l}`); | ||
}, y = (d, l = O.LOCAL) => { | ||
}, C = (d, l = O.LOCAL) => { | ||
const u = h(d); | ||
@@ -361,4 +361,4 @@ u && f(l, { deleted: [u] }); | ||
const u = d.reduce((g, S) => { | ||
const C = h(S); | ||
return C ? [...g, C] : g; | ||
const y = h(S); | ||
return y ? [...g, y] : g; | ||
}, []); | ||
@@ -374,3 +374,3 @@ u.length > 0 && f(l, { deleted: u }); | ||
...l, | ||
bodies: l.bodies.filter((C) => C.id !== d.id) | ||
bodies: l.bodies.filter((y) => y.id !== d.id) | ||
}; | ||
@@ -409,5 +409,5 @@ return e.set(l.id, g), { | ||
if (u) { | ||
const g = u.bodies.find((C) => C.id === d.id), S = { | ||
const g = u.bodies.find((y) => y.id === d.id), S = { | ||
...u, | ||
bodies: u.bodies.map((C) => C.id === g.id ? l : C) | ||
bodies: u.bodies.map((y) => y.id === g.id ? l : y) | ||
}; | ||
@@ -462,3 +462,3 @@ return e.set(u.id, S), g.id !== l.id && (t.delete(g.id), t.set(l.id, S.id)), { | ||
clear: E, | ||
deleteAnnotation: y, | ||
deleteAnnotation: C, | ||
deleteBody: i, | ||
@@ -498,4 +498,4 @@ getAnnotation: v, | ||
const le = 250, Be = (e, t) => { | ||
const n = Q(), o = t || []; | ||
let s = o.length - 1, f = !1, A = 0; | ||
const n = Q(), o = (t == null ? void 0 : t.changes) || []; | ||
let s = t ? t.pointer : -1, f = !1, A = 0; | ||
const b = (r) => { | ||
@@ -520,3 +520,3 @@ if (!f) { | ||
destroy: () => e.unobserve(b), | ||
getHistory: () => [...o], | ||
getHistory: () => ({ changes: [...o], pointer: s }), | ||
on: (r, L) => n.on(r, L), | ||
@@ -565,3 +565,3 @@ redo: () => { | ||
}, 1); | ||
}, y = () => { | ||
}, C = () => { | ||
const { selected: a } = f, i = (a || []).map(({ id: p }) => A.getAnnotation(p)); | ||
@@ -602,3 +602,3 @@ i.forEach((p) => { | ||
}), b == null || b.subscribe((a) => h("viewportIntersect", a.map((i) => A.getAnnotation(i)))), A.observe((a) => { | ||
o && (c && clearTimeout(c), c = setTimeout(y, 1e3)); | ||
o && (c && clearTimeout(c), c = setTimeout(C, 1e3)); | ||
const { created: i, deleted: p } = a.changes; | ||
@@ -670,3 +670,3 @@ (i || []).forEach((r) => h("createAnnotation", r)), (p || []).forEach((r) => h("deleteAnnotation", r)), (a.changes.updated || []).filter((r) => [ | ||
a ? s.setSelected(a, i) : s.clear(); | ||
}, y = (a) => { | ||
}, C = (a) => { | ||
s.clear(), s.setUserSelectAction(a); | ||
@@ -697,3 +697,3 @@ }, D = (a) => { | ||
setSelected: h, | ||
setUserSelectAction: y, | ||
setUserSelectAction: C, | ||
undo: t.undo, | ||
@@ -792,3 +792,3 @@ updateAnnotation: D | ||
}, removeUser: (o) => e.releaseColor(o.appearance.color) }; | ||
}, ye = (e, t) => e.every((n) => e.includes(n)) && t.every((n) => e.includes(n)), je = me(), Pe = (e = we()) => { | ||
}, Ce = (e, t) => e.every((n) => e.includes(n)) && t.every((n) => e.includes(n)), je = me(), Pe = (e = we()) => { | ||
const t = Q(), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = (c, E) => { | ||
@@ -813,6 +813,6 @@ if (n.has(c)) { | ||
}, A = (c) => { | ||
const E = new Set(c.map((y) => y.presenceKey)), T = c.filter(({ presenceKey: y }) => !n.has(y)), h = Array.from(n.values()).filter((y) => !E.has(y.presenceKey)); | ||
T.forEach(({ presenceKey: y, user: D }) => s(y, D)), h.forEach((y) => { | ||
const { presenceKey: D } = y; | ||
o.has(D) && t.emit("selectionChange", y, null), f(D); | ||
const E = new Set(c.map((C) => C.presenceKey)), T = c.filter(({ presenceKey: C }) => !n.has(C)), h = Array.from(n.values()).filter((C) => !E.has(C.presenceKey)); | ||
T.forEach(({ presenceKey: C, user: D }) => s(C, D)), h.forEach((C) => { | ||
const { presenceKey: D } = C; | ||
o.has(D) && t.emit("selectionChange", C, null), f(D); | ||
}), (T.length > 0 || h.length > 0) && t.emit("presence", m()); | ||
@@ -826,3 +826,3 @@ }, b = (c, E) => { | ||
const h = o.get(c); | ||
(!h || !ye(h, E)) && (o.set(c, E), t.emit("selectionChange", T, E)); | ||
(!h || !Ce(h, E)) && (o.set(c, E), t.emit("selectionChange", T, E)); | ||
}, w = (c, E) => { | ||
@@ -829,0 +829,0 @@ const T = n.get(c); |
import { Annotation } from './Annotation'; | ||
import { User } from './User'; | ||
import { PresenceProvider } from '../presence'; | ||
import { ChangeSet, HoverState, SelectionState, Store, UndoStack, UserSelectActionExpression, ViewportState } from '../state'; | ||
import { History, HoverState, SelectionState, Store, UndoStack, UserSelectActionExpression, ViewportState } from '../state'; | ||
import { LifecycleEvents } from '../lifecycle'; | ||
@@ -23,3 +23,3 @@ import { FormatAdapter } from './FormatAdapter'; | ||
getAnnotations(): E[]; | ||
getHistory(): ChangeSet<I>[]; | ||
getHistory(): History<I>; | ||
getSelected(): E[]; | ||
@@ -58,3 +58,3 @@ getUser(): User; | ||
getAnnotations: () => E[]; | ||
getHistory: () => ChangeSet<I>[]; | ||
getHistory: () => History<I>; | ||
getSelected: () => E[]; | ||
@@ -61,0 +61,0 @@ loadAnnotations: (url: string, replace?: boolean) => Promise<any>; |
@@ -9,3 +9,3 @@ import { Unsubscribe } from 'nanoevents'; | ||
destroy(): void; | ||
getHistory(): ChangeSet<T>[]; | ||
getHistory(): History<T>; | ||
on<E extends keyof UndoStackEvents<T>>(event: E, callback: UndoStackEvents<T>[E]): Unsubscribe; | ||
@@ -19,3 +19,7 @@ undo(): void; | ||
} | ||
export declare const createUndoStack: <T extends Annotation>(store: Store<T>, history?: ChangeSet<T>[]) => UndoStack<T>; | ||
export interface History<T extends Annotation> { | ||
changes: ChangeSet<T>[]; | ||
pointer: number; | ||
} | ||
export declare const createUndoStack: <T extends Annotation>(store: Store<T>, history?: History<T>) => UndoStack<T>; | ||
//# sourceMappingURL=UndoStack.d.ts.map |
{ | ||
"name": "@annotorious/core", | ||
"version": "3.0.18", | ||
"version": "3.0.19", | ||
"description": "Annotorious core types and functions", | ||
@@ -37,3 +37,3 @@ "author": "Rainer Simon", | ||
"vite-plugin-dts": "^4.3.0", | ||
"vitest": "^2.1.6" | ||
"vitest": "^2.1.8" | ||
}, | ||
@@ -40,0 +40,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
190935
1373