@arc-js/core 0.0.12 → 0.0.20

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/auto-rooting.jsx CHANGED
@@ -1,33 +1,29 @@
1
- import { j as jsxRuntimeExports } from './_virtual/jsx-runtime';
2
- import * as routesUtils_js from './routes-utils.js';
3
- import { routes } from './routes-utils.js';
4
- export { useRootingActions } from './rooting.hooks.jsx';
1
+ import * as autoRoutes from './routes-utils';
2
+ import { useRootingActions } from './rooting.hooks';
3
+ import React from "react";
5
4
 
6
- var autoRooting = () => {
7
- let routes$1 = routes.map((route) => ({
8
- path: route.path,
9
- element: route.layout ? (jsxRuntimeExports.jsx(route.layout, { children: jsxRuntimeExports.jsx(route.component, {}) })) : (jsxRuntimeExports.jsx(route.component, {})),
10
- ...(!!route.error ? {
11
- errorElement: jsxRuntimeExports.jsx(route.error, {}),
12
- } : {}),
13
- }));
14
- let homeRoute = undefined;
15
- let notFoundRoute = undefined;
16
- homeRoute = routes$1.find((a) => a.path === '/');
17
- notFoundRoute = routes$1.find((a) => a.path === '*');
18
- routes$1 = [
19
- ...(!!homeRoute ? [homeRoute] : []),
20
- ...routes$1.filter((route) => !(!!route.path &&
21
- ['/', '*'].includes(route.path))),
22
- ...(!!notFoundRoute ? [notFoundRoute] : []),
23
- ].filter((route) => (!!route.path && (route.path.indexOf('/_404') === -1 &&
24
- route.path.indexOf('/_layout') === -1)));
25
- if (process.env?.NODE_ENV === 'development') {
26
- console.log(`[router -> routes.tsx] notFoundRoute:: `, notFoundRoute);
27
- console.log(`[router -> routes.tsx] autoRoutes:: `, routesUtils_js);
28
- console.log(`[router -> routes.tsx] routes:: `, routes$1);
29
- }
30
- return routes$1;
5
+ /**
6
+ * Permet d'initialiser toutes les routes de l'application
7
+ * @returns RouteObject[]
8
+ */
9
+ export default () => {
10
+ let routes = autoRoutes.routes.map(route => ({
11
+ path: route.path,
12
+ element: route.layout ? /*#__PURE__*/React.createElement(route.layout, null, /*#__PURE__*/React.createElement(route.component, null)) : /*#__PURE__*/React.createElement(route.component, null),
13
+ ...(!!route.error ? {
14
+ errorElement: /*#__PURE__*/React.createElement(route.error, null)
15
+ } : {})
16
+ }));
17
+ let homeRoute = undefined;
18
+ let notFoundRoute = undefined;
19
+ homeRoute = routes.find(a => a.path === '/');
20
+ notFoundRoute = routes.find(a => a.path === '*');
21
+ routes = [...(!!homeRoute ? [homeRoute] : []), ...routes.filter(route => !(!!route.path && ['/', '*'].includes(route.path))), ...(!!notFoundRoute ? [notFoundRoute] : [])].filter(route => !!route.path && route.path.indexOf('/_404') === -1 && route.path.indexOf('/_layout') === -1);
22
+ if (process.env?.NODE_ENV === 'development') {
23
+ console.log(`[router -> routes.tsx] notFoundRoute:: `, notFoundRoute);
24
+ console.log(`[router -> routes.tsx] autoRoutes:: `, autoRoutes);
25
+ console.log(`[router -> routes.tsx] routes:: `, routes);
26
+ }
27
+ return routes;
31
28
  };
32
-
33
- export { autoRooting as default };
29
+ export { useRootingActions };
package/config.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ declare const NODEENV: 'development' | 'production' | 'debug';
2
+ declare const langs: string[];
3
+ declare const langCodes: {
4
+ fr: string;
5
+ en: string;
6
+ };
7
+
8
+ export { NODEENV, langCodes, langs };
package/config.js ADDED
@@ -0,0 +1,8 @@
1
+ const NODEENV = 'development';
2
+ const langs = ['en', 'fr'];
3
+ const langCodes = {
4
+ 'fr': 'fr_FR',
5
+ 'en': 'en_US',
6
+ };
7
+
8
+ export { NODEENV, langCodes, langs };
package/config.min.js ADDED
@@ -0,0 +1,2 @@
1
+ let NODEENV="development",langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"};export{NODEENV,langCodes,langs};
2
+ //# sourceMappingURL=config.min.js.map
@@ -1,5 +1,28 @@
1
- import { ConfigDefinition, RouteDefinition, ConfigDatasDefinition } from './types.js';
2
- import 'react';
1
+ import { ReactNode } from 'react';
2
+
3
+ interface RouteDefinition {
4
+ truePath: string;
5
+ pathParent?: string;
6
+ path: string;
7
+ component: React.ComponentType<any>;
8
+ layout?: React.ComponentType<{
9
+ children: ReactNode;
10
+ }>;
11
+ error?: React.ComponentType<{}>;
12
+ }
13
+ interface ConfigDefinition {
14
+ parentTruePath: string;
15
+ truePath: string;
16
+ path: string;
17
+ name: string | undefined;
18
+ config: ConfigDatasDefinition;
19
+ }
20
+ interface ConfigDatasDefinition {
21
+ path: string;
22
+ name: string | undefined;
23
+ author: string | undefined;
24
+ isEnabled: boolean;
25
+ }
3
26
 
4
27
  declare const configModules: any;
5
28
  declare function cleanPathConfig(filePath: string): string;
package/minimal-config.js CHANGED
@@ -1,3 +1,22 @@
1
+
2
+
3
+
4
+
5
+ function __awaiter(thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ }
14
+
15
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
16
+ var e = new Error(message);
17
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
18
+ };
19
+
1
20
  const configModules = import.meta.glob([
2
21
  '/src/config.json',
3
22
  '/src/modules/**/config.json'
@@ -16,51 +35,54 @@ function filePathToConfigPath(filePath, isParent = false) {
16
35
  subPath.length > 0)).join('/');
17
36
  return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
18
37
  }
19
- async function getAllConfig() {
20
- let configs = await Promise.all(Object.entries(configModules).map(async ([filePath, module]) => {
21
- const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
22
- const configPath = filePathToConfigPath(filePath);
23
- let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
24
- nameConfig = (typeof nameConfig === 'string' &&
25
- nameConfig.length > 0) ? nameConfig : undefined;
26
- let config = (await module()).default;
27
- config = (typeof config === 'object' &&
28
- !Array.isArray(config) &&
29
- Object.keys(config).length > 0) ? {
30
- path: ((typeof config?.path === 'string' &&
31
- config?.path.length > 0) ? config?.path : configPath),
32
- name: ((typeof config?.name === 'string' &&
33
- config?.name.length > 0) ? config?.name : nameConfig),
34
- description: ((typeof config?.description === 'string' &&
35
- config?.description.length > 0) ? config?.description : undefined),
36
- author: ((typeof config?.author === 'string' &&
37
- config?.author.length > 0) ? config?.author : undefined),
38
- isEnabled: ((typeof config?.isEnabled === 'boolean') ? config?.isEnabled : true),
39
- } : {
40
- path: configPath,
41
- name: nameConfig,
42
- author: undefined,
43
- isEnabled: true,
44
- };
45
- return {
46
- parentTruePath,
47
- truePath: filePath,
48
- path: configPath,
49
- name: nameConfig,
50
- description: undefined,
51
- config,
52
- };
53
- }));
54
- return configs;
38
+ function getAllConfig() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
41
+ const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
42
+ const configPath = filePathToConfigPath(filePath);
43
+ let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
44
+ nameConfig = (typeof nameConfig === 'string' &&
45
+ nameConfig.length > 0) ? nameConfig : undefined;
46
+ let config = (yield module()).default;
47
+ config = (typeof config === 'object' &&
48
+ !Array.isArray(config) &&
49
+ Object.keys(config).length > 0) ? {
50
+ path: ((typeof (config === null || config === void 0 ? void 0 : config.path) === 'string' &&
51
+ (config === null || config === void 0 ? void 0 : config.path.length) > 0) ? config === null || config === void 0 ? void 0 : config.path : configPath),
52
+ name: ((typeof (config === null || config === void 0 ? void 0 : config.name) === 'string' &&
53
+ (config === null || config === void 0 ? void 0 : config.name.length) > 0) ? config === null || config === void 0 ? void 0 : config.name : nameConfig),
54
+ description: ((typeof (config === null || config === void 0 ? void 0 : config.description) === 'string' &&
55
+ (config === null || config === void 0 ? void 0 : config.description.length) > 0) ? config === null || config === void 0 ? void 0 : config.description : undefined),
56
+ author: ((typeof (config === null || config === void 0 ? void 0 : config.author) === 'string' &&
57
+ (config === null || config === void 0 ? void 0 : config.author.length) > 0) ? config === null || config === void 0 ? void 0 : config.author : undefined),
58
+ isEnabled: ((typeof (config === null || config === void 0 ? void 0 : config.isEnabled) === 'boolean') ? config === null || config === void 0 ? void 0 : config.isEnabled : true),
59
+ } : {
60
+ path: configPath,
61
+ name: nameConfig,
62
+ author: undefined,
63
+ isEnabled: true,
64
+ };
65
+ return {
66
+ parentTruePath,
67
+ truePath: filePath,
68
+ path: configPath,
69
+ name: nameConfig,
70
+ description: undefined,
71
+ config,
72
+ };
73
+ })));
74
+ return configs;
75
+ });
55
76
  }
