Latest updates from IceHrmPro
This commit is contained in:
61
web/node_modules/rc-virtual-list/README.md
generated
vendored
Normal file
61
web/node_modules/rc-virtual-list/README.md
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
# rc-virtual-list
|
||||
|
||||
React Virtual List Component which worked with animation.
|
||||
|
||||
[![NPM version][npm-image]][npm-url] [![build status][circleci-image]][circleci-url] [![Test coverage][coveralls-image]][coveralls-url] [![node version][node-image]][node-url] [![npm download][download-image]][download-url]
|
||||
|
||||
[npm-image]: http://img.shields.io/npm/v/rc-virtual-list.svg?style=flat-square
|
||||
[npm-url]: http://npmjs.org/package/rc-virtual-list
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/react-component/virtual-list/master.svg?style=flat-square
|
||||
[circleci-url]: https://circleci.com/gh/react-component/virtual-list/tree/master
|
||||
[coveralls-image]: https://img.shields.io/codecov/c/github/react-component/virtual-list/master.svg?style=flat-square
|
||||
[coveralls-url]: https://codecov.io/gh/react-component/virtual-list
|
||||
[node-image]: https://img.shields.io/badge/node.js-%3E=_6.0-green.svg?style=flat-square
|
||||
[node-url]: http://nodejs.org/download/
|
||||
[download-image]: https://img.shields.io/npm/dm/rc-virtual-list.svg?style=flat-square
|
||||
[download-url]: https://npmjs.org/package/rc-virtual-list
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm start
|
||||
open http://localhost:9001/
|
||||
```
|
||||
|
||||
## Feature
|
||||
|
||||
- Support react.js
|
||||
- Support animation
|
||||
- Support IE11+
|
||||
|
||||
## Install
|
||||
|
||||
[](https://npmjs.org/package/rc-virtual-list)
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import List from 'rc-virtual-list';
|
||||
|
||||
<List data={[0, 1, 2]} height={200} itemHeight={30} itemKey="id">
|
||||
{index => <div>{index}</div>}
|
||||
</List>;
|
||||
```
|
||||
|
||||
# API
|
||||
|
||||
## List
|
||||
|
||||
| Prop | Description | Type | Default |
|
||||
| ---------- | ------------------------------------------------------- | ------------------------------------ | ------- |
|
||||
| children | Render props of item | (item, index, props) => ReactElement | - |
|
||||
| component | Customize List dom element | string \| Component | div |
|
||||
| data | Data list | Array | - |
|
||||
| disabled | Disable scroll check. Usually used on animation control | boolean | false |
|
||||
| height | List height | number | - |
|
||||
| itemHeight | Item minium height | number | - |
|
||||
| itemKey | Match key with item | string | - |
|
||||
|
||||
`children` provides additional `props` argument to support IE 11 scroll shaking.
|
||||
It will set `style` to `visibility: hidden` when measuring. You can ignore this if no requirement on IE.
|
||||
14
web/node_modules/rc-virtual-list/es/Filler.d.ts
generated
vendored
Normal file
14
web/node_modules/rc-virtual-list/es/Filler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as React from 'react';
|
||||
interface FillerProps {
|
||||
prefixCls?: string;
|
||||
/** Virtual filler height. Should be `count * itemMinHeight` */
|
||||
height: number;
|
||||
/** Set offset of visible items. Should be the top of start item position */
|
||||
offset?: number;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
/**
|
||||
* Fill component to provided the scroll content real height.
|
||||
*/
|
||||
declare const Filler: React.FC<FillerProps>;
|
||||
export default Filler;
|
||||
47
web/node_modules/rc-virtual-list/es/Filler.js
generated
vendored
Normal file
47
web/node_modules/rc-virtual-list/es/Filler.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
/**
|
||||
* Fill component to provided the scroll content real height.
|
||||
*/
|
||||
|
||||
var Filler = function Filler(_ref) {
|
||||
var height = _ref.height,
|
||||
offset = _ref.offset,
|
||||
children = _ref.children,
|
||||
prefixCls = _ref.prefixCls;
|
||||
var outerStyle = {};
|
||||
var innerStyle = {
|
||||
display: 'flex',
|
||||
flexDirection: 'column'
|
||||
};
|
||||
|
||||
if (offset !== undefined) {
|
||||
outerStyle = {
|
||||
height: height,
|
||||
position: 'relative',
|
||||
overflow: 'hidden'
|
||||
};
|
||||
innerStyle = _objectSpread({}, innerStyle, {
|
||||
transform: "translateY(".concat(offset, "px)"),
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0
|
||||
});
|
||||
}
|
||||
|
||||
return React.createElement("div", {
|
||||
style: outerStyle
|
||||
}, React.createElement("div", {
|
||||
style: innerStyle,
|
||||
className: classNames(_defineProperty({}, "".concat(prefixCls, "-holder-inner"), prefixCls))
|
||||
}, children));
|
||||
};
|
||||
|
||||
export default Filler;
|
||||
147
web/node_modules/rc-virtual-list/es/List.d.ts
generated
vendored
Normal file
147
web/node_modules/rc-virtual-list/es/List.d.ts
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
import * as React from 'react';
|
||||
import { Key } from './utils/itemUtil';
|
||||
declare type ScrollAlign = 'top' | 'bottom' | 'auto';
|
||||
export declare type RenderFunc<T> = (item: T, index: number, props: {
|
||||
style: React.CSSProperties;
|
||||
}) => React.ReactNode;
|
||||
export interface RelativeScroll {
|
||||
itemIndex: number;
|
||||
relativeTop: number;
|
||||
}
|
||||
export interface ScrollInfo {
|
||||
scrollTop: number;
|
||||
startItemTop: number;
|
||||
startIndex: number;
|
||||
}
|
||||
export interface ListProps<T> extends React.HTMLAttributes<any> {
|
||||
prefixCls?: string;
|
||||
children: RenderFunc<T>;
|
||||
data: T[];
|
||||
height?: number;
|
||||
itemHeight?: number;
|
||||
/** If not match virtual scroll condition, Set List still use height of container. */
|
||||
fullHeight?: boolean;
|
||||
itemKey: Key | ((item: T) => Key);
|
||||
component?: string | React.FC<any> | React.ComponentClass<any>;
|
||||
/** Disable scroll check. Usually used on animation control */
|
||||
disabled?: boolean;
|
||||
/** Set `false` will always use real scroll instead of virtual one */
|
||||
virtual?: boolean;
|
||||
/** When `disabled`, trigger if changed item not render. */
|
||||
onSkipRender?: () => void;
|
||||
onScroll?: React.UIEventHandler<HTMLElement>;
|
||||
}
|
||||
declare type Status = 'NONE' | 'MEASURE_START' | 'MEASURE_DONE' | 'SWITCH_TO_VIRTUAL' | 'SWITCH_TO_RAW';
|
||||
interface ListState<T> {
|
||||
status: Status;
|
||||
scrollTop: number | null;
|
||||
/** Located item index */
|
||||
itemIndex: number;
|
||||
/** Located item bind its height percentage with the `scrollTop` */
|
||||
itemOffsetPtg: number;
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
/**
|
||||
* Calculated by `scrollTop`.
|
||||
* We cache in the state since if `data` length change,
|
||||
* we need revert back to the located item index.
|
||||
*/
|
||||
startItemTop: number;
|
||||
/**
|
||||
* Tell if is using virtual scroll
|
||||
*/
|
||||
isVirtual: boolean;
|
||||
/**
|
||||
* Only used when turn virtual list to raw list
|
||||
*/
|
||||
cacheScroll?: RelativeScroll;
|
||||
/**
|
||||
* Cache `data.length` to use for `disabled` status.
|
||||
*/
|
||||
itemCount: number;
|
||||
}
|
||||
/**
|
||||
* We use class component here since typescript can not support generic in function component
|
||||
*
|
||||
* Virtual list display logic:
|
||||
* 1. scroll / initialize trigger measure
|
||||
* 2. Get location item of current `scrollTop`
|
||||
* 3. [Render] Render visible items
|
||||
* 4. Get all the visible items height
|
||||
* 5. [Render] Update top item `margin-top` to fit the position
|
||||
*
|
||||
* Algorithm:
|
||||
* We split scroll bar into equal slice. An item with whatever height occupy the same range slice.
|
||||
* When `scrollTop` change,
|
||||
* it will calculate the item percentage position and move item to the position.
|
||||
* Then calculate other item position base on the located item.
|
||||
*
|
||||
* Concept:
|
||||
*
|
||||
* # located item
|
||||
* The base position item which other items position calculate base on.
|
||||
*/
|
||||
declare class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
|
||||
static defaultProps: {
|
||||
itemHeight: number;
|
||||
data: any[];
|
||||
};
|
||||
listRef: React.RefObject<HTMLElement>;
|
||||
itemElements: {
|
||||
[index: number]: HTMLElement;
|
||||
};
|
||||
itemElementHeights: {
|
||||
[index: number]: number;
|
||||
};
|
||||
/**
|
||||
* Always point to the latest props if `disabled` is `false`
|
||||
*/
|
||||
cachedProps: Partial<ListProps<T>>;
|
||||
/**
|
||||
* Lock scroll process with `onScroll` event.
|
||||
* This is used for `data` length change and `scrollTop` restore
|
||||
*/
|
||||
lockScroll: boolean;
|
||||
constructor(props: ListProps<T>);
|
||||
static getDerivedStateFromProps(nextProps: ListProps<any>): {
|
||||
itemCount: number;
|
||||
};
|
||||
/**
|
||||
* Phase 1: Initial should sync with default scroll top
|
||||
*/
|
||||
componentDidMount(): void;
|
||||
/**
|
||||
* Phase 4: Record used item height
|
||||
* Phase 5: Trigger re-render to use correct position
|
||||
*/
|
||||
componentDidUpdate(): void;
|
||||
/**
|
||||
* Phase 2: Trigger render since we should re-calculate current position.
|
||||
*/
|
||||
onScroll: React.UIEventHandler<HTMLElement>;
|
||||
onRawScroll: React.UIEventHandler<HTMLElement>;
|
||||
triggerOnScroll: React.UIEventHandler<HTMLElement>;
|
||||
getIndexKey: (index: number, props?: Partial<ListProps<T>>) => string | number;
|
||||
getItemKey: (item: T, props?: Partial<ListProps<T>>) => string | number;
|
||||
/**
|
||||
* Collect current rendered dom element item heights
|
||||
*/
|
||||
collectItemHeights: (range?: {
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
}) => void;
|
||||
scrollTo: (arg0: number | {
|
||||
index: number;
|
||||
align?: ScrollAlign;
|
||||
} | {
|
||||
key: string | number;
|
||||
align?: ScrollAlign;
|
||||
}) => void;
|
||||
internalScrollTo(relativeScroll: RelativeScroll): void;
|
||||
/**
|
||||
* Phase 4: Render item and get all the visible items height
|
||||
*/
|
||||
renderChildren: (list: T[], startIndex: number, renderFunc: RenderFunc<T>) => React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)>) | (new (props: any) => React.Component<any, any, any>)>[];
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default List;
|
||||
786
web/node_modules/rc-virtual-list/es/List.js
generated
vendored
Normal file
786
web/node_modules/rc-virtual-list/es/List.js
generated
vendored
Normal file
@@ -0,0 +1,786 @@
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import raf from 'raf';
|
||||
import Filler from './Filler';
|
||||
import { getElementScrollPercentage, getScrollPercentage, getNodeHeight, getRangeIndex, getItemAbsoluteTop, GHOST_ITEM_KEY, getItemRelativeTop, getCompareItemRelativeTop, alignScrollTop, requireVirtual } from './utils/itemUtil';
|
||||
import { getIndexByStartLoc, findListDiffIndex } from './utils/algorithmUtil';
|
||||
var ScrollStyle = {
|
||||
overflowY: 'auto',
|
||||
overflowAnchor: 'none'
|
||||
};
|
||||
var ITEM_SCALE_RATE = 1;
|
||||
/**
|
||||
* We use class component here since typescript can not support generic in function component
|
||||
*
|
||||
* Virtual list display logic:
|
||||
* 1. scroll / initialize trigger measure
|
||||
* 2. Get location item of current `scrollTop`
|
||||
* 3. [Render] Render visible items
|
||||
* 4. Get all the visible items height
|
||||
* 5. [Render] Update top item `margin-top` to fit the position
|
||||
*
|
||||
* Algorithm:
|
||||
* We split scroll bar into equal slice. An item with whatever height occupy the same range slice.
|
||||
* When `scrollTop` change,
|
||||
* it will calculate the item percentage position and move item to the position.
|
||||
* Then calculate other item position base on the located item.
|
||||
*
|
||||
* Concept:
|
||||
*
|
||||
* # located item
|
||||
* The base position item which other items position calculate base on.
|
||||
*/
|
||||
|
||||
var List = /*#__PURE__*/function (_React$Component) {
|
||||
_inherits(List, _React$Component);
|
||||
|
||||
function List(props) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, List);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(List).call(this, props));
|
||||
_this.listRef = React.createRef();
|
||||
_this.itemElements = {};
|
||||
_this.itemElementHeights = {};
|
||||
/**
|
||||
* Lock scroll process with `onScroll` event.
|
||||
* This is used for `data` length change and `scrollTop` restore
|
||||
*/
|
||||
|
||||
_this.lockScroll = false;
|
||||
/**
|
||||
* Phase 2: Trigger render since we should re-calculate current position.
|
||||
*/
|
||||
|
||||
_this.onScroll = function (event) {
|
||||
var _this$props = _this.props,
|
||||
data = _this$props.data,
|
||||
height = _this$props.height,
|
||||
itemHeight = _this$props.itemHeight,
|
||||
disabled = _this$props.disabled;
|
||||
var _this$listRef$current = _this.listRef.current,
|
||||
originScrollTop = _this$listRef$current.scrollTop,
|
||||
clientHeight = _this$listRef$current.clientHeight,
|
||||
scrollHeight = _this$listRef$current.scrollHeight;
|
||||
var scrollTop = alignScrollTop(originScrollTop, scrollHeight - clientHeight); // Skip if `scrollTop` not change to avoid shake
|
||||
|
||||
if (scrollTop === _this.state.scrollTop || _this.lockScroll || disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var scrollPtg = getElementScrollPercentage(_this.listRef.current);
|
||||
var visibleCount = Math.ceil(height / itemHeight);
|
||||
|
||||
var _getRangeIndex = getRangeIndex(scrollPtg, data.length, visibleCount),
|
||||
itemIndex = _getRangeIndex.itemIndex,
|
||||
itemOffsetPtg = _getRangeIndex.itemOffsetPtg,
|
||||
startIndex = _getRangeIndex.startIndex,
|
||||
endIndex = _getRangeIndex.endIndex;
|
||||
|
||||
_this.setState({
|
||||
status: 'MEASURE_START',
|
||||
scrollTop: scrollTop,
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
startIndex: startIndex,
|
||||
endIndex: endIndex
|
||||
});
|
||||
|
||||
_this.triggerOnScroll(event);
|
||||
};
|
||||
|
||||
_this.onRawScroll = function (event) {
|
||||
var scrollTop = _this.listRef.current.scrollTop;
|
||||
|
||||
_this.setState({
|
||||
scrollTop: scrollTop
|
||||
});
|
||||
|
||||
_this.triggerOnScroll(event);
|
||||
};
|
||||
|
||||
_this.triggerOnScroll = function (event) {
|
||||
var onScroll = _this.props.onScroll;
|
||||
|
||||
if (onScroll && event) {
|
||||
onScroll(event);
|
||||
}
|
||||
};
|
||||
|
||||
_this.getIndexKey = function (index, props) {
|
||||
var mergedProps = props || _this.props;
|
||||
var _mergedProps$data = mergedProps.data,
|
||||
data = _mergedProps$data === void 0 ? [] : _mergedProps$data; // Return ghost key as latest index item
|
||||
|
||||
if (index === data.length) {
|
||||
return GHOST_ITEM_KEY;
|
||||
}
|
||||
|
||||
var item = data[index];
|
||||
|
||||
if (!item) {
|
||||
/* istanbul ignore next */
|
||||
console.error('Not find index item. Please report this since it is a bug.');
|
||||
}
|
||||
|
||||
return _this.getItemKey(item, mergedProps);
|
||||
};
|
||||
|
||||
_this.getItemKey = function (item, props) {
|
||||
var _ref = props || _this.props,
|
||||
itemKey = _ref.itemKey;
|
||||
|
||||
return typeof itemKey === 'function' ? itemKey(item) : item[itemKey];
|
||||
};
|
||||
/**
|
||||
* Collect current rendered dom element item heights
|
||||
*/
|
||||
|
||||
|
||||
_this.collectItemHeights = function (range) {
|
||||
var _ref2 = range || _this.state,
|
||||
startIndex = _ref2.startIndex,
|
||||
endIndex = _ref2.endIndex;
|
||||
|
||||
var data = _this.props.data; // Record here since measure item height will get warning in `render`
|
||||
|
||||
for (var index = startIndex; index <= endIndex; index += 1) {
|
||||
var item = data[index]; // Only collect exist item height
|
||||
|
||||
if (item) {
|
||||
var eleKey = _this.getItemKey(item);
|
||||
|
||||
_this.itemElementHeights[eleKey] = getNodeHeight(_this.itemElements[eleKey]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_this.scrollTo = function (arg0) {
|
||||
raf(function () {
|
||||
// Number top
|
||||
if (_typeof(arg0) === 'object') {
|
||||
var isVirtual = _this.state.isVirtual;
|
||||
var _this$props2 = _this.props,
|
||||
height = _this$props2.height,
|
||||
itemHeight = _this$props2.itemHeight,
|
||||
data = _this$props2.data;
|
||||
var _arg0$align = arg0.align,
|
||||
align = _arg0$align === void 0 ? 'auto' : _arg0$align;
|
||||
var index = 0;
|
||||
|
||||
if ('index' in arg0) {
|
||||
index = arg0.index;
|
||||
} else if ('key' in arg0) {
|
||||
var key = arg0.key;
|
||||
index = data.findIndex(function (item) {
|
||||
return _this.getItemKey(item) === key;
|
||||
});
|
||||
}
|
||||
|
||||
var visibleCount = Math.ceil(height / itemHeight);
|
||||
var item = data[index];
|
||||
|
||||
if (item) {
|
||||
var clientHeight = _this.listRef.current.clientHeight;
|
||||
|
||||
if (isVirtual) {
|
||||
// Calculate related data
|
||||
var _this$state = _this.state,
|
||||
itemIndex = _this$state.itemIndex,
|
||||
itemOffsetPtg = _this$state.itemOffsetPtg;
|
||||
var scrollTop = _this.listRef.current.scrollTop;
|
||||
var scrollPtg = getElementScrollPercentage(_this.listRef.current);
|
||||
var relativeLocatedItemTop = getItemRelativeTop({
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
itemElementHeights: _this.itemElementHeights,
|
||||
scrollPtg: scrollPtg,
|
||||
clientHeight: clientHeight,
|
||||
getItemKey: _this.getIndexKey
|
||||
}); // We will force render related items to collect height for re-location
|
||||
|
||||
_this.setState({
|
||||
startIndex: Math.max(0, index - visibleCount),
|
||||
endIndex: Math.min(data.length - 1, index + visibleCount)
|
||||
}, function () {
|
||||
_this.collectItemHeights(); // Calculate related top
|
||||
|
||||
|
||||
var relativeTop;
|
||||
var mergedAlgin = align;
|
||||
|
||||
if (align === 'auto') {
|
||||
var shouldChange = true; // Check if exist in the visible range
|
||||
|
||||
if (Math.abs(itemIndex - index) < visibleCount) {
|
||||
var itemTop = relativeLocatedItemTop;
|
||||
|
||||
if (index < itemIndex) {
|
||||
for (var i = index; i < itemIndex; i += 1) {
|
||||
var eleKey = _this.getIndexKey(i);
|
||||
|
||||
itemTop -= _this.itemElementHeights[eleKey] || 0;
|
||||
}
|
||||
} else {
|
||||
for (var _i = itemIndex; _i <= index; _i += 1) {
|
||||
var _eleKey = _this.getIndexKey(_i);
|
||||
|
||||
itemTop += _this.itemElementHeights[_eleKey] || 0;
|
||||
}
|
||||
}
|
||||
|
||||
shouldChange = itemTop <= 0 || itemTop >= clientHeight;
|
||||
}
|
||||
|
||||
if (shouldChange) {
|
||||
// Out of range will fall back to position align
|
||||
mergedAlgin = index < itemIndex ? 'top' : 'bottom';
|
||||
} else {
|
||||
var _getRangeIndex2 = getRangeIndex(scrollPtg, data.length, visibleCount),
|
||||
nextIndex = _getRangeIndex2.itemIndex,
|
||||
newOffsetPtg = _getRangeIndex2.itemOffsetPtg,
|
||||
startIndex = _getRangeIndex2.startIndex,
|
||||
endIndex = _getRangeIndex2.endIndex;
|
||||
|
||||
_this.setState({
|
||||
scrollTop: scrollTop,
|
||||
itemIndex: nextIndex,
|
||||
itemOffsetPtg: newOffsetPtg,
|
||||
startIndex: startIndex,
|
||||
endIndex: endIndex
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
} // Align with position should make scroll happen
|
||||
|
||||
|
||||
if (mergedAlgin === 'top') {
|
||||
relativeTop = 0;
|
||||
} else if (mergedAlgin === 'bottom') {
|
||||
var _eleKey2 = _this.getItemKey(item);
|
||||
|
||||
relativeTop = clientHeight - _this.itemElementHeights[_eleKey2] || 0;
|
||||
}
|
||||
|
||||
_this.internalScrollTo({
|
||||
itemIndex: index,
|
||||
relativeTop: relativeTop
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Raw list without virtual scroll set position directly
|
||||
_this.collectItemHeights({
|
||||
startIndex: 0,
|
||||
endIndex: data.length - 1
|
||||
});
|
||||
|
||||
var mergedAlgin = align; // Collection index item position
|
||||
|
||||
var indexItemHeight = _this.itemElementHeights[_this.getIndexKey(index)];
|
||||
|
||||
var itemTop = 0;
|
||||
|
||||
for (var i = 0; i < index; i += 1) {
|
||||
var eleKey = _this.getIndexKey(i);
|
||||
|
||||
itemTop += _this.itemElementHeights[eleKey] || 0;
|
||||
}
|
||||
|
||||
var itemBottom = itemTop + indexItemHeight;
|
||||
|
||||
if (mergedAlgin === 'auto') {
|
||||
if (itemTop < _this.listRef.current.scrollTop) {
|
||||
mergedAlgin = 'top';
|
||||
} else if (itemBottom > _this.listRef.current.scrollTop + clientHeight) {
|
||||
mergedAlgin = 'bottom';
|
||||
}
|
||||
}
|
||||
|
||||
if (mergedAlgin === 'top') {
|
||||
_this.listRef.current.scrollTop = itemTop;
|
||||
} else if (mergedAlgin === 'bottom') {
|
||||
_this.listRef.current.scrollTop = itemTop - (clientHeight - indexItemHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_this.listRef.current.scrollTop = arg0;
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Phase 4: Render item and get all the visible items height
|
||||
*/
|
||||
|
||||
|
||||
_this.renderChildren = function (list, startIndex, renderFunc) {
|
||||
var status = _this.state.status; // We should measure rendered item height
|
||||
|
||||
return list.map(function (item, index) {
|
||||
var eleIndex = startIndex + index;
|
||||
var node = renderFunc(item, eleIndex, {
|
||||
style: status === 'MEASURE_START' ? {
|
||||
visibility: 'hidden'
|
||||
} : {}
|
||||
});
|
||||
|
||||
var eleKey = _this.getIndexKey(eleIndex); // Pass `key` and `ref` for internal measure
|
||||
|
||||
|
||||
return React.cloneElement(node, {
|
||||
key: eleKey,
|
||||
ref: function ref(ele) {
|
||||
_this.itemElements[eleKey] = ele;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
_this.cachedProps = props;
|
||||
_this.state = {
|
||||
status: 'NONE',
|
||||
scrollTop: null,
|
||||
itemIndex: 0,
|
||||
itemOffsetPtg: 0,
|
||||
startIndex: 0,
|
||||
endIndex: 0,
|
||||
startItemTop: 0,
|
||||
isVirtual: requireVirtual(props.height, props.itemHeight, props.data.length, props.virtual),
|
||||
itemCount: props.data.length
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(List, [{
|
||||
key: "componentDidMount",
|
||||
|
||||
/**
|
||||
* Phase 1: Initial should sync with default scroll top
|
||||
*/
|
||||
value: function componentDidMount() {
|
||||
if (this.listRef.current) {
|
||||
this.listRef.current.scrollTop = 0;
|
||||
this.onScroll(null);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phase 4: Record used item height
|
||||
* Phase 5: Trigger re-render to use correct position
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "componentDidUpdate",
|
||||
value: function componentDidUpdate() {
|
||||
var _this2 = this;
|
||||
|
||||
var status = this.state.status;
|
||||
var _this$props3 = this.props,
|
||||
data = _this$props3.data,
|
||||
height = _this$props3.height,
|
||||
itemHeight = _this$props3.itemHeight,
|
||||
disabled = _this$props3.disabled,
|
||||
onSkipRender = _this$props3.onSkipRender,
|
||||
virtual = _this$props3.virtual;
|
||||
var prevData = this.cachedProps.data || [];
|
||||
var changedItemIndex = null;
|
||||
|
||||
if (prevData.length !== data.length) {
|
||||
var diff = findListDiffIndex(prevData, data, this.getItemKey);
|
||||
changedItemIndex = diff ? diff.index : null;
|
||||
}
|
||||
|
||||
if (disabled) {
|
||||
// Should trigger `onSkipRender` to tell that diff component is not render in the list
|
||||
if (data.length > prevData.length) {
|
||||
var _this$state2 = this.state,
|
||||
startIndex = _this$state2.startIndex,
|
||||
endIndex = _this$state2.endIndex;
|
||||
|
||||
if (onSkipRender && (changedItemIndex === null || changedItemIndex < startIndex || endIndex < changedItemIndex)) {
|
||||
onSkipRender();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var isVirtual = requireVirtual(height, itemHeight, data.length, virtual);
|
||||
var nextStatus = status;
|
||||
|
||||
if (this.state.isVirtual !== isVirtual) {
|
||||
nextStatus = isVirtual ? 'SWITCH_TO_VIRTUAL' : 'SWITCH_TO_RAW';
|
||||
this.setState({
|
||||
isVirtual: isVirtual,
|
||||
status: nextStatus
|
||||
});
|
||||
/**
|
||||
* We will wait a tick to let list turn to virtual list.
|
||||
* And then use virtual list sync logic to adjust the scroll.
|
||||
*/
|
||||
|
||||
if (nextStatus === 'SWITCH_TO_VIRTUAL') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (status === 'MEASURE_START') {
|
||||
var _this$state3 = this.state,
|
||||
_startIndex = _this$state3.startIndex,
|
||||
itemIndex = _this$state3.itemIndex,
|
||||
itemOffsetPtg = _this$state3.itemOffsetPtg;
|
||||
var scrollTop = this.listRef.current.scrollTop; // Record here since measure item height will get warning in `render`
|
||||
|
||||
this.collectItemHeights(); // Calculate top visible item top offset
|
||||
|
||||
var locatedItemTop = getItemAbsoluteTop({
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
itemElementHeights: this.itemElementHeights,
|
||||
scrollTop: scrollTop,
|
||||
scrollPtg: getElementScrollPercentage(this.listRef.current),
|
||||
clientHeight: this.listRef.current.clientHeight,
|
||||
getItemKey: this.getIndexKey
|
||||
});
|
||||
var startItemTop = locatedItemTop;
|
||||
|
||||
for (var index = itemIndex - 1; index >= _startIndex; index -= 1) {
|
||||
startItemTop -= this.itemElementHeights[this.getIndexKey(index)] || 0;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
status: 'MEASURE_DONE',
|
||||
startItemTop: startItemTop
|
||||
});
|
||||
}
|
||||
|
||||
if (status === 'SWITCH_TO_RAW') {
|
||||
/**
|
||||
* After virtual list back to raw list,
|
||||
* we update the `scrollTop` to real top instead of percentage top.
|
||||
*/
|
||||
var _this$state$cacheScro = this.state.cacheScroll,
|
||||
_itemIndex = _this$state$cacheScro.itemIndex,
|
||||
relativeTop = _this$state$cacheScro.relativeTop;
|
||||
var rawTop = relativeTop;
|
||||
|
||||
for (var _index = 0; _index < _itemIndex; _index += 1) {
|
||||
rawTop -= this.itemElementHeights[this.getIndexKey(_index)] || 0;
|
||||
}
|
||||
|
||||
this.lockScroll = true;
|
||||
this.listRef.current.scrollTop = -rawTop;
|
||||
this.setState({
|
||||
status: 'MEASURE_DONE',
|
||||
itemIndex: 0
|
||||
});
|
||||
requestAnimationFrame(function () {
|
||||
requestAnimationFrame(function () {
|
||||
_this2.lockScroll = false;
|
||||
});
|
||||
});
|
||||
} else if (prevData.length !== data.length && changedItemIndex !== null && height) {
|
||||
/**
|
||||
* Re-calculate the item position since `data` length changed.
|
||||
* [IMPORTANT] We use relative position calculate here.
|
||||
*/
|
||||
var originItemIndex = this.state.itemIndex;
|
||||
var _this$state4 = this.state,
|
||||
originItemOffsetPtg = _this$state4.itemOffsetPtg,
|
||||
originStartIndex = _this$state4.startIndex,
|
||||
originEndIndex = _this$state4.endIndex,
|
||||
originScrollTop = _this$state4.scrollTop; // 1. Refresh item heights
|
||||
|
||||
this.collectItemHeights(); // 1. Get origin located item top
|
||||
|
||||
var originLocatedItemRelativeTop;
|
||||
|
||||
if (this.state.status === 'SWITCH_TO_VIRTUAL') {
|
||||
originItemIndex = 0;
|
||||
originLocatedItemRelativeTop = -this.state.scrollTop;
|
||||
} else {
|
||||
originLocatedItemRelativeTop = getItemRelativeTop({
|
||||
itemIndex: originItemIndex,
|
||||
itemOffsetPtg: originItemOffsetPtg,
|
||||
itemElementHeights: this.itemElementHeights,
|
||||
scrollPtg: getScrollPercentage({
|
||||
scrollTop: originScrollTop,
|
||||
scrollHeight: prevData.length * itemHeight,
|
||||
clientHeight: this.listRef.current.clientHeight
|
||||
}),
|
||||
clientHeight: this.listRef.current.clientHeight,
|
||||
getItemKey: function getItemKey(index) {
|
||||
return _this2.getIndexKey(index, _this2.cachedProps);
|
||||
}
|
||||
});
|
||||
} // 2. Find the compare item
|
||||
|
||||
|
||||
var originCompareItemIndex = changedItemIndex - 1; // Use next one since there are not more item before removed
|
||||
|
||||
if (originCompareItemIndex < 0) {
|
||||
originCompareItemIndex = 0;
|
||||
} // 3. Find the compare item top
|
||||
|
||||
|
||||
var originCompareItemTop = getCompareItemRelativeTop({
|
||||
locatedItemRelativeTop: originLocatedItemRelativeTop,
|
||||
locatedItemIndex: originItemIndex,
|
||||
compareItemIndex: originCompareItemIndex,
|
||||
startIndex: originStartIndex,
|
||||
endIndex: originEndIndex,
|
||||
getItemKey: function getItemKey(index) {
|
||||
return _this2.getIndexKey(index, _this2.cachedProps);
|
||||
},
|
||||
itemElementHeights: this.itemElementHeights
|
||||
});
|
||||
|
||||
if (nextStatus === 'SWITCH_TO_RAW') {
|
||||
/**
|
||||
* We will record current measure relative item top and apply in raw list after list turned
|
||||
*/
|
||||
this.setState({
|
||||
cacheScroll: {
|
||||
itemIndex: originCompareItemIndex,
|
||||
relativeTop: originCompareItemTop
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.internalScrollTo({
|
||||
itemIndex: originCompareItemIndex,
|
||||
relativeTop: originCompareItemTop
|
||||
});
|
||||
}
|
||||
} else if (nextStatus === 'SWITCH_TO_RAW') {
|
||||
// This is only trigger when height changes that all items can show in raw
|
||||
// Let's reset back to top
|
||||
this.setState({
|
||||
cacheScroll: {
|
||||
itemIndex: 0,
|
||||
relativeTop: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.cachedProps = this.props;
|
||||
}
|
||||
}, {
|
||||
key: "internalScrollTo",
|
||||
value: function internalScrollTo(relativeScroll) {
|
||||
var _this3 = this;
|
||||
|
||||
var compareItemIndex = relativeScroll.itemIndex,
|
||||
compareItemRelativeTop = relativeScroll.relativeTop;
|
||||
var originScrollTop = this.state.scrollTop;
|
||||
var _this$props4 = this.props,
|
||||
data = _this$props4.data,
|
||||
itemHeight = _this$props4.itemHeight,
|
||||
height = _this$props4.height; // 1. Find the best match compare item top
|
||||
|
||||
var bestSimilarity = Number.MAX_VALUE;
|
||||
var bestScrollTop = null;
|
||||
var bestItemIndex = null;
|
||||
var bestItemOffsetPtg = null;
|
||||
var bestStartIndex = null;
|
||||
var bestEndIndex = null;
|
||||
var missSimilarity = 0;
|
||||
var scrollHeight = data.length * itemHeight;
|
||||
var clientHeight = this.listRef.current.clientHeight;
|
||||
var maxScrollTop = scrollHeight - clientHeight;
|
||||
|
||||
for (var i = 0; i < maxScrollTop; i += 1) {
|
||||
var scrollTop = getIndexByStartLoc(0, maxScrollTop, originScrollTop, i);
|
||||
var scrollPtg = getScrollPercentage({
|
||||
scrollTop: scrollTop,
|
||||
scrollHeight: scrollHeight,
|
||||
clientHeight: clientHeight
|
||||
});
|
||||
var visibleCount = Math.ceil(height / itemHeight);
|
||||
|
||||
var _getRangeIndex3 = getRangeIndex(scrollPtg, data.length, visibleCount),
|
||||
itemIndex = _getRangeIndex3.itemIndex,
|
||||
itemOffsetPtg = _getRangeIndex3.itemOffsetPtg,
|
||||
startIndex = _getRangeIndex3.startIndex,
|
||||
endIndex = _getRangeIndex3.endIndex; // No need to check if compare item out of the index to save performance
|
||||
|
||||
|
||||
if (startIndex <= compareItemIndex && compareItemIndex <= endIndex) {
|
||||
// 1.1 Get measure located item relative top
|
||||
var locatedItemRelativeTop = getItemRelativeTop({
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
itemElementHeights: this.itemElementHeights,
|
||||
scrollPtg: scrollPtg,
|
||||
clientHeight: clientHeight,
|
||||
getItemKey: this.getIndexKey
|
||||
});
|
||||
var compareItemTop = getCompareItemRelativeTop({
|
||||
locatedItemRelativeTop: locatedItemRelativeTop,
|
||||
locatedItemIndex: itemIndex,
|
||||
compareItemIndex: compareItemIndex,
|
||||
startIndex: startIndex,
|
||||
endIndex: endIndex,
|
||||
getItemKey: this.getIndexKey,
|
||||
itemElementHeights: this.itemElementHeights
|
||||
}); // 1.2 Find best match compare item top
|
||||
|
||||
var similarity = Math.abs(compareItemTop - compareItemRelativeTop);
|
||||
|
||||
if (similarity < bestSimilarity) {
|
||||
bestSimilarity = similarity;
|
||||
bestScrollTop = scrollTop;
|
||||
bestItemIndex = itemIndex;
|
||||
bestItemOffsetPtg = itemOffsetPtg;
|
||||
bestStartIndex = startIndex;
|
||||
bestEndIndex = endIndex;
|
||||
missSimilarity = 0;
|
||||
} else {
|
||||
missSimilarity += 1;
|
||||
}
|
||||
} // If keeping 10 times not match similarity,
|
||||
// check more scrollTop is meaningless.
|
||||
// Here boundary is set to 10.
|
||||
|
||||
|
||||
if (missSimilarity > 10) {
|
||||
break;
|
||||
}
|
||||
} // 2. Re-scroll if has best scroll match
|
||||
|
||||
|
||||
if (bestScrollTop !== null) {
|
||||
this.lockScroll = true;
|
||||
this.listRef.current.scrollTop = bestScrollTop;
|
||||
this.setState({
|
||||
status: 'MEASURE_START',
|
||||
scrollTop: bestScrollTop,
|
||||
itemIndex: bestItemIndex,
|
||||
itemOffsetPtg: bestItemOffsetPtg,
|
||||
startIndex: bestStartIndex,
|
||||
endIndex: bestEndIndex
|
||||
});
|
||||
requestAnimationFrame(function () {
|
||||
requestAnimationFrame(function () {
|
||||
_this3.lockScroll = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "render",
|
||||
value: function render() {
|
||||
var _this$state5 = this.state,
|
||||
isVirtual = _this$state5.isVirtual,
|
||||
itemCount = _this$state5.itemCount;
|
||||
|
||||
var _this$props5 = this.props,
|
||||
prefixCls = _this$props5.prefixCls,
|
||||
style = _this$props5.style,
|
||||
className = _this$props5.className,
|
||||
_this$props5$componen = _this$props5.component,
|
||||
Component = _this$props5$componen === void 0 ? 'div' : _this$props5$componen,
|
||||
height = _this$props5.height,
|
||||
itemHeight = _this$props5.itemHeight,
|
||||
_this$props5$fullHeig = _this$props5.fullHeight,
|
||||
fullHeight = _this$props5$fullHeig === void 0 ? true : _this$props5$fullHeig,
|
||||
data = _this$props5.data,
|
||||
children = _this$props5.children,
|
||||
itemKey = _this$props5.itemKey,
|
||||
onSkipRender = _this$props5.onSkipRender,
|
||||
disabled = _this$props5.disabled,
|
||||
virtual = _this$props5.virtual,
|
||||
restProps = _objectWithoutProperties(_this$props5, ["prefixCls", "style", "className", "component", "height", "itemHeight", "fullHeight", "data", "children", "itemKey", "onSkipRender", "disabled", "virtual"]);
|
||||
|
||||
var mergedClassName = classNames(prefixCls, className); // Render pure list if not set height or height is enough for all items
|
||||
|
||||
if (!isVirtual) {
|
||||
/**
|
||||
* Virtual list switch is works on component updated.
|
||||
* We should double check here if need cut the content.
|
||||
*/
|
||||
var shouldVirtual = requireVirtual(height, itemHeight, data.length, virtual);
|
||||
return React.createElement(Component, Object.assign({
|
||||
style: height ? _objectSpread({}, style, _defineProperty({}, fullHeight ? 'height' : 'maxHeight', height), ScrollStyle) : style,
|
||||
className: mergedClassName
|
||||
}, restProps, {
|
||||
onScroll: this.onRawScroll,
|
||||
ref: this.listRef
|
||||
}), React.createElement(Filler, {
|
||||
prefixCls: prefixCls,
|
||||
height: height
|
||||
}, this.renderChildren(shouldVirtual ? data.slice(0, Math.ceil(height / itemHeight)) : data, 0, children)));
|
||||
} // Use virtual list
|
||||
|
||||
|
||||
var mergedStyle = _objectSpread({}, style, {
|
||||
height: height
|
||||
}, ScrollStyle);
|
||||
|
||||
var _this$state6 = this.state,
|
||||
status = _this$state6.status,
|
||||
startIndex = _this$state6.startIndex,
|
||||
endIndex = _this$state6.endIndex,
|
||||
startItemTop = _this$state6.startItemTop;
|
||||
var contentHeight = itemCount * itemHeight * ITEM_SCALE_RATE;
|
||||
return React.createElement(Component, Object.assign({
|
||||
style: mergedStyle,
|
||||
className: mergedClassName
|
||||
}, restProps, {
|
||||
onScroll: this.onScroll,
|
||||
ref: this.listRef
|
||||
}), React.createElement(Filler, {
|
||||
prefixCls: prefixCls,
|
||||
height: contentHeight,
|
||||
offset: status === 'MEASURE_DONE' ? startItemTop : 0
|
||||
}, this.renderChildren(data.slice(startIndex, endIndex + 1), startIndex, children)));
|
||||
}
|
||||
}], [{
|
||||
key: "getDerivedStateFromProps",
|
||||
value: function getDerivedStateFromProps(nextProps) {
|
||||
if (!nextProps.disabled) {
|
||||
return {
|
||||
itemCount: nextProps.data.length
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}]);
|
||||
|
||||
return List;
|
||||
}(React.Component);
|
||||
|
||||
List.defaultProps = {
|
||||
itemHeight: 15,
|
||||
data: []
|
||||
};
|
||||
export default List;
|
||||
2
web/node_modules/rc-virtual-list/es/index.d.ts
generated
vendored
Normal file
2
web/node_modules/rc-virtual-list/es/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import List from './List';
|
||||
export default List;
|
||||
2
web/node_modules/rc-virtual-list/es/index.js
generated
vendored
Normal file
2
web/node_modules/rc-virtual-list/es/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import List from './List';
|
||||
export default List;
|
||||
8
web/node_modules/rc-virtual-list/es/mock.d.ts
generated
vendored
Normal file
8
web/node_modules/rc-virtual-list/es/mock.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference types="react" />
|
||||
import OriginList from './List';
|
||||
declare class List<T> extends OriginList<T> {
|
||||
componentDidUpdate(): void;
|
||||
scrollTo: () => void;
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default List;
|
||||
89
web/node_modules/rc-virtual-list/es/mock.js
generated
vendored
Normal file
89
web/node_modules/rc-virtual-list/es/mock.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import OriginList from './List';
|
||||
import Filler from './Filler';
|
||||
|
||||
var List = /*#__PURE__*/function (_OriginList) {
|
||||
_inherits(List, _OriginList);
|
||||
|
||||
function List() {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, List);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(List).apply(this, arguments));
|
||||
|
||||
_this.scrollTo = function () {// Do nothing sine this is a mock!
|
||||
};
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(List, [{
|
||||
key: "componentDidUpdate",
|
||||
value: function componentDidUpdate() {// Do nothing since this is a mock!
|
||||
}
|
||||
}, {
|
||||
key: "render",
|
||||
value: function render() {
|
||||
var _this$props = this.props,
|
||||
prefixCls = _this$props.prefixCls,
|
||||
style = _this$props.style,
|
||||
className = _this$props.className,
|
||||
_this$props$component = _this$props.component,
|
||||
Component = _this$props$component === void 0 ? 'div' : _this$props$component,
|
||||
fullHeight = _this$props.fullHeight,
|
||||
height = _this$props.height,
|
||||
itemHeight = _this$props.itemHeight,
|
||||
virtual = _this$props.virtual,
|
||||
data = _this$props.data,
|
||||
children = _this$props.children,
|
||||
itemKey = _this$props.itemKey,
|
||||
onSkipRender = _this$props.onSkipRender,
|
||||
restProps = _objectWithoutProperties(_this$props, ["prefixCls", "style", "className", "component", "fullHeight", "height", "itemHeight", "virtual", "data", "children", "itemKey", "onSkipRender"]);
|
||||
|
||||
var mergedClassName = classNames(prefixCls, className);
|
||||
return React.createElement(Component, Object.assign({
|
||||
style: _objectSpread({}, style, {
|
||||
height: height
|
||||
}),
|
||||
className: mergedClassName
|
||||
}, restProps), React.createElement(Filler, {
|
||||
prefixCls: prefixCls,
|
||||
height: height
|
||||
}, this.renderChildren(data, 0, children)));
|
||||
}
|
||||
}]);
|
||||
|
||||
return List;
|
||||
}(OriginList);
|
||||
|
||||
export default List;
|
||||
23
web/node_modules/rc-virtual-list/es/utils/algorithmUtil.d.ts
generated
vendored
Normal file
23
web/node_modules/rc-virtual-list/es/utils/algorithmUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Key } from './itemUtil';
|
||||
/**
|
||||
* Get index with specific start index one by one. e.g.
|
||||
* min: 3, max: 9, start: 6
|
||||
*
|
||||
* Return index is:
|
||||
* [0]: 6
|
||||
* [1]: 7
|
||||
* [2]: 5
|
||||
* [3]: 8
|
||||
* [4]: 4
|
||||
* [5]: 9
|
||||
* [6]: 3
|
||||
*/
|
||||
export declare function getIndexByStartLoc(min: number, max: number, start: number, index: number): number;
|
||||
/**
|
||||
* We assume that 2 list has only 1 item diff and others keeping the order.
|
||||
* So we can use dichotomy algorithm to find changed one.
|
||||
*/
|
||||
export declare function findListDiffIndex<T>(originList: T[], targetList: T[], getKey: (item: T) => Key): {
|
||||
index: number;
|
||||
multiple: boolean;
|
||||
} | null;
|
||||
90
web/node_modules/rc-virtual-list/es/utils/algorithmUtil.js
generated
vendored
Normal file
90
web/node_modules/rc-virtual-list/es/utils/algorithmUtil.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Get index with specific start index one by one. e.g.
|
||||
* min: 3, max: 9, start: 6
|
||||
*
|
||||
* Return index is:
|
||||
* [0]: 6
|
||||
* [1]: 7
|
||||
* [2]: 5
|
||||
* [3]: 8
|
||||
* [4]: 4
|
||||
* [5]: 9
|
||||
* [6]: 3
|
||||
*/
|
||||
export function getIndexByStartLoc(min, max, start, index) {
|
||||
var beforeCount = start - min;
|
||||
var afterCount = max - start;
|
||||
var balanceCount = Math.min(beforeCount, afterCount) * 2; // Balance
|
||||
|
||||
if (index <= balanceCount) {
|
||||
var stepIndex = Math.floor(index / 2);
|
||||
|
||||
if (index % 2) {
|
||||
return start + stepIndex + 1;
|
||||
}
|
||||
|
||||
return start - stepIndex;
|
||||
} // One is out of range
|
||||
|
||||
|
||||
if (beforeCount > afterCount) {
|
||||
return start - (index - afterCount);
|
||||
}
|
||||
|
||||
return start + (index - beforeCount);
|
||||
}
|
||||
/**
|
||||
* We assume that 2 list has only 1 item diff and others keeping the order.
|
||||
* So we can use dichotomy algorithm to find changed one.
|
||||
*/
|
||||
|
||||
export function findListDiffIndex(originList, targetList, getKey) {
|
||||
var originLen = originList.length;
|
||||
var targetLen = targetList.length;
|
||||
var shortList;
|
||||
var longList;
|
||||
|
||||
if (originLen === 0 && targetLen === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (originLen < targetLen) {
|
||||
shortList = originList;
|
||||
longList = targetList;
|
||||
} else {
|
||||
shortList = targetList;
|
||||
longList = originList;
|
||||
}
|
||||
|
||||
var notExistKey = {
|
||||
__EMPTY_ITEM__: true
|
||||
};
|
||||
|
||||
function getItemKey(item) {
|
||||
if (item !== undefined) {
|
||||
return getKey(item);
|
||||
}
|
||||
|
||||
return notExistKey;
|
||||
} // Loop to find diff one
|
||||
|
||||
|
||||
var diffIndex = null;
|
||||
var multiple = Math.abs(originLen - targetLen) !== 1;
|
||||
|
||||
for (var i = 0; i < longList.length; i += 1) {
|
||||
var shortKey = getItemKey(shortList[i]);
|
||||
var longKey = getItemKey(longList[i]);
|
||||
|
||||
if (shortKey !== longKey) {
|
||||
diffIndex = i;
|
||||
multiple = multiple || shortKey !== getItemKey(longList[i + 1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return diffIndex === null ? null : {
|
||||
index: diffIndex,
|
||||
multiple: multiple
|
||||
};
|
||||
}
|
||||
64
web/node_modules/rc-virtual-list/es/utils/itemUtil.d.ts
generated
vendored
Normal file
64
web/node_modules/rc-virtual-list/es/utils/itemUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Our algorithm have additional one ghost item
|
||||
* whose index as `data.length` to simplify the calculation
|
||||
*/
|
||||
export declare const GHOST_ITEM_KEY = "__rc_ghost_item__";
|
||||
export declare type Key = string | number;
|
||||
/**
|
||||
* Safari has the elasticity effect which provides negative `scrollTop` value.
|
||||
* We should ignore it since will make scroll animation shake.
|
||||
*/
|
||||
export declare function alignScrollTop(scrollTop: number, scrollRange: number): number;
|
||||
export declare function getScrollPercentage({ scrollTop, scrollHeight, clientHeight, }: {
|
||||
scrollTop: number;
|
||||
scrollHeight: number;
|
||||
clientHeight: number;
|
||||
}): number;
|
||||
export declare function getElementScrollPercentage(element: HTMLElement | null): number;
|
||||
/**
|
||||
* Get node `offsetHeight`. We prefer node is a dom element directly.
|
||||
* But if not provided, downgrade to `findDOMNode` to get the real dom element.
|
||||
*/
|
||||
export declare function getNodeHeight(node: HTMLElement): number;
|
||||
/**
|
||||
* Get display items start, end, located item index. This is pure math calculation
|
||||
*/
|
||||
export declare function getRangeIndex(scrollPtg: number, itemCount: number, visibleCount: number): {
|
||||
itemIndex: number;
|
||||
itemOffsetPtg: number;
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
};
|
||||
interface ItemTopConfig {
|
||||
itemIndex: number;
|
||||
itemElementHeights: {
|
||||
[key: string]: number;
|
||||
};
|
||||
itemOffsetPtg: number;
|
||||
scrollTop: number;
|
||||
scrollPtg: number;
|
||||
clientHeight: number;
|
||||
getItemKey: (index: number) => Key;
|
||||
}
|
||||
/**
|
||||
* Calculate the located item related top with current window height
|
||||
*/
|
||||
export declare function getItemRelativeTop({ itemIndex, itemOffsetPtg, itemElementHeights, scrollPtg, clientHeight, getItemKey, }: Omit<ItemTopConfig, 'scrollTop'>): number;
|
||||
/**
|
||||
* Calculate the located item absolute top with whole scroll height
|
||||
*/
|
||||
export declare function getItemAbsoluteTop({ scrollTop, ...rest }: ItemTopConfig): number;
|
||||
interface CompareItemConfig {
|
||||
locatedItemRelativeTop: number;
|
||||
locatedItemIndex: number;
|
||||
compareItemIndex: number;
|
||||
getItemKey: (index: number) => Key;
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
itemElementHeights: {
|
||||
[key: string]: number;
|
||||
};
|
||||
}
|
||||
export declare function getCompareItemRelativeTop({ locatedItemRelativeTop, locatedItemIndex, compareItemIndex, startIndex, endIndex, getItemKey, itemElementHeights, }: CompareItemConfig): number;
|
||||
export declare function requireVirtual(height: number, itemHeight: number, count: number, virtual: boolean): boolean;
|
||||
export {};
|
||||
159
web/node_modules/rc-virtual-list/es/utils/itemUtil.js
generated
vendored
Normal file
159
web/node_modules/rc-virtual-list/es/utils/itemUtil.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
import findDOMNode from "rc-util/es/Dom/findDOMNode";
|
||||
/**
|
||||
* Our algorithm have additional one ghost item
|
||||
* whose index as `data.length` to simplify the calculation
|
||||
*/
|
||||
|
||||
export var GHOST_ITEM_KEY = '__rc_ghost_item__';
|
||||
/**
|
||||
* Get location item and its align percentage with the scroll percentage.
|
||||
* We should measure current scroll position to decide which item is the location item.
|
||||
* And then fill the top count and bottom count with the base of location item.
|
||||
*
|
||||
* `total` should be the real count instead of `total - 1` in calculation.
|
||||
*/
|
||||
|
||||
function getLocationItem(scrollPtg, total) {
|
||||
var itemIndex = Math.floor(scrollPtg * total);
|
||||
var itemTopPtg = itemIndex / total;
|
||||
var itemBottomPtg = (itemIndex + 1) / total;
|
||||
var itemOffsetPtg = (scrollPtg - itemTopPtg) / (itemBottomPtg - itemTopPtg);
|
||||
return {
|
||||
index: itemIndex,
|
||||
offsetPtg: itemOffsetPtg
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Safari has the elasticity effect which provides negative `scrollTop` value.
|
||||
* We should ignore it since will make scroll animation shake.
|
||||
*/
|
||||
|
||||
|
||||
export function alignScrollTop(scrollTop, scrollRange) {
|
||||
if (scrollTop < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (scrollTop >= scrollRange) {
|
||||
return scrollRange;
|
||||
}
|
||||
|
||||
return scrollTop;
|
||||
}
|
||||
export function getScrollPercentage(_ref) {
|
||||
var scrollTop = _ref.scrollTop,
|
||||
scrollHeight = _ref.scrollHeight,
|
||||
clientHeight = _ref.clientHeight;
|
||||
|
||||
if (scrollHeight <= clientHeight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var scrollRange = scrollHeight - clientHeight;
|
||||
var alignedScrollTop = alignScrollTop(scrollTop, scrollRange);
|
||||
var scrollTopPtg = alignedScrollTop / scrollRange;
|
||||
return scrollTopPtg;
|
||||
}
|
||||
export function getElementScrollPercentage(element) {
|
||||
if (!element) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getScrollPercentage(element);
|
||||
}
|
||||
/**
|
||||
* Get node `offsetHeight`. We prefer node is a dom element directly.
|
||||
* But if not provided, downgrade to `findDOMNode` to get the real dom element.
|
||||
*/
|
||||
|
||||
export function getNodeHeight(node) {
|
||||
var element = findDOMNode(node);
|
||||
return element ? element.offsetHeight : 0;
|
||||
}
|
||||
/**
|
||||
* Get display items start, end, located item index. This is pure math calculation
|
||||
*/
|
||||
|
||||
export function getRangeIndex(scrollPtg, itemCount, visibleCount) {
|
||||
var _getLocationItem = getLocationItem(scrollPtg, itemCount),
|
||||
index = _getLocationItem.index,
|
||||
offsetPtg = _getLocationItem.offsetPtg;
|
||||
|
||||
var beforeCount = Math.ceil(scrollPtg * visibleCount);
|
||||
var afterCount = Math.ceil((1 - scrollPtg) * visibleCount);
|
||||
return {
|
||||
itemIndex: index,
|
||||
itemOffsetPtg: offsetPtg,
|
||||
startIndex: Math.max(0, index - beforeCount),
|
||||
endIndex: Math.min(itemCount - 1, index + afterCount)
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Calculate the located item related top with current window height
|
||||
*/
|
||||
|
||||
export function getItemRelativeTop(_ref2) {
|
||||
var itemIndex = _ref2.itemIndex,
|
||||
itemOffsetPtg = _ref2.itemOffsetPtg,
|
||||
itemElementHeights = _ref2.itemElementHeights,
|
||||
scrollPtg = _ref2.scrollPtg,
|
||||
clientHeight = _ref2.clientHeight,
|
||||
getItemKey = _ref2.getItemKey;
|
||||
var locatedItemHeight = itemElementHeights[getItemKey(itemIndex)] || 0;
|
||||
var locatedItemTop = scrollPtg * clientHeight;
|
||||
var locatedItemOffset = itemOffsetPtg * locatedItemHeight;
|
||||
return Math.floor(locatedItemTop - locatedItemOffset);
|
||||
}
|
||||
/**
|
||||
* Calculate the located item absolute top with whole scroll height
|
||||
*/
|
||||
|
||||
export function getItemAbsoluteTop(_ref3) {
|
||||
var scrollTop = _ref3.scrollTop,
|
||||
rest = _objectWithoutProperties(_ref3, ["scrollTop"]);
|
||||
|
||||
return scrollTop + getItemRelativeTop(rest);
|
||||
}
|
||||
export function getCompareItemRelativeTop(_ref4) {
|
||||
var locatedItemRelativeTop = _ref4.locatedItemRelativeTop,
|
||||
locatedItemIndex = _ref4.locatedItemIndex,
|
||||
compareItemIndex = _ref4.compareItemIndex,
|
||||
startIndex = _ref4.startIndex,
|
||||
endIndex = _ref4.endIndex,
|
||||
getItemKey = _ref4.getItemKey,
|
||||
itemElementHeights = _ref4.itemElementHeights;
|
||||
var originCompareItemTop = locatedItemRelativeTop;
|
||||
var compareItemKey = getItemKey(compareItemIndex);
|
||||
|
||||
if (compareItemIndex <= locatedItemIndex) {
|
||||
for (var index = locatedItemIndex; index >= startIndex; index -= 1) {
|
||||
var key = getItemKey(index);
|
||||
|
||||
if (key === compareItemKey) {
|
||||
break;
|
||||
}
|
||||
|
||||
var prevItemKey = getItemKey(index - 1);
|
||||
originCompareItemTop -= itemElementHeights[prevItemKey] || 0;
|
||||
}
|
||||
} else {
|
||||
for (var _index = locatedItemIndex; _index <= endIndex; _index += 1) {
|
||||
var _key = getItemKey(_index);
|
||||
|
||||
if (_key === compareItemKey) {
|
||||
break;
|
||||
}
|
||||
|
||||
originCompareItemTop += itemElementHeights[_key] || 0;
|
||||
}
|
||||
}
|
||||
|
||||
return originCompareItemTop;
|
||||
}
|
||||
export function requireVirtual(height, itemHeight, count, virtual) {
|
||||
return virtual !== false && typeof height === 'number' && count * itemHeight > height;
|
||||
}
|
||||
14
web/node_modules/rc-virtual-list/lib/Filler.d.ts
generated
vendored
Normal file
14
web/node_modules/rc-virtual-list/lib/Filler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as React from 'react';
|
||||
interface FillerProps {
|
||||
prefixCls?: string;
|
||||
/** Virtual filler height. Should be `count * itemMinHeight` */
|
||||
height: number;
|
||||
/** Set offset of visible items. Should be the top of start item position */
|
||||
offset?: number;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
/**
|
||||
* Fill component to provided the scroll content real height.
|
||||
*/
|
||||
declare const Filler: React.FC<FillerProps>;
|
||||
export default Filler;
|
||||
64
web/node_modules/rc-virtual-list/lib/Filler.js
generated
vendored
Normal file
64
web/node_modules/rc-virtual-list/lib/Filler.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
|
||||
var _classnames = _interopRequireDefault(require("classnames"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
/**
|
||||
* Fill component to provided the scroll content real height.
|
||||
*/
|
||||
var Filler = function Filler(_ref) {
|
||||
var height = _ref.height,
|
||||
offset = _ref.offset,
|
||||
children = _ref.children,
|
||||
prefixCls = _ref.prefixCls;
|
||||
var outerStyle = {};
|
||||
var innerStyle = {
|
||||
display: 'flex',
|
||||
flexDirection: 'column'
|
||||
};
|
||||
|
||||
if (offset !== undefined) {
|
||||
outerStyle = {
|
||||
height: height,
|
||||
position: 'relative',
|
||||
overflow: 'hidden'
|
||||
};
|
||||
innerStyle = _objectSpread({}, innerStyle, {
|
||||
transform: "translateY(".concat(offset, "px)"),
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0
|
||||
});
|
||||
}
|
||||
|
||||
return React.createElement("div", {
|
||||
style: outerStyle
|
||||
}, React.createElement("div", {
|
||||
style: innerStyle,
|
||||
className: (0, _classnames.default)(_defineProperty({}, "".concat(prefixCls, "-holder-inner"), prefixCls))
|
||||
}, children));
|
||||
};
|
||||
|
||||
var _default = Filler;
|
||||
exports.default = _default;
|
||||
147
web/node_modules/rc-virtual-list/lib/List.d.ts
generated
vendored
Normal file
147
web/node_modules/rc-virtual-list/lib/List.d.ts
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
import * as React from 'react';
|
||||
import { Key } from './utils/itemUtil';
|
||||
declare type ScrollAlign = 'top' | 'bottom' | 'auto';
|
||||
export declare type RenderFunc<T> = (item: T, index: number, props: {
|
||||
style: React.CSSProperties;
|
||||
}) => React.ReactNode;
|
||||
export interface RelativeScroll {
|
||||
itemIndex: number;
|
||||
relativeTop: number;
|
||||
}
|
||||
export interface ScrollInfo {
|
||||
scrollTop: number;
|
||||
startItemTop: number;
|
||||
startIndex: number;
|
||||
}
|
||||
export interface ListProps<T> extends React.HTMLAttributes<any> {
|
||||
prefixCls?: string;
|
||||
children: RenderFunc<T>;
|
||||
data: T[];
|
||||
height?: number;
|
||||
itemHeight?: number;
|
||||
/** If not match virtual scroll condition, Set List still use height of container. */
|
||||
fullHeight?: boolean;
|
||||
itemKey: Key | ((item: T) => Key);
|
||||
component?: string | React.FC<any> | React.ComponentClass<any>;
|
||||
/** Disable scroll check. Usually used on animation control */
|
||||
disabled?: boolean;
|
||||
/** Set `false` will always use real scroll instead of virtual one */
|
||||
virtual?: boolean;
|
||||
/** When `disabled`, trigger if changed item not render. */
|
||||
onSkipRender?: () => void;
|
||||
onScroll?: React.UIEventHandler<HTMLElement>;
|
||||
}
|
||||
declare type Status = 'NONE' | 'MEASURE_START' | 'MEASURE_DONE' | 'SWITCH_TO_VIRTUAL' | 'SWITCH_TO_RAW';
|
||||
interface ListState<T> {
|
||||
status: Status;
|
||||
scrollTop: number | null;
|
||||
/** Located item index */
|
||||
itemIndex: number;
|
||||
/** Located item bind its height percentage with the `scrollTop` */
|
||||
itemOffsetPtg: number;
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
/**
|
||||
* Calculated by `scrollTop`.
|
||||
* We cache in the state since if `data` length change,
|
||||
* we need revert back to the located item index.
|
||||
*/
|
||||
startItemTop: number;
|
||||
/**
|
||||
* Tell if is using virtual scroll
|
||||
*/
|
||||
isVirtual: boolean;
|
||||
/**
|
||||
* Only used when turn virtual list to raw list
|
||||
*/
|
||||
cacheScroll?: RelativeScroll;
|
||||
/**
|
||||
* Cache `data.length` to use for `disabled` status.
|
||||
*/
|
||||
itemCount: number;
|
||||
}
|
||||
/**
|
||||
* We use class component here since typescript can not support generic in function component
|
||||
*
|
||||
* Virtual list display logic:
|
||||
* 1. scroll / initialize trigger measure
|
||||
* 2. Get location item of current `scrollTop`
|
||||
* 3. [Render] Render visible items
|
||||
* 4. Get all the visible items height
|
||||
* 5. [Render] Update top item `margin-top` to fit the position
|
||||
*
|
||||
* Algorithm:
|
||||
* We split scroll bar into equal slice. An item with whatever height occupy the same range slice.
|
||||
* When `scrollTop` change,
|
||||
* it will calculate the item percentage position and move item to the position.
|
||||
* Then calculate other item position base on the located item.
|
||||
*
|
||||
* Concept:
|
||||
*
|
||||
* # located item
|
||||
* The base position item which other items position calculate base on.
|
||||
*/
|
||||
declare class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
|
||||
static defaultProps: {
|
||||
itemHeight: number;
|
||||
data: any[];
|
||||
};
|
||||
listRef: React.RefObject<HTMLElement>;
|
||||
itemElements: {
|
||||
[index: number]: HTMLElement;
|
||||
};
|
||||
itemElementHeights: {
|
||||
[index: number]: number;
|
||||
};
|
||||
/**
|
||||
* Always point to the latest props if `disabled` is `false`
|
||||
*/
|
||||
cachedProps: Partial<ListProps<T>>;
|
||||
/**
|
||||
* Lock scroll process with `onScroll` event.
|
||||
* This is used for `data` length change and `scrollTop` restore
|
||||
*/
|
||||
lockScroll: boolean;
|
||||
constructor(props: ListProps<T>);
|
||||
static getDerivedStateFromProps(nextProps: ListProps<any>): {
|
||||
itemCount: number;
|
||||
};
|
||||
/**
|
||||
* Phase 1: Initial should sync with default scroll top
|
||||
*/
|
||||
componentDidMount(): void;
|
||||
/**
|
||||
* Phase 4: Record used item height
|
||||
* Phase 5: Trigger re-render to use correct position
|
||||
*/
|
||||
componentDidUpdate(): void;
|
||||
/**
|
||||
* Phase 2: Trigger render since we should re-calculate current position.
|
||||
*/
|
||||
onScroll: React.UIEventHandler<HTMLElement>;
|
||||
onRawScroll: React.UIEventHandler<HTMLElement>;
|
||||
triggerOnScroll: React.UIEventHandler<HTMLElement>;
|
||||
getIndexKey: (index: number, props?: Partial<ListProps<T>>) => string | number;
|
||||
getItemKey: (item: T, props?: Partial<ListProps<T>>) => string | number;
|
||||
/**
|
||||
* Collect current rendered dom element item heights
|
||||
*/
|
||||
collectItemHeights: (range?: {
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
}) => void;
|
||||
scrollTo: (arg0: number | {
|
||||
index: number;
|
||||
align?: ScrollAlign;
|
||||
} | {
|
||||
key: string | number;
|
||||
align?: ScrollAlign;
|
||||
}) => void;
|
||||
internalScrollTo(relativeScroll: RelativeScroll): void;
|
||||
/**
|
||||
* Phase 4: Render item and get all the visible items height
|
||||
*/
|
||||
renderChildren: (list: T[], startIndex: number, renderFunc: RenderFunc<T>) => React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)>) | (new (props: any) => React.Component<any, any, any>)>[];
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default List;
|
||||
806
web/node_modules/rc-virtual-list/lib/List.js
generated
vendored
Normal file
806
web/node_modules/rc-virtual-list/lib/List.js
generated
vendored
Normal file
@@ -0,0 +1,806 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
|
||||
var _classnames = _interopRequireDefault(require("classnames"));
|
||||
|
||||
var _raf = _interopRequireDefault(require("raf"));
|
||||
|
||||
var _Filler = _interopRequireDefault(require("./Filler"));
|
||||
|
||||
var _itemUtil = require("./utils/itemUtil");
|
||||
|
||||
var _algorithmUtil = require("./utils/algorithmUtil");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var ScrollStyle = {
|
||||
overflowY: 'auto',
|
||||
overflowAnchor: 'none'
|
||||
};
|
||||
var ITEM_SCALE_RATE = 1;
|
||||
/**
|
||||
* We use class component here since typescript can not support generic in function component
|
||||
*
|
||||
* Virtual list display logic:
|
||||
* 1. scroll / initialize trigger measure
|
||||
* 2. Get location item of current `scrollTop`
|
||||
* 3. [Render] Render visible items
|
||||
* 4. Get all the visible items height
|
||||
* 5. [Render] Update top item `margin-top` to fit the position
|
||||
*
|
||||
* Algorithm:
|
||||
* We split scroll bar into equal slice. An item with whatever height occupy the same range slice.
|
||||
* When `scrollTop` change,
|
||||
* it will calculate the item percentage position and move item to the position.
|
||||
* Then calculate other item position base on the located item.
|
||||
*
|
||||
* Concept:
|
||||
*
|
||||
* # located item
|
||||
* The base position item which other items position calculate base on.
|
||||
*/
|
||||
|
||||
var List = /*#__PURE__*/function (_React$Component) {
|
||||
_inherits(List, _React$Component);
|
||||
|
||||
function List(props) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, List);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(List).call(this, props));
|
||||
_this.listRef = React.createRef();
|
||||
_this.itemElements = {};
|
||||
_this.itemElementHeights = {};
|
||||
/**
|
||||
* Lock scroll process with `onScroll` event.
|
||||
* This is used for `data` length change and `scrollTop` restore
|
||||
*/
|
||||
|
||||
_this.lockScroll = false;
|
||||
/**
|
||||
* Phase 2: Trigger render since we should re-calculate current position.
|
||||
*/
|
||||
|
||||
_this.onScroll = function (event) {
|
||||
var _this$props = _this.props,
|
||||
data = _this$props.data,
|
||||
height = _this$props.height,
|
||||
itemHeight = _this$props.itemHeight,
|
||||
disabled = _this$props.disabled;
|
||||
var _this$listRef$current = _this.listRef.current,
|
||||
originScrollTop = _this$listRef$current.scrollTop,
|
||||
clientHeight = _this$listRef$current.clientHeight,
|
||||
scrollHeight = _this$listRef$current.scrollHeight;
|
||||
var scrollTop = (0, _itemUtil.alignScrollTop)(originScrollTop, scrollHeight - clientHeight); // Skip if `scrollTop` not change to avoid shake
|
||||
|
||||
if (scrollTop === _this.state.scrollTop || _this.lockScroll || disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var scrollPtg = (0, _itemUtil.getElementScrollPercentage)(_this.listRef.current);
|
||||
var visibleCount = Math.ceil(height / itemHeight);
|
||||
|
||||
var _getRangeIndex = (0, _itemUtil.getRangeIndex)(scrollPtg, data.length, visibleCount),
|
||||
itemIndex = _getRangeIndex.itemIndex,
|
||||
itemOffsetPtg = _getRangeIndex.itemOffsetPtg,
|
||||
startIndex = _getRangeIndex.startIndex,
|
||||
endIndex = _getRangeIndex.endIndex;
|
||||
|
||||
_this.setState({
|
||||
status: 'MEASURE_START',
|
||||
scrollTop: scrollTop,
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
startIndex: startIndex,
|
||||
endIndex: endIndex
|
||||
});
|
||||
|
||||
_this.triggerOnScroll(event);
|
||||
};
|
||||
|
||||
_this.onRawScroll = function (event) {
|
||||
var scrollTop = _this.listRef.current.scrollTop;
|
||||
|
||||
_this.setState({
|
||||
scrollTop: scrollTop
|
||||
});
|
||||
|
||||
_this.triggerOnScroll(event);
|
||||
};
|
||||
|
||||
_this.triggerOnScroll = function (event) {
|
||||
var onScroll = _this.props.onScroll;
|
||||
|
||||
if (onScroll && event) {
|
||||
onScroll(event);
|
||||
}
|
||||
};
|
||||
|
||||
_this.getIndexKey = function (index, props) {
|
||||
var mergedProps = props || _this.props;
|
||||
var _mergedProps$data = mergedProps.data,
|
||||
data = _mergedProps$data === void 0 ? [] : _mergedProps$data; // Return ghost key as latest index item
|
||||
|
||||
if (index === data.length) {
|
||||
return _itemUtil.GHOST_ITEM_KEY;
|
||||
}
|
||||
|
||||
var item = data[index];
|
||||
|
||||
if (!item) {
|
||||
/* istanbul ignore next */
|
||||
console.error('Not find index item. Please report this since it is a bug.');
|
||||
}
|
||||
|
||||
return _this.getItemKey(item, mergedProps);
|
||||
};
|
||||
|
||||
_this.getItemKey = function (item, props) {
|
||||
var _ref = props || _this.props,
|
||||
itemKey = _ref.itemKey;
|
||||
|
||||
return typeof itemKey === 'function' ? itemKey(item) : item[itemKey];
|
||||
};
|
||||
/**
|
||||
* Collect current rendered dom element item heights
|
||||
*/
|
||||
|
||||
|
||||
_this.collectItemHeights = function (range) {
|
||||
var _ref2 = range || _this.state,
|
||||
startIndex = _ref2.startIndex,
|
||||
endIndex = _ref2.endIndex;
|
||||
|
||||
var data = _this.props.data; // Record here since measure item height will get warning in `render`
|
||||
|
||||
for (var index = startIndex; index <= endIndex; index += 1) {
|
||||
var item = data[index]; // Only collect exist item height
|
||||
|
||||
if (item) {
|
||||
var eleKey = _this.getItemKey(item);
|
||||
|
||||
_this.itemElementHeights[eleKey] = (0, _itemUtil.getNodeHeight)(_this.itemElements[eleKey]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_this.scrollTo = function (arg0) {
|
||||
(0, _raf.default)(function () {
|
||||
// Number top
|
||||
if (_typeof(arg0) === 'object') {
|
||||
var isVirtual = _this.state.isVirtual;
|
||||
var _this$props2 = _this.props,
|
||||
height = _this$props2.height,
|
||||
itemHeight = _this$props2.itemHeight,
|
||||
data = _this$props2.data;
|
||||
var _arg0$align = arg0.align,
|
||||
align = _arg0$align === void 0 ? 'auto' : _arg0$align;
|
||||
var index = 0;
|
||||
|
||||
if ('index' in arg0) {
|
||||
index = arg0.index;
|
||||
} else if ('key' in arg0) {
|
||||
var key = arg0.key;
|
||||
index = data.findIndex(function (item) {
|
||||
return _this.getItemKey(item) === key;
|
||||
});
|
||||
}
|
||||
|
||||
var visibleCount = Math.ceil(height / itemHeight);
|
||||
var item = data[index];
|
||||
|
||||
if (item) {
|
||||
var clientHeight = _this.listRef.current.clientHeight;
|
||||
|
||||
if (isVirtual) {
|
||||
// Calculate related data
|
||||
var _this$state = _this.state,
|
||||
itemIndex = _this$state.itemIndex,
|
||||
itemOffsetPtg = _this$state.itemOffsetPtg;
|
||||
var scrollTop = _this.listRef.current.scrollTop;
|
||||
var scrollPtg = (0, _itemUtil.getElementScrollPercentage)(_this.listRef.current);
|
||||
var relativeLocatedItemTop = (0, _itemUtil.getItemRelativeTop)({
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
itemElementHeights: _this.itemElementHeights,
|
||||
scrollPtg: scrollPtg,
|
||||
clientHeight: clientHeight,
|
||||
getItemKey: _this.getIndexKey
|
||||
}); // We will force render related items to collect height for re-location
|
||||
|
||||
_this.setState({
|
||||
startIndex: Math.max(0, index - visibleCount),
|
||||
endIndex: Math.min(data.length - 1, index + visibleCount)
|
||||
}, function () {
|
||||
_this.collectItemHeights(); // Calculate related top
|
||||
|
||||
|
||||
var relativeTop;
|
||||
var mergedAlgin = align;
|
||||
|
||||
if (align === 'auto') {
|
||||
var shouldChange = true; // Check if exist in the visible range
|
||||
|
||||
if (Math.abs(itemIndex - index) < visibleCount) {
|
||||
var itemTop = relativeLocatedItemTop;
|
||||
|
||||
if (index < itemIndex) {
|
||||
for (var i = index; i < itemIndex; i += 1) {
|
||||
var eleKey = _this.getIndexKey(i);
|
||||
|
||||
itemTop -= _this.itemElementHeights[eleKey] || 0;
|
||||
}
|
||||
} else {
|
||||
for (var _i = itemIndex; _i <= index; _i += 1) {
|
||||
var _eleKey = _this.getIndexKey(_i);
|
||||
|
||||
itemTop += _this.itemElementHeights[_eleKey] || 0;
|
||||
}
|
||||
}
|
||||
|
||||
shouldChange = itemTop <= 0 || itemTop >= clientHeight;
|
||||
}
|
||||
|
||||
if (shouldChange) {
|
||||
// Out of range will fall back to position align
|
||||
mergedAlgin = index < itemIndex ? 'top' : 'bottom';
|
||||
} else {
|
||||
var _getRangeIndex2 = (0, _itemUtil.getRangeIndex)(scrollPtg, data.length, visibleCount),
|
||||
nextIndex = _getRangeIndex2.itemIndex,
|
||||
newOffsetPtg = _getRangeIndex2.itemOffsetPtg,
|
||||
startIndex = _getRangeIndex2.startIndex,
|
||||
endIndex = _getRangeIndex2.endIndex;
|
||||
|
||||
_this.setState({
|
||||
scrollTop: scrollTop,
|
||||
itemIndex: nextIndex,
|
||||
itemOffsetPtg: newOffsetPtg,
|
||||
startIndex: startIndex,
|
||||
endIndex: endIndex
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
} // Align with position should make scroll happen
|
||||
|
||||
|
||||
if (mergedAlgin === 'top') {
|
||||
relativeTop = 0;
|
||||
} else if (mergedAlgin === 'bottom') {
|
||||
var _eleKey2 = _this.getItemKey(item);
|
||||
|
||||
relativeTop = clientHeight - _this.itemElementHeights[_eleKey2] || 0;
|
||||
}
|
||||
|
||||
_this.internalScrollTo({
|
||||
itemIndex: index,
|
||||
relativeTop: relativeTop
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Raw list without virtual scroll set position directly
|
||||
_this.collectItemHeights({
|
||||
startIndex: 0,
|
||||
endIndex: data.length - 1
|
||||
});
|
||||
|
||||
var mergedAlgin = align; // Collection index item position
|
||||
|
||||
var indexItemHeight = _this.itemElementHeights[_this.getIndexKey(index)];
|
||||
|
||||
var itemTop = 0;
|
||||
|
||||
for (var i = 0; i < index; i += 1) {
|
||||
var eleKey = _this.getIndexKey(i);
|
||||
|
||||
itemTop += _this.itemElementHeights[eleKey] || 0;
|
||||
}
|
||||
|
||||
var itemBottom = itemTop + indexItemHeight;
|
||||
|
||||
if (mergedAlgin === 'auto') {
|
||||
if (itemTop < _this.listRef.current.scrollTop) {
|
||||
mergedAlgin = 'top';
|
||||
} else if (itemBottom > _this.listRef.current.scrollTop + clientHeight) {
|
||||
mergedAlgin = 'bottom';
|
||||
}
|
||||
}
|
||||
|
||||
if (mergedAlgin === 'top') {
|
||||
_this.listRef.current.scrollTop = itemTop;
|
||||
} else if (mergedAlgin === 'bottom') {
|
||||
_this.listRef.current.scrollTop = itemTop - (clientHeight - indexItemHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_this.listRef.current.scrollTop = arg0;
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Phase 4: Render item and get all the visible items height
|
||||
*/
|
||||
|
||||
|
||||
_this.renderChildren = function (list, startIndex, renderFunc) {
|
||||
var status = _this.state.status; // We should measure rendered item height
|
||||
|
||||
return list.map(function (item, index) {
|
||||
var eleIndex = startIndex + index;
|
||||
var node = renderFunc(item, eleIndex, {
|
||||
style: status === 'MEASURE_START' ? {
|
||||
visibility: 'hidden'
|
||||
} : {}
|
||||
});
|
||||
|
||||
var eleKey = _this.getIndexKey(eleIndex); // Pass `key` and `ref` for internal measure
|
||||
|
||||
|
||||
return React.cloneElement(node, {
|
||||
key: eleKey,
|
||||
ref: function ref(ele) {
|
||||
_this.itemElements[eleKey] = ele;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
_this.cachedProps = props;
|
||||
_this.state = {
|
||||
status: 'NONE',
|
||||
scrollTop: null,
|
||||
itemIndex: 0,
|
||||
itemOffsetPtg: 0,
|
||||
startIndex: 0,
|
||||
endIndex: 0,
|
||||
startItemTop: 0,
|
||||
isVirtual: (0, _itemUtil.requireVirtual)(props.height, props.itemHeight, props.data.length, props.virtual),
|
||||
itemCount: props.data.length
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(List, [{
|
||||
key: "componentDidMount",
|
||||
|
||||
/**
|
||||
* Phase 1: Initial should sync with default scroll top
|
||||
*/
|
||||
value: function componentDidMount() {
|
||||
if (this.listRef.current) {
|
||||
this.listRef.current.scrollTop = 0;
|
||||
this.onScroll(null);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phase 4: Record used item height
|
||||
* Phase 5: Trigger re-render to use correct position
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "componentDidUpdate",
|
||||
value: function componentDidUpdate() {
|
||||
var _this2 = this;
|
||||
|
||||
var status = this.state.status;
|
||||
var _this$props3 = this.props,
|
||||
data = _this$props3.data,
|
||||
height = _this$props3.height,
|
||||
itemHeight = _this$props3.itemHeight,
|
||||
disabled = _this$props3.disabled,
|
||||
onSkipRender = _this$props3.onSkipRender,
|
||||
virtual = _this$props3.virtual;
|
||||
var prevData = this.cachedProps.data || [];
|
||||
var changedItemIndex = null;
|
||||
|
||||
if (prevData.length !== data.length) {
|
||||
var diff = (0, _algorithmUtil.findListDiffIndex)(prevData, data, this.getItemKey);
|
||||
changedItemIndex = diff ? diff.index : null;
|
||||
}
|
||||
|
||||
if (disabled) {
|
||||
// Should trigger `onSkipRender` to tell that diff component is not render in the list
|
||||
if (data.length > prevData.length) {
|
||||
var _this$state2 = this.state,
|
||||
startIndex = _this$state2.startIndex,
|
||||
endIndex = _this$state2.endIndex;
|
||||
|
||||
if (onSkipRender && (changedItemIndex === null || changedItemIndex < startIndex || endIndex < changedItemIndex)) {
|
||||
onSkipRender();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var isVirtual = (0, _itemUtil.requireVirtual)(height, itemHeight, data.length, virtual);
|
||||
var nextStatus = status;
|
||||
|
||||
if (this.state.isVirtual !== isVirtual) {
|
||||
nextStatus = isVirtual ? 'SWITCH_TO_VIRTUAL' : 'SWITCH_TO_RAW';
|
||||
this.setState({
|
||||
isVirtual: isVirtual,
|
||||
status: nextStatus
|
||||
});
|
||||
/**
|
||||
* We will wait a tick to let list turn to virtual list.
|
||||
* And then use virtual list sync logic to adjust the scroll.
|
||||
*/
|
||||
|
||||
if (nextStatus === 'SWITCH_TO_VIRTUAL') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (status === 'MEASURE_START') {
|
||||
var _this$state3 = this.state,
|
||||
_startIndex = _this$state3.startIndex,
|
||||
itemIndex = _this$state3.itemIndex,
|
||||
itemOffsetPtg = _this$state3.itemOffsetPtg;
|
||||
var scrollTop = this.listRef.current.scrollTop; // Record here since measure item height will get warning in `render`
|
||||
|
||||
this.collectItemHeights(); // Calculate top visible item top offset
|
||||
|
||||
var locatedItemTop = (0, _itemUtil.getItemAbsoluteTop)({
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
itemElementHeights: this.itemElementHeights,
|
||||
scrollTop: scrollTop,
|
||||
scrollPtg: (0, _itemUtil.getElementScrollPercentage)(this.listRef.current),
|
||||
clientHeight: this.listRef.current.clientHeight,
|
||||
getItemKey: this.getIndexKey
|
||||
});
|
||||
var startItemTop = locatedItemTop;
|
||||
|
||||
for (var index = itemIndex - 1; index >= _startIndex; index -= 1) {
|
||||
startItemTop -= this.itemElementHeights[this.getIndexKey(index)] || 0;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
status: 'MEASURE_DONE',
|
||||
startItemTop: startItemTop
|
||||
});
|
||||
}
|
||||
|
||||
if (status === 'SWITCH_TO_RAW') {
|
||||
/**
|
||||
* After virtual list back to raw list,
|
||||
* we update the `scrollTop` to real top instead of percentage top.
|
||||
*/
|
||||
var _this$state$cacheScro = this.state.cacheScroll,
|
||||
_itemIndex = _this$state$cacheScro.itemIndex,
|
||||
relativeTop = _this$state$cacheScro.relativeTop;
|
||||
var rawTop = relativeTop;
|
||||
|
||||
for (var _index = 0; _index < _itemIndex; _index += 1) {
|
||||
rawTop -= this.itemElementHeights[this.getIndexKey(_index)] || 0;
|
||||
}
|
||||
|
||||
this.lockScroll = true;
|
||||
this.listRef.current.scrollTop = -rawTop;
|
||||
this.setState({
|
||||
status: 'MEASURE_DONE',
|
||||
itemIndex: 0
|
||||
});
|
||||
requestAnimationFrame(function () {
|
||||
requestAnimationFrame(function () {
|
||||
_this2.lockScroll = false;
|
||||
});
|
||||
});
|
||||
} else if (prevData.length !== data.length && changedItemIndex !== null && height) {
|
||||
/**
|
||||
* Re-calculate the item position since `data` length changed.
|
||||
* [IMPORTANT] We use relative position calculate here.
|
||||
*/
|
||||
var originItemIndex = this.state.itemIndex;
|
||||
var _this$state4 = this.state,
|
||||
originItemOffsetPtg = _this$state4.itemOffsetPtg,
|
||||
originStartIndex = _this$state4.startIndex,
|
||||
originEndIndex = _this$state4.endIndex,
|
||||
originScrollTop = _this$state4.scrollTop; // 1. Refresh item heights
|
||||
|
||||
this.collectItemHeights(); // 1. Get origin located item top
|
||||
|
||||
var originLocatedItemRelativeTop;
|
||||
|
||||
if (this.state.status === 'SWITCH_TO_VIRTUAL') {
|
||||
originItemIndex = 0;
|
||||
originLocatedItemRelativeTop = -this.state.scrollTop;
|
||||
} else {
|
||||
originLocatedItemRelativeTop = (0, _itemUtil.getItemRelativeTop)({
|
||||
itemIndex: originItemIndex,
|
||||
itemOffsetPtg: originItemOffsetPtg,
|
||||
itemElementHeights: this.itemElementHeights,
|
||||
scrollPtg: (0, _itemUtil.getScrollPercentage)({
|
||||
scrollTop: originScrollTop,
|
||||
scrollHeight: prevData.length * itemHeight,
|
||||
clientHeight: this.listRef.current.clientHeight
|
||||
}),
|
||||
clientHeight: this.listRef.current.clientHeight,
|
||||
getItemKey: function getItemKey(index) {
|
||||
return _this2.getIndexKey(index, _this2.cachedProps);
|
||||
}
|
||||
});
|
||||
} // 2. Find the compare item
|
||||
|
||||
|
||||
var originCompareItemIndex = changedItemIndex - 1; // Use next one since there are not more item before removed
|
||||
|
||||
if (originCompareItemIndex < 0) {
|
||||
originCompareItemIndex = 0;
|
||||
} // 3. Find the compare item top
|
||||
|
||||
|
||||
var originCompareItemTop = (0, _itemUtil.getCompareItemRelativeTop)({
|
||||
locatedItemRelativeTop: originLocatedItemRelativeTop,
|
||||
locatedItemIndex: originItemIndex,
|
||||
compareItemIndex: originCompareItemIndex,
|
||||
startIndex: originStartIndex,
|
||||
endIndex: originEndIndex,
|
||||
getItemKey: function getItemKey(index) {
|
||||
return _this2.getIndexKey(index, _this2.cachedProps);
|
||||
},
|
||||
itemElementHeights: this.itemElementHeights
|
||||
});
|
||||
|
||||
if (nextStatus === 'SWITCH_TO_RAW') {
|
||||
/**
|
||||
* We will record current measure relative item top and apply in raw list after list turned
|
||||
*/
|
||||
this.setState({
|
||||
cacheScroll: {
|
||||
itemIndex: originCompareItemIndex,
|
||||
relativeTop: originCompareItemTop
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.internalScrollTo({
|
||||
itemIndex: originCompareItemIndex,
|
||||
relativeTop: originCompareItemTop
|
||||
});
|
||||
}
|
||||
} else if (nextStatus === 'SWITCH_TO_RAW') {
|
||||
// This is only trigger when height changes that all items can show in raw
|
||||
// Let's reset back to top
|
||||
this.setState({
|
||||
cacheScroll: {
|
||||
itemIndex: 0,
|
||||
relativeTop: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.cachedProps = this.props;
|
||||
}
|
||||
}, {
|
||||
key: "internalScrollTo",
|
||||
value: function internalScrollTo(relativeScroll) {
|
||||
var _this3 = this;
|
||||
|
||||
var compareItemIndex = relativeScroll.itemIndex,
|
||||
compareItemRelativeTop = relativeScroll.relativeTop;
|
||||
var originScrollTop = this.state.scrollTop;
|
||||
var _this$props4 = this.props,
|
||||
data = _this$props4.data,
|
||||
itemHeight = _this$props4.itemHeight,
|
||||
height = _this$props4.height; // 1. Find the best match compare item top
|
||||
|
||||
var bestSimilarity = Number.MAX_VALUE;
|
||||
var bestScrollTop = null;
|
||||
var bestItemIndex = null;
|
||||
var bestItemOffsetPtg = null;
|
||||
var bestStartIndex = null;
|
||||
var bestEndIndex = null;
|
||||
var missSimilarity = 0;
|
||||
var scrollHeight = data.length * itemHeight;
|
||||
var clientHeight = this.listRef.current.clientHeight;
|
||||
var maxScrollTop = scrollHeight - clientHeight;
|
||||
|
||||
for (var i = 0; i < maxScrollTop; i += 1) {
|
||||
var scrollTop = (0, _algorithmUtil.getIndexByStartLoc)(0, maxScrollTop, originScrollTop, i);
|
||||
var scrollPtg = (0, _itemUtil.getScrollPercentage)({
|
||||
scrollTop: scrollTop,
|
||||
scrollHeight: scrollHeight,
|
||||
clientHeight: clientHeight
|
||||
});
|
||||
var visibleCount = Math.ceil(height / itemHeight);
|
||||
|
||||
var _getRangeIndex3 = (0, _itemUtil.getRangeIndex)(scrollPtg, data.length, visibleCount),
|
||||
itemIndex = _getRangeIndex3.itemIndex,
|
||||
itemOffsetPtg = _getRangeIndex3.itemOffsetPtg,
|
||||
startIndex = _getRangeIndex3.startIndex,
|
||||
endIndex = _getRangeIndex3.endIndex; // No need to check if compare item out of the index to save performance
|
||||
|
||||
|
||||
if (startIndex <= compareItemIndex && compareItemIndex <= endIndex) {
|
||||
// 1.1 Get measure located item relative top
|
||||
var locatedItemRelativeTop = (0, _itemUtil.getItemRelativeTop)({
|
||||
itemIndex: itemIndex,
|
||||
itemOffsetPtg: itemOffsetPtg,
|
||||
itemElementHeights: this.itemElementHeights,
|
||||
scrollPtg: scrollPtg,
|
||||
clientHeight: clientHeight,
|
||||
getItemKey: this.getIndexKey
|
||||
});
|
||||
var compareItemTop = (0, _itemUtil.getCompareItemRelativeTop)({
|
||||
locatedItemRelativeTop: locatedItemRelativeTop,
|
||||
locatedItemIndex: itemIndex,
|
||||
compareItemIndex: compareItemIndex,
|
||||
startIndex: startIndex,
|
||||
endIndex: endIndex,
|
||||
getItemKey: this.getIndexKey,
|
||||
itemElementHeights: this.itemElementHeights
|
||||
}); // 1.2 Find best match compare item top
|
||||
|
||||
var similarity = Math.abs(compareItemTop - compareItemRelativeTop);
|
||||
|
||||
if (similarity < bestSimilarity) {
|
||||
bestSimilarity = similarity;
|
||||
bestScrollTop = scrollTop;
|
||||
bestItemIndex = itemIndex;
|
||||
bestItemOffsetPtg = itemOffsetPtg;
|
||||
bestStartIndex = startIndex;
|
||||
bestEndIndex = endIndex;
|
||||
missSimilarity = 0;
|
||||
} else {
|
||||
missSimilarity += 1;
|
||||
}
|
||||
} // If keeping 10 times not match similarity,
|
||||
// check more scrollTop is meaningless.
|
||||
// Here boundary is set to 10.
|
||||
|
||||
|
||||
if (missSimilarity > 10) {
|
||||
break;
|
||||
}
|
||||
} // 2. Re-scroll if has best scroll match
|
||||
|
||||
|
||||
if (bestScrollTop !== null) {
|
||||
this.lockScroll = true;
|
||||
this.listRef.current.scrollTop = bestScrollTop;
|
||||
this.setState({
|
||||
status: 'MEASURE_START',
|
||||
scrollTop: bestScrollTop,
|
||||
itemIndex: bestItemIndex,
|
||||
itemOffsetPtg: bestItemOffsetPtg,
|
||||
startIndex: bestStartIndex,
|
||||
endIndex: bestEndIndex
|
||||
});
|
||||
requestAnimationFrame(function () {
|
||||
requestAnimationFrame(function () {
|
||||
_this3.lockScroll = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "render",
|
||||
value: function render() {
|
||||
var _this$state5 = this.state,
|
||||
isVirtual = _this$state5.isVirtual,
|
||||
itemCount = _this$state5.itemCount;
|
||||
|
||||
var _this$props5 = this.props,
|
||||
prefixCls = _this$props5.prefixCls,
|
||||
style = _this$props5.style,
|
||||
className = _this$props5.className,
|
||||
_this$props5$componen = _this$props5.component,
|
||||
Component = _this$props5$componen === void 0 ? 'div' : _this$props5$componen,
|
||||
height = _this$props5.height,
|
||||
itemHeight = _this$props5.itemHeight,
|
||||
_this$props5$fullHeig = _this$props5.fullHeight,
|
||||
fullHeight = _this$props5$fullHeig === void 0 ? true : _this$props5$fullHeig,
|
||||
data = _this$props5.data,
|
||||
children = _this$props5.children,
|
||||
itemKey = _this$props5.itemKey,
|
||||
onSkipRender = _this$props5.onSkipRender,
|
||||
disabled = _this$props5.disabled,
|
||||
virtual = _this$props5.virtual,
|
||||
restProps = _objectWithoutProperties(_this$props5, ["prefixCls", "style", "className", "component", "height", "itemHeight", "fullHeight", "data", "children", "itemKey", "onSkipRender", "disabled", "virtual"]);
|
||||
|
||||
var mergedClassName = (0, _classnames.default)(prefixCls, className); // Render pure list if not set height or height is enough for all items
|
||||
|
||||
if (!isVirtual) {
|
||||
/**
|
||||
* Virtual list switch is works on component updated.
|
||||
* We should double check here if need cut the content.
|
||||
*/
|
||||
var shouldVirtual = (0, _itemUtil.requireVirtual)(height, itemHeight, data.length, virtual);
|
||||
return React.createElement(Component, Object.assign({
|
||||
style: height ? _objectSpread({}, style, _defineProperty({}, fullHeight ? 'height' : 'maxHeight', height), ScrollStyle) : style,
|
||||
className: mergedClassName
|
||||
}, restProps, {
|
||||
onScroll: this.onRawScroll,
|
||||
ref: this.listRef
|
||||
}), React.createElement(_Filler.default, {
|
||||
prefixCls: prefixCls,
|
||||
height: height
|
||||
}, this.renderChildren(shouldVirtual ? data.slice(0, Math.ceil(height / itemHeight)) : data, 0, children)));
|
||||
} // Use virtual list
|
||||
|
||||
|
||||
var mergedStyle = _objectSpread({}, style, {
|
||||
height: height
|
||||
}, ScrollStyle);
|
||||
|
||||
var _this$state6 = this.state,
|
||||
status = _this$state6.status,
|
||||
startIndex = _this$state6.startIndex,
|
||||
endIndex = _this$state6.endIndex,
|
||||
startItemTop = _this$state6.startItemTop;
|
||||
var contentHeight = itemCount * itemHeight * ITEM_SCALE_RATE;
|
||||
return React.createElement(Component, Object.assign({
|
||||
style: mergedStyle,
|
||||
className: mergedClassName
|
||||
}, restProps, {
|
||||
onScroll: this.onScroll,
|
||||
ref: this.listRef
|
||||
}), React.createElement(_Filler.default, {
|
||||
prefixCls: prefixCls,
|
||||
height: contentHeight,
|
||||
offset: status === 'MEASURE_DONE' ? startItemTop : 0
|
||||
}, this.renderChildren(data.slice(startIndex, endIndex + 1), startIndex, children)));
|
||||
}
|
||||
}], [{
|
||||
key: "getDerivedStateFromProps",
|
||||
value: function getDerivedStateFromProps(nextProps) {
|
||||
if (!nextProps.disabled) {
|
||||
return {
|
||||
itemCount: nextProps.data.length
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}]);
|
||||
|
||||
return List;
|
||||
}(React.Component);
|
||||
|
||||
List.defaultProps = {
|
||||
itemHeight: 15,
|
||||
data: []
|
||||
};
|
||||
var _default = List;
|
||||
exports.default = _default;
|
||||
2
web/node_modules/rc-virtual-list/lib/index.d.ts
generated
vendored
Normal file
2
web/node_modules/rc-virtual-list/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import List from './List';
|
||||
export default List;
|
||||
13
web/node_modules/rc-virtual-list/lib/index.js
generated
vendored
Normal file
13
web/node_modules/rc-virtual-list/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _List = _interopRequireDefault(require("./List"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var _default = _List.default;
|
||||
exports.default = _default;
|
||||
8
web/node_modules/rc-virtual-list/lib/mock.d.ts
generated
vendored
Normal file
8
web/node_modules/rc-virtual-list/lib/mock.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference types="react" />
|
||||
import OriginList from './List';
|
||||
declare class List<T> extends OriginList<T> {
|
||||
componentDidUpdate(): void;
|
||||
scrollTo: () => void;
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default List;
|
||||
106
web/node_modules/rc-virtual-list/lib/mock.js
generated
vendored
Normal file
106
web/node_modules/rc-virtual-list/lib/mock.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
|
||||
var _classnames = _interopRequireDefault(require("classnames"));
|
||||
|
||||
var _List = _interopRequireDefault(require("./List"));
|
||||
|
||||
var _Filler = _interopRequireDefault(require("./Filler"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var List = /*#__PURE__*/function (_OriginList) {
|
||||
_inherits(List, _OriginList);
|
||||
|
||||
function List() {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, List);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(List).apply(this, arguments));
|
||||
|
||||
_this.scrollTo = function () {// Do nothing sine this is a mock!
|
||||
};
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(List, [{
|
||||
key: "componentDidUpdate",
|
||||
value: function componentDidUpdate() {// Do nothing since this is a mock!
|
||||
}
|
||||
}, {
|
||||
key: "render",
|
||||
value: function render() {
|
||||
var _this$props = this.props,
|
||||
prefixCls = _this$props.prefixCls,
|
||||
style = _this$props.style,
|
||||
className = _this$props.className,
|
||||
_this$props$component = _this$props.component,
|
||||
Component = _this$props$component === void 0 ? 'div' : _this$props$component,
|
||||
fullHeight = _this$props.fullHeight,
|
||||
height = _this$props.height,
|
||||
itemHeight = _this$props.itemHeight,
|
||||
virtual = _this$props.virtual,
|
||||
data = _this$props.data,
|
||||
children = _this$props.children,
|
||||
itemKey = _this$props.itemKey,
|
||||
onSkipRender = _this$props.onSkipRender,
|
||||
restProps = _objectWithoutProperties(_this$props, ["prefixCls", "style", "className", "component", "fullHeight", "height", "itemHeight", "virtual", "data", "children", "itemKey", "onSkipRender"]);
|
||||
|
||||
var mergedClassName = (0, _classnames.default)(prefixCls, className);
|
||||
return React.createElement(Component, Object.assign({
|
||||
style: _objectSpread({}, style, {
|
||||
height: height
|
||||
}),
|
||||
className: mergedClassName
|
||||
}, restProps), React.createElement(_Filler.default, {
|
||||
prefixCls: prefixCls,
|
||||
height: height
|
||||
}, this.renderChildren(data, 0, children)));
|
||||
}
|
||||
}]);
|
||||
|
||||
return List;
|
||||
}(_List.default);
|
||||
|
||||
var _default = List;
|
||||
exports.default = _default;
|
||||
23
web/node_modules/rc-virtual-list/lib/utils/algorithmUtil.d.ts
generated
vendored
Normal file
23
web/node_modules/rc-virtual-list/lib/utils/algorithmUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Key } from './itemUtil';
|
||||
/**
|
||||
* Get index with specific start index one by one. e.g.
|
||||
* min: 3, max: 9, start: 6
|
||||
*
|
||||
* Return index is:
|
||||
* [0]: 6
|
||||
* [1]: 7
|
||||
* [2]: 5
|
||||
* [3]: 8
|
||||
* [4]: 4
|
||||
* [5]: 9
|
||||
* [6]: 3
|
||||
*/
|
||||
export declare function getIndexByStartLoc(min: number, max: number, start: number, index: number): number;
|
||||
/**
|
||||
* We assume that 2 list has only 1 item diff and others keeping the order.
|
||||
* So we can use dichotomy algorithm to find changed one.
|
||||
*/
|
||||
export declare function findListDiffIndex<T>(originList: T[], targetList: T[], getKey: (item: T) => Key): {
|
||||
index: number;
|
||||
multiple: boolean;
|
||||
} | null;
|
||||
99
web/node_modules/rc-virtual-list/lib/utils/algorithmUtil.js
generated
vendored
Normal file
99
web/node_modules/rc-virtual-list/lib/utils/algorithmUtil.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getIndexByStartLoc = getIndexByStartLoc;
|
||||
exports.findListDiffIndex = findListDiffIndex;
|
||||
|
||||
/**
|
||||
* Get index with specific start index one by one. e.g.
|
||||
* min: 3, max: 9, start: 6
|
||||
*
|
||||
* Return index is:
|
||||
* [0]: 6
|
||||
* [1]: 7
|
||||
* [2]: 5
|
||||
* [3]: 8
|
||||
* [4]: 4
|
||||
* [5]: 9
|
||||
* [6]: 3
|
||||
*/
|
||||
function getIndexByStartLoc(min, max, start, index) {
|
||||
var beforeCount = start - min;
|
||||
var afterCount = max - start;
|
||||
var balanceCount = Math.min(beforeCount, afterCount) * 2; // Balance
|
||||
|
||||
if (index <= balanceCount) {
|
||||
var stepIndex = Math.floor(index / 2);
|
||||
|
||||
if (index % 2) {
|
||||
return start + stepIndex + 1;
|
||||
}
|
||||
|
||||
return start - stepIndex;
|
||||
} // One is out of range
|
||||
|
||||
|
||||
if (beforeCount > afterCount) {
|
||||
return start - (index - afterCount);
|
||||
}
|
||||
|
||||
return start + (index - beforeCount);
|
||||
}
|
||||
/**
|
||||
* We assume that 2 list has only 1 item diff and others keeping the order.
|
||||
* So we can use dichotomy algorithm to find changed one.
|
||||
*/
|
||||
|
||||
|
||||
function findListDiffIndex(originList, targetList, getKey) {
|
||||
var originLen = originList.length;
|
||||
var targetLen = targetList.length;
|
||||
var shortList;
|
||||
var longList;
|
||||
|
||||
if (originLen === 0 && targetLen === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (originLen < targetLen) {
|
||||
shortList = originList;
|
||||
longList = targetList;
|
||||
} else {
|
||||
shortList = targetList;
|
||||
longList = originList;
|
||||
}
|
||||
|
||||
var notExistKey = {
|
||||
__EMPTY_ITEM__: true
|
||||
};
|
||||
|
||||
function getItemKey(item) {
|
||||
if (item !== undefined) {
|
||||
return getKey(item);
|
||||
}
|
||||
|
||||
return notExistKey;
|
||||
} // Loop to find diff one
|
||||
|
||||
|
||||
var diffIndex = null;
|
||||
var multiple = Math.abs(originLen - targetLen) !== 1;
|
||||
|
||||
for (var i = 0; i < longList.length; i += 1) {
|
||||
var shortKey = getItemKey(shortList[i]);
|
||||
var longKey = getItemKey(longList[i]);
|
||||
|
||||
if (shortKey !== longKey) {
|
||||
diffIndex = i;
|
||||
multiple = multiple || shortKey !== getItemKey(longList[i + 1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return diffIndex === null ? null : {
|
||||
index: diffIndex,
|
||||
multiple: multiple
|
||||
};
|
||||
}
|
||||
64
web/node_modules/rc-virtual-list/lib/utils/itemUtil.d.ts
generated
vendored
Normal file
64
web/node_modules/rc-virtual-list/lib/utils/itemUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Our algorithm have additional one ghost item
|
||||
* whose index as `data.length` to simplify the calculation
|
||||
*/
|
||||
export declare const GHOST_ITEM_KEY = "__rc_ghost_item__";
|
||||
export declare type Key = string | number;
|
||||
/**
|
||||
* Safari has the elasticity effect which provides negative `scrollTop` value.
|
||||
* We should ignore it since will make scroll animation shake.
|
||||
*/
|
||||
export declare function alignScrollTop(scrollTop: number, scrollRange: number): number;
|
||||
export declare function getScrollPercentage({ scrollTop, scrollHeight, clientHeight, }: {
|
||||
scrollTop: number;
|
||||
scrollHeight: number;
|
||||
clientHeight: number;
|
||||
}): number;
|
||||
export declare function getElementScrollPercentage(element: HTMLElement | null): number;
|
||||
/**
|
||||
* Get node `offsetHeight`. We prefer node is a dom element directly.
|
||||
* But if not provided, downgrade to `findDOMNode` to get the real dom element.
|
||||
*/
|
||||
export declare function getNodeHeight(node: HTMLElement): number;
|
||||
/**
|
||||
* Get display items start, end, located item index. This is pure math calculation
|
||||
*/
|
||||
export declare function getRangeIndex(scrollPtg: number, itemCount: number, visibleCount: number): {
|
||||
itemIndex: number;
|
||||
itemOffsetPtg: number;
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
};
|
||||
interface ItemTopConfig {
|
||||
itemIndex: number;
|
||||
itemElementHeights: {
|
||||
[key: string]: number;
|
||||
};
|
||||
itemOffsetPtg: number;
|
||||
scrollTop: number;
|
||||
scrollPtg: number;
|
||||
clientHeight: number;
|
||||
getItemKey: (index: number) => Key;
|
||||
}
|
||||
/**
|
||||
* Calculate the located item related top with current window height
|
||||
*/
|
||||
export declare function getItemRelativeTop({ itemIndex, itemOffsetPtg, itemElementHeights, scrollPtg, clientHeight, getItemKey, }: Omit<ItemTopConfig, 'scrollTop'>): number;
|
||||
/**
|
||||
* Calculate the located item absolute top with whole scroll height
|
||||
*/
|
||||
export declare function getItemAbsoluteTop({ scrollTop, ...rest }: ItemTopConfig): number;
|
||||
interface CompareItemConfig {
|
||||
locatedItemRelativeTop: number;
|
||||
locatedItemIndex: number;
|
||||
compareItemIndex: number;
|
||||
getItemKey: (index: number) => Key;
|
||||
startIndex: number;
|
||||
endIndex: number;
|
||||
itemElementHeights: {
|
||||
[key: string]: number;
|
||||
};
|
||||
}
|
||||
export declare function getCompareItemRelativeTop({ locatedItemRelativeTop, locatedItemIndex, compareItemIndex, startIndex, endIndex, getItemKey, itemElementHeights, }: CompareItemConfig): number;
|
||||
export declare function requireVirtual(height: number, itemHeight: number, count: number, virtual: boolean): boolean;
|
||||
export {};
|
||||
187
web/node_modules/rc-virtual-list/lib/utils/itemUtil.js
generated
vendored
Normal file
187
web/node_modules/rc-virtual-list/lib/utils/itemUtil.js
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.alignScrollTop = alignScrollTop;
|
||||
exports.getScrollPercentage = getScrollPercentage;
|
||||
exports.getElementScrollPercentage = getElementScrollPercentage;
|
||||
exports.getNodeHeight = getNodeHeight;
|
||||
exports.getRangeIndex = getRangeIndex;
|
||||
exports.getItemRelativeTop = getItemRelativeTop;
|
||||
exports.getItemAbsoluteTop = getItemAbsoluteTop;
|
||||
exports.getCompareItemRelativeTop = getCompareItemRelativeTop;
|
||||
exports.requireVirtual = requireVirtual;
|
||||
exports.GHOST_ITEM_KEY = void 0;
|
||||
|
||||
var _findDOMNode = _interopRequireDefault(require("rc-util/lib/Dom/findDOMNode"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
/**
|
||||
* Our algorithm have additional one ghost item
|
||||
* whose index as `data.length` to simplify the calculation
|
||||
*/
|
||||
var GHOST_ITEM_KEY = '__rc_ghost_item__';
|
||||
/**
|
||||
* Get location item and its align percentage with the scroll percentage.
|
||||
* We should measure current scroll position to decide which item is the location item.
|
||||
* And then fill the top count and bottom count with the base of location item.
|
||||
*
|
||||
* `total` should be the real count instead of `total - 1` in calculation.
|
||||
*/
|
||||
|
||||
exports.GHOST_ITEM_KEY = GHOST_ITEM_KEY;
|
||||
|
||||
function getLocationItem(scrollPtg, total) {
|
||||
var itemIndex = Math.floor(scrollPtg * total);
|
||||
var itemTopPtg = itemIndex / total;
|
||||
var itemBottomPtg = (itemIndex + 1) / total;
|
||||
var itemOffsetPtg = (scrollPtg - itemTopPtg) / (itemBottomPtg - itemTopPtg);
|
||||
return {
|
||||
index: itemIndex,
|
||||
offsetPtg: itemOffsetPtg
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Safari has the elasticity effect which provides negative `scrollTop` value.
|
||||
* We should ignore it since will make scroll animation shake.
|
||||
*/
|
||||
|
||||
|
||||
function alignScrollTop(scrollTop, scrollRange) {
|
||||
if (scrollTop < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (scrollTop >= scrollRange) {
|
||||
return scrollRange;
|
||||
}
|
||||
|
||||
return scrollTop;
|
||||
}
|
||||
|
||||
function getScrollPercentage(_ref) {
|
||||
var scrollTop = _ref.scrollTop,
|
||||
scrollHeight = _ref.scrollHeight,
|
||||
clientHeight = _ref.clientHeight;
|
||||
|
||||
if (scrollHeight <= clientHeight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var scrollRange = scrollHeight - clientHeight;
|
||||
var alignedScrollTop = alignScrollTop(scrollTop, scrollRange);
|
||||
var scrollTopPtg = alignedScrollTop / scrollRange;
|
||||
return scrollTopPtg;
|
||||
}
|
||||
|
||||
function getElementScrollPercentage(element) {
|
||||
if (!element) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getScrollPercentage(element);
|
||||
}
|
||||
/**
|
||||
* Get node `offsetHeight`. We prefer node is a dom element directly.
|
||||
* But if not provided, downgrade to `findDOMNode` to get the real dom element.
|
||||
*/
|
||||
|
||||
|
||||
function getNodeHeight(node) {
|
||||
var element = (0, _findDOMNode.default)(node);
|
||||
return element ? element.offsetHeight : 0;
|
||||
}
|
||||
/**
|
||||
* Get display items start, end, located item index. This is pure math calculation
|
||||
*/
|
||||
|
||||
|
||||
function getRangeIndex(scrollPtg, itemCount, visibleCount) {
|
||||
var _getLocationItem = getLocationItem(scrollPtg, itemCount),
|
||||
index = _getLocationItem.index,
|
||||
offsetPtg = _getLocationItem.offsetPtg;
|
||||
|
||||
var beforeCount = Math.ceil(scrollPtg * visibleCount);
|
||||
var afterCount = Math.ceil((1 - scrollPtg) * visibleCount);
|
||||
return {
|
||||
itemIndex: index,
|
||||
itemOffsetPtg: offsetPtg,
|
||||
startIndex: Math.max(0, index - beforeCount),
|
||||
endIndex: Math.min(itemCount - 1, index + afterCount)
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Calculate the located item related top with current window height
|
||||
*/
|
||||
|
||||
|
||||
function getItemRelativeTop(_ref2) {
|
||||
var itemIndex = _ref2.itemIndex,
|
||||
itemOffsetPtg = _ref2.itemOffsetPtg,
|
||||
itemElementHeights = _ref2.itemElementHeights,
|
||||
scrollPtg = _ref2.scrollPtg,
|
||||
clientHeight = _ref2.clientHeight,
|
||||
getItemKey = _ref2.getItemKey;
|
||||
var locatedItemHeight = itemElementHeights[getItemKey(itemIndex)] || 0;
|
||||
var locatedItemTop = scrollPtg * clientHeight;
|
||||
var locatedItemOffset = itemOffsetPtg * locatedItemHeight;
|
||||
return Math.floor(locatedItemTop - locatedItemOffset);
|
||||
}
|
||||
/**
|
||||
* Calculate the located item absolute top with whole scroll height
|
||||
*/
|
||||
|
||||
|
||||
function getItemAbsoluteTop(_ref3) {
|
||||
var scrollTop = _ref3.scrollTop,
|
||||
rest = _objectWithoutProperties(_ref3, ["scrollTop"]);
|
||||
|
||||
return scrollTop + getItemRelativeTop(rest);
|
||||
}
|
||||
|
||||
function getCompareItemRelativeTop(_ref4) {
|
||||
var locatedItemRelativeTop = _ref4.locatedItemRelativeTop,
|
||||
locatedItemIndex = _ref4.locatedItemIndex,
|
||||
compareItemIndex = _ref4.compareItemIndex,
|
||||
startIndex = _ref4.startIndex,
|
||||
endIndex = _ref4.endIndex,
|
||||
getItemKey = _ref4.getItemKey,
|
||||
itemElementHeights = _ref4.itemElementHeights;
|
||||
var originCompareItemTop = locatedItemRelativeTop;
|
||||
var compareItemKey = getItemKey(compareItemIndex);
|
||||
|
||||
if (compareItemIndex <= locatedItemIndex) {
|
||||
for (var index = locatedItemIndex; index >= startIndex; index -= 1) {
|
||||
var key = getItemKey(index);
|
||||
|
||||
if (key === compareItemKey) {
|
||||
break;
|
||||
}
|
||||
|
||||
var prevItemKey = getItemKey(index - 1);
|
||||
originCompareItemTop -= itemElementHeights[prevItemKey] || 0;
|
||||
}
|
||||
} else {
|
||||
for (var _index = locatedItemIndex; _index <= endIndex; _index += 1) {
|
||||
var _key = getItemKey(_index);
|
||||
|
||||
if (_key === compareItemKey) {
|
||||
break;
|
||||
}
|
||||
|
||||
originCompareItemTop += itemElementHeights[_key] || 0;
|
||||
}
|
||||
}
|
||||
|
||||
return originCompareItemTop;
|
||||
}
|
||||
|
||||
function requireVirtual(height, itemHeight, count, virtual) {
|
||||
return virtual !== false && typeof height === 'number' && count * itemHeight > height;
|
||||
}
|
||||
94
web/node_modules/rc-virtual-list/package.json
generated
vendored
Normal file
94
web/node_modules/rc-virtual-list/package.json
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"_from": "rc-virtual-list@^1.1.0",
|
||||
"_id": "rc-virtual-list@1.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-+WwxrtmBta7vcPCty7MtgilBmbxSGwN28Y8o+MG3GkHZccV0tXT+PLnAB+5WOjhhH10iFq+pzviRcXgcZ1x4OA==",
|
||||
"_location": "/rc-virtual-list",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "rc-virtual-list@^1.1.0",
|
||||
"name": "rc-virtual-list",
|
||||
"escapedName": "rc-virtual-list",
|
||||
"rawSpec": "^1.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/antd",
|
||||
"/rc-select",
|
||||
"/rc-tree"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/rc-virtual-list/-/rc-virtual-list-1.1.2.tgz",
|
||||
"_shasum": "fe3da1136b3ce612b37891fc2cf43447c8a40b2f",
|
||||
"_spec": "rc-virtual-list@^1.1.0",
|
||||
"_where": "/Users/thilina/TestProjects/icehrm-pro/web/node_modules/antd",
|
||||
"author": {
|
||||
"name": "smith3816@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/react-component/virtual-list/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"classnames": "^2.2.6",
|
||||
"raf": "^3.4.1",
|
||||
"rc-util": "^4.8.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "React Virtual List Component",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^25.1.3",
|
||||
"@types/react": "^16.8.19",
|
||||
"@types/react-dom": "^16.8.4",
|
||||
"@types/warning": "^3.0.0",
|
||||
"cross-env": "^5.2.0",
|
||||
"enzyme": "^3.1.0",
|
||||
"enzyme-adapter-react-16": "^1.0.2",
|
||||
"enzyme-to-json": "^3.1.4",
|
||||
"father": "^2.13.2",
|
||||
"np": "^5.0.3",
|
||||
"rc-animate": "^2.9.1",
|
||||
"react": "^v16.9.0-alpha.0",
|
||||
"react-dom": "^v16.9.0-alpha.0",
|
||||
"typescript": "^3.5.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.x"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"es",
|
||||
"dist",
|
||||
"assets/*.css"
|
||||
],
|
||||
"homepage": "https://github.com/react-component/virtual-list",
|
||||
"keywords": [
|
||||
"react",
|
||||
"react-component",
|
||||
"virtual-list"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/index",
|
||||
"module": "./es/index",
|
||||
"name": "rc-virtual-list",
|
||||
"peerDependencies": {
|
||||
"react": "*",
|
||||
"react-dom": "*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/react-component/virtual-list.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "father doc build --storybook",
|
||||
"compile": "father build",
|
||||
"lint": "eslint src/ --ext .tsx,.ts",
|
||||
"now-build": "npm run build",
|
||||
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",
|
||||
"start": "cross-env NODE_ENV=development father doc dev --storybook",
|
||||
"test": "father test"
|
||||
},
|
||||
"version": "1.1.2"
|
||||
}
|
||||
Reference in New Issue
Block a user