@depup/react-virtualized 9.22.6-depup.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.
- package/LICENSE +22 -0
- package/README.md +34 -0
- package/changes.json +22 -0
- package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.example.js +184 -0
- package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.jest.js +338 -0
- package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js +204 -0
- package/dist/commonjs/ArrowKeyStepper/index.js +19 -0
- package/dist/commonjs/ArrowKeyStepper/types.js +5 -0
- package/dist/commonjs/AutoSizer/AutoSizer.example.js +104 -0
- package/dist/commonjs/AutoSizer/AutoSizer.jest.js +341 -0
- package/dist/commonjs/AutoSizer/AutoSizer.js +199 -0
- package/dist/commonjs/AutoSizer/AutoSizer.ssr.js +25 -0
- package/dist/commonjs/AutoSizer/index.js +19 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +100 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +99 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +107 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +102 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +107 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.example.js +129 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.jest.js +345 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.js +195 -0
- package/dist/commonjs/CellMeasurer/CellMeasurerCache.jest.js +298 -0
- package/dist/commonjs/CellMeasurer/CellMeasurerCache.js +202 -0
- package/dist/commonjs/CellMeasurer/index.js +22 -0
- package/dist/commonjs/CellMeasurer/types.js +14 -0
- package/dist/commonjs/Collection/Collection.example.js +231 -0
- package/dist/commonjs/Collection/Collection.jest.js +829 -0
- package/dist/commonjs/Collection/Collection.js +266 -0
- package/dist/commonjs/Collection/CollectionView.js +553 -0
- package/dist/commonjs/Collection/Section.jest.js +63 -0
- package/dist/commonjs/Collection/Section.js +57 -0
- package/dist/commonjs/Collection/SectionManager.jest.js +121 -0
- package/dist/commonjs/Collection/SectionManager.js +134 -0
- package/dist/commonjs/Collection/TestData.js +77 -0
- package/dist/commonjs/Collection/index.js +15 -0
- package/dist/commonjs/Collection/types.js +22 -0
- package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.jest.js +34 -0
- package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.js +38 -0
- package/dist/commonjs/ColumnSizer/ColumnSizer.example.js +159 -0
- package/dist/commonjs/ColumnSizer/ColumnSizer.jest.js +129 -0
- package/dist/commonjs/ColumnSizer/ColumnSizer.js +103 -0
- package/dist/commonjs/ColumnSizer/index.js +15 -0
- package/dist/commonjs/Grid/Grid.example.js +330 -0
- package/dist/commonjs/Grid/Grid.jest.js +2561 -0
- package/dist/commonjs/Grid/Grid.js +1432 -0
- package/dist/commonjs/Grid/Grid.ssr.js +62 -0
- package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.jest.js +92 -0
- package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.js +40 -0
- package/dist/commonjs/Grid/defaultCellRangeRenderer.js +139 -0
- package/dist/commonjs/Grid/defaultOverscanIndicesGetter.jest.js +92 -0
- package/dist/commonjs/Grid/defaultOverscanIndicesGetter.js +36 -0
- package/dist/commonjs/Grid/index.js +40 -0
- package/dist/commonjs/Grid/types.js +8 -0
- package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.jest.js +375 -0
- package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.js +296 -0
- package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +201 -0
- package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.js +204 -0
- package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +84 -0
- package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +59 -0
- package/dist/commonjs/Grid/utils/maxElementSize.js +22 -0
- package/dist/commonjs/Grid/utils/updateScrollIndexHelper.jest.js +180 -0
- package/dist/commonjs/Grid/utils/updateScrollIndexHelper.js +85 -0
- package/dist/commonjs/InfiniteLoader/InfiniteLoader.example.js +179 -0
- package/dist/commonjs/InfiniteLoader/InfiniteLoader.jest.js +571 -0
- package/dist/commonjs/InfiniteLoader/InfiniteLoader.js +274 -0
- package/dist/commonjs/InfiniteLoader/index.js +15 -0
- package/dist/commonjs/List/List.example.js +236 -0
- package/dist/commonjs/List/List.jest.js +517 -0
- package/dist/commonjs/List/List.js +318 -0
- package/dist/commonjs/List/index.js +19 -0
- package/dist/commonjs/List/types.js +6 -0
- package/dist/commonjs/Masonry/Masonry.example.js +287 -0
- package/dist/commonjs/Masonry/Masonry.jest.js +450 -0
- package/dist/commonjs/Masonry/Masonry.js +431 -0
- package/dist/commonjs/Masonry/PositionCache.js +88 -0
- package/dist/commonjs/Masonry/createCellPositioner.js +59 -0
- package/dist/commonjs/Masonry/index.js +22 -0
- package/dist/commonjs/MultiGrid/CellMeasurerCacheDecorator.js +106 -0
- package/dist/commonjs/MultiGrid/MultiGrid.example.js +131 -0
- package/dist/commonjs/MultiGrid/MultiGrid.jest.js +584 -0
- package/dist/commonjs/MultiGrid/MultiGrid.js +743 -0
- package/dist/commonjs/MultiGrid/index.js +15 -0
- package/dist/commonjs/ScrollSync/ScrollSync.example.js +257 -0
- package/dist/commonjs/ScrollSync/ScrollSync.jest.js +66 -0
- package/dist/commonjs/ScrollSync/ScrollSync.js +88 -0
- package/dist/commonjs/ScrollSync/index.js +15 -0
- package/dist/commonjs/Table/Column.jest.js +90 -0
- package/dist/commonjs/Table/Column.js +93 -0
- package/dist/commonjs/Table/SortDirection.js +19 -0
- package/dist/commonjs/Table/SortIndicator.js +40 -0
- package/dist/commonjs/Table/Table.example.js +325 -0
- package/dist/commonjs/Table/Table.jest.js +1257 -0
- package/dist/commonjs/Table/Table.js +742 -0
- package/dist/commonjs/Table/createMultiSort.jest.js +165 -0
- package/dist/commonjs/Table/createMultiSort.js +99 -0
- package/dist/commonjs/Table/defaultCellDataGetter.js +21 -0
- package/dist/commonjs/Table/defaultCellRenderer.js +19 -0
- package/dist/commonjs/Table/defaultHeaderRenderer.js +35 -0
- package/dist/commonjs/Table/defaultHeaderRowRenderer.js +21 -0
- package/dist/commonjs/Table/defaultRowRenderer.js +87 -0
- package/dist/commonjs/Table/index.js +78 -0
- package/dist/commonjs/Table/types.js +39 -0
- package/dist/commonjs/WindowScroller/WindowScroller.e2e.js +298 -0
- package/dist/commonjs/WindowScroller/WindowScroller.example.js +167 -0
- package/dist/commonjs/WindowScroller/WindowScroller.header-resize.e2e.js +359 -0
- package/dist/commonjs/WindowScroller/WindowScroller.jest.js +536 -0
- package/dist/commonjs/WindowScroller/WindowScroller.js +268 -0
- package/dist/commonjs/WindowScroller/WindowScroller.ssr.js +25 -0
- package/dist/commonjs/WindowScroller/index.js +23 -0
- package/dist/commonjs/WindowScroller/utils/dimensions.js +89 -0
- package/dist/commonjs/WindowScroller/utils/onScroll.js +70 -0
- package/dist/commonjs/index.js +180 -0
- package/dist/commonjs/jest-setup.js +7 -0
- package/dist/commonjs/utils/TestHelper.js +36 -0
- package/dist/commonjs/utils/animationFrame.js +29 -0
- package/dist/commonjs/utils/createCallbackMemoizer.jest.js +219 -0
- package/dist/commonjs/utils/createCallbackMemoizer.js +31 -0
- package/dist/commonjs/utils/getUpdatedOffsetForIndex.jest.js +68 -0
- package/dist/commonjs/utils/getUpdatedOffsetForIndex.js +38 -0
- package/dist/commonjs/utils/initCellMetadata.js +37 -0
- package/dist/commonjs/utils/requestAnimationTimeout.js +38 -0
- package/dist/commonjs/vendor/binarySearchBounds.js +200 -0
- package/dist/commonjs/vendor/detectElementResize.js +192 -0
- package/dist/commonjs/vendor/intervalTree.js +361 -0
- package/dist/es/ArrowKeyStepper/ArrowKeyStepper.example.js +176 -0
- package/dist/es/ArrowKeyStepper/ArrowKeyStepper.jest.js +332 -0
- package/dist/es/ArrowKeyStepper/ArrowKeyStepper.js +197 -0
- package/dist/es/ArrowKeyStepper/index.js +3 -0
- package/dist/es/ArrowKeyStepper/types.js +4 -0
- package/dist/es/AutoSizer/AutoSizer.example.js +96 -0
- package/dist/es/AutoSizer/AutoSizer.jest.js +335 -0
- package/dist/es/AutoSizer/AutoSizer.js +190 -0
- package/dist/es/AutoSizer/AutoSizer.js.flow +200 -0
- package/dist/es/AutoSizer/AutoSizer.ssr.js +19 -0
- package/dist/es/AutoSizer/index.js +2 -0
- package/dist/es/AutoSizer/index.js.flow +4 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +91 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +90 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +98 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +93 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +98 -0
- package/dist/es/CellMeasurer/CellMeasurer.example.js +120 -0
- package/dist/es/CellMeasurer/CellMeasurer.jest.js +340 -0
- package/dist/es/CellMeasurer/CellMeasurer.js +187 -0
- package/dist/es/CellMeasurer/CellMeasurerCache.jest.js +293 -0
- package/dist/es/CellMeasurer/CellMeasurerCache.js +196 -0
- package/dist/es/CellMeasurer/index.js +4 -0
- package/dist/es/CellMeasurer/types.js +13 -0
- package/dist/es/Collection/Collection.example.js +223 -0
- package/dist/es/Collection/Collection.jest.js +824 -0
- package/dist/es/Collection/Collection.js +257 -0
- package/dist/es/Collection/CollectionView.js +544 -0
- package/dist/es/Collection/Section.jest.js +60 -0
- package/dist/es/Collection/Section.js +51 -0
- package/dist/es/Collection/SectionManager.jest.js +118 -0
- package/dist/es/Collection/SectionManager.js +128 -0
- package/dist/es/Collection/TestData.js +71 -0
- package/dist/es/Collection/index.js +3 -0
- package/dist/es/Collection/types.js +21 -0
- package/dist/es/Collection/utils/calculateSizeAndPositionData.jest.js +31 -0
- package/dist/es/Collection/utils/calculateSizeAndPositionData.js +31 -0
- package/dist/es/ColumnSizer/ColumnSizer.example.js +150 -0
- package/dist/es/ColumnSizer/ColumnSizer.jest.js +123 -0
- package/dist/es/ColumnSizer/ColumnSizer.js +95 -0
- package/dist/es/ColumnSizer/index.js +3 -0
- package/dist/es/Grid/Grid.example.js +321 -0
- package/dist/es/Grid/Grid.jest.js +2555 -0
- package/dist/es/Grid/Grid.js +1425 -0
- package/dist/es/Grid/Grid.ssr.js +57 -0
- package/dist/es/Grid/accessibilityOverscanIndicesGetter.jest.js +87 -0
- package/dist/es/Grid/accessibilityOverscanIndicesGetter.js +33 -0
- package/dist/es/Grid/defaultCellRangeRenderer.js +134 -0
- package/dist/es/Grid/defaultOverscanIndicesGetter.jest.js +87 -0
- package/dist/es/Grid/defaultOverscanIndicesGetter.js +29 -0
- package/dist/es/Grid/index.js +15 -0
- package/dist/es/Grid/types.js +96 -0
- package/dist/es/Grid/utils/CellSizeAndPositionManager.jest.js +372 -0
- package/dist/es/Grid/utils/CellSizeAndPositionManager.js +290 -0
- package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +198 -0
- package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.js +198 -0
- package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +81 -0
- package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +53 -0
- package/dist/es/Grid/utils/maxElementSize.js +16 -0
- package/dist/es/Grid/utils/updateScrollIndexHelper.jest.js +174 -0
- package/dist/es/Grid/utils/updateScrollIndexHelper.js +79 -0
- package/dist/es/InfiniteLoader/InfiniteLoader.example.js +170 -0
- package/dist/es/InfiniteLoader/InfiniteLoader.jest.js +565 -0
- package/dist/es/InfiniteLoader/InfiniteLoader.js +263 -0
- package/dist/es/InfiniteLoader/index.js +3 -0
- package/dist/es/List/List.example.js +227 -0
- package/dist/es/List/List.jest.js +511 -0
- package/dist/es/List/List.js +312 -0
- package/dist/es/List/index.js +3 -0
- package/dist/es/List/types.js +21 -0
- package/dist/es/Masonry/Masonry.example.js +278 -0
- package/dist/es/Masonry/Masonry.jest.js +444 -0
- package/dist/es/Masonry/Masonry.js +421 -0
- package/dist/es/Masonry/PositionCache.js +82 -0
- package/dist/es/Masonry/createCellPositioner.js +53 -0
- package/dist/es/Masonry/index.js +4 -0
- package/dist/es/MultiGrid/CellMeasurerCacheDecorator.js +100 -0
- package/dist/es/MultiGrid/MultiGrid.example.js +122 -0
- package/dist/es/MultiGrid/MultiGrid.jest.js +579 -0
- package/dist/es/MultiGrid/MultiGrid.js +733 -0
- package/dist/es/MultiGrid/index.js +3 -0
- package/dist/es/ScrollSync/ScrollSync.example.js +248 -0
- package/dist/es/ScrollSync/ScrollSync.jest.js +60 -0
- package/dist/es/ScrollSync/ScrollSync.js +80 -0
- package/dist/es/ScrollSync/index.js +3 -0
- package/dist/es/Table/Column.jest.js +84 -0
- package/dist/es/Table/Column.js +85 -0
- package/dist/es/Table/SortDirection.js +13 -0
- package/dist/es/Table/SortIndicator.js +31 -0
- package/dist/es/Table/Table.example.js +316 -0
- package/dist/es/Table/Table.jest.js +1251 -0
- package/dist/es/Table/Table.js +735 -0
- package/dist/es/Table/createMultiSort.jest.js +162 -0
- package/dist/es/Table/createMultiSort.js +93 -0
- package/dist/es/Table/defaultCellDataGetter.js +15 -0
- package/dist/es/Table/defaultCellRenderer.js +13 -0
- package/dist/es/Table/defaultHeaderRenderer.js +25 -0
- package/dist/es/Table/defaultHeaderRowRenderer.js +12 -0
- package/dist/es/Table/defaultRowRenderer.js +77 -0
- package/dist/es/Table/index.js +12 -0
- package/dist/es/Table/types.js +38 -0
- package/dist/es/WindowScroller/WindowScroller.e2e.js +295 -0
- package/dist/es/WindowScroller/WindowScroller.example.js +158 -0
- package/dist/es/WindowScroller/WindowScroller.header-resize.e2e.js +356 -0
- package/dist/es/WindowScroller/WindowScroller.jest.js +530 -0
- package/dist/es/WindowScroller/WindowScroller.js +259 -0
- package/dist/es/WindowScroller/WindowScroller.js.flow +277 -0
- package/dist/es/WindowScroller/WindowScroller.ssr.js +19 -0
- package/dist/es/WindowScroller/index.js +3 -0
- package/dist/es/WindowScroller/index.js.flow +6 -0
- package/dist/es/WindowScroller/utils/dimensions.js +81 -0
- package/dist/es/WindowScroller/utils/dimensions.js.flow +91 -0
- package/dist/es/WindowScroller/utils/onScroll.js +64 -0
- package/dist/es/WindowScroller/utils/onScroll.js.flow +94 -0
- package/dist/es/index.js +13 -0
- package/dist/es/jest-setup.js +5 -0
- package/dist/es/utils/TestHelper.js +30 -0
- package/dist/es/utils/animationFrame.js +23 -0
- package/dist/es/utils/createCallbackMemoizer.jest.js +216 -0
- package/dist/es/utils/createCallbackMemoizer.js +25 -0
- package/dist/es/utils/getUpdatedOffsetForIndex.jest.js +65 -0
- package/dist/es/utils/getUpdatedOffsetForIndex.js +32 -0
- package/dist/es/utils/initCellMetadata.js +31 -0
- package/dist/es/utils/requestAnimationTimeout.js +32 -0
- package/dist/es/vendor/binarySearchBounds.js +194 -0
- package/dist/es/vendor/detectElementResize.js +186 -0
- package/dist/es/vendor/intervalTree.js +354 -0
- package/dist/umd/react-virtualized.js +4638 -0
- package/package.json +188 -0
- package/styles.css +80 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import SectionManager from './SectionManager';
|
|
2
|
+
import { CELLS, SECTION_SIZE } from './TestData';
|
|
3
|
+
function initSectionManager() {
|
|
4
|
+
var sectionManager = new SectionManager(SECTION_SIZE);
|
|
5
|
+
CELLS.forEach(function (cellMetadatum, index) {
|
|
6
|
+
sectionManager.registerCell({
|
|
7
|
+
cellMetadatum: cellMetadatum,
|
|
8
|
+
index: index
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
return sectionManager;
|
|
12
|
+
}
|
|
13
|
+
function verifySections(sectionManager, sizeAndPosition, expectedSizeAndPositionInfos) {
|
|
14
|
+
var sections = sectionManager.getSections(sizeAndPosition);
|
|
15
|
+
expect(sections.length).toEqual(expectedSizeAndPositionInfos.length);
|
|
16
|
+
expectedSizeAndPositionInfos.forEach(function (sizeAndPosition) {
|
|
17
|
+
var match = sections.find(function (section) {
|
|
18
|
+
return section.x === sizeAndPosition.x && section.y === sizeAndPosition.y;
|
|
19
|
+
});
|
|
20
|
+
expect(!!match).toEqual(true);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
describe('SectionManager', function () {
|
|
24
|
+
it('creates the appropriate number of Sections', function () {
|
|
25
|
+
var sectionManager = initSectionManager();
|
|
26
|
+
expect(sectionManager.getTotalSectionCount()).toEqual(6);
|
|
27
|
+
});
|
|
28
|
+
it('returns the proper Sections based on the specified area', function () {
|
|
29
|
+
var sectionManager = initSectionManager();
|
|
30
|
+
verifySections(sectionManager, {
|
|
31
|
+
x: 0,
|
|
32
|
+
y: 0,
|
|
33
|
+
width: 1,
|
|
34
|
+
height: 1
|
|
35
|
+
}, [{
|
|
36
|
+
x: 0,
|
|
37
|
+
y: 0
|
|
38
|
+
}]);
|
|
39
|
+
verifySections(sectionManager, {
|
|
40
|
+
x: 1,
|
|
41
|
+
y: 1,
|
|
42
|
+
width: 1,
|
|
43
|
+
height: 1
|
|
44
|
+
}, [{
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0
|
|
47
|
+
}]);
|
|
48
|
+
verifySections(sectionManager, {
|
|
49
|
+
x: 0,
|
|
50
|
+
y: 0,
|
|
51
|
+
width: 4,
|
|
52
|
+
height: 4
|
|
53
|
+
}, [{
|
|
54
|
+
x: 0,
|
|
55
|
+
y: 0
|
|
56
|
+
}, {
|
|
57
|
+
x: 2,
|
|
58
|
+
y: 0
|
|
59
|
+
}, {
|
|
60
|
+
x: 0,
|
|
61
|
+
y: 2
|
|
62
|
+
}, {
|
|
63
|
+
x: 2,
|
|
64
|
+
y: 2
|
|
65
|
+
}]);
|
|
66
|
+
verifySections(sectionManager, {
|
|
67
|
+
x: 4,
|
|
68
|
+
y: 0,
|
|
69
|
+
width: 2,
|
|
70
|
+
height: 3
|
|
71
|
+
}, [{
|
|
72
|
+
x: 4,
|
|
73
|
+
y: 0
|
|
74
|
+
}, {
|
|
75
|
+
x: 4,
|
|
76
|
+
y: 2
|
|
77
|
+
}]);
|
|
78
|
+
});
|
|
79
|
+
it('assigns cells to the appropriate sections', function () {
|
|
80
|
+
var sectionManager = initSectionManager();
|
|
81
|
+
expect(sectionManager.getCellIndices({
|
|
82
|
+
x: 0,
|
|
83
|
+
y: 0,
|
|
84
|
+
width: 2,
|
|
85
|
+
height: 2
|
|
86
|
+
})).toEqual([0]);
|
|
87
|
+
expect(sectionManager.getCellIndices({
|
|
88
|
+
x: 2,
|
|
89
|
+
y: 0,
|
|
90
|
+
width: 2,
|
|
91
|
+
height: 2
|
|
92
|
+
})).toEqual([1, 2, 3]);
|
|
93
|
+
expect(sectionManager.getCellIndices({
|
|
94
|
+
x: 4,
|
|
95
|
+
y: 0,
|
|
96
|
+
width: 2,
|
|
97
|
+
height: 2
|
|
98
|
+
})).toEqual([6]);
|
|
99
|
+
expect(sectionManager.getCellIndices({
|
|
100
|
+
x: 0,
|
|
101
|
+
y: 2,
|
|
102
|
+
width: 2,
|
|
103
|
+
height: 2
|
|
104
|
+
})).toEqual([4]);
|
|
105
|
+
expect(sectionManager.getCellIndices({
|
|
106
|
+
x: 2,
|
|
107
|
+
y: 2,
|
|
108
|
+
width: 2,
|
|
109
|
+
height: 2
|
|
110
|
+
})).toEqual([3, 4, 5]);
|
|
111
|
+
expect(sectionManager.getCellIndices({
|
|
112
|
+
x: 4,
|
|
113
|
+
y: 2,
|
|
114
|
+
width: 2,
|
|
115
|
+
height: 2
|
|
116
|
+
})).toEqual([7, 8, 9]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
/**
|
|
4
|
+
* Window Sections are used to group nearby cells.
|
|
5
|
+
* This enables us to more quickly determine which cells to display in a given region of the Window.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import Section from './Section';
|
|
9
|
+
/*:: import type {Index, SizeAndPositionInfo} from './types';*/
|
|
10
|
+
var SECTION_SIZE = 100;
|
|
11
|
+
/*:: type RegisterCellParams = {
|
|
12
|
+
cellMetadatum: SizeAndPositionInfo,
|
|
13
|
+
index: number,
|
|
14
|
+
};*/
|
|
15
|
+
/**
|
|
16
|
+
* Contains 0 to many Sections.
|
|
17
|
+
* Grows (and adds Sections) dynamically as cells are registered.
|
|
18
|
+
* Automatically adds cells to the appropriate Section(s).
|
|
19
|
+
*/
|
|
20
|
+
var SectionManager = /*#__PURE__*/function () {
|
|
21
|
+
function SectionManager() {
|
|
22
|
+
var sectionSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SECTION_SIZE;
|
|
23
|
+
_classCallCheck(this, SectionManager);
|
|
24
|
+
this._sectionSize = sectionSize;
|
|
25
|
+
this._cellMetadata = [];
|
|
26
|
+
this._sections = {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Gets all cell indices contained in the specified region.
|
|
31
|
+
* A region may encompass 1 or more Sections.
|
|
32
|
+
*/
|
|
33
|
+
return _createClass(SectionManager, [{
|
|
34
|
+
key: "getCellIndices",
|
|
35
|
+
value: function getCellIndices(_ref /*:: */) /*: Array<number>*/{
|
|
36
|
+
var height = _ref /*:: */.height,
|
|
37
|
+
width = _ref /*:: */.width,
|
|
38
|
+
x = _ref /*:: */.x,
|
|
39
|
+
y = _ref /*:: */.y;
|
|
40
|
+
var indices = {};
|
|
41
|
+
this.getSections({
|
|
42
|
+
height: height,
|
|
43
|
+
width: width,
|
|
44
|
+
x: x,
|
|
45
|
+
y: y
|
|
46
|
+
}).forEach(function (section) {
|
|
47
|
+
return section.getCellIndices().forEach(function (index) {
|
|
48
|
+
indices[index] = index;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Object keys are strings; this function returns numbers
|
|
53
|
+
return Object.keys(indices).map(function (index) {
|
|
54
|
+
return indices[index];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Get size and position information for the cell specified. */
|
|
59
|
+
}, {
|
|
60
|
+
key: "getCellMetadata",
|
|
61
|
+
value: function getCellMetadata(_ref2 /*:: */) /*: SizeAndPositionInfo*/{
|
|
62
|
+
var index = _ref2 /*:: */.index;
|
|
63
|
+
return this._cellMetadata[index];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Get all Sections overlapping the specified region. */
|
|
67
|
+
}, {
|
|
68
|
+
key: "getSections",
|
|
69
|
+
value: function getSections(_ref3 /*:: */) /*: Array<Section>*/{
|
|
70
|
+
var height = _ref3 /*:: */.height,
|
|
71
|
+
width = _ref3 /*:: */.width,
|
|
72
|
+
x = _ref3 /*:: */.x,
|
|
73
|
+
y = _ref3 /*:: */.y;
|
|
74
|
+
var sectionXStart = Math.floor(x / this._sectionSize);
|
|
75
|
+
var sectionXStop = Math.floor((x + width - 1) / this._sectionSize);
|
|
76
|
+
var sectionYStart = Math.floor(y / this._sectionSize);
|
|
77
|
+
var sectionYStop = Math.floor((y + height - 1) / this._sectionSize);
|
|
78
|
+
var sections = [];
|
|
79
|
+
for (var sectionX = sectionXStart; sectionX <= sectionXStop; sectionX++) {
|
|
80
|
+
for (var sectionY = sectionYStart; sectionY <= sectionYStop; sectionY++) {
|
|
81
|
+
var key = "".concat(sectionX, ".").concat(sectionY);
|
|
82
|
+
if (!this._sections[key]) {
|
|
83
|
+
this._sections[key] = new Section({
|
|
84
|
+
height: this._sectionSize,
|
|
85
|
+
width: this._sectionSize,
|
|
86
|
+
x: sectionX * this._sectionSize,
|
|
87
|
+
y: sectionY * this._sectionSize
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
sections.push(this._sections[key]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return sections;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Total number of Sections based on the currently registered cells. */
|
|
97
|
+
}, {
|
|
98
|
+
key: "getTotalSectionCount",
|
|
99
|
+
value: function getTotalSectionCount() {
|
|
100
|
+
return Object.keys(this._sections).length;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Intended for debugger/test purposes only */
|
|
104
|
+
}, {
|
|
105
|
+
key: "toString",
|
|
106
|
+
value: function toString() {
|
|
107
|
+
var _this = this;
|
|
108
|
+
return Object.keys(this._sections).map(function (index) {
|
|
109
|
+
return _this._sections[index].toString();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Adds a cell to the appropriate Sections and registers it metadata for later retrievable. */
|
|
114
|
+
}, {
|
|
115
|
+
key: "registerCell",
|
|
116
|
+
value: function registerCell(_ref4 /*:: */) {
|
|
117
|
+
var cellMetadatum = _ref4 /*:: */.cellMetadatum,
|
|
118
|
+
index = _ref4 /*:: */.index;
|
|
119
|
+
this._cellMetadata[index] = cellMetadatum;
|
|
120
|
+
this.getSections(cellMetadatum).forEach(function (section) {
|
|
121
|
+
return section.addCellIndex({
|
|
122
|
+
index: index
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}]);
|
|
127
|
+
}();
|
|
128
|
+
export { SectionManager as default };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
0 1 2 3 4 5
|
|
3
|
+
┏━━━┯━━━┯━━━┓
|
|
4
|
+
0┃0 0┊1 3┊6 6┃
|
|
5
|
+
1┃0 0┊2 3┊6 6┃
|
|
6
|
+
┠┈┈┈┼┈┈┈┼┈┈┈┨
|
|
7
|
+
2┃4 4┊4 3┊7 8┃
|
|
8
|
+
3┃4 4┊4 5┊9 9┃
|
|
9
|
+
┗━━━┷━━━┷━━━┛
|
|
10
|
+
|
|
11
|
+
Sections to Cells map:
|
|
12
|
+
0.0 [0]
|
|
13
|
+
1.0 [1, 2, 3]
|
|
14
|
+
2.0 [6]
|
|
15
|
+
0.1 [4]
|
|
16
|
+
1.1 [3, 4, 5]
|
|
17
|
+
2.1 [7, 8, 9]
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export var CELLS = [{
|
|
21
|
+
x: 0,
|
|
22
|
+
y: 0,
|
|
23
|
+
width: 2,
|
|
24
|
+
height: 2
|
|
25
|
+
}, {
|
|
26
|
+
x: 2,
|
|
27
|
+
y: 0,
|
|
28
|
+
width: 1,
|
|
29
|
+
height: 1
|
|
30
|
+
}, {
|
|
31
|
+
x: 2,
|
|
32
|
+
y: 1,
|
|
33
|
+
width: 1,
|
|
34
|
+
height: 1
|
|
35
|
+
}, {
|
|
36
|
+
x: 3,
|
|
37
|
+
y: 0,
|
|
38
|
+
width: 1,
|
|
39
|
+
height: 3
|
|
40
|
+
}, {
|
|
41
|
+
x: 0,
|
|
42
|
+
y: 2,
|
|
43
|
+
width: 3,
|
|
44
|
+
height: 2
|
|
45
|
+
}, {
|
|
46
|
+
x: 3,
|
|
47
|
+
y: 3,
|
|
48
|
+
width: 1,
|
|
49
|
+
height: 1
|
|
50
|
+
}, {
|
|
51
|
+
x: 4,
|
|
52
|
+
y: 0,
|
|
53
|
+
width: 2,
|
|
54
|
+
height: 2
|
|
55
|
+
}, {
|
|
56
|
+
x: 4,
|
|
57
|
+
y: 2,
|
|
58
|
+
width: 1,
|
|
59
|
+
height: 1
|
|
60
|
+
}, {
|
|
61
|
+
x: 5,
|
|
62
|
+
y: 2,
|
|
63
|
+
width: 1,
|
|
64
|
+
height: 1
|
|
65
|
+
}, {
|
|
66
|
+
x: 4,
|
|
67
|
+
y: 3,
|
|
68
|
+
width: 2,
|
|
69
|
+
height: 1
|
|
70
|
+
}];
|
|
71
|
+
export var SECTION_SIZE = 2;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*:: export type Index = {
|
|
2
|
+
index: number,
|
|
3
|
+
};*/
|
|
4
|
+
/*:: export type PositionInfo = {
|
|
5
|
+
x: number,
|
|
6
|
+
y: number,
|
|
7
|
+
};*/
|
|
8
|
+
/*:: export type ScrollPosition = {
|
|
9
|
+
scrollLeft: number,
|
|
10
|
+
scrollTop: number,
|
|
11
|
+
};*/
|
|
12
|
+
/*:: export type SizeAndPositionInfo = {
|
|
13
|
+
height: number,
|
|
14
|
+
width: number,
|
|
15
|
+
x: number,
|
|
16
|
+
y: number,
|
|
17
|
+
};*/
|
|
18
|
+
/*:: export type SizeInfo = {
|
|
19
|
+
height: number,
|
|
20
|
+
width: number,
|
|
21
|
+
};*/
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import calculateSizeAndPositionData from './calculateSizeAndPositionData';
|
|
2
|
+
describe('calculateSizeAndPositionData', function () {
|
|
3
|
+
it('should query for size and position of each cell', function () {
|
|
4
|
+
var cellSizeAndPositionGetterCalls = [];
|
|
5
|
+
function cellSizeAndPositionGetter(_ref) {
|
|
6
|
+
var index = _ref.index;
|
|
7
|
+
cellSizeAndPositionGetterCalls.push(index);
|
|
8
|
+
return {
|
|
9
|
+
x: index * 50,
|
|
10
|
+
y: 0,
|
|
11
|
+
width: 50,
|
|
12
|
+
height: 50
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
var _calculateSizeAndPosi = calculateSizeAndPositionData({
|
|
16
|
+
cellCount: 3,
|
|
17
|
+
cellSizeAndPositionGetter: cellSizeAndPositionGetter
|
|
18
|
+
}),
|
|
19
|
+
sectionManager = _calculateSizeAndPosi.sectionManager;
|
|
20
|
+
expect(cellSizeAndPositionGetterCalls).toEqual([0, 1, 2]);
|
|
21
|
+
expect(sectionManager.getTotalSectionCount()).toEqual(2);
|
|
22
|
+
});
|
|
23
|
+
it('should throw an error if invalid metadata is returned for a cell', function () {
|
|
24
|
+
expect(function () {
|
|
25
|
+
return calculateSizeAndPositionData({
|
|
26
|
+
cellCount: 3,
|
|
27
|
+
cellSizeAndPositionGetter: function cellSizeAndPositionGetter() {}
|
|
28
|
+
});
|
|
29
|
+
}).toThrow();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import SectionManager from '../SectionManager';
|
|
2
|
+
export default function calculateSizeAndPositionData(_ref) {
|
|
3
|
+
var cellCount = _ref.cellCount,
|
|
4
|
+
cellSizeAndPositionGetter = _ref.cellSizeAndPositionGetter,
|
|
5
|
+
sectionSize = _ref.sectionSize;
|
|
6
|
+
var cellMetadata = [];
|
|
7
|
+
var sectionManager = new SectionManager(sectionSize);
|
|
8
|
+
var height = 0;
|
|
9
|
+
var width = 0;
|
|
10
|
+
for (var index = 0; index < cellCount; index++) {
|
|
11
|
+
var cellMetadatum = cellSizeAndPositionGetter({
|
|
12
|
+
index: index
|
|
13
|
+
});
|
|
14
|
+
if (cellMetadatum.height == null || isNaN(cellMetadatum.height) || cellMetadatum.width == null || isNaN(cellMetadatum.width) || cellMetadatum.x == null || isNaN(cellMetadatum.x) || cellMetadatum.y == null || isNaN(cellMetadatum.y)) {
|
|
15
|
+
throw Error("Invalid metadata returned for cell ".concat(index, ":\n x:").concat(cellMetadatum.x, ", y:").concat(cellMetadatum.y, ", width:").concat(cellMetadatum.width, ", height:").concat(cellMetadatum.height));
|
|
16
|
+
}
|
|
17
|
+
height = Math.max(height, cellMetadatum.y + cellMetadatum.height);
|
|
18
|
+
width = Math.max(width, cellMetadatum.x + cellMetadatum.width);
|
|
19
|
+
cellMetadata[index] = cellMetadatum;
|
|
20
|
+
sectionManager.registerCell({
|
|
21
|
+
cellMetadatum: cellMetadatum,
|
|
22
|
+
index: index
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
cellMetadata: cellMetadata,
|
|
27
|
+
height: height,
|
|
28
|
+
sectionManager: sectionManager,
|
|
29
|
+
width: width
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
8
|
+
import * as React from 'react';
|
|
9
|
+
import styles from './ColumnSizer.example.css';
|
|
10
|
+
import AutoSizer from '../AutoSizer';
|
|
11
|
+
import ColumnSizer from './ColumnSizer';
|
|
12
|
+
import Grid from '../Grid';
|
|
13
|
+
import { ContentBox, ContentBoxHeader, ContentBoxParagraph } from '../demo/ContentBox';
|
|
14
|
+
import { LabeledInput, InputRow } from '../demo/LabeledInput';
|
|
15
|
+
var ColumnSizerExample = /*#__PURE__*/function (_React$PureComponent) {
|
|
16
|
+
function ColumnSizerExample(props) {
|
|
17
|
+
var _this;
|
|
18
|
+
_classCallCheck(this, ColumnSizerExample);
|
|
19
|
+
_this = _callSuper(this, ColumnSizerExample, [props]);
|
|
20
|
+
_this.state = {
|
|
21
|
+
columnMaxWidth: 100,
|
|
22
|
+
columnMinWidth: 75,
|
|
23
|
+
columnCount: 10
|
|
24
|
+
};
|
|
25
|
+
_this._noColumnMaxWidthChange = _this._noColumnMaxWidthChange.bind(_this);
|
|
26
|
+
_this._noColumnMinWidthChange = _this._noColumnMinWidthChange.bind(_this);
|
|
27
|
+
_this._onColumnCountChange = _this._onColumnCountChange.bind(_this);
|
|
28
|
+
_this._noContentRenderer = _this._noContentRenderer.bind(_this);
|
|
29
|
+
_this._cellRenderer = _this._cellRenderer.bind(_this);
|
|
30
|
+
return _this;
|
|
31
|
+
}
|
|
32
|
+
_inherits(ColumnSizerExample, _React$PureComponent);
|
|
33
|
+
return _createClass(ColumnSizerExample, [{
|
|
34
|
+
key: "render",
|
|
35
|
+
value: function render() {
|
|
36
|
+
var _this2 = this;
|
|
37
|
+
var _this$state = this.state,
|
|
38
|
+
columnMaxWidth = _this$state.columnMaxWidth,
|
|
39
|
+
columnMinWidth = _this$state.columnMinWidth,
|
|
40
|
+
columnCount = _this$state.columnCount;
|
|
41
|
+
return /*#__PURE__*/React.createElement(ContentBox, null, /*#__PURE__*/React.createElement(ContentBoxHeader, {
|
|
42
|
+
text: "ColumnSizer",
|
|
43
|
+
sourceLink: "https://github.com/bvaughn/react-virtualized/blob/master/source/ColumnSizer/ColumnSizer.example.js",
|
|
44
|
+
docsLink: "https://github.com/bvaughn/react-virtualized/blob/master/docs/ColumnSizer.md"
|
|
45
|
+
}), /*#__PURE__*/React.createElement(ContentBoxParagraph, null, "This component decorates a ", /*#__PURE__*/React.createElement("code", null, "Grid"), " and calculates the width of its columns based on the current (", /*#__PURE__*/React.createElement("code", null, "Grid"), ") width."), /*#__PURE__*/React.createElement(InputRow, null, /*#__PURE__*/React.createElement(LabeledInput, {
|
|
46
|
+
label: "Num Columns",
|
|
47
|
+
name: "columnCount",
|
|
48
|
+
onChange: this._onColumnCountChange,
|
|
49
|
+
value: columnCount
|
|
50
|
+
}), /*#__PURE__*/React.createElement(LabeledInput, {
|
|
51
|
+
label: "Column Min Width",
|
|
52
|
+
name: "columnMinWidth",
|
|
53
|
+
onChange: this._noColumnMinWidthChange,
|
|
54
|
+
value: columnMinWidth
|
|
55
|
+
}), /*#__PURE__*/React.createElement(LabeledInput, {
|
|
56
|
+
label: "Column Max Width",
|
|
57
|
+
name: "columnMaxWidth",
|
|
58
|
+
onChange: this._noColumnMaxWidthChange,
|
|
59
|
+
value: columnMaxWidth
|
|
60
|
+
})), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(AutoSizer, {
|
|
61
|
+
disableHeight: true
|
|
62
|
+
}, function (_ref) {
|
|
63
|
+
var width = _ref.width;
|
|
64
|
+
return /*#__PURE__*/React.createElement(ColumnSizer, {
|
|
65
|
+
columnMaxWidth: columnMaxWidth,
|
|
66
|
+
columnMinWidth: columnMinWidth,
|
|
67
|
+
columnCount: columnCount,
|
|
68
|
+
key: "GridColumnSizer",
|
|
69
|
+
width: width
|
|
70
|
+
}, function (_ref2) {
|
|
71
|
+
var adjustedWidth = _ref2.adjustedWidth,
|
|
72
|
+
columnWidth = _ref2.columnWidth,
|
|
73
|
+
registerChild = _ref2.registerChild;
|
|
74
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
75
|
+
className: styles.GridContainer,
|
|
76
|
+
style: {
|
|
77
|
+
height: 50,
|
|
78
|
+
width: adjustedWidth
|
|
79
|
+
}
|
|
80
|
+
}, /*#__PURE__*/React.createElement(Grid, {
|
|
81
|
+
ref: registerChild,
|
|
82
|
+
columnWidth: columnWidth,
|
|
83
|
+
columnCount: columnCount,
|
|
84
|
+
height: 50,
|
|
85
|
+
noContentRenderer: _this2._noContentRenderer,
|
|
86
|
+
cellRenderer: _this2._cellRenderer,
|
|
87
|
+
rowHeight: 50,
|
|
88
|
+
rowCount: 1,
|
|
89
|
+
width: adjustedWidth
|
|
90
|
+
}));
|
|
91
|
+
});
|
|
92
|
+
})));
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
key: "_noColumnMaxWidthChange",
|
|
96
|
+
value: function _noColumnMaxWidthChange(event) {
|
|
97
|
+
var columnMaxWidth = parseInt(event.target.value, 10);
|
|
98
|
+
if (isNaN(columnMaxWidth)) {
|
|
99
|
+
columnMaxWidth = undefined;
|
|
100
|
+
} else {
|
|
101
|
+
columnMaxWidth = Math.min(1000, columnMaxWidth);
|
|
102
|
+
}
|
|
103
|
+
this.setState({
|
|
104
|
+
columnMaxWidth: columnMaxWidth
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "_noColumnMinWidthChange",
|
|
109
|
+
value: function _noColumnMinWidthChange(event) {
|
|
110
|
+
var columnMinWidth = parseInt(event.target.value, 10);
|
|
111
|
+
if (isNaN(columnMinWidth)) {
|
|
112
|
+
columnMinWidth = undefined;
|
|
113
|
+
} else {
|
|
114
|
+
columnMinWidth = Math.max(1, columnMinWidth);
|
|
115
|
+
}
|
|
116
|
+
this.setState({
|
|
117
|
+
columnMinWidth: columnMinWidth
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "_onColumnCountChange",
|
|
122
|
+
value: function _onColumnCountChange(event) {
|
|
123
|
+
this.setState({
|
|
124
|
+
columnCount: parseInt(event.target.value, 10) || 0
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}, {
|
|
128
|
+
key: "_noContentRenderer",
|
|
129
|
+
value: function _noContentRenderer() {
|
|
130
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
131
|
+
className: styles.noCells
|
|
132
|
+
}, "No cells");
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "_cellRenderer",
|
|
136
|
+
value: function _cellRenderer(_ref3) {
|
|
137
|
+
var columnIndex = _ref3.columnIndex,
|
|
138
|
+
key = _ref3.key,
|
|
139
|
+
rowIndex = _ref3.rowIndex,
|
|
140
|
+
style = _ref3.style;
|
|
141
|
+
var className = columnIndex === 0 ? styles.firstCell : styles.cell;
|
|
142
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
143
|
+
className: className,
|
|
144
|
+
key: key,
|
|
145
|
+
style: style
|
|
146
|
+
}, "R:".concat(rowIndex, ", C:").concat(columnIndex));
|
|
147
|
+
}
|
|
148
|
+
}]);
|
|
149
|
+
}(React.PureComponent);
|
|
150
|
+
export { ColumnSizerExample as default };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { findDOMNode } from 'react-dom';
|
|
3
|
+
import { render } from '../TestUtils';
|
|
4
|
+
import ColumnSizer from './ColumnSizer';
|
|
5
|
+
import Grid from '../Grid';
|
|
6
|
+
describe('ColumnSizer', function () {
|
|
7
|
+
function getMarkup() {
|
|
8
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
9
|
+
_ref$columnMinWidth = _ref.columnMinWidth,
|
|
10
|
+
columnMinWidth = _ref$columnMinWidth === void 0 ? undefined : _ref$columnMinWidth,
|
|
11
|
+
_ref$columnMaxWidth = _ref.columnMaxWidth,
|
|
12
|
+
columnMaxWidth = _ref$columnMaxWidth === void 0 ? undefined : _ref$columnMaxWidth,
|
|
13
|
+
_ref$columnCount = _ref.columnCount,
|
|
14
|
+
columnCount = _ref$columnCount === void 0 ? 10 : _ref$columnCount,
|
|
15
|
+
_ref$width = _ref.width,
|
|
16
|
+
width = _ref$width === void 0 ? 200 : _ref$width;
|
|
17
|
+
function cellRenderer(_ref2) {
|
|
18
|
+
var columnIndex = _ref2.columnIndex,
|
|
19
|
+
key = _ref2.key,
|
|
20
|
+
rowIndex = _ref2.rowIndex,
|
|
21
|
+
style = _ref2.style;
|
|
22
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
23
|
+
className: "gridItem",
|
|
24
|
+
key: key,
|
|
25
|
+
style: style
|
|
26
|
+
}, "row:".concat(rowIndex, ", column:").concat(columnIndex));
|
|
27
|
+
}
|
|
28
|
+
return /*#__PURE__*/React.createElement(ColumnSizer, {
|
|
29
|
+
columnMinWidth: columnMinWidth,
|
|
30
|
+
columnMaxWidth: columnMaxWidth,
|
|
31
|
+
columnCount: columnCount,
|
|
32
|
+
width: width
|
|
33
|
+
}, function (_ref3) {
|
|
34
|
+
var adjustedWidth = _ref3.adjustedWidth,
|
|
35
|
+
columnWidth = _ref3.columnWidth,
|
|
36
|
+
registerChild = _ref3.registerChild;
|
|
37
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Grid, {
|
|
38
|
+
columnCount: columnCount,
|
|
39
|
+
columnWidth: columnWidth,
|
|
40
|
+
height: 50,
|
|
41
|
+
ref: registerChild,
|
|
42
|
+
cellRenderer: cellRenderer,
|
|
43
|
+
rowHeight: 50,
|
|
44
|
+
rowCount: 1,
|
|
45
|
+
width: adjustedWidth
|
|
46
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
47
|
+
className: "debug"
|
|
48
|
+
}, "adjustedWidth:".concat(adjustedWidth, " columnWidth:").concat(columnWidth)));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
it('should distribute column widths evenly if no min/max boundaries have been set', function () {
|
|
52
|
+
var rendered = findDOMNode(render(getMarkup()));
|
|
53
|
+
expect(rendered.querySelector('.debug').textContent).toContain('columnWidth:20');
|
|
54
|
+
});
|
|
55
|
+
it('should respect :columnMaxWidth if specified', function () {
|
|
56
|
+
var rendered = findDOMNode(render(getMarkup({
|
|
57
|
+
columnMaxWidth: 10
|
|
58
|
+
})));
|
|
59
|
+
expect(rendered.querySelector('.debug').textContent).toContain('columnWidth:10');
|
|
60
|
+
});
|
|
61
|
+
it('should respect :columnMinWidth if specified', function () {
|
|
62
|
+
var rendered = findDOMNode(render(getMarkup({
|
|
63
|
+
columnMinWidth: 30
|
|
64
|
+
})));
|
|
65
|
+
expect(rendered.querySelector('.debug').textContent).toContain('columnWidth:30');
|
|
66
|
+
});
|
|
67
|
+
describe('recomputeGridSize', function () {
|
|
68
|
+
function helper(updatedProps, expectedTextContent) {
|
|
69
|
+
var renderedA = findDOMNode(render(getMarkup()));
|
|
70
|
+
expect(renderedA.querySelector('.debug').textContent).toContain('columnWidth:20');
|
|
71
|
+
var renderedB = findDOMNode(render(getMarkup(updatedProps)));
|
|
72
|
+
expect(renderedB.querySelector('.debug').textContent).toContain(expectedTextContent);
|
|
73
|
+
}
|
|
74
|
+
it('should recompute metadata sizes if :columnMinWidth changes', function () {
|
|
75
|
+
helper({
|
|
76
|
+
columnMinWidth: 30
|
|
77
|
+
}, 'columnWidth:30');
|
|
78
|
+
});
|
|
79
|
+
it('should recompute metadata sizes if :columnMaxWidth changes', function () {
|
|
80
|
+
helper({
|
|
81
|
+
columnMaxWidth: 15
|
|
82
|
+
}, 'columnWidth:15');
|
|
83
|
+
});
|
|
84
|
+
it('should recompute metadata sizes if :width changes', function () {
|
|
85
|
+
helper({
|
|
86
|
+
width: 300
|
|
87
|
+
}, 'columnWidth:30');
|
|
88
|
+
});
|
|
89
|
+
it('should recompute metadata sizes if :columnCount changes', function () {
|
|
90
|
+
helper({
|
|
91
|
+
columnCount: 2
|
|
92
|
+
}, 'columnWidth:100');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it('should pass the :width as :adjustedWidth if columns require more than the :width to be displayed', function () {
|
|
96
|
+
var rendered = findDOMNode(render(getMarkup({
|
|
97
|
+
columnMinWidth: 30
|
|
98
|
+
})));
|
|
99
|
+
expect(rendered.querySelector('.debug').textContent).toContain('adjustedWidth:200');
|
|
100
|
+
});
|
|
101
|
+
it('should pass an :adjustedWidth if columns require less than the :width to be displayed', function () {
|
|
102
|
+
var rendered = findDOMNode(render(getMarkup({
|
|
103
|
+
columnMaxWidth: 10
|
|
104
|
+
})));
|
|
105
|
+
expect(rendered.querySelector('.debug').textContent).toContain('adjustedWidth:100');
|
|
106
|
+
});
|
|
107
|
+
it('should error if the registered child is not a Grid or a MultiGrid', function () {
|
|
108
|
+
spyOn(console, 'error');
|
|
109
|
+
expect(function () {
|
|
110
|
+
render(/*#__PURE__*/React.createElement(ColumnSizer, {
|
|
111
|
+
columnMinWidth: 100,
|
|
112
|
+
columnMaxWidth: 100,
|
|
113
|
+
columnCount: 100,
|
|
114
|
+
width: 100
|
|
115
|
+
}, function (_ref4) {
|
|
116
|
+
var registerChild = _ref4.registerChild;
|
|
117
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
118
|
+
ref: registerChild
|
|
119
|
+
});
|
|
120
|
+
}));
|
|
121
|
+
}).toThrow();
|
|
122
|
+
});
|
|
123
|
+
});
|