@mpxjs/webpack-plugin 2.9.62 → 2.9.65
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/config.js +38 -10
- package/lib/index.js +1 -3
- package/lib/platform/style/wx/index.js +115 -66
- package/lib/platform/template/wx/index.js +12 -8
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +9 -7
- package/lib/runtime/components/react/context.ts +9 -7
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
- package/lib/runtime/components/react/dist/mpx-button.jsx +53 -74
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +20 -18
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -42
- package/lib/runtime/components/react/dist/mpx-form.jsx +18 -15
- package/lib/runtime/components/react/dist/mpx-icon.jsx +15 -17
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +36 -34
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +36 -31
- package/lib/runtime/components/react/dist/mpx-label.jsx +30 -37
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +15 -19
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +10 -9
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +9 -5
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +13 -8
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +22 -20
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +103 -10
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +149 -54
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +20 -18
- package/lib/runtime/components/react/dist/mpx-radio.jsx +29 -43
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +36 -27
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +141 -75
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +16 -7
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +20 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +18 -14
- package/lib/runtime/components/react/dist/mpx-text.jsx +20 -35
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +296 -210
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -7
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +1 -5
- package/lib/runtime/components/react/dist/utils.jsx +445 -0
- package/lib/runtime/components/react/getInnerListeners.ts +18 -8
- package/lib/runtime/components/react/mpx-button.tsx +83 -91
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +50 -43
- package/lib/runtime/components/react/mpx-checkbox.tsx +56 -64
- package/lib/runtime/components/react/mpx-form.tsx +51 -22
- package/lib/runtime/components/react/mpx-icon.tsx +31 -27
- package/lib/runtime/components/react/mpx-image/index.tsx +54 -47
- package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
- package/lib/runtime/components/react/mpx-input.tsx +59 -38
- package/lib/runtime/components/react/mpx-label.tsx +55 -59
- package/lib/runtime/components/react/mpx-movable-area.tsx +40 -25
- package/lib/runtime/components/react/mpx-movable-view.tsx +29 -29
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
- package/lib/runtime/components/react/mpx-picker/date.tsx +4 -4
- package/lib/runtime/components/react/mpx-picker/index.tsx +12 -11
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +17 -13
- package/lib/runtime/components/react/mpx-picker/region.tsx +23 -19
- package/lib/runtime/components/react/mpx-picker/selector.tsx +7 -7
- package/lib/runtime/components/react/mpx-picker/time.tsx +29 -31
- package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +149 -20
- package/lib/runtime/components/react/mpx-picker-view.tsx +180 -63
- package/lib/runtime/components/react/mpx-radio-group.tsx +51 -47
- package/lib/runtime/components/react/mpx-radio.tsx +57 -72
- package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +136 -104
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +175 -96
- package/lib/runtime/components/react/mpx-swiper/index.tsx +21 -9
- package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +48 -14
- package/lib/runtime/components/react/mpx-switch.tsx +46 -24
- package/lib/runtime/components/react/mpx-text.tsx +38 -45
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +401 -241
- package/lib/runtime/components/react/mpx-web-view.tsx +22 -22
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +4 -4
- package/lib/runtime/components/react/types/global.d.ts +24 -2
- package/lib/runtime/components/react/useNodesRef.ts +1 -7
- package/lib/runtime/components/react/utils.tsx +524 -0
- package/lib/runtime/components/web/mpx-scroll-view.vue +25 -5
- package/lib/style-compiler/index.js +5 -4
- package/lib/template-compiler/compiler.js +133 -161
- package/lib/template-compiler/gen-node-react.js +1 -3
- package/lib/utils/const.js +2 -1
- package/lib/web/processStyles.js +2 -1
- package/lib/web/processTemplate.js +2 -3
- package/lib/wxml/loader.js +1 -1
- package/package.json +7 -4
- package/lib/runtime/components/react/dist/utils.js +0 -148
- package/lib/runtime/components/react/utils.ts +0 -170
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { forwardRef, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
import { noop } from '@mpxjs/utils';
|
|
1
|
+
import { forwardRef, useEffect, useRef } 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 from './useNodesRef';
|
|
10
8
|
const _WebView = forwardRef((props, ref) => {
|
|
11
9
|
const { src, bindmessage = noop, bindload = noop, binderror = noop } = props;
|
|
10
|
+
if (props.style) {
|
|
11
|
+
warn('The web-view component does not support the style prop.');
|
|
12
|
+
}
|
|
12
13
|
const defaultWebViewStyle = {
|
|
13
14
|
position: 'absolute',
|
|
14
15
|
left: 0,
|
|
@@ -16,7 +17,8 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
16
17
|
top: 0,
|
|
17
18
|
bottom: 0
|
|
18
19
|
};
|
|
19
|
-
const
|
|
20
|
+
const webViewRef = useRef(null);
|
|
21
|
+
useNodesRef(props, ref, webViewRef, {
|
|
20
22
|
defaultStyle: defaultWebViewStyle
|
|
21
23
|
});
|
|
22
24
|
const _messageList = [];
|
|
@@ -56,12 +58,14 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
56
58
|
binderror(result);
|
|
57
59
|
};
|
|
58
60
|
const _message = function (res) {
|
|
59
|
-
let data;
|
|
61
|
+
let data = {};
|
|
60
62
|
let asyncCallback;
|
|
61
63
|
const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab });
|
|
62
64
|
try {
|
|
63
65
|
const nativeEventData = res.nativeEvent?.data;
|
|
64
|
-
|
|
66
|
+
if (typeof nativeEventData === 'string') {
|
|
67
|
+
data = JSON.parse(nativeEventData);
|
|
68
|
+
}
|
|
65
69
|
}
|
|
66
70
|
catch (e) {
|
|
67
71
|
data = {};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
export class ExpressionParser {
|
|
2
|
+
tokens;
|
|
3
|
+
formatter;
|
|
4
|
+
functions;
|
|
5
|
+
current;
|
|
6
|
+
constructor(input, formatter = val => parseFloat(val), functions = {}) {
|
|
7
|
+
this.tokens = this.tokenize(input);
|
|
8
|
+
this.formatter = formatter;
|
|
9
|
+
this.functions = functions;
|
|
10
|
+
this.current = 0;
|
|
11
|
+
}
|
|
12
|
+
tokenize(input) {
|
|
13
|
+
const tokens = [];
|
|
14
|
+
const regex = /(\d+\.?\d*(?:px|rpx|%|vw|vh)?|[+\-*/(),]|\b[a-zA-Z_][a-zA-Z0-9_]*\b)/g;
|
|
15
|
+
let match;
|
|
16
|
+
while ((match = regex.exec(input))) {
|
|
17
|
+
if (/^\d+\.?\d*(?:px|rpx|%|vw|vh)?$/.test(match[0])) {
|
|
18
|
+
const lastToken = tokens[tokens.length - 1];
|
|
19
|
+
const last2Token = tokens[tokens.length - 2];
|
|
20
|
+
if (lastToken?.type === '-' && (!last2Token || /^[+\-*/(,]$/.test(last2Token?.type))) {
|
|
21
|
+
tokens.pop();
|
|
22
|
+
tokens.push({
|
|
23
|
+
type: 'NUMBER',
|
|
24
|
+
value: '-' + match[0]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
tokens.push({
|
|
29
|
+
type: 'NUMBER',
|
|
30
|
+
value: match[0]
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
tokens.push({
|
|
36
|
+
type: match[0],
|
|
37
|
+
value: match[0]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return tokens;
|
|
42
|
+
}
|
|
43
|
+
parse() {
|
|
44
|
+
return this.expression();
|
|
45
|
+
}
|
|
46
|
+
expression() {
|
|
47
|
+
let node = this.term();
|
|
48
|
+
while (this.current < this.tokens.length &&
|
|
49
|
+
(this.tokens[this.current].type === '+' || this.tokens[this.current].type === '-')) {
|
|
50
|
+
const operator = this.tokens[this.current].type;
|
|
51
|
+
this.current++;
|
|
52
|
+
const right = this.term();
|
|
53
|
+
node = this.applyOperator(operator, node, right);
|
|
54
|
+
}
|
|
55
|
+
return node;
|
|
56
|
+
}
|
|
57
|
+
term() {
|
|
58
|
+
let node = this.factor();
|
|
59
|
+
while (this.current < this.tokens.length &&
|
|
60
|
+
(this.tokens[this.current].type === '*' || this.tokens[this.current].type === '/')) {
|
|
61
|
+
const operator = this.tokens[this.current].type;
|
|
62
|
+
this.current++;
|
|
63
|
+
const right = this.factor();
|
|
64
|
+
node = this.applyOperator(operator, node, right);
|
|
65
|
+
}
|
|
66
|
+
return node;
|
|
67
|
+
}
|
|
68
|
+
factor() {
|
|
69
|
+
const token = this.tokens[this.current];
|
|
70
|
+
if (token.type === 'NUMBER') {
|
|
71
|
+
this.current++;
|
|
72
|
+
const numericValue = this.formatter(token.value);
|
|
73
|
+
return { type: 'NUMBER', value: numericValue };
|
|
74
|
+
}
|
|
75
|
+
else if (token.type === '(') {
|
|
76
|
+
this.current++;
|
|
77
|
+
const node = this.expression();
|
|
78
|
+
if (this.tokens[this.current].type !== ')') {
|
|
79
|
+
throw new Error('Expected closing parenthesis');
|
|
80
|
+
}
|
|
81
|
+
this.current++;
|
|
82
|
+
return node;
|
|
83
|
+
}
|
|
84
|
+
else if (this.functions[token.type]) {
|
|
85
|
+
this.current++;
|
|
86
|
+
if (this.tokens[this.current].type !== '(') {
|
|
87
|
+
throw new Error('Expected opening parenthesis after function');
|
|
88
|
+
}
|
|
89
|
+
this.current++;
|
|
90
|
+
const args = this.parseArguments();
|
|
91
|
+
if (this.tokens[this.current].type !== ')') {
|
|
92
|
+
throw new Error('Expected closing parenthesis');
|
|
93
|
+
}
|
|
94
|
+
this.current++;
|
|
95
|
+
return this.applyFunction(token.type, args);
|
|
96
|
+
}
|
|
97
|
+
throw new Error(`Unexpected token: ${token.type}`);
|
|
98
|
+
}
|
|
99
|
+
parseArguments() {
|
|
100
|
+
const args = [];
|
|
101
|
+
while (this.current < this.tokens.length && this.tokens[this.current].type !== ')') {
|
|
102
|
+
args.push(this.expression());
|
|
103
|
+
if (this.tokens[this.current].type === ',') {
|
|
104
|
+
this.current++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return args;
|
|
108
|
+
}
|
|
109
|
+
applyOperator(operator, left, right) {
|
|
110
|
+
const leftVal = left.value;
|
|
111
|
+
const rightVal = right.value;
|
|
112
|
+
let result;
|
|
113
|
+
switch (operator) {
|
|
114
|
+
case '+':
|
|
115
|
+
result = leftVal + rightVal;
|
|
116
|
+
break;
|
|
117
|
+
case '-':
|
|
118
|
+
result = leftVal - rightVal;
|
|
119
|
+
break;
|
|
120
|
+
case '*':
|
|
121
|
+
result = leftVal * rightVal;
|
|
122
|
+
break;
|
|
123
|
+
case '/':
|
|
124
|
+
result = leftVal / rightVal;
|
|
125
|
+
break;
|
|
126
|
+
default: throw new Error(`Unknown operator: ${operator}`);
|
|
127
|
+
}
|
|
128
|
+
return { type: 'NUMBER', value: result };
|
|
129
|
+
}
|
|
130
|
+
applyFunction(func, args) {
|
|
131
|
+
if (args.some(arg => arg.type !== 'NUMBER')) {
|
|
132
|
+
throw new Error('Function arguments must be numbers');
|
|
133
|
+
}
|
|
134
|
+
const numericArgs = args.map(arg => arg.value);
|
|
135
|
+
if (this.functions[func]) {
|
|
136
|
+
return { type: 'NUMBER', value: this.functions[func].apply(null, numericArgs) };
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error(`Unknown function: ${func}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export function parseFunc(str, funcName) {
|
|
144
|
+
const regex = new RegExp(`${funcName}\\(`, 'g');
|
|
145
|
+
const result = [];
|
|
146
|
+
let match;
|
|
147
|
+
while ((match = regex.exec(str)) !== null) {
|
|
148
|
+
const start = match.index;
|
|
149
|
+
let i = start + funcName.length + 1;
|
|
150
|
+
let depth = 1;
|
|
151
|
+
const args = [];
|
|
152
|
+
let arg = '';
|
|
153
|
+
while (depth && i < str.length) {
|
|
154
|
+
if (depth === 1 && (str[i] === ',' || str[i] === ')')) {
|
|
155
|
+
args.push(arg.trim());
|
|
156
|
+
arg = '';
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
arg += str[i];
|
|
160
|
+
}
|
|
161
|
+
switch (str[i]) {
|
|
162
|
+
case '(':
|
|
163
|
+
depth++;
|
|
164
|
+
break;
|
|
165
|
+
case ')':
|
|
166
|
+
depth--;
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
// Do nothing
|
|
170
|
+
}
|
|
171
|
+
i++;
|
|
172
|
+
}
|
|
173
|
+
const end = regex.lastIndex = i;
|
|
174
|
+
result.push({
|
|
175
|
+
start,
|
|
176
|
+
end,
|
|
177
|
+
args
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
export class ReplaceSource {
|
|
183
|
+
_source;
|
|
184
|
+
_replacements;
|
|
185
|
+
constructor(source) {
|
|
186
|
+
this._source = source;
|
|
187
|
+
this._replacements = [];
|
|
188
|
+
}
|
|
189
|
+
replace(start, end, content) {
|
|
190
|
+
this._replacements.push({ start, end, content });
|
|
191
|
+
}
|
|
192
|
+
source() {
|
|
193
|
+
if (this._replacements.length === 0) {
|
|
194
|
+
return this._source;
|
|
195
|
+
}
|
|
196
|
+
let current = this._source;
|
|
197
|
+
let pos = 0;
|
|
198
|
+
const result = [];
|
|
199
|
+
for (const replacement of this._replacements) {
|
|
200
|
+
const start = Math.floor(replacement.start);
|
|
201
|
+
const end = Math.floor(replacement.end) + 1;
|
|
202
|
+
if (pos < start) {
|
|
203
|
+
const offset = start - pos;
|
|
204
|
+
result.push(current.slice(0, offset));
|
|
205
|
+
current = current.slice(offset);
|
|
206
|
+
pos = start;
|
|
207
|
+
}
|
|
208
|
+
result.push(replacement.content);
|
|
209
|
+
if (pos < end) {
|
|
210
|
+
const offset = end - pos;
|
|
211
|
+
current = current.slice(offset);
|
|
212
|
+
pos = end;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
result.push(current);
|
|
216
|
+
return result.join('');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useRef, useImperativeHandle } from 'react';
|
|
2
|
-
export default function useNodesRef(props, ref, instance = {}) {
|
|
3
|
-
const nodeRef = useRef(null);
|
|
2
|
+
export default function useNodesRef(props, ref, nodeRef, instance = {}) {
|
|
4
3
|
const _props = useRef(null);
|
|
5
4
|
_props.current = props;
|
|
6
5
|
useImperativeHandle(ref, () => {
|
|
@@ -14,7 +13,4 @@ export default function useNodesRef(props, ref, instance = {}) {
|
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
15
|
});
|
|
17
|
-
return {
|
|
18
|
-
nodeRef
|
|
19
|
-
};
|
|
20
16
|
}
|