@mpxjs/webpack-plugin 2.10.14-beta.4 → 2.10.14-beta.5

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 (92) hide show
  1. package/lib/platform/template/wx/component-config/index.js +3 -1
  2. package/lib/platform/template/wx/component-config/nav-container.js +27 -0
  3. package/lib/runtime/components/ali/mpx-nav-container.mpx +3 -0
  4. package/lib/runtime/components/react/context.ts +18 -6
  5. package/lib/runtime/components/react/dist/context.d.ts +79 -0
  6. package/lib/runtime/components/react/dist/context.js +1 -0
  7. package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
  8. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
  9. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
  10. package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
  11. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
  12. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
  13. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
  14. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
  15. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
  16. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
  17. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
  18. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
  19. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
  20. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
  21. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
  22. package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
  23. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
  24. package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
  25. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
  26. package/lib/runtime/components/react/dist/mpx-input.d.ts +56 -0
  27. package/lib/runtime/components/react/dist/mpx-input.jsx +29 -10
  28. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
  29. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +50 -51
  30. package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
  31. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
  32. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +63 -0
  33. package/lib/runtime/components/react/dist/mpx-nav-container.d.ts +9 -0
  34. package/lib/runtime/components/react/dist/mpx-nav-container.jsx +23 -0
  35. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
  36. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
  37. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
  38. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
  39. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
  40. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
  42. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
  43. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
  44. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
  45. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +31 -0
  46. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
  47. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +22 -0
  48. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
  50. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
  51. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
  52. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
  53. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
  54. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
  55. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
  56. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
  57. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
  58. package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
  59. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
  60. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
  61. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
  62. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
  63. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
  64. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
  65. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
  66. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
  67. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
  68. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +52 -0
  69. package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
  70. package/lib/runtime/components/react/dist/mpx-text.d.ts +21 -0
  71. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
  72. package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
  73. package/lib/runtime/components/react/dist/mpx-view.d.ts +34 -0
  74. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
  75. package/lib/runtime/components/react/dist/nav.d.ts +11 -0
  76. package/lib/runtime/components/react/dist/nav.jsx +141 -0
  77. package/lib/runtime/components/react/dist/parser.d.ts +39 -0
  78. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +32 -0
  79. package/lib/runtime/components/react/dist/useNavShared.d.ts +2 -0
  80. package/lib/runtime/components/react/dist/useNavShared.js +6 -0
  81. package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
  82. package/lib/runtime/components/react/dist/utils.d.ts +122 -0
  83. package/lib/runtime/components/react/mpx-input.tsx +43 -16
  84. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +51 -54
  85. package/lib/runtime/components/react/mpx-nav-container.tsx +33 -0
  86. package/lib/runtime/components/react/nav.tsx +172 -0
  87. package/lib/runtime/components/react/types/common.d.ts +19 -0
  88. package/lib/runtime/components/react/useNavShared.ts +8 -0
  89. package/lib/runtime/components/web/mpx-nav-container.vue +13 -0
  90. package/lib/runtime/components/wx/mpx-nav-container.mpx +9 -0
  91. package/lib/utils/dom-tag-config.js +2 -2
  92. package/package.json +1 -1
