Skip to content

Commit b2421ae

Browse files
decepulisclaude
andcommitted
feat(site): add util reference pipeline for hooks, controllers, mixins, selectors, and utilities
Introduces a convention-based auto-discovery system that generates API reference documentation for non-component exports: React hooks, HTML controllers/mixins, factory functions, selectors, contexts, and utilities. The builder scans package entry points, classifies exports by naming convention (`use*`, `*Controller`, `create*`, `select*`) or `@public` JSDoc tag, extracts type information via typescript-api-extractor and raw TS AST, and outputs JSON consumed by new Astro components (`UtilReference`, `UtilParamsTable`, `UtilReturnTable`). Key design decisions: - Framework-agnostic entries (selectors, createSelector) omit the `frameworks` JSON field, meaning they apply to all frameworks - Framework-specific entries (hooks → react, controllers → html) get `frameworks: ['react']` or `frameworks: ['html']` - Slug collisions use the actual framework prefix (not hardcoded `html-`) - Discovery casts a wide net; only exports with both generated JSON AND a manually-created MDX page appear in the docs - Controller extraction handles both overload declarations and single constructors with a body Also renames ApiReference → ComponentReference to disambiguate from the new UtilReference, adds interactive demos for key utils, and updates the sidebar with Selectors, Hooks & Utilities, and Controllers & Mixins sections. Closes #466 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 78de97e commit b2421ae

File tree

100 files changed

+4946
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4946
-149
lines changed

.claude/skills/api-reference/SKILL.md

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
---
22
name: api-reference
33
description: >-
4-
Scaffold API reference documentation for Video.js 10 components. Validates
5-
the api-docs-builder output, checks design docs and linked PRs for context,
6-
creates the MDX reference page with anatomy, prose sections, demos, and the
7-
ApiReference component. Triggers: "api reference", "reference page",
8-
"scaffold api docs", "add api docs", "component reference".
4+
Scaffold API reference documentation for Video.js 10 components and utility
5+
APIs. Validates the api-docs-builder output, checks design docs and linked
6+
PRs for context, creates the MDX reference page with anatomy, prose sections,
7+
demos, and the ComponentReference/UtilReference component. Triggers: "api
8+
reference", "reference page", "scaffold api docs", "add api docs",
9+
"component reference", "util reference", "hook reference".
910
---
1011

1112
# API Reference
1213

13-
Scaffold a complete API reference page for a Video.js 10 component.
14+
Scaffold a complete API reference page for a Video.js 10 component or utility API.
1415

1516
## Usage
1617

1718
```
18-
/api-reference [component-name]
19+
/api-reference [name]
1920
```
2021

21-
- `component-name` (optional): kebab-case component name (e.g., `play-button`). If omitted, will prompt.
22+
- `name` (optional): kebab-case component name (e.g., `play-button`) or util name (e.g., `use-player`). If omitted, will prompt.
2223

2324
## Arguments
2425

@@ -31,14 +32,15 @@ Load these files based on task:
3132
| Need | Load |
3233
|------|------|
3334
| Builder naming conventions | `references/builder-conventions.md` |
35+
| Util conventions | `references/util-conventions.md` |
3436
| MDX page structure | `references/mdx-structure.md` |
3537
| Demo file patterns | `references/demo-patterns.md` |
3638
| Component libraries reference | `docs` skill → `references/component-libraries.md` |
3739
| Component patterns | `component` skill |
3840
| Accessibility | `aria` skill |
3941
| Design docs | `internal/design/` |
4042

41-
## Your Tasks
43+
## Component Reference Workflow
4244

4345
### Step 1: Gather context
4446

@@ -54,7 +56,7 @@ Accept component name as argument (kebab-case).
5456
### Step 2: Validate api-docs-builder compatibility
5557

5658
1. Run `pnpm -F site api-docs` and check for errors
57-
2. Read the generated JSON at `site/src/content/generated-api-reference/{name}.json`
59+
2. Read the generated JSON at `site/src/content/generated-component-reference/{name}.json`
5860
3. Verify the JSON has expected sections (props, state, dataAttributes, platforms.html.tagName)
5961
4. For multi-part: verify each part appears in `parts` with correct names
6062

