@builder.io/mitosis 0.3.14 → 0.3.16

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.
@@ -264,10 +264,10 @@ var handleNgOutletBindings = function (node, options) {
264
264
  return allProps;
265
265
  };
266
266
  var blockToAngular = function (_a) {
267
- var _b, _c, _d, _e, _f;
268
- var root = _a.root, json = _a.json, _g = _a.options, options = _g === void 0 ? {} : _g, _h = _a.blockOptions, blockOptions = _h === void 0 ? {
267
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
268
+ var root = _a.root, json = _a.json, _l = _a.options, options = _l === void 0 ? {} : _l, _m = _a.blockOptions, blockOptions = _m === void 0 ? {
269
269
  nativeAttributes: [],
270
- } : _h;
270
+ } : _m;
271
271
  var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
272
272
  if (mappers[json.name]) {
273
273
  return mappers[json.name](root, json, options);
@@ -292,14 +292,29 @@ var blockToAngular = function (_a) {
292
292
  var str = '';
293
293
  if ((0, mitosis_node_1.checkIsForNode)(json)) {
294
294
  var indexName = json.scope.indexName;
295
- str += "<ng-container *ngFor=\"let ".concat(json.scope.forName, " of ").concat((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "\">");
295
+ var forName = json.scope.forName;
296
+ // Check if "key" is present for the first child of the for loop
297
+ if (json.children[0].bindings && ((_c = json.children[0].bindings.key) === null || _c === void 0 ? void 0 : _c.code)) {
298
+ var fnIndex = ((_d = root.meta) === null || _d === void 0 ? void 0 : _d._trackByForIndex) || 0;
299
+ var trackByFnName = "trackBy".concat(forName ? forName.charAt(0).toUpperCase() + forName.slice(1) : '').concat(fnIndex);
300
+ root.meta._trackByForIndex = fnIndex + 1;
301
+ var code = (_e = json.children[0].bindings.key) === null || _e === void 0 ? void 0 : _e.code;
302
+ root.state[trackByFnName] = {
303
+ code: "".concat(trackByFnName, "(").concat(indexName !== null && indexName !== void 0 ? indexName : '_', ", ").concat(forName, ") { return ").concat(code, "; }"),
304
+ type: 'method',
305
+ };
306
+ str += "<ng-container *ngFor=\"let ".concat(forName, " of ").concat((_f = json.bindings.each) === null || _f === void 0 ? void 0 : _f.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "; trackBy: ").concat(trackByFnName, "\">");
307
+ }
308
+ else {
309
+ str += "<ng-container *ngFor=\"let ".concat(forName, " of ").concat((_g = json.bindings.each) === null || _g === void 0 ? void 0 : _g.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "\">");
310
+ }
296
311
  str += json.children
297
312
  .map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options, blockOptions: blockOptions }); })
298
313
  .join('\n');
299
314
  str += "</ng-container>";
300
315
  }
