@tarojs/plugin-platform-harmony-ets 4.0.0-canary.8 → 4.0.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 (135) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +23 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/media/image/index.ts +169 -17
  7. package/dist/apis/network/request.ts +5 -5
  8. package/dist/apis/route/index.ts +15 -0
  9. package/dist/apis/storage/index.ts +146 -78
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +2 -1
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +5 -5
  16. package/dist/apis/ui/tab-bar.ts +3 -3
  17. package/dist/apis/utils/index.ts +21 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/index.ts +2 -0
  21. package/dist/apis/wxml/selectorQuery.ts +26 -13
  22. package/dist/components-harmony-ets/button.ets +63 -77
  23. package/dist/components-harmony-ets/canvas.ets +51 -0
  24. package/dist/components-harmony-ets/checkbox.ets +75 -258
  25. package/dist/components-harmony-ets/form.ets +51 -158
  26. package/dist/components-harmony-ets/icon.ets +33 -83
  27. package/dist/components-harmony-ets/image.ets +35 -79
  28. package/dist/components-harmony-ets/index.ets +92 -0
  29. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  30. package/dist/components-harmony-ets/input.ets +64 -101
  31. package/dist/components-harmony-ets/label.ets +72 -174
  32. package/dist/components-harmony-ets/listView.ets +31 -0
  33. package/dist/components-harmony-ets/movableArea.ets +126 -0
  34. package/dist/components-harmony-ets/movableView.ets +93 -0
  35. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  36. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  37. package/dist/components-harmony-ets/picker.ets +46 -163
  38. package/dist/components-harmony-ets/progress.ets +52 -0
  39. package/dist/components-harmony-ets/pseudo.ets +80 -0
  40. package/dist/components-harmony-ets/radio.ets +80 -264
  41. package/dist/components-harmony-ets/richText.ets +20 -102
  42. package/dist/components-harmony-ets/scrollList.ets +108 -0
  43. package/dist/components-harmony-ets/scrollView.ets +71 -160
  44. package/dist/components-harmony-ets/slider.ets +22 -82
  45. package/dist/components-harmony-ets/stickySection.ets +42 -0
  46. package/dist/components-harmony-ets/style.ets +410 -0
  47. package/dist/components-harmony-ets/swiper.ets +64 -87
  48. package/dist/components-harmony-ets/switch.ets +39 -99
  49. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  50. package/dist/components-harmony-ets/text.ets +111 -113
  51. package/dist/components-harmony-ets/textArea.ets +51 -95
  52. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  53. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  54. package/dist/components-harmony-ets/utils/flexManager.ets +50 -19
  55. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  56. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  57. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  58. package/dist/components-harmony-ets/utils/index.ts +54 -50
  59. package/dist/components-harmony-ets/utils/styles.ets +172 -92
  60. package/dist/components-harmony-ets/video.ets +37 -88
  61. package/dist/components-harmony-ets/view.ets +63 -159
  62. package/dist/components-harmony-ets/webView.ets +41 -98
  63. package/dist/index.d.ts +152 -0
  64. package/dist/index.js +187 -56
  65. package/dist/index.js.map +1 -1
  66. package/dist/runtime-ets/bom/document.ts +6 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  68. package/dist/runtime-ets/bom/window.ts +9 -2
  69. package/dist/runtime-ets/current.ts +5 -1
  70. package/dist/runtime-ets/dom/bind.ts +28 -12
  71. package/dist/runtime-ets/dom/class-list.ts +2 -2
  72. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  73. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  74. package/dist/runtime-ets/dom/document.ts +22 -8
  75. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  76. package/dist/runtime-ets/dom/element/element.ts +376 -57
  77. package/dist/runtime-ets/dom/element/form.ts +31 -26
  78. package/dist/runtime-ets/dom/element/index.ts +30 -2
  79. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  80. package/dist/runtime-ets/dom/element/movableView.ts +248 -0
  81. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  82. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  83. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  84. package/dist/runtime-ets/dom/element/text.ts +1 -8
  85. package/dist/runtime-ets/dom/element/video.ts +5 -4
  86. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  87. package/dist/runtime-ets/dom/event.ts +3 -5
  88. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  89. package/dist/runtime-ets/dom/node.ts +65 -32
  90. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  91. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  92. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  93. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  94. package/dist/runtime-ets/index.ts +2 -2
  95. package/dist/runtime-ets/interface/event.ts +1 -1
  96. package/dist/runtime-ets/utils/index.ts +74 -13
  97. package/dist/runtime-ets/utils/info.ts +2 -2
  98. package/dist/runtime-framework/react/app.ts +25 -30
  99. package/dist/runtime-framework/react/hooks.ts +3 -4
  100. package/dist/runtime-framework/react/index.ts +0 -2
  101. package/dist/runtime-framework/react/native-page.ts +219 -82
  102. package/dist/runtime-framework/react/page.ts +6 -10
  103. package/dist/runtime-framework/react/utils/index.ts +3 -3
  104. package/dist/runtime-framework/solid/app.ts +30 -46
  105. package/dist/runtime-framework/solid/connect.ts +21 -3
  106. package/dist/runtime-framework/solid/hooks.ts +17 -12
  107. package/dist/runtime-framework/solid/index.ts +6 -2
  108. package/dist/runtime-framework/solid/page.ts +85 -31
  109. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  110. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  111. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  112. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  113. package/dist/runtime-utils.d.ts +827 -0
  114. package/dist/runtime-utils.js +618 -245
  115. package/dist/runtime-utils.js.map +1 -1
  116. package/dist/runtime.d.ts +1 -0
  117. package/dist/runtime.js +618 -245
  118. package/dist/runtime.js.map +1 -1
  119. package/index.js +3 -1
  120. package/package.json +14 -15
  121. package/static/media/cancel.svg +1 -1
  122. package/static/media/circle.svg +1 -1
  123. package/static/media/clear.svg +1 -1
  124. package/static/media/download.svg +1 -1
  125. package/static/media/info.svg +1 -1
  126. package/static/media/info_circle.svg +1 -1
  127. package/static/media/search.svg +1 -1
  128. package/static/media/success.svg +1 -1
  129. package/static/media/success_no_circle.svg +1 -1
  130. package/static/media/warn.svg +1 -1
  131. package/types/harmony.d.ts +5 -0
  132. package/types/index.d.ts +4 -0
  133. package/types/runtime.d.ts +3 -1
  134. package/dist/runtime-ets/utils/bind.ts +0 -24
  135. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,39 +1,39 @@
