Skip to content

Commit

Permalink
add triggerCallback option
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault Jan Beyer committed Oct 12, 2022
1 parent ba43501 commit 64fbb83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.4.3

- add `triggerCallback` option to `removeSelectables` and `addSelectables`

# 2.4.2

- Add Selecrables events/topics for add/delete: `Selectable:added` & `Selectable:added:pre` & `Selectable:removed` & `Selectable:removed:pre`
Expand Down
10 changes: 8 additions & 2 deletions src/DragSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,15 @@ class DragSelect {
* Add elements that can be selected. No node is added twice
* @param {DSInputElements} elements dom element(s)
* @param {boolean} [addToSelection] if elements should also be added to current selection
* @param {boolean} [triggerCallback] - if callback should be called
* @return {DSInputElements} the added element(s)
*/
addSelectables(elements, addToSelection = false) {
addSelectables(elements, addToSelection, triggerCallback) {
const els = toArray(elements)
this.SelectableSet.addAll(els)
if (addToSelection) this.SelectedSet.addAll(els)
if (triggerCallback)
this.PubSub.publish('callback', { items: this.getSelection() })
return elements
}
/**
Expand Down Expand Up @@ -277,11 +280,14 @@ class DragSelect {
* Remove elements from the elements that can be selected.
* @param {DSInputElements} elements – dom element(s)
* @param {boolean} [removeFromSelection] if elements should also be removed from current selection
* @param {boolean} [triggerCallback] - if callback should be called
* @return {DSInputElements} the removed element(s)
*/
removeSelectables(elements, removeFromSelection = false) {
removeSelectables(elements, removeFromSelection, triggerCallback) {
this.SelectableSet.deleteAll(toArray(elements))
if (removeFromSelection) this.removeSelection(elements)
if (triggerCallback)
this.PubSub.publish('callback', { items: this.getSelection() })
return elements
}
/** The starting/initial position of the cursor/selector @return {Vect2} */
Expand Down

0 comments on commit 64fbb83

Please sign in to comment.