@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/index.d.mts CHANGED
@@ -1,138 +1,135 @@
1
- import { RequestData } from '@hybridly/utils';
2
- import { AxiosResponse, AxiosProgressEvent, Axios } from 'axios';
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
- * Called before a navigation request is going to happen.
9
- */
10
- before: (options: HybridRequestOptions, context: InternalRouterContext) => MaybePromise<any | boolean>;
11
- /**
12
- * Called before the request of a navigation is going to happen.
13
- */
14
- start: (context: InternalRouterContext) => MaybePromise<any>;
15
- /**
16
- * Called when progress on the request is being made.
17
- */
18
- progress: (progress: Progress, context: InternalRouterContext) => MaybePromise<any>;
19
- /**
20
- * Called when data is received after a request for a navigation.
21
- */
22
- data: (response: AxiosResponse, context: InternalRouterContext) => MaybePromise<any>;
23
- /**
24
- * Called when a request is successful and there is no error.
25
- */
26
- success: (payload: HybridPayload, context: InternalRouterContext) => MaybePromise<any>;
27
- /**
28
- * Called when a request is successful but there were errors.
29
- */
30
- error: (errors: Errors, context: InternalRouterContext) => MaybePromise<any>;
31
- /**
32
- * Called when a request has been aborted.
33
- */
34
- abort: (context: InternalRouterContext) => MaybePromise<any>;
35
- /**
36
- * Called when a response to a request is not a valid hybrid response.
37
- */
38
- invalid: (response: AxiosResponse, context: InternalRouterContext) => MaybePromise<any>;
39
- /**
40
- * Called when an unknowne exception was triggered.
41
- */
42
- exception: (error: Error, context: InternalRouterContext) => MaybePromise<any>;
43
- /**
44
- * Called whenever the request failed, for any reason, in addition to other hooks.
45
- */
46
- fail: (context: InternalRouterContext) => MaybePromise<any>;
47
- /**
48
- * Called after a request has been made, even if it didn't succeed.
49
- */
50
- after: (context: InternalRouterContext) => MaybePromise<any>;
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
- /////////////////////// * Called when Hybridly's context is initialized.
55
- ///////////////////////
56
- ///////////////////////
57
- ///////////////////////
58
- ///////////////////////
59
- ///////////////////////
60
- ///////////////////////
61
- ///////////////////////
62
- ///////////////////////
63
- ///////////////////////
64
- ///////////////////////
65
- */
66
- initialized: (context: InternalRouterContext) => MaybePromise<any>;
67
- /**
68
- * Called after Hybridly's initial load.
69
- */
70
- ready: (context: InternalRouterContext) => MaybePromise<any>;
71
- /**
72
- * Called when a back-forward navigation occurs.
73
- */
74
- backForward: (state: any, context: InternalRouterContext) => MaybePromise<any>;
75
- /**
76
- * Called when a component navigation is being made.
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
- * Whether the component being mounted is a dialog.
91
- */
92
- isDialog: boolean;
81
+ /**
82
+ * Whether the component being mounted is a dialog.
83
+ */
84
+ isDialog: boolean;
93
85
  }
