@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/apis/apis.ts +6 -2
  2. package/dist/apis/base/crypto.ts +4 -0
  3. package/dist/apis/base/debug.ts +5 -0
  4. package/dist/apis/base/index.ts +9 -1
  5. package/dist/apis/base/performance.ts +8 -0
  6. package/dist/apis/base/system.ts +1 -1
  7. package/dist/apis/base/update.ts +5 -0
  8. package/dist/apis/base/weapp/app-event.ts +75 -0
  9. package/dist/apis/base/weapp/life-cycle.ts +21 -0
  10. package/dist/apis/canvas/index.ts +18 -0
  11. package/dist/apis/data-analysis/index.ts +6 -0
  12. package/dist/apis/device/accelerometer.ts +2 -1
  13. package/dist/apis/device/accessibility.ts +4 -0
  14. package/dist/apis/device/battery.ts +2 -2
  15. package/dist/apis/device/bluetooth-ble.ts +19 -0
  16. package/dist/apis/device/bluetooth-peripheral.ts +6 -0
  17. package/dist/apis/device/bluetooth.ts +16 -0
  18. package/dist/apis/device/calendar.ts +5 -0
  19. package/dist/apis/device/clipboard.ts +1 -1
  20. package/dist/apis/device/compass.ts +21 -0
  21. package/dist/apis/device/contact.ts +5 -0
  22. package/dist/apis/device/crypto.ts +4 -0
  23. package/dist/apis/device/gyroscope.ts +7 -0
  24. package/dist/apis/device/iBeacon.ts +10 -0
  25. package/dist/apis/device/index.ts +15 -0
  26. package/dist/apis/device/keyboard.ts +2 -1
  27. package/dist/apis/device/motion.ts +6 -0
  28. package/dist/apis/device/network.ts +26 -9
  29. package/dist/apis/device/nfc.ts +10 -0
  30. package/dist/apis/device/phone.ts +2 -1
  31. package/dist/apis/device/scan.ts +4 -0
  32. package/dist/apis/device/screen.ts +2 -1
  33. package/dist/apis/device/sms.ts +4 -0
  34. package/dist/apis/device/vibrate.ts +19 -11
  35. package/dist/apis/device/wifi.ts +15 -0
  36. package/dist/apis/ext/index.ts +5 -0
  37. package/dist/apis/files/index.ts +2 -1
  38. package/dist/apis/files/manager.ts +2 -1
  39. package/dist/apis/framework/index.ts +5 -6
  40. package/dist/apis/location/index.ts +61 -68
  41. package/dist/apis/media/EditorContext.ts +32 -0
  42. package/dist/apis/media/audio/index.ts +18 -0
  43. package/dist/apis/media/background-audio/index.ts +16 -0
  44. package/dist/apis/media/camera.ts +16 -0
  45. package/dist/apis/media/common.ts +2 -1
  46. package/dist/apis/media/{image.ts → image/index.ts} +3 -2
  47. package/dist/apis/media/index.ts +10 -0
  48. package/dist/apis/media/live.ts +5 -0
  49. package/dist/apis/media/map.ts +4 -0
  50. package/dist/apis/media/media-recorder.ts +4 -0
  51. package/dist/apis/media/recorder.ts +6 -0
  52. package/dist/apis/media/video/VideoContext.ts +19 -0
  53. package/dist/apis/media/{video.ts → video/index.ts} +12 -2
  54. package/dist/apis/media/video-decoder.ts +4 -0
  55. package/dist/apis/media/video-processing.ts +4 -0
  56. package/dist/apis/media/voip.ts +19 -0
  57. package/dist/apis/network/index.ts +3 -0
  58. package/dist/apis/network/mdns.ts +13 -0
  59. package/dist/apis/network/request.ts +2 -1
  60. package/dist/apis/network/tcp.ts +4 -0
  61. package/dist/apis/network/udp.ts +4 -0
  62. package/dist/apis/network/webSocket.ts +2 -6
  63. package/dist/apis/open-api/account.ts +4 -0
  64. package/dist/apis/open-api/address.ts +4 -0
  65. package/dist/apis/open-api/authorize.ts +5 -0
  66. package/dist/apis/open-api/card.ts +5 -0
  67. package/dist/apis/open-api/channels-live.ts +11 -0
  68. package/dist/apis/open-api/customer-service.ts +4 -0
  69. package/dist/apis/open-api/device-voip.ts +5 -0
  70. package/dist/apis/open-api/facial.ts +7 -0
  71. package/dist/apis/open-api/favorites.ts +5 -0
  72. package/dist/apis/open-api/group.ts +4 -0
  73. package/dist/apis/open-api/index.ts +20 -6
  74. package/dist/apis/open-api/invoice.ts +5 -0
  75. package/dist/apis/open-api/license-plate.ts +4 -0
  76. package/dist/apis/open-api/login.ts +6 -0
  77. package/dist/apis/open-api/my-miniprogram.ts +4 -0
  78. package/dist/apis/open-api/privacy.ts +7 -0
  79. package/dist/apis/open-api/red-package.ts +4 -0
  80. package/dist/apis/open-api/settings.ts +5 -0
  81. package/dist/apis/open-api/soter.ts +6 -0
  82. package/dist/apis/open-api/subscribe-message.ts +6 -0
  83. package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
  84. package/dist/apis/open-api/werun.ts +5 -0
  85. package/dist/apis/payment/index.ts +6 -0
  86. package/dist/apis/route/index.ts +4 -28
  87. package/dist/apis/share/index.ts +33 -0
  88. package/dist/apis/storage/background-fetch.ts +7 -0
  89. package/dist/apis/storage/cache-manager.ts +4 -0
  90. package/dist/apis/storage/index.ts +20 -18
  91. package/dist/apis/ui/{animation.ts → animation/animation.ts} +2 -2
  92. package/dist/apis/ui/animation/index.ts +7 -0
  93. package/dist/apis/ui/background.ts +2 -18
  94. package/dist/apis/ui/custom-component.ts +8 -0
  95. package/dist/apis/ui/fonts.ts +4 -0
  96. package/dist/apis/ui/index.ts +8 -10
  97. package/dist/apis/ui/interaction/index.ts +3 -0
  98. package/dist/apis/ui/menu.ts +4 -0
  99. package/dist/apis/ui/navigation-bar/index.ts +60 -21
  100. package/dist/apis/ui/pull-down-refresh.ts +1 -1
  101. package/dist/apis/{page → ui/scroll}/index.ts +27 -22
  102. package/dist/apis/ui/sticky.ts +4 -0
  103. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +3 -5
  104. package/dist/apis/ui/window.ts +20 -0
  105. package/dist/apis/utils/handler.ts +4 -4
  106. package/dist/apis/worker/index.ts +4 -0
  107. package/dist/apis/wxml/IntersectionObserver.ts +12 -21
  108. package/dist/apis/wxml/index.ts +5 -2
  109. package/dist/apis/wxml/nodesRef.ts +2 -2
  110. package/dist/apis/wxml/selectorQuery.ts +3 -4
  111. package/dist/components-harmony-ets/button.ets +90 -64
  112. package/dist/components-harmony-ets/checkbox.ets +53 -98
  113. package/dist/components-harmony-ets/form.ets +16 -112
  114. package/dist/components-harmony-ets/icon.ets +59 -46
  115. package/dist/components-harmony-ets/image.ets +15 -40
  116. package/dist/components-harmony-ets/innerHtml.ets +6 -74
  117. package/dist/components-harmony-ets/input.ets +58 -128
  118. package/dist/components-harmony-ets/label.ets +43 -69
  119. package/dist/components-harmony-ets/picker.ets +114 -137
  120. package/dist/components-harmony-ets/radio.ets +55 -103
  121. package/dist/components-harmony-ets/richText.ets +17 -41
  122. package/dist/components-harmony-ets/scrollView.ets +69 -101
  123. package/dist/components-harmony-ets/slider.ets +35 -58
  124. package/dist/components-harmony-ets/swiper.ets +24 -135
  125. package/dist/components-harmony-ets/switch.ets +25 -55
  126. package/dist/components-harmony-ets/text.ets +42 -46
  127. package/dist/components-harmony-ets/textArea.ets +39 -107
  128. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  129. package/dist/components-harmony-ets/utils/flexManager.ets +3 -88
  130. package/dist/components-harmony-ets/utils/helper.ets +2 -62
  131. package/dist/components-harmony-ets/utils/index.ts +1 -1
  132. package/dist/components-harmony-ets/utils/styles.ets +6 -9
  133. package/dist/components-harmony-ets/video.ets +63 -92
  134. package/dist/components-harmony-ets/view.ets +65 -40
  135. package/dist/index.js +33 -4
  136. package/dist/index.js.map +1 -1
  137. package/dist/runtime-ets/bom/getComputedStyle.ts +1 -1
  138. package/dist/runtime-ets/dom/bind.ts +80 -0
  139. package/dist/runtime-ets/dom/class-list.ts +2 -4
  140. package/dist/runtime-ets/dom/comment.ts +1 -2
  141. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +1 -1
  142. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  143. package/dist/runtime-ets/dom/document.ts +14 -43
  144. package/dist/runtime-ets/dom/element/element.ts +162 -0
  145. package/dist/runtime-ets/dom/element/form.ts +397 -0
  146. package/dist/runtime-ets/dom/element/index.ts +89 -0
  147. package/dist/runtime-ets/dom/element/normal.ts +75 -0
  148. package/dist/runtime-ets/dom/element/scrollView.ts +14 -0
  149. package/dist/runtime-ets/dom/element/text.ts +17 -0
  150. package/dist/runtime-ets/dom/element/video.ts +49 -0
  151. package/dist/runtime-ets/dom/event.ts +24 -1
  152. package/dist/runtime-ets/dom/eventTarget.ts +2 -1
  153. package/dist/runtime-ets/dom/node.ts +74 -44
  154. package/dist/runtime-ets/dom/stylesheet/index.ts +136 -23
  155. package/dist/runtime-ets/dom/stylesheet/type.ts +4 -3
  156. package/dist/runtime-ets/dom/stylesheet/util.ts +71 -1
  157. package/dist/runtime-ets/index.ts +0 -1
  158. package/dist/runtime-ets/utils/bind.ts +3 -14
  159. package/dist/runtime-ets/utils/index.ts +12 -7
  160. package/dist/runtime-ets/utils/info.ts +22 -50
  161. package/dist/runtime-framework/react/app.ts +3 -6
  162. package/dist/runtime-framework/react/page.ts +2 -9
  163. package/dist/runtime-framework/solid/page.ts +0 -6
  164. package/dist/runtime-utils.js +1150 -339
  165. package/dist/runtime-utils.js.map +1 -1
  166. package/dist/runtime.js +1150 -339
  167. package/dist/runtime.js.map +1 -1
  168. package/package.json +8 -8
  169. package/types/runtime.d.ts +4 -0
  170. package/LICENSE +0 -160
  171. package/dist/components-harmony-ets/base.ets +0 -63
  172. package/dist/components-harmony-ets/element.ets +0 -223
  173. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  174. package/dist/runtime-ets/dom/element.ts +0 -457
  175. package/dist/runtime-ets/dom/text.ts +0 -19
  176. package/types/api.d.ts +0 -4
