@mpxjs/webpack-plugin 2.9.69 → 2.9.70-alpha.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 (138) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/ResolveDependency.js +5 -0
  5. package/lib/index.js +38 -7
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +53 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/image.js +4 -0
  10. package/lib/platform/template/wx/component-config/input.js +5 -1
  11. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  12. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  13. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  14. package/lib/platform/template/wx/component-config/switch.js +4 -0
  15. package/lib/platform/template/wx/component-config/text.js +4 -0
  16. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  17. package/lib/platform/template/wx/component-config/view.js +4 -0
  18. package/lib/platform/template/wx/index.js +127 -1
  19. package/lib/react/processTemplate.js +3 -0
  20. package/lib/resolve-loader.js +4 -1
  21. package/lib/runtime/components/react/context.ts +4 -0
  22. package/lib/runtime/components/react/dist/context.js +1 -0
  23. package/lib/runtime/components/react/dist/event.config.js +24 -24
  24. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -165
  25. package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
  26. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
  27. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  28. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  29. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  30. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  31. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  32. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  33. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  34. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  35. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  36. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  37. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  38. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  39. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  40. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  41. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  43. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +110 -97
  45. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
  46. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  47. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  48. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  49. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  50. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  51. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  52. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  53. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  54. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  55. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  56. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  57. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  58. package/lib/runtime/components/react/dist/mpx-view.jsx +29 -44
  59. package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
  60. package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
  61. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  62. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  63. package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
  64. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  65. package/lib/runtime/components/react/dist/utils.jsx +20 -24
  66. package/lib/runtime/components/react/getInnerListeners.ts +35 -28
  67. package/lib/runtime/components/react/mpx-button.tsx +55 -36
  68. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  69. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  70. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  71. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  72. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  73. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  74. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  75. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  76. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  77. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  78. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  79. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  80. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  81. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  82. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  83. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  84. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  85. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  86. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  87. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  88. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  89. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  90. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  91. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  92. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  93. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  94. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  95. package/lib/runtime/components/react/mpx-view.tsx +37 -45
  96. package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
  97. package/lib/runtime/components/react/types/global.d.ts +1 -16
  98. package/lib/runtime/components/react/utils.tsx +24 -24
  99. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  100. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  101. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  102. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  103. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  104. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  105. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  106. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  107. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  108. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  109. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  110. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  111. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  112. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  113. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  114. package/lib/runtime/optionProcessor.js +7 -16
  115. package/lib/runtime/optionProcessor.tenon.js +84 -0
  116. package/lib/runtime/utils.js +2 -0
  117. package/lib/style-compiler/index.js +1 -1
  118. package/lib/style-compiler/plugins/hm.js +20 -0
  119. package/lib/template-compiler/bind-this.js +7 -2
  120. package/lib/template-compiler/compiler.js +67 -40
  121. package/lib/template-compiler/gen-node-react.js +2 -2
  122. package/lib/tenon/index.js +117 -0
  123. package/lib/tenon/processJSON.js +352 -0
  124. package/lib/tenon/processScript.js +203 -0
  125. package/lib/tenon/processStyles.js +21 -0
  126. package/lib/tenon/processTemplate.js +126 -0
  127. package/lib/tenon/script-helper.js +223 -0
  128. package/lib/utils/env.js +6 -1
  129. package/lib/utils/get-relative-path.js +25 -0
  130. package/package.json +7 -3
  131. package/LICENSE +0 -433
  132. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  133. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  134. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  135. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  136. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  137. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  138. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
