@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.2 → 4.0.0-alpha.21

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.
Files changed (129) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +25 -17
  6. package/dist/apis/media/image/index.ts +1 -1
  7. package/dist/apis/storage/index.ts +146 -78
  8. package/dist/apis/ui/animation/animation.ts +71 -29
  9. package/dist/apis/ui/background.ts +2 -1
  10. package/dist/apis/ui/interaction/index.ts +42 -59
  11. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  12. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  13. package/dist/apis/ui/scroll/index.ts +5 -5
  14. package/dist/apis/ui/tab-bar.ts +3 -3
  15. package/dist/apis/utils/index.ts +2 -1
  16. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  17. package/dist/apis/wxml/selectorQuery.ts +26 -13
  18. package/dist/components-harmony-ets/button.ets +64 -34
  19. package/dist/components-harmony-ets/canvas.ets +51 -0
  20. package/dist/components-harmony-ets/checkbox.ets +72 -61
  21. package/dist/components-harmony-ets/form.ets +51 -29
  22. package/dist/components-harmony-ets/icon.ets +31 -19
  23. package/dist/components-harmony-ets/image.ets +34 -14
  24. package/dist/components-harmony-ets/index.ets +92 -0
  25. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  26. package/dist/components-harmony-ets/input.ets +49 -41
  27. package/dist/components-harmony-ets/label.ets +71 -44
  28. package/dist/components-harmony-ets/listView.ets +26 -0
  29. package/dist/components-harmony-ets/movableArea.ets +126 -0
  30. package/dist/components-harmony-ets/movableView.ets +93 -0
  31. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  32. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  33. package/dist/components-harmony-ets/picker.ets +42 -38
  34. package/dist/components-harmony-ets/progress.ets +52 -0
  35. package/dist/components-harmony-ets/pseudo.ets +80 -0
  36. package/dist/components-harmony-ets/radio.ets +74 -64
  37. package/dist/components-harmony-ets/richText.ets +14 -30
  38. package/dist/components-harmony-ets/scrollList.ets +94 -0
  39. package/dist/components-harmony-ets/scrollView.ets +61 -57
  40. package/dist/components-harmony-ets/slider.ets +18 -14
  41. package/dist/components-harmony-ets/stickySection.ets +42 -0
  42. package/dist/components-harmony-ets/style.ets +381 -130
  43. package/dist/components-harmony-ets/swiper.ets +61 -20
  44. package/dist/components-harmony-ets/switch.ets +36 -32
  45. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  46. package/dist/components-harmony-ets/text.ets +135 -49
  47. package/dist/components-harmony-ets/textArea.ets +50 -35
  48. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  49. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  50. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  51. package/dist/components-harmony-ets/utils/helper.ets +18 -5
  52. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  53. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  54. package/dist/components-harmony-ets/utils/index.ts +54 -50
  55. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  56. package/dist/components-harmony-ets/video.ets +34 -21
  57. package/dist/components-harmony-ets/view.ets +63 -52
  58. package/dist/components-harmony-ets/webView.ets +40 -34
  59. package/dist/index.d.ts +152 -0
  60. package/dist/index.js +99 -55
  61. package/dist/index.js.map +1 -1
  62. package/dist/runtime-ets/bom/document.ts +6 -4
  63. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  64. package/dist/runtime-ets/bom/window.ts +7 -0
  65. package/dist/runtime-ets/current.ts +3 -0
  66. package/dist/runtime-ets/dom/bind.ts +28 -12
  67. package/dist/runtime-ets/dom/class-list.ts +2 -2
  68. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  69. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  70. package/dist/runtime-ets/dom/document.ts +8 -11
  71. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  72. package/dist/runtime-ets/dom/element/element.ts +348 -57
  73. package/dist/runtime-ets/dom/element/form.ts +31 -26
  74. package/dist/runtime-ets/dom/element/index.ts +30 -2
  75. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  76. package/dist/runtime-ets/dom/element/movableView.ts +244 -0
  77. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  78. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  79. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  80. package/dist/runtime-ets/dom/element/text.ts +1 -8
  81. package/dist/runtime-ets/dom/element/video.ts +5 -4
  82. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  83. package/dist/runtime-ets/dom/event.ts +2 -4
  84. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  85. package/dist/runtime-ets/dom/node.ts +54 -29
  86. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
  87. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  88. package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
  89. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  90. package/dist/runtime-ets/index.ts +2 -1
  91. package/dist/runtime-ets/interface/event.ts +1 -1
  92. package/dist/runtime-ets/utils/index.ts +73 -13
  93. package/dist/runtime-ets/utils/info.ts +2 -2
  94. package/dist/runtime-framework/react/app.ts +9 -4
  95. package/dist/runtime-framework/react/hooks.ts +0 -1
  96. package/dist/runtime-framework/react/index.ts +0 -2
  97. package/dist/runtime-framework/react/native-page.ts +154 -77
  98. package/dist/runtime-framework/react/page.ts +3 -8
  99. package/dist/runtime-framework/solid/app.ts +25 -45
  100. package/dist/runtime-framework/solid/connect.ts +21 -3
  101. package/dist/runtime-framework/solid/hooks.ts +16 -11
  102. package/dist/runtime-framework/solid/index.ts +6 -2
  103. package/dist/runtime-framework/solid/page.ts +84 -30
  104. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  105. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  106. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  107. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  108. package/dist/runtime-utils.d.ts +827 -0
  109. package/dist/runtime-utils.js +435 -218
  110. package/dist/runtime-utils.js.map +1 -1
  111. package/dist/runtime.d.ts +1 -0
  112. package/dist/runtime.js +435 -218
  113. package/dist/runtime.js.map +1 -1
  114. package/index.js +3 -1
  115. package/package.json +14 -15
  116. package/static/media/cancel.svg +1 -1
  117. package/static/media/circle.svg +1 -1
  118. package/static/media/clear.svg +1 -1
  119. package/static/media/download.svg +1 -1
  120. package/static/media/info.svg +1 -1
  121. package/static/media/info_circle.svg +1 -1
  122. package/static/media/search.svg +1 -1
  123. package/static/media/success.svg +1 -1
  124. package/static/media/success_no_circle.svg +1 -1
  125. package/static/media/warn.svg +1 -1
  126. package/types/harmony.d.ts +4 -0
  127. package/types/index.d.ts +4 -0
  128. package/types/runtime.d.ts +1 -1
  129. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -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
 
