@tarojs/plugin-platform-harmony-ets 4.0.0-beta.6 → 4.0.0-beta.61

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 (126) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +9 -0
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/network/request.ts +5 -5
  7. package/dist/apis/route/index.ts +15 -0
  8. package/dist/apis/storage/index.ts +148 -80
  9. package/dist/apis/ui/animation/animation.ts +71 -28
  10. package/dist/apis/ui/background.ts +2 -1
  11. package/dist/apis/ui/interaction/index.ts +42 -59
  12. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  13. package/dist/apis/ui/scroll/index.ts +1 -1
  14. package/dist/apis/utils/index.ts +1 -1
  15. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  16. package/dist/apis/wxml/index.ts +2 -0
  17. package/dist/apis/wxml/selectorQuery.ts +25 -12
  18. package/dist/components-harmony-ets/button.ets +48 -34
  19. package/dist/components-harmony-ets/canvas.ets +51 -0
  20. package/dist/components-harmony-ets/checkbox.ets +69 -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 +42 -40
  27. package/dist/components-harmony-ets/label.ets +69 -42
  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 +73 -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 +71 -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 +15 -14
  41. package/dist/components-harmony-ets/stickySection.ets +42 -0
  42. package/dist/components-harmony-ets/style.ets +372 -130
  43. package/dist/components-harmony-ets/swiper.ets +61 -20
  44. package/dist/components-harmony-ets/switch.ets +30 -28
  45. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  46. package/dist/components-harmony-ets/text.ets +159 -51
  47. package/dist/components-harmony-ets/textArea.ets +35 -34
  48. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  49. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  50. package/dist/components-harmony-ets/utils/flexManager.ets +47 -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 -20
  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 +82 -39
  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 +30 -13
  67. package/dist/runtime-ets/dom/cssNesting.ts +411 -0
  68. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +27 -41
  69. package/dist/runtime-ets/dom/document.ts +22 -8
  70. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  71. package/dist/runtime-ets/dom/element/element.ts +334 -58
  72. package/dist/runtime-ets/dom/element/form.ts +23 -26
  73. package/dist/runtime-ets/dom/element/index.ts +25 -2
  74. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  75. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  76. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  77. package/dist/runtime-ets/dom/element/progress.ts +12 -0
  78. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  79. package/dist/runtime-ets/dom/element/text.ts +1 -8
  80. package/dist/runtime-ets/dom/element/video.ts +5 -3
  81. package/dist/runtime-ets/dom/element/webView.ts +11 -3
  82. package/dist/runtime-ets/dom/event.ts +0 -1
  83. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  84. package/dist/runtime-ets/dom/node.ts +46 -28
  85. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
  86. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  87. package/dist/runtime-ets/dom/stylesheet/type.ts +49 -9
  88. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  89. package/dist/runtime-ets/index.ts +2 -2
  90. package/dist/runtime-ets/interface/event.ts +1 -1
  91. package/dist/runtime-ets/utils/index.ts +67 -11
  92. package/dist/runtime-ets/utils/info.ts +1 -1
  93. package/dist/runtime-framework/react/app.ts +7 -2
  94. package/dist/runtime-framework/react/index.ts +0 -2
  95. package/dist/runtime-framework/react/native-page.ts +32 -14
  96. package/dist/runtime-framework/react/page.ts +3 -8
  97. package/dist/runtime-framework/solid/app.ts +25 -45
  98. package/dist/runtime-framework/solid/connect.ts +21 -3
  99. package/dist/runtime-framework/solid/hooks.ts +16 -11
  100. package/dist/runtime-framework/solid/index.ts +6 -2
  101. package/dist/runtime-framework/solid/page.ts +84 -30
  102. package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
  103. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  104. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  105. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  106. package/dist/runtime-utils.d.ts +827 -0
  107. package/dist/runtime-utils.js +411 -200
  108. package/dist/runtime-utils.js.map +1 -1
  109. package/dist/runtime.d.ts +1 -0
  110. package/dist/runtime.js +411 -200
  111. package/dist/runtime.js.map +1 -1
  112. package/index.js +3 -1
  113. package/package.json +13 -13
  114. package/static/media/cancel.svg +1 -1
  115. package/static/media/circle.svg +1 -1
  116. package/static/media/clear.svg +1 -1
  117. package/static/media/download.svg +1 -1
  118. package/static/media/info.svg +1 -1
  119. package/static/media/info_circle.svg +1 -1
  120. package/static/media/search.svg +1 -1
  121. package/static/media/success.svg +1 -1
  122. package/static/media/success_no_circle.svg +1 -1
  123. package/static/media/warn.svg +1 -1
  124. package/types/harmony.d.ts +4 -0
  125. package/types/index.d.ts +4 -0
  126. /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
 