94
86
  interface HookOptions {
95
- /** Executes the hook only once. */
96
- once?: boolean;
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
- * Close the dialog without a round-trip to the server.
106
- * @default false
107
- */
108
- local?: boolean;
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
- url: string;
113
- port?: number;
114
- defaults: Record<string, any>;
115
- routes: Record<string, RouteDefinition>;
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
- uri: string;
119
- method: Method[];
120
- bindings: Record<string, string>;
121
- domain?: string;
122
- wheres?: Record<string, string>;
123
- name: string;
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
- query?: any;
134
- trailingSlash?: boolean;
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
- /** Dialog data. */
148
- dialog?: Dialog | false;
149
- /** Name of the component to use. */
150
- component?: string;
151
- /** Properties to apply to the component. */
152
- properties?: Properties;
153
- /**
154
- * Whether to replace the current history state instead of adding
155
- * one. This affects the browser's "back" and "forward" features.
156
- */
157
- replace?: ConditionalNavigationOption<boolean>;
158
- /** Whether to preserve the current scrollbar position. */
159
- preserveScroll?: ConditionalNavigationOption<boolean>;
160
- /** Whether to preserve the current view component state. */
161
- preserveState?: ConditionalNavigationOption<boolean>;
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
- /** View to navigate to. */
165
- payload?: HybridPayload;
166
- /**
167
- * Whether to replace the current history state instead of adding
168
- * one. This affects the browser's "back" and "forward" features.
169
- */
170
- replace?: ConditionalNavigationOption<boolean>;
171
- /** Whether to preserve the scrollbars positions on the view. */
172
- preserveScroll?: ConditionalNavigationOption<boolean>;
173
- /** Whether to preserve the current view component's state. */
174
- preserveState?: ConditionalNavigationOption<boolean>;
175
- /** Whether to preserve the current URL. */
176
- preserveUrl?: ConditionalNavigationOption<boolean>;
177
- /**
178
- * Properties of the given URL to override.
179
- * @example
180
- * ```ts
181
- * router.get('/login?redirect=/', {
182
- * transformUrl: { search: '' }
183
- * }
184
- * ```
185
- */
186
- transformUrl?: UrlTransformable;
187
- /**
188
- * Defines whether the history state should be updated.
189
- * @internal
190
- */
191
- updateHistoryState?: boolean;
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
- * Defines the kind of navigation being performed.
196
- * - initial: the initial load's navigation
197
- * - server: a navigation initiated by a server round-trip
198
- * - local: a navigation initiated by `router.local`
199
- * - back-forward: a navigation initiated by the browser's `popstate` event
200
- * @internal
201
- */
202
- type: 'initial' | 'local' | 'back-forward' | 'server';
203
- /**
204
- * Defines whether this navigation opens a dialog.
205
- * @internal
206
- */
207
- hasDialog?: boolean;
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
- /** The URL to navigation. */
212
- url?: UrlResolvable;
213
- /** HTTP verb to use for the request. */
214
- method?: Method | Lowercase<Method>;
215
- /** Body of the request. */
216
- data?: RequestData;
217
- /** Which properties to update for this navigation. Other properties will be ignored. */
218
- only?: string | string[];
219
- /** Which properties not to update for this navigation. Other properties will be updated. */
220
- except?: string | string[];
221
- /** Specific headers to add to the request. */
222
- headers?: Record<string, string>;
223
- /** The bag in which to put potential errors. */
224
- errorBag?: string;
225
- /** Hooks for this navigation. */
226
- hooks?: Partial<RequestHooks>;
227
- /** If `true`, force the usage of a `FormData` object. */
228
- useFormData?: boolean;
229
- /**
230
- * If `false`, disable automatic form spoofing.
231
- * @see https://laravel.com/docs/master/routing#form-method-spoofing
232
- */
233
- spoof?: boolean;
234
- /**
235
- * If `false`, does not trigger the progress bar for this request.
236
- */
237
- progress?: boolean;
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
- response?: AxiosResponse;
241
- error?: {
242
- type: string;
243
- actual: Error;
244
- };
238
+ response?: AxiosResponse;
239
+ error?: {
240
+ type: string;
241
+ actual: Error;
242
+ };
245
243
  }
246
244
  interface DialogRouter {
247
- /** Closes the current dialog. */
248
- close: (options?: CloseDialogOptions) => void;
245
+ /** Closes the current dialog. */
246
+ close: (options?: CloseDialogOptions) => void;
249
247
  }
