@skbkontur/side-menu 4.0.10 → 5.0.0-alpha.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +0 -15
  2. package/README.md +38 -11
  3. package/SideMenuDataTids.d.ts +2 -1
  4. package/SideMenuDataTids.js +2 -1
  5. package/hooks/useMemoIcon.d.ts +1 -2
  6. package/hooks/useMemoIcon.js +0 -9
  7. package/hooks/useNodeState.d.ts +7 -0
  8. package/hooks/useNodeState.js +12 -0
  9. package/hooks/useSideMenuReducer.d.ts +13 -0
  10. package/hooks/useSideMenuReducer.js +23 -0
  11. package/internal/themes/SideMenuDarkTheme.js +6 -0
  12. package/internal/themes/SideMenuTheme.d.ts +32 -10
  13. package/internal/themes/SideMenuTheme.js +44 -30
  14. package/lib/theming/ThemeHelpers.js +0 -4
  15. package/lib/utils/scripts.d.ts +1 -0
  16. package/lib/utils/scripts.js +9 -0
  17. package/package.json +2 -2
  18. package/src/SideMenu/SideMenu.d.ts +9 -4
  19. package/src/SideMenu/SideMenu.js +206 -189
  20. package/src/SideMenu/SideMenu.styles.d.ts +5 -0
  21. package/src/SideMenu/SideMenu.styles.js +35 -12
  22. package/src/SideMenuAvatar/SideMenuAvatar.js +7 -2
  23. package/src/SideMenuBody/SideMenuBody.js +2 -0
  24. package/src/SideMenuBody/SideMenuBody.styles.js +1 -1
  25. package/src/SideMenuContext.d.ts +21 -9
  26. package/src/SideMenuContext.js +6 -1
  27. package/src/SideMenuDivider/SideMenuDivider.js +4 -1
  28. package/src/SideMenuDivider/SideMenuDivider.styles.d.ts +1 -0
  29. package/src/SideMenuDivider/SideMenuDivider.styles.js +5 -2
  30. package/src/SideMenuDropdown/SideMenuDropdown.js +20 -20
  31. package/src/SideMenuDropdown/SideMenuDropdown.styles.d.ts +1 -0
  32. package/src/SideMenuDropdown/SideMenuDropdown.styles.js +13 -8
  33. package/src/SideMenuFooter/SideMenuFooter.js +59 -5
  34. package/src/SideMenuFooter/SideMenuFooter.styles.d.ts +11 -0
  35. package/src/SideMenuFooter/SideMenuFooter.styles.js +38 -4
  36. package/src/SideMenuHeader/SideMenuHeader.js +6 -5
  37. package/src/SideMenuNotifications/BellWidget.js +6 -13
  38. package/src/SideMenuNotifications/BellWidgetError.js +3 -6
  39. package/src/SideMenuNotifications/BellWidgetView.styles.d.ts +4 -7
  40. package/src/SideMenuNotifications/BellWidgetView.styles.js +9 -20
  41. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.js +2 -1
  42. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.d.ts +2 -1
  43. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.js +6 -3
  44. package/src/SideMenuSubLink/SideMenuSubLink.d.ts +1 -1
  45. package/src/internal/BackButton.d.ts +1 -3
  46. package/src/internal/BackButton.js +4 -3
  47. package/src/internal/ClickableElement.d.ts +18 -2
  48. package/src/internal/ClickableElement.js +191 -69
  49. package/src/internal/ClickableElement.styles.d.ts +5 -0
  50. package/src/internal/ClickableElement.styles.js +25 -8
  51. package/src/internal/CollapseToggle.d.ts +2 -0
  52. package/src/internal/CollapseToggle.js +44 -0
  53. package/src/internal/{RightBorder.styles.d.ts → CollapseToggle.styles.d.ts} +2 -1
  54. package/src/internal/CollapseToggle.styles.js +19 -0
  55. package/src/internal/ItemContent/Caption.d.ts +1 -1
  56. package/src/internal/ItemContent/Caption.js +10 -26
  57. package/src/internal/ItemContent/Caption.styles.d.ts +1 -0
  58. package/src/internal/ItemContent/Caption.styles.js +16 -13
  59. package/src/internal/ItemContent/Icon.js +5 -2
  60. package/src/internal/ItemContent/Icon.styles.d.ts +3 -0
  61. package/src/internal/ItemContent/Icon.styles.js +16 -7
  62. package/src/internal/ItemContent/ItemContent.js +17 -5
  63. package/src/internal/ItemContent/ItemContent.styles.d.ts +1 -0
  64. package/src/internal/ItemContent/ItemContent.styles.js +7 -4
  65. package/src/internal/ItemContent/Marker.js +8 -2
  66. package/src/internal/ItemContent/Marker.styles.d.ts +3 -0
  67. package/src/internal/ItemContent/Marker.styles.js +16 -5
  68. package/src/internal/NarrowAccordionDropdown.d.ts +15 -0
  69. package/src/internal/NarrowAccordionDropdown.js +35 -0
  70. package/src/internal/SeparatedSubMenu.js +7 -9
  71. package/src/internal/SeparatedSubMenu.styles.d.ts +0 -3
  72. package/src/internal/SeparatedSubMenu.styles.js +6 -15
  73. package/src/internal/SideMenuLogotype.js +13 -11
  74. package/src/internal/SubMenu.js +3 -2
  75. package/src/navigationAttributes.d.ts +3 -0
  76. package/src/navigationAttributes.js +3 -0
  77. package/src/state/reducer.d.ts +2 -0
  78. package/src/state/reducer.js +258 -0
  79. package/src/state/selectors.d.ts +16 -0
  80. package/src/state/selectors.js +71 -0
  81. package/src/state/types.d.ts +59 -0
  82. package/src/state/types.js +17 -0
  83. package/src/Navigation.d.ts +0 -53
  84. package/src/Navigation.js +0 -194
  85. package/src/SideMenuNotifications/utils/getWrapperHeightClass.d.ts +0 -11
  86. package/src/SideMenuNotifications/utils/getWrapperHeightClass.js +0 -10
  87. package/src/Tree.d.ts +0 -17
  88. package/src/Tree.js +0 -135
  89. package/src/internal/RightBorder.d.ts +0 -9
  90. package/src/internal/RightBorder.js +0 -37
  91. package/src/internal/RightBorder.styles.js +0 -14
