@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121
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 +2 -6
- package/dist/apis/index.ts +25 -17
- package/dist/apis/media/image/index.ts +169 -17
- 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 +6 -6
- package/dist/apis/ui/tab-bar.ts +4 -5
- 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 +80 -0
- 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 +46 -42
- 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 +386 -129
- 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 +49 -19
- 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 +169 -91
- package/dist/components-harmony-ets/video.ets +28 -20
- package/dist/components-harmony-ets/view.ets +45 -39
- 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 +10 -4
- package/dist/runtime-ets/constant.ts +17 -10
- package/dist/runtime-ets/current.ts +5 -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 +379 -55
- 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 +418 -237
- package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
- package/dist/runtime-ets/dom/stylesheet/type.ts +53 -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 +15 -11
- 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 +217 -81
- package/dist/runtime-framework/react/page.ts +4 -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 +827 -0
- package/dist/runtime-utils.js +574 -285
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +574 -285
- 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 +1 -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,47 +52,64 @@ 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 () {
|
|
82
85
|
if (isDefaultEntryDom) {
|
|
83
|
-
Current.app
|
|
86
|
+
if (Current.app) {
|
|
87
|
+
Current.app = Object.assign(this, Current.app)
|
|
88
|
+
} else {
|
|
89
|
+
Current.app = this
|
|
90
|
+
}
|
|
84
91
|
} else {
|
|
85
92
|
nativeComponentApp = this
|
|
86
93
|
}
|
|
87
94
|
cb && cb()
|
|
88
95
|
}
|
|
89
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
|
+
|
|
90
104
|
mount (Component, compId, getCtx, cb?) {
|
|
91
105
|
const isReactComponent = isClassComponent(R, Component)
|
|
92
106
|
const inject = (node?: any) => node && injectPageInstance(node, compId)
|
|
93
|
-
const refs = isReactComponent
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
const refs = isReactComponent
|
|
108
|
+
? { ref: inject }
|
|
109
|
+
: {
|
|
110
|
+
forwardedRef: inject,
|
|
111
|
+
reactReduxForwardedRef: inject,
|
|
112
|
+
}
|
|
97
113
|
if (reactMeta.PageContext === EMPTY_OBJ) {
|
|
98
114
|
reactMeta.PageContext = R.createContext('')
|
|
99
115
|
}
|
|
@@ -107,42 +123,71 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
|
|
|
107
123
|
return h(
|
|
108
124
|
reactMeta.PageContext.Provider,
|
|
109
125
|
{ value: compId },
|
|
110
|
-
h(
|
|
111
|
-
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
$scope: ctx
|
|
117
|
-
}
|
|
118
|
-
)
|
|
126
|
+
h(Component, {
|
|
127
|
+
// TODO: 传递 Props
|
|
128
|
+
...(ctx.props || {}),
|
|
129
|
+
...refs,
|
|
130
|
+
$scope: ctx,
|
|
131
|
+
})
|
|
119
132
|
)
|
|
120
|
-
}
|
|
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
|
+
)
|
|
121
145
|
})
|
|
146
|
+
} else {
|
|
147
|
+
this.setState(
|
|
148
|
+
{
|
|
149
|
+
components: [...this.state.components, item],
|
|
150
|
+
},
|
|
151
|
+
() => cb && cb()
|
|
152
|
+
)
|
|
122
153
|
}
|
|
123
|
-
this.setState({
|
|
124
|
-
components: [...this.state.components, item]
|
|
125
|
-
}, () => cb && cb())
|
|
126
154
|
}
|
|
127
155
|
|
|
128
156
|
unmount (compId, cb?) {
|
|
129
157
|
const components = this.state.components
|
|
130
|
-
const index = components.findIndex(item => item.compId === compId)
|
|
158
|
+
const index = components.findIndex((item) => item.compId === compId)
|
|
131
159
|
const next = [...components.slice(0, index), ...components.slice(index + 1)]
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
+
}
|
|
138
185
|
}
|
|
139
186
|
|
|
140
187
|
render () {
|
|
141
188
|
const components = this.state.components
|
|
142
189
|
|
|
143
|
-
return (
|
|
144
|
-
components.map(({ element }) => element)
|
|
145
|
-
)
|
|
190
|
+
return components.map(({ element }) => element)
|
|
146
191
|
}
|
|
147
192
|
}
|
|
148
193
|
|
|
@@ -153,30 +198,49 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
|
|
|
153
198
|
// create
|
|
154
199
|
const nativeApp = document.createElement('nativeComponent')
|
|
155
200
|
// insert
|
|
156
|
-
app
|
|
201
|
+
app?.appendChild(nativeApp)
|
|
157
202
|
app = nativeApp
|
|
158
203
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
const pages = new Map<string, any>()
|
|
219
|
+
export function setPageById (inst: any, id: string) {
|
|
220
|
+
pages.set(id, inst)
|
|
164
221
|
}
|
|
165
222
|
|
|
166
|
-
export function
|
|
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
|
+
) {
|
|
167
238
|
reactMeta.R = react
|
|
168
239
|
h = react.createElement
|
|
169
240
|
ReactDOM = reactDOM
|
|
170
241
|
setReconciler(ReactDOM)
|
|
171
|
-
const [
|
|
172
|
-
|
|
173
|
-
ONUNLOAD,
|
|
174
|
-
ONREADY,
|
|
175
|
-
ONSHOW,
|
|
176
|
-
ONHIDE,
|
|
177
|
-
LIFECYCLES,
|
|
178
|
-
SIDE_EFFECT_LIFECYCLES
|
|
179
|
-
] = hooks.call('getMiniLifecycleImpl')!.page
|
|
242
|
+
const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES, SIDE_EFFECT_LIFECYCLES] =
|
|
243
|
+
hooks.call('getMiniLifecycleImpl')!.page
|
|
180
244
|
let unmounting = false
|
|
181
245
|
let prepareMountList: (() => void)[] = []
|
|
182
246
|
let pageElement: TaroElement | null = null
|
|
@@ -191,7 +255,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
191
255
|
$taroPath: page.$taroPath,
|
|
192
256
|
onReady: getOnReadyEventKey(id),
|
|
193
257
|
onShow: getOnShowEventKey(id),
|
|
194
|
-
onHide: getOnHideEventKey(id)
|
|
258
|
+
onHide: getOnHideEventKey(id),
|
|
195
259
|
}
|
|
196
260
|
if (!isUndefined(page.exitState)) {
|
|
197
261
|
Current.router.exitState = page.exitState
|
|
@@ -201,12 +265,16 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
201
265
|
const pageObj: Record<string, any> = {
|
|
202
266
|
options: pageConfig,
|
|
203
267
|
[ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: TFunc) {
|
|
204
|
-
hasLoaded = new Promise(resolve => {
|
|
268
|
+
hasLoaded = new Promise((resolve) => {
|
|
269
|
+
loadResolver = resolve
|
|
270
|
+
})
|
|
205
271
|
Current.page = this as any
|
|
206
272
|
this.config = pageConfig || {}
|
|
207
273
|
// this.$taroPath 是页面唯一标识
|
|
208
274
|
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() })
|
|
209
|
-
const $taroPath = this.$taroPath = getPath(id, uniqueOptions)
|
|
275
|
+
const $taroPath = (this.$taroPath = getPath(id, uniqueOptions))
|
|
276
|
+
|
|
277
|
+
setPageById(this, $taroPath)
|
|
210
278
|
|
|
211
279
|
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
212
280
|
if (this.$taroParams == null) {
|
|
@@ -219,7 +287,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
219
287
|
const mountCallback = () => {
|
|
220
288
|
pageElement = document.getElementById($taroPath)
|
|
221
289
|
|
|
222
|
-
ensure(pageElement !== null,
|
|
290
|
+
ensure(pageElement !== null, `Taro Error Page: ${$taroPath}, 该页面执行时出现了报错,导致没有找到页面实例。`)
|
|
223
291
|
|
|
224
292
|
safeExecute($taroPath, ONLOAD, this.$taroParams)
|
|
225
293
|
loadResolver()
|
|
@@ -232,9 +300,10 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
232
300
|
initNativeComponentEntry({
|
|
233
301
|
R: react,
|
|
234
302
|
ReactDOM,
|
|
303
|
+
isUseReact18: pageConfig?.isUseReact18,
|
|
235
304
|
cb: () => {
|
|
236
305
|
Current.app!.mount!(Component, $taroPath, () => this, mountCallback)
|
|
237
|
-
}
|
|
306
|
+
},
|
|
238
307
|
})
|
|
239
308
|
} else {
|
|
240
309
|
Current.app!.mount!(Component, $taroPath, () => this, mountCallback)
|
|
@@ -253,7 +322,11 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
253
322
|
window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
|
|
254
323
|
// 触发onUnload生命周期
|
|
255
324
|
safeExecute($taroPath, ONUNLOAD)
|
|
256
|
-
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
removePageById($taroPath)
|
|
328
|
+
|
|
329
|
+
resetCurrent.call(this)
|
|
257
330
|
unmounting = true
|
|
258
331
|
Current.app!.unmount!($taroPath, () => {
|
|
259
332
|
unmounting = false
|
|
@@ -263,7 +336,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
263
336
|
pageElement = null
|
|
264
337
|
}
|
|
265
338
|
if (prepareMountList.length) {
|
|
266
|
-
prepareMountList.forEach(fn => fn())
|
|
339
|
+
prepareMountList.forEach((fn) => fn())
|
|
267
340
|
prepareMountList = []
|
|
268
341
|
}
|
|
269
342
|
})
|
|
@@ -274,6 +347,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
274
347
|
safeExecute(this.$taroPath, ON_READY)
|
|
275
348
|
// 通过事件触发子组件的生命周期
|
|
276
349
|
requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
|
|
350
|
+
this.onReady = {}
|
|
277
351
|
this.onReady.called = true
|
|
278
352
|
})
|
|
279
353
|
},
|
|
@@ -306,12 +380,13 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
306
380
|
}
|
|
307
381
|
|
|
308
382
|
function resetCurrent () {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
383
|
+
if (Current.page === this) {
|
|
384
|
+
// 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
|
|
385
|
+
Current.page = null
|
|
386
|
+
Current.router = null
|
|
387
|
+
}
|
|
312
388
|
}
|
|
313
389
|
|
|
314
|
-
|
|
315
390
|
LIFECYCLES.forEach((lifecycle) => {
|
|
316
391
|
pageObj[lifecycle] = function () {
|
|
317
392
|
return safeExecute(this.$taroPath, lifecycle, ...arguments)
|
|
@@ -319,11 +394,8 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
319
394
|
})
|
|
320
395
|
|
|
321
396
|
// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
|
|
322
|
-
SIDE_EFFECT_LIFECYCLES.forEach(lifecycle => {
|
|
323
|
-
if (Component[lifecycle] ||
|
|
324
|
-
Component.prototype?.[lifecycle] ||
|
|
325
|
-
Component[lifecycle.replace(/^on/, 'enable')]
|
|
326
|
-
) {
|
|
397
|
+
SIDE_EFFECT_LIFECYCLES.forEach((lifecycle) => {
|
|
398
|
+
if (Component[lifecycle] || Component.prototype?.[lifecycle] || Component[lifecycle.replace(/^on/, 'enable')]) {
|
|
327
399
|
pageObj[lifecycle] = function (...args) {
|
|
328
400
|
const target = args[0]?.target
|
|
329
401
|
if (target?.id) {
|
|
@@ -342,3 +414,67 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
342
414
|
|
|
343
415
|
return pageObj
|
|
344
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,8 @@ 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 = {}
|
|
180
|
+
this.onReady.called = true
|
|
187
181
|
})
|
|
188
182
|
},
|
|
189
183
|
[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 =
|
|
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
|
}
|