@difizen/libro-virtualized 0.1.2

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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/auto-sizer/auto-sizer.d.ts +56 -0
  4. package/es/auto-sizer/auto-sizer.d.ts.map +1 -0
  5. package/es/auto-sizer/auto-sizer.js +157 -0
  6. package/es/auto-sizer/index.d.ts +3 -0
  7. package/es/auto-sizer/index.d.ts.map +1 -0
  8. package/es/auto-sizer/index.js +2 -0
  9. package/es/cell-measurer/cell-measurer-cache.d.ts +52 -0
  10. package/es/cell-measurer/cell-measurer-cache.d.ts.map +1 -0
  11. package/es/cell-measurer/cell-measurer-cache.js +176 -0
  12. package/es/cell-measurer/cell-measurer.d.ts +39 -0
  13. package/es/cell-measurer/cell-measurer.d.ts.map +1 -0
  14. package/es/cell-measurer/cell-measurer.js +154 -0
  15. package/es/cell-measurer/index.d.ts +5 -0
  16. package/es/cell-measurer/index.d.ts.map +1 -0
  17. package/es/cell-measurer/index.js +4 -0
  18. package/es/cell-measurer/types.d.ts +9 -0
  19. package/es/cell-measurer/types.d.ts.map +1 -0
  20. package/es/cell-measurer/types.js +0 -0
  21. package/es/grid/accessibility-overscanIndices-getter.d.ts +11 -0
  22. package/es/grid/accessibility-overscanIndices-getter.d.ts.map +1 -0
  23. package/es/grid/accessibility-overscanIndices-getter.js +33 -0
  24. package/es/grid/default-cell-range-renderer.d.ts +10 -0
  25. package/es/grid/default-cell-range-renderer.d.ts.map +1 -0
  26. package/es/grid/default-cell-range-renderer.js +135 -0
  27. package/es/grid/default-overscanIndices-getter.d.ts +11 -0
  28. package/es/grid/default-overscanIndices-getter.d.ts.map +1 -0
  29. package/es/grid/default-overscanIndices-getter.js +28 -0
  30. package/es/grid/grid.d.ts +359 -0
  31. package/es/grid/grid.d.ts.map +1 -0
  32. package/es/grid/grid.js +1287 -0
  33. package/es/grid/index.d.ts +6 -0
  34. package/es/grid/index.d.ts.map +1 -0
  35. package/es/grid/index.js +4 -0
  36. package/es/grid/types.d.ts +87 -0
  37. package/es/grid/types.d.ts.map +1 -0
  38. package/es/grid/types.js +1 -0
  39. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts +17 -0
  40. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts.map +1 -0
  41. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.js +25 -0
  42. package/es/grid/utils/cell-size-and-position-manager-row.d.ts +97 -0
  43. package/es/grid/utils/cell-size-and-position-manager-row.d.ts.map +1 -0
  44. package/es/grid/utils/cell-size-and-position-manager-row.js +297 -0
  45. package/es/grid/utils/cell-size-and-position-manager.d.ts +85 -0
  46. package/es/grid/utils/cell-size-and-position-manager.d.ts.map +1 -0
  47. package/es/grid/utils/cell-size-and-position-manager.js +268 -0
  48. package/es/grid/utils/max-element-size.d.ts +2 -0
  49. package/es/grid/utils/max-element-size.d.ts.map +1 -0
  50. package/es/grid/utils/max-element-size.js +17 -0
  51. package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts +78 -0
  52. package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts.map +1 -0
  53. package/es/grid/utils/scaling-cell-size-and-position-manager-row.js +187 -0
  54. package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts +70 -0
  55. package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts.map +1 -0
  56. package/es/grid/utils/scaling-cell-size-and-position-manager.js +187 -0
  57. package/es/grid/utils/update-scroll-index-helper.d.ts +24 -0
  58. package/es/grid/utils/update-scroll-index-helper.d.ts.map +1 -0
  59. package/es/grid/utils/update-scroll-index-helper.js +40 -0
  60. package/es/index.d.ts +5 -0
  61. package/es/index.d.ts.map +1 -0
  62. package/es/index.js +4 -0
  63. package/es/list/index.d.ts +3 -0
  64. package/es/list/index.d.ts.map +1 -0
  65. package/es/list/index.js +1 -0
  66. package/es/list/list.d.ts +109 -0
  67. package/es/list/list.d.ts.map +1 -0
  68. package/es/list/list.js +261 -0
  69. package/es/list/types.d.ts +22 -0
  70. package/es/list/types.d.ts.map +1 -0
  71. package/es/list/types.js +1 -0
  72. package/es/utils/animation-frame.d.ts +7 -0
  73. package/es/utils/animation-frame.d.ts.map +1 -0
  74. package/es/utils/animation-frame.js +20 -0
  75. package/es/utils/create-callback-memoizer.d.ts +5 -0
  76. package/es/utils/create-callback-memoizer.d.ts.map +1 -0
  77. package/es/utils/create-callback-memoizer.js +25 -0
  78. package/es/utils/get-updated-offset-for-index.d.ts +14 -0
  79. package/es/utils/get-updated-offset-for-index.d.ts.map +1 -0
  80. package/es/utils/get-updated-offset-for-index.js +32 -0
  81. package/es/utils/init-cell-metadata.d.ts +13 -0
  82. package/es/utils/init-cell-metadata.d.ts.map +1 -0
  83. package/es/utils/init-cell-metadata.js +32 -0
  84. package/es/utils/request-animation-timeout.d.ts +12 -0
  85. package/es/utils/request-animation-timeout.d.ts.map +1 -0
  86. package/es/utils/request-animation-timeout.js +33 -0
  87. package/es/utils/test-helper.d.ts +5 -0
  88. package/es/utils/test-helper.d.ts.map +1 -0
  89. package/es/utils/test-helper.js +31 -0
  90. package/es/vendor/binary-search-bounds.d.ts +22 -0
  91. package/es/vendor/binary-search-bounds.d.ts.map +1 -0
  92. package/es/vendor/binary-search-bounds.js +198 -0
  93. package/es/vendor/detect-element-resize.d.ts +16 -0
  94. package/es/vendor/detect-element-resize.d.ts.map +1 -0
  95. package/es/vendor/detect-element-resize.js +184 -0
  96. package/es/vendor/interval-tree.d.ts +10 -0
  97. package/es/vendor/interval-tree.d.ts.map +1 -0
  98. package/es/vendor/interval-tree.js +359 -0
  99. package/package.json +59 -0
  100. package/src/auto-sizer/auto-sizer.tsx +187 -0
  101. package/src/auto-sizer/index.ts +4 -0
  102. package/src/cell-measurer/cell-measurer-cache.ts +220 -0
  103. package/src/cell-measurer/cell-measurer.ts +151 -0
  104. package/src/cell-measurer/index.ts +5 -0
  105. package/src/cell-measurer/types.ts +8 -0
  106. package/src/grid/accessibility-overscanIndices-getter.ts +38 -0
  107. package/src/grid/default-cell-range-renderer.ts +166 -0
  108. package/src/grid/default-overscanIndices-getter.ts +32 -0
  109. package/src/grid/grid.tsx +1672 -0
  110. package/src/grid/index.ts +14 -0
  111. package/src/grid/types.ts +112 -0
  112. package/src/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.ts +62 -0
  113. package/src/grid/utils/cell-size-and-position-manager-row.ts +365 -0
  114. package/src/grid/utils/cell-size-and-position-manager.ts +309 -0
  115. package/src/grid/utils/max-element-size.ts +18 -0
  116. package/src/grid/utils/scaling-cell-size-and-position-manager-row.ts +206 -0
  117. package/src/grid/utils/scaling-cell-size-and-position-manager.ts +198 -0
  118. package/src/grid/utils/update-scroll-index-helper.ts +96 -0
  119. package/src/index.spec.ts +10 -0
  120. package/src/index.ts +4 -0
  121. package/src/list/index.ts +2 -0
  122. package/src/list/list.tsx +292 -0
  123. package/src/list/types.ts +25 -0
  124. package/src/utils/animation-frame.ts +38 -0
  125. package/src/utils/create-callback-memoizer.ts +32 -0
  126. package/src/utils/get-updated-offset-for-index.ts +33 -0
  127. package/src/utils/init-cell-metadata.ts +32 -0
  128. package/src/utils/request-animation-timeout.ts +44 -0
  129. package/src/utils/test-helper.ts +20 -0
  130. package/src/vendor/binary-search-bounds.ts +203 -0
  131. package/src/vendor/detect-element-resize.ts +241 -0
  132. package/src/vendor/interval-tree.ts +406 -0
