@mpxjs/webpack-plugin 2.10.7 → 2.10.8-beta.3

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 (138) hide show
  1. package/lib/dependencies/RecordPageConfigsMapDependency.js +1 -1
  2. package/lib/dependencies/RequireExternalDependency.js +61 -0
  3. package/lib/file-loader.js +3 -2
  4. package/lib/index.js +55 -9
  5. package/lib/json-compiler/index.js +1 -0
  6. package/lib/parser.js +1 -1
  7. package/lib/platform/json/wx/index.js +43 -25
  8. package/lib/platform/style/wx/index.js +7 -0
  9. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  10. package/lib/platform/template/wx/component-config/index.js +9 -1
  11. package/lib/platform/template/wx/component-config/nav-container.js +27 -0
  12. package/lib/platform/template/wx/component-config/page-container.js +19 -0
  13. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  14. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  15. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  16. package/lib/react/LoadAsyncChunkModule.js +74 -0
  17. package/lib/react/index.js +3 -1
  18. package/lib/react/processJSON.js +74 -13
  19. package/lib/react/processScript.js +6 -6
  20. package/lib/react/script-helper.js +100 -41
  21. package/lib/runtime/components/ali/mpx-nav-container.mpx +3 -0
  22. package/lib/runtime/components/react/context.ts +27 -7
  23. package/lib/runtime/components/react/dist/context.d.ts +78 -0
  24. package/lib/runtime/components/react/dist/context.js +5 -1
  25. package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
  26. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
  27. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
  28. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +135 -0
  29. package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
  30. package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
  31. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
  38. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
  39. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
  40. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
  41. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
  42. package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
  43. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
  44. package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
  45. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
  46. package/lib/runtime/components/react/dist/mpx-input.d.ts +49 -0
  47. package/lib/runtime/components/react/dist/mpx-input.jsx +28 -9
  48. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
  49. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +42 -46
  50. package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
  51. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
  52. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +63 -0
  53. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -6
  54. package/lib/runtime/components/react/dist/mpx-nav-container.d.ts +9 -0
  55. package/lib/runtime/components/react/dist/mpx-nav-container.jsx +23 -0
  56. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
  57. package/lib/runtime/components/react/dist/mpx-page-container.d.ts +27 -0
  58. package/lib/runtime/components/react/dist/mpx-page-container.jsx +255 -0
  59. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
  60. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
  61. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
  62. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
  63. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
  64. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
  65. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
  66. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
  67. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
  68. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +31 -0
  69. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
  70. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +22 -0
  71. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
  72. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
  73. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
  74. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
  75. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
  76. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
  77. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
  78. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
  79. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
  80. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
  81. package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
  82. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
  83. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
  84. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
  85. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
  86. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -15
  87. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
  88. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
  89. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
  90. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +117 -0
  91. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
  92. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  93. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
  94. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +52 -0
  95. package/lib/runtime/components/react/dist/mpx-swiper.jsx +3 -2
  96. package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
  97. package/lib/runtime/components/react/dist/mpx-text.d.ts +21 -0
  98. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
  99. package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
  100. package/lib/runtime/components/react/dist/mpx-view.d.ts +34 -0
  101. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
  102. package/lib/runtime/components/react/dist/nav.d.ts +11 -0
  103. package/lib/runtime/components/react/dist/nav.jsx +141 -0
  104. package/lib/runtime/components/react/dist/parser.d.ts +39 -0
  105. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +32 -0
  106. package/lib/runtime/components/react/dist/useNavShared.d.ts +2 -0
  107. package/lib/runtime/components/react/dist/useNavShared.js +6 -0
  108. package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
  109. package/lib/runtime/components/react/dist/utils.d.ts +121 -0
  110. package/lib/runtime/components/react/mpx-async-suspense.tsx +180 -0
  111. package/lib/runtime/components/react/mpx-button.tsx +3 -2
  112. package/lib/runtime/components/react/mpx-input.tsx +35 -16
  113. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +46 -45
  114. package/lib/runtime/components/react/mpx-movable-view.tsx +8 -4
  115. package/lib/runtime/components/react/mpx-nav-container.tsx +33 -0
  116. package/lib/runtime/components/react/mpx-page-container.tsx +394 -0
  117. package/lib/runtime/components/react/mpx-scroll-view.tsx +84 -59
  118. package/lib/runtime/components/react/mpx-sticky-header.tsx +181 -0
  119. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  120. package/lib/runtime/components/react/mpx-swiper.tsx +4 -2
  121. package/lib/runtime/components/react/nav.tsx +172 -0
  122. package/lib/runtime/components/react/types/common.d.ts +19 -0
  123. package/lib/runtime/components/react/useNavShared.ts +8 -0
  124. package/lib/runtime/components/web/mpx-nav-container.vue +13 -0
  125. package/lib/runtime/components/web/mpx-scroll-view.vue +18 -4
  126. package/lib/runtime/components/web/mpx-sticky-header.vue +99 -0
  127. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  128. package/lib/runtime/components/wx/mpx-nav-container.mpx +9 -0
  129. package/lib/runtime/optionProcessorReact.d.ts +18 -0
  130. package/lib/runtime/optionProcessorReact.js +30 -0
  131. package/lib/script-setup-compiler/index.js +27 -5
  132. package/lib/template-compiler/bind-this.js +2 -1
  133. package/lib/template-compiler/compiler.js +27 -6
  134. package/lib/utils/dom-tag-config.js +18 -4
  135. package/lib/utils/trans-async-sub-rules.js +19 -0
  136. package/lib/web/script-helper.js +1 -1
  137. package/package.json +4 -4
  138. package/LICENSE +0 -433
