1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _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; };
|
8 |
|
9 | var _react = require("react");
|
10 |
|
11 | var _react2 = _interopRequireDefault(_react);
|
12 |
|
13 | var _reactDom = require("react-dom");
|
14 |
|
15 | var _reactDom2 = _interopRequireDefault(_reactDom);
|
16 |
|
17 | var _propTypes = require("prop-types");
|
18 |
|
19 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
20 |
|
21 | var _throttleDebounce = require("throttle-debounce");
|
22 |
|
23 | var _utils = require("./lib/utils");
|
24 |
|
25 | var _FilterType = require("./FilterType");
|
26 |
|
27 | var _FilterType2 = _interopRequireDefault(_FilterType);
|
28 |
|
29 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
30 |
|
31 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
32 |
|
33 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
34 |
|
35 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
36 |
|
37 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
|
38 |
|
39 | var propTypes = {
|
40 | clsPrefix: _propTypes2["default"].string,
|
41 | rowStyle: _propTypes2["default"].object,
|
42 | rows: _propTypes2["default"].array
|
43 | };
|
44 |
|
45 | function getDiv(id) {
|
46 | var div = document.createElement("div");
|
47 | div.className = "u-table-drag-hidden-cont";
|
48 | div.id = id;
|
49 | return div;
|
50 | }
|
51 |
|
52 | var TableHeader = function (_Component) {
|
53 | _inherits(TableHeader, _Component);
|
54 |
|
55 | function TableHeader(props) {
|
56 | _classCallCheck(this, TableHeader);
|
57 |
|
58 | var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
59 |
|
60 | _initialiseProps.call(_this);
|
61 |
|
62 | _this.currentObj = null;
|
63 | _this.theadKey = new Date().getTime();
|
64 | _this.drag = {
|
65 | option: ''
|
66 | };
|
67 | _this.minWidth = parseInt(props.minColumnWidth);
|
68 | _this.table = null;
|
69 | _this._thead = null;
|
70 | _this.event = false;
|
71 | _this.lastColumWidth = null;
|
72 | _this.fixedTable = {};
|
73 | return _this;
|
74 | }
|
75 |
|
76 | TableHeader.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
77 | var _this2 = this;
|
78 |
|
79 |
|
80 | var oldCols = this.props.columnsChildrenList;
|
81 | var newCols = nextProps.columnsChildrenList;
|
82 |
|
83 | if (this._thead) {
|
84 | if (newCols.length !== oldCols.length) {
|
85 | this.event = false;
|
86 | return;
|
87 | }
|
88 | oldCols.some(function (item, index) {
|
89 | if (newCols[index] && newCols[index].dataIndex !== item.dataIndex) {
|
90 | _this2.event = false;
|
91 | return true;
|
92 | }
|
93 | });
|
94 | }
|
95 | };
|
96 |
|
97 | TableHeader.prototype.componentDidUpdate = function componentDidUpdate() {
|
98 | this.initTable();
|
99 | this.initEvent();
|
100 | };
|
101 |
|
102 | TableHeader.prototype.componentDidMount = function componentDidMount() {
|
103 | var uid = "_table_uid_" + new Date().getTime();
|
104 | this._table_none_cont_id = uid;
|
105 | var div = getDiv(uid);
|
106 | document.querySelector("body").appendChild(div);
|
107 | };
|
108 |
|
109 | TableHeader.prototype.componentWillUnmount = function componentWillUnmount() {
|
110 | var _this3 = this;
|
111 |
|
112 | this.fixedTable = null;
|
113 | if (!this.table) return;
|
114 | if (this.props.draggable) {
|
115 | this.removeDragAbleEvent();
|
116 | }
|
117 | if (this.props.dragborder) {
|
118 | this.removeDragBorderEvent();
|
119 | }
|
120 | this.doEventList(this.table.tr, function (tr) {
|
121 | _this3.eventListen([{ key: 'mousedown', fun: _this3.onTrMouseDown }], 'remove', tr);
|
122 | });
|
123 |
|
124 | this.eventListen([{ key: 'mouseup', fun: this.bodyonLineMouseUp }], 'remove', document.body);
|
125 | };
|
126 |
|
127 | |
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | TableHeader.prototype.initTable = function initTable() {
|
135 | var contentTable = this.props.contentTable;
|
136 |
|
137 | if (!this.props.dragborder && !this.props.draggable) return;
|
138 | var tableDome = this._thead.parentNode;
|
139 | var table = {};
|
140 | if (tableDome && tableDome.nodeName && tableDome.nodeName.toUpperCase() == "TABLE") {
|
141 | table.table = tableDome;
|
142 | table.cols = tableDome.getElementsByTagName("col");
|
143 | table.ths = tableDome.getElementsByTagName("th");
|
144 | table.tr = tableDome.getElementsByTagName("tr");
|
145 | table.tableBody = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body');
|
146 | table.tableBodyCols = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body').getElementsByTagName("col");
|
147 | table.bodyRows = table.tableBody && table.tableBody.querySelectorAll('tr') || [];
|
148 |
|
149 | table.fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header');
|
150 | table.fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header');
|
151 | table.contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header');
|
152 | table.fixedLeftBodyTable = contentTable.querySelectorAll('.u-table-fixed-left .u-table-body-outer');
|
153 | if (table.fixedLeftBodyTable) {
|
154 | var leftBodyTableIndex = table.fixedLeftBodyTable.length - 1 < 0 ? 0 : table.fixedLeftBodyTable.length - 1;
|
155 | table.fixedLeftBodyTable = table.fixedLeftBodyTable[leftBodyTableIndex];
|
156 | }
|
157 |
|
158 | table.fixedRightBodyTable = contentTable.querySelectorAll('.u-table-fixed-right .u-table-body-outer');
|
159 | if (table.fixedRightBodyTable) {
|
160 | var rightBodyTableIndex = table.fixedRightBodyTable.length - 1 < 0 ? 0 : table.fixedRightBodyTable.length - 1;
|
161 | table.fixedRightBodyTable = table.fixedRightBodyTable[rightBodyTableIndex];
|
162 | }
|
163 |
|
164 | table.innerTableBody = contentTable.querySelector('.u-table-scroll .u-table-body table');
|
165 | table.fixedLeftBodyRows = table.fixedLeftBodyTable && table.fixedLeftBodyTable.querySelectorAll('tr') || [];
|
166 | table.fixedRightBodyRows = table.fixedRightBodyTable && table.fixedRightBodyTable.querySelectorAll('tr') || [];
|
167 | }
|
168 |
|
169 | this.table = table;
|
170 |
|
171 | if (!this.props.dragborder) return;
|
172 | if (document.getElementById("u-table-drag-thead-" + this.theadKey)) {
|
173 | this.fixedTable = {};
|
174 | var _fixedParentContext = document.getElementById("u-table-drag-thead-" + this.theadKey).parentNode;
|
175 | var siblingDom = _fixedParentContext.parentNode.nextElementSibling;
|
176 | if (siblingDom) {
|
177 | var fixedTable = siblingDom.querySelector("table");
|
178 | this.fixedTable.table = fixedTable;
|
179 | this.fixedTable.cols = fixedTable.getElementsByTagName("col");
|
180 |
|
181 | }
|
182 | }
|
183 | };
|
184 |
|
185 | |
186 |
|
187 |
|
188 |
|
189 |
|
190 | TableHeader.prototype.initEvent = function initEvent() {
|
191 | var _this4 = this;
|
192 |
|
193 | var _props = this.props,
|
194 | dragborder = _props.dragborder,
|
195 | draggable = _props.draggable,
|
196 | rows = _props.rows;
|
197 |
|
198 |
|
199 | if (Object.prototype.toString.call(rows) === '[object Array]' && rows.length === 0) {
|
200 | return;
|
201 | }
|
202 | if (!this.event) {
|
203 |
|
204 | this.event = true;
|
205 | if (dragborder) {
|
206 | this.dragBorderEventInit();
|
207 | }
|
208 | if (draggable) {
|
209 | this.dragAbleEventInit();
|
210 | }
|
211 | if (this.table && this.table.tr) {
|
212 |
|
213 | this.doEventList(this.table.tr, function (tr) {
|
214 | _this4.eventListen([{ key: 'mousedown', fun: _this4.onTrMouseDown }], '', tr);
|
215 | });
|
216 | }
|
217 | this.eventListen([{ key: 'mouseup', fun: this.bodyonLineMouseUp }], '', document.body);
|
218 | }
|
219 | };
|
220 |
|
221 | TableHeader.prototype.doEventList = function doEventList(trs, action) {
|
222 | for (var index = 0; index < trs.length; index++) {
|
223 | action(trs[index]);
|
224 | }
|
225 | };
|
226 |
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 | TableHeader.prototype.dragBorderEventInit = function dragBorderEventInit() {
|
233 | var _this5 = this;
|
234 |
|
235 | if (!this.props.dragborder) return;
|
236 | var events = [{ key: 'mouseup', fun: this.onTrMouseUp }, { key: 'mousemove', fun: this.onTrMouseMove }];
|
237 | this.doEventList(this.table.tr, function (tr) {
|
238 | _this5.eventListen(events, '', tr);
|
239 | });
|
240 |
|
241 | };
|
242 |
|
243 | |
244 |
|
245 |
|
246 |
|
247 |
|
248 | TableHeader.prototype.removeDragBorderEvent = function removeDragBorderEvent() {
|
249 | var _this6 = this;
|
250 |
|
251 | var events = [{ key: 'mouseup', fun: this.onTrMouseUp }, { key: 'mousemove', fun: this.onTrMouseMove }];
|
252 |
|
253 | this.doEventList(this.table.tr, function (tr) {
|
254 | _this6.eventListen(events, 'remove', _this6.table.tr);
|
255 | });
|
256 | };
|
257 |
|
258 | TableHeader.prototype.eventListen = function eventListen(events, type, eventSource) {
|
259 | if (!this.table) return;
|
260 | if (!eventSource) {
|
261 | console.log("Please set the attributes of column !");
|
262 | return;
|
263 | }
|
264 | var tr = this.table.tr;
|
265 |
|
266 | for (var i = 0; i < events.length; i++) {
|
267 | var _event = events[i];
|
268 | if (type === "remove") {
|
269 | _utils.EventUtil.removeHandler(eventSource, _event.key, _event.fun);
|
270 | } else {
|
271 | _utils.EventUtil.addHandler(eventSource, _event.key, _event.fun);
|
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 | TableHeader.prototype.mouseClear = function mouseClear() {
|
313 | if (!this.drag || !this.drag.option) return;
|
314 | var rows = this.props.rows;
|
315 |
|
316 | var data = { rows: rows[0], cols: this.table.cols, currIndex: this.drag.currIndex };
|
317 | this.props.afterDragColWidth && this.props.afterDragColWidth(data);
|
318 | this.drag = {
|
319 | option: ""
|
320 | };
|
321 | this.clearThsDr();
|
322 | };
|
323 |
|
324 | |
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 | |
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 | |
341 |
|
342 |
|
343 | TableHeader.prototype.dragAbleEventInit = function dragAbleEventInit() {
|
344 | if (!this.props.draggable) return;
|
345 | var events = [{ key: 'dragstart', fun: this.onDragStart },
|
346 | { key: 'dragover', fun: this.onDragOver },
|
347 | { key: 'drop', fun: this.onDrop },
|
348 |
|
349 | { key: 'dragenter', fun: this.onDragEnter }, { key: 'dragend', fun: this.onDragEnd }, { key: 'dragleave', fun: this.onDragLeave }];
|
350 | this.eventListen(events, '', this.table.tr[0]);
|
351 | };
|
352 |
|
353 | |
354 |
|
355 |
|
356 |
|
357 |
|
358 | TableHeader.prototype.removeDragAbleEvent = function removeDragAbleEvent() {
|
359 | var events = [{ key: 'dragstart', fun: this.onDragStart }, { key: 'dragover', fun: this.onDragOver }, { key: 'drop', fun: this.onDrop }, { key: 'dragenter', fun: this.onDragEnter }, { key: 'dragend', fun: this.onDragEnd }, { key: 'dragleave', fun: this.onDragLeave }];
|
360 | this.eventListen(events, 'remove', this.table.tr[0]);
|
361 | };
|
362 |
|
363 | |
364 |
|
365 |
|
366 |
|
367 |
|
368 | |
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 | |
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 | TableHeader.prototype.getCurrentEventData = function getCurrentEventData(th) {
|
381 | if (!th) {
|
382 | console.log(" event target is not th ! ");
|
383 | return null;
|
384 | }
|
385 | var key = th.getAttribute('data-line-key');
|
386 | var data = this.props.rows[0].find(function (da) {
|
387 | return da.key == key;
|
388 | });
|
389 | if (data) {
|
390 | return data;
|
391 | } else {
|
392 | console.log(" getCurrentEventData data is null ");
|
393 | return null;
|
394 | }
|
395 | };
|
396 |
|
397 | |
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 | TableHeader.prototype.getThDome = function getThDome(element) {
|
406 | var _tagName = element.tagName.toLowerCase();
|
407 | if (element.getAttribute('data-filter-type') === 'filterContext') return null;
|
408 | if (_tagName === 'i') return null;
|
409 | if (_tagName != 'th') {
|
410 | return this.getThDome(element.parentElement);
|
411 | } else {
|
412 | return element;
|
413 | }
|
414 | };
|
415 |
|
416 |
|
417 |
|
418 | |
419 |
|
420 |
|
421 |
|
422 |
|
423 | |
424 |
|
425 |
|
426 |
|
427 |
|
428 | |
429 |
|
430 |
|
431 |
|
432 |
|
433 | TableHeader.prototype.render = function render() {
|
434 | var _this7 = this;
|
435 |
|
436 | var _props2 = this.props,
|
437 | clsPrefix = _props2.clsPrefix,
|
438 | rowStyle = _props2.rowStyle,
|
439 | draggable = _props2.draggable,
|
440 | dragborder = _props2.dragborder,
|
441 | rows = _props2.rows,
|
442 | filterable = _props2.filterable,
|
443 | fixed = _props2.fixed,
|
444 | lastShowIndex = _props2.lastShowIndex,
|
445 | columnsChildrenList = _props2.columnsChildrenList;
|
446 |
|
447 | var attr = dragborder ? { id: "u-table-drag-thead-" + this.theadKey } : {};
|
448 | var lastObj = columnsChildrenList[columnsChildrenList.length - 1];
|
449 | return _react2["default"].createElement(
|
450 | "thead",
|
451 | _extends({ className: clsPrefix + "-thead" }, attr, { "data-theader-fixed": "scroll", ref: function ref(_thead) {
|
452 | return _this7._thead = _thead;
|
453 | } }),
|
454 | rows.map(function (row, index) {
|
455 | var _rowLeng = row.length - 1;
|
456 | return _react2["default"].createElement(
|
457 | "tr",
|
458 | { key: index, style: rowStyle, className: filterable && index == rows.length - 1 ? 'filterable' : '' },
|
459 | row.map(function (da, columIndex, arr) {
|
460 | da.children = da.required ? _react2["default"].createElement(
|
461 | "span",
|
462 | null,
|
463 | _react2["default"].createElement(
|
464 | "span",
|
465 | { className: "required" },
|
466 | "*"
|
467 | ),
|
468 | da.children
|
469 | ) : da.children;
|
470 | var thHover = da.drgHover ? " " + clsPrefix + "-thead th-drag-hover" : "";
|
471 | delete da.drgHover;
|
472 | var fixedStyle = "";
|
473 | var canDotDrag = "";
|
474 |
|
475 | if (!fixed && (da.fixed || filterable && index == rows.length - 1 && rows[0][columIndex].fixed)) {
|
476 | fixedStyle = " " + clsPrefix + "-row-fixed-columns-in-body";
|
477 | }
|
478 |
|
479 | if (lastShowIndex == columIndex) {
|
480 | canDotDrag = "th-can-not-drag";
|
481 | }
|
482 | var thClassName = "" + da.className ? "" + da.className : '';
|
483 | if (da.titleAlign) {
|
484 | thClassName += " text-" + da.titleAlign + " ";
|
485 | } else if (da.textAlign) {
|
486 | thClassName += " text-" + da.textAlign + " ";
|
487 | }
|
488 |
|
489 | delete da.textAlign;
|
490 | delete da.titleAlign;
|
491 | var keyTemp = {};
|
492 |
|
493 |
|
494 | keyTemp.key = da.key || da.dataindex || index + '-' + columIndex;
|
495 |
|
496 |
|
497 | if (filterable && index == rows.length - 1) {
|
498 | da.children = _this7.filterRenderType(da["filtertype"], da.dataindex, columIndex);
|
499 | if (da.key === undefined) {
|
500 | keyTemp.key = keyTemp.key + '-filterable';
|
501 | }
|
502 | delete da.filterdropdownfocus;
|
503 | }
|
504 |
|
505 | var thDefaultObj = {};
|
506 |
|
507 | if (draggable) {
|
508 | thClassName += " " + clsPrefix + "-thead th-drag " + thHover + " ";
|
509 | }
|
510 | if (dragborder) {
|
511 | thClassName += " " + clsPrefix + "-thead-th " + canDotDrag;
|
512 | }
|
513 | thClassName += " " + fixedStyle;
|
514 | if (!da.fixed) {
|
515 | return _react2["default"].createElement(
|
516 | "th",
|
517 | _extends({}, da, keyTemp, { className: thClassName, "data-th-fixed": da.fixed, "data-line-key": da.key,
|
518 | "data-line-index": columIndex, "data-th-width": da.width, "data-type": "draggable", onCopy: function onCopy(event) {
|
519 | _this7.onCopy(da, columIndex, event);
|
520 | } }),
|
521 | da.children,
|
522 |
|
523 |
|
524 | dragborder && lastObj && da.key != lastObj.key ? _react2["default"].createElement(
|
525 | "div",
|
526 | { ref: function ref(el) {
|
527 | return _this7.gap = el;
|
528 | }, "data-line-key": da.key,
|
529 | "data-line-index": columIndex, "data-th-width": da.width,
|
530 | "data-type": "online", className: clsPrefix + "-thead-th-drag-gap" },
|
531 | _react2["default"].createElement("div", { className: "online" })
|
532 | ) : ""
|
533 | );
|
534 | } else {
|
535 | thDefaultObj = _extends({}, da, {
|
536 | className: thClassName + " " + fixedStyle
|
537 | });
|
538 | da.onClick ? thDefaultObj.onClick = function (e) {
|
539 | da.onClick(da, e);
|
540 | } : "";
|
541 | return _react2["default"].createElement("th", _extends({}, thDefaultObj, keyTemp, { "data-th-fixed": da.fixed, style: { maxWidth: da.width }, onCopy: _this7.onCopy }));
|
542 | }
|
543 | })
|
544 | );
|
545 | })
|
546 | );
|
547 | };
|
548 |
|
549 | return TableHeader;
|
550 | }(_react.Component);
|
551 |
|
552 | TableHeader.defaultProps = {
|
553 | contentWidthDiff: 0
|
554 | };
|
555 |
|
556 | var _initialiseProps = function _initialiseProps() {
|
557 | var _this8 = this;
|
558 |
|
559 | this.getOnLineObject = function (_element) {
|
560 | var type = _element.getAttribute('data-type'),
|
561 | elementObj = null;
|
562 | if (!type) {
|
563 | var element = _element.parentElement || parentNode;
|
564 | if (element.getAttribute('data-type')) {
|
565 | elementObj = element;
|
566 | }
|
567 | } else {
|
568 | elementObj = _element;
|
569 | }
|
570 | return elementObj;
|
571 | };
|
572 |
|
573 | this.onTrMouseDown = function (e) {
|
574 | var eventNoStop = _this8.props.eventNoStop;
|
575 |
|
576 | !eventNoStop && _utils.Event.stopPropagation(e);
|
577 | var event = _utils.Event.getEvent(e),
|
578 | targetEvent = _utils.Event.getTarget(event);
|
579 | var _props3 = _this8.props,
|
580 | clsPrefix = _props3.clsPrefix,
|
581 | contentTable = _props3.contentTable,
|
582 | lastShowIndex = _props3.lastShowIndex,
|
583 | columnsChildrenList = _props3.columnsChildrenList;
|
584 |
|
585 |
|
586 | var currentElement = _this8.getTargetToType(targetEvent);
|
587 | if (!currentElement) return;
|
588 | var type = currentElement.getAttribute('data-type');
|
589 | if (!_this8.props.dragborder && !_this8.props.draggable) return;
|
590 | if (type == 'online' && _this8.props.dragborder) {
|
591 |
|
592 | targetEvent.setAttribute('draggable', false);
|
593 | var currentIndex = -1;
|
594 | var defaultWidth = currentElement.getAttribute("data-th-width");
|
595 | _this8.drag.option = "border";
|
596 | if (columnsChildrenList) {
|
597 | var columnKey = currentElement.getAttribute("data-line-key");
|
598 | if (columnKey) {
|
599 | currentIndex = columnsChildrenList.findIndex(function (da) {
|
600 | return (da.key && da.key.toLowerCase()) === columnKey.toLowerCase();
|
601 | });
|
602 | }
|
603 | }
|
604 | if (currentIndex < 0) {
|
605 | console.log('Key must be set for column!');
|
606 | return;
|
607 | }
|
608 | var currentObj = _this8.table.cols[currentIndex];
|
609 | _this8.drag.currIndex = currentIndex;
|
610 | _this8.drag.oldLeft = event.x;
|
611 | _this8.drag.oldWidth = parseInt(currentObj.style.width);
|
612 | _this8.drag.minWidth = currentObj.style.minWidth != "" ? parseInt(currentObj.style.minWidth) : defaultWidth;
|
613 | _this8.drag.tableWidth = parseInt(_this8.table.table.style.width ? _this8.table.table.style.width : _this8.table.table.scrollWidth);
|
614 | if (!_this8.tableOldWidth) {
|
615 | _this8.tableOldWidth = _this8.drag.tableWidth;
|
616 | }
|
617 | if (!_this8.lastColumWidth) {
|
618 | _this8.lastColumWidth = parseInt(_this8.table.cols[lastShowIndex].style.width);
|
619 | }
|
620 | } else if (type != 'online' && _this8.props.draggable) {
|
621 |
|
622 | if (!_this8.props.draggable) return;
|
623 | var th = _this8.getTargetToType(targetEvent);
|
624 | th.setAttribute('draggable', true);
|
625 | _this8.drag.option = 'dragAble';
|
626 | _this8.currentDome = th;
|
627 | var _currentIndex = parseInt(th.getAttribute("data-line-index"));
|
628 | _this8.drag.currIndex = _currentIndex;
|
629 | } else {
|
630 |
|
631 | return;
|
632 | }
|
633 | };
|
634 |
|
635 | this.getTableWidth = function () {
|
636 | var tableWidth = 0,
|
637 | offWidth = 0;
|
638 | for (var index = 0; index < _this8.table.cols.length; index++) {
|
639 | var da = _this8.table.cols[index];
|
640 | tableWidth += parseInt(da.style.width);
|
641 | }
|
642 | return tableWidth - offWidth;
|
643 | };
|
644 |
|
645 | this.getTargetToType = function (targetEvent) {
|
646 | var tag = targetEvent;
|
647 | if (targetEvent && !targetEvent.getAttribute("data-type")) {
|
648 | tag = _this8.getTargetToType(targetEvent.parentElement);
|
649 | }
|
650 | return tag;
|
651 | };
|
652 |
|
653 | this.getTargetToTh = function (targetEvent) {
|
654 | var th = targetEvent;
|
655 | if (targetEvent.nodeName.toUpperCase() != "TH") {
|
656 | th = _this8.getThDome(targetEvent);
|
657 | }
|
658 |
|
659 | return th;
|
660 | };
|
661 |
|
662 | this.onTrMouseMove = function (e) {
|
663 | if (!_this8.props.dragborder && !_this8.props.draggable) return;
|
664 | var _props4 = _this8.props,
|
665 | clsPrefix = _props4.clsPrefix,
|
666 | dragborder = _props4.dragborder,
|
667 | contentDomWidth = _props4.contentDomWidth,
|
668 | scrollbarWidth = _props4.scrollbarWidth,
|
669 | contentTable = _props4.contentTable,
|
670 | headerScroll = _props4.headerScroll,
|
671 | lastShowIndex = _props4.lastShowIndex,
|
672 | onDraggingBorder = _props4.onDraggingBorder,
|
673 | leftFixedWidth = _props4.leftFixedWidth,
|
674 | rightFixedWidth = _props4.rightFixedWidth,
|
675 | bodyDisplayInRow = _props4.bodyDisplayInRow,
|
676 | eventNoStop = _props4.eventNoStop;
|
677 |
|
678 | !eventNoStop && _utils.Event.stopPropagation(e);
|
679 | var event = _utils.Event.getEvent(e);
|
680 | if (_this8.props.dragborder && _this8.drag.option == "border") {
|
681 |
|
682 | var currentCols = _this8.table.cols[_this8.drag.currIndex];
|
683 | var diff = event.x - _this8.drag.oldLeft;
|
684 | var newWidth = _this8.drag.oldWidth + diff;
|
685 | _this8.drag.newWidth = newWidth > 0 ? newWidth : _this8.minWidth;
|
686 | if (newWidth > _this8.minWidth) {
|
687 | currentCols.style.width = newWidth + 'px';
|
688 |
|
689 |
|
690 | if (!bodyDisplayInRow) {
|
691 | _this8.table.bodyRows.forEach(function (row, index) {
|
692 | var leftRow = _this8.table.fixedLeftBodyRows[index];
|
693 | var rightRow = _this8.table.fixedRightBodyRows[index];
|
694 | if (leftRow || rightRow) {
|
695 | var height = row.getBoundingClientRect().height;
|
696 | leftRow && (leftRow.style.height = height + "px");
|
697 | rightRow && (rightRow.style.height = height + "px");
|
698 | }
|
699 | });
|
700 | }
|
701 |
|
702 |
|
703 | if (_this8.fixedTable.cols) {
|
704 | _this8.fixedTable.cols[_this8.drag.currIndex].style.width = newWidth + "px";
|
705 | }
|
706 |
|
707 | var newDiff = parseInt(currentCols.style.minWidth) - parseInt(currentCols.style.width);
|
708 | if (newDiff > 0) {
|
709 |
|
710 | var lastWidth = _this8.lastColumWidth + newDiff;
|
711 | _this8.table.cols[lastShowIndex].style.width = lastWidth + "px";
|
712 | _this8.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";
|
713 | }
|
714 | var showScroll = contentDomWidth - (leftFixedWidth + rightFixedWidth) - (_this8.drag.tableWidth + diff) - scrollbarWidth;
|
715 |
|
716 | if (headerScroll) {
|
717 | if (showScroll < 0) {
|
718 |
|
719 |
|
720 | _this8.table.contentTableHeader.style.overflowX = 'scroll';
|
721 | _this8.optTableMargin(_this8.table.fixedLeftHeaderTable, scrollbarWidth);
|
722 | _this8.optTableMargin(_this8.table.fixedRighHeadertTable, scrollbarWidth);
|
723 | } else {
|
724 |
|
725 | _this8.table.contentTableHeader.style.overflowX = 'hidden';
|
726 | _this8.optTableMargin(_this8.table.fixedLeftHeaderTable, 0);
|
727 | _this8.optTableMargin(_this8.table.fixedRighHeadertTable, 0);
|
728 | }
|
729 | } else {
|
730 | if (showScroll < 0) {
|
731 | _this8.table.tableBody.style.overflowX = 'auto';
|
732 | _this8.optTableMargin(_this8.table.fixedLeftBodyTable, '-' + scrollbarWidth);
|
733 | _this8.optTableMargin(_this8.table.fixedRightBodyTable, '-' + scrollbarWidth);
|
734 | _this8.optTableScroll(_this8.table.fixedLeftBodyTable, { x: 'scroll' });
|
735 | _this8.optTableScroll(_this8.table.fixedRightBodyTable, { x: 'scroll' });
|
736 | } else {
|
737 | _this8.table.tableBody.style.overflowX = 'hidden';
|
738 | _this8.optTableMargin(_this8.table.fixedLeftBodyTable, 0);
|
739 | _this8.optTableMargin(_this8.table.fixedRightBodyTable, 0);
|
740 | _this8.optTableScroll(_this8.table.fixedLeftBodyTable, { x: 'auto' });
|
741 | _this8.optTableScroll(_this8.table.fixedRightBodyTable, { x: 'auto' });
|
742 | }
|
743 | }
|
744 | } else {
|
745 | _this8.drag.newWidth = _this8.minWidth;
|
746 | }
|
747 | }
|
748 |
|
749 | _this8.drag.newWidth && onDraggingBorder && onDraggingBorder(event, _this8.drag.newWidth);
|
750 | };
|
751 |
|
752 | this.onTrMouseUp = function (e) {
|
753 | var event = _utils.Event.getEvent(e);
|
754 | var width = _this8.drag.newWidth;
|
755 | var opt = _this8.drag.option;
|
756 | _this8.mouseClear();
|
757 | if (opt !== "border") return;
|
758 | _this8.props.onDropBorder && _this8.props.onDropBorder(event, width);
|
759 | };
|
760 |
|
761 | this.clearThsDr = function () {
|
762 | var ths = _this8.table.ths;
|
763 | for (var index = 0; index < ths.length; index++) {
|
764 | ths[index].setAttribute('draggable', false);
|
765 | }
|
766 | };
|
767 |
|
768 | this.bodyonLineMouseUp = function (events, type) {
|
769 | if (!_this8.drag || !_this8.drag.option) return;
|
770 | _this8.mouseClear();
|
771 | };
|
772 |
|
773 | this.optTableMargin = function (table, scrollbarWidth) {
|
774 | if (table) {
|
775 | table.style.marginBottom = scrollbarWidth + "px";
|
776 | }
|
777 | };
|
778 |
|
779 | this.optTableScroll = function (table) {
|
780 | var overflow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
781 |
|
782 | if (table) {
|
783 | var innerTable = table.querySelector('.u-table-body-inner');
|
784 | if (innerTable) {
|
785 |
|
786 | overflow.x && (innerTable.style.overflowX = overflow.x);
|
787 | overflow.y && (innerTable.style.overflowY = overflow.y);
|
788 | }
|
789 | }
|
790 | };
|
791 |
|
792 | this.onDragStart = function (e) {
|
793 | if (!_this8.props.draggable) return;
|
794 | if (_this8.drag && _this8.drag.option != 'dragAble') {
|
795 | return;
|
796 | }
|
797 | var event = _utils.Event.getEvent(e),
|
798 |
|
799 |
|
800 | target = _this8.getTargetToTh(_utils.Event.getTarget(event));
|
801 | var currentIndex = parseInt(target.getAttribute("data-line-index"));
|
802 | var currentKey = target.getAttribute('data-line-key');
|
803 |
|
804 | if (event.dataTransfer.setDragImage) {
|
805 | var crt = target.cloneNode(true);
|
806 | crt.style.backgroundColor = "#ebecf0";
|
807 | crt.style.width = _this8.table.cols[currentIndex].style.width;
|
808 | crt.style.height = "40px";
|
809 |
|
810 |
|
811 | document.getElementById(_this8._table_none_cont_id).appendChild(crt);
|
812 | event.dataTransfer.setDragImage(crt, 0, 0);
|
813 | }
|
814 |
|
815 | event.dataTransfer.effectAllowed = "move";
|
816 | event.dataTransfer.setData("Text", currentKey);
|
817 | _this8.currentObj = _this8.props.rows[0][currentIndex];
|
818 | };
|
819 |
|
820 | this.onDragOver = function (e) {
|
821 | var event = _utils.Event.getEvent(e);
|
822 | event.preventDefault();
|
823 | };
|
824 |
|
825 | this.onDrop = function (e) {
|
826 | if (!_this8.props.draggable) return;
|
827 | var props = _this8.getCurrentEventData(_this8._dragCurrent);
|
828 | e.column = { props: props };
|
829 | if (_this8.drag && _this8.drag.option != 'dragAble') {
|
830 | _this8.props.onDrop(e);
|
831 | return;
|
832 | }
|
833 | var event = _utils.Event.getEvent(e),
|
834 | target = _utils.Event.getTarget(event);
|
835 | event.preventDefault();
|
836 | event.stopPropagation();
|
837 | _this8.currentDome.setAttribute('draggable', false);
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 | if (!_this8.props.onDrop) return;
|
844 |
|
845 | _this8.props.onDrop(event, { dragSource: _this8.currentObj, dragTarg: e.column });
|
846 | };
|
847 |
|
848 | this.onDragEnter = function (e) {
|
849 | var event = _utils.Event.getEvent(e),
|
850 | target = _utils.Event.getTarget(event);
|
851 | _this8._dragCurrent = target;
|
852 | var currentIndex = target.getAttribute("data-line-index");
|
853 | if (!currentIndex || parseInt(currentIndex) === _this8.drag.currIndex) return;
|
854 | if (target.nodeName.toUpperCase() === "TH") {
|
855 |
|
856 | target.setAttribute("style", "border-right:2px dashed rgb(30, 136, 229)");
|
857 |
|
858 | }
|
859 | };
|
860 |
|
861 | this.onDragEnd = function (e) {
|
862 | var event = _utils.Event.getEvent(e),
|
863 | target = _utils.Event.getTarget(event);
|
864 | _this8._dragCurrent.setAttribute("style", "");
|
865 | event.preventDefault();
|
866 | event.stopPropagation();
|
867 |
|
868 | document.getElementById(_this8._table_none_cont_id).innerHTML = "";
|
869 |
|
870 | var data = _this8.getCurrentEventData(_this8._dragCurrent);
|
871 | if (!data) return;
|
872 | if (!_this8.currentObj || _this8.currentObj.key == data.key) return;
|
873 | if (!_this8.props.onDragEnd) return;
|
874 | _this8.props.onDragEnd(event, { dragSource: _this8.currentObj, dragTarg: data });
|
875 | };
|
876 |
|
877 | this.onDragLeave = function (e) {
|
878 | var event = _utils.Event.getEvent(e),
|
879 | target = _utils.Event.getTarget(event);
|
880 | var currentIndex = target.getAttribute("data-line-index");
|
881 | if (!currentIndex || parseInt(currentIndex) === _this8.drag.currIndex) return;
|
882 | if (target.nodeName.toUpperCase() === "TH") {
|
883 | target.setAttribute("style", "");
|
884 |
|
885 | }
|
886 | };
|
887 |
|
888 | this.handlerFilterChange = function (key, value, condition) {
|
889 | var onFilterChange = _this8.props.onFilterChange;
|
890 |
|
891 | if (onFilterChange) {
|
892 | onFilterChange(key, value, condition);
|
893 | }
|
894 | };
|
895 |
|
896 | this.handlerFilterClear = function (field) {
|
897 | var onFilterClear = _this8.props.onFilterClear;
|
898 |
|
899 | if (onFilterClear) {
|
900 | onFilterClear(field);
|
901 | }
|
902 | };
|
903 |
|
904 | this.filterRenderType = function (type, dataIndex, index) {
|
905 | var _props5 = _this8.props,
|
906 | clsPrefix = _props5.clsPrefix,
|
907 | rows = _props5.rows,
|
908 | filterDelay = _props5.filterDelay,
|
909 | locale = _props5.locale;
|
910 |
|
911 | switch (type) {
|
912 |
|
913 | case "text":
|
914 | return _react2["default"].createElement(_FilterType2["default"], {
|
915 | locale: locale
|
916 | , rendertype: type
|
917 | , clsPrefix: clsPrefix
|
918 | , className: clsPrefix + " filter-text",
|
919 | dataIndex: dataIndex
|
920 | , onFilterChange: (0, _throttleDebounce.debounce)(filterDelay || 300, _this8.handlerFilterChange)
|
921 | , onFilterClear: _this8.handlerFilterClear
|
922 | , filterDropdown: rows[1][index]["filterdropdown"]
|
923 | , filterDropdownType: rows[1][index]["filterdropdowntype"]
|
924 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
925 | });
|
926 |
|
927 | case "number":
|
928 | return _react2["default"].createElement(_FilterType2["default"], {
|
929 | locale: locale,
|
930 | rendertype: type,
|
931 | clsPrefix: clsPrefix,
|
932 | className: clsPrefix + " filter-text",
|
933 | dataIndex: dataIndex
|
934 | , onFilterChange: (0, _throttleDebounce.debounce)(filterDelay || 300, _this8.handlerFilterChange)
|
935 | , onFilterClear: _this8.handlerFilterClear
|
936 | , filterDropdown: rows[1][index]["filterdropdown"],
|
937 | filterDropdownType: rows[1][index]["filterdropdowntype"]
|
938 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
939 | , filterInputNumberOptions: rows[1][index]["filterinputnumberoptions"]
|
940 | });
|
941 |
|
942 | case "dropdown":
|
943 | var selectDataSource = [];
|
944 |
|
945 | if (rows.length > 0 && (rows[1][index]["filterdropdownauto"] || "auto") == "auto") {
|
946 | var hash = {};
|
947 |
|
948 | selectDataSource = Array.from(rows[1][0].datasource, function (x) {
|
949 | return {
|
950 | key: x[dataIndex],
|
951 | value: x[dataIndex]
|
952 | };
|
953 | });
|
954 | selectDataSource = selectDataSource.reduceRight(function (item, next) {
|
955 | hash[next.key] ? "" : hash[next.key] = true && item.push(next);
|
956 | return item;
|
957 | }, []);
|
958 | } else {
|
959 |
|
960 | selectDataSource = rows[1][index]["filterdropdowndata"];
|
961 | }
|
962 | return _react2["default"].createElement(_FilterType2["default"], {
|
963 | locale: locale,
|
964 | rendertype: type,
|
965 | className: clsPrefix + " filter-dropdown",
|
966 | data: selectDataSource,
|
967 | notFoundContent: "Loading"
|
968 | , dataIndex: dataIndex
|
969 | , onFilterChange: _this8.handlerFilterChange
|
970 | , onFilterClear: _this8.handlerFilterClear
|
971 | , filterDropdown: rows[1][index]["filterdropdown"],
|
972 | onFocus: rows[1][index]["filterdropdownfocus"],
|
973 | filterDropdownType: rows[1][index]["filterdropdowntype"]
|
974 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
975 | });
|
976 |
|
977 | case "date":
|
978 | return _react2["default"].createElement(_FilterType2["default"], {
|
979 | locale: locale,
|
980 | rendertype: type,
|
981 | className: "filter-date",
|
982 | onClick: function onClick() {},
|
983 | format: rows[1][index]["format"] || "YYYY-MM-DD",
|
984 | dataIndex: dataIndex
|
985 | , onFilterChange: _this8.handlerFilterChange
|
986 | , onFilterClear: _this8.handlerFilterClear
|
987 | , filterDropdown: rows[1][index]["filterdropdown"],
|
988 | filterDropdownType: rows[1][index]["filterdropdowntype"]
|
989 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
990 | });
|
991 |
|
992 | case "dateyear":
|
993 | return _react2["default"].createElement(_FilterType2["default"], {
|
994 | locale: locale,
|
995 | rendertype: type,
|
996 | className: "filter-date",
|
997 | onClick: function onClick() {},
|
998 | format: rows[1][index]["format"] || "YYYY",
|
999 | dataIndex: dataIndex
|
1000 | , onFilterChange: _this8.handlerFilterChange
|
1001 | , onFilterClear: _this8.handlerFilterClear
|
1002 | , filterDropdown: rows[1][index]["filterdropdown"],
|
1003 | filterDropdownType: rows[1][index]["filterdropdowntype"]
|
1004 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
1005 | });
|
1006 |
|
1007 | case "datemonth":
|
1008 | return _react2["default"].createElement(_FilterType2["default"], {
|
1009 | locale: locale,
|
1010 | rendertype: type,
|
1011 | className: "filter-date",
|
1012 | onClick: function onClick() {},
|
1013 | format: rows[1][index]["format"] || "YYYY-MM",
|
1014 | dataIndex: dataIndex
|
1015 | , onFilterChange: _this8.handlerFilterChange
|
1016 | , onFilterClear: _this8.handlerFilterClear
|
1017 | , filterDropdown: rows[1][index]["filterdropdown"],
|
1018 | filterDropdownType: rows[1][index]["filterdropdowntype"]
|
1019 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
1020 | });
|
1021 |
|
1022 | case "dateweek":
|
1023 | return _react2["default"].createElement(_FilterType2["default"], {
|
1024 | locale: locale,
|
1025 | rendertype: type,
|
1026 | className: "filter-date",
|
1027 | onClick: function onClick() {},
|
1028 | format: rows[1][index]["format"] || "YYYY-Wo",
|
1029 | dataIndex: dataIndex
|
1030 | , onFilterChange: _this8.handlerFilterChange
|
1031 | , onFilterClear: _this8.handlerFilterClear
|
1032 | , filterDropdown: rows[1][index]["filterdropdown"],
|
1033 | filterDropdownType: rows[1][index]["filterdropdowntype"]
|
1034 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
1035 | });
|
1036 |
|
1037 | case "daterange":
|
1038 | return _react2["default"].createElement(_FilterType2["default"], {
|
1039 | locale: locale,
|
1040 | rendertype: type,
|
1041 | className: "filter-date",
|
1042 | onClick: function onClick() {},
|
1043 | format: rows[1][index]["format"] || "YYYY-MM-DD",
|
1044 | dataIndex: dataIndex
|
1045 | , onFilterChange: _this8.handlerFilterChange
|
1046 | , onFilterClear: _this8.handlerFilterClear
|
1047 | , filterDropdown: rows[1][index]["filterdropdown"],
|
1048 | filterDropdownType: rows[1][index]["filterdropdowntype"]
|
1049 | , filterDropdownIncludeKeys: rows[1][index]["filterdropdownincludekeys"]
|
1050 | });
|
1051 | default:
|
1052 |
|
1053 | return _react2["default"].createElement("div", null);
|
1054 | }
|
1055 | };
|
1056 |
|
1057 | this.onCopy = function (data, index, event) {
|
1058 | if (_this8.props.onCopy) {
|
1059 | _this8.props.onCopy(_extends(data, { col: index }), event);
|
1060 | }
|
1061 | };
|
1062 | };
|
1063 |
|
1064 | TableHeader.propTypes = propTypes;
|
1065 | exports["default"] = TableHeader;
|
1066 | module.exports = exports["default"]; |
\ | No newline at end of file |