@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,155 @@
1
+ import { View } from 'react-native'
2
+ import { PickerValue } from '@ant-design/react-native'
3
+ import React, { forwardRef, useRef, useContext, useState } from 'react'
4
+ import useInnerProps, { getCustomEvent } from '../getInnerListeners'
5
+ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
6
+ import Selector from './selector'
7
+ import TimeSelector from './time'
8
+ import DateSelector from './date'
9
+ import MultiSelector from './multiSelector'
10
+ import RegionSelector from './region'
11
+ import { PickerProps, EventType, ValueType } from './type'
12
+ import { FormContext, FormFieldValue } from '../context'
13
+ import { throwReactWarning } from '../utils'
14
+
15
+ /**
16
+ * ✔ mode
17
+ * ✔ disabled
18
+ * ✔ bindcancel
19
+ * ✔ bindchange
20
+ * ✔ range
21
+ * ✔ range-key
22
+ * ✔ value
23
+ * ✔ start
24
+ * ✔ end
25
+ * ✔ fields 有效值 year,month,day,表示选择器的粒度
26
+ * ✔ end
27
+ * ✔ custom-item
28
+ * ✔ level 选择器层级 province,city,region,<sub-district不支持>
29
+ * ✔ level
30
+ * ✘ header-text
31
+ * ✘ bindcolumnchange
32
+ */
33
+
34
+ const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: PickerProps, ref): React.JSX.Element => {
35
+ const { mode = 'selector', value, bindcancel, bindchange, children, bindcolumnchange } = props
36
+ let innerLayout = useRef({})
37
+ const { nodeRef } = useNodesRef<View, PickerProps>(props, ref, {
38
+ })
39
+ const innerProps = useInnerProps(props, {
40
+ ref: nodeRef
41
+ }, [], { layoutRef: innerLayout })
42
+
43
+ const [pickerValue, setPickerValue] = useState(value as ValueType)
44
+ const defaultValues = {
45
+ selector: 0,
46
+ multiSelector: [0],
47
+ time: props.start,
48
+ date: props.start,
49
+ region: undefined
50
+ }
51
+
52
+ const formContext = useContext(FormContext)
53
+
54
+ let formValuesMap: Map<string, FormFieldValue> | undefined
55
+
56
+ // 判断 context 是否存在,存在的话读取 context 中存的 formValuesMap
57
+ if (formContext) {
58
+ formValuesMap = formContext.formValuesMap
59
+ }
60
+
61
+ const resetValue = () => {
62
+ type curMode = keyof typeof defaultValues
63
+ const defalutValue = (defaultValues[mode as curMode] !== undefined ? defaultValues[mode as curMode] : value) as ValueType
64
+ setPickerValue(defalutValue)
65
+ }
66
+
67
+ const getValue = () => {
68
+ return pickerValue
69
+ }
70
+ if (formValuesMap) {
71
+ if (!props.name) {
72
+ throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
73
+ } else {
74
+ formValuesMap.set(props.name, { getValue, resetValue })
75
+ }
76
+ }
77
+
78
+ const getInnerLayout = (layout: React.MutableRefObject<{}>) => {
79
+ innerLayout.current = layout.current
80
+ }
81
+
82
+ const onChange = (event: EventType) => {
83
+ const eventData = getCustomEvent('change', {}, { detail: event.detail, layoutRef: innerLayout })
84
+ bindchange && bindchange(eventData)
85
+ setPickerValue(event.detail.value as ValueType)
86
+ }
87
+
88
+ const columnChange = (value: PickerValue[], index: number) => {
89
+ // type: "columnchange", detail: {column: 1, value: 2}
90
+ const eventData = getCustomEvent('columnchange', {}, { detail: { column: index, value }, layoutRef: innerLayout })
91
+ bindcolumnchange && bindcolumnchange(eventData)
92
+ }
93
+ const commonProps = {
94
+ ...{ innerProps },
95
+ mode,
96
+ children,
97
+ bindchange: onChange,
98
+ bindcolumnchange: columnChange,
99
+ bindcancel,
100
+ getInnerLayout
101
+ }
102
+
103
+ const selectorProps = {
104
+ ...commonProps,
105
+ value: pickerValue as PickerValue,
106
+ range: props['range'],
107
+ 'range-key': props['range-key']
108
+ }
109
+
110
+ const multiProps = {
111
+ ...commonProps,
112
+ value: pickerValue as Array<number>,
113
+ range: props['range'],
114
+ 'range-key': props['range-key']
115
+ }
116
+
117
+ const timeProps = {
118
+ ...commonProps,
119
+ value: pickerValue as string,
120
+ start: props['start'],
121
+ end: props['end']
122
+ }
123
+
124
+ const dateProps = {
125
+ ...commonProps,
126
+ value: pickerValue as string,
127
+ start: props['start'],
128
+ end: props['end'],
129
+ fileds: props.fields || 'day'
130
+ }
131
+
132
+ const regionProps = {
133
+ ...commonProps,
134
+ value: pickerValue as Array<string>,
135
+ level: props.level || 'sub-district'
136
+ }
137
+
138
+ if (mode === 'selector') {
139
+ return <Selector {...selectorProps}></Selector>
140
+ } else if (mode === 'multiSelector') {
141
+ return <MultiSelector {...multiProps}></MultiSelector>
142
+ } else if (mode === 'time') {
143
+ return <TimeSelector {...timeProps}></TimeSelector>
144
+ } else if (mode === 'date') {
145
+ return <DateSelector {...dateProps}></DateSelector>
146
+ } else if (mode === 'region') {
147
+ return <RegionSelector {...regionProps}></RegionSelector>
148
+ } else {
149
+ return <View>只支持selector, multiSelector, time, date, region 这些类型</View>
150
+ }
151
+ })
152
+
153
+ _Picker.displayName = 'mpx-picker';
154
+
155
+ export default _Picker
@@ -0,0 +1,153 @@
1
+ import { View, TouchableWithoutFeedback } from 'react-native'
2
+ import { Picker, PickerValue } from '@ant-design/react-native'
3
+ import React, { forwardRef, useState, useRef, useEffect } from 'react'
4
+ import { MultiSelectorProps, LayoutType } from './type'
5
+ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
6
+
7
+ function convertToObj(item?: any, rangeKey = ''): any {
8
+ if (typeof item === 'object') {
9
+ return { value: item[rangeKey], label: item[rangeKey] }
10
+ } else {
11
+ return { value: item, label: item }
12
+ }
13
+ }
14
+
15
+ // eslint-disable-next-line default-param-last
16
+ function formatRangeFun(range: any[][] = [], rangeKey?: string): any[] {
17
+ const result = (range[0] || []).map(item => {
18
+ return convertToObj(item, rangeKey)
19
+ })
20
+ let tmp = result
21
+ for (let i = 1; i < range.length; i++) {
22
+ let child = Array.isArray(range[i]) ? range[i] : []
23
+ const nextColData = child.map(item => {
24
+ return convertToObj(item, rangeKey)
25
+ })
26
+ tmp.forEach(item => {
27
+ item.children = nextColData
28
+ })
29
+ tmp = nextColData
30
+ }
31
+ return result
32
+ }
33
+
34
+ function getIndexByValues(range: any[] = [], value: any[] = []): number[] {
35
+ let tmp = range
36
+ return value.map(v => {
37
+ for (let i = 0; i < tmp.length; i++) {
38
+ if (tmp[i].value === v) {
39
+ tmp = tmp[i].children || []
40
+ return i
41
+ }
42
+ }
43
+ return 0
44
+ })
45
+ }
46
+ // [1,1,2] 寻找出[]
47
+ function getInnerValueByIndex(range: any[] = [], value: any[] = []): string[] {
48
+ let tmp = range
49
+ return value.map(v => {
50
+ let current = tmp[v].value
51
+ tmp = tmp[v].children
52
+ return current
53
+ })
54
+ }
55
+ // column = 1 value = ['无脊柱动物', '扁性动物', '吸血虫'] 根据column 和value 获取到当前列变动选择的值所在当前列的索引
56
+ function getColumnIndexByValue(range: any[] = [], column: number, value: any[] = []): number {
57
+ let curRange = range
58
+ let changeIndex = 0
59
+ let tmpRange: any[] = []
60
+ value.map((item, index) => {
61
+ if (column === index) {
62
+ curRange.map((ritem, rindex) => {
63
+ if (ritem.value === item) {
64
+ changeIndex = rindex
65
+ }
66
+ })
67
+ } else {
68
+ curRange.map((citem, cindex) => {
69
+ if (citem.value === item) {
70
+ tmpRange = citem.children
71
+ }
72
+ })
73
+ curRange = tmpRange
74
+ }
75
+ })
76
+ return changeIndex
77
+ }
78
+
79
+ const _MultiSelectorPicker = forwardRef<HandlerRef<View, MultiSelectorProps>, MultiSelectorProps>((props: MultiSelectorProps, ref): React.JSX.Element => {
80
+ const { range, value, disabled, bindchange, bindcancel, children, bindcolumnchange } = props
81
+ let formatRange = formatRangeFun(range, props['range-key'])
82
+ let 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<View, MultiSelectorProps>(props, ref, {
90
+ })
91
+
92
+ useEffect(() => {
93
+ if (range) {
94
+ const newFormatRange = formatRangeFun(range, props['range-key'])
95
+ setData(newFormatRange)
96
+ }
97
+ const newValue = getInnerValueByIndex(formatRange, value)
98
+ value && setSelected(newValue)
99
+ }, [range, value])
100
+
101
+ const onChange = (value: PickerValue[]) => {
102
+ // e.detail.value 都是索引multi
103
+ const strIndex = getIndexByValues(data, value)
104
+ bindchange && bindchange({
105
+ detail: {
106
+ value: strIndex
107
+ }
108
+ })
109
+ }
110
+
111
+ const onPickerChange = (value: PickerValue[], column: number) => {
112
+ // onPickerChange--- ["无脊柱动物", "节肢动物", "吸血虫"] 1 拿着column
113
+ const changeIndex = getColumnIndexByValue(data, column, value)
114
+ bindcolumnchange && bindcolumnchange(changeIndex, column)
115
+ }
116
+
117
+ const onElementLayout = () => {
118
+ viewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
119
+ layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
120
+ props.getInnerLayout && props.getInnerLayout(layoutRef)
121
+ })
122
+ }
123
+
124
+ const antPickerProps = {
125
+ data,
126
+ value: selected,
127
+ cols: range.length,
128
+ defaultValue: initValue,
129
+ disabled,
130
+ itemHeight: 40,
131
+ onChange,
132
+ onDismiss: bindcancel && bindcancel,
133
+ onPickerChange: onPickerChange
134
+ } as any
135
+
136
+ const touchProps = {
137
+ onLayout: onElementLayout,
138
+ ref: viewRef
139
+ }
140
+
141
+ return (<Picker {...antPickerProps}>
142
+ <TouchableWithoutFeedback>
143
+ <View {...touchProps}>
144
+ {children}
145
+ </View>
146
+ </TouchableWithoutFeedback>
147
+ </Picker>
148
+ )
149
+ })
150
+
151
+ _MultiSelectorPicker.displayName = 'mpx-picker-multiselector'
152
+
153
+ export default _MultiSelectorPicker
@@ -0,0 +1,104 @@
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, { HandlerRef } from '../useNodesRef' // 引入辅助函数
6
+ import { RegionProps, RegionObj, PickerData, LayoutType } from './type'
7
+
8
+ function formateRegionData(clObj: RegionObj[] = [], customItem?: string, depth = 2): PickerData[] {
9
+ const l = depth
10
+ const obj: PickerData[] = []
11
+ if (customItem) {
12
+ const objClone: PickerData = {
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] as PickerData
22
+ }
23
+ obj.push(panding)
24
+ }
25
+ for (let i = 0; i < clObj.length; i++) {
26
+ const region: PickerData = {
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
+
38
+
39
+
40
+ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((props: RegionProps, ref): React.JSX.Element => {
41
+ const { children, value, bindchange, bindcancel, disabled } = props
42
+ let formatRegionData = formateRegionData(regionData, props['custom-item'])
43
+
44
+ const [regionvalue, setRegionValue] = useState(value)
45
+ // 存储layout布局信息
46
+ const layoutRef = useRef({})
47
+ const { nodeRef: viewRef } = useNodesRef<View, RegionProps>(props, ref, {
48
+ })
49
+
50
+ const onChange = (value: string[]): void => {
51
+ // 通过 value 查找 code
52
+ let tmp: RegionObj[] = regionData
53
+ const postcode: (string | undefined)[] = []
54
+ const code = value.map((item) => {
55
+ for (let i = 0; i < tmp.length; i++) {
56
+ if (tmp[i].value === item) {
57
+ const code = tmp[i].code
58
+ postcode.push(tmp[i].postcode)
59
+ tmp = tmp[i].children || []
60
+ return code
61
+ }
62
+ }
63
+ }).filter(code => !!code)
64
+ const detail: Record<string, any> = { value, code }
65
+ if (postcode[2]) detail.postcode = postcode[2]
66
+ setRegionValue(value)
67
+ bindchange && bindchange({
68
+ detail
69
+ })
70
+ }
71
+
72
+ const onElementLayout = (layout: LayoutType) => {
73
+ viewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
74
+ layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
75
+ props.getInnerLayout && props.getInnerLayout(layoutRef)
76
+ })
77
+ }
78
+
79
+ const regionProps = {
80
+ data: formatRegionData,
81
+ value: regionvalue,
82
+ onChange,
83
+ disabled,
84
+ onDismiss: bindcancel && bindcancel
85
+ }
86
+
87
+ const touchProps = {
88
+ onLayout: onElementLayout,
89
+ ref: viewRef
90
+ }
91
+
92
+ return (
93
+ // @ts-ignore
94
+ <Picker {...regionProps}>
95
+ <TouchableWithoutFeedback>
96
+ <View {...touchProps}>{children}</View>
97
+ </TouchableWithoutFeedback>
98
+ </Picker>
99
+ )
100
+
101
+ })
102
+
103
+ _RegionPicker.displayName === 'mpx-picker-region'
104
+ export default _RegionPicker