From 85f2ea4ca43ab2d10ee843356fe90cd79972fbfa Mon Sep 17 00:00:00 2001 From: desmaisons_david Date: Sun, 16 Oct 2016 16:17:46 -0200 Subject: [PATCH] correcting build problem on webpack --- dist/vuedraggable.js | 175 +++++++++++++++++++++++++++++++++++++++ dist/vuedraggable.min.js | 2 +- gulpfile.js | 13 ++- package.json | 6 +- 4 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 dist/vuedraggable.js diff --git a/dist/vuedraggable.js b/dist/vuedraggable.js new file mode 100644 index 00000000..f01f2aa6 --- /dev/null +++ b/dist/vuedraggable.js @@ -0,0 +1,175 @@ +'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; }; + +(function () { + "use strict"; + + function buildDraggable(Sortable) { + function removeNode(node) { + node.parentElement.removeChild(node); + } + + function insertNodeAt(fatherNode, node, position) { + if (position < fatherNode.children.length) { + fatherNode.insertBefore(node, fatherNode.children[position]); + } else { + fatherNode.appendChild(node); + } + } + + function computeVmIndex(vnodes, element) { + return vnodes.map(function (elt) { + return elt.elm; + }).indexOf(element); + } + + function updatePosition(collection, oldIndex, newIndex) { + if (collection) { + collection.splice(newIndex, 0, collection.splice(oldIndex, 1)[0]); + } + } + + function _computeIndexes(slots, children) { + return Array.prototype.map.call(children, function (elt) { + return computeVmIndex(slots, elt); + }); + } + + function merge(target, source) { + var output = Object(target); + for (var nextKey in source) { + if (source.hasOwnProperty(nextKey)) { + output[nextKey] = source[nextKey]; + } + } + return output; + } + + function emit(evtName, evtData) { + this.$emit(evtName.toLowerCase(), evtData); + } + + function delegateAndEmit(evtName) { + var _this = this; + + return function (evtData) { + _this['onDrag' + evtName](evtData); + emit.call(_this, evtName, evtData); + }; + } + + var props = { + options: Object, + list: { + type: Array, + required: false, + default: null + } + }; + + var draggableComponent = { + props: props, + + render: function render(h) { + return h('div', null, this.$slots.default); + }, + mounted: function mounted() { + var _this2 = this; + + var optionsAdded = {}; + ['Start', 'Add', 'Remove', 'Update', 'End'].forEach(function (elt) { + optionsAdded['on' + elt] = delegateAndEmit.call(_this2, elt); + }); + + ['Choose', 'Sort', 'Filter', 'Move', 'Clone'].forEach(function (elt) { + optionsAdded['on' + elt] = emit.bind(_this2, elt); + }); + + var options = merge(this.options, optionsAdded); + this._sortable = new Sortable(this.$el, options); + this.computeIndexes(); + }, + beforeDestroy: function beforeDestroy() { + this._sortable.destroy(); + }, + updated: function updated() { + this.computeIndexes(); + }, + + + methods: { + computeIndexes: function computeIndexes() { + var _this3 = this; + + this.$nextTick(function () { + _this3.visibleIndexes = _computeIndexes(_this3.$slots.default, _this3.$el.children); + }); + }, + onDragStart: function onDragStart(evt) { + if (!this.list) { + return; + } + var currentIndex = computeVmIndex(this.$slots.default, evt.item); + var element = this.list[currentIndex]; + this.context = { + currentIndex: currentIndex, + element: element + }; + evt.item._underlying_vm_ = element; + }, + onDragAdd: function onDragAdd(evt) { + var element = evt.item._underlying_vm_; + if (!this.list || element === undefined) { + return; + } + removeNode(evt.item); + var indexes = this.visibleIndexes; + var domNewIndex = evt.newIndex; + var numberIndexes = indexes.length; + var newIndex = domNewIndex > numberIndexes - 1 ? numberIndexes : indexes[domNewIndex]; + this.list.splice(newIndex, 0, element); + this.computeIndexes(); + }, + onDragRemove: function onDragRemove(evt) { + if (!this.list) { + return; + } + insertNodeAt(this.$el, evt.item, evt.oldIndex); + var isCloning = !!evt.clone; + if (isCloning) { + removeNode(evt.clone); + return; + } + var oldIndex = this.context.currentIndex; + this.list.splice(oldIndex, 1); + }, + onDragUpdate: function onDragUpdate(evt) { + if (!this.list) { + return; + } + removeNode(evt.item); + insertNodeAt(evt.from, evt.item, evt.oldIndex); + var oldIndexVM = this.context.currentIndex; + var newIndexVM = this.visibleIndexes[evt.newIndex]; + updatePosition(this.list, oldIndexVM, newIndexVM); + }, + onDragEnd: function onDragEnd(evt) { + this.computeIndexes(); + } + } + }; + + return draggableComponent; + } + + if (typeof exports == "object") { + var Sortable = require("sortablejs") + module.exports = buildDraggable(Sortable) + } else if (typeof define == "function" && define.amd) { + define(['Sortable'], function(Sortable) { return buildDraggable(Sortable);}); + } else if ( window && (window.Vue) && (window.Sortable)) { + var draggable = buildDraggable(window.Sortable) + Vue.component('draggable', draggable) + } +})(); \ No newline at end of file diff --git a/dist/vuedraggable.min.js b/dist/vuedraggable.min.js index 9de1e409..34fea817 100644 --- a/dist/vuedraggable.min.js +++ b/dist/vuedraggable.min.js @@ -1 +1 @@ -"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(){function t(t){function e(t){t.parentElement.removeChild(t)}function n(t,e,n){nr-1?r:i[o];this.list.splice(s,0,n),this.computeIndexes()}},onDragRemove:function(t){if(this.list){n(this.$el,t.item,t.oldIndex);var i=!!t.clone;if(i)return void e(t.clone);var o=this.context.currentIndex;this.list.splice(o,1)}},onDragUpdate:function(t){if(this.list){e(t.item),n(t.from,t.item,t.oldIndex);var i=this.context.currentIndex,r=this.visibleIndexes[t.newIndex];o(this.list,i,r)}},onDragEnd:function(t){this.computeIndexes()}}};return f}if("object"==("undefined"==typeof exports?"undefined":_typeof(exports))){var e=require("Sortablejs");module.exports=t(e)}else if("function"==typeof define&&define.amd)define(["Sortable"],function(e){return t(e)});else if(window&&window.Vue&&window.Sortable){var n=t(window.Sortable);Vue.component("draggable",n)}}(); \ No newline at end of file +"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(){function t(t){function e(t){t.parentElement.removeChild(t)}function n(t,e,n){nr-1?r:i[o];this.list.splice(s,0,n),this.computeIndexes()}},onDragRemove:function(t){if(this.list){n(this.$el,t.item,t.oldIndex);var i=!!t.clone;if(i)return void e(t.clone);var o=this.context.currentIndex;this.list.splice(o,1)}},onDragUpdate:function(t){if(this.list){e(t.item),n(t.from,t.item,t.oldIndex);var i=this.context.currentIndex,r=this.visibleIndexes[t.newIndex];o(this.list,i,r)}},onDragEnd:function(t){this.computeIndexes()}}};return f}if("object"==("undefined"==typeof exports?"undefined":_typeof(exports))){var e=require("sortablejs");module.exports=t(e)}else if("function"==typeof define&&define.amd)define(["Sortable"],function(e){return t(e)});else if(window&&window.Vue&&window.Sortable){var n=t(window.Sortable);Vue.component("draggable",n)}}(); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 1f36ae20..f6bc1525 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -20,7 +20,18 @@ gulp.task('scripts', function () { var rename = require('gulp-rename'); -gulp.task('js', ['scripts'], function () { +gulp.task('buildjs', ['scripts'], function () { + var jsFilter = $.filter('**/*.js', {restore: true}); + + return gulp.src('src/**/*.js') + .pipe(babel({ + presets: ['es2015'] + })) + .pipe(gulp.dest('dist')) + .pipe($.size()); +}); + +gulp.task('js', ['buildjs'], function () { var jsFilter = $.filter('**/*.js', {restore: true}); return gulp.src('src/**/*.js') diff --git a/package.json b/package.json index d0d358fd..4d2b2037 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "vuedraggable", - "version": "2.0.3", + "version": "2.0.4", "description": "draggable component for vue", - "main": "src/vuedraggable.js", + "main": "dist/vuedraggable.js", "files": [ - "src/vuedraggable.js" + "dist/vuedraggable.js" ], "keywords": [ "vue",