swup 4.2.0 → 4.3.1
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.
- package/dist/Swup.cjs +1 -1
- package/dist/Swup.cjs.map +1 -1
- package/dist/Swup.modern.js +1 -1
- package/dist/Swup.modern.js.map +1 -1
- package/dist/Swup.module.js +1 -1
- package/dist/Swup.module.js.map +1 -1
- package/dist/Swup.umd.js +1 -1
- package/dist/Swup.umd.js.map +1 -1
- package/dist/types/Swup.d.ts +119 -119
- package/dist/types/__test__/index.test.d.ts +1 -1
- package/dist/types/config/version.d.ts +5 -5
- package/dist/types/helpers/Location.d.ts +24 -24
- package/dist/types/helpers/__test__/matchPath.test.d.ts +1 -1
- package/dist/types/helpers/classify.d.ts +2 -2
- package/dist/types/helpers/createHistoryRecord.d.ts +9 -2
- package/dist/types/helpers/delegateEvent.d.ts +7 -7
- package/dist/types/helpers/getCurrentUrl.d.ts +4 -4
- package/dist/types/helpers/matchPath.d.ts +4 -4
- package/dist/types/helpers/updateHistoryRecord.d.ts +2 -2
- package/dist/types/helpers.d.ts +7 -7
- package/dist/types/index.d.ts +14 -14
- package/dist/types/modules/Cache.d.ts +34 -34
- package/dist/types/modules/Classes.d.ts +13 -13
- package/dist/types/modules/Hooks.d.ts +268 -250
- package/dist/types/modules/Visit.d.ts +80 -77
- package/dist/types/modules/__test__/cache.test.d.ts +1 -1
- package/dist/types/modules/__test__/{delegateEvent.d.ts → delegateEvent.test.d.ts} +1 -1
- package/dist/types/modules/__test__/hooks.test.d.ts +1 -1
- package/dist/types/modules/__test__/plugins.test.d.ts +1 -1
- package/dist/types/modules/__test__/replaceContent.test.d.ts +1 -1
- package/dist/types/modules/animatePageIn.d.ts +6 -6
- package/dist/types/modules/animatePageOut.d.ts +6 -6
- package/dist/types/modules/awaitAnimations.d.ts +19 -19
- package/dist/types/modules/fetchPage.d.ts +27 -29
- package/dist/types/modules/getAnchorElement.d.ts +9 -9
- package/dist/types/modules/navigate.d.ts +41 -35
- package/dist/types/modules/plugins.d.ts +26 -26
- package/dist/types/modules/renderPage.d.ts +7 -7
- package/dist/types/modules/replaceContent.d.ts +13 -13
- package/dist/types/modules/resolveUrl.d.ts +14 -14
- package/dist/types/modules/scrollToContent.d.ts +6 -6
- package/dist/types/utils/index.d.ts +20 -20
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -3
- package/src/Swup.ts +26 -17
- package/src/config/version.ts +1 -2
- package/src/helpers/createHistoryRecord.ts +9 -1
- package/src/helpers/matchPath.ts +1 -1
- package/src/helpers/updateHistoryRecord.ts +4 -2
- package/src/modules/Cache.ts +2 -2
- package/src/modules/Classes.ts +1 -1
- package/src/modules/Hooks.ts +91 -39
- package/src/modules/Visit.ts +19 -21
- package/src/modules/__test__/cache.test.ts +3 -3
- package/src/modules/__test__/hooks.test.ts +12 -13
- package/src/modules/animatePageIn.ts +1 -1
- package/src/modules/animatePageOut.ts +2 -2
- package/src/modules/awaitAnimations.ts +1 -1
- package/src/modules/fetchPage.ts +7 -5
- package/src/modules/navigate.ts +23 -4
- package/src/modules/plugins.ts +3 -3
- package/src/modules/renderPage.ts +1 -5
- package/src/modules/replaceContent.ts +13 -0
- package/src/modules/scrollToContent.ts +1 -1
- package/src/utils/index.ts +5 -4
- /package/src/modules/__test__/{delegateEvent.ts → delegateEvent.test.ts} +0 -0
|
@@ -1,250 +1,268 @@
|
|
|
1
|
-
import { DelegateEvent } from 'delegate-it';
|
|
2
|
-
import Swup from '../Swup.js';
|
|
3
|
-
import { Visit } from './Visit.js';
|
|
4
|
-
import { FetchOptions, PageData } from './fetchPage.js';
|
|
5
|
-
export interface HookDefinitions {
|
|
6
|
-
'animation:out:start': undefined;
|
|
7
|
-
'animation:out:await': {
|
|
8
|
-
skip: boolean;
|
|
9
|
-
};
|
|
10
|
-
'animation:out:end': undefined;
|
|
11
|
-
'animation:in:start': undefined;
|
|
12
|
-
'animation:in:await': {
|
|
13
|
-
skip: boolean;
|
|
14
|
-
};
|
|
15
|
-
'animation:in:end': undefined;
|
|
16
|
-
'animation:skip': undefined;
|
|
17
|
-
'cache:clear': undefined;
|
|
18
|
-
'cache:set': {
|
|
19
|
-
page: PageData;
|
|
20
|
-
};
|
|
21
|
-
'content:replace': {
|
|
22
|
-
page: PageData;
|
|
23
|
-
};
|
|
24
|
-
'content:scroll': undefined;
|
|
25
|
-
'enable': undefined;
|
|
26
|
-
'disable': undefined;
|
|
27
|
-
'fetch:request': {
|
|
28
|
-
url: string;
|
|
29
|
-
options: FetchOptions;
|
|
30
|
-
};
|
|
31
|
-
'fetch:error': {
|
|
32
|
-
url: string;
|
|
33
|
-
status: number;
|
|
34
|
-
response: Response;
|
|
35
|
-
};
|
|
36
|
-
'history:popstate': {
|
|
37
|
-
event: PopStateEvent;
|
|
38
|
-
};
|
|
39
|
-
'link:click': {
|
|
40
|
-
el: HTMLAnchorElement;
|
|
41
|
-
event: DelegateEvent<MouseEvent>;
|
|
42
|
-
};
|
|
43
|
-
'link:self': undefined;
|
|
44
|
-
'link:anchor': {
|
|
45
|
-
hash: string;
|
|
46
|
-
};
|
|
47
|
-
'link:newtab': {
|
|
48
|
-
href: string;
|
|
49
|
-
};
|
|
50
|
-
'page:load': {
|
|
51
|
-
page?: PageData;
|
|
52
|
-
cache?: boolean;
|
|
53
|
-
options: FetchOptions;
|
|
54
|
-
};
|
|
55
|
-
'page:view': {
|
|
56
|
-
url: string;
|
|
57
|
-
title: string;
|
|
58
|
-
};
|
|
59
|
-
'scroll:top': {
|
|
60
|
-
options: ScrollIntoViewOptions;
|
|
61
|
-
};
|
|
62
|
-
'scroll:anchor': {
|
|
63
|
-
hash: string;
|
|
64
|
-
options: ScrollIntoViewOptions;
|
|
65
|
-
};
|
|
66
|
-
'visit:start': undefined;
|
|
67
|
-
'visit:end': undefined;
|
|
68
|
-
}
|
|
69
|
-
export
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export type
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
export type
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* @param
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
*
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*
|
|
187
|
-
* @
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @param
|
|
197
|
-
* @
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
*
|
|
213
|
-
* @param
|
|
214
|
-
* @param
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
*
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
*
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*/
|
|
248
|
-
protected
|
|
249
|
-
|
|
250
|
-
|
|
1
|
+
import { DelegateEvent } from 'delegate-it';
|
|
2
|
+
import Swup from '../Swup.js';
|
|
3
|
+
import { Visit } from './Visit.js';
|
|
4
|
+
import { FetchOptions, PageData } from './fetchPage.js';
|
|
5
|
+
export interface HookDefinitions {
|
|
6
|
+
'animation:out:start': undefined;
|
|
7
|
+
'animation:out:await': {
|
|
8
|
+
skip: boolean;
|
|
9
|
+
};
|
|
10
|
+
'animation:out:end': undefined;
|
|
11
|
+
'animation:in:start': undefined;
|
|
12
|
+
'animation:in:await': {
|
|
13
|
+
skip: boolean;
|
|
14
|
+
};
|
|
15
|
+
'animation:in:end': undefined;
|
|
16
|
+
'animation:skip': undefined;
|
|
17
|
+
'cache:clear': undefined;
|
|
18
|
+
'cache:set': {
|
|
19
|
+
page: PageData;
|
|
20
|
+
};
|
|
21
|
+
'content:replace': {
|
|
22
|
+
page: PageData;
|
|
23
|
+
};
|
|
24
|
+
'content:scroll': undefined;
|
|
25
|
+
'enable': undefined;
|
|
26
|
+
'disable': undefined;
|
|
27
|
+
'fetch:request': {
|
|
28
|
+
url: string;
|
|
29
|
+
options: FetchOptions;
|
|
30
|
+
};
|
|
31
|
+
'fetch:error': {
|
|
32
|
+
url: string;
|
|
33
|
+
status: number;
|
|
34
|
+
response: Response;
|
|
35
|
+
};
|
|
36
|
+
'history:popstate': {
|
|
37
|
+
event: PopStateEvent;
|
|
38
|
+
};
|
|
39
|
+
'link:click': {
|
|
40
|
+
el: HTMLAnchorElement;
|
|
41
|
+
event: DelegateEvent<MouseEvent>;
|
|
42
|
+
};
|
|
43
|
+
'link:self': undefined;
|
|
44
|
+
'link:anchor': {
|
|
45
|
+
hash: string;
|
|
46
|
+
};
|
|
47
|
+
'link:newtab': {
|
|
48
|
+
href: string;
|
|
49
|
+
};
|
|
50
|
+
'page:load': {
|
|
51
|
+
page?: PageData;
|
|
52
|
+
cache?: boolean;
|
|
53
|
+
options: FetchOptions;
|
|
54
|
+
};
|
|
55
|
+
'page:view': {
|
|
56
|
+
url: string;
|
|
57
|
+
title: string;
|
|
58
|
+
};
|
|
59
|
+
'scroll:top': {
|
|
60
|
+
options: ScrollIntoViewOptions;
|
|
61
|
+
};
|
|
62
|
+
'scroll:anchor': {
|
|
63
|
+
hash: string;
|
|
64
|
+
options: ScrollIntoViewOptions;
|
|
65
|
+
};
|
|
66
|
+
'visit:start': undefined;
|
|
67
|
+
'visit:end': undefined;
|
|
68
|
+
}
|
|
69
|
+
export interface HookReturnValues {
|
|
70
|
+
'content:scroll': Promise<boolean>;
|
|
71
|
+
'fetch:request': Promise<Response>;
|
|
72
|
+
'page:load': Promise<PageData>;
|
|
73
|
+
'scroll:top': boolean;
|
|
74
|
+
'scroll:anchor': boolean;
|
|
75
|
+
}
|
|
76
|
+
export type HookArguments<T extends HookName> = HookDefinitions[T];
|
|
77
|
+
export type HookName = keyof HookDefinitions;
|
|
78
|
+
/** A generic hook handler. */
|
|
79
|
+
export type Handler<T extends HookName> = (
|
|
80
|
+
/** Context about the current visit. */
|
|
81
|
+
visit: Visit,
|
|
82
|
+
/** Local arguments passed into the handler. */
|
|
83
|
+
args: HookArguments<T>) => Promise<unknown> | unknown;
|
|
84
|
+
/** A default hook handler with an expected return type. */
|
|
85
|
+
export type DefaultHandler<T extends HookName> = (
|
|
86
|
+
/** Context about the current visit. */
|
|
87
|
+
visit: Visit,
|
|
88
|
+
/** Local arguments passed into the handler. */
|
|
89
|
+
args: HookArguments<T>,
|
|
90
|
+
/** Default handler to be executed. Available if replacing an internal hook handler. */
|
|
91
|
+
defaultHandler?: DefaultHandler<T>) => T extends keyof HookReturnValues ? HookReturnValues[T] : Promise<unknown> | unknown;
|
|
92
|
+
export type Handlers = {
|
|
93
|
+
[K in HookName]: Handler<K>[];
|
|
94
|
+
};
|
|
95
|
+
/** Unregister a previously registered hook handler. */
|
|
96
|
+
export type HookUnregister = () => void;
|
|
97
|
+
/** Define when and how a hook handler is executed. */
|
|
98
|
+
export type HookOptions = {
|
|
99
|
+
/** Execute the hook once, then remove the handler */
|
|
100
|
+
once?: boolean;
|
|
101
|
+
/** Execute the hook before the internal default handler */
|
|
102
|
+
before?: boolean;
|
|
103
|
+
/** Set a priority for when to execute this hook. Lower numbers execute first. Default: `0` */
|
|
104
|
+
priority?: number;
|
|
105
|
+
/** Replace the internal default handler with this hook handler */
|
|
106
|
+
replace?: boolean;
|
|
107
|
+
};
|
|
108
|
+
export type HookRegistration<T extends HookName, H extends Handler<T> | DefaultHandler<T> = Handler<T>> = {
|
|
109
|
+
id: number;
|
|
110
|
+
hook: T;
|
|
111
|
+
handler: H;
|
|
112
|
+
defaultHandler?: DefaultHandler<T>;
|
|
113
|
+
} & HookOptions;
|
|
114
|
+
type HookLedger<T extends HookName> = Map<Handler<T>, HookRegistration<T>>;
|
|
115
|
+
interface HookRegistry extends Map<HookName, HookLedger<HookName>> {
|
|
116
|
+
get<K extends HookName>(key: K): HookLedger<K> | undefined;
|
|
117
|
+
set<K extends HookName>(key: K, value: HookLedger<K>): this;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Hook registry.
|
|
121
|
+
*
|
|
122
|
+
* Create, trigger and handle hooks.
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
export declare class Hooks {
|
|
126
|
+
/** Swup instance this registry belongs to */
|
|
127
|
+
protected swup: Swup;
|
|
128
|
+
/** Map of all registered hook handlers. */
|
|
129
|
+
protected registry: HookRegistry;
|
|
130
|
+
protected readonly hooks: HookName[];
|
|
131
|
+
constructor(swup: Swup);
|
|
132
|
+
/**
|
|
133
|
+
* Create ledgers for all core hooks.
|
|
134
|
+
*/
|
|
135
|
+
protected init(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Create a new hook type.
|
|
138
|
+
*/
|
|
139
|
+
create(hook: string): void;
|
|
140
|
+
/**
|
|
141
|
+
* Check if a hook type exists.
|
|
142
|
+
*/
|
|
143
|
+
exists(hook: HookName): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Get the ledger with all registrations for a hook.
|
|
146
|
+
*/
|
|
147
|
+
protected get<T extends HookName>(hook: T): HookLedger<T> | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Remove all handlers of all hooks.
|
|
150
|
+
*/
|
|
151
|
+
clear(): void;
|
|
152
|
+
/**
|
|
153
|
+
* Register a new hook handler.
|
|
154
|
+
* @param hook Name of the hook to listen for
|
|
155
|
+
* @param handler The handler function to execute
|
|
156
|
+
* @param options Object to specify how and when the handler is executed
|
|
157
|
+
* Available options:
|
|
158
|
+
* - `once`: Only execute the handler once
|
|
159
|
+
* - `before`: Execute the handler before the default handler
|
|
160
|
+
* - `priority`: Specify the order in which the handlers are executed
|
|
161
|
+
* - `replace`: Replace the default handler with this handler
|
|
162
|
+
* @returns A function to unregister the handler
|
|
163
|
+
*/
|
|
164
|
+
on<T extends HookName, O extends HookOptions>(hook: T, handler: DefaultHandler<T>, options: O & {
|
|
165
|
+
replace: true;
|
|
166
|
+
}): HookUnregister;
|
|
167
|
+
on<T extends HookName, O extends HookOptions>(hook: T, handler: Handler<T>, options: O): HookUnregister;
|
|
168
|
+
on<T extends HookName>(hook: T, handler: Handler<T>): HookUnregister;
|
|
169
|
+
/**
|
|
170
|
+
* Register a new hook handler to run before the default handler.
|
|
171
|
+
* Shortcut for `hooks.on(hook, handler, { before: true })`.
|
|
172
|
+
* @param hook Name of the hook to listen for
|
|
173
|
+
* @param handler The handler function to execute
|
|
174
|
+
* @param options Any other event options (see `hooks.on()` for details)
|
|
175
|
+
* @returns A function to unregister the handler
|
|
176
|
+
* @see on
|
|
177
|
+
*/
|
|
178
|
+
before<T extends HookName>(hook: T, handler: Handler<T>, options: HookOptions): HookUnregister;
|
|
179
|
+
before<T extends HookName>(hook: T, handler: Handler<T>): HookUnregister;
|
|
180
|
+
/**
|
|
181
|
+
* Register a new hook handler to replace the default handler.
|
|
182
|
+
* Shortcut for `hooks.on(hook, handler, { replace: true })`.
|
|
183
|
+
* @param hook Name of the hook to listen for
|
|
184
|
+
* @param handler The handler function to execute instead of the default handler
|
|
185
|
+
* @param options Any other event options (see `hooks.on()` for details)
|
|
186
|
+
* @returns A function to unregister the handler
|
|
187
|
+
* @see on
|
|
188
|
+
*/
|
|
189
|
+
replace<T extends HookName>(hook: T, handler: DefaultHandler<T>, options: HookOptions): HookUnregister;
|
|
190
|
+
replace<T extends HookName>(hook: T, handler: DefaultHandler<T>): HookUnregister;
|
|
191
|
+
/**
|
|
192
|
+
* Register a new hook handler to run once.
|
|
193
|
+
* Shortcut for `hooks.on(hook, handler, { once: true })`.
|
|
194
|
+
* @param hook Name of the hook to listen for
|
|
195
|
+
* @param handler The handler function to execute
|
|
196
|
+
* @param options Any other event options (see `hooks.on()` for details)
|
|
197
|
+
* @see on
|
|
198
|
+
*/
|
|
199
|
+
once<T extends HookName>(hook: T, handler: Handler<T>, options: HookOptions): HookUnregister;
|
|
200
|
+
once<T extends HookName>(hook: T, handler: Handler<T>): HookUnregister;
|
|
201
|
+
/**
|
|
202
|
+
* Unregister a hook handler.
|
|
203
|
+
* @param hook Name of the hook the handler is registered for
|
|
204
|
+
* @param handler The handler function that was registered.
|
|
205
|
+
* If omitted, all handlers for the hook will be removed.
|
|
206
|
+
*/
|
|
207
|
+
off<T extends HookName>(hook: T, handler: Handler<T> | DefaultHandler<T>): void;
|
|
208
|
+
off<T extends HookName>(hook: T): void;
|
|
209
|
+
/**
|
|
210
|
+
* Trigger a hook asynchronously, executing its default handler and all registered handlers.
|
|
211
|
+
* Will execute all handlers in order and `await` any `Promise`s they return.
|
|
212
|
+
* @param hook Name of the hook to trigger
|
|
213
|
+
* @param args Arguments to pass to the handler
|
|
214
|
+
* @param defaultHandler A default implementation of this hook to execute
|
|
215
|
+
* @returns The resolved return value of the executed default handler
|
|
216
|
+
*/
|
|
217
|
+
call<T extends HookName>(hook: T, args: HookArguments<T>, defaultHandler?: DefaultHandler<T>): Promise<Awaited<ReturnType<DefaultHandler<T>>>>;
|
|
218
|
+
/**
|
|
219
|
+
* Trigger a hook synchronously, executing its default handler and all registered handlers.
|
|
220
|
+
* Will execute all handlers in order, but will **not** `await` any `Promise`s they return.
|
|
221
|
+
* @param hook Name of the hook to trigger
|
|
222
|
+
* @param args Arguments to pass to the handler
|
|
223
|
+
* @param defaultHandler A default implementation of this hook to execute
|
|
224
|
+
* @returns The (possibly unresolved) return value of the executed default handler
|
|
225
|
+
*/
|
|
226
|
+
callSync<T extends HookName>(hook: T, args: HookArguments<T>, defaultHandler?: DefaultHandler<T>): ReturnType<DefaultHandler<T>>;
|
|
227
|
+
/**
|
|
228
|
+
* Execute the handlers for a hook, in order, as `Promise`s that will be `await`ed.
|
|
229
|
+
* @param registrations The registrations (handler + options) to execute
|
|
230
|
+
* @param args Arguments to pass to the handler
|
|
231
|
+
*/
|
|
232
|
+
protected run<T extends HookName>(registrations: HookRegistration<T, DefaultHandler<T>>[], args: HookArguments<T>): Promise<Awaited<ReturnType<DefaultHandler<T>>>[]>;
|
|
233
|
+
protected run<T extends HookName>(registrations: HookRegistration<T>[], args: HookArguments<T>): Promise<unknown[]>;
|
|
234
|
+
/**
|
|
235
|
+
* Execute the handlers for a hook, in order, without `await`ing any returned `Promise`s.
|
|
236
|
+
* @param registrations The registrations (handler + options) to execute
|
|
237
|
+
* @param args Arguments to pass to the handler
|
|
238
|
+
*/
|
|
239
|
+
protected runSync<T extends HookName>(registrations: HookRegistration<T, DefaultHandler<T>>[], args: HookArguments<T>): ReturnType<DefaultHandler<T>>[];
|
|
240
|
+
protected runSync<T extends HookName>(registrations: HookRegistration<T>[], args: HookArguments<T>): unknown[];
|
|
241
|
+
/**
|
|
242
|
+
* Get all registered handlers for a hook, sorted by priority and registration order.
|
|
243
|
+
* @param hook Name of the hook
|
|
244
|
+
* @param defaultHandler The optional default handler of this hook
|
|
245
|
+
* @returns An object with the handlers sorted into `before` and `after` arrays,
|
|
246
|
+
* as well as a flag indicating if the original handler was replaced
|
|
247
|
+
*/
|
|
248
|
+
protected getHandlers<T extends HookName>(hook: T, defaultHandler?: DefaultHandler<T>): {
|
|
249
|
+
found: boolean;
|
|
250
|
+
before: HookRegistration<T, Handler<T>>[];
|
|
251
|
+
handler: HookRegistration<T, DefaultHandler<T>>[];
|
|
252
|
+
after: HookRegistration<T, Handler<T>>[];
|
|
253
|
+
replaced: boolean;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Sort two hook registrations by priority and registration order.
|
|
257
|
+
* @param a The registration object to compare
|
|
258
|
+
* @param b The other registration object to compare with
|
|
259
|
+
* @returns The sort direction
|
|
260
|
+
*/
|
|
261
|
+
protected sortRegistrations<T extends HookName>(a: HookRegistration<T>, b: HookRegistration<T>): number;
|
|
262
|
+
/**
|
|
263
|
+
* Dispatch a custom event on the `document` for a hook. Prefixed with `swup:`
|
|
264
|
+
* @param hook Name of the hook.
|
|
265
|
+
*/
|
|
266
|
+
protected dispatchDomEvent<T extends HookName>(hook: T, args?: HookArguments<T>): void;
|
|
267
|
+
}
|
|
268
|
+
export {};
|