@tarojs/plugin-platform-harmony-ets 4.0.0-beta.1 → 4.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apis/device/memory.ts +10 -3
- package/dist/apis/index.ts +2 -0
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +124 -60
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/components-harmony-ets/button.ets +22 -71
- package/dist/components-harmony-ets/checkbox.ets +22 -138
- package/dist/components-harmony-ets/form.ets +29 -76
- package/dist/components-harmony-ets/icon.ets +5 -67
- package/dist/components-harmony-ets/image.ets +2 -66
- package/dist/components-harmony-ets/innerHtml.ets +2 -2
- package/dist/components-harmony-ets/input.ets +2 -61
- package/dist/components-harmony-ets/label.ets +40 -81
- package/dist/components-harmony-ets/picker.ets +31 -140
- package/dist/components-harmony-ets/radio.ets +22 -138
- package/dist/components-harmony-ets/richText.ets +4 -70
- package/dist/components-harmony-ets/scrollView.ets +34 -132
- package/dist/components-harmony-ets/slider.ets +4 -68
- package/dist/components-harmony-ets/style.ets +154 -0
- package/dist/components-harmony-ets/swiper.ets +4 -68
- package/dist/components-harmony-ets/switch.ets +4 -68
- package/dist/components-harmony-ets/text.ets +5 -69
- package/dist/components-harmony-ets/textArea.ets +2 -61
- package/dist/components-harmony-ets/utils/flexManager.ets +44 -6
- package/dist/components-harmony-ets/utils/helper.ets +2 -2
- package/dist/components-harmony-ets/utils/styles.ets +12 -1
- package/dist/components-harmony-ets/video.ets +4 -68
- package/dist/components-harmony-ets/view.ets +15 -125
- package/dist/components-harmony-ets/webView.ets +50 -0
- package/dist/index.js +87 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/window.ts +2 -2
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +23 -3
- package/dist/runtime-ets/dom/document.ts +21 -4
- package/dist/runtime-ets/dom/element/index.ts +4 -1
- package/dist/runtime-ets/dom/element/normal.ts +1 -0
- package/dist/runtime-ets/dom/element/webView.ts +61 -0
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +73 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +3 -1
- package/dist/runtime-ets/index.ts +1 -2
- package/dist/runtime-ets/utils/index.ts +4 -1
- package/dist/runtime-framework/react/app.ts +12 -22
- package/dist/runtime-framework/react/hooks.ts +3 -3
- package/dist/runtime-framework/react/index.ts +1 -0
- package/dist/runtime-framework/react/native-page.ts +344 -0
- package/dist/runtime-framework/react/page.ts +2 -2
- package/dist/runtime-framework/solid/hooks.ts +3 -3
- package/dist/runtime-utils.js +134 -68
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +134 -68
- package/dist/runtime.js.map +1 -1
- package/package.json +10 -10
- package/types/runtime.d.ts +2 -0
- package/dist/runtime-ets/utils/bind.ts +0 -24
|
@@ -0,0 +1,344 @@
|
|
|
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
|
|
3
|
+
import { ensure, hooks, isUndefined } from '@tarojs/shared'
|
|
4
|
+
|
|
5
|
+
import { ReactMeta as reactMeta } from './app'
|
|
6
|
+
import { setReconciler } from './connect'
|
|
7
|
+
import { ON_HIDE, ON_READY, ON_SHOW } from './constant'
|
|
8
|
+
import {
|
|
9
|
+
addLeadingSlash,
|
|
10
|
+
getOnHideEventKey,
|
|
11
|
+
getOnReadyEventKey,
|
|
12
|
+
getOnShowEventKey,
|
|
13
|
+
getPath,
|
|
14
|
+
injectPageInstance,
|
|
15
|
+
removePageInstance,
|
|
16
|
+
safeExecute
|
|
17
|
+
} from './page'
|
|
18
|
+
import { EMPTY_OBJ, incrementId, isClassComponent } from './utils'
|
|
19
|
+
|
|
20
|
+
import type { AppInstance } from '@tarojs/taro'
|
|
21
|
+
import type * as React from 'react'
|
|
22
|
+
|
|
23
|
+
const getNativeCompId = incrementId()
|
|
24
|
+
let h: typeof React.createElement
|
|
25
|
+
let ReactDOM
|
|
26
|
+
let nativeComponentApp: AppInstance
|
|
27
|
+
interface InitNativeComponentEntryParams {
|
|
28
|
+
R: typeof React
|
|
29
|
+
ReactDOM: typeof ReactDOM
|
|
30
|
+
cb?: TFunc
|
|
31
|
+
// 是否使用默认的 DOM 入口 - app;默认为true,false的时候,会创建一个新的dom并且把它挂载在 app 下面
|
|
32
|
+
isDefaultEntryDom?: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
|
|
36
|
+
const { R, ReactDOM, cb, isDefaultEntryDom = true } = params
|
|
37
|
+
interface IEntryState {
|
|
38
|
+
components: {
|
|
39
|
+
compId: string
|
|
40
|
+
element: React.ReactElement
|
|
41
|
+
}[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface IWrapperProps {
|
|
45
|
+
compId: string
|
|
46
|
+
getCtx: () => any
|
|
47
|
+
renderComponent: (ctx: any) => React.ReactElement
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class NativeComponentWrapper extends R.Component<IWrapperProps, Record<any, any>> {
|
|
51
|
+
root = R.createRef<TaroElement>()
|
|
52
|
+
ctx = this.props.getCtx()
|
|
53
|
+
|
|
54
|
+
componentDidMount () {
|
|
55
|
+
this.ctx.component = this
|
|
56
|
+
const rootElement = this.root.current!
|
|
57
|
+
rootElement.ctx = this.ctx
|
|
58
|
+
// TODO: performUpdate
|
|
59
|
+
// rootElement.performUpdate(true)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
render () {
|
|
63
|
+
return (
|
|
64
|
+
h(
|
|
65
|
+
'view',
|
|
66
|
+
{
|
|
67
|
+
ref: this.root,
|
|
68
|
+
id: this.props.compId
|
|
69
|
+
},
|
|
70
|
+
this.props.renderComponent(this.ctx)
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class Entry extends R.Component<Record<any, any>, IEntryState> {
|
|
77
|
+
state: IEntryState = {
|
|
78
|
+
components: []
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
componentDidMount () {
|
|
82
|
+
if (isDefaultEntryDom) {
|
|
83
|
+
Current.app = this
|
|
84
|
+
} else {
|
|
85
|
+
nativeComponentApp = this
|
|
86
|
+
}
|
|
87
|
+
cb && cb()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
mount (Component, compId, getCtx, cb?) {
|
|
91
|
+
const isReactComponent = isClassComponent(R, Component)
|
|
92
|
+
const inject = (node?: any) => node && injectPageInstance(node, compId)
|
|
93
|
+
const refs = isReactComponent ? { ref: inject } : {
|
|
94
|
+
forwardedRef: inject,
|
|
95
|
+
reactReduxForwardedRef: inject
|
|
96
|
+
}
|
|
97
|
+
if (reactMeta.PageContext === EMPTY_OBJ) {
|
|
98
|
+
reactMeta.PageContext = R.createContext('')
|
|
99
|
+
}
|
|
100
|
+
const item = {
|
|
101
|
+
compId,
|
|
102
|
+
element: h(NativeComponentWrapper, {
|
|
103
|
+
key: compId,
|
|
104
|
+
compId,
|
|
105
|
+
getCtx,
|
|
106
|
+
renderComponent (ctx) {
|
|
107
|
+
return h(
|
|
108
|
+
reactMeta.PageContext.Provider,
|
|
109
|
+
{ value: compId },
|
|
110
|
+
h(
|
|
111
|
+
Component,
|
|
112
|
+
{
|
|
113
|
+
// TODO: 传递 Props
|
|
114
|
+
...(ctx.props || {}),
|
|
115
|
+
...refs,
|
|
116
|
+
$scope: ctx
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
this.setState({
|
|
124
|
+
components: [...this.state.components, item]
|
|
125
|
+
}, () => cb && cb())
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
unmount (compId, cb?) {
|
|
129
|
+
const components = this.state.components
|
|
130
|
+
const index = components.findIndex(item => item.compId === compId)
|
|
131
|
+
const next = [...components.slice(0, index), ...components.slice(index + 1)]
|
|
132
|
+
this.setState({
|
|
133
|
+
components: next
|
|
134
|
+
}, () => {
|
|
135
|
+
removePageInstance(compId)
|
|
136
|
+
cb && cb()
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
render () {
|
|
141
|
+
const components = this.state.components
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
components.map(({ element }) => element)
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
setReconciler(ReactDOM)
|
|
150
|
+
|
|
151
|
+
let app = document.getElementById('app')
|
|
152
|
+
if (!isDefaultEntryDom && !nativeComponentApp) {
|
|
153
|
+
// create
|
|
154
|
+
const nativeApp = document.createElement('nativeComponent')
|
|
155
|
+
// insert
|
|
156
|
+
app.appendChild(nativeApp)
|
|
157
|
+
app = nativeApp
|
|
158
|
+
}
|
|
159
|
+
// eslint-disable-next-line react/no-deprecated
|
|
160
|
+
ReactDOM.render(
|
|
161
|
+
h(Entry, {}),
|
|
162
|
+
app
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function createNativePageConfig (Component, pageName: string, react: typeof React, reactDOM: typeof ReactDOM, pageConfig) {
|
|
167
|
+
reactMeta.R = react
|
|
168
|
+
h = react.createElement
|
|
169
|
+
ReactDOM = reactDOM
|
|
170
|
+
setReconciler(ReactDOM)
|
|
171
|
+
const [
|
|
172
|
+
ONLOAD,
|
|
173
|
+
ONUNLOAD,
|
|
174
|
+
ONREADY,
|
|
175
|
+
ONSHOW,
|
|
176
|
+
ONHIDE,
|
|
177
|
+
LIFECYCLES,
|
|
178
|
+
SIDE_EFFECT_LIFECYCLES
|
|
179
|
+
] = hooks.call('getMiniLifecycleImpl')!.page
|
|
180
|
+
let unmounting = false
|
|
181
|
+
let prepareMountList: (() => void)[] = []
|
|
182
|
+
let pageElement: TaroElement | null = null
|
|
183
|
+
let loadResolver: (...args: unknown[]) => void
|
|
184
|
+
let hasLoaded: Promise<void>
|
|
185
|
+
const id = pageName ?? `taro_page_${getNativeCompId()}`
|
|
186
|
+
function setCurrentRouter (page) {
|
|
187
|
+
const router = page.route || page.__route__ || page.$taroPath
|
|
188
|
+
Current.router = {
|
|
189
|
+
params: page.$taroParams!,
|
|
190
|
+
path: addLeadingSlash(router),
|
|
191
|
+
$taroPath: page.$taroPath,
|
|
192
|
+
onReady: getOnReadyEventKey(id),
|
|
193
|
+
onShow: getOnShowEventKey(id),
|
|
194
|
+
onHide: getOnHideEventKey(id)
|
|
195
|
+
}
|
|
196
|
+
if (!isUndefined(page.exitState)) {
|
|
197
|
+
Current.router.exitState = page.exitState
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const pageObj: Record<string, any> = {
|
|
202
|
+
options: pageConfig,
|
|
203
|
+
[ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: TFunc) {
|
|
204
|
+
hasLoaded = new Promise(resolve => { loadResolver = resolve })
|
|
205
|
+
Current.page = this as any
|
|
206
|
+
this.config = pageConfig || {}
|
|
207
|
+
// this.$taroPath 是页面唯一标识
|
|
208
|
+
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() })
|
|
209
|
+
const $taroPath = this.$taroPath = getPath(id, uniqueOptions)
|
|
210
|
+
|
|
211
|
+
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
212
|
+
if (this.$taroParams == null) {
|
|
213
|
+
this.$taroParams = uniqueOptions
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
setCurrentRouter(this)
|
|
217
|
+
window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
|
|
218
|
+
|
|
219
|
+
const mountCallback = () => {
|
|
220
|
+
pageElement = document.getElementById($taroPath)
|
|
221
|
+
|
|
222
|
+
ensure(pageElement !== null, '没有找到页面实例。')
|
|
223
|
+
|
|
224
|
+
safeExecute($taroPath, ONLOAD, this.$taroParams)
|
|
225
|
+
loadResolver()
|
|
226
|
+
cb && cb(pageElement)
|
|
227
|
+
pageElement.ctx = this
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const mount = () => {
|
|
231
|
+
if (!Current.app) {
|
|
232
|
+
initNativeComponentEntry({
|
|
233
|
+
R: react,
|
|
234
|
+
ReactDOM,
|
|
235
|
+
cb: () => {
|
|
236
|
+
Current.app!.mount!(Component, $taroPath, () => this, mountCallback)
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
} else {
|
|
240
|
+
Current.app!.mount!(Component, $taroPath, () => this, mountCallback)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (unmounting) {
|
|
245
|
+
prepareMountList.push(mount)
|
|
246
|
+
} else {
|
|
247
|
+
mount()
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
[ONUNLOAD] () {
|
|
251
|
+
const $taroPath = this.$taroPath
|
|
252
|
+
// 销毁当前页面的上下文信息
|
|
253
|
+
window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
|
|
254
|
+
// 触发onUnload生命周期
|
|
255
|
+
safeExecute($taroPath, ONUNLOAD)
|
|
256
|
+
resetCurrent()
|
|
257
|
+
unmounting = true
|
|
258
|
+
Current.app!.unmount!($taroPath, () => {
|
|
259
|
+
unmounting = false
|
|
260
|
+
removePageInstance($taroPath)
|
|
261
|
+
if (pageElement) {
|
|
262
|
+
pageElement.ctx = null
|
|
263
|
+
pageElement = null
|
|
264
|
+
}
|
|
265
|
+
if (prepareMountList.length) {
|
|
266
|
+
prepareMountList.forEach(fn => fn())
|
|
267
|
+
prepareMountList = []
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
},
|
|
271
|
+
[ONREADY] () {
|
|
272
|
+
hasLoaded.then(() => {
|
|
273
|
+
// 触发生命周期
|
|
274
|
+
safeExecute(this.$taroPath, ON_READY)
|
|
275
|
+
// 通过事件触发子组件的生命周期
|
|
276
|
+
requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
|
|
277
|
+
this.onReady.called = true
|
|
278
|
+
})
|
|
279
|
+
},
|
|
280
|
+
[ONSHOW] (options = {}) {
|
|
281
|
+
hasLoaded.then(() => {
|
|
282
|
+
// 设置 Current 的 page 和 router
|
|
283
|
+
Current.page = this as any
|
|
284
|
+
setCurrentRouter(this)
|
|
285
|
+
// 恢复上下文信息
|
|
286
|
+
window.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath)
|
|
287
|
+
// 触发生命周期
|
|
288
|
+
safeExecute(this.$taroPath, ON_SHOW, options)
|
|
289
|
+
// 通过事件触发子组件的生命周期
|
|
290
|
+
requestAnimationFrame(() => eventCenter.trigger(getOnShowEventKey(id)))
|
|
291
|
+
})
|
|
292
|
+
},
|
|
293
|
+
[ONHIDE] () {
|
|
294
|
+
// 缓存当前页面上下文信息
|
|
295
|
+
window.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath)
|
|
296
|
+
// 设置 Current 的 page 和 router
|
|
297
|
+
if (Current.page === this) {
|
|
298
|
+
Current.page = null
|
|
299
|
+
Current.router = null
|
|
300
|
+
}
|
|
301
|
+
// 触发生命周期
|
|
302
|
+
safeExecute(this.$taroPath, ON_HIDE)
|
|
303
|
+
// 通过事件触发子组件的生命周期
|
|
304
|
+
eventCenter.trigger(getOnHideEventKey(id))
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function resetCurrent () {
|
|
309
|
+
// 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
|
|
310
|
+
Current.page = null
|
|
311
|
+
Current.router = null
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
LIFECYCLES.forEach((lifecycle) => {
|
|
316
|
+
pageObj[lifecycle] = function () {
|
|
317
|
+
return safeExecute(this.$taroPath, lifecycle, ...arguments)
|
|
318
|
+
}
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
|
|
322
|
+
SIDE_EFFECT_LIFECYCLES.forEach(lifecycle => {
|
|
323
|
+
if (Component[lifecycle] ||
|
|
324
|
+
Component.prototype?.[lifecycle] ||
|
|
325
|
+
Component[lifecycle.replace(/^on/, 'enable')]
|
|
326
|
+
) {
|
|
327
|
+
pageObj[lifecycle] = function (...args) {
|
|
328
|
+
const target = args[0]?.target
|
|
329
|
+
if (target?.id) {
|
|
330
|
+
const id = target.id
|
|
331
|
+
const element = env.document.getElementById(id)
|
|
332
|
+
if (element) {
|
|
333
|
+
target.dataset = element.dataset
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return safeExecute(this.$taroPath, lifecycle, ...args)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
hooks.call('modifyPageObject', pageObj)
|
|
342
|
+
|
|
343
|
+
return pageObj
|
|
344
|
+
}
|
|
@@ -136,7 +136,8 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
|
|
|
136
136
|
window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
|
|
137
137
|
|
|
138
138
|
const mount = () => {
|
|
139
|
-
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
Current.app!.mount!(component, $taroPath, null, () => {
|
|
140
141
|
pageElement = document.getElementById($taroPath)
|
|
141
142
|
|
|
142
143
|
if (!pageElement) {
|
|
@@ -183,7 +184,6 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
|
|
|
183
184
|
safeExecute(this.$taroPath, ON_READY)
|
|
184
185
|
// 通过事件触发子组件的生命周期
|
|
185
186
|
requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
|
|
186
|
-
this.onReady.called = true
|
|
187
187
|
})
|
|
188
188
|
},
|
|
189
189
|
[ONSHOW] (options = {}) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AppInstance,
|
|
3
3
|
Current,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
PageLifeCycle,
|
|
5
|
+
TFunc
|
|
6
6
|
} from '@tarojs/runtime'
|
|
7
7
|
import { isArray, isFunction } from '@tarojs/shared'
|
|
8
8
|
import {
|
|
@@ -16,7 +16,7 @@ import { getPageInstance, injectPageInstance } from './page'
|
|
|
16
16
|
import { HOOKS_APP_ID } from './utils'
|
|
17
17
|
|
|
18
18
|
const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
|
|
19
|
-
return (fn:
|
|
19
|
+
return (fn: TFunc) => {
|
|
20
20
|
const id = ReactMeta.PageContext || HOOKS_APP_ID
|
|
21
21
|
|
|
22
22
|
createRenderEffect(() => {
|
package/dist/runtime-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isFunction, isString, isArray, isObject, isNull, isNumber, isUndefined, queryToJson, PLATFORM_TYPE, singleQuote, internalComponents } from '@tarojs/shared';
|
|
2
2
|
import _display from '@ohos.display';
|
|
3
|
-
import { Current, window, document as document$1, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME
|
|
3
|
+
import { Current, window, hooks, document as document$1, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime';
|
|
4
4
|
import { eventCenter, Events, History } from '@tarojs/runtime/dist/runtime.esm';
|
|
5
5
|
import deviceInfo from '@ohos.deviceInfo';
|
|
6
6
|
import i18n from '@ohos.i18n';
|
|
@@ -736,8 +736,14 @@ const hideKeyboard = function (options) {
|
|
|
736
736
|
};
|
|
737
737
|
const getSelectedTextRange = /* @__PURE__ */ temporarilyNotSupport('getSelectedTextRange');
|
|
738
738
|
|
|
739
|
-
const onMemoryWarning =
|
|
740
|
-
|
|
739
|
+
const onMemoryWarning = (listener) => {
|
|
740
|
+
hooks.tap('getMemoryLevel', (res) => {
|
|
741
|
+
listener(res);
|
|
742
|
+
});
|
|
743
|
+
};
|
|
744
|
+
const offMemoryWarning = (listener) => {
|
|
745
|
+
hooks.off('getMemoryLevel', listener);
|
|
746
|
+
};
|
|
741
747
|
|
|
742
748
|
const stopDeviceMotionListening = temporarilyNotSupport('stopDeviceMotionListening');
|
|
743
749
|
const startDeviceMotionListening = temporarilyNotSupport('startDeviceMotionListening');
|
|
@@ -2605,10 +2611,10 @@ const request = function (options) {
|
|
|
2605
2611
|
header['Content-Type'] = 'application/json';
|
|
2606
2612
|
}
|
|
2607
2613
|
// 检查 Header 是否有 Referer
|
|
2608
|
-
if (isUndefined(header.Referer)) {
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
}
|
|
2614
|
+
// if (isUndefined(header.Referer)) {
|
|
2615
|
+
// const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' }
|
|
2616
|
+
// callAsyncFail(reject, error, options)
|
|
2617
|
+
// }
|
|
2612
2618
|
// 检查 method 是否正确
|
|
2613
2619
|
if (method) {
|
|
2614
2620
|
if (!METHOD.includes(method)) {
|
|
@@ -3054,6 +3060,19 @@ function parseURL(raw = '') {
|
|
|
3054
3060
|
const [urlStr, queryStr = ''] = raw.split('?');
|
|
3055
3061
|
const query = queryToJson(queryStr);
|
|
3056
3062
|
let url = urlStr.replace(/^\//, '');
|
|
3063
|
+
// 处理相对路径
|
|
3064
|
+
if (url.indexOf('.') === 0) {
|
|
3065
|
+
const page = router.getState();
|
|
3066
|
+
const parts = page.path.split('/');
|
|
3067
|
+
parts.pop();
|
|
3068
|
+
url.split('/').forEach((item) => {
|
|
3069
|
+
if (item === '.') {
|
|
3070
|
+
return;
|
|
3071
|
+
}
|
|
3072
|
+
item === '..' ? parts.pop() : parts.push(item);
|
|
3073
|
+
});
|
|
3074
|
+
url = parts.join('/');
|
|
3075
|
+
}
|
|
3057
3076
|
if (isTabPage(url)) {
|
|
3058
3077
|
query.$page = url;
|
|
3059
3078
|
url = TARO_TABBAR_PAGE_PATH;
|
|
@@ -3171,107 +3190,152 @@ const getBackgroundFetchData = /* @__PURE__ */ temporarilyNotSupport('getBackgro
|
|
|
3171
3190
|
// 周期性更新
|
|
3172
3191
|
const createCacheManager = /* @__PURE__ */ temporarilyNotSupport('createCacheManager');
|
|
3173
3192
|
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
.catch((error) => {
|
|
3184
|
-
hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error);
|
|
3193
|
+
/**
|
|
3194
|
+
* 从API Version 6开始,该模块不再维护,可以使用模块@ohos.data.storage。在API Version 9后,推荐使用新模块@ohos.data.preferences。
|
|
3195
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
|
|
3196
|
+
*/
|
|
3197
|
+
let context;
|
|
3198
|
+
let preferences;
|
|
3199
|
+
Current.contextPromise.then((ctx) => {
|
|
3200
|
+
context = ctx;
|
|
3201
|
+
return context;
|
|
3185
3202
|
});
|
|
3186
|
-
function
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
const
|
|
3190
|
-
|
|
3191
|
-
return { result: true, data: item };
|
|
3192
|
-
}
|
|
3193
|
-
catch (error) {
|
|
3194
|
-
return { result: false };
|
|
3203
|
+
function getPreferences() {
|
|
3204
|
+
try {
|
|
3205
|
+
if (!preferences) {
|
|
3206
|
+
const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
|
|
3207
|
+
preferences = dataPreferences.getPreferencesSync(context, { name: `${data.appInfo.uid}Store` });
|
|
3195
3208
|
}
|
|
3196
|
-
}
|
|
3209
|
+
}
|
|
3210
|
+
catch (error) {
|
|
3211
|
+
hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error);
|
|
3212
|
+
}
|
|
3213
|
+
return preferences;
|
|
3197
3214
|
}
|
|
3198
3215
|
const storageSchema = {
|
|
3199
3216
|
key: 'String'
|
|
3200
3217
|
};
|
|
3201
3218
|
function getStorage(options) {
|
|
3219
|
+
const { key, success, fail, complete } = options || {};
|
|
3220
|
+
const handle = new MethodHandler({ name: 'getStorage', success, fail, complete });
|
|
3202
3221
|
return new Promise((resolve, reject) => {
|
|
3203
3222
|
try {
|
|
3204
3223
|
validateParams('getStorage', options, storageSchema);
|
|
3205
3224
|
}
|
|
3206
3225
|
catch (error) {
|
|
3207
3226
|
const res = { errMsg: error.message };
|
|
3208
|
-
return
|
|
3227
|
+
return handle.fail(res, { resolve, reject });
|
|
3228
|
+
}
|
|
3229
|
+
const preferences = getPreferences();
|
|
3230
|
+
if (!preferences)
|
|
3231
|
+
return handle.fail({}, { resolve, reject });
|
|
3232
|
+
const data = preferences.getSync(key, null);
|
|
3233
|
+
if (data) {
|
|
3234
|
+
return handle.success({ data }, { resolve, reject });
|
|
3235
|
+
}
|
|
3236
|
+
else {
|
|
3237
|
+
return handle.success({ errMsg: 'data not found' }, { resolve, reject });
|
|
3209
3238
|
}
|
|
3210
|
-
getItem(options.key).then(({ result, data }) => {
|
|
3211
|
-
const res = { errMsg: 'getStorage:ok' };
|
|
3212
|
-
if (result) {
|
|
3213
|
-
res.data = data;
|
|
3214
|
-
callAsyncSuccess(resolve, res, options);
|
|
3215
|
-
}
|
|
3216
|
-
else {
|
|
3217
|
-
res.errMsg = 'getStorage:fail data not found';
|
|
3218
|
-
callAsyncFail(reject, res, options);
|
|
3219
|
-
}
|
|
3220
|
-
});
|
|
3221
3239
|
});
|
|
3222
3240
|
}
|
|
3241
|
+
function getStorageSync(key) {
|
|
3242
|
+
if (!key) {
|
|
3243
|
+
throw new Error('getStorageSync:fail parameter error: parameter should be String');
|
|
3244
|
+
}
|
|
3245
|
+
const preferences = getPreferences();
|
|
3246
|
+
if (!preferences) {
|
|
3247
|
+
throw new Error('getStorageSync:fail:preferences is null');
|
|
3248
|
+
}
|
|
3249
|
+
const data = preferences.getSync(key, null);
|
|
3250
|
+
if (data) {
|
|
3251
|
+
return data;
|
|
3252
|
+
}
|
|
3253
|
+
else {
|
|
3254
|
+
throw new Error('data not found');
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3223
3257
|
function setStorage(options) {
|
|
3258
|
+
const { key, data, success, fail, complete } = options || {};
|
|
3259
|
+
const handle = new MethodHandler({ name: 'setStorage', success, fail, complete });
|
|
3224
3260
|
return new Promise((resolve, reject) => {
|
|
3225
3261
|
try {
|
|
3226
3262
|
validateParams('setStorage', options, storageSchema);
|
|
3227
3263
|
}
|
|
3228
3264
|
catch (error) {
|
|
3229
3265
|
const res = { errMsg: error.message };
|
|
3230
|
-
return
|
|
3266
|
+
return handle.fail(res, { resolve, reject });
|
|
3231
3267
|
}
|
|
3232
|
-
const
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
}));
|
|
3268
|
+
const preferences = getPreferences();
|
|
3269
|
+
if (!preferences)
|
|
3270
|
+
return handle.fail({}, { resolve, reject });
|
|
3271
|
+
preferences.putSync(key, data);
|
|
3272
|
+
preferences.flush();
|
|
3273
|
+
return handle.success({}, { resolve, reject });
|
|
3239
3274
|
});
|
|
3240
3275
|
}
|
|
3276
|
+
function setStorageSync(key, data) {
|
|
3277
|
+
if (!key) {
|
|
3278
|
+
throw new Error('setStorageSync:fail key error: key should be String');
|
|
3279
|
+
}
|
|
3280
|
+
const preferences = getPreferences();
|
|
3281
|
+
if (!preferences) {
|
|
3282
|
+
throw new Error('setStorageSync:fail:preferences is null');
|
|
3283
|
+
}
|
|
3284
|
+
preferences.putSync(key, data);
|
|
3285
|
+
preferences.flush();
|
|
3286
|
+
}
|
|
3241
3287
|
function removeStorage(options) {
|
|
3288
|
+
const { key, success, fail, complete } = options || {};
|
|
3289
|
+
const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete });
|
|
3242
3290
|
return new Promise((resolve, reject) => {
|
|
3243
3291
|
try {
|
|
3244
3292
|
validateParams('removeStorage', options, storageSchema);
|
|
3245
3293
|
}
|
|
3246
3294
|
catch (error) {
|
|
3247
3295
|
const res = { errMsg: error.message };
|
|
3248
|
-
return
|
|
3296
|
+
return handle.fail(res, { resolve, reject });
|
|
3249
3297
|
}
|
|
3250
|
-
const
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
}));
|
|
3298
|
+
const preferences = getPreferences();
|
|
3299
|
+
if (!preferences)
|
|
3300
|
+
return handle.fail({}, { resolve, reject });
|
|
3301
|
+
preferences.deleteSync(key);
|
|
3302
|
+
preferences.flush();
|
|
3303
|
+
return handle.success({}, { resolve, reject });
|
|
3257
3304
|
});
|
|
3258
3305
|
}
|
|
3306
|
+
function removeStorageSync(key) {
|
|
3307
|
+
if (!key) {
|
|
3308
|
+
throw new Error('removeStorageSync:fail key error: key should be String');
|
|
3309
|
+
}
|
|
3310
|
+
const preferences = getPreferences();
|
|
3311
|
+
if (!preferences) {
|
|
3312
|
+
throw new Error('removeStorageSync:fail:preferences is null');
|
|
3313
|
+
}
|
|
3314
|
+
preferences.deleteSync(key);
|
|
3315
|
+
preferences.flush();
|
|
3316
|
+
}
|
|
3259
3317
|
function clearStorage(options) {
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3318
|
+
const { success, fail, complete } = options || {};
|
|
3319
|
+
const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete });
|
|
3320
|
+
return new Promise((resolve, reject) => {
|
|
3321
|
+
const preferences = getPreferences();
|
|
3322
|
+
if (!preferences)
|
|
3323
|
+
return handle.fail({}, { resolve, reject });
|
|
3324
|
+
preferences.clearSync();
|
|
3325
|
+
preferences.flush();
|
|
3326
|
+
return handle.success({}, { resolve, reject });
|
|
3267
3327
|
});
|
|
3268
3328
|
}
|
|
3329
|
+
function clearStorageSync() {
|
|
3330
|
+
const preferences = getPreferences();
|
|
3331
|
+
if (!preferences) {
|
|
3332
|
+
throw new Error('clearStorageSync:fail:preferences is null');
|
|
3333
|
+
}
|
|
3334
|
+
preferences.clearSync();
|
|
3335
|
+
preferences.flush();
|
|
3336
|
+
}
|
|
3269
3337
|
const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync');
|
|
3270
3338
|
const getStorageInfo = temporarilyNotSupport('getStorageInfo');
|
|
3271
|
-
const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
|
|
3272
|
-
const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
|
|
3273
|
-
const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
|
|
3274
|
-
const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage');
|
|
3275
3339
|
const createBufferURL = /* @__PURE__ */ temporarilyNotSupport('createBufferURL');
|
|
3276
3340
|
const revokeBufferURL = /* @__PURE__ */ temporarilyNotSupport('revokeBufferURL');
|
|
3277
3341
|
const batchSetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchSetStorageSync');
|
|
@@ -4274,6 +4338,7 @@ var apis = /*#__PURE__*/Object.freeze({
|
|
|
4274
4338
|
ENV_TYPE: ENV_TYPE,
|
|
4275
4339
|
Events: Events,
|
|
4276
4340
|
History: History,
|
|
4341
|
+
IntersectionObserver: IntersectionObserver,
|
|
4277
4342
|
addCard: addCard,
|
|
4278
4343
|
addFileToFavorites: addFileToFavorites,
|
|
4279
4344
|
addPhoneCalendar: addPhoneCalendar,
|
|
@@ -4663,7 +4728,7 @@ var apis = /*#__PURE__*/Object.freeze({
|
|
|
4663
4728
|
writeBLECharacteristicValue: writeBLECharacteristicValue
|
|
4664
4729
|
});
|
|
4665
4730
|
|
|
4666
|
-
Object.assign({}, apis);
|
|
4731
|
+
const taro = Object.assign({}, apis);
|
|
4667
4732
|
const requirePlugin = /* @__PURE__ */ permanentlyNotSupport('requirePlugin');
|
|
4668
4733
|
function initNativeApi(taro) {
|
|
4669
4734
|
Current.taro = taro;
|
|
@@ -4727,6 +4792,7 @@ function getAppInfo() {
|
|
|
4727
4792
|
designWidth: config === null || config === void 0 ? void 0 : config.designWidth,
|
|
4728
4793
|
};
|
|
4729
4794
|
}
|
|
4795
|
+
initNativeApi(taro);
|
|
4730
4796
|
|
|
4731
4797
|
const components = {
|
|
4732
4798
|
Checkbox: {
|