forked from hotwired/turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
104 lines (94 loc) · 3.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Adapter } from "./native/adapter"
import { Session } from "./session"
import { Locatable } from "./url"
import { StreamMessage } from "./streams/stream_message"
import { StreamSource } from "./types"
import { VisitOptions } from "./drive/visit"
import { PageRenderer } from "./drive/page_renderer"
import { PageSnapshot } from "./drive/page_snapshot"
import { FrameRenderer } from "./frames/frame_renderer"
import { FormSubmission } from "./drive/form_submission"
const session = new Session
const { navigator } = session
export { navigator, session, PageRenderer, PageSnapshot, FrameRenderer }
/**
* Starts the main session.
* This initialises any necessary observers such as those to monitor
* link interactions.
*/
export function start() {
session.start()
}
/**
* Registers an adapter for the main session.
*
* @param adapter Adapter to register
*/
export function registerAdapter(adapter: Adapter) {
session.registerAdapter(adapter)
}
/**
* Performs an application visit to the given location.
*
* @param location Location to visit (a URL or path)
* @param options Options to apply
* @param options.action Type of history navigation to apply ("restore",
* "replace" or "advance")
* @param options.historyChanged Specifies whether the browser history has
* already been changed for this visit or not
* @param options.referrer Specifies the referrer of this visit such that
* navigations to the same page will not result in a new history entry.
* @param options.snapshotHTML Cached snapshot to render
* @param options.response Response of the specified location
*/
export function visit(location: Locatable, options?: Partial<VisitOptions>) {
session.visit(location, options)
}
/**
* Connects a stream source to the main session.
*
* @param source Stream source to connect
*/
export function connectStreamSource(source: StreamSource) {
session.connectStreamSource(source)
}
/**
* Disconnects a stream source from the main session.
*
* @param source Stream source to disconnect
*/
export function disconnectStreamSource(source: StreamSource) {
session.disconnectStreamSource(source)
}
/**
* Renders a stream message to the main session by appending it to the
* current document.
*
* @param message Message to render
*/
export function renderStreamMessage(message: StreamMessage | string) {
session.renderStreamMessage(message)
}
/**
* Removes all entries from the Turbo Drive page cache.
* Call this when state has changed on the server that may affect cached pages.
*/
export function clearCache() {
session.clearCache()
}
/**
* Sets the delay after which the progress bar will appear during navigation.
*
* The progress bar appears after 500ms by default.
*
* Note that this method has no effect when used with the iOS or Android
* adapters.
*
* @param delay Time to delay in milliseconds
*/
export function setProgressBarDelay(delay: number) {
session.setProgressBarDelay(delay)
}
export function setConfirmMethod(confirmMethod: (message: string, element: HTMLFormElement)=>boolean) {
FormSubmission.confirmMethod = confirmMethod
}