@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,108 @@
1
+ import { eventSource } from '@tarojs/runtime/dist/runtime.esm'
2
+ import { isUndefined } from '@tarojs/shared'
3
+
4
+ import { Current } from '../current'
5
+ import { TaroComment } from './comment'
6
+ import { createCSSStyleDeclaration } from './cssStyleDeclaration'
7
+ import { TaroButtonElement, TaroCheckboxGroupElement, TaroElement, TaroIgnoreElement, TaroImageElement, TaroInputElement, TaroPickerElement, TaroRadioGroupElement, TaroSliderElement, TaroSwitchElement, TaroTextElement, TaroVideoElement, TaroViewElement } from './element'
8
+ import { NodeType, TaroNode } from './node'
9
+ import { TaroTextNode } from './text'
10
+
11
+ import type { Window } from '../bom/window'
12
+
13
+ class TaroDocument extends TaroNode {
14
+ public documentElement: TaroElement
15
+ public head: TaroElement
16
+ public body: TaroElement
17
+ public cookie = ''
18
+ private _win: Window
19
+
20
+ constructor(window: Window) {
21
+ super('#document', NodeType.DOCUMENT_NODE)
22
+ this._win = window
23
+ window._doc = this
24
+ }
25
+
26
+ get defaultView (): Window {
27
+ return this._win
28
+ }
29
+
30
+ public createElement (tagName: string): TaroElement {
31
+ let node: TaroElement
32
+
33
+ // @ts-ignore
34
+ if (Current?.createHarmonyElement) {
35
+ // @ts-ignore
36
+ node = Current.createHarmonyElement(tagName)
37
+ } else {
38
+ switch (tagName) {
39
+ case 'view':
40
+ node = new TaroViewElement()
41
+ break
42
+ case 'text':
43
+ node = new TaroTextElement()
44
+ break
45
+ case 'image':
46
+ node = new TaroImageElement()
47
+ break
48
+ case 'button':
49
+ node = new TaroButtonElement()
50
+ break
51
+ case 'video':
52
+ node = new TaroVideoElement()
53
+ break
54
+ case 'input':
55
+ node = new TaroInputElement()
56
+ break
57
+ case 'switch':
58
+ node = new TaroSwitchElement()
59
+ break
60
+ case 'slider':
61
+ node = new TaroSliderElement()
62
+ break
63
+ case 'checkbox-group':
64
+ node = new TaroCheckboxGroupElement()
65
+ break
66
+ case 'radio-group':
67
+ node = new TaroRadioGroupElement()
68
+ break
69
+ case 'picker':
70
+ node = new TaroPickerElement()
71
+ break
72
+ case 'ignore':
73
+ node = new TaroIgnoreElement()
74
+ break
75
+ default:
76
+ node = new TaroElement(tagName)
77
+ }
78
+ }
79
+ node._doc = this
80
+ // Hack: 此 Proxy 不能放在 Element 类内定义,否则响应式更新会失效
81
+ node._style = createCSSStyleDeclaration(node)
82
+ return node
83
+ }
84
+
85
+ public createTextNode (value: string): TaroTextNode {
86
+ const node = new TaroTextNode(value)
87
+ node._doc = this
88
+ return node
89
+ }
90
+
91
+ public createComment (data: string): TaroComment {
92
+ return new TaroComment(data)
93
+ }
94
+
95
+
96
+ public getElementById<T extends TaroElement> (id: string | undefined | null): T | null {
97
+ const el = eventSource.get(id)
98
+ return isUndefined(el) ? null : el as unknown as T
99
+ }
100
+
101
+ // @Todo
102
+ // public getElementsByClassName (names: string): TaroElement[]
103
+ // public querySelector (selectors: string): TaroElement | null
104
+ // public querySelectorAll (selectors: string): TaroElement[]
105
+ // public createElementNS
106
+ }
107
+
108
+ export { TaroDocument }
@@ -0,0 +1,457 @@
1
+ // @ts-nocheck
2
+ import { eventSource } from '@tarojs/runtime/dist/runtime.esm'
3
+
4
+ import {
5
+ ButtonProps,
6
+ CheckboxGroupProps,
7
+ CheckboxProps,
8
+ FormProps,
9
+ IconProps,
10
+ ImageProps, InputProps,
11
+ LabelProps,
12
+ PickerDateProps,
13
+ PickerMultiSelectorProps,
14
+ PickerSelectorProps,
15
+ PickerTimeProps,
16
+ RadioGroupProps,
17
+ RadioProps,
18
+ RichTextProps,
19
+ ScrollViewProps,
20
+ SliderProps,
21
+ StandardProps,
22
+ SwiperItemProps,
23
+ SwiperProps,
24
+ SwitchProps,
25
+ TextareaProps,
26
+ TextProps,
27
+ VideoProps
28
+ } from '../../components/types'
29
+ import { ATTRIBUTES_CALLBACK_TRIGGER_MAP, ID } from '../constant'
30
+ import { findChildNodeWithDFS, isElement, TaroAny } from '../utils'
31
+ import { triggerAttributesCallback } from '../utils/info'
32
+ import { ClassList } from './class-list'
33
+ import { NodeType, TaroNode } from './node'
34
+ import StyleSheet from './stylesheet'
35
+
36
+ import type { ICSSStyleDeclaration } from './cssStyleDeclaration'
37
+
38
+ type NamedNodeMap = ({ name: string, value: string })[]
39
+
40
+ interface TaroAttributeProps extends StandardProps {
41
+ compileMode?: string | boolean
42
+ compileIf?: boolean
43
+ disabled?: boolean
44
+ }
45
+
46
+ export class TaroElement<T extends TaroAttributeProps = TaroAttributeProps> extends TaroNode {
47
+
48
+ public _attrs: T = {}
49
+
50
+ private _innerHTML = ''
51
+ public readonly tagName: string
52
+
53
+ // 用于标记元素是否已经出现
54
+ private _appearResolve: (value?: unknown) => void
55
+ public awaitAppear: Promise<unknown>
56
+ public resolveAppear = () => this._appearResolve()
57
+
58
+ // public changeRecord = ''
59
+
60
+ constructor(tagName: string) {
61
+ super(tagName.replace(/(?<=.)([A-Z])/g, '-$1').toUpperCase(), NodeType.ELEMENT_NODE)
62
+ this.tagName = this.nodeName
63
+
64
+ this.awaitAppear = new Promise(resolve => { this._appearResolve = resolve })
65
+ }
66
+
67
+ public set id (value: string) {
68
+ this.setAttribute('id', value)
69
+ }
70
+
71
+ public get id (): string {
72
+ return this.getAttribute('id') || this._nid
73
+ }
74
+
75
+ public set className (value: string) {
76
+ this.setAttribute('class', value)
77
+ }
78
+
79
+ public get className (): string {
80
+ return this.getAttribute('class') || ''
81
+ }
82
+
83
+ public get classList (): ClassList {
84
+ return new ClassList(this.className, this)
85
+ }
86
+
87
+ public get attributes (): NamedNodeMap {
88
+ const list: NamedNodeMap = []
89
+ for (const name in this._attrs) {
90
+ const value = this._attrs[name]
91
+ list.push({ name, value })
92
+ }
93
+ return list
94
+ }
95
+
96
+ public get children (): TaroElement[] {
97
+ return this.childNodes.filter(isElement)
98
+ }
99
+
100
+ public setAttribute (name: string, value: any): void {
101
+ if (name === ID) {
102
+ eventSource.delete(this._attrs.id)
103
+ eventSource.set(value, this as any)
104
+ }
105
+
106
+ this._attrs[name] = value
107
+
108
+ const attributeTriggerValue = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
109
+ if (attributeTriggerValue) {
110
+ const { triggerName, valueInspect } = attributeTriggerValue
111
+
112
+ if (valueInspect && !valueInspect(value)) return
113
+
114
+ triggerAttributesCallback(this, triggerName)
115
+ }
116
+ }
117
+
118
+ public getAttribute (name: string): string {
119
+ return this._attrs[name]
120
+ }
121
+
122
+ public removeAttribute (name: string): void {
123
+ delete this._attrs[name]
124
+ }
125
+
126
+ public hasAttribute (name: string): boolean {
127
+ return this._attrs.hasOwnProperty(name)
128
+ }
129
+
130
+ public hasAttributes (): boolean {
131
+ return Object.keys(this._attrs).length > 0
132
+ }
133
+
134
+ public getElementById (id: string | undefined | null): TaroElement | null {
135
+ return findChildNodeWithDFS(this, (el) => {
136
+ return el.id === id
137
+ }, false)
138
+ }
139
+
140
+ public getElementsByTagName<T> (tagName: string): T[] {
141
+ return findChildNodeWithDFS(this, (el) => {
142
+ return el.nodeName === tagName || (tagName === '*' && this !== el)
143
+ }, true) || []
144
+ }
145
+
146
+ public getElementsByClassName (className: string): TaroElement[] {
147
+ const classNames = className.trim().split(/\s+/)
148
+
149
+ return findChildNodeWithDFS(this, (el) => {
150
+ const classList = el.classList
151
+ return classNames.every(c => classList.contains(c))
152
+ }, true) || []
153
+ }
154
+
155
+ // TODO dataset
156
+
157
+ public set innerHTML (value: string) {
158
+ if (this.nodeType === NodeType.ELEMENT_NODE) {
159
+ const ele = this.ownerDocument.createElement('inner-html')
160
+ ele._innerHTML = value
161
+ this.appendChild(ele)
162
+ }
163
+ }
164
+
165
+ public get innerHTML (): string {
166
+ return this._innerHTML
167
+ }
168
+
169
+ public _st = new StyleSheet()
170
+
171
+ // 经转换后的鸿蒙样式
172
+ public get hmStyle () {
173
+ return this._st.hmStyle
174
+ }
175
+
176
+ public _style: ICSSStyleDeclaration
177
+
178
+ public get style (): ICSSStyleDeclaration {
179
+ return this._style
180
+ }
181
+ }
182
+
183
+ export class TaroViewElement extends TaroElement {
184
+ constructor() {
185
+ super('View')
186
+ }
187
+ }
188
+
189
+ export class TaroTextElement extends TaroElement<TextProps> {
190
+ constructor() {
191
+ super('Text')
192
+ }
193
+ }
194
+
195
+ export class TaroImageElement extends TaroElement<ImageProps> {
196
+ constructor() {
197
+ super('Image')
198
+ }
199
+ }
200
+
201
+ export class TaroButtonElement extends TaroElement<ButtonProps> {
202
+ constructor() {
203
+ super('Button')
204
+ }
205
+ }
206
+
207
+
208
+ export class TaroFormWidgetElement<T extends TaroAttributeProps = TaroAttributeProps> extends TaroElement<T> {
209
+
210
+ public get name () {
211
+ return this._attrs.name
212
+ }
213
+
214
+ public set name (val) {
215
+ this._attrs.name = val
216
+ }
217
+
218
+ public get value () {
219
+ return ''
220
+ }
221
+
222
+ public set value (val: any) {
223
+ if (this._instance) {
224
+ this._instance.value = val
225
+ }
226
+ this._attrs.value = val
227
+ }
228
+ }
229
+
230
+ export class TaroInputElement extends TaroFormWidgetElement<InputProps> {
231
+ constructor() {
232
+ super('Input')
233
+ }
234
+
235
+ public get value () {
236
+ if (this._instance) {
237
+ return this._instance.text
238
+ } else {
239
+ return this._attrs.value || ''
240
+ }
241
+ }
242
+
243
+ public set value (val) {
244
+ if (this._instance) {
245
+ this._instance.text = val
246
+ }
247
+ this._attrs.value = val
248
+ }
249
+ }
250
+
251
+ export class TaroSliderElement extends TaroFormWidgetElement<SliderProps> {
252
+ constructor() {
253
+ super('Slider')
254
+ }
255
+
256
+ public get value () {
257
+ if (this._instance) {
258
+ return this._instance.value
259
+ } else {
260
+ return this._attrs.value || ''
261
+ }
262
+ }
263
+
264
+ public set value (val) {
265
+ if (this._instance) {
266
+ this._instance.value = val
267
+ }
268
+ }
269
+ }
270
+
271
+ export class TaroSwitchElement extends TaroFormWidgetElement<SwitchProps> {
272
+ constructor() {
273
+ super('Switch')
274
+ }
275
+
276
+ public get value () {
277
+ if (this._instance) {
278
+ return this._instance.value
279
+ } else {
280
+ return this._attrs.checked || ''
281
+ }
282
+ }
283
+
284
+ public set value (val) {
285
+ if (this._instance) {
286
+ this._instance.value = val
287
+ }
288
+ }
289
+ }
290
+
291
+ export class TaroCheckboxGroupElement extends TaroFormWidgetElement<CheckboxGroupProps> {
292
+ constructor() {
293
+ super('CheckboxGroup')
294
+ }
295
+
296
+ public get value () {
297
+ if (this._instance) {
298
+ return this._instance.getValues()
299
+ }
300
+ }
301
+ }
302
+
303
+ export class TaroRadioGroupElement extends TaroFormWidgetElement<RadioGroupProps> {
304
+ constructor() {
305
+ super('RadioGroup')
306
+ }
307
+
308
+ public get value () {
309
+ if (this._instance) {
310
+ return this._instance.getValue()
311
+ }
312
+ }
313
+
314
+ }
315
+
316
+ export class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | PickerTimeProps | PickerDateProps | PickerMultiSelectorProps> {
317
+ constructor() {
318
+ super('Picker')
319
+ }
320
+
321
+ public get value () {
322
+ if (this._instance) {
323
+ if (this._instance.select instanceof Array) {
324
+ return this._instance.select.join(',')
325
+ }
326
+ return this._instance.select
327
+ }
328
+ }
329
+
330
+ public set value (val) {
331
+ if (this._instance) {
332
+ this._instance.select = val
333
+ }
334
+ }
335
+ }
336
+
337
+ export class TaroVideoElement extends TaroElement<VideoProps> {
338
+ constructor() {
339
+ super('Video')
340
+ }
341
+
342
+ async play() {
343
+ try {
344
+ this._instance.controller.start()
345
+ return Promise.resolve()
346
+ } catch (e) {
347
+ return Promise.reject(e)
348
+ }
349
+ }
350
+
351
+ pause() {
352
+ try {
353
+ this._instance.controller.pause()
354
+ return Promise.resolve()
355
+ } catch (e) {
356
+ return Promise.reject(e)
357
+ }
358
+ }
359
+
360
+ stop() {
361
+ try {
362
+ this._instance.controller.stop()
363
+ return Promise.resolve()
364
+ } catch (e) {
365
+ return Promise.reject(e)
366
+ }
367
+ }
368
+
369
+ get currentTime() {
370
+ return this._instance.nodeInfoMap[this._nid].currentTime || 0
371
+ }
372
+
373
+ set currentTime(val: number) {
374
+ this._instance.nodeInfoMap[this._nid].currentTime = val
375
+ this._instance.controller.setCurrentTime(val)
376
+ }
377
+ }
378
+
379
+ export class TaroScrollViewElement extends TaroElement<ScrollViewProps> {
380
+ constructor() {
381
+ super('ScrollView')
382
+ }
383
+ }
384
+ export class TaroCheckboxElement extends TaroElement<CheckboxProps> {
385
+ constructor() {
386
+ super('Checkbox')
387
+ }
388
+ }
389
+ export class TaroRadioElement extends TaroElement<RadioProps> {
390
+ constructor() {
391
+ super('Radio')
392
+ }
393
+
394
+ public group?: string
395
+ }
396
+ export class TaroIconElement extends TaroElement<IconProps> {
397
+ constructor() {
398
+ super('Icon')
399
+ }
400
+ }
401
+ export class TaroLabelElement extends TaroElement<LabelProps> {
402
+ constructor() {
403
+ super('Label')
404
+ }
405
+ }
406
+ export class TaroRichTextElement extends TaroElement<RichTextProps> {
407
+ constructor() {
408
+ super('RichText')
409
+ }
410
+ }
411
+ export class TaroSwiperElement extends TaroElement<SwiperProps> {
412
+ constructor() {
413
+ super('Swiper')
414
+ }
415
+ }
416
+ export class TaroSwiperItemElement extends TaroElement<SwiperItemProps> {
417
+ constructor() {
418
+ super('SwiperItem')
419
+ }
420
+ }
421
+ export class TaroTextAreaElement extends TaroElement<TextareaProps> {
422
+ constructor() {
423
+ super('TextArea')
424
+ }
425
+ }
426
+
427
+ export class TaroIgnoreElement extends TaroElement {
428
+ isIgnore = true
429
+
430
+ constructor() {
431
+ super('Ignore')
432
+ }
433
+ }
434
+
435
+ export class FormElement extends TaroElement<FormProps> {
436
+ constructor() {
437
+ super('Form')
438
+ }
439
+ // public get type () {
440
+ // return this._attrs.type ?? ''
441
+ // }
442
+ //
443
+ // public set type (val: string) {
444
+ // this.setAttribute('type', val)
445
+ // }
446
+
447
+ public get value () {
448
+ // eslint-disable-next-line dot-notation
449
+ const val = this._attrs.value
450
+ return val == null ? '' : val
451
+ }
452
+
453
+ public set value (val: string | boolean | number | any[]) {
454
+ this.setAttribute('value', val)
455
+ }
456
+ }
457
+
@@ -0,0 +1,164 @@
1
+ import { hooks } from '@tarojs/shared'
2
+
3
+ import { CONFIRM, CURRENT_TARGET, INPUT, KEY_CODE, TARGET, TIME_STAMP, TYPE } from '../constant'
4
+ import { TaroElement } from './element'
5
+
6
+ import type { EventOptions } from '../interface'
7
+
8
+ // Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
9
+ export class TaroEvent<T = any> {
10
+ public type: string
11
+
12
+ public bubbles: boolean
13
+
14
+ public cancelable: boolean
15
+
16
+ public _stop = false
17
+
18
+ public _end = false
19
+
20
+ public defaultPrevented = false
21
+
22
+ public target: TaroElement
23
+
24
+ public currentTarget: TaroElement
25
+
26
+ /** 额外的信息 */
27
+ public detail: T
28
+
29
+ // Mouse Event botton property, it's used in 3rd lib, like react-router. default 0 in general
30
+ public button = 0
31
+
32
+ // timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
33
+ // here use hi-res timestamp
34
+ public timeStamp = Date.now()
35
+
36
+ public mpEvent: TaroEvent | undefined
37
+
38
+ public constructor (type: string, opts: EventOptions, event?: TaroEvent) {
39
+ this.type = type.toLowerCase()
40
+ this.mpEvent = event
41
+ this.bubbles = Boolean(opts && opts.bubbles)
42
+ this.cancelable = Boolean(opts && opts.cancelable)
43
+ }
44
+
45
+ public stopPropagation () {
46
+ this._stop = true
47
+ }
48
+
49
+ public stopImmediatePropagation () {
50
+ this._end = this._stop = true
51
+ }
52
+
53
+ public preventDefault () {
54
+ this.defaultPrevented = true
55
+ }
56
+ }
57
+
58
+
59
+ export function createEvent (event: TaroEvent | string, type?: string, node?: TaroElement) {
60
+ if (typeof event === 'string') {
61
+ // For Vue3 using document.createEvent
62
+ return new TaroEvent(event, { bubbles: true, cancelable: true })
63
+ }
64
+
65
+ if (!type) return
66
+
67
+ const domEv = new TaroEvent(type, { bubbles: true, cancelable: true }, event)
68
+
69
+ for (const key in event) {
70
+ if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
71
+ continue
72
+ } else {
73
+ domEv[key] = event[key]
74
+ }
75
+ }
76
+
77
+ if (domEv.type === CONFIRM && node?.nodeName === INPUT) {
78
+ // eslint-disable-next-line dot-notation
79
+ domEv[KEY_CODE] = 13
80
+ }
81
+
82
+ return domEv
83
+ }
84
+
85
+ function stopOrTriggerPropagation (event: TaroEvent, node: TaroElement) {
86
+ let target = node
87
+
88
+ // eslint-disable-next-line no-unmodified-loop-condition
89
+ while ((target = target.parentNode as TaroElement)) {
90
+ event.currentTarget = target
91
+ const listeners = target.__listeners[event.type]
92
+
93
+ if (!Array.isArray(listeners) || target._attrs?.disabled) {
94
+ continue
95
+ }
96
+
97
+ const _target = target
98
+ collectBatchFunction(event.type, () => {
99
+ hooks.call('dispatchTaroEvent', event, _target)
100
+ })
101
+ }
102
+ }
103
+
104
+ const eventsBatch = {}
105
+ const BUBBLE_EVENTS = new Set([
106
+ 'touchStart',
107
+ 'touchMove',
108
+ 'touchEnd',
109
+ 'touchCancel',
110
+ 'click',
111
+ 'longTap',
112
+ 'change',
113
+ 'submit',
114
+ 'submit-btn',
115
+ 'reset-btn'
116
+ ])
117
+
118
+ function collectBatchFunction (type: string, dispatch: () => void) {
119
+ if (hooks.isExist('batchedEventUpdates')) {
120
+ (eventsBatch[type] ||= []).push(dispatch)
121
+ } else {
122
+ dispatch()
123
+ }
124
+ }
125
+
126
+ export function eventHandler (event, type: string, node: TaroElement) {
127
+ if (!node) return
128
+
129
+ const isBatchUpdates = hooks.isExist('batchedEventUpdates')
130
+ const e = createEvent(event, type, node)
131
+
132
+ if (!e) return
133
+
134
+ const dispatch = () => {
135
+ e.target = e.currentTarget = node
136
+
137
+ // hooks.call('modifyTaroEvent', e, node)
138
+ hooks.call('dispatchTaroEvent', e, node)
139
+
140
+ // BatchUpdates 时冒泡环节需要提前,因为需要收集父节点事件
141
+ if (!isBatchUpdates) {
142
+ stopOrTriggerPropagation(e, node)
143
+ }
144
+
145
+ // hooks.call('dispatchTaroEventFinish', e, node)
146
+ }
147
+
148
+ dispatch()
149
+ if (isBatchUpdates) {
150
+ // collectBatchFunction(type, dispatch)
151
+
152
+ // 如果需要触发冒泡,则执行 stopOrTriggerPropagation
153
+ if (BUBBLE_EVENTS.has(type)) {
154
+ stopOrTriggerPropagation(e, node)
155
+ }
156
+
157
+ hooks.call('batchedEventUpdates', () => {
158
+ if (eventsBatch[type]) {
159
+ eventsBatch[type].forEach(fn => fn())
160
+ delete eventsBatch[type]
161
+ }
162
+ })
163
+ }
164
+ }