@mpxjs/webpack-plugin 2.9.59 → 2.9.64

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 (115) hide show
  1. package/lib/index.js +1 -3
  2. package/lib/platform/style/wx/index.js +344 -270
  3. package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
  4. package/lib/platform/template/wx/component-config/checkbox.js +8 -0
  5. package/lib/platform/template/wx/component-config/cover-image.js +15 -0
  6. package/lib/platform/template/wx/component-config/cover-view.js +9 -0
  7. package/lib/platform/template/wx/component-config/form.js +13 -1
  8. package/lib/platform/template/wx/component-config/icon.js +8 -0
  9. package/lib/platform/template/wx/component-config/index.js +5 -1
  10. package/lib/platform/template/wx/component-config/label.js +15 -0
  11. package/lib/platform/template/wx/component-config/movable-area.js +18 -1
  12. package/lib/platform/template/wx/component-config/movable-view.js +18 -1
  13. package/lib/platform/template/wx/component-config/navigator.js +8 -0
  14. package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
  15. package/lib/platform/template/wx/component-config/picker-view.js +18 -2
  16. package/lib/platform/template/wx/component-config/picker.js +14 -1
  17. package/lib/platform/template/wx/component-config/radio-group.js +8 -0
  18. package/lib/platform/template/wx/component-config/radio.js +8 -0
  19. package/lib/platform/template/wx/component-config/root-portal.js +15 -0
  20. package/lib/platform/template/wx/component-config/switch.js +8 -0
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -3
  22. package/lib/react/processScript.js +2 -0
  23. package/lib/react/processStyles.js +1 -0
  24. package/lib/react/processTemplate.js +2 -3
  25. package/lib/react/style-helper.js +12 -7
  26. package/lib/runtime/components/react/context.ts +40 -0
  27. package/lib/runtime/components/react/dist/context.js +8 -0
  28. package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
  29. package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
  30. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
  31. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
  32. package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
  33. package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
  34. package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
  35. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
  38. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
  39. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
  40. package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
  42. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
  43. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
  44. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
  45. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
  48. package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
  53. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
  54. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
  55. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
  56. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
  57. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
  58. package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
  59. package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
  60. package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
  61. package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
  63. package/lib/runtime/components/react/dist/parser.js +218 -0
  64. package/lib/runtime/components/react/dist/types/common.js +1 -0
  65. package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
  66. package/lib/runtime/components/react/dist/utils.jsx +433 -0
  67. package/lib/runtime/components/react/getInnerListeners.ts +43 -21
  68. package/lib/runtime/components/react/mpx-button.tsx +129 -119
  69. package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
  70. package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
  71. package/lib/runtime/components/react/mpx-form.tsx +117 -0
  72. package/lib/runtime/components/react/mpx-icon.tsx +106 -0
  73. package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
  74. package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
  75. package/lib/runtime/components/react/mpx-input.tsx +90 -42
  76. package/lib/runtime/components/react/mpx-label.tsx +110 -0
  77. package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
  78. package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
  79. package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
  80. package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
  81. package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
  82. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
  83. package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
  84. package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
  85. package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
  86. package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
  87. package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
  88. package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
  89. package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
  90. package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
  91. package/lib/runtime/components/react/mpx-radio.tsx +230 -0
  92. package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
  93. package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
  94. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
  95. package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
  96. package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
  97. package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
  98. package/lib/runtime/components/react/mpx-switch.tsx +148 -0
  99. package/lib/runtime/components/react/mpx-text.tsx +53 -77
  100. package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
  101. package/lib/runtime/components/react/mpx-view.tsx +576 -195
  102. package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
  103. package/lib/runtime/components/react/parser.ts +245 -0
  104. package/lib/runtime/components/react/types/common.ts +12 -0
  105. package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
  106. package/lib/runtime/components/react/types/global.d.ts +17 -1
  107. package/lib/runtime/components/react/useNodesRef.ts +4 -10
  108. package/lib/runtime/components/react/utils.tsx +505 -0
  109. package/lib/runtime/optionProcessor.js +19 -17
  110. package/lib/template-compiler/compiler.js +84 -61
  111. package/lib/template-compiler/gen-node-react.js +7 -9
  112. package/lib/web/processStyles.js +2 -5
  113. package/package.json +8 -3
  114. package/lib/runtime/components/react/dist/utils.js +0 -80
  115. package/lib/runtime/components/react/utils.ts +0 -92
@@ -1,5 +1,5 @@
1
- import React, { forwardRef, useRef } from 'react';
2
- import { default as Carouse } from './carouse';
1
+ import { forwardRef, useRef } from 'react';
2
+ import Carouse from './carouse';
3
3
  import useInnerProps from '../getInnerListeners';
4
4
  import useNodesRef from '../useNodesRef'; // 引入辅助函数
5
5
  /**
@@ -13,13 +13,14 @@ import useNodesRef from '../useNodesRef'; // 引入辅助函数
13
13
  * ✔ circular
14
14
  * ✔ vertical
15
15
  * ✘ display-multiple-items
16
- * previous-margin
17
- * next-margin
16
+ * previous-margin
17
+ * next-margin
18
+ * ✔ easing-function ="easeOutCubic"
18
19
  * ✘ snap-to-edge
19
20
  */
20
21
  const _SwiperWrapper = forwardRef((props, ref) => {
21
22
  const { children } = props;
22
- let innerLayout = useRef({});
23
+ const innerLayout = useRef({});
23
24
  const swiperProp = {
24
25
  circular: props.circular || false,
25
26
  current: props.current || 0,
@@ -27,14 +28,20 @@ const _SwiperWrapper = forwardRef((props, ref) => {
27
28
  duration: props.duration || 500,
28
29
  interval: props.interval || 5000,
29
30
  showsPagination: props['indicator-dots'],
30
- dotColor: props['indicator-color'] || "rgba(0, 0, 0, .3)",
31
+ dotColor: props['indicator-color'] || 'rgba(0, 0, 0, .3)',
31
32
  activeDotColor: props['indicator-active-color'] || '#000000',
32
33
  horizontal: props.vertical !== undefined ? !props.vertical : true,
33
- style: props.style,
34
34
  previousMargin: props['previous-margin'] ? parseInt(props['previous-margin']) : 0,
35
35
  nextMargin: props['next-margin'] ? parseInt(props['next-margin']) : 0,
36
- enableOffset: props['enable-offset'] || false,
37
- bindchange: props.bindchange
36
+ enableOffset: props['enable-offset'] || true,
37
+ enableVar: props['enable-var'] || false,
38
+ parentFontSize: props['parent-font-size'],
39
+ parentWidth: props['parent-width'],
40
+ parentHeight: props['parent-height'],
41
+ style: props.style || {},
42
+ externalVarContext: props['external-var-context'],
43
+ bindchange: props.bindchange,
44
+ easingFunction: props['easing-function'] || 'default'
38
45
  };
39
46
  const { nodeRef } = useNodesRef(props, ref, {});
40
47
  const innerProps = useInnerProps(props, {
@@ -44,12 +51,15 @@ const _SwiperWrapper = forwardRef((props, ref) => {
44
51
  'indicator-color',
45
52
  'indicator-active-color',
46
53
  'previous-margin',
47
- 'next-margin'
54
+ 'vertical',
55
+ 'previous-margin',
56
+ 'next-margin',
57
+ 'easing-function'
48
58
  ], { layoutRef: innerLayout });
49
59
  const getInnerLayout = (layout) => {
50
60
  innerLayout.current = layout.current;
51
61
  };
52
- return <Carouse getInnerLayout={getInnerLayout} innerProps={innerProps} {...swiperProp} {...innerProps}>
62
+ return <Carouse getInnerLayout={getInnerLayout} innerProps={innerProps} {...innerProps} {...swiperProp}>
53
63
  {children}
54
64
  </Carouse>;
55
65
  });
@@ -1,24 +1,32 @@
1
1
  import { View } from 'react-native';
2
- import React, { forwardRef, useRef } from 'react';
2
+ import { forwardRef } from 'react';
3
3
  import useInnerProps from './getInnerListeners';
4
4
  import useNodesRef from './useNodesRef'; // 引入辅助函数
5
+ import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils';
5
6
  const _SwiperItem = forwardRef((props, ref) => {
6
- const { children, 'enable-offset': enableOffset } = props;
7
- const layoutRef = useRef({});
7
+ const { 'enable-offset': enableOffset, 'enable-var': enableVar, 'external-var-context': externalVarContext, style } = props;
8
+ const { textProps } = splitProps(props);
8
9
  const { nodeRef } = useNodesRef(props, ref, {});
9
- const onLayout = () => {
10
- nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
11
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
12
- });
13
- };
10
+ const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
11
+ const { textStyle, innerStyle } = splitStyle(normalStyle);
12
+ const {
13
+ // 存储layout布局信息
14
+ layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
14
15
  const innerProps = useInnerProps(props, {
15
- ...(enableOffset ? { onLayout } : {}),
16
+ style: { ...innerStyle, ...layoutStyle },
17
+ ref: nodeRef,
18
+ ...layoutProps
16
19
  }, [
17
20
  'children',
18
21
  'enable-offset'
19
22
  ], { layoutRef });
20
- return (<View ref={nodeRef} data-itemId={props['item-id']} {...innerProps}>
21
- {children}
23
+ return (<View data-itemId={props['item-id']} {...innerProps}>
24
+ {wrapChildren(props, {
25
+ hasVarDec,
26
+ varContext: varContextRef.current,
27
+ textStyle,
28
+ textProps
29
+ })}
22
30
  </View>);
23
31
  });
24
32
  _SwiperItem.displayName = 'mpx-swiper-item';
@@ -0,0 +1,79 @@
1
+ /**
2
+ * ✔ checked
3
+ * ✔ type
4
+ * ✔ disabled
5
+ * ✔ color
6
+ */
7
+ import { Switch } from 'react-native';
8
+ import { useEffect, forwardRef, useState, useContext } from 'react';
9
+ import { warn } from '@mpxjs/utils';
10
+ import useNodesRef from './useNodesRef'; // 引入辅助函数
11
+ import useInnerProps, { getCustomEvent } from './getInnerListeners';
12
+ import CheckBox from './mpx-checkbox';
13
+ import { FormContext } from './context';
14
+ import { useTransformStyle, useLayout } from './utils';
15
+ const _Switch = forwardRef((props, ref) => {
16
+ const { style = {}, checked = false, type = 'switch', disabled = false, color = '#04BE02', 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindchange, catchchange } = props;
17
+ const [isChecked, setIsChecked] = useState(checked);
18
+ const changeHandler = bindchange || catchchange;
19
+ let formValuesMap;
20
+ const formContext = useContext(FormContext);
21
+ if (formContext) {
22
+ formValuesMap = formContext.formValuesMap;
23
+ }
24
+ const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, {
25
+ enableVar,
26
+ externalVarContext,
27
+ parentFontSize,
28
+ parentWidth,
29
+ parentHeight
30
+ });
31
+ useEffect(() => {
32
+ setIsChecked(checked);
33
+ }, [checked]);
34
+ const { nodeRef } = useNodesRef(props, ref);
35
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
36
+ const onChange = (evt, { checked } = {}) => {
37
+ if (type === 'switch') {
38
+ setIsChecked(evt);
39
+ changeHandler && changeHandler(getCustomEvent('change', {}, { layoutRef, detail: { value: evt } }, props));
40
+ }
41
+ else {
42
+ setIsChecked(checked);
43
+ changeHandler && changeHandler(getCustomEvent('change', evt, { layoutRef, detail: { value: checked } }, props));
44
+ }
45
+ };
46
+ const resetValue = () => {
47
+ setIsChecked(false);
48
+ };
49
+ const getValue = () => {
50
+ return isChecked;
51
+ };
52
+ if (formValuesMap) {
53
+ if (!props.name) {
54
+ warn('If a form component is used, the name attribute is required.');
55
+ }
56
+ else {
57
+ formValuesMap.set(props.name, { getValue, resetValue });
58
+ }
59
+ }
60
+ const innerProps = useInnerProps(props, {
61
+ ref: nodeRef,
62
+ style: { ...normalStyle, ...layoutStyle },
63
+ ...layoutProps,
64
+ ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
65
+ }, [
66
+ 'checked',
67
+ 'disabled',
68
+ 'type',
69
+ 'color'
70
+ ], {
71
+ layoutRef
72
+ });
73
+ if (type === 'checkbox') {
74
+ return <CheckBox {...innerProps} color={color} style={normalStyle} checked={isChecked}/>;
75
+ }
76
+ return <Switch {...innerProps} style={normalStyle} value={isChecked} trackColor={{ false: '#FFF', true: color }} thumbColor={isChecked ? '#FFF' : '#f4f3f4'} ios_backgroundColor="#FFF"/>;
77
+ });
78
+ _Switch.displayName = 'mpx-switch';
79
+ export default _Switch;
@@ -3,65 +3,37 @@
3
3
  * ✘ space
4
4
  * ✘ decode
5
5
  */
6
- import { Text, StyleSheet } from 'react-native';
7
- import { useRef, useEffect, forwardRef } from 'react';
6
+ import { Text } from 'react-native';
7
+ import { useRef, forwardRef } from 'react';
8
8
  import useInnerProps from './getInnerListeners';
9
- // @ts-ignore
10
9
  import useNodesRef from './useNodesRef'; // 引入辅助函数
11
- import { PERCENT_REGEX } from './utils';
12
- const DEFAULT_STYLE = {
13
- fontSize: 16
14
- };
15
- const transformStyle = (styleObj) => {
16
- let { lineHeight } = styleObj;
17
- if (typeof lineHeight === 'string' && PERCENT_REGEX.test(lineHeight)) {
18
- lineHeight = (parseFloat(lineHeight) / 100) * (styleObj.fontSize || DEFAULT_STYLE.fontSize);
19
- styleObj.lineHeight = lineHeight;
20
- }
21
- };
10
+ import { useTransformStyle, wrapChildren } from './utils';
22
11
  const _Text = forwardRef((props, ref) => {
23
- const { style = [], children, selectable, 'enable-offset': enableOffset, 'user-select': userSelect, 'disable-default-style': disableDefaultStyle = false, } = props;
12
+ const { style = {}, selectable, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'user-select': userSelect, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
24
13
  const layoutRef = useRef({});
25
- const styleObj = StyleSheet.flatten(style);
26
- let defaultStyle = {};
27
- if (!disableDefaultStyle) {
28
- defaultStyle = DEFAULT_STYLE;
29
- transformStyle(styleObj);
30
- }
31
- const { nodeRef } = useNodesRef(props, ref, {
32
- defaultStyle
14
+ const { normalStyle, hasVarDec, varContextRef } = useTransformStyle(style, {
15
+ enableVar,
16
+ externalVarContext,
17
+ parentFontSize,
18
+ parentWidth,
19
+ parentHeight
33
20
  });
21
+ const { nodeRef } = useNodesRef(props, ref);
34
22
  const innerProps = useInnerProps(props, {
35
- ref: nodeRef
23
+ ref: nodeRef,
24
+ style: normalStyle,
25
+ selectable: !!selectable || !!userSelect
36
26
  }, [
37
- 'style',
38
- 'children',
39
- 'selectable',
40
- 'user-select',
41
- 'useInherit',
42
- 'enable-offset'
27
+ 'user-select'
43
28
  ], {
44
29
  layoutRef
45
30
  });
46
- useEffect(() => {
47
- let measureTimeout = null;
48
- if (enableOffset) {
49
- measureTimeout = setTimeout(() => {
50
- nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
51
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
52
- });
53
- });
54
- return () => {
55
- if (measureTimeout) {
56
- clearTimeout(measureTimeout);
57
- measureTimeout = null;
58
- }
59
- };
60
- }
61
- }, []);
62
- return (<Text style={{ ...defaultStyle, ...styleObj }} selectable={!!selectable || !!userSelect} {...innerProps}>
63
- {children}
64
- </Text>);
31
+ return (<Text {...innerProps}>
32
+ {wrapChildren(props, {
33
+ hasVarDec,
34
+ varContext: varContextRef.current
35
+ })}
36
+ </Text>);
65
37
  });
66
38
  _Text.displayName = 'mpx-text';
67
39
  export default _Text;
@@ -9,7 +9,7 @@
9
9
  * ✘ show-confirm-bar
10
10
  * ✔ bindlinechange: No `heightRpx` info.
11
11
  */
12
- import React, { forwardRef } from 'react';
12
+ import { forwardRef } from 'react';
13
13
  import { Keyboard } from 'react-native';
14
14
  import Input from './mpx-input';
15
15
  import { omit } from './utils';
@@ -19,7 +19,7 @@ const Textarea = forwardRef((props, ref) => {
19
19
  'type',
20
20
  'password',
21
21
  'multiline',
22
- 'confirm-hold',
22
+ 'confirm-hold'
23
23
  ]);
24
24
  return (<Input ref={ref} multiline confirm-type='next' bindblur={() => Keyboard.dismiss()} {...restProps}/>);
25
25
  });