1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends4 = require('babel-runtime/helpers/extends');
var _extends5 = _interopRequireDefault(_extends4);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _vueTypes = require('../../_util/vue-types');
var _vueTypes2 = _interopRequireDefault(_vueTypes);
var _store = require('../../_util/store');
var _TableCell = require('./TableCell');
var _TableCell2 = _interopRequireDefault(_TableCell);
var _utils = require('./utils');
var _propsUtil = require('../../_util/props-util');
var _BaseMixin = require('../../_util/BaseMixin');
var _BaseMixin2 = _interopRequireDefault(_BaseMixin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function noop() {}
var TableRow = {
name: 'TableRow',
mixins: [_BaseMixin2['default']],
props: (0, _propsUtil.initDefaultProps)({
customRow: _vueTypes2['default'].func,
// onRowClick: PropTypes.func,
// onRowDoubleClick: PropTypes.func,
// onRowContextMenu: PropTypes.func,
// onRowMouseEnter: PropTypes.func,
// onRowMouseLeave: PropTypes.func,
record: _vueTypes2['default'].object,
prefixCls: _vueTypes2['default'].string,
// onHover: PropTypes.func,
columns: _vueTypes2['default'].array,
height: _vueTypes2['default'].oneOfType([_vueTypes2['default'].string, _vueTypes2['default'].number]),
index: _vueTypes2['default'].number,
rowKey: _vueTypes2['default'].oneOfType([_vueTypes2['default'].string, _vueTypes2['default'].number]).isRequired,
className: _vueTypes2['default'].string,
indent: _vueTypes2['default'].number,
indentSize: _vueTypes2['default'].number,
hasExpandIcon: _vueTypes2['default'].func,
hovered: _vueTypes2['default'].bool.isRequired,
visible: _vueTypes2['default'].bool.isRequired,
store: _vueTypes2['default'].object.isRequired,
fixed: _vueTypes2['default'].oneOfType([_vueTypes2['default'].string, _vueTypes2['default'].bool]),
renderExpandIcon: _vueTypes2['default'].func,
renderExpandIconCell: _vueTypes2['default'].func,
components: _vueTypes2['default'].any,
expandedRow: _vueTypes2['default'].bool,
isAnyColumnsFixed: _vueTypes2['default'].bool,
ancestorKeys: _vueTypes2['default'].array.isRequired,
expandIconColumnIndex: _vueTypes2['default'].number,
expandRowByClick: _vueTypes2['default'].bool
// visible: PropTypes.bool,
// hovered: PropTypes.bool,
// height: PropTypes.any,
}, {
// expandIconColumnIndex: 0,
// expandRowByClick: false,
hasExpandIcon: function hasExpandIcon() {},
renderExpandIcon: function renderExpandIcon() {},
renderExpandIconCell: function renderExpandIconCell() {}
}),
data: function data() {
// this.shouldRender = this.visible
return {
shouldRender: this.visible
};
},
mounted: function mounted() {
var _this = this;
if (this.shouldRender) {
this.$nextTick(function () {
_this.saveRowRef();
});
}
},
watch: {
visible: function visible(val) {
if (val) {
this.shouldRender = true;
}
}
},
updated: function updated() {
var _this2 = this;
if (this.shouldRender && !this.rowRef) {
this.$nextTick(function () {
_this2.saveRowRef();
});
}
},
methods: {
onRowClick: function onRowClick(event) {
var record = this.record,
index = this.index;
this.__emit('rowClick', record, index, event);
},
onRowDoubleClick: function onRowDoubleClick(event) {
var record = this.record,
index = this.index;
this.__emit('rowDoubleClick', record, index, event);
},
onContextMenu: function onContextMenu(event) {
var record = this.record,
index = this.index;
this.__emit('rowContextmenu', record, index, event);
},
onMouseEnter: function onMouseEnter(event) {
var record = this.record,
index = this.index,
rowKey = this.rowKey;
this.__emit('hover', true, rowKey);
this.__emit('rowMouseenter', record, index, event);
},
onMouseLeave: function onMouseLeave(event) {
var record = this.record,
index = this.index,
rowKey = this.rowKey;
this.__emit('hover', false, rowKey);
this.__emit('rowMouseleave', record, index, event);
},
setExpanedRowHeight: function setExpanedRowHeight() {
var store = this.store,
rowKey = this.rowKey;
var _store$getState = store.getState(),
expandedRowsHeight = _store$getState.expandedRowsHeight;
var height = this.rowRef.getBoundingClientRect().height;
expandedRowsHeight = (0, _extends5['default'])({}, expandedRowsHeight, (0, _defineProperty3['default'])({}, rowKey, height));
store.setState({ expandedRowsHeight: expandedRowsHeight });
},
setRowHeight: function setRowHeight() {
var store = this.store,
rowKey = this.rowKey;
var _store$getState2 = store.getState(),
fixedColumnsBodyRowsHeight = _store$getState2.fixedColumnsBodyRowsHeight;
var height = this.rowRef.getBoundingClientRect().height;
store.setState({
fixedColumnsBodyRowsHeight: (0, _extends5['default'])({}, fixedColumnsBodyRowsHeight, (0, _defineProperty3['default'])({}, rowKey, height))
});
},
getStyle: function getStyle() {
var height = this.height,
visible = this.visible;
var style = (0, _propsUtil.getStyle)(this);
if (height) {
style = (0, _extends5['default'])({}, style, { height: height });
}
if (!visible && !style.display) {
style = (0, _extends5['default'])({}, style, { display: 'none' });
}
return style;
},
saveRowRef: function saveRowRef() {
this.rowRef = this.$el;
var isAnyColumnsFixed = this.isAnyColumnsFixed,
fixed = this.fixed,
expandedRow = this.expandedRow,
ancestorKeys = this.ancestorKeys;
if (!isAnyColumnsFixed) {
return;
}
if (!fixed && expandedRow) {
this.setExpanedRowHeight();
}
if (!fixed && ancestorKeys.length >= 0) {
this.setRowHeight();
}
}
},
render: function render() {
var h = arguments[0];
if (!this.shouldRender) {
return null;
}
var prefixCls = this.prefixCls,
columns = this.columns,
record = this.record,
rowKey = this.rowKey,
index = this.index,
_customRow = this.customRow,
customRow = _customRow === undefined ? noop : _customRow,
indent = this.indent,
indentSize = this.indentSize,
hovered = this.hovered,
height = this.height,
visible = this.visible,
components = this.components,
hasExpandIcon = this.hasExpandIcon,
renderExpandIcon = this.renderExpandIcon,
renderExpandIconCell = this.renderExpandIconCell;
var BodyRow = components.body.row;
var BodyCell = components.body.cell;
var className = '';
if (hovered) {
className += ' ' + prefixCls + '-hover';
}
var cells = [];
renderExpandIconCell(cells);
for (var i = 0; i < columns.length; i++) {
var column = columns[i];
(0, _utils.warningOnce)(column.onCellClick === undefined, 'column[onCellClick] is deprecated, please use column[customCell] instead.');
cells.push(h(_TableCell2['default'], {
attrs: {
prefixCls: prefixCls,
record: record,
indentSize: indentSize,
indent: indent,
index: index,
column: column,
expandIcon: hasExpandIcon(i) && renderExpandIcon(),
component: BodyCell
},
key: column.key || column.dataIndex }));
}
var _ref = customRow(record, index) || {},
customClass = _ref['class'],
customClassName = _ref.className,
customStyle = _ref.style,
rowProps = (0, _objectWithoutProperties3['default'])(_ref, ['class', 'className', 'style']);
var style = { height: typeof height === 'number' ? height + 'px' : height };
if (!visible) {
style.display = 'none';
}
style = (0, _extends5['default'])({}, style, customStyle);
var rowClassName = (0, _classnames2['default'])(prefixCls, className, prefixCls + '-level-' + indent, customClassName, customClass);
var bodyRowProps = (0, _propsUtil.mergeProps)({
on: {
click: this.onRowClick,
dblclick: this.onRowDoubleClick,
mouseenter: this.onMouseEnter,
mouseleave: this.onMouseLeave,
contextmenu: this.onContextMenu
},
'class': rowClassName
}, (0, _extends5['default'])({}, rowProps, { style: style }), {
attrs: {
'data-row-key': rowKey
}
});
return h(
BodyRow,
bodyRowProps,
[cells]
);
}
};
function getRowHeight(state, props) {
var expandedRowsHeight = state.expandedRowsHeight,
fixedColumnsBodyRowsHeight = state.fixedColumnsBodyRowsHeight;
var fixed = props.fixed,
rowKey = props.rowKey;
if (!fixed) {
return null;
}
if (expandedRowsHeight[rowKey]) {
return expandedRowsHeight[rowKey];
}
if (fixedColumnsBodyRowsHeight[rowKey]) {
return fixedColumnsBodyRowsHeight[rowKey];
}
return null;
}
exports['default'] = (0, _store.connect)(function (state, props) {
var currentHoverKey = state.currentHoverKey,
expandedRowKeys = state.expandedRowKeys;
var rowKey = props.rowKey,
ancestorKeys = props.ancestorKeys;
var visible = ancestorKeys.length === 0 || ancestorKeys.every(function (k) {
return ~expandedRowKeys.indexOf(k);
});
return {
visible: visible,
hovered: currentHoverKey === rowKey,
height: getRowHeight(state, props)
};
})(TableRow);