@mpxjs/webpack-plugin 2.10.4 → 2.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/lib/platform/style/wx/index.js +22 -21
  2. package/lib/react/processScript.js +9 -1
  3. package/lib/react/script-helper.js +5 -1
  4. package/lib/runtime/components/react/dist/event.config.js +0 -2
  5. package/lib/runtime/components/react/dist/getInnerListeners.js +127 -153
  6. package/lib/runtime/components/react/dist/mpx-button.jsx +2 -3
  7. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +3 -4
  8. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -2
  9. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -3
  10. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
  11. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
  12. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  13. package/lib/runtime/components/react/dist/mpx-input.jsx +17 -11
  14. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +22 -29
  15. package/lib/runtime/components/react/dist/mpx-label.jsx +2 -3
  16. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +2 -2
  17. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
  18. package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
  19. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +2 -2
  20. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +2 -3
  21. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +4 -4
  22. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -2
  23. package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -3
  24. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +2 -2
  25. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +1 -1
  26. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +3 -2
  27. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +3 -3
  28. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -5
  29. package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -9
  30. package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -5
  31. package/lib/runtime/components/react/dist/mpx-text.jsx +4 -7
  32. package/lib/runtime/components/react/dist/mpx-video.jsx +2 -2
  33. package/lib/runtime/components/react/dist/mpx-view.jsx +13 -6
  34. package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -4
  35. package/lib/runtime/components/react/dist/utils.jsx +85 -95
  36. package/lib/runtime/components/react/event.config.ts +1 -8
  37. package/lib/runtime/components/react/getInnerListeners.ts +146 -192
  38. package/lib/runtime/components/react/mpx-button.tsx +4 -5
  39. package/lib/runtime/components/react/mpx-canvas/index.tsx +23 -15
  40. package/lib/runtime/components/react/mpx-checkbox-group.tsx +4 -3
  41. package/lib/runtime/components/react/mpx-checkbox.tsx +8 -9
  42. package/lib/runtime/components/react/mpx-form.tsx +25 -19
  43. package/lib/runtime/components/react/mpx-icon/index.tsx +4 -3
  44. package/lib/runtime/components/react/mpx-image.tsx +4 -3
  45. package/lib/runtime/components/react/mpx-input.tsx +22 -15
  46. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +30 -41
  47. package/lib/runtime/components/react/mpx-label.tsx +4 -5
  48. package/lib/runtime/components/react/mpx-movable-area.tsx +22 -13
  49. package/lib/runtime/components/react/mpx-movable-view.tsx +47 -40
  50. package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
  51. package/lib/runtime/components/react/mpx-picker/index.tsx +7 -4
  52. package/lib/runtime/components/react/mpx-picker-view/index.tsx +17 -14
  53. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +4 -4
  54. package/lib/runtime/components/react/mpx-radio-group.tsx +4 -3
  55. package/lib/runtime/components/react/mpx-radio.tsx +8 -9
  56. package/lib/runtime/components/react/mpx-rich-text/index.tsx +15 -6
  57. package/lib/runtime/components/react/mpx-scroll-view.tsx +96 -90
  58. package/lib/runtime/components/react/mpx-simple-text.tsx +10 -3
  59. package/lib/runtime/components/react/mpx-simple-view.tsx +10 -4
  60. package/lib/runtime/components/react/mpx-swiper-item.tsx +31 -24
  61. package/lib/runtime/components/react/mpx-swiper.tsx +67 -61
  62. package/lib/runtime/components/react/mpx-switch.tsx +19 -14
  63. package/lib/runtime/components/react/mpx-text.tsx +16 -13
  64. package/lib/runtime/components/react/mpx-video.tsx +34 -33
  65. package/lib/runtime/components/react/mpx-view.tsx +30 -14
  66. package/lib/runtime/components/react/types/getInnerListeners.d.ts +65 -35
  67. package/lib/runtime/components/react/useAnimationHooks.ts +30 -9
  68. package/lib/runtime/components/react/utils.tsx +91 -98
  69. package/lib/template-compiler/compiler.js +1 -1
  70. package/package.json +3 -3
@@ -26,6 +26,7 @@ const unoVarDecRegExp = /^--un-/;
26
26
  const unoVarUseRegExp = /var\(--un-/;
27
27
  const calcUseRegExp = /calc\(/;
28
28
  const envUseRegExp = /env\(/;
29
+ const filterRegExp = /(calc|env|%)/;
29
30
  const safeAreaInsetMap = {
30
31
  'safe-area-inset-top': 'top',
31
32
  'safe-area-inset-right': 'right',
@@ -181,10 +182,11 @@ function resolveVar(input, varContext) {
181
182
  });
182
183
  return global.__formatValue(replaced.source());
183
184
  }
184
- function transformVar(styleObj, varKeyPaths, varContext) {
185
+ function transformVar(styleObj, varKeyPaths, varContext, visitOther) {
185
186
  varKeyPaths.forEach((varKeyPath) => {
186
187
  setStyle(styleObj, varKeyPath, ({ target, key, value }) => {
187
188
  target[key] = resolveVar(value, varContext);
189
+ visitOther({ target, key, value: target[key], keyPath: varKeyPath });
188
190
  });
189
191
  });
190
192
  }
@@ -224,28 +226,33 @@ function transformCalc(styleObj, calcKeyPaths, formatter) {
224
226
  });
225
227
  });
226
228
  }
227
- const stringifyProps = ['fontWeight'];
228
229
  function transformStringify(styleObj) {
229
- stringifyProps.forEach((prop) => {
230
- if (isNumber(styleObj[prop])) {
231
- styleObj[prop] = '' + styleObj[prop];
232
- }
233
- });
230
+ if (isNumber(styleObj.fontWeight)) {
231
+ styleObj.fontWeight = '' + styleObj.fontWeight;
232
+ }
233
+ }
234
+ function transformPosition(styleObj, meta) {
235
+ if (styleObj.position === 'fixed') {
236
+ styleObj.position = 'absolute';
237
+ meta.hasPositionFixed = true;
238
+ }
234
239
  }
235
240
  export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
236
241
  const varStyle = {};
237
242
  const unoVarStyle = {};
238
243
  const normalStyle = {};
239
- const normalStyleRef = useRef({});
240
- const normalStyleChangedRef = useRef(false);
241
244
  let hasVarDec = false;
242
245
  let hasVarUse = false;
246
+ let hasSelfPercent = false;
243
247
  const varKeyPaths = [];
244
248
  const unoVarKeyPaths = [];
249
+ const percentKeyPaths = [];
250
+ const calcKeyPaths = [];
251
+ const envKeyPaths = [];
245
252
  const [width, setWidth] = useState(0);
246
253
  const [height, setHeight] = useState(0);
247
254
  const navigation = useNavigation();
248
- function varVisitor({ key, value, keyPath }) {
255
+ function varVisitor({ target, key, value, keyPath }) {
249
256
  if (keyPath.length === 1) {
250
257
  if (unoVarDecRegExp.test(key)) {
251
258
  unoVarStyle[key] = value;
@@ -269,6 +276,33 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
269
276
  hasVarUse = true;
270
277
  varKeyPaths.push(keyPath.slice());
271
278
  }
279
+ else {
280
+ visitOther({ target, key, value, keyPath });
281
+ }
282
+ }
283
+ }
284
+ function envVisitor({ value, keyPath }) {
285
+ if (envUseRegExp.test(value)) {
286
+ envKeyPaths.push(keyPath.slice());
287
+ }
288
+ }
289
+ function calcVisitor({ value, keyPath }) {
290
+ if (calcUseRegExp.test(value)) {
291
+ calcKeyPaths.push(keyPath.slice());
292
+ }
293
+ }
294
+ function percentVisitor({ key, value, keyPath }) {
295
+ if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
296
+ hasSelfPercent = true;
297
+ percentKeyPaths.push(keyPath.slice());
298
+ }
299
+ else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
300
+ percentKeyPaths.push(keyPath.slice());
301
+ }
302
+ }
303
+ function visitOther({ target, key, value, keyPath }) {
304
+ if (filterRegExp.test(value)) {
305
+ [envVisitor, percentVisitor, calcVisitor].forEach(visitor => visitor({ target, key, value, keyPath }));
272
306
  }
273
307
  }
274
308
  // traverse var & generate normalStyle
@@ -289,96 +323,57 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
289
323
  if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
290
324
  varContextRef.current = newVarContext;
291
325
  }
292
- transformVar(normalStyle, varKeyPaths, varContextRef.current);
326
+ transformVar(normalStyle, varKeyPaths, varContextRef.current, visitOther);
293
327
  }
294
328
  // apply unocss var
295
329
  if (unoVarKeyPaths.length) {
296
- transformVar(normalStyle, unoVarKeyPaths, unoVarStyle);
297
- }
298
- const { clone, diff } = diffAndCloneA(normalStyle, normalStyleRef.current);
299
- if (diff) {
300
- normalStyleRef.current = clone;
301
- normalStyleChangedRef.current = !normalStyleChangedRef.current;
330
+ transformVar(normalStyle, unoVarKeyPaths, unoVarStyle, visitOther);
302
331
  }