@@ -22,7 +23,6 @@ type TStep = {
22
23
  type TRule = Record<string, any>
23
24
 
24
25
  export class Animation implements Taro.Animation {
25
-
26
26
  unit: string
27
27
  DEFAULT: IAnimationAttr
28
28
 
@@ -71,6 +71,9 @@ export class Animation implements Taro.Animation {
71
71
  transformOrigin,
72
72
  rule: Object.assign({}, this.rule)
73
73
  })
74
+ if (this.rule.transform) {
75
+ this.rule.transform = Object.assign({}, this.rule.transform)
76
+ }
74
77
  return this
75
78
  }
76
79
 
@@ -85,92 +88,137 @@ export class Animation implements Taro.Animation {
85
88
  }
86
89
 
87
90
  rotate (angle: number): Taro.Animation {
88
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
91
+ if (!this.rule.transform) {
92
+ this.rule.transform = {}
93
+ }
94
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
89
95
  return this
90
96
  }
91
97
 
92
98
  rotate3d (x: number, y?: number | undefined, z?: number | undefined, angle?: number | undefined): Taro.Animation {
93
- this.rule.rotate = { x, y, z, angle }
99
+ if (!this.rule.transform) {
100
+ this.rule.transform = {}
101
+ }
102
+ this.rule.transform.Rotate = { x, y, z, angle }
94
103
  return this
95
104
  }
96
105
 
97
106
  rotateX (angle: number): Taro.Animation {
98
- this.rule.rotate = { x: 1, y: 0, z: 0, angle }
107
+ if (!this.rule.transform) {
108
+ this.rule.transform = {}
109
+ }
110
+ this.rule.transform.Rotate = { x: 1, y: 0, z: 0, angle }
99
111
  return this
100
112
  }
101
113
 
102
114
  rotateY (angle: number): Taro.Animation {
103
- this.rule.rotate = { x: 0, y: 1, z: 0, angle }
115
+ if (!this.rule.transform) {
116
+ this.rule.transform = {}
117
+ }
118
+ this.rule.transform.Rotate = { x: 0, y: 1, z: 0, angle }
104
119
  return this
105
120
  }
106
121
 
107
122
  rotateZ (angle: number): Taro.Animation {
108
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
123
+ if (!this.rule.transform) {
124
+ this.rule.transform = {}
125
+ }
126
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
109
127
  return this
110
128
  }
111
129
 
112
130
  scale (sx: number, sy?: number | undefined): Taro.Animation {
113
- this.rule.scale = { x: sx, y: sy }
131
+ if (!this.rule.transform) {
132
+ this.rule.transform = {}
133
+ }
134
+ this.rule.transform.Scale = { x: sx, y: isUndefined(sy) ? sx : sy }
114
135
  return this
115
136
  }
116
137
 
117
138
  scale3d (sx: number, sy: number, sz: number): Taro.Animation {
118
- this.rule.scale = { x: sx, y: sy, z: sz }
139
+ if (!this.rule.transform) {
140
+ this.rule.transform = {}
141
+ }
142
+ this.rule.transform.Scale = { x: sx, y: sy, z: sz }
119
143
  return this
120
144
  }
121
145
 
122
146
  scaleX (scale: number): Taro.Animation {
123
- this.rule.scale = { x: scale }
147
+ if (!this.rule.transform) {
148
+ this.rule.transform = {}
149
+ }
150
+ this.rule.transform.Scale = { x: scale }
124
151
  return this
125
152
  }
126
153
 
127
154
  scaleY (scale: number): Taro.Animation {
128
- this.rule.scale = { y: scale }
155
+ if (!this.rule.transform) {
156
+ this.rule.transform = {}
157
+ }
158
+ this.rule.transform.Scale = { y: scale }
129
159
  return this
130
160
  }
131
161
 
132
162
  scaleZ (scale: number): Taro.Animation {
133
- this.rule.scale = { z: scale }
163
+ if (!this.rule.transform) {
164
+ this.rule.transform = {}
165
+ }
166
+ this.rule.transform.Scale = { z: scale }
134
167
  return this
135
168
  }
136
169
 
137
170
  skew (ax: number, ay: number): Taro.Animation {
138
- this.rule.skew = { x: ax, y: ay }
171
+ temporarilyNotSupport('animation.skew:' + `${ax}, ${ay}`)(ax, ay)
139
172
  return this
140
173
  }
141
174
 
142
175
  skewX (angle: number): Taro.Animation {
143
- this.rule.skew = { x: angle }
176
+ temporarilyNotSupport('animation.skewX:' + angle)(angle)
144
177
  return this
145
178
  }
146
179
 
147
180
  skewY (angle: number): Taro.Animation {
148
- this.rule.skew = { y: angle }
181
+ temporarilyNotSupport('animation.skewY:' + angle)(angle)
149
182
  return this
150
183
  }
151
184
 
152
185
  translate (tx?: number | undefined, ty?: number | undefined): Taro.Animation {
153
- this.rule.translate = { x: tx, y: ty }
186
+ if (!this.rule.transform) {
187
+ this.rule.transform = {}
188
+ }
189
+ this.rule.transform.Translate = { x: tx, y: ty }
154
190
  return this
155
191
  }
156
192
 
157
193
  translate3d (tx?: number | undefined, ty?: number | undefined, tz?: number | undefined): Taro.Animation {
158
- this.rule.translate = { x: tx, y: ty, z: tz }
194
+ if (!this.rule.transform) {
195
+ this.rule.transform = {}
196
+ }
197
+ this.rule.transform.Translate = { x: tx, y: ty, z: tz }
159
198
  return this
160
199
  }
