@kubb/react-fabric 0.15.0 → 0.15.2
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/globals.d.ts +1 -1
- package/dist/index.cjs +121 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +120 -1
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/{jsx-namespace-CYofvEUt.d.ts → jsx-namespace-BUQfB16E.d.ts} +2 -2
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/plugins.cjs +0 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +0 -1
- package/dist/{reactPlugin-Cnw1Sdnt.d.ts → reactPlugin-D2aNZpS7.d.ts} +2 -2
- package/dist/{types-B6MJKUw9.d.ts → types-DG_Fmgyd.d.ts} +53 -4
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/types.ts +1 -0
- package/src/utils/getFunctionParams.ts +247 -0
package/dist/globals.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as __name } from "./chunk-BGCRLu6H.js";
|
|
2
|
-
import { a as FabricExportProps, c as FabricReactElement, d as FabricTextProps, l as FabricReactNode, o as FabricFileProps, p as LineBreakProps, s as FabricImportProps, u as FabricSourceProps } from "./types-
|
|
2
|
+
import { a as FabricExportProps, c as FabricReactElement, d as FabricTextProps, l as FabricReactNode, o as FabricFileProps, p as LineBreakProps, s as FabricImportProps, u as FabricSourceProps } from "./types-DG_Fmgyd.js";
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
5
5
|
//#region src/globals.d.ts
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ let _kubb_fabric_core = require("@kubb/fabric-core");
|
|
|
6
6
|
let node_child_process = require("node:child_process");
|
|
7
7
|
let ws = require("ws");
|
|
8
8
|
ws = require_jsx_runtime.__toESM(ws);
|
|
9
|
+
let remeda = require("remeda");
|
|
9
10
|
//#region src/components/Const.tsx
|
|
10
11
|
var import_react = /* @__PURE__ */ require_jsx_runtime.__toESM(require_jsx_runtime.require_react(), 1);
|
|
11
12
|
/**
|
|
@@ -400,6 +401,124 @@ function createReactFabric(config = {}) {
|
|
|
400
401
|
return fabric;
|
|
401
402
|
}
|
|
402
403
|
//#endregion
|
|
404
|
+
//#region src/utils/getFunctionParams.ts
|
|
405
|
+
function order(items) {
|
|
406
|
+
return (0, remeda.sortBy)(items.filter(Boolean), ([_key, item]) => {
|
|
407
|
+
if (item?.children) return 0;
|
|
408
|
+
if (item?.optional) return 1;
|
|
409
|
+
if (item?.default) return 2;
|
|
410
|
+
return 0;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function parseChild(key, item, options) {
|
|
414
|
+
const entries = order(Object.entries(item.children));
|
|
415
|
+
const types = [];
|
|
416
|
+
const names = [];
|
|
417
|
+
const optional = entries.every(([_key, item]) => item?.optional || !!item?.default);
|
|
418
|
+
entries.forEach(([key, entryItem]) => {
|
|
419
|
+
if (entryItem) {
|
|
420
|
+
const name = parseItem(key, {
|
|
421
|
+
...entryItem,
|
|
422
|
+
type: void 0
|
|
423
|
+
}, options);
|
|
424
|
+
if (entryItem.children) {
|
|
425
|
+
const subTypes = Object.entries(entryItem.children).map(([key]) => {
|
|
426
|
+
return key;
|
|
427
|
+
}).join(", ");
|
|
428
|
+
if (subTypes) names.push(`${name}: { ${subTypes} }`);
|
|
429
|
+
else names.push(name);
|
|
430
|
+
} else if (options.type === "call" && options.transformName) names.push(`${key}: ${name}`);
|
|
431
|
+
else names.push(name);
|
|
432
|
+
if (entries.some(([_key, item]) => item?.type)) types.push(parseItem(key, {
|
|
433
|
+
...entryItem,
|
|
434
|
+
default: void 0
|
|
435
|
+
}, options));
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
const name = item.mode === "inline" ? key : names.length ? `{ ${names.join(", ")} }` : void 0;
|
|
439
|
+
const type = item.type ? item.type : types.length ? `{ ${types.join("; ")} }` : void 0;
|
|
440
|
+
if (!name) return null;
|
|
441
|
+
return parseItem(name, {
|
|
442
|
+
type,
|
|
443
|
+
default: item.default,
|
|
444
|
+
optional: !item.default ? optional : void 0
|
|
445
|
+
}, options);
|
|
446
|
+
}
|
|
447
|
+
function parseItem(name, item, options) {
|
|
448
|
+
const acc = [];
|
|
449
|
+
const transformedName = options.transformName ? options.transformName(name) : name;
|
|
450
|
+
const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type;
|
|
451
|
+
if (options.type === "object") return transformedName;
|
|
452
|
+
if (options.type === "objectValue") return item.value ? `${transformedName}: ${item.value}` : transformedName;
|
|
453
|
+
if (item.type && options.type === "constructor") if (item.optional) if (transformedName.startsWith("{")) acc.push(`${transformedName}: ${transformedType} = {}`);
|
|
454
|
+
else acc.push(`${transformedName}?: ${transformedType}`);
|
|
455
|
+
else acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ""}`);
|
|
456
|
+
else if (item.default && options.type === "constructor") acc.push(`${transformedName} = ${item.default}`);
|
|
457
|
+
else if (item.value) acc.push(`${transformedName} : ${item.value}`);
|
|
458
|
+
else if (item.mode === "inlineSpread") acc.push(`... ${transformedName}`);
|
|
459
|
+
else acc.push(transformedName);
|
|
460
|
+
return acc[0];
|
|
461
|
+
}
|
|
462
|
+
function getFunctionParams(params, options) {
|
|
463
|
+
return order(Object.entries(params)).reduce((acc, [key, item]) => {
|
|
464
|
+
if (!item) return acc;
|
|
465
|
+
if (item.children) {
|
|
466
|
+
if (Object.keys(item.children).length === 0) return acc;
|
|
467
|
+
if (item.mode === "inlineSpread") return [...acc, getFunctionParams(item.children, options)];
|
|
468
|
+
const parsedItem = parseChild(key, item, options);
|
|
469
|
+
if (!parsedItem) return acc;
|
|
470
|
+
return [...acc, parsedItem];
|
|
471
|
+
}
|
|
472
|
+
const parsedItem = parseItem(key, item, options);
|
|
473
|
+
return [...acc, parsedItem];
|
|
474
|
+
}, []).join(", ");
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* @deprecated use @kubb/ast
|
|
478
|
+
*/
|
|
479
|
+
function createFunctionParams(params) {
|
|
480
|
+
return params;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* @deprecated use @kubb/ast
|
|
484
|
+
*/
|
|
485
|
+
var FunctionParams = class FunctionParams {
|
|
486
|
+
#params;
|
|
487
|
+
static factory(params) {
|
|
488
|
+
return new FunctionParams(params);
|
|
489
|
+
}
|
|
490
|
+
constructor(params) {
|
|
491
|
+
this.#params = params;
|
|
492
|
+
}
|
|
493
|
+
get params() {
|
|
494
|
+
return this.#params;
|
|
495
|
+
}
|
|
496
|
+
get flatParams() {
|
|
497
|
+
const flatter = (acc, [key, item]) => {
|
|
498
|
+
if (item?.children) return Object.entries(item.children).reduce(flatter, acc);
|
|
499
|
+
if (item) acc[key] = item;
|
|
500
|
+
return acc;
|
|
501
|
+
};
|
|
502
|
+
return Object.entries(this.#params).reduce(flatter, {});
|
|
503
|
+
}
|
|
504
|
+
toCall({ transformName, transformType } = {}) {
|
|
505
|
+
return getFunctionParams(this.#params, {
|
|
506
|
+
type: "call",
|
|
507
|
+
transformName,
|
|
508
|
+
transformType
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
toObject() {
|
|
512
|
+
return getFunctionParams(this.#params, { type: "object" });
|
|
513
|
+
}
|
|
514
|
+
toObjectValue() {
|
|
515
|
+
return getFunctionParams(this.#params, { type: "objectValue" });
|
|
516
|
+
}
|
|
517
|
+
toConstructor() {
|
|
518
|
+
return getFunctionParams(this.#params, { type: "constructor" });
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
//#endregion
|
|
403
522
|
//#region src/index.ts
|
|
404
523
|
const useState = import_react.useState;
|
|
405
524
|
const useEffect = import_react.useEffect;
|
|
@@ -422,6 +541,7 @@ Object.defineProperty(exports, "FileProcessor", {
|
|
|
422
541
|
}
|
|
423
542
|
});
|
|
424
543
|
exports.Function = Function;
|
|
544
|
+
exports.FunctionParams = FunctionParams;
|
|
425
545
|
exports.Root = require_reactPlugin.Root;
|
|
426
546
|
exports.Runtime = require_reactPlugin.Runtime;
|
|
427
547
|
Object.defineProperty(exports, "TreeNode", {
|
|
@@ -449,6 +569,7 @@ Object.defineProperty(exports, "createFile", {
|
|
|
449
569
|
return _kubb_fabric_core.createFile;
|
|
450
570
|
}
|
|
451
571
|
});
|
|
572
|
+
exports.createFunctionParams = createFunctionParams;
|
|
452
573
|
exports.createReactFabric = createReactFabric;
|
|
453
574
|
exports.openDevtools = openDevtools;
|
|
454
575
|
Object.defineProperty(exports, "useContext", {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["NodeTreeContext","RootContext","NodeTreeContext","FabricContext","NodeTreeContext","FileContext","NodeTreeContext","NodeTreeContext","reactPlugin"],"sources":["../src/components/Const.tsx","../src/components/Fabric.tsx","../src/components/File.tsx","../src/components/Function.tsx","../src/components/Type.tsx","../src/devtools.ts","../src/createReactFabric.ts","../src/index.ts"],"sourcesContent":["import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type ConstProps = {\n key?: Key\n /**\n * Name of the const\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Type to make the const being typed\n */\n type?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Use of `const` assertions\n */\n asConst?: boolean\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript constant declaration.\n */\nexport function Const({ children, ...props }: ConstProps): FabricReactElement {\n const { name, export: canExport, type, JSDoc, asConst } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Const', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n const {name}\n {type ? (\n <>\n {':'}\n {type}{' '}\n </>\n ) : (\n ' '\n )}\n = {children}\n {asConst && <> as const</>}\n </>\n )\n}\n\nConst.displayName = 'Const'\n","import { FabricContext, NodeTreeContext, provide, RootContext, useContext, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode } from '../types.ts'\n\nexport type FabricProps<TMeta extends object = object> = {\n /**\n * Metadata associated with the App.\n */\n meta?: TMeta\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Fabric container containing the FabricContext carrying `meta` and an `exit` hook.\n */\nexport function Fabric<TMeta extends object = object>({ children, ...props }: FabricProps<TMeta>): FabricReactElement {\n const { meta = {} } = props\n\n const { exit } = useContext(RootContext)\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'App', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n provide(FabricContext, { exit, meta })\n\n return <>{children}</>\n}\n\nFabric.displayName = 'Fabric'\n","import { FileContext, NodeTreeContext, provide, useFile, useFileManager, useNodeTree } from '@kubb/fabric-core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { FabricReactElement, FabricReactNode, Key } from '../types.ts'\n\ntype BasePropsWithBaseName = {\n /**\n * Name to be used to dynamicly create the baseName(based on input.path).\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: KubbFile.BaseName\n /**\n * Path will be full qualified path to a specified file.\n */\n path: KubbFile.Path\n}\n\ntype BasePropsWithoutBaseName = {\n baseName?: never\n /**\n * Path will be full qualified path to a specified file.\n */\n path?: KubbFile.Path\n}\n\ntype BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName\n\ntype Props<TMeta> = BaseProps & {\n key?: Key\n meta?: TMeta\n banner?: string\n footer?: string\n children?: FabricReactNode\n}\n\n/**\n * Adds files to the FileManager\n */\nexport function File<TMeta extends object = object>({ children, ...props }: Props<TMeta>): FabricReactElement {\n const { baseName, path, meta = {}, footer, banner } = props\n\n const fileManager = useFileManager()\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'File', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (!baseName || !path) {\n return <>{children}</>\n }\n\n const file: KubbFile.File = {\n baseName,\n path,\n meta,\n banner,\n footer,\n sources: [],\n imports: [],\n exports: [],\n }\n\n const [resolvedFile] = fileManager.add(file)\n provide(FileContext, resolvedFile)\n\n return <kubb-file {...props}>{children}</kubb-file>\n}\n\nFile.displayName = 'File'\n\ntype FileSourceProps = Omit<KubbFile.Source, 'value'> & {\n key?: Key\n children?: FabricReactNode\n}\n\n/**\n * File.Source\n *\n * Marks a block of source text to be associated with the current file when\n * rendering with the FileCollector. Children are treated as the source string.\n */\nfunction FileSource({ children, ...props }: FileSourceProps): FabricReactElement {\n const { name, isExportable, isIndexable, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileSource', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <kubb-source name={name} isTypeOnly={isTypeOnly} isExportable={isExportable} isIndexable={isIndexable}>\n {children}\n </kubb-source>\n )\n}\n\nFileSource.displayName = 'FileSource'\n\nexport type FileExportProps = KubbFile.Export & { key?: Key }\n\n/**\n * File.Export\n *\n * Declares an export entry for the current file. This will be collected by\n * the FileCollector for later emission.\n */\nfunction FileExport(props: FileExportProps): FabricReactElement {\n const { name, path, isTypeOnly, asAlias } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileExport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.exports.push({\n name,\n path,\n asAlias,\n isTypeOnly,\n })\n }\n\n return <kubb-export name={name} path={path} isTypeOnly={isTypeOnly} asAlias={asAlias} />\n}\n\nFileExport.displayName = 'FileExport'\n\nexport type FileImportProps = KubbFile.Import & { key?: Key }\n\n/**\n * File.Import\n *\n * Declares an import entry for the current file.\n */\nfunction FileImport(props: FileImportProps): FabricReactElement {\n const { name, root, path, isTypeOnly, isNameSpace } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileImport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.imports.push({\n name,\n path,\n root,\n isNameSpace,\n isTypeOnly,\n })\n }\n\n return <kubb-import name={name} root={root} path={path} isNameSpace={isNameSpace} isTypeOnly={isTypeOnly} />\n}\n\nFileImport.displayName = 'FileImport'\n\nFile.Export = FileExport\nFile.Import = FileImport\nFile.Source = FileSource\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\ntype Props = {\n key?: Key\n /**\n * Name of the function.\n */\n name: string\n /**\n * Add default when export is being used\n */\n default?: boolean\n /**\n * Parameters/options/props that need to be used.\n */\n params?: string\n /**\n * Does this function need to be exported.\n */\n export?: boolean\n /**\n * Does the function has async/promise behavior.\n * This will also add `Promise<returnType>` as the returnType.\n */\n async?: boolean\n /**\n * Generics that needs to be added for TypeScript.\n */\n generics?: string | string[]\n /**\n * ReturnType(see async for adding Promise type).\n */\n returnType?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript function declaration.\n */\nexport function Function({ children, ...props }: Props): FabricReactElement {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Function', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n {async && <>async </>}\n function {name}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {' {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n </>\n )\n}\n\nFunction.displayName = 'Function'\n\ntype ArrowFunctionProps = Props & {\n /**\n * Create Arrow function in one line\n */\n singleLine?: boolean\n}\n\n/**\n * ArrowFunction\n *\n * Renders an arrow function definition. Supports the same flags as `Function`.\n * Use `singleLine` to render the body as a single-line expression.\n */\nfunction ArrowFunction({ children, ...props }: ArrowFunctionProps) {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'ArrowFunction', props })\n\n provide(NodeTreeContext, childTree)\n }\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n const {name} = {async && <>async </>}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {singleLine && (\n <>\n {' => '}\n {children}\n <br />\n </>\n )}\n {!singleLine && (\n <>\n {' => {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n <br />\n </>\n )}\n </>\n )\n}\n\nArrowFunction.displayName = 'ArrowFunction'\nFunction.Arrow = ArrowFunction\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type TypeProps = {\n key?: Key\n /**\n * Name of the type, this needs to start with a capital letter.\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript type declaration.\n */\nexport function Type({ children, ...props }: TypeProps): FabricReactElement {\n const { name, export: canExport, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Type', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (name.charAt(0).toUpperCase() !== name.charAt(0)) {\n throw new Error('Name should start with a capital letter(see TypeScript types)')\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n type {name} = {children}\n </>\n )\n}\n\nType.displayName = 'Type'\n","import { spawn } from 'node:child_process'\nimport { onProcessExit } from '@kubb/fabric-core'\nimport ws from 'ws'\nimport { Renderer } from './Renderer.ts'\n\ndeclare global {\n var WebSocket: typeof WebSocket\n var isDevtoolsEnabled: any\n}\n\nlet isOpen = false\n\nexport function openDevtools() {\n if (isOpen) {\n return undefined\n }\n // Set up global polyfills BEFORE importing react-devtools-core\n // This is required because react-devtools-core expects these to be available\n const customGlobal = global as any\n customGlobal.WebSocket ||= ws\n customGlobal.window ||= global\n customGlobal.self ||= global\n customGlobal.isDevtoolsEnabled = true\n\n // Filter out Kubb internal components from devtools for a cleaner view.\n // See https://github.com/facebook/react/blob/edf6eac8a181860fd8a2d076a43806f1237495a1/packages/react-devtools-shared/src/types.js#L24\n customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Context.Provider',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Root',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'ErrorBoundary',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-file',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-text',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-import',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-export',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-source',\n isEnabled: true,\n isValid: true,\n },\n ]\n\n // biome-ignore lint/suspicious/noTsIgnore: cannot find types\n // @ts-ignore\n import('react-devtools-core').then(async (devtools) => {\n console.info('Opening devtools')\n const controller = new AbortController()\n if (!isOpen) {\n const child = spawn('npx', ['react-devtools@6.1.5'], {\n signal: controller.signal,\n stdio: 'pipe',\n detached: true,\n })\n child.unref()\n }\n\n isOpen = true\n\n // Destructure the functions from the module\n const { initialize, connectToDevTools } = devtools?.default || devtools\n\n // Initialize DevTools BEFORE importing Renderer (which imports React)\n initialize()\n console.info('Initializing devtools')\n\n // Inject the renderer BEFORE connecting to DevTools\n // This ensures DevTools can properly discover the custom renderer\n Renderer.injectIntoDevTools({\n bundleType: 1,\n version: '19.2.3',\n rendererPackageName: 'kubb',\n // findFiberByHostInstance is required for DevTools to map elements to fibers\n findFiberByHostInstance: () => null,\n })\n\n console.info('Connecting devtools')\n\n try {\n connectToDevTools({\n host: 'localhost',\n port: 8097,\n useHttps: false,\n isAppActive: () => true,\n })\n } catch (e) {\n console.error(e)\n console.info('Error when connecting the devtools')\n }\n\n onProcessExit(() => {\n console.info('Disconnecting devtools')\n controller.abort()\n })\n })\n}\n","import { createFabric } from '@kubb/fabric-core'\nimport type { Fabric, FabricConfig, FabricMode } from '@kubb/fabric-core/types'\nimport { openDevtools } from './devtools.ts'\nimport type { Options } from './plugins/reactPlugin.ts'\nimport { reactPlugin } from './plugins/reactPlugin.ts'\n\nexport function createReactFabric(\n config: FabricConfig<Options & { mode?: FabricMode; devtools?: boolean }> = {},\n): Fabric<Options & { mode?: FabricMode; devtools?: boolean }> {\n if (config.devtools) {\n openDevtools()\n }\n\n const fabric = createFabric({ mode: config.mode })\n\n fabric.use(reactPlugin, {\n stdout: config.stdout,\n stderr: config.stderr,\n debug: config.debug,\n stdin: config.stdin,\n })\n\n return fabric\n}\n","// import './globals.ts'\nimport * as React from 'react'\n\n// expose fabric core helpers\nexport { createContext, createFabric, createFile, FileManager, FileProcessor, TreeNode, useContext } from '@kubb/fabric-core'\n\n// react helpers\nexport const useState = React.useState\nexport const useEffect = React.useEffect\nexport const useReducer = React.useReducer\nexport const useRef = React.useRef\n\nexport { Const } from './components/Const.tsx'\nexport { Fabric } from './components/Fabric.tsx'\nexport { File } from './components/File.tsx'\nexport { Function } from './components/Function.tsx'\n// components\nexport { Root } from './components/Root.tsx'\nexport { Type } from './components/Type.tsx'\n\n// composables\nexport { useFabric } from './composables/useFabric.ts'\nexport { useFile } from './composables/useFile.ts'\nexport { useLifecycle } from './composables/useLifecycle.tsx'\n\n// factories\nexport { createReactFabric } from './createReactFabric.ts'\nexport { openDevtools } from './devtools.ts'\nexport { Runtime } from './Runtime.tsx'\n"],"mappings":";;;;;;;;;;;;;AAmCA,SAAA,MAAA,EAAA,UAAA,GAAA,SAAA;;;AAKE,KAAA,SAAA,EAAA,GAAA,kBAAA,SAAA,kBAAA,iBAAA,SAAA,SAAA;;;;AAMA,QAAA,sCAAA,KAAA,sBAAA,UAAA,EAAA,UAAA;;;;;;;;;;;;;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EACd,OAAO,OAAO;EACf,CAAC;AAEF,QAAO;;;;ACfT,MAAa,WAAA,aAAiB;AAC9B,MAAa,YAAA,aAAkB;AAC/B,MAAa,aAAA,aAAmB;AAChC,MAAa,SAAA,aAAe"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["NodeTreeContext","RootContext","NodeTreeContext","FabricContext","NodeTreeContext","FileContext","NodeTreeContext","NodeTreeContext","reactPlugin","#params"],"sources":["../src/components/Const.tsx","../src/components/Fabric.tsx","../src/components/File.tsx","../src/components/Function.tsx","../src/components/Type.tsx","../src/devtools.ts","../src/createReactFabric.ts","../src/utils/getFunctionParams.ts","../src/index.ts"],"sourcesContent":["import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type ConstProps = {\n key?: Key\n /**\n * Name of the const\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Type to make the const being typed\n */\n type?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Use of `const` assertions\n */\n asConst?: boolean\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript constant declaration.\n */\nexport function Const({ children, ...props }: ConstProps): FabricReactElement {\n const { name, export: canExport, type, JSDoc, asConst } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Const', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n const {name}\n {type ? (\n <>\n {':'}\n {type}{' '}\n </>\n ) : (\n ' '\n )}\n = {children}\n {asConst && <> as const</>}\n </>\n )\n}\n\nConst.displayName = 'Const'\n","import { FabricContext, NodeTreeContext, provide, RootContext, useContext, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode } from '../types.ts'\n\nexport type FabricProps<TMeta extends object = object> = {\n /**\n * Metadata associated with the App.\n */\n meta?: TMeta\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Fabric container containing the FabricContext carrying `meta` and an `exit` hook.\n */\nexport function Fabric<TMeta extends object = object>({ children, ...props }: FabricProps<TMeta>): FabricReactElement {\n const { meta = {} } = props\n\n const { exit } = useContext(RootContext)\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'App', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n provide(FabricContext, { exit, meta })\n\n return <>{children}</>\n}\n\nFabric.displayName = 'Fabric'\n","import { FileContext, NodeTreeContext, provide, useFile, useFileManager, useNodeTree } from '@kubb/fabric-core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { FabricReactElement, FabricReactNode, Key } from '../types.ts'\n\ntype BasePropsWithBaseName = {\n /**\n * Name to be used to dynamicly create the baseName(based on input.path).\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: KubbFile.BaseName\n /**\n * Path will be full qualified path to a specified file.\n */\n path: KubbFile.Path\n}\n\ntype BasePropsWithoutBaseName = {\n baseName?: never\n /**\n * Path will be full qualified path to a specified file.\n */\n path?: KubbFile.Path\n}\n\ntype BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName\n\ntype Props<TMeta> = BaseProps & {\n key?: Key\n meta?: TMeta\n banner?: string\n footer?: string\n children?: FabricReactNode\n}\n\n/**\n * Adds files to the FileManager\n */\nexport function File<TMeta extends object = object>({ children, ...props }: Props<TMeta>): FabricReactElement {\n const { baseName, path, meta = {}, footer, banner } = props\n\n const fileManager = useFileManager()\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'File', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (!baseName || !path) {\n return <>{children}</>\n }\n\n const file: KubbFile.File = {\n baseName,\n path,\n meta,\n banner,\n footer,\n sources: [],\n imports: [],\n exports: [],\n }\n\n const [resolvedFile] = fileManager.add(file)\n provide(FileContext, resolvedFile)\n\n return <kubb-file {...props}>{children}</kubb-file>\n}\n\nFile.displayName = 'File'\n\ntype FileSourceProps = Omit<KubbFile.Source, 'value'> & {\n key?: Key\n children?: FabricReactNode\n}\n\n/**\n * File.Source\n *\n * Marks a block of source text to be associated with the current file when\n * rendering with the FileCollector. Children are treated as the source string.\n */\nfunction FileSource({ children, ...props }: FileSourceProps): FabricReactElement {\n const { name, isExportable, isIndexable, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileSource', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <kubb-source name={name} isTypeOnly={isTypeOnly} isExportable={isExportable} isIndexable={isIndexable}>\n {children}\n </kubb-source>\n )\n}\n\nFileSource.displayName = 'FileSource'\n\nexport type FileExportProps = KubbFile.Export & { key?: Key }\n\n/**\n * File.Export\n *\n * Declares an export entry for the current file. This will be collected by\n * the FileCollector for later emission.\n */\nfunction FileExport(props: FileExportProps): FabricReactElement {\n const { name, path, isTypeOnly, asAlias } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileExport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.exports.push({\n name,\n path,\n asAlias,\n isTypeOnly,\n })\n }\n\n return <kubb-export name={name} path={path} isTypeOnly={isTypeOnly} asAlias={asAlias} />\n}\n\nFileExport.displayName = 'FileExport'\n\nexport type FileImportProps = KubbFile.Import & { key?: Key }\n\n/**\n * File.Import\n *\n * Declares an import entry for the current file.\n */\nfunction FileImport(props: FileImportProps): FabricReactElement {\n const { name, root, path, isTypeOnly, isNameSpace } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileImport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.imports.push({\n name,\n path,\n root,\n isNameSpace,\n isTypeOnly,\n })\n }\n\n return <kubb-import name={name} root={root} path={path} isNameSpace={isNameSpace} isTypeOnly={isTypeOnly} />\n}\n\nFileImport.displayName = 'FileImport'\n\nFile.Export = FileExport\nFile.Import = FileImport\nFile.Source = FileSource\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\ntype Props = {\n key?: Key\n /**\n * Name of the function.\n */\n name: string\n /**\n * Add default when export is being used\n */\n default?: boolean\n /**\n * Parameters/options/props that need to be used.\n */\n params?: string\n /**\n * Does this function need to be exported.\n */\n export?: boolean\n /**\n * Does the function has async/promise behavior.\n * This will also add `Promise<returnType>` as the returnType.\n */\n async?: boolean\n /**\n * Generics that needs to be added for TypeScript.\n */\n generics?: string | string[]\n /**\n * ReturnType(see async for adding Promise type).\n */\n returnType?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript function declaration.\n */\nexport function Function({ children, ...props }: Props): FabricReactElement {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Function', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n {async && <>async </>}\n function {name}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {' {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n </>\n )\n}\n\nFunction.displayName = 'Function'\n\ntype ArrowFunctionProps = Props & {\n /**\n * Create Arrow function in one line\n */\n singleLine?: boolean\n}\n\n/**\n * ArrowFunction\n *\n * Renders an arrow function definition. Supports the same flags as `Function`.\n * Use `singleLine` to render the body as a single-line expression.\n */\nfunction ArrowFunction({ children, ...props }: ArrowFunctionProps) {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'ArrowFunction', props })\n\n provide(NodeTreeContext, childTree)\n }\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n const {name} = {async && <>async </>}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {singleLine && (\n <>\n {' => '}\n {children}\n <br />\n </>\n )}\n {!singleLine && (\n <>\n {' => {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n <br />\n </>\n )}\n </>\n )\n}\n\nArrowFunction.displayName = 'ArrowFunction'\nFunction.Arrow = ArrowFunction\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type TypeProps = {\n key?: Key\n /**\n * Name of the type, this needs to start with a capital letter.\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript type declaration.\n */\nexport function Type({ children, ...props }: TypeProps): FabricReactElement {\n const { name, export: canExport, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Type', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (name.charAt(0).toUpperCase() !== name.charAt(0)) {\n throw new Error('Name should start with a capital letter(see TypeScript types)')\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n type {name} = {children}\n </>\n )\n}\n\nType.displayName = 'Type'\n","import { spawn } from 'node:child_process'\nimport { onProcessExit } from '@kubb/fabric-core'\nimport ws from 'ws'\nimport { Renderer } from './Renderer.ts'\n\ndeclare global {\n var WebSocket: typeof WebSocket\n var isDevtoolsEnabled: any\n}\n\nlet isOpen = false\n\nexport function openDevtools() {\n if (isOpen) {\n return undefined\n }\n // Set up global polyfills BEFORE importing react-devtools-core\n // This is required because react-devtools-core expects these to be available\n const customGlobal = global as any\n customGlobal.WebSocket ||= ws\n customGlobal.window ||= global\n customGlobal.self ||= global\n customGlobal.isDevtoolsEnabled = true\n\n // Filter out Kubb internal components from devtools for a cleaner view.\n // See https://github.com/facebook/react/blob/edf6eac8a181860fd8a2d076a43806f1237495a1/packages/react-devtools-shared/src/types.js#L24\n customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Context.Provider',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Root',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'ErrorBoundary',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-file',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-text',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-import',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-export',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-source',\n isEnabled: true,\n isValid: true,\n },\n ]\n\n // biome-ignore lint/suspicious/noTsIgnore: cannot find types\n // @ts-ignore\n import('react-devtools-core').then(async (devtools) => {\n console.info('Opening devtools')\n const controller = new AbortController()\n if (!isOpen) {\n const child = spawn('npx', ['react-devtools@6.1.5'], {\n signal: controller.signal,\n stdio: 'pipe',\n detached: true,\n })\n child.unref()\n }\n\n isOpen = true\n\n // Destructure the functions from the module\n const { initialize, connectToDevTools } = devtools?.default || devtools\n\n // Initialize DevTools BEFORE importing Renderer (which imports React)\n initialize()\n console.info('Initializing devtools')\n\n // Inject the renderer BEFORE connecting to DevTools\n // This ensures DevTools can properly discover the custom renderer\n Renderer.injectIntoDevTools({\n bundleType: 1,\n version: '19.2.3',\n rendererPackageName: 'kubb',\n // findFiberByHostInstance is required for DevTools to map elements to fibers\n findFiberByHostInstance: () => null,\n })\n\n console.info('Connecting devtools')\n\n try {\n connectToDevTools({\n host: 'localhost',\n port: 8097,\n useHttps: false,\n isAppActive: () => true,\n })\n } catch (e) {\n console.error(e)\n console.info('Error when connecting the devtools')\n }\n\n onProcessExit(() => {\n console.info('Disconnecting devtools')\n controller.abort()\n })\n })\n}\n","import { createFabric } from '@kubb/fabric-core'\nimport type { Fabric, FabricConfig, FabricMode } from '@kubb/fabric-core/types'\nimport { openDevtools } from './devtools.ts'\nimport type { Options } from './plugins/reactPlugin.ts'\nimport { reactPlugin } from './plugins/reactPlugin.ts'\n\nexport function createReactFabric(\n config: FabricConfig<Options & { mode?: FabricMode; devtools?: boolean }> = {},\n): Fabric<Options & { mode?: FabricMode; devtools?: boolean }> {\n if (config.devtools) {\n openDevtools()\n }\n\n const fabric = createFabric({ mode: config.mode })\n\n fabric.use(reactPlugin, {\n stdout: config.stdout,\n stderr: config.stderr,\n debug: config.debug,\n stdin: config.stdin,\n })\n\n return fabric\n}\n","import { sortBy } from 'remeda'\n\nexport type Param = {\n /**\n * `object` will return the pathParams as an object.\n *\n * `inline` will return the pathParams as comma separated params.\n * @default `'inline'`\n * @private\n */\n mode?: 'object' | 'inline' | 'inlineSpread'\n type?: 'string' | 'number' | (string & {})\n optional?: boolean\n /**\n * @example test = \"default\"\n */\n default?: string\n /**\n * Used for no TypeScript(with mode object)\n * @example test: \"default\"\n */\n value?: string\n children?: Params\n}\n\ntype ParamItem =\n | (Pick<Param, 'mode' | 'type' | 'value'> & {\n optional?: true\n default?: never\n children?: Params\n })\n | (Pick<Param, 'mode' | 'type' | 'value'> & {\n optional?: false\n default?: string\n children?: Params\n })\n\nexport type Params = Record<string, Param | undefined>\n\ntype Options = {\n type: 'constructor' | 'call' | 'object' | 'objectValue'\n transformName?: (name: string) => string\n transformType?: (type: string) => string\n}\n\nfunction order(items: Array<[key: string, item?: ParamItem]>) {\n return sortBy(items.filter(Boolean) as Array<[key: string, item?: ParamItem]>, ([_key, item]) => {\n if (item?.children) {\n return 0 // Treat items with children as required (they'll get = {} if all children are optional)\n }\n // Priority order: required (0) → optional (1) → default-only (2)\n if (item?.optional) {\n return 1 // Optional parameters (with or without default)\n }\n if (item?.default) {\n // Parameters with default only (not marked as optional)\n // Note: While the ParamItem type suggests optional and default are mutually exclusive,\n // this handles the case where a parameter has a default value but isn't explicitly marked as optional\n return 2\n }\n return 0 // Required parameters\n })\n}\n\nfunction parseChild(key: string, item: ParamItem, options: Options): string | null {\n // @ts-expect-error\n const entries = order(Object.entries(item.children))\n\n const types: string[] = []\n const names: string[] = []\n\n const optional = entries.every(([_key, item]) => item?.optional || !!item?.default)\n\n entries.forEach(([key, entryItem]) => {\n if (entryItem) {\n const name = parseItem(key, { ...entryItem, type: undefined }, options)\n if (entryItem.children) {\n const subTypes = Object.entries(entryItem.children)\n .map(([key]) => {\n return key\n })\n .join(', ')\n\n if (subTypes) {\n names.push(`${name}: { ${subTypes} }`)\n } else {\n names.push(name)\n }\n } else {\n if (options.type === 'call' && options.transformName) {\n names.push(`${key}: ${name}`)\n } else {\n names.push(name)\n }\n }\n\n if (entries.some(([_key, item]) => item?.type)) {\n types.push(parseItem(key, { ...entryItem, default: undefined }, options))\n }\n }\n })\n\n const name = item.mode === 'inline' ? key : names.length ? `{ ${names.join(', ')} }` : undefined\n const type = item.type ? item.type : types.length ? `{ ${types.join('; ')} }` : undefined\n\n if (!name) {\n return null\n }\n\n return parseItem(\n name,\n {\n type,\n default: item.default,\n optional: !item.default ? optional : undefined,\n } as ParamItem,\n options,\n )\n}\n\nfunction parseItem(name: string, item: ParamItem, options: Options): string {\n const acc: string[] = []\n const transformedName = options.transformName ? options.transformName(name) : name\n const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type\n\n if (options.type === 'object') {\n return transformedName\n }\n\n if (options.type === 'objectValue') {\n return item.value ? `${transformedName}: ${item.value}` : transformedName\n }\n\n //LEGACY\n if (item.type && options.type === 'constructor') {\n if (item.optional) {\n // Check if this is a destructured parameter (object mode)\n const isDestructured = transformedName.startsWith('{')\n if (isDestructured) {\n // For destructured parameters, use \": type = {}\" syntax to make it optional\n acc.push(`${transformedName}: ${transformedType} = {}`)\n } else {\n // For inline parameters, use \"?: type\" syntax\n acc.push(`${transformedName}?: ${transformedType}`)\n }\n } else {\n acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ''}`)\n }\n } else if (item.default && options.type === 'constructor') {\n acc.push(`${transformedName} = ${item.default}`)\n } else if (item.value) {\n acc.push(`${transformedName} : ${item.value}`)\n } else if (item.mode === 'inlineSpread') {\n acc.push(`... ${transformedName}`)\n } else {\n acc.push(transformedName)\n }\n\n return acc[0] as string\n}\n\nexport function getFunctionParams(params: Params, options: Options): string {\n const entries = order(Object.entries(params as Record<string, ParamItem | undefined>))\n\n return entries\n .reduce((acc, [key, item]) => {\n if (!item) {\n return acc\n }\n\n if (item.children) {\n if (Object.keys(item.children).length === 0) {\n return acc\n }\n\n if (item.mode === 'inlineSpread') {\n return [...acc, getFunctionParams(item.children, options)]\n }\n\n const parsedItem = parseChild(key, item, options)\n if (!parsedItem) {\n return acc\n }\n\n return [...acc, parsedItem]\n }\n\n const parsedItem = parseItem(key, item, options)\n\n return [...acc, parsedItem]\n }, [] as string[])\n .join(', ')\n}\n\n/**\n * @deprecated use @kubb/ast\n */\nexport function createFunctionParams(params: Params): Params {\n return params\n}\n\n/**\n * @deprecated use @kubb/ast\n */\nexport class FunctionParams {\n #params: Params\n\n static factory(params: Params) {\n return new FunctionParams(params)\n }\n constructor(params: Params) {\n this.#params = params\n }\n\n get params(): Params {\n return this.#params\n }\n\n get flatParams(): Params {\n const flatter = (acc: Params, [key, item]: [key: string, item?: Param]): Params => {\n if (item?.children) {\n return Object.entries(item.children).reduce(flatter, acc)\n }\n if (item) {\n acc[key] = item\n }\n\n return acc\n }\n return Object.entries(this.#params).reduce(flatter, {} as Params)\n }\n\n toCall({ transformName, transformType }: Pick<Options, 'transformName' | 'transformType'> = {}): string {\n return getFunctionParams(this.#params, { type: 'call', transformName, transformType })\n }\n\n toObject(): string {\n return getFunctionParams(this.#params, { type: 'object' })\n }\n toObjectValue(): string {\n return getFunctionParams(this.#params, { type: 'objectValue' })\n }\n\n toConstructor(): string {\n return getFunctionParams(this.#params, { type: 'constructor' })\n }\n}\n","// import './globals.ts'\nimport * as React from 'react'\n\n// expose fabric core helpers\nexport { createContext, createFabric, createFile, FileManager, FileProcessor, TreeNode, useContext } from '@kubb/fabric-core'\n\n// react helpers\nexport const useState = React.useState\nexport const useEffect = React.useEffect\nexport const useReducer = React.useReducer\nexport const useRef = React.useRef\n\nexport { Const } from './components/Const.tsx'\nexport { Fabric } from './components/Fabric.tsx'\nexport { File } from './components/File.tsx'\nexport { Function } from './components/Function.tsx'\n// components\nexport { Root } from './components/Root.tsx'\nexport { Type } from './components/Type.tsx'\n\n// composables\nexport { useFabric } from './composables/useFabric.ts'\nexport { useFile } from './composables/useFile.ts'\nexport { useLifecycle } from './composables/useLifecycle.tsx'\n\n// factories\nexport { createReactFabric } from './createReactFabric.ts'\nexport { openDevtools } from './devtools.ts'\nexport { Runtime } from './Runtime.tsx'\n// utils\nexport { createFunctionParams, FunctionParams } from './utils/getFunctionParams.ts'\n"],"mappings":";;;;;;;;;;;;;;AAmCA,SAAA,MAAA,EAAA,UAAA,GAAA,SAAA;;;AAKE,KAAA,SAAA,EAAA,GAAA,kBAAA,SAAA,kBAAA,iBAAA,SAAA,SAAA;;;;AAMA,QAAA,sCAAA,KAAA,sBAAA,UAAA,EAAA,UAAA;;;;;;;;;;;;;;;AAwBF,MAAA,cAAA;;;;;;ACrDA,SAAgB,OAAsC,EAAE,UAAU,GAAG,SAAiD;CACpH,MAAM,EAAE,OAAO,EAAE,KAAK;CAEtB,MAAM,EAAE,UAAA,GAAA,kBAAA,YAAoBC,kBAAAA,YAAY;CAExC,MAAM,YAAA,GAAA,kBAAA,cAAwB;AAE9B,KAAI,SAGF,EAAA,GAAA,kBAAA,SAAQC,kBAAAA,iBAFU,SAAS,SAAS;EAAE,MAAM;EAAO;EAAO,CAAC,CAExB;AAGrC,EAAA,GAAA,kBAAA,SAAQC,kBAAAA,eAAe;EAAE;EAAM;EAAM,CAAC;AAEtC,QAAO,sCAAA,IAAA,sBAAA,UAAA,EAAG,UAAY,CAAA;;AAGxB,OAAO,cAAc;;;;;;ACGrB,SAAgB,KAAoC,EAAE,UAAU,GAAG,SAA2C;CAC5G,MAAM,EAAE,UAAU,MAAM,OAAO,EAAE,EAAE,QAAQ,WAAW;CAEtD,MAAM,eAAA,GAAA,kBAAA,iBAA8B;CACpC,MAAM,YAAA,GAAA,kBAAA,cAAwB;AAE9B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AAO,QAAQ,KAAK,SAAS,CAAC,OAAO,SAAS,IAAI;AAE3D,OAAI,KACF,KAAI,OAAO;AAGb,UAAO;;AAET,SAAO,OAAO,QAAQ,MAAA,OAAa,CAAC,OAAO,SAAS,EAAE,CAAW;;CAGnE,OAAO,EAAE,eAAe,kBAAoE,EAAE,EAAU;AACtG,SAAO,kBAAkB,MAAA,QAAc;GAAE,MAAM;GAAQ;GAAe;GAAe,CAAC;;CAGxF,WAAmB;AACjB,SAAO,kBAAkB,MAAA,QAAc,EAAE,MAAM,UAAU,CAAC;;CAE5D,gBAAwB;AACtB,SAAO,kBAAkB,MAAA,QAAc,EAAE,MAAM,eAAe,CAAC;;CAGjE,gBAAwB;AACtB,SAAO,kBAAkB,MAAA,QAAc,EAAE,MAAM,eAAe,CAAC;;;;;AC7OnE,MAAa,WAAA,aAAiB;AAC9B,MAAa,YAAA,aAAkB;AAC/B,MAAa,aAAA,aAAmB;AAChC,MAAa,SAAA,aAAe"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as __name } from "./chunk-BGCRLu6H.js";
|
|
2
|
-
import { c as FabricReactElement, f as Key, h as types_d_exports, l as FabricReactNode } from "./types-
|
|
3
|
-
import { t as Options$1 } from "./reactPlugin-
|
|
2
|
+
import { c as FabricReactElement, f as Key, g as FunctionParams, h as types_d_exports, l as FabricReactNode, y as createFunctionParams } from "./types-DG_Fmgyd.js";
|
|
3
|
+
import { t as Options$1 } from "./reactPlugin-D2aNZpS7.js";
|
|
4
4
|
import { FileManager, FileManager as FileManager$1, FileProcessor, TreeNode, TreeNode as TreeNode$1, createContext, createFabric, createFile, useContext, useFabric, useFile, useLifecycle } from "@kubb/fabric-core";
|
|
5
5
|
import { Fabric as Fabric$1, FabricConfig, FabricMode, KubbFile } from "@kubb/fabric-core/types";
|
|
6
6
|
import * as react from "react";
|
|
@@ -341,5 +341,5 @@ declare const useEffect: typeof react.useEffect;
|
|
|
341
341
|
declare const useReducer: typeof react.useReducer;
|
|
342
342
|
declare const useRef: typeof react.useRef;
|
|
343
343
|
//#endregion
|
|
344
|
-
export { Const, Fabric, File, FileManager, FileProcessor, Function, Root, Runtime, TreeNode, Type, createContext, createFabric, createFile, createReactFabric, openDevtools, useContext, useEffect, useFabric, useFile, useLifecycle, useReducer, useRef, useState };
|
|
344
|
+
export { Const, Fabric, File, FileManager, FileProcessor, Function, FunctionParams, Root, Runtime, TreeNode, Type, createContext, createFabric, createFile, createFunctionParams, createReactFabric, openDevtools, useContext, useEffect, useFabric, useFile, useLifecycle, useReducer, useRef, useState };
|
|
345
345
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { i as Root, n as Runtime, r as Renderer, t as reactPlugin } from "./reac
|
|
|
5
5
|
import { FabricContext, FileContext, FileManager, FileProcessor, NodeTreeContext, RootContext, TreeNode, createContext, createFabric, createFabric as createFabric$1, createFile, createJSDoc, onProcessExit, provide, useContext, useContext as useContext$1, useFabric, useFile, useFile as useFile$1, useFileManager, useLifecycle, useNodeTree } from "@kubb/fabric-core";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
import ws from "ws";
|
|
8
|
+
import { sortBy } from "remeda";
|
|
8
9
|
//#region src/utils/createJSDoc.ts
|
|
9
10
|
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
|
|
10
11
|
//#endregion
|
|
@@ -401,12 +402,130 @@ function createReactFabric(config = {}) {
|
|
|
401
402
|
return fabric;
|
|
402
403
|
}
|
|
403
404
|
//#endregion
|
|
405
|
+
//#region src/utils/getFunctionParams.ts
|
|
406
|
+
function order(items) {
|
|
407
|
+
return sortBy(items.filter(Boolean), ([_key, item]) => {
|
|
408
|
+
if (item?.children) return 0;
|
|
409
|
+
if (item?.optional) return 1;
|
|
410
|
+
if (item?.default) return 2;
|
|
411
|
+
return 0;
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
function parseChild(key, item, options) {
|
|
415
|
+
const entries = order(Object.entries(item.children));
|
|
416
|
+
const types = [];
|
|
417
|
+
const names = [];
|
|
418
|
+
const optional = entries.every(([_key, item]) => item?.optional || !!item?.default);
|
|
419
|
+
entries.forEach(([key, entryItem]) => {
|
|
420
|
+
if (entryItem) {
|
|
421
|
+
const name = parseItem(key, {
|
|
422
|
+
...entryItem,
|
|
423
|
+
type: void 0
|
|
424
|
+
}, options);
|
|
425
|
+
if (entryItem.children) {
|
|
426
|
+
const subTypes = Object.entries(entryItem.children).map(([key]) => {
|
|
427
|
+
return key;
|
|
428
|
+
}).join(", ");
|
|
429
|
+
if (subTypes) names.push(`${name}: { ${subTypes} }`);
|
|
430
|
+
else names.push(name);
|
|
431
|
+
} else if (options.type === "call" && options.transformName) names.push(`${key}: ${name}`);
|
|
432
|
+
else names.push(name);
|
|
433
|
+
if (entries.some(([_key, item]) => item?.type)) types.push(parseItem(key, {
|
|
434
|
+
...entryItem,
|
|
435
|
+
default: void 0
|
|
436
|
+
}, options));
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
const name = item.mode === "inline" ? key : names.length ? `{ ${names.join(", ")} }` : void 0;
|
|
440
|
+
const type = item.type ? item.type : types.length ? `{ ${types.join("; ")} }` : void 0;
|
|
441
|
+
if (!name) return null;
|
|
442
|
+
return parseItem(name, {
|
|
443
|
+
type,
|
|
444
|
+
default: item.default,
|
|
445
|
+
optional: !item.default ? optional : void 0
|
|
446
|
+
}, options);
|
|
447
|
+
}
|
|
448
|
+
function parseItem(name, item, options) {
|
|
449
|
+
const acc = [];
|
|
450
|
+
const transformedName = options.transformName ? options.transformName(name) : name;
|
|
451
|
+
const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type;
|
|
452
|
+
if (options.type === "object") return transformedName;
|
|
453
|
+
if (options.type === "objectValue") return item.value ? `${transformedName}: ${item.value}` : transformedName;
|
|
454
|
+
if (item.type && options.type === "constructor") if (item.optional) if (transformedName.startsWith("{")) acc.push(`${transformedName}: ${transformedType} = {}`);
|
|
455
|
+
else acc.push(`${transformedName}?: ${transformedType}`);
|
|
456
|
+
else acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ""}`);
|
|
457
|
+
else if (item.default && options.type === "constructor") acc.push(`${transformedName} = ${item.default}`);
|
|
458
|
+
else if (item.value) acc.push(`${transformedName} : ${item.value}`);
|
|
459
|
+
else if (item.mode === "inlineSpread") acc.push(`... ${transformedName}`);
|
|
460
|
+
else acc.push(transformedName);
|
|
461
|
+
return acc[0];
|
|
462
|
+
}
|
|
463
|
+
function getFunctionParams(params, options) {
|
|
464
|
+
return order(Object.entries(params)).reduce((acc, [key, item]) => {
|
|
465
|
+
if (!item) return acc;
|
|
466
|
+
if (item.children) {
|
|
467
|
+
if (Object.keys(item.children).length === 0) return acc;
|
|
468
|
+
if (item.mode === "inlineSpread") return [...acc, getFunctionParams(item.children, options)];
|
|
469
|
+
const parsedItem = parseChild(key, item, options);
|
|
470
|
+
if (!parsedItem) return acc;
|
|
471
|
+
return [...acc, parsedItem];
|
|
472
|
+
}
|
|
473
|
+
const parsedItem = parseItem(key, item, options);
|
|
474
|
+
return [...acc, parsedItem];
|
|
475
|
+
}, []).join(", ");
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* @deprecated use @kubb/ast
|
|
479
|
+
*/
|
|
480
|
+
function createFunctionParams(params) {
|
|
481
|
+
return params;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* @deprecated use @kubb/ast
|
|
485
|
+
*/
|
|
486
|
+
var FunctionParams = class FunctionParams {
|
|
487
|
+
#params;
|
|
488
|
+
static factory(params) {
|
|
489
|
+
return new FunctionParams(params);
|
|
490
|
+
}
|
|
491
|
+
constructor(params) {
|
|
492
|
+
this.#params = params;
|
|
493
|
+
}
|
|
494
|
+
get params() {
|
|
495
|
+
return this.#params;
|
|
496
|
+
}
|
|
497
|
+
get flatParams() {
|
|
498
|
+
const flatter = (acc, [key, item]) => {
|
|
499
|
+
if (item?.children) return Object.entries(item.children).reduce(flatter, acc);
|
|
500
|
+
if (item) acc[key] = item;
|
|
501
|
+
return acc;
|
|
502
|
+
};
|
|
503
|
+
return Object.entries(this.#params).reduce(flatter, {});
|
|
504
|
+
}
|
|
505
|
+
toCall({ transformName, transformType } = {}) {
|
|
506
|
+
return getFunctionParams(this.#params, {
|
|
507
|
+
type: "call",
|
|
508
|
+
transformName,
|
|
509
|
+
transformType
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
toObject() {
|
|
513
|
+
return getFunctionParams(this.#params, { type: "object" });
|
|
514
|
+
}
|
|
515
|
+
toObjectValue() {
|
|
516
|
+
return getFunctionParams(this.#params, { type: "objectValue" });
|
|
517
|
+
}
|
|
518
|
+
toConstructor() {
|
|
519
|
+
return getFunctionParams(this.#params, { type: "constructor" });
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
//#endregion
|
|
404
523
|
//#region src/index.ts
|
|
405
524
|
const useState = import_react.useState;
|
|
406
525
|
const useEffect = import_react.useEffect;
|
|
407
526
|
const useReducer = import_react.useReducer;
|
|
408
527
|
const useRef = import_react.useRef;
|
|
409
528
|
//#endregion
|
|
410
|
-
export { Const, Fabric, File, FileManager, FileProcessor, Function, Root, Runtime, TreeNode, Type, createContext, createFabric, createFile, createReactFabric, openDevtools, useContext, useEffect, useFabric, useFile, useLifecycle, useReducer, useRef, useState };
|
|
529
|
+
export { Const, Fabric, File, FileManager, FileProcessor, Function, FunctionParams, Root, Runtime, TreeNode, Type, createContext, createFabric, createFile, createFunctionParams, createReactFabric, openDevtools, useContext, useEffect, useFabric, useFile, useLifecycle, useReducer, useRef, useState };
|
|
411
530
|
|
|
412
531
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useContext","useFile","createFabric"],"sources":["../src/utils/createJSDoc.ts","../src/components/Const.tsx","../src/components/Fabric.tsx","../src/components/File.tsx","../src/components/Function.tsx","../src/components/Type.tsx","../src/devtools.ts","../src/createReactFabric.ts","../src/index.ts"],"sourcesContent":["export { createJSDoc } from '@kubb/fabric-core'\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type ConstProps = {\n key?: Key\n /**\n * Name of the const\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Type to make the const being typed\n */\n type?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Use of `const` assertions\n */\n asConst?: boolean\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript constant declaration.\n */\nexport function Const({ children, ...props }: ConstProps): FabricReactElement {\n const { name, export: canExport, type, JSDoc, asConst } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Const', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n const {name}\n {type ? (\n <>\n {':'}\n {type}{' '}\n </>\n ) : (\n ' '\n )}\n = {children}\n {asConst && <> as const</>}\n </>\n )\n}\n\nConst.displayName = 'Const'\n","import { FabricContext, NodeTreeContext, provide, RootContext, useContext, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode } from '../types.ts'\n\nexport type FabricProps<TMeta extends object = object> = {\n /**\n * Metadata associated with the App.\n */\n meta?: TMeta\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Fabric container containing the FabricContext carrying `meta` and an `exit` hook.\n */\nexport function Fabric<TMeta extends object = object>({ children, ...props }: FabricProps<TMeta>): FabricReactElement {\n const { meta = {} } = props\n\n const { exit } = useContext(RootContext)\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'App', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n provide(FabricContext, { exit, meta })\n\n return <>{children}</>\n}\n\nFabric.displayName = 'Fabric'\n","import { FileContext, NodeTreeContext, provide, useFile, useFileManager, useNodeTree } from '@kubb/fabric-core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { FabricReactElement, FabricReactNode, Key } from '../types.ts'\n\ntype BasePropsWithBaseName = {\n /**\n * Name to be used to dynamicly create the baseName(based on input.path).\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: KubbFile.BaseName\n /**\n * Path will be full qualified path to a specified file.\n */\n path: KubbFile.Path\n}\n\ntype BasePropsWithoutBaseName = {\n baseName?: never\n /**\n * Path will be full qualified path to a specified file.\n */\n path?: KubbFile.Path\n}\n\ntype BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName\n\ntype Props<TMeta> = BaseProps & {\n key?: Key\n meta?: TMeta\n banner?: string\n footer?: string\n children?: FabricReactNode\n}\n\n/**\n * Adds files to the FileManager\n */\nexport function File<TMeta extends object = object>({ children, ...props }: Props<TMeta>): FabricReactElement {\n const { baseName, path, meta = {}, footer, banner } = props\n\n const fileManager = useFileManager()\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'File', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (!baseName || !path) {\n return <>{children}</>\n }\n\n const file: KubbFile.File = {\n baseName,\n path,\n meta,\n banner,\n footer,\n sources: [],\n imports: [],\n exports: [],\n }\n\n const [resolvedFile] = fileManager.add(file)\n provide(FileContext, resolvedFile)\n\n return <kubb-file {...props}>{children}</kubb-file>\n}\n\nFile.displayName = 'File'\n\ntype FileSourceProps = Omit<KubbFile.Source, 'value'> & {\n key?: Key\n children?: FabricReactNode\n}\n\n/**\n * File.Source\n *\n * Marks a block of source text to be associated with the current file when\n * rendering with the FileCollector. Children are treated as the source string.\n */\nfunction FileSource({ children, ...props }: FileSourceProps): FabricReactElement {\n const { name, isExportable, isIndexable, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileSource', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <kubb-source name={name} isTypeOnly={isTypeOnly} isExportable={isExportable} isIndexable={isIndexable}>\n {children}\n </kubb-source>\n )\n}\n\nFileSource.displayName = 'FileSource'\n\nexport type FileExportProps = KubbFile.Export & { key?: Key }\n\n/**\n * File.Export\n *\n * Declares an export entry for the current file. This will be collected by\n * the FileCollector for later emission.\n */\nfunction FileExport(props: FileExportProps): FabricReactElement {\n const { name, path, isTypeOnly, asAlias } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileExport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.exports.push({\n name,\n path,\n asAlias,\n isTypeOnly,\n })\n }\n\n return <kubb-export name={name} path={path} isTypeOnly={isTypeOnly} asAlias={asAlias} />\n}\n\nFileExport.displayName = 'FileExport'\n\nexport type FileImportProps = KubbFile.Import & { key?: Key }\n\n/**\n * File.Import\n *\n * Declares an import entry for the current file.\n */\nfunction FileImport(props: FileImportProps): FabricReactElement {\n const { name, root, path, isTypeOnly, isNameSpace } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileImport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.imports.push({\n name,\n path,\n root,\n isNameSpace,\n isTypeOnly,\n })\n }\n\n return <kubb-import name={name} root={root} path={path} isNameSpace={isNameSpace} isTypeOnly={isTypeOnly} />\n}\n\nFileImport.displayName = 'FileImport'\n\nFile.Export = FileExport\nFile.Import = FileImport\nFile.Source = FileSource\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\ntype Props = {\n key?: Key\n /**\n * Name of the function.\n */\n name: string\n /**\n * Add default when export is being used\n */\n default?: boolean\n /**\n * Parameters/options/props that need to be used.\n */\n params?: string\n /**\n * Does this function need to be exported.\n */\n export?: boolean\n /**\n * Does the function has async/promise behavior.\n * This will also add `Promise<returnType>` as the returnType.\n */\n async?: boolean\n /**\n * Generics that needs to be added for TypeScript.\n */\n generics?: string | string[]\n /**\n * ReturnType(see async for adding Promise type).\n */\n returnType?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript function declaration.\n */\nexport function Function({ children, ...props }: Props): FabricReactElement {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Function', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n {async && <>async </>}\n function {name}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {' {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n </>\n )\n}\n\nFunction.displayName = 'Function'\n\ntype ArrowFunctionProps = Props & {\n /**\n * Create Arrow function in one line\n */\n singleLine?: boolean\n}\n\n/**\n * ArrowFunction\n *\n * Renders an arrow function definition. Supports the same flags as `Function`.\n * Use `singleLine` to render the body as a single-line expression.\n */\nfunction ArrowFunction({ children, ...props }: ArrowFunctionProps) {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'ArrowFunction', props })\n\n provide(NodeTreeContext, childTree)\n }\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n const {name} = {async && <>async </>}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {singleLine && (\n <>\n {' => '}\n {children}\n <br />\n </>\n )}\n {!singleLine && (\n <>\n {' => {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n <br />\n </>\n )}\n </>\n )\n}\n\nArrowFunction.displayName = 'ArrowFunction'\nFunction.Arrow = ArrowFunction\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type TypeProps = {\n key?: Key\n /**\n * Name of the type, this needs to start with a capital letter.\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript type declaration.\n */\nexport function Type({ children, ...props }: TypeProps): FabricReactElement {\n const { name, export: canExport, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Type', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (name.charAt(0).toUpperCase() !== name.charAt(0)) {\n throw new Error('Name should start with a capital letter(see TypeScript types)')\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n type {name} = {children}\n </>\n )\n}\n\nType.displayName = 'Type'\n","import { spawn } from 'node:child_process'\nimport { onProcessExit } from '@kubb/fabric-core'\nimport ws from 'ws'\nimport { Renderer } from './Renderer.ts'\n\ndeclare global {\n var WebSocket: typeof WebSocket\n var isDevtoolsEnabled: any\n}\n\nlet isOpen = false\n\nexport function openDevtools() {\n if (isOpen) {\n return undefined\n }\n // Set up global polyfills BEFORE importing react-devtools-core\n // This is required because react-devtools-core expects these to be available\n const customGlobal = global as any\n customGlobal.WebSocket ||= ws\n customGlobal.window ||= global\n customGlobal.self ||= global\n customGlobal.isDevtoolsEnabled = true\n\n // Filter out Kubb internal components from devtools for a cleaner view.\n // See https://github.com/facebook/react/blob/edf6eac8a181860fd8a2d076a43806f1237495a1/packages/react-devtools-shared/src/types.js#L24\n customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Context.Provider',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Root',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'ErrorBoundary',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-file',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-text',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-import',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-export',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-source',\n isEnabled: true,\n isValid: true,\n },\n ]\n\n // biome-ignore lint/suspicious/noTsIgnore: cannot find types\n // @ts-ignore\n import('react-devtools-core').then(async (devtools) => {\n console.info('Opening devtools')\n const controller = new AbortController()\n if (!isOpen) {\n const child = spawn('npx', ['react-devtools@6.1.5'], {\n signal: controller.signal,\n stdio: 'pipe',\n detached: true,\n })\n child.unref()\n }\n\n isOpen = true\n\n // Destructure the functions from the module\n const { initialize, connectToDevTools } = devtools?.default || devtools\n\n // Initialize DevTools BEFORE importing Renderer (which imports React)\n initialize()\n console.info('Initializing devtools')\n\n // Inject the renderer BEFORE connecting to DevTools\n // This ensures DevTools can properly discover the custom renderer\n Renderer.injectIntoDevTools({\n bundleType: 1,\n version: '19.2.3',\n rendererPackageName: 'kubb',\n // findFiberByHostInstance is required for DevTools to map elements to fibers\n findFiberByHostInstance: () => null,\n })\n\n console.info('Connecting devtools')\n\n try {\n connectToDevTools({\n host: 'localhost',\n port: 8097,\n useHttps: false,\n isAppActive: () => true,\n })\n } catch (e) {\n console.error(e)\n console.info('Error when connecting the devtools')\n }\n\n onProcessExit(() => {\n console.info('Disconnecting devtools')\n controller.abort()\n })\n })\n}\n","import { createFabric } from '@kubb/fabric-core'\nimport type { Fabric, FabricConfig, FabricMode } from '@kubb/fabric-core/types'\nimport { openDevtools } from './devtools.ts'\nimport type { Options } from './plugins/reactPlugin.ts'\nimport { reactPlugin } from './plugins/reactPlugin.ts'\n\nexport function createReactFabric(\n config: FabricConfig<Options & { mode?: FabricMode; devtools?: boolean }> = {},\n): Fabric<Options & { mode?: FabricMode; devtools?: boolean }> {\n if (config.devtools) {\n openDevtools()\n }\n\n const fabric = createFabric({ mode: config.mode })\n\n fabric.use(reactPlugin, {\n stdout: config.stdout,\n stderr: config.stderr,\n debug: config.debug,\n stdin: config.stdin,\n })\n\n return fabric\n}\n","// import './globals.ts'\nimport * as React from 'react'\n\n// expose fabric core helpers\nexport { createContext, createFabric, createFile, FileManager, FileProcessor, TreeNode, useContext } from '@kubb/fabric-core'\n\n// react helpers\nexport const useState = React.useState\nexport const useEffect = React.useEffect\nexport const useReducer = React.useReducer\nexport const useRef = React.useRef\n\nexport { Const } from './components/Const.tsx'\nexport { Fabric } from './components/Fabric.tsx'\nexport { File } from './components/File.tsx'\nexport { Function } from './components/Function.tsx'\n// components\nexport { Root } from './components/Root.tsx'\nexport { Type } from './components/Type.tsx'\n\n// composables\nexport { useFabric } from './composables/useFabric.ts'\nexport { useFile } from './composables/useFile.ts'\nexport { useLifecycle } from './composables/useLifecycle.tsx'\n\n// factories\nexport { createReactFabric } from './createReactFabric.ts'\nexport { openDevtools } from './devtools.ts'\nexport { Runtime } from './Runtime.tsx'\n"],"mappings":";;;;;;;;;;;;;;ACmCA,SAAgB,MAAM,EAAE,UAAU,GAAG,SAAyC;CAC5E,MAAM,EAAE,MAAM,QAAQ,WAAW,MAAM,OAAO,YAAY;CAE1D,MAAM,WAAW,aAAa;AAE9B,KAAI,SAGF,SAAQ,iBAFU,SAAS,SAAS;EAAE,MAAM;EAAS;EAAO,CAAC,CAE1B;AAGrC,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,OAAO,YACN,qBAAA,UAAA,EAAA,UAAA,CACG,YAAY,EAAE,UAAU,OAAO,UAAU,CAAC,EAC3C,oBAAC,MAAD,EAAM,CAAA,CACL,EAAA,CAAA;EAEJ,aAAa,oBAAA,UAAA,EAAA,UAAE,WAAU,CAAA;EAAC;EACpB;EACN,OACC,qBAAA,UAAA,EAAA,UAAA;GACG;GACA;GAAM;GACN,EAAA,CAAA,GAEH;EACA;EACC;EACF,WAAW,oBAAA,UAAA,EAAA,UAAE,aAAY,CAAA;EACzB,EAAA,CAAA;;AAIP,MAAM,cAAc;;;;;;ACrDpB,SAAgB,OAAsC,EAAE,UAAU,GAAG,SAAiD;CACpH,MAAM,EAAE,OAAO,EAAE,KAAK;CAEtB,MAAM,EAAE,SAASA,aAAW,YAAY;CAExC,MAAM,WAAW,aAAa;AAE9B,KAAI,SAGF,SAAQ,i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ACtB,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,OAAO,OAAO;EACd,OAAO,OAAO;EACf,CAAC;AAEF,QAAO;;;;ACfT,MAAa,WAAA,aAAiB;AAC9B,MAAa,YAAA,aAAkB;AAC/B,MAAa,aAAA,aAAmB;AAChC,MAAa,SAAA,aAAe"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useContext","useFile","createFabric","#params"],"sources":["../src/utils/createJSDoc.ts","../src/components/Const.tsx","../src/components/Fabric.tsx","../src/components/File.tsx","../src/components/Function.tsx","../src/components/Type.tsx","../src/devtools.ts","../src/createReactFabric.ts","../src/utils/getFunctionParams.ts","../src/index.ts"],"sourcesContent":["export { createJSDoc } from '@kubb/fabric-core'\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type ConstProps = {\n key?: Key\n /**\n * Name of the const\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Type to make the const being typed\n */\n type?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Use of `const` assertions\n */\n asConst?: boolean\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript constant declaration.\n */\nexport function Const({ children, ...props }: ConstProps): FabricReactElement {\n const { name, export: canExport, type, JSDoc, asConst } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Const', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n const {name}\n {type ? (\n <>\n {':'}\n {type}{' '}\n </>\n ) : (\n ' '\n )}\n = {children}\n {asConst && <> as const</>}\n </>\n )\n}\n\nConst.displayName = 'Const'\n","import { FabricContext, NodeTreeContext, provide, RootContext, useContext, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode } from '../types.ts'\n\nexport type FabricProps<TMeta extends object = object> = {\n /**\n * Metadata associated with the App.\n */\n meta?: TMeta\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Fabric container containing the FabricContext carrying `meta` and an `exit` hook.\n */\nexport function Fabric<TMeta extends object = object>({ children, ...props }: FabricProps<TMeta>): FabricReactElement {\n const { meta = {} } = props\n\n const { exit } = useContext(RootContext)\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'App', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n provide(FabricContext, { exit, meta })\n\n return <>{children}</>\n}\n\nFabric.displayName = 'Fabric'\n","import { FileContext, NodeTreeContext, provide, useFile, useFileManager, useNodeTree } from '@kubb/fabric-core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { FabricReactElement, FabricReactNode, Key } from '../types.ts'\n\ntype BasePropsWithBaseName = {\n /**\n * Name to be used to dynamicly create the baseName(based on input.path).\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: KubbFile.BaseName\n /**\n * Path will be full qualified path to a specified file.\n */\n path: KubbFile.Path\n}\n\ntype BasePropsWithoutBaseName = {\n baseName?: never\n /**\n * Path will be full qualified path to a specified file.\n */\n path?: KubbFile.Path\n}\n\ntype BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName\n\ntype Props<TMeta> = BaseProps & {\n key?: Key\n meta?: TMeta\n banner?: string\n footer?: string\n children?: FabricReactNode\n}\n\n/**\n * Adds files to the FileManager\n */\nexport function File<TMeta extends object = object>({ children, ...props }: Props<TMeta>): FabricReactElement {\n const { baseName, path, meta = {}, footer, banner } = props\n\n const fileManager = useFileManager()\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'File', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (!baseName || !path) {\n return <>{children}</>\n }\n\n const file: KubbFile.File = {\n baseName,\n path,\n meta,\n banner,\n footer,\n sources: [],\n imports: [],\n exports: [],\n }\n\n const [resolvedFile] = fileManager.add(file)\n provide(FileContext, resolvedFile)\n\n return <kubb-file {...props}>{children}</kubb-file>\n}\n\nFile.displayName = 'File'\n\ntype FileSourceProps = Omit<KubbFile.Source, 'value'> & {\n key?: Key\n children?: FabricReactNode\n}\n\n/**\n * File.Source\n *\n * Marks a block of source text to be associated with the current file when\n * rendering with the FileCollector. Children are treated as the source string.\n */\nfunction FileSource({ children, ...props }: FileSourceProps): FabricReactElement {\n const { name, isExportable, isIndexable, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileSource', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <kubb-source name={name} isTypeOnly={isTypeOnly} isExportable={isExportable} isIndexable={isIndexable}>\n {children}\n </kubb-source>\n )\n}\n\nFileSource.displayName = 'FileSource'\n\nexport type FileExportProps = KubbFile.Export & { key?: Key }\n\n/**\n * File.Export\n *\n * Declares an export entry for the current file. This will be collected by\n * the FileCollector for later emission.\n */\nfunction FileExport(props: FileExportProps): FabricReactElement {\n const { name, path, isTypeOnly, asAlias } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileExport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.exports.push({\n name,\n path,\n asAlias,\n isTypeOnly,\n })\n }\n\n return <kubb-export name={name} path={path} isTypeOnly={isTypeOnly} asAlias={asAlias} />\n}\n\nFileExport.displayName = 'FileExport'\n\nexport type FileImportProps = KubbFile.Import & { key?: Key }\n\n/**\n * File.Import\n *\n * Declares an import entry for the current file.\n */\nfunction FileImport(props: FileImportProps): FabricReactElement {\n const { name, root, path, isTypeOnly, isNameSpace } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileImport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.imports.push({\n name,\n path,\n root,\n isNameSpace,\n isTypeOnly,\n })\n }\n\n return <kubb-import name={name} root={root} path={path} isNameSpace={isNameSpace} isTypeOnly={isTypeOnly} />\n}\n\nFileImport.displayName = 'FileImport'\n\nFile.Export = FileExport\nFile.Import = FileImport\nFile.Source = FileSource\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\ntype Props = {\n key?: Key\n /**\n * Name of the function.\n */\n name: string\n /**\n * Add default when export is being used\n */\n default?: boolean\n /**\n * Parameters/options/props that need to be used.\n */\n params?: string\n /**\n * Does this function need to be exported.\n */\n export?: boolean\n /**\n * Does the function has async/promise behavior.\n * This will also add `Promise<returnType>` as the returnType.\n */\n async?: boolean\n /**\n * Generics that needs to be added for TypeScript.\n */\n generics?: string | string[]\n /**\n * ReturnType(see async for adding Promise type).\n */\n returnType?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript function declaration.\n */\nexport function Function({ children, ...props }: Props): FabricReactElement {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Function', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n {async && <>async </>}\n function {name}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {' {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n </>\n )\n}\n\nFunction.displayName = 'Function'\n\ntype ArrowFunctionProps = Props & {\n /**\n * Create Arrow function in one line\n */\n singleLine?: boolean\n}\n\n/**\n * ArrowFunction\n *\n * Renders an arrow function definition. Supports the same flags as `Function`.\n * Use `singleLine` to render the body as a single-line expression.\n */\nfunction ArrowFunction({ children, ...props }: ArrowFunctionProps) {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'ArrowFunction', props })\n\n provide(NodeTreeContext, childTree)\n }\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n {isDefault && <>default </>}\n const {name} = {async && <>async </>}\n {generics && (\n <>\n {'<'}\n {Array.isArray(generics) ? generics.join(', ').trim() : generics}\n {'>'}\n </>\n )}\n ({params}){returnType && !async && <>: {returnType}</>}\n {returnType && async && (\n <>\n : Promise{'<'}\n {returnType}\n {'>'}\n </>\n )}\n {singleLine && (\n <>\n {' => '}\n {children}\n <br />\n </>\n )}\n {!singleLine && (\n <>\n {' => {'}\n <br />\n <indent />\n {/* Indent component to handle indentation*/}\n {children}\n <br />\n <dedent />\n {/* Indent component to handle indentation*/}\n {'}'}\n <br />\n </>\n )}\n </>\n )\n}\n\nArrowFunction.displayName = 'ArrowFunction'\nFunction.Arrow = ArrowFunction\n","import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'\nimport type { FabricReactElement, FabricReactNode, JSDoc, Key } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type TypeProps = {\n key?: Key\n /**\n * Name of the type, this needs to start with a capital letter.\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Children nodes.\n */\n children?: FabricReactNode\n}\n\n/**\n * Generates a TypeScript type declaration.\n */\nexport function Type({ children, ...props }: TypeProps): FabricReactElement {\n const { name, export: canExport, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Type', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (name.charAt(0).toUpperCase() !== name.charAt(0)) {\n throw new Error('Name should start with a capital letter(see TypeScript types)')\n }\n\n return (\n <>\n {JSDoc?.comments && (\n <>\n {createJSDoc({ comments: JSDoc?.comments })}\n <br />\n </>\n )}\n {canExport && <>export </>}\n type {name} = {children}\n </>\n )\n}\n\nType.displayName = 'Type'\n","import { spawn } from 'node:child_process'\nimport { onProcessExit } from '@kubb/fabric-core'\nimport ws from 'ws'\nimport { Renderer } from './Renderer.ts'\n\ndeclare global {\n var WebSocket: typeof WebSocket\n var isDevtoolsEnabled: any\n}\n\nlet isOpen = false\n\nexport function openDevtools() {\n if (isOpen) {\n return undefined\n }\n // Set up global polyfills BEFORE importing react-devtools-core\n // This is required because react-devtools-core expects these to be available\n const customGlobal = global as any\n customGlobal.WebSocket ||= ws\n customGlobal.window ||= global\n customGlobal.self ||= global\n customGlobal.isDevtoolsEnabled = true\n\n // Filter out Kubb internal components from devtools for a cleaner view.\n // See https://github.com/facebook/react/blob/edf6eac8a181860fd8a2d076a43806f1237495a1/packages/react-devtools-shared/src/types.js#L24\n customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Context.Provider',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'Root',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'ErrorBoundary',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-file',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-text',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-import',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-export',\n isEnabled: true,\n isValid: true,\n },\n {\n // ComponentFilterDisplayName\n type: 2,\n value: 'kubb-source',\n isEnabled: true,\n isValid: true,\n },\n ]\n\n // biome-ignore lint/suspicious/noTsIgnore: cannot find types\n // @ts-ignore\n import('react-devtools-core').then(async (devtools) => {\n console.info('Opening devtools')\n const controller = new AbortController()\n if (!isOpen) {\n const child = spawn('npx', ['react-devtools@6.1.5'], {\n signal: controller.signal,\n stdio: 'pipe',\n detached: true,\n })\n child.unref()\n }\n\n isOpen = true\n\n // Destructure the functions from the module\n const { initialize, connectToDevTools } = devtools?.default || devtools\n\n // Initialize DevTools BEFORE importing Renderer (which imports React)\n initialize()\n console.info('Initializing devtools')\n\n // Inject the renderer BEFORE connecting to DevTools\n // This ensures DevTools can properly discover the custom renderer\n Renderer.injectIntoDevTools({\n bundleType: 1,\n version: '19.2.3',\n rendererPackageName: 'kubb',\n // findFiberByHostInstance is required for DevTools to map elements to fibers\n findFiberByHostInstance: () => null,\n })\n\n console.info('Connecting devtools')\n\n try {\n connectToDevTools({\n host: 'localhost',\n port: 8097,\n useHttps: false,\n isAppActive: () => true,\n })\n } catch (e) {\n console.error(e)\n console.info('Error when connecting the devtools')\n }\n\n onProcessExit(() => {\n console.info('Disconnecting devtools')\n controller.abort()\n })\n })\n}\n","import { createFabric } from '@kubb/fabric-core'\nimport type { Fabric, FabricConfig, FabricMode } from '@kubb/fabric-core/types'\nimport { openDevtools } from './devtools.ts'\nimport type { Options } from './plugins/reactPlugin.ts'\nimport { reactPlugin } from './plugins/reactPlugin.ts'\n\nexport function createReactFabric(\n config: FabricConfig<Options & { mode?: FabricMode; devtools?: boolean }> = {},\n): Fabric<Options & { mode?: FabricMode; devtools?: boolean }> {\n if (config.devtools) {\n openDevtools()\n }\n\n const fabric = createFabric({ mode: config.mode })\n\n fabric.use(reactPlugin, {\n stdout: config.stdout,\n stderr: config.stderr,\n debug: config.debug,\n stdin: config.stdin,\n })\n\n return fabric\n}\n","import { sortBy } from 'remeda'\n\nexport type Param = {\n /**\n * `object` will return the pathParams as an object.\n *\n * `inline` will return the pathParams as comma separated params.\n * @default `'inline'`\n * @private\n */\n mode?: 'object' | 'inline' | 'inlineSpread'\n type?: 'string' | 'number' | (string & {})\n optional?: boolean\n /**\n * @example test = \"default\"\n */\n default?: string\n /**\n * Used for no TypeScript(with mode object)\n * @example test: \"default\"\n */\n value?: string\n children?: Params\n}\n\ntype ParamItem =\n | (Pick<Param, 'mode' | 'type' | 'value'> & {\n optional?: true\n default?: never\n children?: Params\n })\n | (Pick<Param, 'mode' | 'type' | 'value'> & {\n optional?: false\n default?: string\n children?: Params\n })\n\nexport type Params = Record<string, Param | undefined>\n\ntype Options = {\n type: 'constructor' | 'call' | 'object' | 'objectValue'\n transformName?: (name: string) => string\n transformType?: (type: string) => string\n}\n\nfunction order(items: Array<[key: string, item?: ParamItem]>) {\n return sortBy(items.filter(Boolean) as Array<[key: string, item?: ParamItem]>, ([_key, item]) => {\n if (item?.children) {\n return 0 // Treat items with children as required (they'll get = {} if all children are optional)\n }\n // Priority order: required (0) → optional (1) → default-only (2)\n if (item?.optional) {\n return 1 // Optional parameters (with or without default)\n }\n if (item?.default) {\n // Parameters with default only (not marked as optional)\n // Note: While the ParamItem type suggests optional and default are mutually exclusive,\n // this handles the case where a parameter has a default value but isn't explicitly marked as optional\n return 2\n }\n return 0 // Required parameters\n })\n}\n\nfunction parseChild(key: string, item: ParamItem, options: Options): string | null {\n // @ts-expect-error\n const entries = order(Object.entries(item.children))\n\n const types: string[] = []\n const names: string[] = []\n\n const optional = entries.every(([_key, item]) => item?.optional || !!item?.default)\n\n entries.forEach(([key, entryItem]) => {\n if (entryItem) {\n const name = parseItem(key, { ...entryItem, type: undefined }, options)\n if (entryItem.children) {\n const subTypes = Object.entries(entryItem.children)\n .map(([key]) => {\n return key\n })\n .join(', ')\n\n if (subTypes) {\n names.push(`${name}: { ${subTypes} }`)\n } else {\n names.push(name)\n }\n } else {\n if (options.type === 'call' && options.transformName) {\n names.push(`${key}: ${name}`)\n } else {\n names.push(name)\n }\n }\n\n if (entries.some(([_key, item]) => item?.type)) {\n types.push(parseItem(key, { ...entryItem, default: undefined }, options))\n }\n }\n })\n\n const name = item.mode === 'inline' ? key : names.length ? `{ ${names.join(', ')} }` : undefined\n const type = item.type ? item.type : types.length ? `{ ${types.join('; ')} }` : undefined\n\n if (!name) {\n return null\n }\n\n return parseItem(\n name,\n {\n type,\n default: item.default,\n optional: !item.default ? optional : undefined,\n } as ParamItem,\n options,\n )\n}\n\nfunction parseItem(name: string, item: ParamItem, options: Options): string {\n const acc: string[] = []\n const transformedName = options.transformName ? options.transformName(name) : name\n const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type\n\n if (options.type === 'object') {\n return transformedName\n }\n\n if (options.type === 'objectValue') {\n return item.value ? `${transformedName}: ${item.value}` : transformedName\n }\n\n //LEGACY\n if (item.type && options.type === 'constructor') {\n if (item.optional) {\n // Check if this is a destructured parameter (object mode)\n const isDestructured = transformedName.startsWith('{')\n if (isDestructured) {\n // For destructured parameters, use \": type = {}\" syntax to make it optional\n acc.push(`${transformedName}: ${transformedType} = {}`)\n } else {\n // For inline parameters, use \"?: type\" syntax\n acc.push(`${transformedName}?: ${transformedType}`)\n }\n } else {\n acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ''}`)\n }\n } else if (item.default && options.type === 'constructor') {\n acc.push(`${transformedName} = ${item.default}`)\n } else if (item.value) {\n acc.push(`${transformedName} : ${item.value}`)\n } else if (item.mode === 'inlineSpread') {\n acc.push(`... ${transformedName}`)\n } else {\n acc.push(transformedName)\n }\n\n return acc[0] as string\n}\n\nexport function getFunctionParams(params: Params, options: Options): string {\n const entries = order(Object.entries(params as Record<string, ParamItem | undefined>))\n\n return entries\n .reduce((acc, [key, item]) => {\n if (!item) {\n return acc\n }\n\n if (item.children) {\n if (Object.keys(item.children).length === 0) {\n return acc\n }\n\n if (item.mode === 'inlineSpread') {\n return [...acc, getFunctionParams(item.children, options)]\n }\n\n const parsedItem = parseChild(key, item, options)\n if (!parsedItem) {\n return acc\n }\n\n return [...acc, parsedItem]\n }\n\n const parsedItem = parseItem(key, item, options)\n\n return [...acc, parsedItem]\n }, [] as string[])\n .join(', ')\n}\n\n/**\n * @deprecated use @kubb/ast\n */\nexport function createFunctionParams(params: Params): Params {\n return params\n}\n\n/**\n * @deprecated use @kubb/ast\n */\nexport class FunctionParams {\n #params: Params\n\n static factory(params: Params) {\n return new FunctionParams(params)\n }\n constructor(params: Params) {\n this.#params = params\n }\n\n get params(): Params {\n return this.#params\n }\n\n get flatParams(): Params {\n const flatter = (acc: Params, [key, item]: [key: string, item?: Param]): Params => {\n if (item?.children) {\n return Object.entries(item.children).reduce(flatter, acc)\n }\n if (item) {\n acc[key] = item\n }\n\n return acc\n }\n return Object.entries(this.#params).reduce(flatter, {} as Params)\n }\n\n toCall({ transformName, transformType }: Pick<Options, 'transformName' | 'transformType'> = {}): string {\n return getFunctionParams(this.#params, { type: 'call', transformName, transformType })\n }\n\n toObject(): string {\n return getFunctionParams(this.#params, { type: 'object' })\n }\n toObjectValue(): string {\n return getFunctionParams(this.#params, { type: 'objectValue' })\n }\n\n toConstructor(): string {\n return getFunctionParams(this.#params, { type: 'constructor' })\n }\n}\n","// import './globals.ts'\nimport * as React from 'react'\n\n// expose fabric core helpers\nexport { createContext, createFabric, createFile, FileManager, FileProcessor, TreeNode, useContext } from '@kubb/fabric-core'\n\n// react helpers\nexport const useState = React.useState\nexport const useEffect = React.useEffect\nexport const useReducer = React.useReducer\nexport const useRef = React.useRef\n\nexport { Const } from './components/Const.tsx'\nexport { Fabric } from './components/Fabric.tsx'\nexport { File } from './components/File.tsx'\nexport { Function } from './components/Function.tsx'\n// components\nexport { Root } from './components/Root.tsx'\nexport { Type } from './components/Type.tsx'\n\n// composables\nexport { useFabric } from './composables/useFabric.ts'\nexport { useFile } from './composables/useFile.ts'\nexport { useLifecycle } from './composables/useLifecycle.tsx'\n\n// factories\nexport { createReactFabric } from './createReactFabric.ts'\nexport { openDevtools } from './devtools.ts'\nexport { Runtime } from './Runtime.tsx'\n// utils\nexport { createFunctionParams, FunctionParams } from './utils/getFunctionParams.ts'\n"],"mappings":";;;;;;;;;;;;;;;ACmCA,SAAgB,MAAM,EAAE,UAAU,GAAG,SAAyC;CAC5E,MAAM,EAAE,MAAM,QAAQ,WAAW,MAAM,OAAO,YAAY;CAE1D,MAAM,WAAW,aAAa;AAE9B,KAAI,SAGF,SAAQ,iBAFU,SAAS,SAAS;EAAE,MAAM;EAAS;EAAO,CAAC,CAE1B;AAGrC,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,OAAO,YACN,qBAAA,UAAA,EAAA,UAAA,CACG,YAAY,EAAE,UAAU,OAAO,UAAU,CAAC,EAC3C,oBAAC,MAAD,EAAM,CAAA,CACL,EAAA,CAAA;EAEJ,aAAa,oBAAA,UAAA,EAAA,UAAE,WAAU,CAAA;EAAC;EACpB;EACN,OACC,qBAAA,UAAA,EAAA,UAAA;GACG;GACA;GAAM;GACN,EAAA,CAAA,GAEH;EACA;EACC;EACF,WAAW,oBAAA,UAAA,EAAA,UAAE,aAAY,CAAA;EACzB,EAAA,CAAA;;AAIP,MAAM,cAAc;;;;;;ACrDpB,SAAgB,OAAsC,EAAE,UAAU,GAAG,SAAiD;CACpH,MAAM,EAAE,OAAO,EAAE,KAAK;CAEtB,MAAM,EAAE,SAASA,aAAW,YAAY;CAExC,MAAM,WAAW,aAAa;AAE9B,KAAI,SAGF,SAAQ,iBAFU,SAAS,SAAS;EAAE,MAAM;E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;AAC/B,MAAa,aAAA,aAAmB;AAChC,MAAa,SAAA,aAAe"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as __name } from "./chunk-BGCRLu6H.js";
|
|
2
|
-
import { c as FabricReactElement, l as FabricReactNode } from "./types-
|
|
3
|
-
import { t as JSX } from "./jsx-namespace-
|
|
2
|
+
import { c as FabricReactElement, l as FabricReactNode } from "./types-DG_Fmgyd.js";
|
|
3
|
+
import { t as JSX } from "./jsx-namespace-BUQfB16E.js";
|
|
4
4
|
import * as react from "react";
|
|
5
5
|
import * as React$1 from "react/jsx-runtime";
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as __name } from "./chunk-BGCRLu6H.js";
|
|
2
|
-
import { a as FabricExportProps, c as FabricReactElement, d as FabricTextProps, l as FabricReactNode, o as FabricFileProps, p as LineBreakProps, s as FabricImportProps, u as FabricSourceProps } from "./types-
|
|
2
|
+
import { a as FabricExportProps, c as FabricReactElement, d as FabricTextProps, l as FabricReactNode, o as FabricFileProps, p as LineBreakProps, s as FabricImportProps, u as FabricSourceProps } from "./types-DG_Fmgyd.js";
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
5
5
|
//#region src/jsx-namespace.d.ts
|
|
@@ -31,4 +31,4 @@ declare namespace JSX$1 {
|
|
|
31
31
|
}
|
|
32
32
|
//#endregion
|
|
33
33
|
export { JSX$1 as t };
|
|
34
|
-
//# sourceMappingURL=jsx-namespace-
|
|
34
|
+
//# sourceMappingURL=jsx-namespace-BUQfB16E.d.ts.map
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as __name } from "./chunk-BGCRLu6H.js";
|
|
2
|
-
import { c as FabricReactElement, l as FabricReactNode } from "./types-
|
|
3
|
-
import { t as JSX } from "./jsx-namespace-
|
|
2
|
+
import { c as FabricReactElement, l as FabricReactNode } from "./types-DG_Fmgyd.js";
|
|
3
|
+
import { t as JSX } from "./jsx-namespace-BUQfB16E.js";
|
|
4
4
|
import * as react from "react";
|
|
5
5
|
import * as React$1 from "react/jsx-runtime";
|
|
6
6
|
|
package/dist/plugins.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./jsx-runtime-Cua1md-Z.cjs");
|
|
3
2
|
const require_reactPlugin = require("./reactPlugin-D74A1eG4.cjs");
|
|
4
3
|
exports.reactPlugin = require_reactPlugin.reactPlugin;
|
|
5
4
|
var _kubb_fabric_core_plugins = require("@kubb/fabric-core/plugins");
|
package/dist/plugins.d.ts
CHANGED
package/dist/plugins.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as __name } from "./chunk-BGCRLu6H.js";
|
|
2
|
-
import { c as FabricReactElement, h as types_d_exports } from "./types-
|
|
2
|
+
import { c as FabricReactElement, h as types_d_exports } from "./types-DG_Fmgyd.js";
|
|
3
3
|
import { TreeNode } from "@kubb/fabric-core";
|
|
4
4
|
import * as _kubb_fabric_core_plugins0 from "@kubb/fabric-core/plugins";
|
|
5
5
|
|
|
@@ -32,4 +32,4 @@ declare global {
|
|
|
32
32
|
declare const reactPlugin: _kubb_fabric_core_plugins0.Plugin<Options, ExtendOptions>;
|
|
33
33
|
//#endregion
|
|
34
34
|
export { reactPlugin as n, Options as t };
|
|
35
|
-
//# sourceMappingURL=reactPlugin-
|
|
35
|
+
//# sourceMappingURL=reactPlugin-D2aNZpS7.d.ts.map
|
|
@@ -2,9 +2,58 @@ import { i as __reExport, n as __exportAll, r as __name } from "./chunk-BGCRLu6H
|
|
|
2
2
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
3
3
|
import React, { JSX, ReactNode } from "react";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/utils/getFunctionParams.d.ts
|
|
6
|
+
type Param = {
|
|
7
|
+
/**
|
|
8
|
+
* `object` will return the pathParams as an object.
|
|
9
|
+
*
|
|
10
|
+
* `inline` will return the pathParams as comma separated params.
|
|
11
|
+
* @default `'inline'`
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
mode?: 'object' | 'inline' | 'inlineSpread';
|
|
15
|
+
type?: 'string' | 'number' | (string & {});
|
|
16
|
+
optional?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* @example test = "default"
|
|
19
|
+
*/
|
|
20
|
+
default?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Used for no TypeScript(with mode object)
|
|
23
|
+
* @example test: "default"
|
|
24
|
+
*/
|
|
25
|
+
value?: string;
|
|
26
|
+
children?: Params;
|
|
27
|
+
};
|
|
28
|
+
type Params = Record<string, Param | undefined>;
|
|
29
|
+
type Options = {
|
|
30
|
+
type: 'constructor' | 'call' | 'object' | 'objectValue';
|
|
31
|
+
transformName?: (name: string) => string;
|
|
32
|
+
transformType?: (type: string) => string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated use @kubb/ast
|
|
36
|
+
*/
|
|
37
|
+
declare function createFunctionParams(params: Params): Params;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated use @kubb/ast
|
|
40
|
+
*/
|
|
41
|
+
declare class FunctionParams {
|
|
42
|
+
#private;
|
|
43
|
+
static factory(params: Params): FunctionParams;
|
|
44
|
+
constructor(params: Params);
|
|
45
|
+
get params(): Params;
|
|
46
|
+
get flatParams(): Params;
|
|
47
|
+
toCall({
|
|
48
|
+
transformName,
|
|
49
|
+
transformType
|
|
50
|
+
}?: Pick<Options, 'transformName' | 'transformType'>): string;
|
|
51
|
+
toObject(): string;
|
|
52
|
+
toObjectValue(): string;
|
|
53
|
+
toConstructor(): string;
|
|
54
|
+
}
|
|
6
55
|
declare namespace types_d_exports {
|
|
7
|
-
export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricExportProps, FabricFileProps, FabricImportProps, FabricReactElement, FabricReactNode, FabricSourceProps, FabricTextProps, Key, LineBreakProps, TextNode };
|
|
56
|
+
export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricExportProps, FabricFileProps, FabricImportProps, FabricReactElement, FabricReactNode, FabricSourceProps, FabricTextProps, Key, LineBreakProps, Param, Params, TextNode };
|
|
8
57
|
}
|
|
9
58
|
import * as import__kubb_fabric_core_types from "@kubb/fabric-core/types";
|
|
10
59
|
type Key = string | number | bigint;
|
|
@@ -57,5 +106,5 @@ type FabricImportProps = KubbFile.Import;
|
|
|
57
106
|
type FabricExportProps = KubbFile.Export;
|
|
58
107
|
type LineBreakProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLBRElement>, HTMLBRElement>;
|
|
59
108
|
//#endregion
|
|
60
|
-
export { FabricExportProps as a, FabricReactElement as c, FabricTextProps as d, Key as f, types_d_exports as h, ElementNames as i, FabricReactNode as l, TextNode as m, DOMNode as n, FabricFileProps as o, LineBreakProps as p, DOMNodeAttribute as r, FabricImportProps as s, DOMElement as t, FabricSourceProps as u };
|
|
61
|
-
//# sourceMappingURL=types-
|
|
109
|
+
export { Param as _, FabricExportProps as a, FabricReactElement as c, FabricTextProps as d, Key as f, FunctionParams as g, types_d_exports as h, ElementNames as i, FabricReactNode as l, TextNode as m, DOMNode as n, FabricFileProps as o, LineBreakProps as p, DOMNodeAttribute as r, FabricImportProps as s, DOMElement as t, FabricSourceProps as u, Params as v, createFunctionParams as y };
|
|
110
|
+
//# sourceMappingURL=types-DG_Fmgyd.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as FabricExportProps, c as FabricReactElement, d as FabricTextProps, f as Key, i as ElementNames, l as FabricReactNode, m as TextNode, n as DOMNode, o as FabricFileProps, p as LineBreakProps, r as DOMNodeAttribute, s as FabricImportProps, t as DOMElement, u as FabricSourceProps } from "./types-
|
|
1
|
+
import { _ as Param, a as FabricExportProps, c as FabricReactElement, d as FabricTextProps, f as Key, i as ElementNames, l as FabricReactNode, m as TextNode, n as DOMNode, o as FabricFileProps, p as LineBreakProps, r as DOMNodeAttribute, s as FabricImportProps, t as DOMElement, u as FabricSourceProps, v as Params } from "./types-DG_Fmgyd.js";
|
|
2
2
|
export * from "@kubb/fabric-core/types";
|
|
3
|
-
export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricExportProps, FabricFileProps, FabricImportProps, FabricReactElement, FabricReactNode, FabricSourceProps, FabricTextProps, Key, LineBreakProps, TextNode };
|
|
3
|
+
export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricExportProps, FabricFileProps, FabricImportProps, FabricReactElement, FabricReactNode, FabricSourceProps, FabricTextProps, Key, LineBreakProps, Param, Params, TextNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/react-fabric",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "React integration for Kubb's fabric - JSX runtime and component-based code generation with React reconciler for building type-safe generators",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"react-devtools-core": "6.1.5",
|
|
107
107
|
"remeda": "^2.33.6",
|
|
108
108
|
"ws": "8.18.0",
|
|
109
|
-
"@kubb/fabric-core": "0.15.
|
|
109
|
+
"@kubb/fabric-core": "0.15.2"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/react": "^19.2.14",
|
package/src/index.ts
CHANGED
|
@@ -27,3 +27,5 @@ export { useLifecycle } from './composables/useLifecycle.tsx'
|
|
|
27
27
|
export { createReactFabric } from './createReactFabric.ts'
|
|
28
28
|
export { openDevtools } from './devtools.ts'
|
|
29
29
|
export { Runtime } from './Runtime.tsx'
|
|
30
|
+
// utils
|
|
31
|
+
export { createFunctionParams, FunctionParams } from './utils/getFunctionParams.ts'
|
package/src/types.ts
CHANGED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { sortBy } from 'remeda'
|
|
2
|
+
|
|
3
|
+
export type Param = {
|
|
4
|
+
/**
|
|
5
|
+
* `object` will return the pathParams as an object.
|
|
6
|
+
*
|
|
7
|
+
* `inline` will return the pathParams as comma separated params.
|
|
8
|
+
* @default `'inline'`
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
mode?: 'object' | 'inline' | 'inlineSpread'
|
|
12
|
+
type?: 'string' | 'number' | (string & {})
|
|
13
|
+
optional?: boolean
|
|
14
|
+
/**
|
|
15
|
+
* @example test = "default"
|
|
16
|
+
*/
|
|
17
|
+
default?: string
|
|
18
|
+
/**
|
|
19
|
+
* Used for no TypeScript(with mode object)
|
|
20
|
+
* @example test: "default"
|
|
21
|
+
*/
|
|
22
|
+
value?: string
|
|
23
|
+
children?: Params
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type ParamItem =
|
|
27
|
+
| (Pick<Param, 'mode' | 'type' | 'value'> & {
|
|
28
|
+
optional?: true
|
|
29
|
+
default?: never
|
|
30
|
+
children?: Params
|
|
31
|
+
})
|
|
32
|
+
| (Pick<Param, 'mode' | 'type' | 'value'> & {
|
|
33
|
+
optional?: false
|
|
34
|
+
default?: string
|
|
35
|
+
children?: Params
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export type Params = Record<string, Param | undefined>
|
|
39
|
+
|
|
40
|
+
type Options = {
|
|
41
|
+
type: 'constructor' | 'call' | 'object' | 'objectValue'
|
|
42
|
+
transformName?: (name: string) => string
|
|
43
|
+
transformType?: (type: string) => string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function order(items: Array<[key: string, item?: ParamItem]>) {
|
|
47
|
+
return sortBy(items.filter(Boolean) as Array<[key: string, item?: ParamItem]>, ([_key, item]) => {
|
|
48
|
+
if (item?.children) {
|
|
49
|
+
return 0 // Treat items with children as required (they'll get = {} if all children are optional)
|
|
50
|
+
}
|
|
51
|
+
// Priority order: required (0) → optional (1) → default-only (2)
|
|
52
|
+
if (item?.optional) {
|
|
53
|
+
return 1 // Optional parameters (with or without default)
|
|
54
|
+
}
|
|
55
|
+
if (item?.default) {
|
|
56
|
+
// Parameters with default only (not marked as optional)
|
|
57
|
+
// Note: While the ParamItem type suggests optional and default are mutually exclusive,
|
|
58
|
+
// this handles the case where a parameter has a default value but isn't explicitly marked as optional
|
|
59
|
+
return 2
|
|
60
|
+
}
|
|
61
|
+
return 0 // Required parameters
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function parseChild(key: string, item: ParamItem, options: Options): string | null {
|
|
66
|
+
// @ts-expect-error
|
|
67
|
+
const entries = order(Object.entries(item.children))
|
|
68
|
+
|
|
69
|
+
const types: string[] = []
|
|
70
|
+
const names: string[] = []
|
|
71
|
+
|
|
72
|
+
const optional = entries.every(([_key, item]) => item?.optional || !!item?.default)
|
|
73
|
+
|
|
74
|
+
entries.forEach(([key, entryItem]) => {
|
|
75
|
+
if (entryItem) {
|
|
76
|
+
const name = parseItem(key, { ...entryItem, type: undefined }, options)
|
|
77
|
+
if (entryItem.children) {
|
|
78
|
+
const subTypes = Object.entries(entryItem.children)
|
|
79
|
+
.map(([key]) => {
|
|
80
|
+
return key
|
|
81
|
+
})
|
|
82
|
+
.join(', ')
|
|
83
|
+
|
|
84
|
+
if (subTypes) {
|
|
85
|
+
names.push(`${name}: { ${subTypes} }`)
|
|
86
|
+
} else {
|
|
87
|
+
names.push(name)
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
if (options.type === 'call' && options.transformName) {
|
|
91
|
+
names.push(`${key}: ${name}`)
|
|
92
|
+
} else {
|
|
93
|
+
names.push(name)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (entries.some(([_key, item]) => item?.type)) {
|
|
98
|
+
types.push(parseItem(key, { ...entryItem, default: undefined }, options))
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const name = item.mode === 'inline' ? key : names.length ? `{ ${names.join(', ')} }` : undefined
|
|
104
|
+
const type = item.type ? item.type : types.length ? `{ ${types.join('; ')} }` : undefined
|
|
105
|
+
|
|
106
|
+
if (!name) {
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return parseItem(
|
|
111
|
+
name,
|
|
112
|
+
{
|
|
113
|
+
type,
|
|
114
|
+
default: item.default,
|
|
115
|
+
optional: !item.default ? optional : undefined,
|
|
116
|
+
} as ParamItem,
|
|
117
|
+
options,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function parseItem(name: string, item: ParamItem, options: Options): string {
|
|
122
|
+
const acc: string[] = []
|
|
123
|
+
const transformedName = options.transformName ? options.transformName(name) : name
|
|
124
|
+
const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type
|
|
125
|
+
|
|
126
|
+
if (options.type === 'object') {
|
|
127
|
+
return transformedName
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (options.type === 'objectValue') {
|
|
131
|
+
return item.value ? `${transformedName}: ${item.value}` : transformedName
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//LEGACY
|
|
135
|
+
if (item.type && options.type === 'constructor') {
|
|
136
|
+
if (item.optional) {
|
|
137
|
+
// Check if this is a destructured parameter (object mode)
|
|
138
|
+
const isDestructured = transformedName.startsWith('{')
|
|
139
|
+
if (isDestructured) {
|
|
140
|
+
// For destructured parameters, use ": type = {}" syntax to make it optional
|
|
141
|
+
acc.push(`${transformedName}: ${transformedType} = {}`)
|
|
142
|
+
} else {
|
|
143
|
+
// For inline parameters, use "?: type" syntax
|
|
144
|
+
acc.push(`${transformedName}?: ${transformedType}`)
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ''}`)
|
|
148
|
+
}
|
|
149
|
+
} else if (item.default && options.type === 'constructor') {
|
|
150
|
+
acc.push(`${transformedName} = ${item.default}`)
|
|
151
|
+
} else if (item.value) {
|
|
152
|
+
acc.push(`${transformedName} : ${item.value}`)
|
|
153
|
+
} else if (item.mode === 'inlineSpread') {
|
|
154
|
+
acc.push(`... ${transformedName}`)
|
|
155
|
+
} else {
|
|
156
|
+
acc.push(transformedName)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return acc[0] as string
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function getFunctionParams(params: Params, options: Options): string {
|
|
163
|
+
const entries = order(Object.entries(params as Record<string, ParamItem | undefined>))
|
|
164
|
+
|
|
165
|
+
return entries
|
|
166
|
+
.reduce((acc, [key, item]) => {
|
|
167
|
+
if (!item) {
|
|
168
|
+
return acc
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (item.children) {
|
|
172
|
+
if (Object.keys(item.children).length === 0) {
|
|
173
|
+
return acc
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (item.mode === 'inlineSpread') {
|
|
177
|
+
return [...acc, getFunctionParams(item.children, options)]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const parsedItem = parseChild(key, item, options)
|
|
181
|
+
if (!parsedItem) {
|
|
182
|
+
return acc
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return [...acc, parsedItem]
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const parsedItem = parseItem(key, item, options)
|
|
189
|
+
|
|
190
|
+
return [...acc, parsedItem]
|
|
191
|
+
}, [] as string[])
|
|
192
|
+
.join(', ')
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @deprecated use @kubb/ast
|
|
197
|
+
*/
|
|
198
|
+
export function createFunctionParams(params: Params): Params {
|
|
199
|
+
return params
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @deprecated use @kubb/ast
|
|
204
|
+
*/
|
|
205
|
+
export class FunctionParams {
|
|
206
|
+
#params: Params
|
|
207
|
+
|
|
208
|
+
static factory(params: Params) {
|
|
209
|
+
return new FunctionParams(params)
|
|
210
|
+
}
|
|
211
|
+
constructor(params: Params) {
|
|
212
|
+
this.#params = params
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
get params(): Params {
|
|
216
|
+
return this.#params
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
get flatParams(): Params {
|
|
220
|
+
const flatter = (acc: Params, [key, item]: [key: string, item?: Param]): Params => {
|
|
221
|
+
if (item?.children) {
|
|
222
|
+
return Object.entries(item.children).reduce(flatter, acc)
|
|
223
|
+
}
|
|
224
|
+
if (item) {
|
|
225
|
+
acc[key] = item
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return acc
|
|
229
|
+
}
|
|
230
|
+
return Object.entries(this.#params).reduce(flatter, {} as Params)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
toCall({ transformName, transformType }: Pick<Options, 'transformName' | 'transformType'> = {}): string {
|
|
234
|
+
return getFunctionParams(this.#params, { type: 'call', transformName, transformType })
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
toObject(): string {
|
|
238
|
+
return getFunctionParams(this.#params, { type: 'object' })
|
|
239
|
+
}
|
|
240
|
+
toObjectValue(): string {
|
|
241
|
+
return getFunctionParams(this.#params, { type: 'objectValue' })
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
toConstructor(): string {
|
|
245
|
+
return getFunctionParams(this.#params, { type: 'constructor' })
|
|
246
|
+
}
|
|
247
|
+
}
|