@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,47 +1,14 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo,
2
- TaroEvent, TaroAny } from '@tarojs/runtime'
1
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
3
2
 
4
- import TaroComponentWrapper from './base'
5
- import { createTaroEvent } from './utils/events'
6
- import { getNodeThresholds, shouldBindEvent, getNormalAttributes } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
7
5
 
8
- import type { TaroSwitchElement } from './element'
9
- import type { TaroStyleType } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
10
7
 
11
8
  interface SwitchAttrs {
12
9
  selectedColor?: ResourceColor
13
10
  }
14
11
 
15
- @Extend(Toggle)
16
- function styles (style: TaroStyleType) {
17
- .id(style.id)
18
- .key(style.id)
19
- .padding(style.padding)
20
- .margin(style.margin)
21
- .width(style.width)
22
- .height(style.height)
23
- .constraintSize(style.constraintSize)
24
- .flexGrow(style.flexGrow)
25
- .flexShrink(style.flexShrink)
26
- .flexBasis(style.flexBasis)
27
- .alignSelf(style.alignSelf)
28
- .backgroundColor(style.backgroundColor)
29
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
30
- .backgroundImageSize(style.backgroundImageSize)
31
- .rotate(style.rotate)
32
- .scale(style.scale)
33
- .translate(style.translate)
34
- .transform(style.transform)
35
- .borderStyle(style.borderStyle)
36
- .borderWidth(style.borderWidth)
37
- .borderColor(style.borderColor)
38
- .borderRadius(style.borderRadius)
39
- .linearGradient(style.linearGradient)
40
- .zIndex(style.zIndex)
41
- .opacity(style.opacity)
42
- .clip(style.clip)
43
- }
44
-
45
12
  @Extend(Toggle)
46
13
  function attrs(attr: SwitchAttrs) {
47
14
  .selectedColor(attr.selectedColor)
@@ -61,53 +28,45 @@ function themeStyles(isDisabled: boolean) {
61
28
 
62
29
  @Component
63
30
  export default struct TaroSwitch {
64
- nodeInfoMap: TaroAny = {}
65
-
31
+ @Builder customBuilder() {}
32
+ @BuilderParam createLazyChildren: (node: TaroSwitchElement) => void = this.customBuilder
66
33
  @ObjectLink node: TaroSwitchElement
67
-
68
- @State value: boolean = false
69
-
70
- @Styles visibleChangeEvent () {
71
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
72
- }
34
+ @State overwriteStyle: Record<string, TaroAny> = {}
73
35
 
74
36
  aboutToAppear () {
75
- initComponentNodeInfo(this, this.node)
76
- bindInstanceToNode(this.node, this)
77
-
78
- this.value = !!this.node._attrs.checked
37
+ if (this.node && !this.node._isInit) {
38
+ this.node._isInit = true
39
+ this.node._instance = this
40
+ this.node._reset = this.node.checked || false
41
+ }
79
42
  }
80
43
 
81
- @Styles defaultEvent () {
82
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
83
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
84
- const eventResult: TaroAny = res.eventResult
85
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
86
- }))
87
- }
44
+ build () {
45
+ Toggle({
46
+ type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
47
+ isOn: this.node.checked,
48
+ })
49
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
50
+ .attrs(getAttributes(this.node))
51
+ .themeStyles(!!this.node._attrs.disabled)
52
+ .onChange((isOn: boolean) => {
53
+ if (this.node) {
54
+ if (!this.node?._attrs.disabled) {
55
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, this.node)
88
56
 
89
- build() {
90
- TaroComponentWrapper({ node: this.node }) {
91
- Toggle({
92
- type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
93
- isOn: this.value,
94
- })
95
- .defaultEvent()
96
- .styles(getNormalAttributes(this.node))
97
- .attrs(getAttributes(this.node))
98
- .themeStyles(!!this.node._attrs.disabled)
99
- .onChange((isOn: boolean) => {
100
- if (!this.node._attrs.disabled) {
101
- this.value = isOn
102
- const event: TaroEvent = createTaroEvent('change', { detail: { value: this.value } }, this.node)
57
+ this.node.updateCheckedValue(isOn)
103
58
  eventHandler(event, 'change', this.node)
104
59
  } else {
105
- // FIXME 找下文档是否有强制刷新方法
106
- this.value = !this.value
107
- this.value = !this.value
60
+ this.node.updateComponent()
108
61
  }
109
- })
110
- .visibleChangeEvent()
111
- }
62
+ }
63
+ })
64
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
65
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
66
+ if (this.node) {
67
+ this.node._nodeInfo.areaInfo = res[1]
68
+ }
69
+ }))
70
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
112
71
  }
