@tarojs/plugin-platform-harmony-ets 4.0.0-canary.9 → 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.
- package/dist/apis/base/system.ts +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +23 -8
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +27 -17
- package/dist/apis/media/image/index.ts +169 -17
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +146 -78
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +58 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- 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 +3 -3
- package/dist/apis/utils/index.ts +21 -2
- package/dist/apis/utils/permissions.ts +6 -0
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +64 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +73 -62
- package/dist/components-harmony-ets/form.ets +51 -29
- package/dist/components-harmony-ets/icon.ets +31 -19
- package/dist/components-harmony-ets/image.ets +34 -14
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +63 -41
- package/dist/components-harmony-ets/label.ets +71 -44
- package/dist/components-harmony-ets/listView.ets +31 -0
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- 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 +43 -39
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +78 -68
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollList.ets +108 -0
- package/dist/components-harmony-ets/scrollView.ets +69 -30
- 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 -130
- package/dist/components-harmony-ets/swiper.ets +61 -20
- 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 +112 -50
- package/dist/components-harmony-ets/textArea.ets +50 -35
- 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 +50 -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 +172 -92
- package/dist/components-harmony-ets/video.ets +34 -21
- package/dist/components-harmony-ets/view.ets +62 -29
- package/dist/components-harmony-ets/webView.ets +40 -34
- package/dist/index.d.ts +152 -0
- package/dist/index.js +102 -56
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +7 -0
- package/dist/runtime-ets/current.ts +5 -1
- 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 +22 -8
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +376 -57
- package/dist/runtime-ets/dom/element/form.ts +31 -26
- package/dist/runtime-ets/dom/element/index.ts +30 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +248 -0
- package/dist/runtime-ets/dom/element/normal.ts +35 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +12 -5
- package/dist/runtime-ets/dom/event.ts +3 -5
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +65 -32
- 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/index.ts +2 -2
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/utils/index.ts +74 -13
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-framework/react/app.ts +15 -10
- package/dist/runtime-framework/react/hooks.ts +0 -1
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +217 -80
- package/dist/runtime-framework/react/page.ts +4 -9
- package/dist/runtime-framework/react/utils/index.ts +3 -3
- package/dist/runtime-framework/solid/app.ts +30 -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 +85 -31
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- 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 +618 -245
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +618 -245
- 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-ets/utils/bind.ts +0 -24
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { Current, document, requestAnimationFrame, TaroElement, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
|
|
2
|
-
import { CONTEXT_ACTIONS, env, eventCenter, TFunc } 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
|
|
@@ -30,10 +29,11 @@ interface InitNativeComponentEntryParams {
|
|
|
30
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
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
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
202
|
+
app?.appendChild(nativeApp)
|
|
157
203
|
app = nativeApp
|
|
158
204
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
@@ -201,12 +266,16 @@ export function createNativePageConfig (Component, pageName: string, react: type
|
|
|
201
266
|
const pageObj: Record<string, any> = {
|
|
202
267
|
options: pageConfig,
|
|
203
268
|
[ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: TFunc) {
|
|
204
|
-
hasLoaded = new Promise(resolve => {
|
|
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
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
|
|
@@ -184,6 +177,8 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
|
|
|
184
177
|
safeExecute(this.$taroPath, ON_READY)
|
|
185
178
|
// 通过事件触发子组件的生命周期
|
|
186
179
|
requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
|
|
180
|
+
this.onReady = {}
|
|
181
|
+
this.onReady.called = true
|
|
187
182
|
})
|
|
188
183
|
},
|
|
189
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 =
|
|
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,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createComponent, h, render } from '@tarojs/plugin-framework-solid/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 {
|
|
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:
|
|
21
|
+
export function createSolidApp(App: SolidComponent, config: AppConfig) {
|
|
23
22
|
setReconciler()
|
|
24
23
|
|
|
25
24
|
if (ReactMeta.PageContext === EMPTY_OBJ) {
|
|
@@ -32,13 +31,10 @@ export function createSolidApp(App: Component, config: AppConfig) {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
function renderReactRoot() {
|
|
35
|
-
|
|
36
|
-
if (isWeb) {
|
|
37
|
-
appId = config?.appId || appId
|
|
38
|
-
}
|
|
34
|
+
const appId = config?.appId || 'app'
|
|
39
35
|
|
|
40
36
|
if (ReactMeta.Container === EMPTY_OBJ) {
|
|
41
|
-
const Container = document.
|
|
37
|
+
const Container = document.getElementById(appId)
|
|
42
38
|
|
|
43
39
|
Container.id = appId
|
|
44
40
|
ReactMeta.Container = Container
|
|
@@ -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
|
|
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
|
|
58
|
+
createComponent(ReactMeta.PageContext.Provider as unknown as SolidComponent, {
|
|
62
59
|
value: id,
|
|
63
60
|
children: () => {
|
|
64
61
|
injectPageInstance(
|
|
@@ -71,38 +68,33 @@ export function createSolidApp(App: Component, config: AppConfig) {
|
|
|
71
68
|
},
|
|
72
69
|
})
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
return h(
|
|
72
|
+
'taro-page',
|
|
73
|
+
{ id, className: 'taro_page' },
|
|
74
|
+
children
|
|
75
|
+
)
|
|
79
76
|
},
|
|
80
77
|
}),
|
|
81
78
|
})
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
renderReactRoot()
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const [ONLAUNCH, ONSHOW, ONHIDE] = hooks.call('getMiniLifecycleImpl')!.app
|
|
81
|
+
renderReactRoot()
|
|
89
82
|
|
|
90
|
-
const
|
|
83
|
+
const app: AppInstance = Object.create(
|
|
91
84
|
{
|
|
92
|
-
mount(component:
|
|
85
|
+
mount(component: SolidComponent, id: string, cb: () => void) {
|
|
93
86
|
setPages((old) => [
|
|
94
87
|
...old,
|
|
95
88
|
{ id, component },
|
|
96
89
|
])
|
|
97
90
|
batch(cb)
|
|
98
91
|
},
|
|
99
|
-
|
|
100
92
|
unmount(id: string, cb: () => void) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
)
|
|
93
|
+
const idx = elements().findIndex((item) => item.id === id)
|
|
94
|
+
setElements((old) => {
|
|
95
|
+
old.splice(idx, 1)
|
|
96
|
+
return old
|
|
97
|
+
})
|
|
106
98
|
batch(cb)
|
|
107
99
|
},
|
|
108
100
|
},
|
|
@@ -112,15 +104,10 @@ export function createSolidApp(App: Component, config: AppConfig) {
|
|
|
112
104
|
value: config,
|
|
113
105
|
}),
|
|
114
106
|
|
|
115
|
-
|
|
107
|
+
onLaunch: setDefaultDescriptor({
|
|
116
108
|
value(options) {
|
|
117
109
|
setRouterParams(options)
|
|
118
110
|
|
|
119
|
-
if (isWeb) {
|
|
120
|
-
// 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后执行 render
|
|
121
|
-
renderReactRoot()
|
|
122
|
-
}
|
|
123
|
-
|
|
124
111
|
const onLaunch = () => {
|
|
125
112
|
const app = getAppInstance()
|
|
126
113
|
|
|
@@ -151,28 +138,25 @@ export function createSolidApp(App: Component, config: AppConfig) {
|
|
|
151
138
|
|
|
152
139
|
onLaunch()
|
|
153
140
|
triggerAppHook('onLaunch', options)
|
|
141
|
+
eventCenter.trigger('__taroRouterLaunch', options)
|
|
154
142
|
},
|
|
155
143
|
}),
|
|
156
|
-
|
|
157
|
-
[ONSHOW]: setDefaultDescriptor({
|
|
144
|
+
onShow: setDefaultDescriptor({
|
|
158
145
|
value(options) {
|
|
159
146
|
setRouterParams(options)
|
|
160
147
|
triggerAppHook('onShow', options)
|
|
161
148
|
},
|
|
162
149
|
}),
|
|
163
|
-
|
|
164
|
-
[ONHIDE]: setDefaultDescriptor({
|
|
150
|
+
onHide: setDefaultDescriptor({
|
|
165
151
|
value() {
|
|
166
152
|
triggerAppHook('onHide')
|
|
167
153
|
},
|
|
168
154
|
}),
|
|
169
|
-
|
|
170
155
|
onError: setDefaultDescriptor({
|
|
171
156
|
value(error: string) {
|
|
172
157
|
triggerAppHook('onError', error)
|
|
173
158
|
},
|
|
174
159
|
}),
|
|
175
|
-
|
|
176
160
|
onPageNotFound: setDefaultDescriptor({
|
|
177
161
|
value(res: unknown) {
|
|
178
162
|
triggerAppHook('onPageNotFound', res)
|
|
@@ -195,6 +179,6 @@ export function createSolidApp(App: Component, config: AppConfig) {
|
|
|
195
179
|
}
|
|
196
180
|
}
|
|
197
181
|
|
|
198
|
-
Current.app =
|
|
199
|
-
return
|
|
182
|
+
Current.app = app
|
|
183
|
+
return app
|
|
200
184
|
}
|