From c102f05bbf78976bf3f2bdb67d8ef5fd9ee10f9e Mon Sep 17 00:00:00 2001 From: Tom Wilkinson Date: Wed, 28 Jul 2021 16:41:52 -0500 Subject: [PATCH 1/5] Create app_history.d.ts --- app_history.d.ts | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app_history.d.ts diff --git a/app_history.d.ts b/app_history.d.ts new file mode 100644 index 0000000..71c748a --- /dev/null +++ b/app_history.d.ts @@ -0,0 +1,99 @@ +interface Window { + readonly appHistory: AppHistory; +} + +interface AppHistory extends EventTarget { + readonly current: AppHistoryEntry|null; + readonly transition: AppHistoryTransition|null; + + entries(): AppHistoryEntry[]; + + readonly canGoBack: boolean; + readonly canGoForward: boolean; + + navigate(url: string, options?: AppHistoryNavigateOptions): Promise; + reload(options?: AppHistoryReloadOptions): Promise; + + goTo(key: string, options?: AppHistoryNavigationOptions): Promise; + back(options?: AppHistoryNavigationOptions): Promise; + forward(options?: AppHistoryNavigationOptions): Promise; + + onnavigate: ((ev: Event) => any)|null; + onnavigatesuccess: ((ev: Event) => any)|null; + onnavigateerror: ((ev: Event) => any)|null; +} + +interface AppHistoryTransition { + readonly navigationType: AppHistoryNavigationType; + readonly from: AppHistoryEntry; + readonly finished: Promise; + + rollback(options?: AppHistoryNavigationOptions): Promise; +} + +interface AppHistoryEntry { + readonly key: string; + readonly id: string; + readonly url: string; + readonly index: number; + readonly sameDocument: boolean; + + getState(): unknown; + + onnavigateto: ((ev: Event) => any)|null; + onnavigatefrom: ((ev: Event) => any)|null; + onfinish: ((ev: Event) => any)|null; + ondispose: ((ev: Event) => any)|null; +} + +type AppHistoryNavigationType = 'reload'|'push'|'replace'|'traverse'; + +interface AppHistoryNavigationOptions { + navigateInfo?: unknown; +} + +interface AppHistoryNavigateOptions extends AppHistoryNavigationOptions { + state?: unknown; + replace?: boolean; +} + +interface AppHistoryReloadOptions extends AppHistoryNavigationOptions { + state?: unknown; +} + +declare class AppHistoryNavigateEvent { + constructor(type: string, eventInit?: AppHistoryNavigateEventInit); + + readonly navigationType: AppHistoryNavigationType; + readonly canRespond: boolean; + readonly userInitiated: boolean; + readonly hashChange: boolean; + readonly destination: AppHistoryDestination; + readonly signal: AbortSignal; + readonly formData: FormData|null; + readonly info: unknown; + + respondWith(newNavigationAction: Promise): void; +} + +interface AppHistoryNavigateEventInit extends EventInit { + navigationType?: AppHistoryNavigationType; + canRespond?: boolean; + userInitiated?: boolean; + hashChange?: boolean; + destination?: AppHistoryDestination; + signal?: AbortSignal; + formData?: FormData|null; + info?: unknown; +} + +interface AppHistoryDestination { + readonly url: string; + readonly attribute: string; + readonly key: string|null; + readonly id: string|null; + readonly index: number; + readonly sameDocument: boolean; + + getState(): unknown; +} From a92720acffcaecfaa7300c8e08201f936d7a8279 Mon Sep 17 00:00:00 2001 From: Tom Wilkinson Date: Wed, 28 Jul 2021 16:49:24 -0500 Subject: [PATCH 2/5] Update app_history.d.ts Fix a few super classes --- app_history.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app_history.d.ts b/app_history.d.ts index 71c748a..a578338 100644 --- a/app_history.d.ts +++ b/app_history.d.ts @@ -31,7 +31,7 @@ interface AppHistoryTransition { rollback(options?: AppHistoryNavigationOptions): Promise; } -interface AppHistoryEntry { +interface AppHistoryEntry extends EventTarget { readonly key: string; readonly id: string; readonly url: string; @@ -61,7 +61,7 @@ interface AppHistoryReloadOptions extends AppHistoryNavigationOptions { state?: unknown; } -declare class AppHistoryNavigateEvent { +declare class AppHistoryNavigateEvent extends Event { constructor(type: string, eventInit?: AppHistoryNavigateEventInit); readonly navigationType: AppHistoryNavigationType; From 43300dee8c4019355e5b0f0ab0e7d2b56cdcd13a Mon Sep 17 00:00:00 2001 From: Tom Wilkinson Date: Thu, 29 Jul 2021 09:10:45 -0500 Subject: [PATCH 3/5] Update app_history.d.ts Updates in response to comments. --- app_history.d.ts | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/app_history.d.ts b/app_history.d.ts index a578338..45363c8 100644 --- a/app_history.d.ts +++ b/app_history.d.ts @@ -2,7 +2,7 @@ interface Window { readonly appHistory: AppHistory; } -interface AppHistory extends EventTarget { +declare class AppHistory extends EventTarget { readonly current: AppHistoryEntry|null; readonly transition: AppHistoryTransition|null; @@ -18,12 +18,12 @@ interface AppHistory extends EventTarget { back(options?: AppHistoryNavigationOptions): Promise; forward(options?: AppHistoryNavigationOptions): Promise; - onnavigate: ((ev: Event) => any)|null; - onnavigatesuccess: ((ev: Event) => any)|null; - onnavigateerror: ((ev: Event) => any)|null; + onnavigate: ((this: AppHistory, ev: Event) => any)|null; + onnavigatesuccess: ((this: AppHistory, ev: Event) => any)|null; + onnavigateerror: ((this: AppHistory, ev: Event) => any)|null; } -interface AppHistoryTransition { +declare class AppHistoryTransition { readonly navigationType: AppHistoryNavigationType; readonly from: AppHistoryEntry; readonly finished: Promise; @@ -31,7 +31,7 @@ interface AppHistoryTransition { rollback(options?: AppHistoryNavigationOptions): Promise; } -interface AppHistoryEntry extends EventTarget { +declare class AppHistoryEntry extends EventTarget { readonly key: string; readonly id: string; readonly url: string; @@ -40,29 +40,29 @@ interface AppHistoryEntry extends EventTarget { getState(): unknown; - onnavigateto: ((ev: Event) => any)|null; - onnavigatefrom: ((ev: Event) => any)|null; - onfinish: ((ev: Event) => any)|null; - ondispose: ((ev: Event) => any)|null; + onnavigateto: ((this: AppHistoryEntry, ev: Event) => any)|null; + onnavigatefrom: ((this: AppHistoryEntry, ev: Event) => any)|null; + onfinish: ((this: AppHistoryEntry, ev: Event) => any)|null; + ondispose: ((this: AppHistoryEntry, ev: Event) => any)|null; } type AppHistoryNavigationType = 'reload'|'push'|'replace'|'traverse'; -interface AppHistoryNavigationOptions { +declare class AppHistoryNavigationOptions { navigateInfo?: unknown; } -interface AppHistoryNavigateOptions extends AppHistoryNavigationOptions { +declare class AppHistoryNavigateOptions extends AppHistoryNavigationOptions { state?: unknown; replace?: boolean; } -interface AppHistoryReloadOptions extends AppHistoryNavigationOptions { +declare class AppHistoryReloadOptions extends AppHistoryNavigationOptions { state?: unknown; } declare class AppHistoryNavigateEvent extends Event { - constructor(type: string, eventInit?: AppHistoryNavigateEventInit); + constructor(type: string, eventInit: AppHistoryNavigateEventInit); readonly navigationType: AppHistoryNavigationType; readonly canRespond: boolean; @@ -76,20 +76,19 @@ declare class AppHistoryNavigateEvent extends Event { respondWith(newNavigationAction: Promise): void; } -interface AppHistoryNavigateEventInit extends EventInit { +declare class AppHistoryNavigateEventInit extends EventInit { navigationType?: AppHistoryNavigationType; canRespond?: boolean; userInitiated?: boolean; hashChange?: boolean; - destination?: AppHistoryDestination; - signal?: AbortSignal; + destination: AppHistoryDestination; + signal: AbortSignal; formData?: FormData|null; info?: unknown; } -interface AppHistoryDestination { +declare class AppHistoryDestination { readonly url: string; - readonly attribute: string; readonly key: string|null; readonly id: string|null; readonly index: number; From acfa7bf63cbbd502f21be19837eba803fc9cbec2 Mon Sep 17 00:00:00 2001 From: Tom Wilkinson Date: Thu, 29 Jul 2021 13:22:15 -0500 Subject: [PATCH 4/5] Update app_history.d.ts Additional changes in response to review. --- app_history.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app_history.d.ts b/app_history.d.ts index 45363c8..d5c760d 100644 --- a/app_history.d.ts +++ b/app_history.d.ts @@ -18,9 +18,9 @@ declare class AppHistory extends EventTarget { back(options?: AppHistoryNavigationOptions): Promise; forward(options?: AppHistoryNavigationOptions): Promise; - onnavigate: ((this: AppHistory, ev: Event) => any)|null; + onnavigate: ((this: AppHistory, ev: AppHistoryNavigateEvent) => any)|null; onnavigatesuccess: ((this: AppHistory, ev: Event) => any)|null; - onnavigateerror: ((this: AppHistory, ev: Event) => any)|null; + onnavigateerror: ((this: AppHistory, ev: ErrorEvent) => any)|null; } declare class AppHistoryTransition { @@ -48,16 +48,16 @@ declare class AppHistoryEntry extends EventTarget { type AppHistoryNavigationType = 'reload'|'push'|'replace'|'traverse'; -declare class AppHistoryNavigationOptions { +interface AppHistoryNavigationOptions { navigateInfo?: unknown; } -declare class AppHistoryNavigateOptions extends AppHistoryNavigationOptions { +interface AppHistoryNavigateOptions extends AppHistoryNavigationOptions { state?: unknown; replace?: boolean; } -declare class AppHistoryReloadOptions extends AppHistoryNavigationOptions { +interface AppHistoryReloadOptions extends AppHistoryNavigationOptions { state?: unknown; } From 5ae87aa5b3a29f9a0867292036e0169629ec665d Mon Sep 17 00:00:00 2001 From: Tom Wilkinson Date: Thu, 29 Jul 2021 13:26:10 -0500 Subject: [PATCH 5/5] Update app_history.d.ts One last interface --- app_history.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_history.d.ts b/app_history.d.ts index d5c760d..69e65f7 100644 --- a/app_history.d.ts +++ b/app_history.d.ts @@ -76,7 +76,7 @@ declare class AppHistoryNavigateEvent extends Event { respondWith(newNavigationAction: Promise): void; } -declare class AppHistoryNavigateEventInit extends EventInit { +interface AppHistoryNavigateEventInit extends EventInit { navigationType?: AppHistoryNavigationType; canRespond?: boolean; userInitiated?: boolean;