@mpxjs/webpack-plugin 2.10.16 → 2.10.17-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/helpers.js +2 -0
- package/lib/index.js +40 -15
- package/lib/json-compiler/helper.js +72 -2
- package/lib/json-compiler/index.js +14 -54
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +10 -4
- package/lib/native-loader.js +6 -3
- package/lib/platform/json/wx/index.js +24 -29
- package/lib/platform/style/wx/index.js +8 -1
- package/lib/platform/template/wx/component-config/button.js +12 -3
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/react/index.js +2 -0
- package/lib/react/processJSON.js +39 -71
- package/lib/react/processStyles.js +3 -2
- package/lib/react/processTemplate.js +8 -6
- package/lib/react/script-helper.js +6 -16
- package/lib/react/style-helper.js +10 -2
- package/lib/runtime/components/react/context.ts +12 -6
- package/lib/runtime/components/react/dist/context.d.ts +75 -0
- package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
- package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +107 -57
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +50 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +32 -8
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +58 -50
- package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +10 -2
- package/lib/runtime/components/react/dist/parser.d.ts +40 -0
- package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.d.ts +123 -0
- package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.jsx +16 -6
- package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-image.tsx +130 -77
- package/lib/runtime/components/react/mpx-input.tsx +38 -15
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +66 -49
- package/lib/runtime/components/react/mpx-nav.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
- package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
- package/lib/runtime/components/react/mpx-text.tsx +38 -5
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +13 -4
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/utils.tsx +15 -6
- package/lib/script-setup-compiler/index.js +2 -2
- package/lib/style-compiler/index.js +3 -2
- package/lib/style-compiler/load-postcss-config.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +10 -2
- package/lib/style-compiler/strip-conditional-loader.js +228 -13
- package/lib/template-compiler/compiler.js +266 -69
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +6 -4
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +2 -1
- package/lib/utils/dom-tag-config.js +5 -5
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -0
- package/lib/utils/merge-visitors.js +55 -0
- package/lib/utils/pre-process-json.js +5 -0
- package/lib/web/index.js +2 -0
- package/lib/web/processJSON.js +44 -16
- package/lib/web/processScript.js +1 -1
- package/lib/web/processTemplate.js +6 -4
- package/lib/web/script-helper.js +19 -9
- package/lib/wxs/pre-loader.js +9 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +7 -5
- package/LICENSE +0 -433
- package/lib/utils/chain-assign.js +0 -47
|
@@ -2,15 +2,41 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* ✔ selectable
|
|
4
4
|
* ✘ space
|
|
5
|
-
*
|
|
5
|
+
* ✔ decode
|
|
6
6
|
*/
|
|
7
7
|
import { Text, TextStyle, TextProps } from 'react-native'
|
|
8
|
-
import { useRef, forwardRef, ReactNode, JSX, createElement } from 'react'
|
|
8
|
+
import { useRef, forwardRef, ReactNode, JSX, createElement, Children } from 'react'
|
|
9
9
|
import Portal from './mpx-portal'
|
|
10
10
|
import useInnerProps from './getInnerListeners'
|
|
11
11
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
12
12
|
import { useTransformStyle, wrapChildren, extendObject } from './utils'
|
|
13
13
|
|
|
14
|
+
const decodeMap = {
|
|
15
|
+
'<': '<',
|
|
16
|
+
'>': '>',
|
|
17
|
+
'"': '"',
|
|
18
|
+
'&': '&',
|
|
19
|
+
''': '\'',
|
|
20
|
+
' ': ' '
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const encodedRe = /&(?:lt|gt|quot|amp|#39|nbsp);/g
|
|
24
|
+
function decode (value: string) {
|
|
25
|
+
if (value != null) {
|
|
26
|
+
return value.replace(encodedRe, function (match) {
|
|
27
|
+
return decodeMap[match as keyof typeof decodeMap]
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getDecodedChildren (children: ReactNode) {
|
|
33
|
+
return Children.map(children, (child) => {
|
|
34
|
+
if (typeof child === 'string') {
|
|
35
|
+
return decode(child)
|
|
36
|
+
}
|
|
37
|
+
return child
|
|
38
|
+
})
|
|
39
|
+
}
|
|
14
40
|
interface _TextProps extends TextProps {
|
|
15
41
|
style?: TextStyle
|
|
16
42
|
children?: ReactNode
|
|
@@ -21,6 +47,7 @@ interface _TextProps extends TextProps {
|
|
|
21
47
|
'parent-font-size'?: number
|
|
22
48
|
'parent-width'?: number
|
|
23
49
|
'parent-height'?: number
|
|
50
|
+
decode?: boolean
|
|
24
51
|
}
|
|
25
52
|
|
|
26
53
|
const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
|
|
@@ -33,7 +60,8 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
|
|
|
33
60
|
'user-select': userSelect,
|
|
34
61
|
'parent-font-size': parentFontSize,
|
|
35
62
|
'parent-width': parentWidth,
|
|
36
|
-
'parent-height': parentHeight
|
|
63
|
+
'parent-height': parentHeight,
|
|
64
|
+
decode
|
|
37
65
|
} = props
|
|
38
66
|
|
|
39
67
|
const {
|
|
@@ -66,12 +94,17 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
|
|
|
66
94
|
}
|
|
67
95
|
),
|
|
68
96
|
[
|
|
69
|
-
'user-select'
|
|
97
|
+
'user-select',
|
|
98
|
+
'decode'
|
|
70
99
|
]
|
|
71
100
|
)
|
|
72
101
|
|
|
102
|
+
const children = decode ? getDecodedChildren(props.children) : props.children
|
|
103
|
+
|
|
73
104
|
let finalComponent:JSX.Element = createElement(Text, innerProps, wrapChildren(
|
|
74
|
-
props,
|
|
105
|
+
extendObject({}, props, {
|
|
106
|
+
children
|
|
107
|
+
}),
|
|
75
108
|
{
|
|
76
109
|
hasVarDec,
|
|
77
110
|
varContext: varContextRef.current
|
|
@@ -127,8 +127,16 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
127
127
|
style: defaultWebViewStyle
|
|
128
128
|
})
|
|
129
129
|
|
|
130
|
+
const getHostFromUrl = function (url: string): string {
|
|
131
|
+
if (!url) return ''
|
|
132
|
+
// 匹配协议://主机名(:端口) 的模式
|
|
133
|
+
const regex = /^(?:https?|ftp):\/\/([^/?:#]+)(?::(\d+))?/i
|
|
134
|
+
const match = url.match(regex)
|
|
135
|
+
return match ? match[1] : ''
|
|
136
|
+
}
|
|
137
|
+
|
|
130
138
|
const hostValidate = (url: string) => {
|
|
131
|
-
const host = url &&
|
|
139
|
+
const host = url && getHostFromUrl(url)
|
|
132
140
|
const hostWhitelists = mpx.config.rnConfig?.webviewConfig?.hostWhitelists || []
|
|
133
141
|
if (hostWhitelists.length) {
|
|
134
142
|
return hostWhitelists.some((item: string) => {
|
|
@@ -343,8 +351,9 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
343
351
|
<View style={styles.loadErrorButton} onTouchEnd={_reload}><Text style={{ fontSize: 12, color: '#666666' }}>{currentErrorText.button}</Text></View>
|
|
344
352
|
</View>
|
|
345
353
|
)
|
|
346
|
-
: (
|
|
347
|
-
|
|
354
|
+
: (
|
|
355
|
+
<WebView
|
|
356
|
+
containerStyle={ defaultWebViewStyle }
|
|
348
357
|
source={{ uri: src }}
|
|
349
358
|
ref={webViewRef}
|
|
350
359
|
javaScriptEnabled={true}
|
|
@@ -356,7 +365,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
356
365
|
onHttpError={onHttpError}
|
|
357
366
|
onError={onError}
|
|
358
367
|
allowsBackForwardNavigationGestures={true}
|
|
359
|
-
|
|
368
|
+
></WebView>)}
|
|
360
369
|
</Portal>
|
|
361
370
|
)
|
|
362
371
|
})
|
|
@@ -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
|
+
}
|
|
@@ -215,24 +215,33 @@ function resolveVar (input: string, varContext: Record<string, any>) {
|
|
|
215
215
|
const parsed = parseFunc(input, 'var')
|
|
216
216
|
const replaced = new ReplaceSource(input)
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
for (const { start, end, args } of parsed) {
|
|
219
219
|
const varName = args[0]
|
|
220
|
-
const fallback = args[1]
|
|
220
|
+
const fallback = args[1]
|
|
221
221
|
let varValue = hasOwn(varContext, varName) ? varContext[varName] : fallback
|
|
222
|
+
if (varValue === undefined) return
|
|
222
223
|
if (varUseRegExp.test(varValue)) {
|
|
223
|
-
varValue =
|
|
224
|
+
varValue = resolveVar(varValue, varContext)
|
|
225
|
+
if (varValue === undefined) return
|
|
224
226
|
} else {
|
|
225
|
-
varValue =
|
|
227
|
+
varValue = global.__formatValue(varValue)
|
|
226
228
|
}
|
|
227
229
|
replaced.replace(start, end - 1, varValue)
|
|
228
|
-
}
|
|
230
|
+
}
|
|
231
|
+
|
|
229
232
|
return global.__formatValue(replaced.source())
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
function transformVar (styleObj: Record<string, any>, varKeyPaths: Array<Array<string>>, varContext: Record<string, any>, visitOther: (arg: VisitorArg) => void) {
|
|
233
236
|
varKeyPaths.forEach((varKeyPath) => {
|
|
234
237
|
setStyle(styleObj, varKeyPath, ({ target, key, value }) => {
|
|
235
|
-
|
|
238
|
+
const resolved = resolveVar(value, varContext)
|
|
239
|
+
if (resolved === undefined) {
|
|
240
|
+
delete target[key]
|
|
241
|
+
error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`)
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
target[key] = resolved
|
|
236
245
|
visitOther({ target, key, value: target[key], keyPath: varKeyPath })
|
|
237
246
|
})
|
|
238
247
|
})
|
|
@@ -98,7 +98,7 @@ function compileScriptSetup (
|
|
|
98
98
|
) {
|
|
99
99
|
if (node) {
|
|
100
100
|
throw new Error(
|
|
101
|
-
`[
|
|
101
|
+
`[Mpx script error]: ${msg}\n\n${filePath}\n${formatCodeFrame(
|
|
102
102
|
content,
|
|
103
103
|
node.start + startOffset,
|
|
104
104
|
end
|
|
@@ -106,7 +106,7 @@ function compileScriptSetup (
|
|
|
106
106
|
)
|
|
107
107
|
} else {
|
|
108
108
|
throw new Error(
|
|
109
|
-
`[
|
|
109
|
+
`[Mpx script error]: ${msg}\n\n${filePath}\n`
|
|
110
110
|
)
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -18,7 +18,8 @@ module.exports = function (css, map) {
|
|
|
18
18
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
19
19
|
const mpx = this.getMpx()
|
|
20
20
|
const mpxStyleOptions = (queryObj.mpxStyleOptions && JSON.parse(queryObj.mpxStyleOptions)) || {}
|
|
21
|
-
const id = queryObj.moduleId || mpxStyleOptions.mid || mpx.getModuleId(resourcePath)
|
|
21
|
+
const id = queryObj.moduleId || mpxStyleOptions.mid || mpx.getModuleId(resourcePath, false, (queryObj.moduleId || mpxStyleOptions.mid) ? null : this)
|
|
22
|
+
|
|
22
23
|
const appInfo = mpx.appInfo
|
|
23
24
|
const defs = mpx.defs
|
|
24
25
|
const mode = mpx.mode
|
|
@@ -55,7 +56,7 @@ module.exports = function (css, map) {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
if (isReact(mode)) {
|
|
58
|
-
plugins.push(transSpecial({ id }))
|
|
59
|
+
plugins.push(transSpecial({ id, transPage: true }))
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
// plugins.push(pluginCondStrip({
|
|
@@ -29,7 +29,7 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
|
|
|
29
29
|
if (err.message.indexOf('No PostCSS Config found') >= 0) {
|
|
30
30
|
return
|
|
31
31
|
}
|
|
32
|
-
loaderContext.emitWarning(`Error loading PostCSS config: ${err.message}`)
|
|
32
|
+
loaderContext.emitWarning(`[Mpx style warning]: Error loading PostCSS config: ${err.message}`)
|
|
33
33
|
})
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const selectorParser = require('postcss-selector-parser')
|
|
2
|
+
const { MPX_TAG_PAGE_SELECTOR } = require('../../utils/const')
|
|
2
3
|
// trans-special
|
|
3
4
|
|
|
4
|
-
module.exports = ({ id }) => {
|
|
5
|
+
module.exports = ({ id, transPage = false }) => {
|
|
5
6
|
return {
|
|
6
7
|
postcssPlugin: 'trans-special',
|
|
7
8
|
Once: (root) => {
|
|
@@ -13,7 +14,14 @@ module.exports = ({ id }) => {
|
|
|
13
14
|
if (/^:host$/.test(n.value)) {
|
|
14
15
|
const compoundSelectors = n.nodes
|
|
15
16
|
n.replaceWith(selectorParser.className({
|
|
16
|
-
value:
|
|
17
|
+
value: `host-${id}`
|
|
18
|
+
}))
|
|
19
|
+
selector.insertAfter(n, compoundSelectors)
|
|
20
|
+
}
|
|
21
|
+
if (transPage && /^page$/.test(n.value)) {
|
|
22
|
+
const compoundSelectors = n.nodes || []
|
|
23
|
+
n.replaceWith(selectorParser.className({
|
|
24
|
+
value: MPX_TAG_PAGE_SELECTOR
|
|
17
25
|
}))
|
|
18
26
|
selector.insertAfter(n, compoundSelectors)
|
|
19
27
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
const fs = require('fs/promises')
|
|
2
|
+
const parseRequest = require('../utils/parse-request')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const loaderUtils = require('loader-utils')
|
|
5
|
+
|
|
1
6
|
class Node {
|
|
2
|
-
constructor
|
|
7
|
+
constructor(type, condition = null) {
|
|
3
8
|
this.type = type // 'If', 'ElseIf', 'Else' 或 'Text'
|
|
4
9
|
this.condition = condition // If 或 Elif 的条件
|
|
5
10
|
this.children = []
|
|
@@ -8,7 +13,7 @@ class Node {
|
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
// 提取 css string 为 token
|
|
11
|
-
function tokenize
|
|
16
|
+
function tokenize(cssString) {
|
|
12
17
|
const regex = /\/\*\s*@mpx-(if|elif|else|endif)(?:\s*\((.*?)\))?\s*\*\//g
|
|
13
18
|
const tokens = []
|
|
14
19
|
let lastIndex = 0
|
|
@@ -37,7 +42,7 @@ function tokenize (cssString) {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
// parse:将生成的 token 数组构造成嵌套的 AST
|
|
40
|
-
function parse
|
|
45
|
+
function parse(cssString) {
|
|
41
46
|
const tokens = tokenize(cssString)
|
|
42
47
|
const ast = []
|
|
43
48
|
const nodeStack = []
|
|
@@ -54,7 +59,7 @@ function parse (cssString) {
|
|
|
54
59
|
currentChildren = node.children
|
|
55
60
|
} else if (token.type === 'elif') {
|
|
56
61
|
if (nodeStack.length === 0) {
|
|
57
|
-
throw new Error('elif without a preceding if')
|
|
62
|
+
throw new Error('[Mpx style error]: elif without a preceding if')
|
|
58
63
|
}
|
|
59
64
|
currentChildren = nodeStack[nodeStack.length - 1]
|
|
60
65
|
const node = new Node('ElseIf', token.condition)
|
|
@@ -62,7 +67,7 @@ function parse (cssString) {
|
|
|
62
67
|
currentChildren = node.children
|
|
63
68
|
} else if (token.type === 'else') {
|
|
64
69
|
if (nodeStack.length === 0) {
|
|
65
|
-
throw new Error('else without a preceding if')
|
|
70
|
+
throw new Error('[Mpx style error]: else without a preceding if')
|
|
66
71
|
}
|
|
67
72
|
currentChildren = nodeStack[nodeStack.length - 1]
|
|
68
73
|
const node = new Node('Else')
|
|
@@ -77,7 +82,7 @@ function parse (cssString) {
|
|
|
77
82
|
return ast
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
function evaluateCondition
|
|
85
|
+
function evaluateCondition(condition, defs) {
|
|
81
86
|
try {
|
|
82
87
|
const keys = Object.keys(defs)
|
|
83
88
|
const values = keys.map(key => defs[key])
|
|
@@ -85,15 +90,15 @@ function evaluateCondition (condition, defs) {
|
|
|
85
90
|
const func = new Function(...keys, `return (${condition});`)
|
|
86
91
|
return func(...values)
|
|
87
92
|
} catch (e) {
|
|
88
|
-
console.error(`Error evaluating condition: ${condition}`, e)
|
|
93
|
+
console.error(`[Mpx style error]:Error evaluating condition: ${condition}`, e)
|
|
89
94
|
return false
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
function traverseAndEvaluate
|
|
98
|
+
function traverseAndEvaluate(ast, defs) {
|
|
94
99
|
let output = ''
|
|
95
100
|
let batchedIf = false
|
|
96
|
-
function traverse
|
|
101
|
+
function traverse(nodes) {
|
|
97
102
|
for (const node of nodes) {
|
|
98
103
|
if (node.type === 'Text') {
|
|
99
104
|
output += node.value
|
|
@@ -118,10 +123,220 @@ function traverseAndEvaluate (ast, defs) {
|
|
|
118
123
|
return output
|
|
119
124
|
}
|
|
120
125
|
|
|
121
|
-
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @param {string} content
|
|
129
|
+
* @param {Record<string, any>} defs
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
function stripCondition(content, defs) {
|
|
133
|
+
const ast = parse(content)
|
|
134
|
+
const result = traverseAndEvaluate(ast, defs)
|
|
135
|
+
return result
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @typedef {Object} StripByPostcssOption
|
|
140
|
+
* @property {string} lang 样式语法格式
|
|
141
|
+
* @property {string} resourcePath 文件路径
|
|
142
|
+
* @property {string} css 源文件
|
|
143
|
+
* @property {Record<string, any>} defs 条件定义
|
|
144
|
+
* @property {import('webpack').LoaderContext<any>['resolve']} resolve webpack resolve 方法
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @typedef {Object} AtImportConfig
|
|
149
|
+
* @property {string} from 当前文件路径
|
|
150
|
+
* @property {(filename: string) => Promise<string> | string;} load 加载文件内容的函数
|
|
151
|
+
* @property {(id: string, base: string) => Promise<string | null> | string | null;} resolve 解析文件路径的函数
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
async function atImport(options) {
|
|
155
|
+
let { css, load, resolve, from } = options
|
|
156
|
+
const fromParent = path.dirname(from)
|
|
157
|
+
const e1 = /\/\*[\s\S]*?\*\//g
|
|
158
|
+
// 匹配 // 单行注释,可能匹配到静态资源中的 http:// 的 //,不过影响不大, @import 不太可能出现在静态资源链接中
|
|
159
|
+
const e2 = /\/\/.*/g
|
|
160
|
+
// 使用正则匹配匹配出 多行注释和单行注释
|
|
161
|
+
const comments = []
|
|
162
|
+
let comment
|
|
163
|
+
while ((comment = e1.exec(css))) {
|
|
164
|
+
const [content] = comment
|
|
165
|
+
comments.push({
|
|
166
|
+
start: comment.index,
|
|
167
|
+
end: comment.index + content.length,
|
|
168
|
+
content: content
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
while ((comment = e2.exec(css))) {
|
|
173
|
+
const [content] = comment
|
|
174
|
+
comments.push({
|
|
175
|
+
start: comment.index,
|
|
176
|
+
end: comment.index + content.length,
|
|
177
|
+
content: content
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 排序方便二分
|
|
182
|
+
comments.sort((a, b) => (a.start > b.start ? 1 : -1))
|
|
183
|
+
|
|
184
|
+
function isInComments(index) {
|
|
185
|
+
let left = 0
|
|
186
|
+
let right = comments.length - 1
|
|
187
|
+
|
|
188
|
+
while (left <= right) {
|
|
189
|
+
const mid = Math.floor((left + right) / 2)
|
|
190
|
+
const comment = comments[mid]
|
|
191
|
+
|
|
192
|
+
if (index >= comment.start && index <= comment.end) {
|
|
193
|
+
return true
|
|
194
|
+
} else if (index < comment.start) {
|
|
195
|
+
right = mid - 1
|
|
196
|
+
} else {
|
|
197
|
+
left = mid + 1
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return false
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 使用正则表达式匹配出所有 @import 语法,语法包含 @import "path", @import 'path', @import url("path"), @import url('path')
|
|
205
|
+
// 注意清理分号,否则留个分号会报错
|
|
206
|
+
const importRegex = /@import\s+(url\(['"]([^'"]+)['"]\)|['"]([^'"]+)['"])(\s*;)?/g
|
|
207
|
+
let importList = []
|
|
208
|
+
let importMatch
|
|
209
|
+
while ((importMatch = importRegex.exec(css))) {
|
|
210
|
+
const fullMatch = importMatch[0]
|
|
211
|
+
const importSyntax = fullMatch.trim()
|
|
212
|
+
importSyntax.startsWith('@import')
|
|
213
|
+
const importValue = importSyntax.slice(7).trim()
|
|
214
|
+
// 匹配 @import 后字符串格式
|
|
215
|
+
const importUrlRegex = /url\s*\(['"]([^'"]+)['"]\)/g
|
|
216
|
+
const importStrRegexp = /^(['"])([^'"]+)\1/
|
|
217
|
+
|
|
218
|
+
let urlMatch = null
|
|
219
|
+
if (importValue.startsWith('url')) {
|
|
220
|
+
urlMatch = importUrlRegex.exec(importValue)?.[1]
|
|
221
|
+
} else {
|
|
222
|
+
urlMatch = importStrRegexp.exec(importValue)?.[2]
|
|
223
|
+
}
|
|
224
|
+
if (!urlMatch) {
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
importList.push({
|
|
229
|
+
start: importMatch.index,
|
|
230
|
+
end: importMatch.index + fullMatch.length,
|
|
231
|
+
content: fullMatch,
|
|
232
|
+
url: urlMatch
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 过滤掉在注释中的 @import 语法
|
|
237
|
+
importList = importList.filter(imp => !isInComments(imp.start))
|
|
238
|
+
|
|
239
|
+
// 逆序替换 import,避免修改内容导致的索引偏移问题
|
|
240
|
+
importList.sort((a, b) => (a.start > b.start ? -1 : 1))
|
|
241
|
+
|
|
242
|
+
for (const imp of importList) {
|
|
243
|
+
const importPath = imp.url
|
|
244
|
+
if (!importPath) continue
|
|
245
|
+
// 非法路径直接报错
|
|
246
|
+
const resolvedUrl = await resolve(importPath, fromParent)
|
|
247
|
+
const content = (await load(resolvedUrl)) ?? ''
|
|
248
|
+
css = css.slice(0, imp.start) + '\n' + content + '\n' + css.slice(imp.end)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return css
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @param {StripByPostcssOption} options
|
|
255
|
+
*/
|
|
256
|
+
async function stripByPostcss(options) {
|
|
257
|
+
const defs = options.defs ?? {}
|
|
258
|
+
|
|
259
|
+
function stripContentCondition(content) {
|
|
260
|
+
content = stripCondition(content, defs)
|
|
261
|
+
|
|
262
|
+
if (options.lang === 'stylus') {
|
|
263
|
+
content = content.replace(/\t/g, ' ')
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return content
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @type {string}
|
|
271
|
+
*/
|
|
272
|
+
const afterConditionStrip = stripContentCondition(options.css, defs)
|
|
273
|
+
|
|
274
|
+
const atImportOptions = {
|
|
275
|
+
async load(filename) {
|
|
276
|
+
let content = await fs.readFile(filename, 'utf-8')
|
|
277
|
+
|
|
278
|
+
content = stripContentCondition(content, defs)
|
|
279
|
+
|
|
280
|
+
return await atImport({
|
|
281
|
+
...atImportOptions,
|
|
282
|
+
from: filename,
|
|
283
|
+
css: content
|
|
284
|
+
})
|
|
285
|
+
},
|
|
286
|
+
resolve: (id, base) => {
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
// 处理 ~ 开头的路径
|
|
289
|
+
options.resolve(base, id.startsWith('~') && !id.startsWith('~/') ? loaderUtils.urlToRequest(id) : id, (err, res) => {
|
|
290
|
+
if (err) return reject(err)
|
|
291
|
+
if (typeof res !== 'string') {
|
|
292
|
+
return reject(new Error(`[mpx-strip-conditional-loader]: Cannot resolve ${id} from ${base}`))
|
|
293
|
+
}
|
|
294
|
+
resolve(res)
|
|
295
|
+
})
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
css: await atImport({
|
|
302
|
+
...atImportOptions,
|
|
303
|
+
from: options.resourcePath,
|
|
304
|
+
css: afterConditionStrip
|
|
305
|
+
})
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const createResolver = (contetx, extensions) =>
|
|
310
|
+
contetx.getResolve({ mainFiles: ['index'], extensions: [...extensions, '.css'], preferRelative: true })
|
|
311
|
+
const resolver = {
|
|
312
|
+
stylus: contetx => createResolver(contetx, ['.styl']),
|
|
313
|
+
scss: contetx => createResolver(contetx, ['.scss']),
|
|
314
|
+
less: contetx => createResolver(contetx, ['.styl'])
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
*
|
|
319
|
+
* @this {import('webpack').LoaderContext<any>}
|
|
320
|
+
* @param {string} css
|
|
321
|
+
*/
|
|
322
|
+
module.exports = async function (css) {
|
|
122
323
|
this.cacheable()
|
|
324
|
+
|
|
325
|
+
const callback = this.async()
|
|
326
|
+
|
|
123
327
|
const mpx = this.getMpx()
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
328
|
+
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
329
|
+
|
|
330
|
+
const result = await stripByPostcss({
|
|
331
|
+
lang: queryObj.lang,
|
|
332
|
+
resourcePath,
|
|
333
|
+
css,
|
|
334
|
+
defs: mpx.defs,
|
|
335
|
+
resolve: resolver[queryObj.lang] ? resolver[queryObj.lang](this) : this.resolve.bind(this)
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
callback(null, result.css, result.map)
|
|
127
339
|
}
|
|
340
|
+
|
|
341
|
+
module.exports.stripByPostcss = stripByPostcss
|
|
342
|
+
module.exports.stripCondition = stripCondition
|