@kubb/renderer-jsx 5.0.0-alpha.33
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/LICENSE +14 -0
- package/dist/chunk-CErwXX-a.js +28 -0
- package/dist/index.cjs +18090 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +330 -0
- package/dist/index.js +18075 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.cjs +11 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +14 -0
- package/dist/jsx-dev-runtime.js +10 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-namespace-Cx1KMEbe.d.ts +39 -0
- package/dist/jsx-runtime-CeMde2cR.cjs +1503 -0
- package/dist/jsx-runtime-CeMde2cR.cjs.map +1 -0
- package/dist/jsx-runtime-Dmf9wTKR.js +1448 -0
- package/dist/jsx-runtime-Dmf9wTKR.js.map +1 -0
- package/dist/jsx-runtime.cjs +15 -0
- package/dist/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime.d.ts +16 -0
- package/dist/jsx-runtime.js +12 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/types-C7FD9BLg.d.ts +119 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/package.json +121 -0
- package/src/Renderer.ts +184 -0
- package/src/Runtime.tsx +171 -0
- package/src/components/Const.tsx +44 -0
- package/src/components/File.tsx +106 -0
- package/src/components/Function.tsx +107 -0
- package/src/components/Jsx.tsx +34 -0
- package/src/components/Root.tsx +64 -0
- package/src/components/Type.tsx +40 -0
- package/src/context/KubbContext.ts +15 -0
- package/src/context/OasContext.ts +9 -0
- package/src/createRenderer.tsx +32 -0
- package/src/dom.ts +91 -0
- package/src/globals.ts +34 -0
- package/src/index.ts +10 -0
- package/src/jsx-dev-runtime.ts +10 -0
- package/src/jsx-namespace.d.ts +53 -0
- package/src/jsx-runtime.ts +12 -0
- package/src/types.ts +113 -0
- package/src/utils.ts +301 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { JSDoc, Key, KubbReactElement, KubbReactNode } from '../types.ts'
|
|
2
|
+
|
|
3
|
+
export type TypeProps = {
|
|
4
|
+
key?: Key
|
|
5
|
+
/**
|
|
6
|
+
* Name of the type, this needs to start with a capital letter.
|
|
7
|
+
*/
|
|
8
|
+
name: string
|
|
9
|
+
/**
|
|
10
|
+
* Does this type need to be exported.
|
|
11
|
+
*/
|
|
12
|
+
export?: boolean
|
|
13
|
+
/**
|
|
14
|
+
* Options for JSdocs.
|
|
15
|
+
*/
|
|
16
|
+
JSDoc?: JSDoc
|
|
17
|
+
/**
|
|
18
|
+
* Children nodes.
|
|
19
|
+
*/
|
|
20
|
+
children?: KubbReactNode
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Generates a TypeScript type declaration.
|
|
25
|
+
*/
|
|
26
|
+
export function Type({ children, ...props }: TypeProps): KubbReactElement {
|
|
27
|
+
const { name, export: canExport, JSDoc } = props
|
|
28
|
+
|
|
29
|
+
if (name.charAt(0).toUpperCase() !== name.charAt(0)) {
|
|
30
|
+
throw new Error('Name should start with a capital letter(see TypeScript types)')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<kubb-type name={name} export={canExport} JSDoc={JSDoc}>
|
|
35
|
+
{children}
|
|
36
|
+
</kubb-type>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Type.displayName = 'Type'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext } from '@internals/utils'
|
|
2
|
+
|
|
3
|
+
export type KubbContextValue = {
|
|
4
|
+
driver: unknown
|
|
5
|
+
plugin: unknown
|
|
6
|
+
mode: 'single' | 'split'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Context key for kubb render-time data (driver, plugin, mode).
|
|
11
|
+
* Use `provide`/`unprovide` from `@internals/utils` around render calls,
|
|
12
|
+
* and `inject` inside generator components.
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
15
|
+
export const KubbContext = createContext<KubbContextValue | null>(null)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext } from '@internals/utils'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Context key for the OAS (OpenAPI Specification) instance.
|
|
5
|
+
* Use `provide`/`unprovide` from `@internals/utils` around render calls,
|
|
6
|
+
* and `inject` inside generator components.
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
9
|
+
export const OasContext = createContext<unknown>(null)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { FileNode } from '@kubb/ast/types'
|
|
2
|
+
import { Runtime } from './Runtime.tsx'
|
|
3
|
+
import type { KubbReactElement } from './types.ts'
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Set this to true to always see the result of the render in the console(line per render)
|
|
8
|
+
*/
|
|
9
|
+
debug?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type Renderer = {
|
|
13
|
+
render(Element: KubbReactElement): Promise<void>
|
|
14
|
+
unmount(error?: Error | number | null): void
|
|
15
|
+
files: Array<FileNode>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createRenderer(options: Options = {}): Renderer {
|
|
19
|
+
const runtime = new Runtime(options)
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
async render(Element) {
|
|
23
|
+
await runtime.render(Element)
|
|
24
|
+
},
|
|
25
|
+
get files() {
|
|
26
|
+
return runtime.nodes
|
|
27
|
+
},
|
|
28
|
+
unmount(error) {
|
|
29
|
+
runtime.unmount(error)
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/dom.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, TextNode } from './types.ts'
|
|
2
|
+
|
|
3
|
+
export const createNode = (nodeName: string): DOMElement => {
|
|
4
|
+
const node: DOMElement = {
|
|
5
|
+
nodeName: nodeName as DOMElement['nodeName'],
|
|
6
|
+
attributes: new Map(),
|
|
7
|
+
childNodes: [],
|
|
8
|
+
parentNode: undefined,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return node
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const appendChildNode = (node: DOMNode, childNode: DOMElement | DOMNode): void => {
|
|
15
|
+
if (childNode.parentNode) {
|
|
16
|
+
removeChildNode(childNode.parentNode, childNode)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (node.nodeName !== '#text') {
|
|
20
|
+
childNode.parentNode = node
|
|
21
|
+
node.childNodes.push(childNode)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const insertBeforeNode = (node: DOMElement, newChildNode: DOMNode, beforeChildNode: DOMNode): void => {
|
|
26
|
+
if (newChildNode.parentNode) {
|
|
27
|
+
removeChildNode(newChildNode.parentNode, newChildNode)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
newChildNode.parentNode = node
|
|
31
|
+
|
|
32
|
+
const index = node.childNodes.indexOf(beforeChildNode)
|
|
33
|
+
if (index >= 0) {
|
|
34
|
+
node.childNodes.splice(index, 0, newChildNode)
|
|
35
|
+
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
node.childNodes.push(newChildNode)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const removeChildNode = (node: DOMElement, removeNode: DOMNode): void => {
|
|
43
|
+
removeNode.parentNode = undefined
|
|
44
|
+
|
|
45
|
+
const index = node.childNodes.indexOf(removeNode)
|
|
46
|
+
if (index >= 0) {
|
|
47
|
+
node.childNodes.splice(index, 1)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const setAttribute = (node: DOMElement, key: string, value: DOMNodeAttribute): void => {
|
|
52
|
+
node.attributes.set(key, value)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const createTextNode = (text: string): TextNode => {
|
|
56
|
+
const node: TextNode = {
|
|
57
|
+
nodeName: '#text',
|
|
58
|
+
nodeValue: text,
|
|
59
|
+
parentNode: undefined,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setTextNodeValue(node, text)
|
|
63
|
+
|
|
64
|
+
return node
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const setTextNodeValue = (node: TextNode, text: string): void => {
|
|
68
|
+
if (typeof text !== 'string') {
|
|
69
|
+
text = String(text)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
node.nodeValue = text
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const nodeNames = new Set<ElementNames>([
|
|
76
|
+
'kubb-export',
|
|
77
|
+
'kubb-file',
|
|
78
|
+
'kubb-source',
|
|
79
|
+
'kubb-import',
|
|
80
|
+
'kubb-function',
|
|
81
|
+
'kubb-arrow-function',
|
|
82
|
+
'kubb-const',
|
|
83
|
+
'kubb-type',
|
|
84
|
+
'kubb-jsx',
|
|
85
|
+
'kubb-text',
|
|
86
|
+
'kubb-root',
|
|
87
|
+
'kubb-app',
|
|
88
|
+
'br',
|
|
89
|
+
'indent',
|
|
90
|
+
'dedent',
|
|
91
|
+
])
|
package/src/globals.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type React from 'react'
|
|
2
|
+
import type {
|
|
3
|
+
KubbExportProps,
|
|
4
|
+
KubbFileProps,
|
|
5
|
+
KubbImportProps,
|
|
6
|
+
KubbJsxProps,
|
|
7
|
+
KubbReactElement,
|
|
8
|
+
KubbReactNode,
|
|
9
|
+
KubbSourceProps,
|
|
10
|
+
KubbTextProps,
|
|
11
|
+
LineBreakProps,
|
|
12
|
+
} from './types.ts'
|
|
13
|
+
|
|
14
|
+
declare global {
|
|
15
|
+
namespace JSX {
|
|
16
|
+
type Element = KubbReactElement
|
|
17
|
+
|
|
18
|
+
interface ElementClass extends React.ComponentClass<any> {
|
|
19
|
+
render(): KubbReactNode
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface IntrinsicElements {
|
|
23
|
+
'kubb-jsx': KubbJsxProps
|
|
24
|
+
'kubb-text': KubbTextProps
|
|
25
|
+
'kubb-file': KubbFileProps
|
|
26
|
+
'kubb-source': KubbSourceProps
|
|
27
|
+
'kubb-import': KubbImportProps
|
|
28
|
+
'kubb-export': KubbExportProps
|
|
29
|
+
br: LineBreakProps
|
|
30
|
+
indent: {}
|
|
31
|
+
dedent: {}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createContext, inject, provide, unprovide } from '@internals/utils'
|
|
2
|
+
export { Const } from './components/Const.tsx'
|
|
3
|
+
export { File } from './components/File.tsx'
|
|
4
|
+
export { Function } from './components/Function.tsx'
|
|
5
|
+
export { Jsx } from './components/Jsx.tsx'
|
|
6
|
+
export { Root } from './components/Root.tsx'
|
|
7
|
+
export { Type } from './components/Type.tsx'
|
|
8
|
+
export { KubbContext } from './context/KubbContext.ts'
|
|
9
|
+
export { OasContext } from './context/OasContext.ts'
|
|
10
|
+
export { createRenderer } from './createRenderer.tsx'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react/jsx-runtime'
|
|
2
|
+
import type { KubbReactElement, KubbReactNode } from './types.ts'
|
|
3
|
+
|
|
4
|
+
export const Fragment = React.Fragment
|
|
5
|
+
export const jsxDEV = React.jsx
|
|
6
|
+
|
|
7
|
+
export type * from './jsx-namespace.d.ts'
|
|
8
|
+
|
|
9
|
+
export type JSXElement = KubbReactElement
|
|
10
|
+
export type ReactNode = KubbReactNode
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// biome-ignore-all lint/correctness/noUnusedVariables: JSX namespace declarations are consumed by TypeScript's JSX type system, not by user code
|
|
2
|
+
import type React from 'react'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
KubbArrowFunctionProps,
|
|
6
|
+
KubbConstProps,
|
|
7
|
+
KubbExportProps,
|
|
8
|
+
KubbFileProps,
|
|
9
|
+
KubbFunctionProps,
|
|
10
|
+
KubbImportProps,
|
|
11
|
+
KubbJsxProps,
|
|
12
|
+
KubbReactElement,
|
|
13
|
+
KubbReactNode,
|
|
14
|
+
KubbSourceProps,
|
|
15
|
+
KubbTextProps,
|
|
16
|
+
KubbTypeProps,
|
|
17
|
+
LineBreakProps,
|
|
18
|
+
} from './types'
|
|
19
|
+
|
|
20
|
+
export namespace JSX {
|
|
21
|
+
type ElementType = React.JSX.ElementType
|
|
22
|
+
type Element = KubbReactElement
|
|
23
|
+
|
|
24
|
+
interface ElementClass extends React.JSX.ElementClass {
|
|
25
|
+
render(): KubbReactNode
|
|
26
|
+
}
|
|
27
|
+
interface ElementAttributesProperty {
|
|
28
|
+
props: {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ElementChildrenAttribute {
|
|
32
|
+
children: {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface IntrinsicElements extends React.JSX.IntrinsicElements {
|
|
36
|
+
'kubb-jsx': KubbJsxProps
|
|
37
|
+
'kubb-text': KubbTextProps
|
|
38
|
+
'kubb-file': KubbFileProps
|
|
39
|
+
'kubb-source': KubbSourceProps
|
|
40
|
+
'kubb-import': KubbImportProps
|
|
41
|
+
'kubb-export': KubbExportProps
|
|
42
|
+
'kubb-function': KubbFunctionProps
|
|
43
|
+
'kubb-arrow-function': KubbArrowFunctionProps
|
|
44
|
+
'kubb-const': KubbConstProps
|
|
45
|
+
'kubb-type': KubbTypeProps
|
|
46
|
+
br: LineBreakProps
|
|
47
|
+
indent: {}
|
|
48
|
+
dedent: {}
|
|
49
|
+
}
|
|
50
|
+
type LibraryManagedAttributes<C, P> = React.JSX.LibraryManagedAttributes<C, P>
|
|
51
|
+
interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}
|
|
52
|
+
interface IntrinsicElements extends React.JSX.IntrinsicElements {}
|
|
53
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react/jsx-runtime'
|
|
2
|
+
import type { KubbReactElement, KubbReactNode } from './types.ts'
|
|
3
|
+
|
|
4
|
+
export const Fragment = React.Fragment
|
|
5
|
+
export const jsx = React.jsx
|
|
6
|
+
export const jsxDEV = React.jsx
|
|
7
|
+
export const jsxs = React.jsxs
|
|
8
|
+
|
|
9
|
+
export type * from './jsx-namespace.d.ts'
|
|
10
|
+
|
|
11
|
+
export type JSXElement = KubbReactElement
|
|
12
|
+
export type ReactNode = KubbReactNode
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ArrowFunctionNode, ConstNode, ExportNode, FileNode, FunctionNode, ImportNode, SourceNode, TypeNode } from '@kubb/ast/types'
|
|
2
|
+
import type React from 'react'
|
|
3
|
+
import type { JSX, ReactNode } from 'react'
|
|
4
|
+
|
|
5
|
+
export type Key = string | number | bigint
|
|
6
|
+
|
|
7
|
+
export type ElementNames =
|
|
8
|
+
| 'br'
|
|
9
|
+
| 'div'
|
|
10
|
+
| 'indent'
|
|
11
|
+
| 'dedent'
|
|
12
|
+
| 'kubb-jsx'
|
|
13
|
+
| 'kubb-text'
|
|
14
|
+
| 'kubb-file'
|
|
15
|
+
| 'kubb-source'
|
|
16
|
+
| 'kubb-import'
|
|
17
|
+
| 'kubb-export'
|
|
18
|
+
| 'kubb-function'
|
|
19
|
+
| 'kubb-arrow-function'
|
|
20
|
+
| 'kubb-const'
|
|
21
|
+
| 'kubb-type'
|
|
22
|
+
| 'kubb-root'
|
|
23
|
+
| 'kubb-app'
|
|
24
|
+
|
|
25
|
+
type Node = {
|
|
26
|
+
parentNode: DOMElement | undefined
|
|
27
|
+
internal_static?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type DOMNodeAttribute = boolean | string | number | Record<string, unknown>
|
|
31
|
+
|
|
32
|
+
type TextName = '#text'
|
|
33
|
+
export type TextNode = {
|
|
34
|
+
nodeName: TextName
|
|
35
|
+
nodeValue: string
|
|
36
|
+
} & Node
|
|
37
|
+
|
|
38
|
+
export type DOMNode<T = { nodeName: NodeNames }> = T extends {
|
|
39
|
+
nodeName: infer U
|
|
40
|
+
}
|
|
41
|
+
? U extends '#text'
|
|
42
|
+
? TextNode
|
|
43
|
+
: DOMElement
|
|
44
|
+
: never
|
|
45
|
+
|
|
46
|
+
type OutputTransformer = (s: string, index: number) => string
|
|
47
|
+
|
|
48
|
+
export type DOMElement = {
|
|
49
|
+
nodeName: ElementNames
|
|
50
|
+
attributes: Map<string, DOMNodeAttribute>
|
|
51
|
+
childNodes: DOMNode[]
|
|
52
|
+
internal_transform?: OutputTransformer
|
|
53
|
+
|
|
54
|
+
// Internal properties
|
|
55
|
+
isStaticDirty?: boolean
|
|
56
|
+
staticNode?: DOMElement
|
|
57
|
+
onComputeLayout?: () => void
|
|
58
|
+
onRender?: () => void
|
|
59
|
+
onImmediateRender?: () => void
|
|
60
|
+
} & Node
|
|
61
|
+
|
|
62
|
+
type NodeNames = ElementNames | TextName
|
|
63
|
+
|
|
64
|
+
export type KubbReactNode = ReactNode
|
|
65
|
+
export type KubbReactElement = JSX.Element
|
|
66
|
+
|
|
67
|
+
export type KubbJsxProps = {
|
|
68
|
+
children?: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type KubbTextProps = {
|
|
72
|
+
children?: KubbReactNode
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type KubbFileProps = {
|
|
76
|
+
id?: string
|
|
77
|
+
children?: KubbReactNode
|
|
78
|
+
baseName: string
|
|
79
|
+
path: string
|
|
80
|
+
override?: boolean
|
|
81
|
+
meta?: FileNode['meta']
|
|
82
|
+
}
|
|
83
|
+
export type KubbSourceProps = Omit<SourceNode, 'kind'> & {
|
|
84
|
+
children?: KubbReactNode
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type KubbImportProps = Omit<ImportNode, 'kind'> & {}
|
|
88
|
+
|
|
89
|
+
export type KubbExportProps = Omit<ExportNode, 'kind'> & {}
|
|
90
|
+
|
|
91
|
+
export type KubbFunctionProps = Omit<FunctionNode, 'kind'> & {
|
|
92
|
+
children?: KubbReactNode
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type KubbArrowFunctionProps = Omit<ArrowFunctionNode, 'kind'> & {
|
|
96
|
+
children?: KubbReactNode
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type KubbConstProps = Omit<ConstNode, 'kind'> & {
|
|
100
|
+
children?: KubbReactNode
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type KubbTypeProps = Omit<TypeNode, 'kind'> & {
|
|
104
|
+
children?: KubbReactNode
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type LineBreakProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLBRElement>, HTMLBRElement>
|
|
108
|
+
|
|
109
|
+
export type JSDoc = {
|
|
110
|
+
comments: string[]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type { Context } from '@internals/utils'
|