@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.
- package/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- 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
|
+
}
|