@mpxjs/webpack-plugin 2.10.24 → 2.11.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 (151) hide show
  1. package/lib/index.js +4 -1
  2. package/lib/platform/style/wx/index.js +417 -120
  3. package/lib/platform/template/wx/component-config/picker.js +0 -6
  4. package/lib/react/style-helper.js +6 -6
  5. package/lib/resolver/AddEnvPlugin.js +1 -1
  6. package/lib/resolver/AddModePlugin.js +1 -1
  7. package/lib/resolver/ExtendComponentsPlugin.js +68 -0
  8. package/lib/runtime/components/extends/section-list.mpx +14 -0
  9. package/lib/runtime/components/react/animationHooks/index.ts +7 -3
  10. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +0 -2
  11. package/lib/runtime/components/react/dist/animationHooks/index.js +6 -1
  12. package/lib/runtime/components/react/dist/event.config.d.ts +2 -6
  13. package/lib/runtime/components/react/dist/event.config.js +28 -24
  14. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +1 -1
  15. package/lib/runtime/components/react/dist/getInnerListeners.js +74 -56
  16. package/lib/runtime/components/react/dist/mpx-button.d.ts +1 -2
  17. package/lib/runtime/components/react/dist/mpx-button.jsx +16 -9
  18. package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -2
  19. package/lib/runtime/components/react/dist/mpx-camera.jsx +36 -5
  20. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -2
  21. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -3
  22. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +1 -1
  23. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -2
  24. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +3 -4
  25. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +1 -2
  26. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +8 -9
  27. package/lib/runtime/components/react/dist/mpx-form.d.ts +1 -2
  28. package/lib/runtime/components/react/dist/mpx-form.jsx +5 -5
  29. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -2
  30. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
  31. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -2
  32. package/lib/runtime/components/react/dist/mpx-image.jsx +59 -43
  33. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +13 -4
  34. package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -2
  35. package/lib/runtime/components/react/dist/mpx-input.jsx +16 -8
  36. package/lib/runtime/components/react/dist/mpx-label.d.ts +1 -2
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +5 -6
  38. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -2
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +3 -3
  40. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +1 -2
  41. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +6 -6
  42. package/lib/runtime/components/react/dist/mpx-nav.jsx +1 -1
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +72 -23
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +2 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +4 -0
  46. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +1 -1
  47. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +10 -14
  48. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -2
  49. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.js +0 -5
  50. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +1 -1
  51. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +34 -14
  52. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -2
  53. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +4 -5
  54. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -2
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +3 -5
  56. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +5 -4
  57. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +2 -2
  58. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +3 -2
  59. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -2
  60. package/lib/runtime/components/react/dist/mpx-progress.jsx +1 -3
  61. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -2
  62. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +3 -4
  63. package/lib/runtime/components/react/dist/mpx-radio.d.ts +1 -2
  64. package/lib/runtime/components/react/dist/mpx-radio.jsx +8 -9
  65. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -2
  66. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -3
  67. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +1 -2
  68. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -6
  69. package/lib/runtime/components/react/dist/mpx-section-list.d.ts +51 -0
  70. package/lib/runtime/components/react/dist/mpx-section-list.jsx +376 -0
  71. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +37 -19
  72. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +4 -1
  73. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -4
  74. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -2
  75. package/lib/runtime/components/react/dist/mpx-slider.jsx +6 -7
  76. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +1 -2
  77. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +5 -5
  78. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +1 -2
  79. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +6 -6
  80. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +1 -2
  81. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -5
  82. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +1 -2
  83. package/lib/runtime/components/react/dist/mpx-swiper.jsx +4 -8
  84. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -2
  85. package/lib/runtime/components/react/dist/mpx-switch.jsx +1 -3
  86. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -2
  87. package/lib/runtime/components/react/dist/mpx-text.jsx +43 -25
  88. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -2
  89. package/lib/runtime/components/react/dist/mpx-video.jsx +4 -5
  90. package/lib/runtime/components/react/dist/mpx-view.d.ts +2 -2
  91. package/lib/runtime/components/react/dist/mpx-view.jsx +214 -114
  92. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +2 -1
  93. package/lib/runtime/components/react/dist/mpx-web-view.jsx +5 -1
  94. package/lib/runtime/components/react/dist/namedColorSet.d.ts +2 -0
  95. package/lib/runtime/components/react/dist/namedColorSet.js +149 -0
  96. package/lib/runtime/components/react/dist/utils.d.ts +71 -70
  97. package/lib/runtime/components/react/dist/utils.jsx +1295 -456
  98. package/lib/runtime/components/react/event.config.ts +32 -25
  99. package/lib/runtime/components/react/getInnerListeners.ts +84 -60
  100. package/lib/runtime/components/react/mpx-button.tsx +18 -18
  101. package/lib/runtime/components/react/mpx-camera.tsx +40 -8
  102. package/lib/runtime/components/react/mpx-canvas/index.tsx +5 -7
  103. package/lib/runtime/components/react/mpx-canvas/utils.tsx +3 -1
  104. package/lib/runtime/components/react/mpx-checkbox-group.tsx +2 -8
  105. package/lib/runtime/components/react/mpx-checkbox.tsx +9 -13
  106. package/lib/runtime/components/react/mpx-form.tsx +6 -8
  107. package/lib/runtime/components/react/mpx-icon/index.tsx +1 -5
  108. package/lib/runtime/components/react/mpx-image.tsx +66 -58
  109. package/lib/runtime/components/react/mpx-inline-text.tsx +13 -4
  110. package/lib/runtime/components/react/mpx-input.tsx +19 -12
  111. package/lib/runtime/components/react/mpx-label.tsx +6 -10
  112. package/lib/runtime/components/react/mpx-movable-area.tsx +3 -5
  113. package/lib/runtime/components/react/mpx-movable-view.tsx +7 -9
  114. package/lib/runtime/components/react/mpx-nav.tsx +1 -1
  115. package/lib/runtime/components/react/mpx-picker/index.tsx +100 -29
  116. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +3 -3
  117. package/lib/runtime/components/react/mpx-picker/selector.tsx +1 -1
  118. package/lib/runtime/components/react/mpx-picker/type.ts +4 -0
  119. package/lib/runtime/components/react/mpx-picker-view/index.tsx +17 -24
  120. package/lib/runtime/components/react/mpx-picker-view/pickerVIewContext.ts +0 -9
  121. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +44 -23
  122. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +1 -9
  123. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +0 -9
  124. package/lib/runtime/components/react/mpx-popup/index.tsx +7 -3
  125. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +3 -2
  126. package/lib/runtime/components/react/mpx-progress.tsx +0 -6
  127. package/lib/runtime/components/react/mpx-radio-group.tsx +2 -8
  128. package/lib/runtime/components/react/mpx-radio.tsx +9 -13
  129. package/lib/runtime/components/react/mpx-rich-text/index.tsx +0 -6
  130. package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -9
  131. package/lib/runtime/components/react/mpx-section-list.tsx +557 -0
  132. package/lib/runtime/components/react/mpx-simple-text.tsx +36 -25
  133. package/lib/runtime/components/react/mpx-simple-view.tsx +17 -5
  134. package/lib/runtime/components/react/mpx-slider.tsx +15 -13
  135. package/lib/runtime/components/react/mpx-sticky-header.tsx +6 -8
  136. package/lib/runtime/components/react/mpx-sticky-section.tsx +7 -9
  137. package/lib/runtime/components/react/mpx-swiper-item.tsx +6 -7
  138. package/lib/runtime/components/react/mpx-swiper.tsx +5 -11
  139. package/lib/runtime/components/react/mpx-switch.tsx +0 -6
  140. package/lib/runtime/components/react/mpx-text.tsx +45 -36
  141. package/lib/runtime/components/react/mpx-video.tsx +3 -8
  142. package/lib/runtime/components/react/mpx-view.tsx +235 -129
  143. package/lib/runtime/components/react/mpx-web-view.tsx +12 -6
  144. package/lib/runtime/components/react/namedColorSet.ts +150 -0
  145. package/lib/runtime/components/react/types/getInnerListeners.d.ts +21 -1
  146. package/lib/runtime/components/react/types/global.d.ts +1 -0
  147. package/lib/runtime/components/react/utils.tsx +1352 -550
  148. package/lib/runtime/i18n.wxs +15 -9
  149. package/lib/style-compiler/strip-conditional.js +19 -4
  150. package/lib/template-compiler/compiler.js +6 -0
  151. package/package.json +6 -6
