@kubb/renderer-jsx 5.23.2 → 5.23.4

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/README.md CHANGED
@@ -49,12 +49,12 @@ const renderer = jsxRenderer()
49
49
 
50
50
  await renderer.render(
51
51
  <File baseName="petStore.ts" path="src/gen/petStore.ts">
52
- <File.Source>
53
- <Type name="Pet">{'{ id: number; name: string }'}</Type>
54
- <Function name="getPet" async>
55
- {"return fetch('/pets')"}
56
- </Function>
57
- </File.Source>
52
+ <Type export name="Pet">
53
+ {'{ id: number; name: string }'}
54
+ </Type>
55
+ <Function export name="getPet" async>
56
+ {"return fetch('/pets')"}
57
+ </Function>
58
58
  </File>,
59
59
  )
60
60
 
@@ -66,7 +66,9 @@ const files = renderer.files
66
66
  | Component | Description |
67
67
  | --------------- | --------------------------------------------------------------------------- |
68
68
  | `<File>` | Declares a generated output file with its path and optional imports/exports |
69
- | `<File.Source>` | The source content block inside a `<File>` |
69
+ | `<Code>` | A printed declaration inside a `<File>`, with `name`, `export` and `type` |
70
+ | `<Raw>` | Text inside a `<File>` that declares nothing, such as a statement or JSON |
71
+ | `<Origin>` | Sets the input location of the sources inside it, such as a JSON pointer |
70
72
  | `<Function>` | Generates a TypeScript function declaration |
71
73
  | `<Type>` | Generates a TypeScript type alias |
72
74
  | `<Const>` | Generates a `const` variable declaration |
package/dist/index.cjs CHANGED
@@ -32,7 +32,20 @@ function Callout({ type, title, children }) {
32
32
  const label = CALLOUT_LABEL[type];
33
33
  const header = title ? `> [!${label}] ${title}` : `> [!${label}]`;
34
34
  const quoted = children.trimEnd().split("\n").map((line) => line.length > 0 ? `> ${line}` : ">").join("\n");
35
- return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", { children: `${header}\n${quoted}` });
35
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-raw", { children: `${header}\n${quoted}` });
36
+ }
37
+ // src/components/Code.tsx
38
+ /**
39
+ * A printed declaration in a `File`, in any language. For a declaration written in JSX, or a TypeScript type, use `Const`, `Type` or `Function`.
40
+ */
41
+ function Code({ children, name, export: canExport, default: isDefault, space }) {
42
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-code", {
43
+ name,
44
+ export: !!canExport,
45
+ default: isDefault,
46
+ space,
47
+ children
48
+ });
36
49
  }
37
50
  // src/components/js/Const.tsx
38
51
  /**
@@ -70,9 +83,9 @@ function Const({ children, ...props }) {
70
83
  * @example Basic file with a source block
71
84
  * ```tsx
72
85
  * <File baseName="petStore.ts" path="src/models/petStore.ts">
73
- * <File.Source name="Pet" isExportable isIndexable>
74
- * {`export type Pet = { id: number; name: string }`}
75
- * </File.Source>
86
+ * <Code name="petSchema" export>
87
+ * {`export const petSchema = z.object({ id: z.number() })`}
88
+ * </Code>
76
89
  * </File>
77
90
  * ```
78
91
  */
@@ -84,47 +97,39 @@ function File({ children, ...props }) {
84
97
  });
85
98
  }
86
99
  /**
87
- * Marks a block of source text to be associated with the enclosing {@link File}.
88
- *
89
- * @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
90
- *
91
- * Children are treated as the source string. `isExportable` marks the source as an exported declaration,
92
- * `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
93
- *
94
- * @example Exportable, indexable source block
95
- * ```tsx
96
- * <File.Source name="Pet" isExportable isIndexable>
97
- * {`export type Pet = { id: number; name: string }`}
98
- * </File.Source>
99
- * ```
100
+ * A block of source text in the enclosing {@link File}.
100
101
  *
101
- * @example Type-only source block
102
- * ```tsx
103
- * <File.Source name="PetId" isTypeOnly isExportable>
104
- * {`export type PetId = string`}
105
- * </File.Source>
106
- * ```
102
+ * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
107
103
  */
108
- function FileSource({ children, ...props }) {
109
- return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", {
110
- ...props,
111
- children
104
+ function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }) {
105
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-origin", {
106
+ pointer,
107
+ children: /* @__PURE__ */ require_jsx_runtime.jsx("kubb-code", {
108
+ name,
109
+ export: isExport ?? isIndexable,
110
+ default: isDefault,
111
+ space,
112
+ isTypeOnly,
113
+ inline,
114
+ children
115
+ })
112
116
  });
113
117
  }
114
118
  /**
115
119
  * Declares an export entry for the enclosing {@link File}.
116
120
  *
117
- * The export is collected by the renderer and emitted at the top of the generated file.
121
+ * The export is collected by the renderer and emitted at the top of the generated file. A name without a
122
+ * `space` is a value.
118
123
  *
119
124
  * @example Named export
120
125
  * ```tsx
121
- * <File.Export name={['Pet']} path="./models/petStore" />
126
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
122
127
  * // export { Pet } from './models/petStore'
123
128
  * ```
124
129
  *
125
130
  * @example Type-only wildcard export
126
131
  * ```tsx
127
- * <File.Export path="./models/petStore" isTypeOnly />
132
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
128
133
  * // export type * from './models/petStore'
129
134
  * ```
130
135
  */
@@ -134,23 +139,18 @@ function FileExport(props) {
134
139
  /**
135
140
  * Declares an import entry for the enclosing {@link File}.
136
141
  *
137
- * The import is collected by the renderer and emitted at the top of the generated file.
142
+ * The import is collected by the renderer and emitted at the top of the generated file. A name without a
143
+ * `space` is a value.
138
144
  *
139
145
  * @example Named import
140
146
  * ```tsx
141
- * <File.Import name={['useState']} path="react" />
147
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
142
148
  * // import { useState } from 'react'
143
149
  * ```
144
150
  *
145
- * @example Type-only import
146
- * ```tsx
147
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
148
- * // import type { Pet } from './models'
149
- * ```
150
- *
151
151
  * @example Namespace import
152
152
  * ```tsx
153
- * <File.Import name="z" path="zod" isNameSpace />
153
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
154
154
  * // import * as z from 'zod'
155
155
  * ```
156
156
  */
@@ -159,7 +159,7 @@ function FileImport(props) {
159
159
  }
160
160
  File.Export = FileExport;
161
161
  File.Import = FileImport;
162
- /** @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6. */
162
+ /** @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6. */
163
163
  File.Source = FileSource;
164
164
  // src/components/md/Frontmatter.tsx
165
165
  /**
@@ -181,7 +181,7 @@ File.Source = FileSource;
181
181
  */
182
182
  function Frontmatter({ data }) {
183
183
  const envelope = Object.keys(data).length === 0 ? "" : `---\n${(0, yaml.stringify)(data).trimEnd()}\n---`;
184
- return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", { children: envelope });
184
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-raw", { children: envelope });
185
185
  }
186
186
  // src/components/js/Function.tsx
187
187
  /**
@@ -237,7 +237,7 @@ Function.Arrow = ArrowFunction;
237
237
  * ```
238
238
  */
239
239
  function Heading({ level, children }) {
240
- return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", { children: `${"#".repeat(level)} ${children}` });
240
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-raw", { children: `${"#".repeat(level)} ${children}` });
241
241
  }
242
242
  // src/components/jsx/Jsx.tsx
243
243
  /**
@@ -278,7 +278,17 @@ function Jsx({ children }) {
278
278
  */
279
279
  function List({ ordered, items }) {
280
280
  const body = items.map((item, index) => `${ordered ? `${index + 1}.` : "-"} ${item}`).join("\n");
281
- return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", { children: body });
281
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-raw", { children: body });
282
+ }
283
+ // src/components/Origin.tsx
284
+ /**
285
+ * Sets the input location of every source inside it. An inner `Origin` wins.
286
+ */
287
+ function Origin({ pointer, children }) {
288
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-origin", {
289
+ pointer,
290
+ children
291
+ });
282
292
  }
