@hybridly/core 0.4.2 → 0.4.3

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