@pixui-dev/pxw 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/bin/pxw.js +199 -199
  2. package/bin/wpbuild.js +10 -10
  3. package/config/default.conf +20 -20
  4. package/config/devops.js +372 -361
  5. package/config/h5es.js +10 -10
  6. package/config/index.html +183 -181
  7. package/config/pfbs.js +245 -245
  8. package/config/util.js +140 -140
  9. package/config/webpack.js +325 -309
  10. package/lib/assets/check.html +62 -62
  11. package/lib/assets/preact.js +4354 -4354
  12. package/lib/check/main.less +62 -62
  13. package/lib/check/main.tsx +41 -41
  14. package/lib/check/tool.js +3 -3
  15. package/lib/check/util.tsx +110 -110
  16. package/lib/grpc-web/dist/ChunkParser.js +117 -117
  17. package/lib/grpc-web/dist/Code.js +58 -58
  18. package/lib/grpc-web/dist/client.js +299 -299
  19. package/lib/grpc-web/dist/debug.js +16 -16
  20. package/lib/grpc-web/dist/detach.js +7 -7
  21. package/lib/grpc-web/dist/index.js +29 -29
  22. package/lib/grpc-web/dist/invoke.js +32 -32
  23. package/lib/grpc-web/dist/message.js +3 -3
  24. package/lib/grpc-web/dist/metadata.js +5 -5
  25. package/lib/grpc-web/dist/service.js +3 -3
  26. package/lib/grpc-web/dist/transports/Transport.js +15 -15
  27. package/lib/grpc-web/dist/transports/http/fetch.js +117 -117
  28. package/lib/grpc-web/dist/transports/http/http.js +15 -15
  29. package/lib/grpc-web/dist/transports/http/xhr.js +136 -136
  30. package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -36
  31. package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -95
  32. package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -17
  33. package/lib/grpc-web/dist/typings/Code.d.ts +20 -20
  34. package/lib/grpc-web/dist/typings/client.d.ts +25 -25
  35. package/lib/grpc-web/dist/typings/debug.d.ts +1 -1
  36. package/lib/grpc-web/dist/typings/detach.d.ts +1 -1
  37. package/lib/grpc-web/dist/typings/index.d.ts +45 -45
  38. package/lib/grpc-web/dist/typings/invoke.d.ts +20 -20
  39. package/lib/grpc-web/dist/typings/message.d.ts +8 -8
  40. package/lib/grpc-web/dist/typings/metadata.d.ts +2 -2
  41. package/lib/grpc-web/dist/typings/service.d.ts +16 -16
  42. package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -22
  43. package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -6
  44. package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -5
  45. package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -27
  46. package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -3
  47. package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -2
  48. package/lib/grpc-web/dist/typings/unary.d.ts +23 -23
  49. package/lib/grpc-web/dist/typings/util.d.ts +2 -2
  50. package/lib/grpc-web/dist/unary.js +44 -44
  51. package/lib/grpc-web/dist/util.js +11 -11
  52. package/lib/grpcTransport/PixHttp2Transport.ts +107 -107
  53. package/lib/grpcTransport/PixLuaTransport.ts +82 -82
  54. package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -1698
  55. package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -1788
  56. package/lib/pi_component/tinyList/tinyList.js +483 -483
  57. package/lib/pi_component/tinyList/tinyList.tsx +517 -517
  58. package/lib/preact-router.js +395 -395
  59. package/lib/preact.js +4355 -4355
  60. package/lib/preact.tq.js +4385 -4385
  61. package/lib/react-window/src/FixedSizeGrid.js +172 -172
  62. package/lib/react-window/src/FixedSizeList.js +91 -91
  63. package/lib/react-window/src/VariableSizeGrid.js +329 -329
  64. package/lib/react-window/src/VariableSizeList.js +231 -231
  65. package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -942
  66. package/lib/react-window/src/__tests__/FixedSizeList.js +749 -749
  67. package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -598
  68. package/lib/react-window/src/__tests__/VariableSizeList.js +345 -345
  69. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -912
  70. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -568
  71. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -542
  72. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -331
  73. package/lib/react-window/src/__tests__/areEqual.js +28 -28
  74. package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -32
  75. package/lib/react-window/src/areEqual.js +13 -13
  76. package/lib/react-window/src/createGridComponent.js +657 -657
  77. package/lib/react-window/src/createListComponent.js +574 -574
  78. package/lib/react-window/src/domHelpers.js +69 -69
  79. package/lib/react-window/src/index.js +9 -9
  80. package/lib/react-window/src/shallowDiffers.js +17 -17
  81. package/lib/react-window/src/shouldComponentUpdate.js +11 -11
  82. package/lib/react-window/src/test.js.flow +382 -382
  83. package/lib/react-window/src/timer.js +36 -36
  84. package/lib/types/dom.ts +17 -17
  85. package/lib/types/ext.d.ts +81 -81
  86. package/lib/types/{css.d.ts → preact/css.d.ts} +7476 -7476
  87. package/lib/types/{preact.d.ts → preact/index.d.ts} +340 -340
  88. package/lib/types/{internal.d.ts → preact/internal.d.ts} +94 -94
  89. package/lib/types/{jsx.d.ts → preact/jsx.d.ts} +309 -309
  90. package/lib/types/preact-router/index.d.ts +85 -0
  91. package/package.json +113 -113
  92. package/scripts/pack.js +40 -40
  93. package/scripts/postinstall.js +11 -11
  94. package/scripts/run-pxw.js +12 -12
  95. package/tsconfig.json +30 -30