113
72
  }
@@ -35,6 +35,8 @@ export const TaroAdTagName = 'ad'
35
35
  export const TaroWebViewTagName = 'web-view'
36
36
  export const TaroBlockTagName = 'block'
37
37
  export const TaroMapTagName = 'map'
38
+ export const TaroPageMetaTagName = 'page-meta'
39
+ export const TaroNavigationBarTagName = 'navigation-bar'
38
40
  export const TaroSlotTagName = 'slot'
39
41
  export const TaroNativeSlotTagName = 'native-slot'
40
42
  export const TaroCustomWrapperTagName = 'custom-wrapper'
@@ -47,3 +49,7 @@ export const TaroListTagName = 'list'
47
49
  export const TaroListItemTagName = 'list-item'
48
50
  export const TaroOpenDataTagName = 'open-data'
49
51
  export const TaroIgnoreTagName = 'ignore'
52
+
53
+ export const TaroStickySectionTagName = 'sticky-section'
54
+ export const TaroStickyHeaderTagName = 'sticky-header'
55
+ export const TaroListViewTagName = 'list-view'
@@ -1,97 +1,152 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny, NodeType } from '@tarojs/runtime'
1
+ import { isString } from '@tarojs/shared'
2
+ import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
2
3
 
3
- import TaroComponentWrapper from './base'
4
- import { getNodeThresholds, getNormalAttributes, getFontAttributes, shouldBindEvent, bindAnimation } from './utils/helper'
4
+ import { textModify, setNormalTextAttributeIntoInstance } from './style'
5
+ import { getButtonColor } from './button'
6
+ import { getImageMode } from './image'
7
+ import { BUTTON_THEME_COLOR } from './utils/constant/style'
8
+ import { getNodeThresholds, getStyleAttr, shouldBindEvent, getNormalAttributes } from './utils/helper'
5
9
 
6
- import type { TaroTextElement } from './element'
7
- import type { TaroStyleType, TaroTextStyleType } from '@tarojs/runtime'
10
+ import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, HarmonyStyle } from '@tarojs/runtime'
8
11
 
