@visactor/vtable 1.5.2 → 1.5.3-alpha.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 (123) hide show
  1. package/cjs/ListTable.d.ts +1 -0
  2. package/cjs/ListTable.js +23 -191
  3. package/cjs/ListTable.js.map +1 -1
  4. package/cjs/core/BaseTable.d.ts +5 -3
  5. package/cjs/core/BaseTable.js +8 -79
  6. package/cjs/core/BaseTable.js.map +1 -1
  7. package/cjs/core/group-helper.d.ts +6 -0
  8. package/cjs/core/group-helper.js +22 -0
  9. package/cjs/core/group-helper.js.map +1 -0
  10. package/cjs/core/record-helper.d.ts +6 -0
  11. package/cjs/core/record-helper.js +230 -0
  12. package/cjs/core/record-helper.js.map +1 -0
  13. package/cjs/core/style-helper.d.ts +3 -0
  14. package/cjs/core/style-helper.js +110 -0
  15. package/cjs/core/style-helper.js.map +1 -0
  16. package/cjs/core/tableHelper.d.ts +0 -2
  17. package/cjs/core/tableHelper.js +9 -18
  18. package/cjs/core/tableHelper.js.map +1 -1
  19. package/cjs/data/CachedDataSource.d.ts +10 -1
  20. package/cjs/data/CachedDataSource.js +78 -3
  21. package/cjs/data/CachedDataSource.js.map +1 -1
  22. package/cjs/dataset/statistics-helper.js +0 -1
  23. package/cjs/event/event.js +2 -1
  24. package/cjs/event/listener/table-group.js.map +1 -1
  25. package/cjs/index.d.ts +1 -1
  26. package/cjs/index.js +1 -1
  27. package/cjs/index.js.map +1 -1
  28. package/cjs/layout/cell-range/simple-cell-range.d.ts +4 -0
  29. package/cjs/layout/cell-range/simple-cell-range.js +106 -0
  30. package/cjs/layout/cell-range/simple-cell-range.js.map +1 -0
  31. package/cjs/layout/layout-helper.js +2 -2
  32. package/cjs/layout/layout-helper.js.map +1 -1
  33. package/cjs/layout/row-height-map.js +1 -0
  34. package/cjs/layout/simple-header-layout.d.ts +1 -2
  35. package/cjs/layout/simple-header-layout.js +2 -88
  36. package/cjs/layout/simple-header-layout.js.map +1 -1
  37. package/cjs/plugins/icons.js +1 -1
  38. package/cjs/plugins/themes.js +1 -1
  39. package/cjs/scenegraph/group-creater/cell-helper.js +11 -6
  40. package/cjs/scenegraph/group-creater/cell-helper.js.map +1 -1
  41. package/cjs/scenegraph/group-creater/column-helper.js +7 -2
  42. package/cjs/scenegraph/group-creater/column-helper.js.map +1 -1
  43. package/cjs/scenegraph/scenegraph.js +1 -1
  44. package/cjs/scenegraph/utils/get-cell-merge.js +1 -1
  45. package/cjs/scenegraph/utils/get-cell-merge.js.map +1 -1
  46. package/cjs/scenegraph/utils/get-hierarchy-offset.js +6 -8
  47. package/cjs/scenegraph/utils/get-hierarchy-offset.js.map +1 -1
  48. package/cjs/themes/theme.d.ts +2 -0
  49. package/cjs/themes/theme.js +12 -4
  50. package/cjs/themes/theme.js.map +1 -1
  51. package/cjs/tools/helper.js.map +1 -1
  52. package/cjs/ts-types/base-table.d.ts +9 -0
  53. package/cjs/ts-types/base-table.js.map +1 -1
  54. package/cjs/ts-types/new-data-set.d.ts +1 -0
  55. package/cjs/ts-types/new-data-set.js.map +1 -1
  56. package/cjs/ts-types/table-engine.d.ts +8 -0
  57. package/cjs/ts-types/table-engine.js.map +1 -1
  58. package/cjs/ts-types/theme.d.ts +1 -0
  59. package/cjs/ts-types/theme.js.map +1 -1
  60. package/cjs/vrender.js.map +1 -1
  61. package/dist/vtable.js +3137 -2870
  62. package/dist/vtable.min.js +2 -2
  63. package/es/ListTable.d.ts +1 -0
  64. package/es/ListTable.js +27 -189
  65. package/es/ListTable.js.map +1 -1
  66. package/es/core/BaseTable.d.ts +5 -3
  67. package/es/core/BaseTable.js +11 -83
  68. package/es/core/BaseTable.js.map +1 -1
  69. package/es/core/group-helper.d.ts +6 -0
  70. package/es/core/group-helper.js +14 -0
  71. package/es/core/group-helper.js.map +1 -0
  72. package/es/core/record-helper.d.ts +6 -0
  73. package/es/core/record-helper.js +220 -0
  74. package/es/core/record-helper.js.map +1 -0
  75. package/es/core/style-helper.d.ts +3 -0
  76. package/es/core/style-helper.js +86 -0
  77. package/es/core/style-helper.js.map +1 -0
  78. package/es/core/tableHelper.d.ts +0 -2
  79. package/es/core/tableHelper.js +6 -16
  80. package/es/core/tableHelper.js.map +1 -1
  81. package/es/data/CachedDataSource.d.ts +10 -1
  82. package/es/data/CachedDataSource.js +79 -0
  83. package/es/data/CachedDataSource.js.map +1 -1
  84. package/es/dataset/statistics-helper.js +1 -2
  85. package/es/event/event.js +2 -1
  86. package/es/event/listener/table-group.js.map +1 -1
  87. package/es/index.d.ts +1 -1
  88. package/es/index.js +1 -1
  89. package/es/index.js.map +1 -1
  90. package/es/layout/cell-range/simple-cell-range.d.ts +4 -0
  91. package/es/layout/cell-range/simple-cell-range.js +99 -0
  92. package/es/layout/cell-range/simple-cell-range.js.map +1 -0
  93. package/es/layout/layout-helper.js +2 -2
  94. package/es/layout/layout-helper.js.map +1 -1
  95. package/es/layout/row-height-map.js +2 -1
  96. package/es/layout/simple-header-layout.d.ts +1 -2
  97. package/es/layout/simple-header-layout.js +3 -87
  98. package/es/layout/simple-header-layout.js.map +1 -1
  99. package/es/plugins/icons.js +1 -1
  100. package/es/plugins/themes.js +1 -1
  101. package/es/scenegraph/group-creater/cell-helper.js +11 -6
  102. package/es/scenegraph/group-creater/cell-helper.js.map +1 -1
  103. package/es/scenegraph/group-creater/column-helper.js +7 -2
  104. package/es/scenegraph/group-creater/column-helper.js.map +1 -1
  105. package/es/scenegraph/scenegraph.js +1 -1
  106. package/es/scenegraph/utils/get-cell-merge.js +1 -1
  107. package/es/scenegraph/utils/get-cell-merge.js.map +1 -1
  108. package/es/scenegraph/utils/get-hierarchy-offset.js +7 -9
  109. package/es/scenegraph/utils/get-hierarchy-offset.js.map +1 -1
  110. package/es/themes/theme.d.ts +2 -0
  111. package/es/themes/theme.js +11 -4
  112. package/es/themes/theme.js.map +1 -1
  113. package/es/tools/helper.js.map +1 -1
  114. package/es/ts-types/base-table.d.ts +9 -0
  115. package/es/ts-types/base-table.js.map +1 -1
  116. package/es/ts-types/new-data-set.d.ts +1 -0
  117. package/es/ts-types/new-data-set.js.map +1 -1
  118. package/es/ts-types/table-engine.d.ts +8 -0
  119. package/es/ts-types/table-engine.js.map +1 -1
  120. package/es/ts-types/theme.d.ts +1 -0
  121. package/es/ts-types/theme.js.map +1 -1
  122. package/es/vrender.js.map +1 -1
  123. package/package.json +3 -3
