@builder.io/mitosis 0.5.6 → 0.5.8
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/builder/generator.js +55 -11
- package/dist/src/generators/context/angular.js +3 -1
- package/dist/src/generators/context/helpers/context-with-symbol-key.js +3 -1
- package/dist/src/generators/context/qwik.js +3 -1
- package/dist/src/generators/context/react.js +3 -1
- package/dist/src/generators/context/rsc.js +3 -1
- package/dist/src/generators/context/solid.js +3 -1
- package/dist/src/generators/context/svelte.js +3 -1
- package/dist/src/generators/mitosis/generator.js +54 -16
- package/dist/src/generators/react/generator.js +3 -1
- package/dist/src/generators/solid/blocks.d.ts +1 -5
- package/dist/src/generators/solid/blocks.js +22 -11
- package/dist/src/generators/solid/index.js +1 -1
- package/package.json +1 -1
|
@@ -85,7 +85,6 @@ const componentMappers = {
|
|
|
85
85
|
];
|
|
86
86
|
block.children.forEach((item) => {
|
|
87
87
|
var _a;
|
|
88
|
-
console.log('item', item);
|
|
89
88
|
if (item.component && validFakeNodeNames.includes((_a = item.component) === null || _a === void 0 ? void 0 : _a.name)) {
|
|
90
89
|
let query;
|
|
91
90
|
if (item.component.options.query) {
|
|
@@ -163,18 +162,56 @@ const componentMappers = {
|
|
|
163
162
|
}, options);
|
|
164
163
|
},
|
|
165
164
|
Show(node, options) {
|
|
166
|
-
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
|
+
}
|
|
167
206
|
return el({
|
|
168
207
|
// TODO: the reverse mapping for this
|
|
169
208
|
component: {
|
|
170
209
|
name: 'Core:Fragment',
|
|
171
210
|
},
|
|
172
211
|
bindings: {
|
|
173
|
-
show: (
|
|
212
|
+
show: (_c = node.bindings.when) === null || _c === void 0 ? void 0 : _c.code,
|
|
174
213
|
},
|
|
175
|
-
children:
|
|
176
|
-
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
177
|
-
.map((node) => (0, exports.blockToBuilder)(node, options)),
|
|
214
|
+
children: [],
|
|
178
215
|
}, options);
|
|
179
216
|
},
|
|
180
217
|
};
|
|
@@ -202,7 +239,7 @@ function tryFormat(code) {
|
|
|
202
239
|
return str;
|
|
203
240
|
}
|
|
204
241
|
const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
205
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
242
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
206
243
|
const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
|
|
207
244
|
if (mapper) {
|
|
208
245
|
return mapper(json, options);
|
|
@@ -252,16 +289,21 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
252
289
|
componentOptions[key] = parsed;
|
|
253
290
|
}
|
|
254
291
|
else {
|
|
255
|
-
|
|
292
|
+
if (!((_f = json.slots) === null || _f === void 0 ? void 0 : _f[key])) {
|
|
293
|
+
builderBindings[`component.options.${key}`] = bindings[key].code;
|
|
294
|
+
}
|
|
256
295
|
}
|
|
257
296
|
}
|
|
258
297
|
}
|
|
259
|
-
const
|
|
298
|
+
for (const key in json.slots) {
|
|
299
|
+
componentOptions[key] = json.slots[key].map((node) => (0, exports.blockToBuilder)(node, options));
|
|
300
|
+
}
|
|
301
|
+
const hasCss = !!((_g = bindings.css) === null || _g === void 0 ? void 0 : _g.code);
|
|
260
302
|
let responsiveStyles = {
|
|
261
303
|
large: {},
|
|
262
304
|
};
|
|
263
305
|
if (hasCss) {
|
|
264
|
-
const cssRules = json5_1.default.parse((
|
|
306
|
+
const cssRules = json5_1.default.parse((_h = bindings.css) === null || _h === void 0 ? void 0 : _h.code);
|
|
265
307
|
const cssRuleKeys = Object.keys(cssRules);
|
|
266
308
|
for (const ruleKey of cssRuleKeys) {
|
|
267
309
|
const mediaQueryMatch = ruleKey.match(media_sizes_1.mediaQueryRegex);
|
|
@@ -285,7 +327,9 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
285
327
|
}
|
|
286
328
|
if (thisIsComponent) {
|
|
287
329
|
for (const key in json.bindings) {
|
|
288
|
-
|
|
330
|
+
if (!((_j = json.slots) === null || _j === void 0 ? void 0 : _j[key])) {
|
|
331
|
+
builderBindings[`component.options.${key}`] = json.bindings[key].code;
|
|
332
|
+
}
|
|
289
333
|
}
|
|
290
334
|
}
|
|
291
335
|
return el({
|
|
@@ -22,7 +22,9 @@ const getContextWithSymbolKey = (options) => ({ context }) => {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
catch (err) {
|
|
25
|
-
|
|
25
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
26
|
+
console.error('Format error for file:', str);
|
|
27
|
+
}
|
|
26
28
|
throw err;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
@@ -18,7 +18,9 @@ const contextToQwik = (options = {}) => ({ context }) => {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
catch (err) {
|
|
21
|
-
|
|
21
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
22
|
+
console.error('Format error for file:', str);
|
|
23
|
+
}
|
|
22
24
|
throw err;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -19,7 +19,9 @@ const contextToReact = (options = { typescript: false, preact: false }) => ({ co
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
catch (err) {
|
|
22
|
-
|
|
22
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
23
|
+
console.error('Format error for file:', str);
|
|
24
|
+
}
|
|
23
25
|
throw err;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -19,7 +19,9 @@ const contextToSolid = (options = {}) => ({ context }) => {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
catch (err) {
|
|
22
|
-
|
|
22
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
23
|
+
console.error('Format error for file:', str);
|
|
24
|
+
}
|
|
23
25
|
throw err;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -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,7 +113,10 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
94
113
|
}
|
|
95
114
|
}
|
|
96
115
|
for (const key in json.bindings) {
|
|
97
|
-
const value = (
|
|
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]) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
98
120
|
if (((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.type) === 'spread') {
|
|
99
121
|
str += ` {...(${(_h = json.bindings[key]) === null || _h === void 0 ? void 0 : _h.code})} `;
|
|
100
122
|
}
|
|
@@ -110,6 +132,20 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
110
132
|
}
|
|
111
133
|
}
|
|
112
134
|
}
|
|
135
|
+
for (const key in json.slots) {
|
|
136
|
+
const value = json.slots[key];
|
|
137
|
+
str += ` ${key}={`;
|
|
138
|
+
if (value.length > 1) {
|
|
139
|
+
str += '<>';
|
|
140
|
+
}
|
|
141
|
+
str += json.slots[key]
|
|
142
|
+
.map((item) => (0, exports.blockToMitosis)(item, options, component, insideJsx))
|
|
143
|
+
.join('\n');
|
|
144
|
+
if (value.length > 1) {
|
|
145
|
+
str += '</>';
|
|
146
|
+
}
|
|
147
|
+
str += `}`;
|
|
148
|
+
}
|
|
113
149
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
114
150
|
return str + ' />';
|
|
115
151
|
}
|
|
@@ -228,7 +264,9 @@ const componentToMitosis = (toMitosisOptions = {}) => ({ component }) => {
|
|
|
228
264
|
});
|
|
229
265
|
}
|
|
230
266
|
catch (err) {
|
|
231
|
-
|
|
267
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
268
|
+
console.error('Format error for file:', str, JSON.stringify(json, null, 2));
|
|
269
|
+
}
|
|
232
270
|
throw err;
|
|
233
271
|
}
|
|
234
272
|
}
|
|
@@ -204,7 +204,9 @@ const componentToReact = (reactOptions = {}) => ({ component, path }) => {
|
|
|
204
204
|
.replace(/;\n\nimport\s/g, ';\nimport ');
|
|
205
205
|
}
|
|
206
206
|
catch (err) {
|
|
207
|
-
|
|
207
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
208
|
+
console.error('Format error for file:', str);
|
|
209
|
+
}
|
|
208
210
|
throw err;
|
|
209
211
|
}
|
|
210
212
|
}
|
|
@@ -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>`
|