161
200
 
162
201
  translateX (translation: number): Taro.Animation {
163
- this.rule.translate = { x: translation }
202
+ if (!this.rule.transform) {
203
+ this.rule.transform = {}
204
+ }
205
+ this.rule.transform.Translate = { x: translation }
164
206
  return this
165
207
  }
166
208
 
167
209
  translateY (translation: number): Taro.Animation {
168
- this.rule.translate = { y: translation }
210
+ if (!this.rule.transform) {
211
+ this.rule.transform = {}
212
+ }
213
+ this.rule.transform.Translate = { y: translation }
169
214
  return this
170
215
  }
171
216
 
172
217
  translateZ (translation: number): Taro.Animation {
173
- this.rule.translate = { z: translation }
218
+ if (!this.rule.transform) {
219
+ this.rule.transform = {}
220
+ }
221
+ this.rule.transform.Translate = { z: translation }
174
222
  return this
175
223
  }
176
224
 
@@ -185,23 +233,17 @@ export class Animation implements Taro.Animation {
185
233
  }
186
234
 
187
235
  width (value: string | number): Taro.Animation {
188
- this.rule.size = {
189
- ...this.rule.size,
190
- width: value
191
- }
236
+ this.rule.width = value
192
237
  return this
193
238
  }
194
239
 
195
240
  height (value: string | number): Taro.Animation {
196
- this.rule.size = {
197
- ...this.rule.size,
198
- height: value
199
- }
241
+ this.rule.height = value
200
242
  return this
201
243
  }
202
244
 
203
245
  left (value: string | number): Taro.Animation {
204
- temporarilyNotSupport('animation.left:' + value)(value)
246
+ this.rule.left = value
205
247
  return this
206
248
  }
207
249
 
@@ -211,7 +253,7 @@ export class Animation implements Taro.Animation {
211
253
  }
212
254
 
213
255
  top (value: string | number): Taro.Animation {
214
- temporarilyNotSupport('animation.top:' + value)(value)
256
+ this.rule.top = value
215
257
  return this
216
258
  }
217
259
 
@@ -11,7 +11,8 @@ export function setBackgroundColor(options: Taro.setBackgroundColor.Option) {
11
11
 
12
12
  return new Promise((resolve, reject) => {
13
13
  eventCenter.trigger('__taroPageStyle', {
14
- backgroundColor: options.backgroundColor || options.backgroundColorTop || options.backgroundColorBottom,
14
+ backgroundColor: options.backgroundColorBottom || options.backgroundColor,
15
+ backgroundColorContext: options.backgroundColorTop || options.backgroundColor
15
16
  })
16
17
 
17
18
  return handle.success({}, { resolve, reject })
@@ -1,4 +1,4 @@
1
- import prompt from '@ohos.prompt'
1
+ import promptAction from '@ohos.promptAction'
2
2
 
3
3
  import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../../utils'
4
4
 
@@ -29,10 +29,11 @@ export function showToast (options) {
29
29
  return callAsyncFail(reject, res, options)
30
30
  }
31
31
 
32
- prompt.showToast({
32
+ promptAction.showToast({
33
33
  message: options.title,
34
34
  duration: options.duration,
35
- bottom: options.bottom
35
+ bottom: options.bottom,
36
+ showMode: 1 // 设置弹窗显示模式,显示在应用之上。
36
37
  })
37
38
  callAsyncSuccess(resolve, resCallback('showToast'), options)
38
39
  })
@@ -72,37 +73,20 @@ export function showModal (options) {
72
73
  })
73
74
  }
74
75
 
75
- return new Promise(resolve => {
76
+ return new Promise((resolve, reject) => {
76
77
  const modalOptions = {
77
78
  title,
78
79
  message: content,
79
80
  buttons: buttons,
80
- success: (data) => {
81
- if (data.index === 1 || !showCancel) {
82
- callAsyncSuccess(
83
- resolve,
84
- {
85
- ...resCallback('showModal'),
86
- confirm: true,
87
- cancel: false,
88
- content: null
89
- },
90
- options
91
- )
92
- } else {
93
- callAsyncSuccess(
94
- resolve,
95
- {
96
- ...resCallback('showModal'),
97
- confirm: false,
98
- cancel: true
99
- },
100
- options
101
- )
102
- }
103
- },
104
- // 鸿蒙没有失败方法,只有取消
105
- cancel: (_) => {
81
+ }
82
+
83
+ promptAction.showDialog(modalOptions, (error, data) => {
84
+ if (error) {
85
+ const res = { errMsg: error }
86
+ callAsyncFail(reject, res, options)
87
+ }
88
+
89
+ if (data.index === 0 && showCancel) {
106
90
  callAsyncSuccess(
107
91
  resolve,
108
92
  {
@@ -112,10 +96,19 @@ export function showModal (options) {
112
96
  },
113
97
  options
114
98
  )
99
+ } else {
100
+ callAsyncSuccess(
101
+ resolve,
102
+ {
103
+ ...resCallback('showModal'),
104
+ confirm: true,
105
+ cancel: false,
106
+ content: null
107
+ },
108
+ options
109
+ )
115
110
  }
116
- }
117
-
118
- prompt.showDialog(modalOptions)
111
+ })
119
112
  })
120
113
  }
121
114
 
@@ -152,45 +145,35 @@ export function showActionSheet (options) {
152
145
 
153
146
  const actionSheetOptions = {
154
147
  title,
155
- buttons,
156
- success: (data) => {
157
- callAsyncSuccess(
158
- resolve,
159
- {
160
- ...data,
161
- ...resCallback('showActionSheet')
162
- },
163
- options
164
- )
165
- },
166
- // 取消方法,并非失败
167
- fail: (data) => {
148
+ buttons
149
+ }
150
+
151
+ promptAction.showActionMenu(actionSheetOptions, (error, data) => {
152
+ if (error) {
168
153
  callAsyncFail(
169
154
  reject,
170
155
  {
171
156
  ...data,
172
- errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet')
157
+ errMsg: data.errMsg?.replace('showActionMenu', 'showActionSheet')
173
158
  },
174
159
  options
175
160
  )
176
161
  }
177
- }
178
162
 
179
- prompt.showActionMenu(actionSheetOptions)
180
- })
181
- }
182
-
183
- export function hideToast (options) {
184
- return new Promise(resolve => {
185
- prompt.showToast({
186
- message: '关闭中',
187
- duration: 10,
188
- bottom: '9999px'
163
+ callAsyncSuccess(
164
+ resolve,
165
+ {
166
+ ...data,
167
+ ...resCallback('showActionSheet')
168
+ },
169
+ options
170
+ )
189
171
  })
190
- callAsyncSuccess(resolve, resCallback('hideToast'), options)
191
172
  })
192
173
  }
193
174
 
175
+ export const hideToast = /* @__PURE__ */ temporarilyNotSupport('hideToast')
176
+
194
177
  export const showLoading = temporarilyNotSupport('showLoading')
195
178
  export const hideLoading = temporarilyNotSupport('hideLoading')
196
179
 
@@ -19,7 +19,7 @@ export const setNavigationBarTitle: typeof Taro.setNavigationBarTitle = function
19
19
 
20
20
  export const setNavigationBarColor: typeof Taro.setNavigationBarColor = function (options) {
21
21
  const { success, fail, complete } = options || {}
22
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete })
22
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete })
23
23
 
24
24
  return new Promise((resolve, reject) => {
25
25
  eventCenter.trigger('__taroNavigationStyle', {
@@ -1,14 +1,17 @@
1
1
  import { Current } from '@tarojs/runtime'
2
2
 
3
- import { callAsyncSuccess } from '../utils'
3
+ import { callAsyncFail, callAsyncSuccess } from '../utils'
4
4
 
5
5
  import type Taro from '@tarojs/taro/types'
6
6
 
7
7
  export const startPullDownRefresh: typeof Taro.startPullDownRefresh = function (options) {
8
- return new Promise(resolve => {
8
+ return new Promise((resolve, reject) => {
9
9
  const taro = (Current as any).taro
10
10
  const page = taro.getCurrentInstance().page
11
11
 
12
+ if (!page) {
13
+ return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options)
14
+ }
12
15
  if (page.isRefreshing instanceof Array) {
13
16
  const index = page.tabBarCurrentIndex || 0
14
17
  page.isRefreshing[index] = true
@@ -23,10 +26,13 @@ export const startPullDownRefresh: typeof Taro.startPullDownRefresh = function (
23
26
  }
24
27
 
25
28
  export const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function (options) {
26
- return new Promise(resolve => {
29
+ return new Promise((resolve, reject) => {
27
30
  const taro = (Current as any).taro
28
31
  const page = taro.getCurrentInstance().page
29
32
 
33
+ if (!page) {
34
+ return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options)
35
+ }
30
36
  if (page.isRefreshing instanceof Array) {
31
37
  const index = page.tabBarCurrentIndex || 0
32
38
  page.isRefreshing[index] = false
@@ -34,8 +34,8 @@ export const pageScrollTo: typeof Taro.pageScrollTo = (options) => {
34
34
  const page = taro.getCurrentInstance().page
35
35
 
36
36
  let scrollValue = -1
37
- let scroller = page.scroller
38
- const currentPageNode = getPageScrollerOrNode(page.node, page)
37
+ let scroller = getPageScrollerOrNode(page?.scroller, page)
38
+ const currentPageNode = getPageScrollerOrNode(page?.node, page)
39
39
 
40
40
  if (scrollTop || typeof scrollTop === 'number') {
41
41
  scrollValue = scrollTop
@@ -66,14 +66,14 @@ export const pageScrollTo: typeof Taro.pageScrollTo = (options) => {
66
66
  scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper(offsetTop, 'px', true)
67
67
  }
68
68
  }
69
- const { xOffset } = scroller.currentOffset()
70
-
71
- if (scrollValue === -1) {
69
+ if (!scroller || scrollValue === -1) {
72
70
  return handle.fail({
73
71
  errMsg: '请检查传入的 scrollTop 或 selector 是否合法'
74
72
  }, { resolve, reject })
75
73
  }
76
74
 
75
+ const { xOffset } = scroller.currentOffset()
76
+
77
77
  try {
78
78
  scroller.scrollTo({
79
79
  xOffset,
@@ -22,7 +22,7 @@ const toggleTabBar = function<T extends ToggleAPIs['type']> (type: T): Extract<T
22
22
  return new Promise((resolve, reject) => {
23
23
  const taro = (Current as any).taro
24
24
  const page = taro.getCurrentInstance().page
25
- const currentData = page._data?.taroTabBar || page.tabBar
25
+ const currentData = page?._data?.taroTabBar || page?.tabBar
26
26
  const res = { errMsg: `${type}TabBar:ok` }
27
27
  const error = { errMsg: `${type}TabBar:fail not TabBar page` }
28
28
 
@@ -49,7 +49,7 @@ export const setTabBarStyle: typeof Taro.setTabBarStyle = function (options = {}
49
49
  return new Promise((resolve, reject) => {
50
50
  const taro = (Current as any).taro
51
51
  const page = taro.getCurrentInstance().page
52
- const currentData = page._data?.taroTabBar || page.tabBar
52
+ const currentData = page?._data?.taroTabBar || page?.tabBar
53
53
  const res = { errMsg: 'setTabBarStyle:ok' }
54
54
  const error = { errMsg: 'setTabBarStyle:fail not TabBar page' }
55
55
 
@@ -74,7 +74,7 @@ export const setTabBarItem: typeof Taro.setTabBarItem = function (options) {
74
74
  return new Promise((resolve, reject) => {
75
75
  const taro = (Current as any).taro
76
76
  const page = taro.getCurrentInstance().page
77
- const currentData = page._data?.taroTabBar || page.tabBar
77
+ const currentData = page?._data?.taroTabBar || page?.tabBar
78
78
  const res = { errMsg: 'setTabBarItem:ok' }
79
79
  const error = { errMsg: 'setTabBarItem:fail not TabBar page' }
80
80
 
@@ -5,6 +5,7 @@ import { ICallbackResult, MethodHandler } from './handler'
5
5
  import type { FunctionType, IAsyncParams } from './types'
6
6
 
7
7
  export * from './validate'
8
+ export { MethodHandler }
8
9
  export { noop } from '@tarojs/shared'
9
10
 
10
11
  export function object2String (obj) {
@@ -19,7 +20,7 @@ export function temporarilyNotSupport (name: string, recommended?: string) {
19
20
  return (option = {}, ...args) => {
20
21
  const { success, fail, complete } = option as any
21
22
  const handle = new MethodHandler({ name, success, fail, complete })
22
- let errMsg = '暂时不支持 API'
23
+ let errMsg = `暂时不支持 API ${name}`
23
24
  if (recommended) {
24
25
  errMsg += `, 请使用 ${recommended}`
25
26
  }
@@ -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
- const currentPage = getPageScrollerOrNode(page.node, page)
23
- this._component = component || currentPage
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?.thresholds = null
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?.thresholds = null
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?.thresholds = thresholds
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?.thresholds = thresholds
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: {
@@ -112,7 +112,7 @@ function filter (fields, dom) {
112
112
  return res
113
113
  }
114
114
  if (context) {
115
- // TODO: 暂未实现获取 context
115
+ // TODO: 暂未实现获取 context
116
116
  // const typeName = dom.type
117
117
  // if (/^video/i.test(typeName)) {
118
118
  // return { context: dom }
@@ -179,37 +179,50 @@ function filter (fields, dom) {
179
179
 
180
180
  function querySelector (selector, selectAll) {
181
181
  if (typeof selector === 'string') {
182
- return parseHandler(selector, selectAll)
182
+ return selector.split(',').reduce((prev, current) => {
183
+ const item = current.trim()
184
+
185
+ return prev.concat(parseHandler(item, selectAll))
186
+ }, [])
183
187
  }
184
- return null
188
+ return []
185
189
  }
186
190
 
187
191
  function queryBat (queue, cb) {
188
192
  const result: any = []
189
193
  const taro = (Current as any).taro
190
194
  const page = taro.getCurrentInstance().page
191
- const element = getPageScrollerOrNode(page.node, page)
195
+ const element = getPageScrollerOrNode(page?.node, page)
192
196
 
193
- if (element == null) return null
197
+ if (!element) return null
194
198
 
195
199
  arr = []
196
200
  traversalDFSDom(element)
197
- queue.forEach(item => {
201
+ queue.forEach((item) => {
198
202
  const { selector, single, fields } = item
199
- const nodeList = querySelector(selector, !single)
200
203
 
201
- result.push(nodeList.map(dom => {
204
+ if (single) {
205
+ const dom = querySelector(selector, !single)[0]
202
206
  // eslint-disable-next-line no-async-promise-executor
203
- return new Promise(async resolve => {
207
+ result.push(new Promise(async resolve => {
204
208
  await setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true)
205
-
206
209
  resolve(filter(fields, dom))
207
- })
208
- }))
210
+ }))
211
+ } else {
212
+ const nodeList = querySelector(selector, !single)
213
+ result.push(nodeList.map(dom => {
214
+ // eslint-disable-next-line no-async-promise-executor
215
+ return new Promise(async resolve => {
216
+ await setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true)
217
+
218
+ resolve(filter(fields, dom))
219
+ })
220
+ }))
221
+ }
209
222
  })
210
223
 
211
224
  Promise.all(result.map(item => {
212
- return Promise.all(item)
225
+ return item instanceof Array ? Promise.all(item) : item
213
226
  })).then(data => {
214
227
  cb(data)
215
228
  })