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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) 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 +74 -21
  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 +27 -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 +17 -9
  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/memory.ts +10 -3
  28. package/dist/apis/device/motion.ts +6 -0
  29. package/dist/apis/device/network.ts +26 -9
  30. package/dist/apis/device/nfc.ts +10 -0
  31. package/dist/apis/device/phone.ts +2 -1
  32. package/dist/apis/device/scan.ts +4 -0
  33. package/dist/apis/device/screen.ts +2 -1
  34. package/dist/apis/device/sms.ts +4 -0
  35. package/dist/apis/device/vibrate.ts +19 -11
  36. package/dist/apis/device/wifi.ts +15 -0
  37. package/dist/apis/ext/index.ts +5 -0
  38. package/dist/apis/files/index.ts +2 -1
  39. package/dist/apis/files/manager.ts +2 -1
  40. package/dist/apis/framework/index.ts +3 -8
  41. package/dist/apis/index.ts +27 -17
  42. package/dist/apis/location/index.ts +61 -68
  43. package/dist/apis/media/EditorContext.ts +32 -0
  44. package/dist/apis/media/audio/index.ts +18 -0
  45. package/dist/apis/media/background-audio/index.ts +16 -0
  46. package/dist/apis/media/camera.ts +16 -0
  47. package/dist/apis/media/common.ts +2 -1
  48. package/dist/apis/media/{image.ts → image/index.ts} +4 -3
  49. package/dist/apis/media/index.ts +10 -0
  50. package/dist/apis/media/live.ts +5 -0
  51. package/dist/apis/media/map.ts +4 -0
  52. package/dist/apis/media/media-recorder.ts +4 -0
  53. package/dist/apis/media/recorder.ts +6 -0
  54. package/dist/apis/media/video/VideoContext.ts +68 -0
  55. package/dist/apis/media/{video.ts → video/index.ts} +13 -2
  56. package/dist/apis/media/video-decoder.ts +4 -0
  57. package/dist/apis/media/video-processing.ts +4 -0
  58. package/dist/apis/media/voip.ts +19 -0
  59. package/dist/apis/network/index.ts +3 -0
  60. package/dist/apis/network/mdns.ts +13 -0
  61. package/dist/apis/network/request.ts +7 -6
  62. package/dist/apis/network/tcp.ts +4 -0
  63. package/dist/apis/network/udp.ts +4 -0
  64. package/dist/apis/network/webSocket.ts +2 -6
  65. package/dist/apis/open-api/account.ts +4 -0
  66. package/dist/apis/open-api/address.ts +4 -0
  67. package/dist/apis/open-api/authorize.ts +5 -0
  68. package/dist/apis/open-api/card.ts +5 -0
  69. package/dist/apis/open-api/channels-live.ts +11 -0
  70. package/dist/apis/open-api/customer-service.ts +4 -0
  71. package/dist/apis/open-api/device-voip.ts +5 -0
  72. package/dist/apis/open-api/facial.ts +7 -0
  73. package/dist/apis/open-api/favorites.ts +5 -0
  74. package/dist/apis/open-api/group.ts +4 -0
  75. package/dist/apis/open-api/index.ts +20 -6
  76. package/dist/apis/open-api/invoice.ts +5 -0
  77. package/dist/apis/open-api/license-plate.ts +4 -0
  78. package/dist/apis/open-api/login.ts +6 -0
  79. package/dist/apis/open-api/my-miniprogram.ts +4 -0
  80. package/dist/apis/open-api/privacy.ts +7 -0
  81. package/dist/apis/open-api/red-package.ts +4 -0
  82. package/dist/apis/open-api/settings.ts +5 -0
  83. package/dist/apis/open-api/soter.ts +6 -0
  84. package/dist/apis/open-api/subscribe-message.ts +6 -0
  85. package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
  86. package/dist/apis/open-api/werun.ts +5 -0
  87. package/dist/apis/payment/index.ts +6 -0
  88. package/dist/apis/route/index.ts +19 -28
  89. package/dist/apis/share/index.ts +33 -0
  90. package/dist/apis/storage/background-fetch.ts +7 -0
  91. package/dist/apis/storage/cache-manager.ts +4 -0
  92. package/dist/apis/storage/index.ts +158 -88
  93. package/dist/apis/ui/{animation.ts → animation/animation.ts} +73 -31
  94. package/dist/apis/ui/animation/index.ts +7 -0
  95. package/dist/apis/ui/background.ts +4 -19
  96. package/dist/apis/ui/custom-component.ts +8 -0
  97. package/dist/apis/ui/fonts.ts +4 -0
  98. package/dist/apis/ui/index.ts +8 -10
  99. package/dist/apis/ui/interaction/index.ts +45 -59
  100. package/dist/apis/ui/menu.ts +4 -0
  101. package/dist/apis/ui/navigation-bar/index.ts +60 -21
  102. package/dist/apis/ui/pull-down-refresh.ts +10 -4
  103. package/dist/apis/{page → ui/scroll}/index.ts +32 -27
  104. package/dist/apis/ui/sticky.ts +4 -0
  105. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +6 -8
  106. package/dist/apis/ui/window.ts +20 -0
  107. package/dist/apis/utils/handler.ts +4 -4
  108. package/dist/apis/utils/index.ts +1 -1
  109. package/dist/apis/worker/index.ts +4 -0
  110. package/dist/apis/wxml/IntersectionObserver.ts +24 -25
  111. package/dist/apis/wxml/index.ts +7 -2
  112. package/dist/apis/wxml/nodesRef.ts +2 -2
  113. package/dist/apis/wxml/selectorQuery.ts +29 -17
  114. package/dist/components-harmony-ets/button.ets +106 -80
  115. package/dist/components-harmony-ets/canvas.ets +51 -0
  116. package/dist/components-harmony-ets/checkbox.ets +82 -148
  117. package/dist/components-harmony-ets/form.ets +45 -132
  118. package/dist/components-harmony-ets/icon.ets +66 -69
  119. package/dist/components-harmony-ets/image.ets +26 -61
  120. package/dist/components-harmony-ets/index.ets +92 -0
  121. package/dist/components-harmony-ets/innerHtml.ets +7 -70
  122. package/dist/components-harmony-ets/input.ets +60 -146
  123. package/dist/components-harmony-ets/label.ets +86 -92
  124. package/dist/components-harmony-ets/listView.ets +26 -0
  125. package/dist/components-harmony-ets/movableArea.ets +124 -0
  126. package/dist/components-harmony-ets/movableView.ets +93 -0
  127. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  128. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  129. package/dist/components-harmony-ets/picker.ets +172 -198
  130. package/dist/components-harmony-ets/progress.ets +52 -0
  131. package/dist/components-harmony-ets/pseudo.ets +80 -0
  132. package/dist/components-harmony-ets/radio.ets +85 -155
  133. package/dist/components-harmony-ets/richText.ets +15 -87
  134. package/dist/components-harmony-ets/scrollList.ets +94 -0
  135. package/dist/components-harmony-ets/scrollView.ets +81 -149
  136. package/dist/components-harmony-ets/slider.ets +47 -94
  137. package/dist/components-harmony-ets/stickySection.ets +42 -0
  138. package/dist/components-harmony-ets/style.ets +396 -0
  139. package/dist/components-harmony-ets/swiper.ets +51 -151
  140. package/dist/components-harmony-ets/switch.ets +35 -76
  141. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  142. package/dist/components-harmony-ets/text.ets +131 -76
  143. package/dist/components-harmony-ets/textArea.ets +64 -140
  144. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  145. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  146. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  147. package/dist/components-harmony-ets/utils/flexManager.ets +68 -85
  148. package/dist/components-harmony-ets/utils/helper.ets +18 -65
  149. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  150. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  151. package/dist/components-harmony-ets/utils/index.ts +55 -51
  152. package/dist/components-harmony-ets/utils/styles.ets +177 -65
  153. package/dist/components-harmony-ets/video.ets +70 -116
  154. package/dist/components-harmony-ets/view.ets +58 -64
  155. package/dist/components-harmony-ets/webView.ets +56 -0
  156. package/dist/index.d.ts +152 -0
  157. package/dist/index.js +230 -60
  158. package/dist/index.js.map +1 -1
  159. package/dist/runtime-ets/bom/document.ts +6 -4
  160. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  161. package/dist/runtime-ets/bom/window.ts +9 -2
  162. package/dist/runtime-ets/current.ts +3 -0
  163. package/dist/runtime-ets/dom/bind.ts +96 -0
  164. package/dist/runtime-ets/dom/class-list.ts +4 -6
  165. package/dist/runtime-ets/dom/comment.ts +1 -2
  166. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  167. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +30 -20
  168. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  169. package/dist/runtime-ets/dom/document.ts +36 -51
  170. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  171. package/dist/runtime-ets/dom/element/element.ts +439 -0
  172. package/dist/runtime-ets/dom/element/form.ts +403 -0
  173. package/dist/runtime-ets/dom/element/index.ts +120 -0
  174. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  175. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  176. package/dist/runtime-ets/dom/element/normal.ts +103 -0
  177. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  178. package/dist/runtime-ets/dom/element/scrollView.ts +15 -0
  179. package/dist/runtime-ets/dom/element/text.ts +10 -0
  180. package/dist/runtime-ets/dom/element/video.ts +50 -0
  181. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  182. package/dist/runtime-ets/dom/event.ts +26 -5
  183. package/dist/runtime-ets/dom/eventTarget.ts +3 -3
  184. package/dist/runtime-ets/dom/node.ts +114 -49
  185. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  186. package/dist/runtime-ets/dom/stylesheet/index.ts +122 -429
  187. package/dist/runtime-ets/dom/stylesheet/type.ts +93 -17
  188. package/dist/runtime-ets/dom/stylesheet/util.ts +145 -17
  189. package/dist/runtime-ets/index.ts +2 -3
  190. package/dist/runtime-ets/interface/event.ts +3 -2
  191. package/dist/runtime-ets/utils/index.ts +87 -17
  192. package/dist/runtime-ets/utils/info.ts +21 -47
  193. package/dist/runtime-framework/react/app.ts +20 -28
  194. package/dist/runtime-framework/react/hooks.ts +3 -4
  195. package/dist/runtime-framework/react/index.ts +1 -2
  196. package/dist/runtime-framework/react/native-page.ts +421 -0
  197. package/dist/runtime-framework/react/page.ts +5 -17
  198. package/dist/runtime-framework/solid/app.ts +25 -45
  199. package/dist/runtime-framework/solid/connect.ts +21 -3
  200. package/dist/runtime-framework/solid/hooks.ts +17 -12
  201. package/dist/runtime-framework/solid/index.ts +6 -2
  202. package/dist/runtime-framework/solid/page.ts +84 -36
  203. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  204. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  205. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  206. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  207. package/dist/runtime-utils.d.ts +827 -0
  208. package/dist/runtime-utils.js +1633 -549
  209. package/dist/runtime-utils.js.map +1 -1
  210. package/dist/runtime.d.ts +1 -0
  211. package/dist/runtime.js +1633 -549
  212. package/dist/runtime.js.map +1 -1
  213. package/index.js +3 -1
  214. package/package.json +14 -15
  215. package/static/media/cancel.svg +1 -0
  216. package/static/media/circle.svg +1 -0
  217. package/static/media/clear.svg +1 -0
  218. package/static/media/download.svg +1 -0
  219. package/static/media/info.svg +1 -0
  220. package/static/media/info_circle.svg +1 -0
  221. package/static/media/search.svg +1 -0
  222. package/static/media/success.svg +1 -0
  223. package/static/media/success_no_circle.svg +1 -0
  224. package/static/media/taro_arrow_left.svg +1 -0
  225. package/static/media/taro_home.svg +1 -0
  226. package/static/media/waiting.svg +1 -0
  227. package/static/media/warn.svg +1 -0
  228. package/types/harmony.d.ts +4 -0
  229. package/types/index.d.ts +4 -0
  230. package/types/runtime.d.ts +7 -1
  231. package/LICENSE +0 -160
  232. package/dist/components-harmony-ets/base.ets +0 -63
  233. package/dist/components-harmony-ets/element.ets +0 -223
  234. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  235. package/dist/runtime-ets/dom/element.ts +0 -457
  236. package/dist/runtime-ets/dom/text.ts +0 -19
  237. package/dist/runtime-ets/utils/bind.ts +0 -35
  238. package/types/api.d.ts +0 -4
  239. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,59 +1,18 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo,
