@mpxjs/webpack-plugin 2.9.69 → 2.9.70-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/ResolveDependency.js +5 -0
  5. package/lib/index.js +38 -7
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +52 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/image.js +4 -0
  10. package/lib/platform/template/wx/component-config/input.js +5 -1
  11. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  12. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  13. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  14. package/lib/platform/template/wx/component-config/switch.js +4 -0
  15. package/lib/platform/template/wx/component-config/text.js +4 -0
  16. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  17. package/lib/platform/template/wx/component-config/view.js +4 -0
  18. package/lib/platform/template/wx/index.js +127 -1
  19. package/lib/react/processTemplate.js +3 -0
  20. package/lib/resolve-loader.js +4 -1
  21. package/lib/runtime/components/react/context.ts +4 -0
  22. package/lib/runtime/components/react/dist/context.js +5 -0
  23. package/lib/runtime/components/react/dist/event.config.js +24 -24
  24. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
  25. package/lib/runtime/components/react/dist/locale-provider.jsx +15 -0
  26. package/lib/runtime/components/react/dist/mpx-button.jsx +39 -74
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
  28. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  29. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  30. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  31. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  32. package/lib/runtime/components/react/dist/mpx-image.jsx +295 -0
  33. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  34. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  35. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  36. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  37. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  38. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  39. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  40. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  41. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -14
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +126 -112
  46. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
  47. package/lib/runtime/components/react/dist/mpx-portal/portal-consumer.jsx +23 -0
  48. package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +124 -0
  49. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +40 -0
  50. package/lib/runtime/components/react/dist/mpx-portal.jsx +12 -0
  51. package/lib/runtime/components/react/dist/mpx-provider.jsx +31 -0
  52. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  53. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  54. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  55. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  56. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  57. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +62 -47
  58. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  59. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  60. package/lib/runtime/components/react/dist/mpx-swiper.jsx +613 -0
  61. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  62. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  63. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  64. package/lib/runtime/components/react/dist/mpx-view.jsx +37 -89
  65. package/lib/runtime/components/react/dist/mpx-web-view.jsx +205 -46
  66. package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
  67. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  68. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  69. package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
  70. package/lib/runtime/components/react/dist/useAnimationHooks.js +50 -12
  71. package/lib/runtime/components/react/dist/utils.jsx +83 -28
  72. package/lib/runtime/components/react/getInnerListeners.ts +35 -28
  73. package/lib/runtime/components/react/mpx-button.tsx +55 -36
  74. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  75. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  76. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  77. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  78. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  79. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  80. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  81. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  82. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  83. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  84. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  85. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  86. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  87. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  88. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  89. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  90. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  91. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  92. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  93. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  94. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  95. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  96. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  97. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  98. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  99. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  100. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  101. package/lib/runtime/components/react/mpx-view.tsx +37 -45
  102. package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
  103. package/lib/runtime/components/react/types/global.d.ts +1 -16
  104. package/lib/runtime/components/react/utils.tsx +24 -24
  105. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  106. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  107. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  108. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  109. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  110. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  111. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  112. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  113. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  114. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  115. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  116. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  117. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  118. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  119. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  120. package/lib/runtime/optionProcessor.js +7 -16
  121. package/lib/runtime/optionProcessor.tenon.js +84 -0
  122. package/lib/runtime/utils.js +2 -0
  123. package/lib/style-compiler/index.js +1 -1
  124. package/lib/style-compiler/plugins/hm.js +20 -0
  125. package/lib/template-compiler/bind-this.js +7 -2
  126. package/lib/template-compiler/compiler.js +67 -40
  127. package/lib/template-compiler/gen-node-react.js +2 -2
  128. package/lib/tenon/index.js +112 -0
  129. package/lib/tenon/processJSON.js +352 -0
  130. package/lib/tenon/processScript.js +198 -0
  131. package/lib/tenon/processStyles.js +21 -0
  132. package/lib/tenon/processTemplate.js +125 -0
  133. package/lib/tenon/script-helper.js +223 -0
  134. package/lib/utils/env.js +6 -1
  135. package/lib/utils/get-relative-path.js +25 -0
  136. package/package.json +7 -3
  137. package/LICENSE +0 -433
  138. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  139. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  140. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  141. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  142. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  143. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  144. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
