1.0.3 • Published 4 years ago

selection-range-enhancer v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Enhance window.Selection

Demo: https://codesandbox.io/s/selection-range-enhancer-fwuy8?file=/src/index.js

This project is dedicated to adding some functions when you work with selection.

Here are the possibilities:

  1. tracks user selection throughout mouse, keyboard, touch, and mouse events
  2. finds intersections between selection and target node
  3. proxies addRange, removeAllRange funcs

API

track

This function allows you to subscribe to selection changes

ArgumentTypeDescription
htmlElementNodewill be used to subscriptions, if subsscribeToDocument is false
config.callback(selection: Selection, additional?: { kind?: OneOf['mouse', 'keyboard', 'pointer', 'touch']; reason?: oneOf['move', 'down', 'up'] }) => unknownwill be called on every selection change
config.useBubblingbooleanby default track subscribes with capture flag, you are able to turn off it providing this param
config.trackDynamicallybooleanwill call config.callback on every touch \ mouse \ pointermove if this param switched to true. Otherwise, callback is called only when touch \ mouse \ pointer is released. Warning: it could reduce the performance of your application. For better UX use debouncing with this callback!
config.trackMousebooleanshould track mouse events
config.trackKeyBoardbooleanshould track keyboard events
config.trackPointerbooleanshould track pointer events
config.trackTouchbooleanshould track touch events
config.subscribeToDocumentbooleanshould subscribe events to the document instead of provided htmlElement