@satriobagasp/vue-slicksort 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018, Jordan Simonds
4
+
5
+ Copyright for portions of this project are held by Claudéric Demers, 2016, as part of project react-sortable-hoc.
6
+ All other copyright for this project are held by Jordan Simonds, 2018.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,461 @@
1
+ # Vue Slicksort 🖖
2
+
3
+ ![Slicksort logo](/logo/logomark.png)
4
+
5
+ > A set of component mixins to turn any list into an animated, touch-friendly, sortable list.
6
+ > Based on [react-sortable-hoc](https://github.com/clauderic/react-sortable-hoc) by [@clauderic]
7
+
8
+ [![npm version](https://img.shields.io/npm/v/vue-slicksort.svg)](https://www.npmjs.com/package/vue-slicksort)
9
+ [![npm downloads](https://img.shields.io/npm/dm/vue-slicksort.svg)](https://www.npmjs.com/package/vue-slicksort)
10
+ [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/Jexordexan/vue-slicksort/blob/master/LICENSE)
11
+ ![gzip size](http://img.badgesize.io/https://npmcdn.com/vue-slicksort?compression=gzip)
12
+
13
+ <p align="center">
14
+ <a href="https://vue-slicksort.netlify.app/">
15
+ <img src="logo/demo.gif">
16
+ </a>
17
+ </p>
18
+
19
+ ### Examples available here: [vue-slicksort.netlify.app/](https://vue-slicksort.netlify.app/)
20
+
21
+ ### [中文文档](./doc/zh.md)
22
+
23
+ ## Features
24
+
25
+ - **`v-model` Compatible** – Make any array editable with the `v-model` standard
26
+ - **Mixin Components** – Integrates with your existing components
27
+ - **Standalone Components** – Easy to use components for slick lists
28
+ - **Drag handle, auto-scrolling, locked axis, events, and more!**
29
+ - **Suuuper smooth animations** – Chasing the 60FPS dream 🌈
30
+ - **Horizontal lists, vertical lists, or a grid** ↔ ↕ ⤡
31
+ - **Touch support** 👌
32
+ - **Oh yeah, and it's DEPENDENCY FREE!** 👌
33
+
34
+ ## Installation
35
+
36
+ Using [npm](https://www.npmjs.com/package/vue-slicksort):
37
+
38
+ ```
39
+ $ npm install vue-slicksort --save
40
+ ```
41
+
42
+ Using yarn:
43
+
44
+ ```
45
+ $ yarn add vue-slicksort
46
+ ```
47
+
48
+ Using a CDN:
49
+
50
+ ```html
51
+ <script src="https://unpkg.com/vue-slicksort@latest/dist/vue-slicksort.min.js"></script>
52
+ ```
53
+
54
+ Then, using a module bundler that supports either CommonJS or ES2015 modules, such as [webpack](https://github.com/webpack/webpack):
55
+
56
+ ```js
57
+ // Using an ES6 transpiler like Babel
58
+ import { ContainerMixin, ElementMixin } from 'vue-slicksort';
59
+
60
+ // Not using an ES6 transpiler
61
+ var slicksort = require('vue-slicksort');
62
+ var ContainerMixin = slicksort.ContainerMixin;
63
+ var ElementMixin = slicksort.ElementMixin;
64
+ ```
65
+
66
+ If you are loading the package via `<script>` tag:
67
+
68
+ ```html
69
+ <script>
70
+ var { ContainerMixin, ElementMixin, HandleDirective } = window.VueSlicksort;
71
+ </script>
72
+ ```
73
+
74
+ ## Usage
75
+
76
+ Check out the docs: [vue-slicksort.netlify.app](https://vue-slicksort.netlify.app/)
77
+
78
+ <!--
79
+ ## Usage
80
+
81
+ ### Basic Example
82
+
83
+ ```js
84
+ import Vue from 'vue';
85
+ import { ContainerMixin, ElementMixin } from 'vue-slicksort';
86
+
87
+ const SortableList = {
88
+ mixins: [ContainerMixin],
89
+ template: `
90
+ <ul class="list">
91
+ <slot />
92
+ </ul>
93
+ `,
94
+ };
95
+
96
+ const SortableItem = {
97
+ mixins: [ElementMixin],
98
+ props: ['item'],
99
+ template: `
100
+ <li class="list-item">{{item}}</li>
101
+ `,
102
+ };
103
+
104
+ const ExampleVue = {
105
+ name: 'Example',
106
+ template: `
107
+ <div class="root">
108
+ <SortableList lockAxis="y" v-model="items">
109
+ <SortableItem v-for="(item, index) in items" :index="index" :key="index" :item="item"/>
110
+ </SortableList>
111
+ </div>
112
+ `,
113
+ components: {
114
+ SortableItem,
115
+ SortableList,
116
+ },
117
+ data() {
118
+ return {
119
+ items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8'],
120
+ };
121
+ },
122
+ };
123
+
124
+ const app = new Vue({
125
+ el: '#root',
126
+ render: (h) => h(ExampleVue),
127
+ });
128
+ ```
129
+
130
+ That's it! Vue Slicksort does not come with any styles by default, since it's meant to enhance your existing components.
131
+
132
+ ## Slicksort components
133
+
134
+ There are two pre-built components that implement the two mixins. Use them like this:
135
+
136
+ ```javascript
137
+ import { SlickList, SlickItem } from 'vue-slicksort';
138
+
139
+ const ExampleVue = {
140
+ name: 'Example',
141
+ template: `
142
+ <div class="root">
143
+ <SlickList lockAxis="y" v-model="items" tag="ul">
144
+ <SlickItem v-for="(item, index) in items" :index="index" :key="index" tag="li">
145
+ {{ item }}
146
+ </SlickItem>
147
+ </SlickList>
148
+ </div>
149
+ `,
150
+ components: {
151
+ SlickItem,
152
+ SlickList,
153
+ },
154
+ data() {
155
+ return {
156
+ items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8'],
157
+ };
158
+ },
159
+ };
160
+ ``` -->
161
+
162
+ <!-- More code examples are available [here](https://github.com/Jexordexan/vue-slicksort/blob/master/examples/). -->
163
+
164
+ ## Why should I use this?
165
+
166
+ There are already a number of great Drag & Drop libraries out there (for instance, [vuedraggable](https://github.com/SortableJS/Vue.Draggable) is fantastic). If those libraries fit your needs, you should definitely give them a try first. However, most of those libraries rely on the HTML5 Drag & Drop API, which has some severe limitations. For instance, things rapidly become tricky if you need to support touch devices, if you need to lock dragging to an axis, or want to animate the nodes as they're being sorted. Vue Slicksort aims to provide a simple set of component mixins to fill those gaps. If you're looking for a dead-simple, mobile-friendly way to add sortable functionality to your lists, then you're in the right place.
167
+ <!--
168
+ ## Customization and props
169
+
170
+ You apply options as individual `props` on whatever component is using the `ContainerMixin`. The component also emits several events during a sorting operation. Here's an example of a customized component:
171
+
172
+ ```html
173
+ <SortableContainer
174
+ :value="items"
175
+ :transitionDuration="250"
176
+ :lockAxis="'y'"
177
+ :useDragHandle="true"
178
+ @sort-start="onSortStart($event)"
179
+ >
180
+ </SortableContainer>
181
+ ```
182
+
183
+ ## `ContainerMixin`
184
+
185
+ ### Props
186
+
187
+ #### `value` _(required)_
188
+
189
+ type: _Array_
190
+
191
+ The `value` can be inherited from `v-model` but has to be set to the same list that is rendered with `v-for` inside the `Container`
192
+
193
+ #### `axis`
194
+
195
+ type: _String_
196
+
197
+ default: `y`
198
+
199
+ Items can be sorted horizontally, vertically or in a grid. Possible values: `x`, `y` or `xy`
200
+
201
+ #### `lockAxis`
202
+
203
+ type: _String_
204
+
205
+ If you'd like, you can lock movement to an axis while sorting. This is not something that is possible with HTML5 Drag & Drop
206
+
207
+ #### `helperClass`
208
+
209
+ type: _String_
210
+
211
+ You can provide a class you'd like to add to the sortable helper to add some styles to it
212
+
213
+ #### `appendTo`
214
+
215
+ type: _String_
216
+
217
+ default: `body`
218
+
219
+ You can provide a querySelector string you'd like to add to the sorting element to add parent dom
220
+
221
+ #### `transitionDuration`
222
+
223
+ type: _Number_
224
+
225
+ default: `300`
226
+
227
+ The duration of the transition when elements shift positions. Set this to `0` if you'd like to disable transitions
228
+
229
+ #### `draggedSettlingDuration`
230
+
231
+ type: _Number_
232
+
233
+ default: `null`
234
+
235
+ Override the settling duration for the drag helper. If not set, `transitionDuration` will be used.
236
+
237
+ #### `pressDelay`
238
+
239
+ type: _Number_
240
+
241
+ default: `0`
242
+
243
+ If you'd like elements to only become sortable after being pressed for a certain time, change this property. A good sensible default value for mobile is `200`. Cannot be used in conjunction with the `distance` prop.
244
+
245
+ #### `pressThreshold`
246
+
247
+ type: _Number_
248
+
249
+ default: `5`
250
+
251
+ Number of pixels of movement to tolerate before ignoring a press event.
252
+
253
+ #### `distance`
254
+
255
+ type: _Number_
256
+
257
+ default: `0`
258
+
259
+ If you'd like elements to only become sortable after being dragged a certain number of pixels. Cannot be used in conjunction with the `pressDelay` prop.
260
+
261
+ #### `useDragHandle`
262
+
263
+ type: _Boolean_
264
+
265
+ default: `false`
266
+
267
+ If you're using the `HandleDirective`, set this to `true`
268
+
269
+ #### `useWindowAsScrollContainer`
270
+
271
+ type: _Boolean_
272
+
273
+ default: `false`
274
+
275
+ If you want, you can set the `window` as the scrolling container
276
+
277
+ #### `hideSortableGhost`
278
+
279
+ type: _Boolean_
280
+
281
+ default: `true`
282
+
283
+ Whether to auto-hide the ghost element. By default, as a convenience, Vue Slicksort List will automatically hide the element that is currently being sorted. Set this to false if you would like to apply your own styling.
284
+
285
+ #### `lockToContainerEdges`
286
+
287
+ type: _Boolean_
288
+
289
+ default: `false`
290
+
291
+ You can lock movement of the sortable element to it's parent `Container`
292
+
293
+ #### `lockOffset`
294
+
295
+ type: _`OffsetValue` or [ `OffsetValue`, `OffsetValue` ]_\*
296
+
297
+ default: `"50%"`
298
+
299
+ When `lockToContainerEdges` is set to `true`, this controls the offset distance between the sortable helper and the top/bottom edges of it's parent `Container`. Percentage values are relative to the height of the item currently being sorted. If you wish to specify different behaviours for locking to the _top_ of the container vs the _bottom_, you may also pass in an `array` (For example: `["0%", "100%"]`).
300
+
301
+ \* `OffsetValue` can either be a finite `Number` or a `String` made up of a number and a unit (`px` or `%`).
302
+ Examples: `10` (which is the same as `"10px"`), `"50%"`
303
+
304
+ #### `shouldCancelStart`
305
+
306
+ type: _Function_
307
+
308
+ default: [Function](https://github.com/Jexordexan/vue-slicksort/blob/master/src/ContainerMixin.js#L41)
309
+
310
+ This function is invoked before sorting begins, and can be used to programatically cancel sorting before it begins. By default, it will cancel sorting if the event target is either an `input`, `textarea`, `select` or `option`.
311
+
312
+ #### `getHelperDimensions`
313
+
314
+ type: _Function_
315
+
316
+ default: [Function](https://github.com/Jexordexan/vue-slicksort/blob/master/src/ContainerMixin.js#L49)
317
+
318
+ Optional `function({node, index})` that should return the computed dimensions of the SortableHelper. See [default implementation](https://github.com/Jexordexan/vue-slicksort/blob/master/src/ContainerMixin.js#L49) for more details
319
+
320
+ ### Events
321
+
322
+ Events are emitted from the Container element, and can be bound to using `v-bind` or `@` directives
323
+
324
+ #### `@sort-start`
325
+
326
+ emits: `{ event: MouseEvent, node: HTMLElement, index: number }`
327
+
328
+ Fired when sorting begins.
329
+
330
+ #### `@sort-move`
331
+
332
+ emits: `{ event }`
333
+
334
+ Fired when the mouse is moved during sorting.
335
+
336
+ #### `@sort-end`
337
+
338
+ emits: `{ event, newIndex, oldIndex }`
339
+
340
+ Fired when sorting has ended.
341
+
342
+ #### `@input`
343
+
344
+ emits: `Array`
345
+
346
+ Fired after sorting has ended with the newly sorted list.
347
+
348
+ ---
349
+
350
+ ## `ElementMixin`
351
+
352
+ ### Props
353
+
354
+ #### `index` _(required)_
355
+
356
+ type: _Number_
357
+
358
+ This is the element's sortableIndex within it's collection. This prop is required.
359
+
360
+ #### `collection`
361
+
362
+ **REMOVED IN v2.0.0**
363
+ Use `group` and multiple scroll containers instead.
364
+
365
+ type: _Number or String_
366
+
367
+ default: `0`
368
+
369
+ The collection the element is part of. This is useful if you have multiple groups of sortable elements within the same `Container`. [Example](http://Jexordexan.github.io/vue-slicksort/#/basic-configuration/multiple-lists)
370
+
371
+ #### `disabled`
372
+
373
+ type: _Boolean_
374
+
375
+ default: `false`
376
+
377
+ Whether the element should be sortable or not
378
+
379
+ ## `HandleDirective`
380
+
381
+ The `v-handle` directive is used inside the draggable element.
382
+
383
+ The Container must have the `:useDragHandle` prop set to `true` for the handle to work as expected.
384
+
385
+ Here is an example for a simple element with a handle:
386
+
387
+ ```html
388
+ <template>
389
+ <li class="list-item">
390
+ <span v-handle class="handle"></span>
391
+ {{item.value}}
392
+ </li>
393
+ </template>
394
+
395
+ <script>
396
+ import { ElementMixin, HandleDirective } from 'vue-slicksort';
397
+
398
+ export default {
399
+ mixins: [ElementMixin],
400
+ directives: { handle: HandleDirective },
401
+ };
402
+ </script>
403
+ ``` -->
404
+
405
+ # FAQ
406
+
407
+ <!-- ### Running Examples
408
+
409
+ In root folder:
410
+
411
+ ```
412
+ $ npm install
413
+ $ npm run storybook
414
+ ``` -->
415
+
416
+
417
+ ### Upgrade from v1.x
418
+
419
+ There are a few changes in v2, mainly support for Vue 3 and dragging between groups. Read more about migrating here:
420
+ [vue-slicksort.netlify.app/migrating-1x](https://vue-slicksort.netlify.app/migrating-1x)
421
+
422
+ ### Upgrade from v0.x
423
+
424
+ The event names have all changed from camelCase to dash-case to accommodate for inline HTML templates.
425
+
426
+ ### Grid support?
427
+
428
+ Need to sort items in a grid? We've got you covered! Just set the `axis` prop to `xy`. Grid support is currently limited to a setup where all the cells in the grid have the same width and height, though we're working hard to get variable width support in the near future.
429
+
430
+ ### Item disappearing when sorting / CSS issues
431
+
432
+ Upon sorting, `vue-slicksort` creates a clone of the element you are sorting (the _sortable-helper_) and appends it to the end of the `appendTo` tag. The original element will still be in-place to preserve its position in the DOM until the end of the drag (with inline-styling to make it invisible). If the _sortable-helper_ gets messed up from a CSS standpoint, consider that maybe your selectors to the draggable item are dependent on a parent element which isn't present anymore (again, since the _sortable-helper_ is at the end of the `appendTo` prop). This can also be a `z-index` issue, for example, when using `vue-slicksort` within a Bootstrap modal, you'll need to increase the `z-index` of the SortableHelper so it is displayed on top of the modal.
433
+
434
+ ### Click events being swallowed
435
+
436
+ By default, `vue-slicksort` is triggered immediately on `mousedown`. If you'd like to prevent this behaviour, there are a number of strategies readily available. You can use the `distance` prop to set a minimum distance (in pixels) to be dragged before sorting is enabled. You can also use the `pressDelay` prop to add a delay before sorting is enabled. Alternatively, you can also use the [HandleDirective](https://github.com/Jexordexan/vue-slicksort/blob/master/src/HandleDirective.js).
437
+
438
+ ### Scoped styles
439
+
440
+ If you are using scoped styles on the sortable list, you can use `appendTo` prop.
441
+
442
+ ## Dependencies
443
+
444
+ Slicksort has no dependencies.
445
+ `vue` is the only peerDependency
446
+
447
+ ## Reporting Issues
448
+
449
+ If believe you've found an issue, please [report it](https://github.com/Jexordexan/vue-slicksort/issues) along with any relevant details to reproduce it. The easiest way to do so is to fork this [jsfiddle](https://jsfiddle.net/Jexordexan/1puv2L6c/).
450
+
451
+ ## Asking for help
452
+
453
+ Please file an issue for personal support requests. Tag them with `question`.
454
+
455
+ ## Contributions
456
+
457
+ Yes please! Feature requests / pull requests are welcome.
458
+
459
+ ## Thanks
460
+
461
+ This library is heavily based on [react-sortable-hoc](https://github.com/clauderic/react-sortable-hoc) by Claudéric Demers (@clauderic). A very simple and low overhead implementation of drag and drop that looks and performs great!