diff --git a/src/annotator/annotation-sync.js b/src/annotator/annotation-sync.js index a92bc45ce84..94a92dddc3a 100644 --- a/src/annotator/annotation-sync.js +++ b/src/annotator/annotation-sync.js @@ -79,7 +79,7 @@ export class AnnotationSync { return; } this.bridge.call( - guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, + guestToSidebarEvents.CREATE_ANNOTATION, this._format(annotation) ); }); diff --git a/src/annotator/test/annotation-sync-test.js b/src/annotator/test/annotation-sync-test.js index af287e305c5..72bdf2613fc 100644 --- a/src/annotator/test/annotation-sync-test.js +++ b/src/annotator/test/annotation-sync-test.js @@ -123,7 +123,7 @@ describe('AnnotationSync', () => { assert.called(fakeBridge.call); assert.calledWith( fakeBridge.call, - guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, + guestToSidebarEvents.CREATE_ANNOTATION, { msg: ann, tag: ann.$tag, diff --git a/src/shared/bridge-events.js b/src/shared/bridge-events.js index bd940cfcfaa..ae570bad538 100644 --- a/src/shared/bridge-events.js +++ b/src/shared/bridge-events.js @@ -29,14 +29,14 @@ export const hostToSidebarEvents = { /** * Events that the guest sends to the sidebar * - * @typedef {'beforeCreateAnnotation'|'closeSidebar'|'focusAnnotations'|'openSidebar'|'showAnnotations'|'sync'|'toggleAnnotationSelection'} GuestToSidebarEvent - * @type {Record<'BEFORE_CREATE_ANNOTATION'|'CLOSE_SIDEBAR'|'FOCUS_ANNOTATIONS'|'OPEN_SIDEBAR'|'SHOW_ANNOTATIONS'|'SYNC'|'TOGGLE_ANNOTATION_SELECTION', GuestToSidebarEvent>} + * @typedef {'createAnnotation'|'closeSidebar'|'focusAnnotations'|'openSidebar'|'showAnnotations'|'sync'|'toggleAnnotationSelection'} GuestToSidebarEvent + * @type {Record<'CREATE_ANNOTATION'|'CLOSE_SIDEBAR'|'FOCUS_ANNOTATIONS'|'OPEN_SIDEBAR'|'SHOW_ANNOTATIONS'|'SYNC'|'TOGGLE_ANNOTATION_SELECTION', GuestToSidebarEvent>} */ export const guestToSidebarEvents = { /** * The guest is asking the sidebar to create an annotation. */ - BEFORE_CREATE_ANNOTATION: 'beforeCreateAnnotation', + CREATE_ANNOTATION: 'createAnnotation', /** * The guest is asking the sidebar to relay the message to open the sidebar. diff --git a/src/sidebar/services/frame-sync.js b/src/sidebar/services/frame-sync.js index c7a0b4ed1cb..7c84a394f36 100644 --- a/src/sidebar/services/frame-sync.js +++ b/src/sidebar/services/frame-sync.js @@ -147,29 +147,26 @@ export class FrameSyncService { */ this._setupSyncFromGuests = () => { // A new annotation, note or highlight was created in the frame - this._guestRPC.on( - guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, - event => { - const annot = Object.assign({}, event.msg, { $tag: event.tag }); - // If user is not logged in, we can't really create a meaningful highlight - // or annotation. Instead, we need to open the sidebar, show an error, - // and delete the (unsaved) annotation so it gets un-selected in the - // target document - if (!store.isLoggedIn()) { - this._hostRPC.call(sidebarToHostEvents.OPEN_SIDEBAR); - store.openSidebarPanel('loginPrompt'); - this._guestRPC.call( - sidebarToGuestEvents.DELETE_ANNOTATION, - formatAnnot(annot) - ); - return; - } - inFrame.add(event.tag); - - // Create the new annotation in the sidebar. - annotationsService.create(annot); + this._guestRPC.on(guestToSidebarEvents.CREATE_ANNOTATION, event => { + const annot = Object.assign({}, event.msg, { $tag: event.tag }); + // If user is not logged in, we can't really create a meaningful highlight + // or annotation. Instead, we need to open the sidebar, show an error, + // and delete the (unsaved) annotation so it gets un-selected in the + // target document + if (!store.isLoggedIn()) { + this._hostRPC.call(sidebarToHostEvents.OPEN_SIDEBAR); + store.openSidebarPanel('loginPrompt'); + this._guestRPC.call( + sidebarToGuestEvents.DELETE_ANNOTATION, + formatAnnot(annot) + ); + return; } - ); + inFrame.add(event.tag); + + // Create the new annotation in the sidebar. + annotationsService.create(annot); + }); // Map of annotation tag to anchoring status // ('anchored'|'orphan'|'timeout'). diff --git a/src/sidebar/services/test/frame-sync-test.js b/src/sidebar/services/test/frame-sync-test.js index 5241daa217d..f70dde3dc3b 100644 --- a/src/sidebar/services/test/frame-sync-test.js +++ b/src/sidebar/services/test/frame-sync-test.js @@ -328,7 +328,7 @@ describe('FrameSyncService', () => { fakeStore.isLoggedIn.returns(true); const ann = { target: [] }; - guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, { + guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, { tag: 't1', msg: ann, }); @@ -352,7 +352,7 @@ describe('FrameSyncService', () => { it('should not create an annotation in the sidebar', () => { const ann = { target: [] }; - guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, { + guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, { tag: 't1', msg: ann, }); @@ -362,7 +362,7 @@ describe('FrameSyncService', () => { it('should open the sidebar', () => { const ann = { target: [] }; - guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, { + guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, { tag: 't1', msg: ann, }); @@ -372,7 +372,7 @@ describe('FrameSyncService', () => { it('should open the login prompt panel', () => { const ann = { target: [] }; - guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, { + guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, { tag: 't1', msg: ann, }); @@ -382,7 +382,7 @@ describe('FrameSyncService', () => { it('should send a "deleteAnnotation" message to the frame', () => { const ann = { target: [] }; - guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, { + guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, { tag: 't1', msg: ann, });