diff --git a/babel.config.js b/babel.config.js index ba17966..9f3933c 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,5 +1,5 @@ module.exports = { presets: [ - '@vue/app' + ['@vue/app', { "useBuiltIns": false }] ] } diff --git a/package.json b/package.json index b0bf051..87ef866 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,40 @@ { - "name": "vlm", - "version": "0.1.0", - "private": true, + "name": "vue-last-modal", + "description": "Minimalistic promise-based, programmatically-opening & stacking modal plugin for Vue.js.", + "version": "1.0.0", + "main": "dist/last-modal.umd.min.js", + "repository": { + "type": "git", + "url": "git+https://github.com/greegus/vue-last-modal.git" + }, + "keywords": [ + "vue", + "modal", + "plugin", + "vuejs", + "dialog", + "stacking", + "promise", + "component", + "web" + ], + "author": "Matus Duchon", + "license": "MIT", + "homepage": "https://github.com/greegus/vue-last-modal#readme", + "bugs": { + "url": "https://github.com/greegus/vue-last-modal/issues" + }, "scripts": { "serve": "vue-cli-service serve", - "build": "vue-cli-service build" + "build": "vue-cli-service build --target lib --name last-modal src/last-modal.js" }, "dependencies": { - "vue": "^2.5.22" + "vue": "^2.5.0" }, "devDependencies": { "@vue/cli-plugin-babel": "^3.0.1", "@vue/cli-service": "^3.0.1", - "vue-template-compiler": "^2.5.21" + "postcss-nested": "^4.1.1", + "vue-template-compiler": "^2.5.0" } } diff --git a/postcss.config.js b/postcss.config.js index 961986e..de25dfe 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,5 +1,6 @@ module.exports = { plugins: { - autoprefixer: {} + 'autoprefixer': {}, + 'postcss-nested': {} } } diff --git a/public/index.html b/public/index.html index 818df17..cd4e624 100644 --- a/public/index.html +++ b/public/index.html @@ -4,6 +4,7 @@ + vlm diff --git a/src/App.vue b/src/App.vue index fcc5662..9089328 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,28 +1,91 @@ - + diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue deleted file mode 100644 index 7fd2dc5..0000000 --- a/src/components/HelloWorld.vue +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - diff --git a/src/components/dialog.vue b/src/components/dialog.vue new file mode 100644 index 0000000..d552a49 --- /dev/null +++ b/src/components/dialog.vue @@ -0,0 +1,46 @@ + + + + + + + diff --git a/src/components/modal-layout.vue b/src/components/modal-layout.vue new file mode 100644 index 0000000..f068db8 --- /dev/null +++ b/src/components/modal-layout.vue @@ -0,0 +1,184 @@ + + + + + diff --git a/src/components/modal-stack.vue b/src/components/modal-stack.vue new file mode 100644 index 0000000..1215fb3 --- /dev/null +++ b/src/components/modal-stack.vue @@ -0,0 +1,178 @@ + + + + + diff --git a/src/last-modal.js b/src/last-modal.js new file mode 100644 index 0000000..44ffe29 --- /dev/null +++ b/src/last-modal.js @@ -0,0 +1,98 @@ +import Dialog from "./components/dialog.vue" +import ModalLayout from "./components/modal-layout.vue" +import ModalStack from "./components/modal-stack.vue" + +const defaultConfig = { + cancelLabel: 'Cancel', + confirmLabel: 'OK', + buttonClassName: 'btn btn-secondary', + primaryButtonClassName: 'btn btn-primary' +} + +const LastModal = { + install(Vue, config = {}) { + let sequence = 0 + + config = Object.assign({}, defaultConfig, config) + + Vue.component(ModalStack.name, ModalStack) + Vue.component(ModalLayout.name, ModalLayout) + + Vue.prototype.$modal = function(component, props = {}, inline = false) { + return new Promise(resolve => { + this.$root.$emit("lastModal.open", { + id: ++sequence, + component, + props, + resolve, + inline + }) + }); + }; + + Vue.prototype.$dialog = function({title, message, buttons}) { + return this.$modal(Dialog, { + title, message, buttons + }) + } + + Vue.prototype.$alert = function(options) { + if (typeof options === 'string') { + options = { + message: options + } + } + + return this.$dialog({ + title: options.title, + message: options.message, + buttons: [ + { + className: config.buttonClassName, + label: options.confirmLabel || config.confirmLabel + } + ] + }) + } + + Vue.prototype.$confirm = function(options) { + if (typeof options === 'string') { + options = { + message: options + } + } + + return this.$dialog({ + title: options.title, + message: options.message, + buttons: [ + { + className: config.buttonClassName, + label: options.cancelLabel || config.cancelLabel, + value: false + }, + { + className: config.primaryButtonClassName, + label: options.confirmLabel || config.confirmLabel, + value: true + } + ] + }) + } + } +}; + +// Auto-install when vue is found (eg. in browser via