@kdcloudjs/table 1.1.3-canary.6 → 1.1.3-canary.7

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.
@@ -12,7 +12,7 @@ export interface FilterFeatureOptions {
12
12
  keepDataSource?: boolean;
13
13
  /** 过滤模式。单列过滤 single,多列过滤 multiple,默认为多选 */
14
14
  mode?: 'single' | 'multiple';
15
- /**过滤图标 */
15
+ /** 过滤图标 */
16
16
  filterIcon?: ReactNode;
17
17
  /** 是否对触发弹出过滤面板 的 click 事件调用 event.stopPropagation() */
18
18
  stopClickEventPropagation?: boolean;
@@ -39,7 +39,7 @@ export function filter() {
39
39
  return _mapInstanceProperty(columns).call(columns, dfs);
40
40
 
41
41
  function dfs(col) {
42
- var _a, _b, _c, _d, _e;
42
+ var _a, _b, _c, _d, _e, _f, _g;
43
43
 
44
44
  var result = _extends({}, col);
45
45
 
@@ -81,12 +81,13 @@ export function filter() {
81
81
  };
82
82
 
83
83
  var filterPanel = (_d = col.features) === null || _d === void 0 ? void 0 : _d.filterPanel;
84
- result.title = _concatInstanceProperty(_context = []).call(_context, _toConsumableArray(_concatInstanceProperty(_context2 = []).call(_context2, (_e = result.title) !== null && _e !== void 0 ? _e : [internals.safeRenderHeader(_extends(_extends({}, col), {
84
+ var colFilterIcon = (_f = (_e = col.features) === null || _e === void 0 ? void 0 : _e.filterIcon) !== null && _f !== void 0 ? _f : filterIcon;
85
+ result.title = _concatInstanceProperty(_context = []).call(_context, _toConsumableArray(_concatInstanceProperty(_context2 = []).call(_context2, (_g = result.title) !== null && _g !== void 0 ? _g : [internals.safeRenderHeader(_extends(_extends({}, col), {
85
86
  title: null
86
87
  }))])), [/*#__PURE__*/React.createElement(Filter, {
87
88
  key: "filter",
88
89
  FilterPanelContent: filterPanel,
89
- filterIcon: filterIcon,
90
+ filterIcon: colFilterIcon,
90
91
  filterModel: inputFiltersMap.get(col.code),
91
92
  setFilterModel: handleFilterChanged,
92
93
  setFilter: setFilter,
@@ -134,8 +135,8 @@ export function filter() {
134
135
  return [item.key, _extends({}, item)];
135
136
  }));
136
137
 
137
- function isMatchedFilterCondition(record, rowIndex) {
138
- return !filtersKeys.some(function (key) {
138
+ function isMatchedFilterCondition(record) {
139
+ return filtersKeys.every(function (key) {
139
140
  var _a, _b;
140
141
 
141
142
  var filterItem = inputFiltersMap.get(key);
@@ -149,24 +150,43 @@ export function filter() {
149
150
  } else {
150
151
  console.warn("\u5217[".concat(key, "]\u672A\u914D\u7F6E\u7B5B\u9009\u51FD\u6570\uFF0C\u8BF7\u8BBE\u7F6E column.features.filterable \u6765\u4F5C\u4E3A\u8BE5\u5217\u7684\u7B5B\u9009\u51FD\u6570, \u76EE\u524D\u4F7F\u7528\u9ED8\u8BA4\u5305\u542B\u7B5B\u9009\u51FD\u6570"));
151
152
  comparisonFn = _filterInstanceProperty(defaultFilterOptionsMap.get('contain'));
152
- } // 不符合过滤条件,退出循环
153
+ }
153
154
 
154
-
155
- return !comparisonFn(_filterInstanceProperty(filterItem), filterItem)(internals.safeGetValue(columnsMap.get(key), record, rowIndex), record);
155
+ return comparisonFn(_filterInstanceProperty(filterItem), filterItem)(internals.safeGetValue(columnsMap.get(key), record, -1), record);
156
156
  });
157
157
  }
158
158
 
159
- return dataSource.reduce(function (pre, record, rowIndex) {
160
- if (isMatchedFilterCondition(record, rowIndex)) {
161
- return _concatInstanceProperty(pre).call(pre, [record]);
162
- }
163
-
164
- return pre;
165
- }, []);
159
+ return layeredFilter(dataSource, isMatchedFilterCondition);
166
160
  }
167
161
 
168
162
  pipeline.dataSource(processDataSource(dataSource));
169
163
  pipeline.columns(processColumns(columns));
170
164
  return pipeline;
171
165
  };
166
+ }
167
+
168
+ function layeredFilter(array, matchFn) {
169
+ return dfs(array);
170
+
171
+ function dfs(rows) {
172
+ var _context6;
173
+
174
+ var parentMatched = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
175
+ return _filterInstanceProperty(_context6 = _mapInstanceProperty(rows).call(rows, function (row) {
176
+ var currentMatched = matchFn(row);
177
+
178
+ if (isLeafNode(row)) {
179
+ return (parentMatched || currentMatched) && _extends({}, row);
180
+ }
181
+
182
+ var children = row.children;
183
+
184
+ var rowAfterFilterChildren = _extends(_extends({}, row), {
185
+ children: dfs(children, parentMatched || currentMatched)
186
+ });
187
+
188
+ var matchedByChildren = !isLeafNode(rowAfterFilterChildren);
189
+ return (parentMatched || currentMatched || matchedByChildren) && rowAfterFilterChildren;
190
+ })).call(_context6, Boolean);
191
+ }
172
192
  }
@@ -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
  }, {
@@ -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
 
@@ -32,6 +32,8 @@ export interface TreeModeFeatureOptions {
32
32
  stopClickEventPropagation?: boolean;
33
33
  /** 指定表格每一行元信息的记录字段 */
34
34
  treeMetaKey?: string | symbol;
35
+ /** 指定展开列 */
36
+ expandColCode?: string;
35
37
  }
36
38
  export declare function treeMode(opts?: TreeModeFeatureOptions): (pipeline: TablePipeline) => TablePipeline;
37
39
  export {};
@@ -1,13 +1,13 @@
1
+ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
1
2
  import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
2
3
  import _getIteratorMethod from "@babel/runtime-corejs3/core-js/get-iterator-method";
3
- import _toArray from "@babel/runtime-corejs3/helpers/toArray";
4
4
  import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
5
5
  import _extends from "@babel/runtime-corejs3/helpers/extends";
6
6
  import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
7
7
 
8
8
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9
9
 
10
- function _unsupportedIterableToArray(o, minLen) { var _context3; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context3 = Object.prototype.toString.call(o)).call(_context3, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _unsupportedIterableToArray(o, minLen) { var _context2; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context2 = Object.prototype.toString.call(o)).call(_context2, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
11
 
12
12
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
13
 
@@ -15,7 +15,7 @@ import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
15
15
  import _Set from "@babel/runtime-corejs3/core-js-stable/set";
16
16
  import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
17
17
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
18
- import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
18
+ import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
19
19
  import cx from 'classnames';
20
20
  import React from 'react';
21
21
  import { ExpansionCell, icons, InlineFlexCell } from '../../common-views';
@@ -31,11 +31,6 @@ export function treeMode() {
31
31
  var stateKey = 'treeMode';
32
32
  var ctx = pipeline.ctx;
33
33
  var primaryKey = pipeline.ensurePrimaryKey('treeMode');
34
-
35
- if (typeof primaryKey !== 'string') {
36
- throw new Error('treeMode 仅支持字符串作为 primaryKey');
37
- }
38
-
39
34
  var openKeys = (_c = (_b = (_a = opts.openKeys) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultOpenKeys) !== null && _c !== void 0 ? _c : [];
40
35
  var openKeySet = new _Set(openKeys);
41
36
 
@@ -90,7 +85,7 @@ export function treeMode() {
90
85
  try {
91
86
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
92
87
  var node = _step.value;
93
- var rowKey = node[primaryKey];
88
+ var rowKey = internals.safeGetRowKey(primaryKey, node, -1);
94
89
  var expanded = openKeySet.has(rowKey);
95
90
  var isLeaf = isLeafNode(node, {
96
91
  depth: depth,
@@ -120,18 +115,20 @@ export function treeMode() {
120
115
  }
121
116
 
122
117
  function processColumns(columns) {
123
- var _context2;
124
-
125
118
  if (columns.length === 0) {
126
119
  return columns;
127
120
  }
128
121
 
129
- var _columns = _toArray(columns),
130
- firstCol = _columns[0],
131
- others = _sliceInstanceProperty(_columns).call(_columns, 1);
122
+ var expandColIndex = _findIndexInstanceProperty(columns).call(columns, function (_ref) {
123
+ var code = _ref.code;
124
+ return code && opts.expandColCode === code;
125
+ });
126
+
127
+ expandColIndex = expandColIndex === -1 ? 0 : expandColIndex;
128
+ var expandCol = columns[expandColIndex];
132
129
 
133
130
  var render = function render(value, record, recordIndex) {
134
- var content = internals.safeRender(firstCol, record, recordIndex);
131
+ var content = internals.safeRender(expandCol, record, recordIndex);
135
132
 
136
133
  if (record[treeMetaKey] == null) {
137
134
  // 没有 treeMeta 信息的话,就返回原先的渲染结果
@@ -191,7 +188,7 @@ export function treeMode() {
191
188
  };
192
189
 
193
190
  var getCellProps = function getCellProps(value, record, rowIndex) {
194
- var prevProps = internals.safeGetCellProps(firstCol, record, rowIndex);
191
+ var prevProps = internals.safeGetCellProps(expandCol, record, rowIndex);
195
192
 
196
193
  if (record[treeMetaKey] == null) {
197
194
  // 没有 treeMeta 信息的话,就返回原先的 cellProps
@@ -220,15 +217,16 @@ export function treeMode() {
220
217
  });
221
218
  };
222
219
 
223
- return _concatInstanceProperty(_context2 = [_extends(_extends({}, firstCol), {
220
+ columns[expandColIndex] = _extends(_extends({}, expandCol), {
224
221
  title: /*#__PURE__*/React.createElement("span", {
225
222
  style: {
226
223
  marginLeft: iconIndent + iconWidth + iconGap
227
224
  }
228
- }, internals.safeRenderHeader(firstCol)),
225
+ }, internals.safeRenderHeader(expandCol)),
229
226
  render: render,
230
- getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps
231
- })]).call(_context2, _toConsumableArray(others));
227
+ getCellProps: clickArea === 'cell' ? getCellProps : expandCol.getCellProps
228
+ });
229
+ return _toConsumableArray(columns);
232
230
  }
233
231
  };
234
232
  }
@@ -12,7 +12,7 @@ export interface FilterFeatureOptions {
12
12
  keepDataSource?: boolean;
13
13
  /** 过滤模式。单列过滤 single,多列过滤 multiple,默认为多选 */
14
14
  mode?: 'single' | 'multiple';
15
- /**过滤图标 */
15
+ /** 过滤图标 */
16
16
  filterIcon?: ReactNode;
17
17
  /** 是否对触发弹出过滤面板 的 click 事件调用 event.stopPropagation() */
18
18
  stopClickEventPropagation?: boolean;
@@ -65,7 +65,7 @@ function filter() {
65
65
  return (0, _map2.default)(columns).call(columns, dfs);
66
66
 
67
67
  function dfs(col) {
68
- var _a, _b, _c, _d, _e;
68
+ var _a, _b, _c, _d, _e, _f, _g;
69
69
 
70
70
  var result = (0, _extends2.default)({}, col);
71
71
  var filterable = col.code && ((_a = col.features) === null || _a === void 0 ? void 0 : _a.filterable);
@@ -104,12 +104,13 @@ function filter() {
104
104
  };
105
105
 
106
106
  var filterPanel = (_d = col.features) === null || _d === void 0 ? void 0 : _d.filterPanel;
107
- result.title = (0, _concat.default)(_context = []).call(_context, (0, _toConsumableArray2.default)((0, _concat.default)(_context2 = []).call(_context2, (_e = result.title) !== null && _e !== void 0 ? _e : [_internals.internals.safeRenderHeader((0, _extends2.default)((0, _extends2.default)({}, col), {
107
+ var colFilterIcon = (_f = (_e = col.features) === null || _e === void 0 ? void 0 : _e.filterIcon) !== null && _f !== void 0 ? _f : filterIcon;
108
+ result.title = (0, _concat.default)(_context = []).call(_context, (0, _toConsumableArray2.default)((0, _concat.default)(_context2 = []).call(_context2, (_g = result.title) !== null && _g !== void 0 ? _g : [_internals.internals.safeRenderHeader((0, _extends2.default)((0, _extends2.default)({}, col), {
108
109
  title: null
109
110
  }))])), [/*#__PURE__*/_react.default.createElement(_filter2.Filter, {
110
111
  key: "filter",
111
112
  FilterPanelContent: filterPanel,
112
- filterIcon: filterIcon,
113
+ filterIcon: colFilterIcon,
113
114
  filterModel: inputFiltersMap.get(col.code),
114
115
  setFilterModel: handleFilterChanged,
115
116
  setFilter: setFilter,
@@ -157,8 +158,8 @@ function filter() {
157
158
  return [item.key, (0, _extends2.default)({}, item)];
158
159
  }));
159
160
 
160
- function isMatchedFilterCondition(record, rowIndex) {
161
- return !filtersKeys.some(function (key) {
161
+ function isMatchedFilterCondition(record) {
162
+ return filtersKeys.every(function (key) {
162
163
  var _a, _b;
163
164
 
164
165
  var filterItem = inputFiltersMap.get(key);
@@ -172,24 +173,41 @@ function filter() {
172
173
  } else {
173
174
  console.warn("\u5217[".concat(key, "]\u672A\u914D\u7F6E\u7B5B\u9009\u51FD\u6570\uFF0C\u8BF7\u8BBE\u7F6E column.features.filterable \u6765\u4F5C\u4E3A\u8BE5\u5217\u7684\u7B5B\u9009\u51FD\u6570, \u76EE\u524D\u4F7F\u7528\u9ED8\u8BA4\u5305\u542B\u7B5B\u9009\u51FD\u6570"));
174
175
  comparisonFn = (0, _filter.default)(defaultFilterOptionsMap.get('contain'));
175
- } // 不符合过滤条件,退出循环
176
+ }
176
177
 
177
-
178
- return !comparisonFn((0, _filter.default)(filterItem), filterItem)(_internals.internals.safeGetValue(columnsMap.get(key), record, rowIndex), record);
178
+ return comparisonFn((0, _filter.default)(filterItem), filterItem)(_internals.internals.safeGetValue(columnsMap.get(key), record, -1), record);
179
179
  });
180
180
  }
181
181
 
182
- return dataSource.reduce(function (pre, record, rowIndex) {
183
- if (isMatchedFilterCondition(record, rowIndex)) {
184
- return (0, _concat.default)(pre).call(pre, [record]);
185
- }
186
-
187
- return pre;
188
- }, []);
182
+ return layeredFilter(dataSource, isMatchedFilterCondition);
189
183
  }
190
184
 
191
185
  pipeline.dataSource(processDataSource(dataSource));
192
186
  pipeline.columns(processColumns(columns));
193
187
  return pipeline;
194
188
  };
189
+ }
190
+
191
+ function layeredFilter(array, matchFn) {
192
+ return dfs(array);
193
+
194
+ function dfs(rows) {
195
+ var _context6;
196
+
197
+ var parentMatched = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
198
+ return (0, _filter.default)(_context6 = (0, _map2.default)(rows).call(rows, function (row) {
199
+ var currentMatched = matchFn(row);
200
+
201
+ if ((0, _utils.isLeafNode)(row)) {
202
+ return (parentMatched || currentMatched) && (0, _extends2.default)({}, row);
203
+ }
204
+
205
+ var children = row.children;
206
+ var rowAfterFilterChildren = (0, _extends2.default)((0, _extends2.default)({}, row), {
207
+ children: dfs(children, parentMatched || currentMatched)
208
+ });
209
+ var matchedByChildren = !(0, _utils.isLeafNode)(rowAfterFilterChildren);
210
+ return (parentMatched || currentMatched || matchedByChildren) && rowAfterFilterChildren;
211
+ })).call(_context6, Boolean);
212
+ }
195
213
  }
@@ -22,7 +22,7 @@ var DEFAULT_FILTER_OPTIONS = [{
22
22
  data = data + '';
23
23
  }
24
24
 
25
- return (0, _includes.default)(data).call(data, value);
25
+ return (0, _includes.default)(data).call(data, value[0]);
26
26
  };
27
27
  }
28
28
  }, {
@@ -38,7 +38,7 @@ var DEFAULT_FILTER_OPTIONS = [{
38
38
  data = data + '';
39
39
  }
40
40
 
41
- return !(0, _includes.default)(data).call(data, value);
41
+ return !(0, _includes.default)(data).call(data, value[0]);
42
42
  };
43
43
  }
44
44
  }, {
@@ -46,7 +46,7 @@ var DEFAULT_FILTER_OPTIONS = [{
46
46
  key: 'equal',
47
47
  filter: function filter(value) {
48
48
  return function (data) {
49
- return value !== data;
49
+ return value[0] === data;
50
50
  };
51
51
  }
52
52
  }, {
@@ -54,7 +54,7 @@ var DEFAULT_FILTER_OPTIONS = [{
54
54
  key: 'notEqual',
55
55
  filter: function filter(value) {
56
56
  return function (data) {
57
- return value !== data;
57
+ return value[0] !== data;
58
58
  };
59
59
  }
60
60
  }, {
@@ -61,7 +61,8 @@ function multiSelect() {
61
61
  /** 所有有效的 keys(disable 状态为 false) */
62
62
 
63
63
  var allKeys = [];
64
- dataSource.forEach(function (row, rowIndex) {
64
+ var flatDataSource = (0, _utils.collectNodes)(dataSource);
65
+ flatDataSource.forEach(function (row, rowIndex) {
65
66
  var rowKey = _internals.internals.safeGetRowKey(primaryKey, row, rowIndex);
66
67
 
67
68
  fullKeySet.add(rowKey); // 在 allKeys 中排除被禁用的 key
@@ -32,6 +32,8 @@ export interface TreeModeFeatureOptions {
32
32
  stopClickEventPropagation?: boolean;
33
33
  /** 指定表格每一行元信息的记录字段 */
34
34
  treeMetaKey?: string | symbol;
35
+ /** 指定展开列 */
36
+ expandColCode?: string;
35
37
  }
36
38
  export declare function treeMode(opts?: TreeModeFeatureOptions): (pipeline: TablePipeline) => TablePipeline;
37
39
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _sliceInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
3
+ var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
4
4
 
5
5
  var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from");
6
6
 
@@ -16,8 +16,6 @@ Object.defineProperty(exports, "__esModule", {
16
16
  exports.treeMetaSymbol = void 0;
17
17
  exports.treeMode = treeMode;
18
18
 
19
- var _toArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/toArray"));
20
-
21
19
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
22
20
 
23
21
  var _extends3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
@@ -32,7 +30,7 @@ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
32
30
 
33
31
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
34
32
 
35
- var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
33
+ var _findIndex = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find-index"));
36
34
 
37
35
  var _classnames = _interopRequireDefault(require("classnames"));
38
36
 
@@ -48,7 +46,7 @@ var _styles = require("../../base/styles");
48
46
 
49
47
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol2 !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
50
48
 
51
- function _unsupportedIterableToArray(o, minLen) { var _context3; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty2(_context3 = Object.prototype.toString.call(o)).call(_context3, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
49
+ function _unsupportedIterableToArray(o, minLen) { var _context2; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context2 = Object.prototype.toString.call(o)).call(_context2, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
52
50
 
53
51
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
54
52
 
@@ -63,11 +61,6 @@ function treeMode() {
63
61
  var stateKey = 'treeMode';
64
62
  var ctx = pipeline.ctx;
65
63
  var primaryKey = pipeline.ensurePrimaryKey('treeMode');
66
-
67
- if (typeof primaryKey !== 'string') {
68
- throw new Error('treeMode 仅支持字符串作为 primaryKey');
69
- }
70
-
71
64
  var openKeys = (_c = (_b = (_a = opts.openKeys) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultOpenKeys) !== null && _c !== void 0 ? _c : [];
72
65
  var openKeySet = new _set.default(openKeys);
73
66
 
@@ -122,7 +115,9 @@ function treeMode() {
122
115
  try {
123
116
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
124
117
  var node = _step.value;
125
- var rowKey = node[primaryKey];
118
+
119
+ var rowKey = _internals.internals.safeGetRowKey(primaryKey, node, -1);
120
+
126
121
  var expanded = openKeySet.has(rowKey);
127
122
  var isLeaf = isLeafNode(node, {
128
123
  depth: depth,
@@ -152,18 +147,19 @@ function treeMode() {
152
147
  }
153
148
 
154
149
  function processColumns(columns) {
155
- var _context2;
156
-
157
150
  if (columns.length === 0) {
158
151
  return columns;
159
152
  }
160
153
 
161
- var _columns = (0, _toArray2.default)(columns),
162
- firstCol = _columns[0],
163
- others = (0, _slice.default)(_columns).call(_columns, 1);
154
+ var expandColIndex = (0, _findIndex.default)(columns).call(columns, function (_ref) {
155
+ var code = _ref.code;
156
+ return code && opts.expandColCode === code;
157
+ });
158
+ expandColIndex = expandColIndex === -1 ? 0 : expandColIndex;
159
+ var expandCol = columns[expandColIndex];
164
160
 
165
161
  var render = function render(value, record, recordIndex) {
166
- var content = _internals.internals.safeRender(firstCol, record, recordIndex);
162
+ var content = _internals.internals.safeRender(expandCol, record, recordIndex);
167
163
 
168
164
  if (record[treeMetaKey] == null) {
169
165
  // 没有 treeMeta 信息的话,就返回原先的渲染结果
@@ -223,7 +219,7 @@ function treeMode() {
223
219
  };
224
220
 
225
221
  var getCellProps = function getCellProps(value, record, rowIndex) {
226
- var prevProps = _internals.internals.safeGetCellProps(firstCol, record, rowIndex);
222
+ var prevProps = _internals.internals.safeGetCellProps(expandCol, record, rowIndex);
227
223
 
228
224
  if (record[treeMetaKey] == null) {
229
225
  // 没有 treeMeta 信息的话,就返回原先的 cellProps
@@ -252,15 +248,16 @@ function treeMode() {
252
248
  });
253
249
  };
254
250
 
255
- return (0, _concat.default)(_context2 = [(0, _extends3.default)((0, _extends3.default)({}, firstCol), {
251
+ columns[expandColIndex] = (0, _extends3.default)((0, _extends3.default)({}, expandCol), {
256
252
  title: /*#__PURE__*/_react.default.createElement("span", {
257
253
  style: {
258
254
  marginLeft: iconIndent + iconWidth + iconGap
259
255
  }
260
- }, _internals.internals.safeRenderHeader(firstCol)),
256
+ }, _internals.internals.safeRenderHeader(expandCol)),
261
257
  render: render,
262
- getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps
263
- })]).call(_context2, (0, _toConsumableArray2.default)(others));
258
+ getCellProps: clickArea === 'cell' ? getCellProps : expandCol.getCellProps
259
+ });
260
+ return (0, _toConsumableArray2.default)(columns);
264
261
  }
265
262
  };
266
263
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdcloudjs/table",
3
- "version": "1.1.3-canary.6",
3
+ "version": "1.1.3-canary.7",
4
4
  "description": "金蝶 react table 组件",
5
5
  "title": "table",
6
6
  "keywords": [