Select Git revision
AnnotationDrawing.js
Forked from
IIIF / Mirador / Mirador annotations
Source project has a limited visibility.
-
Loïs Poujade authored
- if no Openseadragon instance, use a VideoViewerReference (based on OSDReferences) to get canvas size & DOM element - add 2 number fields to specify annotation start/end - speed up build by removing umd (not used in our dev setup) and demo build - remove conflicting dependencies Both removed dependencies are installed at a lower version by another dependence (immutable is installed by draft-js-*)
Loïs Poujade authored- if no Openseadragon instance, use a VideoViewerReference (based on OSDReferences) to get canvas size & DOM element - add 2 number fields to specify annotation start/end - speed up build by removing umd (not used in our dev setup) and demo build - remove conflicting dependencies Both removed dependencies are installed at a lower version by another dependence (immutable is installed by draft-js-*)
LocalStorageAdapter.js 1.50 KiB
/** */
export default class LocalStorageAdapter {
/** */
constructor(annotationPageId) {
this.annotationPageId = annotationPageId;
}
/** */
async create(annotation) {
const emptyAnnoPage = {
id: this.annotationPageId,
items: [],
type: 'AnnotationPage',
};
const annotationPage = await this.all() || emptyAnnoPage;
annotationPage.items.push(annotation);
localStorage.setItem(this.annotationPageId, JSON.stringify(annotationPage));
return annotationPage;
}
/** */
async update(annotation) {
const annotationPage = await this.all();
if (annotationPage) {
const currentIndex = annotationPage.items.findIndex((item) => item.id === annotation.id);
annotationPage.items.splice(currentIndex, 1, annotation);
localStorage.setItem(this.annotationPageId, JSON.stringify(annotationPage));
return annotationPage;
}
return null;
}
/** */
async delete(annoId) {
const annotationPage = await this.all();
if (annotationPage) {
annotationPage.items = annotationPage.items.filter((item) => item.id !== annoId);
}
localStorage.setItem(this.annotationPageId, JSON.stringify(annotationPage));
return annotationPage;
}
/** */
async get(annoId) {
const annotationPage = await this.all();
if (annotationPage) {
return annotationPage.items.find((item) => item.id === annoId);
}
return null;
}
/** */
async all() {
return JSON.parse(localStorage.getItem(this.annotationPageId));
}
}