Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

selection-ranges

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selection-ranges - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

4

CHANGELOG.md

@@ -9,2 +9,6 @@ # Changelog

## 1.1.0
* `FEAT`: add `isSelected(el)` util
## 1.0.1

@@ -11,0 +15,0 @@

32

index.js

@@ -37,2 +37,26 @@ 'use strict';

/**
* Return true if element is part of window selection.
*
* @param {Element} el
* @return {Boolean}
*/
function isSelected(el) {
if (!selection.rangeCount) {
return null;
}
var focusNode = selection.focusNode;
if (el !== focusNode && !el.contains(focusNode)) {
return false;
}
return true;
}
module.exports.isSelected = isSelected;
/**
* Set cursor or selection position.

@@ -60,12 +84,6 @@ *

if (!selection.rangeCount) {
if (!isSelected(el)) {
return null;
}
var focusNode = selection.focusNode;
if (el !== focusNode && !el.contains(focusNode)) {
return null;
}
var range = selection.getRangeAt(0);

@@ -72,0 +90,0 @@

{
"name": "selection-ranges",
"version": "1.0.1",
"version": "1.1.0",
"description": "Selection range manipulation for contenteditable elements",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,2 +8,36 @@ # selection-ranges

## API
```javascript
/**
* Return the selection on the given element as {start, end}.
*
* @param {Element} el
*
* @return {Object} selection range or null if element is not selected
*/
getRange(el);
```
```javascript
/**
* Selects the given range on the specified element.
*
* @param {Element} el
* @param {Object} range {start, end}
*/
setRange(el, range);
```
```javascript
/**
* Return true if element is part of window selection.
*
* @param {Element} el
* @return {Boolean}
*/
isSelected(el);
```
## Usage

@@ -35,4 +69,9 @@

## Related
* [selection-update](https://github.com/nikku/selection-update) - compute input selection updates on external content changes
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc