@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,307 @@
1
+ import React, { forwardRef, useRef, useState, useEffect, useMemo, createElement, useImperativeHandle, useCallback } from 'react';
2
+ import { SectionList, RefreshControl } from 'react-native';
3
+ import useInnerProps, { getCustomEvent } from './getInnerListeners';
4
+ import { extendObject, useLayout, useTransformStyle } from './utils';
5
+ const getGeneric = (generichash, generickey) => {
6
+ if (!generichash || !generickey)
7
+ return null;
8
+ const GenericComponent = global.__mpxGenericsMap?.[generichash]?.[generickey]?.();
9
+ if (!GenericComponent)
10
+ return null;
11
+ return forwardRef((props, ref) => {
12
+ return createElement(GenericComponent, extendObject({}, {
13
+ ref: ref
14
+ }, props));
15
+ });
16
+ };
17
+ const getListHeaderComponent = (generichash, generickey, data) => {
18
+ if (!generichash || !generickey)
19
+ return undefined;
20
+ const ListHeaderComponent = getGeneric(generichash, generickey);
21
+ return ListHeaderComponent ? createElement(ListHeaderComponent, { listHeaderData: data }) : null;
22
+ };
23
+ const getSectionHeaderRenderer = (generichash, generickey) => {
24
+ if (!generichash || !generickey)
25
+ return undefined;
26
+ return (sectionData) => {
27
+ if (!sectionData.section.hasSectionHeader)
28
+ return null;
29
+ const SectionHeaderComponent = getGeneric(generichash, generickey);
30
+ return SectionHeaderComponent ? createElement(SectionHeaderComponent, { itemData: sectionData.section.headerData }) : null;
31
+ };
32
+ };
33
+ const getItemRenderer = (generichash, generickey) => {
34
+ if (!generichash || !generickey)
35
+ return undefined;
36
+ return ({ item }) => {
37
+ const ItemComponent = getGeneric(generichash, generickey);
38
+ return ItemComponent ? createElement(ItemComponent, { itemData: item }) : null;
39
+ };
40
+ };
41
+ const RecycleView = forwardRef((props = {}, ref) => {
42
+ const { enhanced = false, bounces = true, scrollEventThrottle = 0, height, width, listData, generichash, style = {}, itemHeight = {}, sectionHeaderHeight = {}, listHeaderHeight = {}, listHeaderData = null, useListHeader = false, 'genericrecycle-item': genericrecycleItem, 'genericsection-header': genericsectionHeader, 'genericlist-header': genericListHeader, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'enable-sticky': enableSticky = false, 'enable-back-to-top': enableBackToTop = false, 'end-reached-threshold': onEndReachedThreshold = 0.1, 'refresher-enabled': refresherEnabled, 'show-scrollbar': showScrollbar = true, 'refresher-triggered': refresherTriggered } = props;
43
+ const [refreshing, setRefreshing] = useState(!!refresherTriggered);
44
+ const scrollViewRef = useRef(null);
45
+ const indexMap = useRef({});
46
+ const reverseIndexMap = useRef({});
47
+ // 缓存 getGeneric 的结果,避免每次都创建新的组件引用
48
+ const genericComponentsCache = useRef({});
49
+ const getCachedGeneric = useCallback((generichash, generickey) => {
50
+ if (!generichash || !generickey)
51
+ return null;
52
+ const cacheKey = `${generichash}_${generickey}`;
53
+ if (!genericComponentsCache.current[cacheKey]) {
54
+ genericComponentsCache.current[cacheKey] = getGeneric(generichash, generickey);
55
+ }
56
+ return genericComponentsCache.current[cacheKey];
57
+ }, []);
58
+ // 使用 ref 存储最新的 props,避免渲染函数引用变化导致组件重新挂载
59
+ const propsRef = useRef({ generichash, genericrecycleItem, genericsectionHeader, genericListHeader, listHeaderData, useListHeader });
60
+ propsRef.current = { generichash, genericrecycleItem, genericsectionHeader, genericListHeader, listHeaderData, useListHeader };
61
+ // 创建稳定的渲染函数引用,使用 getCachedGeneric 确保组件引用稳定
62
+ const stableItemRenderer = useCallback(({ item }) => {
63
+ const { generichash: hash, genericrecycleItem: key } = propsRef.current;
64
+ const ItemComponent = getCachedGeneric(hash, key);
65
+ return ItemComponent ? createElement(ItemComponent, { itemData: item }) : null;
66
+ }, [getCachedGeneric]);
67
+ const stableSectionHeaderRenderer = useCallback((sectionData) => {
68
+ if (!sectionData.section.hasSectionHeader)
69
+ return null;
70
+ const { generichash: hash, genericsectionHeader: key } = propsRef.current;
71
+ const SectionHeaderComponent = getCachedGeneric(hash, key);
72
+ return SectionHeaderComponent ? createElement(SectionHeaderComponent, { itemData: sectionData.section.headerData }) : null;
73
+ }, [getCachedGeneric]);
74
+ // 创建稳定的 ListHeader 渲染函数,与 section-header 和 item 的处理方式一致
75
+ const getStableListHeader = useCallback(() => {
76
+ const { generichash: hash, genericListHeader: key, listHeaderData: data, useListHeader: use } = propsRef.current;
77
+ if (!use || !hash || !key)
78
+ return null;
79
+ const ListHeaderComponent = getCachedGeneric(hash, key);
80
+ return ListHeaderComponent ? createElement(ListHeaderComponent, { listHeaderData: data }) : null;
81
+ }, [getCachedGeneric]);
82
+ const { hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
83
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef });
84
+ useEffect(() => {
85
+ if (refreshing !== refresherTriggered) {
86
+ setRefreshing(!!refresherTriggered);
87
+ }
88
+ }, [refresherTriggered]);
89
+ const onRefresh = () => {
90
+ const { bindrefresherrefresh } = props;
91
+ bindrefresherrefresh &&
92
+ bindrefresherrefresh(getCustomEvent('refresherrefresh', {}, { layoutRef }, props));
93
+ };
94
+ const onEndReached = () => {
95
+ const { bindscrolltolower } = props;
96
+ bindscrolltolower &&
97
+ bindscrolltolower(getCustomEvent('scrolltolower', {}, { layoutRef }, props));
98
+ };
99
+ const onScroll = (event) => {
100
+ const { bindscroll } = props;
101
+ bindscroll &&
102
+ bindscroll(getCustomEvent('scroll', event.nativeEvent, { layoutRef }, props));
103
+ };
104
+ // 通过sectionIndex和rowIndex获取原始索引
105
+ const getOriginalIndex = (sectionIndex, rowIndex) => {
106
+ const key = `${sectionIndex}_${rowIndex}`;
107
+ return reverseIndexMap.current[key] ?? -1; // 如果找不到,返回-1
108
+ };
109
+ const scrollToIndex = ({ index, animated, viewOffset = 0, viewPosition = 0 }) => {
110
+ if (scrollViewRef.current) {
111
+ // 通过索引映射表快速定位位置
112
+ const position = indexMap.current[index];
113
+ const [sectionIndex, itemIndex] = position.split('_');
114
+ scrollViewRef.current.scrollToLocation?.({
115
+ itemIndex: itemIndex === 'header' ? 0 : Number(itemIndex) + 1,
116
+ sectionIndex: Number(sectionIndex) || 0,
117
+ animated,
118
+ viewOffset,
119
+ viewPosition
120
+ });
121
+ }
122
+ };
123
+ const getItemHeight = ({ sectionIndex, rowIndex }) => {
124
+ if (!itemHeight) {
125
+ return 0;
126
+ }
127
+ if (itemHeight.getter) {
128
+ const item = convertedListData[sectionIndex].data[rowIndex];
129
+ // 使用getOriginalIndex获取原始索引
130
+ const originalIndex = getOriginalIndex(sectionIndex, rowIndex);
131
+ return itemHeight.getter?.(item, originalIndex) || 0;
132
+ }
133
+ else {
134
+ return itemHeight.value || 0;
135
+ }
136
+ };
137
+ const getSectionHeaderHeight = ({ sectionIndex }) => {
138
+ const item = convertedListData[sectionIndex];
139
+ const { hasSectionHeader } = item;
140
+ // 使用getOriginalIndex获取原始索引
141
+ const originalIndex = getOriginalIndex(sectionIndex, 'header');
142
+ if (!hasSectionHeader)
143
+ return 0;
144
+ if (sectionHeaderHeight.getter) {
145
+ return sectionHeaderHeight.getter?.(item, originalIndex) || 0;
146
+ }
147
+ else {
148
+ return sectionHeaderHeight.value || 0;
149
+ }
150
+ };
151
+ const convertedListData = useMemo(() => {
152
+ const sections = [];
153
+ let currentSection = null;
154
+ // 清空之前的索引映射
155
+ indexMap.current = {};
156
+ // 清空反向索引映射
157
+ reverseIndexMap.current = {};
158
+ listData.forEach((item, index) => {
159
+ if (item.isSectionHeader) {
160
+ // 如果已经存在一个 section,先把它添加到 sections 中
161
+ if (currentSection) {
162
+ sections.push(currentSection);
163
+ }
164
+ // 创建新的 section
165
+ currentSection = {
166
+ headerData: item,
167
+ data: [],
168
+ hasSectionHeader: true,
169
+ _originalItemIndex: index
170
+ };
171
+ // 为 section header 添加索引映射
172
+ const sectionIndex = sections.length;
173
+ indexMap.current[index] = `${sectionIndex}_header`;
174
+ // 添加反向索引映射
175
+ reverseIndexMap.current[`${sectionIndex}_header`] = index;
176
+ }
177
+ else {
178
+ // 如果没有当前 section,创建一个默认的
179
+ if (!currentSection) {
180
+ // 创建默认section (无header的section)
181
+ currentSection = {
182
+ headerData: null,
183
+ data: [],
184
+ hasSectionHeader: false,
185
+ _originalItemIndex: -1
186
+ };
187
+ }
188
+ // 将 item 添加到当前 section 的 data 中
189
+ const itemIndex = currentSection.data.length;
190
+ currentSection.data.push(extendObject({}, item, {
191
+ _originalItemIndex: index
192
+ }));
193
+ let sectionIndex;
194
+ // 为 item 添加索引映射 - 存储格式为: "sectionIndex_itemIndex"
195
+ if (!currentSection.hasSectionHeader && sections.length === 0) {
196
+ // 在默认section中(第一个且无header)
197
+ sectionIndex = 0;
198
+ indexMap.current[index] = `${sectionIndex}_${itemIndex}`;
199
+ }
200
+ else {
201
+ // 在普通section中
202
+ sectionIndex = sections.length;
203
+ indexMap.current[index] = `${sectionIndex}_${itemIndex}`;
204
+ }
205
+ // 添加反向索引映射
206
+ reverseIndexMap.current[`${sectionIndex}_${itemIndex}`] = index;
207
+ }
208
+ });
209
+ // 添加最后一个 section
210
+ if (currentSection) {
211
+ sections.push(currentSection);
212
+ }
213
+ return sections;
214
+ }, [listData]);
215
+ const { getItemLayout } = useMemo(() => {
216
+ const layouts = [];
217
+ let offset = 0;
218
+ if (useListHeader) {
219
+ // 计算列表头部的高度
220
+ offset += listHeaderHeight.getter?.() || listHeaderHeight.value || 0;
221
+ }
222
+ // 遍历所有 sections
223
+ convertedListData.forEach((section, sectionIndex) => {
224
+ // 添加 section header 的位置信息
225
+ const headerHeight = getSectionHeaderHeight({ sectionIndex });
226
+ layouts.push({
227
+ length: headerHeight,
228
+ offset,
229
+ index: layouts.length
230
+ });
231
+ offset += headerHeight;
232
+ // 添加该 section 中所有 items 的位置信息
233
+ section.data.forEach((item, itemIndex) => {
234
+ const contenteight = getItemHeight({ sectionIndex, rowIndex: itemIndex });
235
+ layouts.push({
236
+ length: contenteight,
237
+ offset,
238
+ index: layouts.length
239
+ });
240
+ offset += contenteight;
241
+ });
242
+ // 添加该 section 尾部位置信息
243
+ // 因为即使 sectionList 没传 renderSectionFooter,getItemLayout 中的 index 的计算也会包含尾部节点
244
+ layouts.push({
245
+ length: 0,
246
+ offset,
247
+ index: layouts.length
248
+ });
249
+ });
250
+ return {
251
+ itemLayouts: layouts,
252
+ getItemLayout: (data, index) => layouts[index]
253
+ };
254
+ }, [convertedListData, useListHeader, itemHeight.value, itemHeight.getter, sectionHeaderHeight.value, sectionHeaderHeight.getter, listHeaderHeight.value, listHeaderHeight.getter]);
255
+ const scrollAdditionalProps = extendObject({
256
+ alwaysBounceVertical: false,
257
+ alwaysBounceHorizontal: false,
258
+ scrollEventThrottle: scrollEventThrottle,
259
+ scrollsToTop: enableBackToTop,
260
+ showsHorizontalScrollIndicator: showScrollbar,
261
+ onEndReachedThreshold,
262
+ ref: scrollViewRef,
263
+ bounces: false,
264
+ stickySectionHeadersEnabled: enableSticky,
265
+ onScroll: onScroll,
266
+ onEndReached: onEndReached
267
+ }, layoutProps);
268
+ if (enhanced) {
269
+ Object.assign(scrollAdditionalProps, {
270
+ bounces
271
+ });
272
+ }
273
+ if (refresherEnabled) {
274
+ Object.assign(scrollAdditionalProps, {
275
+ refreshing: refreshing
276
+ });
277
+ }
278
+ useImperativeHandle(ref, () => {
279
+ return {
280
+ ...props,
281
+ scrollToIndex
282
+ };
283
+ });
284
+ const innerProps = useInnerProps(extendObject({}, props, scrollAdditionalProps), [
285
+ 'id',
286
+ 'show-scrollbar',
287
+ 'lower-threshold',
288
+ 'refresher-triggered',
289
+ 'refresher-enabled',
290
+ 'bindrefresherrefresh'
291
+ ], { layoutRef });
292
+ return createElement(SectionList, extendObject({
293
+ style: [{ height, width }, style, layoutStyle],
294
+ sections: convertedListData,
295
+ renderItem: stableItemRenderer,
296
+ getItemLayout: getItemLayout,
297
+ ListHeaderComponent: getStableListHeader(),
298
+ renderSectionHeader: stableSectionHeaderRenderer,
299
+ refreshControl: refresherEnabled
300
+ ? React.createElement(RefreshControl, {
301
+ onRefresh: onRefresh,
302
+ refreshing: refreshing
303
+ })
304
+ : undefined
305
+ }, innerProps));
306
+ });
307
+ export default RecycleView;
@@ -0,0 +1 @@
1
+ export declare const generateHTML: (html: string) => string;
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * ✔ nodes
4
+ */
5
+ import { View, ViewProps, ViewStyle } from 'react-native';
6
+ import { HandlerRef } from '../useNodesRef';
7
+ type Node = {
8
+ type: 'node' | 'text';
9
+ name?: string;
10
+ attrs?: any;
11
+ children?: Array<Node>;
12
+ text: string;
13
+ };
14
+ interface _RichTextProps extends ViewProps {
15
+ style?: ViewStyle;
16
+ nodes: string | Array<Node>;
17
+ 'enable-var'?: boolean;
18
+ 'external-var-context'?: Record<string, any>;
19
+ 'parent-font-size'?: number;
20
+ 'parent-width'?: number;
21
+ 'parent-height'?: number;
22
+ }
23
+ declare const _RichText: import("react").ForwardRefExoticComponent<_RichTextProps & import("react").RefAttributes<HandlerRef<View, _RichTextProps>>>;
24
+ export default _RichText;
@@ -66,5 +66,5 @@ const _RichText = forwardRef((props, ref) => {
66
66
  }
67
67
  return finalComponent;
68
68
  });
