@mpxjs/webpack-plugin 2.8.39 → 2.8.40-test

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 (51) hide show
  1. package/lib/dependencies/CommonJsExtractDependency.js +51 -0
  2. package/lib/dependencies/ResolveDependency.js +11 -9
  3. package/lib/extractor.js +1 -0
  4. package/lib/helpers.js +9 -1
  5. package/lib/index.js +173 -72
  6. package/lib/json-compiler/helper.js +25 -9
  7. package/lib/json-compiler/index.js +77 -28
  8. package/lib/loader.js +3 -10
  9. package/lib/native-loader.js +21 -14
  10. package/lib/platform/json/wx/index.js +65 -2
  11. package/lib/platform/run-rules.js +2 -1
  12. package/lib/platform/template/normalize-component-rules.js +2 -0
  13. package/lib/platform/template/wx/component-config/README.md +1 -1
  14. package/lib/platform/template/wx/component-config/fix-html-tag.js +17 -0
  15. package/lib/platform/template/wx/component-config/hypen-tag-name.js +2 -6
  16. package/lib/platform/template/wx/component-config/index.js +4 -2
  17. package/lib/platform/template/wx/component-config/view.js +0 -11
  18. package/lib/platform/template/wx/index.js +65 -18
  19. package/lib/runtime/base.styl +0 -5
  20. package/lib/runtime/components/web/filterTag.js +9 -30
  21. package/lib/runtime/components/web/getInnerListeners.js +2 -14
  22. package/lib/runtime/components/web/mpx-keep-alive.vue +10 -17
  23. package/lib/runtime/components/web/mpx-movable-view.vue +105 -23
  24. package/lib/runtime/components/web/mpx-picker-view.vue +1 -1
  25. package/lib/runtime/components/web/mpx-scroll-view.vue +69 -23
  26. package/lib/runtime/components/web/mpx-swiper.vue +152 -62
  27. package/lib/runtime/components/web/mpx-video.vue +123 -89
  28. package/lib/runtime/components/web/mpx-web-view.vue +120 -81
  29. package/lib/runtime/components/web/promisify.js +19 -0
  30. package/lib/runtime/components/wx/default-page.mpx +27 -0
  31. package/lib/runtime/optionProcessor.js +12 -18
  32. package/lib/style-compiler/index.js +5 -1
  33. package/lib/template-compiler/bind-this.js +280 -49
  34. package/lib/template-compiler/compiler.js +54 -58
  35. package/lib/template-compiler/index.js +35 -23
  36. package/lib/utils/dom-tag-config.js +115 -0
  37. package/lib/utils/make-map.js +12 -0
  38. package/lib/utils/string.js +7 -1
  39. package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -5
  40. package/lib/web/processJSON.js +35 -0
  41. package/lib/web/processScript.js +7 -4
  42. package/lib/web/processTemplate.js +7 -34
  43. package/package.json +4 -4
  44. package/lib/partial-compile/index.js +0 -35
  45. package/lib/template-compiler/preprocessor.js +0 -29
  46. package/lib/wxss/compile-exports.js +0 -52
  47. package/lib/wxss/createResolver.js +0 -36
  48. package/lib/wxss/css-base.js +0 -79
  49. package/lib/wxss/getLocalIdent.js +0 -25
  50. package/lib/wxss/localsLoader.js +0 -44
  51. package/lib/wxss/processCss.js +0 -274
@@ -30,7 +30,12 @@
30
30
  type: [Number, String],
31
31
  default: 0
32
32
  },
33
- scrollOptions: Object,
33
+ scrollOptions: {
34
+ type: Object,
35
+ default: () => {
36
+ return {}
37
+ }
38
+ },
34
39
  updateRefresh: {
35
40
  type: Boolean,
36
41
  default: true
@@ -57,15 +62,23 @@
57
62
  data () {
58
63
  return {
59
64
  isLoading: false,
60
- isAutoPullDown: true
65
+ isAutoPullDown: true,
66
+ currentX: 0,
67
+ currentY: 0,
68
+ lastX: 0,
69
+ lastY: 0
61
70
  }
62
71
  },
63
72
  computed: {
64
73
  _scrollTop () {
65
- return processSize(this.scrollTop)
74
+ const size = processSize(this.scrollTop)
75
+ this.currentY = size
76
+ return size
66
77
  },
67
78
  _scrollLeft () {
68
- return processSize(this.scrollLeft)
79
+ const size = processSize(this.scrollLeft)
80
+ this.currentX = size
81
+ return size
69
82
  },
70
83
  _lowerThreshold () {
71
84
  return processSize(this.lowerThreshold)
@@ -87,10 +100,13 @@
87
100
  className += ' active'
88
101
  }
89
102
  return className
103
+ },
104
+ scroll() {
105
+ return this.scrollX || this.scrollY
90
106
  }
91
107
  },
92
108
  mounted () {
93
- this.init()
109
+ this.initBs()
94
110
  },
95
111
  activated () {
96
112
  if (!this.__mpx_deactivated) {
@@ -106,14 +122,14 @@
106
122
  this.__mpx_deactivated = true
107
123
  },
108
124
  beforeDestroy () {
109
- this.destroy()
125
+ this.destroyBs()
110
126
  },
111
127
  updated () {
112
128
  if (this.updateRefresh) this.refresh()
113
129
  },
114
130
  watch: {
115
131
  scrollIntoView (val) {
116
- this.bs && this.bs.scrollToElement('#' + val, this.scrollWithAnimation ? 200 : 0)
132
+ this.scrollToView(val, this.scrollWithAnimation ? 200 : 0)
117
133
  },
118
134
  _scrollTop (val) {
119
135
  this.bs && this.bs.scrollTo(this.bs.x, -val, this.scrollWithAnimation ? 200 : 0)
@@ -136,20 +152,33 @@
136
152
  }
137
153
  }
138
154
  },
155
+ },
156
+ scroll(val) {
157
+ if (val) {
158
+ this.initBs()
159
+ } else {
160
+ this.disableBs()
161
+ }
139
162
  }
140
163
  },
141
164
  methods: {
142
- destroy () {
165
+ destroyBs () {
143
166
  if (!this.bs) return
144
167
  this.bs.destroy()
145
168
  delete this.bs
146
169
  },
147
- init () {
148
- if (this.bs) return
170
+ disableBs() {
171
+ if (!this.bs) return
172
+ this.bs.disable()
173
+ this.currentX = -this.bs.x
174
+ this.currentY = -this.bs.y
175
+ },
176
+ initBs () {
177
+ this.destroyBs()
149
178
  this.initLayerComputed()
150
179
  const originBsOptions = {
151
- startX: -this._scrollLeft,
152
- startY: -this._scrollTop,
180
+ startX: -this.currentX,
181
+ startY: -this.currentY,
153
182
  scrollX: this.scrollX,
154
183
  scrollY: this.scrollY,
155
184
  probeType: 3,
@@ -170,8 +199,8 @@
170
199
  this.bs.scroller.hooks.on('beforeRefresh', () => {
171
200
  this.initLayerComputed()
172
201
  })
173
- this.lastX = -this._scrollLeft
174
- this.lastY = -this._scrollTop
202
+ this.lastX = -this.currentX
203
+ this.lastY = -this.currentY
175
204
  this.bs.on('scroll', throttle(({ x, y }) => {
176
205
  const deltaX = x - this.lastX
177
206
  const deltaY = y - this.lastY
@@ -201,9 +230,11 @@
201
230
  leading: true,
202
231
  trailing: false
203
232
  }))
204
- if (this.scrollIntoView) {
205
- this.bs.scrollToElement('#' + this.scrollIntoView)
206
- }
233
+ this.bs.on('scrollEnd', () => {
234
+ this.currentX = -this.bs.x
235
+ this.currentY = -this.bs.y
236
+ })
237
+ if (this.scrollIntoView) this.scrollToView(this.scrollIntoView)
207
238
  // 若开启自定义下拉刷新 或 开启 scroll-view 增强特性
208
239
  if (this.refresherEnabled || this.enhanced) {
209
240
  const actionsHandlerHooks = this.bs.scroller.actionsHandler.hooks
@@ -258,12 +289,19 @@
258
289
  }
259
290
  }
260
291
  },
292
+ scrollToView (id, duration = 0) {
293
+ if (!id) return
294
+ id = '#' + id
295
+ if (!document.querySelector(id)) return // 不存在元素时阻断,直接调用better-scroll的方法会报错
296
+ this.bs?.scrollToElement(id, duration)
297
+ },
261
298
  initLayerComputed () {
262
299
  const wrapper = this.$refs.wrapper
263
- const wrapperWidth = wrapper.offsetWidth
264
- const wrapperHeight = wrapper.offsetHeight
265
- this.$refs.innerWrapper.style.width = `${wrapperWidth}px`
266
- this.$refs.innerWrapper.style.height = `${wrapperHeight}px`
300
+ const computedStyle = getComputedStyle(wrapper)
301
+ // 考虑子元素样式可能会设置100%,如果直接继承 scrollContent 的样式可能会有问题
302
+ // 所以使用 wrapper 作为 innerWrapper 的宽高参考依据
303
+ this.$refs.innerWrapper.style.width = `${wrapper.clientWidth - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight)}px`
304
+ this.$refs.innerWrapper.style.height = `${wrapper.clientHeight - parseInt(computedStyle.paddingTop) - parseInt(computedStyle.paddingBottom)}px`
267
305
  const innerWrapper = this.$refs.innerWrapper
268
306
  const childrenArr = Array.from(innerWrapper.children)
269
307
 
@@ -342,7 +380,11 @@
342
380
  class: 'circle circle-c'
343
381
  }),
344
382
  ]
345
- ) : null
383
+ ) : this.$slots.refresher
384
+ ? createElement('div', {
385
+ class: 'mpx-pull-down-slot',
386
+ }, this.$slots.refresher)
387
+ : null
346
388
 
347
389
  const pullDownWrapper = this.refresherEnabled ? createElement('div', {
348
390
  class: 'mpx-pull-down-wrapper',
@@ -376,7 +418,11 @@
376
418
  bottom: 20px
377
419
  left: 50%
378
420
  transform: translateX(-50%)
379
-
421
+ .mpx-pull-down-slot
422
+ position: absolute
423
+ width: 100%
424
+ height: auto
425
+ bottom: 0
380
426
  .mpx-pull-down-content-black
381
427
  .circle
382
428
  display: inline-block;
@@ -2,9 +2,12 @@
2
2
  import getInnerListeners, { getCustomEvent } from './getInnerListeners'
3
3
  import BScroll from '@better-scroll/core'
4
4
  import Slide from '@better-scroll/slide'
5
+ import ObserveDOM from '@better-scroll/observe-dom'
5
6
  import throttle from 'lodash/throttle'
7
+ import { processSize } from '../../utils'
6
8
 
7
9
  BScroll.use(Slide)
10
+ BScroll.use(ObserveDOM)
8
11
 
9
12
  export default {
10
13
  name: 'mpx-swiper',
@@ -37,13 +40,21 @@
37
40
  type: String,
38
41
  default: 'default'
39
42
  },
40
- scrollOptions: Object
43
+ previousMargin: String,
44
+ nextMargin: String,
45
+ scrollOptions: {
46
+ type: Object,
47
+ default: () => {
48
+ return {}
49
+ }
50
+ },
41
51
  },
42
52
  data () {
43
53
  return {
44
54
  currentIndex: this.current,
45
55
  currentChildLength: 0,
46
- lastChildLength: 0
56
+ lastChildLength: 0,
57
+ init: false
47
58
  }
48
59
  },
49
60
  computed: {
@@ -81,13 +92,20 @@
81
92
  default:
82
93
  return
83
94
  }
84
- }
95
+ },
96
+ _previousMargin () {
97
+ return processSize(this.previousMargin) || 0
98
+ },
99
+ _nextMargin () {
100
+ return processSize(this.nextMargin) || 0
101
+ },
85
102
  },
86
103
  updated () {
87
- this.currentChildLength = this.$children && this.$children.length
104
+ this.setCurrentChildLength()
88
105
  },
89
106
  watch: {
90
107
  current (val) {
108
+ this.currentIndex = val
91
109
  if (this.bs) {
92
110
  this.lastX = this.bs.x
93
111
  this.lastY = this.bs.y
@@ -95,7 +113,7 @@
95
113
  this.changeSource = ''
96
114
  this.goto(val)
97
115
  },
98
- currentChildLength(val) {
116
+ currentChildLength (val) {
99
117
  if (val < this.lastChildLength && val < this.currentIndex) {
100
118
  this.goto(0, 0)
101
119
  }
@@ -119,65 +137,128 @@
119
137
  this.itemIds = []
120
138
  },
121
139
  mounted () {
122
- const originBsOptions = {
123
- scrollX: !this.vertical,
124
- scrollY: this.vertical,
125
- slide: {
126
- loop: this.circular,
127
- threshold: 0.5,
128
- speed: this.duration,
129
- easing: this.easing,
130
- interval: this.interval,
131
- autoplay: this.autoplay,
132
- startPageXIndex: this.vertical ? 0 : this.current,
133
- startPageYIndex: this.vertical? this.current : 0
134
- },
135
- momentum: false,
136
- bounce: false,
137
- probeType: 3,
138
- stopPropagation: true
140
+ if (!this.scrollOptions.closeResizeObserver) {
141
+ this.createResizeObserver()
139
142
  }
140
- const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions)
141
- this.bs = new BScroll(this.$refs.wrapper, bsOptions)
142
- this.bs.on('slideWillChange', (page) => {
143
- this.currentIndex = this.vertical ? page.pageY : page.pageX
144
- this.$emit('change', getCustomEvent('change', {
145
- current: this.currentIndex,
146
- currentItemId: this.itemIds[this.currentIndex] || '',
147
- source: this.changeSource
148
- }, this))
149
- })
150
-
151
- this.bs.on('scrollEnd', () => {
152
- this.$emit('animationfinish', getCustomEvent('animationfinish', {
153
- current: this.currentIndex,
154
- currentItemId: this.itemIds[this.currentIndex] || '',
155
- source: this.changeSource
156
- }, this))
157
- })
158
- this.bs.on('scroll', throttle(({ x, y }) => {
159
- this.$emit('transition', getCustomEvent('transition', {
160
- dx: this.lastX - x,
161
- dy: this.lastY - y
162
- }, this))
163
- }, 30, {
164
- leading: true,
165
- trailing: false
166
- }))
167
-
168
- this.bs.on('beforeScrollStart', () => {
169
- if (this.bs) {
170
- this.lastX = this.bs.x
171
- this.lastY = this.bs.y
172
- }
173
- this.changeSource = 'touch'
174
- })
143
+ this.setCurrentChildLength()
144
+ this.initBs()
175
145
  },
176
146
  beforeDestroy () {
177
- this.bs && this.bs.destroy()
178
- delete this.bs
147
+ this.destroyBs()
148
+ if (this.resizeObserver) {
149
+ this.resizeObserver.disconnect()
150
+ this.resizeObserver = null
151
+ }
179
152
  },
180
153
  methods: {
154
+ destroyBs () {
155
+ if (!this.bs) return
156
+ this.bs.destroy()
157
+ delete this.bs
158
+ },
159
+ initLayerComputed () {
160
+ const wrapper = this.$refs.wrapper
161
+ const computedStyle = getComputedStyle(wrapper)
162
+ const innerWrapper = this.$refs.innerWrapper
163
+ let width = wrapper.clientWidth - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight)
164
+ let height = wrapper.clientHeight - parseInt(computedStyle.paddingTop) - parseInt(computedStyle.paddingBottom)
165
+ if (!this.vertical) {
166
+ if (this._previousMargin || this._nextMargin) {
167
+ if (this._previousMargin) {
168
+ innerWrapper.style.marginLeft = `${this._previousMargin}px`
169
+ width = width - this._previousMargin
170
+ }
171
+ if (this._nextMargin) {
172
+ width = width - this._nextMargin
173
+ }
174
+ }
175
+ } else {
176
+ if (this._previousMargin || this._nextMargin) {
177
+ if (this._previousMargin) {
178
+ innerWrapper.style.marginTop = `${this._previousMargin}px`
179
+ height = height - this._previousMargin
180
+ }
181
+ if (this._nextMargin) {
182
+ height = height - this._nextMargin
183
+ }
184
+ }
185
+ }
186
+ innerWrapper.style.height = `${height}px`
187
+ innerWrapper.style.width = `${width}px`
188
+ },
189
+ initBs () {
190
+ this.destroyBs()
191
+ this.initLayerComputed()
192
+ const originBsOptions = {
193
+ scrollX: !this.vertical,
194
+ scrollY: this.vertical,
195
+ slide: {
196
+ loop: this.circular,
197
+ threshold: 0.5,
198
+ speed: this.duration,
199
+ easing: this.easing,
200
+ interval: this.interval,
201
+ autoplay: this.autoplay,
202
+ startPageXIndex: this.vertical ? 0 : this.currentIndex,
203
+ startPageYIndex: this.vertical ? this.currentIndex : 0
204
+ },
205
+ momentum: false,
206
+ bounce: false,
207
+ probeType: 3,
208
+ stopPropagation: true
209
+ }
210
+ const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions)
211
+ this.bs = new BScroll(this.$refs.innerWrapper, bsOptions)
212
+ this.bs.scroller.hooks.on('beforeRefresh', () => {
213
+ this.initLayerComputed()
214
+ })
215
+ this.bs.on('slideWillChange', (page) => {
216
+ this.currentIndex = this.vertical ? page.pageY : page.pageX
217
+ this.$emit('change', getCustomEvent('change', {
218
+ current: this.currentIndex,
219
+ currentItemId: this.itemIds[this.currentIndex] || '',
220
+ source: this.changeSource
221
+ }, this))
222
+ })
223
+
224
+ this.bs.on('scrollEnd', () => {
225
+ this.$emit('animationfinish', getCustomEvent('animationfinish', {
226
+ current: this.currentIndex,
227
+ currentItemId: this.itemIds[this.currentIndex] || '',
228
+ source: this.changeSource
229
+ }, this))
230
+ })
231
+ this.bs.on('scroll', throttle(({ x, y }) => {
232
+ this.$emit('transition', getCustomEvent('transition', {
233
+ dx: this.lastX - x,
234
+ dy: this.lastY - y
235
+ }, this))
236
+ }, 30, {
237
+ leading: true,
238
+ trailing: false
239
+ }))
240
+
241
+ this.bs.on('beforeScrollStart', () => {
242
+ if (this.bs) {
243
+ this.lastX = this.bs.x
244
+ this.lastY = this.bs.y
245
+ }
246
+ this.changeSource = 'touch'
247
+ })
248
+ },
249
+ createResizeObserver () {
250
+ if (typeof ResizeObserver !== 'undefined'){
251
+ this.resizeObserver = new ResizeObserver(entries => {
252
+ if (!this.init) {
253
+ this.init = true
254
+ return
255
+ }
256
+ this.initBs()
257
+ })
258
+ const elementToObserve = document.querySelector('.mpx-swiper');
259
+ this.resizeObserver.observe(elementToObserve);
260
+ }
261
+ },
181
262
  refresh () {
182
263
  this.bs && this.bs.refresh()
183
264
  },
@@ -186,6 +267,9 @@
186
267
  const y = this.vertical ? index : 0
187
268
  const speed = time === 0 ? 0 : this.duration
188
269
  this.bs && this.bs.goToPage(x, y, speed)
270
+ },
271
+ setCurrentChildLength () {
272
+ this.currentChildLength = this.$children && this.$children.length
189
273
  }
190
274
  },
