@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,50 +1,18 @@
1
- import window from '@ohos.window'
2
- import common from '@ohos.app.ability.common'
3
- import { isNumber, isUndefined } from '@tarojs/shared'
4
- import { bindFocus, bindInstanceToNode, eventHandler, Current, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo,
5
- TaroEvent, TaroAny } from '@tarojs/runtime'
1
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
6
2
 
7
- import TaroComponentWrapper from './base'
8
- import { createTaroEvent } from './utils/events'
9
- import { AttributeManager } from './utils/AttributeManager'
10
- import { getNormalAttributes, parseStyles, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
11
- import { TEXT_DEFAULT_STYLE, INPUT_TYPE_MAP, INPUT_CONFIRM_MAP } from './utils/constant/style'
3
+ import commonStyleModify from './style'
4
+ import { parseStyles, shouldBindEvent, getNodeThresholds } from './utils/helper'
5
+ import { INPUT_TYPE_MAP, INPUT_CONFIRM_MAP } from './utils/constant/style'
12
6
 
13
- import type { TaroInputElement } from './element'
14
- import type { TaroStyleType } from '@tarojs/runtime'
7
+ import type { TaroStyleType, TaroAny, TaroInputElement, TaroEvent } from '@tarojs/runtime'
15
8
 
16
9
  interface InputAttrs {
17
10
  textAlign?: TextAlign
11
+ autoFocus?: boolean
18
12
  }
19
13
 
20
14
  @Extend(TextInput)
21
15
  function styles (style: TaroStyleType) {
22
- .id(style.id)
23
- .key(style.id)
24
- .padding(style.padding)
25
- .margin(style.margin)
26
- .width(style.width)
27
- .height(style.height)
28
- .constraintSize(style.constraintSize)
29
- .flexGrow(style.flexGrow)
30
- .flexShrink(style.flexShrink)
31
- .flexBasis(style.flexBasis)
32
- .alignSelf(style.alignSelf)
33
- .backgroundColor(style.backgroundColor)
34
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
35
- .backgroundImageSize(style.backgroundImageSize)
36
- .rotate(style.rotate)
37
- .scale(style.scale)
38
- .translate(style.translate)
39
- .transform(style.transform)
40
- .borderStyle(style.borderStyle)
41
- .borderWidth(style.borderWidth)
42
- .borderColor(style.borderColor)
43
- .borderRadius(style.borderRadius)
44
- .linearGradient(style.linearGradient)
45
- .zIndex(style.zIndex)
46
- .opacity(style.opacity)
47
- .clip(style.clip)
48
16
  .fontColor(style.color)
49
17
  .fontSize(style.fontSize)
50
18
  .fontWeight(style.fontWeight)
@@ -55,141 +23,87 @@ function styles (style: TaroStyleType) {
55
23
  @Extend(TextInput)
56
24
  function attrs(attr: InputAttrs) {
57
25
  .textAlign(attr.textAlign)
26
+ .defaultFocus(attr.autoFocus)
58
27
  }
59
28
 
60
-
61
29
  function getAttributes(node: TaroInputElement): InputAttrs {
62
30
  return {
63
31
  textAlign: node.hmStyle.textAlign,
32
+ autoFocus: node._attrs.autoFocus || node._attrs.focus || false,
64
33
  }
65
34
  }
66
35
 
67
- @Component
68
- struct TaroInput {
69
- nodeInfoMap: TaroAny = {}
70
-
71
- @State text: string = ''
72
-
73
- @ObjectLink node: TaroInputElement
36
+ function getInputType (node: TaroInputElement) {
37
+ if (node._attrs?.password) return InputType.Password
74
38
 
75
- controller: TextInputController = new TextInputController()
39
+ return INPUT_TYPE_MAP.get(node._attrs?.type || '') || InputType.Normal
40
+ }
76
41
 
77
- windowClass?: window.Window
42
+ function getPlaceholderColor (node: TaroInputElement): string {
43
+ const placeholderTextColor: string = node._attrs.placeholderTextColor || ''
44
+ const placeholderStyle: string = node._attrs.placeholderStyle || ''
78
45
 
79
- _height: number = 0
46
+ return placeholderTextColor || parseStyles(placeholderStyle)?.color
47
+ }
80
48
 
81
- @Styles visibleChangeEvent () {
82
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
83
- }
49
+ @Component
50
+ export default struct TaroInput {
51
+ @State value: string = ''
84
52
 
85
- heightChange = (height: number) => {
86
- if (isNumber(height)) {
87
- if (this._height !== height) {
88
- this.onKeyboardHeightChange(height)
89
- this._height = height
90
- }
91
- }
92
- }
53
+ @Builder customBuilder() {}
54
+ @BuilderParam createLazyChildren: (node: TaroInputElement) => void = this.customBuilder
55
+ @ObjectLink node: TaroInputElement
56
+ @State overwriteStyle: Record<string, TaroAny> = {}
93
57
 
94
58
  aboutToAppear () {
95
- initComponentNodeInfo(this, this.node)
96
- bindInstanceToNode(this.node, this)
97
- bindFocus(this.node)
98
- // 绑定动画
99
- bindAnimation(this.node)
100
-
101
- this.text = this.node._attrs.value || ''
102
-
103
- try {
104
- Current.contextPromise
105
- .then((context: common.BaseContext) => {
106
- return window.getLastWindow(context, (err, windowClass: window.Window) => {
107
- const errCode: number = err.code;
108
- if (errCode) {
109
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err))
110
- return;
111
- }
112
- this.windowClass = windowClass
113
- windowClass.on('keyboardHeightChange', this.heightChange)
114
- })
115
- })
116
- } catch (exception) {
117
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception))
118
- }
119
- }
59
+ if (this.node) {
60
+ this.value = this.node.value
61
+ this.node._instance = this
120
62
 
121
- aboutToDisappear () {
122
- if (this.windowClass) {
123
- try {
124
- this.windowClass.off('keyboardHeightChange', this.heightChange)
125
- } catch (err) {
126
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err))
63
+ if (!this.node._isInit) {
64
+ this.node._isInit = true
65
+ this.node._reset = this.node.value || ''
127
66
  }
128
67
  }
129
68
  }
130
69
 
131
- onKeyboardHeightChange (height: number) {
132
- const event: TaroEvent = createTaroEvent('keyboardHeightChange', { detail: { height: height, duration: 0 } }, this.node)
133
- eventHandler(event, 'keyboardHeightChange', this.node)
134
- }
135
-
136
- getPlaceholderColor (node: TaroInputElement): string {
137
- const placeholderTextColor: string = node._attrs.placeholderTextColor || ''
138
- const placeholderStyle: string = node._attrs.placeholderStyle || ''
139
-
140
- return placeholderTextColor || parseStyles(placeholderStyle)?.color
141
- }
142
-
143
- getInputType (node: TaroInputElement) {
144
- if (node._attrs?.password) return InputType.Password
145
- return INPUT_TYPE_MAP.get(node._attrs?.type || '') || InputType.Normal
146
- }
147
-
148
- getText (): string {
149
- return isUndefined(this.node._attrs.value) ? this.text : this.node._attrs.value
150
- }
151
-
152
- @Styles defaultEvent () {
70
+ build () {
71
+ TextInput({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
72
+ .key(this.node._nid)
73
+ .type(getInputType(this.node))
74
+ .maxLength(Number(this.node._attrs?.maxlength) || null)
75
+ .placeholderColor(getPlaceholderColor(this.node))
76
+ .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
77
+ .padding(0) // Note: 移出 Input 默认 padding 设置
78
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
79
+ .styles(this.node?.hmStyle)
80
+ .attrs(getAttributes(this.node))
81
+ .onChange((value: string) => {
82
+ const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
83
+
84
+ this.value = value
85
+ this.node?.updateFormWidgetValue(value)
86
+ eventHandler(event, 'input', this.node)
87
+ })
88
+ .onSubmit(() => {
89
+ const event: TaroEvent = createTaroEvent('confirm', { detail: { value: this.value } }, this.node)
90
+ eventHandler(event, 'confirm', this.node)
91
+ })
153
92
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
154
93
  .onBlur(() => {
155
- const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.text } }, this.node)
94
+ const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
156
95
  eventHandler(event, 'blur', this.node)
157
96
  })
158
97
  .onFocus(() => {
159
- const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.text, height: this._height } }, this.node)
98
+ const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
99
+
160
100
  eventHandler(event, 'focus', this.node)
161
101
  })
