@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.0
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.
- package/lib/index.js +13 -8
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +35 -38
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolver/AddModePlugin.js +8 -8
- package/lib/runtime/components/react/context.ts +6 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
- package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
- package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
- package/lib/runtime/components/react/dist/utils.jsx +70 -23
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +237 -199
- package/lib/runtime/components/react/mpx-button.tsx +104 -57
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
- package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +92 -76
- package/lib/runtime/components/react/mpx-web-view.tsx +116 -54
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +5 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -11
- package/lib/runtime/components/react/utils.tsx +99 -28
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +79 -47
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +6 -4
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✘ type
|
|
3
|
+
* ✘ canvas-id
|
|
4
|
+
* ✘ disable-scroll
|
|
5
|
+
* ✔ bindtouchstart
|
|
6
|
+
* ✔ bindtouchmove
|
|
7
|
+
* ✔ bindtouchend
|
|
8
|
+
* ✔ bindtouchcancel
|
|
9
|
+
* ✔ bindlongtap
|
|
10
|
+
* ✔ binderror
|
|
11
|
+
*/
|
|
12
|
+
import { createElement, useRef, useState, useCallback, useEffect, forwardRef } from 'react';
|
|
13
|
+
import { View, Platform, StyleSheet } from 'react-native';
|
|
14
|
+
import { WebView } from 'react-native-webview';
|
|
15
|
+
import useNodesRef from '../useNodesRef';
|
|
16
|
+
import { useLayout, useTransformStyle, extendObject } from '../utils';
|
|
17
|
+
import useInnerProps, { getCustomEvent } from '../getInnerListeners';
|
|
18
|
+
import Bus from './Bus';
|
|
19
|
+
import { useWebviewBinding, constructors, WEBVIEW_TARGET, ID, registerWebviewConstructor } from './utils';
|
|
20
|
+
import CanvasRenderingContext2D from './CanvasRenderingContext2D';
|
|
21
|
+
import html from './html';
|
|
22
|
+
import './CanvasGradient';
|
|
23
|
+
import { createImage as canvasCreateImage } from './Image';
|
|
24
|
+
import { createImageData as canvasCreateImageData } from './ImageData';
|
|
25
|
+
import { useConstructorsRegistry } from './constructorsRegistry';
|
|
26
|
+
const stylesheet = StyleSheet.create({
|
|
27
|
+
container: { overflow: 'hidden', flex: 0 },
|
|
28
|
+
webview: {
|
|
29
|
+
overflow: 'hidden',
|
|
30
|
+
backgroundColor: 'transparent',
|
|
31
|
+
flex: 0
|
|
32
|
+
},
|
|
33
|
+
webviewAndroid9: {
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
backgroundColor: 'transparent',
|
|
36
|
+
flex: 0,
|
|
37
|
+
opacity: 0.99
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const _Canvas = forwardRef((props = {}, ref) => {
|
|
41
|
+
const { style = {}, originWhitelist = ['*'], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
42
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
43
|
+
const nodeRef = useRef(null);
|
|
44
|
+
const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(extendObject({}, style, stylesheet.container), {
|
|
45
|
+
enableVar,
|
|
46
|
+
externalVarContext,
|
|
47
|
+
parentFontSize,
|
|
48
|
+
parentWidth,
|
|
49
|
+
parentHeight
|
|
50
|
+
});
|
|
51
|
+
const { width, height } = normalStyle;
|
|
52
|
+
const canvasRef = useWebviewBinding({
|
|
53
|
+
targetName: 'canvas',
|
|
54
|
+
properties: { width, height },
|
|
55
|
+
methods: ['toDataURL']
|
|
56
|
+
});
|
|
57
|
+
const { register } = useConstructorsRegistry();
|
|
58
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
59
|
+
const innerProps = useInnerProps(props, {
|
|
60
|
+
ref: nodeRef,
|
|
61
|
+
style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 }),
|
|
62
|
+
...layoutProps
|
|
63
|
+
}, [], {
|
|
64
|
+
layoutRef
|
|
65
|
+
});
|
|
66
|
+
const context2D = new CanvasRenderingContext2D(canvasRef.current);
|
|
67
|
+
register(registerWebviewConstructor);
|
|
68
|
+
// 初始化bus和context2D
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const webviewPostMessage = (message) => {
|
|
71
|
+
if (canvasRef.current.webview) {
|
|
72
|
+
canvasRef.current.webview.postMessage(JSON.stringify(message));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
// 设置bus
|
|
76
|
+
canvasRef.current.bus = new Bus(webviewPostMessage);
|
|
77
|
+
canvasRef.current.bus.pause();
|
|
78
|
+
// 设置 context 2D
|
|
79
|
+
canvasRef.current.context2D = context2D;
|
|
80
|
+
// 设置 getContext 方法
|
|
81
|
+
canvasRef.current.getContext = getContext;
|
|
82
|
+
// 设置 createImage 方法
|
|
83
|
+
canvasRef.current.createImage = createImage;
|
|
84
|
+
// 设置 postMessage 方法
|
|
85
|
+
canvasRef.current.postMessage = postMessage;
|
|
86
|
+
// 设置 listeners
|
|
87
|
+
canvasRef.current.listeners = [];
|
|
88
|
+
canvasRef.current.addMessageListener = addMessageListener;
|
|
89
|
+
canvasRef.current.removeMessageListener = removeMessageListener;
|
|
90
|
+
canvasRef.current.createImageData = createImageData;
|
|
91
|
+
return () => {
|
|
92
|
+
canvasRef.current.bus?.clearBatchingTimeout();
|
|
93
|
+
};
|
|
94
|
+
}, []);
|
|
95
|
+
const createImageData = (dataArray, width, height) => {
|
|
96
|
+
return canvasCreateImageData(canvasRef.current, dataArray, width, height);
|
|
97
|
+
};
|
|
98
|
+
const createImage = (width, height) => {
|
|
99
|
+
return canvasCreateImage(canvasRef.current, width, height);
|
|
100
|
+
};
|
|
101
|
+
const getContext = useCallback((contextType) => {
|
|
102
|
+
if (contextType === '2d') {
|
|
103
|
+
return context2D;
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}, []);
|
|
107
|
+
const postMessage = useCallback(async (message) => {
|
|
108
|
+
if (!canvasRef.current?.bus)
|
|
109
|
+
return;
|
|
110
|
+
const { type, payload } = await canvasRef.current.bus.post({
|
|
111
|
+
id: ID(),
|
|
112
|
+
...message
|
|
113
|
+
});
|
|
114
|
+
switch (type) {
|
|
115
|
+
case 'error': {
|
|
116
|
+
const { binderror } = props;
|
|
117
|
+
binderror &&
|
|
118
|
+
binderror(getCustomEvent('error', {}, {
|
|
119
|
+
detail: {
|
|
120
|
+
errMsg: payload.message
|
|
121
|
+
},
|
|
122
|
+
layoutRef
|
|
123
|
+
}, props));
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case 'json': {
|
|
127
|
+
return payload;
|
|
128
|
+
}
|
|
129
|
+
case 'blob': {
|
|
130
|
+
return atob(payload);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, []);
|
|
134
|
+
const addMessageListener = (listener) => {
|
|
135
|
+
canvasRef.current.listeners.push(listener);
|
|
136
|
+
return () => canvasRef.current.removeMessageListener(listener);
|
|
137
|
+
};
|
|
138
|
+
const removeMessageListener = (listener) => {
|
|
139
|
+
canvasRef.current.listeners.splice(canvasRef.current.listeners.indexOf(listener), 1);
|
|
140
|
+
};
|
|
141
|
+
const onMessage = useCallback((e) => {
|
|
142
|
+
let data = JSON.parse(e.nativeEvent.data);
|
|
143
|
+
switch (data.type) {
|
|
144
|
+
case 'error': {
|
|
145
|
+
const { binderror } = props;
|
|
146
|
+
binderror &&
|
|
147
|
+
binderror(getCustomEvent('error', e, {
|
|
148
|
+
detail: {
|
|
149
|
+
errMsg: data.payload.message
|
|
150
|
+
},
|
|
151
|
+
layoutRef
|
|
152
|
+
}, props));
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
default: {
|
|
156
|
+
if (data.payload) {
|
|
157
|
+
// createLinearGradient 方法调用需要在 constructors 中需要注册 CanvasGradient
|
|
158
|
+
const constructor = constructors[data.meta.constructor];
|
|
159
|
+
if (constructor) {
|
|
160
|
+
const { args, payload } = data;
|
|
161
|
+
// RN 端同步生成一个 CanvasGradient 的实例
|
|
162
|
+
const object = constructor.constructLocally(canvasRef.current, ...args);
|
|
163
|
+
Object.assign(object, payload, {
|
|
164
|
+
[WEBVIEW_TARGET]: data.meta.target
|
|
165
|
+
});
|
|
166
|
+
data = {
|
|
167
|
+
...data,
|
|
168
|
+
payload: object
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
for (const listener of canvasRef.current.listeners) {
|
|
172
|
+
listener(data.payload);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (canvasRef.current.bus) {
|
|
176
|
+
canvasRef.current.bus.handle(data);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, []);
|
|
181
|
+
const onLoad = useCallback(() => {
|
|
182
|
+
setIsLoaded(true);
|
|
183
|
+
if (canvasRef.current?.bus) {
|
|
184
|
+
canvasRef.current.bus.resume();
|
|
185
|
+
}
|
|
186
|
+
}, []);
|
|
187
|
+
useNodesRef(props, ref, nodeRef, {
|
|
188
|
+
style: normalStyle,
|
|
189
|
+
node: canvasRef.current,
|
|
190
|
+
context: context2D
|
|
191
|
+
});
|
|
192
|
+
if (Platform.OS === 'android') {
|
|
193
|
+
const isAndroid9 = Platform.Version >= 28;
|
|
194
|
+
return createElement(View, innerProps, createElement(WebView, {
|
|
195
|
+
ref: (element) => {
|
|
196
|
+
if (canvasRef.current) {
|
|
197
|
+
canvasRef.current.webview = element;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
style: [
|
|
201
|
+
isAndroid9 ? stylesheet.webviewAndroid9 : stylesheet.webview,
|
|
202
|
+
{ height, width }
|
|
203
|
+
],
|
|
204
|
+
source: { html },
|
|
205
|
+
originWhitelist: originWhitelist,
|
|
206
|
+
onMessage: onMessage,
|
|
207
|
+
onLoad: onLoad,
|
|
208
|
+
overScrollMode: 'never',
|
|
209
|
+
mixedContentMode: 'always',
|
|
210
|
+
scalesPageToFit: false,
|
|
211
|
+
javaScriptEnabled: true,
|
|
212
|
+
domStorageEnabled: true,
|
|
213
|
+
thirdPartyCookiesEnabled: true,
|
|
214
|
+
allowUniversalAccessFromFileURLs: true
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
return createElement(View, innerProps, createElement(WebView, {
|
|
218
|
+
ref: (element) => {
|
|
219
|
+
if (canvasRef.current) {
|
|
220
|
+
canvasRef.current.webview = element;
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
style: [stylesheet.webview, { height, width }],
|
|
224
|
+
source: { html },
|
|
225
|
+
originWhitelist: originWhitelist,
|
|
226
|
+
onMessage: onMessage,
|
|
227
|
+
onLoad: onLoad,
|
|
228
|
+
scrollEnabled: false
|
|
229
|
+
}));
|
|
230
|
+
});
|
|
231
|
+
_Canvas.displayName = 'mpxCanvas';
|
|
232
|
+
export default _Canvas;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export const WEBVIEW_TARGET = '@@WEBVIEW_TARGET';
|
|
3
|
+
export const constructors = {};
|
|
4
|
+
export const ID = () => Math.random().toString(32).slice(2);
|
|
5
|
+
const SPECIAL_CONSTRUCTOR = {
|
|
6
|
+
ImageData: {
|
|
7
|
+
className: 'Uint8ClampedArray',
|
|
8
|
+
paramNum: 0
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export const registerWebviewTarget = (instance, targetName) => {
|
|
12
|
+
instance[WEBVIEW_TARGET] = targetName;
|
|
13
|
+
};
|
|
14
|
+
export const registerWebviewProperties = (instance, properties) => {
|
|
15
|
+
Object.entries(properties).forEach(([key, initialValue]) => {
|
|
16
|
+
const privateKey = `__${key}__`;
|
|
17
|
+
instance[privateKey] = initialValue;
|
|
18
|
+
Object.defineProperty(instance, key, {
|
|
19
|
+
configurable: true,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get() {
|
|
22
|
+
return instance[privateKey];
|
|
23
|
+
},
|
|
24
|
+
set(value) {
|
|
25
|
+
instance.postMessage({
|
|
26
|
+
type: 'set',
|
|
27
|
+
payload: {
|
|
28
|
+
target: instance[WEBVIEW_TARGET],
|
|
29
|
+
key,
|
|
30
|
+
value
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (instance.forceUpdate) {
|
|
34
|
+
instance.forceUpdate();
|
|
35
|
+
}
|
|
36
|
+
return (instance[privateKey] = value);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export const registerWebviewMethods = (instance, methods) => {
|
|
42
|
+
methods.forEach(method => {
|
|
43
|
+
instance[method] = (...args) => {
|
|
44
|
+
return instance.postMessage({
|
|
45
|
+
type: 'exec',
|
|
46
|
+
payload: {
|
|
47
|
+
target: instance[WEBVIEW_TARGET],
|
|
48
|
+
method,
|
|
49
|
+
args
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export const registerWebviewConstructor = (constructor, constructorName) => {
|
|
56
|
+
constructors[constructorName] = constructor;
|
|
57
|
+
constructor.constructLocally = function (...args) {
|
|
58
|
+
return new constructor(...args, true);
|
|
59
|
+
};
|
|
60
|
+
constructor.prototype.onConstruction = function (...args) {
|
|
61
|
+
if (SPECIAL_CONSTRUCTOR[constructorName] !== undefined) {
|
|
62
|
+
const { className, paramNum } = SPECIAL_CONSTRUCTOR[constructorName];
|
|
63
|
+
args[paramNum] = { className, classArgs: [args[paramNum]] };
|
|
64
|
+
}
|
|
65
|
+
this[WEBVIEW_TARGET] = ID();
|
|
66
|
+
this.postMessage({
|
|
67
|
+
type: 'construct',
|
|
68
|
+
payload: {
|
|
69
|
+
constructor: constructorName,
|
|
70
|
+
id: this[WEBVIEW_TARGET],
|
|
71
|
+
args
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
constructor.prototype.toJSON = function () {
|
|
76
|
+
return { __ref__: this[WEBVIEW_TARGET] };
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export const useWebviewBinding = ({ targetName, properties = {}, methods = [] }) => {
|
|
80
|
+
const instanceRef = useRef({});
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (instanceRef.current) {
|
|
83
|
+
registerWebviewTarget(instanceRef.current, targetName);
|
|
84
|
+
registerWebviewProperties(instanceRef.current, properties);
|
|
85
|
+
registerWebviewMethods(instanceRef.current, methods);
|
|
86
|
+
}
|
|
87
|
+
}, []);
|
|
88
|
+
return instanceRef;
|
|
89
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✔ bindchange
|
|
3
3
|
*/
|
|
4
|
-
import { useRef, forwardRef, useContext, useMemo, useEffect } from 'react';
|
|
4
|
+
import { useRef, forwardRef, useContext, useMemo, useEffect, createElement } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
6
|
import { warn } from '@mpxjs/utils';
|
|
7
7
|
import { FormContext, CheckboxGroupContext } from './context';
|
|
8
8
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
9
9
|
import useNodesRef from './useNodesRef';
|
|
10
|
-
import { useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
10
|
+
import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
|
|
11
11
|
const CheckboxGroup = forwardRef((props, ref) => {
|
|
12
12
|
const propsRef = useRef({});
|
|
13
13
|
propsRef.current = props;
|
|
@@ -22,13 +22,10 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
22
22
|
flexDirection: 'row',
|
|
23
23
|
flexWrap: 'wrap'
|
|
24
24
|
};
|
|
25
|
-
const styleObj = {
|
|
26
|
-
...defaultStyle,
|
|
27
|
-
...style
|
|
28
|
-
};
|
|
25
|
+
const styleObj = extendObject({}, defaultStyle, style);
|
|
29
26
|
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
30
27
|
const nodeRef = useRef(null);
|
|
31
|
-
useNodesRef(props, ref, nodeRef, {
|
|
28
|
+
useNodesRef(props, ref, nodeRef, { style: normalStyle });
|
|
32
29
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
33
30
|
const getValue = () => {
|
|
34
31
|
const arr = [];
|
|
@@ -60,11 +57,12 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
60
57
|
}
|
|
61
58
|
};
|
|
62
59
|
}, []);
|
|
63
|
-
const innerProps = useInnerProps(props, {
|
|
60
|
+
const innerProps = useInnerProps(props, extendObject({
|
|
64
61
|
ref: nodeRef,
|
|
65
|
-
style: {
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
style: extendObject({}, normalStyle, layoutStyle)
|
|
63
|
+
}, layoutProps), [
|
|
64
|
+
'name'
|
|
65
|
+
], {
|
|
68
66
|
layoutRef
|
|
69
67
|
});
|
|
70
68
|
const contextValue = useMemo(() => {
|
|
@@ -83,14 +81,10 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
83
81
|
notifyChange
|
|
84
82
|
};
|
|
85
83
|
}, []);
|
|
86
|
-
return (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
varContext: varContextRef.current
|
|
91
|
-
})}
|
|
92
|
-
</CheckboxGroupContext.Provider>
|
|
93
|
-
</View>);
|
|
84
|
+
return createElement(View, innerProps, createElement(CheckboxGroupContext.Provider, { value: contextValue }, wrapChildren(props, {
|
|
85
|
+
hasVarDec,
|
|
86
|
+
varContext: varContextRef.current
|
|
87
|
+
})));
|
|
94
88
|
});
|
|
95
89
|
CheckboxGroup.displayName = 'MpxCheckboxGroup';
|
|
96
90
|
export default CheckboxGroup;
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* ✔ checked
|
|
5
5
|
* ✔ color
|
|
6
6
|
*/
|
|
7
|
-
import { useState, useRef, forwardRef, useEffect, useContext } from 'react';
|
|
7
|
+
import { useState, useRef, forwardRef, useEffect, useContext, createElement } from 'react';
|
|
8
8
|
import { View, StyleSheet } from 'react-native';
|
|
9
9
|
import { warn } from '@mpxjs/utils';
|
|
10
10
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
11
11
|
import useNodesRef from './useNodesRef';
|
|
12
12
|
import Icon from './mpx-icon';
|
|
13
|
-
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
13
|
+
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
|
|
14
14
|
import { CheckboxGroupContext, LabelContext } from './context';
|
|
15
15
|
const styles = StyleSheet.create({
|
|
16
16
|
container: {
|
|
@@ -40,19 +40,13 @@ const styles = StyleSheet.create({
|
|
|
40
40
|
});
|
|
41
41
|
const Checkbox = forwardRef((checkboxProps, ref) => {
|
|
42
42
|
const { textProps, innerProps: props = {} } = splitProps(checkboxProps);
|
|
43
|
-
const { value = '', disabled = false, checked = false, color = '#09BB07', style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap,
|
|
43
|
+
const { value = '', disabled = false, checked = false, color = '#09BB07', style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap, _onChange } = props;
|
|
44
44
|
const [isChecked, setIsChecked] = useState(!!checked);
|
|
45
45
|
const groupContext = useContext(CheckboxGroupContext);
|
|
46
46
|
let groupValue;
|
|
47
47
|
let notifyChange;
|
|
48
|
-
const defaultStyle = {
|
|
49
|
-
|
|
50
|
-
...(disabled && styles.wrapperDisabled)
|
|
51
|
-
};
|
|
52
|
-
const styleObj = {
|
|
53
|
-
...styles.container,
|
|
54
|
-
...style
|
|
55
|
-
};
|
|
48
|
+
const defaultStyle = extendObject({}, styles.wrapper, disabled ? styles.wrapperDisabled : null);
|
|
49
|
+
const styleObj = extendObject({}, styles.container, style);
|
|
56
50
|
const onChange = (evt) => {
|
|
57
51
|
if (disabled)
|
|
58
52
|
return;
|
|
@@ -62,27 +56,21 @@ const Checkbox = forwardRef((checkboxProps, ref) => {
|
|
|
62
56
|
groupValue[value].checked = checked;
|
|
63
57
|
}
|
|
64
58
|
notifyChange && notifyChange(evt);
|
|
59
|
+
// Called when the switch type attribute is checkbox
|
|
60
|
+
_onChange && _onChange(evt, { checked });
|
|
65
61
|
};
|
|
66
62
|
const onTap = (evt) => {
|
|
67
|
-
if (disabled)
|
|
68
|
-
return;
|
|
69
63
|
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
70
64
|
onChange(evt);
|
|
71
65
|
};
|
|
72
|
-
const catchTap = (evt) => {
|
|
73
|
-
if (disabled)
|
|
74
|
-
return;
|
|
75
|
-
catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
76
|
-
onChange(evt);
|
|
77
|
-
};
|
|
78
66
|
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
79
67
|
const nodeRef = useRef(null);
|
|
80
68
|
useNodesRef(props, ref, nodeRef, {
|
|
81
|
-
defaultStyle,
|
|
69
|
+
style: extendObject({}, defaultStyle, normalStyle),
|
|
82
70
|
change: onChange
|
|
83
71
|
});
|
|
84
72
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
85
|
-
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
|
|
73
|
+
const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
|
|
86
74
|
if (backgroundStyle) {
|
|
87
75
|
warn('Checkbox does not support background image-related styles!');
|
|
88
76
|
}
|
|
@@ -94,13 +82,16 @@ const Checkbox = forwardRef((checkboxProps, ref) => {
|
|
|
94
82
|
if (labelContext) {
|
|
95
83
|
labelContext.current.triggerChange = onChange;
|
|
96
84
|
}
|
|
97
|
-
const innerProps = useInnerProps(props, {
|
|
85
|
+
const innerProps = useInnerProps(props, extendObject({
|
|
98
86
|
ref: nodeRef,
|
|
99
|
-
style: {
|
|
100
|
-
|
|
101
|
-
bindtap: onTap
|
|
102
|
-
|
|
103
|
-
|
|
87
|
+
style: extendObject({}, innerStyle, layoutStyle)
|
|
88
|
+
}, layoutProps, {
|
|
89
|
+
bindtap: !disabled && onTap
|
|
90
|
+
}), [
|
|
91
|
+
'value',
|
|
92
|
+
'disabled',
|
|
93
|
+
'checked'
|
|
94
|
+
], {
|
|
104
95
|
layoutRef
|
|
105
96
|
});
|
|
106
97
|
useEffect(() => {
|
|
@@ -124,17 +115,17 @@ const Checkbox = forwardRef((checkboxProps, ref) => {
|
|
|
124
115
|
}
|
|
125
116
|
}
|
|
126
117
|
}, [checked]);
|
|
127
|
-
return (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
118
|
+
return createElement(View, innerProps, createElement(View, { style: defaultStyle }, createElement(Icon, {
|
|
119
|
+
type: 'success_no_circle',
|
|
120
|
+
size: 18,
|
|
121
|
+
color: disabled ? '#ADADAD' : color,
|
|
122
|
+
style: isChecked ? styles.iconChecked : styles.icon
|
|
123
|
+
})), wrapChildren(props, {
|
|
124
|
+
hasVarDec,
|
|
125
|
+
varContext: varContextRef.current,
|
|
126
|
+
textStyle,
|
|
127
|
+
textProps
|
|
128
|
+
}));
|
|
138
129
|
});
|
|
139
130
|
Checkbox.displayName = 'MpxCheckbox';
|
|
140
131
|
export default Checkbox;
|
|
@@ -5,26 +5,27 @@
|
|
|
5
5
|
* ✔ bindreset
|
|
6
6
|
*/
|
|
7
7
|
import { View } from 'react-native';
|
|
8
|
-
import { useRef, forwardRef, useMemo } from 'react';
|
|
8
|
+
import { useRef, forwardRef, useMemo, createElement } from 'react';
|
|
9
9
|
import useNodesRef from './useNodesRef';
|
|
10
10
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
11
11
|
import { FormContext } from './context';
|
|
12
|
-
import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren } from './utils';
|
|
12
|
+
import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils';
|
|
13
13
|
const _Form = forwardRef((fromProps, ref) => {
|
|
14
14
|
const { textProps, innerProps: props = {} } = splitProps(fromProps);
|
|
15
15
|
const { style, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
16
16
|
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
17
|
-
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
17
|
+
const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
|
|
18
18
|
const formRef = useRef(null);
|
|
19
|
-
useNodesRef(props, ref, formRef
|
|
19
|
+
useNodesRef(props, ref, formRef, {
|
|
20
|
+
style: normalStyle
|
|
21
|
+
});
|
|
20
22
|
const propsRef = useRef({});
|
|
21
23
|
propsRef.current = props;
|
|
22
24
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef });
|
|
23
|
-
const innerProps = useInnerProps(props, {
|
|
24
|
-
style: {
|
|
25
|
-
ref: formRef
|
|
26
|
-
|
|
27
|
-
}, [
|
|
25
|
+
const innerProps = useInnerProps(props, extendObject({
|
|
26
|
+
style: extendObject({}, innerStyle, layoutStyle),
|
|
27
|
+
ref: formRef
|
|
28
|
+
}, layoutProps), [
|
|
28
29
|
'bindsubmit',
|
|
29
30
|
'bindreset'
|
|
30
31
|
], { layoutRef });
|
|
@@ -56,16 +57,12 @@ const _Form = forwardRef((fromProps, ref) => {
|
|
|
56
57
|
reset
|
|
57
58
|
};
|
|
58
59
|
}, []);
|
|
59
|
-
return (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
textProps
|
|
66
|
-
})}
|
|
67
|
-
</FormContext.Provider>
|
|
68
|
-
</View>);
|
|
60
|
+
return createElement(View, innerProps, createElement(FormContext.Provider, { value: contextValue }, wrapChildren(props, {
|
|
61
|
+
hasVarDec,
|
|
62
|
+
varContext: varContextRef.current,
|
|
63
|
+
textStyle,
|
|
64
|
+
textProps
|
|
65
|
+
})));
|
|
69
66
|
});
|
|
70
67
|
_Form.displayName = 'MpxForm';
|
|
71
68
|
export default _Form;
|