250
248
  interface Router {
251
- /** Aborts the currently pending navigate, if any. */
252
- abort: () => Promise<void>;
253
- /** Checks if there is an active navigate. */
254
- active: () => boolean;
255
- /** Makes a navigate with the given options. */
256
- navigate: (options: HybridRequestOptions) => Promise<NavigationResponse>;
257
- /** Reloads the current page. */
258
- reload: (options?: HybridRequestOptions) => Promise<NavigationResponse>;
259
- /** Makes a request to given named route. The HTTP verb is determined automatically but can be overriden. */
260
- to: <T extends RouteName>(name: T, parameters?: RouteParameters<T>, options?: Omit<HybridRequestOptions, 'url'>) => Promise<NavigationResponse>;
261
- /** Makes a GET request to the given URL. */
262
- get: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
263
- /** Makes a POST request to the given URL. */
264
- post: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
265
- /** Makes a PUT request to the given URL. */
266
- put: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
267
- /** Makes a PATCH request to the given URL. */
268
- patch: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
269
- /** Makes a DELETE request to the given URL. */
270
- delete: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<NavigationResponse>;
271
- /** Navigates to the given external URL. Convenience method using `document.location.href`. */
272
- external: (url: UrlResolvable, data?: HybridRequestOptions['data']) => void;
273
- /** Navigates to the given URL without a server round-trip. */
274
- local: (url: UrlResolvable, options: ComponentNavigationOptions) => Promise<void>;
275
- /** Preloads the given URL. The next time this URL is navigated to, it will be loaded from the cache. */
276
- preload: (url: UrlResolvable, options?: Omit<HybridRequestOptions, 'method' | 'url'>) => Promise<boolean>;
277
- /** Determines if the given route name and parameters matches the current route. */
278
- matches: <T extends RouteName>(name: T, parameters?: RouteParameters<T>) => boolean;
279
- /** Gets the current route name. Returns `undefined` is unknown. */
280
- current: () => RouteName | undefined;
281
- /** Access the dialog router. */
282
- dialog: DialogRouter;
283
- /** Access the history state. */
284
- history: {
285
- /** Remembers a value for the given route. */
286
- remember: (key: string, value: any) => void;
287
- /** Gets a remembered value. */
288
- get: <T = any>(key: string) => T | undefined;
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
- /** The URL to which the request is being made. */
294
- url: URL;
295
- /** Abort controller associated to this request. */
296
- controller: AbortController;
297
- /** Options for the associated hybrid request. */
298
- options: HybridRequestOptions;
299
- /** Navigation identifier. */
300
- id: string;
301
- /** Current status. */
302
- status: 'pending' | 'success' | 'error';
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
- /** Name of the component to use. */
307
- component?: string;
308
- /** Properties to apply to the component. */
309
- properties: Properties;
310
- /** Deferred properties for this view. */
311
- deferred: string[];
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
- /** URL that is the base background view when navigating to the dialog directly. */
315
- baseUrl: string;
316
- /** URL to which the dialog should redirect when closed. */
317
- redirectUrl: string;
318
- /** Unique identifier for this modal's lifecycle. */
319
- key: string;
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
- [name: string]: Property;
320
+ [name: string]: Property;
323
321
  };
324
322
  type Properties = Record<string | number, Property>;
325
323
  interface SwapOptions<T> {
326
- /** The new component. */
327
- component: T;
328
- /** The new properties. */
329
- properties?: any;
330
- /** Whether to preserve the state of the component. */
331
- preserveState?: boolean;
332
- /** Current dialog. */
333
- dialog?: Dialog;
334
- /** On mounted callback. */
335
- onMounted?: (options: MountedHookOptions) => void;
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
- /** The view to use in this request. */
343
- view: View;
344
- /** An optional dialog. */
345
- dialog?: Dialog;
346
- /** The current page URL. */
347
- url: string;
348
- /** The current asset version. */
349
- version: string;
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
- /** Base event. */
353
- event: AxiosProgressEvent;
354
- /** Computed percentage. */
355
- percentage: Readonly<number>;
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
- /** Identifier of the plugin. */
361
- name: string;
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
- /** 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;
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
- /** 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>;
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
- /** 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;
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
- updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
431
+ updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
432
432
  }
433
433
  interface ScrollRegion {
434
- top: number;
435
- left: number;
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
- serialize: <T>(view: T) => string;
440
- unserialize: <T>(state?: string) => T | undefined;
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
- authorization: Authorizations;
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
- versions: {
475
- composer: string;
476
- npm: string;
477
- latest: string;
478
- is_latest: boolean;
479
- };
480
- architecture: {
481
- root_directory: string;
482
- components_directory: string;
483
- application_main_path: string;
484
- };
485
- components: {
486
- eager?: boolean;
487
- files: string[];
488
- views: Component[];
489
- layouts: Component[];
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
- path: string;
496
- identifier: string;
497
- namespace: string;
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
- declare const constants_DIALOG_KEY_HEADER: typeof DIALOG_KEY_HEADER;
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 };