@mpxjs/webpack-plugin 2.10.8 → 2.10.10

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.
@@ -21,13 +21,13 @@ function getAsyncChunkName (chunkName) {
21
21
  return ''
22
22
  }
23
23
 
24
- function getAsyncSuspense (type, moduleId, componentRequest, componentName, chunkName, fallback, loading) {
24
+ function getAsyncSuspense (type, moduleId, componentRequest, componentName, chunkName, getFallback, getLoading) {
25
25
  return `getAsyncSuspense({
26
26
  type: ${JSON.stringify(type)},
27
27
  moduleId: ${JSON.stringify(moduleId)},
28
28
  chunkName: ${JSON.stringify(chunkName)},
29
- loading: ${loading},
30
- fallback: ${fallback},
29
+ getFallback: ${getFallback},
30
+ getLoading: ${getLoading},
31
31
  getChildren () {
32
32
  return import(${getAsyncChunkName(chunkName)}${componentRequest}).then(function (res) {
33
33
  return getComponent(res, {displayName: ${JSON.stringify(componentName)}})
@@ -61,9 +61,9 @@ function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig, rnConfig })
61
61
  const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
62
62
  if (pageCfg.async) {
63
63
  const moduleId = mpx.getModuleId(pageCfg.resource)
64
- const fallback = rnConfig.asyncChunk && rnConfig.asyncChunk.fallback && getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.fallback, { isComponent: true })), 'PageFallback')
65
- const loading = rnConfig.asyncChunk && rnConfig.asyncChunk.loading && getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.loading, { isComponent: true })), 'PageLoading')
66
- pagesMap[pagePath] = getComponentGetter(getAsyncSuspense('page', moduleId, pageRequest, 'Page', pageCfg.async, fallback, loading))
64
+ const getFallback = rnConfig.asyncChunk && rnConfig.asyncChunk.fallback && getComponentGetter(getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.fallback, { isComponent: true })), 'PageFallback'))
65
+ const getLoading = rnConfig.asyncChunk && rnConfig.asyncChunk.loading && getComponentGetter(getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.loading, { isComponent: true })), 'PageLoading'))
66
+ pagesMap[pagePath] = getAsyncSuspense('page', moduleId, pageRequest, 'Page', pageCfg.async, getFallback, getLoading)
67
67
  } else {
68
68
  // 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
69
69
  pagesMap[pagePath] = getComponentGetter(getComponent(pageRequest, 'Page'))
@@ -91,7 +91,7 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC
91
91
  if (componentCfg.async) {
92
92
  const moduleId = mpx.getModuleId(componentCfg.resource)
93
93
  const placeholder = jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName]
94
- let fallback
94
+ let getFallback
95
95
  if (placeholder) {
96
96
  if (localComponentsMap[placeholder]) {
97
97
  const placeholderCfg = localComponentsMap[placeholder]
@@ -101,11 +101,11 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC
101
101
  new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
102
102
  )
103
103
  }
104
- fallback = getComponent(placeholderRequest, placeholder)
104
+ getFallback = getComponentGetter(getComponent(placeholderRequest, placeholder))
105
105
  } else {
106
106
  const tag = `mpx-${placeholder}`
107
107
  if (isBuildInReactTag(tag)) {
108
- fallback = getBuiltInComponent(getBuiltInComponentRequest(tag))
108
+ getFallback = getComponentGetter(getBuiltInComponent(getBuiltInComponentRequest(tag)))
109
109
  } else {
110
110
  loaderContext.emitError(
111
111
  new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} is not built-in component, please check!`)
@@ -117,7 +117,7 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC
117
117
  new Error(`[json processor][${loaderContext.resource}]: ${componentName} has no componentPlaceholder, please check!`)
118
118
  )
119
119
  }
120
- componentsMap[componentName] = getComponentGetter(getAsyncSuspense('component', moduleId, componentRequest, componentName, componentCfg.async, fallback))
120
+ componentsMap[componentName] = getAsyncSuspense('component', moduleId, componentRequest, componentName, componentCfg.async, getFallback)
121
121
  } else {
122
122
  componentsMap[componentName] = getComponentGetter(getComponent(componentRequest, componentName))
123
123
  }
@@ -69,7 +69,7 @@ const DefaultLoading = () => {
69
69
  }} resizeMode={FastImage.resizeMode.contain}></FastImage>
70
70
  </View>);
71
71
  };
