@kubb/renderer-jsx 5.0.0-beta.63 → 5.0.0-beta.64

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/dist/index.cjs CHANGED
@@ -1,8 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_jsx_runtime = require("./jsx-runtime-3ncySO6L.cjs");
2
+ const require_rolldown_runtime = require("./rolldown-runtime-Bx3C2hgW.cjs");
3
+ const require_jsx_runtime = require("./jsx-runtime.cjs");
3
4
  let yaml = require("yaml");
4
5
  let _kubb_ast_factory = require("@kubb/ast/factory");
5
- _kubb_ast_factory = require_jsx_runtime.__toESM(_kubb_ast_factory);
6
+ _kubb_ast_factory = require_rolldown_runtime.__toESM(_kubb_ast_factory, 1);
6
7
  //#region src/components/Callout.tsx
7
8
  const CALLOUT_LABEL = {
8
9
  tip: "TIP",
@@ -212,7 +213,7 @@ File.Source = FileSource;
212
213
  function Frontmatter({ data }) {
213
214
  return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", {
214
215
  name: "frontmatter",
215
- children: `---\n${(0, yaml.stringify)(data).trimEnd()}\n---`
216
+ children: Object.keys(data).length === 0 ? "" : `---\n${(0, yaml.stringify)(data).trimEnd()}\n---`
216
217
  });
217
218
  }
218
219
  Frontmatter.displayName = "Frontmatter";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { t as __name } from "./chunk-C0LytTxp.js";
2
- import { d as KubbReactNode, n as Key, t as JSDoc, u as KubbReactElement } from "./types-UI1cZVah.js";
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { d as KubbReactNode, n as Key, t as JSDoc, u as KubbReactElement } from "./types-CC4v2M00.js";
3
3
  import { ExportNode, FileNode, ImportNode, SourceNode } from "@kubb/ast";
4
4
 
5
5
  //#region src/components/Callout.d.ts
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./chunk-C0LytTxp.js";
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
2
  import { Fragment, jsx } from "./jsx-runtime.js";
3
3
  import { stringify } from "yaml";
4
4
  import * as factory from "@kubb/ast/factory";
@@ -211,7 +211,7 @@ File.Source = FileSource;
211
211
  function Frontmatter({ data }) {
212
212
  return /* @__PURE__ */ jsx("kubb-source", {
213
213
  name: "frontmatter",
214
- children: `---\n${stringify(data).trimEnd()}\n---`
214
+ children: Object.keys(data).length === 0 ? "" : `---\n${stringify(data).trimEnd()}\n---`
215
215
  });
216
216
  }
217
217
  Frontmatter.displayName = "Frontmatter";
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_jsx_runtime = require("./jsx-runtime-3ncySO6L.cjs");
2
+ const require_jsx_runtime = require("./jsx-runtime.cjs");
3
3
  exports.Fragment = require_jsx_runtime.Fragment;
4
4
  exports.jsxDEV = require_jsx_runtime.jsxDEV;
@@ -1,5 +1,5 @@
1
- import { t as __name } from "./chunk-C0LytTxp.js";
2
- import { d as KubbReactNode, u as KubbReactElement } from "./types-UI1cZVah.js";
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { d as KubbReactNode, u as KubbReactElement } from "./types-CC4v2M00.js";
3
3
  import { Fragment, JSX, jsxDEV } from "./jsx-runtime.js";
4
4
 
5
5
  //#region src/jsx-dev-runtime.d.ts
