Commit 1645a344 authored by Robert Knight's avatar Robert Knight

Revise documentation for inter-frame messages.

Revise the documentation in order to:

 - Reduce uninformative noise ("the X frame informs the Y frame to..."). The
   source and destination frame type are given by the type name.

 - Re-phrase the documentation to read more like either a function description
   or an event description, depending on whether the message is a specific
   command/request or a more general event.

 - Use the plural "guests" to make it clear that there can be more than one
   guest frame.

 - Clarify when events specific to third-party authorities are used.
parent f8ffebb6
/** /**
* This module defines the events that are sent between frames with different * This module defines the messages that are sent between frames with different
* roles in the client (guest, host, sidebar). * roles in the client (guest, host, sidebar). Some messages are events in the
* source frame (eg. the active feature flags changed, text was selected)
* others are commands for the target frame (eg. "close the sidebar").
*/ */
/** /**
* Events that the guest sends to the host * Events that guests send to the host.
*/ */
export type GuestToHostEvent = export type GuestToHostEvent =
/** The guest informs the host that text has been unselected. */ /** Text has been deselected in the guest frame. */
| 'textUnselected' | 'textUnselected'
/** The guest informs the host that text has been selected. */ /** Text has been selected in the guest frame. */
| 'textSelected' | 'textSelected'
/** /** Anchors have changed in the guest frame. */
* The guest informs the host that the anchors have been changed in the main annotatable frame.
*/
| 'anchorsChanged' | 'anchorsChanged'
/** /**
...@@ -26,17 +26,15 @@ export type GuestToHostEvent = ...@@ -26,17 +26,15 @@ export type GuestToHostEvent =
| 'highlightsVisibleChanged'; | 'highlightsVisibleChanged';
/** /**
* Events that the guest sends to the sidebar * Events that guests send to the sidebar.
*/ */
export type GuestToSidebarEvent = export type GuestToSidebarEvent =
/** /**
* The guest is asking the sidebar to create an annotation. * A new annotation was created in the guest frame via the Annotate/Highlight controls.
*/ */
| 'createAnnotation' | 'createAnnotation'
/** /** Request to close the sidebar. */
* The guest is asking the sidebar to relay the message to the host to close the sidebar.
*/
| 'closeSidebar' | 'closeSidebar'
/** /**
...@@ -45,37 +43,35 @@ export type GuestToSidebarEvent = ...@@ -45,37 +43,35 @@ export type GuestToSidebarEvent =
*/ */
| 'hoverAnnotations' | 'hoverAnnotations'
/** /** Request to open the sidebar. */
* The guest is asking the sidebar to relay the message to the host to open the sidebar.
*/
| 'openSidebar' | 'openSidebar'
/** The guest is notifying the sidebar of the current document metadata and URIs. */ /** The URIs or metadata of the document in the guest frame changed. */
| 'documentInfoChanged' | 'documentInfoChanged'
/** /** Set the selected annotations. Emitted when the user clicks highlights in the guest frame. */
* The guest is asking the sidebar to display some annotations.
*/
| 'showAnnotations' | 'showAnnotations'
/** /** The anchoring status of annotations changed. */
* The guest informs the sidebar whether annotations were successfully anchored
*/
| 'syncAnchoringStatus' | 'syncAnchoringStatus'
/** /** Toggle whether annotations are selected. */
* The guest is asking the sidebar to toggle some annotations.
*/
| 'toggleAnnotationSelection'; | 'toggleAnnotationSelection';
/** /**
* Events that the host sends to the guest * Events that the host sends to guests.
*/ */
export type HostToGuestEvent = export type HostToGuestEvent =
/** The host requests a guest to create an annotation. */ /**
* The host requests that the guest frame create a new annotation.
*
* This is used for the toolbar button that creates a new annotation or
* page note for the main guest frame, depending on whether there is a
* selection.
*/
| 'createAnnotation' | 'createAnnotation'
/** The host informs guests that text should be unselected. */ /** Clear the selection in the guest frame. */
| 'clearSelection' | 'clearSelection'
/** /**
...@@ -85,22 +81,21 @@ export type HostToGuestEvent = ...@@ -85,22 +81,21 @@ export type HostToGuestEvent =
| 'hoverAnnotations' | 'hoverAnnotations'
/** /**
* The host informs guests to select/toggle on a set of annotations * Select annotations in the guest frame.
*
* This is used to select annotations when the corresponding items in the
* bucket bar are clicked.
*/ */
| 'selectAnnotations' | 'selectAnnotations'
/** /** The layout (width, open/closed state) of the sidebar changed. */
* The host informs guests that the sidebar layout has been changed.
*/
| 'sidebarLayoutChanged' | 'sidebarLayoutChanged'
/** /** Scroll a highlight into view. */
* Scroll to an annotation given its tag.
*/
| 'scrollToAnnotation'; | 'scrollToAnnotation';
/** /**
* Events that the host sends to the sidebar * Events that the host sends to the sidebar.
*/ */
export type HostToSidebarEvent = export type HostToSidebarEvent =
/** /**
...@@ -108,24 +103,20 @@ export type HostToSidebarEvent = ...@@ -108,24 +103,20 @@ export type HostToSidebarEvent =
*/ */
| 'setHighlightsVisible' | 'setHighlightsVisible'
/** /** Notify the sidebar iframe that it has become visible. */
* The host informs the sidebar that the sidebar has been opened.
*/
| 'sidebarOpened' | 'sidebarOpened'
/** /** Notify the sidebar iframe that it has become hidden. */
* The host informs the sidebar that the sidebar has been closed.
*/
| 'sidebarClosed'; | 'sidebarClosed';
/** /**
* Events that the sidebar sends to the guest(s) * Events that the sidebar sends to guests.
*/ */
export type SidebarToGuestEvent = export type SidebarToGuestEvent =
/** /** Remove an annotation from the guest frame. */
* The sidebar is asking the guest(s) to delete an annotation.
*/
| 'deleteAnnotation' | 'deleteAnnotation'
/** The active feature flags changed. */
| 'featureFlagsUpdated' | 'featureFlagsUpdated'
/** /**
...@@ -134,22 +125,14 @@ export type SidebarToGuestEvent = ...@@ -134,22 +125,14 @@ export type SidebarToGuestEvent =
*/ */
| 'hoverAnnotations' | 'hoverAnnotations'
/** /** Load new annotations into the guest frame. */
* The sidebar is asking the guest(s) to load annotations.
*/
| 'loadAnnotations' | 'loadAnnotations'
/** Navigate to the segment of a book associated with an annotation. */ /** Navigate to the segment of a book associated with an annotation. */
| 'navigateToSegment' | 'navigateToSegment'
/** /** Scroll an annotation into view. */
* The sidebar is asking the guest(s) to scroll to certain annotation.
*/
| 'scrollToAnnotation' | 'scrollToAnnotation'
/**
* The sidebar relays to the guest(s) to set the annotation highlights on/off.
*/
| 'setHighlightsVisible' | 'setHighlightsVisible'
/** /**
...@@ -162,82 +145,86 @@ export type SidebarToGuestEvent = ...@@ -162,82 +145,86 @@ export type SidebarToGuestEvent =
*/ */
export type SidebarToHostEvent = export type SidebarToHostEvent =
/** /**
* The sidebar relays to the host to close the sidebar. * Request from the sidebar iframe to close (ie. hide/move offscreen) its
* container in the host frame.
*/ */
| 'closeSidebar' | 'closeSidebar'
/** /** The active feature flags changed. */
* The sidebar informs the host to update the Hypothesis configuration to enable/disable additional features
*/
| 'featureFlagsUpdated' | 'featureFlagsUpdated'
/** /**
* The sidebar is asking the host to open the partner site help page. * Open the partner site help page.
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onhelprequest *
* See https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onhelprequest
*/ */
| 'helpRequested' | 'helpRequested'
/** /**
* The sidebar is asking the host to do a partner site log in * Initiate a login.
* (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. * This is used when the client is embedded in a partner site where a custom
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onloginrequest * Hypothesis login method is used (aka. a third-party authority) and the
* login button in the client is clicked.
*
* See https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onloginrequest
*/ */
| 'loginRequested' | 'loginRequested'
/** /**
* The sidebar is asking the host to do a partner site log out. * Log the user out.
* This is used when the client is embedded in a partner site and a log out *
* button in the client is clicked. * This is used when the client is embedded in a partner site where a custom
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onlogoutrequest * Hypothesis login method is used (aka. a third-party authority) and the
* logout button in the client is clicked.
*
* See https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onlogoutrequest
*/ */
| 'logoutRequested' | 'logoutRequested'
/** /** Open the notebook dialog. */
* The sidebar is asking the host to open the notebook.
*/
| 'openNotebook' | 'openNotebook'
/** /** Open the account settings dialog. */
* The sidebar is asking the host to open the user profile.
*/
| 'openProfile' | 'openProfile'
/** /** Open the sidebar container. */
* The sidebar is asking the host to open the sidebar (side-effect of creating
* an annotation).
*/
| 'openSidebar' | 'openSidebar'
/** /** Make highlights visible in guest frames. */
* The sidebar requests the host to enable the "Show highlights" control.
*/
| 'showHighlights' | 'showHighlights'
/** /**
* The sidebar is asking the host to open the partner site profile page. * Open the profile page for the current user.
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onprofilerequest *
* This is used when the client is embedded in a partner site where a custom
* Hypothesis login method is used (aka. a third-party authority) and the
* profile menu item in the client is clicked.
*
* See https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onprofilerequest
*/ */
| 'profileRequested' | 'profileRequested'
/** /**
* The sidebar informs the host to update the annotation counter in the partner site. * The count of public annotations on the current page changed.
* https://h.readthedocs.io/projects/client/en/latest/publishers/host-page-integration/#cmdoption-arg-data-hypothesis-annotation-count *
* See https://h.readthedocs.io/projects/client/en/latest/publishers/host-page-integration/#cmdoption-arg-data-hypothesis-annotation-count
*/ */
| 'publicAnnotationCountChanged' | 'publicAnnotationCountChanged'
/** /**
* The sidebar is asking the host to do a partner site sign-up. * Initiate an account sign-up.
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onsignuprequest *
* This is used when the client is embedded in a partner site where a custom
* Hypothesis login method is used (aka. a third-party authority) and the
* sign-up link in the client is clicked.
*
* See https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onsignuprequest
*/ */
| 'signupRequested' | 'signupRequested'
/** /** Display a toast message in the host frame. */
* The sidebar is asking the host to toast a message
*/
| 'toastMessageAdded' | 'toastMessageAdded'
/** /** Dismiss a toast message in the host frame. */
* The sidebar is asking the host to dismiss a toast message
*/
| 'toastMessageDismissed'; | 'toastMessageDismissed';
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