191
275
  render (createElement) {
@@ -194,13 +278,13 @@
194
278
  on: getInnerListeners(this, { ignoredListeners: ['change', 'animationfinish', 'transition'] }),
195
279
  ref: 'wrapper'
196
280
  }
281
+
197
282
  const content = createElement('div', {
198
283
  class: {
199
284
  'mpx-swiper-content': true,
200
285
  vertical: this.vertical
201
286
  }
202
287
  }, this.$slots.default)
203
-
204
288
  const children = [content]
205
289
  if (this.indicatorDots) {
206
290
  const items = this.$slots.default.filter((VNode) => VNode.tag && VNode.tag.endsWith('mpx-swiper-item'))
@@ -227,7 +311,14 @@
227
311
  }, dotsItems)
228
312
  children.push(dots)
229
313
  }
230
- return createElement('div', data, children)
314
+
315
+ const innerWrapper = createElement('div', {
316
+ ref: 'innerWrapper',
317
+ class: {
318
+ 'mpx-swiper-wrapper': true
319
+ }
320
+ }, children)
321
+ return createElement('div', data, [innerWrapper])
231
322
  }
232
323
  }
233
324
  </script>
@@ -237,7 +328,6 @@
237
328
  overflow hidden
238
329
  position relative
239
330
 
240
-
241
331
  .mpx-swiper-content
242
332
  width 100%
243
333
  height 100%