@@ -1,6 +1,33 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_jsx_runtime = require("./jsx-runtime-3ncySO6L.cjs");
3
- exports.Fragment = require_jsx_runtime.Fragment;
4
- exports.jsx = require_jsx_runtime.jsx;
5
- exports.jsxDEV = require_jsx_runtime.jsxDEV;
6
- exports.jsxs = require_jsx_runtime.jsxs;
2
+ require("./rolldown-runtime-Bx3C2hgW.cjs");
3
+ //#region src/jsx-runtime.ts
4
+ const KUBB_ELEMENT = Symbol.for("kubb.element");
5
+ /**
6
+ * Fragment marker. A `<>…</>` compiles to `jsx(Fragment, …)`, and the renderer
7
+ * unwraps it while walking the tree.
8
+ */
9
+ const Fragment = Symbol.for("kubb.fragment");
10
+ /**
11
+ * Create a Kubb JSX element. The automatic JSX runtime calls this for every tag,
12
+ * so the renderer never depends on React at runtime. The `type` is a host
13
+ * string, a function component, or `Fragment`, and children are folded into
14
+ * `props`.
15
+ */
16
+ function createElement(type, props, key) {
17
+ return {
18
+ $$typeof: KUBB_ELEMENT,
19
+ type,
20
+ key: key ?? null,
21
+ props: props ?? {}
22
+ };
23
+ }
24
+ const jsx = createElement;
25
+ const jsxs = createElement;
26
+ const jsxDEV = createElement;
27
+ //#endregion
28
+ exports.Fragment = Fragment;
29
+ exports.jsx = jsx;
30
+ exports.jsxDEV = jsxDEV;
31
+ exports.jsxs = jsxs;
32
+
33
+ //# sourceMappingURL=jsx-runtime.cjs.map
@@ -1,5 +1,5 @@
1
- import { t as __name } from "./chunk-C0LytTxp.js";
2
- import { a as KubbExportProps, c as KubbImportProps, d as KubbReactNode, f as KubbSourceProps, i as KubbConstProps, l as KubbJsxProps, m as LineBreakProps, n as Key, o as KubbFileProps, p as KubbTypeProps, r as KubbArrowFunctionProps, s as KubbFunctionProps, u as KubbReactElement } from "./types-UI1cZVah.js";
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { a as KubbExportProps, c as KubbImportProps, d as KubbReactNode, f as KubbSourceProps, i as KubbConstProps, l as KubbJsxProps, m as LineBreakProps, n as Key, o as KubbFileProps, p as KubbTypeProps, r as KubbArrowFunctionProps, s as KubbFunctionProps, u as KubbReactElement } from "./types-CC4v2M00.js";
3
3
 
4
4
  //#region src/jsx-namespace.d.ts
