@mpxjs/webpack-plugin 2.9.66 → 2.9.69

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 (112) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +3 -10
  8. package/lib/platform/style/wx/index.js +15 -10
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  11. package/lib/react/index.js +4 -3
  12. package/lib/react/processJSON.js +5 -13
  13. package/lib/react/processMainScript.js +7 -3
  14. package/lib/react/processScript.js +3 -4
  15. package/lib/react/processStyles.js +14 -4
  16. package/lib/react/processTemplate.js +2 -2
  17. package/lib/resolver/AddModePlugin.js +20 -7
  18. package/lib/runtime/components/react/context.ts +2 -0
  19. package/lib/runtime/components/react/dist/context.js +1 -0
  20. package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
  21. package/lib/runtime/components/react/dist/mpx-button.jsx +44 -9
  22. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  23. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  31. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
  32. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
  33. package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
  34. package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
  35. package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
  38. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
  39. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
  40. package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
  41. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
  42. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
  43. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
  44. package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
  45. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
  46. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
  47. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
  48. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
  49. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
  50. package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
  51. package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
  52. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  53. package/lib/runtime/components/react/dist/mpx-view.jsx +46 -27
  54. package/lib/runtime/components/react/dist/mpx-web-view.jsx +20 -6
  55. package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
  56. package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
  57. package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
  58. package/lib/runtime/components/react/dist/utils.jsx +66 -6
  59. package/lib/runtime/components/react/getInnerListeners.ts +3 -16
  60. package/lib/runtime/components/react/mpx-button.tsx +42 -9
  61. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  62. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  63. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  64. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  65. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  66. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  67. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  68. package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
  69. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  70. package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
  71. package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
  72. package/lib/runtime/components/react/mpx-form.tsx +42 -34
  73. package/lib/runtime/components/react/mpx-icon.tsx +1 -1
  74. package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
  75. package/lib/runtime/components/react/mpx-input.tsx +68 -66
  76. package/lib/runtime/components/react/mpx-label.tsx +11 -8
  77. package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
  78. package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
  79. package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
  80. package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
  81. package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
  82. package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
  83. package/lib/runtime/components/react/mpx-radio.tsx +1 -1
  84. package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
  85. package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
  86. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
  87. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  88. package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
  89. package/lib/runtime/components/react/mpx-switch.tsx +10 -2
  90. package/lib/runtime/components/react/mpx-text.tsx +1 -1
  91. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  92. package/lib/runtime/components/react/mpx-view.tsx +58 -28
  93. package/lib/runtime/components/react/mpx-web-view.tsx +23 -6
  94. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  95. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  96. package/lib/runtime/components/react/types/common.ts +2 -0
  97. package/lib/runtime/components/react/types/global.d.ts +2 -0
  98. package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
  99. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  100. package/lib/runtime/components/react/utils.tsx +94 -8
  101. package/lib/runtime/optionProcessorReact.js +0 -15
  102. package/lib/runtime/swanHelper.wxs +1 -1
  103. package/lib/style-compiler/index.js +1 -1
  104. package/lib/style-compiler/plugins/scope-id.js +1 -0
  105. package/lib/template-compiler/compiler.js +47 -16
  106. package/lib/template-compiler/gen-node-react.js +2 -2
  107. package/lib/template-compiler/index.js +4 -4
  108. package/lib/utils/pre-process-json.js +113 -0
  109. package/lib/web/index.js +5 -4
  110. package/lib/web/processJSON.js +5 -13
  111. package/lib/web/processTemplate.js +2 -2
  112. package/package.json +5 -4
@@ -12,9 +12,8 @@ const createJSONHelper = require('../json-compiler/helper')
12
12
  const getRulesRunner = require('../platform/index')
13
13
  const { RESOLVE_IGNORED_ERR } = require('../utils/const')
14
14
  const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
15
- const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
16
15
 
17
- module.exports = function (json, {
16
+ module.exports = function (jsonContent, {
18
17
  loaderContext,
19
18
  ctorType,
20
19
  pagesMap,
@@ -81,12 +80,11 @@ module.exports = function (json, {
81
80
  }
82
81
 
83
82
  const isApp = ctorType === 'app'
84
- if (!json) {
83
+ if (!jsonContent) {
85
84
  return callback()
86
85
  }
87
- // 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
88
86
  try {
89
- jsonObj = JSON5.parse(json.content)
87
+ jsonObj = JSON5.parse(jsonContent)
90
88
  // 处理runner
91
89
  const rulesRunnerOptions = {
92
90
  mode,
@@ -96,8 +94,8 @@ module.exports = function (json, {
96
94
  warn: emitWarning,
97
95
  error: emitError,
98
96
  data: {
99
- // polyfill global usingComponents & record globalComponents
100
- globalComponents: mpx.usingComponents
97
+ // polyfill global usingComponents
98
+ globalComponents: mpx.globalComponents
101
99
  }
102
100
  }
103
101
 
@@ -110,12 +108,6 @@ module.exports = function (json, {
110
108
  if (rulesRunner) {
111
109
  rulesRunner(jsonObj)
112
110
  }
113
- if (isApp) {
114
- // 收集全局组件
115
- Object.assign(mpx.usingComponents, jsonObj.usingComponents)
116
- // 在 rulesRunner 运行后保存全局注册组件
117
- loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, loaderContext.context))
118
- }
119
111
  } catch (e) {
120
112
  return callback(e)
121
113
  }
@@ -8,7 +8,7 @@ const {
8
8
  module.exports = function ({
9
9
  loaderContext
10
10
  }, callback) {
11
- const { i18n, projectName } = loaderContext.getMpx()
11
+ const { i18n, rnConfig } = loaderContext.getMpx()
12
12
 
13
13
  let output = 'import { AppRegistry } from \'react-native\'\n'
14
14
 
@@ -16,8 +16,12 @@ module.exports = function ({
16
16
  output += buildI18n({ loaderContext })
17
17
  }
18
18
  // 此处可添加前置于App执行的语句
19
- output += `var App = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
20
- output += `AppRegistry.registerComponent(${JSON.stringify(projectName)}, () => App)\n`
19
+ output += `var app = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
20
+ if (rnConfig.projectName) {
21
+ output += `AppRegistry.registerComponent(${JSON.stringify(rnConfig.projectName)}, () => app)\n`
22
+ } else {
23
+ output += 'export default app\n'
24
+ }
21
25
 
22
26
  callback(null, {
23
27
  output
@@ -24,16 +24,15 @@ module.exports = function (script, {
24
24
  if (ctorType === 'app') {
25
25
  output += `
26
26
  import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
27
- import { NavigationContainer, createNavigationContainerRef, StackActions } from '@react-navigation/native'
28
- import { createNativeStackNavigator } from '@react-navigation/native-stack'
27
+ import { NavigationContainer, StackActions } from '@react-navigation/native'
28
+ import { createStackNavigator } from '@react-navigation/stack'
29
29
  import { Provider } from '@ant-design/react-native'
30
30
  import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
31
31
  import { GestureHandlerRootView } from 'react-native-gesture-handler'
32
32
 
33
33
  global.__navigationHelper = {
34
34
  NavigationContainer: NavigationContainer,
35
- createNavigationContainerRef: createNavigationContainerRef,
36
- createNativeStackNavigator: createNativeStackNavigator,
35
+ createStackNavigator: createStackNavigator,
37
36
  StackActions: StackActions,
38
37
  GestureHandlerRootView: GestureHandlerRootView,
39
38
  Provider: Provider,
@@ -56,13 +56,23 @@ module.exports = function (styles, {
56
56
  error
57
57
  })
58
58
  if (ctorType === 'app') {
59
- output += `global.__getAppClassMap = function() {
60
- return ${shallowStringify(classMap)};
59
+ output += `
60
+ let __appClassMap
61
+ global.__getAppClassMap = function() {
62
+ if(!__appClassMap) {
63
+ __appClassMap = ${shallowStringify(classMap)};
64
+ }
65
+ return __appClassMap;
61
66
  };\n`
62
67
  } else {
63
- output += `global.currentInject.injectMethods = {
68
+ output += `
69
+ let __classMap
70
+ global.currentInject.injectMethods = {
64
71
  __getClassMap: function() {
65
- return ${shallowStringify(classMap)};
72
+ if(!__classMap) {
73
+ __classMap = ${shallowStringify(classMap)};
74
+ }
75
+ return __classMap;
66
76
  }
67
77
  };\n`
68
78
  }
@@ -14,7 +14,7 @@ module.exports = function (template, {
14
14
  srcMode,
15
15
  moduleId,
16
16
  ctorType,
17
- usingComponents,
17
+ usingComponentsInfo,
18
18
  componentGenerics
19
19
  }, callback) {
20
20
  const mpx = loaderContext.getMpx()
@@ -64,7 +64,7 @@ module.exports = function (template, {
64
64
  const { root, meta } = templateCompiler.parse(template.content, {
65
65
  warn,
66
66
  error,
67
- usingComponents,
67
+ usingComponentsInfo, // processTemplate中无其他地方使用,直接透传 string 类型
68
68
  hasComment,
69
69
  isNative,
70
70
  ctorType,
@@ -6,16 +6,17 @@ const addInfix = require('../utils/add-infix')
6
6
  const { JSON_JS_EXT } = require('../utils/const')
7
7
 
8
8
  module.exports = class AddModePlugin {
9
- constructor (source, mode, fileConditionRules, target) {
9
+ constructor (source, mode, options, target) {
10
10
  this.source = source
11
11
  this.target = target
12
12
  this.mode = mode
13
- this.fileConditionRules = fileConditionRules
13
+ this.options = options
14
14
  }
15
15
 
16
16
  apply (resolver) {
17
17
  const target = resolver.ensureHook(this.target)
18
- const mode = this.mode
18
+ const { options = {}, mode } = this
19
+ const { defaultMode, fileConditionRules, implicitMode } = options
19
20
  resolver.getHook(this.source).tapAsync('AddModePlugin', (request, resolveContext, callback) => {
20
21
  if (request.mode || request.env) {
21
22
  return callback()
@@ -31,14 +32,26 @@ module.exports = class AddModePlugin {
31
32
  extname = path.extname(resourcePath)
32
33
  }
33
34
  // 当前资源没有后缀名或者路径不符合fileConditionRules规则时,直接返回
34
- if (!extname || !matchCondition(resourcePath, this.fileConditionRules)) return callback()
35
+ if (!extname || !matchCondition(resourcePath, fileConditionRules)) return callback()
35
36
  const queryObj = parseQuery(request.query || '?')
36
- queryObj.mode = mode
37
- queryObj.infix = `${queryObj.infix || ''}.${mode}`
37
+ const queryInfix = queryObj.infix
38
+ if (!implicitMode) queryObj.mode = mode
39
+ queryObj.infix = `${queryInfix || ''}.${mode}`
38
40
  obj.query = stringifyQuery(queryObj)
39
41
  obj.path = addInfix(resourcePath, mode, extname)
40
42
  obj.relativePath = request.relativePath && addInfix(request.relativePath, mode, extname)
41
- resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + mode, resolveContext, callback)
43
+ resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + mode, resolveContext, (err, result) => {
44
+ if (defaultMode && !result) {
45
+ queryObj.infix = `${queryInfix || ''}.${defaultMode}`
46
+ obj.query = stringifyQuery(queryObj)
47
+ obj.path = addInfix(resourcePath, defaultMode, extname)
48
+ resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + defaultMode, resolveContext, (err, result) => {
49
+ callback(err, result)
50
+ })
51
+ return
52
+ }
53
+ callback(err, result)
54
+ })
42
55
  })
43
56
  }
44
57
  }
@@ -46,3 +46,5 @@ export const PickerContext = createContext(null)
46
46
  export const VarContext = createContext({})
47
47
 
48
48
  export const IntersectionObserverContext = createContext<IntersectionObserver | null>(null)
49
+
50
+ export const RouteContext = createContext<number | null>(null)
@@ -7,3 +7,4 @@ export const LabelContext = createContext(null);
7
7
  export const PickerContext = createContext(null);
8
8
  export const VarContext = createContext({});
9
9
  export const IntersectionObserverContext = createContext(null);
10
+ export const RouteContext = createContext(null);
@@ -1,4 +1,5 @@
1
1
  import { useRef } from 'react';
2
+ import { collectDataset } from '@mpxjs/utils';
2
3
  import { omit } from './utils';
3
4
  import eventConfigMap from './event.config';
4
5
  const getTouchEvent = (type, event, props, config) => {
@@ -13,7 +14,7 @@ const getTouchEvent = (type, event, props, config) => {
13
14
  currentTarget: {
14
15
  ...(event.currentTarget || {}),
15
16
  id: id || '',
16
- dataset: getDataSet(props),
17
+ dataset: collectDataset(props),
17
18
  offsetLeft: layoutRef?.current?.offsetLeft || 0,
18
19
  offsetTop: layoutRef?.current?.offsetTop || 0
19
20
  },
@@ -44,16 +45,6 @@ const getTouchEvent = (type, event, props, config) => {
44
45
  preventDefault: event.preventDefault
45
46
  };
46
47
  };
47
- export const getDataSet = (props) => {
48
- const result = {};
49
- for (const key in props) {
50
- if (key.indexOf('data-') === 0) {
51
- const newKey = key.substr(5);
52
- result[newKey] = props[key];
53
- }
54
- }
55
- return result;
56
- };
57
48
  export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, props = {}) => {
58
49
  return {
59
50
  ...oe,
@@ -62,7 +53,7 @@ export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, p
62
53
  target: {
63
54
  ...(oe.target || {}),
64
55
  id: props.id || '',
65
- dataset: getDataSet(props),
56
+ dataset: collectDataset(props),
66
57
  offsetLeft: layoutRef?.current?.offsetLeft || 0,
67
58
  offsetTop: layoutRef?.current?.offsetTop || 0
68
59
  },
@@ -37,10 +37,10 @@
37
37
  import { useEffect, useRef, useState, forwardRef, useContext } from 'react';
38
38
  import { View, StyleSheet, Animated, Easing } from 'react-native';
39
39
  import { warn } from '@mpxjs/utils';
40
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
40
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
41
41
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
42
42
  import useNodesRef from './useNodesRef';
43
- import { FormContext } from './context';
43
+ import { RouteContext, FormContext } from './context';
44
44
  const LOADING_IMAGE_URI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAB8hJREFUeJztnVtsFFUch6ltUYrEAi0Qo40xChGM+oAGI0EEKl4QfDVI9AkqqQZ4IVA1RSIvJlwUWwqJUokGKMVYwHJTq4mGuA+SxpJYggJSSgMpVFOtvbh+J84mk+3smXN2znZm2fNLvoQH5uQ/v4+Z2Z3dHUaNsrGxsbGxsbGxsbGxsbGxsTGSrq6uUqiHqw7iz6Vhz5WzofwYxJP4Mey5cjIUX+4hI0F52PPlXCi9WiKkOuz5ci5WiMFcvHhxOXRCHPpgLdyis4ZJITtqagtgPfRBHH6HV3XWyNpQ/DxHRDJbddYxLKTGEZHMLK2dy8ZQ/O4UQgQzVdcxJYTSZ6aQIfggrZ3MplD6CYmQmOo6BoXEJEK+TGsnsymUXicRIlimso4JIRS+TCJDsD3QzmZDKHwqDEmEdEC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En3KOzTtaG8p+FLkfEX7AOtL6bZVhIAbwJ/zgyLkFkP2KOZEwKsTEQKyRi0b39bjMCofhTHjI8n/1uMwI5rvERro2NjY2NjY2NjY2NjY2NjY1+/gNWA2LIOT/TRAAAAABJRU5ErkJggg==';
45
45
  const TypeColorMap = {
46
46
  default: ['#F8F8F8', '#DEDEDE', '35,35,35', '#F7F7F7'],
@@ -78,6 +78,8 @@ const styles = StyleSheet.create({
78
78
  }
79
79
  });
80
80
  const getOpenTypeEvent = (openType) => {
81
+ if (!openType)
82
+ return;
81
83
  if (!global.__mpx?.config?.rnConfig) {
82
84
  warn('Environment not supported');
83
85
  return;
@@ -94,6 +96,11 @@ const getOpenTypeEvent = (openType) => {
94
96
  }
95
97
  return event;
96
98
  };
99
+ const timer = (data, time = 3000) => new Promise((resolve) => {
100
+ setTimeout(() => {
101
+ resolve(data);
102
+ }, time);
103
+ });
97
104
  const Loading = ({ alone = false }) => {
98
105
  const image = useRef(new Animated.Value(0)).current;
99
106
  const rotate = image.interpolate({
@@ -123,6 +130,7 @@ const Loading = ({ alone = false }) => {
123
130
  const Button = forwardRef((buttonProps, ref) => {
124
131
  const { textProps, innerProps: props = {} } = splitProps(buttonProps);
125
132
  const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap, bindtouchstart, bindtouchend } = props;
133
+ const pageId = useContext(RouteContext);
126
134
  const formContext = useContext(FormContext);
127
135
  let submitFn;
128
136
  let resetFn;
@@ -187,16 +195,43 @@ const Button = forwardRef((buttonProps, ref) => {
187
195
  warn('Button does not support background image-related styles!');
188
196
  }
189
197
  const handleOpenTypeEvent = (evt) => {
190
- if (!openType)
191
- return;
192
198
  const handleEvent = getOpenTypeEvent(openType);
199
+ if (!handleEvent)
200
+ return;
193
201
  if (openType === 'share') {
194
- handleEvent && handleEvent({
202
+ const currentPage = getCurrentPage(pageId);
203
+ const event = {
195
204
  from: 'button',
196
- target: getCustomEvent('tap', evt, { layoutRef }, props).target
197
- });
205
+ target: getCustomEvent('tap', evt, { layoutRef }, props).target,
206
+ webViewUrl: currentPage?.__webViewUrl
207
+ };
208
+ if (currentPage) {
209
+ const defaultMessage = {
210
+ title: global.__mpx.config.rnConfig.projectName || 'AwesomeProject',
211
+ path: currentPage.route || ''
212
+ };
213
+ if (currentPage.onShareAppMessage) {
214
+ const { promise, ...message } = currentPage.onShareAppMessage(event) || {};
215
+ if (promise) {
216
+ Promise.race([Promise.resolve(promise), timer(message)])
217
+ .then((msg) => {
218
+ handleEvent(Object.assign({}, defaultMessage, msg));
219
+ });
220
+ }
221
+ else {
222
+ handleEvent(Object.assign({}, defaultMessage, message));
223
+ }
224
+ }
225
+ else {
226
+ handleEvent(defaultMessage);
227
+ }
228
+ }
229
+ else {
230
+ warn('Current page not found');
231
+ // Todo handleEvent(event)
232
+ }
198
233
  }
199
- if (openType === 'getUserInfo' && handleEvent && bindgetuserinfo) {
234
+ if (openType === 'getUserInfo' && bindgetuserinfo) {
200
235
  Promise.resolve(handleEvent)
201
236
  .then((userInfo) => {
202
237
  if (typeof userInfo === 'object') {
@@ -267,5 +302,5 @@ const Button = forwardRef((buttonProps, ref) => {
267
302
  })}
268
303
  </View>);
269
304
  });
270
- Button.displayName = 'mpx-button';
305
+ Button.displayName = 'MpxButton';
271
306
  export default Button;
@@ -0,0 +1,60 @@
1
+ import { warn } from '@mpxjs/utils';
2
+ export default class Bus {
3
+ _paused = false;
4
+ _messageListeners = {};
5
+ _queue = [];
6
+ _send;
7
+ _timeoutId = null;
8
+ constructor(send) {
9
+ this._send = send;
10
+ }
11
+ post(message) {
12
+ return new Promise((resolve) => {
13
+ if (message.type !== 'set' && message.id) {
14
+ this._messageListeners[message.id] = resolve;
15
+ }
16
+ if (!this._paused) {
17
+ this._queue.push(message);
18
+ this.startBatching();
19
+ }
20
+ else {
21
+ this._queue.push(message);
22
+ }
23
+ });
24
+ }
25
+ handle(message) {
26
+ if (!message.id)
27
+ return;
28
+ const handler = this._messageListeners[message.id];
29
+ delete this._messageListeners[message.id];
30
+ if (handler) {
31
+ handler(message);
32
+ }
33
+ else {
34
+ warn(`Received unexpected message: ${message}`);
35
+ }
36
+ }
37
+ pause() {
38
+ this._paused = true;
39
+ }
40
+ resume() {
41
+ this._paused = false;
42
+ this._send(this._queue);
43
+ this._queue = [];
44
+ }
45
+ startBatching() {
46
+ if (this._timeoutId)
47
+ return;
48
+ this._timeoutId = setTimeout(() => {
49
+ this._send(this._queue);
50
+ this._queue = [];
51
+ this._timeoutId = null;
52
+ }, 16);
53
+ }
54
+ clearBatchingTimeout() {
55
+ if (this._timeoutId) {
56
+ clearTimeout(this._timeoutId);
57
+ this._timeoutId = null;
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,15 @@
1
+ import { registerWebviewMethods } from './utils';
2
+ const METHODS = ['addColorStop'];
3
+ export default class CanvasGradient {
4
+ canvas;
5
+ constructor(canvas, noOnConstruction = false) {
6
+ this.canvas = canvas;
7
+ registerWebviewMethods(this, METHODS);
8
+ if (this.onConstruction && !noOnConstruction) {
9
+ this.onConstruction();
10
+ }
11
+ }
12
+ postMessage(message) {
13
+ return this.canvas.postMessage(message);
14
+ }
15
+ }
@@ -0,0 +1,84 @@
1
+ import { registerWebviewProperties, registerWebviewMethods, registerWebviewTarget } from './utils';
2
+ const PROPERTIES = {
3
+ direction: 'inherit',
4
+ fillStyle: '#000',
5
+ filter: 'none',
6
+ font: '10px sans-serif',
7
+ fontKerning: 'auto',
8
+ fontStretch: 'auto',
9
+ fontVariantCaps: 'normal',
10
+ globalAlpha: 1.0,
11
+ globalCompositeOperation: 'source-over',
12
+ imageSmoothingEnabled: 'true',
13
+ imageSmoothingQuality: 'low',
14
+ letterSpacing: '0px',
15
+ lineCap: 'butt',
16
+ lineDashOffset: 0.0,
17
+ lineJoin: 'miter',
18
+ lineWidth: 1.0,
19
+ miterLimit: 10.0,
20
+ shadowBlur: 0,
21
+ shadowColor: 'rgba(0,0,0,0)',
22
+ shadowOffsetX: 0,
23
+ shadowOffsetY: 0,
24
+ strokeStyle: '#000',
25
+ textAlign: 'start',
26
+ textBaseline: 'alphabetic',
27
+ textRendering: 'auto',
28
+ wordSpacing: '0px'
29
+ };
30
+ const METHODS = [
31
+ 'arc',
32
+ 'arcTo',
33
+ 'beginPath',
34
+ 'bezierCurveTo',
35
+ 'clearRect',
36
+ 'clip',
37
+ 'closePath',
38
+ 'createConicGradient',
39
+ 'createImageData',
40
+ 'createLinearGradient',
41
+ 'createPattern',
42
+ 'createRadialGradient',
43
+ 'drawFocusIfNeeded',
44
+ 'drawImage',
45
+ 'ellipse',
46
+ 'fill',
47
+ 'fillRect',
48
+ 'fillText',
49
+ 'getImageData',
50
+ 'getLineDash',
51
+ 'getTransform',
52
+ 'lineTo',
53
+ 'measureText',
54
+ 'moveTo',
55
+ 'putImageData',
56
+ 'quadraticCurveTo',
57
+ 'rect',
58
+ 'reset',
59
+ 'resetTransform',
60
+ 'restore',
61
+ 'rotate',
62
+ 'roundRect',
63
+ 'save',
64
+ 'scale',
65
+ 'setLineDash',
66
+ 'setTransform',
67
+ 'stroke',
68
+ 'strokeRect',
69
+ 'strokeText',
70
+ 'transform',
71
+ 'translate'
72
+ ];
73
+ export default class CanvasRenderingContext2D {
74
+ canvas;
75
+ constructor(canvas) {
76
+ this.canvas = canvas;
77
+ registerWebviewTarget(this, 'context2D');
78
+ registerWebviewProperties(this, PROPERTIES);
79
+ registerWebviewMethods(this, METHODS);
80
+ }
81
+ postMessage(message) {
82
+ return this.canvas.postMessage(message);
83
+ }
84
+ }
@@ -0,0 +1,87 @@
1
+ import { WEBVIEW_TARGET, registerWebviewProperties } from './utils';
2
+ const PROPERTIES = {
3
+ crossOrigin: undefined,
4
+ height: undefined,
5
+ src: undefined,
6
+ width: undefined
7
+ };
8
+ export class Image {
9
+ [WEBVIEW_TARGET];
10
+ canvas;
11
+ width;
12
+ height;
13
+ _loadListener;
14
+ _errorListener;
15
+ _onload;
16
+ _onerror;
17
+ constructor(canvas, width, height, noOnConstruction = false) {
18
+ this.canvas = canvas;
19
+ registerWebviewProperties(this, PROPERTIES);
20
+ if (width) {
21
+ this.width = width;
22
+ }
23
+ if (height) {
24
+ this.height = height;
25
+ }
26
+ if (this.onConstruction && !noOnConstruction) {
27
+ this.onConstruction();
28
+ this.postMessage({
29
+ type: 'listen',
30
+ payload: {
31
+ types: ['error', 'load'],
32
+ target: this[WEBVIEW_TARGET]
33
+ }
34
+ });
35
+ }
36
+ }
37
+ postMessage(message) {
38
+ return this.canvas.postMessage(message);
39
+ }
40
+ addEventListener(type, callbackFn) {
41
+ return this.canvas.addMessageListener((message) => {
42
+ const target = message?.payload?.target || {};
43
+ if (message &&
44
+ message.type === 'event' &&
45
+ target[WEBVIEW_TARGET] === this[WEBVIEW_TARGET] &&
46
+ message.payload.type === type) {
47
+ for (const key in target) {
48
+ const value = target[key];
49
+ if (key in this && this[key] !== value) {
50
+ this[key] = value;
51
+ }
52
+ }
53
+ callbackFn({
54
+ ...message.payload,
55
+ target: this
56
+ });
57
+ }
58
+ });
59
+ }
60
+ set onload(callback) {
61
+ this._onload = callback;
62
+ if (this._loadListener) {
63
+ this.canvas.removeMessageListener(this._loadListener);
64
+ }
65
+ if (callback) {
66
+ this._loadListener = this.addEventListener('load', callback);
67
+ }
68
+ }
69
+ get onload() {
70
+ return this._onload;
71
+ }
72
+ set onerror(callback) {
73
+ this._onerror = callback;
74
+ if (this._errorListener) {
75
+ this.canvas.removeMessageListener(this._errorListener);
76
+ }
77
+ if (callback) {
78
+ this._errorListener = this.addEventListener('error', callback);
79
+ }
80
+ }
81
+ get onerror() {
82
+ return this._onerror;
83
+ }
84
+ }
85
+ export function createImage(canvas, width, height) {
86
+ return new Image(canvas, width, height);
87
+ }
@@ -0,0 +1,15 @@
1
+ export default class ImageData {
2
+ canvas;
3
+ constructor(canvas, dataArray, width, height, noOnConstruction) {
4
+ this.canvas = canvas;
5
+ if (this.onConstruction && !noOnConstruction) {
6
+ this.onConstruction(dataArray, width, height);
7
+ }
8
+ }
9
+ postMessage = (message) => {
10
+ return this.canvas.postMessage(message);
11
+ };
12
+ }
13
+ export function createImageData(canvas, dataArray, width, height) {
14
+ return new ImageData(canvas, dataArray, width, height);
15
+ }
@@ -0,0 +1,28 @@
1
+ import { Image } from './Image';
2
+ import CanvasGradient from './CanvasGradient';
3
+ import ImageData from './ImageData';
4
+ export var ConstructorType;
5
+ (function (ConstructorType) {
6
+ ConstructorType["Image"] = "Image";
7
+ ConstructorType["CanvasGradient"] = "CanvasGradient";
8
+ ConstructorType["ImageData"] = "ImageData";
9
+ })(ConstructorType || (ConstructorType = {}));
10
+ const constructors = [
11
+ { type: ConstructorType.Image, instance: Image },
12
+ { type: ConstructorType.CanvasGradient, instance: CanvasGradient },
13
+ { type: ConstructorType.ImageData, instance: ImageData }
14
+ ];
15
+ export function useConstructorsRegistry() {
16
+ const register = (registerWebviewConstructor) => {
17
+ constructors.forEach(({ type, instance }) => {
18
+ registerWebviewConstructor(instance, type);
19
+ });
20
+ };
21
+ const getConstructor = (type) => {
22
+ return constructors.find(c => c.type === type)?.instance;
23
+ };
24
+ return {
25
+ register,
26
+ getConstructor
27
+ };
28
+ }