69
- _RichText.displayName = 'mpx-rich-text';
69
+ _RichText.displayName = 'MpxRichText';
70
70
  export default _RichText;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * ✔ enable
3
+ */
4
+ import { ReactNode } from 'react';
5
+ interface RootPortalProps {
6
+ enable?: boolean;
7
+ children: ReactNode;
8
+ [x: string]: any;
9
+ }
10
+ declare const _RootPortal: {
11
+ (props: RootPortalProps): import("react").FunctionComponentElement<import("./mpx-portal/index").PortalProps>;
12
+ displayName: string;
13
+ };
14
+ export default _RootPortal;
@@ -0,0 +1,54 @@
1
+ import { View, NativeSyntheticEvent, NativeScrollEvent, ViewStyle } from 'react-native';
2
+ import { ReactNode } from 'react';
3
+ import { HandlerRef } from './useNodesRef';
4
+ import { GestureHandler } from './utils';
5
+ interface ScrollViewProps {
6
+ children?: ReactNode;
7
+ enhanced?: boolean;
8
+ bounces?: boolean;
9
+ style?: ViewStyle;
10
+ 'scroll-x'?: boolean;
11
+ 'scroll-y'?: boolean;
12
+ 'enable-back-to-top'?: boolean;
13
+ 'show-scrollbar'?: boolean;
14
+ 'paging-enabled'?: boolean;
15
+ 'upper-threshold'?: number;
16
+ 'lower-threshold'?: number;
17
+ 'scroll-with-animation'?: boolean;
18
+ 'refresher-triggered'?: boolean;
19
+ 'refresher-enabled'?: boolean;
20
+ 'refresher-default-style'?: 'black' | 'white' | 'none';
21
+ 'refresher-background'?: string;
22
+ 'refresher-threshold'?: number;
23
+ 'scroll-top'?: number;
24
+ 'scroll-left'?: number;
25
+ 'enable-offset'?: boolean;
26
+ 'scroll-into-view'?: string;
27
+ 'enable-trigger-intersection-observer'?: boolean;
28
+ 'enable-var'?: boolean;
29
+ 'external-var-context'?: Record<string, any>;
30
+ 'parent-font-size'?: number;
31
+ 'parent-width'?: number;
32
+ 'parent-height'?: number;
33
+ 'enable-sticky'?: boolean;
34
+ 'wait-for'?: Array<GestureHandler>;
35
+ 'simultaneous-handlers'?: Array<GestureHandler>;
36
+ 'scroll-event-throttle'?: number;
37
+ 'scroll-into-view-offset'?: number;
38
+ bindscrolltoupper?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
39
+ bindscrolltolower?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
40
+ bindscroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
41
+ bindrefresherrefresh?: (event: NativeSyntheticEvent<unknown>) => void;
42
+ binddragstart?: (event: NativeSyntheticEvent<DragEvent>) => void;
43
+ binddragging?: (event: NativeSyntheticEvent<DragEvent>) => void;
44
+ binddragend?: (event: NativeSyntheticEvent<DragEvent>) => void;
45
+ bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
46
+ bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
47
+ bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
48
+ bindscrollend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
49
+ __selectRef?: (selector: string, nodeType: 'node' | 'component', all?: boolean) => HandlerRef<any, any>;
50
+ }
51
+ declare const _ScrollView: import("react").ForwardRefExoticComponent<ScrollViewProps & import("react").RefAttributes<HandlerRef<import("react").ForwardRefExoticComponent<import("react-native").ScrollViewProps & {
52
+ children?: ReactNode;
53
+ } & import("react-native-gesture-handler").NativeViewGestureHandlerProps & import("react").RefAttributes<import("react").ComponentType<any>>> & import("react-native").ScrollView & View, ScrollViewProps>>>;
54
+ export default _ScrollView;
@@ -48,8 +48,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
48
48
  const scrollOffset = useRef(new RNAnimated.Value(0)).current;
