@mpxjs/webpack-plugin 2.9.59 → 2.9.62

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 (106) hide show
  1. package/lib/platform/style/wx/index.js +314 -254
  2. package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
  3. package/lib/platform/template/wx/component-config/checkbox.js +8 -0
  4. package/lib/platform/template/wx/component-config/cover-image.js +15 -0
  5. package/lib/platform/template/wx/component-config/cover-view.js +9 -0
  6. package/lib/platform/template/wx/component-config/form.js +13 -1
  7. package/lib/platform/template/wx/component-config/icon.js +8 -0
  8. package/lib/platform/template/wx/component-config/index.js +5 -1
  9. package/lib/platform/template/wx/component-config/label.js +15 -0
  10. package/lib/platform/template/wx/component-config/movable-area.js +18 -1
  11. package/lib/platform/template/wx/component-config/movable-view.js +18 -1
  12. package/lib/platform/template/wx/component-config/navigator.js +8 -0
  13. package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
  14. package/lib/platform/template/wx/component-config/picker-view.js +18 -2
  15. package/lib/platform/template/wx/component-config/picker.js +14 -1
  16. package/lib/platform/template/wx/component-config/radio-group.js +8 -0
  17. package/lib/platform/template/wx/component-config/radio.js +8 -0
  18. package/lib/platform/template/wx/component-config/root-portal.js +15 -0
  19. package/lib/platform/template/wx/component-config/switch.js +8 -0
  20. package/lib/platform/template/wx/component-config/unsupported.js +1 -3
  21. package/lib/react/processScript.js +2 -0
  22. package/lib/runtime/components/react/context.ts +38 -0
  23. package/lib/runtime/components/react/dist/context.js +7 -0
  24. package/lib/runtime/components/react/dist/getInnerListeners.js +22 -11
  25. package/lib/runtime/components/react/dist/mpx-button.jsx +67 -45
  26. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +81 -0
  27. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +152 -0
  28. package/lib/runtime/components/react/dist/mpx-form.jsx +59 -0
  29. package/lib/runtime/components/react/dist/mpx-icon.jsx +51 -0
  30. package/lib/runtime/components/react/dist/mpx-image/index.jsx +17 -22
  31. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -1
  32. package/lib/runtime/components/react/dist/mpx-input.jsx +38 -16
  33. package/lib/runtime/components/react/dist/mpx-label.jsx +63 -0
  34. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +46 -0
  35. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
  36. package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
  37. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
  38. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
  39. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +139 -0
  40. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +90 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
  42. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
  43. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
  44. package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +15 -0
  46. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +68 -0
  47. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +79 -0
  48. package/lib/runtime/components/react/dist/mpx-radio.jsx +169 -0
  49. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +11 -0
  50. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +66 -50
  51. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +206 -147
  52. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +9 -7
  53. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +3 -3
  54. package/lib/runtime/components/react/dist/mpx-switch.jsx +76 -0
  55. package/lib/runtime/components/react/dist/mpx-text.jsx +7 -19
  56. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  57. package/lib/runtime/components/react/dist/mpx-view.jsx +326 -96
  58. package/lib/runtime/components/react/dist/mpx-web-view.jsx +9 -15
  59. package/lib/runtime/components/react/dist/types/common.js +1 -0
  60. package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
  61. package/lib/runtime/components/react/dist/utils.js +82 -14
  62. package/lib/runtime/components/react/getInnerListeners.ts +25 -13
  63. package/lib/runtime/components/react/mpx-button.tsx +87 -67
  64. package/lib/runtime/components/react/mpx-checkbox-group.tsx +147 -0
  65. package/lib/runtime/components/react/mpx-checkbox.tsx +245 -0
  66. package/lib/runtime/components/react/mpx-form.tsx +89 -0
  67. package/lib/runtime/components/react/mpx-icon.tsx +103 -0
  68. package/lib/runtime/components/react/mpx-image/index.tsx +20 -32
  69. package/lib/runtime/components/react/mpx-image/svg.tsx +2 -2
  70. package/lib/runtime/components/react/mpx-input.tsx +54 -26
  71. package/lib/runtime/components/react/mpx-label.tsx +115 -0
  72. package/lib/runtime/components/react/mpx-movable-area.tsx +67 -0
  73. package/lib/runtime/components/react/mpx-movable-view.tsx +425 -0
  74. package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
  75. package/lib/runtime/components/react/mpx-picker/date.tsx +83 -0
  76. package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
  77. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +153 -0
  78. package/lib/runtime/components/react/mpx-picker/region.tsx +104 -0
  79. package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
  80. package/lib/runtime/components/react/mpx-picker/selector.tsx +92 -0
  81. package/lib/runtime/components/react/mpx-picker/time.tsx +274 -0
  82. package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
  83. package/lib/runtime/components/react/mpx-picker-view-column.tsx +28 -0
  84. package/lib/runtime/components/react/mpx-picker-view.tsx +104 -0
  85. package/lib/runtime/components/react/mpx-radio-group.tsx +147 -0
  86. package/lib/runtime/components/react/mpx-radio.tsx +246 -0
  87. package/lib/runtime/components/react/mpx-root-portal.tsx +25 -0
  88. package/lib/runtime/components/react/mpx-scroll-view.tsx +82 -58
  89. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +203 -156
  90. package/lib/runtime/components/react/mpx-swiper/index.tsx +12 -13
  91. package/lib/runtime/components/react/mpx-swiper/type.ts +11 -4
  92. package/lib/runtime/components/react/mpx-swiper-item.tsx +5 -3
  93. package/lib/runtime/components/react/mpx-switch.tsx +127 -0
  94. package/lib/runtime/components/react/mpx-text.tsx +52 -68
  95. package/lib/runtime/components/react/mpx-textarea.tsx +2 -2
  96. package/lib/runtime/components/react/mpx-view.tsx +373 -140
  97. package/lib/runtime/components/react/mpx-web-view.tsx +24 -28
  98. package/lib/runtime/components/react/types/common.ts +12 -0
  99. package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
  100. package/lib/runtime/components/react/types/global.d.ts +4 -0
  101. package/lib/runtime/components/react/useNodesRef.ts +3 -8
  102. package/lib/runtime/components/react/utils.ts +93 -15
  103. package/lib/runtime/optionProcessor.js +19 -17
  104. package/lib/template-compiler/compiler.js +56 -41
  105. package/lib/template-compiler/gen-node-react.js +7 -7
  106. package/package.json +6 -3
