@mpxjs/webpack-plugin 2.9.67 → 2.9.69-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 (150) hide show
  1. package/lib/index.js +30 -9
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  4. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  9. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  10. package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
  11. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  12. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  13. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  14. package/lib/react/processStyles.js +14 -4
  15. package/lib/react/processTemplate.js +3 -0
  16. package/lib/resolver/AddEnvPlugin.js +1 -0
  17. package/lib/resolver/AddModePlugin.js +9 -8
  18. package/lib/runtime/components/react/context.ts +14 -0
  19. package/lib/runtime/components/react/dist/context.js +4 -0
  20. package/lib/runtime/components/react/dist/event.config.js +24 -24
  21. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
  22. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  23. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  32. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  33. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  34. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  35. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  36. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  37. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  38. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  40. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  41. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  42. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  48. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  53. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  55. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  56. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
  57. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  58. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  59. package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
  60. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  61. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  62. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  63. package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
  64. package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
  65. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  66. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  69. package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
  70. package/lib/runtime/components/react/dist/utils.jsx +129 -24
  71. package/lib/runtime/components/react/event.config.ts +25 -26
  72. package/lib/runtime/components/react/getInnerListeners.ts +238 -202
  73. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  74. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  75. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  76. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  77. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  78. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  79. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  80. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  81. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  82. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  83. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  84. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  85. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  86. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  87. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  88. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  89. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  90. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  91. package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
  92. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  93. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  95. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  96. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  97. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  98. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  99. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  100. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
  101. package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
  102. package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
  103. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  104. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  105. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  106. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  107. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  108. package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
  109. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  110. package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
  111. package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
  112. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  113. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  114. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  115. package/lib/runtime/components/react/mpx-view.tsx +93 -117
  116. package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
  117. package/lib/runtime/components/react/pickerFaces.ts +112 -0
  118. package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
  119. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  120. package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
  121. package/lib/runtime/components/react/types/common.ts +2 -0
  122. package/lib/runtime/components/react/types/global.d.ts +7 -17
  123. package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
  124. package/lib/runtime/components/react/utils.tsx +169 -29
  125. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  126. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  127. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  128. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  129. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  130. package/lib/runtime/optionProcessor.js +7 -38
  131. package/lib/runtime/utils.js +2 -0
  132. package/lib/style-compiler/index.js +3 -4
  133. package/lib/style-compiler/plugins/scope-id.js +30 -2
  134. package/lib/style-compiler/strip-conditional-loader.js +118 -0
  135. package/lib/template-compiler/bind-this.js +7 -2
  136. package/lib/template-compiler/compiler.js +66 -39
  137. package/lib/template-compiler/gen-node-react.js +3 -3
  138. package/package.json +6 -4
  139. package/LICENSE +0 -433
  140. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  141. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  142. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  143. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  144. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  145. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  146. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  147. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
  148. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  149. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  150. package/lib/runtime/components/web/event.js +0 -105
@@ -3,184 +3,198 @@
3
3
  </template>
4
4
 
5
5
  <script>
6
- import { getCustomEvent } from './getInnerListeners'
7
- import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
8
- const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
9
- const eventLoad = 'load'
10
- const eventError = 'error'
11
- const eventMessage = 'message'
12
- const mpx = global.__mpx
13
- export default {
14
- props: {
15
- src: {
16
- type: String
6
+ import { getCustomEvent } from './getInnerListeners'
7
+ import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
8
+ import { extend, isFunction } from '@mpxjs/utils'
9
+
10
+ const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
11
+ const eventLoad = 'load'
12
+ const eventError = 'error'
13
+ const eventMessage = 'message'
14
+ const mpx = global.__mpx
15
+ export default {
16
+ props: {
17
+ src: {
18
+ type: String
19
+ }
20
+ },
21
+ computed: {
22
+ host () {
23
+ let host = this.src.split('/')
24
+ if (host[2]) {
25
+ host = host[0] + '//' + host[2]
26
+ } else {
27
+ host = ''
17
28
  }
29
+ return host
18
30
  },
19
- computed: {
20
- host () {
21
- let host = this.src.split('/')
22
- if (host[2]) {
23
- host = host[0] + '//' + host[2]
24
- } else {
25
- host = ''
26
- }
27
- return host
28
- },
29
- currentUrl () {
30
- if (!this.src) return ''
31
- const hostValidate = this.hostValidate(this.host)
32
- if (!hostValidate) {
33
- console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
34
- return ''
35
- }
36
- let src
37
- const srcQueryIndex = this.src.indexOf('?')
38
- // webview与被打开页面通过_uid确定关联关系
39
- if (srcQueryIndex > -1) {
40
- src = `${this.src.substring(0, srcQueryIndex + 1)}mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}`
41
- } else {
42
- src = `${this.src}?mpx_webview_id=${this._uid}`
43
- }
44
- return src
45
- },
46
- loadData () {
47
- return {
48
- src: this.host,
49
- fullUrl: this.src
50
- }
31
+ currentUrl () {
32
+ if (!this.src) return ''
33
+ const hostValidate = this.hostValidate(this.host)
34
+ if (!hostValidate) {
35
+ console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
36
+ return ''
51
37
  }
52
- },
53
- watch: {
54
- currentUrl: {
55
- handler (value) {
56
- if (!value) {
57
- this.$emit(eventError, getCustomEvent(eventError, {
58
- ...this.loadData,
59
- errMsg: 'web-view load failed due to not in domain list'
60
- }, this))
61
- } else {
62
- this.$nextTick(() => {
63
- if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
64
- this.mpxIframe = this.$refs.mpxIframe
65
- this.mpxIframe.addEventListener('load', (event) => {
66
- this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
67
- })
68
- }
69
- })
70
- }
71
- },
72
- immediate: true
38
+ let src
39
+ const srcQueryIndex = this.src.indexOf('?')
40
+ // webview与被打开页面通过_uid确定关联关系
41
+ if (srcQueryIndex > -1) {
42
+ src = `${this.src.substring(0, srcQueryIndex + 1)}mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}`
43
+ } else {
44
+ src = `${this.src}?mpx_webview_id=${this._uid}`
73
45
  }
46
+ return src
74
47
  },
75
- beforeCreate () {
76
- this.messageList = []
77
- },
78
- mounted () {
79
- window.addEventListener('message', this.messageCallback)
80
- },
81
- deactivated () {
82
- if (!this.messageList.length) {
83
- return
84
- }
85
- let data = {
86
- type: 'message',
87
- data: this.messageList
48
+ loadData () {
49
+ return {
50
+ src: this.host,
51
+ fullUrl: this.src
88
52
  }
89
- this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
90
- },
91
- destroyed () {
92
- window.removeEventListener('message', this.messageCallback)
93
- if (!this.messageList.length) {
53
+ }
54
+ },
55
+ watch: {
56
+ currentUrl: {
57
+ handler (value) {
58
+ if (!value) {
59
+ this.$emit(eventError, getCustomEvent(eventError, extend({
60
+ errMsg: 'web-view load failed due to not in domain list'
61
+ }, this.loadData), this))
62
+ } else {
63
+ this.$nextTick(() => {
64
+ if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
65
+ this.mpxIframe = this.$refs.mpxIframe
66
+ this.mpxIframe.addEventListener('load', () => {
67
+ this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
68
+ })
69
+ }
70
+ })
71
+ }
72
+ },
73
+ immediate: true
74
+ }
75
+ },
76
+ beforeCreate () {
77
+ this.messageList = []
78
+ },
79
+ mounted () {
80
+ window.addEventListener('message', this.messageCallback)
81
+ },
82
+ deactivated () {
83
+ if (!this.messageList.length) {
84
+ return
85
+ }
86
+ let data = {
87
+ type: 'message',
88
+ data: this.messageList
89
+ }
90
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
91
+ },
92
+ destroyed () {
93
+ window.removeEventListener('message', this.messageCallback)
94
+ if (!this.messageList.length) {
95
+ return
96
+ }
97
+ let data = {
98
+ type: 'message',
99
+ data: this.messageList
100
+ }
101
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
102
+ },
103
+ methods: {
104
+ messageCallback (event) {
105
+ const hostValidate = this.hostValidate(event.origin)
106
+ let data = {}
107
+ try {
108
+ const eventData = event.data
109
+ data = typeof eventData === 'string' ? JSON.parse(eventData) : eventData
110
+ } catch(e){}
111
+ // 判断number类型,防止undefined导致触发return逻辑
112
+ if (data.clientUid !== undefined && +data.clientUid !== this._uid) {
94
113
  return
95
114
  }
96
- let data = {
97
- type: 'message',
98
- data: this.messageList
115
+ let value = data.payload
116
+ const args = data.args
117
+ const params = Array.isArray(args) ? args : [value]
118
+ if (!hostValidate) {
119
+ return
99
120
  }
100
- this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
101
- },
102
- methods: {
103
- messageCallback (event) {
104
- const hostValidate = this.hostValidate(event.origin)
105
- const data = event.data
106
- // 判断number类型,防止undefined导致触发return逻辑
107
- if (data.clientUid !== undefined && +data.clientUid !== this._uid) {
108
- return
109
- }
110
- let value = data.payload
111
- if (!hostValidate) {
112
- return
113
- }
114
- let asyncCallback = null
115
- switch (data.type) {
116
- case 'postMessage':
117
- this.messageList.push(value.data || value)
118
- asyncCallback = Promise.resolve({
119
- errMsg: 'invokeWebappApi:ok'
120
- })
121
- break
122
- case 'navigateTo':
123
- asyncCallback = navObj.navigateTo(value)
124
- break
125
- case 'navigateBack':
126
- asyncCallback = navObj.navigateBack(value)
127
- break
128
- case 'redirectTo':
129
- asyncCallback = navObj.redirectTo(value)
130
- break
131
- case 'switchTab':
132
- asyncCallback = navObj.switchTab(value)
133
- break
134
- case 'reLaunch':
135
- asyncCallback = navObj.reLaunch(value)
136
- break
137
- case 'getLocation':
138
- const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
139
- if (getLocation) {
140
- asyncCallback = getLocation()
121
+ let asyncCallback = null
122
+ const type = data.type
123
+ switch (type) {
124
+ case 'postMessage':
125
+ let data = {
126
+ type: 'message',
127
+ data: params[0]?.data
128
+ }
129
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
130
+ asyncCallback = Promise.resolve({
131
+ errMsg: 'invokeWebappApi:ok'
132
+ })
133
+ break
134
+ case 'navigateTo':
135
+ asyncCallback = navObj.navigateTo(...params)
136
+ break
137
+ case 'navigateBack':
138
+ asyncCallback = navObj.navigateBack(...params)
139
+ break
140
+ case 'redirectTo':
141
+ asyncCallback = navObj.redirectTo(...params)
142
+ break
143
+ case 'switchTab':
144
+ asyncCallback = navObj.switchTab(...params)
145
+ break
146
+ case 'reLaunch':
147
+ asyncCallback = navObj.reLaunch(...params)
148
+ break
149
+ default:
150
+ if (type) {
151
+ const implement = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations[type]
152
+ if (isFunction(implement)) {
153
+ asyncCallback = Promise.resolve(implement(...params))
141
154
  } else {
142
155
  asyncCallback = Promise.reject({
143
- errMsg: '未在apiImplementations中配置getLocation方法'
156
+ errMsg: `未在apiImplementations中配置${type}方法`
144
157
  })
145
158
  }
146
- break
147
- }
148
- asyncCallback && asyncCallback.then((res) => {
149
- this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
150
- type: data.type,
151
- callbackId: data.callbackId,
152
- result: res
153
- }, event.origin)
154
- }).catch((error) => {
155
- this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
156
- type: data.type,
157
- callbackId: data.callbackId,
158
- error
159
- }, event.origin)
159
+ }
160
+ break
161
+ }
162
+ asyncCallback && asyncCallback.then((res) => {
163
+ this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
164
+ type: type,
165
+ callbackId: data.callbackId,
166
+ result: res
167
+ }, event.origin)
168
+ }).catch((error) => {
169
+ this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
170
+ type: type,
171
+ callbackId: data.callbackId,
172
+ error
173
+ }, event.origin)
174
+ })
175
+ },
176
+ hostValidate (host) {
177
+ const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
178
+ if (hostWhitelists.length) {
179
+ return hostWhitelists.some((item) => {
180
+ return host.endsWith(item)
160
181
  })
161
- },
162
- hostValidate (host) {
163
- const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
164
- if (hostWhitelists.length) {
165
- return hostWhitelists.some((item) => {
166
- return host.endsWith(item)
167
- })
168
- } else {
169
- return true
170
- }
182
+ } else {
183
+ return true
171
184
  }
172
185
  }
173
186
  }
187
+ }
174
188
  </script>
175
189
 
176
190
  <style>
177
- .mpx-iframe {
178
- width: 100%;
179
- height: 100%;
180
- position: absolute;
181
- left: 0;
182
- top: 0;
183
- right: 0;
184
- bottom: 0;
185
- }
186
- </style>
191
+ .mpx-iframe {
192
+ width: 100%;
193
+ height: 100%;
194
+ position: absolute;
195
+ left: 0;
196
+ top: 0;
197
+ right: 0;
198
+ bottom: 0;
199
+ }
200
+ </style>
@@ -1,10 +1,7 @@
1
- import { hasOwn, isEmptyObject } from './utils'
1
+ import { hasOwn, isEmptyObject, extend } from './utils'
2
2
  import { isBrowser } from './env'
3
3
  import transRpxStyle from './transRpxStyle'
4
4
  import animation from './animation'
5
- import { createEvent } from './components/web/event'
6
-
7
- createEvent()
8
5
 
9
6
  export function processComponentOption (
10
7
  {
@@ -59,7 +56,7 @@ registered in parent context!`)
59
56
  }
60
57
 
61
58
  if (ctorType === 'page') {
62
- option.__mpxPageConfig = Object.assign({}, global.__mpxPageConfig, pageConfig)
59
+ option.__mpxPageConfig = extend({}, global.__mpxPageConfig, pageConfig)
63
60
  }
64
61
 
65
62
  if (!hasApp) {
@@ -109,7 +106,7 @@ registered in parent context!`)
109
106
  export function getComponent (component, extendOptions) {
110
107
  component = component.__esModule ? component.default : component
111
108
  // eslint-disable-next-line
112
- if (extendOptions) Object.assign(component, extendOptions)
109
+ if (extendOptions) extend(component, extendOptions)
113
110
  return component
114
111
  }
115
112
 
@@ -164,10 +161,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
164
161
  })
165
162
  }
166
163
  const webRouteConfig = global.__mpx.config.webConfig.routeConfig || global.__mpx.config.webRouteConfig
167
- global.__mpxRouter = option.router = new VueRouter({
168
- ...webRouteConfig,
169
- routes: routes
170
- })
164
+ global.__mpxRouter = option.router = new VueRouter(extend({ routes }, webRouteConfig))
171
165
  let mpxStackPath = []
172
166
  if (isBrowser) {
173
167
  // 解决webview被刷新导致路由栈丢失后产生错乱问题
@@ -312,25 +306,6 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
312
306
  })
313
307
  // 处理visibilitychange时触发当前活跃页面组件的onshow/onhide
314
308
  if (isBrowser) {
315
- const errorHandler = function (args, fromVue) {
316
- if (global.__mpxAppCbs && global.__mpxAppCbs.error && global.__mpxAppCbs.error.length) {
317
- global.__mpxAppCbs.error.forEach((cb) => {
318
- cb.apply(null, args)
319
- })
320
- console.error(...args)
321
- } else if (fromVue) {
322
- throw args[0]
323
- }
324
- }
325
- Vue.config.errorHandler = (...args) => {
326
- return errorHandler(args, true)
327
- }
328
- window.addEventListener('error', (event) => {
329
- return errorHandler([event.error, event])
330
- })
331
- window.addEventListener('unhandledrejection', (event) => {
332
- return errorHandler([event.reason, event])
333
- })
334
309
  document.addEventListener('visibilitychange', function () {
335
310
  const vnode = global.__mpxRouter && global.__mpxRouter.__mpxActiveVnode
336
311
  if (vnode && vnode.componentInstance) {
@@ -365,7 +340,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
365
340
 
366
341
  if (App.onAppInit) {
367
342
  global.__mpxAppInit = true
368
- Object.assign(option, App.onAppInit() || {})
343
+ extend(option, App.onAppInit() || {})
369
344
  global.__mpxAppInit = false
370
345
  }
371
346
 
@@ -374,14 +349,8 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
374
349
  option.pinia = global.__mpxPinia
375
350
  }
376
351
 
377
- const app = new Vue({
378
- ...option,
379
- render: (h) => h(App)
380
- })
381
- return {
382
- app,
383
- ...option
384
- }
352
+ const app = new Vue(extend(option, { render: (h) => h(App) }))
353
+ return extend({ app }, option)
385
354
  }
386
355
 
387
356
  export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el }) {
@@ -45,3 +45,5 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
45
45
  export function hasOwn (obj, key) {
46
46
  return hasOwnProperty.call(obj, key)
47
47
  }
48
+
49
+ export const extend = Object.assign
@@ -4,7 +4,6 @@ const loadPostcssConfig = require('./load-postcss-config')
4
4
  const { MPX_ROOT_VIEW, MPX_DISABLE_EXTRACTOR_CACHE } = require('../utils/const')
5
5
  const rpx = require('./plugins/rpx')
6
6
  const vw = require('./plugins/vw')
7
- const pluginCondStrip = require('./plugins/conditional-strip')
8
7
  const scopeId = require('./plugins/scope-id')
9
8
  const transSpecial = require('./plugins/trans-special')
10
9
  const cssArrayList = require('./plugins/css-array-list')
@@ -58,9 +57,9 @@ module.exports = function (css, map) {
58
57
  plugins.push(transSpecial({ id }))
59
58
  }
60
59
 
61
- plugins.push(pluginCondStrip({
62
- defs
63
- }))
60
+ // plugins.push(pluginCondStrip({
61
+ // defs
62
+ // }))
64
63
 
65
64
  for (const item of transRpxRules) {
66
65
  const {
@@ -1,6 +1,8 @@
1
1
  const selectorParser = require('postcss-selector-parser')
2
2
  // scope-id
3
-
3
+ function isSpaceCombinator (node) {
4
+ return node.type === 'combinator' && /^\s+$/.test(node.value)
5
+ }
4
6
  module.exports = ({ id }) => {
5
7
  return {
6
8
  postcssPlugin: 'scope-id',
@@ -31,10 +33,36 @@ module.exports = ({ id }) => {
31
33
  n.spaces.before = n.spaces.after = ''
32
34
  return false
33
35
  }
36
+ if (n.type === 'pseudo' && n.value === ':deep') {
37
+ if (n.nodes.length) {
38
+ let last = n
39
+ n.nodes[0].each((ss) => {
40
+ selector.insertAfter(last, ss)
41
+ last = ss
42
+ })
43
+ const prev = n.prev()
44
+ if (!prev || !isSpaceCombinator(prev)) {
45
+ selector.insertAfter(
46
+ n,
47
+ selectorParser.combinator({
48
+ value: ' '
49
+ })
50
+ )
51
+ }
52
+ n.remove()
53
+ } else {
54
+ const prev = n.prev()
55
+ if (prev && isSpaceCombinator(prev)) {
56
+ prev.remove()
57
+ }
58
+ n.remove()
59
+ }
60
+ return false
61
+ }
34
62
  // /deep/ alias for >>>, since >>> doesn't work in SASS
35
63
  if (n.type === 'tag' && n.value === '/deep/') {
36
64
  const prev = n.prev()
37
- if (prev && prev.type === 'combinator' && prev.value === ' ') {
65
+ if (prev && isSpaceCombinator(prev)) {
38
66
  prev.remove()
39
67
  }
40
68
  n.remove()
@@ -0,0 +1,118 @@
1
+ const MagicString = require('magic-string')
2
+
3
+ function cssConditionalStrip (cssContent, defs) {
4
+ const ms = new MagicString(cssContent)
5
+
6
+ // 正则匹配 @mpx-if, @mpx-elif, @mpx-else, @mpx-endif 的模式
7
+ const ifPattern = /\/\*\s*@mpx-if\s*\((.*?)\)\s*\*\//gs
8
+ const elifPattern = /\/\*\s*@mpx-elif\s*\((.*?)\)\s*\*\//gs
9
+ const elsePattern = /\/\*\s*@mpx-else\s*\*\//gs
10
+ const endifPattern = /\/\*\s*@mpx-endif\s*\*\//gs
11
+
12
+ function evaluateCondition (condition) {
13
+ // 替换变量
14
+ for (const key in defs) {
15
+ condition = condition.replace(new RegExp(`\\b${key}\\b`, 'g'), JSON.stringify(defs[key]))
16
+ }
17
+
18
+ // 解析条件表达式
19
+ try {
20
+ // eslint-disable-next-line no-new-func
21
+ return Function('"use strict";return (' + condition + ')')()
22
+ } catch (e) {
23
+ throw new Error(`Failed to evaluate condition: ${condition}`)
24
+ }
25
+ }
26
+
27
+ let currentStart = 0
28
+ function processCondition (start, end, condition) {
29
+ const conditionResult = evaluateCondition(condition)
30
+ let hasElse = false
31
+ let elseStart = -1
32
+ let elseLen = 0
33
+ currentStart = end + 1
34
+
35
+ while (currentStart < ms.original.length) {
36
+ elsePattern.lastIndex = currentStart
37
+ const elseMatch = elsePattern.exec(ms.original)
38
+ if (elseMatch) {
39
+ elseLen = elseMatch[0].length
40
+ }
41
+
42
+ ifPattern.lastIndex = currentStart
43
+ const ifMatch = ifPattern.exec(ms.original)
44
+
45
+ elifPattern.lastIndex = currentStart
46
+ const elseIfMatch = elifPattern.exec(ms.original)
47
+
48
+ endifPattern.lastIndex = currentStart
49
+ const endifMatch = endifPattern.exec(ms.original)
50
+
51
+ const nextIf = ifMatch ? ifMatch.index : Infinity
52
+ const nextElseIf = elseIfMatch ? elseIfMatch.index : Infinity
53
+ const nextElse = elseMatch ? elseMatch.index : Infinity
54
+ const nextEndif = endifMatch ? endifMatch.index : Infinity
55
+
56
+ const nextMarker = Math.min(nextIf, nextElseIf, nextElse, nextEndif)
57
+
58
+ if (nextMarker === Infinity) break
59
+
60
+ if (nextMarker === nextElse) {
61
+ // 处理 @mpx-else
62
+ hasElse = true
63
+ elseStart = nextElse
64
+ currentStart = elseMatch.index + elseLen
65
+ ms.remove(elseStart, elseStart + elseLen) // 移除 @mpx-else 注释
66
+ } else if (nextMarker === nextElseIf) {
67
+ // 处理 @mpx-elif
68
+ if (!conditionResult) {
69
+ // 前边的if为false,则直接移除前边代码
70
+ ms.remove(start, nextElseIf)
71
+ }
72
+ currentStart = nextElseIf + elseIfMatch[0].length
73
+ ms.remove(nextElseIf, nextElseIf + elseIfMatch[0].length) // 移除 @mpx-elif 注释
74
+ processCondition(nextElseIf, nextElseIf + elseIfMatch[0].length, elseIfMatch[1])
75
+ } else if (nextMarker === nextIf) {
76
+ // 处理嵌套的 @mpx-if
77
+ // 如果遇到了新的 @mpx-if,则递归处理
78
+ currentStart = nextIf + ifMatch[0].length
79
+ ms.remove(nextIf, nextIf + ifMatch[0].length) // 移除 @mpx-if 注释
80
+ processCondition(nextIf, nextIf + ifMatch[0].length, ifMatch[1])
81
+ } else if (nextMarker === nextEndif) {
82
+ // 处理 @mpx-endif block块
83
+ if (conditionResult && hasElse) {
84
+ // 移除 @mpx-else 至 @mpx-endif 代码
85
+ ms.remove(elseStart, endifMatch.index + endifMatch[0].length)
86
+ } else if (!conditionResult && hasElse) {
87
+ ms.remove(start, elseStart + elseLen)
88
+ } else if (!conditionResult) {
89
+ ms.remove(start, endifMatch.index + endifMatch[0].length)
90
+ }
91
+ ms.remove(endifMatch.index, endifMatch.index + endifMatch[0].length) // 移除 @mpx-endif 注释
92
+ currentStart = endifMatch.index + endifMatch[0].length
93
+ break
94
+ }
95
+ // 兜底更新当前开始位置
96
+ if (currentStart < nextMarker) {
97
+ currentStart = nextMarker + 1
98
+ }
99
+ }
100
+ }
101
+
102
+ let match
103
+ while ((match = ifPattern.exec(ms.original)) !== null) {
104
+ processCondition(match.index, ifPattern.lastIndex, match[1])
105
+ // 移除匹配到的 @mpx-if 注释
106
+ ms.remove(match.index, match.index + match[0].length)
107
+ ifPattern.lastIndex = currentStart
108
+ }
109
+
110
+ return ms.toString()
111
+ }
112
+
113
+ module.exports = function (css) {
114
+ this.cacheable()
115
+ const mpx = this.getMpx()
116
+ const defs = mpx.defs
117
+ return cssConditionalStrip(css, defs)
118
+ }
@@ -264,7 +264,8 @@ module.exports = {
264
264
  transform (code, {
265
265
  needCollect = false,
266
266
  renderReduce = false,
267
- ignoreMap = {}
267
+ ignoreMap = {},
268
+ customBindThis
268
269
  } = {}) {
269
270
  const ast = babylon.parse(code, {
270
271
  plugins: [
@@ -420,7 +421,11 @@ module.exports = {
420
421
  if (isProps) {
421
422
  propKeySet.add(name)
422
423
  }
423
- path.replaceWith(t.memberExpression(t.thisExpression(), path.node))
424
+ if (typeof customBindThis === 'function') {
425
+ customBindThis(path, t)
426
+ } else {
427
+ path.replaceWith(t.memberExpression(t.thisExpression(), path.node))
428
+ }
424
429
  }
425
430
  delete path.needBind
426
431
  }