JSFiddle - React, Tailwind, and code Playground
JavaScript
/*
* jQuery UI Selectable Modification to enable Droppable
*
* Allows Shift clicking to select range, and Ctrl clicking to add items to current selection.
*/
$.widget("ui.selectable_shift", $.ui.selectable, {
options: {
appendTo: 'body',
autoRefresh: true,
filter: '*',
distance:40,
tolerance: 'touch'
},
_mouseStart: function (event) {
var self = this;
this.opos = [event.pageX, event.pageY];
if (this.options.disabled)
return;
var options = this.options;
this.selectees = $(options.filter, this.element[0]);
this._trigger("start", event);
$(options.appendTo).append(this.helper);
// position helper (lasso)
this.helper.css({
"left": event.clientX,
"top": event.clientY,
"width": 0,
"height": 0
});
if (options.autoRefresh) {
this.refresh();
}
},
_mouseDrag: function( event ) {
if ( this.options.disableDragEvent ) {
return;
} else {
$.ui.selectable.prototype._mouseDrag.call( this, event );
return;
}
},
_mouseDown: function( event ) {
var self = this;
if ( this.options.disableDragEvent ) {
// Ensures that selectable will act on the mouseDown event
event.originalEvent.mouseHandled = false;
}
$(event.target).parents().andSelf().each(function() {
var selectee = $.data(this, "selectable-item");
if (selectee) {
var doSelect = !event.metaKey || !selectee.$element.hasClass('ui-selected');
selectee.$element
.removeClass(doSelect ? "ui-unselecting" : "ui-selected")
.addClass(doSelect ? "ui-selecting" : "ui-unselecting");
selectee.unselecting = !doSelect;
selectee.selecting = doSelect;
selectee.selected = doSelect;
// selectable (UN)SELECTING callback
if (doSelect) {
...