Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@
/types/current-git-branch/ @maxbogus
/types/curtainsjs/ @Blakeinstein
/types/custom-error-generator/ @thmiceli
/types/custom-functions-runtime/ @OfficeDev @davidchesnut @AlexJerabek @ElizabethSamuel-MSFT @alison-mk
/types/custom-functions-runtime/ @OfficeDev @AlexJerabek @ElizabethSamuel-MSFT @alison-mk
/types/customize-cra/ @k-yle
/types/cvss/ @himynameisdave
/types/cwd/ @BendingBender
Expand Down Expand Up @@ -5033,6 +5033,7 @@
/types/name-all-modules-plugin/ @peterblazejewicz
/types/name-initials/ @atlowChemi
/types/named-routes/ @qqilihq
/types/namespace-emitter/ @remcohaszing
/types/namespace-js/ @kuromoka
/types/nano-cache/ @rcoundon
/types/nano-equal/ @1cheese
Expand Down Expand Up @@ -5391,9 +5392,9 @@
/types/obsolete-web/ @peterblazejewicz
/types/oclazyload/ @rolandzwaga
/types/ofe/ @Morfent
/types/office-js/ @OfficeDev @davidchesnut @AlexJerabek @ElizabethSamuel-MSFT @samantharamon
/types/office-js-preview/ @OfficeDev @davidchesnut @AlexJerabek @ElizabethSamuel-MSFT @samantharamon
/types/office-runtime/ @OfficeDev @davidchesnut @AlexJerabek @ElizabethSamuel-MSFT @alison-mk
/types/office-js/ @OfficeDev @AlexJerabek @ElizabethSamuel-MSFT @samantharamon
/types/office-js-preview/ @OfficeDev @AlexJerabek @ElizabethSamuel-MSFT @samantharamon
/types/office-runtime/ @OfficeDev @AlexJerabek @ElizabethSamuel-MSFT @alison-mk
/types/offline-js/ @cgwrench
/types/offscreen-canvas/ @peterblazejewicz
/types/offscreencanvas/ @kayahr @ova2 @capnmidnight
Expand Down Expand Up @@ -7221,7 +7222,7 @@
/types/shallowequal/v0/ @seansfkelley
/types/shapefile/ @DenisCarriere @Thw0rted
/types/share-api-polyfill/ @jnv
/types/sharedb/ @soney @ericyhwang @pxpeterxu @alecgibson @pypmannetjies @craigbeck
/types/sharedb/ @soney @ericyhwang @pxpeterxu @alecgibson @pypmannetjies @craigbeck @dawidreedsy
/types/sharepoint/ @gandjustas @andrei-markeev @teroarvola @dennispg @SPWizard01 @betlgtu
/types/sharetribe-flex-integration-sdk/ @jayenashar @venmartin
/types/sharetribe-flex-sdk/ @jayenashar @venmartin
Expand Down Expand Up @@ -7812,8 +7813,6 @@
/types/throttle-debounce/ @czbuchi @franklixuefei @oddsund @seiyab
/types/throttleit/ @ifiokjr
/types/through/ @AndrewGaspar
/types/through2/ @Bartvds @valotas @TeamworkGuy2 @Alorel
/types/through2/v0/ @Bartvds
/types/through2-concurrent/ @Alorel
/types/through2-map/ @LucasHill
/types/throw-empty/ @ChocolateLoverRaj
Expand Down Expand Up @@ -8419,6 +8418,7 @@
/types/whois-json/ @hwaien
/types/whois-parsed/ @uchilaka
/types/whoops/ @ffflorian
/types/wicg-cross-origin-storage/ @tomayac @christianliebel
/types/wicg-entries-api/ @HenningCash @RReverser
/types/wicg-file-system-access/ @RReverser
/types/wicg-js-self-profiling/ @NotWoods
Expand Down
45 changes: 45 additions & 0 deletions types/hotwired__turbo/hotwired__turbo-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import {
disconnectStreamSource,
navigator,
NavigatorDelegate,
PageSnapshot,
PageView,
ProgressBar,
registerAdapter,
renderStreamMessage,
session,
SnapshotCache,
start,
StreamActions,
StreamMessage,
Expand Down Expand Up @@ -354,3 +357,45 @@ session.restorationIdentifier;
session.started;
// $ExpectType boolean
session.enabled;

// Test PageView via session.view
// PageView and SnapshotCache are not runtime exports of @hotwired/turbo, only types
// @ts-expect-error
new PageView(session, document.documentElement);
// @ts-expect-error
new SnapshotCache(10);
// $ExpectType PageView
session.view;
// $ExpectType PageView
Turbo.session.view;
// @ts-expect-error - view cannot be reassigned
session.view = session.view;
// $ExpectType URL
session.view.lastRenderedLocation;
session.view.lastRenderedLocation = new URL("https://example.com");
// $ExpectType HTMLElement
session.view.element;
// $ExpectType boolean
session.view.forceReloaded;
// $ExpectType PageSnapshot
session.view.snapshot;
// $ExpectType Promise<PageSnapshot | undefined>
session.view.cacheSnapshot();
session.view.cacheSnapshot(PageSnapshot.fromHTMLString("<html><body></body></html>"));
// $ExpectType PageSnapshot | undefined
session.view.getCachedSnapshotForLocation(new URL("https://example.com"));
session.view.clearSnapshotCache();

// Test SnapshotCache via session.view.snapshotCache
// $ExpectType SnapshotCache
session.view.snapshotCache;
// $ExpectType boolean
session.view.snapshotCache.has(new URL("https://example.com"));
// $ExpectType PageSnapshot | undefined
session.view.snapshotCache.get(new URL("https://example.com"));
// $ExpectType PageSnapshot
session.view.snapshotCache.put(
new URL("https://example.com"),
PageSnapshot.fromHTMLString("<html><body></body></html>"),
);
session.view.snapshotCache.clear();
49 changes: 49 additions & 0 deletions types/hotwired__turbo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,57 @@ export interface TurboHistory {
replace(location: URL, restorationIdentifier?: string): void;
}

export class PageSnapshot {
static fromHTMLString(html?: string): PageSnapshot;
static fromElement(element: Element): PageSnapshot;
static fromDocument(document: Pick<Document, "documentElement" | "body" | "head">): PageSnapshot;

readonly headElement: HTMLHeadElement;
readonly isCacheable: boolean;
readonly isPreviewable: boolean;
readonly isVisitable: boolean;
readonly lang: string | null;
readonly rootLocation: URL;
clone(): PageSnapshot;
}

/**
* An LRU cache of page snapshots, keyed by location.
*
* Note that Turbo does not export the `SnapshotCache` class at runtime —
* obtain the instance via `session.view.snapshotCache`.
*/
export interface SnapshotCache {
has(location: URL): boolean;
get(location: URL): PageSnapshot | undefined;
put(location: URL, snapshot: PageSnapshot): PageSnapshot;
clear(): void;
}

/**
* The session's view of the current page.
*
* Note that Turbo does not export the `PageView` class at runtime —
* obtain the instance via `session.view`.
*/
export interface PageView {
element: HTMLElement;
snapshotCache: SnapshotCache;
/**
* The location of the last rendered page. Keys the snapshot cache and
* page-refresh detection.
*/
lastRenderedLocation: URL;
forceReloaded: boolean;
readonly snapshot: PageSnapshot;
cacheSnapshot(snapshot?: PageSnapshot): Promise<PageSnapshot | undefined>;
getCachedSnapshotForLocation(location: URL): PageSnapshot | undefined;
clearSnapshotCache(): void;
}

export interface TurboSession {
readonly history: TurboHistory;
readonly view: PageView;
adapter: Adapter;
readonly enabled: boolean;
readonly started: boolean;
Expand Down