56
77
  function findConfigModuleRoute(route, configDatas) {
57
- const res = configDatas.sort((a, b) => {
78
+ var _a;
79
+ const res = (_a = configDatas.sort((a, b) => {
58
80
  if (a.truePath.split('/').length > b.truePath.split('/').length)
59
81
  return -1;
60
82
  if (a.truePath.split('/').length < b.truePath.split('/').length)
61
83
  return 1;
62
84
  return 0;
63
- }).find((config) => (route.truePath.indexOf(config.parentTruePath) === 0))?.config;
85
+ }).find((config) => (route.truePath.indexOf(config.parentTruePath) === 0))) === null || _a === void 0 ? void 0 : _a.config;
64
86
  return res;
65
87
  }
66
88
 
@@ -1,2 +1,2 @@
1
- let configModules=import.meta.glob(["/src/config.json","/src/modules/**/config.json"]);function cleanPathConfig(t){return t.replace(/^\/src/,"").replace(/^\/src\/modules\//,"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(t,e=!1){let n=(e="boolean"==typeof e&&e)?t.replace(/config\.json$/,""):cleanPathConfig(t);return(n=n.split("/").filter(t=>"string"==typeof t&&0<t.length).join("/")).startsWith("/")?n:("/"+n).split("//").join("/")}async function getAllConfig(){return await Promise.all(Object.entries(configModules).map(async([t,e])=>{var n=filePathToConfigPath(t,!0).split("/").join("/"),o=filePathToConfigPath(t),i="string"==typeof(i=o.split("/").filter((t,e,n)=>0<e).join("/"))&&0<i.length?i:void 0,e=(await e()).default;return{parentTruePath:n,truePath:t,path:o,name:i,description:void 0,config:"object"==typeof e&&!Array.isArray(e)&&0<Object.keys(e).length?{path:"string"==typeof e?.path&&0<e?.path.length?e?.path:o,name:"string"==typeof e?.name&&0<e?.name.length?e?.name:i,description:"string"==typeof e?.description&&0<e?.description.length?e?.description:void 0,author:"string"==typeof e?.author&&0<e?.author.length?e?.author:void 0,isEnabled:"boolean"!=typeof e?.isEnabled||e?.isEnabled}:{path:o,name:i,author:void 0,isEnabled:!0}}}))}function findConfigModuleRoute(e,t){return t.sort((t,e)=>t.truePath.split("/").length>e.truePath.split("/").length?-1:t.truePath.split("/").length<e.truePath.split("/").length?1:0).find(t=>0===e.truePath.indexOf(t.parentTruePath))?.config}export{cleanPathConfig,configModules,filePathToConfigPath,findConfigModuleRoute,getAllConfig};
1
+ function __awaiter(t,a,r,u){return new(r=r||Promise)(function(e,n){function i(t){try{l(u.next(t))}catch(t){n(t)}}function o(t){try{l(u.throw(t))}catch(t){n(t)}}function l(t){var n;t.done?e(t.value):((n=t.value)instanceof r?n:new r(function(t){t(n)})).then(i,o)}l((u=u.apply(t,a||[])).next())})}let configModules=import.meta.glob(["/src/config.json","/src/modules/**/config.json"]);function cleanPathConfig(t){return t.replace(/^\/src/,"").replace(/^\/src\/modules\//,"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(t,n=!1){let e=(n="boolean"==typeof n&&n)?t.replace(/config\.json$/,""):cleanPathConfig(t);return(e=e.split("/").filter(t=>"string"==typeof t&&0<t.length).join("/")).startsWith("/")?e:("/"+e).split("//").join("/")}function getAllConfig(){return __awaiter(this,void 0,void 0,function*(){return yield Promise.all(Object.entries(configModules).map(t=>__awaiter(this,[t],void 0,function*([t,n]){var e=filePathToConfigPath(t,!0).split("/").join("/"),i=filePathToConfigPath(t),o="string"==typeof(o=i.split("/").filter((t,n,e)=>0<n).join("/"))&&0<o.length?o:void 0,n=(yield n()).default;return{parentTruePath:e,truePath:t,path:i,name:o,description:void 0,config:"object"==typeof n&&!Array.isArray(n)&&0<Object.keys(n).length?{path:"string"==typeof(null==n?void 0:n.path)&&0<(null==n?void 0:n.path.length)?null==n?void 0:n.path:i,name:"string"==typeof(null==n?void 0:n.name)&&0<(null==n?void 0:n.name.length)?null==n?void 0:n.name:o,description:!("string"==typeof(null==n?void 0:n.description)&&0<(null==n?void 0:n.description.length))||null==n?void 0:n.description,author:!("string"==typeof(null==n?void 0:n.author)&&0<(null==n?void 0:n.author.length))||null==n?void 0:n.author,isEnabled:"boolean"!=typeof(null==n?void 0:n.isEnabled)||(null==n?void 0:n.isEnabled)}:{path:i,name:o,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(n,t){return null==(t=t.sort((t,n)=>t.truePath.split("/").length>n.truePath.split("/").length?-1:t.truePath.split("/").length<n.truePath.split("/").length?1:0).find(t=>0===n.truePath.indexOf(t.parentTruePath)))?void 0:t.config}export{cleanPathConfig,configModules,filePathToConfigPath,findConfigModuleRoute,getAllConfig};
2
2
  //# sourceMappingURL=minimal-config.min.js.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.12",
6
+ "version": "0.0.20",
7
7
  "description": "CORE est un module de routage intelligent et auto-configuré pour les applications React avec TypeScript/Javascript. Il fournit un système de routage basé sur la structure de fichiers, des hooks de navigation avancés et une configuration minimale pour les applications modulaires.",
8
8
  "main": "index.js",
9
9
  "keywords": [],
package/rooting.hooks.jsx CHANGED
@@ -1,205 +1,279 @@
1
- import { r as reactExports } from './_virtual/index';
2
- import { d as distExports } from './_virtual/index2';
3
- import { getLang } from './src/utils';
4
- import qust from './node_modules/@arc-js/qust/index';
1
+ import { useEffect } from 'react';
2
+ import { useLocation, useNavigate, useParams, generatePath, createSearchParams, matchPath } from 'react-router-dom';
3
+ import { getLang } from './utils';
4
+ import { qust } from '@arc-js/qust';
5
+ import React from "react";
5
6
 
7
+
8
+ /**
9
+ * Interface du paramètre de configuration de la fonction "goAndReloadRoute" .
10
+ */
11
+
12
+ ;
13
+
14
+ /**
15
+ * Cette fonction permet de recuperer tous les parameters de l'url
16
+ */
6
17
  function getParams() {
7
- const queryString = window.location.search;
8
- const urlParams = new URLSearchParams(queryString);
9
- return urlParams;
18
+ const queryString = window.location.search;
19
+ const urlParams = new URLSearchParams(queryString);
20
+ return urlParams;
10
21
  }
11
- function nativeResolveRoute(config, incorrectUrl = "") {
12
- try {
13
- const params = (typeof config?.params === 'object' &&
14
- Array.isArray(config?.params) === false) ? config?.params : {};
15
- const queries = (typeof config?.queries === 'object' &&
16
- Array.isArray(config?.queries) === false) ? config?.queries : {};
17
- const path = (typeof config?.path === 'string') ? config?.path : incorrectUrl;
18
- if (!config?.queries) {
19
- config.queries = {};
20
- }
21
- let lang = getLang(config?.queries?.lang);
22
- if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
23
- lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
24
- }
25
- config.queries = {
26
- ...config.queries,
27
- lang,
28
- };
29
- let res = distExports.generatePath(path, params);
30
- if (Object.keys(queries).length > 0) {
31
- res = `${res}?${distExports.createSearchParams(queries)}`;
32
- }
33
- return res;
34
- }
35
- catch (error) {
36
- if (process.env?.NODE_ENV === 'development') {
37
- console.log(error);
38
- }
39
- return incorrectUrl;
22
+ ;
23
+ /**
24
+ * Interface du paramètre de configuration de la fonction "goAndReloadRoute" .
25
+ */
26
+
27
+ ;
28
+ /**
29
+ * Interface du paramètre de configuration de la fonction "resolveRoute" .
30
+ */
31
+
32
+ ;
33
+ /**
34
+ * Interface du paramètre de configuration de la fonction "goToRoute" .
35
+ */
36
+
37
+ ;
38
+ /**
39
+ * Interface de retour du hooks "useRootingActions".
40
+ */
41
+
42
+ /**
43
+ * Cette fonction permet de recuperer une route en fonction de son path, ses paramètres et ses query parameters.
44
+ * @param config - la donnée de la route à ressortir
45
+ * @param incorrectUrl - la route qui sera prise en compte si le path n'existe pas
46
+ * @returns string
47
+ */
48
+ export function nativeResolveRoute(config, incorrectUrl = "") {
49
+ try {
50
+ const params = typeof config?.params === 'object' && Array.isArray(config?.params) === false ? config?.params : {};
51
+ const queries = typeof config?.queries === 'object' && Array.isArray(config?.queries) === false ? config?.queries : {};
52
+ const path = typeof config?.path === 'string' ? config?.path : incorrectUrl;
53
+ if (!config?.queries) {
54
+ config.queries = {};
40
55
  }
41
- }
42
- const useRootingActions = () => {
43
- const location = distExports.useLocation();
44
- const pathname = location.pathname;
45
- const params = distExports.useParams();
46
- const pathName = distExports.useLocation().pathname;
47
- const urlSearch = distExports.useLocation().search;
48
- const paramsData = new URLSearchParams(distExports.useLocation().search);
49
- let queries = {};
50
- for (const key of paramsData.keys()) {
51
- const valueParamsData = (paramsData.getAll(key).length === 1) ? paramsData.getAll(key)[0] : paramsData.getAll(key);
52
- queries = {
53
- ...queries,
54
- [key]: valueParamsData,
55
- };
56
+ let lang = getLang(config?.queries?.lang);
57
+ if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
58
+ lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
56
59
  }
57
- const navigate = distExports.useNavigate();
58
- const resolveRoute = (config) => {
59
- const incorrectUrl = pathName;
60
- return nativeResolveRoute(config, incorrectUrl);
60
+ config.queries = {
61
+ ...config.queries,
62
+ lang
61
63
  };
62
- const goToRoute = (config, loaderHandler = () => { }) => {
63
- loaderHandler = !!loaderHandler ? loaderHandler : () => { };
64
- if (!config?.queries) {
65
- config.queries = {};
66
- }
67
- let lang = getLang(config?.queries?.lang);
68
- if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
69
- lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
70
- }
71
- config.queries = {
72
- ...config.queries,
73
- lang,
74
- };
75
- config.queries = Object.fromEntries(Object.entries(config.queries || {}).filter(([key, value]) => value !== undefined && value !== null));
76
- config.params = Object.fromEntries(Object.entries(config.params || {}).filter(([key, value]) => value !== undefined && value !== null));
77
- if (typeof !!config?.enableLoader === 'undefined' &&
78
- (typeof !!config?.enableLoader === 'boolean' &&
79
- !!config?.enableLoader)) {
80
- loaderHandler();
81
- }
82
- const refreshPage = (typeof config?.refreshPage === 'boolean') ? config?.refreshPage : false;
83
- const pathF = resolveRoute({
84
- path: config?.path,
85
- params: config?.params,
86
- queries: config?.queries,
87
- });
88
- if (!!refreshPage) {
89
- window.location = pathF;
90
- }
91
- else {
92
- navigate(pathF, {
93
- replace: config?.replace,
94
- });
95
- }
64
+ let res = generatePath(path, params);
65
+ if (Object.keys(queries).length > 0) {
66
+ res = `${res}?${createSearchParams(queries)}`;
67
+ }
68
+ return res;
69
+ } catch (error) {
70
+ if (process.env?.NODE_ENV === 'development') {
71
+ console.log(error);
72
+ }
73
+ return incorrectUrl;
74
+ }
75
+ }
76
+ ;
77
+
78
+ /**
79
+ * Ce hooks contient toutes les actions necessaires pour le routing.
80
+ * - recuperer les paramètres de la route
81
+ * - Recuperer les query parameters de la route
82
+ * - naviguer au travers des routes
83
+ * - recuperer une route en fonction de son path, ses paramètres et ses query parameters
84
+ * - naviguer vers une route en fonction de son path, ses paramètres et ses query parameters
85
+ * - naviguer vers une route en fonction de son path, ses paramètres et ses query parameters en rafraîchissant le navigateur
86
+ * - recuperer l'url de la route courante
87
+ * - recuperer la chaîne de caractères contenant les query parameters
88
+ * @type {() => RootingActionReturns}
89
+ * @returns {RootingActionReturns} Resultat du hooks.
90
+ */
91
+ export const useRootingActions = () => {
92
+ const location = useLocation();
93
+ const pathname = location.pathname;
94
+ /**
95
+ * L'ensemble des parametres de la route
96
+ * @type {Readonly<Params<string>>}
97
+ */
98
+ const params = useParams();
99
+ /**
100
+ * L'url de la route courante
101
+ * @type {string}
102
+ */
103
+ const pathName = useLocation().pathname;
104
+ /**
105
+ * La chaîne de caractères contenant les query parameters
106
+ * @type {string}
107
+ */
108
+ const urlSearch = useLocation().search;
109
+ const paramsData = new URLSearchParams(useLocation().search);
110
+
111
+ /**
112
+ * L'ensemble des query parameters de la route
113
+ * @type {any}
114
+ */
115
+ let queries = {};
116
+ for (const key of paramsData.keys()) {
117
+ const valueParamsData = paramsData.getAll(key).length === 1 ? paramsData.getAll(key)[0] : paramsData.getAll(key);
118
+ queries = {
119
+ ...queries,
120
+ [key]: valueParamsData
96
121
  };
97
- const goAndReloadRoute = (config, loaderHandler = () => { }) => {
98
- loaderHandler = !!loaderHandler ? loaderHandler : () => { };
99
- if (!config?.queries) {
100
- config.queries = {};
101
- }
102
- let lang = getLang(config?.queries?.lang);
103
- if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
104
- lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
105
- }
106
- config.queries = {
107
- ...config.queries,
108
- lang,
109
- };
110
- config.queries = Object.fromEntries(Object.entries(config.queries || {}).filter(([key, value]) => value !== undefined && value !== null));
111
- config.params = Object.fromEntries(Object.entries(config.params || {}).filter(([key, value]) => value !== undefined && value !== null));
112
- const url = resolveRoute(config);
113
- window.location = url;
114
- if (typeof !!config?.enableLoader === 'undefined' &&
115
- (typeof !!config?.enableLoader === 'boolean' &&
116
- !!config?.enableLoader)) {
117
- loaderHandler();
118
- }
122
+ }
123
+ const navigate = useNavigate();
124
+
125
+ /**
126
+ * Cette fonction permet de recuperer une route en fonction de son path, ses paramètres et ses query parameters.
127
+ * @param {ConfigResolveRoute} config - Paramètre de configuration ou de paramètrage.
128
+ * @type {(config: ConfigResolveRoute) => string}
129
+ * @returns {string} Resultat de la fonction.
130
+ */
131
+ const resolveRoute = config => {
132
+ const incorrectUrl = pathName;
133
+ return nativeResolveRoute(config, incorrectUrl);
134
+ };
135
+ /**
136
+ * Cette fonction permet de naviguer vers une route en fonction de son path, ses paramètres et ses query parameters.
137
+ * @param {ConfigGoToRoute} config - Paramètre de configuration ou de paramètrage.
138
+ * @type {(config: ConfigGoToRoute) => void}
139
+ */
140
+ const goToRoute = (config, loaderHandler = () => {}) => {
141
+ loaderHandler = !!loaderHandler ? loaderHandler : () => {};
142
+ if (!config?.queries) {
143
+ config.queries = {};
144
+ }
145
+ let lang = getLang(config?.queries?.lang);
146
+ if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
147
+ lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
148
+ }
149
+ config.queries = {
150
+ ...config.queries,
151
+ lang
119
152
  };
120
- const getUrlData = (url) => {
121
- let urlF = undefined;
122
- if (typeof url === 'string' &&
123
- url.length > 0) {
124
- urlF = new URL(url);
125
- }
126
- else if (url instanceof URL) {
127
- urlF = url;
128
- }
129
- const paramsData = urlF?.search ? new URLSearchParams(urlF?.search) : undefined;
130
- let queries = undefined;
131
- if (!!paramsData) {
132
- queries = {};
133
- for (const key of paramsData.keys()) {
134
- const valueParamsData = (paramsData.getAll(key).length === 1) ? paramsData.getAll(key)[0] : paramsData.getAll(key);
135
- queries = {
136
- ...queries,
137
- [key]: valueParamsData,
138
- };
139
- }
140
- }
141
- return urlF ? {
142
- host: urlF?.host,
143
- hostname: urlF?.hostname,
144
- pathname: urlF?.pathname,
145
- search: urlF?.search,
146
- queries,
147
- } : undefined;
153
+ config.queries = Object.fromEntries(Object.entries(config.queries || {}).filter(([key, value]) => value !== undefined && value !== null));
154
+ config.params = Object.fromEntries(Object.entries(config.params || {}).filter(([key, value]) => value !== undefined && value !== null));
155
+ if (typeof !!config?.enableLoader === 'undefined' && typeof !!config?.enableLoader === 'boolean' && !!config?.enableLoader) {
156
+ loaderHandler();
157
+ }
158
+ const refreshPage = typeof config?.refreshPage === 'boolean' ? config?.refreshPage : false;
159
+ const pathF = resolveRoute({
160
+ path: config?.path,
161
+ params: config?.params,
162
+ queries: config?.queries
163
+ });
164
+ if (!!refreshPage) {
165
+ window.location = pathF;
166
+ } else {
167
+ navigate(pathF, {
168
+ replace: config?.replace
169
+ });
170
+ }
171
+ };
172
+ /**
173
+ * Cette fonction permet de naviguer vers une route en fonction de son path, ses paramètres et ses query parameters en rafraîchissant le navigateur.
174
+ * @param {ConfigGoAndReloadRoute} config - Paramètre de configuration ou de paramètrage.
175
+ * @type {(config: ConfigGoAndReloadRoute) => void}
176
+ */
177
+ const goAndReloadRoute = (config, loaderHandler = () => {}) => {
178
+ loaderHandler = !!loaderHandler ? loaderHandler : () => {};
179
+ if (!config?.queries) {
180
+ config.queries = {};
181
+ }
182
+ let lang = getLang(config?.queries?.lang);
183
+ if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
184
+ lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
185
+ }
186
+ config.queries = {
187
+ ...config.queries,
188
+ lang
148
189
  };
149
- const goToUrl = (config) => {
150
- const incorrectUrl = "";
151
- const queries = (typeof config?.queries === 'object' &&
152
- Array.isArray(config?.queries) === false) ? config?.queries : {};
153
- const path = (typeof config?.path === 'string') ? config?.path : incorrectUrl;
154
- if (!config?.queries) {
155
- config.queries = {};
156
- }
157
- let lang = getLang(config?.queries?.lang);
158
- if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
159
- lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
160
- }
161
- config.queries = {
162
- ...config.queries,
163
- lang,
190
+ config.queries = Object.fromEntries(Object.entries(config.queries || {}).filter(([key, value]) => value !== undefined && value !== null));
191
+ config.params = Object.fromEntries(Object.entries(config.params || {}).filter(([key, value]) => value !== undefined && value !== null));
192
+ // goToRoute({
193
+ // ...config,
194
+ // refreshPage: false,
195
+ // })
196
+ const url = resolveRoute(config);
197
+ window.location = url;
198
+ if (typeof !!config?.enableLoader === 'undefined' && typeof !!config?.enableLoader === 'boolean' && !!config?.enableLoader) {
199
+ loaderHandler();
200
+ }
201
+ };
202
+ const getUrlData = url => {
203
+ let urlF = undefined;
204
+ if (typeof url === 'string' && url.length > 0) {
205
+ urlF = new URL(url);
206
+ } else if (url instanceof URL) {
207
+ urlF = url;
208
+ }
209
+ const paramsData = urlF?.search ? new URLSearchParams(urlF?.search) : undefined;
210
+ let queries = undefined;
211
+ if (!!paramsData) {
212
+ queries = {};
213
+ for (const key of paramsData.keys()) {
214
+ const valueParamsData = paramsData.getAll(key).length === 1 ? paramsData.getAll(key)[0] : paramsData.getAll(key);
215
+ queries = {
216
+ ...queries,
217
+ [key]: valueParamsData
164
218
  };
165
- const uncleanUrl = qust.stringify(queries);
166
- const qsValue = decodeURI(uncleanUrl);
167
- const url = `${path}?${qsValue}`;
168
- if (!!config?.refreshPage) {
169
- window.location = url;
170
- }
171
- else {
172
- window.location.assign(url);
173
- }
174
- };
175
- const checkIfIsCurrentRoute = (path, exact = true, strict = true) => {
176
- const pathF = (typeof path === 'string' &&
177
- path.length > 0) ? path : '';
178
- const exactF = (typeof exact === 'boolean') ? exact : true;
179
- const strictF = (typeof strict === 'boolean') ? strict : true;
180
- const matchAbout = distExports.matchPath({
181
- path: pathF,
182
- end: exactF,
183
- caseSensitive: strictF,
184
- }, pathname);
185
- return !!matchAbout;
186
- };
187
- reactExports.useEffect(() => {
188
- }, []);
189
- return {
190
- params,
191
- queries,
192
- navigate,
193
- resolveRoute,
194
- goToRoute,
195
- goAndReloadRoute,
196
- pathName,
197
- urlSearch,
198
- getUrlData,
199
- goToUrl,
200
- getParams,
201
- checkIfIsCurrentRoute,
219
+ }
220
+ }
221
+ return urlF ? {
222
+ host: urlF?.host,
223
+ hostname: urlF?.hostname,
224
+ pathname: urlF?.pathname,
225
+ search: urlF?.search,
226
+ queries
227
+ } : undefined;
228
+ };
229
+ const goToUrl = config => {
230
+ const incorrectUrl = "";
231
+ const queries = typeof config?.queries === 'object' && Array.isArray(config?.queries) === false ? config?.queries : {};
232
+ const path = typeof config?.path === 'string' ? config?.path : incorrectUrl;
233
+ if (!config?.queries) {
234
+ config.queries = {};
235
+ }
236
+ let lang = getLang(config?.queries?.lang);
237
+ if (!!config?.queries?.lang && config?.queries?.lang != 'fr') {
238
+ lang = getLang(config?.queries?.lang || getParams().get('lang') || 'fr');
239
+ }
240
+ config.queries = {
241
+ ...config.queries,
242
+ lang
202
243
  };
203
- };
204
-
205
- export { nativeResolveRoute, useRootingActions };
244
+ const uncleanUrl = qust.stringify(queries);
245
+ const qsValue = decodeURI(uncleanUrl);
246
+ const url = `${path}?${qsValue}`;
247
+ if (!!config?.refreshPage) {
248
+ window.location = url;
249
+ } else {
250
+ window.location.assign(url);
251
+ }
252
+ };
253
+ const checkIfIsCurrentRoute = (path, exact = true, strict = true) => {
254
+ const pathF = typeof path === 'string' && path.length > 0 ? path : '';
255
+ const exactF = typeof exact === 'boolean' ? exact : true;
256
+ const strictF = typeof strict === 'boolean' ? strict : true;
257
+ const matchAbout = matchPath({
258
+ path: pathF,
259
+ end: exactF,
260
+ caseSensitive: strictF
261
+ }, pathname);
262
+ return !!matchAbout;
263
+ };
264
+ useEffect(() => {}, []);
265
+ return {
266
+ params,
267
+ queries,
268
+ navigate,
269
+ resolveRoute,
270
+ goToRoute,
271
+ goAndReloadRoute,
272
+ pathName,
273
+ urlSearch,
274
+ getUrlData,
275
+ goToUrl,
276
+ getParams,
277
+ checkIfIsCurrentRoute
278
+ };
279
+ };
package/rooting.hooks.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { useContext, useEffect } from 'react';
2
2
  import { useLocation, useNavigate, useParams, generatePath, createSearchParams, NavigateFunction, Params, matchPath } from 'react-router-dom';
3
- import { getLang } from '../src/utils';
3
+ import { getLang } from './utils';
4
4
  import { qust, Qust } from '@arc-js/qust';
5
5
 
6
6
 
package/routes-utils.d.ts CHANGED
@@ -1,5 +1,15 @@
1
- import { RouteDefinition } from './types.js';
2
- import 'react';
1
+ import { ReactNode } from 'react';
2
+
3
+ interface RouteDefinition {
4
+ truePath: string;
5
+ pathParent?: string;
6
+ path: string;
7
+ component: React.ComponentType<any>;
8
+ layout?: React.ComponentType<{
9
+ children: ReactNode;
10
+ }>;
11
+ error?: React.ComponentType<{}>;
12
+ }
3
13
 
4
14
  declare function getRoutes(): Promise<RouteDefinition[]>;
5
15
  declare const routes: RouteDefinition[];
package/routes-utils.js CHANGED
@@ -1,4 +1,90 @@
1
- import { getAllConfig, findConfigModuleRoute } from './minimal-config.js';
1
+
2
+
3
+
4
+
5
+ function __awaiter(thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ }
14
+
15
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
16
+ var e = new Error(message);
17
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
18
+ };
19
+
20
+ const configModules = import.meta.glob([
21
+ '/src/config.json',
22
+ '/src/modules/**/config.json'
23
+ ]);
24
+ function cleanPathConfig(filePath) {
25
+ return filePath
26
+ .replace(/^\/src/, '')
27
+ .replace(/^\/src\/modules\//, '')
28
+ .replace(/^\/modules\//, '')
29
+ .replace(/config\.json$/, '');
30
+ }
31
+ function filePathToConfigPath(filePath, isParent = false) {
32
+ isParent = (typeof isParent === 'boolean') ? isParent : false;
33
+ let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
34
+ configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
35
+ subPath.length > 0)).join('/');
36
+ return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
37
+ }
38
+ function getAllConfig() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
41
+ const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
42
+ const configPath = filePathToConfigPath(filePath);
43
+ let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
44
+ nameConfig = (typeof nameConfig === 'string' &&
45
+ nameConfig.length > 0) ? nameConfig : undefined;
46
+ let config = (yield module()).default;
47
+ config = (typeof config === 'object' &&
48
+ !Array.isArray(config) &&
49
+ Object.keys(config).length > 0) ? {
50
+ path: ((typeof (config === null || config === void 0 ? void 0 : config.path) === 'string' &&
51
+ (config === null || config === void 0 ? void 0 : config.path.length) > 0) ? config === null || config === void 0 ? void 0 : config.path : configPath),
52
+ name: ((typeof (config === null || config === void 0 ? void 0 : config.name) === 'string' &&
53
+ (config === null || config === void 0 ? void 0 : config.name.length) > 0) ? config === null || config === void 0 ? void 0 : config.name : nameConfig),
54
+ description: ((typeof (config === null || config === void 0 ? void 0 : config.description) === 'string' &&
55
+ (config === null || config === void 0 ? void 0 : config.description.length) > 0) ? config === null || config === void 0 ? void 0 : config.description : undefined),
56
+ author: ((typeof (config === null || config === void 0 ? void 0 : config.author) === 'string' &&
57
+ (config === null || config === void 0 ? void 0 : config.author.length) > 0) ? config === null || config === void 0 ? void 0 : config.author : undefined),
58
+ isEnabled: ((typeof (config === null || config === void 0 ? void 0 : config.isEnabled) === 'boolean') ? config === null || config === void 0 ? void 0 : config.isEnabled : true),
59
+ } : {
60
+ path: configPath,
61
+ name: nameConfig,
62
+ author: undefined,
63
+ isEnabled: true,
64
+ };
65
+ return {
66
+ parentTruePath,
67
+ truePath: filePath,
68
+ path: configPath,
69
+ name: nameConfig,
70
+ description: undefined,
71
+ config,
72
+ };
73
+ })));
74
+ return configs;
75
+ });
76
+ }
77
+ function findConfigModuleRoute(route, configDatas) {
78
+ var _a;
79
+ const res = (_a = configDatas.sort((a, b) => {
80
+ if (a.truePath.split('/').length > b.truePath.split('/').length)
81
+ return -1;
82
+ if (a.truePath.split('/').length < b.truePath.split('/').length)
83
+ return 1;
84
+ return 0;
85
+ }).find((config) => (route.truePath.indexOf(config.parentTruePath) === 0))) === null || _a === void 0 ? void 0 : _a.config;
86
+ return res;
87
+ }
2
88
 
