@mpxjs/webpack-plugin 2.9.0-beta.4 → 2.9.0

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.
@@ -3,7 +3,7 @@ const normalizeTest = require('../normalize-test')
3
3
  const changeKey = require('../change-key')
4
4
  const normalize = require('../../../utils/normalize')
5
5
  const { capitalToHyphen } = require('../../../utils/string')
6
- const { isOriginTag } = require('../../../utils/dom-tag-config')
6
+ const { isOriginTag, isBuildInTag } = require('../../../utils/dom-tag-config')
7
7
 
8
8
  const mpxViewPath = normalize.lib('runtime/components/ali/mpx-view.mpx')
9
9
  const mpxTextPath = normalize.lib('runtime/components/ali/mpx-text.mpx')
@@ -127,7 +127,7 @@ module.exports = function getSpec ({ warn, error }) {
127
127
  }
128
128
 
129
129
  /**
130
- * 将小程序代码中使用的与原生 HTML tag 同名组件进行转化,以解决与原生tag命名冲突问题。
130
+ * 将小程序代码中使用的与原生 HTML tag 或 内建组件 同名的组件进行转化,以解决与原生tag命名冲突问题。
131
131
  * @param {string} type usingComponents
132
132
  * @returns input
133
133
  */
@@ -136,7 +136,7 @@ module.exports = function getSpec ({ warn, error }) {
136
136
  const usingComponents = input[type]
137
137
  if (usingComponents) {
138
138
  Object.keys(usingComponents).forEach(tag => {
139
- if (isOriginTag(tag)) {
139
+ if (isOriginTag(tag) || isBuildInTag(tag)) {
140
140
  usingComponents[`mpx-com-${tag}`] = usingComponents[tag]
141
141
  delete usingComponents[tag]
142
142
  }
@@ -1,9 +1,9 @@
1
- const { isOriginTag } = require('../../../../utils/dom-tag-config')
1
+ const { isOriginTag, isBuildInTag } = require('../../../../utils/dom-tag-config')
2
2
 
3
3
  module.exports = function () {
4
4
  return {
5
5
  waterfall: true,
6
- test: (input) => isOriginTag(input),
6
+ test: (input) => isOriginTag(input) || isBuildInTag(input),
7
7
  // 处理原生tag
8
8
  web (tag, data = {}) {
9
9
  // @see packages/webpack-plugin/lib/platform/json/wx/index.js webHTMLTagProcesser
@@ -41,18 +41,7 @@ module.exports = function ({ print }) {
41
41
  // 快应用通用事件有touchstart|touchmove|touchend|touchcancel|longpress|click|focus|blur
42
42
  event: [
43
43
  {
44
- // 支付宝中的view组件额外支持了transitionEnd|animationStart|animationIteration|animationEnd,故在此声明了组件事件转换逻辑
45
44
  test: /^(transitionend|animationstart|animationiteration|animationend)$/,
46
- //
47
- ali (eventName) {
48
- const eventMap = {
49
- transitionend: 'transitionEnd',
50
- animationstart: 'animationStart',
51
- animationiteration: 'animationIteration',
52
- animationend: 'animationEnd'
53
- }
54
- return eventMap[eventName]
55
- },
56
45
  qa: qaEventLogError
57
46
  }
58
47
  ]
@@ -355,7 +355,7 @@ module.exports = function getSpec ({ warn, error }) {
355
355
  value
356
356
  }
357
357
  },
358
- web ({ name, value }, { eventRules, el }) {
358
+ web ({ name, value }, { eventRules, el, usingComponents }) {
359
359
  if (parseMustacheWithContext(value).hasBinding) {
360
360
  error('Web environment does not support mustache binding in event props!')
361
361
  return
@@ -367,10 +367,11 @@ module.exports = function getSpec ({ warn, error }) {
367
367
  const meta = {
368
368
  modifierStr
369
369
  }
370
+ const isComponent = usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
370
371
  // 记录event监听信息用于后续判断是否需要使用内置基础组件
371
372
  el.hasEvent = true
372
373
  const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'web', meta })
373
- const rEventName = runRules(eventRules, eventName, { mode: 'web' })
374
+ const rEventName = runRules(eventRules, eventName, { mode: 'web', data: { isComponent } })
374
375
  return {
375
376
  name: rPrefix + rEventName + meta.modifierStr,
376
377
  value
@@ -440,7 +441,11 @@ module.exports = function getSpec ({ warn, error }) {
440
441
  touchcancel: 'touchCancel',
441
442
  tap: 'tap',
442
443
  longtap: 'longTap',
443
- longpress: 'longTap'
444
+ longpress: 'longTap',
445
+ transitionend: 'transitionEnd',
446
+ animationstart: 'animationStart',
447
+ animationiteration: 'animationIteration',
448
+ animationend: 'animationEnd'
444
449
  }
445
450
  if (eventMap[eventName]) {
446
451
  return eventMap[eventName]
@@ -453,6 +458,16 @@ module.exports = function getSpec ({ warn, error }) {
453
458
  error(`Web environment does not support [${eventName}] event!`)
454
459
  }
455
460
  }
461
+ },
462
+ // 特殊web事件
463
+ {
464
+ test: /^click$/,
465
+ web (eventName, data) {
466
+ // 自定义组件根节点
467
+ if (data.isComponent) {
468
+ return '_' + eventName
469
+ }
470
+ }
456
471
  }
457
472
  ]
458
473
  }
@@ -64,6 +64,8 @@
64
64
  removeItem.vnode.componentInstance.$destroy()
65
65
  }
66
66
  })
67
+ // 在执行完destroy后再同步lastStack信息,让用户在destroy钩子中还能够访问到销毁之前的页面栈,与小程序保持一致
68
+ router.lastStack = router.stack.slice()
67
69
  router.needRemove.length = 0
68
70
 
69
71
  const stack = router.stack
@@ -10,10 +10,12 @@
10
10
  import {getCustomEvent, extendEvent} from './getInnerListeners'
11
11
  import BScroll from '@better-scroll/core'
12
12
  import Movable from '@better-scroll/movable'
13
+ import ObserveDOM from '@better-scroll/observe-dom'
13
14
  import Zoom from '@better-scroll/zoom'
14
15
 
15
16
  BScroll.use(Movable)
16
17
  BScroll.use(Zoom)
18
+ BScroll.use(ObserveDOM)
17
19
 
18
20
  export default {
19
21
  data () {
@@ -23,6 +25,8 @@
23
25
  maxScrollX: 0,
24
26
  minScrollY: 0,
25
27
  maxScrollY: 0,
28
+ currentX: this.x,
29
+ currentY: this.y,
26
30
  lastestX: 0,
27
31
  lastestY: 0,
28
32
  lastestScale: 1,
@@ -30,7 +34,10 @@
30
34
  isZooming: false,
31
35
  isFirstTouch: true,
32
36
  source: '',
33
- touchEvent: ''
37
+ touchEvent: '',
38
+ isInited: false,
39
+ deactivatedX: 0,
40
+ deactivatedY: 0
34
41
  }
35
42
  },
36
43
  props: {
@@ -89,7 +96,13 @@
89
96
  speed: {
90
97
  type: Number,
91
98
  default: 1000
92
- }
99
+ },
100
+ scrollOptions: {
101
+ type: Object,
102
+ default: () => {
103
+ return {}
104
+ }
105
+ },
93
106
  },
94
107
  watch: {
95
108
  x (newVal) {
@@ -100,6 +113,7 @@
100
113
  if (newVal < this.bs.maxScrollX) {
101
114
  newVal = this.bs.maxScrollX
102
115
  }
116
+ this.currentX = newVal
103
117
  this.bs.scrollTo(newVal, this.bs.y, this.speed)
104
118
  },
105
119
  y (newVal) {
@@ -110,6 +124,7 @@
110
124
  if (newVal < this.bs.maxScrollY) {
111
125
  newVal = this.bs.maxScrollY
112
126
  }
127
+ this.currentY = newVal
113
128
  this.bs.scrollTo(this.bs.x, newVal, this.speed)
114
129
  },
115
130
  scaleValue (newVal) {
@@ -122,22 +137,60 @@
122
137
  }
123
138
  this.bs.zoomTo(newVal, 'center', 'center')
124
139
  },
125
- disabled (newVal) {
126
- if (newVal) {
127
- this.bs && this.bs.disable()
128
- } else {
129
- this.bs && this.bs.enable()
130
- }
140
+ disabled () {
141
+ this.init()
131
142
  }
132
143
  },
133
144
  mounted () {
145
+ if (!this.scrollOptions.closeResizeObserver) {
146
+ this.createResizeObserver()
147
+ }
134
148
  this.init()
135
149
  },
150
+ activated () {
151
+ if (this.deactivatedX || this.deactivatedY) {
152
+ this.refresh()
153
+ this.bs.putAt(this.deactivatedX, this.deactivatedY, 0)
154
+ }
155
+ },
156
+ deactivated () {
157
+ // when the hook is triggered
158
+ // bs will recalculate the boundary of movable to 0
159
+ // so record the position of the movable
160
+ this.deactivatedX = this.bs.x
161
+ this.deactivatedY = this.bs.y
162
+ },
136
163
  beforeDestroy () {
137
- this.bs && this.bs.destroy()
164
+ this.destroyBs()
165
+ if (this.resizeObserver) {
166
+ this.resizeObserver.disconnect()
167
+ this.resizeObserver = null
168
+ }
138
169
  },
139
170
  methods: {
171
+ createResizeObserver () {
172
+ if (typeof ResizeObserver !== 'undefined') {
173
+ this.resizeObserver = new ResizeObserver(entries => {
174
+ if (!this.isInited) {
175
+ this.isInited = true
176
+ return
177
+ }
178
+ this.refresh()
179
+ })
180
+ const elementToObserve = document.querySelector('.mpx-movable-scroll-content')
181
+ this.resizeObserver.observe(elementToObserve)
182
+ }
183
+ },
184
+ refresh () {
185
+ this.bs && this.bs.refresh()
186
+ },
187
+ destroyBs () {
188
+ if (!this.bs) return
189
+ this.bs.destroy()
190
+ delete this.bs
191
+ },
140
192
  init () {
193
+ this.destroyBs()
141
194
  if (!this.$refs.scrollContent.parentNode || (this.$refs.scrollContent.parentNode && this.$refs.scrollContent.parentNode.className !== 'mpx-movable-scroll-wrapper')) {
142
195
  return
143
196
  }
@@ -150,8 +203,8 @@
150
203
  scrollX: false,
151
204
  scrollY: false,
152
205
  movable: true,
153
- startX: this.x,
154
- startY: this.y,
206
+ startX: this.currentX,
207
+ startY: this.currentY,
155
208
  bounce: this.outOfBounds,
156
209
  bounceTime: 800 / (this.damping / 20),
157
210
  probeType: 3,
@@ -160,7 +213,7 @@
160
213
  const BehaviorHooks = this.bs.scroller.scrollBehaviorY.hooks
161
214
  const actionsHandlerHooks = this.bs.scroller.actionsHandler.hooks
162
215
  const scrollerHooks = this.bs.scroller.hooks
163
- this.bs.putAt(this.x, this.y, 0)
216
+ this.bs.putAt(this.currentX, this.currentY, 0)
164
217
  this.lastestX = this.roundFun(this.x)
165
218
  this.lastestY = this.roundFun(this.y)
166
219
  this.lastestScale = this.roundFun(this.scaleValue)
@@ -191,6 +244,10 @@
191
244
  this.lastestX = this.roundFun(position.x)
192
245
  this.lastestY = this.roundFun(position.y)
193
246
  })
247
+ scrollerHooks.on('scrollEnd', (position) =>{
248
+ this.currentX = this.bs.x
249
+ this.currentY = this.bs.y
250
+ })
194
251
  scrollerHooks.on('touchEnd', (position) => {
195
252
  this.isFirstTouch = true
196
253
  if (position.x > this.minScrollX || position.x < this.maxScrollX ||
@@ -257,9 +314,6 @@
257
314
  this.isZooming = false
258
315
  })
259
316
  }
260
- if (this.disabled) { // 禁用
261
- this.bs.disable()
262
- }
263
317
  },
264
318
  initOptions () {
265
319
  if (!this.friction || this.friction < 0) {
@@ -290,19 +344,24 @@
290
344
  swipeTime: 50
291
345
  }
292
346
  }
293
- if (this.direction === 'vertical') {
347
+ if (this.disabled) {
348
+ this.bsOptions = {
349
+ ...this.bsOptions,
350
+ freeScroll: false,
351
+ scrollY: false,
352
+ scrollX: false
353
+ }
354
+ } else if (this.direction === 'vertical') {
294
355
  this.bsOptions = {
295
356
  ...this.bsOptions,
296
357
  scrollY: true
297
358
  }
298
- }
299
- if (this.direction === 'horizontal') {
359
+ } else if (this.direction === 'horizontal') {
300
360
  this.bsOptions = {
301
361
  ...this.bsOptions,
302
362
  scrollX: true
303
363
  }
304
- }
305
- if (this.direction === 'all') {
364
+ } else if (this.direction === 'all') {
306
365
  this.bsOptions = {
307
366
  ...this.bsOptions,
308
367
  freeScroll: true,
@@ -310,6 +369,10 @@
310
369
  scrollY: true
311
370
  }
312
371
  }
372
+ this.bsOptions = {
373
+ ...this.bsOptions,
374
+ ...this.scrollOptions
375
+ }
313
376
  },
314
377
  // 处理小数点,四舍五入,默认保留一位小数
315
378
  roundFun(value, n = 1) {
@@ -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,7 +122,7 @@
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()
@@ -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,6 +230,10 @@
201
230
  leading: true,
202
231
  trailing: false
203
232
  }))
233
+ this.bs.on('scrollEnd', () => {
234
+ this.currentX = -this.bs.x
235
+ this.currentY = -this.bs.y
236
+ })
204
237
  if (this.scrollIntoView) this.scrollToView(this.scrollIntoView)
205
238
  // 若开启自定义下拉刷新 或 开启 scroll-view 增强特性
206
239
  if (this.refresherEnabled || this.enhanced) {
@@ -265,8 +298,10 @@
265
298
  initLayerComputed () {
266
299
  const wrapper = this.$refs.wrapper
267
300
  const computedStyle = getComputedStyle(wrapper)
268
- this.$refs.innerWrapper.style.width = `${computedStyle.clientWidth - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight)}px`
269
- this.$refs.innerWrapper.style.height = `${computedStyle.clientHeight - parseInt(computedStyle.paddingTop) - parseInt(computedStyle.paddingBottom)}px`
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`
270
305
  const innerWrapper = this.$refs.innerWrapper
271
306
  const childrenArr = Array.from(innerWrapper.children)
272
307
 
@@ -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%
@@ -140,6 +140,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
140
140
  routes: routes
141
141
  })
142
142
  global.__mpxRouter.stack = []
143
+ global.__mpxRouter.lastStack = null
143
144
  global.__mpxRouter.needCache = null
144
145
  global.__mpxRouter.needRemove = []
145
146
  global.__mpxRouter.eventChannelMap = {}
@@ -344,7 +345,7 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
344
345
  router.push(context.url)
345
346
  router.onReady(() => {
346
347
  context.rendered = () => {
347
- context.state = JSON.stringify((pinia.state && pinia.state.value) || {})
348
+ context.state = pinia?.state?.value || {}
348
349
  }
349
350
  resolve(app)
350
351
  }, reject)
@@ -361,8 +362,8 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
361
362
  VueRouter,
362
363
  tabBarMap
363
364
  })
364
- if (window.__INITIAL_STATE__) {
365
- pinia.state.value = JSON.parse(window.__INITIAL_STATE__)
365
+ if (window.__INITIAL_STATE__ && pinia) {
366
+ pinia.state.value = window.__INITIAL_STATE__
366
367
  }
367
368
  app.$mount(webConfig.el || '#app')
368
369
  }
@@ -170,7 +170,7 @@ function dealRemove (path, replace) {
170
170
  path.remove()
171
171
  }
172
172
  delete path.needBind
173
- delete path.collectPath
173
+ delete path.collectInfo
174
174
  } catch (e) {
175
175
  }
176
176
  }
@@ -229,7 +229,10 @@ module.exports = {
229
229
  const { last, keyPath } = calPropName(path)
230
230
  path.needBind = true
231
231
  if (needCollect) {
232
- last.collectPath = t.stringLiteral(keyPath)
232
+ last.collectInfo = {
233
+ key: t.stringLiteral(keyPath),
234
+ isSimple: !/[[.]/.test(keyPath)
235
+ }
233
236
  }
234
237
 
235
238
  if (!renderReduce) return
@@ -334,12 +337,14 @@ module.exports = {
334
337
  },
335
338
  MemberExpression: {
336
339
  exit (path) {
337
- if (path.collectPath) {
340
+ if (path.collectInfo) {
341
+ const { isSimple, key } = path.collectInfo
342
+ const callee = isSimple ? t.identifier('_sc') : t.identifier('_c')
338
343
  const replaceNode = renderReduce
339
- ? t.callExpression(t.identifier('_c'), [path.collectPath])
340
- : t.callExpression(t.identifier('_c'), [path.collectPath, path.node])
344
+ ? t.callExpression(callee, [key])
345
+ : t.callExpression(callee, [key, path.node])
341
346
  path.node && path.replaceWith(replaceNode)
342
- delete path.collectPath
347
+ delete path.collectInfo
343
348
  }
344
349
  }
345
350
  }
@@ -94,7 +94,7 @@ global.currentInject = {
94
94
  const rawCode = compiler.genNode(ast)
95
95
  if (rawCode) {
96
96
  const renderCode = `
97
- global.currentInject.render = function (_i, _c, _r) {
97
+ global.currentInject.render = function (_i, _c, _r, _sc) {
98
98
  ${rawCode}
99
99
  _r();
100
100
  };\n`
@@ -68,6 +68,19 @@ const isNativeMiniTag = makeMap(
68
68
  'open-data,native-component,aria-component,page-meta'
69
69
  )
70
70
 
71
+ /**
72
+ * 是否为mpx内置组件
73
+ * collected from packages/webpack-plugin/lib/runtime/components/web/
74
+ */
75
+ const isBuildInTag = makeMap(
76
+ 'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
77
+ 'mpx-swiper-item,mpx-video,mpx-button,mpx-keep-alive,mpx-progress,' +
78
+ 'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
79
+ 'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' +
80
+ 'mpx-tab-bar-container,mpx-form,mpx-navigator,mpx-rich-text,mpx-tab-bar,' +
81
+ 'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
82
+ )
83
+
71
84
  const isSpace = makeMap('ensp,emsp,nbsp')
72
85
 
73
86
  const isContWidth = makeMap('col,colgroup,img,table,td,th,tr')
@@ -92,6 +105,7 @@ module.exports = {
92
105
  isVoidTag,
93
106
  isNonPhrasingTag,
94
107
  isRichTextTag,
108
+ isBuildInTag,
95
109
  isUnaryTag,
96
110
  isSpace,
97
111
  isContWidth,
@@ -129,11 +129,11 @@ function buildGlobalParams ({ moduleId, scriptSrcMode, loaderContext, isProducti
129
129
  global.getCurrentPages = function () {
130
130
  if (!(typeof window !== 'undefined')) {
131
131
  console.error('[Mpx runtime error]: Dangerous API! global.getCurrentPages is running in non browser environment, It may cause some problems, please use this method with caution')
132
- return
133
132
  }
134
- if (!global.__mpxRouter) return []
133
+ const router = global.__mpxRouter
134
+ if(!router) return []
135
135
  // @ts-ignore
136
- return global.__mpxRouter.stack.map(item => {
136
+ return (router.lastStack || router.stack).map(item => {
137
137
  let page
138
138
  const vnode = item.vnode
139
139
  if (vnode && vnode.componentInstance) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.0-beta.4",
3
+ "version": "2.9.0",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14.14.0"
84
84
  },
85
- "gitHead": "300107cbcf0d6847e1d27896ea71ad4ce1387dd5"
85
+ "gitHead": "91ac258dbf1d0a324a74cac606e2cc10ef557823"
86
86
  }