@hybridly/core 0.9.0 → 0.10.0-beta.10

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