@@ -8,9 +8,6 @@ module.exports = function ({ print }) {
8
8
  const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false })
9
9
  const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
10
10
  const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
11
- const iosPropLog = print({ platform: 'ios', tag: TAG_NAME, isError: false })
12
- const androidPropLog = print({ platform: 'android', tag: TAG_NAME, isError: false })
13
- const harmonyPropLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false })
14
11
  const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
15
12
 
16
13
  return {
@@ -48,9 +45,6 @@ module.exports = function ({ print }) {
48
45
  ali: aliPropLog,
49
46
  jd: jdPropLog,
50
47
  qa: qaPropLog,
51
- ios: iosPropLog,
52
- android: androidPropLog,
53
- harmony: harmonyPropLog,
54
48
  ks: ksPropLog
55
49
  }
56
50
  ],
@@ -5,21 +5,21 @@ const getRulesRunner = require('../platform/index')
5
5
  const createDiagnostic = require('../platform/create-diagnostic')
6
6
  const dash2hump = require('../utils/hump-dash').dash2hump
7
7
  const parseValues = require('../utils/string').parseValues
8
- const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh|px)?\s*$/
8
+ const unitRegExp = /^\s*(-?(?:\d+(?:\.\d+)?|\.\d+))(rpx|vw|vh|px)?\s*$/
9
9
  const hairlineRegExp = /^\s*hairlineWidth\s*$/
