@kubb/renderer-jsx 5.0.0-beta.24 → 5.0.0-beta.26
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 +160 -0
- package/dist/index.d.ts +237 -10
- package/dist/index.js +155 -1
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/{jsx-namespace-BW3LepJB.d.ts → jsx-namespace-D_TStJE_.d.ts} +2 -2
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/{types-ChkUbtyQ.d.ts → types-Cur_nGCL.d.ts} +2 -2
- package/dist/types.d.ts +1 -1
- package/package.json +3 -2
- package/src/Runtime.tsx +1 -1
- package/src/SyncRuntime.tsx +11 -11
- package/src/components/Callout.tsx +59 -0
- package/src/components/CodeBlock.tsx +37 -0
- package/src/components/Frontmatter.tsx +38 -0
- package/src/components/Function.tsx +1 -1
- package/src/components/Heading.tsx +34 -0
- package/src/components/List.tsx +40 -0
- package/src/components/Paragraph.tsx +28 -0
- package/src/index.ts +6 -0
- package/src/types.ts +1 -1
- package/src/utils.ts +8 -8
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
|
@@ -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-
|
|
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;
|
|
@@ -143,7 +232,7 @@ type BasePropsWithoutBaseName = {
|
|
|
143
232
|
path?: string | null;
|
|
144
233
|
};
|
|
145
234
|
type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
|
|
146
|
-
type Props$
|
|
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$
|
|
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$
|
|
409
|
+
type Props$4 = {
|
|
285
410
|
key?: Key;
|
|
286
411
|
/**
|
|
287
412
|
* Identifier of the generated function declaration.
|
|
@@ -327,7 +452,7 @@ type Props$1 = {
|
|
|
327
452
|
* @example Multiple generics
|
|
328
453
|
* `generics: ['TData', 'TError = unknown']`
|
|
329
454
|
*/
|
|
330
|
-
generics?: string | string
|
|
455
|
+
generics?: string | Array<string> | null;
|
|
331
456
|
/**
|
|
332
457
|
* TypeScript return type annotation written verbatim after `:`.
|
|
333
458
|
* When `async` is `true`, the value is automatically wrapped in `Promise<…>`.
|
|
@@ -362,12 +487,12 @@ type Props$1 = {
|
|
|
362
487
|
declare function Function({
|
|
363
488
|
children,
|
|
364
489
|
...props
|
|
365
|
-
}: Props$
|
|
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$
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __name } from "./chunk-Bb7HlUDG.js";
|
|
2
|
-
import { h as KubbReactNode, m as KubbReactElement } from "./types-
|
|
3
|
-
import { t as JSX } from "./jsx-namespace-
|
|
2
|
+
import { h as KubbReactNode, m as KubbReactElement } from "./types-Cur_nGCL.js";
|
|
3
|
+
import { t as JSX } from "./jsx-namespace-D_TStJE_.js";
|
|
4
4
|
import * as _$react from "react";
|
|
5
5
|
import * as React$1 from "react/jsx-runtime";
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __name } from "./chunk-Bb7HlUDG.js";
|
|
2
|
-
import { _ as KubbTextProps, c as KubbConstProps, d as KubbFunctionProps, f as KubbImportProps, g as KubbSourceProps, h as KubbReactNode, l as KubbExportProps, m as KubbReactElement, p as KubbJsxProps, s as KubbArrowFunctionProps, u as KubbFileProps, v as KubbTypeProps, y as LineBreakProps } from "./types-
|
|
2
|
+
import { _ as KubbTextProps, c as KubbConstProps, d as KubbFunctionProps, f as KubbImportProps, g as KubbSourceProps, h as KubbReactNode, l as KubbExportProps, m as KubbReactElement, p as KubbJsxProps, s as KubbArrowFunctionProps, u as KubbFileProps, v as KubbTypeProps, y as LineBreakProps } from "./types-Cur_nGCL.js";
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
5
5
|
//#region src/jsx-namespace.d.ts
|
|
@@ -36,4 +36,4 @@ declare namespace JSX$1 {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
export { JSX$1 as t };
|
|
39
|
-
//# sourceMappingURL=jsx-namespace-
|
|
39
|
+
//# sourceMappingURL=jsx-namespace-D_TStJE_.d.ts.map
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __name } from "./chunk-Bb7HlUDG.js";
|
|
2
|
-
import { h as KubbReactNode, m as KubbReactElement } from "./types-
|
|
3
|
-
import { t as JSX } from "./jsx-namespace-
|
|
2
|
+
import { h as KubbReactNode, m as KubbReactElement } from "./types-Cur_nGCL.js";
|
|
3
|
+
import { t as JSX } from "./jsx-namespace-D_TStJE_.js";
|
|
4
4
|
import * as _$react from "react";
|
|
5
5
|
import * as React$1 from "react/jsx-runtime";
|
|
6
6
|
|
|
@@ -51,7 +51,7 @@ type DOMElement = {
|
|
|
51
51
|
/**
|
|
52
52
|
* Ordered list of child nodes attached to this element.
|
|
53
53
|
*/
|
|
54
|
-
childNodes: DOMNode
|
|
54
|
+
childNodes: Array<DOMNode>;
|
|
55
55
|
internal_transform?: OutputTransformer;
|
|
56
56
|
isStaticDirty?: boolean;
|
|
57
57
|
staticNode?: DOMElement;
|
|
@@ -166,4 +166,4 @@ type JSDoc = {
|
|
|
166
166
|
};
|
|
167
167
|
//#endregion
|
|
168
168
|
export { KubbTextProps as _, JSDoc as a, TextNode as b, KubbConstProps as c, KubbFunctionProps as d, KubbImportProps as f, KubbSourceProps as g, KubbReactNode as h, ElementNames as i, KubbExportProps as l, KubbReactElement as m, DOMNode as n, Key as o, KubbJsxProps as p, DOMNodeAttribute as r, KubbArrowFunctionProps as s, DOMElement as t, KubbFileProps as u, KubbTypeProps as v, LineBreakProps as y };
|
|
169
|
-
//# sourceMappingURL=types-
|
|
169
|
+
//# sourceMappingURL=types-Cur_nGCL.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as KubbTextProps, a as JSDoc, b as TextNode, c as KubbConstProps, d as KubbFunctionProps, f as KubbImportProps, g as KubbSourceProps, h as KubbReactNode, i as ElementNames, l as KubbExportProps, m as KubbReactElement, n as DOMNode, o as Key, p as KubbJsxProps, r as DOMNodeAttribute, s as KubbArrowFunctionProps, t as DOMElement, u as KubbFileProps, v as KubbTypeProps, y as LineBreakProps } from "./types-
|
|
1
|
+
import { _ as KubbTextProps, a as JSDoc, b as TextNode, c as KubbConstProps, d as KubbFunctionProps, f as KubbImportProps, g as KubbSourceProps, h as KubbReactNode, i as ElementNames, l as KubbExportProps, m as KubbReactElement, n as DOMNode, o as Key, p as KubbJsxProps, r as DOMNodeAttribute, s as KubbArrowFunctionProps, t as DOMElement, u as KubbFileProps, v as KubbTypeProps, y as LineBreakProps } from "./types-Cur_nGCL.js";
|
|
2
2
|
export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, JSDoc, Key, KubbArrowFunctionProps, KubbConstProps, KubbExportProps, KubbFileProps, KubbFunctionProps, KubbImportProps, KubbJsxProps, KubbReactElement, KubbReactNode, KubbSourceProps, KubbTextProps, KubbTypeProps, LineBreakProps, TextNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/renderer-jsx",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.26",
|
|
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
|
-
"
|
|
78
|
+
"yaml": "^2.9.0",
|
|
79
|
+
"@kubb/ast": "5.0.0-beta.26"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
82
|
"@types/react": "^19.2.14",
|
package/src/Runtime.tsx
CHANGED
package/src/SyncRuntime.tsx
CHANGED
|
@@ -60,13 +60,13 @@ function toBool(val: unknown): boolean {
|
|
|
60
60
|
return (val ?? false) as boolean
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function collectCodeNodes(props: Record<string, unknown>): CodeNode
|
|
64
|
-
const nodes: CodeNode
|
|
63
|
+
function collectCodeNodes(props: Record<string, unknown>): Array<CodeNode> {
|
|
64
|
+
const nodes: Array<CodeNode> = []
|
|
65
65
|
collectCode(props['children'], nodes)
|
|
66
66
|
return nodes
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function collectCode(element: unknown, nodes: CodeNode
|
|
69
|
+
function collectCode(element: unknown, nodes: Array<CodeNode>): void {
|
|
70
70
|
walkElement(
|
|
71
71
|
element,
|
|
72
72
|
(text) => {
|
|
@@ -76,7 +76,7 @@ function collectCode(element: unknown, nodes: CodeNode[]): void {
|
|
|
76
76
|
)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function resolveCodeNode(type: string, props: Record<string, unknown>, nodes: CodeNode
|
|
79
|
+
function resolveCodeNode(type: string, props: Record<string, unknown>, nodes: Array<CodeNode>): void {
|
|
80
80
|
if (type === 'br') {
|
|
81
81
|
nodes.push(createBreak())
|
|
82
82
|
return
|
|
@@ -103,7 +103,7 @@ function resolveCodeNode(type: string, props: Record<string, unknown>, nodes: Co
|
|
|
103
103
|
export: props['export'] as boolean | null | undefined,
|
|
104
104
|
default: props['default'] as boolean | null | undefined,
|
|
105
105
|
async: props['async'] as boolean | null | undefined,
|
|
106
|
-
generics: props['generics'] as string | string
|
|
106
|
+
generics: props['generics'] as string | Array<string> | null | undefined,
|
|
107
107
|
returnType: props['returnType'] as string | null | undefined,
|
|
108
108
|
JSDoc: props['JSDoc'] as JSDocNode | null | undefined,
|
|
109
109
|
nodes: collectCodeNodes(props),
|
|
@@ -120,7 +120,7 @@ function resolveCodeNode(type: string, props: Record<string, unknown>, nodes: Co
|
|
|
120
120
|
export: props['export'] as boolean | null | undefined,
|
|
121
121
|
default: props['default'] as boolean | null | undefined,
|
|
122
122
|
async: props['async'] as boolean | null | undefined,
|
|
123
|
-
generics: props['generics'] as string | string
|
|
123
|
+
generics: props['generics'] as string | Array<string> | null | undefined,
|
|
124
124
|
returnType: props['returnType'] as string | null | undefined,
|
|
125
125
|
singleLine: props['singleLine'] as boolean | null | undefined,
|
|
126
126
|
JSDoc: props['JSDoc'] as JSDocNode | null | undefined,
|
|
@@ -157,12 +157,12 @@ function resolveCodeNode(type: string, props: Record<string, unknown>, nodes: Co
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
type FileChildren = { sources: SourceNode
|
|
160
|
+
type FileChildren = { sources: Array<SourceNode>; exports: Array<ExportNode>; imports: Array<ImportNode> }
|
|
161
161
|
|
|
162
162
|
function collectFileChildren(element: unknown): FileChildren {
|
|
163
|
-
const sources: SourceNode
|
|
164
|
-
const exports: ExportNode
|
|
165
|
-
const imports: ImportNode
|
|
163
|
+
const sources: Array<SourceNode> = []
|
|
164
|
+
const exports: Array<ExportNode> = []
|
|
165
|
+
const imports: Array<ImportNode> = []
|
|
166
166
|
|
|
167
167
|
walkElement(
|
|
168
168
|
element,
|
|
@@ -278,7 +278,7 @@ export class SyncRuntime {
|
|
|
278
278
|
/**
|
|
279
279
|
* Accumulated {@link FileNode} results from every {@link render} call.
|
|
280
280
|
*/
|
|
281
|
-
nodes: FileNode
|
|
281
|
+
nodes: Array<FileNode> = []
|
|
282
282
|
|
|
283
283
|
/**
|
|
284
284
|
* Walks `element` synchronously, converts every `<kubb-file>` subtree into
|
|
@@ -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'
|
|
@@ -46,7 +46,7 @@ type Props = {
|
|
|
46
46
|
* @example Multiple generics
|
|
47
47
|
* `generics: ['TData', 'TError = unknown']`
|
|
48
48
|
*/
|
|
49
|
-
generics?: string | string
|
|
49
|
+
generics?: string | Array<string> | null
|
|
50
50
|
/**
|
|
51
51
|
* TypeScript return type annotation written verbatim after `:`.
|
|
52
52
|
* When `async` is `true`, the value is automatically wrapped in `Promise<…>`.
|
|
@@ -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'
|
package/src/types.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -37,8 +37,8 @@ function toBool(val: unknown): boolean {
|
|
|
37
37
|
* `kubb-type`, and similar elements are converted into their respective {@link CodeNode}s.
|
|
38
38
|
* Any unrecognized element names are silently skipped.
|
|
39
39
|
*/
|
|
40
|
-
function collectCodeNodes(element: DOMElement): CodeNode
|
|
41
|
-
const result: CodeNode
|
|
40
|
+
function collectCodeNodes(element: DOMElement): Array<CodeNode> {
|
|
41
|
+
const result: Array<CodeNode> = []
|
|
42
42
|
|
|
43
43
|
for (const child of element.childNodes) {
|
|
44
44
|
if (!child) continue
|
|
@@ -63,7 +63,7 @@ function collectCodeNodes(element: DOMElement): CodeNode[] {
|
|
|
63
63
|
export: attrs['export'] as boolean | null | undefined,
|
|
64
64
|
default: attrs['default'] as boolean | null | undefined,
|
|
65
65
|
async: attrs['async'] as boolean | null | undefined,
|
|
66
|
-
generics: attrs['generics'] as string | string
|
|
66
|
+
generics: attrs['generics'] as string | Array<string> | null | undefined,
|
|
67
67
|
returnType: attrs['returnType'] as string | null | undefined,
|
|
68
68
|
JSDoc: attrs['JSDoc'] as JSDocNode | null | undefined,
|
|
69
69
|
nodes: collectCodeNodes(child),
|
|
@@ -81,7 +81,7 @@ function collectCodeNodes(element: DOMElement): CodeNode[] {
|
|
|
81
81
|
export: attrs['export'] as boolean | null | undefined,
|
|
82
82
|
default: attrs['default'] as boolean | null | undefined,
|
|
83
83
|
async: attrs['async'] as boolean | null | undefined,
|
|
84
|
-
generics: attrs['generics'] as string | string
|
|
84
|
+
generics: attrs['generics'] as string | Array<string> | null | undefined,
|
|
85
85
|
returnType: attrs['returnType'] as string | null | undefined,
|
|
86
86
|
singleLine: attrs['singleLine'] as boolean | null | undefined,
|
|
87
87
|
JSDoc: attrs['JSDoc'] as JSDocNode | null | undefined,
|
|
@@ -187,9 +187,9 @@ function* collectFileEntries(node: DOMElement): Generator<SourceNode | ExportNod
|
|
|
187
187
|
* node by its `.kind`.
|
|
188
188
|
*/
|
|
189
189
|
function createFileNode(child: DOMElement): FileNode {
|
|
190
|
-
const sources: SourceNode
|
|
191
|
-
const exports: ExportNode
|
|
192
|
-
const imports: ImportNode
|
|
190
|
+
const sources: Array<SourceNode> = []
|
|
191
|
+
const exports: Array<ExportNode> = []
|
|
192
|
+
const imports: Array<ImportNode> = []
|
|
193
193
|
|
|
194
194
|
for (const node of collectFileEntries(child)) {
|
|
195
195
|
if (node.kind === 'Source') {
|
|
@@ -241,6 +241,6 @@ export function* streamFiles(node: DOMElement): Generator<FileNode> {
|
|
|
241
241
|
* Returns the list of file nodes in document order. Nested files are supported;
|
|
242
242
|
* the walker descends into non-file elements and recurses through them.
|
|
243
243
|
*/
|
|
244
|
-
export function collectFiles(node: DOMElement): FileNode
|
|
244
|
+
export function collectFiles(node: DOMElement): Array<FileNode> {
|
|
245
245
|
return [...streamFiles(node)]
|
|
246
246
|
}
|