@mpxjs/webpack-plugin 2.10.22 → 2.10.24-test.1

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 (123) hide show
  1. package/lib/loader.js +2 -0
  2. package/lib/platform/style/wx/index.js +395 -104
  3. package/lib/react/index.js +3 -1
  4. package/lib/react/processTemplate.js +3 -1
  5. package/lib/react/style-helper.js +6 -6
  6. package/lib/runtime/components/react/animationHooks/index.ts +7 -3
  7. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +0 -2
  8. package/lib/runtime/components/react/dist/animationHooks/index.js +6 -1
  9. package/lib/runtime/components/react/dist/event.config.d.ts +2 -6
  10. package/lib/runtime/components/react/dist/event.config.js +28 -24
  11. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +1 -1
  12. package/lib/runtime/components/react/dist/getInnerListeners.js +74 -56
  13. package/lib/runtime/components/react/dist/mpx-button.d.ts +1 -1
  14. package/lib/runtime/components/react/dist/mpx-button.jsx +16 -9
  15. package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -1
  16. package/lib/runtime/components/react/dist/mpx-camera.jsx +1 -2
  17. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  18. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -2
  19. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +1 -1
  20. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  21. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +3 -4
  22. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +1 -1
  23. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +8 -9
  24. package/lib/runtime/components/react/dist/mpx-form.d.ts +1 -1
  25. package/lib/runtime/components/react/dist/mpx-form.jsx +5 -5
  26. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  27. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
  28. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  29. package/lib/runtime/components/react/dist/mpx-image.jsx +59 -43
  30. package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -1
  31. package/lib/runtime/components/react/dist/mpx-input.jsx +2 -2
  32. package/lib/runtime/components/react/dist/mpx-label.d.ts +1 -1
  33. package/lib/runtime/components/react/dist/mpx-label.jsx +5 -6
  34. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  35. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +3 -3
  36. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +1 -1
  37. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +6 -6
  38. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +1 -1
  39. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +5 -7
  40. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  41. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +2 -2
  42. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  43. package/lib/runtime/components/react/dist/mpx-progress.jsx +1 -2
  44. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  45. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +3 -4
  46. package/lib/runtime/components/react/dist/mpx-radio.d.ts +1 -1
  47. package/lib/runtime/components/react/dist/mpx-radio.jsx +8 -9
  48. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  49. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -2
  50. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +1 -1
  51. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -6
  52. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +36 -31
  53. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +4 -2
  54. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +24 -17
  55. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  56. package/lib/runtime/components/react/dist/mpx-slider.jsx +6 -6
  57. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +1 -1
  58. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +5 -5
  59. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +1 -1
  60. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +6 -6
  61. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +1 -1
  62. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -5
  63. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +1 -1
  64. package/lib/runtime/components/react/dist/mpx-swiper.jsx +4 -7
  65. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-switch.jsx +1 -2
  67. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  68. package/lib/runtime/components/react/dist/mpx-text.jsx +44 -40
  69. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-video.jsx +4 -4
  71. package/lib/runtime/components/react/dist/mpx-view.d.ts +2 -1
  72. package/lib/runtime/components/react/dist/mpx-view.jsx +229 -128
  73. package/lib/runtime/components/react/dist/mpx-web-view.jsx +5 -1
  74. package/lib/runtime/components/react/dist/namedColorSet.d.ts +2 -0
  75. package/lib/runtime/components/react/dist/namedColorSet.js +149 -0
  76. package/lib/runtime/components/react/dist/utils.d.ts +73 -69
  77. package/lib/runtime/components/react/dist/utils.jsx +1295 -442
  78. package/lib/runtime/components/react/event.config.ts +32 -25
  79. package/lib/runtime/components/react/getInnerListeners.ts +84 -60
  80. package/lib/runtime/components/react/mpx-button.tsx +18 -16
  81. package/lib/runtime/components/react/mpx-camera.tsx +0 -3
  82. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -3
  83. package/lib/runtime/components/react/mpx-canvas/utils.tsx +3 -1
  84. package/lib/runtime/components/react/mpx-checkbox-group.tsx +2 -6
  85. package/lib/runtime/components/react/mpx-checkbox.tsx +9 -11
  86. package/lib/runtime/components/react/mpx-form.tsx +6 -6
  87. package/lib/runtime/components/react/mpx-icon/index.tsx +1 -3
  88. package/lib/runtime/components/react/mpx-image.tsx +65 -54
  89. package/lib/runtime/components/react/mpx-input.tsx +1 -3
  90. package/lib/runtime/components/react/mpx-label.tsx +6 -8
  91. package/lib/runtime/components/react/mpx-movable-area.tsx +3 -4
  92. package/lib/runtime/components/react/mpx-movable-view.tsx +7 -7
  93. package/lib/runtime/components/react/mpx-picker-view/index.tsx +6 -8
  94. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +2 -4
  95. package/lib/runtime/components/react/mpx-progress.tsx +0 -3
  96. package/lib/runtime/components/react/mpx-radio-group.tsx +2 -6
  97. package/lib/runtime/components/react/mpx-radio.tsx +9 -11
  98. package/lib/runtime/components/react/mpx-rich-text/index.tsx +0 -3
  99. package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -7
  100. package/lib/runtime/components/react/mpx-simple-text.tsx +36 -38
  101. package/lib/runtime/components/react/mpx-simple-view.tsx +29 -17
  102. package/lib/runtime/components/react/mpx-slider.tsx +15 -10
  103. package/lib/runtime/components/react/mpx-sticky-header.tsx +6 -6
  104. package/lib/runtime/components/react/mpx-sticky-section.tsx +7 -7
  105. package/lib/runtime/components/react/mpx-swiper-item.tsx +6 -6
  106. package/lib/runtime/components/react/mpx-swiper.tsx +5 -8
  107. package/lib/runtime/components/react/mpx-switch.tsx +0 -3
  108. package/lib/runtime/components/react/mpx-text.tsx +46 -49
  109. package/lib/runtime/components/react/mpx-video.tsx +3 -5
  110. package/lib/runtime/components/react/mpx-view.tsx +250 -141
  111. package/lib/runtime/components/react/mpx-web-view.tsx +8 -3
  112. package/lib/runtime/components/react/namedColorSet.ts +150 -0
  113. package/lib/runtime/components/react/types/getInnerListeners.d.ts +21 -1
  114. package/lib/runtime/components/react/types/global.d.ts +1 -0
  115. package/lib/runtime/components/react/utils.tsx +1347 -539
  116. package/lib/runtime/i18n.wxs +15 -9
  117. package/lib/style-compiler/strip-conditional.js +19 -4
  118. package/lib/template-compiler/compiler.js +5 -1
  119. package/lib/utils/source-location.js +9 -13
  120. package/lib/web/index.js +3 -1
  121. package/lib/web/processTemplate.js +3 -1
  122. package/package.json +5 -4
  123. package/LICENSE +0 -433
