@types/hotwired__turbo 8.0.5 → 8.0.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.
- hotwired__turbo/README.md +1 -1
- hotwired__turbo/index.d.ts +297 -7
- hotwired__turbo/package.json +2 -2
hotwired__turbo/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for @hotwired/turbo (https://turbo.hotwir
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hotwired__turbo.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Tue, 03 Feb 2026 08:44:26 GMT
|
|
12
12
|
* Dependencies: none
|
|
13
13
|
|
|
14
14
|
# Credits
|
hotwired__turbo/index.d.ts
CHANGED
|
@@ -13,10 +13,13 @@ export class FrameElement extends HTMLElement {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export class StreamElement extends HTMLElement {
|
|
16
|
+
static renderElement(newElement: StreamElement): Promise<void>;
|
|
17
|
+
|
|
16
18
|
connectedCallback(): Promise<void>;
|
|
17
19
|
render(): Promise<void>;
|
|
18
20
|
disconnect(): void;
|
|
19
21
|
removeDuplicateTargetChildren(): void;
|
|
22
|
+
removeDuplicateTargetSiblings(): void;
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
* The current action.
|
|
@@ -38,6 +41,41 @@ export class StreamElement extends HTMLElement {
|
|
|
38
41
|
* Reads the request-id attribute
|
|
39
42
|
*/
|
|
40
43
|
readonly requestId: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Gets the main `<template>` element used for rendering.
|
|
47
|
+
*/
|
|
48
|
+
readonly templateElement: HTMLTemplateElement;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets a cloned copy of the template's content.
|
|
52
|
+
*/
|
|
53
|
+
readonly templateContent: DocumentFragment;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class StreamSourceElement extends HTMLElement {
|
|
57
|
+
streamSource: WebSocket | EventSource | null;
|
|
58
|
+
readonly src: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface StreamSource {
|
|
62
|
+
addEventListener(
|
|
63
|
+
type: "message",
|
|
64
|
+
listener: (event: MessageEvent) => void,
|
|
65
|
+
options?: boolean | AddEventListenerOptions,
|
|
66
|
+
): void;
|
|
67
|
+
removeEventListener(
|
|
68
|
+
type: "message",
|
|
69
|
+
listener: (event: MessageEvent) => void,
|
|
70
|
+
options?: boolean | EventListenerOptions,
|
|
71
|
+
): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class StreamMessage {
|
|
75
|
+
static readonly contentType: "text/vnd.turbo-stream.html";
|
|
76
|
+
readonly fragment: DocumentFragment;
|
|
77
|
+
static wrap(message: StreamMessage | string): StreamMessage;
|
|
78
|
+
constructor(fragment: DocumentFragment);
|
|
41
79
|
}
|
|
42
80
|
|
|
43
81
|
export class FetchRequest {
|
|
@@ -67,19 +105,114 @@ export class FetchResponse {
|
|
|
67
105
|
succeeded: boolean;
|
|
68
106
|
}
|
|
69
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Interface for accessing the browser adapter.
|
|
110
|
+
* The adapter handles form submission lifecycle events.
|
|
111
|
+
*/
|
|
112
|
+
export interface BrowserAdapter {
|
|
113
|
+
formSubmissionStarted(formSubmission?: FormSubmission): void;
|
|
114
|
+
formSubmissionFinished(formSubmission?: FormSubmission): void;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Interface for the Turbo navigator.
|
|
119
|
+
* Provides methods for programmatic navigation and form submission.
|
|
120
|
+
*/
|
|
121
|
+
export interface Navigator {
|
|
122
|
+
/**
|
|
123
|
+
* Submits a form programmatically through Turbo Drive.
|
|
124
|
+
*
|
|
125
|
+
* @param form The form element to submit
|
|
126
|
+
* @param submitter Optional submitter element (button or input)
|
|
127
|
+
*/
|
|
128
|
+
submitForm(form: HTMLFormElement, submitter?: HTMLElement): void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Interface for the Turbo page cache.
|
|
133
|
+
* Provides methods for managing the page cache.
|
|
134
|
+
*/
|
|
135
|
+
export interface Cache {
|
|
136
|
+
/**
|
|
137
|
+
* Removes all entries from the Turbo Drive page cache.
|
|
138
|
+
* Call this when state has changed on the server that may affect cached pages.
|
|
139
|
+
*/
|
|
140
|
+
clear(): void;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Resets the cache control meta tag to allow normal caching.
|
|
144
|
+
*/
|
|
145
|
+
resetCacheControl(): void;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Sets the cache control meta tag to "no-cache", preventing the page from being cached.
|
|
149
|
+
*/
|
|
150
|
+
exemptPageFromCache(): void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Sets the cache control meta tag to "no-preview", preventing the page from being used as a preview.
|
|
154
|
+
*/
|
|
155
|
+
exemptPageFromPreview(): void;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Configuration for Turbo Drive.
|
|
160
|
+
*/
|
|
161
|
+
export interface DriveConfig {
|
|
162
|
+
/** Whether Turbo Drive is enabled. Defaults to true. */
|
|
163
|
+
enabled: boolean;
|
|
164
|
+
/** Delay in milliseconds before showing the progress bar. Defaults to 500. */
|
|
165
|
+
progressBarDelay: number;
|
|
166
|
+
/** Set of file extensions that should not be handled by Turbo Drive. */
|
|
167
|
+
unvisitableExtensions: Set<string>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Submitter configuration callbacks for form submission.
|
|
172
|
+
*/
|
|
173
|
+
export interface SubmitterConfig {
|
|
174
|
+
/** Called before form submission to disable the submitter. */
|
|
175
|
+
beforeSubmit(submitter: HTMLElement): void;
|
|
176
|
+
/** Called after form submission to re-enable the submitter. */
|
|
177
|
+
afterSubmit(submitter: HTMLElement): void;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Configuration for Turbo form handling.
|
|
182
|
+
*/
|
|
183
|
+
export interface FormsConfig {
|
|
184
|
+
/** Form handling mode: "on" (default), "off", or "optin". */
|
|
185
|
+
mode: "on" | "off" | "optin";
|
|
186
|
+
/** Custom confirmation method. Falls back to window.confirm if not defined. */
|
|
187
|
+
confirm?: (message: string, element: HTMLFormElement, submitter: HTMLElement | null) => Promise<boolean>;
|
|
188
|
+
/**
|
|
189
|
+
* Controls how submitters are disabled during form submission.
|
|
190
|
+
* Can be "disabled" (default), "aria-disabled", or a custom SubmitterConfig.
|
|
191
|
+
*/
|
|
192
|
+
submitter: "disabled" | "aria-disabled" | SubmitterConfig;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The Turbo configuration object.
|
|
197
|
+
*/
|
|
198
|
+
export interface TurboConfig {
|
|
199
|
+
drive: DriveConfig;
|
|
200
|
+
forms: FormsConfig;
|
|
201
|
+
}
|
|
202
|
+
|
|
70
203
|
/**
|
|
71
204
|
* Connects a stream source to the main session.
|
|
72
205
|
*
|
|
73
206
|
* @param source Stream source to connect
|
|
74
207
|
*/
|
|
75
|
-
export function connectStreamSource(source:
|
|
208
|
+
export function connectStreamSource(source: StreamSource): void;
|
|
76
209
|
|
|
77
210
|
/**
|
|
78
211
|
* Disconnects a stream source from the main session.
|
|
79
212
|
*
|
|
80
213
|
* @param source Stream source to disconnect
|
|
81
214
|
*/
|
|
82
|
-
export function disconnectStreamSource(source:
|
|
215
|
+
export function disconnectStreamSource(source: StreamSource): void;
|
|
83
216
|
|
|
84
217
|
/**
|
|
85
218
|
* Renders a stream message to the main session by appending it to the
|
|
@@ -87,13 +220,14 @@ export function disconnectStreamSource(source: unknown): void;
|
|
|
87
220
|
*
|
|
88
221
|
* @param message Message to render
|
|
89
222
|
*/
|
|
90
|
-
export function renderStreamMessage(message:
|
|
223
|
+
export function renderStreamMessage(message: StreamMessage | string): void;
|
|
91
224
|
|
|
92
225
|
export interface TurboSession {
|
|
93
|
-
connectStreamSource(source:
|
|
94
|
-
disconnectStreamSource(source:
|
|
95
|
-
renderStreamMessage(message:
|
|
226
|
+
connectStreamSource(source: StreamSource): void;
|
|
227
|
+
disconnectStreamSource(source: StreamSource): void;
|
|
228
|
+
renderStreamMessage(message: StreamMessage | string): void;
|
|
96
229
|
drive: boolean;
|
|
230
|
+
adapter: BrowserAdapter;
|
|
97
231
|
}
|
|
98
232
|
|
|
99
233
|
export const StreamActions: {
|
|
@@ -107,6 +241,93 @@ export interface VisitOptions {
|
|
|
107
241
|
}
|
|
108
242
|
export function visit(location: string, options?: VisitOptions): void;
|
|
109
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Starts the main Turbo session.
|
|
246
|
+
* This initializes observers to monitor link interactions.
|
|
247
|
+
*/
|
|
248
|
+
export function start(): void;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Registers an adapter for the main session.
|
|
252
|
+
*
|
|
253
|
+
* @param adapter Adapter to register
|
|
254
|
+
*/
|
|
255
|
+
export function registerAdapter(adapter: unknown): void;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Sets the form mode for Turbo Drive.
|
|
259
|
+
*
|
|
260
|
+
* @param mode Form handling mode
|
|
261
|
+
* @deprecated Use `Turbo.config.forms.mode = mode` instead.
|
|
262
|
+
*/
|
|
263
|
+
export function setFormMode(mode: "on" | "off" | "optin"): void;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Options for morphing elements.
|
|
267
|
+
*/
|
|
268
|
+
export interface MorphOptions {
|
|
269
|
+
callbacks?: {
|
|
270
|
+
beforeNodeMorphed?: (currentElement: Element, newElement: Element) => boolean;
|
|
271
|
+
};
|
|
272
|
+
morphStyle?: "innerHTML" | "outerHTML";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Morph the state of the currentElement based on the attributes and contents of
|
|
277
|
+
* the newElement. Morphing may dispatch turbo:before-morph-element,
|
|
278
|
+
* turbo:before-morph-attribute, and turbo:morph-element events.
|
|
279
|
+
*
|
|
280
|
+
* @param currentElement Element destination of morphing changes
|
|
281
|
+
* @param newElement Element source of morphing changes
|
|
282
|
+
* @param options Optional morphing options
|
|
283
|
+
*/
|
|
284
|
+
export function morphElements(currentElement: Element, newElement: Element | ChildNode[], options?: MorphOptions): void;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Morph the child elements of the currentElement based on the child elements of
|
|
288
|
+
* the newElement. Morphing children may dispatch turbo:before-morph-element,
|
|
289
|
+
* turbo:before-morph-attribute, and turbo:morph-element events.
|
|
290
|
+
*
|
|
291
|
+
* @param currentElement Element destination of morphing children changes
|
|
292
|
+
* @param newElement Element source of morphing children changes
|
|
293
|
+
* @param options Optional morphing options
|
|
294
|
+
*/
|
|
295
|
+
export function morphChildren(currentElement: Element, newElement: Element, options?: MorphOptions): void;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Morph the state of the currentBody based on the attributes and contents of
|
|
299
|
+
* the newBody. Morphing body elements may dispatch turbo:morph,
|
|
300
|
+
* turbo:before-morph-element, turbo:before-morph-attribute, and
|
|
301
|
+
* turbo:morph-element events.
|
|
302
|
+
*
|
|
303
|
+
* @param currentBody HTMLBodyElement destination of morphing changes
|
|
304
|
+
* @param newBody HTMLBodyElement source of morphing changes
|
|
305
|
+
*/
|
|
306
|
+
export function morphBodyElements(currentBody: HTMLBodyElement, newBody: HTMLBodyElement): void;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Morph the child elements of the currentFrame based on the child elements of
|
|
310
|
+
* the newFrame. Morphing turbo-frame elements may dispatch turbo:before-frame-morph,
|
|
311
|
+
* turbo:before-morph-element, turbo:before-morph-attribute, and
|
|
312
|
+
* turbo:morph-element events.
|
|
313
|
+
*
|
|
314
|
+
* @param currentFrame FrameElement destination of morphing children changes
|
|
315
|
+
* @param newFrame FrameElement source of morphing children changes
|
|
316
|
+
*/
|
|
317
|
+
export function morphTurboFrameElements(currentFrame: FrameElement, newFrame: FrameElement): void;
|
|
318
|
+
|
|
319
|
+
/** The Turbo session navigator */
|
|
320
|
+
export const navigator: Navigator;
|
|
321
|
+
|
|
322
|
+
/** The Turbo page cache */
|
|
323
|
+
export const cache: Cache;
|
|
324
|
+
|
|
325
|
+
/** The Turbo configuration object */
|
|
326
|
+
export const config: TurboConfig;
|
|
327
|
+
|
|
328
|
+
/** The Turbo session */
|
|
329
|
+
export const session: TurboSession;
|
|
330
|
+
|
|
110
331
|
export interface TurboGlobal {
|
|
111
332
|
/**
|
|
112
333
|
* Sets the delay after which the {@link https://turbo.hotwired.dev/handbook/drive#displaying-progress progress bar} will appear during navigation, in milliseconds.
|
|
@@ -115,23 +336,61 @@ export interface TurboGlobal {
|
|
|
115
336
|
* Note that this method has no effect when used with the iOS or Android adapters.
|
|
116
337
|
*
|
|
117
338
|
* @param delayInMilliseconds
|
|
339
|
+
* @deprecated Use `Turbo.config.drive.progressBarDelay = delayInMilliseconds` instead.
|
|
118
340
|
*/
|
|
119
341
|
setProgressBarDelay(delayInMilliseconds: number): void;
|
|
120
342
|
|
|
121
343
|
/**
|
|
122
344
|
* Sets the method that is called by links decorated with {@link https://turbo.hotwired.dev/handbook/drive#requiring-confirmation-for-a-visit data-turbo-confirm}.
|
|
123
345
|
**
|
|
124
|
-
* The default is the browser
|
|
346
|
+
* The default is the browser's built in confirm.
|
|
125
347
|
*
|
|
126
348
|
* The method should return true if the visit can proceed.
|
|
127
349
|
*
|
|
128
350
|
* @param confirmMethod
|
|
351
|
+
* @deprecated Use `Turbo.config.forms.confirm = confirmMethod` instead.
|
|
129
352
|
*/
|
|
130
353
|
setConfirmMethod(confirmMethod: () => boolean): void;
|
|
131
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Sets the form mode for Turbo Drive.
|
|
357
|
+
*
|
|
358
|
+
* @param mode Form handling mode
|
|
359
|
+
* @deprecated Use `Turbo.config.forms.mode = mode` instead.
|
|
360
|
+
*/
|
|
361
|
+
setFormMode(mode: "on" | "off" | "optin"): void;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Registers an adapter for the main session.
|
|
365
|
+
*
|
|
366
|
+
* @param adapter Adapter to register
|
|
367
|
+
*/
|
|
368
|
+
registerAdapter(adapter: unknown): void;
|
|
369
|
+
|
|
132
370
|
visit(location: string, options?: { action?: Action; frame?: string }): void;
|
|
133
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Starts the main Turbo session.
|
|
374
|
+
* This initializes observers to monitor link interactions.
|
|
375
|
+
*/
|
|
376
|
+
start(): void;
|
|
377
|
+
|
|
378
|
+
connectStreamSource(source: StreamSource): void;
|
|
379
|
+
disconnectStreamSource(source: StreamSource): void;
|
|
380
|
+
renderStreamMessage(message: StreamMessage | string): void;
|
|
381
|
+
|
|
382
|
+
morphElements(currentElement: Element, newElement: Element | ChildNode[], options?: MorphOptions): void;
|
|
383
|
+
morphChildren(currentElement: Element, newElement: Element, options?: MorphOptions): void;
|
|
384
|
+
morphBodyElements(currentBody: HTMLBodyElement, newBody: HTMLBodyElement): void;
|
|
385
|
+
morphTurboFrameElements(currentFrame: FrameElement, newFrame: FrameElement): void;
|
|
386
|
+
|
|
134
387
|
session: TurboSession;
|
|
388
|
+
navigator: Navigator;
|
|
389
|
+
cache: Cache;
|
|
390
|
+
config: TurboConfig;
|
|
391
|
+
StreamActions: {
|
|
392
|
+
[action: string]: (this: StreamElement) => void;
|
|
393
|
+
};
|
|
135
394
|
}
|
|
136
395
|
|
|
137
396
|
declare global {
|
|
@@ -175,6 +434,31 @@ export type TurboBeforeStreamRenderEvent = CustomEvent<{
|
|
|
175
434
|
render: Render;
|
|
176
435
|
}>;
|
|
177
436
|
|
|
437
|
+
export type TurboMorphEvent = CustomEvent<{
|
|
438
|
+
currentElement: Element;
|
|
439
|
+
newElement: Element;
|
|
440
|
+
}>;
|
|
441
|
+
|
|
442
|
+
export type TurboBeforeMorphElementEvent = CustomEvent<{
|
|
443
|
+
currentElement: Element;
|
|
444
|
+
newElement: Element;
|
|
445
|
+
}>;
|
|
446
|
+
|
|
447
|
+
export type TurboMorphElementEvent = CustomEvent<{
|
|
448
|
+
currentElement: Element;
|
|
449
|
+
newElement: Element;
|
|
450
|
+
}>;
|
|
451
|
+
|
|
452
|
+
export type TurboBeforeMorphAttributeEvent = CustomEvent<{
|
|
453
|
+
attributeName: string;
|
|
454
|
+
mutationType: "updated" | "removed";
|
|
455
|
+
}>;
|
|
456
|
+
|
|
457
|
+
export type TurboBeforeFrameMorphEvent = CustomEvent<{
|
|
458
|
+
currentElement: FrameElement;
|
|
459
|
+
newElement: FrameElement;
|
|
460
|
+
}>;
|
|
461
|
+
|
|
178
462
|
export interface FormSubmission {
|
|
179
463
|
action: string;
|
|
180
464
|
body: FormData | URLSearchParams;
|
|
@@ -222,6 +506,7 @@ export type TurboFetchRequestErrorEvent = CustomEvent<{
|
|
|
222
506
|
export interface TurboElementTagNameMap {
|
|
223
507
|
"turbo-frame": FrameElement;
|
|
224
508
|
"turbo-stream": StreamElement;
|
|
509
|
+
"turbo-stream-source": StreamSourceElement;
|
|
225
510
|
}
|
|
226
511
|
|
|
227
512
|
export interface TurboElementEventMap {
|
|
@@ -247,6 +532,11 @@ export interface TurboGlobalEventHandlersEventMap extends TurboElementEventMap {
|
|
|
247
532
|
"turbo:render": TurboRenderEvent;
|
|
248
533
|
"turbo:reload": TurboReloadEvent;
|
|
249
534
|
"turbo:visit": TurboVisitEvent;
|
|
535
|
+
"turbo:morph": TurboMorphEvent;
|
|
536
|
+
"turbo:before-morph-element": TurboBeforeMorphElementEvent;
|
|
537
|
+
"turbo:morph-element": TurboMorphElementEvent;
|
|
538
|
+
"turbo:before-morph-attribute": TurboBeforeMorphAttributeEvent;
|
|
539
|
+
"turbo:before-frame-morph": TurboBeforeFrameMorphEvent;
|
|
250
540
|
}
|
|
251
541
|
|
|
252
542
|
declare global {
|
hotwired__turbo/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/hotwired__turbo",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.6",
|
|
4
4
|
"description": "TypeScript definitions for @hotwired/turbo",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hotwired__turbo",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"scripts": {},
|
|
32
32
|
"dependencies": {},
|
|
33
33
|
"peerDependencies": {},
|
|
34
|
-
"typesPublisherContentHash": "
|
|
34
|
+
"typesPublisherContentHash": "3413337378061f55d2a3cc7e42d4c4de9965540188d35a5fe149152450814574",
|
|
35
35
|
"typeScriptVersion": "5.2"
|
|
36
36
|
}
|