@kubb/renderer-jsx 5.0.0-alpha.34 → 5.0.0-alpha.35
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/{chunk-CErwXX-a.js → chunk-Bb7HlUDG.js} +1 -1
- package/dist/index.cjs +271 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +336 -47
- package/dist/index.js +273 -110
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.cjs +1 -1
- package/dist/jsx-dev-runtime.d.ts +3 -3
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/{jsx-namespace-Cx1KMEbe.d.ts → jsx-namespace-DdqdFHqm.d.ts} +3 -3
- package/dist/{jsx-runtime-Dmf9wTKR.js → jsx-runtime-7z5lYBqC.js} +2 -2
- package/dist/{jsx-runtime-Dmf9wTKR.js.map → jsx-runtime-7z5lYBqC.js.map} +1 -1
- package/dist/{jsx-runtime-CeMde2cR.cjs → jsx-runtime-Dnd1wztY.cjs} +2 -2
- package/dist/{jsx-runtime-CeMde2cR.cjs.map → jsx-runtime-Dnd1wztY.cjs.map} +1 -1
- package/dist/jsx-runtime.cjs +1 -1
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +2 -2
- package/dist/types-BEu94Tb3.d.ts +176 -0
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/Runtime.tsx +3 -4
- package/src/components/Const.tsx +35 -7
- package/src/components/File.tsx +96 -16
- package/src/components/Function.tsx +59 -14
- package/src/components/Root.tsx +11 -5
- package/src/components/Type.tsx +32 -6
- package/src/constants.ts +28 -0
- package/src/context/KubbContext.ts +1 -1
- package/src/createRenderer.tsx +64 -3
- package/src/dom.ts +35 -21
- package/src/index.ts +1 -1
- package/src/types.ts +107 -5
- package/src/utils.ts +74 -108
- package/dist/types-C7FD9BLg.d.ts +0 -119
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as __name, r as __toESM, t as __commonJSMin } from "./chunk-
|
|
2
|
-
import { n as require_react } from "./jsx-runtime-
|
|
1
|
+
import { n as __name, r as __toESM, t as __commonJSMin } from "./chunk-Bb7HlUDG.js";
|
|
2
|
+
import { n as require_react } from "./jsx-runtime-7z5lYBqC.js";
|
|
3
3
|
import { Fragment, jsx } from "./jsx-runtime.js";
|
|
4
|
-
import { createArrowFunction, createBreak, createConst, createFunction, createJsx, createSource, createText, createType } from "@kubb/ast";
|
|
4
|
+
import { createArrowFunction, createBreak, createConst, createExport, createFunction, createImport, createJsx, createSource, createText, createType } from "@kubb/ast";
|
|
5
5
|
//#region ../../internals/utils/src/context.ts
|
|
6
6
|
/**
|
|
7
7
|
* Context stack for tracking the current context values
|
|
@@ -109,6 +109,21 @@ function onProcessExit(callback) {
|
|
|
109
109
|
//#region src/components/Const.tsx
|
|
110
110
|
/**
|
|
111
111
|
* Generates a TypeScript constant declaration.
|
|
112
|
+
*
|
|
113
|
+
* @example Named export with type annotation
|
|
114
|
+
* ```tsx
|
|
115
|
+
* <Const export name="petSchema" type="z.ZodType<Pet>">
|
|
116
|
+
* {`z.object({ id: z.number() })`}
|
|
117
|
+
* </Const>
|
|
118
|
+
* // export const petSchema: z.ZodType<Pet> = z.object({ id: z.number() })
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @example With JSDoc and const assertion
|
|
122
|
+
* ```tsx
|
|
123
|
+
* <Const name="HTTP_METHODS" asConst JSDoc={{ comments: ['@description Supported HTTP methods.'] }}>
|
|
124
|
+
* {`['GET', 'POST', 'PUT', 'DELETE']`}
|
|
125
|
+
* </Const>
|
|
126
|
+
* ```
|
|
112
127
|
*/
|
|
113
128
|
function Const({ children, ...props }) {
|
|
114
129
|
const { name, export: canExport, type, JSDoc, asConst } = props;
|
|
@@ -125,7 +140,20 @@ Const.displayName = "Const";
|
|
|
125
140
|
//#endregion
|
|
126
141
|
//#region src/components/File.tsx
|
|
127
142
|
/**
|
|
128
|
-
*
|
|
143
|
+
* Declares a generated file entry to be collected by the renderer.
|
|
144
|
+
*
|
|
145
|
+
* When both `baseName` and `path` are provided, the component registers a new
|
|
146
|
+
* `FileNode` and passes its children through as source blocks.
|
|
147
|
+
* When either is omitted the children are rendered inline without creating a file entry.
|
|
148
|
+
*
|
|
149
|
+
* @example Basic file with a source block
|
|
150
|
+
* ```tsx
|
|
151
|
+
* <File baseName="petStore.ts" path="src/models/petStore.ts">
|
|
152
|
+
* <File.Source name="Pet" isExportable isIndexable>
|
|
153
|
+
* {`export type Pet = { id: number; name: string }`}
|
|
154
|
+
* </File.Source>
|
|
155
|
+
* </File>
|
|
156
|
+
* ```
|
|
129
157
|
*/
|
|
130
158
|
function File({ children, ...props }) {
|
|
131
159
|
const { baseName, path } = props;
|
|
@@ -137,10 +165,24 @@ function File({ children, ...props }) {
|
|
|
137
165
|
}
|
|
138
166
|
File.displayName = "File";
|
|
139
167
|
/**
|
|
140
|
-
* File.
|
|
168
|
+
* Marks a block of source text to be associated with the enclosing {@link File}.
|
|
169
|
+
*
|
|
170
|
+
* Children are treated as the source string. When `isExportable` is `true` the
|
|
171
|
+
* `name` is used for deduplication and barrel generation.
|
|
172
|
+
*
|
|
173
|
+
* @example Exportable, indexable source block
|
|
174
|
+
* ```tsx
|
|
175
|
+
* <File.Source name="Pet" isExportable isIndexable>
|
|
176
|
+
* {`export type Pet = { id: number; name: string }`}
|
|
177
|
+
* </File.Source>
|
|
178
|
+
* ```
|
|
141
179
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
180
|
+
* @example Type-only source block
|
|
181
|
+
* ```tsx
|
|
182
|
+
* <File.Source name="PetId" isTypeOnly isExportable>
|
|
183
|
+
* {`export type PetId = string`}
|
|
184
|
+
* </File.Source>
|
|
185
|
+
* ```
|
|
144
186
|
*/
|
|
145
187
|
function FileSource({ children, ...props }) {
|
|
146
188
|
const { name, isExportable, isIndexable, isTypeOnly } = props;
|
|
@@ -154,10 +196,21 @@ function FileSource({ children, ...props }) {
|
|
|
154
196
|
}
|
|
155
197
|
FileSource.displayName = "FileSource";
|
|
156
198
|
/**
|
|
157
|
-
* File.
|
|
199
|
+
* Declares an export entry for the enclosing {@link File}.
|
|
158
200
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
201
|
+
* The export is collected by the renderer and emitted at the top of the generated file.
|
|
202
|
+
*
|
|
203
|
+
* @example Named export
|
|
204
|
+
* ```tsx
|
|
205
|
+
* <File.Export name={['Pet']} path="./models/petStore" />
|
|
206
|
+
* // export { Pet } from './models/petStore'
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example Type-only wildcard export
|
|
210
|
+
* ```tsx
|
|
211
|
+
* <File.Export path="./models/petStore" isTypeOnly />
|
|
212
|
+
* // export type * from './models/petStore'
|
|
213
|
+
* ```
|
|
161
214
|
*/
|
|
162
215
|
function FileExport(props) {
|
|
163
216
|
const { name, path, isTypeOnly, asAlias } = props;
|
|
@@ -170,9 +223,27 @@ function FileExport(props) {
|
|
|
170
223
|
}
|
|
171
224
|
FileExport.displayName = "FileExport";
|
|
172
225
|
/**
|
|
173
|
-
* File.
|
|
226
|
+
* Declares an import entry for the enclosing {@link File}.
|
|
227
|
+
*
|
|
228
|
+
* The import is collected by the renderer and emitted at the top of the generated file.
|
|
174
229
|
*
|
|
175
|
-
*
|
|
230
|
+
* @example Named import
|
|
231
|
+
* ```tsx
|
|
232
|
+
* <File.Import name={['useState']} path="react" />
|
|
233
|
+
* // import { useState } from 'react'
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @example Type-only import
|
|
237
|
+
* ```tsx
|
|
238
|
+
* <File.Import name={['Pet']} path="./models" isTypeOnly />
|
|
239
|
+
* // import type { Pet } from './models'
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @example Namespace import
|
|
243
|
+
* ```tsx
|
|
244
|
+
* <File.Import name="z" path="zod" isNameSpace />
|
|
245
|
+
* // import * as z from 'zod'
|
|
246
|
+
* ```
|
|
176
247
|
*/
|
|
177
248
|
function FileImport(props) {
|
|
178
249
|
const { name, root, path, isTypeOnly, isNameSpace } = props;
|
|
@@ -192,6 +263,16 @@ File.Source = FileSource;
|
|
|
192
263
|
//#region src/components/Function.tsx
|
|
193
264
|
/**
|
|
194
265
|
* Generates a TypeScript function declaration.
|
|
266
|
+
*
|
|
267
|
+
* @example Async exported function with generics
|
|
268
|
+
* ```tsx
|
|
269
|
+
* <Function export async name="getPet" generics={['TData = Pet']} params="petId: string" returnType="TData">
|
|
270
|
+
* {`return client.get(\`/pets/\${petId}\`)`}
|
|
271
|
+
* </Function>
|
|
272
|
+
* // export async function getPet<TData = Pet>(petId: string): Promise<TData> {
|
|
273
|
+
* // return client.get(`/pets/${petId}`)
|
|
274
|
+
* // }
|
|
275
|
+
* ```
|
|
195
276
|
*/
|
|
196
277
|
function Function$1({ children, ...props }) {
|
|
197
278
|
const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc } = props;
|
|
@@ -210,10 +291,17 @@ function Function$1({ children, ...props }) {
|
|
|
210
291
|
__name(Function$1, "Function");
|
|
211
292
|
Function$1.displayName = "Function";
|
|
212
293
|
/**
|
|
213
|
-
*
|
|
294
|
+
* Generates an arrow function expression assigned to a `const`.
|
|
295
|
+
* Supports the same flags as {@link Function}.
|
|
296
|
+
* Use `singleLine` to render the body as a concise expression rather than a block.
|
|
214
297
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
298
|
+
* @example Single-line arrow function
|
|
299
|
+
* ```tsx
|
|
300
|
+
* <Function.Arrow export name="double" params="n: number" returnType="number" singleLine>
|
|
301
|
+
* {`n * 2`}
|
|
302
|
+
* </Function.Arrow>
|
|
303
|
+
* // export const double = (n: number): number => n * 2
|
|
304
|
+
* ```
|
|
217
305
|
*/
|
|
218
306
|
function ArrowFunction({ children, ...props }) {
|
|
219
307
|
const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props;
|
|
@@ -271,7 +359,10 @@ var ErrorBoundary = class extends import_react.Component {
|
|
|
271
359
|
}
|
|
272
360
|
};
|
|
273
361
|
/**
|
|
274
|
-
*
|
|
362
|
+
* Root component for the Kubb renderer tree.
|
|
363
|
+
*
|
|
364
|
+
* Wraps all children in an `ErrorBoundary` so that render errors are caught
|
|
365
|
+
* and forwarded to `onError` rather than crashing the process.
|
|
275
366
|
*/
|
|
276
367
|
function Root({ onError, children }) {
|
|
277
368
|
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
@@ -285,7 +376,25 @@ Root.displayName = "Root";
|
|
|
285
376
|
//#endregion
|
|
286
377
|
//#region src/components/Type.tsx
|
|
287
378
|
/**
|
|
288
|
-
* Generates a TypeScript type declaration.
|
|
379
|
+
* Generates a TypeScript type alias declaration.
|
|
380
|
+
*
|
|
381
|
+
* Throws if `name` does not start with an uppercase letter — TypeScript type aliases
|
|
382
|
+
* should follow PascalCase naming conventions.
|
|
383
|
+
*
|
|
384
|
+
* @example Simple exported type alias
|
|
385
|
+
* ```tsx
|
|
386
|
+
* <Type export name="PetId">
|
|
387
|
+
* {`string | number`}
|
|
388
|
+
* </Type>
|
|
389
|
+
* // export type PetId = string | number
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* @example Type alias with JSDoc
|
|
393
|
+
* ```tsx
|
|
394
|
+
* <Type export name="Pet" JSDoc={{ comments: ['@description A pet in the store.'] }}>
|
|
395
|
+
* {`{ id: number; name: string }`}
|
|
396
|
+
* </Type>
|
|
397
|
+
* ```
|
|
289
398
|
*/
|
|
290
399
|
function Type({ children, ...props }) {
|
|
291
400
|
const { name, export: canExport, JSDoc } = props;
|
|
@@ -351,11 +460,42 @@ var require_react_reconciler_constants_development = /* @__PURE__ */ __commonJSM
|
|
|
351
460
|
"production" !== process.env.NODE_ENV && (exports.ConcurrentRoot = 1, exports.ContinuousEventPriority = 8, exports.DefaultEventPriority = 32, exports.DiscreteEventPriority = 2, exports.IdleEventPriority = 268435456, exports.LegacyRoot = 0, exports.NoEventPriority = 0);
|
|
352
461
|
}));
|
|
353
462
|
//#endregion
|
|
354
|
-
//#region src/
|
|
463
|
+
//#region src/constants.ts
|
|
355
464
|
var import_constants = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
356
465
|
if (process.env.NODE_ENV === "production") module.exports = require_react_reconciler_constants_production();
|
|
357
466
|
else module.exports = require_react_reconciler_constants_development();
|
|
358
467
|
})))();
|
|
468
|
+
/**
|
|
469
|
+
* Name used for text-node entries in the virtual DOM.
|
|
470
|
+
*/
|
|
471
|
+
const TEXT_NODE_NAME = "#text";
|
|
472
|
+
/**
|
|
473
|
+
* Set of all element names recognized by the Kubb renderer.
|
|
474
|
+
* Used to distinguish Kubb-owned elements from unrecognized or text nodes during tree traversal.
|
|
475
|
+
*/
|
|
476
|
+
const nodeNames = new Set([
|
|
477
|
+
"kubb-export",
|
|
478
|
+
"kubb-file",
|
|
479
|
+
"kubb-source",
|
|
480
|
+
"kubb-import",
|
|
481
|
+
"kubb-function",
|
|
482
|
+
"kubb-arrow-function",
|
|
483
|
+
"kubb-const",
|
|
484
|
+
"kubb-type",
|
|
485
|
+
"kubb-jsx",
|
|
486
|
+
"kubb-text",
|
|
487
|
+
"kubb-root",
|
|
488
|
+
"kubb-app",
|
|
489
|
+
"br",
|
|
490
|
+
"indent",
|
|
491
|
+
"dedent"
|
|
492
|
+
]);
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/dom.ts
|
|
495
|
+
/**
|
|
496
|
+
* Create a new, empty {@link DOMElement} with the given node name.
|
|
497
|
+
* The element has no attributes, no children, and no parent.
|
|
498
|
+
*/
|
|
359
499
|
const createNode = (nodeName) => {
|
|
360
500
|
return {
|
|
361
501
|
nodeName,
|
|
@@ -364,6 +504,13 @@ const createNode = (nodeName) => {
|
|
|
364
504
|
parentNode: void 0
|
|
365
505
|
};
|
|
366
506
|
};
|
|
507
|
+
/**
|
|
508
|
+
* Append `childNode` as the last child of `node`.
|
|
509
|
+
*
|
|
510
|
+
* If `childNode` already has a parent, it is removed from that parent first
|
|
511
|
+
* (matching standard DOM move semantics).
|
|
512
|
+
* Text nodes (`nodeName === '#text'`) are silently ignored.
|
|
513
|
+
*/
|
|
367
514
|
const appendChildNode = (node, childNode) => {
|
|
368
515
|
if (childNode.parentNode) removeChildNode(childNode.parentNode, childNode);
|
|
369
516
|
if (node.nodeName !== "#text") {
|
|
@@ -371,6 +518,12 @@ const appendChildNode = (node, childNode) => {
|
|
|
371
518
|
node.childNodes.push(childNode);
|
|
372
519
|
}
|
|
373
520
|
};
|
|
521
|
+
/**
|
|
522
|
+
* Insert `newChildNode` before `beforeChildNode` in `node`'s child list.
|
|
523
|
+
*
|
|
524
|
+
* If `newChildNode` already has a parent, it is removed from that parent first.
|
|
525
|
+
* If `beforeChildNode` is not found, `newChildNode` is appended at the end.
|
|
526
|
+
*/
|
|
374
527
|
const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
|
|
375
528
|
if (newChildNode.parentNode) removeChildNode(newChildNode.parentNode, newChildNode);
|
|
376
529
|
newChildNode.parentNode = node;
|
|
@@ -381,44 +534,41 @@ const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
|
|
|
381
534
|
}
|
|
382
535
|
node.childNodes.push(newChildNode);
|
|
383
536
|
};
|
|
537
|
+
/**
|
|
538
|
+
* Remove `removeNode` from `node`'s child list and clear its `parentNode` reference.
|
|
539
|
+
* Does nothing if `removeNode` is not a direct child of `node`.
|
|
540
|
+
*/
|
|
384
541
|
const removeChildNode = (node, removeNode) => {
|
|
385
542
|
removeNode.parentNode = void 0;
|
|
386
543
|
const index = node.childNodes.indexOf(removeNode);
|
|
387
544
|
if (index >= 0) node.childNodes.splice(index, 1);
|
|
388
545
|
};
|
|
546
|
+
/**
|
|
547
|
+
* Set an attribute on `node`, storing it in the node's `attributes` map.
|
|
548
|
+
*/
|
|
389
549
|
const setAttribute = (node, key, value) => {
|
|
390
550
|
node.attributes.set(key, value);
|
|
391
551
|
};
|
|
552
|
+
/**
|
|
553
|
+
* Create a new {@link TextNode} with the given text value.
|
|
554
|
+
*/
|
|
392
555
|
const createTextNode = (text) => {
|
|
393
556
|
const node = {
|
|
394
|
-
nodeName:
|
|
557
|
+
nodeName: TEXT_NODE_NAME,
|
|
395
558
|
nodeValue: text,
|
|
396
559
|
parentNode: void 0
|
|
397
560
|
};
|
|
398
561
|
setTextNodeValue(node, text);
|
|
399
562
|
return node;
|
|
400
563
|
};
|
|
564
|
+
/**
|
|
565
|
+
* Update the `nodeValue` of an existing {@link TextNode}.
|
|
566
|
+
* Non-string values are coerced to strings via `String(text)`.
|
|
567
|
+
*/
|
|
401
568
|
const setTextNodeValue = (node, text) => {
|
|
402
569
|
if (typeof text !== "string") text = String(text);
|
|
403
570
|
node.nodeValue = text;
|
|
404
571
|
};
|
|
405
|
-
const nodeNames = new Set([
|
|
406
|
-
"kubb-export",
|
|
407
|
-
"kubb-file",
|
|
408
|
-
"kubb-source",
|
|
409
|
-
"kubb-import",
|
|
410
|
-
"kubb-function",
|
|
411
|
-
"kubb-arrow-function",
|
|
412
|
-
"kubb-const",
|
|
413
|
-
"kubb-type",
|
|
414
|
-
"kubb-jsx",
|
|
415
|
-
"kubb-text",
|
|
416
|
-
"kubb-root",
|
|
417
|
-
"kubb-app",
|
|
418
|
-
"br",
|
|
419
|
-
"indent",
|
|
420
|
-
"dedent"
|
|
421
|
-
]);
|
|
422
572
|
//#endregion
|
|
423
573
|
//#region ../../node_modules/.pnpm/scheduler@0.27.0/node_modules/scheduler/cjs/scheduler.production.js
|
|
424
574
|
/**
|
|
@@ -17720,7 +17870,7 @@ const Renderer = (0, import_react_reconciler.default)({
|
|
|
17720
17870
|
},
|
|
17721
17871
|
getCurrentUpdatePriority: () => currentUpdatePriority,
|
|
17722
17872
|
resolveUpdatePriority() {
|
|
17723
|
-
if (currentUpdatePriority !==
|
|
17873
|
+
if (currentUpdatePriority !== import_constants.NoEventPriority) return currentUpdatePriority;
|
|
17724
17874
|
return import_constants.DefaultEventPriority;
|
|
17725
17875
|
},
|
|
17726
17876
|
maySuspendCommit() {
|
|
@@ -17753,8 +17903,10 @@ const Renderer = (0, import_react_reconciler.default)({
|
|
|
17753
17903
|
//#region src/utils.ts
|
|
17754
17904
|
/**
|
|
17755
17905
|
* Collect the text and nested AST-node children of a single kubb-* element.
|
|
17756
|
-
*
|
|
17757
|
-
* become
|
|
17906
|
+
*
|
|
17907
|
+
* `#text` children become raw {@link TextNode}s; nested `kubb-function`, `kubb-const`,
|
|
17908
|
+
* `kubb-type`, and similar elements are converted into their respective {@link CodeNode}s.
|
|
17909
|
+
* Any unrecognized DOM elements are silently skipped.
|
|
17758
17910
|
*/
|
|
17759
17911
|
function collectChildNodes(element) {
|
|
17760
17912
|
const result = [];
|
|
@@ -17822,6 +17974,17 @@ function collectChildNodes(element) {
|
|
|
17822
17974
|
}
|
|
17823
17975
|
return result;
|
|
17824
17976
|
}
|
|
17977
|
+
/**
|
|
17978
|
+
* Traverse `node` and collect all `<kubb-source>` elements into a `Set<SourceNode>`.
|
|
17979
|
+
*
|
|
17980
|
+
* Elements whose `nodeName` is in `ignores` are skipped entirely (including their subtrees).
|
|
17981
|
+
* This is used to collect source blocks from a file node while excluding import/export subtrees.
|
|
17982
|
+
*
|
|
17983
|
+
* @example Collect sources while ignoring export and import elements
|
|
17984
|
+
* ```ts
|
|
17985
|
+
* const sources = squashSourceNodes(fileElement, ['kubb-export', 'kubb-import'])
|
|
17986
|
+
* ```
|
|
17987
|
+
*/
|
|
17825
17988
|
function squashSourceNodes(node, ignores) {
|
|
17826
17989
|
const ignoreSet = new Set(ignores);
|
|
17827
17990
|
const sources = /* @__PURE__ */ new Set();
|
|
@@ -17830,70 +17993,12 @@ function squashSourceNodes(node, ignores) {
|
|
|
17830
17993
|
if (!child) continue;
|
|
17831
17994
|
if (child.nodeName !== "#text" && ignoreSet.has(child.nodeName)) continue;
|
|
17832
17995
|
if (child.nodeName === "kubb-source") {
|
|
17833
|
-
const orderedNodes = [];
|
|
17834
|
-
for (const c of child.childNodes) {
|
|
17835
|
-
if (!c) continue;
|
|
17836
|
-
if (c.nodeName === "#text") {
|
|
17837
|
-
const text = c.nodeValue;
|
|
17838
|
-
if (text && text.trim().length > 0) orderedNodes.push(createText(text));
|
|
17839
|
-
} else if (c.nodeName === "br") orderedNodes.push(createBreak());
|
|
17840
|
-
else if (c.nodeName === "kubb-function") {
|
|
17841
|
-
const attrs = c.attributes;
|
|
17842
|
-
orderedNodes.push(createFunction({
|
|
17843
|
-
name: attrs.get("name"),
|
|
17844
|
-
params: attrs.get("params"),
|
|
17845
|
-
export: attrs.get("export"),
|
|
17846
|
-
default: attrs.get("default"),
|
|
17847
|
-
async: attrs.get("async"),
|
|
17848
|
-
generics: attrs.get("generics"),
|
|
17849
|
-
returnType: attrs.get("returnType"),
|
|
17850
|
-
JSDoc: attrs.get("JSDoc"),
|
|
17851
|
-
nodes: collectChildNodes(c)
|
|
17852
|
-
}));
|
|
17853
|
-
} else if (c.nodeName === "kubb-arrow-function") {
|
|
17854
|
-
const attrs = c.attributes;
|
|
17855
|
-
orderedNodes.push(createArrowFunction({
|
|
17856
|
-
name: attrs.get("name"),
|
|
17857
|
-
params: attrs.get("params"),
|
|
17858
|
-
export: attrs.get("export"),
|
|
17859
|
-
default: attrs.get("default"),
|
|
17860
|
-
async: attrs.get("async"),
|
|
17861
|
-
generics: attrs.get("generics"),
|
|
17862
|
-
returnType: attrs.get("returnType"),
|
|
17863
|
-
singleLine: attrs.get("singleLine"),
|
|
17864
|
-
JSDoc: attrs.get("JSDoc"),
|
|
17865
|
-
nodes: collectChildNodes(c)
|
|
17866
|
-
}));
|
|
17867
|
-
} else if (c.nodeName === "kubb-const") {
|
|
17868
|
-
const attrs = c.attributes;
|
|
17869
|
-
orderedNodes.push(createConst({
|
|
17870
|
-
name: attrs.get("name"),
|
|
17871
|
-
type: attrs.get("type"),
|
|
17872
|
-
export: attrs.get("export"),
|
|
17873
|
-
asConst: attrs.get("asConst"),
|
|
17874
|
-
JSDoc: attrs.get("JSDoc"),
|
|
17875
|
-
nodes: collectChildNodes(c)
|
|
17876
|
-
}));
|
|
17877
|
-
} else if (c.nodeName === "kubb-type") {
|
|
17878
|
-
const attrs = c.attributes;
|
|
17879
|
-
orderedNodes.push(createType({
|
|
17880
|
-
name: attrs.get("name"),
|
|
17881
|
-
export: attrs.get("export"),
|
|
17882
|
-
JSDoc: attrs.get("JSDoc"),
|
|
17883
|
-
nodes: collectChildNodes(c)
|
|
17884
|
-
}));
|
|
17885
|
-
} else if (c.nodeName === "kubb-jsx") {
|
|
17886
|
-
const textChild = c.childNodes[0];
|
|
17887
|
-
const value = textChild?.nodeName === "#text" ? textChild.nodeValue : "";
|
|
17888
|
-
if (value) orderedNodes.push(createJsx(value));
|
|
17889
|
-
}
|
|
17890
|
-
}
|
|
17891
17996
|
const source = createSource({
|
|
17892
17997
|
name: child.attributes.get("name")?.toString(),
|
|
17893
17998
|
isTypeOnly: child.attributes.get("isTypeOnly") ?? false,
|
|
17894
17999
|
isExportable: child.attributes.get("isExportable") ?? false,
|
|
17895
18000
|
isIndexable: child.attributes.get("isIndexable") ?? false,
|
|
17896
|
-
nodes:
|
|
18001
|
+
nodes: collectChildNodes(child)
|
|
17897
18002
|
});
|
|
17898
18003
|
sources.add(source);
|
|
17899
18004
|
continue;
|
|
@@ -17904,47 +18009,60 @@ function squashSourceNodes(node, ignores) {
|
|
|
17904
18009
|
walk(node);
|
|
17905
18010
|
return sources;
|
|
17906
18011
|
}
|
|
18012
|
+
/**
|
|
18013
|
+
* Traverse `node` and collect all `<kubb-export>` elements into a `Set<ExportNode>`.
|
|
18014
|
+
*/
|
|
17907
18015
|
function squashExportNodes(node) {
|
|
17908
18016
|
const exports = /* @__PURE__ */ new Set();
|
|
17909
18017
|
const walk = (current) => {
|
|
17910
18018
|
for (const child of current.childNodes) {
|
|
17911
18019
|
if (!child) continue;
|
|
17912
18020
|
if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
|
|
17913
|
-
if (child.nodeName === "kubb-export") exports.add({
|
|
18021
|
+
if (child.nodeName === "kubb-export") exports.add(createExport({
|
|
17914
18022
|
name: child.attributes.get("name"),
|
|
17915
18023
|
path: child.attributes.get("path"),
|
|
17916
18024
|
isTypeOnly: child.attributes.get("isTypeOnly") ?? false,
|
|
17917
18025
|
asAlias: child.attributes.get("asAlias") ?? false
|
|
17918
|
-
});
|
|
18026
|
+
}));
|
|
17919
18027
|
}
|
|
17920
18028
|
};
|
|
17921
18029
|
walk(node);
|
|
17922
18030
|
return exports;
|
|
17923
18031
|
}
|
|
18032
|
+
/**
|
|
18033
|
+
* Traverse `node` and collect all `<kubb-import>` elements into a `Set<ImportNode>`.
|
|
18034
|
+
*/
|
|
17924
18035
|
function squashImportNodes(node) {
|
|
17925
18036
|
const imports = /* @__PURE__ */ new Set();
|
|
17926
18037
|
const walk = (current) => {
|
|
17927
18038
|
for (const child of current.childNodes) {
|
|
17928
18039
|
if (!child) continue;
|
|
17929
18040
|
if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
|
|
17930
|
-
if (child.nodeName === "kubb-import") imports.add({
|
|
18041
|
+
if (child.nodeName === "kubb-import") imports.add(createImport({
|
|
17931
18042
|
name: child.attributes.get("name"),
|
|
17932
18043
|
path: child.attributes.get("path"),
|
|
17933
18044
|
root: child.attributes.get("root"),
|
|
17934
18045
|
isTypeOnly: child.attributes.get("isTypeOnly") ?? false,
|
|
17935
18046
|
isNameSpace: child.attributes.get("isNameSpace") ?? false
|
|
17936
|
-
});
|
|
18047
|
+
}));
|
|
17937
18048
|
}
|
|
17938
18049
|
};
|
|
17939
18050
|
walk(node);
|
|
17940
18051
|
return imports;
|
|
17941
18052
|
}
|
|
17942
|
-
|
|
18053
|
+
/**
|
|
18054
|
+
* Walk the virtual DOM tree rooted at `node` and convert every `<kubb-file>` element
|
|
18055
|
+
* into a {@link FileNode}, collecting its source blocks, imports, and exports.
|
|
18056
|
+
*
|
|
18057
|
+
* Returns the list of file nodes in document order. Nested files are supported —
|
|
18058
|
+
* the walker descends into non-file elements and recurses through them.
|
|
18059
|
+
*/
|
|
18060
|
+
function processFiles(node) {
|
|
17943
18061
|
const collected = [];
|
|
17944
|
-
|
|
18062
|
+
function walk(current) {
|
|
17945
18063
|
for (const child of current.childNodes) {
|
|
17946
18064
|
if (!child) continue;
|
|
17947
|
-
if (child.nodeName !== "#text" && child.nodeName !== "kubb-file" && nodeNames.has(child.nodeName))
|
|
18065
|
+
if (child.nodeName !== "#text" && child.nodeName !== "kubb-file" && nodeNames.has(child.nodeName)) walk(child);
|
|
17948
18066
|
if (child.nodeName === "kubb-file") {
|
|
17949
18067
|
if (child.attributes.has("baseName") && child.attributes.has("path")) {
|
|
17950
18068
|
const sources = squashSourceNodes(child, ["kubb-export", "kubb-import"]);
|
|
@@ -17962,7 +18080,7 @@ async function processFiles(node) {
|
|
|
17962
18080
|
}
|
|
17963
18081
|
}
|
|
17964
18082
|
}
|
|
17965
|
-
|
|
18083
|
+
walk(node);
|
|
17966
18084
|
return collected;
|
|
17967
18085
|
}
|
|
17968
18086
|
//#endregion
|
|
@@ -17999,12 +18117,13 @@ var Runtime = class {
|
|
|
17999
18117
|
rejectExitPromise = () => {};
|
|
18000
18118
|
unsubscribeExit = () => {};
|
|
18001
18119
|
onRender = () => {
|
|
18002
|
-
|
|
18120
|
+
const task = this.#renderPromise.catch(() => {}).then(() => {
|
|
18003
18121
|
if (this.#isUnmounted) return;
|
|
18004
|
-
const files =
|
|
18122
|
+
const files = processFiles(this.#rootNode);
|
|
18005
18123
|
this.nodes.push(...files);
|
|
18006
18124
|
if (!this.#options?.debug) return;
|
|
18007
|
-
})
|
|
18125
|
+
});
|
|
18126
|
+
this.#renderPromise = task.catch((error) => {
|
|
18008
18127
|
this.onError(error);
|
|
18009
18128
|
});
|
|
18010
18129
|
return this.#renderPromise;
|
|
@@ -18055,6 +18174,28 @@ var Runtime = class {
|
|
|
18055
18174
|
};
|
|
18056
18175
|
//#endregion
|
|
18057
18176
|
//#region src/createRenderer.tsx
|
|
18177
|
+
/**
|
|
18178
|
+
* Create a Kubb JSX renderer.
|
|
18179
|
+
*
|
|
18180
|
+
* The renderer converts a React JSX element tree — built from the components in this
|
|
18181
|
+
* package — into an array of {@link FileNode} entries representing the generated files.
|
|
18182
|
+
*
|
|
18183
|
+
* @example Basic usage
|
|
18184
|
+
* ```ts
|
|
18185
|
+
* import { createRenderer, File } from '@kubb/renderer-jsx'
|
|
18186
|
+
*
|
|
18187
|
+
* const renderer = createRenderer()
|
|
18188
|
+
* await renderer.render(
|
|
18189
|
+
* <File baseName="pet.ts" path="src/models/pet.ts">
|
|
18190
|
+
* <File.Source name="Pet" isExportable isIndexable>
|
|
18191
|
+
* {`export type Pet = { id: number; name: string }`}
|
|
18192
|
+
* </File.Source>
|
|
18193
|
+
* </File>
|
|
18194
|
+
* )
|
|
18195
|
+
* console.log(renderer.files) // [FileNode]
|
|
18196
|
+
* renderer.unmount()
|
|
18197
|
+
* ```
|
|
18198
|
+
*/
|
|
18058
18199
|
function createRenderer(options = {}) {
|
|
18059
18200
|
const runtime = new Runtime(options);
|
|
18060
18201
|
return {
|
|
@@ -18069,7 +18210,29 @@ function createRenderer(options = {}) {
|
|
|
18069
18210
|
}
|
|
18070
18211
|
};
|
|
18071
18212
|
}
|
|
18213
|
+
/**
|
|
18214
|
+
* A renderer factory for generators that produce JSX output.
|
|
18215
|
+
*
|
|
18216
|
+
* Pass this as the `renderer` property of a `defineGenerator` call so that
|
|
18217
|
+
* core can render the JSX element tree returned by your generator methods
|
|
18218
|
+
* without a hard dependency on `@kubb/renderer-jsx`.
|
|
18219
|
+
*
|
|
18220
|
+
* @example
|
|
18221
|
+
* ```ts
|
|
18222
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
18223
|
+
* import { defineGenerator } from '@kubb/core'
|
|
18224
|
+
*
|
|
18225
|
+
* export const myGenerator = defineGenerator<PluginTs>({
|
|
18226
|
+
* name: 'my-generator',
|
|
18227
|
+
* renderer: jsxRenderer,
|
|
18228
|
+
* schema(node, options) {
|
|
18229
|
+
* return <File baseName="output.ts" path="src/output.ts">...</File>
|
|
18230
|
+
* },
|
|
18231
|
+
* })
|
|
18232
|
+
* ```
|
|
18233
|
+
*/
|
|
18234
|
+
const jsxRenderer = () => createRenderer();
|
|
18072
18235
|
//#endregion
|
|
18073
|
-
export { Const, File, Function$1 as Function, Jsx, KubbContext, OasContext, Root, Type, createContext, createRenderer, inject, provide, unprovide };
|
|
18236
|
+
export { Const, File, Function$1 as Function, Jsx, KubbContext, OasContext, Root, Type, createContext, createRenderer, inject, jsxRenderer, provide, unprovide };
|
|
18074
18237
|
|
|
18075
18238
|
//# sourceMappingURL=index.js.map
|