package/es/ListTable.d.ts CHANGED
@@ -87,4 +87,5 @@ export declare class ListTable extends BaseTable implements ListTableAPI {
87
87
  }[];
88
88
  }[];
89
89
  isAggregation(col: number, row: number): boolean;
90
+ getGroupTitleLevel(col: number, row: number): number | undefined;
90
91
  }
package/es/ListTable.js CHANGED
@@ -2,9 +2,9 @@ import { HierarchyState } from "./ts-types";
2
2
 
3
3
  import { SimpleHeaderLayoutMap } from "./layout";
4
4
 
5
- import { isValid } from "@visactor/vutils";
5
+ import { isArray, isValid } from "@visactor/vutils";
6
6
 
7
- import { _setDataSource, _setRecords, sortRecords } from "./core/tableHelper";
7
+ import { _setDataSource, _setRecords } from "./core/tableHelper";
8
8
 
9
9
  import { BaseTable } from "./core";
10
10
 
@@ -30,17 +30,23 @@ import { setCellCheckboxState } from "./state/checkbox/checkbox";
30
30
 
31
31
  import { Factory } from "./core/factory";
32
32
 
33
+ import { getGroupByDataConfig } from "./core/group-helper";
34
+
35
+ import { listTableAddRecord, listTableAddRecords, listTableDeleteRecords, listTableUpdateRecords, sortRecords } from "./core/record-helper";
36
+
33
37
  export class ListTable extends BaseTable {
34
38
  constructor(container, options) {
35
- var _a, _b;
39
+ var _a, _b, _c, _d;
36
40
  "node" === Env.mode ? (options = container, container = null) : container instanceof HTMLElement || (options = container,
37
41
  container = container.container ? container.container : null), super(container, options),
38
42
  this.showHeader = !0;
39
43
  const internalProps = this.internalProps;
40
44
  if (internalProps.frozenColDragHeaderMode = options.frozenColDragHeaderMode, this.pagination = options.pagination,
41
- internalProps.sortState = options.sortState, internalProps.dataConfig = {}, internalProps.columns = options.columns ? cloneDeepSpec(options.columns, [ "children" ]) : options.header ? cloneDeepSpec(options.header, [ "children" ]) : [],
42
- this.internalProps.headerHelper.setTableColumnsEditor(), this.showHeader = null === (_a = options.showHeader) || void 0 === _a || _a,
43
- this.transpose = null !== (_b = options.transpose) && void 0 !== _b && _b, "node" !== Env.mode && (this.editorManager = new EditManeger(this)),
45
+ internalProps.sortState = options.sortState, internalProps.dataConfig = options.groupBy ? getGroupByDataConfig(options.groupBy) : {},
46
+ internalProps.columns = options.columns ? cloneDeepSpec(options.columns, [ "children" ]) : options.header ? cloneDeepSpec(options.header, [ "children" ]) : [],
47
+ internalProps.enableTreeNodeMerge = null !== (_b = null !== (_a = options.enableTreeNodeMerge) && void 0 !== _a ? _a : isValid(options.groupBy)) && void 0 !== _b && _b,
48
+ this.internalProps.headerHelper.setTableColumnsEditor(), this.showHeader = null === (_c = options.showHeader) || void 0 === _c || _c,
49
+ this.transpose = null !== (_d = options.transpose) && void 0 !== _d && _d, "node" !== Env.mode && (this.editorManager = new EditManeger(this)),
44
50
  this.refreshHeader(), this.internalProps.useOneRowHeightFillAll = !1, options.dataSource ? _setDataSource(this, options.dataSource) : options.records ? this.setRecords(options.records, {
45
51
  sortState: internalProps.sortState
46
52
  }) : this.setRecords([]), options.title) {
@@ -344,7 +350,9 @@ export class ListTable extends BaseTable {
344
350
  return null;
345
351
  }
346
352
  getHierarchyState(col, row) {
347
- if (!this.getBodyColumnDefine(col, row).tree) return HierarchyState.none;
353
+ if (!this.options.groupBy) {
354
+ if (!this.getBodyColumnDefine(col, row).tree) return HierarchyState.none;
355
+ }
348
356
  const index = this.getRecordShowIndexByCell(col, row);
349
357
  return this.dataSource.getHierarchyState(index);
350
358
  }
@@ -609,194 +617,16 @@ export class ListTable extends BaseTable {
609
617
  this.scenegraph.updateNextFrame();
610
618
  }
611
619
  addRecord(record, recordIndex) {
612
- if (this.sortState) this.dataSource.addRecordForSorted(record), sortRecords(this),
613
- this.refreshRowColCount(), this.scenegraph.clearCells(), this.scenegraph.createSceneGraph(); else {
614
- (void 0 === recordIndex || recordIndex > this.dataSource.sourceLength) && (recordIndex = this.dataSource.sourceLength);
615
- const headerCount = this.transpose ? this.rowHeaderLevelCount : this.columnHeaderLevelCount;
616
- this.dataSource.addRecord(record, recordIndex);
617
- const oldRowCount = this.rowCount;
618
- if (this.refreshRowColCount(), 0 === this.scenegraph.proxy.totalActualBodyRowCount) return this.scenegraph.clearCells(),
619
- void this.scenegraph.createSceneGraph();
620
- const newRowCount = this.transpose ? this.colCount : this.rowCount;
621
- if (this.pagination) {
622
- const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination, endIndex = perPageCount * (currentPage || 0) + perPageCount;
623
- if (recordIndex < endIndex) if (recordIndex < endIndex - perPageCount) this.scenegraph.clearCells(),
624
- this.scenegraph.createSceneGraph(); else {
625
- const rowNum = recordIndex - (endIndex - perPageCount) + headerCount;
626
- if (oldRowCount - headerCount === this.pagination.perPageCount) {
627
- const updateRows = [];
628
- for (let row = rowNum; row < newRowCount; row++) this.transpose ? updateRows.push({
629
- col: row,
630
- row: 0
631
- }) : updateRows.push({
632
- col: 0,
633
- row: row
634
- });
635
- this.transpose ? this.scenegraph.updateCol([], [], updateRows) : this.scenegraph.updateRow([], [], updateRows);
636
- } else {
637
- const addRows = [];
638
- for (let row = rowNum; row < Math.min(newRowCount, rowNum + 1); row++) this.transpose ? addRows.push({
639
- col: row,
640
- row: 0
641
- }) : addRows.push({
642
- col: 0,
643
- row: row
644
- });
645
- this.transpose ? this.scenegraph.updateCol([], addRows, []) : this.scenegraph.updateRow([], addRows, []);
646
- }
647
- }
648
- } else {
649
- const addRows = [];
650
- for (let row = recordIndex + headerCount; row < recordIndex + headerCount + 1; row++) this.transpose ? addRows.push({
651
- col: row,
652
- row: 0
653
- }) : addRows.push({
654
- col: 0,
655
- row: row
656
- });
657
- this.transpose ? this.scenegraph.updateCol([], addRows, []) : this.scenegraph.updateRow([], addRows, []);
658
- }
659
- }
620
+ listTableAddRecord(record, recordIndex, this);
660
621
  }
661
622
  addRecords(records, recordIndex) {
662
- if (this.sortState) this.dataSource.addRecordsForSorted(records), sortRecords(this),
663
- this.refreshRowColCount(), this.scenegraph.clearCells(), this.scenegraph.createSceneGraph(); else {
664
- void 0 === recordIndex || recordIndex > this.dataSource.sourceLength ? recordIndex = this.dataSource.sourceLength : recordIndex < 0 && (recordIndex = 0);
665
- const headerCount = this.transpose ? this.rowHeaderLevelCount : this.columnHeaderLevelCount;
666
- this.dataSource.addRecords(records, recordIndex);
667
- const oldRowCount = this.transpose ? this.colCount : this.rowCount;
668
- if (this.refreshRowColCount(), 0 === this.scenegraph.proxy.totalActualBodyRowCount) return this.scenegraph.clearCells(),
669
- void this.scenegraph.createSceneGraph();
670
- const newRowCount = this.transpose ? this.colCount : this.rowCount;
671
- if (this.pagination) {
672
- const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination, endIndex = perPageCount * (currentPage || 0) + perPageCount;
673
- if (recordIndex < endIndex) if (recordIndex < endIndex - perPageCount) this.scenegraph.clearCells(),
674
- this.scenegraph.createSceneGraph(); else {
675
- const rowNum = recordIndex - (endIndex - perPageCount) + headerCount;
676
- if (oldRowCount - headerCount === this.pagination.perPageCount) {
677
- const updateRows = [];
678
- for (let row = rowNum; row < newRowCount; row++) this.transpose ? updateRows.push({
679
- col: row,
680
- row: 0
681
- }) : updateRows.push({
682
- col: 0,
683
- row: row
684
- });
685
- this.transpose ? this.scenegraph.updateCol([], [], updateRows) : this.scenegraph.updateRow([], [], updateRows);
686
- } else {
687
- const addRows = [];
688
- for (let row = rowNum; row < Math.min(newRowCount, rowNum + (Array.isArray(records) ? records.length : 1)); row++) this.transpose ? addRows.push({
689
- col: row,
690
- row: 0
691
- }) : addRows.push({
692
- col: 0,
693
- row: row
694
- });
695
- this.transpose ? this.scenegraph.updateCol([], addRows, []) : this.scenegraph.updateRow([], addRows, []);
696
- }
697
- }
698
- } else {
699
- const addRows = [];
700
- for (let row = recordIndex + headerCount; row < recordIndex + headerCount + (Array.isArray(records) ? records.length : 1); row++) this.transpose ? addRows.push({
701
- col: row,
702
- row: 0
703
- }) : addRows.push({
704
- col: 0,
705
- row: row
706
- });
707
- this.transpose ? this.scenegraph.updateCol([], addRows, []) : this.scenegraph.updateRow([], addRows, []);
708
- }
709
- }
623
+ listTableAddRecords(records, recordIndex, this);
710
624
  }
711
625
  deleteRecords(recordIndexs) {
712
- if ((null == recordIndexs ? void 0 : recordIndexs.length) > 0) if (this.sortState) this.dataSource.deleteRecordsForSorted(recordIndexs),
713
- sortRecords(this), this.refreshRowColCount(), this.scenegraph.clearCells(), this.scenegraph.createSceneGraph(); else {
714
- const deletedRecordIndexs = this.dataSource.deleteRecords(recordIndexs);
715
- if (0 === deletedRecordIndexs.length) return;
716
- const oldRowCount = this.transpose ? this.colCount : this.rowCount;
717
- this.refreshRowColCount();
718
- const newRowCount = this.transpose ? this.colCount : this.rowCount, recordIndexsMinToMax = deletedRecordIndexs.sort(((a, b) => a - b)), minRecordIndex = recordIndexsMinToMax[0];
719
- if (this.pagination) {
720
- const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination, endIndex = perPageCount * (currentPage || 0) + perPageCount;
721
- if (minRecordIndex < endIndex) if (minRecordIndex < endIndex - perPageCount) this.scenegraph.clearCells(),
722
- this.scenegraph.createSceneGraph(); else {
723
- const updateRows = [], delRows = [];
724
- for (let row = minRecordIndex - (endIndex - perPageCount) + (this.transpose ? this.rowHeaderLevelCount : this.columnHeaderLevelCount); row < newRowCount; row++) this.transpose ? updateRows.push({
725
- col: row,
726
- row: 0
727
- }) : updateRows.push({
728
- col: 0,
729
- row: row
730
- });
731
- if (newRowCount < oldRowCount) for (let row = newRowCount; row < oldRowCount; row++) this.transpose ? delRows.push({
732
- col: row,
733
- row: 0
734
- }) : delRows.push({
735
- col: 0,
736
- row: row
737
- });
738
- this.transpose ? this.scenegraph.updateCol(delRows, [], updateRows) : this.scenegraph.updateRow(delRows, [], updateRows);
739
- }
740
- } else {
741
- const delRows = [];
742
- for (let index = 0; index < recordIndexsMinToMax.length; index++) {
743
- const rowNum = recordIndexsMinToMax[index] + (this.transpose ? this.rowHeaderLevelCount : this.columnHeaderLevelCount);
744
- this.transpose ? delRows.push({
745
- col: rowNum,
746
- row: 0
747
- }) : delRows.push({
748
- col: 0,
749
- row: rowNum
750
- });
751
- }
752
- this.transpose ? this.scenegraph.updateCol(delRows, [], []) : this.scenegraph.updateRow(delRows, [], []);
753
- }
754
- }
626
+ listTableDeleteRecords(recordIndexs, this);
755
627
  }
756
628
  updateRecords(records, recordIndexs) {
757
- if ((null == recordIndexs ? void 0 : recordIndexs.length) > 0) if (this.sortState) this.dataSource.updateRecordsForSorted(records, recordIndexs),
758
- sortRecords(this), this.refreshRowColCount(), this.scenegraph.clearCells(), this.scenegraph.createSceneGraph(); else {
759
- const updateRecordIndexs = this.dataSource.updateRecords(records, recordIndexs);
760
- if (0 === updateRecordIndexs.length) return;
761
- const recordIndexsMinToMax = updateRecordIndexs.sort(((a, b) => a - b));
762
- if (this.pagination) {
763
- const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination, endIndex = perPageCount * (currentPage || 0) + perPageCount, updateRows = [];
764
- for (let index = 0; index < recordIndexsMinToMax.length; index++) {
765
- const recordIndex = recordIndexsMinToMax[index];
766
- if (recordIndex < endIndex && recordIndex >= endIndex - perPageCount) {
767
- const rowNum = recordIndex - (endIndex - perPageCount) + (this.transpose ? this.rowHeaderLevelCount : this.columnHeaderLevelCount);
768
- updateRows.push(rowNum);
769
- }
770
- }
771
- if (updateRows.length >= 1) {
772
- const updateRowCells = [];
773
- for (let index = 0; index < updateRows.length; index++) {
774
- const updateRow = updateRows[index];
775
- this.transpose ? updateRowCells.push({
776
- col: updateRow,
777
- row: 0
778
- }) : updateRowCells.push({
779
- col: 0,
780
- row: updateRow
781
- });
782
- }
783
- this.transpose ? this.scenegraph.updateCol([], [], updateRowCells) : this.scenegraph.updateRow([], [], updateRowCells);
784
- }
785
- } else {
786
- const updateRows = [];
787
- for (let index = 0; index < recordIndexsMinToMax.length; index++) {
788
- const rowNum = recordIndexsMinToMax[index] + (this.transpose ? this.rowHeaderLevelCount : this.columnHeaderLevelCount);
789
- this.transpose ? updateRows.push({
790
- col: rowNum,
791
- row: 0
792
- }) : updateRows.push({
793
- col: 0,
794
- row: rowNum
795
- });
796
- }
797
- this.transpose ? this.scenegraph.updateCol([], [], updateRows) : this.scenegraph.updateRow([], [], updateRows);
798
- }
799
- }
629
+ listTableUpdateRecords(records, recordIndexs, this);
800
630
  }
801
631
  _hasCustomRenderOrLayout() {
802
632
  var _a, _b, _c, _d;
@@ -832,5 +662,13 @@ export class ListTable extends BaseTable {
832
662
  isAggregation(col, row) {
833
663
  return this.internalProps.layoutMap.isAggregation(col, row);
834
664
  }
665
+ getGroupTitleLevel(col, row) {
666
+ var _a;
667
+ if (!this.options.groupBy) return;
668
+ const indexArr = this.dataSource.getIndexKey(this.getRecordShowIndexByCell(col, row)), groupLength = null !== (_a = this.dataSource.getGroupLength()) && void 0 !== _a ? _a : 0;
669
+ let indexArrLngth = isArray(indexArr) ? indexArr.length - 1 : 0;
670
+ return groupLength > 0 && indexArrLngth === groupLength && (indexArrLngth = void 0),
671
+ indexArrLngth;
672
+ }
835
673
  }
836
674
  //# sourceMappingURL=ListTable.js.map