@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 +27 -31
- package/config.d.ts +8 -0
- package/config.js +8 -0
- package/config.min.js +2 -0
- package/minimal-config.d.ts +25 -2
- package/minimal-config.js +60 -38
- package/minimal-config.min.js +1 -1
- package/package.json +1 -1
- package/rooting.hooks.jsx +268 -194
- package/rooting.hooks.tsx +1 -1
- package/routes-utils.d.ts +12 -2
- package/routes-utils.js +179 -89
- package/routes-utils.min.js +1 -1
- package/utils.d.ts +4 -0
- package/utils.js +16 -0
- package/utils.min.js +2 -0
- package/auto-rooting.min.jsx +0 -1
- package/rooting.hooks.min.jsx +0 -1
package/auto-rooting.jsx
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
package/config.js
ADDED
package/config.min.js
ADDED
package/minimal-config.d.ts
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
nameConfig
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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))
|
|
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
|
|
package/minimal-config.min.js
CHANGED
|
@@ -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,
|
|
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.
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import { getLang } from './
|
|
4
|
-
import qust from '
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
const queryString = window.location.search;
|
|
19
|
+
const urlParams = new URLSearchParams(queryString);
|
|
20
|
+
return urlParams;
|
|
10
21
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return nativeResolveRoute(config, incorrectUrl);
|
|
60
|
+
config.queries = {
|
|
61
|
+
...config.queries,
|
|
62
|
+
lang
|
|
61
63
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
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 '
|
|
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 {
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
|
69
|
-
arrayPartRoute
|
|
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
|
|
173
|
+
return possibleLayouts === null || possibleLayouts === void 0 ? void 0 : possibleLayouts[0];
|
|
83
174
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
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
|
|
package/routes-utils.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
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
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
package/auto-rooting.min.jsx
DELETED
|
@@ -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};
|
package/rooting.hooks.min.jsx
DELETED
|
@@ -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};
|