@kubb/renderer-jsx 5.0.0-beta.9 → 5.0.0-beta.91

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,54 +1,59 @@
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";
3
- import * as _$_kubb_ast0 from "@kubb/ast";
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { i as KubbReactNode, n as Key, r as KubbReactElement, t as JSDoc } from "./types-1dqfG_Fl.js";
4
3
  import { ExportNode, ImportNode, SourceNode } from "@kubb/ast";
5
- import * as _$react from "react";
6
4
 
7
- //#region ../../internals/utils/src/context.d.ts
8
- /**
9
- * Context type that carries type information about its value
10
- * This is a branded symbol type that enables type-safe context usage
11
- */
12
- type Context<T> = symbol & {
13
- readonly __type: T;
5
+ //#region src/components/md/Callout.d.ts
6
+ declare const CALLOUT_LABEL: {
7
+ readonly tip: "TIP";
8
+ readonly note: "NOTE";
9
+ readonly important: "IMPORTANT";
10
+ readonly warning: "WARNING";
11
+ readonly caution: "CAUTION";
12
+ };
13
+ type CalloutType = keyof typeof CALLOUT_LABEL;
14
+ type Props$7 = {
15
+ key?: Key;
16
+ /**
17
+ * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
18
+ */
19
+ type: CalloutType;
20
+ /**
21
+ * Optional title rendered on the same line as the marker.
22
+ */
23
+ title?: string | null;
24
+ /**
25
+ * Body text. Each line is quoted with `> ` so multi-line content stays
26
+ * inside the callout block.
27
+ */
28
+ children: string;
14
29
  };
15
30
  /**
16
- * Provides a value to descendant components (Vue 3 style)
31
+ * Renders a GitHub-style alert callout using the `> [!TYPE]` blockquote syntax.
17
32
  *
18
- * @example
19
- * ```ts
20
- * const ThemeKey = Symbol('theme')
21
- * provide(ThemeKey, { color: 'blue' })
22
- * ```
23
- */
24
- declare function provide<T>(key: symbol | Context<T>, value: T): void;
25
- /**
26
- * Injects a value provided by an ancestor component (Vue 3 style)
33
+ * Emits a `<File.Source>` block containing `> [!TYPE] Title` followed by the
34
+ * body with every line prefixed by `> `.
27
35
  *
28
36
  * @example
29
- * ```ts
30
- * const theme = inject(ThemeKey, { color: 'default' })
31
- * ```
32
- */
33
- declare function inject<T>(key: symbol | Context<T>, defaultValue?: T): T;
34
- /**
35
- * Removes a provided value from the context stack (for cleanup)
36
- * @internal
37
- */
38
- declare function unprovide<T>(key: symbol | Context<T>): void;
39
- /**
40
- * Creates a context key with a default value (React-style compatibility)
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
41
  *
42
- * @example
43
- * ```ts
44
- * const ThemeContext = createContext({ color: 'blue' })
45
- * // ThemeContext is now typed as Context<{ color: string }>
46
- * const theme = useContext(ThemeContext) // theme is { color: string }
42
+ * <Callout type="warning" title="Heads up">Breaking change in v6.</Callout>
43
+ * // > [!WARNING] Heads up
44
+ * // > Breaking change in v6.
47
45
  * ```
48
46
  */
49
- declare function createContext<T>(defaultValue: T): Context<T>;
47
+ declare function Callout({
48
+ type,
49
+ title,
50
+ children
51
+ }: Props$7): KubbReactElement;
52
+ declare namespace Callout {
53
+ var displayName: string;
54
+ }
50
55
  //#endregion
51
- //#region src/components/Const.d.ts
56
+ //#region src/components/js/Const.d.ts
52
57
  type ConstProps = {
53
58
  key?: Key;
54
59
  /**
@@ -62,30 +67,28 @@ type ConstProps = {
62
67
  * Emit the `export` keyword before the `const` declaration.
63
68
  * - `true` generates `export const name = …`
64
69
  * - `false` generates `const name = …`
65
- * @default false
66
70
  */
67
- export?: boolean;
71
+ export?: boolean | null;
68
72
  /**
69
73
  * TypeScript type annotation for the constant, written verbatim after `const name:`.
70
74
  *
71
75
  * @example
72
76
  * `type: 'Pet'` → `const pet: Pet = …`
73
77
  */
74
- type?: string;
78
+ type?: string | null;
75
79
  /**
76
80
  * JSDoc block to prepend to the constant declaration.
77
81
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
78
82
  */
79
- JSDoc?: JSDoc;
83
+ JSDoc?: JSDoc | null;
80
84
  /**
81
- * Append `as const` after the initialiser, enabling TypeScript const assertions.
85
+ * Append `as const` after the initializer, enabling TypeScript const assertions.
82
86
  * - `true` generates `const name = … as const`
83
87
  * - `false` generates `const name = …`
84
- * @default false
85
88
  */
86
- asConst?: boolean;
89
+ asConst?: boolean | null;
87
90
  /**
88
- * Child nodes rendered as the initialiser expression of the constant.
91
+ * Child nodes rendered as the initializer expression of the constant.
89
92
  */
90
93
  children?: KubbReactNode;
91
94
  };
@@ -139,26 +142,34 @@ type BasePropsWithoutBaseName = {
139
142
  baseName?: never;
140
143
  /**
141
144
  * Fully qualified path to the generated file.
142
- * Optional when `baseName` is omitted the component renders its children inline.
145
+ * Optional when `baseName` is omitted, the component renders its children inline.
143
146
  */
144
- path?: string;
147
+ path?: string | null;
145
148
  };
146
149
  type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
147
- type Props$2<TMeta> = BaseProps & {
150
+ type Props$6<TMeta> = BaseProps & {
148
151
  key?: Key;
149
152
  /**
150
- * Arbitrary metadata attached to the file node.
151
- * Used by plugins for barrel generation and custom post-processing.
153
+ * Arbitrary metadata attached to the file node for plugins to read.
152
154
  */
153
- meta?: TMeta;
155
+ meta?: TMeta | null;
154
156
  /**
155
157
  * Text prepended to the generated file content before any source blocks.
158
+ * Accepts `null` so `resolver.default.banner()` results can be passed directly.
156
159
  */
157
- banner?: string;
160
+ banner?: string | null;
158
161
  /**
159
162
  * Text appended to the generated file content after all source blocks.
163
+ * Accepts `null` so `resolver.default.footer()` results can be passed directly.
160
164
  */
161
- footer?: string;
165
+ footer?: string | null;
166
+ /**
167
+ * Absolute on-disk path to copy verbatim into the output, bypassing the parser. Use to emit a
168
+ * real source file shipped inside a package (a template) into the generated folder. Only
169
+ * `banner`/`footer` are applied around the copied content; child source blocks are ignored for
170
+ * output but still drive barrel generation.
171
+ */
172
+ copy?: string | null;
162
173
  /**
163
174
  * Child nodes rendered as the content of this file (source blocks, imports, exports).
164
175
  */
@@ -183,7 +194,7 @@ type Props$2<TMeta> = BaseProps & {
183
194
  declare function File<TMeta extends object = object>({
184
195
  children,
185
196
  ...props
186
- }: Props$2<TMeta>): KubbReactElement;
197
+ }: Props$6<TMeta>): KubbReactElement;
187
198
  declare namespace File {
188
199
  var displayName: string;
189
200
  var Export: typeof FileExport;
@@ -200,8 +211,8 @@ type FileSourceProps = Omit<SourceNode, 'kind' | 'value'> & {
200
211
  /**
201
212
  * Marks a block of source text to be associated with the enclosing {@link File}.
202
213
  *
203
- * Children are treated as the source string. When `isExportable` is `true` the
204
- * `name` is used for deduplication and barrel generation.
214
+ * Children are treated as the source string. `isExportable` prepends the `export` keyword,
215
+ * `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
205
216
  *
206
217
  * @example Exportable, indexable source block
207
218
  * ```tsx
@@ -279,8 +290,43 @@ declare namespace FileImport {
279
290
  var displayName: string;
280
291
  }
281
292
  //#endregion
282
- //#region src/components/Function.d.ts
283
- type Props$1 = {
293
+ //#region src/components/md/Frontmatter.d.ts
294
+ type Props$5 = {
295
+ key?: Key;
296
+ /**
297
+ * Plain object serialized as YAML between `---` fences.
298
+ *
299
+ * @example
300
+ * `{ title: 'Pets', layout: 'doc' }`
301
+ */
302
+ data: Record<string, unknown>;
303
+ };
304
+ /**
305
+ * Emits a YAML frontmatter envelope at the top of a generated markdown file.
306
+ *
307
+ * Renders a `<File.Source>` block containing `---\n<yaml>\n---`. Place it as
308
+ * the first child of `<File>` so it appears at the top of the output. Pair with
309
+ * `parserMd` to write `.md` files whose frontmatter downstream tooling can read.
310
+ *
311
+ * @example Page frontmatter at the top of a generated markdown file
312
+ * ```tsx
313
+ * <File baseName="pets.md" path="src/pets.md">
314
+ * <Frontmatter data={{ title: 'Pets', layout: 'doc' }} />
315
+ * <File.Source>
316
+ * {'# Pets\n\nList of pets.'}
317
+ * </File.Source>
318
+ * </File>
319
+ * ```
320
+ */
321
+ declare function Frontmatter({
322
+ data
323
+ }: Props$5): KubbReactElement;
324
+ declare namespace Frontmatter {
325
+ var displayName: string;
326
+ }
327
+ //#endregion
328
+ //#region src/components/js/Function.d.ts
329
+ type Props$4 = {
284
330
  key?: Key;
285
331
  /**
286
332
  * Identifier of the generated function declaration.
@@ -292,30 +338,27 @@ type Props$1 = {
292
338
  /**
293
339
  * Emit `default` after the `export` keyword, making this the module's default export.
294
340
  * Requires `export` to also be `true`.
295
- * @default false
296
341
  */
297
- default?: boolean;
342
+ default?: boolean | null;
298
343
  /**
299
344
  * Parameter list written verbatim between the function's parentheses.
300
345
  *
301
346
  * @example
302
347
  * `params: 'petId: string, options?: RequestOptions'`
303
348
  */
304
- params?: string;
349
+ params?: string | null;
305
350
  /**
306
351
  * Emit the `export` keyword before the function declaration.
307
352
  * - `true` generates `export function name(…) { … }`
308
353
  * - `false` generates `function name(…) { … }`
309
- * @default false
310
354
  */
311
- export?: boolean;
355
+ export?: boolean | null;
312
356
  /**
313
357
  * Emit the `async` keyword, making this an async function.
314
358
  * The return type is automatically wrapped in `Promise<returnType>` when both
315
359
  * `async` and `returnType` are set.
316
- * @default false
317
360
  */
318
- async?: boolean;
361
+ async?: boolean | null;
319
362
  /**
320
363
  * TypeScript generic type parameters written verbatim between `<` and `>`.
321
364
  * Pass an array to emit multiple parameters separated by commas.
@@ -326,7 +369,7 @@ type Props$1 = {
326
369
  * @example Multiple generics
327
370
  * `generics: ['TData', 'TError = unknown']`
328
371
  */
329
- generics?: string | string[];
372
+ generics?: string | Array<string> | null;
330
373
  /**
331
374
  * TypeScript return type annotation written verbatim after `:`.
332
375
  * When `async` is `true`, the value is automatically wrapped in `Promise<…>`.
@@ -334,12 +377,12 @@ type Props$1 = {
334
377
  * @example
335
378
  * `returnType: 'Pet'`
336
379
  */
337
- returnType?: string;
380
+ returnType?: string | null;
338
381
  /**
339
382
  * JSDoc block to prepend to the function declaration.
340
383
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
341
384
  */
342
- JSDoc?: JSDoc;
385
+ JSDoc?: JSDoc | null;
343
386
  /**
344
387
  * Child nodes rendered as the body of the function.
345
388
  */
@@ -361,19 +404,18 @@ type Props$1 = {
361
404
  declare function Function({
362
405
  children,
363
406
  ...props
364
- }: Props$1): KubbReactElement;
407
+ }: Props$4): KubbReactElement;
365
408
  declare namespace Function {
366
409
  var displayName: string;
367
410
  var Arrow: typeof ArrowFunction;
368
411
  }
369
- type ArrowFunctionProps = Props$1 & {
412
+ type ArrowFunctionProps = Props$4 & {
370
413
  /**
371
414
  * Render the arrow function as a single-line expression (no braces around the body).
372
415
  * - `true` generates `const name = (…) => expression`
373
416
  * - `false` generates `const name = (…) => { … }`
374
- * @default false
375
417
  */
376
- singleLine?: boolean;
418
+ singleLine?: boolean | null;
377
419
  };
378
420
  /**
379
421
  * Generates an arrow function expression assigned to a `const`.
@@ -391,16 +433,51 @@ type ArrowFunctionProps = Props$1 & {
391
433
  declare function ArrowFunction({
392
434
  children,
393
435
  ...props
394
- }: ArrowFunctionProps): _$react.JSX.Element;
436
+ }: ArrowFunctionProps): any;
395
437
  declare namespace ArrowFunction {
396
438
  var displayName: string;
397
439
  }
398
440
  //#endregion
399
- //#region src/components/Jsx.d.ts
400
- type Props = {
441
+ //#region src/components/md/Heading.d.ts
442
+ type Level = 1 | 2 | 3 | 4 | 5 | 6;
443
+ type Props$3 = {
444
+ key?: Key;
445
+ /**
446
+ * Heading depth, `1` through `6`. Matches the number of `#` characters
447
+ * prefixed to the heading text.
448
+ */
449
+ level: Level;
401
450
  /**
402
- * Raw JSX string to embed verbatim in the generated code.
403
- * Supports JSX fragments (`<>…</>`), elements, and any valid JSX syntax.
451
+ * Heading text. Inline markdown (links, emphasis) is passed through verbatim.
452
+ */
453
+ children: string;
454
+ };
455
+ /**
456
+ * Renders an ATX-style markdown heading.
457
+ *
458
+ * Emits a `<File.Source>` block containing `${'#'.repeat(level)} ${children}`.
459
+ * Use inside a `<File>` rendered by `parserMd`.
460
+ *
461
+ * @example
462
+ * ```tsx
463
+ * <Heading level={2}>Installation</Heading>
464
+ * // ## Installation
465
+ * ```
466
+ */
467
+ declare function Heading({
468
+ level,
469
+ children
470
+ }: Props$3): KubbReactElement;
471
+ declare namespace Heading {
472
+ var displayName: string;
473
+ }
474
+ //#endregion
475
+ //#region src/components/jsx/Jsx.d.ts
476
+ type Props$2 = {
477
+ /**
478
+ * Raw JSX string embedded verbatim in the generated code, including
479
+ * fragments (`<>…</>`).
480
+ *
404
481
  * @example
405
482
  * ```tsx
406
483
  * <Jsx>{'<>\n <a href={href}>Open</a>\n</>'}</Jsx>
@@ -411,10 +488,10 @@ type Props = {
411
488
  /**
412
489
  * Embeds a raw JSX string verbatim in the generated source code.
413
490
  *
414
- * Use this component when you need to include JSX markup (including fragments
415
- * `<>…</>`) in the body of a generated function or component. The `children`
416
- * prop must be a plain string expression attributes that reference runtime
417
- * values should be written as template literals.
491
+ * Use this component to include JSX markup (including fragments `<>…</>`) in the
492
+ * body of a generated function or component. The `children` prop must be a plain
493
+ * string. Write expression attributes that reference runtime values as template
494
+ * literals.
418
495
  *
419
496
  * @example
420
497
  * ```tsx
@@ -425,44 +502,80 @@ type Props = {
425
502
  */
426
503
  declare function Jsx({
427
504
  children
428
- }: Props): KubbReactElement;
505
+ }: Props$2): KubbReactElement;
429
506
  declare namespace Jsx {
430
507
  var displayName: string;
431
508
  }
432
509
  //#endregion
433
- //#region src/components/Root.d.ts
434
- type RootProps = {
510
+ //#region src/components/md/List.d.ts
511
+ type Props$1 = {
512
+ key?: Key;
435
513
  /**
436
- * Callback invoked to unmount the entire renderer tree.
437
- * Called with an `Error` when the exit is caused by a render error,
438
- * or with `undefined` for a clean shutdown.
514
+ * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
515
+ * emits a bullet list (`- …`).
516
+ *
517
+ * @default false
439
518
  */
440
- onExit: (error?: Error) => void;
519
+ ordered?: boolean | null;
441
520
  /**
442
- * Callback invoked whenever a render error is caught by the error boundary.
443
- * Use this to propagate errors up to the caller of {@link createRenderer}.
521
+ * One entry per line. Inline markdown is passed through verbatim.
444
522
  */
445
- onError: (error: Error) => void;
523
+ items: ReadonlyArray<string>;
524
+ };
525
+ /**
526
+ * Renders a markdown list.
527
+ *
528
+ * Emits a `<File.Source>` block containing one entry per line, prefixed with
529
+ * `1.` / `2.` … when `ordered`, or `-` otherwise.
530
+ *
531
+ * @example
532
+ * ```tsx
533
+ * <List items={['Add the parser', 'Render the page']} />
534
+ * // - Add the parser
535
+ * // - Render the page
536
+ *
537
+ * <List ordered items={['First', 'Second']} />
538
+ * // 1. First
539
+ * // 2. Second
540
+ * ```
541
+ */
542
+ declare function List({
543
+ ordered,
544
+ items
545
+ }: Props$1): KubbReactElement;
546
+ declare namespace List {
547
+ var displayName: string;
548
+ }
549
+ //#endregion
550
+ //#region src/components/md/Paragraph.d.ts
551
+ type Props = {
552
+ key?: Key;
446
553
  /**
447
- * Child nodes rendered inside the error boundary.
554
+ * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
555
+ * through verbatim.
448
556
  */
449
- children?: KubbReactNode;
557
+ children: string;
450
558
  };
451
559
  /**
452
- * Root component for the Kubb renderer tree.
560
+ * Renders a markdown paragraph.
561
+ *
562
+ * Emits a `<File.Source>` block containing the text as-is. Paragraphs are
563
+ * separated from surrounding blocks by blank lines via the parser's source
564
+ * joining.
453
565
  *
454
- * Wraps all children in an `ErrorBoundary` so that render errors are caught
455
- * and forwarded to `onError` rather than crashing the process.
566
+ * @example
567
+ * ```tsx
568
+ * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
569
+ * ```
456
570
  */
457
- declare function Root({
458
- onError,
571
+ declare function Paragraph({
459
572
  children
460
- }: RootProps): KubbReactElement;
461
- declare namespace Root {
573
+ }: Props): KubbReactElement;
574
+ declare namespace Paragraph {
462
575
  var displayName: string;
463
576
  }
464
577
  //#endregion
465
- //#region src/components/Type.d.ts
578
+ //#region src/components/js/Type.d.ts
466
579
  type TypeProps = {
467
580
  key?: Key;
468
581
  /**
@@ -477,14 +590,13 @@ type TypeProps = {
477
590
  * Emit the `export` keyword before the type alias declaration.
478
591
  * - `true` generates `export type Name = …`
479
592
  * - `false` generates `type Name = …`
480
- * @default false
481
593
  */
482
- export?: boolean;
594
+ export?: boolean | null;
483
595
  /**
484
596
  * JSDoc block to prepend to the type alias declaration.
485
597
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
486
598
  */
487
- JSDoc?: JSDoc;
599
+ JSDoc?: JSDoc | null;
488
600
  /**
489
601
  * Child nodes rendered as the type expression on the right-hand side of the alias.
490
602
  */
@@ -493,7 +605,7 @@ type TypeProps = {
493
605
  /**
494
606
  * Generates a TypeScript type alias declaration.
495
607
  *
496
- * Throws if `name` does not start with an uppercase letter TypeScript type aliases
608
+ * Throws if `name` does not start with an uppercase letter. TypeScript type aliases
497
609
  * should follow PascalCase naming conventions.
498
610
  *
499
611
  * @example Simple exported type alias
@@ -519,33 +631,39 @@ declare namespace Type {
519
631
  var displayName: string;
520
632
  }
521
633
  //#endregion
522
- //#region src/createRenderer.d.ts
634
+ //#region src/jsxRenderer.d.ts
523
635
  /**
524
- * A renderer factory for generators that produce JSX output.
636
+ * Factory for a renderer that walks the JSX tree in a single recursive pass,
637
+ * with no React reconciler or scheduler. Pass it as the `renderer` property on
638
+ * `defineGenerator`. Kubb core calls the factory once per render cycle and stays
639
+ * generic, with no hard dependency on `@kubb/renderer-jsx`.
525
640
  *
526
- * Pass this as the `renderer` property of a `defineGenerator` call so that
527
- * core can render the JSX element tree returned by your generator methods
528
- * without a hard dependency on `@kubb/renderer-jsx`.
641
+ * Every component must be a pure function. Hooks, suspense, and class
642
+ * components are not supported.
529
643
  *
530
- * @example
531
- * ```ts
532
- * import { jsxRenderer } from '@kubb/renderer-jsx'
644
+ * @example Wire up a JSX generator
645
+ * ```tsx
533
646
  * import { defineGenerator } from '@kubb/core'
647
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
534
648
  *
535
649
  * export const myGenerator = defineGenerator<PluginTs>({
536
- * name: 'my-generator',
650
+ * name: 'types',
537
651
  * renderer: jsxRenderer,
538
- * schema(node, options) {
539
- * return <File baseName="output.ts" path="src/output.ts">...</File>
652
+ * schema(node, ctx) {
653
+ * return (
654
+ * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
655
+ * <Type node={node} resolver={ctx.resolver} />
656
+ * </File>
657
+ * )
540
658
  * },
541
659
  * })
542
660
  * ```
543
661
  */
544
662
  declare const jsxRenderer: () => {
545
663
  render(element: KubbReactElement): Promise<void>;
546
- readonly files: _$_kubb_ast0.FileNode[];
547
- unmount(error?: Error | number | null): void;
664
+ readonly files: import("@kubb/ast").FileNode[];
665
+ [Symbol.dispose](): void;
548
666
  };
549
667
  //#endregion
550
- export { Const, File, Function, Jsx, Root, Type, createContext, inject, jsxRenderer, provide, unprovide };
668
+ export { Callout, Const, File, Frontmatter, Function, Heading, Jsx, List, Paragraph, Type, jsxRenderer };
551
669
  //# sourceMappingURL=index.d.ts.map