@bit-sun/business-component 2.2.43 → 2.2.44

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.
@@ -0,0 +1,8 @@
1
+ interface TableSticky {
2
+ getContainer?: () => Window | HTMLElement;
3
+ }
4
+ declare const useSticky: (sticky: boolean | TableSticky) => {
5
+ isSticky: boolean;
6
+ container: Window | HTMLElement | Document;
7
+ };
8
+ export default useSticky;
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import { message, Menu, Space, Dropdown, Tooltip, Button, Checkbox, Input, Modal, Select, Form, Divider, Spin, Table, TreeSelect, Tag, Popover, Card, Avatar, Image, InputNumber, Typography, Alert, Anchor, Breadcrumb, Drawer as Drawer$1, List, Tree, Row, Col, Tabs, Affix } from 'antd';
3
- import _, { omit, debounce, cloneDeep as cloneDeep$1, isEmpty } from 'lodash';
3
+ import _, { omit, debounce, cloneDeep as cloneDeep$1, throttle, isEmpty } from 'lodash';
4
4
  import React, { useState, useEffect, forwardRef, useImperativeHandle, useRef, useMemo, Component, useLayoutEffect, createRef } from 'react';
5
5
  import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
6
6
  import { UnorderedListOutlined, ProfileTwoTone, ExclamationCircleOutlined, DownOutlined, CopyOutlined, SearchOutlined, CaretLeftOutlined, CloseCircleOutlined, ArrowLeftOutlined, FolderOutlined, EllipsisOutlined, CaretDownOutlined, HomeOutlined, DoubleLeftOutlined, DoubleRightOutlined, MenuUnfoldOutlined, DashOutlined, SettingOutlined, BulbOutlined, PlayCircleOutlined, SaveOutlined, FullscreenExitOutlined } from '@ant-design/icons';
@@ -22435,13 +22435,25 @@ var headersToRows = function headersToRows(originColumns) {
22435
22435
  var css_248z$n = ".editTableWrapper {\n width: 1000px;\n height: 500px;\n overflow: auto;\n position: relative;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n.editTableWrapper table {\n table-layout: fixed;\n}\n.editTableWrapper .editTable {\n position: relative;\n overflow: hidden;\n border-top: 0;\n background: #fff;\n}\n.editTableWrapper .north__west {\n position: sticky;\n background-color: #f7f8fb;\n left: 0px;\n top: 0px;\n font-size: 14px;\n color: #606266;\n z-index: 5;\n}\n.editTableWrapper .north__west th {\n background: #fff;\n font-size: 14px;\n color: #606266;\n z-index: 5;\n}\n.editTableWrapper .south__west {\n z-index: 4;\n position: absolute;\n left: 0px;\n top: 0;\n}\n.editTableWrapper .south__west th {\n background: #fff;\n font-size: 14px;\n color: #606266;\n z-index: 4;\n}\n.editTableWrapper .south__west td {\n font-size: 12px;\n background: #fff;\n color: #6a6a6a;\n}\n.editTableWrapper .south__west td svg {\n width: 20px;\n height: 20px;\n vertical-align: middle;\n}\n.editTableWrapper .editTable__block {\n -webkit-user-select: none;\n -moz-user-select: none;\n user-select: none;\n position: absolute;\n border-collapse: collapse;\n padding: 0;\n}\n.editTableWrapper .editTable__block th,\n.editTableWrapper .editTable__block td {\n box-sizing: border-box;\n font-size: 11px;\n color: #6a6a6a;\n}\n.editTableWrapper .value_table table {\n table-layout: fixed;\n min-width: 100%;\n}\n.editTableWrapper .table_border_style {\n border-collapse: separate;\n border-spacing: 0;\n border-left: 1px solid #f0f0f0;\n border-top: 1px solid #f0f0f0;\n}\n.editTableWrapper .table_border_style td {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n box-sizing: border-box;\n border-right: 1px solid #f0f0f0;\n border-bottom: 1px solid #f0f0f0;\n padding: 0 10px;\n font-size: 14px;\n line-height: 28px;\n}\n";
22436
22436
  styleInject(css_248z$n);
22437
22437
 
22438
+ var useSticky = function useSticky(sticky) {
22439
+ var _ref = _typeof(sticky) === 'object' ? sticky : {},
22440
+ _ref$getContainer = _ref.getContainer,
22441
+ getContainer = _ref$getContainer === void 0 ? function () {
22442
+ return window.document;
22443
+ } : _ref$getContainer;
22444
+ var container = getContainer();
22445
+ return React.useMemo(function () {
22446
+ var isSticky = !!sticky;
22447
+ return {
22448
+ isSticky: isSticky,
22449
+ container: container
22450
+ };
22451
+ }, [sticky]);
22452
+ };
22453
+
22438
22454
  function getOffset(node) {
22439
22455
  var box = node.getBoundingClientRect();
22440
22456
  var docElem = document.documentElement;
22441
- console.log(box, 'box', {
22442
- left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
22443
- top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
22444
- });
22445
22457
  // < ie8 不支持 win.pageXOffset, 则使用 docElem.scrollLeft
22446
22458
  return {
22447
22459
  left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
@@ -22449,11 +22461,14 @@ function getOffset(node) {
22449
22461
  };
22450
22462
  }
22451
22463
  var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22452
- var _viewPort$current;
22464
+ var _viewPort$current, _viewPort$current2;
22453
22465
  var viewPort = _ref.viewPort,
22454
- width = _ref.width;
22466
+ stickyProps = _ref.stickyProps;
22467
+ var _useSticky = useSticky(stickyProps),
22468
+ isSticky = _useSticky.isSticky,
22469
+ container = _useSticky.container;
22455
22470
  var _useState = useState({
22456
- isHiddenScrollBar: false
22471
+ isHiddenScrollBar: !isSticky
22457
22472
  }),
22458
22473
  _useState2 = _slicedToArray(_useState, 2),
22459
22474
  scrollState = _useState2[0],
@@ -22482,9 +22497,10 @@ var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22482
22497
  }
22483
22498
  };
22484
22499
  useEffect(function () {
22485
- document.addEventListener('scroll', onContainerScroll);
22500
+ var onscroll = throttle(onContainerScroll, 50);
22501
+ container.addEventListener('scroll', onscroll);
22486
22502
  return function () {
22487
- document.removeEventListener('scroll', onContainerScroll);
22503
+ container.removeEventListener('scroll', onscroll);
22488
22504
  };
22489
22505
  }, []);
22490
22506
  if (scrollState.isHiddenScrollBar) {
@@ -22492,10 +22508,10 @@ var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22492
22508
  }
22493
22509
  return /*#__PURE__*/React.createElement("div", {
22494
22510
  ref: ref,
22495
- onScroll: function onScroll(e) {
22511
+ onScroll: throttle(function (e) {
22496
22512
  // @ts-ignore
22497
22513
  viewPort.current.scrollTo(e.target.scrollLeft, 0);
22498
- },
22514
+ }, 50),
22499
22515
  style: {
22500
22516
  position: 'fixed',
22501
22517
  zIndex: '9999',
@@ -22511,7 +22527,7 @@ var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22511
22527
  style: {
22512
22528
  height: '1px',
22513
22529
  backgroundColor: '#fff',
22514
- width: width
22530
+ width: ((_viewPort$current2 = viewPort.current) === null || _viewPort$current2 === void 0 ? void 0 : _viewPort$current2.scrollWidth) || 0
22515
22531
  }
22516
22532
  }));
22517
22533
  };
