@mpxjs/core 2.9.67 → 2.9.70-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/@types/global.d.ts +1 -1
  2. package/package.json +18 -9
  3. package/src/convertor/convertor.js +13 -32
  4. package/src/convertor/getConvertMode.js +1 -0
  5. package/src/convertor/wxToAli.js +3 -3
  6. package/src/convertor/wxToReact.js +1 -1
  7. package/src/convertor/wxToSwan.js +3 -3
  8. package/src/convertor/wxToTenon.js +86 -0
  9. package/src/convertor/wxToWeb.js +3 -3
  10. package/src/core/proxy.js +18 -11
  11. package/src/dynamic/dynamicRenderMixin.js +2 -2
  12. package/src/external/vue.tenon.js +13 -0
  13. package/src/index.js +1 -1
  14. package/src/observer/reactive.js +1 -1
  15. package/src/observer/ref.js +3 -2
  16. package/src/observer/scheduler.js +4 -0
  17. package/src/observer/watch.js +5 -4
  18. package/src/platform/builtInMixins/index.js +5 -0
  19. package/src/platform/builtInMixins/pageStatusMixin.tenon.js +40 -0
  20. package/src/platform/builtInMixins/proxyEventMixin.tenon.js +46 -0
  21. package/src/platform/builtInMixins/styleHelperMixin.ios.js +28 -25
  22. package/src/platform/createApp.ios.js +44 -16
  23. package/src/platform/createApp.js +11 -4
  24. package/src/platform/export/apiInject.tenon.js +1 -0
  25. package/src/platform/export/index.tenon.js +78 -0
  26. package/src/platform/patch/builtInKeysMap.js +1 -1
  27. package/src/platform/patch/{ali/getDefaultOptions.js → getDefaultOptions.ali.js} +3 -3
  28. package/src/platform/patch/{react/getDefaultOptions.ios.js → getDefaultOptions.ios.js} +266 -190
  29. package/src/platform/patch/{wx/getDefaultOptions.js → getDefaultOptions.js} +11 -5
  30. package/src/platform/patch/getDefaultOptions.tenon.js +99 -0
  31. package/src/platform/patch/{web/getDefaultOptions.js → getDefaultOptions.web.js} +5 -5
  32. package/src/platform/patch/index.js +4 -21
  33. package/src/platform/patch/{ali/lifecycle.js → lifecycle/index.ali.js} +2 -0
  34. package/src/platform/patch/lifecycle/index.js +1 -0
  35. package/src/platform/patch/{swan/lifecycle.js → lifecycle/index.swan.js} +2 -0
  36. package/src/platform/patch/lifecycle/index.tenon.js +52 -0
  37. package/src/platform/patch/{web/lifecycle.js → lifecycle/index.web.js} +4 -0
  38. package/src/platform/patch/{wx/lifecycle.js → lifecycle/index.wx.js} +2 -0
  39. package/LICENSE +0 -433
  40. package/src/platform/patch/react/getDefaultOptions.js +0 -1
  41. package/src/platform/patch/swan/getDefaultOptions.js +0 -34
@@ -1,19 +1,22 @@
1
- import { isObject, isArray, dash2hump, isFunction, cached, getFocusedNavigation } from '@mpxjs/utils'
1
+ import { isObject, isArray, dash2hump, cached, isEmptyObject } from '@mpxjs/utils'
2
2
  import { Dimensions, StyleSheet } from 'react-native'
3
3
 
4
+ let { width, height } = Dimensions.get('screen')
5
+
6
+ Dimensions.addEventListener('change', ({ screen }) => {
7
+ width = screen.width
8
+ height = screen.height
9
+ })
10
+
4
11
  function rpx (value) {
5
- const { width } = Dimensions.get('screen')
6
12
  // rn 单位 dp = 1(css)px = 1 物理像素 * pixelRatio(像素比)
7
13
  // px = rpx * (750 / 屏幕宽度)
8
14
  return value * width / 750
9
15
  }
10
16
  function vw (value) {
11
- const { width } = Dimensions.get('screen')
12
17
  return value * width / 100
13
18
  }
14
19
  function vh (value) {
15
- const navigation = getFocusedNavigation()
16
- const height = navigation?.layout?.height || Dimensions.get('screen').height
17
20
  return value * height / 100
18
21
  }
19
22
 
@@ -23,15 +26,18 @@ const unit = {
23
26
  vh
24
27
  }
25
28
 