@@ -88,9 +90,36 @@ Load `references/mdx-structure.md` for the full structure template.
8890

8991
1. Create `site/src/content/docs/reference/{name}.mdx`
9092
2. Add to sidebar in `site/src/docs.config.ts` (alphabetically within Components section)
91-
3. Structure: frontmatter → imports → Anatomy → prose sections → Examples → `<ApiReference />`
93+
3. Structure: frontmatter → imports → Anatomy → prose sections → Examples → `<ComponentReference />`
9294
4. Run `pnpm dev` from root and verify the page renders in both HTML and React framework modes
9395

96+
## Util Reference Workflow
97+
98+
For hooks, controllers, mixins, factories, and utilities. Load `references/util-conventions.md` for full details.
99+
100+
### Step 1: Ensure auto-discovery can find the util
101+
102+
1. The util must be exported from one of the scanned package index files (`packages/react/src/index.ts`, `packages/html/src/index.ts`, or the store subpath indexes)
103+
2. Add JSDoc with a description to the source export
104+
3. If the export doesn't match a naming convention (`use*`, `*Controller`, `create*`), add `@public` to its JSDoc
105+
106+
Load `references/util-conventions.md` for the full inclusion and classification rules.
107+
108+
### Step 2: Generate and validate JSON
109+
110+
1. Run `pnpm -F site api-docs` and check for errors
111+
2. Read the generated JSON at `site/src/content/generated-util-reference/{slug}.json`
112+
3. Verify it has the expected overloads, parameters, and return value
113+
114+
### Step 3: Create MDX page
115+
116+
1. Create `site/src/content/docs/reference/{slug}.mdx`
117+
2. Structure: frontmatter → `import UtilReference``## Import``## Usage``<UtilReference util="..." />`
118+
3. Add to sidebar in `site/src/docs.config.ts`:
119+
- React utils → "Hooks & Utilities" section (`frameworks: ['react']`)
120+
- HTML utils → "Controllers & Mixins" section (`frameworks: ['html']`)
121+
4. Run `pnpm dev` and verify the page renders correctly
122+
94123
## Related Skills
95124

96125
| Need | Use |

.claude/skills/api-reference/references/builder-conventions.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ The builder fails silently for many issues — data just won't appear in the JSO
7676
# Generate JSON
7777
pnpm -F site api-docs
7878

79-
# Check output
80-
cat site/src/content/generated-api-reference/{name}.json
79+
# Check component output
80+
cat site/src/content/generated-component-reference/{name}.json
81+
82+
# Check util output
83+
cat site/src/content/generated-util-reference/{slug}.json
8184

8285
# Verify schema
83-
# The builder validates against ComponentApiReferenceSchema before writing.
86+
# The builder validates against ComponentReferenceSchema / UtilReferenceSchema before writing.
8487
# Schema errors are logged as errors and cause exit code 1.
8588
```

.claude/skills/api-reference/references/mdx-structure.md

Lines changed: 104 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
Structure and conventions for API reference MDX pages at `site/src/content/docs/reference/`.
44

5-
## Frontmatter
5+
## Component Pages
6+
7+
### Frontmatter
68

79
```yaml
810
---
@@ -17,7 +19,7 @@ description: A button component for muting and unmuting audio playback
1719
- `frameworkTitle.html`: The `static tagName` from the HTML element file
1820
- `description`: One-line description of the component
1921

20-
## Page Structure
22+
### Page Structure
2123

2224
```
2325
frontmatter
@@ -29,7 +31,7 @@ imports (React demos, HTML demos)
2931
## Examples
3032
### BasicUsage
3133
### [Additional demos]
32-
<ApiReference component="{PascalCase}" />
34+
<ComponentReference component="{PascalCase}" />
3335
```
3436

3537
## Imports Section
@@ -185,19 +187,115 @@ Key details:
185187
- React source tabs: `App.tsx`, `App.css`
186188
- HTML source tabs: `index.html`, `index.css`, `index.ts`
187189

