@mpxjs/webpack-plugin 2.9.0-beta.3 → 2.9.0-beta.5
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.
- package/lib/index.js +3 -10
- package/lib/platform/json/wx/index.js +3 -3
- package/lib/platform/template/wx/component-config/fix-html-tag.js +2 -2
- package/lib/platform/template/wx/index.js +13 -2
- package/lib/runtime/components/web/mpx-keep-alive.vue +2 -0
- package/lib/runtime/components/web/mpx-movable-view.vue +83 -20
- package/lib/runtime/components/web/mpx-scroll-view.vue +50 -15
- package/lib/runtime/components/web/mpx-swiper.vue +152 -62
- package/lib/runtime/optionProcessor.js +4 -3
- package/lib/template-compiler/bind-this.js +45 -14
- package/lib/template-compiler/compiler.js +103 -67
- package/lib/template-compiler/index.js +32 -35
- package/lib/utils/dom-tag-config.js +14 -0
- package/lib/web/processTemplate.js +1 -11
- package/lib/web/script-helper.js +3 -3
- package/package.json +2 -2
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
141
|
-
this.
|
|
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.
|
|
178
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
365
|
+
if (window.__INITIAL_STATE__ && pinia) {
|
|
366
|
+
pinia.state.value = window.__INITIAL_STATE__
|
|
366
367
|
}
|
|
367
368
|
app.$mount(webConfig.el || '#app')
|
|
368
369
|
}
|
|
@@ -85,7 +85,7 @@ function checkDelAndGetPath (path) {
|
|
|
85
85
|
if (args.length === 1) {
|
|
86
86
|
delPath = current.parentPath
|
|
87
87
|
} else {
|
|
88
|
-
// case:
|
|
88
|
+
// case: _i(a, function() {})
|
|
89
89
|
canDel = false
|
|
90
90
|
break
|
|
91
91
|
}
|
|
@@ -96,6 +96,16 @@ function checkDelAndGetPath (path) {
|
|
|
96
96
|
} else {
|
|
97
97
|
delPath = current.parentPath
|
|
98
98
|
}
|
|
99
|
+
} else if (t.isLogicalExpression(current.container)) { // case: a || ''
|
|
100
|
+
const key = current.key === 'left' ? 'right' : 'left'
|
|
101
|
+
if (t.isLiteral(current.parent[key])) {
|
|
102
|
+
delPath = current.parentPath
|
|
103
|
+
} else {
|
|
104
|
+
canDel = false
|
|
105
|
+
break
|
|
106
|
+
}
|
|
107
|
+
} else if (current.key === 'expression' && t.isExpressionStatement(current.parentPath)) { // dealRemove删除节点时需要
|
|
108
|
+
delPath = current.parentPath
|
|
99
109
|
} else {
|
|
100
110
|
break
|
|
101
111
|
}
|
|
@@ -152,10 +162,6 @@ function checkPrefix (keys, key) {
|
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
function dealRemove (path, replace) {
|
|
155
|
-
while (path.key === 'expression' && t.isExpressionStatement(path.parentPath)) {
|
|
156
|
-
path = path.parentPath
|
|
157
|
-
}
|
|
158
|
-
|
|
159
165
|
try {
|
|
160
166
|
if (replace) {
|
|
161
167
|
path.replaceWith(t.stringLiteral(''))
|
|
@@ -163,8 +169,9 @@ function dealRemove (path, replace) {
|
|
|
163
169
|
t.validate(path, path.key, null)
|
|
164
170
|
path.remove()
|
|
165
171
|
}
|
|
172
|
+
delete path.needBind
|
|
173
|
+
delete path.collectInfo
|
|
166
174
|
} catch (e) {
|
|
167
|
-
console.error(e)
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -202,13 +209,30 @@ module.exports = {
|
|
|
202
209
|
Identifier (path) {
|
|
203
210
|
if (
|
|
204
211
|
checkBindThis(path) &&
|
|
205
|
-
!path.scope.hasBinding(path.node.name) &&
|
|
206
212
|
!ignoreMap[path.node.name]
|
|
207
213
|
) {
|
|
214
|
+
const scopeBinding = path.scope.hasBinding(path.node.name)
|
|
215
|
+
// 删除局部作用域的变量
|
|
216
|
+
if (scopeBinding) {
|
|
217
|
+
if (renderReduce) {
|
|
218
|
+
const { delPath, canDel, ignore, replace } = checkDelAndGetPath(path)
|
|
219
|
+
if (canDel && !ignore) {
|
|
220
|
+
delPath.delInfo = {
|
|
221
|
+
isLocal: true,
|
|
222
|
+
canDel,
|
|
223
|
+
replace
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return
|
|
228
|
+
}
|
|
208
229
|
const { last, keyPath } = calPropName(path)
|
|
209
230
|
path.needBind = true
|
|
210
231
|
if (needCollect) {
|
|
211
|
-
last.
|
|
232
|
+
last.collectInfo = {
|
|
233
|
+
key: t.stringLiteral(keyPath),
|
|
234
|
+
isSimple: !/[[.]/.test(keyPath)
|
|
235
|
+
}
|
|
212
236
|
}
|
|
213
237
|
|
|
214
238
|
if (!renderReduce) return
|
|
@@ -272,10 +296,14 @@ module.exports = {
|
|
|
272
296
|
enter (path) {
|
|
273
297
|
// 删除重复变量
|
|
274
298
|
if (path.delInfo) {
|
|
275
|
-
const { keyPath, canDel, replace } = path.delInfo
|
|
299
|
+
const { keyPath, canDel, isLocal, replace } = path.delInfo
|
|
276
300
|
delete path.delInfo
|
|
277
301
|
|
|
278
302
|
if (canDel) {
|
|
303
|
+
if (isLocal) { // 局部作用域里的变量,可直接删除
|
|
304
|
+
dealRemove(path, replace)
|
|
305
|
+
return
|
|
306
|
+
}
|
|
279
307
|
const data = bindingsMap.get(currentBlock)
|
|
280
308
|
const { bindings, pBindings } = data
|
|
281
309
|
const allBindings = Object.assign({}, pBindings, bindings)
|
|
@@ -283,14 +311,12 @@ module.exports = {
|
|
|
283
311
|
// 优先判断前缀,再判断全等
|
|
284
312
|
if (checkPrefix(Object.keys(allBindings), keyPath) || pBindings[keyPath]) {
|
|
285
313
|
dealRemove(path, replace)
|
|
286
|
-
return
|
|
287
314
|
} else {
|
|
288
315
|
const currentBlockVars = bindings[keyPath]
|
|
289
316
|
if (currentBlockVars.length > 1) {
|
|
290
317
|
const index = currentBlockVars.findIndex(item => !item.canDel)
|
|
291
318
|
if (index !== -1 || currentBlockVars[0].path !== path) { // 当前block中存在不可删除的变量 || 不是第一个可删除变量,即可删除该变量
|
|
292
319
|
dealRemove(path, replace)
|
|
293
|
-
return
|
|
294
320
|
}
|
|
295
321
|
}
|
|
296
322
|
}
|
|
@@ -311,9 +337,14 @@ module.exports = {
|
|
|
311
337
|
},
|
|
312
338
|
MemberExpression: {
|
|
313
339
|
exit (path) {
|
|
314
|
-
if (path.
|
|
315
|
-
|
|
316
|
-
|
|
340
|
+
if (path.collectInfo) {
|
|
341
|
+
const { isSimple, key } = path.collectInfo
|
|
342
|
+
const callee = isSimple ? t.identifier('_sc') : t.identifier('_c')
|
|
343
|
+
const replaceNode = renderReduce
|
|
344
|
+
? t.callExpression(callee, [key])
|
|
345
|
+
: t.callExpression(callee, [key, path.node])
|
|
346
|
+
path.node && path.replaceWith(replaceNode)
|
|
347
|
+
delete path.collectInfo
|
|
317
348
|
}
|
|
318
349
|
}
|
|
319
350
|
}
|