@mpxjs/webpack-plugin 2.10.4 → 2.10.5-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 (100) hide show
  1. package/lib/index.js +10 -1
  2. package/lib/json-compiler/helper.js +1 -4
  3. package/lib/platform/json/wx/index.js +0 -1
  4. package/lib/platform/style/wx/index.js +22 -21
  5. package/lib/platform/template/wx/component-config/button.js +1 -1
  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 +21 -1
  11. package/lib/react/processJSON.js +7 -6
  12. package/lib/react/processScript.js +9 -1
  13. package/lib/react/script-helper.js +5 -1
  14. package/lib/resolver/PackageEntryPlugin.js +3 -1
  15. package/lib/runtime/components/react/context.ts +12 -3
  16. package/lib/runtime/components/react/dist/context.js +4 -1
  17. package/lib/runtime/components/react/dist/event.config.js +0 -2
  18. package/lib/runtime/components/react/dist/getInnerListeners.js +127 -153
  19. package/lib/runtime/components/react/dist/mpx-button.jsx +11 -7
  20. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +2 -4
  21. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +23 -21
  22. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +9 -4
  23. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +9 -5
  24. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
  25. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +9 -4
  26. package/lib/runtime/components/react/dist/mpx-image.jsx +11 -4
  27. package/lib/runtime/components/react/dist/mpx-input.jsx +24 -13
  28. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +23 -30
  29. package/lib/runtime/components/react/dist/mpx-label.jsx +9 -5
  30. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -4
  31. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +77 -43
  32. package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
  33. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -14
  34. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +10 -10
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +28 -10
  36. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -4
  37. package/lib/runtime/components/react/dist/mpx-radio.jsx +9 -5
  38. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +9 -4
  39. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -11
  40. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +3 -2
  41. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +3 -3
  42. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
  43. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  44. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +15 -14
  45. package/lib/runtime/components/react/dist/mpx-swiper.jsx +86 -40
  46. package/lib/runtime/components/react/dist/mpx-switch.jsx +10 -7
  47. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -9
  48. package/lib/runtime/components/react/dist/mpx-video.jsx +9 -4
  49. package/lib/runtime/components/react/dist/mpx-view.jsx +15 -10
  50. package/lib/runtime/components/react/dist/mpx-web-view.jsx +13 -13
  51. package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -4
  52. package/lib/runtime/components/react/dist/utils.jsx +99 -98
  53. package/lib/runtime/components/react/event.config.ts +1 -8
  54. package/lib/runtime/components/react/getInnerListeners.ts +146 -192
  55. package/lib/runtime/components/react/mpx-button.tsx +16 -8
  56. package/lib/runtime/components/react/mpx-canvas/Image.ts +4 -4
  57. package/lib/runtime/components/react/mpx-canvas/index.tsx +47 -32
  58. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -4
  59. package/lib/runtime/components/react/mpx-checkbox.tsx +17 -10
  60. package/lib/runtime/components/react/mpx-form.tsx +25 -19
  61. package/lib/runtime/components/react/mpx-icon/index.tsx +13 -4
  62. package/lib/runtime/components/react/mpx-image.tsx +42 -22
  63. package/lib/runtime/components/react/mpx-input.tsx +32 -16
  64. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +31 -42
  65. package/lib/runtime/components/react/mpx-label.tsx +13 -6
  66. package/lib/runtime/components/react/mpx-movable-area.tsx +29 -14
  67. package/lib/runtime/components/react/mpx-movable-view.tsx +121 -81
  68. package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
  69. package/lib/runtime/components/react/mpx-picker/index.tsx +24 -19
  70. package/lib/runtime/components/react/mpx-picker-view/index.tsx +39 -22
  71. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +36 -32
  72. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -12
  73. package/lib/runtime/components/react/mpx-radio.tsx +17 -10
  74. package/lib/runtime/components/react/mpx-rich-text/index.tsx +25 -8
  75. package/lib/runtime/components/react/mpx-scroll-view.tsx +95 -60
  76. package/lib/runtime/components/react/mpx-simple-text.tsx +10 -3
  77. package/lib/runtime/components/react/mpx-simple-view.tsx +10 -4
  78. package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
  79. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  80. package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -43
  81. package/lib/runtime/components/react/mpx-swiper.tsx +142 -79
  82. package/lib/runtime/components/react/mpx-switch.tsx +29 -16
  83. package/lib/runtime/components/react/mpx-text.tsx +26 -15
  84. package/lib/runtime/components/react/mpx-video.tsx +41 -35
  85. package/lib/runtime/components/react/mpx-view.tsx +38 -18
  86. package/lib/runtime/components/react/mpx-web-view.tsx +12 -12
  87. package/lib/runtime/components/react/types/getInnerListeners.d.ts +65 -35
  88. package/lib/runtime/components/react/useAnimationHooks.ts +30 -9
  89. package/lib/runtime/components/react/utils.tsx +107 -103
  90. package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
  91. package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
  92. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  93. package/lib/runtime/components/web/mpx-web-view.vue +1 -1
  94. package/lib/runtime/mpxGlobal.js +1 -0
  95. package/lib/runtime/optionProcessor.d.ts +5 -0
  96. package/lib/template-compiler/bind-this.js +8 -7
  97. package/lib/template-compiler/compiler.js +1 -1
  98. package/lib/wxs/pre-loader.js +1 -0
  99. package/package.json +3 -3
  100. 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>
