@skbkontur/side-menu 5.0.0-beta.0 → 5.0.0-beta.1

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 (35) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +1 -1
  3. package/src/SideMenu/SideMenu.js +13 -16
  4. package/src/SideMenu/SideMenu.styles.d.ts +4 -4
  5. package/src/SideMenu/SideMenu.styles.js +25 -29
  6. package/src/SideMenuBody/SideMenuBody.js +4 -28
  7. package/src/SideMenuBody/SideMenuBody.styles.js +1 -2
  8. package/src/SideMenuContext.d.ts +1 -8
  9. package/src/SideMenuDropdown/SideMenuDropdown.js +7 -7
  10. package/src/SideMenuDropdown/SideMenuDropdown.styles.d.ts +0 -1
  11. package/src/SideMenuDropdown/SideMenuDropdown.styles.js +4 -8
  12. package/src/SideMenuFooter/SideMenuFooter.js +6 -30
  13. package/src/SideMenuFooter/SideMenuFooter.styles.js +2 -3
  14. package/src/SideMenuHeader/SideMenuHeader.js +4 -1
  15. package/src/SideMenuHeader/SideMenuHeader.styles.d.ts +2 -0
  16. package/src/SideMenuHeader/SideMenuHeader.styles.js +12 -5
  17. package/src/internal/ClickableElement.d.ts +3 -1
  18. package/src/internal/ClickableElement.js +26 -31
  19. package/src/internal/InnerSubMenu.js +4 -0
  20. package/src/internal/ItemContent/Caption.styles.js +1 -1
  21. package/src/internal/ItemContent/Icon.js +1 -0
  22. package/src/internal/ItemContent/Icon.styles.d.ts +1 -0
  23. package/src/internal/ItemContent/Icon.styles.js +14 -12
  24. package/src/internal/ItemContent/ItemContent.js +26 -7
  25. package/src/internal/ItemContent/ItemContent.styles.d.ts +0 -1
  26. package/src/internal/ItemContent/ItemContent.styles.js +2 -6
  27. package/src/internal/ItemContent/Marker.js +1 -1
  28. package/src/internal/NarrowAccordionDropdown.d.ts +1 -2
  29. package/src/internal/NarrowAccordionDropdown.js +9 -14
  30. package/src/internal/SideMenuLogotype.js +5 -0
  31. package/src/internal/SideMenuLogotype.styles.d.ts +2 -0
  32. package/src/internal/SideMenuLogotype.styles.js +12 -5
  33. package/src/internal/subMenuItems.d.ts +3 -0
  34. package/src/internal/subMenuItems.js +43 -0
  35. package/src/state/reducer.js +46 -26
@@ -31,14 +31,15 @@ function getDescendantIds(state, id) {
31
31
  return result;
32
32
  }
33
33
  function register(state, id, parentId, isSubMenuItem) {
34
- var _a;
34
+ var e_2, _a;
35
+ var _b, _c;
35
36
  if (state.parentOf.has(id) || id === ROOT || id === parentId) {
36
37
  return state;
37
38
  }
38
39
  var parentOf = new Map(state.parentOf);
39
40
  parentOf.set(id, parentId);
40
41
  var childrenOf = new Map(state.childrenOf);
41
- var parentKids = new Set((_a = childrenOf.get(parentId)) !== null && _a !== void 0 ? _a : []);
42
+ var parentKids = new Set((_b = childrenOf.get(parentId)) !== null && _b !== void 0 ? _b : []);
42
43
  parentKids.add(id);
43
44
  childrenOf.set(parentId, parentKids);
44
45
  var subMenuIds = isSubMenuItem ? new Set(state.subMenuIds).add(id) : state.subMenuIds;
@@ -47,18 +48,37 @@ function register(state, id, parentId, isSubMenuItem) {
47
48
  if (next.pendingActiveItemId === id) {
48
49
  return __assign(__assign({}, select(next, id, false)), { pendingActiveItemId: null });
49
50
  }
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) });
51
+ if (next.activeAncestorIds.has(id)) {
52
+ var openNodeIds = new Set(next.openNodeIds).add(id);
53
+ var activeItemId = next.activeItemId;
54
+ if (activeItemId !== null && next.parentOf.has(activeItemId)) {
55
+ // Effects can register a selected child before its parents. Each ancestor
56
+ // that registers can extend the known path towards the top-level section.
57
+ var activeAncestorIds = new Set(ancestors(next, activeItemId));
58
+ try {
59
+ for (var activeAncestorIds_1 = __values(activeAncestorIds), activeAncestorIds_1_1 = activeAncestorIds_1.next(); !activeAncestorIds_1_1.done; activeAncestorIds_1_1 = activeAncestorIds_1.next()) {
60
+ var ancestor = activeAncestorIds_1_1.value;
61
+ if (next.parentOf.has(ancestor) && !next.activeAncestorIds.has(ancestor)) {
62
+ openNodeIds.add(ancestor);
63
+ }
64
+ }
65
+ }
66
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
67
+ finally {
68
+ try {
69
+ if (activeAncestorIds_1_1 && !activeAncestorIds_1_1.done && (_a = activeAncestorIds_1.return)) _a.call(activeAncestorIds_1);
70
+ }
71
+ finally { if (e_2) throw e_2.error; }
72
+ }
73
+ return __assign(__assign({}, next), { activeFirstLevelParentId: (_c = firstLevelParent(next, activeItemId)) !== null && _c !== void 0 ? _c : next.activeFirstLevelParentId, activeAncestorIds: activeAncestorIds, openNodeIds: openNodeIds });
74
+ }
75
+ // The selected item can still be unmounted when its ancestors reappear.
76
+ return __assign(__assign({}, next), { openNodeIds: openNodeIds });
57
77
  }
