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