@@ -0,0 +1,135 @@
1
+ import { useState, useEffect, useCallback, useRef, createElement } from 'react';
2
+ import { View, Image, StyleSheet, Text, TouchableOpacity } from 'react-native';
3
+ import FastImage from '@d11/react-native-fast-image';
4
+ const asyncChunkMap = new Map();
5
+ const styles = StyleSheet.create({
6
+ container: {
7
+ flex: 1,
8
+ padding: 20,
9
+ backgroundColor: '#fff'
10
+ },
11
+ loadingImage: {
12
+ width: 100,
13
+ height: 100,
14
+ marginTop: 220,
15
+ alignSelf: 'center'
16
+ },
17
+ buttonText: {
18
+ color: '#fff',
19
+ fontSize: 16,
20
+ fontWeight: '500',
21
+ textAlign: 'center'
22
+ },
23
+ errorImage: {
24
+ marginTop: 80,
25
+ width: 220,
26
+ aspectRatio: 1,
27
+ alignSelf: 'center'
28
+ },
29
+ errorText: {
30
+ fontSize: 16,
31
+ textAlign: 'center',
32
+ color: '#333',
33
+ marginBottom: 20
34
+ },
35
+ retryButton: {
36
+ position: 'absolute',
37
+ bottom: 54,
38
+ left: 20,
39
+ right: 20,
40
+ backgroundColor: '#fff',
41
+ paddingVertical: 15,
42
+ borderRadius: 30,
43
+ marginTop: 40,
44
+ borderWidth: 1,
45
+ borderColor: '#FF5F00'
46
+ },
47
+ retryButtonText: {
48
+ color: '#FF5F00',
49
+ fontSize: 16,
50
+ fontWeight: '500',
51
+ textAlign: 'center'
52
+ }
53
+ });
54
+ const DefaultFallback = ({ onReload }) => {
55
+ return (<View style={styles.container}>
56
+ <Image source={{
57
+ uri: 'https://dpubstatic.udache.com/static/dpubimg/Vak5mZvezPpKV5ZJI6P9b_drn-fallbak.png'
58
+ }} style={styles.errorImage} resizeMode="contain"/>
59
+ <Text style={styles.errorText}>网络出了点问题,请查看网络环境</Text>
60
+ <TouchableOpacity style={styles.retryButton} onPress={onReload} activeOpacity={0.7}>
61
+ <Text style={styles.retryButtonText}>点击重试</Text>
62
+ </TouchableOpacity>
63
+ </View>);
64
+ };
65
+ const DefaultLoading = () => {
66
+ return (<View style={styles.container}>
67
+ <FastImage style={styles.loadingImage} source={{
68
+ uri: 'https://dpubstatic.udache.com/static/dpubimg/439jiCVOtNOnEv9F2LaDs_loading.gif'
69
+ }} resizeMode={FastImage.resizeMode.contain}></FastImage>
70
+ </View>);
71
+ };
72
+ const AsyncSuspense = ({ type, innerProps, chunkName, moduleId, loading, fallback, getChildren }) => {
73
+ const [status, setStatus] = useState('pending');
74
+ const chunkLoaded = asyncChunkMap.has(moduleId);
75
+ const loadChunkPromise = useRef(null);
76
+ const reloadPage = useCallback(() => {
77
+ setStatus('pending');
78
+ }, []);
79
+ useEffect(() => {
80
+ let cancelled = false;
81
+ if (!chunkLoaded && status === 'pending') {
82
+ if (loadChunkPromise.current) {
83
+ loadChunkPromise
84
+ .current.then((res) => {
85
+ if (cancelled)
86
+ return;
87
+ asyncChunkMap.set(moduleId, res);
88
+ setStatus('loaded');
89
+ })
90
+ .catch((e) => {
91
+ if (cancelled)
92
+ return;
93
+ if (type === 'component') {
94
+ global.onLazyLoadError({
95
+ type: 'subpackage',
96
+ subpackage: [chunkName],
97
+ errMsg: `loadSubpackage: ${e.type}`
98
+ });
99
+ }
100
+ loadChunkPromise.current = null;
101
+ setStatus('error');
102
+ });
103
+ }
104
+ }
105
+ return () => {
106
+ cancelled = true;
107
+ };
108
+ }, [status]);
109
+ if (chunkLoaded) {
110
+ const Comp = asyncChunkMap.get(moduleId);
111
+ return createElement(Comp, innerProps);
112
+ }
113
+ else if (status === 'error') {
114
+ if (type === 'page') {
115
+ fallback = fallback || DefaultFallback;
116
+ return createElement(fallback, { onReload: reloadPage });
117
+ }
118
+ else {
119
+ return fallback ? createElement(fallback, innerProps) : null;
120
+ }
121
+ }
122
+ else {
123
+ if (!loadChunkPromise.current) {
124
+ loadChunkPromise.current = getChildren();
125
+ }
126
+ if (type === 'page') {
127
+ return createElement(loading || DefaultLoading);
128
+ }
129
+ else {
130
+ return fallback ? createElement(fallback, innerProps) : null;
131
+ }
132
+ }
133
+ };
134
+ AsyncSuspense.displayName = 'MpxAsyncSuspense';
135
+ export default AsyncSuspense;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * ✔ size
3
+ * ✔ type
4
+ * ✔ plain
5
+ * ✔ disabled
6
+ * ✔ loading
7
+ * ✔ form-type
8
+ * - open-type: Partially. Only support `share`、`getUserInfo`
9
+ * ✔ hover-class: Convert hoverClass to hoverStyle.
10
+ * ✔ hover-style
11
+ * ✘ hover-stop-propagation
12
+ * ✔ hover-start-time
13
+ * ✔ hover-stay-time
14
+ * ✘ lang
15
+ * ✘ session-from
16
+ * ✘ send-message-title
17
+ * ✘ send-message-path
18
+ * ✘ send-message-img
19
+ * ✘ app-parameter
20
+ * ✘ show-message-card
21
+ * ✘ phone-number-no-quota-toast
22
+ * ✘ bindgetuserinfo
23
+ * ✘ bindcontact
24
+ * ✘ createliveactivity
25
+ * ✘ bindgetphonenumber
26
+ * ✘ bindgetphonenumber
27
+ * ✘ bindgetrealtimephonenumber
28
+ * ✘ binderror
29
+ * ✘ bindopensetting
30
+ * ✘ bindlaunchapp
31
+ * ✘ bindlaunchapp
32
+ * ✘ bindchooseavatar
33
+ * ✘ bindchooseavatar
34
+ * ✘ bindagreeprivacyauthorization
35
+ * ✔ bindtap
36
+ */
37
+ import { ReactNode } from 'react';
38
+ import { View, ViewStyle, TextStyle, NativeSyntheticEvent } from 'react-native';
39
+ import { HandlerRef } from './useNodesRef';
40
+ import type { ExtendedViewStyle } from './types/common';
41
+ export type Type = 'default' | 'primary' | 'warn';
42
+ export type OpenType = 'share' | 'getUserInfo';
43
+ export type OpenTypeEvent = 'onShareAppMessage' | 'onUserInfo';
44
+ export interface ButtonProps {
45
+ size?: string;
46
+ type?: Type;
47
+ plain?: boolean;
48
+ disabled?: boolean;
49
+ loading?: boolean;
50
+ 'hover-class'?: string;
51
+ 'hover-style'?: ExtendedViewStyle;
52
+ 'hover-start-time'?: number;
53
+ 'hover-stay-time'?: number;
54
+ 'open-type'?: OpenType;
55
+ 'form-type'?: 'submit' | 'reset';
56
+ 'enable-offset'?: boolean;
57
+ 'enable-var'?: boolean;
58
+ 'external-var-context'?: Record<string, any>;
59
+ 'parent-font-size'?: number;
60
+ 'parent-width'?: number;
61
+ 'parent-height'?: number;
62
+ style?: ViewStyle & TextStyle & Record<string, any>;
63
+ children: ReactNode;
64
+ bindgetuserinfo?: (userInfo: any) => void;
65
+ bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void;
66
+ }
67
+ declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HandlerRef<View, ButtonProps>>>;
68
+ export default Button;
@@ -35,7 +35,7 @@
35
35
  * ✔ bindtap
