@stencil/angular-output-target 0.6.1-dev.11655499531.137e1d26 → 0.6.1-dev.11657573317.16e0205c

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,7 +4,6 @@ import { fromEvent } from 'rxjs';
4
4
 
5
5
  export const proxyInputs = (Cmp: any, inputs: string[]) => {
6
6
  const Prototype = Cmp.prototype;
7
-
8
7
  inputs.forEach(item => {
9
8
  Object.defineProperty(Prototype, item, {
10
9
  get() {
@@ -43,20 +42,6 @@ export const defineCustomElement = (tagName: string, customElement: any) => {
43
42
  }
44
43
  }
45
44
 
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
-
60
45
  // tslint:disable-next-line: only-arrow-functions
61
46
  export function ProxyCmp(opts: { defineCustomElementFn?: () => void, inputs?: any; methods?: any }) {
62
47
  const decorator = function (cls: any) {
@@ -66,8 +51,6 @@ export function ProxyCmp(opts: { defineCustomElementFn?: () => void, inputs?: an
66
51
  defineCustomElementFn();
67
52
  }
68
53
 
69
- clearAngularOutputBindings(cls);
70
-
71
54
  if (inputs) {
72
55
  proxyInputs(cls, inputs);
73
56
  }
@@ -1,4 +1,4 @@
1
- import { dashToPascalCase, formatCustomEventInterfaceName, normalizePath } from './utils';
1
+ import { dashToPascalCase, normalizePath } from './utils';
2
2
  export const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir, includeImportCustomElements = false, customElementsDir = 'components') => (cmpMeta) => {
3
3
  // Collect component meta
4
4
  const inputs = [
@@ -41,12 +41,6 @@ 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
- ];
50
44
  // Generate outputs
51
45
  outputs.forEach((output, index) => {
52
46
  componentEvents.push(` /**
@@ -65,18 +59,10 @@ export const createComponentDefinition = (componentCorePackage, distTypesDir, ro
65
59
  .replace(/\n/g, ' ')
66
60
  .replace(/\s{2,}/g, ' ')
67
61
  .replace(/,\s*/g, ', '));
68
- /**
69
- * Starting in Stencil 2.16.0, the compiler will generate a CustomEvent interface
70
- * for each component with custom events.
71
- *
72
- * The name of this custom event is "ComponentTagNameCustomEvent".
73
- */
74
- componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
75
- outputBindings.push(` @Output() ${output.name} = new EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>();`);
62
+ componentEvents.push(` ${output.name}: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
76
63
  if (index === outputs.length - 1) {
77
64
  // Empty line to push end `}` to new line
78
65
  componentEvents.push('\n');
79
- outputBindings.push('\n');
80
66
  }
81
67
  });
82
68
  const lines = [
@@ -90,7 +76,6 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
90
76
  })
91
77
  export class ${tagNameAsPascal} {`,
92
78
  ];
93
- lines.push(...outputBindings);
94
79
  lines.push(' protected el: HTMLElement;');
95
80
  lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
96
81
  c.detach();
package/dist/index.cjs.js CHANGED
@@ -81,16 +81,6 @@ async function readPackageJson(config, rootDir) {
81
81
  }
82
82
  return pkgData;
83
83
  }
84
- /**
85
- * Returns the formatted custom event interface name for the component.
86
- * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
87
- *
88
- * @param componentTagName The tag selector of the component (i.e. my-cmp)
89
- * @returns The formatted custom event interface name.
90
- */
91
- function formatCustomEventInterfaceName(componentTagName) {
92
- return `${dashToPascalCase(componentTagName)}CustomEvent`;
93
- }
94
84
  const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
95
85
  const NON_ASCII_REGEX = /[^\x00-\x80]+/;
96
86
  const SLASH_REGEX = /\\/g;
@@ -137,12 +127,6 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
137
127
  const componentEvents = [
138
128
  '' // Empty first line
139
129
  ];
140
- /**
141
- * The list of @Output() bindings to generate for the component.
142
- */
143
- const outputBindings = [
144
- ''
145
- ];
146
130
  // Generate outputs
147
131
  outputs.forEach((output, index) => {
148
132
  componentEvents.push(` /**
@@ -161,18 +145,10 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
161
145
  .replace(/\n/g, ' ')
162
146
  .replace(/\s{2,}/g, ' ')
163
147
  .replace(/,\s*/g, ', '));
164
- /**
165
- * Starting in Stencil 2.16.0, the compiler will generate a CustomEvent interface
166
- * for each component with custom events.
167
- *
168
- * The name of this custom event is "ComponentTagNameCustomEvent".
169
- */
170
- componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
171
- outputBindings.push(` @Output() ${output.name} = new EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>();`);
148
+ componentEvents.push(` ${output.name}: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
172
149
  if (index === outputs.length - 1) {
173
150
  // Empty line to push end `}` to new line
174
151
  componentEvents.push('\n');
175
- outputBindings.push('\n');
176
152
  }
177
153
  });
178
154
  const lines = [
@@ -186,7 +162,6 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
186
162
  })
187
163
  export class ${tagNameAsPascal} {`,
188
164
  ];
189
- lines.push(...outputBindings);
190
165
  lines.push(' protected el: HTMLElement;');
191
166
  lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
192
167
  c.detach();
@@ -325,9 +300,8 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
325
300
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
326
301
  const imports = `/* tslint:disable */
327
302
  /* auto-generated angular directive proxies */
328
- import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone, Output } from '@angular/core';
303
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
329
304
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
330
- const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
331
305
  /**
332
306
  * Generate JSX import type from correct location.
333
307
  * When using custom elements build, we need to import from
@@ -335,21 +309,11 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
335
309
  * otherwise we risk bundlers pulling in lazy loaded imports.
336
310
  */
337
311
  const generateTypeImports = () => {
312
+ let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
313
+ importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
338
314
  return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
339
315
  };
340
- /**
341
- * Components that have custom events have uniquely generated interfaces as of
342
- * Stencil 2.16.0. We import these interfaces so they can be used in the generate
343
- * functions for the @Output() events.
344
- */
345
- const customEventInterfaces = components.filter(c => c.events.filter(e => !e.internal).length > 0).map(c => {
346
- return formatCustomEventInterfaceName(c.tagName);
347
- });
348
- const customEventImports = `import type { ${customEventInterfaces.join(', ')} } from '${importLocation}';\n`;
349
- const typeImports = [
350
- generateTypeImports(),
351
- customEventImports,
352
- ];
316
+ const typeImports = generateTypeImports();
353
317
  let sourceImports = '';
354
318
  /**
355
319
  * Build an array of Custom Elements build imports and namespace them
@@ -367,7 +331,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
367
331
  }
368
332
  const final = [
369
333
  imports,
370
- typeImports.join('\n'),
334
+ typeImports,
371
335
  sourceImports,
372
336
  components
373
337
  .map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
@@ -375,14 +339,6 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
375
339
  ];
376
340
  return final.join('\n') + '\n';
377
341
  }
378
- /**
379
- * Returns the path to import the file from.
380
- */
381
- const getImportPackageName = (outputTarget, componentsTypeFile) => {
382
- let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
383
- importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
384
- return importLocation;
385
- };
386
342
  const GENERATED_DTS = 'components.d.ts';
387
343
  const IMPORT_TYPES = 'Components';
388
344
 
package/dist/index.js CHANGED
@@ -73,16 +73,6 @@ async function readPackageJson(config, rootDir) {
73
73
  }
74
74
  return pkgData;
75
75
  }
76
- /**
77
- * Returns the formatted custom event interface name for the component.
78
- * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
79
- *
80
- * @param componentTagName The tag selector of the component (i.e. my-cmp)
81
- * @returns The formatted custom event interface name.
82
- */
83
- function formatCustomEventInterfaceName(componentTagName) {
84
- return `${dashToPascalCase(componentTagName)}CustomEvent`;
85
- }
86
76
  const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
87
77
  const NON_ASCII_REGEX = /[^\x00-\x80]+/;
88
78
  const SLASH_REGEX = /\\/g;
@@ -129,12 +119,6 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
129
119
  const componentEvents = [
130
120
  '' // Empty first line
131
121
  ];
132
- /**
133
- * The list of @Output() bindings to generate for the component.
134
- */
135
- const outputBindings = [
136
- ''
137
- ];
138
122
  // Generate outputs
139
123
  outputs.forEach((output, index) => {
140
124
  componentEvents.push(` /**
@@ -153,18 +137,10 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
153
137
  .replace(/\n/g, ' ')
154
138
  .replace(/\s{2,}/g, ' ')
155
139
  .replace(/,\s*/g, ', '));
156
- /**
157
- * Starting in Stencil 2.16.0, the compiler will generate a CustomEvent interface
158
- * for each component with custom events.
159
- *
160
- * The name of this custom event is "ComponentTagNameCustomEvent".
161
- */
162
- componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
163
- outputBindings.push(` @Output() ${output.name} = new EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>();`);
140
+ componentEvents.push(` ${output.name}: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
164
141
  if (index === outputs.length - 1) {
165
142
  // Empty line to push end `}` to new line
166
143
  componentEvents.push('\n');
167
- outputBindings.push('\n');
168
144
  }
169
145
  });
170
146
  const lines = [
@@ -178,7 +154,6 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
178
154
  })
179
155
  export class ${tagNameAsPascal} {`,
180
156
  ];
181
- lines.push(...outputBindings);
182
157
  lines.push(' protected el: HTMLElement;');
183
158
  lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
184
159
  c.detach();
@@ -317,9 +292,8 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
317
292
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
318
293
  const imports = `/* tslint:disable */
319
294
  /* auto-generated angular directive proxies */
320
- import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone, Output } from '@angular/core';
295
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
321
296
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
322
- const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
323
297
  /**
324
298
  * Generate JSX import type from correct location.
325
299
  * When using custom elements build, we need to import from
@@ -327,21 +301,11 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
327
301
  * otherwise we risk bundlers pulling in lazy loaded imports.
328
302
  */
329
303
  const generateTypeImports = () => {
304
+ let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
305
+ importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
330
306
  return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
331
307
  };
332
- /**
333
- * Components that have custom events have uniquely generated interfaces as of
334
- * Stencil 2.16.0. We import these interfaces so they can be used in the generate
335
- * functions for the @Output() events.
336
- */
337
- const customEventInterfaces = components.filter(c => c.events.filter(e => !e.internal).length > 0).map(c => {
338
- return formatCustomEventInterfaceName(c.tagName);
339
- });
340
- const customEventImports = `import type { ${customEventInterfaces.join(', ')} } from '${importLocation}';\n`;
341
- const typeImports = [
342
- generateTypeImports(),
343
- customEventImports,
344
- ];
308
+ const typeImports = generateTypeImports();
345
309
  let sourceImports = '';
346
310
  /**
347
311
  * Build an array of Custom Elements build imports and namespace them
@@ -359,7 +323,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
359
323
  }
360
324
  const final = [
361
325
  imports,
362
- typeImports.join('\n'),
326
+ typeImports,
363
327
  sourceImports,
364
328
  components
365
329
  .map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
@@ -367,14 +331,6 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
367
331
  ];
368
332
  return final.join('\n') + '\n';
369
333
  }
370
- /**
371
- * Returns the path to import the file from.
372
- */
373
- const getImportPackageName = (outputTarget, componentsTypeFile) => {
374
- let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
375
- importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
376
- return importLocation;
377
- };
378
334
  const GENERATED_DTS = 'components.d.ts';
379
335
  const IMPORT_TYPES = 'Components';
380
336
 
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase, formatCustomEventInterfaceName } from './utils';
2
+ import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase } from './utils';
3
3
  import { createComponentDefinition } from './generate-angular-component';
4
4
  import { generateAngularDirectivesFile } from './generate-angular-directives-file';
5
5
  import generateValueAccessors from './generate-value-accessors';
@@ -39,9 +39,8 @@ 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, Output } from '@angular/core';
42
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
43
43
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
44
- const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
45
44
  /**
46
45
  * Generate JSX import type from correct location.
47
46
  * When using custom elements build, we need to import from
@@ -49,21 +48,11 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
49
48
  * otherwise we risk bundlers pulling in lazy loaded imports.
50
49
  */
51
50
  const generateTypeImports = () => {
51
+ let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
52
+ importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
52
53
  return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
53
54
  };
54
- /**
55
- * Components that have custom events have uniquely generated interfaces as of
56
- * Stencil 2.16.0. We import these interfaces so they can be used in the generate
57
- * functions for the @Output() events.
58
- */
59
- const customEventInterfaces = components.filter(c => c.events.filter(e => !e.internal).length > 0).map(c => {
60
- return formatCustomEventInterfaceName(c.tagName);
61
- });
62
- const customEventImports = `import type { ${customEventInterfaces.join(', ')} } from '${importLocation}';\n`;
63
- const typeImports = [
64
- generateTypeImports(),
65
- customEventImports,
66
- ];
55
+ const typeImports = generateTypeImports();
67
56
  let sourceImports = '';
68
57
  /**
69
58
  * Build an array of Custom Elements build imports and namespace them
@@ -81,7 +70,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
81
70
  }
82
71
  const final = [
83
72
  imports,
84
- typeImports.join('\n'),
73
+ typeImports,
85
74
  sourceImports,
86
75
  components
87
76
  .map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
@@ -89,13 +78,5 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
89
78
  ];
90
79
  return final.join('\n') + '\n';
91
80
  }
92
- /**
93
- * Returns the path to import the file from.
94
- */
95
- const getImportPackageName = (outputTarget, componentsTypeFile) => {
96
- let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
97
- importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
98
- return importLocation;
99
- };
100
81
  const GENERATED_DTS = 'components.d.ts';
101
82
  const IMPORT_TYPES = 'Components';
package/dist/utils.d.ts CHANGED
@@ -7,11 +7,3 @@ export declare function normalizePath(str: string): string;
7
7
  export declare function relativeImport(pathFrom: string, pathTo: string, ext?: string): string;
8
8
  export declare function isRelativePath(path: string): boolean | "";
9
9
  export declare function readPackageJson(config: Config, rootDir: string): Promise<PackageJSON>;
10
- /**
11
- * Returns the formatted custom event interface name for the component.
12
- * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
13
- *
14
- * @param componentTagName The tag selector of the component (i.e. my-cmp)
15
- * @returns The formatted custom event interface name.
16
- */
17
- export declare function formatCustomEventInterfaceName(componentTagName: string): string;
package/dist/utils.js CHANGED
@@ -74,16 +74,6 @@ export async function readPackageJson(config, rootDir) {
74
74
  }
75
75
  return pkgData;
76
76
  }
77
- /**
78
- * Returns the formatted custom event interface name for the component.
79
- * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
80
- *
81
- * @param componentTagName The tag selector of the component (i.e. my-cmp)
82
- * @returns The formatted custom event interface name.
83
- */
84
- export function formatCustomEventInterfaceName(componentTagName) {
85
- return `${dashToPascalCase(componentTagName)}CustomEvent`;
86
- }
87
77
  const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
88
78
  const NON_ASCII_REGEX = /[^\x00-\x80]+/;
89
79
  const SLASH_REGEX = /\\/g;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/angular-output-target",
3
- "version": "0.6.1-dev.11655499531.137e1d26",
3
+ "version": "0.6.1-dev.11657573317.16e0205c",
4
4
  "description": "Angular output target for @stencil/core components.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "@angular/forms": "8.2.14"
40
40
  },
41
41
  "peerDependencies": {
42
- "@stencil/core": "^2.16.0"
42
+ "@stencil/core": "^2.9.0"
43
43
  },
44
44
  "jest": {
45
45
  "transform": {
@@ -55,5 +55,5 @@
55
55
  ],
56
56
  "testURL": "http://localhost"
57
57
  },
58
- "gitHead": "37e1d26a7f4f1fd4c6085af5b4abea974ac4c68b"
58
+ "gitHead": "6e0205c1e021addd4683bd5fc976cc6c9a126c3a"
59
59
  }