UNPKG

element-nice-ui

Version:

A Component Library for Vue.js.

641 lines (590 loc) 19 kB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // 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 }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/dist/"; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 237); /******/ }) /************************************************************************/ /******/ ({ /***/ 2: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; }); /* globals __VUE_SSR_CONTEXT__ */ // IMPORTANT: Do NOT use ES2015 features in this file (except for modules). // This module is a runtime utility for cleaner component module output and will // be included in the final webpack user bundle. function normalizeComponent( scriptExports, render, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier /* server only */, shadowMode /* vue-cli only */ ) { // Vue.extend constructor export interop var options = typeof scriptExports === 'function' ? scriptExports.options : scriptExports // render functions if (render) { options.render = render options.staticRenderFns = staticRenderFns options._compiled = true } // functional template if (functionalTemplate) { options.functional = true } // scopedId if (scopeId) { options._scopeId = 'data-v-' + scopeId } var hook if (moduleIdentifier) { // server build hook = function (context) { // 2.3 injection context = context || // cached call (this.$vnode && this.$vnode.ssrContext) || // stateful (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional // 2.2 with runInNewContext: true if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { context = __VUE_SSR_CONTEXT__ } // inject component styles if (injectStyles) { injectStyles.call(this, context) } // register component module identifier for async chunk inferrence if (context && context._registeredComponents) { context._registeredComponents.add(moduleIdentifier) } } // used by ssr in case component is cached and beforeCreate // never gets called options._ssrRegister = hook } else if (injectStyles) { hook = shadowMode ? function () { injectStyles.call( this, (options.functional ? this.parent : this).$root.$options.shadowRoot ) } : injectStyles } if (hook) { if (options.functional) { // for template-only hot-reload because in that case the render fn doesn't // go through the normalizer options._injectStyles = hook // register for functional component in vue file var originalRender = options.render options.render = function renderWithStyleInjection(h, context) { hook.call(context) return originalRender(h, context) } } else { // inject component registration as beforeCreate hook var existing = options.beforeCreate options.beforeCreate = existing ? [].concat(existing, hook) : [hook] } } return { exports: scriptExports, options: options } } /***/ }), /***/ 237: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // CONCATENATED MODULE: ./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib/loaders/templateLoader.js??ref--5!./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib??vue-loader-options!./packages/rate/src/main.vue?vue&type=template&id=2d86d7d4 var render = function render() { var _vm = this, _c = _vm._self._c return _c( "div", { staticClass: "el-rate", attrs: { role: "slider", "aria-valuenow": _vm.currentValue, "aria-valuetext": _vm.text, "aria-valuemin": "0", "aria-valuemax": _vm.max, tabindex: "0", }, on: { keydown: _vm.handleKey }, }, [ _vm._l(_vm.max, function (item, key) { return _c( "span", { key: key, staticClass: "el-rate__item", style: { cursor: _vm.rateDisabled ? "auto" : "pointer" }, on: { mousemove: function ($event) { return _vm.setCurrentValue(item, $event) }, mouseleave: _vm.resetCurrentValue, click: function ($event) { return _vm.selectValue(item) }, }, }, [ _c( "i", { staticClass: "el-rate__icon", class: [ _vm.classes[item - 1], { hover: _vm.hoverIndex === item }, ], style: _vm.getIconStyle(item), }, [ _vm.showDecimalIcon(item) ? _c("i", { staticClass: "el-rate__decimal", class: _vm.decimalIconClass, style: _vm.decimalStyle, }) : _vm._e(), ] ), ] ) }), _vm.showText || _vm.showScore ? _c( "span", { staticClass: "el-rate__text", style: { color: _vm.textColor } }, [_vm._v(_vm._s(_vm.text))] ) : _vm._e(), ], 2 ) } var staticRenderFns = [] render._withStripped = true // CONCATENATED MODULE: ./packages/rate/src/main.vue?vue&type=template&id=2d86d7d4 // EXTERNAL MODULE: external "element-nice-ui/lib/utils/dom" var dom_ = __webpack_require__(8); // EXTERNAL MODULE: external "element-nice-ui/lib/utils/types" var types_ = __webpack_require__(41); // EXTERNAL MODULE: external "element-nice-ui/lib/mixins/migrating" var migrating_ = __webpack_require__(25); var migrating_default = /*#__PURE__*/__webpack_require__.n(migrating_); // EXTERNAL MODULE: external "element-nice-ui/lib/utils/util" var util_ = __webpack_require__(5); // CONCATENATED MODULE: ./node_modules/.pnpm/babel-loader@8.4.1_@babel+core@7.28.0_webpack@4.47.0/node_modules/babel-loader/lib!./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib??vue-loader-options!./packages/rate/src/main.vue?vue&type=script&lang=js /* harmony default export */ var mainvue_type_script_lang_js = ({ name: 'ElRate', mixins: [migrating_default.a], inject: { elForm: { default: '' } }, data() { return { pointerAtLeftHalf: true, currentValue: this.value, hoverIndex: -1 }; }, props: { value: { type: Number, default: 0 }, lowThreshold: { type: Number, default: 2 }, highThreshold: { type: Number, default: 4 }, max: { type: Number, default: 5 }, colors: { type: [Array, Object], default() { return ['#F7BA2A', '#F7BA2A', '#F7BA2A']; } }, voidColor: { type: String, default: '#C6D1DE' }, disabledVoidColor: { type: String, default: '#EFF2F7' }, iconClasses: { type: [Array, Object], default() { return ['el-icon-star-on', 'el-icon-star-on', 'el-icon-star-on']; } }, voidIconClass: { type: String, default: 'el-icon-star-off' }, disabledVoidIconClass: { type: String, default: 'el-icon-star-on' }, disabled: { type: Boolean, default: undefined }, allowHalf: { type: Boolean, default: false }, showText: { type: Boolean, default: false }, showScore: { type: Boolean, default: false }, textColor: { type: String, default: '#1f2d3d' }, texts: { type: Array, default() { return ['极差', '失望', '一般', '满意', '惊喜']; } }, scoreTemplate: { type: String, default: '{value}' } }, computed: { text() { let result = ''; if (this.showScore) { result = this.scoreTemplate.replace(/\{\s*value\s*\}/, this.rateDisabled ? this.value : this.currentValue); } else if (this.showText) { result = this.texts[Math.ceil(this.currentValue) - 1]; } return result; }, decimalStyle() { let width = ''; if (this.rateDisabled) { width = "".concat(this.valueDecimal, "%"); } else if (this.allowHalf) { width = '50%'; } return { color: this.activeColor, width }; }, valueDecimal() { return this.value * 100 - Math.floor(this.value) * 100; }, classMap() { return Array.isArray(this.iconClasses) ? { [this.lowThreshold]: this.iconClasses[0], [this.highThreshold]: { value: this.iconClasses[1], excluded: true }, [this.max]: this.iconClasses[2] } : this.iconClasses; }, decimalIconClass() { return this.getValueFromMap(this.value, this.classMap); }, voidClass() { return this.rateDisabled ? this.disabledVoidIconClass : this.voidIconClass; }, activeClass() { return this.getValueFromMap(this.currentValue, this.classMap); }, colorMap() { return Array.isArray(this.colors) ? { [this.lowThreshold]: this.colors[0], [this.highThreshold]: { value: this.colors[1], excluded: true }, [this.max]: this.colors[2] } : this.colors; }, activeColor() { return this.getValueFromMap(this.currentValue, this.colorMap); }, classes() { let result = []; let i = 0; let threshold = this.currentValue; if (this.allowHalf && this.currentValue !== Math.floor(this.currentValue)) { threshold--; } for (; i < threshold; i++) { result.push(this.activeClass); } for (; i < this.max; i++) { result.push(this.voidClass); } return result; }, rateDisabled() { return Object(util_["getDefined"])(this.disabled, (this.elForm || {}).disabled, false); } }, watch: { value(val) { this.currentValue = val; this.pointerAtLeftHalf = this.value !== Math.floor(this.value); } }, methods: { getMigratingConfig() { return { props: { 'text-template': 'text-template is renamed to score-template.' } }; }, getValueFromMap(value, map) { const matchedKeys = Object.keys(map).filter(key => { const val = map[key]; const excluded = Object(types_["isObject"])(val) ? val.excluded : false; return excluded ? value < key : value <= key; }).sort((a, b) => a - b); const matchedValue = map[matchedKeys[0]]; return Object(types_["isObject"])(matchedValue) ? matchedValue.value : matchedValue || ''; }, showDecimalIcon(item) { let showWhenDisabled = this.rateDisabled && this.valueDecimal > 0 && item - 1 < this.value && item > this.value; /* istanbul ignore next */ let showWhenAllowHalf = this.allowHalf && this.pointerAtLeftHalf && item - 0.5 <= this.currentValue && item > this.currentValue; return showWhenDisabled || showWhenAllowHalf; }, getIconStyle(item) { const voidColor = this.rateDisabled ? this.disabledVoidColor : this.voidColor; return { color: item <= this.currentValue ? this.activeColor : voidColor }; }, selectValue(value) { if (this.rateDisabled) { return; } if (this.allowHalf && this.pointerAtLeftHalf) { this.$emit('input', this.currentValue); this.$emit('change', this.currentValue); } else { this.$emit('input', value); this.$emit('change', value); } }, handleKey(e) { if (this.rateDisabled) { return; } let currentValue = this.currentValue; const keyCode = e.keyCode; if (keyCode === 38 || keyCode === 39) { // left / down if (this.allowHalf) { currentValue += 0.5; } else { currentValue += 1; } e.stopPropagation(); e.preventDefault(); } else if (keyCode === 37 || keyCode === 40) { if (this.allowHalf) { currentValue -= 0.5; } else { currentValue -= 1; } e.stopPropagation(); e.preventDefault(); } currentValue = currentValue < 0 ? 0 : currentValue; currentValue = currentValue > this.max ? this.max : currentValue; this.$emit('input', currentValue); this.$emit('change', currentValue); }, setCurrentValue(value, event) { if (this.rateDisabled) { return; } /* istanbul ignore if */ if (this.allowHalf) { let target = event.target; if (Object(dom_["hasClass"])(target, 'el-rate__item')) { target = target.querySelector('.el-rate__icon'); } if (Object(dom_["hasClass"])(target, 'el-rate__decimal')) { target = target.parentNode; } this.pointerAtLeftHalf = event.offsetX * 2 <= target.clientWidth; this.currentValue = this.pointerAtLeftHalf ? value - 0.5 : value; } else { this.currentValue = value; } this.hoverIndex = value; }, resetCurrentValue() { if (this.rateDisabled) { return; } if (this.allowHalf) { this.pointerAtLeftHalf = this.value !== Math.floor(this.value); } this.currentValue = this.value; this.hoverIndex = -1; } }, created() { if (!this.value) { this.$emit('input', 0); } } }); // CONCATENATED MODULE: ./packages/rate/src/main.vue?vue&type=script&lang=js /* harmony default export */ var src_mainvue_type_script_lang_js = (mainvue_type_script_lang_js); // EXTERNAL MODULE: ./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib/runtime/componentNormalizer.js var componentNormalizer = __webpack_require__(2); // CONCATENATED MODULE: ./packages/rate/src/main.vue /* normalize component */ var component = Object(componentNormalizer["a" /* default */])( src_mainvue_type_script_lang_js, render, staticRenderFns, false, null, null, null ) /* harmony default export */ var main = (component.exports); // CONCATENATED MODULE: ./packages/rate/index.js /* istanbul ignore next */ main.install = function (Vue) { Vue.component(main.name, main); }; /* harmony default export */ var rate = __webpack_exports__["default"] = (main); /***/ }), /***/ 25: /***/ (function(module, exports) { module.exports = require("element-nice-ui/lib/mixins/migrating"); /***/ }), /***/ 41: /***/ (function(module, exports) { module.exports = require("element-nice-ui/lib/utils/types"); /***/ }), /***/ 5: /***/ (function(module, exports) { module.exports = require("element-nice-ui/lib/utils/util"); /***/ }), /***/ 8: /***/ (function(module, exports) { module.exports = require("element-nice-ui/lib/utils/dom"); /***/ }) /******/ });