@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
@@ -0,0 +1,142 @@
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
+ const 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
+ const 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
+ return ritem;
64
+ });
65
+ }
66
+ else {
67
+ curRange.map((citem, cindex) => {
68
+ if (citem.value === item) {
69
+ tmpRange = citem.children;
70
+ }
71
+ return citem;
72
+ });
73
+ curRange = tmpRange;
74
+ }
75
+ return item;
76
+ });
77
+ return changeIndex;
78
+ }
79
+ const _MultiSelectorPicker = forwardRef((props, ref) => {
80
+ const { range, value, disabled, bindchange, bindcancel, children, bindcolumnchange } = props;
81
+ const formatRange = formatRangeFun(range, props['range-key']);
82
+ const initValue = getInnerValueByIndex(formatRange, value);
83
+ // 选中的索引值
84
+ const [selected, setSelected] = useState(initValue);
85
+ // range数据源
86
+ const [data, setData] = useState(formatRange || []);
87
+ // 存储layout布局信息
88
+ const layoutRef = useRef({});
89
+ const { nodeRef: viewRef } = useNodesRef(props, ref, {});
90
+ useEffect(() => {
91
+ if (range) {
92
+ const newFormatRange = formatRangeFun(range, props['range-key']);
93
+ setData(newFormatRange);
94
+ }
95
+ const newValue = getInnerValueByIndex(formatRange, value);
96
+ value && setSelected(newValue);
97
+ }, [range, value]);
98
+ const onChange = (value) => {
99
+ // e.detail.value 都是索引multi
100
+ const strIndex = getIndexByValues(data, value);
101
+ bindchange && bindchange({
102
+ detail: {
103
+ value: strIndex
104
+ }
105
+ });
106
+ };
107
+ const onPickerChange = (value, column) => {
108
+ // onPickerChange--- ["无脊柱动物", "节肢动物", "吸血虫"] 1 拿着column
109
+ const changeIndex = getColumnIndexByValue(data, column, value);
110
+ bindcolumnchange && bindcolumnchange(changeIndex, column);
111
+ };
112
+ const onElementLayout = () => {
113
+ viewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
114
+ layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
115
+ props.getInnerLayout && props.getInnerLayout(layoutRef);
116
+ });
117
+ };
118
+ const antPickerProps = {
119
+ data,
120
+ value: selected,
121
+ cols: range.length,
122
+ defaultValue: initValue,
123
+ disabled,
124
+ itemHeight: 40,
125
+ onChange,
126
+ onDismiss: bindcancel && bindcancel,
127
+ onPickerChange: onPickerChange
128
+ };
129
+ const touchProps = {
130
+ onLayout: onElementLayout,
131
+ ref: viewRef
132
+ };
133
+ return (<Picker {...antPickerProps}>
134
+ <TouchableWithoutFeedback>
135
+ <View {...touchProps}>
136
+ {children}
137
+ </View>
138
+ </TouchableWithoutFeedback>
139
+ </Picker>);
140
+ });
141
+ _MultiSelectorPicker.displayName = 'mpx-picker-multiselector';
142
+ export default _MultiSelectorPicker;
@@ -0,0 +1,94 @@
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
+ // 'PickerData[]' is not assignable to type 'PickerColumn | PickerColumn[]'.
9
+ // const obj: PickerColumnItem[] = []
10
+ const obj = [];
11
+ if (customItem) {
12
+ const objClone = {
13
+ value: customItem,
14
+ label: customItem,
15
+ children: []
16
+ };
17
+ const panding = { ...objClone };
18
+ let loop = panding;
19
+ while (depth-- > 0) {
20
+ loop.children = [{ ...objClone }];
21
+ loop = loop.children[0];
22
+ }
23
+ obj.push(panding);
24
+ }
25
+ for (let i = 0; i < clObj.length; i++) {
26
+ const region = {
27
+ value: clObj[i].value,
28
+ label: clObj[i].value
29
+ };
30
+ if (clObj[i].children) {
31
+ region.children = formateRegionData(clObj[i].children, customItem, l - 1);
32
+ }
33
+ obj.push(region);
34
+ }
35
+ return obj;
36
+ }
37
+ const _RegionPicker = forwardRef((props, ref) => {
38
+ const { children, value, bindchange, bindcancel, disabled } = props;
39
+ const formatRegionData = formateRegionData(regionData, props['custom-item']);
40
+ const [regionvalue, setRegionValue] = useState(value);
41
+ // 存储layout布局信息
42
+ const layoutRef = useRef({});
43
+ const { nodeRef: viewRef } = useNodesRef(props, ref, {});
44
+ const onChange = (value) => {
45
+ // 通过 value 查找 code
46
+ let tmp = regionData;
47
+ const postcode = [];
48
+ const code = value.map((item) => {
49
+ for (let i = 0; i < tmp.length; i++) {
50
+ if (tmp[i].value === item) {
51
+ const code = tmp[i].code;
52
+ postcode.push(tmp[i].postcode);
53
+ tmp = tmp[i].children || [];
54
+ return code;
55
+ }
56
+ }
57
+ return item;
58
+ }).filter(code => !!code);
59
+ const detail = { value, code };
60
+ if (postcode[2])
61
+ detail.postcode = postcode[2];
62
+ setRegionValue(value);
63
+ bindchange && bindchange({
64
+ detail
65
+ });
66
+ };
67
+ const onElementLayout = (layout) => {
68
+ viewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
69
+ layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
70
+ props.getInnerLayout && props.getInnerLayout(layoutRef);
71
+ });
72
+ };
73
+ const onDismiss = () => {
74
+ bindcancel && bindcancel();
75
+ };
76
+ const regionProps = {
77
+ data: formatRegionData,
78
+ value: regionvalue,
79
+ onChange,
80
+ disabled,
81
+ onDismiss
82
+ };
83
+ const touchProps = {
84
+ onLayout: onElementLayout,
85
+ ref: viewRef
86
+ };
87
+ return (<Picker {...regionProps}>
88
+ <TouchableWithoutFeedback>
89
+ <View {...touchProps}>{children}</View>
90
+ </TouchableWithoutFeedback>
91
+ </Picker>);
92
+ });
93
+ _RegionPicker.displayName = 'mpx-picker-region';
94
+ export default _RegionPicker;