UNPKG

ten-design-vue

Version:

ten-vue

753 lines (670 loc) 22.6 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 = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 4); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { module.exports = require("./util"); /***/ }), /* 1 */ /***/ (function(module, exports) { module.exports = require("./mention-option"); /***/ }), /* 2 */ /***/ (function(module, exports) { module.exports = require("../popup"); /***/ }), /* 3 */ /***/ (function(module, exports) { module.exports = require("../loading"); /***/ }), /* 4 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./src/components/mention/mention.vue?vue&type=template&id=4269193a& var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"ten-mention"},[_c('div',{ref:"spy",staticClass:"ten-mention__spy"},[_c('span',[_vm._v(_vm._s(_vm.value.slice(0, _vm.matchLocation)))]),_c('ten-popup',{attrs:{"trigger-type":"manual","show":_vm.showPop,"direction":_vm.direction,"popup-class":_vm.popupClass,"offset":_vm.offset},scopedSlots:_vm._u([{key:"default",fn:function(){return [_c('div',{ref:"popup",staticClass:"ten-mention__popup-content"},[_vm._t("default",function(){return [(_vm.dataSource.length > 0)?_vm._l((_vm.options),function(option){return _c('ten-mention-option',{key:option._value,attrs:{"value":option._value}},[_vm._v("\n "+_vm._s(option._label)+"\n ")])}):_vm._e()]}),(!_vm.loading && _vm.isEmpty)?_c('div',{staticClass:"ten-mention__empty"},[_vm._t("emptyTip",function(){return [_vm._v("\n "+_vm._s(_vm.emptyTip)+"\n ")]})],2):_vm._e(),(_vm.loading)?_c('div',{staticClass:"ten-mention__loading"},[_c('ten-loading',{attrs:{"type":"block"}})],1):_vm._e()],2)]},proxy:true},{key:"trigger",fn:function(){return [_c('span',[_vm._v(_vm._s(_vm.matchPrefix))])]},proxy:true}],null,true)}),_vm._v("\n "+_vm._s(_vm.value.slice(_vm.matchLocation + _vm.matchPrefix.length))+"\n ")],1),_c('ten-input-textarea',_vm._g(_vm._b({ref:"inputTextarea",staticClass:"ten-mention__textarea",attrs:{"value":_vm.value,"rows":_vm.rows},on:{"keydown":_vm.onKeyDown,"keyup":_vm.onKeyUp,"input":_vm.onInput,"blur":_vm.onBlur}},'ten-input-textarea',_vm.$attrs,false),_vm.textareaListeners))],1)} var staticRenderFns = [] // CONCATENATED MODULE: ./src/components/mention/mention.vue?vue&type=template&id=4269193a& // EXTERNAL MODULE: external "./mention-option" var external_mention_option_ = __webpack_require__(1); var external_mention_option_default = /*#__PURE__*/__webpack_require__.n(external_mention_option_); // EXTERNAL MODULE: external "../popup" var external_popup_ = __webpack_require__(2); var external_popup_default = /*#__PURE__*/__webpack_require__.n(external_popup_); // EXTERNAL MODULE: external "../loading" var external_loading_ = __webpack_require__(3); var external_loading_default = /*#__PURE__*/__webpack_require__.n(external_loading_); // EXTERNAL MODULE: external "./util" var external_util_ = __webpack_require__(0); // CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--1!./node_modules/vue-loader/lib??vue-loader-options!./src/components/mention/mention.vue?vue&type=script&lang=js& function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // var ENTER = external_util_["KEY_CODE"].ENTER, UP = external_util_["KEY_CODE"].UP, DOWN = external_util_["KEY_CODE"].DOWN, ESC = external_util_["KEY_CODE"].ESC; var mentionvue_type_script_lang_js_name = 'ten-mention'; /* harmony default export */ var mentionvue_type_script_lang_js_ = ({ name: mentionvue_type_script_lang_js_name, provide: function provide() { return { mention: this }; }, inject: { formItem: { from: 'tenFormItem', default: null } }, components: { TenMentionOption: external_mention_option_default.a, TenPopup: external_popup_default.a, TenLoading: external_loading_default.a }, props: { /** * @model * value 值 */ value: { type: String, default: '' }, /** * 默认值 */ defaultValue: { type: String, default: '' }, /** * 选项数据源 * 支持{label, value}对象数组, 也支持字符串数组 */ dataSource: { type: Array, default: function _default() { return []; } }, /** * 选项为对象时,指定选项的value在data中的键值。 * 设置为函数时,参数为data,函数返回值将指定为value。 * 设置value-type="data"或者使用data-source可能需要设置。 */ optionValue: { type: [String, Function], default: 'value' }, /** * 选项为对象时,指定选项的label在data中的键值。 * 可设置为函数时,参数为data,函数返回值将指定为label。 * 设置value-type="data"或者使用data-source可能需要设置。 */ optionLabel: { type: [String, Function], default: 'label' }, /** * 设置为 true 则根据 optionLabel 的值自动筛选 * 设置为 false 不作过滤操作 * 可以是函数,自定义筛选规则 * (text, value) => {} */ filterOption: { type: [Boolean, Function], default: function _default() { return external_util_["filterOption"]; } }, /** * 当下拉列表结果为空时显示的内容 */ emptyTip: { type: String, default: '暂无数据' }, /** * 弹窗方向 */ direction: { type: String, default: 'bottom left' }, /** * 设置触发关键字 */ prefix: { type: [String, Array], default: '@' }, /** * 设置选中项前后分隔符 */ split: { type: String, default: ' ' }, /** * 自定义触发验证逻辑 */ validateSearch: { type: Function, default: external_util_["validateSearch"] }, /** * 是否加载中,异步获取选项时适用 */ loading: { type: Boolean, default: false }, /** * 文本域行数 */ rows: { type: [Number, String], default: 1 } }, data: function data() { return { matchText: '', matchPrefix: '', matchLocation: '', focusIndex: 0, showPop: false, isEmpty: false, options: [], offset: { x: 0, y: 0 } }; }, computed: { popupClass: function popupClass() { return ['ten-mention__popup', 'ten-mention-options', { 'ten-mention__popup--loading': this.loading }]; }, textareaListeners: function textareaListeners() { var listener = _objectSpread({}, this.$listeners); delete listener.input; return listener; } }, watch: { matchText: { handler: function handler() { var _this = this; this.$nextTick(function () { _this.isEmpty = _this.getVisibleOptions().length === 0; }); }, immediate: true }, matchPrefix: function matchPrefix() { var _this2 = this; this.$nextTick(function () { _this2.isEmpty = _this2.getVisibleOptions().length === 0; }); }, dataSource: { handler: function handler(newDataSource) { var _this3 = this; this.options = newDataSource.map(function (data) { return _this3.createOptionObj(data); }); }, immediate: true, deep: true } }, mounted: function mounted() { this.$on('option:click', this.onOptionClick); this.$on('option:focus', this.onOptionFocus); this.$on('option:update', this.onOptionUpdateFromSlot); }, methods: { getVisibleOptions: function getVisibleOptions() { return this.$refs.popup ? Array.from(this.$refs.popup.querySelectorAll('div[class*="ten-mention-option--visible"]')) : []; }, createOptionObj: function createOptionObj(option) { if (option !== null && _typeof(option) === 'object') { var _value = typeof this.optionValue === 'function' ? this.optionValue(option) : option[this.optionValue]; var _label = typeof this.optionLabel === 'function' ? this.optionLabel(option) : option[this.optionLabel]; return { _value: _value, _label: _label }; } return { _value: option, _label: String(option) }; }, onKeyDown: function onKeyDown(e) { var showPop = this.showPop, focusIndex = this.focusIndex; var visibleOptions = this.getVisibleOptions(); var total = visibleOptions.length; if (showPop) { var keyCode = e.keyCode; switch (keyCode) { case ENTER: // enter if (focusIndex < total) { visibleOptions[focusIndex].click(); } e.preventDefault(); break; case UP: // up this.focusIndex = focusIndex === 0 ? total - 1 : focusIndex - 1; e.preventDefault(); break; case DOWN: // down this.focusIndex = focusIndex === total - 1 ? 0 : focusIndex + 1; e.preventDefault(); break; case ESC: // esc this.stopMatch(); break; default: break; } } }, onKeyUp: function onKeyUp(e) { var keyCode = e.keyCode, key = e.key; if ([ENTER, UP, DOWN, ESC].includes(keyCode)) return; var prevMeasureText = this.matchText; var input = e.target; var beforeSelectionText = Object(external_util_["getBeforeSelectionText"])(input); var _getLastMeasureIndex = Object(external_util_["getLastMeasureIndex"])(beforeSelectionText, this.prefix), location = _getLastMeasureIndex.location, prefix = _getLastMeasureIndex.prefix; if (location !== -1) { var matchText = beforeSelectionText.slice(location + prefix.length); var validateMatch = this.validateSearch(matchText, this.$props); if (validateMatch) { if (key === prefix || matchText === '' || matchText !== prevMeasureText) { this.startMatch(matchText, prefix, location); } /** * 搜索时触发 * * @event search * @param {String} text * @param {String} prefix */ this.$emit('search', matchText, prefix); } else { this.stopMatch(); } } else if (this.showPop) { this.stopMatch(); } }, startMatch: function startMatch(matchText, prefix, location) { var _this4 = this; this.$nextTick(function () { var input = _this4.$refs.inputTextarea.getInputElement(); _this4.$refs.spy.scrollTop = input.scrollTop; _this4.focusIndex = 0; _this4.matchPrefix = prefix; _this4.matchText = matchText; _this4.matchLocation = location; _this4.showPop = true; }); }, stopMatch: function stopMatch() { this.matchText = ''; this.matchPrefix = ''; this.matchLocation = 0; this.focusIndex = 0; this.showPop = false; }, onOptionFocus: function onOptionFocus(focusOption) { this.focusIndex = focusOption.index; }, onOptionClick: function onOptionClick(selectOption) { var _this5 = this; var value = this.value, location = this.matchLocation, prefix = this.matchPrefix, split = this.split; var targetText = selectOption.value; var input = this.$refs.inputTextarea.getInputElement(); var selectionStart = input.selectionStart; var _replaceWithMeasure = Object(external_util_["replaceWithMeasure"])(value, { location: location, targetText: targetText, prefix: prefix, selectionStart: selectionStart, split: split }), text = _replaceWithMeasure.text, selectionLocation = _replaceWithMeasure.selectionLocation; this.stopMatch(); /** * @ignore */ this.$emit('input', text); /** * 选项选中时触发 * * @event select * @param {Object} OptionProps * @param {String} prefix */ this.$emit('select', selectOption.$props, prefix); this.$nextTick(function () { Object(external_util_["setInputSelection"])(input, selectionLocation); _this5.formItem && _this5.formItem.$emit('form.change'); }); }, onOptionUpdateFromSlot: function onOptionUpdateFromSlot() { // 全量获取用户的slot,确保更新的值和顺序 if (this.$scopedSlots.default) { this.options = this.$scopedSlots.default().map(function (vnode) { if (vnode && vnode.componentInstance && vnode.componentInstance.optionObj) { return _extends({}, vnode.componentInstance.optionObj); } return undefined; }).filter(function (v) { return v; }); } }, onInput: function onInput(v) { this.$emit('input', v); }, onBlur: function onBlur() { this.stopMatch(); this.formItem && this.formItem.$emit('form.blur'); }, focus: function focus() { this.$refs.inputTextarea && this.$refs.inputTextarea.focus(); }, blur: function blur() { this.$refs.inputTextarea && this.$refs.inputTextarea.blur(); } } }); // CONCATENATED MODULE: ./src/components/mention/mention.vue?vue&type=script&lang=js& /* harmony default export */ var mention_mentionvue_type_script_lang_js_ = (mentionvue_type_script_lang_js_); // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js /* 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 } } // CONCATENATED MODULE: ./src/components/mention/mention.vue /* normalize component */ var component = normalizeComponent( mention_mentionvue_type_script_lang_js_, render, staticRenderFns, false, null, null, null ) /* harmony default export */ var mention = __webpack_exports__["default"] = (component.exports); /***/ }) /******/ ]);