36
36
  */
37
37
  import { createElement, useEffect, useRef, forwardRef, useContext } from 'react';
38
- import { View, StyleSheet, Animated, Easing } from 'react-native';
38
+ import { View, StyleSheet, Animated, Easing, useAnimatedValue } from 'react-native';
39
39
  import { warn } from '@mpxjs/utils';
40
40
  import { GestureDetector } from 'react-native-gesture-handler';
41
41
  import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils';
@@ -104,7 +104,7 @@ const timer = (data, time = 3000) => new Promise((resolve) => {
104
104
  }, time);
105
105
  });
106
106
  const Loading = ({ alone = false }) => {
107
- const image = useRef(new Animated.Value(0)).current;
107
+ const image = useAnimatedValue(0);
108
108
  const rotate = image.interpolate({
109
109
  inputRange: [0, 1],
110
110
  outputRange: ['0deg', '360deg']
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ interface Message {
3
+ id?: string;
4
+ type: string;
5
+ payload?: any;
6
+ }
7
+ export default class Bus {
8
+ _paused: Boolean;
9
+ _messageListeners: {
10
+ [key: string]: (message: Message) => void;
11
+ };
12
+ _queue: Message[];
13
+ _send: (message: Message | Message[]) => void;
14
+ _timeoutId: NodeJS.Timeout | null;
15
+ constructor(send: (message: Message | Message[]) => void);
16
+ post(message: Message): Promise<any>;
17
+ handle(message: Message): void;
18
+ pause(): void;
19
+ resume(): void;
20
+ startBatching(): void;
21
+ clearBatchingTimeout(): void;
22
+ }
23
+ export {};
@@ -0,0 +1,7 @@
1
+ import { WebviewMessage, CanvasInstance } from './utils';
2
+ export default class CanvasGradient {
3
+ private canvas;
4
+ [key: string]: any;
5
+ constructor(canvas: CanvasInstance, noOnConstruction?: boolean);
6
+ postMessage(message: WebviewMessage): Promise<any>;
7
+ }
@@ -0,0 +1,6 @@
1
+ import { CanvasInstance, WebviewMessage } from './utils';
2
+ export default class CanvasRenderingContext2D {
3
+ canvas: CanvasInstance;
4
+ constructor(canvas: CanvasInstance);
5
+ postMessage(message: WebviewMessage): Promise<any>;
6
+ }
@@ -0,0 +1,20 @@
1
+ import { WebviewMessage, WEBVIEW_TARGET, CanvasInstance } from './utils';
2
+ export declare class Image {
3
+ [WEBVIEW_TARGET]: string;
4
+ canvas: any;
5
+ width: number;
6
+ height: number;
7
+ private _loadListener;
8
+ private _errorListener;
9
+ private _onload;
10
+ private _onerror;
11
+ [key: string]: any;
12
+ constructor(canvas: CanvasInstance, width?: number, height?: number, noOnConstruction?: boolean);
13
+ postMessage(message: WebviewMessage): any;
14
+ addEventListener(type: 'load' | 'error', callbackFn: Function): any;
15
+ set onload(callback: ((...args: any[]) => void));
16
+ get onload(): ((...args: any[]) => void);
17
+ set onerror(callback: ((...args: any[]) => void));
18
+ get onerror(): ((...args: any[]) => void);
19
+ }
20
+ export declare function createImage(canvas: CanvasInstance, width?: number, height?: number): Image;
@@ -0,0 +1,8 @@
1
+ import { WebviewMessage, CanvasInstance } from './utils';
2
+ export default class ImageData {
3
+ canvas: CanvasInstance;
4
+ [key: string]: any;
5
+ constructor(canvas: CanvasInstance, dataArray: number[], width: number, height: number, noOnConstruction?: boolean);
6
+ postMessage: (message: WebviewMessage) => Promise<any>;
7
+ }
8
+ export declare function createImageData(canvas: CanvasInstance, dataArray: number[], width: number, height: number): ImageData;
@@ -0,0 +1,10 @@
1
+ import { WebviewConstructor } from './utils';
2
+ export declare enum ConstructorType {
3
+ Image = "Image",
4
+ CanvasGradient = "CanvasGradient",
5
+ ImageData = "ImageData"
6
+ }
7
+ export declare function useConstructorsRegistry(): {
8
+ register: (registerWebviewConstructor: Function) => void;
9
+ getConstructor: (type: ConstructorType) => WebviewConstructor | undefined;
10
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: "<html><head>\n <meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no\" name=\"viewport\">\n <style>\n html {\n -ms-content-zooming: none;\n -ms-touch-action: pan-x pan-y;\n }\n body {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n margin: 0;\n padding: 0;\n overflow: hidden;\n }\n * {\n user-select: none;\n -ms-user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n }\n </style>\n </head>\n <body>\n <script>\n var scale = function (ratio) {\n return function (item) {\n if (typeof item === \"number\") {\n return item * ratio;\n }\n return item;\n };\n};\nfunction autoScaleCanvas(canvas) {\n var ctx = canvas.getContext(\"2d\");\n var ratio = window.devicePixelRatio || 1;\n if (ratio !== 1) {\n canvas.width *= ratio;\n canvas.height *= ratio;\n ctx.scale(ratio, ratio);\n ctx.isPointInPath = function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n return CanvasRenderingContext2D.prototype.isPointInPath.apply(ctx, args.map(scale(ratio)));\n };\n }\n return canvas;\n}\nwindow.autoScaleCanvas = autoScaleCanvas;\n</script>\n<script>\n\nvar WEBVIEW_TARGET = '@@WEBVIEW_TARGET';\n\nvar ID = function () {\n return Math.random().toString(32).slice(2);\n};\n\nvar flattenObjectCopyValue = function (flatObj, srcObj, key) {\n var value = srcObj[key];\n if (typeof value === 'function') {\n return;\n }\n if (typeof value === 'object' && value instanceof Node) {\n return;\n }\n flatObj[key] = flattenObject(value);\n};\n\nvar flattenObject = function (object) {\n if (typeof object !== 'object' || object === null) {\n return object;\n }\n // Handle TypedArray\n if (object instanceof Uint8ClampedArray) {\n return Array.from(object);\n }\n var flatObject = {};\n for (var key in object) {\n flattenObjectCopyValue(flatObject, object, key);\n }\n for (var key in Object.getOwnPropertyNames(object)) {\n flattenObjectCopyValue(flatObject, object, key);\n }\n return flatObject;\n};\n\nvar AutoScaledCanvas = function (element) {\n this.element = element;\n};\n\nAutoScaledCanvas.prototype.toDataURL = function () {\n return this.element.toDataURL.apply(this.element, arguments);\n};\n\nAutoScaledCanvas.prototype.autoScale = function () {\n if (this.savedHeight !== undefined) {\n this.element.height = this.savedHeight;\n }\n if (this.savedWidth !== undefined) {\n this.element.width = this.savedWidth;\n }\n window.autoScaleCanvas(this.element);\n};\n\nObject.defineProperty(AutoScaledCanvas.prototype, 'width', {\n get: function () {\n return this.element.width;\n },\n set: function (value) {\n this.savedWidth = value;\n this.autoScale();\n return value;\n },\n});\n\nObject.defineProperty(AutoScaledCanvas.prototype, 'height', {\n get: function () {\n return this.element.height;\n },\n set: function (value) {\n this.savedHeight = value;\n this.autoScale();\n return value;\n },\n});\nvar toMessage = function (result) {\n if (result instanceof Blob) {\n return {\n type: 'blob',\n payload: btoa(result),\n meta: {},\n };\n }\n if (result instanceof Object) {\n if (!result[WEBVIEW_TARGET]) {\n var id = ID();\n result[WEBVIEW_TARGET] = id;\n targets[id] = result;\n }\n return {\n type: 'json',\n payload: flattenObject(result),\n args: toArgs(flattenObject(result)),\n meta: {\n target: result[WEBVIEW_TARGET],\n constructor: result.__constructorName__ || result.constructor.name,\n },\n };\n }\n return {\n type: 'json',\n payload: typeof result === 'string' ? result : JSON.stringify(result),\n meta: {},\n };\n};\nvar toArgs = function (result) {\n var args = [];\n for (var key in result) {\n if (result[key] !== undefined && key !== '@@WEBVIEW_TARGET') {\n args.push(result[key]);\n }\n }\n return args;\n};\n\nvar createObjectsFromArgs = function (args) {\n for (var index = 0; index < args.length; index += 1) {\n var currentArg = args[index];\n if (currentArg && currentArg.className !== undefined) {\n var className = currentArg.className, classArgs = currentArg.classArgs;\n // new ImageData,第一个参数需要是 Uint8ClampedArray\n var object = new (Function.prototype.bind.apply(constructors[className], [null].concat(classArgs)))();\n args[index] = object;\n }\n }\n return args;\n};\n\nvar canvas = document.createElement('canvas');\ncanvas.style.width = '100%';\ncanvas.style.height = '100%';\nvar autoScaledCanvas = new AutoScaledCanvas(canvas);\n\nvar targets = {\n canvas: autoScaledCanvas,\n context2D: canvas.getContext('2d'),\n};\n\nvar constructors = {\n CanvasGradient: CanvasGradient,\n Image: Image,\n ImageData: ImageData,\n Uint8ClampedArray: Uint8ClampedArray,\n};\n\nImage.bind =\n Image.bind ||\n function () {\n return Image;\n };\n\nImageData.bind =\n ImageData.bind ||\n function () {\n return ImageData;\n };\nUint8ClampedArray.bind =\n Uint8ClampedArray.bind ||\n function () {\n return Uint8ClampedArray;\n };\n\nvar populateRefs = function (arg) {\n if (arg && arg.__ref__) {\n return targets[arg.__ref__];\n }\n return arg;\n};\ndocument.body.appendChild(canvas);\n\nvar mergeObjects = function (target, source) {\n for (var key in source) {\n if (source.hasOwnProperty(key)) {\n target[key] = source[key];\n }\n }\n return target;\n};\n\nfunction handleMessage(message) {\n var id = message.id,\n type = message.type,\n payload = message.payload;\n\n switch (type) {\n case 'exec': {\n var target = payload.target,\n method = payload.method,\n args = payload.args;\n var result = targets[target][method].apply(targets[target], args.map(populateRefs));\n var msg = toMessage(result);\n\n if (typeof result === 'object' && !msg.meta.constructor) {\n for (var constructorName in constructors) {\n if (result instanceof constructors[constructorName]) {\n msg.meta.constructor = constructorName;\n }\n }\n }\n window.ReactNativeWebView.postMessage(JSON.stringify(mergeObjects({ id: id }, msg)));\n break;\n }\n case 'set': {\n var target = payload.target,\n key = payload.key,\n value = payload.value;\n targets[target][key] = populateRefs(value);\n break;\n }\n case 'construct': {\n var constructor = payload.constructor,\n target = payload.id,\n args = payload.args || [];\n var newArgs = createObjectsFromArgs(args);\n var object;\n try {\n object = new (Function.prototype.bind.apply(constructors[constructor], [null].concat(newArgs)))();\n }\n catch (error) {\n throw new Error('Error while constructing '.concat(constructor, ' ').concat(error.message));\n }\n object.__constructorName__ = constructor;\n var msg = toMessage({});\n targets[target] = object;\n window.ReactNativeWebView.postMessage(JSON.stringify(mergeObjects({ id: id }, msg)));\n break;\n }\n case 'listen': {\n var types = payload.types,\n target = payload.target;\n for (var i = 0; i < types.length; i++) {\n var eventType = types[i];\n targets[target].addEventListener(eventType, function (e) {\n const message = toMessage({\n type: 'event',\n payload: {\n type: e.type,\n target: mergeObjects(flattenObject(targets[target]), {\n [WEBVIEW_TARGET]: target,\n }),\n },\n });\n window.ReactNativeWebView.postMessage(\n JSON.stringify(mergeObjects({ id: id }, message))\n );\n });\n }\n break;\n}\n }\n}\nvar handleError = function (err, message) {\n window.ReactNativeWebView.postMessage(JSON.stringify({\n id: message.id,\n type: 'error',\n payload: {\n message: err.message,\n stack: err.stack,\n },\n }));\n document.removeEventListener('message', handleIncomingMessage);\n};\n\nfunction handleIncomingMessage(data) {\n if (Array.isArray(data)) {\n for (var i = 0; i < data.length; i++) {\n try {\n handleMessage(data[i]);\n } catch (err) {\n handleError(err, data[i]);\n }\n }\n } else {\n try {\n handleMessage(data);\n } catch (err) {\n handleError(err, data);\n }\n }\n}\n\nwindow.mpxWebviewMessageCallback = handleIncomingMessage\n</script>\n \n\n</body></html>";
2
+ export default _default;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ✘ type
3
+ * ✘ canvas-id
4
+ * ✘ disable-scroll
5
+ * ✔ bindtouchstart
6
+ * ✔ bindtouchmove
7
+ * ✔ bindtouchend
8
+ * ✔ bindtouchcancel
9
+ * ✔ bindlongtap
10
+ * ✔ binderror
11
+ */
12
+ import { TouchEvent } from 'react';
13
+ import { View, NativeSyntheticEvent } from 'react-native';
14
+ import { HandlerRef } from '../useNodesRef';
15
+ import './CanvasGradient';
16
+ interface CanvasProps {
17
+ style?: Record<string, any>;
18
+ originWhitelist?: Array<string>;
19
+ 'enable-var'?: boolean;
20
+ 'parent-font-size'?: number;
21
+ 'parent-width'?: number;
22
+ 'parent-height'?: number;
23
+ 'external-var-context'?: Record<string, any>;
24
+ bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
25
+ bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
26
+ bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
27
+ bindtouchcancel?: (event: NativeSyntheticEvent<TouchEvent>) => void;
28
+ bindlongtap?: (event: NativeSyntheticEvent<TouchEvent>) => void;
29
+ binderror?: (event: NativeSyntheticEvent<ErrorEvent>) => void;
30
+ }
31
+ declare const _Canvas: import("react").ForwardRefExoticComponent<CanvasProps & import("react").RefAttributes<HandlerRef<CanvasProps & View, CanvasProps>>>;
32
+ export default _Canvas;
@@ -0,0 +1,52 @@
1
+ /// <reference types="react" />
2
+ import { WebView } from 'react-native-webview';
3
+ import Bus from './Bus';
4
+ export declare const WEBVIEW_TARGET = "@@WEBVIEW_TARGET";
5
+ export declare const constructors: Record<string, any>;
6
+ export declare const ID: () => string;
7
+ export interface Instance {
8
+ postMessage: (...args: any[]) => void;
9
+ [WEBVIEW_TARGET]?: string;
10
+ [key: string]: any;
11
+ }
12
+ export interface WebviewConstructor {
13
+ new (...args: any[]): Instance;
14
+ constructLocally?: (...args: unknown[]) => Instance;
15
+ }
16
+ export interface WebviewMessage {
17
+ type: 'set' | 'exec' | 'listen' | 'event' | 'construct';
18
+ payload: {
19
+ target?: string | {
20
+ [key: string]: any;
21
+ };
22
+ key?: string;
23
+ value?: any;
24
+ method?: string;
25
+ args?: any[];
26
+ types?: string[];
27
+ type?: string;
28
+ constructor?: string | Function;
29
+ id?: string;
30
+ };
31
+ }
32
+ export interface CanvasInstance {
33
+ webview: WebView | null;
34
+ bus: Bus | null;
35
+ context2D: CanvasRenderingContext2D;
36
+ getContext: (contextType: string) => CanvasRenderingContext2D | null;
37
+ createImage: (width?: number, height?: number) => any;
38
+ postMessage: (message: WebviewMessage) => Promise<any>;
39
+ listeners: Array<(payload: any) => void>;
40
+ addMessageListener: (listener: (payload: any) => void) => () => void;
41
+ removeMessageListener: (listener: (payload: any) => void) => void;
42
+ createImageData: (dataArray: number[], width?: number, height?: number) => any;
43
+ }
44
+ export declare const registerWebviewTarget: (instance: Instance, targetName: string) => void;
45
+ export declare const registerWebviewProperties: (instance: Instance, properties: Record<string, any>) => void;
46
+ export declare const registerWebviewMethods: (instance: Instance, methods: string[]) => void;
47
+ export declare const registerWebviewConstructor: (constructor: WebviewConstructor, constructorName: string) => void;
48
+ export declare const useWebviewBinding: ({ targetName, properties, methods }: {
49
+ targetName: string;
50
+ properties?: Record<string, any> | undefined;
51
+ methods?: string[] | undefined;
52
+ }) => import("react").MutableRefObject<{}>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * ✔ bindchange
3
+ */
4
+ import { ReactNode } from 'react';
5
+ import { View, NativeSyntheticEvent, ViewStyle } from 'react-native';
6
+ import { HandlerRef } from './useNodesRef';
7
+ export interface CheckboxGroupProps {
8
+ name: string;
9
+ style?: ViewStyle & Record<string, any>;
10
+ 'enable-offset'?: boolean;
11
+ 'enable-var'?: boolean;
12
+ 'external-var-context'?: Record<string, any>;
13
+ 'parent-font-size'?: number;
14
+ 'parent-width'?: number;
15
+ 'parent-height'?: number;
16
+ children: ReactNode;
17
+ bindchange?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void;
18
+ }
19
+ declare const CheckboxGroup: import("react").ForwardRefExoticComponent<CheckboxGroupProps & import("react").RefAttributes<HandlerRef<View, CheckboxGroupProps>>>;
20
+ export default CheckboxGroup;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ✔ value
3
+ * ✔ disabled
4
+ * ✔ checked
5
+ * ✔ color
6
+ */
7
+ import { ReactNode } from 'react';
8
+ import { View, ViewStyle, NativeSyntheticEvent } from 'react-native';
9
+ import { HandlerRef } from './useNodesRef';
10
+ interface Selection {
11
+ value?: string;
12
+ checked?: boolean;
13
+ }
14
+ export interface CheckboxProps extends Selection {
15
+ disabled?: boolean;
16
+ color?: string;
17
+ style?: ViewStyle & Record<string, any>;
18
+ groupValue?: Array<string>;
19
+ 'enable-offset'?: boolean;
20
+ 'enable-var'?: boolean;
21
+ 'external-var-context'?: Record<string, any>;
22
+ 'parent-font-size'?: number;
23
+ 'parent-width'?: number;
24
+ 'parent-height'?: number;
25
+ children?: ReactNode;
26
+ bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void;
27
+ _onChange?: (evt: NativeSyntheticEvent<TouchEvent> | unknown, { checked }: {
28
+ checked: boolean;
29
+ }) => void;
30
+ }
31
+ declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HandlerRef<View, CheckboxProps>>>;
32
+ export default Checkbox;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * ✘ report-submit
3
+ * ✘ report-submit-timeout
4
+ * ✔ bindsubmit
5
+ * ✔ bindreset
6
+ */
7
+ import { View } from 'react-native';
8
+ import { ReactNode } from 'react';
9
+ import { HandlerRef } from './useNodesRef';
10
+ interface FormProps {
11
+ style?: Record<string, any>;
12
+ children?: ReactNode;
13
+ 'enable-offset'?: boolean;
14
+ 'enable-var'?: boolean;
15
+ 'external-var-context'?: Record<string, any>;
16
+ 'parent-font-size'?: number;
17
+ 'parent-width'?: number;
18
+ 'parent-height'?: number;
19
+ bindsubmit?: (evt: {
20
+ detail: {
21
+ value: any;
22
+ };
23
+ }) => void;
24
+ bindreset?: () => void;
25
+ }
26
+ declare const _Form: import("react").ForwardRefExoticComponent<FormProps & import("react").RefAttributes<HandlerRef<View, FormProps>>>;
27
+ export default _Form;
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import { Text, TextStyle } from 'react-native';
3
+ import { HandlerRef } from '../useNodesRef';
4
+ export type IconType = 'success' | 'success_no_circle' | 'info' | 'warn' | 'waiting' | 'cancel' | 'download' | 'search' | 'clear';
5
+ export interface IconProps {
6
+ type: IconType;
7
+ size?: number;
8
+ color?: string;
9
+ style?: TextStyle & Record<string, any>;
10
+ 'enable-offset'?: boolean;
11
+ 'enable-var'?: boolean;
12
+ 'external-var-context'?: Record<string, any>;
13
+ 'parent-font-size'?: number;
14
+ 'parent-width'?: number;
15
+ 'parent-height'?: number;
16
+ }
17
+ declare const Icon: import("react").ForwardRefExoticComponent<IconProps & import("react").RefAttributes<HandlerRef<Text, IconProps>>>;
18
+ export default Icon;
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import { Image as RNImage, ImageStyle, NativeSyntheticEvent, ImageErrorEventData, ImageLoadEventData } from 'react-native';
3
+ import { HandlerRef } from './useNodesRef';
4
+ export type Mode = 'scaleToFill' | 'aspectFit' | 'aspectFill' | 'widthFix' | 'heightFix' | 'top' | 'bottom' | 'center' | 'left' | 'right' | 'top left' | 'top right' | 'bottom left' | 'bottom right';
5
+ export interface ImageProps {
6
+ src?: string;
7
+ mode?: Mode;
8
+ svg?: boolean;
9
+ style?: ImageStyle & Record<string, any>;
10
+ 'enable-offset'?: boolean;
11
+ 'enable-var'?: boolean;
12
+ 'external-var-context'?: Record<string, any>;
13
+ 'parent-font-size'?: number;
14
+ 'parent-width'?: number;
15
+ 'parent-height'?: number;
16
+ 'enable-fast-image'?: boolean;
17
+ bindload?: (evt: NativeSyntheticEvent<ImageLoadEventData> | unknown) => void;
18
+ binderror?: (evt: NativeSyntheticEvent<ImageErrorEventData> | unknown) => void;
19
+ }
20
+ declare const Image: import("react").ForwardRefExoticComponent<ImageProps & import("react").RefAttributes<HandlerRef<RNImage, ImageProps>>>;
21
+ export default Image;
@@ -0,0 +1,7 @@
1
+ import { TextProps } from 'react-native';
2
+ import { JSX } from 'react';
3
+ declare const InlineText: {
4
+ (props: TextProps): JSX.Element;
5
+ displayName: string;
6
+ };
7
+ export default InlineText;
@@ -0,0 +1,49 @@
1
+ /// <reference types="react" />
2
+ import { TextInput, TextStyle, ViewStyle, NativeSyntheticEvent, TextInputTextInputEventData, TextInputKeyPressEventData, TextInputContentSizeChangeEventData, FlexStyle, TextInputSelectionChangeEventData, TextInputFocusEventData, TextInputSubmitEditingEventData } from 'react-native';
3
+ import { HandlerRef } from './useNodesRef';
4
+ type InputStyle = Omit<TextStyle & ViewStyle & Pick<FlexStyle, 'minHeight'>, 'borderLeftWidth' | 'borderTopWidth' | 'borderRightWidth' | 'borderBottomWidth' | 'borderTopLeftRadius' | 'borderTopRightRadius' | 'borderBottomRightRadius' | 'borderBottomLeftRadius'>;
5
+ type Type = 'text' | 'number' | 'idcard' | 'digit';
6
+ type ConfirmType = 'done' | 'send' | 'search' | 'next' | 'go' | 'return';
7
+ export interface InputProps {
8
+ name?: string;
9
+ style?: InputStyle & Record<string, any>;
10
+ value?: string | number;
11
+ type?: Type;
12
+ password?: boolean;
13
+ placeholder?: string;
14
+ disabled?: boolean;
15
+ 'cursor-spacing'?: number;
16
+ maxlength?: number;
17
+ 'auto-focus'?: boolean;
18
+ focus?: boolean;
19
+ 'confirm-type'?: ConfirmType;
20
+ 'confirm-hold'?: boolean;
21
+ cursor?: number;
22
+ 'cursor-color'?: string;
23
+ 'selection-start'?: number;
24
+ 'selection-end'?: number;
25
+ 'placeholder-style'?: {
26
+ color?: string;
27
+ };
28
+ 'enable-offset'?: boolean;
29
+ 'enable-var'?: boolean;
30
+ 'external-var-context'?: Record<string, any>;
31
+ 'parent-font-size'?: number;
32
+ 'parent-width'?: number;
33
+ 'parent-height'?: number;
34
+ 'adjust-position': boolean;
35
+ bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void;
36
+ bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
37
+ bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
38
+ bindconfirm?: (evt: NativeSyntheticEvent<TextInputSubmitEditingEventData | TextInputKeyPressEventData> | unknown) => void;
39
+ bindselectionchange?: (evt: NativeSyntheticEvent<TextInputSelectionChangeEventData> | unknown) => void;
40
+ }
41
+ export interface PrivateInputProps {
42
+ allowFontScaling?: boolean;
43
+ multiline?: boolean;
44
+ 'auto-height'?: boolean;
45
+ bindlinechange?: (evt: NativeSyntheticEvent<TextInputContentSizeChangeEventData> | unknown) => void;
46
+ }
47
+ type FinalInputProps = InputProps & PrivateInputProps;
48
+ declare const Input: import("react").ForwardRefExoticComponent<InputProps & PrivateInputProps & import("react").RefAttributes<HandlerRef<TextInput, FinalInputProps>>>;
49
+ export default Input;
@@ -144,8 +144,8 @@ const Input = forwardRef((props, ref) => {
144
144
  }
145
145
  };
146
146
  const setKeyboardAvoidContext = () => {
147
- if (adjustPosition && keyboardAvoid) {
148
- keyboardAvoid.current = { cursorSpacing, ref: nodeRef };
147
+ if (keyboardAvoid) {
148
+ keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition };
149
149
  }
150
150
  };
151
151
  const onTouchStart = () => {
@@ -156,13 +156,32 @@ const Input = forwardRef((props, ref) => {
156
156
  evt.nativeEvent.origin = 'input';
157
157
  };
158
158
  const onFocus = (evt) => {
159
- setKeyboardAvoidContext();
160
- bindfocus && bindfocus(getCustomEvent('focus', evt, {
161
- detail: {
162
- value: tmpValue.current || ''
163
- },
164
- layoutRef
165
- }, props));
159
+ if (!keyboardAvoid?.current) {
160
+ setKeyboardAvoidContext();
161
+ }
162
+ if (bindfocus && keyboardAvoid?.current) {
163
+ const focusAction = () => {
164
+ bindfocus(getCustomEvent('focus', evt, {
165
+ detail: {
166
+ value: tmpValue.current || '',
167
+ height: keyboardAvoid.current?.keyboardHeight,
168
+ },
169
+ layoutRef
170
+ }, props));
171
+ if (keyboardAvoid.current?.onKeyboardShow) {
172
+ keyboardAvoid.current.onKeyboardShow = undefined;
173
+ }
174
+ };
175
+ if (keyboardAvoid.current.keyboardHeight) {
176
+ // iOS: keyboard 获取高度时机 keyboardWillShow 在 input focus 之前,可以立即执行
177
+ focusAction();
178
+ }
179
+ else {
180
+ // Android,Harmony: keyboard 获取高度时机 keyboardDidShow 在 input focus 之后,需要延迟回调
181
+ evt.persist();
182
+ keyboardAvoid.current.onKeyboardShow = focusAction;
183
+ }
184
+ }
166
185
  };
167
186
  const onBlur = (evt) => {
168
187
  bindblur && bindblur(getCustomEvent('blur', evt, {