@@ -22672,9 +22688,9 @@ var index$7 = /*#__PURE__*/forwardRef(function (props, ref) {
22672
22688
  className: 'editTableWrapper',
22673
22689
  onScroll: onScroll,
22674
22690
  ref: viewPort
22675
- }, (tableProps === null || tableProps === void 0 ? void 0 : tableProps.sticky) && /*#__PURE__*/React.createElement(FixedScrollBar$1, {
22691
+ }, /*#__PURE__*/React.createElement(FixedScrollBar$1, {
22692
+ stickyProps: tableProps === null || tableProps === void 0 ? void 0 : tableProps.sticky,
22676
22693
  viewPort: viewPort,
22677
- width: "".concat(config.colHeaderWidth + 1 + placeholderWidth, "px"),
22678
22694
  ref: topScrollBar
22679
22695
  }), /*#__PURE__*/React.createElement("div", {
22680
22696
  style: {
package/dist/index.js CHANGED
@@ -22453,13 +22453,25 @@ var headersToRows = function headersToRows(originColumns) {
22453
22453
  var css_248z$n = ".editTableWrapper {\n width: 1000px;\n height: 500px;\n overflow: auto;\n position: relative;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n.editTableWrapper table {\n table-layout: fixed;\n}\n.editTableWrapper .editTable {\n position: relative;\n overflow: hidden;\n border-top: 0;\n background: #fff;\n}\n.editTableWrapper .north__west {\n position: sticky;\n background-color: #f7f8fb;\n left: 0px;\n top: 0px;\n font-size: 14px;\n color: #606266;\n z-index: 5;\n}\n.editTableWrapper .north__west th {\n background: #fff;\n font-size: 14px;\n color: #606266;\n z-index: 5;\n}\n.editTableWrapper .south__west {\n z-index: 4;\n position: absolute;\n left: 0px;\n top: 0;\n}\n.editTableWrapper .south__west th {\n background: #fff;\n font-size: 14px;\n color: #606266;\n z-index: 4;\n}\n.editTableWrapper .south__west td {\n font-size: 12px;\n background: #fff;\n color: #6a6a6a;\n}\n.editTableWrapper .south__west td svg {\n width: 20px;\n height: 20px;\n vertical-align: middle;\n}\n.editTableWrapper .editTable__block {\n -webkit-user-select: none;\n -moz-user-select: none;\n user-select: none;\n position: absolute;\n border-collapse: collapse;\n padding: 0;\n}\n.editTableWrapper .editTable__block th,\n.editTableWrapper .editTable__block td {\n box-sizing: border-box;\n font-size: 11px;\n color: #6a6a6a;\n}\n.editTableWrapper .value_table table {\n table-layout: fixed;\n min-width: 100%;\n}\n.editTableWrapper .table_border_style {\n border-collapse: separate;\n border-spacing: 0;\n border-left: 1px solid #f0f0f0;\n border-top: 1px solid #f0f0f0;\n}\n.editTableWrapper .table_border_style td {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n box-sizing: border-box;\n border-right: 1px solid #f0f0f0;\n border-bottom: 1px solid #f0f0f0;\n padding: 0 10px;\n font-size: 14px;\n line-height: 28px;\n}\n";
22454
22454
  styleInject(css_248z$n);
22455
22455
 
22456
+ var useSticky = function useSticky(sticky) {
22457
+ var _ref = _typeof(sticky) === 'object' ? sticky : {},
22458
+ _ref$getContainer = _ref.getContainer,
22459
+ getContainer = _ref$getContainer === void 0 ? function () {
22460
+ return window.document;
22461
+ } : _ref$getContainer;
22462
+ var container = getContainer();
22463
+ return React__default['default'].useMemo(function () {
22464
+ var isSticky = !!sticky;
22465
+ return {
22466
+ isSticky: isSticky,
22467
+ container: container
22468
+ };
22469
+ }, [sticky]);
22470
+ };
22471
+
22456
22472
  function getOffset(node) {
22457
22473
  var box = node.getBoundingClientRect();
22458
22474
  var docElem = document.documentElement;
22459
- console.log(box, 'box', {
22460
- left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
22461
- top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
22462
- });
22463
22475
  // < ie8 不支持 win.pageXOffset, 则使用 docElem.scrollLeft
22464
22476
  return {
22465
22477
  left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
@@ -22467,11 +22479,14 @@ function getOffset(node) {
22467
22479
  };
22468
22480
  }
22469
22481
  var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22470
- var _viewPort$current;
22482
+ var _viewPort$current, _viewPort$current2;
22471
22483
  var viewPort = _ref.viewPort,
22472
- width = _ref.width;
22484
+ stickyProps = _ref.stickyProps;
22485
+ var _useSticky = useSticky(stickyProps),
22486
+ isSticky = _useSticky.isSticky,
22487
+ container = _useSticky.container;
22473
22488
  var _useState = React.useState({
22474
- isHiddenScrollBar: false
22489
+ isHiddenScrollBar: !isSticky
22475
22490
  }),
22476
22491
  _useState2 = _slicedToArray(_useState, 2),
22477
22492
  scrollState = _useState2[0],
@@ -22500,9 +22515,10 @@ var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22500
22515
  }
22501
22516
  };
22502
22517
  React.useEffect(function () {
22503
- document.addEventListener('scroll', onContainerScroll);
22518
+ var onscroll = _.throttle(onContainerScroll, 50);
22519
+ container.addEventListener('scroll', onscroll);
22504
22520
  return function () {
22505
- document.removeEventListener('scroll', onContainerScroll);
22521
+ container.removeEventListener('scroll', onscroll);
22506
22522
  };
22507
22523
  }, []);
22508
22524
  if (scrollState.isHiddenScrollBar) {
@@ -22510,10 +22526,10 @@ var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22510
22526
  }
22511
22527
  return /*#__PURE__*/React__default['default'].createElement("div", {
22512
22528
  ref: ref,
22513
- onScroll: function onScroll(e) {
22529
+ onScroll: _.throttle(function (e) {
22514
22530
  // @ts-ignore
22515
22531
  viewPort.current.scrollTo(e.target.scrollLeft, 0);
22516
- },
22532
+ }, 50),
22517
22533
  style: {
22518
22534
  position: 'fixed',
22519
22535
  zIndex: '9999',
@@ -22529,7 +22545,7 @@ var FixedScrollBar = function FixedScrollBar(_ref, ref) {
22529
22545
  style: {
22530
22546
  height: '1px',
22531
22547
  backgroundColor: '#fff',
22532
- width: width
22548
+ width: ((_viewPort$current2 = viewPort.current) === null || _viewPort$current2 === void 0 ? void 0 : _viewPort$current2.scrollWidth) || 0
22533
22549
  }
22534
22550
  }));
22535
22551
  };
@@ -22690,9 +22706,9 @@ var index$7 = /*#__PURE__*/React.forwardRef(function (props, ref) {
22690
22706
  className: 'editTableWrapper',
22691
22707
  onScroll: onScroll,
22692
22708
  ref: viewPort
22693
- }, (tableProps === null || tableProps === void 0 ? void 0 : tableProps.sticky) && /*#__PURE__*/React__default['default'].createElement(FixedScrollBar$1, {
22709
+ }, /*#__PURE__*/React__default['default'].createElement(FixedScrollBar$1, {
22710
+ stickyProps: tableProps === null || tableProps === void 0 ? void 0 : tableProps.sticky,
22694
22711
  viewPort: viewPort,
22695
- width: "".concat(config.colHeaderWidth + 1 + placeholderWidth, "px"),
22696
22712
  ref: topScrollBar
22697
22713
  }), /*#__PURE__*/React__default['default'].createElement("div", {
22698
22714
  style: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bit-sun/business-component",
3
- "version": "2.2.43",
3
+ "version": "2.2.44",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -1,14 +1,10 @@
1
1
  import React, {useEffect, useImperativeHandle, useRef, useState} from 'react'
2
+ import {throttle} from "lodash";
3
+ import useSticky from "./hooks/useSticky";
2
4
 
3
5
  function getOffset(node: any) {
4
6
  const box = node.getBoundingClientRect();
5
7
  const docElem = document.documentElement;
6
- console.log(box, 'box', {
7
- left: box.left + (window.pageXOffset || docElem.scrollLeft) -
8
- (docElem.clientLeft || document.body.clientLeft || 0),
9
- top: box.top + (window.pageYOffset || docElem.scrollTop) -
10
- (docElem.clientTop || document.body.clientTop || 0),
11
- })
12
8
  // < ie8 不支持 win.pageXOffset, 则使用 docElem.scrollLeft
13
9
  return {
14
10
  left: box.left + (window.pageXOffset || docElem.scrollLeft) -
@@ -18,13 +14,11 @@ function getOffset(node: any) {
18
14
  };
19
15
  }
20
16
 
21
-
22
- const FixedScrollBar = ({viewPort, width}: any, ref: any) => {
23
-
17
+ const FixedScrollBar = ({viewPort, stickyProps}: any, ref: any) => {
18
+ const {isSticky, container} = useSticky(stickyProps)
24
19
  const [scrollState, setScrollState] = useState({
25
- isHiddenScrollBar: false
20
+ isHiddenScrollBar: !isSticky
26
21
  })
27
-
28
22
  const onContainerScroll = () => {
29
23
  if (!viewPort.current) {
30
24
  return;
@@ -32,7 +26,6 @@ const FixedScrollBar = ({viewPort, width}: any, ref: any) => {
32
26
  const tableOffsetTop = getOffset(viewPort.current).top;
33
27
  const tableBottomOffset = tableOffsetTop + viewPort.current.offsetHeight;
34
28
  const currentClientOffset = document.documentElement.scrollTop + window.innerHeight
35
-
36
29
  if (
37
30
  tableBottomOffset - 1 <= currentClientOffset ||
38
31
  tableOffsetTop >= currentClientOffset
@@ -51,9 +44,10 @@ const FixedScrollBar = ({viewPort, width}: any, ref: any) => {
51
44
  };
52
45
 
53
46
  useEffect(() => {
54
- document.addEventListener('scroll', onContainerScroll)
47
+ const onscroll = throttle(onContainerScroll, 50)
48
+ container.addEventListener('scroll', onscroll)
55
49
  return () => {
56
- document.removeEventListener('scroll', onContainerScroll)
50
+ container.removeEventListener('scroll', onscroll)
57
51
  }
58
52
  },[])
59
53
 
@@ -64,10 +58,10 @@ const FixedScrollBar = ({viewPort, width}: any, ref: any) => {
64
58
  return (
65
59
  <div
66
60
  ref={ref}
67
- onScroll={(e) => {
61
+ onScroll={throttle((e) => {
68
62
  // @ts-ignore
69
63
  viewPort.current.scrollTo(e.target.scrollLeft, 0)
70
- }}
64
+ }, 50)}
71
65
  style={{
72
66
  position:'fixed',
73
67
  zIndex: '9999',
@@ -83,7 +77,7 @@ const FixedScrollBar = ({viewPort, width}: any, ref: any) => {
83
77
  style={{
84
78
  height: '1px',
85
79
  backgroundColor: '#fff',
86
- width,
80
+ width: viewPort.current?.scrollWidth || 0,
87
81
  }}></div>
88
82
  </div>
89
83
  )
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+
3
+ interface TableSticky{
4
+ getContainer?: () => Window | HTMLElement;
5
+ }
6
+
7
+ const useSticky = (sticky: boolean | TableSticky) => {
8
+ const {getContainer = () => window.document} = typeof sticky === 'object' ? sticky : {}
9
+
10
+ const container = getContainer()
11
+ return React.useMemo(() => {
12
+ const isSticky = !!sticky
13
+ return {
14
+ isSticky,
15
+ container,
16
+ }
17
+ },[sticky])
18
+
19
+ }
20
+
21
+ export default useSticky
@@ -152,11 +152,11 @@ export default forwardRef((props, ref) => {
152
152
  onScroll={onScroll}
153
153
  ref={viewPort}
154
154
  >
155
- {tableProps?.sticky && <FixedScrollBar
155
+ <FixedScrollBar
156
+ stickyProps={tableProps?.sticky}
156
157
  viewPort={viewPort}
157
- width={`${config.colHeaderWidth + 1 + placeholderWidth}px`}
158
158
  ref={topScrollBar}
159
- />}
159
+ />
160
160
  <div style={{
161
161
  width: `${config.colHeaderWidth + 1 + placeholderWidth}px`,
162
162
  position: 'absolute',