UNPKG

ex-table-column

Version:

Extended to element table column, supports column width to be automatically adjusted according to content, supports all attributes of el-table-column, compatible el-table-column.

806 lines (697 loc) 21.1 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("element-ui"), require("vue")); else if(typeof define === 'function' && define.amd) define(["element-ui", ], factory); else if(typeof exports === 'object') exports["ex-table-column"] = factory(require("element-ui"), require("vue")); else root["ex-table-column"] = factory(root["element-ui"], root["Vue"]); })((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__5f72__, __WEBPACK_EXTERNAL_MODULE__8bbf__) { return /******/ (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 = "fb15"); /******/ }) /************************************************************************/ /******/ ({ /***/ "5f72": /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE__5f72__; /***/ }), /***/ "8bbf": /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE__8bbf__; /***/ }), /***/ "f6fd": /***/ (function(module, exports) { // document.currentScript polyfill by Adam Miller // MIT license (function(document){ var currentScript = "currentScript", scripts = document.getElementsByTagName('script'); // Live NodeList collection // If browser needs currentScript polyfill, add get currentScript() to the document object if (!(currentScript in document)) { Object.defineProperty(document, currentScript, { get: function(){ // IE 6-10 supports script readyState // IE 10+ support stack trace try { throw new Error(); } catch (err) { // Find the second match for the "at" string to get file src url from stack. // Specifically works with the format of stack traces in IE. var i, res = ((/.*at [^\(]*\((.*):.+:.+\)$/ig).exec(err.stack) || [false])[1]; // For all scripts on the page, if src matches or if ready state is interactive, return the script tag for(i in scripts){ if(scripts[i].src == res || scripts[i].readyState == "interactive"){ return scripts[i]; } } // If no match, return null return null; } } }); } })(document); /***/ }), /***/ "fb15": /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js // This file is imported into lib/wc client bundles. if (typeof window !== 'undefined') { if (true) { __webpack_require__("f6fd") } var i if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) { __webpack_require__.p = i[1] // eslint-disable-line } } // Indicate to webpack that this file can be concatenated /* harmony default export */ var setPublicPath = (null); // EXTERNAL MODULE: external "element-ui" var external_element_ui_ = __webpack_require__("5f72"); // EXTERNAL MODULE: external {"commonjs":"vue","commonjs2":"vue","root":"Vue"} var external_commonjs_vue_commonjs2_vue_root_Vue_ = __webpack_require__("8bbf"); var external_commonjs_vue_commonjs2_vue_root_Vue_default = /*#__PURE__*/__webpack_require__.n(external_commonjs_vue_commonjs2_vue_root_Vue_); // CONCATENATED MODULE: ./node_modules/element-ui/src/utils/types.js function isString(obj) { return Object.prototype.toString.call(obj) === '[object String]'; } function isObject(obj) { return Object.prototype.toString.call(obj) === '[object Object]'; } function isHtmlElement(node) { return node && node.nodeType === Node.ELEMENT_NODE; } const isFunction = (functionToCheck) => { var getType = {}; return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; }; const isUndefined = (val)=> { return val === void 0; }; const isDefined = (val) => { return val !== undefined && val !== null; }; // CONCATENATED MODULE: ./node_modules/element-ui/src/utils/util.js const util_hasOwnProperty = Object.prototype.hasOwnProperty; function noop() {}; function hasOwn(obj, key) { return util_hasOwnProperty.call(obj, key); }; function extend(to, _from) { for (let key in _from) { to[key] = _from[key]; } return to; }; function toObject(arr) { var res = {}; for (let i = 0; i < arr.length; i++) { if (arr[i]) { extend(res, arr[i]); } } return res; }; const getValueByPath = function(object, prop) { prop = prop || ''; const paths = prop.split('.'); let current = object; let result = null; for (let i = 0, j = paths.length; i < j; i++) { const path = paths[i]; if (!current) break; if (i === j - 1) { result = current[path]; break; } current = current[path]; } return result; }; function getPropByPath(obj, path, strict) { let tempObj = obj; path = path.replace(/\[(\w+)\]/g, '.$1'); path = path.replace(/^\./, ''); let keyArr = path.split('.'); let i = 0; for (let len = keyArr.length; i < len - 1; ++i) { if (!tempObj && !strict) break; let key = keyArr[i]; if (key in tempObj) { tempObj = tempObj[key]; } else { if (strict) { throw new Error('please transfer a valid prop path to form item!'); } break; } } return { o: tempObj, k: keyArr[i], v: tempObj ? tempObj[keyArr[i]] : null }; }; const generateId = function() { return Math.floor(Math.random() * 10000); }; const valueEquals = (a, b) => { // see: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript if (a === b) return true; if (!(a instanceof Array)) return false; if (!(b instanceof Array)) return false; if (a.length !== b.length) return false; for (let i = 0; i !== a.length; ++i) { if (a[i] !== b[i]) return false; } return true; }; const escapeRegexpString = (value = '') => String(value).replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); // TODO: use native Array.find, Array.findIndex when IE support is dropped const arrayFindIndex = function(arr, pred) { for (let i = 0; i !== arr.length; ++i) { if (pred(arr[i])) { return i; } } return -1; }; const arrayFind = function(arr, pred) { const idx = arrayFindIndex(arr, pred); return idx !== -1 ? arr[idx] : undefined; }; // coerce truthy value to array const coerceTruthyValueToArray = function(val) { if (Array.isArray(val)) { return val; } else if (val) { return [val]; } else { return []; } }; const isIE = function() { return !external_commonjs_vue_commonjs2_vue_root_Vue_default.a.prototype.$isServer && !isNaN(Number(document.documentMode)); }; const isEdge = function() { return !external_commonjs_vue_commonjs2_vue_root_Vue_default.a.prototype.$isServer && navigator.userAgent.indexOf('Edge') > -1; }; const isFirefox = function() { return !external_commonjs_vue_commonjs2_vue_root_Vue_default.a.prototype.$isServer && !!window.navigator.userAgent.match(/firefox/i); }; const autoprefixer = function(style) { if (typeof style !== 'object') return style; const rules = ['transform', 'transition', 'animation']; const prefixes = ['ms-', 'webkit-']; rules.forEach(rule => { const value = style[rule]; if (rule && value) { prefixes.forEach(prefix => { style[prefix + rule] = value; }); } }); return style; }; const kebabCase = function(str) { const hyphenateRE = /([^-])([A-Z])/g; return str .replace(hyphenateRE, '$1-$2') .replace(hyphenateRE, '$1-$2') .toLowerCase(); }; const capitalize = function(str) { if (!isString(str)) return str; return str.charAt(0).toUpperCase() + str.slice(1); }; const looseEqual = function(a, b) { const isObjectA = isObject(a); const isObjectB = isObject(b); if (isObjectA && isObjectB) { return JSON.stringify(a) === JSON.stringify(b); } else if (!isObjectA && !isObjectB) { return String(a) === String(b); } else { return false; } }; const arrayEquals = function(arrayA, arrayB) { arrayA = arrayA || []; arrayB = arrayB || []; if (arrayA.length !== arrayB.length) { return false; } for (let i = 0; i < arrayA.length; i++) { if (!looseEqual(arrayA[i], arrayB[i])) { return false; } } return true; }; const isEqual = function(value1, value2) { if (Array.isArray(value1) && Array.isArray(value2)) { return arrayEquals(value1, value2); } return looseEqual(value1, value2); }; const isEmpty = function(val) { // null or undefined if (val == null) return true; if (typeof val === 'boolean') return false; if (typeof val === 'number') return !val; if (val instanceof Error) return val.message === ''; switch (Object.prototype.toString.call(val)) { // String or Array case '[object String]': case '[object Array]': return !val.length; // Map or Set or File case '[object File]': case '[object Map]': case '[object Set]': { return !val.size; } // Plain Object case '[object Object]': { return !Object.keys(val).length; } } return false; }; function rafThrottle(fn) { let locked = false; return function(...args) { if (locked) return; locked = true; window.requestAnimationFrame(_ => { fn.apply(this, args); locked = false; }); }; } function objToArray(obj) { if (Array.isArray(obj)) { return obj; } return isEmpty(obj) ? [] : [obj]; } // CONCATENATED MODULE: ./node_modules/element-ui/packages/table/src/util.js const getCell = function(event) { let cell = event.target; while (cell && cell.tagName.toUpperCase() !== 'HTML') { if (cell.tagName.toUpperCase() === 'TD') { return cell; } cell = cell.parentNode; } return null; }; const util_isObject = function(obj) { return obj !== null && typeof obj === 'object'; }; const orderBy = function(array, sortKey, reverse, sortMethod, sortBy) { if (!sortKey && !sortMethod && (!sortBy || Array.isArray(sortBy) && !sortBy.length)) { return array; } if (typeof reverse === 'string') { reverse = reverse === 'descending' ? -1 : 1; } else { reverse = (reverse && reverse < 0) ? -1 : 1; } const getKey = sortMethod ? null : function(value, index) { if (sortBy) { if (!Array.isArray(sortBy)) { sortBy = [sortBy]; } return sortBy.map(function(by) { if (typeof by === 'string') { return getValueByPath(value, by); } else { return by(value, index, array); } }); } if (sortKey !== '$key') { if (util_isObject(value) && '$value' in value) value = value.$value; } return [util_isObject(value) ? getValueByPath(value, sortKey) : value]; }; const compare = function(a, b) { if (sortMethod) { return sortMethod(a.value, b.value); } for (let i = 0, len = a.key.length; i < len; i++) { if (a.key[i] < b.key[i]) { return -1; } if (a.key[i] > b.key[i]) { return 1; } } return 0; }; return array.map(function(value, index) { return { value: value, index: index, key: getKey ? getKey(value, index) : null }; }).sort(function(a, b) { let order = compare(a, b); if (!order) { // make stable https://en.wikipedia.org/wiki/Sorting_algorithm#Stability order = a.index - b.index; } return order * reverse; }).map(item => item.value); }; const getColumnById = function(table, columnId) { let column = null; table.columns.forEach(function(item) { if (item.id === columnId) { column = item; } }); return column; }; const getColumnByKey = function(table, columnKey) { let column = null; for (let i = 0; i < table.columns.length; i++) { const item = table.columns[i]; if (item.columnKey === columnKey) { column = item; break; } } return column; }; const getColumnByCell = function(table, cell) { const matches = (cell.className || '').match(/el-table_[^\s]+/gm); if (matches) { return getColumnById(table, matches[0]); } return null; }; const getRowIdentity = (row, rowKey) => { if (!row) throw new Error('row is required when get row identity'); if (typeof rowKey === 'string') { if (rowKey.indexOf('.') < 0) { return row[rowKey]; } let key = rowKey.split('.'); let current = row; for (let i = 0; i < key.length; i++) { current = current[key[i]]; } return current; } else if (typeof rowKey === 'function') { return rowKey.call(null, row); } }; const getKeysMap = function(array, rowKey) { const arrayMap = {}; (array || []).forEach((row, index) => { arrayMap[getRowIdentity(row, rowKey)] = { row, index }; }); return arrayMap; }; function util_hasOwn(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } function mergeOptions(defaults, config) { const options = {}; let key; for (key in defaults) { options[key] = defaults[key]; } for (key in config) { if (util_hasOwn(config, key)) { const value = config[key]; if (typeof value !== 'undefined') { options[key] = value; } } } return options; } function parseWidth(width) { if (width !== undefined) { width = parseInt(width, 10); if (isNaN(width)) { width = null; } } return width; } function parseMinWidth(minWidth) { if (typeof minWidth !== 'undefined') { minWidth = parseWidth(minWidth); if (isNaN(minWidth)) { minWidth = 80; } } return minWidth; }; function parseHeight(height) { if (typeof height === 'number') { return height; } if (typeof height === 'string') { if (/^\d+(?:px)?$/.test(height)) { return parseInt(height, 10); } else { return height; } } return null; } // https://github.com/reduxjs/redux/blob/master/src/compose.js function compose(...funcs) { if (funcs.length === 0) { return arg => arg; } if (funcs.length === 1) { return funcs[0]; } return funcs.reduce((a, b) => (...args) => a(b(...args))); } function toggleRowStatus(statusArr, row, newVal) { let changed = false; const index = statusArr.indexOf(row); const included = index !== -1; const addRow = () => { statusArr.push(row); changed = true; }; const removeRow = () => { statusArr.splice(index, 1); changed = true; }; if (typeof newVal === 'boolean') { if (newVal && !included) { addRow(); } else if (!newVal && included) { removeRow(); } } else { if (included) { removeRow(); } else { addRow(); } } return changed; } function walkTreeNode(root, cb, childrenKey = 'children', lazyKey = 'hasChildren') { const isNil = (array) => !(Array.isArray(array) && array.length); function _walker(parent, children, level) { cb(parent, children, level); children.forEach(item => { if (item[lazyKey]) { cb(item, null, level + 1); return; } const children = item[childrenKey]; if (!isNil(children)) { _walker(item, children, level + 1); } }); } root.forEach(item => { if (item[lazyKey]) { cb(item, null, 0); return; } const children = item[childrenKey]; if (!isNil(children)) { _walker(item, children, 0); } }); } // CONCATENATED MODULE: ./src/components/util.js function max(list) { return Math.max.apply(null, list.filter(function (item) { return !isNaN(item); })); } function map(list, fn) { return Array.prototype.map.call(list, fn); } function util_isEmpty(item) { return item.length === 0; } // CONCATENATED MODULE: ./src/components/ExTableColumn.js /* harmony default export */ var ExTableColumn = ({ name: 'ExTableColumn', extends: external_element_ui_["TableColumn"], // 指定继承组件 props: { fitByClass: { type: String, default: 'cell' }, autoFit: { type: Boolean, default: false }, fitGap: { type: Number, default: 0 }, fitHeader: { type: Boolean, default: false } }, data: function data() { return { autoWidth: 0 }; }, computed: { realMinWidth: function realMinWidth() { if (this.autoFit) { return parseMinWidth(max([this.minWidth, this.autoWidth])); } return external_element_ui_["TableColumn"].computed.realMinWidth.call(this); } }, methods: { updateAutoWidth: function updateAutoWidth() { if (!this.autoFit) return; var cellWrapperClass = this.fitHeader ? ".".concat(this.columnId) : "td.".concat(this.columnId); var cells = window.document.querySelectorAll("".concat(cellWrapperClass, " .").concat(this.fitByClass)); if (util_isEmpty(cells)) { cells = window.document.querySelectorAll("".concat(cellWrapperClass, " .cell")); } if (util_isEmpty(cells)) { return; } var autoMinWidth = max(map(cells, function (item) { return item.getBoundingClientRect().width; })) + this.fitGap + 1; if (this.autoWidth !== autoMinWidth) { this.autoWidth = autoMinWidth; } } }, updated: function updated() { this.updateAutoWidth(); }, mounted: function mounted() { this.$nextTick(this.updateAutoWidth); } }); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js /* harmony default export */ var entry_lib = __webpack_exports__["default"] = (ExTableColumn); /***/ }) /******/ }); }); //# sourceMappingURL=ex-table-column.umd.js.map