303
- const memoResult = useMemo(() => {
304
- let hasSelfPercent = false;
305
- let hasPositionFixed = false;
306
- const percentKeyPaths = [];
307
- const calcKeyPaths = [];
308
- const envKeyPaths = [];
309
- // transform can be memoized
310
- function envVisitor({ value, keyPath }) {
311
- if (envUseRegExp.test(value)) {
312
- envKeyPaths.push(keyPath.slice());
313
- }
314
- }
315
- function calcVisitor({ value, keyPath }) {
316
- if (calcUseRegExp.test(value)) {
317
- calcKeyPaths.push(keyPath.slice());
318
- }
319
- }
320
- function percentVisitor({ key, value, keyPath }) {
321
- if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
322
- hasSelfPercent = true;
323
- percentKeyPaths.push(keyPath.slice());
324
- }
325
- else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
326
- percentKeyPaths.push(keyPath.slice());
327
- }
328
- }
329
- function transformPosition(styleObj) {
330
- if (styleObj.position === 'fixed') {
331
- hasPositionFixed = true;
332
- styleObj.position = 'absolute';
333
- }
332
+ const percentConfig = {
333
+ width,
334
+ height,
335
+ fontSize: normalStyle.fontSize,
336
+ parentWidth,
337
+ parentHeight,
338
+ parentFontSize
339
+ };
340
+ const positionMeta = {
341
+ hasPositionFixed: false
342
+ };
343
+ // apply env
344
+ transformEnv(normalStyle, envKeyPaths, navigation);
345
+ // apply percent
346
+ transformPercent(normalStyle, percentKeyPaths, percentConfig);
347
+ // apply calc
348
+ transformCalc(normalStyle, calcKeyPaths, (value, key) => {
349
+ if (PERCENT_REGEX.test(value)) {
350
+ const resolved = resolvePercent(value, key, percentConfig);
351
+ return typeof resolved === 'number' ? resolved : 0;
334
352
  }
335
- // traverse env & calc & percent
336
- traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
337
- const percentConfig = {
338
- width,
339
- height,
340
- fontSize: normalStyle.fontSize,
341
- parentWidth,
342
- parentHeight,
343
- parentFontSize
344
- };
345
- // apply env
346
- transformEnv(normalStyle, envKeyPaths, navigation);
347
- // apply percent
348
- transformPercent(normalStyle, percentKeyPaths, percentConfig);
349
- // apply calc
350
- transformCalc(normalStyle, calcKeyPaths, (value, key) => {
351
- if (PERCENT_REGEX.test(value)) {
352
- const resolved = resolvePercent(value, key, percentConfig);
353
- return typeof resolved === 'number' ? resolved : 0;
353
+ else {
354
+ const formatted = global.__formatValue(value);
355
+ if (typeof formatted === 'number') {
356
+ return formatted;
354
357
  }
355
358
  else {
356
- const formatted = global.__formatValue(value);
357
- if (typeof formatted === 'number') {
358
- return formatted;
359
- }
360
- else {
361
- warn('calc() only support number, px, rpx, % temporarily.');
362
- return 0;
363
- }
359
+ warn('calc() only support number, px, rpx, % temporarily.');
360
+ return 0;
364
361
  }
365
- });
366
- // apply position
367
- transformPosition(normalStyle);
368
- // transform number enum stringify
369
- transformStringify(normalStyle);
370
- return {
371
- normalStyle,
372
- hasSelfPercent,
373
- hasPositionFixed
374
- };
375
- }, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize]);
376
- return extendObject({
362
+ }
363
+ });
364
+ // apply position
365
+ transformPosition(normalStyle, positionMeta);
366
+ // transform number enum stringify
367
+ transformStringify(normalStyle);
368
+ return {
377
369
  hasVarDec,
378
370
  varContextRef,
379
371
  setWidth,
380
- setHeight
381
- }, memoResult);
372
+ setHeight,
373
+ normalStyle,
374
+ hasSelfPercent,
375
+ hasPositionFixed: positionMeta.hasPositionFixed
376
+ };
382
377
  }
383
378
  export function traverseStyle(styleObj, visitors) {
384
379
  const keyPath = [];
@@ -387,12 +382,7 @@ export function traverseStyle(styleObj, visitors) {
387
382
  target.forEach((value, index) => {
388
383
  const key = String(index);
389
384
  keyPath.push(key);
390
- visitors.forEach(visitor => visitor({
391
- target,
392
- key,
393
- value,
394
- keyPath
395
- }));
385
+ visitors.forEach(visitor => visitor({ target, key, value, keyPath }));
396
386
  traverse(value);
397
387
  keyPath.pop();
398
388
  });
@@ -1,11 +1,3 @@
1
- interface EventConfig {
2
- [key: string]: string[];
3
- }
4
-
5
- export const TAP_EVENTS = ['bindtap', 'catchtap', 'capture-bindtap', 'capture-catchtap']
6
-
7
- export const LONGPRESS_EVENTS = ['bindlongpress', 'catchlongpress', 'capture-bindlongpress', 'capture-catchlongpress']
8
-
9
1
  const eventConfigMap: { [key: string]: { bitFlag: string; events: string[] } } = {
10
2
  bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
11
3
  bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
@@ -32,4 +24,5 @@ const eventConfigMap: { [key: string]: { bitFlag: string; events: string[] } } =
32
24
  'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'] },
33
25
  'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'] }
34
26
  }
27
+
35
28
  export default eventConfigMap