2
- TaroElement,
3
- TaroAny,
4
- TaroEvent
5
- } from '@tarojs/runtime'
6
-
7
- import { createNode } from './render'
8
- import TaroComponentWrapper from './base'
9
- import { AttributeManager } from './utils/AttributeManager'
1
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
+
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
10
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
11
- import { createTaroEvent } from './utils/events'
12
- import { FlexManager } from './utils/FlexManager'
13
- import { shouldBindEvent, getNormalAttributes, getNodeThresholds, bindAnimation } from './utils/helper'
5
+ import { FlexManager } from './utils/flexManager'
6
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
14
7
 
15
- import type { TaroRadioGroupElement, TaroRadioElement } from './element'
16
- import type { TaroStyleType, HarmonyType } from '@tarojs/runtime'
8
+ import { TaroEvent, TaroAny, HarmonyType, TaroRadioGroupElement, TaroRadioElement } from '@tarojs/runtime'
9
+ import { isUndefined } from '@tarojs/shared'
17
10
 
18
- interface RadioOptions {
19
- group: string
20
- value: string
21
- }
22
11
  interface RadioAttrs {
23
12
  radioStyle?: HarmonyType.RadioStyle
24
13
  themeStyles?: boolean
25
14
  }
26
15
 
27
- @Extend(Radio)
28
- function style (style: TaroStyleType) {
29
- .id(style.id)
30
- .key(style.id)
31
- .padding(style.padding)
32
- .margin(style.margin)
33
- .width(style.width)
34
- .height(style.height)
35
- .constraintSize(style.constraintSize)
36
- .flexGrow(style.flexGrow)
37
- .flexShrink(style.flexShrink)
38
- .flexBasis(style.flexBasis)
39
- .alignSelf(style.alignSelf)
40
- .backgroundColor(style.backgroundColor)
41
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
42
- .backgroundImageSize(style.backgroundImageSize)
43
- .rotate(style.rotate)
44
- .scale(style.scale)
45
- .translate(style.translate)
46
- .transform(style.transform)
47
- .borderStyle(style.borderStyle)
48
- .borderWidth(style.borderWidth)
49
- .borderColor(style.borderColor)
50
- .borderRadius(style.borderRadius)
51
- .linearGradient(style.linearGradient)
52
- .zIndex(style.zIndex)
53
- .opacity(style.opacity)
54
- .clip(style.clip)
55
- }
56
-
57
16
  @Extend(Radio)
