@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27 → 4.0.0-alpha.10

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 (239) hide show
  1. package/dist/apis/apis.ts +6 -2
  2. package/dist/apis/base/crypto.ts +4 -0
  3. package/dist/apis/base/debug.ts +5 -0
  4. package/dist/apis/base/index.ts +9 -1
  5. package/dist/apis/base/performance.ts +8 -0
  6. package/dist/apis/base/system.ts +74 -21
  7. package/dist/apis/base/update.ts +5 -0
  8. package/dist/apis/base/weapp/app-event.ts +75 -0
  9. package/dist/apis/base/weapp/life-cycle.ts +21 -0
  10. package/dist/apis/canvas/index.ts +27 -0
  11. package/dist/apis/data-analysis/index.ts +6 -0
  12. package/dist/apis/device/accelerometer.ts +2 -1
  13. package/dist/apis/device/accessibility.ts +4 -0
  14. package/dist/apis/device/battery.ts +2 -2
  15. package/dist/apis/device/bluetooth-ble.ts +19 -0
  16. package/dist/apis/device/bluetooth-peripheral.ts +6 -0
  17. package/dist/apis/device/bluetooth.ts +16 -0
  18. package/dist/apis/device/calendar.ts +5 -0
  19. package/dist/apis/device/clipboard.ts +17 -9
  20. package/dist/apis/device/compass.ts +21 -0
  21. package/dist/apis/device/contact.ts +5 -0
  22. package/dist/apis/device/crypto.ts +4 -0
  23. package/dist/apis/device/gyroscope.ts +7 -0
  24. package/dist/apis/device/iBeacon.ts +10 -0
  25. package/dist/apis/device/index.ts +15 -0
  26. package/dist/apis/device/keyboard.ts +2 -1
  27. package/dist/apis/device/memory.ts +10 -3
  28. package/dist/apis/device/motion.ts +6 -0
  29. package/dist/apis/device/network.ts +26 -9
  30. package/dist/apis/device/nfc.ts +10 -0
  31. package/dist/apis/device/phone.ts +2 -1
  32. package/dist/apis/device/scan.ts +4 -0
  33. package/dist/apis/device/screen.ts +2 -1
  34. package/dist/apis/device/sms.ts +4 -0
  35. package/dist/apis/device/vibrate.ts +19 -11
  36. package/dist/apis/device/wifi.ts +15 -0
  37. package/dist/apis/ext/index.ts +5 -0
  38. package/dist/apis/files/index.ts +2 -1
  39. package/dist/apis/files/manager.ts +2 -1
  40. package/dist/apis/framework/index.ts +3 -8
  41. package/dist/apis/index.ts +27 -17
  42. package/dist/apis/location/index.ts +61 -68
  43. package/dist/apis/media/EditorContext.ts +32 -0
  44. package/dist/apis/media/audio/index.ts +18 -0
  45. package/dist/apis/media/background-audio/index.ts +16 -0
  46. package/dist/apis/media/camera.ts +16 -0
  47. package/dist/apis/media/common.ts +2 -1
  48. package/dist/apis/media/{image.ts → image/index.ts} +4 -3
  49. package/dist/apis/media/index.ts +10 -0
  50. package/dist/apis/media/live.ts +5 -0
  51. package/dist/apis/media/map.ts +4 -0
  52. package/dist/apis/media/media-recorder.ts +4 -0
  53. package/dist/apis/media/recorder.ts +6 -0
  54. package/dist/apis/media/video/VideoContext.ts +68 -0
  55. package/dist/apis/media/{video.ts → video/index.ts} +13 -2
  56. package/dist/apis/media/video-decoder.ts +4 -0
  57. package/dist/apis/media/video-processing.ts +4 -0
  58. package/dist/apis/media/voip.ts +19 -0
  59. package/dist/apis/network/index.ts +3 -0
  60. package/dist/apis/network/mdns.ts +13 -0
  61. package/dist/apis/network/request.ts +7 -6
  62. package/dist/apis/network/tcp.ts +4 -0
  63. package/dist/apis/network/udp.ts +4 -0
  64. package/dist/apis/network/webSocket.ts +2 -6
  65. package/dist/apis/open-api/account.ts +4 -0
  66. package/dist/apis/open-api/address.ts +4 -0
  67. package/dist/apis/open-api/authorize.ts +5 -0
  68. package/dist/apis/open-api/card.ts +5 -0
  69. package/dist/apis/open-api/channels-live.ts +11 -0
  70. package/dist/apis/open-api/customer-service.ts +4 -0
  71. package/dist/apis/open-api/device-voip.ts +5 -0
  72. package/dist/apis/open-api/facial.ts +7 -0
  73. package/dist/apis/open-api/favorites.ts +5 -0
  74. package/dist/apis/open-api/group.ts +4 -0
  75. package/dist/apis/open-api/index.ts +20 -6
  76. package/dist/apis/open-api/invoice.ts +5 -0
  77. package/dist/apis/open-api/license-plate.ts +4 -0
  78. package/dist/apis/open-api/login.ts +6 -0
  79. package/dist/apis/open-api/my-miniprogram.ts +4 -0
  80. package/dist/apis/open-api/privacy.ts +7 -0
  81. package/dist/apis/open-api/red-package.ts +4 -0
  82. package/dist/apis/open-api/settings.ts +5 -0
  83. package/dist/apis/open-api/soter.ts +6 -0
  84. package/dist/apis/open-api/subscribe-message.ts +6 -0
  85. package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
  86. package/dist/apis/open-api/werun.ts +5 -0
  87. package/dist/apis/payment/index.ts +6 -0
  88. package/dist/apis/route/index.ts +19 -28
  89. package/dist/apis/share/index.ts +33 -0
  90. package/dist/apis/storage/background-fetch.ts +7 -0
  91. package/dist/apis/storage/cache-manager.ts +4 -0
  92. package/dist/apis/storage/index.ts +158 -88
  93. package/dist/apis/ui/{animation.ts → animation/animation.ts} +73 -31
  94. package/dist/apis/ui/animation/index.ts +7 -0
  95. package/dist/apis/ui/background.ts +4 -19
  96. package/dist/apis/ui/custom-component.ts +8 -0
  97. package/dist/apis/ui/fonts.ts +4 -0
  98. package/dist/apis/ui/index.ts +8 -10
  99. package/dist/apis/ui/interaction/index.ts +45 -59
  100. package/dist/apis/ui/menu.ts +4 -0
  101. package/dist/apis/ui/navigation-bar/index.ts +60 -21
  102. package/dist/apis/ui/pull-down-refresh.ts +10 -4
  103. package/dist/apis/{page → ui/scroll}/index.ts +32 -27
  104. package/dist/apis/ui/sticky.ts +4 -0
  105. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +6 -8
  106. package/dist/apis/ui/window.ts +20 -0
  107. package/dist/apis/utils/handler.ts +4 -4
  108. package/dist/apis/utils/index.ts +1 -1
  109. package/dist/apis/worker/index.ts +4 -0
  110. package/dist/apis/wxml/IntersectionObserver.ts +24 -25
  111. package/dist/apis/wxml/index.ts +7 -2
  112. package/dist/apis/wxml/nodesRef.ts +2 -2
  113. package/dist/apis/wxml/selectorQuery.ts +29 -17
  114. package/dist/components-harmony-ets/button.ets +106 -80
  115. package/dist/components-harmony-ets/canvas.ets +51 -0
  116. package/dist/components-harmony-ets/checkbox.ets +82 -148
  117. package/dist/components-harmony-ets/form.ets +45 -132
  118. package/dist/components-harmony-ets/icon.ets +66 -69
  119. package/dist/components-harmony-ets/image.ets +26 -61
  120. package/dist/components-harmony-ets/index.ets +92 -0
  121. package/dist/components-harmony-ets/innerHtml.ets +7 -70
  122. package/dist/components-harmony-ets/input.ets +60 -146
  123. package/dist/components-harmony-ets/label.ets +86 -92
  124. package/dist/components-harmony-ets/listView.ets +26 -0
  125. package/dist/components-harmony-ets/movableArea.ets +124 -0
  126. package/dist/components-harmony-ets/movableView.ets +93 -0
  127. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  128. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  129. package/dist/components-harmony-ets/picker.ets +172 -198
  130. package/dist/components-harmony-ets/progress.ets +52 -0
  131. package/dist/components-harmony-ets/pseudo.ets +80 -0
  132. package/dist/components-harmony-ets/radio.ets +85 -155
  133. package/dist/components-harmony-ets/richText.ets +15 -87
  134. package/dist/components-harmony-ets/scrollList.ets +94 -0
  135. package/dist/components-harmony-ets/scrollView.ets +81 -149
  136. package/dist/components-harmony-ets/slider.ets +47 -94
  137. package/dist/components-harmony-ets/stickySection.ets +42 -0
  138. package/dist/components-harmony-ets/style.ets +396 -0
  139. package/dist/components-harmony-ets/swiper.ets +51 -151
  140. package/dist/components-harmony-ets/switch.ets +35 -76
  141. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  142. package/dist/components-harmony-ets/text.ets +131 -76
  143. package/dist/components-harmony-ets/textArea.ets +64 -140
  144. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  145. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  146. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  147. package/dist/components-harmony-ets/utils/flexManager.ets +68 -85
  148. package/dist/components-harmony-ets/utils/helper.ets +18 -65
  149. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  150. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  151. package/dist/components-harmony-ets/utils/index.ts +55 -51
  152. package/dist/components-harmony-ets/utils/styles.ets +177 -65
  153. package/dist/components-harmony-ets/video.ets +70 -116
  154. package/dist/components-harmony-ets/view.ets +58 -64
  155. package/dist/components-harmony-ets/webView.ets +56 -0
  156. package/dist/index.d.ts +152 -0
  157. package/dist/index.js +230 -60
  158. package/dist/index.js.map +1 -1
  159. package/dist/runtime-ets/bom/document.ts +6 -4
  160. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  161. package/dist/runtime-ets/bom/window.ts +9 -2
  162. package/dist/runtime-ets/current.ts +3 -0
  163. package/dist/runtime-ets/dom/bind.ts +96 -0
  164. package/dist/runtime-ets/dom/class-list.ts +4 -6
  165. package/dist/runtime-ets/dom/comment.ts +1 -2
  166. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  167. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +30 -20
  168. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  169. package/dist/runtime-ets/dom/document.ts +36 -51
  170. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  171. package/dist/runtime-ets/dom/element/element.ts +439 -0
  172. package/dist/runtime-ets/dom/element/form.ts +403 -0
  173. package/dist/runtime-ets/dom/element/index.ts +120 -0
  174. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  175. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  176. package/dist/runtime-ets/dom/element/normal.ts +103 -0
  177. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  178. package/dist/runtime-ets/dom/element/scrollView.ts +15 -0
  179. package/dist/runtime-ets/dom/element/text.ts +10 -0
  180. package/dist/runtime-ets/dom/element/video.ts +50 -0
  181. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  182. package/dist/runtime-ets/dom/event.ts +26 -5
  183. package/dist/runtime-ets/dom/eventTarget.ts +3 -3
  184. package/dist/runtime-ets/dom/node.ts +114 -49
  185. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  186. package/dist/runtime-ets/dom/stylesheet/index.ts +122 -429
  187. package/dist/runtime-ets/dom/stylesheet/type.ts +93 -17
  188. package/dist/runtime-ets/dom/stylesheet/util.ts +145 -17
  189. package/dist/runtime-ets/index.ts +2 -3
  190. package/dist/runtime-ets/interface/event.ts +3 -2
  191. package/dist/runtime-ets/utils/index.ts +87 -17
  192. package/dist/runtime-ets/utils/info.ts +21 -47
  193. package/dist/runtime-framework/react/app.ts +20 -28
  194. package/dist/runtime-framework/react/hooks.ts +3 -4
  195. package/dist/runtime-framework/react/index.ts +1 -2
  196. package/dist/runtime-framework/react/native-page.ts +421 -0
  197. package/dist/runtime-framework/react/page.ts +5 -17
  198. package/dist/runtime-framework/solid/app.ts +25 -45
  199. package/dist/runtime-framework/solid/connect.ts +21 -3
  200. package/dist/runtime-framework/solid/hooks.ts +17 -12
  201. package/dist/runtime-framework/solid/index.ts +6 -2
  202. package/dist/runtime-framework/solid/page.ts +84 -36
  203. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  204. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  205. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  206. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  207. package/dist/runtime-utils.d.ts +827 -0
  208. package/dist/runtime-utils.js +1633 -549
  209. package/dist/runtime-utils.js.map +1 -1
  210. package/dist/runtime.d.ts +1 -0
  211. package/dist/runtime.js +1633 -549
  212. package/dist/runtime.js.map +1 -1
  213. package/index.js +3 -1
  214. package/package.json +14 -15
  215. package/static/media/cancel.svg +1 -0
  216. package/static/media/circle.svg +1 -0
  217. package/static/media/clear.svg +1 -0
  218. package/static/media/download.svg +1 -0
  219. package/static/media/info.svg +1 -0
  220. package/static/media/info_circle.svg +1 -0
  221. package/static/media/search.svg +1 -0
  222. package/static/media/success.svg +1 -0
  223. package/static/media/success_no_circle.svg +1 -0
  224. package/static/media/taro_arrow_left.svg +1 -0
  225. package/static/media/taro_home.svg +1 -0
  226. package/static/media/waiting.svg +1 -0
  227. package/static/media/warn.svg +1 -0
  228. package/types/harmony.d.ts +4 -0
  229. package/types/index.d.ts +4 -0
  230. package/types/runtime.d.ts +7 -1
  231. package/LICENSE +0 -160
  232. package/dist/components-harmony-ets/base.ets +0 -63
  233. package/dist/components-harmony-ets/element.ets +0 -223
  234. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  235. package/dist/runtime-ets/dom/element.ts +0 -457
  236. package/dist/runtime-ets/dom/text.ts +0 -19
  237. package/dist/runtime-ets/utils/bind.ts +0 -35
  238. package/types/api.d.ts +0 -4
  239. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,7 +1,5 @@
