@readium/navigator 2.5.5 → 2.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
4
4
  "type": "module",
5
5
  "description": "Next generation SDK for publications in Web Apps",
6
6
  "author": "readium",
@@ -81,6 +81,7 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
81
81
  private _css: ReadiumCSS;
82
82
  private _preferencesEditor: EpubPreferencesEditor | null = null;
83
83
  private _injector: Injector | null = null;
84
+ private _isNavigating = false;
84
85
  private readonly _readiumRulesPromise: Promise<IInjectableRule[]>;
85
86
  private readonly _injectablesConfig: IInjectablesConfig;
86
87
  private readonly _contentProtection: IContentProtectionConfig;
@@ -758,33 +759,45 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
758
759
  }
759
760
 
760
761
  public goBackward(_: boolean, cb: (ok: boolean) => void): void {
762
+ if(this._isNavigating) { cb(false); return; }
763
+ this._isNavigating = true;
761
764
  if(this._layout === Layout.fixed) {
762
- this.changeResource(-1);
763
- cb(true);
765
+ this.changeResource(-1).then((ok) => {
766
+ this._isNavigating = false;
767
+ cb(ok);
768
+ });
764
769
  } else {
765
770
  this._cframes[0]?.msg?.send("go_prev", undefined, async (ack) => {
766
- if(ack)
767
- // OK
771
+ if(ack) {
772
+ this._isNavigating = false;
768
773
  cb(true);
769
- else
770
- // Need to change resources because we're at the beginning of the current one
771
- cb(await this.changeResource(-1));
774
+ } else {
775
+ const ok = await this.changeResource(-1);
776
+ this._isNavigating = false;
777
+ cb(ok);
778
+ }
772
779
  });
773
780
  }
774
781
  }
775
782
 
776
783
  public goForward(_: boolean, cb: (ok: boolean) => void): void {
784
+ if(this._isNavigating) { cb(false); return; }
785
+ this._isNavigating = true;
777
786
  if(this._layout === Layout.fixed) {
778
- this.changeResource(1);
779
- cb(true);
787
+ this.changeResource(1).then((ok) => {
788
+ this._isNavigating = false;
789
+ cb(ok);
790
+ });
780
791
  } else {
781
792
  this._cframes[0]?.msg?.send("go_next", undefined, async (ack) => {
782
- if(ack)
783
- // OK
793
+ if(ack) {
794
+ this._isNavigating = false;
784
795
  cb(true);
785
- else
786
- // Need to change resources because we're at the end of the current one
787
- cb(await this.changeResource(1));
796
+ } else {
797
+ const ok = await this.changeResource(1);
798
+ this._isNavigating = false;
799
+ cb(ok);
800
+ }
788
801
  });
789
802
  }
790
803
  }
@@ -907,8 +920,14 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
907
920
  return cb(this.listeners.handleLocator(locator));
908
921
  }
909
922
 
923
+ if(this._isNavigating) { cb(false); return; }
924
+ this._isNavigating = true;
925
+
910
926
  this.currentLocation = this.positions.find(p => p.href === link!.href)!;
911
- this.apply().then(() => this.loadLocator(locator, (ok) => cb(ok))).then(() => {
927
+ this.apply().then(() => this.loadLocator(locator, (ok) => {
928
+ this._isNavigating = false;
929
+ cb(ok);
930
+ })).then(() => {
912
931
  // Now that we've gone to the right locator, we can attach the listeners.
913
932
  // Doing this only at this stage reduces janky UI with multiple locator updates.
914
933
  this.attachListener();
@@ -115,6 +115,9 @@ export class FrameManager {
115
115
  this.frame.style.opacity = "0";
116
116
  this.frame.style.pointerEvents = "none";
117
117
  this.hidden = true;
118
+ // Return focus to the parent document so keyboard events aren't silently
119
+ // swallowed by a hidden iframe whose comms channel has been halted.
120
+ this.frame.blur();
118
121
  if(this.frame.parentElement) {
119
122
  if(this.comms === undefined || !this.comms.ready) return;
120
123
  return new Promise((res, _) => {
@@ -199,6 +199,9 @@ export class FXLFrameManager {
199
199
  async unfocus(): Promise<void> {
200
200
  if(this.frame.parentElement) {
201
201
  if(this.comms === undefined) return;
202
+ // Return focus to the parent document so keyboard events aren't silently
203
+ // swallowed by an off-screen iframe whose comms channel has been halted.
204
+ this.frame.blur();
202
205
  return new Promise((res, _) => {
203
206
  this.comms?.send("unfocus", undefined, (_: boolean) => {
204
207
  this.comms?.halt();
@@ -72,6 +72,7 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
72
72
  private _css: WebPubCSS;
73
73
  private _preferencesEditor: WebPubPreferencesEditor | null = null;
74
74
  private readonly _injector: Injector | null = null;
75
+ private _isNavigating = false;
75
76
  private readonly _contentProtection: IContentProtectionConfig;
76
77
  private readonly _keyboardPeripherals: IKeyboardPeripheralsConfig;
77
78
  private readonly _navigatorProtector: NavigatorProtector | null = null;
@@ -463,14 +464,20 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
463
464
  }
464
465
 
465
466
  goBackward(_animated: boolean, cb: (ok: boolean) => void): void {
466
- this.changeResource(-1).then((success) => {
467
- cb(success);
467
+ if(this._isNavigating) { cb(false); return; }
468
+ this._isNavigating = true;
469
+ this.changeResource(-1).then((ok) => {
470
+ this._isNavigating = false;
471
+ cb(ok);
468
472
  });
469
473
  }
470
474
 
471
475
  goForward(_animated: boolean, cb: (ok: boolean) => void): void {
472
- this.changeResource(1).then((success) => {
473
- cb(success);
476
+ if(this._isNavigating) { cb(false); return; }
477
+ this._isNavigating = true;
478
+ this.changeResource(1).then((ok) => {
479
+ this._isNavigating = false;
480
+ cb(ok);
474
481
  });
475
482
  }
476
483
 
@@ -581,8 +588,14 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
581
588
  this.currentIndex = index;
582
589
  }
583
590
 
591
+ if(this._isNavigating) { cb(false); return; }
592
+ this._isNavigating = true;
593
+
584
594
  this.currentLocation = this.createCurrentLocator();
585
- this.apply().then(() => this.loadLocator(locator, (ok) => cb(ok))).then(() => {
595
+ this.apply().then(() => this.loadLocator(locator, (ok) => {
596
+ this._isNavigating = false;
597
+ cb(ok);
598
+ })).then(() => {
586
599
  // Now that we've gone to the right locator, we can attach the listeners.
587
600
  // Doing this only at this stage reduces janky UI with multiple locator updates.
588
601
  this.attachListener();
@@ -50,6 +50,7 @@ export declare class EpubNavigator extends VisualNavigator implements Configurab
50
50
  private _css;
51
51
  private _preferencesEditor;
52
52
  private _injector;
53
+ private _isNavigating;
53
54
  private readonly _readiumRulesPromise;
54
55
  private readonly _injectablesConfig;
55
56
  private readonly _contentProtection;
@@ -44,6 +44,7 @@ export declare class WebPubNavigator extends VisualNavigator implements Configur
44
44
  private _css;
45
45
  private _preferencesEditor;
46
46
  private readonly _injector;
47
+ private _isNavigating;
47
48
  private readonly _contentProtection;
48
49
  private readonly _keyboardPeripherals;
49
50
  private readonly _navigatorProtector;