@kubb/react-fabric 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Fabric-DitK3IEP.d.ts → Fabric-BELBf-bX.d.cts} +5 -5
- package/dist/{Fabric-C61uYmUy.d.cts → Fabric-DbJhvsCq.d.ts} +5 -5
- package/dist/globals.d.cts +2 -2
- package/dist/globals.d.ts +2 -2
- package/dist/index.cjs +123 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -209
- package/dist/index.d.ts +59 -197
- package/dist/index.js +102 -39
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.cts +5 -5
- package/dist/jsx-dev-runtime.d.ts +3 -3
- package/dist/{jsx-namespace-BnoysbjP.d.cts → jsx-namespace-B6xgRlZE.d.cts} +2 -2
- package/dist/{jsx-namespace-D0a66_uR.d.ts → jsx-namespace-BNUcRr9S.d.ts} +2 -2
- package/dist/jsx-runtime.d.cts +5 -5
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/parsers.d.cts +1 -1
- package/dist/parsers.d.ts +1 -1
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.d.cts +3 -2
- package/dist/plugins.d.ts +3 -2
- package/dist/plugins.js +1 -1
- package/dist/{reactPlugin-4-kcMKwZ.d.ts → reactPlugin-9l7--xRt.d.ts} +7 -6
- package/dist/{reactPlugin-D4SmGYbm.cjs → reactPlugin-B8F6jVb5.cjs} +33 -13
- package/dist/reactPlugin-B8F6jVb5.cjs.map +1 -0
- package/dist/{reactPlugin-DT9toQPK.js → reactPlugin-CAtVV84d.js} +34 -14
- package/dist/reactPlugin-CAtVV84d.js.map +1 -0
- package/dist/{reactPlugin-B4xarQJX.d.cts → reactPlugin-DdQ8nZeK.d.cts} +7 -6
- package/dist/{types-BL7PkfqA.d.ts → types-QgmDVUxV.d.ts} +56 -3
- package/dist/{types-BdOHT5YF.d.cts → types-f5qVBVRo.d.cts} +56 -3
- package/dist/types.d.cts +3 -3
- package/dist/types.d.ts +3 -3
- package/package.json +2 -2
- package/src/Runtime.tsx +22 -12
- package/src/components/App.tsx +23 -7
- package/src/components/Const.tsx +17 -4
- package/src/components/File.tsx +83 -24
- package/src/components/Function.tsx +28 -7
- package/src/components/Root.tsx +23 -16
- package/src/components/Type.tsx +17 -4
- package/src/components/__snapshots__/arrow_function.ts +3 -0
- package/src/components/__snapshots__/arrow_function_default.ts +3 -0
- package/src/components/__snapshots__/arrow_function_generics.ts +3 -0
- package/src/components/__snapshots__/arrow_function_single_line.ts +1 -0
- package/src/components/__snapshots__/arrow_function_with_generics.ts +3 -0
- package/src/components/__snapshots__/async_arrow_function.ts +3 -0
- package/src/components/__snapshots__/async_function.ts +3 -0
- package/src/components/__snapshots__/async_function_with_Promise_return_type.ts +3 -0
- package/src/components/__snapshots__/basic_arrow_function.ts +3 -0
- package/src/components/__snapshots__/basic_const.ts +1 -0
- package/src/components/__snapshots__/basic_export.ts +1 -0
- package/src/components/__snapshots__/basic_function.ts +3 -0
- package/src/components/__snapshots__/basic_import.ts +1 -0
- package/src/components/__snapshots__/basic_type.ts +1 -0
- package/src/components/__snapshots__/const_with_JSDoc.ts +4 -0
- package/src/components/__snapshots__/const_with_as_const.ts +1 -0
- package/src/components/__snapshots__/const_with_type.ts +1 -0
- package/src/components/__snapshots__/default_exported_arrow_function.ts +3 -0
- package/src/components/__snapshots__/default_exported_function.ts +3 -0
- package/src/components/__snapshots__/exported_arrow_function.ts +3 -0
- package/src/components/__snapshots__/exported_const.ts +1 -0
- package/src/components/__snapshots__/exported_function.ts +3 -0
- package/src/components/__snapshots__/exported_type.ts +1 -0
- package/src/components/__snapshots__/function_generics.ts +3 -0
- package/src/components/__snapshots__/function_with_JSDoc.ts +6 -0
- package/src/components/__snapshots__/function_with_comments.ts +6 -0
- package/src/components/__snapshots__/function_with_generics.ts +3 -0
- package/src/components/__snapshots__/function_with_parameters.ts +3 -0
- package/src/components/__snapshots__/function_with_params.ts +3 -0
- package/src/components/__snapshots__/function_with_returnType.ts +3 -0
- package/src/components/__snapshots__/function_with_return_type.ts +3 -0
- package/src/components/__snapshots__/matches_with_root_import.ts +1 -0
- package/src/components/__snapshots__/multiple_functions.ts +3 -0
- package/src/components/__snapshots__/named_export.ts +1 -0
- package/src/components/__snapshots__/named_export_(object_advanced).ts +1 -0
- package/src/components/__snapshots__/named_import.ts +1 -0
- package/src/components/__snapshots__/named_import_(object).ts +1 -0
- package/src/components/__snapshots__/named_import_(object_advanced).ts +1 -0
- package/src/components/__snapshots__/named_typed_export.ts +1 -0
- package/src/components/__snapshots__/named_typed_import.ts +1 -0
- package/src/components/__snapshots__/single_line_arrow_function.ts +1 -0
- package/src/components/__snapshots__/type_with_JSDoc.ts +4 -0
- package/src/components/__snapshots__/typed_export.ts +1 -0
- package/src/components/__snapshots__/typed_import.ts +1 -0
- package/src/composables/useLifecycle.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/plugins/reactPlugin.ts +7 -6
- package/dist/reactPlugin-D4SmGYbm.cjs.map +0 -1
- package/dist/reactPlugin-DT9toQPK.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { o as Plugin } from "./Fabric-
|
|
1
|
+
import { o as Plugin } from "./Fabric-BELBf-bX.cjs";
|
|
2
|
+
import { o as KubbElement } from "./types-f5qVBVRo.cjs";
|
|
2
3
|
import { ElementType } from "react";
|
|
3
4
|
|
|
4
5
|
//#region src/plugins/reactPlugin.d.ts
|
|
@@ -12,15 +13,15 @@ type Options = {
|
|
|
12
13
|
debug?: boolean;
|
|
13
14
|
};
|
|
14
15
|
type ExtendOptions = {
|
|
15
|
-
render(App: ElementType): Promise<void>;
|
|
16
|
-
renderToString(App: ElementType): Promise<string>;
|
|
16
|
+
render(App: KubbElement | ElementType): Promise<void>;
|
|
17
|
+
renderToString(App: KubbElement | ElementType): Promise<string>;
|
|
17
18
|
waitUntilExit(): Promise<void>;
|
|
18
19
|
};
|
|
19
20
|
declare global {
|
|
20
21
|
namespace Kubb {
|
|
21
22
|
interface Fabric {
|
|
22
|
-
render(App: ElementType): Promise<void>;
|
|
23
|
-
renderToString(App: ElementType): Promise<string>;
|
|
23
|
+
render(App: KubbElement | ElementType): Promise<void>;
|
|
24
|
+
renderToString(App: KubbElement | ElementType): Promise<string>;
|
|
24
25
|
waitUntilExit(): Promise<void>;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -28,4 +29,4 @@ declare global {
|
|
|
28
29
|
declare const reactPlugin: Plugin<Options, ExtendOptions>;
|
|
29
30
|
//#endregion
|
|
30
31
|
export { reactPlugin as n, Options as t };
|
|
31
|
-
//# sourceMappingURL=reactPlugin-
|
|
32
|
+
//# sourceMappingURL=reactPlugin-DdQ8nZeK.d.cts.map
|
|
@@ -1,6 +1,59 @@
|
|
|
1
|
-
import { b as Source, g as Import, h as File, p as Export } from "./Fabric-
|
|
1
|
+
import { b as Source, c as FileManager, g as Import, h as File, p as Export } from "./Fabric-DbJhvsCq.js";
|
|
2
2
|
import React, { JSX, Key, ReactNode } from "react";
|
|
3
3
|
|
|
4
|
+
//#region ../fabric-core/src/utils/TreeNode.d.ts
|
|
5
|
+
type BarrelData = {
|
|
6
|
+
file?: File;
|
|
7
|
+
path: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
type Graph = {
|
|
11
|
+
nodes: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}>;
|
|
15
|
+
edges: Array<{
|
|
16
|
+
from: string;
|
|
17
|
+
to: string;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
declare class TreeNode<TData = unknown> {
|
|
21
|
+
#private;
|
|
22
|
+
data: TData;
|
|
23
|
+
parent?: TreeNode<TData>;
|
|
24
|
+
children: Array<TreeNode<TData>>;
|
|
25
|
+
constructor(data: TData, parent?: TreeNode<TData>);
|
|
26
|
+
addChild(data: TData): TreeNode<TData>;
|
|
27
|
+
getChildByName(name: string): TreeNode<TData> | undefined;
|
|
28
|
+
get leaves(): Array<TreeNode<TData>>;
|
|
29
|
+
forEach(callback: (node: TreeNode<TData>) => void): this;
|
|
30
|
+
findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined;
|
|
31
|
+
static toGraph(root: TreeNode<BarrelData>): Graph;
|
|
32
|
+
static fromFiles(files: Array<File>, rootFolder?: string): TreeNode<BarrelData> | null;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../fabric-core/src/composables/useNodeTree.d.ts
|
|
36
|
+
type ComponentNode = {
|
|
37
|
+
type: string;
|
|
38
|
+
props: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region ../fabric-core/src/contexts/RootContext.d.ts
|
|
42
|
+
type RootContextProps = {
|
|
43
|
+
/**
|
|
44
|
+
* Exit (unmount) the whole app.
|
|
45
|
+
*/
|
|
46
|
+
exit: (error?: Error) => void;
|
|
47
|
+
/**
|
|
48
|
+
* TreeNode representing the tree structure of the app.
|
|
49
|
+
*/
|
|
50
|
+
treeNode: TreeNode<ComponentNode>;
|
|
51
|
+
/**
|
|
52
|
+
* FileManager instance for managing files within the app.
|
|
53
|
+
*/
|
|
54
|
+
fileManager: FileManager;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
4
57
|
//#region ../fabric-core/src/types.d.ts
|
|
5
58
|
type JSDoc = {
|
|
6
59
|
comments: string[];
|
|
@@ -102,5 +155,5 @@ type KubbImportProps = Import;
|
|
|
102
155
|
type KubbExportProps = Export;
|
|
103
156
|
type LineBreakProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLBRElement>, HTMLBRElement>;
|
|
104
157
|
//#endregion
|
|
105
|
-
export { Params as _, Key as a, KubbFileProps as c, KubbSourceProps as d, KubbTextProps as f, Param as g, FunctionParams as h, ElementNames as i, KubbImportProps as l, TextNode as m, DOMNode as n, KubbElement as o, LineBreakProps as p, DOMNodeAttribute as r, KubbExportProps as s, DOMElement as t, KubbNode as u, createFunctionParams as v, JSDoc as y };
|
|
106
|
-
//# sourceMappingURL=types-
|
|
158
|
+
export { Params as _, Key as a, RootContextProps as b, KubbFileProps as c, KubbSourceProps as d, KubbTextProps as f, Param as g, FunctionParams as h, ElementNames as i, KubbImportProps as l, TextNode as m, DOMNode as n, KubbElement as o, LineBreakProps as p, DOMNodeAttribute as r, KubbExportProps as s, DOMElement as t, KubbNode as u, createFunctionParams as v, ComponentNode as x, JSDoc as y };
|
|
159
|
+
//# sourceMappingURL=types-QgmDVUxV.d.ts.map
|
|
@@ -1,6 +1,59 @@
|
|
|
1
|
-
import { b as Source, g as Import, h as File, p as Export } from "./Fabric-
|
|
1
|
+
import { b as Source, c as FileManager, g as Import, h as File, p as Export } from "./Fabric-BELBf-bX.cjs";
|
|
2
2
|
import React, { JSX, Key, ReactNode } from "react";
|
|
3
3
|
|
|
4
|
+
//#region ../fabric-core/src/utils/TreeNode.d.ts
|
|
5
|
+
type BarrelData = {
|
|
6
|
+
file?: File;
|
|
7
|
+
path: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
type Graph = {
|
|
11
|
+
nodes: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}>;
|
|
15
|
+
edges: Array<{
|
|
16
|
+
from: string;
|
|
17
|
+
to: string;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
declare class TreeNode<TData = unknown> {
|
|
21
|
+
#private;
|
|
22
|
+
data: TData;
|
|
23
|
+
parent?: TreeNode<TData>;
|
|
24
|
+
children: Array<TreeNode<TData>>;
|
|
25
|
+
constructor(data: TData, parent?: TreeNode<TData>);
|
|
26
|
+
addChild(data: TData): TreeNode<TData>;
|
|
27
|
+
getChildByName(name: string): TreeNode<TData> | undefined;
|
|
28
|
+
get leaves(): Array<TreeNode<TData>>;
|
|
29
|
+
forEach(callback: (node: TreeNode<TData>) => void): this;
|
|
30
|
+
findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined;
|
|
31
|
+
static toGraph(root: TreeNode<BarrelData>): Graph;
|
|
32
|
+
static fromFiles(files: Array<File>, rootFolder?: string): TreeNode<BarrelData> | null;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../fabric-core/src/composables/useNodeTree.d.ts
|
|
36
|
+
type ComponentNode = {
|
|
37
|
+
type: string;
|
|
38
|
+
props: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region ../fabric-core/src/contexts/RootContext.d.ts
|
|
42
|
+
type RootContextProps = {
|
|
43
|
+
/**
|
|
44
|
+
* Exit (unmount) the whole app.
|
|
45
|
+
*/
|
|
46
|
+
exit: (error?: Error) => void;
|
|
47
|
+
/**
|
|
48
|
+
* TreeNode representing the tree structure of the app.
|
|
49
|
+
*/
|
|
50
|
+
treeNode: TreeNode<ComponentNode>;
|
|
51
|
+
/**
|
|
52
|
+
* FileManager instance for managing files within the app.
|
|
53
|
+
*/
|
|
54
|
+
fileManager: FileManager;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
4
57
|
//#region ../fabric-core/src/types.d.ts
|
|
5
58
|
type JSDoc = {
|
|
6
59
|
comments: string[];
|
|
@@ -102,5 +155,5 @@ type KubbImportProps = Import;
|
|
|
102
155
|
type KubbExportProps = Export;
|
|
103
156
|
type LineBreakProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLBRElement>, HTMLBRElement>;
|
|
104
157
|
//#endregion
|
|
105
|
-
export { Params as _, Key as a, KubbFileProps as c, KubbSourceProps as d, KubbTextProps as f, Param as g, FunctionParams as h, ElementNames as i, KubbImportProps as l, TextNode as m, DOMNode as n, KubbElement as o, LineBreakProps as p, DOMNodeAttribute as r, KubbExportProps as s, DOMElement as t, KubbNode as u, createFunctionParams as v, JSDoc as y };
|
|
106
|
-
//# sourceMappingURL=types-
|
|
158
|
+
export { Params as _, Key as a, RootContextProps as b, KubbFileProps as c, KubbSourceProps as d, KubbTextProps as f, Param as g, FunctionParams as h, ElementNames as i, KubbImportProps as l, TextNode as m, DOMNode as n, KubbElement as o, LineBreakProps as p, DOMNodeAttribute as r, KubbExportProps as s, DOMElement as t, KubbNode as u, createFunctionParams as v, ComponentNode as x, JSDoc as y };
|
|
159
|
+
//# sourceMappingURL=types-f5qVBVRo.d.cts.map
|
package/dist/types.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { _ as KubbFile_d_exports, a as FabricOptions, i as FabricMode, n as FabricConfig, r as FabricContext } from "./Fabric-
|
|
2
|
-
import { _ as Params, a as Key, c as KubbFileProps, d as KubbSourceProps, f as KubbTextProps, g as Param, i as ElementNames, l as KubbImportProps, m as TextNode, n as DOMNode, o as KubbElement, p as LineBreakProps, r as DOMNodeAttribute, s as KubbExportProps, t as DOMElement, u as KubbNode, y as JSDoc } from "./types-
|
|
3
|
-
export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricConfig, FabricContext, FabricMode, FabricOptions, JSDoc, Key, KubbElement, KubbExportProps, KubbFile_d_exports as KubbFile, KubbFileProps, KubbImportProps, KubbNode, KubbSourceProps, KubbTextProps, LineBreakProps, Param, Params, TextNode };
|
|
1
|
+
import { _ as KubbFile_d_exports, a as FabricOptions, i as FabricMode, n as FabricConfig, r as FabricContext } from "./Fabric-BELBf-bX.cjs";
|
|
2
|
+
import { _ as Params, a as Key, b as RootContextProps, c as KubbFileProps, d as KubbSourceProps, f as KubbTextProps, g as Param, i as ElementNames, l as KubbImportProps, m as TextNode, n as DOMNode, o as KubbElement, p as LineBreakProps, r as DOMNodeAttribute, s as KubbExportProps, t as DOMElement, u as KubbNode, x as ComponentNode, y as JSDoc } from "./types-f5qVBVRo.cjs";
|
|
3
|
+
export { ComponentNode, DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricConfig, FabricContext, FabricMode, FabricOptions, JSDoc, Key, KubbElement, KubbExportProps, KubbFile_d_exports as KubbFile, KubbFileProps, KubbImportProps, KubbNode, KubbSourceProps, KubbTextProps, LineBreakProps, Param, Params, RootContextProps, TextNode };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { _ as KubbFile_d_exports, a as FabricOptions, i as FabricMode, n as FabricConfig, r as FabricContext } from "./Fabric-
|
|
2
|
-
import { _ as Params, a as Key, c as KubbFileProps, d as KubbSourceProps, f as KubbTextProps, g as Param, i as ElementNames, l as KubbImportProps, m as TextNode, n as DOMNode, o as KubbElement, p as LineBreakProps, r as DOMNodeAttribute, s as KubbExportProps, t as DOMElement, u as KubbNode, y as JSDoc } from "./types-
|
|
3
|
-
export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricConfig, FabricContext, FabricMode, FabricOptions, JSDoc, Key, KubbElement, KubbExportProps, KubbFile_d_exports as KubbFile, KubbFileProps, KubbImportProps, KubbNode, KubbSourceProps, KubbTextProps, LineBreakProps, Param, Params, TextNode };
|
|
1
|
+
import { _ as KubbFile_d_exports, a as FabricOptions, i as FabricMode, n as FabricConfig, r as FabricContext } from "./Fabric-DbJhvsCq.js";
|
|
2
|
+
import { _ as Params, a as Key, b as RootContextProps, c as KubbFileProps, d as KubbSourceProps, f as KubbTextProps, g as Param, i as ElementNames, l as KubbImportProps, m as TextNode, n as DOMNode, o as KubbElement, p as LineBreakProps, r as DOMNodeAttribute, s as KubbExportProps, t as DOMElement, u as KubbNode, x as ComponentNode, y as JSDoc } from "./types-QgmDVUxV.js";
|
|
3
|
+
export { ComponentNode, DOMElement, DOMNode, DOMNodeAttribute, ElementNames, FabricConfig, FabricContext, FabricMode, FabricOptions, JSDoc, Key, KubbElement, KubbExportProps, KubbFile_d_exports as KubbFile, KubbFileProps, KubbImportProps, KubbNode, KubbSourceProps, KubbTextProps, LineBreakProps, Param, Params, RootContextProps, TextNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/react-fabric",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "React integration for Kubb, providing JSX runtime support and React component generation capabilities for code generation plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"react-devtools-core": "6.1.2",
|
|
112
112
|
"signal-exit": "^4.1.0",
|
|
113
113
|
"ws": "8.18.0",
|
|
114
|
-
"@kubb/fabric-core": "0.
|
|
114
|
+
"@kubb/fabric-core": "0.11.1"
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@types/react": "^19.2.8",
|
package/src/Runtime.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
|
-
import type
|
|
2
|
+
import { type FileManager, TreeNode } from '@kubb/fabric-core'
|
|
3
3
|
import type { ReactNode } from 'react'
|
|
4
4
|
import { ConcurrentRoot } from 'react-reconciler/constants.js'
|
|
5
5
|
import { onExit } from 'signal-exit'
|
|
@@ -7,7 +7,7 @@ import { Root } from './components/Root.tsx'
|
|
|
7
7
|
import { createNode } from './dom.ts'
|
|
8
8
|
import type { FiberRoot } from './Renderer.ts'
|
|
9
9
|
import { Renderer } from './Renderer.ts'
|
|
10
|
-
import type { DOMElement } from './types.ts'
|
|
10
|
+
import type { ComponentNode, DOMElement } from './types.ts'
|
|
11
11
|
import { processFiles } from './utils/processFiles.ts'
|
|
12
12
|
import { squashTextNodes } from './utils/squashTextNodes.ts'
|
|
13
13
|
|
|
@@ -167,11 +167,16 @@ export class Runtime {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
async render(node: ReactNode): Promise<void> {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
const treeNode = new TreeNode<ComponentNode>({ type: 'Root', props: {} })
|
|
171
|
+
const props = {
|
|
172
|
+
fileManager: this.fileManager,
|
|
173
|
+
treeNode,
|
|
174
|
+
onExit: this.onExit.bind(this),
|
|
175
|
+
onError: this.onError.bind(this),
|
|
176
|
+
}
|
|
177
|
+
treeNode.data.props = props
|
|
178
|
+
|
|
179
|
+
const element = <Root {...props}>{node}</Root>
|
|
175
180
|
|
|
176
181
|
Renderer.updateContainerSync(element, this.#container, null, null)
|
|
177
182
|
Renderer.flushSyncWork()
|
|
@@ -186,11 +191,16 @@ export class Runtime {
|
|
|
186
191
|
}
|
|
187
192
|
|
|
188
193
|
async renderToString(node: ReactNode): Promise<string> {
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
const treeNode = new TreeNode<ComponentNode>({ type: 'Root', props: {} })
|
|
195
|
+
const props = {
|
|
196
|
+
fileManager: this.fileManager,
|
|
197
|
+
treeNode,
|
|
198
|
+
onExit: this.onExit.bind(this),
|
|
199
|
+
onError: this.onError.bind(this),
|
|
200
|
+
}
|
|
201
|
+
treeNode.data.props = props
|
|
202
|
+
|
|
203
|
+
const element = <Root {...props}>{node}</Root>
|
|
194
204
|
|
|
195
205
|
Renderer.updateContainerSync(element, this.#container, null, null)
|
|
196
206
|
Renderer.flushSyncWork()
|
package/src/components/App.tsx
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
import { AppContext, provide, RootContext, useContext } from '@kubb/fabric-core'
|
|
1
|
+
import { AppContext, NodeTreeContext, provide, RootContext, useContext, useNodeTree } from '@kubb/fabric-core'
|
|
2
2
|
import type { KubbNode } from '../types.ts'
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type AppProps<TMeta extends object = object> = {
|
|
5
|
+
/**
|
|
6
|
+
* Metadata associated with the App.
|
|
7
|
+
*/
|
|
8
|
+
meta?: TMeta
|
|
9
|
+
/**
|
|
10
|
+
* Children nodes.
|
|
11
|
+
*/
|
|
12
|
+
children?: KubbNode
|
|
7
13
|
}
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
11
|
-
* This component mirrors the Fabric app container in React.
|
|
16
|
+
* App container containing the AppContext carrying `meta` and an `exit` hook.
|
|
12
17
|
*/
|
|
13
|
-
export function App<TMeta =
|
|
18
|
+
export function App<TMeta extends object = object>({ children, ...props }: AppProps<TMeta>) {
|
|
19
|
+
const { meta = {} } = props
|
|
20
|
+
|
|
14
21
|
const { exit } = useContext(RootContext)
|
|
22
|
+
|
|
23
|
+
const nodeTree = useNodeTree()
|
|
24
|
+
|
|
25
|
+
if (nodeTree) {
|
|
26
|
+
const childTree = nodeTree.addChild({ type: 'App', props })
|
|
27
|
+
|
|
28
|
+
provide(NodeTreeContext, childTree)
|
|
29
|
+
}
|
|
30
|
+
|
|
15
31
|
provide(AppContext, { exit, meta })
|
|
16
32
|
|
|
17
33
|
return children
|
package/src/components/Const.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'
|
|
1
2
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
|
-
|
|
3
3
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
export type ConstProps = {
|
|
6
6
|
key?: Key
|
|
7
7
|
/**
|
|
8
8
|
* Name of the const
|
|
@@ -24,13 +24,26 @@ type Props = {
|
|
|
24
24
|
* Use of `const` assertions
|
|
25
25
|
*/
|
|
26
26
|
asConst?: boolean
|
|
27
|
+
/**
|
|
28
|
+
* Children nodes.
|
|
29
|
+
*/
|
|
27
30
|
children?: KubbNode
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
34
|
+
* Generates a TypeScript constant declaration.
|
|
32
35
|
*/
|
|
33
|
-
export function Const({
|
|
36
|
+
export function Const({ children, ...props }: ConstProps) {
|
|
37
|
+
const { name, export: canExport, type, JSDoc, asConst } = props
|
|
38
|
+
|
|
39
|
+
const nodeTree = useNodeTree()
|
|
40
|
+
|
|
41
|
+
if (nodeTree) {
|
|
42
|
+
const childTree = nodeTree.addChild({ type: 'Const', props })
|
|
43
|
+
|
|
44
|
+
provide(NodeTreeContext, childTree)
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
return (
|
|
35
48
|
<>
|
|
36
49
|
{JSDoc?.comments && (
|
package/src/components/File.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FileContext, NodeTreeContext, provide, useFile, useFileManager, useNodeTree } from '@kubb/fabric-core'
|
|
2
2
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
3
|
import type { Key, KubbNode } from '../types.ts'
|
|
4
4
|
|
|
@@ -34,31 +34,39 @@ type Props<TMeta> = BaseProps & {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* for children. When `baseName` and `path` are provided the file will be
|
|
39
|
-
* registered so it can be emitted by the collector later.
|
|
37
|
+
* Adds files to the FileManager
|
|
40
38
|
*/
|
|
41
|
-
export function File<TMeta extends object = object>({ children, ...
|
|
42
|
-
const
|
|
43
|
-
provide(FileCollectorContext, collector)
|
|
39
|
+
export function File<TMeta extends object = object>({ children, ...props }: Props<TMeta>) {
|
|
40
|
+
const { baseName, path, meta = {}, footer, banner } = props
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
const fileManager = useFileManager()
|
|
43
|
+
const nodeTree = useNodeTree()
|
|
44
|
+
|
|
45
|
+
if (nodeTree) {
|
|
46
|
+
const childTree = nodeTree.addChild({ type: 'File', props })
|
|
47
|
+
|
|
48
|
+
provide(NodeTreeContext, childTree)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!baseName || !path) {
|
|
46
52
|
return <>{children}</>
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
footer: rest.footer,
|
|
55
|
+
const file: KubbFile.File = {
|
|
56
|
+
baseName,
|
|
57
|
+
path,
|
|
58
|
+
meta,
|
|
59
|
+
banner,
|
|
60
|
+
footer,
|
|
56
61
|
sources: [],
|
|
57
62
|
imports: [],
|
|
58
63
|
exports: [],
|
|
59
|
-
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const [resolvedFile] = fileManager.add(file)
|
|
67
|
+
provide(FileContext, resolvedFile)
|
|
60
68
|
|
|
61
|
-
return <kubb-file {...
|
|
69
|
+
return <kubb-file {...props}>{children}</kubb-file>
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
File.displayName = 'KubbFile'
|
|
@@ -74,7 +82,17 @@ type FileSourceProps = Omit<KubbFile.Source, 'value'> & {
|
|
|
74
82
|
* Marks a block of source text to be associated with the current file when
|
|
75
83
|
* rendering with the FileCollector. Children are treated as the source string.
|
|
76
84
|
*/
|
|
77
|
-
function FileSource({
|
|
85
|
+
function FileSource({ children, ...props }: FileSourceProps) {
|
|
86
|
+
const { name, isExportable, isIndexable, isTypeOnly } = props
|
|
87
|
+
|
|
88
|
+
const nodeTree = useNodeTree()
|
|
89
|
+
|
|
90
|
+
if (nodeTree) {
|
|
91
|
+
const childTree = nodeTree.addChild({ type: 'FileSource', props })
|
|
92
|
+
|
|
93
|
+
provide(NodeTreeContext, childTree)
|
|
94
|
+
}
|
|
95
|
+
|
|
78
96
|
return (
|
|
79
97
|
<kubb-source name={name} isTypeOnly={isTypeOnly} isExportable={isExportable} isIndexable={isIndexable}>
|
|
80
98
|
{children}
|
|
@@ -84,7 +102,7 @@ function FileSource({ isTypeOnly, name, isExportable, isIndexable, children }: F
|
|
|
84
102
|
|
|
85
103
|
FileSource.displayName = 'KubbFileSource'
|
|
86
104
|
|
|
87
|
-
type FileExportProps = KubbFile.Export & { key?: Key }
|
|
105
|
+
export type FileExportProps = KubbFile.Export & { key?: Key }
|
|
88
106
|
|
|
89
107
|
/**
|
|
90
108
|
* File.Export
|
|
@@ -92,21 +110,62 @@ type FileExportProps = KubbFile.Export & { key?: Key }
|
|
|
92
110
|
* Declares an export entry for the current file. This will be collected by
|
|
93
111
|
* the FileCollector for later emission.
|
|
94
112
|
*/
|
|
95
|
-
function FileExport(
|
|
96
|
-
|
|
113
|
+
function FileExport(props: FileExportProps) {
|
|
114
|
+
const { name, path, isTypeOnly, asAlias } = props
|
|
115
|
+
|
|
116
|
+
const nodeTree = useNodeTree()
|
|
117
|
+
const file = useFile()
|
|
118
|
+
|
|
119
|
+
if (nodeTree) {
|
|
120
|
+
const childTree = nodeTree.addChild({ type: 'FileExport', props })
|
|
121
|
+
|
|
122
|
+
provide(NodeTreeContext, childTree)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (file) {
|
|
126
|
+
file.exports.push({
|
|
127
|
+
name,
|
|
128
|
+
path,
|
|
129
|
+
asAlias,
|
|
130
|
+
isTypeOnly,
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return <kubb-export name={name} path={path} isTypeOnly={isTypeOnly} asAlias={asAlias} />
|
|
97
135
|
}
|
|
98
136
|
|
|
99
137
|
FileExport.displayName = 'KubbFileExport'
|
|
100
138
|
|
|
101
|
-
type FileImportProps = KubbFile.Import & { key?: Key }
|
|
139
|
+
export type FileImportProps = KubbFile.Import & { key?: Key }
|
|
102
140
|
|
|
103
141
|
/**
|
|
104
142
|
* File.Import
|
|
105
143
|
*
|
|
106
144
|
* Declares an import entry for the current file.
|
|
107
145
|
*/
|
|
108
|
-
function FileImport(
|
|
109
|
-
|
|
146
|
+
function FileImport(props: FileImportProps) {
|
|
147
|
+
const { name, root, path, isTypeOnly, isNameSpace } = props
|
|
148
|
+
|
|
149
|
+
const nodeTree = useNodeTree()
|
|
150
|
+
const file = useFile()
|
|
151
|
+
|
|
152
|
+
if (nodeTree) {
|
|
153
|
+
const childTree = nodeTree.addChild({ type: 'FileImport', props })
|
|
154
|
+
|
|
155
|
+
provide(NodeTreeContext, childTree)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (file) {
|
|
159
|
+
file.imports.push({
|
|
160
|
+
name,
|
|
161
|
+
path,
|
|
162
|
+
root,
|
|
163
|
+
isNameSpace,
|
|
164
|
+
isTypeOnly,
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return <kubb-import name={name} root={root} path={path} isNameSpace={isNameSpace} isTypeOnly={isTypeOnly} />
|
|
110
169
|
}
|
|
111
170
|
|
|
112
171
|
FileImport.displayName = 'KubbFileImport'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'
|
|
2
|
+
import type { JSDoc, Key } from '../types.ts'
|
|
2
3
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
3
4
|
import { Indent } from './Indent.tsx'
|
|
4
5
|
|
|
@@ -29,7 +30,6 @@ type Props = {
|
|
|
29
30
|
* Generics that needs to be added for TypeScript.
|
|
30
31
|
*/
|
|
31
32
|
generics?: string | string[]
|
|
32
|
-
|
|
33
33
|
/**
|
|
34
34
|
* ReturnType(see async for adding Promise type).
|
|
35
35
|
*/
|
|
@@ -38,14 +38,26 @@ type Props = {
|
|
|
38
38
|
* Options for JSdocs.
|
|
39
39
|
*/
|
|
40
40
|
JSDoc?: JSDoc
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Children nodes.
|
|
43
|
+
*/
|
|
44
|
+
children?: string
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
/**
|
|
45
|
-
*
|
|
46
|
-
* Supports optional export/default/async flags, generics, params and JSDoc.
|
|
48
|
+
* Generates a TypeScript function declaration.
|
|
47
49
|
*/
|
|
48
|
-
export function Function({
|
|
50
|
+
export function Function({ children, ...props }: Props) {
|
|
51
|
+
const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props
|
|
52
|
+
|
|
53
|
+
const nodeTree = useNodeTree()
|
|
54
|
+
|
|
55
|
+
if (nodeTree) {
|
|
56
|
+
const childTree = nodeTree.addChild({ type: 'Function', props })
|
|
57
|
+
|
|
58
|
+
provide(NodeTreeContext, childTree)
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
return (
|
|
50
62
|
<>
|
|
51
63
|
{JSDoc?.comments && (
|
|
@@ -97,7 +109,16 @@ type ArrowFunctionProps = Props & {
|
|
|
97
109
|
* Renders an arrow function definition. Supports the same flags as `Function`.
|
|
98
110
|
* Use `singleLine` to render the body as a single-line expression.
|
|
99
111
|
*/
|
|
100
|
-
function ArrowFunction({
|
|
112
|
+
function ArrowFunction({ children, ...props }: ArrowFunctionProps) {
|
|
113
|
+
const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props
|
|
114
|
+
|
|
115
|
+
const nodeTree = useNodeTree()
|
|
116
|
+
|
|
117
|
+
if (nodeTree) {
|
|
118
|
+
const childTree = nodeTree.addChild({ type: 'ArrowFunction', props })
|
|
119
|
+
|
|
120
|
+
provide(NodeTreeContext, childTree)
|
|
121
|
+
}
|
|
101
122
|
return (
|
|
102
123
|
<>
|
|
103
124
|
{JSDoc?.comments && (
|
package/src/components/Root.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { provide, RootContext } from '@kubb/fabric-core'
|
|
1
|
+
import { type FileManager, NodeTreeContext, provide, RootContext, type TreeNode } from '@kubb/fabric-core'
|
|
2
2
|
import { Component } from 'react'
|
|
3
3
|
|
|
4
|
-
import type { KubbNode } from '../types.ts'
|
|
4
|
+
import type { ComponentNode, KubbNode } from '../types.ts'
|
|
5
5
|
|
|
6
6
|
type ErrorBoundaryProps = {
|
|
7
7
|
onError: (error: Error) => void
|
|
@@ -33,28 +33,35 @@ class ErrorBoundary extends Component<{
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
type RootProps = {
|
|
36
|
+
export type RootProps = {
|
|
37
37
|
/**
|
|
38
|
-
* Exit (unmount)
|
|
38
|
+
* Exit (unmount) the whole app.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
onExit: (error?: Error) => void
|
|
41
41
|
/**
|
|
42
|
-
* Error hook
|
|
42
|
+
* Error hook receiving runtime exceptions.
|
|
43
43
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
onError: (error: Error) => void
|
|
45
|
+
/**
|
|
46
|
+
* TreeNode representing the tree structure of the app.
|
|
47
|
+
*/
|
|
48
|
+
treeNode: TreeNode<ComponentNode>
|
|
49
|
+
/**
|
|
50
|
+
* FileManager instance for managing files within the app.
|
|
51
|
+
*/
|
|
52
|
+
fileManager: FileManager
|
|
53
|
+
/**
|
|
54
|
+
* Children nodes.
|
|
55
|
+
*/
|
|
56
|
+
children?: KubbNode
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
/**
|
|
49
|
-
*
|
|
50
|
-
* ErrorBoundary so errors can be forwarded to the `onError` handler.
|
|
51
|
-
*
|
|
52
|
-
* This component provides the root behaviour for the React Fabric runtime.
|
|
53
|
-
*
|
|
54
|
-
* Returns a React node tree representing the root of the Fabric app.
|
|
60
|
+
* This component provides the root behavior for the Fabric runtime.
|
|
55
61
|
*/
|
|
56
|
-
export function Root({ onError, onExit, children }: RootProps) {
|
|
57
|
-
provide(RootContext, { exit: onExit })
|
|
62
|
+
export function Root({ onError, onExit, treeNode, fileManager, children }: RootProps) {
|
|
63
|
+
provide(RootContext, { exit: onExit, treeNode, fileManager })
|
|
64
|
+
provide(NodeTreeContext, treeNode)
|
|
58
65
|
|
|
59
66
|
return (
|
|
60
67
|
<ErrorBoundary
|
package/src/components/Type.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { NodeTreeContext, provide, useNodeTree } from '@kubb/fabric-core'
|
|
1
2
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
3
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
3
4
|
|
|
4
|
-
type
|
|
5
|
+
export type TypeProps = {
|
|
5
6
|
key?: Key
|
|
6
7
|
/**
|
|
7
8
|
* Name of the type, this needs to start with a capital letter.
|
|
@@ -15,14 +16,26 @@ type Props = {
|
|
|
15
16
|
* Options for JSdocs.
|
|
16
17
|
*/
|
|
17
18
|
JSDoc?: JSDoc
|
|
19
|
+
/**
|
|
20
|
+
* Children nodes.
|
|
21
|
+
*/
|
|
18
22
|
children?: KubbNode
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
23
|
-
* with a capital letter and optionally emits JSDoc comments.
|
|
26
|
+
* Generates a TypeScript type declaration.
|
|
24
27
|
*/
|
|
25
|
-
export function Type({
|
|
28
|
+
export function Type({ children, ...props }: TypeProps) {
|
|
29
|
+
const { name, export: canExport, JSDoc } = props
|
|
30
|
+
|
|
31
|
+
const nodeTree = useNodeTree()
|
|
32
|
+
|
|
33
|
+
if (nodeTree) {
|
|
34
|
+
const childTree = nodeTree.addChild({ type: 'Type', props })
|
|
35
|
+
|
|
36
|
+
provide(NodeTreeContext, childTree)
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
if (name.charAt(0).toUpperCase() !== name.charAt(0)) {
|
|
27
40
|
throw new Error('Name should start with a capital letter(see TypeScript types)')
|
|
28
41
|
}
|