@hybridly/core 0.7.18 → 0.8.0
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 +7 -11
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +8 -12
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -77,7 +77,7 @@ async function runPluginHooks(hook, ...args) {
|
|
|
77
77
|
await forEachPlugin(async (plugin) => {
|
|
78
78
|
if (plugin[hook]) {
|
|
79
79
|
utils.debug.plugin(plugin.name, `Calling "${hook}" hook.`);
|
|
80
|
-
result
|
|
80
|
+
result &&= await plugin[hook]?.(...args) !== false;
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
return result;
|
|
@@ -404,7 +404,7 @@ function urlMatchesRoute(fullUrl, name, routeParameters) {
|
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
406
|
function generateRouteFromName(name, parameters, absolute, shouldThrow) {
|
|
407
|
-
const url = getUrlFromName(name, parameters
|
|
407
|
+
const url = getUrlFromName(name, parameters);
|
|
408
408
|
return absolute === false ? url.toString().replace(url.origin, "") : url.toString();
|
|
409
409
|
}
|
|
410
410
|
function getNameFromUrl(url, parameters) {
|
|
@@ -417,7 +417,7 @@ function getNameFromUrl(url, parameters) {
|
|
|
417
417
|
function getUrlFromName(name, parameters, shouldThrow) {
|
|
418
418
|
const routing = getRouting();
|
|
419
419
|
const definition = getRouteDefinition(name);
|
|
420
|
-
const transforms = getRouteTransformable(name, parameters
|
|
420
|
+
const transforms = getRouteTransformable(name, parameters);
|
|
421
421
|
const url = makeUrl(routing.url, (url2) => ({
|
|
422
422
|
hostname: definition.domain || url2.hostname,
|
|
423
423
|
port: routing.port?.toString() || url2.port,
|
|
@@ -465,9 +465,6 @@ function getRouteTransformable(routeName, routeParameters, shouldThrow) {
|
|
|
465
465
|
if (optional) {
|
|
466
466
|
return "";
|
|
467
467
|
}
|
|
468
|
-
if (shouldThrow === false) {
|
|
469
|
-
return "";
|
|
470
|
-
}
|
|
471
468
|
throw new MissingRouteParameter(parameterName, routeName);
|
|
472
469
|
};
|
|
473
470
|
const path = definition.uri.replace(/{([^}?]+)(\??)}/g, replaceParameter);
|
|
@@ -950,13 +947,12 @@ function isHybridResponse(response) {
|
|
|
950
947
|
return !!response?.headers[HYBRIDLY_HEADER];
|
|
951
948
|
}
|
|
952
949
|
async function navigate(options) {
|
|
953
|
-
var _a;
|
|
954
950
|
const context = getRouterContext();
|
|
955
|
-
options.hasDialog
|
|
951
|
+
options.hasDialog ??= !!options.payload?.dialog;
|
|
956
952
|
utils.debug.router("Making an internal navigation:", { context, options });
|
|
957
953
|
await runHooks("navigating", {}, options, context);
|
|
958
|
-
options.payload
|
|
959
|
-
|
|
954
|
+
options.payload ??= payloadFromContext();
|
|
955
|
+
options.payload.view ??= payloadFromContext().view;
|
|
960
956
|
function evaluateConditionalOption(option) {
|
|
961
957
|
return typeof option === "function" ? option(options) : option;
|
|
962
958
|
}
|
|
@@ -1089,7 +1085,7 @@ async function performLocalNavigation(targetUrl, options) {
|
|
|
1089
1085
|
url,
|
|
1090
1086
|
view: {
|
|
1091
1087
|
component: options?.component ?? context.view.component,
|
|
1092
|
-
properties: options?.properties ??
|
|
1088
|
+
properties: options?.properties ?? context.view.properties,
|
|
1093
1089
|
deferred: []
|
|
1094
1090
|
}
|
|
1095
1091
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -277,7 +277,7 @@ interface Router {
|
|
|
277
277
|
/** Determines if the given route name and parameters matches the current route. */
|
|
278
278
|
matches: <T extends RouteName>(name: T, parameters?: RouteParameters<T>) => boolean;
|
|
279
279
|
/** Gets the current route name. Returns `undefined` is unknown. */
|
|
280
|
-
current: () =>
|
|
280
|
+
current: () => RouteName | undefined;
|
|
281
281
|
/** Access the dialog router. */
|
|
282
282
|
dialog: DialogRouter;
|
|
283
283
|
/** Access the history state. */
|
package/dist/index.d.mts
CHANGED
|
@@ -277,7 +277,7 @@ interface Router {
|
|
|
277
277
|
/** Determines if the given route name and parameters matches the current route. */
|
|
278
278
|
matches: <T extends RouteName>(name: T, parameters?: RouteParameters<T>) => boolean;
|
|
279
279
|
/** Gets the current route name. Returns `undefined` is unknown. */
|
|
280
|
-
current: () =>
|
|
280
|
+
current: () => RouteName | undefined;
|
|
281
281
|
/** Access the dialog router. */
|
|
282
282
|
dialog: DialogRouter;
|
|
283
283
|
/** Access the history state. */
|
package/dist/index.d.ts
CHANGED
|
@@ -277,7 +277,7 @@ interface Router {
|
|
|
277
277
|
/** Determines if the given route name and parameters matches the current route. */
|
|
278
278
|
matches: <T extends RouteName>(name: T, parameters?: RouteParameters<T>) => boolean;
|
|
279
279
|
/** Gets the current route name. Returns `undefined` is unknown. */
|
|
280
|
-
current: () =>
|
|
280
|
+
current: () => RouteName | undefined;
|
|
281
281
|
/** Access the dialog router. */
|
|
282
282
|
dialog: DialogRouter;
|
|
283
283
|
/** Access the history state. */
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { debug, merge, removeTrailingSlash, debounce, random, hasFiles, objectToFormData, match, showResponseErrorModal, when } from '@hybridly/utils';
|
|
2
2
|
import qs from 'qs';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
-
import {
|
|
4
|
+
import { parse, stringify } from 'superjson';
|
|
5
5
|
|
|
6
6
|
const STORAGE_EXTERNAL_KEY = "hybridly:external";
|
|
7
7
|
const HYBRIDLY_HEADER = "x-hybrid";
|
|
@@ -70,7 +70,7 @@ async function runPluginHooks(hook, ...args) {
|
|
|
70
70
|
await forEachPlugin(async (plugin) => {
|
|
71
71
|
if (plugin[hook]) {
|
|
72
72
|
debug.plugin(plugin.name, `Calling "${hook}" hook.`);
|
|
73
|
-
result
|
|
73
|
+
result &&= await plugin[hook]?.(...args) !== false;
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
return result;
|
|
@@ -397,7 +397,7 @@ function urlMatchesRoute(fullUrl, name, routeParameters) {
|
|
|
397
397
|
});
|
|
398
398
|
}
|
|
399
399
|
function generateRouteFromName(name, parameters, absolute, shouldThrow) {
|
|
400
|
-
const url = getUrlFromName(name, parameters
|
|
400
|
+
const url = getUrlFromName(name, parameters);
|
|
401
401
|
return absolute === false ? url.toString().replace(url.origin, "") : url.toString();
|
|
402
402
|
}
|
|
403
403
|
function getNameFromUrl(url, parameters) {
|
|
@@ -410,7 +410,7 @@ function getNameFromUrl(url, parameters) {
|
|
|
410
410
|
function getUrlFromName(name, parameters, shouldThrow) {
|
|
411
411
|
const routing = getRouting();
|
|
412
412
|
const definition = getRouteDefinition(name);
|
|
413
|
-
const transforms = getRouteTransformable(name, parameters
|
|
413
|
+
const transforms = getRouteTransformable(name, parameters);
|
|
414
414
|
const url = makeUrl(routing.url, (url2) => ({
|
|
415
415
|
hostname: definition.domain || url2.hostname,
|
|
416
416
|
port: routing.port?.toString() || url2.port,
|
|
@@ -458,9 +458,6 @@ function getRouteTransformable(routeName, routeParameters, shouldThrow) {
|
|
|
458
458
|
if (optional) {
|
|
459
459
|
return "";
|
|
460
460
|
}
|
|
461
|
-
if (shouldThrow === false) {
|
|
462
|
-
return "";
|
|
463
|
-
}
|
|
464
461
|
throw new MissingRouteParameter(parameterName, routeName);
|
|
465
462
|
};
|
|
466
463
|
const path = definition.uri.replace(/{([^}?]+)(\??)}/g, replaceParameter);
|
|
@@ -943,13 +940,12 @@ function isHybridResponse(response) {
|
|
|
943
940
|
return !!response?.headers[HYBRIDLY_HEADER];
|
|
944
941
|
}
|
|
945
942
|
async function navigate(options) {
|
|
946
|
-
var _a;
|
|
947
943
|
const context = getRouterContext();
|
|
948
|
-
options.hasDialog
|
|
944
|
+
options.hasDialog ??= !!options.payload?.dialog;
|
|
949
945
|
debug.router("Making an internal navigation:", { context, options });
|
|
950
946
|
await runHooks("navigating", {}, options, context);
|
|
951
|
-
options.payload
|
|
952
|
-
|
|
947
|
+
options.payload ??= payloadFromContext();
|
|
948
|
+
options.payload.view ??= payloadFromContext().view;
|
|
953
949
|
function evaluateConditionalOption(option) {
|
|
954
950
|
return typeof option === "function" ? option(options) : option;
|
|
955
951
|
}
|
|
@@ -1082,7 +1078,7 @@ async function performLocalNavigation(targetUrl, options) {
|
|
|
1082
1078
|
url,
|
|
1083
1079
|
view: {
|
|
1084
1080
|
component: options?.component ?? context.view.component,
|
|
1085
|
-
properties: options?.properties ??
|
|
1081
|
+
properties: options?.properties ?? context.view.properties,
|
|
1086
1082
|
deferred: []
|
|
1087
1083
|
}
|
|
1088
1084
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "Core functionality of Hybridly",
|
|
6
6
|
"author": "Enzo Innocenzi <enzo@innocenzi.dev>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"axios": "^1.7.2"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"qs": "^6.
|
|
45
|
-
"superjson": "^2.2.
|
|
46
|
-
"@hybridly/utils": "0.
|
|
44
|
+
"qs": "^6.14.0",
|
|
45
|
+
"superjson": "^2.2.2",
|
|
46
|
+
"@hybridly/utils": "0.8.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"defu": "^6.1.4"
|