29
+ const empty = {}
30
+
26
31
  function formatValue (value) {
27
- let matched
28
- if ((matched = numberRegExp.exec(value))) {
29
- value = +matched[1]
30
- } else if ((matched = unitRegExp.exec(value))) {
31
- value = unit[matched[2]](+matched[1])
32
- } else if (hairlineRegExp.test(value)) {
33
- value = StyleSheet.hairlineWidth
32
+ const matched = unitRegExp.exec(value)
33
+ if (matched) {
34
+ if (!matched[2] || matched[2] === 'px') {
35
+ return +matched[1]
36
+ } else {
37
+ return unit[matched[2]](+matched[1])
38
+ }
34
39
  }
40
+ if (hairlineRegExp.test(value)) return StyleSheet.hairlineWidth
35
41
  return value
36
42
  }
37
43
 
@@ -106,8 +112,7 @@ function stringifyDynamicClass (value) {
106
112
 
107
113
  const listDelimiter = /;(?![^(]*[)])/g
108
114
  const propertyDelimiter = /:(.+)/
109
- const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh)\s*$/
110
- const numberRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
115
+ const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh|px)?\s*$/
111
116
  const hairlineRegExp = /^\s*hairlineWidth\s*$/
112
117
  const varRegExp = /^--/
113
118
 
@@ -164,14 +169,8 @@ export default function styleHelperMixin () {
164
169
  },
165
170
  __getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, hide) {
166
171
  const result = {}
167
- const classMap = {}
168
- // todo 全局样式在每个页面和组件中生效,以支持全局原子类,后续支持样式模块复用后可考虑移除
169
- if (isFunction(global.__getAppClassMap)) {
170
- Object.assign(classMap, global.__getAppClassMap())
171
- }
172
- if (isFunction(this.__getClassMap)) {
173
- Object.assign(classMap, this.__getClassMap())
174
- }
172
+ const classMap = this.__getClassMap?.() || {}
173
+ const appClassMap = global.__getAppClassMap?.() || {}
175
174
 
176
175
  if (staticClass || dynamicClass) {
177
176
  // todo 当前为了复用小程序unocss产物,暂时进行mpEscape,等后续正式支持unocss后可不进行mpEscape
@@ -179,9 +178,12 @@ export default function styleHelperMixin () {
179
178
  classString.split(/\s+/).forEach((className) => {
180
179
  if (classMap[className]) {
181
180
  Object.assign(result, classMap[className])
182
- } else if (this.props[className] && isObject(this.props[className])) {
181
+ } else if (appClassMap[className]) {
182
+ // todo 全局样式在每个页面和组件中生效,以支持全局原子类,后续支持样式模块复用后可考虑移除
183
+ Object.assign(result, appClassMap[className])
184
+ } else if (this.__props[className] && isObject(this.__props[className])) {
183
185
  // externalClasses必定以对象形式传递下来
184
- Object.assign(result, this.props[className])
186
+ Object.assign(result, this.__props[className])
185
187
  }
186
188
  })
187
189
  }
@@ -196,7 +198,8 @@ export default function styleHelperMixin () {
196
198
  display: 'none'
197
199
  })
198
200
  }
199
- return result
201
+
202
+ return isEmptyObject(result) ? empty : result
200
203
  }
201
204
  }
202
205
  }
@@ -1,14 +1,14 @@
1
1
  import transferOptions from '../core/transferOptions'
2
2
  import builtInKeysMap from './patch/builtInKeysMap'
3
- import { makeMap, spreadProp, parseUrlQuery } from '@mpxjs/utils'
3
+ import { makeMap, spreadProp, parseUrlQuery, getFocusedNavigation, hasOwn, extend } from '@mpxjs/utils'
4
4
  import { mergeLifecycle } from '../convertor/mergeLifecycle'
5
- import * as wxLifecycle from '../platform/patch/wx/lifecycle'
5
+ import { LIFECYCLE } from '../platform/patch/lifecycle/index'
6
6
  import Mpx from '../index'
7
7
  import { createElement, memo, useRef, useEffect } from 'react'
8
8
  import * as ReactNative from 'react-native'
9
9
  import { ref } from '../observer/ref'
10
10
 
11
- const appHooksMap = makeMap(mergeLifecycle(wxLifecycle.LIFECYCLE).app)
11
+ const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
12
12
 
