@mpxjs/webpack-plugin 2.9.69 → 2.9.70
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/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
- package/lib/runtime/components/react/dist/utils.jsx +107 -82
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -188
- package/lib/runtime/components/react/mpx-button.tsx +64 -50
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +55 -65
- package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
- package/lib/runtime/components/react/types/global.d.ts +3 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +113 -82
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +77 -46
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +5 -4
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
ReactNode,
|
|
9
9
|
useContext,
|
|
10
10
|
useMemo,
|
|
11
|
-
useEffect
|
|
11
|
+
useEffect,
|
|
12
|
+
createElement
|
|
12
13
|
} from 'react'
|
|
13
14
|
import {
|
|
14
15
|
View,
|
|
@@ -20,7 +21,7 @@ import { warn } from '@mpxjs/utils'
|
|
|
20
21
|
import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './context'
|
|
21
22
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
22
23
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
23
|
-
import { useLayout, useTransformStyle, wrapChildren } from './utils'
|
|
24
|
+
import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
|
|
24
25
|
|
|
25
26
|
export interface RadioGroupProps {
|
|
26
27
|
name: string
|
|
@@ -67,10 +68,7 @@ const radioGroup = forwardRef<
|
|
|
67
68
|
flexWrap: 'wrap'
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
const styleObj = {
|
|
71
|
-
...defaultStyle,
|
|
72
|
-
...style
|
|
73
|
-
}
|
|
71
|
+
const styleObj = extendObject({}, defaultStyle, style)
|
|
74
72
|
|
|
75
73
|
const {
|
|
76
74
|
hasSelfPercent,
|
|
@@ -82,7 +80,7 @@ const radioGroup = forwardRef<
|
|
|
82
80
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
83
81
|
|
|
84
82
|
const nodeRef = useRef(null)
|
|
85
|
-
useNodesRef(props, ref, nodeRef, {
|
|
83
|
+
useNodesRef(props, ref, nodeRef, { style: normalStyle })
|
|
86
84
|
|
|
87
85
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
88
86
|
|
|
@@ -144,31 +142,30 @@ const radioGroup = forwardRef<
|
|
|
144
142
|
|
|
145
143
|
const innerProps = useInnerProps(
|
|
146
144
|
props,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
extendObject(
|
|
146
|
+
{
|
|
147
|
+
ref: nodeRef,
|
|
148
|
+
style: extendObject({}, normalStyle, layoutStyle)
|
|
149
|
+
},
|
|
150
|
+
layoutProps
|
|
151
|
+
),
|
|
152
|
+
['name'],
|
|
153
153
|
{
|
|
154
154
|
layoutRef
|
|
155
155
|
}
|
|
156
156
|
)
|
|
157
157
|
|
|
158
|
-
return (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
</RadioGroupContext.Provider>
|
|
171
|
-
</View>
|
|
158
|
+
return createElement(View, innerProps, createElement(
|
|
159
|
+
RadioGroupContext.Provider,
|
|
160
|
+
{ value: contextValue },
|
|
161
|
+
wrapChildren(
|
|
162
|
+
props,
|
|
163
|
+
{
|
|
164
|
+
hasVarDec,
|
|
165
|
+
varContext: varContextRef.current
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
)
|
|
172
169
|
)
|
|
173
170
|
})
|
|
174
171
|
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* ✔ checked
|
|
5
5
|
* ✔ color
|
|
6
6
|
*/
|
|
7
|
-
import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction } from 'react'
|
|
7
|
+
import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction, createElement } from 'react'
|
|
8
8
|
import { View, StyleSheet, ViewStyle, NativeSyntheticEvent } 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, { HandlerRef } 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
|
|
|
16
16
|
export interface RadioProps {
|
|
@@ -27,7 +27,6 @@ export interface RadioProps {
|
|
|
27
27
|
'parent-height'?: number;
|
|
28
28
|
children: ReactNode
|
|
29
29
|
bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
30
|
-
catchtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
const styles = StyleSheet.create({
|
|
@@ -79,8 +78,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
79
78
|
'parent-font-size': parentFontSize,
|
|
80
79
|
'parent-width': parentWidth,
|
|
81
80
|
'parent-height': parentHeight,
|
|
82
|
-
bindtap
|
|
83
|
-
catchtap
|
|
81
|
+
bindtap
|
|
84
82
|
} = props
|
|
85
83
|
|
|
86
84
|
const [isChecked, setIsChecked] = useState<boolean>(!!checked)
|
|
@@ -91,16 +89,14 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
91
89
|
|
|
92
90
|
const labelContext = useContext(LabelContext)
|
|
93
91
|
|
|
94
|
-
const defaultStyle =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
const defaultStyle = extendObject(
|
|
93
|
+
{},
|
|
94
|
+
styles.wrapper,
|
|
95
|
+
isChecked ? styles.wrapperChecked : {},
|
|
96
|
+
disabled ? styles.wrapperDisabled : {}
|
|
97
|
+
)
|
|
99
98
|
|
|
100
|
-
const styleObj = {
|
|
101
|
-
...styles.container,
|
|
102
|
-
...style
|
|
103
|
-
}
|
|
99
|
+
const styleObj = extendObject({}, styles.container, style)
|
|
104
100
|
|
|
105
101
|
const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
106
102
|
if (disabled || isChecked) return
|
|
@@ -116,16 +112,10 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
116
112
|
}
|
|
117
113
|
|
|
118
114
|
const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
119
|
-
if (disabled) return
|
|
120
115
|
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
|
|
121
116
|
onChange(evt)
|
|
122
117
|
}
|
|
123
118
|
|
|
124
|
-
const catchTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
125
|
-
if (disabled) return
|
|
126
|
-
catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props))
|
|
127
|
-
}
|
|
128
|
-
|
|
129
119
|
const {
|
|
130
120
|
hasSelfPercent,
|
|
131
121
|
normalStyle,
|
|
@@ -135,7 +125,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
135
125
|
setHeight
|
|
136
126
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
137
127
|
|
|
138
|
-
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
|
|
128
|
+
const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
139
129
|
|
|
140
130
|
if (backgroundStyle) {
|
|
141
131
|
warn('Radio does not support background image-related styles!')
|
|
@@ -143,7 +133,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
143
133
|
|
|
144
134
|
const nodeRef = useRef(null)
|
|
145
135
|
useNodesRef(props, ref, nodeRef, {
|
|
146
|
-
defaultStyle,
|
|
136
|
+
style: extendObject({}, defaultStyle, normalStyle),
|
|
147
137
|
change: onChange
|
|
148
138
|
})
|
|
149
139
|
|
|
@@ -160,14 +150,21 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
160
150
|
|
|
161
151
|
const innerProps = useInnerProps(
|
|
162
152
|
props,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
153
|
+
extendObject(
|
|
154
|
+
{
|
|
155
|
+
ref: nodeRef,
|
|
156
|
+
style: extendObject({}, innerStyle, layoutStyle)
|
|
157
|
+
},
|
|
158
|
+
layoutProps,
|
|
159
|
+
{
|
|
160
|
+
bindtap: !disabled && onTap
|
|
161
|
+
}
|
|
162
|
+
),
|
|
163
|
+
[
|
|
164
|
+
'value',
|
|
165
|
+
'disabled',
|
|
166
|
+
'checked'
|
|
167
|
+
],
|
|
171
168
|
{
|
|
172
169
|
layoutRef
|
|
173
170
|
}
|
|
@@ -196,32 +193,26 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
196
193
|
}
|
|
197
194
|
}, [checked])
|
|
198
195
|
|
|
199
|
-
return (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
</View>
|
|
196
|
+
return createElement(View, innerProps,
|
|
197
|
+
createElement(
|
|
198
|
+
View,
|
|
199
|
+
{ style: defaultStyle },
|
|
200
|
+
createElement(Icon, {
|
|
201
|
+
type: 'success',
|
|
202
|
+
size: 24,
|
|
203
|
+
color: disabled ? '#E1E1E1' : color,
|
|
204
|
+
style: extendObject({}, styles.icon, isChecked && styles.iconChecked, disabled && styles.iconDisabled)
|
|
205
|
+
})
|
|
206
|
+
),
|
|
207
|
+
wrapChildren(
|
|
208
|
+
props,
|
|
213
209
|
{
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
varContext: varContextRef.current,
|
|
219
|
-
textStyle,
|
|
220
|
-
textProps
|
|
221
|
-
}
|
|
222
|
-
)
|
|
210
|
+
hasVarDec,
|
|
211
|
+
varContext: varContextRef.current,
|
|
212
|
+
textStyle,
|
|
213
|
+
textProps
|
|
223
214
|
}
|
|
224
|
-
|
|
215
|
+
)
|
|
225
216
|
)
|
|
226
217
|
}
|
|
227
218
|
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
export const generateHTML = (html: string) => {
|
|
3
|
+
return `<html><head>
|
|
4
|
+
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no" name="viewport">
|
|
5
|
+
<style>
|
|
6
|
+
html {
|
|
7
|
+
-ms-content-zooming: none;
|
|
8
|
+
-ms-touch-action: pan-x pan-y;
|
|
9
|
+
}
|
|
10
|
+
body {
|
|
11
|
+
position: fixed;
|
|
12
|
+
top: 0;
|
|
13
|
+
right: 0;
|
|
14
|
+
bottom: 0;
|
|
15
|
+
left: 0;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
}
|
|
18
|
+
html,body {
|
|
19
|
+
margin: 0;
|
|
20
|
+
padding: 0;
|
|
21
|
+
}
|
|
22
|
+
* {
|
|
23
|
+
user-select: none;
|
|
24
|
+
-ms-user-select: none;
|
|
25
|
+
-moz-user-select: none;
|
|
26
|
+
-webkit-user-select: none;
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
29
|
+
</head>
|
|
30
|
+
<body><div id="rich-text">${html}</div>
|
|
31
|
+
<script>
|
|
32
|
+
function sendHeight() {
|
|
33
|
+
const dom = document.getElementById('rich-text')
|
|
34
|
+
window.ReactNativeWebView.postMessage(dom.scrollHeight);
|
|
35
|
+
}
|
|
36
|
+
window.onload = sendHeight;
|
|
37
|
+
</script>
|
|
38
|
+
</body
|
|
39
|
+
></html>`
|
|
40
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* ✔ nodes
|
|
4
|
+
*/
|
|
5
|
+
import { View, ViewProps, ViewStyle } from 'react-native'
|
|
6
|
+
import { useRef, forwardRef, JSX, useState } from 'react'
|
|
7
|
+
import useInnerProps from '../getInnerListeners'
|
|
8
|
+
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
9
|
+
import { useTransformStyle, useLayout } from '../utils'
|
|
10
|
+
import { WebView, WebViewMessageEvent } from 'react-native-webview'
|
|
11
|
+
import { generateHTML } from './html'
|
|
12
|
+
|
|
13
|
+
type Node = {
|
|
14
|
+
type: 'node' | 'text'
|
|
15
|
+
name?: string
|
|
16
|
+
attrs?: any
|
|
17
|
+
children?: Array<Node>
|
|
18
|
+
text: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface _RichTextProps extends ViewProps {
|
|
22
|
+
style?: ViewStyle
|
|
23
|
+
nodes: string | Array<Node>
|
|
24
|
+
'enable-var'?: boolean
|
|
25
|
+
'external-var-context'?: Record<string, any>
|
|
26
|
+
'parent-font-size'?: number
|
|
27
|
+
'parent-width'?: number
|
|
28
|
+
'parent-height'?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function jsonToHtmlStr (elements: Array<Node>) {
|
|
32
|
+
let htmlStr = ''
|
|
33
|
+
|
|
34
|
+
for (const element of elements) {
|
|
35
|
+
if (element.type === 'text') {
|
|
36
|
+
htmlStr += element.text
|
|
37
|
+
return htmlStr
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { name, attrs = {}, children = [] } = element
|
|
41
|
+
|
|
42
|
+
let attrStr = ''
|
|
43
|
+
for (const [key, value] of Object.entries(attrs)) attrStr += ` ${key}="${value}"`
|
|
44
|
+
|
|
45
|
+
let childrenStr = ''
|
|
46
|
+
for (const child of children) childrenStr += jsonToHtmlStr([child])
|
|
47
|
+
|
|
48
|
+
htmlStr += `<${name}${attrStr}>${childrenStr}</${name}>`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return htmlStr
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((props, ref): JSX.Element => {
|
|
55
|
+
const {
|
|
56
|
+
style = {},
|
|
57
|
+
nodes,
|
|
58
|
+
'enable-var': enableVar,
|
|
59
|
+
'external-var-context': externalVarContext,
|
|
60
|
+
'parent-font-size': parentFontSize,
|
|
61
|
+
'parent-width': parentWidth,
|
|
62
|
+
'parent-height': parentHeight
|
|
63
|
+
} = props
|
|
64
|
+
|
|
65
|
+
const nodeRef = useRef(null)
|
|
66
|
+
const [webViewHeight, setWebViewHeight] = useState(0)
|
|
67
|
+
|
|
68
|
+
const {
|
|
69
|
+
normalStyle,
|
|
70
|
+
hasSelfPercent,
|
|
71
|
+
setWidth,
|
|
72
|
+
setHeight
|
|
73
|
+
} = useTransformStyle(Object.assign({
|
|
74
|
+
width: '100%',
|
|
75
|
+
height: webViewHeight
|
|
76
|
+
}, style), {
|
|
77
|
+
enableVar,
|
|
78
|
+
externalVarContext,
|
|
79
|
+
parentFontSize,
|
|
80
|
+
parentWidth,
|
|
81
|
+
parentHeight
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const {
|
|
85
|
+
layoutRef,
|
|
86
|
+
layoutStyle,
|
|
87
|
+
layoutProps
|
|
88
|
+
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
89
|
+
|
|
90
|
+
useNodesRef<View, _RichTextProps>(props, ref, nodeRef, {
|
|
91
|
+
layoutRef
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const innerProps = useInnerProps(props, {
|
|
95
|
+
ref: nodeRef,
|
|
96
|
+
style: { ...normalStyle, ...layoutStyle },
|
|
97
|
+
...layoutProps
|
|
98
|
+
}, [], {
|
|
99
|
+
layoutRef
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const html: string = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes)
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<View
|
|
106
|
+
{...innerProps}
|
|
107
|
+
>
|
|
108
|
+
<WebView
|
|
109
|
+
source={{ html: generateHTML(html) }}
|
|
110
|
+
onMessage={(event: WebViewMessageEvent) => {
|
|
111
|
+
setWebViewHeight(+event.nativeEvent.data)
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
</WebView>
|
|
115
|
+
</View>
|
|
116
|
+
)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
_RichText.displayName = 'mpx-rich-text'
|
|
120
|
+
|
|
121
|
+
export default _RichText
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✔ enable
|
|
3
3
|
*/
|
|
4
|
-
import { ReactNode } from 'react'
|
|
4
|
+
import { ReactNode, createElement, Fragment } from 'react'
|
|
5
5
|
import { Portal } from '@ant-design/react-native'
|
|
6
6
|
import { warn } from '@mpxjs/utils'
|
|
7
7
|
interface RootPortalProps {
|
|
@@ -16,10 +16,8 @@ const _RootPortal = (props: RootPortalProps) => {
|
|
|
16
16
|
warn('The root-portal component does not support the style prop.')
|
|
17
17
|
}
|
|
18
18
|
return enable
|
|
19
|
-
?
|
|
20
|
-
|
|
21
|
-
</Portal>
|
|
22
|
-
: <>{children}</>
|
|
19
|
+
? createElement(Portal, null, children)
|
|
20
|
+
: createElement(Fragment, null, children)
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
_RootPortal.displayName = 'MpxRootPortal'
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { ScrollView } from 'react-native-gesture-handler'
|
|
35
35
|
import { View, RefreshControl, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
|
|
36
|
-
import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext } from 'react'
|
|
36
|
+
import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, createElement } 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, { HandlerRef } from './useNodesRef'
|
|
41
|
-
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, flatGesture, GestureHandler } from './utils'
|
|
41
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler } from './utils'
|
|
42
42
|
import { IntersectionObserverContext } from './context'
|
|
43
43
|
|
|
44
44
|
interface ScrollViewProps {
|
|
@@ -165,7 +165,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
165
165
|
const initialTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
166
166
|
const intersectionObservers = useContext(IntersectionObserverContext)
|
|
167
167
|
|
|
168
|
-
const
|
|
168
|
+
const firstScrollIntoViewChange = useRef<boolean>(false)
|
|
169
169
|
|
|
170
170
|
const {
|
|
171
171
|
normalStyle,
|
|
@@ -176,10 +176,11 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
176
176
|
setHeight
|
|
177
177
|
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
178
178
|
|
|
179
|
-
const { textStyle, innerStyle } = splitStyle(normalStyle)
|
|
179
|
+
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
180
180
|
|
|
181
181
|
const scrollViewRef = useAnimatedRef<ScrollView>()
|
|
182
182
|
useNodesRef(props, ref, scrollViewRef, {
|
|
183
|
+
style: normalStyle,
|
|
183
184
|
scrollOffset: scrollOptions,
|
|
184
185
|
node: {
|
|
185
186
|
scrollEnabled: scrollX || scrollY,
|
|
@@ -219,23 +220,28 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
219
220
|
}, [refresherTriggered])
|
|
220
221
|
|
|
221
222
|
useEffect(() => {
|
|
222
|
-
if (scrollIntoView && __selectRef
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
nodeRef.current?.measureLayout(
|
|
229
|
-
scrollViewRef.current,
|
|
230
|
-
(left: number, top:number) => {
|
|
231
|
-
scrollToOffset(left, top)
|
|
232
|
-
}
|
|
233
|
-
)
|
|
234
|
-
}
|
|
235
|
-
})
|
|
223
|
+
if (scrollIntoView && __selectRef) {
|
|
224
|
+
if (!firstScrollIntoViewChange.current) {
|
|
225
|
+
setTimeout(handleScrollIntoView)
|
|
226
|
+
} else {
|
|
227
|
+
handleScrollIntoView()
|
|
228
|
+
}
|
|
236
229
|
}
|
|
230
|
+
firstScrollIntoViewChange.current = true
|
|
237
231
|
}, [scrollIntoView])
|
|
238
232
|
|
|
233
|
+
function handleScrollIntoView () {
|
|
234
|
+
const refs = __selectRef!(`#${scrollIntoView}`, 'node')
|
|
235
|
+
if (!refs) return
|
|
236
|
+
const { nodeRef } = refs.getNodeInstance()
|
|
237
|
+
nodeRef.current?.measureLayout(
|
|
238
|
+
scrollViewRef.current,
|
|
239
|
+
(left: number, top:number) => {
|
|
240
|
+
scrollToOffset(left, top)
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
function selectLength (size: { height: number; width: number }) {
|
|
240
246
|
return !scrollX ? size.height : size.width
|
|
241
247
|
}
|
|
@@ -298,14 +304,13 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
298
304
|
const visibleLength = selectLength(e.nativeEvent.layoutMeasurement)
|
|
299
305
|
const contentLength = selectLength(e.nativeEvent.contentSize)
|
|
300
306
|
const offset = selectOffset(e.nativeEvent.contentOffset)
|
|
301
|
-
scrollOptions.current
|
|
302
|
-
...scrollOptions.current,
|
|
307
|
+
extendObject(scrollOptions.current, {
|
|
303
308
|
contentLength,
|
|
304
309
|
offset,
|
|
305
310
|
scrollLeft: position.scrollLeft,
|
|
306
311
|
scrollTop: position.scrollTop,
|
|
307
312
|
visibleLength
|
|
308
|
-
}
|
|
313
|
+
})
|
|
309
314
|
}
|
|
310
315
|
|
|
311
316
|
function onScroll (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
@@ -426,34 +431,36 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
426
431
|
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
427
432
|
}
|
|
428
433
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
434
|
+
const scrollAdditionalProps: ScrollAdditionalProps = extendObject(
|
|
435
|
+
{
|
|
436
|
+
style: extendObject({}, innerStyle, layoutStyle),
|
|
437
|
+
pinchGestureEnabled: false,
|
|
438
|
+
horizontal: scrollX && !scrollY,
|
|
439
|
+
scrollEventThrottle: scrollEventThrottle,
|
|
440
|
+
scrollsToTop: enableBackToTop,
|
|
441
|
+
showsHorizontalScrollIndicator: scrollX && showScrollbar,
|
|
442
|
+
showsVerticalScrollIndicator: scrollY && showScrollbar,
|
|
443
|
+
scrollEnabled: scrollX || scrollY,
|
|
444
|
+
ref: scrollViewRef,
|
|
445
|
+
onScroll: onScroll,
|
|
446
|
+
onContentSizeChange: onContentSizeChange,
|
|
447
|
+
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
|
|
448
|
+
bindtouchmove: ((enhanced && binddragging) || bindtouchend) && onScrollTouchMove,
|
|
449
|
+
bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
|
|
450
|
+
onScrollBeginDrag: onScrollDrag,
|
|
451
|
+
onScrollEndDrag: onScrollDrag,
|
|
452
|
+
onMomentumScrollEnd: onScrollEnd
|
|
453
|
+
},
|
|
454
|
+
(simultaneousHandlers ? { simultaneousHandlers } : {}),
|
|
455
|
+
(waitForHandlers ? { waitFor: waitForHandlers } : {}),
|
|
456
|
+
layoutProps
|
|
457
|
+
)
|
|
458
|
+
|
|
451
459
|
if (enhanced) {
|
|
452
|
-
scrollAdditionalProps
|
|
453
|
-
...scrollAdditionalProps,
|
|
460
|
+
Object.assign(scrollAdditionalProps, {
|
|
454
461
|
bounces,
|
|
455
462
|
pagingEnabled
|
|
456
|
-
}
|
|
463
|
+
})
|
|
457
464
|
}
|
|
458
465
|
|
|
459
466
|
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
@@ -489,32 +496,26 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
489
496
|
white: ['#fff']
|
|
490
497
|
}
|
|
491
498
|
|
|
492
|
-
return (
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
refreshControl
|
|
496
|
-
? (
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
hasVarDec,
|
|
511
|
-
varContext: varContextRef.current,
|
|
512
|
-
textStyle,
|
|
513
|
-
textProps
|
|
514
|
-
}
|
|
515
|
-
)
|
|
499
|
+
return createElement(
|
|
500
|
+
ScrollView,
|
|
501
|
+
extendObject({}, innerProps, {
|
|
502
|
+
refreshControl: refresherEnabled
|
|
503
|
+
? createElement(RefreshControl, extendObject({
|
|
504
|
+
progressBackgroundColor: refresherBackground,
|
|
505
|
+
refreshing: refreshing,
|
|
506
|
+
onRefresh: onRefresh
|
|
507
|
+
}, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
|
|
508
|
+
: undefined
|
|
509
|
+
}),
|
|
510
|
+
wrapChildren(
|
|
511
|
+
props,
|
|
512
|
+
{
|
|
513
|
+
hasVarDec,
|
|
514
|
+
varContext: varContextRef.current,
|
|
515
|
+
textStyle,
|
|
516
|
+
textProps
|
|
516
517
|
}
|
|
517
|
-
|
|
518
|
+
)
|
|
518
519
|
)
|
|
519
520
|
})
|
|
520
521
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Text, TextProps } from 'react-native'
|
|
2
|
+
import { JSX, createElement } from 'react'
|
|
3
|
+
|
|
4
|
+
import { extendObject } from './utils'
|
|
5
|
+
|
|
6
|
+
const _Text2 = (props: TextProps): JSX.Element => {
|
|
7
|
+
const {
|
|
8
|
+
allowFontScaling = false
|
|
9
|
+
} = props
|
|
10
|
+
|
|
11
|
+
return createElement(Text, extendObject({}, props, {
|
|
12
|
+
allowFontScaling
|
|
13
|
+
}))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
_Text2.displayName = 'MpxSimpleText'
|
|
17
|
+
|
|
18
|
+
export default _Text2
|