mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-29 17:40:05 +03:00
feat: add listening for redocUpdatePosition event on window to update scrollPosition by url/history
This commit is contained in:
parent
4be8be3284
commit
621766abed
|
@ -58,6 +58,8 @@ export class AppStore {
|
||||||
private scroll: ScrollService;
|
private scroll: ScrollService;
|
||||||
private disposer: Lambda | null = null;
|
private disposer: Lambda | null = null;
|
||||||
|
|
||||||
|
private readonly listener: EventListenerOrEventListenerObject = this.updateOnEvent.bind(this);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
spec: OpenAPISpec,
|
spec: OpenAPISpec,
|
||||||
specUrl?: string,
|
specUrl?: string,
|
||||||
|
@ -73,7 +75,7 @@ export class AppStore {
|
||||||
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
||||||
|
|
||||||
// Listen for external event to update
|
// Listen for external event to update
|
||||||
window.addEventListener('redocUpdatePosition', this.updateOnEvent);
|
window.addEventListener('redocUpdatePosition', this.listener);
|
||||||
|
|
||||||
// override the openApi standard to version 3.1.0
|
// override the openApi standard to version 3.1.0
|
||||||
// TODO remove when fully supporting open API 3.1.0
|
// TODO remove when fully supporting open API 3.1.0
|
||||||
|
@ -101,7 +103,7 @@ export class AppStore {
|
||||||
dispose() {
|
dispose() {
|
||||||
this.scroll.dispose();
|
this.scroll.dispose();
|
||||||
this.menu.dispose();
|
this.menu.dispose();
|
||||||
window.removeEventListener('redocUpdatePosition', this.updateOnEvent);
|
window.removeEventListener('redocUpdatePosition', this.listener);
|
||||||
if (this.search) {
|
if (this.search) {
|
||||||
this.search.dispose();
|
this.search.dispose();
|
||||||
}
|
}
|
||||||
|
@ -129,10 +131,6 @@ export class AppStore {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateOnEvent(): void {
|
|
||||||
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateMarkOnMenu(idx: number) {
|
private updateMarkOnMenu(idx: number) {
|
||||||
const start = Math.max(0, idx);
|
const start = Math.max(0, idx);
|
||||||
const end = Math.min(this.menu.flatItems.length, start + 5);
|
const end = Math.min(this.menu.flatItems.length, start + 5);
|
||||||
|
@ -157,6 +155,10 @@ export class AppStore {
|
||||||
this.marker.addOnly(elements);
|
this.marker.addOnly(elements);
|
||||||
this.marker.mark();
|
this.marker.mark();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateOnEvent(): void {
|
||||||
|
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_OPTIONS: RedocRawOptions = {
|
const DEFAULT_OPTIONS: RedocRawOptions = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user