@kubb/react-fabric 0.0.0-canary-20251020201500
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 +21 -0
- package/README.md +52 -0
- package/dist/devtools.cjs +10817 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +1 -0
- package/dist/devtools.d.ts +1 -0
- package/dist/devtools.js +10817 -0
- package/dist/devtools.js.map +1 -0
- package/dist/globals-8sJ940pg.cjs +0 -0
- package/dist/globals-C6rGETh5.d.ts +166 -0
- package/dist/globals-CnATk-Sl.d.cts +166 -0
- package/dist/globals-Df5klKjG.js +1 -0
- package/dist/globals.cjs +1 -0
- package/dist/globals.d.cts +2 -0
- package/dist/globals.d.ts +2 -0
- package/dist/globals.js +3 -0
- package/dist/index.cjs +15924 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +331 -0
- package/dist/index.d.ts +331 -0
- package/dist/index.js +15899 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.cjs +9 -0
- package/dist/jsx-dev-runtime.d.cts +13 -0
- package/dist/jsx-dev-runtime.d.ts +13 -0
- package/dist/jsx-dev-runtime.js +6 -0
- package/dist/jsx-runtime-B3MMb3PL.cjs +233 -0
- package/dist/jsx-runtime-B3MMb3PL.cjs.map +1 -0
- package/dist/jsx-runtime-BPQkRAg2.js +228 -0
- package/dist/jsx-runtime-BPQkRAg2.js.map +1 -0
- package/dist/jsx-runtime-DmD5u6a-.js +13 -0
- package/dist/jsx-runtime-DmD5u6a-.js.map +1 -0
- package/dist/jsx-runtime-zKfRQHQD.cjs +36 -0
- package/dist/jsx-runtime-zKfRQHQD.cjs.map +1 -0
- package/dist/jsx-runtime.cjs +9 -0
- package/dist/jsx-runtime.js +6 -0
- package/dist/react-BBkwFtZV.js +1138 -0
- package/dist/react-BBkwFtZV.js.map +1 -0
- package/dist/react-Bq0UOw6S.cjs +1156 -0
- package/dist/react-Bq0UOw6S.cjs.map +1 -0
- package/dist/types-C3p0Ljxf.d.cts +85 -0
- package/dist/types-DEroxUW0.d.ts +85 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/package.json +115 -0
- package/src/ReactTemplate.tsx +229 -0
- package/src/components/App.tsx +27 -0
- package/src/components/Const.tsx +53 -0
- package/src/components/File.tsx +100 -0
- package/src/components/Function.tsx +139 -0
- package/src/components/Indent.tsx +53 -0
- package/src/components/Root.tsx +75 -0
- package/src/components/Type.tsx +40 -0
- package/src/createApp.ts +23 -0
- package/src/devtools.ts +118 -0
- package/src/dom.ts +75 -0
- package/src/globals.ts +52 -0
- package/src/hooks/useApp.ts +15 -0
- package/src/hooks/useFile.ts +14 -0
- package/src/hooks/useLifecycle.tsx +18 -0
- package/src/index.ts +24 -0
- package/src/jsx-runtime.ts +8 -0
- package/src/kubbRenderer.ts +175 -0
- package/src/types.ts +53 -0
- package/src/utils/createJSDoc.ts +9 -0
- package/src/utils/getFunctionParams.ts +236 -0
- package/src/utils/processFiles.ts +44 -0
- package/src/utils/squashExportNodes.ts +23 -0
- package/src/utils/squashImportNodes.ts +23 -0
- package/src/utils/squashSourceNodes.ts +40 -0
- package/src/utils/squashTextNodes.ts +82 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { orderBy } from 'natural-orderby'
|
|
2
|
+
|
|
3
|
+
export type Param = {
|
|
4
|
+
/**
|
|
5
|
+
* `object` will return the pathParams as an object.
|
|
6
|
+
*
|
|
7
|
+
* `inline` will return the pathParams as comma separated params.
|
|
8
|
+
* @default `'inline'`
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
mode?: 'object' | 'inline' | 'inlineSpread'
|
|
12
|
+
type?: 'string' | 'number' | (string & {})
|
|
13
|
+
optional?: boolean
|
|
14
|
+
/**
|
|
15
|
+
* @example test = "default"
|
|
16
|
+
*/
|
|
17
|
+
default?: string
|
|
18
|
+
/**
|
|
19
|
+
* Used for no TypeScript(with mode object)
|
|
20
|
+
* @example test: "default"
|
|
21
|
+
*/
|
|
22
|
+
value?: string
|
|
23
|
+
children?: Params
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type ParamItem =
|
|
27
|
+
| (Pick<Param, 'mode' | 'type' | 'value'> & {
|
|
28
|
+
optional?: true
|
|
29
|
+
default?: never
|
|
30
|
+
children?: Params
|
|
31
|
+
})
|
|
32
|
+
| (Pick<Param, 'mode' | 'type' | 'value'> & {
|
|
33
|
+
optional?: false
|
|
34
|
+
default?: string
|
|
35
|
+
children?: Params
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export type Params = Record<string, Param | undefined>
|
|
39
|
+
|
|
40
|
+
type Options = {
|
|
41
|
+
type: 'constructor' | 'call' | 'object' | 'objectValue'
|
|
42
|
+
transformName?: (name: string) => string
|
|
43
|
+
transformType?: (type: string) => string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function order(items: Array<[key: string, item?: ParamItem]>) {
|
|
47
|
+
return orderBy(
|
|
48
|
+
items.filter(Boolean),
|
|
49
|
+
[
|
|
50
|
+
([_key, item]) => {
|
|
51
|
+
if (item?.children) {
|
|
52
|
+
return undefined
|
|
53
|
+
}
|
|
54
|
+
return !item?.default
|
|
55
|
+
},
|
|
56
|
+
([_key, item]) => {
|
|
57
|
+
if (item?.children) {
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
60
|
+
return !item?.optional
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
['desc', 'desc'],
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseChild(key: string, item: ParamItem, options: Options): string | null {
|
|
68
|
+
// @ts-expect-error
|
|
69
|
+
const entries = order(Object.entries(item.children))
|
|
70
|
+
|
|
71
|
+
const types: string[] = []
|
|
72
|
+
const names: string[] = []
|
|
73
|
+
|
|
74
|
+
const optional = entries.every(([_key, item]) => item?.optional)
|
|
75
|
+
|
|
76
|
+
entries.forEach(([key, entryItem]) => {
|
|
77
|
+
if (entryItem) {
|
|
78
|
+
const name = parseItem(key, { ...entryItem, type: undefined }, options)
|
|
79
|
+
if (entryItem.children) {
|
|
80
|
+
const subTypes = Object.entries(entryItem.children)
|
|
81
|
+
.map(([key]) => {
|
|
82
|
+
return key
|
|
83
|
+
})
|
|
84
|
+
.join(', ')
|
|
85
|
+
|
|
86
|
+
if (subTypes) {
|
|
87
|
+
names.push(`${name}: { ${subTypes} }`)
|
|
88
|
+
} else {
|
|
89
|
+
names.push(name)
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
if (options.type === 'call' && options.transformName) {
|
|
93
|
+
names.push(`${key}: ${name}`)
|
|
94
|
+
} else {
|
|
95
|
+
names.push(name)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (entries.some(([_key, item]) => item?.type)) {
|
|
100
|
+
types.push(parseItem(key, { ...entryItem, default: undefined }, options))
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const name = item.mode === 'inline' ? key : names.length ? `{ ${names.join(', ')} }` : undefined
|
|
106
|
+
const type = item.type ? item.type : types.length ? `{ ${types.join('; ')} }` : undefined
|
|
107
|
+
|
|
108
|
+
if (!name) {
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return parseItem(
|
|
113
|
+
name,
|
|
114
|
+
{
|
|
115
|
+
type,
|
|
116
|
+
default: item.default,
|
|
117
|
+
optional: !item.default ? optional : undefined,
|
|
118
|
+
} as ParamItem,
|
|
119
|
+
options,
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseItem(name: string, item: ParamItem, options: Options): string {
|
|
124
|
+
const acc: string[] = []
|
|
125
|
+
const transformedName = options.transformName ? options.transformName(name) : name
|
|
126
|
+
const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type
|
|
127
|
+
|
|
128
|
+
if (options.type === 'object') {
|
|
129
|
+
return transformedName
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (options.type === 'objectValue') {
|
|
133
|
+
return item.value ? `${transformedName}: ${item.value}` : transformedName
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//LEGACY
|
|
137
|
+
if (item.type && options.type === 'constructor') {
|
|
138
|
+
if (item.optional) {
|
|
139
|
+
acc.push(`${transformedName}?: ${transformedType}`)
|
|
140
|
+
} else {
|
|
141
|
+
acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ''}`)
|
|
142
|
+
}
|
|
143
|
+
} else if (item.default && options.type === 'constructor') {
|
|
144
|
+
acc.push(`${transformedName} = ${item.default}`)
|
|
145
|
+
} else if (item.value) {
|
|
146
|
+
acc.push(`${transformedName} : ${item.value}`)
|
|
147
|
+
} else if (item.mode === 'inlineSpread') {
|
|
148
|
+
acc.push(`... ${transformedName}`)
|
|
149
|
+
} else {
|
|
150
|
+
acc.push(transformedName)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return acc[0] as string
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function getFunctionParams(params: Params, options: Options): string {
|
|
157
|
+
const entries = order(Object.entries(params as Record<string, ParamItem | undefined>))
|
|
158
|
+
|
|
159
|
+
return entries
|
|
160
|
+
.reduce((acc, [key, item]) => {
|
|
161
|
+
if (!item) {
|
|
162
|
+
return acc
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (item.children) {
|
|
166
|
+
if (Object.keys(item.children).length === 0) {
|
|
167
|
+
return acc
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (item.mode === 'inlineSpread') {
|
|
171
|
+
return [...acc, getFunctionParams(item.children, options)]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const parsedItem = parseChild(key, item, options)
|
|
175
|
+
if (!parsedItem) {
|
|
176
|
+
return acc
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return [...acc, parsedItem]
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const parsedItem = parseItem(key, item, options)
|
|
183
|
+
|
|
184
|
+
return [...acc, parsedItem]
|
|
185
|
+
}, [] as string[])
|
|
186
|
+
.join(', ')
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function createFunctionParams(params: Params): Params {
|
|
190
|
+
return params
|
|
191
|
+
}
|
|
192
|
+
// TODO use of zod
|
|
193
|
+
//TODO use of string as `$name: $type` to create templates for functions instead of call/constructor
|
|
194
|
+
export class FunctionParams {
|
|
195
|
+
#params: Params
|
|
196
|
+
|
|
197
|
+
static factory(params: Params) {
|
|
198
|
+
return new FunctionParams(params)
|
|
199
|
+
}
|
|
200
|
+
constructor(params: Params) {
|
|
201
|
+
this.#params = params
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
get params(): Params {
|
|
205
|
+
return this.#params
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
get flatParams(): Params {
|
|
209
|
+
const flatter = (acc: Params, [key, item]: [key: string, item?: Param]): Params => {
|
|
210
|
+
if (item?.children) {
|
|
211
|
+
return Object.entries(item.children).reduce(flatter, acc)
|
|
212
|
+
}
|
|
213
|
+
if (item) {
|
|
214
|
+
acc[key] = item
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return acc
|
|
218
|
+
}
|
|
219
|
+
return Object.entries(this.#params).reduce(flatter, {} as Params)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
toCall({ transformName, transformType }: Pick<Options, 'transformName' | 'transformType'> = {}): string {
|
|
223
|
+
return getFunctionParams(this.#params, { type: 'call', transformName, transformType })
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
toObject(): string {
|
|
227
|
+
return getFunctionParams(this.#params, { type: 'object' })
|
|
228
|
+
}
|
|
229
|
+
toObjectValue(): string {
|
|
230
|
+
return getFunctionParams(this.#params, { type: 'objectValue' })
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
toConstructor(): string {
|
|
234
|
+
return getFunctionParams(this.#params, { type: 'constructor' })
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { nodeNames } from '../dom.ts'
|
|
2
|
+
import { squashExportNodes } from './squashExportNodes.ts'
|
|
3
|
+
import { squashImportNodes } from './squashImportNodes.ts'
|
|
4
|
+
import { squashSourceNodes } from './squashSourceNodes.ts'
|
|
5
|
+
|
|
6
|
+
import type { AppContext, KubbFile } from '@kubb/fabric-core'
|
|
7
|
+
import type React from 'react'
|
|
8
|
+
import type { File } from '../components/File.tsx'
|
|
9
|
+
import type { DOMElement } from '../types.ts'
|
|
10
|
+
|
|
11
|
+
export function processFiles(node: DOMElement, context: AppContext) {
|
|
12
|
+
for (let index = 0; index < node.childNodes.length; index++) {
|
|
13
|
+
const childNode = node.childNodes[index]
|
|
14
|
+
|
|
15
|
+
if (!childNode) {
|
|
16
|
+
continue
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (childNode.nodeName !== '#text' && childNode.nodeName !== 'kubb-file' && nodeNames.includes(childNode.nodeName)) {
|
|
20
|
+
processFiles(childNode, context)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (childNode.nodeName === 'kubb-file') {
|
|
24
|
+
const attributes = childNode.attributes as React.ComponentProps<typeof File>
|
|
25
|
+
|
|
26
|
+
if (attributes.baseName && attributes.path) {
|
|
27
|
+
const sources = squashSourceNodes(childNode, ['kubb-export', 'kubb-import'])
|
|
28
|
+
|
|
29
|
+
const file: KubbFile.File = {
|
|
30
|
+
baseName: attributes.baseName,
|
|
31
|
+
path: attributes.path,
|
|
32
|
+
sources: [...sources],
|
|
33
|
+
exports: [...squashExportNodes(childNode)],
|
|
34
|
+
imports: [...squashImportNodes(childNode)],
|
|
35
|
+
meta: attributes.meta || {},
|
|
36
|
+
footer: attributes.footer,
|
|
37
|
+
banner: attributes.banner,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
context.addFile(file)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { nodeNames } from '../dom.ts'
|
|
2
|
+
|
|
3
|
+
import type { KubbFile } from '@kubb/fabric-core'
|
|
4
|
+
import type React from 'react'
|
|
5
|
+
import type { File } from '../components/File.tsx'
|
|
6
|
+
import type { DOMElement } from '../types.ts'
|
|
7
|
+
|
|
8
|
+
export function squashExportNodes(node: DOMElement): Set<KubbFile.ResolvedExport> {
|
|
9
|
+
let exports = new Set<KubbFile.Export>()
|
|
10
|
+
|
|
11
|
+
node.childNodes.filter(Boolean).forEach((childNode) => {
|
|
12
|
+
if (childNode.nodeName !== '#text' && nodeNames.includes(childNode.nodeName)) {
|
|
13
|
+
exports = new Set([...exports, ...squashExportNodes(childNode)])
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (childNode.nodeName === 'kubb-export') {
|
|
17
|
+
const attributes = childNode.attributes as React.ComponentProps<typeof File.Export>
|
|
18
|
+
exports.add(attributes)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return exports
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { nodeNames } from '../dom.ts'
|
|
2
|
+
|
|
3
|
+
import type { KubbFile } from '@kubb/fabric-core'
|
|
4
|
+
import type React from 'react'
|
|
5
|
+
import type { File } from '../components/File.tsx'
|
|
6
|
+
import type { DOMElement } from '../types.ts'
|
|
7
|
+
|
|
8
|
+
export function squashImportNodes(node: DOMElement): Set<KubbFile.Import> {
|
|
9
|
+
let imports = new Set<KubbFile.Import>()
|
|
10
|
+
|
|
11
|
+
node.childNodes.filter(Boolean).forEach((childNode) => {
|
|
12
|
+
if (childNode.nodeName !== '#text' && nodeNames.includes(childNode.nodeName)) {
|
|
13
|
+
imports = new Set([...imports, ...squashImportNodes(childNode)])
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (childNode.nodeName === 'kubb-import') {
|
|
17
|
+
const attributes = childNode.attributes as React.ComponentProps<typeof File.Import>
|
|
18
|
+
imports.add(attributes)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return imports
|
|
23
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { nodeNames } from '../dom.ts'
|
|
2
|
+
|
|
3
|
+
import type { KubbFile } from '@kubb/fabric-core'
|
|
4
|
+
import type React from 'react'
|
|
5
|
+
import type { File } from '../components/File.tsx'
|
|
6
|
+
import type { DOMElement, ElementNames } from '../types.ts'
|
|
7
|
+
import { squashTextNodes } from './squashTextNodes.ts'
|
|
8
|
+
|
|
9
|
+
export function squashSourceNodes(node: DOMElement, ignores: Array<ElementNames>): Set<KubbFile.Source> {
|
|
10
|
+
let sources = new Set<KubbFile.Source>()
|
|
11
|
+
|
|
12
|
+
for (const childNode of node.childNodes) {
|
|
13
|
+
if (!childNode) {
|
|
14
|
+
continue
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (childNode.nodeName !== '#text' && ignores.includes(childNode.nodeName)) {
|
|
18
|
+
continue
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (childNode.nodeName === 'kubb-source') {
|
|
22
|
+
const attributes = childNode.attributes as React.ComponentProps<typeof File.Source>
|
|
23
|
+
const value = squashTextNodes(childNode)
|
|
24
|
+
|
|
25
|
+
sources.add({
|
|
26
|
+
...attributes,
|
|
27
|
+
// remove end enter
|
|
28
|
+
value: value.trim().replace(/^\s+|\s+$/g, ''),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (childNode.nodeName !== '#text' && nodeNames.includes(childNode.nodeName)) {
|
|
35
|
+
sources = new Set([...sources, ...squashSourceNodes(childNode, ignores)])
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return sources
|
|
40
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createImport, createExport, print } from '@kubb/fabric-core/parsers/typescript'
|
|
2
|
+
|
|
3
|
+
import type { File } from '../components/File.tsx'
|
|
4
|
+
import { nodeNames } from '../dom.ts'
|
|
5
|
+
import type { DOMElement } from '../types.ts'
|
|
6
|
+
|
|
7
|
+
export function squashTextNodes(node: DOMElement): string {
|
|
8
|
+
let text = ''
|
|
9
|
+
|
|
10
|
+
for (const childNode of node.childNodes) {
|
|
11
|
+
if (!childNode) {
|
|
12
|
+
continue
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let nodeText = ''
|
|
16
|
+
|
|
17
|
+
const getPrintText = (text: string): string => {
|
|
18
|
+
if (childNode.nodeName === 'kubb-import') {
|
|
19
|
+
const attributes = childNode.attributes as React.ComponentProps<typeof File.Import>
|
|
20
|
+
|
|
21
|
+
return print([
|
|
22
|
+
createImport({
|
|
23
|
+
name: attributes.name,
|
|
24
|
+
path: attributes.path,
|
|
25
|
+
root: attributes.root,
|
|
26
|
+
isTypeOnly: attributes.isTypeOnly,
|
|
27
|
+
}),
|
|
28
|
+
])
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (childNode.nodeName === 'kubb-export') {
|
|
32
|
+
const attributes = childNode.attributes as React.ComponentProps<typeof File.Export>
|
|
33
|
+
if (attributes.path) {
|
|
34
|
+
return print([
|
|
35
|
+
createExport({
|
|
36
|
+
name: attributes.name,
|
|
37
|
+
path: attributes.path,
|
|
38
|
+
isTypeOnly: attributes.isTypeOnly,
|
|
39
|
+
asAlias: attributes.asAlias,
|
|
40
|
+
}),
|
|
41
|
+
])
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (childNode.nodeName === 'kubb-source') {
|
|
46
|
+
return text
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return text
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (childNode.nodeName === '#text') {
|
|
53
|
+
nodeText = childNode.nodeValue
|
|
54
|
+
} else {
|
|
55
|
+
if (['kubb-text', 'kubb-file', 'kubb-source'].includes(childNode.nodeName)) {
|
|
56
|
+
nodeText = squashTextNodes(childNode)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
nodeText = getPrintText(nodeText)
|
|
60
|
+
|
|
61
|
+
if (childNode.nodeName === 'br') {
|
|
62
|
+
nodeText = '\n'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// no kubb element or br
|
|
66
|
+
if (![...nodeNames, 'br'].includes(childNode.nodeName)) {
|
|
67
|
+
const attributes = Object.entries(childNode.attributes).reduce((acc, [key, value]) => {
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
return `${acc} ${key}="${value}"`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return `${acc} ${key}={${value}}`
|
|
73
|
+
}, '')
|
|
74
|
+
nodeText = `<${childNode.nodeName}${attributes}>${squashTextNodes(childNode)}</${childNode.nodeName}>`
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
text += nodeText
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return text
|
|
82
|
+
}
|