@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.0

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 (140) hide show
  1. package/lib/index.js +13 -8
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +35 -38
  4. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  9. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  10. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  11. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  12. package/lib/react/processStyles.js +14 -4
  13. package/lib/react/processTemplate.js +3 -0
  14. package/lib/resolver/AddModePlugin.js +8 -8
  15. package/lib/runtime/components/react/context.ts +6 -0
  16. package/lib/runtime/components/react/dist/context.js +2 -0
  17. package/lib/runtime/components/react/dist/event.config.js +24 -24
  18. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  19. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  20. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  21. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  22. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  23. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  29. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  30. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  31. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  32. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  33. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  34. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  35. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  36. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  37. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  38. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  39. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  40. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  41. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  44. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  46. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  47. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  48. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  49. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  50. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  51. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  52. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  53. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  54. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  55. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  56. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  57. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  58. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  59. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  60. package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
  61. package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
  62. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  63. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  64. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  65. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  66. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  67. package/lib/runtime/components/react/dist/utils.jsx +70 -23
  68. package/lib/runtime/components/react/event.config.ts +25 -26
  69. package/lib/runtime/components/react/getInnerListeners.ts +237 -199
  70. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  71. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  72. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  73. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  74. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  75. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  76. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  77. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  78. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  79. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  80. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  81. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  82. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  83. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  84. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  85. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  86. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  87. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  88. package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
  89. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  90. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  91. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  92. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  93. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  95. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  96. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  97. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  98. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  99. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  100. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  101. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  102. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  103. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  104. package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
  105. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  106. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  107. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  108. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  109. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  110. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  111. package/lib/runtime/components/react/mpx-view.tsx +92 -76
  112. package/lib/runtime/components/react/mpx-web-view.tsx +116 -54
  113. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  114. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  115. package/lib/runtime/components/react/types/common.ts +2 -0
  116. package/lib/runtime/components/react/types/global.d.ts +5 -17
  117. package/lib/runtime/components/react/useAnimationHooks.ts +36 -11
  118. package/lib/runtime/components/react/utils.tsx +99 -28
  119. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  120. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  121. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  122. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  123. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  124. package/lib/runtime/optionProcessor.js +7 -38
  125. package/lib/runtime/utils.js +2 -0
  126. package/lib/style-compiler/plugins/scope-id.js +30 -2
  127. package/lib/template-compiler/bind-this.js +7 -2
  128. package/lib/template-compiler/compiler.js +79 -47
  129. package/lib/template-compiler/gen-node-react.js +3 -3
  130. package/lib/utils/pre-process-json.js +9 -5
  131. package/package.json +6 -4
  132. package/LICENSE +0 -433
  133. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  134. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  135. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  136. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  137. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  138. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  139. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  140. package/lib/runtime/components/web/event.js +0 -105
@@ -1,9 +1,8 @@
1
1
  import { View } from 'react-native';