13
13
  function getOrientation (window = ReactNative.Dimensions.get('window')) {
14
14
  return window.width > window.height ? 'landscape' : 'portrait'
@@ -30,11 +30,7 @@ function filterOptions (options, appData) {
30
30
  }
31
31
 
32
32
  function createAppInstance (appData) {
33
- const instance = {
34
- ...Mpx.prototype,
35
- ...appData
36
- }
37
- return instance
33
+ return extend({}, Mpx.prototype, appData)
38
34
  }
39
35
 
40
36
  export default function createApp (option, config = {}) {
@@ -143,15 +139,33 @@ export default function createApp (option, config = {}) {
143
139
 
144
140
  const changeSubscription = ReactNative.AppState.addEventListener('change', (currentState) => {
145
141
  if (currentState === 'active') {
142
+ let options = global.__mpxEnterOptions
143
+ const navigation = getFocusedNavigation()
144
+ if (navigation) {
145
+ const state = navigation.getState()
146
+ const current = state.routes[state.index]
147
+ options = {
148
+ path: current.name,
149
+ query: current.params,
150
+ scene: 0,
151
+ shareTicket: '',
152
+ referrerInfo: {}
153
+ }
154
+ }
146
155
  global.__mpxAppCbs.show.forEach((cb) => {
147
- cb(global.__mpxEnterOptions)
156
+ cb(options)
148
157
  })
149
- global.__mpxAppFocusedState.value = 'show'
158
+ if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
159
+ global.__mpxPageStatusMap[navigation.pageId] = 'show'
160
+ }
150
161
  } else if (currentState === 'inactive') {
151
162
  global.__mpxAppCbs.hide.forEach((cb) => {
152
163
  cb()
153
164
  })
154
- global.__mpxAppFocusedState.value = 'hide'
165
+ const navigation = getFocusedNavigation()
166
+ if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
167
+ global.__mpxPageStatusMap[navigation.pageId] = 'hide'
168
+ }
155
169
  }
156
170
  })
157
171
 
@@ -161,7 +175,10 @@ export default function createApp (option, config = {}) {
161
175
  const orientation = getOrientation(window)
162
176
  if (orientation === lastOrientation) return
163
177
  lastOrientation = orientation
164
- global.__mpxAppFocusedState.value = `resize${count++}`
178
+ const navigation = getFocusedNavigation()
179
+ if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
180
+ global.__mpxPageStatusMap[navigation.pageId] = `resize${count++}`
181
+ }
165
182
  })
