ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
146 lines (118 loc) • 5.86 kB
JavaScript
import { createVNode as _createVNode } from "vue";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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; }
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); }
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
import { defineComponent } from 'vue';
import T, { defaultTableProps } from './Table';
import { getOptionProps, getKey, getPropsData, getSlot } from '../_util/props-util';
var Table = defineComponent({
name: 'ATable',
Column: T.Column,
ColumnGroup: T.ColumnGroup,
inheritAttrs: false,
props: defaultTableProps,
methods: {
normalize: function normalize() {
var _this = this;
var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var columns = [];
elements.forEach(function (element) {
var _a, _b, _c, _d;
if (!element) {
return;
}
var key = getKey(element);
var style = ((_a = element.props) === null || _a === void 0 ? void 0 : _a.style) || {};
var cls = ((_b = element.props) === null || _b === void 0 ? void 0 : _b.class) || '';
var props = getPropsData(element);
var _e = element.children || {},
children = _e.default,
restSlots = __rest(_e, ["default"]);
var column = _extends(_extends(_extends({}, restSlots), props), {
style: style,
class: cls
});
if (key) {
column.key = key;
}
if ((_c = element.type) === null || _c === void 0 ? void 0 : _c.__ANT_TABLE_COLUMN_GROUP) {
column.children = _this.normalize(typeof children === 'function' ? children() : children);
} else {
var customRender = (_d = element.children) === null || _d === void 0 ? void 0 : _d.default;
column.customRender = column.customRender || customRender;
}
columns.push(column);
});
return columns;
},
updateColumns: function updateColumns() {
var _this2 = this;
var cols = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var columns = [];
var $slots = this.$slots;
cols.forEach(function (col) {
var _col$slots = col.slots,
slots = _col$slots === void 0 ? {} : _col$slots,
restProps = __rest(col, ["slots"]);
var column = _extends({}, restProps);
Object.keys(slots).forEach(function (key) {
var name = slots[key];
if (column[key] === undefined && $slots[name]) {
column[key] = $slots[name];
}
}); // if (slotScopeName && $scopedSlots[slotScopeName]) {
// column.customRender = column.customRender || $scopedSlots[slotScopeName]
// }
if (col.children) {
column.children = _this2.updateColumns(column.children);
}
columns.push(column);
});
return columns;
}
},
render: function render() {
var normalize = this.normalize,
$slots = this.$slots;
var props = _extends(_extends({}, getOptionProps(this)), this.$attrs);
var columns = props.columns ? this.updateColumns(props.columns) : normalize(getSlot(this));
var title = props.title,
footer = props.footer;
var slotTitle = $slots.title,
slotFooter = $slots.footer,
_$slots$expandedRowRe = $slots.expandedRowRender,
expandedRowRender = _$slots$expandedRowRe === void 0 ? props.expandedRowRender : _$slots$expandedRowRe,
expandIcon = $slots.expandIcon;
title = title || slotTitle;
footer = footer || slotFooter;
var tProps = _extends(_extends({}, props), {
columns: columns,
title: title,
footer: footer,
expandedRowRender: expandedRowRender,
expandIcon: this.$props.expandIcon || expandIcon
});
return _createVNode(T, _objectSpread(_objectSpread({}, tProps), {}, {
"ref": "table"
}), null);
}
});
/* istanbul ignore next */
Table.install = function (app) {
app.component(Table.name, Table);
app.component(Table.Column.name, Table.Column);
app.component(Table.ColumnGroup.name, Table.ColumnGroup);
return app;
};
export default Table;