@mpxjs/webpack-plugin 2.9.0-beta.0 → 2.9.0-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 (38) hide show
  1. package/lib/dependencies/DynamicEntryDependency.js +10 -16
  2. package/lib/dependencies/ResolveDependency.js +11 -9
  3. package/lib/index.js +73 -30
  4. package/lib/json-compiler/default-page.mpx +3 -0
  5. package/lib/json-compiler/helper.js +7 -4
  6. package/lib/json-compiler/index.js +41 -19
  7. package/lib/loader.js +2 -9
  8. package/lib/native-loader.js +3 -8
  9. package/lib/parser.js +0 -1
  10. package/lib/platform/json/wx/index.js +21 -0
  11. package/lib/platform/template/wx/component-config/component.js +1 -2
  12. package/lib/platform/template/wx/component-config/hypen-tag-name.js +2 -6
  13. package/lib/platform/template/wx/component-config/index.js +2 -2
  14. package/lib/platform/template/wx/index.js +12 -14
  15. package/lib/runtime/components/web/getInnerListeners.js +16 -2
  16. package/lib/runtime/components/web/mpx-checkbox-group.vue +1 -1
  17. package/lib/runtime/components/web/mpx-form.vue +2 -2
  18. package/lib/runtime/components/web/mpx-image.vue +11 -15
  19. package/lib/runtime/components/web/mpx-movable-view.vue +3 -3
  20. package/lib/runtime/components/web/mpx-picker-view.vue +5 -5
  21. package/lib/runtime/components/web/mpx-picker.vue +3 -3
  22. package/lib/runtime/components/web/mpx-progress.vue +3 -1
  23. package/lib/runtime/components/web/mpx-radio-group.vue +1 -1
  24. package/lib/runtime/components/web/mpx-scroll-view.vue +9 -9
  25. package/lib/runtime/components/web/mpx-slider.vue +4 -4
  26. package/lib/runtime/components/web/mpx-swiper.vue +3 -3
  27. package/lib/runtime/components/web/mpx-switch.vue +1 -1
  28. package/lib/runtime/components/web/mpx-video.vue +14 -28
  29. package/lib/runtime/components/web/mpx-web-view.vue +4 -4
  30. package/lib/runtime/stringify.wxs +44 -8
  31. package/lib/style-compiler/index.js +3 -1
  32. package/lib/template-compiler/compiler.js +73 -50
  33. package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -18
  34. package/lib/wxss/runtime/api.js +18 -19
  35. package/lib/wxss/runtime/noSourceMaps.js +3 -1
  36. package/lib/wxss/runtime/sourceMaps.js +8 -7
  37. package/package.json +3 -3
  38. package/lib/partial-compile/index.js +0 -35
@@ -3,9 +3,7 @@ const JSON5 = require('json5')
3
3
  const getComponentConfigs = require('./component-config')
4
4
  const normalizeComponentRules = require('../normalize-component-rules')
5
5
  const isValidIdentifierStr = require('../../../utils/is-valid-identifier-str')
6
- const templateCompiler = require('../../../template-compiler/compiler')
7
- const parseMustache = templateCompiler.parseMustache
8
- const stringifyWithResolveComputed = templateCompiler.stringifyWithResolveComputed
6
+ const { parseMustacheWithContext, stringifyWithResolveComputed } = require('../../../template-compiler/compiler')
9
7
  const normalize = require('../../../utils/normalize')
10
8
 
