@builder.io/mitosis 0.5.7 → 0.5.9
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.
|
@@ -162,18 +162,56 @@ const componentMappers = {
|
|
|
162
162
|
}, options);
|
|
163
163
|
},
|
|
164
164
|
Show(node, options) {
|
|
165
|
-
var _a;
|
|
165
|
+
var _a, _b, _c;
|
|
166
|
+
const elseCase = node.meta.else;
|
|
167
|
+
const children = node.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes);
|
|
168
|
+
const showNode = children.length > 0
|
|
169
|
+
? el({
|
|
170
|
+
// TODO: the reverse mapping for this
|
|
171
|
+
component: {
|
|
172
|
+
name: 'Core:Fragment',
|
|
173
|
+
},
|
|
174
|
+
bindings: {
|
|
175
|
+
show: (_a = node.bindings.when) === null || _a === void 0 ? void 0 : _a.code,
|
|
176
|
+
},
|
|
177
|
+
children: children.map((node) => (0, exports.blockToBuilder)(node, options)),
|
|
178
|
+
}, options)
|
|
179
|
+
: undefined;
|
|
180
|
+
const elseNode = elseCase && (0, filter_empty_text_nodes_1.filterEmptyTextNodes)(elseCase)
|
|
181
|
+
? el({
|
|
182
|
+
// TODO: the reverse mapping for this
|
|
183
|
+
component: {
|
|
184
|
+
name: 'Core:Fragment',
|
|
185
|
+
},
|
|
186
|
+
bindings: {
|
|
187
|
+
hide: (_b = node.bindings.when) === null || _b === void 0 ? void 0 : _b.code,
|
|
188
|
+
},
|
|
189
|
+
children: [(0, exports.blockToBuilder)(elseCase, options)],
|
|
190
|
+
}, options)
|
|
191
|
+
: undefined;
|
|
192
|
+
if (elseNode && showNode) {
|
|
193
|
+
return el({
|
|
194
|
+
component: {
|
|
195
|
+
name: 'Core:Fragment',
|
|
196
|
+
},
|
|
197
|
+
children: [showNode, elseNode],
|
|
198
|
+
}, options);
|
|
199
|
+
}
|
|
200
|
+
else if (showNode) {
|
|
201
|
+
return showNode;
|
|
202
|
+
}
|
|
203
|
+
else if (elseNode) {
|
|
204
|
+
return elseNode;
|
|
205
|
+
}
|
|
166
206
|
return el({
|
|
167
207
|
// TODO: the reverse mapping for this
|
|
168
208
|
component: {
|
|
169
209
|
name: 'Core:Fragment',
|
|
170
210
|
},
|
|
171
211
|
bindings: {
|
|
172
|
-
show: (
|
|
212
|
+
show: (_c = node.bindings.when) === null || _c === void 0 ? void 0 : _c.code,
|
|
173
213
|
},
|
|
174
|
-
children:
|
|
175
|
-
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
176
|
-
.map((node) => (0, exports.blockToBuilder)(node, options)),
|
|
214
|
+
children: [],
|
|
177
215
|
}, options);
|
|
178
216
|
},
|
|
179
217
|
};
|
|
@@ -365,6 +403,20 @@ const componentToBuilder = (options = {}) => ({ component }) => {
|
|
|
365
403
|
if (value) {
|
|
366
404
|
(0, lodash_1.set)(el, 'component.options.symbol.content', value);
|
|
367
405
|
}
|
|
406
|
+
if (el.bindings) {
|
|
407
|
+
for (const [key, value] of Object.entries(el.bindings)) {
|
|
408
|
+
if (value.match(/\n|;/)) {
|
|
409
|
+
if (!el.code) {
|
|
410
|
+
el.code = {};
|
|
411
|
+
}
|
|
412
|
+
if (!el.code.bindings) {
|
|
413
|
+
el.code.bindings = {};
|
|
414
|
+
}
|
|
415
|
+
el.code.bindings[key] = value;
|
|
416
|
+
el.bindings[key] = ` return ${value}`;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
368
420
|
}
|
|
369
421
|
});
|
|
370
422
|
return result;
|
|
@@ -27,7 +27,7 @@ const isValidAttributeName = (str) => {
|
|
|
27
27
|
return Boolean(str && /^[$a-z0-9\-_:]+$/i.test(str));
|
|
28
28
|
};
|
|
29
29
|
const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
30
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
31
31
|
const options = {
|
|
32
32
|
format: exports.DEFAULT_FORMAT,
|
|
33
33
|
...toMitosisOptions,
|
|
@@ -41,19 +41,29 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
41
41
|
prettier: options.prettier,
|
|
42
42
|
}, component, insideJsx);
|
|
43
43
|
}
|
|
44
|
-
if (
|
|
44
|
+
if ((0, mitosis_node_1.checkIsShowNode)(json)) {
|
|
45
45
|
const when = (_a = json.bindings.when) === null || _a === void 0 ? void 0 : _a.code;
|
|
46
46
|
const elseCase = json.meta.else;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
if (options.nativeConditionals) {
|
|
48
|
+
const needsWrapper = json.children.length !== 1;
|
|
49
|
+
const renderChildren = `${needsWrapper ? '<>' : ''}
|
|
50
|
+
${json.children
|
|
51
|
+
.map((child) => (0, exports.blockToMitosis)(child, options, component, needsWrapper))
|
|
52
|
+
.join('\n')}
|
|
53
|
+
${needsWrapper ? '</>' : ''}`;
|
|
54
|
+
const renderElse = elseCase && (0, is_mitosis_node_1.isMitosisNode)(elseCase)
|
|
55
|
+
? (0, exports.blockToMitosis)(elseCase, options, component, false)
|
|
56
|
+
: 'null';
|
|
57
|
+
return `${insideJsx ? '{' : ''}(${when}) ? ${renderChildren} : ${renderElse}${insideJsx ? '}' : ''}`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const elseHandler = elseCase
|
|
61
|
+
? ` else={${(0, exports.blockToMitosis)(elseCase, options, component, false)}}`
|
|
62
|
+
: '';
|
|
63
|
+
return `<Show when={${when}}${elseHandler}>
|
|
64
|
+
${json.children.map((child) => (0, exports.blockToMitosis)(child, options, component, true)).join('\n')}
|
|
65
|
+
</Show>`;
|
|
66
|
+
}
|
|
57
67
|
}
|
|
58
68
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
59
69
|
const needsWrapper = json.children.length !== 1;
|
|
@@ -66,7 +76,6 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
66
76
|
.join('\n')}
|
|
67
77
|
${needsWrapper ? '</>' : ''}
|
|
68
78
|
))${insideJsx ? '}' : ''}`;
|
|
69
|
-
console.log(a);
|
|
70
79
|
return a;
|
|
71
80
|
}
|
|
72
81
|
return `<For each={${(_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code}}>
|
|
@@ -77,10 +86,20 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
77
86
|
</For>`;
|
|
78
87
|
}
|
|
79
88
|
if (json.properties._text) {
|
|
80
|
-
|
|
89
|
+
if (insideJsx) {
|
|
90
|
+
return `${json.properties._text}`;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return `<>${json.properties._text}</>`;
|
|
94
|
+
}
|
|
81
95
|
}
|
|
82
96
|
if ((_d = json.bindings._text) === null || _d === void 0 ? void 0 : _d.code) {
|
|
83
|
-
|
|
97
|
+
if (insideJsx) {
|
|
98
|
+
return `{${json.bindings._text.code}}`;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return `${json.bindings._text.code}`;
|
|
102
|
+
}
|
|
84
103
|
}
|
|
85
104
|
let str = '';
|
|
86
105
|
str += `<${json.name} `;
|
|
@@ -94,12 +113,12 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
94
113
|
}
|
|
95
114
|
}
|
|
96
115
|
for (const key in json.bindings) {
|
|
97
|
-
const value = (
|
|
98
|
-
if ((
|
|
116
|
+
const value = (_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.code;
|
|
117
|
+
if ((_f = json.slots) === null || _f === void 0 ? void 0 : _f[key]) {
|
|
99
118
|
continue;
|
|
100
119
|
}
|
|
101
|
-
if (((
|
|
102
|
-
str += ` {...(${(
|
|
120
|
+
if (((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.type) === 'spread') {
|
|
121
|
+
str += ` {...(${(_h = json.bindings[key]) === null || _h === void 0 ? void 0 : _h.code})} `;
|
|
103
122
|
}
|
|
104
123
|
else if (key.startsWith('on')) {
|
|
105
124
|
str += ` ${key}={event => ${value.replace(/\s*;$/, '')}} `;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { MitosisComponent } from '../../types/mitosis-component';
|
|
2
2
|
import { MitosisNode } from '../../types/mitosis-node';
|
|
3
3
|
import { ToSolidOptions } from './types';
|
|
4
|
-
export declare const blockToSolid: (
|
|
5
|
-
json: MitosisNode;
|
|
6
|
-
options: ToSolidOptions;
|
|
7
|
-
component: MitosisComponent;
|
|
8
|
-
}) => string;
|
|
4
|
+
export declare const blockToSolid: (json: MitosisNode, component: MitosisComponent, options: ToSolidOptions, insideJsx: boolean) => string;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.blockToSolid = void 0;
|
|
4
4
|
const babel_transform_1 = require("../../helpers/babel-transform");
|
|
5
5
|
const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
6
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
6
7
|
const typescript_1 = require("../../helpers/typescript");
|
|
7
8
|
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
8
9
|
const core_1 = require("@babel/core");
|
|
@@ -17,24 +18,34 @@ const transformAttributeName = (name) => {
|
|
|
17
18
|
return ATTTRIBUTE_MAPPERS[name];
|
|
18
19
|
return name;
|
|
19
20
|
};
|
|
20
|
-
const blockToSolid = (
|
|
21
|
-
var _a, _b;
|
|
22
|
-
if (
|
|
23
|
-
|
|
21
|
+
const blockToSolid = (json, component, options, insideJsx) => {
|
|
22
|
+
var _a, _b, _c;
|
|
23
|
+
if (insideJsx) {
|
|
24
|
+
if (json.properties._text) {
|
|
25
|
+
return json.properties._text;
|
|
26
|
+
}
|
|
27
|
+
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
28
|
+
return `{${json.bindings._text.code}}`;
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
else {
|
|
32
|
+
if (json.properties._text) {
|
|
33
|
+
return `<>${json.properties._text}</>`;
|
|
34
|
+
}
|
|
35
|
+
if ((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code) {
|
|
36
|
+
return `${json.bindings._text.code}`;
|
|
37
|
+
}
|
|
27
38
|
}
|
|
28
39
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
29
40
|
const needsWrapper = json.children.length !== 1;
|
|
30
41
|
// The SolidJS `<For>` component has a special index() signal function.
|
|
31
42
|
// https://www.solidjs.com/docs/latest#%3Cfor%3E
|
|
32
|
-
return `<For each={${(
|
|
43
|
+
return `<For each={${(_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code}}>
|
|
33
44
|
{(${json.scope.forName}, _index) => {
|
|
34
45
|
const ${json.scope.indexName || 'index'} = _index();
|
|
35
46
|
return ${needsWrapper ? '<>' : ''}${json.children
|
|
36
47
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
37
|
-
.map((child) => (0, exports.blockToSolid)(
|
|
48
|
+
.map((child) => (0, exports.blockToSolid)(child, component, options, needsWrapper))}}}
|
|
38
49
|
${needsWrapper ? '</>' : ''}
|
|
39
50
|
</For>`;
|
|
40
51
|
}
|
|
@@ -45,8 +56,8 @@ const blockToSolid = ({ json, options, component, }) => {
|
|
|
45
56
|
else {
|
|
46
57
|
str += `<${json.name} `;
|
|
47
58
|
}
|
|
48
|
-
if (json.name === 'Show' && json.meta.else) {
|
|
49
|
-
str += `fallback={${(0, exports.blockToSolid)(
|
|
59
|
+
if (json.name === 'Show' && (0, is_mitosis_node_1.isMitosisNode)(json.meta.else)) {
|
|
60
|
+
str += `fallback={${(0, exports.blockToSolid)(json.meta.else, component, options, false)}}`;
|
|
50
61
|
}
|
|
51
62
|
const classString = (0, styles_1.collectClassString)(json, options);
|
|
52
63
|
if (classString) {
|
|
@@ -106,7 +117,7 @@ const blockToSolid = ({ json, options, component, }) => {
|
|
|
106
117
|
if (json.children) {
|
|
107
118
|
str += json.children
|
|
108
119
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
109
|
-
.map((item) => (0, exports.blockToSolid)(
|
|
120
|
+
.map((item) => (0, exports.blockToSolid)(item, component, options, true))
|
|
110
121
|
.join('\n');
|
|
111
122
|
}
|
|
112
123
|
if (json.name === 'Fragment') {
|
|
@@ -231,7 +231,7 @@ const componentToSolid = (passedOptions) => ({ component }) => {
|
|
|
231
231
|
return (${addWrapper ? '<>' : ''}
|
|
232
232
|
${json.children
|
|
233
233
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
234
|
-
.map((item) => (0, blocks_1.blockToSolid)(
|
|
234
|
+
.map((item) => (0, blocks_1.blockToSolid)(item, component, options, addWrapper))
|
|
235
235
|
.join('\n')}
|
|
236
236
|
${options.stylesType === 'style-tag' && css && css.trim().length > 4
|
|
237
237
|
? `<style>{\`${css}\`}</style>`
|