@@ -4,25 +4,16 @@ export var getStyles = memoizeGetStyles(function (_a) {
4
4
  var css = _a.css;
5
5
  return ({
6
6
  root: function (t) {
7
- return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n top: 0;\n background: ", ";\n left: 100%;\n justify-content: flex-start;\n border-right: 1px solid ", ";\n z-index: 8000;\n "], ["\n position: absolute;\n top: 0;\n background: ", ";\n left: 100%;\n justify-content: flex-start;\n border-right: 1px solid ", ";\n z-index: 8000;\n "])), t.sideMenuSeparatedSubMenuBg, t.sideMenuSeparatedSubMenuBorderRightColor);
8
- },
9
- rootTouchScreen: function (t) {
10
- return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n left: ", ";\n z-index: -1;\n "], ["\n left: ", ";\n z-index: -1;\n "])), t.sideMenuWidthTouchScreen);
11
- },
12
- rootNarrowDesktop: function (t) {
13
- return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n left: ", ";\n z-index: -1;\n "], ["\n left: ", ";\n z-index: -1;\n "])), t.sideMenuWidthCollapsed);
14
- },
15
- rootDesktop: function () {
16
- return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n z-index: -1;\n "], ["\n z-index: -1;\n "])));
7
+ return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: ", ";\n border-right: 1px solid ", ";\n z-index: 8000;\n "], ["\n background: ", ";\n border-right: 1px solid ", ";\n z-index: 8000;\n "])), t.sideMenuSeparatedSubMenuBg, t.sideMenuSeparatedSubMenuBorderRightColor);
17
8
  },
18
9
  rootTablet: function (t) {
19
- return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n box-shadow: ", ";\n clip-path: inset(0 -", " 0 0);\n border-right: none;\n "], ["\n box-shadow: ", ";\n clip-path: inset(0 -", " 0 0);\n border-right: none;\n "])), t.sideMenuBoxShadow, t.sideMenuSeparatedSubMenuBoxShadowRadius);
10
+ return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border-right: none;\n "], ["\n border-right: none;\n "])));
20
11
  },
21
12
  contentWrapper: function (t) {
22
- return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding: ", " ", ";\n "], ["\n padding: ", " ", ";\n "])), t.sideMenuSeparatedSubMenuPaddingY, t.sideMenuSeparatedSubMenuPaddingX);
13
+ return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n padding: ", " ", ";\n "], ["\n padding: ", " ", ";\n "])), t.sideMenuSeparatedSubMenuPaddingY, t.sideMenuSeparatedSubMenuPaddingX);
23
14
  },
24
15
  contentWrapperMobile: function () {
25
- return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n padding-top: 0;\n "], ["\n padding-top: 0;\n "])));
16
+ return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n padding-top: 0;\n "], ["\n padding-top: 0;\n "])));
26
17
  },
27
18
  });
28
19
  });
@@ -30,8 +21,8 @@ export var getCustomStyles = function (_a) {
30
21
  var css = _a.css;
31
22
  return ({
32
23
  rootMobile: function (headerHeight) {
33
- return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "], ["\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "])), headerHeight, headerHeight);
24
+ return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n position: absolute;\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "], ["\n position: absolute;\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "])), headerHeight, headerHeight);
34
25
  },
35
26
  });
36
27
  };
37
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
28
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
@@ -2,7 +2,7 @@ import { __assign, __read, __rest } from "tslib";
2
2
  import { Logotype } from '@skbkontur/react-ui-addons/components/Logotype/Logotype';
3
3
  import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
4
4
  import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
