@kubb/renderer-jsx 5.25.0 → 5.25.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/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./rolldown-runtime-BRMrT0dX.cjs");
3
3
  const require_jsx_runtime = require("./jsx-runtime.cjs");
4
- let yaml = require("yaml");
5
4
  let _kubb_ast = require("@kubb/ast");
5
+ let yaml = require("yaml");
6
6
  // src/components/md/Callout.tsx
7
7
  const CALLOUT_LABEL = {
8
8
  tip: "TIP",
@@ -101,12 +101,16 @@ function File({ children, ...props }) {
101
101
  *
102
102
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
103
103
  */
104
- function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }) {
104
+ function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isExportable, space, isTypeOnly, inline }) {
105
105
  return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-origin", {
106
106
  pointer,
107
107
  children: /* @__PURE__ */ require_jsx_runtime.jsx("kubb-code", {
108
108
  name,
109
- export: isExport ?? isIndexable,
109
+ export: _kubb_ast.ast.file.isExported({
110
+ export: isExport,
111
+ isIndexable,
112
+ isExportable
113
+ }),
110
114
  default: isDefault,
111
115
  space,
112
116
  isTypeOnly,
@@ -455,7 +459,7 @@ function collectFileChildren(element) {
455
459
  sources.push(_kubb_ast.ast.factory.createSource({
456
460
  name: name?.toString(),
457
461
  ...space ? { space } : {},
458
- isTypeOnly: !!isTypeOnly,
462
+ ...isTypeOnly != null ? { isTypeOnly } : {},
459
463
  export: !!isExport,
460
464
  ...isDefault ? { default: true } : {},
461
465
  ...inline ? { inline } : {},
@@ -507,7 +511,7 @@ function collectFileChildren(element) {
507
511
  const node = createCodeNode(host.type, host.props);
508
512
  sources.push(_kubb_ast.ast.factory.createSource({
509
513
  name,
510
- isTypeOnly: host.type === "kubb-type",
514
+ ...host.type === "kubb-type" ? { isTypeOnly: true } : {},
511
515
  export: !!canExport,
512
516
  ...isDefault ? { default: true } : {},
513
517
  ...inline && "nodes" in node ? { inline: { expression: _kubb_ast.ast.node.getText(node.nodes) } } : {},
@@ -543,27 +547,25 @@ function createFileNode(props) {
543
547
  }
544
548
  /**
545
549
  * Factory for a renderer that walks the JSX tree in a single recursive pass,
546
- * with no React reconciler or scheduler. Pass it as the `renderer` property on
547
- * `defineGenerator`. Kubb core calls the factory once per render cycle and stays
548
- * generic, with no hard dependency on `@kubb/renderer-jsx`. Every component must be a pure
549
- * function. Hooks, suspense and class components are not supported.
550
+ * with no React reconciler or scheduler. Kit renders a template's JSX with it by default;
551
+ * pass it as `renderer` to `addTemplate` to set it explicitly. Kubb core calls the factory
552
+ * once per render cycle and stays generic, with no hard dependency on `@kubb/renderer-jsx`.
553
+ * Every component must be a pure function. Hooks, suspense and class components are not supported.
550
554
  *
551
- * @example Wire up a JSX generator
555
+ * @example Wire up a JSX template
552
556
  * ```tsx
553
- * import { defineGenerator } from '@kubb/kit'
554
- * import { jsxRenderer } from '@kubb/renderer-jsx'
555
- *
556
- * export const myGenerator = defineGenerator<PluginTs>({
557
- * name: 'types',
558
- * renderer: jsxRenderer,
559
- * schema(node, ctx) {
560
- * return (
561
- * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
562
- * <Type node={node} resolver={ctx.resolver} />
563
- * </File>
564
- * )
557
+ * import { addTemplate, defineTemplate } from '@kubb/kit'
558
+ * import { File, jsxRenderer } from '@kubb/renderer-jsx'
559
+ *
560
+ * export const typesTemplate = defineTemplate<PluginTs>({
561
+ * kind: 'Schema',
562
+ * render(node, ctx) {
563
+ * return <File {...ctx.file(node)}>…</File>
565
564
  * },
566
565
  * })
566
+ *
567
+ * // In the plugin's `setup`:
568
+ * addTemplate(typesTemplate, { renderer: jsxRenderer })
567
569
  * ```
568
570
  */
569
571
  const jsxRenderer = () => {
package/dist/index.d.cts CHANGED
@@ -8,7 +8,7 @@ declare const CALLOUT_LABEL: {
8
8
  readonly caution: 'CAUTION';
9
9
  };
10
10
  type CalloutType = keyof typeof CALLOUT_LABEL;
11
- type Props$11 = {
11
+ type CalloutProps = {
12
12
  key?: Key;
13
13
  /**
14
14
  * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
@@ -41,8 +41,8 @@ type Props$11 = {
41
41
  * // > Breaking change in v6.
42
42
  * ```
43
43
  */
44
- export declare function Callout({ type, title, children }: Props$11): KubbReactElement;
45
- type Props$10 = {
44
+ export declare function Callout({ type, title, children }: CalloutProps): KubbReactElement;
45
+ type CodeProps = {
46
46
  key?: Key;
47
47
  name: string;
48
48
  /**
@@ -63,7 +63,7 @@ type Props$10 = {
63
63
  /**
64
64
  * A printed declaration in a `File`, in any language. For a declaration written in JSX, or a TypeScript type, use `Const`, `Type` or `Function`.
65
65
  */
66
- export declare function Code({ children, name, export: canExport, default: isDefault, space }: Props$10): KubbReactElement;
66
+ export declare function Code({ children, name, export: canExport, default: isDefault, space }: CodeProps): KubbReactElement;
67
67
  type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
68
68
  key?: Key;
69
69
  /**
@@ -107,7 +107,7 @@ type BasePropsWithoutBaseName = {
107
107
  path?: string | null;
108
108
  };
109
109
  type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
110
- type Props$9<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy' | 'inline'> & {
110
+ type FileProps<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy' | 'inline'> & {
111
111
  key?: Key;
112
112
  /**
113
113
  * Arbitrary metadata attached to the file node for plugins to read.
@@ -134,7 +134,7 @@ type Props$9<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, '
134
134
  * </File>
135
135
  * ```
136
136
  */
137
- export declare function File<TMeta extends object = object>({ children, ...props }: Props$9<TMeta>): KubbReactElement;
137
+ export declare function File<TMeta extends object = object>({ children, ...props }: FileProps<TMeta>): KubbReactElement;
138
138
  export declare namespace File {
139
139
  export { FileExport as Export };
140
140
  export { FileImport as Import };
@@ -152,7 +152,7 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value' | 'nodes'> & {
152
152
  *
153
153
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
154
154
  */
155
- declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
155
+ declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isExportable, space, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
156
156
  type FileExportProps = ast.ExportInput & {
157
157
  key?: Key;
158
158
  };
@@ -197,7 +197,7 @@ type FileImportProps = ast.ImportInput & {
197
197
  * ```
198
198
  */
199
199
  declare function FileImport(props: FileImportProps): KubbReactElement;
200
- type Props$8 = {
200
+ type FrontmatterProps = {
201
201
  key?: Key;
202
202
  /**
203
203
  * Plain object serialized as YAML between `---` fences.
@@ -224,8 +224,8 @@ type Props$8 = {
224
224
  * </File>
225
225
  * ```
226
226
  */
227
- export declare function Frontmatter({ data }: Props$8): KubbReactElement;
228
- type Props$7 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
227
+ export declare function Frontmatter({ data }: FrontmatterProps): KubbReactElement;
228
+ type FunctionProps = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
229
229
  key?: Key;
230
230
  /**
231
231
  * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
@@ -252,7 +252,7 @@ type Props$7 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
252
252
  * // }
253
253
  * ```
254
254
  */
255
- export declare function Function({ children, ...props }: Props$7): KubbReactElement;
255
+ export declare function Function({ children, ...props }: FunctionProps): KubbReactElement;
256
256
  export declare namespace Function {
257
257
  export { ArrowFunction as Arrow };
258
258
  }
@@ -285,7 +285,7 @@ type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
285
285
  */
286
286
  declare function ArrowFunction({ children, ...props }: ArrowFunctionProps): KubbReactElement;
287
287
  type Level = 1 | 2 | 3 | 4 | 5 | 6;
288
- type Props$6 = {
288
+ type HeadingProps = {
289
289
  key?: Key;
290
290
  /**
291
291
  * Heading depth, `1` through `6`. Matches the number of `#` characters
@@ -309,8 +309,8 @@ type Props$6 = {
309
309
  * // ## Installation
310
310
  * ```
311
311
  */
312
- export declare function Heading({ level, children }: Props$6): KubbReactElement;
313
- type Props$5 = {
312
+ export declare function Heading({ level, children }: HeadingProps): KubbReactElement;
313
+ type JsxProps = {
314
314
  key?: Key;
315
315
  /**
316
316
  * Raw JSX string embedded verbatim in the generated code, including
@@ -338,8 +338,8 @@ type Props$5 = {
338
338
  * </Function>
339
339
  * ```
340
340
  */
341
- export declare function Jsx({ children }: Props$5): KubbReactElement;
342
- type Props$4 = {
341
+ export declare function Jsx({ children }: JsxProps): KubbReactElement;
342
+ type ListProps = {
343
343
  key?: Key;
344
344
  /**
345
345
  * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
@@ -370,8 +370,8 @@ type Props$4 = {
370
370
  * // 2. Second
371
371
  * ```
372
372
  */
373
- export declare function List({ ordered, items }: Props$4): KubbReactElement;
374
- type Props$3 = {
373
+ export declare function List({ ordered, items }: ListProps): KubbReactElement;
374
+ type OriginProps = {
375
375
  /**
376
376
  * The input location, in the form the adapter reads, such as `#/components/schemas/Pet`.
377
377
  */
@@ -381,8 +381,8 @@ type Props$3 = {
381
381
  /**
382
382
  * Sets the input location of every source inside it. An inner `Origin` wins.
383
383
  */
384
- export declare function Origin({ pointer, children }: Props$3): KubbReactElement;
385
- type Props$2 = {
384
+ export declare function Origin({ pointer, children }: OriginProps): KubbReactElement;
385
+ type ParagraphProps = {
386
386
  key?: Key;
387
387
  /**
388
388
  * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
@@ -402,8 +402,8 @@ type Props$2 = {
402
402
  * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
403
403
  * ```
404
404
  */
405
- export declare function Paragraph({ children }: Props$2): KubbReactElement;
406
- type Props$1 = {
405
+ export declare function Paragraph({ children }: ParagraphProps): KubbReactElement;
406
+ type RawProps = {
407
407
  key?: Key;
408
408
  /**
409
409
  * Dedupes the block when several generators add it to one file.
@@ -414,8 +414,8 @@ type Props$1 = {
414
414
  /**
415
415
  * Text in a `File` that declares nothing, such as a statement, JSON or markdown. Barrels leave it out.
416
416
  */
417
- export declare function Raw({ children, name }: Props$1): KubbReactElement;
418
- type Props<TOutput> = {
417
+ export declare function Raw({ children, name }: RawProps): KubbReactElement;
418
+ type SchemaProps<TOutput> = {
419
419
  node: ast.SchemaNode;
420
420
  printer: Pick<ast.Printer, 'drainImports'> & {
421
421
  print: (node: ast.SchemaNode) => TOutput | null;
@@ -430,7 +430,7 @@ type Props<TOutput> = {
430
430
  * <Schema node={node} printer={printer}>{(code) => <Const export name="petSchema">{code}</Const>}</Schema>
431
431
  * ```
432
432
  */
433
- export declare function Schema<TOutput>({ node, printer, children }: Props<TOutput>): KubbReactElement | null;
433
+ export declare function Schema<TOutput>({ node, printer, children }: SchemaProps<TOutput>): KubbReactElement | null;
434
434
  type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
435
435
  key?: Key;
436
436
  /**
@@ -466,27 +466,25 @@ type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
466
466
  export declare function Type({ children, ...props }: TypeProps): KubbReactElement;
467
467
  /**
468
468
  * Factory for a renderer that walks the JSX tree in a single recursive pass,
469
- * with no React reconciler or scheduler. Pass it as the `renderer` property on
470
- * `defineGenerator`. Kubb core calls the factory once per render cycle and stays
471
- * generic, with no hard dependency on `@kubb/renderer-jsx`. Every component must be a pure
472
- * function. Hooks, suspense and class components are not supported.
469
+ * with no React reconciler or scheduler. Kit renders a template's JSX with it by default;
470
+ * pass it as `renderer` to `addTemplate` to set it explicitly. Kubb core calls the factory
471
+ * once per render cycle and stays generic, with no hard dependency on `@kubb/renderer-jsx`.
472
+ * Every component must be a pure function. Hooks, suspense and class components are not supported.
473
473
  *
474
- * @example Wire up a JSX generator
474
+ * @example Wire up a JSX template
475
475
  * ```tsx
476
- * import { defineGenerator } from '@kubb/kit'
477
- * import { jsxRenderer } from '@kubb/renderer-jsx'
478
- *
479
- * export const myGenerator = defineGenerator<PluginTs>({
480
- * name: 'types',
481
- * renderer: jsxRenderer,
482
- * schema(node, ctx) {
483
- * return (
484
- * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
485
- * <Type node={node} resolver={ctx.resolver} />
486
- * </File>
487
- * )
476
+ * import { addTemplate, defineTemplate } from '@kubb/kit'
477
+ * import { File, jsxRenderer } from '@kubb/renderer-jsx'
478
+ *
479
+ * export const typesTemplate = defineTemplate<PluginTs>({
480
+ * kind: 'Schema',
481
+ * render(node, ctx) {
482
+ * return <File {...ctx.file(node)}>…</File>
488
483
  * },
489
484
  * })
485
+ *
486
+ * // In the plugin's `setup`:
487
+ * addTemplate(typesTemplate, { renderer: jsxRenderer })
490
488
  * ```
491
489
  */
492
490
  export declare const jsxRenderer: () => {
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ declare const CALLOUT_LABEL: {
8
8
  readonly caution: 'CAUTION';
9
9
  };
10
10
  type CalloutType = keyof typeof CALLOUT_LABEL;
11
- type Props$11 = {
11
+ type CalloutProps = {
12
12
  key?: Key;
13
13
  /**
14
14
  * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
@@ -41,8 +41,8 @@ type Props$11 = {
41
41
  * // > Breaking change in v6.
42
42
  * ```
43
43
  */
44
- export declare function Callout({ type, title, children }: Props$11): KubbReactElement;
45
- type Props$10 = {
44
+ export declare function Callout({ type, title, children }: CalloutProps): KubbReactElement;
45
+ type CodeProps = {
46
46
  key?: Key;
47
47
  name: string;
48
48
  /**
@@ -63,7 +63,7 @@ type Props$10 = {
63
63
  /**
64
64
  * A printed declaration in a `File`, in any language. For a declaration written in JSX, or a TypeScript type, use `Const`, `Type` or `Function`.
65
65
  */
66
- export declare function Code({ children, name, export: canExport, default: isDefault, space }: Props$10): KubbReactElement;
66
+ export declare function Code({ children, name, export: canExport, default: isDefault, space }: CodeProps): KubbReactElement;
67
67
  type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
68
68
  key?: Key;
69
69
  /**
@@ -107,7 +107,7 @@ type BasePropsWithoutBaseName = {
107
107
  path?: string | null;
108
108
  };
109
109
  type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
110
- type Props$9<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy' | 'inline'> & {
110
+ type FileProps<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy' | 'inline'> & {
111
111
  key?: Key;
112
112
  /**
113
113
  * Arbitrary metadata attached to the file node for plugins to read.
@@ -134,7 +134,7 @@ type Props$9<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, '
134
134
  * </File>
135
135
  * ```
136
136
  */
137
- export declare function File<TMeta extends object = object>({ children, ...props }: Props$9<TMeta>): KubbReactElement;
137
+ export declare function File<TMeta extends object = object>({ children, ...props }: FileProps<TMeta>): KubbReactElement;
138
138
  export declare namespace File {
139
139
  export { FileExport as Export };
140
140
  export { FileImport as Import };
@@ -152,7 +152,7 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value' | 'nodes'> & {
152
152
  *
153
153
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
154
154
  */
155
- declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
155
+ declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isExportable, space, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
156
156
  type FileExportProps = ast.ExportInput & {
157
157
  key?: Key;
158
158
  };
@@ -197,7 +197,7 @@ type FileImportProps = ast.ImportInput & {
197
197
  * ```
198
198
  */
199
199
  declare function FileImport(props: FileImportProps): KubbReactElement;
200
- type Props$8 = {
200
+ type FrontmatterProps = {
201
201
  key?: Key;
202
202
  /**
203
203
  * Plain object serialized as YAML between `---` fences.
@@ -224,8 +224,8 @@ type Props$8 = {
224
224
  * </File>
225
225
  * ```
226
226
  */
227
- export declare function Frontmatter({ data }: Props$8): KubbReactElement;
228
- type Props$7 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
227
+ export declare function Frontmatter({ data }: FrontmatterProps): KubbReactElement;
228
+ type FunctionProps = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
229
229
  key?: Key;
230
230
  /**
231
231
  * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
@@ -252,7 +252,7 @@ type Props$7 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
252
252
  * // }
253
253
  * ```
254
254
  */
255
- export declare function Function({ children, ...props }: Props$7): KubbReactElement;
255
+ export declare function Function({ children, ...props }: FunctionProps): KubbReactElement;
256
256
  export declare namespace Function {
257
257
  export { ArrowFunction as Arrow };
258
258
  }
@@ -285,7 +285,7 @@ type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
285
285
  */
286
286
  declare function ArrowFunction({ children, ...props }: ArrowFunctionProps): KubbReactElement;
287
287
  type Level = 1 | 2 | 3 | 4 | 5 | 6;
288
- type Props$6 = {
288
+ type HeadingProps = {
289
289
  key?: Key;
290
290
  /**
291
291
  * Heading depth, `1` through `6`. Matches the number of `#` characters
@@ -309,8 +309,8 @@ type Props$6 = {
309
309
  * // ## Installation
310
310
  * ```
311
311
  */
312
- export declare function Heading({ level, children }: Props$6): KubbReactElement;
313
- type Props$5 = {
312
+ export declare function Heading({ level, children }: HeadingProps): KubbReactElement;
313
+ type JsxProps = {
314
314
  key?: Key;
315
315
  /**
316
316
  * Raw JSX string embedded verbatim in the generated code, including
@@ -338,8 +338,8 @@ type Props$5 = {
338
338
  * </Function>
339
339
  * ```
340
340
  */
341
- export declare function Jsx({ children }: Props$5): KubbReactElement;
342
- type Props$4 = {
341
+ export declare function Jsx({ children }: JsxProps): KubbReactElement;
342
+ type ListProps = {
343
343
  key?: Key;
344
344
  /**
345
345
  * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
@@ -370,8 +370,8 @@ type Props$4 = {
370
370
  * // 2. Second
371
371
  * ```
372
372
  */
373
- export declare function List({ ordered, items }: Props$4): KubbReactElement;
374
- type Props$3 = {
373
+ export declare function List({ ordered, items }: ListProps): KubbReactElement;
374
+ type OriginProps = {
375
375
  /**
376
376
  * The input location, in the form the adapter reads, such as `#/components/schemas/Pet`.
377
377
  */
@@ -381,8 +381,8 @@ type Props$3 = {
381
381
  /**
382
382
  * Sets the input location of every source inside it. An inner `Origin` wins.
383
383
  */
384
- export declare function Origin({ pointer, children }: Props$3): KubbReactElement;
385
- type Props$2 = {
384
+ export declare function Origin({ pointer, children }: OriginProps): KubbReactElement;
385
+ type ParagraphProps = {
386
386
  key?: Key;
387
387
  /**
388
388
  * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
@@ -402,8 +402,8 @@ type Props$2 = {
402
402
  * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
403
403
  * ```
404
404
  */
405
- export declare function Paragraph({ children }: Props$2): KubbReactElement;
406
- type Props$1 = {
405
+ export declare function Paragraph({ children }: ParagraphProps): KubbReactElement;
406
+ type RawProps = {
407
407
  key?: Key;
408
408
  /**
409
409
  * Dedupes the block when several generators add it to one file.
@@ -414,8 +414,8 @@ type Props$1 = {
414
414
  /**
415
415
  * Text in a `File` that declares nothing, such as a statement, JSON or markdown. Barrels leave it out.
416
416
  */
417
- export declare function Raw({ children, name }: Props$1): KubbReactElement;
418
- type Props<TOutput> = {
417
+ export declare function Raw({ children, name }: RawProps): KubbReactElement;
418
+ type SchemaProps<TOutput> = {
419
419
  node: ast.SchemaNode;
420
420
  printer: Pick<ast.Printer, 'drainImports'> & {
421
421
  print: (node: ast.SchemaNode) => TOutput | null;
@@ -430,7 +430,7 @@ type Props<TOutput> = {
430
430
  * <Schema node={node} printer={printer}>{(code) => <Const export name="petSchema">{code}</Const>}</Schema>
431
431
  * ```
432
432
  */
433
- export declare function Schema<TOutput>({ node, printer, children }: Props<TOutput>): KubbReactElement | null;
433
+ export declare function Schema<TOutput>({ node, printer, children }: SchemaProps<TOutput>): KubbReactElement | null;
434
434
  type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
435
435
  key?: Key;
436
436
  /**
@@ -466,27 +466,25 @@ type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
466
466
  export declare function Type({ children, ...props }: TypeProps): KubbReactElement;
467
467
  /**
468
468
  * Factory for a renderer that walks the JSX tree in a single recursive pass,
469
- * with no React reconciler or scheduler. Pass it as the `renderer` property on
470
- * `defineGenerator`. Kubb core calls the factory once per render cycle and stays
471
- * generic, with no hard dependency on `@kubb/renderer-jsx`. Every component must be a pure
472
- * function. Hooks, suspense and class components are not supported.
469
+ * with no React reconciler or scheduler. Kit renders a template's JSX with it by default;
470
+ * pass it as `renderer` to `addTemplate` to set it explicitly. Kubb core calls the factory
471
+ * once per render cycle and stays generic, with no hard dependency on `@kubb/renderer-jsx`.
472
+ * Every component must be a pure function. Hooks, suspense and class components are not supported.
473
473
  *
474
- * @example Wire up a JSX generator
474
+ * @example Wire up a JSX template
475
475
  * ```tsx
476
- * import { defineGenerator } from '@kubb/kit'
477
- * import { jsxRenderer } from '@kubb/renderer-jsx'
478
- *
479
- * export const myGenerator = defineGenerator<PluginTs>({
480
- * name: 'types',
481
- * renderer: jsxRenderer,
482
- * schema(node, ctx) {
483
- * return (
484
- * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
485
- * <Type node={node} resolver={ctx.resolver} />
486
- * </File>
487
- * )
476
+ * import { addTemplate, defineTemplate } from '@kubb/kit'
477
+ * import { File, jsxRenderer } from '@kubb/renderer-jsx'
478
+ *
479
+ * export const typesTemplate = defineTemplate<PluginTs>({
480
+ * kind: 'Schema',
481
+ * render(node, ctx) {
482
+ * return <File {...ctx.file(node)}>…</File>
488
483
  * },
489
484
  * })
485
+ *
486
+ * // In the plugin's `setup`:
487
+ * addTemplate(typesTemplate, { renderer: jsxRenderer })
490
488
  * ```
491
489
  */
492
490
  export declare const jsxRenderer: () => {
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./rolldown-runtime-BowF1xt-.js";
2
2
  import { Fragment, isKubbElement, jsx, jsxs } from "./jsx-runtime.js";
3
- import { stringify } from "yaml";
4
3
  import { ast } from "@kubb/ast";
4
+ import { stringify } from "yaml";
5
5
  // src/components/md/Callout.tsx
6
6
  const CALLOUT_LABEL = {
7
7
  tip: "TIP",
@@ -100,12 +100,16 @@ function File({ children, ...props }) {
100
100
  *
101
101
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
102
102
  */
103
- function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }) {
103
+ function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isExportable, space, isTypeOnly, inline }) {
104
104
  return /* @__PURE__ */ jsx("kubb-origin", {
105
105
  pointer,
106
106
  children: /* @__PURE__ */ jsx("kubb-code", {
107
107
  name,
108
- export: isExport ?? isIndexable,
108
+ export: ast.file.isExported({
109
+ export: isExport,
110
+ isIndexable,
111
+ isExportable
112
+ }),
109
113
  default: isDefault,
110
114
  space,
111
115
  isTypeOnly,
@@ -454,7 +458,7 @@ function collectFileChildren(element) {
454
458
  sources.push(ast.factory.createSource({
455
459
  name: name?.toString(),
456
460
  ...space ? { space } : {},
457
- isTypeOnly: !!isTypeOnly,
461
+ ...isTypeOnly != null ? { isTypeOnly } : {},
458
462
  export: !!isExport,
459
463
  ...isDefault ? { default: true } : {},
460
464
  ...inline ? { inline } : {},
@@ -506,7 +510,7 @@ function collectFileChildren(element) {
506
510
  const node = createCodeNode(host.type, host.props);
507
511
  sources.push(ast.factory.createSource({
508
512
  name,
509
- isTypeOnly: host.type === "kubb-type",
513
+ ...host.type === "kubb-type" ? { isTypeOnly: true } : {},
510
514
  export: !!canExport,
511
515
  ...isDefault ? { default: true } : {},
512
516
  ...inline && "nodes" in node ? { inline: { expression: ast.node.getText(node.nodes) } } : {},
@@ -542,27 +546,25 @@ function createFileNode(props) {
542
546
  }
543
547
  /**
544
548
  * Factory for a renderer that walks the JSX tree in a single recursive pass,
545
- * with no React reconciler or scheduler. Pass it as the `renderer` property on
546
- * `defineGenerator`. Kubb core calls the factory once per render cycle and stays
547
- * generic, with no hard dependency on `@kubb/renderer-jsx`. Every component must be a pure
548
- * function. Hooks, suspense and class components are not supported.
549
+ * with no React reconciler or scheduler. Kit renders a template's JSX with it by default;
550
+ * pass it as `renderer` to `addTemplate` to set it explicitly. Kubb core calls the factory
551
+ * once per render cycle and stays generic, with no hard dependency on `@kubb/renderer-jsx`.
552
+ * Every component must be a pure function. Hooks, suspense and class components are not supported.
549
553
  *
550
- * @example Wire up a JSX generator
554
+ * @example Wire up a JSX template
551
555
  * ```tsx
552
- * import { defineGenerator } from '@kubb/kit'
553
- * import { jsxRenderer } from '@kubb/renderer-jsx'
554
- *
555
- * export const myGenerator = defineGenerator<PluginTs>({
556
- * name: 'types',
557
- * renderer: jsxRenderer,
558
- * schema(node, ctx) {
559
- * return (
560
- * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
561
- * <Type node={node} resolver={ctx.resolver} />
562
- * </File>
563
- * )
556
+ * import { addTemplate, defineTemplate } from '@kubb/kit'
557
+ * import { File, jsxRenderer } from '@kubb/renderer-jsx'
558
+ *
559
+ * export const typesTemplate = defineTemplate<PluginTs>({
560
+ * kind: 'Schema',
561
+ * render(node, ctx) {
562
+ * return <File {...ctx.file(node)}>…</File>
564
563
  * },
565
564
  * })
565
+ *
566
+ * // In the plugin's `setup`:
567
+ * addTemplate(typesTemplate, { renderer: jsxRenderer })
566
568
  * ```
567
569
  */
568
570
  const jsxRenderer = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.25.0",
3
+ "version": "5.25.1",
4
4
  "description": "Self-contained synchronous JSX renderer for Kubb. Turns JSX into FileNodes with built-in components (File, Function, Type, Const). An alternative for the ast.factory syntax.",
5
5
  "keywords": [
6
6
  "codegen",
@@ -97,10 +97,10 @@
97
97
  "yaml": "^2.9.1"
98
98
  },
99
99
  "devDependencies": {
100
- "@kubb/ast": "5.25.0"
100
+ "@kubb/ast": "5.25.1"
101
101
  },
102
102
  "peerDependencies": {
103
- "@kubb/ast": "^5.25.0"
103
+ "@kubb/ast": "^5.25.1"
104
104
  },
105
105
  "engines": {
106
106
  "node": ">=22.22"