@kubb/renderer-jsx 5.0.0-beta.6 → 5.0.0-beta.61
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 +17 -10
- package/README.md +134 -0
- package/dist/chunk-C0LytTxp.js +8 -0
- package/dist/index.cjs +386 -17922
- package/dist/index.d.ts +232 -147
- package/dist/index.js +370 -17903
- package/dist/jsx-dev-runtime.cjs +3 -10
- package/dist/jsx-dev-runtime.d.ts +4 -8
- package/dist/jsx-dev-runtime.js +1 -9
- package/dist/jsx-runtime-3ncySO6L.cjs +89 -0
- package/dist/jsx-runtime.cjs +5 -14
- package/dist/jsx-runtime.d.ts +60 -10
- package/dist/jsx-runtime.js +24 -7
- package/dist/types-UI1cZVah.d.ts +115 -0
- package/dist/types.d.ts +2 -2
- package/package.json +6 -29
- package/src/SyncRuntime.tsx +298 -0
- package/src/components/Callout.tsx +59 -0
- package/src/components/Const.tsx +4 -4
- package/src/components/File.tsx +7 -5
- package/src/components/Frontmatter.tsx +38 -0
- package/src/components/Function.tsx +8 -8
- package/src/components/Heading.tsx +34 -0
- package/src/components/Jsx.tsx +1 -1
- package/src/components/List.tsx +40 -0
- package/src/components/Paragraph.tsx +28 -0
- package/src/components/Type.tsx +3 -3
- package/src/constants.ts +9 -28
- package/src/createRenderer.tsx +38 -75
- package/src/globals.ts +14 -6
- package/src/index.ts +6 -3
- package/src/jsx-dev-runtime.ts +1 -3
- package/src/jsx-namespace.d.ts +21 -13
- package/src/jsx-runtime.ts +22 -6
- package/src/types.ts +16 -100
- package/dist/chunk-Bb7HlUDG.js +0 -28
- package/dist/jsx-namespace-CNp0arTN.d.ts +0 -39
- package/dist/jsx-runtime-Cvu_ZYgL.js +0 -1448
- package/dist/jsx-runtime-DdmO3p0U.cjs +0 -1503
- package/dist/types-nAFMiWFw.d.ts +0 -168
- package/src/Renderer.ts +0 -184
- package/src/Runtime.tsx +0 -170
- package/src/components/Root.tsx +0 -70
- package/src/dom.ts +0 -105
- package/src/utils.ts +0 -267
package/src/utils.ts
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import type { ArrowFunctionNode, CodeNode, ExportNode, FileNode, ImportNode, JSDocNode, SourceNode } from '@kubb/ast'
|
|
2
|
-
import {
|
|
3
|
-
createArrowFunction,
|
|
4
|
-
createBreak,
|
|
5
|
-
createConst,
|
|
6
|
-
createExport,
|
|
7
|
-
createFunction,
|
|
8
|
-
createImport,
|
|
9
|
-
createJsx,
|
|
10
|
-
createSource,
|
|
11
|
-
createText,
|
|
12
|
-
createType,
|
|
13
|
-
} from '@kubb/ast'
|
|
14
|
-
import { nodeNames, TEXT_NODE_NAME } from './constants.ts'
|
|
15
|
-
import type { DOMElement, DOMNode, ElementNames } from './types.ts'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Collect the text and nested AST-node children of a single kubb-* element.
|
|
19
|
-
*
|
|
20
|
-
* `#text` children become raw {@link TextNode}s; nested `kubb-function`, `kubb-const`,
|
|
21
|
-
* `kubb-type`, and similar elements are converted into their respective {@link CodeNode}s.
|
|
22
|
-
* Any unrecognized DOM elements are silently skipped.
|
|
23
|
-
*/
|
|
24
|
-
function collectChildNodes(element: DOMElement): Array<CodeNode> {
|
|
25
|
-
const result: Array<CodeNode> = []
|
|
26
|
-
|
|
27
|
-
for (const child of element.childNodes) {
|
|
28
|
-
if (!child) {
|
|
29
|
-
continue
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (child.nodeName === TEXT_NODE_NAME) {
|
|
33
|
-
const text = (child as DOMNode<{ nodeName: '#text' }>).nodeValue
|
|
34
|
-
if (text && text.trim().length > 0) {
|
|
35
|
-
result.push(createText(text))
|
|
36
|
-
}
|
|
37
|
-
continue
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (child.nodeName === 'br') {
|
|
41
|
-
result.push(createBreak())
|
|
42
|
-
continue
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (child.nodeName === 'kubb-function') {
|
|
46
|
-
const attrs = child.attributes
|
|
47
|
-
result.push(
|
|
48
|
-
createFunction({
|
|
49
|
-
name: attrs.get('name') as string,
|
|
50
|
-
params: attrs.get('params') as string | undefined,
|
|
51
|
-
export: attrs.get('export') as boolean | undefined,
|
|
52
|
-
default: attrs.get('default') as boolean | undefined,
|
|
53
|
-
async: attrs.get('async') as boolean | undefined,
|
|
54
|
-
generics: attrs.get('generics') as string | undefined,
|
|
55
|
-
returnType: attrs.get('returnType') as string | undefined,
|
|
56
|
-
JSDoc: attrs.get('JSDoc') as JSDocNode | undefined,
|
|
57
|
-
nodes: collectChildNodes(child),
|
|
58
|
-
}),
|
|
59
|
-
)
|
|
60
|
-
} else if (child.nodeName === 'kubb-arrow-function') {
|
|
61
|
-
const attrs = child.attributes
|
|
62
|
-
result.push(
|
|
63
|
-
createArrowFunction({
|
|
64
|
-
name: attrs.get('name') as string,
|
|
65
|
-
params: attrs.get('params') as string | undefined,
|
|
66
|
-
export: attrs.get('export') as boolean | undefined,
|
|
67
|
-
default: attrs.get('default') as boolean | undefined,
|
|
68
|
-
async: attrs.get('async') as boolean | undefined,
|
|
69
|
-
generics: attrs.get('generics') as string | undefined,
|
|
70
|
-
returnType: attrs.get('returnType') as string | undefined,
|
|
71
|
-
singleLine: attrs.get('singleLine') as boolean | undefined,
|
|
72
|
-
JSDoc: attrs.get('JSDoc') as JSDocNode | undefined,
|
|
73
|
-
nodes: collectChildNodes(child),
|
|
74
|
-
} as Omit<ArrowFunctionNode, 'kind'>),
|
|
75
|
-
)
|
|
76
|
-
} else if (child.nodeName === 'kubb-const') {
|
|
77
|
-
const attrs = child.attributes
|
|
78
|
-
result.push(
|
|
79
|
-
createConst({
|
|
80
|
-
name: attrs.get('name') as string,
|
|
81
|
-
type: attrs.get('type') as string | undefined,
|
|
82
|
-
export: attrs.get('export') as boolean | undefined,
|
|
83
|
-
asConst: attrs.get('asConst') as boolean | undefined,
|
|
84
|
-
JSDoc: attrs.get('JSDoc') as JSDocNode | undefined,
|
|
85
|
-
nodes: collectChildNodes(child),
|
|
86
|
-
}),
|
|
87
|
-
)
|
|
88
|
-
} else if (child.nodeName === 'kubb-type') {
|
|
89
|
-
const attrs = child.attributes
|
|
90
|
-
result.push(
|
|
91
|
-
createType({
|
|
92
|
-
name: attrs.get('name') as string,
|
|
93
|
-
export: attrs.get('export') as boolean | undefined,
|
|
94
|
-
JSDoc: attrs.get('JSDoc') as JSDocNode | undefined,
|
|
95
|
-
nodes: collectChildNodes(child),
|
|
96
|
-
}),
|
|
97
|
-
)
|
|
98
|
-
} else if (child.nodeName === 'kubb-jsx') {
|
|
99
|
-
const textChild = child.childNodes[0]
|
|
100
|
-
const value = textChild?.nodeName === TEXT_NODE_NAME ? (textChild as DOMNode<{ nodeName: '#text' }>).nodeValue : ''
|
|
101
|
-
if (value) {
|
|
102
|
-
result.push(createJsx(value))
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return result
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Traverse `node` and collect all `<kubb-source>` elements into a `Set<SourceNode>`.
|
|
112
|
-
*
|
|
113
|
-
* Elements whose `nodeName` is in `ignores` are skipped entirely (including their subtrees).
|
|
114
|
-
* This is used to collect source blocks from a file node while excluding import/export subtrees.
|
|
115
|
-
*
|
|
116
|
-
* @example Collect sources while ignoring export and import elements
|
|
117
|
-
* ```ts
|
|
118
|
-
* const sources = squashSourceNodes(fileElement, ['kubb-export', 'kubb-import'])
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
function squashSourceNodes(node: DOMElement, ignores: Array<ElementNames>): Set<SourceNode> {
|
|
122
|
-
const ignoreSet = new Set(ignores)
|
|
123
|
-
const sources = new Set<SourceNode>()
|
|
124
|
-
|
|
125
|
-
const walk = (current: DOMElement): void => {
|
|
126
|
-
for (const child of current.childNodes) {
|
|
127
|
-
if (!child) {
|
|
128
|
-
continue
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (child.nodeName !== TEXT_NODE_NAME && ignoreSet.has(child.nodeName)) {
|
|
132
|
-
continue
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (child.nodeName === 'kubb-source') {
|
|
136
|
-
const source = createSource({
|
|
137
|
-
name: child.attributes.get('name')?.toString(),
|
|
138
|
-
isTypeOnly: (child.attributes.get('isTypeOnly') ?? false) as boolean,
|
|
139
|
-
isExportable: (child.attributes.get('isExportable') ?? false) as boolean,
|
|
140
|
-
isIndexable: (child.attributes.get('isIndexable') ?? false) as boolean,
|
|
141
|
-
nodes: collectChildNodes(child),
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
sources.add(source)
|
|
145
|
-
continue
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (child.nodeName !== TEXT_NODE_NAME && nodeNames.has(child.nodeName)) {
|
|
149
|
-
walk(child)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
walk(node)
|
|
155
|
-
return sources
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Traverse `node` and collect all `<kubb-export>` elements into a `Set<ExportNode>`.
|
|
160
|
-
*/
|
|
161
|
-
function squashExportNodes(node: DOMElement): Set<ExportNode> {
|
|
162
|
-
const exports = new Set<ExportNode>()
|
|
163
|
-
|
|
164
|
-
const walk = (current: DOMElement): void => {
|
|
165
|
-
for (const child of current.childNodes) {
|
|
166
|
-
if (!child) {
|
|
167
|
-
continue
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (child.nodeName !== TEXT_NODE_NAME && nodeNames.has(child.nodeName)) {
|
|
171
|
-
walk(child)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (child.nodeName === 'kubb-export') {
|
|
175
|
-
exports.add(
|
|
176
|
-
createExport({
|
|
177
|
-
name: child.attributes.get('name') as ExportNode['name'],
|
|
178
|
-
path: child.attributes.get('path') as string,
|
|
179
|
-
isTypeOnly: (child.attributes.get('isTypeOnly') ?? false) as boolean,
|
|
180
|
-
asAlias: (child.attributes.get('asAlias') ?? false) as boolean,
|
|
181
|
-
}),
|
|
182
|
-
)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
walk(node)
|
|
188
|
-
return exports
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Traverse `node` and collect all `<kubb-import>` elements into a `Set<ImportNode>`.
|
|
193
|
-
*/
|
|
194
|
-
function squashImportNodes(node: DOMElement): Set<ImportNode> {
|
|
195
|
-
const imports = new Set<ImportNode>()
|
|
196
|
-
|
|
197
|
-
const walk = (current: DOMElement): void => {
|
|
198
|
-
for (const child of current.childNodes) {
|
|
199
|
-
if (!child) {
|
|
200
|
-
continue
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (child.nodeName !== TEXT_NODE_NAME && nodeNames.has(child.nodeName)) {
|
|
204
|
-
walk(child)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (child.nodeName === 'kubb-import') {
|
|
208
|
-
imports.add(
|
|
209
|
-
createImport({
|
|
210
|
-
name: child.attributes.get('name') as ImportNode['name'],
|
|
211
|
-
path: child.attributes.get('path') as string,
|
|
212
|
-
root: child.attributes.get('root') as string | undefined,
|
|
213
|
-
isTypeOnly: (child.attributes.get('isTypeOnly') ?? false) as boolean,
|
|
214
|
-
isNameSpace: (child.attributes.get('isNameSpace') ?? false) as boolean,
|
|
215
|
-
}),
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
walk(node)
|
|
222
|
-
return imports
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Walk the virtual DOM tree rooted at `node` and convert every `<kubb-file>` element
|
|
227
|
-
* into a {@link FileNode}, collecting its source blocks, imports, and exports.
|
|
228
|
-
*
|
|
229
|
-
* Returns the list of file nodes in document order. Nested files are supported —
|
|
230
|
-
* the walker descends into non-file elements and recurses through them.
|
|
231
|
-
*/
|
|
232
|
-
export function processFiles(node: DOMElement): Array<FileNode> {
|
|
233
|
-
const collected: Array<FileNode> = []
|
|
234
|
-
|
|
235
|
-
function walk(current: DOMElement) {
|
|
236
|
-
for (const child of current.childNodes) {
|
|
237
|
-
if (!child) {
|
|
238
|
-
continue
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (child.nodeName !== TEXT_NODE_NAME && child.nodeName !== 'kubb-file' && nodeNames.has(child.nodeName)) {
|
|
242
|
-
walk(child)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (child.nodeName === 'kubb-file') {
|
|
246
|
-
if (child.attributes.has('baseName') && child.attributes.has('path')) {
|
|
247
|
-
const sources = squashSourceNodes(child, ['kubb-export', 'kubb-import'])
|
|
248
|
-
|
|
249
|
-
collected.push({
|
|
250
|
-
baseName: child.attributes.get('baseName'),
|
|
251
|
-
path: child.attributes.get('path'),
|
|
252
|
-
meta: child.attributes.get('meta') || {},
|
|
253
|
-
footer: child.attributes.get('footer'),
|
|
254
|
-
banner: child.attributes.get('banner'),
|
|
255
|
-
sources: [...sources],
|
|
256
|
-
exports: [...squashExportNodes(child)],
|
|
257
|
-
imports: [...squashImportNodes(child)],
|
|
258
|
-
} as FileNode)
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
walk(node)
|
|
265
|
-
|
|
266
|
-
return collected
|
|
267
|
-
}
|