@builder.io/mitosis 0.5.20 → 0.5.22

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') {
@@ -120,13 +120,52 @@ 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
+ /**
160
+ * All binding values are strings, but we don't want to stringify the values
161
+ * within the style object otherwise the bindings will be evaluated as strings.
162
+ * As a result, do not use JSON.stringify here.
163
+ */
164
+ for (const key in responsiveStyles) {
165
+ const styles = Object.keys(responsiveStyles[key]);
166
+ const keyValues = styles.map((prop) => `${prop}: ${responsiveStyles[key][prop]}`);
167
+ const stringifiedObject = `{ ${keyValues.join(', ')} }`;
168
+ styleBindings[key] = stringifiedObject;
130
169
  }
131
170
  }
132
171
  const styleKeys = Object.keys(styleBindings);
@@ -326,22 +365,25 @@ const componentMappers = {
326
365
  delete node.bindings.columns;
327
366
  delete node.properties.columns;
328
367
  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',
368
+ ((_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)({
369
+ name: 'Column',
370
+ /**
371
+ * If width if undefined, do not create a binding otherwise its JSX will
372
+ * be <Column width={} /> which is not valid due to the empty expression.
373
+ */
374
+ ...(col.width !== undefined && {
333
375
  bindings: {
334
- width: { code: (_a = col.width) === null || _a === void 0 ? void 0 : _a.toString() },
376
+ width: { code: col.width.toString() },
335
377
  },
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
- })) || [];
378
+ }),
379
+ ...(col.link && {
380
+ properties: {
381
+ link: col.link,
382
+ },
383
+ }),
384
+ meta: (0, exports.getMetaFromBlock)(block, options),
385
+ children: col.blocks.map((col) => (0, exports.builderElementToMitosisNode)(col, options)),
386
+ }))) || [];
345
387
  return node;
346
388
  },
347
389
  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.20",
25
+ "version": "0.5.22",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {