@stencil/angular-output-target 0.6.1-dev.11650996582.1590f5aa → 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.
- package/angular-component-lib/utils.ts +17 -0
- package/dist/generate-angular-component.js +17 -2
- package/dist/index.cjs.js +50 -6
- package/dist/index.js +50 -6
- package/dist/output-angular.js +25 -6
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +10 -0
- package/package.json +3 -3
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dashToPascalCase, normalizePath } from './utils';
|
|
1
|
+
import { dashToPascalCase, formatCustomEventInterfaceName, 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,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(` /**
|
|
@@ -59,10 +65,18 @@ export const createComponentDefinition = (componentCorePackage, distTypesDir, ro
|
|
|
59
65
|
.replace(/\n/g, ' ')
|
|
60
66
|
.replace(/\s{2,}/g, ' ')
|
|
61
67
|
.replace(/,\s*/g, ', '));
|
|
62
|
-
|
|
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()}>>();`);
|
|
63
76
|
if (index === outputs.length - 1) {
|
|
64
77
|
// Empty line to push end `}` to new line
|
|
65
78
|
componentEvents.push('\n');
|
|
79
|
+
outputBindings.push('\n');
|
|
66
80
|
}
|
|
67
81
|
});
|
|
68
82
|
const lines = [
|
|
@@ -76,6 +90,7 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
|
|
|
76
90
|
})
|
|
77
91
|
export class ${tagNameAsPascal} {`,
|
|
78
92
|
];
|
|
93
|
+
lines.push(...outputBindings);
|
|
79
94
|
lines.push(' protected el: HTMLElement;');
|
|
80
95
|
lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
|
|
81
96
|
c.detach();
|
package/dist/index.cjs.js
CHANGED
|
@@ -81,6 +81,16 @@ 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
|
+
}
|
|
84
94
|
const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
|
|
85
95
|
const NON_ASCII_REGEX = /[^\x00-\x80]+/;
|
|
86
96
|
const SLASH_REGEX = /\\/g;
|
|
@@ -127,6 +137,12 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
|
|
|
127
137
|
const componentEvents = [
|
|
128
138
|
'' // Empty first line
|
|
129
139
|
];
|
|
140
|
+
/**
|
|
141
|
+
* The list of @Output() bindings to generate for the component.
|
|
142
|
+
*/
|
|
143
|
+
const outputBindings = [
|
|
144
|
+
''
|
|
145
|
+
];
|
|
130
146
|
// Generate outputs
|
|
131
147
|
outputs.forEach((output, index) => {
|
|
132
148
|
componentEvents.push(` /**
|
|
@@ -145,10 +161,18 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
|
|
|
145
161
|
.replace(/\n/g, ' ')
|
|
146
162
|
.replace(/\s{2,}/g, ' ')
|
|
147
163
|
.replace(/,\s*/g, ', '));
|
|
148
|
-
|
|
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()}>>();`);
|
|
149
172
|
if (index === outputs.length - 1) {
|
|
150
173
|
// Empty line to push end `}` to new line
|
|
151
174
|
componentEvents.push('\n');
|
|
175
|
+
outputBindings.push('\n');
|
|
152
176
|
}
|
|
153
177
|
});
|
|
154
178
|
const lines = [
|
|
@@ -162,6 +186,7 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
|
|
|
162
186
|
})
|
|
163
187
|
export class ${tagNameAsPascal} {`,
|
|
164
188
|
];
|
|
189
|
+
lines.push(...outputBindings);
|
|
165
190
|
lines.push(' protected el: HTMLElement;');
|
|
166
191
|
lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
|
|
167
192
|
c.detach();
|
|
@@ -300,8 +325,9 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
|
300
325
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
301
326
|
const imports = `/* tslint:disable */
|
|
302
327
|
/* auto-generated angular directive proxies */
|
|
303
|
-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
|
|
328
|
+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone, Output } from '@angular/core';
|
|
304
329
|
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
330
|
+
const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
|
|
305
331
|
/**
|
|
306
332
|
* Generate JSX import type from correct location.
|
|
307
333
|
* When using custom elements build, we need to import from
|
|
@@ -309,11 +335,21 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
309
335
|
* otherwise we risk bundlers pulling in lazy loaded imports.
|
|
310
336
|
*/
|
|
311
337
|
const generateTypeImports = () => {
|
|
312
|
-
let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
|
|
313
|
-
importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
|
|
314
338
|
return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
315
339
|
};
|
|
316
|
-
|
|
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
|
+
];
|
|
317
353
|
let sourceImports = '';
|
|
318
354
|
/**
|
|
319
355
|
* Build an array of Custom Elements build imports and namespace them
|
|
@@ -331,7 +367,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
331
367
|
}
|
|
332
368
|
const final = [
|
|
333
369
|
imports,
|
|
334
|
-
typeImports,
|
|
370
|
+
typeImports.join('\n'),
|
|
335
371
|
sourceImports,
|
|
336
372
|
components
|
|
337
373
|
.map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
|
|
@@ -339,6 +375,14 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
339
375
|
];
|
|
340
376
|
return final.join('\n') + '\n';
|
|
341
377
|
}
|
|
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
|
+
};
|
|
342
386
|
const GENERATED_DTS = 'components.d.ts';
|
|
343
387
|
const IMPORT_TYPES = 'Components';
|
|
344
388
|
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,16 @@ 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
|
+
}
|
|
76
86
|
const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
|
|
77
87
|
const NON_ASCII_REGEX = /[^\x00-\x80]+/;
|
|
78
88
|
const SLASH_REGEX = /\\/g;
|
|
@@ -119,6 +129,12 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
|
|
|
119
129
|
const componentEvents = [
|
|
120
130
|
'' // Empty first line
|
|
121
131
|
];
|
|
132
|
+
/**
|
|
133
|
+
* The list of @Output() bindings to generate for the component.
|
|
134
|
+
*/
|
|
135
|
+
const outputBindings = [
|
|
136
|
+
''
|
|
137
|
+
];
|
|
122
138
|
// Generate outputs
|
|
123
139
|
outputs.forEach((output, index) => {
|
|
124
140
|
componentEvents.push(` /**
|
|
@@ -137,10 +153,18 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
|
|
|
137
153
|
.replace(/\n/g, ' ')
|
|
138
154
|
.replace(/\s{2,}/g, ' ')
|
|
139
155
|
.replace(/,\s*/g, ', '));
|
|
140
|
-
|
|
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()}>>();`);
|
|
141
164
|
if (index === outputs.length - 1) {
|
|
142
165
|
// Empty line to push end `}` to new line
|
|
143
166
|
componentEvents.push('\n');
|
|
167
|
+
outputBindings.push('\n');
|
|
144
168
|
}
|
|
145
169
|
});
|
|
146
170
|
const lines = [
|
|
@@ -154,6 +178,7 @@ ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
|
|
|
154
178
|
})
|
|
155
179
|
export class ${tagNameAsPascal} {`,
|
|
156
180
|
];
|
|
181
|
+
lines.push(...outputBindings);
|
|
157
182
|
lines.push(' protected el: HTMLElement;');
|
|
158
183
|
lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
|
|
159
184
|
c.detach();
|
|
@@ -292,8 +317,9 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
|
292
317
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
293
318
|
const imports = `/* tslint:disable */
|
|
294
319
|
/* auto-generated angular directive proxies */
|
|
295
|
-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
|
|
320
|
+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone, Output } from '@angular/core';
|
|
296
321
|
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
322
|
+
const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
|
|
297
323
|
/**
|
|
298
324
|
* Generate JSX import type from correct location.
|
|
299
325
|
* When using custom elements build, we need to import from
|
|
@@ -301,11 +327,21 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
301
327
|
* otherwise we risk bundlers pulling in lazy loaded imports.
|
|
302
328
|
*/
|
|
303
329
|
const generateTypeImports = () => {
|
|
304
|
-
let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
|
|
305
|
-
importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
|
|
306
330
|
return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
307
331
|
};
|
|
308
|
-
|
|
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
|
+
];
|
|
309
345
|
let sourceImports = '';
|
|
310
346
|
/**
|
|
311
347
|
* Build an array of Custom Elements build imports and namespace them
|
|
@@ -323,7 +359,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
323
359
|
}
|
|
324
360
|
const final = [
|
|
325
361
|
imports,
|
|
326
|
-
typeImports,
|
|
362
|
+
typeImports.join('\n'),
|
|
327
363
|
sourceImports,
|
|
328
364
|
components
|
|
329
365
|
.map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
|
|
@@ -331,6 +367,14 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
331
367
|
];
|
|
332
368
|
return final.join('\n') + '\n';
|
|
333
369
|
}
|
|
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
|
+
};
|
|
334
378
|
const GENERATED_DTS = 'components.d.ts';
|
|
335
379
|
const IMPORT_TYPES = 'Components';
|
|
336
380
|
|
package/dist/output-angular.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase } from './utils';
|
|
2
|
+
import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase, formatCustomEventInterfaceName } 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,8 +39,9 @@ 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
|
+
const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
|
|
44
45
|
/**
|
|
45
46
|
* Generate JSX import type from correct location.
|
|
46
47
|
* When using custom elements build, we need to import from
|
|
@@ -48,11 +49,21 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
48
49
|
* otherwise we risk bundlers pulling in lazy loaded imports.
|
|
49
50
|
*/
|
|
50
51
|
const generateTypeImports = () => {
|
|
51
|
-
let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
|
|
52
|
-
importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
|
|
53
52
|
return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
54
53
|
};
|
|
55
|
-
|
|
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
|
+
];
|
|
56
67
|
let sourceImports = '';
|
|
57
68
|
/**
|
|
58
69
|
* Build an array of Custom Elements build imports and namespace them
|
|
@@ -70,7 +81,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
70
81
|
}
|
|
71
82
|
const final = [
|
|
72
83
|
imports,
|
|
73
|
-
typeImports,
|
|
84
|
+
typeImports.join('\n'),
|
|
74
85
|
sourceImports,
|
|
75
86
|
components
|
|
76
87
|
.map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
|
|
@@ -78,5 +89,13 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
|
|
78
89
|
];
|
|
79
90
|
return final.join('\n') + '\n';
|
|
80
91
|
}
|
|
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
|
+
};
|
|
81
100
|
const GENERATED_DTS = 'components.d.ts';
|
|
82
101
|
const IMPORT_TYPES = 'Components';
|
package/dist/utils.d.ts
CHANGED
|
@@ -7,3 +7,11 @@ 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,6 +74,16 @@ 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
|
+
}
|
|
77
87
|
const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
|
|
78
88
|
const NON_ASCII_REGEX = /[^\x00-\x80]+/;
|
|
79
89
|
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.
|
|
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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@angular/forms": "8.2.14"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@stencil/core": "^2.
|
|
42
|
+
"@stencil/core": "^2.16.0"
|
|
43
43
|
},
|
|
44
44
|
"jest": {
|
|
45
45
|
"transform": {
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
],
|
|
56
56
|
"testURL": "http://localhost"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "37e1d26a7f4f1fd4c6085af5b4abea974ac4c68b"
|
|
59
59
|
}
|