@kubb/react-fabric 0.0.0-canary-20251020201500 → 0.0.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/index.cjs +46 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -20
- package/dist/index.d.ts +47 -20
- package/dist/index.js +46 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ReactTemplate.tsx +5 -4
- package/src/components/Const.tsx +17 -4
- package/src/components/Function.tsx +38 -6
- package/src/components/Root.tsx +9 -5
- package/src/components/Text.tsx +31 -0
- package/src/components/Type.tsx +7 -1
- package/src/createApp.ts +2 -1
- package/src/dom.ts +3 -5
- package/src/hooks/useApp.ts +2 -2
- package/src/index.ts +1 -0
- package/src/utils/throttle.ts +30 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/react-fabric",
|
|
3
|
-
"version": "0.0.0
|
|
3
|
+
"version": "0.0.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",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"react-reconciler": "0.32.0",
|
|
84
84
|
"signal-exit": "^4.1.0",
|
|
85
85
|
"ws": "^8.18.3",
|
|
86
|
-
"@kubb/fabric-core": "0.0.0
|
|
86
|
+
"@kubb/fabric-core": "0.0.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@types/react": "^19.2.2",
|
package/src/ReactTemplate.tsx
CHANGED
|
@@ -3,6 +3,7 @@ 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'
|
|
6
7
|
import { Root } from './components/Root.tsx'
|
|
7
8
|
import { createNode } from './dom.ts'
|
|
8
9
|
import type { FiberRoot } from './kubbRenderer.ts'
|
|
@@ -165,9 +166,9 @@ export class ReactTemplate {
|
|
|
165
166
|
: text
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
render(node: ReactNode): void {
|
|
169
|
+
render(node: ReactNode, { meta = {} }: Omit<RootContextProps, 'exit'> = { meta: {} }): void {
|
|
169
170
|
const element = (
|
|
170
|
-
<Root onExit={this.onExit.bind(this)} onError={this.onError.bind(this)}>
|
|
171
|
+
<Root meta={meta} onExit={this.onExit.bind(this)} onError={this.onError.bind(this)}>
|
|
171
172
|
{node}
|
|
172
173
|
</Root>
|
|
173
174
|
)
|
|
@@ -176,9 +177,9 @@ export class ReactTemplate {
|
|
|
176
177
|
KubbRenderer.flushSyncWork()
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
async renderToString(node: ReactNode): Promise<string> {
|
|
180
|
+
async renderToString(node: ReactNode, { meta = {} }: Omit<RootContextProps, 'exit'> = { meta: {} }): Promise<string> {
|
|
180
181
|
const element = (
|
|
181
|
-
<Root onExit={this.onExit.bind(this)} onError={this.onError.bind(this)}>
|
|
182
|
+
<Root meta={meta} onExit={this.onExit.bind(this)} onError={this.onError.bind(this)}>
|
|
182
183
|
{node}
|
|
183
184
|
</Root>
|
|
184
185
|
)
|
package/src/components/Const.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
2
|
|
|
3
|
+
import { Space } from './Text.tsx'
|
|
3
4
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
4
5
|
|
|
5
6
|
type Props = {
|
|
@@ -36,16 +37,28 @@ export function Const({ name, export: canExport, type, JSDoc, asConst, children
|
|
|
36
37
|
<br />
|
|
37
38
|
</>
|
|
38
39
|
)}
|
|
39
|
-
{canExport &&
|
|
40
|
-
|
|
40
|
+
{canExport && (
|
|
41
|
+
<>
|
|
42
|
+
export
|
|
43
|
+
<Space />
|
|
44
|
+
</>
|
|
45
|
+
)}
|
|
46
|
+
const {name}
|
|
47
|
+
<Space />
|
|
41
48
|
{type && (
|
|
42
49
|
<>
|
|
43
50
|
{':'}
|
|
44
|
-
{type}
|
|
51
|
+
{type}
|
|
52
|
+
<Space />
|
|
45
53
|
</>
|
|
46
54
|
)}
|
|
47
55
|
= {children}
|
|
48
|
-
{asConst &&
|
|
56
|
+
{asConst && (
|
|
57
|
+
<>
|
|
58
|
+
<Space />
|
|
59
|
+
as const
|
|
60
|
+
</>
|
|
61
|
+
)}
|
|
49
62
|
</>
|
|
50
63
|
)
|
|
51
64
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
2
|
import { Indent } from './Indent.tsx'
|
|
3
|
+
import { Space } from './Text.tsx'
|
|
3
4
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
4
5
|
|
|
5
6
|
type Props = {
|
|
@@ -50,9 +51,24 @@ export function Function({ name, default: isDefault, export: canExport, async, g
|
|
|
50
51
|
<br />
|
|
51
52
|
</>
|
|
52
53
|
)}
|
|
53
|
-
{canExport &&
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
{canExport && (
|
|
55
|
+
<>
|
|
56
|
+
export
|
|
57
|
+
<Space />
|
|
58
|
+
</>
|
|
59
|
+
)}
|
|
60
|
+
{isDefault && (
|
|
61
|
+
<>
|
|
62
|
+
default
|
|
63
|
+
<Space />
|
|
64
|
+
</>
|
|
65
|
+
)}
|
|
66
|
+
{async && (
|
|
67
|
+
<>
|
|
68
|
+
async
|
|
69
|
+
<Space />
|
|
70
|
+
</>
|
|
71
|
+
)}
|
|
56
72
|
function {name}
|
|
57
73
|
{generics && (
|
|
58
74
|
<>
|
|
@@ -96,9 +112,25 @@ function ArrowFunction({ name, default: isDefault, export: canExport, async, gen
|
|
|
96
112
|
<br />
|
|
97
113
|
</>
|
|
98
114
|
)}
|
|
99
|
-
{canExport &&
|
|
100
|
-
|
|
101
|
-
|
|
115
|
+
{canExport && (
|
|
116
|
+
<>
|
|
117
|
+
export
|
|
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
|
+
)}
|
|
102
134
|
{generics && (
|
|
103
135
|
<>
|
|
104
136
|
{'<'}
|
package/src/components/Root.tsx
CHANGED
|
@@ -2,8 +2,9 @@ import { Component, createContext } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import type { KubbNode } from '../types.ts'
|
|
4
4
|
|
|
5
|
-
type ErrorBoundaryProps = {
|
|
5
|
+
type ErrorBoundaryProps<Meta extends Record<string, unknown> = Record<string, unknown>> = {
|
|
6
6
|
onError: (error: Error) => void
|
|
7
|
+
meta: Meta
|
|
7
8
|
children?: KubbNode
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -32,18 +33,20 @@ class ErrorBoundary extends Component<{
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export type RootContextProps = {
|
|
36
|
+
export type RootContextProps<Meta extends Record<string, unknown> = Record<string, unknown>> = {
|
|
36
37
|
/**
|
|
37
38
|
* Exit (unmount) the whole Ink app.
|
|
38
39
|
*/
|
|
39
40
|
readonly exit: (error?: Error) => void
|
|
41
|
+
readonly meta: Meta
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
export const RootContext = createContext<RootContextProps>({
|
|
43
45
|
exit: () => {},
|
|
46
|
+
meta: {},
|
|
44
47
|
})
|
|
45
48
|
|
|
46
|
-
type RootProps = {
|
|
49
|
+
type RootProps<Meta extends Record<string, unknown> = Record<string, unknown>> = {
|
|
47
50
|
/**
|
|
48
51
|
* Exit (unmount) hook
|
|
49
52
|
*/
|
|
@@ -52,10 +55,11 @@ type RootProps = {
|
|
|
52
55
|
* Error hook
|
|
53
56
|
*/
|
|
54
57
|
readonly onError: (error: Error) => void
|
|
58
|
+
readonly meta: Meta
|
|
55
59
|
readonly children?: KubbNode
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
export function Root({ onError, onExit, children }: RootProps) {
|
|
62
|
+
export function Root<Meta extends Record<string, unknown> = Record<string, unknown>>({ onError, onExit, meta, children }: RootProps<Meta>) {
|
|
59
63
|
try {
|
|
60
64
|
return (
|
|
61
65
|
<ErrorBoundary
|
|
@@ -63,7 +67,7 @@ export function Root({ onError, onExit, children }: RootProps) {
|
|
|
63
67
|
onError(error)
|
|
64
68
|
}}
|
|
65
69
|
>
|
|
66
|
-
<RootContext.Provider value={{ exit: onExit }}>{children}</RootContext.Provider>
|
|
70
|
+
<RootContext.Provider value={{ meta, exit: onExit }}>{children}</RootContext.Provider>
|
|
67
71
|
</ErrorBoundary>
|
|
68
72
|
)
|
|
69
73
|
} catch (_e) {
|
|
@@ -0,0 +1,31 @@
|
|
|
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/components/Type.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JSDoc, Key, KubbNode } from '../types.ts'
|
|
2
|
+
import { Space } from './Text.tsx'
|
|
2
3
|
import { createJSDoc } from '../utils/createJSDoc.ts'
|
|
3
4
|
|
|
4
5
|
type Props = {
|
|
@@ -31,7 +32,12 @@ export function Type({ name, export: canExport, JSDoc, children }: Props) {
|
|
|
31
32
|
<br />
|
|
32
33
|
</>
|
|
33
34
|
)}
|
|
34
|
-
{canExport &&
|
|
35
|
+
{canExport && (
|
|
36
|
+
<>
|
|
37
|
+
export
|
|
38
|
+
<Space />
|
|
39
|
+
</>
|
|
40
|
+
)}
|
|
35
41
|
type {name} = {children}
|
|
36
42
|
</>
|
|
37
43
|
)
|
package/src/createApp.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
2
|
import { defineApp } from '@kubb/fabric-core'
|
|
3
|
-
import {
|
|
3
|
+
import type { ElementType } from 'react'
|
|
4
|
+
import { createElement } from './index.ts'
|
|
4
5
|
import { ReactTemplate } from './ReactTemplate.tsx'
|
|
5
6
|
|
|
6
7
|
export const createApp = defineApp<ElementType>((app, context) => {
|
package/src/dom.ts
CHANGED
|
@@ -11,15 +11,13 @@ export const createNode = (nodeName: string): DOMElement => {
|
|
|
11
11
|
return node
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const appendChildNode = (node:
|
|
14
|
+
export const appendChildNode = (node: DOMElement, childNode: DOMElement): void => {
|
|
15
15
|
if (childNode.parentNode) {
|
|
16
16
|
removeChildNode(childNode.parentNode, childNode)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
node.childNodes.push(childNode)
|
|
22
|
-
}
|
|
19
|
+
childNode.parentNode = node
|
|
20
|
+
node.childNodes.push(childNode)
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
export const insertBeforeNode = (node: DOMElement, newChildNode: DOMNode, beforeChildNode: DOMNode): void => {
|
package/src/hooks/useApp.ts
CHANGED
|
@@ -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
|
|
7
|
+
export function useApp(): AppContextProps {
|
|
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
|
|
15
15
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ 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'
|
|
10
11
|
export { Type } from './components/Type.tsx'
|
|
11
12
|
export { createApp } from './createApp.ts'
|
|
12
13
|
export { useApp } from './hooks/useApp.ts'
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|