@builder.io/mitosis 0.0.145 → 0.0.147
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/dist/src/generators/react/blocks.js +10 -4
- package/dist/src/generators/react/generator.js +1 -1
- package/dist/src/generators/vue/compositionApi.js +1 -2
- package/dist/src/helpers/filter-empty-text-nodes.d.ts +1 -0
- package/dist/src/helpers/filter-empty-text-nodes.js +5 -3
- package/dist/src/helpers/is-root-text-node.js +1 -1
- package/dist/src/parsers/builder/builder.d.ts +1 -0
- package/dist/src/parsers/builder/builder.js +16 -16
- package/dist/src/parsers/jsx/jsx.js +5 -0
- package/package.json +1 -1
|
@@ -59,13 +59,13 @@ var NODE_MAPPERS = {
|
|
|
59
59
|
return '';
|
|
60
60
|
}
|
|
61
61
|
var children = (0, helpers_1.processBinding)('props.children', options);
|
|
62
|
-
return "{".concat(children, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}");
|
|
62
|
+
return "<>{".concat(children, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}</>");
|
|
63
63
|
}
|
|
64
64
|
var slotProp = (0, helpers_1.processBinding)(slotName, options).replace('name=', '');
|
|
65
65
|
if (!slotProp.startsWith('props.')) {
|
|
66
66
|
slotProp = "props.".concat(slotProp);
|
|
67
67
|
}
|
|
68
|
-
return "{".concat(slotProp, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}");
|
|
68
|
+
return "<>{".concat(slotProp, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}</>");
|
|
69
69
|
},
|
|
70
70
|
Fragment: function (json, options, component) {
|
|
71
71
|
var wrap = (0, helpers_1.wrapInFragment)(json);
|
|
@@ -85,7 +85,12 @@ var NODE_MAPPERS = {
|
|
|
85
85
|
},
|
|
86
86
|
Show: function (json, options, component) {
|
|
87
87
|
var _a;
|
|
88
|
-
var wrap = (0, helpers_1.wrapInFragment)(json) ||
|
|
88
|
+
var wrap = (0, helpers_1.wrapInFragment)(json) ||
|
|
89
|
+
(0, is_root_text_node_1.isRootTextNode)(json) ||
|
|
90
|
+
component.children[0] === json ||
|
|
91
|
+
// when `<Show><For>...</For></Show>`, we need to wrap the For generated code in a fragment
|
|
92
|
+
// since it's a `.map()` call
|
|
93
|
+
(json.children.length === 1 && ['For', 'Show'].includes(json.children[0].name));
|
|
89
94
|
var wrapElse = json.meta.else &&
|
|
90
95
|
((0, helpers_1.wrapInFragment)(json.meta.else) || (0, mitosis_node_1.checkIsForNode)(json.meta.else));
|
|
91
96
|
return "{".concat((0, helpers_1.processBinding)((_a = json.bindings.when) === null || _a === void 0 ? void 0 : _a.code, options), " ? (\n ").concat(wrap ? (0, helpers_1.openFrag)(options) : '').concat(json.children
|
|
@@ -123,6 +128,7 @@ var BINDING_MAPPERS = __assign({ ref: function (ref, value, options) {
|
|
|
123
128
|
} }, ATTTRIBUTE_MAPPERS);
|
|
124
129
|
var blockToReact = function (json, options, component, parentSlots) {
|
|
125
130
|
var _a, _b, _c;
|
|
131
|
+
if (parentSlots === void 0) { parentSlots = []; }
|
|
126
132
|
if (NODE_MAPPERS[json.name]) {
|
|
127
133
|
return NODE_MAPPERS[json.name](json, options, component, parentSlots);
|
|
128
134
|
}
|
|
@@ -219,7 +225,7 @@ var blockToReact = function (json, options, component, parentSlots) {
|
|
|
219
225
|
if (json.children) {
|
|
220
226
|
childrenNodes = json.children
|
|
221
227
|
.map(function (item) { return (0, exports.blockToReact)(item, options, component, needsToRenderSlots); })
|
|
222
|
-
.join('
|
|
228
|
+
.join('');
|
|
223
229
|
}
|
|
224
230
|
if (needsToRenderSlots.length) {
|
|
225
231
|
needsToRenderSlots.forEach(function (_a) {
|
|
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.generateCompositionApiScript = void 0;
|
|
11
11
|
var dedent_1 = require("../../helpers/dedent");
|
|
12
12
|
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
13
|
-
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
14
13
|
var json5_1 = __importDefault(require("json5"));
|
|
15
14
|
var lodash_1 = require("lodash");
|
|
16
15
|
var helpers_1 = require("./helpers");
|
|
@@ -93,7 +92,7 @@ function generateCompositionApiScript(component, options, template, props, onUpd
|
|
|
93
92
|
code: hook.deps || '',
|
|
94
93
|
options: options,
|
|
95
94
|
json: component,
|
|
96
|
-
}), ", (
|
|
95
|
+
}), ", () => { ").concat(hook.code, " }, {immediate: true})");
|
|
97
96
|
}).join('\n')) || '', methods !== null && methods !== void 0 ? methods : '');
|
|
98
97
|
return str;
|
|
99
98
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterEmptyTextNodes = void 0;
|
|
4
|
-
var
|
|
5
|
-
return
|
|
3
|
+
exports.filterEmptyTextNodes = exports.isEmptyTextNode = void 0;
|
|
4
|
+
var isEmptyTextNode = function (node) {
|
|
5
|
+
return typeof node.properties._text === 'string' && node.properties._text.trim().length === 0;
|
|
6
6
|
};
|
|
7
|
+
exports.isEmptyTextNode = isEmptyTextNode;
|
|
8
|
+
var filterEmptyTextNodes = function (node) { return !(0, exports.isEmptyTextNode)(node); };
|
|
7
9
|
exports.filterEmptyTextNodes = filterEmptyTextNodes;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isTextNode = exports.isRootTextNode = void 0;
|
|
4
4
|
function isRootTextNode(json) {
|
|
5
5
|
var firstChild = json.children[0];
|
|
6
|
-
return Boolean(firstChild && isTextNode(firstChild));
|
|
6
|
+
return Boolean(json.children.length === 1 && firstChild && isTextNode(firstChild));
|
|
7
7
|
}
|
|
8
8
|
exports.isRootTextNode = isRootTextNode;
|
|
9
9
|
function isTextNode(node) {
|
|
@@ -11,6 +11,7 @@ type BuilderToMitosisOptions = {
|
|
|
11
11
|
};
|
|
12
12
|
includeBuilderExtras?: boolean;
|
|
13
13
|
preserveTextBlocks?: boolean;
|
|
14
|
+
includeSpecialBindings?: boolean;
|
|
14
15
|
};
|
|
15
16
|
export declare const builderElementToMitosisNode: (block: BuilderElement, options: BuilderToMitosisOptions, _internalOptions?: InternalOptions) => MitosisNode;
|
|
16
17
|
/**
|
|
@@ -417,6 +417,7 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
417
417
|
var _a;
|
|
418
418
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
419
419
|
if (_internalOptions === void 0) { _internalOptions = {}; }
|
|
420
|
+
var _x = options.includeSpecialBindings, includeSpecialBindings = _x === void 0 ? true : _x;
|
|
420
421
|
if (((_b = block.component) === null || _b === void 0 ? void 0 : _b.name) === 'Core:Fragment') {
|
|
421
422
|
block.component.name = 'Fragment';
|
|
422
423
|
}
|
|
@@ -501,9 +502,9 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
501
502
|
}
|
|
502
503
|
var useKey = key.replace(/^(component\.)?options\./, '');
|
|
503
504
|
if (!useKey.includes('.')) {
|
|
504
|
-
bindings[useKey] = {
|
|
505
|
+
bindings[useKey] = (0, bindings_1.createSingleBinding)({
|
|
505
506
|
code: blockBindings[key].code || blockBindings[key],
|
|
506
|
-
};
|
|
507
|
+
});
|
|
507
508
|
}
|
|
508
509
|
else if (useKey.includes('style') && useKey.includes('.')) {
|
|
509
510
|
var styleProperty = useKey.split('.')[1];
|
|
@@ -538,19 +539,18 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
538
539
|
}
|
|
539
540
|
return true;
|
|
540
541
|
})
|
|
541
|
-
.map(function (item) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
bindings: {},
|
|
548
|
-
properties: { name: key },
|
|
549
|
-
children: childrenElements,
|
|
542
|
+
.map(function (item) {
|
|
543
|
+
var node = (0, exports.builderElementToMitosisNode)(item, __assign(__assign({}, options), { includeSpecialBindings: false }));
|
|
544
|
+
// For now, stringify to Mitosis nodes even though that only really works in React, due to syntax overlap.
|
|
545
|
+
// the correct long term solution is to hold on to the Mitosis Node, and have a plugin for each framework
|
|
546
|
+
// which processes any Mitosis nodes set into the attribute and moves them as slots when relevant (Svelte/Vue)
|
|
547
|
+
return (0, __1.blockToMitosis)(node, {}, null);
|
|
550
548
|
});
|
|
549
|
+
var strVal = childrenElements.length === 1 ? childrenElements[0] : "<>".concat(childrenElements.join(''), "</>");
|
|
550
|
+
bindings[key] = (0, bindings_1.createSingleBinding)({ code: strVal });
|
|
551
551
|
}
|
|
552
552
|
else {
|
|
553
|
-
bindings[key] = { code: json5_1.default.stringify(value) };
|
|
553
|
+
bindings[key] = (0, bindings_1.createSingleBinding)({ code: json5_1.default.stringify(value) });
|
|
554
554
|
}
|
|
555
555
|
}
|
|
556
556
|
}
|
|
@@ -564,19 +564,19 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
564
564
|
if (binding.startsWith('component.options') || binding.startsWith('options')) {
|
|
565
565
|
var value = blockBindings[binding];
|
|
566
566
|
var useKey = binding.replace(/^(component\.options\.|options\.)/, '');
|
|
567
|
-
bindings[useKey] = { code: value };
|
|
567
|
+
bindings[useKey] = (0, bindings_1.createSingleBinding)({ code: value });
|
|
568
568
|
}
|
|
569
569
|
}
|
|
570
570
|
var node = (0, create_mitosis_node_1.createMitosisNode)({
|
|
571
571
|
name: ((_r = (_q = block.component) === null || _q === void 0 ? void 0 : _q.name) === null || _r === void 0 ? void 0 : _r.replace(/[^a-z0-9]/gi, '')) ||
|
|
572
572
|
block.tagName ||
|
|
573
573
|
(block.linkUrl ? 'a' : 'div'),
|
|
574
|
-
properties: __assign(__assign(__assign({}, (block.component && { $tagName: block.tagName })), (block.class && { class: block.class })), properties),
|
|
574
|
+
properties: __assign(__assign(__assign({}, (block.component && includeSpecialBindings && { $tagName: block.tagName })), (block.class && { class: block.class })), properties),
|
|
575
575
|
bindings: __assign(__assign(__assign(__assign({}, bindings), actionBindings), (styleString && {
|
|
576
|
-
style: { code: styleString },
|
|
576
|
+
style: (0, bindings_1.createSingleBinding)({ code: styleString }),
|
|
577
577
|
})), (css &&
|
|
578
578
|
Object.keys(css).length && {
|
|
579
|
-
css: { code: JSON.stringify(css) },
|
|
579
|
+
css: (0, bindings_1.createSingleBinding)({ code: JSON.stringify(css) }),
|
|
580
580
|
})),
|
|
581
581
|
});
|
|
582
582
|
// Has single text node child
|
|
@@ -38,6 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.parseJsx = void 0;
|
|
41
|
+
var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
42
|
+
var traverse_nodes_1 = require("../../helpers/traverse-nodes");
|
|
41
43
|
var babel = __importStar(require("@babel/core"));
|
|
42
44
|
var generator_1 = __importDefault(require("@babel/generator"));
|
|
43
45
|
var plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
|
|
@@ -234,6 +236,9 @@ function parseJsx(jsx, _options) {
|
|
|
234
236
|
mitosisComponent.context.get[context].type = 'reactive';
|
|
235
237
|
});
|
|
236
238
|
}
|
|
239
|
+
(0, traverse_nodes_1.traverseNodes)(mitosisComponent, function (node) {
|
|
240
|
+
node.children = node.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes);
|
|
241
|
+
});
|
|
237
242
|
return mitosisComponent;
|
|
238
243
|
}
|
|
239
244
|
exports.parseJsx = parseJsx;
|