@mpxjs/webpack-plugin 2.9.69 → 2.9.70
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/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
- package/lib/runtime/components/react/dist/utils.jsx +107 -82
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -188
- package/lib/runtime/components/react/mpx-button.tsx +64 -50
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +55 -65
- package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
- package/lib/runtime/components/react/types/global.d.ts +3 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +113 -82
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +77 -46
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +5 -4
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
|
|
2
2
|
import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
|
|
3
|
-
import { isObject, isFunction, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils'
|
|
3
|
+
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils'
|
|
4
4
|
import { VarContext } from './context'
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser'
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
@@ -10,15 +10,18 @@ import type { AnyFunc, ExtendedFunctionComponent } from './types/common'
|
|
|
10
10
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
|
|
11
11
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/
|
|
12
12
|
export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/
|
|
13
|
+
export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i
|
|
13
14
|
export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/
|
|
14
|
-
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/
|
|
15
|
+
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/
|
|
15
16
|
export const DEFAULT_FONT_SIZE = 16
|
|
16
17
|
export const HIDDEN_STYLE = {
|
|
17
18
|
opacity: 0
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
const varDecRegExp =
|
|
21
|
+
const varDecRegExp = /^--/
|
|
21
22
|
const varUseRegExp = /var\(/
|
|
23
|
+
const unoVarDecRegExp = /^--un-/
|
|
24
|
+
const unoVarUseRegExp = /var\(--un-/
|
|
22
25
|
const calcUseRegExp = /calc\(/
|
|
23
26
|
const envUseRegExp = /env\(/
|
|
24
27
|
|
|
@@ -31,15 +34,12 @@ const safeAreaInsetMap: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {
|
|
|
31
34
|
|
|
32
35
|
function getSafeAreaInset (name: string) {
|
|
33
36
|
const navigation = getFocusedNavigation()
|
|
34
|
-
const insets = {
|
|
35
|
-
...initialWindowMetrics?.insets,
|
|
36
|
-
...navigation?.insets
|
|
37
|
-
}
|
|
37
|
+
const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets)
|
|
38
38
|
return insets[safeAreaInsetMap[name]]
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function omit<T, K extends string> (obj: T, fields: K[]): Omit<T, K> {
|
|
42
|
-
const shallowCopy: any =
|
|
42
|
+
const shallowCopy: any = extendObject({}, obj)
|
|
43
43
|
for (let i = 0; i < fields.length; i += 1) {
|
|
44
44
|
const key = fields[i]
|
|
45
45
|
delete shallowCopy[key]
|
|
@@ -79,7 +79,7 @@ export const parseInlineStyle = (inlineStyle = ''): Record<string, string> => {
|
|
|
79
79
|
const [k, v, ...rest] = style.split(':')
|
|
80
80
|
if (rest.length || !v || !k) return styleObj
|
|
81
81
|
const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase())
|
|
82
|
-
return
|
|
82
|
+
return extendObject(styleObj, { [key]: global.__formatValue(v.trim()) })
|
|
83
83
|
}, {})
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -90,25 +90,18 @@ export const parseUrl = (cssUrl = '') => {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export const getRestProps = (transferProps: any = {}, originProps: any = {}, deletePropsKey: any = []) => {
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
return extendObject(
|
|
94
|
+
{},
|
|
95
|
+
transferProps,
|
|
96
|
+
omit(originProps, deletePropsKey)
|
|
97
|
+
)
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
export function isText (ele: ReactNode): ele is ReactElement {
|
|
100
101
|
if (isValidElement(ele)) {
|
|
101
102
|
const displayName = (ele.type as ExtendedFunctionComponent)?.displayName
|
|
102
103
|
const isCustomText = (ele.type as ExtendedFunctionComponent)?.isCustomText
|
|
103
|
-
return displayName === 'MpxText' || displayName === 'Text' || !!isCustomText
|
|
104
|
-
}
|
|
105
|
-
return false
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function isEmbedded (ele: ReactNode): ele is ReactElement {
|
|
109
|
-
if (isValidElement(ele)) {
|
|
110
|
-
const displayName = (ele.type as ExtendedFunctionComponent)?.displayName || ''
|
|
111
|
-
return ['mpx-checkbox', 'mpx-radio', 'mpx-switch'].includes(displayName)
|
|
104
|
+
return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'Text' || !!isCustomText
|
|
112
105
|
}
|
|
113
106
|
return false
|
|
114
107
|
}
|
|
@@ -276,6 +269,15 @@ function transformCalc (styleObj: Record<string, any>, calcKeyPaths: Array<Array
|
|
|
276
269
|
})
|
|
277
270
|
}
|
|
278
271
|
|
|
272
|
+
const stringifyProps = ['fontWeight']
|
|
273
|
+
function transformStringify (styleObj: Record<string, any>) {
|
|
274
|
+
stringifyProps.forEach((prop) => {
|
|
275
|
+
if (isNumber(styleObj[prop])) {
|
|
276
|
+
styleObj[prop] = '' + styleObj[prop]
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
279
281
|
interface TransformStyleConfig {
|
|
280
282
|
enableVar?: boolean
|
|
281
283
|
externalVarContext?: Record<string, any>
|
|
@@ -286,11 +288,15 @@ interface TransformStyleConfig {
|
|
|
286
288
|
|
|
287
289
|
export function useTransformStyle (styleObj: Record<string, any> = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig) {
|
|
288
290
|
const varStyle: Record<string, any> = {}
|
|
291
|
+
const unoVarStyle: Record<string, any> = {}
|
|
289
292
|
const normalStyle: Record<string, any> = {}
|
|
293
|
+
const normalStyleRef = useRef<Record<string, any>>({})
|
|
294
|
+
const normalStyleChangedRef = useRef(false)
|
|
290
295
|
let hasVarDec = false
|
|
291
296
|
let hasVarUse = false
|
|
292
297
|
let hasSelfPercent = false
|
|
293
298
|
const varKeyPaths: Array<Array<string>> = []
|
|
299
|
+
const unoVarKeyPaths: Array<Array<string>> = []
|
|
294
300
|
const percentKeyPaths: Array<Array<string>> = []
|
|
295
301
|
const calcKeyPaths: Array<Array<string>> = []
|
|
296
302
|
const envKeyPaths: Array<Array<string>> = []
|
|
@@ -299,7 +305,9 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
299
305
|
|
|
300
306
|
function varVisitor ({ key, value, keyPath }: VisitorArg) {
|
|
301
307
|
if (keyPath.length === 1) {
|
|
302
|
-
if (
|
|
308
|
+
if (unoVarDecRegExp.test(key)) {
|
|
309
|
+
unoVarStyle[key] = value
|
|
310
|
+
} else if (varDecRegExp.test(key)) {
|
|
303
311
|
hasVarDec = true
|
|
304
312
|
varStyle[key] = value
|
|
305
313
|
} else {
|
|
@@ -308,25 +316,32 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
308
316
|
}
|
|
309
317
|
}
|
|
310
318
|
// 对于var定义中使用的var无需替换值,可以通过resolveVar递归解析出值
|
|
311
|
-
if (!varDecRegExp.test(key)
|
|
312
|
-
|
|
313
|
-
|
|
319
|
+
if (!varDecRegExp.test(key)) {
|
|
320
|
+
// 一般情况下一个样式属性中不会混用unocss var和普通css var,可分开进行互斥处理
|
|
321
|
+
if (unoVarUseRegExp.test(value)) {
|
|
322
|
+
unoVarKeyPaths.push(keyPath.slice())
|
|
323
|
+
} else if (varUseRegExp.test(value)) {
|
|
324
|
+
hasVarUse = true
|
|
325
|
+
varKeyPaths.push(keyPath.slice())
|
|
326
|
+
}
|
|
314
327
|
}
|
|
315
328
|
}
|
|
316
329
|
|
|
317
|
-
// traverse var
|
|
330
|
+
// traverse var & generate normalStyle
|
|
318
331
|
traverseStyle(styleObj, [varVisitor])
|
|
332
|
+
|
|
319
333
|
hasVarDec = hasVarDec || !!externalVarContext
|
|
320
334
|
enableVar = enableVar || hasVarDec || hasVarUse
|
|
321
335
|
const enableVarRef = useRef(enableVar)
|
|
322
336
|
if (enableVarRef.current !== enableVar) {
|
|
323
337
|
error('css variable use/declare should be stable in the component lifecycle, or you can set [enable-var] with true.')
|
|
324
338
|
}
|
|
325
|
-
// apply var
|
|
339
|
+
// apply css var
|
|
326
340
|
const varContextRef = useRef({})
|
|
327
341
|
if (enableVarRef.current) {
|
|
342
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
328
343
|
const varContext = useContext(VarContext)
|
|
329
|
-
const newVarContext =
|
|
344
|
+
const newVarContext = extendObject({}, varContext, externalVarContext, varStyle)
|
|
330
345
|
// 缓存比较newVarContext是否发生变化
|
|
331
346
|
if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
|
|
332
347
|
varContextRef.current = newVarContext
|
|
@@ -334,68 +349,86 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
334
349
|
transformVar(normalStyle, varKeyPaths, varContextRef.current)
|
|
335
350
|
}
|
|
336
351
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
352
|
+
// apply unocss var
|
|
353
|
+
if (unoVarKeyPaths.length) {
|
|
354
|
+
transformVar(normalStyle, unoVarKeyPaths, unoVarStyle)
|
|
341
355
|
}
|
|
342
356
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
357
|
+
const { clone, diff } = diffAndCloneA(normalStyle, normalStyleRef.current)
|
|
358
|
+
if (diff) {
|
|
359
|
+
normalStyleRef.current = clone
|
|
360
|
+
normalStyleChangedRef.current = !normalStyleChangedRef.current
|
|
347
361
|
}
|
|
348
362
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
363
|
+
const memoResult = useMemo(() => {
|
|
364
|
+
// transform can be memoized
|
|
365
|
+
function envVisitor ({ value, keyPath }: VisitorArg) {
|
|
366
|
+
if (envUseRegExp.test(value)) {
|
|
367
|
+
envKeyPaths.push(keyPath.slice())
|
|
368
|
+
}
|
|
355
369
|
}
|
|
356
|
-
}
|
|
357
370
|
|
|
358
|
-
|
|
359
|
-
|
|
371
|
+
function calcVisitor ({ value, keyPath }: VisitorArg) {
|
|
372
|
+
if (calcUseRegExp.test(value)) {
|
|
373
|
+
calcKeyPaths.push(keyPath.slice())
|
|
374
|
+
}
|
|
375
|
+
}
|
|
360
376
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
377
|
+
function percentVisitor ({ key, value, keyPath }: VisitorArg) {
|
|
378
|
+
if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
379
|
+
hasSelfPercent = true
|
|
380
|
+
percentKeyPaths.push(keyPath.slice())
|
|
381
|
+
} else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
382
|
+
percentKeyPaths.push(keyPath.slice())
|
|
383
|
+
}
|
|
384
|
+
}
|
|
369
385
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
386
|
+
// traverse env & calc & percent
|
|
387
|
+
traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor])
|
|
388
|
+
|
|
389
|
+
const percentConfig = {
|
|
390
|
+
width,
|
|
391
|
+
height,
|
|
392
|
+
fontSize: normalStyle.fontSize,
|
|
393
|
+
parentWidth,
|
|
394
|
+
parentHeight,
|
|
395
|
+
parentFontSize
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// apply env
|
|
399
|
+
transformEnv(normalStyle, envKeyPaths)
|
|
400
|
+
// apply percent
|
|
401
|
+
transformPercent(normalStyle, percentKeyPaths, percentConfig)
|
|
402
|
+
// apply calc
|
|
403
|
+
transformCalc(normalStyle, calcKeyPaths, (value: string, key: string) => {
|
|
404
|
+
if (PERCENT_REGEX.test(value)) {
|
|
405
|
+
const resolved = resolvePercent(value, key, percentConfig)
|
|
406
|
+
return typeof resolved === 'number' ? resolved : 0
|
|
383
407
|
} else {
|
|
384
|
-
|
|
385
|
-
|
|
408
|
+
const formatted = global.__formatValue(value)
|
|
409
|
+
if (typeof formatted === 'number') {
|
|
410
|
+
return formatted
|
|
411
|
+
} else {
|
|
412
|
+
warn('calc() only support number, px, rpx, % temporarily.')
|
|
413
|
+
return 0
|
|
414
|
+
}
|
|
386
415
|
}
|
|
416
|
+
})
|
|
417
|
+
// transform number enum stringify
|
|
418
|
+
transformStringify(normalStyle)
|
|
419
|
+
|
|
420
|
+
return {
|
|
421
|
+
normalStyle,
|
|
422
|
+
hasSelfPercent
|
|
387
423
|
}
|
|
388
|
-
})
|
|
424
|
+
}, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize])
|
|
389
425
|
|
|
390
|
-
return {
|
|
391
|
-
normalStyle,
|
|
392
|
-
hasSelfPercent,
|
|
426
|
+
return extendObject({
|
|
393
427
|
hasVarDec,
|
|
394
|
-
enableVarRef,
|
|
395
428
|
varContextRef,
|
|
396
429
|
setWidth,
|
|
397
430
|
setHeight
|
|
398
|
-
}
|
|
431
|
+
}, memoResult)
|
|
399
432
|
}
|
|
400
433
|
|
|
401
434
|
export interface VisitorArg {
|
|
@@ -475,7 +508,7 @@ interface LayoutConfig {
|
|
|
475
508
|
export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }: LayoutConfig) => {
|
|
476
509
|
const layoutRef = useRef({})
|
|
477
510
|
const hasLayoutRef = useRef(false)
|
|
478
|
-
const layoutStyle
|
|
511
|
+
const layoutStyle = useMemo(() => { return !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {} }, [hasLayoutRef.current])
|
|
479
512
|
const layoutProps: Record<string, any> = {}
|
|
480
513
|
const enableOffset = props['enable-offset']
|
|
481
514
|
if (hasSelfPercent || onLayout || enableOffset) {
|
|
@@ -514,8 +547,8 @@ export function wrapChildren (props: Record<string, any> = {}, { hasVarDec, varC
|
|
|
514
547
|
if (textStyle || textProps) {
|
|
515
548
|
children = Children.map(children, (child) => {
|
|
516
549
|
if (isText(child)) {
|
|
517
|
-
const style = {
|
|
518
|
-
return cloneElement(child, {
|
|
550
|
+
const style = extendObject({}, textStyle, child.props.style)
|
|
551
|
+
return cloneElement(child, extendObject({}, textProps, { style }))
|
|
519
552
|
}
|
|
520
553
|
return child
|
|
521
554
|
})
|
|
@@ -563,7 +596,7 @@ export const useStableCallback = <T extends AnyFunc | null | undefined> (
|
|
|
563
596
|
}
|
|
564
597
|
|
|
565
598
|
export const usePrevious = <T, > (value: T): T | undefined => {
|
|
566
|
-
const ref = useRef<T | undefined>(
|
|
599
|
+
const ref = useRef<T | undefined>()
|
|
567
600
|
const prev = ref.current
|
|
568
601
|
ref.current = value
|
|
569
602
|
return prev
|
|
@@ -584,9 +617,7 @@ export function flatGesture (gestures: Array<GestureHandler> = []) {
|
|
|
584
617
|
})) || []
|
|
585
618
|
}
|
|
586
619
|
|
|
587
|
-
export
|
|
588
|
-
return Object.assign({}, ...args)
|
|
589
|
-
}
|
|
620
|
+
export const extendObject = Object.assign
|
|
590
621
|
|
|
591
622
|
export function getCurrentPage (pageId: number | null) {
|
|
592
623
|
if (!global.getCurrentPages) return
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { extend } from '../../utils'
|
|
1
2
|
function processModel (listeners, context) {
|
|
2
3
|
// 该函数只有wx:model的情况下才调用,而且默认e.detail.value有值
|
|
3
4
|
// 该函数必须在产生merge前执行
|
|
@@ -53,7 +54,7 @@ export function extendEvent (e, extendObj = {}) {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
export function inheritEvent (type, oe, detail = {}) {
|
|
56
|
-
detail =
|
|
57
|
+
detail = extend({}, oe.detail, detail)
|
|
57
58
|
const ne = getCustomEvent(type, detail)
|
|
58
59
|
extendEvent(ne, {
|
|
59
60
|
timeStamp: oe.timeStamp,
|
|
@@ -68,12 +69,11 @@ export function inheritEvent (type, oe, detail = {}) {
|
|
|
68
69
|
export function getCustomEvent (type, detail = {}, target = null) {
|
|
69
70
|
const targetEl = (target && target.$el) || null
|
|
70
71
|
const targetInfo = targetEl ? { target: targetEl, currentTarget: targetEl } : {}
|
|
71
|
-
return {
|
|
72
|
+
return extend({
|
|
72
73
|
type,
|
|
73
74
|
detail,
|
|
74
|
-
timeStamp: new Date().valueOf()
|
|
75
|
-
|
|
76
|
-
}
|
|
75
|
+
timeStamp: new Date().valueOf()
|
|
76
|
+
}, targetInfo)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function noop () {
|
|
@@ -82,7 +82,7 @@ function noop () {
|
|
|
82
82
|
|
|
83
83
|
export default function getInnerListeners (context, options = {}) {
|
|
84
84
|
let { mergeBefore = {}, mergeAfter = {}, defaultListeners = [], ignoredListeners = [] } = options
|
|
85
|
-
const listeners =
|
|
85
|
+
const listeners = extend({}, context.$listeners)
|
|
86
86
|
defaultListeners.forEach((key) => {
|
|
87
87
|
if (!listeners[key]) listeners[key] = noop
|
|
88
88
|
})
|