1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getComponentDecoratorMetadata = exports.getComponentPropsDecoratorMetadata = exports.isStandaloneComponent = exports.isComponent = exports.isDeclarable = exports.getComponentInputsOutputs = void 0;
|
4 | const core_1 = require("@angular/core");
|
5 | const reflectionCapabilities = new core_1.ɵReflectionCapabilities();
|
6 |
|
7 |
|
8 |
|
9 | const getComponentInputsOutputs = (component) => {
|
10 | const componentMetadata = (0, exports.getComponentDecoratorMetadata)(component);
|
11 | const componentPropsMetadata = (0, exports.getComponentPropsDecoratorMetadata)(component);
|
12 | const initialValue = {
|
13 | inputs: [],
|
14 | outputs: [],
|
15 | };
|
16 |
|
17 | if (componentMetadata && componentMetadata.inputs) {
|
18 | initialValue.inputs.push(...componentMetadata.inputs.map((i) => ({
|
19 | propName: typeof i === 'string' ? i : i.name,
|
20 | templateName: typeof i === 'string' ? i : i.alias,
|
21 | })));
|
22 | }
|
23 | if (componentMetadata && componentMetadata.outputs) {
|
24 | initialValue.outputs.push(...componentMetadata.outputs.map((i) => ({ propName: i, templateName: i })));
|
25 | }
|
26 | if (!componentPropsMetadata) {
|
27 | return initialValue;
|
28 | }
|
29 |
|
30 |
|
31 | return Object.entries(componentPropsMetadata).reduce((previousValue, [propertyName, values]) => {
|
32 | const value = values.find((v) => v instanceof core_1.Input || v instanceof core_1.Output);
|
33 | if (value instanceof core_1.Input) {
|
34 | const inputToAdd = {
|
35 | propName: propertyName,
|
36 | templateName: value.bindingPropertyName ?? value.alias ?? propertyName,
|
37 | };
|
38 | const previousInputsFiltered = previousValue.inputs.filter((i) => i.templateName !== propertyName);
|
39 | return {
|
40 | ...previousValue,
|
41 | inputs: [...previousInputsFiltered, inputToAdd],
|
42 | };
|
43 | }
|
44 | if (value instanceof core_1.Output) {
|
45 | const outputToAdd = {
|
46 | propName: propertyName,
|
47 | templateName: value.bindingPropertyName ?? value.alias ?? propertyName,
|
48 | };
|
49 | const previousOutputsFiltered = previousValue.outputs.filter((i) => i.templateName !== propertyName);
|
50 | return {
|
51 | ...previousValue,
|
52 | outputs: [...previousOutputsFiltered, outputToAdd],
|
53 | };
|
54 | }
|
55 | return previousValue;
|
56 | }, initialValue);
|
57 | };
|
58 | exports.getComponentInputsOutputs = getComponentInputsOutputs;
|
59 | const isDeclarable = (component) => {
|
60 | if (!component) {
|
61 | return false;
|
62 | }
|
63 | const decorators = reflectionCapabilities.annotations(component);
|
64 | return !!(decorators || []).find((d) => d instanceof core_1.Directive || d instanceof core_1.Pipe || d instanceof core_1.Component);
|
65 | };
|
66 | exports.isDeclarable = isDeclarable;
|
67 | const isComponent = (component) => {
|
68 | if (!component) {
|
69 | return false;
|
70 | }
|
71 | const decorators = reflectionCapabilities.annotations(component);
|
72 | return (decorators || []).some((d) => d instanceof core_1.Component);
|
73 | };
|
74 | exports.isComponent = isComponent;
|
75 | const isStandaloneComponent = (component) => {
|
76 | if (!component) {
|
77 | return false;
|
78 | }
|
79 | const decorators = reflectionCapabilities.annotations(component);
|
80 |
|
81 |
|
82 | return (decorators || []).some((d) => (d instanceof core_1.Component || d instanceof core_1.Directive || d instanceof core_1.Pipe) && d.standalone);
|
83 | };
|
84 | exports.isStandaloneComponent = isStandaloneComponent;
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | const getComponentPropsDecoratorMetadata = (component) => {
|
90 | return reflectionCapabilities.propMetadata(component);
|
91 | };
|
92 | exports.getComponentPropsDecoratorMetadata = getComponentPropsDecoratorMetadata;
|
93 |
|
94 |
|
95 |
|
96 | const getComponentDecoratorMetadata = (component) => {
|
97 | const decorators = reflectionCapabilities.annotations(component);
|
98 | return decorators.reverse().find((d) => d instanceof core_1.Component);
|
99 | };
|
100 | exports.getComponentDecoratorMetadata = getComponentDecoratorMetadata;
|