2
- import { LinearGradient } from 'react-native-linear-gradient';
3
- import React, { forwardRef, useState, useRef } from 'react';
2
+ import React, { forwardRef, useRef } from 'react';
4
3
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
5
- import useNodesRef from './useNodesRef'; // 引入辅助函数
6
- import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from './utils';
4
+ import useNodesRef from './useNodesRef';
5
+ import { useLayout, splitProps, splitStyle, wrapChildren, parseInlineStyle, useTransformStyle, extendObject } from './utils';
7
6
  const styles = {
8
7
  wrapper: {
9
8
  display: 'flex',
@@ -12,84 +11,72 @@ const styles = {
12
11
  justifyContent: 'space-around',
13
12
  overflow: 'hidden',
14
13
  alignItems: 'center'
15
- },
16
- maskTop: {
17
- position: 'absolute',
18
- width: 1000,
19
- zIndex: 100
20
- },
21
- maskBottom: {
22
- position: 'absolute',
23
- width: 1000,
24
- zIndex: 100
25
14
  }
26
15
  };
16
+ const DefaultPickerItemH = 36;
27
17
  const _PickerView = forwardRef((props, ref) => {
28
18
  const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
29
- // indicatorStyle 需要转换为rn的style
30
- // 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
31
19
  const indicatorStyle = parseInlineStyle(props['indicator-style']);
32
- const { height: indicatorH, width: indicatorW } = indicatorStyle;
20
+ const pickerMaskStyle = parseInlineStyle(props['mask-style']);
21
+ const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle;
33
22
  const nodeRef = useRef(null);
34
- useNodesRef(props, ref, nodeRef, {});
35
- // picker-view 设置的color等textStyle,在小程序上的表现是可以继承到最内层的text样式, 但是RN内部column是slot无法设置, 需要业务自己在column内的元素上设置
23
+ const cloneRef = useRef(null);
24
+ const activeValueRef = useRef(value);
25
+ activeValueRef.current = value.slice();
26
+ const snapActiveValueRef = useRef(null);
27
+ console.log('[mpx-picker-view] value=', value, Date.now());
36
28
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
37
- const { textStyle } = splitStyle(normalStyle);
29
+ useNodesRef(props, ref, nodeRef, {
30
+ style: normalStyle
31
+ });
32
+ const { layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
38
33
  const { textProps } = splitProps(props);
39
- const {
40
- // 存储layout布局信息
41
- layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
42
- const isSetW = indicatorW !== undefined ? 1 : 0;
43
- const cloneRef = useRef(null);
44
- const maskPos = {};
45
- let [pickH, setPickH] = useState(0);
46
- const itemH = pickH / 5;
47
- if (normalStyle?.height && pickH && pickH !== normalStyle?.height) {
48
- maskPos.height = itemH * 2 + Math.ceil((normalStyle.height - pickH) / 2);
49
- }
50
- else {
51
- maskPos.height = itemH * 2;
52
- }
53
- const onColumnLayoutChange = (layoutConfig) => {
54
- pickH = layoutConfig.height;
55
- setPickH(layoutConfig.height);
34
+ const { textStyle } = splitStyle(normalStyle);
35
+ const onSelectChange = (columnIndex, selectedIndex) => {
36
+ const activeValue = activeValueRef.current;
37
+ activeValue[columnIndex] = selectedIndex;
38
+ console.log('[mpx-picker-view], onSelectChange ---> columnIndex=', columnIndex, 'selectedIndex=', selectedIndex, 'activeValue=', activeValue);
39
+ const eventData = getCustomEvent('change', {}, { detail: { value: activeValue, source: 'change' }, layoutRef });
40
+ bindchange?.(eventData);
41
+ snapActiveValueRef.current = activeValueRef.current;
42
+ };
43
+ const hasDiff = (a = [], b) => {
44
+ return a.some((v, i) => v !== b[i]);
56
45
  };
57
- const onSelectChange = (columnIndex, selIndex) => {
58
- const changeValue = value.slice();
59
- changeValue[columnIndex] = selIndex;
60
- const eventData = getCustomEvent('change', {}, { detail: { value: changeValue, source: 'change' }, layoutRef });
61
- bindchange && bindchange(eventData);
46
+ const onInitialChange = (isInvalid, value) => {
47
+ if (isInvalid || !snapActiveValueRef.current || hasDiff(snapActiveValueRef.current, value)) {
48
+ console.log('[mpx-picker-view], onInitialChange-1 ===> value=', value);
49
+ const eventData = getCustomEvent('change', {}, { detail: { value, source: 'change' }, layoutRef });
50
+ bindchange?.(eventData);
51
+ snapActiveValueRef.current = value.slice();
52
+ }
62
53
  };
63
- const innerProps = useInnerProps(props, {
54
+ const innerProps = useInnerProps(props, extendObject({
64
55
  ref: nodeRef,
65
- style: {
66
- ...normalStyle,
67
- ...layoutStyle,
56
+ style: extendObject({}, normalStyle, layoutStyle, {
68
57
  position: 'relative',
69
58
  overflow: 'hidden'
70
- },
71
- ...layoutProps
72
- }, [
73
- 'enable-offset'
74
- ], { layoutRef });
75
- const cloneChild = (child, index) => {
76
- // const extraProps = index === 0 ? { getInnerLayout: getInnerLayout, innerProps } : {}
77
- const extraProps = {};
78
- const childProps = {
79
- ...child?.props,
59
+ }),
60
+ layoutProps
61
+ }), ['enable-offset'], { layoutRef });
62
+ const renderColumn = (child, index, columnData, initialIndex) => {
63
+ const childProps = child?.props || {};
64
+ const wrappedProps = extendObject({}, childProps, {
65
+ columnData,
80
66
  ref: cloneRef,
81
- prefix: index,
82
- key: 'pick-view' + index,
67
+ columnIndex: index,
68
+ key: `pick-view-${index}`,
83
69
  wrapperStyle: {
84
- height: normalStyle?.height || 0,
85
- itemHeight: indicatorH || 0
70
+ height: normalStyle?.height || DefaultPickerItemH,
71
+ itemHeight: indicatorH || DefaultPickerItemH
86
72
  },
87
- onColumnLayoutChange,
73
+ columnStyle: normalStyle,
88
74
  onSelectChange: onSelectChange.bind(null, index),
89
- selectedIndex: value?.[index] || 0,
90
- ...extraProps
91
- };
92
- const realElement = React.cloneElement(child, childProps);
75
+ initialIndex,
76
+ pickerOverlayStyle,
77
+ pickerMaskStyle
78
+ });
79
+ const realElement = React.cloneElement(child, wrappedProps);
93
80
  return wrapChildren({
94
81
  children: realElement
95
82
  }, {
@@ -99,65 +86,37 @@ const _PickerView = forwardRef((props, ref) => {
99
86
  textProps
100
87
  });
101
88
  };
102
- const renderTopMask = () => {
103
- const linearProps = {
104
- colors: ['rgba(255,255,255,0.8)', 'rgba(255,255,255,0.2)'],
105
- style: [
106
- styles.maskTop,
107
- {
108
- height: maskPos.height,
109
- top: 0,
110
- pointerEvents: 'none'
111
- }
112
- ]
113
- };
114
- return (<LinearGradient {...linearProps}/>);
115
- };
116
- const renderBottomMask = () => {
117
- const linearProps = {
118
- colors: ['rgba(255,255,255,0.2)', 'rgba(255,255,255,0.8)'],
119
- style: [
120
- styles.maskBottom,
121
- {
122
- height: maskPos.height,
123
- bottom: 0,
124
- pointerEvents: 'none'
125
- }
126
- ]
127
- };
128
- return <LinearGradient {...linearProps}></LinearGradient>;
129
- };
130
- const renderLine = () => {
131
- return <View style={[{
132
- position: 'absolute',
133
- top: '50%',
134
- transform: [{ translateY: -(itemH / 2) }],
135
- height: itemH,
136
- borderTopWidth: 1,
137
- borderBottomWidth: 1,
138
- borderColor: '#f0f0f0',
139
- width: '100%',
140
- zIndex: 101
141
- }]}></View>;
89
+ const validateChildInitialIndex = (index, data) => {
90
+ return Math.max(0, Math.min(value[index] || 0, data.length - 1));
142
91
  };
143
- const renderSubChild = () => {
144
- if (Array.isArray(children)) {
145
- return children.map((item, index) => {
146
- return cloneChild(item, index);
147
- });
148
- }
149
- else {
150
- return cloneChild(children, 0);
92
+ const flatColumnChildren = (data) => {
93
+ const columnData = React.Children.toArray(data?.props?.children);
94
+ if (columnData.length === 1 && React.isValidElement(columnData[0]) && columnData[0].type === React.Fragment) {
95
+ // 只有一个 Fragment 嵌套情况
96
+ return React.Children.toArray(columnData[0].props.children);
151
97
  }
98
+ return columnData;
99
+ };
100
+ const renderPickerColumns = () => {
101
+ const columns = React.Children.toArray(children);
102
+ const renderColumns = [];
103
+ const validValue = [];
104
+ let isInvalid = false;
105
+ columns.forEach((item, index) => {
106
+ const columnData = flatColumnChildren(item);
107
+ const validIndex = validateChildInitialIndex(index, columnData);
108
+ if (validIndex !== value[index]) {
109
+ isInvalid = true;
110
+ }
111
+ validValue.push(validIndex);
112
+ renderColumns.push(renderColumn(item, index, columnData, validIndex));
113
+ });
114
+ onInitialChange(isInvalid, validValue);
115
+ return renderColumns;
152
116
  };
153
117
  return (<View {...innerProps}>
154
- {renderTopMask()}
155
- <View style={[styles.wrapper]}>
156
- {renderSubChild()}
157
- </View>
158
- {renderBottomMask()}
159
- {!isSetW && renderLine()}
160
- </View>);
118
+ <View style={[styles.wrapper]}>{renderPickerColumns()}</View>
119
+ </View>);
161
120
  });
162
- _PickerView.displayName = 'mpx-picker-view';
121
+ _PickerView.displayName = 'MpxPickerView';
163
122
  export default _PickerView;
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * ✔ bindchange
3
3
  */
4
- import { useRef, forwardRef, useContext, useMemo, useEffect } from 'react';
4
+ import { useRef, forwardRef, useContext, useMemo, useEffect, createElement } from 'react';
5
5
  import { View } from 'react-native';
6
6
  import { warn } from '@mpxjs/utils';
7
7
  import { FormContext, RadioGroupContext } from './context';
8
8
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
9
9
  import useNodesRef from './useNodesRef';
10
- import { useLayout, useTransformStyle, wrapChildren } from './utils';
10
+ import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
11
11
  const radioGroup = forwardRef((props, ref) => {
12
12
  const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
13
13
  const propsRef = useRef({});
@@ -22,13 +22,10 @@ const radioGroup = forwardRef((props, ref) => {
22
22
  flexDirection: 'row',
23
23
  flexWrap: 'wrap'
24
24
  };
25
- const styleObj = {
26
- ...defaultStyle,
27
- ...style
28
- };
25
+ const styleObj = extendObject({}, defaultStyle, style);
29
26
  const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
30
27
  const nodeRef = useRef(null);
31
- useNodesRef(props, ref, nodeRef, { defaultStyle });
28
+ useNodesRef(props, ref, nodeRef, { style: normalStyle });
32
29
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
33
30
  const getValue = () => {
34
31
  for (const key in groupValue) {
@@ -74,21 +71,16 @@ const radioGroup = forwardRef((props, ref) => {
74
71
  notifyChange
75
72
  };
76
73
  }, []);
77
- const innerProps = useInnerProps(props, {
74
+ const innerProps = useInnerProps(props, extendObject({
78
75
  ref: nodeRef,
79
- style: { ...normalStyle, ...layoutStyle },
80
- ...layoutProps
81
- }, [], {
76
+ style: extendObject({}, normalStyle, layoutStyle)
77
+ }, layoutProps), ['name'], {
82
78
  layoutRef
83
79
  });
84
- return (<View {...innerProps}>
85
- <RadioGroupContext.Provider value={contextValue}>
86
- {wrapChildren(props, {
87
- hasVarDec,
88
- varContext: varContextRef.current
89
- })}
90
- </RadioGroupContext.Provider>
91
- </View>);
80
+ return createElement(View, innerProps, createElement(RadioGroupContext.Provider, { value: contextValue }, wrapChildren(props, {
81
+ hasVarDec,
82
+ varContext: varContextRef.current
83
+ })));
92
84
  });
93
85
  radioGroup.displayName = 'MpxRadioGroup';
94
86
  export default radioGroup;
@@ -4,13 +4,13 @@
4
4
  * ✔ checked
5
5
  * ✔ color
6
6
  */
7
- import { useRef, useState, forwardRef, useEffect, useContext } from 'react';
7
+ import { useRef, useState, forwardRef, useEffect, useContext, createElement } from 'react';
8
8
  import { View, StyleSheet } from 'react-native';
9
9
  import { warn } from '@mpxjs/utils';
10
10
  import { LabelContext, RadioGroupContext } from './context';
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
12
12
  import useNodesRef from './useNodesRef';
13
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
14
14
  import Icon from './mpx-icon';
15
15
  const styles = StyleSheet.create({
16
16
  container: {
@@ -47,21 +47,14 @@ const styles = StyleSheet.create({
47
47
  });
48
48
  const Radio = forwardRef((radioProps, ref) => {
49
49
  const { textProps, innerProps: props = {} } = splitProps(radioProps);
50
- const { value = '', disabled = false, checked = false, color = '#09BB07', style = [], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap, catchtap } = props;
50
+ const { value = '', disabled = false, checked = false, color = '#09BB07', style = [], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap } = props;
51
51
  const [isChecked, setIsChecked] = useState(!!checked);
52
52
  const groupContext = useContext(RadioGroupContext);
53
53
  let groupValue;
54
54
  let notifyChange;
55
55
  const labelContext = useContext(LabelContext);
56
- const defaultStyle = {
57
- ...styles.wrapper,
58
- ...(isChecked && styles.wrapperChecked),
59
- ...(disabled && styles.wrapperDisabled)
60
- };
61
- const styleObj = {
62
- ...styles.container,
63
- ...style
64
- };
56
+ const defaultStyle = extendObject({}, styles.wrapper, isChecked ? styles.wrapperChecked : {}, disabled ? styles.wrapperDisabled : {});
57
+ const styleObj = extendObject({}, styles.container, style);
65
58
  const onChange = (evt) => {
66
59
  if (disabled || isChecked)
67
60
  return;
@@ -77,24 +70,17 @@ const Radio = forwardRef((radioProps, ref) => {
77
70
  notifyChange && notifyChange(evt);
78
71
  };
79
72
  const onTap = (evt) => {
80
- if (disabled)
81
- return;
82
73
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
83
74
  onChange(evt);
84
75
  };
85
- const catchTap = (evt) => {
86
- if (disabled)
87
- return;
88
- catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
89
- };
90
76
  const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
91
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
77
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
92
78
  if (backgroundStyle) {
93
79
  warn('Radio does not support background image-related styles!');
94
80
  }
95
81
  const nodeRef = useRef(null);
96
82
  useNodesRef(props, ref, nodeRef, {
97
- defaultStyle,
83
+ style: extendObject({}, defaultStyle, normalStyle),
98
84
  change: onChange
99
85
  });
100
86
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
@@ -105,13 +91,16 @@ const Radio = forwardRef((radioProps, ref) => {
105
91
  if (labelContext) {
106
92
  labelContext.current.triggerChange = onChange;
107
93
  }
108
- const innerProps = useInnerProps(props, {
94
+ const innerProps = useInnerProps(props, extendObject({
109
95
  ref: nodeRef,
110
- style: { ...innerStyle, ...layoutStyle },
111
- ...layoutProps,
112
- bindtap: onTap,
113
- catchtap: catchTap
114
- }, [], {
96
+ style: extendObject({}, innerStyle, layoutStyle)
97
+ }, layoutProps, {
98
+ bindtap: !disabled && onTap
99
+ }), [
100
+ 'value',
101
+ 'disabled',
102
+ 'checked'
103
+ ], {
115
104
  layoutRef
116
105
  });
117
106
  useEffect(() => {
@@ -135,21 +124,17 @@ const Radio = forwardRef((radioProps, ref) => {
135
124
  }
136
125
  }
137
126
  }, [checked]);
138
- return (<View {...innerProps}>
139
- <View style={defaultStyle}>
140
- <Icon type='success' size={24} color={disabled ? '#E1E1E1' : color} style={{
141
- ...styles.icon,
142
- ...(isChecked && styles.iconChecked),
143
- ...(disabled && styles.iconDisabled)
144
- }}/>
145
- </View>
146
- {wrapChildren(props, {
147
- hasVarDec,
148
- varContext: varContextRef.current,
149
- textStyle,
150
- textProps
151
- })}
152
- </View>);
127
+ return createElement(View, innerProps, createElement(View, { style: defaultStyle }, createElement(Icon, {
128
+ type: 'success',
129
+ size: 24,
130
+ color: disabled ? '#E1E1E1' : color,
131
+ style: extendObject({}, styles.icon, isChecked && styles.iconChecked, disabled && styles.iconDisabled)
132
+ })), wrapChildren(props, {
133
+ hasVarDec,
134
+ varContext: varContextRef.current,
135
+ textStyle,
136
+ textProps
137
+ }));
153
138
  });
154
139
  Radio.displayName = 'MpxRadio';
155
140
  export default Radio;
@@ -0,0 +1,39 @@
1
+ export const generateHTML = (html) => {
2
+ return `<html><head>
3
+ <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no" name="viewport">
4
+ <style>
5
+ html {
6
+ -ms-content-zooming: none;
7
+ -ms-touch-action: pan-x pan-y;
8
+ }
9
+ body {
10
+ position: fixed;
11
+ top: 0;
12
+ right: 0;
13
+ bottom: 0;
14
+ left: 0;
15
+ overflow: hidden;
16
+ }
17
+ html,body {
18
+ margin: 0;
19
+ padding: 0;
20
+ }
21
+ * {
22
+ user-select: none;
23
+ -ms-user-select: none;
24
+ -moz-user-select: none;
25
+ -webkit-user-select: none;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body><div id="rich-text">${html}</div>
30
+ <script>
31
+ function sendHeight() {
32
+ const dom = document.getElementById('rich-text')
33
+ window.ReactNativeWebView.postMessage(dom.scrollHeight);
34
+ }
35
+ window.onload = sendHeight;
36
+ </script>
37
+ </body
38
+ ></html>`;
39
+ };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * ✔ nodes
3
+ */
4
+ import { View } from 'react-native';
5
+ import { useRef, forwardRef, useState } from 'react';
6
+ import useInnerProps from '../getInnerListeners';
7
+ import useNodesRef from '../useNodesRef'; // 引入辅助函数
8
+ import { useTransformStyle, useLayout } from '../utils';
9
+ import { WebView } from 'react-native-webview';
10
+ import { generateHTML } from './html';
11
+ function jsonToHtmlStr(elements) {
12
+ let htmlStr = '';
13
+ for (const element of elements) {
14
+ if (element.type === 'text') {
15
+ htmlStr += element.text;
16
+ return htmlStr;
17
+ }
18
+ const { name, attrs = {}, children = [] } = element;
19
+ let attrStr = '';
20
+ for (const [key, value] of Object.entries(attrs))
21
+ attrStr += ` ${key}="${value}"`;
22
+ let childrenStr = '';
23
+ for (const child of children)
24
+ childrenStr += jsonToHtmlStr([child]);
25
+ htmlStr += `<${name}${attrStr}>${childrenStr}</${name}>`;
26
+ }
27
+ return htmlStr;
28
+ }
29
+ const _RichText = forwardRef((props, ref) => {
30
+ const { style = {}, nodes, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
31
+ const nodeRef = useRef(null);
32
+ const [webViewHeight, setWebViewHeight] = useState(0);
33
+ const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(Object.assign({
34
+ width: '100%',
35
+ height: webViewHeight
36
+ }, style), {
37
+ enableVar,
38
+ externalVarContext,
39
+ parentFontSize,
40
+ parentWidth,
41
+ parentHeight
42
+ });
43
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
44
+ useNodesRef(props, ref, nodeRef, {
45
+ layoutRef
46
+ });
47
+ const innerProps = useInnerProps(props, {
48
+ ref: nodeRef,
49
+ style: { ...normalStyle, ...layoutStyle },
50
+ ...layoutProps
51
+ }, [], {
52
+ layoutRef
53
+ });
54
+ const html = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes);
55
+ return (<View {...innerProps}>
56
+ <WebView source={{ html: generateHTML(html) }} onMessage={(event) => {
57
+ setWebViewHeight(+event.nativeEvent.data);
58
+ }}>
59
+ </WebView>
60
+ </View>);
61
+ });
62
+ _RichText.displayName = 'mpx-rich-text';
63
+ export default _RichText;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * ✔ enable
3
+ */
4
+ import { createElement, Fragment } from 'react';
1
5
  import { Portal } from '@ant-design/react-native';
2
6
  import { warn } from '@mpxjs/utils';
3
7
  const _RootPortal = (props) => {
@@ -6,10 +10,8 @@ const _RootPortal = (props) => {
6
10
  warn('The root-portal component does not support the style prop.');
7
11
  }
8
12
  return enable
9
- ? <Portal>
10
- {children}
11
- </Portal>
12
- : <>{children}</>;
13
+ ? createElement(Portal, null, children)
14
+ : createElement(Fragment, null, children);
13
15
  };
14
16
  _RootPortal.displayName = 'MpxRootPortal';
15
17
  export default _RootPortal;