@teleporthq/teleport-plugin-html-base-component 0.35.0-alpha.0 → 0.36.0-alpha.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.
@@ -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
- externals: Record<string, ComponentUIDL>,
34
+ subComponentOptions: {
35
+ externals: Record<string, ComponentUIDL>
36
+ plugins: ComponentPlugin[]
37
+ },
33
38
  routeDefinitions: UIDLRouteDefinitions,
34
39
  structure: {
35
40
  chunks: ChunkDefinition[]
@@ -43,7 +48,7 @@ export const generateHtmlSynatx: NodeToHTML<UIDLNode, Promise<HastNode | HastTex
43
48
  templatesLookUp,
44
49
  propDefinitions,
45
50
  stateDefinitions,
46
- externals,
51
+ subComponentOptions,
47
52
  routeDefinitions,
48
53
  structure
49
54
  ) => {
@@ -64,7 +69,7 @@ export const generateHtmlSynatx: NodeToHTML<UIDLNode, Promise<HastNode | HastTex
64
69
  templatesLookUp,
65
70
  propDefinitions,
66
71
  stateDefinitions,
67
- externals,
72
+ subComponentOptions,
68
73
  routeDefinitions,
69
74
  structure
70
75
  )
@@ -75,7 +80,7 @@ export const generateHtmlSynatx: NodeToHTML<UIDLNode, Promise<HastNode | HastTex
75
80
  templatesLookUp,
76
81
  propDefinitions,
77
82
  stateDefinitions,
78
- externals,
83
+ subComponentOptions,
79
84
  routeDefinitions,
80
85
  structure
81
86
  )
@@ -96,7 +101,7 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
96
101
  templatesLookUp,
97
102
  propDefinitions,
98
103
  stateDefinitions,
99
- externals,
104
+ subComponentOptions,
100
105
  routeDefinitions,
101
106
  structure
102
107
  ) => {
@@ -123,7 +128,7 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
123
128
  node,
124
129
  propDefinitions,
125
130
  stateDefinitions,
126
- externals,
131
+ subComponentOptions,
127
132
  routeDefinitions,
128
133
  structure
129
134
  )
@@ -137,7 +142,7 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
137
142
  templatesLookUp,
138
143
  propDefinitions,
139
144
  stateDefinitions,
140
- externals,
145
+ subComponentOptions,
141
146
  routeDefinitions,
142
147
  structure
143
148
  )
@@ -179,7 +184,10 @@ const generateComponentContent = async (
179
184
  node: UIDLElementNode,
180
185
  propDefinitions: Record<string, UIDLPropDefinition>,
181
186
  stateDefinitions: Record<string, UIDLStateDefinition>,
182
- externals: Record<string, ComponentUIDL>,
187
+ subComponentOptions: {
188
+ externals: Record<string, ComponentUIDL>
189
+ plugins: ComponentPlugin[]
190
+ },
183
191
  routeDefinitions: UIDLRouteDefinitions,
184
192
  structure: {
185
193
  chunks: ChunkDefinition[]
@@ -187,8 +195,9 @@ const generateComponentContent = async (
187
195
  options: GeneratorOptions
188
196
  }
189
197
  ) => {
198
+ const { externals, plugins } = subComponentOptions
190
199
  const { elementType, attrs = {}, key, children = [] } = node.content
191
- const { dependencies, chunks, options } = structure
200
+ const { dependencies, chunks = [], options } = structure
192
201
  const comp = UIDLUtils.cloneObject(externals[elementType] || {}) as ComponentUIDL
193
202
  const lookUpTemplates: Record<string, unknown> = {}
194
203
  let compHasSlots: boolean = false
@@ -284,21 +293,21 @@ const generateComponentContent = async (
284
293
  lookUpTemplates,
285
294
  propsForInstance,
286
295
  statesForInstance,
287
- externals,
296
+ subComponentOptions,
288
297
  routeDefinitions,
289
298
  structure
290
299
  )) as unknown as HastNode
291
300
 
292
301
  const cssPlugin = createCSSPlugin({
293
302
  templateStyle: 'html',
294
- templateChunkName: 'html-template',
303
+ templateChunkName: DEFAULT_COMPONENT_CHUNK_NAME,
295
304
  declareDependency: 'import',
296
305
  forceScoping: true,
297
306
  chunkName: comp.name,
298
307
  staticPropReferences: true,
299
308
  })
300
309
 
301
- const result = await cssPlugin({
310
+ const initialStructure: ComponentStructure = {
302
311
  uidl: {
303
312
  ...comp,
304
313
  propDefinitions: propsForInstance,
@@ -318,7 +327,15 @@ const generateComponentContent = async (
318
327
  ],
319
328
  dependencies,
320
329
  options,
321
- })
330
+ }
331
+
332
+ const result = await [cssPlugin, ...plugins].reduce(
333
+ async (previousPluginOperation: Promise<ComponentStructure>, plugin) => {
334
+ const modifiedStructure = await previousPluginOperation
335
+ return plugin(modifiedStructure)
336
+ },
337
+ Promise.resolve(initialStructure)
338
+ )
322
339
 
323
340
  if (compHasSlots) {
324
341
  result.chunks.forEach((chunk) => {
@@ -329,7 +346,12 @@ const generateComponentContent = async (
329
346
  } else {
330
347
  const chunk = chunks.find((item) => item.name === comp.name)
331
348
  if (!chunk) {
332
- const styleChunk = result.chunks.find((item: ChunkDefinition) => item.name === comp.name)
349
+ const styleChunk = result.chunks.find(
350
+ (item: ChunkDefinition) => item.fileType === FileType.CSS
351
+ )
352
+ if (!styleChunk) {
353
+ return
354
+ }
333
355
  chunks.push(styleChunk)
334
356
  }
335
357
  }