@@ -0,0 +1,396 @@
1
+ /**
2
+ * ✔ src
3
+ * ✔ mode
4
+ * ✘ show-menu-by-longpress
5
+ * ✔ binderror
6
+ * ✔ bindload
7
+ * ✘ fade-in
8
+ * ✔ webp
9
+ * ✘ lazy-load
10
+ * ✔ bindtap
11
+ * ✔ DEFAULT_SIZE
12
+ */
13
+ import { useEffect, useMemo, useState, useRef, forwardRef } from 'react'
14
+ import {
15
+ Image as RNImage,
16
+ View,
17
+ ImageStyle,
18
+ ImageResizeMode,
19
+ NativeSyntheticEvent,
20
+ ImageErrorEventData,
21
+ LayoutChangeEvent,
22
+ DimensionValue,
23
+ ImageLoadEventData
24
+ } from 'react-native'
25
+ import { SvgCssUri } from 'react-native-svg/css'
26
+ import useInnerProps, { getCustomEvent } from './getInnerListeners'
27
+ import useNodesRef, { HandlerRef } from './useNodesRef'
28
+ import { SVG_REGEXP, useLayout, useTransformStyle, extendObject } from './utils'
29
+
30
+ export type Mode =
31
+ | 'scaleToFill'
32
+ | 'aspectFit'
33
+ | 'aspectFill'
34
+ | 'widthFix'
35
+ | 'heightFix'
36
+ | 'top'
37
+ | 'bottom'
38
+ | 'center'
39
+ | 'left'
40
+ | 'right'
41
+ | 'top left'
42
+ | 'top right'
43
+ | 'bottom left'
44
+ | 'bottom right'
45
+
46
+ export interface ImageProps {
47
+ src?: string
48
+ mode?: Mode
49
+ svg?: boolean
50
+ style?: ImageStyle & Record<string, any>
51
+ 'enable-offset'?: boolean;
52
+ 'enable-var'?: boolean
53
+ 'external-var-context'?: Record<string, any>
54
+ 'parent-font-size'?: number
55
+ 'parent-width'?: number
56
+ 'parent-height'?: number
57
+ bindload?: (evt: NativeSyntheticEvent<ImageLoadEventData> | unknown) => void
58
+ binderror?: (evt: NativeSyntheticEvent<ImageErrorEventData> | unknown) => void
59
+ }
60
+
61
+ const DEFAULT_IMAGE_WIDTH = 320
62
+ const DEFAULT_IMAGE_HEIGHT = 240
63
+
64
+ const cropMode: Mode[] = [
65
+ 'top',
66
+ 'bottom',
67
+ 'center',
68
+ 'right',
69
+ 'left',
70
+ 'top left',
71
+ 'top right',
72
+ 'bottom left',
73
+ 'bottom right'
74
+ ]
75
+
76
+ const ModeMap = new Map<Mode, ImageResizeMode | undefined>([
77
+ ['scaleToFill', 'stretch'],
78
+ ['aspectFit', 'contain'],
79
+ ['aspectFill', 'cover'],
80
+ ['widthFix', 'stretch'],
81
+ ['heightFix', 'stretch'],
82
+ ...cropMode.map<[Mode, ImageResizeMode]>(mode => [mode, 'stretch'])
83
+ ])
84
+
85
+ const isNumber = (value: DimensionValue) => typeof value === 'number'
86
+
87
+ const relativeCenteredSize = (viewSize: number, imageSize: number) => (viewSize - imageSize) / 2
88
+
89
+ function noMeetCalcRule (isSvg: boolean, mode: Mode, viewWidth: number, viewHeight: number, ratio: number) {
90
+ const isMeetSize = viewWidth && viewHeight && ratio
91
+ if (isSvg && !isMeetSize) return true
92
+ if (!isSvg && !['scaleToFill', 'aspectFit', 'aspectFill'].includes(mode) && !isMeetSize) return true
93
+ return false
94
+ }
95
+
96
+ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, ref): JSX.Element => {
97
+ const {
98
+ src = '',
99
+ mode = 'scaleToFill',
100
+ style = {},
101
+ 'enable-var': enableVar,
102
+ 'external-var-context': externalVarContext,
103
+ 'parent-font-size': parentFontSize,
104
+ 'parent-width': parentWidth,
105
+ 'parent-height': parentHeight,
106
+ bindload,
107
+ binderror
108
+ } = props
109
+
110
+ const defaultStyle = {
111
+ width: DEFAULT_IMAGE_WIDTH,
112
+ height: DEFAULT_IMAGE_HEIGHT
113
+ }
114
+
115
+ const styleObj = extendObject(
116
+ {},
117
+ defaultStyle,
118
+ style,
119
+ { overflow: 'hidden' }
120
+ )
121
+
122
+ const nodeRef = useRef(null)
123
+
124
+ const onLayout = ({ nativeEvent: { layout: { width, height } } }: LayoutChangeEvent) => {
125
+ setViewWidth(width)
126
+ setViewHeight(height)
127
+ }
128
+
129
+ const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
130
+
131
+ useNodesRef(props, ref, nodeRef, {
132
+ style: normalStyle
133
+ })
134
+
135
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout })
136
+
137
+ const { width, height } = normalStyle
138
+
139
+ const isSvg = SVG_REGEXP.test(src)
140
+ const isWidthFixMode = mode === 'widthFix'
141
+ const isHeightFixMode = mode === 'heightFix'
142
+ const isCropMode = cropMode.includes(mode)
143
+ const isLayoutMode = isWidthFixMode || isHeightFixMode || isCropMode
144
+ const resizeMode: ImageResizeMode = ModeMap.get(mode) || 'stretch'
145
+
146
+ const [viewWidth, setViewWidth] = useState(isNumber(width) ? width : 0)
147
+ const [viewHeight, setViewHeight] = useState(isNumber(height) ? height : 0)
148
+ const [imageWidth, setImageWidth] = useState(0)
149
+ const [imageHeight, setImageHeight] = useState(0)
150
+ const [ratio, setRatio] = useState(0)
151
+
152
+ const fixedHeight = useMemo(() => {
153
+ const fixed = viewWidth * ratio
154
+ return !fixed ? viewHeight : fixed
155
+ }, [ratio, viewWidth, viewHeight])
156
+
157
+ const fixedWidth = useMemo(() => {
158
+ if (!ratio) return viewWidth
159
+ const fixed = viewHeight / ratio
160
+ return !fixed ? viewWidth : fixed
161
+ }, [ratio, viewWidth, viewHeight])
162
+
163
+ const modeStyle: ImageStyle = useMemo(() => {
164
+ if (noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio)) return {}
165
+ switch (mode) {
166
+ case 'scaleToFill':
167
+ case 'aspectFit':
168
+ if (isSvg) {
169
+ const scale = ratio <= 1
170
+ ? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
171
+ : imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight
172
+ return {
173
+ transform: [
174
+ { scale },
175
+ ratio <= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
176
+ ]
177
+ }
178
+ }
179
+ return {}
180
+ case 'aspectFill':
181
+ if (isSvg) {
182
+ const scale = ratio >= 1
183
+ ? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
184
+ : imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight
185
+ return {
186
+ transform: [
187
+ { scale },
188
+ ratio >= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
189
+ ]
190
+ }
191
+ }
192
+ return {}
193
+ case 'widthFix':
194
+ case 'heightFix':
195
+ if (isSvg) {
196
+ const scale = ratio >= 1
197
+ ? imageWidth >= fixedWidth ? fixedWidth / imageWidth : imageWidth / fixedWidth
198
+ : imageHeight >= fixedHeight ? fixedHeight / imageHeight : imageHeight / fixedHeight
199
+ return {
200
+ transform: [{ scale }]
201
+ }
202
+ }
203
+ return {}
204
+ case 'top':
205
+ return {
206
+ transform: [
207
+ { translateX: relativeCenteredSize(viewWidth, imageWidth) }
208
+ ]
209
+ }
210
+ case 'bottom':
211
+ return {
212
+ transform: [
213
+ { translateY: viewHeight - imageHeight },
214
+ { translateX: relativeCenteredSize(viewWidth, imageWidth) }
215
+ ]
216
+ }
217
+ case 'center':
218
+ return {
219
+ transform: [
220
+ { translateY: relativeCenteredSize(viewHeight, imageHeight) },
221
+ { translateX: relativeCenteredSize(viewWidth, imageWidth) }
222
+ ]
223
+ }
224
+ case 'left':
225
+ return {
226
+ transform: [
227
+ { translateY: relativeCenteredSize(viewHeight, imageHeight) }
228
+ ]
229
+ }
230
+ case 'right':
231
+ return {
232
+ transform: [
233
+ { translateY: relativeCenteredSize(viewHeight, imageHeight) },
234
+ { translateX: viewWidth - imageWidth }
235
+ ]
236
+ }
237
+ case 'top left':
238
+ return {}
239
+ case 'top right':
240
+ return {
241
+ transform: [
242
+ { translateX: viewWidth - imageWidth }
243
+ ]
244
+ }
245
+ case 'bottom left':
246
+ return {
247
+ transform: [
248
+ { translateY: viewHeight - imageHeight }
249
+ ]
250
+ }
251
+ case 'bottom right':
252
+ return {
253
+ transform: [
254
+ { translateY: viewHeight - imageHeight },
255
+ { translateX: viewWidth - imageWidth }
256
+ ]
257
+ }
258
+ default:
259
+ return {}
260
+ }
261
+ }, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio, fixedWidth, fixedHeight])
262
+
263
+ const onSvgLoad = (evt: LayoutChangeEvent) => {
264
+ const { width, height } = evt.nativeEvent.layout
265
+ setRatio(!width ? 0 : height / width)
266
+ setImageWidth(width)
267
+ setImageHeight(height)
268
+
269
+ bindload && bindload(
270
+ getCustomEvent(
271
+ 'load',
272
+ evt,
273
+ {
274
+ detail: { width, height },
275
+ layoutRef
276
+ },
277
+ props
278
+ )
279
+ )
280
+ }
281
+
282
+ const onSvgError = (evt: Error) => {
283
+ binderror!(
284
+ getCustomEvent(
285
+ 'error',
286
+ evt,
287
+ {
288
+ detail: { errMsg: evt?.message },
289
+ layoutRef
290
+ },
291
+ props
292
+ )
293
+ )
294
+ }
295
+
296
+ const onImageLoad = (evt: NativeSyntheticEvent<ImageLoadEventData>) => {
297
+ evt.persist()
298
+ RNImage.getSize(src, (width: number, height: number) => {
299
+ bindload!(
300
+ getCustomEvent(
301
+ 'load',
302
+ evt,
303
+ {
304
+ detail: { width, height },
305
+ layoutRef
306
+ },
307
+ props
308
+ )
309
+ )
310
+ })
311
+ }
312
+
313
+ const onImageError = (evt: NativeSyntheticEvent<ImageErrorEventData>) => {
314
+ binderror!(
315
+ getCustomEvent(
316
+ 'error',
317
+ evt,
318
+ {
319
+ detail: { errMsg: evt.nativeEvent.error },
320
+ layoutRef
321
+ },
322
+ props
323
+ )
324
+ )
325
+ }
326
+
327
+ useEffect(() => {
328
+ if (!isSvg && isLayoutMode) {
329
+ RNImage.getSize(src, (width: number, height: number) => {
330
+ setRatio(!width ? 0 : height / width)
331
+ setImageWidth(width)
332
+ setImageHeight(height)
333
+ })
334
+ }
335
+ }, [src, isSvg, isLayoutMode])
336
+
337
+ const innerProps = useInnerProps(
338
+ props,
339
+ extendObject(
340
+ {
341
+ ref: nodeRef,
342
+ style: extendObject(
343
+ {},
344
+ normalStyle,
345
+ layoutStyle,
346
+ isHeightFixMode ? { width: fixedWidth } : {},
347
+ isWidthFixMode ? { height: fixedHeight } : {}
348
+ )
349
+ },
350
+ layoutProps
351
+ ),
352
+ [
353
+ 'src',
354
+ 'mode',
355
+ 'svg'
356
+ ],
357
+ {
358
+ layoutRef
359
+ }
360
+ )
361
+
362
+ return (
363
+ <View {...innerProps}>
364
+ {
365
+ isSvg
366
+ ? <SvgCssUri
367
+ uri={src}
368
+ onLayout={onSvgLoad}
369
+ onError={binderror && onSvgError}
370
+ style={extendObject(
371
+ { transformOrigin: 'top left' },
372
+ modeStyle
373
+ )}
374
+ />
375
+ : <RNImage
376
+ source={{ uri: src }}
377
+ resizeMode={resizeMode}
378
+ onLoad={bindload && onImageLoad}
379
+ onError={binderror && onImageError}
380
+ style={extendObject(
381
+ {
382
+ transformOrigin: 'top left',
383
+ width: isCropMode ? imageWidth : '100%',
384
+ height: isCropMode ? imageHeight : '100%'
385
+ },
386
+ isCropMode ? modeStyle : {}
387
+ )}
388
+ />
389
+ }
390
+ </View>
391
+ )
392
+ })
393
+
394
+ Image.displayName = 'mpx-image'
395
+
396
+ export default Image
@@ -17,7 +17,7 @@
17
17
  * ✔ cursor-color
