@mpxjs/core 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 (40) hide show
  1. package/@types/global.d.ts +1 -1
  2. package/package.json +6 -5
  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/wxToSwan.js +3 -3
  7. package/src/convertor/wxToTenon.js +86 -0
  8. package/src/convertor/wxToWeb.js +3 -3
  9. package/src/core/proxy.js +18 -11
  10. package/src/dynamic/dynamicRenderMixin.js +2 -2
  11. package/src/external/vue.tenon.js +13 -0
  12. package/src/index.js +1 -1
  13. package/src/observer/reactive.js +1 -1
  14. package/src/observer/ref.js +3 -2
  15. package/src/observer/scheduler.js +4 -0
  16. package/src/observer/watch.js +5 -4
  17. package/src/platform/builtInMixins/index.js +5 -0
  18. package/src/platform/builtInMixins/pageStatusMixin.tenon.js +40 -0
  19. package/src/platform/builtInMixins/proxyEventMixin.tenon.js +46 -0
  20. package/src/platform/builtInMixins/styleHelperMixin.ios.js +7 -4
  21. package/src/platform/createApp.ios.js +22 -11
  22. package/src/platform/createApp.js +11 -4
  23. package/src/platform/export/apiInject.tenon.js +1 -0
  24. package/src/platform/export/index.tenon.js +78 -0
  25. package/src/platform/patch/builtInKeysMap.js +1 -1
  26. package/src/platform/patch/{ali/getDefaultOptions.js → getDefaultOptions.ali.js} +3 -3
  27. package/src/platform/patch/{react/getDefaultOptions.ios.js → getDefaultOptions.ios.js} +258 -183
  28. package/src/platform/patch/{wx/getDefaultOptions.js → getDefaultOptions.js} +11 -5
  29. package/src/platform/patch/getDefaultOptions.tenon.js +99 -0
  30. package/src/platform/patch/{web/getDefaultOptions.js → getDefaultOptions.web.js} +5 -5
  31. package/src/platform/patch/index.js +4 -21
  32. package/src/platform/patch/{ali/lifecycle.js → lifecycle/index.ali.js} +2 -0
  33. package/src/platform/patch/lifecycle/index.js +1 -0
  34. package/src/platform/patch/{swan/lifecycle.js → lifecycle/index.swan.js} +2 -0
  35. package/src/platform/patch/lifecycle/index.tenon.js +52 -0
  36. package/src/platform/patch/{web/lifecycle.js → lifecycle/index.web.js} +4 -0
  37. package/src/platform/patch/{wx/lifecycle.js → lifecycle/index.wx.js} +2 -0
  38. package/LICENSE +0 -433
  39. package/src/platform/patch/react/getDefaultOptions.js +0 -1
  40. package/src/platform/patch/swan/getDefaultOptions.js +0 -34
@@ -1,14 +1,14 @@
1
1
  import transferOptions from '../core/transferOptions'
2
2
  import builtInKeysMap from './patch/builtInKeysMap'
3
- import { makeMap, spreadProp, parseUrlQuery, getFocusedNavigation } 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 = {}) {
@@ -159,12 +155,17 @@ export default function createApp (option, config = {}) {
159
155
  global.__mpxAppCbs.show.forEach((cb) => {
160
156
  cb(options)
161
157
  })
162
- global.__mpxAppFocusedState.value = 'show'
158
+ if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
159
+ global.__mpxPageStatusMap[navigation.pageId] = 'show'
160
+ }
163
161
  } else if (currentState === 'inactive') {
164
162
  global.__mpxAppCbs.hide.forEach((cb) => {
165
163
  cb()
166
164
  })
167
- global.__mpxAppFocusedState.value = 'hide'
165
+ const navigation = getFocusedNavigation()
166
+ if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
167
+ global.__mpxPageStatusMap[navigation.pageId] = 'hide'
168
+ }
168
169
  }
169
170
  })
170
171
 
@@ -174,7 +175,10 @@ export default function createApp (option, config = {}) {
174
175
  const orientation = getOrientation(window)
175
176
  if (orientation === lastOrientation) return
176
177
  lastOrientation = orientation
177
- 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
+ }
178
182
  })
179
183
  return () => {
180
184
  changeSubscription && changeSubscription.remove()
@@ -216,4 +220,11 @@ export default function createApp (option, config = {}) {
216
220
  }
217
221
  return []
218
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
+ }
219
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) {