@kubb/react-fabric 0.0.0 → 0.0.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/devtools.cjs +154 -85
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.js +154 -85
- package/dist/devtools.js.map +1 -1
- package/dist/index.cjs +47 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -50
- package/dist/index.d.ts +61 -50
- package/dist/index.js +47 -72
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
- package/src/ReactTemplate.tsx +21 -23
- package/src/components/Const.tsx +4 -17
- package/src/components/Function.tsx +6 -38
- package/src/components/Root.tsx +5 -9
- package/src/components/Type.tsx +1 -7
- package/src/{hooks → composables}/useApp.ts +2 -2
- package/src/createApp.ts +4 -9
- package/src/dom.ts +5 -3
- package/src/index.ts +3 -4
- package/src/components/Text.tsx +0 -31
- package/src/utils/throttle.ts +0 -30
- /package/src/{hooks → composables}/useFile.ts +0 -0
- /package/src/{hooks → composables}/useLifecycle.tsx +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/react-fabric",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.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",
|
|
@@ -59,6 +59,12 @@
|
|
|
59
59
|
"devtools": [
|
|
60
60
|
"./dist/devtools.d.ts"
|
|
61
61
|
],
|
|
62
|
+
"jsx-dev-runtime": [
|
|
63
|
+
"./dist/jsx-dev-runtime.d.ts"
|
|
64
|
+
],
|
|
65
|
+
"jsx-runtime": [
|
|
66
|
+
"./dist/jsx-runtime.d.ts"
|
|
67
|
+
],
|
|
62
68
|
"types": [
|
|
63
69
|
"./dist/types.d.ts"
|
|
64
70
|
]
|
|
@@ -79,11 +85,11 @@
|
|
|
79
85
|
"indent-string": "^5.0.0",
|
|
80
86
|
"natural-orderby": "^5.0.0",
|
|
81
87
|
"react": "^19.2.0",
|
|
82
|
-
"react-devtools-inline": "^7.0.
|
|
88
|
+
"react-devtools-inline": "^7.0.1",
|
|
83
89
|
"react-reconciler": "0.32.0",
|
|
84
90
|
"signal-exit": "^4.1.0",
|
|
85
91
|
"ws": "^8.18.3",
|
|
86
|
-
"@kubb/fabric-core": "0.0.
|
|
92
|
+
"@kubb/fabric-core": "0.0.1"
|
|
87
93
|
},
|
|
88
94
|
"devDependencies": {
|
|
89
95
|
"@types/react": "^19.2.2",
|
package/src/ReactTemplate.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import type { AppContext } from '@kubb/fabric-core'
|
|
|
3
3
|
import type { ReactNode } from 'react'
|
|
4
4
|
import { ConcurrentRoot } from 'react-reconciler/constants'
|
|
5
5
|
import { onExit } from 'signal-exit'
|
|
6
|
-
import type { RootContextProps } from './components/Root.tsx'
|
|
7
6
|
import { Root } from './components/Root.tsx'
|
|
8
7
|
import { createNode } from './dom.ts'
|
|
9
8
|
import type { FiberRoot } from './kubbRenderer.ts'
|
|
@@ -12,8 +11,7 @@ import type { DOMElement } from './types.ts'
|
|
|
12
11
|
import { squashTextNodes } from './utils/squashTextNodes.ts'
|
|
13
12
|
import { processFiles } from './utils/processFiles.ts'
|
|
14
13
|
|
|
15
|
-
export type
|
|
16
|
-
context: AppContext
|
|
14
|
+
export type ReactAppContext = AppContext<{
|
|
17
15
|
stdout?: NodeJS.WriteStream
|
|
18
16
|
stdin?: NodeJS.ReadStream
|
|
19
17
|
stderr?: NodeJS.WriteStream
|
|
@@ -21,10 +19,10 @@ export type ReactTemplateOptions = {
|
|
|
21
19
|
* Set this to true to always see the result of the render in the console(line per render)
|
|
22
20
|
*/
|
|
23
21
|
debug?: boolean
|
|
24
|
-
}
|
|
22
|
+
}>
|
|
25
23
|
|
|
26
24
|
export class ReactTemplate {
|
|
27
|
-
readonly #
|
|
25
|
+
readonly #context: ReactAppContext
|
|
28
26
|
// Ignore last render after unmounting a tree to prevent empty output before exit
|
|
29
27
|
#isUnmounted: boolean
|
|
30
28
|
|
|
@@ -32,8 +30,8 @@ export class ReactTemplate {
|
|
|
32
30
|
readonly #container: FiberRoot
|
|
33
31
|
readonly #rootNode: DOMElement
|
|
34
32
|
|
|
35
|
-
constructor(
|
|
36
|
-
this.#
|
|
33
|
+
constructor(context: ReactAppContext) {
|
|
34
|
+
this.#context = context
|
|
37
35
|
|
|
38
36
|
this.#rootNode = createNode('kubb-root')
|
|
39
37
|
this.#rootNode.onRender = this.onRender
|
|
@@ -122,25 +120,25 @@ export class ReactTemplate {
|
|
|
122
120
|
return
|
|
123
121
|
}
|
|
124
122
|
|
|
125
|
-
this.#
|
|
123
|
+
this.#context.clear()
|
|
126
124
|
|
|
127
|
-
processFiles(this.#rootNode, this.#
|
|
125
|
+
processFiles(this.#rootNode, this.#context)
|
|
128
126
|
|
|
129
|
-
if (!this.#options
|
|
127
|
+
if (!this.#context.options?.debug && !this.#context.options?.stdout) {
|
|
130
128
|
return
|
|
131
129
|
}
|
|
132
130
|
|
|
133
|
-
const output = await this.#getOutput(this.#rootNode, this.#
|
|
131
|
+
const output = await this.#getOutput(this.#rootNode, this.#context)
|
|
134
132
|
|
|
135
|
-
if (this.#options
|
|
133
|
+
if (this.#context.options?.debug) {
|
|
136
134
|
console.log('Rendering: \n')
|
|
137
135
|
console.log(output)
|
|
138
136
|
}
|
|
139
137
|
|
|
140
|
-
if (this.#options.
|
|
141
|
-
this.#options.stdout.clearLine(0)
|
|
142
|
-
this.#options.stdout.cursorTo(0)
|
|
143
|
-
this.#options.stdout.write(output)
|
|
138
|
+
if (this.#context.options?.stdout && process.env.NODE_ENV !== 'test') {
|
|
139
|
+
this.#context.options.stdout.clearLine(0)
|
|
140
|
+
this.#context.options.stdout.cursorTo(0)
|
|
141
|
+
this.#context.options.stdout.write(output)
|
|
144
142
|
}
|
|
145
143
|
}
|
|
146
144
|
onError(error: Error): void {
|
|
@@ -166,9 +164,9 @@ export class ReactTemplate {
|
|
|
166
164
|
: text
|
|
167
165
|
}
|
|
168
166
|
|
|
169
|
-
render(node: ReactNode
|
|
167
|
+
render(node: ReactNode): void {
|
|
170
168
|
const element = (
|
|
171
|
-
<Root
|
|
169
|
+
<Root onExit={this.onExit.bind(this)} onError={this.onError.bind(this)}>
|
|
172
170
|
{node}
|
|
173
171
|
</Root>
|
|
174
172
|
)
|
|
@@ -177,9 +175,9 @@ export class ReactTemplate {
|
|
|
177
175
|
KubbRenderer.flushSyncWork()
|
|
178
176
|
}
|
|
179
177
|
|
|
180
|
-
async renderToString(node: ReactNode
|
|
178
|
+
async renderToString(node: ReactNode): Promise<string> {
|
|
181
179
|
const element = (
|
|
182
|
-
<Root
|
|
180
|
+
<Root onExit={this.onExit.bind(this)} onError={this.onError.bind(this)}>
|
|
183
181
|
{node}
|
|
184
182
|
</Root>
|
|
185
183
|
)
|
|
@@ -187,9 +185,9 @@ export class ReactTemplate {
|
|
|
187
185
|
KubbRenderer.updateContainerSync(element, this.#container, null, null)
|
|
188
186
|
KubbRenderer.flushSyncWork()
|
|
189
187
|
|
|
190
|
-
this.#
|
|
188
|
+
this.#context.clear()
|
|
191
189
|
|
|
192
|
-
return this.#getOutput(this.#rootNode, this.#
|
|
190
|
+
return this.#getOutput(this.#rootNode, this.#context)
|
|
193
191
|
}
|
|
194
192
|
|
|
195
193
|
unmount(error?: Error | number | null): void {
|
|
@@ -197,7 +195,7 @@ export class ReactTemplate {
|
|
|
197
195
|
return
|
|
198
196
|
}
|
|
199
197
|
|
|
200
|
-
if (this.#options
|
|
198
|
+
if (this.#context.options?.debug) {
|
|
201
199
|
console.log('Unmount', error)
|
|
202
200
|
}
|
|
203
201
|
|
package/src/components/Const.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
2
|
|
|
3
|
-
import { Space } from './Text.tsx'
|
|
4
3
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
5
4
|
|
|
6
5
|
type Props = {
|
|
@@ -37,28 +36,16 @@ export function Const({ name, export: canExport, type, JSDoc, asConst, children
|
|
|
37
36
|
<br />
|
|
38
37
|
</>
|
|
39
38
|
)}
|
|
40
|
-
{canExport &&
|
|
41
|
-
|
|
42
|
-
export
|
|
43
|
-
<Space />
|
|
44
|
-
</>
|
|
45
|
-
)}
|
|
46
|
-
const {name}
|
|
47
|
-
<Space />
|
|
39
|
+
{canExport && <>export </>}
|
|
40
|
+
const {name}{' '}
|
|
48
41
|
{type && (
|
|
49
42
|
<>
|
|
50
43
|
{':'}
|
|
51
|
-
{type}
|
|
52
|
-
<Space />
|
|
44
|
+
{type}{' '}
|
|
53
45
|
</>
|
|
54
46
|
)}
|
|
55
47
|
= {children}
|
|
56
|
-
{asConst &&
|
|
57
|
-
<>
|
|
58
|
-
<Space />
|
|
59
|
-
as const
|
|
60
|
-
</>
|
|
61
|
-
)}
|
|
48
|
+
{asConst && <> as const</>}
|
|
62
49
|
</>
|
|
63
50
|
)
|
|
64
51
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
2
|
import { Indent } from './Indent.tsx'
|
|
3
|
-
import { Space } from './Text.tsx'
|
|
4
3
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
5
4
|
|
|
6
5
|
type Props = {
|
|
@@ -51,24 +50,9 @@ export function Function({ name, default: isDefault, export: canExport, async, g
|
|
|
51
50
|
<br />
|
|
52
51
|
</>
|
|
53
52
|
)}
|
|
54
|
-
{canExport &&
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
<Space />
|
|
58
|
-
</>
|
|
59
|
-
)}
|
|
60
|
-
{isDefault && (
|
|
61
|
-
<>
|
|
62
|
-
default
|
|
63
|
-
<Space />
|
|
64
|
-
</>
|
|
65
|
-
)}
|
|
66
|
-
{async && (
|
|
67
|
-
<>
|
|
68
|
-
async
|
|
69
|
-
<Space />
|
|
70
|
-
</>
|
|
71
|
-
)}
|
|
53
|
+
{canExport && <>export </>}
|
|
54
|
+
{isDefault && <>default </>}
|
|
55
|
+
{async && <>async </>}
|
|
72
56
|
function {name}
|
|
73
57
|
{generics && (
|
|
74
58
|
<>
|
|
@@ -112,25 +96,9 @@ function ArrowFunction({ name, default: isDefault, export: canExport, async, gen
|
|
|
112
96
|
<br />
|
|
113
97
|
</>
|
|
114
98
|
)}
|
|
115
|
-
{canExport &&
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
<Space />
|
|
119
|
-
</>
|
|
120
|
-
)}
|
|
121
|
-
{isDefault && (
|
|
122
|
-
<>
|
|
123
|
-
default
|
|
124
|
-
<Space />
|
|
125
|
-
</>
|
|
126
|
-
)}
|
|
127
|
-
const {name} =<Space />
|
|
128
|
-
{async && (
|
|
129
|
-
<>
|
|
130
|
-
async
|
|
131
|
-
<Space />
|
|
132
|
-
</>
|
|
133
|
-
)}
|
|
99
|
+
{canExport && <>export </>}
|
|
100
|
+
{isDefault && <>default </>}
|
|
101
|
+
const {name} = {async && <>async </>}
|
|
134
102
|
{generics && (
|
|
135
103
|
<>
|
|
136
104
|
{'<'}
|
package/src/components/Root.tsx
CHANGED
|
@@ -2,9 +2,8 @@ import { Component, createContext } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import type { KubbNode } from '../types.ts'
|
|
4
4
|
|
|
5
|
-
type ErrorBoundaryProps
|
|
5
|
+
type ErrorBoundaryProps = {
|
|
6
6
|
onError: (error: Error) => void
|
|
7
|
-
meta: Meta
|
|
8
7
|
children?: KubbNode
|
|
9
8
|
}
|
|
10
9
|
|
|
@@ -33,20 +32,18 @@ class ErrorBoundary extends Component<{
|
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
export type RootContextProps
|
|
35
|
+
export type RootContextProps = {
|
|
37
36
|
/**
|
|
38
37
|
* Exit (unmount) the whole Ink app.
|
|
39
38
|
*/
|
|
40
39
|
readonly exit: (error?: Error) => void
|
|
41
|
-
readonly meta: Meta
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
export const RootContext = createContext<RootContextProps>({
|
|
45
43
|
exit: () => {},
|
|
46
|
-
meta: {},
|
|
47
44
|
})
|
|
48
45
|
|
|
49
|
-
type RootProps
|
|
46
|
+
type RootProps = {
|
|
50
47
|
/**
|
|
51
48
|
* Exit (unmount) hook
|
|
52
49
|
*/
|
|
@@ -55,11 +52,10 @@ type RootProps<Meta extends Record<string, unknown> = Record<string, unknown>> =
|
|
|
55
52
|
* Error hook
|
|
56
53
|
*/
|
|
57
54
|
readonly onError: (error: Error) => void
|
|
58
|
-
readonly meta: Meta
|
|
59
55
|
readonly children?: KubbNode
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
export function Root
|
|
58
|
+
export function Root({ onError, onExit, children }: RootProps) {
|
|
63
59
|
try {
|
|
64
60
|
return (
|
|
65
61
|
<ErrorBoundary
|
|
@@ -67,7 +63,7 @@ export function Root<Meta extends Record<string, unknown> = Record<string, unkno
|
|
|
67
63
|
onError(error)
|
|
68
64
|
}}
|
|
69
65
|
>
|
|
70
|
-
<RootContext.Provider value={{
|
|
66
|
+
<RootContext.Provider value={{ exit: onExit }}>{children}</RootContext.Provider>
|
|
71
67
|
</ErrorBoundary>
|
|
72
68
|
)
|
|
73
69
|
} catch (_e) {
|
package/src/components/Type.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
|
-
import { Space } from './Text.tsx'
|
|
3
2
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
4
3
|
|
|
5
4
|
type Props = {
|
|
@@ -32,12 +31,7 @@ export function Type({ name, export: canExport, JSDoc, children }: Props) {
|
|
|
32
31
|
<br />
|
|
33
32
|
</>
|
|
34
33
|
)}
|
|
35
|
-
{canExport &&
|
|
36
|
-
<>
|
|
37
|
-
export
|
|
38
|
-
<Space />
|
|
39
|
-
</>
|
|
40
|
-
)}
|
|
34
|
+
{canExport && <>export </>}
|
|
41
35
|
type {name} = {children}
|
|
42
36
|
</>
|
|
43
37
|
)
|
|
@@ -4,12 +4,12 @@ import { App, type AppContextProps } from '../components/App.tsx'
|
|
|
4
4
|
/**
|
|
5
5
|
* `useApp` will return the current App with plugin, pluginManager, fileManager and mode.
|
|
6
6
|
*/
|
|
7
|
-
export function useApp(): AppContextProps {
|
|
7
|
+
export function useApp<TMeta = unknown>(): AppContextProps<TMeta> {
|
|
8
8
|
const app = useContext(App.Context)
|
|
9
9
|
|
|
10
10
|
if (!app) {
|
|
11
11
|
throw new Error('<App /> should be set')
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
return app
|
|
14
|
+
return app as AppContextProps<TMeta>
|
|
15
15
|
}
|
package/src/createApp.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
1
|
import { defineApp } from '@kubb/fabric-core'
|
|
3
|
-
import type
|
|
4
|
-
import {
|
|
5
|
-
import { ReactTemplate } from './ReactTemplate.tsx'
|
|
2
|
+
import { type ElementType, createElement } from 'react'
|
|
3
|
+
import { type ReactAppContext, ReactTemplate } from './ReactTemplate.tsx'
|
|
6
4
|
|
|
7
|
-
export const createApp = defineApp<ElementType>((app, context) => {
|
|
8
|
-
const template =
|
|
9
|
-
process.env.NODE_ENV === 'test'
|
|
10
|
-
? new ReactTemplate({ context })
|
|
11
|
-
: new ReactTemplate({ context, stdout: process.stdout, stderr: process.stderr, stdin: process.stdin })
|
|
5
|
+
export const createApp = defineApp<ElementType, ReactAppContext>((app, context) => {
|
|
6
|
+
const template = new ReactTemplate(context)
|
|
12
7
|
|
|
13
8
|
return {
|
|
14
9
|
render() {
|
package/src/dom.ts
CHANGED
|
@@ -11,13 +11,15 @@ export const createNode = (nodeName: string): DOMElement => {
|
|
|
11
11
|
return node
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const appendChildNode = (node:
|
|
14
|
+
export const appendChildNode = (node: DOMNode, childNode: DOMElement | DOMNode): void => {
|
|
15
15
|
if (childNode.parentNode) {
|
|
16
16
|
removeChildNode(childNode.parentNode, childNode)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (node.nodeName !== '#text') {
|
|
20
|
+
childNode.parentNode = node
|
|
21
|
+
node.childNodes.push(childNode)
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export const insertBeforeNode = (node: DOMElement, newChildNode: DOMNode, beforeChildNode: DOMNode): void => {
|
package/src/index.ts
CHANGED
|
@@ -7,12 +7,11 @@ export { Const } from './components/Const.tsx'
|
|
|
7
7
|
export { File } from './components/File.tsx'
|
|
8
8
|
export { Function } from './components/Function.tsx'
|
|
9
9
|
export { Indent } from './components/Indent.tsx'
|
|
10
|
-
export { Text } from './components/Text.tsx'
|
|
11
10
|
export { Type } from './components/Type.tsx'
|
|
12
11
|
export { createApp } from './createApp.ts'
|
|
13
|
-
export { useApp } from './
|
|
14
|
-
export { useFile } from './
|
|
15
|
-
export { useLifecycle } from './
|
|
12
|
+
export { useApp } from './composables/useApp.ts'
|
|
13
|
+
export { useFile } from './composables/useFile.ts'
|
|
14
|
+
export { useLifecycle } from './composables/useLifecycle.tsx'
|
|
16
15
|
export { createFunctionParams, FunctionParams } from './utils/getFunctionParams.ts'
|
|
17
16
|
|
|
18
17
|
export const createContext = React.createContext
|
package/src/components/Text.tsx
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Key, KubbNode } from '../types.ts'
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
key?: Key
|
|
5
|
-
/**
|
|
6
|
-
* Change the indent.
|
|
7
|
-
* @default 0
|
|
8
|
-
* @deprecated
|
|
9
|
-
*/
|
|
10
|
-
indentSize?: number
|
|
11
|
-
children?: KubbNode
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated
|
|
16
|
-
*/
|
|
17
|
-
export function Text({ children }: Props) {
|
|
18
|
-
return <kubb-text>{children}</kubb-text>
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type SpaceProps = {}
|
|
22
|
-
|
|
23
|
-
Text.displayName = 'KubbText'
|
|
24
|
-
|
|
25
|
-
export function Space({}: SpaceProps) {
|
|
26
|
-
return <kubb-text> </kubb-text>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Space.displayName = 'KubbSpace'
|
|
30
|
-
|
|
31
|
-
Text.Space = Space
|
package/src/utils/throttle.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const throttle = <R, A extends any[]>(fn: (...args: A) => R, delay: number): [(...args: A) => R | undefined, () => void] => {
|
|
2
|
-
let wait = false
|
|
3
|
-
let timeout: NodeJS.Timeout
|
|
4
|
-
let cancelled = false
|
|
5
|
-
|
|
6
|
-
return [
|
|
7
|
-
(...args: A) => {
|
|
8
|
-
if (cancelled) {
|
|
9
|
-
return undefined
|
|
10
|
-
}
|
|
11
|
-
if (wait) {
|
|
12
|
-
return undefined
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const val = fn(...args)
|
|
16
|
-
|
|
17
|
-
wait = true
|
|
18
|
-
|
|
19
|
-
timeout = setTimeout(() => {
|
|
20
|
-
wait = false
|
|
21
|
-
}, delay) as NodeJS.Timeout
|
|
22
|
-
|
|
23
|
-
return val
|
|
24
|
-
},
|
|
25
|
-
() => {
|
|
26
|
-
cancelled = true
|
|
27
|
-
clearTimeout(timeout)
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
}
|
|
File without changes
|
|
File without changes
|