188-
## ApiReference Component
190+
### ComponentReference Component
189191

190192
Always the last element in the file:
191193

192194
```mdx
193-
<ApiReference component="MuteButton" />
195+
<ComponentReference component="MuteButton" />
194196
```
195197

196198
The component auto-renders Props, State, Data Attributes for single-part and all Parts for multi-part.
197199

200+
### Required Astro Component Imports
201+
202+
Every component reference MDX needs these at the top of the imports:
203+
204+
```mdx
205+
import ComponentReference from "@/components/docs/api-reference/ComponentReference.astro";
206+
import FrameworkCase from "@/components/docs/FrameworkCase.astro";
207+
import StyleCase from "@/components/docs/StyleCase.astro";
208+
import Demo from "@/components/docs/demos/Demo.astro";
209+
```
210+
211+
---
212+
213+
## Util Pages
214+
215+
Util pages document React hooks/utilities and HTML controllers/mixins. They are simpler than component pages — no demos, no anatomy.
216+
217+
### Frontmatter
218+
219+
```yaml
220+
---
221+
title: usePlayer
222+
description: Hook to access the player store from within a Player Provider
223+
---
224+
```
225+
226+
- `title`: The exported function/class name (e.g., `usePlayer`, `PlayerController`)
227+
- No `frameworkTitle` — util pages are framework-specific
228+
- `description`: One-line description
229+
230+
### Page Structure
231+
232+
```
233+
frontmatter
234+
import UtilReference
235+
## Import
236+
## Usage
237+
<UtilReference util="{Name}" />
238+
```
239+
240+
### Import Section
241+
242+
Show the import statement for the util:
243+
244+
```mdx
245+
## Import
246+
247+
\`\`\`tsx
248+
import { usePlayer } from '@videojs/react';
249+
\`\`\`
250+
```
251+
252+
### Usage Section
253+
254+
Explain usage patterns with code examples. For multi-overload utils, document each overload:
255+
256+
```mdx
257+
## Usage
258+
259+
`usePlayer` has two overloads:
260+
261+
**Store access (no subscription)** -- returns the store instance.
262+
263+
\`\`\`tsx
264+
const store = usePlayer();
265+
\`\`\`
266+
267+
**Selector-based subscription** -- returns selected state.
268+
269+
\`\`\`tsx
270+
const paused = usePlayer((s) => s.paused);
271+
\`\`\`
272+
```
273+
274+
### UtilReference Component
275+
276+
Always the last element in the file:
277+
278+
```mdx
279+
<UtilReference util="usePlayer" />
280+
```
281+
282+
The component auto-renders Parameters and Return Value tables. For multi-overload utils, it renders each overload with its own sections.
283+
284+
### Required Import
285+
286+
```mdx
287+
import UtilReference from "@/components/docs/api-reference/UtilReference.astro";
288+
```
289+
290+
---
291+
198292
## Sidebar Entry
199293

200-
Add to `site/src/docs.config.ts` in the Components section, alphabetically:
294+
Add to `site/src/docs.config.ts` in the appropriate section, alphabetically:
295+
296+
- **Components** — UI component reference pages
297+
- **Hooks & Utilities** (`frameworks: ['react']`) — React hooks and utilities
298+
- **Controllers & Mixins** (`frameworks: ['html']`) — HTML controllers and mixins
201299

202300
```ts
203301
{
@@ -212,14 +310,3 @@ Add to `site/src/docs.config.ts` in the Components section, alphabetically:
212310
],
213311
},
214312
```
215-
216-
## Required Astro Component Imports
217-
218-
Every reference MDX needs these at the top of the imports:
219-
220-
```mdx
221-
import ApiReference from "@/components/docs/api-reference/ApiReference.astro";
222-
import FrameworkCase from "@/components/docs/FrameworkCase.astro";
223-
import StyleCase from "@/components/docs/StyleCase.astro";
224-
import Demo from "@/components/docs/demos/Demo.astro";
225-
```

0 commit comments

Comments
 (0)