@mpxjs/webpack-plugin 2.10.16 → 2.10.17-beta.10

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 (226) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/dependencies/AppEntryDependency.js +2 -2
  3. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  4. package/lib/dependencies/ResolveDependency.js +1 -1
  5. package/lib/file-loader.js +4 -1
  6. package/lib/global.d.ts +245 -0
  7. package/lib/helpers.js +2 -0
  8. package/lib/index.js +80 -19
  9. package/lib/json-compiler/helper.js +72 -2
  10. package/lib/json-compiler/index.js +45 -59
  11. package/lib/json-compiler/plugin.js +2 -2
  12. package/lib/loader.js +14 -4
  13. package/lib/native-loader.js +6 -3
  14. package/lib/platform/json/wx/index.js +30 -29
  15. package/lib/platform/style/wx/index.js +51 -36
  16. package/lib/platform/template/wx/component-config/ad.js +5 -0
  17. package/lib/platform/template/wx/component-config/button.js +22 -6
  18. package/lib/platform/template/wx/component-config/camera.js +25 -3
  19. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  20. package/lib/platform/template/wx/component-config/component.js +31 -33
  21. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  22. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  23. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  24. package/lib/platform/template/wx/component-config/form.js +27 -2
  25. package/lib/platform/template/wx/component-config/image.js +5 -0
  26. package/lib/platform/template/wx/component-config/input.js +11 -1
  27. package/lib/platform/template/wx/component-config/label.js +10 -2
  28. package/lib/platform/template/wx/component-config/map.js +11 -0
  29. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  30. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  31. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  32. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  33. package/lib/platform/template/wx/component-config/picker.js +3 -1
  34. package/lib/platform/template/wx/component-config/progress.js +11 -1
  35. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  36. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  37. package/lib/platform/template/wx/component-config/slider.js +8 -0
  38. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  39. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  40. package/lib/platform/template/wx/component-config/text.js +5 -0
  41. package/lib/platform/template/wx/component-config/textarea.js +20 -3
  42. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  43. package/lib/platform/template/wx/component-config/video.js +10 -0
  44. package/lib/platform/template/wx/index.js +21 -1
  45. package/lib/react/LoadAsyncChunkModule.js +1 -1
  46. package/lib/react/index.js +2 -0
  47. package/lib/react/processJSON.js +59 -72
  48. package/lib/react/processScript.js +1 -0
  49. package/lib/react/processStyles.js +24 -11
  50. package/lib/react/processTemplate.js +8 -6
  51. package/lib/react/script-helper.js +6 -17
  52. package/lib/react/style-helper.js +84 -13
  53. package/lib/resolver/AddModePlugin.js +23 -8
  54. package/lib/runtime/components/ali/mpx-recycle-view.mpx +518 -0
  55. package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
  56. package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
  57. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  58. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
  59. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  60. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  61. package/lib/runtime/components/react/context.ts +19 -7
  62. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  63. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  64. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  65. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
  66. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  67. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  68. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  69. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  70. package/lib/runtime/components/react/dist/context.d.ts +79 -0
  71. package/lib/runtime/components/react/dist/context.js +1 -0
  72. package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
  73. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
  74. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
  75. package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
  76. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  77. package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
  78. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
  79. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
  80. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
  81. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
  82. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
  83. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
  84. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
  85. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
  86. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  87. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
  88. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
  89. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
  90. package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
  91. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
  92. package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
  93. package/lib/runtime/components/react/dist/mpx-image.jsx +109 -59
  94. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
  95. package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
  96. package/lib/runtime/components/react/dist/mpx-input.jsx +52 -17
  97. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
  98. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +62 -49
  99. package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
  100. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
  101. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +65 -0
  102. package/lib/runtime/components/react/dist/mpx-nav.d.ts +8 -0
  103. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  104. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
  105. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
  106. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
  107. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
  108. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
  109. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
  110. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
  111. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
  112. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
  113. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
  114. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +32 -0
  115. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  116. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
  117. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +23 -0
  118. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  119. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
  120. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  121. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +13 -0
  122. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  123. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
  124. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
  125. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
  126. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
  127. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
  128. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
  129. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  130. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
  131. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
  132. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  133. package/lib/runtime/components/react/dist/mpx-progress.d.ts +23 -0
  134. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
  135. package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
  136. package/lib/runtime/components/react/dist/mpx-recycle-view.d.ts +45 -0
  137. package/lib/runtime/components/react/dist/mpx-recycle-view.jsx +307 -0
  138. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
  139. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
  140. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  141. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
  142. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
  143. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  144. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
  145. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
  146. package/lib/runtime/components/react/dist/mpx-slider.d.ts +30 -0
  147. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
  148. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
  149. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
  150. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +63 -0
  151. package/lib/runtime/components/react/dist/mpx-swiper.jsx +77 -44
  152. package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
  153. package/lib/runtime/components/react/dist/mpx-text.d.ts +22 -0
  154. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  155. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
  156. package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
  157. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  158. package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
  159. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
  160. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -3
  161. package/lib/runtime/components/react/dist/parser.d.ts +39 -0
  162. package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
  163. package/lib/runtime/components/react/dist/utils.d.ts +124 -0
  164. package/lib/runtime/components/react/dist/utils.jsx +42 -17
  165. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  166. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  167. package/lib/runtime/components/react/mpx-image.tsx +132 -79
  168. package/lib/runtime/components/react/mpx-input.tsx +63 -24
  169. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +70 -48
  170. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  171. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  172. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  173. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  174. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  175. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  176. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  177. package/lib/runtime/components/react/mpx-recycle-view.tsx +437 -0
  178. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  179. package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -17
  180. package/lib/runtime/components/react/mpx-sticky-section.tsx +1 -1
  181. package/lib/runtime/components/react/mpx-swiper.tsx +92 -42
  182. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  183. package/lib/runtime/components/react/mpx-view.tsx +28 -13
  184. package/lib/runtime/components/react/mpx-web-view.tsx +14 -5
  185. package/lib/runtime/components/react/tsconfig.json +26 -0
  186. package/lib/runtime/components/react/types/common.d.ts +19 -0
  187. package/lib/runtime/components/react/types/global.d.ts +1 -0
  188. package/lib/runtime/components/react/utils.tsx +43 -21
  189. package/lib/runtime/components/web/mpx-recycle-view.vue +508 -0
  190. package/lib/runtime/components/wx/mpx-list-header-default.mpx +21 -0
  191. package/lib/runtime/components/wx/mpx-recycle-item-default.mpx +21 -0
  192. package/lib/runtime/components/wx/mpx-recycle-view.mpx +193 -0
  193. package/lib/runtime/components/wx/mpx-section-header-default.mpx +21 -0
  194. package/lib/runtime/optionProcessor.js +5 -0
  195. package/lib/runtime/optionProcessorReact.js +7 -0
  196. package/lib/runtime/stringify.wxs +2 -2
  197. package/lib/script-setup-compiler/index.js +2 -2
  198. package/lib/style-compiler/index.js +3 -2
  199. package/lib/style-compiler/load-postcss-config.js +1 -1
  200. package/lib/style-compiler/plugins/trans-special.js +10 -2
  201. package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
  202. package/lib/style-compiler/strip-conditional-loader.js +124 -18
  203. package/lib/template-compiler/compiler.js +272 -72
  204. package/lib/template-compiler/gen-node-react.js +18 -6
  205. package/lib/template-compiler/index.js +6 -4
  206. package/lib/template-compiler/parse-exps.js +1 -1
  207. package/lib/utils/const.js +19 -1
  208. package/lib/utils/dom-tag-config.js +6 -6
  209. package/lib/utils/env.js +6 -1
  210. package/lib/utils/get-build-tag-component.js +35 -0
  211. package/lib/utils/merge-visitors.js +55 -0
  212. package/lib/utils/pre-process-json.js +5 -0
  213. package/lib/utils/process-extend-components.js +43 -0
  214. package/lib/utils/string.js +25 -1
  215. package/lib/web/index.js +2 -0
  216. package/lib/web/processJSON.js +64 -18
  217. package/lib/web/processScript.js +1 -1
  218. package/lib/web/processTemplate.js +6 -4
  219. package/lib/web/script-helper.js +19 -9
  220. package/lib/wxs/pre-loader.js +9 -6
  221. package/lib/wxss/loader.js +1 -9
  222. package/package.json +11 -7
  223. package/LICENSE +0 -433
  224. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  225. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  226. package/lib/utils/chain-assign.js +0 -47
@@ -0,0 +1,518 @@
1
+ <template>
2
+ <view class="mpx-recycle-view">
3
+ <scroll-view
4
+ id="scrollViewContainer"
5
+ class="scroll-view-container"
6
+ wx:ref="mpxRecycleView"
7
+ scroll-y="{{true}}"
8
+ scroll-top="{{scrollTop}}"
9
+ enhanced="{{enhanced}}"
10
+ scroll-with-animation="{{scrollWithAnimation}}"
11
+ scroll-animation-duration="{{scrollAnimationDuration}}"
12
+ refresher-enabled="{{refresherEnabled}}"
13
+ refresher-triggered="{{refresherTriggered}}"
14
+ bindscroll="onScroll"
15
+ bindscrolltolower="onScrolltolower"
16
+ bindrefresherrefresh="onRefresherrefresh"
17
+ wx:style="{{scrollViewStyle}}"
18
+ >
19
+ <view class="content-wrapper">
20
+ <block wx:if="{{useListHeader}}">
21
+ <list-header listHeaderData="{{listHeaderData}}"></list-header>
22
+ </block>
23
+ <view
24
+ class="infinite-list-placeholder"
25
+ ref="infinitePlaceholder"
26
+ wx:style="{{placeholderStyle}}"
27
+ ></view>
28
+ <view class="infinite-list" ref="infiniteList" wx:style="{{infiniteListStyle}}">
29
+ <block wx:for="{{visibleData}}">
30
+ <section-header
31
+ wx:if="{{item.itemData.isSectionHeader}}"
32
+ wx:key="header{{_index}}"
33
+ itemData="{{item.itemData}}"
34
+ />
35
+ <recycle-item
36
+ wx:if="{{!item.itemData.isSectionHeader}}"
37
+ wx:key="item{{_index}}"
38
+ itemData="{{item.itemData}}"
39
+ />
40
+ </block>
41
+ </view>
42
+ </view>
43
+ <block
44
+ wx:if="{{ _stickyHeaders &&
45
+ _stickyHeaders.length &&
46
+ positions.length &&
47
+ enableSticky
48
+ }}"
49
+ >
50
+ <sticky-header
51
+ scroll-view-id="scrollViewContainer"
52
+ sticky-id="mpx-sticky-header-{{index}}"
53
+ wx:ref="stickyHeader"
54
+ class="sticky-section"
55
+ wx:style="top: {{(positions[stickyItem._index] && positions[stickyItem._index].top) || 0}}px"
56
+ wx:for="{{_stickyHeaders}}"
57
+ wx:for-item="stickyItem"
58
+ wx:key="_index"
59
+ enable-polling="{{enablePolling}}"
60
+ polling-duration="{{pollingDuration}}"
61
+ >
62
+ <section-header
63
+ wx:key="{{'header' + stickyItem._index}}"
64
+ itemData="{{stickyItem.itemData}}"
65
+ />
66
+ </sticky-header>
67
+ </block>
68
+ </scroll-view>
69
+ </view>
70
+ </template>
71
+
72
+ <script>
73
+ import mpx, { createComponent } from '@mpxjs/core'
74
+ createComponent({
75
+ properties: {
76
+ width: String | Number,
77
+ height: String | Number,
78
+ listData: {
79
+ type: Array,
80
+ value: () => {
81
+ return []
82
+ }
83
+ },
84
+ scrollOptions: {
85
+ type: Object,
86
+ value: () => {
87
+ return {}
88
+ }
89
+ },
90
+ minRenderCount: {
91
+ type: Number,
92
+ value: 10
93
+ },
94
+ bufferScale: {
95
+ type: Number,
96
+ value: 1
97
+ },
98
+ itemHeight: {
99
+ type: Object,
100
+ value: () => {
101
+ return {}
102
+ }
103
+ },
104
+ listHeaderHeight: {
105
+ type: Object,
106
+ value: () => {
107
+ return {}
108
+ }
109
+ },
110
+ sectionHeaderHeight: {
111
+ type: Object,
112
+ value: () => {
113
+ return {}
114
+ }
115
+ },
116
+ listHeaderData: {
117
+ type: Object,
118
+ value: () => {
119
+ return {}
120
+ }
121
+ },
122
+ enhanced: {
123
+ type: Boolean,
124
+ value: false
125
+ },
126
+ refresherEnabled: {
127
+ type: Boolean,
128
+ value: false
129
+ },
130
+ refresherTriggered: {
131
+ type: Boolean,
132
+ value: false
133
+ },
134
+ enableSticky: {
135
+ type: Boolean,
136
+ value: false
137
+ },
138
+ scrollWithAnimation: {
139
+ type: Boolean,
140
+ value: false
141
+ },
142
+ scrollAnimationDuration: {
143
+ type: Number,
144
+ value: 300
145
+ },
146
+ enablePolling: {
147
+ type: Boolean,
148
+ value: false
149
+ },
150
+ pollingDuration: {
151
+ type: Number,
152
+ value: 3000
153
+ },
154
+ useListHeader: {
155
+ type: Boolean,
156
+ value: false
157
+ }
158
+ },
159
+ data: {
160
+ start: 0,
161
+ end: 0,
162
+ containerHeight: 0,
163
+ positions: [],
164
+ visibleCounts: [],
165
+ infiniteListStyle: '',
166
+ placeholderStyle: '',
167
+ scrollTop: 0
168
+ },
169
+ computed: {
170
+ _listData() {
171
+ return this.listData.map((item, index) => {
172
+ return {
173
+ itemData: item,
174
+ _index: `_${index}`
175
+ }
176
+ })
177
+ },
178
+ _stickyHeaders() {
179
+ const data = []
180
+ this.listData.forEach((item, index) => {
181
+ if (item.isSectionHeader) {
182
+ data.push({
183
+ itemData: item,
184
+ _index: index
185
+ })
186
+ }
187
+ })
188
+ return data
189
+ },
190
+ scrollViewStyle() {
191
+ return `height: ${this.formatDimension(
192
+ this.height
193
+ )};width: ${this.formatDimension(this.width)}`
194
+ },
195
+ visibleCount() {
196
+ if (!this.visibleCounts.length) return this.minRenderCount
197
+ return Math.max(this.visibleCounts[this.start], this.minRenderCount)
198
+ },
199
+ aboveCount() {
200
+ if (!this._listData.length || !this.visibleCounts.length) return 0
201
+ let count = 0
202
+ const startIndex = Math.max(0, this.start)
203
+ const endIndex = Math.max(0, startIndex - this.bufferScale)
204
+
205
+ for (let i = startIndex; i > endIndex; i--) {
206
+ count += this.visibleCounts[i] || 0
207
+ }
208
+
209
+ return count
210
+ },
211
+ belowCount() {
212
+ if (!this._listData.length || !this.visibleCounts.length) return 0
213
+ let count = 0
214
+ const startIndex = Math.min(this.start, this._listData.length - 1)
215
+ const endIndex = Math.min(startIndex + this.bufferScale, this._listData.length - 1)
216
+
217
+ for (let i = startIndex; i < endIndex; i++) {
218
+ count += this.visibleCounts[i] || 0
219
+ }
220
+
221
+ return count
222
+ },
223
+ visibleData() {
224
+ if (!this._listData.length) return []
225
+
226
+ const start = Math.min(Math.max(0, this.start - this.aboveCount), this._listData.length - 1)
227
+
228
+ let end = Math.min(this._listData.length, this.start + this.visibleCount + this.belowCount)
229
+
230
+ // 如果接近列表末尾,确保显示所有剩余项目
231
+ if (end > this._listData.length - 3) {
232
+ end = this._listData.length
233
+ }
234
+
235
+ return this._listData.slice(start, end).map((item, idx) => {
236
+ const realIndex = start + idx
237
+ return {
238
+ ...item,
239
+ _index: `_${realIndex}`
240
+ }
241
+ })
242
+ },
243
+ _listHeaderHeight() {
244
+ let listHeaderHeight = 0
245
+ if (this.useListHeader) {
246
+ listHeaderHeight = this.getItemHeight(this.listHeaderData, 0, 'listHeaderHeight') || 0
247
+ }
248
+ return listHeaderHeight
249
+ },
250
+ placeholderHeight() {
251
+ if (!this.positions.length) return 0
252
+ return this.positions[this.positions.length - 1].bottom - this._listHeaderHeight || 0
253
+ }
254
+ },
255
+ watch: {
256
+ listData: {
257
+ handler() {
258
+ this.initPositions()
259
+ this.setPlaceholderStyle()
260
+ // 更新真实偏移量
261
+ this.setStartOffset()
262
+ }
263
+ },
264
+ containerHeight() {
265
+ this.calculateVisibleCounts()
266
+ }
267
+ },
268
+ ready() {
269
+ this.initPositions()
270
+ this.getContainerHeight()
271
+ this.setPlaceholderStyle()
272
+ if (!this.positions || !this.positions.length) {
273
+ return
274
+ }
275
+ this.start = this.getStartIndex()
276
+ this.end = this.start + this.visibleCount
277
+ this.setStartOffset()
278
+ },
279
+ methods: {
280
+ getContainerHeight() {
281
+ mpx
282
+ .createSelectorQuery()
283
+ .select('#scrollViewContainer')
284
+ .boundingClientRect((rect) => {
285
+ if (!rect) return
286
+ this.containerHeight = rect.height
287
+ })
288
+ .exec()
289
+ },
290
+ formatDimension(value) {
291
+ return typeof value === 'number' ? `${value}px` : value || '100%'
292
+ },
293
+ setPlaceholderStyle() {
294
+ this.placeholderStyle = `height: ${this.placeholderHeight}px`
295
+ },
296
+ initPositions() {
297
+ let bottom = this._listHeaderHeight || 0
298
+ this.positions = this._listData.map((item, index) => {
299
+ const height = this.getItemHeight(
300
+ item.itemData,
301
+ index,
302
+ item.itemData.isSectionHeader ? 'sectionHeaderHeight' : 'itemHeight'
303
+ )
304
+ const position = {
305
+ index,
306
+ height: height,
307
+ top: bottom,
308
+ bottom: bottom + height
309
+ }
310
+ bottom = position.bottom
311
+ return position
312
+ })
313
+
314
+ if (this.containerHeight) {
315
+ this.calculateVisibleCounts()
316
+ }
317
+ },
318
+ calculateVisibleCounts() {
319
+ this.visibleCounts = this.positions.map((_, startIndex) => {
320
+ let count = 0
321
+ let totalHeight = 0
322
+
323
+ for (let i = startIndex; i < this.positions.length; i++) {
324
+ totalHeight += this.positions[i].height
325
+ if (totalHeight > this.containerHeight) {
326
+ break
327
+ }
328
+ count++
329
+ }
330
+
331
+ // 如果是最后几个项目,确保全部显示
332
+ if (startIndex + count > this.positions.length - 3) {
333
+ count = this.positions.length - startIndex
334
+ }
335
+
336
+ return count
337
+ })
338
+ },
339
+
340
+ getStartIndex(scrollTop = 0) {
341
+ // 确保不会返回超出范围的索引
342
+ if (!this.positions.length) {
343
+ return 0
344
+ }
345
+
346
+ // 如果滚动位置为0,直接返回0
347
+ if (scrollTop <= 0) {
348
+ return 0
349
+ }
350
+ const index = this.binarySearch(this.positions, scrollTop)
351
+ return Math.max(0, Math.min(index, this._listData.length - 1))
352
+ },
353
+ binarySearch(list, value) {
354
+ if (!list.length) return 0
355
+
356
+ // 如果 scrollTop 超过了最后一个元素的底部
357
+ if (value >= list[list.length - 1].bottom) {
358
+ return list.length - 1
359
+ }
360
+
361
+ let start = 0
362
+ let end = list.length - 1
363
+
364
+ while (start <= end) {
365
+ const midIndex = Math.floor((start + end) / 2)
366
+ const midValue = list[midIndex]
367
+
368
+ if (value >= midValue.top && value < midValue.bottom) {
369
+ return midIndex
370
+ }
371
+
372
+ if (value < midValue.top) {
373
+ end = midIndex - 1
374
+ } else {
375
+ start = midIndex + 1
376
+ }
377
+ }
378
+
379
+ return Math.min(Math.max(0, start - 1), list.length - 1)
380
+ },
381
+ setStartOffset() {
382
+ if (!this.positions.length) return
383
+ if (this.start >= 1) {
384
+ // 确保 startIndex 不会超出范围
385
+ const startIndex = Math.min(
386
+ Math.max(0, this.start - this.aboveCount),
387
+ this.positions.length - 1
388
+ )
389
+
390
+ const offset = this.positions[startIndex].top
391
+ this.infiniteListStyle = `transform: translateY(${offset}px)`
392
+ } else {
393
+ this.infiniteListStyle = `transform: translateY(${this.positions[0].top}px)`
394
+ }
395
+ },
396
+ getItemHeight(item, index, key) {
397
+ const { value, getter } = this[key]
398
+ if (typeof getter === 'function') {
399
+ return getter(item, index) || 0
400
+ } else {
401
+ return value || 0
402
+ }
403
+ },
404
+ onScroll(e) {
405
+ const { scrollTop } = e.detail
406
+ const newStart = this.getStartIndex(scrollTop)
407
+ // 只有当start发生足够变化时才更新,避免滚动触发重渲染
408
+ if (Math.abs(newStart - this.end) >= Math.floor(this.belowCount / 2)) {
409
+ this.start = newStart
410
+ this.end = this.start + this.visibleCount
411
+ this.setStartOffset()
412
+ }
413
+
414
+ this.triggerEvent('scroll', e)
415
+ },
416
+ onScrolltolower(e) {
417
+ this.triggerEvent('scrolltolower', e)
418
+ },
419
+ onRefresherrefresh(e) {
420
+ this.triggerEvent('refresherrefresh', e)
421
+ },
422
+ scrollToIndex({ index, viewPosition = 0 }) {
423
+ const isStickyHeader = this._listData[index].itemData?.isSectionHeader
424
+ let prevHeaderHeight = 0
425
+ // 如果不是sticky header 查找最近一个吸顶的 sticky header
426
+ if (!isStickyHeader && this.enableSticky) {
427
+ for (let i = index - 1; i >= 0; i--) {
428
+ if (this._listData[i].itemData?.isSectionHeader) {
429
+ prevHeaderHeight = this.positions[i].height
430
+ break
431
+ }
432
+ }
433
+ }
434
+
435
+ const itemTop = (this.positions[index]?.top || 0) - prevHeaderHeight
436
+ const itemHeight = this.positions[index]?.height || 0
437
+ const containerHeight = this.containerHeight
438
+
439
+ let targetTop = itemTop
440
+ if (viewPosition === 1) {
441
+ // 滚动到可视区底部
442
+ targetTop = itemTop - (containerHeight - itemHeight)
443
+ } else if (viewPosition === 0.5) {
444
+ // 滚动到可视区中央
445
+ targetTop = itemTop - (containerHeight - itemHeight) / 2
446
+ }
447
+ // 支付宝小程序不支持 animated 参数,也不支持 scrollTo 方法滚动
448
+ this.scrollTop = targetTop
449
+
450
+ setTimeout(() => {
451
+ this.refreshStickyHeader()
452
+ }, this.scrollAnimationDuration + 100)
453
+ },
454
+ refreshStickyHeader() {
455
+ if (!this.$refs.stickyHeader) return
456
+
457
+ this.$refs.stickyHeader.forEach((header) => {
458
+ if (header && header.refresh) {
459
+ header.refresh()
460
+ }
461
+ })
462
+ }
463
+ }
464
+ })
465
+ </script>
466
+
467
+ <style scoped>
468
+ .scroll-view-container {
469
+ position: relative;
470
+ }
471
+ .mpx-recycle-view {
472
+ position: relative;
473
+ overflow: hidden;
474
+ }
475
+
476
+ .content-wrapper {
477
+ position: relative;
478
+ width: 100%;
479
+ }
480
+
481
+ .infinite-list {
482
+ left: 0;
483
+ right: 0;
484
+ top: 0;
485
+ position: absolute;
486
+ will-change: transform;
487
+ -webkit-backface-visibility: hidden;
488
+ backface-visibility: hidden;
489
+ /* 支付宝环境需要设置允许事件穿透, 否则滑不动 */
490
+ /* @mpx-if (__mpx_mode__ === 'ali') */
491
+ pointer-events: none;
492
+ /* @mpx-endif */
493
+ }
494
+ .sticky-section {
495
+ position: absolute;
496
+ width: 100%;
497
+ height: 100%;
498
+ }
499
+ </style>
500
+ <script type="application/json">
501
+ {
502
+ "disableScroll": true,
503
+ "usingComponents": {
504
+ "sticky-header": "./mpx-sticky-header.mpx"
505
+ },
506
+ "componentGenerics": {
507
+ "recycle-item": {
508
+ "default": "../wx/mpx-recycle-item-default.mpx"
509
+ },
510
+ "section-header": {
511
+ "default": "../wx/mpx-section-header-default.mpx"
512
+ },
513
+ "list-header": {
514
+ "default": "../wx/mpx-list-header-default.mpx"
515
+ }
516
+ }
517
+ }
518
+ </script>