Created
April 22, 2019 08:46
-
-
Save jorgefilipecosta/e199d6b3659936fc76535545b082a869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const { withSelect } = wp.data; | |
const { Component } = wp.element; | |
const { compose } = wp.compose; | |
class HighlightT extends Component { | |
componentDidUpdate(prevProps) { | |
const { isTyping } = this.props; | |
if (!isTyping && prevProps.isTyping) { | |
wp.data.dispatch('core/annotations').__experimentalAddAnnotation({ | |
source: 'my-annotations-plugin', | |
blockClientId: wp.data.select('core/editor').getBlocks()[Math.floor((Math.random() * 4))].clientId, | |
richTextIdentifier: 'content', | |
range: { | |
start: 0, | |
end: 3, | |
}, | |
}); | |
} | |
} | |
render() { | |
return null; | |
} | |
} | |
const applyWithSelect = withSelect((select) => { | |
console.log('eslint'); | |
return { | |
isTyping: select('core/editor').isTyping(), | |
}; | |
}); | |
const Highlight = compose( | |
applyWithSelect, | |
)( HighlightT ); | |
const { registerPlugin } = wp.plugins; | |
registerPlugin('highlight', { | |
render: Highlight, | |
icon: 'admin-links', | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment