@mpxjs/webpack-plugin 2.9.67 → 2.9.69

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 (48) hide show
  1. package/lib/index.js +13 -8
  2. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  3. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  4. package/lib/react/processStyles.js +14 -4
  5. package/lib/resolver/AddModePlugin.js +8 -8
  6. package/lib/runtime/components/react/context.ts +2 -0
  7. package/lib/runtime/components/react/dist/context.js +1 -0
  8. package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
  9. package/lib/runtime/components/react/dist/mpx-button.jsx +43 -8
  10. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  11. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  12. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  13. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  14. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  15. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  16. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  17. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
  18. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  19. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
  20. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
  21. package/lib/runtime/components/react/dist/mpx-view.jsx +45 -26
  22. package/lib/runtime/components/react/dist/mpx-web-view.jsx +19 -5
  23. package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
  24. package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
  25. package/lib/runtime/components/react/dist/utils.jsx +54 -3
  26. package/lib/runtime/components/react/getInnerListeners.ts +3 -17
  27. package/lib/runtime/components/react/mpx-button.tsx +41 -8
  28. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  29. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  30. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  31. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  32. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  33. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  34. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  35. package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
  36. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  37. package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
  38. package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
  39. package/lib/runtime/components/react/mpx-view.tsx +57 -27
  40. package/lib/runtime/components/react/mpx-web-view.tsx +22 -5
  41. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  42. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  43. package/lib/runtime/components/react/types/common.ts +2 -0
  44. package/lib/runtime/components/react/types/global.d.ts +2 -0
  45. package/lib/runtime/components/react/utils.tsx +78 -7
  46. package/lib/template-compiler/compiler.js +3 -2
  47. package/lib/template-compiler/gen-node-react.js +2 -2
  48. package/package.json +5 -4
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Borrowed from open-source code: https://github.com/quidone/react-native-wheel-picker
3
+ * Special thanks to the authors for their contribution to the open-source community.
4
+ */
5
+
6
+ export type Faces = {
7
+ index: number
8
+ deg: number
9
+ offsetY: number
10
+ opacity: number
11
+ screenHeight: number
12
+ }
13
+
14
+ export const degToRad = (deg: number) => (Math.PI * deg) / 180
15
+
16
+ // Calculates the height of the element after rotating it relative to the user's screen.
17
+ const calcHeight = (degree: number, itemHeight: number) =>
18
+ itemHeight * Math.cos(degToRad(degree))
19
+
20
+ export const calcPickerHeight = (faces: Faces[], itemHeight: number) => {
21
+ if (faces.length === 7) {
22
+ return itemHeight * 5
23
+ }
24
+ return faces.reduce((r, v) => r + calcHeight(Math.abs(v.deg), itemHeight), 0)
25
+ }
26
+
27
+ export const createFaces = (
28
+ itemHeight: number,
29
+ visibleCount: number
30
+ ): Faces[] => {
31
+ // e.g [30, 60, 90]
32
+ const getDegreesRelativeCenter = () => {
33
+ const maxStep = Math.trunc((visibleCount + 2) / 2) // + 2 because there are 2 more faces at 90 degrees
34
+ const stepDegree = 90 / maxStep
35
+
36
+ const result = []
37
+ for (let i = 1; i <= maxStep; i++) {
38
+ result.push(i * stepDegree)
39
+ }
40
+ return result
41
+ }
42
+
43
+ const getScreenHeightsAndOffsets = <T extends readonly number[]>(
44
+ degrees: T
45
+ ): [T, T] => {
46
+ const screenHeights = degrees.map((deg) =>
47
+ calcHeight(deg, itemHeight)
48
+ ) as unknown as T
49
+ const freeSpaces = screenHeights.map(
50
+ (screenHeight) => itemHeight - screenHeight
51
+ )
52
+ const offsets = freeSpaces.map((freeSpace, index) => {
53
+ let offset = freeSpace / 2
54
+ for (let i = 0; i < index; i++) {
55
+ offset += freeSpaces[i]
56
+ }
57
+ return offset
58
+ }) as unknown as T
59
+ return [screenHeights, offsets]
60
+ }
61
+
62
+ const getOpacity = (index: number) => {
63
+ const map: Record<number, number> = {
64
+ 0: 0,
65
+ 1: 0.2,
66
+ 2: 0.35,
67
+ 3: 0.45,
68
+ 4: 0.5
69
+ }
70
+ return map[index] ?? Math.min(1, map[4] + index * 0.5)
71
+ }
72
+
73
+ const degrees = getDegreesRelativeCenter()
74
+ const [screenHeight, offsets] = getScreenHeightsAndOffsets(degrees)
75
+
76
+ return [
77
+ // top items
78
+ ...degrees
79
+ .map<Faces>((degree, index) => {
80
+ return {
81
+ index: -1 * (index + 1),
82
+ deg: degree,
83
+ opacity: getOpacity(degrees.length - 1 - index),
84
+ offsetY: -1 * offsets[index],
85
+ screenHeight: screenHeight[index]
86
+ }
87
+ })
88
+ .reverse(),
89
+
90
+ // center item
91
+ { index: 0, deg: 0, opacity: 1, offsetY: 0, screenHeight: itemHeight },
92
+
93
+ // bottom items
94
+ ...degrees.map<Faces>((degree, index) => {
95
+ return {
96
+ index: index + 1,
97
+ deg: -1 * degree,
98
+ opacity: getOpacity(degrees.length - 1 - index),
99
+ offsetY: offsets[index],
100
+ screenHeight: screenHeight[index]
101
+ }
102
+ })
103
+ ]
104
+ }
@@ -0,0 +1,32 @@
1
+ import React from 'react'
2
+ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
3
+
4
+ type OverlayProps = {
5
+ itemHeight: number
6
+ overlayItemStyle?: StyleProp<ViewStyle>
7
+ overlayContainerStyle?: StyleProp<ViewStyle>
8
+ }
9
+
10
+ const Overlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }: OverlayProps) => {
11
+ return (
12
+ <View style={[styles.overlayContainer, overlayContainerStyle]} pointerEvents={'none'}>
13
+ <View style={[styles.selection, { height: itemHeight }, overlayItemStyle]} />
14
+ </View>
15
+ )
16
+ }
17
+
18
+ const styles = StyleSheet.create({
19
+ overlayContainer: {
20
+ ...StyleSheet.absoluteFillObject,
21
+ justifyContent: 'center',
22
+ alignItems: 'center'
23
+ },
24
+ selection: {
25
+ borderTopWidth: 1,
26
+ borderBottomWidth: 1,
27
+ borderColor: 'rgba(0, 0, 0, 0.05)',
28
+ alignSelf: 'stretch'
29
+ }
30
+ })
31
+
32
+ export default React.memo(Overlay)
@@ -16,3 +16,5 @@ export type ExtendedViewStyle = ViewStyle & {
16
16
  export type ExtendedFunctionComponent = FunctionComponent & {
17
17
  isCustomText?: boolean
18
18
  }
19
+
20
+ export type AnyFunc = (...args: ReadonlyArray<any>) => any
@@ -16,6 +16,7 @@ declare module 'react-native-svg/css' {
16
16
 
17
17
  declare module '@mpxjs/utils' {
18
18
  export function isEmptyObject (obj: Object): boolean
19
+ export function isFunction (fn: unknown): boolean
19
20
  export function hasOwn (obj: Object, key: string): boolean
20
21
  export function noop (...arg: any): void
21
22
  export function diffAndCloneA<A, B> (a: A, b?: B): {
@@ -26,6 +27,7 @@ declare module '@mpxjs/utils' {
26
27
  export function isObject (value): value is Object
27
28
  export function error (msg: string, location?: string, e?: any): void
28
29
  export function warn (msg: string, location?: string, e?: any): void
30
+ export function collectDataset (props: Record<string, any>, needParse?: boolean): Record<string, any>
29
31
  export function getFocusedNavigation (): {
30
32
  insets: {
31
33
  top: number
@@ -1,10 +1,11 @@
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'
1
+ import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
2
+ import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
3
+ import { isObject, isFunction, 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'
7
- import type { ExtendedFunctionComponent } from './types/common'
7
+ import FastImage, { FastImageProps } from '@d11/react-native-fast-image'
8
+ import type { AnyFunc, ExtendedFunctionComponent } from './types/common'
8
9
 
9
10
  export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
10
11
  export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/
@@ -78,7 +79,7 @@ export const parseInlineStyle = (inlineStyle = ''): Record<string, string> => {
78
79
  const [k, v, ...rest] = style.split(':')
79
80
  if (rest.length || !v || !k) return styleObj
80
81
  const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase())
81
- return Object.assign(styleObj, { [key]: v.trim() })
82
+ return Object.assign(styleObj, { [key]: global.__formatValue(v.trim()) })
82
83
  }, {})
83
84
  }
84
85
 
@@ -525,9 +526,52 @@ export function wrapChildren (props: Record<string, any> = {}, { hasVarDec, varC
525
526
  return children
526
527
  }
527
528
 
529
+ export const debounce = <T extends AnyFunc> (
530
+ func: T,
531
+ delay: number
532
+ ): ((...args: Parameters<T>) => void) & { clear: () => void } => {
533
+ let timer: any
534
+ const wrapper = (...args: ReadonlyArray<any>) => {
535
+ clearTimeout(timer)
536
+ timer = setTimeout(() => {
537
+ func(...args)
538
+ }, delay)
539
+ }
540
+ wrapper.clear = () => {
541
+ clearTimeout(timer)
542
+ }
543
+ return wrapper
544
+ }
545
+
546
+ export const useDebounceCallback = <T extends AnyFunc> (
547
+ func: T,
548
+ delay: number
549
+ ): ((...args: Parameters<T>) => void) & { clear: () => void } => {
550
+ const debounced = useMemo(() => debounce(func, delay), [func])
551
+ return debounced
552
+ }
553
+
554
+ export const useStableCallback = <T extends AnyFunc | null | undefined> (
555
+ callback: T
556
+ ): T extends AnyFunc ? T : () => void => {
557
+ const ref = useRef<T>(callback)
558
+ ref.current = callback
559
+ return useCallback<any>(
560
+ (...args: any[]) => ref.current?.(...args),
561
+ []
562
+ )
563
+ }
564
+
565
+ export const usePrevious = <T, > (value: T): T | undefined => {
566
+ const ref = useRef<T | undefined>(undefined)
567
+ const prev = ref.current
568
+ ref.current = value
569
+ return prev
570
+ }
571
+
528
572
  export interface GestureHandler {
529
- nodeRefs?: Array<{ getNodeInstance: () => { nodeRef: unknown } }>;
530
- current?: unknown;
573
+ nodeRefs?: Array<{ getNodeInstance: () => { nodeRef: unknown } }>
574
+ current?: unknown
531
575
  }
532
576
 
533
577
  export function flatGesture (gestures: Array<GestureHandler> = []) {
@@ -539,3 +583,30 @@ export function flatGesture (gestures: Array<GestureHandler> = []) {
539
583
  return gesture?.current ? [gesture] : []
540
584
  })) || []
541
585
  }
586
+
587
+ export function extendObject (...args: Record<string, any>[]) {
588
+ return Object.assign({}, ...args)
589
+ }
590
+
591
+ export function getCurrentPage (pageId: number | null) {
592
+ if (!global.getCurrentPages) return
593
+ const pages = global.getCurrentPages()
594
+ return pages.find((page: any) => isFunction(page.getPageId) && page.getPageId() === pageId)
595
+ }
596
+
597
+ export function renderImage (
598
+ imageProps: ImageProps | FastImageProps,
599
+ enableFastImage = false
600
+ ) {
601
+ const Component: React.ComponentType<ImageProps | FastImageProps> = enableFastImage ? FastImage : Image
602
+ return <Component {...imageProps} />
603
+ }
604
+
605
+ export function pickStyle (styleObj: Record<string, any> = {}, pickedKeys: Array<string>, callback?: (key: string, val: number | string) => number | string) {
606
+ return pickedKeys.reduce<Record<string, any>>((acc, key) => {
607
+ if (key in styleObj) {
608
+ acc[key] = callback ? callback(key, styleObj[key]) : styleObj[key]
609
+ }
610
+ return acc
611
+ }, {})
612
+ }
@@ -1374,7 +1374,8 @@ function processEvent (el, options) {
1374
1374
  function processSlotReact (el, meta) {
1375
1375
  if (el.tag === 'slot') {
1376
1376
  el.slot = {
1377
- name: getAndRemoveAttr(el, 'name').val
1377
+ name: getAndRemoveAttr(el, 'name').val,
1378
+ slot: getAndRemoveAttr(el, 'slot').val
1378
1379
  }
1379
1380
  meta.options = meta.options || {}
1380
1381
  meta.options.disableMemo = true
@@ -2619,8 +2620,8 @@ function processElement (el, root, options, meta) {
2619
2620
  // 预处理代码维度条件编译
2620
2621
  processIf(el)
2621
2622
  processFor(el)
2623
+ processRefReact(el, meta)
2622
2624
  if (!pass) {
2623
- processRefReact(el, meta)
2624
2625
  processStyleReact(el, options)
2625
2626
  processEventReact(el)
2626
2627
  processComponentIs(el, options)
@@ -56,8 +56,8 @@ function genNode (node) {
56
56
  return map
57
57
  }, {})
58
58
  if (node.slot) {
59
- const name = node.slot.name
60
- exp += `__getSlot(${name ? s(name) : ''})`
59
+ const { name, slot } = node.slot
60
+ exp += `__getSlot(${name ? s(name) : ''}${slot ? `, ${s(slot)}` : ''})`
61
61
  } else {
62
62
  exp += `createElement(${`getComponent(${node.is || s(node.tag)})`}`
63
63
  if (node.attrsList.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.67",
3
+ "version": "2.9.69",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -28,7 +28,7 @@
28
28
  "@better-scroll/wheel": "^2.5.1",
29
29
  "@better-scroll/zoom": "^2.5.1",
30
30
  "@mpxjs/template-engine": "^2.8.7",
31
- "@mpxjs/utils": "^2.9.67",
31
+ "@mpxjs/utils": "^2.9.69",
32
32
  "acorn": "^8.11.3",
33
33
  "acorn-walk": "^7.2.0",
34
34
  "async": "^2.6.0",
@@ -82,7 +82,8 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@ant-design/react-native": "^5.2.2",
85
- "@mpxjs/api-proxy": "^2.9.67",
85
+ "@d11/react-native-fast-image": "^8.6.12",
86
+ "@mpxjs/api-proxy": "^2.9.69",
86
87
  "@types/babel-traverse": "^6.25.4",
87
88
  "@types/babel-types": "^7.0.4",
88
89
  "@types/react": "^18.2.79",
@@ -97,5 +98,5 @@
97
98
  "engines": {
98
99
  "node": ">=14.14.0"
99
100
  },
100
- "gitHead": "b23d3850c16543c5998811b8d1d8e6ee7988c0f8"
101
+ "gitHead": "e23c51acc4c2ffdd31fcc6c27aae1aed42d1ade2"
101
102
  }