@mpxjs/webpack-plugin 2.10.15-2 → 2.10.15-4

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.
@@ -100,15 +100,6 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
100
100
  layoutRef
101
101
  }, propsRef.current));
102
102
  }, []);
103
- // 节流版本的 change 事件触发
104
- const handleTriggerChangeThrottled = useCallback(({ x, y, type }) => {
105
- 'worklet';
106
- const now = Date.now();
107
- if (now - lastChangeTime.value >= changeThrottleTime) {
108
- lastChangeTime.value = now;
109
- runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type });
110
- }
111
- }, [changeThrottleTime]);
112
103
  useEffect(() => {
113
104
  runOnUI(() => {
114
105
  if (offsetX.value !== x || offsetY.value !== y) {
@@ -302,6 +293,15 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
302
293
  triggerEndOnJS
303
294
  });
304
295
  const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef);
296
+ // 节流版本的 change 事件触发
297
+ const handleTriggerChangeThrottled = useCallback(({ x, y, type }) => {
298
+ 'worklet';
299
+ const now = Date.now();
300
+ if (now - lastChangeTime.value >= changeThrottleTime) {
301
+ lastChangeTime.value = now;
302
+ runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type });
303
+ }
304
+ }, [changeThrottleTime]);
305
305
  const gesture = useMemo(() => {
306
306
  const handleTriggerMove = (e) => {
307
307
  'worklet';
@@ -120,6 +120,8 @@ const SwiperWrapper = forwardRef((props, ref) => {
120
120
  const strVelocity = 'velocity' + dir.toUpperCase();
121
121
  // 标识手指触摸和抬起, 起点在onBegin
122
122
  const touchfinish = useSharedValue(true);
123
+ // 记录onUpdate时的方向,用于进行onFinalize中的值修正
124
+ const preUpdateTransDir = useSharedValue(0);
123
125
  // 记录上一帧的绝对定位坐标
124
126
  const preAbsolutePos = useSharedValue(0);
125
127
  // 记录从onBegin 到 onTouchesUp 时移动的距离
@@ -325,11 +327,9 @@ const SwiperWrapper = forwardRef((props, ref) => {
325
327
  resumeLoop
326
328
  };
327
329
  }, []);
328
- function handleSwiperChange(current, pCurrent) {
329
- if (pCurrent !== currentIndex.value) {
330
- const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
331
- bindchange && bindchange(eventData);
332
- }
330
+ function handleSwiperChange(current) {
331
+ const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
332
+ bindchange && bindchange(eventData);
333
333
  }
334
334
  const runOnJSCallbackRef = useRef({
335
335
  loop,
@@ -379,7 +379,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
379
379
  // 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
380
380
  useAnimatedReaction(() => currentIndex.value, (newIndex, preIndex) => {
381
381
  // 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
382
- if (newIndex !== preIndex && bindchange) {
382
+ if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
383
383
  runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent);
384
384
  }
385
385
  });
@@ -411,9 +411,9 @@ const SwiperWrapper = forwardRef((props, ref) => {
411
411
  }
412
412
  }, [children.length]);
413
413
  useEffect(() => {
414
- // 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
414
+ // 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
415
415
  // 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
416
- if (propCurrent !== currentIndex.value) {
416
+ if (propCurrent !== currentIndex.value && touchfinish.value) {
417
417
  updateCurrent(propCurrent, step.value);
418
418
  }
419
419
  }, [propCurrent]);
@@ -662,6 +662,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
662
662
  translation: moveDistance,
663
663
  transdir: moveDistance
664
664
  };
665
+ preUpdateTransDir.value = moveDistance;
665
666
  // 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
666
667
  const { half } = computeHalf(eventData);
667
668
  if (childrenLength.value > 1 && half) {
@@ -702,11 +703,17 @@ const SwiperWrapper = forwardRef((props, ref) => {
702
703
  if (touchfinish.value)
703
704
  return;
704
705
  touchfinish.value = true;
706
+ /**
707
+ * 安卓修正
708
+ * 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
709
+ * 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
710
+ * 解决方式:修正
711
+ */
705
712
  // 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
706
713
  const moveDistance = e[strAbso] - preAbsolutePos.value;
707
714
  const eventData = {
708
715
  translation: moveDistance,
709
- transdir: moveDistance !== 0 ? moveDistance : e[strAbso] - moveTranstion.value
716
+ transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
710
717
  };
711
718
  // 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
712
719
  if (childrenLength.value === 1) {
@@ -200,16 +200,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
200
200
  )
201
201
  }, [])
202
202
 
203
- // 节流版本的 change 事件触发
204
- const handleTriggerChangeThrottled = useCallback(({ x, y, type }: { x: number; y: number; type?: string }) => {
205
- 'worklet'
206
- const now = Date.now()
207
- if (now - lastChangeTime.value >= changeThrottleTime) {
208
- lastChangeTime.value = now
209
- runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type })
210
- }
211
- }, [changeThrottleTime])
212
-
213
203
  useEffect(() => {
214
204
  runOnUI(() => {
215
205
  if (offsetX.value !== x || offsetY.value !== y) {
@@ -414,6 +404,16 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
414
404
  })
415
405
  const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
416
406
 
407
+ // 节流版本的 change 事件触发
408
+ const handleTriggerChangeThrottled = useCallback(({ x, y, type }: { x: number; y: number; type?: string }) => {
409
+ 'worklet'
410
+ const now = Date.now()
411
+ if (now - lastChangeTime.value >= changeThrottleTime) {
412
+ lastChangeTime.value = now
413
+ runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type })
414
+ }
415
+ }, [changeThrottleTime])
416
+
417
417
  const gesture = useMemo(() => {
418
418
  const handleTriggerMove = (e: GestureTouchEvent) => {
419
419
  'worklet'
@@ -207,6 +207,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
207
207
  const strVelocity = 'velocity' + dir.toUpperCase() as StrVelocityType
208
208
  // 标识手指触摸和抬起, 起点在onBegin
209
209
  const touchfinish = useSharedValue(true)
210
+ // 记录onUpdate时的方向,用于进行onFinalize中的值修正
211
+ const preUpdateTransDir = useSharedValue(0)
210
212
  // 记录上一帧的绝对定位坐标
211
213
  const preAbsolutePos = useSharedValue(0)
212
214
  // 记录从onBegin 到 onTouchesUp 时移动的距离
@@ -429,11 +431,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
429
431
  }
430
432
  }, [])
431
433
 
432
- function handleSwiperChange (current: number, pCurrent: number) {
433
- if (pCurrent !== currentIndex.value) {
434
- const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
435
- bindchange && bindchange(eventData)
436
- }
434
+ function handleSwiperChange (current: number) {
435
+ const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
436
+ bindchange && bindchange(eventData)
437
437
  }
438
438
 
439
439
  const runOnJSCallbackRef = useRef({
@@ -482,7 +482,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
482
482
  // 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
483
483
  useAnimatedReaction(() => currentIndex.value, (newIndex: number, preIndex: number) => {
484
484
  // 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
485
- if (newIndex !== preIndex && bindchange) {
485
+ if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
486
486
  runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
487
487
  }
488
488
  })
@@ -517,9 +517,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
517
517
  }, [children.length])
518
518
 
519
519
  useEffect(() => {
520
- // 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
520
+ // 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
521
521
  // 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
522
- if (propCurrent !== currentIndex.value) {
522
+ if (propCurrent !== currentIndex.value && touchfinish.value) {
523
523
  updateCurrent(propCurrent, step.value)
524
524
  }
525
525
  }, [propCurrent])
@@ -757,6 +757,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
757
757
  translation: moveDistance,
758
758
  transdir: moveDistance
759
759
  }
760
+ preUpdateTransDir.value = moveDistance
760
761
  // 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
761
762
  const { half } = computeHalf(eventData)
762
763
  if (childrenLength.value > 1 && half) {
@@ -794,11 +795,17 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
794
795
  'worklet'
795
796
  if (touchfinish.value) return
796
797
  touchfinish.value = true
798
+ /**
799
+ * 安卓修正
800
+ * 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
801
+ * 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
802
+ * 解决方式:修正
803
+ */
797
804
  // 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
798
805
  const moveDistance = e[strAbso] - preAbsolutePos.value
799
806
  const eventData = {
800
807
  translation: moveDistance,
801
- transdir: moveDistance !== 0 ? moveDistance : e[strAbso] - moveTranstion.value
808
+ transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
802
809
  }
803
810
  // 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
804
811
  if (childrenLength.value === 1) {
@@ -88,7 +88,16 @@ function parseHTML (html, options) {
88
88
  match.end = index
89
89
  handleStartTag(match)
90
90
  }
91
+ continue
92
+ }
93
+
94
+ // If we reach here, the `<` at position 0 does not start a valid tag/comment/end tag
95
+ // Treat it as plain text to avoid infinite loop on stray '<'
96
+ if (options.chars) {
97
+ options.chars('<')
91
98
  }
99
+ advance(1)
100
+ continue
92
101
  }
93
102
  let text, rest, next
94
103
  if (textEnd >= 0) {
@@ -14,7 +14,8 @@ export function processComponentOption (
14
14
  componentGenerics,
15
15
  genericsInfo,
16
16
  wxsMixin,
17
- hasApp
17
+ hasApp,
18
+ disablePageTransition
18
19
  }
19
20
  ) {
20
21
  // 局部注册页面和组件中依赖的组件
@@ -79,7 +80,7 @@ registered in parent context!`)
79
80
  transitionName: ''
80
81
  }
81
82
  }
82
- if (!global.__mpx.config.webConfig.disablePageTransition) {
83
+ if (!disablePageTransition) {
83
84
  option.watch = {
84
85
  $route: {
85
86
  handler () {
@@ -1936,7 +1936,18 @@ function processAttrs (el, options) {
1936
1936
  el.attrsList.forEach((attr) => {
1937
1937
  const isTemplateData = el.tag === 'template' && attr.name === 'data'
1938
1938
  const needWrap = isTemplateData && mode !== 'swan'
1939
- const value = needWrap ? `{${attr.value}}` : attr.value
1939
+ let value = needWrap ? `{${attr.value}}` : attr.value
1940
+
1941
+ // 修复React Native环境下属性值中插值表达式带空格的问题
1942
+ if (isReact(mode) && typeof value === 'string') {
1943
+ // 检查是否为带空格的插值表达式
1944
+ const trimmedValue = value.trim()
1945
+ if (trimmedValue.startsWith('{{') && trimmedValue.endsWith('}}')) {
1946
+ // 如果是纯插值表达式但带有前后空格,则使用去除空格后的值进行解析
1947
+ value = trimmedValue
1948
+ }
1949
+ }
1950
+
1940
1951
  const parsed = parseMustacheWithContext(value)
1941
1952
  if (parsed.hasBinding) {
1942
1953
  // 该属性判断用于提供给运行时对于计算属性作为props传递时提出警告
@@ -27,6 +27,8 @@ module.exports = function (script, {
27
27
  }, callback) {
28
28
  const { projectRoot, appInfo, webConfig, i18n } = loaderContext.getMpx()
29
29
 
30
+ const { disablePageTransition = true } = webConfig
31
+
30
32
  let output = '/* script */\n'
31
33
 
32
34
  let scriptSrcMode = srcMode
@@ -86,7 +88,8 @@ module.exports = function (script, {
86
88
  componentGenerics: ${JSON.stringify(componentGenerics)},
87
89
  genericsInfo: ${JSON.stringify(genericsInfo)},
88
90
  wxsMixin: getWxsMixin(wxsModules),
89
- hasApp: ${hasApp}
91
+ hasApp: ${hasApp},
92
+ disablePageTransition: ${JSON.stringify(disablePageTransition)},
90
93
  })\n`
91
94
  return content
92
95
  }
@@ -35,11 +35,13 @@ module.exports = function (template, {
35
35
  let output = '/* template */\n'
36
36
 
37
37
  if (ctorType === 'app') {
38
- const { el } = webConfig
38
+ const { el, disablePageTransition = true } = webConfig
39
39
  const idName = (el && el.match(/#(.*)/) && el.match(/#(.*)/)[1]) || 'app'
40
40
  template = {
41
41
  tag: 'template',
42
- content: `<div id="${idName}"><transition :name="transitionName"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></transition></div>`
42
+ content: disablePageTransition
43
+ ? `<div id="${idName}"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></div>`
44
+ : `<div id="${idName}"><transition :name="transitionName"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></transition></div>`
43
45
  }
44
46
  builtInComponentsMap['mpx-keep-alive'] = {
45
47
  resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.15-2",
3
+ "version": "2.10.15-4",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"