@builder.io/mitosis 0.11.6 → 0.12.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.
|
@@ -462,147 +462,6 @@ const componentMappers = {
|
|
|
462
462
|
children: (block.children || []).map((child) => (0, exports.builderElementToMitosisNode)(updateBindings(child, 'state.$index', 'index'), options)),
|
|
463
463
|
});
|
|
464
464
|
},
|
|
465
|
-
Text: (block, options) => {
|
|
466
|
-
var _a, _b, _c;
|
|
467
|
-
let css = getCssFromBlock(block);
|
|
468
|
-
const styleString = (0, exports.getStyleStringFromBlock)(block, options);
|
|
469
|
-
const actionBindings = getActionBindingsFromBlock(block, options);
|
|
470
|
-
const localizedValues = {};
|
|
471
|
-
const blockBindings = {
|
|
472
|
-
...mapBuilderBindingsToMitosisBindingWithCode(block.bindings, options),
|
|
473
|
-
...mapBuilderBindingsToMitosisBindingWithCode((_a = block.code) === null || _a === void 0 ? void 0 : _a.bindings, options),
|
|
474
|
-
};
|
|
475
|
-
const bindings = {
|
|
476
|
-
...(0, lodash_1.omitBy)(blockBindings, (value, key) => {
|
|
477
|
-
if (key === 'component.options.text') {
|
|
478
|
-
return true;
|
|
479
|
-
}
|
|
480
|
-
if (key && key.includes('style')) {
|
|
481
|
-
return true;
|
|
482
|
-
}
|
|
483
|
-
return false;
|
|
484
|
-
}),
|
|
485
|
-
...actionBindings,
|
|
486
|
-
...(styleString && {
|
|
487
|
-
style: { code: styleString },
|
|
488
|
-
}),
|
|
489
|
-
...(Object.keys(css).length && {
|
|
490
|
-
css: { code: JSON.stringify(css) },
|
|
491
|
-
}),
|
|
492
|
-
};
|
|
493
|
-
const properties = { ...block.properties };
|
|
494
|
-
for (const key in properties) {
|
|
495
|
-
if (typeof properties[key] === 'object' &&
|
|
496
|
-
properties[key] !== null &&
|
|
497
|
-
properties[key]['@type'] === '@builder.io/core:LocalizedValue') {
|
|
498
|
-
const localizedValue = properties[key];
|
|
499
|
-
localizedValues[`properties.${key}`] = localizedValue;
|
|
500
|
-
properties[key] = localizedValue.Default;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
if (options.includeBuilderExtras && block.id)
|
|
504
|
-
properties['builder-id'] = block.id;
|
|
505
|
-
if (block.class)
|
|
506
|
-
properties['class'] = block.class;
|
|
507
|
-
if (block.layerName) {
|
|
508
|
-
properties.$name = block.layerName;
|
|
509
|
-
}
|
|
510
|
-
// Add data attributes for Builder layer properties
|
|
511
|
-
const dataAttributes = {};
|
|
512
|
-
if (block.layerLocked !== undefined) {
|
|
513
|
-
dataAttributes['data-builder-layerLocked'] = String(block.layerLocked);
|
|
514
|
-
}
|
|
515
|
-
if (block.groupLocked !== undefined) {
|
|
516
|
-
dataAttributes['data-builder-groupLocked'] = String(block.groupLocked);
|
|
517
|
-
}
|
|
518
|
-
const innerBindings = {};
|
|
519
|
-
const componentOptionsText = blockBindings['component.options.text'];
|
|
520
|
-
if (componentOptionsText) {
|
|
521
|
-
innerBindings[options.preserveTextBlocks ? 'innerHTML' : '_text'] = (0, bindings_1.createSingleBinding)({
|
|
522
|
-
code: wrapBindingIfNeeded(componentOptionsText.code, options),
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
let text = ((_b = block.component.options) === null || _b === void 0 ? void 0 : _b.text) || '';
|
|
526
|
-
if (typeof text === 'object' &&
|
|
527
|
-
text !== null &&
|
|
528
|
-
text['@type'] === '@builder.io/core:LocalizedValue') {
|
|
529
|
-
localizedValues['component.options.text'] = (_c = block.component.options) === null || _c === void 0 ? void 0 : _c.text;
|
|
530
|
-
text = text.Default;
|
|
531
|
-
}
|
|
532
|
-
// Builder uses {{}} for bindings, but Mitosis expects {} so we need to convert
|
|
533
|
-
const innerProperties = innerBindings._text
|
|
534
|
-
? {}
|
|
535
|
-
: {
|
|
536
|
-
[options.preserveTextBlocks ? 'innerHTML' : '_text']: text.replace(/\{\{(.*?)\}\}/g, '{$1}'),
|
|
537
|
-
};
|
|
538
|
-
if (options.preserveTextBlocks) {
|
|
539
|
-
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
540
|
-
name: block.tagName || 'div',
|
|
541
|
-
bindings,
|
|
542
|
-
properties: {
|
|
543
|
-
...properties,
|
|
544
|
-
...dataAttributes,
|
|
545
|
-
},
|
|
546
|
-
meta: (0, exports.getMetaFromBlock)(block, options),
|
|
547
|
-
...(Object.keys(localizedValues).length && { localizedValues }),
|
|
548
|
-
children: [
|
|
549
|
-
(0, create_mitosis_node_1.createMitosisNode)({
|
|
550
|
-
bindings: innerBindings,
|
|
551
|
-
properties: {
|
|
552
|
-
...innerProperties,
|
|
553
|
-
class: 'builder-text',
|
|
554
|
-
},
|
|
555
|
-
...(Object.keys(localizedValues).length && { localizedValues }),
|
|
556
|
-
}),
|
|
557
|
-
],
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
// Disabling for now
|
|
561
|
-
const assumeLink = false;
|
|
562
|
-
const finalProperties = {
|
|
563
|
-
...(assumeLink
|
|
564
|
-
? {
|
|
565
|
-
href: '...',
|
|
566
|
-
}
|
|
567
|
-
: {}),
|
|
568
|
-
...properties,
|
|
569
|
-
...dataAttributes,
|
|
570
|
-
};
|
|
571
|
-
const finalTagname = block.tagName || (assumeLink ? 'a' : 'div');
|
|
572
|
-
if ((block.tagName && block.tagName !== 'div') ||
|
|
573
|
-
hasStyles(block) ||
|
|
574
|
-
hasComponent(block) ||
|
|
575
|
-
hasBindings(block) ||
|
|
576
|
-
hasProperties(block)) {
|
|
577
|
-
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
578
|
-
name: finalTagname,
|
|
579
|
-
bindings,
|
|
580
|
-
properties: finalProperties,
|
|
581
|
-
meta: (0, exports.getMetaFromBlock)(block, options),
|
|
582
|
-
children: [
|
|
583
|
-
(0, create_mitosis_node_1.createMitosisNode)({
|
|
584
|
-
bindings: innerBindings,
|
|
585
|
-
properties: innerProperties,
|
|
586
|
-
...(Object.keys(localizedValues).length && { localizedValues }),
|
|
587
|
-
}),
|
|
588
|
-
],
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
592
|
-
name: finalTagname,
|
|
593
|
-
properties: {
|
|
594
|
-
...finalProperties,
|
|
595
|
-
...properties,
|
|
596
|
-
...innerProperties,
|
|
597
|
-
},
|
|
598
|
-
bindings: {
|
|
599
|
-
...bindings,
|
|
600
|
-
...innerBindings,
|
|
601
|
-
},
|
|
602
|
-
meta: (0, exports.getMetaFromBlock)(block, options),
|
|
603
|
-
...(Object.keys(localizedValues).length && { localizedValues }),
|
|
604
|
-
});
|
|
605
|
-
},
|
|
606
465
|
};
|
|
607
466
|
const processBoundLogic = (code) => {
|
|
608
467
|
const ast = babel.parse(code);
|
|
@@ -625,7 +484,7 @@ const processBoundLogic = (code) => {
|
|
|
625
484
|
return code;
|
|
626
485
|
};
|
|
627
486
|
const builderElementToMitosisNode = (block, options, _internalOptions = {}) => {
|
|
628
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v
|
|
487
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
629
488
|
const { includeSpecialBindings = true } = options;
|
|
630
489
|
const localizedValues = {};
|
|
631
490
|
if (((_a = block.component) === null || _a === void 0 ? void 0 : _a.name) === 'Core:Fragment') {
|
|
@@ -904,33 +763,6 @@ const builderElementToMitosisNode = (block, options, _internalOptions = {}) => {
|
|
|
904
763
|
},
|
|
905
764
|
...(Object.keys(localizedValues).length && { localizedValues }),
|
|
906
765
|
});
|
|
907
|
-
// Has single text node child
|
|
908
|
-
const firstChild = (_w = block.children) === null || _w === void 0 ? void 0 : _w[0];
|
|
909
|
-
if (((_x = block.children) === null || _x === void 0 ? void 0 : _x.length) === 1 &&
|
|
910
|
-
((_y = firstChild === null || firstChild === void 0 ? void 0 : firstChild.component) === null || _y === void 0 ? void 0 : _y.name) === 'Text' &&
|
|
911
|
-
!options.preserveTextBlocks) {
|
|
912
|
-
const textProperties = (0, exports.builderElementToMitosisNode)(firstChild, options);
|
|
913
|
-
const parsedNodeCss = json5_1.default.parse(((_z = node.bindings.css) === null || _z === void 0 ? void 0 : _z.code) || '{}');
|
|
914
|
-
const parsedTextCss = json5_1.default.parse(((_0 = textProperties.bindings.css) === null || _0 === void 0 ? void 0 : _0.code) || '{}');
|
|
915
|
-
const mergedCss = combineStyles(parsedNodeCss, parsedTextCss);
|
|
916
|
-
// Don't merge if text has styling that matters
|
|
917
|
-
const doNotMerge =
|
|
918
|
-
// Text has flex alignment
|
|
919
|
-
['end', 'right', 'center'].includes(parsedTextCss.alignSelf) ||
|
|
920
|
-
// Text has specific styling
|
|
921
|
-
parsedTextCss.backgroundColor ||
|
|
922
|
-
parsedTextCss.opacity ||
|
|
923
|
-
parsedTextCss.background;
|
|
924
|
-
if (!doNotMerge) {
|
|
925
|
-
return (0, lodash_1.merge)({}, textProperties, node, {
|
|
926
|
-
bindings: {
|
|
927
|
-
...(Object.keys(mergedCss).length && {
|
|
928
|
-
css: { code: json5_1.default.stringify(mergedCss) },
|
|
929
|
-
}),
|
|
930
|
-
},
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
766
|
node.children = children.concat((block.children || []).map((item) => (0, exports.builderElementToMitosisNode)(item, options)));
|
|
935
767
|
return node;
|
|
936
768
|
};
|
|
@@ -492,6 +492,52 @@ exports.components = {
|
|
|
492
492
|
});
|
|
493
493
|
return wrapOutput(node, videoContainer, components);
|
|
494
494
|
},
|
|
495
|
+
Text: (node) => {
|
|
496
|
+
if (node.properties.text) {
|
|
497
|
+
node.properties._text = node.properties.text;
|
|
498
|
+
delete node.properties.text;
|
|
499
|
+
}
|
|
500
|
+
if (node.bindings.text) {
|
|
501
|
+
node.bindings._text = node.bindings.text;
|
|
502
|
+
delete node.bindings.text;
|
|
503
|
+
}
|
|
504
|
+
const { _text: propText, $tagName: nodeTagName, ...outerProps } = node.properties;
|
|
505
|
+
const { _text: bindingText, ...outerBindings } = node.bindings;
|
|
506
|
+
const hasBindings = Object.keys(outerProps).length > 0;
|
|
507
|
+
const hasProperties = Object.keys(outerBindings).length > 0;
|
|
508
|
+
/**
|
|
509
|
+
* If there are things we need to reflect on the text then we must
|
|
510
|
+
* render a wrapper div so we can put it on that element.
|
|
511
|
+
*/
|
|
512
|
+
if (hasBindings || hasProperties) {
|
|
513
|
+
/**
|
|
514
|
+
* Text binding needs to be on the inner text node. Some generators
|
|
515
|
+
* will skip rendering other bindings if they see a _text binding,
|
|
516
|
+
* so the _text binding needs to go on the inner text node, and all
|
|
517
|
+
* other bindings need to go on the wrapper div so they get generated.
|
|
518
|
+
*/
|
|
519
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
520
|
+
name: 'div',
|
|
521
|
+
bindings: outerBindings,
|
|
522
|
+
properties: outerProps,
|
|
523
|
+
children: [
|
|
524
|
+
(0, create_mitosis_node_1.createMitosisNode)({
|
|
525
|
+
...node,
|
|
526
|
+
properties: {
|
|
527
|
+
$tagName: nodeTagName,
|
|
528
|
+
...(propText ? { _text: propText } : {}),
|
|
529
|
+
},
|
|
530
|
+
bindings: bindingText ? { _text: bindingText } : {},
|
|
531
|
+
name: nodeTagName !== null && nodeTagName !== void 0 ? nodeTagName : 'div',
|
|
532
|
+
}),
|
|
533
|
+
],
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
537
|
+
...node,
|
|
538
|
+
name: nodeTagName !== null && nodeTagName !== void 0 ? nodeTagName : 'div',
|
|
539
|
+
});
|
|
540
|
+
},
|
|
495
541
|
};
|
|
496
542
|
const compileAwayBuilderComponentsFromTree = (tree, components) => {
|
|
497
543
|
(0, legacy_1.default)(tree).forEach(function (item) {
|