diff --git a/README.md b/README.md index b3dcd451..a5260678 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,9 @@ Note that all the method starting by "on" will be ignored as draggable component Type: `String`
Default: `'div'` -HTML node type of the element that draggable component create as outer element for the included slot. +HTML node type of the element that draggable component create as outer element for the included slot.
+It is also possible to pass the name of vue component as element. In this case, draggable attribute will be passed to the create component.
+See also [componentData](#componentData) if you need to set props or event to the created component. #### clone Type: `Function`
@@ -178,6 +180,45 @@ checkMove: function(evt){ ``` See complete example: [Cancel.html](https://github.com/SortableJS/Vue.Draggable/blob/master/examples/Cancel.html), [cancel.js](https://github.com/SortableJS/Vue.Draggable/blob/master/examples/script/cancel.js) +#### componentData +Type: `Object`
+Required: `false`
+Default: `null`
+ +This props is used to pass additional information to child component declared by [element props](#element).
+Value: +* `props`: props to be passed to the child component +* `on`: events to be subscribe in the child component + +Example (using [element UI library](http://element.eleme.io/#/en-US)): +```HTML + + +
{{e.description}}
+
+
+``` +```javascript +methods: { + handleChange() { + console.log('changed'); + }, + inputChanged(value) { + this.activeNames = value; + }, + getComponentData() { + return { + on: { + change: this.handleChange, + input: this.inputChanged + }, + props: { + value: this.activeNames + } + }; + } + } +``` ### Events diff --git a/dist/vuedraggable.js b/dist/vuedraggable.js index 2e88e272..f3645485 100644 --- a/dist/vuedraggable.js +++ b/dist/vuedraggable.js @@ -1,7 +1,5 @@ 'use strict'; -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; - var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } @@ -395,7 +393,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr return draggableComponent; } - if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) == "object") { + if (typeof exports == "object") { var Sortable = require("sortablejs"); module.exports = buildDraggable(Sortable); } else if (typeof define == "function" && define.amd) { diff --git a/dist/vuedraggable.min.js b/dist/vuedraggable.min.js index 7972f16d..1c997dbd 100644 --- a/dist/vuedraggable.min.js +++ b/dist/vuedraggable.min.js @@ -1 +1 @@ -"use strict";function _toConsumableArray(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);ne-1?e:n[t]},getComponent:function(){return this.$slots["default"][0].componentInstance},resetTransitionData:function(t){if(this.noTransitionOnDrag&&this.transitionMode){var n=this.getChildrenNodes();n[t].data=null;var e=this.getComponent();e.children=[],e.kept=void 0}},onDragStart:function(t){this.context=this.getUnderlyingVm(t.item),t.item._underlying_vm_=this.clone(this.context.element),d=t.item},onDragAdd:function(t){var n=t.item._underlying_vm_;if(void 0!==n){e(t.item);var o=this.getVmIndex(t.newIndex);this.spliceList(o,0,n),this.computeIndexes();var i={element:n,newIndex:o};this.emitChanges({added:i})}},onDragRemove:function(t){if(o(this.rootContainer,t.item,t.oldIndex),this.isCloning)return void e(t.clone);var n=this.context.index;this.spliceList(n,1);var i={element:this.context.element,oldIndex:n};this.resetTransitionData(n),this.emitChanges({removed:i})},onDragUpdate:function(t){e(t.item),o(t.from,t.item,t.oldIndex);var n=this.context.index,i=this.getVmIndex(t.newIndex);this.updatePosition(n,i);var r={element:this.context.element,oldIndex:n,newIndex:i};this.emitChanges({moved:r})},computeFutureIndex:function(t,n){if(!t.element)return 0;var e=[].concat(_toConsumableArray(n.to.children)).filter(function(t){return"none"!==t.style.display}),o=e.indexOf(n.related),i=t.component.getVmIndex(o),r=e.indexOf(d)!=-1;return r||!n.willInsertAfter?i:i+1},onDragMove:function(t,n){var e=this.move;if(!e||!this.realList)return!0;var o=this.getRelatedContextFromMoveEvent(t),i=this.context,r=this.computeFutureIndex(o,t);return _extends(i,{futureIndex:r}),_extends(t,{relatedContext:o,draggedContext:i}),e(t,n)},onDragEnd:function(t){this.computeIndexes(),d=null}}};return h}if(Array.from||(Array.from=function(t){return[].slice.call(t)}),"object"==("undefined"==typeof exports?"undefined":_typeof(exports))){var e=require("sortablejs");module.exports=n(e)}else if("function"==typeof define&&define.amd)define(["sortablejs"],function(t){return n(t)});else if(window&&window.Vue&&window.Sortable){var o=n(window.Sortable);Vue.component("draggable",o)}}(); \ No newline at end of file +"use strict";function _toConsumableArray(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);ne-1?e:n[t]},getComponent:function(){return this.$slots["default"][0].componentInstance},resetTransitionData:function(t){if(this.noTransitionOnDrag&&this.transitionMode){var n=this.getChildrenNodes();n[t].data=null;var e=this.getComponent();e.children=[],e.kept=void 0}},onDragStart:function(t){this.context=this.getUnderlyingVm(t.item),t.item._underlying_vm_=this.clone(this.context.element),d=t.item},onDragAdd:function(t){var n=t.item._underlying_vm_;if(void 0!==n){e(t.item);var o=this.getVmIndex(t.newIndex);this.spliceList(o,0,n),this.computeIndexes();var i={element:n,newIndex:o};this.emitChanges({added:i})}},onDragRemove:function(t){if(o(this.rootContainer,t.item,t.oldIndex),this.isCloning)return void e(t.clone);var n=this.context.index;this.spliceList(n,1);var i={element:this.context.element,oldIndex:n};this.resetTransitionData(n),this.emitChanges({removed:i})},onDragUpdate:function(t){e(t.item),o(t.from,t.item,t.oldIndex);var n=this.context.index,i=this.getVmIndex(t.newIndex);this.updatePosition(n,i);var r={element:this.context.element,oldIndex:n,newIndex:i};this.emitChanges({moved:r})},computeFutureIndex:function(t,n){if(!t.element)return 0;var e=[].concat(_toConsumableArray(n.to.children)).filter(function(t){return"none"!==t.style.display}),o=e.indexOf(n.related),i=t.component.getVmIndex(o),r=e.indexOf(d)!=-1;return r||!n.willInsertAfter?i:i+1},onDragMove:function(t,n){var e=this.move;if(!e||!this.realList)return!0;var o=this.getRelatedContextFromMoveEvent(t),i=this.context,r=this.computeFutureIndex(o,t);return _extends(i,{futureIndex:r}),_extends(t,{relatedContext:o,draggedContext:i}),e(t,n)},onDragEnd:function(t){this.computeIndexes(),d=null}}};return h}if(Array.from||(Array.from=function(t){return[].slice.call(t)}),(typeof exports == "object")){var e=require("sortablejs");module.exports=n(e)}else if("function"==typeof define&&define.amd)define(["sortablejs"],function(t){return n(t)});else if(window&&window.Vue&&window.Sortable){var o=n(window.Sortable);Vue.component("draggable",o)}}(); \ No newline at end of file