import Editor from "../editor" ; import { ComponentType , Article , Table , Heading , Paragraph , Media , CodeBlock , InlineImage , ListEnum , HeadingEnum , MediaType , CustomCollection , List , } from "../components" ; class ComponentFactory { static bulider : ComponentFactory ; static getInstance ( editor ? ) { if ( ! this . bulider ) { this . bulider = new ComponentFactory ( editor ) ; } return this . bulider ; } typeMap : { [ key ] : any ; } ; editor ? : Editor ; constructor ( editor ? ) { this . editor = editor ; this . typeMap = { [ ComponentType . article ] : Article , [ ComponentType . list ] : List , [ ComponentType . table ] : Table , [ ComponentType . heading ] : Heading , [ ComponentType . paragraph ] : Paragraph , [ ComponentType . media ] : Media , [ ComponentType . codeBlock ] : CodeBlock , [ ComponentType . inlineImage ] : InlineImage , [ ComponentType . customerCollection ] : CustomCollection , } ; } buildArticle ( ) { return new Article ( this . editor ) ; } buildCustomCollection ( tag = "div" , children = [ ] ) { return new CustomCollection ( tag , children , this . editor ) ; } buildList ( type = ListEnum . ul , children = [ ] ) { return new List ( type , children , this . editor ) ; } buildTable ( row , col , head = [ ] , children = [ ] ) { return new Table ( row , col , head , children , this . editor ) ; } buildHeading ( type , text ? ) { return new Heading ( type , text , this . editor ) ; } buildParagraph ( text ? ) { return new Paragraph ( text , this . editor ) ; } buildMedia ( mediaType , src ) { return new Media ( mediaType , src , this . editor ) ; } buildCode ( content = "" , language = "" ) { return new CodeBlock ( content , language , this . editor ) ; } buildInlineImage ( src ) { return new InlineImage ( src ) ; } } export default ComponentFactory ;