@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,195 @@
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 { 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'
12
+
13
+ import type { TaroInputElement } from './element'
14
+ import type { TaroStyleType } from '@tarojs/runtime'
15
+
16
+ interface InputAttrs {
17
+ textAlign?: TextAlign
18
+ }
19
+
20
+ @Extend(TextInput)
21
+ 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
+ .fontColor(style.color)
49
+ .fontSize(style.fontSize)
50
+ .fontWeight(style.fontWeight)
51
+ .fontStyle(style.fontStyle)
52
+ .fontFamily(style.fontFamily)
53
+ }
54
+
55
+ @Extend(TextInput)
56
+ function attrs(attr: InputAttrs) {
57
+ .textAlign(attr.textAlign)
58
+ }
59
+
60
+
61
+ function getAttributes(node: TaroInputElement): InputAttrs {
62
+ return {
63
+ textAlign: node.hmStyle.textAlign,
64
+ }
65
+ }
66
+
67
+ @Component
68
+ struct TaroInput {
69
+ nodeInfoMap: TaroAny = {}
70
+
71
+ @State text: string = ''
72
+
73
+ @ObjectLink node: TaroInputElement
74
+
75
+ controller: TextInputController = new TextInputController()
76
+
77
+ windowClass?: window.Window
78
+
79
+ _height: number = 0
80
+
81
+ @Styles visibleChangeEvent () {
82
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
83
+ }
84
+
85
+ heightChange = (height: number) => {
86
+ if (isNumber(height)) {
87
+ if (this._height !== height) {
88
+ this.onKeyboardHeightChange(height)
89
+ this._height = height
90
+ }
91
+ }
92
+ }
93
+
94
+ 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
+ }
120
+
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))
127
+ }
128
+ }
129
+ }
130
+
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 () {
153
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
154
+ .onBlur(() => {
155
+ const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.text } }, this.node)
156
+ eventHandler(event, 'blur', this.node)
157
+ })
158
+ .onFocus(() => {
159
+ const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.text, height: this._height } }, this.node)
160
+ eventHandler(event, 'focus', this.node)
161
+ })
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]
165
+ }))
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
+ }
192
+ }
193
+ }
194
+
195
+ export default TaroInput
@@ -0,0 +1,111 @@
1
+ import { bindInstanceToNode, Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME,
2
+ 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 { FlexManager } from './utils/FlexManager'
8
+ import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
9
+
10
+ import type { TaroLabelElement, TaroElement } from './element'
11
+ import type { TaroStyleType } from '@tarojs/runtime'
12
+
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
+ }
42
+
43
+ @Component
44
+ export default struct TaroLabel {
45
+ nodeInfoMap: TaroAny = {}
46
+
47
+ @Styles visibleChangeEvent () {
48
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
49
+ }
50
+
51
+ @ObjectLink node: TaroLabelElement
52
+
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
+ }
96
+ }
97
+ }
98
+
99
+ build() {
100
+ TaroComponentWrapper({ node: this.node }) {
101
+ Flex(FlexManager.flexOptions(this.node)) {
102
+ ForEach(this.node.childNodes, (item: TaroElement) => {
103
+ createNode(item)
104
+ }, (item: TaroElement) => item._nid)
105
+ }
106
+ .attrs(getNormalAttributes(this.node))
107
+ .defaultEvent()
108
+ .visibleChangeEvent()
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,370 @@
1
+ import { bindInstanceToNode, AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, getPageScrollerOrNode,
2
+ TaroAny,
3
+ TaroEvent
4
+ } from '@tarojs/runtime'
5
+ import { createNode } from './render'
6
+ import TaroComponentWrapper from './base'
7
+ import { getSingleSelector, getMultiSelector } from './utils'
8
+ import { TOUCH_EVENT_MAP } from './utils/constant/event'
9
+ import { FlexManager } from './utils/FlexManager'
10
+ import { createTaroEvent } from './utils/events'
11
+ import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
12
+
13
+ import type { TaroPickerElement, TaroElement } from './element'
14
+ import type { TaroStyleType } from '@tarojs/runtime'
15
+
16
+ import { PickerDateProps, PickerMultiSelectorProps, PickerSelectorProps, PickerTimeProps } from './types'
17
+
18
+ @Extend(TextPicker)
19
+ function textPickerAttrs (style: TaroStyleType) {
20
+ .id(style.id)
21
+ .key(style.id)
22
+ .padding(style.padding)
23
+ .margin(style.margin)
24
+ .width(style.width || '100%')
25
+ .height(style.height)
26
+ .constraintSize(style.constraintSize)
27
+ .flexGrow(style.flexGrow)
28
+ .flexShrink(style.flexShrink)
29
+ .flexBasis(style.flexBasis)
30
+ .alignSelf(style.alignSelf)
31
+ .backgroundColor(style.backgroundColor || '#fff')
32
+ .backgroundImage(style.backgroundImage, style.backgroundRepeat)
33
+ .backgroundImageSize(style.backgroundImageSize)
34
+ .rotate(style.rotate)
35
+ .scale(style.scale)
36
+ .translate(style.translate)
37
+ .transform(style.transform)
38
+ .borderStyle(style.borderStyle)
39
+ .borderWidth(style.borderWidth)
40
+ .borderColor(style.borderColor)
41
+ .borderRadius(style.borderRadius)
42
+ .linearGradient(style.linearGradient)
43
+ .zIndex(style.zIndex)
44
+ .opacity(style.opacity)
45
+ .clip(style.clip)
46
+ }
47
+
48
+ @Extend(DatePicker)
49
+ function datePickerAttrs (style: TaroStyleType) {
50
+ .id(style.id)
51
+ .key(style.id)
52
+ .padding(style.padding)
53
+ .margin(style.margin)
54
+ .width(style.width || '100%')
55
+ .height(style.height)
56
+ .constraintSize(style.constraintSize)
57
+ .flexGrow(style.flexGrow)
58
+ .flexShrink(style.flexShrink)
59
+ .flexBasis(style.flexBasis)
60
+ .alignSelf(style.alignSelf)
61
+ .backgroundColor(style.backgroundColor || '#fff')
62
+ .backgroundImage(style.backgroundImage, style.backgroundRepeat)
63
+ .backgroundImageSize(style.backgroundImageSize)
64
+ .rotate(style.rotate)
65
+ .scale(style.scale)
66
+ .translate(style.translate)
67
+ .transform(style.transform)
68
+ .borderStyle(style.borderStyle)
69
+ .borderWidth(style.borderWidth)
70
+ .borderColor(style.borderColor)
71
+ .borderRadius(style.borderRadius)
72
+ .linearGradient(style.linearGradient)
73
+ .zIndex(style.zIndex)
74
+ .opacity(style.opacity)
75
+ .clip(style.clip)
76
+ }
77
+
78
+ interface TimeRange {
79
+ startHH: number
80
+ startMM: number
81
+ endHH: number
82
+ endMM: number
83
+ }
84
+
85
+ @CustomDialog
86
+ export struct PickerView {
87
+
88
+ @ObjectLink node: TaroPickerElement
89
+
90
+ @Link select: string | number
91
+
92
+ controller?: CustomDialogController
93
+
94
+ multiColumnIndex: number[] = []
95
+
96
+ showSelector: number[] = []
97
+
98
+ getDateOptions (): DatePickerOptions {
99
+ const _attrs = this.node._attrs as PickerDateProps
100
+ return {
101
+ start: new Date(_attrs.start || ''),
102
+ end: new Date(_attrs.end || ''),
103
+ selected: new Date(_attrs.value || ''),
104
+ }
105
+ }
106
+
107
+ getTextOptions (): TextPickerOptions {
108
+ let mode: string = this.node._attrs.mode || 'selector'
109
+ if (!mode) {
110
+ const _attrs = this.node._attrs as PickerSelectorProps
111
+ const range = _attrs.range
112
+ if (range && range.length && range[0] instanceof Array) {
113
+ mode = 'multiSelector'
114
+ }
115
+ mode = 'selector'
116
+ }
117
+ switch (mode) {
118
+ case 'time': {
119
+ const _attrs = this.node._attrs as PickerTimeProps
120
+ let timeRange: TimeRange = {
121
+ startHH: 0,
122
+ startMM: 0,
123
+ endHH: 23,
124
+ endMM: 59
125
+ }
126
+ if (_attrs.start) {
127
+ const _start = _attrs.start.split(':')
128
+ timeRange.startHH = parseInt(_start[0])
129
+ timeRange.startMM = parseInt(_start[1])
130
+ }
131
+ if (_attrs.end) {
132
+ const _end = _attrs.end.split(':')
133
+ timeRange.endHH = parseInt(_end[0])
134
+ timeRange.endMM = parseInt(_end[1])
135
+ }
136
+ const left = generateNumberArray(timeRange.startHH, timeRange.endHH)
137
+ const right = generateNumberArray(timeRange.startMM, timeRange.endMM)
138
+ const range = [left, right]
139
+ const _selected = _attrs.value.split(':')
140
+ return {
141
+ range: range,
142
+ selected: [left.findIndex(i => parseInt(_selected[0]) === Number(i)), right.findIndex(i => parseInt(_selected[1]) === Number(i))],
143
+ }
144
+ }
145
+ case 'multiSelector': {
146
+ const _attrs = this.node._attrs as PickerMultiSelectorProps
147
+ const value = _attrs.value as number[]
148
+ let showRange = _attrs.range as string[][]
149
+ this.showSelector = value
150
+ showRange = getMultiSelector(this, _attrs.range, _attrs.rangeKey, value)
151
+ let selects: string | number | string[] | number[] = this.select
152
+ if (typeof selects === 'string') {
153
+ selects = selects.split(',').map(i => Number(i))
154
+ }
155
+ return {
156
+ range: showRange,
157
+ selected: selects || value
158
+ }
159
+ }
160
+ default: {
161
+ const _attrs = this.node._attrs as PickerSelectorProps
162
+ const range = _attrs.range
163
+ let showRange = _attrs.range as string[]
164
+ if (_attrs.rangeKey && typeof range[0] === 'object') {
165
+ showRange = getSingleSelector(this, range, _attrs.rangeKey)
166
+ }
167
+ return {
168
+ range: showRange,
169
+ selected: (this.select as number) || _attrs.value
170
+ }
171
+ }
172
+ }
173
+ }
174
+
175
+ emitEvent = (type: string, detail: TaroAny = {}) => {
176
+ const event: TaroEvent = createTaroEvent(type, { detail }, this.node)
177
+ event.stopPropagation()
178
+ eventHandler(event, type, this.node)
179
+ }
180
+
181
+ getText = () => {
182
+ if (this.node._attrs.mode === 'selector') {
183
+ const _attrs = this.node._attrs as PickerSelectorProps
184
+ return [_attrs.textProps?.okText || '确认', _attrs.textProps?.cancelText || '取消']
185
+ } else {
186
+ return ['确认', '取消']
187
+ }
188
+ }
189
+
190
+ @Builder
191
+ showDialog() {
192
+ Column() {
193
+ Flex({
194
+ direction: FlexDirection.Row,
195
+ justifyContent: FlexAlign.SpaceBetween,
196
+ alignItems: ItemAlign.Center
197
+ }) {
198
+ Text(this.getText()[1]).fontSize(15).padding({top: 20, bottom: 40}).fontColor('#888').onClick(() => {
199
+ this.emitEvent('cancel')
200
+ this.controller?.close()
201
+ })
202
+ Text(this.getText()[0]).fontSize(15).padding({top: 20, bottom: 40}).fontColor('#1aad19').onClick(() => {
203
+ this.emitEvent('change', { value: this.select})
204
+ this.controller?.close()
205
+ })
206
+ }
207
+ .width('100%')
208
+ .backgroundColor('#fff')
209
+ .padding({
210
+ left: 20,
211
+ right: 20
212
+ })
213
+ if (this.node._attrs.mode === 'selector') {
214
+ TextPicker(this.getTextOptions())
215
+ .selectedTextStyle({
216
+ color: '#000'
217
+ })
218
+ .canLoop(false)
219
+ .textPickerAttrs(getNormalAttributes(this.node))
220
+ .onChange((value, index) => {
221
+ this.select = index as number
222
+ })
223
+ } else if (this.node._attrs.mode === 'multiSelector') {
224
+ TextPicker(this.getTextOptions())
225
+ .selectedTextStyle({
226
+ color: '#000'
227
+ })
228
+ .canLoop(false)
229
+ .textPickerAttrs(getNormalAttributes(this.node))
230
+ .onChange((value, index) => {
231
+ if (index instanceof Array) {
232
+ this.select = index.join(',')
233
+ // 计算几列发生了变化
234
+ const originIndexs: number[] = this.multiColumnIndex || this.showSelector
235
+ this.multiColumnIndex = index
236
+ let changeValue: number | undefined
237
+ const changeIndex = index.findIndex((item, i) => {
238
+ const originIndex = originIndexs[i]
239
+ if (originIndex != item) {
240
+ changeValue = item
241
+ return true
242
+ }
243
+ return false
244
+ })
245
+ if (changeIndex < 0) {
246
+ return
247
+ }
248
+ this.emitEvent('columnChange', { column: changeIndex, value: changeValue })
249
+ }
250
+ })
251
+ } else if (this.node._attrs.mode === 'date') {
252
+ DatePicker(this.getDateOptions())
253
+ .selectedTextStyle({
254
+ color: '#000'
255
+ })
256
+ .datePickerAttrs(getNormalAttributes(this.node))
257
+ .onChange(value => {
258
+ this.select = `${value.year}-${value.month}-${value.day}`
259
+ })
260
+ } else if (this.node._attrs.mode === 'time') {
261
+ TextPicker(this.getTextOptions())
262
+ .selectedTextStyle({
263
+ color: '#000'
264
+ })
265
+ .canLoop(false)
266
+ .textPickerAttrs(getNormalAttributes(this.node))
267
+ .onChange((value) => {
268
+ this.select = `${('00'+value[0]).slice(-2)}:${('00'+value[1]).slice(-2)}}`
269
+ })
270
+ }
271
+ }
272
+ }
273
+
274
+ build() {
275
+ this.showDialog()
276
+ }
277
+ }
278
+
279
+
280
+
281
+ @Component
282
+ export default struct TaroPicker {
283
+ nodeInfoMap: TaroAny = {}
284
+
285
+ @State select: string = ''
286
+
287
+ @ObjectLink node: TaroPickerElement
288
+
289
+ aboutToAppear () {
290
+ initComponentNodeInfo(this, this.node)
291
+ bindInstanceToNode(this.node, this)
292
+ // 绑定动画
293
+ bindAnimation(this.node)
294
+
295
+ this.select = this.node._attrs.value as TaroAny
296
+
297
+ this.node.addEventListener('click', this.handleClick)
298
+ }
299
+
300
+ dialogController: CustomDialogController | null = null
301
+
302
+ aboutToDisappear() {
303
+ this.dialogController = null // 将dialogController置空
304
+ }
305
+
306
+
307
+ handleClick = () => {
308
+ if (!this.dialogController) {
309
+ this.dialogController = new CustomDialogController({
310
+ builder: PickerView({
311
+ node: this.node,
312
+ select: this.select
313
+ }),
314
+ customStyle: true,
315
+ cornerRadius: '0vp',
316
+ autoCancel: true,
317
+ alignment: DialogAlignment.Bottom,
318
+ offset: { dx: 0, dy: 0 },
319
+ gridCount: 4,
320
+ cancel: () => {
321
+ const event: TaroEvent = createTaroEvent('cancel', { detail: {} }, this.node)
322
+ event.stopPropagation()
323
+ eventHandler(event, 'cancel', this.node)
324
+ }
325
+ })
326
+ }
327
+ this.dialogController.open()
328
+ }
329
+
330
+ @Styles defaultEvent () {
331
+ .onClick((e: ClickEvent) => {
332
+ eventHandler(e, 'click', this.node)
333
+ })
334
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
335
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
336
+ const eventResult: TaroAny = res.eventResult
337
+ this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
338
+ }))
339
+ }
340
+
341
+ @Styles visibleChangeEvent () {
342
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
343
+ }
344
+
345
+ build() {
346
+ TaroComponentWrapper({ node: this.node }) {
347
+ Flex(FlexManager.flexOptions(this.node)) {
348
+ ForEach(this.node.childNodes, (item: TaroElement) => {
349
+ createNode(item)
350
+ }, (item: TaroElement) => item._nid)
351
+ }
352
+ .defaultEvent()
353
+ .visibleChangeEvent()
354
+ }
355
+ }
356
+ }
357
+
358
+
359
+
360
+ function generateNumberArray(x: number, y: number) {
361
+ // 创建一个空数组来存储结果
362
+ let result: string[] = []
363
+
364
+ // 使用循环将 x 到 y 之间的数字添加到数组中
365
+ for (let i = x; i <= y; i++) {
366
+ result.push(`${i}`)
367
+ }
368
+ // 返回结果数组
369
+ return result
370
+ }