@teleporthq/teleport-shared 0.41.0 → 0.42.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__/utils/string-utils.ts +3 -0
- package/__tests__/utils/uidl-utils.ts +59 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/utils/generic.d.ts +3 -0
- package/dist/cjs/utils/generic.d.ts.map +1 -1
- package/dist/cjs/utils/generic.js +46 -1
- package/dist/cjs/utils/generic.js.map +1 -1
- package/dist/cjs/utils/string-utils.d.ts.map +1 -1
- package/dist/cjs/utils/string-utils.js +1 -1
- package/dist/cjs/utils/string-utils.js.map +1 -1
- package/dist/cjs/utils/uidl-utils.d.ts +1 -0
- package/dist/cjs/utils/uidl-utils.d.ts.map +1 -1
- package/dist/cjs/utils/uidl-utils.js +391 -33
- package/dist/cjs/utils/uidl-utils.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils/generic.d.ts +3 -0
- package/dist/esm/utils/generic.d.ts.map +1 -1
- package/dist/esm/utils/generic.js +43 -0
- package/dist/esm/utils/generic.js.map +1 -1
- package/dist/esm/utils/string-utils.d.ts.map +1 -1
- package/dist/esm/utils/string-utils.js +1 -1
- package/dist/esm/utils/string-utils.js.map +1 -1
- package/dist/esm/utils/uidl-utils.d.ts +1 -0
- package/dist/esm/utils/uidl-utils.d.ts.map +1 -1
- package/dist/esm/utils/uidl-utils.js +389 -32
- package/dist/esm/utils/uidl-utils.js.map +1 -1
- package/package.json +3 -3
- package/src/utils/generic.ts +55 -0
- package/src/utils/string-utils.ts +1 -1
- package/src/utils/uidl-utils.ts +446 -44
package/src/utils/uidl-utils.ts
CHANGED
|
@@ -32,7 +32,10 @@ export const extractRoutes = (rootComponent: UIDLRootComponent) => {
|
|
|
32
32
|
|
|
33
33
|
// Look for conditional nodes in the first level children of the root element
|
|
34
34
|
return rootElement.children.filter(
|
|
35
|
-
(child) =>
|
|
35
|
+
(child) =>
|
|
36
|
+
child.type === 'conditional' &&
|
|
37
|
+
child.content.reference.type === 'dynamic' &&
|
|
38
|
+
child.content.reference.content.id === 'route'
|
|
36
39
|
) as UIDLConditionalNode[]
|
|
37
40
|
}
|
|
38
41
|
|
|
@@ -143,6 +146,10 @@ export const prefixAssetsPath = (
|
|
|
143
146
|
const assetName = basename(originalString)
|
|
144
147
|
const decodedAssetName = decodeURIComponent(assetName)
|
|
145
148
|
|
|
149
|
+
// Extract the full path from the original string (normalize to remove leading slash)
|
|
150
|
+
const fullPath = originalString.startsWith('/') ? originalString.slice(1) : originalString
|
|
151
|
+
const decodedFullPath = decodeURIComponent(fullPath)
|
|
152
|
+
|
|
146
153
|
/*
|
|
147
154
|
If the value is missing from the mapping, it means
|
|
148
155
|
- asset is missing in the project packer
|
|
@@ -150,9 +157,14 @@ export const prefixAssetsPath = (
|
|
|
150
157
|
|
|
151
158
|
Note: We need to check for decoded asset name as well as for some special characters such as katakana / kanjis / hiraganas
|
|
152
159
|
the src / url leading to the asset can be encoded and we need to check the decoded version against the asset mapping
|
|
160
|
+
|
|
161
|
+
Try full-path lookup first (to handle duplicate filenames in different folders),
|
|
162
|
+
then fall back to basename-only (for backward compatibility)
|
|
153
163
|
*/
|
|
154
164
|
|
|
155
165
|
if (
|
|
166
|
+
!(typeof mappings[fullPath] === 'string') &&
|
|
167
|
+
!(typeof mappings[decodedFullPath] === 'string') &&
|
|
156
168
|
!(typeof mappings[assetName] === 'string') &&
|
|
157
169
|
!(typeof mappings[decodedAssetName] === 'string')
|
|
158
170
|
) {
|
|
@@ -161,10 +173,17 @@ export const prefixAssetsPath = (
|
|
|
161
173
|
|
|
162
174
|
/*
|
|
163
175
|
need to use either the original or decoded assetName to retrieve its mapping if there is one
|
|
176
|
+
Priority: fullPath > decodedFullPath > assetName > decodedAssetName
|
|
164
177
|
*/
|
|
165
178
|
|
|
166
179
|
const assetNameUsedForMapping =
|
|
167
|
-
typeof mappings[
|
|
180
|
+
typeof mappings[fullPath] === 'string'
|
|
181
|
+
? fullPath
|
|
182
|
+
: typeof mappings[decodedFullPath] === 'string'
|
|
183
|
+
? decodedFullPath
|
|
184
|
+
: typeof mappings[assetName] === 'string'
|
|
185
|
+
? assetName
|
|
186
|
+
: decodedAssetName
|
|
168
187
|
|
|
169
188
|
/*
|
|
170
189
|
If the value from the mapping is an empty string
|
|
@@ -195,14 +214,35 @@ export const traverseNodes = (
|
|
|
195
214
|
fn: (node: UIDLNode | UIDLComponentStyleReference, parentNode: UIDLNode) => void,
|
|
196
215
|
parent: UIDLNode | null = null
|
|
197
216
|
) => {
|
|
217
|
+
if (!node.type) {
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
|
|
198
221
|
fn(node, parent)
|
|
199
222
|
|
|
200
223
|
switch (node.type) {
|
|
201
224
|
case 'element':
|
|
225
|
+
// Check if this element node is wrapping a data-source node
|
|
226
|
+
// This happens when node.content has a 'type' property that is a data-source type
|
|
227
|
+
if (
|
|
228
|
+
node.content &&
|
|
229
|
+
typeof node.content === 'object' &&
|
|
230
|
+
'type' in node.content &&
|
|
231
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')
|
|
232
|
+
) {
|
|
233
|
+
// Treat the entire node.content as a data-source node
|
|
234
|
+
traverseNodes(node.content as any, fn, node)
|
|
235
|
+
break
|
|
236
|
+
}
|
|
237
|
+
|
|
202
238
|
const { attrs, children, style, abilities, referencedStyles } = node.content
|
|
203
239
|
if (attrs) {
|
|
204
240
|
Object.keys(attrs).forEach((attrKey) => {
|
|
205
|
-
|
|
241
|
+
const attr = attrs[attrKey]
|
|
242
|
+
if (attr.type === 'object') {
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
traverseNodes(attr, fn, node)
|
|
206
246
|
})
|
|
207
247
|
}
|
|
208
248
|
|
|
@@ -244,6 +284,9 @@ export const traverseNodes = (
|
|
|
244
284
|
if (node.content.nodes.empty) {
|
|
245
285
|
traverseNodes(node.content.nodes.empty, fn)
|
|
246
286
|
}
|
|
287
|
+
if (node.content.nodes.loading) {
|
|
288
|
+
traverseNodes(node.content.nodes.loading, fn)
|
|
289
|
+
}
|
|
247
290
|
break
|
|
248
291
|
|
|
249
292
|
case 'cms-item':
|
|
@@ -256,6 +299,54 @@ export const traverseNodes = (
|
|
|
256
299
|
}
|
|
257
300
|
break
|
|
258
301
|
|
|
302
|
+
case 'cms-mixed-type':
|
|
303
|
+
if (node.content.nodes?.fallback) {
|
|
304
|
+
traverseNodes(node.content.nodes.fallback, fn)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (node.content.nodes?.error) {
|
|
308
|
+
traverseNodes(node.content.nodes.error, fn)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
Object.keys(node.content?.mappings || {}).forEach((key) => {
|
|
312
|
+
traverseNodes(node.content.mappings[key], fn)
|
|
313
|
+
})
|
|
314
|
+
break
|
|
315
|
+
|
|
316
|
+
case 'data-source-item':
|
|
317
|
+
if (node.content.nodes?.success) {
|
|
318
|
+
traverseNodes(node.content.nodes.success, fn)
|
|
319
|
+
}
|
|
320
|
+
if (node.content.nodes?.error) {
|
|
321
|
+
traverseNodes(node.content.nodes.error, fn)
|
|
322
|
+
}
|
|
323
|
+
if (node.content.nodes?.loading) {
|
|
324
|
+
traverseNodes(node.content.nodes.loading, fn)
|
|
325
|
+
}
|
|
326
|
+
if (node.content.children) {
|
|
327
|
+
node.content.children.forEach((child) => {
|
|
328
|
+
traverseNodes(child, fn, node)
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
break
|
|
332
|
+
|
|
333
|
+
case 'data-source-list':
|
|
334
|
+
if (node.content.nodes?.success) {
|
|
335
|
+
traverseNodes(node.content.nodes.success, fn)
|
|
336
|
+
}
|
|
337
|
+
if (node.content.nodes?.error) {
|
|
338
|
+
traverseNodes(node.content.nodes.error, fn)
|
|
339
|
+
}
|
|
340
|
+
if (node.content.nodes?.loading) {
|
|
341
|
+
traverseNodes(node.content.nodes.loading, fn)
|
|
342
|
+
}
|
|
343
|
+
if (node.content.children) {
|
|
344
|
+
node.content.children.forEach((child) => {
|
|
345
|
+
traverseNodes(child, fn, node)
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
break
|
|
349
|
+
|
|
259
350
|
case 'repeat':
|
|
260
351
|
traverseNodes(node.content.node, fn, node)
|
|
261
352
|
traverseNodes(node.content.dataSource, fn, node)
|
|
@@ -294,6 +385,18 @@ export const traverseResources = (
|
|
|
294
385
|
) => {
|
|
295
386
|
switch (node.type) {
|
|
296
387
|
case 'element':
|
|
388
|
+
// Check if this element node is wrapping a data-source node
|
|
389
|
+
if (
|
|
390
|
+
node.content &&
|
|
391
|
+
typeof node.content === 'object' &&
|
|
392
|
+
'type' in node.content &&
|
|
393
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')
|
|
394
|
+
) {
|
|
395
|
+
// Treat the entire node.content as a data-source node
|
|
396
|
+
traverseResources(node.content as any, fn)
|
|
397
|
+
break
|
|
398
|
+
}
|
|
399
|
+
|
|
297
400
|
const { children } = node.content
|
|
298
401
|
|
|
299
402
|
if (children) {
|
|
@@ -318,6 +421,9 @@ export const traverseResources = (
|
|
|
318
421
|
if (node.content.nodes.empty) {
|
|
319
422
|
traverseResources(node.content.nodes.empty, fn)
|
|
320
423
|
}
|
|
424
|
+
if (node.content.nodes.loading) {
|
|
425
|
+
traverseResources(node.content.nodes.loading, fn)
|
|
426
|
+
}
|
|
321
427
|
break
|
|
322
428
|
|
|
323
429
|
case 'cms-item':
|
|
@@ -330,6 +436,44 @@ export const traverseResources = (
|
|
|
330
436
|
}
|
|
331
437
|
break
|
|
332
438
|
|
|
439
|
+
case 'cms-mixed-type':
|
|
440
|
+
if (node.content.nodes?.fallback) {
|
|
441
|
+
traverseResources(node.content.nodes.fallback, fn)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (node.content.nodes?.error) {
|
|
445
|
+
traverseResources(node.content.nodes.error, fn)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
Object.keys(node.content?.mappings || {}).forEach((key) => {
|
|
449
|
+
traverseResources(node.content.mappings[key], fn)
|
|
450
|
+
})
|
|
451
|
+
break
|
|
452
|
+
|
|
453
|
+
case 'data-source-item':
|
|
454
|
+
if (node.content.nodes?.success) {
|
|
455
|
+
traverseResources(node.content.nodes.success, fn)
|
|
456
|
+
}
|
|
457
|
+
if (node.content.nodes?.error) {
|
|
458
|
+
traverseResources(node.content.nodes.error, fn)
|
|
459
|
+
}
|
|
460
|
+
if (node.content.nodes?.loading) {
|
|
461
|
+
traverseResources(node.content.nodes.loading, fn)
|
|
462
|
+
}
|
|
463
|
+
break
|
|
464
|
+
|
|
465
|
+
case 'data-source-list':
|
|
466
|
+
if (node.content.nodes?.success) {
|
|
467
|
+
traverseResources(node.content.nodes.success, fn)
|
|
468
|
+
}
|
|
469
|
+
if (node.content.nodes?.error) {
|
|
470
|
+
traverseResources(node.content.nodes.error, fn)
|
|
471
|
+
}
|
|
472
|
+
if (node.content.nodes?.loading) {
|
|
473
|
+
traverseResources(node.content.nodes.loading, fn)
|
|
474
|
+
}
|
|
475
|
+
break
|
|
476
|
+
|
|
333
477
|
case 'repeat':
|
|
334
478
|
traverseResources(node.content.node, fn)
|
|
335
479
|
break
|
|
@@ -360,19 +504,45 @@ export const traverseResources = (
|
|
|
360
504
|
const traverseStyleObject = (style: UIDLStyleDefinitions) => {
|
|
361
505
|
Object.keys(style).forEach((styleKey) => {
|
|
362
506
|
const styleValue = style[styleKey]
|
|
363
|
-
// TODO: cross-check the support for the strings as content for styles
|
|
364
507
|
if (styleValue.type !== 'static' && styleValue.type !== 'dynamic') {
|
|
365
|
-
throw new Error(`We support only 'static' and 'dynamic' content for styles
|
|
508
|
+
throw new Error(`We support only 'static' and 'dynamic' content for styles \n
|
|
509
|
+
Received \n
|
|
510
|
+
${JSON.stringify(styleValue, null, 2)}`)
|
|
366
511
|
}
|
|
367
512
|
})
|
|
368
513
|
}
|
|
369
514
|
|
|
370
515
|
// Parses a node structure recursively and applies a function to each UIDLElement instance
|
|
371
516
|
export const traverseElements = (node: UIDLNode, fn: (element: UIDLElement) => void) => {
|
|
517
|
+
if (!node || !node.type) {
|
|
518
|
+
return
|
|
519
|
+
}
|
|
520
|
+
|
|
372
521
|
switch (node.type) {
|
|
373
522
|
case 'element':
|
|
523
|
+
// Check if this element node is wrapping a data-source node
|
|
524
|
+
if (
|
|
525
|
+
node.content &&
|
|
526
|
+
typeof node.content === 'object' &&
|
|
527
|
+
'type' in node.content &&
|
|
528
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')
|
|
529
|
+
) {
|
|
530
|
+
// Treat the entire node.content as a data-source node
|
|
531
|
+
traverseElements(node.content as any, fn)
|
|
532
|
+
break
|
|
533
|
+
}
|
|
534
|
+
|
|
374
535
|
fn(node.content)
|
|
375
536
|
|
|
537
|
+
if (node.content.attrs) {
|
|
538
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
539
|
+
const attrValue = node.content.attrs[attrKey]
|
|
540
|
+
if (attrValue.type === 'element') {
|
|
541
|
+
traverseElements(attrValue, fn)
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
376
546
|
if (node.content.children) {
|
|
377
547
|
node.content.children.forEach((child) => {
|
|
378
548
|
traverseElements(child, fn)
|
|
@@ -388,6 +558,16 @@ export const traverseElements = (node: UIDLNode, fn: (element: UIDLElement) => v
|
|
|
388
558
|
if (node.content.nodes.loading) {
|
|
389
559
|
traverseElements(node.content.nodes.loading, fn)
|
|
390
560
|
}
|
|
561
|
+
|
|
562
|
+
if (node.content.attrs) {
|
|
563
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
564
|
+
const attrValue = node.content.attrs[attrKey]
|
|
565
|
+
if (attrValue.type === 'element') {
|
|
566
|
+
traverseElements(attrValue, fn)
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
391
571
|
break
|
|
392
572
|
|
|
393
573
|
case 'cms-list-repeater':
|
|
@@ -395,6 +575,9 @@ export const traverseElements = (node: UIDLNode, fn: (element: UIDLElement) => v
|
|
|
395
575
|
if (node.content.nodes.empty) {
|
|
396
576
|
traverseElements(node.content.nodes.empty, fn)
|
|
397
577
|
}
|
|
578
|
+
if (node.content.nodes.loading) {
|
|
579
|
+
traverseElements(node.content.nodes.loading, fn)
|
|
580
|
+
}
|
|
398
581
|
|
|
399
582
|
break
|
|
400
583
|
|
|
@@ -406,6 +589,80 @@ export const traverseElements = (node: UIDLNode, fn: (element: UIDLElement) => v
|
|
|
406
589
|
if (node.content.nodes.loading) {
|
|
407
590
|
traverseElements(node.content.nodes.loading, fn)
|
|
408
591
|
}
|
|
592
|
+
|
|
593
|
+
if (node.content.attrs) {
|
|
594
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
595
|
+
const attrValue = node.content.attrs[attrKey]
|
|
596
|
+
if (attrValue.type === 'element') {
|
|
597
|
+
traverseElements(attrValue, fn)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
break
|
|
603
|
+
|
|
604
|
+
case 'cms-mixed-type':
|
|
605
|
+
if (node.content.nodes?.fallback) {
|
|
606
|
+
traverseElements(node.content.nodes.fallback, fn)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (node.content.nodes?.error) {
|
|
610
|
+
traverseElements(node.content.nodes.error, fn)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
Object.keys(node.content?.mappings || {}).forEach((key) => {
|
|
614
|
+
traverseElements(node.content.mappings[key], fn)
|
|
615
|
+
})
|
|
616
|
+
|
|
617
|
+
if (node.content.attrs) {
|
|
618
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
619
|
+
const attrValue = node.content.attrs[attrKey]
|
|
620
|
+
if (attrValue.type === 'element') {
|
|
621
|
+
traverseElements(attrValue, fn)
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
break
|
|
627
|
+
|
|
628
|
+
case 'data-source-item':
|
|
629
|
+
if (node.content.nodes?.success) {
|
|
630
|
+
traverseElements(node.content.nodes.success, fn)
|
|
631
|
+
}
|
|
632
|
+
if (node.content.nodes?.error) {
|
|
633
|
+
traverseElements(node.content.nodes.error, fn)
|
|
634
|
+
}
|
|
635
|
+
if (node.content.nodes?.loading) {
|
|
636
|
+
traverseElements(node.content.nodes.loading, fn)
|
|
637
|
+
}
|
|
638
|
+
if (node.content.attrs) {
|
|
639
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
640
|
+
const attrValue = node.content.attrs[attrKey]
|
|
641
|
+
if (attrValue.type === 'element') {
|
|
642
|
+
traverseElements(attrValue, fn)
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
break
|
|
647
|
+
|
|
648
|
+
case 'data-source-list':
|
|
649
|
+
if (node.content.nodes?.success) {
|
|
650
|
+
traverseElements(node.content.nodes.success, fn)
|
|
651
|
+
}
|
|
652
|
+
if (node.content.nodes?.error) {
|
|
653
|
+
traverseElements(node.content.nodes.error, fn)
|
|
654
|
+
}
|
|
655
|
+
if (node.content.nodes?.loading) {
|
|
656
|
+
traverseElements(node.content.nodes.loading, fn)
|
|
657
|
+
}
|
|
658
|
+
if (node.content.attrs) {
|
|
659
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
660
|
+
const attrValue = node.content.attrs[attrKey]
|
|
661
|
+
if (attrValue.type === 'element') {
|
|
662
|
+
traverseElements(attrValue, fn)
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
409
666
|
break
|
|
410
667
|
|
|
411
668
|
case 'repeat':
|
|
@@ -431,18 +688,39 @@ export const traverseElements = (node: UIDLNode, fn: (element: UIDLElement) => v
|
|
|
431
688
|
|
|
432
689
|
default:
|
|
433
690
|
throw new Error(
|
|
434
|
-
`traverseElements was given an unsupported node type :
|
|
435
|
-
node,
|
|
436
|
-
null,
|
|
437
|
-
2
|
|
438
|
-
)}`
|
|
691
|
+
`traverseElements was given an unsupported node type : \n ${JSON.stringify(node, null, 2)}`
|
|
439
692
|
)
|
|
440
693
|
}
|
|
441
694
|
}
|
|
442
695
|
|
|
443
696
|
export const traverseRepeats = (node: UIDLNode, fn: (element: UIDLRepeatContent) => void) => {
|
|
697
|
+
if (!node || !node.type) {
|
|
698
|
+
return
|
|
699
|
+
}
|
|
700
|
+
|
|
444
701
|
switch (node.type) {
|
|
445
702
|
case 'element':
|
|
703
|
+
// Check if this element node is wrapping a data-source node
|
|
704
|
+
if (
|
|
705
|
+
node.content &&
|
|
706
|
+
typeof node.content === 'object' &&
|
|
707
|
+
'type' in node.content &&
|
|
708
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')
|
|
709
|
+
) {
|
|
710
|
+
// Treat the entire node.content as a data-source node
|
|
711
|
+
traverseRepeats(node.content as any, fn)
|
|
712
|
+
break
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (node.content.attrs) {
|
|
716
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
717
|
+
const attrValue = node.content.attrs[attrKey]
|
|
718
|
+
if (attrValue.type === 'element') {
|
|
719
|
+
traverseRepeats(attrValue, fn)
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
446
724
|
if (node.content.children) {
|
|
447
725
|
node.content.children.forEach((child) => {
|
|
448
726
|
traverseRepeats(child, fn)
|
|
@@ -459,6 +737,16 @@ export const traverseRepeats = (node: UIDLNode, fn: (element: UIDLRepeatContent)
|
|
|
459
737
|
if (node.content.nodes.loading) {
|
|
460
738
|
traverseRepeats(node.content.nodes.loading, fn)
|
|
461
739
|
}
|
|
740
|
+
|
|
741
|
+
if (node.content.attrs) {
|
|
742
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
743
|
+
const attrValue = node.content.attrs[attrKey]
|
|
744
|
+
if (attrValue.type === 'element') {
|
|
745
|
+
traverseRepeats(attrValue, fn)
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
462
750
|
break
|
|
463
751
|
|
|
464
752
|
case 'cms-list-repeater':
|
|
@@ -466,17 +754,55 @@ export const traverseRepeats = (node: UIDLNode, fn: (element: UIDLRepeatContent)
|
|
|
466
754
|
if (node.content.nodes.empty) {
|
|
467
755
|
traverseRepeats(node.content.nodes.empty, fn)
|
|
468
756
|
}
|
|
757
|
+
if (node.content.nodes.loading) {
|
|
758
|
+
traverseRepeats(node.content.nodes.loading, fn)
|
|
759
|
+
}
|
|
469
760
|
|
|
470
761
|
break
|
|
471
762
|
|
|
472
763
|
case 'cms-item':
|
|
473
764
|
traverseRepeats(node.content.nodes.success, fn)
|
|
765
|
+
|
|
474
766
|
if (node.content.nodes.error) {
|
|
475
767
|
traverseRepeats(node.content.nodes.error, fn)
|
|
476
768
|
}
|
|
769
|
+
|
|
477
770
|
if (node.content.nodes.loading) {
|
|
478
771
|
traverseRepeats(node.content.nodes.loading, fn)
|
|
479
772
|
}
|
|
773
|
+
|
|
774
|
+
if (node.content.attrs) {
|
|
775
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
776
|
+
const attrValue = node.content.attrs[attrKey]
|
|
777
|
+
if (attrValue.type === 'element') {
|
|
778
|
+
traverseRepeats(attrValue, fn)
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
break
|
|
783
|
+
|
|
784
|
+
case 'cms-mixed-type':
|
|
785
|
+
if (node.content.nodes?.fallback) {
|
|
786
|
+
traverseRepeats(node.content.nodes.fallback, fn)
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
if (node.content.nodes?.error) {
|
|
790
|
+
traverseRepeats(node.content.nodes.error, fn)
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
Object.keys(node.content?.mappings || {}).forEach((key) => {
|
|
794
|
+
traverseRepeats(node.content.mappings[key], fn)
|
|
795
|
+
})
|
|
796
|
+
|
|
797
|
+
if (node.content.attrs) {
|
|
798
|
+
for (const attrKey of Object.keys(node.content.attrs)) {
|
|
799
|
+
const attrValue = node.content.attrs[attrKey]
|
|
800
|
+
if (attrValue.type === 'element') {
|
|
801
|
+
traverseRepeats(attrValue, fn)
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
480
806
|
break
|
|
481
807
|
|
|
482
808
|
case 'repeat':
|
|
@@ -495,6 +821,30 @@ export const traverseRepeats = (node: UIDLNode, fn: (element: UIDLRepeatContent)
|
|
|
495
821
|
}
|
|
496
822
|
break
|
|
497
823
|
|
|
824
|
+
case 'data-source-item':
|
|
825
|
+
if ((node as any).content.nodes?.success) {
|
|
826
|
+
traverseRepeats((node as any).content.nodes.success, fn)
|
|
827
|
+
}
|
|
828
|
+
if ((node as any).content.nodes?.error) {
|
|
829
|
+
traverseRepeats((node as any).content.nodes.error, fn)
|
|
830
|
+
}
|
|
831
|
+
if ((node as any).content.nodes?.loading) {
|
|
832
|
+
traverseRepeats((node as any).content.nodes.loading, fn)
|
|
833
|
+
}
|
|
834
|
+
break
|
|
835
|
+
|
|
836
|
+
case 'data-source-list':
|
|
837
|
+
if ((node as any).content.nodes?.success) {
|
|
838
|
+
traverseRepeats((node as any).content.nodes.success, fn)
|
|
839
|
+
}
|
|
840
|
+
if ((node as any).content.nodes?.error) {
|
|
841
|
+
traverseRepeats((node as any).content.nodes.error, fn)
|
|
842
|
+
}
|
|
843
|
+
if ((node as any).content.nodes?.loading) {
|
|
844
|
+
traverseRepeats((node as any).content.nodes.loading, fn)
|
|
845
|
+
}
|
|
846
|
+
break
|
|
847
|
+
|
|
498
848
|
case 'static':
|
|
499
849
|
case 'dynamic':
|
|
500
850
|
case 'raw':
|
|
@@ -518,6 +868,7 @@ interface SplitResponse {
|
|
|
518
868
|
dynamicStyles: UIDLStyleDefinitions
|
|
519
869
|
tokenStyles: UIDLStyleDefinitions
|
|
520
870
|
}
|
|
871
|
+
|
|
521
872
|
export const splitDynamicAndStaticStyles = (
|
|
522
873
|
style: UIDLStyleDefinitions | Record<string, UIDLStyleSheetContent>
|
|
523
874
|
): SplitResponse => {
|
|
@@ -672,13 +1023,13 @@ export const transformStylesAssignmentsToJson = (
|
|
|
672
1023
|
return acc
|
|
673
1024
|
}
|
|
674
1025
|
|
|
675
|
-
if (type === 'dynamic') {
|
|
1026
|
+
if (type === 'dynamic' && content.referenceType !== 'global') {
|
|
676
1027
|
if (['state', 'prop'].includes(content?.referenceType)) {
|
|
677
1028
|
acc[key] = {
|
|
678
1029
|
type,
|
|
679
1030
|
content: {
|
|
680
1031
|
...content,
|
|
681
|
-
id:
|
|
1032
|
+
id: generateIdWithRefPath(content.id, content.refPath),
|
|
682
1033
|
},
|
|
683
1034
|
}
|
|
684
1035
|
} else {
|
|
@@ -701,6 +1052,23 @@ export const transformStylesAssignmentsToJson = (
|
|
|
701
1052
|
return newStyleObject
|
|
702
1053
|
}
|
|
703
1054
|
|
|
1055
|
+
export const generateIdWithRefPath = (contentId: string, refPath?: string[]) => {
|
|
1056
|
+
let processedId = contentId
|
|
1057
|
+
if (refPath) {
|
|
1058
|
+
const processedRefPath = refPath.reduce((acc, path) => {
|
|
1059
|
+
return `${acc}?.['${path}']`
|
|
1060
|
+
}, '')
|
|
1061
|
+
|
|
1062
|
+
// This is a bit ugly, but in some cases props are parsed twice or already generated.
|
|
1063
|
+
// To avoid possible bugs, this should be a good safety measure
|
|
1064
|
+
if (!processedId.includes(processedRefPath)) {
|
|
1065
|
+
processedId = `${processedId}${processedRefPath}`
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
return StringUtils.createStateOrPropStoringValue(processedId)
|
|
1070
|
+
}
|
|
1071
|
+
|
|
704
1072
|
/*
|
|
705
1073
|
All the props passed to the components are transformed to a unique case
|
|
706
1074
|
to minimize the collision of using cameCalse in one place and dashCase in
|
|
@@ -728,47 +1096,64 @@ export const transformAttributesAssignmentsToJson = (
|
|
|
728
1096
|
}
|
|
729
1097
|
|
|
730
1098
|
if (!Array.isArray(attributeContent) && entityType === 'object') {
|
|
731
|
-
// if this value is already properly declared, make sure it is not
|
|
732
1099
|
const { type } = attributeContent as UIDLAttributeValue
|
|
733
|
-
if (['static', 'import', 'raw', 'expr'].indexOf(type as string) !== -1) {
|
|
734
|
-
const propKey = isLocalComponent ? StringUtils.createStateOrPropStoringValue(key) : key
|
|
735
|
-
acc[propKey] = attributeContent as UIDLAttributeValue
|
|
736
|
-
return acc
|
|
737
|
-
}
|
|
738
1100
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
)
|
|
1101
|
+
switch (type) {
|
|
1102
|
+
case 'import':
|
|
1103
|
+
case 'static':
|
|
1104
|
+
case 'raw':
|
|
1105
|
+
case 'expr': {
|
|
1106
|
+
const propKey = isLocalComponent ? StringUtils.createStateOrPropStoringValue(key) : key
|
|
1107
|
+
acc[propKey] = attributeContent as UIDLAttributeValue
|
|
1108
|
+
return acc
|
|
745
1109
|
}
|
|
746
|
-
return acc
|
|
747
|
-
}
|
|
748
1110
|
|
|
749
|
-
|
|
750
|
-
if (type === 'dynamic') {
|
|
751
|
-
if (['state', 'prop'].includes(content?.referenceType)) {
|
|
1111
|
+
case 'comp-style': {
|
|
752
1112
|
acc[key] = {
|
|
753
|
-
type,
|
|
754
|
-
content:
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
},
|
|
1113
|
+
type: 'comp-style',
|
|
1114
|
+
content: StringUtils.createStateOrPropStoringValue(
|
|
1115
|
+
(attributeContent as UIDLComponentStyleReference).content
|
|
1116
|
+
),
|
|
758
1117
|
}
|
|
759
|
-
|
|
1118
|
+
return acc
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
case 'dynamic': {
|
|
1122
|
+
const { content } = attributeContent as UIDLDynamicReference
|
|
1123
|
+
// global id's dont need to be transformed. As they are constants and each one is handled by the generator
|
|
1124
|
+
// depending on the context and the framework.
|
|
1125
|
+
if (
|
|
1126
|
+
['state', 'prop'].includes(content?.referenceType) &&
|
|
1127
|
+
content.referenceType !== 'global'
|
|
1128
|
+
) {
|
|
1129
|
+
acc[key] = {
|
|
1130
|
+
type,
|
|
1131
|
+
content: {
|
|
1132
|
+
...content,
|
|
1133
|
+
id: generateIdWithRefPath(content.id, content.refPath),
|
|
1134
|
+
},
|
|
1135
|
+
}
|
|
1136
|
+
} else {
|
|
1137
|
+
acc[key] = attributeContent as UIDLAttributeValue
|
|
1138
|
+
}
|
|
1139
|
+
return acc
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
case 'object':
|
|
1143
|
+
case 'element':
|
|
760
1144
|
acc[key] = attributeContent as UIDLAttributeValue
|
|
1145
|
+
return acc
|
|
1146
|
+
|
|
1147
|
+
default: {
|
|
1148
|
+
throw new Error(
|
|
1149
|
+
`transformAttributesAssignmentsToJson encountered a style value that is not supported ${JSON.stringify(
|
|
1150
|
+
attributeContent,
|
|
1151
|
+
null,
|
|
1152
|
+
2
|
|
1153
|
+
)}`
|
|
1154
|
+
)
|
|
761
1155
|
}
|
|
762
|
-
return acc
|
|
763
1156
|
}
|
|
764
|
-
|
|
765
|
-
throw new Error(
|
|
766
|
-
`transformAttributesAssignmentsToJson encountered a style value that is not supported ${JSON.stringify(
|
|
767
|
-
attributeContent,
|
|
768
|
-
null,
|
|
769
|
-
2
|
|
770
|
-
)}`
|
|
771
|
-
)
|
|
772
1157
|
}
|
|
773
1158
|
}, newAttrObject)
|
|
774
1159
|
|
|
@@ -827,6 +1212,9 @@ export const removeChildNodes = (
|
|
|
827
1212
|
if (node.content.nodes.empty) {
|
|
828
1213
|
removeChildNodes(node.content.nodes.empty, criteria)
|
|
829
1214
|
}
|
|
1215
|
+
if (node.content.nodes.loading) {
|
|
1216
|
+
removeChildNodes(node.content.nodes.loading, criteria)
|
|
1217
|
+
}
|
|
830
1218
|
|
|
831
1219
|
break
|
|
832
1220
|
case 'cms-item':
|
|
@@ -839,6 +1227,20 @@ export const removeChildNodes = (
|
|
|
839
1227
|
}
|
|
840
1228
|
break
|
|
841
1229
|
|
|
1230
|
+
case 'cms-mixed-type':
|
|
1231
|
+
if (node.content.nodes?.fallback) {
|
|
1232
|
+
removeChildNodes(node.content.nodes.fallback, criteria)
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
if (node.content.nodes?.error) {
|
|
1236
|
+
removeChildNodes(node.content.nodes.error, criteria)
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
Object.keys(node.content?.mappings || {}).forEach((key) => {
|
|
1240
|
+
removeChildNodes(node.content.mappings[key], criteria)
|
|
1241
|
+
})
|
|
1242
|
+
break
|
|
1243
|
+
|
|
842
1244
|
case 'conditional':
|
|
843
1245
|
removeChildNodes(node.content.node, criteria)
|
|
844
1246
|
break
|