@@ -197,4 +197,4 @@ export default {
197
197
  right: 0;
198
198
  bottom: 0;
199
199
  }
200
- </style>
200
+ </style>
@@ -0,0 +1 @@
1
+ module.exports = Object.create(global)
@@ -4,8 +4,13 @@ declare global {
4
4
  [key: string]: any
5
5
  }
6
6
  }
7
+ interface Window {
8
+ mpxGlobal: Record<string, any>
9
+ }
7
10
  }
8
11
 
12
+ declare const mpxGlobal: Record<string, any>
13
+
9
14
  export function processComponentOption (...args: any): object
10
15
 
11
16
  export function getComponent (...args: any): object
@@ -70,7 +70,7 @@ function getCollectPath (path) {
70
70
  function checkDelAndGetPath (path) {
71
71
  let current = path
72
72
  let delPath = path
73
- let canDel = true
73
+ let canDel = true // 是否可删除,优先级比replace高
74
74
  let ignore = false
75
75
  let replace = false
76
76
 
@@ -80,8 +80,13 @@ function checkDelAndGetPath (path) {
80
80
  if (t.isUnaryExpression(current.parent) && current.key === 'argument') {
81
81
  delPath = current.parentPath
82
82
  } else if (t.isCallExpression(current.parent)) {
83
- const args = current.node.arguments || current.parent.arguments || []
84
- if (args.length === 1) { // case: String(a) || this._p(a)
83
+ const args = current.parent.arguments || []
84
+ if (
85
+ // case: String(a) || this._p(a)
86
+ args.length === 1 ||
87
+ // 除了自身,参数列表里只能是数字或字符串才能删
88
+ (args.every(node => node === current.node || t.isNumericLiteral(node) || t.isStringLiteral(node)))
89
+ ) {
85
90
  delPath = current.parentPath
86
91
  } else {
87
92
  break
@@ -123,24 +128,20 @@ function checkDelAndGetPath (path) {
123
128
 
124
129
  if (t.isCallExpression(parent) && listKey === 'arguments') {
125
130
  canDel = false
126
- break
127
131
  }
128
132
 
129
133
  if (t.isMemberExpression(parent) && parent.computed) {
130
134
  canDel = false
131
- break
132
135
  }
133
136
 
134
137
  if (t.isLogicalExpression(parent)) { // case: a || ((b || c) && d)
135
138
  canDel = false
136
139
  ignore = true
137
- break
138
140
  }
139
141
 
140
142
  if (t.isConditionalExpression(parent)) {
141
143
  if (key === 'test') {
142
144
  canDel = false
143
- break
144
145
  } else {
145
146
  ignore = true
146
147
  replace = true // 继续往上找,判断是否存在if条件等
@@ -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)
2728
2729
  if (!pass) {
2729
- processStyleReact(el, options)
2730
2730
  processEventReact(el, options)
2731
2731
  processComponentGenerics(el, meta)
2732
2732
  processComponentIs(el, options)
@@ -54,6 +54,7 @@ module.exports = function (content) {
54
54
  ExportNamedDeclaration (path) {
55
55
  if (
56
56
  path.node.declaration &&
57
+ path.node.declaration.declarations &&
57
58
  path.node.declaration.declarations.length === 1 &&
58
59
  path.node.declaration.declarations[0].id.name === path.node.declaration.declarations[0].init.name
59
60
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.4",
3
+ "version": "2.10.5-beta.1",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -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.4",
86
+ "@mpxjs/api-proxy": "^2.10.5 | ^2.10.5-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": "c877bcebc894c75fe107f7b997cee5b494932e43"
103
+ "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
104
104
  }