@mpxjs/webpack-plugin 2.10.6 → 2.10.7-beta.1

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 (61) hide show
  1. package/lib/file-loader.js +1 -1
  2. package/lib/index.js +41 -13
  3. package/lib/platform/json/wx/index.js +43 -26
  4. package/lib/platform/template/wx/component-config/button.js +1 -1
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  6. package/lib/platform/template/wx/component-config/index.js +5 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  9. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  10. package/lib/platform/template/wx/index.js +2 -1
  11. package/lib/react/LoadAsyncChunkModule.js +68 -0
  12. package/lib/react/index.js +3 -1
  13. package/lib/react/processJSON.js +68 -12
  14. package/lib/react/processScript.js +4 -3
  15. package/lib/react/script-helper.js +92 -18
  16. package/lib/runtime/components/react/AsyncContainer.tsx +217 -0
  17. package/lib/runtime/components/react/AsyncSuspense.tsx +81 -0
  18. package/lib/runtime/components/react/context.ts +12 -3
  19. package/lib/runtime/components/react/dist/AsyncContainer.jsx +160 -0
  20. package/lib/runtime/components/react/dist/AsyncSuspense.jsx +68 -0
  21. package/lib/runtime/components/react/dist/context.js +4 -1
  22. package/lib/runtime/components/react/dist/getInnerListeners.js +1 -1
  23. package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
  24. package/lib/runtime/components/react/dist/mpx-input.jsx +1 -1
  25. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +1 -1
  26. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +55 -40
  27. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +3 -0
  28. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +17 -6
  29. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
  30. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  31. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +2 -2
  32. package/lib/runtime/components/react/dist/mpx-swiper.jsx +53 -27
  33. package/lib/runtime/components/react/dist/mpx-view.jsx +21 -7
  34. package/lib/runtime/components/react/dist/mpx-web-view.jsx +16 -30
  35. package/lib/runtime/components/react/dist/useAnimationHooks.js +2 -87
  36. package/lib/runtime/components/react/dist/utils.jsx +105 -1
  37. package/lib/runtime/components/react/getInnerListeners.ts +1 -1
  38. package/lib/runtime/components/react/mpx-button.tsx +3 -2
  39. package/lib/runtime/components/react/mpx-input.tsx +1 -1
  40. package/lib/runtime/components/react/mpx-movable-area.tsx +1 -1
  41. package/lib/runtime/components/react/mpx-movable-view.tsx +60 -41
  42. package/lib/runtime/components/react/mpx-rich-text/index.tsx +3 -0
  43. package/lib/runtime/components/react/mpx-scroll-view.tsx +68 -50
  44. package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
  45. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  46. package/lib/runtime/components/react/mpx-swiper-item.tsx +2 -2
  47. package/lib/runtime/components/react/mpx-swiper.tsx +53 -25
  48. package/lib/runtime/components/react/mpx-view.tsx +20 -7
  49. package/lib/runtime/components/react/mpx-web-view.tsx +14 -34
  50. package/lib/runtime/components/react/types/global.d.ts +15 -0
  51. package/lib/runtime/components/react/useAnimationHooks.ts +2 -85
  52. package/lib/runtime/components/react/utils.tsx +104 -1
  53. package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
  54. package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
  55. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  56. package/lib/runtime/optionProcessor.js +0 -2
  57. package/lib/template-compiler/compiler.js +2 -2
  58. package/lib/utils/dom-tag-config.js +17 -3
  59. package/lib/web/script-helper.js +1 -1
  60. package/package.json +4 -4
  61. package/LICENSE +0 -433
@@ -44,6 +44,7 @@
44
44
  enhanced: Boolean,
45
45
  refresherEnabled: Boolean,
46
46
  refresherTriggered: Boolean,
47
+ enableSticky: Boolean,
47
48
  refresherThreshold: {
48
49
  type: Number,
49
50
  default: 45
@@ -57,6 +58,16 @@
57
58
  default: ''
58
59
  }
59
60
  },
