@mpxjs/webpack-plugin 2.9.17 → 2.9.19-react.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.
- package/lib/config.js +59 -97
- package/lib/dependencies/ResolveDependency.js +2 -2
- package/lib/helpers.js +5 -1
- package/lib/index.js +27 -19
- package/lib/loader.js +56 -118
- package/lib/native-loader.js +43 -20
- package/lib/platform/index.js +3 -0
- package/lib/platform/style/wx/index.js +413 -0
- package/lib/platform/template/wx/component-config/button.js +36 -0
- package/lib/platform/template/wx/component-config/cover-view.js +1 -1
- package/lib/platform/template/wx/component-config/image.js +15 -0
- package/lib/platform/template/wx/component-config/input.js +36 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +27 -1
- package/lib/platform/template/wx/component-config/swiper-item.js +13 -1
- package/lib/platform/template/wx/component-config/swiper.js +25 -1
- package/lib/platform/template/wx/component-config/text.js +17 -1
- package/lib/platform/template/wx/component-config/textarea.js +39 -0
- package/lib/platform/template/wx/component-config/unsupported.js +18 -0
- package/lib/platform/template/wx/component-config/view.js +15 -1
- package/lib/platform/template/wx/index.js +89 -7
- package/lib/react/index.js +92 -0
- package/lib/react/processJSON.js +362 -0
- package/lib/react/processScript.js +40 -0
- package/lib/react/processStyles.js +63 -0
- package/lib/react/processTemplate.js +151 -0
- package/lib/react/script-helper.js +79 -0
- package/lib/react/style-helper.js +91 -0
- package/lib/runtime/components/react/event.config.ts +32 -0
- package/lib/runtime/components/react/getInnerListeners.ts +289 -0
- package/lib/runtime/components/react/getInnerListeners.type.ts +68 -0
- package/lib/runtime/components/react/mpx-button.tsx +402 -0
- package/lib/runtime/components/react/mpx-image/index.tsx +351 -0
- package/lib/runtime/components/react/mpx-image/svg.tsx +21 -0
- package/lib/runtime/components/react/mpx-input.tsx +389 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +412 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +407 -0
- package/lib/runtime/components/react/mpx-swiper/index.tsx +68 -0
- package/lib/runtime/components/react/mpx-swiper/type.ts +69 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -0
- package/lib/runtime/components/react/mpx-text.tsx +106 -0
- package/lib/runtime/components/react/mpx-textarea.tsx +46 -0
- package/lib/runtime/components/react/mpx-view.tsx +397 -0
- package/lib/runtime/components/react/utils.ts +92 -0
- package/lib/runtime/components/web/event.js +100 -0
- package/lib/runtime/components/web/getInnerListeners.js +0 -78
- package/lib/runtime/components/web/mpx-button.vue +1 -1
- package/lib/runtime/components/web/mpx-navigator.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +113 -37
- package/lib/runtime/oc.wxs +16 -0
- package/lib/runtime/optionProcessor.js +1 -1
- package/lib/runtime/stringify.wxs +3 -7
- package/lib/runtime/useNodesRef.ts +39 -0
- package/lib/style-compiler/index.js +2 -1
- package/lib/template-compiler/compiler.js +544 -121
- package/lib/template-compiler/gen-node-react.js +95 -0
- package/lib/template-compiler/index.js +19 -31
- package/lib/utils/env.js +17 -0
- package/lib/utils/make-map.js +1 -1
- package/lib/utils/shallow-stringify.js +17 -0
- package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -1
- package/lib/web/index.js +122 -0
- package/lib/web/processMainScript.js +6 -4
- package/lib/web/processScript.js +9 -5
- package/lib/web/processTemplate.js +14 -14
- package/lib/web/script-helper.js +11 -19
- package/package.json +7 -3
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { isEmptyObject } from '../../utils'
|
|
2
|
-
import { isBrowser } from '../../env'
|
|
3
|
-
|
|
4
1
|
function processModel (listeners, context) {
|
|
5
2
|
// 该函数只有wx:model的情况下才调用,而且默认e.detail.value有值
|
|
6
3
|
// 该函数必须在产生merge前执行
|
|
@@ -44,80 +41,6 @@ function mergeListeners (listeners, otherListeners, options = {}) {
|
|
|
44
41
|
})
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
function processTap (listeners, context) {
|
|
48
|
-
const listenerMap = {}
|
|
49
|
-
const tapEvents = ['tap', 'longpress', 'longtap']
|
|
50
|
-
const isTouchDevice = isBrowser ? document && ('ontouchstart' in document.documentElement) : true
|
|
51
|
-
tapEvents.forEach((eventName) => {
|
|
52
|
-
if (listeners[eventName]) {
|
|
53
|
-
listenerMap[eventName] = true
|
|
54
|
-
delete listeners[eventName]
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
if (isEmptyObject(listenerMap)) return
|
|
58
|
-
context.__mpxTapInfo = context.__mpxTapInfo || {}
|
|
59
|
-
let events
|
|
60
|
-
if (isTouchDevice) {
|
|
61
|
-
events = {
|
|
62
|
-
touchstart (e) {
|
|
63
|
-
context.__mpxTapInfo.detail = {
|
|
64
|
-
x: e.changedTouches[0].pageX,
|
|
65
|
-
y: e.changedTouches[0].pageY
|
|
66
|
-
}
|
|
67
|
-
context.__mpxTapInfo.startTimer = null
|
|
68
|
-
context.__mpxTapInfo.needTap = true
|
|
69
|
-
if (listenerMap.longpress || listenerMap.longtap) {
|
|
70
|
-
context.__mpxTapInfo.startTimer = setTimeout(() => {
|
|
71
|
-
context.__mpxTapInfo.needTap = false
|
|
72
|
-
if (listenerMap.longpress) {
|
|
73
|
-
const re = inheritEvent('longpress', e, context.__mpxTapInfo.detail)
|
|
74
|
-
context.$emit('longpress', re)
|
|
75
|
-
}
|
|
76
|
-
if (listenerMap.longtap) {
|
|
77
|
-
const re = inheritEvent('longtap', e, context.__mpxTapInfo.detail)
|
|
78
|
-
context.$emit('longtap', re)
|
|
79
|
-
}
|
|
80
|
-
}, 350)
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
touchmove (e) {
|
|
84
|
-
const tapDetailInfo = context.__mpxTapInfo.detail || {}
|
|
85
|
-
const currentPageX = e.changedTouches[0].pageX
|
|
86
|
-
const currentPageY = e.changedTouches[0].pageY
|
|
87
|
-
if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
|
|
88
|
-
context.__mpxTapInfo.needTap = false
|
|
89
|
-
context.__mpxTapInfo.startTimer && clearTimeout(context.__mpxTapInfo.startTimer)
|
|
90
|
-
context.__mpxTapInfo.startTimer = null
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
touchend (e) {
|
|
94
|
-
context.__mpxTapInfo.startTimer && clearTimeout(context.__mpxTapInfo.startTimer)
|
|
95
|
-
if (listenerMap.tap && context.__mpxTapInfo.needTap) {
|
|
96
|
-
const re = inheritEvent('tap', e, context.__mpxTapInfo.detail)
|
|
97
|
-
context.$emit('tap', re)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
events = {
|
|
103
|
-
click (e) {
|
|
104
|
-
if (listenerMap.tap) {
|
|
105
|
-
context.__mpxTapInfo.detail = {
|
|
106
|
-
x: e.pageX,
|
|
107
|
-
y: e.pageY
|
|
108
|
-
}
|
|
109
|
-
const re = inheritEvent('tap', e, context.__mpxTapInfo.detail)
|
|
110
|
-
context.$emit('tap', re)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
mergeListeners(listeners, events, {
|
|
117
|
-
force: true
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
|
|
121
44
|
export function extendEvent (e, extendObj = {}) {
|
|
122
45
|
Object.keys(extendObj).forEach((key) => {
|
|
123
46
|
Object.defineProperty(e, key, {
|
|
@@ -181,7 +104,6 @@ export default function getInnerListeners (context, options = {}) {
|
|
|
181
104
|
}
|
|
182
105
|
|
|
183
106
|
processModel(listeners, context)
|
|
184
|
-
processTap(listeners, context)
|
|
185
107
|
mergeListeners(listeners, mergeBefore, mergeBeforeOptions)
|
|
186
108
|
mergeListeners(listeners, mergeAfter, mergeAfterOptions)
|
|
187
109
|
ignoredListeners.forEach((key) => {
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import { processSize } from '../../utils'
|
|
4
4
|
import BScroll from '@better-scroll/core'
|
|
5
5
|
import PullDown from '@better-scroll/pull-down'
|
|
6
|
-
import ObserveDom from '@better-scroll/observe-dom'
|
|
7
6
|
import throttle from 'lodash/throttle'
|
|
7
|
+
import debounce from 'lodash/debounce'
|
|
8
8
|
|
|
9
|
-
BScroll.use(ObserveDom)
|
|
10
9
|
BScroll.use(PullDown)
|
|
11
10
|
|
|
11
|
+
let mutationObserver = null
|
|
12
|
+
|
|
12
13
|
export default {
|
|
13
14
|
name: 'mpx-scroll-view',
|
|
14
15
|
props: {
|
|
@@ -36,10 +37,6 @@
|
|
|
36
37
|
return {}
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
|
-
updateRefresh: {
|
|
40
|
-
type: Boolean,
|
|
41
|
-
default: true
|
|
42
|
-
},
|
|
43
40
|
scrollIntoView: String,
|
|
44
41
|
scrollWithAnimation: Boolean,
|
|
45
42
|
enableFlex: Boolean,
|
|
@@ -66,7 +63,11 @@
|
|
|
66
63
|
currentX: 0,
|
|
67
64
|
currentY: 0,
|
|
68
65
|
lastX: 0,
|
|
69
|
-
lastY: 0
|
|
66
|
+
lastY: 0,
|
|
67
|
+
lastContentWidth: 0,
|
|
68
|
+
lastContentHeight: 0,
|
|
69
|
+
lastWrapperWidth: 0,
|
|
70
|
+
lastWrapperHeight: 0
|
|
70
71
|
}
|
|
71
72
|
},
|
|
72
73
|
computed: {
|
|
@@ -101,12 +102,28 @@
|
|
|
101
102
|
}
|
|
102
103
|
return className
|
|
103
104
|
},
|
|
104
|
-
scroll() {
|
|
105
|
+
scroll () {
|
|
105
106
|
return this.scrollX || this.scrollY
|
|
106
107
|
}
|
|
107
108
|
},
|
|
108
109
|
mounted () {
|
|
110
|
+
this.debounceRefresh = debounce(function () {
|
|
111
|
+
this.refresh()
|
|
112
|
+
}, 200, {
|
|
113
|
+
leading: false,
|
|
114
|
+
trailing: true
|
|
115
|
+
})
|
|
116
|
+
this.dispatchScrollTo = throttle(function (direction) {
|
|
117
|
+
let eventName = 'scrolltoupper'
|
|
118
|
+
if (direction === 'bottom' || direction === 'right') eventName = 'scrolltolower'
|
|
119
|
+
this.$emit(eventName, getCustomEvent(eventName, { direction }, this))
|
|
120
|
+
}, 200, {
|
|
121
|
+
leading: true,
|
|
122
|
+
trailing: false
|
|
123
|
+
})
|
|
109
124
|
this.initBs()
|
|
125
|
+
this.observeAnimation('add')
|
|
126
|
+
this.handleMutationObserver()
|
|
110
127
|
},
|
|
111
128
|
activated () {
|
|
112
129
|
if (!this.__mpx_deactivated) {
|
|
@@ -121,11 +138,11 @@
|
|
|
121
138
|
deactivated () {
|
|
122
139
|
this.__mpx_deactivated = true
|
|
123
140
|
},
|
|
141
|
+
|
|
124
142
|
beforeDestroy () {
|
|
125
143
|
this.destroyBs()
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (this.updateRefresh) this.refresh()
|
|
144
|
+
this.observeAnimation('remove')
|
|
145
|
+
this.destroyMutationObserver()
|
|
129
146
|
},
|
|
130
147
|
watch: {
|
|
131
148
|
scrollIntoView (val) {
|
|
@@ -153,7 +170,7 @@
|
|
|
153
170
|
}
|
|
154
171
|
},
|
|
155
172
|
},
|
|
156
|
-
scroll(val) {
|
|
173
|
+
scroll (val) {
|
|
157
174
|
if (val) {
|
|
158
175
|
this.initBs()
|
|
159
176
|
} else {
|
|
@@ -162,12 +179,19 @@
|
|
|
162
179
|
}
|
|
163
180
|
},
|
|
164
181
|
methods: {
|
|
182
|
+
observeAnimation (type) {
|
|
183
|
+
const eventNames = ['transitionend', 'animationend']
|
|
184
|
+
const behaviorType = type === 'add' ? 'addEventListener' : 'removeEventListener'
|
|
185
|
+
eventNames.forEach(eventName => {
|
|
186
|
+
this.$refs.scrollContent?.[behaviorType](eventName, this.handleObserveAnimation)
|
|
187
|
+
})
|
|
188
|
+
},
|
|
165
189
|
destroyBs () {
|
|
166
190
|
if (!this.bs) return
|
|
167
191
|
this.bs.destroy()
|
|
168
192
|
delete this.bs
|
|
169
193
|
},
|
|
170
|
-
disableBs() {
|
|
194
|
+
disableBs () {
|
|
171
195
|
if (!this.bs) return
|
|
172
196
|
this.bs.disable()
|
|
173
197
|
this.currentX = -this.bs.x
|
|
@@ -176,6 +200,9 @@
|
|
|
176
200
|
initBs () {
|
|
177
201
|
this.destroyBs()
|
|
178
202
|
this.initLayerComputed()
|
|
203
|
+
if (this.scrollOptions.observeDOM) {
|
|
204
|
+
console.warn('[Mpx runtime warn]The observeDOM attribute in scroll-view has been deprecated, please stop using it')
|
|
205
|
+
}
|
|
179
206
|
const originBsOptions = {
|
|
180
207
|
startX: -this.currentX,
|
|
181
208
|
startY: -this.currentY,
|
|
@@ -194,11 +221,8 @@
|
|
|
194
221
|
stop: 56
|
|
195
222
|
}
|
|
196
223
|
}
|
|
197
|
-
const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions)
|
|
224
|
+
const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions, { observeDOM: false })
|
|
198
225
|
this.bs = new BScroll(this.$refs.wrapper, bsOptions)
|
|
199
|
-
this.bs.scroller.hooks.on('beforeRefresh', () => {
|
|
200
|
-
this.initLayerComputed()
|
|
201
|
-
})
|
|
202
226
|
this.lastX = -this.currentX
|
|
203
227
|
this.lastY = -this.currentY
|
|
204
228
|
this.bs.on('scroll', throttle(({ x, y }) => {
|
|
@@ -283,6 +307,7 @@
|
|
|
283
307
|
}
|
|
284
308
|
}
|
|
285
309
|
})
|
|
310
|
+
|
|
286
311
|
this.bs.on('pullingDown', () => {
|
|
287
312
|
this.$emit('refresherrefresh', getCustomEvent('refresherrefresh', {}, this))
|
|
288
313
|
})
|
|
@@ -297,13 +322,17 @@
|
|
|
297
322
|
},
|
|
298
323
|
initLayerComputed () {
|
|
299
324
|
const wrapper = this.$refs.wrapper
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
325
|
+
const scrollWrapperWidth = wrapper?.clientWidth || 0
|
|
326
|
+
const scrollWrapperHeight = wrapper?.clientHeight || 0
|
|
327
|
+
if (wrapper) {
|
|
328
|
+
const computedStyle = getComputedStyle(wrapper)
|
|
329
|
+
// 考虑子元素样式可能会设置100%,如果直接继承 scrollContent 的样式可能会有问题
|
|
330
|
+
// 所以使用 wrapper 作为 innerWrapper 的宽高参考依据
|
|
331
|
+
this.$refs.innerWrapper.style.width = `${scrollWrapperWidth - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight)}px`
|
|
332
|
+
this.$refs.innerWrapper.style.height = `${scrollWrapperHeight - parseInt(computedStyle.paddingTop) - parseInt(computedStyle.paddingBottom)}px`
|
|
333
|
+
}
|
|
305
334
|
const innerWrapper = this.$refs.innerWrapper
|
|
306
|
-
const childrenArr = Array.from(innerWrapper.children)
|
|
335
|
+
const childrenArr = innerWrapper ? Array.from(innerWrapper.children) : []
|
|
307
336
|
|
|
308
337
|
const getMinLength = (min, value) => {
|
|
309
338
|
if (min === undefined) {
|
|
@@ -334,27 +363,72 @@
|
|
|
334
363
|
maxRight = getMaxLength(maxRight, temp.right)
|
|
335
364
|
maxBottom = getMaxLength(maxBottom, temp.bottom)
|
|
336
365
|
})
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
366
|
+
const width = maxRight - minLeft || 0
|
|
367
|
+
const height = maxBottom - minTop || 0
|
|
368
|
+
if (this.$refs.scrollContent) {
|
|
369
|
+
this.$refs.scrollContent.style.width = `${width}px`
|
|
370
|
+
this.$refs.scrollContent.style.height = `${height}px`
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
scrollContentWidth: width,
|
|
374
|
+
scrollContentHeight: height,
|
|
375
|
+
scrollWrapperWidth,
|
|
376
|
+
scrollWrapperHeight
|
|
377
|
+
}
|
|
342
378
|
},
|
|
343
379
|
refresh () {
|
|
344
380
|
if (this.__mpx_deactivated) {
|
|
345
381
|
this.__mpx_deactivated_refresh = true
|
|
346
382
|
return
|
|
347
383
|
}
|
|
348
|
-
|
|
384
|
+
const { scrollContentWidth, scrollContentHeight, scrollWrapperWidth, scrollWrapperHeight} = this.initLayerComputed()
|
|
385
|
+
if (!this.compare(scrollWrapperWidth, this.lastWrapperWidth) || !this.compare(scrollWrapperHeight, this.lastWrapperHeight) || !this.compare(scrollContentWidth, this.lastContentWidth) || !this.compare(scrollContentHeight, this.lastContentHeight)) {
|
|
386
|
+
this.lastContentWidth = scrollContentWidth
|
|
387
|
+
this.lastContentHeight = scrollContentHeight
|
|
388
|
+
this.lastWrapperWidth = scrollWrapperWidth
|
|
389
|
+
this.lastWrapperHeight = scrollWrapperHeight
|
|
390
|
+
if (this.bs) this.bs.refresh()
|
|
391
|
+
}
|
|
349
392
|
},
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
393
|
+
compare(num1, num2, scale = 1) {
|
|
394
|
+
return Math.abs(num1 - num2) < scale
|
|
395
|
+
},
|
|
396
|
+
handleMutationObserver () {
|
|
397
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
398
|
+
mutationObserver = new MutationObserver((mutations) => this.mutationObserverHandler(mutations))
|
|
399
|
+
const config = { attributes: true, childList: true, subtree: true }
|
|
400
|
+
mutationObserver.observe(this.$refs.wrapper, config)
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
mutationObserverHandler (mutations) {
|
|
404
|
+
let needRefresh = false
|
|
405
|
+
for (let i = 0; i < mutations.length; i++) {
|
|
406
|
+
const mutation = mutations[i]
|
|
407
|
+
if (mutation.type !== 'attributes') {
|
|
408
|
+
needRefresh = true
|
|
409
|
+
break
|
|
410
|
+
} else {
|
|
411
|
+
if (mutation.target !== this.$refs.scrollContent && mutation.target !== this.$refs.innerWrapper) {
|
|
412
|
+
needRefresh = true
|
|
413
|
+
break
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (needRefresh) {
|
|
418
|
+
this.debounceRefresh()
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
handleObserveAnimation (e) {
|
|
422
|
+
if (e.target !== this.$refs.scrollContent) {
|
|
423
|
+
this.debounceRefresh()
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
destroyMutationObserver () {
|
|
427
|
+
if (mutationObserver) {
|
|
428
|
+
mutationObserver.disconnect()
|
|
429
|
+
mutationObserver = null
|
|
430
|
+
}
|
|
431
|
+
}
|
|
358
432
|
},
|
|
359
433
|
render (createElement) {
|
|
360
434
|
const data = {
|
|
@@ -418,11 +492,13 @@
|
|
|
418
492
|
bottom: 20px
|
|
419
493
|
left: 50%
|
|
420
494
|
transform: translateX(-50%)
|
|
495
|
+
|
|
421
496
|
.mpx-pull-down-slot
|
|
422
497
|
position: absolute
|
|
423
498
|
width: 100%
|
|
424
499
|
height: auto
|
|
425
500
|
bottom: 0
|
|
501
|
+
|
|
426
502
|
.mpx-pull-down-content-black
|
|
427
503
|
.circle
|
|
428
504
|
display: inline-block;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// 可选链wxs
|
|
2
|
+
module.exports.g = function (val, valKeyArr) {
|
|
3
|
+
var res = val
|
|
4
|
+
if (typeof val !== 'object') {
|
|
5
|
+
return undefined
|
|
6
|
+
}
|
|
7
|
+
var len = valKeyArr.length
|
|
8
|
+
var i = 0
|
|
9
|
+
while (i < len) {
|
|
10
|
+
if ((res = res[valKeyArr[i]]) === undefined) {
|
|
11
|
+
break
|
|
12
|
+
}
|
|
13
|
+
i++
|
|
14
|
+
}
|
|
15
|
+
return res
|
|
16
|
+
}
|
|
@@ -86,7 +86,7 @@ export function getComponent (component, extendOptions) {
|
|
|
86
86
|
export function getWxsMixin (wxsModules) {
|
|
87
87
|
if (!wxsModules || !Object.keys(wxsModules).length) return
|
|
88
88
|
return {
|
|
89
|
-
|
|
89
|
+
beforeCreate () {
|
|
90
90
|
Object.keys(wxsModules).forEach((key) => {
|
|
91
91
|
if (key in this) {
|
|
92
92
|
console.error(`[Mpx runtime error]: The wxs module key [${key}] exist in the component/page instance already, please check and rename it!`)
|
|
@@ -90,10 +90,6 @@ function isArray (arr) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
function isDef (v) {
|
|
94
|
-
return v !== undefined && v !== null
|
|
95
|
-
}
|
|
96
|
-
|
|
97
93
|
var escapeMap = {
|
|
98
94
|
'(': '_pl_',
|
|
99
95
|
')': '_pr_',
|
|
@@ -145,11 +141,11 @@ function stringifyDynamicClass (value) {
|
|
|
145
141
|
|
|
146
142
|
function stringifyArray (value) {
|
|
147
143
|
var res = ''
|
|
148
|
-
var
|
|
144
|
+
var classString
|
|
149
145
|
for (var i = 0; i < value.length; i++) {
|
|
150
|
-
if (
|
|
146
|
+
if ((classString = stringifyDynamicClass(value[i]))) {
|
|
151
147
|
if (res) res += ' '
|
|
152
|
-
res +=
|
|
148
|
+
res += classString
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
151
|
return res
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useRef, useEffect, useImperativeHandle, RefObject, ForwardedRef } from 'react'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
type Obj = Record<string, any>
|
|
5
|
+
|
|
6
|
+
export type HandlerRef<T, P> = {
|
|
7
|
+
getNodeInstance(): {
|
|
8
|
+
props: RefObject<P>,
|
|
9
|
+
nodeRef: RefObject<T>,
|
|
10
|
+
instance: Obj
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function useNodesRef<T, P>(props: P, ref: ForwardedRef<HandlerRef<T, P>>, instance:Obj = {} ) {
|
|
15
|
+
const nodeRef = useRef<T>(null)
|
|
16
|
+
const _props = useRef<P | null>(props)
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
_props.current = props
|
|
20
|
+
return () => {
|
|
21
|
+
_props.current = null // 组件销毁,清空 _props 依赖数据
|
|
22
|
+
}
|
|
23
|
+
}, [props])
|
|
24
|
+
useImperativeHandle(ref, () => {
|
|
25
|
+
return {
|
|
26
|
+
getNodeInstance () {
|
|
27
|
+
return {
|
|
28
|
+
props: _props,
|
|
29
|
+
nodeRef,
|
|
30
|
+
instance
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
nodeRef
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -9,6 +9,7 @@ const scopeId = require('./plugins/scope-id')
|
|
|
9
9
|
const transSpecial = require('./plugins/trans-special')
|
|
10
10
|
const { matchCondition } = require('../utils/match-condition')
|
|
11
11
|
const parseRequest = require('../utils/parse-request')
|
|
12
|
+
const isReact = require('../utils/env').isReact
|
|
12
13
|
|
|
13
14
|
module.exports = function (css, map) {
|
|
14
15
|
this.cacheable()
|
|
@@ -47,7 +48,7 @@ module.exports = function (css, map) {
|
|
|
47
48
|
plugins.push(transSpecial({ id }))
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
if (mode === 'web') {
|
|
51
|
+
if (mode === 'web' || isReact(mode)) {
|
|
51
52
|
plugins.push(transSpecial({ id }))
|
|
52
53
|
}
|
|
53
54
|
|