Repository navigation
Expand file tree
/
Copy pathnav-dropdowns.js
More file actions
343 lines (337 loc) · 13.7 KB
/
Copy pathnav-dropdowns.js
File metadata and controls
343 lines (337 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// Hover dropdowns for the desktop nav tabs.
//
// Mintlify has no native "hover a tab, see its sections" affordance — the only
// built-in dropdown is the click-to-open `menu` tab format (our "Popular" tab).
// This script injects a small panel into each tab listing that tab's main
// sections (the sidebar groups), linked to each section's first page. Show/hide
// is pure CSS (:hover / :focus-within — see the "Nav tab dropdowns" block in
// style.css); this file only builds the DOM.
//
// NAV_SECTIONS_BY_VERSION is generated from docs.json (`navigation.versions`):
// one map per version, chosen at attach time from the URL's /v2 | /v3 prefix
// (v4 pages carry no prefix). Per tab: one row per group (or per page for
// pages-only tabs, or per menu item for menu tabs), href = the group's first
// page. Single-group tabs (Mock Servers) list their pages instead, like
// pages-only tabs. Maps are matched to tabs BY LABEL (the tab's visible text),
// so renaming a tab in docs.json without updating this map simply leaves that
// tab dropdown-less — a safe failure, but keep the two files in sync. Tabs
// with fewer than 2 sections get no dropdown on purpose. Several versions
// share tab labels ("Getting Started" exists in v2 AND v3) and React may
// re-use tab DOM nodes across a version switch, so each injected panel is
// stamped with its version (data-ver) and rebuilt when it goes stale.
//
// Mechanics worth knowing before editing:
// - Each `.nav-tabs-item` is position:relative and overflow-visible, so the
// panel is appended INSIDE the item (absolute, top:100%). That is what lets
// plain CSS :hover keep the panel open while the pointer is over it.
// - The tab itself is a Next.js client-side <Link> whose click handler lives
// on React's delegated root listener. Clicks inside the panel therefore
// stopPropagation(), otherwise bubbling would ALSO trigger the outer link
// and route to the tab's landing page instead of the clicked section. The
// inner anchor then navigates natively (full page load — fine for docs).
// - "Popular" (the docs.json `menu` tab) is a <button> whose native Radix
// menu ALREADY opens on hover, with icons and per-item descriptions. It is
// skipped here — attaching a second panel would stack the two dropdowns.
// Its NAV_SECTIONS entry is kept so the map stays a complete mirror of
// docs.json, and in case the tab ever becomes a plain link.
// - React hydration owns the navbar DOM at startup and SPA route changes can
// re-render it, discarding injected nodes. attach() is idempotent and cheap
// (9 items), so it runs on load and again via MutationObserver whenever the
// navbar re-renders. If hydration strips the first injection, the observer
// converges on the next mutation.
(function () {
var NAV_SECTIONS_BY_VERSION = {
v4: {
"Get Started": [
{ label: "Introduction", href: "/introduction/getting-started" },
{
label: "Bruno Basics",
href: "/get-started/bruno-basics/create-a-workspace",
},
{
label: "Import & Migrate",
href: "/get-started/import-export-data/import-collections",
},
],
"API Client": [
{ label: "Overview", href: "/api-client/overview" },
{ label: "Send Requests", href: "/send-requests/overview" },
{ label: "Variables", href: "/variables/overview" },
{ label: "Authentication", href: "/auth/overview" },
{ label: "Secret Management", href: "/secrets-management/overview" },
{ label: "Tests", href: "/testing/tests/introduction" },
{ label: "Scripts", href: "/testing/script/overview" },
{ label: "Git & Collaboration", href: "/git-integration/overview" },
{ label: "AI", href: "/ai/bruno-ai/introduction" },
{ label: "Apps", href: "/apps/overview" },
{ label: "Settings", href: "/get-started/configure/settings" },
{ label: "Debugging", href: "/debugging/timeline" },
],
CLI: [
{ label: "Overview", href: "/bru-cli/overview" },
{ label: "bru run", href: "/bru-cli/run/overview" },
{ label: "bru import", href: "/bru-cli/import/overview" },
{ label: "bru docs", href: "/bru-cli/docs/overview" },
{ label: "Configuration", href: "/bru-cli/proxyConfiguration" },
{ label: "CI/CD", href: "/bru-cli/docker" },
],
"API Docs": [
{ label: "Overview", href: "/api-docs/overview" },
{ label: "Write Docs in Bruno", href: "/api-docs/workspace-docs" },
{ label: "Generate HTML Docs", href: "/html-docs/overview" },
],
"Mock Servers": [
{ label: "Overview", href: "/mock-servers/overview" },
{
label: "Getting Started",
href: "/mock-servers/tutorial/mock-from-response-examples",
},
{
label: "Create a Mock Server",
href: "/mock-servers/create-mock-server",
},
{ label: "Run a Mock Server", href: "/mock-servers/run-mock-server" },
],
"VS Code": [
{ label: "Overview", href: "/vs-code-extension/overview" },
{
label: "Install and Configure",
href: "/vs-code-extension/install-config",
},
{ label: "Send Requests", href: "/vs-code-extension/send-req" },
],
Formats: [
{ label: "Overview", href: "/reference/overview" },
{ label: "OpenAPI", href: "/open-api/overview" },
{ label: "OpenCollection YAML", href: "/opencollection-yaml/overview" },
{ label: "Converters", href: "/converters/overview" },
{ label: "Bru Lang", href: "/bru-lang/overview" },
],
Licensing: [
{ label: "Overview", href: "/license-overview" },
{ label: "End Users", href: "/license-end-users/activate-license" },
{
label: "Administrators",
href: "/license-administrators/license-portal",
},
],
Popular: [
{
label: "JavaScript API Reference",
href: "/testing/script/javascript-reference",
},
{
label: "Postman Migration",
href: "/get-started/import-export-data/postman-migration",
},
{
label: "Environment Variables",
href: "/variables/environment-variables",
},
{ label: "Bruno CLI Examples", href: "/bru-cli/run/overview" },
],
},
v3: {
"Getting Started": [
{ label: "Introduction", href: "/v3/introduction/getting-started" },
{
label: "Bruno Basics",
href: "/v3/get-started/bruno-basics/create-a-workspace",
},
{
label: "Import or Export Data",
href: "/v3/get-started/import-export-data/import-collections",
},
{ label: "Configure", href: "/v3/get-started/configure/settings" },
],
"Core Features": [
{ label: "Send Requests", href: "/v3/send-requests/overview" },
{ label: "Variables", href: "/v3/variables/overview" },
{
label: "Git Integration & Collaboration",
href: "/v3/git-integration/overview",
},
{ label: "Git Providers", href: "/v3/git-providers/overview" },
{ label: "Tests and Scripts", href: "/v3/testing/tests/introduction" },
{ label: "Secret Management", href: "/v3/secrets-management/overview" },
{ label: "Authentication & Authorization", href: "/v3/auth/overview" },
{ label: "Debugging", href: "/v3/debugging/timeline" },
],
"API Tools": [
{ label: "Create Documentation", href: "/v3/api-docs/overview" },
{ label: "OpenAPI", href: "/v3/open-api/overview" },
],
"Developer Tools": [
{ label: "AI Agents", href: "/v3/agents/overview" },
{ label: "Bruno CLI", href: "/v3/bru-cli/overview" },
{ label: "Bru Lang", href: "/v3/bru-lang/overview" },
{
label: "OpenCollection YAML",
href: "/v3/opencollection-yaml/overview",
},
{ label: "Converters", href: "/v3/converters/overview" },
{ label: "VS Code Extension", href: "/v3/vs-code-extension/overview" },
],
"License Management": [
{ label: "Overview", href: "/v3/license-overview" },
{ label: "End Users", href: "/v3/license-end-users/activate-license" },
{
label: "License Administrators",
href: "/v3/license-administrators/license-portal",
},
],
"Advanced Guides": [
{ label: "Visualizer", href: "/v3/advanced-guides/visualize" },
],
},
v2: {
Introduction: [
{ label: "What is Bruno?", href: "/v2/introduction/what-is-bruno" },
{ label: "Manifesto", href: "/v2/introduction/manifesto" },
{
label: "Feedback & Community",
href: "/v2/introduction/feedback-community",
},
],
"Getting Started": [
{
label: "Bruno Basics",
href: "/v2/get-started/bruno-basics/download",
},
{
label: "Import or Export Data",
href: "/v2/get-started/import-export-data/import-collections",
},
{ label: "Configure", href: "/v2/get-started/configure/settings" },
],
"Core Features": [
{ label: "Send Requests", href: "/v2/send-requests/overview" },
{ label: "Variables", href: "/v2/variables/overview" },
{
label: "Git Integration & Collaboration",
href: "/v2/git-integration/overview",
},
{ label: "Tests and Scripts", href: "/v2/testing/tests/introduction" },
{ label: "Secret Management", href: "/v2/secrets-management/overview" },
{ label: "Authentication & Authorization", href: "/v2/auth/overview" },
],
"API Tools": [
{ label: "Create Documentation", href: "/v2/api-docs/overview" },
{ label: "OpenAPI", href: "/v2/open-api/overview" },
],
"Developer Tools": [
{ label: "Bruno CLI", href: "/v2/bru-cli/overview" },
{ label: "Bru Lang", href: "/v2/bru-lang/overview" },
{ label: "Converters", href: "/v2/converters/overview" },
{ label: "VS Code Extension", href: "/v2/vs-code-extension/overview" },
],
"License Management": [
{ label: "Overview", href: "/v2/license-overview" },
{ label: "End Users", href: "/v2/license-end-users/activate-license" },
{
label: "License Administrators",
href: "/v2/license-administrators/license-portal",
},
],
"Advanced Guides": [
{
label: "Bruno Starter Guide",
href: "/v2/advanced-guides/starter-guide",
},
{
label: "Response Visualization",
href: "/v2/advanced-guides/visualize",
},
],
},
};
function buildDropdown(sections) {
var wrap = document.createElement("div");
wrap.className = "bru-nav-dd";
var panel = document.createElement("div");
panel.className = "bru-nav-dd-panel";
sections.forEach(function (s) {
var a = document.createElement("a");
a.className = "bru-nav-dd-link";
a.href = s.href;
a.textContent = s.label;
panel.appendChild(a);
});
wrap.appendChild(panel);
// Keep panel clicks away from the surrounding tab link/button (see header
// comment); the anchor's own default navigation still runs.
wrap.addEventListener("click", function (e) {
e.stopPropagation();
});
return wrap;
}
// Right-align panels that would spill past the viewport's right edge
// (the last tabs on narrow desktop widths).
function alignDropdowns() {
document
.querySelectorAll(".nav-tabs .nav-tabs-item > .bru-nav-dd")
.forEach(function (dd) {
var itemLeft = dd.parentElement.getBoundingClientRect().left;
dd.classList.toggle(
"bru-dd-right",
itemLeft + dd.offsetWidth > window.innerWidth - 8,
);
});
}
function attach() {
var items = document.querySelectorAll(".nav-tabs .nav-tabs-item");
if (!items.length) return;
var match = window.location.pathname.match(/^\/(v2|v3)(\/|$)/);
var version = match ? match[1] : "v4";
var sectionsByTab = NAV_SECTIONS_BY_VERSION[version];
var added = false;
items.forEach(function (item) {
// Menu tabs (<button>, e.g. "Popular") have a native hover menu — skip.
if (item.tagName !== "A") return;
var existing = item.querySelector(".bru-nav-dd");
if (existing && existing.getAttribute("data-ver") === version) return;
if (existing) {
// Tab node survived a version switch with a panel built for the old
// version's map — rebuild below (or drop, if this label has none).
existing.remove();
item.classList.remove("bru-has-dd");
}
var sections = sectionsByTab[(item.textContent || "").trim()];
if (!sections || sections.length < 2) return;
var dd = buildDropdown(sections);
dd.setAttribute("data-ver", version);
item.appendChild(dd);
item.classList.add("bru-has-dd");
added = true;
});
if (added) alignDropdowns();
}
var scheduled = false;
function scheduleAttach() {
if (scheduled) return;
scheduled = true;
requestAnimationFrame(function () {
scheduled = false;
attach();
});
}
function start() {
attach();
new MutationObserver(scheduleAttach).observe(document.body, {
childList: true,
subtree: true,
});
var resizeTimer;
window.addEventListener("resize", function () {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(alignDropdowns, 150);
});
}
// Wait for full load so React finishes hydrating the navbar before we
// inject into it; the observer covers everything after that.
if (document.readyState === "complete") {
start();
} else {
window.addEventListener("load", start);
}
})();