61
+ provide () {
62
+ return {
63
+ scrollOffset: {
64
+ get: () => this.lastY
65
+ },
66
+ refreshVersion: {
67
+ get: () => this.refreshVersion
68
+ }
69
+ }
70
+ },
60
71
  data () {
61
72
  return {
62
73
  isLoading: false,
@@ -68,7 +79,8 @@
68
79
  lastContentWidth: 0,
69
80
  lastContentHeight: 0,
70
81
  lastWrapperWidth: 0,
71
- lastWrapperHeight: 0
82
+ lastWrapperHeight: 0,
83
+ refreshVersion: 0
72
84
  }
73
85
  },
74
86
  computed: {
@@ -222,6 +234,9 @@
222
234
  stop: 56
223
235
  }
224
236
  }
237
+ if(this.enableSticky) {
238
+ originBsOptions.useTransition = false
239
+ }
225
240
  const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions, { observeDOM: false })
226
241
  this.bs = new BScroll(this.$refs.wrapper, bsOptions)
227
242
  this.lastX = -this.currentX
@@ -251,7 +266,7 @@
251
266
  }
252
267
  this.lastX = x
253
268
  this.lastY = y
254
- }, 30, {
269
+ }, this.enableSticky ? 0 : 30, {
255
270
  leading: true,
256
271
  trailing: true
257
272
  }))
@@ -327,6 +342,7 @@
327
342
  const scrollWrapperHeight = wrapper?.clientHeight || 0
328
343
  if (wrapper) {
329
344
  const computedStyle = getComputedStyle(wrapper)
345
+ this.refreshVersion = this.refreshVersion + 1
330
346
  // 考虑子元素样式可能会设置100%,如果直接继承 scrollContent 的样式可能会有问题
331
347
  // 所以使用 wrapper 作为 innerWrapper 的宽高参考依据
332
348
  this.$refs.innerWrapper.style.width = `${scrollWrapperWidth - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight)}px`
@@ -458,7 +474,8 @@
458
474
  }
459
475
 
460
476
  const innerWrapper = createElement('div', {
461
- ref: 'innerWrapper'
477
+ ref: 'innerWrapper',
478
+ class: 'mpx-inner-wrapper'
462
479
  }, this.$slots.default)
463
480
 
