@hybridly/core 0.0.1-dev.3 → 0.1.0-alpha.0
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/index.cjs +387 -165
- package/dist/index.d.ts +240 -138
- package/dist/index.mjs +386 -165
- package/package.json +5 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,138 +1,100 @@
|
|
|
1
1
|
import { RequestData } from '@hybridly/utils';
|
|
2
|
-
import { AxiosResponse, AxiosProgressEvent } from 'axios';
|
|
2
|
+
import { AxiosResponse, AxiosProgressEvent, Axios } from 'axios';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface RequestHooks {
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
before: (options:
|
|
8
|
+
* Called before a navigation request is going to happen.
|
|
9
|
+
*/
|
|
10
|
+
before: (options: HybridRequestOptions, context: InternalRouterContext) => MaybePromise<any | boolean>;
|
|
11
11
|
/**
|
|
12
|
-
* Called before the request of a
|
|
12
|
+
* Called before the request of a navigation is going to happen.
|
|
13
13
|
*/
|
|
14
14
|
start: (context: InternalRouterContext) => MaybePromise<any>;
|
|
15
15
|
/**
|
|
16
16
|
* Called when progress on the request is being made.
|
|
17
17
|
*/
|
|
18
|
-
progress: (progress: Progress) => MaybePromise<any>;
|
|
18
|
+
progress: (progress: Progress, context: InternalRouterContext) => MaybePromise<any>;
|
|
19
19
|
/**
|
|
20
|
-
* Called when data is received after a request for a
|
|
20
|
+
* Called when data is received after a request for a navigation.
|
|
21
21
|
*/
|
|
22
|
-
data: (response: AxiosResponse) => MaybePromise<any>;
|
|
22
|
+
data: (response: AxiosResponse, context: InternalRouterContext) => MaybePromise<any>;
|
|
23
23
|
/**
|
|
24
24
|
* Called when a request is successful and there is no error.
|
|
25
25
|
*/
|
|
26
|
-
success: (payload:
|
|
26
|
+
success: (payload: HybridPayload, context: InternalRouterContext) => MaybePromise<any>;
|
|
27
27
|
/**
|
|
28
28
|
* Called when a request is successful but there were errors.
|
|
29
29
|
*/
|
|
30
|
-
error: (errors: Errors) => MaybePromise<any>;
|
|
30
|
+
error: (errors: Errors, context: InternalRouterContext) => MaybePromise<any>;
|
|
31
31
|
/**
|
|
32
32
|
* Called when a request has been aborted.
|
|
33
33
|
*/
|
|
34
34
|
abort: (context: InternalRouterContext) => MaybePromise<any>;
|
|
35
35
|
/**
|
|
36
|
-
* Called when a response to a request is not a valid
|
|
36
|
+
* Called when a response to a request is not a valid hybrid response.
|
|
37
37
|
*/
|
|
38
|
-
invalid: (response: AxiosResponse) => MaybePromise<
|
|
38
|
+
invalid: (response: AxiosResponse, context: InternalRouterContext) => MaybePromise<any>;
|
|
39
39
|
/**
|
|
40
40
|
* Called when an unknowne exception was triggered.
|
|
41
41
|
*/
|
|
42
|
-
exception: (error: Error) => MaybePromise<
|
|
42
|
+
exception: (error: Error, context: InternalRouterContext) => MaybePromise<any>;
|
|
43
43
|
/**
|
|
44
44
|
* Called whenever the request failed, for any reason, in addition to other hooks.
|
|
45
45
|
*/
|
|
46
|
-
fail: (context: InternalRouterContext) => MaybePromise<
|
|
46
|
+
fail: (context: InternalRouterContext) => MaybePromise<any>;
|
|
47
47
|
/**
|
|
48
48
|
* Called after a request has been made, even if it didn't succeed.
|
|
49
49
|
*/
|
|
50
|
-
after: (context: InternalRouterContext) => MaybePromise<
|
|
50
|
+
after: (context: InternalRouterContext) => MaybePromise<any>;
|
|
51
|
+
}
|
|
52
|
+
interface Hooks extends RequestHooks {
|
|
53
|
+
/**
|
|
54
|
+
* Called when Hybridly's context is initialized.
|
|
55
|
+
*/
|
|
56
|
+
initialized: (context: InternalRouterContext) => MaybePromise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Called after Hybridly's initial page load.
|
|
59
|
+
*/
|
|
60
|
+
ready: (context: InternalRouterContext) => MaybePromise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Called when a back-forward navigation occurs.
|
|
63
|
+
*/
|
|
64
|
+
backForward: (state: any, context: InternalRouterContext) => MaybePromise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* Called when a component navigation is being made.
|
|
67
|
+
*/
|
|
68
|
+
navigating: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
51
69
|
/**
|
|
52
|
-
* Called when a
|
|
70
|
+
* Called when a component has been navigated to.
|
|
53
71
|
*/
|
|
54
|
-
|
|
72
|
+
navigated: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
73
|
+
}
|
|
74
|
+
interface HookOptions {
|
|
75
|
+
/** Executes the hook only once. */
|
|
76
|
+
once?: boolean;
|
|
55
77
|
}
|
|
56
78
|
/**
|
|
57
79
|
* Registers a global hook.
|
|
58
80
|
*/
|
|
59
|
-
declare function registerHook<T extends keyof Hooks>(hook: T, fn: Hooks[T]): () => void;
|
|
60
|
-
/**
|
|
61
|
-
* Registers a global hook that will run only once.
|
|
62
|
-
*/
|
|
63
|
-
declare function registerHookOnce<T extends keyof Hooks>(hook: T, fn: Hooks[T]): void;
|
|
81
|
+
declare function registerHook<T extends keyof Hooks>(hook: T, fn: Hooks[T], options?: HookOptions): () => void;
|
|
64
82
|
|
|
65
|
-
interface Plugin {
|
|
83
|
+
interface Plugin extends Partial<Hooks> {
|
|
84
|
+
/** Identifier of the plugin. */
|
|
66
85
|
name: string;
|
|
67
|
-
initialized: (context: InternalRouterContext) => MaybePromise<void>;
|
|
68
|
-
hooks: Partial<Hooks>;
|
|
69
86
|
}
|
|
70
87
|
declare function definePlugin(plugin: Plugin): Plugin;
|
|
71
88
|
|
|
72
|
-
|
|
73
|
-
interface RouterContextOptions {
|
|
74
|
-
/** The initial payload served by the browser. */
|
|
75
|
-
payload: VisitPayload;
|
|
76
|
-
/** Adapter-specific functions. */
|
|
77
|
-
adapter: Adapter;
|
|
78
|
-
/** History state serializer. */
|
|
79
|
-
serializer?: Serializer;
|
|
80
|
-
/** List of plugins. */
|
|
81
|
-
plugins?: Plugin[];
|
|
82
|
-
}
|
|
83
|
-
/** Router context. */
|
|
84
|
-
interface InternalRouterContext {
|
|
85
|
-
/** The current, normalized URL. */
|
|
86
|
-
url: string;
|
|
87
|
-
/** The current view. */
|
|
88
|
-
view: View;
|
|
89
|
-
/** The current, optional dialog. */
|
|
90
|
-
dialog?: View;
|
|
91
|
-
/** The current local asset version. */
|
|
92
|
-
version: string;
|
|
93
|
-
/** The current adapter's functions. */
|
|
94
|
-
adapter: Adapter;
|
|
95
|
-
/** Scroll positions of the current page's DOM elements. */
|
|
96
|
-
scrollRegions: ScrollRegion[];
|
|
97
|
-
/** Arbitrary state. */
|
|
98
|
-
state: Record<string, any>;
|
|
99
|
-
/** Currently pending visit. */
|
|
100
|
-
activeVisit?: PendingVisit;
|
|
101
|
-
/** History state serializer. */
|
|
102
|
-
serializer: Serializer;
|
|
103
|
-
/** List of plugins. */
|
|
104
|
-
plugins: Plugin[];
|
|
105
|
-
/** Global hooks. */
|
|
106
|
-
hooks: Partial<Record<keyof Hooks, Array<Function>>>;
|
|
107
|
-
}
|
|
108
|
-
/** Router context. */
|
|
109
|
-
declare type RouterContext = Readonly<InternalRouterContext>;
|
|
110
|
-
/** Adapter-specific functions. */
|
|
111
|
-
interface Adapter {
|
|
112
|
-
/** Resolves a component from the given name. */
|
|
113
|
-
resolveComponent: ResolveComponent;
|
|
114
|
-
/** Swaps to the given view. */
|
|
115
|
-
swapView: SwapView;
|
|
116
|
-
/** Swaps to the given dialog. */
|
|
117
|
-
swapDialog: SwapDialog;
|
|
118
|
-
/** Called when the context is updated. */
|
|
119
|
-
update?: (context: InternalRouterContext) => void;
|
|
120
|
-
}
|
|
121
|
-
interface ScrollRegion {
|
|
122
|
-
top: number;
|
|
123
|
-
left: number;
|
|
124
|
-
}
|
|
125
|
-
/** Provides methods to serialize the state into the history state. */
|
|
126
|
-
interface Serializer {
|
|
127
|
-
serialize: <T>(view: T) => any;
|
|
128
|
-
unserialize: <T>(state: any) => T;
|
|
89
|
+
interface CloseDialogOptions extends HybridRequestOptions {
|
|
129
90
|
}
|
|
130
91
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
92
|
+
type UrlResolvable = string | URL | Location;
|
|
93
|
+
type UrlTransformable = BaseUrlTransformable | ((string: URL) => BaseUrlTransformable);
|
|
94
|
+
type BaseUrlTransformable = Partial<Omit<URL, 'searchParams' | 'toJSON' | 'toString'>> & {
|
|
95
|
+
query?: any;
|
|
96
|
+
trailingSlash?: boolean;
|
|
97
|
+
};
|
|
136
98
|
/**
|
|
137
99
|
* Converts an input to an URL, optionally changing its properties after initialization.
|
|
138
100
|
*/
|
|
@@ -142,12 +104,12 @@ declare function makeUrl(href: UrlResolvable, transformations?: UrlTransformable
|
|
|
142
104
|
*/
|
|
143
105
|
declare function sameUrls(...hrefs: UrlResolvable[]): boolean;
|
|
144
106
|
|
|
145
|
-
|
|
146
|
-
interface
|
|
107
|
+
type ConditionalNavigationOption = boolean | ((payload: HybridPayload) => boolean);
|
|
108
|
+
interface ComponentNavigationOptions {
|
|
147
109
|
/** Name of the component to use. */
|
|
148
110
|
component?: string;
|
|
149
111
|
/** Properties to apply to the component. */
|
|
150
|
-
properties
|
|
112
|
+
properties?: Properties;
|
|
151
113
|
/**
|
|
152
114
|
* Whether to replace the current history state instead of adding
|
|
153
115
|
* one. This affects the browser's "back" and "forward" features.
|
|
@@ -160,7 +122,7 @@ interface LocalVisitOptions {
|
|
|
160
122
|
}
|
|
161
123
|
interface NavigationOptions {
|
|
162
124
|
/** View to navigate to. */
|
|
163
|
-
payload?:
|
|
125
|
+
payload?: HybridPayload;
|
|
164
126
|
/**
|
|
165
127
|
* Whether to replace the current history state instead of adding
|
|
166
128
|
* one. This affects the browser's "back" and "forward" features.
|
|
@@ -188,62 +150,79 @@ interface NavigationOptions {
|
|
|
188
150
|
*/
|
|
189
151
|
updateHistoryState?: boolean;
|
|
190
152
|
/**
|
|
191
|
-
* Defines whether this navigation is a back/forward
|
|
153
|
+
* Defines whether this navigation is a back/forward navigation from the popstate event.
|
|
192
154
|
* @internal This is an advanced property meant to be used internally.
|
|
193
155
|
*/
|
|
194
156
|
isBackForward?: boolean;
|
|
195
157
|
}
|
|
196
|
-
|
|
197
|
-
interface
|
|
198
|
-
/** The URL to
|
|
158
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
159
|
+
interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
|
|
160
|
+
/** The URL to navigation. */
|
|
199
161
|
url?: UrlResolvable;
|
|
200
162
|
/** HTTP verb to use for the request. */
|
|
201
|
-
method?: Method
|
|
163
|
+
method?: Method | Lowercase<Method>;
|
|
202
164
|
/** Body of the request. */
|
|
203
165
|
data?: RequestData;
|
|
204
|
-
/** Which properties to update for this
|
|
166
|
+
/** Which properties to update for this navigation. Other properties will be ignored. */
|
|
205
167
|
only?: string | string[];
|
|
206
|
-
/** Which properties not to update for this
|
|
168
|
+
/** Which properties not to update for this navigation. Other properties will be updated. */
|
|
207
169
|
except?: string | string[];
|
|
208
170
|
/** Specific headers to add to the request. */
|
|
209
171
|
headers?: Record<string, string>;
|
|
210
172
|
/** The bag in which to put potential errors. */
|
|
211
173
|
errorBag?: string;
|
|
212
|
-
/** Hooks for this
|
|
213
|
-
hooks?: Partial<
|
|
174
|
+
/** Hooks for this navigation. */
|
|
175
|
+
hooks?: Partial<RequestHooks>;
|
|
214
176
|
/** If `true`, force the usage of a `FormData` object. */
|
|
215
177
|
useFormData?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* If `false`, disable automatic form spoofing.
|
|
180
|
+
* @see https://laravel.com/docs/9.x/routing#form-method-spoofing
|
|
181
|
+
*/
|
|
182
|
+
spoof?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* If `false`, does not trigger the progress bar for this request.
|
|
185
|
+
*/
|
|
186
|
+
progress?: boolean;
|
|
216
187
|
}
|
|
217
|
-
interface
|
|
188
|
+
interface NavigationResponse {
|
|
218
189
|
response?: AxiosResponse;
|
|
219
190
|
error?: {
|
|
220
191
|
type: string;
|
|
221
192
|
actual: Error;
|
|
222
193
|
};
|
|
223
194
|
}
|
|
195
|
+
interface DialogRouter {
|
|
196
|
+
/** Closes the current dialog. */
|
|
197
|
+
close: (options?: CloseDialogOptions) => void;
|
|
198
|
+
}
|
|
224
199
|
interface Router {
|
|
225
|
-
/** Aborts the currently pending
|
|
200
|
+
/** Aborts the currently pending navigate, if any. */
|
|
226
201
|
abort: () => Promise<void>;
|
|
227
|
-
/** Checks if there is an active
|
|
202
|
+
/** Checks if there is an active navigate. */
|
|
228
203
|
active: () => boolean;
|
|
229
|
-
/** Makes a
|
|
230
|
-
|
|
204
|
+
/** Makes a navigate with the given options. */
|
|
205
|
+
navigate: (options: HybridRequestOptions) => Promise<NavigationResponse>;
|
|
231
206
|
/** Reloads the current page. */
|
|
232
|
-
reload: (options?:
|
|
207
|
+
reload: (options?: HybridRequestOptions) => Promise<NavigationResponse>;
|
|
208
|
+
/** Makes a request to given named route. The HTTP verb is determined automatically but can be overriden. */
|
|
209
|
+
to: <T extends RouteName>(name: T, parameters?: RouteParameters<T>, options?: Omit<HybridRequestOptions, 'url'>) => Promise<NavigationResponse>;
|
|
233
210
|
/** Makes a GET request to the given URL. */
|
|
234
|
-
get: (url: UrlResolvable, options?: Omit<
|
|
211
|
+
get: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
235
212
|
/** Makes a POST request to the given URL. */
|
|
236
|
-
post: (url: UrlResolvable, options?: Omit<
|
|
213
|
+
post: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
237
214
|
/** Makes a PUT request to the given URL. */
|
|
238
|
-
put: (url: UrlResolvable, options?: Omit<
|
|
215
|
+
put: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
239
216
|
/** Makes a PATCH request to the given URL. */
|
|
240
|
-
patch: (url: UrlResolvable, options?: Omit<
|
|
217
|
+
patch: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
241
218
|
/** Makes a DELETE request to the given URL. */
|
|
242
|
-
delete: (url: UrlResolvable, options?: Omit<
|
|
243
|
-
/** Navigates to the given external URL.
|
|
244
|
-
external: (url: UrlResolvable, data?:
|
|
219
|
+
delete: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
220
|
+
/** Navigates to the given external URL. Convenience method using `document.location.href`. */
|
|
221
|
+
external: (url: UrlResolvable, data?: HybridRequestOptions['data']) => void;
|
|
245
222
|
/** Navigates to the given URL without a server round-trip. */
|
|
246
|
-
local: (url: UrlResolvable, options:
|
|
223
|
+
local: (url: UrlResolvable, options: ComponentNavigationOptions) => Promise<void>;
|
|
224
|
+
/** Access the dialog router. */
|
|
225
|
+
dialog: DialogRouter;
|
|
247
226
|
/** Access the history state. */
|
|
248
227
|
history: {
|
|
249
228
|
/** Remembers a value for the given route. */
|
|
@@ -252,45 +231,57 @@ interface Router {
|
|
|
252
231
|
get: <T = any>(key: string) => T | undefined;
|
|
253
232
|
};
|
|
254
233
|
}
|
|
255
|
-
/**
|
|
256
|
-
interface
|
|
234
|
+
/** A navigation being made. */
|
|
235
|
+
interface PendingNavigation {
|
|
257
236
|
/** The URL to which the request is being made. */
|
|
258
237
|
url: URL;
|
|
259
238
|
/** Abort controller associated to this request. */
|
|
260
239
|
controller: AbortController;
|
|
261
|
-
/** Options for the associated
|
|
262
|
-
options:
|
|
263
|
-
/**
|
|
240
|
+
/** Options for the associated hybrid request. */
|
|
241
|
+
options: HybridRequestOptions;
|
|
242
|
+
/** Navigation identifier. */
|
|
264
243
|
id: string;
|
|
244
|
+
/** Current status. */
|
|
245
|
+
status: 'pending' | 'success' | 'error';
|
|
265
246
|
}
|
|
266
247
|
/** A page or dialog component. */
|
|
267
248
|
interface View {
|
|
268
249
|
/** Name of the component to use. */
|
|
269
|
-
|
|
250
|
+
component: string;
|
|
270
251
|
/** Properties to apply to the component. */
|
|
271
252
|
properties: Properties;
|
|
272
253
|
}
|
|
273
|
-
|
|
254
|
+
interface Dialog extends View {
|
|
255
|
+
/** URL that is the base background page when navigating to the dialog directly. */
|
|
256
|
+
baseUrl: string;
|
|
257
|
+
/** URL to which the dialog should redirect when closed. */
|
|
258
|
+
redirectUrl: string;
|
|
259
|
+
/** Unique identifier for this modal's lifecycle. */
|
|
260
|
+
key: string;
|
|
261
|
+
}
|
|
262
|
+
type Property = null | string | number | boolean | Property[] | {
|
|
274
263
|
[name: string]: Property;
|
|
275
264
|
};
|
|
276
|
-
|
|
265
|
+
type Properties = Record<string | number, Property>;
|
|
277
266
|
interface SwapOptions<T> {
|
|
278
267
|
/** The new component. */
|
|
279
268
|
component: T;
|
|
269
|
+
/** The new properties. */
|
|
270
|
+
properties?: any;
|
|
280
271
|
/** Whether to preserve the state of the component. */
|
|
281
272
|
preserveState?: boolean;
|
|
273
|
+
/** Current dialog. */
|
|
274
|
+
dialog?: Dialog;
|
|
282
275
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
/** The payload of a visit request from the server. */
|
|
289
|
-
interface VisitPayload {
|
|
276
|
+
type ViewComponent = any;
|
|
277
|
+
type ResolveComponent = (name: string) => Promise<ViewComponent>;
|
|
278
|
+
type SwapView = (options: SwapOptions<ViewComponent>) => Promise<void>;
|
|
279
|
+
/** The payload of a navigation request from the server. */
|
|
280
|
+
interface HybridPayload {
|
|
290
281
|
/** The view to use in this request. */
|
|
291
282
|
view: View;
|
|
292
283
|
/** An optional dialog. */
|
|
293
|
-
dialog?:
|
|
284
|
+
dialog?: Dialog;
|
|
294
285
|
/** The current page URL. */
|
|
295
286
|
url: string;
|
|
296
287
|
/** The current asset version. */
|
|
@@ -306,11 +297,107 @@ interface Errors {
|
|
|
306
297
|
[key: string]: string;
|
|
307
298
|
}
|
|
308
299
|
|
|
300
|
+
interface RoutingConfiguration {
|
|
301
|
+
url: string;
|
|
302
|
+
port?: number;
|
|
303
|
+
defaults: Record<string, any>;
|
|
304
|
+
routes: Record<string, RouteDefinition>;
|
|
305
|
+
}
|
|
306
|
+
interface RouteDefinition {
|
|
307
|
+
uri: string;
|
|
308
|
+
method: Method[];
|
|
309
|
+
bindings: Record<string, string>;
|
|
310
|
+
domain?: string;
|
|
311
|
+
wheres?: Record<string, string>;
|
|
312
|
+
name: string;
|
|
313
|
+
}
|
|
314
|
+
interface GlobalRouteCollection extends RoutingConfiguration {
|
|
315
|
+
}
|
|
316
|
+
type RouteName = keyof GlobalRouteCollection['routes'];
|
|
317
|
+
type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
|
|
318
|
+
|
|
319
|
+
/** Options for creating a router context. */
|
|
320
|
+
interface RouterContextOptions {
|
|
321
|
+
/** The initial payload served by the browser. */
|
|
322
|
+
payload: HybridPayload;
|
|
323
|
+
/** Adapter-specific functions. */
|
|
324
|
+
adapter: Adapter;
|
|
325
|
+
/** History state serializer. */
|
|
326
|
+
serializer?: Serializer;
|
|
327
|
+
/** List of plugins. */
|
|
328
|
+
plugins?: Plugin[];
|
|
329
|
+
/** The Axios instance. */
|
|
330
|
+
axios?: Axios;
|
|
331
|
+
/** Initial routing configuration. */
|
|
332
|
+
routing?: RoutingConfiguration;
|
|
333
|
+
/** Whether to display response error modals. */
|
|
334
|
+
responseErrorModals?: boolean;
|
|
335
|
+
}
|
|
336
|
+
/** Router context. */
|
|
337
|
+
interface InternalRouterContext {
|
|
338
|
+
/** The current, normalized URL. */
|
|
339
|
+
url: string;
|
|
340
|
+
/** The current view. */
|
|
341
|
+
view: View;
|
|
342
|
+
/** The current, optional dialog. */
|
|
343
|
+
dialog?: Dialog;
|
|
344
|
+
/** The current local asset version. */
|
|
345
|
+
version: string;
|
|
346
|
+
/** The current adapter's functions. */
|
|
347
|
+
adapter: ResolvedAdapter;
|
|
348
|
+
/** Scroll positions of the current page's DOM elements. */
|
|
349
|
+
scrollRegions: ScrollRegion[];
|
|
350
|
+
/** Arbitrary state. */
|
|
351
|
+
state: Record<string, any>;
|
|
352
|
+
/** Currently pending navigation. */
|
|
353
|
+
pendingNavigation?: PendingNavigation;
|
|
354
|
+
/** History state serializer. */
|
|
355
|
+
serializer: Serializer;
|
|
356
|
+
/** List of plugins. */
|
|
357
|
+
plugins: Plugin[];
|
|
358
|
+
/** Global hooks. */
|
|
359
|
+
hooks: Partial<Record<keyof Hooks, Array<Function>>>;
|
|
360
|
+
/** The Axios instance. */
|
|
361
|
+
axios: Axios;
|
|
362
|
+
/** Routing configuration. */
|
|
363
|
+
routing?: RoutingConfiguration;
|
|
364
|
+
/** Whether to display response error modals. */
|
|
365
|
+
responseErrorModals?: boolean;
|
|
366
|
+
}
|
|
367
|
+
/** Router context. */
|
|
368
|
+
type RouterContext = Readonly<InternalRouterContext>;
|
|
369
|
+
/** Adapter-specific functions. */
|
|
370
|
+
interface Adapter {
|
|
371
|
+
/** Resolves a component from the given name. */
|
|
372
|
+
resolveComponent: ResolveComponent;
|
|
373
|
+
/** Called when the view is swapped. */
|
|
374
|
+
onViewSwap: SwapView;
|
|
375
|
+
/** Called when the context is updated. */
|
|
376
|
+
onContextUpdate?: (context: InternalRouterContext) => void;
|
|
377
|
+
/** Called when a dialog is closed. */
|
|
378
|
+
onDialogClose?: (context: InternalRouterContext) => void;
|
|
379
|
+
}
|
|
380
|
+
interface ResolvedAdapter extends Adapter {
|
|
381
|
+
updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
|
|
382
|
+
}
|
|
383
|
+
interface ScrollRegion {
|
|
384
|
+
top: number;
|
|
385
|
+
left: number;
|
|
386
|
+
}
|
|
387
|
+
/** Provides methods to serialize the state into the history state. */
|
|
388
|
+
interface Serializer {
|
|
389
|
+
serialize: <T>(view: T) => any;
|
|
390
|
+
unserialize: <T>(state: any) => T;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Gets the current context. */
|
|
394
|
+
declare function getRouterContext(): RouterContext;
|
|
395
|
+
|
|
309
396
|
/**
|
|
310
397
|
* The hybridly router.
|
|
311
398
|
* This is the core function that you can use to navigate in
|
|
312
399
|
* your application. Make sure the routes you call return a
|
|
313
|
-
*
|
|
400
|
+
* hybrid response, otherwise you need to call `external`.
|
|
314
401
|
*
|
|
315
402
|
* @example
|
|
316
403
|
* router.get('/posts/edit', { post })
|
|
@@ -328,11 +415,22 @@ interface Authorizable<Authorizations extends Record<string, boolean>> {
|
|
|
328
415
|
*/
|
|
329
416
|
declare function can<Authorizations extends Record<string, boolean>, Data extends Authorizable<Authorizations>, Action extends keyof Data['authorization']>(resource: Data, action: Action): Authorizations[Action];
|
|
330
417
|
|
|
418
|
+
/**
|
|
419
|
+
* Generates a route from the given route name.
|
|
420
|
+
*/
|
|
421
|
+
declare function route<T extends RouteName>(name: T, parameters?: RouteParameters<T>, absolute?: boolean): string;
|
|
422
|
+
/**
|
|
423
|
+
* Determines if the current route correspond to the given route name and parameters.
|
|
424
|
+
*/
|
|
425
|
+
declare function current<T extends RouteName>(name: T, parameters?: RouteParameters<T>, mode?: 'loose' | 'strict'): boolean;
|
|
426
|
+
|
|
331
427
|
declare const STORAGE_EXTERNAL_KEY = "hybridly:external";
|
|
332
|
-
declare const HYBRIDLY_HEADER = "x-
|
|
333
|
-
declare const
|
|
428
|
+
declare const HYBRIDLY_HEADER = "x-hybrid";
|
|
429
|
+
declare const EXTERNAL_NAVIGATION_HEADER: string;
|
|
334
430
|
declare const PARTIAL_COMPONENT_HEADER: string;
|
|
335
431
|
declare const ONLY_DATA_HEADER: string;
|
|
432
|
+
declare const DIALOG_KEY_HEADER: string;
|
|
433
|
+
declare const DIALOG_REDIRECT_HEADER: string;
|
|
336
434
|
declare const EXCEPT_DATA_HEADER: string;
|
|
337
435
|
declare const CONTEXT_HEADER: string;
|
|
338
436
|
declare const VERSION_HEADER: string;
|
|
@@ -341,9 +439,11 @@ declare const SCROLL_REGION_ATTRIBUTE = "scroll-region";
|
|
|
341
439
|
|
|
342
440
|
declare const constants_STORAGE_EXTERNAL_KEY: typeof STORAGE_EXTERNAL_KEY;
|
|
343
441
|
declare const constants_HYBRIDLY_HEADER: typeof HYBRIDLY_HEADER;
|
|
344
|
-
declare const
|
|
442
|
+
declare const constants_EXTERNAL_NAVIGATION_HEADER: typeof EXTERNAL_NAVIGATION_HEADER;
|
|
345
443
|
declare const constants_PARTIAL_COMPONENT_HEADER: typeof PARTIAL_COMPONENT_HEADER;
|
|
346
444
|
declare const constants_ONLY_DATA_HEADER: typeof ONLY_DATA_HEADER;
|
|
445
|
+
declare const constants_DIALOG_KEY_HEADER: typeof DIALOG_KEY_HEADER;
|
|
446
|
+
declare const constants_DIALOG_REDIRECT_HEADER: typeof DIALOG_REDIRECT_HEADER;
|
|
347
447
|
declare const constants_EXCEPT_DATA_HEADER: typeof EXCEPT_DATA_HEADER;
|
|
348
448
|
declare const constants_CONTEXT_HEADER: typeof CONTEXT_HEADER;
|
|
349
449
|
declare const constants_VERSION_HEADER: typeof VERSION_HEADER;
|
|
@@ -353,9 +453,11 @@ declare namespace constants {
|
|
|
353
453
|
export {
|
|
354
454
|
constants_STORAGE_EXTERNAL_KEY as STORAGE_EXTERNAL_KEY,
|
|
355
455
|
constants_HYBRIDLY_HEADER as HYBRIDLY_HEADER,
|
|
356
|
-
|
|
456
|
+
constants_EXTERNAL_NAVIGATION_HEADER as EXTERNAL_NAVIGATION_HEADER,
|
|
357
457
|
constants_PARTIAL_COMPONENT_HEADER as PARTIAL_COMPONENT_HEADER,
|
|
358
458
|
constants_ONLY_DATA_HEADER as ONLY_DATA_HEADER,
|
|
459
|
+
constants_DIALOG_KEY_HEADER as DIALOG_KEY_HEADER,
|
|
460
|
+
constants_DIALOG_REDIRECT_HEADER as DIALOG_REDIRECT_HEADER,
|
|
359
461
|
constants_EXCEPT_DATA_HEADER as EXCEPT_DATA_HEADER,
|
|
360
462
|
constants_CONTEXT_HEADER as CONTEXT_HEADER,
|
|
361
463
|
constants_VERSION_HEADER as VERSION_HEADER,
|
|
@@ -364,4 +466,4 @@ declare namespace constants {
|
|
|
364
466
|
};
|
|
365
467
|
}
|
|
366
468
|
|
|
367
|
-
export { Authorizable, MaybePromise, Method, Plugin, ResolveComponent,
|
|
469
|
+
export { Authorizable, GlobalRouteCollection, HybridPayload, HybridRequestOptions, MaybePromise, Method, NavigationResponse, Plugin, Progress, ResolveComponent, RouteDefinition, RouteName, RouteParameters, Router, RouterContext, RouterContextOptions, RoutingConfiguration, UrlResolvable, can, constants, createRouter, current, definePlugin, getRouterContext, makeUrl, registerHook, route, router, sameUrls };
|