@@ -1,28 +1,35 @@
1
- const eventConfigMap: { [key: string]: { bitFlag: string; events: string[] } } = {
2
- bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
3
- bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
4
- bindtouchstart: { bitFlag: '2', events: ['onTouchStart'] },
5
- bindtouchmove: { bitFlag: '3', events: ['onTouchMove'] },
6
- bindtouchend: { bitFlag: '4', events: ['onTouchEnd'] },
7
- bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'] },
8
- catchtap: { bitFlag: '6', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
9
- catchlongpress: { bitFlag: '7', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
10
- catchtouchstart: { bitFlag: '8', events: ['onTouchStart'] },
11
- catchtouchmove: { bitFlag: '9', events: ['onTouchMove'] },
12
- catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'] },
13
- catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'] },
14
- 'capture-bindtap': { bitFlag: 'c', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
15
- 'capture-bindlongpress': { bitFlag: 'd', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
16
- 'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'] },
17
- 'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'] },
18
- 'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'] },
19
- 'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'] },
20
- 'capture-catchtap': { bitFlag: 'i', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
21
- 'capture-catchlongpress': { bitFlag: 'j', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
22
- 'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'] },
23
- 'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'] },
24
- 'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'] },
25
- 'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'] }
1
+ import type { EventMeta } from './types/getInnerListeners'
2
+
3
+ const tapEvents = ['onTouchStart', 'onTouchMove', 'onTouchEnd']
4
+ const longpressEvents = ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel']
5
+ const tapCaptureEvents = ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture']
6
+ const longpressCaptureEvents = ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture']
7
+
8
+ const eventConfigMap: Record<string, EventMeta> = {
9
+ bindtap: { bitFlag: '0', events: tapEvents, eventName: 'tap', eventType: 'bubble', hasCatch: false },
10
+ bindlongpress: { bitFlag: '1', events: longpressEvents, eventName: 'longpress', eventType: 'bubble', hasCatch: false },
11
+ bindtouchstart: { bitFlag: '2', events: ['onTouchStart'], eventName: 'touchstart', eventType: 'bubble', hasCatch: false },
12
+ bindtouchmove: { bitFlag: '3', events: ['onTouchMove'], eventName: 'touchmove', eventType: 'bubble', hasCatch: false },
13
+ bindtouchend: { bitFlag: '4', events: ['onTouchEnd'], eventName: 'touchend', eventType: 'bubble', hasCatch: false },
14
+ bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'], eventName: 'touchcancel', eventType: 'bubble', hasCatch: false },
15
+ catchtap: { bitFlag: '6', events: tapEvents, eventName: 'tap', eventType: 'bubble', hasCatch: true },
16
+ catchlongpress: { bitFlag: '7', events: longpressEvents, eventName: 'longpress', eventType: 'bubble', hasCatch: true },
17
+ catchtouchstart: { bitFlag: '8', events: ['onTouchStart'], eventName: 'touchstart', eventType: 'bubble', hasCatch: true },
18
+ catchtouchmove: { bitFlag: '9', events: ['onTouchMove'], eventName: 'touchmove', eventType: 'bubble', hasCatch: true },
19
+ catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'], eventName: 'touchend', eventType: 'bubble', hasCatch: true },
20
+ catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'], eventName: 'touchcancel', eventType: 'bubble', hasCatch: true },
21
+ 'capture-bindtap': { bitFlag: 'c', events: tapCaptureEvents, eventName: 'tap', eventType: 'capture', hasCatch: false },
22
+ 'capture-bindlongpress': { bitFlag: 'd', events: longpressCaptureEvents, eventName: 'longpress', eventType: 'capture', hasCatch: false },
23
+ 'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'], eventName: 'touchstart', eventType: 'capture', hasCatch: false },
24
+ 'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'], eventName: 'touchmove', eventType: 'capture', hasCatch: false },
25
+ 'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'], eventName: 'touchend', eventType: 'capture', hasCatch: false },
26
+ 'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'], eventName: 'touchcancel', eventType: 'capture', hasCatch: false },
27
+ 'capture-catchtap': { bitFlag: 'i', events: tapCaptureEvents, eventName: 'tap', eventType: 'capture', hasCatch: true },
28
+ 'capture-catchlongpress': { bitFlag: 'j', events: longpressCaptureEvents, eventName: 'longpress', eventType: 'capture', hasCatch: true },
29
+ 'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'], eventName: 'touchstart', eventType: 'capture', hasCatch: true },
30
+ 'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'], eventName: 'touchmove', eventType: 'capture', hasCatch: true },
31
+ 'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'], eventName: 'touchend', eventType: 'capture', hasCatch: true },
32
+ 'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'], eventName: 'touchcancel', eventType: 'capture', hasCatch: true }
26
33
  }
