@gravitee/gamma-modules-sdk 1.0.0-alpha.1 → 1.0.0-alpha.1-feat-routing.df22a7d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routing.d.ts +53 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +62 -0
- package/package.json +11 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routing domain — generic helpers for federated modules mounted under the
|
|
3
|
+
* gamma host URL scheme `/environments/:envHrid/:moduleId/<routeKey>`.
|
|
4
|
+
*/
|
|
5
|
+
export interface ModuleRouteDefinition {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly label: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ModuleRouteConfig<K extends string = string> {
|
|
10
|
+
readonly routeKeys: readonly K[];
|
|
11
|
+
readonly routes: Record<K, ModuleRouteDefinition>;
|
|
12
|
+
readonly defaultRouteKey: K;
|
|
13
|
+
}
|
|
14
|
+
/** Type-guard: is `segment` one of the declared route keys? */
|
|
15
|
+
export declare function isRouteKey<K extends string>(segment: string, routeKeys: readonly K[]): segment is K;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the active sidebar key and optional host module prefix from the URL.
|
|
18
|
+
*
|
|
19
|
+
* Handles three mounting modes:
|
|
20
|
+
* 1. **Federated** — `/environments/:envHrid/:moduleId/<routeKey>`
|
|
21
|
+
* 2. **Standalone with prefix** — `/:moduleId/<routeKey>`
|
|
22
|
+
* 3. **Legacy standalone** — `/<routeKey>` (first segment is itself a key)
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveModulePath<K extends string>(pathname: string, config: ModuleRouteConfig<K>): {
|
|
25
|
+
modulePrefix: string;
|
|
26
|
+
activeNavKey: K;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Pure string builder: returns the target pathname for navigating to a route
|
|
30
|
+
* key inside a module.
|
|
31
|
+
*
|
|
32
|
+
* When federated, the environment prefix is extracted from `currentPathname`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildModuleNavPath(modulePrefix: string, key: string, currentPathname?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the "root" pathname for breadcrumbs (e.g. the module's landing page
|
|
37
|
+
* under the current environment).
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildModuleRootPath(pathname: string, modulePrefix: string, defaultRouteKey: string): string;
|
|
40
|
+
export interface ModuleRoutingResult<K extends string = string> {
|
|
41
|
+
modulePrefix: string;
|
|
42
|
+
activeNavKey: K;
|
|
43
|
+
navigateToKey: (key: string) => void;
|
|
44
|
+
rootPath: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Convenience hook that composes the pure routing helpers for a federated module.
|
|
48
|
+
*
|
|
49
|
+
* Returns raw data — no JSX, no graphene types. Modules use the returned values
|
|
50
|
+
* to wire graphene layout components in their own `ModuleLayout`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useModuleRouting<K extends string>(config: ModuleRouteConfig<K>): ModuleRoutingResult<K>;
|
|
53
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../src/routing.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AAIH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAClD,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC;CAC7B;AAID,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,CAEnG;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC3B;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,CAAC,CAAA;CAAE,CAqB3C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAUtG;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAS3G;AAID,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,CAAC,CAAC;IAChB,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsBvG"}
|
package/dist/routing.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useCallback as e, useMemo as t } from "react";
|
|
2
|
+
import { useLocation as n, useNavigate as r } from "react-router-dom";
|
|
3
|
+
//#region src/routing.ts
|
|
4
|
+
function i(e, t) {
|
|
5
|
+
return t.includes(e);
|
|
6
|
+
}
|
|
7
|
+
function a(e, t) {
|
|
8
|
+
let n = e.split("/").filter(Boolean), { routeKeys: r, defaultRouteKey: a } = t;
|
|
9
|
+
if (n.length === 0) return {
|
|
10
|
+
modulePrefix: "",
|
|
11
|
+
activeNavKey: a
|
|
12
|
+
};
|
|
13
|
+
if (n[0] === "environments" && n.length >= 3) {
|
|
14
|
+
let e = n[2], t = n[3] ?? a;
|
|
15
|
+
return {
|
|
16
|
+
modulePrefix: e,
|
|
17
|
+
activeNavKey: i(t, r) ? t : a
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (i(n[0], r)) return {
|
|
21
|
+
modulePrefix: "",
|
|
22
|
+
activeNavKey: n[0]
|
|
23
|
+
};
|
|
24
|
+
let o = n[0], s = n[1] ?? a;
|
|
25
|
+
return {
|
|
26
|
+
modulePrefix: o,
|
|
27
|
+
activeNavKey: i(s, r) ? s : a
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function o(e, t, n) {
|
|
31
|
+
if (e) {
|
|
32
|
+
let r = n ?? (typeof window < "u" ? window.location.pathname : ""), i = r.indexOf("/", 14);
|
|
33
|
+
return r.startsWith("/environments/") && i > 0 ? `${r.slice(0, i)}/${e}/${t}` : `/${e}/${t}`;
|
|
34
|
+
}
|
|
35
|
+
return `/${t}`;
|
|
36
|
+
}
|
|
37
|
+
function s(e, t, n) {
|
|
38
|
+
if (!t) return "/";
|
|
39
|
+
let r = e.indexOf("/", 14);
|
|
40
|
+
return e.startsWith("/environments/") && r > 0 ? `${e.slice(0, r)}/${t}/${n}` : `/${t}/${n}`;
|
|
41
|
+
}
|
|
42
|
+
function c(i) {
|
|
43
|
+
let c = n(), l = r(), { modulePrefix: u, activeNavKey: d } = t(() => a(c.pathname, i), [c.pathname, i]), f = t(() => s(c.pathname, u, i.defaultRouteKey), [
|
|
44
|
+
c.pathname,
|
|
45
|
+
u,
|
|
46
|
+
i.defaultRouteKey
|
|
47
|
+
]);
|
|
48
|
+
return {
|
|
49
|
+
modulePrefix: u,
|
|
50
|
+
activeNavKey: d,
|
|
51
|
+
navigateToKey: e((e) => {
|
|
52
|
+
l(o(u, e, c.pathname));
|
|
53
|
+
}, [
|
|
54
|
+
l,
|
|
55
|
+
u,
|
|
56
|
+
c.pathname
|
|
57
|
+
]),
|
|
58
|
+
rootPath: f
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { o as buildModuleNavPath, s as buildModuleRootPath, i as isRouteKey, a as resolveModulePath, c as useModuleRouting };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravitee/gamma-modules-sdk",
|
|
3
|
-
"version": "1.0.0-alpha.1",
|
|
3
|
+
"version": "1.0.0-alpha.1-feat-routing.df22a7d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"packageManager": "yarn@4.13.0",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
},
|
|
20
20
|
"./types": {
|
|
21
21
|
"types": "./dist/types.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./routing": {
|
|
24
|
+
"types": "./dist/routing.d.ts",
|
|
25
|
+
"import": "./dist/routing.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"scripts": {
|
|
@@ -28,12 +32,14 @@
|
|
|
28
32
|
"lint:fix:all": "yarn lint:fix && yarn format",
|
|
29
33
|
"typecheck": "tsc --noEmit",
|
|
30
34
|
"format": "prettier --write .",
|
|
35
|
+
"test": "vitest run",
|
|
31
36
|
"format:check": "prettier --check .",
|
|
32
37
|
"prepare": "husky"
|
|
33
38
|
},
|
|
34
39
|
"peerDependencies": {
|
|
35
40
|
"react": ">=19",
|
|
36
|
-
"react-dom": ">=19"
|
|
41
|
+
"react-dom": ">=19",
|
|
42
|
+
"react-router-dom": ">=6"
|
|
37
43
|
},
|
|
38
44
|
"devDependencies": {
|
|
39
45
|
"@commitlint/cli": "20.5.0",
|
|
@@ -60,11 +66,13 @@
|
|
|
60
66
|
"prettier": "3.8.3",
|
|
61
67
|
"react": "19.2.5",
|
|
62
68
|
"react-dom": "19.2.5",
|
|
69
|
+
"react-router-dom": "7.6.1",
|
|
63
70
|
"semantic-release": "25.0.3",
|
|
64
71
|
"typescript": "6.0.3",
|
|
65
72
|
"typescript-eslint": "8.58.2",
|
|
66
73
|
"vite": "8.0.8",
|
|
67
|
-
"vite-plugin-dts": "4.5.4"
|
|
74
|
+
"vite-plugin-dts": "4.5.4",
|
|
75
|
+
"vitest": "3.2.1"
|
|
68
76
|
},
|
|
69
77
|
"lint-staged": {
|
|
70
78
|
"*.{ts,tsx}": [
|