5
5
  /**
@@ -1,4 +1,4 @@
1
- import "./chunk-C0LytTxp.js";
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
2
  //#region src/jsx-runtime.ts
3
3
  const KUBB_ELEMENT = Symbol.for("kubb.element");
4
4
  /**
@@ -24,37 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  //#endregion
27
- //#region src/jsx-runtime.ts
28
- const KUBB_ELEMENT = Symbol.for("kubb.element");
29
- /**
30
- * Fragment marker. A `<>…</>` compiles to `jsx(Fragment, …)`, and the renderer
31
- * unwraps it while walking the tree.
32
- */
33
- const Fragment = Symbol.for("kubb.fragment");
34
- /**
35
- * Create a Kubb JSX element. The automatic JSX runtime calls this for every tag,
36
- * so the renderer never depends on React at runtime. The `type` is a host
37
- * string, a function component, or `Fragment`, and children are folded into
38
- * `props`.
39
- */
40
- function createElement(type, props, key) {
41
- return {
42
- $$typeof: KUBB_ELEMENT,
43
- type,
44
- key: key ?? null,
45
- props: props ?? {}
46
- };
47
- }
48
- const jsx = createElement;
49
- const jsxs = createElement;
50
- const jsxDEV = createElement;
51
- //#endregion
52
- Object.defineProperty(exports, "Fragment", {
53
- enumerable: true,
54
- get: function() {
55
- return Fragment;
56
- }
57
- });
58
27
  Object.defineProperty(exports, "__name", {
59
28
  enumerable: true,
60
29
  get: function() {
@@ -67,23 +36,3 @@ Object.defineProperty(exports, "__toESM", {
67
36
  return __toESM;
68
37
  }
69
38
  });
70
- Object.defineProperty(exports, "jsx", {
71
- enumerable: true,
72
- get: function() {
73
- return jsx;
74
- }
75
- });
76
- Object.defineProperty(exports, "jsxDEV", {
77
- enumerable: true,
78
- get: function() {
79
- return jsxDEV;
80
- }
81
- });
82
- Object.defineProperty(exports, "jsxs", {
83
- enumerable: true,
84
- get: function() {
85
- return jsxs;
86
- }
87
- });
88
-
89
- //# sourceMappingURL=jsx-runtime-3ncySO6L.cjs.map
@@ -1,4 +1,4 @@
1
- import { t as __name } from "./chunk-C0LytTxp.js";
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
2
  import { ArrowFunctionNode, ConstNode, ExportNode, FileNode, FunctionNode, ImportNode, SourceNode, TypeNode } from "@kubb/ast";
3
3
 
4
4
  //#region src/types.d.ts
@@ -112,4 +112,4 @@ type JSDoc = {
112
112
  };
113
113
  //#endregion
114
114
  export { KubbExportProps as a, KubbImportProps as c, KubbReactNode as d, KubbSourceProps as f, KubbConstProps as i, KubbJsxProps as l, LineBreakProps as m, Key as n, KubbFileProps as o, KubbTypeProps as p, KubbArrowFunctionProps as r, KubbFunctionProps as s, JSDoc as t, KubbReactElement as u };
115
- //# sourceMappingURL=types-UI1cZVah.d.ts.map
115
+ //# sourceMappingURL=types-CC4v2M00.d.ts.map
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as KubbExportProps, c as KubbImportProps, d as KubbReactNode, f as KubbSourceProps, i as KubbConstProps, l as KubbJsxProps, m as LineBreakProps, n as Key, o as KubbFileProps, p as KubbTypeProps, r as KubbArrowFunctionProps, s as KubbFunctionProps, t as JSDoc, u as KubbReactElement } from "./types-UI1cZVah.js";
1
+ import { a as KubbExportProps, c as KubbImportProps, d as KubbReactNode, f as KubbSourceProps, i as KubbConstProps, l as KubbJsxProps, m as LineBreakProps, n as Key, o as KubbFileProps, p as KubbTypeProps, r as KubbArrowFunctionProps, s as KubbFunctionProps, t as JSDoc, u as KubbReactElement } from "./types-CC4v2M00.js";
2
2
  export { JSDoc, Key, KubbArrowFunctionProps, KubbConstProps, KubbExportProps, KubbFileProps, KubbFunctionProps, KubbImportProps, KubbJsxProps, KubbReactElement, KubbReactNode, KubbSourceProps, KubbTypeProps, LineBreakProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.0.0-beta.63",
3
+ "version": "5.0.0-beta.64",
4
4
  "description": "Self-contained synchronous JSX renderer for Kubb. Turns JSX into FileNodes with built-in components (File, Function, Type, Const) for component-based, type-safe code generation. No React dependency.",
5
5
  "keywords": [
6
6
  "codegen",
@@ -17,7 +17,6 @@
17
17
  "directory": "packages/renderer-jsx"
18
18
  },
19
19
  "files": [
20
- "src",
21
20
  "dist",
22
21
  "*.d.ts",
23
22
  "*.d.cts",
@@ -75,7 +74,7 @@
75
74
  },
76
75
  "dependencies": {
77
76
  "yaml": "^2.9.0",
78
- "@kubb/ast": "5.0.0-beta.63"
77
+ "@kubb/ast": "5.0.0-beta.64"
79
78
  },
80
79
  "devDependencies": {
81
80
  "@internals/utils": "0.0.0"
@@ -1,297 +0,0 @@
1
- import type { ArrowFunctionNode, CodeNode, ExportNode, FileNode, ImportNode, JSDocNode, SourceNode } from '@kubb/ast'
2
- import * as factory from '@kubb/ast/factory'
3
- import { KUBB_ARROW_FUNCTION, KUBB_CONST, KUBB_EXPORT, KUBB_FILE, KUBB_FUNCTION, KUBB_IMPORT, KUBB_JSX, KUBB_SOURCE, KUBB_TYPE } from './constants.ts'
4
- import { Fragment } from './jsx-runtime.ts'
5
- import type { KubbReactElement } from './types.ts'
6
-
7
- type OnText = (text: string) => void
8
- type OnHost = (type: string, props: Record<string, unknown>) => void
9
-
10
- /**
11
- * Walks `element`, resolving arrays, Fragments, and function components, then
12
- * calls `onText` for primitive values and `onHost` for each host element.
13
- * Function components are called synchronously. Hooks and class components are
14
- * not supported.
15
- */
16
- function walkElement(element: unknown, onText: OnText, onHost: OnHost): void {
17
- if (element == null || typeof element === 'boolean') return
18
-
19
- if (typeof element === 'string' || typeof element === 'number' || typeof element === 'bigint') {
20
- onText(String(element))
21
- return
22
- }
23
-
24
- if (Array.isArray(element)) {
25
- for (const child of element) walkElement(child, onText, onHost)
26
- return
27
- }
28
-
29
- if (typeof element === 'object' && '$$typeof' in element) {
30
- const el = element as unknown as KubbReactElement
31
- const { type } = el
32
- const props = el.props as Record<string, unknown>
33
-
34
- if (type === Fragment) {
35
- walkElement(props['children'], onText, onHost)
36
- return
37
- }
38
- if (typeof type === 'function') {
39
- walkElement((type as (p: unknown) => unknown)(props), onText, onHost)
40
- return
41
- }
42
- if (typeof type === 'string') {
43
- onHost(type, props)
44
- }
45
- }
46
- }
47
-
48
- function toBool(val: unknown): boolean {
49
- return (val ?? false) as boolean
50
- }
51
-
52
- function collectCodeNodes(props: Record<string, unknown>): Array<CodeNode> {
53
- const nodes: Array<CodeNode> = []
54
- collectCode(props['children'], nodes)
55
- return nodes
56
- }
57
-
58
- function collectCode(element: unknown, nodes: Array<CodeNode>): void {
59
- walkElement(
60
- element,
61
- (text) => {
62
- if (text.trim()) nodes.push(factory.createText(text))
63
- },
64
- (type, props) => resolveCodeNode(type, props, nodes),
65
- )
66
- }
67
-
68
- function resolveCodeNode(type: string, props: Record<string, unknown>, nodes: Array<CodeNode>): void {
69
- if (type === 'br') {
70
- nodes.push(factory.createBreak())
71
- return
72
- }
73
-
74
- if (type === KUBB_JSX) {
75
- let value = ''
76
- walkElement(
77
- props['children'],
78
- (t) => {
79
- value += t
80
- },
81
- () => {},
82
- )
83
- if (value) nodes.push(factory.createJsx(value))
84
- return
85
- }
86
-
87
- if (type === KUBB_FUNCTION) {
88
- nodes.push(
89
- factory.createFunction({
90
- name: props['name'] as string,
91
- params: props['params'] as string | null | undefined,
92
- export: props['export'] as boolean | null | undefined,
93
- default: props['default'] as boolean | null | undefined,
94
- async: props['async'] as boolean | null | undefined,
95
- generics: props['generics'] as string | Array<string> | null | undefined,
96
- returnType: props['returnType'] as string | null | undefined,
97
- JSDoc: props['JSDoc'] as JSDocNode | null | undefined,
98
- nodes: collectCodeNodes(props),
99
- }),
100
- )
101
- return
102
- }
103
-
104
- if (type === KUBB_ARROW_FUNCTION) {
105
- nodes.push(
106
- factory.createArrowFunction({
107
- name: props['name'] as string,
108
- params: props['params'] as string | null | undefined,
109
- export: props['export'] as boolean | null | undefined,
110
- default: props['default'] as boolean | null | undefined,
111
- async: props['async'] as boolean | null | undefined,
112
- generics: props['generics'] as string | Array<string> | null | undefined,
113
- returnType: props['returnType'] as string | null | undefined,
114
- singleLine: props['singleLine'] as boolean | null | undefined,
115
- JSDoc: props['JSDoc'] as JSDocNode | null | undefined,
116
- nodes: collectCodeNodes(props),
117
- } as Omit<ArrowFunctionNode, 'kind'>),
118
- )
119
- return
120
- }
121
-
122
- if (type === KUBB_CONST) {
123
- nodes.push(
124
- factory.createConst({
125
- name: props['name'] as string,
126
- type: props['type'] as string | null | undefined,
127
- export: props['export'] as boolean | null | undefined,
128
- asConst: props['asConst'] as boolean | null | undefined,
129
- JSDoc: props['JSDoc'] as JSDocNode | null | undefined,
130
- nodes: collectCodeNodes(props),
131
- }),
132
- )
133
- return
134
- }
135
-
136
- if (type === KUBB_TYPE) {
137
- nodes.push(
138
- factory.createType({
139
- name: props['name'] as string,
140
- export: props['export'] as boolean | null | undefined,
141
- JSDoc: props['JSDoc'] as JSDocNode | null | undefined,
142
- nodes: collectCodeNodes(props),
143
- }),
144
- )
145
- return
146
- }
147
- }
148
-
149
- type FileChildren = { sources: Array<SourceNode>; exports: Array<ExportNode>; imports: Array<ImportNode> }
150
-
151
- function collectFileChildren(element: unknown): FileChildren {
152
- const sources: Array<SourceNode> = []
153
- const exports: Array<ExportNode> = []
154
- const imports: Array<ImportNode> = []
155
-
156
- walkElement(
157
- element,
158
- (text) => {
159
- if (text.trim()) {
160
- throw new Error(`[react] '${text}' should be part of <File.Source> component when using the <File/> component`)
161
- }
162
- },
163
- (type, props) => {
164
- if (type === KUBB_SOURCE) {
165
- sources.push(
166
- factory.createSource({
167
- name: props['name']?.toString(),
168
- isTypeOnly: toBool(props['isTypeOnly']),
169
- isExportable: toBool(props['isExportable']),
170
- isIndexable: toBool(props['isIndexable']),
171
- nodes: collectCodeNodes(props),
172
- }),
173
- )
174
- return
175
- }
176
-
177
- if (type === KUBB_EXPORT) {
178
- exports.push(
179
- factory.createExport({
180
- name: props['name'] as ExportNode['name'],
181
- path: props['path'] as string,
182
- isTypeOnly: toBool(props['isTypeOnly']),
183
- asAlias: toBool(props['asAlias']),
184
- }),
185
- )
186
- return
187
- }
188
-
189
- if (type === KUBB_IMPORT) {
190
- imports.push(
191
- factory.createImport({
192
- name: props['name'] as ImportNode['name'],
193
- path: props['path'] as string,
194
- root: props['root'] as string | null | undefined,
195
- isTypeOnly: toBool(props['isTypeOnly']),
196
- isNameSpace: toBool(props['isNameSpace']),
197
- }),
198
- )
199
- return
200
- }
201
-
202
- const nested = collectFileChildren(props['children'])
203
- sources.push(...nested.sources)
204
- exports.push(...nested.exports)
205
- imports.push(...nested.imports)
206
- },
207
- )
208
-
209
- return { sources, exports, imports }
210
- }
211
-
212
- function* walkFiles(element: unknown): Generator<FileNode> {
213
- if (element == null || typeof element === 'boolean') return
214
-
215
- if (typeof element === 'string' || typeof element === 'number' || typeof element === 'bigint') return
216
-
217
- if (Array.isArray(element)) {
218
- for (const child of element) yield* walkFiles(child)
219
- return
220
- }
221
-
222
- if (typeof element === 'object' && '$$typeof' in element) {
223
- const el = element as unknown as KubbReactElement
224
- const { type } = el
225
- const props = el.props as Record<string, unknown>
226
-
227
- if (type === Fragment) {
228
- yield* walkFiles(props['children'])
229
- return
230
- }
231
-
232
- if (typeof type === 'function') {
233
- yield* walkFiles((type as (p: unknown) => unknown)(props))
234
- return
235
- }
236
-
237
- if (typeof type === 'string') {
238
- if (type === KUBB_FILE && props['baseName'] !== undefined && props['path'] !== undefined) {
239
- const { sources, exports, imports } = collectFileChildren(props['children'])
240
- yield {
241
- baseName: props['baseName'],
242
- path: props['path'],
243
- meta: props['meta'] || {},
244
- footer: props['footer'],
245
- banner: props['banner'],
246
- sources,
247
- exports,
248
- imports,
249
- } as FileNode
250
- } else {
251
- yield* walkFiles(props['children'])
252
- }
253
- }
254
- }
255
- }
256
-
257
- /**
258
- * Synchronous JSX renderer that walks the element tree in a single pass,
259
- * producing {@link FileNode} objects directly without an intermediate virtual
260
- * DOM. No React fiber, scheduler, or work loop is involved.
261
- *
262
- * All components must be pure functions. Hooks and class components are not
263
- * supported.
264
- */
265
- export class SyncRuntime {
266
- /**
267
- * Accumulated {@link FileNode} results from every {@link render} call.
268
- */
269
- nodes: Array<FileNode> = []
270
-
271
- /**
272
- * Walks `element` synchronously, converts every `<kubb-file>` subtree into
273
- * a {@link FileNode} with no intermediate virtual DOM, and appends the results
274
- * to {@link nodes}.
275
- */
276
- render(element: KubbReactElement): void {
277
- for (const file of walkFiles(element)) {
278
- this.nodes.push(file)
279
- }
280
- }
281
-
282
- /**
283
- * Walks `element` synchronously and yields each {@link FileNode} as it is
284
- * produced, without buffering into an intermediate array first. Callers can
285
- * begin processing each file before the rest of the element tree is traversed.
286
- *
287
- * @example
288
- * ```ts
289
- * for (const file of runtime.stream(element)) {
290
- * await writeFile(file)
291
- * }
292
- * ```
293
- */
294
- *stream(element: KubbReactElement): Generator<FileNode> {
295
- yield* walkFiles(element)
296
- }
297
- }
@@ -1,58 +0,0 @@
1
- import type { Key, KubbReactElement } from '../types.ts'
2
-
3
- const CALLOUT_LABEL = {
4
- tip: 'TIP',
5
- note: 'NOTE',
6
- important: 'IMPORTANT',
7
- warning: 'WARNING',
8
- caution: 'CAUTION',
9
- } as const
10
-
11
- export type CalloutType = keyof typeof CALLOUT_LABEL
12
-
13
- type Props = {
14
- key?: Key
15
- /**
16
- * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
17
- */
18
- type: CalloutType
19
- /**
20
- * Optional title rendered on the same line as the marker.
21
- */
22
- title?: string | null
23
- /**
24
- * Body text. Each line is quoted with `> ` so multi-line content stays
25
- * inside the callout block.
26
- */
27
- children: string
28
- }
29
-
30
- /**
31
- * Renders a GitHub-style alert callout using the `> [!TYPE]` blockquote syntax.
32
- *
33
- * Emits a `<File.Source>` block containing `> [!TYPE] Title` followed by the
34
- * body with every line prefixed by `> `.
35
- *
36
- * @example
37
- * ```tsx
38
- * <Callout type="tip">Run `kubb start --watch` to keep the generator hot.</Callout>
39
- * // > [!TIP]
40
- * // > Run `kubb start --watch` to keep the generator hot.
41
- *
42
- * <Callout type="warning" title="Heads up">Breaking change in v6.</Callout>
43
- * // > [!WARNING] Heads up
44
- * // > Breaking change in v6.
45
- * ```
46
- */
47
- export function Callout({ type, title, children }: Props): KubbReactElement {
48
- const label = CALLOUT_LABEL[type]
49
- const header = title ? `> [!${label}] ${title}` : `> [!${label}]`
50
- const quoted = children
51
- .trimEnd()
52
- .split('\n')
53
- .map((line) => (line.length > 0 ? `> ${line}` : '>'))
54
- .join('\n')
55
- return <kubb-source name="callout">{`${header}\n${quoted}`}</kubb-source>
56
- }
57
-
58
- Callout.displayName = 'Callout'
@@ -1,70 +0,0 @@
1
- import type { JSDoc, Key, KubbReactElement, KubbReactNode } from '../types.ts'
2
-
3
- type ConstProps = {
4
- key?: Key
5
- /**
6
- * Identifier of the generated constant declaration.
7
- *
8
- * @example
9
- * `name: 'petSchema'`
10
- */
11
- name: string
12
- /**
13
- * Emit the `export` keyword before the `const` declaration.
14
- * - `true` generates `export const name = …`
15
- * - `false` generates `const name = …`
16
- */
17
- export?: boolean | null
18
- /**
19
- * TypeScript type annotation for the constant, written verbatim after `const name:`.
20
- *
21
- * @example
22
- * `type: 'Pet'` → `const pet: Pet = …`
23
- */
24
- type?: string | null
25
- /**
26
- * JSDoc block to prepend to the constant declaration.
27
- * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
28
- */
29
- JSDoc?: JSDoc | null
30
- /**
31
- * Append `as const` after the initializer, enabling TypeScript const assertions.
32
- * - `true` generates `const name = … as const`
33
- * - `false` generates `const name = …`
34
- */
35
- asConst?: boolean | null
36
- /**
37
- * Child nodes rendered as the initializer expression of the constant.
38
- */
39
- children?: KubbReactNode
40
- }
41
-
42
- /**
43
- * Generates a TypeScript constant declaration.
44
- *
45
- * @example Named export with type annotation
46
- * ```tsx
47
- * <Const export name="petSchema" type="z.ZodType<Pet>">
48
- * {`z.object({ id: z.number() })`}
49
- * </Const>
50
- * // export const petSchema: z.ZodType<Pet> = z.object({ id: z.number() })
51
- * ```
52
- *
53
- * @example With JSDoc and const assertion
54
- * ```tsx
55
- * <Const name="HTTP_METHODS" asConst JSDoc={{ comments: ['@description Supported HTTP methods.'] }}>
56
- * {`['GET', 'POST', 'PUT', 'DELETE']`}
57
- * </Const>
58
- * ```
59
- */
60
- export function Const({ children, ...props }: ConstProps): KubbReactElement {
61
- const { name, export: canExport, type, JSDoc, asConst } = props
62
-
63
- return (
64
- <kubb-const name={name} type={type} export={canExport} asConst={asConst} JSDoc={JSDoc}>
65
- {children}
66
- </kubb-const>
67
- )
68
- }
69
-
70
- Const.displayName = 'Const'