Project-Page | Documentation | Github | NPM
DragSelect 
easily add a selection algorithm to your application/website.
The project page is https://dragselect.com/. And you find the documentation there.
Easy JavaScript library for selecting and moving elements. With no dependencies. Drag-Select & Drag-And-Drop.
Project-Page | Documentation | Github | NPM
easily add a selection algorithm to your application/website.
The project page is https://dragselect.com/. And you find the documentation there.
useLayers
option to enable/disable the z-index
manipulation on drag/select of nodes. Thanks to @digitalclubb for the contributing PR #234"elementselect" => "DS:select",
"elementunselect" => "DS:unselect",
"autoscroll" => "DS:scroll",
"dragstart" => "DS:start",
"dragmove" => "DS:update",
"callback" => "DS:end",
"preelementselect" => "DS:select:pre",
"preelementunselect" => "DS:unselect:pre",
"preautoscroll" => "DS:scroll:pre",
"predragstart" => "DS:start:pre",
"predragmove" => "DS:update:pre",
"precallback" => "DS:end:pre",
"DS:added:pre"
"DS:added"
"DS:removed:pre"
"DS:removed"
.es6m.
to .esm.
because that makes more sensedragAsBlock
is the default behavior..filterDragElements
Override inspired by #158removeSelectables
as of 148 note however, that the items are still in the settings, thus will be re-added when manually running .start()
dragAsBlock: true
and report any issue you find here. Thanks to @rendertom for the addition #162.Note: this feature will be turned on by default in a future release once proper testing and all bugs are fixed
filterSelected
in Selection
moduleisCollision
helper method.setSettings({ area: '...' })
would not remove the old event listeners. Which causes the mobile touch scroll from being blocked when switching between the Document to an areas.setSettings
would not work with customStyles
.setSettings
would not work with dropZones.droppables
within dropZones
optional and use all selectables as default value if no droppables are provided.${droppedInsideClass}
was removed even tho’ the item was dropped inside a zoneselectionThreshold
settings, solves #130refreshMemoryRate
settings, to increase/decrease performance as necessarytriggerCallback
option to removeSelectables
and addSelectables
Selectable:added
& Selectable:added:pre
& Selectable:removed
& Selectable:removed:pre
setSettings
method, you can pass any settings in the object and they will be updated. Example: update the drag area at any time by running: ds.setSettings({ area: document.getElementById("new-area") })
.ctrlKey
, shiftKey
and metaKey
. Use Control
, Shift
and Meta
respectively instead.getCursorPositionDifference
. Calculate the difference on your own instead.DragSelect.subscribe("callback", (callbackObject) => {})
instead.pre
events not working properly.pre
callbacks are fired in a LIFO order, last in first out.isDraggingKeyboard
keyboardDrag: false
pre
events for all events. i.e. predragstart
, predragmove
, etc.break
functionality to give maximum flexibility on 3rd party integrationAll these changes solve #80
useTransform: false
issueimmediateDrag
to false
if you want drag-ability only after a selection was madedraggability
to false
dragKeys
.The selector element is now not rendered inside of the area instead we generate a div overlaying the actual area and render the element inside that div. Which has a lot of benefits:
ds-selector-area
overflowTolerance
propertyThere were various bugs before 2.0 which would bypass the area restrictions and user would still be able to select elements outside of the area. We now check whether the elements are inside of the area to know whether they are selectable or not.
Changed the callbacks to follow a pub/sub pattern. They're not events you can subscribe to and they will pass back an object always following the same pattern holding extra information. Currently DragSelect still supports setting callbacks in the constructor method to make it easier for you to transition. However, in future, only subscribers will work.
subscribe
(listen to an event), unsubscribe
(remove listener) and publish
(publish an event yourself!)addEventListener
is subscribe
)Here is an example on what you'll have to change:
const ds = new DragSelect({
callback: (items, event) => console.log('my callback', items, event),
onDragMove: (event) => console.log('my callback', event),
onDragStartBegin: (event) => console.log('my callback', event),
onDragStart: (event) => console.log('my callback', event),
onElementSelect: (item) => console.log('my callback', item),
onElementUnselect: (item) => console.log('my callback', item),
})
const ds = new DragSelect({})
ds.subscribe('callback', ({ items, item, event }) =>
console.log('my callback', items, event)
)
ds.subscribe('dragmove', ({ items, item, event }) =>
console.log('my callback', event)
)
// dragstartbegin was removed use dragstart instead
ds.subscribe('dragstart', ({ items, item, event }) =>
console.log('my callback', event)
)
ds.subscribe('elementselect', ({ items, item, event }) =>
console.log('my callback', item)
)
ds.subscribe('elementunselect', ({ items, item, event }) =>
console.log('my callback', item)
)
Based on the changes, some methods did not make sense anymore. So we cleaned them up. Generally we want to move away from providing utility methods (like i.e. cursor position retrieval) instead we want to focus on the tool itself only. In case you still want any of the public method or a new one, feel free to open an issue.
Public methods that were removed:
.break
(use .stop
and .start
instead) (back in v2.2.0).getCursorPos
.getScroll
.getAreaRect
.toArray
.isCursorNearEdge
.toggle
(use .toggleSelection
instead).select
(use .setSelection
or .addSelection
instead).getCursorPositionDifference
(is deprecated, calculate yourself instead. i.e. .getCurrentCursorPosition().x - .getInitialCursorPosition().x
)event.key
on Keyboard Events (see MDN docs)However, that means that the key names have changes. Following keys should be replaced:
"ctrlKey"
use "Control"
now"shiftKey"
use "Shift"
now"metaKey"
use "Meta"
nowThis version is an (almost) complete rewrite of DragSelect. Of course the main reason is to improve the ease to add new features and maintain existing ones but that also gave the opportunity to add some performance improvements.
The setup used to measure this is the performance test which runs DragSelect over 25.000 selectable Nodes. We compared the accumulated average execution times before and after the changes. Before the changes that was an average of 3s/run. Now we lows of 1.5s.
= 59,67% performance increase
getScroll
and getAreaRect
. They will both become internal methods. Unless you've valid reasons to keep exposing them._
at the start). You'll not be able to extend them, nor override, nor use directly. Also here, unless you've valid reasons to keep them exposed.isCursorNearEdge(event, area)
in favor of isCursorNearEdge(area, event)
/bin
zoom
issue. See PR #42zoom
value for use-cases with CSS scale transformations. Implemented in PR #40. Thanks to @staradayev for your contribution!stop()
functionality #37 and #38. Big thanks to @Martin-Eckleben for the contribution!reset()
now only resets the tool while resetWithCallback()
also triggers the callback.dist/
folder holding only the relevant files. In order to not introduce breaking changed to standarts introduced earlier.DragSelect.js
as "main"
in package.json
in order to get intellisensemodule export DragSelect
that can be used in for example:<script type="module">
import DragSelect from "path/to/DragSelect.es6m.js"
new DragSelect({...});
</script>
dist
folder to the docs
folder to adhere to github pages standartdocument.documentElement
scrolling bugonDragStartBegin
callback. Helpful for my friends at issue #24_isElementTouching
function. Tested on 30.000 Nodes. The selection is still usable although a bit laggy on 30k nodes.isElementTouching
to private _isElementTouching
. You also have to pass a selectionRect
as second argument now instead of just passing the container node. This is not considered a breaking change because that function was not exposed before.setSelectables()
method. Based on request from @n1crack. See issue #30test3
with an automated test for constrained selectionmultiSelectMode
to set the multi-selection as default behavior. See #19. Thanks to @riless for the contribution!.toggleSelection
public method.addSelection
, .removeSelection
and .setSelection
by adding a third option (see docs)..addSelection
, .removeSelection
, .setSelection
, .clearSelection
.break
functionality to break out of execution from within callbacksonDragStart
and onDragMove
callback