@@ -0,0 +1,172 @@
1
+ /* eslint-disable space-before-function-paren */
2
+ import { createElement, useState, useMemo, memo, useContext, useLayoutEffect } from 'react'
3
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
4
+ import { StatusBar, processColor, TouchableWithoutFeedback, Image, View, StyleSheet, Text } from 'react-native'
5
+ import { useNavShared } from './useNavShared'
6
+
7
+ function convertToHex(color?: string) {
8
+ try {
9
+ const intColor = processColor(color) as number | null | undefined
10
+ if (intColor === null || intColor === undefined) {
11
+ return null
12
+ }
13
+ // 将32位整数颜色值转换为RGBA
14
+ const r = (intColor >> 16) & 255
15
+ const g = (intColor >> 8) & 255
16
+ const b = intColor & 255
17
+ // 转换为十六进制
18
+ const hexR = r.toString(16).padStart(2, '0')
19
+ const hexG = g.toString(16).padStart(2, '0')
20
+ const hexB = b.toString(16).padStart(2, '0')
21
+ return `#${hexR}${hexG}${hexB}`
22
+ } catch (error) {
23
+ return null
24
+ }
25
+ }
26
+
27
+ const titleHeight = 44
28
+ export function useInnerHeaderHeight(pageConfig: PageConfig) {
29
+ const safeArea = useSafeAreaInsets()
30
+ if (pageConfig.navigationStyle === 'custom') {
31
+ return 0
32
+ } else {
33
+ const safeAreaTop = safeArea?.top || 0
34
+ const headerHeight = safeAreaTop + titleHeight
35
+ return headerHeight
36
+ }
37
+ }
38
+
39
+ const styles = StyleSheet.create({
40
+ header: {
41
+ elevation: 3
42
+ },
43
+ headerContent: {
44
+ flexDirection: 'row',
45
+ alignItems: 'center',
46
+ justifyContent: 'center'
47
+ },
48
+ backButton: {
49
+ position: 'absolute',
50
+ height: '100%',
51
+ width: 40,
52
+ left: 0,
53
+ top: 0,
54
+ alignItems: 'center',
55
+ justifyContent: 'center'
56
+ },
57
+ backButtonImage: {
58
+ width: 22,
59
+ height: 22
60
+ },
61
+ title: {
62
+ fontSize: 17,
63
+ fontWeight: 600,
64
+ width: '60%',
65
+ textAlign: 'center'
66
+ }
67
+ })
68
+ const NavColor = {
69
+ White: '#ffffff',
70
+ Black: '#000000'
71
+ }
72
+ // navigationBarTextStyle 只支持黑白 'white'/'black
73
+ const validBarTextStyle = (textStyle?: string) => {
74
+ const textStyleColor = convertToHex(textStyle)
75
+ if (textStyle && textStyleColor && [NavColor.White, NavColor.Black].includes(textStyleColor)) {
76
+ return textStyleColor
77
+ } else {
78
+ return NavColor.White
79
+ }
80
+ }
81
+
82
+ export interface MpxNavProps {
83
+ pageConfig: PageConfig
84
+ navigation: any
85
+ }
86
+
87
+ export interface MpxNavFactorOptions {
88
+ Mpx: any
89
+ }
90
+
91
+ const BACK_ICON =
92
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg=='
93
+
94
+ function createMpxNav(options: MpxNavFactorOptions) {
95
+ const { Mpx } = options
96
+ const innerNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
97
+ const [innerPageConfig, setPageConfig] = useState<PageConfig>(pageConfig || {})
98
+ const [customNav] = useNavShared()
99
+ const safeAreaTop = useSafeAreaInsets()?.top || 0
100
+
101
+ navigation.setPageConfig = (config: PageConfig) => {
102
+ setPageConfig(Object.assign({}, innerPageConfig, config))
103
+ }
104
+ const isCustom = innerPageConfig.navigationStyle === 'custom'
105
+ const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
106
+ // 状态栏的颜色
107
+ const statusBarElement = (
108
+ <StatusBar
109
+ translucent
110
+ backgroundColor='transparent'
111
+ barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
112
+ )
113
+
114
+ if (isCustom)
115
+ return (
116
+ <>
117
+ {statusBarElement}
118
+ {customNav}
119
+ </>
120
+ )
121
+ // 假设是栈导航,获取栈的长度
122
+ const stackLength = navigation.getState()?.routes?.length
123
+ const onStackTopBack = Mpx.config?.rnConfig?.onStackTopBack
124
+ const isHandleStackTopBack = typeof onStackTopBack === 'function'
125
+
126
+ // 回退按钮与图标
127
+ // prettier-ignore
128
+ const backElement = stackLength > 1 || isHandleStackTopBack
129
+ ? (
130
+ <TouchableWithoutFeedback
131
+ onPress={() => {
132
+ if (stackLength <= 1 && isHandleStackTopBack) {
133
+ onStackTopBack()
134
+ return
135
+ }
136
+ navigation.goBack()
137
+ }}>
138
+ <View style={[styles.backButton]}>
139
+ <Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
140
+ </View>
141
+ </TouchableWithoutFeedback>
142
+ )
143
+ : null
144
+
145
+ return (
146
+ <View
147
+ style={[
148
+ styles.header,
149
+ {
150
+ paddingTop: safeAreaTop,
151
+ backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
152
+ }
153
+ ]}>
154
+ {statusBarElement}
155
+ {/* TODO: 确定 height 的有效性 */}
156
+ {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
157
+ {/* @ts-expect-error */}
158
+ <View style={styles.headerContent} height={titleHeight}>
159
+ {backElement}
160
+ <Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
161
+ {innerPageConfig.navigationBarTitleText?.trim() || ''}
162
+ </Text>
163
+ </View>
164
+ </View>
165
+ )
166
+ })
167
+
168
+ innerNav.displayName = 'MpxNav'
169
+ return innerNav
170
+ }
171
+
172
+ export default createMpxNav
@@ -18,3 +18,22 @@ export type ExtendedFunctionComponent = FunctionComponent & {
18
18
  }
19
19
 
20
20
  export type AnyFunc = (...args: ReadonlyArray<any>) => any
21
+
22
+ declare global {
23
+ interface PageConfig {
24
+ /**
25
+ * 是否自定义导航栏
26
+ */
27
+ navigationStyle?: 'custom'
28
+ /**
29
+ * 标题栏样式
30
+ */
31
+ navigationBarTextStyle?: 'white' | 'black' | '#ffffff' | '#000000'
32
+ /**
33
+ * 页面标题
34
+ */
35
+ navigationBarTitleText?: string
36
+
37
+ [key: string]: any
38
+ }
39
+ }
@@ -0,0 +1,8 @@
1
+ import { useContext } from 'react'
2
+ import { NavSharedContext } from './context'
3
+
4
+ export function useNavShared () {
5
+ const navSharedValue = useContext(NavSharedContext)
6
+
7
+ return [navSharedValue.customNav, navSharedValue.setCustomNav] as const
8
+ }
@@ -0,0 +1,13 @@
1
+ <script>
2
+ export default {
3
+ name: 'mpx-view',
4
+ data() {
5
+ return {}
6
+ },
7
+ props: {},
8
+ render() {
9
+ return this.$slots.default
10
+ },
11
+ methods: {}
12
+ }
13
+ </script>
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <slot />
3
+ </template>
4
+ <script type="application/json">
5
+ {
6
+ "component": true,
7
+ "usingComponents": {}
8
+ }
9
+ </script>
@@ -78,7 +78,7 @@ const isBuildInWebTag = makeMap(
78
78
  'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
79
79
  'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' +
80
80
  'mpx-tab-bar-container,mpx-form,mpx-navigator,mpx-rich-text,mpx-tab-bar,' +
81
- 'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
81
+ 'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text,mpx-nav-container'
82
82
  )
83
83
 
84
84
  /**
@@ -91,7 +91,7 @@ const isBuildInReactTag = makeMap(
91
91
  'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
92
92
  'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
93
93
  'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
94
- 'mpx-icon,mpx-canvas'
94
+ 'mpx-icon,mpx-canvas,mpx-nav-container'
95
95
  )
96
96
 
97
97
  const isSpace = makeMap('ensp,emsp,nbsp')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.14-beta.4",
3
+ "version": "2.10.14-beta.5",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"