@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
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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 += `</${
|
|
476
|
+
str += `</${element}>`;
|
|
445
477
|
}
|
|
446
478
|
return str;
|
|
447
479
|
};
|
|
@@ -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:
|
|
141
|
-
* 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
|
-
|
|
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
|
-
|
|
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);
|