@kubb/renderer-jsx 5.0.0-beta.23 → 5.0.0-beta.25

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,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_jsx_runtime = require("./jsx-runtime-DdmO3p0U.cjs");
3
3
  const require_jsx_runtime$1 = require("./jsx-runtime.cjs");
4
+ let yaml = require("yaml");
4
5
  let _kubb_ast = require("@kubb/ast");
5
6
  //#region ../../internals/utils/src/context.ts
6
7
  /**
@@ -109,6 +110,64 @@ function onProcessExit(callback) {
109
110
  return unsubscribe;
110
111
  }
111
112
  //#endregion
113
+ //#region src/components/Callout.tsx
114
+ const CALLOUT_LABEL = {
115
+ tip: "TIP",
116
+ note: "NOTE",
117
+ important: "IMPORTANT",
118
+ warning: "WARNING",
119
+ caution: "CAUTION"
120
+ };
121
+ /**
122
+ * Renders a GitHub-style alert callout — portable across GitHub, GitLab,
123
+ * VitePress, Obsidian, and MDX.
124
+ *
125
+ * Emits a `<File.Source>` block containing `> [!TYPE] Title` followed by the
126
+ * body with every line prefixed by `> `.
127
+ *
128
+ * @example
129
+ * ```tsx
130
+ * <Callout type="tip">Run `kubb start --watch` to keep the generator hot.</Callout>
131
+ * // > [!TIP]
132
+ * // > Run `kubb start --watch` to keep the generator hot.
133
+ *
134
+ * <Callout type="warning" title="Heads up">Breaking change in v6.</Callout>
135
+ * // > [!WARNING] Heads up
136
+ * // > Breaking change in v6.
137
+ * ```
138
+ */
139
+ function Callout({ type, title, children }) {
140
+ const label = CALLOUT_LABEL[type];
141
+ return /* @__PURE__ */ require_jsx_runtime$1.jsx("kubb-source", {
142
+ name: "callout",
143
+ children: `${title ? `> [!${label}] ${title}` : `> [!${label}]`}\n${children.trimEnd().split("\n").map((line) => line.length > 0 ? `> ${line}` : ">").join("\n")}`
144
+ });
145
+ }
146
+ Callout.displayName = "Callout";
147
+ //#endregion
148
+ //#region src/components/CodeBlock.tsx
149
+ /**
150
+ * Renders a fenced markdown code block.
151
+ *
152
+ * Emits a `<File.Source>` block containing the children wrapped in
153
+ * triple-backtick fences with an optional language tag.
154
+ *
155
+ * @example
156
+ * ```tsx
157
+ * <CodeBlock lang="typescript">{'const pet = { id: 1 }'}</CodeBlock>
158
+ * // ```typescript
159
+ * // const pet = { id: 1 }
160
+ * // ```
161
+ * ```
162
+ */
163
+ function CodeBlock({ lang, children }) {
164
+ return /* @__PURE__ */ require_jsx_runtime$1.jsx("kubb-source", {
165
+ name: "codeBlock",
166
+ children: `\`\`\`${lang ?? ""}\n${children}\n\`\`\``
167
+ });
168
+ }
169
+ CodeBlock.displayName = "CodeBlock";
170
+ //#endregion
112
171
  //#region src/components/Const.tsx
113
172
  /**
114
173
  * Generates a TypeScript constant declaration.
@@ -263,6 +322,33 @@ File.Export = FileExport;
263
322
  File.Import = FileImport;
264
323
  File.Source = FileSource;
265
324
  //#endregion
325
+ //#region src/components/Frontmatter.tsx
326
+ /**
327
+ * Emits a YAML frontmatter envelope at the top of a generated markdown file.
328
+ *
329
+ * Renders a `<File.Source>` block containing `---\n<yaml>\n---`. Place it as
330
+ * the first child of `<File>` so it appears at the top of the output. Pair with
331
+ * `parserMd` to write `.md` files that downstream tooling (VitePress, MDX,
332
+ * static-site generators) treats as frontmatter.
333
+ *
334
+ * @example Page frontmatter at the top of a generated markdown file
335
+ * ```tsx
336
+ * <File baseName="pets.md" path="src/pets.md">
337
+ * <Frontmatter data={{ title: 'Pets', layout: 'doc' }} />
338
+ * <File.Source>
339
+ * {'# Pets\n\nList of pets.'}
340
+ * </File.Source>
341
+ * </File>
342
+ * ```
343
+ */
344
+ function Frontmatter({ data }) {
345
+ return /* @__PURE__ */ require_jsx_runtime$1.jsx("kubb-source", {
346
+ name: "frontmatter",
347
+ children: `---\n${(0, yaml.stringify)(data).trimEnd()}\n---`
348
+ });
349
+ }
350
+ Frontmatter.displayName = "Frontmatter";
351
+ //#endregion
266
352
  //#region src/components/Function.tsx
267
353
  /**
268
354
  * Generates a TypeScript function declaration.
@@ -324,6 +410,27 @@ function ArrowFunction({ children, ...props }) {
324
410
  ArrowFunction.displayName = "ArrowFunction";
325
411
  Function$1.Arrow = ArrowFunction;
326
412
  //#endregion
413
+ //#region src/components/Heading.tsx
414
+ /**
415
+ * Renders an ATX-style markdown heading.
416
+ *
417
+ * Emits a `<File.Source>` block containing `${'#'.repeat(level)} ${children}`.
418
+ * Use inside a `<File>` rendered by `parserMd`.
419
+ *
420
+ * @example
421
+ * ```tsx
422
+ * <Heading level={2}>Installation</Heading>
423
+ * // ## Installation
424
+ * ```
425
+ */
426
+ function Heading({ level, children }) {
427
+ return /* @__PURE__ */ require_jsx_runtime$1.jsx("kubb-source", {
428
+ name: "heading",
429
+ children: `${"#".repeat(level)} ${children}`
430
+ });
431
+ }
432
+ Heading.displayName = "Heading";
433
+ //#endregion
327
434
  //#region src/components/Jsx.tsx
328
435
  /**
329
436
  * Embeds a raw JSX string verbatim in the generated source code.
@@ -345,6 +452,53 @@ function Jsx({ children }) {
345
452
  }
346
453
  Jsx.displayName = "Jsx";
347
454
  //#endregion
455
+ //#region src/components/List.tsx
456
+ /**
457
+ * Renders a markdown list.
458
+ *
459
+ * Emits a `<File.Source>` block containing one entry per line, prefixed with
460
+ * `1.` / `2.` … when `ordered`, or `-` otherwise.
461
+ *
462
+ * @example
463
+ * ```tsx
464
+ * <List items={['Add the parser', 'Render the page']} />
465
+ * // - Add the parser
466
+ * // - Render the page
467
+ *
468
+ * <List ordered items={['First', 'Second']} />
469
+ * // 1. First
470
+ * // 2. Second
471
+ * ```
472
+ */
473
+ function List({ ordered, items }) {
474
+ return /* @__PURE__ */ require_jsx_runtime$1.jsx("kubb-source", {
475
+ name: "list",
476
+ children: items.map((item, index) => `${ordered ? `${index + 1}.` : "-"} ${item}`).join("\n")
477
+ });
478
+ }
479
+ List.displayName = "List";
480
+ //#endregion
481
+ //#region src/components/Paragraph.tsx
482
+ /**
483
+ * Renders a markdown paragraph.
484
+ *
485
+ * Emits a `<File.Source>` block containing the text as-is. Paragraphs are
486
+ * separated from surrounding blocks by blank lines via the parser's source
487
+ * joining.
488
+ *
489
+ * @example
490
+ * ```tsx
491
+ * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
492
+ * ```
493
+ */
494
+ function Paragraph({ children }) {
495
+ return /* @__PURE__ */ require_jsx_runtime$1.jsx("kubb-source", {
496
+ name: "paragraph",
497
+ children
498
+ });
499
+ }
500
+ Paragraph.displayName = "Paragraph";
501
+ //#endregion
348
502
  //#region src/components/Root.tsx
349
503
  var import_react = /* @__PURE__ */ require_jsx_runtime.__toESM(require_jsx_runtime.require_react());
350
504
  var ErrorBoundary = class extends import_react.Component {
@@ -18487,10 +18641,16 @@ const jsxRendererSync = () => {
18487
18641
  };
18488
18642
  };
18489
18643
  //#endregion
18644
+ exports.Callout = Callout;
18645
+ exports.CodeBlock = CodeBlock;
18490
18646
  exports.Const = Const;
