@stacksjs/components 0.2.990 → 0.2.997

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.
Files changed (95) hide show
  1. package/dist/ApiOperation-369y1zgt.stx +114 -0
  2. package/dist/ApiReference-ww45jj32.stx +92 -0
  3. package/dist/ApiSchema-dsx4tsv4.stx +47 -0
  4. package/dist/AreaChart-8fy34adp.stx +77 -0
  5. package/dist/BarChart-4xdrjhhn.stx +77 -0
  6. package/dist/{Combobox-9n04ec5w.stx → Combobox-fgbpxbty.stx} +174 -5
  7. package/dist/ComboboxOptions-sfkc98a9.stx +36 -0
  8. package/dist/{CommandPalette-cj6pe5ph.stx → CommandPalette-sf03s7b2.stx} +3 -1
  9. package/dist/LineChart-ctebkkm8.stx +77 -0
  10. package/dist/{List-5ey6k813.stx → List-mjkged1z.stx} +1 -1
  11. package/dist/{Notification-b3cz24f0.stx → Notification-1pvt347q.stx} +16 -4
  12. package/dist/{Popover-jjt7p7sn.stx → Popover-gntg33xd.stx} +1 -1
  13. package/dist/PricingPlan-h7jt2696.stx +67 -0
  14. package/dist/PricingTable-v3vdn6av.stx +149 -0
  15. package/dist/SecretField-q2xgth94.stx +219 -0
  16. package/dist/{Select-36s22z6d.stx → Select-yhmtvqcx.stx} +7 -4
  17. package/dist/Sparkline-gp859n4h.stx +29 -0
  18. package/dist/StatCard-gff0yx6b.stx +93 -0
  19. package/dist/StatGroup-e0d5dmt7.stx +17 -0
  20. package/dist/components/CodeBlock.d.ts +4 -1
  21. package/dist/components/CodeGroup.d.ts +34 -0
  22. package/dist/components/code-group.d.ts +19 -0
  23. package/dist/components/index.d.ts +2 -0
  24. package/dist/index.d.ts +13 -0
  25. package/dist/index.js +25 -22
  26. package/dist/ui/api-reference/ApiOperation.d.ts +17 -0
  27. package/dist/ui/api-reference/ApiReference.d.ts +28 -0
  28. package/dist/ui/api-reference/ApiSchema.d.ts +17 -0
  29. package/dist/ui/api-reference/index.d.ts +30 -0
  30. package/dist/ui/api-reference/openapi.d.ts +137 -0
  31. package/dist/ui/chart/AreaChart.d.ts +33 -0
  32. package/dist/ui/chart/BarChart.d.ts +33 -0
  33. package/dist/ui/chart/LineChart.d.ts +33 -0
  34. package/dist/ui/chart/Sparkline.d.ts +19 -0
  35. package/dist/ui/chart/core.d.ts +111 -0
  36. package/dist/ui/chart/index.d.ts +51 -0
  37. package/dist/ui/chart/interaction.d.ts +11 -0
  38. package/dist/ui/combobox/Combobox.d.ts +10 -1
  39. package/dist/ui/combobox/ComboboxOptions.d.ts +6 -0
  40. package/dist/ui/combobox/index.d.ts +7 -0
  41. package/dist/ui/command-palette/CommandPalette.d.ts +2 -0
  42. package/dist/ui/input/SecretField.d.ts +56 -0
  43. package/dist/ui/input/index.d.ts +21 -0
  44. package/dist/ui/notification/Notification.d.ts +2 -0
  45. package/dist/ui/pricing/PricingPlan.d.ts +21 -0
  46. package/dist/ui/pricing/PricingTable.d.ts +50 -0
  47. package/dist/ui/pricing/index.d.ts +38 -0
  48. package/dist/ui/pricing/pricing.d.ts +64 -0
  49. package/dist/ui/select/Select.d.ts +2 -0
  50. package/dist/ui/stat/StatCard.d.ts +42 -0
  51. package/dist/ui/stat/StatGroup.d.ts +12 -0
  52. package/dist/ui/stat/format.d.ts +37 -0
  53. package/dist/ui/stat/index.d.ts +23 -0
  54. package/package.json +3 -3
  55. package/src/components/CodeBlock.stx +4 -1
  56. package/src/components/CodeGroup.stx +217 -0
  57. package/src/components/code-group.ts +57 -0
  58. package/src/components/index.ts +2 -0
  59. package/src/index.ts +18 -0
  60. package/src/ui/api-reference/ApiOperation.stx +114 -0
  61. package/src/ui/api-reference/ApiReference.stx +92 -0
  62. package/src/ui/api-reference/ApiSchema.stx +47 -0
  63. package/src/ui/api-reference/README.md +44 -0
  64. package/src/ui/api-reference/index.ts +35 -0
  65. package/src/ui/api-reference/openapi.ts +825 -0
  66. package/src/ui/chart/AreaChart.stx +77 -0
  67. package/src/ui/chart/BarChart.stx +77 -0
  68. package/src/ui/chart/LineChart.stx +77 -0
  69. package/src/ui/chart/README.md +97 -0
  70. package/src/ui/chart/Sparkline.stx +29 -0
  71. package/src/ui/chart/core.ts +730 -0
  72. package/src/ui/chart/index.ts +71 -0
  73. package/src/ui/chart/interaction.ts +175 -0
  74. package/src/ui/combobox/Combobox.stx +174 -5
  75. package/src/ui/combobox/ComboboxOptions.stx +20 -0
  76. package/src/ui/combobox/README.md +41 -0
  77. package/src/ui/combobox/index.ts +13 -0
  78. package/src/ui/command-palette/CommandPalette.stx +3 -1
  79. package/src/ui/input/SecretField.stx +219 -0
  80. package/src/ui/input/index.ts +32 -0
  81. package/src/ui/list/List.stx +1 -1
  82. package/src/ui/notification/Notification.stx +16 -4
  83. package/src/ui/popover/Popover.stx +1 -1
  84. package/src/ui/pricing/PricingPlan.stx +67 -0
  85. package/src/ui/pricing/PricingTable.stx +149 -0
  86. package/src/ui/pricing/README.md +74 -0
  87. package/src/ui/pricing/index.ts +49 -0
  88. package/src/ui/pricing/pricing.ts +177 -0
  89. package/src/ui/select/Select.stx +7 -4
  90. package/src/ui/stat/README.md +60 -0
  91. package/src/ui/stat/StatCard.stx +93 -0
  92. package/src/ui/stat/StatGroup.stx +17 -0
  93. package/src/ui/stat/format.ts +147 -0
  94. package/src/ui/stat/index.ts +38 -0
  95. package/dist/ComboboxOptions-zhr9b6rx.stx +0 -16
