@types/hotwired__turbo 8.0.5 → 8.0.7

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 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: Thu, 01 Jan 2026 04:28:37 GMT
11
+ * Last updated: Sun, 01 Mar 2026 23:38:06 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
@@ -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,13 +41,52 @@ 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);
79
+ }
80
+
81
+ export interface FetchRequestHeaders {
82
+ [header: string]: string | undefined;
41
83
  }
42
84
 
43
85
  export class FetchRequest {
44
86
  body: FormData | URLSearchParams;
45
87
  enctype: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
46
88
  fetchOptions: RequestInit;
47
- headers: Headers | { [k: string]: any };
89
+ headers: FetchRequestHeaders;
48
90
  method: "get" | "post" | "put" | "patch" | "delete";
49
91
  params: URLSearchParams;
50
92
  target: HTMLFormElement | HTMLAnchorElement | FrameElement | null;
@@ -67,19 +109,114 @@ export class FetchResponse {
67
109
  succeeded: boolean;
68
110
  }
69
111
 
112
+ /**
113
+ * Interface for accessing the browser adapter.
114
+ * The adapter handles form submission lifecycle events.
115
+ */
116
+ export interface BrowserAdapter {
117
+ formSubmissionStarted(formSubmission?: FormSubmission): void;
118
+ formSubmissionFinished(formSubmission?: FormSubmission): void;
119
+ }
120
+
121
+ /**
122
+ * Interface for the Turbo navigator.
123
+ * Provides methods for programmatic navigation and form submission.
124
+ */
125
+ export interface Navigator {
126
+ /**
127
+ * Submits a form programmatically through Turbo Drive.
128
+ *
129
+ * @param form The form element to submit
130
+ * @param submitter Optional submitter element (button or input)
131
+ */
132
+ submitForm(form: HTMLFormElement, submitter?: HTMLElement): void;
133
+ }
134
+
135
+ /**
136
+ * Interface for the Turbo page cache.
137
+ * Provides methods for managing the page cache.
138
+ */
139
+ export interface Cache {
140
+ /**
141
+ * Removes all entries from the Turbo Drive page cache.
142
+ * Call this when state has changed on the server that may affect cached pages.
143
+ */
144
+ clear(): void;
145
+
146
+ /**
147
+ * Resets the cache control meta tag to allow normal caching.
148
+ */
149
+ resetCacheControl(): void;
150
+
151
+ /**
152
+ * Sets the cache control meta tag to "no-cache", preventing the page from being cached.
153
+ */
154
+ exemptPageFromCache(): void;
155
+
156
+ /**
157
+ * Sets the cache control meta tag to "no-preview", preventing the page from being used as a preview.
158
+ */
159
+ exemptPageFromPreview(): void;
160
+ }
161
+
162
+ /**
163
+ * Configuration for Turbo Drive.
164
+ */
165
+ export interface DriveConfig {
166
+ /** Whether Turbo Drive is enabled. Defaults to true. */
167
+ enabled: boolean;
168
+ /** Delay in milliseconds before showing the progress bar. Defaults to 500. */
169
+ progressBarDelay: number;
170
+ /** Set of file extensions that should not be handled by Turbo Drive. */
171
+ unvisitableExtensions: Set<string>;
172
+ }
173
+
174
+ /**
175
+ * Submitter configuration callbacks for form submission.
176
+ */
177
+ export interface SubmitterConfig {
178
+ /** Called before form submission to disable the submitter. */
179
+ beforeSubmit(submitter: HTMLElement): void;
180
+ /** Called after form submission to re-enable the submitter. */
181
+ afterSubmit(submitter: HTMLElement): void;
182
+ }
183
+
184
+ /**
185
+ * Configuration for Turbo form handling.
186
+ */
187
+ export interface FormsConfig {
188
+ /** Form handling mode: "on" (default), "off", or "optin". */
189
+ mode: "on" | "off" | "optin";
190
+ /** Custom confirmation method. Falls back to window.confirm if not defined. */
191
+ confirm?: (message: string, element: HTMLFormElement, submitter: HTMLElement | null) => Promise<boolean>;
192
+ /**
193
+ * Controls how submitters are disabled during form submission.
194
+ * Can be "disabled" (default), "aria-disabled", or a custom SubmitterConfig.
195
+ */
196
+ submitter: "disabled" | "aria-disabled" | SubmitterConfig;
197
+ }
198
+
199
+ /**
200
+ * The Turbo configuration object.
201
+ */
202
+ export interface TurboConfig {
203
+ drive: DriveConfig;
204
+ forms: FormsConfig;
205
+ }
206
+
70
207
  /**
71
208
  * Connects a stream source to the main session.
72
209
  *
73
210
  * @param source Stream source to connect
74
211
  */
75
- export function connectStreamSource(source: unknown): void;
212
+ export function connectStreamSource(source: StreamSource): void;
76
213
 
77
214
  /**
78
215
  * Disconnects a stream source from the main session.
79
216
  *
80
217
  * @param source Stream source to disconnect
81
218
  */
82
- export function disconnectStreamSource(source: unknown): void;
219
+ export function disconnectStreamSource(source: StreamSource): void;
83
220
 
84
221
  /**
85
222
  * Renders a stream message to the main session by appending it to the
@@ -87,13 +224,14 @@ export function disconnectStreamSource(source: unknown): void;
87
224
  *
88
225
  * @param message Message to render
89
226
  */
90
- export function renderStreamMessage(message: unknown): void;
227
+ export function renderStreamMessage(message: StreamMessage | string): void;
91
228
 
92
229
  export interface TurboSession {
93
- connectStreamSource(source: unknown): void;
94
- disconnectStreamSource(source: unknown): void;
95
- renderStreamMessage(message: unknown): void;
230
+ connectStreamSource(source: StreamSource): void;
231
+ disconnectStreamSource(source: StreamSource): void;
232
+ renderStreamMessage(message: StreamMessage | string): void;
96
233
  drive: boolean;
234
+ adapter: BrowserAdapter;
97
235
  }
98
236
 
99
237
  export const StreamActions: {
@@ -107,6 +245,93 @@ export interface VisitOptions {
107
245
  }
108
246
  export function visit(location: string, options?: VisitOptions): void;
109
247
 
248
+ /**
249
+ * Starts the main Turbo session.
250
+ * This initializes observers to monitor link interactions.
251
+ */
252
+ export function start(): void;
253
+
254
+ /**
255
+ * Registers an adapter for the main session.
256
+ *
257
+ * @param adapter Adapter to register
258
+ */
259
+ export function registerAdapter(adapter: unknown): void;
260
+
261
+ /**
262
+ * Sets the form mode for Turbo Drive.
263
+ *
264
+ * @param mode Form handling mode
265
+ * @deprecated Use `Turbo.config.forms.mode = mode` instead.
266
+ */
267
+ export function setFormMode(mode: "on" | "off" | "optin"): void;
268
+
269
+ /**
270
+ * Options for morphing elements.
271
+ */
272
+ export interface MorphOptions {
273
+ callbacks?: {
274
+ beforeNodeMorphed?: (currentElement: Element, newElement: Element) => boolean;
275
+ };
276
+ morphStyle?: "innerHTML" | "outerHTML";
277
+ }
278
+
279
+ /**
280
+ * Morph the state of the currentElement based on the attributes and contents of
281
+ * the newElement. Morphing may dispatch turbo:before-morph-element,
282
+ * turbo:before-morph-attribute, and turbo:morph-element events.
283
+ *
284
+ * @param currentElement Element destination of morphing changes
285
+ * @param newElement Element source of morphing changes
286
+ * @param options Optional morphing options
287
+ */
288
+ export function morphElements(currentElement: Element, newElement: Element | ChildNode[], options?: MorphOptions): void;
289
+
290
+ /**
291
+ * Morph the child elements of the currentElement based on the child elements of
292
+ * the newElement. Morphing children may dispatch turbo:before-morph-element,
293
+ * turbo:before-morph-attribute, and turbo:morph-element events.
294
+ *
295
+ * @param currentElement Element destination of morphing children changes
296
+ * @param newElement Element source of morphing children changes
297
+ * @param options Optional morphing options
298
+ */
299
+ export function morphChildren(currentElement: Element, newElement: Element, options?: MorphOptions): void;
300
+
301
+ /**
302
+ * Morph the state of the currentBody based on the attributes and contents of
303
+ * the newBody. Morphing body elements may dispatch turbo:morph,
304
+ * turbo:before-morph-element, turbo:before-morph-attribute, and
305
+ * turbo:morph-element events.
306
+ *
307
+ * @param currentBody HTMLBodyElement destination of morphing changes
308
+ * @param newBody HTMLBodyElement source of morphing changes
309
+ */
310
+ export function morphBodyElements(currentBody: HTMLBodyElement, newBody: HTMLBodyElement): void;
311
+
312
+ /**
313
+ * Morph the child elements of the currentFrame based on the child elements of
314
+ * the newFrame. Morphing turbo-frame elements may dispatch turbo:before-frame-morph,
315
+ * turbo:before-morph-element, turbo:before-morph-attribute, and
316
+ * turbo:morph-element events.
317
+ *
318
+ * @param currentFrame FrameElement destination of morphing children changes
319
+ * @param newFrame FrameElement source of morphing children changes
320
+ */
321
+ export function morphTurboFrameElements(currentFrame: FrameElement, newFrame: FrameElement): void;
322
+
323
+ /** The Turbo session navigator */
324
+ export const navigator: Navigator;
325
+
326
+ /** The Turbo page cache */
327
+ export const cache: Cache;
328
+
329
+ /** The Turbo configuration object */
330
+ export const config: TurboConfig;
331
+
332
+ /** The Turbo session */
333
+ export const session: TurboSession;
334
+
110
335
  export interface TurboGlobal {
111
336
  /**
112
337
  * 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 +340,61 @@ export interface TurboGlobal {
115
340
  * Note that this method has no effect when used with the iOS or Android adapters.
116
341
  *
117
342
  * @param delayInMilliseconds
343
+ * @deprecated Use `Turbo.config.drive.progressBarDelay = delayInMilliseconds` instead.
118
344
  */
119
345
  setProgressBarDelay(delayInMilliseconds: number): void;
120
346
 
121
347
  /**
122
348
  * 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
349
  **
124
- * The default is the browsers built in confirm.
350
+ * The default is the browser's built in confirm.
125
351
  *
126
352
  * The method should return true if the visit can proceed.
127
353
  *
128
354
  * @param confirmMethod
355
+ * @deprecated Use `Turbo.config.forms.confirm = confirmMethod` instead.
129
356
  */
130
357
  setConfirmMethod(confirmMethod: () => boolean): void;
131
358
 
359
+ /**
360
+ * Sets the form mode for Turbo Drive.
361
+ *
362
+ * @param mode Form handling mode
363
+ * @deprecated Use `Turbo.config.forms.mode = mode` instead.
364
+ */
365
+ setFormMode(mode: "on" | "off" | "optin"): void;
366
+
367
+ /**
368
+ * Registers an adapter for the main session.
369
+ *
370
+ * @param adapter Adapter to register
371
+ */
372
+ registerAdapter(adapter: unknown): void;
373
+
132
374
  visit(location: string, options?: { action?: Action; frame?: string }): void;
133
375
 
376
+ /**
377
+ * Starts the main Turbo session.
378
+ * This initializes observers to monitor link interactions.
379
+ */
380
+ start(): void;
381
+
382
+ connectStreamSource(source: StreamSource): void;
383
+ disconnectStreamSource(source: StreamSource): void;
384
+ renderStreamMessage(message: StreamMessage | string): void;
385
+
386
+ morphElements(currentElement: Element, newElement: Element | ChildNode[], options?: MorphOptions): void;
387
+ morphChildren(currentElement: Element, newElement: Element, options?: MorphOptions): void;
388
+ morphBodyElements(currentBody: HTMLBodyElement, newBody: HTMLBodyElement): void;
389
+ morphTurboFrameElements(currentFrame: FrameElement, newFrame: FrameElement): void;
390
+
134
391
  session: TurboSession;
392
+ navigator: Navigator;
393
+ cache: Cache;
394
+ config: TurboConfig;
395
+ StreamActions: {
396
+ [action: string]: (this: StreamElement) => void;
397
+ };
135
398
  }
136
399
 
137
400
  declare global {
@@ -175,6 +438,31 @@ export type TurboBeforeStreamRenderEvent = CustomEvent<{
175
438
  render: Render;
176
439
  }>;
177
440
 
441
+ export type TurboMorphEvent = CustomEvent<{
442
+ currentElement: Element;
443
+ newElement: Element;
444
+ }>;
445
+
446
+ export type TurboBeforeMorphElementEvent = CustomEvent<{
447
+ currentElement: Element;
448
+ newElement: Element;
449
+ }>;
450
+
451
+ export type TurboMorphElementEvent = CustomEvent<{
452
+ currentElement: Element;
453
+ newElement: Element;
454
+ }>;
455
+
456
+ export type TurboBeforeMorphAttributeEvent = CustomEvent<{
457
+ attributeName: string;
458
+ mutationType: "updated" | "removed";
459
+ }>;
460
+
461
+ export type TurboBeforeFrameMorphEvent = CustomEvent<{
462
+ currentElement: FrameElement;
463
+ newElement: FrameElement;
464
+ }>;
465
+
178
466
  export interface FormSubmission {
179
467
  action: string;
180
468
  body: FormData | URLSearchParams;
@@ -205,9 +493,9 @@ export type TurboFrameMissingEvent = CustomEvent<{
205
493
  }>;
206
494
 
207
495
  export type TurboBeforeFetchRequestEvent = CustomEvent<{
208
- fetchOptions: RequestInit;
496
+ fetchOptions: Omit<RequestInit, "headers"> & { headers: FetchRequestHeaders };
209
497
  url: URL;
210
- resume: (value: any) => void;
498
+ resume: (value?: unknown) => void;
211
499
  }>;
212
500
 
213
501
  export type TurboBeforeFetchResponseEvent = CustomEvent<{
@@ -222,6 +510,7 @@ export type TurboFetchRequestErrorEvent = CustomEvent<{
222
510
  export interface TurboElementTagNameMap {
223
511
  "turbo-frame": FrameElement;
224
512
  "turbo-stream": StreamElement;
513
+ "turbo-stream-source": StreamSourceElement;
225
514
  }
226
515
 
227
516
  export interface TurboElementEventMap {
@@ -247,6 +536,11 @@ export interface TurboGlobalEventHandlersEventMap extends TurboElementEventMap {
247
536
  "turbo:render": TurboRenderEvent;
248
537
  "turbo:reload": TurboReloadEvent;
249
538
  "turbo:visit": TurboVisitEvent;
539
+ "turbo:morph": TurboMorphEvent;
540
+ "turbo:before-morph-element": TurboBeforeMorphElementEvent;
541
+ "turbo:morph-element": TurboMorphElementEvent;
542
+ "turbo:before-morph-attribute": TurboBeforeMorphAttributeEvent;
543
+ "turbo:before-frame-morph": TurboBeforeFrameMorphEvent;
250
544
  }
251
545
 
252
546
  declare global {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/hotwired__turbo",
3
- "version": "8.0.5",
3
+ "version": "8.0.7",
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": "7cefcb735be30522b374d78df45635bb5079e0cd2123523fc36ed0c740b534d2",
34
+ "typesPublisherContentHash": "096a2fd4ffe6909711dc1bf4550cdbc775cdf71010cb71feb54a37794e1478c9",
35
35
  "typeScriptVersion": "5.2"
36
36
  }