From 81ab83613263c530cddd706fd286c2ca72953906 Mon Sep 17 00:00:00 2001 From: Pantelis Peslis Date: Tue, 5 Jul 2016 15:15:27 +0300 Subject: [PATCH] Compile using babel (fix #24) --- dist/vue-typeahead.common.js | 124 +++++++++++++++++++++++++++++++++++ dist/vue-typeahead.js | 123 ---------------------------------- package.json | 4 +- 3 files changed, 126 insertions(+), 125 deletions(-) create mode 100644 dist/vue-typeahead.common.js delete mode 100644 dist/vue-typeahead.js diff --git a/dist/vue-typeahead.common.js b/dist/vue-typeahead.common.js new file mode 100644 index 0000000..dd929c7 --- /dev/null +++ b/dist/vue-typeahead.common.js @@ -0,0 +1,124 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); + +var _defineProperty3 = _interopRequireDefault(_defineProperty2); + +var _assign = require('babel-runtime/core-js/object/assign'); + +var _assign2 = _interopRequireDefault(_assign); + +var _vue = require('vue'); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = { + data: function data() { + return { + items: [], + query: '', + current: -1, + loading: false, + queryParamName: 'q' + }; + }, + + + computed: { + hasItems: function hasItems() { + return this.items.length > 0; + }, + isEmpty: function isEmpty() { + return !this.query; + }, + isDirty: function isDirty() { + return !!this.query; + } + }, + + methods: { + update: function update() { + var _this = this; + + if (!this.query) { + return this.reset(); + } + + if (this.minChars && this.query.length < this.minChars) { + return; + } + + this.loading = true; + + this.fetch().then(function (response) { + if (_this.query) { + var data = response.data; + data = _this.prepareResponseData ? _this.prepareResponseData(data) : data; + _this.items = _this.limit ? data.slice(0, _this.limit) : data; + _this.current = -1; + _this.loading = false; + } + }); + }, + fetch: function fetch() { + if (!this.$http) { + return _vue.util.warn('You need to install the `vue-resource` plugin', this); + } + + if (!this.src) { + return _vue.util.warn('You need to set the `src` property', this); + } + + if (this.src.substr(-1) !== '/') { + this.src += '/'; + } + + var src = this.queryParamName ? this.src : this.src + this.query; + + var params = this.queryParamName ? (0, _assign2.default)((0, _defineProperty3.default)({}, this.queryParamName, this.query), this.data) : this.data; + + return this.$http.get(src, params); + }, + reset: function reset() { + this.items = []; + this.query = ''; + this.loading = false; + }, + setActive: function setActive(index) { + this.current = index; + }, + activeClass: function activeClass(index) { + return { + active: this.current === index + }; + }, + hit: function hit() { + if (this.current !== -1) { + this.onHit(this.items[this.current]); + } + }, + up: function up() { + if (this.current > 0) { + this.current--; + } else if (this.current === -1) { + this.current = this.items.length - 1; + } else { + this.current = -1; + } + }, + down: function down() { + if (this.current < this.items.length - 1) { + this.current++; + } else { + this.current = -1; + } + }, + onHit: function onHit() { + _vue.util.warn('You need to implement the `onHit` method', this); + } + } +}; diff --git a/dist/vue-typeahead.js b/dist/vue-typeahead.js deleted file mode 100644 index 48e598e..0000000 --- a/dist/vue-typeahead.js +++ /dev/null @@ -1,123 +0,0 @@ -'use strict'; - -var vue = require('vue'); - -var main = { - data () { - return { - items: [], - query: '', - current: -1, - loading: false, - queryParamName: 'q' - } - }, - - computed: { - hasItems () { - return this.items.length > 0 - }, - - isEmpty () { - return !this.query - }, - - isDirty () { - return !!this.query - } - }, - - methods: { - update () { - if (!this.query) { - return this.reset() - } - - if (this.minChars && this.query.length < this.minChars) { - return - } - - this.loading = true - - this.fetch().then((response) => { - if (this.query) { - let data = response.data - data = this.prepareResponseData ? this.prepareResponseData(data) : data - this.items = this.limit ? data.slice(0, this.limit) : data - this.current = -1 - this.loading = false - } - }) - }, - - fetch () { - if (!this.$http) { - return vue.util.warn('You need to install the `vue-resource` plugin', this) - } - - if (!this.src) { - return vue.util.warn('You need to set the `src` property', this) - } - - if (this.src.substr(-1) !== '/') { - this.src += '/' - } - - const src = this.queryParamName - ? this.src - : this.src + this.query - - const params = this.queryParamName - ? Object.assign({ [this.queryParamName]: this.query }, this.data) - : this.data - - return this.$http.get(src, params) - }, - - reset () { - this.items = [] - this.query = '' - this.loading = false - }, - - setActive (index) { - this.current = index - }, - - activeClass (index) { - return { - active: this.current === index - } - }, - - hit () { - if (this.current !== -1) { - this.onHit(this.items[this.current]) - } - }, - - up () { - if (this.current > 0) { - this.current-- - } else if (this.current === -1) { - this.current = this.items.length - 1 - } else { - this.current = -1 - } - }, - - down () { - if (this.current < this.items.length - 1) { - this.current++ - } else { - this.current = -1 - } - }, - - onHit () { - vue.util.warn('You need to implement the `onHit` method', this) - } - } -} - -module.exports = main; \ No newline at end of file diff --git a/package.json b/package.json index 5e522f1..525dccd 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "vue", "typeahead" ], - "main": "dist/vue-typeahead.js", + "main": "dist/vue-typeahead.common.js", "repository": { "type": "git", "url": "https://github.com/pespantelis/vue-typeahead.git" @@ -19,7 +19,7 @@ "lint": "eslint src demo", "dev": "webpack-dev-server --content-base demo/ --inline --hot", "build": "cross-env NODE_ENV=production webpack --progress --hide-modules", - "dist": "rollup src/main.js -o dist/vue-typeahead.js -f cjs" + "dist": "babel src/main.js --out-file dist/vue-typeahead.common.js" }, "dependencies": { "babel-runtime": "^6.0.0",