@@ -1,4 +1,6 @@
1
1
  export { default as CodeBlock } from './CodeBlock.stx'
2
+ export { default as CodeGroup } from './CodeGroup.stx'
3
+ export { type CodeTab, defaultTabIndex, readCodeTabs } from './code-group'
2
4
  export { default as Footer } from './Footer.stx'
3
5
  export { default as Hero } from './Hero.stx'
4
6
  export { default as Installation } from './Installation.stx'
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Export shared components (these will be imported as .stx files)
2
2
  export { default as CodeBlock } from './components/CodeBlock.stx'
3
+ export { default as CodeGroup } from './components/CodeGroup.stx'
4
+ export { type CodeTab, defaultTabIndex, readCodeTabs } from './components/code-group'
3
5
 
4
6
  export { default as Footer } from './components/Footer.stx'
5
7
  export { default as Hero } from './components/Hero.stx'
@@ -12,6 +14,7 @@ export * from './utils/overlays'
12
14
  export * from './theme'
13
15
  // Export UI components
14
16
  export * from './ui/accordion'
17
+ export * from './ui/api-reference'
15
18
  export * from './ui/app-frame'
16
19
  export * from './ui/appearance-picker'
17
20
  export * from './ui/audio'
@@ -28,6 +31,7 @@ export * from './ui/empty-state'
28
31
  export * from './ui/error-state'
29
32
  export * from './ui/theme-toggle'
30
33
  export * from './ui/card'
34
+ export * from './ui/chart'
31
35
 
32
36
  export * from './ui/checkbox'
33
37
  export * from './ui/choice-chips'
