@@ -5,82 +5,109 @@ ember-sortablejs
5
5
6
6
This addon allows you to use drag and drop in your ember application using [ SortableJS/Sortable] ( https://github.com/SortableJS/Sortable )
7
7
8
-
9
8
Compatibility
10
9
------------------------------------------------------------------------------
11
10
12
11
* Ember.js v3.13 or above
13
12
* Ember CLI v3.13 or above
14
- * Node.js v8 or above
15
-
13
+ * Node.js v10 or above
16
14
17
15
Installation
18
16
------------------------------------------------------------------------------
19
-
17
+ > ** NOTE ** : The beta version is out. Please give me a hand and test it out.
20
18
```
21
- ember install ember-sortablejs
19
+ ember install ember-sortablejs@beta
22
20
```
23
21
22
+ This addon has a peer dependency on ` sortablejs ` that will be installed with the addon
23
+
24
+ Still to do
25
+ ------------------------------------------------------------------------------
26
+ Refer to the upcoming [ project] ( https://github.com/SortableJS/ember-sortablejs/projects/2 )
27
+
28
+ Library support
29
+ ------------------------------------------------------------------------------
30
+ Currently supported:
31
+ - [x] Drag from one list to another
32
+ - [x] Sort
33
+ - [x] Clone
34
+ - [ ] Swap
35
+ - [ ] Multi Drag
36
+ - [ ] Nested List
24
37
25
38
Usage
26
39
------------------------------------------------------------------------------
27
40
28
- ``` html
41
+ ``` hbs
29
42
<SortableJs
43
+ @items={{array "one" "two" "three" "four" "five"}}
30
44
@options={{hash animation=150 ghostClass="ghost-class" group="shared-list"}}
31
- @onChoose ={{fn this.onChoose}}
32
- @onUnchoose ={{fn this.onUnchoose}}
33
- @onStart ={{fn this.onStart}}
34
- @onEnd ={{fn this.onEnd}}
35
- @onAdd ={{fn this.onAdd}}
36
- @onUpdate ={{fn this.onUpdate}}
37
- @onRemove ={{fn this.onRemove}}
38
- @onMove ={{fn this.onMove}}
39
- @onClone ={{fn this.onClone}}
40
- @onChange ={{fn this.onChange}}
41
- as |sortable|
45
+ @onStart={{this.onStart}}
46
+ @onEnd={{this.onEnd}}
47
+ as |list|
42
48
>
43
- <div class =" list-group-item bg-yellow" >Item 1</div >
44
- <div class =" list-group-item bg-yellow" >Item 2</div >
45
- <div class =" list-group-item bg-yellow" >Item 3</div >
46
- <div class =" list-group-item bg-yellow" >Item 4</div >
47
- <div class =" list-group-item bg-yellow" >Item 5</div >
49
+ {{#each list as |item|}}
50
+ <div class="list-group-item bg-yellow">{{item.value}}</div>
51
+ {{/each}}
48
52
</SortableJs>
49
53
```
50
54
55
+ How it works
56
+ ------------------------------------------------------------------------------
57
+ SortableJs works by manipulating the DOM directly this is very compatible with
58
+ the Glimmer VM. To mitigate this we need tu use SortableJs as a middle and use
59
+ the events it emits to update state and prevent the DOM manipulation the lib does.
60
+
61
+ This is accomplished by maintaining an internal list. This list is a copy of the
62
+ array supplied via ` @items ` . The events ` onStart ` , ` onEnd ` , ` onUpdate ` , ` onAdd ` ,
63
+ ` onRemove ` are intercepted to prevent DOM manipulation and maintaining the internal
64
+ list.
65
+
66
+ I you have ideas on how to approach this better. Please open an issue 😄
67
+
68
+ Caveats
69
+ ------------------------------------------------------------------------------
70
+ - Not SortableJS plugins work.
71
+ - While you could bypass ` @items ` I highly discourage since the library manipulates the DOM directly.
72
+
51
73
Options
52
74
------------------------------------------------------------------------------
53
75
The addon supports all the options that sortable accepts, see: https://github.com/SortableJS/Sortable#options
54
76
55
- The events:
56
- - ` onChoose `
57
- - ` onUnchoose `
58
- - ` onStart `
59
- - ` onEnd `
60
- - ` onAdd `
61
- - ` onUpdate `
62
- - ` onSort `
63
- - ` onRemove `
64
- - ` onMove `
65
- - ` onClone `
66
- - ` onChange `
67
- - ` scrollFn `
68
- - ` setData `
69
- - ` onFilter `
70
- - ` onSpill `
71
-
72
- Should be in the component signature as closure actions.
73
- All actions get the events as described in the SortableJS docs as well as the sortable instance.
74
- ``` js
75
- onChoose (evt , sortable ) {... }
76
- ```
77
+ Component API
78
+ ------------------------------------------------------------------------------
79
+ | arg| type| description|
80
+ | :---| :---:| :---|
81
+ | ` @items ` | Array | A list of the items to be managed by the addon|
82
+ | ` @onChoose ` | Function | (SortablejsEvent) => {...}
83
+ | ` @onUnchoose ` | Function | (SortablejsEvent) => {...}
84
+ | ` @onStart ` | Function | (SortablejsEvent) => {...}
85
+ | ` @onEnd ` | Function | (SortablejsEvent, cancelDnD) => {...}
86
+ | ` @onAdd ` | Function | (SortablejsEvent) => {...}
87
+ | ` @onUpdate ` | Function | (SortablejsEvent) => {...}
88
+ | ` @onSort ` | Function | (SortablejsEvent) => {...}
89
+ | ` @onRemove ` | Function | (SortablejsEvent) => {...}
90
+ | ` @onMove ` | Function | (SortablejsMoveEvent) => {...}
91
+ | ` @onClone ` | Function | (SortablejsEvent) => {...}
92
+ | ` @onChange ` | Function | (SortablejsEvent) => {...}
93
+ | ` @scrollFn ` | Function | (SortablejsEvent) => {...}
94
+ | ` @setData ` | Function | (SortablejsEvent) => {...}
95
+ | ` @onFilter ` | Function | (SortablejsEvent) => {...}
96
+ | ` @onSpill ` | Function | (SortablejsEvent) => {...}
97
+
98
+ ` SortablejsEvent ` - A [ ` CustomEvent ` ] ( https://github.com/SortableJS/Sortable#event-object-demo ) provided by SortableJS
99
+
100
+ ` SortablejsMoveEvent ` - A [ ` CustomEvent ` ] ( https://github.com/SortableJS/Sortable#move-event-object ) provided by SortableJS
101
+
102
+ ` cancelDnD ` - A callback provided by the ember addon to basically undo you last drag and drop or sort;
103
+
77
104
Migrating from 1.x
78
105
------------------------------------------------------------------------------
79
106
- ` onSetData ` is no longer suported. Rename argument to ` setData ` .
80
107
- ` <SortableJs> ` no longer expects a wrapped list. Instead the addon itself will act as the sortable list container.
81
108
82
109
v1
83
- ``` html
110
+ ``` hbs
84
111
<SortableJs
85
112
@options={{hash animation=150 ghostClass="ghost-class" group="shared-list"}}
86
113
>
95
122
```
96
123
97
124
v2
98
- ``` html
125
+ ``` hbs
99
126
<SortableJs
100
127
class="list-group"
128
+ @items={{array "Item 1" "Item 2" "Item 3" "Item 4" "Item 5"}}
101
129
@options={{hash animation=150 ghostClass="ghost-class" group="shared-list"}}
130
+ as |list|
102
131
>
103
- <div class =" list-group-item" >Item 1</div >
104
- <div class =" list-group-item" >Item 2</div >
105
- <div class =" list-group-item" >Item 3</div >
106
- <div class =" list-group-item" >Item 4</div >
107
- <div class =" list-group-item" >Item 5</div >
132
+ {{#each list as |item|}}
133
+ <div class="list-group-item">Item 1</div>
134
+ {{/each}}
108
135
</SortableJs>
109
136
```
110
137
License
0 commit comments