@@ -0,0 +1,139 @@
1
+ import { View, TouchableWithoutFeedback } from 'react-native';
2
+ import { Picker } from '@ant-design/react-native';
3
+ import React, { forwardRef, useState, useRef, useEffect } from 'react';
4
+ import useNodesRef from '../useNodesRef'; // 引入辅助函数
5
+ function convertToObj(item, rangeKey = '') {
6
+ if (typeof item === 'object') {
7
+ return { value: item[rangeKey], label: item[rangeKey] };
8
+ }
9
+ else {
10
+ return { value: item, label: item };
11
+ }
12
+ }
13
+ // eslint-disable-next-line default-param-last
14
+ function formatRangeFun(range = [], rangeKey) {
15
+ const result = (range[0] || []).map(item => {
16
+ return convertToObj(item, rangeKey);
17
+ });
18
+ let tmp = result;
19
+ for (let i = 1; i < range.length; i++) {
20
+ let child = Array.isArray(range[i]) ? range[i] : [];
21
+ const nextColData = child.map(item => {
22
+ return convertToObj(item, rangeKey);
23
+ });
24
+ tmp.forEach(item => {
25
+ item.children = nextColData;
26
+ });
27
+ tmp = nextColData;
28
+ }
29
+ return result;
30
+ }
31
+ function getIndexByValues(range = [], value = []) {
32
+ let tmp = range;
33
+ return value.map(v => {
34
+ for (let i = 0; i < tmp.length; i++) {
35
+ if (tmp[i].value === v) {
36
+ tmp = tmp[i].children || [];
37
+ return i;
38
+ }
39
+ }
40
+ return 0;
41
+ });
42
+ }
43
+ // [1,1,2] 寻找出[]
44
+ function getInnerValueByIndex(range = [], value = []) {
45
+ let tmp = range;
46
+ return value.map(v => {
47
+ let current = tmp[v].value;
48
+ tmp = tmp[v].children;
49
+ return current;
50
+ });
51
+ }
52
+ // column = 1 value = ['无脊柱动物', '扁性动物', '吸血虫'] 根据column 和value 获取到当前列变动选择的值所在当前列的索引
53
+ function getColumnIndexByValue(range = [], column, value = []) {
54
+ let curRange = range;
55
+ let changeIndex = 0;
56
+ let tmpRange = [];
57
+ value.map((item, index) => {
58
+ if (column === index) {
59
+ curRange.map((ritem, rindex) => {
60
+ if (ritem.value === item) {
61
+ changeIndex = rindex;
62
+ }
63
+ });
64
+ }
65
+ else {
66
+ curRange.map((citem, cindex) => {
67
+ if (citem.value === item) {
68
+ tmpRange = citem.children;
69
+ }
70
+ });
71
+ curRange = tmpRange;
72
+ }
73
+ });
74
+ return changeIndex;
75
+ }
76
+ const _MultiSelectorPicker = forwardRef((props, ref) => {
77
+ const { range, value, disabled, bindchange, bindcancel, children, bindcolumnchange } = props;
78
+ let formatRange = formatRangeFun(range, props['range-key']);
79
+ let initValue = getInnerValueByIndex(formatRange, value);
80
+ // 选中的索引值
81
+ const [selected, setSelected] = useState(initValue);
82
+ // range数据源
83
+ const [data, setData] = useState(formatRange || []);
84
+ // 存储layout布局信息
85
+ const layoutRef = useRef({});
86
+ const { nodeRef: viewRef } = useNodesRef(props, ref, {});
87
+ useEffect(() => {
88
+ if (range) {
89
+ const newFormatRange = formatRangeFun(range, props['range-key']);
90
+ setData(newFormatRange);
91
+ }
92
+ const newValue = getInnerValueByIndex(formatRange, value);
93
+ value && setSelected(newValue);
94
+ }, [range, value]);
95
+ const onChange = (value) => {
96
+ // e.detail.value 都是索引multi
97
+ const strIndex = getIndexByValues(data, value);
98
+ bindchange && bindchange({
99
+ detail: {
100
+ value: strIndex
101
+ }
102
+ });
103
+ };
104
+ const onPickerChange = (value, column) => {
105
+ // onPickerChange--- ["无脊柱动物", "节肢动物", "吸血虫"] 1 拿着column
106
+ const changeIndex = getColumnIndexByValue(data, column, value);
107
+ bindcolumnchange && bindcolumnchange(changeIndex, column);
108
+ };
109
+ const onElementLayout = () => {
110
+ viewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
111
+ layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
112
+ props.getInnerLayout && props.getInnerLayout(layoutRef);
113
+ });
114
+ };
115
+ const antPickerProps = {
116
+ data,
117
+ value: selected,
118
+ cols: range.length,
119
+ defaultValue: initValue,
120
+ disabled,
121
+ itemHeight: 40,
122
+ onChange,
123
+ onDismiss: bindcancel && bindcancel,
124
+ onPickerChange: onPickerChange
125
+ };
126
+ const touchProps = {
127
+ onLayout: onElementLayout,
128
+ ref: viewRef
129
+ };
130
+ return (<Picker {...antPickerProps}>
131
+ <TouchableWithoutFeedback>
132
+ <View {...touchProps}>
133
+ {children}
134
+ </View>
135
+ </TouchableWithoutFeedback>
136
+ </Picker>);
137
+ });
138
+ _MultiSelectorPicker.displayName = 'mpx-picker-multiselector';
139
+ export default _MultiSelectorPicker;
@@ -0,0 +1,90 @@
1
+ import { View, TouchableWithoutFeedback } from 'react-native';
2
+ import { Picker } from '@ant-design/react-native';
3
+ import { regionData } from './regionData';
4
+ import React, { forwardRef, useState, useRef } from 'react';
5
+ import useNodesRef from '../useNodesRef'; // 引入辅助函数
6
+ function formateRegionData(clObj = [], customItem, depth = 2) {
7
+ const l = depth;
8
+ const obj = [];
9
+ if (customItem) {
10
+ const objClone = {
11
+ value: customItem,
12
+ label: customItem,
13
+ children: []
14
+ };
15
+ const panding = { ...objClone };
16
+ let loop = panding;
17
+ while (depth-- > 0) {
18
+ loop.children = [{ ...objClone }];
19
+ loop = loop.children[0];
20
+ }
21
+ obj.push(panding);
22
+ }
23
+ for (let i = 0; i < clObj.length; i++) {
24
+ const region = {
25
+ value: clObj[i].value,
26
+ label: clObj[i].value,
27
+ };
28
+ if (clObj[i].children) {
29
+ region.children = formateRegionData(clObj[i].children, customItem, l - 1);
30
+ }
31
+ obj.push(region);
32
+ }
33
+ return obj;
34
+ }
35
+ const _RegionPicker = forwardRef((props, ref) => {
36
+ const { children, value, bindchange, bindcancel, disabled } = props;
37
+ let formatRegionData = formateRegionData(regionData, props['custom-item']);
38
+ const [regionvalue, setRegionValue] = useState(value);
39
+ // 存储layout布局信息
40
+ const layoutRef = useRef({});
41
+ const { nodeRef: viewRef } = useNodesRef(props, ref, {});
42
+ const onChange = (value) => {
43
+ // 通过 value 查找 code
44
+ let tmp = regionData;
45
+ const postcode = [];
46
+ const code = value.map((item) => {
47
+ for (let i = 0; i < tmp.length; i++) {
48
+ if (tmp[i].value === item) {
49
+ const code = tmp[i].code;
50
+ postcode.push(tmp[i].postcode);
51
+ tmp = tmp[i].children || [];
52
+ return code;
53
+ }
54
+ }
55
+ }).filter(code => !!code);
56
+ const detail = { value, code };
57
+ if (postcode[2])
58
+ detail.postcode = postcode[2];
59
+ setRegionValue(value);
60
+ bindchange && bindchange({
61
+ detail
62
+ });
63
+ };
64
+ const onElementLayout = (layout) => {
65
+ viewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
66
+ layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
67
+ props.getInnerLayout && props.getInnerLayout(layoutRef);
68
+ });
69
+ };
70
+ const regionProps = {
71
+ data: formatRegionData,
72
+ value: regionvalue,
73
+ onChange,
74
+ disabled,
75
+ onDismiss: bindcancel && bindcancel
76
+ };
77
+ const touchProps = {
78
+ onLayout: onElementLayout,
79
+ ref: viewRef
80
+ };
81
+ return (
82
+ // @ts-ignore
83
+ <Picker {...regionProps}>
84
+ <TouchableWithoutFeedback>
85
+ <View {...touchProps}>{children}</View>
86
+ </TouchableWithoutFeedback>
87
+ </Picker>);
88
+ });
89
+ _RegionPicker.displayName === 'mpx-picker-region';
90
+ export default _RegionPicker;