Commit a28acdfc authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate bucket-bar module to TypeScript

parent 5000c046
import { render } from 'preact'; import { render } from 'preact';
import type { AnchorPosition, Destroyable } from '../types/annotator';
import Buckets from './components/Buckets'; import Buckets from './components/Buckets';
import { computeBuckets } from './util/buckets'; import { computeBuckets } from './util/buckets';
/** export type BucketBarOptions = {
* @typedef {import('../types/annotator').AnchorPosition} AnchorPosition onFocusAnnotations: (tags: string[]) => void;
* @typedef {import('../types/annotator').Destroyable} Destroyable onScrollToClosestOffScreenAnchor: (
*/ tags: string[],
direction: 'down' | 'up'
) => void;
onSelectAnnotations: (tags: string[], toggle: boolean) => void;
};
/** /**
* Controller for the "bucket bar" shown alongside the sidebar indicating where * Controller for the "bucket bar" shown alongside the sidebar indicating where
* annotations are in the document. * annotations are in the document.
*
* @implements {Destroyable}
*/
export class BucketBar {
/**
* @param {HTMLElement} container
* @param {object} options
* @param {(tags: string[]) => void} options.onFocusAnnotations
* @param {(tags: string[], direction: 'down'|'up') => void} options.onScrollToClosestOffScreenAnchor
* @param {(tags: string[], toggle: boolean) => void} options.onSelectAnnotations
*/ */
export class BucketBar implements Destroyable {
private _bucketsContainer: HTMLDivElement;
private _onFocusAnnotations: BucketBarOptions['onFocusAnnotations'];
private _onScrollToClosestOffScreenAnchor: BucketBarOptions['onScrollToClosestOffScreenAnchor'];
private _onSelectAnnotations: BucketBarOptions['onSelectAnnotations'];
constructor( constructor(
container, container: HTMLElement,
{ {
onFocusAnnotations, onFocusAnnotations,
onScrollToClosestOffScreenAnchor, onScrollToClosestOffScreenAnchor,
onSelectAnnotations, onSelectAnnotations,
} }: BucketBarOptions
) { ) {
this._bucketsContainer = document.createElement('div'); this._bucketsContainer = document.createElement('div');
container.appendChild(this._bucketsContainer); container.appendChild(this._bucketsContainer);
...@@ -46,10 +47,7 @@ export class BucketBar { ...@@ -46,10 +47,7 @@ export class BucketBar {
this._bucketsContainer.remove(); this._bucketsContainer.remove();
} }
/** update(positions: AnchorPosition[]) {
* @param {AnchorPosition[]} positions
*/
update(positions) {
const buckets = computeBuckets(positions); const buckets = computeBuckets(positions);
render( render(
<Buckets <Buckets
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment