@tarojs/plugin-platform-harmony-ets 4.0.0-beta.4 → 4.0.0-beta.41
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 +53 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +32 -17
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +126 -68
- package/dist/apis/ui/animation/animation.ts +2 -1
- package/dist/apis/utils/index.ts +1 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/apis/wxml/selectorQuery.ts +18 -9
- package/dist/components-harmony-ets/button.ets +48 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +69 -61
- package/dist/components-harmony-ets/form.ets +51 -29
- package/dist/components-harmony-ets/icon.ets +34 -19
- package/dist/components-harmony-ets/image.ets +27 -14
- package/dist/components-harmony-ets/index.ets +76 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +41 -40
- package/dist/components-harmony-ets/label.ets +71 -42
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +73 -0
- package/dist/components-harmony-ets/picker.ets +42 -38
- 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 +71 -64
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollView.ets +64 -30
- package/dist/components-harmony-ets/slider.ets +15 -14
- package/dist/components-harmony-ets/style.ets +346 -130
- package/dist/components-harmony-ets/swiper.ets +38 -20
- package/dist/components-harmony-ets/switch.ets +30 -28
- package/dist/components-harmony-ets/text.ets +121 -51
- package/dist/components-harmony-ets/textArea.ets +35 -34
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
- package/dist/components-harmony-ets/utils/flexManager.ets +43 -19
- package/dist/components-harmony-ets/utils/helper.ets +4 -5
- 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 +50 -51
- package/dist/components-harmony-ets/utils/styles.ets +164 -92
- package/dist/components-harmony-ets/video.ets +34 -20
- 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 +74 -37
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +1 -1
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +7 -0
- package/dist/runtime-ets/current.ts +3 -0
- package/dist/runtime-ets/dom/bind.ts +20 -6
- package/dist/runtime-ets/dom/cssNesting.ts +393 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +12 -40
- package/dist/runtime-ets/dom/document.ts +23 -8
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +218 -51
- package/dist/runtime-ets/dom/element/form.ts +15 -18
- package/dist/runtime-ets/dom/element/index.ts +18 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
- package/dist/runtime-ets/dom/element/movableView.ts +193 -0
- package/dist/runtime-ets/dom/element/normal.ts +13 -4
- package/dist/runtime-ets/dom/element/progress.ts +12 -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 -3
- package/dist/runtime-ets/dom/element/webView.ts +8 -0
- package/dist/runtime-ets/dom/event.ts +0 -1
- package/dist/runtime-ets/dom/eventTarget.ts +0 -3
- package/dist/runtime-ets/dom/node.ts +45 -27
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +330 -230
- package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
- package/dist/runtime-ets/dom/stylesheet/type.ts +28 -9
- 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 +43 -10
- package/dist/runtime-ets/utils/info.ts +1 -1
- package/dist/runtime-framework/react/app.ts +7 -2
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +22 -12
- package/dist/runtime-framework/react/page.ts +3 -8
- package/dist/runtime-framework/solid/app.ts +25 -45
- 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 -30
- package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
- 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 +0 -2
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +284 -126
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +284 -126
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +13 -13
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/dist/runtime-ets/utils/bind.ts +0 -24
- /package/dist/components-harmony-ets/{index.ts → tag.ts} +0 -0
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
package/dist/apis/base/system.ts
CHANGED
|
@@ -1,24 +1,56 @@
|
|
|
1
|
+
import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'
|
|
1
2
|
// 设备信息,从 API Version 6 开始支持
|
|
2
3
|
import deviceInfo from '@ohos.deviceInfo'
|
|
3
4
|
// 显示设备属性,从 API Version 7 开始支持
|
|
4
5
|
import _display from '@ohos.display'
|
|
5
6
|
// 从 API Version 7 开始支持
|
|
6
7
|
import i18n from '@ohos.i18n'
|
|
7
|
-
|
|
8
|
-
import deviceMethod from '@system.device'
|
|
8
|
+
import { Current, window } from '@tarojs/runtime'
|
|
9
9
|
|
|
10
10
|
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
11
11
|
|
|
12
12
|
import type Taro from '@tarojs/taro/types'
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
let display
|
|
15
|
+
let navigationIndicatorRect
|
|
16
|
+
let safeArea: TaroGeneral.SafeAreaResult | null = null
|
|
17
|
+
let statusBarHeight
|
|
18
|
+
let windowRect
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
(Current as any).contextPromise.then((context) => {
|
|
21
|
+
const win = window.__ohos.getLastWindow(context)
|
|
22
|
+
win.then(mainWindow => {
|
|
23
|
+
const topRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_SYSTEM).topRect
|
|
24
|
+
navigationIndicatorRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect
|
|
25
|
+
statusBarHeight = topRect.top + topRect.height
|
|
26
|
+
windowRect = mainWindow.getWindowProperties().windowRect
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
try {
|
|
29
|
+
display = _display.getDefaultDisplaySync()
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} }: _display.CutoutInfo = {}) => {
|
|
32
|
+
if (err?.code) {
|
|
33
|
+
console.error('Failed to get cutout info', JSON.stringify(err))
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const top = Math.max(...boundingRects.map(rect => rect.top + rect.height), waterfallDisplayAreaRects.top?.top + waterfallDisplayAreaRects.top?.height, statusBarHeight)
|
|
38
|
+
const bottom = display.height - Math.min(waterfallDisplayAreaRects.bottom?.top, navigationIndicatorRect?.top)
|
|
39
|
+
const left = waterfallDisplayAreaRects.left?.left + waterfallDisplayAreaRects.left?.width
|
|
40
|
+
const right = display.width - waterfallDisplayAreaRects.right?.left
|
|
41
|
+
safeArea = {
|
|
42
|
+
top,
|
|
43
|
+
bottom,
|
|
44
|
+
left,
|
|
45
|
+
right,
|
|
46
|
+
height: bottom - top,
|
|
47
|
+
width: right - left,
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error('Failed to get display', e)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
22
54
|
})
|
|
23
55
|
|
|
24
56
|
/* 同步版本 */
|
|
@@ -32,7 +64,7 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
|
32
64
|
res.cameraAuthorized = null // 允许使用摄像头的开关 boolean
|
|
33
65
|
res.enableDebug = null // 是否已打开调试 boolean
|
|
34
66
|
res.fontSizeSetting = null // 用户字体大小(单位px) number
|
|
35
|
-
res.language = i18n
|
|
67
|
+
res.language = i18n?.getSystemLanguage?.() // string
|
|
36
68
|
res.locationAuthorized = null // 定位的开关 boolean
|
|
37
69
|
res.locationEnabled = null // 地理位置的系统开关 boolean
|
|
38
70
|
res.microphoneAuthorized = null // 麦克风的开关 boolean
|
|
@@ -43,17 +75,18 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
|
43
75
|
res.notificationSoundAuthorized = false // 通知带有声音的开关(仅 iOS 有效)boolean
|
|
44
76
|
res.phoneCalendarAuthorized = null // 使用日历的开关 boolean
|
|
45
77
|
res.wifiEnabled = false // Wi-Fi 的系统开关 boolean
|
|
46
|
-
res.pixelRatio =
|
|
47
|
-
res.platform = '
|
|
48
|
-
res.safeArea =
|
|
49
|
-
res.screenHeight = display
|
|
50
|
-
res.screenWidth = display
|
|
51
|
-
res.statusBarHeight =
|
|
52
|
-
res.system = deviceInfo
|
|
53
|
-
|
|
54
|
-
res.
|
|
55
|
-
res.windowHeight =
|
|
56
|
-
res.
|
|
78
|
+
res.pixelRatio = display && display.densityPixels // 设备像素比,number
|
|
79
|
+
res.platform = 'harmony' // 客户端平台 string
|
|
80
|
+
res.safeArea = safeArea // 在竖屏正方向下的安全区域 General.SafeAreaResult
|
|
81
|
+
res.screenHeight = display?.height // 屏幕高度,单位px number
|
|
82
|
+
res.screenWidth = display?.width // 屏幕宽度,单位px number
|
|
83
|
+
res.statusBarHeight = statusBarHeight // 状态栏的高度,单位px number
|
|
84
|
+
res.system = deviceInfo?.osFullName // 操作系统及版本 string
|
|
85
|
+
// Note: 更新配置时才能记录
|
|
86
|
+
res.theme = AppStorage.get('__TARO_APP_CONFIG')?.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light' // 系统当前主题,取值为light或dark 'light' | 'dark'
|
|
87
|
+
res.windowHeight = windowRect?.height // 可使用窗口高度,单位px number
|
|
88
|
+
res.windowWidth = windowRect?.width // 可使用窗口宽度,单位px number
|
|
89
|
+
res.version = deviceInfo?.displayVersion // 版本号 string
|
|
57
90
|
|
|
58
91
|
return res
|
|
59
92
|
}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
import { eventSource } from '@tarojs/runtime'
|
|
2
|
+
|
|
1
3
|
import { temporarilyNotSupport } from '../utils'
|
|
2
4
|
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import type { TaroCanvasElement } from '@tarojs/runtime'
|
|
3
7
|
// 画布
|
|
4
8
|
|
|
5
9
|
/** 创建离屏 canvas 实例 */
|
|
6
10
|
export const createOffscreenCanvas = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
7
11
|
|
|
8
12
|
/** 创建 canvas 的绘图上下文 CanvasContext 对象 */
|
|
9
|
-
export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
13
|
+
// export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
14
|
+
export const createCanvasContext = (canvasId: string) => {
|
|
15
|
+
const dom = eventSource.get(`canvasId-${canvasId}`)
|
|
16
|
+
// return dom as TaroCanvasElement
|
|
17
|
+
if (dom) return (dom as unknown as TaroCanvasElement).context
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
/** 把当前画布指定区域的内容导出生成指定大小的图片 */
|
|
12
21
|
export const canvasToTempFilePath = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Current } from '@tarojs/runtime'
|
|
2
|
-
|
|
3
1
|
import { temporarilyNotSupport } from '../utils'
|
|
4
2
|
|
|
5
3
|
export const ENV_TYPE = {
|
|
@@ -19,12 +17,10 @@ export function getEnv () {
|
|
|
19
17
|
return ENV_TYPE.HARMONY
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
export { Current }
|
|
23
|
-
|
|
24
20
|
// TODO
|
|
25
21
|
export const getCurrentPages = () => []
|
|
26
22
|
|
|
27
|
-
export
|
|
23
|
+
export { Current, getCurrentInstance } from '@tarojs/runtime'
|
|
28
24
|
|
|
29
25
|
export const requirePlugin = temporarilyNotSupport('requirePlugin')
|
|
30
26
|
|
package/dist/apis/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ const defaultUnitPrecision = 5
|
|
|
33
33
|
const defaultTargetUnit = 'vp'
|
|
34
34
|
|
|
35
35
|
export function getApp () {
|
|
36
|
-
return Current.app
|
|
36
|
+
return Current.app || {}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function initPxTransform ({
|
|
@@ -58,20 +58,30 @@ export function initPxTransform ({
|
|
|
58
58
|
|
|
59
59
|
const display = _display.getDefaultDisplaySync()
|
|
60
60
|
|
|
61
|
+
let displayWidth = display.width
|
|
62
|
+
let ratioCache: number | false = false
|
|
61
63
|
let designWidthFunc: (input: number) => number
|
|
64
|
+
let designWidth = defaultDesignWidth
|
|
65
|
+
let deviceRatio = defaultDesignRatio
|
|
62
66
|
function getRatio (value: number) {
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
// Note: 提前调用 display 可能无法获取正确值
|
|
68
|
+
if (ratioCache === false || displayWidth !== display.width) {
|
|
69
|
+
const config = (Current as any).taro?.config || {}
|
|
70
|
+
if (!isFunction(designWidthFunc)) {
|
|
71
|
+
designWidthFunc = isFunction(config.designWidth)
|
|
72
|
+
? config.designWidth
|
|
73
|
+
: () => config.designWidth
|
|
74
|
+
designWidth = designWidthFunc(value) || defaultDesignWidth
|
|
75
|
+
deviceRatio = config.deviceRatio || defaultDesignRatio
|
|
76
|
+
if (!(designWidth in deviceRatio)) {
|
|
77
|
+
throw new Error(`deviceRatio 配置中不存在 ${designWidth} 的设置!`)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
displayWidth = display.width
|
|
81
|
+
ratioCache = Math.min(display.width, display.height) / designWidth
|
|
73
82
|
}
|
|
74
|
-
|
|
83
|
+
|
|
84
|
+
return ratioCache
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
// Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
|
|
@@ -79,6 +89,9 @@ export function pxTransformHelper (size: number, unit?: string, isNumber = false
|
|
|
79
89
|
const config = (Current as any).taro?.config || {}
|
|
80
90
|
const targetUnit = unit || config.targetUnit || defaultTargetUnit
|
|
81
91
|
|
|
92
|
+
if (targetUnit === 'PX') {
|
|
93
|
+
return px2vp(size * display.scaledDensity) + 'vp'
|
|
94
|
+
}
|
|
82
95
|
const ratio = getRatio(size)
|
|
83
96
|
let val = size * ratio
|
|
84
97
|
|
|
@@ -92,19 +105,19 @@ export function pxTransformHelper (size: number, unit?: string, isNumber = false
|
|
|
92
105
|
return isNumber ? val : val + targetUnit
|
|
93
106
|
}
|
|
94
107
|
|
|
95
|
-
export function pxTransform (size: number): number {
|
|
108
|
+
export function pxTransform (size: number): number | string {
|
|
96
109
|
const config = (Current as any).taro?.config || {}
|
|
97
110
|
const targetUnit = config.targetUnit || defaultTargetUnit
|
|
98
111
|
|
|
99
|
-
|
|
112
|
+
const val = size
|
|
100
113
|
switch (targetUnit) {
|
|
101
114
|
case 'vp':
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
return pxTransformHelper(size, 'px')
|
|
116
|
+
// return `${size}lpx`
|
|
104
117
|
default:
|
|
105
118
|
// NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
|
|
106
119
|
}
|
|
107
|
-
return val +
|
|
120
|
+
return val + targetUnit
|
|
108
121
|
}
|
|
109
122
|
|
|
110
123
|
export function canIUseWebp () {
|
|
@@ -120,5 +133,7 @@ export function getAppInfo () {
|
|
|
120
133
|
}
|
|
121
134
|
}
|
|
122
135
|
|
|
136
|
+
initNativeApi(taro)
|
|
137
|
+
|
|
123
138
|
export * from './apis'
|
|
124
139
|
export default taro
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// ✅ RequestTask.onHeadersReceived
|
|
7
7
|
|
|
8
8
|
import http from '@ohos.net.http'
|
|
9
|
-
import { isString
|
|
9
|
+
import { isString } from '@tarojs/shared'
|
|
10
10
|
|
|
11
11
|
import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
|
|
12
12
|
|
|
@@ -59,10 +59,10 @@ export const request: typeof Taro.request = function (options) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// 检查 Header 是否有 Referer
|
|
62
|
-
if (isUndefined(header.Referer)) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
62
|
+
// if (isUndefined(header.Referer)) {
|
|
63
|
+
// const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' }
|
|
64
|
+
// callAsyncFail(reject, error, options)
|
|
65
|
+
// }
|
|
66
66
|
|
|
67
67
|
// 检查 method 是否正确
|
|
68
68
|
if (method) {
|
package/dist/apis/route/index.ts
CHANGED
|
@@ -16,6 +16,21 @@ function parseURL (raw = ''): [string, Record<string, unknown>] {
|
|
|
16
16
|
const [urlStr, queryStr = ''] = raw.split('?')
|
|
17
17
|
const query: Record<string, unknown> = queryToJson(queryStr)
|
|
18
18
|
let url = urlStr.replace(/^\//, '')
|
|
19
|
+
|
|
20
|
+
// 处理相对路径
|
|
21
|
+
if (url.indexOf('.') === 0) {
|
|
22
|
+
const page = router.getState()
|
|
23
|
+
const parts = page.path.split('/')
|
|
24
|
+
parts.pop()
|
|
25
|
+
url.split('/').forEach((item) => {
|
|
26
|
+
if (item === '.') {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
item === '..' ? parts.pop() : parts.push(item)
|
|
30
|
+
})
|
|
31
|
+
url = parts.join('/')
|
|
32
|
+
}
|
|
33
|
+
|
|
19
34
|
if (isTabPage(url)) {
|
|
20
35
|
query.$page = url
|
|
21
36
|
url = TARO_TABBAR_PAGE_PATH
|
|
@@ -3,114 +3,171 @@
|
|
|
3
3
|
* https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
|
|
4
4
|
*/
|
|
5
5
|
import bundleManager from '@ohos.bundle.bundleManager'
|
|
6
|
-
import
|
|
7
|
-
import hilog from '@ohos.hilog'
|
|
6
|
+
import distributedKVStore from '@ohos.data.distributedKVStore'
|
|
8
7
|
import { Current } from '@tarojs/runtime'
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { temporarilyNotSupport, validateParams } from '../utils'
|
|
10
|
+
import { MethodHandler } from '../utils/handler'
|
|
11
11
|
|
|
12
12
|
import type Taro from '@tarojs/taro/types'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error)
|
|
25
|
-
})
|
|
14
|
+
let context
|
|
15
|
+
let kvManager: distributedKVStore.KVManager
|
|
16
|
+
let kvStore: distributedKVStore.SingleKVStore
|
|
17
|
+
|
|
18
|
+
(Current as any).contextPromise.then((ctx) => {
|
|
19
|
+
context = ctx
|
|
20
|
+
const kvManagerConfig: distributedKVStore.KVManagerConfig = {
|
|
21
|
+
context: context,
|
|
22
|
+
bundleName: 'com.example.taro'
|
|
23
|
+
}
|
|
26
24
|
|
|
27
|
-
async function getItem (key: string): Promise<{ result: boolean, data?: number | string | boolean }> {
|
|
28
25
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
// 创建KVManager实例
|
|
27
|
+
kvManager = distributedKVStore.createKVManager(kvManagerConfig)
|
|
28
|
+
// 继续创建获取数据库
|
|
29
|
+
const options: distributedKVStore.Options = {
|
|
30
|
+
createIfMissing: true,
|
|
31
|
+
encrypt: false,
|
|
32
|
+
backup: false,
|
|
33
|
+
autoSync: false,
|
|
34
|
+
// kvStoreType不填时,默认创建多设备协同数据库
|
|
35
|
+
kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
|
|
36
|
+
// 多设备协同数据库:kvStoreType: distributedKVStore.KVStoreType.DEVICE_COLLABORATION,
|
|
37
|
+
securityLevel: distributedKVStore.SecurityLevel.S1
|
|
38
|
+
}
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
|
|
41
|
+
kvManager.getKVStore<distributedKVStore.SingleKVStore>(`${data.appInfo.uid}Store`, options, (err, store: distributedKVStore.SingleKVStore) => {
|
|
42
|
+
if (err) {
|
|
43
|
+
console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
kvStore = store
|
|
47
|
+
// 请确保获取到键值数据库实例后,再进行相关数据操作
|
|
48
|
+
})
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.error(`Failed to create KVManager. Code:${e.code},message:${e.message}`)
|
|
35
51
|
}
|
|
36
|
-
|
|
52
|
+
|
|
53
|
+
return context
|
|
54
|
+
})
|
|
37
55
|
|
|
38
56
|
const storageSchema = {
|
|
39
57
|
key: 'String'
|
|
40
58
|
}
|
|
41
59
|
|
|
60
|
+
function checkContextExist (api: string, isAsync = false) {
|
|
61
|
+
if (!context || !kvStore) {
|
|
62
|
+
const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`
|
|
63
|
+
if (isAsync) {
|
|
64
|
+
return {
|
|
65
|
+
isExist: false,
|
|
66
|
+
error: Promise.reject(new Error(message))
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
console.warn(message)
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
isExist: false,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
isExist: true,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
42
82
|
export function getStorage<T = any> (options: Taro.getStorage.Option<T>) {
|
|
83
|
+
const name = 'getStorage'
|
|
84
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
85
|
+
|
|
86
|
+
if (!isExist) {
|
|
87
|
+
return error
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { key, success, fail, complete } = options || {}
|
|
91
|
+
const handle = new MethodHandler<{data: any}>({ name, success, fail, complete })
|
|
92
|
+
|
|
43
93
|
return new Promise((resolve, reject) => {
|
|
44
94
|
try {
|
|
45
|
-
validateParams(
|
|
95
|
+
validateParams(name, options, storageSchema)
|
|
46
96
|
} catch (error) {
|
|
47
97
|
const res = { errMsg: error.message }
|
|
48
|
-
return
|
|
98
|
+
return handle.fail(res, { resolve, reject })
|
|
49
99
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} else {
|
|
57
|
-
res.errMsg = 'getStorage:fail data not found'
|
|
58
|
-
callAsyncFail(reject, res, options)
|
|
100
|
+
|
|
101
|
+
kvStore = kvStore as distributedKVStore.SingleKVStore
|
|
102
|
+
kvStore.get(key, (err, data) => {
|
|
103
|
+
if (!err) {
|
|
104
|
+
handle.fail({ errMsg: `Failed to get data. Code:${err.code},message:${err.message}` }, { resolve, reject })
|
|
105
|
+
return
|
|
59
106
|
}
|
|
107
|
+
|
|
108
|
+
handle.success({ data }, { resolve, reject })
|
|
60
109
|
})
|
|
61
110
|
})
|
|
62
111
|
}
|
|
63
112
|
|
|
64
113
|
export function setStorage (options: Taro.setStorage.Option) {
|
|
114
|
+
const name = 'setStorage'
|
|
115
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
116
|
+
|
|
117
|
+
if (!isExist) {
|
|
118
|
+
return error
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const { key, data, success, fail, complete } = options || {}
|
|
122
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
123
|
+
|
|
65
124
|
return new Promise((resolve, reject) => {
|
|
66
125
|
try {
|
|
67
|
-
validateParams(
|
|
126
|
+
validateParams(name, options, storageSchema)
|
|
68
127
|
} catch (error) {
|
|
69
128
|
const res = { errMsg: error.message }
|
|
70
|
-
return
|
|
129
|
+
return handle.fail(res, { resolve, reject })
|
|
71
130
|
}
|
|
72
131
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
132
|
+
kvStore = kvStore as distributedKVStore.SingleKVStore
|
|
133
|
+
kvStore.put(key, data, (err) => {
|
|
134
|
+
if (!err) {
|
|
135
|
+
handle.fail({ errMsg: `Failed to put data. Code:${err.code},message:${err.message}` }, { resolve, reject })
|
|
136
|
+
return
|
|
137
|
+
}
|
|
79
138
|
|
|
80
|
-
|
|
139
|
+
handle.success({}, { resolve, reject })
|
|
81
140
|
})
|
|
82
141
|
})
|
|
83
142
|
}
|
|
84
143
|
|
|
85
144
|
export function removeStorage (options: Taro.removeStorage.Option) {
|
|
145
|
+
const name = 'removeStorage'
|
|
146
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
147
|
+
|
|
148
|
+
if (!isExist) {
|
|
149
|
+
return error
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const { key, success, fail, complete } = options || {}
|
|
153
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
154
|
+
|
|
86
155
|
return new Promise((resolve, reject) => {
|
|
87
156
|
try {
|
|
88
|
-
validateParams(
|
|
157
|
+
validateParams(name, options, storageSchema)
|
|
89
158
|
} catch (error) {
|
|
90
159
|
const res = { errMsg: error.message }
|
|
91
|
-
return
|
|
160
|
+
return handle.fail(res, { resolve, reject })
|
|
92
161
|
}
|
|
93
162
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const res = { errMsg: 'removeStorage:ok' }
|
|
101
|
-
callAsyncSuccess(resolve, res, options)
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function clearStorage (options: Taro.clearStorage.Option) {
|
|
107
|
-
return new Promise(resolve => {
|
|
108
|
-
preferencesPromise.then(async (preferences) => {
|
|
109
|
-
await preferences.clear()
|
|
110
|
-
await preferences.flush()
|
|
163
|
+
kvStore = kvStore as distributedKVStore.SingleKVStore
|
|
164
|
+
kvStore.delete(key, (err) => {
|
|
165
|
+
if (!err) {
|
|
166
|
+
handle.fail({ errMsg: `Failed to delete data. Code:${err.code},message:${err.message}` }, { resolve, reject })
|
|
167
|
+
return
|
|
168
|
+
}
|
|
111
169
|
|
|
112
|
-
|
|
113
|
-
callAsyncSuccess(resolve, res, options)
|
|
170
|
+
handle.success({}, { resolve, reject })
|
|
114
171
|
})
|
|
115
172
|
})
|
|
116
173
|
}
|
|
@@ -118,11 +175,6 @@ export function clearStorage (options: Taro.clearStorage.Option) {
|
|
|
118
175
|
export const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync')
|
|
119
176
|
export const getStorageInfo = temporarilyNotSupport('getStorageInfo')
|
|
120
177
|
|
|
121
|
-
export const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage')
|
|
122
|
-
export const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage')
|
|
123
|
-
export const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage')
|
|
124
|
-
export const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage')
|
|
125
|
-
|
|
126
178
|
export const createBufferURL = /* @__PURE__ */ temporarilyNotSupport('createBufferURL')
|
|
127
179
|
export const revokeBufferURL = /* @__PURE__ */ temporarilyNotSupport('revokeBufferURL')
|
|
128
180
|
|
|
@@ -131,5 +183,11 @@ export const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetSt
|
|
|
131
183
|
export const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync')
|
|
132
184
|
export const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage')
|
|
133
185
|
|
|
186
|
+
export const clearStorage = temporarilyNotSupport('removeStorageSync')
|
|
187
|
+
export const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage')
|
|
188
|
+
export const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage')
|
|
189
|
+
export const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage')
|
|
190
|
+
export const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage')
|
|
191
|
+
|
|
134
192
|
export * from './background-fetch'
|
|
135
193
|
export * from './cache-manager'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import matrix4 from '@ohos.matrix4'
|
|
2
|
+
import { isUndefined } from '@tarojs/shared'
|
|
2
3
|
|
|
3
4
|
import { temporarilyNotSupport } from '../../utils'
|
|
4
5
|
|
|
@@ -110,7 +111,7 @@ export class Animation implements Taro.Animation {
|
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
scale (sx: number, sy?: number | undefined): Taro.Animation {
|
|
113
|
-
this.rule.scale = { x: sx, y: sy }
|
|
114
|
+
this.rule.scale = { x: sx, y: isUndefined(sy) ? sx : sy }
|
|
114
115
|
return this
|
|
115
116
|
}
|
|
116
117
|
|
package/dist/apis/utils/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ export function temporarilyNotSupport (name: string, recommended?: string) {
|
|
|
19
19
|
return (option = {}, ...args) => {
|
|
20
20
|
const { success, fail, complete } = option as any
|
|
21
21
|
const handle = new MethodHandler({ name, success, fail, complete })
|
|
22
|
-
let errMsg =
|
|
22
|
+
let errMsg = `暂时不支持 API ${name}`
|
|
23
23
|
if (recommended) {
|
|
24
24
|
errMsg += `, 请使用 ${recommended}`
|
|
25
25
|
}
|
|
@@ -19,31 +19,33 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
|
|
|
19
19
|
constructor(component: any, options: Taro.createIntersectionObserver.Option = {}) {
|
|
20
20
|
const taro = (Current as any).taro
|
|
21
21
|
const page = taro.getCurrentInstance().page
|
|
22
|
-
|
|
23
|
-
this._component = component ||
|
|
22
|
+
|
|
23
|
+
this._component = component || getPageScrollerOrNode(page?.node, page)
|
|
24
24
|
Object.assign(this._options, options)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
public disconnect (): void {
|
|
28
|
-
if (this._observerNodes) {
|
|
28
|
+
if (this._observerNodes && this._component) {
|
|
29
29
|
if (this._observerNodes instanceof Array) {
|
|
30
30
|
this._observerNodes.forEach((n: TaroElement & any) => {
|
|
31
31
|
disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME)
|
|
32
32
|
// @ts-ignore
|
|
33
|
-
n._nodeInfo
|
|
33
|
+
n._nodeInfo.thresholds = null
|
|
34
34
|
})
|
|
35
35
|
} else {
|
|
36
36
|
disconnectEvent(this._observerNodes, VISIBLE_CHANGE_EVENT_NAME)
|
|
37
37
|
// @ts-ignore
|
|
38
38
|
if (this._observerNodes._nodeInfo) {
|
|
39
39
|
// @ts-ignore
|
|
40
|
-
this._observerNodes._nodeInfo
|
|
40
|
+
this._observerNodes._nodeInfo.thresholds = null
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
public observe (targetSelector: string, callback: Taro.IntersectionObserver.ObserveCallback): void {
|
|
47
|
+
if (!this._component) return
|
|
48
|
+
|
|
47
49
|
const { observeAll, thresholds } = this._options
|
|
48
50
|
const node = findChildNodeWithDFS(this._component, targetSelector, observeAll)
|
|
49
51
|
this._observerNodes = node
|
|
@@ -52,20 +54,24 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
|
|
|
52
54
|
if (node instanceof Array) {
|
|
53
55
|
node.forEach(n => {
|
|
54
56
|
// @ts-ignore
|
|
55
|
-
n._nodeInfo
|
|
57
|
+
n._nodeInfo.thresholds = thresholds
|
|
56
58
|
|
|
57
59
|
setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
|
|
58
|
-
callback(this.handleResult(isVisible, currentRatio))
|
|
60
|
+
callback(this.handleResult(isVisible, currentRatio, n))
|
|
59
61
|
})
|
|
60
62
|
})
|
|
61
63
|
} else {
|
|
62
64
|
// @ts-ignore
|
|
63
|
-
node._nodeInfo
|
|
65
|
+
node._nodeInfo.thresholds = thresholds
|
|
64
66
|
|
|
65
67
|
setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
|
|
66
|
-
callback(this.handleResult(isVisible, currentRatio))
|
|
68
|
+
callback(this.handleResult(isVisible, currentRatio, node))
|
|
67
69
|
})
|
|
68
70
|
}
|
|
71
|
+
} else {
|
|
72
|
+
callback({
|
|
73
|
+
errMsg: 'IntersectionObserver.observe:fail cannot find the node for selector.'
|
|
74
|
+
})
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
|
|
@@ -80,8 +86,10 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
|
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
// @ts-ignore
|
|
83
|
-
private handleResult (isVisible: boolean, currentRatio: number): Taro.IntersectionObserver.ObserveCallbackResult {
|
|
89
|
+
private handleResult (isVisible: boolean, currentRatio: number, node: TaroElement): Taro.IntersectionObserver.ObserveCallbackResult {
|
|
84
90
|
const result = {
|
|
91
|
+
id: node.id,
|
|
92
|
+
dataset: node.dataset,
|
|
85
93
|
intersectionRatio: currentRatio,
|
|
86
94
|
// TODO 未做,等待能拿到element的info信息
|
|
87
95
|
boundingClientRect: {
|
package/dist/apis/wxml/index.ts
CHANGED