@@ -0,0 +1,23 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { getFocusedNavigation } from '@mpxjs/utils';
3
+ const PortalConsumer = ({ manager, children }) => {
4
+ const keyRef = useRef(null);
5
+ useEffect(() => {
6
+ const navigation = getFocusedNavigation();
7
+ const curPageId = navigation?.pageId;
8
+ manager.update(keyRef.current, children, curPageId);
9
+ }, [children]);
10
+ useEffect(() => {
11
+ if (!manager) {
12
+ throw new Error('Looks like you forgot to wrap your root component with `Provider` component from `@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-portal`.\n\n');
13
+ }
14
+ const navigation = getFocusedNavigation();
15
+ const curPageId = navigation?.pageId;
16
+ keyRef.current = manager.mount(children, undefined, curPageId);
17
+ return () => {
18
+ manager.unmount(keyRef.current, curPageId);
19
+ };
20
+ }, []);
21
+ return null;
22
+ };
23
+ export default PortalConsumer;
@@ -0,0 +1,124 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { View, DeviceEventEmitter, NativeEventEmitter, StyleSheet } from 'react-native';
3
+ import PortalManager from './portal-manager';
4
+ import { getFocusedNavigation } from '@mpxjs/utils';
5
+ import { PortalContext } from '../context';
6
+ // events
7
+ const addType = 'MPX_RN_ADD_PORTAL';
8
+ const removeType = 'MPX_RN_REMOVE_PORTAL';
9
+ // fix react native web does not support DeviceEventEmitter
10
+ const TopViewEventEmitter = DeviceEventEmitter || new NativeEventEmitter();
11
+ const styles = StyleSheet.create({
12
+ container: {
13
+ flex: 1
14
+ }
15
+ });
16
+ class PortalGuard {
17
+ nextKey = 10000;
18
+ add = (e) => {
19
+ const key = this.nextKey++;
20
+ TopViewEventEmitter.emit(addType, e, key);
21
+ return key;
22
+ };
23
+ remove = (key) => {
24
+ TopViewEventEmitter.emit(removeType, key);
25
+ };
26
+ }
27
+ /**
28
+ * portal
29
+ */
30
+ export const portal = new PortalGuard();
31
+ const PortalHost = ({ children }) => {
32
+ const _nextKey = useRef(0);
33
+ const _queue = useRef([]);
34
+ const _addType = useRef(null);
35
+ const _removeType = useRef(null);
36
+ const manager = useRef(null);
37
+ let currentPageId;
38
+ const _mount = (children, _key, curPageId) => {
39
+ const navigation = getFocusedNavigation();
40
+ const pageId = navigation?.pageId;
41
+ if (pageId !== (curPageId ?? currentPageId)) {
42
+ return;
43
+ }
44
+ const key = _key || _nextKey.current++;
45
+ if (manager.current) {
46
+ manager.current.mount(key, children);
47
+ }
48
+ else {
49
+ _queue.current.push({ type: 'mount', key, children });
50
+ }
51
+ return key;
52
+ };
53
+ const _unmount = (key, curPageId) => {
54
+ const navigation = getFocusedNavigation();
55
+ const pageId = navigation?.pageId;
56
+ if (pageId !== (curPageId ?? currentPageId)) {
57
+ return;
58
+ }
59
+ if (manager.current) {
60
+ manager.current.unmount(key);
61
+ }
62
+ else {
63
+ _queue.current.push({ type: 'unmount', key });
64
+ }
65
+ };
66
+ const _update = (key, children, curPageId) => {
67
+ const navigation = getFocusedNavigation();
68
+ const pageId = navigation?.pageId;
69
+ if (pageId !== (curPageId ?? currentPageId)) {
70
+ return;
71
+ }
72
+ if (manager.current) {
73
+ manager.current.update(key, children);
74
+ }
75
+ else {
76
+ const op = { type: 'mount', key, children };
77
+ const index = _queue.current.findIndex((o) => o.type === 'mount' || (o.type === 'update' && o.key === key));
78
+ if (index > -1) {
79
+ _queue.current[index] = op;
80
+ }
81
+ else {
82
+ _queue.current.push(op);
83
+ }
84
+ }
85
+ };
86
+ useEffect(() => {
87
+ const navigation = getFocusedNavigation();
88
+ currentPageId = navigation?.pageId;
89
+ _addType.current = TopViewEventEmitter.addListener(addType, _mount);
90
+ _removeType.current = TopViewEventEmitter.addListener(removeType, _unmount);
91
+ return () => {
92
+ while (_queue.current.length && manager.current) {
93
+ const action = _queue.current.pop();
94
+ if (!action) {
95
+ continue;
96
+ }
97
+ // tslint:disable-next-line:switch-default
98
+ switch (action.type) {
99
+ case 'mount':
100
+ manager.current?.mount(action.key, action.children);
101
+ break;
102
+ case 'update':
103
+ manager.current?.update(action.key, action.children);
104
+ break;
105
+ case 'unmount':
106
+ manager.current?.unmount(action.key);
107
+ break;
108
+ }
109
+ }
110
+ };
111
+ }, []);
112
+ return (<PortalContext.Provider value={{
113
+ mount: _mount,
114
+ update: _update,
115
+ unmount: _unmount
116
+ }}>
117
+ {/* Need collapsable=false here to clip the elevations, otherwise they appear above Portal components */}
118
+ <View style={styles.container} collapsable={false}>
119
+ {children}
120
+ </View>
121
+ <PortalManager ref={manager}/>
122
+ </PortalContext.Provider>);
123
+ };
124
+ export default PortalHost;
@@ -0,0 +1,40 @@
1
+ import { useState, useCallback, forwardRef, useImperativeHandle } from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ const _PortalManager = forwardRef((props, ref) => {
4
+ const [state, setState] = useState({
5
+ portals: []
6
+ });
7
+ const mount = useCallback((key, children) => {
8
+ setState((prevState) => ({
9
+ portals: [...prevState.portals, { key, children }]
10
+ }));
11
+ }, [state]);
12
+ const update = useCallback((key, children) => {
13
+ setState((prevState) => ({
14
+ portals: prevState.portals.map((item) => {
15
+ if (item.key === key) {
16
+ return { ...item, children };
17
+ }
18
+ return item;
19
+ })
20
+ }));
21
+ }, [state]);
22
+ const unmount = useCallback((key) => {
23
+ setState((prevState) => ({
24
+ portals: prevState.portals.filter((item) => item.key !== key)
25
+ }));
26
+ }, []);
27
+ useImperativeHandle(ref, () => ({
28
+ mount,
29
+ update,
30
+ unmount,
31
+ portals: state.portals
32
+ }));
33
+ return (<>
34
+ {state.portals.map(({ key, children }, i) => (<View key={key} collapsable={false} // Need collapsable=false here to clip the elevations
35
+ pointerEvents="box-none" style={[StyleSheet.absoluteFill, { zIndex: 1000 + i }]}>
36
+ {children}
37
+ </View>))}
38
+ </>);
39
+ });
40
+ export default _PortalManager;
@@ -0,0 +1,12 @@
1
+ import { PortalContext } from './context';
2
+ import PortalConsumer from './mpx-portal/portal-consumer';
3
+ import PortalHost, { portal } from './mpx-portal/portal-host';
4
+ const Portal = ({ children }) => {
5
+ return (<PortalContext.Consumer>
6
+ {(manager) => (<PortalConsumer manager={manager}>{children}</PortalConsumer>)}
7
+ </PortalContext.Consumer>);
8
+ };
9
+ Portal.Host = PortalHost;
10
+ Portal.add = portal.add;
11
+ Portal.remove = portal.remove;
12
+ export default Portal;
@@ -0,0 +1,31 @@
1
+ import { createContext, useMemo } from 'react';
2
+ import LocaleProvider from './locale-provider';
3
+ import Portal from './mpx-portal';
4
+ import { extendObject } from './utils';
5
+ const defaultTheme = {
6
+ color_text_base: '#000000',
7
+ color_text_base_inverse: '#ffffff',
8
+ color_text_secondary: '#a4a9b0',
9
+ color_text_placeholder: '#bbbbbb',
10
+ color_text_disabled: '#bbbbbb',
11
+ color_text_caption: '#888888',
12
+ color_text_paragraph: '#333333',
13
+ color_error: '#ff4d4f',
14
+ color_warning: '#faad14',
15
+ color_success: '#52c41a',
16
+ color_primary: '#1677ff'
17
+ };
18
+ export const ThemeContext = createContext(defaultTheme);
19
+ const ThemeProvider = (props) => {
20
+ const { value, children } = props;
21
+ const theme = useMemo(() => (extendObject({}, defaultTheme, value)), [value]);
22
+ return <ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>;
23
+ };
24
+ const Provider = ({ locale, theme, children }) => {
25
+ return (<LocaleProvider locale={locale}>
26
+ <ThemeProvider value={theme}>
27
+ <Portal.Host>{children}</Portal.Host>
28
+ </ThemeProvider>
29
+ </LocaleProvider>);
30
+ };
31
+ export default Provider;
@@ -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, RadioGroupContext } 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 radioGroup = forwardRef((props, ref) => {
12
12
  const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
13
13
  const propsRef = useRef({});
@@ -22,13 +22,10 @@ const radioGroup = 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, { defaultStyle });
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
  for (const key in groupValue) {
@@ -74,21 +71,16 @@ const radioGroup = forwardRef((props, ref) => {
74
71
  notifyChange
75
72
  };
76
73
  }, []);
77
- const innerProps = useInnerProps(props, {
74
+ const innerProps = useInnerProps(props, extendObject({
78
75
  ref: nodeRef,
79
- style: { ...normalStyle, ...layoutStyle },
80
- ...layoutProps
81
- }, [], {
76
+ style: extendObject({}, normalStyle, layoutStyle)
77
+ }, layoutProps), ['name'], {
82
78
  layoutRef
83
79
  });
84
- return (<View {...innerProps}>
85
- <RadioGroupContext.Provider value={contextValue}>
86
- {wrapChildren(props, {
87
- hasVarDec,
88
- varContext: varContextRef.current
89
- })}
90
- </RadioGroupContext.Provider>
91
- </View>);
80
+ return createElement(View, innerProps, createElement(RadioGroupContext.Provider, { value: contextValue }, wrapChildren(props, {
81
+ hasVarDec,
82
+ varContext: varContextRef.current
83
+ })));
92
84
  });
93
85
  radioGroup.displayName = 'MpxRadioGroup';
94
86
  export default radioGroup;
@@ -4,13 +4,13 @@
4
4
  * ✔ checked
5
5
  * ✔ color
6
6
  */
7
- import { useRef, useState, forwardRef, useEffect, useContext } from 'react';
7
+ import { useRef, useState, forwardRef, useEffect, useContext, createElement } from 'react';
8
8
  import { View, StyleSheet } from 'react-native';
9
9
  import { warn } from '@mpxjs/utils';
10
10
  import { LabelContext, RadioGroupContext } from './context';
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
12
12
  import useNodesRef from './useNodesRef';
13
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
14
14
  import Icon from './mpx-icon';
15
15
  const styles = StyleSheet.create({
16
16
  container: {
@@ -47,21 +47,14 @@ const styles = StyleSheet.create({
47
47
  });
48
48
  const Radio = forwardRef((radioProps, ref) => {
49
49
  const { textProps, innerProps: props = {} } = splitProps(radioProps);
50
- 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, catchtap } = props;
50
+ 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 } = props;
51
51
  const [isChecked, setIsChecked] = useState(!!checked);
52
52
  const groupContext = useContext(RadioGroupContext);
53
53
  let groupValue;
54
54
  let notifyChange;
55
55
  const labelContext = useContext(LabelContext);
56
- const defaultStyle = {
57
- ...styles.wrapper,
58
- ...(isChecked && styles.wrapperChecked),
59
- ...(disabled && styles.wrapperDisabled)
60
- };
61
- const styleObj = {
62
- ...styles.container,
63
- ...style
64
- };
56
+ const defaultStyle = extendObject({}, styles.wrapper, isChecked ? styles.wrapperChecked : {}, disabled ? styles.wrapperDisabled : {});
57
+ const styleObj = extendObject({}, styles.container, style);
65
58
  const onChange = (evt) => {
66
59
  if (disabled || isChecked)
67
60
  return;
@@ -77,24 +70,17 @@ const Radio = forwardRef((radioProps, ref) => {
77
70
  notifyChange && notifyChange(evt);
78
71
  };
79
72
  const onTap = (evt) => {
80
- if (disabled)
81
- return;
82
73
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
83
74
  onChange(evt);
84
75
  };
85
- const catchTap = (evt) => {
86
- if (disabled)
87
- return;
88
- catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
89
- };
90
76
  const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
91
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
77
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
92
78
  if (backgroundStyle) {
93
79
  warn('Radio does not support background image-related styles!');
94
80
  }
95
81
  const nodeRef = useRef(null);
96
82
  useNodesRef(props, ref, nodeRef, {
97
- defaultStyle,
83
+ style: extendObject({}, defaultStyle, normalStyle),
98
84
  change: onChange
99
85
  });
100
86
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
@@ -105,13 +91,16 @@ const Radio = forwardRef((radioProps, ref) => {
105
91
  if (labelContext) {
106
92
  labelContext.current.triggerChange = onChange;
107
93
  }
108
- const innerProps = useInnerProps(props, {
94
+ const innerProps = useInnerProps(props, extendObject({
109
95
  ref: nodeRef,
110
- style: { ...innerStyle, ...layoutStyle },
111
- ...layoutProps,
112
- bindtap: onTap,
113
- catchtap: catchTap
114
- }, [], {
96
+ style: extendObject({}, innerStyle, layoutStyle)
97
+ }, layoutProps, {
98
+ bindtap: !disabled && onTap
99
+ }), [
100
+ 'value',
101
+ 'disabled',
102
+ 'checked'
103
+ ], {
115
104
  layoutRef
116
105
  });
117
106
  useEffect(() => {
@@ -135,21 +124,17 @@ const Radio = forwardRef((radioProps, ref) => {
135
124
  }
136
125
  }
137
126
  }, [checked]);
138
- return (<View {...innerProps}>
139
- <View style={defaultStyle}>
140
- <Icon type='success' size={24} color={disabled ? '#E1E1E1' : color} style={{
141
- ...styles.icon,
142
- ...(isChecked && styles.iconChecked),
143
- ...(disabled && styles.iconDisabled)
144
- }}/>
145
- </View>
146
- {wrapChildren(props, {
147
- hasVarDec,
148
- varContext: varContextRef.current,
149
- textStyle,
150
- textProps
151
- })}
152
- </View>);
127
+ return createElement(View, innerProps, createElement(View, { style: defaultStyle }, createElement(Icon, {
128
+ type: 'success',
129
+ size: 24,
130
+ color: disabled ? '#E1E1E1' : color,
131
+ style: extendObject({}, styles.icon, isChecked && styles.iconChecked, disabled && styles.iconDisabled)
132
+ })), wrapChildren(props, {
133
+ hasVarDec,
134
+ varContext: varContextRef.current,
135
+ textStyle,
136
+ textProps
137
+ }));
153
138
  });
154
139
  Radio.displayName = 'MpxRadio';
155
140
  export default Radio;
@@ -0,0 +1,39 @@
1
+ export const generateHTML = (html) => {
2
+ return `<html><head>
3
+ <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no" name="viewport">
4
+ <style>
5
+ html {
6
+ -ms-content-zooming: none;
7
+ -ms-touch-action: pan-x pan-y;
8
+ }
9
+ body {
10
+ position: fixed;
11
+ top: 0;
12
+ right: 0;
13
+ bottom: 0;
14
+ left: 0;
15
+ overflow: hidden;
16
+ }
17
+ html,body {
18
+ margin: 0;
19
+ padding: 0;
20
+ }
21
+ * {
22
+ user-select: none;
23
+ -ms-user-select: none;
24
+ -moz-user-select: none;
25
+ -webkit-user-select: none;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body><div id="rich-text">${html}</div>
30
+ <script>
31
+ function sendHeight() {
32
+ const dom = document.getElementById('rich-text')
33
+ window.ReactNativeWebView.postMessage(dom.scrollHeight);
34
+ }
35
+ window.onload = sendHeight;
36
+ </script>
37
+ </body
38
+ ></html>`;
39
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * ✔ nodes
3
+ */
4
+ import { View } from 'react-native';
5
+ import { useRef, forwardRef, useState, createElement } from 'react';
6
+ import useInnerProps from '../getInnerListeners';
7
+ import useNodesRef from '../useNodesRef'; // 引入辅助函数
8
+ import { useTransformStyle, useLayout, extendObject } from '../utils';
9
+ import { WebView } from 'react-native-webview';
10
+ import { generateHTML } from './html';
11
+ function jsonToHtmlStr(elements) {
12
+ let htmlStr = '';
13
+ for (const element of elements) {
14
+ if (element.type === 'text') {
15
+ htmlStr += element.text;
16
+ return htmlStr;
17
+ }
18
+ const { name, attrs = {}, children = [] } = element;
19
+ let attrStr = '';
20
+ for (const [key, value] of Object.entries(attrs))
21
+ attrStr += ` ${key}="${value}"`;
22
+ let childrenStr = '';
23
+ for (const child of children)
24
+ childrenStr += jsonToHtmlStr([child]);
25
+ htmlStr += `<${name}${attrStr}>${childrenStr}</${name}>`;
26
+ }
27
+ return htmlStr;
28
+ }
29
+ const _RichText = forwardRef((props, ref) => {
30
+ const { style = {}, nodes, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
31
+ const nodeRef = useRef(null);
32
+ const [webViewHeight, setWebViewHeight] = useState(0);
33
+ const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(Object.assign({
34
+ width: '100%',
35
+ height: webViewHeight
36
+ }, style), {
37
+ enableVar,
38
+ externalVarContext,
39
+ parentFontSize,
40
+ parentWidth,
41
+ parentHeight
42
+ });
43
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
44
+ useNodesRef(props, ref, nodeRef, {
45
+ layoutRef
46
+ });
47
+ const innerProps = useInnerProps(props, extendObject({
48
+ ref: nodeRef,
49
+ style: extendObject(normalStyle, layoutStyle)
50
+ }, layoutProps), [], {
51
+ layoutRef
52
+ });
53
+ const html = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes);
54
+ return createElement(View, innerProps, createElement(WebView, {
55
+ source: { html: generateHTML(html) },
56
+ onMessage: (event) => {
57
+ setWebViewHeight(+event.nativeEvent.data);
58
+ }
59
+ }));
60
+ });
61
+ _RichText.displayName = 'mpx-rich-text';
62
+ export default _RichText;
@@ -1,4 +1,8 @@
1
- import { Portal } from '@ant-design/react-native';
1
+ /**
2
+ * ✔ enable
3
+ */
4
+ import { createElement, Fragment } from 'react';
5
+ import Portal from './mpx-portal';
2
6
  import { warn } from '@mpxjs/utils';
3
7
  const _RootPortal = (props) => {
4
8
  const { children, enable = true } = props;
@@ -6,10 +10,8 @@ const _RootPortal = (props) => {
6
10
  warn('The root-portal component does not support the style prop.');
7
11
  }
8
12
  return enable
9
- ? <Portal>
10
- {children}
11
- </Portal>
12
- : <>{children}</>;
13
+ ? createElement(Portal, null, children)
14
+ : createElement(Fragment, null, children);
13
15
  };
14
16
  _RootPortal.displayName = 'MpxRootPortal';
15
17
  export default _RootPortal;