18
18
  * ✔ selection-start
19
19
  * ✔ selection-end
20
- * adjust-position
20
+ * adjust-position
21
21
  * ✘ hold-keyboard
22
22
  * ✘ safe-password-cert-path
23
23
  * ✘ safe-password-length
@@ -55,10 +55,10 @@ import {
55
55
  TextInputSubmitEditingEventData
56
56
  } from 'react-native'
57
57
  import { warn } from '@mpxjs/utils'
58
- import { parseInlineStyle, useUpdateEffect, useTransformStyle, useLayout } from './utils'
58
+ import { parseInlineStyle, useUpdateEffect, useTransformStyle, useLayout, extendObject } from './utils'
59
59
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
60
60
  import useNodesRef, { HandlerRef } from './useNodesRef'
61
- import { FormContext, FormFieldValue } from './context'
61
+ import { FormContext, FormFieldValue, KeyboardAvoidContext } from './context'
62
62
 
63
63
  type InputStyle = Omit<
64
64
  TextStyle & ViewStyle & Pick<FlexStyle, 'minHeight'>,
@@ -98,6 +98,7 @@ export interface InputProps {
98
98
  'parent-font-size'?: number
99
99
  'parent-width'?: number
100
100
  'parent-height'?: number
101
+ 'adjust-position': boolean,
101
102
  bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
102
103
  bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
103
104
  bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
@@ -106,6 +107,7 @@ export interface InputProps {
106
107
  }
107
108
 
108
109
  export interface PrivateInputProps {
110
+ allowFontScaling?: boolean
109
111
  multiline?: boolean
110
112
  'auto-height'?: boolean
111
113
  bindlinechange?: (evt: NativeSyntheticEvent<TextInputContentSizeChangeEventData> | unknown) => void
@@ -127,6 +129,7 @@ const keyboardTypeMap: Record<Type, string> = {
127
129
  const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps>((props: FinalInputProps, ref): JSX.Element => {
128
130
  const {
129
131
  style = {},
132
+ allowFontScaling = false,
130
133
  type = 'text',
131
134
  value,
132
135
  password,
@@ -146,6 +149,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
146
149
  'parent-font-size': parentFontSize,
147
150
  'parent-width': parentWidth,
148
151
  'parent-height': parentHeight,
152
+ 'adjust-position': adjustPosition = true,
149
153
  bindinput,
150
154
  bindfocus,
151
155
  bindblur,
@@ -159,6 +163,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
159
163
 
160
164
  const formContext = useContext(FormContext)
161
165
 
166
+ const setKeyboardAvoidEnabled = useContext(KeyboardAvoidContext)
167
+
162
168
  let formValuesMap: Map<string, FormFieldValue> | undefined
163
169
 
164
170
  if (formContext) {
@@ -170,20 +176,20 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
170
176
  const placeholderTextColor = parseInlineStyle(placeholderStyle)?.color
171
177
  const textAlignVertical = multiline ? 'top' : 'auto'
172
178
 
173
- const tmpValue = useRef<string>()
179
+ const tmpValue = useRef<string | undefined>(defaultValue)
174
180
  const cursorIndex = useRef<number>(0)
175
181
  const lineCount = useRef<number>(0)
176
182
 
177
183
  const [inputValue, setInputValue] = useState(defaultValue)
178
184
  const [contentHeight, setContentHeight] = useState(0)
179
185
 
180
- const styleObj = {
181
- padding: 0,
182
- ...style,
183
- ...multiline && autoHeight && {
184
- height: Math.max((style as any)?.minHeight || 35, contentHeight)
185
- }
186
- }
186
+ const styleObj = extendObject(
187
+ { padding: 0, backgroundColor: '#fff' },
188
+ style,
189
+ multiline && autoHeight
190
+ ? { height: Math.max((style as any)?.minHeight || 35, contentHeight) }
191
+ : {}
192
+ )
187
193
 
188
194
  const {
189
195
  hasSelfPercent,
@@ -193,7 +199,9 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
193
199
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
194
200
 
195
201
  const nodeRef = useRef(null)
196
- useNodesRef(props, ref, nodeRef)
202
+ useNodesRef(props, ref, nodeRef, {
203
+ style: normalStyle
204
+ })
197
205
 
198
206
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
199
207
 
@@ -378,6 +386,10 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
378
386
  }
379
387
  }, [])
380
388
 
389
+ useEffect(() => {
390
+ setKeyboardAvoidEnabled?.(adjustPosition)
391
+ }, [adjustPosition])
392
+
381
393
  useUpdateEffect(() => {
382
394
  if (!nodeRef?.current) {
383
395
  return
@@ -387,28 +399,44 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
387
399
  : (nodeRef.current as TextInput)?.blur()
388
400
  }, [focus])
389
401
 
390
- const composeStyle = { ...normalStyle, ...layoutStyle }
391
-
392
- const innerProps = useInnerProps(props, {
393
- ref: nodeRef,
394
- style: {
395
- padding: 0,
396
- ...composeStyle,
397
- ...multiline && autoHeight && {
398
- height: Math.max((composeStyle as any)?.minHeight || 35, contentHeight)
402
+ const innerProps = useInnerProps(
403
+ props,
404
+ extendObject(
405
+ {
406
+ ref: nodeRef,
407
+ style: extendObject({}, normalStyle, layoutStyle),
408
+ allowFontScaling
409
+ },
410
+ layoutProps,
411
+ {
412
+ onFocus: bindfocus && onInputFocus,
413
+ onBlur: bindblur && onInputBlur,
414
+ onKeyPress: bindconfirm && onKeyPress,
415
+ onSubmitEditing: bindconfirm && multiline && onSubmitEditing,
416
+ onSelectionChange: bindselectionchange && onSelectionChange
399
417
  }
400
- },
401
- ...layoutProps,
402
- onFocus: bindfocus && onInputFocus,
403
- onBlur: bindblur && onInputBlur,
404
- onKeyPress: bindconfirm && onKeyPress,
405
- onSubmitEditing: bindconfirm && multiline && onSubmitEditing,
406
- onSelectionChange: bindselectionchange && onSelectionChange
407
- },
408
- [],
409
- {
410
- layoutRef
411
- })
418
+ ),
419
+ [
420
+ 'type',
421
+ 'keyboardType',
422
+ 'password',
423
+ 'placeholder-style',
424
+ 'disabled',
425
+ 'maxlength',
426
+ 'auto-focus',
427
+ 'focus',
428
+ 'confirm-type',
429
+ 'confirm-hold',
430
+ 'cursor',
431
+ 'cursor-color',
432
+ 'selection-start',
433
+ 'selection-end',
434
+ 'multiline'
435
+ ],
436
+ {
437
+ layoutRef
438
+ }
439
+ )
412
440
 
413
441
  return (
414
442
  <TextInput
@@ -6,7 +6,7 @@ import { View, ViewStyle, NativeSyntheticEvent } from 'react-native'
6
6
  import { noop, warn } from '@mpxjs/utils'
7
7
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
8
8
  import useNodesRef, { HandlerRef } from './useNodesRef'
9
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
9
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
10
10
  import { LabelContext, LabelContextValue } from './context'
11
11
 
12
12
  export interface LabelProps {
@@ -42,10 +42,7 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
42
42
  flexDirection: 'row'
43
43
  }
44
44
 
45
- const styleObj = {
46
- ...defaultStyle,
47
- ...style
48
- }
45
+ const styleObj = extendObject({}, defaultStyle, style)
49
46
 
50
47
  const {
51
48
  hasSelfPercent,
@@ -57,11 +54,11 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
57
54
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
58
55
 
59
56
  const nodeRef = useRef(null)
60
- useNodesRef(props, ref, nodeRef, { defaultStyle })
57
+ useNodesRef(props, ref, nodeRef, { style: normalStyle })
61
58
 
62
59
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
63
60
 
64
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
61
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
65
62
 
66
63
  if (backgroundStyle) {
67
64
  warn('Label does not support background image-related styles!')
@@ -79,12 +76,16 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
79
76
 
80
77
  const innerProps = useInnerProps(
81
78
  props,
82
- {
83
- ref: nodeRef,
84
- style: { ...innerStyle, ...layoutStyle },
85
- ...layoutProps,
86
- bindtap: onTap
87
- },
79
+ extendObject(
80
+ {
81
+ ref: nodeRef,
82
+ style: extendObject({}, innerStyle, layoutStyle)
83
+ },
84
+ layoutProps,
85
+ {
86
+ bindtap: onTap
87
+ }
88
+ ),
88
89
  [],
89
90
  {
90
91
  layoutRef
@@ -7,7 +7,7 @@ import { JSX, forwardRef, ReactNode, useRef, useMemo } from 'react'
7
7
  import useNodesRef, { HandlerRef } from './useNodesRef'
8
8
  import useInnerProps from './getInnerListeners'
9
9
  import { MovableAreaContext } from './context'
10
- import { useTransformStyle, wrapChildren, useLayout } from './utils'
10
+ import { useTransformStyle, wrapChildren, useLayout, extendObject } from './utils'
11
11
 
12
12
  interface MovableAreaProps {
13
13
  style?: Record<string, any>;
@@ -35,7 +35,9 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
35
35
  } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
36
36
 
37
37
  const movableViewRef = useRef(null)
38
- useNodesRef(props, ref, movableViewRef)
38
+ useNodesRef(props, ref, movableViewRef, {
39
+ style: normalStyle
40
+ })
39
41
 
40
42
  const contextValue = useMemo(() => ({
41
43
  height: normalStyle.height || 10,
@@ -44,11 +46,10 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
44
46
 
45
47
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef })
46
48
 
47
- const innerProps = useInnerProps(props, {
48
- style: { height: contextValue.height, width: contextValue.width, overflow: 'hidden', ...normalStyle, ...layoutStyle },
49
- ref: movableViewRef,
50
- ...layoutProps
51
- }, [], { layoutRef })
49
+ const innerProps = useInnerProps(props, extendObject({
50
+ style: extendObject({ height: contextValue.height, width: contextValue.width, overflow: 'hidden' }, normalStyle, layoutStyle),
51
+ ref: movableViewRef
52
+ }, layoutProps), [], { layoutRef })
52
53
 
53
54
  return (
54
55
  <MovableAreaContext.Provider value={contextValue}>
@@ -148,7 +148,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
148
148
  const nodeRef = useRef<View>(null)
149
149
 
150
150
  useNodesRef(props, ref, nodeRef, {
151
- defaultStyle: styles.container,
151
+ style: normalStyle,
152
152
  gestureRef: movableGestureRef
153
153
  })
154
154
 
@@ -27,12 +27,14 @@ function dateToString (date: Date, fields: 'day' | 'month' | 'year' = 'day'): st
27
27
  }
28
28
 
29
29
  const _DatePicker = forwardRef<HandlerRef<View, DateProps>, DateProps>((props: DateProps, ref): React.JSX.Element => {
30
- const { children, start = '1970-01-01', end = '2999-01-01', value, bindchange, bindcancel, disabled, fields } = props
30
+ const { children, start = '1970-01-01', end = '2999-01-01', value, bindchange, bindcancel, disabled, fields, style } = props
31
31
  const [datevalue, setDateValue] = useState(value)
32
32
  // 存储layout布局信息
33
33
  const layoutRef = useRef({})
34
34
  const viewRef = useRef<View>(null)
35
- useNodesRef<View, DateProps>(props, ref, viewRef, {
35
+ const nodeRef = useRef<View>(null)
36
+ useNodesRef<View, DateProps>(props, ref, nodeRef, {
37
+ style
36
38
  })
37
39
 
38
40
  useEffect(() => {
@@ -58,6 +60,7 @@ const _DatePicker = forwardRef<HandlerRef<View, DateProps>, DateProps>((props: D
58
60
  }
59
61
 
60
62
  const dateProps = {
63
+ ref: nodeRef,
61
64
  precision: fields,
62
65
  value: formatTimeStr(datevalue),
63
66
  minDate: formatTimeStr(start),