283
293
  // src/components/md/Paragraph.tsx
284
294
  /**
@@ -294,7 +304,17 @@ function List({ ordered, items }) {
294
304
  * ```
295
305
  */
296
306
  function Paragraph({ children }) {
297
- return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-source", { children });
307
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-raw", { children });
308
+ }
309
+ // src/components/Raw.tsx
310
+ /**
311
+ * Text in a `File` that declares nothing, such as a statement, JSON or markdown. Barrels leave it out.
312
+ */
313
+ function Raw({ children, name }) {
314
+ return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-raw", {
315
+ name,
316
+ children
317
+ });
298
318
  }
299
319
  // src/components/Schema.tsx
300
320
  /**
@@ -310,6 +330,7 @@ function Schema({ node, printer, children }) {
310
330
  const imports = printer.drainImports();
311
331
  if (!output) return null;
312
332
  return /* @__PURE__ */ require_jsx_runtime.jsxs(require_jsx_runtime.Fragment, { children: [imports.map((imp) => /* @__PURE__ */ require_jsx_runtime.jsx(File.Import, {
333
+ names: imp.names,
313
334
  name: imp.name,
314
335
  path: imp.path,
315
336
  root: imp.root,
@@ -416,29 +437,52 @@ function collectCodeNodes(element) {
416
437
  });
417
438
  return nodes;
418
439
  }
440
+ /**
441
+ * Gives each source without a pointer the one of the enclosing `Origin`, so the innermost `Origin` wins.
442
+ */
443
+ function withOrigin(sources, pointer) {
444
+ if (!pointer) return sources;
445
+ return sources.map((source) => source.pointer ? source : {
446
+ ...source,
447
+ pointer
448
+ });
449
+ }
419
450
  function collectFileChildren(element) {
420
451
  const sources = [];
421
452
  const exports = [];
422
453
  const imports = [];
423
454
  walkElement(element, (text) => {
424
- if (text.trim()) throw new Error(`[jsx] '${text}' should be part of <File.Source> component when using the <File/> component`);
455
+ if (text.trim()) throw new Error(`[jsx] '${text}' should be part of a <Code> or <Raw> component when using the <File/> component`);
425
456
  }, (host) => {
426
- if (host.type === "kubb-source") {
427
- const { name, pointer, isTypeOnly, isExportable, isIndexable, inline, children } = host.props;
457
+ if (host.type === "kubb-code") {
458
+ const { name, space, isTypeOnly, export: isExport, default: isDefault, inline, children } = host.props;
428
459
  sources.push(_kubb_ast.ast.factory.createSource({
429
460
  name: name?.toString(),
430
- ...pointer !== void 0 ? { pointer } : {},
461
+ ...space ? { space } : {},
431
462
  isTypeOnly: !!isTypeOnly,
432
- isExportable: !!isExportable,
433
- isIndexable: !!isIndexable,
463
+ export: !!isExport,
464
+ ...isDefault ? { default: true } : {},
434
465
  ...inline ? { inline } : {},
435
466
  nodes: collectCodeNodes(children)
436
467
  }));
437
468
  return;
438
469
  }
470
+ if (host.type === "kubb-raw") {
471
+ const { name, children } = host.props;
472
+ sources.push(_kubb_ast.ast.factory.createSource({
473
+ name: name?.toString(),
474
+ isTypeOnly: false,
475
+ export: false,
476
+ nodes: collectCodeNodes(children)
477
+ }));
478
+ return;
479
+ }
439
480
  if (host.type === "kubb-export") {
440
- const { name, path, isTypeOnly, asAlias } = host.props;
441
- exports.push(_kubb_ast.ast.factory.createExport({
481
+ const { names, name, path, isTypeOnly, asAlias } = host.props;
482
+ exports.push(names ? _kubb_ast.ast.factory.createExport({
483
+ names,
484
+ path
485
+ }) : _kubb_ast.ast.factory.createExport({
442
486
  name,
443
487
  path,
444
488
  isTypeOnly: !!isTypeOnly,
@@ -447,8 +491,12 @@ function collectFileChildren(element) {
447
491
  return;
448
492
  }
449
493
  if (host.type === "kubb-import") {
450
- const { name, path, root, isTypeOnly, isNameSpace } = host.props;
451
- imports.push(_kubb_ast.ast.factory.createImport({
494
+ const { names, name, path, root, isTypeOnly, isNameSpace } = host.props;
495
+ imports.push(names ? _kubb_ast.ast.factory.createImport({
496
+ names,
497
+ path,
498
+ root
499
+ }) : _kubb_ast.ast.factory.createImport({
452
500
  name,
453
501
  path,
454
502
  root,
@@ -464,15 +512,15 @@ function collectFileChildren(element) {
464
512
  sources.push(_kubb_ast.ast.factory.createSource({
465
513
  name,
466
514
  isTypeOnly: host.type === "kubb-type",
467
- isExportable: !!canExport,
468
- isIndexable: !!canExport && !isDefault,
515
+ export: !!canExport,
516
+ ...isDefault ? { default: true } : {},
469
517
  ...inline && "nodes" in node ? { inline: { expression: _kubb_ast.ast.node.getText(node.nodes) } } : {},
470
518
  nodes: [node]
471
519
  }));
472
520
  return;
473
521
  }
474
522
  const nested = collectFileChildren(childrenOf(host));
475
- sources.push(...nested.sources);
523
+ sources.push(...host.type === "kubb-origin" ? withOrigin(nested.sources, host.props.pointer) : nested.sources);
476
524
  exports.push(...nested.exports);
477
525
  imports.push(...nested.imports);
478
526
  });
@@ -491,6 +539,7 @@ function createFileNode(props) {
491
539
  footer: props.footer,
492
540
  banner: props.banner,
493
541
  copy: props.copy,
542
+ inline: props.inline,
494
543
  sources,
495
544
  exports,
496
545
  imports
@@ -543,6 +592,7 @@ const jsxRenderer = () => {
543
592
  };
544
593
  };
545
594
  exports.Callout = Callout;
595
+ exports.Code = Code;
546
596
  exports.Const = Const;
547
597
  exports.File = File;
548
598
  exports.Frontmatter = Frontmatter;
@@ -550,7 +600,9 @@ exports.Function = Function;
550
600
  exports.Heading = Heading;
551
601
  exports.Jsx = Jsx;
552
602
  exports.List = List;
603
+ exports.Origin = Origin;
553
604
  exports.Paragraph = Paragraph;
605
+ exports.Raw = Raw;
554
606
  exports.Schema = Schema;
555
607
  exports.Type = Type;
556
608
  exports.jsxRenderer = jsxRenderer;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as KubbReactNode, n as Key, r as KubbReactElement, t as JSDoc } from "./types-D_u8uaRO.cjs";
1
+ import { i as KubbReactNode, n as Key, r as KubbReactElement, t as JSDoc } from "./types-CpFFjEcD.cjs";
2
2
  import { ast } from "@kubb/ast";
3
3
  declare const CALLOUT_LABEL: {
4
4
  readonly tip: 'TIP';
@@ -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$8 = {
11
+ type Props$11 = {
12
12
  key?: Key;
13
13
  /**
14
14
  * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
@@ -41,10 +41,37 @@ type Props$8 = {
41
41
  * // > Breaking change in v6.
42
42
  * ```
43
43
  */
44
- export declare function Callout({ type, title, children }: Props$8): KubbReactElement;
44
+ export declare function Callout({ type, title, children }: Props$11): KubbReactElement;
45
+ type Props$10 = {
46
+ key?: Key;
47
+ name: string;
48
+ /**
49
+ * Lists the declaration in barrels. The text still needs its own `export` keyword.
50
+ */
51
+ export?: boolean;
52
+ /**
53
+ * Marks an exported declaration as the default export, which barrels skip.
54
+ */
55
+ default?: boolean;
56
+ /**
57
+ * Whether the declaration is a type or a value. Imports and barrels of a type print `type`.
58
+ * @default 'value'
59
+ */
60
+ space?: ast.Space;
61
+ children?: KubbReactNode;
62
+ };
63
+ /**
64
+ * A printed declaration in a `File`, in any language. For a declaration written in JSX, or a TypeScript type, use `Const`, `Type` or `Function`.
65
+ */
66
+ export declare function Code({ children, name, export: canExport, default: isDefault, space }: Props$10): KubbReactElement;
45
67
  type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
46
68
  key?: Key;
47
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
69
+ /**
70
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
71
+ * or, without it, when every source in that file is inline.
72
+ *
73
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
74
+ */
48
75
  inline?: boolean;
49
76
  /**
50
77
  * Child nodes rendered as the initializer expression of the constant.
@@ -80,7 +107,7 @@ type BasePropsWithoutBaseName = {
80
107
  path?: string | null;
81
108
  };
82
109
  type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
83
- type Props$7<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy'> & {
110
+ type Props$9<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy' | 'inline'> & {
84
111
  key?: Key;
85
112
  /**
86
113
  * Arbitrary metadata attached to the file node for plugins to read.
@@ -101,19 +128,19 @@ type Props$7<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, '
101
128
  * @example Basic file with a source block
102
129
  * ```tsx
103
130
  * <File baseName="petStore.ts" path="src/models/petStore.ts">
104
- * <File.Source name="Pet" isExportable isIndexable>
105
- * {`export type Pet = { id: number; name: string }`}
106
- * </File.Source>
131
+ * <Code name="petSchema" export>
132
+ * {`export const petSchema = z.object({ id: z.number() })`}
133
+ * </Code>
107
134
  * </File>
108
135
  * ```
109
136
  */
110
- export declare function File<TMeta extends object = object>({ children, ...props }: Props$7<TMeta>): KubbReactElement;
137
+ export declare function File<TMeta extends object = object>({ children, ...props }: Props$9<TMeta>): KubbReactElement;
111
138
  export declare namespace File {
112
139
  export { FileExport as Export };
113
140
  export { FileImport as Import };
114
141
  export { FileSource as Source };
115
142
  }
116
- type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value'> & {
143
+ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value' | 'nodes'> & {
117
144
  key?: Key;
118
145
  /**
119
146
  * Child nodes rendered as the source content of this block.
@@ -121,77 +148,56 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value'> & {
121
148
  children?: KubbReactNode;
122
149
  };
123
150
  /**
124
- * Marks a block of source text to be associated with the enclosing {@link File}.
125
- *
126
- * @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
127
- *
128
- * Children are treated as the source string. `isExportable` marks the source as an exported declaration,
129
- * `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
130
- *
131
- * @example Exportable, indexable source block
132
- * ```tsx
133
- * <File.Source name="Pet" isExportable isIndexable>
134
- * {`export type Pet = { id: number; name: string }`}
135
- * </File.Source>
136
- * ```
151
+ * A block of source text in the enclosing {@link File}.
137
152
  *
138
- * @example Type-only source block
139
- * ```tsx
140
- * <File.Source name="PetId" isTypeOnly isExportable>
141
- * {`export type PetId = string`}
142
- * </File.Source>
143
- * ```
153
+ * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
144
154
  */
145
- declare function FileSource({ children, ...props }: FileSourceProps): KubbReactElement;
146
- type FileExportProps = Omit<ast.ExportNode, 'kind'> & {
155
+ declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
156
+ type FileExportProps = ast.ExportInput & {
147
157
  key?: Key;
148
158
  };
149
159
  /**
150
160
  * Declares an export entry for the enclosing {@link File}.
151
161
  *
152
- * The export is collected by the renderer and emitted at the top of the generated file.
162
+ * The export is collected by the renderer and emitted at the top of the generated file. A name without a
163
+ * `space` is a value.
153
164
  *
154
165
  * @example Named export
155
166
  * ```tsx
156
- * <File.Export name={['Pet']} path="./models/petStore" />
167
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
157
168
  * // export { Pet } from './models/petStore'
158
169
  * ```
159
170
  *
160
171
  * @example Type-only wildcard export
161
172
  * ```tsx
162
- * <File.Export path="./models/petStore" isTypeOnly />
173
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
163
174
  * // export type * from './models/petStore'
164
175
  * ```
165
176
  */
166
177
  declare function FileExport(props: FileExportProps): KubbReactElement;
167
- type FileImportProps = Omit<ast.ImportNode, 'kind'> & {
178
+ type FileImportProps = ast.ImportInput & {
168
179
  key?: Key;
169
180
  };
170
181
  /**
171
182
  * Declares an import entry for the enclosing {@link File}.
172
183
  *
173
- * The import is collected by the renderer and emitted at the top of the generated file.
184
+ * The import is collected by the renderer and emitted at the top of the generated file. A name without a
185
+ * `space` is a value.
174
186
  *
175
187
  * @example Named import
176
188
  * ```tsx
177
- * <File.Import name={['useState']} path="react" />
189
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
178
190
  * // import { useState } from 'react'
179
191
  * ```
180
192
  *
181
- * @example Type-only import
182
- * ```tsx
183
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
184
- * // import type { Pet } from './models'
185
- * ```
186
- *
187
193
  * @example Namespace import
188
194
  * ```tsx
189
- * <File.Import name="z" path="zod" isNameSpace />
195
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
190
196
  * // import * as z from 'zod'
191
197
  * ```
192
198
  */
193
199
  declare function FileImport(props: FileImportProps): KubbReactElement;
194
- type Props$6 = {
200
+ type Props$8 = {
195
201
  key?: Key;
196
202
  /**
197
203
  * Plain object serialized as YAML between `---` fences.
@@ -218,10 +224,15 @@ type Props$6 = {
218
224
  * </File>
219
225
  * ```
220
226
  */
221
- export declare function Frontmatter({ data }: Props$6): KubbReactElement;
222
- type Props$5 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
227
+ export declare function Frontmatter({ data }: Props$8): KubbReactElement;
228
+ type Props$7 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
223
229
  key?: Key;
224
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
230
+ /**
231
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
232
+ * or, without it, when every source in that file is inline.
233
+ *
234
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
235
+ */
225
236
  inline?: boolean;
226
237
  /**
227
238
  * Child nodes rendered as the body of the function.
@@ -241,13 +252,18 @@ type Props$5 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
241
252
  * // }
242
253
  * ```
243
254
  */
244
- export declare function Function({ children, ...props }: Props$5): KubbReactElement;
255
+ export declare function Function({ children, ...props }: Props$7): KubbReactElement;
245
256
  export declare namespace Function {
246
257
  export { ArrowFunction as Arrow };
247
258
  }
248
259
  type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
249
260
  key?: Key;
250
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
261
+ /**
262
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
263
+ * or, without it, when every source in that file is inline.
264
+ *
265
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
266
+ */
251
267
  inline?: boolean;
252
268
  /**
253
269
  * Child nodes rendered as the body of the function.
@@ -269,7 +285,7 @@ type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
269
285
  */
270
286
  declare function ArrowFunction({ children, ...props }: ArrowFunctionProps): KubbReactElement;
271
287
  type Level = 1 | 2 | 3 | 4 | 5 | 6;
272
- type Props$4 = {
288
+ type Props$6 = {
273
289
  key?: Key;
274
290
  /**
275
291
  * Heading depth, `1` through `6`. Matches the number of `#` characters
@@ -293,8 +309,8 @@ type Props$4 = {
293
309
  * // ## Installation
294
310
  * ```
295
311
  */
296
- export declare function Heading({ level, children }: Props$4): KubbReactElement;
297
- type Props$3 = {
312
+ export declare function Heading({ level, children }: Props$6): KubbReactElement;
313
+ type Props$5 = {
298
314
  key?: Key;
299
315
  /**
300
316
  * Raw JSX string embedded verbatim in the generated code, including
@@ -322,8 +338,8 @@ type Props$3 = {
322
338
  * </Function>
323
339
  * ```
324
340
  */
325
- export declare function Jsx({ children }: Props$3): KubbReactElement;
326
- type Props$2 = {
341
+ export declare function Jsx({ children }: Props$5): KubbReactElement;
342
+ type Props$4 = {
327
343
  key?: Key;
328
344
  /**
329
345
  * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
@@ -354,8 +370,19 @@ type Props$2 = {
354
370
  * // 2. Second
355
371
  * ```
356
372
  */
357
- export declare function List({ ordered, items }: Props$2): KubbReactElement;
358
- type Props$1 = {
373
+ export declare function List({ ordered, items }: Props$4): KubbReactElement;
374
+ type Props$3 = {
375
+ /**
376
+ * The input location, in the form the adapter reads, such as `#/components/schemas/Pet`.
377
+ */
378
+ pointer?: string;
379
+ children?: KubbReactNode;
380
+ };
381
+ /**
382
+ * Sets the input location of every source inside it. An inner `Origin` wins.
383
+ */
384
+ export declare function Origin({ pointer, children }: Props$3): KubbReactElement;
385
+ type Props$2 = {
359
386
  key?: Key;
360
387
  /**
361
388
  * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
@@ -375,7 +402,19 @@ type Props$1 = {
375
402
  * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
376
403
  * ```
377
404
  */
378
- export declare function Paragraph({ children }: Props$1): KubbReactElement;
405
+ export declare function Paragraph({ children }: Props$2): KubbReactElement;
406
+ type Props$1 = {
407
+ key?: Key;
408
+ /**
409
+ * Dedupes the block when several generators add it to one file.
410
+ */
411
+ name?: string;
412
+ children?: KubbReactNode;
413
+ };
414
+ /**
415
+ * Text in a `File` that declares nothing, such as a statement, JSON or markdown. Barrels leave it out.
416
+ */
417
+ export declare function Raw({ children, name }: Props$1): KubbReactElement;
379
418
  type Props<TOutput> = {
380
419
  node: ast.SchemaNode;
381
420
  printer: Pick<ast.Printer, 'drainImports'> & {
@@ -394,7 +433,12 @@ type Props<TOutput> = {
394
433
  export declare function Schema<TOutput>({ node, printer, children }: Props<TOutput>): KubbReactElement | null;
395
434
  type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
396
435
  key?: Key;
397
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
436
+ /**
437
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
438
+ * or, without it, when every source in that file is inline.
439
+ *
440
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
441
+ */
398
442
  inline?: boolean;
399
443
  /**
400
444
  * Child nodes rendered as the type expression on the right-hand side of the alias.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as KubbReactNode, n as Key, r as KubbReactElement, t as JSDoc } from "./types-D_u8uaRO.js";
1
+ import { i as KubbReactNode, n as Key, r as KubbReactElement, t as JSDoc } from "./types-BiISTVBi.js";
2
2
  import { ast } from "@kubb/ast";
3
3
  declare const CALLOUT_LABEL: {
4
4
  readonly tip: 'TIP';
@@ -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$8 = {
11
+ type Props$11 = {
12
12
  key?: Key;
13
13
  /**
14
14
  * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
@@ -41,10 +41,37 @@ type Props$8 = {
41
41
  * // > Breaking change in v6.
42
42
  * ```
43
43
  */
44
- export declare function Callout({ type, title, children }: Props$8): KubbReactElement;
44
+ export declare function Callout({ type, title, children }: Props$11): KubbReactElement;
45
+ type Props$10 = {
46
+ key?: Key;
47
+ name: string;
48
+ /**
49
+ * Lists the declaration in barrels. The text still needs its own `export` keyword.
50
+ */
51
+ export?: boolean;
52
+ /**
53
+ * Marks an exported declaration as the default export, which barrels skip.
54
+ */
55
+ default?: boolean;
56
+ /**
57
+ * Whether the declaration is a type or a value. Imports and barrels of a type print `type`.
58
+ * @default 'value'
59
+ */
60
+ space?: ast.Space;
61
+ children?: KubbReactNode;
62
+ };
63
+ /**
64
+ * A printed declaration in a `File`, in any language. For a declaration written in JSX, or a TypeScript type, use `Const`, `Type` or `Function`.
65
+ */
66
+ export declare function Code({ children, name, export: canExport, default: isDefault, space }: Props$10): KubbReactElement;
45
67
  type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
46
68
  key?: Key;
47
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
69
+ /**
70
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
71
+ * or, without it, when every source in that file is inline.
72
+ *
73
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
74
+ */
48
75
  inline?: boolean;
49
76
  /**
50
77
  * Child nodes rendered as the initializer expression of the constant.
@@ -80,7 +107,7 @@ type BasePropsWithoutBaseName = {
80
107
  path?: string | null;
81
108
  };
82
109
  type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
83
- type Props$7<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy'> & {
110
+ type Props$9<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, 'banner' | 'footer' | 'copy' | 'inline'> & {
84
111
  key?: Key;
85
112
  /**
86
113
  * Arbitrary metadata attached to the file node for plugins to read.
@@ -101,19 +128,19 @@ type Props$7<TMeta extends object> = BaseProps & Pick<ast.UserFileNode<TMeta>, '
101
128
  * @example Basic file with a source block
102
129
  * ```tsx
103
130
  * <File baseName="petStore.ts" path="src/models/petStore.ts">
104
- * <File.Source name="Pet" isExportable isIndexable>
105
- * {`export type Pet = { id: number; name: string }`}
106
- * </File.Source>
131
+ * <Code name="petSchema" export>
132
+ * {`export const petSchema = z.object({ id: z.number() })`}
133
+ * </Code>
107
134
  * </File>
108
135
  * ```
109
136
  */
110
- export declare function File<TMeta extends object = object>({ children, ...props }: Props$7<TMeta>): KubbReactElement;
137
+ export declare function File<TMeta extends object = object>({ children, ...props }: Props$9<TMeta>): KubbReactElement;
111
138
  export declare namespace File {
112
139
  export { FileExport as Export };
113
140
  export { FileImport as Import };
114
141
  export { FileSource as Source };
115
142
  }
116
- type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value'> & {
143
+ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value' | 'nodes'> & {
117
144
  key?: Key;
118
145
  /**
119
146
  * Child nodes rendered as the source content of this block.
@@ -121,77 +148,56 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value'> & {
121
148
  children?: KubbReactNode;
122
149
  };
123
150
  /**
124
- * Marks a block of source text to be associated with the enclosing {@link File}.
125
- *
126
- * @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
127
- *
128
- * Children are treated as the source string. `isExportable` marks the source as an exported declaration,
129
- * `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
130
- *
131
- * @example Exportable, indexable source block
132
- * ```tsx
133
- * <File.Source name="Pet" isExportable isIndexable>
134
- * {`export type Pet = { id: number; name: string }`}
135
- * </File.Source>
136
- * ```
151
+ * A block of source text in the enclosing {@link File}.
137
152
  *
138
- * @example Type-only source block
139
- * ```tsx
140
- * <File.Source name="PetId" isTypeOnly isExportable>
141
- * {`export type PetId = string`}
142
- * </File.Source>
143
- * ```
153
+ * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
144
154
  */
145
- declare function FileSource({ children, ...props }: FileSourceProps): KubbReactElement;
146
- type FileExportProps = Omit<ast.ExportNode, 'kind'> & {
155
+ declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
156
+ type FileExportProps = ast.ExportInput & {
147
157
  key?: Key;
148
158
  };
149
159
  /**
150
160
  * Declares an export entry for the enclosing {@link File}.
151
161
  *
152
- * The export is collected by the renderer and emitted at the top of the generated file.
162
+ * The export is collected by the renderer and emitted at the top of the generated file. A name without a
163
+ * `space` is a value.
153
164
  *
154
165
  * @example Named export
155
166
  * ```tsx
156
- * <File.Export name={['Pet']} path="./models/petStore" />
167
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
157
168
  * // export { Pet } from './models/petStore'
158
169
  * ```
159
170
  *
160
171
  * @example Type-only wildcard export
161
172
  * ```tsx
162
- * <File.Export path="./models/petStore" isTypeOnly />
173
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
163
174
  * // export type * from './models/petStore'
164
175
  * ```
165
176
  */
166
177
  declare function FileExport(props: FileExportProps): KubbReactElement;
167
- type FileImportProps = Omit<ast.ImportNode, 'kind'> & {
178
+ type FileImportProps = ast.ImportInput & {
168
179
  key?: Key;
169
180
  };
170
181
  /**
171
182
  * Declares an import entry for the enclosing {@link File}.
172
183
  *
173
- * The import is collected by the renderer and emitted at the top of the generated file.
184
+ * The import is collected by the renderer and emitted at the top of the generated file. A name without a
185
+ * `space` is a value.
174
186
  *
175
187
  * @example Named import
176
188
  * ```tsx
177
- * <File.Import name={['useState']} path="react" />
189
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
178
190
  * // import { useState } from 'react'
179
191
  * ```
180
192
  *
181
- * @example Type-only import
182
- * ```tsx
183
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
184
- * // import type { Pet } from './models'
185
- * ```
186
- *
187
193
  * @example Namespace import
188
194
  * ```tsx
189
- * <File.Import name="z" path="zod" isNameSpace />
195
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
190
196
  * // import * as z from 'zod'
191
197
  * ```
192
198
  */
193
199
  declare function FileImport(props: FileImportProps): KubbReactElement;
194
- type Props$6 = {
200
+ type Props$8 = {
195
201
  key?: Key;
196
202
  /**
197
203
  * Plain object serialized as YAML between `---` fences.
@@ -218,10 +224,15 @@ type Props$6 = {
218
224
  * </File>
219
225
  * ```
220
226
  */
221
- export declare function Frontmatter({ data }: Props$6): KubbReactElement;
222
- type Props$5 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
227
+ export declare function Frontmatter({ data }: Props$8): KubbReactElement;
228
+ type Props$7 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
223
229
  key?: Key;
224
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
230
+ /**
231
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
232
+ * or, without it, when every source in that file is inline.
233
+ *
234
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
235
+ */
225
236
  inline?: boolean;
226
237
  /**
227
238
  * Child nodes rendered as the body of the function.
@@ -241,13 +252,18 @@ type Props$5 = Omit<ast.FunctionNode, 'kind' | 'nodes'> & {
241
252
  * // }
242
253
  * ```
243
254
  */
244
- export declare function Function({ children, ...props }: Props$5): KubbReactElement;
255
+ export declare function Function({ children, ...props }: Props$7): KubbReactElement;
245
256
  export declare namespace Function {
246
257
  export { ArrowFunction as Arrow };
247
258
  }
248
259
  type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
249
260
  key?: Key;
250
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
261
+ /**
262
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
263
+ * or, without it, when every source in that file is inline.
264
+ *
265
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
266
+ */
251
267
  inline?: boolean;
252
268
  /**
253
269
  * Child nodes rendered as the body of the function.
@@ -269,7 +285,7 @@ type ArrowFunctionProps = Omit<ast.ArrowFunctionNode, 'kind' | 'nodes'> & {
269
285
  */
270
286
  declare function ArrowFunction({ children, ...props }: ArrowFunctionProps): KubbReactElement;
271
287
  type Level = 1 | 2 | 3 | 4 | 5 | 6;
272
- type Props$4 = {
288
+ type Props$6 = {
273
289
  key?: Key;
274
290
  /**
275
291
  * Heading depth, `1` through `6`. Matches the number of `#` characters
@@ -293,8 +309,8 @@ type Props$4 = {
293
309
  * // ## Installation
294
310
  * ```
295
311
  */
296
- export declare function Heading({ level, children }: Props$4): KubbReactElement;
297
- type Props$3 = {
312
+ export declare function Heading({ level, children }: Props$6): KubbReactElement;
313
+ type Props$5 = {
298
314
  key?: Key;
299
315
  /**
300
316
  * Raw JSX string embedded verbatim in the generated code, including
@@ -322,8 +338,8 @@ type Props$3 = {
322
338
  * </Function>
323
339
  * ```
324
340
  */
325
- export declare function Jsx({ children }: Props$3): KubbReactElement;
326
- type Props$2 = {
341
+ export declare function Jsx({ children }: Props$5): KubbReactElement;
342
+ type Props$4 = {
327
343
  key?: Key;
328
344
  /**
329
345
  * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
@@ -354,8 +370,19 @@ type Props$2 = {
354
370
  * // 2. Second
355
371
  * ```
356
372
  */
357
- export declare function List({ ordered, items }: Props$2): KubbReactElement;
358
- type Props$1 = {
373
+ export declare function List({ ordered, items }: Props$4): KubbReactElement;
374
+ type Props$3 = {
375
+ /**
376
+ * The input location, in the form the adapter reads, such as `#/components/schemas/Pet`.
377
+ */
378
+ pointer?: string;
379
+ children?: KubbReactNode;
380
+ };
381
+ /**
382
+ * Sets the input location of every source inside it. An inner `Origin` wins.
383
+ */
384
+ export declare function Origin({ pointer, children }: Props$3): KubbReactElement;
385
+ type Props$2 = {
359
386
  key?: Key;
360
387
  /**
361
388
  * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
@@ -375,7 +402,19 @@ type Props$1 = {
375
402
  * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
376
403
  * ```
377
404
  */
378
- export declare function Paragraph({ children }: Props$1): KubbReactElement;
405
+ export declare function Paragraph({ children }: Props$2): KubbReactElement;
406
+ type Props$1 = {
407
+ key?: Key;
408
+ /**
409
+ * Dedupes the block when several generators add it to one file.
410
+ */
411
+ name?: string;
412
+ children?: KubbReactNode;
413
+ };
414
+ /**
415
+ * Text in a `File` that declares nothing, such as a statement, JSON or markdown. Barrels leave it out.
416
+ */
417
+ export declare function Raw({ children, name }: Props$1): KubbReactElement;
379
418
  type Props<TOutput> = {
380
419
  node: ast.SchemaNode;
381
420
  printer: Pick<ast.Printer, 'drainImports'> & {
@@ -394,7 +433,12 @@ type Props<TOutput> = {
394
433
  export declare function Schema<TOutput>({ node, printer, children }: Props<TOutput>): KubbReactElement | null;
395
434
  type TypeProps = Omit<ast.TypeNode, 'kind' | 'nodes'> & {
396
435
  key?: Key;
397
- /** Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File`. */
436
+ /**
437
+ * Lets importing files use the body in place of the name. Read when the declaration sits directly in a `File` that sets `inline`,
438
+ * or, without it, when every source in that file is inline.
439
+ *
440
+ * @deprecated Set `inline` on the `File`. Removed in Kubb v6.
441
+ */
398
442
  inline?: boolean;
399
443
  /**
400
444
  * Child nodes rendered as the type expression on the right-hand side of the alias.
package/dist/index.js CHANGED
@@ -31,7 +31,20 @@ function Callout({ type, title, children }) {
31
31
  const label = CALLOUT_LABEL[type];
32
32
  const header = title ? `> [!${label}] ${title}` : `> [!${label}]`;
33
33
  const quoted = children.trimEnd().split("\n").map((line) => line.length > 0 ? `> ${line}` : ">").join("\n");
34
- return /* @__PURE__ */ jsx("kubb-source", { children: `${header}\n${quoted}` });
34
+ return /* @__PURE__ */ jsx("kubb-raw", { children: `${header}\n${quoted}` });
35
+ }
36
+ // src/components/Code.tsx
37
+ /**
38
+ * A printed declaration in a `File`, in any language. For a declaration written in JSX, or a TypeScript type, use `Const`, `Type` or `Function`.
39
+ */
40
+ function Code({ children, name, export: canExport, default: isDefault, space }) {
41
+ return /* @__PURE__ */ jsx("kubb-code", {
42
+ name,
43
+ export: !!canExport,
44
+ default: isDefault,
45
+ space,
46
+ children
47
+ });
35
48
  }
36
49
  // src/components/js/Const.tsx
37
50
  /**
@@ -69,9 +82,9 @@ function Const({ children, ...props }) {
69
82
  * @example Basic file with a source block
70
83
  * ```tsx
71
84
  * <File baseName="petStore.ts" path="src/models/petStore.ts">
72
- * <File.Source name="Pet" isExportable isIndexable>
73
- * {`export type Pet = { id: number; name: string }`}
74
- * </File.Source>
85
+ * <Code name="petSchema" export>
86
+ * {`export const petSchema = z.object({ id: z.number() })`}
87
+ * </Code>
75
88
  * </File>
76
89
  * ```
77
90
  */
@@ -83,47 +96,39 @@ function File({ children, ...props }) {
83
96
  });
84
97
  }
85
98
  /**
86
- * Marks a block of source text to be associated with the enclosing {@link File}.
87
- *
88
- * @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6.
89
- *
90
- * Children are treated as the source string. `isExportable` marks the source as an exported declaration,
91
- * `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
92
- *
93
- * @example Exportable, indexable source block
94
- * ```tsx
95
- * <File.Source name="Pet" isExportable isIndexable>
96
- * {`export type Pet = { id: number; name: string }`}
97
- * </File.Source>
98
- * ```
99
+ * A block of source text in the enclosing {@link File}.
99
100
  *
100
- * @example Type-only source block
101
- * ```tsx
102
- * <File.Source name="PetId" isTypeOnly isExportable>
103
- * {`export type PetId = string`}
104
- * </File.Source>
105
- * ```
101
+ * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
106
102
  */
107
- function FileSource({ children, ...props }) {
108
- return /* @__PURE__ */ jsx("kubb-source", {
109
- ...props,
110
- children
103
+ function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }) {
104
+ return /* @__PURE__ */ jsx("kubb-origin", {
105
+ pointer,
106
+ children: /* @__PURE__ */ jsx("kubb-code", {
107
+ name,
108
+ export: isExport ?? isIndexable,
109
+ default: isDefault,
110
+ space,
111
+ isTypeOnly,
112
+ inline,
113
+ children
114
+ })
111
115
  });
112
116
  }
113
117
  /**
114
118
  * Declares an export entry for the enclosing {@link File}.
115
119
  *
116
- * The export is collected by the renderer and emitted at the top of the generated file.
120
+ * The export is collected by the renderer and emitted at the top of the generated file. A name without a
121
+ * `space` is a value.
117
122
  *
118
123
  * @example Named export
119
124
  * ```tsx
120
- * <File.Export name={['Pet']} path="./models/petStore" />
125
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
121
126
  * // export { Pet } from './models/petStore'
122
127
  * ```
123
128
  *
124
129
  * @example Type-only wildcard export
125
130
  * ```tsx
126
- * <File.Export path="./models/petStore" isTypeOnly />
131
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
127
132
  * // export type * from './models/petStore'
128
133
  * ```
129
134
  */
@@ -133,23 +138,18 @@ function FileExport(props) {
133
138
  /**
134
139
  * Declares an import entry for the enclosing {@link File}.
135
140
  *
136
- * The import is collected by the renderer and emitted at the top of the generated file.
141
+ * The import is collected by the renderer and emitted at the top of the generated file. A name without a
142
+ * `space` is a value.
137
143
  *
138
144
  * @example Named import
139
145
  * ```tsx
140
- * <File.Import name={['useState']} path="react" />
146
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
141
147
  * // import { useState } from 'react'
142
148
  * ```
143
149
  *
144
- * @example Type-only import
145
- * ```tsx
146
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
147
- * // import type { Pet } from './models'
148
- * ```
149
- *
150
150
  * @example Namespace import
151
151
  * ```tsx
152
- * <File.Import name="z" path="zod" isNameSpace />
152
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
153
153
  * // import * as z from 'zod'
154
154
  * ```
155
155
  */
@@ -158,7 +158,7 @@ function FileImport(props) {
158
158
  }
159
159
  File.Export = FileExport;
160
160
  File.Import = FileImport;
161
- /** @deprecated Put `Const`, `Type` or `Function` directly in `File`. They take `inline` too. Removed in Kubb v6. */
161
+ /** @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6. */
162
162
  File.Source = FileSource;
163
163
  // src/components/md/Frontmatter.tsx
164
164
  /**
@@ -180,7 +180,7 @@ File.Source = FileSource;
180
180
  */
181
181
  function Frontmatter({ data }) {
182
182
  const envelope = Object.keys(data).length === 0 ? "" : `---\n${stringify(data).trimEnd()}\n---`;
183
- return /* @__PURE__ */ jsx("kubb-source", { children: envelope });
183
+ return /* @__PURE__ */ jsx("kubb-raw", { children: envelope });
184
184
  }
185
185
  // src/components/js/Function.tsx
186
186
  /**
@@ -236,7 +236,7 @@ Function.Arrow = ArrowFunction;
236
236
  * ```
237
237
  */
238
238
  function Heading({ level, children }) {
239
- return /* @__PURE__ */ jsx("kubb-source", { children: `${"#".repeat(level)} ${children}` });
239
+ return /* @__PURE__ */ jsx("kubb-raw", { children: `${"#".repeat(level)} ${children}` });
240
240
  }
241
241
  // src/components/jsx/Jsx.tsx
242
242
  /**
@@ -277,7 +277,17 @@ function Jsx({ children }) {
277
277
  */
278
278
  function List({ ordered, items }) {
279
279
  const body = items.map((item, index) => `${ordered ? `${index + 1}.` : "-"} ${item}`).join("\n");
280
- return /* @__PURE__ */ jsx("kubb-source", { children: body });
280
+ return /* @__PURE__ */ jsx("kubb-raw", { children: body });
281
+ }
282
+ // src/components/Origin.tsx
283
+ /**
284
+ * Sets the input location of every source inside it. An inner `Origin` wins.
285
+ */
286
+ function Origin({ pointer, children }) {
287
+ return /* @__PURE__ */ jsx("kubb-origin", {
288
+ pointer,
289
+ children
290
+ });
281
291
  }
282
292
  // src/components/md/Paragraph.tsx
283
293
  /**
@@ -293,7 +303,17 @@ function List({ ordered, items }) {
293
303
  * ```
294
304
  */
295
305
  function Paragraph({ children }) {
296
- return /* @__PURE__ */ jsx("kubb-source", { children });
306
+ return /* @__PURE__ */ jsx("kubb-raw", { children });
307
+ }
308
+ // src/components/Raw.tsx
309
+ /**
310
+ * Text in a `File` that declares nothing, such as a statement, JSON or markdown. Barrels leave it out.
311
+ */
312
+ function Raw({ children, name }) {
313
+ return /* @__PURE__ */ jsx("kubb-raw", {
314
+ name,
315
+ children
316
+ });
297
317
  }
298
318
  // src/components/Schema.tsx
299
319
  /**
@@ -309,6 +329,7 @@ function Schema({ node, printer, children }) {
309
329
  const imports = printer.drainImports();
310
330
  if (!output) return null;
311
331
  return /* @__PURE__ */ jsxs(Fragment, { children: [imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
332
+ names: imp.names,
312
333
  name: imp.name,
313
334
  path: imp.path,
314
335
  root: imp.root,
@@ -415,29 +436,52 @@ function collectCodeNodes(element) {
415
436
  });
416
437
  return nodes;
417
438
  }
439
+ /**
440
+ * Gives each source without a pointer the one of the enclosing `Origin`, so the innermost `Origin` wins.
441
+ */
442
+ function withOrigin(sources, pointer) {
443
+ if (!pointer) return sources;
444
+ return sources.map((source) => source.pointer ? source : {
445
+ ...source,
446
+ pointer
447
+ });
448
+ }
418
449
  function collectFileChildren(element) {
419
450
  const sources = [];
420
451
  const exports = [];
421
452
  const imports = [];
422
453
  walkElement(element, (text) => {
423
- if (text.trim()) throw new Error(`[jsx] '${text}' should be part of <File.Source> component when using the <File/> component`);
454
+ if (text.trim()) throw new Error(`[jsx] '${text}' should be part of a <Code> or <Raw> component when using the <File/> component`);
424
455
  }, (host) => {
425
- if (host.type === "kubb-source") {
426
- const { name, pointer, isTypeOnly, isExportable, isIndexable, inline, children } = host.props;
456
+ if (host.type === "kubb-code") {
457
+ const { name, space, isTypeOnly, export: isExport, default: isDefault, inline, children } = host.props;
427
458
  sources.push(ast.factory.createSource({
428
459
  name: name?.toString(),
429
- ...pointer !== void 0 ? { pointer } : {},
460
+ ...space ? { space } : {},
430
461
  isTypeOnly: !!isTypeOnly,
431
- isExportable: !!isExportable,
432
- isIndexable: !!isIndexable,
462
+ export: !!isExport,
463
+ ...isDefault ? { default: true } : {},
433
464
  ...inline ? { inline } : {},
434
465
  nodes: collectCodeNodes(children)
435
466
  }));
436
467
  return;
437
468
  }
469
+ if (host.type === "kubb-raw") {
470
+ const { name, children } = host.props;
471
+ sources.push(ast.factory.createSource({
472
+ name: name?.toString(),
473
+ isTypeOnly: false,
474
+ export: false,
475
+ nodes: collectCodeNodes(children)
476
+ }));
477
+ return;
478
+ }
438
479
  if (host.type === "kubb-export") {
439
- const { name, path, isTypeOnly, asAlias } = host.props;
440
- exports.push(ast.factory.createExport({
480
+ const { names, name, path, isTypeOnly, asAlias } = host.props;
481
+ exports.push(names ? ast.factory.createExport({
482
+ names,
483
+ path
484
+ }) : ast.factory.createExport({
441
485
  name,
442
486
  path,
443
487
  isTypeOnly: !!isTypeOnly,
@@ -446,8 +490,12 @@ function collectFileChildren(element) {
446
490
  return;
447
491
  }
448
492
  if (host.type === "kubb-import") {
449
- const { name, path, root, isTypeOnly, isNameSpace } = host.props;
450
- imports.push(ast.factory.createImport({
493
+ const { names, name, path, root, isTypeOnly, isNameSpace } = host.props;
494
+ imports.push(names ? ast.factory.createImport({
495
+ names,
496
+ path,
497
+ root
498
+ }) : ast.factory.createImport({
451
499
  name,
452
500
  path,
453
501
  root,
@@ -463,15 +511,15 @@ function collectFileChildren(element) {
463
511
  sources.push(ast.factory.createSource({
464
512
  name,
465
513
  isTypeOnly: host.type === "kubb-type",
466
- isExportable: !!canExport,
467
- isIndexable: !!canExport && !isDefault,
514
+ export: !!canExport,
515
+ ...isDefault ? { default: true } : {},
468
516
  ...inline && "nodes" in node ? { inline: { expression: ast.node.getText(node.nodes) } } : {},
469
517
  nodes: [node]
470
518
  }));
471
519
  return;
472
520
  }
473
521
  const nested = collectFileChildren(childrenOf(host));
474
- sources.push(...nested.sources);
522
+ sources.push(...host.type === "kubb-origin" ? withOrigin(nested.sources, host.props.pointer) : nested.sources);
475
523
  exports.push(...nested.exports);
476
524
  imports.push(...nested.imports);
477
525
  });
@@ -490,6 +538,7 @@ function createFileNode(props) {
490
538
  footer: props.footer,
491
539
  banner: props.banner,
492
540
  copy: props.copy,
541
+ inline: props.inline,
493
542
  sources,
494
543
  exports,
495
544
  imports
@@ -541,6 +590,6 @@ const jsxRenderer = () => {
541
590
  [Symbol.dispose]() {}
542
591
  };
543
592
  };
544
- export { Callout, Const, File, Frontmatter, Function, Heading, Jsx, List, Paragraph, Schema, Type, jsxRenderer };
593
+ export { Callout, Code, Const, File, Frontmatter, Function, Heading, Jsx, List, Origin, Paragraph, Raw, Schema, Type, jsxRenderer };
545
594
 
546
595
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { i as KubbReactNode, n as Key, r as KubbReactElement } from "./types-D_u8uaRO.cjs";
1
+ import { i as KubbReactNode, n as Key, r as KubbReactElement } from "./types-CpFFjEcD.cjs";
2
2
  import { ast } from "@kubb/ast";
3
3
  /**
4
4
  * JSX contract for `@kubb/renderer-jsx`, resolved through `jsxImportSource`.
@@ -25,11 +25,17 @@ declare namespace JSX {
25
25
  id?: string | null;
26
26
  children?: KubbReactNode;
27
27
  };
28
- ['kubb-source']: Omit<ast.SourceNode, 'kind'> & {
28
+ ['kubb-origin']: Pick<ast.SourceNode, 'pointer'> & {
29
29
  children?: KubbReactNode;
30
30
  };
31
- ['kubb-import']: Omit<ast.ImportNode, 'kind'> & {};
32
- ['kubb-export']: Omit<ast.ExportNode, 'kind'> & {};
31
+ ['kubb-code']: Pick<ast.SourceNode, 'name' | 'export' | 'default' | 'space' | 'isTypeOnly' | 'inline'> & {
32
+ children?: KubbReactNode;
33
+ };
34
+ ['kubb-raw']: Pick<ast.SourceNode, 'name'> & {
35
+ children?: KubbReactNode;
36
+ };
37
+ ['kubb-import']: ast.ImportInput & {};
38
+ ['kubb-export']: ast.ExportInput & {};
33
39
  ['kubb-function']: Omit<ast.FunctionNode, 'kind'> & {
34
40
  inline?: boolean;
35
41
  children?: KubbReactNode;
@@ -1,4 +1,4 @@
1
- import { i as KubbReactNode, n as Key, r as KubbReactElement } from "./types-D_u8uaRO.js";
1
+ import { i as KubbReactNode, n as Key, r as KubbReactElement } from "./types-BiISTVBi.js";
2
2
  import { ast } from "@kubb/ast";
3
3
  /**
4
4
  * JSX contract for `@kubb/renderer-jsx`, resolved through `jsxImportSource`.
@@ -25,11 +25,17 @@ declare namespace JSX {
25
25
  id?: string | null;
26
26
  children?: KubbReactNode;
27
27
  };
28
- ['kubb-source']: Omit<ast.SourceNode, 'kind'> & {
28
+ ['kubb-origin']: Pick<ast.SourceNode, 'pointer'> & {
29
29
  children?: KubbReactNode;
30
30
  };
31
- ['kubb-import']: Omit<ast.ImportNode, 'kind'> & {};
32
- ['kubb-export']: Omit<ast.ExportNode, 'kind'> & {};
31
+ ['kubb-code']: Pick<ast.SourceNode, 'name' | 'export' | 'default' | 'space' | 'isTypeOnly' | 'inline'> & {
32
+ children?: KubbReactNode;
33
+ };
34
+ ['kubb-raw']: Pick<ast.SourceNode, 'name'> & {
35
+ children?: KubbReactNode;
36
+ };
37
+ ['kubb-import']: ast.ImportInput & {};
38
+ ['kubb-export']: ast.ExportInput & {};
33
39
  ['kubb-function']: Omit<ast.FunctionNode, 'kind'> & {
34
40
  inline?: boolean;
35
41
  children?: KubbReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.23.2",
3
+ "version": "5.23.4",
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.23.2",
97
+ "@kubb/ast": "^5.23.4",
98
98
  "yaml": "^2.9.1"
99
99
  },
100
100
  "engines": {