bullet_train-sortable 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +1 -1
- data/app/javascript/concerns/index.js +1 -0
- data/app/javascript/controllers/index.js +18 -0
- data/app/javascript/controllers/sortable_controller.js +80 -0
- data/app/javascript/index.js +2 -0
- data/lib/bullet_train/sortable/version.rb +1 -1
- metadata +7 -4
- data/app/javascript/concerns/sortable.js +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e84511987b36e406e093226b47388d30f93efcc481666a42718bd866ca5e13c
|
4
|
+
data.tar.gz: 5e92c6e7f2ec330a6c66caa683dcc2e9665da9047a39db7cc7619d969296d070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b37f7953f0229ee1bf9ff2349f01137b0a8ccfd1eb1f12efd9e3ffe1834579288368c6677346a8ce98f26a09245e446bf9256f392c8551e04076572a388a3215
|
7
|
+
data.tar.gz: a79e8e3f162bcbed90578dc349a0bd83598043f58bb519eaf64cc697a8031f52094f367c621da19a8b3e0a8f5015b266115d6a0ba865031c73b3fe8d1254f558
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,7 @@ $ gem install bullet_train-sortable
|
|
22
22
|
```
|
23
23
|
|
24
24
|
## Contributing
|
25
|
-
|
25
|
+
See [`RELEASE.md` in bullet_train-base](https://github.com/bullet-train-co/bullet_train-base/blob/main/RELEASE.md) for instructions on local development and for publishing both the gem and the npm package.
|
26
26
|
|
27
27
|
## License
|
28
28
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1 @@
|
|
1
|
+
import "./reassignable"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { identifierForContextKey } from "@hotwired/stimulus-webpack-helpers"
|
2
|
+
|
3
|
+
import SortableController from './sortable_controller'
|
4
|
+
|
5
|
+
export const controllerDefinitions = [
|
6
|
+
[SortableController, 'sortable_controller.js']
|
7
|
+
].map(function(d) {
|
8
|
+
const key = d[1]
|
9
|
+
const controller = d[0]
|
10
|
+
return {
|
11
|
+
identifier: identifierForContextKey(key),
|
12
|
+
controllerConstructor: controller
|
13
|
+
}
|
14
|
+
})
|
15
|
+
|
16
|
+
export {
|
17
|
+
SortableController
|
18
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
require("dragula/dist/dragula.min.css")
|
3
|
+
|
4
|
+
import dragula from 'dragula';
|
5
|
+
|
6
|
+
export default class extends Controller {
|
7
|
+
static values = {
|
8
|
+
reorderPath: String,
|
9
|
+
saveOnReorder: { type: Boolean, default: true }
|
10
|
+
}
|
11
|
+
|
12
|
+
// will be reissued as native dom events name prepended with 'sortable:' e.g. 'sortable:drag', 'sortable:drop', etc
|
13
|
+
static pluginEventsToReissue = [ "drag", "dragend", "drop", "cancel", "remove", "shadow", "over", "out", "cloned" ]
|
14
|
+
|
15
|
+
connect() {
|
16
|
+
if (!this.hasReorderPathValue) { return }
|
17
|
+
this.initPluginInstance()
|
18
|
+
}
|
19
|
+
|
20
|
+
disconnect() {
|
21
|
+
this.teardownPluginInstance()
|
22
|
+
}
|
23
|
+
|
24
|
+
initPluginInstance() {
|
25
|
+
const self = this
|
26
|
+
this.plugin = dragula([this.element], {
|
27
|
+
moves: function(el, container, handle) {
|
28
|
+
var $handles = $(el).find('.reorder-handle')
|
29
|
+
if ($handles.length) {
|
30
|
+
return !!$(handle).closest('.reorder-handle').length
|
31
|
+
} else {
|
32
|
+
if (!$(handle).closest('.undraggable').length) {
|
33
|
+
return self.element === container
|
34
|
+
} else {
|
35
|
+
return false
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
39
|
+
accepts: function (el, target, source, sibling) {
|
40
|
+
if ($(sibling).hasClass('undraggable') && $(sibling).prev().hasClass('undraggable')) {
|
41
|
+
return false
|
42
|
+
} else {
|
43
|
+
return true
|
44
|
+
}
|
45
|
+
},
|
46
|
+
}).on('drop', function (el) {
|
47
|
+
// save order here.
|
48
|
+
if (self.saveOnReorderValue) {
|
49
|
+
self.saveSortOrder()
|
50
|
+
}
|
51
|
+
}).on('over', function (el, container) {
|
52
|
+
// deselect any text fields, or else things go slow!
|
53
|
+
$(document.activeElement).blur()
|
54
|
+
})
|
55
|
+
|
56
|
+
this.initReissuePluginEventsAsNativeEvents()
|
57
|
+
}
|
58
|
+
|
59
|
+
initReissuePluginEventsAsNativeEvents() {
|
60
|
+
this.constructor.pluginEventsToReissue.forEach((eventName) => {
|
61
|
+
this.plugin.on(eventName, (...args) => {
|
62
|
+
this.dispatch(eventName, { detail: { plugin: 'dragula', type: eventName, args: args }})
|
63
|
+
})
|
64
|
+
})
|
65
|
+
}
|
66
|
+
|
67
|
+
teardownPluginInstance() {
|
68
|
+
if (this.plugin === undefined) { return }
|
69
|
+
|
70
|
+
// revert to original markup, remove any event listeners
|
71
|
+
this.plugin.destroy()
|
72
|
+
}
|
73
|
+
|
74
|
+
saveSortOrder() {
|
75
|
+
var idsInOrder = Array.from(this.element.childNodes).map((el) => { return parseInt(el.dataset?.id) });
|
76
|
+
|
77
|
+
$.post(this.reorderPathValue, {ids_in_order: idsInOrder})
|
78
|
+
}
|
79
|
+
|
80
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-sortable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -36,8 +36,11 @@ files:
|
|
36
36
|
- Rakefile
|
37
37
|
- app/assets/config/bullet_train_sortable_manifest.js
|
38
38
|
- app/controllers/concerns/sortable_actions.rb
|
39
|
+
- app/javascript/concerns/index.js
|
39
40
|
- app/javascript/concerns/reassignable.js
|
40
|
-
- app/javascript/
|
41
|
+
- app/javascript/controllers/index.js
|
42
|
+
- app/javascript/controllers/sortable_controller.js
|
43
|
+
- app/javascript/index.js
|
41
44
|
- app/models/concerns/sortable.rb
|
42
45
|
- config/routes.rb
|
43
46
|
- lib/bullet_train/sortable.rb
|
@@ -65,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
68
|
- !ruby/object:Gem::Version
|
66
69
|
version: '0'
|
67
70
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
71
|
+
rubygems_version: 3.3.7
|
69
72
|
signing_key:
|
70
73
|
specification_version: 4
|
71
74
|
summary: Bullet Train Sortable
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require("dragula/dist/dragula.min.css")
|
2
|
-
|
3
|
-
import dragula from 'dragula';
|
4
|
-
|
5
|
-
function saveSortOrder($container) {
|
6
|
-
var idsInOrder = $container.find('> *').map(function(index,element) { return parseInt($(element).attr('data-id')); }).toArray();
|
7
|
-
$.post($container.attr('data-reorder'), {ids_in_order: idsInOrder}, function() {
|
8
|
-
if ($container.closest('.opened-modally').length) {
|
9
|
-
refreshModalBase();
|
10
|
-
}
|
11
|
-
});
|
12
|
-
}
|
13
|
-
|
14
|
-
function enableSortable($scope) {
|
15
|
-
setTimeout(function() {
|
16
|
-
var selector = '[data-reorder]';
|
17
|
-
var $reorderable = $scope.find(selector).addBack(selector);
|
18
|
-
console.log("enabling sort on array of " + $reorderable.length);
|
19
|
-
|
20
|
-
$reorderable.each(function (index, container) {
|
21
|
-
|
22
|
-
var $container = $(container);
|
23
|
-
|
24
|
-
// enable drag-and-drop reordering.
|
25
|
-
var dragulaObj = dragula([container], {
|
26
|
-
moves: function(el, container, handle) {
|
27
|
-
var $handles = $(el).find('.reorder-handle')
|
28
|
-
if ($handles.length) {
|
29
|
-
return !!$(handle).closest('.reorder-handle').length
|
30
|
-
} else {
|
31
|
-
if (!$(handle).closest('.undraggable').length) {
|
32
|
-
return $(handle).closest('[data-reorder]')[0] == container;
|
33
|
-
} else {
|
34
|
-
return false;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
},
|
38
|
-
accepts: function (el, target, source, sibling) {
|
39
|
-
if ($(sibling).hasClass('undraggable') && $(sibling).prev().hasClass('undraggable')) {
|
40
|
-
return false;
|
41
|
-
} else {
|
42
|
-
return true;
|
43
|
-
}
|
44
|
-
},
|
45
|
-
}).on('drop', function (el) {
|
46
|
-
|
47
|
-
// save order here.
|
48
|
-
saveSortOrder($container);
|
49
|
-
|
50
|
-
}).on('over', function (el, container) {
|
51
|
-
|
52
|
-
// deselect any text fields, or else things go slow!
|
53
|
-
$(document.activeElement).blur();
|
54
|
-
|
55
|
-
});
|
56
|
-
|
57
|
-
});
|
58
|
-
}, 500);
|
59
|
-
}
|
60
|
-
|
61
|
-
$(document).on('turbo:load', function() {
|
62
|
-
console.log("🍩 Sortable: Enabling on <body> after a Turbo load.")
|
63
|
-
enableSortable($('body'));
|
64
|
-
})
|
65
|
-
|
66
|
-
$(document).on('sprinkles:update', function(event) {
|
67
|
-
console.log("🍩 Sortable: Enabling on the following element after a Sprinkles content update:")
|
68
|
-
console.log(event.target);
|
69
|
-
enableSortable($(event.target));
|
70
|
-
})
|