9
- @Extend(Text)
10
- function textStyle (style: TaroStyleType) {
11
- .id(style.id)
12
- .key(style.id)
13
- .padding(style.padding)
14
- .margin(style.margin)
15
- .width(style.width)
16
- .height(style.height)
17
- .constraintSize(style.constraintSize)
18
- .flexGrow(style.flexGrow)
19
- .flexShrink(style.flexShrink)
20
- .flexBasis(style.flexBasis)
21
- .alignSelf(style.alignSelf)
22
- .backgroundColor(style.backgroundColor)
23
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
24
- .backgroundImageSize(style.backgroundImageSize)
25
- .rotate(style.rotate)
26
- .scale(style.scale)
27
- .translate(style.translate)
28
- .transform(style.transform)
29
- .borderStyle(style.borderStyle)
30
- .borderWidth(style.borderWidth)
31
- .borderColor(style.borderColor)
32
- .borderRadius(style.borderRadius)
33
- .linearGradient(style.linearGradient)
34
- .zIndex(style.zIndex)
35
- .opacity(style.opacity)
36
- .clip(style.clip)
37
- .fontColor(style.color)
38
- .fontSize(style.fontSize)
39
- .fontWeight(style.fontWeight)
40
- .fontStyle(style.fontStyle)
41
- .fontFamily(style.fontFamily)
42
- .lineHeight(style.lineHeight)
43
- .decoration({
44
- type: style.decoration,
45
- color: style.color
46
- })
12
+ function getButtonFontSize (node: TaroButtonElement): string | number {
13
+ const isMini = node._attrs.size === 'mini'
14
+
15
+ return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
47
16
  }
48
17
 
49
- @Extend(Text)
50
- function textAttr(attr: TaroTextStyleType) {
51
- .textAlign(attr.textAlign)
52
- .textOverflow(attr.textOverflow)
53
- .maxLines(attr.maxLines)
54
- .letterSpacing(attr.letterSpacing)
18
+ function getTextInViewWidth (node: TaroElement | null): TaroAny {
19
+ if (node) {
20
+ const hmStyle = node.hmStyle || {}
21
+ const isFlexView = hmStyle.display === 'flex'
22
+ const width: TaroAny = getStyleAttr(node, 'width')
23
+ const isPercentWidth = isString(width) && width.includes('%')
24
+
25
+ return isFlexView || isPercentWidth ? null : getStyleAttr(node, 'width')
26
+ }
55
27
  }
56
28
 
57
29
 
58
30
  @Component
59
31
  export default struct TaroText {
60
- nodeInfoMap: TaroAny = {}
32
+ @Builder customBuilder() {}
33
+ @BuilderParam createLazyChildren: (node: TaroTextElement) => void = this.customBuilder
34
+ @ObjectLink node: TaroTextElement
35
+ @State overwriteStyle: Record<string, TaroAny> = {}
61
36
 
62
- @Styles visibleChangeEvent () {
63
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
37
+ aboutToAppear(): void {
38
+ if (this.node) {
39
+ this.node._instance = this
40
+ }
64
41
  }
65
42
 
66
- @ObjectLink node: TaroTextElement
67
-
68
- aboutToAppear () {
69
- initComponentNodeInfo(this, this.node)
70
- bindInstanceToNode(this.node, this)
71
- // 绑定动画
72
- bindAnimation(this.node)
43
+ build () {
44
+ if (this.node.nodeType === NodeType.TEXT_NODE) {
45
+ if (this.node.parentNode) {
46
+ if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
47
+ Text(this.node.textContent)
48
+ .attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement, {
49
+ fontSize: getButtonFontSize(this.node.parentNode as TaroButtonElement),
50
+ color: getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type || '').text)
51
+ }))
52
+ } else {
53
+ Text(this.node.textContent)
54
+ .attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement))
55
+ .width(getTextInViewWidth(this.node.parentElement))
56
+ }
57
+ }
58
+ } else {
59
+ Text(this.node.textContent) {
60
+ // text 下还有标签
61
+ if (this.node.childNodes.length > 1 || ((this.node.childNodes[0] && this.node.childNodes[0] as TaroElement)?.nodeType === NodeType.ELEMENT_NODE)) {
62
+ ForEach(this.node.childNodes, (item: TaroElement) => {
63
+ createTextChildNode(item)
64
+ }, (item: TaroElement) => `${item._nid}${this.node._updateTrigger}`)
65
+ }
66
+ }
67
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
68
+ .attributeModifier(textModify.setNode(this.node).withNormalStyle().setAnimationStyle(this.overwriteStyle))
69
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
70
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
71
+ this.node._nodeInfo.areaInfo = res[1]
72
+ }))
73
+ }
73
74
  }
75
+ }
74
76
 
75
- @Styles defaultEvent () {
76
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
77
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
78
- const eventResult: TaroAny = res.eventResult
79
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
80
- }))
77
+ @Builder
78
+ function createTextChildNode (item: TaroElement) {
79
+ if (item.tagName === 'IMAGE') {
80
+ ImageSpan(item.getAttribute('src'))
81
+ // .attributeModifier(commonStyleModify.setNode(item))
82
+ .objectFit(getImageMode(item.getAttribute('mode')))
83
+ // .verticalAlign(align)
84
+ .width(item._st.hmStyle.width)
85
+ .height(item._st.hmStyle.height)
86
+ .margin({
87
+ top: item._st.hmStyle.marginTop,
88
+ left: item._st.hmStyle.marginLeft,
89
+ right: item._st.hmStyle.marginRight,
90
+ bottom: item._st.hmStyle.marginBottom,
91
+ })
92
+ .padding({
93
+ top: item._st.hmStyle.paddingTop,
94
+ left: item._st.hmStyle.paddingLeft,
95
+ right: item._st.hmStyle.paddingRight,
96
+ bottom: item._st.hmStyle.paddingBottom,
97
+ })
98
+ .textBackgroundStyle({
99
+ color: item._st.hmStyle.backgroundColor,
100
+ radius: {
101
+ topLeft: item._st.hmStyle.borderTopLeftRadius,
102
+ topRight: item._st.hmStyle.borderTopRightRadius,
103
+ bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
104
+ bottomRight: item._st.hmStyle.borderBottomRightRadius,
105
+ }
106
+ })
107
+ .borderRadius({
108
+ topLeft: item._st.hmStyle.borderTopLeftRadius,
109
+ topRight: item._st.hmStyle.borderTopRightRadius,
110
+ bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
111
+ bottomRight: item._st.hmStyle.borderBottomRightRadius
112
+ })
113
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
114
+ } else if (item.nodeType === NodeType.TEXT_NODE) {
115
+ Span(item.textContent)
116
+ } else if (item.tagName === 'TEXT') {
117
+ Span(item.textContent)
118
+ .attributeModifier(spanModify.setNode(item))
119
+ .letterSpacing(item._st.hmStyle.letterSpacing)
120
+ .textBackgroundStyle({
121
+ color: item._st.hmStyle.backgroundColor,
122
+ radius: {
123
+ topLeft: item._st.hmStyle.borderTopLeftRadius,
124
+ topRight: item._st.hmStyle.borderTopRightRadius,
125
+ bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
126
+ bottomRight: item._st.hmStyle.borderBottomRightRadius,
127
+ }
128
+ })
129
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
81
130
  }
131
+ }
82
132
 