1
1
  import { Current, document, requestAnimationFrame, TaroElement, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
- import { CONTEXT_ACTIONS, env, eventCenter, Func } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
2
+ import { addLeadingSlash, CONTEXT_ACTIONS, env, eventCenter, TFunc } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
3
3
  import { ensure, hooks, isUndefined } from '@tarojs/shared'
4
4
 
5
5
  import { ReactMeta as reactMeta } from './app'
6
6
  import { setReconciler } from './connect'
7
7
  import { ON_HIDE, ON_READY, ON_SHOW } from './constant'
8
8
  import {
9
- addLeadingSlash,
10
9
  getOnHideEventKey,
11
10
  getOnReadyEventKey,
12
- getOnShowEventKey,
11
+ getOnShowEventKey,
13
12
  getPath,
14
13
  injectPageInstance,
15
14
  removePageInstance,
16
- safeExecute
15
+ safeExecute,
17
16
  } from './page'
18
17
  import { EMPTY_OBJ, incrementId, isClassComponent } from './utils'
19
18
 
20
19
  import type { AppInstance } from '@tarojs/taro'
21
20
  import type * as React from 'react'
22
21
 
23
- const getNativeCompId = incrementId()
22
+ const getNativeCompId = incrementId(1)
24
23
  let h: typeof React.createElement
25
24
  let ReactDOM
26
25
  let nativeComponentApp: AppInstance
27
26
  interface InitNativeComponentEntryParams {
28
27
  R: typeof React
29
28
  ReactDOM: typeof ReactDOM
30
- cb?: Func
29
+ cb?: TFunc
31
30
  // 是否使用默认的 DOM 入口 - app;默认为true,false的时候,会创建一个新的dom并且把它挂载在 app 下面
32
31
  isDefaultEntryDom?: boolean
32
+ isUseReact18?: boolean
33
33
  }
34
34
 
35
35
  function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
36
- const { R, ReactDOM, cb, isDefaultEntryDom = true } = params
36
+ const { R, ReactDOM, cb, isDefaultEntryDom = true, isUseReact18 = false } = params
37
37
  interface IEntryState {
38
38
  components: {
39
39
  compId: string
@@ -53,47 +53,64 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
53
53
 
54
54
  componentDidMount () {
55
55
  this.ctx.component = this
56
- const rootElement = this.root.current!
57
- rootElement.ctx = this.ctx
58
- // TODO: performUpdate
59
- // rootElement.performUpdate(true)
56
+ if (this.root.current) {
57
+ this.root.current = this.ctx
58
+ }
59
+ }
60
+
61
+ // React 16 uncaught error 会导致整个应用 crash,
62
+ // 目前把错误缩小到页面
63
+ componentDidCatch (error, info: React.ErrorInfo) {
64
+ console.warn(`Taro Error Page 报错信息:${error}`)
65
+ console.error(`Taro Error Page 报错堆栈:${info.componentStack}`)
60
66
  }
61
67
 
62
68
  render () {
63
- return (
64
- h(
65
- 'view',
66
- {
67
- ref: this.root,
68
- id: this.props.compId
69
- },
70
- this.props.renderComponent(this.ctx)
71
- )
69
+ return h(
70
+ 'taro-page',
71
+ {
72
+ ref: this.root,
73
+ id: this.props.compId,
74
+ },
75
+ this.props.renderComponent(this.ctx)
72
76
  )
73
77
  }
74
78
  }
75
79
 
76
80
  class Entry extends R.Component<Record<any, any>, IEntryState> {
77
81
  state: IEntryState = {
78
- components: []
82
+ components: [],
79
83
  }
80
84
 
81
85
  componentDidMount () {
82
86
  if (isDefaultEntryDom) {
83
- Current.app = this
87
+ if (Current.app) {
88
+ Current.app = Object.assign(this, Current.app)
89
+ } else {
90
+ Current.app = this
91
+ }
84
92
  } else {
85
93
  nativeComponentApp = this
86
94
  }
87
95
  cb && cb()
88
96
  }
89
97
 
98
+ // React 16 uncaught error 会导致整个应用 crash,
99
+ // 目前把错误缩小到页面
100
+ componentDidCatch (error, info: React.ErrorInfo) {
101
+ console.warn(error)
102
+ console.error(info.componentStack)
103
+ }
104
+
90
105
  mount (Component, compId, getCtx, cb?) {
91
106
  const isReactComponent = isClassComponent(R, Component)
92
107
  const inject = (node?: any) => node && injectPageInstance(node, compId)
93
- const refs = isReactComponent ? { ref: inject } : {
94
- forwardedRef: inject,
95
- reactReduxForwardedRef: inject
96
- }
108
+ const refs = isReactComponent
109
+ ? { ref: inject }
110
+ : {
111
+ forwardedRef: inject,
112
+ reactReduxForwardedRef: inject,
113
+ }
97
114
  if (reactMeta.PageContext === EMPTY_OBJ) {
98
115
  reactMeta.PageContext = R.createContext('')
99
116
  }
@@ -107,42 +124,71 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
107
124
  return h(
108
125
  reactMeta.PageContext.Provider,
109
126
  { value: compId },
110
- h(
111
- Component,
112
- {
113
- // TODO: 传递 Props
114
- ...(ctx.data ||= {}).props,
115
- ...refs,
116
- $scope: ctx
117
- }
118
- )
127
+ h(Component, {
128
+ // TODO: 传递 Props
129
+ ...(ctx.props || {}),
130
+ ...refs,
131
+ $scope: ctx,
132
+ })
119
133
  )
120
- }
134
+ },
135
+ }),
136
+ }
137
+
138
+ if (isUseReact18) {
139
+ ReactDOM.flushSync(() => {
140
+ this.setState(
141
+ {
142
+ components: [...this.state.components, item],
143
+ },
144
+ () => cb && cb()
145
+ )
121
146
  })
147
+ } else {
148
+ this.setState(
149
+ {
150
+ components: [...this.state.components, item],
151
+ },
152
+ () => cb && cb()
153
+ )
122
154
  }
