@kdcloudjs/table 1.1.0 → 1.1.2

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.
@@ -143,6 +143,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
143
143
  _this.rootSubscription = new _rxjs.Subscription();
144
144
  _this.hasScrollY = false;
145
145
  _this.resizeSubject = new _rxjs.Subject();
146
+ _this.offsetY = 0;
146
147
 
147
148
  _this.getRowNodeListByEvent = function (e) {
148
149
  var nodeList = null;
@@ -208,6 +209,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
208
209
  className: (0, _classnames.default)(tableBodyClassName, 'empty')
209
210
  }, /*#__PURE__*/_react.default.createElement("div", {
210
211
  className: _styles.Classes.virtual,
212
+ tabIndex: -1,
211
213
  style: virtualStyle
212
214
  }, /*#__PURE__*/_react.default.createElement(_empty.EmptyHtmlTable, {
213
215
  descriptors: info.visible,
@@ -222,6 +224,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
222
224
  bottomBlank = _info$verticalRenderR.bottomBlank,
223
225
  topBlank = _info$verticalRenderR.topBlank,
224
226
  bottomIndex = _info$verticalRenderR.bottomIndex;
227
+ var stickyRightOffset = _this.hasScrollY ? _this.getScrollBarWidth() : 0;
225
228
  var renderBody = (0, _renderTemplates.default)('body');
226
229
 
227
230
  if (typeof renderBody === 'function') {
@@ -230,7 +233,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
230
233
  onMouseEnter: _this.handleRowMouseEnter,
231
234
  onMouseLeave: _this.handleRowMouseLeave
232
235
  },
233
- hasScrollY: _this.hasScrollY
236
+ stickyRightOffset: stickyRightOffset
234
237
  });
235
238
  }
236
239
 
@@ -238,6 +241,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
238
241
  className: tableBodyClassName
239
242
  }, /*#__PURE__*/_react.default.createElement("div", {
240
243
  className: _styles.Classes.virtual,
244
+ tabIndex: -1,
241
245
  style: virtualStyle
242
246
  }, topBlank > 0 && /*#__PURE__*/_react.default.createElement("div", {
243
247
  key: "top-blank",
@@ -250,7 +254,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
250
254
  getRowProps: getRowProps,
251
255
  primaryKey: primaryKey,
252
256
  data: (0, _slice.default)(dataSource).call(dataSource, topIndex, bottomIndex),
253
- hasScrollY: _this.hasScrollY,
257
+ stickyRightOffset: stickyRightOffset,
254
258
  horizontalRenderInfo: info,
255
259
  verticalRenderInfo: {
256
260
  first: 0,
@@ -312,7 +316,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
312
316
  var innerTableWidth = tableBodyHtmlTable.offsetWidth;
313
317
  var artTableWidth = artTable.offsetWidth;
314
318
  var stickyScrollHeightProp = this.props.stickyScrollHeight;
315
- var stickyScrollHeight = stickyScrollHeightProp === 'auto' ? (0, _utils.getScrollbarSize)().height : stickyScrollHeightProp; // stickyScroll.style.marginTop = `-${stickyScrollHeight + 1}px`
319
+ var stickyScrollHeight = stickyScrollHeightProp === 'auto' ? this.getScrollBarWidth() : stickyScrollHeightProp; // stickyScroll.style.marginTop = `-${stickyScrollHeight + 1}px`
316
320
  // 设置滚动条高度
317
321
 
318
322
  stickyScroll.style.height = "".concat(stickyScrollHeight, "px");
@@ -377,7 +381,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
377
381
  }), /*#__PURE__*/_react.default.createElement("div", {
378
382
  className: _styles.Classes.verticalScrollPlaceholder,
379
383
  style: this.hasScrollY ? {
380
- width: (0, _utils.getScrollbarSize)().width
384
+ width: this.getScrollBarWidth()
381
385
  } : undefined
382
386
  }));
383
387
  }
@@ -484,7 +488,7 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
484
488
  }), /*#__PURE__*/_react.default.createElement("div", {
485
489
  className: _styles.Classes.verticalScrollPlaceholder,
486
490
  style: this.hasScrollY ? {
487
- width: (0, _utils.getScrollbarSize)().width,
491
+ width: this.getScrollBarWidth(),
488
492
  visibility: 'initial'
489
493
  } : undefined
490
494
  }));
@@ -529,6 +533,11 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
529
533
  className: _styles.Classes.stickyScrollItem
530
534
  }));
531
535
  }
536
+ }, {
537
+ key: "getScrollBarWidth",
538
+ value: function getScrollBarWidth() {
539
+ return this.props.scrollbarWidth || (0, _utils.getScrollbarSize)().width;
540
+ }
532
541
  }, {
533
542
  key: "render",
534
543
  value: function render() {
@@ -701,6 +710,47 @@ var BaseTable = /*#__PURE__*/function (_React$Component) {
701
710
  })).subscribe(function (sizeAndOffset) {
702
711
  _this2.setState(sizeAndOffset);
703
712
  }));
