@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Difizen Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,56 @@
1
+ import * as React from 'react';
2
+ type Size = {
3
+ height: number;
4
+ width: number;
5
+ };
6
+ type Props = {
7
+ /** Function responsible for rendering children.*/
8
+ children: (param: Size) => React.ReactNode;
9
+ /** Optional custom CSS class name to attach to root AutoSizer element. */
10
+ className?: string;
11
+ /** Default height to use for initial render; useful for SSR */
12
+ defaultHeight?: number;
13
+ /** Default width to use for initial render; useful for SSR */
14
+ defaultWidth?: number;
15
+ /** Disable dynamic :height property */
16
+ disableHeight: boolean;
17
+ /** Disable dynamic :width property */
18
+ disableWidth: boolean;
19
+ /** Nonce of the inlined stylesheet for Content Security Policy */
20
+ nonce?: string;
21
+ /** Callback to be invoked on-resize */
22
+ onResize: (param: Size) => void;
23
+ /** Optional inline style */
24
+ style?: object;
25
+ };
26
+ type State = {
27
+ height: number;
28
+ width: number;
29
+ };
30
+ type ResizeHandler = (element: HTMLElement, onResize: () => void) => void;
31
+ type DetectElementResize = {
32
+ addResizeListener: ResizeHandler;
33
+ removeResizeListener: ResizeHandler;
34
+ };
35
+ export default class AutoSizer extends React.PureComponent<Props, State> {
36
+ static defaultProps: {
37
+ onResize: () => void;
38
+ disableHeight: boolean;
39
+ disableWidth: boolean;
40
+ style: {};
41
+ };
42
+ state: {
43
+ height: number;
44
+ width: number;
45
+ };
46
+ _parentNode?: HTMLElement;
47
+ _autoSizer: HTMLElement | null;
48
+ _detectElementResize: DetectElementResize;
49
+ componentDidMount(): void;
50
+ componentWillUnmount(): void;
51
+ render(): import("react/jsx-runtime").JSX.Element;
52
+ _onResize: () => void;
53
+ _setRef: (autoSizer: HTMLElement | null) => void;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=auto-sizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-sizer.d.ts","sourceRoot":"","sources":["../../src/auto-sizer/auto-sizer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,kDAAkD;IAClD,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,SAAS,CAAC;IAE3C,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,uCAAuC;IACvC,aAAa,EAAE,OAAO,CAAC;IAEvB,sCAAsC;IACtC,YAAY,EAAE,OAAO,CAAC;IAEtB,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,uCAAuC;IACvC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC;IAEhC,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,aAAa,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAE1E,KAAK,mBAAmB,GAAG;IACzB,iBAAiB,EAAE,aAAa,CAAC;IACjC,oBAAoB,EAAE,aAAa,CAAC;CACrC,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC;IACtE,MAAM,CAAC,YAAY;;;;;MAOjB;IAEO,KAAK;;;MAGZ;IAEF,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/B,oBAAoB,EAAE,mBAAmB,CAAC;IAEjC,iBAAiB;IAwBjB,oBAAoB;IAMpB,MAAM;IAkDf,SAAS,aAgCP;IAEF,OAAO,cAAe,WAAW,GAAG,IAAI,UAEtC;CACH"}
@@ -0,0 +1,157 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ 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); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
+ 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); }
10
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
14
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
+ import * as React from 'react';
18
+ import createDetectElementResize from "../vendor/detect-element-resize.js";
19
+ import { jsx as _jsx } from "react/jsx-runtime";
20
+ var AutoSizer = /*#__PURE__*/function (_React$PureComponent) {
21
+ _inherits(AutoSizer, _React$PureComponent);
22
+ var _super = _createSuper(AutoSizer);
23
+ function AutoSizer() {
24
+ var _this;
25
+ _classCallCheck(this, AutoSizer);
26
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27
+ args[_key] = arguments[_key];
28
+ }
29
+ _this = _super.call.apply(_super, [this].concat(args));
30
+ _this.state = {
31
+ height: _this.props.defaultHeight || 0,
32
+ width: _this.props.defaultWidth || 0
33
+ };
34
+ _this._onResize = function () {
35
+ var _this$props = _this.props,
36
+ disableHeight = _this$props.disableHeight,
37
+ disableWidth = _this$props.disableWidth,
38
+ onResize = _this$props.onResize;
39
+ if (_this._parentNode) {
40
+ // Guard against AutoSizer component being removed from the DOM immediately after being added.
41
+ // This can result in invalid style values which can result in NaN values if we don't handle them.
42
+ // See issue #150 for more context.
43
+
44
+ var height = _this._parentNode.offsetHeight || 0;
45
+ var width = _this._parentNode.offsetWidth || 0;
46
+ var style = window.getComputedStyle(_this._parentNode) || {};
47
+ var paddingLeft = parseInt(style.paddingLeft, 10) || 0;
48
+ var paddingRight = parseInt(style.paddingRight, 10) || 0;
49
+ var paddingTop = parseInt(style.paddingTop, 10) || 0;
50
+ var paddingBottom = parseInt(style.paddingBottom, 10) || 0;
51
+ var newHeight = height - paddingTop - paddingBottom;
52
+ var newWidth = width - paddingLeft - paddingRight;
53
+ if (!disableHeight && _this.state.height !== newHeight || !disableWidth && _this.state.width !== newWidth) {
54
+ _this.setState({
55
+ height: height - paddingTop - paddingBottom,
56
+ width: width - paddingLeft - paddingRight
57
+ });
58
+ onResize({
59
+ height: height,
60
+ width: width
61
+ });
62
+ }
63
+ }
64
+ };
65
+ _this._setRef = function (autoSizer) {
66
+ _this._autoSizer = autoSizer;
67
+ };
68
+ return _this;
69
+ }
70
+ _createClass(AutoSizer, [{
71
+ key: "componentDidMount",
72
+ value: function componentDidMount() {
73
+ var nonce = this.props.nonce;
74
+ if (this._autoSizer && this._autoSizer.parentNode && this._autoSizer.parentNode.ownerDocument && this._autoSizer.parentNode.ownerDocument.defaultView && this._autoSizer.parentNode instanceof this._autoSizer.parentNode.ownerDocument.defaultView.HTMLElement) {
75
+ // Delay access of parentNode until mount.
76
+ // This handles edge-cases where the component has already been unmounted before its ref has been set,
77
+ // As well as libraries like react-lite which have a slightly different lifecycle.
78
+ this._parentNode = this._autoSizer.parentNode;
79
+
80
+ // Defer requiring resize handler in order to support server-side rendering.
81
+ // See issue #41
82
+ this._detectElementResize = createDetectElementResize(nonce);
83
+ this._detectElementResize.addResizeListener(this._parentNode, this._onResize);
84
+ this._onResize();
85
+ }
86
+ }
87
+ }, {
88
+ key: "componentWillUnmount",
89
+ value: function componentWillUnmount() {
90
+ if (this._detectElementResize && this._parentNode) {
91
+ this._detectElementResize.removeResizeListener(this._parentNode, this._onResize);
92
+ }
93
+ }
94
+ }, {
95
+ key: "render",
96
+ value: function render() {
97
+ var _this$props2 = this.props,
98
+ children = _this$props2.children,
99
+ className = _this$props2.className,
100
+ disableHeight = _this$props2.disableHeight,
101
+ disableWidth = _this$props2.disableWidth,
102
+ style = _this$props2.style;
103
+ var _this$state = this.state,
104
+ height = _this$state.height,
105
+ width = _this$state.width;
106
+
107
+ // Outer div should not force width/height since that may prevent containers from shrinking.
108
+ // Inner component should overflow and use calculated width/height.
109
+ // See issue #68 for more information.
110
+ var outerStyle = {
111
+ overflow: 'visible'
112
+ };
113
+ var childParams = {
114
+ height: 0,
115
+ width: 0
116
+ };
117
+ if (!disableHeight) {
118
+ outerStyle['height'] = 0;
119
+ childParams['height'] = height;
120
+ }
121
+ if (!disableWidth) {
122
+ outerStyle['width'] = 0;
123
+ childParams['width'] = width;
124
+ }
125
+
126
+ /**
127
+ * TODO: Avoid rendering children before the initial measurements have been collected.
128
+ * At best this would just be wasting cycles.
129
+ * Add this check into version 10 though as it could break too many ref callbacks in version 9.
130
+ * Note that if default width/height props were provided this would still work with SSR.
131
+ if (
132
+ height !== 0 &&
133
+ width !== 0
134
+ ) {
135
+ child = children({ height, width })
136
+ }
137
+ */
138
+
139
+ return /*#__PURE__*/_jsx("div", {
140
+ className: className,
141
+ ref: this._setRef,
142
+ style: _objectSpread(_objectSpread({}, outerStyle), style),
143
+ children: children(childParams)
144
+ });
145
+ }
146
+ }]);
147
+ return AutoSizer;
148
+ }(React.PureComponent);
149
+ AutoSizer.defaultProps = {
150
+ onResize: function onResize() {
151
+ //
152
+ },
153
+ disableHeight: false,
154
+ disableWidth: false,
155
+ style: {}
156
+ };
157
+ export { AutoSizer as default };
@@ -0,0 +1,3 @@
1
+ export { default } from './auto-sizer.js';
2
+ export { default as AutoSizer } from './auto-sizer.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auto-sizer/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from "./auto-sizer.js";
2
+ export { default as AutoSizer } from "./auto-sizer.js";
@@ -0,0 +1,52 @@
1
+ /** @flow */
2
+ import type { CellMeasureCache } from './types.js';
3
+ export declare const DEFAULT_HEIGHT = 30;
4
+ export declare const DEFAULT_WIDTH = 100;
5
+ type KeyMapper = (rowIndex: number, columnIndex: number) => any;
6
+ type CellMeasurerCacheParams = {
7
+ defaultHeight?: number;
8
+ defaultWidth?: number;
9
+ fixedHeight?: boolean;
10
+ fixedWidth?: boolean;
11
+ minHeight?: number;
12
+ minWidth?: number;
13
+ keyMapper?: KeyMapper;
14
+ };
15
+ type Cache = Record<any, number>;
16
+ type IndexParam = {
17
+ index: number;
18
+ };
19
+ /**
20
+ * Caches measurements for a given cell.
21
+ */
22
+ export default class CellMeasurerCache implements CellMeasureCache {
23
+ _cellHeightCache: Cache;
24
+ _cellWidthCache: Cache;
25
+ _columnWidthCache: Cache;
26
+ _rowHeightCache: Cache;
27
+ _defaultHeight: number;
28
+ _defaultWidth: number;
29
+ _minHeight: number;
30
+ _minWidth: number;
31
+ _keyMapper: KeyMapper;
32
+ _hasFixedHeight: boolean;
33
+ _hasFixedWidth: boolean;
34
+ _columnCount: number;
35
+ _rowCount: number;
36
+ constructor(params?: CellMeasurerCacheParams);
37
+ clear(rowIndex: number, columnIndex?: number): void;
38
+ clearAll(): void;
39
+ columnWidth: ({ index }: IndexParam) => number;
40
+ get defaultHeight(): number;
41
+ get defaultWidth(): number;
42
+ hasFixedHeight(): boolean;
43
+ hasFixedWidth(): boolean;
44
+ getHeight(rowIndex: number, columnIndex?: number): number;
45
+ getWidth(rowIndex: number, columnIndex?: number): number;
46
+ has(rowIndex: number, columnIndex?: number): boolean;
47
+ rowHeight: ({ index }: IndexParam) => number;
48
+ set(rowIndex: number, columnIndex: number, width: number, height: number): void;
49
+ _updateCachedColumnAndRowSizes(rowIndex: number, columnIndex: number): void;
50
+ }
51
+ export {};
52
+ //# sourceMappingURL=cell-measurer-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-measurer-cache.d.ts","sourceRoot":"","sources":["../../src/cell-measurer/cell-measurer-cache.ts"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,aAAa,MAAM,CAAC;AAIjC,KAAK,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,GAAG,CAAC;AAEhE,KAAK,uBAAuB,GAAG;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,KAAK,KAAK,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAEjC,KAAK,UAAU,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,YAAW,gBAAgB;IAChE,gBAAgB,EAAE,KAAK,CAAM;IAC7B,eAAe,EAAE,KAAK,CAAM;IAC5B,iBAAiB,EAAE,KAAK,CAAM;IAC9B,eAAe,EAAE,KAAK,CAAM;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,SAAS,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,SAAK;IACjB,SAAS,SAAK;gBAEF,MAAM,GAAE,uBAA4B;IAmDhD,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,SAAI;IASvC,QAAQ;IASR,WAAW,cAAe,UAAU,YAMlC;IAEF,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,cAAc,IAAI,OAAO;IAIzB,aAAa,IAAI,OAAO;IAIxB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,MAAM;IAYpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,MAAM;IAYnD,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,OAAO;IAM/C,SAAS,cAAe,UAAU,YAMhC;IAEF,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAiB/E,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;CAsBrE"}
@@ -0,0 +1,176 @@
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
+ export var DEFAULT_HEIGHT = 30;
8
+ export var DEFAULT_WIDTH = 100;
9
+
10
+ // Enables more intelligent mapping of a given column and row index to an item ID.
11
+ // This prevents a cell cache from being invalidated when its parent collection is modified.
12
+ /**
13
+ * Caches measurements for a given cell.
14
+ */
15
+ var CellMeasurerCache = /*#__PURE__*/function () {
16
+ function CellMeasurerCache() {
17
+ var _this = this;
18
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ _classCallCheck(this, CellMeasurerCache);
20
+ this._cellHeightCache = {};
21
+ this._cellWidthCache = {};
22
+ this._columnWidthCache = {};
23
+ this._rowHeightCache = {};
24
+ this._columnCount = 0;
25
+ this._rowCount = 0;
26
+ this.columnWidth = function (_ref) {
27
+ var index = _ref.index;
28
+ var key = _this._keyMapper(0, index);
29
+ return Object.prototype.hasOwnProperty.call(_this._columnWidthCache, key) ? _this._columnWidthCache[key] : _this._defaultWidth;
30
+ };
31
+ this.rowHeight = function (_ref2) {
32
+ var index = _ref2.index;
33
+ var key = _this._keyMapper(index, 0);
34
+ return Object.prototype.hasOwnProperty.call(_this._rowHeightCache, key) ? _this._rowHeightCache[key] : _this._defaultHeight;
35
+ };
36
+ var defaultHeight = params.defaultHeight,
37
+ defaultWidth = params.defaultWidth,
38
+ fixedHeight = params.fixedHeight,
39
+ fixedWidth = params.fixedWidth,
40
+ keyMapper = params.keyMapper,
41
+ minHeight = params.minHeight,
42
+ minWidth = params.minWidth;
43
+ this._hasFixedHeight = fixedHeight === true;
44
+ this._hasFixedWidth = fixedWidth === true;
45
+ this._minHeight = minHeight || 0;
46
+ this._minWidth = minWidth || 0;
47
+ this._keyMapper = keyMapper || defaultKeyMapper;
48
+ this._defaultHeight = Math.max(this._minHeight, typeof defaultHeight === 'number' ? defaultHeight : DEFAULT_HEIGHT);
49
+ this._defaultWidth = Math.max(this._minWidth, typeof defaultWidth === 'number' ? defaultWidth : DEFAULT_WIDTH);
50
+ if (process.env['NODE_ENV'] !== 'production') {
51
+ if (this._hasFixedHeight === false && this._hasFixedWidth === false) {
52
+ console.warn("CellMeasurerCache should only measure a cell's width or height. " + 'You have configured CellMeasurerCache to measure both. ' + 'This will result in poor performance.');
53
+ }
54
+ if (this._hasFixedHeight === false && this._defaultHeight === 0) {
55
+ console.warn('Fixed height CellMeasurerCache should specify a :defaultHeight greater than 0. ' + 'Failing to do so will lead to unnecessary layout and poor performance.');
56
+ }
57
+ if (this._hasFixedWidth === false && this._defaultWidth === 0) {
58
+ console.warn('Fixed width CellMeasurerCache should specify a :defaultWidth greater than 0. ' + 'Failing to do so will lead to unnecessary layout and poor performance.');
59
+ }
60
+ }
61
+ }
62
+ _createClass(CellMeasurerCache, [{
63
+ key: "clear",
64
+ value: function clear(rowIndex) {
65
+ var columnIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
66
+ var key = this._keyMapper(rowIndex, columnIndex);
67
+ delete this._cellHeightCache[key];
68
+ delete this._cellWidthCache[key];
69
+ this._updateCachedColumnAndRowSizes(rowIndex, columnIndex);
70
+ }
71
+ }, {
72
+ key: "clearAll",
73
+ value: function clearAll() {
74
+ this._cellHeightCache = {};
75
+ this._cellWidthCache = {};
76
+ this._columnWidthCache = {};
77
+ this._rowHeightCache = {};
78
+ this._rowCount = 0;
79
+ this._columnCount = 0;
80
+ }
81
+ }, {
82
+ key: "defaultHeight",
83
+ get: function get() {
84
+ return this._defaultHeight;
85
+ }
86
+ }, {
87
+ key: "defaultWidth",
88
+ get: function get() {
89
+ return this._defaultWidth;
90
+ }
91
+ }, {
92
+ key: "hasFixedHeight",
93
+ value: function hasFixedHeight() {
94
+ return this._hasFixedHeight;
95
+ }
96
+ }, {
97
+ key: "hasFixedWidth",
98
+ value: function hasFixedWidth() {
99
+ return this._hasFixedWidth;
100
+ }
101
+ }, {
102
+ key: "getHeight",
103
+ value: function getHeight(rowIndex) {
104
+ var columnIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
105
+ if (this._hasFixedHeight) {
106
+ return this._defaultHeight;
107
+ } else {
108
+ var key = this._keyMapper(rowIndex, columnIndex);
109
+ return Object.prototype.hasOwnProperty.call(this._cellHeightCache, key) ? Math.max(this._minHeight, this._cellHeightCache[key]) : this._defaultHeight;
110
+ }
111
+ }
112
+ }, {
113
+ key: "getWidth",
114
+ value: function getWidth(rowIndex) {
115
+ var columnIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
116
+ if (this._hasFixedWidth) {
117
+ return this._defaultWidth;
118
+ } else {
119
+ var key = this._keyMapper(rowIndex, columnIndex);
120
+ return Object.prototype.hasOwnProperty.call(this._cellWidthCache, key) ? Math.max(this._minWidth, this._cellWidthCache[key]) : this._defaultWidth;
121
+ }
122
+ }
123
+ }, {
124
+ key: "has",
125
+ value: function has(rowIndex) {
126
+ var columnIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
127
+ var key = this._keyMapper(rowIndex, columnIndex);
128
+ return Object.prototype.hasOwnProperty.call(this._cellHeightCache, key);
129
+ }
130
+ }, {
131
+ key: "set",
132
+ value: function set(rowIndex, columnIndex, width, height) {
133
+ var key = this._keyMapper(rowIndex, columnIndex);
134
+ if (columnIndex >= this._columnCount) {
135
+ this._columnCount = columnIndex + 1;
136
+ }
137
+ if (rowIndex >= this._rowCount) {
138
+ this._rowCount = rowIndex + 1;
139
+ }
140
+
141
+ // Size is cached per cell so we don't have to re-measure if cells are re-ordered.
142
+ this._cellHeightCache[key] = height;
143
+ this._cellWidthCache[key] = width;
144
+ this._updateCachedColumnAndRowSizes(rowIndex, columnIndex);
145
+ }
146
+ }, {
147
+ key: "_updateCachedColumnAndRowSizes",
148
+ value: function _updateCachedColumnAndRowSizes(rowIndex, columnIndex) {
149
+ // :columnWidth and :rowHeight are derived based on all cells in a column/row.
150
+ // Pre-cache these derived values for faster lookup later.
151
+ // Reads are expected to occur more frequently than writes in this case.
152
+ // Only update non-fixed dimensions though to avoid doing unnecessary work.
153
+ if (!this._hasFixedWidth) {
154
+ var columnWidth = 0;
155
+ for (var i = 0; i < this._rowCount; i++) {
156
+ columnWidth = Math.max(columnWidth, this.getWidth(i, columnIndex));
157
+ }
158
+ var columnKey = this._keyMapper(0, columnIndex);
159
+ this._columnWidthCache[columnKey] = columnWidth;
160
+ }
161
+ if (!this._hasFixedHeight) {
162
+ var rowHeight = 0;
163
+ for (var _i = 0; _i < this._columnCount; _i++) {
164
+ rowHeight = Math.max(rowHeight, this.getHeight(rowIndex, _i));
165
+ }
166
+ var rowKey = this._keyMapper(rowIndex, 0);
167
+ this._rowHeightCache[rowKey] = rowHeight;
168
+ }
169
+ }
170
+ }]);
171
+ return CellMeasurerCache;
172
+ }();
173
+ export { CellMeasurerCache as default };
174
+ function defaultKeyMapper(rowIndex, columnIndex) {
175
+ return "".concat(rowIndex, "-").concat(columnIndex);
176
+ }
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ import type { CellMeasureCache } from './types.js';
3
+ type Children = (params: {
4
+ measure: () => void;
5
+ }) => React.ReactNode;
6
+ type Cell = {
7
+ columnIndex: number;
8
+ rowIndex: number;
9
+ };
10
+ type Props = {
11
+ cache: CellMeasureCache;
12
+ children: Children | React.ReactNode;
13
+ columnIndex?: number;
14
+ index?: number;
15
+ parent: {
16
+ invalidateCellSizeAfterRender?: (cell: Cell) => void;
17
+ recomputeGridSize?: (cell: Cell) => void;
18
+ };
19
+ rowIndex?: number;
20
+ };
21
+ /**
22
+ * Wraps a cell and measures its rendered content.
23
+ * Measurements are stored in a per-cell cache.
24
+ * Cached-content is not be re-measured.
25
+ */
26
+ export default class CellMeasurer extends React.PureComponent<Props> {
27
+ static __internalCellMeasurerFlag: boolean;
28
+ componentDidMount(): void;
29
+ componentDidUpdate(): void;
30
+ render(): React.ReactNode;
31
+ _getCellMeasurements(): {
32
+ height: number;
33
+ width: number;
34
+ };
35
+ _maybeMeasureCell(): void;
36
+ _measure: () => void;
37
+ }
38
+ export {};
39
+ //# sourceMappingURL=cell-measurer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-measurer.d.ts","sourceRoot":"","sources":["../../src/cell-measurer/cell-measurer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,KAAK,KAAK,CAAC,SAAS,CAAC;AAErE,KAAK,IAAI,GAAG;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACN,6BAA6B,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;QACrD,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;KAC1C,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC;IAClE,MAAM,CAAC,0BAA0B,UAAS;IAEjC,iBAAiB;IAIjB,kBAAkB;IAIlB,MAAM;IAQf,oBAAoB;;;;IAkDpB,iBAAiB;IAuBjB,QAAQ,aAuBN;CACH"}