49
49
  const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
50
50
  const waitForHandlers = flatGesture(waitFor);
51
- const snapScrollTop = useRef(0);
52
- const snapScrollLeft = useRef(0);
53
51
  const [refreshing, setRefreshing] = useState(false);
54
52
  const [enableScroll, setEnableScroll] = useState(true);
55
53
  const enableScrollValue = useSharedValue(true);
@@ -127,14 +125,12 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
127
125
  warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion');
128
126
  }
129
127
  useEffect(() => {
130
- if (snapScrollTop.current !== scrollTop || snapScrollLeft.current !== scrollLeft) {
131
- initialTimeout.current = setTimeout(() => {
132
- scrollToOffset(scrollLeft, scrollTop);
133
- }, 0);
134
- return () => {
135
- initialTimeout.current && clearTimeout(initialTimeout.current);
136
- };
137
- }
128
+ initialTimeout.current = setTimeout(() => {
129
+ scrollToOffset(scrollLeft, scrollTop);
130
+ }, 0);
131
+ return () => {
132
+ initialTimeout.current && clearTimeout(initialTimeout.current);
133
+ };
138
134
  }, [scrollTop, scrollLeft]);
139
135
  useEffect(() => {
140
136
  if (scrollIntoView && __selectRef) {
@@ -316,10 +312,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
316
312
  function scrollToOffset(x = 0, y = 0, animated = scrollWithAnimation) {
317
313
  if (scrollViewRef.current) {
318
314
  scrollViewRef.current.scrollTo({ x, y, animated });
319
- scrollOptions.current.scrollLeft = x;
320
- scrollOptions.current.scrollTop = y;
321
- snapScrollLeft.current = x;
322
- snapScrollTop.current = y;
323
315
  }
324
316
  }
325
317
  function onScrollTouchMove(e) {
@@ -0,0 +1,7 @@
1
+ import { TextProps } from 'react-native';
2
+ import { JSX } from 'react';
3
+ declare const SimpleText: {
4
+ (props: TextProps): JSX.Element;
5
+ displayName: string;
6
+ };
7
+ export default SimpleText;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { ViewProps } from 'react-native';
3
+ declare const SimpleView: {
4
+ (simpleViewProps: ViewProps): JSX.Element;
5
+ displayName: string;
6
+ };
7
+ export default SimpleView;
@@ -0,0 +1,30 @@
1
+ /// <reference types="react" />
2
+ import { View, ViewStyle } from 'react-native';
3
+ import { HandlerRef } from './useNodesRef';
4
+ export interface SliderProps {
5
+ min?: number;
6
+ max?: number;
7
+ step?: number;
8
+ disabled?: boolean;
9
+ value?: number;
10
+ color?: string;
11
+ 'selected-color'?: string;
12
+ activeColor?: string;
13
+ backgroundColor?: string;
14
+ 'block-size'?: number;
15
+ 'block-color'?: string;
16
+ name?: string;
17
+ bindchange?: (event: any) => void;
18
+ catchchange?: (event: any) => void;
19
+ bindchanging?: (event: any) => void;
20
+ catchchanging?: (event: any) => void;
21
+ style?: ViewStyle & Record<string, any>;
22
+ 'enable-offset'?: boolean;
23
+ 'enable-var'?: boolean;
24
+ 'external-var-context'?: Record<string, any>;
25
+ 'parent-font-size'?: number;
26
+ 'parent-width'?: number;
27
+ 'parent-height'?: number;
28
+ }
29
+ declare const Slider: import("react").ForwardRefExoticComponent<SliderProps & import("react").RefAttributes<HandlerRef<View, SliderProps>>>;
30
+ export default Slider;
@@ -0,0 +1,17 @@
1
+ import { ReactNode } from 'react';
2
+ import { View, NativeSyntheticEvent, ViewStyle } from 'react-native';
3
+ import { HandlerRef } from './useNodesRef';
4
+ interface StickyHeaderProps {
5
+ children?: ReactNode;
6
+ style?: ViewStyle;
7
+ padding?: [number, number, number, number];
8
+ 'offset-top'?: number;
9
+ 'enable-var'?: boolean;
10
+ 'external-var-context'?: Record<string, any>;
11
+ 'parent-font-size'?: number;
12
+ 'parent-width'?: number;
13
+ 'parent-height'?: number;
14
+ bindstickontopchange?: (e: NativeSyntheticEvent<unknown>) => void;
15
+ }
16
+ declare const _StickyHeader: import("react").ForwardRefExoticComponent<StickyHeaderProps & import("react").RefAttributes<HandlerRef<View, StickyHeaderProps>>>;
17
+ export default _StickyHeader;
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import { View, ViewStyle } from 'react-native';
3
+ import { HandlerRef } from './useNodesRef';
4
+ interface StickySectionProps {
5
+ children?: ReactNode;
6
+ style?: ViewStyle;
7
+ 'offset-top'?: number;
8
+ 'enable-var'?: boolean;
9
+ 'external-var-context'?: Record<string, any>;
10
+ 'parent-font-size'?: number;
11
+ 'parent-width'?: number;
12
+ 'parent-height'?: number;
13
+ }
14
+ declare const _StickySection: import("react").ForwardRefExoticComponent<StickySectionProps & import("react").RefAttributes<HandlerRef<View, StickySectionProps>>>;
15
+ export default _StickySection;
@@ -0,0 +1,18 @@
1
+ import { View } from 'react-native';
2
+ import { ReactNode } from 'react';
3
+ import { HandlerRef } from './useNodesRef';
4
+ interface SwiperItemProps {
5
+ 'item-id'?: string;
6
+ 'enable-offset'?: boolean;
7
+ 'enable-var': boolean;
8
+ 'external-var-context'?: Record<string, any>;
9
+ 'parent-font-size'?: number;
10
+ 'parent-width'?: number;
11
+ 'parent-height'?: number;
12
+ children?: ReactNode;
13
+ style?: Object;
14
+ customStyle: Object;
15
+ itemIndex: number;
16
+ }
17
+ declare const _SwiperItem: import("react").ForwardRefExoticComponent<SwiperItemProps & import("react").RefAttributes<HandlerRef<View, SwiperItemProps>>>;
18
+ export default _SwiperItem;
@@ -0,0 +1,63 @@
1
+ import { View, NativeSyntheticEvent } from 'react-native';
2
+ import React, { ReactNode } from 'react';
3
+ import { HandlerRef } from './useNodesRef';
4
+ import { GestureHandler } from './utils';
5
+ /**
6
+ * ✔ indicator-dots
7
+ * ✔ indicator-color
8
+ * ✔ indicator-width
9
+ * ✔ indicator-height
10
+ * ✔ indicator-radius
11
+ * ✔ indicator-spacing
12
+ * ✔ indicator-margin
13
+ * ✔ indicator-active-color
14
+ * ✔ autoplay
15
+ * ✔ current
16
+ * ✔ interval
17
+ * ✔ duration
18
+ * ✔ circular
19
+ * ✔ vertical
20
+ * ✔ previous-margin
21
+ * ✔ next-margin
22
+ * ✔ easing-function ="easeOutCubic"
23
+ * ✘ display-multiple-items
24
+ * ✘ snap-to-edge
25
+ */
26
+ type EaseType = 'default' | 'linear' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic';
27
+ interface SwiperProps {
28
+ children?: ReactNode;
29
+ circular?: boolean;
30
+ current?: number;
31
+ interval?: number;
32
+ autoplay?: boolean;
33
+ duration?: number;
34
+ scale?: boolean;
35
+ 'indicator-dots'?: boolean;
36
+ 'indicator-color'?: string;
37
+ 'indicator-width'?: number;
38
+ 'indicator-height'?: number;
39
+ 'indicator-spacing'?: number;
40
+ 'indicator-radius'?: number;
41
+ 'indicator-margin'?: number;
42
+ 'indicator-active-color'?: string;
43
+ vertical?: boolean;
44
+ style: {
45
+ [key: string]: any;
46
+ };
47
+ 'easing-function'?: EaseType;
48
+ 'previous-margin'?: string;
49
+ 'next-margin'?: string;
50
+ 'enable-offset'?: boolean;
51
+ 'enable-var': boolean;
52
+ 'parent-font-size'?: number;
53
+ 'parent-width'?: number;
54
+ 'parent-height'?: number;
55
+ 'external-var-context'?: Record<string, any>;
56
+ 'wait-for'?: Array<GestureHandler>;
57
+ 'simultaneous-handlers'?: Array<GestureHandler>;
58
+ disableGesture?: boolean;
59
+ 'display-multiple-items'?: number;
60
+ bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
61
+ }
62
+ declare const SwiperWrapper: React.ForwardRefExoticComponent<SwiperProps & React.RefAttributes<HandlerRef<View, SwiperProps>>>;
63
+ export default SwiperWrapper;