72
- const AsyncSuspense = ({ type, innerProps, chunkName, moduleId, loading, fallback, getChildren }) => {
72
+ const AsyncSuspense = ({ type, chunkName, moduleId, innerProps, getLoading, getFallback, getChildren }) => {
73
73
  const [status, setStatus] = useState('pending');
74
74
  const chunkLoaded = asyncChunkMap.has(moduleId);
75
75
  const loadChunkPromise = useRef(null);
@@ -112,11 +112,11 @@ const AsyncSuspense = ({ type, innerProps, chunkName, moduleId, loading, fallbac
112
112
  }
113
113
  else if (status === 'error') {
114
114
  if (type === 'page') {
115
- fallback = fallback || DefaultFallback;
115
+ const fallback = getFallback ? getFallback() : DefaultFallback;
116
116
  return createElement(fallback, { onReload: reloadPage });
117
117
  }
118
118
  else {
119
- return fallback ? createElement(fallback, innerProps) : null;
119
+ return getFallback ? createElement(getFallback(), innerProps) : null;
120
120
  }
121
121
  }
122
122
  else {
@@ -124,10 +124,11 @@ const AsyncSuspense = ({ type, innerProps, chunkName, moduleId, loading, fallbac
124
124
  loadChunkPromise.current = getChildren();
125
125
  }
126
126
  if (type === 'page') {
127
- return createElement(loading || DefaultLoading);
127
+ const loading = getLoading ? getLoading() : DefaultLoading;
128
+ return createElement(loading);
128
129
  }
129
130
  else {
130
- return fallback ? createElement(fallback, innerProps) : null;
131
+ return getFallback ? createElement(getFallback(), innerProps) : null;
131
132
  }
132
133
  }
133
134
  };
@@ -34,7 +34,7 @@
34
34
  import { ScrollView, RefreshControl, Gesture, GestureDetector } from 'react-native-gesture-handler';
35
35
  import { Animated as RNAnimated } from 'react-native';
36
36
  import { isValidElement, Children, useRef, useState, useEffect, forwardRef, useContext, useMemo, createElement } from 'react';
37
- import Animated, { useAnimatedRef, useSharedValue, withTiming, useAnimatedStyle, runOnJS } from 'react-native-reanimated';
37
+ import Animated, { useSharedValue, withTiming, useAnimatedStyle, runOnJS } from 'react-native-reanimated';
38
38
  import { warn, hasOwn } from '@mpxjs/utils';
39
39
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
40
40
  import useNodesRef from './useNodesRef';
@@ -78,7 +78,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
78
78
  const hasRefresher = refresherContent && refresherEnabled;
79
79
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, hasPositionFixed, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
80
80
  const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
81
- const scrollViewRef = useAnimatedRef();
81
+ const scrollViewRef = useRef(null);
82
82
  useNodesRef(props, ref, scrollViewRef, {
83
83
  style: normalStyle,
84
84
  scrollOffset: scrollOptions,
@@ -122,6 +122,8 @@ const selfPercentRule = {
122
122
  };
123
123
  const parentHeightPercentRule = {
124
124
  height: true,
125
+ minHeight: true,
126
+ maxHeight: true,
125
127
  top: true,
126
128
  bottom: true
127
129
  };
@@ -99,8 +99,8 @@ interface AsyncSuspenseProps {
99
99
  chunkName: string
100
100
  moduleId: string
101
101
  innerProps: any,
102
- loading?: ComponentType<unknown>
103
- fallback?: ComponentType<unknown>
102
+ getLoading?: () => ComponentType<unknown>
103
+ getFallback?: () => ComponentType<unknown>
104
104
  getChildren: () => Promise<ReactNode>
105
105
  }
106
106
 
@@ -108,11 +108,11 @@ type ComponentStauts = 'pending' | 'error' | 'loaded'
108
108
 
109
109
  const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
110
110
  type,
111
- innerProps,
112
111
  chunkName,
113
112
  moduleId,
114
- loading,
115
- fallback,
113
+ innerProps,
114
+ getLoading,
115
+ getFallback,
116
116
  getChildren
117
117
  }) => {
118
118
  const [status, setStatus] = useState<ComponentStauts>('pending')
@@ -158,19 +158,20 @@ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
158
158
  return createElement(Comp, innerProps)
159
159
  } else if (status === 'error') {
160
160
  if (type === 'page') {
161
- fallback = fallback || DefaultFallback
161
+ const fallback = getFallback ? getFallback() : DefaultFallback
162
162
  return createElement(fallback as ComponentType<DefaultFallbackProps>, { onReload: reloadPage })
163
163
  } else {
164
- return fallback ? createElement(fallback, innerProps) : null
164
+ return getFallback ? createElement(getFallback(), innerProps) : null
165
165
  }
166
166
  } else {
167
167
  if (!loadChunkPromise.current) {
168
168
  loadChunkPromise.current = getChildren()
169
169
  }
170
170
  if (type === 'page') {
171
- return createElement(loading || DefaultLoading)
171
+ const loading = getLoading ? getLoading() : DefaultLoading
172
+ return createElement(loading)
172
173
  } else {
173
- return fallback ? createElement(fallback, innerProps) : null
174
+ return getFallback ? createElement(getFallback(), innerProps) : null
174
175
  }
175
176
  }
176
177
  }
@@ -34,7 +34,7 @@
34
34
  import { ScrollView, RefreshControl, Gesture, GestureDetector } from 'react-native-gesture-handler'
35
35
  import { View, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle, Animated as RNAnimated } from 'react-native'
36
36
  import { isValidElement, Children, JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, useMemo, createElement } from 'react'
37
- import Animated, { useAnimatedRef, useSharedValue, withTiming, useAnimatedStyle, runOnJS } from 'react-native-reanimated'
37
+ import Animated, { useSharedValue, withTiming, useAnimatedStyle, runOnJS } from 'react-native-reanimated'
38
38
  import { warn, hasOwn } from '@mpxjs/utils'
39
39
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
40
40
  import useNodesRef, { HandlerRef } from './useNodesRef'
@@ -209,7 +209,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
209
209
 
210
210
  const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
211
211
 
212
- const scrollViewRef = useAnimatedRef<ScrollView>()
212
+ const scrollViewRef = useRef<ScrollView>(null)
213
213
  useNodesRef(props, ref, scrollViewRef, {
214
214
  style: normalStyle,
215
215
  scrollOffset: scrollOptions,
@@ -1,5 +1,4 @@
1
1
  import { useRef, useImperativeHandle, RefObject, ForwardedRef } from 'react'
2
- import { useAnimatedRef } from 'react-native-reanimated'
3
2
 
4
3
  type Obj = Record<string, any>
5
4
 
@@ -156,6 +156,8 @@ const selfPercentRule: Record<string, 'height' | 'width'> = {
156
156
 
157
157
  const parentHeightPercentRule: Record<string, boolean> = {
158
158
  height: true,
159
+ minHeight: true,
160
+ maxHeight: true,
159
161
  top: true,
160
162
  bottom: true
161
163
  }
@@ -310,7 +312,7 @@ function parseValues (str: string, char = ' ') {
310
312
  // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
311
313
  function parseTransform (transformStr: string) {
312
314
  const values = parseValues(transformStr)
313
- const transform: {[propName: string]: string|number|number[]}[] = []
315
+ const transform: { [propName: string]: string | number | number[] }[] = []
314
316
  values.forEach(item => {
315
317
  const match = item.match(/([/\w]+)\((.+)\)/)
316
318
  if (match && match.length >= 3) {
@@ -18,10 +18,9 @@ interface AsyncSuspenseProps {
18
18
  type: 'component' | 'page'
19
19
  chunkName: string
20
20
  moduleId: string
21
- innerProps: any
22
- loading: ComponentType<unknown>
23
- fallback: ComponentType<unknown>
21
+ getFallback?: () => ComponentType<unknown>
22
+ getLoading?: () => ComponentType<unknown>
24
23
  getChildren: () => Promise<AsyncModule>
25
24
  }
26
25
 
27
- export function getAsyncSuspense(props: AsyncSuspenseProps): ReactNode
26
+ export function getAsyncSuspense (props: AsyncSuspenseProps): ReactNode
@@ -10,8 +10,9 @@ export function getComponent (component, extendOptions) {
10
10
  }
11
11
 
12
12
  export function getAsyncSuspense (commonProps) {
13
+ let result
13
14
  if (commonProps.type === 'component') {
14
- return memo(forwardRef(function (props, ref) {
15
+ result = memo(forwardRef(function (props, ref) {
15
16
  return createElement(AsyncSuspense,
16
17
  extend(commonProps, {
17
18
  innerProps: Object.assign({}, props, { ref })
@@ -19,14 +20,16 @@ export function getAsyncSuspense (commonProps) {
19
20
  )
20
21
  }))
21
22
  } else {
22
- return function (props) {
23
+ result = memo(function (props) {
23
24
  return createElement(AsyncSuspense,
24
25
  extend(commonProps, {
25
26
  innerProps: props
26
27
  })
27
28
  )
28
- }
29
+ })
29
30
  }
31
+ result.displayName = 'AsyncSuspenseHOC'
32
+ return result
30
33
  }
31
34
 
32
35
  export function getLazyPage (getComponent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.8",
3
+ "version": "2.10.10",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -100,5 +100,5 @@
100
100
  "engines": {
101
101
  "node": ">=14.14.0"
102
102
  },
103
- "gitHead": "23f6e6d5fa30e4abdc35e137007edbd38337b36e"
103
+ "gitHead": "cee4b9ba7c2b455ebb864cbad7d2a8374b2d7308"
104
104
  }