@@ -71,6 +72,9 @@ export class Animation implements Taro.Animation {
71
72
  transformOrigin,
72
73
  rule: Object.assign({}, this.rule)
73
74
  })
75
+ if (this.rule.transform) {
76
+ this.rule.transform = Object.assign({}, this.rule.transform)
77
+ }
74
78
  return this
75
79
  }
76
80
 
@@ -85,92 +89,137 @@ export class Animation implements Taro.Animation {
85
89
  }
86
90
 
87
91
  rotate (angle: number): Taro.Animation {
88
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
92
+ if (!this.rule.transform) {
93
+ this.rule.transform = {}
94
+ }
95
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
89
96
  return this
90
97
  }
91
98
 
92
99
  rotate3d (x: number, y?: number | undefined, z?: number | undefined, angle?: number | undefined): Taro.Animation {
93
- this.rule.rotate = { x, y, z, angle }
100
+ if (!this.rule.transform) {
101
+ this.rule.transform = {}
102
+ }
103
+ this.rule.transform.Rotate = { x, y, z, angle }
94
104
  return this
95
105
  }
96
106
 
97
107
  rotateX (angle: number): Taro.Animation {
98
- this.rule.rotate = { x: 1, y: 0, z: 0, angle }
108
+ if (!this.rule.transform) {
109
+ this.rule.transform = {}
110
+ }
111
+ this.rule.transform.Rotate = { x: 1, y: 0, z: 0, angle }
99
112
  return this
100
113
  }
101
114
 
102
115
  rotateY (angle: number): Taro.Animation {
103
- this.rule.rotate = { x: 0, y: 1, z: 0, angle }
116
+ if (!this.rule.transform) {
117
+ this.rule.transform = {}
118
+ }
119
+ this.rule.transform.Rotate = { x: 0, y: 1, z: 0, angle }
104
120
  return this
105
121
  }
106
122
 
107
123
  rotateZ (angle: number): Taro.Animation {
108
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
124
+ if (!this.rule.transform) {
125
+ this.rule.transform = {}
126
+ }
127
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
109
128
  return this
110
129
  }
111
130
 
112
131
  scale (sx: number, sy?: number | undefined): Taro.Animation {
113
- this.rule.scale = { x: sx, y: sy }
132
+ if (!this.rule.transform) {
133
+ this.rule.transform = {}
134
+ }
135
+ this.rule.transform.Scale = { x: sx, y: isUndefined(sy) ? sx : sy }
114
136
  return this
115
137
  }
116
138
 
117
139
  scale3d (sx: number, sy: number, sz: number): Taro.Animation {
118
- this.rule.scale = { x: sx, y: sy, z: sz }
140
+ if (!this.rule.transform) {
141
+ this.rule.transform = {}
142
+ }
143
+ this.rule.transform.Scale = { x: sx, y: sy, z: sz }
119
144
  return this
120
145
  }
121
146
 
122
147
  scaleX (scale: number): Taro.Animation {
123
- this.rule.scale = { x: scale }
148
+ if (!this.rule.transform) {
149
+ this.rule.transform = {}
150
+ }
151
+ this.rule.transform.Scale = { x: scale }
124
152
  return this
125
153
  }
126
154
 
127
155
  scaleY (scale: number): Taro.Animation {
128
- this.rule.scale = { y: scale }
156
+ if (!this.rule.transform) {
157
+ this.rule.transform = {}
158
+ }
159
+ this.rule.transform.Scale = { y: scale }
129
160
  return this
130
161
  }
131
162
 
132
163
  scaleZ (scale: number): Taro.Animation {
133
- this.rule.scale = { z: scale }
164
+ if (!this.rule.transform) {
165
+ this.rule.transform = {}
166
+ }
167
+ this.rule.transform.Scale = { z: scale }
134
168
  return this
135
169
  }
136
170
 
137
171
  skew (ax: number, ay: number): Taro.Animation {
138
- this.rule.skew = { x: ax, y: ay }
172
+ temporarilyNotSupport('animation.skew:' + `${ax}, ${ay}`)(ax, ay)
139
173
  return this
140
174
  }
141
175
 
142
176
  skewX (angle: number): Taro.Animation {
143
- this.rule.skew = { x: angle }
177
+ temporarilyNotSupport('animation.skewX:' + angle)(angle)
144
178
  return this
145
179
  }
146
180
 
147
181
  skewY (angle: number): Taro.Animation {
148
- this.rule.skew = { y: angle }
182
+ temporarilyNotSupport('animation.skewY:' + angle)(angle)
149
183
  return this
150
184
  }
151
185
 
152
186
  translate (tx?: number | undefined, ty?: number | undefined): Taro.Animation {
153
- this.rule.translate = { x: tx, y: ty }
187
+ if (!this.rule.transform) {
188
+ this.rule.transform = {}
189
+ }
190
+ this.rule.transform.Translate = { x: tx, y: ty }
154
191
  return this
155
192
  }
156
193
 
157
194
  translate3d (tx?: number | undefined, ty?: number | undefined, tz?: number | undefined): Taro.Animation {
158
- this.rule.translate = { x: tx, y: ty, z: tz }
195
+ if (!this.rule.transform) {
196
+ this.rule.transform = {}
197
+ }
198
+ this.rule.transform.Translate = { x: tx, y: ty, z: tz }
159
199
  return this
160
200
  }
161
201
 
162
202
  translateX (translation: number): Taro.Animation {
163
- this.rule.translate = { x: translation }
203
+ if (!this.rule.transform) {
204
+ this.rule.transform = {}
205
+ }
206
+ this.rule.transform.Translate = { x: translation }
164
207
  return this
165
208
  }
166
209
 
167
210
  translateY (translation: number): Taro.Animation {
168
- this.rule.translate = { y: translation }
211
+ if (!this.rule.transform) {
212
+ this.rule.transform = {}
213
+ }
214
+ this.rule.transform.Translate = { y: translation }
169
215
  return this
170
216
  }
171
217
 
172
218
  translateZ (translation: number): Taro.Animation {
173
- this.rule.translate = { z: translation }
219
+ if (!this.rule.transform) {
220
+ this.rule.transform = {}
221
+ }
222
+ this.rule.transform.Translate = { z: translation }
174
223
  return this
175
224
  }
176
225
 
@@ -185,23 +234,17 @@ export class Animation implements Taro.Animation {
185
234
  }
186
235
 
187
236
  width (value: string | number): Taro.Animation {
188
- this.rule.size = {
189
- ...this.rule.size,
190
- width: value
191
- }
237
+ this.rule.width = value
192
238
  return this
193
239
  }
194
240
 
195
241
  height (value: string | number): Taro.Animation {
196
- this.rule.size = {
197
- ...this.rule.size,
198
- height: value
199
- }
242
+ this.rule.height = value
200
243
  return this
201
244
  }
202
245
 
203
246
  left (value: string | number): Taro.Animation {
204
- temporarilyNotSupport('animation.left:' + value)(value)
247
+ this.rule.left = value
205
248
  return this
206
249
  }
207
250
 
@@ -211,7 +254,7 @@ export class Animation implements Taro.Animation {
211
254
  }
212
255
 
213
256
  top (value: string | number): Taro.Animation {
214
- temporarilyNotSupport('animation.top:' + value)(value)
257
+ this.rule.top = value
215
258
  return this
216
259
  }
217
260
 
@@ -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', {
@@ -34,7 +34,7 @@ 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
37
+ let scroller = getPageScrollerOrNode(page.scroller, page)
38
38
  const currentPageNode = getPageScrollerOrNode(page.node, page)
39
39
 
40
40
  if (scrollTop || typeof scrollTop === 'number') {
@@ -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 = '暂时不支持 API'
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
- 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: {
@@ -13,3 +13,5 @@ export const createIntersectionObserver: typeof Taro.createIntersectionObserver
13
13
  }
14
14
 
15
15
  export const createMediaQueryObserver = /* @__PURE__ */ temporarilyNotSupport('createMediaQueryObserver')
16
+
17
+ export { IntersectionObserver }
@@ -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,9 +179,13 @@ 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) {
@@ -194,22 +198,31 @@ function queryBat (queue, cb) {
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
-
201
- result.push(nodeList.map(dom => {
203
+
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
  })
@@ -1,5 +1,4 @@
1
1
  import { eventHandler, createTaroEvent, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
- import { createLazyChildren } from './render'
3
2
  import commonStyleModify from './style'
4
3
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
5
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
@@ -66,13 +65,13 @@ function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
66
65
  }
67
66
  }
68
67
 
69
- function getButtonWidth (node: TaroButtonElement) {
68
+ function getButtonWidth (node: TaroButtonElement): string | number {
70
69
  const isMini = node._attrs.size === 'mini'
71
70
 
72
71
  return isMini ? convertNumber2VP(120) : '100%'
73
72
  }
74
73
 
75
- function getButtonHeight (node: TaroButtonElement) {
74
+ function getButtonHeight (node: TaroButtonElement): string | number {
76
75
  const isMini = node._attrs.size === 'mini'
77
76
 
78
77
  return isMini ? convertNumber2VP(60) : convertNumber2VP(92)
@@ -94,38 +93,53 @@ function getButtonMinHeight (node: TaroButtonElement): string | number | undefin
94
93
  return getButtonHeight(node)
95
94
  }
96
95
 
97
- @Builder
98
- export default function TaroButton (node: TaroButtonElement) {
99
- Button({ stateEffect: !node._attrs.disabled }) {
100
- Row() {
101
- if (node._attrs.loading) {
102
- LoadingProgress()
103
- .width(20).height(20)
104
- .color(getThemeAttributes(node).color)
105
- }
106
- createLazyChildren(node)
96
+ @Component
97
+ export default struct TaroButton {
98
+ @Builder customBuilder() {}
99
+ @BuilderParam createLazyChildren: (node: TaroButtonElement) => void = this.customBuilder
100
+ @ObjectLink node: TaroButtonElement
101
+ @State overwriteStyle: Record<string, TaroAny> = {}
102
+
103
+ aboutToAppear(): void {
104
+ if (this.node) {
105
+ this.node._instance = this
107
106
  }
108
107
  }
109
- .themeStyles(getThemeAttributes(node))
110
- .attributeModifier(commonStyleModify.setNode(node))
111
- .constraintSize({
112
- minWidth: node.hmStyle?.minWidth || getButtonMinWidth(node),
113
- minHeight: node.hmStyle?.minHeight || getButtonMinHeight(node),
114
- maxWidth: node.hmStyle?.maxWidth,
115
- maxHeight: node.hmStyle?.maxHeight,
116
- })
117
- .type(ButtonType.Normal)
118
- .onClick((e: ClickEvent) => {
119
- if (node._attrs.formType && ['submit', 'reset'].includes(node._attrs.formType)) {
120
- const eventName = node._attrs.formType + '-btn'
121
- const event: TaroEvent = createTaroEvent(eventName, {}, node)
122
- eventHandler(event, eventName, node)
108
+
109
+ build() {
110
+ Button({ stateEffect: !this.node._attrs.disabled }) {
111
+ if (this.node._attrs.loading) {
112
+ Row() {
113
+ LoadingProgress()
114
+ .width(20).height(20)
115
+ .color(getThemeAttributes(this.node).color)
116
+ this.createLazyChildren(this.node)
117
+ }
118
+ } else {
119
+ this.createLazyChildren(this.node)
120
+ }
123
121
  }
124
- eventHandler(e, 'click', node)
125
- })
126
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
127
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
128
- node._nodeInfo.areaInfo = res[1]
129
- }))
130
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
122
+ .themeStyles(getThemeAttributes(this.node))
123
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
124
+ .constraintSize({
125
+ minWidth: this.node.hmStyle?.minWidth || getButtonMinWidth(this.node),
126
+ minHeight: this.node.hmStyle?.minHeight || getButtonMinHeight(this.node),
127
+ maxWidth: this.node.hmStyle?.maxWidth,
128
+ maxHeight: this.node.hmStyle?.maxHeight,
129
+ })
130
+ .type(ButtonType.Normal)
131
+ .onClick((e: ClickEvent) => {
132
+ if (this.node._attrs.formType && ['submit', 'reset'].includes(this.node._attrs.formType)) {
133
+ const eventName = this.node._attrs.formType + '-btn'
134
+ const event: TaroEvent = createTaroEvent(eventName, {}, this.node)
135
+ eventHandler(event, eventName, this.node)
136
+ }
137
+ eventHandler(e, 'click', this.node)
138
+ })
139
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
140
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
141
+ this.node._nodeInfo.areaInfo = res[1]
142
+ }))
143
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
144
+ }
131
145
  }