@kdcloudjs/table 1.1.3 → 1.1.4-canary.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.
Files changed (73) hide show
  1. package/dist/@kdcloudjs/table.css +1 -1
  2. package/dist/@kdcloudjs/table.js +599 -268
  3. package/dist/@kdcloudjs/table.js.map +1 -1
  4. package/dist/@kdcloudjs/table.min.css +1 -1
  5. package/dist/@kdcloudjs/table.min.js +10 -9
  6. package/dist/@kdcloudjs/table.min.js.map +1 -1
  7. package/es/table/base/html-table.js +1 -1
  8. package/es/table/base/styles.d.ts +7 -2
  9. package/es/table/base/styles.js +13 -6
  10. package/es/table/base/table.d.ts +2 -0
  11. package/es/table/base/table.js +31 -53
  12. package/es/table/base/utils.d.ts +7 -0
  13. package/es/table/base/utils.js +29 -1
  14. package/es/table/pipeline/features/columnDrag.js +21 -11
  15. package/es/table/pipeline/features/columnFilter.d.ts +2 -2
  16. package/es/table/pipeline/features/columnFilter.js +35 -15
  17. package/es/table/pipeline/features/columnResizeWidth.js +1 -1
  18. package/es/table/pipeline/features/filter/DefaultFilterContent.js +22 -2
  19. package/es/table/pipeline/features/filter/DefaultFilterIcon.d.ts +5 -0
  20. package/es/table/pipeline/features/filter/DefaultFilterIcon.js +20 -0
  21. package/es/table/pipeline/features/filter/Filter.d.ts +1 -1
  22. package/es/table/pipeline/features/filter/Filter.js +16 -20
  23. package/es/table/pipeline/features/filter/FilterPanel.js +21 -15
  24. package/es/table/pipeline/features/filter/util.js +4 -4
  25. package/es/table/pipeline/features/footerDataSource.d.ts +9 -0
  26. package/es/table/pipeline/features/footerDataSource.js +25 -0
  27. package/es/table/pipeline/features/index.d.ts +1 -0
  28. package/es/table/pipeline/features/index.js +2 -1
  29. package/es/table/pipeline/features/multiSelect.js +7 -2
  30. package/es/table/pipeline/features/rangeSelection.d.ts +1 -1
  31. package/es/table/pipeline/features/rangeSelection.js +156 -28
  32. package/es/table/pipeline/features/singleSelect.js +4 -0
  33. package/es/table/pipeline/features/treeMode.d.ts +2 -0
  34. package/es/table/pipeline/features/treeMode.js +18 -20
  35. package/es/table/pipeline/pipeline.d.ts +5 -1
  36. package/es/table/pipeline/pipeline.js +12 -11
  37. package/es/table/utils/keyCode.d.ts +4 -0
  38. package/es/table/utils/keyCode.js +4 -0
  39. package/es/table/utils/mergeCellProps.js +2 -6
  40. package/lib/table/base/html-table.js +1 -1
  41. package/lib/table/base/styles.d.ts +7 -2
  42. package/lib/table/base/styles.js +13 -6
  43. package/lib/table/base/table.d.ts +2 -0
  44. package/lib/table/base/table.js +31 -53
  45. package/lib/table/base/utils.d.ts +7 -0
  46. package/lib/table/base/utils.js +35 -1
  47. package/lib/table/pipeline/features/columnDrag.js +21 -11
  48. package/lib/table/pipeline/features/columnFilter.d.ts +2 -2
  49. package/lib/table/pipeline/features/columnFilter.js +33 -15
  50. package/lib/table/pipeline/features/columnResizeWidth.js +1 -1
  51. package/lib/table/pipeline/features/filter/DefaultFilterContent.js +23 -1
  52. package/lib/table/pipeline/features/filter/DefaultFilterIcon.d.ts +5 -0
  53. package/lib/table/pipeline/features/filter/DefaultFilterIcon.js +30 -0
  54. package/lib/table/pipeline/features/filter/Filter.d.ts +1 -1
  55. package/lib/table/pipeline/features/filter/Filter.js +17 -20
  56. package/lib/table/pipeline/features/filter/FilterPanel.js +21 -14
  57. package/lib/table/pipeline/features/filter/util.js +4 -4
  58. package/lib/table/pipeline/features/footerDataSource.d.ts +9 -0
  59. package/lib/table/pipeline/features/footerDataSource.js +41 -0
  60. package/lib/table/pipeline/features/index.d.ts +1 -0
  61. package/lib/table/pipeline/features/index.js +15 -1
  62. package/lib/table/pipeline/features/multiSelect.js +6 -1
  63. package/lib/table/pipeline/features/rangeSelection.d.ts +1 -1
  64. package/lib/table/pipeline/features/rangeSelection.js +158 -30
  65. package/lib/table/pipeline/features/singleSelect.js +4 -0
  66. package/lib/table/pipeline/features/treeMode.d.ts +2 -0
  67. package/lib/table/pipeline/features/treeMode.js +19 -22
  68. package/lib/table/pipeline/pipeline.d.ts +5 -1
  69. package/lib/table/pipeline/pipeline.js +13 -11
  70. package/lib/table/utils/keyCode.d.ts +4 -0
  71. package/lib/table/utils/keyCode.js +11 -0
  72. package/lib/table/utils/mergeCellProps.js +2 -6
  73. package/package.json +3 -3
@@ -6,11 +6,12 @@ var _templateObject;
6
6
 
7
7
  import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
8
8
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
9
- import React, { useEffect } from 'react';
9
+ import React, { useEffect, useRef } from 'react';
10
10
  import styled from 'styled-components';
11
11
  import cx from 'classnames';
12
12
  import { DEFAULT_FILTER_OPTIONS } from './util';
13
13
  import { Classes, ButtonCSS } from '../../../base/styles';
14
+ import KeyCode from '../../../utils/keyCode';
14
15
  var DefaultFilterContentStyle = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n background-color: #ffffff;\n border-radius: 2px;\n width: 100%;\n\n ", "\n .filter-option-list {\n display: flex;\n flex-direction: column;\n margin-top: 8px;\n ul {\n margin: 0;\n padding: 0;\n li {\n display: flex;\n position: relative;\n flex-shrink: 0;\n height: 32px;\n align-items: center;\n border-radius: 2px;\n font-size: 12px;\n color: var(--color);\n padding: 0 12px;\n overflow: hidden;\n cursor: pointer;\n &:hover{\n background-color: var(--primary-color-level1);\n }\n }\n li.active{\n background-color: var(--primary-color-level1);\n }\n }\n }\n\n .filter-search {\n display: flex;\n padding: 6px 12px;\n\n .filter-search-inner {\n width: 100%;\n font-size: 12px;\n color: #333333;\n height: 28px;\n line-height: 28px;\n padding: 0 8px;\n outline: none;\n background-color: #FAFAFA;\n border-radius: 2px;\n border: 1px solid var(--strong-border-color);\n &:hover{\n border-color: var(--primary-color)\n } \n &:focus{\n border-color: var(--primary-color)\n } \n }\n }\n\n .filter-footer {\n display: flex;\n flex-direction: row;\n padding: 8px 12px;\n justify-content: space-between;\n\n .filter-btn {\n text-align: center;\n font-size: 12px;\n width: 60px;\n height: 24px;\n line-height: 24px;\n }\n \n }\n"])), ButtonCSS);
15
16
 
16
17
  function DefaultFilterContent(_ref) {
@@ -30,6 +31,7 @@ function DefaultFilterContent(_ref) {
30
31
  innerValue = _React$useState4[0],
31
32
  setInnerValue = _React$useState4[1];
32
33
 
34
+ var inputRef = useRef();
33
35
  var handleClick = React.useCallback(function (option) {
34
36
  setSelectedValue(option.key);
35
37
  }, []);
@@ -47,10 +49,26 @@ function DefaultFilterContent(_ref) {
47
49
  });
48
50
  };
49
51
 
52
+ var handleKeyDown = function handleKeyDown(e) {
53
+ if (e.keyCode === KeyCode.ENTER) {
54
+ confirm();
55
+ }
56
+ };
57
+
50
58
  useEffect(function () {
51
59
  setSelectedValue((filterModel === null || filterModel === void 0 ? void 0 : filterModel.filterCondition) || 'contain');
52
60
  setInnerValue((filterModel === null || filterModel === void 0 ? void 0 : _filterInstanceProperty(filterModel)) || '');
53
61
  }, [filterModel]);