@@ -0,0 +1,6 @@
1
+ export { default as accessibilityOverscanIndicesGetter } from './accessibility-overscanIndices-getter.js';
2
+ export { default as defaultCellRangeRenderer } from './default-cell-range-renderer.js';
3
+ export { default as defaultOverscanIndicesGetter } from './default-overscanIndices-getter.js';
4
+ export { default, default as Grid } from './grid.js';
5
+ export type { Alignment, CellPosition, CellRendererParams, CellSize, NoContentRenderer, OverscanIndicesGetter, RenderedSection, Scroll, } from './types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/grid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC1G,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACvF,OAAO,EAAE,OAAO,IAAI,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AACrD,YAAY,EACV,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,MAAM,GACP,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { default as accessibilityOverscanIndicesGetter } from "./accessibility-overscanIndices-getter.js";
2
+ export { default as defaultCellRangeRenderer } from "./default-cell-range-renderer.js";
3
+ export { default as defaultOverscanIndicesGetter } from "./default-overscanIndices-getter.js";
4
+ export { default, default as Grid } from "./grid.js";
@@ -0,0 +1,87 @@
1
+ import type * as React from 'react';
2
+ import type ScalingCellSizeAndPositionManager from './utils/scaling-cell-size-and-position-manager.js';
3
+ export type CellPosition = {
4
+ columnIndex: number;
5
+ rowIndex: number;
6
+ };
7
+ export type CellRendererParams = {
8
+ columnIndex: number;
9
+ isScrolling: boolean;
10
+ isVisible: boolean;
11
+ key: string;
12
+ parent: object;
13
+ rowIndex: number;
14
+ style: object;
15
+ };
16
+ export type CellRenderer = (props: CellRendererParams) => React.ReactNode;
17
+ export type CellCache = Record<string, React.ReactNode>;
18
+ export type StyleCache = Record<string, object>;
19
+ export type CellRangeRendererParams = {
20
+ cellCache: CellCache;
21
+ cellRenderer: CellRenderer;
22
+ columnSizeAndPositionManager: ScalingCellSizeAndPositionManager;
23
+ columnStartIndex: number;
24
+ columnStopIndex: number;
25
+ deferredMeasurementCache?: object;
26
+ horizontalOffsetAdjustment: number;
27
+ isScrolling: boolean;
28
+ isScrollingOptOut: boolean;
29
+ parent: object;
30
+ rowSizeAndPositionManager: ScalingCellSizeAndPositionManager;
31
+ rowStartIndex: number;
32
+ rowStopIndex: number;
33
+ scrollLeft: number;
34
+ scrollTop: number;
35
+ styleCache: StyleCache;
36
+ verticalOffsetAdjustment: number;
37
+ visibleColumnIndices: Record<any, any>;
38
+ visibleRowIndices: Record<any, any>;
39
+ };
40
+ export type CellRangeRenderer = (params: CellRangeRendererParams) => React.ReactNode[];
41
+ export type CellSizeGetter = (params: {
42
+ index: number;
43
+ }) => number;
44
+ export type CellSize = CellSizeGetter | number;
45
+ export type NoContentRenderer = () => React.ReactNode | null;
46
+ export type Scroll = {
47
+ clientHeight: number;
48
+ clientWidth: number;
49
+ scrollHeight: number;
50
+ scrollLeft: number;
51
+ scrollTop: number;
52
+ scrollWidth: number;
53
+ };
54
+ export type ScrollbarPresenceChange = {
55
+ horizontal: boolean;
56
+ vertical: boolean;
57
+ size: number;
58
+ };
59
+ export type RenderedSection = {
60
+ columnOverscanStartIndex: number;
61
+ columnOverscanStopIndex: number;
62
+ columnStartIndex: number;
63
+ columnStopIndex: number;
64
+ rowOverscanStartIndex: number;
65
+ rowOverscanStopIndex: number;
66
+ rowStartIndex: number;
67
+ rowStopIndex: number;
68
+ };
69
+ export type OverscanIndicesGetterParams = {
70
+ direction: 'horizontal' | 'vertical';
71
+ scrollDirection: -1 | 1;
72
+ cellCount: number;
73
+ overscanCellsCount: number;
74
+ startIndex: number;
75
+ stopIndex: number;
76
+ };
77
+ export type OverscanIndices = {
78
+ overscanStartIndex: number;
79
+ overscanStopIndex: number;
80
+ };
81
+ export type OverscanIndicesGetter = (params: OverscanIndicesGetterParams) => OverscanIndices;
82
+ export type Alignment = 'auto' | 'end' | 'start' | 'center';
83
+ export type VisibleCellRange = {
84
+ start?: number;
85
+ stop?: number;
86
+ };
87
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,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MAAM,MAAM,2BAA2B,GAAG;IAExC,SAAS,EAAE,YAAY,GAAG,UAAU,CAAC;IAGrC,eAAe,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IAGxB,SAAS,EAAE,MAAM,CAAC;IAGlB,kBAAkB,EAAE,MAAM,CAAC;IAG3B,UAAU,EAAE,MAAM,CAAC;IAGnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,CAClC,MAAM,EAAE,2BAA2B,KAChC,eAAe,CAAC;AAErB,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Helper method that determines when to recalculate row or column metadata.
3
+ */
4
+ type Params<T> = {
5
+ cellCount: number;
6
+ cellSize?: number | null;
7
+ computeMetadataCallback: (props: T) => void;
8
+ computeMetadataCallbackProps: T;
9
+ nextCellsCount: number;
10
+ nextCellSize?: number | null;
11
+ nextScrollToIndex: number;
12
+ scrollToIndex: number;
13
+ updateScrollOffsetForScrollToIndex: () => void;
14
+ };
15
+ export default function calculateSizeAndPositionDataAndUpdateScrollOffset({ cellCount, cellSize, computeMetadataCallback, computeMetadataCallbackProps, nextCellsCount, nextCellSize, nextScrollToIndex, scrollToIndex, updateScrollOffsetForScrollToIndex, }: Params<any>): void;
16
+ export {};
17
+ //# sourceMappingURL=calculate-size-and-position-data-and-update-scroll-offset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculate-size-and-position-data-and-update-scroll-offset.d.ts","sourceRoot":"","sources":["../../../src/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,KAAK,MAAM,CAAC,CAAC,IAAI;IAEf,SAAS,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAGzB,uBAAuB,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAG5C,4BAA4B,EAAE,CAAC,CAAC;IAGhC,cAAc,EAAE,MAAM,CAAC;IAGvB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAG7B,iBAAiB,EAAE,MAAM,CAAC;IAG1B,aAAa,EAAE,MAAM,CAAC;IAGtB,kCAAkC,EAAE,MAAM,IAAI,CAAC;CAChD,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,iDAAiD,CAAC,EACxE,SAAS,EACT,QAAQ,EACR,uBAAuB,EACvB,4BAA4B,EAC5B,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,kCAAkC,GACnC,EAAE,MAAM,CAAC,GAAG,CAAC,QAgBb"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Helper method that determines when to recalculate row or column metadata.
3
+ */
4
+ export default function calculateSizeAndPositionDataAndUpdateScrollOffset(_ref) {
5
+ var cellCount = _ref.cellCount,
6
+ cellSize = _ref.cellSize,
7
+ computeMetadataCallback = _ref.computeMetadataCallback,
8
+ computeMetadataCallbackProps = _ref.computeMetadataCallbackProps,
9
+ nextCellsCount = _ref.nextCellsCount,
10
+ nextCellSize = _ref.nextCellSize,
11
+ nextScrollToIndex = _ref.nextScrollToIndex,
12
+ scrollToIndex = _ref.scrollToIndex,
13
+ updateScrollOffsetForScrollToIndex = _ref.updateScrollOffsetForScrollToIndex;
14
+ // Don't compare cell sizes if they are functions because inline functions would cause infinite loops.
15
+ // In that event users should use the manual recompute methods to inform of changes.
16
+ if (cellCount !== nextCellsCount || (typeof cellSize === 'number' || typeof nextCellSize === 'number') && cellSize !== nextCellSize) {
17
+ computeMetadataCallback(computeMetadataCallbackProps);
18
+
19
+ // Updated cell metadata may have hidden the previous scrolled-to item.
20
+ // In this case we should also update the scrollTop to ensure it stays visible.
21
+ if (scrollToIndex >= 0 && scrollToIndex === nextScrollToIndex) {
22
+ updateScrollOffsetForScrollToIndex();
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,97 @@
1
+ import type { Alignment, CellSizeGetter, VisibleCellRange } from '../types.js';
2
+ type CellSizeAndPositionManagerParams = {
3
+ cellCount: number;
4
+ cellSizeGetter: CellSizeGetter;
5
+ estimatedCellSize: number;
6
+ cellsHeight: number[];
7
+ editorAreaHeight: number[];
8
+ totalSize: number;
9
+ editorsOffset: number[];
10
+ };
11
+ type ConfigureParams = {
12
+ cellCount: number;
13
+ estimatedCellSize: number;
14
+ cellSizeGetter: CellSizeGetter;
15
+ cellsHeight: number[];
16
+ editorAreaHeight: number[];
17
+ totalSize: number;
18
+ editorsOffset: number[];
19
+ };
20
+ type GetUpdatedOffsetForIndex = {
21
+ align: Alignment;
22
+ containerSize: number;
23
+ currentOffset: number;
24
+ targetIndex: number;
25
+ };
26
+ type GetVisibleCellRangeParams = {
27
+ containerSize: number;
28
+ offset: number;
29
+ };
30
+ type SizeAndPositionData = {
31
+ offset: number;
32
+ size: number;
33
+ };
34
+ /**
35
+ * Just-in-time calculates and caches size and position information for a collection of cells.
36
+ */
37
+ export default class RowCellSizeAndPositionManager {
38
+ _cellSizeAndPositionData: any;
39
+ _lastMeasuredIndex: number;
40
+ _lastBatchedIndex: number;
41
+ _cellCount: number;
42
+ _cellSizeGetter: CellSizeGetter;
43
+ _estimatedCellSize: number;
44
+ _cellsHeight: number[];
45
+ _editorAreaHeight: number[];
46
+ _totalSize: number;
47
+ _editorsOffset: number[];
48
+ constructor({ cellCount, cellSizeGetter, estimatedCellSize, cellsHeight, editorAreaHeight, totalSize, editorsOffset, }: CellSizeAndPositionManagerParams);
49
+ areOffsetsAdjusted(): boolean;
50
+ configure({ cellCount, estimatedCellSize, cellSizeGetter, cellsHeight, editorAreaHeight, totalSize, editorsOffset, }: ConfigureParams): void;
51
+ getCellCount(): number;
52
+ getEstimatedCellSize(): number;
53
+ getLastMeasuredIndex(): number;
54
+ getOffsetAdjustment(): number;
55
+ /**
56
+ * This method returns the size and position for the cell at the specified index.
57
+ * It just-in-time calculates (or used cached values) for cells leading up to the index.
58
+ */
59
+ getSizeAndPositionOfCell(index: number): SizeAndPositionData;
60
+ getSizeAndPositionOfLastMeasuredCell(): SizeAndPositionData;
61
+ /**
62
+ * Total size of all cells being measured.
63
+ * This value will be completely estimated initially.
64
+ * As cells are measured, the estimate will be updated.
65
+ */
66
+ getTotalSize(): number;
67
+ /**
68
+ * Determines a new offset that ensures a certain cell is visible, given the current offset.
69
+ * If the cell is already visible then the current offset will be returned.
70
+ * If the current offset is too great or small, it will be adjusted just enough to ensure the specified index is visible.
71
+ *
72
+ * @param align Desired alignment within container; one of "auto" (default), "start", or "end"
73
+ * @param containerSize Size (width or height) of the container viewport
74
+ * @param currentOffset Container's current (x or y) offset
75
+ * @param totalSize Total size (width or height) of all cells
76
+ * @return Offset to use to ensure the specified cell is visible
77
+ */
78
+ getUpdatedOffsetForIndex({ align, containerSize, currentOffset, targetIndex, }: GetUpdatedOffsetForIndex): number;
79
+ getVisibleCellRange(params: GetVisibleCellRangeParams): VisibleCellRange;
80
+ /**
81
+ * Clear all cached values for cells after the specified index.
82
+ * This method should be called for any cell that has changed its size.
83
+ * It will not immediately perform any calculations; they'll be performed the next time getSizeAndPositionOfCell() is called.
84
+ */
85
+ resetCell(index: number): void;
86
+ _binarySearch(high: number, low: number, offset: number): number;
87
+ _exponentialSearch(index: number, offset: number): number;
88
+ /**
89
+ * Searches for the cell (index) nearest the specified offset.
90
+ *
91
+ * If no exact match is found the next lowest cell index will be returned.
92
+ * This allows partially visible cells (with offsets just before/above the fold) to be visible.
93
+ */
94
+ _findNearestCell(offset: number): number;
95
+ }
96
+ export {};
97
+ //# sourceMappingURL=cell-size-and-position-manager-row.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-size-and-position-manager-row.d.ts","sourceRoot":"","sources":["../../../src/grid/utils/cell-size-and-position-manager-row.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E,KAAK,gCAAgC,GAAG;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,6BAA6B;IAGhD,wB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,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAsBzC"}
@@ -0,0 +1,297 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ /* eslint-disable prefer-const */
8
+ /* eslint-disable @typescript-eslint/no-unused-vars */
9
+ /* eslint-disable no-param-reassign */
10
+ /**
11
+ * Just-in-time calculates and caches size and position information for a collection of cells.
12
+ */
13
+ var RowCellSizeAndPositionManager = /*#__PURE__*/function () {
14
+ function RowCellSizeAndPositionManager(_ref) {
15
+ var cellCount = _ref.cellCount,
16
+ cellSizeGetter = _ref.cellSizeGetter,
17
+ estimatedCellSize = _ref.estimatedCellSize,
18
+ cellsHeight = _ref.cellsHeight,
19
+ editorAreaHeight = _ref.editorAreaHeight,
20
+ totalSize = _ref.totalSize,
21
+ editorsOffset = _ref.editorsOffset;
22
+ _classCallCheck(this, RowCellSizeAndPositionManager);
23
+ // Cache of size and position data for cells, mapped by cell index.
24
+ // Note that invalid values may exist in this map so only rely on cells up to this._lastMeasuredIndex
25
+ this._cellSizeAndPositionData = {};
26
+ // Measurements for cells up to this index can be trusted; cells afterward should be estimated.
27
+ this._lastMeasuredIndex = -1;
28
+ // Used in deferred mode to track which cells have been queued for measurement.
29
+ this._lastBatchedIndex = -1;
30
+ // this._cellSizeGetter = cellSizeGetter;
31
+ this._cellCount = cellCount;
32
+ this._estimatedCellSize = estimatedCellSize;
33
+ this._cellsHeight = cellsHeight;
34
+ this._editorAreaHeight = editorAreaHeight;
35
+ this._editorsOffset = editorsOffset;
36
+ this._totalSize = totalSize;
37
+ this._lastMeasuredIndex = -1;
38
+ this._cellSizeAndPositionData = {};
39
+
40
+ // this._cellSizeGetter = (params: { index: number }) => {
41
+ // // return this._cellsHeight[params.index];
42
+ // return this._editorAreaHeight[params.index];
43
+ // };
44
+ }
45
+ _createClass(RowCellSizeAndPositionManager, [{
46
+ key: "areOffsetsAdjusted",
47
+ value: function areOffsetsAdjusted() {
48
+ return false;
49
+ }
50
+ }, {
51
+ key: "configure",
52
+ value: function configure(_ref2) {
53
+ var cellCount = _ref2.cellCount,
54
+ estimatedCellSize = _ref2.estimatedCellSize,
55
+ cellSizeGetter = _ref2.cellSizeGetter,
56
+ cellsHeight = _ref2.cellsHeight,
57
+ editorAreaHeight = _ref2.editorAreaHeight,
58
+ totalSize = _ref2.totalSize,
59
+ editorsOffset = _ref2.editorsOffset;
60
+ this._cellCount = cellCount;
61
+ this._estimatedCellSize = estimatedCellSize;
62
+ // this._cellSizeGetter = cellSizeGetter;
63
+ this._cellsHeight = cellsHeight;
64
+ this._editorAreaHeight = editorAreaHeight;
65
+ this._editorsOffset = editorsOffset;
66
+ this._totalSize = totalSize;
67
+ this._lastMeasuredIndex = -1;
68
+ this._cellSizeAndPositionData = {};
69
+ }
70
+ }, {
71
+ key: "getCellCount",
72
+ value: function getCellCount() {
73
+ return this._cellCount;
74
+ }
75
+ }, {
76
+ key: "getEstimatedCellSize",
77
+ value: function getEstimatedCellSize() {
78
+ return this._estimatedCellSize;
79
+ }
80
+ }, {
81
+ key: "getLastMeasuredIndex",
82
+ value: function getLastMeasuredIndex() {
83
+ return this._lastMeasuredIndex;
84
+ }
85
+ }, {
86
+ key: "getOffsetAdjustment",
87
+ value: function getOffsetAdjustment() {
88
+ return 0;
89
+ }
90
+
91
+ /**
92
+ * This method returns the size and position for the cell at the specified index.
93
+ * It just-in-time calculates (or used cached values) for cells leading up to the index.
94
+ */
95
+ }, {
96
+ key: "getSizeAndPositionOfCell",
97
+ value: function getSizeAndPositionOfCell(index) {
98
+ if (index < 0 || index >= this._cellCount) {
99
+ throw Error("Requested index ".concat(index, " is outside of range 0..").concat(this._cellCount));
100
+ }
101
+ if (index > this._lastMeasuredIndex) {
102
+ var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
103
+ var offset = lastMeasuredCellSizeAndPosition.offset; // + lastMeasuredCellSizeAndPosition.size;
104
+
105
+ for (var i = this._lastMeasuredIndex + 1; i <= index; i++) {
106
+ // const size = this._cellSizeGetter({ index: i });
107
+ var size = this._editorAreaHeight[i];
108
+ offset = this._editorsOffset[i]; // 上border高度
109
+
110
+ // undefined or NaN probably means a logic error in the size getter.
111
+ // null means we're using CellMeasurer and haven't yet measured a given index.
112
+ if (size === undefined || isNaN(size)) {
113
+ throw Error("Invalid size returned for cell ".concat(i, " of value ").concat(size));
114
+ } else if (size === null) {
115
+ this._cellSizeAndPositionData[i] = {
116
+ offset: offset,
117
+ size: 0
118
+ };
119
+ this._lastBatchedIndex = index;
120
+ } else {
121
+ this._cellSizeAndPositionData[i] = {
122
+ offset: offset,
123
+ size: size
124
+ };
125
+ this._lastMeasuredIndex = index;
126
+ }
127
+ }
128
+ }
129
+ return this._cellSizeAndPositionData[index];
130
+ }
131
+ }, {
132
+ key: "getSizeAndPositionOfLastMeasuredCell",
133
+ value: function getSizeAndPositionOfLastMeasuredCell() {
134
+ return this._lastMeasuredIndex >= 0 ? this._cellSizeAndPositionData[this._lastMeasuredIndex] : {
135
+ offset: 0,
136
+ size: 0
137
+ };
138
+ }
139
+
140
+ /**
141
+ * Total size of all cells being measured.
142
+ * This value will be completely estimated initially.
143
+ * As cells are measured, the estimate will be updated.
144
+ */
145
+ }, {
146
+ key: "getTotalSize",
147
+ value: function getTotalSize() {
148
+ return this._totalSize;
149
+
150
+ // const lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
151
+ // const totalSizeOfMeasuredCells =
152
+ // lastMeasuredCellSizeAndPosition.offset + lastMeasuredCellSizeAndPosition.size;
153
+ // const numUnmeasuredCells = this._cellCount - this._lastMeasuredIndex - 1;
154
+ // const totalSizeOfUnmeasuredCells = numUnmeasuredCells * this._estimatedCellSize;
155
+ // return totalSizeOfMeasuredCells + totalSizeOfUnmeasuredCells;
156
+ }
157
+
158
+ /**
159
+ * Determines a new offset that ensures a certain cell is visible, given the current offset.
160
+ * If the cell is already visible then the current offset will be returned.
161
+ * If the current offset is too great or small, it will be adjusted just enough to ensure the specified index is visible.
162
+ *
163
+ * @param align Desired alignment within container; one of "auto" (default), "start", or "end"
164
+ * @param containerSize Size (width or height) of the container viewport
165
+ * @param currentOffset Container's current (x or y) offset
166
+ * @param totalSize Total size (width or height) of all cells
167
+ * @return Offset to use to ensure the specified cell is visible
168
+ */
169
+ }, {
170
+ key: "getUpdatedOffsetForIndex",
171
+ value: function getUpdatedOffsetForIndex(_ref3) {
172
+ var _ref3$align = _ref3.align,
173
+ align = _ref3$align === void 0 ? 'auto' : _ref3$align,
174
+ containerSize = _ref3.containerSize,
175
+ currentOffset = _ref3.currentOffset,
176
+ targetIndex = _ref3.targetIndex;
177
+ if (containerSize <= 0) {
178
+ return 0;
179
+ }
180
+ var datum = this.getSizeAndPositionOfCell(targetIndex);
181
+ var minOffset = datum.offset;
182
+ var maxOffset = datum.offset + datum.size - containerSize;
183
+ var idealOffset;
184
+ switch (align) {
185
+ case 'start':
186
+ idealOffset = minOffset;
187
+ break;
188
+ case 'end':
189
+ idealOffset = maxOffset;
190
+ break;
191
+ case 'center':
192
+ idealOffset = minOffset + datum.size / 2;
193
+ break;
194
+ default:
195
+ idealOffset = minOffset;
196
+ break;
197
+ }
198
+ var totalSize = this.getTotalSize();
199
+ return Math.max(0, Math.min(totalSize - containerSize, idealOffset));
200
+ }
201
+ }, {
202
+ key: "getVisibleCellRange",
203
+ value: function getVisibleCellRange(params) {
204
+ var containerSize = params.containerSize,
205
+ offset = params.offset;
206
+ var totalSize = this.getTotalSize();
207
+ if (totalSize === 0) {
208
+ return {};
209
+ }
210
+ var maxOffset = offset + containerSize;
211
+ var start = this._findNearestCell(offset);
212
+ var datum = this.getSizeAndPositionOfCell(start);
213
+ offset = datum.offset;
214
+ var stop = start;
215
+ while (offset < maxOffset && stop < this._cellCount - 1) {
216
+ stop++;
217
+ offset = this.getSizeAndPositionOfCell(stop).offset;
218
+ }
219
+ return {
220
+ start: start,
221
+ stop: stop
222
+ };
223
+ }
224
+
225
+ /**
226
+ * Clear all cached values for cells after the specified index.
227
+ * This method should be called for any cell that has changed its size.
228
+ * It will not immediately perform any calculations; they'll be performed the next time getSizeAndPositionOfCell() is called.
229
+ */
230
+ }, {
231
+ key: "resetCell",
232
+ value: function resetCell(index) {
233
+ this._lastMeasuredIndex = Math.min(this._lastMeasuredIndex, index - 1);
234
+ }
235
+ }, {
236
+ key: "_binarySearch",
237
+ value: function _binarySearch(high, low, offset) {
238
+ while (low <= high) {
239
+ var middle = low + Math.floor((high - low) / 2);
240
+ var currentOffset = this.getSizeAndPositionOfCell(middle).offset || (middle > 0 ? this.getSizeAndPositionOfCell(middle - 1).offset || 0 : 0);
241
+ if (currentOffset === offset) {
242
+ return middle;
243
+ } else if (currentOffset < offset) {
244
+ low = middle + 1;
245
+ } else if (currentOffset > offset) {
246
+ high = middle - 1;
247
+ }
248
+ }
249
+ if (low > 0) {
250
+ return low - 1;
251
+ } else {
252
+ return 0;
253
+ }
254
+ }
255
+ }, {
256
+ key: "_exponentialSearch",
257
+ value: function _exponentialSearch(index, offset) {
258
+ var interval = 1;
259
+ while (index < this._cellCount && this.getSizeAndPositionOfCell(index).offset < offset) {
260
+ index += interval;
261
+ interval *= 2;
262
+ }
263
+ return this._binarySearch(Math.min(index, this._cellCount - 1), Math.floor(index / 2), offset);
264
+ }
265
+
266
+ /**
267
+ * Searches for the cell (index) nearest the specified offset.
268
+ *
269
+ * If no exact match is found the next lowest cell index will be returned.
270
+ * This allows partially visible cells (with offsets just before/above the fold) to be visible.
271
+ */
272
+ }, {
273
+ key: "_findNearestCell",
274
+ value: function _findNearestCell(offset) {
275
+ if (isNaN(offset)) {
276
+ throw Error("Invalid offset ".concat(offset, " specified"));
277
+ }
278
+
279
+ // Our search algorithms find the nearest match at or below the specified offset.
280
+ // So make sure the offset is at least 0 or no match will be found.
281
+ offset = Math.max(0, offset);
282
+ var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
283
+ var lastMeasuredIndex = Math.max(0, this._lastMeasuredIndex);
284
+ if (lastMeasuredCellSizeAndPosition.offset >= offset) {
285
+ // If we've already measured cells within this range just use a binary search as it's faster.
286
+ return this._binarySearch(lastMeasuredIndex, 0, offset);
287
+ } else {
288
+ // If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
289
+ // The exponential search avoids pre-computing sizes for the full set of cells as a binary search would.
290
+ // The overall complexity for this approach is O(log n).
291
+ return this._exponentialSearch(lastMeasuredIndex, offset);
292
+ }
293
+ }
294
+ }]);
295
+ return RowCellSizeAndPositionManager;
296
+ }();
297
+ export { RowCellSizeAndPositionManager as default };
@@ -0,0 +1,85 @@
1
+ import type { Alignment, CellSizeGetter, VisibleCellRange } from '../types.js';
2
+ type CellSizeAndPositionManagerParams = {
3
+ cellCount: number;
4
+ cellSizeGetter: CellSizeGetter;
5
+ estimatedCellSize: number;
6
+ };
7
+ type ConfigureParams = {
8
+ cellCount: number;
9
+ estimatedCellSize: number;
10
+ cellSizeGetter: CellSizeGetter;
11
+ };
12
+ type GetUpdatedOffsetForIndex = {
13
+ align: Alignment;
14
+ containerSize: number;
15
+ currentOffset: number;
16
+ targetIndex: number;
17
+ };
18
+ type GetVisibleCellRangeParams = {
19
+ containerSize: number;
20
+ offset: number;
21
+ };
22
+ type SizeAndPositionData = {
23
+ offset: number;
24
+ size: number;
25
+ };
26
+ /**
27
+ * Just-in-time calculates and caches size and position information for a collection of cells.
28
+ */
29
+ export default class CellSizeAndPositionManager {
30
+ _cellSizeAndPositionData: any;
31
+ _lastMeasuredIndex: number;
32
+ _lastBatchedIndex: number;
33
+ _cellCount: number;
34
+ _cellSizeGetter: CellSizeGetter;
35
+ _estimatedCellSize: number;
36
+ constructor({ cellCount, cellSizeGetter, estimatedCellSize, }: CellSizeAndPositionManagerParams);
37
+ areOffsetsAdjusted(): boolean;
38
+ configure({ cellCount, estimatedCellSize, cellSizeGetter }: ConfigureParams): void;
39
+ getCellCount(): number;
40
+ getEstimatedCellSize(): number;
41
+ getLastMeasuredIndex(): number;
42
+ getOffsetAdjustment(): number;
43
+ /**
44
+ * This method returns the size and position for the cell at the specified index.
45
+ * It just-in-time calculates (or used cached values) for cells leading up to the index.
46
+ */
47
+ getSizeAndPositionOfCell(index: number): SizeAndPositionData;
48
+ getSizeAndPositionOfLastMeasuredCell(): SizeAndPositionData;
49
+ /**
50
+ * Total size of all cells being measured.
51
+ * This value will be completely estimated initially.
52
+ * As cells are measured, the estimate will be updated.
53
+ */
54
+ getTotalSize(): number;
55
+ /**
56
+ * Determines a new offset that ensures a certain cell is visible, given the current offset.
57
+ * If the cell is already visible then the current offset will be returned.
58
+ * If the current offset is too great or small, it will be adjusted just enough to ensure the specified index is visible.
59
+ *
60
+ * @param align Desired alignment within container; one of "auto" (default), "start", or "end"
61
+ * @param containerSize Size (width or height) of the container viewport
62
+ * @param currentOffset Container's current (x or y) offset
63
+ * @param totalSize Total size (width or height) of all cells
64
+ * @return Offset to use to ensure the specified cell is visible
65
+ */
66
+ getUpdatedOffsetForIndex({ align, containerSize, currentOffset, targetIndex, }: GetUpdatedOffsetForIndex): number;
67
+ getVisibleCellRange(params: GetVisibleCellRangeParams): VisibleCellRange;
68
+ /**
69
+ * Clear all cached values for cells after the specified index.
70
+ * This method should be called for any cell that has changed its size.
71
+ * It will not immediately perform any calculations; they'll be performed the next time getSizeAndPositionOfCell() is called.
72
+ */
73
+ resetCell(index: number): void;
74
+ _binarySearch(high: number, low: number, offset: number): number;
75
+ _exponentialSearch(index: number, offset: number): number;
76
+ /**
77
+ * Searches for the cell (index) nearest the specified offset.
78
+ *
79
+ * If no exact match is found the next lowest cell index will be returned.
80
+ * This allows partially visible cells (with offsets just before/above the fold) to be visible.
81
+ */
82
+ _findNearestCell(offset: number): number;
83
+ }
84
+ export {};
85
+ //# sourceMappingURL=cell-size-and-position-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-size-and-position-manager.d.ts","sourceRoot":"","sources":["../../../src/grid/utils/cell-size-and-position-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E,KAAK,gCAAgC,GAAG;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAA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