From ab7d2c06e25432fe9cc143452ccf0d8477a3c5b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Sanz=20Garc=C3=ADa?= Date: Fri, 8 Oct 2021 14:06:34 +0200 Subject: [PATCH] Replace lookup by TS type I have created type definitions for all the names of events that are sent across the different frames using various `Bridge`s. It is based on the previous `bridge-events.js`. I broke down the events in four sections based on the direction of the messages: * host -> sidebar events * sidebar -> host events * sidebar -> guest/s events * guest -> sidebar events For those events that didn't have a description I added one. This is more stringent and less verbose than the previous lookup system. --- package.json | 4 +- src/annotator/annotation-counts.js | 7 +- src/annotator/cross-frame.js | 4 +- src/annotator/features.js | 3 +- src/annotator/sidebar.js | 12 +- src/annotator/test/features-test.js | 3 +- src/annotator/test/sidebar-test.js | 25 ++- src/shared/bridge-events.js | 48 ------ src/shared/bridge.js | 4 +- src/sidebar/components/HypothesisApp.js | 7 +- src/sidebar/components/TopBar.js | 3 +- src/sidebar/components/UserMenu.js | 3 +- .../components/test/HypothesisApp-test.js | 14 +- src/sidebar/components/test/TopBar-test.js | 10 +- src/sidebar/components/test/UserMenu-test.js | 10 +- src/sidebar/services/features.js | 6 +- src/sidebar/services/frame-sync.js | 8 +- src/sidebar/services/test/features-test.js | 5 +- src/tsconfig.json | 2 +- src/types/bridge-events.d.ts | 150 ++++++++++++++++++ 20 files changed, 194 insertions(+), 134 deletions(-) delete mode 100644 src/shared/bridge-events.js create mode 100644 src/types/bridge-events.d.ts diff --git a/package.json b/package.json index 6f6fdda4760..5d8082b19c0 100644 --- a/package.json +++ b/package.json @@ -123,8 +123,8 @@ "scripts": { "build": "cross-env NODE_ENV=production gulp build", "lint": "eslint .", - "checkformatting": "prettier --check '**/*.{js,scss}'", - "format": "prettier --list-different --write '**/*.{js,scss}'", + "checkformatting": "prettier --check '**/*.{js,scss,d.ts}'", + "format": "prettier --list-different --write '**/*.{js,scss,d.ts}'", "test": "gulp test", "typecheck": "tsc --build tsconfig.json", "report-coverage": "codecov -f coverage/coverage-final.json", diff --git a/src/annotator/annotation-counts.js b/src/annotator/annotation-counts.js index aedcd8db3f3..408966174e5 100644 --- a/src/annotator/annotation-counts.js +++ b/src/annotator/annotation-counts.js @@ -1,5 +1,3 @@ -import events from '../shared/bridge-events'; - const ANNOTATION_COUNT_ATTR = 'data-hypothesis-annotation-count'; /** @@ -11,10 +9,7 @@ const ANNOTATION_COUNT_ATTR = 'data-hypothesis-annotation-count'; */ export default function annotationCounts(rootEl, crossframe) { - crossframe.on( - events.PUBLIC_ANNOTATION_COUNT_CHANGED, - updateAnnotationCountElems - ); + crossframe.on('publicAnnotationCountChanged', updateAnnotationCountElems); function updateAnnotationCountElems(newCount) { const elems = rootEl.querySelectorAll('[' + ANNOTATION_COUNT_ATTR + ']'); diff --git a/src/annotator/cross-frame.js b/src/annotator/cross-frame.js index 5c926fc00e4..92f133fd387 100644 --- a/src/annotator/cross-frame.js +++ b/src/annotator/cross-frame.js @@ -64,7 +64,7 @@ export class CrossFrame { /** * Subscribe to an event from the sidebar. * - * @param {string} method + * @param {import('../types/bridge-events').BrideEvents} method * @param {(...args: any[]) => void} listener * * @see {Bridge.on} for details. @@ -76,7 +76,7 @@ export class CrossFrame { /** * Call an RPC method exposed by the sidebar to the annotator. * - * @param {string} method - Name of remote method to call. + * @param {import('../types/bridge-events').BrideEvents} method - Name of remote method to call. * @param {any[]} args * * @see {Bridge.call} for details. diff --git a/src/annotator/features.js b/src/annotator/features.js index eb2e84ba417..27c22c582ca 100644 --- a/src/annotator/features.js +++ b/src/annotator/features.js @@ -1,4 +1,3 @@ -import events from '../shared/bridge-events'; import warnOnce from '../shared/warn-once'; let _features = {}; @@ -9,7 +8,7 @@ const _set = features => { export default { init: function (crossframe) { - crossframe.on(events.FEATURE_FLAGS_UPDATED, _set); + crossframe.on('featureFlagsUpdated', _set); }, reset: function () { diff --git a/src/annotator/sidebar.js b/src/annotator/sidebar.js index 46ac05eded2..a5bc607807b 100644 --- a/src/annotator/sidebar.js +++ b/src/annotator/sidebar.js @@ -1,7 +1,6 @@ import Hammer from 'hammerjs'; import { Bridge } from '../shared/bridge'; -import events from '../shared/bridge-events'; import { ListenerCollection } from '../shared/listener-collection'; import annotationCounts from './annotation-counts'; @@ -252,12 +251,13 @@ export default class Sidebar { this.show(); }); + /** @type{Array<[import('../types/bridge-events').BrideEvents, function]>} */ const eventHandlers = [ - [events.LOGIN_REQUESTED, this.onLoginRequest], - [events.LOGOUT_REQUESTED, this.onLogoutRequest], - [events.SIGNUP_REQUESTED, this.onSignupRequest], - [events.PROFILE_REQUESTED, this.onProfileRequest], - [events.HELP_REQUESTED, this.onHelpRequest], + ['loginRequested', this.onLoginRequest], + ['logoutRequested', this.onLogoutRequest], + ['signupRequested', this.onSignupRequest], + ['profileRequested', this.onProfileRequest], + ['helpRequested', this.onHelpRequest], ]; eventHandlers.forEach(([event, handler]) => { if (handler) { diff --git a/src/annotator/test/features-test.js b/src/annotator/test/features-test.js index 2af6ef6dba5..57f90b77e3a 100644 --- a/src/annotator/test/features-test.js +++ b/src/annotator/test/features-test.js @@ -1,4 +1,3 @@ -import events from '../../shared/bridge-events'; import features from '../features'; import { $imports } from '../features'; @@ -23,7 +22,7 @@ describe('features - annotation layer', () => { features.init({ on: function (topic, handler) { - if (topic === events.FEATURE_FLAGS_UPDATED) { + if (topic === 'featureFlagsUpdated') { featureFlagsUpdateHandler = handler; } }, diff --git a/src/annotator/test/sidebar-test.js b/src/annotator/test/sidebar-test.js index 47fbec3563b..59317f1fbc8 100644 --- a/src/annotator/test/sidebar-test.js +++ b/src/annotator/test/sidebar-test.js @@ -1,7 +1,4 @@ -import events from '../../shared/bridge-events'; - -import Sidebar, { MIN_RESIZE } from '../sidebar'; -import { $imports } from '../sidebar'; +import Sidebar, { MIN_RESIZE, $imports } from '../sidebar'; import { EventBus } from '../util/emitter'; const DEFAULT_WIDTH = 350; @@ -366,7 +363,7 @@ describe('Sidebar', () => { const onLoginRequest = sandbox.stub(); createSidebar({ services: [{ onLoginRequest }] }); - emitEvent(events.LOGIN_REQUESTED); + emitEvent('loginRequested'); assert.called(onLoginRequest); }); @@ -386,7 +383,7 @@ describe('Sidebar', () => { ], }); - emitEvent(events.LOGIN_REQUESTED); + emitEvent('loginRequested'); assert.called(firstOnLogin); assert.notCalled(secondOnLogin); @@ -406,7 +403,7 @@ describe('Sidebar', () => { ], }); - emitEvent(events.LOGIN_REQUESTED); + emitEvent('loginRequested'); assert.notCalled(secondOnLogin); assert.notCalled(thirdOnLogin); @@ -414,17 +411,17 @@ describe('Sidebar', () => { it('does not crash if there is no services', () => { createSidebar(); // No config.services - emitEvent(events.LOGIN_REQUESTED); + emitEvent('loginRequested'); }); it('does not crash if services is an empty array', () => { createSidebar({ services: [] }); - emitEvent(events.LOGIN_REQUESTED); + emitEvent('loginRequested'); }); it('does not crash if the first service has no onLoginRequest', () => { createSidebar({ services: [{}] }); - emitEvent(events.LOGIN_REQUESTED); + emitEvent('loginRequested'); }); }); @@ -433,7 +430,7 @@ describe('Sidebar', () => { const onLogoutRequest = sandbox.stub(); createSidebar({ services: [{ onLogoutRequest }] }); - emitEvent(events.LOGOUT_REQUESTED); + emitEvent('logoutRequested'); assert.called(onLogoutRequest); })); @@ -443,7 +440,7 @@ describe('Sidebar', () => { const onSignupRequest = sandbox.stub(); createSidebar({ services: [{ onSignupRequest }] }); - emitEvent(events.SIGNUP_REQUESTED); + emitEvent('signupRequested'); assert.called(onSignupRequest); })); @@ -453,7 +450,7 @@ describe('Sidebar', () => { const onProfileRequest = sandbox.stub(); createSidebar({ services: [{ onProfileRequest }] }); - emitEvent(events.PROFILE_REQUESTED); + emitEvent('profileRequested'); assert.called(onProfileRequest); })); @@ -463,7 +460,7 @@ describe('Sidebar', () => { const onHelpRequest = sandbox.stub(); createSidebar({ services: [{ onHelpRequest }] }); - emitEvent(events.HELP_REQUESTED); + emitEvent('helpRequested'); assert.called(onHelpRequest); })); diff --git a/src/shared/bridge-events.js b/src/shared/bridge-events.js deleted file mode 100644 index fad0aa4b12e..00000000000 --- a/src/shared/bridge-events.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * This module defines the set of global events that are dispatched - * across the bridge between the sidebar and annotator - */ -export default { - // Events that the sidebar sends to the annotator - // ---------------------------------------------- - - /** - * The updated feature flags for the user - */ - FEATURE_FLAGS_UPDATED: 'featureFlagsUpdated', - - /** - * The sidebar is asking the annotator to open the partner site help page. - */ - HELP_REQUESTED: 'helpRequested', - - /** The sidebar is asking the annotator to do a partner site log in - * (for example, pop up a log in window). This is used when the client is - * embedded in a partner site and a log in button in the client is clicked. - */ - LOGIN_REQUESTED: 'loginRequested', - - /** The sidebar is asking the annotator to do a partner site log out. - * This is used when the client is embedded in a partner site and a log out - * button in the client is clicked. - */ - LOGOUT_REQUESTED: 'logoutRequested', - - /** - * The sidebar is asking the annotator to open the partner site profile page. - */ - PROFILE_REQUESTED: 'profileRequested', - - /** - * The set of annotations was updated. - */ - PUBLIC_ANNOTATION_COUNT_CHANGED: 'publicAnnotationCountChanged', - - /** - * The sidebar is asking the annotator to do a partner site sign-up. - */ - SIGNUP_REQUESTED: 'signupRequested', - - // Events that the annotator sends to the sidebar - // ---------------------------------------------- -}; diff --git a/src/shared/bridge.js b/src/shared/bridge.js index c777de42836..dc286742ca2 100644 --- a/src/shared/bridge.js +++ b/src/shared/bridge.js @@ -66,7 +66,7 @@ export class Bridge { * Make a method call on all channels, collect the results and pass them to a * callback when all results are collected. * - * @param {string} method - Name of remote method to call. + * @param {import('../types/bridge-events').BrideEvents} method - Name of remote method to call. * @param {any[]} args - Arguments to method. Final argument is an optional * callback with this type: `(error: string|Error|null, ...result: any[]) => void`. * This callback, if any, will be triggered once a response (via `postMessage`) @@ -132,7 +132,7 @@ export class Bridge { * Register a listener to be invoked when any connected channel sends a * message to this `Bridge`. * - * @param {string} method + * @param {import('../types/bridge-events').BrideEvents} method * @param {(...args: any[]) => void} listener -- Final argument is an optional * callback of the type: `(error: string|Error|null, ...result: any[]) => void`. * This callback must be invoked in order to respond (via `postMessage`) diff --git a/src/sidebar/components/HypothesisApp.js b/src/sidebar/components/HypothesisApp.js index 03e89aea85e..0babe163340 100644 --- a/src/sidebar/components/HypothesisApp.js +++ b/src/sidebar/components/HypothesisApp.js @@ -1,7 +1,6 @@ import classnames from 'classnames'; import { useEffect, useMemo } from 'preact/hooks'; -import bridgeEvents from '../../shared/bridge-events'; import { confirm } from '../../shared/prompts'; import { serviceConfig } from '../config/service-config'; import { useStoreProxy } from '../store/use-store'; @@ -98,7 +97,7 @@ function HypothesisApp({ auth, frameSync, settings, session, toastMessenger }) { const login = async () => { if (serviceConfig(settings)) { // Let the host page handle the login request - frameSync.notifyHost(bridgeEvents.LOGIN_REQUESTED); + frameSync.notifyHost('loginRequested'); return; } @@ -116,7 +115,7 @@ function HypothesisApp({ auth, frameSync, settings, session, toastMessenger }) { const signUp = () => { if (serviceConfig(settings)) { // Let the host page handle the signup request - frameSync.notifyHost(bridgeEvents.SIGNUP_REQUESTED); + frameSync.notifyHost('signupRequested'); return; } window.open(store.getLink('signup')); @@ -156,7 +155,7 @@ function HypothesisApp({ auth, frameSync, settings, session, toastMessenger }) { store.discardAllDrafts(); if (serviceConfig(settings)) { - frameSync.notifyHost(bridgeEvents.LOGOUT_REQUESTED); + frameSync.notifyHost('logoutRequested'); return; } diff --git a/src/sidebar/components/TopBar.js b/src/sidebar/components/TopBar.js index fb7ad296010..030e16c3aa9 100644 --- a/src/sidebar/components/TopBar.js +++ b/src/sidebar/components/TopBar.js @@ -1,6 +1,5 @@ import { IconButton, LinkButton } from '@hypothesis/frontend-shared'; -import bridgeEvents from '../../shared/bridge-events'; import { serviceConfig } from '../config/service-config'; import { useStoreProxy } from '../store/use-store'; import { isThirdPartyService } from '../helpers/is-third-party-service'; @@ -71,7 +70,7 @@ function TopBar({ const requestHelp = () => { const service = serviceConfig(settings); if (service && service.onHelpRequestProvided) { - frameSync.notifyHost(bridgeEvents.HELP_REQUESTED); + frameSync.notifyHost('helpRequested'); } else { store.toggleSidebarPanel('help'); } diff --git a/src/sidebar/components/UserMenu.js b/src/sidebar/components/UserMenu.js index 77b574f5766..29531b287f4 100644 --- a/src/sidebar/components/UserMenu.js +++ b/src/sidebar/components/UserMenu.js @@ -1,7 +1,6 @@ import { SvgIcon } from '@hypothesis/frontend-shared'; import { useState } from 'preact/hooks'; -import bridgeEvents from '../../shared/bridge-events'; import { serviceConfig } from '../config/service-config'; import { isThirdPartyUser } from '../helpers/account-id'; import { useStoreProxy } from '../store/use-store'; @@ -70,7 +69,7 @@ function UserMenu({ auth, frameSync, onLogout, settings }) { }; const onProfileSelected = () => - isThirdParty && frameSync.notifyHost(bridgeEvents.PROFILE_REQUESTED); + isThirdParty && frameSync.notifyHost('profileRequested'); // Generate dynamic props for the profile component const profileItemProps = (() => { diff --git a/src/sidebar/components/test/HypothesisApp-test.js b/src/sidebar/components/test/HypothesisApp-test.js index 617106b2e8d..c7c7c6375ba 100644 --- a/src/sidebar/components/test/HypothesisApp-test.js +++ b/src/sidebar/components/test/HypothesisApp-test.js @@ -1,8 +1,6 @@ import { mount } from 'enzyme'; -import bridgeEvents from '../../../shared/bridge-events'; import mockImportedComponents from '../../../test-util/mock-imported-components'; - import HypothesisApp, { $imports } from '../HypothesisApp'; describe('HypothesisApp', () => { @@ -228,10 +226,7 @@ describe('HypothesisApp', () => { it('sends SIGNUP_REQUESTED event', () => { const wrapper = createComponent(); clickSignUp(wrapper); - assert.calledWith( - fakeFrameSync.notifyHost, - bridgeEvents.SIGNUP_REQUESTED - ); + assert.calledWith(fakeFrameSync.notifyHost, 'signupRequested'); }); it('does not open a URL directly', () => { @@ -304,7 +299,7 @@ describe('HypothesisApp', () => { assert.equal(fakeFrameSync.notifyHost.callCount, 1); assert.isTrue( - fakeFrameSync.notifyHost.calledWithExactly(bridgeEvents.LOGIN_REQUESTED) + fakeFrameSync.notifyHost.calledWithExactly('loginRequested') ); }); }); @@ -412,10 +407,7 @@ describe('HypothesisApp', () => { await clickLogOut(wrapper); assert.calledOnce(fakeFrameSync.notifyHost); - assert.calledWithExactly( - fakeFrameSync.notifyHost, - bridgeEvents.LOGOUT_REQUESTED - ); + assert.calledWithExactly(fakeFrameSync.notifyHost, 'logoutRequested'); }); it('does not send LOGOUT_REQUESTED if the user cancels the prompt', async () => { diff --git a/src/sidebar/components/test/TopBar-test.js b/src/sidebar/components/test/TopBar-test.js index 7074d3afba2..1782192377d 100644 --- a/src/sidebar/components/test/TopBar-test.js +++ b/src/sidebar/components/test/TopBar-test.js @@ -1,9 +1,6 @@ import { mount } from 'enzyme'; -import bridgeEvents from '../../../shared/bridge-events'; -import TopBar from '../TopBar'; -import { $imports } from '../TopBar'; - +import TopBar, { $imports } from '../TopBar'; import { checkAccessibility } from '../../../test-util/accessibility'; import mockImportedComponents from '../../../test-util/mock-imported-components'; @@ -123,10 +120,7 @@ describe('TopBar', () => { helpButton.props().onClick(); assert.equal(fakeStore.toggleSidebarPanel.callCount, 0); - assert.calledWith( - fakeFrameSync.notifyHost, - bridgeEvents.HELP_REQUESTED - ); + assert.calledWith(fakeFrameSync.notifyHost, 'helpRequested'); }); }); }); diff --git a/src/sidebar/components/test/UserMenu-test.js b/src/sidebar/components/test/UserMenu-test.js index a31ff56e5e5..7e97cbf6e69 100644 --- a/src/sidebar/components/test/UserMenu-test.js +++ b/src/sidebar/components/test/UserMenu-test.js @@ -1,11 +1,8 @@ import { mount } from 'enzyme'; import { act } from 'preact/test-utils'; -import bridgeEvents from '../../../shared/bridge-events'; -import UserMenu from '../UserMenu'; -import { $imports } from '../UserMenu'; - import mockImportedComponents from '../../../test-util/mock-imported-components'; +import UserMenu, { $imports } from '../UserMenu'; describe('UserMenu', () => { let fakeAuth; @@ -148,10 +145,7 @@ describe('UserMenu', () => { onProfileSelected(); assert.equal(fakeFrameSync.notifyHost.callCount, 1); - assert.calledWith( - fakeFrameSync.notifyHost, - bridgeEvents.PROFILE_REQUESTED - ); + assert.calledWith(fakeFrameSync.notifyHost, 'profileRequested'); }); it('should not fire profile event for first-party user', () => { diff --git a/src/sidebar/services/features.js b/src/sidebar/services/features.js index d8856c82868..1fd01a30f52 100644 --- a/src/sidebar/services/features.js +++ b/src/sidebar/services/features.js @@ -1,4 +1,3 @@ -import bridgeEvents from '../../shared/bridge-events'; import { watch } from '../util/watch'; /** @@ -26,10 +25,7 @@ export class FeaturesService { init() { const currentFlags = () => this._store.profile().features; const sendFeatureFlags = () => { - this._frameSync.notifyHost( - bridgeEvents.FEATURE_FLAGS_UPDATED, - currentFlags() || {} - ); + this._frameSync.notifyHost('featureFlagsUpdated', currentFlags() || {}); }; // Re-send feature flags to connected frames when flags change or a new diff --git a/src/sidebar/services/frame-sync.js b/src/sidebar/services/frame-sync.js index a240c3e9abd..e8ba45d9939 100644 --- a/src/sidebar/services/frame-sync.js +++ b/src/sidebar/services/frame-sync.js @@ -1,6 +1,5 @@ import debounce from 'lodash.debounce'; -import bridgeEvents from '../../shared/bridge-events'; import { Bridge } from '../../shared/bridge'; import { isReply, isPublic } from '../helpers/annotation-metadata'; import { watch } from '../util/watch'; @@ -118,10 +117,7 @@ export class FrameSyncService { if (frames.length > 0) { if (frames.every(frame => frame.isAnnotationFetchComplete)) { if (publicAnns === 0 || publicAnns !== prevPublicAnns) { - this._hostRPC.call( - bridgeEvents.PUBLIC_ANNOTATION_COUNT_CHANGED, - publicAnns - ); + this._hostRPC.call('publicAnnotationCountChanged', publicAnns); prevPublicAnns = publicAnns; } } @@ -282,7 +278,7 @@ export class FrameSyncService { /** * Send an RPC message to the host frame. * - * @param {string} method + * @param {import('../../types/bridge-events').BrideEvents} method * @param {any[]} args */ notifyHost(method, ...args) { diff --git a/src/sidebar/services/test/features-test.js b/src/sidebar/services/test/features-test.js index 55be3a7f0b6..0ae337b0252 100644 --- a/src/sidebar/services/test/features-test.js +++ b/src/sidebar/services/test/features-test.js @@ -1,4 +1,3 @@ -import bridgeEvents from '../../../shared/bridge-events'; import { FeaturesService } from '../features'; describe('FeaturesService', () => { @@ -52,7 +51,7 @@ describe('FeaturesService', () => { assert.calledWith( fakeFrameSync.notifyHost, - bridgeEvents.FEATURE_FLAGS_UPDATED, + 'featureFlagsUpdated', fakeStore.profile().features ); }); @@ -71,7 +70,7 @@ describe('FeaturesService', () => { assert.calledWith( fakeFrameSync.notifyHost, - bridgeEvents.FEATURE_FLAGS_UPDATED, + 'featureFlagsUpdated', fakeStore.profile().features ); }); diff --git a/src/tsconfig.json b/src/tsconfig.json index 718aa0ffe97..bd94bd1fa7e 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -14,7 +14,7 @@ // Let argument to catch statement be `any` rather than `unknown`. "useUnknownInCatchVariables": false }, - "include": ["**/*.js"], + "include": ["**/*.js", "**/*.d.ts"], "exclude": [ // Tests are not checked. "**/test/**/*.js", diff --git a/src/types/bridge-events.d.ts b/src/types/bridge-events.d.ts new file mode 100644 index 00000000000..16b21cf6bc7 --- /dev/null +++ b/src/types/bridge-events.d.ts @@ -0,0 +1,150 @@ +/** + * This module defines the set of global events that are dispatched across the + * the bridge/s between the sidebar-host, and sidebar-guest/s. + */ + +/** + * Events that the sidebar sends to the host + */ +type SidebarToHostEvents = { + /** + * The sidebar is asking the host to open the sidebar. + */ + CLOSE_SIDEBAR: 'closeSidebar'; + + /** + * The updated feature flags for the user + */ + FEATURE_FLAGS_UPDATED: 'featureFlagsUpdated'; + + /** + * The sidebar is asking the host to open the partner site help page. + */ + HELP_REQUESTED: 'helpRequested'; + + /** + * The sidebar is asking the host to do a partner site log in + * (for example, pop up a log in window). This is used when the client is + * embedded in a partner site and a log in button in the client is clicked. + */ + LOGIN_REQUESTED: 'loginRequested'; + + /** + * The sidebar is asking the host to do a partner site log out. + * This is used when the client is embedded in a partner site and a log out + * button in the client is clicked. + */ + LOGOUT_REQUESTED: 'logoutRequested'; + + /** + * The sidebar is asking the host to open the notebook. + */ + OPEN_NOTEBOOK: 'openNotebook'; + + /** + * The sidebar is asking the host to open the sidebar. + */ + OPEN_SIDEBAR: 'openSidebar'; + + /** + * The sidebar is asking the host to open the partner site profile page. + */ + PROFILE_REQUESTED: 'profileRequested'; + + /** + * The sidebar is updating the number of annotations in the partner site. + */ + PUBLIC_ANNOTATION_COUNT_CHANGED: 'publicAnnotationCountChanged'; + + /** + * The sidebar is asking the host to do a partner site sign-up. + */ + SIGNUP_REQUESTED: 'signupRequested'; +}; + +/** + * Events that the host sends to the sidebar + */ +type HostToSidebarEvents = { + /** + * The host is asking the sidebar to delete a frame using an identifier + */ + DESTROY_FRAME: 'destroyFrame'; + + /** + * The host informs the sidebar that the sidebar has been opened + */ + SIDEBAR_OPENED: 'sidebarOpened'; +}; + +/** + * Events that the sidebar sends to the guest/s + */ +type SidebarToGuestEvents = { + /** + * The sidebar is asking the guest/s to focus on certain annotations. + */ + FOCUS_ANNOTATIONS: 'focusAnnotations'; + + /** + * The sidebar is asking the guest/s to get the document metadata. + */ + GET_DOCUMENT_INFO: 'getDocumentInfo'; + + /** + * The sidebar is asking the guest/s to load annotations. + */ + LOAD_ANNOTATIONS: 'loadAnnotations'; + + /** + * The sidebar is asking the guest/s to scroll to certain annotation. + */ + SCROLL_TO_ANNOTATION: 'scrollToAnnotation'; + + /** + * The sidebar is asking the guest/s to set the annotation highlights on/off. + */ + SET_VISIBLE_HIGHLIGHTS: 'setVisibleHighlights'; +}; + +/** + * Events that the guest sends to the sidebar + */ +type GuestToSidebarEvents = { + /** + * The guest is asking the sidebar to create an annotation + */ + BEFORE_CREATE_ANNOTATION: 'beforeCreateAnnotation'; + + /** + * The guest is asking the sidebar to delete an annotation + */ + DELETE_ANNOTATION: 'deleteAnnotation'; + + /** + * The guest is asking the sidebar to open the sidebar. + */ + OPEN_SIDEBAR: 'openSidebar'; + + /** + * The guest is asking the sidebar to display some annotations + */ + SHOW_ANNOTATIONS: 'showAnnotations'; + + /** + * The guest is asking the sidebar to sync the annotations + */ + SYNC: 'sync'; + + /** + * The guest is asking the host to toggle some annotations + */ + TOGGLE_ANNOTATION_SELECTION: 'toggleAnnotationSelection'; +}; + +export type BrideEvents = + | 'connect' + | SidebarToHostEvents[keyof SidebarToHostEvents] + | HostToSidebarEvents[keyof HostToSidebarEvents] + | SidebarToGuestEvents[keyof SidebarToGuestEvents] + | GuestToSidebarEvents[keyof GuestToSidebarEvents];