shineout 1.10.1 → 1.10.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,8 @@ var _Scroll2 = require("../Scroll/Scroll");
41
41
 
42
42
  var _Colgroup = _interopRequireDefault(require("./Colgroup"));
43
43
 
44
+ var _emptyDom = _interopRequireDefault(require("./emptyDom"));
45
+
44
46
  var _Thead = _interopRequireDefault(require("./Thead"));
45
47
 
46
48
  var _Tbody = _interopRequireDefault(require("./Tbody"));
@@ -78,6 +80,7 @@ function (_PureComponent) {
78
80
  _this.handleScroll = _this.handleScroll.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
79
81
  _this.handleSortChange = _this.handleSortChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
80
82
  _this.scrollToTop = _this.scrollToTop.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
83
+ _this.getHeader = _this.getHeader.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
81
84
  _this.cachedRowHeight = [];
82
85
  _this.lastScrollArgs = {};
83
86
  _this.lastScrollTop = 0;
@@ -119,6 +122,11 @@ function (_PureComponent) {
119
122
  this.ajustBottom(dataChange);
120
123
  };
121
124
 
125
+ _proto.getHeader = function getHeader(_ref) {
126
+ var el = _ref.el;
127
+ this.headerEl = el;
128
+ };
129
+
122
130
  _proto.getIndex = function getIndex(scrollTop) {
123
131
  if (scrollTop === void 0) {
124
132
  scrollTop = this.state.scrollTop;
@@ -590,13 +598,15 @@ function (_PureComponent) {
590
598
 
591
599
  _proto.handleColgroup = function handleColgroup(tds) {
592
600
  var columns = this.props.columns;
601
+ var items = tds || this.headerEl && this.headerEl.querySelectorAll('th');
602
+ if (!items) return;
593
603
  var colgroup = [];
594
604
 
595
605
  var _loop = function _loop(i, count) {
596
- var _tds$i$getBoundingCli = tds[i].getBoundingClientRect(),
597
- width = _tds$i$getBoundingCli.width;
606
+ var _items$i$getBoundingC = items[i].getBoundingClientRect(),
607
+ width = _items$i$getBoundingC.width;
598
608
 
599
- var colSpan = parseInt(tds[i].getAttribute('colspan'), 10);
609
+ var colSpan = parseInt(items[i].getAttribute('colspan'), 10);
600
610
 
601
611
  if (colSpan > 1) {
602
612
  (0, _numbers.split)(width, (0, _numbers.range)(colSpan).map(function (j) {
@@ -609,7 +619,7 @@ function (_PureComponent) {
609
619
  }
610
620
  };
611
621
 
612
- for (var i = 0, count = tds.length; i < count; i++) {
622
+ for (var i = 0, count = items.length; i < count; i++) {
613
623
  _loop(i, count);
614
624
  }
615
625
 
@@ -645,7 +655,10 @@ function (_PureComponent) {
645
655
  });
646
656
 
647
657
  if (!data || data.length === 0) {
648
- return _react.default.createElement("div", null);
658
+ return _react.default.createElement(_emptyDom.default, {
659
+ onEmptyRender: this.handleColgroup,
660
+ columns: columns
661
+ });
649
662
  }
650
663
 
651
664
  var dataUpdated = this.lastData !== data; // Incorrect height due to changing data length dynamically
@@ -728,6 +741,7 @@ function (_PureComponent) {
728
741
  columns: columns,
729
742
  resizable: columnResizable && this.lastScrollArgs[4]
730
743
  }), _react.default.createElement(_Thead.default, (0, _extends2.default)({}, this.props, {
744
+ onHeaderRender: this.getHeader,
731
745
  colgroup: colgroup,
732
746
  onSortChange: this.handleSortChange,
733
747
  onColChange: onResize
@@ -59,6 +59,7 @@ function (_PureComponent) {
59
59
  _this.handleScroll = _this.handleScroll.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
60
60
  _this.handleColgroup = _this.handleColgroup.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
61
61
  _this.resetColGroup = _this.resetColGroup.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
62
+ _this.getHeader = _this.getHeader.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
62
63
  return _this;
63
64
  }
64
65
 
@@ -86,6 +87,11 @@ function (_PureComponent) {
86
87
  if (this.removeReiszeObserver) this.removeReiszeObserver();
87
88
  };
88
89
 
90
+ _proto.getHeader = function getHeader(_ref) {
91
+ var el = _ref.el;
92
+ this.headerEl = el;
93
+ };
94
+
89
95
  _proto.bindElement = function bindElement(key, el) {
90
96
  this[key] = el; // this.body will be undefined on componentDidMount when columns length is 0
91
97
 
@@ -125,14 +131,16 @@ function (_PureComponent) {
125
131
  };
126
132
 
127
133
  _proto.handleColgroup = function handleColgroup(tds) {
134
+ var items = tds || this.headerEl && this.headerEl.querySelectorAll('th');
135
+ if (!items) return;
128
136
  var columns = this.props.columns;
129
137
  var colgroup = [];
130
138
 
131
139
  var _loop = function _loop(i, count) {
132
- var _tds$i$getBoundingCli = tds[i].getBoundingClientRect(),
133
- width = _tds$i$getBoundingCli.width;
140
+ var _items$i$getBoundingC = items[i].getBoundingClientRect(),
141
+ width = _items$i$getBoundingC.width;
134
142
 
135
- var colSpan = parseInt(tds[i].getAttribute('colspan'), 10);
143
+ var colSpan = parseInt(items[i].getAttribute('colspan'), 10);
136
144
 
137
145
  if (colSpan > 1) {
138
146
  (0, _numbers.split)(width, (0, _numbers.range)(colSpan).map(function (j) {
@@ -145,7 +153,7 @@ function (_PureComponent) {
145
153
  }
146
154
  };
147
155
 
148
- for (var i = 0, count = tds.length; i < count; i++) {
156
+ for (var i = 0, count = items.length; i < count; i++) {
149
157
  _loop(i, count);
150
158
  }
151
159
 
@@ -155,8 +163,8 @@ function (_PureComponent) {
155
163
  });
156
164
  };
157
165
 
158
- _proto.handleScroll = function handleScroll(_ref) {
159
- var currentTarget = _ref.currentTarget;
166
+ _proto.handleScroll = function handleScroll(_ref2) {
167
+ var currentTarget = _ref2.currentTarget;
160
168
  var scrollLeft = currentTarget.scrollLeft;
161
169
  setScrollLeft(this.header, scrollLeft);
162
170
  setScrollLeft(this.body, scrollLeft);
@@ -185,6 +193,7 @@ function (_PureComponent) {
185
193
  columns: columns,
186
194
  resizable: columnResizable
187
195
  }), _react.default.createElement(_Thead.default, (0, _extends2.default)({}, this.props, {
196
+ onHeaderRender: this.getHeader,
188
197
  colgroup: colgroup,
189
198
  onSortChange: this.handleSortChange,
190
199
  onColChange: onResize
@@ -151,7 +151,7 @@ function (_Component) {
151
151
  columnResizable: columnResizable
152
152
  });
153
153
  var isEmpty = (!data || data.length === 0) && !children;
154
- var useSeparate = fixed && !isEmpty;
154
+ var useSeparate = fixed;
155
155
  var ResizeSepTable = columnResizable ? ResizeSeperateTable : _SeperateTable.default;
156
156
  var ResizeSimTable = columnResizable ? ResizeSimpleTable : _SimpleTable.default;
157
157
  var RenderTable = useSeparate ? ResizeSepTable : ResizeSimTable;
@@ -132,6 +132,8 @@ function (_PureComponent) {
132
132
  datum.unsubscribe(RENDER_COL_GROUP_EVENT, this.bodyRender);
133
133
 
134
134
  if (this.body.clientHeight === 0) {
135
+ this.colgroupSetted = true;
136
+ onBodyRender(null);
135
137
  datum.subscribe(RENDER_COL_GROUP_EVENT, this.bodyRender);
136
138
  return;
137
139
  }
@@ -46,11 +46,20 @@ function (_PureComponent) {
46
46
  _this.handleMouseDown = _this.handleResize.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), 'mousedown');
47
47
  _this.handleMouseMove = _this.handleResize.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), 'mousemove');
48
48
  _this.handleMouseUp = _this.handleResize.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), 'mouseup');
49
+ _this.bindHeader = _this.bindHeader.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
49
50
  return _this;
50
51
  }
51
52
 
52
53
  var _proto = Thead.prototype;
53
54
 
55
+ _proto.componentDidMount = function componentDidMount() {
56
+ var onHeaderRender = this.props.onHeaderRender;
57
+
58
+ if (onHeaderRender) {
59
+ onHeaderRender(this);
60
+ }
61
+ };
62
+
54
63
  _proto.setColumns = function setColumns(columns, col, level, index) {
55
64
  if (index === void 0) {
56
65
  index = 0;
@@ -95,6 +104,10 @@ function (_PureComponent) {
95
104
  return colSpan;
96
105
  };
97
106
 
107
+ _proto.bindHeader = function bindHeader(el) {
108
+ this.el = el;
109
+ };
110
+
98
111
  _proto.resizeColgroup = function resizeColgroup(deltaX) {
99
112
  var columns = this.props.columns;
100
113
  var item = columns[this.resizingIndex];
@@ -264,7 +277,9 @@ function (_PureComponent) {
264
277
 
265
278
  _proto.render = function render() {
266
279
  var trs = this.formatTrs();
267
- return _react.default.createElement("thead", null, trs.map(function (tr, i) {
280
+ return _react.default.createElement("thead", {
281
+ ref: this.bindHeader
282
+ }, trs.map(function (tr, i) {
268
283
  return _react.default.createElement("tr", {
269
284
  key: i
270
285
  }, tr);
@@ -288,7 +303,8 @@ Thead.propTypes = {
288
303
  treeColumnsName: _propTypes.default.string,
289
304
  treeCheckAll: _propTypes.default.bool,
290
305
  colgroup: _propTypes.default.array,
291
- renderSorter: _propTypes.default.func
306
+ renderSorter: _propTypes.default.func,
307
+ onHeaderRender: _propTypes.default.func
292
308
  };
293
309
  Thead.defaultProps = {
294
310
  showSelectAll: true
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+
8
+ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+
14
+ var _shallowEqual = require("shineout/utils/shallowEqual");
15
+
16
+ var EmptyDom =
17
+ /*#__PURE__*/
18
+ function (_React$PureComponent) {
19
+ (0, _inheritsLoose2.default)(EmptyDom, _React$PureComponent);
20
+
21
+ function EmptyDom() {
22
+ return _React$PureComponent.apply(this, arguments) || this;
23
+ }
24
+
25
+ var _proto = EmptyDom.prototype;
26
+
27
+ _proto.componentDidMount = function componentDidMount() {
28
+ if (this.props.onEmptyRender) {
29
+ this.props.onEmptyRender();
30
+ }
31
+ };
32
+
33
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
34
+ var _this = this;
35
+
36
+ if (!(0, _shallowEqual.compareColumns)(prevProps.columns, this.props.columns)) {
37
+ setTimeout(function () {
38
+ _this.props.onEmptyRender();
39
+ });
40
+ }
41
+ };
42
+
43
+ _proto.render = function render() {
44
+ return _react.default.createElement("div", null);
45
+ };
46
+
47
+ return EmptyDom;
48
+ }(_react.default.PureComponent);
49
+
50
+ EmptyDom.propTypes = {
51
+ onEmptyRender: _propTypes.default.func,
52
+ columns: _propTypes.default.any
53
+ };
54
+ var _default = EmptyDom;
55
+ exports.default = _default;
@@ -76,10 +76,19 @@ var _default = function _default(Table) {
76
76
  };
77
77
 
78
78
  _proto.handleResize = function handleResize(index, width, colgroup) {
79
+ if (colgroup === void 0) {
80
+ colgroup = [];
81
+ }
82
+
79
83
  var onColumnResize = this.props.onColumnResize;
80
84
  var changed = (0, _immer.default)(this.state, function (draft) {
81
85
  var column = draft.columns[index];
82
- draft.delta += parseFloat(width - (column.width || colgroup[index] || 0));
86
+ var beforeWidth = column.width || colgroup[index];
87
+
88
+ if (beforeWidth) {
89
+ draft.delta += parseFloat(width - beforeWidth);
90
+ }
91
+
83
92
  colgroup[index] = width;
84
93
  draft.columns.forEach(function (col, i) {
85
94
  var w = colgroup[i];
package/css/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Created by scripts/src-index.js.
2
2
  import * as utils from './utils'
3
3
 
4
- export default { utils, version: '1.10.1' }
4
+ export default { utils, version: '1.10.2-beta.1' }
5
5
  export { utils }
6
6
  export { setLocale } from './locale'
7
7
  export { color, style } from './utils/expose'
package/css/index.js CHANGED
@@ -224,6 +224,6 @@ exports.Upload = _Upload.default;
224
224
  // Created by scripts/src-index.js.
225
225
  var _default = {
226
226
  utils: utils,
227
- version: '1.10.1'
227
+ version: '1.10.2-beta.1'
228
228
  };
229
229
  exports.default = _default;