@marlinjai/clearify 1.6.2 → 1.6.3
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.
- package/package.json +1 -1
- package/src/theme/Sidebar.tsx +24 -2
package/package.json
CHANGED
package/src/theme/Sidebar.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { Link, useLocation } from 'react-router-dom';
|
|
2
|
+
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import type { NavigationItem, SectionNavigation } from '../types/index.js';
|
|
5
5
|
|
|
@@ -46,6 +46,18 @@ function collectGroupKeys(items: NavigationItem[], prefix = ''): string[] {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** Walk the navigation tree depth-first and return the first leaf path. */
|
|
50
|
+
function findFirstPath(items: NavigationItem[]): string | undefined {
|
|
51
|
+
for (const item of items) {
|
|
52
|
+
if (item.path) return item.path;
|
|
53
|
+
if (item.children) {
|
|
54
|
+
const found = findFirstPath(item.children);
|
|
55
|
+
if (found) return found;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
function SectionSwitcher({
|
|
50
62
|
sections,
|
|
51
63
|
activeId,
|
|
@@ -93,6 +105,7 @@ function SectionSwitcher({
|
|
|
93
105
|
|
|
94
106
|
export function Sidebar({ sections, open, onClose }: SidebarProps) {
|
|
95
107
|
const location = useLocation();
|
|
108
|
+
const navigate = useNavigate();
|
|
96
109
|
|
|
97
110
|
const isSectionData = sections.length > 0 && sections[0]?.id != null && Array.isArray(sections[0]?.navigation);
|
|
98
111
|
const legacyNavigation = !isSectionData ? (sections as unknown as NavigationItem[]) : null;
|
|
@@ -237,7 +250,16 @@ export function Sidebar({ sections, open, onClose }: SidebarProps) {
|
|
|
237
250
|
<SectionSwitcher
|
|
238
251
|
sections={sections}
|
|
239
252
|
activeId={selectedSectionId}
|
|
240
|
-
onSelect={
|
|
253
|
+
onSelect={(id) => {
|
|
254
|
+
setSelectedSectionId(id);
|
|
255
|
+
const section = sections.find((s) => s.id === id);
|
|
256
|
+
if (section) {
|
|
257
|
+
const firstPath = findFirstPath(section.navigation) ?? section.basePath;
|
|
258
|
+
if (firstPath && firstPath !== location.pathname) {
|
|
259
|
+
navigate(firstPath);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}}
|
|
241
263
|
/>
|
|
242
264
|
)}
|
|
243
265
|
{hasCollapsibleGroups && (
|