@kubb/renderer-jsx 5.22.0 → 5.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +40 -1
- package/dist/index.d.cts +42 -16
- package/dist/index.d.ts +42 -16
- package/dist/index.js +41 -3
- package/dist/jsx-runtime.d.cts +4 -0
- package/dist/jsx-runtime.d.ts +4 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -86,6 +86,8 @@ function File({ children, ...props }) {
|
|
|
86
86
|
/**
|
|
87
87
|
* Marks a block of source text to be associated with the enclosing {@link File}.
|
|
88
88
|
*
|
|
89
|
+
* @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
|
|
90
|
+
*
|
|
89
91
|
* Children are treated as the source string. `isExportable` marks the source as an exported declaration,
|
|
90
92
|
* `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
|
|
91
93
|
*
|
|
@@ -157,6 +159,7 @@ function FileImport(props) {
|
|
|
157
159
|
}
|
|
158
160
|
File.Export = FileExport;
|
|
159
161
|
File.Import = FileImport;
|
|
162
|
+
/** @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6. */
|
|
160
163
|
File.Source = FileSource;
|
|
161
164
|
// src/components/md/Frontmatter.tsx
|
|
162
165
|
/**
|
|
@@ -293,6 +296,27 @@ function List({ ordered, items }) {
|
|
|
293
296
|
function Paragraph({ children }) {
|
|
294
297
|
return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", { children });
|
|
295
298
|
}
|
|
299
|
+
// src/components/Schema.tsx
|
|
300
|
+
/**
|
|
301
|
+
* Prints `node`, adds the printer's imports, and renders `children` with the code. Renders nothing when the printer returns nothing.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```tsx
|
|
305
|
+
* <Schema node={node} printer={printer}>{(code) => <Const export name="petSchema">{code}</Const>}</Schema>
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
function Schema({ node, printer, children }) {
|
|
309
|
+
const output = printer.print(node);
|
|
310
|
+
const imports = printer.drainImports();
|
|
311
|
+
if (!output) return null;
|
|
312
|
+
return /* @__PURE__ */ require_jsx_runtime.jsxs(require_jsx_runtime.Fragment, { children: [imports.map((imp) => /* @__PURE__ */ require_jsx_runtime.jsx(File.Import, {
|
|
313
|
+
name: imp.name,
|
|
314
|
+
path: imp.path,
|
|
315
|
+
root: imp.root,
|
|
316
|
+
isTypeOnly: imp.isTypeOnly,
|
|
317
|
+
isNameSpace: imp.isNameSpace
|
|
318
|
+
}, [imp.path, imp.name].join("-"))), children(output)] });
|
|
319
|
+
}
|
|
296
320
|
// src/components/js/Type.tsx
|
|
297
321
|
/**
|
|
298
322
|
* Generates a TypeScript type alias declaration.
|
|
@@ -365,7 +389,7 @@ function isCodeHost(host) {
|
|
|
365
389
|
return host.type in codeFactories;
|
|
366
390
|
}
|
|
367
391
|
function createCodeNode(type, props) {
|
|
368
|
-
const { children, ...rest } = props;
|
|
392
|
+
const { children, inline: _inline, ...rest } = props;
|
|
369
393
|
return codeFactories[type]({
|
|
370
394
|
...rest,
|
|
371
395
|
nodes: collectCodeNodes(children)
|
|
@@ -433,6 +457,20 @@ function collectFileChildren(element) {
|
|
|
433
457
|
}));
|
|
434
458
|
return;
|
|
435
459
|
}
|
|
460
|
+
if (isCodeHost(host)) {
|
|
461
|
+
const { name, export: canExport, inline } = host.props;
|
|
462
|
+
const isDefault = "default" in host.props && !!host.props.default;
|
|
463
|
+
const node = createCodeNode(host.type, host.props);
|
|
464
|
+
sources.push(_kubb_ast.ast.factory.createSource({
|
|
465
|
+
name,
|
|
466
|
+
isTypeOnly: host.type === "kubb-type",
|
|
467
|
+
isExportable: !!canExport,
|
|
468
|
+
isIndexable: !!canExport && !isDefault,
|
|
469
|
+
...inline && "nodes" in node ? { inline: { expression: _kubb_ast.ast.node.getText(node.nodes) } } : {},
|
|
470
|
+
nodes: [node]
|
|
471
|
+
}));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
436
474
|
const nested = collectFileChildren(childrenOf(host));
|
|
437
475
|
sources.push(...nested.sources);
|
|
438
476
|
exports.push(...nested.exports);
|
|
@@ -513,6 +551,7 @@ exports.Heading = Heading;
|
|
|
513
551
|
exports.Jsx = Jsx;
|
|
514
552
|
exports.List = List;
|
|
515
553
|
exports.Paragraph = Paragraph;
|
|
554
|
+
exports.Schema = Schema;
|
|
516
555
|
exports.Type = Type;
|
|
517
556
|
exports.jsxRenderer = jsxRenderer;
|
|
518
557
|
|
package/dist/index.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ declare const CALLOUT_LABEL: {
|
|
|
8
8
|
readonly caution: 'CAUTION';
|
|
9
9
|
};
|
|
10
10
|
type CalloutType = keyof typeof CALLOUT_LABEL;
|
|
11
|
-
type Props$
|
|
11
|
+
type Props$8 = {
|
|
12
12
|
key?: Key;
|
|
13
13
|
/**
|
|
14
14
|
* Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
|
|
@@ -41,9 +41,11 @@ type Props$7 = {
|
|
|
41
41
|
* // > Breaking change in v6.
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
export declare function Callout({ type, title, children }: Props$
|
|
44
|
+
export declare function Callout({ type, title, children }: Props$8): KubbReactElement;
|
|
45
45
|
type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
|
|
46
46
|
key?: Key;
|
|
47
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
48
|
+
inline?: boolean;
|
|
47
49
|
/**
|
|
48
50
|
* Child nodes rendered as the initializer expression of the constant.
|
|
49
51
|
*/
|
|
@@ -78,7 +80,7 @@ type BasePropsWithoutBaseName = {
|
|
|
78
80
|
path?: string | null;
|
|
79
81
|
};
|
|
80
82
|
type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
|
|
81
|
-
type Props$
|
|
83
|
+
type Props$7<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy'> & {
|
|
82
84
|
key?: Key;
|
|
83
85
|
/**
|
|
84
86
|
* Arbitrary metadata attached to the file node for plugins to read.
|
|
@@ -105,7 +107,7 @@ type Props$6<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, '
|
|
|
105
107
|
* </File>
|
|
106
108
|
* ```
|
|
107
109
|
*/
|
|
108
|
-
export declare function File<TMeta extends object = object>({ children, ...props }: Props$
|
|
110
|
+
export declare function File<TMeta extends object = object>({ children, ...props }: Props$7<TMeta>): KubbReactElement;
|
|
109
111
|
export declare namespace File {
|
|
110
112
|
export { FileExport as Export };
|
|
111
113
|
export { FileImport as Import };
|
|
@@ -121,6 +123,8 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value'> & {
|
|
|
121
123
|
/**
|
|
122
124
|
* Marks a block of source text to be associated with the enclosing {@link File}.
|
|
123
125
|
*
|
|
126
|
+
* @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
|
|
127
|
+
*
|
|
124
128
|
* Children are treated as the source string. `isExportable` marks the source as an exported declaration,
|
|
125
129
|
* `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
|
|
126
130
|
*
|
|
@@ -187,7 +191,7 @@ type FileImportProps = Omit<ast.ImportNode, 'kind'> & {
|
|
|
187
191
|
* ```
|
|
188
192
|
*/
|
|
189
193
|
declare function FileImport(props: FileImportProps): KubbReactElement;
|
|
190
|
-
type Props$
|
|
194
|
+
type Props$6 = {
|
|
191
195
|
key?: Key;
|
|
192
196
|
/**
|
|
193
197
|
* Plain object serialized as YAML between `---` fences.
|
|
@@ -214,9 +218,11 @@ type Props$5 = {
|
|
|
214
218
|
* </File>
|
|
215
219
|
* ```
|
|
216
220
|
*/
|
|
217
|
-
export declare function Frontmatter({ data }: Props$
|
|
218
|
-
type Props$
|
|
221
|
+
export declare function Frontmatter({ data }: Props$6): KubbReactElement;
|
|
222
|
+
type Props$5 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
|
|
219
223
|
key?: Key;
|
|
224
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
225
|
+
inline?: boolean;
|
|
220
226
|
/**
|
|
221
227
|
* Child nodes rendered as the body of the function.
|
|
222
228
|
*/
|
|
@@ -235,12 +241,14 @@ type Props$4 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
|
|
|
235
241
|
* // }
|
|
236
242
|
* ```
|
|
237
243
|
*/
|
|
238
|
-
export declare function Function({ children, ...props }: Props$
|
|
244
|
+
export declare function Function({ children, ...props }: Props$5): KubbReactElement;
|
|
239
245
|
export declare namespace Function {
|
|
240
246
|
export { ArrowFunction as Arrow };
|
|
241
247
|
}
|
|
242
248
|
type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
|
|
243
249
|
key?: Key;
|
|
250
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
251
|
+
inline?: boolean;
|
|
244
252
|
/**
|
|
245
253
|
* Child nodes rendered as the body of the function.
|
|
246
254
|
*/
|
|
@@ -261,7 +269,7 @@ type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
|
|
|
261
269
|
*/
|
|
262
270
|
declare function ArrowFunction({ children, ...props }: ArrowFunctionProps): KubbReactElement;
|
|
263
271
|
type Level = 1 | 2 | 3 | 4 | 5 | 6;
|
|
264
|
-
type Props$
|
|
272
|
+
type Props$4 = {
|
|
265
273
|
key?: Key;
|
|
266
274
|
/**
|
|
267
275
|
* Heading depth, `1` through `6`. Matches the number of `#` characters
|
|
@@ -285,8 +293,8 @@ type Props$3 = {
|
|
|
285
293
|
* // ## Installation
|
|
286
294
|
* ```
|
|
287
295
|
*/
|
|
288
|
-
export declare function Heading({ level, children }: Props$
|
|
289
|
-
type Props$
|
|
296
|
+
export declare function Heading({ level, children }: Props$4): KubbReactElement;
|
|
297
|
+
type Props$3 = {
|
|
290
298
|
key?: Key;
|
|
291
299
|
/**
|
|
292
300
|
* Raw JSX string embedded verbatim in the generated code, including
|
|
@@ -314,8 +322,8 @@ type Props$2 = {
|
|
|
314
322
|
* </Function>
|
|
315
323
|
* ```
|
|
316
324
|
*/
|
|
317
|
-
export declare function Jsx({ children }: Props$
|
|
318
|
-
type Props$
|
|
325
|
+
export declare function Jsx({ children }: Props$3): KubbReactElement;
|
|
326
|
+
type Props$2 = {
|
|
319
327
|
key?: Key;
|
|
320
328
|
/**
|
|
321
329
|
* When `true`, emits a numbered list (`1. …`). When `false` or omitted,
|
|
@@ -346,8 +354,8 @@ type Props$1 = {
|
|
|
346
354
|
* // 2. Second
|
|
347
355
|
* ```
|
|
348
356
|
*/
|
|
349
|
-
export declare function List({ ordered, items }: Props$
|
|
350
|
-
type Props = {
|
|
357
|
+
export declare function List({ ordered, items }: Props$2): KubbReactElement;
|
|
358
|
+
type Props$1 = {
|
|
351
359
|
key?: Key;
|
|
352
360
|
/**
|
|
353
361
|
* Paragraph text. Inline markdown (links, emphasis, code spans) is passed
|
|
@@ -367,9 +375,27 @@ type Props = {
|
|
|
367
375
|
* <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
|
|
368
376
|
* ```
|
|
369
377
|
*/
|
|
370
|
-
export declare function Paragraph({ children }: Props): KubbReactElement;
|
|
378
|
+
export declare function Paragraph({ children }: Props$1): KubbReactElement;
|
|
379
|
+
type Props<TOutput> = {
|
|
380
|
+
node: ast.SchemaNode;
|
|
381
|
+
printer: Pick<ast.Printer, 'drainImports'> & {
|
|
382
|
+
print: (node: ast.SchemaNode) => TOutput | null;
|
|
383
|
+
};
|
|
384
|
+
children: (output: NonNullable<TOutput>) => KubbReactNode;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* Prints `node`, adds the printer's imports, and renders `children` with the code. Renders nothing when the printer returns nothing.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```tsx
|
|
391
|
+
* <Schema node={node} printer={printer}>{(code) => <Const export name="petSchema">{code}</Const>}</Schema>
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
export declare function Schema<TOutput>({ node, printer, children }: Props<TOutput>): KubbReactElement | null;
|
|
371
395
|
type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
|
|
372
396
|
key?: Key;
|
|
397
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
398
|
+
inline?: boolean;
|
|
373
399
|
/**
|
|
374
400
|
* Child nodes rendered as the type expression on the right-hand side of the alias.
|
|
375
401
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare const CALLOUT_LABEL: {
|
|
|
8
8
|
readonly caution: 'CAUTION';
|
|
9
9
|
};
|
|
10
10
|
type CalloutType = keyof typeof CALLOUT_LABEL;
|
|
11
|
-
type Props$
|
|
11
|
+
type Props$8 = {
|
|
12
12
|
key?: Key;
|
|
13
13
|
/**
|
|
14
14
|
* Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
|
|
@@ -41,9 +41,11 @@ type Props$7 = {
|
|
|
41
41
|
* // > Breaking change in v6.
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
export declare function Callout({ type, title, children }: Props$
|
|
44
|
+
export declare function Callout({ type, title, children }: Props$8): KubbReactElement;
|
|
45
45
|
type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
|
|
46
46
|
key?: Key;
|
|
47
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
48
|
+
inline?: boolean;
|
|
47
49
|
/**
|
|
48
50
|
* Child nodes rendered as the initializer expression of the constant.
|
|
49
51
|
*/
|
|
@@ -78,7 +80,7 @@ type BasePropsWithoutBaseName = {
|
|
|
78
80
|
path?: string | null;
|
|
79
81
|
};
|
|
80
82
|
type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
|
|
81
|
-
type Props$
|
|
83
|
+
type Props$7<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy'> & {
|
|
82
84
|
key?: Key;
|
|
83
85
|
/**
|
|
84
86
|
* Arbitrary metadata attached to the file node for plugins to read.
|
|
@@ -105,7 +107,7 @@ type Props$6<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, '
|
|
|
105
107
|
* </File>
|
|
106
108
|
* ```
|
|
107
109
|
*/
|
|
108
|
-
export declare function File<TMeta extends object = object>({ children, ...props }: Props$
|
|
110
|
+
export declare function File<TMeta extends object = object>({ children, ...props }: Props$7<TMeta>): KubbReactElement;
|
|
109
111
|
export declare namespace File {
|
|
110
112
|
export { FileExport as Export };
|
|
111
113
|
export { FileImport as Import };
|
|
@@ -121,6 +123,8 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value'> & {
|
|
|
121
123
|
/**
|
|
122
124
|
* Marks a block of source text to be associated with the enclosing {@link File}.
|
|
123
125
|
*
|
|
126
|
+
* @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
|
|
127
|
+
*
|
|
124
128
|
* Children are treated as the source string. `isExportable` marks the source as an exported declaration,
|
|
125
129
|
* `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
|
|
126
130
|
*
|
|
@@ -187,7 +191,7 @@ type FileImportProps = Omit<ast.ImportNode, 'kind'> & {
|
|
|
187
191
|
* ```
|
|
188
192
|
*/
|
|
189
193
|
declare function FileImport(props: FileImportProps): KubbReactElement;
|
|
190
|
-
type Props$
|
|
194
|
+
type Props$6 = {
|
|
191
195
|
key?: Key;
|
|
192
196
|
/**
|
|
193
197
|
* Plain object serialized as YAML between `---` fences.
|
|
@@ -214,9 +218,11 @@ type Props$5 = {
|
|
|
214
218
|
* </File>
|
|
215
219
|
* ```
|
|
216
220
|
*/
|
|
217
|
-
export declare function Frontmatter({ data }: Props$
|
|
218
|
-
type Props$
|
|
221
|
+
export declare function Frontmatter({ data }: Props$6): KubbReactElement;
|
|
222
|
+
type Props$5 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
|
|
219
223
|
key?: Key;
|
|
224
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
225
|
+
inline?: boolean;
|
|
220
226
|
/**
|
|
221
227
|
* Child nodes rendered as the body of the function.
|
|
222
228
|
*/
|
|
@@ -235,12 +241,14 @@ type Props$4 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
|
|
|
235
241
|
* // }
|
|
236
242
|
* ```
|
|
237
243
|
*/
|
|
238
|
-
export declare function Function({ children, ...props }: Props$
|
|
244
|
+
export declare function Function({ children, ...props }: Props$5): KubbReactElement;
|
|
239
245
|
export declare namespace Function {
|
|
240
246
|
export { ArrowFunction as Arrow };
|
|
241
247
|
}
|
|
242
248
|
type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
|
|
243
249
|
key?: Key;
|
|
250
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
251
|
+
inline?: boolean;
|
|
244
252
|
/**
|
|
245
253
|
* Child nodes rendered as the body of the function.
|
|
246
254
|
*/
|
|
@@ -261,7 +269,7 @@ type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
|
|
|
261
269
|
*/
|
|
262
270
|
declare function ArrowFunction({ children, ...props }: ArrowFunctionProps): KubbReactElement;
|
|
263
271
|
type Level = 1 | 2 | 3 | 4 | 5 | 6;
|
|
264
|
-
type Props$
|
|
272
|
+
type Props$4 = {
|
|
265
273
|
key?: Key;
|
|
266
274
|
/**
|
|
267
275
|
* Heading depth, `1` through `6`. Matches the number of `#` characters
|
|
@@ -285,8 +293,8 @@ type Props$3 = {
|
|
|
285
293
|
* // ## Installation
|
|
286
294
|
* ```
|
|
287
295
|
*/
|
|
288
|
-
export declare function Heading({ level, children }: Props$
|
|
289
|
-
type Props$
|
|
296
|
+
export declare function Heading({ level, children }: Props$4): KubbReactElement;
|
|
297
|
+
type Props$3 = {
|
|
290
298
|
key?: Key;
|
|
291
299
|
/**
|
|
292
300
|
* Raw JSX string embedded verbatim in the generated code, including
|
|
@@ -314,8 +322,8 @@ type Props$2 = {
|
|
|
314
322
|
* </Function>
|
|
315
323
|
* ```
|
|
316
324
|
*/
|
|
317
|
-
export declare function Jsx({ children }: Props$
|
|
318
|
-
type Props$
|
|
325
|
+
export declare function Jsx({ children }: Props$3): KubbReactElement;
|
|
326
|
+
type Props$2 = {
|
|
319
327
|
key?: Key;
|
|
320
328
|
/**
|
|
321
329
|
* When `true`, emits a numbered list (`1. …`). When `false` or omitted,
|
|
@@ -346,8 +354,8 @@ type Props$1 = {
|
|
|
346
354
|
* // 2. Second
|
|
347
355
|
* ```
|
|
348
356
|
*/
|
|
349
|
-
export declare function List({ ordered, items }: Props$
|
|
350
|
-
type Props = {
|
|
357
|
+
export declare function List({ ordered, items }: Props$2): KubbReactElement;
|
|
358
|
+
type Props$1 = {
|
|
351
359
|
key?: Key;
|
|
352
360
|
/**
|
|
353
361
|
* Paragraph text. Inline markdown (links, emphasis, code spans) is passed
|
|
@@ -367,9 +375,27 @@ type Props = {
|
|
|
367
375
|
* <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
|
|
368
376
|
* ```
|
|
369
377
|
*/
|
|
370
|
-
export declare function Paragraph({ children }: Props): KubbReactElement;
|
|
378
|
+
export declare function Paragraph({ children }: Props$1): KubbReactElement;
|
|
379
|
+
type Props<TOutput> = {
|
|
380
|
+
node: ast.SchemaNode;
|
|
381
|
+
printer: Pick<ast.Printer, 'drainImports'> & {
|
|
382
|
+
print: (node: ast.SchemaNode) => TOutput | null;
|
|
383
|
+
};
|
|
384
|
+
children: (output: NonNullable<TOutput>) => KubbReactNode;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* Prints `node`, adds the printer's imports, and renders `children` with the code. Renders nothing when the printer returns nothing.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```tsx
|
|
391
|
+
* <Schema node={node} printer={printer}>{(code) => <Const export name="petSchema">{code}</Const>}</Schema>
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
export declare function Schema<TOutput>({ node, printer, children }: Props<TOutput>): KubbReactElement | null;
|
|
371
395
|
type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
|
|
372
396
|
key?: Key;
|
|
397
|
+
/** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
|
|
398
|
+
inline?: boolean;
|
|
373
399
|
/**
|
|
374
400
|
* Child nodes rendered as the type expression on the right-hand side of the alias.
|
|
375
401
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./rolldown-runtime-BowF1xt-.js";
|
|
2
|
-
import { Fragment, isKubbElement, jsx } from "./jsx-runtime.js";
|
|
2
|
+
import { Fragment, isKubbElement, jsx, jsxs } from "./jsx-runtime.js";
|
|
3
3
|
import { stringify } from "yaml";
|
|
4
4
|
import { ast } from "@kubb/ast";
|
|
5
5
|
// src/components/md/Callout.tsx
|
|
@@ -85,6 +85,8 @@ function File({ children, ...props }) {
|
|
|
85
85
|
/**
|
|
86
86
|
* Marks a block of source text to be associated with the enclosing {@link File}.
|
|
87
87
|
*
|
|
88
|
+
* @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
|
|
89
|
+
*
|
|
88
90
|
* Children are treated as the source string. `isExportable` marks the source as an exported declaration,
|
|
89
91
|
* `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
|
|
90
92
|
*
|
|
@@ -156,6 +158,7 @@ function FileImport(props) {
|
|
|
156
158
|
}
|
|
157
159
|
File.Export = FileExport;
|
|
158
160
|
File.Import = FileImport;
|
|
161
|
+
/** @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6. */
|
|
159
162
|
File.Source = FileSource;
|
|
160
163
|
// src/components/md/Frontmatter.tsx
|
|
161
164
|
/**
|
|
@@ -292,6 +295,27 @@ function List({ ordered, items }) {
|
|
|
292
295
|
function Paragraph({ children }) {
|
|
293
296
|
return /* @__PURE__ */ jsx("kubb-source", { children });
|
|
294
297
|
}
|
|
298
|
+
// src/components/Schema.tsx
|
|
299
|
+
/**
|
|
300
|
+
* Prints `node`, adds the printer's imports, and renders `children` with the code. Renders nothing when the printer returns nothing.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```tsx
|
|
304
|
+
* <Schema node={node} printer={printer}>{(code) => <Const export name="petSchema">{code}</Const>}</Schema>
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
function Schema({ node, printer, children }) {
|
|
308
|
+
const output = printer.print(node);
|
|
309
|
+
const imports = printer.drainImports();
|
|
310
|
+
if (!output) return null;
|
|
311
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
312
|
+
name: imp.name,
|
|
313
|
+
path: imp.path,
|
|
314
|
+
root: imp.root,
|
|
315
|
+
isTypeOnly: imp.isTypeOnly,
|
|
316
|
+
isNameSpace: imp.isNameSpace
|
|
317
|
+
}, [imp.path, imp.name].join("-"))), children(output)] });
|
|
318
|
+
}
|
|
295
319
|
// src/components/js/Type.tsx
|
|
296
320
|
/**
|
|
297
321
|
* Generates a TypeScript type alias declaration.
|
|
@@ -364,7 +388,7 @@ function isCodeHost(host) {
|
|
|
364
388
|
return host.type in codeFactories;
|
|
365
389
|
}
|
|
366
390
|
function createCodeNode(type, props) {
|
|
367
|
-
const { children, ...rest } = props;
|
|
391
|
+
const { children, inline: _inline, ...rest } = props;
|
|
368
392
|
return codeFactories[type]({
|
|
369
393
|
...rest,
|
|
370
394
|
nodes: collectCodeNodes(children)
|
|
@@ -432,6 +456,20 @@ function collectFileChildren(element) {
|
|
|
432
456
|
}));
|
|
433
457
|
return;
|
|
434
458
|
}
|
|
459
|
+
if (isCodeHost(host)) {
|
|
460
|
+
const { name, export: canExport, inline } = host.props;
|
|
461
|
+
const isDefault = "default" in host.props && !!host.props.default;
|
|
462
|
+
const node = createCodeNode(host.type, host.props);
|
|
463
|
+
sources.push(ast.factory.createSource({
|
|
464
|
+
name,
|
|
465
|
+
isTypeOnly: host.type === "kubb-type",
|
|
466
|
+
isExportable: !!canExport,
|
|
467
|
+
isIndexable: !!canExport && !isDefault,
|
|
468
|
+
...inline && "nodes" in node ? { inline: { expression: ast.node.getText(node.nodes) } } : {},
|
|
469
|
+
nodes: [node]
|
|
470
|
+
}));
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
435
473
|
const nested = collectFileChildren(childrenOf(host));
|
|
436
474
|
sources.push(...nested.sources);
|
|
437
475
|
exports.push(...nested.exports);
|
|
@@ -503,6 +541,6 @@ const jsxRenderer = () => {
|
|
|
503
541
|
[Symbol.dispose]() {}
|
|
504
542
|
};
|
|
505
543
|
};
|
|
506
|
-
export { Callout, Const, File, Frontmatter, Function, Heading, Jsx, List, Paragraph, Type, jsxRenderer };
|
|
544
|
+
export { Callout, Const, File, Frontmatter, Function, Heading, Jsx, List, Paragraph, Schema, Type, jsxRenderer };
|
|
507
545
|
|
|
508
546
|
//# sourceMappingURL=index.js.map
|
package/dist/jsx-runtime.d.cts
CHANGED
|
@@ -31,15 +31,19 @@ declare namespace JSX {
|
|
|
31
31
|
['kubb-import']: Omit<ast.ImportNode, 'kind'> & {};
|
|
32
32
|
['kubb-export']: Omit<ast.ExportNode, 'kind'> & {};
|
|
33
33
|
['kubb-function']: Omit<ast.FunctionNode, 'kind'> & {
|
|
34
|
+
inline?: boolean;
|
|
34
35
|
children?: KubbReactNode;
|
|
35
36
|
};
|
|
36
37
|
['kubb-arrow-function']: Omit<ast.ArrowFunctionNode, 'kind'> & {
|
|
38
|
+
inline?: boolean;
|
|
37
39
|
children?: KubbReactNode;
|
|
38
40
|
};
|
|
39
41
|
['kubb-const']: Omit<ast.ConstNode, 'kind'> & {
|
|
42
|
+
inline?: boolean;
|
|
40
43
|
children?: KubbReactNode;
|
|
41
44
|
};
|
|
42
45
|
['kubb-type']: Omit<ast.TypeNode, 'kind'> & {
|
|
46
|
+
inline?: boolean;
|
|
43
47
|
children?: KubbReactNode;
|
|
44
48
|
};
|
|
45
49
|
br: {};
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -31,15 +31,19 @@ declare namespace JSX {
|
|
|
31
31
|
['kubb-import']: Omit<ast.ImportNode, 'kind'> & {};
|
|
32
32
|
['kubb-export']: Omit<ast.ExportNode, 'kind'> & {};
|
|
33
33
|
['kubb-function']: Omit<ast.FunctionNode, 'kind'> & {
|
|
34
|
+
inline?: boolean;
|
|
34
35
|
children?: KubbReactNode;
|
|
35
36
|
};
|
|
36
37
|
['kubb-arrow-function']: Omit<ast.ArrowFunctionNode, 'kind'> & {
|
|
38
|
+
inline?: boolean;
|
|
37
39
|
children?: KubbReactNode;
|
|
38
40
|
};
|
|
39
41
|
['kubb-const']: Omit<ast.ConstNode, 'kind'> & {
|
|
42
|
+
inline?: boolean;
|
|
40
43
|
children?: KubbReactNode;
|
|
41
44
|
};
|
|
42
45
|
['kubb-type']: Omit<ast.TypeNode, 'kind'> & {
|
|
46
|
+
inline?: boolean;
|
|
43
47
|
children?: KubbReactNode;
|
|
44
48
|
};
|
|
45
49
|
br: {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/renderer-jsx",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.23.1",
|
|
4
4
|
"description": "Self-contained synchronous JSX renderer for Kubb. Turns JSX into FileNodes with built-in components (File, Function, Type, Const). An alternative for the ast.factory syntax.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"registry": "https://registry.npmjs.org/"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@kubb/ast": "^5.
|
|
97
|
+
"@kubb/ast": "^5.23.1",
|
|
98
98
|
"yaml": "^2.9.1"
|
|
99
99
|
},
|
|
100
100
|
"engines": {
|