@plitzi/sdk-navigation 0.32.24 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @plitzi/sdk-navigation
2
2
 
3
+ ## 0.33.0
4
+
5
+ ### Minor Changes
6
+
7
+ - v0.33.0
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @plitzi/sdk-shared@0.33.0
13
+
14
+ ## 0.32.25
15
+
16
+ ### Patch Changes
17
+
18
+ - v0.32.25
19
+ - Updated dependencies
20
+ - @plitzi/sdk-shared@0.32.25
21
+
3
22
  ## 0.32.24
4
23
 
5
24
  ### Patch Changes
@@ -1,28 +1,2 @@
1
- import { PageFolder, Element } from '@plitzi/sdk-shared';
2
- import { PathMatch } from 'react-router-dom';
3
- export type NavigationAction = 'accessDenied' | 'normal' | 'redirect' | 'notFound';
4
- export type NavigationAccessLevel = 'public' | 'authenticated';
5
- export type Path = {
6
- accessLevel?: NavigationAccessLevel;
7
- enabled?: boolean;
8
- hasAccess: boolean;
9
- isRaw: boolean;
10
- pageId: string;
11
- path: string;
12
- unauthorizedBehaviour?: NavigationAction;
13
- unauthorizedPageRedirect?: string;
14
- };
15
- declare function getPageFullPath(pages: Record<string, Element>, pageFolders: PageFolder[], pageId: string, asString: true): string;
16
- declare function getPageFullPath(pages: Record<string, Element>, pageFolders: PageFolder[], pageId: string, asString?: false): Record<string, string>;
17
- declare const isPageAuthored: (accessLevel?: NavigationAccessLevel, authenticated?: boolean, previewMode?: boolean) => boolean;
18
- declare const getPaths: (pages?: Record<string, Element>, pageFolders?: PageFolder[], authenticated?: boolean, basePath?: string, previewMode?: boolean, strictMode?: boolean) => Path[];
19
- declare const matchRoutePath: (paths: Path[], pathName: string, authenticated: boolean) => {
20
- action: {
21
- type: "authenticated" | "accessDenied" | "redirect" | "notFound" | "normal";
22
- path?: string;
23
- };
24
- pathMatch?: PathMatch;
25
- pageId?: string;
26
- };
27
- declare const getRouteParams: (path: string) => string[];
28
- export { getPageFullPath, getPaths, matchRoutePath, isPageAuthored, getRouteParams };
1
+ export { getPageFullPath, getPaths, getRouteParams, isPageAuthored, matchPath, matchRoutePath } from '@plitzi/sdk-shared/navigation';
2
+ export type { NavigationAccessLevel, NavigationAction, Path, PathMatch, PathPattern } from '@plitzi/sdk-shared/navigation';
@@ -1,125 +1,2 @@
1
- import { get as e } from "@plitzi/plitzi-ui/helpers";
2
- import { matchPath as t } from "react-router-dom";
3
- //#region src/NavigationHelper.ts
4
- var n = (e) => e.replace(/{{([a-zA-Z0-9-_:*/]+)}}/i, ":$1").replaceAll(/[/]+/gim, "/"), r = (e, t) => {
5
- if (!t || !e[t]) return "";
6
- let { slug: n, parentId: i } = e[t];
7
- return i ? `${r(e, i)}/${n}` : n;
8
- };
9
- function i(t, i, a, o = !1) {
10
- let { slug: s = "", folder: c, default: l } = e(t, `${a}.attributes`, {
11
- slug: a,
12
- folder: "",
13
- default: !1
14
- });
15
- if (l && !o) return {
16
- "/": a,
17
- [`/${a}`]: a
18
- };
19
- if (l && o) return "/";
20
- if (!c && !o) return {
21
- [n(`/${s}`)]: a,
22
- [`/${a}`]: a
23
- };
24
- if (!c && o) return `/${s}`;
25
- if (!i.find((e) => e.id === c)) return o ? `/${s}` : {
26
- [n(`/${s}`)]: a,
27
- [`/${a}`]: a
28
- };
29
- let u = [r(i.reduce((e, t) => ({
30
- ...e,
31
- [t.id]: t
32
- }), {}), c), s || a].filter(Boolean).join("/");
33
- return o ? `/${u}` : {
34
- [`/${u}`]: a,
35
- [`/${a}`]: a
36
- };
37
- }
38
- var a = (e, t, n = !0) => !e || !n || t === void 0 || t && e === "authenticated" || !t && e === "public" ? !0 : t && e === "public" ? !1 : !e, o = (e = {}, t = [], n, r = "", o = !0, s = !0) => {
39
- let c = Object.keys(e).reduce((s, c) => {
40
- let { attributes: { accessLevel: l, enabled: u = !0, unauthorizedBehaviour: d } } = e[c], { attributes: { unauthorizedPageRedirect: f } } = e[c];
41
- if (!u && o) return s;
42
- f &&= i(e, t, f.replace("/", ""), !0);
43
- let p = i(e, t, c), m = Object.keys(p).map((e) => ({
44
- pageId: c,
45
- path: `${r}${e}`.replaceAll("//", "/"),
46
- accessLevel: l,
47
- enabled: u,
48
- isRaw: `/${c}` === e,
49
- unauthorizedBehaviour: d,
50
- unauthorizedPageRedirect: f,
51
- hasAccess: a(l, n, o)
52
- }));
53
- return [...s, ...m];
54
- }, []).filter((e) => e.path !== "*" || e.hasAccess).sort((e, t) => e.path === t.path ? e.accessLevel === "authenticated" ? -1 : 1 : e.path > t.path ? -1 : 1);
55
- if (!c.find((e) => e.path === "*") && !s) {
56
- let e = c.find((e) => e.path === "/" && e.hasAccess);
57
- e && e.unauthorizedBehaviour === "redirect" && e.unauthorizedPageRedirect && c.push({
58
- ...e,
59
- path: "*",
60
- hasAccess: !1,
61
- isRaw: !0,
62
- unauthorizedBehaviour: "redirect",
63
- unauthorizedPageRedirect: "/"
64
- });
65
- }
66
- return c;
67
- }, s = (e, n, r) => {
68
- if (!n) return {
69
- action: {
70
- type: "accessDenied",
71
- path: void 0
72
- },
73
- pathMatch: void 0
74
- };
75
- let i = [];
76
- e.forEach((e) => {
77
- let r = t({
78
- path: e.path,
79
- end: e.path !== "*"
80
- }, n);
81
- r && i.push({
82
- matchResult: r,
83
- path: e,
84
- pageId: e.pageId
85
- });
86
- });
87
- let a = i.find(({ path: { accessLevel: e } }) => e === "authenticated" && r || e === "public" && !r || !e);
88
- if (a ||= i.find(({ path: { accessLevel: e } }) => e === "authenticated" && !r || e === "public" && r), !a && e.find((e) => e.path === "/" && e.hasAccess)) return {
89
- action: {
90
- type: "redirect",
91
- path: "/"
92
- },
93
- pathMatch: void 0
94
- };
95
- if (!a) return {
96
- action: {
97
- type: "notFound",
98
- path: void 0
99
- },
100
- pathMatch: void 0
101
- };
102
- let { pageId: o, matchResult: s, path: { hasAccess: c, unauthorizedBehaviour: l, unauthorizedPageRedirect: u } } = a;
103
- return !c && l === "redirect" && u ? {
104
- action: {
105
- type: "redirect",
106
- path: u
107
- },
108
- pathMatch: void 0
109
- } : c ? {
110
- action: {
111
- type: "normal",
112
- path: void 0
113
- },
114
- pathMatch: s,
115
- pageId: o
116
- } : {
117
- action: {
118
- type: "accessDenied",
119
- path: void 0
120
- },
121
- pathMatch: void 0
122
- };
123
- }, c = (e) => !e || typeof e != "string" ? [] : (e.match(/:[a-zA-Z0-9-_:*]+/gim) || []).map((e) => e.replace(":", ""));
124
- //#endregion
125
- export { i as getPageFullPath, o as getPaths, c as getRouteParams, a as isPageAuthored, s as matchRoutePath };
1
+ import { getPageFullPath as e, getPaths as t, getRouteParams as n, isPageAuthored as r, matchPath as i, matchRoutePath as a } from "@plitzi/sdk-shared/navigation";
2
+ export { e as getPageFullPath, t as getPaths, n as getRouteParams, r as isPageAuthored, i as matchPath, a as matchRoutePath };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { default as useNavigation } from './hooks/useNavigation';
2
- import { default as NavigationContext } from './NavigationContext';
3
2
  import { getPageFullPath, getPaths, matchRoutePath, isPageAuthored } from './NavigationHelper';