5
- import React, { forwardRef, useContext, useEffect, useRef, useState } from 'react';
5
+ import React, { forwardRef, useContext, useLayoutEffect, useRef, useState } from 'react';
6
6
  import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
7
7
  import { SideMenuContext } from '../SideMenuContext.js';
8
8
  import { Burger } from './Burger.js';
@@ -27,7 +27,7 @@ var getProductName = function (productLogo) {
27
27
  : 'kontur';
28
28
  };
29
29
  var getStaticIconPath = function (productName) {
30
- return "https://s.kontur.ru/common-v2/icons-products/".concat(productName, "/").concat(productName, "-").concat(parseInt(sideMenuLogotypeIconSize), ".svg");
30
+ return "https://s.kontur.ru/common-v2/icons-products/".concat(productName, "/").concat(productName, "-").concat(parseInt(sideMenuLogotypeIconSize, 10), ".svg");
31
31
  };
32
32
  /**
33
33
  * Логотип
@@ -44,23 +44,25 @@ var SideMenuLogotype = forwardRef(function (_a, ref) {
44
44
  var productName = getProductName(productLogo);
45
45
  var refLogotype = useRef(null);
46
46
  var _e = __read(useState(28), 2), size = _e[0], setSize = _e[1];
47
- var _f = __read(useState(false), 2), isSizeCalculated = _f[0], setIsSizeCalculated = _f[1];
47
+ var _f = __read(useState(true), 2), isSizeCalculated = _f[0], setIsSizeCalculated = _f[1];
48
48
  var _g = __read(useState(getStaticIconPath(productName)), 2), productIconUrl = _g[0], setProductIconUrl = _g[1];
49
49
  var isTabletOrMobile = context.isTablet || context.isMobile;
50
- useEffect(function () {
50
+ var isDesktopCollapsedMode = !context.isOpened && (context.isDesktop || context.isNarrowDesktop);
51
+ var sideMenuWidth = theme.sideMenuWidth, sideMenuMarginX = theme.sideMenuMarginX, sideMenuLogotypePaddingLeft = theme.sideMenuLogotypePaddingLeft;
52
+ useLayoutEffect(function () {
51
53
  var _a, _b;
52
54
  var logotypeWidth = (_b = (_a = refLogotype.current) === null || _a === void 0 ? void 0 : _a.logotypeRef) === null || _b === void 0 ? void 0 : _b.clientWidth;
53
- var maxWidth = parseInt(theme.sideMenuWidth) -
54
- 2 * parseInt(theme.sideMenuMarginX) -
55
- parseInt(theme.sideMenuLogotypePaddingLeft) +
55
+ var maxWidth = parseInt(sideMenuWidth, 10) -
56
+ 2 * parseInt(sideMenuMarginX, 10) -
57
+ parseInt(sideMenuLogotypePaddingLeft, 10) +
56
58
  (withWidget ? -28 : 0);
57
59
  if (logotypeWidth && logotypeWidth > maxWidth && !rest.size) {
58
60
  setSize(24);
59
61
  }
60
62
  setIsSizeCalculated(true);
61
- }, []);
62
- var getWidget = function (withWidget, isCollapsedInNarrowDesktop) {
63
- if (isCollapsedInNarrowDesktop) {
63
+ }, [sideMenuWidth, sideMenuMarginX, sideMenuLogotypePaddingLeft, withWidget, rest.size]);
64
+ var getWidget = function (withWidget, isCollapsedOnDesktop) {
65
+ if (isCollapsedOnDesktop) {
64
66
  return false;
65
67
  }
66
68
  return withWidget;
@@ -79,7 +81,7 @@ var SideMenuLogotype = forwardRef(function (_a, ref) {
79
81
  _d[styles.logoWrapperHidden()] = isSizeCalculated && !context.isOpened && !isTabletOrMobile,
80
82
  _d)) },
81
83
  isTabletOrMobile && React.createElement(Burger, null),
82
- React.createElement(Logotype, __assign({ ref: refLogotype, size: size, productLogo: productLogo, konturLogo: konturLogo, withWidget: getWidget(withWidget, !context.isOpened && context.isCollapsable) }, rest)))));
84
+ React.createElement(Logotype, __assign({ ref: refLogotype, size: size, productLogo: productLogo, konturLogo: konturLogo, withWidget: getWidget(withWidget, isDesktopCollapsedMode) }, rest)))));
83
85
  });
84
86
  SideMenuLogotype.displayName = 'SideMenuLogotype';
85
87
  var SideMenuLogotypeWithStaticFields = Object.assign(SideMenuLogotype, { __KONTUR_REACT_UI__: 'SideMenuLogotype' });
@@ -1,5 +1,6 @@
1
1
  import React, { forwardRef, useContext } from 'react';
2
2
  import { SideMenuContext } from '../SideMenuContext.js';
3
+ import { separatedShown } from '../state/selectors.js';
3
4
  import { InnerSubMenu } from './InnerSubMenu.js';
4
5
  import { NestedMenu } from './NestedMenu.js';
5
6
  import { SeparatedSubMenu } from './SeparatedSubMenu.js';
@@ -9,14 +10,14 @@ import { SeparatedSubMenu } from './SeparatedSubMenu.js';
9
10
  * @visibleName InnerSubMenu
10
11
  */
