@visactor/vtable 0.22.4-alpha.0 → 0.23.0

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 (155) hide show
  1. package/cjs/ListTable.d.ts +3 -3
  2. package/cjs/ListTable.js +40 -31
  3. package/cjs/ListTable.js.map +1 -1
  4. package/cjs/PivotTable.d.ts +1 -1
  5. package/cjs/PivotTable.js +19 -17
  6. package/cjs/PivotTable.js.map +1 -1
  7. package/cjs/core/BaseTable.d.ts +1 -0
  8. package/cjs/core/BaseTable.js +5 -1
  9. package/cjs/core/BaseTable.js.map +1 -1
  10. package/cjs/core/TABLE_EVENT_TYPE.d.ts +5 -0
  11. package/cjs/core/TABLE_EVENT_TYPE.js +6 -1
  12. package/cjs/core/TABLE_EVENT_TYPE.js.map +1 -1
  13. package/cjs/core/tableHelper.js +1 -2
  14. package/cjs/core/tableHelper.js.map +1 -1
  15. package/cjs/data/CachedDataSource.d.ts +1 -0
  16. package/cjs/data/CachedDataSource.js +10 -6
  17. package/cjs/data/CachedDataSource.js.map +1 -1
  18. package/cjs/data/DataSource.d.ts +10 -3
  19. package/cjs/data/DataSource.js +159 -95
  20. package/cjs/data/DataSource.js.map +1 -1
  21. package/cjs/event/event.d.ts +2 -0
  22. package/cjs/event/event.js +29 -1
  23. package/cjs/event/event.js.map +1 -1
  24. package/cjs/event/listener/container-dom.js +78 -39
  25. package/cjs/event/listener/container-dom.js.map +1 -1
  26. package/cjs/event/listener/table-group.js +6 -5
  27. package/cjs/event/listener/table-group.js.map +1 -1
  28. package/cjs/event/media-click.js +2 -1
  29. package/cjs/event/sparkline-event.js +1 -2
  30. package/cjs/index.d.ts +1 -1
  31. package/cjs/index.js +1 -1
  32. package/cjs/index.js.map +1 -1
  33. package/cjs/layout/simple-header-layout.d.ts +7 -3
  34. package/cjs/layout/simple-header-layout.js +47 -35
  35. package/cjs/layout/simple-header-layout.js.map +1 -1
  36. package/cjs/scenegraph/component/table-component.js +12 -7
  37. package/cjs/scenegraph/component/table-component.js.map +1 -1
  38. package/cjs/scenegraph/layout/frozen.js +2 -2
  39. package/cjs/scenegraph/layout/frozen.js.map +1 -1
  40. package/cjs/scenegraph/scenegraph.d.ts +3 -0
  41. package/cjs/scenegraph/scenegraph.js +6 -3
  42. package/cjs/scenegraph/scenegraph.js.map +1 -1
  43. package/cjs/scenegraph/select/create-select-border.d.ts +1 -1
  44. package/cjs/scenegraph/select/create-select-border.js +24 -5
  45. package/cjs/scenegraph/select/create-select-border.js.map +1 -1
  46. package/cjs/scenegraph/select/delete-select-border.d.ts +1 -0
  47. package/cjs/scenegraph/select/delete-select-border.js +15 -4
  48. package/cjs/scenegraph/select/delete-select-border.js.map +1 -1
  49. package/cjs/scenegraph/select/move-select-border.js +3 -1
  50. package/cjs/scenegraph/select/move-select-border.js.map +1 -1
  51. package/cjs/scenegraph/select/update-select-border.js +9 -2
  52. package/cjs/scenegraph/select/update-select-border.js.map +1 -1
  53. package/cjs/state/cell-move/index.js +1 -1
  54. package/cjs/state/cell-move/index.js.map +1 -1
  55. package/cjs/state/resize/update-resize-column.js +1 -1
  56. package/cjs/state/resize/update-resize-column.js.map +1 -1
  57. package/cjs/state/select/update-position.js +39 -8
  58. package/cjs/state/select/update-position.js.map +1 -1
  59. package/cjs/state/state.d.ts +16 -0
  60. package/cjs/state/state.js +63 -14
  61. package/cjs/state/state.js.map +1 -1
  62. package/cjs/themes/component.js +1 -1
  63. package/cjs/themes/theme.js +4 -0
  64. package/cjs/themes/theme.js.map +1 -1
  65. package/cjs/tools/util.d.ts +0 -1
  66. package/cjs/tools/util.js +3 -13
  67. package/cjs/tools/util.js.map +1 -1
  68. package/cjs/ts-types/base-table.d.ts +4 -0
  69. package/cjs/ts-types/base-table.js.map +1 -1
  70. package/cjs/ts-types/events.d.ts +26 -0
  71. package/cjs/ts-types/events.js.map +1 -1
  72. package/cjs/ts-types/table-engine.d.ts +4 -4
  73. package/cjs/ts-types/table-engine.js.map +1 -1
  74. package/cjs/ts-types/theme.d.ts +1 -0
  75. package/cjs/ts-types/theme.js.map +1 -1
  76. package/cjs/vrender.js.map +1 -1
  77. package/dist/vtable.js +936 -357
  78. package/dist/vtable.min.js +2 -2
  79. package/es/ListTable.d.ts +3 -3
  80. package/es/ListTable.js +41 -32
  81. package/es/ListTable.js.map +1 -1
  82. package/es/PivotTable.d.ts +1 -1
  83. package/es/PivotTable.js +19 -17
  84. package/es/PivotTable.js.map +1 -1
  85. package/es/core/BaseTable.d.ts +1 -0
  86. package/es/core/BaseTable.js +6 -2
  87. package/es/core/BaseTable.js.map +1 -1
  88. package/es/core/TABLE_EVENT_TYPE.d.ts +5 -0
  89. package/es/core/TABLE_EVENT_TYPE.js +6 -1
  90. package/es/core/TABLE_EVENT_TYPE.js.map +1 -1
  91. package/es/core/tableHelper.js +1 -2
  92. package/es/core/tableHelper.js.map +1 -1
  93. package/es/data/CachedDataSource.d.ts +1 -0
  94. package/es/data/CachedDataSource.js +9 -7
  95. package/es/data/CachedDataSource.js.map +1 -1
  96. package/es/data/DataSource.d.ts +10 -3
  97. package/es/data/DataSource.js +159 -95
  98. package/es/data/DataSource.js.map +1 -1
  99. package/es/event/event.d.ts +2 -0
  100. package/es/event/event.js +29 -1
  101. package/es/event/event.js.map +1 -1
  102. package/es/event/listener/container-dom.js +78 -39
  103. package/es/event/listener/container-dom.js.map +1 -1
  104. package/es/event/listener/table-group.js +6 -5
  105. package/es/event/listener/table-group.js.map +1 -1
  106. package/es/event/media-click.js +2 -1
  107. package/es/event/sparkline-event.js +1 -2
  108. package/es/index.d.ts +1 -1
  109. package/es/index.js +1 -1
  110. package/es/index.js.map +1 -1
  111. package/es/layout/simple-header-layout.d.ts +7 -3
  112. package/es/layout/simple-header-layout.js +47 -35
  113. package/es/layout/simple-header-layout.js.map +1 -1
  114. package/es/scenegraph/component/table-component.js +12 -7
  115. package/es/scenegraph/component/table-component.js.map +1 -1
  116. package/es/scenegraph/layout/frozen.js +2 -2
  117. package/es/scenegraph/layout/frozen.js.map +1 -1
  118. package/es/scenegraph/scenegraph.d.ts +3 -0
  119. package/es/scenegraph/scenegraph.js +7 -4
  120. package/es/scenegraph/scenegraph.js.map +1 -1
  121. package/es/scenegraph/select/create-select-border.d.ts +1 -1
  122. package/es/scenegraph/select/create-select-border.js +24 -5
  123. package/es/scenegraph/select/create-select-border.js.map +1 -1
  124. package/es/scenegraph/select/delete-select-border.d.ts +1 -0
  125. package/es/scenegraph/select/delete-select-border.js +12 -2
  126. package/es/scenegraph/select/delete-select-border.js.map +1 -1
  127. package/es/scenegraph/select/move-select-border.js +3 -1
  128. package/es/scenegraph/select/move-select-border.js.map +1 -1
  129. package/es/scenegraph/select/update-select-border.js +9 -2
  130. package/es/scenegraph/select/update-select-border.js.map +1 -1
  131. package/es/state/cell-move/index.js +1 -1
  132. package/es/state/cell-move/index.js.map +1 -1
  133. package/es/state/resize/update-resize-column.js +1 -1
  134. package/es/state/resize/update-resize-column.js.map +1 -1
  135. package/es/state/select/update-position.js +39 -8
  136. package/es/state/select/update-position.js.map +1 -1
  137. package/es/state/state.d.ts +16 -0
  138. package/es/state/state.js +63 -14
  139. package/es/state/state.js.map +1 -1
  140. package/es/themes/component.js +1 -1
  141. package/es/themes/theme.js +4 -0
  142. package/es/themes/theme.js.map +1 -1
  143. package/es/tools/util.d.ts +0 -1
  144. package/es/tools/util.js +0 -10
  145. package/es/tools/util.js.map +1 -1
  146. package/es/ts-types/base-table.d.ts +4 -0
  147. package/es/ts-types/base-table.js.map +1 -1
  148. package/es/ts-types/events.d.ts +26 -0
  149. package/es/ts-types/events.js.map +1 -1
  150. package/es/ts-types/table-engine.d.ts +4 -4
  151. package/es/ts-types/table-engine.js.map +1 -1
  152. package/es/ts-types/theme.d.ts +1 -0
  153. package/es/ts-types/theme.js.map +1 -1
  154. package/es/vrender.js.map +1 -1
  155. package/package.json +3 -3
