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

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 (212) hide show
  1. package/LICENSE +160 -0
  2. package/dist/apis/apis.ts +15 -0
  3. package/dist/apis/base/index.ts +5 -0
  4. package/dist/apis/base/system.ts +77 -0
  5. package/dist/apis/device/accelerometer.ts +76 -0
  6. package/dist/apis/device/battery.ts +24 -0
  7. package/dist/apis/device/clipboard.ts +70 -0
  8. package/dist/apis/device/index.ts +9 -0
  9. package/dist/apis/device/keyboard.ts +62 -0
  10. package/dist/apis/device/memory.ts +4 -0
  11. package/dist/apis/device/network.ts +72 -0
  12. package/dist/apis/device/phone.ts +43 -0
  13. package/dist/apis/device/screen.ts +79 -0
  14. package/dist/apis/device/vibrate.ts +24 -0
  15. package/dist/apis/files/index.ts +135 -0
  16. package/dist/apis/files/manager.ts +941 -0
  17. package/dist/apis/framework/index.ts +32 -0
  18. package/dist/apis/index.ts +124 -0
  19. package/dist/apis/location/index.ts +133 -0
  20. package/dist/apis/media/common.ts +74 -0
  21. package/dist/apis/media/image.ts +122 -0
  22. package/dist/apis/media/index.ts +3 -0
  23. package/dist/apis/media/video.ts +86 -0
  24. package/dist/apis/navigate/index.ts +8 -0
  25. package/dist/apis/network/downloadFile.ts +113 -0
  26. package/dist/apis/network/index.ts +4 -0
  27. package/dist/apis/network/request.ts +113 -0
  28. package/dist/apis/network/uploadFile.ts +158 -0
  29. package/dist/apis/network/webSocket.ts +130 -0
  30. package/dist/apis/open-api/index.ts +7 -0
  31. package/dist/apis/open-api/user-info/index.ts +85 -0
  32. package/dist/apis/page/index.ts +92 -0
  33. package/dist/apis/route/index.ts +138 -0
  34. package/dist/apis/storage/index.ts +133 -0
  35. package/dist/apis/tabbar/index.ts +147 -0
  36. package/dist/apis/ui/animation.ts +222 -0
  37. package/dist/apis/ui/background.ts +35 -0
  38. package/dist/apis/ui/index.ts +14 -0
  39. package/dist/apis/ui/interaction/index.ts +195 -0
  40. package/dist/apis/ui/navigation-bar/index.ts +33 -0
  41. package/dist/apis/ui/pull-down-refresh.ts +41 -0
  42. package/dist/apis/utils/handler.ts +116 -0
  43. package/dist/apis/utils/index.ts +85 -0
  44. package/dist/apis/utils/types.ts +12 -0
  45. package/dist/apis/utils/validate.ts +87 -0
  46. package/dist/apis/wxml/IntersectionObserver.ts +119 -0
  47. package/dist/apis/wxml/index.ts +12 -0
  48. package/dist/apis/wxml/nodesRef.ts +56 -0
  49. package/dist/apis/wxml/selectorQuery.ts +287 -0
  50. package/dist/components/components-react.js +51 -0
  51. package/dist/components/components-react.js.map +1 -0
  52. package/dist/components-harmony/button/index.css +109 -0
  53. package/dist/components-harmony/button/index.hml +31 -0
  54. package/dist/components-harmony/button/index.js +105 -0
  55. package/dist/components-harmony/camera/index.hml +6 -0
  56. package/dist/components-harmony/camera/index.js +12 -0
  57. package/dist/components-harmony/checkbox/index.hml +11 -0
  58. package/dist/components-harmony/checkbox/index.js +60 -0
  59. package/dist/components-harmony/checkbox-group/index.hml +3 -0
  60. package/dist/components-harmony/checkbox-group/index.js +22 -0
  61. package/dist/components-harmony/cover-image/index.css +4 -0
  62. package/dist/components-harmony/cover-image/index.hml +9 -0
  63. package/dist/components-harmony/cover-image/index.js +15 -0
  64. package/dist/components-harmony/form/index.hml +10 -0
  65. package/dist/components-harmony/form/index.js +11 -0
  66. package/dist/components-harmony/icon/index.css +27 -0
  67. package/dist/components-harmony/icon/index.hml +54 -0
  68. package/dist/components-harmony/icon/index.js +17 -0
  69. package/dist/components-harmony/image/index.css +5 -0
  70. package/dist/components-harmony/image/index.hml +11 -0
  71. package/dist/components-harmony/image/index.js +28 -0
  72. package/dist/components-harmony/input/index.hml +21 -0
  73. package/dist/components-harmony/input/index.js +98 -0
  74. package/dist/components-harmony/label/index.hml +3 -0
  75. package/dist/components-harmony/label/index.js +6 -0
  76. package/dist/components-harmony/navbar/index.css +56 -0
  77. package/dist/components-harmony/navbar/index.hml +9 -0
  78. package/dist/components-harmony/navbar/index.js +30 -0
  79. package/dist/components-harmony/navigator/index.css +8 -0
  80. package/dist/components-harmony/navigator/index.hml +9 -0
  81. package/dist/components-harmony/navigator/index.js +104 -0
  82. package/dist/components-harmony/picker/index.hml +25 -0
  83. package/dist/components-harmony/picker/index.js +132 -0
  84. package/dist/components-harmony/picker-view/index.hml +23 -0
  85. package/dist/components-harmony/picker-view/index.js +161 -0
  86. package/dist/components-harmony/picker-view-column/index.hml +3 -0
  87. package/dist/components-harmony/picker-view-column/index.js +3 -0
  88. package/dist/components-harmony/progress/index.css +4 -0
  89. package/dist/components-harmony/progress/index.hml +28 -0
  90. package/dist/components-harmony/progress/index.js +23 -0
  91. package/dist/components-harmony/radio/index.hml +11 -0
  92. package/dist/components-harmony/radio/index.js +41 -0
  93. package/dist/components-harmony/radio-group/index.hml +3 -0
  94. package/dist/components-harmony/radio-group/index.js +11 -0
  95. package/dist/components-harmony/rich-text/index.hml +5 -0
  96. package/dist/components-harmony/rich-text/index.js +16 -0
  97. package/dist/components-harmony/scroll-view/index.css +5 -0
  98. package/dist/components-harmony/scroll-view/index.hml +12 -0
  99. package/dist/components-harmony/scroll-view/index.js +65 -0
  100. package/dist/components-harmony/slider/index.hml +16 -0
  101. package/dist/components-harmony/slider/index.js +53 -0
  102. package/dist/components-harmony/swiper/index.css +3 -0
  103. package/dist/components-harmony/swiper/index.hml +14 -0
  104. package/dist/components-harmony/swiper/index.js +19 -0
  105. package/dist/components-harmony/switch/index.hml +7 -0
  106. package/dist/components-harmony/switch/index.js +16 -0
  107. package/dist/components-harmony/tabbar/index.css +7 -0
  108. package/dist/components-harmony/tabbar/index.hml +26 -0
  109. package/dist/components-harmony/tabbar/index.js +42 -0
  110. package/dist/components-harmony/textarea/index.hml +24 -0
  111. package/dist/components-harmony/textarea/index.js +92 -0
  112. package/dist/components-harmony/utils/index.js +41 -0
  113. package/dist/components-harmony/video/index.hml +7 -0
  114. package/dist/components-harmony/video/index.js +73 -0
  115. package/dist/components-harmony/web-view/index.hml +8 -0
  116. package/dist/components-harmony/web-view/index.js +22 -0
  117. package/dist/components-harmony-ets/base.ets +63 -0
  118. package/dist/components-harmony-ets/button.ets +119 -0
  119. package/dist/components-harmony-ets/checkbox.ets +219 -0
  120. package/dist/components-harmony-ets/element.ets +223 -0
  121. package/dist/components-harmony-ets/form.ets +149 -0
  122. package/dist/components-harmony-ets/icon.ets +84 -0
  123. package/dist/components-harmony-ets/image.ets +85 -0
  124. package/dist/components-harmony-ets/index.ts +49 -0
  125. package/dist/components-harmony-ets/innerHtml.ets +79 -0
  126. package/dist/components-harmony-ets/input.ets +195 -0
  127. package/dist/components-harmony-ets/label.ets +111 -0
  128. package/dist/components-harmony-ets/picker.ets +370 -0
  129. package/dist/components-harmony-ets/radio.ets +225 -0
  130. package/dist/components-harmony-ets/richText.ets +97 -0
  131. package/dist/components-harmony-ets/scrollView.ets +199 -0
  132. package/dist/components-harmony-ets/slider.ets +159 -0
  133. package/dist/components-harmony-ets/swiper.ets +204 -0
  134. package/dist/components-harmony-ets/switch.ets +113 -0
  135. package/dist/components-harmony-ets/text.ets +97 -0
  136. package/dist/components-harmony-ets/textArea.ets +169 -0
  137. package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
  138. package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
  139. package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
  140. package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
  141. package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
  142. package/dist/components-harmony-ets/utils/events.ts +24 -0
  143. package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
  144. package/dist/components-harmony-ets/utils/helper.ets +99 -0
  145. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
  146. package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
  147. package/dist/components-harmony-ets/utils/index.ts +83 -0
  148. package/dist/components-harmony-ets/utils/styles.ets +91 -0
  149. package/dist/components-harmony-ets/video.ets +161 -0
  150. package/dist/components-harmony-ets/view.ets +79 -0
  151. package/dist/index.js +1183 -0
  152. package/dist/index.js.map +1 -0
  153. package/dist/runtime-ets/bom/document.ts +38 -0
  154. package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
  155. package/dist/runtime-ets/bom/navigator.ts +21 -0
  156. package/dist/runtime-ets/bom/raf.ts +37 -0
  157. package/dist/runtime-ets/bom/window.ts +44 -0
  158. package/dist/runtime-ets/constant.ts +29 -0
  159. package/dist/runtime-ets/current.ts +16 -0
  160. package/dist/runtime-ets/dom/class-list.ts +117 -0
  161. package/dist/runtime-ets/dom/comment.ts +10 -0
  162. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
  163. package/dist/runtime-ets/dom/document.ts +108 -0
  164. package/dist/runtime-ets/dom/element.ts +457 -0
  165. package/dist/runtime-ets/dom/event.ts +164 -0
  166. package/dist/runtime-ets/dom/eventTarget.ts +98 -0
  167. package/dist/runtime-ets/dom/node.ts +215 -0
  168. package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
  169. package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
  170. package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
  171. package/dist/runtime-ets/dom/text.ts +19 -0
  172. package/dist/runtime-ets/index.ts +19 -0
  173. package/dist/runtime-ets/interface/event.ts +9 -0
  174. package/dist/runtime-ets/interface/index.ts +1 -0
  175. package/dist/runtime-ets/utils/bind.ts +35 -0
  176. package/dist/runtime-ets/utils/index.ts +135 -0
  177. package/dist/runtime-ets/utils/info.ts +128 -0
  178. package/dist/runtime-framework/react/app.ts +256 -0
  179. package/dist/runtime-framework/react/connect.ts +24 -0
  180. package/dist/runtime-framework/react/constant.ts +5 -0
  181. package/dist/runtime-framework/react/hooks.ts +101 -0
  182. package/dist/runtime-framework/react/index.ts +16 -0
  183. package/dist/runtime-framework/react/page.ts +263 -0
  184. package/dist/runtime-framework/react/utils/index.ts +25 -0
  185. package/dist/runtime-framework/react/utils/is.ts +46 -0
  186. package/dist/runtime-framework/solid/README.md +99 -0
  187. package/dist/runtime-framework/solid/app.ts +200 -0
  188. package/dist/runtime-framework/solid/connect.ts +11 -0
  189. package/dist/runtime-framework/solid/contant.ts +5 -0
  190. package/dist/runtime-framework/solid/hooks.ts +88 -0
  191. package/dist/runtime-framework/solid/index.ts +10 -0
  192. package/dist/runtime-framework/solid/page.ts +202 -0
  193. package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
  194. package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
  195. package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
  196. package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
  197. package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
  198. package/dist/runtime-framework/solid/utils/index.ts +49 -0
  199. package/dist/runtime-framework/solid/utils/is.ts +46 -0
  200. package/dist/runtime-utils.js +4149 -0
  201. package/dist/runtime-utils.js.map +1 -0
  202. package/dist/runtime.js +4150 -0
  203. package/dist/runtime.js.map +1 -0
  204. package/dist/template/container.js +7 -0
  205. package/index.js +4 -0
  206. package/package.json +54 -0
  207. package/types/api.d.ts +4 -0
  208. package/types/component.d.ts +4 -0
  209. package/types/harmony.d.ts +11 -0
  210. package/types/runtime.d.ts +15 -0
  211. package/types/taro.d.ts +7 -0
  212. package/types/webpack-sources.d.ts +108 -0