11
9
  module.exports = function getSpec ({ warn, error }) {
@@ -17,10 +15,10 @@ module.exports = function getSpec ({ warn, error }) {
17
15
  postProps: [
18
16
  {
19
17
  web ({ name, value }) {
20
- const parsed = parseMustache(value)
18
+ const parsed = parseMustacheWithContext(value)
21
19
  if (parsed.hasBinding) {
22
20
  return {
23
- name: name === 'animation' ? 'v-' + name : ':' + name,
21
+ name: name === 'animation' ? 'v-animation' : ':' + name,
24
22
  value: parsed.result
25
23
  }
26
24
  }
@@ -34,7 +32,7 @@ module.exports = function getSpec ({ warn, error }) {
34
32
  test: 'wx:for',
35
33
  swan (obj, data) {
36
34
  const attrsMap = data.el.attrsMap
37
- const parsed = parseMustache(obj.value)
35
+ const parsed = parseMustacheWithContext(obj.value)
38
36
  let listName = parsed.result
39
37
  const el = data.el
40
38
 
@@ -48,7 +46,7 @@ module.exports = function getSpec ({ warn, error }) {
48
46
  }
49
47
 
50
48
  if (keyName) {
51
- const parsed = parseMustache(keyName)
49
+ const parsed = parseMustacheWithContext(keyName)
52
50
  if (parsed.hasBinding) {
53
51
  // keyStr = ` trackBy ${parsed.result.slice(1, -1)}`
54
52
  } else if (keyName === '*this') {
@@ -78,7 +76,7 @@ module.exports = function getSpec ({ warn, error }) {
78
76
  }
79
77
  },
80
78
  web ({ value }, { el }) {
81
- const parsed = parseMustache(value)
79
+ const parsed = parseMustacheWithContext(value)
82
80
  const attrsMap = el.attrsMap
83
81
  const itemName = attrsMap['wx:for-item'] || 'item'
84
82
  const indexName = attrsMap['wx:for-index'] || 'index'
@@ -190,16 +188,16 @@ module.exports = function getSpec ({ warn, error }) {
190
188
  }
191
189
  const styleBinding = []
192
190
  el.isStyleParsed = true
193
- el.attrsList.forEach((item) => {
194
- const parsed = parseMustache(item.value)
191
+ el.attrsList.filter(item => this.test.test(item.name)).forEach((item) => {
192
+ const parsed = parseMustacheWithContext(item.value)
195
193
  if (item.name === 'style') {
196
194
  if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
197
- styleBinding.push(parseMustache(item.value).result)
195
+ styleBinding.push(parsed.result)
198
196
  } else {
199
197
  styleBinding.push(JSON.stringify(item.value))
200
198
  }
201
199
  } else if (item.name === 'wx:style') {
202
- styleBinding.push(parseMustache(item.value).result)
200
+ styleBinding.push(parsed.result)
203
201
  }
204
202
  })
205
203
  return {
@@ -212,7 +210,7 @@ module.exports = function getSpec ({ warn, error }) {
212
210
  // 样式类名绑定
213
211
  test: /^wx:(class)$/,
214
212
  web ({ value }) {
215
- const parsed = parseMustache(value)
213
+ const parsed = parseMustacheWithContext(value)
216
214
  return {
217
215
  name: ':class',
218
216
  value: parsed.result
@@ -266,7 +264,7 @@ module.exports = function getSpec ({ warn, error }) {
266
264
  },
267
265
  web ({ name, value }) {
268
266
  let dir = this.test.exec(name)[1]
269
- const parsed = parseMustache(value)
267
+ const parsed = parseMustacheWithContext(value)
270
268
  if (dir === 'elif') {
271
269
  dir = 'else-if'
272
270
  }
@@ -143,11 +143,25 @@ export function inheritEvent (type, oe, detail = {}) {
143
143
  }
144
144
 
145
145
  export function getCustomEvent (type, detail = {}, target = null) {
146
+ const targetInfo = {}
147
+ if (target) {
148
+ const targetEl = target.$el || {}
149
+ const info = {
150
+ id: targetEl.id || '',
151
+ dataset: targetEl.dataset || {},
152
+ offsetTop: targetEl.offsetTop || 0,
153
+ offsetLeft: targetEl.offsetLeft || 0
154
+ }
155
+ Object.assign(targetInfo, {
156
+ target: info,
157
+ currentTarget: info
158
+ })
159
+ }
146
160
  return {
147
161
  type,
148
162
  detail,
149
- target,
150
- timeStamp: new Date().valueOf()
163
+ timeStamp: new Date().valueOf(),
164
+ ...targetInfo
151
165
  }
152
166
  }
153
167
 
@@ -79,7 +79,7 @@
79
79
  } else {
80
80
  value = this.getValue()
81
81
  }
82
- this.$emit('change', getCustomEvent('change', { value }, this.$refs.checkboxGroup))
82
+ this.$emit('change', getCustomEvent('change', { value }, this))
83
83
  }
84
84
  }
85
85
  }
@@ -76,11 +76,11 @@
76
76
  methods: {
77
77
  submit () {
78
78
  const value = getFormValue(this.$slots.default)
79
- this.$emit('submit', getCustomEvent('submit', { value }))
79
+ this.$emit('submit', getCustomEvent('submit', { value }, this))
80
80
  },
81
81
  reset () {
82
82
  setFormValue(this.$slots.default, this.initialValue)
83
- this.$emit('reset', getCustomEvent('reset', { value: this.initialValue }))
83
+ this.$emit('reset', getCustomEvent('reset', { value: this.initialValue }, this))
84
84
  }
85
85
  }
86
86
  }
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import getInnerListeners, { extendEvent } from './getInnerListeners'
2
+ import getInnerListeners, { getCustomEvent } from './getInnerListeners'
3
3
  import { isBrowser } from '../../env'
4
4
 
5
5
  export default {
@@ -24,18 +24,14 @@
24
24
  beforeCreate () {
25
25
  if (isBrowser) {
26
26
  this.image = new Image()
27
- this.image.onload = (e) => {
28
- extendEvent(e, {
29
- detail: {
30
- width: this.image.width,
31
- height: this.image.height
32
- }
33
- })
34
-
35
- this.$emit('load', e)
27
+ this.image.onload = () => {
28
+ this.$emit('load', getCustomEvent('load', {
29
+ width: this.image.width,
30
+ height: this.image.height
31
+ }, this))
36
32
  }
37
- this.image.onerror = (e) => {
38
- this.$emit('error', e)
33
+ this.image.onerror = () => {
34
+ this.$emit('error', getCustomEvent('error', {}, this))
39
35
  }
40
36
  }
41
37
  },
@@ -51,9 +47,9 @@
51
47
  if (this.mode === 'widthFix' || this.mode === 'heightFix') {
52
48
  let style
53
49
  if (this.mode === 'widthFix') {
54
- style = {
55
- height: 'auto'
56
- }
50
+ style = {
51
+ height: 'auto'
52
+ }
57
53
  } else {
58
54
  style = {
59
55
  width: 'auto'
@@ -179,7 +179,7 @@
179
179
  x: this.roundFun(position.x) ? this.roundFun(position.x) : 0,
180
180
  y: this.roundFun(position.y) ? this.roundFun(position.y) : 0,
181
181
  source: this.source
182
- }))
182
+ }, this))
183
183
  }
184
184
  this.lastestX = this.roundFun(position.x)
185
185
  this.lastestY = this.roundFun(position.y)
@@ -215,7 +215,7 @@
215
215
  this.touchEvent = 'vtouchmove'
216
216
  }
217
217
  }
218
- this.$emit(this.touchEvent)
218
+ this.$emit(this.touchEvent, getCustomEvent(this.touchEvent, {}, this))
219
219
  this.isFirstTouch = false
220
220
  })
221
221
  if (this.inertia) { // movable-view是否带有惯性
@@ -233,7 +233,7 @@
233
233
  x: this.roundFun(this.bs.x),
234
234
  y: this.roundFun(this.bs.y),
235
235
  scale: this.roundFun(scale)
236
- }))
236
+ }, this))
237
237
  this.lastestScale = this.roundFun(scale)
