@pnkx-lib/ui 1.9.448 → 1.9.450
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default from 'react';
|
|
4
|
-
import { useLocation, Link } from 'react-router';
|
|
4
|
+
import { useLocation, generatePath, Link } from 'react-router';
|
|
5
5
|
|
|
6
6
|
const extractRoutesFromMenu = (menuItems) => {
|
|
7
7
|
const routes = [];
|
|
@@ -54,17 +54,31 @@ function validateAbsolutePaths(menu, nearestAncestorPath) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
function compilePattern(pattern) {
|
|
58
|
+
const pat = normalize(pattern);
|
|
59
|
+
const keys = [];
|
|
60
|
+
const escaped = pat.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
61
|
+
const withCaptures = escaped.replace(/:([^/]+)/g, (_m, key) => {
|
|
62
|
+
keys.push(key);
|
|
63
|
+
return "([^/]+)";
|
|
64
|
+
});
|
|
65
|
+
const regex = new RegExp(`^${withCaptures}/?$`);
|
|
66
|
+
return { regex, keys };
|
|
67
|
+
}
|
|
68
|
+
function matchPath(pattern, pathname) {
|
|
69
|
+
const { regex } = compilePattern(pattern);
|
|
70
|
+
return regex.test(normalize(pathname));
|
|
71
|
+
}
|
|
72
|
+
function extractParams(pattern, pathname) {
|
|
73
|
+
const { regex, keys } = compilePattern(pattern);
|
|
74
|
+
const m = regex.exec(normalize(pathname));
|
|
75
|
+
if (!m) return {};
|
|
76
|
+
const out = {};
|
|
77
|
+
for (let i = 0; i < keys.length; i++) out[keys[i]] = m[i + 1];
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
const hasParams = (p) => !!p && /:([^/]+)/.test(p ?? "");
|
|
63
81
|
const full = (itemPath) => normalize(itemPath ?? "/");
|
|
64
|
-
const matchPath = (configPath, pathname) => {
|
|
65
|
-
const rx = pathToRegex(configPath);
|
|
66
|
-
return rx.test(normalize(pathname));
|
|
67
|
-
};
|
|
68
82
|
function findTrail(menu, pathUrl) {
|
|
69
83
|
const trail = [];
|
|
70
84
|
const walk = (items) => {
|
|
@@ -87,16 +101,38 @@ function useBreadcrumb(menuRouter, customBreadcrumb) {
|
|
|
87
101
|
() => findTrail(menuRouter, normalizedPath),
|
|
88
102
|
[menuRouter, normalizedPath]
|
|
89
103
|
);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
const leaf = React.useMemo(
|
|
105
|
+
() => trail.length ? trail[trail.length - 1] : void 0,
|
|
106
|
+
[trail]
|
|
107
|
+
);
|
|
108
|
+
const paramsFromLeaf = React.useMemo(
|
|
109
|
+
() => leaf?.path ? extractParams(leaf.path, normalizedPath) : {},
|
|
110
|
+
[leaf?.path, normalizedPath]
|
|
95
111
|
);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
112
|
+
const filteredTrail = React.useMemo(() => {
|
|
113
|
+
if (!trail.length || leaf?.isShowBreadcrumb !== true) return [];
|
|
114
|
+
return trail.filter(
|
|
115
|
+
(node, i) => i === trail.length - 1 || Boolean(node.path)
|
|
116
|
+
);
|
|
117
|
+
}, [trail, leaf]);
|
|
118
|
+
if (!filteredTrail.length) return [];
|
|
119
|
+
const last = filteredTrail.length - 1;
|
|
120
|
+
const items = filteredTrail.map((node, i) => {
|
|
121
|
+
const isLast = i === last;
|
|
122
|
+
const pattern = node.path ?? node.fullPath;
|
|
123
|
+
let href;
|
|
124
|
+
if (pattern) {
|
|
125
|
+
href = hasParams(pattern) ? (() => {
|
|
126
|
+
try {
|
|
127
|
+
return generatePath(pattern, paramsFromLeaf);
|
|
128
|
+
} catch {
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
131
|
+
})() : pattern;
|
|
132
|
+
}
|
|
133
|
+
const titleNode = isLast ? /* @__PURE__ */ jsx("span", { children: node.name }) : href ? /* @__PURE__ */ jsx(Link, { to: href, children: node.name }) : /* @__PURE__ */ jsx("span", { children: node.name });
|
|
134
|
+
return { title: titleNode };
|
|
135
|
+
});
|
|
100
136
|
return [
|
|
101
137
|
...items,
|
|
102
138
|
...customBreadcrumb?.length ? [
|
package/es/index.js
CHANGED
|
@@ -84,7 +84,7 @@ export { Cascader } from './fields/CascaderField.js';
|
|
|
84
84
|
export { InputRangePicker } from './fields/InputRangePicker.js';
|
|
85
85
|
export { useToast } from './hooks/useToast.js';
|
|
86
86
|
export { useMessage } from './hooks/useMessage.js';
|
|
87
|
-
export { c as createComponentWithProps, e as extractRoutesFromMenu, n as normalize, v as validateAbsolutePaths } from './chunks/useBreadcrumb-
|
|
87
|
+
export { c as createComponentWithProps, e as extractRoutesFromMenu, n as normalize, v as validateAbsolutePaths } from './chunks/useBreadcrumb-DtXCsh1h.js';
|
|
88
88
|
|
|
89
89
|
const generateId = (name, path) => {
|
|
90
90
|
const source = `${name}-${path || ""}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { r } from '../chunks/index-t0ynpS_n.js';
|
|
3
3
|
import { Breadcrumb } from './Breadcrumb.js';
|
|
4
|
-
import { u as useBreadcrumb } from '../chunks/useBreadcrumb-
|
|
4
|
+
import { u as useBreadcrumb } from '../chunks/useBreadcrumb-DtXCsh1h.js';
|
|
5
5
|
|
|
6
6
|
const BreadcrumbHeading = (props) => {
|
|
7
7
|
const { menu, customBreadcum } = props;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { u as useBreadcrumb } from '../chunks/useBreadcrumb-
|
|
2
|
+
import { u as useBreadcrumb } from '../chunks/useBreadcrumb-DtXCsh1h.js';
|
|
3
3
|
import { Breadcrumb } from './Breadcrumb.js';
|
|
4
4
|
|
|
5
5
|
const WrapperBreadcrumb = ({ menu }) => {
|