18491
18647
  exports.File = File;
18648
+ exports.Frontmatter = Frontmatter;
18492
18649
  exports.Function = Function$1;
18650
+ exports.Heading = Heading;
18493
18651
  exports.Jsx = Jsx;
18652
+ exports.List = List;
18653
+ exports.Paragraph = Paragraph;
18494
18654
  exports.Root = Root;
18495
18655
  exports.Type = Type;
18496
18656
  exports.createContext = createContext;
package/dist/index.d.ts CHANGED
@@ -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;
@@ -143,7 +232,7 @@ type BasePropsWithoutBaseName = {
143
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.
@@ -184,7 +273,7 @@ type Props$2<TMeta> = BaseProps & {
184
273
  declare function File<TMeta extends object = object>({
185
274
  children,
186
275
  ...props
187
- }: Props$2<TMeta>): KubbReactElement;
276
+ }: Props$6<TMeta>): KubbReactElement;
188
277
  declare namespace File {
189
278
  var displayName: string;
190
279
  var Export: typeof FileExport;
@@ -280,8 +369,44 @@ declare namespace FileImport {
280
369
  var displayName: string;
281
370
  }
282
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
283
408
  //#region src/components/Function.d.ts
284
- type Props$1 = {
409
+ type Props$4 = {
285
410
  key?: Key;
286
411
  /**
287
412
  * Identifier of the generated function declaration.
@@ -362,12 +487,12 @@ type Props$1 = {
362
487
  declare function Function({
363
488
  children,
364
489
  ...props
365
- }: Props$1): KubbReactElement;
490
+ }: Props$4): KubbReactElement;
366
491
  declare namespace Function {
367
492
  var displayName: string;
368
493
  var Arrow: typeof ArrowFunction;
369
494
  }
370
- type ArrowFunctionProps = Props$1 & {
495
+ type ArrowFunctionProps = Props$4 & {
371
496
  /**
372
497
  * Render the arrow function as a single-line expression (no braces around the body).
373
498
  * - `true` generates `const name = (…) => expression`
@@ -397,8 +522,42 @@ declare namespace ArrowFunction {
397
522
  var displayName: string;
398
523
  }
399
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
400
559
  //#region src/components/Jsx.d.ts
401
- type Props = {
560
+ type Props$2 = {
402
561
  /**
403
562
  * Raw JSX string to embed verbatim in the generated code.
404
563
  * Supports JSX fragments (`<>…</>`), elements, and any valid JSX syntax.
@@ -426,11 +585,79 @@ type Props = {
426
585
  */
427
586
  declare function Jsx({
428
587
  children
429
- }: Props): KubbReactElement;
588
+ }: Props$2): KubbReactElement;
430
589
  declare namespace Jsx {
431
590
  var displayName: string;
432
591
  }
433
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
434
661
  //#region src/components/Root.d.ts
435
662
  type RootProps = {
436
663
  /**
@@ -603,5 +830,5 @@ declare const jsxRendererSync: () => {
603
830
  [Symbol.dispose](): void;
604
831
  };
605
832
  //#endregion
606
- export { Const, File, Function, Jsx, Root, Type, createContext, inject, jsxRenderer, jsxRendererSync, provide, unprovide };
833
+ export { Callout, CodeBlock, Const, File, Frontmatter, Function, Heading, Jsx, List, Paragraph, Root, Type, createContext, inject, jsxRenderer, jsxRendererSync, provide, unprovide };
607
834
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { n as __name, r as __toESM, t as __commonJSMin } from "./chunk-Bb7HlUDG.js";
2
2
  import { n as require_react } from "./jsx-runtime-Cvu_ZYgL.js";
3
3
  import { Fragment, jsx } from "./jsx-runtime.js";
4
+ import { stringify } from "yaml";
4
5
  import { createArrowFunction, createBreak, createConst, createExport, createFunction, createImport, createJsx, createSource, createText, createType } from "@kubb/ast";
5
6
  //#region ../../internals/utils/src/context.ts
6
7
  /**
@@ -109,6 +110,64 @@ function onProcessExit(callback) {
109
110
  return unsubscribe;
110
111
  }
111
112
  //#endregion
113
+ //#region src/components/Callout.tsx
114
+ const CALLOUT_LABEL = {
115
+ tip: "TIP",
116
+ note: "NOTE",
117
+ important: "IMPORTANT",
118
+ warning: "WARNING",
119
+ caution: "CAUTION"
120
+ };
121
+ /**
122
+ * Renders a GitHub-style alert callout — portable across GitHub, GitLab,
123
+ * VitePress, Obsidian, and MDX.
124
+ *
125
+ * Emits a `<File.Source>` block containing `> [!TYPE] Title` followed by the
126
+ * body with every line prefixed by `> `.
127
+ *
128
+ * @example
129
+ * ```tsx
130
+ * <Callout type="tip">Run `kubb start --watch` to keep the generator hot.</Callout>
131
+ * // > [!TIP]
132
+ * // > Run `kubb start --watch` to keep the generator hot.
133
+ *
134
+ * <Callout type="warning" title="Heads up">Breaking change in v6.</Callout>
135
+ * // > [!WARNING] Heads up
136
+ * // > Breaking change in v6.
137
+ * ```
138
+ */
139
+ function Callout({ type, title, children }) {
140
+ const label = CALLOUT_LABEL[type];
141
+ return /* @__PURE__ */ jsx("kubb-source", {
142
+ name: "callout",
143
+ children: `${title ? `> [!${label}] ${title}` : `> [!${label}]`}\n${children.trimEnd().split("\n").map((line) => line.length > 0 ? `> ${line}` : ">").join("\n")}`
144
+ });
145
+ }
146
+ Callout.displayName = "Callout";
147
+ //#endregion
148
+ //#region src/components/CodeBlock.tsx
149
+ /**
150
+ * Renders a fenced markdown code block.
151
+ *
152
+ * Emits a `<File.Source>` block containing the children wrapped in
153
+ * triple-backtick fences with an optional language tag.
154
+ *
155
+ * @example
156
+ * ```tsx
157
+ * <CodeBlock lang="typescript">{'const pet = { id: 1 }'}</CodeBlock>
158
+ * // ```typescript
159
+ * // const pet = { id: 1 }
160
+ * // ```
161
+ * ```
162
+ */
163
+ function CodeBlock({ lang, children }) {
164
+ return /* @__PURE__ */ jsx("kubb-source", {
165
+ name: "codeBlock",
166
+ children: `\`\`\`${lang ?? ""}\n${children}\n\`\`\``
167
+ });
168
+ }
169
+ CodeBlock.displayName = "CodeBlock";
170
+ //#endregion
112
171
  //#region src/components/Const.tsx
113
172
  /**
114
173
  * Generates a TypeScript constant declaration.
@@ -263,6 +322,33 @@ File.Export = FileExport;
263
322
  File.Import = FileImport;
264
323
  File.Source = FileSource;
265
324
  //#endregion
325
+ //#region src/components/Frontmatter.tsx
326
+ /**
327
+ * Emits a YAML frontmatter envelope at the top of a generated markdown file.
328
+ *
329
+ * Renders a `<File.Source>` block containing `---\n<yaml>\n---`. Place it as
330
+ * the first child of `<File>` so it appears at the top of the output. Pair with
331
+ * `parserMd` to write `.md` files that downstream tooling (VitePress, MDX,
332
+ * static-site generators) treats as frontmatter.
333
+ *
334
+ * @example Page frontmatter at the top of a generated markdown file
335
+ * ```tsx
336
+ * <File baseName="pets.md" path="src/pets.md">
337
+ * <Frontmatter data={{ title: 'Pets', layout: 'doc' }} />
338
+ * <File.Source>
339
+ * {'# Pets\n\nList of pets.'}
340
+ * </File.Source>
341
+ * </File>
342
+ * ```
343
+ */
344
+ function Frontmatter({ data }) {
345
+ return /* @__PURE__ */ jsx("kubb-source", {
346
+ name: "frontmatter",
347
+ children: `---\n${stringify(data).trimEnd()}\n---`
348
+ });
349
+ }
350
+ Frontmatter.displayName = "Frontmatter";
351
+ //#endregion
266
352
  //#region src/components/Function.tsx
267
353
  /**
268
354
  * Generates a TypeScript function declaration.
@@ -324,6 +410,27 @@ function ArrowFunction({ children, ...props }) {
324
410
  ArrowFunction.displayName = "ArrowFunction";
325
411
  Function$1.Arrow = ArrowFunction;
326
412
  //#endregion
413
+ //#region src/components/Heading.tsx
414
+ /**
415
+ * Renders an ATX-style markdown heading.
416
+ *
417
+ * Emits a `<File.Source>` block containing `${'#'.repeat(level)} ${children}`.
418
+ * Use inside a `<File>` rendered by `parserMd`.
419
+ *
420
+ * @example
421
+ * ```tsx
422
+ * <Heading level={2}>Installation</Heading>
423
+ * // ## Installation
424
+ * ```
425
+ */
426
+ function Heading({ level, children }) {
427
+ return /* @__PURE__ */ jsx("kubb-source", {
428
+ name: "heading",
429
+ children: `${"#".repeat(level)} ${children}`
430
+ });
431
+ }
432
+ Heading.displayName = "Heading";
433
+ //#endregion
327
434
  //#region src/components/Jsx.tsx
328
435
  /**
329
436
  * Embeds a raw JSX string verbatim in the generated source code.
@@ -345,6 +452,53 @@ function Jsx({ children }) {
345
452
  }
346
453
  Jsx.displayName = "Jsx";
347
454
  //#endregion
455
+ //#region src/components/List.tsx
456
+ /**
457
+ * Renders a markdown list.
458
+ *
459
+ * Emits a `<File.Source>` block containing one entry per line, prefixed with
460
+ * `1.` / `2.` … when `ordered`, or `-` otherwise.
461
+ *
462
+ * @example
463
+ * ```tsx
464
+ * <List items={['Add the parser', 'Render the page']} />
465
+ * // - Add the parser
466
+ * // - Render the page
467
+ *
468
+ * <List ordered items={['First', 'Second']} />
469
+ * // 1. First
470
+ * // 2. Second
471
+ * ```
472
+ */
473
+ function List({ ordered, items }) {
474
+ return /* @__PURE__ */ jsx("kubb-source", {
475
+ name: "list",
476
+ children: items.map((item, index) => `${ordered ? `${index + 1}.` : "-"} ${item}`).join("\n")
477
+ });
478
+ }
479
+ List.displayName = "List";
480
+ //#endregion
481
+ //#region src/components/Paragraph.tsx
482
+ /**
483
+ * Renders a markdown paragraph.
484
+ *
485
+ * Emits a `<File.Source>` block containing the text as-is. Paragraphs are
486
+ * separated from surrounding blocks by blank lines via the parser's source
487
+ * joining.
488
+ *
489
+ * @example
490
+ * ```tsx
491
+ * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
492
+ * ```
493
+ */
494
+ function Paragraph({ children }) {
495
+ return /* @__PURE__ */ jsx("kubb-source", {
496
+ name: "paragraph",
497
+ children
498
+ });
499
+ }
500
+ Paragraph.displayName = "Paragraph";
501
+ //#endregion
348
502
  //#region src/components/Root.tsx
349
503
  var import_react = /* @__PURE__ */ __toESM(require_react());
350
504
  var ErrorBoundary = class extends import_react.Component {
@@ -18484,6 +18638,6 @@ const jsxRendererSync = () => {
18484
18638
  };
18485
18639
  };
18486
18640
  //#endregion
18487
- export { Const, File, Function$1 as Function, Jsx, Root, Type, createContext, inject, jsxRenderer, jsxRendererSync, provide, unprovide };
18641
+ export { Callout, CodeBlock, Const, File, Frontmatter, Function$1 as Function, Heading, Jsx, List, Paragraph, Root, Type, createContext, inject, jsxRenderer, jsxRendererSync, provide, unprovide };
18488
18642
 
18489
18643
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.0.0-beta.23",
3
+ "version": "5.0.0-beta.25",
4
4
  "description": "JSX-based renderer for Kubb. Provides a custom React runtime, reconciler, and built-in components (File, Function, Type, Const) for component-based, type-safe code generation.",
5
5
  "keywords": [
6
6
  "codegen",
@@ -75,7 +75,8 @@
75
75
  "registry": "https://registry.npmjs.org/"
76
76
  },
77
77
  "dependencies": {
78
- "@kubb/ast": "5.0.0-beta.23"
78
+ "yaml": "^2.8.1",
79
+ "@kubb/ast": "5.0.0-beta.25"
79
80
  },
80
81
  "devDependencies": {
81
82
  "@types/react": "^19.2.14",
@@ -0,0 +1,59 @@
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 — portable across GitHub, GitLab,
32
+ * VitePress, Obsidian, and MDX.
33
+ *
34
+ * Emits a `<File.Source>` block containing `> [!TYPE] Title` followed by the
35
+ * body with every line prefixed by `> `.
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * <Callout type="tip">Run `kubb start --watch` to keep the generator hot.</Callout>
40
+ * // > [!TIP]
41
+ * // > Run `kubb start --watch` to keep the generator hot.
42
+ *
43
+ * <Callout type="warning" title="Heads up">Breaking change in v6.</Callout>
44
+ * // > [!WARNING] Heads up
45
+ * // > Breaking change in v6.
46
+ * ```
47
+ */
48
+ export function Callout({ type, title, children }: Props): KubbReactElement {
49
+ const label = CALLOUT_LABEL[type]
50
+ const header = title ? `> [!${label}] ${title}` : `> [!${label}]`
51
+ const quoted = children
52
+ .trimEnd()
53
+ .split('\n')
54
+ .map((line) => (line.length > 0 ? `> ${line}` : '>'))
55
+ .join('\n')
56
+ return <kubb-source name="callout">{`${header}\n${quoted}`}</kubb-source>
57
+ }
58
+
59
+ Callout.displayName = 'Callout'
@@ -0,0 +1,37 @@
1
+ import type { Key, KubbReactElement } from '../types.ts'
2
+
3
+ type Props = {
4
+ key?: Key
5
+ /**
6
+ * Language tag for syntax highlighting. Rendered after the opening fence.
7
+ *
8
+ * @example
9
+ * `lang: 'typescript'`
10
+ */
11
+ lang?: string
12
+ /**
13
+ * Code body. Wrapped in triple-backtick fences as-is.
14
+ */
15
+ children: string
16
+ }
17
+
18
+ /**
19
+ * Renders a fenced markdown code block.
20
+ *
21
+ * Emits a `<File.Source>` block containing the children wrapped in
22
+ * triple-backtick fences with an optional language tag.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <CodeBlock lang="typescript">{'const pet = { id: 1 }'}</CodeBlock>
27
+ * // ```typescript
28
+ * // const pet = { id: 1 }
29
+ * // ```
30
+ * ```
31
+ */
32
+ export function CodeBlock({ lang, children }: Props): KubbReactElement {
33
+ const fence = `\`\`\`${lang ?? ''}\n${children}\n\`\`\``
34
+ return <kubb-source name="codeBlock">{fence}</kubb-source>
35
+ }
36
+
37
+ CodeBlock.displayName = 'CodeBlock'
@@ -0,0 +1,38 @@
1
+ import { stringify } from 'yaml'
2
+ import type { Key, KubbReactElement } from '../types.ts'
3
+
4
+ type Props = {
5
+ key?: Key
6
+ /**
7
+ * Plain object serialised as YAML between `---` fences.
8
+ *
9
+ * @example
10
+ * `data: { title: 'Pets', layout: 'doc' }`
11
+ */
12
+ data: Record<string, unknown>
13
+ }
14
+
15
+ /**
16
+ * Emits a YAML frontmatter envelope at the top of a generated markdown file.
17
+ *
18
+ * Renders a `<File.Source>` block containing `---\n<yaml>\n---`. Place it as
19
+ * the first child of `<File>` so it appears at the top of the output. Pair with
20
+ * `parserMd` to write `.md` files that downstream tooling (VitePress, MDX,
21
+ * static-site generators) treats as frontmatter.
22
+ *
23
+ * @example Page frontmatter at the top of a generated markdown file
24
+ * ```tsx
25
+ * <File baseName="pets.md" path="src/pets.md">
26
+ * <Frontmatter data={{ title: 'Pets', layout: 'doc' }} />
27
+ * <File.Source>
28
+ * {'# Pets\n\nList of pets.'}
29
+ * </File.Source>
30
+ * </File>
31
+ * ```
32
+ */
33
+ export function Frontmatter({ data }: Props): KubbReactElement {
34
+ const envelope = `---\n${stringify(data).trimEnd()}\n---`
35
+ return <kubb-source name="frontmatter">{envelope}</kubb-source>
36
+ }
37
+
38
+ Frontmatter.displayName = 'Frontmatter'
@@ -0,0 +1,34 @@
1
+ import type { Key, KubbReactElement } from '../types.ts'
2
+
3
+ type Level = 1 | 2 | 3 | 4 | 5 | 6
4
+
5
+ type Props = {
6
+ key?: Key
7
+ /**
8
+ * Heading depth, `1` through `6`. Matches the number of `#` characters
9
+ * prefixed to the heading text.
10
+ */
11
+ level: Level
12
+ /**
13
+ * Heading text. Inline markdown (links, emphasis) is passed through verbatim.
14
+ */
15
+ children: string
16
+ }
17
+
18
+ /**
19
+ * Renders an ATX-style markdown heading.
20
+ *
21
+ * Emits a `<File.Source>` block containing `${'#'.repeat(level)} ${children}`.
22
+ * Use inside a `<File>` rendered by `parserMd`.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <Heading level={2}>Installation</Heading>
27
+ * // ## Installation
28
+ * ```
29
+ */
30
+ export function Heading({ level, children }: Props): KubbReactElement {
31
+ return <kubb-source name="heading">{`${'#'.repeat(level)} ${children}`}</kubb-source>
32
+ }
33
+
34
+ Heading.displayName = 'Heading'
@@ -0,0 +1,40 @@
1
+ import type { Key, KubbReactElement } from '../types.ts'
2
+
3
+ type Props = {
4
+ key?: Key
5
+ /**
6
+ * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
7
+ * emits a bullet list (`- …`).
8
+ *
9
+ * @default false
10
+ */
11
+ ordered?: boolean | null
12
+ /**
13
+ * One entry per line. Inline markdown is passed through verbatim.
14
+ */
15
+ items: ReadonlyArray<string>
16
+ }
17
+
18
+ /**
19
+ * Renders a markdown list.
20
+ *
21
+ * Emits a `<File.Source>` block containing one entry per line, prefixed with
22
+ * `1.` / `2.` … when `ordered`, or `-` otherwise.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <List items={['Add the parser', 'Render the page']} />
27
+ * // - Add the parser
28
+ * // - Render the page
29
+ *
30
+ * <List ordered items={['First', 'Second']} />
31
+ * // 1. First
32
+ * // 2. Second
33
+ * ```
34
+ */
35
+ export function List({ ordered, items }: Props): KubbReactElement {
36
+ const body = items.map((item, index) => `${ordered ? `${index + 1}.` : '-'} ${item}`).join('\n')
37
+ return <kubb-source name="list">{body}</kubb-source>
38
+ }
39
+
40
+ List.displayName = 'List'
@@ -0,0 +1,28 @@
1
+ import type { Key, KubbReactElement } from '../types.ts'
2
+
3
+ type Props = {
4
+ key?: Key
5
+ /**
6
+ * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
7
+ * through verbatim.
8
+ */
9
+ children: string
10
+ }
11
+
12
+ /**
13
+ * Renders a markdown paragraph.
14
+ *
15
+ * Emits a `<File.Source>` block containing the text as-is. Paragraphs are
16
+ * separated from surrounding blocks by blank lines via the parser's source
17
+ * joining.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
22
+ * ```
23
+ */
24
+ export function Paragraph({ children }: Props): KubbReactElement {
25
+ return <kubb-source name="paragraph">{children}</kubb-source>
26
+ }
27
+
28
+ Paragraph.displayName = 'Paragraph'
package/src/index.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  export { createContext, inject, provide, unprovide } from '@internals/utils'
2
+ export { Callout } from './components/Callout.tsx'
3
+ export { CodeBlock } from './components/CodeBlock.tsx'
2
4
  export { Const } from './components/Const.tsx'
3
5
  export { File } from './components/File.tsx'
6
+ export { Frontmatter } from './components/Frontmatter.tsx'
4
7
  export { Function } from './components/Function.tsx'
8
+ export { Heading } from './components/Heading.tsx'
5
9
  export { Jsx } from './components/Jsx.tsx'
10
+ export { List } from './components/List.tsx'
11
+ export { Paragraph } from './components/Paragraph.tsx'
6
12
  export { Root } from './components/Root.tsx'
7
13
  export { Type } from './components/Type.tsx'
8
14
  export { jsxRenderer, jsxRendererSync } from './createRenderer.tsx'