Commit 32ddd01d authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate bucket-bar-client module to TypeScript

parent a28acdfc
import { ListenerCollection } from '../shared/listener-collection'; import { ListenerCollection } from '../shared/listener-collection';
import type { PortRPC } from '../shared/messaging';
import type { Anchor, Destroyable } from '../types/annotator';
import type {
HostToGuestEvent,
GuestToHostEvent,
} from '../types/port-rpc-events';
import { computeAnchorPositions } from './util/buckets'; import { computeAnchorPositions } from './util/buckets';
/** type HostRPC = PortRPC<HostToGuestEvent, GuestToHostEvent>;
* @typedef {import('../shared/messaging').PortRPC<HostToGuestEvent, GuestToHostEvent>} HostRPC
* @typedef {import('../types/annotator').Anchor} Anchor export type BucketBarClientOptions = {
* @typedef {import('../types/annotator').AnchorPosition} AnchorPosition contentContainer: Element;
* @typedef {import('../types/annotator').Destroyable} Destroyable hostRPC: HostRPC;
* @typedef {import('../types/port-rpc-events').HostToGuestEvent} HostToGuestEvent };
* @typedef {import('../types/port-rpc-events').GuestToHostEvent} GuestToHostEvent
*/
/** /**
* Communicate to the host frame when: * Communicate to the host frame when:
* *
* 1. The set of anchors has been changed (due to annotations being added or removed) * 1. The set of anchors has been changed (due to annotations being added or removed)
* 2. The position of anchors relative to the viewport of the guest has changed * 2. The position of anchors relative to the viewport of the guest has changed
*
* @implements {Destroyable}
*/ */
export class BucketBarClient { export class BucketBarClient implements Destroyable {
/** private _hostRPC: HostRPC;
* @param {object} options private _updatePending: boolean;
* @param {Element} options.contentContainer - The scrollable container element for the private _anchors: Anchor[];
* document content. All of the highlights that the bucket bar's buckets point private _listeners: ListenerCollection;
* at should be contained within this element.
* @param {HostRPC} options.hostRPC constructor({ contentContainer, hostRPC }: BucketBarClientOptions) {
*/
constructor({ contentContainer, hostRPC }) {
this._hostRPC = hostRPC; this._hostRPC = hostRPC;
this._updatePending = false; this._updatePending = false;
/** @type {Anchor[]} */
this._anchors = []; this._anchors = [];
this._listeners = new ListenerCollection(); this._listeners = new ListenerCollection();
...@@ -50,10 +49,9 @@ export class BucketBarClient { ...@@ -50,10 +49,9 @@ export class BucketBarClient {
* Updates are debounced to reduce the overhead of gathering and sending anchor * Updates are debounced to reduce the overhead of gathering and sending anchor
* position data across frames. * position data across frames.
* *
* @param {Anchor[]} [anchors] - pass this option when anchors are added or * @param anchors - pass this option when anchors are added or deleted
* deleted
*/ */
update(anchors) { update(anchors?: Anchor[]) {
if (anchors) { if (anchors) {
this._anchors = anchors; this._anchors = anchors;
} }
......
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