@@ -86,13 +86,13 @@ class DataSource extends EventTarget_1.EventTarget {
86
86
  return EVENT_TYPE;
87
87
  }
88
88
  constructor(dataSourceObj, dataConfig, pagination, columnObjs, rowHierarchyType, hierarchyExpandLevel) {
89
- var _a, _b;
89
+ var _a;
90
90
  super(), this.currentIndexedData = [], this.hierarchyExpandLevel = 0, this.hasHierarchyStateExpand = !1,
91
91
  this.beforeChangedRecordsMap = [], this.registedAggregators = {}, this.fieldAggregators = [],
92
92
  this.layoutColumnObjects = [], this.registerAggregators(), this.dataSourceObj = dataSourceObj,
93
- this.dataConfig = dataConfig, this._get = (null == dataSourceObj ? void 0 : dataSourceObj.get.bind(dataSourceObj)) || void 0,
94
- this.layoutColumnObjects = columnObjs, this._source = this.processRecords(null !== (_a = null == dataSourceObj ? void 0 : dataSourceObj.source) && void 0 !== _a ? _a : dataSourceObj),
95
- this._sourceLength = (null === (_b = this._source) || void 0 === _b ? void 0 : _b.length) || 0,
93
+ this.dataConfig = dataConfig, this._get = null == dataSourceObj ? void 0 : dataSourceObj.get,
94
+ this.layoutColumnObjects = columnObjs, this._source = (null == dataSourceObj ? void 0 : dataSourceObj.records) ? this.processRecords(null == dataSourceObj ? void 0 : dataSourceObj.records) : dataSourceObj,
95
+ this._sourceLength = (null === (_a = this._source) || void 0 === _a ? void 0 : _a.length) || 0,
96
96
  this.sortedIndexMap = new Map, this._currentPagerIndexedData = [], this.userPagination = pagination,
97
97
  this.pagination = pagination || {
98
98
  totalCount: this._sourceLength,
@@ -102,7 +102,7 @@ class DataSource extends EventTarget_1.EventTarget {
102
102
  this.currentIndexedData = Array.from({
103
103
  length: this._sourceLength
104
104
  }, ((_, i) => i)), "tree" === rowHierarchyType && this.initTreeHierarchyState(),
105
- this.updatePagerData();
105
+ this.rowHierarchyType = rowHierarchyType, this.updatePagerData();
106
106
  }
107
107
  initTreeHierarchyState() {
108
108
  var _a;
@@ -111,8 +111,8 @@ class DataSource extends EventTarget_1.EventTarget {
111
111
  }, ((_, i) => i));
112
112
  let nodeLength = this._sourceLength;
113
113
  for (let i = 0; i < nodeLength; i++) {
114
- const indexKey = this.currentIndexedData[i], nodeData = this.getOriginalRecord(indexKey);
115
- if ((null === (_a = nodeData.children) || void 0 === _a ? void 0 : _a.length) > 0) {
114
+ const indexKey = this.currentIndexedData[i], nodeData = this.getOriginalRecord(indexKey), children = null !== (_a = nodeData.filteredChildren) && void 0 !== _a ? _a : nodeData.children;
115
+ if ((null == children ? void 0 : children.length) > 0) {
116
116
  if (this.hierarchyExpandLevel > 1 ? !nodeData.hierarchyState && (nodeData.hierarchyState = ts_types_1.HierarchyState.expand) : !nodeData.hierarchyState && (nodeData.hierarchyState = ts_types_1.HierarchyState.collapse),
117
117
  this.hasHierarchyStateExpand = !0, nodeData.hierarchyState === ts_types_1.HierarchyState.collapse) continue;
118
118
  const childrenLength = this.initChildrenNodeHierarchy(indexKey, this.hierarchyExpandLevel, 2, nodeData);
@@ -149,18 +149,29 @@ class DataSource extends EventTarget_1.EventTarget {
149
149
  }
150
150
  }
151
151
  processRecords(records) {
152
- var _a, _b;
152
+ var _a, _b, _c, _d, _e, _f, _g, _h;
153
153
  this._generateFieldAggragations();
154
- const filteredRecords = [], isHasAggregation = this.fieldAggregators.length >= 1, isHasFilterRule = (null === (_b = null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules) || void 0 === _b ? void 0 : _b.length) >= 1;
155
- if (isHasFilterRule || isHasAggregation) {
154
+ const filteredRecords = [], isHasAggregation = this.fieldAggregators.length >= 1;
155
+ if ((null === (_b = null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules) || void 0 === _b ? void 0 : _b.length) >= 1 || (null === (_c = this.lastFilterRules) || void 0 === _c ? void 0 : _c.length) >= 1 || isHasAggregation) {
156
156
  for (let i = 0, len = records.length; i < len; i++) {
157
157
  const record = records[i];
158
- isHasFilterRule ? this.filterRecord(record) && (filteredRecords.push(record), isHasAggregation && this.processRecord(record)) : isHasAggregation && this.processRecord(record);
158
+ (null === (_e = null === (_d = this.dataConfig) || void 0 === _d ? void 0 : _d.filterRules) || void 0 === _e ? void 0 : _e.length) >= 1 ? this.filterRecord(record) && (filteredRecords.push(record),
159
+ "tree" === this.rowHierarchyType && record.children && (record.filteredChildren = this.filteredChildren(record.children)),
160
+ isHasAggregation && this.processRecord(record)) : (null === (_f = this.lastFilterRules) || void 0 === _f ? void 0 : _f.length) >= 1 ? (this.clearFilteredChildren(record),
161
+ isHasAggregation && this.processRecord(record)) : isHasAggregation && this.processRecord(record);
159
162
  }
160
- if (isHasFilterRule) return filteredRecords;
163
+ if ((null === (_h = null === (_g = this.dataConfig) || void 0 === _g ? void 0 : _g.filterRules) || void 0 === _h ? void 0 : _h.length) >= 1) return filteredRecords;
161
164
  }
162
165
  return records;
163
166
  }
167
+ filteredChildren(records) {
168
+ const filteredRecords = [];
169
+ for (let i = 0, len = records.length; i < len; i++) {
170
+ const record = records[i];
171
+ this.filterRecord(record) && (filteredRecords.push(record), record.children && (record.filteredChildren = this.filteredChildren(record.children)));
172
+ }
173
+ return filteredRecords;
174
+ }
164
175
  processRecord(record) {
165
176
  for (let i = 0; i < this.fieldAggregators.length; i++) {
166
177
  this.fieldAggregators[i].push(record);
@@ -169,12 +180,12 @@ class DataSource extends EventTarget_1.EventTarget {
169
180
  initChildrenNodeHierarchy(indexKey, hierarchyExpandLevel, currentLevel, nodeData) {
170
181
  var _a, _b, _c;
171
182
  let childTotalLength = 0;
172
- const nodeLength = null !== (_b = null === (_a = nodeData.children) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0;
183
+ const nodeLength = nodeData.filteredChildren ? nodeData.filteredChildren.length : null !== (_b = null === (_a = nodeData.children) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0;
173
184
  for (let j = 0; j < nodeLength; j++) {
174
185
  (currentLevel <= hierarchyExpandLevel || nodeData.hierarchyState === ts_types_1.HierarchyState.expand) && (childTotalLength += 1);
175
- const childNodeData = nodeData.children[j], childIndexKey = Array.isArray(indexKey) ? indexKey.concat(j) : [ indexKey, j ];
186
+ const childNodeData = nodeData.filteredChildren ? nodeData.filteredChildren[j] : nodeData.children[j], childIndexKey = Array.isArray(indexKey) ? indexKey.concat(j) : [ indexKey, j ];
176
187
  (currentLevel <= hierarchyExpandLevel || nodeData.hierarchyState === ts_types_1.HierarchyState.expand) && this.currentIndexedData.splice(this.currentIndexedData.indexOf(indexKey) + childTotalLength, 0, childIndexKey),
177
- (null === (_c = childNodeData.children) || void 0 === _c ? void 0 : _c.length) > 0 && (currentLevel < hierarchyExpandLevel || childNodeData.hierarchyState === ts_types_1.HierarchyState.expand ? (!childNodeData.hierarchyState && (childNodeData.hierarchyState = ts_types_1.HierarchyState.expand),
188
+ (childNodeData.filteredChildren ? childNodeData.filteredChildren.length > 0 : (null === (_c = childNodeData.children) || void 0 === _c ? void 0 : _c.length) > 0) && (currentLevel < hierarchyExpandLevel || childNodeData.hierarchyState === ts_types_1.HierarchyState.expand ? (!childNodeData.hierarchyState && (childNodeData.hierarchyState = ts_types_1.HierarchyState.expand),
178
189
  this.hasHierarchyStateExpand = !0) : !childNodeData.hierarchyState && (childNodeData.hierarchyState = ts_types_1.HierarchyState.collapse)),
179
190
  childNodeData.hierarchyState === ts_types_1.HierarchyState.expand && (childTotalLength += this.initChildrenNodeHierarchy(childIndexKey, hierarchyExpandLevel, currentLevel + 1, childNodeData));
180
191
  }
@@ -195,6 +206,9 @@ class DataSource extends EventTarget_1.EventTarget {
195
206
  firstLevelIndex >= startIndex && firstLevelIndex < endIndex) this._currentPagerIndexedData.push(currentIndexedData[i]); else if (firstLevelIndex >= endIndex) break;
196
207
  } else if (this._sourceLength > 0) throw new Error("currentIndexedData should has values!");
197
208
  }
209
+ get records() {
210
+ return Array.isArray(this._source) ? this._source : [];
211
+ }
198
212
  get source() {
199
213
  return this._source;
200
214
  }
@@ -231,10 +245,12 @@ class DataSource extends EventTarget_1.EventTarget {
231
245
  this.pushChildrenNode(indexed, ts_types_1.HierarchyState.expand, data), this.hasHierarchyStateExpand = !0; else if (state === ts_types_1.HierarchyState.expand) {
232
246
  let childrenLength = 0;
233
247
  const computeChildrenNodeLength = (indexKey, hierarchyState, nodeData) => {
234
- if (hierarchyState && hierarchyState !== ts_types_1.HierarchyState.collapse && hierarchyState !== ts_types_1.HierarchyState.none && nodeData.children) for (let i = 0; i < nodeData.children.length; i++) {
248
+ if (!hierarchyState || hierarchyState === ts_types_1.HierarchyState.collapse || hierarchyState === ts_types_1.HierarchyState.none) return;
249
+ const children = nodeData.filteredChildren ? nodeData.filteredChildren : nodeData.children;
250
+ if (children) for (let i = 0; i < children.length; i++) {
235
251
  childrenLength += 1;
236
252
  const childIndex = Array.isArray(indexKey) ? indexKey.concat([ i ]) : [ indexKey, i ];
237
- computeChildrenNodeLength(childIndex, nodeData.children[i].hierarchyState, nodeData.children[i]);
253
+ computeChildrenNodeLength(childIndex, children[i].hierarchyState, children[i]);
238
254
  }
239
255
  };
240
256
  computeChildrenNodeLength(indexed, state, data), this.currentIndexedData.splice(this.currentIndexedData.indexOf(indexed) + 1, childrenLength),
@@ -244,23 +260,25 @@ class DataSource extends EventTarget_1.EventTarget {
244
260
  return (0, diff_cell_1.calculateArrayDiff)(oldIndexedData, this.currentIndexedData);
245
261
  }
246
262
  pushChildrenNode(indexKey, hierarchyState, nodeData) {
263
+ var _a;
247
264
  if (!hierarchyState || hierarchyState === ts_types_1.HierarchyState.collapse || hierarchyState === ts_types_1.HierarchyState.none) return 0;
248
265
  let childrenLength = 0;
249
- if (nodeData.children) {
266
+ const children = nodeData.filteredChildren ? nodeData.filteredChildren : nodeData.children;
267
+ if (children) {
250
268
  const subNodeSortedIndexArray = Array.from({
251
- length: nodeData.children.length
269
+ length: children.length
252
270
  }, ((_, i) => i));
253
271
  this.lastOrder && "normal" !== this.lastOrder && this.lastOrderField && sort.sort((index => (0,
254
272
  vutils_1.isValid)(subNodeSortedIndexArray[index]) ? subNodeSortedIndexArray[index] : subNodeSortedIndexArray[index] = index), ((index, rel) => {
255
273
  subNodeSortedIndexArray[index] = rel;
256
- }), nodeData.children.length, this.lastOrderFn, this.lastOrder, (index => this.getOriginalField(Array.isArray(indexKey) ? indexKey.concat([ index ]) : [ indexKey, index ], this.lastOrderField)));
274
+ }), children.length, this.lastOrderFn, this.lastOrder, (index => this.getOriginalField(Array.isArray(indexKey) ? indexKey.concat([ index ]) : [ indexKey, index ], this.lastOrderField)));
257
275
  for (let i = 0; i < subNodeSortedIndexArray.length; i++) {
258
276
  childrenLength += 1;
259
277
  const childIndex = Array.isArray(indexKey) ? indexKey.concat([ subNodeSortedIndexArray[i] ]) : [ indexKey, subNodeSortedIndexArray[i] ];
260
278
  this.currentIndexedData.splice(this.currentIndexedData.indexOf(indexKey) + childrenLength, 0, childIndex);
261
279
  const childData = this.getOriginalRecord(childIndex);
262
- !nodeData.children[i].hierarchyState && childData.children && (nodeData.children[i].hierarchyState = ts_types_1.HierarchyState.collapse),
263
- childrenLength += this.pushChildrenNode(childIndex, nodeData.children[i].hierarchyState, nodeData.children[subNodeSortedIndexArray[i]]);
280
+ !childData.hierarchyState && (null !== (_a = childData.filteredChildren) && void 0 !== _a ? _a : childData.children) && (childData.hierarchyState = ts_types_1.HierarchyState.collapse),
281
+ childrenLength += this.pushChildrenNode(childIndex, childData.hierarchyState, children[subNodeSortedIndexArray[i]]);
264
282
  }
265
283
  }
266
284
  return childrenLength;
@@ -283,74 +301,94 @@ class DataSource extends EventTarget_1.EventTarget {
283
301
  }
284
302
  }
285
303
  setRecord(record, index) {
286
- const indexed = this.getIndexKey(index);
287
- if (Array.isArray(indexed)) {
288
- const c_node_index = indexed[indexed.length - 1];
289
- this.getOriginalRecord(indexed.slice(0, indexed.length - 1)).children.splice(c_node_index, 1, record);
290
- } else this.source.splice(indexed, 1, record);
304
+ var _a, _b;
305
+ let isAdd = !0;
306
+ if ((null === (_b = null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules) || void 0 === _b ? void 0 : _b.length) >= 1 && (this.filterRecord(record) ? "tree" === this.rowHierarchyType && record.children && (record.filteredChildren = this.filteredChildren(record.children)) : isAdd = !1),
307
+ isAdd && Array.isArray(this.records)) {
308
+ const indexed = this.getIndexKey(index);
309
+ Array.isArray(indexed) || this.records.splice(indexed, 1, record);
310
+ }
291
311
  }
292
312
  addRecord(record, index) {
293
- if (this.source.splice(index, 0, record), this.currentIndexedData.push(this.currentIndexedData.length),
294
- this._sourceLength += 1, this.initTreeHierarchyState(), this.userPagination) {
295
- this.pagination.totalCount = this._sourceLength;
296
- const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
297
- index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
298
- } else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
299
- this.updatePagerData();
313
+ var _a;
314
+ if (Array.isArray(this.records)) {
315
+ if (this.records.splice(index, 0, record), this.currentIndexedData.push(this.currentIndexedData.length),
316
+ this._sourceLength += 1, "tree" === this.rowHierarchyType && this.initTreeHierarchyState(),
317
+ this.userPagination) {
318
+ this.pagination.totalCount = this._sourceLength;
319
+ const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
320
+ index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
321
+ } else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
322
+ this.updatePagerData();
323
+ (null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, 1);
324
+ }
300
325
  }
301
326
  addRecords(recordArr, index) {
302
- if (Array.isArray(recordArr)) {
303
- this.source.splice(index, 0, ...recordArr);
304
- for (let i = 0; i < recordArr.length; i++) this.currentIndexedData.push(this.currentIndexedData.length);
305
- this._sourceLength += recordArr.length;
327
+ var _a;
328
+ if (Array.isArray(this.records)) {
329
+ if (Array.isArray(recordArr)) {
330
+ this.records.splice(index, 0, ...recordArr);
331
+ for (let i = 0; i < recordArr.length; i++) this.currentIndexedData.push(this.currentIndexedData.length);
332
+ this._sourceLength += recordArr.length;
333
+ }
334
+ if (this.userPagination) {
335
+ this.pagination.totalCount = this._sourceLength;
336
+ const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
337
+ index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
338
+ } else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
339
+ this.updatePagerData();
340
+ (null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, recordArr.length);
306
341
  }
307
- if (this.userPagination) {
308
- this.pagination.totalCount = this._sourceLength;
309
- const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
310
- index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
311
- } else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
312
- this.updatePagerData();
313
342
  }
314
343
  addRecordForSorted(record) {
315
- this.source.push(record), this.currentIndexedData.push(this.currentIndexedData.length),
344
+ Array.isArray(this.records) && (this.records.push(record), this.currentIndexedData.push(this.currentIndexedData.length),
316
345
  this._sourceLength += 1, this.sortedIndexMap.clear(), this.userPagination || (this.pagination.perPageCount = this._sourceLength,
317
- this.pagination.totalCount = this._sourceLength);
346
+ this.pagination.totalCount = this._sourceLength));
318
347
  }
319
348
  addRecordsForSorted(recordArr) {
320
- if (Array.isArray(recordArr)) {
321
- this.source.push(...recordArr);
322
- for (let i = 0; i < recordArr.length; i++) this.currentIndexedData.push(this.currentIndexedData.length);
323
- this._sourceLength += recordArr.length, this.sortedIndexMap.clear();
349
+ if (Array.isArray(this.records)) {
350
+ if (Array.isArray(recordArr)) {
351
+ this.records.push(...recordArr);
352
+ for (let i = 0; i < recordArr.length; i++) this.currentIndexedData.push(this.currentIndexedData.length);
353
+ this._sourceLength += recordArr.length, this.sortedIndexMap.clear();
354
+ }
355
+ this.userPagination || (this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength);
324
356
  }
325
- this.userPagination || (this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength);
326
357
  }
327
358
  deleteRecords(recordIndexs) {
328
- const realDeletedRecordIndexs = [], recordIndexsMaxToMin = recordIndexs.sort(((a, b) => b - a));
329
- for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
330
- const recordIndex = recordIndexsMaxToMin[index];
331
- recordIndex >= this._sourceLength || recordIndex < 0 || (realDeletedRecordIndexs.push(recordIndex),
332
- this.source.splice(recordIndex, 1), this.currentIndexedData.pop(), this._sourceLength -= 1);
359
+ var _a;
360
+ if (Array.isArray(this.records)) {
361
+ const realDeletedRecordIndexs = [], recordIndexsMaxToMin = recordIndexs.sort(((a, b) => b - a));
362
+ for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
363
+ const recordIndex = recordIndexsMaxToMin[index];
364
+ recordIndex >= this._sourceLength || recordIndex < 0 || (realDeletedRecordIndexs.push(recordIndex),
365
+ this.records.splice(recordIndex, 1), this.currentIndexedData.pop(), this._sourceLength -= 1);
366
+ }
367
+ return this.userPagination || (this.pagination.perPageCount = this._sourceLength,
368
+ this.pagination.totalCount = this._sourceLength), this.updatePagerData(), (null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.deleted) && this.dataSourceObj.deleted(realDeletedRecordIndexs),
369
+ realDeletedRecordIndexs;
333
370
  }
334
- return this.userPagination || (this.pagination.perPageCount = this._sourceLength,
335
- this.pagination.totalCount = this._sourceLength), this.updatePagerData(), realDeletedRecordIndexs;
371
+ return [];
336
372
  }
337
373
  deleteRecordsForSorted(recordIndexs) {
338
- const recordIndexsMaxToMin = recordIndexs.sort(((a, b) => b - a));
339
- for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
340
- const recordIndex = recordIndexsMaxToMin[index];
341
- if (recordIndex >= this._sourceLength || recordIndex < 0) continue;
342
- const rawIndex = this.currentIndexedData[recordIndex];
343
- this.source.splice(rawIndex, 1), this._sourceLength -= 1;
374
+ if (Array.isArray(this.records)) {
375
+ const recordIndexsMaxToMin = recordIndexs.sort(((a, b) => b - a));
376
+ for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
377
+ const recordIndex = recordIndexsMaxToMin[index];
378
+ if (recordIndex >= this._sourceLength || recordIndex < 0) continue;
379
+ const rawIndex = this.currentIndexedData[recordIndex];
380
+ this.records.splice(rawIndex, 1), this._sourceLength -= 1;
381
+ }
382
+ this.sortedIndexMap.clear(), this.userPagination || (this.pagination.perPageCount = this._sourceLength,
383
+ this.pagination.totalCount = this._sourceLength);
344
384
  }
345
- this.sortedIndexMap.clear(), this.userPagination || (this.pagination.perPageCount = this._sourceLength,
346
- this.pagination.totalCount = this._sourceLength);
347
385
  }
348
386
  updateRecords(records, recordIndexs) {
349
387
  const realDeletedRecordIndexs = [];
350
388
  for (let index = 0; index < recordIndexs.length; index++) {
351
389
  const recordIndex = recordIndexs[index];
352
390
  recordIndex >= this._sourceLength || recordIndex < 0 || (realDeletedRecordIndexs.push(recordIndex),
353
- this.source[recordIndex] = records[index]);
391
+ this.records[recordIndex] = records[index]);
354
392
  }
355
393
  return this.userPagination && this.updatePagerData(), realDeletedRecordIndexs;
356
394
  }
@@ -361,7 +399,7 @@ class DataSource extends EventTarget_1.EventTarget {
361
399
  if (recordIndex >= this._sourceLength || recordIndex < 0) continue;
362
400
  const rawIndex = this.currentIndexedData[recordIndex];
363
401
  if ("number" != typeof rawIndex) return;
364
- realDeletedRecordIndexs.push(recordIndex), this.source[rawIndex] = records[index];
402
+ realDeletedRecordIndexs.push(recordIndex), this.records[rawIndex] = records[index];
365
403
  }
366
404
  this.sortedIndexMap.clear();
367
405
  }
@@ -390,18 +428,23 @@ class DataSource extends EventTarget_1.EventTarget {
390
428
  }, this.sortedIndexMap.set(field, filedMap)), filedMap[order] = sortedIndexArray,
391
429
  this.updatePagerData(), this.fireListeners(EVENT_TYPE.CHANGE_ORDER, null);
392
430
  }
393
- filterRecord(record) {
431
+ clearFilteredChildren(record) {
394
432
  var _a, _b;
433
+ record.filteredChildren = void 0;
434
+ for (let i = 0; null !== (_b = i < (null === (_a = record.children) || void 0 === _a ? void 0 : _a.length)) && void 0 !== _b && _b; i++) this.clearFilteredChildren(record.children[i]);
435
+ }
436
+ filterRecord(record) {
437
+ var _a, _b, _c;
395
438
  let isReserved = !0;
396
- for (let i = 0; i < this.dataConfig.filterRules.length; i++) {
397
- const filterRule = null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules[i];
439
+ for (let i = 0; i < (null === (_a = this.dataConfig.filterRules) || void 0 === _a ? void 0 : _a.length); i++) {
440
+ const filterRule = null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules[i];
398
441
  if (filterRule.filterKey) {
399
442
  const filterValue = record[filterRule.filterKey];
400
443
  if (-1 === filterRule.filteredValues.indexOf(filterValue)) {
401
444
  isReserved = !1;
402
445
  break;
403
446
  }
404
- } else if (!(null === (_b = filterRule.filterFunc) || void 0 === _b ? void 0 : _b.call(filterRule, record))) {
447
+ } else if (!(null === (_c = filterRule.filterFunc) || void 0 === _c ? void 0 : _c.call(filterRule, record))) {
405
448
  isReserved = !1;
406
449
  break;
407
450
  }
@@ -410,7 +453,8 @@ class DataSource extends EventTarget_1.EventTarget {
410
453
  }
411
454
  updateFilterRulesForSorted(filterRules) {
412
455
  var _a, _b, _c;
413
- this.dataConfig.filterRules = filterRules, this._source = this.processRecords(null !== (_b = null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.source) && void 0 !== _b ? _b : this.dataSourceObj),
456
+ this.lastFilterRules = this.dataConfig.filterRules, this.dataConfig.filterRules = filterRules,
457
+ this._source = this.processRecords(null !== (_b = null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.records) && void 0 !== _b ? _b : this.dataSourceObj),
414
458
  this._sourceLength = (null === (_c = this._source) || void 0 === _c ? void 0 : _c.length) || 0,
415
459
  this.sortedIndexMap.clear(), this.currentIndexedData = Array.from({
416
460
  length: this._sourceLength
@@ -419,12 +463,14 @@ class DataSource extends EventTarget_1.EventTarget {
419
463
  }
420
464
  updateFilterRules(filterRules) {
421
465
  var _a, _b, _c;
422
- this.dataConfig.filterRules = filterRules, this._source = this.processRecords(null !== (_b = null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.source) && void 0 !== _b ? _b : this.dataSourceObj),
466
+ this.lastFilterRules = this.dataConfig.filterRules, this.dataConfig.filterRules = filterRules,
467
+ this._source = this.processRecords(null !== (_b = null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.records) && void 0 !== _b ? _b : this.dataSourceObj),
423
468
  this._sourceLength = (null === (_c = this._source) || void 0 === _c ? void 0 : _c.length) || 0,
424
469
  this.currentIndexedData = Array.from({
425
470
  length: this._sourceLength
426
471
  }, ((_, i) => i)), this.userPagination || (this.pagination.perPageCount = this._sourceLength,
427
- this.pagination.totalCount = this._sourceLength), this.updatePagerData();
472
+ this.pagination.totalCount = this._sourceLength, "tree" === this.rowHierarchyType && this.initTreeHierarchyState()),
473
+ this.updatePagerData();
428
474
  }
429
475
  clearSortedIndexMap() {
430
476
  this.lastOrderField && this.lastOrder && this.sortedIndexMap.forEach(((sortMap, key) => {
@@ -450,7 +496,7 @@ class DataSource extends EventTarget_1.EventTarget {
450
496
  }
451
497
  release() {
452
498
  var _a;
453
- null === (_a = super.release) || void 0 === _a || _a.call(this);
499
+ null === (_a = super.release) || void 0 === _a || _a.call(this), this.lastFilterRules = null;
454
500
  }
455
501
  clearSortedMap() {
456
502
  this.currentIndexedData && (this.currentIndexedData.length = 0), this.currentIndexedData = null,
@@ -462,14 +508,18 @@ class DataSource extends EventTarget_1.EventTarget {
462
508
  this.currentIndexedData = null, this.currentPagerIndexedData.length = 0;
463
509
  }
464
510
  getOriginalRecord(dataIndex) {
465
- var _a;
466
- return (null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules) ? this.source[dataIndex] : getValue(this._get(dataIndex), (val => {
511
+ let data;
512
+ return data = this.dataSourceObj.records ? Array.isArray(dataIndex) ? getValueFromDeepArray(this.records, dataIndex) : this.records[dataIndex] : this._get(dataIndex),
513
+ getValue(data, (val => {
467
514
  this.recordPromiseCallBack(dataIndex, val);
468
515
  }));
469
516
  }
470
517
  getRawRecord(dataIndex) {
471
518
  var _a;
472
- return (null === (_a = this.beforeChangedRecordsMap) || void 0 === _a ? void 0 : _a[dataIndex]) ? this.beforeChangedRecordsMap[dataIndex] : getValue(this._get(dataIndex), (val => {
519
+ if (null === (_a = this.beforeChangedRecordsMap) || void 0 === _a ? void 0 : _a[dataIndex]) return this.beforeChangedRecordsMap[dataIndex];
520
+ let data;
521
+ return data = this.dataSourceObj.records ? Array.isArray(dataIndex) ? getValueFromDeepArray(this.records, dataIndex) : this.records[dataIndex] : this._get(dataIndex),
522
+ getValue(data, (val => {
473
523
  this.recordPromiseCallBack(dataIndex, val);
474
524
  }));
475
525
  }
@@ -512,6 +562,7 @@ class DataSource extends EventTarget_1.EventTarget {
512
562
  return !0;
513
563
  }
514
564
  reorderRecord(sourceIndex, targetIndex) {
565
+ var _a;
515
566
  if ("asc" !== this.lastOrder && "desc" !== this.lastOrder && this.isCanExchangeOrder(sourceIndex, targetIndex)) if (this.hasHierarchyStateExpand) {
516
567
  let sourceI, targetI, sourceIndexs = this.currentPagerIndexedData[sourceIndex], targetIndexs = this.currentPagerIndexedData[targetIndex];
517
568
  if (sourceIndexs = Array.isArray(sourceIndexs) ? [ ...sourceIndexs ] : [ sourceIndexs ],
@@ -524,37 +575,37 @@ class DataSource extends EventTarget_1.EventTarget {
524
575
  }
525
576
  if (sourceI = sourceIndexs.splice(sourceIndexs.length - 1, 1)[0], targetI = targetIndexs.splice(targetIndexs.length - 1, 1)[0],
526
577
  sourceIndexs.length >= 1) {
527
- const parent = this.getOriginalRecord(sourceIndexs), sourceIds = parent.children.splice(sourceI, 1);
528
- sourceIds.unshift(targetI, 0), Array.prototype.splice.apply(parent.children, sourceIds);
578
+ const parent = this.getOriginalRecord(sourceIndexs), sourceIds = parent.filteredChildren ? parent.filteredChildren.splice(sourceI, 1) : parent.children.splice(sourceI, 1);
579
+ sourceIds.unshift(targetI, 0), Array.prototype.splice.apply(null !== (_a = parent.filteredChildren) && void 0 !== _a ? _a : parent.children, sourceIds);
529
580
  } else {
530
- const sourceIds = this.source.splice(sourceI, 1);
531
- sourceIds.unshift(targetI, 0), Array.prototype.splice.apply(this.source, sourceIds);
581
+ const sourceIds = this.records.splice(sourceI, 1);
582
+ sourceIds.unshift(targetI, 0), Array.prototype.splice.apply(this.records, sourceIds);
532
583
  }
533
584
  } else {
534
585
  sourceI = this.currentPagerIndexedData[sourceIndex], targetI = this.currentPagerIndexedData[targetIndex];
535
- const records = this.source.splice(sourceI, 1);
536
- records.unshift(targetI, 0), Array.prototype.splice.apply(this.source, records);
586
+ const records = this.records.splice(sourceI, 1);
587
+ records.unshift(targetI, 0), Array.prototype.splice.apply(this.records, records);
537
588
  }
538
589
  this.restoreTreeHierarchyState(), this.updatePagerData();
539
590
  } else {
540
- const records = this.source.splice(sourceIndex, 1);
541
- records.unshift(targetIndex, 0), Array.prototype.splice.apply(this.source, records);
591
+ const records = this.records.splice(sourceIndex, 1);
592
+ records.unshift(targetIndex, 0), Array.prototype.splice.apply(this.records, records);
542
593
  }
543
594
  }
544
595
  restoreTreeHierarchyState() {
545
- var _a;
596
+ var _a, _b;
546
597
  if (this.hierarchyExpandLevel) {
547
598
  for (let i = 0; i < this._sourceLength; i++) {
548
599
  const nodeData = this.getOriginalRecord(i);
549
- nodeData.children && !nodeData.hierarchyState && (nodeData.hierarchyState = ts_types_1.HierarchyState.collapse);
600
+ (null !== (_a = nodeData.filteredChildren) && void 0 !== _a ? _a : nodeData.children) && !nodeData.hierarchyState && (nodeData.hierarchyState = ts_types_1.HierarchyState.collapse);
550
601
  }
551
602
  this.currentIndexedData = Array.from({
552
603
  length: this._sourceLength
553
604
  }, ((_, i) => i));
554
605
  let nodeLength = this._sourceLength;
555
606
  for (let i = 0; i < nodeLength; i++) {
556
- const indexKey = this.currentIndexedData[i], nodeData = this.getOriginalRecord(indexKey);
557
- if ((null === (_a = nodeData.children) || void 0 === _a ? void 0 : _a.length) > 0 && nodeData.hierarchyState === ts_types_1.HierarchyState.expand) {
607
+ const indexKey = this.currentIndexedData[i], nodeData = this.getOriginalRecord(indexKey), children = null !== (_b = nodeData.filteredChildren) && void 0 !== _b ? _b : nodeData.children;
608
+ if ((null == children ? void 0 : children.length) > 0 && nodeData.hierarchyState === ts_types_1.HierarchyState.expand) {
558
609
  this.hasHierarchyStateExpand = !0;
559
610
  const childrenLength = this.restoreChildrenNodeHierarchy(indexKey, nodeData);
560
611
  i += childrenLength, nodeLength += childrenLength;
@@ -565,10 +616,10 @@ class DataSource extends EventTarget_1.EventTarget {
565
616
  restoreChildrenNodeHierarchy(indexKey, nodeData) {
566
617
  var _a, _b;
567
618
  let childTotalLength = 0;
568
- const nodeLength = null !== (_b = null === (_a = nodeData.children) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0;
619
+ const children = null !== (_a = nodeData.filteredChildren) && void 0 !== _a ? _a : nodeData.children, nodeLength = null !== (_b = null == children ? void 0 : children.length) && void 0 !== _b ? _b : 0;
569
620
  for (let j = 0; j < nodeLength; j++) {
570
621
  nodeData.hierarchyState === ts_types_1.HierarchyState.expand && (childTotalLength += 1);
571
- const childNodeData = nodeData.children[j], childIndexKey = Array.isArray(indexKey) ? indexKey.concat(j) : [ indexKey, j ];
622
+ const childNodeData = children[j], childIndexKey = Array.isArray(indexKey) ? indexKey.concat(j) : [ indexKey, j ];
572
623
  nodeData.hierarchyState === ts_types_1.HierarchyState.expand && this.currentIndexedData.splice(this.currentIndexedData.indexOf(indexKey) + childTotalLength, 0, childIndexKey),
573
624
  childTotalLength += this.restoreChildrenNodeHierarchy(childIndexKey, childNodeData);
574
625
  }
@@ -576,8 +627,21 @@ class DataSource extends EventTarget_1.EventTarget {
576
627
  }
577
628
  }
578
629
 
630
+ function getValueFromDeepArray(array, index) {
631
+ var _a;
632
+ let result = array;
633
+ for (let i = 0; i < index.length; i++) {
634
+ const currentIdx = index[i];
635
+ if (!result[currentIdx]) return;
636
+ result = result[currentIdx];
637
+ const children = null !== (_a = result.filteredChildren) && void 0 !== _a ? _a : null == result ? void 0 : result.children;
638
+ children && i + 1 < index.length && (result = children);
639
+ }
640
+ return result;
641
+ }
642
+
643
+ //# sourceMappingURL=DataSource.js.map
579
644
  exports.DataSource = DataSource, DataSource.EMPTY = new DataSource({
580
645
  get() {},
581
646
  length: 0
582
- });
583
- //# sourceMappingURL=DataSource.js.map
647
+ });