UNPKG

vue-integer-plusminus

Version:

Integer input with increment and decrement buttons for vue 3

736 lines (653 loc) 25 kB
/******/ (function() { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 332: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(601); /* harmony import */ var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(314); /* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__); // Imports var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()((_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default())); // Module ___CSS_LOADER_EXPORT___.push([module.id, ":root{--ipm-border-color:#ccc;--ipm-background-color:transparent;--ipm-btn-color:inherit;--ipm-btn-background-color:#ddd;--ipm-btn-background-color-hover:#ccc;--ipm-btn-background-color-disabled:#eee;--ipm-btn-color-disabled:#777}.int-pm{display:flex;text-align:center}.int-pm .int-pm-value{border-width:1px 0;border-color:var(--ipm-border-color);border-style:solid;padding:0 10px;background-color:var(--ipm-background-color)}.int-pm .int-pm-btn{border:1px solid var(--ipm-border-color);background-color:var(--ipm-btn-background-color);cursor:pointer;padding:5px 10px;color:var(--ipm-btn-color)}.int-pm .int-pm-btn:hover{background-color:var(--ipm-btn-background-color-hover)}.int-pm .int-pm-btn.disabled{color:var(--ipm-btn-background-disabled);cursor:not-allowed}.int-pm .int-pm-btn.disabled,.int-pm .int-pm-btn.disabled:hover{background-color:var(--ipm-btn-background-color-disabled)}.int-pm.int-pm-vertical{flex-direction:column}.int-pm.int-pm-vertical .int-pm-value{border-width:0 1px;padding:5px 10px}", ""]); // Exports /* harmony default export */ __webpack_exports__["default"] = (___CSS_LOADER_EXPORT___); /***/ }), /***/ 314: /***/ (function(module) { "use strict"; /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ module.exports = function (cssWithMappingToString) { var list = []; // return the list of modules as css string list.toString = function toString() { return this.map(function (item) { var content = ""; var needLayer = typeof item[5] !== "undefined"; if (item[4]) { content += "@supports (".concat(item[4], ") {"); } if (item[2]) { content += "@media ".concat(item[2], " {"); } if (needLayer) { content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {"); } content += cssWithMappingToString(item); if (needLayer) { content += "}"; } if (item[2]) { content += "}"; } if (item[4]) { content += "}"; } return content; }).join(""); }; // import a list of modules into the list list.i = function i(modules, media, dedupe, supports, layer) { if (typeof modules === "string") { modules = [[null, modules, undefined]]; } var alreadyImportedModules = {}; if (dedupe) { for (var k = 0; k < this.length; k++) { var id = this[k][0]; if (id != null) { alreadyImportedModules[id] = true; } } } for (var _k = 0; _k < modules.length; _k++) { var item = [].concat(modules[_k]); if (dedupe && alreadyImportedModules[item[0]]) { continue; } if (typeof layer !== "undefined") { if (typeof item[5] === "undefined") { item[5] = layer; } else { item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}"); item[5] = layer; } } if (media) { if (!item[2]) { item[2] = media; } else { item[1] = "@media ".concat(item[2], " {").concat(item[1], "}"); item[2] = media; } } if (supports) { if (!item[4]) { item[4] = "".concat(supports); } else { item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}"); item[4] = supports; } } list.push(item); } }; return list; }; /***/ }), /***/ 601: /***/ (function(module) { "use strict"; module.exports = function (i) { return i[1]; }; /***/ }), /***/ 444: /***/ (function(module, __unused_webpack_exports, __webpack_require__) { // style-loader: Adds some css to the DOM by adding a <style> tag // load the styles var content = __webpack_require__(332); if(content.__esModule) content = content.default; if(typeof content === 'string') content = [[module.id, content, '']]; if(content.locals) module.exports = content.locals; // add the styles to the DOM var add = (__webpack_require__(548)/* ["default"] */ .A) var update = add("62acad38", content, true, {"sourceMap":false,"shadowMode":false}); /***/ }), /***/ 548: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; // EXPORTS __webpack_require__.d(__webpack_exports__, { A: function() { return /* binding */ addStylesClient; } }); ;// ./node_modules/vue-style-loader/lib/listToStyles.js /** * Translates the list format produced by css-loader into something * easier to manipulate. */ function listToStyles (parentId, list) { var styles = [] var newStyles = {} for (var i = 0; i < list.length; i++) { var item = list[i] var id = item[0] var css = item[1] var media = item[2] var sourceMap = item[3] var part = { id: parentId + ':' + i, css: css, media: media, sourceMap: sourceMap } if (!newStyles[id]) { styles.push(newStyles[id] = { id: id, parts: [part] }) } else { newStyles[id].parts.push(part) } } return styles } ;// ./node_modules/vue-style-loader/lib/addStylesClient.js /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra Modified by Evan You @yyx990803 */ var hasDocument = typeof document !== 'undefined' if (typeof DEBUG !== 'undefined' && DEBUG) { if (!hasDocument) { throw new Error( 'vue-style-loader cannot be used in a non-browser environment. ' + "Use { target: 'node' } in your Webpack config to indicate a server-rendering environment." ) } } /* type StyleObject = { id: number; parts: Array<StyleObjectPart> } type StyleObjectPart = { css: string; media: string; sourceMap: ?string } */ var stylesInDom = {/* [id: number]: { id: number, refs: number, parts: Array<(obj?: StyleObjectPart) => void> } */} var head = hasDocument && (document.head || document.getElementsByTagName('head')[0]) var singletonElement = null var singletonCounter = 0 var isProduction = false var noop = function () {} var options = null var ssrIdKey = 'data-vue-ssr-id' // Force single-tag solution on IE6-9, which has a hard limit on the # of <style> // tags it will allow on a page var isOldIE = typeof navigator !== 'undefined' && /msie [6-9]\b/.test(navigator.userAgent.toLowerCase()) function addStylesClient (parentId, list, _isProduction, _options) { isProduction = _isProduction options = _options || {} var styles = listToStyles(parentId, list) addStylesToDom(styles) return function update (newList) { var mayRemove = [] for (var i = 0; i < styles.length; i++) { var item = styles[i] var domStyle = stylesInDom[item.id] domStyle.refs-- mayRemove.push(domStyle) } if (newList) { styles = listToStyles(parentId, newList) addStylesToDom(styles) } else { styles = [] } for (var i = 0; i < mayRemove.length; i++) { var domStyle = mayRemove[i] if (domStyle.refs === 0) { for (var j = 0; j < domStyle.parts.length; j++) { domStyle.parts[j]() } delete stylesInDom[domStyle.id] } } } } function addStylesToDom (styles /* Array<StyleObject> */) { for (var i = 0; i < styles.length; i++) { var item = styles[i] var domStyle = stylesInDom[item.id] if (domStyle) { domStyle.refs++ for (var j = 0; j < domStyle.parts.length; j++) { domStyle.parts[j](item.parts[j]) } for (; j < item.parts.length; j++) { domStyle.parts.push(addStyle(item.parts[j])) } if (domStyle.parts.length > item.parts.length) { domStyle.parts.length = item.parts.length } } else { var parts = [] for (var j = 0; j < item.parts.length; j++) { parts.push(addStyle(item.parts[j])) } stylesInDom[item.id] = { id: item.id, refs: 1, parts: parts } } } } function createStyleElement () { var styleElement = document.createElement('style') styleElement.type = 'text/css' head.appendChild(styleElement) return styleElement } function addStyle (obj /* StyleObjectPart */) { var update, remove var styleElement = document.querySelector('style[' + ssrIdKey + '~="' + obj.id + '"]') if (styleElement) { if (isProduction) { // has SSR styles and in production mode. // simply do nothing. return noop } else { // has SSR styles but in dev mode. // for some reason Chrome can't handle source map in server-rendered // style tags - source maps in <style> only works if the style tag is // created and inserted dynamically. So we remove the server rendered // styles and inject new ones. styleElement.parentNode.removeChild(styleElement) } } if (isOldIE) { // use singleton mode for IE9. var styleIndex = singletonCounter++ styleElement = singletonElement || (singletonElement = createStyleElement()) update = applyToSingletonTag.bind(null, styleElement, styleIndex, false) remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true) } else { // use multi-style-tag mode in all other cases styleElement = createStyleElement() update = applyToTag.bind(null, styleElement) remove = function () { styleElement.parentNode.removeChild(styleElement) } } update(obj) return function updateStyle (newObj /* StyleObjectPart */) { if (newObj) { if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap) { return } update(obj = newObj) } else { remove() } } } var replaceText = (function () { var textStore = [] return function (index, replacement) { textStore[index] = replacement return textStore.filter(Boolean).join('\n') } })() function applyToSingletonTag (styleElement, index, remove, obj) { var css = remove ? '' : obj.css if (styleElement.styleSheet) { styleElement.styleSheet.cssText = replaceText(index, css) } else { var cssNode = document.createTextNode(css) var childNodes = styleElement.childNodes if (childNodes[index]) styleElement.removeChild(childNodes[index]) if (childNodes.length) { styleElement.insertBefore(cssNode, childNodes[index]) } else { styleElement.appendChild(cssNode) } } } function applyToTag (styleElement, obj) { var css = obj.css var media = obj.media var sourceMap = obj.sourceMap if (media) { styleElement.setAttribute('media', media) } if (options.ssrId) { styleElement.setAttribute(ssrIdKey, obj.id) } if (sourceMap) { // https://developer.chrome.com/devtools/docs/javascript-debugging // this makes source maps inside style tags work properly in Chrome css += '\n/*# sourceURL=' + sourceMap.sources[0] + ' */' // http://stackoverflow.com/a/26603875 css += '\n/*# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + ' */' } if (styleElement.styleSheet) { styleElement.styleSheet.cssText = css } else { while (styleElement.firstChild) { styleElement.removeChild(styleElement.firstChild) } styleElement.appendChild(document.createTextNode(css)) } } /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ id: moduleId, /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ !function() { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function() { return module['default']; } : /******/ function() { return module; }; /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ !function() { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = function(exports, definition) { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ !function() { /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } /******/ }(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ !function() { /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/publicPath */ /******/ !function() { /******/ __webpack_require__.p = ""; /******/ }(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. !function() { "use strict"; // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // EXPORTS __webpack_require__.d(__webpack_exports__, { IntegerPlusminus: function() { return /* reexport */ IntegerPlusminus; }, "default": function() { return /* binding */ entry_lib; }, install: function() { return /* reexport */ install; } }); ;// ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js /* eslint-disable no-var */ // This file is imported into lib/wc client bundles. if (typeof window !== 'undefined') { var currentScript = window.document.currentScript if (false) { var getCurrentScript; } var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/) if (src) { __webpack_require__.p = src[1] // eslint-disable-line } } // Indicate to webpack that this file can be concatenated /* harmony default export */ var setPublicPath = (null); ;// external {"commonjs":"vue","commonjs2":"vue","root":"Vue"} var external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject = require("vue"); ;// ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/IntegerPlusminus.vue?vue&type=script&setup=true&lang=js const _hoisted_1 = ["aria-label", "disabled"]; const _hoisted_2 = ["aria-valuenow", "aria-valuemin", "aria-valuemax", "aria-label"]; const _hoisted_3 = ["name", "value"]; const _hoisted_4 = ["aria-label", "disabled"]; /* harmony default export */ var IntegerPlusminusvue_type_script_setup_true_lang_js = ({ __name: 'IntegerPlusminus', props: { modelValue: Number, initialValue: { type: Number, default: 0 }, min: { type: Number, default: 0 }, max: { type: Number, default: undefined }, step: { type: Number, default: 1 }, vertical: { type: Boolean, default: false }, incrementAriaLabel: { type: String, default: undefined }, decrementAriaLabel: { type: String, default: undefined }, spinButtonAriaLabel: { type: String, default: undefined }, formName: { type: String, default: 'integerPlusMinus' }, disabled: { type: Boolean, default: false } }, emits: ['update:modelValue', 'ipm-input', 'ipm-increment', 'ipm-decrement'], setup(__props, { emit: __emit }) { const props = __props; const intValue = (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.ref)(0); const spinButton = (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.ref)(null); const emit = __emit; // computed const canIncrement = (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.computed)(() => { if (props.disabled) return false; return props.max === undefined || intValue.value + props.step <= props.max; }); const canDecrement = (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.computed)(() => { if (props.disabled) return false; return intValue.value - props.step >= props.min; }); (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.onMounted)(() => { window.addEventListener('keydown', keyUp); if (props.modelValue === undefined) { intValue.value = props.initialValue; } else { intValue.value = props.modelValue; } }); (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.watch)(() => props.modelValue, (newValue, oldValue) => { if (newValue !== intValue.value) intValue.value = newValue; }); // methods const inputChange = () => { if (props.modelValue !== undefined) { emit('update:modelValue', intValue.value); emit('ipm-input', intValue.value); } }; const isSpinButtonFocused = () => { return document.activeElement === spinButton.value; }; const setToMin = () => { if (props.disabled) return; intValue.value = props.min; inputChange(); }; const setToMax = () => { if (props.disabled) return; intValue.value = props.max; inputChange(); }; const increment = () => { if (canIncrement.value) { intValue.value = intValue.value + props.step; emit('ipm-increment', intValue.value); inputChange(); } }; const decrement = () => { if (canDecrement.value) { intValue.value = intValue.value - props.step; emit('ipm-decrement', intValue.value); inputChange(); } }; const keyUp = event => { if (isSpinButtonFocused()) { if (event.keyCode === 33 || event.keyCode === 38) { // page up || up arrow increment(); event.preventDefault(); } if (event.keyCode === 34 || event.keyCode === 40) { // page down || down arrow decrement(); event.preventDefault(); } if (event.keyCode === 36) { // home button setToMin(); event.preventDefault(); } // if max, set to max if (props.max !== undefined && event.keyCode === 35) { // end button setToMax(); event.preventDefault(); } } }; const getBtnClass = isFirstBtn => { let btnClass = 'int-pm-'; if (isFirstBtn && !props.vertical || !isFirstBtn && props.vertical) { btnClass += 'decrement'; if (!canDecrement.value) btnClass += ' disabled'; } else { btnClass += 'increment'; if (!canIncrement.value) btnClass += ' disabled'; } return btnClass; }; return (_ctx, _cache) => { return (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock)(), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementBlock)("div", { class: (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.normalizeClass)(["int-pm", { 'int-pm-vertical': __props.vertical }]) }, [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("button", { class: (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.normalizeClass)(["int-pm-btn", getBtnClass(true)]), onClick: _cache[0] || (_cache[0] = $event => __props.vertical ? increment() : decrement()), "aria-label": __props.decrementAriaLabel, disabled: __props.disabled }, [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.renderSlot)(_ctx.$slots, __props.vertical ? 'increment' : 'decrement', {}, () => [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createTextVNode)((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.toDisplayString)(__props.vertical ? '+' : '-'), 1)])], 10, _hoisted_1), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("div", { class: "int-pm-value", ref_key: "spinButton", ref: spinButton, role: "spinbutton", tabindex: "0", "aria-valuenow": intValue.value, "aria-valuemin": __props.min, "aria-valuemax": __props.max, "aria-label": __props.spinButtonAriaLabel }, [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.renderSlot)(_ctx.$slots, "default", {}, () => [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createTextVNode)((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.toDisplayString)(intValue.value), 1)])], 8, _hoisted_2), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("input", { type: "hidden", name: __props.formName, value: intValue.value }, null, 8, _hoisted_3), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("button", { class: (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.normalizeClass)(["int-pm-btn", getBtnClass(false)]), onClick: _cache[1] || (_cache[1] = $event => __props.vertical ? decrement() : increment()), "aria-label": __props.incrementAriaLabel, disabled: __props.disabled }, [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.renderSlot)(_ctx.$slots, __props.vertical ? 'decrement' : 'increment', {}, () => [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createTextVNode)((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.toDisplayString)(__props.vertical ? '-' : '+'), 1)])], 10, _hoisted_4)], 2); }; } }); ;// ./src/components/IntegerPlusminus.vue?vue&type=script&setup=true&lang=js ;// ./src/components/IntegerPlusminus.vue const __exports__ = IntegerPlusminusvue_type_script_setup_true_lang_js; /* harmony default export */ var IntegerPlusminus = (__exports__); // EXTERNAL MODULE: ./src/styles/common.scss var common = __webpack_require__(444); ;// ./src/index.js // Component imports // Default export for global usage const install = app => { app.component('integer-plusminus', IntegerPlusminus); }; /* harmony default export */ var src_0 = (install); // Named export for specific usage ;// ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js /* harmony default export */ var entry_lib = (src_0); }(); module.exports = __webpack_exports__; /******/ })() ;