162
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
163
- const eventResult: TaroAny = res.eventResult
164
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
102
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
103
+ if (this.node) {
104
+ this.node._nodeInfo.areaInfo = res[1]
105
+ }
165
106
  }))
166
- }
167
-
168
- build() {
169
- TaroComponentWrapper({ node: this.node }) {
170
- TextInput({ text: this.getText(), placeholder: this.node._attrs?.placeholder || '', controller: this.controller })
171
- .focusable(true)
172
- .key(this.node._nid)
173
- .type(this.getInputType(this.node))
174
- .maxLength(Number(this.node._attrs?.maxlength) || null)
175
- .placeholderColor(this.getPlaceholderColor(this.node))
176
- .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
177
- .defaultEvent()
178
- .styles(getNormalAttributes(this.node))
179
- .attrs(getAttributes(this.node))
180
- .style(TextInputStyle.Inline)
181
- .onChange((value: string) => {
182
- const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
183
- eventHandler(event, 'input', this.node)
184
- this.text = value
185
- })
186
- .onSubmit(() => {
187
- const event: TaroEvent = createTaroEvent('confirm', { detail: { value: this.text } }, this.node)
188
- eventHandler(event, 'confirm', this.node)
189
- })
190
- .visibleChangeEvent()
191
- }
107
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
192
108
  }
193
109
  }
194
-
195
- export default TaroInput
@@ -1,111 +1,105 @@
1
- import { bindInstanceToNode, Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME,
2
- TaroAny } from '@tarojs/runtime'
1
+ import { Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
+
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
3
4
 
4
- import { createNode } from './render'
5
- import TaroComponentWrapper from './base'
6
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
7
- import { FlexManager } from './utils/FlexManager'
8
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
6
+ import { FlexManager } from './utils/flexManager'
7
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
9
8
 
10
- import type { TaroLabelElement, TaroElement } from './element'
11
- import type { TaroStyleType } from '@tarojs/runtime'
9
+ import type { TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
10
+ import { isUndefined } from '@tarojs/shared'
12
11
 
13
- @Extend(Flex)
14
- function attrs (style: TaroStyleType) {
15
- .id(style.id)
16
- .key(style.id)
17
- .padding(style.padding)
18
- .margin(style.margin)
19
- .width(style.width)
20
- .height(style.height)
21
- .constraintSize(style.constraintSize)
22
- .flexGrow(style.flexGrow)
23
- .flexShrink(style.flexShrink)
24
- .flexBasis(style.flexBasis)
25
- .alignSelf(style.alignSelf)
26
- .backgroundColor(style.backgroundColor)
27
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
28
- .backgroundImageSize(style.backgroundImageSize)
29
- .rotate(style.rotate)
30
- .scale(style.scale)
31
- .translate(style.translate)
32
- .transform(style.transform)
33
- .borderStyle(style.borderStyle)
34
- .borderWidth(style.borderWidth)
35
- .borderColor(style.borderColor)
36
- .borderRadius(style.borderRadius)
37
- .linearGradient(style.linearGradient)
38
- .zIndex(style.zIndex)
39
- .opacity(style.opacity)
40
- .clip(style.clip)
41
- }
12
+ function handleTargetChange (id: string) {
13
+ const taro: TaroAny = Current.taro
14
+ const page: TaroAny = taro.getCurrentInstance().page
15
+ const currentPageNode: TaroElement = getPageScrollerOrNode(page?.node, page)
16
+ const node: TaroElement | null = currentPageNode?.getElementById(id)
42
17
 
43
- @Component
44
- export default struct TaroLabel {
45
- nodeInfoMap: TaroAny = {}
18
+ if (!node) return
46
19
 
47
- @Styles visibleChangeEvent () {
48
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
20
+ if (['BUTTON', 'CHECKBOX', 'RADIO', 'SWITCH', 'INPUT'].includes(node.tagName)) {
21
+ switch (node.tagName) {
22
+ case 'RADIO':
23
+ const radioNode: TaroRadioElement = node as TaroRadioElement
24
+ if (!radioNode.checked) {
25
+ radioNode.checked = !radioNode.checked
26
+ }
27
+ break
28
+ case 'CHECKBOX':
29
+ const checkBoxNode: TaroCheckboxElement = node as TaroCheckboxElement
30
+ checkBoxNode.checked = !checkBoxNode.checked
31
+ break
32
+ default:
33
+ focusControl.requestFocus(id)
34
+ }
49
35
  }
36
+ }
50
37
 
38
+ @Component
39
+ export default struct TaroLabel {
40
+ @Builder customBuilder() {}
41
+ @BuilderParam createLazyChildren: (node: TaroLabelElement) => void = this.customBuilder
51
42
  @ObjectLink node: TaroLabelElement
43
+ @State overwriteStyle: Record<string, TaroAny> = {}
52
44
 
53
- aboutToAppear () {
54
- initComponentNodeInfo(this, this.node)
55
- bindInstanceToNode(this.node, this)
56
- // 绑定动画
57
- bindAnimation(this.node)
58
- }
59
-
60
- @Styles defaultEvent () {
61
- .onClick((e: ClickEvent) => {
62
- const firstChild = this.node.childNodes[0] as TaroElement | null
63
- const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
64
- this.handleTargetChange(id)
65
- eventHandler(e, 'click', this.node)
66
- })
67
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
68
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
69
- const eventResult: TaroAny = res.eventResult
70
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
71
- }))
72
- }
73
-
74
- handleTargetChange (id: string) {
75
- const taro: TaroAny = Current.taro
76
- const page: TaroAny = taro.getCurrentInstance().page
77
- const currentPageNode: TaroElement = getPageScrollerOrNode(page.node, page)
78
- const node: TaroElement | null = currentPageNode.getElementById(id)
79
-
80
- if (!node || !node._instance) return
81
-
82
- if (['BUTTON', 'CHECKBOX', 'RADIO', 'SWITCH', 'INPUT'].includes(node.tagName)) {
83
- const instance: TaroAny = node._instance
84
- switch (node.tagName) {
85
- case 'RADIO':
86
- if (!instance.checked) {
87
- instance.checked = !instance.checked
88
- }
89
- break
90
- case 'CHECKBOX':
91
- instance.checked = !instance.checked
92
- break
93
- default:
94
- focusControl.requestFocus(id)
95
- }
45
+ aboutToAppear(): void {
46
+ if (this.node) {
47
+ this.node._instance = this
96
48
  }
97
49
  }
98
50
 
99
51
  build() {
100
- TaroComponentWrapper({ node: this.node }) {
52
+ if (FlexManager.useFlexLayout(this.node)) {
101
53
  Flex(FlexManager.flexOptions(this.node)) {
102
- ForEach(this.node.childNodes, (item: TaroElement) => {
103
- createNode(item)
104
- }, (item: TaroElement) => item._nid)
54
+ this.createLazyChildren(this.node)
105
55
  }
106
- .attrs(getNormalAttributes(this.node))
107
- .defaultEvent()
108
- .visibleChangeEvent()
56
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
57
+ .onClick((e: ClickEvent) => {
58
+ const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
59
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
60
+
61
+ handleTargetChange(id)
62
+ eventHandler(e, 'click', this.node)
63
+ })
64
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
65
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
66
+ this.node._nodeInfo.areaInfo = res[1]
67
+ }))
68
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
69
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
70
+ Row() {
71
+ this.createLazyChildren(this.node)
72
+ }
73
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
74
+ .onClick((e: ClickEvent) => {
75
+ const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
76
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
77
+
78
+ handleTargetChange(id)
79
+ eventHandler(e, 'click', this.node)
80
+ })
81
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
82
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
83
+ this.node._nodeInfo.areaInfo = res[1]
84
+ }))
85
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
86
+ } else {
87
+ Column() {
88
+ this.createLazyChildren(this.node)
89
+ }
90
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
91
+ .onClick((e: ClickEvent) => {
92
+ const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
93
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
94
+
95
+ handleTargetChange(id)
96
+ eventHandler(e, 'click', this.node)
97
+ })
98
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
99
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
100
+ this.node._nodeInfo.areaInfo = res[1]
101
+ }))
102
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
109
103
  }
