@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.
Files changed (115) hide show
  1. package/lib/index.js +1 -3
  2. package/lib/platform/style/wx/index.js +344 -270
  3. package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
  4. package/lib/platform/template/wx/component-config/checkbox.js +8 -0
  5. package/lib/platform/template/wx/component-config/cover-image.js +15 -0
  6. package/lib/platform/template/wx/component-config/cover-view.js +9 -0
  7. package/lib/platform/template/wx/component-config/form.js +13 -1
  8. package/lib/platform/template/wx/component-config/icon.js +8 -0
  9. package/lib/platform/template/wx/component-config/index.js +5 -1
  10. package/lib/platform/template/wx/component-config/label.js +15 -0
  11. package/lib/platform/template/wx/component-config/movable-area.js +18 -1
  12. package/lib/platform/template/wx/component-config/movable-view.js +18 -1
  13. package/lib/platform/template/wx/component-config/navigator.js +8 -0
  14. package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
  15. package/lib/platform/template/wx/component-config/picker-view.js +18 -2
  16. package/lib/platform/template/wx/component-config/picker.js +14 -1
  17. package/lib/platform/template/wx/component-config/radio-group.js +8 -0
  18. package/lib/platform/template/wx/component-config/radio.js +8 -0
  19. package/lib/platform/template/wx/component-config/root-portal.js +15 -0
  20. package/lib/platform/template/wx/component-config/switch.js +8 -0
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -3
  22. package/lib/react/processScript.js +2 -0
  23. package/lib/react/processStyles.js +1 -0
  24. package/lib/react/processTemplate.js +2 -3
  25. package/lib/react/style-helper.js +12 -7
  26. package/lib/runtime/components/react/context.ts +40 -0
  27. package/lib/runtime/components/react/dist/context.js +8 -0
  28. package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
  29. package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
  30. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
  31. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
  32. package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
  33. package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
  34. package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
  35. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
  38. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
  39. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
  40. package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
  42. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
  43. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
  44. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
  45. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
  48. package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
  53. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
  54. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
  55. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
  56. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
  57. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
  58. package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
  59. package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
  60. package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
  61. package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
  63. package/lib/runtime/components/react/dist/parser.js +218 -0
  64. package/lib/runtime/components/react/dist/types/common.js +1 -0
  65. package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
  66. package/lib/runtime/components/react/dist/utils.jsx +433 -0
  67. package/lib/runtime/components/react/getInnerListeners.ts +43 -21
  68. package/lib/runtime/components/react/mpx-button.tsx +129 -119
  69. package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
  70. package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
  71. package/lib/runtime/components/react/mpx-form.tsx +117 -0
  72. package/lib/runtime/components/react/mpx-icon.tsx +106 -0
  73. package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
  74. package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
  75. package/lib/runtime/components/react/mpx-input.tsx +90 -42
  76. package/lib/runtime/components/react/mpx-label.tsx +110 -0
  77. package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
  78. package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
  79. package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
  80. package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
  81. package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
  82. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
  83. package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
  84. package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
  85. package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
  86. package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
  87. package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
  88. package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
  89. package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
  90. package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
  91. package/lib/runtime/components/react/mpx-radio.tsx +230 -0
  92. package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
  93. package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
  94. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
  95. package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
  96. package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
  97. package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
  98. package/lib/runtime/components/react/mpx-switch.tsx +148 -0
  99. package/lib/runtime/components/react/mpx-text.tsx +53 -77
  100. package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
  101. package/lib/runtime/components/react/mpx-view.tsx +576 -195
  102. package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
  103. package/lib/runtime/components/react/parser.ts +245 -0
  104. package/lib/runtime/components/react/types/common.ts +12 -0
  105. package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
  106. package/lib/runtime/components/react/types/global.d.ts +17 -1
  107. package/lib/runtime/components/react/useNodesRef.ts +4 -10
  108. package/lib/runtime/components/react/utils.tsx +505 -0
  109. package/lib/runtime/optionProcessor.js +19 -17
  110. package/lib/template-compiler/compiler.js +84 -61
  111. package/lib/template-compiler/gen-node-react.js +7 -9
  112. package/lib/web/processStyles.js +2 -5
  113. package/package.json +8 -3
  114. package/lib/runtime/components/react/dist/utils.js +0 -80
  115. package/lib/runtime/components/react/utils.ts +0 -92
@@ -1,28 +1,24 @@
1
1
  import { forwardRef, useEffect } from 'react';
2
- // @ts-ignore
3
- import { noop } from '@mpxjs/utils';
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
- import { StyleSheet } from 'react-native';
11
8
  const _WebView = forwardRef((props, ref) => {
12
9
  const { src, bindmessage = noop, bindload = noop, binderror = noop } = props;
13
- const defaultWebViewStyle = [
14
- {
15
- position: 'absolute',
16
- left: 0,
17
- right: 0,
18
- top: 0,
19
- bottom: 0
20
- }
21
- ];
10
+ if (props.style) {
11
+ warn('The web-view component does not support the style prop.');
12
+ }
13
+ const defaultWebViewStyle = {
14
+ position: 'absolute',
15
+ left: 0,
16
+ right: 0,
17
+ top: 0,
18
+ bottom: 0
19
+ };
22
20
  const { nodeRef: webViewRef } = useNodesRef(props, ref, {
23
- defaultStyle: StyleSheet.flatten([
24
- ...defaultWebViewStyle
25
- ])
21
+ defaultStyle: defaultWebViewStyle
26
22
  });
27
23
  const _messageList = [];
28
24
  const handleUnload = () => {
@@ -61,12 +57,14 @@ const _WebView = forwardRef((props, ref) => {
61
57
  binderror(result);
62
58
  };
63
59
  const _message = function (res) {
64
- let data;
60
+ let data = {};
65
61
  let asyncCallback;
66
62
  const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab });
67
63
  try {
68
64
  const nativeEventData = res.nativeEvent?.data;
69
- data = JSON.parse(nativeEventData);
65
+ if (typeof nativeEventData === 'string') {
66
+ data = JSON.parse(nativeEventData);
67
+ }
70
68
  }
71
69
  catch (e) {
72
70
  data = {};
@@ -106,9 +104,8 @@ const _WebView = forwardRef((props, ref) => {
106
104
  }
107
105
  });
108
106
  };
109
- // @ts-ignore
110
107
  return (<Portal>
111
- <WebView style={[...defaultWebViewStyle]} source={{ uri: src }} ref={webViewRef} onLoad={_load} onError={_error} onMessage={_message} javaScriptEnabled={true}></WebView>
108
+ <WebView style={defaultWebViewStyle} source={{ uri: src }} ref={webViewRef} onLoad={_load} onError={_error} onMessage={_message} javaScriptEnabled={true}></WebView>
112
109
  </Portal>);
113
110
  });
114
111
  _WebView.displayName = 'mpx-web-view';
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,8 @@
1
- import { useRef, useEffect, useImperativeHandle } from 'react';
1
+ import { useRef, useImperativeHandle } from 'react';
2
2
  export default function useNodesRef(props, ref, instance = {}) {
3
3
  const nodeRef = useRef(null);
4
- const _props = useRef(props);
5
- useEffect(() => {
6
- _props.current = props;
7
- return () => {
8
- _props.current = null; // 组件销毁,清空 _props 依赖数据
9
- };
10
- }, [props]);
4
+ const _props = useRef(null);
5
+ _props.current = props;
11
6
  useImperativeHandle(ref, () => {
12
7
  return {
13
8
  getNodeInstance() {