1
- // eslint-disable-next-line import/no-duplicates
2
- import { Current, document, requestAnimationFrame, window } from '@tarojs/runtime'
3
- // eslint-disable-next-line import/no-duplicates
4
- import { CONTEXT_ACTIONS, env, eventCenter } from '@tarojs/runtime/dist/runtime.esm'
1
+ import { Current, document, requestAnimationFrame, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
+ import { addLeadingSlash, CONTEXT_ACTIONS, env, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
5
3
  import { hooks, isArray, isFunction, isUndefined } from '@tarojs/shared'
6
4
 
7
5
  import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './constant'
@@ -9,17 +7,14 @@ import { incrementId } from './utils'
9
7
 
10
8
  import type { PageConfig } from '@tarojs/taro'
11
9
 
12
- // TODO TYPE
13
10
  const instances = new Map<string, any>()
14
11
  const pageId = incrementId()
15
12
 
16
- // TODO TYPE
17
13
  export function injectPageInstance (inst: any, id: string) {
18
14
  hooks.call('mergePageInstance', instances.get(id), inst)
19
15
  instances.set(id, inst)
20
16
  }
21
17
 
22
- // TODO TYPE
23
18
  export function getPageInstance (id: string): any {
24
19
  return instances.get(id)
25
20
  }
@@ -28,13 +23,6 @@ export function removePageInstance (id: string) {
28
23
  instances.delete(id)
29
24
  }
30
25
 
31
- export function addLeadingSlash (path?: string): string {
32
- if (path == null) {
33
- return ''
34
- }
35
- return path.charAt(0) === '/' ? path : '/' + path
36
- }
37
-
38
26
  export function safeExecute (path: string, lifecycle: string, ...args: unknown[]) {
39
27
  const instance = instances.get(path)
40
28
 
@@ -98,12 +86,10 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
98
86
  SIDE_EFFECT_LIFECYCLES,
99
87
  ] = hooks.call('getMiniLifecycleImpl')!.page
100
88
 
101
- // TODO TYPE
102
89
  let pageElement: any = null
103
90
  let unmounting = false
104
91
  let prepareMountList: (() => void)[] = []
105
92
 
106
- // TODO TYPE
107
93
  function setCurrentRouter (page) {
108
94
  const router = page.route || page.__route__ || page.$taroPath
109
95
 
@@ -143,7 +129,8 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
143
129
  window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
144
130
 
145
131
  const mount = () => {
146
- Current.app!.mount!(component, $taroPath, () => {
132
+ // @ts-ignore
133
+ Current.app!.mount!(component, $taroPath, null, () => {
147
134
  pageElement = document.getElementById($taroPath)
148
135
 
149
136
  if (!pageElement) {
@@ -190,6 +177,7 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
190
177
  safeExecute(this.$taroPath, ON_READY)
191
178
  // 通过事件触发子组件的生命周期
192
179
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
180
+ this.onReady = {}
193
181
  this.onReady.called = true
194
182
  })
195
183
  },
@@ -1,17 +1,16 @@
1
- import { Current, document } from '@tarojs/runtime'
2
- import { hooks, isWebPlatform } from '@tarojs/shared'
1
+ import { createComponent, h, render } from '@tarojs/plugin-framework-react/dist/reconciler'
2
+ import { Current, document } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
3
+ import { eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
4
+ import { hooks } from '@tarojs/shared'
3
5
  import { batch, createContext, createRoot, createSignal, For } from 'solid-js'
4
6
 
5
7
  import { setReconciler } from './connect'
6
8
  import { getPageInstance, injectPageInstance } from './page'
7
- import { createComponent, h, render } from './reconciler'
8
9
  import { EMPTY_OBJ, HOOKS_APP_ID, setDefaultDescriptor, setRouterParams } from './utils'
9
10
 
10
11
  import type { AppInstance, Instance, PageLifeCycle, PageProps, ReactAppInstance } from '@tarojs/runtime'
11
12
  import type { AppConfig } from '@tarojs/taro'
12
- import type { Component } from './connect'
13
-
14
- const isWeb = isWebPlatform()
13
+ import type { SolidComponent } from './connect'
15
14
 
16
15
  export const ReactMeta = {
17
16
  R: EMPTY_OBJ,
@@ -19,7 +18,7 @@ export const ReactMeta = {
19
18
  PageContext: EMPTY_OBJ
20
19
  }
21
20
 
22
- export function createSolidApp(App: Component, config: AppConfig) {
21
+ export function createSolidApp(App: SolidComponent, config: AppConfig) {
23
22
  setReconciler()
24
23
 
25
24
  if (ReactMeta.PageContext === EMPTY_OBJ) {
@@ -32,10 +31,7 @@ export function createSolidApp(App: Component, config: AppConfig) {
32
31
  }
33
32
 
34
33
  function renderReactRoot() {
35
- let appId = 'app'
36
- if (isWeb) {
37
- appId = config?.appId || appId
38
- }
34
+ const appId = 'app'
39
35
 
40
36
  if (ReactMeta.Container === EMPTY_OBJ) {
41
37
  const Container = document.createElement('view')
@@ -48,17 +44,18 @@ export function createSolidApp(App: Component, config: AppConfig) {
48
44
  render(AppWrapper, root)
49
45
  }
50
46
  const [pages, setPages] = createSignal<any[]>([])
47
+ const [elements, setElements] = createSignal<any[]>([])
51
48
 
52
49
  function AppWrapper () {
53
50
  appRef = {} as unknown as ReactAppInstance
54
51
  return createComponent(App, {
55
- children: createComponent(For as unknown as Component, {
52
+ children: createComponent(For as unknown as SolidComponent, {
56
53
  get each() {
57
54
  return pages()
58
55
  },
59
56
  children: ({ id, component }) => {
60
57
  const children = () =>
61
- createComponent(ReactMeta.PageContext.Provider as unknown as Component, {
58
+ createComponent(ReactMeta.PageContext.Provider as unknown as SolidComponent, {
62
59
  value: id,
63
60
  children: () => {
64
61
  injectPageInstance(
@@ -71,38 +68,29 @@ export function createSolidApp(App: Component, config: AppConfig) {
71
68
  },
72
69
  })
73
70
 
74
- if (isWeb) {
75
- return h('div', { id, className: 'taro_page' }, children)
76
- } else {
77
- return h('root', { id }, children)
78
- }
71
+ return h('root', { id }, children)
79
72
  },
80
73
  }),
81
74
  })
82
75
  }
83
76
 
84
- if (!isWeb) {
85
- renderReactRoot()
86
- }
87
-
88
- const [ONLAUNCH, ONSHOW, ONHIDE] = hooks.call('getMiniLifecycleImpl')!.app
77
+ renderReactRoot()
89
78
 
90
- const appObj: AppInstance = Object.create(
79
+ const app: AppInstance = Object.create(
91
80
  {
92
- mount(component: Component, id: string, cb: () => void) {
81
+ mount(component: SolidComponent, id: string, cb: () => void) {
93
82
  setPages((old) => [
94
83
  ...old,
95
84
  { id, component },
96
85
  ])
97
86
  batch(cb)
98
87
  },
99
-
100
88
  unmount(id: string, cb: () => void) {
101
- setPages(
102
- pages().filter((item) => {
103
- return item.id !== id
104
- })
105
- )
89
+ const idx = elements().findIndex((item) => item.id === id)
90
+ setElements((old) => {
91
+ old.splice(idx, 1)
92
+ return old
93
+ })
106
94
  batch(cb)
107
95
  },
108
96
  },
@@ -112,15 +100,10 @@ export function createSolidApp(App: Component, config: AppConfig) {
112
100
  value: config,
113
101
  }),
114
102
 
115
- [ONLAUNCH]: setDefaultDescriptor({
103
+ onLaunch: setDefaultDescriptor({
116
104
  value(options) {
117
105
  setRouterParams(options)
118
106
 
119
- if (isWeb) {
120
- // 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后执行 render
121
- renderReactRoot()
122
- }
123
-
124
107
  const onLaunch = () => {
125
108
  const app = getAppInstance()
126
109
 
@@ -151,28 +134,25 @@ export function createSolidApp(App: Component, config: AppConfig) {
151
134
 
152
135
  onLaunch()
153
136
  triggerAppHook('onLaunch', options)
137
+ eventCenter.trigger('__taroRouterLaunch', options)
154
138
  },
155
139
  }),
156
-
157
- [ONSHOW]: setDefaultDescriptor({
140
+ onShow: setDefaultDescriptor({
158
141
  value(options) {
159
142
  setRouterParams(options)
160
143
  triggerAppHook('onShow', options)
161
144
  },
162
145
  }),
163
-
164
- [ONHIDE]: setDefaultDescriptor({
146
+ onHide: setDefaultDescriptor({
165
147
  value() {
166
148
  triggerAppHook('onHide')
167
149
  },
168
150
  }),
169
-
170
151
  onError: setDefaultDescriptor({
171
152
  value(error: string) {
172
153
  triggerAppHook('onError', error)
173
154
  },
174
155
  }),
175
-
176
156
  onPageNotFound: setDefaultDescriptor({
177
157
  value(res: unknown) {
178
158
  triggerAppHook('onPageNotFound', res)
@@ -195,6 +175,6 @@ export function createSolidApp(App: Component, config: AppConfig) {
195
175
  }
196
176
  }
197
177
 
198
- Current.app = appObj
199
- return appObj
178
+ Current.app = app
179
+ return app
200
180
  }
@@ -1,11 +1,29 @@
1
- import { TaroNode } from '@tarojs/runtime'
2
1
  import { hooks } from '@tarojs/shared'
3
2
  import { batch } from 'solid-js'
4
3
 
5
- export type Component = (props?: any) => TaroNode
4
+ import { ensureIsArray } from './utils'
6
5
 
7
- export function setReconciler() {
6
+ import type { TaroNode } from '@tarojs/runtime'
7
+
8
+ export type SolidComponent = (props?: any) => TaroNode
9
+
10
+ export function setReconciler () {
8
11
  hooks.tap('batchedEventUpdates', function (cb) {
9
12
  batch(cb)
10
13
  })
14
+
15
+ hooks.tap('mergePageInstance', function (prev, next) {
16
+ if (!prev || !next) return
17
+
18
+ // 子组件使用 lifecycle hooks 注册了生命周期后,会存在 prev,里面是注册的生命周期回调。
19
+
20
+ // prev 使用 Object.create(null) 创建,H5 的 fast-refresh 可能也会导致存在 prev,要排除这些意外产生的 prev
21
+ if ('constructor' in prev) return
22
+
23
+ Object.keys(prev).forEach(item => {
24
+ const prevList = prev[item]
25
+ const nextList = ensureIsArray<() => any>(next[item])
26
+ next[item] = nextList.concat(prevList)
27
+ })
28
+ })
11
29
  }
@@ -1,9 +1,4 @@
1
- import {
2
- AppInstance,
3
- Current,
4
- Func,
5
- PageLifeCycle
6
- } from '@tarojs/runtime'
1
+ import { Current } from '@tarojs/runtime'
7
2
  import { isArray, isFunction } from '@tarojs/shared'
8
3
  import {
9
4
  createMemo,
@@ -15,8 +10,14 @@ import { ReactMeta } from './app'
15
10
  import { getPageInstance, injectPageInstance } from './page'
16
11
  import { HOOKS_APP_ID } from './utils'
17
12
 
13
+ import type {
14
+ AppInstance,
15
+ PageLifeCycle,
16
+ TFunc
17
+ } from '@tarojs/runtime/dist/runtime.esm'
18
+
18
19
  const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
19
- return (fn: Func) => {
20
+ return (fn: TFunc) => {
20
21
  const id = ReactMeta.PageContext || HOOKS_APP_ID
21
22
 
22
23
  createRenderEffect(() => {
@@ -30,10 +31,13 @@ const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
30
31
  })
31
32
  }
32
33
 
33
- if (isFunction(inst![lifecycle])) {
34
- inst![lifecycle] = [inst?.[lifecycle], fn]
34
+ if (isFunction(inst[lifecycle])) {
35
+ inst[lifecycle] = [inst[lifecycle], fn]
35
36
  } else {
36
- inst![lifecycle] = [...(inst![lifecycle] || []), fn]
37
+ inst[lifecycle] = [
38
+ ...((inst[lifecycle]) || []),
39
+ fn
40
+ ]
37
41
  }
38
42
 
39
43
  if (first) {
@@ -43,9 +47,9 @@ const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
43
47
  onCleanup(() => {
44
48
  const list = inst![lifecycle]
45
49
  if (list === fn) {
46
- inst![lifecycle] = undefined
50
+ (inst[lifecycle]) = undefined
47
51
  } else if (isArray(list)) {
48
- inst![lifecycle] = list.filter((item) => item !== fn)
52
+ (inst[lifecycle]) = list.filter(item => item !== fn)
49
53
  }
50
54
  })
51
55
  })
@@ -58,6 +62,7 @@ export const useDidShow = createTaroHook('componentDidShow')
58
62
 
59
63
  /** App */
60
64
  export const useError = createTaroHook('onError')
65
+ export const useUnhandledRejection = createTaroHook('onUnhandledRejection')
61
66
  export const useLaunch = createTaroHook('onLaunch')
62
67
  export const usePageNotFound = createTaroHook('onPageNotFound')
63
68
 
@@ -1,8 +1,12 @@
1
1
  import { hooks } from '@tarojs/shared'
2
2
 
3
- // declare const __TARO_FRAMEWORK__: string;
3
+ import * as taroHooks from './hooks'
4
4
 
5
- hooks.tap('initNativeApi', function (_taro) {})
5
+ hooks.tap('initNativeApi', function (taro) {
6
+ for (const hook in taroHooks) {
7
+ taro[hook] = taroHooks[hook]
8
+ }
9
+ })
6
10
 
7
11
  export * from './app'
8
12
  export * from './connect'
@@ -1,19 +1,20 @@
1
- import { Current } from '@tarojs/runtime'
2
- import { isArray, isFunction, isUndefined } from '@tarojs/shared'
1
+ import { Current, document, requestAnimationFrame, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
+ import { addLeadingSlash, CONTEXT_ACTIONS, env, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
3
+ import { hooks, isArray, isFunction, isUndefined } from '@tarojs/shared'
3
4
 
4
- import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './contant'
5
+ import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './constant'
5
6
  import { incrementId } from './utils'
6
7
 
7
- // TODO TYPE
8
+ import type { PageConfig } from '@tarojs/taro'
9
+
8
10
  const instances = new Map<string, any>()
9
11
  const pageId = incrementId()
10
12
 
11
- // TODO TYPE
12
13
  export function injectPageInstance (inst: any, id: string) {
14
+ hooks.call('mergePageInstance', instances.get(id), inst)
13
15
  instances.set(id, inst)
14
16
  }
15
17
 
16
- // TODO TYPE
17
18
  export function getPageInstance (id: string): any {
18
19
  return instances.get(id)
19
20
  }
@@ -22,13 +23,6 @@ export function removePageInstance (id: string) {
22
23
  instances.delete(id)
23
24
  }
24
25
 
25
- export function addLeadingSlash (path?: string): string {
26
- if (path == null) {
27
- return ''
28
- }
29
- return path.charAt(0) === '/' ? path : '/' + path
30
- }
31
-
32
26
  export function safeExecute (path: string, lifecycle: string, ...args: unknown[]) {
33
27
  const instance = instances.get(path)
34
28
 
@@ -36,6 +30,7 @@ export function safeExecute (path: string, lifecycle: string, ...args: unknown[]
36
30
  return
37
31
  }
38
32
 
33
+ lifecycle = lifecycle.replace(/^on(Show|Hide)$/, 'componentDid$1')
39
34
  const func = instance[lifecycle]
40
35
 
41
36
  if (isArray(func)) {
@@ -78,15 +73,23 @@ export function getOnHideEventKey (path: string) {
78
73
  return path + '.' + ON_HIDE
79
74
  }
80
75
 
81
- export function createPageConfig (component: any, pageName?: string) {
76
+ export function createPageConfig (component: any, pageName?: string, pageConfig?: PageConfig) {
82
77
  // 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上
83
78
  const id = pageName ?? `taro_page_${pageId()}`
84
- // TODO TYPE
79
+ const [
80
+ ONLOAD,
81
+ ONUNLOAD,
82
+ ONREADY,
83
+ ONSHOW,
84
+ ONHIDE,
85
+ LIFECYCLES,
86
+ SIDE_EFFECT_LIFECYCLES,
87
+ ] = hooks.call('getMiniLifecycleImpl')!.page
88
+
85
89
  let pageElement: any = null
86
90
  let unmounting = false
87
91
  let prepareMountList: (() => void)[] = []
88
92
 
89
- // TODO TYPE
90
93
  function setCurrentRouter (page) {
91
94
  const router = page.route || page.__route__ || page.$taroPath
92
95
 
@@ -107,7 +110,7 @@ export function createPageConfig (component: any, pageName?: string) {
107
110
  let loadResolver: (...args: any[]) => void
108
111
  let hasLoaded: Promise<void>
109
112
  const page = {
110
- onLoad (options: Readonly<Record<string, unknown>> = {}, cb?: (...args: any[]) => any) {
113
+ [ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: (...args: any[]) => any) {
111
114
  hasLoaded = new Promise(resolve => { loadResolver = resolve })
112
115
 
113
116
  Current.page = this as any
@@ -123,22 +126,21 @@ export function createPageConfig (component: any, pageName?: string) {
123
126
 
124
127
  setCurrentRouter(this)
125
128
 
126
- // window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
129
+ window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
127
130
 
128
131
  const mount = () => {
132
+ // @ts-ignore
129
133
  Current.app!.mount!(component, $taroPath, () => {
130
- // TODO TYPE env
131
- // pageElement = document.getElementById($taroPath)
134
+ pageElement = document.getElementById($taroPath)
132
135
 
133
- // if (!pageElement) {
134
- // throw new Error(`没有找到页面实例。`)
135
- // }
136
+ if (!pageElement) {
137
+ throw new Error(`没有找到页面实例。`)
138
+ }
136
139
 
137
140
  safeExecute($taroPath, ON_LOAD, this.$taroParams)
138
141
  loadResolver()
139
- cb && cb()
140
- // pageElement.ctx = this
141
- // pageElement.performUpdate(true, cb)
142
+ cb && cb(pageElement)
143
+ pageElement.ctx = this
142
144
  })
143
145
  }
144
146
 
@@ -148,10 +150,10 @@ export function createPageConfig (component: any, pageName?: string) {
148
150
  mount()
149
151
  }
150
152
  },
151
- onUnLoad () {
153
+ [ONUNLOAD] () {
152
154
  const $taroPath = this.$taroPath
153
155
  // 销毁当前页面的上下文信息
154
- // window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
156
+ window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
155
157
 
156
158
  // 触发onUnload生命周期
157
159
  safeExecute($taroPath, ON_UNLOAD)
@@ -169,22 +171,31 @@ export function createPageConfig (component: any, pageName?: string) {
169
171
  }
170
172
  })
171
173
  },
172
- onShow (options = {}) {
174
+ [ONREADY] () {
175
+ hasLoaded.then(() => {
176
+ // 触发生命周期
177
+ safeExecute(this.$taroPath, ON_READY)
178
+ // 通过事件触发子组件的生命周期
179
+ requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
180
+ this.onReady.called = true
181
+ })
182
+ },
183
+ [ONSHOW] (options = {}) {
173
184
  hasLoaded.then(() => {
174
185
  // 设置 Current 的 page 和 router
175
186
  Current.page = this as any
176
187
  setCurrentRouter(this)
177
188
  // 恢复上下文信息
178
- // window.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath)
189
+ window.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath)
179
190
  // 触发生命周期
180
191
  safeExecute(this.$taroPath, ON_SHOW, options)
181
- // TODO 通过事件触发子组件的生命周期
182
- // raf(() => eventCenter.trigger(getOnShowEventKey(id)))
192
+ // 通过事件触发子组件的生命周期
193
+ requestAnimationFrame(() => eventCenter.trigger(getOnShowEventKey(id)))
183
194
  })
184
195
  },
185
- onHide () {
196
+ [ONHIDE] () {
186
197
  // 缓存当前页面上下文信息
187
- // window.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath)
198
+ window.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath)
188
199
 
189
200
  // 设置 Current 的 page 和 router
190
201
  if (Current.page === this) {
@@ -194,9 +205,46 @@ export function createPageConfig (component: any, pageName?: string) {
194
205
  // 触发生命周期
195
206
  safeExecute(this.$taroPath, ON_HIDE)
196
207
  // TODO 通过事件触发子组件的生命周期
197
- // eventCenter.trigger(getOnHideEventKey(id))
198
- }
208
+ eventCenter.trigger(getOnHideEventKey(id))
209
+ },
199
210
  }
200
211
 
212
+ LIFECYCLES.forEach((lifecycle) => {
213
+ let isDefer = false
214
+ lifecycle = lifecycle.replace(/^defer:/, () => {
215
+ isDefer = true
216
+ return ''
217
+ })
218
+ page[lifecycle] = function () {
219
+ const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments)
220
+ if (isDefer) {
221
+ hasLoaded.then(exec)
222
+ } else {
223
+ return exec()
224
+ }
225
+ }
226
+ })
227
+
228
+ // onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
229
+ SIDE_EFFECT_LIFECYCLES.forEach(lifecycle => {
230
+ if (component[lifecycle] ||
231
+ component.prototype?.[lifecycle] ||
232
+ component[lifecycle.replace(/^on/, 'enable')] ||
233
+ pageConfig?.[lifecycle.replace(/^on/, 'enable')]
234
+ ) {
235
+ page[lifecycle] = function (...args) {
236
+ const target = args[0]?.target as any
237
+ if (target?.id) {
238
+ const id = target.id
239
+ const element = env.document.getElementById(id)
240
+ if (element) {
241
+ target.dataset = element.dataset
242
+ }
243
+ }
244
+ return safeExecute(this.$taroPath, lifecycle, ...args)
245
+ }
246
+ }
247
+ })
248
+
201
249
  return page
202
250
  }