@@ -1,172 +1,172 @@
1
- // @flow
2
-
3
- import createGridComponent from './createGridComponent';
4
-
5
- import type { Props, ScrollToAlign } from './createGridComponent';
6
-
7
- const FixedSizeGrid = createGridComponent({
8
- getColumnOffset: ({ columnWidth }: Props<any>, index: number): number => index * ((columnWidth: any): number),
9
-
10
- getColumnWidth: ({ columnWidth }: Props<any>, index: number): number => ((columnWidth: any): number),
11
-
12
- getRowOffset: ({ rowHeight }: Props<any>, index: number): number => index * ((rowHeight: any): number),
13
-
14
- getRowHeight: ({ rowHeight }: Props<any>, index: number): number => ((rowHeight: any): number),
15
-
16
- getEstimatedTotalHeight: ({ rowCount, rowHeight }: Props<any>) => ((rowHeight: any): number) * rowCount,
17
-
18
- getEstimatedTotalWidth: ({ columnCount, columnWidth }: Props<any>) => ((columnWidth: any): number) * columnCount,
19
-
20
- getOffsetForColumnAndAlignment: (
21
- { columnCount, columnWidth, width }: Props<any>,
22
- columnIndex: number,
23
- align: ScrollToAlign,
24
- scrollLeft: number,
25
- instanceProps: typeof undefined,
26
- scrollbarSize: number,
27
- ): number => {
28
- const lastColumnOffset = Math.max(0, columnCount * ((columnWidth: any): number) - width);
29
- const maxOffset = Math.min(lastColumnOffset, columnIndex * ((columnWidth: any): number));
30
- const minOffset = Math.max(0, columnIndex * ((columnWidth: any): number) - width + scrollbarSize + ((columnWidth: any): number));
31
-
32
- if (align === 'smart') {
33
- if (scrollLeft >= minOffset - width && scrollLeft <= maxOffset + width) {
34
- align = 'auto';
35
- } else {
36
- align = 'center';
37
- }
38
- }
39
-
40
- switch (align) {
41
- case 'start':
42
- return maxOffset;
43
- case 'end':
44
- return minOffset;
45
- case 'center':
46
- // "Centered" offset is usually the average of the min and max.
47
- // But near the edges of the list, this doesn't hold true.
48
- const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
49
- if (middleOffset < Math.ceil(width / 2)) {
50
- return 0; // near the beginning
51
- } else if (middleOffset > lastColumnOffset + Math.floor(width / 2)) {
52
- return lastColumnOffset; // near the end
53
- } else {
54
- return middleOffset;
55
- }
56
- case 'auto':
57
- default:
58
- if (scrollLeft >= minOffset && scrollLeft <= maxOffset) {
59
- return scrollLeft;
60
- } else if (minOffset > maxOffset) {
61
- // Because we only take into account the scrollbar size when calculating minOffset
62
- // this value can be larger than maxOffset when at the end of the list
63
- return minOffset;
64
- } else if (scrollLeft < minOffset) {
65
- return minOffset;
66
- } else {
67
- return maxOffset;
68
- }
69
- }
70
- },
71
-
72
- getOffsetForRowAndAlignment: (
73
- { rowHeight, height, rowCount }: Props<any>,
74
- rowIndex: number,
75
- align: ScrollToAlign,
76
- scrollTop: number,
77
- instanceProps: typeof undefined,
78
- scrollbarSize: number,
79
- ): number => {
80
- const lastRowOffset = Math.max(0, rowCount * ((rowHeight: any): number) - height);
81
- const maxOffset = Math.min(lastRowOffset, rowIndex * ((rowHeight: any): number));
82
- const minOffset = Math.max(0, rowIndex * ((rowHeight: any): number) - height + scrollbarSize + ((rowHeight: any): number));
83
-
84
- if (align === 'smart') {
85
- if (scrollTop >= minOffset - height && scrollTop <= maxOffset + height) {
86
- align = 'auto';
87
- } else {
88
- align = 'center';
89
- }
90
- }
91
-
92
- switch (align) {
93
- case 'start':
94
- return maxOffset;
95
- case 'end':
96
- return minOffset;
97
- case 'center':
98
- // "Centered" offset is usually the average of the min and max.
99
- // But near the edges of the list, this doesn't hold true.
100
- const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
101
- if (middleOffset < Math.ceil(height / 2)) {
102
- return 0; // near the beginning
103
- } else if (middleOffset > lastRowOffset + Math.floor(height / 2)) {
104
- return lastRowOffset; // near the end
105
- } else {
106
- return middleOffset;
107
- }
108
- case 'auto':
109
- default:
110
- if (scrollTop >= minOffset && scrollTop <= maxOffset) {
111
- return scrollTop;
112
- } else if (minOffset > maxOffset) {
113
- // Because we only take into account the scrollbar size when calculating minOffset
114
- // this value can be larger than maxOffset when at the end of the list
115
- return minOffset;
116
- } else if (scrollTop < minOffset) {
117
- return minOffset;
118
- } else {
119
- return maxOffset;
120
- }
121
- }
122
- },
123
-
124
- getColumnStartIndexForOffset: ({ columnWidth, columnCount }: Props<any>, scrollLeft: number): number =>
125
- Math.max(0, Math.min(columnCount - 1, Math.floor(scrollLeft / ((columnWidth: any): number)))),
126
-
127
- getColumnStopIndexForStartIndex: ({ columnWidth, columnCount, width }: Props<any>, startIndex: number, scrollLeft: number): number => {
128
- const left = startIndex * ((columnWidth: any): number);
129
- const numVisibleColumns = Math.ceil((width + scrollLeft - left) / ((columnWidth: any): number));
130
- return Math.max(
131
- 0,
132
- Math.min(
133
- columnCount - 1,
134
- startIndex + numVisibleColumns - 1, // -1 is because stop index is inclusive
135
- ),
136
- );
137
- },
138
-
139
- getRowStartIndexForOffset: ({ rowHeight, rowCount }: Props<any>, scrollTop: number): number => Math.max(0, Math.min(rowCount - 1, Math.floor(scrollTop / ((rowHeight: any): number)))),
140
-
141
- getRowStopIndexForStartIndex: ({ rowHeight, rowCount, height }: Props<any>, startIndex: number, scrollTop: number): number => {
142
- const top = startIndex * ((rowHeight: any): number);
143
- const numVisibleRows = Math.ceil((height + scrollTop - top) / ((rowHeight: any): number));
144
- return Math.max(
145
- 0,
146
- Math.min(
147
- rowCount - 1,
148
- startIndex + numVisibleRows - 1, // -1 is because stop index is inclusive
149
- ),
150
- );
151
- },
152
-
153
- initInstanceProps(props: Props<any>): any {
154
- // Noop
155
- },
156
-
157
- shouldResetStyleCacheOnItemSizeChange: true,
158
-
159
- validateProps: ({ columnWidth, rowHeight }: Props<any>): void => {
160
- if (process.env.NODE_ENV !== 'production') {
161
- if (typeof columnWidth !== 'number') {
162
- throw Error('An invalid "columnWidth" prop has been specified. ' + 'Value should be a number. ' + `"${columnWidth === null ? 'null' : typeof columnWidth}" was specified.`);
163
- }
164
-
165
- if (typeof rowHeight !== 'number') {
166
- throw Error('An invalid "rowHeight" prop has been specified. ' + 'Value should be a number. ' + `"${rowHeight === null ? 'null' : typeof rowHeight}" was specified.`);
167
- }
168
- }
169
- },
170
- });
171
-
172
- export default FixedSizeGrid;
1
+ // @flow
2
+
3
+ import createGridComponent from './createGridComponent';
4
+
5
+ import type { Props, ScrollToAlign } from './createGridComponent';
6
+
7
+ const FixedSizeGrid = createGridComponent({
8
+ getColumnOffset: ({ columnWidth }: Props<any>, index: number): number => index * ((columnWidth: any): number),
9
+
10
+ getColumnWidth: ({ columnWidth }: Props<any>, index: number): number => ((columnWidth: any): number),
11
+
12
+ getRowOffset: ({ rowHeight }: Props<any>, index: number): number => index * ((rowHeight: any): number),
13
+
14
+ getRowHeight: ({ rowHeight }: Props<any>, index: number): number => ((rowHeight: any): number),
15
+
16
+ getEstimatedTotalHeight: ({ rowCount, rowHeight }: Props<any>) => ((rowHeight: any): number) * rowCount,
17
+
18
+ getEstimatedTotalWidth: ({ columnCount, columnWidth }: Props<any>) => ((columnWidth: any): number) * columnCount,
19
+
20
+ getOffsetForColumnAndAlignment: (
21
+ { columnCount, columnWidth, width }: Props<any>,
22
+ columnIndex: number,
23
+ align: ScrollToAlign,
24
+ scrollLeft: number,
25
+ instanceProps: typeof undefined,
26
+ scrollbarSize: number,
27
+ ): number => {
28
+ const lastColumnOffset = Math.max(0, columnCount * ((columnWidth: any): number) - width);
29
+ const maxOffset = Math.min(lastColumnOffset, columnIndex * ((columnWidth: any): number));
30
+ const minOffset = Math.max(0, columnIndex * ((columnWidth: any): number) - width + scrollbarSize + ((columnWidth: any): number));
31
+
32
+ if (align === 'smart') {
33
+ if (scrollLeft >= minOffset - width && scrollLeft <= maxOffset + width) {
34
+ align = 'auto';
35
+ } else {
36
+ align = 'center';
37
+ }
38
+ }
39
+
40
+ switch (align) {
41
+ case 'start':
42
+ return maxOffset;
43
+ case 'end':
44
+ return minOffset;
45
+ case 'center':
46
+ // "Centered" offset is usually the average of the min and max.
47
+ // But near the edges of the list, this doesn't hold true.
48
+ const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
49
+ if (middleOffset < Math.ceil(width / 2)) {
50
+ return 0; // near the beginning
51
+ } else if (middleOffset > lastColumnOffset + Math.floor(width / 2)) {
52
+ return lastColumnOffset; // near the end
53
+ } else {
54
+ return middleOffset;
55
+ }
56
+ case 'auto':
57
+ default:
58
+ if (scrollLeft >= minOffset && scrollLeft <= maxOffset) {
59
+ return scrollLeft;
60
+ } else if (minOffset > maxOffset) {
61
+ // Because we only take into account the scrollbar size when calculating minOffset
62
+ // this value can be larger than maxOffset when at the end of the list
63
+ return minOffset;
64
+ } else if (scrollLeft < minOffset) {
65
+ return minOffset;
66
+ } else {
67
+ return maxOffset;
68
+ }
69
+ }
70
+ },
71
+
72
+ getOffsetForRowAndAlignment: (
73
+ { rowHeight, height, rowCount }: Props<any>,
74
+ rowIndex: number,
75
+ align: ScrollToAlign,
76
+ scrollTop: number,
77
+ instanceProps: typeof undefined,
78
+ scrollbarSize: number,
79
+ ): number => {
80
+ const lastRowOffset = Math.max(0, rowCount * ((rowHeight: any): number) - height);
81
+ const maxOffset = Math.min(lastRowOffset, rowIndex * ((rowHeight: any): number));
82
+ const minOffset = Math.max(0, rowIndex * ((rowHeight: any): number) - height + scrollbarSize + ((rowHeight: any): number));
83
+
84
+ if (align === 'smart') {
85
+ if (scrollTop >= minOffset - height && scrollTop <= maxOffset + height) {
86
+ align = 'auto';
87
+ } else {
88
+ align = 'center';
89
+ }
90
+ }
91
+
92
+ switch (align) {
93
+ case 'start':
94
+ return maxOffset;
95
+ case 'end':
96
+ return minOffset;
97
+ case 'center':
98
+ // "Centered" offset is usually the average of the min and max.
99
+ // But near the edges of the list, this doesn't hold true.
100
+ const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
101
+ if (middleOffset < Math.ceil(height / 2)) {
102
+ return 0; // near the beginning
103
+ } else if (middleOffset > lastRowOffset + Math.floor(height / 2)) {
104
+ return lastRowOffset; // near the end
105
+ } else {
106
+ return middleOffset;
107
+ }
108
+ case 'auto':
109
+ default:
110
+ if (scrollTop >= minOffset && scrollTop <= maxOffset) {
111
+ return scrollTop;
112
+ } else if (minOffset > maxOffset) {
113
+ // Because we only take into account the scrollbar size when calculating minOffset
114
+ // this value can be larger than maxOffset when at the end of the list
115
+ return minOffset;
116
+ } else if (scrollTop < minOffset) {
117
+ return minOffset;
118
+ } else {
119
+ return maxOffset;
120
+ }
121
+ }
122
+ },
123
+
124
+ getColumnStartIndexForOffset: ({ columnWidth, columnCount }: Props<any>, scrollLeft: number): number =>
125
+ Math.max(0, Math.min(columnCount - 1, Math.floor(scrollLeft / ((columnWidth: any): number)))),
126
+
127
+ getColumnStopIndexForStartIndex: ({ columnWidth, columnCount, width }: Props<any>, startIndex: number, scrollLeft: number): number => {
128
+ const left = startIndex * ((columnWidth: any): number);
129
+ const numVisibleColumns = Math.ceil((width + scrollLeft - left) / ((columnWidth: any): number));
130
+ return Math.max(
131
+ 0,
132
+ Math.min(
133
+ columnCount - 1,
134
+ startIndex + numVisibleColumns - 1, // -1 is because stop index is inclusive
135
+ ),
136
+ );
137
+ },
138
+
139
+ getRowStartIndexForOffset: ({ rowHeight, rowCount }: Props<any>, scrollTop: number): number => Math.max(0, Math.min(rowCount - 1, Math.floor(scrollTop / ((rowHeight: any): number)))),
140
+
141
+ getRowStopIndexForStartIndex: ({ rowHeight, rowCount, height }: Props<any>, startIndex: number, scrollTop: number): number => {
142
+ const top = startIndex * ((rowHeight: any): number);
143
+ const numVisibleRows = Math.ceil((height + scrollTop - top) / ((rowHeight: any): number));
144
+ return Math.max(
145
+ 0,
146
+ Math.min(
147
+ rowCount - 1,
148
+ startIndex + numVisibleRows - 1, // -1 is because stop index is inclusive
149
+ ),
150
+ );
151
+ },
152
+
153
+ initInstanceProps(props: Props<any>): any {
154
+ // Noop
155
+ },
156
+
157
+ shouldResetStyleCacheOnItemSizeChange: true,
158
+
159
+ validateProps: ({ columnWidth, rowHeight }: Props<any>): void => {
160
+ if (process.env.NODE_ENV !== 'production') {
161
+ if (typeof columnWidth !== 'number') {
162
+ throw Error('An invalid "columnWidth" prop has been specified. ' + 'Value should be a number. ' + `"${columnWidth === null ? 'null' : typeof columnWidth}" was specified.`);
163
+ }
164
+
165
+ if (typeof rowHeight !== 'number') {
166
+ throw Error('An invalid "rowHeight" prop has been specified. ' + 'Value should be a number. ' + `"${rowHeight === null ? 'null' : typeof rowHeight}" was specified.`);
167
+ }
168
+ }
169
+ },
170
+ });
171
+
172
+ export default FixedSizeGrid;
@@ -1,91 +1,91 @@
1
- // @flow
2
-
3
- import createListComponent from './createListComponent';
4
-
5
- import type { Props, ScrollToAlign } from './createListComponent';
6
-
7
- const FixedSizeList = createListComponent({
8
- getItemOffset: ({ itemSize }: Props<any>, index: number): number => index * ((itemSize: any): number),
9
-
10
- getItemSize: ({ itemSize }: Props<any>, index: number): number => ((itemSize: any): number),
11
-
12
- getEstimatedTotalSize: ({ itemCount, itemSize }: Props<any>) => ((itemSize: any): number) * itemCount,
13
-
14
- getOffsetForIndexAndAlignment: ({ direction, height, itemCount, itemSize, layout, width }: Props<any>, index: number, align: ScrollToAlign, scrollOffset: number): number => {
15
- // TODO Deprecate direction "horizontal"
16
- const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
17
- const size = (((isHorizontal ? width : height): any): number);
18
- const lastItemOffset = Math.max(0, itemCount * ((itemSize: any): number) - size);
19
- const maxOffset = Math.min(lastItemOffset, index * ((itemSize: any): number));
20
- const minOffset = Math.max(0, index * ((itemSize: any): number) - size + ((itemSize: any): number));
21
-
22
- if (align === 'smart') {
23
- if (scrollOffset >= minOffset - size && scrollOffset <= maxOffset + size) {
24
- align = 'auto';
25
- } else {
26
- align = 'center';
27
- }
28
- }
29
-
30
- switch (align) {
31
- case 'start':
32
- return maxOffset;
33
- case 'end':
34
- return minOffset;
35
- case 'center': {
36
- // "Centered" offset is usually the average of the min and max.
37
- // But near the edges of the list, this doesn't hold true.
38
- const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
39
- if (middleOffset < Math.ceil(size / 2)) {
40
- return 0; // near the beginning
41
- } else if (middleOffset > lastItemOffset + Math.floor(size / 2)) {
42
- return lastItemOffset; // near the end
43
- } else {
44
- return middleOffset;
45
- }
46
- }
47
- case 'auto':
48
- default:
49
- if (scrollOffset >= minOffset && scrollOffset <= maxOffset) {
50
- return scrollOffset;
51
- } else if (scrollOffset < minOffset) {
52
- return minOffset;
53
- } else {
54
- return maxOffset;
55
- }
56
- }
57
- },
58
-
59
- getStartIndexForOffset: ({ itemCount, itemSize }: Props<any>, offset: number): number => Math.max(0, Math.min(itemCount - 1, Math.floor(offset / ((itemSize: any): number)))),
60
-
61
- getStopIndexForStartIndex: ({ direction, height, itemCount, itemSize, layout, width }: Props<any>, startIndex: number, scrollOffset: number): number => {
62
- // TODO Deprecate direction "horizontal"
63
- const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
64
- const offset = startIndex * ((itemSize: any): number);
65
- const size = (((isHorizontal ? width : height): any): number);
66
- const numVisibleItems = Math.ceil((size + scrollOffset - offset) / ((itemSize: any): number));
67
- return Math.max(
68
- 0,
69
- Math.min(
70
- itemCount - 1,
71
- startIndex + numVisibleItems - 1, // -1 is because stop index is inclusive
72
- ),
73
- );
74
- },
75
-
76
- initInstanceProps(props: Props<any>): any {
77
- // Noop
78
- },
79
-
80
- shouldResetStyleCacheOnItemSizeChange: true,
81
-
82
- validateProps: ({ itemSize }: Props<any>): void => {
83
- if (process.env.NODE_ENV !== 'production') {
84
- if (typeof itemSize !== 'number') {
85
- throw Error('An invalid "itemSize" prop has been specified. ' + 'Value should be a number. ' + `"${itemSize === null ? 'null' : typeof itemSize}" was specified.`);
86
- }
87
- }
88
- },
89
- });
90
-
91
- export default FixedSizeList;
1
+ // @flow
2
+
3
+ import createListComponent from './createListComponent';
4
+
5
+ import type { Props, ScrollToAlign } from './createListComponent';
6
+
7
+ const FixedSizeList = createListComponent({
8
+ getItemOffset: ({ itemSize }: Props<any>, index: number): number => index * ((itemSize: any): number),
9
+
10
+ getItemSize: ({ itemSize }: Props<any>, index: number): number => ((itemSize: any): number),
11
+
12
+ getEstimatedTotalSize: ({ itemCount, itemSize }: Props<any>) => ((itemSize: any): number) * itemCount,
13
+
14
+ getOffsetForIndexAndAlignment: ({ direction, height, itemCount, itemSize, layout, width }: Props<any>, index: number, align: ScrollToAlign, scrollOffset: number): number => {
15
+ // TODO Deprecate direction "horizontal"
16
+ const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
17
+ const size = (((isHorizontal ? width : height): any): number);
18
+ const lastItemOffset = Math.max(0, itemCount * ((itemSize: any): number) - size);
19
+ const maxOffset = Math.min(lastItemOffset, index * ((itemSize: any): number));
20
+ const minOffset = Math.max(0, index * ((itemSize: any): number) - size + ((itemSize: any): number));
21
+
22
+ if (align === 'smart') {
23
+ if (scrollOffset >= minOffset - size && scrollOffset <= maxOffset + size) {
24
+ align = 'auto';
25
+ } else {
26
+ align = 'center';
27
+ }
28
+ }
29
+
30
+ switch (align) {
31
+ case 'start':
32
+ return maxOffset;
33
+ case 'end':
34
+ return minOffset;
35
+ case 'center': {
36
+ // "Centered" offset is usually the average of the min and max.
37
+ // But near the edges of the list, this doesn't hold true.
38
+ const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
39
+ if (middleOffset < Math.ceil(size / 2)) {
40
+ return 0; // near the beginning
41
+ } else if (middleOffset > lastItemOffset + Math.floor(size / 2)) {
42
+ return lastItemOffset; // near the end
43
+ } else {
44
+ return middleOffset;
45
+ }
46
+ }
47
+ case 'auto':
48
+ default:
49
+ if (scrollOffset >= minOffset && scrollOffset <= maxOffset) {
50
+ return scrollOffset;
51
+ } else if (scrollOffset < minOffset) {
52
+ return minOffset;
53
+ } else {
54
+ return maxOffset;
55
+ }
56
+ }
57
+ },
58
+
59
+ getStartIndexForOffset: ({ itemCount, itemSize }: Props<any>, offset: number): number => Math.max(0, Math.min(itemCount - 1, Math.floor(offset / ((itemSize: any): number)))),
60
+
61
+ getStopIndexForStartIndex: ({ direction, height, itemCount, itemSize, layout, width }: Props<any>, startIndex: number, scrollOffset: number): number => {
62
+ // TODO Deprecate direction "horizontal"
63
+ const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
64
+ const offset = startIndex * ((itemSize: any): number);
65
+ const size = (((isHorizontal ? width : height): any): number);
66
+ const numVisibleItems = Math.ceil((size + scrollOffset - offset) / ((itemSize: any): number));
67
+ return Math.max(
68
+ 0,
69
+ Math.min(
70
+ itemCount - 1,
71
+ startIndex + numVisibleItems - 1, // -1 is because stop index is inclusive
72
+ ),
73
+ );
74
+ },
75
+
76
+ initInstanceProps(props: Props<any>): any {
77
+ // Noop
78
+ },
79
+
80
+ shouldResetStyleCacheOnItemSizeChange: true,
81
+
82
+ validateProps: ({ itemSize }: Props<any>): void => {
83
+ if (process.env.NODE_ENV !== 'production') {
84
+ if (typeof itemSize !== 'number') {
85
+ throw Error('An invalid "itemSize" prop has been specified. ' + 'Value should be a number. ' + `"${itemSize === null ? 'null' : typeof itemSize}" was specified.`);
86
+ }
87
+ }
88
+ },
89
+ });
90
+
91
+ export default FixedSizeList;