301
316
  else if (json.name === 'Show') {
302
- var condition = (_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code;
317
+ var condition = (_h = json.bindings.when) === null || _h === void 0 ? void 0 : _h.code;
303
318
  if (options.state === 'inline-with-wrappers' && (condition === null || condition === void 0 ? void 0 : condition.includes('typeof'))) {
304
319
  var wordAfterTypeof = condition.split('typeof')[1].trim().split(' ')[0];
305
320
  condition = condition.replace("typeof ".concat(wordAfterTypeof), "useTypeOf(".concat(wordAfterTypeof, ")"));
@@ -310,7 +325,7 @@ var blockToAngular = function (_a) {
310
325
  .join('\n');
311
326
  str += "</ng-container>";
312
327
  // else condition
313
- if ((0, is_mitosis_node_1.isMitosisNode)((_e = json.meta) === null || _e === void 0 ? void 0 : _e.else)) {
328
+ if ((0, is_mitosis_node_1.isMitosisNode)((_j = json.meta) === null || _j === void 0 ? void 0 : _j.else)) {
314
329
  str += "<ng-container *ngIf=\"!(".concat(condition, ")\">");
315
330
  str += (0, exports.blockToAngular)({ root: root, json: json.meta.else, options: options, blockOptions: blockOptions });
316
331
  str += "</ng-container>";
@@ -327,7 +342,7 @@ var blockToAngular = function (_a) {
327
342
  code: 'null',
328
343
  type: 'property',
329
344
  };
330
- if (!((_f = root.hooks.onInit) === null || _f === void 0 ? void 0 : _f.code.includes(inputsPropsStateName))) {
345
+ if (!((_k = root.hooks.onInit) === null || _k === void 0 ? void 0 : _k.code.includes(inputsPropsStateName))) {
331
346
  if (!root.hooks.onInit) {
332
347
  root.hooks.onInit = { code: '' };
333
348
  }
@@ -437,6 +452,8 @@ var handleBindings = function (json, item, index, forName, indexName) {
437
452
  if (forName) {
438
453
  if (item.name === 'For')
439
454
  continue;
455
+ if (key === 'key')
456
+ continue;
440
457
  if (key.startsWith('on')) {
441
458
  var _j = item.bindings[key].arguments, cusArgs = _j === void 0 ? ['event'] : _j;
442
459
  var eventBindingName = "".concat(generateNewBindingName(index, item.name), "_event");
@@ -713,6 +730,10 @@ var componentToAngular = function (userOptions) {
713
730
  template = tryFormat(template, 'html');
714
731
  }
715
732
  (0, strip_meta_properties_1.stripMetaProperties)(json);
733
+ var _p = traverseToGetAllDynamicComponents(json, options, {
734
+ childComponents: childComponents,
735
+ nativeAttributes: (_e = (_d = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _d === void 0 ? void 0 : _d.nativeAttributes) !== null && _e !== void 0 ? _e : [],
736
+ }), dynamicComponents = _p.components, dynamicTemplate = _p.dynamicTemplate;
716
737
  var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
717
738
  format: 'class',
718
739
  valueMapper: processAngularCode({
@@ -723,10 +744,6 @@ var componentToAngular = function (userOptions) {
723
744
  stateVars: stateVars,
724
745
  }),
725
746
  });
726
- var _p = traverseToGetAllDynamicComponents(json, options, {
727
- childComponents: childComponents,
728
- nativeAttributes: (_e = (_d = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _d === void 0 ? void 0 : _d.nativeAttributes) !== null && _e !== void 0 ? _e : [],
729
- }), dynamicComponents = _p.components, dynamicTemplate = _p.dynamicTemplate;
730
747
  var hostDisplayCss = options.visuallyIgnoreHostElement ? ':host { display: contents; }' : '';
731
748
  var styles = css.length ? [hostDisplayCss, css].join('\n') : hostDisplayCss;
732
749
  // Preparing built in component metadata parameters
@@ -167,29 +167,44 @@ var TWRNC_STYLES_PLUGIN = function () { return ({
167
167
  post: function (json) {
168
168
  (0, legacy_1.default)(json).forEach(function (node) {
169
169
  if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
170
- var combinedClasses = [
171
- node.properties.class,
172
- node.properties.className,
173
- node.bindings.class,
174
- node.bindings.className,
175
- ]
170
+ var staticClasses = [node.properties.class, node.properties.className]
176
171
  .filter(Boolean)
177
172
  .join(' ');
178
- if (combinedClasses) {
179
- node.properties.style = "{tw`".concat(combinedClasses, "`}");
180
- }
181
- if (node.properties.class) {
182
- delete node.properties.class;
183
- }
184
- if (node.properties.className) {
185
- delete node.properties.className;
186
- }
187
- if (node.bindings.class) {
188
- delete node.bindings.class;
189
- }
190
- if (node.bindings.className) {
191
- delete node.bindings.className;
173
+ var dynamicClasses = [node.bindings.class, node.bindings.className].filter(Boolean);
174
+ if (staticClasses || dynamicClasses.length) {
175
+ var styleCode = '';
176
+ if (staticClasses) {
177
+ styleCode = "tw`".concat(staticClasses, "`");
178
+ }
179
+ if (dynamicClasses.length) {
180
+ var dynamicCode = dynamicClasses
181
+ .map(function (dc) { return (dc && dc.code ? dc.code : null); })
182
+ .filter(Boolean)
183
+ .join(', ');
184
+ if (dynamicCode) {
185
+ if (styleCode) {
186
+ // If we have both static and dynamic classes
187
+ styleCode = "tw.style(".concat(styleCode, ", ").concat(dynamicCode, ")");
188
+ }
189
+ else if (dynamicClasses.length > 1) {
190
+ // If we have multiple dynamic classes
191
+ styleCode = "tw.style([".concat(dynamicCode, "])");
192
+ }
193
+ else {
194
+ // If we have a single dynamic class
195
+ styleCode = "tw.style(".concat(dynamicCode, ")");
196
+ }
197
+ }
198
+ }
199
+ if (styleCode) {
200
+ node.bindings.style = (0, bindings_1.createSingleBinding)({ code: styleCode });
201
+ }
192
202
  }
203
+ // Clean up original class and className properties/bindings
204
+ delete node.properties.class;
205
+ delete node.properties.className;
206
+ delete node.bindings.class;
207
+ delete node.bindings.className;
193
208
  }
194
209
  });
195
210
  },
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.3.14",
25
+ "version": "0.3.16",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {