@mpxjs/webpack-plugin 2.9.70 → 2.9.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +3 -1
- package/lib/platform/template/wx/component-config/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/picker-view.js +1 -5
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/platform/template/wx/index.js +3 -5
- package/lib/react/processScript.js +2 -1
- package/lib/react/script-helper.js +5 -1
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -31
- package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +93 -58
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +151 -127
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +38 -34
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +11 -4
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +670 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +15 -53
- package/lib/runtime/components/react/dist/pickerFaces.js +7 -6
- package/lib/runtime/components/react/dist/pickerVIewContext.js +14 -0
- package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +23 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +20 -2
- package/lib/runtime/components/react/dist/utils.jsx +74 -11
- package/lib/runtime/components/react/getInnerListeners.ts +43 -32
- package/lib/runtime/components/react/mpx-button.tsx +20 -57
- package/lib/runtime/components/react/mpx-movable-view.tsx +119 -74
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
- package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +12 -18
- package/lib/runtime/components/react/mpx-scroll-view.tsx +21 -10
- package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
- package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
- package/lib/runtime/components/react/mpx-view.tsx +18 -65
- package/lib/runtime/components/react/pickerFaces.ts +10 -7
- package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
- package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
- package/lib/runtime/components/react/types/global.d.ts +10 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +24 -3
- package/lib/runtime/components/react/utils.tsx +85 -12
- package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
- package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
- package/lib/template-compiler/compiler.js +62 -14
- package/lib/wxss/loader.js +15 -2
- package/package.json +3 -3
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -480
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +0 -21
- package/lib/runtime/components/react/dist/types/common.js +0 -1
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -1
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
- /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { View } from 'react-native';
|
|
2
|
-
import React, { forwardRef,
|
|
2
|
+
import React, { forwardRef, useRef } from 'react';
|
|
3
3
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
4
4
|
import useNodesRef from './useNodesRef';
|
|
5
|
-
import { useLayout, splitProps, splitStyle, wrapChildren,
|
|
5
|
+
import { useLayout, splitProps, splitStyle, wrapChildren, useTransformStyle, extendObject } from './utils';
|
|
6
|
+
import { PickerViewStyleContext } from './pickerVIewContext';
|
|
6
7
|
const styles = {
|
|
7
8
|
wrapper: {
|
|
8
9
|
display: 'flex',
|
|
@@ -13,42 +14,38 @@ const styles = {
|
|
|
13
14
|
alignItems: 'center'
|
|
14
15
|
}
|
|
15
16
|
};
|
|
17
|
+
const DefaultPickerItemH = 36;
|
|
16
18
|
const _PickerView = forwardRef((props, ref) => {
|
|
17
|
-
const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
|
|
18
|
-
|
|
19
|
-
// 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
|
|
20
|
-
const indicatorStyle = parseInlineStyle(props['indicator-style']);
|
|
21
|
-
const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle;
|
|
22
|
-
const [pickMaxH, setPickMaxH] = useState(0);
|
|
19
|
+
const { children, value = [], bindchange, style, 'indicator-style': indicatorStyle = {}, 'mask-style': pickerMaskStyle = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
|
|
20
|
+
const { height: indicatorH, ...pickerIndicatorStyle } = indicatorStyle;
|
|
23
21
|
const nodeRef = useRef(null);
|
|
24
22
|
const cloneRef = useRef(null);
|
|
25
23
|
const activeValueRef = useRef(value);
|
|
26
24
|
activeValueRef.current = value.slice();
|
|
25
|
+
const snapActiveValueRef = useRef(null);
|
|
27
26
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
28
27
|
useNodesRef(props, ref, nodeRef, {
|
|
29
28
|
style: normalStyle
|
|
30
29
|
});
|
|
31
|
-
const {
|
|
32
|
-
// 存储layout布局信息
|
|
33
|
-
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
|
|
30
|
+
const { layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
|
|
34
31
|
const { textProps } = splitProps(props);
|
|
35
32
|
const { textStyle } = splitStyle(normalStyle);
|
|
36
|
-
const onColumnItemRawHChange = (height) => {
|
|
37
|
-
if (height > pickMaxH) {
|
|
38
|
-
setPickMaxH(height);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const bindchangeDebounce = useDebounceCallback(useStableCallback(bindchange), 300);
|
|
42
33
|
const onSelectChange = (columnIndex, selectedIndex) => {
|
|
43
|
-
bindchangeDebounce.clear();
|
|
44
34
|
const activeValue = activeValueRef.current;
|
|
45
35
|
activeValue[columnIndex] = selectedIndex;
|
|
46
|
-
const eventData = getCustomEvent('change', {}, { detail: { value: activeValue, source: 'change' }, layoutRef });
|
|
47
|
-
|
|
36
|
+
const eventData = getCustomEvent('change', {}, { detail: { value: activeValue.slice(), source: 'change' }, layoutRef });
|
|
37
|
+
bindchange?.(eventData);
|
|
38
|
+
snapActiveValueRef.current = activeValueRef.current;
|
|
48
39
|
};
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
const hasDiff = (a = [], b) => {
|
|
41
|
+
return a.some((v, i) => v !== b[i]);
|
|
42
|
+
};
|
|
43
|
+
const onInitialChange = (isInvalid, value) => {
|
|
44
|
+
if (isInvalid || !snapActiveValueRef.current || hasDiff(snapActiveValueRef.current, value)) {
|
|
45
|
+
const eventData = getCustomEvent('change', {}, { detail: { value: value.slice(), source: 'change' }, layoutRef });
|
|
46
|
+
bindchange?.(eventData);
|
|
47
|
+
snapActiveValueRef.current = value.slice();
|
|
48
|
+
}
|
|
52
49
|
};
|
|
53
50
|
const innerProps = useInnerProps(props, extendObject({
|
|
54
51
|
ref: nodeRef,
|
|
@@ -57,9 +54,14 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
57
54
|
overflow: 'hidden'
|
|
58
55
|
}),
|
|
59
56
|
layoutProps
|
|
60
|
-
}), [
|
|
57
|
+
}), [
|
|
58
|
+
'enable-offset',
|
|
59
|
+
'indicator-style',
|
|
60
|
+
'indicator-class',
|
|
61
|
+
'mask-style',
|
|
62
|
+
'mask-class'
|
|
63
|
+
], { layoutRef });
|
|
61
64
|
const renderColumn = (child, index, columnData, initialIndex) => {
|
|
62
|
-
const extraProps = {};
|
|
63
65
|
const childProps = child?.props || {};
|
|
64
66
|
const wrappedProps = extendObject({}, childProps, {
|
|
65
67
|
columnData,
|
|
@@ -67,14 +69,14 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
67
69
|
columnIndex: index,
|
|
68
70
|
key: `pick-view-${index}`,
|
|
69
71
|
wrapperStyle: {
|
|
70
|
-
height: normalStyle?.height ||
|
|
71
|
-
itemHeight: indicatorH ||
|
|
72
|
+
height: normalStyle?.height || DefaultPickerItemH,
|
|
73
|
+
itemHeight: indicatorH || DefaultPickerItemH
|
|
72
74
|
},
|
|
73
|
-
onColumnItemRawHChange,
|
|
74
75
|
onSelectChange: onSelectChange.bind(null, index),
|
|
75
76
|
initialIndex,
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
pickerIndicatorStyle,
|
|
78
|
+
pickerMaskStyle
|
|
79
|
+
});
|
|
78
80
|
const realElement = React.cloneElement(child, wrappedProps);
|
|
79
81
|
return wrapChildren({
|
|
80
82
|
children: realElement
|
|
@@ -110,12 +112,14 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
110
112
|
validValue.push(validIndex);
|
|
111
113
|
renderColumns.push(renderColumn(item, index, columnData, validIndex));
|
|
112
114
|
});
|
|
113
|
-
isInvalid
|
|
115
|
+
onInitialChange(isInvalid, validValue);
|
|
114
116
|
return renderColumns;
|
|
115
117
|
};
|
|
116
|
-
return (<
|
|
117
|
-
<View
|
|
118
|
-
|
|
118
|
+
return (<PickerViewStyleContext.Provider value={textStyle}>
|
|
119
|
+
<View {...innerProps}>
|
|
120
|
+
<View style={[styles.wrapper]}>{renderPickerColumns()}</View>
|
|
121
|
+
</View>
|
|
122
|
+
</PickerViewStyleContext.Provider>);
|
|
119
123
|
});
|
|
120
124
|
_PickerView.displayName = 'MpxPickerView';
|
|
121
125
|
export default _PickerView;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* ✔ nodes
|
|
3
3
|
*/
|
|
4
4
|
import { View } from 'react-native';
|
|
5
|
-
import { useRef, forwardRef, useState } from 'react';
|
|
5
|
+
import { useRef, forwardRef, useState, createElement } from 'react';
|
|
6
6
|
import useInnerProps from '../getInnerListeners';
|
|
7
7
|
import useNodesRef from '../useNodesRef'; // 引入辅助函数
|
|
8
|
-
import { useTransformStyle, useLayout } from '../utils';
|
|
8
|
+
import { useTransformStyle, useLayout, extendObject } from '../utils';
|
|
9
9
|
import { WebView } from 'react-native-webview';
|
|
10
10
|
import { generateHTML } from './html';
|
|
11
11
|
function jsonToHtmlStr(elements) {
|
|
@@ -44,20 +44,19 @@ const _RichText = forwardRef((props, ref) => {
|
|
|
44
44
|
useNodesRef(props, ref, nodeRef, {
|
|
45
45
|
layoutRef
|
|
46
46
|
});
|
|
47
|
-
const innerProps = useInnerProps(props, {
|
|
47
|
+
const innerProps = useInnerProps(props, extendObject({
|
|
48
48
|
ref: nodeRef,
|
|
49
|
-
style:
|
|
50
|
-
|
|
51
|
-
}, [], {
|
|
49
|
+
style: extendObject(normalStyle, layoutStyle)
|
|
50
|
+
}, layoutProps), [], {
|
|
52
51
|
layoutRef
|
|
53
52
|
});
|
|
54
53
|
const html = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes);
|
|
55
|
-
return (
|
|
56
|
-
|
|
54
|
+
return createElement(View, innerProps, createElement(WebView, {
|
|
55
|
+
source: { html: generateHTML(html) },
|
|
56
|
+
onMessage: (event) => {
|
|
57
57
|
setWebViewHeight(+event.nativeEvent.data);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
</View>);
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
61
60
|
});
|
|
62
61
|
_RichText.displayName = 'mpx-rich-text';
|
|
63
62
|
export default _RichText;
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { ScrollView } from 'react-native-gesture-handler';
|
|
35
35
|
import { RefreshControl } from 'react-native';
|
|
36
|
-
import { useRef, useState, useEffect, forwardRef, useContext, createElement } from 'react';
|
|
36
|
+
import { useRef, useState, useEffect, forwardRef, useContext, createElement, useMemo } from 'react';
|
|
37
37
|
import { useAnimatedRef } from 'react-native-reanimated';
|
|
38
38
|
import { warn } from '@mpxjs/utils';
|
|
39
39
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
40
40
|
import useNodesRef from './useNodesRef';
|
|
41
41
|
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
|
|
42
|
-
import { IntersectionObserverContext } from './context';
|
|
42
|
+
import { IntersectionObserverContext, ScrollViewContext } from './context';
|
|
43
43
|
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
44
44
|
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
45
45
|
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchstart, bindtouchmove, bindtouchend, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, __selectRef } = props;
|
|
@@ -78,6 +78,11 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
78
78
|
},
|
|
79
79
|
gestureRef: scrollViewRef
|
|
80
80
|
});
|
|
81
|
+
const contextValue = useMemo(() => {
|
|
82
|
+
return {
|
|
83
|
+
gestureRef: scrollViewRef
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
81
86
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
|
|
82
87
|
if (scrollX && scrollY) {
|
|
83
88
|
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');
|
|
@@ -196,6 +201,8 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
196
201
|
layoutRef
|
|
197
202
|
}, props));
|
|
198
203
|
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
204
|
+
onStartReached(e);
|
|
205
|
+
onEndReached(e);
|
|
199
206
|
if (enableTriggerIntersectionObserver && intersectionObservers) {
|
|
200
207
|
for (const key in intersectionObservers) {
|
|
201
208
|
intersectionObservers[key].throttleMeasure();
|
|
@@ -342,12 +349,12 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
342
349
|
onRefresh: onRefresh
|
|
343
350
|
}, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
|
|
344
351
|
: undefined
|
|
345
|
-
}), wrapChildren(props, {
|
|
352
|
+
}), createElement(ScrollViewContext.Provider, { value: contextValue }, wrapChildren(props, {
|
|
346
353
|
hasVarDec,
|
|
347
354
|
varContext: varContextRef.current,
|
|
348
355
|
textStyle,
|
|
349
356
|
textProps
|
|
350
|
-
}));
|
|
357
|
+
})));
|
|
351
358
|
});
|
|
352
359
|
_ScrollView.displayName = 'MpxScrollView';
|
|
353
360
|
export default _ScrollView;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forwardRef, useRef } from 'react';
|
|
1
|
+
import Animated, { useAnimatedStyle, interpolate } from 'react-native-reanimated';
|
|
2
|
+
import { forwardRef, useRef, useContext } from 'react';
|
|
3
3
|
import useInnerProps from './getInnerListeners';
|
|
4
4
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
5
5
|
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils';
|
|
6
|
+
import { SwiperContext } from './context';
|
|
6
7
|
const _SwiperItem = forwardRef((props, ref) => {
|
|
7
|
-
const { 'enable-var': enableVar, 'external-var-context': externalVarContext, style } = props;
|
|
8
|
+
const { 'enable-var': enableVar, 'external-var-context': externalVarContext, style, customStyle, itemIndex } = props;
|
|
9
|
+
const contextValue = useContext(SwiperContext);
|
|
10
|
+
const offset = contextValue.offset || 0;
|
|
11
|
+
const step = contextValue.step || 0;
|
|
12
|
+
const scale = contextValue.scale || false;
|
|
13
|
+
const dir = contextValue.dir || 'x';
|
|
8
14
|
const { textProps } = splitProps(props);
|
|
9
15
|
const nodeRef = useRef(null);
|
|
10
16
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
@@ -16,21 +22,38 @@ const _SwiperItem = forwardRef((props, ref) => {
|
|
|
16
22
|
// 存储layout布局信息
|
|
17
23
|
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
|
|
18
24
|
const innerProps = useInnerProps(props, {
|
|
19
|
-
style: { ...innerStyle, ...layoutStyle },
|
|
20
25
|
ref: nodeRef,
|
|
21
26
|
...layoutProps
|
|
22
27
|
}, [
|
|
23
28
|
'children',
|
|
24
|
-
'enable-offset'
|
|
29
|
+
'enable-offset',
|
|
30
|
+
'style'
|
|
25
31
|
], { layoutRef });
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
const itemAnimatedStyle = useAnimatedStyle(() => {
|
|
33
|
+
if (!step.value)
|
|
34
|
+
return {};
|
|
35
|
+
const inputRange = [step.value, 0];
|
|
36
|
+
const outputRange = [0.7, 1];
|
|
37
|
+
// 实现元素的宽度跟随step从0到真实宽度,且不能触发重新渲染整个组件,通过AnimatedStyle的方式实现
|
|
38
|
+
const outerLayoutStyle = dir === 'x' ? { width: step.value, height: '100%' } : { width: '100%', height: step.value };
|
|
39
|
+
const transformStyle = [];
|
|
40
|
+
if (scale) {
|
|
41
|
+
transformStyle.push({
|
|
42
|
+
scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return Object.assign(outerLayoutStyle, {
|
|
46
|
+
transform: transformStyle
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return (<Animated.View {...innerProps} style={[innerStyle, layoutStyle, itemAnimatedStyle, customStyle]} data-itemId={props['item-id']}>
|
|
50
|
+
{wrapChildren(props, {
|
|
28
51
|
hasVarDec,
|
|
29
52
|
varContext: varContextRef.current,
|
|
30
53
|
textStyle,
|
|
31
54
|
textProps
|
|
32
55
|
})}
|
|
33
|
-
</View>);
|
|
56
|
+
</Animated.View>);
|
|
34
57
|
});
|
|
35
58
|
_SwiperItem.displayName = 'MpxSwiperItem';
|
|
36
59
|
export default _SwiperItem;
|