@builder.io/mitosis 0.5.21 → 0.5.23

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.
@@ -67,6 +67,7 @@ const is_children_1 = __importDefault(require("../../helpers/is-children"));
67
67
  const on_mount_1 = require("../helpers/on-mount");
68
68
  const helpers_2 = require("./helpers");
69
69
  const types_1 = require("./types");
70
+ const parse_selector_1 = require("./parse-selector");
70
71
  const { types } = babel;
71
72
  const mappers = {
72
73
  Fragment: (root, json, options, blockOptions) => {
@@ -362,10 +363,41 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
362
363
  str += `</ng-container>`;
363
364
  }
364
365
  else {
365
- const elSelector = childComponents.find((impName) => impName === json.name)
366
- ? (0, lodash_1.kebabCase)(json.name)
367
- : json.name;
368
- str += `<${elSelector} `;
366
+ let element, classNames = [], attributes;
367
+ const isComponent = childComponents.find((impName) => impName === json.name);
368
+ if (isComponent) {
369
+ const selector = json.meta.selector || (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.selector);
370
+ if (selector) {
371
+ try {
372
+ ({ element, classNames, attributes } = (0, parse_selector_1.parse)(`${selector}`));
373
+ }
374
+ catch (_s) {
375
+ element = (0, lodash_1.kebabCase)(json.name);
376
+ }
377
+ }
378
+ else {
379
+ element = (0, lodash_1.kebabCase)(json.name);
380
+ }
381
+ }
382
+ else {
383
+ element = json.name;
384
+ }
385
+ str += `<${element} `;
386
+ // TODO: merge with existing classes/bindings
387
+ if (classNames.length) {
388
+ str += `class="${classNames.join(' ')}" `;
389
+ }
390
+ // TODO: Merge with existing properties
391
+ if (attributes) {
392
+ Object.entries(attributes).forEach(([key, value]) => {
393
+ if (value) {
394
+ str += `${key}=${JSON.stringify(value)} `;
395
+ }
396
+ else {
397
+ str += `${key} `;
398
+ }
399
+ });
400
+ }
369
401
  for (const key in json.properties) {
370
402
  if (key.startsWith('$')) {
371
403
  continue;
@@ -441,7 +473,7 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
441
473
  .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
442
474
  .join('\n');
443
475
  }
444
- str += `</${elSelector}>`;
476
+ str += `</${element}>`;
445
477
  }
446
478
  return str;
447
479
  };
@@ -0,0 +1,5 @@
1
+ export declare function parse(selector: string): {
2
+ element: string | null;
3
+ classNames: string[];
4
+ attributes: Record<string, string>;
5
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse = void 0;
4
+ const compiler_1 = require("@angular/compiler");
5
+ function parse(selector) {
6
+ const { element, classNames, attrs } = compiler_1.CssSelector.parse(selector)[0];
7
+ const attributes = attrs.reduce((acc, attr, i) => {
8
+ if (i % 2 === 0) {
9
+ acc[attr] = attrs[i + 1];
10
+ }
11
+ return acc;
12
+ }, {});
13
+ return {
14
+ element,
15
+ classNames,
16
+ attributes,
17
+ };
18
+ }
19
+ exports.parse = parse;
@@ -137,8 +137,8 @@ const getStyleStringFromBlock = (block, options) => {
137
137
  * responsiveStyles.large.background: "state.background"
138
138
  * Should get mapped to:
139
139
  * @media (max-width: 1200px): {
140
- * color: "state.color",
141
- * background: "state.background"
140
+ * color: state.color,
141
+ * background: state.background
142
142
  * }
143
143
  */
144
144
  }
@@ -156,9 +156,16 @@ const getStyleStringFromBlock = (block, options) => {
156
156
  };
157
157
  }
158
158
  }
159
- // All binding values are strings, so stringify media query objects
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
+ */
160
164
  for (const key in responsiveStyles) {
161
- styleBindings[key] = JSON.stringify(responsiveStyles[key]);
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;
162
169
  }
163
170
  }
164
171
  const styleKeys = Object.keys(styleBindings);
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.21",
25
+ "version": "0.5.23",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {