bdsa-react-components 0.1.2 → 0.1.3

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,6 +1,6 @@
1
1
  # bdsa-react-components - CURSOR Integration Guide
2
2
 
3
- **Version:** 0.1.2 | **Generated:** 2025-11-01T20:15:49.818Z
3
+ **Version:** 0.1.3 | **Generated:** 2025-11-01T22:49:22.223Z
4
4
 
5
5
  > This document provides everything Cursor needs to integrate and use the bdsa-react-components library.
6
6
  > Copy this entire document into your project's .cursorrules or docs folder.
@@ -217,7 +217,33 @@ const fetchWithAuth = async (url: string, options?: RequestInit) => {
217
217
  />
218
218
  ```
219
219
 
220
- ### 2. SlideViewer with API-Fetched Annotations
220
+ ### 2. SlideViewer with API-Fetched Annotations (RECOMMENDED)
221
+
222
+ **Recommended approach:** Use `onLoadedAnnotationIdsChange` to sync annotation state:
223
+
224
+ ```tsx
225
+ const [annotationIds, setAnnotationIds] = useState<string[]>([])
226
+ const imageId = '6903df8dd26a6d93de19a9b2'
227
+
228
+ <>
229
+ <AnnotationManager
230
+ imageId={imageId}
231
+ apiBaseUrl="http://bdsa.pathology.emory.edu:8080/api/v1"
232
+ onLoadedAnnotationIdsChange={(ids) => {
233
+ // Automatically syncs when user loads/unloads annotations
234
+ setAnnotationIds(ids)
235
+ }}
236
+ />
237
+ <SlideViewer
238
+ imageInfo={{ dziUrl: `.../item/${imageId}/tiles/dzi.dzi` }}
239
+ annotationIds={annotationIds}
240
+ apiBaseUrl="http://bdsa.pathology.emory.edu:8080/api/v1"
241
+ height="800px"
242
+ />
243
+ </>
244
+ ```
245
+
246
+ **Alternative (legacy):** Using `onAnnotationsLoaded` - requires manual ID extraction:
221
247
 
222
248
  ```tsx
223
249
  const [annotationIds, setAnnotationIds] = useState<string[]>([])
@@ -238,6 +264,12 @@ const imageId = '6903df8dd26a6d93de19a9b2'
238
264
  </>
239
265
  ```
240
266
 
267
+ **Additional callbacks available:**
268
+
269
+ - `onAnnotationLoad(id, data?)` - Fires when an annotation is loaded
270
+ - `onAnnotationHide(id)` - Fires when an annotation is hidden/unloaded
271
+ - `onAnnotationOpacityChange(id, opacity)` - Fires when opacity changes
272
+
241
273
  ### 3. FolderBrowser
242
274
 
243
275
  ```tsx
@@ -279,6 +311,67 @@ const imageId = '6903df8dd26a6d93de19a9b2'
279
311
  - Ensure `dist/index.d.ts` exists in the library
280
312
  - Restart TypeScript server in your editor (VS Code: Cmd+Shift+P → "TypeScript: Restart TS Server")
281
313
 
314
+ ## Annotation Caching
315
+
316
+ The library includes automatic IndexedDB-based caching for annotation documents to speed up loading and reduce server requests.
317
+
318
+ ### Auto-Enabled Caching
319
+
320
+ Both `AnnotationManager` and `SlideViewer` automatically create and use an `IndexedDBAnnotationCache` instance by default. This provides:
321
+
322
+ - **Persistent caching** across page refreshes (uses IndexedDB, 50MB+ capacity)
323
+ - **Automatic cache validation** using version hashes from annotation headers
324
+ - **Per-annotation cache indicators** (database icon) when cached
325
+ - **Per-annotation cache bypass** (refresh icon) to clear and reload specific annotations
326
+
327
+ ### Disabling Cache
328
+
329
+ To disable caching globally for debugging:
330
+
331
+ ```tsx
332
+ <AnnotationManager
333
+ imageId="..."
334
+ apiBaseUrl="..."
335
+ disableCache={true} // Disables all caching
336
+ />
337
+ <SlideViewer
338
+ annotationIds={[...]}
339
+ disableCache={true} // Disables all caching
340
+ />
341
+ ```
342
+
343
+ ### Cache Implementation
344
+
345
+ ```tsx
346
+ import { IndexedDBAnnotationCache, MemoryAnnotationCache } from 'bdsa-react-components'
347
+
348
+ // Use a specific cache implementation (optional)
349
+ const cache = new IndexedDBAnnotationCache()
350
+ <AnnotationManager annotationCache={cache} ... />
351
+ <SlideViewer annotationCache={cache} ... />
352
+ ```
353
+
354
+ ### Cache Utilities
355
+
356
+ ```tsx
357
+ import { checkIndexedDBQuota, requestPersistentStorage, logQuotaInfo } from 'bdsa-react-components'
358
+
359
+ // Check cache quota and usage
360
+ const quotaInfo = await checkIndexedDBQuota()
361
+ if (quotaInfo) {
362
+ console.log(`Usage: ${quotaInfo.usagePercent.toFixed(1)}%`)
363
+ console.log(`Available: ${quotaInfo.available} bytes`)
364
+ }
365
+
366
+ // Request persistent storage (prevents browser cleanup)
367
+ await requestPersistentStorage()
368
+
369
+ // Log quota info in readable format
370
+ await logQuotaInfo()
371
+ ```
372
+
373
+ **Note:** IndexedDB storage limits are automatically managed by the browser. When quota is exceeded, the browser will prompt the user for permission to expand storage.
374
+
282
375
  ## Dependencies
283
376
 
284
377
  **Peer:** react ^18.0.0, react-dom ^18.0.0
@@ -47,6 +47,30 @@ export interface AnnotationManagerProps {
47
47
  onAnnotationOpacityChange?: (annotationId: string, opacity: number) => void;
48
48
  /** Callback when annotation has finished loading and is ready (called by SlideViewer after rendering) */
49
49
  onAnnotationReady?: (annotationId: string) => void;
50
+ /**
51
+ * Callback fired whenever the list of loaded annotation IDs changes.
52
+ * This is called when:
53
+ * - User clicks "Load" on an annotation
54
+ * - User clicks "Hide" on an annotation
55
+ * - Annotations are unloaded
56
+ *
57
+ * @param annotationIds - Array of currently loaded annotation IDs
58
+ */
59
+ onLoadedAnnotationIdsChange?: (annotationIds: string[]) => void;
60
+ /**
61
+ * Callback fired when an individual annotation is loaded.
62
+ * Useful for tracking which specific annotation was just loaded.
63
+ *
64
+ * @param annotationId - The ID of the annotation that was loaded
65
+ * @param annotationData - The full annotation document (optional, for performance)
66
+ */
67
+ onAnnotationLoad?: (annotationId: string, annotationData?: unknown) => void;
68
+ /**
69
+ * Callback fired when an individual annotation is hidden/unloaded.
70
+ *
71
+ * @param annotationId - The ID of the annotation that was hidden
72
+ */
73
+ onAnnotationHide?: (annotationId: string) => void;
50
74
  /** Map of annotation IDs to their loaded state */
51
75
  loadedAnnotations?: Set<string>;
52
76
  /** Map of annotation IDs to their visibility state */
@@ -1 +1 @@
1
- {"version":3,"file":"AnnotationManager.d.ts","sourceRoot":"","sources":["../../../src/components/AnnotationManager/AnnotationManager.tsx"],"names":[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AAO,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,EAAE;QACpC,WAAW,EAAE,sBAAsB,EAAE,CAAA;QACrC,OAAO,EAAE,OAAO,CAAA;QAChB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;QACnB,aAAa,EAAE,MAAM,EAAE,CAAA;QACvB,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QAC9B,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACxC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxC,UAAU,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;QAC1C,gBAAgB,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;QAChD,UAAU,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;QAC3D,iBAAiB,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAA;KAC7D,KAAK,KAAK,CAAC,SAAS,CAAC,CAAA;CACzB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,+FAilB7B,CAAA"}
1
+ {"version":3,"file":"AnnotationManager.d.ts","sourceRoot":"","sources":["../../../src/components/AnnotationManager/AnnotationManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,yBAAyB,CAAA;AAEhC,MAAM,WAAW,sBAAsB;IACnC,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;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