464
481
  const pullDownContent = this.refresherDefaultStyle !== 'none' ? createElement('div', {
@@ -568,4 +585,4 @@
568
585
  background: rgba(255, 255, 255, .7)
569
586
  100%
570
587
  background: rgba(255, 255, 255, .3)
571
- </style>
588
+ </style>
@@ -0,0 +1,91 @@
1
+ <script>
2
+ import { warn } from '@mpxjs/utils'
3
+ import { getCustomEvent } from './getInnerListeners'
4
+
5
+ export default {
6
+ name: 'mpx-sticky-header',
7
+ inject: ['scrollOffset', 'refreshVersion'],
8
+ props: {
9
+ 'offsetTop': {
10
+ type: Number,
11
+ default: 0
12
+ }
13
+ },
14
+ data() {
15
+ return {
16
+ headerTop: 0,
17
+ isStickOnTop: false
18
+ }
19
+ },
20
+ computed: {
21
+ _scrollOffset() {
22
+ return -this.scrollOffset?.get() || 0
23
+ },
24
+ _refreshVersion() {
25
+ return this.refreshVersion?.get() || 0
26
+ }
27
+ },
28
+ watch: {
29
+ _scrollOffset: {
30
+ handler(newScrollOffset) {
31
+ const newIsStickOnTop = newScrollOffset > this.headerTop
32
+ if (newIsStickOnTop !== this.isStickOnTop) {
33
+ this.isStickOnTop = newIsStickOnTop
34
+ this.$emit('stickontopchange', getCustomEvent('stickontopchange', {
35
+ isStickOnTop: newIsStickOnTop
36
+ }, this))
37
+ }
38
+ const stickyHeader = this.$refs.stickyHeader
39
+ if (!stickyHeader) return
40
+ if (this.isStickOnTop) {
41
+ stickyHeader.style.transform = `translateY(${newScrollOffset - this.headerTop + this.offsetTop}px)`
42
+ } else {
43
+ stickyHeader.style.transform = 'none'
44
+ }
45
+ },
46
+ immediate: true
47
+ },
48
+ _refreshVersion: {
49
+ handler() {
50
+ const parentElement = this.$el.parentElement
51
+ if (!parentElement) return
52
+
53
+ const parentClass = parentElement.className || ''
54
+ const isStickySection = /mpx-sticky-section/.test(parentClass)
55
+ const isScrollViewWrapper = /mpx-inner-wrapper/.test(parentClass)
56
+
57
+ if (!isStickySection && !isScrollViewWrapper) {
58
+ warn('sticky-header only supports being a direct child of a scroll-view or sticky-section component.')
59
+ return
60
+ }
61
+
62
+ this.headerTop = isStickySection
63
+ ? this.$el.offsetTop + parentElement.offsetTop
64
+ : this.$el.offsetTop
65
+
66
+ const stickyHeader = this.$refs.stickyHeader
67
+ if (!stickyHeader) return
68
+
69
+ if (this._scrollOffset > this.headerTop) {
70
+ stickyHeader.style.transform = `translateY(${this._scrollOffset - this.headerTop + this.offsetTop}px)`
71
+ } else {
72
+ stickyHeader.style.transform = 'none'
73
+ }
74
+ },
75
+ }
76
+ },
77
+ render(h) {
78
+ const style = {
79
+ width: '100%',
80
+ boxSizing: 'border-box',
81
+ position: 'relative',
82
+ zIndex: 10
83
+ }
84
+
85
+ return h('div', {
86
+ style,
87
+ ref: 'stickyHeader'
88
+ }, this.$slots.default)
89
+ }
90
+ }
91
+ </script>
@@ -0,0 +1,15 @@
1
+ <script>
2
+ export default {
3
+ name: 'mpx-sticky-section',
4
+ render(h) {
5
+ const style = {
6
+ position: 'relative'
7
+ }
8
+
9
+ return h('div', {
10
+ style,
11
+ class: 'mpx-sticky-section'
12
+ }, this.$slots.default)
13
+ }
14
+ }
15
+ </script>
@@ -181,7 +181,6 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
181
181
  global.__mpxRouter.lastStack = null
182
182
  global.__mpxRouter.needCache = null
183
183
  global.__mpxRouter.needRemove = []
184
- global.__mpxRouter.eventChannelMap = {}
185
184
  global.__mpxRouter.currentActionType = null
186
185
  // 处理reLaunch中传递的url并非首页时的replace逻辑
187
186
  global.__mpxRouter.beforeEach(function (to, from, next) {
@@ -241,7 +240,6 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
241
240
  case 'to':
242
241
  stack.push(insertItem)
243
242
  global.__mpxRouter.needCache = insertItem
244
- if (action.eventChannel) global.__mpxRouter.eventChannelMap[to.path.slice(1)] = action.eventChannel
245
243
  break
246
244
  case 'back':
247
245
  global.__mpxRouter.needRemove = stack.splice(stack.length - action.delta, action.delta)
@@ -180,7 +180,7 @@ const i18nModuleName = '_i'
180
180
  const stringifyWxsPath = '~' + normalize.lib('runtime/stringify.wxs')
181
181
  const stringifyModuleName = '_s'
182
182
  const optionalChainWxsPath = '~' + normalize.lib('runtime/oc.wxs')
183
- const optionalChainWxsName = '_o'
183
+ const optionalChainWxsName = '_oc' // 改成_oc解决web下_o重名问题
184
184
 
185
185
  const tagRES = /(\{\{(?:.|\n|\r)+?\}\})(?!})/
186
186
  const tagRE = /\{\{((?:.|\n|\r)+?)\}\}(?!})/
@@ -2725,8 +2725,8 @@ function processElement (el, root, options, meta) {
2725
2725
  processIf(el)
2726
2726
  processFor(el)
2727
2727
  processRefReact(el, meta)
2728
- processStyleReact(el, options)
2729
2728
  if (!pass) {
2729
+ processStyleReact(el, options)
2730
2730
  processEventReact(el, options)
2731
2731
  processComponentGenerics(el, meta)
2732
2732
  processComponentIs(el, options)
@@ -72,7 +72,7 @@ const isNativeMiniTag = makeMap(
72
72
  * 是否为mpx内置组件
73
73
  * collected from packages/webpack-plugin/lib/runtime/components/web/
74
74
  */
75
- const isBuildInTag = makeMap(
75
+ const isBuildInWebTag = makeMap(
76
76
  'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
77
77
  'mpx-swiper-item,mpx-video,mpx-button,mpx-keep-alive,mpx-progress,' +
78
78
  'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
@@ -81,6 +81,19 @@ const isBuildInTag = makeMap(
81
81
  'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
82
82
  )
83
83
 
84
+ /**
85
+ * 是否为mpx2rn内置组件
86
+ */
87
+ const isBuildInReactTag = makeMap(
88
+ 'mpx-web-view,mpx-view,mpx-video,mpx-textarea,mpx-text,mpx-switch,' +
89
+ 'mpx-swiper,mpx-swiper-item,mpx-simple-view,mpx-simple-text,mpx-scroll-view,' +
90
+ 'mpx-root-portal,mpx-radio,mpx-radio-group,mpx-navigator,mpx-movable-view,' +
91
+ 'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
92
+ 'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
93
+ 'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
94
+ 'mpx-icon,mpx-canvas'
95
+ )
96
+
84
97
  const isSpace = makeMap('ensp,emsp,nbsp')
85
98
 
86
99
  const isContWidth = makeMap('col,colgroup,img,table,td,th,tr')
@@ -105,11 +118,12 @@ module.exports = {
105
118
  isVoidTag,
106
119
  isNonPhrasingTag,
107
120
  isRichTextTag,
108
- isBuildInTag,
121
+ isBuildInWebTag,
109
122
  isUnaryTag,
110
123
  isSpace,
111
124
  isContWidth,
112
125
  isContHeight,
113
126
  isNativeMiniTag,
114
- isContConRow
127
+ isContConRow,
128
+ isBuildInReactTag
115
129
  }
@@ -13,7 +13,7 @@ function stringifyRequest (loaderContext, request) {
13
13
 
14
14
  function getAsyncChunkName (chunkName) {
15
15
  if (chunkName && typeof chunkName !== 'boolean') {
16
- return `/* webpackChunkName: "${chunkName}" */`
16
+ return `/* webpackChunkName: "${chunkName}/index" */`
17
17
  }
18
18
  return ''
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.6",
3
+ "version": "2.10.7-beta.1",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -28,7 +28,7 @@
28
28
  "@better-scroll/wheel": "^2.5.1",
29
29
  "@better-scroll/zoom": "^2.5.1",
30
30
  "@mpxjs/template-engine": "^2.8.7",
31
- "@mpxjs/utils": "^2.10.6",
31
+ "@mpxjs/utils": "^2.10.7 | ^2.10.7-beta.1",
32
32
  "acorn": "^8.11.3",
33
33
  "acorn-walk": "^7.2.0",
34
34
  "async": "^2.6.0",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@d11/react-native-fast-image": "^8.6.12",
86
- "@mpxjs/api-proxy": "^2.10.6",
86
+ "@mpxjs/api-proxy": "^2.10.7 | ^2.10.7-beta.1",
87
87
  "@types/babel-traverse": "^6.25.4",
88
88
  "@types/babel-types": "^7.0.4",
89
89
  "@types/react": "^18.2.79",
@@ -100,5 +100,5 @@
100
100
  "engines": {
101
101
  "node": ">=14.14.0"
102
102
  },
103
- "gitHead": "e28605bc2d8ab33f4dccf13ea98d9ca996f43ed6"
103
+ "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
104
104
  }