@hybridly/core 0.10.0-beta.14 → 0.10.0-beta.15
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.d.mts +269 -140
- package/dist/index.mjs +1014 -559
- package/package.json +49 -51
package/dist/index.d.mts
CHANGED
|
@@ -1,60 +1,122 @@
|
|
|
1
|
+
import * as _hybridly_utils0 from "@hybridly/utils";
|
|
1
2
|
import { RequestData } from "@hybridly/utils";
|
|
2
|
-
import { Axios, AxiosProgressEvent, AxiosResponse } from "axios";
|
|
3
3
|
|
|
4
|
+
//#region src/http/client.d.ts
|
|
5
|
+
interface HttpUploadProgressEvent {
|
|
6
|
+
loaded: number;
|
|
7
|
+
total?: number;
|
|
8
|
+
lengthComputable: boolean;
|
|
9
|
+
percentage: number;
|
|
10
|
+
}
|
|
11
|
+
interface HttpHeaders {
|
|
12
|
+
all: Readonly<Record<string, string>>;
|
|
13
|
+
get: (name: string) => string | undefined;
|
|
14
|
+
has: (name: string) => boolean;
|
|
15
|
+
isContentType: (matcher: string | RegExp) => boolean;
|
|
16
|
+
}
|
|
17
|
+
interface HttpRequest {
|
|
18
|
+
url: string;
|
|
19
|
+
method?: string;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
params?: RequestData;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
onUploadProgress?: (event: HttpUploadProgressEvent) => void | Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
interface HttpResponse<T = unknown> {
|
|
27
|
+
data: T;
|
|
28
|
+
rawData: ArrayBuffer;
|
|
29
|
+
status: number;
|
|
30
|
+
statusText: string;
|
|
31
|
+
headers: HttpHeaders;
|
|
32
|
+
request: XMLHttpRequest;
|
|
33
|
+
config: HttpRequest;
|
|
34
|
+
toBlob: (type?: string) => Blob;
|
|
35
|
+
}
|
|
36
|
+
interface HttpClient {
|
|
37
|
+
request: <T = unknown>(config: HttpRequest) => Promise<HttpResponse<T>>;
|
|
38
|
+
}
|
|
39
|
+
type HttpErrorCode = 'ERR_ABORTED' | 'ERR_NETWORK' | 'ECONNABORTED';
|
|
40
|
+
type HttpErrorKind = 'abort' | 'network' | 'timeout';
|
|
41
|
+
declare class HttpError extends Error {
|
|
42
|
+
readonly config: HttpRequest;
|
|
43
|
+
readonly request: XMLHttpRequest;
|
|
44
|
+
readonly response?: HttpResponse;
|
|
45
|
+
readonly code: HttpErrorCode;
|
|
46
|
+
readonly kind: HttpErrorKind;
|
|
47
|
+
readonly reason?: unknown;
|
|
48
|
+
readonly isHttpError = true;
|
|
49
|
+
constructor(message: string, options: HttpErrorOptions);
|
|
50
|
+
}
|
|
51
|
+
declare class HttpAbortError extends HttpError {
|
|
52
|
+
constructor(options: HttpErrorOptions);
|
|
53
|
+
}
|
|
54
|
+
declare function isHttpError(error: unknown): error is HttpError;
|
|
55
|
+
declare function isHttpAbortError(error: unknown): error is HttpAbortError;
|
|
56
|
+
declare function createXhrHttpClient(): HttpClient;
|
|
57
|
+
interface HttpErrorOptions {
|
|
58
|
+
config: HttpRequest;
|
|
59
|
+
request: XMLHttpRequest;
|
|
60
|
+
response?: HttpResponse;
|
|
61
|
+
code?: HttpErrorCode;
|
|
62
|
+
kind?: HttpErrorKind;
|
|
63
|
+
reason?: unknown;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
4
66
|
//#region src/types.d.ts
|
|
5
67
|
type MaybePromise<T> = T | Promise<T>;
|
|
6
68
|
//#endregion
|
|
7
69
|
//#region src/plugins/hooks.d.ts
|
|
8
70
|
interface RequestHooks {
|
|
9
71
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
before: (
|
|
72
|
+
* Called before a navigation request is going to happen.
|
|
73
|
+
*/
|
|
74
|
+
before: (request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any | boolean>;
|
|
13
75
|
/**
|
|
14
76
|
* Called before the request of a navigation is going to happen.
|
|
15
77
|
*/
|
|
16
|
-
start: (context: InternalRouterContext) => MaybePromise<any>;
|
|
78
|
+
start: (request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any>;
|
|
17
79
|
/**
|
|
18
80
|
* Called when progress on the request is being made.
|
|
19
81
|
*/
|
|
20
|
-
progress: (progress:
|
|
82
|
+
progress: (progress: HttpUploadProgressEvent, request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any>;
|
|
21
83
|
/**
|
|
22
84
|
* Called when data is received after a request for a navigation.
|
|
23
85
|
*/
|
|
24
|
-
data: (response:
|
|
86
|
+
data: (request: PendingHybridRequest, response: HttpResponse, context: InternalRouterContext) => MaybePromise<any>;
|
|
25
87
|
/**
|
|
26
88
|
* Called when a request is successful and there is no error.
|
|
27
89
|
*/
|
|
28
|
-
success: (payload: HybridPayload, context: InternalRouterContext) => MaybePromise<any>;
|
|
90
|
+
success: (payload: HybridPayload, request: PendingHybridRequest, response: HttpResponse, context: InternalRouterContext) => MaybePromise<any>;
|
|
29
91
|
/**
|
|
30
|
-
* Called when a request is successful but there were errors.
|
|
92
|
+
* Called when a request is successful but there were validation errors.
|
|
31
93
|
*/
|
|
32
|
-
error: (errors: Errors, context: InternalRouterContext) => MaybePromise<any>;
|
|
94
|
+
'validation-error': (errors: Errors, request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any>;
|
|
33
95
|
/**
|
|
34
96
|
* Called when a request has been aborted.
|
|
35
97
|
*/
|
|
36
|
-
abort: (context: InternalRouterContext) => MaybePromise<any>;
|
|
98
|
+
abort: (request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any>;
|
|
37
99
|
/**
|
|
38
100
|
* Called when a response to a request is not a valid hybrid response.
|
|
39
101
|
*/
|
|
40
|
-
invalid: (response:
|
|
102
|
+
invalid: (request: PendingHybridRequest, response: HttpResponse, context: InternalRouterContext) => MaybePromise<any>;
|
|
41
103
|
/**
|
|
42
|
-
* Called when an
|
|
104
|
+
* Called when an unknown exception was triggered.
|
|
43
105
|
*/
|
|
44
|
-
exception: (error: Error, context: InternalRouterContext) => MaybePromise<any>;
|
|
106
|
+
exception: (error: Error, request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any>;
|
|
45
107
|
/**
|
|
46
108
|
* Called whenever the request failed, for any reason, in addition to other hooks.
|
|
47
109
|
*/
|
|
48
|
-
fail: (context: InternalRouterContext) => MaybePromise<any>;
|
|
110
|
+
fail: (error: Error, request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any>;
|
|
49
111
|
/**
|
|
50
112
|
* Called after a request has been made, even if it didn't succeed.
|
|
51
113
|
*/
|
|
52
|
-
after: (context: InternalRouterContext) => MaybePromise<any>;
|
|
114
|
+
after: (request: PendingHybridRequest, context: InternalRouterContext) => MaybePromise<any>;
|
|
53
115
|
}
|
|
54
116
|
interface Hooks extends RequestHooks {
|
|
55
117
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
118
|
+
* Called when Hybridly's context is initialized.
|
|
119
|
+
*/
|
|
58
120
|
initialized: (context: InternalRouterContext) => MaybePromise<any>;
|
|
59
121
|
/**
|
|
60
122
|
* Called after Hybridly's initial load.
|
|
@@ -92,14 +154,12 @@ interface HookOptions {
|
|
|
92
154
|
*/
|
|
93
155
|
declare function registerHook<T extends keyof Hooks>(hook: T, fn: Hooks[T], options?: HookOptions): () => void;
|
|
94
156
|
//#endregion
|
|
95
|
-
//#region src/
|
|
96
|
-
interface
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
* @default false
|
|
100
|
-
*/
|
|
101
|
-
local?: boolean;
|
|
157
|
+
//#region src/plugins/plugin.d.ts
|
|
158
|
+
interface Plugin extends Partial<Hooks> {
|
|
159
|
+
/** Identifier of the plugin. */
|
|
160
|
+
name: string;
|
|
102
161
|
}
|
|
162
|
+
declare function definePlugin(plugin: Plugin): Plugin;
|
|
103
163
|
//#endregion
|
|
104
164
|
//#region src/routing/types.d.ts
|
|
105
165
|
interface RoutingConfiguration {
|
|
@@ -121,6 +181,96 @@ interface GlobalRouteCollection extends RoutingConfiguration {}
|
|
|
121
181
|
type RouteName = keyof GlobalRouteCollection['routes'];
|
|
122
182
|
type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
|
|
123
183
|
//#endregion
|
|
184
|
+
//#region src/context/types.d.ts
|
|
185
|
+
/** Options for creating a router context. */
|
|
186
|
+
interface RouterContextOptions {
|
|
187
|
+
/** The initial payload served by the browser. */
|
|
188
|
+
payload: HybridPayload;
|
|
189
|
+
/** Adapter-specific functions. */
|
|
190
|
+
adapter: Adapter;
|
|
191
|
+
/** History state serializer. */
|
|
192
|
+
serializer?: Serializer;
|
|
193
|
+
/** List of plugins. */
|
|
194
|
+
plugins?: Plugin[];
|
|
195
|
+
/** The HTTP client instance. */
|
|
196
|
+
http?: HttpClient;
|
|
197
|
+
/** Initial routing configuration. */
|
|
198
|
+
routing?: RoutingConfiguration;
|
|
199
|
+
/** Whether to display response error modals. */
|
|
200
|
+
responseErrorModals?: boolean;
|
|
201
|
+
}
|
|
202
|
+
/** Router context. */
|
|
203
|
+
interface InternalRouterContext {
|
|
204
|
+
/** The current, normalized URL. */
|
|
205
|
+
url: string;
|
|
206
|
+
/** Validation errors grouped by error bag. */
|
|
207
|
+
validation: Record<string, Errors>;
|
|
208
|
+
/** The current view. */
|
|
209
|
+
view: View;
|
|
210
|
+
/** The current, optional dialog. */
|
|
211
|
+
dialog?: Dialog;
|
|
212
|
+
/** The current local asset version. */
|
|
213
|
+
version: string;
|
|
214
|
+
/** The current adapter's functions. */
|
|
215
|
+
adapter: ResolvedAdapter;
|
|
216
|
+
/** Scroll positions of the current page's DOM elements. */
|
|
217
|
+
scrollRegions: ScrollRegion[];
|
|
218
|
+
/** Arbitrary state. */
|
|
219
|
+
memo: Record<string, any>;
|
|
220
|
+
/** History state serializer. */
|
|
221
|
+
serializer: Serializer;
|
|
222
|
+
/** List of plugins. */
|
|
223
|
+
plugins: Plugin[];
|
|
224
|
+
/** Global hooks. */
|
|
225
|
+
hooks: Partial<Record<keyof Hooks, Array<Function>>>;
|
|
226
|
+
/** The HTTP client instance. */
|
|
227
|
+
http: HttpClient;
|
|
228
|
+
/** Routing configuration. */
|
|
229
|
+
routing?: RoutingConfiguration;
|
|
230
|
+
/** Whether to display response error modals. */
|
|
231
|
+
responseErrorModals?: boolean;
|
|
232
|
+
}
|
|
233
|
+
/** Router context. */
|
|
234
|
+
type RouterContext = Readonly<InternalRouterContext>;
|
|
235
|
+
/** Adapter-specific functions. */
|
|
236
|
+
interface Adapter {
|
|
237
|
+
/** Resolves a component from the given name. */
|
|
238
|
+
resolveComponent: ResolveComponent;
|
|
239
|
+
/** Called when the view is swapped. */
|
|
240
|
+
onViewSwap: SwapView;
|
|
241
|
+
/** Called when the context is updated. */
|
|
242
|
+
onContextUpdate?: (context: InternalRouterContext) => void;
|
|
243
|
+
/** Called when a dialog is closed. */
|
|
244
|
+
onDialogClose?: (context: InternalRouterContext) => void;
|
|
245
|
+
/** Called when Hybridly is waiting for a component to be mounted. The given callback should be executed after the view component is mounted. */
|
|
246
|
+
executeOnMounted: (callback: Function) => void;
|
|
247
|
+
}
|
|
248
|
+
interface ResolvedAdapter extends Adapter {
|
|
249
|
+
updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
|
|
250
|
+
}
|
|
251
|
+
interface ScrollRegion {
|
|
252
|
+
top: number;
|
|
253
|
+
left: number;
|
|
254
|
+
}
|
|
255
|
+
/** Provides methods to serialize the state into the history state. */
|
|
256
|
+
interface Serializer {
|
|
257
|
+
serialize: <T>(view: T) => string;
|
|
258
|
+
unserialize: <T>(state?: string) => T | undefined;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/context/context.d.ts
|
|
262
|
+
/** Gets the current context. */
|
|
263
|
+
declare function getRouterContext(): RouterContext;
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/dialog/index.d.ts
|
|
266
|
+
interface CloseDialogOptions extends HybridRequestOptions {
|
|
267
|
+
/**
|
|
268
|
+
* Close the dialog without a round-trip to the server.
|
|
269
|
+
* @default false
|
|
270
|
+
*/
|
|
271
|
+
local?: boolean;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
124
274
|
//#region src/url.d.ts
|
|
125
275
|
type UrlResolvable = string | URL | Location;
|
|
126
276
|
type UrlTransformable = BaseUrlTransformable | ((string: URL) => BaseUrlTransformable);
|
|
@@ -186,6 +336,12 @@ interface NavigationOptions {
|
|
|
186
336
|
* @internal
|
|
187
337
|
*/
|
|
188
338
|
updateHistoryState?: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Defines the type of view transition to use. If a string or array is given, uses it as the transition type.
|
|
341
|
+
*
|
|
342
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API/Using_types
|
|
343
|
+
*/
|
|
344
|
+
viewTransition?: string | string[] | boolean;
|
|
189
345
|
}
|
|
190
346
|
interface InternalNavigationOptions extends NavigationOptions {
|
|
191
347
|
/**
|
|
@@ -202,11 +358,34 @@ interface InternalNavigationOptions extends NavigationOptions {
|
|
|
202
358
|
* @internal
|
|
203
359
|
*/
|
|
204
360
|
hasDialog?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Final properties object for the view.
|
|
363
|
+
* @internal
|
|
364
|
+
*/
|
|
365
|
+
properties?: Properties;
|
|
205
366
|
}
|
|
206
367
|
type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
368
|
+
type RequestMode = 'navigation' | 'async';
|
|
369
|
+
type AsyncInterruptionScope = 'none' | 'all' | 'same-group';
|
|
207
370
|
interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
|
|
208
371
|
/** The URL to navigation. */
|
|
209
372
|
url?: UrlResolvable;
|
|
373
|
+
/** Defines how this request should be executed. */
|
|
374
|
+
mode?: RequestMode;
|
|
375
|
+
/**
|
|
376
|
+
* Group identifier used to interrupt asynchronous requests.
|
|
377
|
+
* @see interruptAsyncOnStart
|
|
378
|
+
*/
|
|
379
|
+
group?: string;
|
|
380
|
+
/** Whether this asynchronous request should be interrupted whenever a new navigation request starts. */
|
|
381
|
+
cancelOnNavigation?: boolean;
|
|
382
|
+
/**
|
|
383
|
+
* Defines which asynchronous requests should be interrupted when this request starts.
|
|
384
|
+
* `none` (default): does not interrupt any request
|
|
385
|
+
* `same-group` (default if `group` is specified): interrupts requests that share the same group identifier
|
|
386
|
+
* `all`: interrupts all asynchronous requests
|
|
387
|
+
*/
|
|
388
|
+
interruptAsyncOnStart?: AsyncInterruptionScope;
|
|
210
389
|
/** HTTP verb to use for the request. */
|
|
211
390
|
method?: Method | Lowercase<Method>;
|
|
212
391
|
/** Body of the request. */
|
|
@@ -215,6 +394,8 @@ interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
|
|
|
215
394
|
only?: string | string[];
|
|
216
395
|
/** Which properties not to update for this navigation. Other properties will be updated. */
|
|
217
396
|
except?: string | string[];
|
|
397
|
+
/** Which properties to clear before the update. */
|
|
398
|
+
reset?: string | string[];
|
|
218
399
|
/** Specific headers to add to the request. */
|
|
219
400
|
headers?: Record<string, string>;
|
|
220
401
|
/** The bag in which to put potential errors. */
|
|
@@ -228,27 +409,21 @@ interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
|
|
|
228
409
|
* @see https://laravel.com/docs/master/routing#form-method-spoofing
|
|
229
410
|
*/
|
|
230
411
|
spoof?: boolean;
|
|
231
|
-
/**
|
|
232
|
-
* If `false`, does not trigger the progress bar for this request.
|
|
233
|
-
*/
|
|
412
|
+
/** If `false`, does not trigger the progress bar for this request. */
|
|
234
413
|
progress?: boolean;
|
|
414
|
+
/** Abort controller for this request. */
|
|
415
|
+
abortController?: AbortController;
|
|
235
416
|
}
|
|
236
417
|
interface NavigationResponse {
|
|
237
|
-
response?:
|
|
238
|
-
error?:
|
|
239
|
-
type: string;
|
|
240
|
-
actual: Error;
|
|
241
|
-
};
|
|
418
|
+
response?: HttpResponse;
|
|
419
|
+
error?: Error;
|
|
242
420
|
}
|
|
243
421
|
interface DialogRouter {
|
|
244
422
|
/** Closes the current dialog. */
|
|
245
423
|
close: (options?: CloseDialogOptions) => void;
|
|
246
424
|
}
|
|
247
425
|
interface Router {
|
|
248
|
-
|
|
249
|
-
abort: () => Promise<void>;
|
|
250
|
-
/** Checks if there is an active navigate. */
|
|
251
|
-
active: () => boolean;
|
|
426
|
+
abort: () => void;
|
|
252
427
|
/** Makes a navigate with the given options. */
|
|
253
428
|
navigate: (options: HybridRequestOptions) => Promise<NavigationResponse>;
|
|
254
429
|
/** Reloads the current page. */
|
|
@@ -269,8 +444,6 @@ interface Router {
|
|
|
269
444
|
external: (url: UrlResolvable, data?: HybridRequestOptions['data']) => void;
|
|
270
445
|
/** Navigates to the given URL without a server round-trip. */
|
|
271
446
|
local: (url: UrlResolvable, options: ComponentNavigationOptions) => Promise<void>;
|
|
272
|
-
/** Preloads the given URL. The next time this URL is navigated to, it will be loaded from the cache. */
|
|
273
|
-
preload: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<boolean>;
|
|
274
447
|
/** Determines if the given route name and parameters matches the current route. */
|
|
275
448
|
matches: <T extends RouteName>(name: T, parameters?: RouteParameters<T>) => boolean;
|
|
276
449
|
/** Gets the current route name. Returns `undefined` is unknown. */
|
|
@@ -283,8 +456,8 @@ interface Router {
|
|
|
283
456
|
get: <T = any>(key: string) => T | undefined;
|
|
284
457
|
};
|
|
285
458
|
}
|
|
286
|
-
/** A
|
|
287
|
-
interface
|
|
459
|
+
/** A hybrid request being made. */
|
|
460
|
+
interface PendingHybridRequest {
|
|
288
461
|
/** The URL to which the request is being made. */
|
|
289
462
|
url: URL;
|
|
290
463
|
/** Abort controller associated to this request. */
|
|
@@ -293,8 +466,18 @@ interface PendingNavigation {
|
|
|
293
466
|
options: HybridRequestOptions;
|
|
294
467
|
/** Navigation identifier. */
|
|
295
468
|
id: string;
|
|
296
|
-
/**
|
|
297
|
-
|
|
469
|
+
/** Whether the request has completed. */
|
|
470
|
+
completed: boolean;
|
|
471
|
+
/** Whether the request has been gracefully interrupted. */
|
|
472
|
+
cancelled: boolean;
|
|
473
|
+
/** Whether the request has been forcefully interrupted. */
|
|
474
|
+
interrupted: boolean;
|
|
475
|
+
/** Promise for the request. */
|
|
476
|
+
promise: Promise<NavigationResponse>;
|
|
477
|
+
/** Callback that resolves the request promise. */
|
|
478
|
+
resolve: (response: NavigationResponse) => void;
|
|
479
|
+
/** The view from which the request has started. */
|
|
480
|
+
view: View;
|
|
298
481
|
}
|
|
299
482
|
/** A view or dialog component. */
|
|
300
483
|
interface View {
|
|
@@ -303,7 +486,10 @@ interface View {
|
|
|
303
486
|
/** Properties to apply to the component. */
|
|
304
487
|
properties: Properties;
|
|
305
488
|
/** Deferred properties for this view. */
|
|
306
|
-
deferred: string[]
|
|
489
|
+
deferred: Record<string, string | string[]>;
|
|
490
|
+
/** Properties that should be merged with the existing payload. */
|
|
491
|
+
mergeable: Array<[string, boolean, // true = prepend, false = append
|
|
492
|
+
string | null]>;
|
|
307
493
|
}
|
|
308
494
|
interface Dialog extends Required<View> {
|
|
309
495
|
/** URL that is the base background view when navigating to the dialog directly. */
|
|
@@ -338,6 +524,8 @@ interface HybridPayload {
|
|
|
338
524
|
view: View;
|
|
339
525
|
/** An optional dialog. */
|
|
340
526
|
dialog?: Dialog;
|
|
527
|
+
/** Validation errors grouped by error bag. */
|
|
528
|
+
validation: Validation;
|
|
341
529
|
/** The current page URL. */
|
|
342
530
|
url: string;
|
|
343
531
|
/** The current asset version. */
|
|
@@ -345,101 +533,12 @@ interface HybridPayload {
|
|
|
345
533
|
}
|
|
346
534
|
interface Progress {
|
|
347
535
|
/** Base event. */
|
|
348
|
-
event:
|
|
536
|
+
event: HttpUploadProgressEvent;
|
|
349
537
|
/** Computed percentage. */
|
|
350
538
|
percentage: Readonly<number>;
|
|
351
539
|
}
|
|
352
|
-
type Errors = any
|
|
353
|
-
|
|
354
|
-
//#region src/plugins/plugin.d.ts
|
|
355
|
-
interface Plugin extends Partial<Hooks> {
|
|
356
|
-
/** Identifier of the plugin. */
|
|
357
|
-
name: string;
|
|
358
|
-
}
|
|
359
|
-
declare function definePlugin(plugin: Plugin): Plugin;
|
|
360
|
-
//#endregion
|
|
361
|
-
//#region src/context/types.d.ts
|
|
362
|
-
/** Options for creating a router context. */
|
|
363
|
-
interface RouterContextOptions {
|
|
364
|
-
/** The initial payload served by the browser. */
|
|
365
|
-
payload: HybridPayload;
|
|
366
|
-
/** Adapter-specific functions. */
|
|
367
|
-
adapter: Adapter;
|
|
368
|
-
/** History state serializer. */
|
|
369
|
-
serializer?: Serializer;
|
|
370
|
-
/** List of plugins. */
|
|
371
|
-
plugins?: Plugin[];
|
|
372
|
-
/** The Axios instance. */
|
|
373
|
-
axios?: Axios;
|
|
374
|
-
/** Initial routing configuration. */
|
|
375
|
-
routing?: RoutingConfiguration;
|
|
376
|
-
/** Whether to display response error modals. */
|
|
377
|
-
responseErrorModals?: boolean;
|
|
378
|
-
}
|
|
379
|
-
/** Router context. */
|
|
380
|
-
interface InternalRouterContext {
|
|
381
|
-
/** The current, normalized URL. */
|
|
382
|
-
url: string;
|
|
383
|
-
/** The current view. */
|
|
384
|
-
view: View;
|
|
385
|
-
/** The current, optional dialog. */
|
|
386
|
-
dialog?: Dialog;
|
|
387
|
-
/** The current local asset version. */
|
|
388
|
-
version: string;
|
|
389
|
-
/** The current adapter's functions. */
|
|
390
|
-
adapter: ResolvedAdapter;
|
|
391
|
-
/** Scroll positions of the current page's DOM elements. */
|
|
392
|
-
scrollRegions: ScrollRegion[];
|
|
393
|
-
/** Arbitrary state. */
|
|
394
|
-
memo: Record<string, any>;
|
|
395
|
-
/** Currently pending navigation. */
|
|
396
|
-
pendingNavigation?: PendingNavigation;
|
|
397
|
-
/** History state serializer. */
|
|
398
|
-
serializer: Serializer;
|
|
399
|
-
/** List of plugins. */
|
|
400
|
-
plugins: Plugin[];
|
|
401
|
-
/** Global hooks. */
|
|
402
|
-
hooks: Partial<Record<keyof Hooks, Array<Function>>>;
|
|
403
|
-
/** The Axios instance. */
|
|
404
|
-
axios: Axios;
|
|
405
|
-
/** Routing configuration. */
|
|
406
|
-
routing?: RoutingConfiguration;
|
|
407
|
-
/** Whether to display response error modals. */
|
|
408
|
-
responseErrorModals?: boolean;
|
|
409
|
-
/** Cache of preload requests. */
|
|
410
|
-
preloadCache: Map<string, AxiosResponse>;
|
|
411
|
-
}
|
|
412
|
-
/** Router context. */
|
|
413
|
-
type RouterContext = Readonly<InternalRouterContext>;
|
|
414
|
-
/** Adapter-specific functions. */
|
|
415
|
-
interface Adapter {
|
|
416
|
-
/** Resolves a component from the given name. */
|
|
417
|
-
resolveComponent: ResolveComponent;
|
|
418
|
-
/** Called when the view is swapped. */
|
|
419
|
-
onViewSwap: SwapView;
|
|
420
|
-
/** Called when the context is updated. */
|
|
421
|
-
onContextUpdate?: (context: InternalRouterContext) => void;
|
|
422
|
-
/** Called when a dialog is closed. */
|
|
423
|
-
onDialogClose?: (context: InternalRouterContext) => void;
|
|
424
|
-
/** Called when Hybridly is waiting for a component to be mounted. The given callback should be executed after the view component is mounted. */
|
|
425
|
-
executeOnMounted: (callback: Function) => void;
|
|
426
|
-
}
|
|
427
|
-
interface ResolvedAdapter extends Adapter {
|
|
428
|
-
updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
|
|
429
|
-
}
|
|
430
|
-
interface ScrollRegion {
|
|
431
|
-
top: number;
|
|
432
|
-
left: number;
|
|
433
|
-
}
|
|
434
|
-
/** Provides methods to serialize the state into the history state. */
|
|
435
|
-
interface Serializer {
|
|
436
|
-
serialize: <T>(view: T) => string;
|
|
437
|
-
unserialize: <T>(state?: string) => T | undefined;
|
|
438
|
-
}
|
|
439
|
-
//#endregion
|
|
440
|
-
//#region src/context/context.d.ts
|
|
441
|
-
/** Gets the current context. */
|
|
442
|
-
declare function getRouterContext(): RouterContext;
|
|
540
|
+
type Errors = Record<string, any>;
|
|
541
|
+
type Validation = Record<string, Errors>;
|
|
443
542
|
//#endregion
|
|
444
543
|
//#region src/router/router.d.ts
|
|
445
544
|
/**
|
|
@@ -451,10 +550,40 @@ declare function getRouterContext(): RouterContext;
|
|
|
451
550
|
* @example
|
|
452
551
|
* router.get('/posts/edit', { post })
|
|
453
552
|
*/
|
|
454
|
-
declare const router:
|
|
553
|
+
declare const router: {
|
|
554
|
+
abort: () => void;
|
|
555
|
+
navigate: (options: HybridRequestOptions) => Promise<NavigationResponse>;
|
|
556
|
+
reload: (options: HybridRequestOptions | undefined) => Promise<NavigationResponse>;
|
|
557
|
+
get: (url: UrlResolvable, options?: Omit<HybridRequestOptions, "method" | "url"> | undefined) => Promise<NavigationResponse>;
|
|
558
|
+
post: (url: UrlResolvable, options?: Omit<HybridRequestOptions, "method" | "url"> | undefined) => Promise<NavigationResponse>;
|
|
559
|
+
put: (url: UrlResolvable, options?: Omit<HybridRequestOptions, "method" | "url"> | undefined) => Promise<NavigationResponse>;
|
|
560
|
+
patch: (url: UrlResolvable, options?: Omit<HybridRequestOptions, "method" | "url"> | undefined) => Promise<NavigationResponse>;
|
|
561
|
+
delete: (url: UrlResolvable, options?: Omit<HybridRequestOptions, "method" | "url"> | undefined) => Promise<NavigationResponse>;
|
|
562
|
+
local: (url: UrlResolvable, options?: ComponentNavigationOptions) => Promise<void>;
|
|
563
|
+
external: (url: UrlResolvable, data?: _hybridly_utils0.RequestData) => void;
|
|
564
|
+
to: <T extends RouteName>(name: T, parameters: Record<string, any> | undefined, options: Omit<HybridRequestOptions, "url"> | undefined) => Promise<NavigationResponse>;
|
|
565
|
+
matches: <T extends RouteName>(name: T, parameters: Record<string, any> | undefined) => boolean;
|
|
566
|
+
current: () => string | undefined;
|
|
567
|
+
dialog: {
|
|
568
|
+
close: (options?: CloseDialogOptions | undefined) => Promise<void | NavigationResponse>;
|
|
569
|
+
};
|
|
570
|
+
history: {
|
|
571
|
+
get: <T = any>(key: string) => T | undefined;
|
|
572
|
+
remember: (key: string, value: any) => void;
|
|
573
|
+
};
|
|
574
|
+
};
|
|
455
575
|
/** Creates the hybridly router. */
|
|
456
576
|
declare function createRouter(options: RouterContextOptions): Promise<InternalRouterContext>;
|
|
457
577
|
//#endregion
|
|
578
|
+
//#region src/query.d.ts
|
|
579
|
+
type QueryArrayFormat = 'indices' | 'brackets';
|
|
580
|
+
interface StringifyQueryOptions {
|
|
581
|
+
arrayFormat?: QueryArrayFormat;
|
|
582
|
+
addQueryPrefix?: boolean;
|
|
583
|
+
}
|
|
584
|
+
declare function parseQueryString(query: string): Record<string, any>;
|
|
585
|
+
declare function stringifyQueryString(value: unknown, options?: StringifyQueryOptions): string;
|
|
586
|
+
//#endregion
|
|
458
587
|
//#region src/authorization.d.ts
|
|
459
588
|
interface Authorizable<Authorizations extends Record<string, boolean>> {
|
|
460
589
|
authorization: Authorizations;
|
|
@@ -493,7 +622,6 @@ interface DynamicConfiguration {
|
|
|
493
622
|
interface Component {
|
|
494
623
|
path: string;
|
|
495
624
|
identifier: string;
|
|
496
|
-
namespace: string;
|
|
497
625
|
}
|
|
498
626
|
//#endregion
|
|
499
627
|
//#region src/properties.d.ts
|
|
@@ -502,13 +630,14 @@ interface Component {
|
|
|
502
630
|
*/
|
|
503
631
|
interface GlobalHybridlyProperties {}
|
|
504
632
|
declare namespace constants_d_exports {
|
|
505
|
-
export { DIALOG_KEY_HEADER, DIALOG_REDIRECT_HEADER, ERROR_BAG_HEADER, EXCEPT_DATA_HEADER, EXTERNAL_NAVIGATION_HEADER, EXTERNAL_NAVIGATION_TARGET_HEADER, HYBRIDLY_HEADER, ONLY_DATA_HEADER, PARTIAL_COMPONENT_HEADER, SCROLL_REGION_ATTRIBUTE, STORAGE_EXTERNAL_KEY, VERSION_HEADER };
|
|
633
|
+
export { DIALOG_KEY_HEADER, DIALOG_REDIRECT_HEADER, ERROR_BAG_HEADER, EXCEPT_DATA_HEADER, EXTERNAL_NAVIGATION_HEADER, EXTERNAL_NAVIGATION_TARGET_HEADER, HYBRIDLY_HEADER, ONLY_DATA_HEADER, PARTIAL_COMPONENT_HEADER, RESET_HEADER, SCROLL_REGION_ATTRIBUTE, STORAGE_EXTERNAL_KEY, VERSION_HEADER };
|
|
506
634
|
}
|
|
507
635
|
declare const STORAGE_EXTERNAL_KEY = "hybridly:external";
|
|
508
636
|
declare const HYBRIDLY_HEADER = "x-hybrid";
|
|
509
637
|
declare const EXTERNAL_NAVIGATION_HEADER = "x-hybrid-external";
|
|
510
638
|
declare const EXTERNAL_NAVIGATION_TARGET_HEADER = "x-hybrid-external-target";
|
|
511
639
|
declare const PARTIAL_COMPONENT_HEADER = "x-hybrid-partial-component";
|
|
640
|
+
declare const RESET_HEADER = "x-hybrid-reset";
|
|
512
641
|
declare const ONLY_DATA_HEADER = "x-hybrid-only-data";
|
|
513
642
|
declare const DIALOG_KEY_HEADER = "x-hybrid-dialog-key";
|
|
514
643
|
declare const DIALOG_REDIRECT_HEADER = "x-hybrid-dialog-redirect";
|
|
@@ -517,4 +646,4 @@ declare const VERSION_HEADER = "x-hybrid-version";
|
|
|
517
646
|
declare const ERROR_BAG_HEADER = "x-hybrid-error-bag";
|
|
518
647
|
declare const SCROLL_REGION_ATTRIBUTE = "scroll-region";
|
|
519
648
|
//#endregion
|
|
520
|
-
export { type Authorizable, type DynamicConfiguration, type GlobalHybridlyProperties, type GlobalRouteCollection, type HybridPayload, type HybridRequestOptions, MaybePromise, type Method, type NavigationResponse, type Plugin, type Progress, type ResolveComponent, type RouteDefinition, type RouteName, type RouteParameters, type Router, type RouterContext, type RouterContextOptions, type RoutingConfiguration, type UrlResolvable, can, constants_d_exports as constants, createRouter, definePlugin, getRouterContext, makeUrl, registerHook, route, router, sameUrls };
|
|
649
|
+
export { type AsyncInterruptionScope, type Authorizable, type DynamicConfiguration, type Errors, type GlobalHybridlyProperties, type GlobalRouteCollection, type HttpClient, type HttpErrorCode, type HttpErrorKind, type HttpRequest, type HttpResponse, type HttpUploadProgressEvent, type HybridPayload, type HybridRequestOptions, MaybePromise, type Method, type NavigationResponse, type PendingHybridRequest, type Plugin, type Progress, type QueryArrayFormat, type RequestMode, type ResolveComponent, type RouteDefinition, type RouteName, type RouteParameters, type Router, type RouterContext, type RouterContextOptions, type RoutingConfiguration, type StringifyQueryOptions, type UrlResolvable, type Validation, can, constants_d_exports as constants, createRouter, createXhrHttpClient, definePlugin, getRouterContext, isHttpAbortError, isHttpError, makeUrl, parseQueryString, registerHook, route, router, sameUrls, stringifyQueryString };
|