@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.
- package/lib/index.js +30 -9
- 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/canvas.js +8 -0
- 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/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- 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/processStyles.js +14 -4
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolver/AddEnvPlugin.js +1 -0
- package/lib/resolver/AddModePlugin.js +9 -8
- package/lib/runtime/components/react/context.ts +14 -0
- package/lib/runtime/components/react/dist/context.js +4 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
- package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- 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 +14 -14
- 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-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
- 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 +62 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
- 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 +67 -94
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
- package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
- package/lib/runtime/components/react/dist/utils.jsx +129 -24
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -202
- package/lib/runtime/components/react/mpx-button.tsx +104 -57
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- 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 +22 -26
- 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-item.tsx +88 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
- package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
- 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 +115 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
- package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
- 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 +93 -117
- package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
- package/lib/runtime/components/react/pickerFaces.ts +112 -0
- package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +7 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
- package/lib/runtime/components/react/utils.tsx +169 -29
- 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/index.js +3 -4
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/style-compiler/strip-conditional-loader.js +118 -0
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +66 -39
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/package.json +6 -4
- package/LICENSE +0 -433
- 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/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- 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/react/mpx-swiper/carouse.tsx +0 -525
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import { useEffect, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
|
|
2
|
-
import { LayoutChangeEvent, TextStyle } from 'react-native'
|
|
3
|
-
import { isObject, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils'
|
|
4
|
-
import { VarContext } from './context'
|
|
1
|
+
import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
|
|
2
|
+
import { LayoutChangeEvent, TextStyle, ImageProps, Image, Platform } from 'react-native'
|
|
3
|
+
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils'
|
|
4
|
+
import { VarContext, ScrollViewContext } from './context'
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser'
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
7
|
-
import
|
|
7
|
+
import FastImage, { FastImageProps } from '@d11/react-native-fast-image'
|
|
8
|
+
import type { AnyFunc, ExtendedFunctionComponent, ExtendedViewStyle } from './types/common'
|
|
9
|
+
import { runOnJS } from 'react-native-reanimated'
|
|
10
|
+
import { Gesture } from 'react-native-gesture-handler'
|
|
8
11
|
|
|
9
12
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
|
|
10
13
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/
|
|
11
14
|
export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/
|
|
15
|
+
export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i
|
|
12
16
|
export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/
|
|
13
|
-
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/
|
|
17
|
+
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/
|
|
14
18
|
export const DEFAULT_FONT_SIZE = 16
|
|
15
19
|
export const HIDDEN_STYLE = {
|
|
16
20
|
opacity: 0
|
|
17
21
|
}
|
|
18
22
|
|
|
23
|
+
export const isIOS = Platform.OS === 'ios'
|
|
24
|
+
export const isAndroid = Platform.OS === 'android'
|
|
25
|
+
|
|
19
26
|
const varDecRegExp = /^--.*/
|
|
20
27
|
const varUseRegExp = /var\(/
|
|
21
28
|
const calcUseRegExp = /calc\(/
|
|
@@ -30,10 +37,7 @@ const safeAreaInsetMap: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {
|
|
|
30
37
|
|
|
31
38
|
function getSafeAreaInset (name: string) {
|
|
32
39
|
const navigation = getFocusedNavigation()
|
|
33
|
-
const insets = {
|
|
34
|
-
...initialWindowMetrics?.insets,
|
|
35
|
-
...navigation?.insets
|
|
36
|
-
}
|
|
40
|
+
const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets)
|
|
37
41
|
return insets[safeAreaInsetMap[name]]
|
|
38
42
|
}
|
|
39
43
|
|
|
@@ -78,7 +82,7 @@ export const parseInlineStyle = (inlineStyle = ''): Record<string, string> => {
|
|
|
78
82
|
const [k, v, ...rest] = style.split(':')
|
|
79
83
|
if (rest.length || !v || !k) return styleObj
|
|
80
84
|
const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase())
|
|
81
|
-
return Object.assign(styleObj, { [key]: v.trim() })
|
|
85
|
+
return Object.assign(styleObj, { [key]: global.__formatValue(v.trim()) })
|
|
82
86
|
}, {})
|
|
83
87
|
}
|
|
84
88
|
|
|
@@ -89,25 +93,18 @@ export const parseUrl = (cssUrl = '') => {
|
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
export const getRestProps = (transferProps: any = {}, originProps: any = {}, deletePropsKey: any = []) => {
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
return extendObject(
|
|
97
|
+
{},
|
|
98
|
+
transferProps,
|
|
99
|
+
omit(originProps, deletePropsKey)
|
|
100
|
+
)
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
export function isText (ele: ReactNode): ele is ReactElement {
|
|
99
104
|
if (isValidElement(ele)) {
|
|
100
105
|
const displayName = (ele.type as ExtendedFunctionComponent)?.displayName
|
|
101
106
|
const isCustomText = (ele.type as ExtendedFunctionComponent)?.isCustomText
|
|
102
|
-
return displayName === 'MpxText' || displayName === 'Text' || !!isCustomText
|
|
103
|
-
}
|
|
104
|
-
return false
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function isEmbedded (ele: ReactNode): ele is ReactElement {
|
|
108
|
-
if (isValidElement(ele)) {
|
|
109
|
-
const displayName = (ele.type as ExtendedFunctionComponent)?.displayName || ''
|
|
110
|
-
return ['mpx-checkbox', 'mpx-radio', 'mpx-switch'].includes(displayName)
|
|
107
|
+
return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'Text' || !!isCustomText
|
|
111
108
|
}
|
|
112
109
|
return false
|
|
113
110
|
}
|
|
@@ -275,6 +272,15 @@ function transformCalc (styleObj: Record<string, any>, calcKeyPaths: Array<Array
|
|
|
275
272
|
})
|
|
276
273
|
}
|
|
277
274
|
|
|
275
|
+
const stringifyProps = ['fontWeight']
|
|
276
|
+
function transformStringify (styleObj: Record<string, any>) {
|
|
277
|
+
stringifyProps.forEach((prop) => {
|
|
278
|
+
if (isNumber(styleObj[prop])) {
|
|
279
|
+
styleObj[prop] = '' + styleObj[prop]
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
278
284
|
interface TransformStyleConfig {
|
|
279
285
|
enableVar?: boolean
|
|
280
286
|
externalVarContext?: Record<string, any>
|
|
@@ -385,6 +391,8 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
385
391
|
}
|
|
386
392
|
}
|
|
387
393
|
})
|
|
394
|
+
// transform number enum stringify
|
|
395
|
+
transformStringify(normalStyle)
|
|
388
396
|
|
|
389
397
|
return {
|
|
390
398
|
normalStyle,
|
|
@@ -474,7 +482,7 @@ interface LayoutConfig {
|
|
|
474
482
|
export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }: LayoutConfig) => {
|
|
475
483
|
const layoutRef = useRef({})
|
|
476
484
|
const hasLayoutRef = useRef(false)
|
|
477
|
-
const layoutStyle
|
|
485
|
+
const layoutStyle = useMemo(() => { return !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {} }, [hasLayoutRef.current])
|
|
478
486
|
const layoutProps: Record<string, any> = {}
|
|
479
487
|
const enableOffset = props['enable-offset']
|
|
480
488
|
if (hasSelfPercent || onLayout || enableOffset) {
|
|
@@ -494,6 +502,7 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
|
|
|
494
502
|
props.onLayout && props.onLayout(e)
|
|
495
503
|
}
|
|
496
504
|
}
|
|
505
|
+
|
|
497
506
|
return {
|
|
498
507
|
layoutRef,
|
|
499
508
|
layoutStyle,
|
|
@@ -513,8 +522,8 @@ export function wrapChildren (props: Record<string, any> = {}, { hasVarDec, varC
|
|
|
513
522
|
if (textStyle || textProps) {
|
|
514
523
|
children = Children.map(children, (child) => {
|
|
515
524
|
if (isText(child)) {
|
|
516
|
-
const style = {
|
|
517
|
-
return cloneElement(child, {
|
|
525
|
+
const style = extendObject({}, textStyle, child.props.style)
|
|
526
|
+
return cloneElement(child, extendObject({}, textProps, { style }))
|
|
518
527
|
}
|
|
519
528
|
return child
|
|
520
529
|
})
|
|
@@ -525,9 +534,52 @@ export function wrapChildren (props: Record<string, any> = {}, { hasVarDec, varC
|
|
|
525
534
|
return children
|
|
526
535
|
}
|
|
527
536
|
|
|
537
|
+
export const debounce = <T extends AnyFunc> (
|
|
538
|
+
func: T,
|
|
539
|
+
delay: number
|
|
540
|
+
): ((...args: Parameters<T>) => void) & { clear: () => void } => {
|
|
541
|
+
let timer: any
|
|
542
|
+
const wrapper = (...args: ReadonlyArray<any>) => {
|
|
543
|
+
clearTimeout(timer)
|
|
544
|
+
timer = setTimeout(() => {
|
|
545
|
+
func(...args)
|
|
546
|
+
}, delay)
|
|
547
|
+
}
|
|
548
|
+
wrapper.clear = () => {
|
|
549
|
+
clearTimeout(timer)
|
|
550
|
+
}
|
|
551
|
+
return wrapper
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export const useDebounceCallback = <T extends AnyFunc> (
|
|
555
|
+
func: T,
|
|
556
|
+
delay: number
|
|
557
|
+
): ((...args: Parameters<T>) => void) & { clear: () => void } => {
|
|
558
|
+
const debounced = useMemo(() => debounce(func, delay), [func])
|
|
559
|
+
return debounced
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export const useStableCallback = <T extends AnyFunc | null | undefined> (
|
|
563
|
+
callback: T
|
|
564
|
+
): T extends AnyFunc ? T : () => void => {
|
|
565
|
+
const ref = useRef<T>(callback)
|
|
566
|
+
ref.current = callback
|
|
567
|
+
return useCallback<any>(
|
|
568
|
+
(...args: any[]) => ref.current?.(...args),
|
|
569
|
+
[]
|
|
570
|
+
)
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export const usePrevious = <T, > (value: T): T | undefined => {
|
|
574
|
+
const ref = useRef<T | undefined>(undefined)
|
|
575
|
+
const prev = ref.current
|
|
576
|
+
ref.current = value
|
|
577
|
+
return prev
|
|
578
|
+
}
|
|
579
|
+
|
|
528
580
|
export interface GestureHandler {
|
|
529
|
-
nodeRefs?: Array<{ getNodeInstance: () => { nodeRef: unknown } }
|
|
530
|
-
current?: unknown
|
|
581
|
+
nodeRefs?: Array<{ getNodeInstance: () => { nodeRef: unknown } }>
|
|
582
|
+
current?: unknown
|
|
531
583
|
}
|
|
532
584
|
|
|
533
585
|
export function flatGesture (gestures: Array<GestureHandler> = []) {
|
|
@@ -539,3 +591,91 @@ export function flatGesture (gestures: Array<GestureHandler> = []) {
|
|
|
539
591
|
return gesture?.current ? [gesture] : []
|
|
540
592
|
})) || []
|
|
541
593
|
}
|
|
594
|
+
|
|
595
|
+
export const extendObject = Object.assign
|
|
596
|
+
|
|
597
|
+
export function getCurrentPage (pageId: number | null) {
|
|
598
|
+
if (!global.getCurrentPages) return
|
|
599
|
+
const pages = global.getCurrentPages()
|
|
600
|
+
return pages.find((page: any) => isFunction(page.getPageId) && page.getPageId() === pageId)
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function renderImage (
|
|
604
|
+
imageProps: ImageProps | FastImageProps,
|
|
605
|
+
enableFastImage = false
|
|
606
|
+
) {
|
|
607
|
+
const Component: React.ComponentType<ImageProps | FastImageProps> = enableFastImage ? FastImage : Image
|
|
608
|
+
return <Component {...imageProps} />
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export function pickStyle (styleObj: Record<string, any> = {}, pickedKeys: Array<string>, callback?: (key: string, val: number | string) => number | string) {
|
|
612
|
+
return pickedKeys.reduce<Record<string, any>>((acc, key) => {
|
|
613
|
+
if (key in styleObj) {
|
|
614
|
+
acc[key] = callback ? callback(key, styleObj[key]) : styleObj[key]
|
|
615
|
+
}
|
|
616
|
+
return acc
|
|
617
|
+
}, {})
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export function useHoverStyle ({ hoverStyle, hoverStartTime, hoverStayTime, disabled } : { hoverStyle?: ExtendedViewStyle, hoverStartTime: number, hoverStayTime: number, disabled?: boolean }) {
|
|
621
|
+
const enableHoverStyle = !!hoverStyle
|
|
622
|
+
const enableHoverStyleRef = useRef(enableHoverStyle)
|
|
623
|
+
if (enableHoverStyleRef.current !== enableHoverStyle) {
|
|
624
|
+
throw new Error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.')
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (!enableHoverStyle) return { enableHoverStyle }
|
|
628
|
+
|
|
629
|
+
const gestureRef = useContext(ScrollViewContext).gestureRef
|
|
630
|
+
const [isHover, setIsHover] = useState(false)
|
|
631
|
+
const dataRef = useRef<{
|
|
632
|
+
startTimer?: ReturnType<typeof setTimeout>
|
|
633
|
+
stayTimer?: ReturnType<typeof setTimeout>
|
|
634
|
+
}>({})
|
|
635
|
+
|
|
636
|
+
useEffect(() => {
|
|
637
|
+
return () => {
|
|
638
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
639
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
|
|
640
|
+
}
|
|
641
|
+
}, [])
|
|
642
|
+
|
|
643
|
+
const setStartTimer = () => {
|
|
644
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
645
|
+
dataRef.current.startTimer = setTimeout(() => {
|
|
646
|
+
setIsHover(true)
|
|
647
|
+
}, +hoverStartTime)
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const setStayTimer = () => {
|
|
651
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
|
|
652
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
653
|
+
dataRef.current.stayTimer = setTimeout(() => {
|
|
654
|
+
setIsHover(false)
|
|
655
|
+
}, +hoverStayTime)
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const gesture = useMemo(() => {
|
|
659
|
+
return Gesture.Pan()
|
|
660
|
+
.onTouchesDown(() => {
|
|
661
|
+
'worklet'
|
|
662
|
+
if (disabled) return
|
|
663
|
+
runOnJS(setStartTimer)()
|
|
664
|
+
})
|
|
665
|
+
.onTouchesUp(() => {
|
|
666
|
+
'worklet'
|
|
667
|
+
if (disabled) return
|
|
668
|
+
runOnJS(setStayTimer)()
|
|
669
|
+
})
|
|
670
|
+
}, [disabled])
|
|
671
|
+
|
|
672
|
+
if (gestureRef) {
|
|
673
|
+
gesture.simultaneousWithExternalGesture(gestureRef)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return {
|
|
677
|
+
isHover,
|
|
678
|
+
gesture,
|
|
679
|
+
enableHoverStyle
|
|
680
|
+
}
|
|
681
|
+
}
|
|
@@ -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
|
})
|