58
78
  return next;
59
79
  }
60
80
  function unregister(state, id) {
61
- var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
81
+ var e_3, _a, e_4, _b, e_5, _c, e_6, _d;
62
82
  if (!state.parentOf.has(id) || id === ROOT) {
63
83
  return state;
64
84
  }
@@ -74,12 +94,12 @@ function unregister(state, id) {
74
94
  parentOf.delete(rid);
75
95
  }
76
96
  }
77
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
97
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
78
98
  finally {
79
99
  try {
80
100
  if (idsToRemove_1_1 && !idsToRemove_1_1.done && (_a = idsToRemove_1.return)) _a.call(idsToRemove_1);
81
101
  }
82
- finally { if (e_2) throw e_2.error; }
102
+ finally { if (e_3) throw e_3.error; }
83
103
  }
84
104
  var childrenOf = new Map(state.childrenOf);
85
105
  try {
@@ -88,12 +108,12 @@ function unregister(state, id) {
88
108
  childrenOf.delete(rid);
89
109
  }
90
110
  }
91
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
111
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
92
112
  finally {
93
113
  try {
94
114
  if (idsToRemove_2_1 && !idsToRemove_2_1.done && (_b = idsToRemove_2.return)) _b.call(idsToRemove_2);
95
115
  }
96
- finally { if (e_3) throw e_3.error; }
116
+ finally { if (e_4) throw e_4.error; }
97
117
  }
98
118
  var parentKids = childrenOf.get(parentId);
99
119
  if (parentKids) {
@@ -112,12 +132,12 @@ function unregister(state, id) {
112
132
  }
113
133
  }
114
134
  }
115
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
135
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
116
136
  finally {
117
137
  try {
118
138
  if (idsToRemove_3_1 && !idsToRemove_3_1.done && (_c = idsToRemove_3.return)) _c.call(idsToRemove_3);
119
139
  }
120
- finally { if (e_4) throw e_4.error; }
140
+ finally { if (e_5) throw e_5.error; }
121
141
  }
122
142
  var openNodeIds = state.openNodeIds;
123
143
  try {
@@ -130,12 +150,12 @@ function unregister(state, id) {
130
150
  }
131
151
  }
132
152
  }
133
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
153
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
134
154
  finally {
135
155
  try {
136
156
  if (idsToRemove_4_1 && !idsToRemove_4_1.done && (_d = idsToRemove_4.return)) _d.call(idsToRemove_4);
137
157
  }
138
- finally { if (e_5) throw e_5.error; }
158
+ finally { if (e_6) throw e_6.error; }
139
159
  }
140
160
  return __assign(__assign({}, state), { parentOf: parentOf, childrenOf: childrenOf, subMenuIds: subMenuIds, openNodeIds: openNodeIds });
141
161
  }
@@ -162,7 +182,7 @@ function computeSeparatedShown(state, active, prevShown) {
162
182
  * `isButton` only suppresses the active-item change; expansion rules are identical.
163
183
  */
164
184
  function select(state, id, isButton) {
165
- var e_6, _a;
185
+ var e_7, _a;
166
186
  if (!state.parentOf.has(id)) {
167
187
  return state;
168
188
  }
@@ -178,19 +198,19 @@ function select(state, id, isButton) {
178
198
  openNodeIds.add(ancestor);
179
199
  }
180
200
  }
181
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
201
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
182
202
  finally {
183
203
  try {
184
204
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
185
205
  }
186
- finally { if (e_6) throw e_6.error; }
206
+ finally { if (e_7) throw e_7.error; }
187
207
  }
188
208
  var nextActive = isButton ? state.activeItemId : id;
189
209
  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
210
  return __assign(__assign({}, next), { separatedMenuShown: computeSeparatedShown(next, nextActive, state.separatedMenuShown) });
191
211
  }
192
212
  function closeNode(state, id) {
193
- var e_7, _a;
213
+ var e_8, _a;
194
214
  if (!state.openNodeIds.has(id)) {
195
215
  return state;
196
216
  }
@@ -202,12 +222,12 @@ function closeNode(state, id) {
202
222
  openNodeIds.delete(descendant);
203
223
  }
204
224
  }
205
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
225
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
206
226
  finally {
207
227
  try {
208
228
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
209
229
  }
210
- finally { if (e_7) throw e_7.error; }
230
+ finally { if (e_8) throw e_8.error; }
211
231
  }
212
232
  // Collapsing a top-level section in separated mode also hides the separated column,
213
233
  // so the root stops reserving the column's double-width space.
@@ -221,11 +241,11 @@ function setActiveItem(state, id) {
221
241
  return __assign(__assign({}, state), { activeItemId: null, activeFirstLevelParentId: null, activeAncestorIds: new Set(), separatedMenuShown: false, pendingActiveItemId: null });
222
242
  }
223
243
  if (state.activeItemId === id) {
224
- return state;
244
+ return state.pendingActiveItemId === null ? state : __assign(__assign({}, state), { pendingActiveItemId: null });
225
245
  }
226
246
  // Node not registered yet (controlled prop set before mount): defer until it registers.
227
247
  if (!state.parentOf.has(id)) {
228
- return __assign(__assign({}, state), { pendingActiveItemId: id, activeAncestorIds: new Set() });
248
+ return __assign(__assign({}, state), { pendingActiveItemId: id });
229
249
  }
230
250
  return __assign(__assign({}, select(state, id, false)), { pendingActiveItemId: null });
231
251
  }