@mpxjs/webpack-plugin 2.10.16-beta.7 → 2.10.17-beta.1

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 (58) hide show
  1. package/lib/config.js +0 -60
  2. package/lib/file-loader.js +3 -13
  3. package/lib/json-compiler/index.js +2 -2
  4. package/lib/platform/json/wx/index.js +0 -6
  5. package/lib/platform/template/wx/component-config/ad.js +0 -5
  6. package/lib/platform/template/wx/component-config/button.js +2 -9
  7. package/lib/platform/template/wx/component-config/camera.js +3 -25
  8. package/lib/platform/template/wx/component-config/canvas.js +1 -8
  9. package/lib/platform/template/wx/component-config/cover-image.js +2 -7
  10. package/lib/platform/template/wx/component-config/cover-view.js +1 -3
  11. package/lib/platform/template/wx/component-config/form.js +2 -27
  12. package/lib/platform/template/wx/component-config/image.js +0 -5
  13. package/lib/platform/template/wx/component-config/input.js +0 -10
  14. package/lib/platform/template/wx/component-config/label.js +2 -10
  15. package/lib/platform/template/wx/component-config/map.js +0 -11
  16. package/lib/platform/template/wx/component-config/movable-area.js +1 -4
  17. package/lib/platform/template/wx/component-config/movable-view.js +2 -17
  18. package/lib/platform/template/wx/component-config/navigator.js +0 -26
  19. package/lib/platform/template/wx/component-config/picker-view.js +0 -12
  20. package/lib/platform/template/wx/component-config/picker.js +1 -3
  21. package/lib/platform/template/wx/component-config/progress.js +1 -11
  22. package/lib/platform/template/wx/component-config/rich-text.js +0 -5
  23. package/lib/platform/template/wx/component-config/scroll-view.js +1 -12
  24. package/lib/platform/template/wx/component-config/slider.js +0 -8
  25. package/lib/platform/template/wx/component-config/swiper-item.js +2 -5
  26. package/lib/platform/template/wx/component-config/swiper.js +0 -10
  27. package/lib/platform/template/wx/component-config/text.js +0 -5
  28. package/lib/platform/template/wx/component-config/textarea.js +2 -19
  29. package/lib/platform/template/wx/component-config/unsupported.js +1 -10
  30. package/lib/platform/template/wx/component-config/video.js +0 -10
  31. package/lib/platform/template/wx/index.js +1 -21
  32. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  33. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -1
  34. package/lib/runtime/components/react/dist/mpx-image.jsx +26 -20
  35. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -1
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +1 -3
  37. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  38. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -1
  39. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -3
  40. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  41. package/lib/runtime/components/react/mpx-image.tsx +41 -35
  42. package/lib/runtime/components/react/mpx-input.tsx +1 -3
  43. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  44. package/lib/runtime/components/react/mpx-web-view.tsx +14 -5
  45. package/lib/runtime/stringify.wxs +2 -2
  46. package/lib/style-compiler/strip-conditional-loader.js +142 -90
  47. package/lib/template-compiler/bind-this.js +2 -2
  48. package/lib/template-compiler/compiler.js +3 -4
  49. package/lib/template-compiler/index.js +6 -6
  50. package/lib/utils/dom-tag-config.js +1 -1
  51. package/lib/utils/merge-visitors.js +55 -0
  52. package/lib/wxs/pre-loader.js +8 -5
  53. package/package.json +3 -12
  54. package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -28
  55. package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +0 -1
  56. package/lib/runtime/components/react/dist/mpx-camera.jsx +0 -102
  57. package/lib/runtime/components/react/mpx-camera.tsx +0 -167
  58. package/lib/utils/chain-assign.js +0 -47
@@ -1,102 +0,0 @@
1
- import React, { forwardRef, useRef, useCallback, useContext, useState, useEffect } from 'react';
2
- import { Camera, useCameraDevice, useCodeScanner, useCameraFormat } from 'react-native-vision-camera';
3
- import { getCustomEvent } from './getInnerListeners';
4
- import { RouteContext } from './context';
5
- const _camera = forwardRef((props, ref) => {
6
- const cameraRef = useRef(null);
7
- const { mode = 'normal', resolution = 'medium', devicePosition = 'back', flash = 'auto', frameSize = 'medium', bindinitdone, bindstop, bindscancode } = props;
8
- const isPhoto = mode === 'normal';
9
- const device = useCameraDevice(devicePosition || 'back');
10
- const { navigation } = useContext(RouteContext) || {};
11
- const [zoomValue, setZoomValue] = useState(1);
12
- const [hasPermission, setHasPermission] = useState(null);
13
- // 先定义常量,避免在条件判断后使用
14
- const maxZoom = device?.maxZoom || 1;
15
- const RESOLUTION_MAPPING = {
16
- low: { width: 640, height: 480 },
17
- medium: { width: 1280, height: 720 },
18
- high: { width: 1920, height: 1080 }
19
- };
20
- const FRAME_SIZE_MAPPING = {
21
- small: { width: 480, height: 360 },
22
- medium: { width: 720, height: 540 },
23
- large: { width: 1080, height: 810 }
24
- };
25
- // 所有 Hooks 必须在条件判断之前调用
26
- const format = useCameraFormat(device, [
27
- {
28
- photoResolution: RESOLUTION_MAPPING[resolution],
29
- videoResolution: FRAME_SIZE_MAPPING[frameSize] || RESOLUTION_MAPPING[resolution]
30
- }
31
- ]);
32
- const codeScanner = useCodeScanner({
33
- codeTypes: ['qr', 'ean-13'],
34
- onCodeScanned: (codes) => {
35
- const result = codes.map(code => code.value).join(',');
36
- bindscancode && bindscancode(getCustomEvent('scancode', {}, {
37
- detail: {
38
- result: codes.map(code => code.value).join(',')
39
- }
40
- }));
41
- }
42
- });
43
- const onInitialized = useCallback(() => {
44
- bindinitdone && bindinitdone(getCustomEvent('initdone', {}, {
45
- detail: {
46
- maxZoom
47
- }
48
- }));
49
- }, [bindinitdone, maxZoom]);
50
- const onStopped = useCallback(() => {
51
- bindstop && bindstop();
52
- }, [bindstop]);
53
- // 检查相机权限
54
- useEffect(() => {
55
- const checkCameraPermission = async () => {
56
- try {
57
- const cameraPermission = global?.__mpx?.config?.rnConfig?.cameraPermission;
58
- if (typeof cameraPermission === 'function') {
59
- const permissionResult = await cameraPermission();
60
- setHasPermission(permissionResult === true);
61
- }
62
- else {
63
- setHasPermission(true);
64
- }
65
- }
66
- catch (error) {
67
- setHasPermission(false);
68
- }
69
- };
70
- checkCameraPermission();
71
- }, []);
72
- const camera = {
73
- setZoom: (zoom) => {
74
- setZoomValue(zoom);
75
- },
76
- getTakePhoto: () => {
77
- return cameraRef.current?.takePhoto;
78
- },
79
- getStartRecord: () => {
80
- return cameraRef.current?.startRecording;
81
- },
82
- getStopRecord: () => {
83
- return cameraRef.current?.stopRecording;
84
- }
85
- };
86
- if (navigation) {
87
- navigation.camera = camera;
88
- }
89
- // 所有 Hooks 调用完成后再进行条件判断
90
- if (hasPermission === null) {
91
- return null;
92
- }
93
- if (!hasPermission) {
94
- return null;
95
- }
96
- if (!device) {
97
- return null;
98
- }
99
- return (<Camera ref={cameraRef} isActive={true} photo={isPhoto} video={true} onInitialized={onInitialized} onStopped={onStopped} device={device} flash={flash} format={format} codeScanner={!isPhoto ? codeScanner : undefined} style={{ flex: 1 }} zoom={zoomValue} {...props}/>);
100
- });
101
- _camera.displayName = 'MpxCamera';
102
- export default _camera;
@@ -1,167 +0,0 @@
1
- import React, { forwardRef, useRef, useCallback, useContext, useState, useEffect } from 'react'
2
- import { Camera, useCameraDevice, useCodeScanner, useCameraFormat, useFrameProcessor } from 'react-native-vision-camera'
3
- import { getCustomEvent } from './getInnerListeners'
4
- import { RouteContext } from './context'
5
-
6
- interface CameraProps {
7
- mode?: 'normal' | 'scanCode'
8
- resolution?: 'low' | 'medium' | 'high'
9
- devicePosition?: 'front' | 'back'
10
- flash?: 'auto' | 'on' | 'off'
11
- frameSize?: 'small' | 'medium' | 'large'
12
- style?: Record<string, any>
13
- bindstop?: () => void
14
- binderror?: (error: { message: string }) => void
15
- bindinitdone?: (result: { type: string, data: string }) => void
16
- bindscancode?: (result: { type: string, data: string }) => void
17
- }
18
-
19
- interface CameraRef {
20
- setZoom: (zoom: number) => void
21
- getTakePhoto: () => (() => Promise<any>) | undefined
22
- getStartRecord: () => ((options: any) => void) | undefined
23
- getStopRecord: () => (() => void) | undefined
24
- }
25
-
26
- type HandlerRef<T, P> = {
27
- // 根据实际的 HandlerRef 类型定义调整
28
- current: T | null
29
- }
30
-
31
- const _camera = forwardRef<HandlerRef<Camera, CameraProps>, CameraProps>((props: CameraProps, ref): JSX.Element | null => {
32
- const cameraRef = useRef<Camera>(null)
33
- const {
34
- mode = 'normal',
35
- resolution = 'medium',
36
- devicePosition = 'back',
37
- flash = 'auto',
38
- frameSize = 'medium',
39
- bindinitdone,
40
- bindstop,
41
- bindscancode
42
- } = props
43
-
44
- const isPhoto = mode === 'normal'
45
- const device = useCameraDevice(devicePosition || 'back')
46
- const { navigation } = useContext(RouteContext) || {}
47
- const [zoomValue, setZoomValue] = useState<number>(1)
48
- const [hasPermission, setHasPermission] = useState<boolean | null>(null)
49
-
50
- // 先定义常量,避免在条件判断后使用
51
- const maxZoom = device?.maxZoom || 1
52
- const RESOLUTION_MAPPING: Record<string, { width: number, height: number }> = {
53
- low: { width: 640, height: 480 },
54
- medium: { width: 1280, height: 720 },
55
- high: { width: 1920, height: 1080 }
56
- }
57
- const FRAME_SIZE_MAPPING: Record<string, { width: number, height: number }> = {
58
- small: { width: 480, height: 360 },
59
- medium: { width: 720, height: 540 },
60
- large: { width: 1080, height: 810 }
61
- }
62
-
63
- // 所有 Hooks 必须在条件判断之前调用
64
- const format = useCameraFormat(device, [
65
- {
66
- photoResolution: RESOLUTION_MAPPING[resolution],
67
- videoResolution: FRAME_SIZE_MAPPING[frameSize] || RESOLUTION_MAPPING[resolution]
68
- }
69
- ])
70
-
71
- const codeScanner = useCodeScanner({
72
- codeTypes: ['qr', 'ean-13'],
73
- onCodeScanned: (codes) => {
74
- const result = codes.map(code => code.value).join(',')
75
- bindscancode && bindscancode(getCustomEvent('scancode', {}, {
76
- detail: {
77
- result: codes.map(code => code.value).join(',')
78
- }
79
- }))
80
- }
81
- })
82
-
83
- const onInitialized = useCallback(() => {
84
- bindinitdone && bindinitdone(getCustomEvent('initdone', {}, {
85
- detail: {
86
- maxZoom
87
- }
88
- }))
89
- }, [bindinitdone, maxZoom])
90
-
91
- const onStopped = useCallback(() => {
92
- bindstop && bindstop()
93
- }, [bindstop])
94
-
95
- // 检查相机权限
96
- useEffect(() => {
97
- const checkCameraPermission = async () => {
98
- try {
99
- const cameraPermission = global?.__mpx?.config?.rnConfig?.cameraPermission
100
- if (typeof cameraPermission === 'function') {
101
- const permissionResult = await cameraPermission()
102
- setHasPermission(permissionResult === true)
103
- } else {
104
- setHasPermission(true)
105
- }
106
- } catch (error) {
107
- setHasPermission(false)
108
- }
109
- }
110
-
111
- checkCameraPermission()
112
- }, [])
113
-
114
- const camera: CameraRef = {
115
- setZoom: (zoom: number) => {
116
- setZoomValue(zoom)
117
- },
118
- getTakePhoto: () => {
119
- return cameraRef.current?.takePhoto
120
- },
121
- getStartRecord: () => {
122
- return cameraRef.current?.startRecording
123
- },
124
- getStopRecord: () => {
125
- return cameraRef.current?.stopRecording
126
- }
127
- }
128
-
129
- if (navigation) {
130
- navigation.camera = camera
131
- }
132
-
133
- // 所有 Hooks 调用完成后再进行条件判断
134
- if (hasPermission === null) {
135
- return null
136
- }
137
-
138
- if (!hasPermission) {
139
- return null
140
- }
141
-
142
- if (!device) {
143
- return null
144
- }
145
-
146
- return (
147
- <Camera
148
- ref={cameraRef}
149
- isActive={true}
150
- photo={isPhoto}
151
- video={true}
152
- onInitialized={onInitialized}
153
- onStopped={onStopped}
154
- device={device}
155
- flash={flash}
156
- format={format}
157
- codeScanner={!isPhoto ? codeScanner : undefined}
158
- style={{ flex: 1 }}
159
- zoom={zoomValue}
160
- {...props}
161
- />
162
- )
163
- })
164
-
165
- _camera.displayName = 'MpxCamera'
166
-
167
- export default _camera
@@ -1,47 +0,0 @@
1
- /**
2
- * 链式合并方法的工具函数
3
- *
4
- * 在多条件分支下使用 Object.assign 会导致同名方法被覆盖,
5
- * 这个函数通过创建组合函数来确保所有方法都能按顺序执行。
6
- *
7
- * @param {Object} target - 目标 visitor 对象
8
- * @param {Object} source - 要链式分配的 visitor 方法对象
9
- *
10
- * @example
11
- * const visitor = {}
12
- *
13
- * // 第一次合并
14
- * chainAssign(visitor, {
15
- * CallExpression(path) {
16
- * console.log('第一个处理器')
17
- * }
18
- * })
19
- *
20
- * // 第二次合并 - 不会覆盖,而是组合执行
21
- * chainAssign(visitor, {
22
- * CallExpression(path) {
23
- * console.log('第二个处理器')
24
- * }
25
- * })
26
- *
27
- * // 执行时会依次输出:
28
- * // 第一个处理器
29
- * // 第二个处理器
30
- */
31
- module.exports = function chainAssign (target, source) {
32
- for (const [key, value] of Object.entries(source)) {
33
- if (target[key]) {
34
- // 如果已存在同名方法,创建组合函数依次执行
35
- const originalMethod = target[key]
36
- target[key] = function (path) {
37
- originalMethod.call(this, path)
38
- // 只有当节点没有停止遍历或被移除时才继续执行
39
- if (!path.removed && !path.shouldStop) {
40
- value.call(this, path)
41
- }
42
- }
43
- } else {
44
- target[key] = value
45
- }
46
- }
47
- }