@mpxjs/webpack-plugin 2.9.59 → 2.9.64
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/index.js +1 -3
- package/lib/platform/style/wx/index.js +344 -270
- package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
- package/lib/platform/template/wx/component-config/checkbox.js +8 -0
- package/lib/platform/template/wx/component-config/cover-image.js +15 -0
- package/lib/platform/template/wx/component-config/cover-view.js +9 -0
- package/lib/platform/template/wx/component-config/form.js +13 -1
- package/lib/platform/template/wx/component-config/icon.js +8 -0
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/label.js +15 -0
- package/lib/platform/template/wx/component-config/movable-area.js +18 -1
- package/lib/platform/template/wx/component-config/movable-view.js +18 -1
- package/lib/platform/template/wx/component-config/navigator.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view.js +18 -2
- package/lib/platform/template/wx/component-config/picker.js +14 -1
- package/lib/platform/template/wx/component-config/radio-group.js +8 -0
- package/lib/platform/template/wx/component-config/radio.js +8 -0
- package/lib/platform/template/wx/component-config/root-portal.js +15 -0
- package/lib/platform/template/wx/component-config/switch.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -3
- package/lib/react/processScript.js +2 -0
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +12 -7
- package/lib/runtime/components/react/context.ts +40 -0
- package/lib/runtime/components/react/dist/context.js +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
- package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
- package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
- package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
- package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/types/common.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
- package/lib/runtime/components/react/dist/utils.jsx +433 -0
- package/lib/runtime/components/react/getInnerListeners.ts +43 -21
- package/lib/runtime/components/react/mpx-button.tsx +129 -119
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
- package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
- package/lib/runtime/components/react/mpx-form.tsx +117 -0
- package/lib/runtime/components/react/mpx-icon.tsx +106 -0
- package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
- package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
- package/lib/runtime/components/react/mpx-input.tsx +90 -42
- package/lib/runtime/components/react/mpx-label.tsx +110 -0
- package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
- package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
- package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
- package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
- package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
- package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
- package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
- package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
- package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
- package/lib/runtime/components/react/mpx-radio.tsx +230 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
- package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
- package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
- package/lib/runtime/components/react/mpx-switch.tsx +148 -0
- package/lib/runtime/components/react/mpx-text.tsx +53 -77
- package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
- package/lib/runtime/components/react/mpx-view.tsx +576 -195
- package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +12 -0
- package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
- package/lib/runtime/components/react/types/global.d.ts +17 -1
- package/lib/runtime/components/react/useNodesRef.ts +4 -10
- package/lib/runtime/components/react/utils.tsx +505 -0
- package/lib/runtime/optionProcessor.js +19 -17
- package/lib/template-compiler/compiler.js +84 -61
- package/lib/template-compiler/gen-node-react.js +7 -9
- package/lib/web/processStyles.js +2 -5
- package/package.json +8 -3
- package/lib/runtime/components/react/dist/utils.js +0 -80
- package/lib/runtime/components/react/utils.ts +0 -92
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { forwardRef, JSX,
|
|
2
|
-
|
|
3
|
-
import { noop } from '@mpxjs/utils'
|
|
1
|
+
import { forwardRef, JSX, useEffect } from 'react'
|
|
2
|
+
import { noop, warn } from '@mpxjs/utils'
|
|
4
3
|
import { Portal } from '@ant-design/react-native'
|
|
5
4
|
import { getCustomEvent } from './getInnerListeners'
|
|
6
5
|
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
7
|
-
// @ts-ignore
|
|
8
6
|
import { WebView } from 'react-native-webview'
|
|
9
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
10
|
-
import {
|
|
8
|
+
import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent } from 'react-native-webview/lib/WebViewTypes'
|
|
11
9
|
|
|
12
10
|
type OnMessageCallbackEvent = {
|
|
13
11
|
detail: {
|
|
@@ -22,10 +20,11 @@ type CommonCallbackEvent = {
|
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
interface WebViewProps {
|
|
25
|
-
src
|
|
23
|
+
src?: string
|
|
26
24
|
bindmessage?: (event: OnMessageCallbackEvent) => void
|
|
27
25
|
bindload?: (event: CommonCallbackEvent) => void
|
|
28
26
|
binderror?: (event: CommonCallbackEvent) => void
|
|
27
|
+
[x: string]: any
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
interface PayloadData {
|
|
@@ -43,33 +42,28 @@ interface NativeEvent {
|
|
|
43
42
|
data: string
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
interface LoadRes {
|
|
47
|
-
timeStamp: string,
|
|
48
|
-
nativeEvent: NativeEvent
|
|
49
|
-
}
|
|
50
|
-
|
|
51
45
|
interface FormRef {
|
|
52
46
|
postMessage: (value: any) => void;
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element => {
|
|
56
50
|
const { src, bindmessage = noop, bindload = noop, binderror = noop } = props
|
|
51
|
+
if (props.style) {
|
|
52
|
+
warn('The web-view component does not support the style prop.')
|
|
53
|
+
}
|
|
54
|
+
const defaultWebViewStyle = {
|
|
55
|
+
position: 'absolute' as 'absolute' | 'relative' | 'static',
|
|
56
|
+
left: 0 as number,
|
|
57
|
+
right: 0 as number,
|
|
58
|
+
top: 0 as number,
|
|
59
|
+
bottom: 0 as number
|
|
60
|
+
}
|
|
57
61
|
|
|
58
|
-
const defaultWebViewStyle = [
|
|
59
|
-
{
|
|
60
|
-
position: 'absolute',
|
|
61
|
-
left: 0,
|
|
62
|
-
right: 0,
|
|
63
|
-
top: 0,
|
|
64
|
-
bottom: 0
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
62
|
const { nodeRef: webViewRef } = useNodesRef<WebView, WebViewProps>(props, ref, {
|
|
68
|
-
defaultStyle:
|
|
69
|
-
...defaultWebViewStyle
|
|
70
|
-
])
|
|
63
|
+
defaultStyle: defaultWebViewStyle
|
|
71
64
|
})
|
|
72
|
-
|
|
65
|
+
|
|
66
|
+
const _messageList: any[] = []
|
|
73
67
|
const handleUnload = () => {
|
|
74
68
|
// 这里是 WebView 销毁前执行的逻辑
|
|
75
69
|
bindmessage(getCustomEvent('messsage', {}, {
|
|
@@ -86,7 +80,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
86
80
|
handleUnload()
|
|
87
81
|
}
|
|
88
82
|
}, [])
|
|
89
|
-
const _load = function(res:
|
|
83
|
+
const _load = function (res: WebViewNavigationEvent) {
|
|
90
84
|
const result = {
|
|
91
85
|
type: 'load',
|
|
92
86
|
timeStamp: res.timeStamp,
|
|
@@ -96,7 +90,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
96
90
|
}
|
|
97
91
|
bindload(result)
|
|
98
92
|
}
|
|
99
|
-
const _error = function(res:
|
|
93
|
+
const _error = function (res: WebViewErrorEvent) {
|
|
100
94
|
const result = {
|
|
101
95
|
type: 'error',
|
|
102
96
|
timeStamp: res.timeStamp,
|
|
@@ -106,17 +100,19 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
106
100
|
}
|
|
107
101
|
binderror(result)
|
|
108
102
|
}
|
|
109
|
-
const _message = function(res:
|
|
110
|
-
let data: MessageData
|
|
103
|
+
const _message = function (res: WebViewMessageEvent) {
|
|
104
|
+
let data: MessageData = {}
|
|
111
105
|
let asyncCallback
|
|
112
106
|
const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
|
|
113
107
|
try {
|
|
114
108
|
const nativeEventData = res.nativeEvent?.data
|
|
115
|
-
|
|
109
|
+
if (typeof nativeEventData === 'string') {
|
|
110
|
+
data = JSON.parse(nativeEventData)
|
|
111
|
+
}
|
|
116
112
|
} catch (e) {
|
|
117
113
|
data = {}
|
|
118
114
|
}
|
|
119
|
-
const postData:PayloadData = data.payload || {}
|
|
115
|
+
const postData: PayloadData = data.payload || {}
|
|
120
116
|
switch (data.type) {
|
|
121
117
|
case 'postMessage':
|
|
122
118
|
_messageList.push(postData.data)
|
|
@@ -152,16 +148,15 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
152
148
|
}
|
|
153
149
|
})
|
|
154
150
|
}
|
|
155
|
-
|
|
156
|
-
return(<Portal>
|
|
151
|
+
return (<Portal>
|
|
157
152
|
<WebView
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
153
|
+
style={defaultWebViewStyle}
|
|
154
|
+
source={{ uri: src }}
|
|
155
|
+
ref={webViewRef}
|
|
156
|
+
onLoad={_load}
|
|
157
|
+
onError={_error}
|
|
158
|
+
onMessage={_message}
|
|
159
|
+
javaScriptEnabled={true}
|
|
165
160
|
></WebView>
|
|
166
161
|
</Portal>)
|
|
167
162
|
})
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
interface Token {
|
|
2
|
+
type: string
|
|
3
|
+
value: string | number
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
interface ExpressionNode {
|
|
7
|
+
type: 'NUMBER'
|
|
8
|
+
value: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ExpressionParser {
|
|
12
|
+
private tokens: Token[]
|
|
13
|
+
private formatter: (val: string) => number
|
|
14
|
+
private functions: { [key: string]: (...args: number[]) => number }
|
|
15
|
+
private current: number
|
|
16
|
+
|
|
17
|
+
constructor (input: string, formatter: (val: string) => number = val => parseFloat(val), functions: { [key: string]: (...args: number[]) => number } = {}) {
|
|
18
|
+
this.tokens = this.tokenize(input)
|
|
19
|
+
this.formatter = formatter
|
|
20
|
+
this.functions = functions
|
|
21
|
+
this.current = 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
tokenize (input: string): Token[] {
|
|
25
|
+
const tokens: Token[] = []
|
|
26
|
+
const regex = /(\d+\.?\d*(?:px|rpx|%|vw|vh)?|[+\-*/(),]|\b[a-zA-Z_][a-zA-Z0-9_]*\b)/g
|
|
27
|
+
let match: RegExpExecArray | null
|
|
28
|
+
while ((match = regex.exec(input))) {
|
|
29
|
+
if (/^\d+\.?\d*(?:px|rpx|%|vw|vh)?$/.test(match[0])) {
|
|
30
|
+
const lastToken = tokens[tokens.length - 1]
|
|
31
|
+
const last2Token = tokens[tokens.length - 2]
|
|
32
|
+
if (lastToken?.type === '-' && (!last2Token || /^[+\-*/(,]$/.test(last2Token?.type))) {
|
|
33
|
+
tokens.pop()
|
|
34
|
+
tokens.push({
|
|
35
|
+
type: 'NUMBER',
|
|
36
|
+
value: '-' + match[0]
|
|
37
|
+
})
|
|
38
|
+
} else {
|
|
39
|
+
tokens.push({
|
|
40
|
+
type: 'NUMBER',
|
|
41
|
+
value: match[0]
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
tokens.push({
|
|
46
|
+
type: match[0],
|
|
47
|
+
value: match[0]
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return tokens
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
parse (): ExpressionNode {
|
|
55
|
+
return this.expression()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private expression (): ExpressionNode {
|
|
59
|
+
let node = this.term()
|
|
60
|
+
while (this.current < this.tokens.length &&
|
|
61
|
+
(this.tokens[this.current].type === '+' || this.tokens[this.current].type === '-')) {
|
|
62
|
+
const operator = this.tokens[this.current].type
|
|
63
|
+
this.current++
|
|
64
|
+
const right = this.term()
|
|
65
|
+
node = this.applyOperator(operator, node, right)
|
|
66
|
+
}
|
|
67
|
+
return node
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private term (): ExpressionNode {
|
|
71
|
+
let node = this.factor()
|
|
72
|
+
while (this.current < this.tokens.length &&
|
|
73
|
+
(this.tokens[this.current].type === '*' || this.tokens[this.current].type === '/')) {
|
|
74
|
+
const operator = this.tokens[this.current].type
|
|
75
|
+
this.current++
|
|
76
|
+
const right = this.factor()
|
|
77
|
+
node = this.applyOperator(operator, node, right)
|
|
78
|
+
}
|
|
79
|
+
return node
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private factor (): ExpressionNode {
|
|
83
|
+
const token = this.tokens[this.current]
|
|
84
|
+
if (token.type === 'NUMBER') {
|
|
85
|
+
this.current++
|
|
86
|
+
const numericValue = this.formatter(token.value as string)
|
|
87
|
+
return { type: 'NUMBER', value: numericValue }
|
|
88
|
+
} else if (token.type === '(') {
|
|
89
|
+
this.current++
|
|
90
|
+
const node = this.expression()
|
|
91
|
+
if (this.tokens[this.current].type !== ')') {
|
|
92
|
+
throw new Error('Expected closing parenthesis')
|
|
93
|
+
}
|
|
94
|
+
this.current++
|
|
95
|
+
return node
|
|
96
|
+
} else if (this.functions[token.type]) {
|
|
97
|
+
this.current++
|
|
98
|
+
if (this.tokens[this.current].type !== '(') {
|
|
99
|
+
throw new Error('Expected opening parenthesis after function')
|
|
100
|
+
}
|
|
101
|
+
this.current++
|
|
102
|
+
const args = this.parseArguments()
|
|
103
|
+
if (this.tokens[this.current].type !== ')') {
|
|
104
|
+
throw new Error('Expected closing parenthesis')
|
|
105
|
+
}
|
|
106
|
+
this.current++
|
|
107
|
+
return this.applyFunction(token.type, args)
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Unexpected token: ${token.type}`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private parseArguments (): ExpressionNode[] {
|
|
113
|
+
const args: ExpressionNode[] = []
|
|
114
|
+
while (this.current < this.tokens.length && this.tokens[this.current].type !== ')') {
|
|
115
|
+
args.push(this.expression())
|
|
116
|
+
if (this.tokens[this.current].type === ',') {
|
|
117
|
+
this.current++
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return args
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private applyOperator (operator: string, left: ExpressionNode, right: ExpressionNode): ExpressionNode {
|
|
124
|
+
const leftVal = left.value
|
|
125
|
+
const rightVal = right.value
|
|
126
|
+
let result: number
|
|
127
|
+
switch (operator) {
|
|
128
|
+
case '+': result = leftVal + rightVal; break
|
|
129
|
+
case '-': result = leftVal - rightVal; break
|
|
130
|
+
case '*': result = leftVal * rightVal; break
|
|
131
|
+
case '/': result = leftVal / rightVal; break
|
|
132
|
+
default: throw new Error(`Unknown operator: ${operator}`)
|
|
133
|
+
}
|
|
134
|
+
return { type: 'NUMBER', value: result }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private applyFunction (func: string, args: ExpressionNode[]): ExpressionNode {
|
|
138
|
+
if (args.some(arg => arg.type !== 'NUMBER')) {
|
|
139
|
+
throw new Error('Function arguments must be numbers')
|
|
140
|
+
}
|
|
141
|
+
const numericArgs = args.map(arg => arg.value)
|
|
142
|
+
if (this.functions[func]) {
|
|
143
|
+
return { type: 'NUMBER', value: this.functions[func].apply(null, numericArgs) }
|
|
144
|
+
} else {
|
|
145
|
+
throw new Error(`Unknown function: ${func}`)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface FuncInfo {
|
|
151
|
+
start: number
|
|
152
|
+
end: number
|
|
153
|
+
args: string[]
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function parseFunc (str: string, funcName: string): FuncInfo[] {
|
|
157
|
+
const regex = new RegExp(`${funcName}\\(`, 'g')
|
|
158
|
+
const result: FuncInfo[] = []
|
|
159
|
+
let match: RegExpExecArray | null
|
|
160
|
+
|
|
161
|
+
while ((match = regex.exec(str)) !== null) {
|
|
162
|
+
const start = match.index
|
|
163
|
+
let i = start + funcName.length + 1
|
|
164
|
+
let depth = 1
|
|
165
|
+
const args: string[] = []
|
|
166
|
+
let arg = ''
|
|
167
|
+
|
|
168
|
+
while (depth && i < str.length) {
|
|
169
|
+
if (depth === 1 && (str[i] === ',' || str[i] === ')')) {
|
|
170
|
+
args.push(arg.trim())
|
|
171
|
+
arg = ''
|
|
172
|
+
} else {
|
|
173
|
+
arg += str[i]
|
|
174
|
+
}
|
|
175
|
+
switch (str[i]) {
|
|
176
|
+
case '(':
|
|
177
|
+
depth++
|
|
178
|
+
break
|
|
179
|
+
case ')':
|
|
180
|
+
depth--
|
|
181
|
+
break
|
|
182
|
+
default:
|
|
183
|
+
// Do nothing
|
|
184
|
+
}
|
|
185
|
+
i++
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const end = regex.lastIndex = i
|
|
189
|
+
result.push({
|
|
190
|
+
start,
|
|
191
|
+
end,
|
|
192
|
+
args
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return result
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface Replacement {
|
|
200
|
+
start: number
|
|
201
|
+
end: number
|
|
202
|
+
content: string
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export class ReplaceSource {
|
|
206
|
+
private _source: string
|
|
207
|
+
private _replacements: Replacement[]
|
|
208
|
+
|
|
209
|
+
constructor (source: string) {
|
|
210
|
+
this._source = source
|
|
211
|
+
this._replacements = []
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
replace (start: number, end: number, content: string): void {
|
|
215
|
+
this._replacements.push({ start, end, content })
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
source (): string {
|
|
219
|
+
if (this._replacements.length === 0) {
|
|
220
|
+
return this._source
|
|
221
|
+
}
|
|
222
|
+
let current = this._source
|
|
223
|
+
let pos = 0
|
|
224
|
+
const result: string[] = []
|
|
225
|
+
|
|
226
|
+
for (const replacement of this._replacements) {
|
|
227
|
+
const start = Math.floor(replacement.start)
|
|
228
|
+
const end = Math.floor(replacement.end) + 1
|
|
229
|
+
if (pos < start) {
|
|
230
|
+
const offset = start - pos
|
|
231
|
+
result.push(current.slice(0, offset))
|
|
232
|
+
current = current.slice(offset)
|
|
233
|
+
pos = start
|
|
234
|
+
}
|
|
235
|
+
result.push(replacement.content)
|
|
236
|
+
if (pos < end) {
|
|
237
|
+
const offset = end - pos
|
|
238
|
+
current = current.slice(offset)
|
|
239
|
+
pos = end
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
result.push(current)
|
|
243
|
+
return result.join('')
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ViewStyle, ImageResizeMode } from 'react-native'
|
|
2
|
+
|
|
3
|
+
type NumberVal = number | `${number}%`
|
|
4
|
+
type backgroundPositionList = [ 'left'| 'right', NumberVal, 'top' | 'bottom', NumberVal ] | []
|
|
5
|
+
|
|
6
|
+
export type ExtendedViewStyle = ViewStyle & {
|
|
7
|
+
backgroundImage?: string
|
|
8
|
+
backgroundSize?: Array<NumberVal | 'auto' | 'contain' | 'cover'>
|
|
9
|
+
borderRadius?: string | number
|
|
10
|
+
backgroundPosition?: backgroundPositionList
|
|
11
|
+
[key: string]: any
|
|
12
|
+
}
|
|
@@ -12,4 +12,20 @@ declare module 'react-native-svg/css' {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const WithLocalSvg: React.ComponentType<WithLocalSvgProps>
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module '@mpxjs/utils' {
|
|
18
|
+
export function isEmptyObject (obj: Object): boolean
|
|
19
|
+
export function hasOwn (obj: Object, key: string): boolean
|
|
20
|
+
export function noop (...arg: any): void
|
|
21
|
+
export function diffAndCloneA<A, B> (a: A, b?: B): {
|
|
22
|
+
clone: A
|
|
23
|
+
diff: boolean
|
|
24
|
+
diffData: Object | null
|
|
25
|
+
}
|
|
26
|
+
export function isObject (value): value is Object
|
|
27
|
+
export function error (msg: string, location?: string, e?: any): void
|
|
28
|
+
export function warn (msg: string, location?: string, e?: any): void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare let global: Record<string, any>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { useRef,
|
|
2
|
-
|
|
1
|
+
import { useRef, useImperativeHandle, RefObject, ForwardedRef } from 'react'
|
|
3
2
|
|
|
4
3
|
type Obj = Record<string, any>
|
|
5
4
|
|
|
@@ -11,16 +10,11 @@ export type HandlerRef<T, P> = {
|
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
export default function useNodesRef<T, P>(props: P, ref: ForwardedRef<HandlerRef<T, P>>, instance:Obj = {}
|
|
13
|
+
export default function useNodesRef<T, P> (props: P, ref: ForwardedRef<HandlerRef<T, P>>, instance:Obj = {}) {
|
|
15
14
|
const nodeRef = useRef<T>(null)
|
|
16
|
-
const _props = useRef<P | null>(
|
|
15
|
+
const _props = useRef<P | null>(null)
|
|
16
|
+
_props.current = props
|
|
17
17
|
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
_props.current = props
|
|
20
|
-
return () => {
|
|
21
|
-
_props.current = null // 组件销毁,清空 _props 依赖数据
|
|
22
|
-
}
|
|
23
|
-
}, [props])
|
|
24
18
|
useImperativeHandle(ref, () => {
|
|
25
19
|
return {
|
|
26
20
|
getNodeInstance () {
|