yaz
is a execCommand implementation for modern html elements like strong and to fixes awkward things on editable body.
It's simply and mini.
Installation
to install node package:
npm install yaz
or use direct on web browser:
Usage
For example:
Make boldlorem ipsum dolor sit amet.
const toggleBold = { if yazRange yazRange else const element = document yazRange } window'btn-bold'onclick = toggleBold
That's it. For better UX lets impore the code:
import yaz from 'yaz' + const theButton = window['btn-bold'] const toggleBold = () => { if (yaz.Range.isWrappedWith("STRONG")) { yaz.Range.undo("STRONG")+ theButton.classList.remove('active') } else { const element = document.createElement('strong') yaz.Range.surround(element)+ theButton.classList.add('active') }} + theButton.onclick = toggleBold
Now the button looks visible active if the selected range is bold.