@builder.io/mitosis 0.12.0 → 0.12.1

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.
@@ -1 +1 @@
1
- export declare const tryFormat: (str: string, parser: string) => string;
1
+ export declare const tryFormat: (str: string, parser: string, htmlWhitespaceSensitivity?: 'css' | 'strict' | 'ignore') => string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tryFormat = void 0;
4
4
  const standalone_1 = require("prettier/standalone");
5
- const tryFormat = (str, parser) => {
5
+ const tryFormat = (str, parser, htmlWhitespaceSensitivity = 'css') => {
6
6
  try {
7
7
  return (0, standalone_1.format)(str, {
8
8
  parser,
@@ -13,7 +13,7 @@ const tryFormat = (str, parser) => {
13
13
  require('prettier/parser-html'),
14
14
  require('prettier/parser-babel'),
15
15
  ],
16
- htmlWhitespaceSensitivity: 'ignore',
16
+ htmlWhitespaceSensitivity,
17
17
  });
18
18
  }
19
19
  catch (err) {
@@ -6,13 +6,13 @@ const format_1 = require("../../../generators/angular/helpers/format");
6
6
  const get_outputs_1 = require("../../../generators/angular/helpers/get-outputs");
7
7
  const get_refs_1 = require("../../../generators/angular/helpers/get-refs");
8
8
  const get_styles_1 = require("../../../generators/angular/helpers/get-styles");
9
+ const hooks_1 = require("../../../generators/angular/helpers/hooks");
9
10
  const blocks_1 = require("../../../generators/angular/signals/blocks");
10
11
  const helpers_2 = require("../../../generators/angular/signals/helpers");
11
12
  const get_computed_1 = require("../../../generators/angular/signals/helpers/get-computed");
12
13
  const get_inputs_1 = require("../../../generators/angular/signals/helpers/get-inputs");
13
14
  const get_code_processor_plugins_1 = require("../../../generators/angular/signals/plugins/get-code-processor-plugins");
14
15
  const types_1 = require("../../../generators/angular/types");
15
- const on_mount_1 = require("../../../generators/helpers/on-mount");
16
16
  const dedent_1 = require("../../../helpers/dedent");
17
17
  const event_handlers_1 = require("../../../helpers/event-handlers");
18
18
  const fast_clone_1 = require("../../../helpers/fast-clone");
@@ -97,15 +97,6 @@ const componentToAngularSignals = (userOptions = {}) => {
97
97
  if (shouldUseSanitizer) {
98
98
  injectables.push('protected sanitizer: DomSanitizer');
99
99
  }
100
- if (json.hooks.onMount.length > 0) {
101
- json.compileContext.angular.hooks.ngAfterViewInit = {
102
- code: `
103
- if (typeof window !== 'undefined') {
104
- ${(0, on_mount_1.stringifySingleScopeOnMount)(json)}
105
- }
106
- `,
107
- };
108
- }
109
100
  // HTML
110
101
  let template = json.children
111
102
  .map((item) => {
@@ -125,7 +116,8 @@ const componentToAngularSignals = (userOptions = {}) => {
125
116
  })
126
117
  .join('\n');
127
118
  if (options.prettier !== false) {
128
- template = (0, format_1.tryFormat)(template, 'html');
119
+ // We need to use 'strict' mode for Angular otherwise it could add spaces around some content
120
+ template = (0, format_1.tryFormat)(template, 'html', 'strict');
129
121
  }
130
122
  const { components: dynamicComponents, dynamicTemplate } = (0, helpers_1.traverseToGetAllDynamicComponents)(json, options, {
131
123
  childComponents,
@@ -215,6 +207,10 @@ Please add a initial value for every state property even if it's \`undefined\`.`
215
207
  domRefs.size !== 0 ||
216
208
  ((_y = (_x = (_w = (_v = json.compileContext) === null || _v === void 0 ? void 0 : _v.angular) === null || _w === void 0 ? void 0 : _w.extra) === null || _x === void 0 ? void 0 : _x.spreadRefs) === null || _y === void 0 ? void 0 : _y.length) > 0;
217
209
  // Imports
210
+ const emptyOnMount = (0, is_hook_empty_1.isHookEmpty)(json.hooks.onMount);
211
+ const emptyOnUnMount = (0, is_hook_empty_1.isHookEmpty)(json.hooks.onUnMount);
212
+ const AfterViewInit = Boolean(!emptyOnMount || withAttributePassing);
213
+ const OnDestroy = !emptyOnUnMount;
218
214
  const coreImports = (0, helpers_2.getAngularCoreImportsAsString)({
219
215
  refs: domRefs.size !== 0,
220
216
  input: props.length !== 0,
@@ -224,11 +220,25 @@ Please add a initial value for every state property even if it's \`undefined\`.`
224
220
  signal: dataString.length !== 0 || hasDynamicComponents,
225
221
  computed: gettersString.length !== 0,
226
222
  onPush,
223
+ AfterViewInit,
224
+ OnDestroy,
227
225
  viewChild: importsViewChild,
228
226
  viewContainerRef: hasDynamicComponents,
229
227
  templateRef: hasDynamicComponents,
230
228
  renderer: usesRenderer2,
231
229
  });
230
+ // Hooks
231
+ if (!emptyOnMount) {
232
+ (0, hooks_1.addCodeNgAfterViewInit)(json, json.hooks.onMount.map((onMount) => onMount.code).join('\n'));
233
+ }
234
+ // Angular interfaces
235
+ const angularInterfaces = [];
236
+ if (AfterViewInit) {
237
+ angularInterfaces.push('AfterViewInit');
238
+ }
239
+ if (OnDestroy) {
240
+ angularInterfaces.push('OnDestroy');
241
+ }
232
242
  let str = (0, dedent_1.dedent) `
233
243
  import { ${coreImports} } from '@angular/core';
234
244
  import { CommonModule } from '@angular/common';
@@ -260,7 +270,7 @@ Please add a initial value for every state property even if it's \`undefined\`.`
260
270
  .map(([k, v]) => `${k}: ${v}`)
261
271
  .join(',')}
262
272
  })
263
- export ${options.defaultExportComponents ? 'default ' : ''}class ${json.name} {
273
+ export ${options.defaultExportComponents ? 'default ' : ''}class ${json.name} ${angularInterfaces.length ? ` implements ${angularInterfaces.join(',')}` : ''} {
264
274
  ${(0, lodash_1.uniq)(json.compileContext.angular.extra.importCalls)
265
275
  .map((importCall) => `protected readonly ${importCall} = ${importCall};`)
266
276
  .join('\n')}
@@ -336,17 +346,19 @@ Please add a initial value for every state property even if it's \`undefined\`.`
336
346
  .filter(([_, value]) => !(0, is_hook_empty_1.isHookEmpty)(value))
337
347
  .map(([key, value]) => {
338
348
  return `${key}() {
349
+ if (typeof window !== 'undefined') {
339
350
  ${value.code}
351
+ }
340
352
  }`;
341
353
  })
342
354
  .join('\n')
343
355
  : ''}
344
356
 
345
- ${json.hooks.onUnMount
346
- ? `ngOnDestroy() {
357
+ ${emptyOnUnMount
358
+ ? ''
359
+ : `ngOnDestroy() {
347
360
  ${((_10 = json.hooks.onUnMount) === null || _10 === void 0 ? void 0 : _10.code) || ''}
348
- }`
349
- : ''}
361
+ }`}
350
362
 
351
363
  }
352
364
  `;
@@ -1,9 +1,11 @@
1
- export declare const getAngularCoreImportsAsString: ({ refs, output, input, model, onPush, effect, signal, computed, viewChild, viewContainerRef, templateRef, renderer, }: {
1
+ export declare const getAngularCoreImportsAsString: ({ refs, output, input, model, onPush, effect, signal, AfterViewInit, OnDestroy, computed, viewChild, viewContainerRef, templateRef, renderer, }: {
2
2
  refs: boolean;
3
3
  output: boolean;
4
4
  input: boolean;
5
5
  model: boolean;
6
6
  onPush: boolean;
7
+ AfterViewInit: boolean;
8
+ OnDestroy: boolean;
7
9
  effect: boolean;
8
10
  signal: boolean;
9
11
  computed: boolean;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAngularCoreImportsAsString = void 0;
4
- const getAngularCoreImportsAsString = ({ refs, output, input, model, onPush, effect, signal, computed, viewChild, viewContainerRef, templateRef, renderer, }) => {
4
+ const getAngularCoreImportsAsString = ({ refs, output, input, model, onPush, effect, signal, AfterViewInit, OnDestroy, computed, viewChild, viewContainerRef, templateRef, renderer, }) => {
5
5
  const angularCoreImports = {
6
6
  Component: true,
7
7
  viewChild: refs || viewChild,
8
8
  ElementRef: refs || viewChild,
9
9
  ViewContainerRef: viewContainerRef,
10
10
  TemplateRef: templateRef,
11
- Renderer2: !!renderer,
11
+ Renderer2: renderer,
12
12
  model,
13
13
  output,
14
14
  input,
@@ -16,6 +16,8 @@ const getAngularCoreImportsAsString = ({ refs, output, input, model, onPush, eff
16
16
  signal,
17
17
  computed,
18
18
  ChangeDetectionStrategy: onPush,
19
+ OnDestroy,
20
+ AfterViewInit,
19
21
  InputSignal: input,
20
22
  ModelSignal: model,
21
23
  };
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.12.0",
25
+ "version": "0.12.1",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {