UNPKG

3.96 kBSource Map (JSON)View Raw
1{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../src/lib/utils/options/sources/component.ts"],"names":[],"mappings":";;;;;;;;AAAA,+CAAmG;AACnG,wCAA8C;AAS9C,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,0BAAgB;IAGvC,UAAU;QAChB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEpC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE;YAC5B,CAAC,0BAAc,CAAC,KAAK,CAAC,EAAI,IAAI,CAAC,gBAAgB;YAC/C,CAAC,0BAAc,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,kBAAkB;SACpD,CAAC,CAAC;IACP,CAAC;IAEO,YAAY,CAAC,SAAiC;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,aAAa,CAAC;QACrC,IAAI,CAAC,IAAI,EAAE;YACP,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC/D,OAAO;SACV;QAED,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACtC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,qBAAqB,EAAE,CAAC,CAAC;SACjE;QAED,IAAI,SAAS,YAAY,8BAAkB,EAAE;YACzC,KAAK,IAAI,KAAK,IAAI,SAAS,CAAC,aAAa,EAAE,EAAE;gBACzC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;aAC5B;SACJ;IACL,CAAC;IAEO,eAAe,CAAC,SAAiC;QACrD,IAAI,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QAClE,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACd,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACtC,KAAK,IAAI,WAAW,IAAI,SAAS,CAAC,qBAAqB,EAAE,EAAE;gBACvD,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;aACxD;SACJ;QAED,IAAI,SAAS,YAAY,8BAAkB,EAAE;YACzC,KAAK,IAAI,KAAK,IAAI,SAAS,CAAC,aAAa,EAAE,EAAE;gBACzC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;aAC/B;SACJ;IACL,CAAC;IAEO,gBAAgB,CAAC,CAAiB;QACtC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAEO,kBAAkB,CAAC,CAAiB;QACxC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACJ,CAAA;AAvDY,eAAe;IAD3B,qBAAS,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAC,CAAC;GAC1B,eAAe,CAuD3B;AAvDY,0CAAe","sourcesContent":["import { Component, ComponentEvent, AbstractComponent, ChildableComponent } from '../../component';\nimport { OptionsComponent } from '../options';\n\n/**\n * Aggregates options declared by other components.\n *\n * Listens for when a component is added and adds the component's declared\n * options to the `Options` component.\n */\n@Component({name: 'options:component'})\nexport class ComponentSource extends OptionsComponent {\n private knownComponents!: string[];\n\n protected initialize() {\n this.knownComponents = [];\n this.addComponent(this.application);\n\n this.listenTo(this.application, {\n [ComponentEvent.ADDED]: this.onComponentAdded,\n [ComponentEvent.REMOVED]: this.onComponentRemoved\n });\n }\n\n private addComponent(component: AbstractComponent<any>) {\n const name = component.componentName;\n if (!name) {\n this.application.logger.error('Component without name found.');\n return;\n }\n\n if (!this.knownComponents.includes(name)) {\n this.knownComponents.push(name);\n this.owner.addDeclarations(component.getOptionDeclarations());\n }\n\n if (component instanceof ChildableComponent) {\n for (let child of component.getComponents()) {\n this.addComponent(child);\n }\n }\n }\n\n private removeComponent(component: AbstractComponent<any>) {\n let index = this.knownComponents.indexOf(component.componentName);\n if (index !== -1) {\n this.knownComponents.splice(index, 1);\n for (let declaration of component.getOptionDeclarations()) {\n this.owner.removeDeclarationByName(declaration.name);\n }\n }\n\n if (component instanceof ChildableComponent) {\n for (let child of component.getComponents()) {\n this.removeComponent(child);\n }\n }\n }\n\n private onComponentAdded(e: ComponentEvent) {\n this.addComponent(e.component);\n }\n\n private onComponentRemoved(e: ComponentEvent) {\n this.removeComponent(e.component);\n }\n}\n"]}
\No newline at end of file