@hybridly/core 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const qs = require('qs');
4
3
  const utils = require('@hybridly/utils');
4
+ const qs = require('qs');
5
5
  const axios = require('axios');
6
6
  const superjson = require('superjson');
7
7
 
@@ -524,6 +524,27 @@ function updateRoutingConfiguration(routing) {
524
524
  setContext({ routing });
525
525
  }
526
526
 
527
+ function isDownloadResponse(response) {
528
+ return response.status === 200 && !!response.headers["content-disposition"];
529
+ }
530
+ async function handleDownloadResponse(response) {
531
+ const blob = new Blob([response.data], { type: response.headers["content-type"] });
532
+ const urlObject = window.webkitURL || window.URL;
533
+ const link = document.createElement("a");
534
+ link.style.display = "none";
535
+ link.href = urlObject.createObjectURL(blob);
536
+ link.download = getFileNameFromContentDispositionHeader(response.headers["content-disposition"]);
537
+ link.click();
538
+ setTimeout(() => {
539
+ urlObject.revokeObjectURL(link.href);
540
+ link.remove();
541
+ }, 0);
542
+ }
543
+ function getFileNameFromContentDispositionHeader(header) {
544
+ const result = header.split(";")[1]?.trim().split("=")[1];
545
+ return result?.replace(/^"(.*)"$/, "$1") ?? "";
546
+ }
547
+
527
548
  const state = {
528
549
  initialized: false,
529
550
  context: {}
@@ -550,7 +571,7 @@ async function initializeContext(options) {
550
571
  },
551
572
  scrollRegions: [],
552
573
  plugins: options.plugins ?? [],
553
- axios: options.axios ?? axios__default.create(),
574
+ axios: registerAxios(options.axios ?? axios__default.create()),
554
575
  routing: options.routing,
555
576
  preloadCache: /* @__PURE__ */ new Map(),
556
577
  hooks: {},
@@ -559,6 +580,23 @@ async function initializeContext(options) {
559
580
  await runHooks("initialized", {}, state.context);
560
581
  return getInternalRouterContext();
561
582
  }
583
+ function registerAxios(axios2) {
584
+ axios2.interceptors.response.use(
585
+ (response) => {
586
+ if (!isDownloadResponse(response)) {
587
+ const text = new TextDecoder().decode(response.data);
588
+ try {
589
+ response.data = JSON.parse(text);
590
+ } catch {
591
+ response.data = text;
592
+ }
593
+ }
594
+ return response;
595
+ },
596
+ (error) => Promise.reject(error)
597
+ );
598
+ return axios2;
599
+ }
562
600
  function setContext(merge = {}, options = {}) {
563
601
  Object.keys(merge).forEach((key) => {
564
602
  Reflect.set(state.context, key, merge[key]);
@@ -644,27 +682,6 @@ async function closeDialog(options) {
644
682
  });
645
683
  }
646
684
 
647
- function isDownloadResponse(response) {
648
- return response.status === 200 && !!response.headers["content-disposition"];
649
- }
650
- async function handleDownloadResponse(response) {
651
- const blob = new Blob([response.data], { type: "application/octet-stream" });
652
- const urlObject = window.webkitURL || window.URL;
653
- const link = document.createElement("a");
654
- link.style.display = "none";
655
- link.href = urlObject.createObjectURL(blob);
656
- link.download = getFileNameFromContentDispositionHeader(response.headers["content-disposition"]);
657
- link.click();
658
- setTimeout(() => {
659
- urlObject.revokeObjectURL(link.href);
660
- link.remove();
661
- }, 0);
662
- }
663
- function getFileNameFromContentDispositionHeader(header) {
664
- const result = header.split(";")[1]?.trim().split("=")[1];
665
- return result?.replace(/^"(.*)"$/, "$1") ?? "";
666
- }
667
-
668
685
  function isPreloaded(targetUrl) {
669
686
  const context = getInternalRouterContext();
670
687
  return context.preloadCache.has(targetUrl.toString()) ?? false;
@@ -1005,6 +1022,7 @@ async function performHybridRequest(targetUrl, options, abortController) {
1005
1022
  "X-Requested-With": "XMLHttpRequest",
1006
1023
  "Accept": "text/html, application/xhtml+xml"
1007
1024
  },
1025
+ responseType: "arraybuffer",
1008
1026
  validateStatus: () => true,
1009
1027
  onUploadProgress: async (event) => {
1010
1028
  await runHooks("progress", options.hooks, {
package/dist/index.d.cts CHANGED
@@ -90,12 +90,6 @@ interface HookOptions {
90
90
  */
91
91
  declare function registerHook<T extends keyof Hooks>(hook: T, fn: Hooks[T], options?: HookOptions): () => void;
92
92
 
93
- interface Plugin extends Partial<Hooks> {
94
- /** Identifier of the plugin. */
95
- name: string;
96
- }
97
- declare function definePlugin(plugin: Plugin): Plugin;
98
-
99
93
  interface CloseDialogOptions extends HybridRequestOptions {
100
94
  /**
101
95
  * Close the dialog without a round-trip to the server.
@@ -104,6 +98,25 @@ interface CloseDialogOptions extends HybridRequestOptions {
104
98
  local?: boolean;
105
99
  }
106
100
 
101
+ interface RoutingConfiguration {
102
+ url: string;
103
+ port?: number;
104
+ defaults: Record<string, any>;
105
+ routes: Record<string, RouteDefinition>;
106
+ }
107
+ interface RouteDefinition {
108
+ uri: string;
109
+ method: Method[];
110
+ bindings: Record<string, string>;
111
+ domain?: string;
112
+ wheres?: Record<string, string>;
113
+ name: string;
114
+ }
115
+ interface GlobalRouteCollection extends RoutingConfiguration {
116
+ }
117
+ type RouteName = keyof GlobalRouteCollection['routes'];
118
+ type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
119
+
107
120
  type UrlResolvable = string | URL | Location;
108
121
  type UrlTransformable = BaseUrlTransformable | ((string: URL) => BaseUrlTransformable);
109
122
  type BaseUrlTransformable = Partial<Omit<URL, 'searchParams' | 'toJSON' | 'toString'>> & {
@@ -333,24 +346,11 @@ interface Progress {
333
346
  }
334
347
  type Errors = any;
335
348
 
336
- interface RoutingConfiguration {
337
- url: string;
338
- port?: number;
339
- defaults: Record<string, any>;
340
- routes: Record<string, RouteDefinition>;
341
- }
342
- interface RouteDefinition {
343
- uri: string;
344
- method: Method[];
345
- bindings: Record<string, string>;
346
- domain?: string;
347
- wheres?: Record<string, string>;
349
+ interface Plugin extends Partial<Hooks> {
350
+ /** Identifier of the plugin. */
348
351
  name: string;
349
352
  }
350
- interface GlobalRouteCollection extends RoutingConfiguration {
351
- }
352
- type RouteName = keyof GlobalRouteCollection['routes'];
353
- type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
353
+ declare function definePlugin(plugin: Plugin): Plugin;
354
354
 
355
355
  /** Options for creating a router context. */
356
356
  interface RouterContextOptions {
@@ -474,7 +474,7 @@ interface DynamicConfiguration {
474
474
  };
475
475
  components: {
476
476
  eager?: boolean;
477
- directories: string[];
477
+ files: string[];
478
478
  views: Component[];
479
479
  layouts: Component[];
480
480
  components: Component[];
package/dist/index.d.mts CHANGED
@@ -90,12 +90,6 @@ interface HookOptions {
90
90
  */
91
91
  declare function registerHook<T extends keyof Hooks>(hook: T, fn: Hooks[T], options?: HookOptions): () => void;
92
92
 
93
- interface Plugin extends Partial<Hooks> {
94
- /** Identifier of the plugin. */
95
- name: string;
96
- }
97
- declare function definePlugin(plugin: Plugin): Plugin;
98
-
99
93
  interface CloseDialogOptions extends HybridRequestOptions {
100
94
  /**
101
95
  * Close the dialog without a round-trip to the server.
@@ -104,6 +98,25 @@ interface CloseDialogOptions extends HybridRequestOptions {
104
98
  local?: boolean;
105
99
  }
106
100
 
101
+ interface RoutingConfiguration {
102
+ url: string;
103
+ port?: number;
104
+ defaults: Record<string, any>;
105
+ routes: Record<string, RouteDefinition>;
106
+ }
107
+ interface RouteDefinition {
108
+ uri: string;
109
+ method: Method[];
110
+ bindings: Record<string, string>;
111
+ domain?: string;
112
+ wheres?: Record<string, string>;
113
+ name: string;
114
+ }
115
+ interface GlobalRouteCollection extends RoutingConfiguration {
116
+ }
117
+ type RouteName = keyof GlobalRouteCollection['routes'];
118
+ type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
119
+
107
120
  type UrlResolvable = string | URL | Location;
108
121
  type UrlTransformable = BaseUrlTransformable | ((string: URL) => BaseUrlTransformable);
109
122
  type BaseUrlTransformable = Partial<Omit<URL, 'searchParams' | 'toJSON' | 'toString'>> & {
@@ -333,24 +346,11 @@ interface Progress {
333
346
  }
334
347
  type Errors = any;
335
348
 
336
- interface RoutingConfiguration {
337
- url: string;
338
- port?: number;
339
- defaults: Record<string, any>;
340
- routes: Record<string, RouteDefinition>;
341
- }
342
- interface RouteDefinition {
343
- uri: string;
344
- method: Method[];
345
- bindings: Record<string, string>;
346
- domain?: string;
347
- wheres?: Record<string, string>;
349
+ interface Plugin extends Partial<Hooks> {
350
+ /** Identifier of the plugin. */
348
351
  name: string;
349
352
  }
350
- interface GlobalRouteCollection extends RoutingConfiguration {
351
- }
352
- type RouteName = keyof GlobalRouteCollection['routes'];
353
- type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
353
+ declare function definePlugin(plugin: Plugin): Plugin;
354
354
 
355
355
  /** Options for creating a router context. */
356
356
  interface RouterContextOptions {
@@ -474,7 +474,7 @@ interface DynamicConfiguration {
474
474
  };
475
475
  components: {
476
476
  eager?: boolean;
477
- directories: string[];
477
+ files: string[];
478
478
  views: Component[];
479
479
  layouts: Component[];
480
480
  components: Component[];
package/dist/index.d.ts CHANGED
@@ -90,12 +90,6 @@ interface HookOptions {
90
90
  */
91
91
  declare function registerHook<T extends keyof Hooks>(hook: T, fn: Hooks[T], options?: HookOptions): () => void;
92
92
 
93
- interface Plugin extends Partial<Hooks> {
94
- /** Identifier of the plugin. */
95
- name: string;
96
- }
97
- declare function definePlugin(plugin: Plugin): Plugin;
98
-
99
93
  interface CloseDialogOptions extends HybridRequestOptions {
100
94
  /**
101
95
  * Close the dialog without a round-trip to the server.
@@ -104,6 +98,25 @@ interface CloseDialogOptions extends HybridRequestOptions {
104
98
  local?: boolean;
105
99
  }
106
100
 
101
+ interface RoutingConfiguration {
102
+ url: string;
103
+ port?: number;
104
+ defaults: Record<string, any>;
105
+ routes: Record<string, RouteDefinition>;
106
+ }
107
+ interface RouteDefinition {
108
+ uri: string;
109
+ method: Method[];
110
+ bindings: Record<string, string>;
111
+ domain?: string;
112
+ wheres?: Record<string, string>;
113
+ name: string;
114
+ }
115
+ interface GlobalRouteCollection extends RoutingConfiguration {
116
+ }
117
+ type RouteName = keyof GlobalRouteCollection['routes'];
118
+ type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
119
+
107
120
  type UrlResolvable = string | URL | Location;
108
121
  type UrlTransformable = BaseUrlTransformable | ((string: URL) => BaseUrlTransformable);
109
122
  type BaseUrlTransformable = Partial<Omit<URL, 'searchParams' | 'toJSON' | 'toString'>> & {
@@ -333,24 +346,11 @@ interface Progress {
333
346
  }
334
347
  type Errors = any;
335
348
 
336
- interface RoutingConfiguration {
337
- url: string;
338
- port?: number;
339
- defaults: Record<string, any>;
340
- routes: Record<string, RouteDefinition>;
341
- }
342
- interface RouteDefinition {
343
- uri: string;
344
- method: Method[];
345
- bindings: Record<string, string>;
346
- domain?: string;
347
- wheres?: Record<string, string>;
349
+ interface Plugin extends Partial<Hooks> {
350
+ /** Identifier of the plugin. */
348
351
  name: string;
349
352
  }
350
- interface GlobalRouteCollection extends RoutingConfiguration {
351
- }
352
- type RouteName = keyof GlobalRouteCollection['routes'];
353
- type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteCollection['routes'][T]['bindings'], any> & Record<string, any>;
353
+ declare function definePlugin(plugin: Plugin): Plugin;
354
354
 
355
355
  /** Options for creating a router context. */
356
356
  interface RouterContextOptions {
@@ -474,7 +474,7 @@ interface DynamicConfiguration {
474
474
  };
475
475
  components: {
476
476
  eager?: boolean;
477
- directories: string[];
477
+ files: string[];
478
478
  views: Component[];
479
479
  layouts: Component[];
480
480
  components: Component[];
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import qs from 'qs';
2
1
  import { debug, merge, removeTrailingSlash, debounce, random, hasFiles, objectToFormData, match, showResponseErrorModal, when } from '@hybridly/utils';
2
+ import qs from 'qs';
3
3
  import axios from 'axios';
4
4
  import { stringify, parse } from 'superjson';
5
5
 
@@ -517,6 +517,27 @@ function updateRoutingConfiguration(routing) {
517
517
  setContext({ routing });
518
518
  }
519
519
 
520
+ function isDownloadResponse(response) {
521
+ return response.status === 200 && !!response.headers["content-disposition"];
522
+ }
523
+ async function handleDownloadResponse(response) {
524
+ const blob = new Blob([response.data], { type: response.headers["content-type"] });
525
+ const urlObject = window.webkitURL || window.URL;
526
+ const link = document.createElement("a");
527
+ link.style.display = "none";
528
+ link.href = urlObject.createObjectURL(blob);
529
+ link.download = getFileNameFromContentDispositionHeader(response.headers["content-disposition"]);
530
+ link.click();
531
+ setTimeout(() => {
532
+ urlObject.revokeObjectURL(link.href);
533
+ link.remove();
534
+ }, 0);
535
+ }
536
+ function getFileNameFromContentDispositionHeader(header) {
537
+ const result = header.split(";")[1]?.trim().split("=")[1];
538
+ return result?.replace(/^"(.*)"$/, "$1") ?? "";
539
+ }
540
+
520
541
  const state = {
521
542
  initialized: false,
522
543
  context: {}
@@ -543,7 +564,7 @@ async function initializeContext(options) {
543
564
  },
544
565
  scrollRegions: [],
545
566
  plugins: options.plugins ?? [],
546
- axios: options.axios ?? axios.create(),
567
+ axios: registerAxios(options.axios ?? axios.create()),
547
568
  routing: options.routing,
548
569
  preloadCache: /* @__PURE__ */ new Map(),
549
570
  hooks: {},
@@ -552,6 +573,23 @@ async function initializeContext(options) {
552
573
  await runHooks("initialized", {}, state.context);
553
574
  return getInternalRouterContext();
554
575
  }
576
+ function registerAxios(axios2) {
577
+ axios2.interceptors.response.use(
578
+ (response) => {
579
+ if (!isDownloadResponse(response)) {
580
+ const text = new TextDecoder().decode(response.data);
581
+ try {
582
+ response.data = JSON.parse(text);
583
+ } catch {
584
+ response.data = text;
585
+ }
586
+ }
587
+ return response;
588
+ },
589
+ (error) => Promise.reject(error)
590
+ );
591
+ return axios2;
592
+ }
555
593
  function setContext(merge = {}, options = {}) {
556
594
  Object.keys(merge).forEach((key) => {
557
595
  Reflect.set(state.context, key, merge[key]);
@@ -637,27 +675,6 @@ async function closeDialog(options) {
637
675
  });
638
676
  }
639
677
 
640
- function isDownloadResponse(response) {
641
- return response.status === 200 && !!response.headers["content-disposition"];
642
- }
643
- async function handleDownloadResponse(response) {
644
- const blob = new Blob([response.data], { type: "application/octet-stream" });
645
- const urlObject = window.webkitURL || window.URL;
646
- const link = document.createElement("a");
647
- link.style.display = "none";
648
- link.href = urlObject.createObjectURL(blob);
649
- link.download = getFileNameFromContentDispositionHeader(response.headers["content-disposition"]);
650
- link.click();
651
- setTimeout(() => {
652
- urlObject.revokeObjectURL(link.href);
653
- link.remove();
654
- }, 0);
655
- }
656
- function getFileNameFromContentDispositionHeader(header) {
657
- const result = header.split(";")[1]?.trim().split("=")[1];
658
- return result?.replace(/^"(.*)"$/, "$1") ?? "";
659
- }
660
-
661
678
  function isPreloaded(targetUrl) {
662
679
  const context = getInternalRouterContext();
663
680
  return context.preloadCache.has(targetUrl.toString()) ?? false;
@@ -998,6 +1015,7 @@ async function performHybridRequest(targetUrl, options, abortController) {
998
1015
  "X-Requested-With": "XMLHttpRequest",
999
1016
  "Accept": "text/html, application/xhtml+xml"
1000
1017
  },
1018
+ responseType: "arraybuffer",
1001
1019
  validateStatus: () => true,
1002
1020
  onUploadProgress: async (event) => {
1003
1021
  await runHooks("progress", options.hooks, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "Core functionality of Hybridly",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -18,6 +18,10 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/hybridly/hybridly/issues"
20
20
  },
21
+ "publishConfig": {
22
+ "provenance": true,
23
+ "access": "public"
24
+ },
21
25
  "sideEffects": false,
22
26
  "files": [
23
27
  "dist",
@@ -34,15 +38,15 @@
34
38
  "module": "dist/index.mjs",
35
39
  "types": "dist/index.d.ts",
36
40
  "peerDependencies": {
37
- "axios": "^1.6.2"
41
+ "axios": "^1.6.7"
38
42
  },
39
43
  "dependencies": {
40
- "qs": "^6.11.2",
44
+ "qs": "^6.12.0",
41
45
  "superjson": "^2.2.1",
42
- "@hybridly/utils": "0.6.1"
46
+ "@hybridly/utils": "0.7.1"
43
47
  },
44
48
  "devDependencies": {
45
- "defu": "^6.1.3"
49
+ "defu": "^6.1.4"
46
50
  },
47
51
  "scripts": {
48
52
  "build": "unbuild",