123
- this.setState({
124
- components: [...this.state.components, item]
125
- }, () => cb && cb())
126
155
  }
127
156
 
128
157
  unmount (compId, cb?) {
129
158
  const components = this.state.components
130
- const index = components.findIndex(item => item.compId === compId)
159
+ const index = components.findIndex((item) => item.compId === compId)
131
160
  const next = [...components.slice(0, index), ...components.slice(index + 1)]
132
- this.setState({
133
- components: next
134
- }, () => {
135
- removePageInstance(compId)
136
- cb && cb()
137
- })
161
+
162
+
163
+ if (isUseReact18) {
164
+ ReactDOM.flushSync(() => {
165
+ this.setState(
166
+ {
167
+ components: next,
168
+ },
169
+ () => {
170
+ removePageInstance(compId)
171
+ cb && cb()
172
+ }
173
+ )
174
+ })
175
+ } else {
176
+ this.setState(
177
+ {
178
+ components: next,
179
+ },
180
+ () => {
181
+ removePageInstance(compId)
182
+ cb && cb()
183
+ }
184
+ )
185
+ }
138
186
  }
139
187
 
140
188
  render () {
141
189
  const components = this.state.components
142
190
 
143
- return (
144
- components.map(({ element }) => element)
145
- )
191
+ return components.map(({ element }) => element)
146
192
  }
