byted-vui
Version:
A Component Library for Vue.js.
1,666 lines (1,395 loc) • 112 kB
JavaScript
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, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // 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 = 218);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ (function(module, exports) {
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file.
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
module.exports = function normalizeComponent (
rawScriptExports,
compiledTemplate,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier /* server only */
) {
var esModule
var scriptExports = rawScriptExports = rawScriptExports || {}
// ES6 modules interop
var type = typeof rawScriptExports.default
if (type === 'object' || type === 'function') {
esModule = rawScriptExports
scriptExports = rawScriptExports.default
}
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (compiledTemplate) {
options.render = compiledTemplate.render
options.staticRenderFns = compiledTemplate.staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 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 = injectStyles
}
if (hook) {
var functional = options.functional
var existing = functional
? options.render
: options.beforeCreate
if (!functional) {
// inject component registration as beforeCreate hook
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
} else {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functioal component in vue file
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return existing(h, context)
}
}
}
return {
esModule: esModule,
exports: scriptExports,
options: options
}
}
/***/ }),
/***/ 10:
/***/ (function(module, exports) {
module.exports = require("byted-vui/lib/utils/clickoutside");
/***/ }),
/***/ 13:
/***/ (function(module, exports) {
module.exports = require("byted-vui/lib/utils/popup");
/***/ }),
/***/ 14:
/***/ (function(module, exports) {
module.exports = require("throttle-debounce/debounce");
/***/ }),
/***/ 16:
/***/ (function(module, exports) {
module.exports = require("byted-vui/lib/checkbox");
/***/ }),
/***/ 18:
/***/ (function(module, exports) {
module.exports = require("byted-vui/lib/utils/resize-event");
/***/ }),
/***/ 2:
/***/ (function(module, exports) {
module.exports = require("byted-vui/lib/utils/dom");
/***/ }),
/***/ 218:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _table = __webpack_require__(219);
var _table2 = _interopRequireDefault(_table);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* istanbul ignore next */
_table2.default.install = function (Vue) {
Vue.component(_table2.default.name, _table2.default);
};
exports.default = _table2.default;
/***/ }),
/***/ 219:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue__ = __webpack_require__(73);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue__);
/* harmony namespace reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue__[key]; }) }(__WEBPACK_IMPORT_KEY__));
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_0ece1c0d_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_table_vue__ = __webpack_require__(230);
var normalizeComponent = __webpack_require__(0)
/* script */
/* template */
/* template functional */
var __vue_template_functional__ = false
/* styles */
var __vue_styles__ = null
/* scopeId */
var __vue_scopeId__ = null
/* moduleIdentifier (server only) */
var __vue_module_identifier__ = null
var Component = normalizeComponent(
__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue___default.a,
__WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_0ece1c0d_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_table_vue__["a" /* default */],
__vue_template_functional__,
__vue_styles__,
__vue_scopeId__,
__vue_module_identifier__
)
/* harmony default export */ __webpack_exports__["default"] = (Component.exports);
/***/ }),
/***/ 220:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _normalizeWheel = __webpack_require__(221);
var _normalizeWheel2 = _interopRequireDefault(_normalizeWheel);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var mousewheel = function mousewheel(element, callback) {
if (element && element.addEventListener) {
element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', function (event) {
var normalized = (0, _normalizeWheel2.default)(event);
callback && callback.apply(this, [event, normalized]);
});
}
};
exports.default = {
bind: function bind(el, binding) {
mousewheel(el, binding.value);
}
};
/***/ }),
/***/ 221:
/***/ (function(module, exports) {
module.exports = require("normalize-wheel");
/***/ }),
/***/ 222:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _vue = __webpack_require__(4);
var _vue2 = _interopRequireDefault(_vue);
var _debounce = __webpack_require__(14);
var _debounce2 = _interopRequireDefault(_debounce);
var _merge = __webpack_require__(9);
var _merge2 = _interopRequireDefault(_merge);
var _dom = __webpack_require__(2);
var _util = __webpack_require__(74);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var sortData = function sortData(data, states) {
var sortingColumn = states.sortingColumn;
if (!sortingColumn || typeof sortingColumn.sortable === 'string') {
return data;
}
return (0, _util.orderBy)(data, states.sortProp, states.sortOrder, sortingColumn.sortMethod, sortingColumn.sortBy);
};
var getKeysMap = function getKeysMap(array, rowKey) {
var arrayMap = {};
(array || []).forEach(function (row, index) {
arrayMap[(0, _util.getRowIdentity)(row, rowKey)] = { row: row, index: index };
});
return arrayMap;
};
var toggleRowSelection = function toggleRowSelection(states, row, selected) {
var changed = false;
var selection = states.selection;
var index = selection.indexOf(row);
if (typeof selected === 'undefined') {
if (index === -1) {
selection.push(row);
changed = true;
} else {
selection.splice(index, 1);
changed = true;
}
} else {
if (selected && index === -1) {
selection.push(row);
changed = true;
} else if (!selected && index > -1) {
selection.splice(index, 1);
changed = true;
}
}
return changed;
};
var toggleRowExpansion = function toggleRowExpansion(states, row, expanded) {
var changed = false;
var expandRows = states.expandRows;
if (typeof expanded !== 'undefined') {
var index = expandRows.indexOf(row);
if (expanded) {
if (index === -1) {
expandRows.push(row);
changed = true;
}
} else {
if (index !== -1) {
expandRows.splice(index, 1);
changed = true;
}
}
} else {
var _index = expandRows.indexOf(row);
if (_index === -1) {
expandRows.push(row);
changed = true;
} else {
expandRows.splice(_index, 1);
changed = true;
}
}
return changed;
};
var TableStore = function TableStore(table) {
var initialState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!table) {
throw new Error('Table is required.');
}
this.table = table;
this.states = {
rowKey: null,
_columns: [],
originColumns: [],
columns: [],
fixedColumns: [],
rightFixedColumns: [],
leafColumns: [],
fixedLeafColumns: [],
rightFixedLeafColumns: [],
leafColumnsLength: 0,
fixedLeafColumnsLength: 0,
rightFixedLeafColumnsLength: 0,
isComplex: false,
filteredData: null,
data: null,
sortingColumn: null,
sortProp: null,
sortOrder: null,
isAllSelected: false,
selection: [],
reserveSelection: false,
selectable: null,
currentRow: null,
hoverRow: null,
filters: {},
expandRows: [],
defaultExpandAll: false,
selectOnIndeterminate: false
};
for (var prop in initialState) {
if (initialState.hasOwnProperty(prop) && this.states.hasOwnProperty(prop)) {
this.states[prop] = initialState[prop];
}
}
};
TableStore.prototype.mutations = {
setData: function setData(states, data) {
var _this = this;
var dataInstanceChanged = states._data !== data;
states._data = data;
Object.keys(states.filters).forEach(function (columnId) {
var values = states.filters[columnId];
if (!values || values.length === 0) return;
var column = (0, _util.getColumnById)(_this.states, columnId);
if (column && column.filterMethod) {
data = data.filter(function (row) {
return values.some(function (value) {
return column.filterMethod.call(null, value, row, column);
});
});
}
});
states.filteredData = data;
states.data = sortData(data || [], states);
this.updateCurrentRow();
var rowKey = states.rowKey;
if (!states.reserveSelection) {
if (dataInstanceChanged) {
this.clearSelection();
} else {
this.cleanSelection();
}
this.updateAllSelected();
} else {
if (rowKey) {
var selection = states.selection;
var selectedMap = getKeysMap(selection, rowKey);
states.data.forEach(function (row) {
var rowId = (0, _util.getRowIdentity)(row, rowKey);
var rowInfo = selectedMap[rowId];
if (rowInfo) {
selection[rowInfo.index] = row;
}
});
this.updateAllSelected();
} else {
console.warn('WARN: rowKey is required when reserve-selection is enabled.');
}
}
var defaultExpandAll = states.defaultExpandAll;
if (defaultExpandAll) {
this.states.expandRows = (states.data || []).slice(0);
} else if (rowKey) {
// update expandRows to new rows according to rowKey
var ids = getKeysMap(this.states.expandRows, rowKey);
var expandRows = [];
for (var _iterator = states.data, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var row = _ref;
var rowId = (0, _util.getRowIdentity)(row, rowKey);
if (ids[rowId]) {
expandRows.push(row);
}
}
this.states.expandRows = expandRows;
} else {
// clear the old rows
this.states.expandRows = [];
}
_vue2.default.nextTick(function () {
return _this.table.updateScrollY();
});
},
changeSortCondition: function changeSortCondition(states, options) {
var _this2 = this;
states.data = sortData(states.filteredData || states._data || [], states);
var _table = this.table,
$el = _table.$el,
highlightCurrentRow = _table.highlightCurrentRow;
if ($el && highlightCurrentRow) {
var data = states.data;
var tr = $el.querySelector('tbody').children;
var rows = [].filter.call(tr, function (row) {
return (0, _dom.hasClass)(row, 'el-table__row');
});
var row = rows[data.indexOf(states.currentRow)];
[].forEach.call(rows, function (row) {
return (0, _dom.removeClass)(row, 'current-row');
});
(0, _dom.addClass)(row, 'current-row');
}
if (!options || !options.silent) {
this.table.$emit('sort-change', {
column: this.states.sortingColumn,
prop: this.states.sortProp,
order: this.states.sortOrder
});
}
_vue2.default.nextTick(function () {
return _this2.table.updateScrollY();
});
},
sort: function sort(states, options) {
var _this3 = this;
var prop = options.prop,
order = options.order;
if (prop) {
states.sortProp = prop;
states.sortOrder = order || 'ascending';
_vue2.default.nextTick(function () {
for (var i = 0, length = states.columns.length; i < length; i++) {
var column = states.columns[i];
if (column.property === states.sortProp) {
column.order = states.sortOrder;
states.sortingColumn = column;
break;
}
}
if (states.sortingColumn) {
_this3.commit('changeSortCondition');
}
});
}
},
filterChange: function filterChange(states, options) {
var _this4 = this;
var column = options.column,
values = options.values,
silent = options.silent;
if (values && !Array.isArray(values)) {
values = [values];
}
var prop = column.property;
var filters = {};
if (prop) {
states.filters[column.id] = values;
filters[column.columnKey || column.id] = values;
}
var data = states._data;
Object.keys(states.filters).forEach(function (columnId) {
var values = states.filters[columnId];
if (!values || values.length === 0) return;
var column = (0, _util.getColumnById)(_this4.states, columnId);
if (column && column.filterMethod) {
data = data.filter(function (row) {
return values.some(function (value) {
return column.filterMethod.call(null, value, row, column);
});
});
}
});
states.filteredData = data;
states.data = sortData(data, states);
if (!silent) {
this.table.$emit('filter-change', filters);
}
_vue2.default.nextTick(function () {
return _this4.table.updateScrollY();
});
},
insertColumn: function insertColumn(states, column, index, parent) {
var array = states._columns;
if (parent) {
array = parent.children;
if (!array) array = parent.children = [];
}
if (typeof index !== 'undefined') {
array.splice(index, 0, column);
} else {
array.push(column);
}
if (column.type === 'selection') {
states.selectable = column.selectable;
states.reserveSelection = column.reserveSelection;
}
if (this.table.$ready) {
this.updateColumns(); // hack for dynamics insert column
this.scheduleLayout();
}
},
removeColumn: function removeColumn(states, column, parent) {
var array = states._columns;
if (parent) {
array = parent.children;
if (!array) array = parent.children = [];
}
if (array) {
array.splice(array.indexOf(column), 1);
}
if (this.table.$ready) {
this.updateColumns(); // hack for dynamics remove column
this.scheduleLayout();
}
},
setHoverRow: function setHoverRow(states, row) {
states.hoverRow = row;
},
setCurrentRow: function setCurrentRow(states, row) {
var oldCurrentRow = states.currentRow;
states.currentRow = row;
if (oldCurrentRow !== row) {
this.table.$emit('current-change', row, oldCurrentRow);
}
},
rowSelectedChanged: function rowSelectedChanged(states, row) {
var changed = toggleRowSelection(states, row);
var selection = states.selection;
if (changed) {
var table = this.table;
table.$emit('selection-change', selection ? selection.slice() : []);
table.$emit('select', selection, row);
}
this.updateAllSelected();
},
toggleAllSelection: (0, _debounce2.default)(10, function (states) {
var data = states.data || [];
if (data.length === 0) return;
var selection = this.states.selection;
// when only some rows are selected (but not all), select or deselect all of them
// depending on the value of selectOnIndeterminate
var value = states.selectOnIndeterminate ? !states.isAllSelected : !(states.isAllSelected || selection.length);
var selectionChanged = false;
data.forEach(function (item, index) {
if (states.selectable) {
if (states.selectable.call(null, item, index) && toggleRowSelection(states, item, value)) {
selectionChanged = true;
}
} else {
if (toggleRowSelection(states, item, value)) {
selectionChanged = true;
}
}
});
var table = this.table;
if (selectionChanged) {
table.$emit('selection-change', selection ? selection.slice() : []);
}
table.$emit('select-all', selection);
states.isAllSelected = value;
})
};
var doFlattenColumns = function doFlattenColumns(columns) {
var result = [];
columns.forEach(function (column) {
if (column.children) {
result.push.apply(result, doFlattenColumns(column.children));
} else {
result.push(column);
}
});
return result;
};
TableStore.prototype.updateColumns = function () {
var states = this.states;
var _columns = states._columns || [];
states.fixedColumns = _columns.filter(function (column) {
return column.fixed === true || column.fixed === 'left';
});
states.rightFixedColumns = _columns.filter(function (column) {
return column.fixed === 'right';
});
if (states.fixedColumns.length > 0 && _columns[0] && _columns[0].type === 'selection' && !_columns[0].fixed) {
_columns[0].fixed = true;
states.fixedColumns.unshift(_columns[0]);
}
var notFixedColumns = _columns.filter(function (column) {
return !column.fixed;
});
states.originColumns = [].concat(states.fixedColumns).concat(notFixedColumns).concat(states.rightFixedColumns);
var leafColumns = doFlattenColumns(notFixedColumns);
var fixedLeafColumns = doFlattenColumns(states.fixedColumns);
var rightFixedLeafColumns = doFlattenColumns(states.rightFixedColumns);
states.leafColumnsLength = leafColumns.length;
states.fixedLeafColumnsLength = fixedLeafColumns.length;
states.rightFixedLeafColumnsLength = rightFixedLeafColumns.length;
states.columns = [].concat(fixedLeafColumns).concat(leafColumns).concat(rightFixedLeafColumns);
states.isComplex = states.fixedColumns.length > 0 || states.rightFixedColumns.length > 0;
};
TableStore.prototype.isSelected = function (row) {
return (this.states.selection || []).indexOf(row) > -1;
};
TableStore.prototype.clearSelection = function () {
var states = this.states;
states.isAllSelected = false;
var oldSelection = states.selection;
if (states.selection.length) {
states.selection = [];
}
if (oldSelection.length > 0) {
this.table.$emit('selection-change', states.selection ? states.selection.slice() : []);
}
};
TableStore.prototype.setExpandRowKeys = function (rowKeys) {
var expandRows = [];
var data = this.states.data;
var rowKey = this.states.rowKey;
if (!rowKey) throw new Error('[Table] prop row-key should not be empty.');
var keysMap = getKeysMap(data, rowKey);
rowKeys.forEach(function (key) {
var info = keysMap[key];
if (info) {
expandRows.push(info.row);
}
});
this.states.expandRows = expandRows;
};
TableStore.prototype.toggleRowSelection = function (row, selected) {
var changed = toggleRowSelection(this.states, row, selected);
if (changed) {
this.table.$emit('selection-change', this.states.selection ? this.states.selection.slice() : []);
}
};
TableStore.prototype.toggleRowExpansion = function (row, expanded) {
var changed = toggleRowExpansion(this.states, row, expanded);
if (changed) {
this.table.$emit('expand-change', row, this.states.expandRows);
this.scheduleLayout();
}
};
TableStore.prototype.isRowExpanded = function (row) {
var _states = this.states,
_states$expandRows = _states.expandRows,
expandRows = _states$expandRows === undefined ? [] : _states$expandRows,
rowKey = _states.rowKey;
if (rowKey) {
var expandMap = getKeysMap(expandRows, rowKey);
return !!expandMap[(0, _util.getRowIdentity)(row, rowKey)];
}
return expandRows.indexOf(row) !== -1;
};
TableStore.prototype.cleanSelection = function () {
var selection = this.states.selection || [];
var data = this.states.data;
var rowKey = this.states.rowKey;
var deleted = void 0;
if (rowKey) {
deleted = [];
var selectedMap = getKeysMap(selection, rowKey);
var dataMap = getKeysMap(data, rowKey);
for (var key in selectedMap) {
if (selectedMap.hasOwnProperty(key) && !dataMap[key]) {
deleted.push(selectedMap[key].row);
}
}
} else {
deleted = selection.filter(function (item) {
return data.indexOf(item) === -1;
});
}
deleted.forEach(function (deletedItem) {
selection.splice(selection.indexOf(deletedItem), 1);
});
if (deleted.length) {
this.table.$emit('selection-change', selection ? selection.slice() : []);
}
};
TableStore.prototype.clearFilter = function () {
var states = this.states;
var _table$$refs = this.table.$refs,
tableHeader = _table$$refs.tableHeader,
fixedTableHeader = _table$$refs.fixedTableHeader,
rightFixedTableHeader = _table$$refs.rightFixedTableHeader;
var panels = {};
if (tableHeader) panels = (0, _merge2.default)(panels, tableHeader.filterPanels);
if (fixedTableHeader) panels = (0, _merge2.default)(panels, fixedTableHeader.filterPanels);
if (rightFixedTableHeader) panels = (0, _merge2.default)(panels, rightFixedTableHeader.filterPanels);
var keys = Object.keys(panels);
if (!keys.length) return;
keys.forEach(function (key) {
panels[key].filteredValue = [];
});
states.filters = {};
this.commit('filterChange', {
column: {},
values: [],
silent: true
});
};
TableStore.prototype.clearSort = function () {
var states = this.states;
if (!states.sortingColumn) return;
states.sortingColumn.order = null;
states.sortProp = null;
states.sortOrder = null;
this.commit('changeSortCondition', {
silent: true
});
};
TableStore.prototype.updateAllSelected = function () {
var states = this.states;
var selection = states.selection,
rowKey = states.rowKey,
selectable = states.selectable,
data = states.data;
if (!data || data.length === 0) {
states.isAllSelected = false;
return;
}
var selectedMap = void 0;
if (rowKey) {
selectedMap = getKeysMap(states.selection, rowKey);
}
var isSelected = function isSelected(row) {
if (selectedMap) {
return !!selectedMap[(0, _util.getRowIdentity)(row, rowKey)];
} else {
return selection.indexOf(row) !== -1;
}
};
var isAllSelected = true;
var selectedCount = 0;
for (var i = 0, j = data.length; i < j; i++) {
var item = data[i];
var isRowSelectable = selectable && selectable.call(null, item, i);
if (!isSelected(item)) {
if (!selectable || isRowSelectable) {
isAllSelected = false;
break;
}
} else {
selectedCount++;
}
}
if (selectedCount === 0) isAllSelected = false;
states.isAllSelected = isAllSelected;
};
TableStore.prototype.scheduleLayout = function (updateColumns) {
if (updateColumns) {
this.updateColumns();
}
this.table.debouncedUpdateLayout();
};
TableStore.prototype.setCurrentRowKey = function (key) {
var states = this.states;
var rowKey = states.rowKey;
if (!rowKey) throw new Error('[Table] row-key should not be empty.');
var data = states.data || [];
var keysMap = getKeysMap(data, rowKey);
var info = keysMap[key];
if (info) {
states.currentRow = info.row;
}
};
TableStore.prototype.updateCurrentRow = function () {
var states = this.states;
var table = this.table;
var data = states.data || [];
var oldCurrentRow = states.currentRow;
if (data.indexOf(oldCurrentRow) === -1) {
states.currentRow = null;
if (states.currentRow !== oldCurrentRow) {
table.$emit('current-change', null, oldCurrentRow);
}
}
};
TableStore.prototype.commit = function (name) {
var mutations = this.mutations;
if (mutations[name]) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
mutations[name].apply(this, [this.states].concat(args));
} else {
throw new Error('Action not found: ' + name);
}
};
exports.default = TableStore;
/***/ }),
/***/ 223:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _scrollbarWidth = __webpack_require__(40);
var _scrollbarWidth2 = _interopRequireDefault(_scrollbarWidth);
var _vue = __webpack_require__(4);
var _vue2 = _interopRequireDefault(_vue);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TableLayout = function () {
function TableLayout(options) {
_classCallCheck(this, TableLayout);
this.observers = [];
this.table = null;
this.store = null;
this.columns = null;
this.fit = true;
this.showHeader = true;
this.height = null;
this.scrollX = false;
this.scrollY = false;
this.bodyWidth = null;
this.fixedWidth = null;
this.rightFixedWidth = null;
this.tableHeight = null;
this.headerHeight = 44; // Table Header Height
this.appendHeight = 0; // Append Slot Height
this.footerHeight = 44; // Table Footer Height
this.viewportHeight = null; // Table Height - Scroll Bar Height
this.bodyHeight = null; // Table Height - Table Header Height
this.fixedBodyHeight = null; // Table Height - Table Header Height - Scroll Bar Height
this.gutterWidth = (0, _scrollbarWidth2.default)();
for (var name in options) {
if (options.hasOwnProperty(name)) {
this[name] = options[name];
}
}
if (!this.table) {
throw new Error('table is required for Table Layout');
}
if (!this.store) {
throw new Error('store is required for Table Layout');
}
}
TableLayout.prototype.updateScrollY = function updateScrollY() {
var height = this.height;
if (typeof height !== 'string' && typeof height !== 'number') return;
var bodyWrapper = this.table.bodyWrapper;
if (this.table.$el && bodyWrapper) {
var body = bodyWrapper.querySelector('.vi-table__body');
this.scrollY = body.offsetHeight > this.bodyHeight;
}
};
TableLayout.prototype.setHeight = function setHeight(value) {
var _this = this;
var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'height';
if (_vue2.default.prototype.$isServer) return;
var el = this.table.$el;
if (typeof value === 'string' && /^\d+$/.test(value)) {
value = Number(value);
}
this.height = value;
if (!el && (value || value === 0)) return _vue2.default.nextTick(function () {
return _this.setHeight(value, prop);
});
if (typeof value === 'number') {
el.style[prop] = value + 'px';
this.updateElsHeight();
} else if (typeof value === 'string') {
el.style[prop] = value;
this.updateElsHeight();
}
};
TableLayout.prototype.setMaxHeight = function setMaxHeight(value) {
return this.setHeight(value, 'max-height');
};
TableLayout.prototype.updateElsHeight = function updateElsHeight() {
var _this2 = this;
if (!this.table.$ready) return _vue2.default.nextTick(function () {
return _this2.updateElsHeight();
});
var _table$$refs = this.table.$refs,
headerWrapper = _table$$refs.headerWrapper,
appendWrapper = _table$$refs.appendWrapper,
footerWrapper = _table$$refs.footerWrapper;
this.appendHeight = appendWrapper ? appendWrapper.offsetHeight : 0;
if (this.showHeader && !headerWrapper) return;
var headerHeight = this.headerHeight = !this.showHeader ? 0 : headerWrapper.offsetHeight;
if (this.showHeader && headerWrapper.offsetWidth > 0 && (this.table.columns || []).length > 0 && headerHeight < 2) {
return _vue2.default.nextTick(function () {
return _this2.updateElsHeight();
});
}
var tableHeight = this.tableHeight = this.table.$el.clientHeight;
if (this.height !== null && (!isNaN(this.height) || typeof this.height === 'string')) {
var footerHeight = this.footerHeight = footerWrapper ? footerWrapper.offsetHeight : 0;
this.bodyHeight = tableHeight - headerHeight - footerHeight + (footerWrapper ? 1 : 0);
}
this.fixedBodyHeight = this.scrollX ? this.bodyHeight - this.gutterWidth : this.bodyHeight;
var noData = !this.table.data || this.table.data.length === 0;
this.viewportHeight = this.scrollX ? tableHeight - (noData ? 0 : this.gutterWidth) : tableHeight;
this.updateScrollY();
this.notifyObservers('scrollable');
};
TableLayout.prototype.getFlattenColumns = function getFlattenColumns() {
var flattenColumns = [];
var columns = this.table.columns;
columns.forEach(function (column) {
if (column.isColumnGroup) {
flattenColumns.push.apply(flattenColumns, column.columns);
} else {
flattenColumns.push(column);
}
});
return flattenColumns;
};
TableLayout.prototype.updateColumnsWidth = function updateColumnsWidth() {
if (_vue2.default.prototype.$isServer) return;
var fit = this.fit;
var bodyWidth = this.table.$el.clientWidth;
var bodyMinWidth = 0;
var flattenColumns = this.getFlattenColumns();
var flexColumns = flattenColumns.filter(function (column) {
return typeof column.width !== 'number';
});
flattenColumns.forEach(function (column) {
// Clean those columns whose width changed from flex to unflex
if (typeof column.width === 'number' && column.realWidth) column.realWidth = null;
});
if (flexColumns.length > 0 && fit) {
flattenColumns.forEach(function (column) {
bodyMinWidth += column.width || column.minWidth || 80;
});
var scrollYWidth = this.scrollY ? this.gutterWidth : 0;
if (bodyMinWidth <= bodyWidth - scrollYWidth) {
// DON'T HAVE SCROLL BAR
this.scrollX = false;
var totalFlexWidth = bodyWidth - scrollYWidth - bodyMinWidth;
if (flexColumns.length === 1) {
flexColumns[0].realWidth = (flexColumns[0].minWidth || 80) + totalFlexWidth;
} else {
var allColumnsWidth = flexColumns.reduce(function (prev, column) {
return prev + (column.minWidth || 80);
}, 0);
var flexWidthPerPixel = totalFlexWidth / allColumnsWidth;
var noneFirstWidth = 0;
flexColumns.forEach(function (column, index) {
if (index === 0) return;
var flexWidth = Math.floor((column.minWidth || 80) * flexWidthPerPixel);
noneFirstWidth += flexWidth;
column.realWidth = (column.minWidth || 80) + flexWidth;
});
flexColumns[0].realWidth = (flexColumns[0].minWidth || 80) + totalFlexWidth - noneFirstWidth;
}
} else {
// HAVE HORIZONTAL SCROLL BAR
this.scrollX = true;
flexColumns.forEach(function (column) {
column.realWidth = column.minWidth;
});
}
this.bodyWidth = Math.max(bodyMinWidth, bodyWidth);
this.table.resizeState.width = this.bodyWidth;
} else {
flattenColumns.forEach(function (column) {
if (!column.width && !column.minWidth) {
column.realWidth = 80;
} else {
column.realWidth = column.width || column.minWidth;
}
bodyMinWidth += column.realWidth;
});
this.scrollX = bodyMinWidth > bodyWidth;
this.bodyWidth = bodyMinWidth;
}
var fixedColumns = this.store.states.fixedColumns;
if (fixedColumns.length > 0) {
var fixedWidth = 0;
fixedColumns.forEach(function (column) {
fixedWidth += column.realWidth || column.width;
});
this.fixedWidth = fixedWidth;
}
var rightFixedColumns = this.store.states.rightFixedColumns;
if (rightFixedColumns.length > 0) {
var rightFixedWidth = 0;
rightFixedColumns.forEach(function (column) {
rightFixedWidth += column.realWidth || column.width;
});
this.rightFixedWidth = rightFixedWidth;
}
this.notifyObservers('columns');
};
TableLayout.prototype.addObserver = function addObserver(observer) {
this.observers.push(observer);
};
TableLayout.prototype.removeObserver = function removeObserver(observer) {
var index = this.observers.indexOf(observer);
if (index !== -1) {
this.observers.splice(index, 1);
}
};
TableLayout.prototype.notifyObservers = function notifyObservers(event) {
var _this3 = this;
var observers = this.observers;
observers.forEach(function (observer) {
switch (event) {
case 'columns':
observer.onColumnsChange(_this3);
break;
case 'scrollable':
observer.onScrollableChange(_this3);
break;
default:
throw new Error('Table Layout don\'t have event ' + event + '.');
}
});
};
return TableLayout;
}();
exports.default = TableLayout;
/***/ }),
/***/ 224:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _util = __webpack_require__(74);
var _dom = __webpack_require__(2);
var _checkbox = __webpack_require__(16);
var _checkbox2 = _interopRequireDefault(_checkbox);
var _tooltip = __webpack_require__(23);
var _tooltip2 = _interopRequireDefault(_tooltip);
var _debounce = __webpack_require__(14);
var _debounce2 = _interopRequireDefault(_debounce);
var _layoutObserver = __webpack_require__(41);
var _layoutObserver2 = _interopRequireDefault(_layoutObserver);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
name: 'ViTableBody',
mixins: [_layoutObserver2.default],
components: {
ViCheckbox: _checkbox2.default,
ViTooltip: _tooltip2.default
},
props: {
store: {
required: true
},
stripe: Boolean,
context: {},
rowClassName: [String, Function],
rowStyle: [Object, Function],
fixed: String,
highlight: Boolean
},
render: function render(h) {
var _this = this;
var columnsHidden = this.columns.map(function (column, index) {
return _this.isColumnHidden(index);
});
return h(
'table',
{
'class': 'vi-table__body',
attrs: { cellspacing: '0',
cellpadding: '0',
border: '0' }
},
[h('colgroup', [this._l(this.columns, function (column) {
return h('col', {
attrs: { name: column.id }
});
})]), h('tbody', [this._l(this.data, function (row, $index) {
return [h(
'tr',
{
style: _this.rowStyle ? _this.getRowStyle(row, $index) : null,
key: _this.table.rowKey ? _this.getKeyOfRow(row, $index) : $index,
on: {
'dblclick': function dblclick($event) {
return _this.handleDoubleClick($event, row);
},
'click': function click($event) {
return _this.handleClick($event, row);
},
'contextmenu': function contextmenu($event) {
return _this.handleContextMenu($event, row);
},
'mouseenter': function mouseenter(_) {
return _this.handleMouseEnter($index);
},
'mouseleave': function mouseleave(_) {
return _this.handleMouseLeave();
}
},
'class': [_this.getRowClass(row, $index)] },
[_this._l(_this.columns, function (column, cellIndex) {
var _getSpan = _this.getSpan(row, column, $index, cellIndex),
rowspan = _getSpan.rowspan,
colspan = _getSpan.colspan;
if (!rowspan || !colspan) {
return '';
} else {
if (rowspan === 1 && colspan === 1) {
return h(
'td',
{
style: _this.getCellStyle($index, cellIndex, row, column),
'class': _this.getCellClass($index, cellIndex, row, column),
on: {
'mouseenter': function mouseenter($event) {
return _this.handleCellMouseEnter($event, row);
},
'mouseleave': _this.handleCellMouseLeave
}
},
[column.renderCell.call(_this._renderProxy, h, {
row: row,
column: column,
$index: $index,
store: _this.store,
_self: _this.context || _this.table.$vnode.context
}, columnsHidden[cellIndex])]
);
} else {
return h(
'td',
{
style: _this.getCellStyle($index, cellIndex, row, column),
'class': _this.getCellClass($index, cellIndex, row, column),
attrs: { rowspan: rowspan,
colspan: colspan
},
on: {
'mouseenter': function mouseenter($event) {
return _this.handleCellMouseEnter($event, row);
},
'mouseleave': _this.handleCellMouseLeave
}
},
[column.renderCell.call(_this._renderProxy, h, {
row: row,
column: column,
$index: $index,
store: _this.store,
_self: _this.context || _this.table.$vnode.context
}, columnsHidden[cellIndex])]
);
}
}
})]
), _this.store.isRowExpanded(row) ? h('tr', [h(
'td',
{
attrs: { colspan: _this.columns.length },
'class': 'vi-table__expanded-cell' },
[_this.table.renderExpanded ? _this.table.renderExpanded(h, { row: row, $index: $index, store: _this.store }) : '']
)]) : ''];
}).concat(h('vi-tooltip', {
attrs: { effect: this.table.tooltipEffect, placement: 'top', content: this.tooltipContent },
ref: 'tooltip' }))])]
);
},
watch: {
'store.states.hoverRow': function storeStatesHoverRow(newVal, oldVal) {
if (!this.store.states.isComplex) return;
var el = this.$el;
if (!el) return;
var tr = el.querySelector('tbody').children;
var rows = [].filter.call(tr, function (row) {
return (0, _dom.hasClass)(row, 'vi-table__row');
});
var oldRow = rows[oldVal];
var newRow = rows[newVal];
if (oldRow) {
(0, _dom.removeClass)(oldRow, 'hover-row');
}
if (newRow) {
(0, _dom.addClass)(newRow, 'hover-row');
}
},
'store.states.currentRow': function storeStatesCurrentRow(newVal, oldVal) {
if (!this.highlight) return;
var el = this.$el;
if (!el) return;
var data = this.store.states.data;
var tr = el.querySelector('tbody').children;
var rows = [].filter.call(tr, function (row) {
return (0, _dom.hasClass)(row, 'el-table__row');
});
var oldRow = rows[data.indexOf(oldVal)];
var newRow = rows[data.indexOf(newVal)];
if (oldRow) {
(0, _dom.removeClass)(oldRow, 'current-row');
} else {
[].forEach.call(rows, function (row) {
return (0, _dom.removeClass)(row, 'current-row');
});
}
if (newRow) {
(0, _dom.addClass)(newRow, 'current-row');
}
}
},
computed: {
table: function table() {
return this.$parent;
},
data: function data() {
return this.store.states.data;
},
columnsCount: function columnsCount() {
return this.store.states.columns.length;
},
leftFixedLeafCount: function leftFixedLeafCount() {
return this.store.states.fixedLeafColumnsLength;
},
rightFixedLeafCount: function rightFixedLeafCount() {
return this.store.states.rightFixedLeafColumnsLength;
},
leftFixedCount: function leftFixedCount() {
return this.store.states.fixedColumns.length;
},
rightFixedCount: function rightFixedCount() {
return this.store.states.rightFixedColumns.length;
},
columns: function columns() {
return this.store.states.columns;
}
},
data: function data() {
return {
tooltipContent: ''
};
},
created: function created() {
this.activateTooltip = (0, _debounce2.default)(50, function (tooltip) {
return tooltip.handleShowPopper();
});
},
methods: {
getKeyOfRow: function getKeyOfRow(row, index) {
var rowKey = this.table.rowKey;
if (rowKey) {
return (0, _util.getRowIdentity)(row, rowKey);
}
return index;
},
isColumnHidden: function isColumnHidden(index) {
if (this.fixed === true || this.fixed === 'left') {
return index >= this.leftFixedLeafCount;
} else if (this.fixed === 'right') {
return index < this.columnsCount - this.rightFixedLeafCount;
} else {
return index < this.leftFixedLeafCount || index >= this.columnsCount - this.rightFixedLeafCount;
}
},
getSpan: function getSpan(row, column, rowIndex, columnIndex) {
var rowspan = 1;
var colspan = 1;
var fn = this.table.spanMethod;
if (typeof fn === 'function') {
var result = fn({
row: row,
column: column,
rowIndex: rowIndex,
columnIndex: columnIndex
});
if (Array.isArray(result)) {
rowspan = result[0];
colspan = result[1];
} else if ((typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object') {
rowspan = result.rowspan;
colspan = result.colspan;
}
}
return {
rowspan: rowspan,
colspan: colspan
};
},
getRowStyle: function getRowStyle(row, rowIndex) {
var rowStyle = this.table.rowStyle;
if (typeof rowStyle === 'function') {
return rowStyle.call(null, {
row: row,
rowIndex: rowIndex
});
}
return rowStyle;
},
getRowClass: function getRowClass(row, rowIndex) {
var currentRow = this.store.states.currentRow;
var classes = this.table.highlightCurrentRow && currentRow === row ? ['vi-table__row', 'current-row'] : ['vi-table__row'];
if (this.stripe && rowIndex % 2 === 1) {
classes.push('vi-table__row--striped');
}
var rowClassName = this.table.rowClassName;
if (typeof rowClassName === 'string') {
classes.push(rowClassName);
} else if (typeof rowClassName === 'function') {
classes.push(rowClassName.call(null, {
row: row,
rowIndex: rowIndex
}));
}
if (this.store.states.expandRows.indexOf(row) > -1) {
classes.push('expanded');
}
return classes.join(' ');
},
getCellStyle: function getCellStyle(rowIndex, columnIndex, row, column) {
var cellStyle = this.table.cellStyle;
if (typeof cellStyle === 'function') {
return cellStyle.call(null, {
rowIndex: rowIndex,
columnIndex: columnIndex,
row: row,
column: column
});
}
return cellStyle;
},
getCellClass: function getCellClass(rowIndex, columnIndex, row, column) {
var classes = [column.id, column.align, column.className];
if (this.isColumnHidden(columnIndex)) {
classes.push('is-hidden');
}
var cellClassName = this.table.cellClassName;
if (typeof cellClassName === 'string') {
classes.push(cellClassName);
} else if (typeof cellClassName === 'function') {
classes.push(cellClassName.call(null, {
rowIndex: rowIndex,
columnIndex: columnIndex,
row: row,
column: column
}));
}
return classes.join(' ');
},
handleCellMouseEnter: function handleCellMouseEnter(event, row) {
var table = this.table;
var cell = (0, _util.getCell)(event);
if (cell) {
var column = (0, _util.getColumnByCell)(table, cell);
var hoverState = table.hoverState = { cell: cell, column: column, row: row };
table.$emit('cell-mouse-enter', hoverState.row, hover