10
10
  const varRegExp = /^--/
11
11
  const cssPrefixExp = /^-(webkit|moz|ms|o)-/
12
12
  function getClassMap ({ content, styles, filename, inputFileSystem, mode, srcMode, ctorType, formatValueName, warn, error }) {
13
13
  const classMap = ctorType === 'page'
14
- ? { [MPX_TAG_PAGE_SELECTOR]: { flex: 1, height: "'100%'" } }
15
- : {}
14
+ ? { [MPX_TAG_PAGE_SELECTOR]: { flex: 1, height: "'100%'" } }
15
+ : {}
16
16
 
17
17
  styles = styles && styles.length
18
18
  ? styles
19
19
  : [{
20
- content,
21
- filename
22
- }]
20
+ content,
21
+ filename
22
+ }]
23
23
 
24
24
  function formatValue (value) {
25
25
  let needStringify = true
@@ -19,7 +19,7 @@ module.exports = class AddEnvPlugin {
19
19
  const envPattern = new RegExp(`\\.${env}(\\.|$)`)
20
20
 
21
21
  resolver.getHook(this.source).tapAsync('AddEnvPlugin', (request, resolveContext, callback) => {
22
- if (request.env) {
22
+ if (request.__mpxResolvedExtendComponent || request.env) {
23
23
  return callback()
24
24
  }
25
25
  const obj = {
@@ -21,7 +21,7 @@ module.exports = class AddModePlugin {
21
21
  const defaultModePattern = new RegExp(`\\.${defaultMode}(\\.|$)`)
22
22
 
23
23
  resolver.getHook(this.source).tapAsync('AddModePlugin', (request, resolveContext, callback) => {
24
- if (request.mode || request.env) {
24
+ if (request.__mpxResolvedExtendComponent || request.mode || request.env) {
25
25
  return callback()
26
26
  }
27
27
  const obj = {
@@ -0,0 +1,68 @@
1
+ const path = require('path')
2
+ const toPosix = require('../utils/to-posix')
3
+ const EXTEND_COMPONENT_PATH_REGEXP = /@mpxjs\/webpack-plugin\/lib\/runtime\/components\/extends\/[^/]+$/
4
+ const RN_COMPONENTS_DIST_PATH = 'lib/runtime/components/react/dist'
5
+ const EXTEND_COMPONENTS = {
6
+ 'section-list': {
7
+ ios: `${RN_COMPONENTS_DIST_PATH}/mpx-section-list.jsx`,
8
+ android: `${RN_COMPONENTS_DIST_PATH}/mpx-section-list.jsx`,
9
+ harmony: `${RN_COMPONENTS_DIST_PATH}/mpx-section-list.jsx`
10
+ }
11
+ }
12
+
13
+ /**
14
+ * 扩展组件路径解析插件
15
+ * 将 @mpxjs/webpack-plugin/lib/runtime/components/extends/[component-name] 格式的路径
16
+ * 解析为对应平台的实际组件路径
17
+ */
18
+ module.exports = class ExtendComponentsPlugin {
19
+ constructor (source, mode, target) {
20
+ this.source = source
21
+ this.target = target
22
+ this.mode = mode
23
+ }
24
+
25
+ apply (resolver) {
26
+ const target = resolver.ensureHook(this.target)
27
+ const mode = this.mode
28
+
29
+ resolver.getHook(this.source).tapAsync('ExtendComponentsPlugin', (request, resolveContext, callback) => {
30
+ if (request.__mpxResolvedExtendComponent) return callback()
31
+
32
+ const componentName = getComponentName(request)
33
+ if (!componentName) {
34
+ return callback()
35
+ }
36
+
37
+ // 检查组件是否在配置中
38
+ const componentTargetMap = EXTEND_COMPONENTS[componentName]
39
+ const targetSubPath = componentTargetMap && componentTargetMap[mode]
40
+ if (!targetSubPath) {
41
+ return callback(new Error(`Extended component "${componentName}" cannot be used on the ${mode} platform.`))
42
+ }
43
+ const targetPath = path.join(request.descriptionFileRoot, targetSubPath)
44
+ const targetRelativePath = `./${targetSubPath}`
45
+
46
+ const redirectRequest = Object.assign({}, request, {
47
+ path: targetPath,
48
+ relativePath: targetRelativePath,
49
+ __mpxResolvedExtendComponent: true
50
+ })
51
+
52
+ resolver.doResolve(
53
+ target,
54
+ redirectRequest,
55
+ `resolve extend component: ${componentName} to ${targetPath}`,
56
+ resolveContext,
57
+ callback
58
+ )
59
+ })
60
+ }
61
+ }
62
+
63
+ function getComponentName (request) {
64
+ if (!request.path) return
65
+ const requestPath = toPosix(request.path)
66
+ if (!EXTEND_COMPONENT_PATH_REGEXP.test(requestPath)) return
67
+ return path.basename(requestPath, path.extname(requestPath))
68
+ }
@@ -0,0 +1,14 @@
1
+ <!--
2
+ Placeholder for @mpxjs/webpack-plugin/lib/runtime/components/extends/section-list.
3
+ ExtendComponentsPlugin should always redirect requests away from this file at
4
+ build time. Reaching this module means the plugin failed to redirect — most
5
+ likely because section-list is not supported on the current platform, or
6
+ ExtendComponentsPlugin is not registered on the resolver.
7
+ -->
8
+ <template></template>
9
+
10
+ <script>
11
+ import { error } from '@mpxjs/utils'
12
+ error('section-list extend placeholder reached at runtime, ExtendComponentsPlugin redirect failed. See build log for the original error.')
13
+ export default {}
14
+ </script>
@@ -4,14 +4,13 @@ import useAnimationAPIHooks from './useAnimationAPIHooks'
4
4
  import useTransitionHooks from './useTransitionHooks'
5
5
  import type { AnimatableValue } from 'react-native-reanimated'
6
6
  import type { MutableRefObject } from 'react'
7
- import type { NativeSyntheticEvent } from 'react-native'
8
7
  import type { _ViewProps } from '../mpx-view'
9
8
 
10
9
  // 动画类型
11
10
  export type AnimationType = 'api'|'animation'|'transition'|'none'
12
11
 
13
- export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean | AnimationType, layoutRef: MutableRefObject<any>, transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void }) {
14
- const { style: originalStyle = {}, enableAnimation, animation, transitionend, layoutRef } = props
12
+ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean | AnimationType, layoutRef: MutableRefObject<any> }) {
13
+ const { style: originalStyle = {}, enableAnimation, animation, catchtransitionend, bindtransitionend, layoutRef } = props
15
14
  // 记录动画类型
16
15
  let animationType = ''
17
16
  if (hasOwn(originalStyle, 'animation') || (hasOwn(originalStyle, 'animationName') && hasOwn(originalStyle, 'animationDuration'))) {
@@ -42,6 +41,11 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
42
41
  if (!animationTypeRef.current) return { enableStyleAnimation: false }
43
42
 
44
43
  const hooksProps = { style: originalStyle }
44
+ const transitionend = typeof catchtransitionend === 'function'
45
+ ? catchtransitionend
46
+ : typeof bindtransitionend === 'function'
47
+ ? bindtransitionend
48
+ : undefined
45
49
  if (transitionend && typeof transitionend === 'function') {
46
50
  function withTimingCallback (finished?: boolean, current?: AnimatableValue, duration?: number) {
47
51
  const target = {
@@ -1,11 +1,9 @@
1
1
  import type { MutableRefObject } from 'react';
2
- import type { NativeSyntheticEvent } from 'react-native';
3
2
  import type { _ViewProps } from '../mpx-view';
4
3
  export type AnimationType = 'api' | 'animation' | 'transition' | 'none';
5
4
  export default function useAnimationHooks<T, P>(props: _ViewProps & {
6
5
  enableAnimation?: boolean | AnimationType;
7
6
  layoutRef: MutableRefObject<any>;
8
- transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
9
7
  }): {
10
8
  enableStyleAnimation: boolean;
11
9
  animationStyle?: undefined;
@@ -3,7 +3,7 @@ import { useRef } from 'react';
3
3
  import useAnimationAPIHooks from './useAnimationAPIHooks';
4
4
  import useTransitionHooks from './useTransitionHooks';
5
5
  export default function useAnimationHooks(props) {
6
- const { style: originalStyle = {}, enableAnimation, animation, transitionend, layoutRef } = props;
6
+ const { style: originalStyle = {}, enableAnimation, animation, catchtransitionend, bindtransitionend, layoutRef } = props;
7
7
  // 记录动画类型
8
8
  let animationType = '';
9
9
  if (hasOwn(originalStyle, 'animation') || (hasOwn(originalStyle, 'animationName') && hasOwn(originalStyle, 'animationDuration'))) {
@@ -34,6 +34,11 @@ export default function useAnimationHooks(props) {
34
34
  if (!animationTypeRef.current)
35
35
  return { enableStyleAnimation: false };
36
36
  const hooksProps = { style: originalStyle };
37
+ const transitionend = typeof catchtransitionend === 'function'
38
+ ? catchtransitionend
39
+ : typeof bindtransitionend === 'function'
40
+ ? bindtransitionend
41
+ : undefined;
37
42
  if (transitionend && typeof transitionend === 'function') {
38
43
  function withTimingCallback(finished, current, duration) {
39
44
  const target = {
@@ -1,7 +1,3 @@
1
- declare const eventConfigMap: {
2
- [key: string]: {
3
- bitFlag: string;
4
- events: string[];
5
- };
6
- };
1
+ import type { EventMeta } from './types/getInnerListeners';
2
+ declare const eventConfigMap: Record<string, EventMeta>;
7
3
  export default eventConfigMap;
@@ -1,27 +1,31 @@
1
+ const tapEvents = ['onTouchStart', 'onTouchMove', 'onTouchEnd'];
2
+ const longpressEvents = ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'];
3
+ const tapCaptureEvents = ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'];
4
+ const longpressCaptureEvents = ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'];
1
5
  const eventConfigMap = {
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'] }
6
+ bindtap: { bitFlag: '0', events: tapEvents, eventName: 'tap', eventType: 'bubble', hasCatch: false },
7
+ bindlongpress: { bitFlag: '1', events: longpressEvents, eventName: 'longpress', eventType: 'bubble', hasCatch: false },
8
+ bindtouchstart: { bitFlag: '2', events: ['onTouchStart'], eventName: 'touchstart', eventType: 'bubble', hasCatch: false },
9
+ bindtouchmove: { bitFlag: '3', events: ['onTouchMove'], eventName: 'touchmove', eventType: 'bubble', hasCatch: false },
10
+ bindtouchend: { bitFlag: '4', events: ['onTouchEnd'], eventName: 'touchend', eventType: 'bubble', hasCatch: false },
11
+ bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'], eventName: 'touchcancel', eventType: 'bubble', hasCatch: false },
12
+ catchtap: { bitFlag: '6', events: tapEvents, eventName: 'tap', eventType: 'bubble', hasCatch: true },
13
+ catchlongpress: { bitFlag: '7', events: longpressEvents, eventName: 'longpress', eventType: 'bubble', hasCatch: true },
14
+ catchtouchstart: { bitFlag: '8', events: ['onTouchStart'], eventName: 'touchstart', eventType: 'bubble', hasCatch: true },
15
+ catchtouchmove: { bitFlag: '9', events: ['onTouchMove'], eventName: 'touchmove', eventType: 'bubble', hasCatch: true },
16
+ catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'], eventName: 'touchend', eventType: 'bubble', hasCatch: true },
17
+ catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'], eventName: 'touchcancel', eventType: 'bubble', hasCatch: true },
18
+ 'capture-bindtap': { bitFlag: 'c', events: tapCaptureEvents, eventName: 'tap', eventType: 'capture', hasCatch: false },
19
+ 'capture-bindlongpress': { bitFlag: 'd', events: longpressCaptureEvents, eventName: 'longpress', eventType: 'capture', hasCatch: false },
20
+ 'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'], eventName: 'touchstart', eventType: 'capture', hasCatch: false },
21
+ 'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'], eventName: 'touchmove', eventType: 'capture', hasCatch: false },
22
+ 'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'], eventName: 'touchend', eventType: 'capture', hasCatch: false },
23
+ 'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'], eventName: 'touchcancel', eventType: 'capture', hasCatch: false },
24
+ 'capture-catchtap': { bitFlag: 'i', events: tapCaptureEvents, eventName: 'tap', eventType: 'capture', hasCatch: true },
25
+ 'capture-catchlongpress': { bitFlag: 'j', events: longpressCaptureEvents, eventName: 'longpress', eventType: 'capture', hasCatch: true },
26
+ 'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'], eventName: 'touchstart', eventType: 'capture', hasCatch: true },
27
+ 'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'], eventName: 'touchmove', eventType: 'capture', hasCatch: true },
28
+ 'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'], eventName: 'touchend', eventType: 'capture', hasCatch: true },
29
+ 'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'], eventName: 'touchcancel', eventType: 'capture', hasCatch: true }
26
30
  };
27
31
  export default eventConfigMap;
@@ -3,5 +3,5 @@ export declare const getCustomEvent: (type: string | undefined, oe: any, { detai
3
3
  detail?: Record<string, unknown> | undefined;
4
4
  layoutRef?: LayoutRef | undefined;
5
5
  }, props?: Props) => any;
6
- declare const useInnerProps: (props?: Props, userRemoveProps?: RemoveProps, rawConfig?: RawConfig) => Record<string, (e: ExtendedNativeTouchEvent) => void> & Omit<Props, string>;
6
+ declare const useInnerProps: (props?: Props, userRemoveProps?: RemoveProps, rawConfig?: RawConfig) => Record<string, (e: ExtendedNativeTouchEvent) => void> & Props;
7
7
  export default useInnerProps;
@@ -1,11 +1,22 @@
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
  const globalEventState = {
6
6
  needPress: true,
7
7
  identifier: null
8
8
  };
9
+ const baseRemovePropsMap = {
10
+ children: true,
11
+ 'enable-background': true,
12
+ 'enable-offset': true,
13
+ 'enable-var': true,
14
+ 'external-var-context': true,
15
+ 'parent-font-size': true,
16
+ 'parent-width': true,
17
+ 'parent-height': true,
18
+ 'enable-text-pass-through': true
19
+ };
9
20
  const getTouchEvent = (type, event, config) => {
10
21
  const { navigation, propsRef, layoutRef } = config;
11
22
  const props = propsRef.current;
@@ -162,26 +173,44 @@ function handleTouchcancel(e, type, eventConfig) {
162
173
  handleEmitEvent('touchcancel', e, type, eventConfig);
163
174
  innerRef.current.startTimer[type] && clearTimeout(innerRef.current.startTimer[type]);
164
175
  }
165
- function createTouchEventHandler(eventName, eventConfig) {
176
+ const touchHandlerMap = {
177
+ onTouchStart: {
178
+ type: 'bubble',
179
+ handler: handleTouchstart
180
+ },
181
+ onTouchMove: {
182
+ type: 'bubble',
183
+ handler: handleTouchmove
184
+ },
185
+ onTouchEnd: {
186
+ type: 'bubble',
187
+ handler: handleTouchend
188
+ },
189
+ onTouchCancel: {
190
+ type: 'bubble',
191
+ handler: handleTouchcancel
192
+ },
193
+ onTouchStartCapture: {
194
+ type: 'capture',
195
+ handler: handleTouchstart
196
+ },
197
+ onTouchMoveCapture: {
198
+ type: 'capture',
199
+ handler: handleTouchmove
200
+ },
201
+ onTouchEndCapture: {
202
+ type: 'capture',
203
+ handler: handleTouchend
204
+ },
205
+ onTouchCancelCapture: {
206
+ type: 'capture',
207
+ handler: handleTouchcancel
208
+ }
209
+ };
210
+ function createTouchEventHandler(eventName, eventConfigRef) {
211
+ const eventHandler = touchHandlerMap[eventName];
166
212
  return (e) => {
167
- const bubbleHandlerMap = {
168
- onTouchStart: handleTouchstart,
169
- onTouchMove: handleTouchmove,
170
- onTouchEnd: handleTouchend,
171
- onTouchCancel: handleTouchcancel
172
- };
173
- const captureHandlerMap = {
174
- onTouchStartCapture: handleTouchstart,
175
- onTouchMoveCapture: handleTouchmove,
176
- onTouchEndCapture: handleTouchend,
177
- onTouchCancelCapture: handleTouchcancel
178
- };
179
- if (bubbleHandlerMap[eventName]) {
180
- bubbleHandlerMap[eventName](e, 'bubble', eventConfig);
181
- }
182
- if (captureHandlerMap[eventName]) {
183
- captureHandlerMap[eventName](e, 'capture', eventConfig);
184
- }
213
+ eventHandler.handler(e, eventHandler.type, eventConfigRef.current);
185
214
  };
186
215
  }
187
216
  const useInnerProps = (props = {}, userRemoveProps = [], rawConfig) => {
@@ -209,58 +238,47 @@ const useInnerProps = (props = {}, userRemoveProps = [], rawConfig) => {
209
238
  disableTap: false,
210
239
  navigation
211
240
  }, rawConfig);
241
+ const eventConfigRef = useRef(eventConfig);
242
+ const restProps = {};
243
+ const eventNameMap = {};
244
+ const userRemovePropsMap = {};
212
245
  let hashEventKey = '';
213
- const rawEventKeys = [];
214
- const transformedEventSet = new Set();
246
+ userRemoveProps.forEach((key) => {
247
+ userRemovePropsMap[key] = true;
248
+ });
215
249
  Object.keys(props).forEach((key) => {
216
- if (eventConfigMap[key]) {
217
- hashEventKey += eventConfigMap[key].bitFlag;
218
- rawEventKeys.push(key);
219
- eventConfigMap[key].events.forEach((event) => {
220
- transformedEventSet.add(event);
250
+ const eventMeta = eventConfigMap[key];
251
+ if (eventMeta) {
252
+ hashEventKey += eventMeta.bitFlag;
253
+ eventMeta.events.forEach((event) => {
254
+ eventNameMap[event] = true;
221
255
  });
222
- const match = /^(bind|catch|capture-bind|capture-catch)(.*)$/.exec(key);
223
- const prefix = match[1];
224
- const eventName = match[2];
225
- eventConfig[eventName] = eventConfig[eventName] || {
256
+ eventConfig[eventMeta.eventName] = eventConfig[eventMeta.eventName] || {
226
257
  bubble: [],
227
258
  capture: [],
228
259
  hasCatch: false
229
260
  };
230
- if (prefix === 'bind' || prefix === 'catch') {
231
- eventConfig[eventName].bubble.push(key);
232
- }
233
- else {
234
- eventConfig[eventName].capture.push(key);
235
- }
236
- if (prefix === 'catch' || prefix === 'capture-catch') {
237
- eventConfig[eventName].hasCatch = true;
261
+ eventConfig[eventMeta.eventName][eventMeta.eventType].push(key);
262
+ if (eventMeta.hasCatch) {
263
+ eventConfig[eventMeta.eventName].hasCatch = true;
238
264
  }
265
+ return;
266
+ }
267
+ if (!baseRemovePropsMap[key] && !userRemovePropsMap[key]) {
268
+ restProps[key] = props[key];
239
269
  }
240
270
  });
271
+ eventConfigRef.current = eventConfig;
241
272
  const events = useMemo(() => {
242
273
  if (!hashEventKey) {
243
274
  return {};
244
275
  }
245
276
  const events = {};
246
- for (const eventName of transformedEventSet) {
247
- events[eventName] = createTouchEventHandler(eventName, eventConfig);
248
- }
277
+ Object.keys(eventNameMap).forEach((eventName) => {
278
+ events[eventName] = createTouchEventHandler(eventName, eventConfigRef);
279
+ });
249
280
  return events;
250
281
  }, [hashEventKey]);
251
- const removeProps = [
252
- 'children',
253
- 'enable-background',
254
- 'enable-offset',
255
- 'enable-var',
256
- 'external-var-context',
257
- 'parent-font-size',
258
- 'parent-width',
259
- 'parent-height',
260
- 'enable-text-pass-through',
261
- ...userRemoveProps,
262
- ...rawEventKeys
263
- ];
264
- return extendObject({}, events, omit(props, removeProps));
282
+ return extendObject({}, events, restProps);
265
283
  };
266
284
  export default useInnerProps;
@@ -55,8 +55,7 @@ export interface ButtonProps {
55
55
  'form-type'?: 'submit' | 'reset';
56
56
  'enable-offset'?: boolean;
57
57
  'enable-var'?: boolean;
58
- 'external-var-context'?: Record<string, any>;
59
- 'parent-font-size'?: number;
58
+ 'enable-text-pass-through'?: boolean;
60
59
  'parent-width'?: number;
61
60
  'parent-height'?: number;
62
61
  style?: ViewStyle & TextStyle & Record<string, any>;
@@ -36,9 +36,9 @@
36
36
  */
37
37
  import { createElement, useEffect, useRef, forwardRef, useContext } from 'react';
38
38
  import { View, StyleSheet, Animated, Easing, useAnimatedValue } from 'react-native';
39
- import { warn } from '@mpxjs/utils';
39
+ import { warn, hasOwn } from '@mpxjs/utils';
40
40
  import { GestureDetector } from 'react-native-gesture-handler';
41
- import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover, useTextPassThroughValue } from './utils';
41
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover, useTextPassThrough } from './utils';
42
42
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
43
43
  import useNodesRef from './useNodesRef';
44
44
  import { RouteContext, FormContext } from './context';
@@ -55,14 +55,14 @@ const OpenTypeEventsMap = new Map([
55
55
  ]);
56
56
  const styles = StyleSheet.create({
57
57
  button: {
58
- width: '100%',
59
58
  flexDirection: 'row',
60
59
  justifyContent: 'center',
61
60
  alignItems: 'center',
62
61
  height: 46,
63
62
  borderRadius: 5,
64
63
  backgroundColor: '#F8F8F8',
65
- marginHorizontal: 'auto' // 按钮默认居中
64
+ marginHorizontal: 'auto',
65
+ paddingHorizontal: 14
66
66
  },
67
67
  buttonMini: {
68
68
  height: 30
@@ -130,7 +130,7 @@ const Loading = ({ alone = false }) => {
130
130
  };
131
131
  const Button = forwardRef((buttonProps, ref) => {
132
132
  const { textProps, innerProps: props = {} } = splitProps(buttonProps);
133
- const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap } = props;
133
+ const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'enable-text-pass-through': enableTextPassThrough, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap } = props;
134
134
  const { pageId } = useContext(RouteContext) || {};
135
135
  const formContext = useContext(FormContext);
136
136
  const enableHover = hoverClass !== 'none';
@@ -166,14 +166,21 @@ const Button = forwardRef((buttonProps, ref) => {
166
166
  };
167
167
  const defaultViewStyle = extendObject({}, styles.button, isMiniSize ? styles.buttonMini : null, viewStyle);
168
168
  const defaultTextStyle = extendObject({}, styles.text, isMiniSize ? styles.textMini : {}, { color: plain ? plainTextColor : normalTextColor });
169
+ const styleObj = isHover ? extendObject({}, style, hoverStyle) : style;
169
170
  const defaultStyle = extendObject({}, defaultViewStyle, defaultTextStyle);
170
- const styleObj = extendObject({}, defaultStyle, style, isHover ? hoverStyle : {});
171
- const { hasPositionFixed, hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
171
+ // 用户 shorthand 优先:避免 longhand default 反向覆盖
172
+ if (hasOwn(styleObj, 'margin')) {
173
+ delete defaultStyle.marginHorizontal;
174
+ }
175
+ if (hasOwn(styleObj, 'padding')) {
176
+ delete defaultStyle.paddingHorizontal;
177
+ }
178
+ const { hasPositionFixed, hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, parentWidth, parentHeight, defaultStyle });
172
179
  const nodeRef = useRef(null);
173
180
  useNodesRef(props, ref, nodeRef, { style: normalStyle });
174
181
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
175
182
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
176
- const textPassThrough = useTextPassThroughValue(textStyle, textProps);
183
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough });
177
184
  if (backgroundStyle) {
178
185
  warn('Button does not support background image-related styles!');
179
186
  }
@@ -259,7 +266,7 @@ const Button = forwardRef((buttonProps, ref) => {
259
266
  layoutRef,
260
267
  disableTap: disabled
261
268
  });
262
- const baseButton = createElement(View, innerProps, loading && createElement(Loading, { alone: !children }), wrapChildren(props, {
269
+ const baseButton = createElement(View, innerProps, loading && createElement(Loading, { alone: !children }), wrapChildren(props.children, {
263
270
  hasVarDec,
264
271
  varContext: varContextRef.current,
265
272
  textPassThrough
@@ -18,11 +18,9 @@ interface CameraProps {
18
18
  type: string;
19
19
  data: string;
20
20
  }) => void;
21
- 'parent-font-size'?: number;
22
21
  'parent-width'?: number;
23
22
  'parent-height'?: number;
24
23
  'enable-var'?: boolean;
25
- 'external-var-context'?: any;
26
24
  }
27
25
  type HandlerRef<T, P> = {
28
26
  current: T | null;
@@ -12,15 +12,24 @@ const qualityValue = {
12
12
  original: 100
13
13
  };
14
14
  let RecordRes = null;
15
+ const cameraPermissionCacheMap = new Map();
16
+ function getCameraPermissionCache(pageId) {
17
+ if (pageId == null)
18
+ return;
19
+ let cache = cameraPermissionCacheMap.get(pageId);
20
+ if (!cache) {
21
+ cache = {};
22
+ cameraPermissionCacheMap.set(pageId, cache);
23
+ }
24
+ return cache;
25
+ }
15
26
  const _camera = forwardRef((props, ref) => {
16
27
  // eslint-disable-next-line @typescript-eslint/no-var-requires
17
28
  const cameraRef = useRef(null);
18
- const { mode = 'normal', resolution = 'medium', 'device-position': devicePosition = 'back', flash = 'auto', 'frame-size': frameSize = 'medium', bindinitdone, bindstop, bindscancode, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'enable-var': enableVar, 'external-var-context': externalVarContext, style = {} } = props;
29
+ const { mode = 'normal', resolution = 'medium', 'device-position': devicePosition = 'back', flash = 'auto', 'frame-size': frameSize = 'medium', bindinitdone, bindstop, bindscancode, 'parent-width': parentWidth, 'parent-height': parentHeight, 'enable-var': enableVar, style = {} } = props;
19
30
  const styleObj = extendObject({}, style);
20
31
  const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, {
21
32
  enableVar,
22
- externalVarContext,
23
- parentFontSize,
24
33
  parentWidth,
25
34
  parentHeight
26
35
  });
@@ -210,14 +219,36 @@ const _camera = forwardRef((props, ref) => {
210
219
  try {
211
220
  const cameraPermission = global?.__mpx?.config?.rnConfig?.cameraPermission;
212
221
  if (typeof cameraPermission === 'function') {
213
- const permissionResult = await cameraPermission();
214
- setHasPermission(permissionResult === true);
222
+ const permissionCache = getCameraPermissionCache(pageId);
223
+ if (permissionCache && hasOwn(permissionCache, 'result')) {
224
+ setHasPermission(permissionCache.result === true);
225
+ return;
226
+ }
227
+ let permissionResult;
228
+ if (permissionCache) {
229
+ if (!permissionCache.promise) {
230
+ permissionCache.promise = cameraPermission();
231
+ }
232
+ permissionResult = await permissionCache.promise;
233
+ }
234
+ else {
235
+ permissionResult = await cameraPermission();
236
+ }
237
+ const granted = permissionResult === true;
238
+ if (permissionCache) {
239
+ permissionCache.result = granted;
240
+ }
241
+ setHasPermission(granted);
215
242
  }
216
243
  else {
217
244
  setHasPermission(true);
218
245
  }
219
246
  }
220
247
  catch (error) {
248
+ const permissionCache = getCameraPermissionCache(pageId);
249
+ if (permissionCache) {
250
+ permissionCache.result = false;
251
+ }
221
252
  setHasPermission(false);
222
253
  }
223
254
  };