@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,73 @@
|
|
|
1
|
+
import { createOption } from '../utils'
|
|
2
|
+
|
|
3
|
+
const NUM_HORIZONTAL = -90
|
|
4
|
+
const NUM_HORIZONTAL_ANTI = 90
|
|
5
|
+
const NUM_VERTICAL = 0
|
|
6
|
+
|
|
7
|
+
export default createOption({
|
|
8
|
+
props: [
|
|
9
|
+
'id',
|
|
10
|
+
'src',
|
|
11
|
+
'controls',
|
|
12
|
+
'autoplay',
|
|
13
|
+
'speed',
|
|
14
|
+
'loop',
|
|
15
|
+
'muted',
|
|
16
|
+
'initialTime',
|
|
17
|
+
'direction',
|
|
18
|
+
'objectFit',
|
|
19
|
+
'poster'
|
|
20
|
+
],
|
|
21
|
+
|
|
22
|
+
data () {
|
|
23
|
+
let videoDirection = 'auto'
|
|
24
|
+
if (this.direction === NUM_VERTICAL) {
|
|
25
|
+
videoDirection = 'vertical'
|
|
26
|
+
} else if (this.direction === NUM_HORIZONTAL || this.direction === NUM_HORIZONTAL_ANTI) {
|
|
27
|
+
videoDirection = 'horizontal'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
duration: 0,
|
|
32
|
+
videoDirection
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
preparedCallback: function (e) {
|
|
37
|
+
this.duration = e.duration
|
|
38
|
+
this.$trigger('loadedmetadata', { duration: this.duration })
|
|
39
|
+
},
|
|
40
|
+
startCallback: function () {
|
|
41
|
+
this.$trigger('play')
|
|
42
|
+
},
|
|
43
|
+
pauseCallback: function () {
|
|
44
|
+
this.$trigger('pause')
|
|
45
|
+
},
|
|
46
|
+
finishCallback: function () {
|
|
47
|
+
this.$trigger('ended')
|
|
48
|
+
},
|
|
49
|
+
stopCallback: function () {
|
|
50
|
+
this.$trigger('stop')
|
|
51
|
+
},
|
|
52
|
+
errorCallback: function () {
|
|
53
|
+
this.$trigger('error')
|
|
54
|
+
},
|
|
55
|
+
seekedCallback: function (e) {
|
|
56
|
+
const buffered = this.duration > 0 ? (e.currenttime / this.duration) * 100 : 0
|
|
57
|
+
this.$trigger('progress', { buffered })
|
|
58
|
+
},
|
|
59
|
+
timeupdateCallback: function (e) {
|
|
60
|
+
this.$trigger('timeupdate', { currentTime: e.currenttime, duration: this.duration })
|
|
61
|
+
},
|
|
62
|
+
clickCallback: function () {
|
|
63
|
+
this.$trigger('tap')
|
|
64
|
+
},
|
|
65
|
+
fullscreenChangeCallback: function (e) {
|
|
66
|
+
const isFullScreen = !!e.fullscreen
|
|
67
|
+
let direction = NUM_VERTICAL
|
|
68
|
+
if (isFullScreen) {
|
|
69
|
+
direction = this.videoDirection === 'horizontal' ? NUM_HORIZONTAL_ANTI : NUM_VERTICAL
|
|
70
|
+
}
|
|
71
|
+
this.$trigger('fullscreenchange', { fullScreen: isFullScreen, direction })
|
|
72
|
+
}
|
|
73
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 鸿蒙SDK API Version 6
|
|
3
|
+
* 需在config.json中配置
|
|
4
|
+
* "reqPermissions": [
|
|
5
|
+
* {
|
|
6
|
+
* "name": "ohos.permission.INTERNET"
|
|
7
|
+
* }
|
|
8
|
+
* ],
|
|
9
|
+
* 文档地址 https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-components-web-0000001135254399
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createOption } from '../utils'
|
|
13
|
+
|
|
14
|
+
export default createOption({
|
|
15
|
+
props: ['id', 'src'],
|
|
16
|
+
onError ({ url: src, errorCode, description }) {
|
|
17
|
+
this.$trigger('error', { src, errorCode, description })
|
|
18
|
+
},
|
|
19
|
+
onLoad ({ url: src }) {
|
|
20
|
+
this.$trigger('load', { src })
|
|
21
|
+
}
|
|
22
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { convertNumber2VP } from '../runtime'
|
|
2
|
+
import { AttributeManager } from './utils/AttributeManager'
|
|
3
|
+
|
|
4
|
+
import type { TaroElement } from './element'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@Component
|
|
8
|
+
export default struct TaroComponentWrapper {
|
|
9
|
+
node?: TaroElement
|
|
10
|
+
|
|
11
|
+
@BuilderParam createElement: () => void
|
|
12
|
+
|
|
13
|
+
top(): Length {
|
|
14
|
+
return this.node?.hmStyle?.top || 0
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
left(): Length {
|
|
18
|
+
return this.node?.hmStyle?.left || 0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Builder createFlexElementWithPosition () {
|
|
22
|
+
if (this.node?.hmStyle?.position === 'absolute') {
|
|
23
|
+
Stack({ alignContent: Alignment.TopStart }) {
|
|
24
|
+
this.createElement()
|
|
25
|
+
}
|
|
26
|
+
.position({
|
|
27
|
+
x: this.left(),
|
|
28
|
+
y: this.top()
|
|
29
|
+
})
|
|
30
|
+
.id(this.node?._attrs?.id || this.node?._nid)
|
|
31
|
+
.key(this.node?._attrs?.id || this.node?._nid)
|
|
32
|
+
.zIndex(Number(this.node?.hmStyle?.zIndex) || null)
|
|
33
|
+
} else if (this.node?.hmStyle?.position === 'fixed') {
|
|
34
|
+
Stack({ alignContent: Alignment.TopStart }) {
|
|
35
|
+
this.createElement()
|
|
36
|
+
}
|
|
37
|
+
.position({
|
|
38
|
+
x: this.left(),
|
|
39
|
+
y: this.top()
|
|
40
|
+
})
|
|
41
|
+
.id(this.node?._attrs?.id || this.node?._nid)
|
|
42
|
+
.key(this.node?._attrs?.id || this.node?._nid)
|
|
43
|
+
.zIndex(Number(this.node?.hmStyle?.zIndex) || null)
|
|
44
|
+
} else if ((this.node?.hmStyle?.position === 'relative')) {
|
|
45
|
+
Stack({ alignContent: Alignment.TopStart }) {
|
|
46
|
+
this.createElement()
|
|
47
|
+
}
|
|
48
|
+
.offset({
|
|
49
|
+
x: this.left(),
|
|
50
|
+
y: this.top()
|
|
51
|
+
})
|
|
52
|
+
.id(this.node?._attrs?.id || this.node?._nid)
|
|
53
|
+
.key(this.node?._attrs?.id || this.node?._nid)
|
|
54
|
+
.zIndex(Number(this.node?.hmStyle?.zIndex) || null)
|
|
55
|
+
} else {
|
|
56
|
+
this.createElement()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
build () {
|
|
61
|
+
this.createFlexElementWithPosition()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo } from '@tarojs/runtime'
|
|
2
|
+
import { createNode } from './render'
|
|
3
|
+
import TaroComponentWrapper from './base'
|
|
4
|
+
import { createTaroEvent } from './utils/events'
|
|
5
|
+
import { BUTTON_THEME_COLOR } from './utils/constant/style'
|
|
6
|
+
import { AttributeManager } from './utils/AttributeManager'
|
|
7
|
+
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
8
|
+
import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
|
|
9
|
+
|
|
10
|
+
import type { TaroAny, TaroEvent } from '@tarojs/runtime'
|
|
11
|
+
import type { TaroButtonElement, TaroElement } from './element'
|
|
12
|
+
import type { TaroStyleType } from '@tarojs/runtime'
|
|
13
|
+
|
|
14
|
+
@Extend(Button)
|
|
15
|
+
function attrs (style: TaroStyleType) {
|
|
16
|
+
.id(style.id)
|
|
17
|
+
.key(style.id)
|
|
18
|
+
.padding(style.padding)
|
|
19
|
+
.margin(style.margin)
|
|
20
|
+
.width(style.width)
|
|
21
|
+
.height(style.height)
|
|
22
|
+
.constraintSize(style.constraintSize)
|
|
23
|
+
.flexGrow(style.flexGrow)
|
|
24
|
+
.flexShrink(style.flexShrink)
|
|
25
|
+
.flexBasis(style.flexBasis)
|
|
26
|
+
.alignSelf(style.alignSelf)
|
|
27
|
+
.backgroundColor(style.backgroundColor)
|
|
28
|
+
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
29
|
+
.backgroundImageSize(style.backgroundImageSize)
|
|
30
|
+
.rotate(style.rotate)
|
|
31
|
+
.scale(style.scale)
|
|
32
|
+
.translate(style.translate)
|
|
33
|
+
.transform(style.transform)
|
|
34
|
+
.borderStyle(style.borderStyle)
|
|
35
|
+
.borderWidth(style.borderWidth)
|
|
36
|
+
.borderColor(style.borderColor)
|
|
37
|
+
.borderRadius(style.borderRadius)
|
|
38
|
+
.linearGradient(style.linearGradient)
|
|
39
|
+
.zIndex(style.zIndex)
|
|
40
|
+
.opacity(style.opacity)
|
|
41
|
+
.clip(style.clip)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@Extend(Button)
|
|
46
|
+
function themeStyles(style: TaroStyleType) {
|
|
47
|
+
.border({
|
|
48
|
+
width: 1,
|
|
49
|
+
color: style.backgroundColor
|
|
50
|
+
})
|
|
51
|
+
.fontColor(style.color)
|
|
52
|
+
.opacity(style.opacity)
|
|
53
|
+
.backgroundColor(style.backgroundColor)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
|
|
57
|
+
const hmStyle = node.hmStyle
|
|
58
|
+
const _attrs = node._attrs
|
|
59
|
+
const isPlain: boolean = _attrs.plain || false
|
|
60
|
+
const isDisabled: boolean = _attrs.disabled || false
|
|
61
|
+
const type: string = _attrs.type || 'default'
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
opacity: isDisabled ? 0.4 : 1,
|
|
65
|
+
backgroundColor: isPlain ? Color.Transparent : (hmStyle.backgroundColor || BUTTON_THEME_COLOR.get(type).background),
|
|
66
|
+
color: hmStyle.color || BUTTON_THEME_COLOR.get(type).text,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Component
|
|
71
|
+
export default struct TaroButton {
|
|
72
|
+
nodeInfoMap: TaroAny = {}
|
|
73
|
+
|
|
74
|
+
@ObjectLink node: TaroButtonElement
|
|
75
|
+
|
|
76
|
+
@Styles visibleChangeEvent () {
|
|
77
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
aboutToAppear () {
|
|
81
|
+
initComponentNodeInfo(this, this.node)
|
|
82
|
+
bindInstanceToNode(this.node, this)
|
|
83
|
+
// 绑定动画
|
|
84
|
+
bindAnimation(this.node)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
build() {
|
|
88
|
+
TaroComponentWrapper({ node: this.node }) {
|
|
89
|
+
Button({ stateEffect: !this.node._attrs.disabled }) {
|
|
90
|
+
Row() {
|
|
91
|
+
if (this.node._attrs.loading) {
|
|
92
|
+
LoadingProgress()
|
|
93
|
+
.width(20).height(20)
|
|
94
|
+
.color(getThemeAttributes(this.node).color)
|
|
95
|
+
}
|
|
96
|
+
ForEach(this.node.childNodes, (item: TaroElement) => {
|
|
97
|
+
createNode(item)
|
|
98
|
+
}, (item: TaroElement) => item._nid)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
.attrs(getNormalAttributes(this.node))
|
|
102
|
+
.themeStyles(getThemeAttributes(this.node))
|
|
103
|
+
.onClick((e: ClickEvent) => {
|
|
104
|
+
if (['submit', 'reset'].includes(this.node._attrs.formType)) {
|
|
105
|
+
const eventName = this.node._attrs.formType + '-btn'
|
|
106
|
+
const event: TaroEvent = createTaroEvent(eventName, {}, this.node)
|
|
107
|
+
eventHandler(event, eventName, this.node)
|
|
108
|
+
}
|
|
109
|
+
eventHandler(e, 'click', this.node)
|
|
110
|
+
})
|
|
111
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
112
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
|
|
113
|
+
const eventResult: TaroAny = res.eventResult
|
|
114
|
+
this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
|
|
115
|
+
}))
|
|
116
|
+
.visibleChangeEvent()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny, TaroEvent } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import TaroComponentWrapper from './base'
|
|
4
|
+
import { createNode } from './render'
|
|
5
|
+
import { createTaroEvent } from './utils/events'
|
|
6
|
+
import { FlexManager } from './utils/FlexManager'
|
|
7
|
+
import { shouldBindEvent, getNormalAttributes, getNodeThresholds } from './utils/helper'
|
|
8
|
+
|
|
9
|
+
import type { TaroCheckboxElement, TaroCheckboxGroupElement, TaroElement } from './element'
|
|
10
|
+
import type { TaroStyleType } from '@tarojs/runtime'
|
|
11
|
+
|
|
12
|
+
interface CheckboxOptions {
|
|
13
|
+
name?: string
|
|
14
|
+
group?: string
|
|
15
|
+
}
|
|
16
|
+
interface CheckboxAttrs {
|
|
17
|
+
selectedColor?: ResourceColor
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Extend(Checkbox)
|
|
21
|
+
function checkboxStyle (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
|
+
}
|
|
49
|
+
|
|
50
|
+
@Extend(Checkbox)
|
|
51
|
+
function checkboxAttr(attr: CheckboxAttrs) {
|
|
52
|
+
.selectedColor(attr.selectedColor)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getAttributes (node: TaroCheckboxElement): CheckboxAttrs {
|
|
56
|
+
const _attrs = node._attrs
|
|
57
|
+
const checkboxAttrs: CheckboxAttrs = {}
|
|
58
|
+
checkboxAttrs.selectedColor = _attrs.color || '#1aad19'
|
|
59
|
+
return checkboxAttrs
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getOptions (node: TaroCheckboxElement): CheckboxOptions {
|
|
63
|
+
const value: string = node._attrs.value
|
|
64
|
+
return {
|
|
65
|
+
name: value || node.textContent
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@Component
|
|
71
|
+
export struct TaroCheckbox {
|
|
72
|
+
nodeInfoMap: TaroAny = {}
|
|
73
|
+
|
|
74
|
+
@ObjectLink node: TaroCheckboxElement
|
|
75
|
+
|
|
76
|
+
@State checked: boolean = false
|
|
77
|
+
|
|
78
|
+
@Styles visibleChangeEvent () {
|
|
79
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
aboutToAppear () {
|
|
83
|
+
initComponentNodeInfo(this, this.node)
|
|
84
|
+
bindInstanceToNode(this.node, this)
|
|
85
|
+
|
|
86
|
+
this.checked = !!this.node._attrs.checked
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Styles defaultEvent () {
|
|
90
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
91
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
|
|
92
|
+
const eventResult: TaroAny = res.eventResult
|
|
93
|
+
this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
|
|
94
|
+
}))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
build() {
|
|
98
|
+
TaroComponentWrapper({ node: this.node }) {
|
|
99
|
+
Stack() {
|
|
100
|
+
Row() {
|
|
101
|
+
Checkbox(getOptions(this.node))
|
|
102
|
+
.defaultEvent()
|
|
103
|
+
.checkboxStyle(getNormalAttributes(this.node))
|
|
104
|
+
.checkboxAttr(getAttributes(this.node))
|
|
105
|
+
.opacity(!!this.node._attrs.disabled ? 0.4 : 1)
|
|
106
|
+
.select(this.checked)
|
|
107
|
+
.onChange((value: boolean) => {
|
|
108
|
+
if (!!this.node._attrs.disabled) {
|
|
109
|
+
// FIXME 找下文档是否有强制刷新方法
|
|
110
|
+
this.checked = !this.checked
|
|
111
|
+
this.checked = !this.checked
|
|
112
|
+
} else {
|
|
113
|
+
this.checked = value
|
|
114
|
+
if (this.checked) {
|
|
115
|
+
const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node._attrs.value } }, this.node)
|
|
116
|
+
eventHandler(event, 'change', this.node)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
.visibleChangeEvent()
|
|
121
|
+
Text(this.node.textContent)
|
|
122
|
+
.textAlign(TextAlign.Center)
|
|
123
|
+
.opacity(!!this.node._attrs.disabled ? 0.4 : 1)
|
|
124
|
+
}
|
|
125
|
+
.onClick(() => {
|
|
126
|
+
this.checked = !this.checked
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@Extend(Flex)
|
|
135
|
+
function checkboxGroupAttrs (style: TaroStyleType) {
|
|
136
|
+
.id(style.id)
|
|
137
|
+
.key(style.id)
|
|
138
|
+
.padding(style.padding)
|
|
139
|
+
.margin(style.margin)
|
|
140
|
+
.width(style.width)
|
|
141
|
+
.height(style.height)
|
|
142
|
+
.constraintSize(style.constraintSize)
|
|
143
|
+
.flexGrow(style.flexGrow)
|
|
144
|
+
.flexShrink(style.flexShrink)
|
|
145
|
+
.flexBasis(style.flexBasis)
|
|
146
|
+
.alignSelf(style.alignSelf)
|
|
147
|
+
.backgroundColor(style.backgroundColor)
|
|
148
|
+
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
149
|
+
.backgroundImageSize(style.backgroundImageSize)
|
|
150
|
+
.rotate(style.rotate)
|
|
151
|
+
.scale(style.scale)
|
|
152
|
+
.translate(style.translate)
|
|
153
|
+
.transform(style.transform)
|
|
154
|
+
.borderStyle(style.borderStyle)
|
|
155
|
+
.borderWidth(style.borderWidth)
|
|
156
|
+
.borderColor(style.borderColor)
|
|
157
|
+
.borderRadius(style.borderRadius)
|
|
158
|
+
.linearGradient(style.linearGradient)
|
|
159
|
+
.zIndex(style.zIndex)
|
|
160
|
+
.opacity(style.opacity)
|
|
161
|
+
.clip(style.clip)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface ChangeEventDetail { value: string[] }
|
|
165
|
+
|
|
166
|
+
@Component
|
|
167
|
+
export struct TaroCheckboxGroup {
|
|
168
|
+
nodeInfoMap: TaroAny = {}
|
|
169
|
+
|
|
170
|
+
@ObjectLink node: TaroCheckboxGroupElement
|
|
171
|
+
|
|
172
|
+
@Styles visibleChangeEvent () {
|
|
173
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
aboutToAppear () {
|
|
177
|
+
initComponentNodeInfo(this, this.node)
|
|
178
|
+
bindInstanceToNode(this.node, this)
|
|
179
|
+
|
|
180
|
+
// 阻止事件冒泡传递上去
|
|
181
|
+
this.node.addEventListener('change', (e: TaroEvent<ChangeEventDetail>) => {
|
|
182
|
+
e.stopPropagation()
|
|
183
|
+
e.detail.value = this.getValues()
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Element使用的获取值方法
|
|
188
|
+
getValues () {
|
|
189
|
+
const childList = this.node.getElementsByTagName<TaroCheckboxElement>('CHECKBOX')
|
|
190
|
+
const result: string[] = []
|
|
191
|
+
childList.forEach(element => {
|
|
192
|
+
if (element._instance.checked) {
|
|
193
|
+
result.push(element._attrs.value)
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
return result
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@Styles defaultEvent () {
|
|
200
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
201
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
|
|
202
|
+
const eventResult: TaroAny = res.eventResult
|
|
203
|
+
this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
|
|
204
|
+
}))
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
build() {
|
|
208
|
+
TaroComponentWrapper({ node: this.node }) {
|
|
209
|
+
Flex(FlexManager.flexOptions(this.node)) {
|
|
210
|
+
ForEach(this.node.childNodes, (item: TaroElement) => {
|
|
211
|
+
createNode(item)
|
|
212
|
+
}, (item: TaroElement) => item._nid)
|
|
213
|
+
}
|
|
214
|
+
.checkboxGroupAttrs(getNormalAttributes(this.node))
|
|
215
|
+
.defaultEvent()
|
|
216
|
+
.visibleChangeEvent()
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|