11
12
  var SubMenu = forwardRef(function (_a, ref) {
12
- var _b;
13
13
  var children = _a.children, isOpened = _a.isOpened, isSubMenu = _a.isSubMenu, isSeparatedMenu = _a.isSeparatedMenu, caption = _a.caption, htmlId = _a.htmlId;
14
14
  var context = useContext(SideMenuContext);
15
+ var isSeparatedMenuShown = separatedShown(context.state);
15
16
  if (isSubMenu) {
16
17
  return (React.createElement(NestedMenu, { ref: ref, htmlId: htmlId, isOpened: isOpened }, children));
17
18
  }
18
19
  if (isSeparatedMenu) {
19
- return (React.createElement(SeparatedSubMenu, { ref: ref, caption: caption, htmlId: htmlId, isOpened: isOpened && ((_b = context.navigation) === null || _b === void 0 ? void 0 : _b.isSeparatedMenuShown) }, children));
20
+ return (React.createElement(SeparatedSubMenu, { ref: ref, caption: caption, htmlId: htmlId, isOpened: isOpened && isSeparatedMenuShown }, children));
20
21
  }
21
22
  return (React.createElement(InnerSubMenu, { ref: ref, htmlId: htmlId, isOpened: isOpened }, children));
22
23
  });
@@ -0,0 +1,3 @@
1
+ export declare const navigationAttribute = "data-navigation-id";
2
+ export declare const navigationAttributeForSeparatedMenu = "data-parent-navigation-id";
3
+ export declare const navigationAttributeBackButton = "data-navigation-back-button";
@@ -0,0 +1,3 @@
1
+ export var navigationAttribute = 'data-navigation-id';
2
+ export var navigationAttributeForSeparatedMenu = 'data-parent-navigation-id';
3
+ export var navigationAttributeBackButton = 'data-navigation-back-button';
@@ -0,0 +1,2 @@
1
+ import { type Action, type SideMenuState } from './types.js';
2
+ export declare function sideMenuReducer(state: SideMenuState, action: Action): SideMenuState;
@@ -0,0 +1,258 @@
1
+ import { __assign, __read, __spreadArray, __values } from "tslib";
2
+ import { isSubMenu, hasChildren, firstLevelParent, ancestors } from './selectors.js';
3
+ import { ROOT } from './types.js';
4
+ function getDescendantIds(state, id) {
5
+ var e_1, _a;
6
+ var result = [];
7
+ var queue = [id];
8
+ while (queue.length > 0) {
9
+ var current = queue.shift();
10
+ if (current === undefined) {
11
+ continue;
12
+ }
13
+ var kids = state.childrenOf.get(current);
14
+ if (kids) {
15
+ try {
16
+ for (var kids_1 = (e_1 = void 0, __values(kids)), kids_1_1 = kids_1.next(); !kids_1_1.done; kids_1_1 = kids_1.next()) {
17
+ var kid = kids_1_1.value;
18
+ result.push(kid);
19
+ queue.push(kid);
20
+ }
21
+ }
22
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
23
+ finally {
24
+ try {
25
+ if (kids_1_1 && !kids_1_1.done && (_a = kids_1.return)) _a.call(kids_1);
26
+ }
27
+ finally { if (e_1) throw e_1.error; }
28
+ }
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ function register(state, id, parentId, isSubMenuItem) {
34
+ var _a;
35
+ if (state.parentOf.has(id) || id === ROOT || id === parentId) {
36
+ return state;
37
+ }
38
+ var parentOf = new Map(state.parentOf);
39
+ parentOf.set(id, parentId);
40
+ var childrenOf = new Map(state.childrenOf);
41
+ var parentKids = new Set((_a = childrenOf.get(parentId)) !== null && _a !== void 0 ? _a : []);
42
+ parentKids.add(id);
43
+ childrenOf.set(parentId, parentKids);
44
+ var subMenuIds = isSubMenuItem ? new Set(state.subMenuIds).add(id) : state.subMenuIds;
45
+ var next = __assign(__assign({}, state), { parentOf: parentOf, childrenOf: childrenOf, subMenuIds: subMenuIds });
46
+ // A controlled `activeItem` that named this node before it registered is applied now.
47
+ if (next.pendingActiveItemId === id) {
48
+ return __assign(__assign({}, select(next, id, false)), { pendingActiveItemId: null });
49
+ }
50
+ // Re-expand an ancestor of the active item that re-mounts (e.g. after the narrow
51
+ // accordion dropdown closes and the menu is expanded back to the inline view). The
52
+ // ancestor ids are captured at selection time in `activeAncestorIds` and survive the
53
+ // unmount, so each ancestor re-opens as it registers and the path to the active item
54
+ // is restored — including nested sub-subitems.
55
+ if (next.activeAncestorIds.has(id) && !next.openNodeIds.has(id)) {
56
+ return __assign(__assign({}, next), { openNodeIds: new Set(next.openNodeIds).add(id) });
57
+ }
58
+ return next;
59
+ }
60
+ function unregister(state, id) {
61
+ var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
62
+ if (!state.parentOf.has(id) || id === ROOT) {
63
+ return state;
64
+ }
65
+ var parentId = state.parentOf.get(id);
66
+ if (parentId === undefined) {
67
+ return state;
68
+ }
69
+ var idsToRemove = new Set(__spreadArray([id], __read(getDescendantIds(state, id)), false));
70
+ var parentOf = new Map(state.parentOf);
71
+ try {
72
+ for (var idsToRemove_1 = __values(idsToRemove), idsToRemove_1_1 = idsToRemove_1.next(); !idsToRemove_1_1.done; idsToRemove_1_1 = idsToRemove_1.next()) {
73
+ var rid = idsToRemove_1_1.value;
74
+ parentOf.delete(rid);
75
+ }
76
+ }
77
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
78
+ finally {
79
+ try {
80
+ if (idsToRemove_1_1 && !idsToRemove_1_1.done && (_a = idsToRemove_1.return)) _a.call(idsToRemove_1);
81
+ }
82
+ finally { if (e_2) throw e_2.error; }
83
+ }
84
+ var childrenOf = new Map(state.childrenOf);
85
+ try {
86
+ for (var idsToRemove_2 = __values(idsToRemove), idsToRemove_2_1 = idsToRemove_2.next(); !idsToRemove_2_1.done; idsToRemove_2_1 = idsToRemove_2.next()) {
87
+ var rid = idsToRemove_2_1.value;
88
+ childrenOf.delete(rid);
89
+ }
90
+ }
91
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
92
+ finally {
93
+ try {
94
+ if (idsToRemove_2_1 && !idsToRemove_2_1.done && (_b = idsToRemove_2.return)) _b.call(idsToRemove_2);
95
+ }
96
+ finally { if (e_3) throw e_3.error; }
97
+ }
98
+ var parentKids = childrenOf.get(parentId);
99
+ if (parentKids) {
100
+ var next = new Set(parentKids);
101
+ next.delete(id);
102
+ childrenOf.set(parentId, next);
103
+ }
104
+ var subMenuIds = state.subMenuIds;
105
+ try {
106
+ for (var idsToRemove_3 = __values(idsToRemove), idsToRemove_3_1 = idsToRemove_3.next(); !idsToRemove_3_1.done; idsToRemove_3_1 = idsToRemove_3.next()) {
107
+ var rid = idsToRemove_3_1.value;
108
+ if (subMenuIds.has(rid)) {
109
+ var next = new Set(subMenuIds);
110
+ next.delete(rid);
111
+ subMenuIds = next;
112
+ }
113
+ }
114
+ }
115
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
116
+ finally {
117
+ try {
118
+ if (idsToRemove_3_1 && !idsToRemove_3_1.done && (_c = idsToRemove_3.return)) _c.call(idsToRemove_3);
119
+ }
120
+ finally { if (e_4) throw e_4.error; }
121
+ }
122
+ var openNodeIds = state.openNodeIds;
123
+ try {
124
+ for (var idsToRemove_4 = __values(idsToRemove), idsToRemove_4_1 = idsToRemove_4.next(); !idsToRemove_4_1.done; idsToRemove_4_1 = idsToRemove_4.next()) {
125
+ var rid = idsToRemove_4_1.value;
126
+ if (openNodeIds.has(rid)) {
127
+ var next = new Set(openNodeIds);
128
+ next.delete(rid);
129
+ openNodeIds = next;
130
+ }
131
+ }
132
+ }
133
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
134
+ finally {
135
+ try {
136
+ if (idsToRemove_4_1 && !idsToRemove_4_1.done && (_d = idsToRemove_4.return)) _d.call(idsToRemove_4);
137
+ }
138
+ finally { if (e_5) throw e_5.error; }
139
+ }
140
+ return __assign(__assign({}, state), { parentOf: parentOf, childrenOf: childrenOf, subMenuIds: subMenuIds, openNodeIds: openNodeIds });
141
+ }
142
+ /**
143
+ * Mirrors the legacy `MenuNavigation.switchVisibilityOfSeparatedMenu`: the panel
144
+ * shows when the active item has children or is itself a sub-item, except on
145
+ * mobile navigating back to a top-level item while the panel is already shown
146
+ * collapses it (the BackButton toggle). `prevShown` carries that statefulness.
147
+ */
148
+ function computeSeparatedShown(state, active, prevShown) {
149
+ if (!state.isSeparatedMenu || active === null) {
150
+ return false;
151
+ }
152
+ var activeHasParent = isSubMenu(state, active);
153
+ var activeHasChildren = hasChildren(state, active);
154
+ var shouldShow = activeHasParent || activeHasChildren;
155
+ if (state.viewport === 'mobile' && !activeHasParent && prevShown) {
156
+ return false;
157
+ }
158
+ return shouldShow;
159
+ }
160
+ /**
161
+ * Core selection transition (replaces switchActiveMenuItem + openMenuItems).
162
+ * `isButton` only suppresses the active-item change; expansion rules are identical.
163
+ */
164
+ function select(state, id, isButton) {
165
+ var e_6, _a;
166
+ if (!state.parentOf.has(id)) {
167
+ return state;
168
+ }
169
+ var changed = firstLevelParent(state, state.activeItemId) !== firstLevelParent(state, id);
170
+ var closeAll = !isSubMenu(state, id) || changed;
171
+ var openNodeIds = closeAll ? new Set() : new Set(state.openNodeIds);
172
+ if (hasChildren(state, id)) {
173
+ openNodeIds.add(id);
174
+ }
175
+ try {
176
+ for (var _b = __values(ancestors(state, id)), _c = _b.next(); !_c.done; _c = _b.next()) {
177
+ var ancestor = _c.value;
178
+ openNodeIds.add(ancestor);
179
+ }
180
+ }
181
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
182
+ finally {
183
+ try {
184
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
185
+ }
186
+ finally { if (e_6) throw e_6.error; }
187
+ }
188
+ var nextActive = isButton ? state.activeItemId : id;
189
+ var next = __assign(__assign({}, state), { openNodeIds: openNodeIds, activeItemId: nextActive, activeFirstLevelParentId: nextActive !== null ? firstLevelParent(state, nextActive) : null, activeAncestorIds: nextActive !== null ? new Set(ancestors(state, nextActive)) : new Set() });
190
+ return __assign(__assign({}, next), { separatedMenuShown: computeSeparatedShown(next, nextActive, state.separatedMenuShown) });
191
+ }
192
+ function closeNode(state, id) {
193
+ var e_7, _a;
194
+ if (!state.openNodeIds.has(id)) {
195
+ return state;
196
+ }
197
+ var openNodeIds = new Set(state.openNodeIds);
198
+ openNodeIds.delete(id);
199
+ try {
200
+ for (var _b = __values(getDescendantIds(state, id)), _c = _b.next(); !_c.done; _c = _b.next()) {
201
+ var descendant = _c.value;
202
+ openNodeIds.delete(descendant);
203
+ }
204
+ }
205
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
206
+ finally {
207
+ try {
208
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
209
+ }
210
+ finally { if (e_7) throw e_7.error; }
211
+ }
212
+ // Collapsing a top-level section in separated mode also hides the separated column,
213
+ // so the root stops reserving the column's double-width space.
214
+ if (state.isSeparatedMenu && state.parentOf.get(id) === ROOT) {
215
+ return __assign(__assign({}, state), { openNodeIds: openNodeIds, separatedMenuShown: false });
216
+ }
217
+ return __assign(__assign({}, state), { openNodeIds: openNodeIds });
218
+ }
219
+ function setActiveItem(state, id) {
220
+ if (id === null) {
221
+ return __assign(__assign({}, state), { activeItemId: null, activeFirstLevelParentId: null, activeAncestorIds: new Set(), separatedMenuShown: false, pendingActiveItemId: null });
222
+ }
223
+ if (state.activeItemId === id) {
224
+ return state;
225
+ }
226
+ // Node not registered yet (controlled prop set before mount): defer until it registers.
227
+ if (!state.parentOf.has(id)) {
228
+ return __assign(__assign({}, state), { pendingActiveItemId: id, activeAncestorIds: new Set() });
229
+ }
230
+ return __assign(__assign({}, select(state, id, false)), { pendingActiveItemId: null });
231
+ }
232
+ export function sideMenuReducer(state, action) {
233
+ switch (action.type) {
234
+ case 'REGISTER':
235
+ return register(state, action.id, action.parentId, action.isSubMenu);
236
+ case 'UNREGISTER':
237
+ return unregister(state, action.id);
238
+ case 'SELECT':
239
+ return select(state, action.id, action.isButton);
240
+ case 'CLOSE_NODE':
241
+ return closeNode(state, action.id);
242
+ case 'SET_ACTIVE_ITEM':
243
+ return setActiveItem(state, action.id);
244
+ case 'SET_VIEWPORT':
245
+ return action.viewport === state.viewport ? state : __assign(__assign({}, state), { viewport: action.viewport });
246
+ case 'SET_OPENED':
247
+ return action.open === state.isOpened ? state : __assign(__assign({}, state), { isOpened: action.open });
248
+ case 'SET_SEPARATED_MENU': {
249
+ if (action.isSeparatedMenu === state.isSeparatedMenu) {
250
+ return state;
251
+ }
252
+ var next = __assign(__assign({}, state), { isSeparatedMenu: action.isSeparatedMenu });
253
+ return __assign(__assign({}, next), { separatedMenuShown: computeSeparatedShown(next, next.activeItemId, state.separatedMenuShown) });
254
+ }
255
+ default:
256
+ return state;
257
+ }
258
+ }
@@ -0,0 +1,16 @@
1
+ import { type SideMenuState } from './types.js';
2
+ export declare function isActive(state: SideMenuState, id: string): boolean;
3
+ export declare function isRegistered(state: SideMenuState, id: string): boolean;
4
+ export declare function isSubMenu(state: SideMenuState, id: string): boolean;
5
+ export declare function hasChildren(state: SideMenuState, id: string): boolean;
6
+ export declare function isExpanded(state: SideMenuState, id: string): boolean;
7
+ export declare function depth(state: SideMenuState, id: string): number;
8
+ export declare function isNestedSubMenu(state: SideMenuState, id: string): boolean;
9
+ export declare function ancestors(state: SideMenuState, id: string): string[];
10
+ /**
11
+ * The top-level (child-of-ROOT) ancestor of `id`, or null when `id` is itself
12
+ * top-level or unknown. Mirrors the original `getFirstLevelParent` semantics.
13
+ */
14
+ export declare function firstLevelParent(state: SideMenuState, id: string | null): string | null;
15
+ export declare function hasSeparatedSubMenu(state: SideMenuState, id: string): boolean;
16
+ export declare function separatedShown(state: SideMenuState): boolean;
@@ -0,0 +1,71 @@
1
+ import { ROOT } from './types.js';
2
+ export function isActive(state, id) {
3
+ return state.activeItemId === id;
4
+ }
5
+ export function isRegistered(state, id) {
6
+ return state.parentOf.has(id);
7
+ }
8
+ export function isSubMenu(state, id) {
9
+ return state.subMenuIds.has(id);
10
+ }
11
+ export function hasChildren(state, id) {
12
+ var kids = state.childrenOf.get(id);
13
+ return kids !== undefined && kids.size > 0;
14
+ }
15
+ export function isExpanded(state, id) {
16
+ return state.openNodeIds.has(id);
17
+ }
18
+ export function depth(state, id) {
19
+ var d = 0;
20
+ var current = state.parentOf.get(id);
21
+ while (current !== undefined && current !== ROOT) {
22
+ d += 1;
23
+ current = state.parentOf.get(current);
24
+ }
25
+ return d;
26
+ }
27
+ export function isNestedSubMenu(state, id) {
28
+ return depth(state, id) >= 2;
29
+ }
30
+ export function ancestors(state, id) {
31
+ var result = [];
32
+ var current = state.parentOf.get(id);
33
+ while (current !== undefined && current !== ROOT) {
34
+ result.push(current);
35
+ current = state.parentOf.get(current);
36
+ }
37
+ return result;
38
+ }
39
+ /**
40
+ * The top-level (child-of-ROOT) ancestor of `id`, or null when `id` is itself
41
+ * top-level or unknown. Mirrors the original `getFirstLevelParent` semantics.
42
+ */
43
+ export function firstLevelParent(state, id) {
44
+ if (id === null) {
45
+ return null;
46
+ }
47
+ var parent = state.parentOf.get(id);
48
+ if (parent === undefined) {
49
+ return null;
50
+ }
51
+ if (parent === ROOT) {
52
+ return null;
53
+ }
54
+ var node = parent;
55
+ while (true) {
56
+ var p = state.parentOf.get(node);
57
+ if (p === undefined) {
58
+ return null;
59
+ }
60
+ if (p === ROOT) {
61
+ return node;
62
+ }
63
+ node = p;
64
+ }
65
+ }
66
+ export function hasSeparatedSubMenu(state, id) {
67
+ return state.isSeparatedMenu && hasChildren(state, id);
68
+ }
69
+ export function separatedShown(state) {
70
+ return state.separatedMenuShown;
71
+ }
@@ -0,0 +1,59 @@
1
+ export type Viewport = 'desktop' | 'narrowDesktop' | 'tablet' | 'mobile';
2
+ export declare const ROOT = "__root__";
3
+ export interface SideMenuState {
4
+ /** id -> parentId (or ROOT). Presence of a key means the node is registered. */
5
+ parentOf: Map<string, string>;
6
+ /** id -> child ids. ROOT maps to the top-level item ids. */
7
+ childrenOf: Map<string, Set<string>>;
8
+ /** ids that are SubItems (rendered with _isSubMenu). */
9
+ subMenuIds: Set<string>;
10
+ /** the single active item, or null. */
11
+ activeItemId: string | null;
12
+ /** top-level ancestor of the active item (its section), or null. Captured at selection time
13
+ * so it survives the active item unmounting (e.g. when the narrow accordion dropdown closes). */
14
+ activeFirstLevelParentId: string | null;
15
+ /** ancestor ids of the active item captured at selection time. Survives the active item
16
+ * unmounting (e.g. narrow accordion dropdown closing) so ancestors re-expand on re-register. */
17
+ activeAncestorIds: Set<string>;
18
+ /** a controlled `activeItem` prop that named a not-yet-registered node; applied when it registers. */
19
+ pendingActiveItemId: string | null;
20
+ /** ids of nodes whose submenu is expanded. */
21
+ openNodeIds: Set<string>;
22
+ /** whether the separated sub-menu column is currently shown (stateful; mobile back-toggle lives here). */
23
+ separatedMenuShown: boolean;
24
+ /** resolved viewport, set via SET_VIEWPORT. */
25
+ viewport: Viewport;
26
+ /** resolved root open state, set via SET_OPENED. */
27
+ isOpened: boolean;
28
+ /** separated-menu mode, set via SET_SEPARATED_MENU. */
29
+ isSeparatedMenu: boolean;
30
+ }
31
+ export type Action = {
32
+ type: 'REGISTER';
33
+ id: string;
34
+ parentId: string;
35
+ isSubMenu: boolean;
36
+ } | {
37
+ type: 'UNREGISTER';
38
+ id: string;
39
+ } | {
40
+ type: 'SELECT';
41
+ id: string;
42
+ isButton: boolean;
43
+ } | {
44
+ type: 'CLOSE_NODE';
45
+ id: string;
46
+ } | {
47
+ type: 'SET_ACTIVE_ITEM';
48
+ id: string | null;
49
+ } | {
50
+ type: 'SET_VIEWPORT';
51
+ viewport: Viewport;
52
+ } | {
53
+ type: 'SET_OPENED';
54
+ open: boolean;
55
+ } | {
56
+ type: 'SET_SEPARATED_MENU';
57
+ isSeparatedMenu: boolean;
58
+ };
59
+ export declare function createInitialState(): SideMenuState;
@@ -0,0 +1,17 @@
1
+ export var ROOT = '__root__';
2
+ export function createInitialState() {
3
+ return {
4
+ parentOf: new Map(),
5
+ childrenOf: new Map([[ROOT, new Set()]]),
6
+ subMenuIds: new Set(),
7
+ activeItemId: null,
8
+ activeFirstLevelParentId: null,
9
+ activeAncestorIds: new Set(),
10
+ pendingActiveItemId: null,
11
+ openNodeIds: new Set(),
12
+ separatedMenuShown: false,
13
+ viewport: 'desktop',
14
+ isOpened: false,
15
+ isSeparatedMenu: false,
16
+ };
17
+ }
@@ -1,53 +0,0 @@
1
- import type { RefObject } from 'react';
2
- import type { TreeNode } from './Tree.js';
3
- import { Tree } from './Tree.js';
4
- export declare const navigationAttribute = "data-navigation-id";
5
- export declare const navigationAttributeForSeparatedMenu = "data-parent-navigation-id";
6
- export declare const navigationAttributeBackButton = "data-navigation-back-button";
7
- export interface NavigableElement {
8
- setIsActive: (value: boolean) => void;
9
- setIsOpened: (value: boolean) => void;
10
- setIsNestedSubMenu: (value: boolean) => void;
11
- setHasSubIcons: (value: boolean) => void;
12
- setIsFirstLevelParentOfActiveMenuItem: (value: boolean) => void;
13
- isSubMenu?: boolean;
14
- }
15
- interface MenuNavigationOptions {
16
- rootRef: RefObject<HTMLDivElement> | null;
17
- activeMenuItem?: string;
18
- setActiveMenuItem: (id: string) => void;
19
- isSeparatedMenu: boolean;
20
- isSeparatedMenuShown: boolean;
21
- setIsSeparatedMenuShown: (value: boolean) => void;
22
- isOpened?: boolean;
23
- isDesktop?: boolean;
24
- isMobile?: boolean;
25
- isCollapsable?: boolean;
26
- }
27
- export declare class MenuNavigation {
28
- navigationTree: Tree | null;
29
- activeMenuItem?: string;
30
- isSeparatedMenuShown?: boolean;
31
- setIsSeparatedMenuShown?: (value: boolean) => void;
32
- activeMenuItemTreeNode?: TreeNode;
33
- private readonly rootRef;
34
- private readonly setActiveMenuItem?;
35
- private isSeparatedMenu;
36
- private readonly isOpened?;
37
- private readonly isDesktop?;
38
- private readonly isMobile?;
39
- isCollapsable?: boolean;
40
- private menuItemsIds;
41
- constructor(options: MenuNavigationOptions);
42
- updateNavigationTree(): void;
43
- addValue(id: string, value: NavigableElement): void;
44
- switchActiveMenuItem(id?: string, isButton?: boolean): void;
45
- switchIsSeparatedMenu(value: boolean): void;
46
- private setHighlightedFirstLevelMenuItemInCollapsedInnerMenu;
47
- private getFirstLevelParent;
48
- private openMenuItems;
49
- private openAllParents;
50
- private getParentId;
51
- private switchVisibilityOfSeparatedMenu;
52
- }
53
- export {};