@mpxjs/webpack-plugin 2.10.17 → 2.10.18-beta.2

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