@@ -0,0 +1,204 @@
1
+ import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo,
2
+ TaroEvent, TaroAny } from '@tarojs/runtime'
3
+
4
+ import { createNode } from './render'
5
+ import TaroComponentWrapper from './base'
6
+ import { TOUCH_EVENT_MAP } from './utils/constant/event'
7
+ import { createTaroEvent } from './utils/events'
8
+ import { FlexManager } from './utils/FlexManager'
9
+ import { getNodeThresholds, getNormalAttributes, shouldBindEvent, bindAnimation } from './utils/helper'
10
+
11
+ import type { TaroSwiperElement, TaroSwiperItemElement, TaroElement } from './element'
12
+ import type { TaroStyleType } from '@tarojs/runtime'
13
+
14
+ interface SwiperAttrs {
15
+ index?: number
16
+ loop?: boolean
17
+ duration?: number
18
+ interval?: number
19
+ vertical?: boolean
20
+ autoPlay?: boolean
21
+ indicator?: boolean
22
+ }
23
+
24
+ @Extend(Swiper)
25
+ function swiperStyle (style: TaroStyleType) {
26
+ .id(style.id)
27
+ .key(style.id)
28
+ .padding(style.padding)
29
+ .margin(style.margin)
30
+ .width(style.width)
31
+ .height(style.height)
32
+ .constraintSize(style.constraintSize)
33
+ .flexGrow(style.flexGrow)
34
+ .flexShrink(style.flexShrink)
35
+ .flexBasis(style.flexBasis)
36
+ .alignSelf(style.alignSelf)
37
+ .backgroundColor(style.backgroundColor)
38
+ .backgroundImage(style.backgroundImage, style.backgroundRepeat)
39
+ .backgroundImageSize(style.backgroundImageSize)
40
+ .rotate(style.rotate)
41
+ .scale(style.scale)
42
+ .translate(style.translate)
43
+ .transform(style.transform)
44
+ .borderStyle(style.borderStyle)
45
+ .borderWidth(style.borderWidth)
46
+ .borderColor(style.borderColor)
47
+ .borderRadius(style.borderRadius)
48
+ .linearGradient(style.linearGradient)
49
+ .zIndex(style.zIndex)
50
+ .opacity(style.opacity)
51
+ .clip(style.clip)
52
+ }
53
+
54
+ @Extend(Swiper)
55
+ function swiperAttr (attr: SwiperAttrs) {
56
+ .index(attr.index)
57
+ .loop(attr.loop)
58
+ .duration(attr.duration)
59
+ .interval(attr.interval)
60
+ .vertical(attr.vertical)
61
+ .autoPlay(attr.autoPlay)
62
+ .indicator(attr.indicator)
63
+ }
64
+
65
+ function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
66
+ const _attrs = node._attrs
67
+ const swiperAttrs: SwiperAttrs = {}
68
+ swiperAttrs.index = _attrs.current || 0
69
+ swiperAttrs.loop = _attrs.circular || false
70
+ swiperAttrs.duration = _attrs.duration || 500
71
+ swiperAttrs.interval = _attrs.interval || 5000
72
+ swiperAttrs.vertical = _attrs.vertical || false
73
+ swiperAttrs.autoPlay = _attrs.autoplay || false
74
+ swiperAttrs.indicator = _attrs.indicatorDots || false
75
+ return swiperAttrs
76
+ }
77
+
78
+ @Component
79
+ export struct TaroSwiper {
80
+ private swiperController: SwiperController = new SwiperController()
81
+
82
+ nodeInfoMap: TaroAny = {}
83
+
84
+ @ObjectLink node: TaroSwiperElement
85
+
86
+ @Styles visibleChangeEvent () {
87
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
88
+ }
89
+
90
+ aboutToAppear () {
91
+ initComponentNodeInfo(this, this.node)
92
+ bindInstanceToNode(this.node, this)
93
+ // 绑定动画
94
+ bindAnimation(this.node)
95
+ }
96
+
97
+ @Styles defaultEvent () {
98
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
99
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
100
+ const eventResult: TaroAny = res.eventResult
101
+ this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
102
+ }))
103
+ }
104
+
105
+ build() {
106
+ TaroComponentWrapper({ node: this.node }) {
107
+ Swiper(this.swiperController) {
108
+ ForEach(this.node.childNodes, (item: TaroElement) => {
109
+ createNode(item)
110
+ }, (item: TaroElement) => item._nid)
111
+ }
112
+ .swiperStyle(getNormalAttributes(this.node))
113
+ .swiperAttr(getSwiperAttributes(this.node))
114
+ .defaultEvent()
115
+ .indicatorStyle({
116
+ color: this.node.getAttribute('indicatorColor'),
117
+ selectedColor: this.node.getAttribute('indicatorActiveColor')
118
+ })
119
+ .onChange((index: number) => {
120
+ const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
121
+ eventHandler(event, 'change', this.node)
122
+ })
123
+ .visibleChangeEvent()
124
+ }
125
+ }
126
+ }
127
+
128
+ @Extend(Flex)
129
+ function flexStyle (style: TaroStyleType) {
130
+ .id(style.id)
131
+ .key(style.id)
132
+ .padding(style.padding)
133
+ .margin(style.margin)
134
+ .width(style.width)
135
+ .height(style.height)
136
+ .constraintSize(style.constraintSize)
137
+ .flexGrow(style.flexGrow)
138
+ .flexShrink(style.flexShrink)
139
+ .flexBasis(style.flexBasis)
140
+ .alignSelf(style.alignSelf)
141
+ .backgroundColor(style.backgroundColor)
142
+ .backgroundImage(style.backgroundImage, style.backgroundRepeat)
143
+ .backgroundImageSize(style.backgroundImageSize)
144
+ .rotate(style.rotate)
145
+ .scale(style.scale)
146
+ .translate(style.translate)
147
+ .transform(style.transform)
148
+ .borderStyle(style.borderStyle)
149
+ .borderWidth(style.borderWidth)
150
+ .borderColor(style.borderColor)
151
+ .borderRadius(style.borderRadius)
152
+ .linearGradient(style.linearGradient)
153
+ .zIndex(style.zIndex)
154
+ .opacity(style.opacity)
155
+ .clip(style.clip)
156
+ }
157
+
158
+ function getAttributes (node: TaroSwiperItemElement) {
159
+ const _attrs = node._attrs
160
+ const _nid = node._nid
161
+ const style = getNormalAttributes(node)
162
+ style.id = _attrs.itemId || _attrs.id || _nid
163
+ return style
164
+ }
165
+
166
+ @Component
167
+ export struct TaroSwiperItem {
168
+ nodeInfoMap: TaroAny = {}
169
+
170
+ @Styles visibleChangeEvent () {
171
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
172
+ }
173
+
174
+ @ObjectLink node: TaroSwiperItemElement
175
+
176
+ aboutToAppear () {
177
+ initComponentNodeInfo(this, this.node)
178
+ bindInstanceToNode(this.node, this)
179
+ // 绑定动画
180
+ bindAnimation(this.node)
181
+ }
182
+
183
+ @Styles defaultEvent () {
184
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
185
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
186
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
187
+ const eventResult: TaroAny = res.eventResult
188
+ this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
189
+ }))
190
+ }
191
+
192
+ build() {
193
+ TaroComponentWrapper({ node: this.node }) {
194
+ Flex(FlexManager.flexOptions(this.node)) {
195
+ ForEach(this.node.childNodes, (item: TaroElement) => {
196
+ createNode(item)
197
+ }, (item: TaroElement) => item._nid)
198
+ }
199
+ .flexStyle(getAttributes(this.node))
200
+ .defaultEvent()
201
+ .visibleChangeEvent()
202
+ }
203
+ }
204
+ }
@@ -0,0 +1,113 @@
1
+ import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo,
2
+ TaroEvent, TaroAny } from '@tarojs/runtime'
3
+
4
+ import TaroComponentWrapper from './base'
5
+ import { createTaroEvent } from './utils/events'
6
+ import { getNodeThresholds, shouldBindEvent, getNormalAttributes } from './utils/helper'
7
+
8
+ import type { TaroSwitchElement } from './element'
9
+ import type { TaroStyleType } from '@tarojs/runtime'
10
+
11
+ interface SwitchAttrs {
12
+ selectedColor?: ResourceColor
13
+ }
14
+
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
+ @Extend(Toggle)
46
+ function attrs(attr: SwitchAttrs) {
47
+ .selectedColor(attr.selectedColor)
48
+ }
49
+
50
+ function getAttributes (node: TaroSwitchElement): SwitchAttrs {
51
+ const _attrs = node._attrs
52
+ const switchStyle: SwitchAttrs = {}
53
+ switchStyle.selectedColor = _attrs.color || '#04BE02'
54
+ return switchStyle
55
+ }
56
+
57
+ @Extend(Toggle)
58
+ function themeStyles(isDisabled: boolean) {
59
+ .opacity(isDisabled ? 0.4 : 1)
60
+ }
61
+
62
+ @Component
63
+ export default struct TaroSwitch {
64
+ nodeInfoMap: TaroAny = {}
65
+
66
+ @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
+ }
73
+
74
+ aboutToAppear () {
75
+ initComponentNodeInfo(this, this.node)
76
+ bindInstanceToNode(this.node, this)
77
+
78
+ this.value = !!this.node._attrs.checked
79
+ }
80
+
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
+ }
88
+
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)
103
+ eventHandler(event, 'change', this.node)
104
+ } else {
105
+ // FIXME 找下文档是否有强制刷新方法
106
+ this.value = !this.value
107
+ this.value = !this.value
108
+ }
109
+ })
110
+ .visibleChangeEvent()
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,97 @@
1
+ import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny, NodeType } from '@tarojs/runtime'
2
+
3
+ import TaroComponentWrapper from './base'
4
+ import { getNodeThresholds, getNormalAttributes, getFontAttributes, shouldBindEvent, bindAnimation } from './utils/helper'
5
+
6
+ import type { TaroTextElement } from './element'
7
+ import type { TaroStyleType, TaroTextStyleType } from '@tarojs/runtime'
8
+
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
+ })
47
+ }
48
+
49
+ @Extend(Text)
50
+ function textAttr(attr: TaroTextStyleType) {
51
+ .textAlign(attr.textAlign)
52
+ .textOverflow(attr.textOverflow)
53
+ .maxLines(attr.maxLines)
54
+ .letterSpacing(attr.letterSpacing)
55
+ }
56
+
57
+
58
+ @Component
59
+ export default struct TaroText {
60
+ nodeInfoMap: TaroAny = {}
61
+
62
+ @Styles visibleChangeEvent () {
63
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
64
+ }
65
+
66
+ @ObjectLink node: TaroTextElement
67
+
68
+ aboutToAppear () {
69
+ initComponentNodeInfo(this, this.node)
70
+ bindInstanceToNode(this.node, this)
71
+ // 绑定动画
72
+ bindAnimation(this.node)
73
+ }
74
+
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
+ }))
81
+ }
82
+
83
+
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
+ }
95
+ }
96
+ }
97
+ }
@@ -0,0 +1,169 @@
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'
6
+
7
+ import TaroComponentWrapper from './base'
8
+ import { createTaroEvent } from './utils/events'
9
+ import { getNodeThresholds, getNormalAttributes, getFontAttributes, parseStyles, shouldBindEvent, bindAnimation } from './utils/helper'
10
+
11
+ import type { TaroTextAreaElement } from './element'
12
+ import type { TaroStyleType, TaroTextStyleType } from '@tarojs/runtime'
13
+
14
+ @Extend(TextArea)
15
+ 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
+ .fontColor(style.color)
43
+ .fontSize(style.fontSize)
44
+ .fontWeight(style.fontWeight)
45
+ .fontStyle(style.fontStyle)
46
+ .fontFamily(style.fontFamily)
47
+ }
48
+
49
+ @Extend(TextArea)
50
+ function textAttr(attr: TaroTextStyleType) {
51
+ .textAlign(attr.textAlign)
52
+ .maxLines(attr.maxLines)
53
+ }
54
+
55
+ @Component
56
+ struct TaroTextArea {
57
+ nodeInfoMap: TaroAny = {}
58
+
59
+ @State text: string = ''
60
+
61
+ @ObjectLink node: TaroTextAreaElement
62
+
63
+ controller: TextAreaController = new TextAreaController()
64
+
65
+ windowClass?: window.Window
66
+
67
+ _height: number = 0
68
+
69
+ heightChange = (height: number) => {
70
+ if (isNumber(height)) {
71
+ if (this._height !== height) {
72
+ this.onKeyboardHeightChange(height)
73
+ this._height = height
74
+ }
75
+ }
76
+ }
77
+
78
+ @Styles visibleChangeEvent () {
79
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
+ }
81
+
82
+ aboutToAppear () {
83
+ initComponentNodeInfo(this, this.node)
84
+ bindInstanceToNode(this.node, this)
85
+ bindFocus(this.node)
86
+ // 绑定动画
87
+ bindAnimation(this.node)
88
+
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))
115
+ }
116
+ }
117
+ }
118
+
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
+ }
166
+ }
167
+ }
168
+
169
+ export default TaroTextArea