@teleporthq/teleport-plugin-html-base-component 0.29.0-alpha.0 → 0.29.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/__tests__/index.ts +1 -1
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +21 -15
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node-handlers.d.ts +5 -2
- package/dist/cjs/node-handlers.d.ts.map +1 -1
- package/dist/cjs/node-handlers.js +54 -38
- package/dist/cjs/node-handlers.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +21 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node-handlers.d.ts +5 -2
- package/dist/esm/node-handlers.d.ts.map +1 -1
- package/dist/esm/node-handlers.js +54 -38
- package/dist/esm/node-handlers.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/constants.ts +1 -1
- package/src/index.ts +21 -10
- package/src/node-handlers.ts +40 -20
package/src/node-handlers.ts
CHANGED
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
UIDLStyleValue,
|
|
18
18
|
GeneratorOptions,
|
|
19
19
|
UIDLRouteDefinitions,
|
|
20
|
+
ComponentPlugin,
|
|
21
|
+
ComponentStructure,
|
|
20
22
|
} from '@teleporthq/teleport-types'
|
|
21
23
|
import { HASTBuilders, HASTUtils } from '@teleporthq/teleport-plugin-common'
|
|
22
24
|
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared'
|
|
@@ -29,7 +31,10 @@ type NodeToHTML<NodeType, ReturnType> = (
|
|
|
29
31
|
templatesLookUp: Record<string, unknown>,
|
|
30
32
|
propDefinitions: Record<string, UIDLPropDefinition>,
|
|
31
33
|
stateDefinitions: Record<string, UIDLStateDefinition>,
|
|
32
|
-
|
|
34
|
+
subComponentOptions: {
|
|
35
|
+
externals: Record<string, ComponentUIDL>
|
|
36
|
+
plugins: ComponentPlugin[]
|
|
37
|
+
},
|
|
33
38
|
routeDefinitions: UIDLRouteDefinitions,
|
|
34
39
|
structure: {
|
|
35
40
|
chunks: ChunkDefinition[]
|
|
@@ -43,11 +48,12 @@ export const generateHtmlSynatx: NodeToHTML<UIDLNode, Promise<HastNode | HastTex
|
|
|
43
48
|
templatesLookUp,
|
|
44
49
|
propDefinitions,
|
|
45
50
|
stateDefinitions,
|
|
46
|
-
|
|
51
|
+
subComponentOptions,
|
|
47
52
|
routeDefinitions,
|
|
48
53
|
structure
|
|
49
54
|
) => {
|
|
50
55
|
switch (node.type) {
|
|
56
|
+
case 'inject':
|
|
51
57
|
case 'raw':
|
|
52
58
|
return HASTBuilders.createTextNode(node.content.toString())
|
|
53
59
|
|
|
@@ -63,7 +69,7 @@ export const generateHtmlSynatx: NodeToHTML<UIDLNode, Promise<HastNode | HastTex
|
|
|
63
69
|
templatesLookUp,
|
|
64
70
|
propDefinitions,
|
|
65
71
|
stateDefinitions,
|
|
66
|
-
|
|
72
|
+
subComponentOptions,
|
|
67
73
|
routeDefinitions,
|
|
68
74
|
structure
|
|
69
75
|
)
|
|
@@ -74,7 +80,7 @@ export const generateHtmlSynatx: NodeToHTML<UIDLNode, Promise<HastNode | HastTex
|
|
|
74
80
|
templatesLookUp,
|
|
75
81
|
propDefinitions,
|
|
76
82
|
stateDefinitions,
|
|
77
|
-
|
|
83
|
+
subComponentOptions,
|
|
78
84
|
routeDefinitions,
|
|
79
85
|
structure
|
|
80
86
|
)
|
|
@@ -95,7 +101,7 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
|
|
|
95
101
|
templatesLookUp,
|
|
96
102
|
propDefinitions,
|
|
97
103
|
stateDefinitions,
|
|
98
|
-
|
|
104
|
+
subComponentOptions,
|
|
99
105
|
routeDefinitions,
|
|
100
106
|
structure
|
|
101
107
|
) => {
|
|
@@ -108,7 +114,6 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
|
|
|
108
114
|
dependency,
|
|
109
115
|
key,
|
|
110
116
|
} = node.content
|
|
111
|
-
|
|
112
117
|
const elementNode = HASTBuilders.createHTMLNode(elementType)
|
|
113
118
|
templatesLookUp[key] = elementNode
|
|
114
119
|
|
|
@@ -122,7 +127,7 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
|
|
|
122
127
|
node,
|
|
123
128
|
propDefinitions,
|
|
124
129
|
stateDefinitions,
|
|
125
|
-
|
|
130
|
+
subComponentOptions,
|
|
126
131
|
routeDefinitions,
|
|
127
132
|
structure
|
|
128
133
|
)
|
|
@@ -136,7 +141,7 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
|
|
|
136
141
|
templatesLookUp,
|
|
137
142
|
propDefinitions,
|
|
138
143
|
stateDefinitions,
|
|
139
|
-
|
|
144
|
+
subComponentOptions,
|
|
140
145
|
routeDefinitions,
|
|
141
146
|
structure
|
|
142
147
|
)
|
|
@@ -178,7 +183,10 @@ const generateComponentContent = async (
|
|
|
178
183
|
node: UIDLElementNode,
|
|
179
184
|
propDefinitions: Record<string, UIDLPropDefinition>,
|
|
180
185
|
stateDefinitions: Record<string, UIDLStateDefinition>,
|
|
181
|
-
|
|
186
|
+
subComponentOptions: {
|
|
187
|
+
externals: Record<string, ComponentUIDL>
|
|
188
|
+
plugins: ComponentPlugin[]
|
|
189
|
+
},
|
|
182
190
|
routeDefinitions: UIDLRouteDefinitions,
|
|
183
191
|
structure: {
|
|
184
192
|
chunks: ChunkDefinition[]
|
|
@@ -186,8 +194,9 @@ const generateComponentContent = async (
|
|
|
186
194
|
options: GeneratorOptions
|
|
187
195
|
}
|
|
188
196
|
) => {
|
|
197
|
+
const { externals, plugins } = subComponentOptions
|
|
189
198
|
const { elementType, attrs = {}, key, children = [] } = node.content
|
|
190
|
-
const { dependencies, chunks, options } = structure
|
|
199
|
+
const { dependencies, chunks = [], options } = structure
|
|
191
200
|
const comp = UIDLUtils.cloneObject(externals[elementType] || {}) as ComponentUIDL
|
|
192
201
|
const lookUpTemplates: Record<string, unknown> = {}
|
|
193
202
|
let compHasSlots: boolean = false
|
|
@@ -229,7 +238,6 @@ const generateComponentContent = async (
|
|
|
229
238
|
}
|
|
230
239
|
|
|
231
240
|
const combinedProps = { ...propDefinitions, ...(comp?.propDefinitions || {}) }
|
|
232
|
-
|
|
233
241
|
const propsForInstance = Object.keys(combinedProps).reduce(
|
|
234
242
|
(acc: Record<string, UIDLPropDefinition>, propKey) => {
|
|
235
243
|
if (attrs[propKey]) {
|
|
@@ -262,7 +270,6 @@ const generateComponentContent = async (
|
|
|
262
270
|
},
|
|
263
271
|
{}
|
|
264
272
|
)
|
|
265
|
-
|
|
266
273
|
const elementNode = HASTBuilders.createHTMLNode(StringUtils.camelCaseToDashCase(elementType))
|
|
267
274
|
lookUpTemplates[key] = elementNode
|
|
268
275
|
|
|
@@ -283,21 +290,21 @@ const generateComponentContent = async (
|
|
|
283
290
|
lookUpTemplates,
|
|
284
291
|
propsForInstance,
|
|
285
292
|
statesForInstance,
|
|
286
|
-
|
|
293
|
+
subComponentOptions,
|
|
287
294
|
routeDefinitions,
|
|
288
295
|
structure
|
|
289
296
|
)) as unknown as HastNode
|
|
290
297
|
|
|
291
298
|
const cssPlugin = createCSSPlugin({
|
|
292
299
|
templateStyle: 'html',
|
|
293
|
-
templateChunkName:
|
|
300
|
+
templateChunkName: DEFAULT_COMPONENT_CHUNK_NAME,
|
|
294
301
|
declareDependency: 'import',
|
|
295
302
|
forceScoping: true,
|
|
296
303
|
chunkName: comp.name,
|
|
297
304
|
staticPropReferences: true,
|
|
298
305
|
})
|
|
299
306
|
|
|
300
|
-
const
|
|
307
|
+
const initialStructure: ComponentStructure = {
|
|
301
308
|
uidl: {
|
|
302
309
|
...comp,
|
|
303
310
|
propDefinitions: propsForInstance,
|
|
@@ -317,7 +324,15 @@ const generateComponentContent = async (
|
|
|
317
324
|
],
|
|
318
325
|
dependencies,
|
|
319
326
|
options,
|
|
320
|
-
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const result = await [cssPlugin, ...plugins].reduce(
|
|
330
|
+
async (previousPluginOperation: Promise<ComponentStructure>, plugin) => {
|
|
331
|
+
const modifiedStructure = await previousPluginOperation
|
|
332
|
+
return plugin(modifiedStructure)
|
|
333
|
+
},
|
|
334
|
+
Promise.resolve(initialStructure)
|
|
335
|
+
)
|
|
321
336
|
|
|
322
337
|
if (compHasSlots) {
|
|
323
338
|
result.chunks.forEach((chunk) => {
|
|
@@ -328,7 +343,12 @@ const generateComponentContent = async (
|
|
|
328
343
|
} else {
|
|
329
344
|
const chunk = chunks.find((item) => item.name === comp.name)
|
|
330
345
|
if (!chunk) {
|
|
331
|
-
const styleChunk = result.chunks.find(
|
|
346
|
+
const styleChunk = result.chunks.find(
|
|
347
|
+
(item: ChunkDefinition) => item.fileType === FileType.CSS
|
|
348
|
+
)
|
|
349
|
+
if (!styleChunk) {
|
|
350
|
+
return
|
|
351
|
+
}
|
|
332
352
|
chunks.push(styleChunk)
|
|
333
353
|
}
|
|
334
354
|
}
|
|
@@ -409,7 +429,7 @@ const handleAttributes = (
|
|
|
409
429
|
}
|
|
410
430
|
|
|
411
431
|
if (attrValue.type === 'raw') {
|
|
412
|
-
HASTUtils.addAttributeToNode(htmlNode, attrKey,
|
|
432
|
+
HASTUtils.addAttributeToNode(htmlNode, attrKey, attrValue.content)
|
|
413
433
|
return
|
|
414
434
|
}
|
|
415
435
|
|
|
@@ -427,7 +447,7 @@ const getValueFromReference = (
|
|
|
427
447
|
key: string,
|
|
428
448
|
definitions: Record<string, UIDLPropDefinition>
|
|
429
449
|
): string => {
|
|
430
|
-
const usedReferenceValue = definitions[key]
|
|
450
|
+
const usedReferenceValue = definitions[key.includes('.') ? key.split('.')[0] : key]
|
|
431
451
|
|
|
432
452
|
if (!usedReferenceValue) {
|
|
433
453
|
throw new HTMLComponentGeneratorError(
|
|
@@ -445,7 +465,7 @@ const getValueFromReference = (
|
|
|
445
465
|
)
|
|
446
466
|
}
|
|
447
467
|
|
|
448
|
-
if (!['string', 'number'].includes(usedReferenceValue?.type)) {
|
|
468
|
+
if (!['string', 'number', 'object'].includes(usedReferenceValue?.type)) {
|
|
449
469
|
throw new HTMLComponentGeneratorError(
|
|
450
470
|
`Attribute is using dynamic value, but received of type ${JSON.stringify(
|
|
451
471
|
usedReferenceValue,
|