@hitachivantara/app-shell-navigation 0.1.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,7 +15,7 @@ const m = (t) => t.viewBundle !== void 0, S = (t) => typeof t != "string" && !m(
|
|
|
15
15
|
const c = a.replace(/\$/, "_");
|
|
16
16
|
let p, i;
|
|
17
17
|
c.startsWith("/") ? (p = s == null ? void 0 : s.id, i = c.substring(1)) : i = c;
|
|
18
|
-
const o = (h = (g = t.mainPanel) == null ? void 0 : g.views) == null ? void 0 : h.find((r) => r.bundle === `${i}` || r.bundle === `${i}.js` || r.bundle === `${p}/${i}.js` || r.bundle === `${p}
|
|
18
|
+
const o = (h = (g = t.mainPanel) == null ? void 0 : g.views) == null ? void 0 : h.find((r) => r.bundle === `${i}` || r.bundle === `${i}.js` || r.bundle === `${p}/${i}.js` || r.bundle === `${p}/${i}`);
|
|
19
19
|
return o != null && o.route ? `${H(o.route, n)}${l ?? ""}${f ?? ""}` : void 0;
|
|
20
20
|
}, [t, s == null ? void 0 : s.id]), b = $((e, a) => {
|
|
21
21
|
let n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigation.js","sources":["../../../../src/lib/hooks/useNavigation.tsx"],"sourcesContent":["import { useCallback, useContext } from \"react\";\nimport { Path, useNavigate } from \"react-router-dom\";\n\nimport {\n HvAppShellViewContext,\n useHvAppShellConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport { NavigationOptions, To, ViewDestination } from \"../types\";\nimport compileHref from \"../utils/navigationUtil\";\n\nconst isViewDestination = (to: To): to is ViewDestination => {\n return (to as ViewDestination).viewBundle !== undefined;\n};\n\nconst isPathDestination = (to: To): to is Partial<Path> => {\n return typeof to !== \"string\" && !isViewDestination(to);\n};\n\nconst useNavigation = () => {\n const config = useHvAppShellConfig();\n const viewContext = useContext(HvAppShellViewContext);\n const navigateReactRouter = useNavigate();\n\n /**\n * Utility to search for the route of an application view bundle directory on the App Shell configuration file.\n *\n * @param viewBundleDir The application view bundle directory name and optional route parameters.\n *\n * @returns The compiled route or undefined if none was found.\n */\n const getViewRoute = useCallback(\n (viewBundleDir: string | ViewDestination): string | undefined => {\n let viewBundle;\n let pathParams;\n let search;\n let hash;\n\n if (isViewDestination(viewBundleDir)) {\n ({ viewBundle, pathParams, search, hash } = viewBundleDir);\n } else {\n viewBundle = viewBundleDir;\n }\n const bundleWithReplacedPlaceholders = viewBundle.replace(/\\$/, \"_\");\n\n let appId: string | undefined;\n let bundle: string;\n\n // local navigation\n if (bundleWithReplacedPlaceholders.startsWith(\"/\")) {\n appId = viewContext?.id;\n bundle = bundleWithReplacedPlaceholders.substring(1);\n } else {\n bundle = bundleWithReplacedPlaceholders;\n }\n\n const view = config.mainPanel?.views?.find(\n v =>\n v.bundle === `${bundle}` ||\n v.bundle === `${bundle}.js` ||\n v.bundle === `${appId}/${bundle}.js` ||\n v.bundle === `${appId}
|
|
1
|
+
{"version":3,"file":"useNavigation.js","sources":["../../../../src/lib/hooks/useNavigation.tsx"],"sourcesContent":["import { useCallback, useContext } from \"react\";\nimport { Path, useNavigate } from \"react-router-dom\";\n\nimport {\n HvAppShellViewContext,\n useHvAppShellConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport { NavigationOptions, To, ViewDestination } from \"../types\";\nimport compileHref from \"../utils/navigationUtil\";\n\nconst isViewDestination = (to: To): to is ViewDestination => {\n return (to as ViewDestination).viewBundle !== undefined;\n};\n\nconst isPathDestination = (to: To): to is Partial<Path> => {\n return typeof to !== \"string\" && !isViewDestination(to);\n};\n\nconst useNavigation = () => {\n const config = useHvAppShellConfig();\n const viewContext = useContext(HvAppShellViewContext);\n const navigateReactRouter = useNavigate();\n\n /**\n * Utility to search for the route of an application view bundle directory on the App Shell configuration file.\n *\n * @param viewBundleDir The application view bundle directory name and optional route parameters.\n *\n * @returns The compiled route or undefined if none was found.\n */\n const getViewRoute = useCallback(\n (viewBundleDir: string | ViewDestination): string | undefined => {\n let viewBundle;\n let pathParams;\n let search;\n let hash;\n\n if (isViewDestination(viewBundleDir)) {\n ({ viewBundle, pathParams, search, hash } = viewBundleDir);\n } else {\n viewBundle = viewBundleDir;\n }\n const bundleWithReplacedPlaceholders = viewBundle.replace(/\\$/, \"_\");\n\n let appId: string | undefined;\n let bundle: string;\n\n // local navigation\n if (bundleWithReplacedPlaceholders.startsWith(\"/\")) {\n appId = viewContext?.id;\n bundle = bundleWithReplacedPlaceholders.substring(1);\n } else {\n bundle = bundleWithReplacedPlaceholders;\n }\n\n const view = config.mainPanel?.views?.find(\n v =>\n v.bundle === `${bundle}` ||\n v.bundle === `${bundle}.js` ||\n v.bundle === `${appId}/${bundle}.js` ||\n v.bundle === `${appId}/${bundle}`\n );\n\n return view?.route\n ? `${compileHref(view.route, pathParams)}${search ?? \"\"}${hash ?? \"\"}`\n : undefined;\n },\n [config, viewContext?.id]\n );\n\n /**\n * Performs navigation, through 'history.push' or 'history.replace', for the given destination with the passed navigation options.\n * @see https://reactrouter.com/hooks/use-navigate\n *\n * @param to The destination of the navigation. For ViewDestination type see {@link ViewDestination}.\n * @param options The navigation options.\n */\n const navigate = useCallback(\n (to: To, options?: Partial<NavigationOptions>) => {\n let path;\n if (isPathDestination(to)) {\n path = to;\n } else {\n const route = getViewRoute(to);\n\n if (route == null) {\n if (typeof to === \"string\") {\n path = to;\n } else {\n // If route for given module is not found on the App Shell configuration file, do nothing.\n console.warn(\n `Navigate request to a non existing path [${to.viewBundle}]. Skipping`\n );\n return;\n }\n } else {\n path = route;\n }\n }\n\n navigateReactRouter(path, options);\n },\n [getViewRoute, navigateReactRouter]\n );\n\n return { getViewRoute, navigate };\n};\nexport default useNavigation;\n"],"names":["isViewDestination","to","viewBundle","undefined","isPathDestination","useNavigation","config","useHvAppShellConfig","viewContext","useContext","HvAppShellViewContext","navigateReactRouter","useNavigate","getViewRoute","useCallback","viewBundleDir","pathParams","search","hash","bundleWithReplacedPlaceholders","replace","appId","bundle","startsWith","id","substring","view","mainPanel","views","find","v","route","compileHref","navigate","options","path","console","warn","useNavigation$1"],"mappings":";;;;AAWA,MAAMA,IAAoBA,CAACC,MACjBA,EAAuBC,eAAeC,QAG1CC,IAAoBA,CAACH,MAClB,OAAOA,KAAO,YAAY,CAACD,EAAkBC,CAAE,GAGlDI,IAAgBA,MAAM;AAC1B,QAAMC,IAASC,KACTC,IAAcC,EAAWC,CAAqB,GAC9CC,IAAsBC,KAStBC,IAAeC,EACnB,CAACC,MAAgE;;AAC3Db,QAAAA,GACAc,GACAC,GACAC;AAEAlB,IAAAA,EAAkBe,CAAa,IAChC;AAAA,MAAEb,YAAAA;AAAAA,MAAYc,YAAAA;AAAAA,MAAYC,QAAAA;AAAAA,MAAQC,MAAAA;AAAAA,IAASH,IAAAA,IAE/BA,IAAAA;AAEf,UAAMI,IAAiCjB,EAAWkB,QAAQ,MAAM,GAAG;AAE/DC,QAAAA,GACAC;AAGAH,IAAAA,EAA+BI,WAAW,GAAG,KAC/CF,IAAQb,KAAAA,gBAAAA,EAAagB,IACZL,IAAAA,EAA+BM,UAAU,CAAC,KAE1CN,IAAAA;AAGX,UAAMO,KAAOpB,KAAAA,IAAAA,EAAOqB,cAAPrB,gBAAAA,EAAkBsB,UAAlBtB,gBAAAA,EAAyBuB,KACpCC,CAAAA,MACEA,EAAER,WAAY,GAAEA,CAAO,MACvBQ,EAAER,WAAY,GAAEA,CAAO,SACvBQ,EAAER,WAAY,GAAED,CAAM,IAAGC,CAAO,SAChCQ,EAAER,WAAY,GAAED,CAAM,IAAGC,CAAO;AAGpC,WAAOI,KAAAA,QAAAA,EAAMK,QACR,GAAEC,EAAYN,EAAKK,OAAOf,CAAU,CAAE,GAAEC,KAAU,EAAG,GAAEC,KAAQ,EAAG,KACnEf;AAAAA,EAEN,GAAA,CAACG,GAAQE,KAAAA,gBAAAA,EAAagB,EAAE,CAC1B,GASMS,IAAWnB,EACf,CAACb,GAAQiC,MAAyC;AAC5CC,QAAAA;AACA/B,QAAAA,EAAkBH,CAAE;AACfA,MAAAA,IAAAA;AAAAA,SACF;AACC8B,YAAAA,IAAQlB,EAAaZ,CAAE;AAE7B,UAAI8B,KAAS;AACP,YAAA,OAAO9B,KAAO;AACTA,UAAAA,IAAAA;AAAAA,aACF;AAELmC,kBAAQC,KACL,4CAA2CpC,EAAGC,UAAW,aAC5D;AACA;AAAA,QACF;AAAA;AAEO6B,QAAAA,IAAAA;AAAAA,IAEX;AAEApB,IAAAA,EAAoBwB,GAAMD,CAAO;AAAA,EAAA,GAEnC,CAACrB,GAAcF,CAAmB,CACpC;AAEO,SAAA;AAAA,IAAEE,cAAAA;AAAAA,IAAcoB,UAAAA;AAAAA,EAAAA;AACzB,GACAK,IAAejC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/app-shell-navigation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "AppShell Navigation",
|
|
5
5
|
"author": "Hitachi Vantara - Boba Fett Team",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"coverage": "vitest run --coverage"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@hitachivantara/app-shell-shared": "0.
|
|
38
|
+
"@hitachivantara/app-shell-shared": "1.0.0",
|
|
39
39
|
"path-to-regexp": "^6.2.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"vite-plugin-dts": "^3.6.4",
|
|
57
57
|
"vite-tsconfig-paths": "^4.0.5"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "350741fa1c73417931caede99e0193b6955a9a29"
|
|
60
60
|
}
|