@kubb/renderer-jsx 5.0.0-beta.3 → 5.0.0-beta.30

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as __name } from "./chunk-Bb7HlUDG.js";
2
- import { a as JSDoc, h as KubbReactNode, m as KubbReactElement, o as Key } from "./types-nAFMiWFw.js";
2
+ import { a as JSDoc, h as KubbReactNode, m as KubbReactElement, o as Key } from "./types-Cur_nGCL.js";
3
3
  import { ExportNode, FileNode, ImportNode, SourceNode } from "@kubb/ast";
4
4
  import * as _$react from "react";
5
5
 
@@ -47,6 +47,95 @@ declare function unprovide<T>(key: symbol | Context<T>): void;
47
47
  */
48
48
  declare function createContext<T>(defaultValue: T): Context<T>;
49
49
  //#endregion
50
+ //#region src/components/Callout.d.ts
51
+ declare const CALLOUT_LABEL: {
52
+ readonly tip: "TIP";
53
+ readonly note: "NOTE";
54
+ readonly important: "IMPORTANT";
55
+ readonly warning: "WARNING";
56
+ readonly caution: "CAUTION";
57
+ };
58
+ type CalloutType = keyof typeof CALLOUT_LABEL;
59
+ type Props$8 = {
60
+ key?: Key;
61
+ /**
62
+ * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
63
+ */
64
+ type: CalloutType;
65
+ /**
66
+ * Optional title rendered on the same line as the marker.
67
+ */
68
+ title?: string | null;
69
+ /**
70
+ * Body text. Each line is quoted with `> ` so multi-line content stays
71
+ * inside the callout block.
72
+ */
73
+ children: string;
74
+ };
75
+ /**
76
+ * Renders a GitHub-style alert callout — portable across GitHub, GitLab,
77
+ * VitePress, Obsidian, and MDX.
78
+ *
79
+ * Emits a `<File.Source>` block containing `> [!TYPE] Title` followed by the
80
+ * body with every line prefixed by `> `.
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * <Callout type="tip">Run `kubb start --watch` to keep the generator hot.</Callout>
85
+ * // > [!TIP]
86
+ * // > Run `kubb start --watch` to keep the generator hot.
87
+ *
88
+ * <Callout type="warning" title="Heads up">Breaking change in v6.</Callout>
89
+ * // > [!WARNING] Heads up
90
+ * // > Breaking change in v6.
91
+ * ```
92
+ */
93
+ declare function Callout({
94
+ type,
95
+ title,
96
+ children
97
+ }: Props$8): KubbReactElement;
98
+ declare namespace Callout {
99
+ var displayName: string;
100
+ }
101
+ //#endregion
102
+ //#region src/components/CodeBlock.d.ts
103
+ type Props$7 = {
104
+ key?: Key;
105
+ /**
106
+ * Language tag for syntax highlighting. Rendered after the opening fence.
107
+ *
108
+ * @example
109
+ * `lang: 'typescript'`
110
+ */
111
+ lang?: string;
112
+ /**
113
+ * Code body. Wrapped in triple-backtick fences as-is.
114
+ */
115
+ children: string;
116
+ };
117
+ /**
118
+ * Renders a fenced markdown code block.
119
+ *
120
+ * Emits a `<File.Source>` block containing the children wrapped in
121
+ * triple-backtick fences with an optional language tag.
122
+ *
123
+ * @example
124
+ * ```tsx
125
+ * <CodeBlock lang="typescript">{'const pet = { id: 1 }'}</CodeBlock>
126
+ * // ```typescript
127
+ * // const pet = { id: 1 }
128
+ * // ```
129
+ * ```
130
+ */
131
+ declare function CodeBlock({
132
+ lang,
133
+ children
134
+ }: Props$7): KubbReactElement;
135
+ declare namespace CodeBlock {
136
+ var displayName: string;
137
+ }
138
+ //#endregion
50
139
  //#region src/components/Const.d.ts
51
140
  type ConstProps = {
52
141
  key?: Key;
@@ -63,26 +152,26 @@ type ConstProps = {
63
152
  * - `false` generates `const name = …`
64
153
  * @default false
65
154
  */
66
- export?: boolean;
155
+ export?: boolean | null;
67
156
  /**
68
157
  * TypeScript type annotation for the constant, written verbatim after `const name:`.
69
158
  *
70
159
  * @example
71
160
  * `type: 'Pet'` → `const pet: Pet = …`
72
161
  */
73
- type?: string;
162
+ type?: string | null;
74
163
  /**
75
164
  * JSDoc block to prepend to the constant declaration.
76
165
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
77
166
  */
78
- JSDoc?: JSDoc;
167
+ JSDoc?: JSDoc | null;
79
168
  /**
80
169
  * Append `as const` after the initialiser, enabling TypeScript const assertions.
81
170
  * - `true` generates `const name = … as const`
82
171
  * - `false` generates `const name = …`
83
172
  * @default false
84
173
  */
85
- asConst?: boolean;
174
+ asConst?: boolean | null;
86
175
  /**
87
176
  * Child nodes rendered as the initialiser expression of the constant.
88
177
  */
@@ -140,24 +229,26 @@ type BasePropsWithoutBaseName = {
140
229
  * Fully qualified path to the generated file.
141
230
  * Optional when `baseName` is omitted — the component renders its children inline.
142
231
  */
143
- path?: string;
232
+ path?: string | null;
144
233
  };
145
234
  type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
146
- type Props$2<TMeta> = BaseProps & {
235
+ type Props$6<TMeta> = BaseProps & {
147
236
  key?: Key;
148
237
  /**
149
238
  * Arbitrary metadata attached to the file node.
150
239
  * Used by plugins for barrel generation and custom post-processing.
151
240
  */
152
- meta?: TMeta;
241
+ meta?: TMeta | null;
153
242
  /**
154
243
  * Text prepended to the generated file content before any source blocks.
244
+ * Accepts `null` so `resolver.resolveBanner()` results can be passed directly.
155
245
  */
156
- banner?: string;
246
+ banner?: string | null;
157
247
  /**
158
248
  * Text appended to the generated file content after all source blocks.
249
+ * Accepts `null` so `resolver.resolveFooter()` results can be passed directly.
159
250
  */
160
- footer?: string;
251
+ footer?: string | null;
161
252
  /**
162
253
  * Child nodes rendered as the content of this file (source blocks, imports, exports).
163
254
  */
@@ -182,7 +273,7 @@ type Props$2<TMeta> = BaseProps & {
182
273
  declare function File<TMeta extends object = object>({
183
274
  children,
184
275
  ...props
185
- }: Props$2<TMeta>): KubbReactElement;
276
+ }: Props$6<TMeta>): KubbReactElement;
186
277
  declare namespace File {
187
278
  var displayName: string;
188
279
  var Export: typeof FileExport;
@@ -278,8 +369,44 @@ declare namespace FileImport {
278
369
  var displayName: string;
279
370
  }
280
371
  //#endregion
372
+ //#region src/components/Frontmatter.d.ts
373
+ type Props$5 = {
374
+ key?: Key;
375
+ /**
376
+ * Plain object serialised as YAML between `---` fences.
377
+ *
378
+ * @example
379
+ * `data: { title: 'Pets', layout: 'doc' }`
380
+ */
381
+ data: Record<string, unknown>;
382
+ };
383
+ /**
384
+ * Emits a YAML frontmatter envelope at the top of a generated markdown file.
385
+ *
386
+ * Renders a `<File.Source>` block containing `---\n<yaml>\n---`. Place it as
387
+ * the first child of `<File>` so it appears at the top of the output. Pair with
388
+ * `parserMd` to write `.md` files that downstream tooling (VitePress, MDX,
389
+ * static-site generators) treats as frontmatter.
390
+ *
391
+ * @example Page frontmatter at the top of a generated markdown file
392
+ * ```tsx
393
+ * <File baseName="pets.md" path="src/pets.md">
394
+ * <Frontmatter data={{ title: 'Pets', layout: 'doc' }} />
395
+ * <File.Source>
396
+ * {'# Pets\n\nList of pets.'}
397
+ * </File.Source>
398
+ * </File>
399
+ * ```
400
+ */
401
+ declare function Frontmatter({
402
+ data
403
+ }: Props$5): KubbReactElement;
404
+ declare namespace Frontmatter {
405
+ var displayName: string;
406
+ }
407
+ //#endregion
281
408
  //#region src/components/Function.d.ts
282
- type Props$1 = {
409
+ type Props$4 = {
283
410
  key?: Key;
284
411
  /**
285
412
  * Identifier of the generated function declaration.
@@ -293,28 +420,28 @@ type Props$1 = {
293
420
  * Requires `export` to also be `true`.
294
421
  * @default false
295
422
  */
296
- default?: boolean;
423
+ default?: boolean | null;
297
424
  /**
298
425
  * Parameter list written verbatim between the function's parentheses.
299
426
  *
300
427
  * @example
301
428
  * `params: 'petId: string, options?: RequestOptions'`
302
429
  */
303
- params?: string;
430
+ params?: string | null;
304
431
  /**
305
432
  * Emit the `export` keyword before the function declaration.
306
433
  * - `true` generates `export function name(…) { … }`
307
434
  * - `false` generates `function name(…) { … }`
308
435
  * @default false
309
436
  */
310
- export?: boolean;
437
+ export?: boolean | null;
311
438
  /**
312
439
  * Emit the `async` keyword, making this an async function.
313
440
  * The return type is automatically wrapped in `Promise<returnType>` when both
314
441
  * `async` and `returnType` are set.
315
442
  * @default false
316
443
  */
317
- async?: boolean;
444
+ async?: boolean | null;
318
445
  /**
319
446
  * TypeScript generic type parameters written verbatim between `<` and `>`.
320
447
  * Pass an array to emit multiple parameters separated by commas.
@@ -325,7 +452,7 @@ type Props$1 = {
325
452
  * @example Multiple generics
326
453
  * `generics: ['TData', 'TError = unknown']`
327
454
  */
328
- generics?: string | string[];
455
+ generics?: string | Array<string> | null;
329
456
  /**
330
457
  * TypeScript return type annotation written verbatim after `:`.
331
458
  * When `async` is `true`, the value is automatically wrapped in `Promise<…>`.
@@ -333,12 +460,12 @@ type Props$1 = {
333
460
  * @example
334
461
  * `returnType: 'Pet'`
335
462
  */
336
- returnType?: string;
463
+ returnType?: string | null;
337
464
  /**
338
465
  * JSDoc block to prepend to the function declaration.
339
466
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
340
467
  */
341
- JSDoc?: JSDoc;
468
+ JSDoc?: JSDoc | null;
342
469
  /**
343
470
  * Child nodes rendered as the body of the function.
344
471
  */
@@ -360,19 +487,19 @@ type Props$1 = {
360
487
  declare function Function({
361
488
  children,
362
489
  ...props
363
- }: Props$1): KubbReactElement;
490
+ }: Props$4): KubbReactElement;
364
491
  declare namespace Function {
365
492
  var displayName: string;
366
493
  var Arrow: typeof ArrowFunction;
367
494
  }
368
- type ArrowFunctionProps = Props$1 & {
495
+ type ArrowFunctionProps = Props$4 & {
369
496
  /**
370
497
  * Render the arrow function as a single-line expression (no braces around the body).
371
498
  * - `true` generates `const name = (…) => expression`
372
499
  * - `false` generates `const name = (…) => { … }`
373
500
  * @default false
374
501
  */
375
- singleLine?: boolean;
502
+ singleLine?: boolean | null;
376
503
  };
377
504
  /**
378
505
  * Generates an arrow function expression assigned to a `const`.
@@ -395,8 +522,42 @@ declare namespace ArrowFunction {
395
522
  var displayName: string;
396
523
  }
397
524
  //#endregion
525
+ //#region src/components/Heading.d.ts
526
+ type Level = 1 | 2 | 3 | 4 | 5 | 6;
527
+ type Props$3 = {
528
+ key?: Key;
529
+ /**
530
+ * Heading depth, `1` through `6`. Matches the number of `#` characters
531
+ * prefixed to the heading text.
532
+ */
533
+ level: Level;
534
+ /**
535
+ * Heading text. Inline markdown (links, emphasis) is passed through verbatim.
536
+ */
537
+ children: string;
538
+ };
539
+ /**
540
+ * Renders an ATX-style markdown heading.
541
+ *
542
+ * Emits a `<File.Source>` block containing `${'#'.repeat(level)} ${children}`.
543
+ * Use inside a `<File>` rendered by `parserMd`.
544
+ *
545
+ * @example
546
+ * ```tsx
547
+ * <Heading level={2}>Installation</Heading>
548
+ * // ## Installation
549
+ * ```
550
+ */
551
+ declare function Heading({
552
+ level,
553
+ children
554
+ }: Props$3): KubbReactElement;
555
+ declare namespace Heading {
556
+ var displayName: string;
557
+ }
558
+ //#endregion
398
559
  //#region src/components/Jsx.d.ts
399
- type Props = {
560
+ type Props$2 = {
400
561
  /**
401
562
  * Raw JSX string to embed verbatim in the generated code.
402
563
  * Supports JSX fragments (`<>…</>`), elements, and any valid JSX syntax.
@@ -424,11 +585,79 @@ type Props = {
424
585
  */
425
586
  declare function Jsx({
426
587
  children
427
- }: Props): KubbReactElement;
588
+ }: Props$2): KubbReactElement;
428
589
  declare namespace Jsx {
429
590
  var displayName: string;
430
591
  }
431
592
  //#endregion
593
+ //#region src/components/List.d.ts
594
+ type Props$1 = {
595
+ key?: Key;
596
+ /**
597
+ * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
598
+ * emits a bullet list (`- …`).
599
+ *
600
+ * @default false
601
+ */
602
+ ordered?: boolean | null;
603
+ /**
604
+ * One entry per line. Inline markdown is passed through verbatim.
605
+ */
606
+ items: ReadonlyArray<string>;
607
+ };
608
+ /**
609
+ * Renders a markdown list.
610
+ *
611
+ * Emits a `<File.Source>` block containing one entry per line, prefixed with
612
+ * `1.` / `2.` … when `ordered`, or `-` otherwise.
613
+ *
614
+ * @example
615
+ * ```tsx
616
+ * <List items={['Add the parser', 'Render the page']} />
617
+ * // - Add the parser
618
+ * // - Render the page
619
+ *
620
+ * <List ordered items={['First', 'Second']} />
621
+ * // 1. First
622
+ * // 2. Second
623
+ * ```
624
+ */
625
+ declare function List({
626
+ ordered,
627
+ items
628
+ }: Props$1): KubbReactElement;
629
+ declare namespace List {
630
+ var displayName: string;
631
+ }
632
+ //#endregion
633
+ //#region src/components/Paragraph.d.ts
634
+ type Props = {
635
+ key?: Key;
636
+ /**
637
+ * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
638
+ * through verbatim.
639
+ */
640
+ children: string;
641
+ };
642
+ /**
643
+ * Renders a markdown paragraph.
644
+ *
645
+ * Emits a `<File.Source>` block containing the text as-is. Paragraphs are
646
+ * separated from surrounding blocks by blank lines via the parser's source
647
+ * joining.
648
+ *
649
+ * @example
650
+ * ```tsx
651
+ * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
652
+ * ```
653
+ */
654
+ declare function Paragraph({
655
+ children
656
+ }: Props): KubbReactElement;
657
+ declare namespace Paragraph {
658
+ var displayName: string;
659
+ }
660
+ //#endregion
432
661
  //#region src/components/Root.d.ts
433
662
  type RootProps = {
434
663
  /**
@@ -478,12 +707,12 @@ type TypeProps = {
478
707
  * - `false` generates `type Name = …`
479
708
  * @default false
480
709
  */
481
- export?: boolean;
710
+ export?: boolean | null;
482
711
  /**
483
712
  * JSDoc block to prepend to the type alias declaration.
484
713
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
485
714
  */
486
- JSDoc?: JSDoc;
715
+ JSDoc?: JSDoc | null;
487
716
  /**
488
717
  * Child nodes rendered as the type expression on the right-hand side of the alias.
489
718
  */
@@ -519,78 +748,87 @@ declare namespace Type {
519
748
  }
520
749
  //#endregion
521
750
  //#region src/createRenderer.d.ts
522
- type Options = {
523
- /**
524
- * Print each render result to the console for debugging.
525
- * Useful when diagnosing output differences between renders.
526
- * @default false
527
- */
528
- debug?: boolean;
529
- };
530
751
  /**
531
- * The renderer instance returned by {@link createRenderer}.
532
- */
533
- type Renderer = {
534
- /**
535
- * Render a JSX element tree and collect the resulting {@link FileNode} entries.
536
- * Resolves once all synchronous render work (including React's flush) is done.
537
- */
538
- render(Element: KubbReactElement): Promise<void>;
539
- /**
540
- * Tear down the renderer and release all React resources.
541
- * Pass an `Error` to signal an abnormal shutdown.
542
- */
543
- unmount(error?: Error | number | null): void;
544
- /**
545
- * The {@link FileNode} entries collected from the most recent `render` call.
546
- */
547
- files: Array<FileNode>;
548
- };
549
- /**
550
- * Create a Kubb JSX renderer.
752
+ * Renderer factory that turns the JSX produced by a generator into
753
+ * `FileNode`s using React's reconciler under the hood. Pass as the `renderer`
754
+ * property on `defineGenerator`. Kubb core stays generic, with no hard
755
+ * dependency on `@kubb/renderer-jsx`.
551
756
  *
552
- * The renderer converts a React JSX element tree built from the components in this
553
- * package into an array of {@link FileNode} entries representing the generated files.
757
+ * Use this when generators rely on React features (hooks, suspense, context).
758
+ * For pure-function components, see {@link jsxRendererSync} for ~2-4× faster
759
+ * rendering.
554
760
  *
555
- * @example Basic usage
556
- * ```ts
557
- * import { createRenderer, File } from '@kubb/renderer-jsx'
558
- *
559
- * const renderer = createRenderer()
560
- * await renderer.render(
561
- * <File baseName="pet.ts" path="src/models/pet.ts">
562
- * <File.Source name="Pet" isExportable isIndexable>
563
- * {`export type Pet = { id: number; name: string }`}
564
- * </File.Source>
565
- * </File>
566
- * )
567
- * console.log(renderer.files) // [FileNode]
568
- * renderer.unmount()
761
+ * @example Wire up a JSX generator
762
+ * ```tsx
763
+ * import { defineGenerator } from '@kubb/core'
764
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
765
+ *
766
+ * export const myGenerator = defineGenerator<PluginTs>({
767
+ * name: 'types',
768
+ * renderer: jsxRenderer,
769
+ * schema(node, ctx) {
770
+ * return (
771
+ * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
772
+ * <Type node={node} resolver={ctx.resolver} />
773
+ * </File>
774
+ * )
775
+ * },
776
+ * })
569
777
  * ```
570
778
  */
571
- declare function createRenderer(options?: Options): Renderer;
779
+ declare const jsxRenderer: () => {
780
+ render(element: KubbReactElement): Promise<void>;
781
+ readonly files: FileNode[];
782
+ dispose(): void;
783
+ unmount(error?: Error | number | null): void;
784
+ [Symbol.dispose](): void;
785
+ };
572
786
  /**
573
- * A renderer factory for generators that produce JSX output.
787
+ * Lightweight renderer that walks the JSX tree in a single recursive pass —
788
+ * no React reconciler, no scheduler. Drop-in replacement for
789
+ * {@link jsxRenderer} at roughly 2–4× the throughput.
574
790
  *
575
- * Pass this as the `renderer` property of a `defineGenerator` call so that
576
- * core can render the JSX element tree returned by your generator methods
577
- * without a hard dependency on `@kubb/renderer-jsx`.
791
+ * Constraints: every component must be a pure function. Hooks, suspense, and
792
+ * class components are not supported.
578
793
  *
579
- * @example
580
- * ```ts
581
- * import { jsxRenderer } from '@kubb/renderer-jsx'
794
+ * Use this for generators that produce large amounts of output and do not need
795
+ * React's runtime features. It also exposes `stream()` for incremental file
796
+ * emission.
797
+ *
798
+ * @example Drop-in faster renderer
799
+ * ```tsx
582
800
  * import { defineGenerator } from '@kubb/core'
801
+ * import { jsxRendererSync } from '@kubb/renderer-jsx'
583
802
  *
584
803
  * export const myGenerator = defineGenerator<PluginTs>({
585
- * name: 'my-generator',
586
- * renderer: jsxRenderer,
587
- * schema(node, options) {
588
- * return <File baseName="output.ts" path="src/output.ts">...</File>
804
+ * name: 'types',
805
+ * renderer: jsxRendererSync,
806
+ * schema(node, ctx) {
807
+ * return (
808
+ * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
809
+ * <Type node={node} resolver={ctx.resolver} />
810
+ * </File>
811
+ * )
589
812
  * },
590
813
  * })
591
814
  * ```
815
+ *
816
+ * @example Stream files as they are produced
817
+ * ```tsx
818
+ * const renderer = jsxRendererSync()
819
+ * for (const file of renderer.stream(element)) {
820
+ * await writeFile(file.path, file.sources[0])
821
+ * }
822
+ * ```
592
823
  */
593
- declare const jsxRenderer: () => Renderer;
824
+ declare const jsxRendererSync: () => {
825
+ render(element: KubbReactElement): Promise<void>;
826
+ readonly files: FileNode[];
827
+ stream(element: KubbReactElement): Generator<FileNode>;
828
+ dispose(): void;
829
+ unmount(_error?: Error | number | null): void;
830
+ [Symbol.dispose](): void;
831
+ };
594
832
  //#endregion
595
- export { Const, File, Function, Jsx, Root, Type, createContext, createRenderer, inject, jsxRenderer, provide, unprovide };
833
+ export { Callout, CodeBlock, Const, File, Frontmatter, Function, Heading, Jsx, List, Paragraph, Root, Type, createContext, inject, jsxRenderer, jsxRendererSync, provide, unprovide };
596
834
  //# sourceMappingURL=index.d.ts.map