asab_webui_shell 27.8.3 → 27.8.5
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.
|
@@ -12,18 +12,16 @@ var _reactI18next = require("react-i18next");
|
|
|
12
12
|
var _reactstrap = require("reactstrap");
|
|
13
13
|
var _asab_webui_components = require("asab_webui_components");
|
|
14
14
|
var _SidebarIcon = _interopRequireDefault(require("./SidebarIcon"));
|
|
15
|
+
var _sidebarRouteMatch = require("./utils/sidebarRouteMatch.js");
|
|
15
16
|
var cache;
|
|
16
17
|
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
17
18
|
var SidebarItem = _ref => {
|
|
18
19
|
var _item$name;
|
|
19
20
|
var item = _ref.item,
|
|
20
21
|
disabled = _ref.disabled,
|
|
21
|
-
isOpen = _ref.isOpen,
|
|
22
|
-
setOpen = _ref.setOpen,
|
|
23
22
|
isSmallResolution = _ref.isSmallResolution,
|
|
24
23
|
_ref$beacon = _ref.beacon,
|
|
25
|
-
beacon = _ref$beacon === void 0 ? undefined : _ref$beacon
|
|
26
|
-
openFor = _ref.openFor;
|
|
24
|
+
beacon = _ref$beacon === void 0 ? undefined : _ref$beacon;
|
|
27
25
|
var location = (0, _reactRouter.useLocation)();
|
|
28
26
|
var _useTranslation = (0, _reactI18next.useTranslation)(),
|
|
29
27
|
t = _useTranslation.t;
|
|
@@ -36,15 +34,11 @@ var SidebarItem = _ref => {
|
|
|
36
34
|
isActive = _useState2[0],
|
|
37
35
|
setActive = _useState2[1];
|
|
38
36
|
var lowercasedItemName = item === null || item === void 0 || (_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.toLowerCase();
|
|
39
|
-
// Attention
|
|
37
|
+
// Attention required flag
|
|
40
38
|
var itemBeacon = beacon === null || beacon === void 0 ? void 0 : beacon["beacon.".concat(lowercasedItemName)];
|
|
41
39
|
(0, _react.useEffect)(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
setOpen(false);
|
|
45
|
-
}
|
|
46
|
-
setActive(Boolean(item.url && (location.pathname === item.url || location.pathname.startsWith(item.url + '/'))) || matchesOpenFor(location.pathname, item.openFor));
|
|
47
|
-
}, [location]);
|
|
40
|
+
setActive(Boolean(item.url && (location.pathname === item.url || location.pathname.startsWith(item.url + '/'))) || (0, _sidebarRouteMatch.matchesOpenFor)(location.pathname, item.openFor));
|
|
41
|
+
}, [location.pathname]);
|
|
48
42
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
49
43
|
className: "nav-item"
|
|
50
44
|
}, /*#__PURE__*/_react.default.createElement(_reactRouter.Link, {
|
|
@@ -81,12 +75,16 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
81
75
|
disabled = _ref2.disabled,
|
|
82
76
|
isSmallResolution = _ref2.isSmallResolution,
|
|
83
77
|
_ref2$beacon = _ref2.beacon,
|
|
84
|
-
beacon = _ref2$beacon === void 0 ? undefined : _ref2$beacon
|
|
85
|
-
|
|
78
|
+
beacon = _ref2$beacon === void 0 ? undefined : _ref2$beacon,
|
|
79
|
+
_ref2$defaultOpen = _ref2.defaultOpen,
|
|
80
|
+
defaultOpen = _ref2$defaultOpen === void 0 ? false : _ref2$defaultOpen;
|
|
81
|
+
var _useState3 = (0, _react.useState)(defaultOpen),
|
|
86
82
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
87
83
|
isOpen = _useState4[0],
|
|
88
84
|
setOpen = _useState4[1];
|
|
89
85
|
var location = (0, _reactRouter.useLocation)();
|
|
86
|
+
//Track the last pathname to avoid a React Strict Mode double-invoke (same pathname, different effect run)
|
|
87
|
+
var lastPathname = (0, _react.useRef)(null);
|
|
90
88
|
var _useTranslation2 = (0, _reactI18next.useTranslation)(),
|
|
91
89
|
t = _useTranslation2.t;
|
|
92
90
|
var isSidebarCollapsed = (0, _asab_webui_components.useAppSelector)(state => {
|
|
@@ -102,21 +100,34 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
102
100
|
return sum + (current.count || 0); // Ensure we sum only valid count values
|
|
103
101
|
}, 0) : 0;
|
|
104
102
|
|
|
105
|
-
//
|
|
103
|
+
// Open or close the collapsible based on whether the current route belongs to it.
|
|
104
|
+
// All open/close logic lives here so individual child items cannot conflict with each other.
|
|
106
105
|
(0, _react.useEffect)(() => {
|
|
107
|
-
if (item.children
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
if (!item.children) return;
|
|
107
|
+
var shouldBeOpen = (0, _sidebarRouteMatch.collapsibleMatchesRoute)(location.pathname, item);
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
Detect a real navigation vs. mount / Strict Mode double-invoke.
|
|
111
|
+
Strict Mode runs the effect twice with the same pathname; comparing against
|
|
112
|
+
the last handled pathname (rather than a boolean flag) correctly treats
|
|
113
|
+
both runs as "mount" and never closes a defaultOpen collapsible.
|
|
114
|
+
*/
|
|
115
|
+
var isNavigation = lastPathname.current !== null && lastPathname.current !== location.pathname;
|
|
116
|
+
lastPathname.current = location.pathname;
|
|
117
|
+
if (!isNavigation) {
|
|
118
|
+
// Mount (or Strict Mode re-mount): only auto-open, never auto-close.
|
|
119
|
+
if (shouldBeOpen) setOpen(true);
|
|
120
|
+
return;
|
|
118
121
|
}
|
|
119
|
-
|
|
122
|
+
|
|
123
|
+
// On subsequent navigations: use the functional updater so isOpen is never stale
|
|
124
|
+
// and never needs to be listed as a dependency.
|
|
125
|
+
setOpen(prev => {
|
|
126
|
+
if (!prev && shouldBeOpen) return true;
|
|
127
|
+
if (prev && !shouldBeOpen) return false;
|
|
128
|
+
return prev;
|
|
129
|
+
});
|
|
130
|
+
}, [location.pathname]);
|
|
120
131
|
var onClickOpen = e => {
|
|
121
132
|
e.preventDefault();
|
|
122
133
|
setOpen(!isOpen);
|
|
@@ -167,10 +178,7 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
167
178
|
key: idx,
|
|
168
179
|
item: child,
|
|
169
180
|
disabled: disabled,
|
|
170
|
-
isOpen: isOpen,
|
|
171
|
-
setOpen: setOpen,
|
|
172
181
|
isSmallResolution: isSmallResolution,
|
|
173
|
-
openFor: item.openFor,
|
|
174
182
|
beacon: itemsBeacon["beacon.".concat(child === null || child === void 0 || (_child$name = child.name) === null || _child$name === void 0 ? void 0 : _child$name.toLowerCase())] && childBeacon(itemsBeacon, "beacon.".concat(child.name.toLowerCase()))
|
|
175
183
|
});
|
|
176
184
|
})));
|
|
@@ -193,16 +201,4 @@ var childBeacon = (data, key) => {
|
|
|
193
201
|
return data[key] ? {
|
|
194
202
|
[key]: data[key]
|
|
195
203
|
} : {};
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
// Optional item.openFor patterns, e.g. ['/route/*'] - keeps parent open on matching routes
|
|
199
|
-
var matchesOpenFor = (pathname, patterns) => {
|
|
200
|
-
var _patterns$some;
|
|
201
|
-
return (_patterns$some = patterns === null || patterns === void 0 ? void 0 : patterns.some(p => {
|
|
202
|
-
if (p.endsWith('*')) {
|
|
203
|
-
var prefix = p.slice(0, -1);
|
|
204
|
-
return pathname.startsWith(prefix) || pathname === prefix.slice(0, -1);
|
|
205
|
-
}
|
|
206
|
-
return pathname === p || pathname.startsWith(p + '/');
|
|
207
|
-
})) !== null && _patterns$some !== void 0 ? _patterns$some : false;
|
|
208
204
|
};
|
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.SidebarItemRenderer = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactRouter = require("react-router");
|
|
9
10
|
var _SidebarItem = require("./SidebarItem");
|
|
11
|
+
var _sidebarRouteMatch = require("./utils/sidebarRouteMatch.js");
|
|
10
12
|
var SidebarItemRenderer = _ref => {
|
|
11
13
|
var sidebarItems = _ref.sidebarItems,
|
|
12
14
|
sessionExpired = _ref.sessionExpired,
|
|
@@ -14,6 +16,12 @@ var SidebarItemRenderer = _ref => {
|
|
|
14
16
|
isSmallResolution = _ref$isSmallResolutio === void 0 ? undefined : _ref$isSmallResolutio,
|
|
15
17
|
_ref$beacon = _ref.beacon,
|
|
16
18
|
beacon = _ref$beacon === void 0 ? undefined : _ref$beacon;
|
|
19
|
+
var location = (0, _reactRouter.useLocation)();
|
|
20
|
+
/*
|
|
21
|
+
Default-open the first collapsible unless some other sidebar item already owns the route.
|
|
22
|
+
If the first item itself matches (e.g. its child), start open to avoid a closed-then-open flash.
|
|
23
|
+
*/
|
|
24
|
+
var otherItemOwnsRoute = sidebarItems === null || sidebarItems === void 0 ? void 0 : sidebarItems.slice(1).some(item => (0, _sidebarRouteMatch.navItemMatchesRoute)(location.pathname, item));
|
|
17
25
|
return /*#__PURE__*/_react.default.createElement("nav", {
|
|
18
26
|
className: "nav flex-column"
|
|
19
27
|
}, sidebarItems.map((item, idx) => item.children ? /*#__PURE__*/_react.default.createElement(_SidebarItem.SidebarCollapsibleItem, {
|
|
@@ -21,7 +29,8 @@ var SidebarItemRenderer = _ref => {
|
|
|
21
29
|
item: item,
|
|
22
30
|
disabled: sessionExpired,
|
|
23
31
|
isSmallResolution: isSmallResolution,
|
|
24
|
-
beacon: beacon
|
|
32
|
+
beacon: beacon,
|
|
33
|
+
defaultOpen: idx === 0 && !otherItemOwnsRoute
|
|
25
34
|
}) : /*#__PURE__*/_react.default.createElement(_SidebarItem.SidebarItem, {
|
|
26
35
|
key: idx,
|
|
27
36
|
item: item,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.navItemMatchesRoute = exports.matchesOpenFor = exports.collapsibleMatchesRoute = void 0;
|
|
7
|
+
// Optional item.openFor patterns, e.g. ['/route/*'] - keeps parent open on matching routes
|
|
8
|
+
var matchesOpenFor = (pathname, patterns) => {
|
|
9
|
+
var _patterns$some;
|
|
10
|
+
return (_patterns$some = patterns === null || patterns === void 0 ? void 0 : patterns.some(p => {
|
|
11
|
+
if (p.endsWith('*')) {
|
|
12
|
+
var prefix = p.slice(0, -1);
|
|
13
|
+
return pathname.startsWith(prefix) || pathname === prefix.slice(0, -1);
|
|
14
|
+
}
|
|
15
|
+
return pathname === p || pathname.startsWith(p + '/');
|
|
16
|
+
})) !== null && _patterns$some !== void 0 ? _patterns$some : false;
|
|
17
|
+
};
|
|
18
|
+
exports.matchesOpenFor = matchesOpenFor;
|
|
19
|
+
var collapsibleMatchesRoute = (pathname, item) => {
|
|
20
|
+
if (!(item !== null && item !== void 0 && item.children)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (matchesOpenFor(pathname, item.openFor)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return item.children.some(child => child.url && (pathname === child.url || pathname.startsWith(child.url + '/')) || matchesOpenFor(pathname, child.openFor));
|
|
27
|
+
};
|
|
28
|
+
exports.collapsibleMatchesRoute = collapsibleMatchesRoute;
|
|
29
|
+
var navItemMatchesRoute = (pathname, item) => {
|
|
30
|
+
if (item !== null && item !== void 0 && item.children) {
|
|
31
|
+
return collapsibleMatchesRoute(pathname, item);
|
|
32
|
+
}
|
|
33
|
+
return Boolean((item === null || item === void 0 ? void 0 : item.url) && (pathname === item.url || pathname.startsWith(item.url + '/'))) || matchesOpenFor(pathname, item === null || item === void 0 ? void 0 : item.openFor);
|
|
34
|
+
};
|
|
35
|
+
exports.navItemMatchesRoute = navItemMatchesRoute;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Optional item.openFor patterns, e.g. ['/route/*'] - keeps parent open on matching routes
|
|
2
|
+
export const matchesOpenFor = (pathname, patterns) =>
|
|
3
|
+
patterns?.some((p) => {
|
|
4
|
+
if (p.endsWith('*')) {
|
|
5
|
+
const prefix = p.slice(0, -1);
|
|
6
|
+
return pathname.startsWith(prefix) || pathname === prefix.slice(0, -1);
|
|
7
|
+
}
|
|
8
|
+
return pathname === p || pathname.startsWith(p + '/');
|
|
9
|
+
}) ?? false;
|
|
10
|
+
|
|
11
|
+
export const collapsibleMatchesRoute = (pathname, item) => {
|
|
12
|
+
if (!item?.children) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (matchesOpenFor(pathname, item.openFor)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return item.children.some((child) =>
|
|
19
|
+
(child.url && (pathname === child.url || pathname.startsWith(child.url + '/')))
|
|
20
|
+
|| matchesOpenFor(pathname, child.openFor)
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const navItemMatchesRoute = (pathname, item) => {
|
|
25
|
+
if (item?.children) {
|
|
26
|
+
return collapsibleMatchesRoute(pathname, item);
|
|
27
|
+
}
|
|
28
|
+
return Boolean(item?.url && (pathname === item.url || pathname.startsWith(item.url + '/')))
|
|
29
|
+
|| matchesOpenFor(pathname, item?.openFor);
|
|
30
|
+
};
|