713
+ this.rootSubscription.add(richVisibleRects$.pipe(op.map(function (_ref7) {
714
+ var clipRect = _ref7.clipRect,
715
+ offsetY = _ref7.offsetY;
716
+ return {
717
+ maxRenderHeight: clipRect.bottom - clipRect.top,
718
+ maxRenderWidth: clipRect.right - clipRect.left,
719
+ offsetY: offsetY
720
+ };
721
+ }), op.distinctUntilChanged(function (x, y) {
722
+ return x.offsetY - y.offsetY === 0;
723
+ }), // 计算得到当前行索引对应的数据块,blocks改成数组的形式,兼容快速拖动可视区域出现两个数据块的情况
724
+ op.map(function (sizeAndOffset) {
725
+ var _a;
726
+
727
+ var offsetY = sizeAndOffset.offsetY,
728
+ maxRenderHeight = sizeAndOffset.maxRenderHeight;
729
+ var scrollDirection = offsetY - _this2.offsetY >= 0 ? 'down' : 'up';
730
+ _this2.offsetY = offsetY;
731
+ var rowCount = _this2.props.dataSource.length;
732
+
733
+ var vertical = _this2.rowHeightManager.getRenderRange(offsetY, maxRenderHeight, rowCount);
734
+
735
+ var topIndex = vertical.topIndex,
736
+ bottomIndex = vertical.bottomIndex;
737
+ var blockSize = ((_a = _this2.props.scrollLoad) === null || _a === void 0 ? void 0 : _a.blockSize) || 200;
738
+ var topBlockStartIndex = Math.floor(Math.max(topIndex - 1, 0) / blockSize) * blockSize;
739
+ var bottomBlockStartIndex = Math.floor((bottomIndex + 1) / blockSize) * blockSize;
740
+ return scrollDirection === 'down' ? [topBlockStartIndex, bottomBlockStartIndex] : [bottomBlockStartIndex, topBlockStartIndex];
741
+ }), op.distinctUntilChanged(function (x, y) {
742
+ return x[0] === y[0] && x[1] === y[1];
743
+ }), op.switchMap(function (startIndexs) {
744
+ var event$ = (0, _rxjs.from)(startIndexs);
745
+ return event$.pipe(op.map(function (startIndex) {
746
+ return startIndex;
747
+ }));
748
+ }), // 过滤掉重复掉值
749
+ op.distinctUntilChanged()).subscribe(function (startIndex) {
750
+ var _a;
751
+
752
+ (_a = _this2.props.scrollLoad) === null || _a === void 0 ? void 0 : _a.callback(startIndex);
753
+ }));
704
754
  }
705
755
  }, {
706
756
  key: "componentWillUnmount",
@@ -60,8 +60,8 @@ function FilterPanel(_ref) {
60
60
 
61
61
  var _useState3 = (0, _react.useState)(false),
62
62
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
63
- opaque = _useState4[0],
64
- setOpaque = _useState4[1];
63
+ visible = _useState4[0],
64
+ setVisible = _useState4[1];
65
65
 
66
66
  var ref = _react.default.useRef(null);
67
67
 
@@ -71,16 +71,16 @@ function FilterPanel(_ref) {
71
71
 
72
72
  (0, _react.useEffect)(function () {
73
73
  setPerfectPosition((0, _utils.keepWithinBounds)(document.body, ref.current, position.x, position.y, true));
74
- setOpaque(true);
74
+ setVisible(true);
75
75
  }, [position]);
76
76
  useWindowEvents(function (e) {
77
77
  return !isContainPanel(e) && onClose();
78
78
  }, ['mousedown']);
79
79
  return /*#__PURE__*/_react.default.createElement(FilterPanelStyle, {
80
80
  style: (0, _extends2.default)((0, _extends2.default)({}, style), {
81
- left: perfectPosition.x,
82
- top: perfectPosition.y,
83
- opacity: opaque ? 1 : 0
81
+ left: visible ? perfectPosition.x : 0,
82
+ top: visible ? perfectPosition.y : 0,
83
+ opacity: visible ? 1 : 0
84
84
  }),
85
85
  ref: ref
86
86
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -153,6 +153,8 @@ function rangeSelection(opts) {
153
153
  };
154
154
 
155
155
  var onKeyDown = function onKeyDown(e) {
156
+ if (!(0, _utils.isElementInEventPath)(tableBody, e.nativeEvent)) return;
157
+
156
158
  if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
157
159
  var rowLen = pipeline.getDataSource().length;
158
160
 
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  /** elementUtil html元素用的工具函数 */
3
- export declare function getEventPath(event: MouseEvent | React.MouseEvent<HTMLTableElement, MouseEvent>): any;
3
+ export declare function getEventPath(event: MouseEvent | React.MouseEvent<HTMLTableElement, MouseEvent> | KeyboardEvent): any;
4
4
  /**
5
5
  * 获取点击事件是否发生在元素内部
6
6
  * @param ele
7
7
  * @param event
8
8
  */
9
- export declare function isElementInEventPath(ele?: HTMLElement, event?: MouseEvent): boolean;
9
+ export declare function isElementInEventPath(ele?: HTMLElement, event?: MouseEvent | KeyboardEvent): boolean;
10
10
  /**
11
11
  * 根据点击路径获取对应元素
12
12
  * @param path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdcloudjs/table",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "金蝶 react table 组件",
5
5
  "title": "table",
6
6
  "keywords": [