@kubb/react-fabric 0.9.5 → 0.11.0
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/{devtools-D6dZodXp.js → devtools-8_UKWDTl.js} +1 -1
- package/dist/{devtools-D6dZodXp.js.map → devtools-8_UKWDTl.js.map} +1 -1
- package/dist/{devtools-CRkwwngz.cjs → devtools-BOpUJhc_.cjs} +1 -1
- package/dist/{devtools-CRkwwngz.cjs.map → devtools-BOpUJhc_.cjs.map} +1 -1
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.js +1 -1
- package/dist/globals.d.cts +2 -2
- package/dist/globals.d.ts +2 -2
- package/dist/index.cjs +166 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -359
- package/dist/index.d.ts +3 -359
- package/dist/index.js +151 -68
- 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-BAkGpU6g.d.ts → jsx-namespace-CBOEkCmJ.d.ts} +2 -2
- package/dist/{jsx-namespace-CCPa1Nut.d.cts → jsx-namespace-od7sqrmY.d.cts} +2 -2
- package/dist/{jsx-runtime-BEVcoJUm.cjs → jsx-runtime-Cq39dA50.cjs} +1 -1
- package/dist/{jsx-runtime-BEVcoJUm.cjs.map → jsx-runtime-Cq39dA50.cjs.map} +1 -1
- package/dist/{jsx-runtime-DDu0mFTI.js → jsx-runtime-Isgf9orn.js} +1 -1
- package/dist/{jsx-runtime-DDu0mFTI.js.map → jsx-runtime-Isgf9orn.js.map} +1 -1
- package/dist/jsx-runtime.cjs +1 -1
- package/dist/jsx-runtime.d.cts +5 -5
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +1 -1
- package/dist/parsers.d.cts +1 -1
- package/dist/parsers.d.ts +1 -1
- package/dist/plugins.cjs +2 -2
- package/dist/plugins.d.cts +2 -2
- package/dist/plugins.d.ts +2 -2
- package/dist/plugins.js +2 -2
- package/dist/{reactPlugin-CXaAO13f.cjs → reactPlugin-B8F6jVb5.cjs} +77 -64
- package/dist/reactPlugin-B8F6jVb5.cjs.map +1 -0
- package/dist/{reactPlugin-ixOr00MK.js → reactPlugin-CAtVV84d.js} +78 -53
- package/dist/reactPlugin-CAtVV84d.js.map +1 -0
- package/dist/types-C3ODUOKN.d.cts +675 -0
- package/dist/types-DwaohVJS.d.ts +675 -0
- package/dist/types.d.cts +3 -3
- package/dist/types.d.ts +3 -3
- package/package.json +3 -3
- package/src/Runtime.tsx +22 -12
- package/src/components/App.tsx +24 -15
- package/src/components/Const.tsx +19 -3
- package/src/components/File.tsx +107 -31
- package/src/components/Function.tsx +36 -5
- package/src/components/Indent.tsx +3 -0
- package/src/components/Root.tsx +26 -20
- package/src/components/Type.tsx +19 -2
- 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/useApp.ts +1 -15
- package/src/composables/useFile.ts +1 -12
- package/src/composables/useLifecycle.tsx +7 -8
- package/src/index.ts +5 -1
- package/src/plugins/reactPlugin.ts +7 -6
- package/src/types.ts +0 -4
- package/src/utils/createJSDoc.ts +1 -8
- package/dist/reactPlugin-4-kcMKwZ.d.ts +0 -31
- package/dist/reactPlugin-B4xarQJX.d.cts +0 -31
- package/dist/reactPlugin-CXaAO13f.cjs.map +0 -1
- package/dist/reactPlugin-ixOr00MK.js.map +0 -1
- package/dist/types-CSUzVTpn.d.ts +0 -104
- package/dist/types-DP2mgqeb.d.cts +0 -104
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/react-fabric",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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,10 +111,10 @@
|
|
|
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.0"
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
|
-
"@types/react": "^19.2.
|
|
117
|
+
"@types/react": "^19.2.8",
|
|
118
118
|
"@types/react-reconciler": "0.32.0",
|
|
119
119
|
"@types/ws": "^8.18.1",
|
|
120
120
|
"react": "19.2.1",
|
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,27 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppContext, NodeTreeContext, provide, RootContext, useContext, useNodeTree } from '@kubb/fabric-core'
|
|
2
2
|
import type { KubbNode } from '../types.ts'
|
|
3
|
-
import { RootContext } from './Root.tsx'
|
|
4
3
|
|
|
5
|
-
export type
|
|
4
|
+
export type AppProps<TMeta extends object = object> = {
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
6
|
+
* Metadata associated with the App.
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
meta?: TMeta
|
|
9
|
+
/**
|
|
10
|
+
* Children nodes.
|
|
11
|
+
*/
|
|
12
|
+
children?: KubbNode
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
15
|
+
/**
|
|
16
|
+
* App container containing the AppContext carrying `meta` and an `exit` hook.
|
|
17
|
+
*/
|
|
18
|
+
export function App<TMeta extends object = object>({ children, ...props }: AppProps<TMeta>) {
|
|
19
|
+
const { meta = {} } = props
|
|
19
20
|
|
|
20
|
-
export function App<TMeta = unknown>({ meta, children }: Props<TMeta>) {
|
|
21
21
|
const { exit } = useContext(RootContext)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const nodeTree = useNodeTree()
|
|
24
|
+
|
|
25
|
+
if (nodeTree) {
|
|
26
|
+
const childTree = nodeTree.addChild({ type: 'App', props })
|
|
27
|
+
|
|
28
|
+
provide(NodeTreeContext, childTree)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
provide(AppContext, { exit, meta })
|
|
32
|
+
|
|
33
|
+
return children
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
App.Context = AppContext
|
|
27
36
|
App.displayName = 'KubbApp'
|
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,10 +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
|
+
/**
|
|
34
|
+
* Generates a TypeScript constant declaration.
|
|
35
|
+
*/
|
|
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
|
+
|
|
31
47
|
return (
|
|
32
48
|
<>
|
|
33
49
|
{JSDoc?.comments && (
|
package/src/components/File.tsx
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
+
import { FileContext, NodeTreeContext, provide, useFile, useFileManager, useNodeTree } from '@kubb/fabric-core'
|
|
1
2
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
2
|
-
import { createContext } from 'react'
|
|
3
3
|
import type { Key, KubbNode } from '../types.ts'
|
|
4
4
|
|
|
5
|
-
export type FileContextProps<TMeta extends object = object> = {
|
|
6
|
-
/**
|
|
7
|
-
* Name to be used to dynamicly create the baseName(based on input.path).
|
|
8
|
-
* Based on UNIX basename
|
|
9
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
10
|
-
*/
|
|
11
|
-
baseName: KubbFile.BaseName
|
|
12
|
-
/**
|
|
13
|
-
* Path will be full qualified path to a specified file.
|
|
14
|
-
*/
|
|
15
|
-
path: KubbFile.Path
|
|
16
|
-
meta?: TMeta
|
|
17
|
-
}
|
|
18
|
-
const FileContext = createContext<FileContextProps>({} as FileContextProps)
|
|
19
|
-
|
|
20
5
|
type BasePropsWithBaseName = {
|
|
21
6
|
/**
|
|
22
7
|
* Name to be used to dynamicly create the baseName(based on input.path).
|
|
@@ -48,16 +33,40 @@ type Props<TMeta> = BaseProps & {
|
|
|
48
33
|
children?: KubbNode
|
|
49
34
|
}
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Adds files to the FileManager
|
|
38
|
+
*/
|
|
39
|
+
export function File<TMeta extends object = object>({ children, ...props }: Props<TMeta>) {
|
|
40
|
+
const { baseName, path, meta = {}, footer, banner } = props
|
|
41
|
+
|
|
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) {
|
|
53
52
|
return <>{children}</>
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const file: KubbFile.File = {
|
|
56
|
+
baseName,
|
|
57
|
+
path,
|
|
58
|
+
meta,
|
|
59
|
+
banner,
|
|
60
|
+
footer,
|
|
61
|
+
sources: [],
|
|
62
|
+
imports: [],
|
|
63
|
+
exports: [],
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const [resolvedFile] = fileManager.add(file)
|
|
67
|
+
provide(FileContext, resolvedFile)
|
|
68
|
+
|
|
69
|
+
return <kubb-file {...props}>{children}</kubb-file>
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
File.displayName = 'KubbFile'
|
|
@@ -67,7 +76,23 @@ type FileSourceProps = Omit<KubbFile.Source, 'value'> & {
|
|
|
67
76
|
children?: KubbNode
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
|
|
79
|
+
/**
|
|
80
|
+
* File.Source
|
|
81
|
+
*
|
|
82
|
+
* Marks a block of source text to be associated with the current file when
|
|
83
|
+
* rendering with the FileCollector. Children are treated as the source string.
|
|
84
|
+
*/
|
|
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
|
+
|
|
71
96
|
return (
|
|
72
97
|
<kubb-source name={name} isTypeOnly={isTypeOnly} isExportable={isExportable} isIndexable={isIndexable}>
|
|
73
98
|
{children}
|
|
@@ -77,18 +102,70 @@ function FileSource({ isTypeOnly, name, isExportable, isIndexable, children }: F
|
|
|
77
102
|
|
|
78
103
|
FileSource.displayName = 'KubbFileSource'
|
|
79
104
|
|
|
80
|
-
type FileExportProps = KubbFile.Export & { key?: Key }
|
|
105
|
+
export type FileExportProps = KubbFile.Export & { key?: Key }
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* File.Export
|
|
109
|
+
*
|
|
110
|
+
* Declares an export entry for the current file. This will be collected by
|
|
111
|
+
* the FileCollector for later emission.
|
|
112
|
+
*/
|
|
113
|
+
function FileExport(props: FileExportProps) {
|
|
114
|
+
const { name, path, isTypeOnly, asAlias } = props
|
|
115
|
+
|
|
116
|
+
const nodeTree = useNodeTree()
|
|
117
|
+
const file = useFile()
|
|
81
118
|
|
|
82
|
-
|
|
83
|
-
|
|
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} />
|
|
84
135
|
}
|
|
85
136
|
|
|
86
137
|
FileExport.displayName = 'KubbFileExport'
|
|
87
138
|
|
|
88
|
-
type FileImportProps = KubbFile.Import & { key?: Key }
|
|
139
|
+
export type FileImportProps = KubbFile.Import & { key?: Key }
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* File.Import
|
|
143
|
+
*
|
|
144
|
+
* Declares an import entry for the current file.
|
|
145
|
+
*/
|
|
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
|
+
}
|
|
89
167
|
|
|
90
|
-
|
|
91
|
-
return <kubb-import name={name} root={root} path={path} isNameSpace={isNameSpace} isTypeOnly={isTypeOnly || false} />
|
|
168
|
+
return <kubb-import name={name} root={root} path={path} isNameSpace={isNameSpace} isTypeOnly={isTypeOnly} />
|
|
92
169
|
}
|
|
93
170
|
|
|
94
171
|
FileImport.displayName = 'KubbFileImport'
|
|
@@ -96,4 +173,3 @@ FileImport.displayName = 'KubbFileImport'
|
|
|
96
173
|
File.Export = FileExport
|
|
97
174
|
File.Import = FileImport
|
|
98
175
|
File.Source = FileSource
|
|
99
|
-
File.Context = FileContext
|
|
@@ -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,10 +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
|
+
/**
|
|
48
|
+
* Generates a TypeScript function declaration.
|
|
49
|
+
*/
|
|
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
|
+
|
|
45
61
|
return (
|
|
46
62
|
<>
|
|
47
63
|
{JSDoc?.comments && (
|
|
@@ -87,7 +103,22 @@ type ArrowFunctionProps = Props & {
|
|
|
87
103
|
singleLine?: boolean
|
|
88
104
|
}
|
|
89
105
|
|
|
90
|
-
|
|
106
|
+
/**
|
|
107
|
+
* ArrowFunction
|
|
108
|
+
*
|
|
109
|
+
* Renders an arrow function definition. Supports the same flags as `Function`.
|
|
110
|
+
* Use `singleLine` to render the body as a single-line expression.
|
|
111
|
+
*/
|
|
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
|
+
}
|
|
91
122
|
return (
|
|
92
123
|
<>
|
|
93
124
|
{JSDoc?.comments && (
|
|
@@ -10,6 +10,9 @@ type IndentProps = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Indents all children by `size` spaces.
|
|
12
12
|
* Collapses consecutive <br /> tags to at most 2.
|
|
13
|
+
*
|
|
14
|
+
* Indent will dedent and re-indent string children and will prefix
|
|
15
|
+
* non-string children with the requested number of spaces.
|
|
13
16
|
*/
|
|
14
17
|
export function Indent({ size = 2, children }: IndentProps) {
|
|
15
18
|
if (!children) return null
|
package/src/components/Root.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type FileManager, NodeTreeContext, provide, RootContext, type TreeNode } from '@kubb/fabric-core'
|
|
2
|
+
import { Component } from 'react'
|
|
2
3
|
|
|
3
|
-
import type { KubbNode } from '../types.ts'
|
|
4
|
+
import type { ComponentNode, KubbNode } from '../types.ts'
|
|
4
5
|
|
|
5
6
|
type ErrorBoundaryProps = {
|
|
6
7
|
onError: (error: Error) => void
|
|
@@ -32,40 +33,45 @@ class ErrorBoundary extends Component<{
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export type
|
|
36
|
+
export type RootProps = {
|
|
36
37
|
/**
|
|
37
|
-
* Exit (unmount) the whole
|
|
38
|
+
* Exit (unmount) the whole app.
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
onExit: (error?: Error) => void
|
|
41
|
+
/**
|
|
42
|
+
* Error hook receiving runtime exceptions.
|
|
43
|
+
*/
|
|
44
|
+
onError: (error: Error) => void
|
|
45
|
+
/**
|
|
46
|
+
* TreeNode representing the tree structure of the app.
|
|
47
|
+
*/
|
|
48
|
+
treeNode: TreeNode<ComponentNode>
|
|
47
49
|
/**
|
|
48
|
-
*
|
|
50
|
+
* FileManager instance for managing files within the app.
|
|
49
51
|
*/
|
|
50
|
-
|
|
52
|
+
fileManager: FileManager
|
|
51
53
|
/**
|
|
52
|
-
*
|
|
54
|
+
* Children nodes.
|
|
53
55
|
*/
|
|
54
|
-
|
|
55
|
-
readonly children?: KubbNode
|
|
56
|
+
children?: KubbNode
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
/**
|
|
60
|
+
* This component provides the root behavior for the Fabric runtime.
|
|
61
|
+
*/
|
|
62
|
+
export function Root({ onError, onExit, treeNode, fileManager, children }: RootProps) {
|
|
63
|
+
provide(RootContext, { exit: onExit, treeNode, fileManager })
|
|
64
|
+
provide(NodeTreeContext, treeNode)
|
|
65
|
+
|
|
59
66
|
return (
|
|
60
67
|
<ErrorBoundary
|
|
61
68
|
onError={(error) => {
|
|
62
69
|
onError(error)
|
|
63
70
|
}}
|
|
64
71
|
>
|
|
65
|
-
|
|
72
|
+
{children}
|
|
66
73
|
</ErrorBoundary>
|
|
67
74
|
)
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
Root.Context = RootContext
|
|
71
77
|
Root.displayName = 'KubbRoot'
|
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,10 +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
|
+
/**
|
|
26
|
+
* Generates a TypeScript type declaration.
|
|
27
|
+
*/
|
|
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
|
+
|
|
22
39
|
if (name.charAt(0).toUpperCase() !== name.charAt(0)) {
|
|
23
40
|
throw new Error('Name should start with a capital letter(see TypeScript types)')
|
|
24
41
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getData = async <TData>(): Promise<number> => 2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const myVar = "hello"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kubb/react-fabric";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import fabric from "@kubb/react-fabric";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
type MyType = { a: string }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const myVar = "hello" as const
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const myVar :string = "hello"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const myVar = "hello"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MyType = { a: string }
|