@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
|
@@ -16,7 +16,11 @@ export var extractRoutes = function (rootComponent) {
|
|
|
16
16
|
// Assuming root element starts with a UIDLElementNode
|
|
17
17
|
var rootElement = rootComponent.node.content;
|
|
18
18
|
// Look for conditional nodes in the first level children of the root element
|
|
19
|
-
return rootElement.children.filter(function (child) {
|
|
19
|
+
return rootElement.children.filter(function (child) {
|
|
20
|
+
return child.type === 'conditional' &&
|
|
21
|
+
child.content.reference.type === 'dynamic' &&
|
|
22
|
+
child.content.reference.content.id === 'route';
|
|
23
|
+
});
|
|
20
24
|
};
|
|
21
25
|
export var createWebComponentFriendlyName = function (componentName) {
|
|
22
26
|
var dashCaseName = camelCaseToDashCase(componentName);
|
|
@@ -104,6 +108,9 @@ export var prefixAssetsPath = function (originalString, assets) {
|
|
|
104
108
|
var prefix = assets.prefix, _a = assets.mappings, mappings = _a === void 0 ? {} : _a, identifier = assets.identifier;
|
|
105
109
|
var assetName = basename(originalString);
|
|
106
110
|
var decodedAssetName = decodeURIComponent(assetName);
|
|
111
|
+
// Extract the full path from the original string (normalize to remove leading slash)
|
|
112
|
+
var fullPath = originalString.startsWith('/') ? originalString.slice(1) : originalString;
|
|
113
|
+
var decodedFullPath = decodeURIComponent(fullPath);
|
|
107
114
|
/*
|
|
108
115
|
If the value is missing from the mapping, it means
|
|
109
116
|
- asset is missing in the project packer
|
|
@@ -111,15 +118,27 @@ export var prefixAssetsPath = function (originalString, assets) {
|
|
|
111
118
|
|
|
112
119
|
Note: We need to check for decoded asset name as well as for some special characters such as katakana / kanjis / hiraganas
|
|
113
120
|
the src / url leading to the asset can be encoded and we need to check the decoded version against the asset mapping
|
|
121
|
+
|
|
122
|
+
Try full-path lookup first (to handle duplicate filenames in different folders),
|
|
123
|
+
then fall back to basename-only (for backward compatibility)
|
|
114
124
|
*/
|
|
115
|
-
if (!(typeof mappings[
|
|
125
|
+
if (!(typeof mappings[fullPath] === 'string') &&
|
|
126
|
+
!(typeof mappings[decodedFullPath] === 'string') &&
|
|
127
|
+
!(typeof mappings[assetName] === 'string') &&
|
|
116
128
|
!(typeof mappings[decodedAssetName] === 'string')) {
|
|
117
129
|
return originalString;
|
|
118
130
|
}
|
|
119
131
|
/*
|
|
120
132
|
need to use either the original or decoded assetName to retrieve its mapping if there is one
|
|
133
|
+
Priority: fullPath > decodedFullPath > assetName > decodedAssetName
|
|
121
134
|
*/
|
|
122
|
-
var assetNameUsedForMapping = typeof mappings[
|
|
135
|
+
var assetNameUsedForMapping = typeof mappings[fullPath] === 'string'
|
|
136
|
+
? fullPath
|
|
137
|
+
: typeof mappings[decodedFullPath] === 'string'
|
|
138
|
+
? decodedFullPath
|
|
139
|
+
: typeof mappings[assetName] === 'string'
|
|
140
|
+
? assetName
|
|
141
|
+
: decodedAssetName;
|
|
123
142
|
/*
|
|
124
143
|
If the value from the mapping is an empty string
|
|
125
144
|
we need to not join it in the return path as it would append
|
|
@@ -141,15 +160,32 @@ export var cloneObject = function (node) { return JSON.parse(JSON.stringify(node
|
|
|
141
160
|
// This function parses all the UIDLNodes in a tree structure
|
|
142
161
|
// enabling a function to be applied to each individual node
|
|
143
162
|
export var traverseNodes = function (node, fn, parent) {
|
|
144
|
-
var _a, _b, _c;
|
|
163
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
145
164
|
if (parent === void 0) { parent = null; }
|
|
165
|
+
if (!node.type) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
146
168
|
fn(node, parent);
|
|
147
169
|
switch (node.type) {
|
|
148
170
|
case 'element':
|
|
149
|
-
|
|
171
|
+
// Check if this element node is wrapping a data-source node
|
|
172
|
+
// This happens when node.content has a 'type' property that is a data-source type
|
|
173
|
+
if (node.content &&
|
|
174
|
+
typeof node.content === 'object' &&
|
|
175
|
+
'type' in node.content &&
|
|
176
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')) {
|
|
177
|
+
// Treat the entire node.content as a data-source node
|
|
178
|
+
traverseNodes(node.content, fn, node);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
var _o = node.content, attrs_1 = _o.attrs, children = _o.children, style = _o.style, abilities = _o.abilities, referencedStyles = _o.referencedStyles;
|
|
150
182
|
if (attrs_1) {
|
|
151
183
|
Object.keys(attrs_1).forEach(function (attrKey) {
|
|
152
|
-
|
|
184
|
+
var attr = attrs_1[attrKey];
|
|
185
|
+
if (attr.type === 'object') {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
traverseNodes(attr, fn, node);
|
|
153
189
|
});
|
|
154
190
|
}
|
|
155
191
|
if (referencedStyles && Object.keys(referencedStyles).length > 0) {
|
|
@@ -185,6 +221,9 @@ export var traverseNodes = function (node, fn, parent) {
|
|
|
185
221
|
if (node.content.nodes.empty) {
|
|
186
222
|
traverseNodes(node.content.nodes.empty, fn);
|
|
187
223
|
}
|
|
224
|
+
if (node.content.nodes.loading) {
|
|
225
|
+
traverseNodes(node.content.nodes.loading, fn);
|
|
226
|
+
}
|
|
188
227
|
break;
|
|
189
228
|
case 'cms-item':
|
|
190
229
|
traverseNodes(node.content.nodes.success, fn);
|
|
@@ -195,6 +234,49 @@ export var traverseNodes = function (node, fn, parent) {
|
|
|
195
234
|
traverseNodes(node.content.nodes.loading, fn);
|
|
196
235
|
}
|
|
197
236
|
break;
|
|
237
|
+
case 'cms-mixed-type':
|
|
238
|
+
if ((_d = node.content.nodes) === null || _d === void 0 ? void 0 : _d.fallback) {
|
|
239
|
+
traverseNodes(node.content.nodes.fallback, fn);
|
|
240
|
+
}
|
|
241
|
+
if ((_e = node.content.nodes) === null || _e === void 0 ? void 0 : _e.error) {
|
|
242
|
+
traverseNodes(node.content.nodes.error, fn);
|
|
243
|
+
}
|
|
244
|
+
Object.keys(((_f = node.content) === null || _f === void 0 ? void 0 : _f.mappings) || {}).forEach(function (key) {
|
|
245
|
+
traverseNodes(node.content.mappings[key], fn);
|
|
246
|
+
});
|
|
247
|
+
break;
|
|
248
|
+
case 'data-source-item':
|
|
249
|
+
if ((_g = node.content.nodes) === null || _g === void 0 ? void 0 : _g.success) {
|
|
250
|
+
traverseNodes(node.content.nodes.success, fn);
|
|
251
|
+
}
|
|
252
|
+
if ((_h = node.content.nodes) === null || _h === void 0 ? void 0 : _h.error) {
|
|
253
|
+
traverseNodes(node.content.nodes.error, fn);
|
|
254
|
+
}
|
|
255
|
+
if ((_j = node.content.nodes) === null || _j === void 0 ? void 0 : _j.loading) {
|
|
256
|
+
traverseNodes(node.content.nodes.loading, fn);
|
|
257
|
+
}
|
|
258
|
+
if (node.content.children) {
|
|
259
|
+
node.content.children.forEach(function (child) {
|
|
260
|
+
traverseNodes(child, fn, node);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
case 'data-source-list':
|
|
265
|
+
if ((_k = node.content.nodes) === null || _k === void 0 ? void 0 : _k.success) {
|
|
266
|
+
traverseNodes(node.content.nodes.success, fn);
|
|
267
|
+
}
|
|
268
|
+
if ((_l = node.content.nodes) === null || _l === void 0 ? void 0 : _l.error) {
|
|
269
|
+
traverseNodes(node.content.nodes.error, fn);
|
|
270
|
+
}
|
|
271
|
+
if ((_m = node.content.nodes) === null || _m === void 0 ? void 0 : _m.loading) {
|
|
272
|
+
traverseNodes(node.content.nodes.loading, fn);
|
|
273
|
+
}
|
|
274
|
+
if (node.content.children) {
|
|
275
|
+
node.content.children.forEach(function (child) {
|
|
276
|
+
traverseNodes(child, fn, node);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
198
280
|
case 'repeat':
|
|
199
281
|
traverseNodes(node.content.node, fn, node);
|
|
200
282
|
traverseNodes(node.content.dataSource, fn, node);
|
|
@@ -221,8 +303,18 @@ export var traverseNodes = function (node, fn, parent) {
|
|
|
221
303
|
}
|
|
222
304
|
};
|
|
223
305
|
export var traverseResources = function (node, fn) {
|
|
306
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
224
307
|
switch (node.type) {
|
|
225
308
|
case 'element':
|
|
309
|
+
// Check if this element node is wrapping a data-source node
|
|
310
|
+
if (node.content &&
|
|
311
|
+
typeof node.content === 'object' &&
|
|
312
|
+
'type' in node.content &&
|
|
313
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')) {
|
|
314
|
+
// Treat the entire node.content as a data-source node
|
|
315
|
+
traverseResources(node.content, fn);
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
226
318
|
var children = node.content.children;
|
|
227
319
|
if (children) {
|
|
228
320
|
children.forEach(function (child) {
|
|
@@ -244,6 +336,9 @@ export var traverseResources = function (node, fn) {
|
|
|
244
336
|
if (node.content.nodes.empty) {
|
|
245
337
|
traverseResources(node.content.nodes.empty, fn);
|
|
246
338
|
}
|
|
339
|
+
if (node.content.nodes.loading) {
|
|
340
|
+
traverseResources(node.content.nodes.loading, fn);
|
|
341
|
+
}
|
|
247
342
|
break;
|
|
248
343
|
case 'cms-item':
|
|
249
344
|
traverseResources(node.content.nodes.success, fn);
|
|
@@ -254,6 +349,39 @@ export var traverseResources = function (node, fn) {
|
|
|
254
349
|
traverseResources(node.content.nodes.loading, fn);
|
|
255
350
|
}
|
|
256
351
|
break;
|
|
352
|
+
case 'cms-mixed-type':
|
|
353
|
+
if ((_a = node.content.nodes) === null || _a === void 0 ? void 0 : _a.fallback) {
|
|
354
|
+
traverseResources(node.content.nodes.fallback, fn);
|
|
355
|
+
}
|
|
356
|
+
if ((_b = node.content.nodes) === null || _b === void 0 ? void 0 : _b.error) {
|
|
357
|
+
traverseResources(node.content.nodes.error, fn);
|
|
358
|
+
}
|
|
359
|
+
Object.keys(((_c = node.content) === null || _c === void 0 ? void 0 : _c.mappings) || {}).forEach(function (key) {
|
|
360
|
+
traverseResources(node.content.mappings[key], fn);
|
|
361
|
+
});
|
|
362
|
+
break;
|
|
363
|
+
case 'data-source-item':
|
|
364
|
+
if ((_d = node.content.nodes) === null || _d === void 0 ? void 0 : _d.success) {
|
|
365
|
+
traverseResources(node.content.nodes.success, fn);
|
|
366
|
+
}
|
|
367
|
+
if ((_e = node.content.nodes) === null || _e === void 0 ? void 0 : _e.error) {
|
|
368
|
+
traverseResources(node.content.nodes.error, fn);
|
|
369
|
+
}
|
|
370
|
+
if ((_f = node.content.nodes) === null || _f === void 0 ? void 0 : _f.loading) {
|
|
371
|
+
traverseResources(node.content.nodes.loading, fn);
|
|
372
|
+
}
|
|
373
|
+
break;
|
|
374
|
+
case 'data-source-list':
|
|
375
|
+
if ((_g = node.content.nodes) === null || _g === void 0 ? void 0 : _g.success) {
|
|
376
|
+
traverseResources(node.content.nodes.success, fn);
|
|
377
|
+
}
|
|
378
|
+
if ((_h = node.content.nodes) === null || _h === void 0 ? void 0 : _h.error) {
|
|
379
|
+
traverseResources(node.content.nodes.error, fn);
|
|
380
|
+
}
|
|
381
|
+
if ((_j = node.content.nodes) === null || _j === void 0 ? void 0 : _j.loading) {
|
|
382
|
+
traverseResources(node.content.nodes.loading, fn);
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
257
385
|
case 'repeat':
|
|
258
386
|
traverseResources(node.content.node, fn);
|
|
259
387
|
break;
|
|
@@ -277,17 +405,38 @@ export var traverseResources = function (node, fn) {
|
|
|
277
405
|
var traverseStyleObject = function (style) {
|
|
278
406
|
Object.keys(style).forEach(function (styleKey) {
|
|
279
407
|
var styleValue = style[styleKey];
|
|
280
|
-
// TODO: cross-check the support for the strings as content for styles
|
|
281
408
|
if (styleValue.type !== 'static' && styleValue.type !== 'dynamic') {
|
|
282
|
-
throw new Error("We support only 'static' and 'dynamic' content for styles");
|
|
409
|
+
throw new Error("We support only 'static' and 'dynamic' content for styles \n\n Received \n\n ".concat(JSON.stringify(styleValue, null, 2)));
|
|
283
410
|
}
|
|
284
411
|
});
|
|
285
412
|
};
|
|
286
413
|
// Parses a node structure recursively and applies a function to each UIDLElement instance
|
|
287
414
|
export var traverseElements = function (node, fn) {
|
|
415
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
416
|
+
if (!node || !node.type) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
288
419
|
switch (node.type) {
|
|
289
420
|
case 'element':
|
|
421
|
+
// Check if this element node is wrapping a data-source node
|
|
422
|
+
if (node.content &&
|
|
423
|
+
typeof node.content === 'object' &&
|
|
424
|
+
'type' in node.content &&
|
|
425
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')) {
|
|
426
|
+
// Treat the entire node.content as a data-source node
|
|
427
|
+
traverseElements(node.content, fn);
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
290
430
|
fn(node.content);
|
|
431
|
+
if (node.content.attrs) {
|
|
432
|
+
for (var _i = 0, _k = Object.keys(node.content.attrs); _i < _k.length; _i++) {
|
|
433
|
+
var attrKey = _k[_i];
|
|
434
|
+
var attrValue = node.content.attrs[attrKey];
|
|
435
|
+
if (attrValue.type === 'element') {
|
|
436
|
+
traverseElements(attrValue, fn);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
291
440
|
if (node.content.children) {
|
|
292
441
|
node.content.children.forEach(function (child) {
|
|
293
442
|
traverseElements(child, fn);
|
|
@@ -302,12 +451,24 @@ export var traverseElements = function (node, fn) {
|
|
|
302
451
|
if (node.content.nodes.loading) {
|
|
303
452
|
traverseElements(node.content.nodes.loading, fn);
|
|
304
453
|
}
|
|
454
|
+
if (node.content.attrs) {
|
|
455
|
+
for (var _l = 0, _m = Object.keys(node.content.attrs); _l < _m.length; _l++) {
|
|
456
|
+
var attrKey = _m[_l];
|
|
457
|
+
var attrValue = node.content.attrs[attrKey];
|
|
458
|
+
if (attrValue.type === 'element') {
|
|
459
|
+
traverseElements(attrValue, fn);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
305
463
|
break;
|
|
306
464
|
case 'cms-list-repeater':
|
|
307
465
|
traverseElements(node.content.nodes.list, fn);
|
|
308
466
|
if (node.content.nodes.empty) {
|
|
309
467
|
traverseElements(node.content.nodes.empty, fn);
|
|
310
468
|
}
|
|
469
|
+
if (node.content.nodes.loading) {
|
|
470
|
+
traverseElements(node.content.nodes.loading, fn);
|
|
471
|
+
}
|
|
311
472
|
break;
|
|
312
473
|
case 'cms-item':
|
|
313
474
|
traverseElements(node.content.nodes.success, fn);
|
|
@@ -317,6 +478,75 @@ export var traverseElements = function (node, fn) {
|
|
|
317
478
|
if (node.content.nodes.loading) {
|
|
318
479
|
traverseElements(node.content.nodes.loading, fn);
|
|
319
480
|
}
|
|
481
|
+
if (node.content.attrs) {
|
|
482
|
+
for (var _o = 0, _p = Object.keys(node.content.attrs); _o < _p.length; _o++) {
|
|
483
|
+
var attrKey = _p[_o];
|
|
484
|
+
var attrValue = node.content.attrs[attrKey];
|
|
485
|
+
if (attrValue.type === 'element') {
|
|
486
|
+
traverseElements(attrValue, fn);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
break;
|
|
491
|
+
case 'cms-mixed-type':
|
|
492
|
+
if ((_a = node.content.nodes) === null || _a === void 0 ? void 0 : _a.fallback) {
|
|
493
|
+
traverseElements(node.content.nodes.fallback, fn);
|
|
494
|
+
}
|
|
495
|
+
if ((_b = node.content.nodes) === null || _b === void 0 ? void 0 : _b.error) {
|
|
496
|
+
traverseElements(node.content.nodes.error, fn);
|
|
497
|
+
}
|
|
498
|
+
Object.keys(((_c = node.content) === null || _c === void 0 ? void 0 : _c.mappings) || {}).forEach(function (key) {
|
|
499
|
+
traverseElements(node.content.mappings[key], fn);
|
|
500
|
+
});
|
|
501
|
+
if (node.content.attrs) {
|
|
502
|
+
for (var _q = 0, _r = Object.keys(node.content.attrs); _q < _r.length; _q++) {
|
|
503
|
+
var attrKey = _r[_q];
|
|
504
|
+
var attrValue = node.content.attrs[attrKey];
|
|
505
|
+
if (attrValue.type === 'element') {
|
|
506
|
+
traverseElements(attrValue, fn);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
break;
|
|
511
|
+
case 'data-source-item':
|
|
512
|
+
if ((_d = node.content.nodes) === null || _d === void 0 ? void 0 : _d.success) {
|
|
513
|
+
traverseElements(node.content.nodes.success, fn);
|
|
514
|
+
}
|
|
515
|
+
if ((_e = node.content.nodes) === null || _e === void 0 ? void 0 : _e.error) {
|
|
516
|
+
traverseElements(node.content.nodes.error, fn);
|
|
517
|
+
}
|
|
518
|
+
if ((_f = node.content.nodes) === null || _f === void 0 ? void 0 : _f.loading) {
|
|
519
|
+
traverseElements(node.content.nodes.loading, fn);
|
|
520
|
+
}
|
|
521
|
+
if (node.content.attrs) {
|
|
522
|
+
for (var _s = 0, _t = Object.keys(node.content.attrs); _s < _t.length; _s++) {
|
|
523
|
+
var attrKey = _t[_s];
|
|
524
|
+
var attrValue = node.content.attrs[attrKey];
|
|
525
|
+
if (attrValue.type === 'element') {
|
|
526
|
+
traverseElements(attrValue, fn);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
break;
|
|
531
|
+
case 'data-source-list':
|
|
532
|
+
if ((_g = node.content.nodes) === null || _g === void 0 ? void 0 : _g.success) {
|
|
533
|
+
traverseElements(node.content.nodes.success, fn);
|
|
534
|
+
}
|
|
535
|
+
if ((_h = node.content.nodes) === null || _h === void 0 ? void 0 : _h.error) {
|
|
536
|
+
traverseElements(node.content.nodes.error, fn);
|
|
537
|
+
}
|
|
538
|
+
if ((_j = node.content.nodes) === null || _j === void 0 ? void 0 : _j.loading) {
|
|
539
|
+
traverseElements(node.content.nodes.loading, fn);
|
|
540
|
+
}
|
|
541
|
+
if (node.content.attrs) {
|
|
542
|
+
for (var _u = 0, _v = Object.keys(node.content.attrs); _u < _v.length; _u++) {
|
|
543
|
+
var attrKey = _v[_u];
|
|
544
|
+
var attrValue = node.content.attrs[attrKey];
|
|
545
|
+
if (attrValue.type === 'element') {
|
|
546
|
+
traverseElements(attrValue, fn);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
320
550
|
break;
|
|
321
551
|
case 'repeat':
|
|
322
552
|
traverseElements(node.content.node, fn);
|
|
@@ -336,12 +566,34 @@ export var traverseElements = function (node, fn) {
|
|
|
336
566
|
case 'expr':
|
|
337
567
|
break;
|
|
338
568
|
default:
|
|
339
|
-
throw new Error("traverseElements was given an unsupported node type :
|
|
569
|
+
throw new Error("traverseElements was given an unsupported node type : \n ".concat(JSON.stringify(node, null, 2)));
|
|
340
570
|
}
|
|
341
571
|
};
|
|
342
572
|
export var traverseRepeats = function (node, fn) {
|
|
573
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
574
|
+
if (!node || !node.type) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
343
577
|
switch (node.type) {
|
|
344
578
|
case 'element':
|
|
579
|
+
// Check if this element node is wrapping a data-source node
|
|
580
|
+
if (node.content &&
|
|
581
|
+
typeof node.content === 'object' &&
|
|
582
|
+
'type' in node.content &&
|
|
583
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')) {
|
|
584
|
+
// Treat the entire node.content as a data-source node
|
|
585
|
+
traverseRepeats(node.content, fn);
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
if (node.content.attrs) {
|
|
589
|
+
for (var _i = 0, _k = Object.keys(node.content.attrs); _i < _k.length; _i++) {
|
|
590
|
+
var attrKey = _k[_i];
|
|
591
|
+
var attrValue = node.content.attrs[attrKey];
|
|
592
|
+
if (attrValue.type === 'element') {
|
|
593
|
+
traverseRepeats(attrValue, fn);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
345
597
|
if (node.content.children) {
|
|
346
598
|
node.content.children.forEach(function (child) {
|
|
347
599
|
traverseRepeats(child, fn);
|
|
@@ -356,12 +608,24 @@ export var traverseRepeats = function (node, fn) {
|
|
|
356
608
|
if (node.content.nodes.loading) {
|
|
357
609
|
traverseRepeats(node.content.nodes.loading, fn);
|
|
358
610
|
}
|
|
611
|
+
if (node.content.attrs) {
|
|
612
|
+
for (var _l = 0, _m = Object.keys(node.content.attrs); _l < _m.length; _l++) {
|
|
613
|
+
var attrKey = _m[_l];
|
|
614
|
+
var attrValue = node.content.attrs[attrKey];
|
|
615
|
+
if (attrValue.type === 'element') {
|
|
616
|
+
traverseRepeats(attrValue, fn);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
359
620
|
break;
|
|
360
621
|
case 'cms-list-repeater':
|
|
361
622
|
traverseRepeats(node.content.nodes.list, fn);
|
|
362
623
|
if (node.content.nodes.empty) {
|
|
363
624
|
traverseRepeats(node.content.nodes.empty, fn);
|
|
364
625
|
}
|
|
626
|
+
if (node.content.nodes.loading) {
|
|
627
|
+
traverseRepeats(node.content.nodes.loading, fn);
|
|
628
|
+
}
|
|
365
629
|
break;
|
|
366
630
|
case 'cms-item':
|
|
367
631
|
traverseRepeats(node.content.nodes.success, fn);
|
|
@@ -371,6 +635,35 @@ export var traverseRepeats = function (node, fn) {
|
|
|
371
635
|
if (node.content.nodes.loading) {
|
|
372
636
|
traverseRepeats(node.content.nodes.loading, fn);
|
|
373
637
|
}
|
|
638
|
+
if (node.content.attrs) {
|
|
639
|
+
for (var _o = 0, _p = Object.keys(node.content.attrs); _o < _p.length; _o++) {
|
|
640
|
+
var attrKey = _p[_o];
|
|
641
|
+
var attrValue = node.content.attrs[attrKey];
|
|
642
|
+
if (attrValue.type === 'element') {
|
|
643
|
+
traverseRepeats(attrValue, fn);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
break;
|
|
648
|
+
case 'cms-mixed-type':
|
|
649
|
+
if ((_a = node.content.nodes) === null || _a === void 0 ? void 0 : _a.fallback) {
|
|
650
|
+
traverseRepeats(node.content.nodes.fallback, fn);
|
|
651
|
+
}
|
|
652
|
+
if ((_b = node.content.nodes) === null || _b === void 0 ? void 0 : _b.error) {
|
|
653
|
+
traverseRepeats(node.content.nodes.error, fn);
|
|
654
|
+
}
|
|
655
|
+
Object.keys(((_c = node.content) === null || _c === void 0 ? void 0 : _c.mappings) || {}).forEach(function (key) {
|
|
656
|
+
traverseRepeats(node.content.mappings[key], fn);
|
|
657
|
+
});
|
|
658
|
+
if (node.content.attrs) {
|
|
659
|
+
for (var _q = 0, _r = Object.keys(node.content.attrs); _q < _r.length; _q++) {
|
|
660
|
+
var attrKey = _r[_q];
|
|
661
|
+
var attrValue = node.content.attrs[attrKey];
|
|
662
|
+
if (attrValue.type === 'element') {
|
|
663
|
+
traverseRepeats(attrValue, fn);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
374
667
|
break;
|
|
375
668
|
case 'repeat':
|
|
376
669
|
fn(node.content);
|
|
@@ -384,6 +677,28 @@ export var traverseRepeats = function (node, fn) {
|
|
|
384
677
|
traverseRepeats(node.content.fallback, fn);
|
|
385
678
|
}
|
|
386
679
|
break;
|
|
680
|
+
case 'data-source-item':
|
|
681
|
+
if ((_d = node.content.nodes) === null || _d === void 0 ? void 0 : _d.success) {
|
|
682
|
+
traverseRepeats(node.content.nodes.success, fn);
|
|
683
|
+
}
|
|
684
|
+
if ((_e = node.content.nodes) === null || _e === void 0 ? void 0 : _e.error) {
|
|
685
|
+
traverseRepeats(node.content.nodes.error, fn);
|
|
686
|
+
}
|
|
687
|
+
if ((_f = node.content.nodes) === null || _f === void 0 ? void 0 : _f.loading) {
|
|
688
|
+
traverseRepeats(node.content.nodes.loading, fn);
|
|
689
|
+
}
|
|
690
|
+
break;
|
|
691
|
+
case 'data-source-list':
|
|
692
|
+
if ((_g = node.content.nodes) === null || _g === void 0 ? void 0 : _g.success) {
|
|
693
|
+
traverseRepeats(node.content.nodes.success, fn);
|
|
694
|
+
}
|
|
695
|
+
if ((_h = node.content.nodes) === null || _h === void 0 ? void 0 : _h.error) {
|
|
696
|
+
traverseRepeats(node.content.nodes.error, fn);
|
|
697
|
+
}
|
|
698
|
+
if ((_j = node.content.nodes) === null || _j === void 0 ? void 0 : _j.loading) {
|
|
699
|
+
traverseRepeats(node.content.nodes.loading, fn);
|
|
700
|
+
}
|
|
701
|
+
break;
|
|
387
702
|
case 'static':
|
|
388
703
|
case 'dynamic':
|
|
389
704
|
case 'raw':
|
|
@@ -504,11 +819,11 @@ export var transformStylesAssignmentsToJson = function (styleObject) {
|
|
|
504
819
|
acc[key] = styleContentAtKey;
|
|
505
820
|
return acc;
|
|
506
821
|
}
|
|
507
|
-
if (type === 'dynamic') {
|
|
822
|
+
if (type === 'dynamic' && content.referenceType !== 'global') {
|
|
508
823
|
if (['state', 'prop'].includes(content === null || content === void 0 ? void 0 : content.referenceType)) {
|
|
509
824
|
acc[key] = {
|
|
510
825
|
type: type,
|
|
511
|
-
content: __assign(__assign({}, content), { id:
|
|
826
|
+
content: __assign(__assign({}, content), { id: generateIdWithRefPath(content.id, content.refPath) }),
|
|
512
827
|
};
|
|
513
828
|
}
|
|
514
829
|
else {
|
|
@@ -521,6 +836,20 @@ export var transformStylesAssignmentsToJson = function (styleObject) {
|
|
|
521
836
|
}, newStyleObject);
|
|
522
837
|
return newStyleObject;
|
|
523
838
|
};
|
|
839
|
+
export var generateIdWithRefPath = function (contentId, refPath) {
|
|
840
|
+
var processedId = contentId;
|
|
841
|
+
if (refPath) {
|
|
842
|
+
var processedRefPath = refPath.reduce(function (acc, path) {
|
|
843
|
+
return "".concat(acc, "?.['").concat(path, "']");
|
|
844
|
+
}, '');
|
|
845
|
+
// This is a bit ugly, but in some cases props are parsed twice or already generated.
|
|
846
|
+
// To avoid possible bugs, this should be a good safety measure
|
|
847
|
+
if (!processedId.includes(processedRefPath)) {
|
|
848
|
+
processedId = "".concat(processedId).concat(processedRefPath);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return StringUtils.createStateOrPropStoringValue(processedId);
|
|
852
|
+
};
|
|
524
853
|
/*
|
|
525
854
|
All the props passed to the components are transformed to a unique case
|
|
526
855
|
to minimize the collision of using cameCalse in one place and dashCase in
|
|
@@ -539,34 +868,47 @@ export var transformAttributesAssignmentsToJson = function (attributesObject, is
|
|
|
539
868
|
return acc;
|
|
540
869
|
}
|
|
541
870
|
if (!Array.isArray(attributeContent) && entityType === 'object') {
|
|
542
|
-
// if this value is already properly declared, make sure it is not
|
|
543
871
|
var type = attributeContent.type;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
return acc;
|
|
555
|
-
}
|
|
556
|
-
var content = attributeContent.content;
|
|
557
|
-
if (type === 'dynamic') {
|
|
558
|
-
if (['state', 'prop'].includes(content === null || content === void 0 ? void 0 : content.referenceType)) {
|
|
872
|
+
switch (type) {
|
|
873
|
+
case 'import':
|
|
874
|
+
case 'static':
|
|
875
|
+
case 'raw':
|
|
876
|
+
case 'expr': {
|
|
877
|
+
var propKey = isLocalComponent ? StringUtils.createStateOrPropStoringValue(key) : key;
|
|
878
|
+
acc[propKey] = attributeContent;
|
|
879
|
+
return acc;
|
|
880
|
+
}
|
|
881
|
+
case 'comp-style': {
|
|
559
882
|
acc[key] = {
|
|
560
|
-
type:
|
|
561
|
-
content:
|
|
883
|
+
type: 'comp-style',
|
|
884
|
+
content: StringUtils.createStateOrPropStoringValue(attributeContent.content),
|
|
562
885
|
};
|
|
886
|
+
return acc;
|
|
563
887
|
}
|
|
564
|
-
|
|
888
|
+
case 'dynamic': {
|
|
889
|
+
var content = attributeContent.content;
|
|
890
|
+
// global id's dont need to be transformed. As they are constants and each one is handled by the generator
|
|
891
|
+
// depending on the context and the framework.
|
|
892
|
+
if (['state', 'prop'].includes(content === null || content === void 0 ? void 0 : content.referenceType) &&
|
|
893
|
+
content.referenceType !== 'global') {
|
|
894
|
+
acc[key] = {
|
|
895
|
+
type: type,
|
|
896
|
+
content: __assign(__assign({}, content), { id: generateIdWithRefPath(content.id, content.refPath) }),
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
acc[key] = attributeContent;
|
|
901
|
+
}
|
|
902
|
+
return acc;
|
|
903
|
+
}
|
|
904
|
+
case 'object':
|
|
905
|
+
case 'element':
|
|
565
906
|
acc[key] = attributeContent;
|
|
907
|
+
return acc;
|
|
908
|
+
default: {
|
|
909
|
+
throw new Error("transformAttributesAssignmentsToJson encountered a style value that is not supported ".concat(JSON.stringify(attributeContent, null, 2)));
|
|
566
910
|
}
|
|
567
|
-
return acc;
|
|
568
911
|
}
|
|
569
|
-
throw new Error("transformAttributesAssignmentsToJson encountered a style value that is not supported ".concat(JSON.stringify(attributeContent, null, 2)));
|
|
570
912
|
}
|
|
571
913
|
}, newAttrObject);
|
|
572
914
|
return newAttrObject;
|
|
@@ -588,6 +930,7 @@ export var findFirstElementNode = function (node) {
|
|
|
588
930
|
}
|
|
589
931
|
};
|
|
590
932
|
export var removeChildNodes = function (node, criteria) {
|
|
933
|
+
var _a, _b, _c;
|
|
591
934
|
switch (node.type) {
|
|
592
935
|
case 'element':
|
|
593
936
|
if (node.content.children) {
|
|
@@ -614,6 +957,9 @@ export var removeChildNodes = function (node, criteria) {
|
|
|
614
957
|
if (node.content.nodes.empty) {
|
|
615
958
|
removeChildNodes(node.content.nodes.empty, criteria);
|
|
616
959
|
}
|
|
960
|
+
if (node.content.nodes.loading) {
|
|
961
|
+
removeChildNodes(node.content.nodes.loading, criteria);
|
|
962
|
+
}
|
|
617
963
|
break;
|
|
618
964
|
case 'cms-item':
|
|
619
965
|
removeChildNodes(node.content.nodes.success, criteria);
|
|
@@ -624,6 +970,17 @@ export var removeChildNodes = function (node, criteria) {
|
|
|
624
970
|
removeChildNodes(node.content.nodes.loading, criteria);
|
|
625
971
|
}
|
|
626
972
|
break;
|
|
973
|
+
case 'cms-mixed-type':
|
|
974
|
+
if ((_a = node.content.nodes) === null || _a === void 0 ? void 0 : _a.fallback) {
|
|
975
|
+
removeChildNodes(node.content.nodes.fallback, criteria);
|
|
976
|
+
}
|
|
977
|
+
if ((_b = node.content.nodes) === null || _b === void 0 ? void 0 : _b.error) {
|
|
978
|
+
removeChildNodes(node.content.nodes.error, criteria);
|
|
979
|
+
}
|
|
980
|
+
Object.keys(((_c = node.content) === null || _c === void 0 ? void 0 : _c.mappings) || {}).forEach(function (key) {
|
|
981
|
+
removeChildNodes(node.content.mappings[key], criteria);
|
|
982
|
+
});
|
|
983
|
+
break;
|
|
627
984
|
case 'conditional':
|
|
628
985
|
removeChildNodes(node.content.node, criteria);
|
|
629
986
|
break;
|