@builder.io/mitosis 0.3.12 → 0.3.13

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;
268
- var root = _a.root, json = _a.json, _f = _a.options, options = _f === void 0 ? {} : _f, _g = _a.blockOptions, blockOptions = _g === void 0 ? {
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 ? {
269
269
  nativeAttributes: [],
270
- } : _g;
270
+ } : _h;
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);
@@ -327,14 +327,11 @@ var blockToAngular = function (_a) {
327
327
  code: 'null',
328
328
  type: 'property',
329
329
  };
330
- if (!root.hooks.onMount
331
- .map(function (hook) { return hook.code; })
332
- .join('')
333
- .includes(inputsPropsStateName)) {
334
- root.hooks.onMount.push({
335
- code: "this.".concat(inputsPropsStateName, " = {").concat(allProps, "}"),
336
- onSSR: false,
337
- });
330
+ if (!((_f = root.hooks.onInit) === null || _f === void 0 ? void 0 : _f.code.includes(inputsPropsStateName))) {
331
+ if (!root.hooks.onInit) {
332
+ root.hooks.onInit = { code: '' };
333
+ }
334
+ root.hooks.onInit.code += "\nthis.".concat(inputsPropsStateName, " = {").concat(allProps, "};\n");
338
335
  }
339
336
  if (root.hooks.onUpdate &&
340
337
  root.hooks.onUpdate.length > 0 &&
@@ -427,7 +424,7 @@ var generateNewBindingName = function (index, name) {
427
424
  return "node_".concat(index, "_").concat(name.replaceAll('.', '_').replaceAll('-', '_'));
428
425
  };
429
426
  var handleBindings = function (json, item, index, forName, indexName) {
430
- var _a, _b, _c, _d, _e, _f;
427
+ var _a, _b, _c, _d, _e, _f, _g, _h;
431
428
  for (var key in item.bindings) {
432
429
  if (key.startsWith('"') ||
433
430
  key.startsWith('$') ||
@@ -441,7 +438,7 @@ var handleBindings = function (json, item, index, forName, indexName) {
441
438
  if (item.name === 'For')
442
439
  continue;
443
440
  if (key.startsWith('on')) {
444
- var _g = item.bindings[key].arguments, cusArgs = _g === void 0 ? ['event'] : _g;
441
+ var _j = item.bindings[key].arguments, cusArgs = _j === void 0 ? ['event'] : _j;
445
442
  var eventBindingName = "".concat(generateNewBindingName(index, item.name), "_event");
446
443
  if (((_a = item.bindings[key]) === null || _a === void 0 ? void 0 : _a.code.trim().startsWith('{')) &&
447
444
  ((_b = item.bindings[key]) === null || _b === void 0 ? void 0 : _b.code.trim().endsWith('}'))) {
@@ -470,10 +467,10 @@ var handleBindings = function (json, item, index, forName, indexName) {
470
467
  else if ((_c = item.bindings[key]) === null || _c === void 0 ? void 0 : _c.code) {
471
468
  if (((_d = item.bindings[key]) === null || _d === void 0 ? void 0 : _d.type) !== 'spread' && !key.startsWith('on')) {
472
469
  json.state[newBindingName] = { code: 'null', type: 'property' };
473
- json.hooks['onMount'].push({
474
- code: "state.".concat(newBindingName, " = ").concat(item.bindings[key].code),
475
- onSSR: false,
476
- });
470
+ if (!((_e = json.hooks['onInit']) === null || _e === void 0 ? void 0 : _e.code)) {
471
+ json.hooks['onInit'] = { code: '' };
472
+ }
473
+ json.hooks['onInit'].code += "\nstate.".concat(newBindingName, " = ").concat(item.bindings[key].code, ";\n");
477
474
  json.hooks['onUpdate'] = json.hooks['onUpdate'] || [];
478
475
  json.hooks['onUpdate'].push({
479
476
  code: "state.".concat(newBindingName, " = ").concat(item.bindings[key].code),
@@ -481,9 +478,9 @@ var handleBindings = function (json, item, index, forName, indexName) {
481
478
  item.bindings[key].code = "state.".concat(newBindingName);
482
479
  }
483
480
  else if (key.startsWith('on')) {
484
- var _h = item.bindings[key].arguments, cusArgs = _h === void 0 ? ['event'] : _h;
485
- if (((_e = item.bindings[key]) === null || _e === void 0 ? void 0 : _e.code.trim().startsWith('{')) &&
486
- ((_f = item.bindings[key]) === null || _f === void 0 ? void 0 : _f.code.trim().endsWith('}'))) {
481
+ var _k = item.bindings[key].arguments, cusArgs = _k === void 0 ? ['event'] : _k;
482
+ if (((_f = item.bindings[key]) === null || _f === void 0 ? void 0 : _f.code.trim().startsWith('{')) &&
483
+ ((_g = item.bindings[key]) === null || _g === void 0 ? void 0 : _g.code.trim().endsWith('}'))) {
487
484
  json.state[newBindingName] = {
488
485
  code: "(".concat(cusArgs.join(', '), ") => ").concat(item.bindings[key].code),
489
486
  type: 'function',
@@ -493,10 +490,10 @@ var handleBindings = function (json, item, index, forName, indexName) {
493
490
  }
494
491
  else {
495
492
  json.state[newBindingName] = { code: "null", type: 'property' };
496
- json.hooks['onMount'].push({
497
- code: "state.".concat(newBindingName, " = {...(").concat(item.bindings[key].code, ")}"),
498
- onSSR: false,
499
- });
493
+ if (!((_h = json.hooks['onInit']) === null || _h === void 0 ? void 0 : _h.code)) {
494
+ json.hooks['onInit'] = { code: '' };
495
+ }
496
+ json.hooks['onInit'].code += "\nstate.".concat(newBindingName, " = {...(").concat(item.bindings[key].code, ")};\n");
500
497
  json.hooks['onUpdate'] = json.hooks['onUpdate'] || [];
501
498
  json.hooks['onUpdate'].push({
502
499
  code: "state.".concat(newBindingName, " = {...(").concat(item.bindings[key].code, ")}"),
@@ -562,7 +559,7 @@ var classPropertiesPlugin = function () { return ({
562
559
  var componentToAngular = function (userOptions) {
563
560
  if (userOptions === void 0) { userOptions = {}; }
564
561
  return function (_a) {
565
- var _b, _c, _d, _e, _f, _g, _h, _j, _k;
562
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
566
563
  var _component = _a.component;
567
564
  // Make a copy we can safely mutate, similar to babel's toolchain
568
565
  var json = (0, fast_clone_1.fastClone)(_component);
@@ -629,7 +626,7 @@ var componentToAngular = function (userOptions) {
629
626
  if (options.plugins) {
630
627
  json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
631
628
  }
632
- var _l = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _l[0], hasPropRef = _l[1];
629
+ var _m = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _m[0], hasPropRef = _m[1];
633
630
  var childComponents = [];
634
631
  var propsTypeRef = json.propsTypeRef !== 'any' ? json.propsTypeRef : undefined;
635
632
  json.imports.forEach(function (_a) {
@@ -641,7 +638,7 @@ var componentToAngular = function (userOptions) {
641
638
  });
642
639
  });
643
640
  var customImports = (0, get_custom_imports_1.getCustomImports)(json);
644
- var _m = json.exports, localExports = _m === void 0 ? {} : _m;
641
+ var _o = json.exports, localExports = _o === void 0 ? {} : _o;
645
642
  var localExportVars = Object.keys(localExports)
646
643
  .filter(function (key) { return localExports[key].usedInLocal; })
647
644
  .map(function (key) { return "".concat(key, " = ").concat(key, ";"); });
@@ -656,7 +653,7 @@ var componentToAngular = function (userOptions) {
656
653
  }
657
654
  return "public ".concat(variableName, " : ").concat(variableType);
658
655
  });
659
- var hasConstructor = Boolean(injectables.length || ((_d = json.hooks) === null || _d === void 0 ? void 0 : _d.onInit));
656
+ var hasConstructor = Boolean(injectables.length);
660
657
  var props = (0, get_props_1.getProps)(json);
661
658
  // prevent jsx props from showing up as @Input
662
659
  if (hasPropRef) {
@@ -726,10 +723,10 @@ var componentToAngular = function (userOptions) {
726
723
  stateVars: stateVars,
727
724
  }),
728
725
  });
729
- var _o = traverseToGetAllDynamicComponents(json, options, {
726
+ var _p = traverseToGetAllDynamicComponents(json, options, {
730
727
  childComponents: childComponents,
731
- nativeAttributes: (_f = (_e = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _e === void 0 ? void 0 : _e.nativeAttributes) !== null && _f !== void 0 ? _f : [],
732
- }), dynamicComponents = _o.components, dynamicTemplate = _o.dynamicTemplate;
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;
733
730
  var hostDisplayCss = options.visuallyIgnoreHostElement ? ':host { display: contents; }' : '';
734
731
  var styles = css.length ? [hostDisplayCss, css].join('\n') : hostDisplayCss;
735
732
  // Preparing built in component metadata parameters
@@ -764,7 +761,7 @@ var componentToAngular = function (userOptions) {
764
761
  .join(',');
765
762
  return "const defaultProps = {".concat(defalutPropsString, "};\n");
766
763
  };
767
- var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " ", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export default class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n \n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "], ["\n import { ", " ", " Component ", "", " ", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export default class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n \n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.inject) ? 'Inject, forwardRef,' : '', domRefs.size || dynamicComponents.size ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', dynamicComponents.size ? ', ViewContainerRef, TemplateRef' : '', options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', getPropsDefinition({ json: json }), (0, render_imports_1.renderPreComponent)({
764
+ var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " ", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export default class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n \n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "], ["\n import { ", " ", " Component ", "", " ", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export default class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n \n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_f = options === null || options === void 0 ? void 0 : options.experimental) === null || _f === void 0 ? void 0 : _f.inject) ? 'Inject, forwardRef,' : '', domRefs.size || dynamicComponents.size ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', dynamicComponents.size ? ', ViewContainerRef, TemplateRef' : '', options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', getPropsDefinition({ json: json }), (0, render_imports_1.renderPreComponent)({
768
765
  explicitImportFileExtension: options.explicitImportFileExtension,
769
766
  component: json,
770
767
  target: 'angular',
@@ -817,11 +814,13 @@ var componentToAngular = function (userOptions) {
817
814
  ? ''
818
815
  : "constructor(\n".concat(injectables.join(',\n')).concat(dynamicComponents.size
819
816
  ? "\nprivate vcRef".concat(options.typescript ? ': ViewContainerRef' : '', ",\n")
820
- : '', ") {\n ").concat(!((_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
821
- ? ''
822
- : "\n ".concat((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, "\n "), "\n }\n "), !json.hooks.onMount.length && !dynamicComponents.size
817
+ : '', ") {}\n "), !json.hooks.onMount.length && !dynamicComponents.size && !((_g = json.hooks.onInit) === null || _g === void 0 ? void 0 : _g.code)
823
818
  ? ''
824
- : "ngOnInit() {\n ".concat((0, on_mount_1.stringifySingleScopeOnMount)(json), "\n ").concat(dynamicComponents.size
819
+ : "ngOnInit() {\n ".concat(!((_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
820
+ ? ''
821
+ : "\n ".concat((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, "\n "), "\n ").concat(json.hooks.onMount.length > 0
822
+ ? "\n if (typeof window !== 'undefined') {\n ".concat((0, on_mount_1.stringifySingleScopeOnMount)(json), "\n }\n ")
823
+ : '', "\n ").concat(dynamicComponents.size
825
824
  ? "\n this.myContent = [".concat(Array.from(dynamicComponents)
826
825
  .map(function (component) {
827
826
  return "this.vcRef.createEmbeddedView(this.".concat(component
@@ -831,10 +830,10 @@ var componentToAngular = function (userOptions) {
831
830
  .join(', '), "];\n ")
832
831
  : '', "\n }"), !((_k = json.hooks.onUpdate) === null || _k === void 0 ? void 0 : _k.length)
833
832
  ? ''
834
- : "ngOnChanges() {\n ".concat(json.hooks.onUpdate.reduce(function (code, hook) {
833
+ : "ngOnChanges() {\n if (typeof window !== 'undefined') {\n ".concat((_l = json.hooks.onUpdate) === null || _l === void 0 ? void 0 : _l.reduce(function (code, hook) {
835
834
  code += hook.code;
836
835
  return code + '\n';
837
- }, ''), "\n }"), !json.hooks.onUnMount
836
+ }, ''), "\n }\n }\n "), !json.hooks.onUnMount
838
837
  ? ''
839
838
  : "ngOnDestroy() {\n ".concat(json.hooks.onUnMount.code, "\n }"));
840
839
  if (options.standalone !== true) {
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.12",
25
+ "version": "0.3.13",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {