@builder.io/mitosis 0.5.19 → 0.5.21

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.
@@ -114,7 +114,7 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
114
114
  }
115
115
  for (const key in json.bindings) {
116
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]) {
117
+ if (!value || ((_f = json.slots) === null || _f === void 0 ? void 0 : _f[key])) {
118
118
  continue;
119
119
  }
120
120
  if (((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.type) === 'spread') {
@@ -50,8 +50,8 @@ const blockToSolid = (json, component, options, insideJsx) => {
50
50
  </For>`;
51
51
  }
52
52
  let str = '';
53
- const isFragmentWithoutKey = json.name === 'Fragment' && !json.bindings.key;
54
- if (isFragmentWithoutKey) {
53
+ const isFragment = json.name === 'Fragment';
54
+ if (isFragment) {
55
55
  str += '<';
56
56
  }
57
57
  else {
@@ -61,15 +61,19 @@ const blockToSolid = (json, component, options, insideJsx) => {
61
61
  str += `fallback={${(0, exports.blockToSolid)(json.meta.else, component, options, false)}}`;
62
62
  }
63
63
  const classString = (0, styles_1.collectClassString)(json, options);
64
- if (classString) {
64
+ if (classString && !isFragment) {
65
65
  str += ` class=${classString} `;
66
66
  }
67
67
  for (const key in json.properties) {
68
+ if (isFragment)
69
+ continue;
68
70
  const value = json.properties[key];
69
71
  const newKey = transformAttributeName(key);
70
72
  str += ` ${newKey}="${value}" `;
71
73
  }
72
74
  for (const key in json.bindings) {
75
+ if (isFragment)
76
+ continue;
73
77
  const { code, arguments: cusArg = ['event'], type } = json.bindings[key];
74
78
  if (!code)
75
79
  continue;
@@ -122,7 +126,7 @@ const blockToSolid = (json, component, options, insideJsx) => {
122
126
  .map((item) => (0, exports.blockToSolid)(item, component, options, true))
123
127
  .join('\n');
124
128
  }
125
- if (isFragmentWithoutKey) {
129
+ if (isFragment) {
126
130
  str += '</>';
127
131
  }
128
132
  else {
@@ -120,13 +120,45 @@ const getActionBindingsFromBlock = (block, options) => {
120
120
  const getStyleStringFromBlock = (block, options) => {
121
121
  var _a, _b;
122
122
  const styleBindings = {};
123
+ const responsiveStyles = {};
123
124
  let styleString = '';
124
125
  if (block.bindings) {
125
126
  for (const key in block.bindings) {
126
- if (key.includes('style') && key.includes('.')) {
127
+ if (!key.includes('.')) {
128
+ continue;
129
+ }
130
+ if (key.includes('style')) {
127
131
  const styleProperty = key.split('.')[1];
128
132
  styleBindings[styleProperty] = convertExportDefaultToReturn(((_b = (_a = block.code) === null || _a === void 0 ? void 0 : _a.bindings) === null || _b === void 0 ? void 0 : _b[key]) || block.bindings[key]);
133
+ /**
134
+ * responsiveStyles that are bound need to be merged into media queries.
135
+ * Example:
136
+ * responsiveStyles.large.color: "state.color"
137
+ * responsiveStyles.large.background: "state.background"
138
+ * Should get mapped to:
139
+ * @media (max-width: 1200px): {
140
+ * color: "state.color",
141
+ * background: "state.background"
142
+ * }
143
+ */
129
144
  }
145
+ else if (key.includes('responsiveStyles')) {
146
+ const [_, size, prop] = key.split('.');
147
+ const mediaKey = `@media (max-width: ${media_sizes_1.sizes[size].max}px)`;
148
+ /**
149
+ * The media query key has spaces/special characters so we need to ensure
150
+ * that the key is always a string otherwise there will be runtime errors.
151
+ */
152
+ const objKey = `"${mediaKey}"`;
153
+ responsiveStyles[objKey] = {
154
+ ...responsiveStyles[objKey],
155
+ [prop]: block.bindings[key],
156
+ };
157
+ }
158
+ }
159
+ // All binding values are strings, so stringify media query objects
160
+ for (const key in responsiveStyles) {
161
+ styleBindings[key] = JSON.stringify(responsiveStyles[key]);
130
162
  }
131
163
  }
132
164
  const styleKeys = Object.keys(styleBindings);
@@ -326,22 +358,25 @@ const componentMappers = {
326
358
  delete node.bindings.columns;
327
359
  delete node.properties.columns;
328
360
  node.children =
329
- ((_b = (_a = block.component) === null || _a === void 0 ? void 0 : _a.options.columns) === null || _b === void 0 ? void 0 : _b.map((col, index) => {
330
- var _a;
331
- return (0, create_mitosis_node_1.createMitosisNode)({
332
- name: 'Column',
361
+ ((_b = (_a = block.component) === null || _a === void 0 ? void 0 : _a.options.columns) === null || _b === void 0 ? void 0 : _b.map((col, index) => (0, create_mitosis_node_1.createMitosisNode)({
362
+ name: 'Column',
363
+ /**
364
+ * If width if undefined, do not create a binding otherwise its JSX will
365
+ * be <Column width={} /> which is not valid due to the empty expression.
366
+ */
367
+ ...(col.width !== undefined && {
333
368
  bindings: {
334
- width: { code: (_a = col.width) === null || _a === void 0 ? void 0 : _a.toString() },
369
+ width: { code: col.width.toString() },
335
370
  },
336
- ...(col.link && {
337
- properties: {
338
- link: col.link,
339
- },
340
- }),
341
- meta: (0, exports.getMetaFromBlock)(block, options),
342
- children: col.blocks.map((col) => (0, exports.builderElementToMitosisNode)(col, options)),
343
- });
344
- })) || [];
371
+ }),
372
+ ...(col.link && {
373
+ properties: {
374
+ link: col.link,
375
+ },
376
+ }),
377
+ meta: (0, exports.getMetaFromBlock)(block, options),
378
+ children: col.blocks.map((col) => (0, exports.builderElementToMitosisNode)(col, options)),
379
+ }))) || [];
345
380
  return node;
346
381
  },
347
382
  PersonalizationContainer(block, options) {
@@ -19,6 +19,9 @@ export type generatorsOption = {
19
19
  };
20
20
  export type MitosisConfig = {
21
21
  generators?: generatorsOption;
22
+ /**
23
+ * Apply common options to all targets
24
+ */
22
25
  commonOptions?: Omit<BaseTranspilerOptions, 'experimental'>;
23
26
  /**
24
27
  * List of targets to compile to.
@@ -57,6 +60,7 @@ export type MitosisConfig = {
57
60
  * react: {
58
61
  * stateType: 'builder';
59
62
  * stylesType: 'styled-jsx'
63
+ * plugins: [myPlugin]
60
64
  * }
61
65
  * }
62
66
  * ```
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.5.19",
25
+ "version": "0.5.21",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {