@mpxjs/core 2.10.17-unocss.1 → 2.10.18-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.
package/@types/index.d.ts
CHANGED
|
@@ -115,7 +115,7 @@ interface Context {
|
|
|
115
115
|
refs: ObjectOf<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>
|
|
116
116
|
asyncRefs: ObjectOf<Promise<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>>
|
|
117
117
|
|
|
118
|
-
forceUpdate (
|
|
118
|
+
forceUpdate (data?: object): void
|
|
119
119
|
|
|
120
120
|
selectComponent: ReplaceWxComponentIns['selectComponent']
|
|
121
121
|
selectAllComponents: ReplaceWxComponentIns['selectAllComponents']
|
|
@@ -204,7 +204,7 @@ export interface MpxComponentIns {
|
|
|
204
204
|
|
|
205
205
|
$watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
|
|
206
206
|
|
|
207
|
-
$forceUpdate (
|
|
207
|
+
$forceUpdate (data?: object): void
|
|
208
208
|
|
|
209
209
|
$nextTick (fn: () => void): void
|
|
210
210
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.18-beta.1",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mpxjs/utils": "^2.10.
|
|
22
|
+
"@mpxjs/utils": "^2.10.18",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.10.0"
|
|
25
25
|
},
|
|
@@ -101,6 +101,35 @@ function formatValue (value, unitType) {
|
|
|
101
101
|
|
|
102
102
|
global.__formatValue = formatValue
|
|
103
103
|
|
|
104
|
+
const escapeReg = /[()[\]{}#!.:,%'"+$]/g
|
|
105
|
+
const escapeMap = {
|
|
106
|
+
'(': '_pl_',
|
|
107
|
+
')': '_pr_',
|
|
108
|
+
'[': '_bl_',
|
|
109
|
+
']': '_br_',
|
|
110
|
+
'{': '_cl_',
|
|
111
|
+
'}': '_cr_',
|
|
112
|
+
'#': '_h_',
|
|
113
|
+
'!': '_i_',
|
|
114
|
+
'/': '_s_',
|
|
115
|
+
'.': '_d_',
|
|
116
|
+
':': '_c_',
|
|
117
|
+
',': '_2c_',
|
|
118
|
+
'%': '_p_',
|
|
119
|
+
'\'': '_q_',
|
|
120
|
+
'"': '_dq_',
|
|
121
|
+
'+': '_a_',
|
|
122
|
+
$: '_si_'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const mpEscape = cached((str) => {
|
|
126
|
+
return str.replace(escapeReg, function (match) {
|
|
127
|
+
if (escapeMap[match]) return escapeMap[match]
|
|
128
|
+
// unknown escaped
|
|
129
|
+
return '_u_'
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
104
133
|
function concat (a = '', b = '') {
|
|
105
134
|
return a ? b ? (a + ' ' + b) : a : b
|
|
106
135
|
}
|
|
@@ -215,58 +244,6 @@ function getMediaStyle (media) {
|
|
|
215
244
|
}, {})
|
|
216
245
|
}
|
|
217
246
|
|
|
218
|
-
const createLayer = (isNativeStyle) => {
|
|
219
|
-
const layerMap = {
|
|
220
|
-
preflight: isNativeStyle ? [] : {},
|
|
221
|
-
app: isNativeStyle ? [] : {},
|
|
222
|
-
uno: isNativeStyle ? [] : {},
|
|
223
|
-
normal: isNativeStyle ? [] : {},
|
|
224
|
-
important: isNativeStyle ? [] : {}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const genResult = () => {
|
|
228
|
-
if (isNativeStyle) {
|
|
229
|
-
return [
|
|
230
|
-
...layerMap.preflight,
|
|
231
|
-
...layerMap.app,
|
|
232
|
-
...layerMap.uno,
|
|
233
|
-
...layerMap.normal,
|
|
234
|
-
...layerMap.important
|
|
235
|
-
]
|
|
236
|
-
} else {
|
|
237
|
-
return Object.assign({}, layerMap.preflight, layerMap.app, layerMap.uno, layerMap.normal, layerMap.important)
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const mergeToLayer = (name, ...classObjs) => {
|
|
242
|
-
const layer = layerMap[name] || layerMap.normal
|
|
243
|
-
return isNativeStyle ? layer.push(...classObjs) : Object.assign(layer, ...classObjs)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
mergeToLayer,
|
|
248
|
-
layerMap,
|
|
249
|
-
genResult
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const HIDE_STYLE = {
|
|
254
|
-
// display: 'none'
|
|
255
|
-
// RN下display:'none'容易引发未知异常问题,使用布局样式模拟
|
|
256
|
-
flex: 0,
|
|
257
|
-
height: 0,
|
|
258
|
-
width: 0,
|
|
259
|
-
paddingTop: 0,
|
|
260
|
-
paddingRight: 0,
|
|
261
|
-
paddingBottom: 0,
|
|
262
|
-
paddingLeft: 0,
|
|
263
|
-
marginTop: 0,
|
|
264
|
-
marginRight: 0,
|
|
265
|
-
marginBottom: 0,
|
|
266
|
-
marginLeft: 0,
|
|
267
|
-
overflow: 'hidden'
|
|
268
|
-
}
|
|
269
|
-
|
|
270
247
|
export default function styleHelperMixin () {
|
|
271
248
|
return {
|
|
272
249
|
methods: {
|
|
@@ -278,73 +255,70 @@ export default function styleHelperMixin () {
|
|
|
278
255
|
},
|
|
279
256
|
__getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, hide) {
|
|
280
257
|
const isNativeStaticStyle = staticStyle && isNativeStyle(staticStyle)
|
|
258
|
+
let result = isNativeStaticStyle ? [] : {}
|
|
259
|
+
const mergeResult = isNativeStaticStyle ? (...args) => result.push(...args) : (...args) => Object.assign(result, ...args)
|
|
281
260
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.__getSizeCount()
|
|
261
|
+
this.__getSizeCount()
|
|
285
262
|
|
|
286
263
|
if (staticClass || dynamicClass) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
let needAddUnoPreflight = false
|
|
264
|
+
// todo 当前为了复用小程序unocss产物,暂时进行mpEscape,等后续正式支持unocss后可不进行mpEscape
|
|
265
|
+
const classString = mpEscape(concat(staticClass, stringifyDynamicClass(dynamicClass)))
|
|
290
266
|
|
|
291
267
|
classString.split(/\s+/).forEach((className) => {
|
|
292
|
-
let localStyle, appStyle
|
|
268
|
+
let localStyle, appStyle
|
|
293
269
|
if (localStyle = this.__getClassStyle?.(className)) {
|
|
294
270
|
if (localStyle._media?.length) {
|
|
295
|
-
|
|
271
|
+
mergeResult(localStyle._default, getMediaStyle(localStyle._media))
|
|
296
272
|
} else {
|
|
297
|
-
|
|
273
|
+
mergeResult(localStyle)
|
|
298
274
|
}
|
|
299
|
-
} else if (unoStyle = global.__getUnoStyle(className)) {
|
|
300
|
-
if (unoStyle._media?.length) {
|
|
301
|
-
mergeToLayer(unoStyle.__layer || 'uno', unoStyle._default, getMediaStyle(unoStyle._media))
|
|
302
|
-
} else {
|
|
303
|
-
mergeToLayer(unoStyle.__layer || 'uno', unoStyle)
|
|
304
|
-
}
|
|
305
|
-
if (unoStyle.transform || unoStyle.filter) needAddUnoPreflight = true
|
|
306
|
-
} else if (unoVarStyle = global.__getUnoVarStyle(className)) {
|
|
307
|
-
mergeToLayer('important', unoVarStyle)
|
|
308
275
|
} else if (appStyle = global.__getAppClassStyle?.(className)) {
|
|
309
276
|
if (appStyle._media?.length) {
|
|
310
|
-
|
|
277
|
+
mergeResult(appStyle._default, getMediaStyle(appStyle._media))
|
|
311
278
|
} else {
|
|
312
|
-
|
|
279
|
+
mergeResult(appStyle)
|
|
313
280
|
}
|
|
314
281
|
} else if (isObject(this.__props[className])) {
|
|
315
282
|
// externalClasses必定以对象形式传递下来
|
|
316
|
-
|
|
283
|
+
mergeResult(this.__props[className])
|
|
317
284
|
}
|
|
318
285
|
})
|
|
319
|
-
|
|
320
|
-
if (needAddUnoPreflight) {
|
|
321
|
-
mergeToLayer('preflight', global.__getAppClassStyle?.('__uno_preflight'))
|
|
322
|
-
}
|
|
323
286
|
}
|
|
324
287
|
|
|
325
288
|
if (staticStyle || dynamicStyle) {
|
|
326
289
|
const styleObj = {}
|
|
327
290
|
if (isNativeStaticStyle) {
|
|
328
291
|
if (Array.isArray(staticStyle)) {
|
|
329
|
-
|
|
292
|
+
result = result.concat(staticStyle)
|
|
330
293
|
} else {
|
|
331
|
-
|
|
294
|
+
mergeResult(staticStyle)
|
|
332
295
|
}
|
|
333
296
|
} else {
|
|
334
297
|
Object.assign(styleObj, parseStyleText(staticStyle))
|
|
335
298
|
}
|
|
336
299
|
Object.assign(styleObj, normalizeDynamicStyle(dynamicStyle))
|
|
337
|
-
|
|
300
|
+
mergeResult(transformStyleObj(styleObj))
|
|
338
301
|
}
|
|
339
302
|
|
|
340
303
|
if (hide) {
|
|
341
|
-
|
|
304
|
+
mergeResult({
|
|
305
|
+
// display: 'none'
|
|
306
|
+
// RN下display:'none'容易引发未知异常问题,使用布局样式模拟
|
|
307
|
+
flex: 0,
|
|
308
|
+
height: 0,
|
|
309
|
+
width: 0,
|
|
310
|
+
paddingTop: 0,
|
|
311
|
+
paddingRight: 0,
|
|
312
|
+
paddingBottom: 0,
|
|
313
|
+
paddingLeft: 0,
|
|
314
|
+
marginTop: 0,
|
|
315
|
+
marginRight: 0,
|
|
316
|
+
marginBottom: 0,
|
|
317
|
+
marginLeft: 0,
|
|
318
|
+
overflow: 'hidden'
|
|
319
|
+
})
|
|
342
320
|
}
|
|
343
|
-
|
|
344
|
-
const result = genResult()
|
|
345
|
-
|
|
346
321
|
const isEmpty = isNativeStaticStyle ? !result.length : isEmptyObject(result)
|
|
347
|
-
|
|
348
322
|
return isEmpty ? empty : result
|
|
349
323
|
}
|
|
350
324
|
}
|
|
@@ -76,7 +76,6 @@ export default function createApp (options) {
|
|
|
76
76
|
return createElement(Stack.Screen, {
|
|
77
77
|
name: key,
|
|
78
78
|
getComponent,
|
|
79
|
-
initialParams,
|
|
80
79
|
layout: headerLayout
|
|
81
80
|
})
|
|
82
81
|
}
|
|
@@ -211,6 +210,10 @@ export default function createApp (options) {
|
|
|
211
210
|
}, [])
|
|
212
211
|
|
|
213
212
|
const { initialRouteName, initialParams } = initialRouteRef.current
|
|
213
|
+
if (!global.__mpxAppHotLaunched) {
|
|
214
|
+
global.__mpxInitialRouteName = initialRouteName
|
|
215
|
+
global.__mpxInitialRunParams = initialParams
|
|
216
|
+
}
|
|
214
217
|
const navScreenOpts = {
|
|
215
218
|
headerShown: false,
|
|
216
219
|
statusBarTranslucent: Mpx.config.rnConfig.statusBarTranslucent ?? true,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context'
|
|
18
18
|
import { PortalHost, useSafeAreaInsets, initialWindowMetrics } from '../env/navigationHelper'
|
|
19
19
|
import { useInnerHeaderHeight } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-nav'
|
|
20
|
+
import Mpx from '../../index'
|
|
20
21
|
|
|
21
22
|
function getSystemInfo () {
|
|
22
23
|
const windowDimensions = global.__mpxAppDimensionsInfo.window
|
|
@@ -294,13 +295,17 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
294
295
|
instance[key] = method.bind(instance)
|
|
295
296
|
})
|
|
296
297
|
}
|
|
297
|
-
|
|
298
|
+
const loadParams = {}
|
|
298
299
|
if (type === 'page') {
|
|
299
300
|
const props = propsRef.current
|
|
300
301
|
instance.route = props.route.name
|
|
301
302
|
global.__mpxPagesMap = global.__mpxPagesMap || {}
|
|
302
303
|
global.__mpxPagesMap[props.route.key] = [instance, props.navigation]
|
|
303
304
|
setFocusedNavigation(props.navigation)
|
|
305
|
+
|
|
306
|
+
if (!global.__mpxAppHotLaunched && global.__mpxInitialRunParams) {
|
|
307
|
+
Object.assign(loadParams, global.__mpxInitialRunParams)
|
|
308
|
+
}
|
|
304
309
|
set(global.__mpxPageSizeCountMap, pageId, global.__mpxSizeCount)
|
|
305
310
|
// App onLaunch 在 Page created 之前执行
|
|
306
311
|
if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
|
|
@@ -310,11 +315,10 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
310
315
|
|
|
311
316
|
const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
|
|
312
317
|
proxy.created()
|
|
313
|
-
|
|
314
318
|
if (type === 'page') {
|
|
315
319
|
const props = propsRef.current
|
|
316
320
|
const decodedQuery = {}
|
|
317
|
-
const rawQuery = props.route.params || {}
|
|
321
|
+
const rawQuery = Object.assign({}, loadParams, props.route.params || {})
|
|
318
322
|
if (isObject(rawQuery)) {
|
|
319
323
|
for (const key in rawQuery) {
|
|
320
324
|
decodedQuery[key] = decodeURIComponent(rawQuery[key])
|
|
@@ -397,7 +401,7 @@ const triggerResizeEvent = (mpxProxy, sizeRef) => {
|
|
|
397
401
|
}
|
|
398
402
|
}
|
|
399
403
|
|
|
400
|
-
function usePageEffect (mpxProxy, pageId) {
|
|
404
|
+
function usePageEffect (mpxProxy, pageId, type) {
|
|
401
405
|
const sizeRef = useRef(getSystemInfo())
|
|
402
406
|
|
|
403
407
|
useEffect(() => {
|
|
@@ -414,7 +418,7 @@ function usePageEffect (mpxProxy, pageId) {
|
|
|
414
418
|
triggerResizeEvent(mpxProxy, sizeRef)
|
|
415
419
|
|
|
416
420
|
// 如果当前全局size与pagesize不一致,在show之后触发一次resize事件
|
|
417
|
-
if (newVal === 'show' && global.__mpxPageSizeCountMap[pageId] !== global.__mpxSizeCount) {
|
|
421
|
+
if (type === 'page' && newVal === 'show' && global.__mpxPageSizeCountMap[pageId] !== global.__mpxSizeCount) {
|
|
418
422
|
// 刷新__mpxPageSizeCountMap, 每个页面仅会执行一次,直接驱动render刷新
|
|
419
423
|
global.__mpxPageSizeCountMap[pageId] = global.__mpxSizeCount
|
|
420
424
|
}
|
|
@@ -426,7 +430,9 @@ function usePageEffect (mpxProxy, pageId) {
|
|
|
426
430
|
}
|
|
427
431
|
return () => {
|
|
428
432
|
unWatch && unWatch()
|
|
429
|
-
|
|
433
|
+
if (type === 'page') {
|
|
434
|
+
del(global.__mpxPageSizeCountMap, pageId)
|
|
435
|
+
}
|
|
430
436
|
}
|
|
431
437
|
}, [])
|
|
432
438
|
}
|
|
@@ -613,6 +619,20 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
|
|
|
613
619
|
)
|
|
614
620
|
}
|
|
615
621
|
}
|
|
622
|
+
|
|
623
|
+
function updateProps (instance, props, validProps) {
|
|
624
|
+
Object.keys(validProps).forEach((key) => {
|
|
625
|
+
if (hasOwn(props, key)) {
|
|
626
|
+
instance[key] = props[key]
|
|
627
|
+
} else {
|
|
628
|
+
const altKey = hump2dash(key)
|
|
629
|
+
if (hasOwn(props, altKey)) {
|
|
630
|
+
instance[key] = props[altKey]
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
})
|
|
634
|
+
}
|
|
635
|
+
|
|
616
636
|
export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
617
637
|
rawOptions = mergeOptions(rawOptions, type, false)
|
|
618
638
|
const componentsMap = currentInject.componentsMap
|
|
@@ -665,16 +685,14 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
665
685
|
|
|
666
686
|
if (!isFirst) {
|
|
667
687
|
// 处理props更新
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
})
|
|
688
|
+
if (Mpx.config.forceFlushSync) {
|
|
689
|
+
// 避免开启forceFlushSync时react报错:Cannot update a component while rendering a different component
|
|
690
|
+
Promise.resolve().then(() => {
|
|
691
|
+
updateProps(instance, props, validProps)
|
|
692
|
+
})
|
|
693
|
+
} else {
|
|
694
|
+
updateProps(instance, props, validProps)
|
|
695
|
+
}
|
|
678
696
|
}
|
|
679
697
|
|
|
680
698
|
useEffect(() => {
|
|
@@ -684,7 +702,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
684
702
|
}
|
|
685
703
|
})
|
|
686
704
|
|
|
687
|
-
usePageEffect(proxy, pageId)
|
|
705
|
+
usePageEffect(proxy, pageId, type)
|
|
688
706
|
useEffect(() => {
|
|
689
707
|
proxy.mounted()
|
|
690
708
|
return () => {
|