@kubb/renderer-jsx 5.23.3 → 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/dist/index.cjs CHANGED
@@ -38,11 +38,12 @@ function Callout({ type, title, children }) {
38
38
  /**
39
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
40
  */
41
- function Code({ children, name, export: canExport, default: isDefault }) {
41
+ function Code({ children, name, export: canExport, default: isDefault, space }) {
42
42
  return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-code", {
43
43
  name,
44
44
  export: !!canExport,
45
45
  default: isDefault,
46
+ space,
46
47
  children
47
48
  });
48
49
  }
@@ -100,13 +101,14 @@ function File({ children, ...props }) {
100
101
  *
101
102
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
102
103
  */
103
- function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isTypeOnly, inline }) {
104
+ function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }) {
104
105
  return /* @__PURE__ */ require_jsx_runtime.jsx("kubb-origin", {
105
106
  pointer,
106
107
  children: /* @__PURE__ */ require_jsx_runtime.jsx("kubb-code", {
107
108
  name,
108
109
  export: isExport ?? isIndexable,
109
110
  default: isDefault,
111
+ space,
110
112
  isTypeOnly,
111
113
  inline,
112
114
  children
@@ -116,17 +118,18 @@ function FileSource({ children, name, pointer, export: isExport, default: isDefa
116
118
  /**
117
119
  * Declares an export entry for the enclosing {@link File}.
118
120
  *
119
- * 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.
120
123
  *
121
124
  * @example Named export
122
125
  * ```tsx
123
- * <File.Export name={['Pet']} path="./models/petStore" />
126
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
124
127
  * // export { Pet } from './models/petStore'
125
128
  * ```
126
129
  *
127
130
  * @example Type-only wildcard export
128
131
  * ```tsx
129
- * <File.Export path="./models/petStore" isTypeOnly />
132
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
130
133
  * // export type * from './models/petStore'
131
134
  * ```
132
135
  */
@@ -136,23 +139,18 @@ function FileExport(props) {
136
139
  /**
137
140
  * Declares an import entry for the enclosing {@link File}.
138
141
  *
139
- * 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.
140
144
  *
141
145
  * @example Named import
142
146
  * ```tsx
143
- * <File.Import name={['useState']} path="react" />
147
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
144
148
  * // import { useState } from 'react'
145
149
  * ```
146
150
  *
147
- * @example Type-only import
148
- * ```tsx
149
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
150
- * // import type { Pet } from './models'
151
- * ```
152
- *
153
151
  * @example Namespace import
154
152
  * ```tsx
155
- * <File.Import name="z" path="zod" isNameSpace />
153
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
156
154
  * // import * as z from 'zod'
157
155
  * ```
158
156
  */
@@ -332,6 +330,7 @@ function Schema({ node, printer, children }) {
332
330
  const imports = printer.drainImports();
333
331
  if (!output) return null;
334
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,
335
334
  name: imp.name,
336
335
  path: imp.path,
337
336
  root: imp.root,
@@ -456,9 +455,10 @@ function collectFileChildren(element) {
456
455
  if (text.trim()) throw new Error(`[jsx] '${text}' should be part of a <Code> or <Raw> component when using the <File/> component`);
457
456
  }, (host) => {
458
457
  if (host.type === "kubb-code") {
459
- const { name, isTypeOnly, export: isExport, default: isDefault, inline, children } = host.props;
458
+ const { name, space, isTypeOnly, export: isExport, default: isDefault, inline, children } = host.props;
460
459
  sources.push(_kubb_ast.ast.factory.createSource({
461
460
  name: name?.toString(),
461
+ ...space ? { space } : {},
462
462
  isTypeOnly: !!isTypeOnly,
463
463
  export: !!isExport,
464
464
  ...isDefault ? { default: true } : {},
@@ -478,8 +478,11 @@ function collectFileChildren(element) {
478
478
  return;
479
479
  }
480
480
  if (host.type === "kubb-export") {
481
- const { name, path, isTypeOnly, asAlias } = host.props;
482
- 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({
483
486
  name,
484
487
  path,
485
488
  isTypeOnly: !!isTypeOnly,
@@ -488,8 +491,12 @@ function collectFileChildren(element) {
488
491
  return;
489
492
  }
490
493
  if (host.type === "kubb-import") {
491
- const { name, path, root, isTypeOnly, isNameSpace } = host.props;
492
- 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({
493
500
  name,
494
501
  path,
495
502
  root,
package/dist/index.d.cts CHANGED
@@ -53,12 +53,17 @@ type Props$10 = {
53
53
  * Marks an exported declaration as the default export, which barrels skip.
54
54
  */
55
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;
56
61
  children?: KubbReactNode;
57
62
  };
58
63
  /**
59
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`.
60
65
  */
61
- export declare function Code({ children, name, export: canExport, default: isDefault }: Props$10): KubbReactElement;
66
+ export declare function Code({ children, name, export: canExport, default: isDefault, space }: Props$10): KubbReactElement;
62
67
  type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
63
68
  key?: Key;
64
69
  /**
@@ -147,51 +152,47 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value' | 'nodes'> & {
147
152
  *
148
153
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
149
154
  */
150
- declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
151
- 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 & {
152
157
  key?: Key;
153
158
  };
154
159
  /**
155
160
  * Declares an export entry for the enclosing {@link File}.
156
161
  *
157
- * 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.
158
164
  *
159
165
  * @example Named export
160
166
  * ```tsx
161
- * <File.Export name={['Pet']} path="./models/petStore" />
167
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
162
168
  * // export { Pet } from './models/petStore'
163
169
  * ```
164
170
  *
165
171
  * @example Type-only wildcard export
166
172
  * ```tsx
167
- * <File.Export path="./models/petStore" isTypeOnly />
173
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
168
174
  * // export type * from './models/petStore'
169
175
  * ```
170
176
  */
171
177
  declare function FileExport(props: FileExportProps): KubbReactElement;
172
- type FileImportProps = Omit<ast.ImportNode, 'kind'> & {
178
+ type FileImportProps = ast.ImportInput & {
173
179
  key?: Key;
174
180
  };
175
181
  /**
176
182
  * Declares an import entry for the enclosing {@link File}.
177
183
  *
178
- * 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.
179
186
  *
180
187
  * @example Named import
181
188
  * ```tsx
182
- * <File.Import name={['useState']} path="react" />
189
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
183
190
  * // import { useState } from 'react'
184
191
  * ```
185
192
  *
186
- * @example Type-only import
187
- * ```tsx
188
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
189
- * // import type { Pet } from './models'
190
- * ```
191
- *
192
193
  * @example Namespace import
193
194
  * ```tsx
194
- * <File.Import name="z" path="zod" isNameSpace />
195
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
195
196
  * // import * as z from 'zod'
196
197
  * ```
197
198
  */
package/dist/index.d.ts CHANGED
@@ -53,12 +53,17 @@ type Props$10 = {
53
53
  * Marks an exported declaration as the default export, which barrels skip.
54
54
  */
55
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;
56
61
  children?: KubbReactNode;
57
62
  };
58
63
  /**
59
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`.
60
65
  */
61
- export declare function Code({ children, name, export: canExport, default: isDefault }: Props$10): KubbReactElement;
66
+ export declare function Code({ children, name, export: canExport, default: isDefault, space }: Props$10): KubbReactElement;
62
67
  type ConstProps = Omit<ast.ConstNode, 'kind' | 'nodes'> & {
63
68
  key?: Key;
64
69
  /**
@@ -147,51 +152,47 @@ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value' | 'nodes'> & {
147
152
  *
148
153
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
149
154
  */
150
- declare function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isTypeOnly, inline }: FileSourceProps): KubbReactElement;
151
- 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 & {
152
157
  key?: Key;
153
158
  };
154
159
  /**
155
160
  * Declares an export entry for the enclosing {@link File}.
156
161
  *
157
- * 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.
158
164
  *
159
165
  * @example Named export
160
166
  * ```tsx
161
- * <File.Export name={['Pet']} path="./models/petStore" />
167
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
162
168
  * // export { Pet } from './models/petStore'
163
169
  * ```
164
170
  *
165
171
  * @example Type-only wildcard export
166
172
  * ```tsx
167
- * <File.Export path="./models/petStore" isTypeOnly />
173
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
168
174
  * // export type * from './models/petStore'
169
175
  * ```
170
176
  */
171
177
  declare function FileExport(props: FileExportProps): KubbReactElement;
172
- type FileImportProps = Omit<ast.ImportNode, 'kind'> & {
178
+ type FileImportProps = ast.ImportInput & {
173
179
  key?: Key;
174
180
  };
175
181
  /**
176
182
  * Declares an import entry for the enclosing {@link File}.
177
183
  *
178
- * 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.
179
186
  *
180
187
  * @example Named import
181
188
  * ```tsx
182
- * <File.Import name={['useState']} path="react" />
189
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
183
190
  * // import { useState } from 'react'
184
191
  * ```
185
192
  *
186
- * @example Type-only import
187
- * ```tsx
188
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
189
- * // import type { Pet } from './models'
190
- * ```
191
- *
192
193
  * @example Namespace import
193
194
  * ```tsx
194
- * <File.Import name="z" path="zod" isNameSpace />
195
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
195
196
  * // import * as z from 'zod'
196
197
  * ```
197
198
  */
package/dist/index.js CHANGED
@@ -37,11 +37,12 @@ function Callout({ type, title, children }) {
37
37
  /**
38
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
39
  */
40
- function Code({ children, name, export: canExport, default: isDefault }) {
40
+ function Code({ children, name, export: canExport, default: isDefault, space }) {
41
41
  return /* @__PURE__ */ jsx("kubb-code", {
42
42
  name,
43
43
  export: !!canExport,
44
44
  default: isDefault,
45
+ space,
45
46
  children
46
47
  });
47
48
  }
@@ -99,13 +100,14 @@ function File({ children, ...props }) {
99
100
  *
100
101
  * @deprecated Use `Code` or `Raw`, or put `Const`, `Type` or `Function` directly in `File`. Removed in Kubb v6.
101
102
  */
102
- function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, isTypeOnly, inline }) {
103
+ function FileSource({ children, name, pointer, export: isExport, default: isDefault, isIndexable, space, isTypeOnly, inline }) {
103
104
  return /* @__PURE__ */ jsx("kubb-origin", {
104
105
  pointer,
105
106
  children: /* @__PURE__ */ jsx("kubb-code", {
106
107
  name,
107
108
  export: isExport ?? isIndexable,
108
109
  default: isDefault,
110
+ space,
109
111
  isTypeOnly,
110
112
  inline,
111
113
  children
@@ -115,17 +117,18 @@ function FileSource({ children, name, pointer, export: isExport, default: isDefa
115
117
  /**
116
118
  * Declares an export entry for the enclosing {@link File}.
117
119
  *
118
- * 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.
119
122
  *
120
123
  * @example Named export
121
124
  * ```tsx
122
- * <File.Export name={['Pet']} path="./models/petStore" />
125
+ * <File.Export names={[{ name: 'Pet' }]} path="./models/petStore" />
123
126
  * // export { Pet } from './models/petStore'
124
127
  * ```
125
128
  *
126
129
  * @example Type-only wildcard export
127
130
  * ```tsx
128
- * <File.Export path="./models/petStore" isTypeOnly />
131
+ * <File.Export names={[{ name: '*', space: 'type' }]} path="./models/petStore" />
129
132
  * // export type * from './models/petStore'
130
133
  * ```
131
134
  */
@@ -135,23 +138,18 @@ function FileExport(props) {
135
138
  /**
136
139
  * Declares an import entry for the enclosing {@link File}.
137
140
  *
138
- * 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.
139
143
  *
140
144
  * @example Named import
141
145
  * ```tsx
142
- * <File.Import name={['useState']} path="react" />
146
+ * <File.Import names={[{ name: 'useState', space: 'value' }]} path="react" />
143
147
  * // import { useState } from 'react'
144
148
  * ```
145
149
  *
146
- * @example Type-only import
147
- * ```tsx
148
- * <File.Import name={['Pet']} path="./models" isTypeOnly />
149
- * // import type { Pet } from './models'
150
- * ```
151
- *
152
150
  * @example Namespace import
153
151
  * ```tsx
154
- * <File.Import name="z" path="zod" isNameSpace />
152
+ * <File.Import names={[{ name: '*', alias: 'z', space: 'value' }]} path="zod" />
155
153
  * // import * as z from 'zod'
156
154
  * ```
157
155
  */
@@ -331,6 +329,7 @@ function Schema({ node, printer, children }) {
331
329
  const imports = printer.drainImports();
332
330
  if (!output) return null;
333
331
  return /* @__PURE__ */ jsxs(Fragment, { children: [imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
332
+ names: imp.names,
334
333
  name: imp.name,
335
334
  path: imp.path,
336
335
  root: imp.root,
@@ -455,9 +454,10 @@ function collectFileChildren(element) {
455
454
  if (text.trim()) throw new Error(`[jsx] '${text}' should be part of a <Code> or <Raw> component when using the <File/> component`);
456
455
  }, (host) => {
457
456
  if (host.type === "kubb-code") {
458
- const { name, isTypeOnly, export: isExport, default: isDefault, inline, children } = host.props;
457
+ const { name, space, isTypeOnly, export: isExport, default: isDefault, inline, children } = host.props;
459
458
  sources.push(ast.factory.createSource({
460
459
  name: name?.toString(),
460
+ ...space ? { space } : {},
461
461
  isTypeOnly: !!isTypeOnly,
462
462
  export: !!isExport,
463
463
  ...isDefault ? { default: true } : {},
@@ -477,8 +477,11 @@ function collectFileChildren(element) {
477
477
  return;
478
478
  }
479
479
  if (host.type === "kubb-export") {
480
- const { name, path, isTypeOnly, asAlias } = host.props;
481
- 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({
482
485
  name,
483
486
  path,
484
487
  isTypeOnly: !!isTypeOnly,
@@ -487,8 +490,12 @@ function collectFileChildren(element) {
487
490
  return;
488
491
  }
489
492
  if (host.type === "kubb-import") {
490
- const { name, path, root, isTypeOnly, isNameSpace } = host.props;
491
- 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({
492
499
  name,
493
500
  path,
494
501
  root,
@@ -28,14 +28,14 @@ declare namespace JSX {
28
28
  ['kubb-origin']: Pick<ast.SourceNode, 'pointer'> & {
29
29
  children?: KubbReactNode;
30
30
  };
31
- ['kubb-code']: Pick<ast.SourceNode, 'name' | 'export' | 'default' | 'isTypeOnly' | 'inline'> & {
31
+ ['kubb-code']: Pick<ast.SourceNode, 'name' | 'export' | 'default' | 'space' | 'isTypeOnly' | 'inline'> & {
32
32
  children?: KubbReactNode;
33
33
  };
34
34
  ['kubb-raw']: Pick<ast.SourceNode, 'name'> & {
35
35
  children?: KubbReactNode;
36
36
  };
37
- ['kubb-import']: Omit<ast.ImportNode, 'kind'> & {};
38
- ['kubb-export']: Omit<ast.ExportNode, 'kind'> & {};
37
+ ['kubb-import']: ast.ImportInput & {};
38
+ ['kubb-export']: ast.ExportInput & {};
39
39
  ['kubb-function']: Omit<ast.FunctionNode, 'kind'> & {
40
40
  inline?: boolean;
41
41
  children?: KubbReactNode;
@@ -28,14 +28,14 @@ declare namespace JSX {
28
28
  ['kubb-origin']: Pick<ast.SourceNode, 'pointer'> & {
29
29
  children?: KubbReactNode;
30
30
  };
31
- ['kubb-code']: Pick<ast.SourceNode, 'name' | 'export' | 'default' | 'isTypeOnly' | 'inline'> & {
31
+ ['kubb-code']: Pick<ast.SourceNode, 'name' | 'export' | 'default' | 'space' | 'isTypeOnly' | 'inline'> & {
32
32
  children?: KubbReactNode;
33
33
  };
34
34
  ['kubb-raw']: Pick<ast.SourceNode, 'name'> & {
35
35
  children?: KubbReactNode;
36
36
  };
37
- ['kubb-import']: Omit<ast.ImportNode, 'kind'> & {};
38
- ['kubb-export']: Omit<ast.ExportNode, 'kind'> & {};
37
+ ['kubb-import']: ast.ImportInput & {};
38
+ ['kubb-export']: ast.ExportInput & {};
39
39
  ['kubb-function']: Omit<ast.FunctionNode, 'kind'> & {
40
40
  inline?: boolean;
41
41
  children?: KubbReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.23.3",
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.3",
97
+ "@kubb/ast": "^5.23.4",
98
98
  "yaml": "^2.9.1"
99
99
  },
100
100
  "engines": {