Skip to content

Commit 3c02814

Browse files
committed
Auto-generate JS component Dependencies tables
Derive each docs "Dependencies" table from the component's real import graph (site/src/libs/js-dependencies.ts) via a new <JsDependencies> shortcode, so the tables stay in sync with the source automatically instead of being hand-maintained. Add the table to every JavaScript- backed component page and migrate the existing tooltip, popover, and menu tables onto the shortcode.
1 parent 0ac9597 commit 3c02814

24 files changed

Lines changed: 289 additions & 45 deletions

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Sass source in `scss/`, TypeScript source in `js/src/`, docs site in `site/` (As
4646
- Frontmatter schema: `title` (required), `description` (required), `toc`, `aliases`, `added`, `mdn`, `reference`, etc.
4747
- Shortcodes: `Example`, `Callout`, `Code`, `Details`
4848
- Internal links: `[[docsref:/path/]]`
49+
- JS component "Dependencies" tables are auto-generated — add a `### Dependencies` heading with `<JsDependencies component="<js-src-basename>" />` (before `### Options`) on any doc for a `js/src/*.ts` component. The table is derived at build time by walking the component's import graph in `site/src/libs/js-dependencies.ts`; never hand-write the file list. When a new source file or third-party package enters the graph, add its human-readable label to `FILE_DESCRIPTIONS` / `PACKAGE_DESCRIPTIONS` in that lib (the build throws if a label is missing).
4950

5051
## Formatting
5152

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
import { getJsDependencies } from '@libs/js-dependencies'
3+
4+
interface Props {
5+
/**
6+
* Name of the component's JavaScript source file (relative to `js/src`, without extension), e.g. `tooltip` or
7+
* `otp-input`. The dependency table is generated by walking this file's import graph.
8+
*/
9+
component: string
10+
/**
11+
* Optional display name used in the introductory sentence, defaulting to the `component` value.
12+
*/
13+
name?: string
14+
}
15+
16+
const { component, name } = Astro.props
17+
18+
if (!component) {
19+
throw new Error("Missing required 'component' prop for the '<JsDependencies />' component.")
20+
}
21+
22+
const dependencies = getJsDependencies(component)
23+
const label = name ?? component
24+
---
25+
26+
<p>The {label} plugin requires the following JavaScript files if you’re building Bootstrap’s JS from source:</p>
27+
28+
<div class="table-responsive">
29+
<table class="table md:table-stacked">
30+
<thead>
31+
<tr>
32+
<th>File</th>
33+
<th>Description</th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
{
38+
dependencies.map((dependency) => (
39+
<tr>
40+
<td data-cell="File">
41+
<code>{dependency.file}</code>
42+
</td>
43+
<td data-cell="Description">{dependency.description}</td>
44+
</tr>
45+
))
46+
}
47+
</tbody>
48+
</table>
49+
</div>

site/src/components/shortcodes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export { default as Details } from './Details.astro'
99
export { default as Example } from './Example.astro'
1010
export { default as GuideFooter } from './GuideFooter.mdx'
1111
export { default as JsDataAttributes } from './JsDataAttributes.mdx'
12+
export { default as JsDependencies } from './JsDependencies.astro'
1213
export { default as JsDismiss } from './JsDismiss.astro'
1314
export { default as JsDocs } from './JsDocs.astro'
1415
export { default as MenuPlacementPlayground } from './MenuPlacementPlayground.astro'

site/src/content/docs/components/alert.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ See the [triggers](#triggers) section for more details.
134134

135135
**Note that closing an alert will remove it from the DOM.**
136136

137+
### Dependencies
138+
139+
<JsDependencies component="alert" />
140+
137141
### Methods
138142

139143
You can create an alert instance with the alert constructor, for example:

site/src/content/docs/components/button.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ Add `data-bs-toggle="button"` to toggle a button’s `active` state. If you’re
259259
| `data-bs-toggle="button"` | Toggles the button’s active (`pressed`) state via the Button plugin. |
260260
</BsTable>
261261

262+
### Dependencies
263+
264+
<JsDependencies component="button" />
265+
262266
### Methods
263267

264268
You can create a button instance with the button constructor, for example:

site/src/content/docs/components/carousel.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ Call carousel manually with:
571571
const carousel = new bootstrap.Carousel('#myCarousel')
572572
```
573573

574+
### Dependencies
575+
576+
<JsDependencies component="carousel" />
577+
574578
### Options
575579

576580
<JsDataAttributes />

site/src/content/docs/components/collapse.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ const collapseElementList = document.querySelectorAll('.collapse')
137137
const collapseList = [...collapseElementList].map(collapseEl => new bootstrap.Collapse(collapseEl))
138138
```
139139

140+
### Dependencies
141+
142+
<JsDependencies component="collapse" />
143+
140144
### Options
141145

142146
<JsDataAttributes />

site/src/content/docs/components/dialog.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ Create a dialog with a single line of JavaScript:
485485
const myDialog = new bootstrap.Dialog('#myDialog')
486486
```
487487

488+
### Dependencies
489+
490+
<JsDependencies component="dialog" />
491+
488492
### Options
489493

490494
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-bs-`, as in `data-bs-backdrop="static"`.

site/src/content/docs/components/drawer.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ const drawerElementList = document.querySelectorAll('dialog.drawer')
349349
const drawerList = [...drawerElementList].map(drawerEl => new bootstrap.Drawer(drawerEl))
350350
```
351351

352+
### Dependencies
353+
354+
<JsDependencies component="drawer" />
355+
352356
### Options
353357

354358
<JsDataAttributes />

site/src/content/docs/components/menu.mdx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -619,20 +619,7 @@ menu.toggle()
619619

620620
### Dependencies
621621

622-
The menu plugin requires the following JavaScript files if you’re building Bootstrap’s JS from source:
623-
624-
<BsTable>
625-
| File | Description |
626-
| --- | --- |
627-
| `js/src/menu.ts` | Main menu component |
628-
| `js/src/base-component.ts` | Base component class |
629-
| `js/src/dom/event-handler.ts` | Event handling utilities |
630-
| `js/src/dom/manipulator.ts` | Data attribute manipulation |
631-
| `js/src/dom/selector-engine.ts` | DOM selector utilities |
632-
| `js/src/util/index.ts` | Core utility functions |
633-
| `js/src/util/floating-ui.ts` | Responsive placement utilities |
634-
| `@floating-ui/dom` | Third-party positioning library |
635-
</BsTable>
622+
<JsDependencies component="menu" />
636623

637624
### Options
638625

0 commit comments

Comments
 (0)