58
17
  function radioAttr (attr: RadioAttrs) {
59
18
  .radioStyle(attr.radioStyle)
@@ -76,148 +35,119 @@ function themeStyles(isDisabled: boolean) {
76
35
 
77
36
  @Component
78
37
  export struct TaroRadio {
79
- nodeInfoMap: TaroAny = {}
80
-
38
+ @Builder customBuilder() {}
39
+ @BuilderParam createLazyChildren: (node: TaroRadioElement) => void = this.customBuilder
81
40
  @ObjectLink node: TaroRadioElement
82
-
83
- @State checked: boolean = false
41
+ @State overwriteStyle: Record<string, TaroAny> = {}
84
42
 
85
43
  aboutToAppear () {
86
- initComponentNodeInfo(this, this.node)
87
- bindInstanceToNode(this.node, this)
88
-
89
- this.checked = !!this.node._attrs.checked
90
- }
91
-
92
- @Styles defaultEvent () {
93
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
94
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
95
- const eventResult: TaroAny = res.eventResult
96
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
97
- }))
44
+ if (this.node && !this.node._isInit) {
45
+ this.node._isInit = true
46
+ this.node._instance = this
47
+ this.node._reset = this.node.checked || false
48
+ }
98
49
  }
99
50
 
100
- build() {
101
- TaroComponentWrapper({ node: this.node }) {
102
- Stack() {
103
- Row() {
104
- Radio({
105
- group: this.node.group || this.node.parentNode?._nid || '',
106
- value: this.node._attrs.value || '',
107
- })
108
- .checked(this.checked)
109
- .defaultEvent()
110
- .style(getNormalAttributes(this.node))
111
- .radioAttr(getAttributes(this.node))
112
- .onChange((value: boolean) => {
113
- if (!!this.node._attrs.disabled) {
114
- // FIXME 找下文档是否有强制刷新方法
115
- this.checked = !this.checked
116
- this.checked = !this.checked
51
+ build () {
52
+ Stack() {
53
+ Row() {
54
+ Radio({
55
+ group: this.node.group || this.node.parentNode?._nid || '',
56
+ value: this.node.value || '',
57
+ })
58
+ .checked(this.node.checked)
59
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
60
+ .radioAttr(getAttributes(this.node))
61
+ .onChange((value: boolean) => {
62
+ if (this.node) {
63
+ if (!!this.node?._attrs.disabled) {
64
+ this.node.updateComponent()
117
65
  } else {
118
- this.checked = value
119
- if (this.checked) {
120
- const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node._attrs.value } }, this.node)
66
+ this.node.updateCheckedValue(value)
67
+
68
+ if (value) {
69
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
121
70
  eventHandler(event, 'change', this.node)
122
71
  }
123
72
  }
124
- })
125
- Text(this.node.textContent)
126
- .textAlign(TextAlign.Center)
127
- .opacity(!!this.node._attrs.disabled ? 0.4 : 1)
128
- }
129
- .onClick(() => {
130
- if (!this.checked) {
131
- this.checked = !this.checked
132
- }
133
- })
73
+ }
74
+ })
75
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
76
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
77
+ if (this.node) {
78
+ this.node._nodeInfo.areaInfo = res[1]
79
+ }
80
+ }))
81
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
82
+ Text(this.node.textContent)
83
+ .textAlign(TextAlign.Center)
84
+ .opacity(!!this.node?._attrs.disabled ? 0.4 : 1)
134
85
  }
86
+ .onClick(() => {
87
+ if (this.node) {
88
+ if (!this.node._checked && !this.node?._attrs.disabled) {
89
+ this.node.checked = !this.node.checked
90
+ }
91
+ }
92
+ })
135
93
  }
