@hybridly/core 0.8.3 → 0.10.0-beta.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/_chunks/chunk.mjs +20 -0
- package/dist/index.d.mts +391 -411
- package/dist/index.mjs +1045 -948
- package/package.json +11 -13
- package/LICENSE +0 -19
- package/dist/index.cjs +0 -1108
- package/dist/index.d.cts +0 -543
- package/dist/index.d.ts +0 -543
- package/properties.d.ts +0 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,138 +1,135 @@
|
|
|
1
|
-
import { RequestData } from
|
|
2
|
-
import {
|
|
1
|
+
import { RequestData } from "@hybridly/utils";
|
|
2
|
+
import { Axios, AxiosProgressEvent, AxiosResponse } from "axios";
|
|
3
3
|
|
|
4
|
+
//#region src/types.d.ts
|
|
4
5
|
type MaybePromise<T> = T | Promise<T>;
|
|
5
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/plugins/hooks.d.ts
|
|
6
8
|
interface RequestHooks {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Called before a navigation request is going to happen.
|
|
11
|
+
*/
|
|
12
|
+
before: (options: HybridRequestOptions, context: InternalRouterContext) => MaybePromise<any | boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Called before the request of a navigation is going to happen.
|
|
15
|
+
*/
|
|
16
|
+
start: (context: InternalRouterContext) => MaybePromise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Called when progress on the request is being made.
|
|
19
|
+
*/
|
|
20
|
+
progress: (progress: Progress, context: InternalRouterContext) => MaybePromise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* Called when data is received after a request for a navigation.
|
|
23
|
+
*/
|
|
24
|
+
data: (response: AxiosResponse, context: InternalRouterContext) => MaybePromise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Called when a request is successful and there is no error.
|
|
27
|
+
*/
|
|
28
|
+
success: (payload: HybridPayload, context: InternalRouterContext) => MaybePromise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Called when a request is successful but there were errors.
|
|
31
|
+
*/
|
|
32
|
+
error: (errors: Errors, context: InternalRouterContext) => MaybePromise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Called when a request has been aborted.
|
|
35
|
+
*/
|
|
36
|
+
abort: (context: InternalRouterContext) => MaybePromise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Called when a response to a request is not a valid hybrid response.
|
|
39
|
+
*/
|
|
40
|
+
invalid: (response: AxiosResponse, context: InternalRouterContext) => MaybePromise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Called when an unknowne exception was triggered.
|
|
43
|
+
*/
|
|
44
|
+
exception: (error: Error, context: InternalRouterContext) => MaybePromise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Called whenever the request failed, for any reason, in addition to other hooks.
|
|
47
|
+
*/
|
|
48
|
+
fail: (context: InternalRouterContext) => MaybePromise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* Called after a request has been made, even if it didn't succeed.
|
|
51
|
+
*/
|
|
52
|
+
after: (context: InternalRouterContext) => MaybePromise<any>;
|
|
51
53
|
}
|
|
52
54
|
interface Hooks extends RequestHooks {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*/
|
|
78
|
-
navigating: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
79
|
-
/**
|
|
80
|
-
* Called when a component has been navigated to.
|
|
81
|
-
*/
|
|
82
|
-
navigated: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
83
|
-
/**
|
|
84
|
-
* Called when a component has been navigated to and was mounted by the adapter.
|
|
85
|
-
*/
|
|
86
|
-
mounted: (options: InternalNavigationOptions & MountedHookOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Called when Hybridly's context is initialized.
|
|
57
|
+
*/
|
|
58
|
+
initialized: (context: InternalRouterContext) => MaybePromise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Called after Hybridly's initial load.
|
|
61
|
+
*/
|
|
62
|
+
ready: (context: InternalRouterContext) => MaybePromise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Called when a back-forward navigation occurs.
|
|
65
|
+
*/
|
|
66
|
+
backForward: (state: any, context: InternalRouterContext) => MaybePromise<any>;
|
|
67
|
+
/**
|
|
68
|
+
* Called when a component navigation is being made.
|
|
69
|
+
*/
|
|
70
|
+
navigating: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Called when a component has been navigated to.
|
|
73
|
+
*/
|
|
74
|
+
navigated: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
75
|
+
/**
|
|
76
|
+
* Called when a component has been navigated to and was mounted by the adapter.
|
|
77
|
+
*/
|
|
78
|
+
mounted: (options: InternalNavigationOptions & MountedHookOptions, context: InternalRouterContext) => MaybePromise<any>;
|
|
87
79
|
}
|
|
88
80
|
interface MountedHookOptions {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Whether the component being mounted is a dialog.
|
|
83
|
+
*/
|
|
84
|
+
isDialog: boolean;
|
|
93
85
|
}
|
|
94
86
|
interface HookOptions {
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
/** Executes the hook only once. */
|
|
88
|
+
once?: boolean;
|
|
97
89
|
}
|
|
98
90
|
/**
|
|
99
91
|
* Registers a global hook.
|
|
100
92
|
*/
|
|
101
93
|
declare function registerHook<T extends keyof Hooks>(hook: T, fn: Hooks[T], options?: HookOptions): () => void;
|
|
102
|
-
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/dialog/index.d.ts
|
|
103
96
|
interface CloseDialogOptions extends HybridRequestOptions {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Close the dialog without a round-trip to the server.
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
local?: boolean;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/routing/types.d.ts
|
|
111
105
|
interface RoutingConfiguration {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
url: string;
|
|
107
|
+
port?: number;
|
|
108
|
+
defaults: Record<string, any>;
|
|
109
|
+
routes: Record<string, RouteDefinition>;
|
|
110
|
+
absolute: boolean;
|
|
116
111
|
}
|
|
117
112
|
interface RouteDefinition {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
interface GlobalRouteCollection extends RoutingConfiguration {
|
|
126
|
-
}
|
|
113
|
+
uri: string;
|
|
114
|
+
method: Method[];
|
|
115
|
+
bindings: Record<string, string>;
|
|
116
|
+
domain?: string;
|
|
117
|
+
wheres?: Record<string, string>;
|
|
118
|
+
name: string;
|
|
119
|
+
}
|
|
120
|
+
interface GlobalRouteCollection extends RoutingConfiguration {}
|
|
127
121
|
type RouteName = keyof GlobalRouteCollection['routes'];
|
|
128
122
|
type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
|
|
129
|
-
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/url.d.ts
|
|
130
125
|
type UrlResolvable = string | URL | Location;
|
|
131
126
|
type UrlTransformable = BaseUrlTransformable | ((string: URL) => BaseUrlTransformable);
|
|
132
127
|
type BaseUrlTransformable = Partial<Omit<URL, 'searchParams' | 'toJSON' | 'toString'>> & {
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
query?: any;
|
|
129
|
+
trailingSlash?: boolean;
|
|
135
130
|
};
|
|
131
|
+
/** Normalizes the given input to an URL. */
|
|
132
|
+
|
|
136
133
|
/**
|
|
137
134
|
* Converts an input to an URL, optionally changing its properties after initialization.
|
|
138
135
|
*/
|
|
@@ -141,308 +138,313 @@ declare function makeUrl(href: UrlResolvable, transformations?: UrlTransformable
|
|
|
141
138
|
* Checks if the given URLs have the same origin and path.
|
|
142
139
|
*/
|
|
143
140
|
declare function sameUrls(...hrefs: UrlResolvable[]): boolean;
|
|
144
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/router/types.d.ts
|
|
145
143
|
type ConditionalNavigationOption<T extends boolean | string> = T | ((payload: NavigationOptions) => T);
|
|
146
144
|
interface ComponentNavigationOptions {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
145
|
+
/** Dialog data. */
|
|
146
|
+
dialog?: Dialog | false;
|
|
147
|
+
/** Name of the component to use. */
|
|
148
|
+
component?: string;
|
|
149
|
+
/** Properties to apply to the component. */
|
|
150
|
+
properties?: Properties;
|
|
151
|
+
/**
|
|
152
|
+
* Whether to replace the current history state instead of adding
|
|
153
|
+
* one. This affects the browser's "back" and "forward" features.
|
|
154
|
+
*/
|
|
155
|
+
replace?: ConditionalNavigationOption<boolean>;
|
|
156
|
+
/** Whether to preserve the current scrollbar position. */
|
|
157
|
+
preserveScroll?: ConditionalNavigationOption<boolean>;
|
|
158
|
+
/** Whether to preserve the current view component state. */
|
|
159
|
+
preserveState?: ConditionalNavigationOption<boolean>;
|
|
162
160
|
}
|
|
163
161
|
interface NavigationOptions {
|
|
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
|
-
|
|
162
|
+
/** View to navigate to. */
|
|
163
|
+
payload?: HybridPayload;
|
|
164
|
+
/**
|
|
165
|
+
* Whether to replace the current history state instead of adding
|
|
166
|
+
* one. This affects the browser's "back" and "forward" features.
|
|
167
|
+
*/
|
|
168
|
+
replace?: ConditionalNavigationOption<boolean>;
|
|
169
|
+
/** Whether to preserve the scrollbars positions on the view. */
|
|
170
|
+
preserveScroll?: ConditionalNavigationOption<boolean>;
|
|
171
|
+
/** Whether to preserve the current view component's state. */
|
|
172
|
+
preserveState?: ConditionalNavigationOption<boolean>;
|
|
173
|
+
/** Whether to preserve the current URL. */
|
|
174
|
+
preserveUrl?: ConditionalNavigationOption<boolean>;
|
|
175
|
+
/**
|
|
176
|
+
* Properties of the given URL to override.
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* router.get('/login?redirect=/', {
|
|
180
|
+
* transformUrl: { search: '' }
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
transformUrl?: UrlTransformable;
|
|
185
|
+
/**
|
|
186
|
+
* Defines whether the history state should be updated.
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
updateHistoryState?: boolean;
|
|
192
190
|
}
|
|
193
191
|
interface InternalNavigationOptions extends NavigationOptions {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Defines the kind of navigation being performed.
|
|
194
|
+
* - initial: the initial load's navigation
|
|
195
|
+
* - server: a navigation initiated by a server round-trip
|
|
196
|
+
* - local: a navigation initiated by `router.local`
|
|
197
|
+
* - back-forward: a navigation initiated by the browser's `popstate` event
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
type: 'initial' | 'local' | 'back-forward' | 'server';
|
|
201
|
+
/**
|
|
202
|
+
* Defines whether this navigation opens a dialog.
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
205
|
+
hasDialog?: boolean;
|
|
208
206
|
}
|
|
209
207
|
type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
210
208
|
interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
209
|
+
/** The URL to navigation. */
|
|
210
|
+
url?: UrlResolvable;
|
|
211
|
+
/** HTTP verb to use for the request. */
|
|
212
|
+
method?: Method | Lowercase<Method>;
|
|
213
|
+
/** Body of the request. */
|
|
214
|
+
data?: RequestData;
|
|
215
|
+
/** Which properties to update for this navigation. Other properties will be ignored. */
|
|
216
|
+
only?: string | string[];
|
|
217
|
+
/** Which properties not to update for this navigation. Other properties will be updated. */
|
|
218
|
+
except?: string | string[];
|
|
219
|
+
/** Specific headers to add to the request. */
|
|
220
|
+
headers?: Record<string, string>;
|
|
221
|
+
/** The bag in which to put potential errors. */
|
|
222
|
+
errorBag?: string;
|
|
223
|
+
/** Hooks for this navigation. */
|
|
224
|
+
hooks?: Partial<RequestHooks>;
|
|
225
|
+
/** If `true`, force the usage of a `FormData` object. */
|
|
226
|
+
useFormData?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* If `false`, disable automatic form spoofing.
|
|
229
|
+
* @see https://laravel.com/docs/master/routing#form-method-spoofing
|
|
230
|
+
*/
|
|
231
|
+
spoof?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* If `false`, does not trigger the progress bar for this request.
|
|
234
|
+
*/
|
|
235
|
+
progress?: boolean;
|
|
238
236
|
}
|
|
239
237
|
interface NavigationResponse {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
response?: AxiosResponse;
|
|
239
|
+
error?: {
|
|
240
|
+
type: string;
|
|
241
|
+
actual: Error;
|
|
242
|
+
};
|
|
245
243
|
}
|
|
246
244
|
interface DialogRouter {
|
|
247
|
-
|
|
248
|
-
|
|
245
|
+
/** Closes the current dialog. */
|
|
246
|
+
close: (options?: CloseDialogOptions) => void;
|
|
249
247
|
}
|
|
250
248
|
interface Router {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
249
|
+
/** Aborts the currently pending navigate, if any. */
|
|
250
|
+
abort: () => Promise<void>;
|
|
251
|
+
/** Checks if there is an active navigate. */
|
|
252
|
+
active: () => boolean;
|
|
253
|
+
/** Makes a navigate with the given options. */
|
|
254
|
+
navigate: (options: HybridRequestOptions) => Promise<NavigationResponse>;
|
|
255
|
+
/** Reloads the current page. */
|
|
256
|
+
reload: (options?: HybridRequestOptions) => Promise<NavigationResponse>;
|
|
257
|
+
/** Makes a request to given named route. The HTTP verb is determined automatically but can be overriden. */
|
|
258
|
+
to: <T extends RouteName>(name: T, parameters?: RouteParameters<T>, options?: Omit<HybridRequestOptions, 'url'>) => Promise<NavigationResponse>;
|
|
259
|
+
/** Makes a GET request to the given URL. */
|
|
260
|
+
get: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
261
|
+
/** Makes a POST request to the given URL. */
|
|
262
|
+
post: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
263
|
+
/** Makes a PUT request to the given URL. */
|
|
264
|
+
put: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
265
|
+
/** Makes a PATCH request to the given URL. */
|
|
266
|
+
patch: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
267
|
+
/** Makes a DELETE request to the given URL. */
|
|
268
|
+
delete: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
|
|
269
|
+
/** Navigates to the given external URL. Convenience method using `document.location.href`. */
|
|
270
|
+
external: (url: UrlResolvable, data?: HybridRequestOptions['data']) => void;
|
|
271
|
+
/** Navigates to the given URL without a server round-trip. */
|
|
272
|
+
local: (url: UrlResolvable, options: ComponentNavigationOptions) => Promise<void>;
|
|
273
|
+
/** Preloads the given URL. The next time this URL is navigated to, it will be loaded from the cache. */
|
|
274
|
+
preload: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<boolean>;
|
|
275
|
+
/** Determines if the given route name and parameters matches the current route. */
|
|
276
|
+
matches: <T extends RouteName>(name: T, parameters?: RouteParameters<T>) => boolean;
|
|
277
|
+
/** Gets the current route name. Returns `undefined` is unknown. */
|
|
278
|
+
current: () => RouteName | undefined;
|
|
279
|
+
/** Access the dialog router. */
|
|
280
|
+
dialog: DialogRouter;
|
|
281
|
+
/** Access the history state. */
|
|
282
|
+
history: {
|
|
283
|
+
/** Remembers a value for the given route. */
|
|
284
|
+
remember: (key: string, value: any) => void;
|
|
285
|
+
/** Gets a remembered value. */
|
|
286
|
+
get: <T = any>(key: string) => T | undefined;
|
|
287
|
+
};
|
|
290
288
|
}
|
|
291
289
|
/** A navigation being made. */
|
|
292
290
|
interface PendingNavigation {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
291
|
+
/** The URL to which the request is being made. */
|
|
292
|
+
url: URL;
|
|
293
|
+
/** Abort controller associated to this request. */
|
|
294
|
+
controller: AbortController;
|
|
295
|
+
/** Options for the associated hybrid request. */
|
|
296
|
+
options: HybridRequestOptions;
|
|
297
|
+
/** Navigation identifier. */
|
|
298
|
+
id: string;
|
|
299
|
+
/** Current status. */
|
|
300
|
+
status: 'pending' | 'success' | 'error';
|
|
303
301
|
}
|
|
304
302
|
/** A view or dialog component. */
|
|
305
303
|
interface View {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
304
|
+
/** Name of the component to use. */
|
|
305
|
+
component?: string;
|
|
306
|
+
/** Properties to apply to the component. */
|
|
307
|
+
properties: Properties;
|
|
308
|
+
/** Deferred properties for this view. */
|
|
309
|
+
deferred: string[];
|
|
312
310
|
}
|
|
313
311
|
interface Dialog extends Required<View> {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
312
|
+
/** URL that is the base background view when navigating to the dialog directly. */
|
|
313
|
+
baseUrl: string;
|
|
314
|
+
/** URL to which the dialog should redirect when closed. */
|
|
315
|
+
redirectUrl: string;
|
|
316
|
+
/** Unique identifier for this modal's lifecycle. */
|
|
317
|
+
key: string;
|
|
320
318
|
}
|
|
321
319
|
type Property = null | string | number | boolean | Property[] | {
|
|
322
|
-
|
|
320
|
+
[name: string]: Property;
|
|
323
321
|
};
|
|
324
322
|
type Properties = Record<string | number, Property>;
|
|
325
323
|
interface SwapOptions<T> {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
324
|
+
/** The new component. */
|
|
325
|
+
component: T;
|
|
326
|
+
/** The new properties. */
|
|
327
|
+
properties?: any;
|
|
328
|
+
/** Whether to preserve the state of the component. */
|
|
329
|
+
preserveState?: boolean;
|
|
330
|
+
/** Current dialog. */
|
|
331
|
+
dialog?: Dialog;
|
|
332
|
+
/** On mounted callback. */
|
|
333
|
+
onMounted?: (options: MountedHookOptions) => void;
|
|
336
334
|
}
|
|
337
335
|
type ViewComponent = any;
|
|
338
336
|
type ResolveComponent = (name: string) => Promise<ViewComponent>;
|
|
339
337
|
type SwapView = (options: SwapOptions<ViewComponent>) => Promise<void>;
|
|
340
338
|
/** The payload of a navigation request from the server. */
|
|
341
339
|
interface HybridPayload {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
340
|
+
/** The view to use in this request. */
|
|
341
|
+
view: View;
|
|
342
|
+
/** An optional dialog. */
|
|
343
|
+
dialog?: Dialog;
|
|
344
|
+
/** The current page URL. */
|
|
345
|
+
url: string;
|
|
346
|
+
/** The current asset version. */
|
|
347
|
+
version: string;
|
|
350
348
|
}
|
|
351
349
|
interface Progress {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
350
|
+
/** Base event. */
|
|
351
|
+
event: AxiosProgressEvent;
|
|
352
|
+
/** Computed percentage. */
|
|
353
|
+
percentage: Readonly<number>;
|
|
356
354
|
}
|
|
357
355
|
type Errors = any;
|
|
358
|
-
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/plugins/plugin.d.ts
|
|
359
358
|
interface Plugin extends Partial<Hooks> {
|
|
360
|
-
|
|
361
|
-
|
|
359
|
+
/** Identifier of the plugin. */
|
|
360
|
+
name: string;
|
|
362
361
|
}
|
|
363
362
|
declare function definePlugin(plugin: Plugin): Plugin;
|
|
364
|
-
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/context/types.d.ts
|
|
365
365
|
/** Options for creating a router context. */
|
|
366
366
|
interface RouterContextOptions {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
367
|
+
/** The initial payload served by the browser. */
|
|
368
|
+
payload: HybridPayload;
|
|
369
|
+
/** Adapter-specific functions. */
|
|
370
|
+
adapter: Adapter;
|
|
371
|
+
/** History state serializer. */
|
|
372
|
+
serializer?: Serializer;
|
|
373
|
+
/** List of plugins. */
|
|
374
|
+
plugins?: Plugin[];
|
|
375
|
+
/** The Axios instance. */
|
|
376
|
+
axios?: Axios;
|
|
377
|
+
/** Initial routing configuration. */
|
|
378
|
+
routing?: RoutingConfiguration;
|
|
379
|
+
/** Whether to display response error modals. */
|
|
380
|
+
responseErrorModals?: boolean;
|
|
381
381
|
}
|
|
382
382
|
/** Router context. */
|
|
383
383
|
interface InternalRouterContext {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
384
|
+
/** The current, normalized URL. */
|
|
385
|
+
url: string;
|
|
386
|
+
/** The current view. */
|
|
387
|
+
view: View;
|
|
388
|
+
/** The current, optional dialog. */
|
|
389
|
+
dialog?: Dialog;
|
|
390
|
+
/** The current local asset version. */
|
|
391
|
+
version: string;
|
|
392
|
+
/** The current adapter's functions. */
|
|
393
|
+
adapter: ResolvedAdapter;
|
|
394
|
+
/** Scroll positions of the current page's DOM elements. */
|
|
395
|
+
scrollRegions: ScrollRegion[];
|
|
396
|
+
/** Arbitrary state. */
|
|
397
|
+
memo: Record<string, any>;
|
|
398
|
+
/** Currently pending navigation. */
|
|
399
|
+
pendingNavigation?: PendingNavigation;
|
|
400
|
+
/** History state serializer. */
|
|
401
|
+
serializer: Serializer;
|
|
402
|
+
/** List of plugins. */
|
|
403
|
+
plugins: Plugin[];
|
|
404
|
+
/** Global hooks. */
|
|
405
|
+
hooks: Partial<Record<keyof Hooks, Array<Function>>>;
|
|
406
|
+
/** The Axios instance. */
|
|
407
|
+
axios: Axios;
|
|
408
|
+
/** Routing configuration. */
|
|
409
|
+
routing?: RoutingConfiguration;
|
|
410
|
+
/** Whether to display response error modals. */
|
|
411
|
+
responseErrorModals?: boolean;
|
|
412
|
+
/** Cache of preload requests. */
|
|
413
|
+
preloadCache: Map<string, AxiosResponse>;
|
|
414
414
|
}
|
|
415
415
|
/** Router context. */
|
|
416
416
|
type RouterContext = Readonly<InternalRouterContext>;
|
|
417
417
|
/** Adapter-specific functions. */
|
|
418
418
|
interface Adapter {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
419
|
+
/** Resolves a component from the given name. */
|
|
420
|
+
resolveComponent: ResolveComponent;
|
|
421
|
+
/** Called when the view is swapped. */
|
|
422
|
+
onViewSwap: SwapView;
|
|
423
|
+
/** Called when the context is updated. */
|
|
424
|
+
onContextUpdate?: (context: InternalRouterContext) => void;
|
|
425
|
+
/** Called when a dialog is closed. */
|
|
426
|
+
onDialogClose?: (context: InternalRouterContext) => void;
|
|
427
|
+
/** Called when Hybridly is waiting for a component to be mounted. The given callback should be executed after the view component is mounted. */
|
|
428
|
+
executeOnMounted: (callback: Function) => void;
|
|
429
429
|
}
|
|
430
430
|
interface ResolvedAdapter extends Adapter {
|
|
431
|
-
|
|
431
|
+
updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
|
|
432
432
|
}
|
|
433
433
|
interface ScrollRegion {
|
|
434
|
-
|
|
435
|
-
|
|
434
|
+
top: number;
|
|
435
|
+
left: number;
|
|
436
436
|
}
|
|
437
437
|
/** Provides methods to serialize the state into the history state. */
|
|
438
438
|
interface Serializer {
|
|
439
|
-
|
|
440
|
-
|
|
439
|
+
serialize: <T>(view: T) => string;
|
|
440
|
+
unserialize: <T>(state?: string) => T | undefined;
|
|
441
441
|
}
|
|
442
|
-
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/context/context.d.ts
|
|
443
444
|
/** Gets the current context. */
|
|
444
445
|
declare function getRouterContext(): RouterContext;
|
|
445
|
-
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/router/router.d.ts
|
|
446
448
|
/**
|
|
447
449
|
* The hybridly router.
|
|
448
450
|
* This is the core function that you can use to navigate in
|
|
@@ -455,48 +457,56 @@ declare function getRouterContext(): RouterContext;
|
|
|
455
457
|
declare const router: Router;
|
|
456
458
|
/** Creates the hybridly router. */
|
|
457
459
|
declare function createRouter(options: RouterContextOptions): Promise<InternalRouterContext>;
|
|
458
|
-
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region src/authorization.d.ts
|
|
459
462
|
interface Authorizable<Authorizations extends Record<string, boolean>> {
|
|
460
|
-
|
|
463
|
+
authorization: Authorizations;
|
|
461
464
|
}
|
|
462
465
|
/**
|
|
463
466
|
* Checks whether the given data has the authorization for the given action.
|
|
464
467
|
* If the data object has no authorization definition corresponding to the given action, this method will return `false`.
|
|
465
468
|
*/
|
|
466
469
|
declare function can<Authorizations extends Record<string, boolean>, Data extends Authorizable<Authorizations>, Action extends keyof Data['authorization']>(resource: Data, action: Action): Authorizations[Action];
|
|
467
|
-
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region src/routing/route.d.ts
|
|
468
472
|
/**
|
|
469
473
|
* Generates a route from the given route name.
|
|
470
474
|
*/
|
|
471
475
|
declare function route<T extends RouteName>(name: T, parameters?: RouteParameters<T>, absolute?: boolean): string;
|
|
472
|
-
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/config/types.d.ts
|
|
473
478
|
interface DynamicConfiguration {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
components: Component[];
|
|
491
|
-
};
|
|
492
|
-
routing: RoutingConfiguration;
|
|
479
|
+
versions: {
|
|
480
|
+
composer: string;
|
|
481
|
+
npm: string;
|
|
482
|
+
latest: string;
|
|
483
|
+
is_latest: boolean;
|
|
484
|
+
};
|
|
485
|
+
architecture: {
|
|
486
|
+
root_directory: string;
|
|
487
|
+
application_main_path: string;
|
|
488
|
+
};
|
|
489
|
+
components: {
|
|
490
|
+
eager?: boolean;
|
|
491
|
+
views: Component[];
|
|
492
|
+
layouts: Component[];
|
|
493
|
+
};
|
|
494
|
+
routing: RoutingConfiguration;
|
|
493
495
|
}
|
|
494
496
|
interface Component {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
497
|
+
path: string;
|
|
498
|
+
identifier: string;
|
|
499
|
+
namespace: string;
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/properties.d.ts
|
|
503
|
+
/**
|
|
504
|
+
* Represents the global properties shared by the back-end.
|
|
505
|
+
*/
|
|
506
|
+
interface GlobalHybridlyProperties {}
|
|
507
|
+
declare namespace constants_d_exports {
|
|
508
|
+
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 };
|
|
498
509
|
}
|
|
499
|
-
|
|
500
510
|
declare const STORAGE_EXTERNAL_KEY = "hybridly:external";
|
|
501
511
|
declare const HYBRIDLY_HEADER = "x-hybrid";
|
|
502
512
|
declare const EXTERNAL_NAVIGATION_HEADER = "x-hybrid-external";
|
|
@@ -509,35 +519,5 @@ declare const EXCEPT_DATA_HEADER = "x-hybrid-except-data";
|
|
|
509
519
|
declare const VERSION_HEADER = "x-hybrid-version";
|
|
510
520
|
declare const ERROR_BAG_HEADER = "x-hybrid-error-bag";
|
|
511
521
|
declare const SCROLL_REGION_ATTRIBUTE = "scroll-region";
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
declare const constants_DIALOG_REDIRECT_HEADER: typeof DIALOG_REDIRECT_HEADER;
|
|
515
|
-
declare const constants_ERROR_BAG_HEADER: typeof ERROR_BAG_HEADER;
|
|
516
|
-
declare const constants_EXCEPT_DATA_HEADER: typeof EXCEPT_DATA_HEADER;
|
|
517
|
-
declare const constants_EXTERNAL_NAVIGATION_HEADER: typeof EXTERNAL_NAVIGATION_HEADER;
|
|
518
|
-
declare const constants_EXTERNAL_NAVIGATION_TARGET_HEADER: typeof EXTERNAL_NAVIGATION_TARGET_HEADER;
|
|
519
|
-
declare const constants_HYBRIDLY_HEADER: typeof HYBRIDLY_HEADER;
|
|
520
|
-
declare const constants_ONLY_DATA_HEADER: typeof ONLY_DATA_HEADER;
|
|
521
|
-
declare const constants_PARTIAL_COMPONENT_HEADER: typeof PARTIAL_COMPONENT_HEADER;
|
|
522
|
-
declare const constants_SCROLL_REGION_ATTRIBUTE: typeof SCROLL_REGION_ATTRIBUTE;
|
|
523
|
-
declare const constants_STORAGE_EXTERNAL_KEY: typeof STORAGE_EXTERNAL_KEY;
|
|
524
|
-
declare const constants_VERSION_HEADER: typeof VERSION_HEADER;
|
|
525
|
-
declare namespace constants {
|
|
526
|
-
export {
|
|
527
|
-
constants_DIALOG_KEY_HEADER as DIALOG_KEY_HEADER,
|
|
528
|
-
constants_DIALOG_REDIRECT_HEADER as DIALOG_REDIRECT_HEADER,
|
|
529
|
-
constants_ERROR_BAG_HEADER as ERROR_BAG_HEADER,
|
|
530
|
-
constants_EXCEPT_DATA_HEADER as EXCEPT_DATA_HEADER,
|
|
531
|
-
constants_EXTERNAL_NAVIGATION_HEADER as EXTERNAL_NAVIGATION_HEADER,
|
|
532
|
-
constants_EXTERNAL_NAVIGATION_TARGET_HEADER as EXTERNAL_NAVIGATION_TARGET_HEADER,
|
|
533
|
-
constants_HYBRIDLY_HEADER as HYBRIDLY_HEADER,
|
|
534
|
-
constants_ONLY_DATA_HEADER as ONLY_DATA_HEADER,
|
|
535
|
-
constants_PARTIAL_COMPONENT_HEADER as PARTIAL_COMPONENT_HEADER,
|
|
536
|
-
constants_SCROLL_REGION_ATTRIBUTE as SCROLL_REGION_ATTRIBUTE,
|
|
537
|
-
constants_STORAGE_EXTERNAL_KEY as STORAGE_EXTERNAL_KEY,
|
|
538
|
-
constants_VERSION_HEADER as VERSION_HEADER,
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
export { can, constants, createRouter, definePlugin, getRouterContext, makeUrl, registerHook, route, router, sameUrls };
|
|
543
|
-
export type { Authorizable, DynamicConfiguration, GlobalRouteCollection, HybridPayload, HybridRequestOptions, MaybePromise, Method, NavigationResponse, Plugin, Progress, ResolveComponent, RouteDefinition, RouteName, RouteParameters, Router, RouterContext, RouterContextOptions, RoutingConfiguration, UrlResolvable };
|
|
522
|
+
//#endregion
|
|
523
|
+
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 };
|