147
193
  }
148
194
 
@@ -153,30 +199,49 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
153
199
  // create
154
200
  const nativeApp = document.createElement('nativeComponent')
155
201
  // insert
156
- app.appendChild(nativeApp)
202
+ app?.appendChild(nativeApp)
157
203
  app = nativeApp
158
204
  }
159
- // eslint-disable-next-line react/no-deprecated
160
- ReactDOM.render(
161
- h(Entry, {}),
162
- app
163
- )
205
+
206
+ if (isUseReact18) {
207
+ const root = ReactDOM.createRoot(app)
208
+
209
+ ReactDOM.flushSync(() => {
210
+ root.render?.(h(Entry))
211
+ })
212
+ } else {
213
+ // eslint-disable-next-line react/no-deprecated
214
+ ReactDOM.render(h(Entry, {}), app)
215
+ }
216
+ }
217
+
218
+
219
+ const pages = new Map<string, any>()
220
+ export function setPageById (inst: any, id: string) {
221
+ pages.set(id, inst)
164
222
  }
165
223
 
166
- export function createNativePageConfig (Component, pageName: string, react: typeof React, reactDOM: typeof ReactDOM, pageConfig) {
224
+ export function getPageById (id: string): any {
225
+ return pages.get(id)
226
+ }
227
+
228
+ export function removePageById (id: string) {
229
+ pages.delete(id)
230
+ }
231
+
232
+ export function createNativePageConfig (
233
+ Component,
234
+ pageName: string,
235
+ react: typeof React,
236
+ reactDOM: typeof ReactDOM,
237
+ pageConfig
238
+ ) {
167
239
  reactMeta.R = react
168
240
  h = react.createElement
169
241
  ReactDOM = reactDOM
170
242
  setReconciler(ReactDOM)
171
- const [
172
- ONLOAD,
173
- ONUNLOAD,
174
- ONREADY,
175
- ONSHOW,
176
- ONHIDE,
177
- LIFECYCLES,
178
- SIDE_EFFECT_LIFECYCLES
179
- ] = hooks.call('getMiniLifecycleImpl')!.page
243
+ const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES, SIDE_EFFECT_LIFECYCLES] =
244
+ hooks.call('getMiniLifecycleImpl')!.page
180
245
  let unmounting = false
181
246
  let prepareMountList: (() => void)[] = []
182
247
  let pageElement: TaroElement | null = null
@@ -191,7 +256,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
191
256
  $taroPath: page.$taroPath,
192
257
  onReady: getOnReadyEventKey(id),
193
258
  onShow: getOnShowEventKey(id),
194
- onHide: getOnHideEventKey(id)
259
+ onHide: getOnHideEventKey(id),
195
260
  }