3
89
  const errorPageName = '_error';
4
90
  const defaultErrorPath = '/src/pages/_error';
@@ -35,40 +121,45 @@ function filePathToRoutePath(filePath) {
35
121
  }
36
122
  return routePath.startsWith(indexPagePath) ? routePath : `/${routePath}`;
37
123
  }
38
- async function findLayoutForPage(filePath) {
39
- const layoutPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${layoutName}.tsx`);
40
- const layoutModules = import.meta.glob('/src/modules/**/_layout.tsx', { eager: true });
41
- const defaultLayoutModules = import.meta.glob('/src/pages/_layout.tsx', { eager: true });
42
- return layoutModules[layoutPath]?.default || defaultLayoutModules[`${defaultLayoutPath}.tsx`]?.default;
124
+ function findLayoutForPage(filePath) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ var _a, _b;
127
+ const layoutPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${layoutName}.tsx`);
128
+ const layoutModules = import.meta.glob('/src/modules/**/_layout.tsx', { eager: true });
129
+ const defaultLayoutModules = import.meta.glob('/src/pages/_layout.tsx', { eager: true });
130
+ return ((_a = layoutModules[layoutPath]) === null || _a === void 0 ? void 0 : _a.default) || ((_b = defaultLayoutModules[`${defaultLayoutPath}.tsx`]) === null || _b === void 0 ? void 0 : _b.default);
131
+ });
43
132
  }
