@kubb/renderer-jsx 5.0.0-beta.4 → 5.0.0-beta.40
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 +134 -0
- package/dist/index.cjs +621 -193
- package/dist/index.d.ts +326 -90
- package/dist/index.js +615 -193
- package/dist/jsx-dev-runtime.cjs +1 -1
- package/dist/jsx-dev-runtime.d.ts +7 -8
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/{jsx-namespace-CNp0arTN.d.ts → jsx-namespace-dmStM1a2.d.ts} +3 -3
- package/dist/{jsx-runtime-DdmO3p0U.cjs → jsx-runtime-4M1bV6ub.cjs} +9 -9
- package/dist/{jsx-runtime-Cvu_ZYgL.js → jsx-runtime-CQ6-_gue.js} +10 -10
- package/dist/jsx-runtime.cjs +1 -1
- package/dist/jsx-runtime.d.ts +9 -10
- package/dist/jsx-runtime.js +2 -2
- package/dist/{types-nAFMiWFw.d.ts → types-B5VGpHs0.d.ts} +11 -10
- package/dist/types.d.ts +1 -1
- package/package.json +8 -12
- package/src/Renderer.ts +1 -5
- package/src/Runtime.tsx +7 -18
- package/src/SyncRuntime.tsx +309 -0
- package/src/components/Callout.tsx +59 -0
- package/src/components/CodeBlock.tsx +37 -0
- package/src/components/Const.tsx +4 -4
- package/src/components/File.tsx +7 -5
- package/src/components/Frontmatter.tsx +38 -0
- package/src/components/Function.tsx +8 -8
- package/src/components/Heading.tsx +34 -0
- package/src/components/Jsx.tsx +1 -1
- package/src/components/List.tsx +40 -0
- package/src/components/Paragraph.tsx +28 -0
- package/src/components/Type.tsx +3 -3
- package/src/constants.ts +19 -9
- package/src/createRenderer.tsx +81 -62
- package/src/dom.ts +7 -19
- package/src/index.ts +7 -1
- package/src/types.ts +9 -8
- package/src/utils.ts +153 -174
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jsx-dev-runtime.cjs.map +0 -1
- package/dist/jsx-dev-runtime.js.map +0 -1
- package/dist/jsx-runtime-Cvu_ZYgL.js.map +0 -1
- package/dist/jsx-runtime-DdmO3p0U.cjs.map +0 -1
- package/dist/jsx-runtime.cjs.map +0 -1
- package/dist/jsx-runtime.js.map +0 -1
- /package/dist/{chunk-Bb7HlUDG.js → chunk-DoukXa0m.js} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
4
|
+
</a>
|
|
5
|
+
|
|
6
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
7
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
8
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
9
|
+
[![License][license-src]][license-href]
|
|
10
|
+
[![Sponsors][sponsors-src]][sponsors-href]
|
|
11
|
+
|
|
12
|
+
<h4>
|
|
13
|
+
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
14
|
+
<span> · </span>
|
|
15
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
16
|
+
<span> · </span>
|
|
17
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
18
|
+
</h4>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/renderer-jsx
|
|
24
|
+
|
|
25
|
+
### JSX-based renderer for Kubb
|
|
26
|
+
|
|
27
|
+
Provides a custom React runtime, reconciler, and built-in components (`File`, `Function`, `Type`, `Const`) for component-based, type-safe code generation inside Kubb plugins.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @kubb/renderer-jsx
|
|
33
|
+
# or
|
|
34
|
+
pnpm add @kubb/renderer-jsx
|
|
35
|
+
# or
|
|
36
|
+
npm install @kubb/renderer-jsx
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Use the built-in components inside a Kubb plugin to emit generated files:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { createRenderer } from '@kubb/renderer-jsx'
|
|
45
|
+
import { File, Function, Type } from '@kubb/renderer-jsx'
|
|
46
|
+
|
|
47
|
+
const renderer = createRenderer()
|
|
48
|
+
|
|
49
|
+
await renderer.render(
|
|
50
|
+
<File baseName="petStore.ts" path="src/gen/petStore.ts">
|
|
51
|
+
<File.Source>
|
|
52
|
+
<Type name="Pet">{'{ id: number; name: string }'}</Type>
|
|
53
|
+
<Function name="getPet" async>
|
|
54
|
+
{"return fetch('/pets')"}
|
|
55
|
+
</Function>
|
|
56
|
+
</File.Source>
|
|
57
|
+
</File>,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const files = renderer.files
|
|
61
|
+
renderer.unmount()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Built-in Components
|
|
65
|
+
|
|
66
|
+
| Component | Description |
|
|
67
|
+
| --------------- | --------------------------------------------------------------------------- |
|
|
68
|
+
| `<File>` | Declares a generated output file with its path and optional imports/exports |
|
|
69
|
+
| `<File.Source>` | The source content block inside a `<File>` |
|
|
70
|
+
| `<Function>` | Generates a TypeScript function declaration |
|
|
71
|
+
| `<Type>` | Generates a TypeScript type alias |
|
|
72
|
+
| `<Const>` | Generates a `const` variable declaration |
|
|
73
|
+
| `<Jsx>` | Renders JSX expressions inside generated output |
|
|
74
|
+
| `<Root>` | Root container for the renderer tree |
|
|
75
|
+
|
|
76
|
+
## API
|
|
77
|
+
|
|
78
|
+
### `createRenderer(options?)`
|
|
79
|
+
|
|
80
|
+
Creates a new renderer instance.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const renderer = createRenderer({ debug: false })
|
|
84
|
+
await renderer.render(<MyComponent />)
|
|
85
|
+
const files = renderer.files // FileNode[]
|
|
86
|
+
renderer.unmount()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `jsxRenderer`
|
|
90
|
+
|
|
91
|
+
Pre-built renderer instance for use directly in Kubb plugins as the `jsxRenderer` plugin option.
|
|
92
|
+
|
|
93
|
+
## JSX Runtime
|
|
94
|
+
|
|
95
|
+
`@kubb/renderer-jsx` ships its own JSX runtime (`jsx-runtime` and `jsx-dev-runtime`). Configure your `tsconfig.json` to use it:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"compilerOptions": {
|
|
100
|
+
"jsx": "react-jsx",
|
|
101
|
+
"jsxImportSource": "@kubb/renderer-jsx"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Supporting Kubb
|
|
107
|
+
|
|
108
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
109
|
+
|
|
110
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
111
|
+
- [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
|
|
112
|
+
|
|
113
|
+
<p align="center">
|
|
114
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
115
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
116
|
+
</a>
|
|
117
|
+
</p>
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
|
|
122
|
+
|
|
123
|
+
<!-- Badges -->
|
|
124
|
+
|
|
125
|
+
[npm-version-src]: https://img.shields.io/npm/v/@kubb/renderer-jsx?flat&colorA=18181B&colorB=f58517
|
|
126
|
+
[npm-version-href]: https://npmjs.com/package/@kubb/renderer-jsx
|
|
127
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/renderer-jsx?flat&colorA=18181B&colorB=f58517
|
|
128
|
+
[npm-downloads-href]: https://npmjs.com/package/@kubb/renderer-jsx
|
|
129
|
+
[license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
|
|
130
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
131
|
+
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
132
|
+
[coverage-href]: https://www.npmjs.com/package/@kubb/renderer-jsx
|
|
133
|
+
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
134
|
+
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|