62
+ useEffect(function () {
63
+ // 兼容设置焦点后发生滚动
64
+ setTimeout(function () {
65
+ var _a;
66
+
67
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus({
68
+ preventScroll: true
69
+ });
70
+ });
71
+ }, []);
54
72
  return /*#__PURE__*/React.createElement(DefaultFilterContentStyle, null, /*#__PURE__*/React.createElement("div", {
55
73
  className: 'filter-option-list'
56
74
  }, /*#__PURE__*/React.createElement("ul", null, _mapInstanceProperty(DEFAULT_FILTER_OPTIONS).call(DEFAULT_FILTER_OPTIONS, function (option, index) {
@@ -72,7 +90,9 @@ function DefaultFilterContent(_ref) {
72
90
  value: innerValue,
73
91
  onChange: function onChange(e) {
74
92
  setInnerValue(e.target.value);
75
- }
93
+ },
94
+ onKeyDown: handleKeyDown,
95
+ ref: inputRef
76
96
  })), /*#__PURE__*/React.createElement("div", {
77
97
  className: 'filter-footer'
78
98
  }, /*#__PURE__*/React.createElement("button", {
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export default function DefaultFilterIcon({ width, height }: {
3
+ width: string | number;
4
+ height: string | number;
5
+ }): JSX.Element;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ export default function DefaultFilterIcon(_ref) {
3
+ var width = _ref.width,
4
+ height = _ref.height;
5
+ return /*#__PURE__*/React.createElement("svg", {
6
+ width: width,
7
+ height: height,
8
+ style: {
9
+ verticalAlign: 'middle'
10
+ },
11
+ viewBox: "0 0 1024 1024",
12
+ focusable: "false",
13
+ "data-icon": "filter",
14
+ fill: "currentColor",
15
+ version: "1.1",
16
+ xmlns: "http://www.w3.org/2000/svg"
17
+ }, /*#__PURE__*/React.createElement("path", {
18
+ d: "M891.448889 159.573333L626.460444 460.231111v443.221333c0 32.881778-25.429333 63.658667-55.864888 63.658667l-170.268445-172.942222V456.419556L132.266667 159.857778A59.619556 59.619556 0 0 1 173.511111 56.888889h676.977778c32.995556 0 59.733333 26.680889 59.733333 59.562667 0 17.066667-7.224889 32.312889-18.773333 43.121777z"
19
+ }));
20
+ }
@@ -6,7 +6,7 @@ interface FilterProps {
6
6
  size?: number;
7
7
  isFilterActive: boolean;
8
8
  FilterPanelContent?: FilterPanelType;
9
- filterIcon?: ReactNode;
9
+ filterIcon?: ReactNode | ((filtered: boolean) => ReactNode);
10
10
  setFilterModel: DefaultFilterPanelProps['setFilterModel'];
11
11
  filterModel: DefaultFilterPanelProps['filterModel'];
12
12
  setFilter: CustomeFilterPanelProps['setFilter'];
@@ -10,10 +10,11 @@ import styled from 'styled-components';
10
10
  import { Classes } from '../../../base/styles';
11
11
  import FilterPanel from './FilterPanel';
12
12
  import DefaultFilterContent from './DefaultFilterContent';
13
+ import DefaultFilterIcon from './DefaultFilterIcon';
13
14
  import { calculatePopupRelative } from '../../../utils';
14
15
  import { addResizeObserver } from '../../../base/utils';
15
16
  import cx from 'classnames';
16
- var HEADER_ICON_OFFSET_Y = 6 + 1; // padding-top + border
17
+ var HEADER_ICON_OFFSET_Y = 8 + 1; // padding-top + border
17
18
 
18
19
  var HEADER_ICON_OFFSET_X = 16 + 1; // padding-left+ border
19
20
 
@@ -88,10 +89,6 @@ function Filter(_ref2) {
88
89
  return setShowPanel(false);
89
90
  };
90
91
 
91
- var handleMouseDown = function handleMouseDown(e) {
92
- e.stopPropagation(); // 阻止触发拖拽
93
- };
94
-
95
92
  var renderPanelContent = function renderPanelContent() {
96
93
  if (FilterPanelContent) {
97
94
  return /*#__PURE__*/React.createElement(FilterPanelContent, {
@@ -111,6 +108,12 @@ function Filter(_ref2) {
111
108
  };
112
109
 
113
110
  var handleIconClick = function handleIconClick(e) {
111
+ // 只有当icon区域点击会触发面板展开
112
+ // 防止 createPortal 区域的点击触发该事件
113
+ if (!e.currentTarget.contains(e.target)) {
114
+ return;
115
+ }
116
+
114
117
  if (stopClickEventPropagation) {
115
118
  e.stopPropagation();
116
119
  }
@@ -119,27 +122,20 @@ function Filter(_ref2) {
119
122
  };
120
123
 
121
124
  var iconClassName = cx((_cx = {}, _defineProperty(_cx, className, true), _defineProperty(_cx, 'filter-panel-open', showPanel), _cx));
125
+ var displayFilterIcon = typeof filterIcon === 'function' ? filterIcon(isFilterActive) : filterIcon;
122
126
  return /*#__PURE__*/React.createElement(FilterIconSpanStyle, {
123
127
  style: style,
124
128
  className: iconClassName,
125
- onMouseDown: handleMouseDown,
126
- ref: iconRef
127
- }, /*#__PURE__*/React.createElement("span", {
128
- className: Classes.filterIcon,
129
129
  onClick: handleIconClick
130
- }, filterIcon || /*#__PURE__*/React.createElement("svg", {
130
+ }, /*#__PURE__*/React.createElement("span", {
131
+ ref: iconRef,
132
+ className: Classes.filterIcon
133
+ }, displayFilterIcon || /*#__PURE__*/React.createElement(DefaultFilterIcon, {
131
134
  width: size,
132
- height: size,
133
- viewBox: "64 64 896 896",
134
- focusable: "false",
135
- "data-icon": "filter",
136
- fill: "currentColor",
137
- "aria-hidden": "true"
138
- }, /*#__PURE__*/React.createElement("path", {
139
- d: "M349 838c0 17.7 14.2 32 31.8 32h262.4c17.6 0 31.8-14.3\n 31.8-32V642H349v196zm531.1-684H143.9c-24.5 0-39.8 26.7-27.5\n 48l221.3 376h348.8l221.3-376c12.1-21.3-3.2-48-27.7-48z"
140
- }))), showPanel && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(Panel, {
135
+ height: size
136
+ })), showPanel && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(Panel, {
141
137
  ele: iconRef.current,
142
- filterIcon: filterIcon,
138
+ filterIcon: displayFilterIcon,
143
139
  hidePanel: hidePanel,
144
140
  renderPanelContent: renderPanelContent
145
141
  }), document.body));
@@ -4,10 +4,11 @@ import _taggedTemplateLiteral from "@babel/runtime-corejs3/helpers/taggedTemplat
4
4
 
5
5
  var _templateObject;
6
6
 
7
- import React, { useEffect, useState } from 'react';
7
+ import React, { useEffect, useState, useRef } from 'react';
8
8
  import styled from 'styled-components';
9
9
  import { isElementInEventPath, keepWithinBounds } from '../../../utils/';
10
- var FilterPanelStyle = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n max-height: 450px;\n min-width: 160px;\n border-radius: 2px;\n background-color: #fff;\n box-shadow: 0 0 5px 0 rgba(154,154,154,.5);\n cursor: default;\n\n .popup-header {\n display: flex;\n background-color: #ebedf1;\n\n .popup-header-icon {\n color:#666;\n background-color: #fff;\n padding: 6px 16px 6px 16px;\n display: inline-block;\n border-right: 1px solid transparent;\n border-left: 1px solid transparent;\n border-top: 1px solid transparent;\n border-top-right-radius: 2px;\n border-top-left-radius: 2px;\n }\n }\n\n .popup-body {\n display: flex;\n }\n"])));
10
+ import DefaultFilterIcon from './DefaultFilterIcon';
11
+ var FilterPanelStyle = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n max-height: 450px;\n min-width: 160px;\n border-radius: 2px;\n background-color: #fff;\n box-shadow: 0 0 5px 0 rgba(154,154,154,.5);\n cursor: default;\n\n .popup-header {\n display: flex;\n background-color: #ebedf1;\n\n .popup-header-icon {\n display: flex;\n color:#666;\n background-color: #fff;\n padding: 8px 16px 8px 16px;\n border-right: 1px solid transparent;\n border-left: 1px solid transparent;\n border-top: 1px solid transparent;\n border-top-right-radius: 2px;\n border-top-left-radius: 2px;\n }\n }\n\n .popup-body {\n display: flex;\n }\n"])));
11
12
 
12
13
  var useWindowEvents = function useWindowEvents(func, evens) {
13
14
  React.useEffect(function () {
@@ -49,31 +50,36 @@ function FilterPanel(_ref) {
49
50
  setPerfectPosition(keepWithinBounds(document.body, ref.current, position.x, position.y, true));
50
51
  setVisible(true);
51
52
  }, [position]);
53
+ var hasPopupMouseEvent = useRef(false);
54
+
55
+ var handleMouseEvent = function handleMouseEvent() {
56
+ // 当弹出的过滤面板内部发生鼠标按下、抬起事件时,标记当前事件,并在click捕获期清除标记,用来确定鼠标按下、抬起发生在过滤面板内部
57
+ // 利用了React.createPortal冒泡是根据React Tree的特性:
58
+ // https://jwwnz.medium.com/react-portals-and-event-bubbling-8df3e35ca3f1
59
+ hasPopupMouseEvent.current = true;
60
+ };
61
+
52
62
  useWindowEvents(function (e) {
53
- return !isContainPanel(e) && onClose();
54
- }, ['mousedown']);
63
+ !isContainPanel(e) && !hasPopupMouseEvent.current && onClose();
64
+ hasPopupMouseEvent.current = false;
65
+ }, ['click']);
55
66
  return /*#__PURE__*/React.createElement(FilterPanelStyle, {
56
67
  style: _extends(_extends({}, style), {
57
68
  left: visible ? perfectPosition.x : 0,
58
69
  top: visible ? perfectPosition.y : 0,
59
70
  opacity: visible ? 1 : 0
60
71
  }),
72
+ onMouseDown: handleMouseEvent,
73
+ onMouseUp: handleMouseEvent,
61
74
  ref: ref
62
75
  }, /*#__PURE__*/React.createElement("div", {
63
76
  className: 'popup-header'
64
77
  }, /*#__PURE__*/React.createElement("span", {
65
78
  className: 'popup-header-icon'
66
- }, filterIcon || /*#__PURE__*/React.createElement("svg", {
67
- width: 14,
68
- height: 14,
69
- viewBox: "64 64 896 896",
70
- focusable: "false",
71
- "data-icon": "filter",
72
- fill: "currentColor",
73
- "aria-hidden": "true"
74
- }, /*#__PURE__*/React.createElement("path", {
75
- d: "M349 838c0 17.7 14.2 32 31.8 32h262.4c17.6 0 31.8-14.3\n 31.8-32V642H349v196zm531.1-684H143.9c-24.5 0-39.8 26.7-27.5\n 48l221.3 376h348.8l221.3-376c12.1-21.3-3.2-48-27.7-48z"
76
- })))), /*#__PURE__*/React.createElement("div", {
79
+ }, filterIcon || /*#__PURE__*/React.createElement(DefaultFilterIcon, {
80
+ width: 12,
81
+ height: 12
82
+ }))), /*#__PURE__*/React.createElement("div", {
77
83
  className: "popup-body"
78
84
  }, children));
79
85
  }
@@ -12,7 +12,7 @@ var DEFAULT_FILTER_OPTIONS = [{
12
12
  data = data + '';
13
13
  }
14
14
 
15
- return _includesInstanceProperty(data).call(data, value);
15
+ return _includesInstanceProperty(data).call(data, value[0]);
16
16
  };
17
17
  }
18
18
  }, {
@@ -28,7 +28,7 @@ var DEFAULT_FILTER_OPTIONS = [{
28
28
  data = data + '';
29
29
  }
30
30
 
31
- return !_includesInstanceProperty(data).call(data, value);
31
+ return !_includesInstanceProperty(data).call(data, value[0]);
32
32
  };
33
33
  }
34
34
  }, {
@@ -36,7 +36,7 @@ var DEFAULT_FILTER_OPTIONS = [{
36
36
  key: 'equal',
37
37
  filter: function filter(value) {
38
38
  return function (data) {
39
- return value !== data;
39
+ return value[0] === data;
40
40
  };
41
41
  }
42
42
  }, {
@@ -44,7 +44,7 @@ var DEFAULT_FILTER_OPTIONS = [{
44
44
  key: 'notEqual',
45
45
  filter: function filter(value) {
46
46
  return function (data) {
47
- return value !== data;
47
+ return value[0] !== data;
48
48
  };
49
49
  }
50
50
  }, {
@@ -0,0 +1,9 @@
1
+ import { TablePipeline } from '../pipeline';
2
+ export interface FooterDataSourceFeatureOptions {
3
+ /** 指定表格页脚每一行元信息的记录字段 */
4
+ footerRowMetaKey?: string | symbol;
5
+ /** 表格页脚数据源 */
6
+ dataSource?: any[];
7
+ }
8
+ export declare const footerRowMetaSymbol: unique symbol;
9
+ export declare function footerDataSource(opts?: FooterDataSourceFeatureOptions): (pipeline: TablePipeline) => TablePipeline;
@@ -0,0 +1,25 @@
1
+ import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
+ import _extends from "@babel/runtime-corejs3/helpers/extends";
3
+ import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
4
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
5
+ export var footerRowMetaSymbol = _Symbol('footer-row');
6
+ export function footerDataSource() {
7
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8
+ return function footerDataSourceStep(pipeline) {
9
+ var _a, _b;
10
+
11
+ var footerDataSource = (_a = opts.dataSource) !== null && _a !== void 0 ? _a : pipeline.getFooterDataSource();
12
+ var footerRowMetaKey = (_b = opts.footerRowMetaKey) !== null && _b !== void 0 ? _b : footerRowMetaSymbol;
13
+ pipeline.setFeatureOptions('footerRowMetaKey', footerRowMetaKey);
14
+
15
+ if (footerDataSource) {
16
+ pipeline.footerDataSource(_mapInstanceProperty(footerDataSource).call(footerDataSource, function (row) {
17
+ return _extends(_defineProperty({}, footerRowMetaKey, true), row);
18
+ }));
19
+ } else {
20
+ console.warn('调用 pipeline.use(features.footerDataSource()) 前请先设置页脚数据源,设置方法有:pipeline.use(features.footerDataSource({dataSource:any[]})) 或者 pipeline.footerDataSource(any[])');
21
+ }
22
+
23
+ return pipeline;
24
+ };
25
+ }
@@ -16,3 +16,4 @@ export { contextMenu, ContextMenuFeatureOptions } from './contextMenu';
16
16
  export { filter, FilterFeatureOptions } from './columnFilter';
17
17
  export { rangeSelection, RangeSelectionFeatureOptions } from './rangeSelection';
18
18
  export { mergeCellHover } from './mergeCellHover';
19
+ export { footerDataSource, FooterDataSourceFeatureOptions, footerRowMetaSymbol } from './footerDataSource';
@@ -15,4 +15,5 @@ export { columnResize } from './columnResizeWidth';
15
15
  export { contextMenu } from './contextMenu';
16
16
  export { filter } from './columnFilter';
17
17
  export { rangeSelection } from './rangeSelection';
18
- export { mergeCellHover } from './mergeCellHover';
18
+ export { mergeCellHover } from './mergeCellHover';
19
+ export { footerDataSource, footerRowMetaSymbol } from './footerDataSource';
@@ -5,7 +5,7 @@ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instan
5
5
  import React from 'react';
6
6
  import { internals } from '../../internals';
7
7
  import { always, arrayUtils } from '../../utils/others';
8
- import { mergeCellProps } from '../../utils';
8
+ import { collectNodes, mergeCellProps } from '../../utils';
9
9
  export function multiSelect() {
10
10
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
11
  return function multiSelectStep(pipeline) {
@@ -44,7 +44,8 @@ export function multiSelect() {
44
44
  /** 所有有效的 keys(disable 状态为 false) */
45
45
 
46
46
  var allKeys = [];
47
- dataSource.forEach(function (row, rowIndex) {
47
+ var flatDataSource = collectNodes(dataSource);
48
+ flatDataSource.forEach(function (row, rowIndex) {
48
49
  var rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
49
50
  fullKeySet.add(rowKey); // 在 allKeys 中排除被禁用的 key
50
51
 
@@ -110,6 +111,10 @@ export function multiSelect() {
110
111
  return mergeCellProps(preCellProps, checkboxCellProps);
111
112
  },
112
113
  render: function render(_, row, rowIndex) {
114
+ if (row[pipeline.getFeatureOptions('footerRowMetaKey')]) {
115
+ return null;
116
+ }
117
+
113
118
  var key = internals.safeGetRowKey(primaryKey, row, rowIndex);
114
119
  var checked = set.has(key);
115
120
  return /*#__PURE__*/React.createElement(Checkbox, {
@@ -6,5 +6,5 @@ export interface RangeSelectionFeatureOptions {
6
6
  preventkDefaultOfKeyDownEvent?: boolean;
7
7
  }
8
8
  export declare const rangeSelectionKey = "rangeSelection";
9
- export declare const lastClickCell = "lastClickCell";
9
+ export declare const lastClickCellKey = "lastClickCell";
10
10
  export declare function rangeSelection(opts: RangeSelectionFeatureOptions): (pipeline: TablePipeline) => TablePipeline;
@@ -10,40 +10,42 @@ import { map, takeUntil } from 'rxjs/operators';
10
10
  import { Classes } from '../../base/styles';
11
11
  import cx from 'classnames';
12
12
  export var rangeSelectionKey = 'rangeSelection';
13
- export var lastClickCell = 'lastClickCell';
13
+ export var lastClickCellKey = 'lastClickCell';
14
14
  export function rangeSelection(opts) {
15
15
  return function step(pipeline) {
16
16
  var SCROLL_SIZE = 30;
17
17
  var tableBody = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.tableBody;
18
+ var tableFooter = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.tableFooter;
18
19
 
19
20
  if (!tableBody) {
20
21
  return pipeline;
21
22
  }
22
23
 
23
24
  var columns = pipeline.getColumns();
25
+ var dataSource = pipeline.getDataSource();
24
26
 
25
27
  var rangeSelectedChange = function rangeSelectedChange(rangeSelection) {
26
28
  var _a;
27
29
 
28
30
  pipeline.setStateAtKey(rangeSelectionKey, rangeSelection);
29
31
  (_a = opts === null || opts === void 0 ? void 0 : opts.rangeSelectedChange) === null || _a === void 0 ? void 0 : _a.call(opts, rangeSelection);
30
- }; // if (!pipeline.getFeatureOptions(rangeSelectionKey)) {
31
- // pipeline.setFeatureOptions(rangeSelectionKey, {
32
- // optionKey: rangeSelectionKey,
33
- // rangeSelectedChange: rangeSelectedChange
34
- // })
35
- // }
36
-
32
+ };
37
33
 
38
34
  var setRangeSelection = function setRangeSelection(startDragCell, draggingCell) {
39
- if (!startDragCell || !draggingCell || isSameCell(startDragCell, draggingCell)) return;
35
+ if (!startDragCell || !draggingCell) return;
40
36
  var rangeColumns = getRangeColumns(startDragCell, draggingCell, columns);
41
- var isTopToBottom = startDragCell.rowIndex <= draggingCell.rowIndex;
37
+
38
+ var _getRangeSelectionRow = getRangeSelectionRowInfo(startDragCell, draggingCell, dataSource),
39
+ startRow = _getRangeSelectionRow.startRow,
40
+ endRow = _getRangeSelectionRow.endRow,
41
+ footerRowRange = _getRangeSelectionRow.footerRowRange;
42
+
42
43
  var rangeSelection = {
43
- startRow: isTopToBottom ? startDragCell.rowIndex : startDragCell.rowIndex + startDragCell.rowSpan - 1,
44
- endRow: isTopToBottom ? draggingCell.rowIndex + draggingCell.rowSpan - 1 : draggingCell.rowIndex,
44
+ startRow: startRow,
45
+ endRow: endRow,
45
46
  columns: rangeColumns,
46
- startColumn: startDragCell.column
47
+ startColumn: startDragCell.column,
48
+ footerRowRange: footerRowRange
47
49
  };
48
50
  rangeSelectedChange(rangeSelection);
49
51
  };
@@ -54,23 +56,23 @@ export function rangeSelection(opts) {
54
56
 
55
57
  if (clickCell) {
56
58
  if (event.shiftKey) {
57
- var _lastClickCell = pipeline.getStateAtKey(lastClickCell);
59
+ var _lastClickCell = pipeline.getStateAtKey(lastClickCellKey);
58
60
 
59
61
  if (_lastClickCell) {
60
62
  setRangeSelection(_lastClickCell, clickCell);
61
63
  } else {
62
64
  // 第一次进来就按住shift键,这时候要记住点击的单元格
63
- pipeline.setStateAtKey(lastClickCell, clickCell);
65
+ pipeline.setStateAtKey(lastClickCellKey, clickCell);
64
66
  }
65
67
  } else {
66
- pipeline.setStateAtKey(lastClickCell, clickCell);
67
- rangeSelectedChange(null);
68
+ pipeline.setStateAtKey(lastClickCellKey, clickCell);
69
+ setRangeSelection(clickCell, clickCell);
68
70
  }
69
71
  }
70
72
  };
71
73
 
72
74
  var onMouseDown = function onMouseDown(mouseDownEvent) {
73
- if (mouseDownEvent.button !== 0 || !isElementInEventPath(tableBody, mouseDownEvent.nativeEvent)) return; // mouseDownEvent.preventDefault()
75
+ if (mouseDownEvent.button !== 0 || !(isElementInEventPath(tableBody, mouseDownEvent.nativeEvent) || isElementInEventPath(tableFooter, mouseDownEvent.nativeEvent))) return; // mouseDownEvent.preventDefault()
74
76
  // shift + 点击选中
75
77
 
76
78
  shiftKeySelect(mouseDownEvent);
@@ -126,10 +128,11 @@ export function rangeSelection(opts) {
126
128
  };
127
129
 
128
130
  var onKeyDown = function onKeyDown(e) {
129
- if (!isElementInEventPath(tableBody, e.nativeEvent)) return;
131
+ if (!(isElementInEventPath(tableBody, e.nativeEvent) || isElementInEventPath(tableFooter, e.nativeEvent))) return;
130
132
 
131
133
  if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
132
134
  var rowLen = pipeline.getDataSource().length;
135
+ var footerDataSource = pipeline.getFooterDataSource() || [];
133
136
 
134
137
  if (columns.length && rowLen) {
135
138
  opts.preventkDefaultOfKeyDownEvent !== false && e.preventDefault();
@@ -137,7 +140,11 @@ export function rangeSelection(opts) {
137
140
  startRow: 0,
138
141
  endRow: rowLen - 1,
139
142
  columns: columns,
140
- startColumn: columns[0]
143
+ startColumn: columns[0],
144
+ footerRowRange: footerDataSource.length > 0 ? {
145
+ startRow: 0,
146
+ endRow: footerDataSource.length - 1
147
+ } : null
141
148
  });
142
149
  }
143
150
  }
@@ -146,7 +153,8 @@ export function rangeSelection(opts) {
146
153
  pipeline.addTableProps({
147
154
  onMouseDown: onMouseDown,
148
155
  onKeyDown: onKeyDown,
149
- tabIndex: -1
156
+ tabIndex: -1,
157
+ className: cx([Classes.rangeSelection])
150
158
  }); // todo: 后面可以把mousedown放到一个流里面
151
159
 
152
160
  return pipeline.mapColumns(makeRecursiveMapper(function (col) {
@@ -162,15 +170,29 @@ export function rangeSelection(opts) {
162
170
  var _cx;
163
171
 
164
172
  var prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
173
+ var isInFooter = record[pipeline.getFeatureOptions('footerRowMetaKey')];
165
174
  var startRow = rangeSelection.startRow,
166
175
  endRow = rangeSelection.endRow,
167
- columns = rangeSelection.columns;
168
- var startIndex = startRow < endRow ? startRow : endRow;
169
- var endIndex = startRow < endRow ? endRow : startRow;
176
+ columns = rangeSelection.columns,
177
+ footerRowRange = rangeSelection.footerRowRange;
178
+
179
+ var _getRowIndex = getRowIndex(startRow, endRow),
180
+ startRowIndex = _getRowIndex.startRowIndex,
181
+ endRowIndex = _getRowIndex.endRowIndex;
182
+
183
+ var _getFooterRowIndex = getFooterRowIndex(footerRowRange),
184
+ footerStartRowIndex = _getFooterRowIndex.startRowIndex,
185
+ footerEndRowIndex = _getFooterRowIndex.endRowIndex;
186
+
170
187
  var startCol = columns[0];
171
188
  var endCol = columns[columns.length - 1];
172
- var match = rowIndex >= startIndex && rowIndex <= endIndex;
173
- var className = cx((_cx = {}, _defineProperty(_cx, Classes.tableCellRangeSelected, match), _defineProperty(_cx, Classes.tableCellRangeTop, rowIndex === startIndex), _defineProperty(_cx, Classes.tableCellRangeLeft, col.code === startCol.code && match), _defineProperty(_cx, Classes.tableCellRangeBottom, rowIndex === endIndex), _defineProperty(_cx, Classes.tableCellRangeRight, col.code === endCol.code && match), _cx));
189
+ var bodyMatch = !isInFooter && rowIndex >= startRowIndex && rowIndex <= endRowIndex;
190
+ var footerMatch = isInFooter && footerRowRange && rowIndex >= footerStartRowIndex && rowIndex <= footerEndRowIndex;
191
+ var match = footerMatch || bodyMatch;
192
+ var matchSingleCell = match && isCellRangeSingleCell(rangeSelection); // 单个范围选中单元格不显示样式
193
+
194
+ var showCellRangeStyle = match && !matchSingleCell;
195
+ var className = cx((_cx = {}, _defineProperty(_cx, Classes.tableCellRangeSingleCell, matchSingleCell), _defineProperty(_cx, Classes.tableCellRangeSelected, showCellRangeStyle), _defineProperty(_cx, Classes.tableCellRangeTop, showCellRangeStyle && (isInFooter ? startRowIndex !== -1 ? false : rowIndex === footerStartRowIndex : rowIndex === startRowIndex)), _defineProperty(_cx, Classes.tableCellRangeLeft, showCellRangeStyle && col.code === startCol.code), _defineProperty(_cx, Classes.tableCellRangeBottom, showCellRangeStyle && (isInFooter ? rowIndex === footerEndRowIndex : footerRowRange ? false : rowIndex === endRowIndex)), _defineProperty(_cx, Classes.tableCellRangeRight, showCellRangeStyle && col.code === endCol.code), _cx));
174
196
  return mergeCellProps(prevCellProps, {
175
197
  className: className
176
198
  });
@@ -196,7 +218,8 @@ function getTargetCell(target, columns) {
196
218
  rowIndex: parseInt(target.getAttribute('data-rowindex')),
197
219
  rowSpan: parseInt(target.getAttribute('rowspan') || 1),
198
220
  code: columnCode,
199
- column: column
221
+ column: column,
222
+ isInFooter: isEleInFooter(target)
200
223
  }
201
224
  };
202
225
  }();
@@ -211,7 +234,19 @@ function getTargetCell(target, columns) {
211
234
  }
212
235
 
213
236
  function isSameCell(cell1, cell2) {
214
- return cell1.rowIndex === cell2.rowIndex && cell1.code === cell2.code;
237
+ return cell1.rowIndex === cell2.rowIndex && cell1.code === cell2.code && cell1.isInFooter === cell2.isInFooter;
238
+ }
239
+
240
+ function isEleInFooter(target) {
241
+ while (target && !target.classList.contains(Classes.artTable)) {
242
+ if (target.classList.contains(Classes.tableFooter)) {
243
+ return true;
244
+ }
245
+
246
+ target = target.parentElement;
247
+ }
248
+
249
+ return false;
215
250
  }
216
251
 
217
252
  function getRangeColumns(startCell, endCell, columns) {
@@ -230,4 +265,97 @@ function getRangeColumns(startCell, endCell, columns) {
230
265
  } else {
231
266
  return _sliceInstanceProperty(flatColumns).call(flatColumns, endIndex, startIndex + 1);
232
267
  }
268
+ }
269
+
270
+ function getRangeSelectionRowInfo(startCell, endCell, dataSource) {
271
+ var footerRowRange = null;
272
+ var startRow = -1;
273
+ var endRow = -1;
274
+
275
+ var _getCellRangeRow = getCellRangeRow(startCell, endCell),
276
+ _startRow = _getCellRangeRow.startRow,
277
+ _endRow = _getCellRangeRow.endRow; // 两个单元格都在表体
278
+
279
+
280
+ if (!startCell.isInFooter && !endCell.isInFooter) {
281
+ startRow = _startRow;
282
+ endRow = _endRow;
283
+ } else if (startCell.isInFooter && endCell.isInFooter) {
284
+ // 两个单元格都在表底
285
+ footerRowRange = {
286
+ startRow: _startRow,
287
+ endRow: _endRow
288
+ };
289
+ } else {
290
+ // 一个单元格在表体,一个在表底
291
+ if (startCell.isInFooter) {
292
+ startRow = dataSource.length - 1;
293
+ endRow = endCell.rowIndex;
294
+ footerRowRange = {
295
+ startRow: startCell.rowIndex,
296
+ endRow: 0
297
+ };
298
+ } else {
299
+ startRow = startCell.rowIndex;
300
+ endRow = dataSource.length - 1;
301
+ footerRowRange = {
302
+ startRow: 0,
303
+ endRow: endCell.rowIndex
304
+ };
305
+ }
306
+ }
307
+
308
+ return {
309
+ startRow: startRow,
310
+ endRow: endRow,
311
+ footerRowRange: footerRowRange
312
+ };
313
+ }
314
+
315
+ function getCellRangeRow(startCell, endCell) {
316
+ if (isSameCell(startCell, endCell)) {
317
+ return {
318
+ startRow: startCell.rowIndex,
319
+ endRow: startCell.rowIndex
320
+ };
321
+ }
322
+
323
+ var isTopToBottom = startCell.rowIndex <= endCell.rowIndex;
324
+ var startRow = isTopToBottom ? startCell.rowIndex : startCell.rowIndex + startCell.rowSpan - 1;
325
+ var endRow = isTopToBottom ? endCell.rowIndex + endCell.rowSpan - 1 : endCell.rowIndex;
326
+ return {
327
+ startRow: startRow,
328
+ endRow: endRow
329
+ };
330
+ }
331
+
332
+ function isCellRangeSingleCell(rangeSelection) {
333
+ var startRow = rangeSelection.startRow,
334
+ endRow = rangeSelection.endRow,
335
+ columns = rangeSelection.columns,
336
+ footerRowRange = rangeSelection.footerRowRange;
337
+ var isBodySingleCell = !footerRowRange && startRow === endRow && columns.length === 1;
338
+ var isFooterSingleCell = startRow === -1 && footerRowRange.startRow === footerRowRange.endRow && columns.length === 1;
339
+ return isBodySingleCell || isFooterSingleCell;
340
+ }
341
+
342
+ function getRowIndex(startRow, endRow) {
343
+ var isReverse = startRow > endRow;
344
+ var startRowIndex = isReverse ? endRow : startRow;
345
+ var endRowIndex = isReverse ? startRow : endRow;
346
+ return {
347
+ startRowIndex: startRowIndex,
348
+ endRowIndex: endRowIndex
349
+ };
350
+ }
351
+
352
+ function getFooterRowIndex(footerRowRange) {
353
+ if (footerRowRange) {
354
+ return getRowIndex(footerRowRange.startRow, footerRowRange.endRow);
355
+ }
356
+
357
+ return {
358
+ startRowIndex: -1,
359
+ endRowIndex: -1
360
+ };
233
361
  }
@@ -60,6 +60,10 @@ export function singleSelect() {
60
60
  return preCellProps;
61
61
  },
62
62
  render: function render(_, row, rowIndex) {
63
+ if (row[pipeline.getFeatureOptions('footerRowMetaKey')]) {
64
+ return null;
65
+ }
66
+
63
67
  var rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
64
68
  return /*#__PURE__*/React.createElement(Radio, {
65
69
  checked: value === rowKey,