44
- async function findErrorForPage(filePath) {
45
- const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
46
- const errorModules = import.meta.glob("/src/modules/**/_error.tsx", { eager: true });
47
- const defaultErrorModules = import.meta.glob("/src/pages/_error.tsx", { eager: true });
48
- if (process.env?.NODE_ENV === 'debug') {
49
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
50
- filePath,
51
- errorPath,
52
- }));
53
- }
54
- return errorModules[errorPath]?.default || defaultErrorModules[`${defaultErrorPath}.tsx`]?.default;
133
+ function findErrorForPage(filePath) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ var _a, _b, _c;
136
+ const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
137
+ const errorModules = import.meta.glob("/src/modules/**/_error.tsx", { eager: true });
138
+ const defaultErrorModules = import.meta.glob("/src/pages/_error.tsx", { eager: true });
139
+ if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'debug') {
140
+ console.log(`[src -> @arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
141
+ filePath,
142
+ errorPath,
143
+ }));
144
+ }
145
+ return ((_b = errorModules[errorPath]) === null || _b === void 0 ? void 0 : _b.default) || ((_c = defaultErrorModules[`${defaultErrorPath}.tsx`]) === null || _c === void 0 ? void 0 : _c.default);
146
+ });
55
147
  }
56
- async function findErrorForPageLink(filePath) {
57
- const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
58
- return cleanPathPage(errorPath).split('/src').join('');
148
+ function findErrorForPageLink(filePath) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
151
+ return cleanPathPage(errorPath).split('/src').join('');
152
+ });
59
153
  }
60
154
  function nearestRoute(targetRoute, routes) {
61
- const possibleLayouts = routes.map((route) => ({
62
- ...route,
63
- path: (route.path || '').split('/').filter((partRoute, indexPartRoute, arrayPartRoute) => ((arrayPartRoute.length >= 2 &&
64
- typeof arrayPartRoute?.[arrayPartRoute.length - 2] === 'string' &&
65
- arrayPartRoute?.[arrayPartRoute.length - 2].length <= 0 &&
155
+ const possibleLayouts = routes.map((route) => (Object.assign(Object.assign({}, route), { path: (route.path || '').split('/').filter((partRoute, indexPartRoute, arrayPartRoute) => ((arrayPartRoute.length >= 2 &&
156
+ typeof (arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2]) === 'string' &&
157
+ (arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2].length) <= 0 &&
66
158
  indexPartRoute < (arrayPartRoute.length - 2)) ||
67
159
  (!(arrayPartRoute.length >= 2 &&
68
- typeof arrayPartRoute?.[arrayPartRoute.length - 2] === 'string' &&
69
- arrayPartRoute?.[arrayPartRoute.length - 2].length <= 0) &&
70
- indexPartRoute < (arrayPartRoute.length - 1)))).join('/'),
71
- })).filter((route) => targetRoute.path.indexOf(route.path) === 0).sort((a, b) => {
160
+ typeof (arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2]) === 'string' &&
161
+ (arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2].length) <= 0) &&
162
+ indexPartRoute < (arrayPartRoute.length - 1)))).join('/') }))).filter((route) => targetRoute.path.indexOf(route.path) === 0).sort((a, b) => {
72
163
  if (a.path.indexOf(targetRoute.path) > b.path.indexOf(targetRoute.path))
73
164
  return -1;
74
165
  if (a.path.indexOf(targetRoute.path) < b.path.indexOf(targetRoute.path))
@@ -79,69 +170,68 @@ function nearestRoute(targetRoute, routes) {
79
170
  return 1;
80
171
  return 0;
81
172
  });
82
- return possibleLayouts?.[0];
173
+ return possibleLayouts === null || possibleLayouts === void 0 ? void 0 : possibleLayouts[0];
83
174
  }
84
- async function getRoutes() {
85
- const configs = await getAllConfig();
86
- if (process.env?.NODE_ENV === 'development') {
87
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
88
- }
89
- let routes = await Promise.all(Object.entries(pageModules).map(async ([filePath, module]) => {
90
- let layout = (!([
91
- notFoundPageName
92
- ].map((path) => (cleanPathPage(path))).includes(cleanPathPage(filePath)))) ? await findLayoutForPage(filePath) : undefined;
93
- let erroPage = await findErrorForPage(filePath);
94
- await findErrorForPageLink(filePath);
95
- const routePath = filePathToRoutePath(filePath);
96
- const component = (await module()).default;
97
- const routePathParent = routePath.split('/').filter((val, index, arr) => (typeof val === 'string' &&
98
- val.length > 0 &&
99
- index < (arr.length - 1))).join('/');
100
- return {
101
- truePath: filePath,
102
- path: routePath,
103
- component,
104
- layout,
105
- error: erroPage,
106
- pathParent: routePathParent,
107
- };
108
- }));
109
- const notFoundRoutes = routes.filter((route) => (!!route.truePath &&
110
- route.truePath.split('/').filter((partRoute) => partRoute.indexOf('_404.tsx') !== -1).length > 0)).map((route) => ({
111
- ...route,
112
- path: route.path.split('/').map((partRoute) => partRoute.split('_404').join(notFoundPagePath)).join('/'),
113
- }));
114
- routes = [
115
- ...routes.filter((route) => !(!!route.truePath &&
116
- route.truePath.split('/').filter((partRoute) => partRoute.indexOf('_404.tsx') !== -1).length > 0)),
117
- ...notFoundRoutes,
118
- ];
119
- const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
120
- const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
121
- if (process.env?.NODE_ENV === 'development') {
122
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | notFoundRoutes:: `, notFoundRoutes);
123
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | routes:: `, routes);
124
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | layoutRoutes:: `, layoutRoutes);
125
- }
126
- routes = routes.map((route) => ({
127
- ...route,
128
- layout: nearestRoute(route, layoutRoutes)?.component || route.layout,
129
- error: nearestRoute(route, errorRoutes)?.component || route.error,
130
- }));
131
- const routesF = routes.map((route, indexRoute) => {
132
- const routeConfig = findConfigModuleRoute(route, configs);
133
- if (typeof routeConfig?.path === 'string' &&
134
- routeConfig?.path.length > 0 &&
135
- routeConfig?.path != '/') {
136
- route.path = route.path.split('/').filter((subPath, indexSubPath, path) => (indexSubPath > 1)).join('/');
137
- route.path = `${routeConfig?.path}/${route.path}`.split('//').join('/');
175
+ function getRoutes() {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ var _a, _b, _c;
178
+ const configs = yield getAllConfig();
179
+ if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
180
+ console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
181
+ }
182
+ let routes = yield Promise.all(Object.entries(pageModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
183
+ let layout = (!([
184
+ notFoundPageName
185
+ ].map((path) => (cleanPathPage(path))).includes(cleanPathPage(filePath)))) ? yield findLayoutForPage(filePath) : undefined;
186
+ let erroPage = yield findErrorForPage(filePath);
187
+ yield findErrorForPageLink(filePath);
188
+ const routePath = filePathToRoutePath(filePath);
189
+ const component = (yield module()).default;
190
+ const routePathParent = routePath.split('/').filter((val, index, arr) => (typeof val === 'string' &&
191
+ val.length > 0 &&
192
+ index < (arr.length - 1))).join('/');
193
+ return {
194
+ truePath: filePath,
195
+ path: routePath,
196
+ component,
197
+ layout,
198
+ error: erroPage,
199
+ pathParent: routePathParent,
200
+ };
201
+ })));
202
+ const notFoundRoutes = routes.filter((route) => (!!route.truePath &&
203
+ route.truePath.split('/').filter((partRoute) => partRoute.indexOf('_404.tsx') !== -1).length > 0)).map((route) => (Object.assign(Object.assign({}, route), { path: route.path.split('/').map((partRoute) => partRoute.split('_404').join(notFoundPagePath)).join('/') })));
204
+ routes = [
205
+ ...routes.filter((route) => !(!!route.truePath &&
206
+ route.truePath.split('/').filter((partRoute) => partRoute.indexOf('_404.tsx') !== -1).length > 0)),
207
+ ...notFoundRoutes,
208
+ ];
209
+ const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
210
+ const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
211
+ if (((_b = process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') {
212
+ console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | notFoundRoutes:: `, notFoundRoutes);
213
+ console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | routes:: `, routes);
214
+ console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | layoutRoutes:: `, layoutRoutes);
138
215
  }
139
- return route;
216
+ routes = routes.map((route) => {
217
+ var _a, _b;
218
+ return (Object.assign(Object.assign({}, route), { layout: ((_a = nearestRoute(route, layoutRoutes)) === null || _a === void 0 ? void 0 : _a.component) || route.layout, error: ((_b = nearestRoute(route, errorRoutes)) === null || _b === void 0 ? void 0 : _b.component) || route.error }));
219
+ });
220
+ const routesF = routes.map((route, indexRoute) => {
221
+ const routeConfig = findConfigModuleRoute(route, configs);
222
+ if (typeof (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) === 'string' &&
223
+ (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path.length) > 0 &&
224
+ (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) != '/') {
225
+ route.path = route.path.split('/').filter((subPath, indexSubPath, path) => (indexSubPath > 1)).join('/');
226
+ route.path = `${routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path}/${route.path}`.split('//').join('/');
227
+ }
228
+ return route;
229
+ });
230
+ if (((_c = process.env) === null || _c === void 0 ? void 0 : _c.NODE_ENV) === 'development') {
231
+ console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
232
+ }
233
+ return routesF;
140
234
  });
141
- if (process.env?.NODE_ENV === 'development') {
142
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
143
- }
144
- return routesF;
145
235
  }
146
236
  const routes = await getRoutes();
147
237
 
@@ -1,2 +1,2 @@
1
- import{getAllConfig,findConfigModuleRoute}from"./minimal-config.js";let errorPageName="_error",defaultErrorPath="/src/pages/_error",notFoundPageName="_404",notFoundPagePath="*",defaultLayoutPath="/src/pages/_layout",layoutName="_layout",indexPageName="index",indexPageRule=/\/index$/,indexPagePath="/",pageModules=import.meta.glob(["/src/pages/**/*.tsx","/src/modules/**/pages/**/*.tsx"]);function cleanPathPage(e){return e.replace(/^\/src\/pages\//,"").replace(/^\/src\/modules\//,"").replace(/\/pages\//,"/").replace(/\.tsx$/,"").replace(/\{([^\]]+)\}/g,":$1")}function filePathToRoutePath(e){let t=cleanPathPage(e);if(t.endsWith("/"+indexPageName))t=t.replace(indexPageRule,"")||indexPagePath;else if(t===""+indexPageName)t=indexPagePath;else if(t===notFoundPageName)return t=notFoundPagePath;return t.startsWith(indexPagePath)?t:"/"+t}async function findLayoutForPage(e){var e=e.replace(/\/pages\/.*\.tsx$/,`/pages/${layoutName}.tsx`),t=import.meta.glob("/src/modules/**/_layout.tsx",{eager:!0}),a=import.meta.glob("/src/pages/_layout.tsx",{eager:!0});return t[e]?.default||a[defaultLayoutPath+".tsx"]?.default}async function findErrorForPage(e){var e=e.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`),t=import.meta.glob("/src/modules/**/_error.tsx",{eager:!0}),a=import.meta.glob("/src/pages/_error.tsx",{eager:!0});return process.env?.NODE_ENV,t[e]?.default||a[defaultErrorPath+".tsx"]?.default}async function findErrorForPageLink(e){return cleanPathPage(e.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`)).split("/src").join("")}function nearestRoute(a,e){return e.map(e=>({...e,path:(e.path||"").split("/").filter((e,t,a)=>2<=a.length&&"string"==typeof a?.[a.length-2]&&a?.[a.length-2].length<=0&&t<a.length-2||!(2<=a.length&&"string"==typeof a?.[a.length-2]&&a?.[a.length-2].length<=0)&&t<a.length-1).join("/")})).filter(e=>0===a.path.indexOf(e.path)).sort((e,t)=>e.path.indexOf(a.path)>t.path.indexOf(a.path)?-1:e.path.indexOf(a.path)<t.path.indexOf(a.path)?1:e.path.split("/").length>t.path.split("/").length?-1:e.path.split("/").length<t.path.split("/").length?1:0)?.[0]}async function getRoutes(){let r=await getAllConfig(),e=(process.env?.NODE_ENV,await Promise.all(Object.entries(pageModules).map(async([e,t])=>{var a=[notFoundPageName].map(e=>cleanPathPage(e)).includes(cleanPathPage(e))?void 0:await findLayoutForPage(e),r=await findErrorForPage(e),n=(await findErrorForPageLink(e),filePathToRoutePath(e)),t=(await t()).default,o=n.split("/").filter((e,t,a)=>"string"==typeof e&&0<e.length&&t<a.length-1).join("/");return{truePath:e,path:n,component:t,layout:a,error:r,pathParent:o}})));var t=e.filter(e=>!!e.truePath&&0<e.truePath.split("/").filter(e=>-1!==e.indexOf("_404.tsx")).length).map(e=>({...e,path:e.path.split("/").map(e=>e.split("_404").join(notFoundPagePath)).join("/")}));let a=(e=[...e.filter(e=>!(e.truePath&&0<e.truePath.split("/").filter(e=>-1!==e.indexOf("_404.tsx")).length)),...t]).filter(e=>!!e.path&&-1!==e.path.indexOf("/_layout")),n=e.filter(e=>!!e.path&&-1!==e.path.indexOf("/_error"));process.env?.NODE_ENV;t=(e=e.map(e=>({...e,layout:nearestRoute(e,a)?.component||e.layout,error:nearestRoute(e,n)?.component||e.error}))).map((e,t)=>{var a=findConfigModuleRoute(e,r);return"string"==typeof a?.path&&0<a?.path.length&&"/"!=a?.path&&(e.path=e.path.split("/").filter((e,t,a)=>1<t).join("/"),e.path=(a?.path+"/"+e.path).split("//").join("/")),e});return process.env?.NODE_ENV,t}let routes=await getRoutes();export{getRoutes,routes};
1
+ function __awaiter(t,l,r,u){return new(r=r||Promise)(function(n,e){function a(t){try{o(u.next(t))}catch(t){e(t)}}function i(t){try{o(u.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?n(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(a,i)}o((u=u.apply(t,l||[])).next())})}let configModules=import.meta.glob(["/src/config.json","/src/modules/**/config.json"]);function cleanPathConfig(t){return t.replace(/^\/src/,"").replace(/^\/src\/modules\//,"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(t,e=!1){let n=(e="boolean"==typeof e&&e)?t.replace(/config\.json$/,""):cleanPathConfig(t);return(n=n.split("/").filter(t=>"string"==typeof t&&0<t.length).join("/")).startsWith("/")?n:("/"+n).split("//").join("/")}function getAllConfig(){return __awaiter(this,void 0,void 0,function*(){return yield Promise.all(Object.entries(configModules).map(t=>__awaiter(this,[t],void 0,function*([t,e]){var n=filePathToConfigPath(t,!0).split("/").join("/"),a=filePathToConfigPath(t),i="string"==typeof(i=a.split("/").filter((t,e,n)=>0<e).join("/"))&&0<i.length?i:void 0,e=(yield e()).default;return{parentTruePath:n,truePath:t,path:a,name:i,description:void 0,config:"object"==typeof e&&!Array.isArray(e)&&0<Object.keys(e).length?{path:"string"==typeof(null==e?void 0:e.path)&&0<(null==e?void 0:e.path.length)?null==e?void 0:e.path:a,name:"string"==typeof(null==e?void 0:e.name)&&0<(null==e?void 0:e.name.length)?null==e?void 0:e.name:i,description:!("string"==typeof(null==e?void 0:e.description)&&0<(null==e?void 0:e.description.length))||null==e?void 0:e.description,author:!("string"==typeof(null==e?void 0:e.author)&&0<(null==e?void 0:e.author.length))||null==e?void 0:e.author,isEnabled:"boolean"!=typeof(null==e?void 0:e.isEnabled)||(null==e?void 0:e.isEnabled)}:{path:a,name:i,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(e,t){return null==(t=t.sort((t,e)=>t.truePath.split("/").length>e.truePath.split("/").length?-1:t.truePath.split("/").length<e.truePath.split("/").length?1:0).find(t=>0===e.truePath.indexOf(t.parentTruePath)))?void 0:t.config}let errorPageName="_error",defaultErrorPath="/src/pages/_error",notFoundPageName="_404",notFoundPagePath="*",defaultLayoutPath="/src/pages/_layout",layoutName="_layout",indexPageName="index",indexPageRule=/\/index$/,indexPagePath="/",pageModules=import.meta.glob(["/src/pages/**/*.tsx","/src/modules/**/pages/**/*.tsx"]);function cleanPathPage(t){return t.replace(/^\/src\/pages\//,"").replace(/^\/src\/modules\//,"").replace(/\/pages\//,"/").replace(/\.tsx$/,"").replace(/\{([^\]]+)\}/g,":$1")}function filePathToRoutePath(t){let e=cleanPathPage(t);if(e.endsWith("/"+indexPageName))e=e.replace(indexPageRule,"")||indexPagePath;else if(e===""+indexPageName)e=indexPagePath;else if(e===notFoundPageName)return e=notFoundPagePath;return e.startsWith(indexPagePath)?e:"/"+e}function findLayoutForPage(a){return __awaiter(this,void 0,void 0,function*(){var t=a.replace(/\/pages\/.*\.tsx$/,`/pages/${layoutName}.tsx`),e=import.meta.glob("/src/modules/**/_layout.tsx",{eager:!0}),n=import.meta.glob("/src/pages/_layout.tsx",{eager:!0});return(null==(e=e[t])?void 0:e.default)||(null==(t=n[defaultLayoutPath+".tsx"])?void 0:t.default)})}function findErrorForPage(i){return __awaiter(this,void 0,void 0,function*(){var t,e=i.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`),n=import.meta.glob("/src/modules/**/_error.tsx",{eager:!0}),a=import.meta.glob("/src/pages/_error.tsx",{eager:!0});return null!=(t=process.env)&&t.NODE_ENV,(null==(t=n[e])?void 0:t.default)||(null==(n=a[defaultErrorPath+".tsx"])?void 0:n.default)})}function findErrorForPageLink(t){return __awaiter(this,void 0,void 0,function*(){return cleanPathPage(t.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`)).split("/src").join("")})}function nearestRoute(n,t){t=t.map(t=>Object.assign(Object.assign({},t),{path:(t.path||"").split("/").filter((t,e,n)=>2<=n.length&&"string"==typeof(null==n?void 0:n[n.length-2])&&(null==n?void 0:n[n.length-2].length)<=0&&e<n.length-2||!(2<=n.length&&"string"==typeof(null==n?void 0:n[n.length-2])&&(null==n?void 0:n[n.length-2].length)<=0)&&e<n.length-1).join("/")})).filter(t=>0===n.path.indexOf(t.path)).sort((t,e)=>t.path.indexOf(n.path)>e.path.indexOf(n.path)?-1:t.path.indexOf(n.path)<e.path.indexOf(n.path)?1:t.path.split("/").length>e.path.split("/").length?-1:t.path.split("/").length<e.path.split("/").length?1:0);return null==t?void 0:t[0]}function getRoutes(){return __awaiter(this,void 0,void 0,function*(){let t,e,n,a=yield getAllConfig(),i=(null==(t=process.env)||t.NODE_ENV,yield Promise.all(Object.entries(pageModules).map(t=>__awaiter(this,[t],void 0,function*([t,e]){var n=[notFoundPageName].map(t=>cleanPathPage(t)).includes(cleanPathPage(t))?void 0:yield findLayoutForPage(t),a=yield findErrorForPage(t),i=(yield findErrorForPageLink(t),filePathToRoutePath(t)),e=(yield e()).default,o=i.split("/").filter((t,e,n)=>"string"==typeof t&&0<t.length&&e<n.length-1).join("/");return{truePath:t,path:i,component:e,layout:n,error:a,pathParent:o}}))));var o=i.filter(t=>!!t.truePath&&0<t.truePath.split("/").filter(t=>-1!==t.indexOf("_404.tsx")).length).map(t=>Object.assign(Object.assign({},t),{path:t.path.split("/").map(t=>t.split("_404").join(notFoundPagePath)).join("/")}));let l=(i=[...i.filter(t=>!(t.truePath&&0<t.truePath.split("/").filter(t=>-1!==t.indexOf("_404.tsx")).length)),...o]).filter(t=>!!t.path&&-1!==t.path.indexOf("/_layout")),r=i.filter(t=>!!t.path&&-1!==t.path.indexOf("/_error"));null!=(e=process.env)&&e.NODE_ENV;o=(i=i.map(t=>{var e;return Object.assign(Object.assign({},t),{layout:(null==(e=nearestRoute(t,l))?void 0:e.component)||t.layout,error:(null==(e=nearestRoute(t,r))?void 0:e.component)||t.error})})).map((t,e)=>{var n=findConfigModuleRoute(t,a);return"string"==typeof(null==n?void 0:n.path)&&0<(null==n?void 0:n.path.length)&&"/"!=(null==n?void 0:n.path)&&(t.path=t.path.split("/").filter((t,e,n)=>1<e).join("/"),t.path=(`${null==n?void 0:n.path}/`+t.path).split("//").join("/")),t});return null!=(n=process.env)&&n.NODE_ENV,o})}let routes=await getRoutes();export{getRoutes,routes};
2
2
  //# sourceMappingURL=routes-utils.min.js.map
package/utils.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare function getLang(lang: string): string;
2
+ declare function getLangCode(lang: string): string;
3
+
4
+ export { getLang, getLangCode };
package/utils.js ADDED
@@ -0,0 +1,16 @@
1
+ const langs = ['en', 'fr'];
2
+ const langCodes = {
3
+ 'fr': 'fr_FR',
4
+ 'en': 'en_US',
5
+ };
6
+
7
+ function getLang(lang) {
8
+ let result = lang;
9
+ result = langs.includes(result) ? result : 'fr';
10
+ return result;
11
+ }
12
+ function getLangCode(lang) {
13
+ return langCodes[getLang(lang)];
14
+ }
15
+
16
+ export { getLang, getLangCode };
package/utils.min.js ADDED
@@ -0,0 +1,2 @@
1
+ let langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"};function getLang(n){return langs.includes(n)?n:"fr"}function getLangCode(n){return langCodes[getLang(n)]}export{getLang,getLangCode};
2
+ //# sourceMappingURL=utils.min.js.map
@@ -1 +0,0 @@
1
- import{j as jsxRuntimeExports}from"./_virtual/jsx-runtime";import*as routesUtils_js from"./routes-utils.js";import{routes}from"./routes-utils.js";export{useRootingActions}from"./rooting.hooks.jsx";var autoRooting=()=>{let t=routes.map(t=>({path:t.path,element:t.layout?jsxRuntimeExports.jsx(t.layout,{children:jsxRuntimeExports.jsx(t.component,{})}):jsxRuntimeExports.jsx(t.component,{}),...t.error?{errorElement:jsxRuntimeExports.jsx(t.error,{})}:{}}));var o=t.find(t=>"/"===t.path),r=t.find(t=>"*"===t.path);return t=[...o?[o]:[],...t.filter(t=>!(t.path&&["/","*"].includes(t.path))),...r?[r]:[]].filter(t=>!!t.path&&-1===t.path.indexOf("/_404")&&-1===t.path.indexOf("/_layout")),process.env?.NODE_ENV,t};export{autoRooting as default};
@@ -1 +0,0 @@
1
- import{r as reactExports}from"./_virtual/index";import{d as distExports}from"./_virtual/index2";import{getLang}from"./src/utils";import qust from"./node_modules/@arc-js/qust/index";function getParams(){var e=window.location.search;return new URLSearchParams(e)}function nativeResolveRoute(a,t=""){try{var s="object"==typeof a?.params&&!1===Array.isArray(a?.params)?a?.params:{},i="object"==typeof a?.queries&&!1===Array.isArray(a?.queries)?a?.queries:{},o="string"==typeof a?.path?a?.path:t;a?.queries||(a.queries={});let e=getLang(a?.queries?.lang),r=(a?.queries?.lang&&"fr"!=a?.queries?.lang&&(e=getLang(a?.queries?.lang||getParams().get("lang")||"fr")),a.queries={...a.queries,lang:e},distExports.generatePath(o,s));return r=0<Object.keys(i).length?r+"?"+distExports.createSearchParams(i):r}catch(e){return process.env?.NODE_ENV,t}}let useRootingActions=()=>{let t=distExports.useLocation().pathname;var e=distExports.useParams();let r=distExports.useLocation().pathname;var a,s=distExports.useLocation().search,i=new URLSearchParams(distExports.useLocation().search);let o={};for(a of i.keys()){var n=1===i.getAll(a).length?i.getAll(a)[0]:i.getAll(a);o={...o,[a]:n}}let l=distExports.useNavigate(),u=e=>nativeResolveRoute(e,r);return reactExports.useEffect(()=>{},[]),{params:e,queries:o,navigate:l,resolveRoute:u,goToRoute:(e,r=()=>{})=>{r=r||(()=>{}),e?.queries||(e.queries={});let a=getLang(e?.queries?.lang);e?.queries?.lang&&"fr"!=e?.queries?.lang&&(a=getLang(e?.queries?.lang||getParams().get("lang")||"fr")),e.queries={...e.queries,lang:a},e.queries=Object.fromEntries(Object.entries(e.queries||{}).filter(([,e])=>null!=e)),e.params=Object.fromEntries(Object.entries(e.params||{}).filter(([,e])=>null!=e)),void 0===!!e?.enableLoader&&"boolean"==typeof!!e?.enableLoader&&e?.enableLoader&&r();var r="boolean"==typeof e?.refreshPage&&e?.refreshPage,t=u({path:e?.path,params:e?.params,queries:e?.queries});r?window.location=t:l(t,{replace:e?.replace})},goAndReloadRoute:(e,r=()=>{})=>{r=r||(()=>{}),e?.queries||(e.queries={});let a=getLang(e?.queries?.lang);e?.queries?.lang&&"fr"!=e?.queries?.lang&&(a=getLang(e?.queries?.lang||getParams().get("lang")||"fr")),e.queries={...e.queries,lang:a},e.queries=Object.fromEntries(Object.entries(e.queries||{}).filter(([,e])=>null!=e)),e.params=Object.fromEntries(Object.entries(e.params||{}).filter(([,e])=>null!=e));var t=u(e);window.location=t,void 0===!!e?.enableLoader&&"boolean"==typeof!!e?.enableLoader&&e?.enableLoader&&r()},pathName:r,urlSearch:s,getUrlData:e=>{let r=void 0;"string"==typeof e&&0<e.length?r=new URL(e):e instanceof URL&&(r=e);var a=r?.search?new URLSearchParams(r?.search):void 0;let t=void 0;if(a){t={};for(var s of a.keys()){var i=1===a.getAll(s).length?a.getAll(s)[0]:a.getAll(s);t={...t,[s]:i}}}return r?{host:r?.host,hostname:r?.hostname,pathname:r?.pathname,search:r?.search,queries:t}:void 0},goToUrl:e=>{var r="object"==typeof e?.queries&&!1===Array.isArray(e?.queries)?e?.queries:{},a="string"==typeof e?.path?e?.path:"";e?.queries||(e.queries={});let t=getLang(e?.queries?.lang);e?.queries?.lang&&"fr"!=e?.queries?.lang&&(t=getLang(e?.queries?.lang||getParams().get("lang")||"fr")),e.queries={...e.queries,lang:t};r=qust.stringify(r),a=a+"?"+decodeURI(r);e?.refreshPage?window.location=a:window.location.assign(a)},getParams:getParams,checkIfIsCurrentRoute:(e,r=!0,a=!0)=>{e="string"==typeof e&&0<e.length?e:"";return!!distExports.matchPath({path:e,end:"boolean"!=typeof r||r,caseSensitive:"boolean"!=typeof a||a},t)}}};export{nativeResolveRoute,useRootingActions};