133
+ class SpanStyleModify implements AttributeModifier<SpanAttribute> {
134
+ node: TaroTextElement | null = null
135
+ style: HarmonyStyle | null = null
136
+ overwriteStyle: Record<string, TaroAny> = {}
137
+ withNormal = false
83
138
 
84
- build() {
85
- TaroComponentWrapper({ node: this.node }) {
86
- if (this.node.nodeType === NodeType.TEXT_NODE) {
87
- Text(this.node.textContent)
88
- } else {
89
- Text(this.node.textContent)
90
- .defaultEvent()
91
- .textStyle(getNormalAttributes(this.node))
92
- .textAttr(getFontAttributes(this.node))
93
- .visibleChangeEvent()
94
- }
139
+ setNode (node: TaroTextElement) {
140
+ this.node = node
141
+ this.style = getNormalAttributes(this.node)
142
+ return this
143
+ }
144
+
145
+ applyNormalAttribute(instance: SpanAttribute): void {
146
+ if (this.node && this.style) {
147
+ setNormalTextAttributeIntoInstance(instance, this.style, this.node)
95
148
  }
96
149
  }
97
150
  }
151
+
152
+ const spanModify = new SpanStyleModify()
@@ -1,44 +1,16 @@
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 { getNodeThresholds, getNormalAttributes, getFontAttributes, parseStyles, shouldBindEvent, bindAnimation } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
10
5
 
11
- import type { TaroTextAreaElement } from './element'
12
- import type { TaroStyleType, TaroTextStyleType } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroTextAreaElement, TaroEvent } from '@tarojs/runtime'
7
+
8
+ interface TextareaAttrs extends TaroTextStyleType {
9
+ autoFocus?: boolean
10
+ }
13
11
 
14
12
  @Extend(TextArea)
15
13
  function textStyle (style: TaroStyleType) {
16
- .id(style.id)
17
- .key(style.id)
18
- .padding(style.padding)
19
- .margin(style.margin)
20
- .width(style.width)
21
- .height(style.height)
22
- .constraintSize(style.constraintSize)
23
- .flexGrow(style.flexGrow)
24
- .flexShrink(style.flexShrink)
25
- .flexBasis(style.flexBasis)
26
- .alignSelf(style.alignSelf)
27
- .backgroundColor(style.backgroundColor)
28
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
29
- .backgroundImageSize(style.backgroundImageSize)
30
- .rotate(style.rotate)
31
- .scale(style.scale)
32
- .translate(style.translate)
33
- .transform(style.transform)
34
- .borderStyle(style.borderStyle)
35
- .borderWidth(style.borderWidth)
36
- .borderColor(style.borderColor)
37
- .borderRadius(style.borderRadius)
38
- .linearGradient(style.linearGradient)
39
- .zIndex(style.zIndex)
40
- .opacity(style.opacity)
41
- .clip(style.clip)
42
14
  .fontColor(style.color)
43
15
  .fontSize(style.fontSize)
44
16
  .fontWeight(style.fontWeight)
@@ -47,123 +19,75 @@ function textStyle (style: TaroStyleType) {
47
19
  }
48
20
 
49
21
  @Extend(TextArea)
50
- function textAttr(attr: TaroTextStyleType) {
22
+ function textAttr(attr: TextareaAttrs) {
51
23
  .textAlign(attr.textAlign)
52
- .maxLines(attr.maxLines)
24
+ .maxLines(attr.WebkitLineClamp)
25
+ .defaultFocus(attr.autoFocus)
53
26
  }
54
27
 
55
- @Component
56
- struct TaroTextArea {
57
- nodeInfoMap: TaroAny = {}
58
-
59
- @State text: string = ''
60
-
61
- @ObjectLink node: TaroTextAreaElement
62
-
63
- controller: TextAreaController = new TextAreaController()
28
+ function getAttributes(node: TaroTextAreaElement): TextareaAttrs {
29
+ const attrs: TaroAny = getFontAttributes(node)
30
+ attrs.autoFocus = node._attrs.autoFocus || node._attrs.focus || false
31
+ return attrs
32
+ }
64
33
 
65
- windowClass?: window.Window
34
+ function getPlaceholderColor (node: TaroTextAreaElement): string {
35
+ const placeholderStyle: string = node._attrs.placeholderStyle || ''
66
36
 
67
- _height: number = 0
37
+ return parseStyles(placeholderStyle)?.color
38
+ }
68
39
 
69
- heightChange = (height: number) => {
70
- if (isNumber(height)) {
71
- if (this._height !== height) {
72
- this.onKeyboardHeightChange(height)
73
- this._height = height
74
- }
75
- }
76
- }
40
+ @Component
41
+ export default struct TaroTextArea {
42
+ @State value: string = ''
77
43
 
78
- @Styles visibleChangeEvent () {
79
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
- }
44
+ @Builder customBuilder() {}
45
+ @BuilderParam createLazyChildren: (node: TaroTextAreaElement) => void = this.customBuilder
46
+ @ObjectLink node: TaroTextAreaElement
47
+ @State overwriteStyle: Record<string, TaroAny> = {}
81
48
 
82
49
  aboutToAppear () {
83
- initComponentNodeInfo(this, this.node)
84
- bindInstanceToNode(this.node, this)
85
- bindFocus(this.node)
86
- // 绑定动画
87
- bindAnimation(this.node)
50
+ if (this.node) {
51
+ this.value = this.node.value
52
+ this.node._instance = this
88
53
 
89
- this.text = this.node._attrs.value || ''
90
-
91
- try {
92
- Current.contextPromise
93
- .then((context: common.BaseContext) => {
94
- return window.getLastWindow(context, (err, windowClass: window.Window) => {
95
- const errCode: number = err.code;
96
- if (errCode) {
97
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err))
98
- return;
99
- }
100
- this.windowClass = windowClass
101
- windowClass.on('keyboardHeightChange', this.heightChange)
102
- })
103
- })
104
- } catch (exception) {
105
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception))
106
- }
107
- }
108
-
109
- aboutToDisappear () {
110
- if (this.windowClass) {
111
- try {
112
- this.windowClass.off('keyboardHeightChange', this.heightChange)
113
- } catch (err) {
114
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err))
54
+ if (!this.node._isInit) {
55
+ this.node._isInit = true
56
+ this.node._reset = this.node.value || ''
115
57
  }
116
58
  }
117
59
  }
118
60
 
119
- onKeyboardHeightChange (height: number) {
120
- const event: TaroEvent = createTaroEvent('keyboardHeightChange', { detail: { height, duration: 0 } }, this.node)
121
- eventHandler(event, 'keyboardHeightChange', this.node)
122
- }
123
-
124
- getPlaceholderColor (node: TaroTextAreaElement): string {
125
- const placeholderStyle: string = node._attrs.placeholderStyle || ''
126
-
127
- return parseStyles(placeholderStyle)?.color
128
- }
129
-
130
- getText (): string {
131
- return isUndefined(this.node._attrs.value) ? this.text : this.node._attrs.value
132
- }
133
-
134
- @Styles defaultEvent () {
135
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
136
- .onBlur(() => {
137
- const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.text } }, this.node)
138
- eventHandler(event, 'blur', this.node)
139
- })
140
- .onFocus(() => {
141
- const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.text, height: this._height } }, this.node)
142
- eventHandler(event, 'focus', this.node)
143
- })
144
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
145
- const eventResult: TaroAny = res.eventResult
146
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
147
- }))
148
- }
149
-
150
- build() {
151
- TaroComponentWrapper({ node: this.node }) {
152
- TextArea({ text: this.getText(), placeholder: this.node._attrs?.placeholder || '', controller: this.controller })
153
- .focusable(true)
154
- .key(this.node._nid)
155
- .placeholderColor(this.getPlaceholderColor(this.node))
156
- .defaultEvent()
157
- .textStyle(getNormalAttributes(this.node))
158
- .textAttr(getFontAttributes(this.node))
159
- .onChange((value: string) => {
160
- const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
161
- eventHandler(event, 'input', this.node)
162
- this.text = value
163
- })
164
- .visibleChangeEvent()
165
- }
61
+ build () {
62
+ TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
63
+ .key(this.node._nid)
64
+ .maxLength(Number(this.node._attrs?.maxlength) || null)
65
+ .placeholderColor(getPlaceholderColor(this.node))
66
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
67
+ .textStyle(this.node?.hmStyle)
68
+ .textAttr(getAttributes(this.node))
69
+ .onChange((value: string) => {
70
+ const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
71
+
72
+ this.value = value
73
+ this.node?.updateFormWidgetValue(value)
74
+ eventHandler(event, 'input', this.node)
75
+ })
76
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
77
+ .onBlur(() => {
78
+ const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
79
+ eventHandler(event, 'blur', this.node)
80
+ })
81
+ .onFocus(() => {
82
+ const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
83
+
84
+ eventHandler(event, 'focus', this.node)
85
+ })
86
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
87
+ if (this.node) {
88
+ this.node._nodeInfo.areaInfo = res[1]
89
+ }
90
+ }))
91
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
166
92
  }
