@builder.io/mitosis 0.5.5 → 0.5.7
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 +12 -6
- 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 +23 -4
- package/dist/src/generators/react/generator.js +3 -1
- package/dist/src/parsers/jsx/state.js +9 -0
- 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) {
|
|
@@ -202,7 +201,7 @@ function tryFormat(code) {
|
|
|
202
201
|
return str;
|
|
203
202
|
}
|
|
204
203
|
const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
205
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
204
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
206
205
|
const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
|
|
207
206
|
if (mapper) {
|
|
208
207
|
return mapper(json, options);
|
|
@@ -252,16 +251,21 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
252
251
|
componentOptions[key] = parsed;
|
|
253
252
|
}
|
|
254
253
|
else {
|
|
255
|
-
|
|
254
|
+
if (!((_f = json.slots) === null || _f === void 0 ? void 0 : _f[key])) {
|
|
255
|
+
builderBindings[`component.options.${key}`] = bindings[key].code;
|
|
256
|
+
}
|
|
256
257
|
}
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
|
-
const
|
|
260
|
+
for (const key in json.slots) {
|
|
261
|
+
componentOptions[key] = json.slots[key].map((node) => (0, exports.blockToBuilder)(node, options));
|
|
262
|
+
}
|
|
263
|
+
const hasCss = !!((_g = bindings.css) === null || _g === void 0 ? void 0 : _g.code);
|
|
260
264
|
let responsiveStyles = {
|
|
261
265
|
large: {},
|
|
262
266
|
};
|
|
263
267
|
if (hasCss) {
|
|
264
|
-
const cssRules = json5_1.default.parse((
|
|
268
|
+
const cssRules = json5_1.default.parse((_h = bindings.css) === null || _h === void 0 ? void 0 : _h.code);
|
|
265
269
|
const cssRuleKeys = Object.keys(cssRules);
|
|
266
270
|
for (const ruleKey of cssRuleKeys) {
|
|
267
271
|
const mediaQueryMatch = ruleKey.match(media_sizes_1.mediaQueryRegex);
|
|
@@ -285,7 +289,9 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
285
289
|
}
|
|
286
290
|
if (thisIsComponent) {
|
|
287
291
|
for (const key in json.bindings) {
|
|
288
|
-
|
|
292
|
+
if (!((_j = json.slots) === null || _j === void 0 ? void 0 : _j[key])) {
|
|
293
|
+
builderBindings[`component.options.${key}`] = json.bindings[key].code;
|
|
294
|
+
}
|
|
289
295
|
}
|
|
290
296
|
}
|
|
291
297
|
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
|
}
|
|
@@ -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, _j;
|
|
31
31
|
const options = {
|
|
32
32
|
format: exports.DEFAULT_FORMAT,
|
|
33
33
|
...toMitosisOptions,
|
|
@@ -95,8 +95,11 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
95
95
|
}
|
|
96
96
|
for (const key in json.bindings) {
|
|
97
97
|
const value = (_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code;
|
|
98
|
-
if ((
|
|
99
|
-
|
|
98
|
+
if ((_g = json.slots) === null || _g === void 0 ? void 0 : _g[key]) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (((_h = json.bindings[key]) === null || _h === void 0 ? void 0 : _h.type) === 'spread') {
|
|
102
|
+
str += ` {...(${(_j = json.bindings[key]) === null || _j === void 0 ? void 0 : _j.code})} `;
|
|
100
103
|
}
|
|
101
104
|
else if (key.startsWith('on')) {
|
|
102
105
|
str += ` ${key}={event => ${value.replace(/\s*;$/, '')}} `;
|
|
@@ -110,6 +113,20 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
}
|
|
116
|
+
for (const key in json.slots) {
|
|
117
|
+
const value = json.slots[key];
|
|
118
|
+
str += ` ${key}={`;
|
|
119
|
+
if (value.length > 1) {
|
|
120
|
+
str += '<>';
|
|
121
|
+
}
|
|
122
|
+
str += json.slots[key]
|
|
123
|
+
.map((item) => (0, exports.blockToMitosis)(item, options, component, insideJsx))
|
|
124
|
+
.join('\n');
|
|
125
|
+
if (value.length > 1) {
|
|
126
|
+
str += '</>';
|
|
127
|
+
}
|
|
128
|
+
str += `}`;
|
|
129
|
+
}
|
|
113
130
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
114
131
|
return str + ' />';
|
|
115
132
|
}
|
|
@@ -228,7 +245,9 @@ const componentToMitosis = (toMitosisOptions = {}) => ({ component }) => {
|
|
|
228
245
|
});
|
|
229
246
|
}
|
|
230
247
|
catch (err) {
|
|
231
|
-
|
|
248
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
249
|
+
console.error('Format error for file:', str, JSON.stringify(json, null, 2));
|
|
250
|
+
}
|
|
232
251
|
throw err;
|
|
233
252
|
}
|
|
234
253
|
}
|
|
@@ -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
|
}
|
|
@@ -100,6 +100,15 @@ function mapStateIdentifiers(json) {
|
|
|
100
100
|
const stateProperties = Object.keys(json.state);
|
|
101
101
|
const plugin = (0, process_code_1.createCodeProcessorPlugin)(() => (code) => mapStateIdentifiersInExpression(code, stateProperties));
|
|
102
102
|
plugin(json);
|
|
103
|
+
for (const key in json.targetBlocks) {
|
|
104
|
+
const targetBlock = json.targetBlocks[key];
|
|
105
|
+
for (const targetBlockKey of Object.keys(targetBlock)) {
|
|
106
|
+
const block = targetBlock[targetBlockKey];
|
|
107
|
+
if (block && 'code' in block) {
|
|
108
|
+
block.code = mapStateIdentifiersInExpression(block.code, stateProperties);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
103
112
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
104
113
|
// only consolidate bindings for HTML tags, not custom components
|
|
105
114
|
// custom components are always PascalCase, e.g. MyComponent
|