@@ -60,6 +64,7 @@ export * from './ui/payment'
60
64
  export * from './ui/popover'
61
65
  export * from './ui/portal'
62
66
  export * from './ui/preview-frame'
67
+ export * from './ui/pricing'
63
68
  export * from './ui/progress'
64
69
  export * from './ui/radio'
65
70
  export * from './ui/radio-group'
@@ -72,6 +77,7 @@ export * from './ui/skeleton'
72
77
  export * from './ui/slider'
73
78
  export * from './ui/spinner'
74
79
  export * from './ui/split-pane'
80
+ export * from './ui/stat'
75
81
  export * from './ui/stepper'
76
82
  export * from './ui/storage'
77
83
  export * from './ui/switch'
@@ -112,6 +118,18 @@ export interface CodeBlockProps extends ComponentProps {
112
118
  theme?: 'light' | 'dark' | 'auto'
113
119
  lineNumbers?: boolean
114
120
  copyable?: boolean
121
+ /** The tab name inside a `<CodeGroup>`. Default: the language. */
122
+ label?: string
123
+ /** Inside a `<CodeGroup>`, the tab shown first. */
124
+ default?: boolean
125
+ }
126
+
127
+ export interface CodeGroupProps extends ComponentProps {
128
+ /** Groups with the same key share the chosen language, stored in localStorage under it. Default `code-language`. */
129
+ syncKey?: string
130
+ /** Accessible name of the tab list. Default `Code examples`. */
131
+ label?: string
132
+ id?: string
115
133
  }
116
134
 
