@builder.io/mitosis 0.4.3 → 0.4.4

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.
@@ -149,7 +149,7 @@ function tryFormat(code) {
149
149
  return str;
150
150
  }
151
151
  const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
152
- var _a, _b, _c, _d, _e, _f;
152
+ var _a, _b, _c, _d, _e, _f, _g;
153
153
  const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
154
154
  if (mapper) {
155
155
  return mapper(json, options);
@@ -168,7 +168,8 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
168
168
  component: {
169
169
  name: 'Text',
170
170
  options: {
171
- text: json.properties._text,
171
+ // Mitosis uses {} for bindings, but Builder expects {{}} so we need to convert
172
+ text: (_c = json.properties._text) === null || _c === void 0 ? void 0 : _c.replace(/\{(.*?)\}/g, '{{$1}}'),
172
173
  },
173
174
  },
174
175
  }, options);
@@ -178,10 +179,10 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
178
179
  const actions = {};
179
180
  for (const key in bindings) {
180
181
  const eventBindingKeyRegex = /^on([A-Z])/;
181
- const firstCharMatchForEventBindingKey = (_c = key.match(eventBindingKeyRegex)) === null || _c === void 0 ? void 0 : _c[1];
182
+ const firstCharMatchForEventBindingKey = (_d = key.match(eventBindingKeyRegex)) === null || _d === void 0 ? void 0 : _d[1];
182
183
  if (firstCharMatchForEventBindingKey) {
183
184
  actions[key.replace(eventBindingKeyRegex, firstCharMatchForEventBindingKey.toLowerCase())] =
184
- (0, remove_surrounding_block_1.removeSurroundingBlock)((_d = bindings[key]) === null || _d === void 0 ? void 0 : _d.code);
185
+ (0, remove_surrounding_block_1.removeSurroundingBlock)((_e = bindings[key]) === null || _e === void 0 ? void 0 : _e.code);
185
186
  delete bindings[key];
186
187
  }
187
188
  }
@@ -202,12 +203,12 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
202
203
  }
203
204
  }
204
205
  }
205
- const hasCss = !!((_e = bindings.css) === null || _e === void 0 ? void 0 : _e.code);
206
+ const hasCss = !!((_f = bindings.css) === null || _f === void 0 ? void 0 : _f.code);
206
207
  let responsiveStyles = {
207
208
  large: {},
208
209
  };
209
210
  if (hasCss) {
210
- const cssRules = json5_1.default.parse((_f = bindings.css) === null || _f === void 0 ? void 0 : _f.code);
211
+ const cssRules = json5_1.default.parse((_g = bindings.css) === null || _g === void 0 ? void 0 : _g.code);
211
212
  const cssRuleKeys = Object.keys(cssRules);
212
213
  for (const ruleKey of cssRuleKeys) {
213
214
  const mediaQueryMatch = ruleKey.match(media_sizes_1.mediaQueryRegex);
@@ -285,6 +286,7 @@ const componentToBuilder = (options = {}) => ({ component }) => {
285
286
  ${(0, on_mount_1.stringifySingleScopeOnMount)(component)}
286
287
  })`}
287
288
  `),
289
+ cssCode: component === null || component === void 0 ? void 0 : component.style,
288
290
  blocks: component.children
289
291
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
290
292
  .map((child) => (0, exports.blockToBuilder)(child, options)),
@@ -171,6 +171,8 @@ const componentToMitosis = (toMitosisOptions = {}) => ({ component }) => {
171
171
 
172
172
  ${!((_a = json.hooks.onUnMount) === null || _a === void 0 ? void 0 : _a.code) ? '' : `onUnMount(() => { ${json.hooks.onUnMount.code} })`}
173
173
 
174
+ ${json.style ? `useStyle(\`${json.style}\`)` : ''}
175
+
174
176
  return (${addWrapper ? '<>' : ''}
175
177
  ${json.children.map((item) => (0, exports.blockToMitosis)(item, options, component)).join('\n')}
176
178
  ${addWrapper ? '</>' : ''})
@@ -393,10 +393,11 @@ const componentMappers = {
393
393
  });
394
394
  }
395
395
  const text = block.component.options.text;
396
+ // Builder uses {{}} for bindings, but Mitosis expects {} so we need to convert
396
397
  const innerProperties = innerBindings._text
397
398
  ? {}
398
399
  : {
399
- [options.preserveTextBlocks ? 'innerHTML' : '_text']: text,
400
+ [options.preserveTextBlocks ? 'innerHTML' : '_text']: text.replace(/\{\{(.*?)\}\}/g, '{$1}'),
400
401
  };
401
402
  if (options.preserveTextBlocks) {
402
403
  return (0, create_mitosis_node_1.createMitosisNode)({
@@ -867,7 +868,7 @@ exports.createBuilderElement = createBuilderElement;
867
868
  const isBuilderElement = (el) => (el === null || el === void 0 ? void 0 : el['@type']) === '@builder.io/sdk:Element';
868
869
  exports.isBuilderElement = isBuilderElement;
869
870
  const builderContentPartToMitosisComponent = (builderContent, options = {}) => {
870
- var _a, _b, _c, _d, _e, _f, _g, _h;
871
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
871
872
  builderContent = (0, fast_clone_1.fastClone)(builderContent);
872
873
  (0, legacy_1.default)(builderContent).forEach(function (elem) {
873
874
  var _a, _b;
@@ -910,9 +911,11 @@ const builderContentPartToMitosisComponent = (builderContent, options = {}) => {
910
911
  useMetadata: {
911
912
  httpRequests: (_d = builderContent.data) === null || _d === void 0 ? void 0 : _d.httpRequests,
912
913
  },
914
+ // cmp.meta.cssCode exists for backwards compatibility, prefer cmp.style
913
915
  ...(((_e = builderContent.data) === null || _e === void 0 ? void 0 : _e.cssCode) && { cssCode: builderContent.data.cssCode }),
914
916
  },
915
- inputs: (_g = (_f = builderContent.data) === null || _f === void 0 ? void 0 : _f.inputs) === null || _g === void 0 ? void 0 : _g.map((input) => ({
917
+ ...(((_f = builderContent.data) === null || _f === void 0 ? void 0 : _f.cssCode) && { style: (_g = builderContent.data) === null || _g === void 0 ? void 0 : _g.cssCode }),
918
+ inputs: (_j = (_h = builderContent.data) === null || _h === void 0 ? void 0 : _h.inputs) === null || _j === void 0 ? void 0 : _j.map((input) => ({
916
919
  name: input.name,
917
920
  defaultValue: input.defaultValue,
918
921
  })),
@@ -926,7 +929,7 @@ const builderContentPartToMitosisComponent = (builderContent, options = {}) => {
926
929
  : []),
927
930
  ],
928
931
  },
929
- children: (((_h = builderContent.data) === null || _h === void 0 ? void 0 : _h.blocks) || [])
932
+ children: (((_k = builderContent.data) === null || _k === void 0 ? void 0 : _k.blocks) || [])
930
933
  .filter((item) => {
931
934
  var _a, _b;
932
935
  if ((_b = (_a = item.properties) === null || _a === void 0 ? void 0 : _a.src) === null || _b === void 0 ? void 0 : _b.includes('/api/v1/pixel')) {
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.4.3",
25
+ "version": "0.4.4",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {