@openpkg-ts/react 0.2.5 → 0.3.1
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/README.md +152 -2
- package/dist/index.d.ts +23 -23
- package/dist/index.js +1 -1
- package/dist/shared/{chunk-j3c78zxw.js → chunk-2t4e6p1b.js} +34 -7
- package/dist/styled.d.ts +642 -111
- package/dist/styled.js +1735 -107
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -28,6 +28,14 @@ import {
|
|
|
28
28
|
ParamRow,
|
|
29
29
|
Signature,
|
|
30
30
|
TypeTable,
|
|
31
|
+
// Section components
|
|
32
|
+
FunctionSection,
|
|
33
|
+
ClassSection,
|
|
34
|
+
InterfaceSection,
|
|
35
|
+
EnumSection,
|
|
36
|
+
VariableSection,
|
|
37
|
+
ExportCard,
|
|
38
|
+
ExportIndexPage,
|
|
31
39
|
} from '@openpkg-ts/react';
|
|
32
40
|
```
|
|
33
41
|
|
|
@@ -43,6 +51,13 @@ import {
|
|
|
43
51
|
| `ParamRow` | Single parameter row |
|
|
44
52
|
| `Signature` | Type signature renderer |
|
|
45
53
|
| `TypeTable` | Type properties table |
|
|
54
|
+
| `FunctionSection` | Function export section |
|
|
55
|
+
| `ClassSection` | Class export section |
|
|
56
|
+
| `InterfaceSection` | Interface export section |
|
|
57
|
+
| `EnumSection` | Enum export section |
|
|
58
|
+
| `VariableSection` | Variable/constant section |
|
|
59
|
+
| `ExportCard` | Single export card |
|
|
60
|
+
| `ExportIndexPage` | Index page for all exports |
|
|
46
61
|
|
|
47
62
|
### Styled Components
|
|
48
63
|
|
|
@@ -50,7 +65,27 @@ Pre-styled with Tailwind v4.
|
|
|
50
65
|
|
|
51
66
|
```tsx
|
|
52
67
|
import {
|
|
53
|
-
//
|
|
68
|
+
// Stripe/Supabase-style layout (NEW)
|
|
69
|
+
StripeAPIReferencePage,
|
|
70
|
+
APIReferenceLayout,
|
|
71
|
+
SyncScrollProvider,
|
|
72
|
+
MethodSection,
|
|
73
|
+
MethodSectionFromSpec,
|
|
74
|
+
|
|
75
|
+
// Parameter components (Stripe-style)
|
|
76
|
+
APIParameterItem,
|
|
77
|
+
NestedParameterToggle,
|
|
78
|
+
NestedParameterContainer,
|
|
79
|
+
ExpandableParameter,
|
|
80
|
+
EnumValuesSection,
|
|
81
|
+
|
|
82
|
+
// Code example components
|
|
83
|
+
ExampleChips,
|
|
84
|
+
CodePanel,
|
|
85
|
+
CollapsiblePanel,
|
|
86
|
+
ExampleSection,
|
|
87
|
+
|
|
88
|
+
// Full pages (original)
|
|
54
89
|
APIPage,
|
|
55
90
|
FunctionPage,
|
|
56
91
|
ClassPage,
|
|
@@ -78,7 +113,54 @@ import {
|
|
|
78
113
|
|
|
79
114
|
## Usage
|
|
80
115
|
|
|
81
|
-
###
|
|
116
|
+
### Stripe/Supabase-Style API Reference (NEW)
|
|
117
|
+
|
|
118
|
+
Two-column layout with synchronized scrolling:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import { StripeAPIReferencePage } from '@openpkg-ts/react/styled';
|
|
122
|
+
import spec from './openpkg.json';
|
|
123
|
+
|
|
124
|
+
export default function APIReference() {
|
|
125
|
+
return <StripeAPIReferencePage spec={spec} />;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Features:
|
|
130
|
+
- Two-column layout (docs left, code examples right)
|
|
131
|
+
- Sticky right panel with synchronized scrolling
|
|
132
|
+
- Stripe-style nested parameters with expandable containers
|
|
133
|
+
- Rose Pine syntax highlighting
|
|
134
|
+
- Collapsible accordion panels
|
|
135
|
+
|
|
136
|
+
### Custom Stripe-Style Layout
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import {
|
|
140
|
+
APIReferenceLayout,
|
|
141
|
+
SyncScrollProvider,
|
|
142
|
+
MethodSectionFromSpec,
|
|
143
|
+
ExampleSection,
|
|
144
|
+
} from '@openpkg-ts/react/styled';
|
|
145
|
+
|
|
146
|
+
export default function CustomAPIPage({ spec }) {
|
|
147
|
+
return (
|
|
148
|
+
<SyncScrollProvider>
|
|
149
|
+
<APIReferenceLayout
|
|
150
|
+
examples={<ExamplesColumn spec={spec} />}
|
|
151
|
+
leftWidth="55%"
|
|
152
|
+
rightWidth="45%"
|
|
153
|
+
>
|
|
154
|
+
{spec.exports.map(exp => (
|
|
155
|
+
<MethodSectionFromSpec key={exp.name} spec={spec} export={exp} />
|
|
156
|
+
))}
|
|
157
|
+
</APIReferenceLayout>
|
|
158
|
+
</SyncScrollProvider>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Full API Page (Original)
|
|
82
164
|
|
|
83
165
|
```tsx
|
|
84
166
|
import { FullAPIReferencePage } from '@openpkg-ts/react/styled';
|
|
@@ -128,12 +210,36 @@ Convert spec data to component props:
|
|
|
128
210
|
|
|
129
211
|
```tsx
|
|
130
212
|
import {
|
|
213
|
+
// Original adapters
|
|
131
214
|
specParamToAPIParam,
|
|
132
215
|
specSchemaToAPISchema,
|
|
133
216
|
specExamplesToCodeExamples,
|
|
134
217
|
buildImportStatement,
|
|
135
218
|
getLanguagesFromExamples,
|
|
219
|
+
|
|
220
|
+
// New Stripe-style adapters
|
|
221
|
+
specParamToNestedParam,
|
|
222
|
+
specParamsToNestedParams,
|
|
223
|
+
resolveSchemaRef,
|
|
224
|
+
specExampleToCodeExample,
|
|
225
|
+
generateDefaultExample,
|
|
226
|
+
} from '@openpkg-ts/react/styled';
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Hooks
|
|
230
|
+
|
|
231
|
+
Extract method data from spec:
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
import {
|
|
235
|
+
useMethodFromSpec,
|
|
236
|
+
useMethodsFromSpec,
|
|
237
|
+
extractMethodData,
|
|
136
238
|
} from '@openpkg-ts/react/styled';
|
|
239
|
+
|
|
240
|
+
// In component
|
|
241
|
+
const method = useMethodFromSpec(spec, 'createClient');
|
|
242
|
+
// Returns: { title, signature, description, parameters, examples, returnType, isAsync }
|
|
137
243
|
```
|
|
138
244
|
|
|
139
245
|
## Headless Utilities
|
|
@@ -148,6 +254,50 @@ import {
|
|
|
148
254
|
} from '@openpkg-ts/react';
|
|
149
255
|
```
|
|
150
256
|
|
|
257
|
+
## Component Registry
|
|
258
|
+
|
|
259
|
+
Install components via CLI (shadcn-compatible):
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# List available components
|
|
263
|
+
openpkg docs list
|
|
264
|
+
|
|
265
|
+
# Add Stripe-style components
|
|
266
|
+
openpkg docs add stripe-api-reference-page
|
|
267
|
+
openpkg docs add method-section-from-spec
|
|
268
|
+
openpkg docs add api-reference-layout sync-scroll-provider
|
|
269
|
+
openpkg docs add api-parameter-item expandable-property
|
|
270
|
+
openpkg docs add example-chips code-panel collapsible-panel
|
|
271
|
+
|
|
272
|
+
# Add original section components
|
|
273
|
+
openpkg docs add function-section class-section interface-section
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
29 components available:
|
|
277
|
+
- **Stripe-style Layouts**: `api-reference-layout`, `sync-scroll-provider`, `method-section`, `stripe-api-reference-page`, `method-section-from-spec`
|
|
278
|
+
- **Parameter Components**: `api-parameter-item`, `nested-parameter-toggle`, `nested-parameter-container`, `expandable-property`, `enum-values-section`
|
|
279
|
+
- **Code Examples**: `example-chips`, `code-panel`, `collapsible-panel`, `example-section`
|
|
280
|
+
- **Original Sections**: `function-section`, `class-section`, `interface-section`, `enum-section`, `variable-section`
|
|
281
|
+
- **Primitives**: `export-card`, `param-table`, `signature`, `members-table`, `type-table`
|
|
282
|
+
|
|
283
|
+
## React Layout Generation
|
|
284
|
+
|
|
285
|
+
Generate a single layout file that uses registry components:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
openpkg docs generate spec.json -f react -o ./app/api
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Creates:
|
|
292
|
+
- `layout.tsx` - Main layout with navigation
|
|
293
|
+
- `spec.json` - Bundled spec data
|
|
294
|
+
|
|
295
|
+
Then add components:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
openpkg docs add function-section class-section
|
|
299
|
+
```
|
|
300
|
+
|
|
151
301
|
## License
|
|
152
302
|
|
|
153
303
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { SpecMember } from "@openpkg-ts/spec";
|
|
1
|
+
import { SpecMember as SpecMember2 } from "@openpkg-ts/spec";
|
|
2
2
|
interface CollapsibleMethodProps {
|
|
3
3
|
/** Method member to display */
|
|
4
|
-
member:
|
|
4
|
+
member: SpecMember2;
|
|
5
5
|
/** Default expanded state */
|
|
6
6
|
defaultExpanded?: boolean;
|
|
7
7
|
/** Custom className */
|
|
8
8
|
className?: string;
|
|
9
9
|
/** Custom header renderer */
|
|
10
|
-
renderHeader?: (member:
|
|
10
|
+
renderHeader?: (member: SpecMember2, expanded: boolean, toggle: () => void) => React.ReactNode;
|
|
11
11
|
/** Custom content renderer */
|
|
12
|
-
renderContent?: (member:
|
|
12
|
+
renderContent?: (member: SpecMember2) => React.ReactNode;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Headless collapsible method component.
|
|
@@ -100,30 +100,30 @@ declare function NestedProperty({ name, schema, required, depth }: NestedPropert
|
|
|
100
100
|
* ```
|
|
101
101
|
*/
|
|
102
102
|
declare function ExpandableProperty({ param, depth, className }: ExpandablePropertyProps): React.ReactNode;
|
|
103
|
-
import { SpecMember as
|
|
103
|
+
import { SpecMember as SpecMember5 } from "@openpkg-ts/spec";
|
|
104
104
|
interface MembersTableProps {
|
|
105
105
|
/** Members to display */
|
|
106
|
-
members:
|
|
106
|
+
members: SpecMember5[];
|
|
107
107
|
/** Custom className */
|
|
108
108
|
className?: string;
|
|
109
109
|
/** Group by kind (constructor, property, method) */
|
|
110
110
|
groupByKind?: boolean;
|
|
111
111
|
/** Custom member renderer */
|
|
112
|
-
renderMember?: (member:
|
|
112
|
+
renderMember?: (member: SpecMember5, index: number) => React.ReactNode;
|
|
113
113
|
}
|
|
114
114
|
interface MemberGroups {
|
|
115
|
-
constructors:
|
|
116
|
-
properties:
|
|
117
|
-
methods:
|
|
118
|
-
accessors:
|
|
119
|
-
other:
|
|
115
|
+
constructors: SpecMember5[];
|
|
116
|
+
properties: SpecMember5[];
|
|
117
|
+
methods: SpecMember5[];
|
|
118
|
+
accessors: SpecMember5[];
|
|
119
|
+
other: SpecMember5[];
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
122
|
* Group members by their kind.
|
|
123
123
|
*/
|
|
124
|
-
declare function groupMembersByKind(members:
|
|
124
|
+
declare function groupMembersByKind(members: SpecMember5[]): MemberGroups;
|
|
125
125
|
interface MemberRowProps {
|
|
126
|
-
member:
|
|
126
|
+
member: SpecMember5;
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
129
|
* Individual member row.
|
|
@@ -138,19 +138,19 @@ declare function MemberRow({ member }: MemberRowProps): React.ReactNode;
|
|
|
138
138
|
* ```
|
|
139
139
|
*/
|
|
140
140
|
declare function MembersTable({ members, className, groupByKind, renderMember }: MembersTableProps): React.ReactNode;
|
|
141
|
-
import { SpecMember as
|
|
141
|
+
import { SpecMember as SpecMember6, SpecSignatureParameter as SpecSignatureParameter3 } from "@openpkg-ts/spec";
|
|
142
142
|
interface ParamTableProps {
|
|
143
143
|
/** Parameters or members to display */
|
|
144
|
-
items: (
|
|
144
|
+
items: (SpecSignatureParameter3 | SpecMember6)[];
|
|
145
145
|
/** Show required indicator */
|
|
146
146
|
showRequired?: boolean;
|
|
147
147
|
/** Custom className */
|
|
148
148
|
className?: string;
|
|
149
149
|
/** Render custom row */
|
|
150
|
-
renderRow?: (item:
|
|
150
|
+
renderRow?: (item: SpecSignatureParameter3 | SpecMember6, index: number) => React.ReactNode;
|
|
151
151
|
}
|
|
152
152
|
interface ParamRowProps {
|
|
153
|
-
item:
|
|
153
|
+
item: SpecSignatureParameter3 | SpecMember6;
|
|
154
154
|
showRequired?: boolean;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
@@ -172,10 +172,10 @@ declare function ParamRow({ item, showRequired }: ParamRowProps): React.ReactNod
|
|
|
172
172
|
* ```
|
|
173
173
|
*/
|
|
174
174
|
declare function ParamTable({ items, showRequired, className, renderRow }: ParamTableProps): React.ReactNode;
|
|
175
|
-
import { SpecExport } from "@openpkg-ts/spec";
|
|
175
|
+
import { SpecExport as SpecExport6 } from "@openpkg-ts/spec";
|
|
176
176
|
interface SignatureProps {
|
|
177
177
|
/** The to render signature for */
|
|
178
|
-
export:
|
|
178
|
+
export: SpecExport6;
|
|
179
179
|
/** Index of signature to render (for overloaded functions) */
|
|
180
180
|
signatureIndex?: number;
|
|
181
181
|
/** Custom className */
|
|
@@ -198,16 +198,16 @@ interface SignatureProps {
|
|
|
198
198
|
* ```
|
|
199
199
|
*/
|
|
200
200
|
declare function Signature({ export: exp, signatureIndex, className, children }: SignatureProps): React.ReactNode;
|
|
201
|
-
import { SpecMember as
|
|
201
|
+
import { SpecMember as SpecMember7, SpecSignatureParameter as SpecSignatureParameter4 } from "@openpkg-ts/spec";
|
|
202
202
|
interface TypeTableProps {
|
|
203
203
|
/** Members or parameters to display */
|
|
204
|
-
items: (
|
|
204
|
+
items: (SpecSignatureParameter4 | SpecMember7)[];
|
|
205
205
|
/** Show required indicator */
|
|
206
206
|
showRequired?: boolean;
|
|
207
207
|
/** Custom className */
|
|
208
208
|
className?: string;
|
|
209
209
|
/** Render custom row */
|
|
210
|
-
renderRow?: (item:
|
|
210
|
+
renderRow?: (item: SpecSignatureParameter4 | SpecMember7, index: number) => React.ReactNode;
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
213
|
* Headless type table for displaying interface/type members.
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
18
18
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
19
|
|
|
20
20
|
// src/components/headless/CollapsibleMethod.tsx
|
|
21
|
-
import { formatReturnType, formatSchema, getMemberBadges } from "@openpkg-ts/sdk";
|
|
21
|
+
import { formatReturnType, formatSchema, getMemberBadges } from "@openpkg-ts/sdk/browser";
|
|
22
22
|
import { useEffect, useState } from "react";
|
|
23
23
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
24
24
|
|
|
@@ -91,7 +91,7 @@ function CollapsibleMethod({
|
|
|
91
91
|
member.description && /* @__PURE__ */ jsx("p", {
|
|
92
92
|
children: member.description
|
|
93
93
|
}),
|
|
94
|
-
hasParams && /* @__PURE__ */ jsxs("div", {
|
|
94
|
+
hasParams && sig?.parameters && /* @__PURE__ */ jsxs("div", {
|
|
95
95
|
"data-params-section": true,
|
|
96
96
|
children: [
|
|
97
97
|
/* @__PURE__ */ jsx("h4", {
|
|
@@ -220,7 +220,7 @@ function ExampleBlock({
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
// src/components/headless/ExpandableProperty.tsx
|
|
223
|
-
import { formatSchema as formatSchema2 } from "@openpkg-ts/sdk";
|
|
223
|
+
import { formatSchema as formatSchema2 } from "@openpkg-ts/sdk/browser";
|
|
224
224
|
import { useState as useState3 } from "react";
|
|
225
225
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
226
226
|
|
|
@@ -365,7 +365,7 @@ function ExpandableProperty({
|
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
// src/components/headless/MembersTable.tsx
|
|
368
|
-
import { formatSchema as formatSchema3, getMemberBadges as getMemberBadges2 } from "@openpkg-ts/sdk";
|
|
368
|
+
import { formatSchema as formatSchema3, getMemberBadges as getMemberBadges2 } from "@openpkg-ts/sdk/browser";
|
|
369
369
|
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
370
370
|
|
|
371
371
|
function groupMembersByKind(members) {
|
|
@@ -502,7 +502,7 @@ function MembersTable({
|
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
// src/components/headless/ParamTable.tsx
|
|
505
|
-
import { formatSchema as formatSchema4 } from "@openpkg-ts/sdk";
|
|
505
|
+
import { formatSchema as formatSchema4 } from "@openpkg-ts/sdk/browser";
|
|
506
506
|
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
507
507
|
|
|
508
508
|
function isParameter(item) {
|
|
@@ -576,7 +576,7 @@ function ParamTable({
|
|
|
576
576
|
}
|
|
577
577
|
|
|
578
578
|
// src/components/headless/Signature.tsx
|
|
579
|
-
import { buildSignatureString } from "@openpkg-ts/sdk";
|
|
579
|
+
import { buildSignatureString } from "@openpkg-ts/sdk/browser";
|
|
580
580
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
581
581
|
|
|
582
582
|
function Signature({
|
|
@@ -596,7 +596,7 @@ function Signature({
|
|
|
596
596
|
}
|
|
597
597
|
|
|
598
598
|
// src/components/headless/TypeTable.tsx
|
|
599
|
-
import { formatSchema as formatSchema5 } from "@openpkg-ts/sdk";
|
|
599
|
+
import { formatSchema as formatSchema5 } from "@openpkg-ts/sdk/browser";
|
|
600
600
|
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
601
601
|
|
|
602
602
|
function isParameter2(item) {
|
|
@@ -667,4 +667,31 @@ function TypeTable({
|
|
|
667
667
|
]
|
|
668
668
|
});
|
|
669
669
|
}
|
|
670
|
+
|
|
671
|
+
// src/components/headless/ClassSection.tsx
|
|
672
|
+
import { formatSchema as formatSchema6 } from "@openpkg-ts/sdk/browser";
|
|
673
|
+
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
674
|
+
|
|
675
|
+
// src/components/headless/EnumSection.tsx
|
|
676
|
+
import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
677
|
+
|
|
678
|
+
// src/components/headless/ExportCard.tsx
|
|
679
|
+
import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
680
|
+
|
|
681
|
+
// src/components/headless/ExportIndexPage.tsx
|
|
682
|
+
import { useMemo, useState as useState4 } from "react";
|
|
683
|
+
import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
684
|
+
|
|
685
|
+
// src/components/headless/FunctionSection.tsx
|
|
686
|
+
import { formatSchema as formatSchema7 } from "@openpkg-ts/sdk/browser";
|
|
687
|
+
import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
688
|
+
|
|
689
|
+
// src/components/headless/InterfaceSection.tsx
|
|
690
|
+
import { formatSchema as formatSchema8 } from "@openpkg-ts/sdk/browser";
|
|
691
|
+
import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
692
|
+
|
|
693
|
+
// src/components/headless/VariableSection.tsx
|
|
694
|
+
import { formatSchema as formatSchema9 } from "@openpkg-ts/sdk/browser";
|
|
695
|
+
import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
696
|
+
|
|
670
697
|
export { __toESM, __commonJS, CollapsibleMethod, getExampleCode, getExampleTitle, getExampleLanguage, cleanCode, ExampleBlock, NestedProperty, ExpandableProperty, groupMembersByKind, MemberRow, MembersTable, ParamRow, ParamTable, Signature, TypeTable };
|