110
104
  }
111
105
  }
@@ -0,0 +1,26 @@
1
+ import commonStyleModify from './style'
2
+
3
+ import type { TaroViewElement, TaroAny } from '@tarojs/runtime'
4
+
5
+ @Component
6
+ export default struct TaroListView {
7
+ @Builder customBuilder() {}
8
+ @BuilderParam createLazyChildren: (node: TaroViewElement) => void = this.customBuilder
9
+ @ObjectLink node: TaroViewElement
10
+ @State overwriteStyle: Record<string, TaroAny> = {}
11
+
12
+ aboutToAppear(): void {
13
+ if (this.node) {
14
+ this.node._instance = this
15
+ }
16
+ }
17
+
18
+ build() {
19
+ ListItem() {
20
+ Stack() {
21
+ this.createLazyChildren(this.node)
22
+ }
23
+ }
24
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
25
+ }
26
+ }
@@ -0,0 +1,124 @@
1
+ import type { TaroAny, TaroMovableAreaElement, TaroMovableViewElement } from '@tarojs/runtime'
2
+ import { isTaroMovableViewElement } from '@tarojs/runtime'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+
5
+ import { FlexManager } from './utils/flexManager'
6
+ import { isUndefined } from '@tarojs/shared'
7
+
8
+ @Component
9
+ export default struct TaroMovableArea {
10
+ @Builder
11
+ customBuilder() {
12
+ }
13
+
14
+ @BuilderParam createLazyChildren: (node: TaroMovableAreaElement) => void = this.customBuilder
15
+ @ObjectLink node: TaroMovableAreaElement
16
+ @State overwriteStyle: Record<string, TaroAny> = {}
17
+
18
+ aboutToAppear(): void {
19
+ if (this.node) {
20
+ this.node._instance = this
21
+ }
22
+ }
23
+
24
+
25
+
26
+
27
+
28
+ build() {
29
+ if (FlexManager.useFlexLayout(this.node)) {
30
+ Flex(FlexManager.flexOptions(this.node)) {
31
+ this.createLazyChildren(this.node)
32
+ }
33
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
34
+ .clip(true)
35
+ .onAreaChange((oldValue: Area, newValue: Area) => {
36
+ areaChangeHandle(this.node, newValue)
37
+ })
38
+ .gesture(
39
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
40
+ this.node.childNodes.forEach(item => {
41
+ if (isTaroMovableViewElement(item)) {
42
+ item.startScale()
43
+ }
44
+ })
45
+ }).onActionUpdate((event) => {
46
+ const scaleArea = this.node.getAttribute('scaleArea')
47
+ if (scaleArea) {
48
+ this.node.childNodes.forEach(item => {
49
+ if (isTaroMovableViewElement(item)) {
50
+ item.doScale(event.scale)
51
+ }
52
+ })
53
+ }
54
+ })
55
+ )
56
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
57
+ Row() {
58
+ this.createLazyChildren(this.node)
59
+ }
60
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
61
+ .clip(true)
62
+ .onAreaChange((oldValue: Area, newValue: Area) => {
63
+ areaChangeHandle(this.node, newValue)
64
+ })
65
+ .gesture(
66
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
67
+ this.node.childNodes.forEach(item => {
68
+ if (isTaroMovableViewElement(item)) {
69
+ item.startScale()
70
+ }
71
+ })
72
+ }).onActionUpdate((event) => {
73
+ const scaleArea = this.node.getAttribute('scaleArea')
74
+ if (scaleArea) {
75
+ this.node.childNodes.forEach(item => {
76
+ if (isTaroMovableViewElement(item)) {
77
+ item.doScale(event.scale)
78
+ }
79
+ })
80
+ }
81
+ })
82
+ )
83
+ } else {
84
+ Column() {
85
+ this.createLazyChildren(this.node)
86
+ }
87
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
88
+ .clip(true)
89
+ .onAreaChange((oldValue: Area, newValue: Area) => {
90
+ areaChangeHandle(this.node, newValue)
91
+ })
92
+ .gesture(
93
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
94
+ this.node.childNodes.forEach(item => {
95
+ if (isTaroMovableViewElement(item)) {
96
+ item.startScale()
97
+ }
98
+ })
99
+ }).onActionUpdate((event) => {
100
+ const scaleArea = this.node.getAttribute('scaleArea')
101
+ if (scaleArea) {
102
+ this.node.childNodes.forEach(item => {
103
+ if (isTaroMovableViewElement(item)) {
104
+ item.doScale(event.scale)
105
+ }
106
+ })
107
+ }
108
+ })
109
+ )
110
+ }
111
+ }
112
+ }
113
+ function areaChangeHandle(node: TaroMovableAreaElement,newValue: Area) {
114
+ node.childNodes.forEach(item => {
115
+ if (isTaroMovableViewElement(item)) {
116
+ if (item.area?.w !== Number(newValue.width) || item.area?.h !== Number(newValue.height)) {
117
+ item.area = {
118
+ w: Number(newValue.width),
119
+ h: Number(newValue.height)
120
+ }
121
+ }
122
+ }
123
+ })
124
+ }