@marlinjai/clearify 1.6.1 → 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
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;
|
|
@@ -189,8 +202,14 @@ export function Sidebar({ sections, open, onClose }: SidebarProps) {
|
|
|
189
202
|
});
|
|
190
203
|
};
|
|
191
204
|
|
|
192
|
-
const handleExpandAll = () =>
|
|
193
|
-
|
|
205
|
+
const handleExpandAll = () => {
|
|
206
|
+
setExpandedGroups(new Set(allGroupKeys));
|
|
207
|
+
window.dispatchEvent(new CustomEvent('clearify:expand-all'));
|
|
208
|
+
};
|
|
209
|
+
const handleCollapseAll = () => {
|
|
210
|
+
setExpandedGroups(new Set());
|
|
211
|
+
window.dispatchEvent(new CustomEvent('clearify:collapse-all'));
|
|
212
|
+
};
|
|
194
213
|
|
|
195
214
|
return (
|
|
196
215
|
<>
|
|
@@ -231,7 +250,16 @@ export function Sidebar({ sections, open, onClose }: SidebarProps) {
|
|
|
231
250
|
<SectionSwitcher
|
|
232
251
|
sections={sections}
|
|
233
252
|
activeId={selectedSectionId}
|
|
234
|
-
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
|
+
}}
|
|
235
263
|
/>
|
|
236
264
|
)}
|
|
237
265
|
{hasCollapsibleGroups && (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import { OperationCard } from './OperationCard.js';
|
|
3
3
|
|
|
4
4
|
interface TagGroupProps {
|
|
@@ -17,6 +17,17 @@ function operationAnchorId(tag: string, method: string, path: string): string {
|
|
|
17
17
|
export function TagGroup({ tag, description, operations, baseUrl }: TagGroupProps) {
|
|
18
18
|
const [expanded, setExpanded] = useState(true);
|
|
19
19
|
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const onExpand = () => setExpanded(true);
|
|
22
|
+
const onCollapse = () => setExpanded(false);
|
|
23
|
+
window.addEventListener('clearify:expand-all', onExpand);
|
|
24
|
+
window.addEventListener('clearify:collapse-all', onCollapse);
|
|
25
|
+
return () => {
|
|
26
|
+
window.removeEventListener('clearify:expand-all', onExpand);
|
|
27
|
+
window.removeEventListener('clearify:collapse-all', onCollapse);
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
20
31
|
return (
|
|
21
32
|
<div
|
|
22
33
|
id={`tag/${encodeURIComponent(tag)}`}
|