import { CompositeDecorator , DraftDecorator , EditorState } from 'draft-js' ; import { List } from 'immutable' ; import { PluginEditorProps } from '.' ; import createCompositeDecorator from './createCompositeDecorator' ; import MultiDecorator from './MultiDecorator' ; const decoratorIsCustom = ( decorator ) : decorator is DraftDecorator => typeof decorator . getDecorations === 'function' && typeof decorator . getComponentForKey === 'function' && typeof decorator . getPropsForKey === 'function' ; const getDecoratorsFromProps = ( { decorators , plugins = [ ] , } ) : List < CompositeDecorator | DraftDecorator > => List ( [ { decorators } , ... plugins ] ) . filter ( ( plugin ) => plugin ?. decorators !== undefined ) . flatMap ( ( plugin ) => plugin ?. decorators ) as List < CompositeDecorator | DraftDecorator > ; export default function resolveDecorators ( props , getEditorState , onChange ) { const decorators = getDecoratorsFromProps ( props ) ; const compositeDecorator = createCompositeDecorator ( decorators . filter ( ( decorator ) => ! decoratorIsCustom ( decorator ! ) ) as List < DraftDecorator > , getEditorState , onChange ) ; const customDecorators = decorators . filter ( ( decorator ) => decoratorIsCustom ( decorator ) ) as List < CompositeDecorator > ; return new MultiDecorator ( customDecorators . push ( compositeDecorator ) ) ; }