@pixui-dev/pxw 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pxw.js +217 -0
- package/bin/wpbuild.js +10 -0
- package/config/default.conf +21 -0
- package/config/devops.js +358 -0
- package/config/h5es.js +10 -0
- package/config/index.html +181 -0
- package/config/pfbs.js +207 -0
- package/config/testhelp.js +0 -0
- package/config/util.js +140 -0
- package/config/webpack.js +291 -0
- package/lib/assets/border.png +0 -0
- package/lib/assets/check.html +62 -0
- package/lib/assets/pixui.png +0 -0
- package/lib/assets/preact.js +4354 -0
- package/lib/assets/preact.png +0 -0
- package/lib/check/main.less +63 -0
- package/lib/check/main.tsx +41 -0
- package/lib/check/tool.js +3 -0
- package/lib/check/util.tsx +110 -0
- package/lib/grpc-web/dist/ChunkParser.js +117 -0
- package/lib/grpc-web/dist/ChunkParser.js.map +1 -0
- package/lib/grpc-web/dist/Code.js +58 -0
- package/lib/grpc-web/dist/Code.js.map +1 -0
- package/lib/grpc-web/dist/client.js +299 -0
- package/lib/grpc-web/dist/client.js.map +1 -0
- package/lib/grpc-web/dist/debug.js +16 -0
- package/lib/grpc-web/dist/debug.js.map +1 -0
- package/lib/grpc-web/dist/detach.js +7 -0
- package/lib/grpc-web/dist/detach.js.map +1 -0
- package/lib/grpc-web/dist/index.js +29 -0
- package/lib/grpc-web/dist/index.js.map +1 -0
- package/lib/grpc-web/dist/invoke.js +32 -0
- package/lib/grpc-web/dist/invoke.js.map +1 -0
- package/lib/grpc-web/dist/message.js +3 -0
- package/lib/grpc-web/dist/message.js.map +1 -0
- package/lib/grpc-web/dist/metadata.js +5 -0
- package/lib/grpc-web/dist/metadata.js.map +1 -0
- package/lib/grpc-web/dist/service.js +3 -0
- package/lib/grpc-web/dist/service.js.map +1 -0
- package/lib/grpc-web/dist/transports/Transport.js +15 -0
- package/lib/grpc-web/dist/transports/Transport.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/fetch.js +117 -0
- package/lib/grpc-web/dist/transports/http/fetch.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/http.js +15 -0
- package/lib/grpc-web/dist/transports/http/http.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/xhr.js +136 -0
- package/lib/grpc-web/dist/transports/http/xhr.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -0
- package/lib/grpc-web/dist/transports/http/xhrUtil.js.map +1 -0
- package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -0
- package/lib/grpc-web/dist/transports/websocket/websocket.js.map +1 -0
- package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -0
- package/lib/grpc-web/dist/typings/Code.d.ts +20 -0
- package/lib/grpc-web/dist/typings/client.d.ts +25 -0
- package/lib/grpc-web/dist/typings/debug.d.ts +1 -0
- package/lib/grpc-web/dist/typings/detach.d.ts +1 -0
- package/lib/grpc-web/dist/typings/index.d.ts +45 -0
- package/lib/grpc-web/dist/typings/invoke.d.ts +20 -0
- package/lib/grpc-web/dist/typings/message.d.ts +8 -0
- package/lib/grpc-web/dist/typings/metadata.d.ts +2 -0
- package/lib/grpc-web/dist/typings/service.d.ts +16 -0
- package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -0
- package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -0
- package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -0
- package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -0
- package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -0
- package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -0
- package/lib/grpc-web/dist/typings/unary.d.ts +23 -0
- package/lib/grpc-web/dist/typings/util.d.ts +2 -0
- package/lib/grpc-web/dist/unary.js +44 -0
- package/lib/grpc-web/dist/unary.js.map +1 -0
- package/lib/grpc-web/dist/util.js +11 -0
- package/lib/grpc-web/dist/util.js.map +1 -0
- package/lib/grpcTransport/PixHttp2Transport.ts +107 -0
- package/lib/grpcTransport/PixLuaTransport.ts +82 -0
- package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -0
- package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -0
- package/lib/pi_component/tinyList/tinyList.js +483 -0
- package/lib/pi_component/tinyList/tinyList.tsx +517 -0
- package/lib/pika-svelte/compiler.js +29829 -0
- package/lib/pika-svelte/easing/index.js +158 -0
- package/lib/pika-svelte/index.js +72 -0
- package/lib/pika-svelte/internal/index.js +1926 -0
- package/lib/pika-svelte/motion/index.js +210 -0
- package/lib/pika-svelte/package.json +145 -0
- package/lib/pika-svelte/register.js +57 -0
- package/lib/pika-svelte/rollup.config.js +126 -0
- package/lib/pika-svelte/store/index.js +123 -0
- package/lib/pika-svelte/transition/index.js +185 -0
- package/lib/preact-router.js +395 -0
- package/lib/preact.js +4355 -0
- package/lib/preact.tq.js +4385 -0
- package/lib/react-window/src/FixedSizeGrid.js +172 -0
- package/lib/react-window/src/FixedSizeList.js +91 -0
- package/lib/react-window/src/VariableSizeGrid.js +329 -0
- package/lib/react-window/src/VariableSizeList.js +231 -0
- package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -0
- package/lib/react-window/src/__tests__/FixedSizeList.js +749 -0
- package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -0
- package/lib/react-window/src/__tests__/VariableSizeList.js +345 -0
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -0
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -0
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -0
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -0
- package/lib/react-window/src/__tests__/areEqual.js +28 -0
- package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -0
- package/lib/react-window/src/areEqual.js +13 -0
- package/lib/react-window/src/createGridComponent.js +657 -0
- package/lib/react-window/src/createListComponent.js +574 -0
- package/lib/react-window/src/domHelpers.js +69 -0
- package/lib/react-window/src/index.js +9 -0
- package/lib/react-window/src/shallowDiffers.js +17 -0
- package/lib/react-window/src/shouldComponentUpdate.js +11 -0
- package/lib/react-window/src/test.js.flow +382 -0
- package/lib/react-window/src/timer.js +36 -0
- package/lib/svelte-tab/Tab.svelte +31 -0
- package/lib/svelte-tab/TabList.svelte +10 -0
- package/lib/svelte-tab/TabPanel.svelte +13 -0
- package/lib/svelte-tab/Tabs.svelte +68 -0
- package/lib/svelte-tab/tabs.js +4 -0
- package/lib/types/css.d.ts +7476 -0
- package/lib/types/dom.ts +17 -0
- package/lib/types/ext.d.ts +81 -0
- package/lib/types/internal.d.ts +94 -0
- package/lib/types/jsx.d.ts +309 -0
- package/lib/types/preact.d.ts +340 -0
- package/package.json +111 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import memoizeOne from 'memoize-one';
|
|
4
|
+
import { createElement, PureComponent } from 'react';
|
|
5
|
+
import { cancelTimeout, requestTimeout } from './timer';
|
|
6
|
+
import { getRTLOffsetType } from './domHelpers';
|
|
7
|
+
|
|
8
|
+
import type { TimeoutID } from './timer';
|
|
9
|
+
|
|
10
|
+
export type ScrollToAlign = 'auto' | 'smart' | 'center' | 'start' | 'end';
|
|
11
|
+
|
|
12
|
+
type itemSize = number | ((index: number) => number);
|
|
13
|
+
// TODO Deprecate directions "horizontal" and "vertical"
|
|
14
|
+
type Direction = 'ltr' | 'rtl' | 'horizontal' | 'vertical';
|
|
15
|
+
type Layout = 'horizontal' | 'vertical';
|
|
16
|
+
|
|
17
|
+
type RenderComponentProps<T> = {|
|
|
18
|
+
data: T,
|
|
19
|
+
index: number,
|
|
20
|
+
isScrolling?: boolean,
|
|
21
|
+
style: Object,
|
|
22
|
+
|};
|
|
23
|
+
type RenderComponent<T> = React$ComponentType<$Shape<RenderComponentProps<T>>>;
|
|
24
|
+
|
|
25
|
+
type ScrollDirection = 'forward' | 'backward';
|
|
26
|
+
|
|
27
|
+
type onItemsRenderedCallback = ({
|
|
28
|
+
overscanStartIndex: number,
|
|
29
|
+
overscanStopIndex: number,
|
|
30
|
+
visibleStartIndex: number,
|
|
31
|
+
visibleStopIndex: number,
|
|
32
|
+
}) => void;
|
|
33
|
+
type onScrollCallback = ({
|
|
34
|
+
scrollDirection: ScrollDirection,
|
|
35
|
+
scrollOffset: number,
|
|
36
|
+
scrollUpdateWasRequested: boolean,
|
|
37
|
+
}) => void;
|
|
38
|
+
|
|
39
|
+
type ScrollEvent = SyntheticEvent<HTMLDivElement>;
|
|
40
|
+
type ItemStyleCache = { [index: number]: Object };
|
|
41
|
+
|
|
42
|
+
type OuterProps = {|
|
|
43
|
+
children: React$Node,
|
|
44
|
+
className: string | void,
|
|
45
|
+
onScroll: (ScrollEvent) => void,
|
|
46
|
+
style: {
|
|
47
|
+
[string]: mixed,
|
|
48
|
+
},
|
|
49
|
+
|};
|
|
50
|
+
|
|
51
|
+
type InnerProps = {|
|
|
52
|
+
children: React$Node,
|
|
53
|
+
style: {
|
|
54
|
+
[string]: mixed,
|
|
55
|
+
},
|
|
56
|
+
|};
|
|
57
|
+
|
|
58
|
+
export type Props<T> = {|
|
|
59
|
+
children: RenderComponent<T>,
|
|
60
|
+
className?: string,
|
|
61
|
+
direction: Direction,
|
|
62
|
+
height: number | string,
|
|
63
|
+
initialScrollOffset?: number,
|
|
64
|
+
innerRef?: any,
|
|
65
|
+
innerElementType?: string | React$AbstractComponent<InnerProps, any>,
|
|
66
|
+
innerTagName?: string, // deprecated
|
|
67
|
+
itemCount: number,
|
|
68
|
+
itemData: T,
|
|
69
|
+
itemKey?: (index: number, data: T) => any,
|
|
70
|
+
itemSize: itemSize,
|
|
71
|
+
layout: Layout,
|
|
72
|
+
onItemsRendered?: onItemsRenderedCallback,
|
|
73
|
+
onScroll?: onScrollCallback,
|
|
74
|
+
outerRef?: any,
|
|
75
|
+
outerElementType?: string | React$AbstractComponent<OuterProps, any>,
|
|
76
|
+
outerTagName?: string, // deprecated
|
|
77
|
+
overscanCount: number,
|
|
78
|
+
style?: Object,
|
|
79
|
+
useIsScrolling: boolean,
|
|
80
|
+
width: number | string,
|
|
81
|
+
|};
|
|
82
|
+
|
|
83
|
+
type State = {|
|
|
84
|
+
instance: any,
|
|
85
|
+
isScrolling: boolean,
|
|
86
|
+
scrollDirection: ScrollDirection,
|
|
87
|
+
scrollOffset: number,
|
|
88
|
+
scrollUpdateWasRequested: boolean,
|
|
89
|
+
|};
|
|
90
|
+
|
|
91
|
+
type GetItemOffset = (props: Props<any>, index: number, instanceProps: any) => number;
|
|
92
|
+
type GetItemSize = (props: Props<any>, index: number, instanceProps: any) => number;
|
|
93
|
+
type GetEstimatedTotalSize = (props: Props<any>, instanceProps: any) => number;
|
|
94
|
+
type GetOffsetForIndexAndAlignment = (props: Props<any>, index: number, align: ScrollToAlign, scrollOffset: number, instanceProps: any) => number;
|
|
95
|
+
type GetStartIndexForOffset = (props: Props<any>, offset: number, instanceProps: any) => number;
|
|
96
|
+
type GetStopIndexForStartIndex = (props: Props<any>, startIndex: number, scrollOffset: number, instanceProps: any) => number;
|
|
97
|
+
type InitInstanceProps = (props: Props<any>, instance: any) => any;
|
|
98
|
+
type ValidateProps = (props: Props<any>) => void;
|
|
99
|
+
|
|
100
|
+
const IS_SCROLLING_DEBOUNCE_INTERVAL = 150;
|
|
101
|
+
|
|
102
|
+
const defaultItemKey = (index: number, data: any) => index;
|
|
103
|
+
|
|
104
|
+
// In DEV mode, this Set helps us only log a warning once per component instance.
|
|
105
|
+
// This avoids spamming the console every time a render happens.
|
|
106
|
+
let devWarningsDirection = null;
|
|
107
|
+
let devWarningsTagName = null;
|
|
108
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
109
|
+
if (typeof window !== 'undefined' && typeof window.WeakSet !== 'undefined') {
|
|
110
|
+
devWarningsDirection = new WeakSet();
|
|
111
|
+
devWarningsTagName = new WeakSet();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default function createListComponent({
|
|
116
|
+
getItemOffset,
|
|
117
|
+
getEstimatedTotalSize,
|
|
118
|
+
getItemSize,
|
|
119
|
+
getOffsetForIndexAndAlignment,
|
|
120
|
+
getStartIndexForOffset,
|
|
121
|
+
getStopIndexForStartIndex,
|
|
122
|
+
initInstanceProps,
|
|
123
|
+
shouldResetStyleCacheOnItemSizeChange,
|
|
124
|
+
validateProps,
|
|
125
|
+
}: {|
|
|
126
|
+
getItemOffset: GetItemOffset,
|
|
127
|
+
getEstimatedTotalSize: GetEstimatedTotalSize,
|
|
128
|
+
getItemSize: GetItemSize,
|
|
129
|
+
getOffsetForIndexAndAlignment: GetOffsetForIndexAndAlignment,
|
|
130
|
+
getStartIndexForOffset: GetStartIndexForOffset,
|
|
131
|
+
getStopIndexForStartIndex: GetStopIndexForStartIndex,
|
|
132
|
+
initInstanceProps: InitInstanceProps,
|
|
133
|
+
shouldResetStyleCacheOnItemSizeChange: boolean,
|
|
134
|
+
validateProps: ValidateProps,
|
|
135
|
+
|}) {
|
|
136
|
+
return class List<T> extends PureComponent<Props<T>, State> {
|
|
137
|
+
_instanceProps: any = initInstanceProps(this.props, this);
|
|
138
|
+
_outerRef: ?HTMLDivElement;
|
|
139
|
+
_resetIsScrollingTimeoutId: TimeoutID | null = null;
|
|
140
|
+
|
|
141
|
+
static defaultProps = {
|
|
142
|
+
direction: 'ltr',
|
|
143
|
+
itemData: undefined,
|
|
144
|
+
layout: 'vertical',
|
|
145
|
+
overscanCount: 2,
|
|
146
|
+
useIsScrolling: false,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
state: State = {
|
|
150
|
+
instance: this,
|
|
151
|
+
isScrolling: false,
|
|
152
|
+
scrollDirection: 'forward',
|
|
153
|
+
scrollOffset: typeof this.props.initialScrollOffset === 'number' ? this.props.initialScrollOffset : 0,
|
|
154
|
+
scrollUpdateWasRequested: false,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Always use explicit constructor for React components.
|
|
158
|
+
// It produces less code after transpilation. (#26)
|
|
159
|
+
// eslint-disable-next-line no-useless-constructor
|
|
160
|
+
constructor(props: Props<T>) {
|
|
161
|
+
super(props);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
static getDerivedStateFromProps(nextProps: Props<T>, prevState: State): $Shape<State> | null {
|
|
165
|
+
validateSharedProps(nextProps, prevState);
|
|
166
|
+
validateProps(nextProps);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
scrollTo(scrollOffset: number): void {
|
|
171
|
+
scrollOffset = Math.max(0, scrollOffset);
|
|
172
|
+
|
|
173
|
+
this.setState((prevState) => {
|
|
174
|
+
if (prevState.scrollOffset === scrollOffset) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
scrollDirection: prevState.scrollOffset < scrollOffset ? 'forward' : 'backward',
|
|
179
|
+
scrollOffset: scrollOffset,
|
|
180
|
+
scrollUpdateWasRequested: true,
|
|
181
|
+
};
|
|
182
|
+
}, this._resetIsScrollingDebounced);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
scrollToItem(index: number, align: ScrollToAlign = 'auto'): void {
|
|
186
|
+
const { itemCount } = this.props;
|
|
187
|
+
const { scrollOffset } = this.state;
|
|
188
|
+
|
|
189
|
+
index = Math.max(0, Math.min(index, itemCount - 1));
|
|
190
|
+
|
|
191
|
+
this.scrollTo(getOffsetForIndexAndAlignment(this.props, index, align, scrollOffset, this._instanceProps));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
componentDidMount() {
|
|
195
|
+
const { direction, initialScrollOffset, layout } = this.props;
|
|
196
|
+
|
|
197
|
+
if (typeof initialScrollOffset === 'number' && this._outerRef != null) {
|
|
198
|
+
const outerRef = ((this._outerRef: any): HTMLElement);
|
|
199
|
+
// TODO Deprecate direction "horizontal"
|
|
200
|
+
if (direction === 'horizontal' || layout === 'horizontal') {
|
|
201
|
+
outerRef.scrollLeft = initialScrollOffset;
|
|
202
|
+
} else {
|
|
203
|
+
outerRef.scrollTop = initialScrollOffset;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this._callPropsCallbacks();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
componentDidUpdate() {
|
|
211
|
+
const { direction, layout } = this.props;
|
|
212
|
+
const { scrollOffset, scrollUpdateWasRequested } = this.state;
|
|
213
|
+
|
|
214
|
+
if (scrollUpdateWasRequested && this._outerRef != null) {
|
|
215
|
+
const outerRef = ((this._outerRef: any): HTMLElement);
|
|
216
|
+
|
|
217
|
+
// TODO Deprecate direction "horizontal"
|
|
218
|
+
if (direction === 'horizontal' || layout === 'horizontal') {
|
|
219
|
+
if (direction === 'rtl') {
|
|
220
|
+
// TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
|
|
221
|
+
// This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
|
|
222
|
+
// So we need to determine which browser behavior we're dealing with, and mimic it.
|
|
223
|
+
switch (getRTLOffsetType()) {
|
|
224
|
+
case 'negative':
|
|
225
|
+
outerRef.scrollLeft = -scrollOffset;
|
|
226
|
+
break;
|
|
227
|
+
case 'positive-ascending':
|
|
228
|
+
outerRef.scrollLeft = scrollOffset;
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
const { clientWidth, scrollWidth } = outerRef;
|
|
232
|
+
outerRef.scrollLeft = scrollWidth - clientWidth - scrollOffset;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
outerRef.scrollLeft = scrollOffset;
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
outerRef.scrollTop = scrollOffset;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
this._callPropsCallbacks();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
componentWillUnmount() {
|
|
247
|
+
if (this._resetIsScrollingTimeoutId !== null) {
|
|
248
|
+
cancelTimeout(this._resetIsScrollingTimeoutId);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
render() {
|
|
253
|
+
const {
|
|
254
|
+
children,
|
|
255
|
+
className,
|
|
256
|
+
direction,
|
|
257
|
+
height,
|
|
258
|
+
innerRef,
|
|
259
|
+
innerElementType,
|
|
260
|
+
innerTagName,
|
|
261
|
+
itemCount,
|
|
262
|
+
itemData,
|
|
263
|
+
itemKey = defaultItemKey,
|
|
264
|
+
layout,
|
|
265
|
+
outerElementType,
|
|
266
|
+
outerTagName,
|
|
267
|
+
style,
|
|
268
|
+
useIsScrolling,
|
|
269
|
+
width,
|
|
270
|
+
} = this.props;
|
|
271
|
+
const { isScrolling } = this.state;
|
|
272
|
+
|
|
273
|
+
// TODO Deprecate direction "horizontal"
|
|
274
|
+
const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
|
|
275
|
+
|
|
276
|
+
const onScroll = isHorizontal ? this._onScrollHorizontal : this._onScrollVertical;
|
|
277
|
+
|
|
278
|
+
const [startIndex, stopIndex] = this._getRangeToRender();
|
|
279
|
+
|
|
280
|
+
const items = [];
|
|
281
|
+
if (itemCount > 0) {
|
|
282
|
+
for (let index = startIndex; index <= stopIndex; index++) {
|
|
283
|
+
items.push(
|
|
284
|
+
createElement(children, {
|
|
285
|
+
data: itemData,
|
|
286
|
+
key: itemKey(index, itemData),
|
|
287
|
+
index,
|
|
288
|
+
isScrolling: useIsScrolling ? isScrolling : undefined,
|
|
289
|
+
style: this._getItemStyle(index),
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Read this value AFTER items have been created,
|
|
296
|
+
// So their actual sizes (if variable) are taken into consideration.
|
|
297
|
+
const estimatedTotalSize = getEstimatedTotalSize(this.props, this._instanceProps);
|
|
298
|
+
|
|
299
|
+
return createElement(
|
|
300
|
+
outerElementType || outerTagName || 'div',
|
|
301
|
+
{
|
|
302
|
+
className,
|
|
303
|
+
onScroll,
|
|
304
|
+
ref: this._outerRefSetter,
|
|
305
|
+
style: {
|
|
306
|
+
display: 'flex',
|
|
307
|
+
flexDirection: 'column',
|
|
308
|
+
position: 'relative',
|
|
309
|
+
height,
|
|
310
|
+
width,
|
|
311
|
+
overflow: 'scroll', //'auto',
|
|
312
|
+
WebkitOverflowScrolling: 'touch',
|
|
313
|
+
willChange: 'transform',
|
|
314
|
+
direction,
|
|
315
|
+
...style,
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
createElement(innerElementType || innerTagName || 'div', {
|
|
319
|
+
children: items,
|
|
320
|
+
ref: innerRef,
|
|
321
|
+
style: {
|
|
322
|
+
flexShrink: 0,
|
|
323
|
+
height: isHorizontal ? '100%' : estimatedTotalSize,
|
|
324
|
+
pointerEvents: isScrolling ? 'none' : undefined,
|
|
325
|
+
width: isHorizontal ? estimatedTotalSize : '100%',
|
|
326
|
+
},
|
|
327
|
+
}),
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
_callOnItemsRendered: (overscanStartIndex: number, overscanStopIndex: number, visibleStartIndex: number, visibleStopIndex: number) => void;
|
|
332
|
+
_callOnItemsRendered = memoizeOne((overscanStartIndex: number, overscanStopIndex: number, visibleStartIndex: number, visibleStopIndex: number) =>
|
|
333
|
+
((this.props.onItemsRendered: any): onItemsRenderedCallback)({
|
|
334
|
+
overscanStartIndex,
|
|
335
|
+
overscanStopIndex,
|
|
336
|
+
visibleStartIndex,
|
|
337
|
+
visibleStopIndex,
|
|
338
|
+
}),
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
_callOnScroll: (scrollDirection: ScrollDirection, scrollOffset: number, scrollUpdateWasRequested: boolean) => void;
|
|
342
|
+
_callOnScroll = memoizeOne((scrollDirection: ScrollDirection, scrollOffset: number, scrollUpdateWasRequested: boolean) =>
|
|
343
|
+
((this.props.onScroll: any): onScrollCallback)({
|
|
344
|
+
scrollDirection,
|
|
345
|
+
scrollOffset,
|
|
346
|
+
scrollUpdateWasRequested,
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
_callPropsCallbacks() {
|
|
351
|
+
if (typeof this.props.onItemsRendered === 'function') {
|
|
352
|
+
const { itemCount } = this.props;
|
|
353
|
+
if (itemCount > 0) {
|
|
354
|
+
const [overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex] = this._getRangeToRender();
|
|
355
|
+
this._callOnItemsRendered(overscanStartIndex, overscanStopIndex, visibleStartIndex, visibleStopIndex);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (typeof this.props.onScroll === 'function') {
|
|
360
|
+
const { scrollDirection, scrollOffset, scrollUpdateWasRequested } = this.state;
|
|
361
|
+
this._callOnScroll(scrollDirection, scrollOffset, scrollUpdateWasRequested);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Lazily create and cache item styles while scrolling,
|
|
366
|
+
// So that pure component sCU will prevent re-renders.
|
|
367
|
+
// We maintain this cache, and pass a style prop rather than index,
|
|
368
|
+
// So that List can clear cached styles and force item re-render if necessary.
|
|
369
|
+
_getItemStyle: (index: number) => Object;
|
|
370
|
+
_getItemStyle = (index: number): Object => {
|
|
371
|
+
const { direction, itemSize, layout } = this.props;
|
|
372
|
+
|
|
373
|
+
const itemStyleCache = this._getItemStyleCache(
|
|
374
|
+
shouldResetStyleCacheOnItemSizeChange && itemSize,
|
|
375
|
+
shouldResetStyleCacheOnItemSizeChange && layout,
|
|
376
|
+
shouldResetStyleCacheOnItemSizeChange && direction,
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
let style;
|
|
380
|
+
if (itemStyleCache.hasOwnProperty(index)) {
|
|
381
|
+
style = itemStyleCache[index];
|
|
382
|
+
} else {
|
|
383
|
+
const offset = getItemOffset(this.props, index, this._instanceProps);
|
|
384
|
+
const size = getItemSize(this.props, index, this._instanceProps);
|
|
385
|
+
|
|
386
|
+
// TODO Deprecate direction "horizontal"
|
|
387
|
+
const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
|
|
388
|
+
|
|
389
|
+
const isRtl = direction === 'rtl';
|
|
390
|
+
const offsetHorizontal = isHorizontal ? offset : 0;
|
|
391
|
+
itemStyleCache[index] = style = {
|
|
392
|
+
position: 'absolute',
|
|
393
|
+
left: isRtl ? undefined : offsetHorizontal,
|
|
394
|
+
right: isRtl ? offsetHorizontal : undefined,
|
|
395
|
+
top: !isHorizontal ? offset : 0,
|
|
396
|
+
height: !isHorizontal ? size : '100%',
|
|
397
|
+
width: isHorizontal ? size : '100%',
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return style;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
_getItemStyleCache: (_: any, __: any, ___: any) => ItemStyleCache;
|
|
405
|
+
_getItemStyleCache = memoizeOne((_: any, __: any, ___: any) => ({}));
|
|
406
|
+
|
|
407
|
+
_getRangeToRender(): [number, number, number, number] {
|
|
408
|
+
const { itemCount, overscanCount } = this.props;
|
|
409
|
+
const { isScrolling, scrollDirection, scrollOffset } = this.state;
|
|
410
|
+
|
|
411
|
+
if (itemCount === 0) {
|
|
412
|
+
return [0, 0, 0, 0];
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const startIndex = getStartIndexForOffset(this.props, scrollOffset, this._instanceProps);
|
|
416
|
+
const stopIndex = getStopIndexForStartIndex(this.props, startIndex, scrollOffset, this._instanceProps);
|
|
417
|
+
|
|
418
|
+
// Overscan by one item in each direction so that tab/focus works.
|
|
419
|
+
// If there isn't at least one extra item, tab loops back around.
|
|
420
|
+
const overscanBackward = !isScrolling || scrollDirection === 'backward' ? Math.max(1, overscanCount) : 1;
|
|
421
|
+
const overscanForward = !isScrolling || scrollDirection === 'forward' ? Math.max(1, overscanCount) : 1;
|
|
422
|
+
|
|
423
|
+
return [Math.max(0, startIndex - overscanBackward), Math.max(0, Math.min(itemCount - 1, stopIndex + overscanForward)), startIndex, stopIndex];
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
_onScrollHorizontal = (event: ScrollEvent): void => {
|
|
427
|
+
const { clientWidth, scrollLeft, scrollWidth } = event.currentTarget;
|
|
428
|
+
this.setState((prevState) => {
|
|
429
|
+
if (prevState.scrollOffset === scrollLeft) {
|
|
430
|
+
// Scroll position may have been updated by cDM/cDU,
|
|
431
|
+
// In which case we don't need to trigger another render,
|
|
432
|
+
// And we don't want to update state.isScrolling.
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const { direction } = this.props;
|
|
437
|
+
|
|
438
|
+
let scrollOffset = scrollLeft;
|
|
439
|
+
if (direction === 'rtl') {
|
|
440
|
+
// TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
|
|
441
|
+
// This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
|
|
442
|
+
// It's also easier for this component if we convert offsets to the same format as they would be in for ltr.
|
|
443
|
+
// So the simplest solution is to determine which browser behavior we're dealing with, and convert based on it.
|
|
444
|
+
switch (getRTLOffsetType()) {
|
|
445
|
+
case 'negative':
|
|
446
|
+
scrollOffset = -scrollLeft;
|
|
447
|
+
break;
|
|
448
|
+
case 'positive-descending':
|
|
449
|
+
scrollOffset = scrollWidth - clientWidth - scrollLeft;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
|
|
455
|
+
scrollOffset = Math.max(0, Math.min(scrollOffset, scrollWidth - clientWidth));
|
|
456
|
+
|
|
457
|
+
return {
|
|
458
|
+
isScrolling: true,
|
|
459
|
+
scrollDirection: prevState.scrollOffset < scrollLeft ? 'forward' : 'backward',
|
|
460
|
+
scrollOffset,
|
|
461
|
+
scrollUpdateWasRequested: false,
|
|
462
|
+
};
|
|
463
|
+
}, this._resetIsScrollingDebounced);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
_onScrollVertical = (event: ScrollEvent): void => {
|
|
467
|
+
const { clientHeight, scrollHeight, scrollTop } = event.currentTarget;
|
|
468
|
+
console.log('onScroll', clientHeight, scrollHeight, scrollTop);
|
|
469
|
+
this.setState((prevState) => {
|
|
470
|
+
if (prevState.scrollOffset === scrollTop) {
|
|
471
|
+
// Scroll position may have been updated by cDM/cDU,
|
|
472
|
+
// In which case we don't need to trigger another render,
|
|
473
|
+
// And we don't want to update state.isScrolling.
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
|
|
478
|
+
const scrollOffset = Math.max(0, Math.min(scrollTop, scrollHeight - clientHeight));
|
|
479
|
+
|
|
480
|
+
return {
|
|
481
|
+
isScrolling: true,
|
|
482
|
+
scrollDirection: prevState.scrollOffset < scrollOffset ? 'forward' : 'backward',
|
|
483
|
+
scrollOffset,
|
|
484
|
+
scrollUpdateWasRequested: false,
|
|
485
|
+
};
|
|
486
|
+
}, this._resetIsScrollingDebounced);
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
_outerRefSetter = (ref: any): void => {
|
|
490
|
+
const { outerRef } = this.props;
|
|
491
|
+
|
|
492
|
+
this._outerRef = ((ref: any): HTMLDivElement);
|
|
493
|
+
|
|
494
|
+
if (typeof outerRef === 'function') {
|
|
495
|
+
outerRef(ref);
|
|
496
|
+
} else if (outerRef != null && typeof outerRef === 'object' && outerRef.hasOwnProperty('current')) {
|
|
497
|
+
outerRef.current = ref;
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
_resetIsScrollingDebounced = () => {
|
|
502
|
+
if (this._resetIsScrollingTimeoutId !== null) {
|
|
503
|
+
cancelTimeout(this._resetIsScrollingTimeoutId);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
this._resetIsScrollingTimeoutId = requestTimeout(this._resetIsScrolling, IS_SCROLLING_DEBOUNCE_INTERVAL);
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
_resetIsScrolling = () => {
|
|
510
|
+
this._resetIsScrollingTimeoutId = null;
|
|
511
|
+
|
|
512
|
+
this.setState({ isScrolling: false }, () => {
|
|
513
|
+
// Clear style cache after state update has been committed.
|
|
514
|
+
// This way we don't break pure sCU for items that don't use isScrolling param.
|
|
515
|
+
this._getItemStyleCache(-1, null);
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// NOTE: I considered further wrapping individual items with a pure ListItem component.
|
|
522
|
+
// This would avoid ever calling the render function for the same index more than once,
|
|
523
|
+
// But it would also add the overhead of a lot of components/fibers.
|
|
524
|
+
// I assume people already do this (render function returning a class component),
|
|
525
|
+
// So my doing it would just unnecessarily double the wrappers.
|
|
526
|
+
|
|
527
|
+
const validateSharedProps = ({ children, direction, height, layout, innerTagName, outerTagName, width }: Props<any>, { instance }: State): void => {
|
|
528
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
529
|
+
if (innerTagName != null || outerTagName != null) {
|
|
530
|
+
if (devWarningsTagName && !devWarningsTagName.has(instance)) {
|
|
531
|
+
devWarningsTagName.add(instance);
|
|
532
|
+
console.warn('The innerTagName and outerTagName props have been deprecated. ' + 'Please use the innerElementType and outerElementType props instead.');
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// TODO Deprecate direction "horizontal"
|
|
537
|
+
const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
|
|
538
|
+
|
|
539
|
+
switch (direction) {
|
|
540
|
+
case 'horizontal':
|
|
541
|
+
case 'vertical':
|
|
542
|
+
if (devWarningsDirection && !devWarningsDirection.has(instance)) {
|
|
543
|
+
devWarningsDirection.add(instance);
|
|
544
|
+
console.warn('The direction prop should be either "ltr" (default) or "rtl". ' + 'Please use the layout prop to specify "vertical" (default) or "horizontal" orientation.');
|
|
545
|
+
}
|
|
546
|
+
break;
|
|
547
|
+
case 'ltr':
|
|
548
|
+
case 'rtl':
|
|
549
|
+
// Valid values
|
|
550
|
+
break;
|
|
551
|
+
default:
|
|
552
|
+
throw Error('An invalid "direction" prop has been specified. ' + 'Value should be either "ltr" or "rtl". ' + `"${direction}" was specified.`);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
switch (layout) {
|
|
556
|
+
case 'horizontal':
|
|
557
|
+
case 'vertical':
|
|
558
|
+
// Valid values
|
|
559
|
+
break;
|
|
560
|
+
default:
|
|
561
|
+
throw Error('An invalid "layout" prop has been specified. ' + 'Value should be either "horizontal" or "vertical". ' + `"${layout}" was specified.`);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (children == null) {
|
|
565
|
+
throw Error('An invalid "children" prop has been specified. ' + 'Value should be a React component. ' + `"${children === null ? 'null' : typeof children}" was specified.`);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (isHorizontal && typeof width !== 'number') {
|
|
569
|
+
throw Error('An invalid "width" prop has been specified. ' + 'Horizontal lists must specify a number for width. ' + `"${width === null ? 'null' : typeof width}" was specified.`);
|
|
570
|
+
} else if (!isHorizontal && typeof height !== 'number') {
|
|
571
|
+
throw Error('An invalid "height" prop has been specified. ' + 'Vertical lists must specify a number for height. ' + `"${height === null ? 'null' : typeof height}" was specified.`);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
let size: number = -1;
|
|
4
|
+
|
|
5
|
+
// This utility copied from "dom-helpers" package.
|
|
6
|
+
export function getScrollbarSize(recalculate?: boolean = false): number {
|
|
7
|
+
if (size === -1 || recalculate) {
|
|
8
|
+
const div = document.createElement('div');
|
|
9
|
+
const style = div.style;
|
|
10
|
+
style.width = '50px';
|
|
11
|
+
style.height = '50px';
|
|
12
|
+
style.overflow = 'scroll';
|
|
13
|
+
|
|
14
|
+
((document.body: any): HTMLBodyElement).appendChild(div);
|
|
15
|
+
|
|
16
|
+
size = div.offsetWidth - div.clientWidth;
|
|
17
|
+
|
|
18
|
+
((document.body: any): HTMLBodyElement).removeChild(div);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return size;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type RTLOffsetType = 'negative' | 'positive-descending' | 'positive-ascending';
|
|
25
|
+
|
|
26
|
+
let cachedRTLResult: RTLOffsetType | null = null;
|
|
27
|
+
|
|
28
|
+
// TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
|
|
29
|
+
// Chrome does not seem to adhere; its scrollLeft values are positive (measured relative to the left).
|
|
30
|
+
// Safari's elastic bounce makes detecting this even more complicated wrt potential false positives.
|
|
31
|
+
// The safest way to check this is to intentionally set a negative offset,
|
|
32
|
+
// and then verify that the subsequent "scroll" event matches the negative offset.
|
|
33
|
+
// If it does not match, then we can assume a non-standard RTL scroll implementation.
|
|
34
|
+
export function getRTLOffsetType(recalculate?: boolean = false): RTLOffsetType {
|
|
35
|
+
if (cachedRTLResult === null || recalculate) {
|
|
36
|
+
const outerDiv = document.createElement('div');
|
|
37
|
+
const outerStyle = outerDiv.style;
|
|
38
|
+
outerStyle.width = '50px';
|
|
39
|
+
outerStyle.height = '50px';
|
|
40
|
+
outerStyle.overflow = 'scroll';
|
|
41
|
+
outerStyle.direction = 'rtl';
|
|
42
|
+
|
|
43
|
+
const innerDiv = document.createElement('div');
|
|
44
|
+
const innerStyle = innerDiv.style;
|
|
45
|
+
innerStyle.width = '100px';
|
|
46
|
+
innerStyle.height = '100px';
|
|
47
|
+
|
|
48
|
+
outerDiv.appendChild(innerDiv);
|
|
49
|
+
|
|
50
|
+
((document.body: any): HTMLBodyElement).appendChild(outerDiv);
|
|
51
|
+
|
|
52
|
+
if (outerDiv.scrollLeft > 0) {
|
|
53
|
+
cachedRTLResult = 'positive-descending';
|
|
54
|
+
} else {
|
|
55
|
+
outerDiv.scrollLeft = 1;
|
|
56
|
+
if (outerDiv.scrollLeft === 0) {
|
|
57
|
+
cachedRTLResult = 'negative';
|
|
58
|
+
} else {
|
|
59
|
+
cachedRTLResult = 'positive-ascending';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
((document.body: any): HTMLBodyElement).removeChild(outerDiv);
|
|
64
|
+
|
|
65
|
+
return cachedRTLResult;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return cachedRTLResult;
|
|
69
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
export { default as VariableSizeGrid } from './VariableSizeGrid';
|
|
4
|
+
export { default as VariableSizeList } from './VariableSizeList';
|
|
5
|
+
export { default as FixedSizeGrid } from './FixedSizeGrid';
|
|
6
|
+
export { default as FixedSizeList } from './FixedSizeList';
|
|
7
|
+
|
|
8
|
+
export { default as areEqual } from './areEqual';
|
|
9
|
+
export { default as shouldComponentUpdate } from './shouldComponentUpdate';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
// Pulled from react-compat
|
|
4
|
+
// https://github.com/developit/preact-compat/blob/7c5de00e7c85e2ffd011bf3af02899b63f699d3a/src/index.js#L349
|
|
5
|
+
export default function shallowDiffers(prev: Object, next: Object): boolean {
|
|
6
|
+
for (let attribute in prev) {
|
|
7
|
+
if (!(attribute in next)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
for (let attribute in next) {
|
|
12
|
+
if (prev[attribute] !== next[attribute]) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import areEqual from './areEqual';
|
|
4
|
+
import shallowDiffers from './shallowDiffers';
|
|
5
|
+
|
|
6
|
+
// Custom shouldComponentUpdate for class components.
|
|
7
|
+
// It knows to compare individual style props and ignore the wrapper object.
|
|
8
|
+
// See https://reactjs.org/docs/react-component.html#shouldcomponentupdate
|
|
9
|
+
export default function shouldComponentUpdate(nextProps: Object, nextState: Object): boolean {
|
|
10
|
+
return !areEqual(this.props, nextProps) || shallowDiffers(this.state, nextState);
|
|
11
|
+
}
|