@@ -11,7 +11,7 @@ interface IMethodParam<T = Partial<ICallbackResult>> {
11
11
  name: string
12
12
  success?: TCallback<T & ICallbackResult>
13
13
  fail?: TCallback
14
- complete?: TCallback
14
+ complete?: TCallback<T | ICallbackResult>
15
15
  }
16
16
  interface IMockPromise {
17
17
  resolve?: typeof Promise.resolve | TFunc
@@ -23,7 +23,7 @@ export class MethodHandler<T = Partial<ICallbackResult>> {
23
23
 
24
24
  protected __success?: TCallback<T>
25
25
  protected __fail?: TCallback
26
- protected __complete?: TCallback
26
+ protected __complete?: TCallback<T | ICallbackResult>
27
27
 
28
28
  protected isHandlerError = false
29
29
 
@@ -41,7 +41,7 @@ export class MethodHandler<T = Partial<ICallbackResult>> {
41
41
  res.errMsg = `${this.methodName}:ok`
42
42
  }
43
43
  isFunction(this.__success) && this.__success(res as T)
44
- isFunction(this.__complete) && this.__complete(res)
44
+ isFunction(this.__complete) && this.__complete(res as T)
45
45
 
46
46
  const { resolve = Promise.resolve.bind(Promise) } = promise
47
47
  return resolve(res as Required<T & U & ICallbackResult>)
@@ -54,7 +54,7 @@ export class MethodHandler<T = Partial<ICallbackResult>> {
54
54
  res.errMsg = `${this.methodName}:fail ${res.errMsg}`
55
55
  }
56
56
  isFunction(this.__fail) && this.__fail(res)
57
- isFunction(this.__complete) && this.__complete(res)
57
+ isFunction(this.__complete) && this.__complete(res as ICallbackResult)
58
58
 
59
59
  const {
60
60
  resolve = Promise.resolve.bind(Promise),
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // Worker
4
+ export const createWorker = /* @__PURE__ */ temporarilyNotSupport('createWorker')
@@ -1,9 +1,9 @@
1
- import Taro from '@tarojs/api'
2
- // @ts-ignore
3
1
  import { Current, disconnectEvent, findChildNodeWithDFS, getPageScrollerOrNode, setNodeEventCallbackAndTriggerComponentUpdate, TaroElement, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
4
2
 
5
3
  import { temporarilyNotSupport } from '../utils'
6
4
 
5
+ import type Taro from '@tarojs/taro/types'
6
+
7
7
  export class IntersectionObserver implements Taro.IntersectionObserver {
8
8
  // 自定义组件实例
9
9
  private _component: any
@@ -29,17 +29,15 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
29
29
  if (this._observerNodes instanceof Array) {
30
30
  this._observerNodes.forEach((n: TaroElement & any) => {
31
31
  disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME)
32
- if (n._instance) {
33
- // @ts-ignore
34
- n._instance?.nodeInfoMap?.[n._nid]?.thresholds = null
35
- }
32
+ // @ts-ignore
33
+ n._nodeInfo?.thresholds = null
36
34
  })
37
35
  } else {
38
36
  disconnectEvent(this._observerNodes, VISIBLE_CHANGE_EVENT_NAME)
39
37
  // @ts-ignore
40
- if (this._observerNodes._instance) {
38
+ if (this._observerNodes._nodeInfo) {
41
39
  // @ts-ignore
42
- this._observerNodes._instance?.nodeInfoMap?.[this._observerNodes._nid]?.thresholds = null
40
+ this._observerNodes._nodeInfo?.thresholds = null
43
41
  }
44
42
  }
45
43
  }
@@ -50,29 +48,22 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
50
48
  const node = findChildNodeWithDFS(this._component, targetSelector, observeAll)
51
49
  this._observerNodes = node
52
50
 
53
-
54
51
  if (node) {
55
52
  if (node instanceof Array) {
56
53
  node.forEach(n => {
57
54
  // @ts-ignore
58
- n.awaitAppear.then(() => {
59
- // @ts-ignore
60
- n._instance?.nodeInfoMap?.[n._nid]?.thresholds = thresholds
55
+ n._nodeInfo?.thresholds = thresholds
61
56
 
62
- setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
63
- callback(this.handleResult(isVisible, currentRatio))
64
- })
57
+ setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
58
+ callback(this.handleResult(isVisible, currentRatio))
65
59
  })
66
60
  })
67
61
  } else {
68
62
  // @ts-ignore
69
- node.awaitAppear.then(() => {
70
- // @ts-ignore
71
- node._instance?.nodeInfoMap?.[node._nid]?.thresholds = thresholds
63
+ node._nodeInfo?.thresholds = thresholds
72
64
 
73
- setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
74
- callback(this.handleResult(isVisible, currentRatio))
75
- })
65
+ setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
66
+ callback(this.handleResult(isVisible, currentRatio))
76
67
  })
77
68
  }
78
69
  }
@@ -1,8 +1,9 @@
1
- import Taro from '@tarojs/taro'
2
-
1
+ import { temporarilyNotSupport } from '../utils'
3
2
  import { IntersectionObserver } from './IntersectionObserver'
4
3
  import { SelectorQuery } from './selectorQuery'
5
4
 
5
+ import type Taro from '@tarojs/taro/types'
6
+
6
7
  export const createSelectorQuery = () => {
7
8
  return new SelectorQuery()
8
9
  }
@@ -10,3 +11,5 @@ export const createSelectorQuery = () => {
10
11
  export const createIntersectionObserver: typeof Taro.createIntersectionObserver = (component, options) => {
11
12
  return new IntersectionObserver(component, options)
12
13
  }
14
+
15
+ export const createMediaQueryObserver = /* @__PURE__ */ temporarilyNotSupport('createMediaQueryObserver')
@@ -1,7 +1,7 @@
1
- import Taro from '@tarojs/api'
2
-
3
1
  import { SelectorQuery } from './selectorQuery'
4
2
 
3
+ import type Taro from '@tarojs/taro/types'
4
+
5
5
  export class NodesRef implements Taro.NodesRef {
6
6
  _component?: any
7
7
  _selector: string
@@ -2,7 +2,7 @@ import { AREA_CHANGE_EVENT_NAME, Current, getPageScrollerOrNode, setNodeEventCal
2
2
 
3
3
  import { NodesRef } from './nodesRef'
4
4
 
5
- import type Taro from '@tarojs/api'
5
+ import type Taro from '@tarojs/taro/types'
6
6
 
7
7
  interface ISelectorQueryQueue {
8
8
  component: any
@@ -135,8 +135,7 @@ function filter (fields, dom) {
135
135
  // if (dataset) res.dataset = Object.assign({}, dom.dataset)
136
136
 
137
137
  if (rect || size) {
138
- const id = dom?._nid
139
- const { areaInfo } = dom?._instance?.nodeInfoMap?.[id] || {}
138
+ const { areaInfo } = dom?._nodeInfo || {}
140
139
 
141
140
  if (areaInfo) {
142
141
  if (rect) {
@@ -153,7 +152,7 @@ function filter (fields, dom) {
153
152
  }
154
153
  }
155
154
  if (scrollOffset) {
156
- const scroller = dom._instance.scroller
155
+ const scroller = dom.scroller
157
156
 
158
157
  if (scroller) {
159
158
  const { xOffset, yOffset } = scroller.currentOffset()
@@ -1,58 +1,68 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo } from '@tarojs/runtime'
2
- import { createNode } from './render'
3
- import TaroComponentWrapper from './base'
4
- import { createTaroEvent } from './utils/events'
1
+ import { eventHandler, createTaroEvent, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
+ import { createLazyChildren } from './render'
5
3
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
6
- import { AttributeManager } from './utils/AttributeManager'
7
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
8
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
5
+ import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
9
6
 
10
- import type { TaroAny, TaroEvent } from '@tarojs/runtime'
11
- import type { TaroButtonElement, TaroElement } from './element'
12
- import type { TaroStyleType } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroEvent, TaroButtonElement, TaroStyleType } from '@tarojs/runtime'
13
8
 
14
9
  @Extend(Button)
15
10
  function attrs (style: TaroStyleType) {
16
11
  .id(style.id)
17
12
  .key(style.id)
18
- .padding(style.padding)
19
- .margin(style.margin)
20
13
  .width(style.width)
21
14
  .height(style.height)
22
- .constraintSize(style.constraintSize)
15
+ .padding({
16
+ top: style.padding?.top,
17
+ left: style.padding?.left || 10,
18
+ right: style.padding?.right || 10,
19
+ bottom: style.padding?.bottom,
20
+ })
21
+ .margin(style.margin)
23
22
  .flexGrow(style.flexGrow)
24
23
  .flexShrink(style.flexShrink)
25
24
  .flexBasis(style.flexBasis)
26
25
  .alignSelf(style.alignSelf)
27
- .backgroundColor(style.backgroundColor)
28
26
  .backgroundImage(style.backgroundImage, style.backgroundRepeat)
29
27
  .backgroundImageSize(style.backgroundImageSize)
28
+ .backgroundImagePosition(style.backgroundImagePosition)
30
29
  .rotate(style.rotate)
31
30
  .scale(style.scale)
32
31
  .translate(style.translate)
33
32
  .transform(style.transform)
34
33
  .borderStyle(style.borderStyle)
35
- .borderWidth(style.borderWidth)
36
- .borderColor(style.borderColor)
37
- .borderRadius(style.borderRadius)
38
34
  .linearGradient(style.linearGradient)
39
35
  .zIndex(style.zIndex)
40
- .opacity(style.opacity)
41
36
  .clip(style.clip)
42
37
  }
43
38
 
44
-
45
39
  @Extend(Button)
46
40
  function themeStyles(style: TaroStyleType) {
47
- .border({
48
- width: 1,
49
- color: style.backgroundColor
50
- })
51
41
  .fontColor(style.color)
52
42
  .opacity(style.opacity)
43
+ .borderColor(style.borderColor)
44
+ .borderWidth(style.borderWidth)
45
+ .borderRadius(style.borderRadius)
53
46
  .backgroundColor(style.backgroundColor)
54
47
  }
55
48
 
49
+ export function getButtonColor (node: TaroButtonElement, color: ResourceColor) {
50
+ const _attrs = node._attrs
51
+ const isDisabled: boolean = _attrs.disabled || false
52
+ const isPlain: boolean = _attrs.plain || false
53
+ const type: string = _attrs.type || 'default'
54
+
55
+ if (isDisabled && isPlain) {
56
+ return Color.Black
57
+ }
58
+
59
+ if (isPlain) {
60
+ return BUTTON_THEME_COLOR.get(type).plainText
61
+ }
62
+
63
+ return color
64
+ }
65
+
56
66
  function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
57
67
  const hmStyle = node.hmStyle
58
68
  const _attrs = node._attrs
@@ -61,59 +71,75 @@ function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
61
71
  const type: string = _attrs.type || 'default'
62
72
 
63
73
  return {
64
- opacity: isDisabled ? 0.4 : 1,
74
+ borderColor: hmStyle.borderColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
75
+ borderWidth: hmStyle.borderWidth || 1,
76
+ borderRadius: hmStyle.borderRadius || convertNumber2VP(10),
77
+ opacity: isDisabled ? 0.4 : hmStyle.opacity,
65
78
  backgroundColor: isPlain ? Color.Transparent : (hmStyle.backgroundColor || BUTTON_THEME_COLOR.get(type).background),
66
- color: hmStyle.color || BUTTON_THEME_COLOR.get(type).text,
79
+ color: hmStyle.color || getButtonColor(node, BUTTON_THEME_COLOR.get(type).text),
67
80
  }
68
81
  }
69
82
 
70
- @Component
71
- export default struct TaroButton {
72
- nodeInfoMap: TaroAny = {}
83
+ function getButtonWidth (node: TaroButtonElement) {
84
+ const isMini = node._attrs.size === 'mini'
85
+
86
+ return isMini ? convertNumber2VP(120) : '100%'
87
+ }
73
88
 
74
- @ObjectLink node: TaroButtonElement
89
+ function getButtonHeight (node: TaroButtonElement) {
90
+ const isMini = node._attrs.size === 'mini'
75
91
 
76
- @Styles visibleChangeEvent () {
77
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
92
+ return isMini ? convertNumber2VP(60) : convertNumber2VP(92)
93
+ }
94
+
95
+ function getButtonMinWidth (node: TaroButtonElement): string | number | undefined {
96
+ if (node.hmStyle.width) {
97
+ return undefined
78
98
  }
79
99
 
80
- aboutToAppear () {
81
- initComponentNodeInfo(this, this.node)
82
- bindInstanceToNode(this.node, this)
83
- // 绑定动画
84
- bindAnimation(this.node)
100
+ return getButtonWidth(node)
101
+ }
102
+
103
+ function getButtonMinHeight (node: TaroButtonElement): string | number | undefined {
104
+ if (node.hmStyle.height) {
105
+ return undefined
85
106
  }
86
107
 
87
- build() {
88
- TaroComponentWrapper({ node: this.node }) {
89
- Button({ stateEffect: !this.node._attrs.disabled }) {
90
- Row() {
91
- if (this.node._attrs.loading) {
92
- LoadingProgress()
93
- .width(20).height(20)
94
- .color(getThemeAttributes(this.node).color)
95
- }
96
- ForEach(this.node.childNodes, (item: TaroElement) => {
97
- createNode(item)
98
- }, (item: TaroElement) => item._nid)
99
- }
108
+ return getButtonHeight(node)
109
+ }
110
+
111
+ @Builder
112
+ export default function TaroButton (node: TaroButtonElement) {
113
+ Button({ stateEffect: !node._attrs.disabled }) {
114
+ Row() {
115
+ if (node._attrs.loading) {
116
+ LoadingProgress()
117
+ .width(20).height(20)
118
+ .color(getThemeAttributes(node).color)
100
119
  }
101
- .attrs(getNormalAttributes(this.node))
102
- .themeStyles(getThemeAttributes(this.node))
103
- .onClick((e: ClickEvent) => {
104
- if (['submit', 'reset'].includes(this.node._attrs.formType)) {
105
- const eventName = this.node._attrs.formType + '-btn'
106
- const event: TaroEvent = createTaroEvent(eventName, {}, this.node)
107
- eventHandler(event, eventName, this.node)
108
- }
109
- eventHandler(e, 'click', this.node)
110
- })
111
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
112
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
113
- const eventResult: TaroAny = res.eventResult
114
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
115
- }))
116
- .visibleChangeEvent()
120
+ createLazyChildren(node)
117
121
  }
118
122
  }
123
+ .themeStyles(getThemeAttributes(node))
124
+ .attrs(getNormalAttributes(node))
125
+ .constraintSize({
126
+ minWidth: node.hmStyle?.constraintSize?.minWidth || getButtonMinWidth(node),
127
+ minHeight: node.hmStyle?.constraintSize?.minHeight || getButtonMinHeight(node),
128
+ maxWidth: node.hmStyle?.constraintSize?.maxWidth,
129
+ maxHeight: node.hmStyle?.constraintSize?.maxHeight,
130
+ })
131
+ .type(ButtonType.Normal)
132
+ .onClick((e: ClickEvent) => {
133
+ if (['submit', 'reset'].includes(node._attrs.formType)) {
134
+ const eventName = node._attrs.formType + '-btn'
135
+ const event: TaroEvent = createTaroEvent(eventName, {}, node)
136
+ eventHandler(event, eventName, node)
137
+ }
138
+ eventHandler(e, 'click', node)
139
+ })
140
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
141
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
142
+ node._nodeInfo.areaInfo = res[1]
143
+ }))
144
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
119
145
  }
@@ -1,13 +1,10 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny, TaroEvent } from '@tarojs/runtime'
1
+ import { createTaroEvent, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import TaroComponentWrapper from './base'
4
- import { createNode } from './render'
5
- import { createTaroEvent } from './utils/events'
3
+ import { createLazyChildren } from './render'
6
4
  import { FlexManager } from './utils/FlexManager'
7
5
  import { shouldBindEvent, getNormalAttributes, getNodeThresholds } from './utils/helper'
8
6
 
9
- import type { TaroCheckboxElement, TaroCheckboxGroupElement, TaroElement } from './element'
10
- import type { TaroStyleType } from '@tarojs/runtime'
7
+ import type { TaroStyleType, TaroAny, TaroEvent, TaroCheckboxElement, TaroCheckboxGroupElement } from '@tarojs/runtime'
11
8
 
12
9
  interface CheckboxOptions {
13
10
  name?: string
@@ -33,6 +30,7 @@ function checkboxStyle (style: TaroStyleType) {
33
30
  .backgroundColor(style.backgroundColor)
34
31
  .backgroundImage(style.backgroundImage, style.backgroundRepeat)
35
32
  .backgroundImageSize(style.backgroundImageSize)
33
+ .backgroundImagePosition(style.backgroundImagePosition)
36
34
  .rotate(style.rotate)
37
35
  .scale(style.scale)
38
36
  .translate(style.translate)
@@ -60,77 +58,49 @@ function getAttributes (node: TaroCheckboxElement): CheckboxAttrs {
60
58
  }
61
59
 
62
60
  function getOptions (node: TaroCheckboxElement): CheckboxOptions {
63
- const value: string = node._attrs.value
64
61
  return {
65
- name: value || node.textContent
62
+ name: node.value as string || node.textContent
66
63
  }
67
64
  }
68
65
 
69
-
70
- @Component
71
- export struct TaroCheckbox {
72
- nodeInfoMap: TaroAny = {}
73
-
74
- @ObjectLink node: TaroCheckboxElement
75
-
76
- @State checked: boolean = false
77
-
78
- @Styles visibleChangeEvent () {
79
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
- }
81
-
82
- aboutToAppear () {
83
- initComponentNodeInfo(this, this.node)
84
- bindInstanceToNode(this.node, this)
85
-
86
- this.checked = !!this.node._attrs.checked
87
- }
88
-
89
- @Styles defaultEvent () {
90
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
91
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
92
- const eventResult: TaroAny = res.eventResult
93
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
94
- }))
95
- }
96
-
97
- build() {
98
- TaroComponentWrapper({ node: this.node }) {
99
- Stack() {
100
- Row() {
101
- Checkbox(getOptions(this.node))
102
- .defaultEvent()
103
- .checkboxStyle(getNormalAttributes(this.node))
104
- .checkboxAttr(getAttributes(this.node))
105
- .opacity(!!this.node._attrs.disabled ? 0.4 : 1)
106
- .select(this.checked)
107
- .onChange((value: boolean) => {
108
- if (!!this.node._attrs.disabled) {
109
- // FIXME 找下文档是否有强制刷新方法
110
- this.checked = !this.checked
111
- this.checked = !this.checked
112
- } else {
113
- this.checked = value
114
- if (this.checked) {
115
- const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node._attrs.value } }, this.node)
116
- eventHandler(event, 'change', this.node)
117
- }
118
- }
119
- })
120
- .visibleChangeEvent()
121
- Text(this.node.textContent)
122
- .textAlign(TextAlign.Center)
123
- .opacity(!!this.node._attrs.disabled ? 0.4 : 1)
124
- }
125
- .onClick(() => {
126
- this.checked = !this.checked
66
+ @Builder
67
+ export function TaroCheckbox(node: TaroCheckboxElement) {
68
+ Stack() {
69
+ Row() {
70
+ Checkbox(getOptions(node))
71
+ .checkboxStyle(getNormalAttributes(node))
72
+ .checkboxAttr(getAttributes(node))
73
+ .opacity(!!node._attrs.disabled ? 0.4 : 1)
74
+ .select(node.checked)
75
+ .onChange((value: boolean) => {
76
+ if (!!node?._attrs.disabled) {
77
+ node.updateComponent()
78
+ } else {
79
+ node.updateCheckedValue(value)
80
+
81
+ if (value) {
82
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: node?._attrs.value } }, node)
83
+ eventHandler(event, 'change', node)
84
+ }
85
+ }
127
86
  })
128
- }
87
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
88
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
89
+ node._nodeInfo.areaInfo = res[1]
90
+ }))
91
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
92
+ Text(node.textContent)
93
+ .textAlign(TextAlign.Center)
94
+ .opacity(!!node._attrs.disabled ? 0.4 : 1)
129
95
  }
96
+ .onClick(() => {
97
+ if (!node?._attrs.disabled) {
98
+ node.checked = !node.checked
99
+ }
100
+ })
130
101
  }
131
102
  }
132
103
 
133
-
134
104
  @Extend(Flex)
135
105
  function checkboxGroupAttrs (style: TaroStyleType) {
136
106
  .id(style.id)
@@ -147,6 +117,7 @@ function checkboxGroupAttrs (style: TaroStyleType) {
147
117
  .backgroundColor(style.backgroundColor)
148
118
  .backgroundImage(style.backgroundImage, style.backgroundRepeat)
149
119
  .backgroundImageSize(style.backgroundImageSize)
120
+ .backgroundImagePosition(style.backgroundImagePosition)
150
121
  .rotate(style.rotate)
151
122
  .scale(style.scale)
152
123
  .translate(style.translate)
@@ -165,51 +136,35 @@ interface ChangeEventDetail { value: string[] }
165
136
 
166
137
  @Component
167
138
  export struct TaroCheckboxGroup {
168
- nodeInfoMap: TaroAny = {}
169
-
170
- @ObjectLink node: TaroCheckboxGroupElement
139
+ node: TaroCheckboxGroupElement | null = null
171
140
 
172
141
  @Styles visibleChangeEvent () {
173
142
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
174
143
  }
175
144
 
176
145
  aboutToAppear () {
177
- initComponentNodeInfo(this, this.node)
178
- bindInstanceToNode(this.node, this)
179
-
180
- // 阻止事件冒泡传递上去
181
- this.node.addEventListener('change', (e: TaroEvent<ChangeEventDetail>) => {
182
- e.stopPropagation()
183
- e.detail.value = this.getValues()
184
- })
185
- }
186
-
187
- // Element使用的获取值方法
188
- getValues () {
189
- const childList = this.node.getElementsByTagName<TaroCheckboxElement>('CHECKBOX')
190
- const result: string[] = []
191
- childList.forEach(element => {
192
- if (element._instance.checked) {
193
- result.push(element._attrs.value)
194
- }
195
- })
196
- return result
146
+ if (this.node) {
147
+ // 阻止事件冒泡传递上去
148
+ this.node.addEventListener('change', (e: TaroEvent<ChangeEventDetail>) => {
149
+ e.stopPropagation()
150
+ e.detail.value = (this.node as TaroCheckboxGroupElement).value
151
+ })
152
+ }
197
153
  }
198
154
 
199
155
  @Styles defaultEvent () {
200
156
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
201
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
202
- const eventResult: TaroAny = res.eventResult
203
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
157
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
158
+ if (this.node) {
159
+ this.node._nodeInfo.areaInfo = res[1]
160
+ }
204
161
  }))
205
162
  }
206
163
 
207
164
  build() {
208
- TaroComponentWrapper({ node: this.node }) {
165
+ if (this.node) {
209
166
  Flex(FlexManager.flexOptions(this.node)) {
210
- ForEach(this.node.childNodes, (item: TaroElement) => {
211
- createNode(item)
212
- }, (item: TaroElement) => item._nid)
167
+ createLazyChildren(this.node)
213
168
  }
214
169
  .checkboxGroupAttrs(getNormalAttributes(this.node))
215
170
  .defaultEvent()