27
34
 
28
35
  export default eventConfigMap
@@ -1,17 +1,19 @@
1
1
  import { useRef, useMemo } from 'react'
2
2
  import { collectDataset } from '@mpxjs/utils'
3
- import { omit, extendObject, useNavigation } from './utils'
3
+ import { extendObject, useNavigation } from './utils'
4
4
  import eventConfigMap from './event.config'
5
5
  import {
6
6
  Props,
7
7
  EventConfig,
8
+ EventConfigRef,
8
9
  RawConfig,
9
10
  EventType,
10
11
  RemoveProps,
11
12
  InnerRef,
12
13
  LayoutRef,
13
14
  ExtendedNativeTouchEvent,
14
- GlobalEventState
15
+ GlobalEventState,
16
+ TouchHandlerConfig
15
17
  } from './types/getInnerListeners'
16
18
 
17
19
  const globalEventState: GlobalEventState = {
@@ -19,6 +21,18 @@ const globalEventState: GlobalEventState = {
19
21
  identifier: null
20
22
  }
21
23
 
24
+ const baseRemovePropsMap: Record<string, boolean> = {
25
+ children: true,
26
+ 'enable-background': true,
27
+ 'enable-offset': true,
28
+ 'enable-var': true,
29
+ 'external-var-context': true,
30
+ 'parent-font-size': true,
31
+ 'parent-width': true,
32
+ 'parent-height': true,
33
+ 'enable-text-pass-through': true
34
+ }
35
+
22
36
  const getTouchEvent = (
23
37
  type: string,
24
38
  event: ExtendedNativeTouchEvent,
@@ -216,29 +230,45 @@ function handleTouchcancel (e: ExtendedNativeTouchEvent, type: EventType, eventC
216
230
  innerRef.current.startTimer[type] && clearTimeout(innerRef.current.startTimer[type] as unknown as number)
217
231
  }
218
232
 
219
- function createTouchEventHandler (eventName: string, eventConfig: EventConfig) {
220
- return (e: ExtendedNativeTouchEvent) => {
221
- const bubbleHandlerMap: Record<string, any> = {
222
- onTouchStart: handleTouchstart,
223
- onTouchMove: handleTouchmove,
224
- onTouchEnd: handleTouchend,
225
- onTouchCancel: handleTouchcancel
226
- }
227
-
228
- const captureHandlerMap: Record<string, any> = {
229
- onTouchStartCapture: handleTouchstart,
230
- onTouchMoveCapture: handleTouchmove,
231
- onTouchEndCapture: handleTouchend,
232
- onTouchCancelCapture: handleTouchcancel
233
- }
234
-
235
- if (bubbleHandlerMap[eventName]) {
236
- bubbleHandlerMap[eventName](e, 'bubble', eventConfig)
237
- }
233
+ const touchHandlerMap: Record<string, TouchHandlerConfig> = {
234
+ onTouchStart: {
235
+ type: 'bubble',
236
+ handler: handleTouchstart
237
+ },
238
+ onTouchMove: {
239
+ type: 'bubble',
240
+ handler: handleTouchmove
241
+ },
242
+ onTouchEnd: {
243
+ type: 'bubble',
244
+ handler: handleTouchend
245
+ },
246
+ onTouchCancel: {
247
+ type: 'bubble',
248
+ handler: handleTouchcancel
249
+ },
250
+ onTouchStartCapture: {
251
+ type: 'capture',
252
+ handler: handleTouchstart
253
+ },
254
+ onTouchMoveCapture: {
255
+ type: 'capture',
256
+ handler: handleTouchmove
257
+ },
258
+ onTouchEndCapture: {
259
+ type: 'capture',
260
+ handler: handleTouchend
261
+ },
262
+ onTouchCancelCapture: {
263
+ type: 'capture',
264
+ handler: handleTouchcancel
265
+ }
266
+ }
238
267
 
239
- if (captureHandlerMap[eventName]) {
240
- captureHandlerMap[eventName](e, 'capture', eventConfig)
241
- }
268
+ function createTouchEventHandler (eventName: string, eventConfigRef: EventConfigRef) {
269
+ const eventHandler = touchHandlerMap[eventName]
270
+ return (e: ExtendedNativeTouchEvent) => {
271
+ eventHandler.handler(e, eventHandler.type, eventConfigRef.current)
242
272
  }
243
273
  }
244
274
 
@@ -271,37 +301,45 @@ const useInnerProps = (
271
301
  disableTap: false,
272
302
  navigation
273
303
  }, rawConfig)
304
+ const eventConfigRef = useRef<EventConfig>(eventConfig)
274
305
 
306
+ const restProps: Props = {}
307
+ const eventNameMap: Record<string, boolean> = {}
308
+ const userRemovePropsMap: Record<string, boolean> = {}
275
309
  let hashEventKey = ''
276
- const rawEventKeys: Array<string> = []
277
- const transformedEventSet = new Set<string>()
310
+
311
+ userRemoveProps.forEach((key) => {
312
+ userRemovePropsMap[key] = true
313
+ })
314
+
278
315
  Object.keys(props).forEach((key) => {
279
- if (eventConfigMap[key]) {
280
- hashEventKey += eventConfigMap[key].bitFlag
281
- rawEventKeys.push(key)
282
- eventConfigMap[key].events.forEach((event) => {
283
- transformedEventSet.add(event)
316
+ const eventMeta = eventConfigMap[key]
317
+
318
+ if (eventMeta) {
319
+ hashEventKey += eventMeta.bitFlag
320
+ eventMeta.events.forEach((event) => {
321
+ eventNameMap[event] = true
284
322
  })
285
- const match = /^(bind|catch|capture-bind|capture-catch)(.*)$/.exec(key)!
286
- const prefix = match[1]
287
- const eventName = match[2]
288
- eventConfig[eventName] = eventConfig[eventName] || {
323
+ eventConfig[eventMeta.eventName] = eventConfig[eventMeta.eventName] || {
289
324
  bubble: [],
290
325
  capture: [],
291
326
  hasCatch: false
292
327
  }
293
- if (prefix === 'bind' || prefix === 'catch') {
294
- eventConfig[eventName].bubble.push(key)
295
- } else {
296
- eventConfig[eventName].capture.push(key)
297
- }
328
+ eventConfig[eventMeta.eventName][eventMeta.eventType].push(key)
298
329
 
299
- if (prefix === 'catch' || prefix === 'capture-catch') {
300
- eventConfig[eventName].hasCatch = true
330
+ if (eventMeta.hasCatch) {
331
+ eventConfig[eventMeta.eventName].hasCatch = true
301
332
  }
333
+ return
334
+ }
335
+
336
+ if (!baseRemovePropsMap[key] && !userRemovePropsMap[key]) {
337
+ restProps[key] = props[key]
302
338
  }
303
339
  })
304
340
 
341
+ eventConfigRef.current = eventConfig
342
+
305
343
  const events = useMemo(() => {
306
344
  if (!hashEventKey) {
307
345
  return {}
@@ -309,31 +347,17 @@ const useInnerProps = (
309
347
 
310
348
  const events: Record<string, (e: ExtendedNativeTouchEvent) => void> = {}
311
349
 
312
- for (const eventName of transformedEventSet) {
313
- events[eventName] = createTouchEventHandler(eventName, eventConfig)
314
- }
350
+ Object.keys(eventNameMap).forEach((eventName) => {
351
+ events[eventName] = createTouchEventHandler(eventName, eventConfigRef)
352
+ })
315
353
 
316
354
  return events
317
355
  }, [hashEventKey])
318
356
 
319
- const removeProps = [
320
- 'children',
321
- 'enable-background',
322
- 'enable-offset',
323
- 'enable-var',
324
- 'external-var-context',
325
- 'parent-font-size',
326
- 'parent-width',
327
- 'parent-height',
328
- 'enable-text-pass-through',
329
- ...userRemoveProps,
330
- ...rawEventKeys
331
- ]
332
-
333
357
  return extendObject(
334
358
  {},
335
359
  events,
336
- omit(props, removeProps)
360
+ restProps
337
361
  )
338
362
  }
339
363
  export default useInnerProps
@@ -45,9 +45,9 @@ import {
45
45
  NativeSyntheticEvent,
46
46
  useAnimatedValue
47
47
  } from 'react-native'
48
- import { warn } from '@mpxjs/utils'
48
+ import { warn, hasOwn } from '@mpxjs/utils'
49
49
  import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
50
- import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover, useTextPassThroughValue } from './utils'
50
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover, useTextPassThrough } from './utils'
51
51
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
52
52
  import useNodesRef, { HandlerRef } from './useNodesRef'
53
53
  import { RouteContext, FormContext } from './context'
@@ -79,7 +79,7 @@ export interface ButtonProps {
79
79
  'form-type'?: 'submit' | 'reset'
80
80
  'enable-offset'?: boolean,
81
81
  'enable-var'?: boolean
82
- 'external-var-context'?: Record<string, any>
82
+ 'enable-text-pass-through'?: boolean
83
83
  'parent-font-size'?: number
84
84
  'parent-width'?: number
85
85
  'parent-height'?: number
@@ -105,14 +105,14 @@ const OpenTypeEventsMap = new Map<OpenType, OpenTypeEvent>([
105
105
 
106
106
  const styles = StyleSheet.create({
107
107
  button: {
108
- width: '100%',
109
108
  flexDirection: 'row',
110
109
  justifyContent: 'center',
111
110
  alignItems: 'center',
112
111
  height: 46,
113
112
  borderRadius: 5,
114
113
  backgroundColor: '#F8F8F8',
115
- marginHorizontal: 'auto' // 按钮默认居中
114
+ marginHorizontal: 'auto',
115
+ paddingHorizontal: 14
116
116
  },
117
117
  buttonMini: {
118
118
  height: 30
@@ -211,7 +211,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
211
211
  'open-type': openType,
212
212
  'form-type': formType,
213
213
  'enable-var': enableVar,
214
- 'external-var-context': externalVarContext,
214
+ 'enable-text-pass-through': enableTextPassThrough,
215
215
  'parent-font-size': parentFontSize,
216
216
  'parent-width': parentWidth,
217
217
  'parent-height': parentHeight,
@@ -282,14 +282,16 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
282
282
  { color: plain ? plainTextColor : normalTextColor }
283
283
  )
284
284
 
285
- const defaultStyle = extendObject({}, defaultViewStyle, defaultTextStyle)
285
+ const styleObj = isHover ? extendObject({}, style, hoverStyle) : style
286
286
 
287
- const styleObj = extendObject(
288
- {},
289
- defaultStyle,
290
- style,
291
- isHover ? hoverStyle : {}
292
- )
287
+ const defaultStyle: Record<string, any> = extendObject({}, defaultViewStyle, defaultTextStyle)
288
+ // 用户 shorthand 优先:避免 longhand default 反向覆盖
289
+ if (hasOwn(styleObj, 'margin')) {
290
+ delete defaultStyle.marginHorizontal
291
+ }
292
+ if (hasOwn(styleObj, 'padding')) {
293
+ delete defaultStyle.paddingHorizontal
294
+ }
293
295
 
294
296
  const {
295
297
  hasPositionFixed,
@@ -299,7 +301,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
299
301
  varContextRef,
300
302
  setWidth,
301
303
  setHeight
302
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
304
+ } = useTransformStyle(styleObj, { enableVar, parentFontSize, parentWidth, parentHeight, defaultStyle })
303
305
 
304
306
  const nodeRef = useRef(null)
305
307
 
@@ -308,7 +310,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
308
310
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
309
311
 
310
312
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
311
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
313
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
312
314
 
313
315
  if (backgroundStyle) {
314
316
  warn('Button does not support background image-related styles!')
@@ -407,7 +409,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
407
409
 
408
410
  const baseButton = createElement(View, innerProps, loading && createElement(Loading, { alone: !children }),
409
411
  wrapChildren(
410
- props,
412
+ props.children,
411
413
  {
412
414
  hasVarDec,
413
415
  varContext: varContextRef.current,
@@ -28,7 +28,6 @@ interface CameraProps {
28
28
  'parent-width'?: number
29
29
  'parent-height'?: number
30
30
  'enable-var'?: boolean
31
- 'external-var-context'?: any
32
31
  }
33
32
 
34
33
  interface TakePhotoOptions {
@@ -81,7 +80,6 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
81
80
  'parent-width': parentWidth,
82
81
  'parent-height': parentHeight,
83
82
  'enable-var': enableVar,
84
- 'external-var-context': externalVarContext,
85
83
  style = {}
86
84
  } = props
87
85
  const styleObj = extendObject(
@@ -95,7 +93,6 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
95
93
  setHeight
96
94
  } = useTransformStyle(styleObj, {
97
95
  enableVar,
98
- externalVarContext,
99
96
  parentFontSize,
100
97
  parentWidth,
101
98
  parentHeight
@@ -55,7 +55,6 @@ interface CanvasProps {
55
55
  'parent-font-size'?: number
56
56
  'parent-width'?: number
57
57
  'parent-height'?: number
58
- 'external-var-context'?: Record<string, any>
59
58
  bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void
60
59
  bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void
61
60
  bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void
@@ -65,7 +64,7 @@ interface CanvasProps {
65
64
  }
66
65
 
67
66
  const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasProps>((props: CanvasProps = {}, ref): JSX.Element => {
68
- const { style = {}, originWhitelist = ['*'], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props
67
+ const { style = {}, originWhitelist = ['*'], 'enable-var': enableVar, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props
69
68
  const [isLoaded, setIsLoaded] = useState(false)
70
69
  const nodeRef = useRef(null)
71
70
 
@@ -77,7 +76,6 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
77
76
  setHeight
78
77
  } = useTransformStyle(extendObject({}, style, stylesheet.container), {
79
78
  enableVar,
80
- externalVarContext,
81
79
  parentFontSize,
82
80
  parentWidth,
83
81
  parentHeight
@@ -42,7 +42,9 @@ export interface WebviewMessage {
42
42
  }
43
43
 
44
44
  export interface CanvasInstance {
45
- webview: WebView | null;
45
+ // react-native-webview@13.17+ WebView 泛型默认值由 {} 改为 undefined,
46
+ // ref 回调推断出的 WebView<unknown> 无法赋给默认实参化后的类型,这里显式用 any 兼容各版本
47
+ webview: WebView<any> | null;
46
48
  bus: Bus | null;
47
49
  context2D: CanvasRenderingContext2D;
48
50
  getContext: (contextType: string) => CanvasRenderingContext2D | null;
@@ -28,7 +28,6 @@ export interface CheckboxGroupProps {
28
28
  style?: ViewStyle & Record<string, any>
29
29
  'enable-offset'?: boolean
30
30
  'enable-var'?: boolean
31
- 'external-var-context'?: Record<string, any>
32
31
  'parent-font-size'?: number
33
32
  'parent-width'?: number
34
33
  'parent-height'?: number
@@ -45,7 +44,6 @@ const CheckboxGroup = forwardRef<
45
44
  const {
46
45
  style = {},
47
46
  'enable-var': enableVar,
48
- 'external-var-context': externalVarContext,
49
47
  'parent-font-size': parentFontSize,
50
48
  'parent-width': parentWidth,
51
49
  'parent-height': parentHeight
@@ -66,8 +64,6 @@ const CheckboxGroup = forwardRef<
66
64
  flexWrap: 'wrap'
67
65
  }
68
66
 
69
- const styleObj = extendObject({}, defaultStyle, style)
70
-
71
67
  const {
72
68
  hasPositionFixed,
73
69
  hasSelfPercent,
@@ -76,7 +72,7 @@ const CheckboxGroup = forwardRef<
76
72
  varContextRef,
77
73
  setWidth,
78
74
  setHeight
79
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
75
+ } = useTransformStyle(style, { enableVar, parentFontSize, parentWidth, parentHeight, defaultStyle })
80
76
 
81
77
  const nodeRef = useRef(null)
82
78
 
@@ -169,7 +165,7 @@ const CheckboxGroup = forwardRef<
169
165
  CheckboxGroupContext.Provider,
170
166
  { value: contextValue },
171
167
  wrapChildren(
172
- props,
168
+ props.children,
173
169
  {
174
170
  hasVarDec,
175
171
  varContext: varContextRef.current
@@ -26,7 +26,7 @@ import { warn } from '@mpxjs/utils'
26
26
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
27
27
  import useNodesRef, { HandlerRef } from './useNodesRef'
28
28
  import Icon from './mpx-icon'
29
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThroughValue } from './utils'
29
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThrough } from './utils'
30
30
  import { CheckboxGroupContext, LabelContext } from './context'
31
31
  import Portal from './mpx-portal'
32
32
 
@@ -42,7 +42,7 @@ export interface CheckboxProps extends Selection {
42
42
  groupValue?: Array<string>
43
43
  'enable-offset'?: boolean
44
44
  'enable-var'?: boolean
45
- 'external-var-context'?: Record<string, any>
45
+ 'enable-text-pass-through'?: boolean
46
46
  'parent-font-size'?: number
47
47
  'parent-width'?: number
48
48
  'parent-height'?: number
@@ -89,7 +89,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
89
89
  color = '#09BB07',
90
90
  style = {},
91
91
  'enable-var': enableVar,
92
- 'external-var-context': externalVarContext,
92
+ 'enable-text-pass-through': enableTextPassThrough,
93
93
  'parent-font-size': parentFontSize,
94
94
  'parent-width': parentWidth,
95
95
  'parent-height': parentHeight,
@@ -103,14 +103,12 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
103
103
  let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> } } | undefined
104
104
  let notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void | undefined
105
105
 
106
- const defaultStyle = extendObject(
106
+ const wrapperStyle = extendObject(
107
107
  {},
108
108
  styles.wrapper,
109
109
  disabled ? styles.wrapperDisabled : null
110
110
  )
111
111
 
112
- const styleObj = extendObject({}, styles.container, style)
113
-
114
112
  const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
115
113
  if (disabled) return
116
114
  const checked = !isChecked
@@ -136,19 +134,19 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
136
134
  varContextRef,
137
135
  setWidth,
138
136
  setHeight
139
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
137
+ } = useTransformStyle(style, { enableVar, parentFontSize, parentWidth, parentHeight, defaultStyle: styles.container })
140
138
 
141
139
  const nodeRef = useRef(null)
142
140
 
143
141
  useNodesRef(props, ref, nodeRef, {
144
- style: extendObject({}, defaultStyle, normalStyle),
142
+ style: normalStyle,
145
143
  change: onChange
146
144
  })
147
145
 
148
146
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
149
147
 
150
148
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
151
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
149
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
152
150
 
153
151
  if (backgroundStyle) {
154
152
  warn('Checkbox does not support background image-related styles!')
@@ -214,7 +212,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
214
212
  const finalComponent = createElement(View, innerProps,
215
213
  createElement(
216
214
  View,
217
- { style: defaultStyle },
215
+ { style: wrapperStyle },
218
216
  createElement(Icon, {
219
217
  type: 'success_no_circle',
220
218
  size: 18,
@@ -223,7 +221,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
223
221
  })
224
222
  ),
225
223
  wrapChildren(
226
- props,
224
+ props.children,
227
225
  {
228
226
  hasVarDec,
229
227
  varContext: varContextRef.current,
@@ -9,13 +9,13 @@ import { JSX, useRef, forwardRef, ReactNode, useMemo, createElement } from 'reac
9
9
  import useNodesRef, { HandlerRef } from './useNodesRef'
10
10
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
11
11
  import { FormContext } from './context'
12
- import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject, useTextPassThroughValue } from './utils'
12
+ import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject, useTextPassThrough } from './utils'
13
13
  interface FormProps {
14
14
  style?: Record<string, any>
15
15
  children?: ReactNode
16
16
  'enable-offset'?: boolean
17
17
  'enable-var'?: boolean
18
- 'external-var-context'?: Record<string, any>
18
+ 'enable-text-pass-through'?: boolean
19
19
  'parent-font-size'?: number
20
20
  'parent-width'?: number
21
21
  'parent-height'?: number
@@ -32,7 +32,7 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
32
32
  const {
33
33
  style,
34
34
  'enable-var': enableVar,
35
- 'external-var-context': externalVarContext,
35
+ 'enable-text-pass-through': enableTextPassThrough,
36
36
  'parent-font-size': parentFontSize,
37
37
  'parent-width': parentWidth,
38
38
  'parent-height': parentHeight
@@ -45,10 +45,10 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
45
45
  varContextRef,
46
46
  setWidth,
47
47
  setHeight
48
- } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
48
+ } = useTransformStyle(style, { enableVar, parentFontSize, parentWidth, parentHeight })
49
49
 
50
50
  const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
51
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
51
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
52
52
 
53
53
  const formRef = useRef(null)
54
54
  useNodesRef(props, ref, formRef, {
@@ -114,7 +114,7 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
114
114
  FormContext.Provider,
115
115
  { value: contextValue },
116
116
  wrapChildren(
117
- props,
117
+ props.children,
118
118
  {
119
119
  hasVarDec,
120
120
  varContext: varContextRef.current,
@@ -37,7 +37,6 @@ export interface IconProps {
37
37
  style?: TextStyle & Record<string, any>
38
38
  'enable-offset'?: boolean
39
39
  'enable-var'?: boolean
40
- 'external-var-context'?: Record<string, any>
41
40
  'parent-font-size'?: number
42
41
  'parent-width'?: number
43
42
  'parent-height'?: number
@@ -63,7 +62,6 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
63
62
  color,
64
63
  style = {},
65
64
  'enable-var': enableVar,
66
- 'external-var-context': externalVarContext,
67
65
  'parent-font-size': parentFontSize,
68
66
  'parent-width': parentWidth,
69
67
  'parent-height': parentHeight
@@ -81,7 +79,7 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
81
79
  normalStyle,
82
80
  setWidth,
83
81
  setHeight
84
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
82
+ } = useTransformStyle(styleObj, { enableVar, parentFontSize, parentWidth, parentHeight })
85
83
 
86
84
  const nodeRef = useRef(null)
87
85
  useNodesRef(props, ref, nodeRef, { style: normalStyle })