238
238
  })
239
239
  this.bs.on('zoomEnd', ({ scale }) => {
@@ -97,13 +97,13 @@
97
97
  },
98
98
  notifyChange() {
99
99
  const value = this.getValue()
100
- this.$emit('change', getCustomEvent('change', {value}))
100
+ this.$emit('change', getCustomEvent('change', { value }, this))
101
101
  },
102
- notifyPickstart(value) {
103
- this.$emit('pickstart', getCustomEvent('pickstart', {value}))
102
+ notifyPickstart() {
103
+ this.$emit('pickstart', getCustomEvent('pickstart', {}, this))
104
104
  },
105
- notifyPickend(value) {
106
- this.$emit('pickend', getCustomEvent('pickend', {value}))
105
+ notifyPickend() {
106
+ this.$emit('pickend', getCustomEvent('pickend', {}, this))
107
107
  }
108
108
  }
109
109
  }
@@ -266,11 +266,11 @@
266
266
  default:
267
267
  value = this.selectedIndex[0]
268
268
  }
269
- this.$emit('change', getCustomEvent('change', {value}))
269
+ this.$emit('change', getCustomEvent('change', {value}, this))
270
270
  },
271
271
  _cancel () {
272
272
  this.hide()
273
- this.$emit('cancel', getCustomEvent('cancel'))
273
+ this.$emit('cancel', getCustomEvent('cancel', {}, this))
274
274
  },
275
275
  _isMoving () {
276
276
  return this.wheels.some((wheel) => {
@@ -327,7 +327,7 @@
327
327
  this.$emit('columnchange', getCustomEvent('columnchange', {
328
328
  column: i,
329
329
  value: currentIndex
330
- }))
330
+ }, this))
331
331
  }
332
332
  }
333
333
  if (this.mode === 'time' || this.mode === 'date') {
@@ -113,7 +113,9 @@
113
113
  ref: 'progress',
114
114
  on: {
115
115
  transitionend: () => {
116
- this.$emit('activeend', getCustomEvent('activeend'))
116
+ this.$emit('activeend', getCustomEvent('activeend', {
117
+ curPercent: this.percent
118
+ }, this))
117
119
  }
118
120
  }
119
121
  })
@@ -84,7 +84,7 @@
84
84
  } else {
85
85
  value = this.getValue()
86
86
  }
87
- this.$emit('change', getCustomEvent('change', { value }, this.$refs.radioGroup))
87
+ this.$emit('change', getCustomEvent('change', { value }, this))
88
88
  }
89
89
  }
90
90
  }
@@ -124,7 +124,7 @@
124
124
  refresherTriggered: {
125
125
  handler (val) {
126
126
  if (!val) {
127
- this.$emit('refresherrestore')
127
+ this.$emit('refresherrestore', getCustomEvent('refresherrestore', {}, this))
128
128
  this.isLoading = false
129
129
  this.isAutoPullDown = true
130
130
  this.bs && this.bs.finishPullDown()
@@ -182,7 +182,7 @@
182
182
  scrollHeight: this.bs.scrollerHeight,
183
183
  deltaX,
184
184
  deltaY
185
- }))
185
+ }, this))
186
186
  if (this.bs.minScrollX - x < this._upperThreshold && deltaX > 0) {
187
187
  this.dispatchScrollTo('left')
188
188
  }
@@ -212,7 +212,7 @@
212
212
  this.$emit('dragstart', getCustomEvent('dragstart', {
213
213
  scrollLeft: this.bs.x ? this.bs.x * -1 : 0,
214
214
  scrollTop: this.bs.y ? this.bs.y * -1 : 0
215
- }))
215
+ }, this))
216
216
  }
217
217
  if (this.refresherEnabled) {
218
218
  this.isAutoPullDown = false
@@ -223,13 +223,13 @@
223
223
  this.$emit('dragging', getCustomEvent('dragging', {
224
224
  scrollLeft: this.bs.x ? this.bs.x * -1 : 0,
225
225
  scrollTop: this.bs.y ? this.bs.y * -1 : 0
226
- }))
226
+ }, this))
227
227
  }
228
228
  if (this.refresherEnabled) {
229
229
  if (this.bs.y > 0 && this.bs.y < this.refresherThreshold && this.bs.movingDirectionY !== 1) {
230
230
  this.isAutoPullDown = false
231
231
  this.isLoading = false
232
- this.$emit('refresherpulling')
232
+ this.$emit('refresherpulling', getCustomEvent('refresherpulling', {}, this))
233
233
  }
234
234
  }
235
235
  })
@@ -238,7 +238,7 @@
238
238
  this.$emit('dragend', getCustomEvent('dragend', {
239
239
  scrollLeft: this.bs.x ? this.bs.x * -1 : 0,
240
240
  scrollTop: this.bs.y ? this.bs.y * -1 : 0
241
- }))
241
+ }, this))
242
242
  }
243
243
  })
244
244
  if (this.refresherEnabled) {
@@ -248,12 +248,12 @@
248
248
  this.isLoading = true
249
249
  if (this.bs.y < this.refresherThreshold) {
250
250
  this.isAutoPullDown = true
251
- this.$emit('refresherabort')
251
+ this.$emit('refresherabort', getCustomEvent('refresherabort', {}, this))
252
252
  }
253
253
  }
254
254
  })
255
255
  this.bs.on('pullingDown', () => {
256
- this.$emit('refresherrefresh')
256
+ this.$emit('refresherrefresh', getCustomEvent('refresherrefresh', {}, this))
257
257
  })
258
258
  }
259
259
  }
@@ -312,7 +312,7 @@
312
312
  dispatchScrollTo: throttle(function (direction) {
313
313
  let eventName = 'scrolltoupper'
314
314
  if (direction === 'bottom' || direction === 'right') eventName = 'scrolltolower'
315
- this.$emit(eventName, getCustomEvent(eventName, { direction }))
315
+ this.$emit(eventName, getCustomEvent(eventName, { direction }, this))
316
316
  }, 200, {
317
317
  leading: true,
318
318
  trailing: false
@@ -156,12 +156,12 @@
156
156
  let eventName = 'changing'
157
157
  let moveStartX = event.targetTouches[0] && event.targetTouches[0].pageX
158
158
  this.setLineValue(moveStartX)
159
- this.$emit(eventName, getCustomEvent(eventName, { value: this.sliderValue }, this.$refs.slider))
159
+ this.$emit(eventName, getCustomEvent(eventName, { value: this.sliderValue }, this))
160
160
  }
161
161
  },
162
162
  sliderTouchEnd (event) {
163
163
  let eventName = 'change'
164
- this.$emit(eventName, getCustomEvent(eventName, { value: this.sliderValue }, this.$refs.slider))
164
+ this.$emit(eventName, getCustomEvent(eventName, { value: this.sliderValue }, this))
165
165
  this.isDrag = false
166
166
  },
167
167
  sliderClick (event) {
@@ -170,7 +170,7 @@
170
170
  }
171
171
  this.setLineValue(event.pageX)
172
172
  let eventName = 'change'
173
- this.$emit(eventName, getCustomEvent(eventName, { value: this.sliderValue }, this.$refs.slider))
173
+ this.$emit(eventName, getCustomEvent(eventName, { value: this.sliderValue }, this))
174
174
  },
175
175
  setLineValue (moveStartX) {
176
176
  moveStartX = moveStartX - this.startX
@@ -200,7 +200,7 @@
200
200
  } else {
201
201
  value = this.getValue()
202
202
  }
203
- this.$emit('change', getCustomEvent('change', { value: value }, this.$refs.slider))
203
+ this.$emit('change', getCustomEvent('change', { value: value }, this))
204
204
  }
205
205
  }
206
206
  }
@@ -145,7 +145,7 @@
145
145
  current: this.currentIndex,
146
146
  currentItemId: this.itemIds[this.currentIndex] || '',
147
147
  source: this.changeSource
148
- }))
148
+ }, this))
149
149
  })
150
150
 
151
151
  this.bs.on('scrollEnd', () => {
@@ -153,13 +153,13 @@
153
153
  current: this.currentIndex,
154
154
  currentItemId: this.itemIds[this.currentIndex] || '',
155
155
  source: this.changeSource
156
- }))
156
+ }, this))
157
157
  })
158
158
  this.bs.on('scroll', throttle(({ x, y }) => {
159
159
  this.$emit('transition', getCustomEvent('transition', {
160
160
  dx: this.lastX - x,
161
161
  dy: this.lastY - y
162
- }))
162
+ }, this))
163
163
  }, 30, {
164
164
  leading: true,
165
165
  trailing: false
@@ -80,7 +80,7 @@
80
80
  } else {
81
81
  value = this.getValue()
82
82
  }
83
- this.$emit('change', getCustomEvent('change', { value }, this.$refs.switch))
83
+ this.$emit('change', getCustomEvent('change', { value }, this))
84
84
  }
85
85
  }
86
86
  }
@@ -14,7 +14,7 @@
14
14
  </template>
15
15
 
16
16
  <script>
17
- import { inheritEvent, extendEvent } from './getInnerListeners'
17
+ import { inheritEvent } from './getInnerListeners'
18
18
 
19
19
  export default {
20
20
  name: 'mpx-video',
@@ -169,75 +169,61 @@
169
169
  const videoNode = this.$refs['_mpx_video_ref']
170
170
 
171
171
  videoNode.addEventListener('play', (e) => {
172
- extendEvent(e, { detail: {} })
173
- this.$emit('play', e)
172
+ this.$emit('play', inheritEvent('play', e, {}))
174
173
  })
175
174
 
176
175
  videoNode.addEventListener('pause', (e) => {
177
- extendEvent(e, { detail: {} })
178
- this.$emit('pause', e)
176
+ this.$emit('pause', inheritEvent('pause', e, {}))
179
177
  })
180
178
 
181
179
  videoNode.addEventListener('ended', (e) => {
182
- extendEvent(e, { detail: {} })
183
- this.$emit('ended', e)
180
+ this.$emit('ended', inheritEvent('ended', e, {}))
184
181
  })
185
182
 
186
183
  videoNode.addEventListener('timeupdate', (e) => {
187
184
  const eNode = e.target
188
- extendEvent(e, { detail: { currentTime: eNode.currentTime, duration: eNode.duration } })
189
- this.$emit('timeupdate', e)
185
+ this.$emit('timeupdate', inheritEvent('timeupdate', e, { currentTime: eNode.currentTime, duration: eNode.duration }))
190
186
  })
191
187
 
192
188
  videoNode.addEventListener('error', (e) => {
193
- extendEvent(e, { detail: {} })
194
- this.$emit('error', e)
189
+ this.$emit('error', inheritEvent('error', e, {}))
195
190
  })
196
191
 
197
192
  videoNode.addEventListener('waiting', (e) => {
198
- extendEvent(e, { detail: {} })
199
- this.$emit('waiting', e)
193
+ this.$emit('waiting', inheritEvent('waiting', e, {}))
200
194
  })
201
195
 
202
196
  videoNode.addEventListener('loadedmetadata', (e) => {
203
197
  const eNode = e.target
204
- extendEvent(e, { detail: { width: eNode.videoWidth, height: eNode.videoHeight, duration: eNode.duration } })
205
- this.$emit('loadedmetadata', e)
198
+ this.$emit('loadedmetadata', inheritEvent('loadedmetadata', e, { width: eNode.videoWidth, height: eNode.videoHeight, duration: eNode.duration }))
206
199
  })
207
200
 
208
201
  videoNode.addEventListener('progress', (e) => {
209
202
  const eNode = e.target
210
203
  const buffered = (eNode?.buffered?.end(0)) / (eNode?.duration)
211
- extendEvent(e, { detail: { buffered: buffered * 100 } })
212
- this.$emit('progress', e)
204
+ this.$emit('progress', inheritEvent('progress', e, { buffered: buffered * 100 }))
213
205
  })
214
206
 
215
207
  videoNode.addEventListener('seeked', (e) => {
216
208
  const eNode = e.target
217
- const ne = inheritEvent('seekcomplete', e, { position: eNode.currentTime })
218
- this.$emit('seekcomplete', ne)
209
+ this.$emit('seekcomplete', inheritEvent('seekcomplete', e, { position: eNode.currentTime }))
219
210
  })
220
211
 
221
212
  videoNode.addEventListener('fullscreenchange', (e) => {
222
213
  // TODO direction
223
- extendEvent(e, { detail: { fullScreen: false } })
224
214
  if (document.isFullScreen) {
225
- e.detail.fullScreen = true
226
- this.$emit('fullscreenchange', e)
215
+ this.$emit('fullscreenchange', inheritEvent('fullscreenchange', e, { fullScreen: true }))
227
216
  } else {
228
- e.detail.fullScreen = false
229
- this.$emit('fullscreenchange', e)
217
+ this.$emit('fullscreenchange', inheritEvent('fullscreenchange', e, { fullScreen: false }))
230
218
  }
231
219
  })
232
220
 
233
221
  videoNode.addEventListener('enterpictureinpicture', (e) => {
234
- extendEvent(e, { detail: {} })
235
- this.$emit('enterpictureinpicture', e)
222
+ this.$emit('enterpictureinpicture', inheritEvent('enterpictureinpicture', e, {}))
236
223
  })
237
224
 
238
225
  videoNode.addEventListener('leavepictureinpicture', (e) => {
239
- extendEvent(e, { detail: {} })
240
- this.$emit('leavepictureinpicture', e)
226
+ this.$emit('leavepictureinpicture', inheritEvent('leavepictureinpicture', e, {}))
241
227
  })
242
228
  }
243
229
  }
@@ -49,7 +49,7 @@
49
49
  const loadData = {
50
50
  src: this.src
51
51
  }
52
- this.$emit(eventError, getCustomEvent(eventError, loadData))
52
+ this.$emit(eventError, getCustomEvent(eventError, loadData, this))
53
53
  }
54
54
  }, 1000)
55
55
  this.mpxIframe = this.$refs.mpxIframe
@@ -92,7 +92,7 @@
92
92
  const loadData = {
93
93
  src: this.src
94
94
  }
95
- this.$emit(eventLoad, getCustomEvent(eventLoad, loadData))
95
+ this.$emit(eventLoad, getCustomEvent(eventLoad, loadData, this))
96
96
  }
97
97
  })
98
98
  },
@@ -108,7 +108,7 @@
108
108
  type: 'message',
109
109
  data: this.messageList
110
110
  }
111
- this.$emit(eventMessage, getCustomEvent(eventMessage, data))
111
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
112
112
  },
113
113
  destroyed () {
114
114
  if (!this.isPostMessage) {
@@ -118,7 +118,7 @@
118
118
  type: 'message',
119
119
  data: this.messageList
120
120
  }
121
- this.$emit(eventMessage, getCustomEvent(eventMessage, data))
121
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
122
122
  }
123
123
  }
124
124
  </script>
@@ -24,8 +24,9 @@ function objectKeys (obj) {
24
24
  var shift = false
25
25
  for (var i = 1; i < objStr.length - 1; i++) {
26
26
  var item = objStr[i]
27
+ var lastItem = objStr[i - 1]
27
28
  if (inKey) {
28
- if (item === ':') {
29
+ if (item === ':' && lastItem === '"') {
29
30
  keys.push(key.slice(1, -1))
30
31
  key = ''
31
32
  inKey = false
@@ -93,18 +94,53 @@ function isDef (v) {
93
94
  return v !== undefined && v !== null
94
95
  }
95
96
 
97
+ var escapeMap = {
98
+ '(': '_pl_',
99
+ ')': '_pr_',
100
+ '[': '_bl_',
101
+ ']': '_br_',
102
+ '{': '_cl_',
103
+ '#': '_h_',
104
+ '!': '_i_',
105
+ '/': '_s_',
106
+ '.': '_d_',
107
+ ':': '_c_',
108
+ ',': '_2c_',
109
+ '%': '_p_',
110
+ // wxs can not use '\'' as key
111
+ // wxs环境中'\''!=="'",此文件不能格式化,否则会导致程序错误
112
+ "'": '_q_',
113
+ // wxs can not use '"' as key
114
+ '"': '_dq_',
115
+ '+': '_a_',
116
+ '$': '_si_'
117
+ }
118
+
119
+ var escapeReg = genRegExp('[()[\]{}#!/.:,%\'"+$]', 'g')
120
+
121
+ function mpEscape (str) {
122
+ return str.replace(escapeReg, function (match) {
123
+ if (escapeMap[match]) return escapeMap[match]
124
+ // fix wxs can not use '}' as key
125
+ if (match === '}') return '_cr_'
126
+ // unknown escaped
127
+ return '_u_'
128
+ })
129
+ }
130
+
131
+
96
132
  function stringifyDynamicClass (value) {
97
- if (!value) return ''
98
133
  if (isArray(value)) {
99
- return stringifyArray(value)
100
- }
101
- if (isObject(value)) {
102
- return stringifyObject(value)
134
+ value = stringifyArray(value)
135
+ } else if (isObject(value)) {
136
+ value = stringifyObject(value)
103
137
  }
138
+
104
139
  if (typeof value === 'string') {
105
- return value
140
+ return mpEscape(value)
141
+ } else {
142
+ return ''
106
143
  }
107
- return ''
108
144
  }
109
145
 
110
146
  function stringifyArray (value) {
@@ -30,7 +30,7 @@ module.exports = function (css, map) {
30
30
 
31
31
  const inlineConfig = Object.assign({}, mpx.postcssInlineConfig, { defs })
32
32
  loadPostcssConfig(this, inlineConfig).then(config => {
33
- const plugins = config.plugins.concat(trim)
33
+ const plugins = [trim] // init with trim plugin
34
34
  const options = Object.assign(
35
35
  {
36
36
  to: this.resourcePath,
@@ -79,6 +79,8 @@ module.exports = function (css, map) {
79
79
  }
80
80
  }
81
81
 
82
+ plugins.push(...config.plugins) // push user config plugins
83
+
82
84
  return postcss(plugins)
83
85
  .process(css, options)
84
86
  .then(result => {