@mpxjs/webpack-plugin 2.8.25-alpha.21 → 2.8.25-alpha.22

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 (72) hide show
  1. package/lib/runtime/components/react/dist/KeyboardAvoidingView.jsx +89 -0
  2. package/lib/runtime/components/react/dist/context.js +14 -0
  3. package/lib/runtime/components/react/dist/event.config.js +27 -0
  4. package/lib/runtime/components/react/dist/getInnerListeners.js +262 -0
  5. package/lib/runtime/components/react/dist/mpx-button.jsx +271 -0
  6. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  7. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  8. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  9. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  10. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  11. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  12. package/lib/runtime/components/react/dist/mpx-canvas/html.js +341 -0
  13. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +236 -0
  14. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  15. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +90 -0
  16. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +131 -0
  17. package/lib/runtime/components/react/dist/mpx-form.jsx +68 -0
  18. package/lib/runtime/components/react/dist/mpx-icon/icons/cancel.png +0 -0
  19. package/lib/runtime/components/react/dist/mpx-icon/icons/clear.png +0 -0
  20. package/lib/runtime/components/react/dist/mpx-icon/icons/download.png +0 -0
  21. package/lib/runtime/components/react/dist/mpx-icon/icons/info.png +0 -0
  22. package/lib/runtime/components/react/dist/mpx-icon/icons/search.png +0 -0
  23. package/lib/runtime/components/react/dist/mpx-icon/icons/success.png +0 -0
  24. package/lib/runtime/components/react/dist/mpx-icon/icons/success_no_circle.png +0 -0
  25. package/lib/runtime/components/react/dist/mpx-icon/icons/waiting.png +0 -0
  26. package/lib/runtime/components/react/dist/mpx-icon/icons/warn.png +0 -0
  27. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +50 -0
  28. package/lib/runtime/components/react/dist/mpx-image.jsx +292 -0
  29. package/lib/runtime/components/react/dist/mpx-input.jsx +292 -0
  30. package/lib/runtime/components/react/dist/mpx-label.jsx +52 -0
  31. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +32 -0
  32. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +468 -0
  33. package/lib/runtime/components/react/dist/mpx-navigator.jsx +33 -0
  34. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +74 -0
  35. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +141 -0
  36. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +147 -0
  37. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +99 -0
  38. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
  39. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +81 -0
  40. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +242 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
  42. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +35 -0
  43. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +193 -0
  44. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +125 -0
  45. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +30 -0
  46. package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +112 -0
  47. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +41 -0
  48. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +86 -0
  49. package/lib/runtime/components/react/dist/mpx-radio.jsx +140 -0
  50. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  51. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  52. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +17 -0
  53. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +372 -0
  54. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  55. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +59 -0
  56. package/lib/runtime/components/react/dist/mpx-swiper.jsx +671 -0
  57. package/lib/runtime/components/react/dist/mpx-switch.jsx +97 -0
  58. package/lib/runtime/components/react/dist/mpx-text.jsx +41 -0
  59. package/lib/runtime/components/react/dist/mpx-textarea.jsx +40 -0
  60. package/lib/runtime/components/react/dist/mpx-video.jsx +248 -0
  61. package/lib/runtime/components/react/dist/mpx-view.jsx +611 -0
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +289 -0
  63. package/lib/runtime/components/react/dist/parser.js +218 -0
  64. package/lib/runtime/components/react/dist/pickerFaces.js +76 -0
  65. package/lib/runtime/components/react/dist/pickerVIewContext.js +14 -0
  66. package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +23 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/useAnimationHooks.js +346 -0
  69. package/lib/runtime/components/react/dist/useNodesRef.js +16 -0
  70. package/lib/runtime/components/react/dist/utils.jsx +599 -0
  71. package/package.json +6 -3
  72. package/LICENSE +0 -433
