export const typeFilter = mark => mark . type === 'color' ; export const hasMark = value => value . marks . some ( typeFilter ) ; export const getMarks = value => value . marks . filter ( typeFilter ) ; export const getMark = value => value . marks . filter ( typeFilter ) . first ( ) ; export const createMark = rgba => ( { type : 'color' , data : { rgba } } ) ; export const reapplyMark = ( { change , rgba } ) => { getMarks ( change . value ) . map ( mark => change . removeMark ( mark ) ) ; return change . addMark ( createMark ( rgba ) ) ; } ; export const applyMark = ( { change , rgba } ) => change . addMark ( createMark ( rgba ) ) ; param { Object } attributes property property property property property property export const colorMarkStrategy = attributes => { const { value , rgba } = attributes ; const { selection } = value ; if ( hasMark ( value ) ) { if ( selection . isExpanded ) { return reapplyMark ( { change : value . change ( ) , rgba } ) ; } else console . info ( '[SlateJS][ColorPlugin] selection collapsed, w/ mark exists' ) ; } else { if ( selection . isExpanded ) { return applyMark ( { change : value . change ( ) , rgba } ) ; } else console . info ( '[SlateJS][ColorPlugin] selection collapsed, w/o mark' ) ; } return value . change ( ) ; } ;