136
94
  }
137
95
  }
138
96
 
139
- @Extend(Flex)
140
- function radioGroupAttrs (style: TaroStyleType) {
141
- .id(style.id)
142
- .key(style.id)
143
- .padding(style.padding)
144
- .margin(style.margin)
145
- .width(style.width)
146
- .height(style.height)
147
- .constraintSize(style.constraintSize)
148
- .flexGrow(style.flexGrow)
149
- .flexShrink(style.flexShrink)
150
- .flexBasis(style.flexBasis)
151
- .alignSelf(style.alignSelf)
152
- .backgroundColor(style.backgroundColor)
153
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
154
- .backgroundImageSize(style.backgroundImageSize)
155
- .rotate(style.rotate)
156
- .scale(style.scale)
157
- .translate(style.translate)
158
- .transform(style.transform)
159
- .borderStyle(style.borderStyle)
160
- .borderWidth(style.borderWidth)
161
- .borderColor(style.borderColor)
162
- .borderRadius(style.borderRadius)
163
- .linearGradient(style.linearGradient)
164
- .zIndex(style.zIndex)
165
- .opacity(style.opacity)
166
- .clip(style.clip)
167
- }
168
-
169
97
 
170
98
  @Component
171
99
  export struct TaroRadioGroup {
172
- nodeInfoMap: TaroAny = {}
100
+ @Builder customBuilder() {}
101
+ @BuilderParam createLazyChildren: (node: TaroRadioGroupElement) => void = this.customBuilder
102
+ @ObjectLink node: TaroRadioGroupElement
103
+ @State overwriteStyle: Record<string, TaroAny> = {}
173
104
 
174
105
  @Styles visibleChangeEvent () {
175
106
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
176
107
  }
177
108
 
178
- @ObjectLink node: TaroRadioGroupElement
179
-
180
109
  aboutToAppear () {
181
- initComponentNodeInfo(this, this.node)
182
- bindInstanceToNode(this.node, this)
183
- // 绑定动画
184
- bindAnimation(this.node)
185
- const childList = this.node.getElementsByTagName<TaroRadioElement>('RADIO')
186
- childList.forEach(element => {
187
- element.group = this.node._attrs.name || this.node._nid
188
- })
189
- // 阻止事件冒泡传递上去
190
- this.node.addEventListener('change', (e: TaroEvent) => e.stopPropagation())
191
- }
192
-
193
- // Element使用的获取器
194
- getValue (): string | undefined {
195
- const childList = this.node.getElementsByTagName<TaroRadioElement>('RADIO')
196
- for (let i = 0; i < childList.length; i++) {
197
- if (childList[i]._instance.checked) {
198
- return childList[i]._attrs.value
199
- }
110
+ if (this.node) {
111
+ this.node._instance = this
112
+ const childList = this.node.getElementsByTagName<TaroRadioElement>('RADIO')
113
+ childList.forEach(element => {
114
+ element.group = this.node?._attrs.name || this.node?._nid
115
+ })
116
+ // 阻止事件冒泡传递上去
117
+ this.node.addEventListener('change', (e: TaroEvent) => e.stopPropagation())
200
118
  }
201
- return undefined
202
119
  }
203
120
 
204
121
  @Styles defaultEvent () {
205
122
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
206
123
  .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
207
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
208
- const eventResult: TaroAny = res.eventResult
209
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
124
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
125
+ if (this.node) {
126
+ this.node._nodeInfo.areaInfo = res[1]
127
+ }
210
128
  }))
211
129
  }
212
130
 
213
131
  build() {
214
- TaroComponentWrapper({ node: this.node }) {
132
+ if (FlexManager.useFlexLayout(this.node)) {
215
133
  Flex(FlexManager.flexOptions(this.node)) {
216
- ForEach(this.node.childNodes, (item: TaroElement) => {
217
- createNode(item)
218
- }, (item: TaroElement) => item._nid)
134
+ this.createLazyChildren(this.node)
135
+ }
136
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
137
+ .defaultEvent()
138
+ .visibleChangeEvent()
139
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
140
+ Row() {
141
+ this.createLazyChildren(this.node)
142
+ }
143
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
144
+ .defaultEvent()
145
+ .visibleChangeEvent()
146
+ } else {
147
+ Column() {
148
+ this.createLazyChildren(this.node)
219
149
  }
220
- .radioGroupAttrs(getNormalAttributes(this.node))
150
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
221
151
  .defaultEvent()
222
152
  .visibleChangeEvent()
223
153
  }
@@ -1,97 +1,25 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny } from '@tarojs/runtime'
1
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import TaroComponentWrapper from './base'
4
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent, bindAnimation } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { generateText } from './utils'
5
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
5
6
 
6
- import type { RichTextProps } from '@tarojs/components/types/RichText'
7
- import type { TaroRichTextElement } from './element'
8
- import type { TaroStyleType } from '@tarojs/runtime'
9
-
10
- @Extend(RichText)
11
- function attrs (style: TaroStyleType) {
12
- .id(style.id)
13
- .key(style.id)
14
- .padding(style.padding)
15
- .margin(style.margin)
16
- .width(style.width)
17
- .height(style.height)
18
- .constraintSize(style.constraintSize)
19
- .flexGrow(style.flexGrow)
20
- .flexShrink(style.flexShrink)
21
- .flexBasis(style.flexBasis)
22
- .alignSelf(style.alignSelf)
23
- .backgroundColor(style.backgroundColor)
24
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
25
- .backgroundImageSize(style.backgroundImageSize)
26
- .rotate(style.rotate)
27
- .scale(style.scale)
28
- .translate(style.translate)
29
- .transform(style.transform)
30
- .borderStyle(style.borderStyle)
31
- .borderWidth(style.borderWidth)
32
- .borderColor(style.borderColor)
33
- .borderRadius(style.borderRadius)
34
- .linearGradient(style.linearGradient)
35
- .zIndex(style.zIndex)
36
- .opacity(style.opacity)
37
- .clip(style.clip)
38
- }
7
+ import type { TaroAny, TaroRichTextElement } from '@tarojs/runtime'
39
8
 
40
9
  @Component
41
10
  export default struct TaroRichText {
42
- nodeInfoMap: TaroAny = {}
43
-
11
+ @Builder customBuilder() {}
12
+ @BuilderParam createLazyChildren: (node: TaroRichTextElement) => void = this.customBuilder
44
13
  @ObjectLink node: TaroRichTextElement
45
14
 
46
- @Styles visibleChangeEvent () {
47
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
48
- }
49
-
50
- aboutToAppear () {
51
- initComponentNodeInfo(this, this.node)
52
- bindInstanceToNode(this.node, this)
53
- // 绑定动画
54
- bindAnimation(this.node)
55
- }
56
-
57
- @Styles defaultEvent () {
58
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
59
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
60
- const eventResult: TaroAny = res.eventResult
61
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
62
- }))
63
- }
64
-
65
- generateText (): string {
66
- return parseHtmlNode(this.node._attrs.nodes || '')
15
+ build () {
16
+ RichText(generateText(this.node))
17
+ .attributeModifier(commonStyleModify.setNode(this.node))
18
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
19
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
20
+ this.node._nodeInfo.areaInfo = res[1]
21
+ }))
22
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
67
23
  }
68
-
69
- build() {
70
- TaroComponentWrapper({ node: this.node }) {
71
- RichText(this.generateText())
72
- .attrs(getNormalAttributes(this.node))
73
- .defaultEvent()
74
- .visibleChangeEvent()
75
- }
76
- }
77
- }
78
-
79
-
80
- // 将nodeTree转换成harmony需要的string结构
81
- function nodeToHtml(node: RichTextProps.Text | RichTextProps.HTMLElement): string {
82
- if (node.type === 'text') {
83
- return node.text;
84
- }
85
- if (node.attrs) {
86
- const attributes = Object.entries(node.attrs)
87
- .map((item: [string, string]) => `${item[0]}="${item[1]}"`)
88
- .join(' ');
89
- const childrenHtml: string = typeof node.children === 'string' ? node.children : (node.children || []).map((child: RichTextProps.Text | RichTextProps.HTMLElement) => nodeToHtml(child)).join('');
90
- return `<${node.name}${attributes ? ' ' + attributes : ''}>${childrenHtml}</${node.name}>`;
91
- }
92
- return ''
93
24
  }