196
261
  if (!isUndefined(page.exitState)) {
197
262
  Current.router.exitState = page.exitState
@@ -200,13 +265,17 @@ export function createNativePageConfig (Component, pageName: string, react: type
200
265
 
201
266
  const pageObj: Record<string, any> = {
202
267
  options: pageConfig,
203
- [ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: Func) {
204
- hasLoaded = new Promise(resolve => { loadResolver = resolve })
268
+ [ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: TFunc) {
269
+ hasLoaded = new Promise((resolve) => {
270
+ loadResolver = resolve
271
+ })
205
272
  Current.page = this as any
206
273
  this.config = pageConfig || {}
207
274
  // this.$taroPath 是页面唯一标识
208
275
  const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() })
209
- const $taroPath = this.$taroPath = getPath(id, uniqueOptions)
276
+ const $taroPath = (this.$taroPath = getPath(id, uniqueOptions))
277
+
278
+ setPageById(this, $taroPath)
210
279
 
211
280
  // this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
212
281
  if (this.$taroParams == null) {
@@ -219,7 +288,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
219
288
  const mountCallback = () => {
220
289
  pageElement = document.getElementById($taroPath)
221
290
 
222
- ensure(pageElement !== null, '没有找到页面实例。')
291
+ ensure(pageElement !== null, `Taro Error Page: ${$taroPath}, 该页面执行时出现了报错,导致没有找到页面实例。`)
223
292
 
224
293
  safeExecute($taroPath, ONLOAD, this.$taroParams)
225
294
  loadResolver()
@@ -232,9 +301,10 @@ export function createNativePageConfig (Component, pageName: string, react: type
232
301
  initNativeComponentEntry({
233
302
  R: react,
234
303
  ReactDOM,
304
+ isUseReact18: pageConfig?.isUseReact18,
235
305
  cb: () => {
236
306
  Current.app!.mount!(Component, $taroPath, () => this, mountCallback)
237
- }
307
+ },
238
308
  })
239
309
  } else {
240
310
  Current.app!.mount!(Component, $taroPath, () => this, mountCallback)
@@ -253,7 +323,11 @@ export function createNativePageConfig (Component, pageName: string, react: type
253
323
  window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
254
324
  // 触发onUnload生命周期
255
325
  safeExecute($taroPath, ONUNLOAD)
256
- resetCurrent()
326
+
327
+
328
+ removePageById($taroPath)
329
+
330
+ resetCurrent.call(this)
257
331
  unmounting = true
258
332
  Current.app!.unmount!($taroPath, () => {
259
333
  unmounting = false
@@ -263,7 +337,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
263
337
  pageElement = null
264
338
  }
265
339
  if (prepareMountList.length) {
266
- prepareMountList.forEach(fn => fn())
340
+ prepareMountList.forEach((fn) => fn())
267
341
  prepareMountList = []
268
342
  }
269
343
  })
@@ -274,6 +348,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
274
348
  safeExecute(this.$taroPath, ON_READY)
275
349
  // 通过事件触发子组件的生命周期
276
350
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
351
+ this.onReady = {}
277
352
  this.onReady.called = true
278
353
  })
279
354
  },
@@ -306,12 +381,13 @@ export function createNativePageConfig (Component, pageName: string, react: type
306
381
  }
307
382
 
308
383
  function resetCurrent () {
309
- // 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
310
- Current.page = null
311
- Current.router = null
384
+ if (Current.page === this) {
385
+ // 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
386
+ Current.page = null
387
+ Current.router = null
388
+ }
312
389
  }
313
390
 
314
-
315
391
  LIFECYCLES.forEach((lifecycle) => {
316
392
  pageObj[lifecycle] = function () {
317
393
  return safeExecute(this.$taroPath, lifecycle, ...arguments)
@@ -319,11 +395,8 @@ export function createNativePageConfig (Component, pageName: string, react: type
319
395
  })
320
396
 
321
397
  // onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
322
- SIDE_EFFECT_LIFECYCLES.forEach(lifecycle => {
323
- if (Component[lifecycle] ||
324
- Component.prototype?.[lifecycle] ||
325
- Component[lifecycle.replace(/^on/, 'enable')]
326
- ) {
398
+ SIDE_EFFECT_LIFECYCLES.forEach((lifecycle) => {
399
+ if (Component[lifecycle] || Component.prototype?.[lifecycle] || Component[lifecycle.replace(/^on/, 'enable')]) {
327
400
  pageObj[lifecycle] = function (...args) {
328
401
  const target = args[0]?.target
329
402
  if (target?.id) {
@@ -342,3 +415,67 @@ export function createNativePageConfig (Component, pageName: string, react: type
342
415
 
343
416
  return pageObj
344
417
  }
418
+
419
+ export function createNativeComponentConfig (
420
+ Component,
421
+ react: typeof React,
422
+ reactdom,
423
+ componentConfig
424
+ ) {
425
+ reactMeta.R = react
426
+ h = react.createElement
427
+ ReactDOM = reactdom
428
+ setReconciler(ReactDOM)
429
+ const { isNewBlended, isUseReact18 } = componentConfig
430
+
431
+ const componentObj: Record<string, any> = {
432
+ options: componentConfig,
433
+ onLoad (
434
+ options: Readonly<Record<string, unknown>> = {}, // eslint-disable-line @typescript-eslint/no-unused-vars
435
+ cb?: TFunc
436
+ ) {
437
+ const app = isNewBlended ? nativeComponentApp : Current.app
438
+
439
+ const mountComponent = () => {
440
+ const app = isNewBlended ? nativeComponentApp : Current.app
441
+ const compId = (this.compId = getNativeCompId())
442
+
443
+ this.config = componentConfig
444
+ app!.mount!(
445
+ Component,
446
+ compId,
447
+ () => this,
448
+ () => {
449
+ const el = document.getElementById(compId)
450
+
451
+ if (!el) {
452
+ throw new Error(`没有找到组件实例。`)
453
+ } else {
454
+ el.ctx = this
455
+ cb && cb(el)
456
+ }
457
+ }
458
+ )
459
+ }
460
+
461
+ if (!app) {
462
+ initNativeComponentEntry({
463
+ R: react,
464
+ ReactDOM,
465
+ isDefaultEntryDom: !isNewBlended,
466
+ isUseReact18,
467
+ cb: mountComponent,
468
+ })
469
+ } else {
470
+ mountComponent()
471
+ }
472
+ },
473
+
474
+ onUnload () {
475
+ const app = isNewBlended ? nativeComponentApp : Current.app
476
+ app!.unmount!(this.compId)
477
+ },
478
+ }
479
+
480
+ return componentObj
481
+ }
@@ -1,5 +1,5 @@
1
1
  import { Current, document, requestAnimationFrame, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
- import { CONTEXT_ACTIONS, env, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // 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
3
  import { hooks, isArray, isFunction, isUndefined } from '@tarojs/shared'
4
4
 
5
5
  import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './constant'
@@ -8,7 +8,7 @@ import { incrementId } from './utils'
8
8
  import type { PageConfig } from '@tarojs/taro'
9
9
 
10
10
  const instances = new Map<string, any>()
11
- const pageId = incrementId()
11
+ const pageId = incrementId(1)
12
12
 
13
13
  export function injectPageInstance (inst: any, id: string) {
14
14
  hooks.call('mergePageInstance', instances.get(id), inst)
@@ -23,13 +23,6 @@ export function removePageInstance (id: string) {
23
23
  instances.delete(id)
24
24
  }
25
25
 
26
- export function addLeadingSlash (path?: string): string {
27
- if (path == null) {
28
- return ''
29
- }
30
- return path.charAt(0) === '/' ? path : '/' + path
31
- }
32
-
33
26
  export function safeExecute (path: string, lifecycle: string, ...args: unknown[]) {
34
27
  const instance = instances.get(path)
35
28
 
@@ -136,7 +129,8 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
136
129
  window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
137
130
 
138
131
  const mount = () => {
139
- Current.app!.mount!(component, $taroPath, () => {
132
+ // @ts-ignore
133
+ Current.app!.mount!(component, $taroPath, null, () => {
140
134
  pageElement = document.getElementById($taroPath)
141
135
 
142
136
  if (!pageElement) {
@@ -183,6 +177,8 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
183
177
  safeExecute(this.$taroPath, ON_READY)
184
178
  // 通过事件触发子组件的生命周期
185
179
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
180
+ this.onReady = {}
181
+ this.onReady.called = true
186
182
  })
187
183
  },
188
184
  [ONSHOW] (options = {}) {
@@ -7,9 +7,9 @@ export function capitalize (s: string) {
7
7
  return s.charAt(0).toUpperCase() + s.slice(1)
8
8
  }
9
9
 
10
- export const incrementId = () => {
11
- let n = 0
12
- return () => (n++).toString()
10
+ export const incrementId = (init = 0) => {
11
+ let n = init
12
+ return () => n++
13
13
  }
14
14
 
15
15
  export function ensureIsArray<T> (item: T | T[]): T[] {