@@ -0,0 +1,236 @@
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
+ const jsCode = `
73
+ window.mpxWebviewMessageCallback(${JSON.stringify(message)});
74
+ true;
75
+ `;
76
+ canvasRef.current.webview.injectJavaScript(jsCode);
77
+ }
78
+ };
79
+ // 设置bus
80
+ canvasRef.current.bus = new Bus(webviewPostMessage);
81
+ canvasRef.current.bus.pause();
82
+ // 设置 context 2D
83
+ canvasRef.current.context2D = context2D;
84
+ // 设置 getContext 方法
85
+ canvasRef.current.getContext = getContext;
86
+ // 设置 createImage 方法
87
+ canvasRef.current.createImage = createImage;
88
+ // 设置 postMessage 方法
89
+ canvasRef.current.postMessage = postMessage;
90
+ // 设置 listeners
91
+ canvasRef.current.listeners = [];
92
+ canvasRef.current.addMessageListener = addMessageListener;
93
+ canvasRef.current.removeMessageListener = removeMessageListener;
94
+ canvasRef.current.createImageData = createImageData;
95
+ return () => {
96
+ canvasRef.current.bus?.clearBatchingTimeout();
97
+ };
98
+ }, []);
99
+ const createImageData = (dataArray, width, height) => {
100
+ return canvasCreateImageData(canvasRef.current, dataArray, width, height);
101
+ };
102
+ const createImage = (width, height) => {
103
+ return canvasCreateImage(canvasRef.current, width, height);
104
+ };
105
+ const getContext = useCallback((contextType) => {
106
+ if (contextType === '2d') {
107
+ return context2D;
108
+ }
109
+ return null;
110
+ }, []);
111
+ const postMessage = useCallback(async (message) => {
112
+ if (!canvasRef.current?.bus)
113
+ return;
114
+ const { type, payload } = await canvasRef.current.bus.post({
115
+ id: ID(),
116
+ ...message
117
+ });
118
+ switch (type) {
119
+ case 'error': {
120
+ const { binderror } = props;
121
+ binderror &&
122
+ binderror(getCustomEvent('error', {}, {
123
+ detail: {
124
+ errMsg: payload.message
125
+ },
126
+ layoutRef
127
+ }, props));
128
+ break;
129
+ }
130
+ case 'json': {
131
+ return payload;
132
+ }
133
+ case 'blob': {
134
+ return atob(payload);
135
+ }
136
+ }
137
+ }, []);
138
+ const addMessageListener = (listener) => {
139
+ canvasRef.current.listeners.push(listener);
140
+ return () => canvasRef.current.removeMessageListener(listener);
141
+ };
142
+ const removeMessageListener = (listener) => {
143
+ canvasRef.current.listeners.splice(canvasRef.current.listeners.indexOf(listener), 1);
144
+ };
145
+ const onMessage = useCallback((e) => {
146
+ let data = JSON.parse(e.nativeEvent.data);
147
+ switch (data.type) {
148
+ case 'error': {
149
+ const { binderror } = props;
150
+ binderror &&
151
+ binderror(getCustomEvent('error', e, {
152
+ detail: {
153
+ errMsg: data.payload.message
154
+ },
155
+ layoutRef
156
+ }, props));
157
+ break;
158
+ }
159
+ default: {
160
+ if (data.payload) {
161
+ // createLinearGradient 方法调用需要在 constructors 中需要注册 CanvasGradient
162
+ const constructor = constructors[data.meta.constructor];
163
+ if (constructor) {
164
+ const { args, payload } = data;
165
+ // RN 端同步生成一个 CanvasGradient 的实例
166
+ const object = constructor.constructLocally(canvasRef.current, ...args);
167
+ Object.assign(object, payload, {
168
+ [WEBVIEW_TARGET]: data.meta.target
169
+ });
170
+ data = {
171
+ ...data,
172
+ payload: object
173
+ };
174
+ }
175
+ for (const listener of canvasRef.current.listeners) {
176
+ listener(data.payload);
177
+ }
178
+ }
179
+ if (canvasRef.current.bus) {
180
+ canvasRef.current.bus.handle(data);
181
+ }
182
+ }
183
+ }
184
+ }, []);
185
+ const onLoad = useCallback(() => {
186
+ setIsLoaded(true);
187
+ if (canvasRef.current?.bus) {
188
+ canvasRef.current.bus.resume();
189
+ }
190
+ }, []);
191
+ useNodesRef(props, ref, nodeRef, {
192
+ style: normalStyle,
193
+ node: canvasRef.current,
194
+ context: context2D
195
+ });
196
+ if (Platform.OS === 'android') {
197
+ const isAndroid9 = Platform.Version >= 28;
198
+ return createElement(View, innerProps, createElement(WebView, {
199
+ ref: (element) => {
200
+ if (canvasRef.current) {
201
+ canvasRef.current.webview = element;
202
+ }
203
+ },
204
+ style: [
205
+ isAndroid9 ? stylesheet.webviewAndroid9 : stylesheet.webview,
206
+ { height, width }
207
+ ],
208
+ source: { html },
209
+ originWhitelist: originWhitelist,
210
+ onMessage: onMessage,
211
+ onLoad: onLoad,
212
+ overScrollMode: 'never',
213
+ mixedContentMode: 'always',
214
+ scalesPageToFit: false,
215
+ javaScriptEnabled: true,
216
+ domStorageEnabled: true,
217
+ thirdPartyCookiesEnabled: true,
218
+ allowUniversalAccessFromFileURLs: true
219
+ }));
220
+ }
221
+ return createElement(View, innerProps, createElement(WebView, {
222
+ ref: (element) => {
223
+ if (canvasRef.current) {
224
+ canvasRef.current.webview = element;
225
+ }
226
+ },
227
+ style: [stylesheet.webview, { height, width }],
228
+ source: { html },
229
+ originWhitelist: originWhitelist,
230
+ onMessage: onMessage,
231
+ onLoad: onLoad,
232
+ scrollEnabled: false
233
+ }));
234
+ });
235
+ _Canvas.displayName = 'mpxCanvas';
236
+ 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
+ };
@@ -0,0 +1,90 @@
1
+ /**
2
+ * ✔ bindchange
3
+ */
4
+ import { useRef, forwardRef, useContext, useMemo, useEffect, createElement } from 'react';
5
+ import { View } from 'react-native';
6
+ import { warn } from '@mpxjs/utils';
7
+ import { FormContext, CheckboxGroupContext } from './context';
8
+ import useInnerProps, { getCustomEvent } from './getInnerListeners';
9
+ import useNodesRef from './useNodesRef';
10
+ import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
11
+ const CheckboxGroup = forwardRef((props, ref) => {
12
+ const propsRef = useRef({});
13
+ propsRef.current = props;
14
+ const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
15
+ const formContext = useContext(FormContext);
16
+ let formValuesMap;
17
+ if (formContext) {
18
+ formValuesMap = formContext.formValuesMap;
19
+ }
20
+ const groupValue = useRef({}).current;
21
+ const defaultStyle = {
22
+ flexDirection: 'row',
23
+ flexWrap: 'wrap'
24
+ };
25
+ const styleObj = extendObject({}, defaultStyle, style);
26
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
27
+ const nodeRef = useRef(null);
28
+ useNodesRef(props, ref, nodeRef, { style: normalStyle });
29
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
30
+ const getValue = () => {
31
+ const arr = [];
32
+ for (const key in groupValue) {
33
+ if (groupValue[key].checked) {
34
+ arr.push(key);
35
+ }
36
+ }
37
+ return arr;
38
+ };
39
+ const resetValue = () => {
40
+ Object.keys(groupValue).forEach((key) => {
41
+ groupValue[key].checked = false;
42
+ groupValue[key].setValue(false);
43
+ });
44
+ };
45
+ if (formValuesMap) {
46
+ if (!props.name) {
47
+ warn('If a form component is used, the name attribute is required.');
48
+ }
49
+ else {
50
+ formValuesMap.set(props.name, { getValue, resetValue });
51
+ }
52
+ }
53
+ useEffect(() => {
54
+ return () => {
55
+ if (formValuesMap && props.name) {
56
+ formValuesMap.delete(props.name);
57
+ }
58
+ };
59
+ }, []);
60
+ const innerProps = useInnerProps(props, extendObject({
61
+ ref: nodeRef,
62
+ style: extendObject({}, normalStyle, layoutStyle)
63
+ }, layoutProps), [
64
+ 'name'
65
+ ], {
66
+ layoutRef
67
+ });
68
+ const contextValue = useMemo(() => {
69
+ const notifyChange = (evt) => {
70
+ const { bindchange } = propsRef.current;
71
+ bindchange &&
72
+ bindchange(getCustomEvent('tap', evt, {
73
+ layoutRef,
74
+ detail: {
75
+ value: getValue()
76
+ }
77
+ }, propsRef.current));
78
+ };
79
+ return {
80
+ groupValue,
81
+ notifyChange
82
+ };
83
+ }, []);
84
+ return createElement(View, innerProps, createElement(CheckboxGroupContext.Provider, { value: contextValue }, wrapChildren(props, {
85
+ hasVarDec,
86
+ varContext: varContextRef.current
87
+ })));
88
+ });
89
+ CheckboxGroup.displayName = 'MpxCheckboxGroup';
90
+ export default CheckboxGroup;
@@ -0,0 +1,131 @@
1
+ /**
2
+ * ✔ value
3
+ * ✔ disabled
4
+ * ✔ checked
5
+ * ✔ color
6
+ */
7
+ import { useState, useRef, forwardRef, useEffect, useContext, createElement } from 'react';
8
+ import { View, StyleSheet } from 'react-native';
9
+ import { warn } from '@mpxjs/utils';
10
+ import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
+ import useNodesRef from './useNodesRef';
12
+ import Icon from './mpx-icon';
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
14
+ import { CheckboxGroupContext, LabelContext } from './context';
15
+ const styles = StyleSheet.create({
16
+ container: {
17
+ flexDirection: 'row',
18
+ alignItems: 'center'
19
+ },
20
+ wrapper: {
21
+ alignItems: 'center',
22
+ justifyContent: 'center',
23
+ width: 24,
24
+ height: 24,
25
+ borderColor: '#D1D1D1',
26
+ borderWidth: 1,
27
+ borderRadius: 3,
28
+ backgroundColor: '#ffffff',
29
+ marginRight: 5
30
+ },
31
+ wrapperDisabled: {
32
+ backgroundColor: '#E1E1E1'
33
+ },
34
+ icon: {
35
+ opacity: 0
36
+ },
37
+ iconChecked: {
38
+ opacity: 1
39
+ }
40
+ });
41
+ const Checkbox = forwardRef((checkboxProps, ref) => {
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, _onChange } = props;
44
+ const [isChecked, setIsChecked] = useState(!!checked);
45
+ const groupContext = useContext(CheckboxGroupContext);
46
+ let groupValue;
47
+ let notifyChange;
48
+ const defaultStyle = extendObject({}, styles.wrapper, disabled ? styles.wrapperDisabled : null);
49
+ const styleObj = extendObject({}, styles.container, style);
50
+ const onChange = (evt) => {
51
+ if (disabled)
52
+ return;
53
+ const checked = !isChecked;
54
+ setIsChecked(checked);
55
+ if (groupValue) {
56
+ groupValue[value].checked = checked;
57
+ }
58
+ notifyChange && notifyChange(evt);
59
+ // Called when the switch type attribute is checkbox
60
+ _onChange && _onChange(evt, { checked });
61
+ };
62
+ const onTap = (evt) => {
63
+ bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
64
+ onChange(evt);
65
+ };
66
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
67
+ const nodeRef = useRef(null);
68
+ useNodesRef(props, ref, nodeRef, {
69
+ style: extendObject({}, defaultStyle, normalStyle),
70
+ change: onChange
71
+ });
72
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
73
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
74
+ if (backgroundStyle) {
75
+ warn('Checkbox does not support background image-related styles!');
76
+ }
77
+ const labelContext = useContext(LabelContext);
78
+ if (groupContext) {
79
+ groupValue = groupContext.groupValue;
80
+ notifyChange = groupContext.notifyChange;
81
+ }
82
+ if (labelContext) {
83
+ labelContext.current.triggerChange = onChange;
84
+ }
85
+ const innerProps = useInnerProps(props, extendObject({
86
+ ref: nodeRef,
87
+ style: extendObject({}, innerStyle, layoutStyle)
88
+ }, layoutProps, {
89
+ bindtap: !disabled && onTap
90
+ }), [
91
+ 'value',
92
+ 'disabled',
93
+ 'checked'
94
+ ], {
95
+ layoutRef
96
+ });
97
+ useEffect(() => {
98
+ if (groupValue) {
99
+ groupValue[value] = {
100
+ checked: checked,
101
+ setValue: setIsChecked
102
+ };
103
+ }
104
+ return () => {
105
+ if (groupValue) {
106
+ delete groupValue[value];
107
+ }
108
+ };
109
+ }, []);
110
+ useEffect(() => {
111
+ if (checked !== isChecked) {
112
+ setIsChecked(checked);
113
+ if (groupValue) {
114
+ groupValue[value].checked = checked;
115
+ }
116
+ }
117
+ }, [checked]);
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
+ }));
129
+ });
130
+ Checkbox.displayName = 'MpxCheckbox';
131
+ export default Checkbox;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * ✘ report-submit
3
+ * ✘ report-submit-timeout
4
+ * ✔ bindsubmit
5
+ * ✔ bindreset
6
+ */
7
+ import { View } from 'react-native';
8
+ import { useRef, forwardRef, useMemo, createElement } from 'react';
9
+ import useNodesRef from './useNodesRef';
10
+ import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
+ import { FormContext } from './context';
12
+ import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils';
13
+ const _Form = forwardRef((fromProps, ref) => {
14
+ const { textProps, innerProps: props = {} } = splitProps(fromProps);
15
+ const { style, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
16
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
17
+ const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
18
+ const formRef = useRef(null);
19
+ useNodesRef(props, ref, formRef, {
20
+ style: normalStyle
21
+ });
22
+ const propsRef = useRef({});
23
+ propsRef.current = props;
24
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef });
25
+ const innerProps = useInnerProps(props, extendObject({
26
+ style: extendObject({}, innerStyle, layoutStyle),
27
+ ref: formRef
28
+ }, layoutProps), [
29
+ 'bindsubmit',
30
+ 'bindreset'
31
+ ], { layoutRef });
32
+ const contextValue = useMemo(() => {
33
+ const formValuesMap = new Map();
34
+ const submit = () => {
35
+ const { bindsubmit } = propsRef.current;
36
+ const formValue = {};
37
+ for (const name of formValuesMap.keys()) {
38
+ if (formValuesMap.get(name).getValue) {
39
+ formValue[name] = formValuesMap.get(name).getValue();
40
+ }
41
+ }
42
+ bindsubmit && bindsubmit(getCustomEvent('submit', {}, {
43
+ detail: {
44
+ value: formValue
45
+ },
46
+ layoutRef
47
+ }, propsRef.current));
48
+ };
49
+ const reset = () => {
50
+ const { bindreset } = propsRef.current;
51
+ bindreset && bindreset();
52
+ formValuesMap.forEach(item => item.resetValue());
53
+ };
54
+ return {
55
+ formValuesMap,
56
+ submit,
57
+ reset
58
+ };
59
+ }, []);
60
+ return createElement(View, innerProps, createElement(FormContext.Provider, { value: contextValue }, wrapChildren(props, {
61
+ hasVarDec,
62
+ varContext: varContextRef.current,
63
+ textStyle,
64
+ textProps
65
+ })));
66
+ });
67
+ _Form.displayName = 'MpxForm';
68
+ export default _Form;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * ✔ type
3
+ * ✔ size
4
+ * ✔ color
5
+ */
6
+ import { forwardRef, useRef, createElement } from 'react';
7
+ import { Image } from 'react-native';
8
+ import useInnerProps from '../getInnerListeners';
9
+ import useNodesRef from '../useNodesRef';
10
+ import { useLayout, useTransformStyle, extendObject } from '../utils';
11
+ import Success from './icons/success.png';
12
+ import SuccessNoCircle from './icons/success_no_circle.png';
13
+ import Info from './icons/info.png';
14
+ import Warn from './icons/warn.png';
15
+ import Waiting from './icons/waiting.png';
16
+ import Cancel from './icons/cancel.png';
17
+ import Download from './icons/download.png';
18
+ import Search from './icons/search.png';
19
+ import Clear from './icons/clear.png';
20
+ const IconTypeMap = new Map([
21
+ ['success', Success],
22
+ ['success_no_circle', SuccessNoCircle],
23
+ ['info', Info],
24
+ ['warn', Warn],
25
+ ['waiting', Waiting],
26
+ ['cancel', Cancel],
27
+ ['download', Download],
28
+ ['search', Search],
29
+ ['clear', Clear]
30
+ ]);
31
+ const Icon = forwardRef((props, ref) => {
32
+ const { type, size = 23, color, style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
33
+ const source = IconTypeMap.get(type);
34
+ const defaultStyle = { width: ~~size, height: ~~size };
35
+ const styleObj = extendObject({}, defaultStyle, style);
36
+ const { hasSelfPercent, normalStyle, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
37
+ const nodeRef = useRef(null);
38
+ useNodesRef(props, ref, nodeRef, { style: normalStyle });
39
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
40
+ const innerProps = useInnerProps(props, extendObject({
41
+ ref: nodeRef,
42
+ source,
43
+ style: extendObject({}, normalStyle, layoutStyle, { tintColor: color })
44
+ }, layoutProps), [], {
45
+ layoutRef
46
+ });
47
+ return createElement(Image, innerProps);
48
+ });
49
+ Icon.displayName = 'MpxIcon';
50
+ export default Icon;