@stencil/angular-output-target 0.6.1-dev.11655483906.1e51ded4 → 0.6.1-dev.11655499531.137e1d26

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.
@@ -4,6 +4,7 @@ import { fromEvent } from 'rxjs';
4
4
 
5
5
  export const proxyInputs = (Cmp: any, inputs: string[]) => {
6
6
  const Prototype = Cmp.prototype;
7
+
7
8
  inputs.forEach(item => {
8
9
  Object.defineProperty(Prototype, item, {
9
10
  get() {
@@ -42,6 +43,20 @@ export const defineCustomElement = (tagName: string, customElement: any) => {
42
43
  }
43
44
  }
44
45
 
46
+ const NG_COMP_DEF = 'ɵcmp';
47
+
48
+ export const clearAngularOutputBindings = (cls: any) => {
49
+ const instance = cls.prototype.constructor;
50
+ if (instance[NG_COMP_DEF]) {
51
+ /**
52
+ * With the output targets generating @Output() proxies, we need to
53
+ * clear the metadata (ɵcmp.outputs) so that Angular does not add its own event listener
54
+ * and cause duplicate event emissions for the web component events.
55
+ */
56
+ instance[NG_COMP_DEF].outputs = {};
57
+ }
58
+ };
59
+
45
60
  // tslint:disable-next-line: only-arrow-functions
46
61
  export function ProxyCmp(opts: { defineCustomElementFn?: () => void, inputs?: any; methods?: any }) {
47
62
  const decorator = function (cls: any) {
@@ -51,6 +66,8 @@ export function ProxyCmp(opts: { defineCustomElementFn?: () => void, inputs?: an
51
66
  defineCustomElementFn();
52
67
  }
53
68
 
69
+ clearAngularOutputBindings(cls);
70
+
54
71
  if (inputs) {
55
72
  proxyInputs(cls, inputs);
56
73
  }
@@ -41,6 +41,12 @@ export const createComponentDefinition = (componentCorePackage, distTypesDir, ro
41
41
  const componentEvents = [
42
42
  '' // Empty first line
43
43
  ];
44
+ /**
45
+ * The list of @Output() bindings to generate for the component.
46
+ */
47
+ const outputBindings = [
48
+ ''
49
+ ];
44
50
  // Generate outputs
45
51
  outputs.forEach((output, index) => {
46
52
  componentEvents.push(` /**
@@ -66,9 +72,11 @@ export const createComponentDefinition = (componentCorePackage, distTypesDir, ro
66
72
  * The name of this custom event is "ComponentTagNameCustomEvent".
67
73
  */
68
74
  componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
75
+ outputBindings.push(` @Output() ${output.name} = new EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>();`);
69
76
  if (index === outputs.length - 1) {
70
77
  // Empty line to push end `}` to new line
71
78
  componentEvents.push('\n');
79
+ outputBindings.push('\n');
72
80
  }
73
81
  });
74
82
  const lines = [
@@ -82,6 +90,7 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
82
90
  })
83
91
  export class ${tagNameAsPascal} {`,
84
92
  ];
93
+ lines.push(...outputBindings);
85
94
  lines.push(' protected el: HTMLElement;');
86
95
  lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
87
96
  c.detach();
package/dist/index.cjs.js CHANGED
@@ -137,6 +137,12 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
137
137
  const componentEvents = [
138
138
  '' // Empty first line
139
139
  ];
140
+ /**
141
+ * The list of @Output() bindings to generate for the component.
142
+ */
143
+ const outputBindings = [
144
+ ''
145
+ ];
140
146
  // Generate outputs
141
147
  outputs.forEach((output, index) => {
142
148
  componentEvents.push(` /**
@@ -162,9 +168,11 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
162
168
  * The name of this custom event is "ComponentTagNameCustomEvent".
163
169
  */
164
170
  componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
171
+ outputBindings.push(` @Output() ${output.name} = new EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>();`);
165
172
  if (index === outputs.length - 1) {
166
173
  // Empty line to push end `}` to new line
167
174
  componentEvents.push('\n');
175
+ outputBindings.push('\n');
168
176
  }
169
177
  });
170
178
  const lines = [
@@ -178,6 +186,7 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
178
186
  })
179
187
  export class ${tagNameAsPascal} {`,
180
188
  ];
189
+ lines.push(...outputBindings);
181
190
  lines.push(' protected el: HTMLElement;');
182
191
  lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
183
192
  c.detach();
@@ -316,7 +325,7 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
316
325
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
317
326
  const imports = `/* tslint:disable */
318
327
  /* auto-generated angular directive proxies */
319
- import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
328
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone, Output } from '@angular/core';
320
329
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
321
330
  const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
322
331
  /**
package/dist/index.js CHANGED
@@ -129,6 +129,12 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
129
129
  const componentEvents = [
130
130
  '' // Empty first line
131
131
  ];
132
+ /**
133
+ * The list of @Output() bindings to generate for the component.
134
+ */
135
+ const outputBindings = [
136
+ ''
137
+ ];
132
138
  // Generate outputs
133
139
  outputs.forEach((output, index) => {
134
140
  componentEvents.push(` /**
@@ -154,9 +160,11 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
154
160
  * The name of this custom event is "ComponentTagNameCustomEvent".
155
161
  */
156
162
  componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
163
+ outputBindings.push(` @Output() ${output.name} = new EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>();`);
157
164
  if (index === outputs.length - 1) {
158
165
  // Empty line to push end `}` to new line
159
166
  componentEvents.push('\n');
167
+ outputBindings.push('\n');
160
168
  }
161
169
  });
162
170
  const lines = [
@@ -170,6 +178,7 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
170
178
  })
171
179
  export class ${tagNameAsPascal} {`,
172
180
  ];
181
+ lines.push(...outputBindings);
173
182
  lines.push(' protected el: HTMLElement;');
174
183
  lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
175
184
  c.detach();
@@ -308,7 +317,7 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
308
317
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
309
318
  const imports = `/* tslint:disable */
310
319
  /* auto-generated angular directive proxies */
311
- import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
320
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone, Output } from '@angular/core';
312
321
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
313
322
  const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
314
323
  /**
@@ -39,7 +39,7 @@ export function generateProxies(components, pkgData, outputTarget, rootDir) {
39
39
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
40
40
  const imports = `/* tslint:disable */
41
41
  /* auto-generated angular directive proxies */
42
- import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
42
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone, Output } from '@angular/core';
43
43
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
44
44
  const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
45
45
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/angular-output-target",
3
- "version": "0.6.1-dev.11655483906.1e51ded4",
3
+ "version": "0.6.1-dev.11655499531.137e1d26",
4
4
  "description": "Angular output target for @stencil/core components.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -55,5 +55,5 @@
55
55
  ],
56
56
  "testURL": "http://localhost"
57
57
  },
58
- "gitHead": "e51ded46a46fbcd7d0f191a9dc237bef362aab9f"
58
+ "gitHead": "37e1d26a7f4f1fd4c6085af5b4abea974ac4c68b"
59
59
  }