@pnkx-lib/ui 1.9.447 → 1.9.449

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 = [];
@@ -61,10 +61,17 @@ const pathToRegex = (pattern) => {
61
61
  return new RegExp(`^${withParams}/?$`);
62
62
  };
63
63
  const full = (itemPath) => normalize(itemPath ?? "/");
64
- const matchPath = (configPath, pathname) => {
65
- const rx = pathToRegex(configPath);
66
- return rx.test(normalize(pathname));
67
- };
64
+ const matchPath = (configPath, pathname) => pathToRegex(configPath).test(normalize(pathname));
65
+ function extractParams(pattern, pathname) {
66
+ const pat = normalize(pattern);
67
+ const path = normalize(pathname);
68
+ const escaped = pat.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
69
+ const named = escaped.replace(/:([^/]+)/g, (_, key) => `(?<${key}>[^/]+)`);
70
+ const rx = new RegExp(`^${named}/?$`);
71
+ const m = rx.exec(path);
72
+ return m?.groups ?? {};
73
+ }
74
+ const hasParams = (p) => !!p && /:([^/]+)/.test(p ?? "");
68
75
  function findTrail(menu, pathUrl) {
69
76
  const trail = [];
70
77
  const walk = (items) => {
@@ -87,16 +94,38 @@ function useBreadcrumb(menuRouter, customBreadcrumb) {
87
94
  () => findTrail(menuRouter, normalizedPath),
88
95
  [menuRouter, normalizedPath]
89
96
  );
90
- if (trail.length === 0) return [];
91
- const leaf = trail[trail.length - 1];
92
- if (leaf.isShowBreadcrumb !== true) return [];
93
- const filtered = trail.filter(
94
- (node, i) => i === trail.length - 1 || Boolean(node.path)
97
+ const leaf = React.useMemo(
98
+ () => trail.length ? trail[trail.length - 1] : void 0,
99
+ [trail]
95
100
  );
96
- const last = filtered.length - 1;
97
- const items = filtered.map((node, i) => ({
98
- title: i === last ? /* @__PURE__ */ jsx("span", { children: node.name }) : /* @__PURE__ */ jsx(Link, { to: node.fullPath, children: node.name })
99
- }));
101
+ const paramsFromLeaf = React.useMemo(
102
+ () => leaf?.path ? extractParams(leaf.path, normalizedPath) : {},
103
+ [leaf?.path, normalizedPath]
104
+ );
105
+ const filteredTrail = React.useMemo(() => {
106
+ if (!trail.length || leaf?.isShowBreadcrumb !== true) return [];
107
+ return trail.filter(
108
+ (node, i) => i === trail.length - 1 || Boolean(node.path)
109
+ );
110
+ }, [trail, leaf]);
111
+ if (!filteredTrail.length) return [];
112
+ const last = filteredTrail.length - 1;
113
+ const items = filteredTrail.map((node, i) => {
114
+ const isLast = i === last;
115
+ const pattern = node.path ?? node.fullPath;
116
+ let href;
117
+ if (pattern) {
118
+ href = hasParams(pattern) ? (() => {
119
+ try {
120
+ return generatePath(pattern, paramsFromLeaf);
121
+ } catch {
122
+ return void 0;
123
+ }
124
+ })() : pattern;
125
+ }
126
+ const titleNode = isLast ? /* @__PURE__ */ jsx("span", { children: node.name }) : href ? /* @__PURE__ */ jsx(Link, { to: href, children: node.name }) : /* @__PURE__ */ jsx("span", { children: node.name });
127
+ return { title: titleNode };
128
+ });
100
129
  return [
101
130
  ...items,
102
131
  ...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-CpCPSE3S.js';
87
+ export { c as createComponentWithProps, e as extractRoutesFromMenu, n as normalize, v as validateAbsolutePaths } from './chunks/useBreadcrumb-CQA2mBvb.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-CpCPSE3S.js';
4
+ import { u as useBreadcrumb } from '../chunks/useBreadcrumb-CQA2mBvb.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-CpCPSE3S.js';
2
+ import { u as useBreadcrumb } from '../chunks/useBreadcrumb-CQA2mBvb.js';
3
3
  import { Breadcrumb } from './Breadcrumb.js';
4
4
 
5
5
  const WrapperBreadcrumb = ({ menu }) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pnkx-lib/ui",
3
3
  "private": false,
4
- "version": "1.9.447",
4
+ "version": "1.9.449",
5
5
  "type": "module",
6
6
  "main": "./es/index.js",
7
7
  "module": "./es/index.js",