@@ -5,6 +5,7 @@ import type { ConstExportDoc } from 'dgeni-packages/typescript/api-doc-types/Con
55import type { FunctionExportDoc } from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc' ;
66import { MethodMemberDoc } from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc' ;
77import { PropertyMemberDoc } from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc' ;
8+ import { createRef } from 'tools/dgeni/src/utils/create-ref' ;
89import { TypeFlags } from 'typescript' ;
910
1011import {
@@ -27,6 +28,9 @@ import {
2728 DaffDocsApiTypeProperty ,
2829 daffDocsGetRoleFromTsDoc ,
2930 DaffDocsTsDocument ,
31+ daffDocsApiParseHostDirective ,
32+ daffDocsApiParseHostDirectiveField ,
33+ DaffDocsApiHostDirective ,
3034} from '@daffodil/docs-utils' ;
3135
3236import { InlineTagProcessor } from './inline-tag-processor' ;
@@ -229,6 +233,7 @@ export class RoleProcessor implements FilterableProcessor {
229233 readonly directiveSerialize = serializeFactory < DaffApiDirective > (
230234 [
231235 'selector' ,
236+ 'hostDirectives' ,
232237 ] ,
233238 {
234239 inputs : arraySerializer ( this . inputSerialize ) ,
@@ -242,6 +247,7 @@ export class RoleProcessor implements FilterableProcessor {
242247 constructor (
243248 private markdown : MarkdownCodeProcessor ,
244249 private inlineTagProcessor : InlineTagProcessor ,
250+ private aliasMap ,
245251 ) { }
246252
247253 $process ( docs : Array < Document > ) : Array < Document > {
@@ -309,9 +315,44 @@ export class RoleProcessor implements FilterableProcessor {
309315 directive ( doc : SerializableDoc & DaffApiDirective & ClassExportDoc ) : SerializableDoc & DaffApiDirective {
310316 this . klass ( < any > doc ) ;
311317 doc . serializer = this . directiveSerialize ;
318+ const directiveArg : any = doc . decorators [ 0 ] . argumentInfo [ 0 ] ;
312319 doc . inputs = [ ] ;
313320 doc . outputs = [ ] ;
314- doc . selector = doc . decorators [ 0 ] . argumentInfo [ 0 ] [ 0 ] ;
321+ doc . selector = directiveArg . selector ;
322+ doc . hostDirectives = ( < Array < string > > directiveArg . hostDirectives )
323+ ?. map ( daffDocsApiParseHostDirective )
324+ . map < DaffDocsApiHostDirective > ( ( { directive, inputs, outputs } ) => ( {
325+ directive : createRef ( directive ) ,
326+ inputs : inputs ? JSON . parse ( inputs . replaceAll ( '\'' , '\"' ) ) . map ( daffDocsApiParseHostDirectiveField ) : [ ] ,
327+ outputs : outputs ? JSON . parse ( outputs . replaceAll ( '\'' , '\"' ) ) . map ( daffDocsApiParseHostDirectiveField ) : [ ] ,
328+ } ) ) || [ ] ;
329+ doc . hostDirectives . forEach ( ( hostDirective ) => {
330+ const directiveDoc = this . aliasMap . getDocs ( hostDirective . directive . label ) [ 0 ] ;
331+ if ( directiveDoc ) {
332+ hostDirective . inputs . forEach ( ( input ) => {
333+ const parentInput = directiveDoc . members . find ( ( member ) => member . name === input . parentField || input . field ) ;
334+ if ( parentInput ) {
335+ doc . inputs . push ( {
336+ ...parentInput ,
337+ name : input . field ,
338+ required : ! parentInput . isOptional ,
339+ inheritedFrom : hostDirective . directive ,
340+ } ) ;
341+ }
342+ } ) ;
343+ hostDirective . outputs . forEach ( ( output ) => {
344+ const parentOutput = directiveDoc . members . find ( ( member ) => member . name === output . parentField || output . field ) ;
345+ if ( parentOutput ) {
346+ doc . outputs . push ( {
347+ ...parentOutput ,
348+ name : output . field ,
349+ required : ! parentOutput . isOptional ,
350+ inheritedFrom : hostDirective . directive ,
351+ } ) ;
352+ }
353+ } ) ;
354+ }
355+ } ) ;
315356 // TODO: support signals
316357 doc . props = doc . props . reduce ( ( acc , prop ) => {
317358 if ( prop . decorators ?. find ( ( { name } ) => name === 'Input' ) ) {
@@ -443,5 +484,5 @@ export class RoleProcessor implements FilterableProcessor {
443484
444485export const ROLE_PROVIDER = < const > [
445486 ROLE_PROCESSOR_NAME ,
446- ( markdown : MarkdownCodeProcessor , inlineTagProcessorForRealz : InlineTagProcessor ) => new RoleProcessor ( markdown , inlineTagProcessorForRealz ) ,
487+ ( markdown : MarkdownCodeProcessor , inlineTagProcessorForRealz : InlineTagProcessor , aliasMap ) => new RoleProcessor ( markdown , inlineTagProcessorForRealz , aliasMap ) ,
447488] ;
0 commit comments