4
- export * from './NavigationContext';
5
3
  export * from './NavigationHelper';
6
4
  export * from './hooks/useNavigation';
7
- export { getPageFullPath, getPaths, matchRoutePath, isPageAuthored, NavigationContext, useNavigation };
5
+ export { getPageFullPath, getPaths, matchRoutePath, isPageAuthored, useNavigation };
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
1
  import e from "./hooks/useNavigation.mjs";
2
- import t from "./NavigationContext.mjs";
3
- import { getPageFullPath as n, getPaths as r, getRouteParams as i, isPageAuthored as a, matchRoutePath as o } from "./NavigationHelper.mjs";
4
- export { t as NavigationContext, n as getPageFullPath, r as getPaths, i as getRouteParams, a as isPageAuthored, o as matchRoutePath, e as useNavigation };
2
+ import { getPageFullPath as t, getPaths as n, getRouteParams as r, isPageAuthored as i, matchPath as a, matchRoutePath as o } from "./NavigationHelper.mjs";
3
+ export { t as getPageFullPath, n as getPaths, r as getRouteParams, i as isPageAuthored, a as matchPath, o as matchRoutePath, e as useNavigation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-navigation",
3
- "version": "0.32.24",
3
+ "version": "0.33.0",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist"
@@ -10,10 +10,6 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.mjs"
12
12
  },
13
- "./NavigationContext": {
14
- "types": "./dist/NavigationContext.d.ts",
15
- "import": "./dist/NavigationContext.mjs"
16
- },
17
13
  "./NavigationHelper": {
18
14
  "types": "./dist/NavigationHelper.d.ts",
19
15
  "import": "./dist/NavigationHelper.mjs"
@@ -44,8 +40,9 @@
44
40
  "eslint": "^9.39.5",
45
41
  "react": "^19.2.8",
46
42
  "react-dom": "^19.2.8",
43
+ "react-router-dom": "^7.18.2",
47
44
  "typescript": "^6.0.3",
48
- "vite": "^8.2.0",
45
+ "vite": "^8.2.1",
49
46
  "vitest": "^4.1.10"
50
47
  },
51
48
  "peerDependencies": {
@@ -53,9 +50,7 @@
53
50
  "react-dom": "^19"
54
51
  },
55
52
  "dependencies": {
56
- "@plitzi/plitzi-ui": "^1.6.18",
57
- "@plitzi/sdk-shared": "0.32.24",
58
- "react-router": "^8.3.0",
59
- "react-router-dom": "^7.18.2"
53
+ "@plitzi/plitzi-ui": "^1.6.19",
54
+ "@plitzi/sdk-shared": "0.33.0"
60
55
  }
61
56
  }
@@ -1,3 +0,0 @@
1
- import { NavigationContextValue } from '@plitzi/sdk-shared';
2
- declare const NavigationContext: import('react').Context<NavigationContextValue>;
3
- export default NavigationContext;
@@ -1,5 +0,0 @@
1
- import { createContext as e } from "react";
2
- var t = e({});
3
- t.displayName = "NavigationContext";
4
- //#endregion
5
- export { t as default };