166
183
  return () => {
167
184
  changeSubscription && changeSubscription.remove()
@@ -180,9 +197,13 @@ export default function createApp (option, config = {}) {
180
197
  createElement(Stack.Navigator,
181
198
  {
182
199
  initialRouteName,
183
- headerBackButtonDisplayMode: 'minimal',
184
- headerMode: 'float',
185
- gestureEnabled: true
200
+ screenOptions: {
201
+ gestureEnabled: true,
202
+ // 7.x替换headerBackTitleVisible
203
+ // headerBackButtonDisplayMode: 'minimal',
204
+ headerBackTitleVisible: false,
205
+ headerMode: 'float'
206
+ }
186
207
  },
187
208
  ...getPageScreens(initialRouteName, initialParams)
188
209
  )
@@ -191,7 +212,7 @@ export default function createApp (option, config = {}) {
191
212
  })
192
213
 
193
214
  global.getCurrentPages = function () {
194
- const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
215
+ const navigation = getFocusedNavigation()
195
216
  if (navigation) {
196
217
  return navigation.getState().routes.map((route) => {
197
218
  return global.__mpxPagesMap[route.key] && global.__mpxPagesMap[route.key][0]
@@ -199,4 +220,11 @@ export default function createApp (option, config = {}) {
199
220
  }
200
221
  return []
201
222
  }
223
+
224
+ global.setCurrentPageStatus = function (status) {
225
+ const navigation = getFocusedNavigation()
226
+ if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
227
+ global.__mpxPageStatusMap[navigation.pageId] = status
228
+ }
229
+ }
202
230
  }
@@ -3,11 +3,11 @@ import mergeOptions from '../core/mergeOptions'
3
3
  import builtInKeysMap from './patch/builtInKeysMap'
4
4
  import { makeMap, spreadProp, isBrowser } from '@mpxjs/utils'
5
5
  import { mergeLifecycle } from '../convertor/mergeLifecycle'
6
- import * as webLifecycle from '../platform/patch/web/lifecycle'
6
+ import { LIFECYCLE } from '../platform/patch/lifecycle/index'
7
7
  import Mpx from '../index'
8
8
  import { initAppProvides } from './export/apiInject'
9
9
 
10
- const webAppHooksMap = makeMap(mergeLifecycle(webLifecycle.LIFECYCLE).app)
10
+ const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
11
11
 
12
12
  function filterOptions (options, appData) {
13
13
  const newOptions = {}
@@ -15,7 +15,7 @@ function filterOptions (options, appData) {
15
15
  if (builtInKeysMap[key]) {
16
16
  return
17
17
  }
18
- if (__mpx_mode__ === 'web' && !webAppHooksMap[key] && key !== 'provide') {
18
+ if (__mpx_mode__ === 'web' && !appHooksMap[key] && key !== 'provide') {
19
19
  appData[key] = options[key]
20
20
  } else {
21
21
  newOptions[key] = options[key]
@@ -66,6 +66,13 @@ export default function createApp (option, config = {}) {
66
66
  }
67
67
  }
68
68
  })
69
+ } else if (__mpx_mode__ === 'tenon') {
70
+ // todo add tenon mixins
71
+ builtInMixins.push({
72
+ onLaunch () {
73
+ // console.log('tenon mixins')
74
+ }
75
+ })
69
76
  } else {
70
77
  builtInMixins.push({
71
78
  onLaunch () {
@@ -78,7 +85,7 @@ export default function createApp (option, config = {}) {
78
85
  rawOptions.mixins = builtInMixins
79
86
  const defaultOptions = filterOptions(spreadProp(mergeOptions(rawOptions, 'app', false), 'methods'), appData)
80
87
 
81
- if (__mpx_mode__ === 'web') {
88
+ if (__mpx_mode__ === 'web' || __mpx_mode__ === 'tenon') {
82
89
  global.__mpxOptionsMap = global.__mpxOptionsMap || {}
83
90
  global.__mpxOptionsMap[currentInject.moduleId] = defaultOptions
84
91
  global.getApp = function () {
@@ -0,0 +1 @@
1
+ export { provide, inject } from '@hummer/tenon-vue'
@@ -0,0 +1,78 @@
1
+ import {
2
+ effectScope as vueEffectScope,
3
+ getCurrentScope as getCurrentVueScope,
4
+ onScopeDispose
5
+ } from '@hummer/tenon-vue'
6
+
7
+ import {
8
+ hasOwn,
9
+ isValidArrayIndex
10
+ } from '@mpxjs/utils'
11
+
12
+ export {
13
+ // watch
14
+ watchEffect,
15
+ watchSyncEffect,
16
+ watchPostEffect,
17
+ watch,
18
+ // reactive
19
+ reactive,
20
+ isReactive,
21
+ shallowReactive,
22
+ markRaw,
23
+ // ref
24
+ ref,
25
+ unref,
26
+ toRef,
27
+ toRefs,
28
+ isRef,
29
+ customRef,
30
+ shallowRef,
31
+ triggerRef,
32
+ // computed
33
+ computed,
34
+ // instance
35
+ getCurrentInstance,
36
+ provide,
37
+ inject
38
+ } from '@hummer/tenon-vue'
39
+
40
+ export function set (target, key, val) {
41
+ if (Array.isArray(target) && isValidArrayIndex(key)) {
42
+ target.length = Math.max(target.length, key)
43
+ target.splice(key, 1, val)
44
+ return val
45
+ }
46
+ target[key] = val
47
+ return val
48
+ }
49
+
50
+ export function del (target, key) {
51
+ if (Array.isArray(target) && isValidArrayIndex(key)) {
52
+ target.splice(key, 1)
53
+ return
54
+ }
55
+ if (!hasOwn(target, key)) {
56
+ return
57
+ }
58
+ delete target[key]
59
+ }
60
+
61
+ const noop = () => {
62
+ }
63
+
64
+ const fixEffectScope = (scope) => {
65
+ scope.pause = noop
66
+ scope.resume = noop
67
+ return scope
68
+ }
69
+
70
+ const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
71
+ const getCurrentScope = () => fixEffectScope(getCurrentVueScope())
72
+
73
+ export {
74
+ // effectScope
75
+ effectScope,
76
+ getCurrentScope,
77
+ onScopeDispose
78
+ }
@@ -3,7 +3,7 @@ import { makeMap } from '@mpxjs/utils'
3
3
 
4
4
  let builtInKeys
5
5
 
6
- if (__mpx_mode__ === 'web') {
6
+ if (__mpx_mode__ === 'web' || __mpx_mode__ === 'tenon') {
7
7
  builtInKeys = [
8
8
  'proto',
9
9
  'mixins',
@@ -1,6 +1,6 @@
1
- import MpxProxy from '../../../core/proxy'
2
- import builtInKeysMap from '../builtInKeysMap'
3
- import mergeOptions from '../../../core/mergeOptions'
1
+ import MpxProxy from '../../core/proxy'
2
+ import builtInKeysMap from './builtInKeysMap'
3
+ import mergeOptions from '../../core/mergeOptions'
4
4
  import { error, diffAndCloneA, hasOwn, noop, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
5
5
 
6
6
  function transformApiForProxy (context, currentInject) {