167
93
  }
168
-
169
- export default TaroTextArea
@@ -60,7 +60,7 @@ class AttributeManager {
60
60
  const dataValue: string = AttributeManager.getNodeStyle(style, 'animation')
61
61
 
62
62
  if (dataValue) {
63
- let values: string[] = dataValue.trim().split(new RegExp("/\s+/"))
63
+ let values: string[] = dataValue.toString().trim().split(new RegExp("/\s+/"))
64
64
  switch (values.length) {
65
65
  case 4:
66
66
  res = { duration: values[0], curve: values[1], delay: values[2] }
@@ -1,9 +1,6 @@
1
- import { bindFocus, bindInstanceToNode, bindScrollTo, initComponentNodeInfo, TaroAny, TaroElement } from '@tarojs/runtime'
2
-
3
- import { bindAnimation } from './helper'
1
+ import { TaroAny, TaroElement } from '@tarojs/runtime'
4
2
 
5
3
  export class DynamicCenter {
6
-
7
4
  install (node: TaroElement, parentNode: TaroElement) {
8
5
  if (!parentNode._isCompileMode) return
9
6
 
@@ -14,7 +11,7 @@ export class DynamicCenter {
14
11
  if (!node._isCompileMode || !node._instance) return
15
12
 
16
13
  if (node._attrs?._dynamicID) {
17
- node._instance[node._attrs._dynamicID] = null
14
+ node._instance[node._attrs._dynamicID] = new TaroElement('Ignore')
18
15
  }
19
16
  node._instance = null
20
17
  }
@@ -25,13 +22,7 @@ export class DynamicCenter {
25
22
  const dynamicID = node._attrs?._dynamicID
26
23
 
27
24
  // dynamicID 只是为了更新到精准的 node
28
- // 而为了让半编译模板中每个 node 都能响应 api 的调用,因此 initComponentNodeInfo、bindInstanceToNode 和各种 bindAttribute 都需要执行
29
- initComponentNodeInfo(component, node)
30
- bindInstanceToNode(node, component)
31
- bindFocus(node)
32
- bindAnimation(node)
33
- bindScrollTo(node, component)
34
-
25
+ node._instance = component
35
26
  node._isCompileMode = true
36
27
 
37
28
  if (dynamicID) {
@@ -45,4 +36,4 @@ export class DynamicCenter {
45
36
  this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
46
37
  }
47
38
  }
48
- }
39
+ }