94
25
 
95
- function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElement> | string) {
96
- return typeof nodes === 'string' ? nodes: `<div>${nodes.map(node => nodeToHtml(node)).join('')}</div>`
97
- }
@@ -0,0 +1,94 @@
1
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
+
3
+ import commonStyleModify from './style'
4
+ import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
6
+
7
+ import type { TaroScrollViewElement, TaroAny, TaroEvent } from '@tarojs/runtime'
8
+
9
+ interface ScrollViewAttrs {
10
+ scrollBar: BarState
11
+ }
12
+ interface ScrollViewCurrentOffset {
13
+ xOffset: number
14
+ yOffset: number
15
+ }
16
+ interface ScrollViewEvent {
17
+ deltaX: number
18
+ deltaY: number
19
+ scrollLeft: number
20
+ scrollTop: number
21
+ scrollWidth: number
22
+ scrollHeight: number
23
+ }
24
+
25
+ function getAttributes (node: TaroScrollViewElement): ScrollViewAttrs {
26
+ const _attrs = node._attrs
27
+ const scrollAttrs: ScrollViewAttrs = {
28
+ scrollBar: typeof _attrs.showScrollbar === 'boolean'
29
+ ? _attrs.showScrollbar ? BarState.On : BarState.Off
30
+ : BarState.Auto
31
+ }
32
+ return scrollAttrs
33
+ }
34
+
35
+ function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', scrollOffset?: number) {
36
+ const currentOffset = node.scroller.currentOffset() as ScrollViewCurrentOffset
37
+ const currentXOffset = currentOffset?.xOffset || 0
38
+ const currentYOffset = currentOffset?.yOffset || 0
39
+ const value: ScrollViewEvent = {
40
+ deltaX: vp2px(node._attrs.scrollX ? scrollOffset : 0),
41
+ deltaY: vp2px(node._attrs.scrollX ? 0 : scrollOffset),
42
+ scrollLeft: vp2px(currentXOffset),
43
+ scrollTop: vp2px(currentYOffset),
44
+ scrollWidth: vp2px(Number(node._nodeInfo?._scroll?.width)),
45
+ scrollHeight: vp2px(Number(node._nodeInfo?._scroll?.height)),
46
+ }
47
+ const event: TaroEvent = createTaroEvent(eventName, { detail: value }, node)
48
+
49
+ eventHandler(event, eventName, node)
50
+ }
51
+
52
+ @Component
53
+ export default struct TaroScrollList {
54
+ @Builder customBuilder() {}
55
+ @BuilderParam createLazyChildren: (node: TaroScrollViewElement) => void = this.customBuilder
56
+ @ObjectLink node: TaroScrollViewElement
57
+ @State overwriteStyle: Record<string, TaroAny> = {}
58
+
59
+ aboutToAppear(): void {
60
+ if (this.node) {
61
+ this.node._instance = this
62
+ }
63
+ }
64
+
65
+ handleScroll = (scrollOffset: number) => {
66
+ handleScrollEvent(this.node, 'scroll', scrollOffset)
67
+ }
68
+
69
+ build() {
70
+ List({
71
+ scroller: this.node.scroller
72
+ }) {
73
+ this.createLazyChildren(this.node)
74
+ }
75
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
76
+ .sticky(StickyStyle.Header)
77
+ .listDirection(this.node.getAttribute('scrollX') ? Axis.Horizontal: Axis.Vertical)
78
+ .align(Alignment.TopStart)
79
+ .clip(true)
80
+ .scrollBar(getAttributes(this.node).scrollBar)
81
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
82
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
83
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
84
+ this.node._nodeInfo.areaInfo = res[1]
85
+ }))
86
+ .onDidScroll(shouldBindEvent((scrollOffset: number) => { handleScrollEvent(this.node, 'scroll', scrollOffset) }, this.node, ['scroll']))
87
+ .onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
88
+ .onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
89
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
90
+ .onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
91
+ }
92
+ }
93
+
94
+