117
135
  export interface HeroProps extends ComponentProps {
@@ -0,0 +1,114 @@
1
+ <script server cache>
2
+ /*
3
+ * <ApiOperation> (stacksjs/stx#2324): one operation from buildApiReference,
4
+ * as a section with its own anchor: method and path, summary, description,
5
+ * deprecation, the auth it needs, parameters, the request body, each response
6
+ * with its schema, and request examples in curl, JavaScript and Python as a
7
+ * CodeGroup, so the reader's language follows them across the page.
8
+ */
9
+ export const op = $props.operation && typeof $props.operation === 'object' ? $props.operation : null
10
+ export const syncKey = $props.syncKey || 'code-language'
11
+ export const className = $props.className || ''
12
+ const methodTone = { GET: 'bg-info-soft text-info-soft-ink', POST: 'bg-success-soft text-success-soft-ink', PUT: 'bg-warning-soft text-warning-soft-ink', PATCH: 'bg-warning-soft text-warning-soft-ink', DELETE: 'bg-danger-soft text-danger-soft-ink' }
13
+ export const methodClasses = `inline-flex items-center rounded px-2 py-0.5 font-mono text-xs font-semibold ${op ? (methodTone[op.method] || 'bg-surface-sunken text-fg') : ''}`
14
+ export const groups = op ? ['path', 'query', 'header', 'cookie'].map(place => ({ place, title: `${place.charAt(0).toUpperCase()}${place.slice(1)} parameters`, items: op.parameters.filter(p => p.in === place) })).filter(g => g.items.length) : []
15
+ export const statusTone = op ? op.responses.map(r => r.status.startsWith('2') ? 'text-success' : r.status.startsWith('4') || r.status.startsWith('5') ? 'text-danger' : 'text-fg-soft') : []
16
+ </script>
17
+
18
+ @if(op)
19
+ <section id="{{ op.anchor }}" class="scroll-mt-20 border-t border-line py-10 {{ className }}" data-stx-api-operation="{{ op.id }}" aria-labelledby="{{ op.anchor }}-title">
20
+ <h3 id="{{ op.anchor }}-title" class="flex flex-wrap items-center gap-2 text-xl font-semibold text-fg">
21
+ <a href="#{{ op.anchor }}" class="hover:underline">{{ op.summary || op.method + ' ' + op.path }}</a>
22
+ @if(op.webhook)<span class="rounded bg-info-soft px-2 py-0.5 text-xs font-medium text-info-soft-ink">Webhook</span>@endif
23
+ @if(op.deprecated)<span class="rounded bg-warning-soft px-2 py-0.5 text-xs font-medium text-warning-soft-ink">Deprecated</span>@endif
24
+ </h3>
25
+ <p class="mt-2 flex items-center gap-2"><span class="{{ methodClasses }}">{{ op.method }}</span><code class="font-mono text-sm text-fg">{{ op.path }}</code></p>
26
+ @if(op.description)<p class="mt-3 text-sm text-fg-muted">{{ op.description }}</p>@endif
27
+
28
+ <p class="mt-3 text-sm text-fg-muted" data-stx-api-security>
29
+ @if(op.webhook)
30
+ Sent by the API to the URL you subscribe; answer with one of the responses below.
31
+ @elseif(op.security.length)
32
+ Requires
33
+ @foreach(op.security as i => alternative)@if(i > 0) or @endif@foreach(alternative as j => requirement)@if(j > 0) and @endif<a href="#{{ requirement.anchor }}" class="font-medium text-link hover:underline">{{ requirement.name }}</a>@if(requirement.scopes.length) ({{ requirement.scopes.join(', ') }})@endif@endforeach@endforeach
34
+ @else
35
+ No authentication.
36
+ @endif
37
+ </p>
38
+
39
+ @foreach(groups as group)
40
+ <h4 class="mt-6 text-sm font-semibold text-fg">{{ group.title }}</h4>
41
+ <table class="mt-2 w-full border-collapse text-left text-sm">
42
+ <caption class="sr-only">{{ group.title }}</caption>
43
+ <thead>
44
+ <tr class="border-b border-line text-xs uppercase tracking-wide text-fg-soft"><th scope="col" class="py-2 pr-4 font-medium">Name</th><th scope="col" class="py-2 pr-4 font-medium">Type</th><th scope="col" class="py-2 font-medium">Description</th></tr>
45
+ </thead>
46
+ <tbody>
47
+ @foreach(group.items as param)
48
+ <tr class="border-b border-line align-top">
49
+ <th scope="row" class="py-2 pr-4 font-mono text-[13px] font-normal text-fg">{{ param.name }}@if(param.required)<span class="ml-1 text-danger" aria-hidden="true">*</span><span class="sr-only"> (required)</span>@endif</th>
50
+ <td class="py-2 pr-4 font-mono text-[13px] text-fg-muted">{{ param.type }}</td>
51
+ <td class="py-2 text-fg-muted">{{ param.description }}@if(param.deprecated) <span class="text-warning">Deprecated.</span>@endif</td>
52
+ </tr>
53
+ @endforeach
54
+ </tbody>
55
+ </table>
56
+ @endforeach
57
+
58
+ @if(op.body)
59
+ <h4 class="mt-6 text-sm font-semibold text-fg">Request body <span class="font-mono text-xs font-normal text-fg-soft">{{ op.body.mediaType }}</span>@if(op.body.ref) <a href="#{{ op.body.ref }}" class="font-mono text-xs font-normal text-link hover:underline">{{ op.body.schema }}</a>@endif@if(op.body.required)<span class="ml-1 text-xs font-normal text-danger">required</span>@endif</h4>
60
+ @if(op.body.description)<p class="mt-1 text-sm text-fg-muted">{{ op.body.description }}</p>@endif
61
+ <ApiSchema :rows="op.body.rows" caption="Request body fields" />
62
+ @if(op.body.example)
63
+ <details class="mt-3" data-stx-api-example="request">
64
+ <summary class="cursor-pointer text-sm text-fg-muted">Example body</summary>
65
+ <div class="mt-2"><CodeBlock language="json" :code="op.body.example" /></div>
66
+ </details>
67
+ @endif
68
+ @endif
69
+
70
+ <h4 class="mt-6 text-sm font-semibold text-fg">Responses</h4>
71
+ <dl class="mt-2 space-y-4">
72
+ @foreach(op.responses as i => response)
73
+ <div data-stx-api-response="{{ response.status }}">
74
+ <dt class="flex items-center gap-2 text-sm"><span class="font-mono font-semibold {{ statusTone[i] }}">{{ response.status }}</span><span class="text-fg-muted">{{ response.description }}</span>@if(response.ref)<a href="#{{ response.ref }}" class="font-mono text-xs text-link hover:underline">{{ response.schema }}</a>@endif@if(response.mediaType)<span class="font-mono text-xs text-fg-soft">{{ response.mediaType }}</span>@endif</dt>
75
+ @if(response.headers.length)
76
+ <dd class="mt-2">
77
+ <table class="w-full border-collapse text-left text-sm">
78
+ <caption class="sr-only">{{ response.status }} response headers</caption>
79
+ <thead><tr class="border-b border-line text-xs uppercase tracking-wide text-fg-soft"><th scope="col" class="py-2 pr-4 font-medium">Header</th><th scope="col" class="py-2 pr-4 font-medium">Type</th><th scope="col" class="py-2 font-medium">Description</th></tr></thead>
80
+ <tbody>
81
+ @foreach(response.headers as header)
82
+ <tr class="border-b border-line align-top"><th scope="row" class="py-2 pr-4 font-mono text-[13px] font-normal text-fg">{{ header.name }}</th><td class="py-2 pr-4 font-mono text-[13px] text-fg-muted">{{ header.type }}</td><td class="py-2 text-fg-muted">{{ header.description }}</td></tr>
83
+ @endforeach
84
+ </tbody>
85
+ </table>
86
+ </dd>
87
+ @endif
88
+ @if(response.rows.length)
89
+ <dd><ApiSchema :rows="response.rows" :caption="response.status + ' response fields'" /></dd>
90
+ @endif
91
+ @if(response.example && response.example !== 'null')
92
+ <dd>
93
+ <details class="mt-2" data-stx-api-example="{{ response.status }}">
94
+ <summary class="cursor-pointer text-sm text-fg-muted">Example response</summary>
95
+ <div class="mt-2"><CodeBlock language="json" :code="response.example" /></div>
96
+ </details>
97
+ </dd>
98
+ @endif
99
+ </div>
100
+ @endforeach
101
+ </dl>
102
+
103
+ @if(op.examples)
104
+ <h4 class="mt-6 text-sm font-semibold text-fg">Example request</h4>
105
+ <div class="mt-2">
106
+ <CodeGroup :syncKey="syncKey" label="Example request">
107
+ <CodeBlock language="bash" label="curl" :code="op.examples.curl" />
108
+ <CodeBlock language="javascript" label="JavaScript" :code="op.examples.javascript" />
109
+ <CodeBlock language="python" label="Python" :code="op.examples.python" />
110
+ </CodeGroup>
111
+ </div>
112
+ @endif
113
+ </section>
114
+ @endif
@@ -0,0 +1,92 @@
1
+ <script server>
2
+ import { buildApiReference, loadOpenApi } from './openapi'
3
+
4
+ /*
5
+ * <ApiReference> (stacksjs/stx#2324): a whole API reference from an OpenAPI
6
+ * 3.0 or 3.1 document, read at build time.
7
+ *
8
+ * <ApiReference spec="./openapi.json" />
9
+ *
10
+ * `spec` is a path (JSON or YAML), a URL, or the parsed document. Everything
11
+ * is rendered on the server: a table of contents, the authentication
12
+ * schemes, each tag's operations (<ApiOperation>) and every named schema
13
+ * (<ApiSchema>), each with a stable anchor. No script is needed to read it;
14
+ * the examples' language tabs are a CodeGroup.
15
+ *
16
+ * A document that does not validate throws an OpenApiError naming the
17
+ * offending path. It is a declared build failure (`stxBuildFailure`), so a
18
+ * static build or `build-views` stops with that message instead of writing
19
+ * the page without its reference; in development it is logged and the
20
+ * component renders a notice in its place.
21
+ */
22
+ export const reference = buildApiReference(await loadOpenApi($props.spec), { baseUrl: $props.baseUrl || '' })
23
+ export const syncKey = $props.syncKey || 'code-language'
24
+ export const showToc = $bool($props.toc, true)
25
+ export const className = $props.className || ''
26
+ /* The search index entries, for a docs site's search to read off the page (escaped as an attribute). */
27
+ export const searchJson = JSON.stringify(reference.search)
28
+ </script>
29
+
30
+ @if(reference)
31
+ <div class="lg:grid lg:grid-cols-[16rem_minmax(0,1fr)] lg:gap-10 {{ className }}" data-stx-api-reference data-search-index="{{ searchJson }}">
32
+ @if(showToc)
33
+ <nav class="mb-8 text-sm lg:sticky lg:top-6 lg:mb-0 lg:max-h-[calc(100vh-3rem)] lg:self-start lg:overflow-y-auto" aria-label="API reference">
34
+ <ul class="space-y-4" role="list">
35
+ @foreach(reference.toc as section)
36
+ <li>
37
+ <a href="#{{ section.anchor }}" class="font-semibold text-fg hover:underline">{{ section.text }}</a>
38
+ <ul class="mt-2 space-y-1 border-l border-line pl-3" role="list">
39
+ @foreach(section.children as item)
40
+ <li><a href="#{{ item.anchor }}" class="flex items-baseline gap-2 text-fg-muted hover:text-fg">@if(item.method)<span class="w-12 shrink-0 font-mono text-[10px] font-semibold text-fg-soft">{{ item.method }}</span>@endif<span>{{ item.text }}</span></a></li>
41
+ @endforeach
42
+ </ul>
43
+ </li>
44
+ @endforeach
45
+ </ul>
46
+ </nav>
47
+ @endif
48
+
49
+ <div class="min-w-0">
50
+ <header>
51
+ <h1 class="text-3xl font-semibold tracking-tight text-fg">{{ reference.title }}@if(reference.version) <span class="align-middle text-sm font-normal text-fg-soft">v{{ reference.version }}</span>@endif</h1>
52
+ @if(reference.description)<p class="mt-2 text-fg-muted">{{ reference.description }}</p>@endif
53
+ <p class="mt-2 text-sm text-fg-soft">Base URL <code class="font-mono text-fg">{{ reference.baseUrl }}</code></p>
54
+ </header>
55
+
56
+ @if(reference.securitySchemes.length)
57
+ <section id="authentication" class="scroll-mt-20 mt-10" aria-labelledby="authentication-title">
58
+ <h2 id="authentication-title" class="text-2xl font-semibold text-fg"><a href="#authentication" class="hover:underline">Authentication</a></h2>
59
+ <dl class="mt-4 space-y-3">
60
+ @foreach(reference.securitySchemes as scheme)
61
+ <div id="{{ scheme.anchor }}" class="scroll-mt-20" data-stx-api-security-scheme="{{ scheme.name }}">
62
+ <dt class="font-mono text-sm font-semibold text-fg">{{ scheme.name }}</dt>
63
+ <dd class="text-sm text-fg-muted">{{ scheme.summary }}@if(scheme.description). {{ scheme.description }}@endif</dd>
64
+ </div>
65
+ @endforeach
66
+ </dl>
67
+ </section>
68
+ @endif
69
+
70
+ @foreach(reference.tags as tag)
71
+ <section id="{{ tag.anchor }}" class="scroll-mt-20 mt-12" aria-labelledby="{{ tag.anchor }}-title" data-stx-api-tag="{{ tag.name }}">
72
+ <h2 id="{{ tag.anchor }}-title" class="text-2xl font-semibold text-fg"><a href="#{{ tag.anchor }}" class="hover:underline">{{ tag.name }}</a></h2>
73
+ @if(tag.description)<p class="mt-2 text-fg-muted">{{ tag.description }}</p>@endif
74
+ @foreach(tag.operations as operation)
75
+ <ApiOperation :operation="operation" :syncKey="syncKey" />
76
+ @endforeach
77
+ </section>
78
+ @endforeach
79
+
80
+ @if(reference.schemas.length)
81
+ <section id="schemas" class="scroll-mt-20 mt-12 space-y-10" aria-labelledby="schemas-title">
82
+ <h2 id="schemas-title" class="text-2xl font-semibold text-fg"><a href="#schemas" class="hover:underline">Schemas</a></h2>
83
+ @foreach(reference.schemas as schema)
84
+ <ApiSchema :schema="schema" />
85
+ @endforeach
86
+ </section>
87
+ @endif
88
+ </div>
89
+ </div>
90
+ @else
91
+ <div role="alert" class="rounded-panel border border-danger-line bg-danger-soft p-4 text-sm text-danger-soft-ink {{ className }}" data-stx-api-reference-error>The API reference could not be rendered: its OpenAPI document is invalid. The build log names the offending path.</div>
92
+ @endif
@@ -0,0 +1,47 @@
1
+ <script server cache>
2
+ /*
3
+ * <ApiSchema> (stacksjs/stx#2324): a schema's fields as a table. Given a
4
+ * named `schema` from buildApiReference it is a section with its own anchor
5
+ * (`schema-<name>`); given only `rows` it is the table, as an operation's
6
+ * body and responses use it. A field whose type is a named schema links to
7
+ * that schema's section rather than expanding it again.
8
+ */
9
+ const named = $props.schema && typeof $props.schema === 'object' ? $props.schema : null
10
+ export const schema = named
11
+ export const rows = named ? named.rows : (Array.isArray($props.rows) ? $props.rows : [])
12
+ export const caption = $props.caption || (named ? `${named.name} fields` : 'Fields')
13
+ export const className = $props.className || ''
14
+ export const indent = rows.map(row => `padding-left: ${row.depth * 1.25}rem`)
15
+ </script>
16
+
17
+ @if(schema)
18
+ <section id="{{ schema.anchor }}" class="scroll-mt-20 {{ className }}" data-stx-api-schema="{{ schema.name }}" aria-labelledby="{{ schema.anchor }}-title">
19
+ <h3 id="{{ schema.anchor }}-title" class="text-lg font-semibold text-fg"><a href="#{{ schema.anchor }}" class="hover:underline">{{ schema.name }}</a> <span class="ml-1 font-mono text-sm font-normal text-fg-soft">{{ schema.type }}</span></h3>
20
+ @if(schema.description)<p class="mt-1 text-sm text-fg-muted">{{ schema.description }}</p>@endif
21
+ @endif
22
+ @if(rows.length)
23
+ <div class="mt-3 overflow-x-auto">
24
+ <table class="w-full border-collapse text-left text-sm">
25
+ <caption class="sr-only">{{ caption }}</caption>
26
+ <thead>
27
+ <tr class="border-b border-line text-xs uppercase tracking-wide text-fg-soft">
28
+ <th scope="col" class="py-2 pr-4 font-medium">Field</th>
29
+ <th scope="col" class="py-2 pr-4 font-medium">Type</th>
30
+ <th scope="col" class="py-2 font-medium">Description</th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ @foreach(rows as i => row)
35
+ <tr class="border-b border-line align-top">
36
+ <th scope="row" class="py-2 pr-4 font-mono text-[13px] font-normal text-fg" style="{{ indent[i] }}">{{ row.name }}@if(row.required)<span class="ml-1 text-danger" aria-hidden="true">*</span><span class="sr-only"> (required)</span>@endif</th>
37
+ <td class="py-2 pr-4 font-mono text-[13px] text-fg-muted">@if(row.ref)<a href="#{{ row.ref }}" class="text-link hover:underline">{{ row.type }}</a>@else{{ row.type }}@endif</td>
38
+ <td class="py-2 text-fg-muted">{{ row.description }}@foreach(row.notes as note)<span class="ml-1 inline-block rounded bg-surface-sunken px-1.5 py-0.5 font-mono text-xs text-fg-soft">{{ note }}</span>@endforeach</td>
39
+ </tr>
40
+ @endforeach
41
+ </tbody>
42
+ </table>
43
+ </div>
44
+ @endif
45
+ @if(schema)
46
+ </section>
47
+ @endif
@@ -0,0 +1,44 @@
1
+ # API Reference
2
+
3
+ Render a navigable API reference from an OpenAPI 3.0 or 3.1 document, entirely on the server.
4
+
5
+ ```stx
6
+ <ApiReference spec="./storage/openapi.json" />
7
+ ```
8
+
9
+ `spec` is a path to a JSON or YAML file, a URL, or the parsed document; it is read when the page is built. The reference has:
10
+
11
+ - a table of contents (`<nav aria-label="API reference">`) linking every section;
12
+ - **Authentication**: each security scheme (`Header X-Api-Key`, `Bearer token (JWT)`, OAuth 2 flows);
13
+ - one section per **tag**, in the document's order, with each **operation**: method and path, summary, description, a deprecation badge, which schemes it requires (or "No authentication."), path, query, header and cookie parameters, the request body and every response with its fields;
14
+ - request examples in **curl, JavaScript and Python**, generated from the operation with its required parameters and auth header, in a `CodeGroup` so the reader's language follows every example on the site;
15
+ - each response's **headers**, and an **example payload** for the request body and each response;
16
+ - 3.1 **webhooks**, as operations the API sends;
17
+ - every named **schema**, with `$ref` resolved, `allOf` merged, `oneOf`/`anyOf` listed as options, and a field whose type is a named schema linking to it instead of expanding it again (so recursive schemas are safe).
18
+
19
+ Every operation, schema, tag and scheme has a stable anchor: `op-<operationId>`, `schema-<name>`, `tag-<name>`, `security-<name>`. The root carries `data-search-index`, a JSON list of `{ title, anchor, text, kind }` for a docs site's search.
20
+
21
+ ## Props
22
+
23
+ | Prop | Type | Default | Description |
24
+ |------|------|---------|-------------|
25
+ | `spec` | `string \| object` | - | Path, URL or document |
26
+ | `baseUrl` | `string` | the first `servers` URL | Base URL used in examples |
27
+ | `syncKey` | `string` | `'code-language'` | CodeGroup key for the examples' tabs |
28
+ | `toc` | `boolean` | `true` | Show the table of contents |
29
+ | `className` | `string` | `''` | Additional classes |
30
+
31
+ `<ApiOperation :operation>` and `<ApiSchema :schema>` (or `:rows`) render one operation or one schema from the model, for a page laid out by hand.
32
+
33
+ ## Invalid documents
34
+
35
+ `loadOpenApi` validates the document and throws an `OpenApiError` naming the offending path (`Invalid OpenAPI document at paths./keys.get.responses: an operation needs at least one response`). The error is a declared build failure (`stxBuildFailure: true`), so a static build or `build-views` stops with that message rather than writing the page without its reference. In development the message is logged and the component renders a notice in its place.
36
+
37
+ ## Split documents and webhooks
38
+
39
+ A `$ref` to another file (`./schemas.yaml#/Key`) is inlined when the document is loaded from a path or URL, resolved relative to the file that holds it, as are `#/...` refs inside that file. 3.1 `webhooks` are listed under **Webhooks** (`webhook-<operationId>`), marked as sent by the API, without request examples. Responses show their headers, and the request body and each response have an example payload (the document's own example, else one built from the schema).
40
+
41
+ ## The model
42
+
43
+ `buildApiReference(doc)` returns the JSON-safe model the components render: `tags[].operations[]`, `schemas[]`, `securitySchemes[]`, `toc` and `search`. Use it to feed another renderer, such as a docs site's sidebar.
44
+
@@ -0,0 +1,35 @@
1
+ export { default as ApiOperation } from './ApiOperation.stx'
2
+ export { default as ApiReference } from './ApiReference.stx'
3
+ export { default as ApiSchema } from './ApiSchema.stx'
4
+ export {
5
+ type ApiBody,
6
+ type ApiOperation as ApiOperationModel,
7
+ type ApiParameter,
8
+ type ApiReferenceModel,
9
+ type ApiResponse,
10
+ type ApiSchema as ApiSchemaModel,
11
+ type ApiSecurityScheme,
12
+ type ApiTag,
13
+ buildApiReference,
14
+ exampleFor,
15
+ loadOpenApi,
16
+ OpenApiError,
17
+ parseOpenApiText,
18
+ requestExamples,
19
+ resolveRef,
20
+ type SchemaRow,
21
+ schemaRows,
22
+ validateOpenApi,
23
+ } from './openapi'
24
+
25
+ export interface ApiReferenceProps {
26
+ /** A path to a JSON or YAML document, a URL, or the parsed document. Read at build time. */
27
+ spec: string | Record<string, unknown>
28
+ /** Overrides the document's first server URL in examples. */
29
+ baseUrl?: string
30
+ /** The CodeGroup sync key for the examples' language tabs. Default `code-language`. */
31
+ syncKey?: string
32
+ /** Show the table of contents. Default true. */
33
+ toc?: boolean
34
+ className?: string
35
+ }