@tarojs/plugin-platform-harmony-ets 4.0.0-beta.11 → 4.0.0-beta.111
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/dist/apis/base/system.ts +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +16 -8
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +25 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/storage/index.ts +135 -131
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +42 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +5 -5
- package/dist/apis/ui/tab-bar.ts +3 -3
- package/dist/apis/utils/index.ts +2 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +35 -8
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +70 -60
- package/dist/components-harmony-ets/form.ets +35 -16
- package/dist/components-harmony-ets/icon.ets +16 -8
- package/dist/components-harmony-ets/image.ets +22 -6
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +6 -5
- package/dist/components-harmony-ets/input.ets +62 -40
- package/dist/components-harmony-ets/label.ets +44 -21
- package/dist/components-harmony-ets/listView.ets +31 -0
- package/dist/components-harmony-ets/movableArea.ets +112 -53
- package/dist/components-harmony-ets/movableView.ets +75 -48
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +41 -38
- package/dist/components-harmony-ets/progress.ets +31 -24
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +76 -66
- package/dist/components-harmony-ets/richText.ets +4 -25
- package/dist/components-harmony-ets/scrollList.ets +103 -0
- package/dist/components-harmony-ets/scrollView.ets +47 -47
- package/dist/components-harmony-ets/slider.ets +18 -14
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +386 -130
- package/dist/components-harmony-ets/swiper.ets +41 -4
- package/dist/components-harmony-ets/switch.ets +35 -31
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +102 -46
- package/dist/components-harmony-ets/textArea.ets +49 -34
- package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
- package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
- package/dist/components-harmony-ets/utils/helper.ets +20 -8
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +170 -93
- package/dist/components-harmony-ets/video.ets +27 -19
- package/dist/components-harmony-ets/view.ets +47 -40
- package/dist/components-harmony-ets/webView.ets +6 -5
- package/dist/index.d.ts +152 -0
- package/dist/index.js +69 -43
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +7 -0
- package/dist/runtime-ets/current.ts +5 -1
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +419 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
- package/dist/runtime-ets/dom/document.ts +8 -11
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +376 -56
- package/dist/runtime-ets/dom/element/form.ts +20 -22
- package/dist/runtime-ets/dom/element/index.ts +22 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
- package/dist/runtime-ets/dom/element/movableView.ts +234 -2
- package/dist/runtime-ets/dom/element/normal.ts +27 -6
- package/dist/runtime-ets/dom/element/progress.ts +0 -2
- package/dist/runtime-ets/dom/element/text.ts +0 -8
- package/dist/runtime-ets/dom/element/video.ts +4 -4
- package/dist/runtime-ets/dom/element/webView.ts +4 -5
- package/dist/runtime-ets/dom/event.ts +3 -5
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +51 -19
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
- package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
- package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/index.ts +2 -1
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/utils/index.ts +74 -13
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-framework/react/app.ts +15 -10
- package/dist/runtime-framework/react/hooks.ts +0 -1
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +185 -78
- package/dist/runtime-framework/react/page.ts +4 -9
- package/dist/runtime-framework/react/utils/index.ts +3 -3
- package/dist/runtime-framework/solid/app.ts +30 -46
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +85 -31
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +3 -5
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +425 -253
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +425 -253
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -1
- package/static/media/circle.svg +1 -1
- package/static/media/clear.svg +1 -1
- package/static/media/download.svg +1 -1
- package/static/media/info.svg +1 -1
- package/static/media/info_circle.svg +1 -1
- package/static/media/search.svg +1 -1
- package/static/media/success.svg +1 -1
- package/static/media/success_no_circle.svg +1 -1
- package/static/media/warn.svg +1 -1
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +1 -1
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
|
-
import commonStyleModify from './style'
|
|
4
|
-
import { createLazyChildren } from './render'
|
|
3
|
+
import commonStyleModify, { rowModify, columnModify } from './style'
|
|
5
4
|
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
6
|
-
import { FlexManager } from './utils/
|
|
5
|
+
import { FlexManager } from './utils/flexManager'
|
|
7
6
|
import { shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
8
7
|
|
|
9
8
|
import { TaroEvent, TaroAny, HarmonyType, TaroRadioGroupElement, TaroRadioElement } from '@tarojs/runtime'
|
|
9
|
+
import { isUndefined } from '@tarojs/shared'
|
|
10
10
|
|
|
11
11
|
interface RadioAttrs {
|
|
12
12
|
radioStyle?: HarmonyType.RadioStyle
|
|
13
13
|
themeStyles?: boolean
|
|
14
|
+
disabled?: boolean
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
@Extend(Radio)
|
|
17
18
|
function radioAttr (attr: RadioAttrs) {
|
|
18
19
|
.radioStyle(attr.radioStyle)
|
|
19
|
-
.themeStyles(attr.themeStyles)
|
|
20
|
+
.themeStyles(attr.themeStyles || false)
|
|
21
|
+
.enabled(!attr.disabled)
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
function getAttributes (node: TaroRadioElement): RadioAttrs {
|
|
@@ -25,6 +27,7 @@ function getAttributes (node: TaroRadioElement): RadioAttrs {
|
|
|
25
27
|
checkedBackgroundColor: node._attrs.color || '#1aad19'
|
|
26
28
|
}
|
|
27
29
|
radioAttrs.themeStyles = !!node._attrs.disabled
|
|
30
|
+
radioAttrs.disabled = !!node._attrs.disabled
|
|
28
31
|
return radioAttrs
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -35,59 +38,61 @@ function themeStyles(isDisabled: boolean) {
|
|
|
35
38
|
|
|
36
39
|
@Component
|
|
37
40
|
export struct TaroRadio {
|
|
41
|
+
@Builder customBuilder() {}
|
|
42
|
+
@BuilderParam createLazyChildren: (node: TaroRadioElement, layer?: number) => void = this.customBuilder
|
|
38
43
|
@ObjectLink node: TaroRadioElement
|
|
39
|
-
|
|
44
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
45
|
+
|
|
40
46
|
aboutToAppear () {
|
|
41
47
|
if (this.node && !this.node._isInit) {
|
|
42
48
|
this.node._isInit = true
|
|
49
|
+
this.node._instance = this
|
|
43
50
|
this.node._reset = this.node.checked || false
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
build () {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
if (this.node) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
eventHandler(event, 'change', this.node)
|
|
68
|
-
}
|
|
55
|
+
Stack() {
|
|
56
|
+
Row() {
|
|
57
|
+
Radio({
|
|
58
|
+
group: this.node.group || this.node.parentNode?._nid.toString() || '',
|
|
59
|
+
value: this.node.value || '',
|
|
60
|
+
})
|
|
61
|
+
.checked(this.node.checked)
|
|
62
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
63
|
+
.radioAttr(getAttributes(this.node))
|
|
64
|
+
.onChange((value: boolean) => {
|
|
65
|
+
if (this.node) {
|
|
66
|
+
if (!!this.node?._attrs.disabled) {
|
|
67
|
+
this.node.updateComponent()
|
|
68
|
+
} else {
|
|
69
|
+
this.node.updateCheckedValue(value)
|
|
70
|
+
|
|
71
|
+
if (value) {
|
|
72
|
+
const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
|
|
73
|
+
eventHandler(event, 'change', this.node)
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
|
-
})
|
|
72
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
73
|
-
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
74
|
-
if (this.node) {
|
|
75
|
-
this.node._nodeInfo.areaInfo = res[1]
|
|
76
|
-
}
|
|
77
|
-
}))
|
|
78
|
-
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
79
|
-
Text(this.node.textContent)
|
|
80
|
-
.textAlign(TextAlign.Center)
|
|
81
|
-
.opacity(!!this.node?._attrs.disabled ? 0.4 : 1)
|
|
82
|
-
}
|
|
83
|
-
.onClick(() => {
|
|
84
|
-
if (this.node) {
|
|
85
|
-
if (!this.node._checked && !this.node?._attrs.disabled) {
|
|
86
|
-
this.node.checked = !this.node.checked
|
|
87
76
|
}
|
|
88
|
-
}
|
|
89
|
-
|
|
77
|
+
})
|
|
78
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
79
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
80
|
+
if (this.node) {
|
|
81
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
82
|
+
}
|
|
83
|
+
}))
|
|
84
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
85
|
+
Text(this.node.textContent)
|
|
86
|
+
.textAlign(TextAlign.Center)
|
|
87
|
+
.opacity(!!this.node?._attrs.disabled ? 0.4 : 1)
|
|
90
88
|
}
|
|
89
|
+
.onClick(() => {
|
|
90
|
+
if (this.node) {
|
|
91
|
+
if (!this.node._checked && !this.node?._attrs.disabled) {
|
|
92
|
+
this.node.checked = !this.node.checked
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
})
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
}
|
|
@@ -95,7 +100,10 @@ export struct TaroRadio {
|
|
|
95
100
|
|
|
96
101
|
@Component
|
|
97
102
|
export struct TaroRadioGroup {
|
|
103
|
+
@Builder customBuilder() {}
|
|
104
|
+
@BuilderParam createLazyChildren: (node: TaroRadioGroupElement, layer?: number) => void = this.customBuilder
|
|
98
105
|
@ObjectLink node: TaroRadioGroupElement
|
|
106
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
99
107
|
|
|
100
108
|
@Styles visibleChangeEvent () {
|
|
101
109
|
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
@@ -103,9 +111,10 @@ export struct TaroRadioGroup {
|
|
|
103
111
|
|
|
104
112
|
aboutToAppear () {
|
|
105
113
|
if (this.node) {
|
|
114
|
+
this.node._instance = this
|
|
106
115
|
const childList = this.node.getElementsByTagName<TaroRadioElement>('RADIO')
|
|
107
116
|
childList.forEach(element => {
|
|
108
|
-
element.group = this.node?._attrs.name || this.node?._nid
|
|
117
|
+
element.group = this.node?._attrs.name || this.node?._nid.toString()
|
|
109
118
|
})
|
|
110
119
|
// 阻止事件冒泡传递上去
|
|
111
120
|
this.node.addEventListener('change', (e: TaroEvent) => e.stopPropagation())
|
|
@@ -113,8 +122,8 @@ export struct TaroRadioGroup {
|
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
@Styles defaultEvent () {
|
|
116
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
117
|
-
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
125
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
126
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
|
|
118
127
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
119
128
|
if (this.node) {
|
|
120
129
|
this.node._nodeInfo.areaInfo = res[1]
|
|
@@ -123,26 +132,27 @@ export struct TaroRadioGroup {
|
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
build() {
|
|
126
|
-
if (this.node) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
.
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
.alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
|
|
144
|
-
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
135
|
+
if (FlexManager.useFlexLayout(this.node)) {
|
|
136
|
+
Flex(FlexManager.flexOptions(this.node)) {
|
|
137
|
+
this.createLazyChildren(this.node, 0)
|
|
138
|
+
}
|
|
139
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
140
|
+
.defaultEvent()
|
|
141
|
+
.visibleChangeEvent()
|
|
142
|
+
} else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
|
|
143
|
+
Row() {
|
|
144
|
+
this.createLazyChildren(this.node, 0)
|
|
145
|
+
}
|
|
146
|
+
.attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
147
|
+
.defaultEvent()
|
|
148
|
+
.visibleChangeEvent()
|
|
149
|
+
} else {
|
|
150
|
+
Column() {
|
|
151
|
+
this.createLazyChildren(this.node, 0)
|
|
145
152
|
}
|
|
153
|
+
.attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
154
|
+
.defaultEvent()
|
|
155
|
+
.visibleChangeEvent()
|
|
146
156
|
}
|
|
147
157
|
}
|
|
148
158
|
}
|
|
@@ -1,46 +1,25 @@
|
|
|
1
1
|
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
3
|
import commonStyleModify from './style'
|
|
4
|
+
import { generateText } from './utils'
|
|
4
5
|
import { getNodeThresholds, shouldBindEvent } from './utils/helper'
|
|
5
6
|
|
|
6
|
-
import type { RichTextProps } from '@tarojs/components/types/RichText'
|
|
7
7
|
import type { TaroAny, TaroRichTextElement } from '@tarojs/runtime'
|
|
8
8
|
|
|
9
|
-
function generateText (node: TaroRichTextElement): string {
|
|
10
|
-
return parseHtmlNode(node._attrs.nodes || '')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
9
|
@Component
|
|
14
10
|
export default struct TaroRichText {
|
|
11
|
+
@Builder customBuilder() {}
|
|
12
|
+
@BuilderParam createLazyChildren: (node: TaroRichTextElement, layer?: number) => void = this.customBuilder
|
|
15
13
|
@ObjectLink node: TaroRichTextElement
|
|
16
14
|
|
|
17
15
|
build () {
|
|
18
16
|
RichText(generateText(this.node))
|
|
19
17
|
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
20
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
18
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
21
19
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
22
20
|
this.node._nodeInfo.areaInfo = res[1]
|
|
23
21
|
}))
|
|
24
22
|
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
25
|
-
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
// 将nodeTree转换成harmony需要的string结构
|
|
30
|
-
function nodeToHtml(node: RichTextProps.Text | RichTextProps.HTMLElement): string {
|
|
31
|
-
if (node.type === 'text') {
|
|
32
|
-
return node.text;
|
|
33
|
-
}
|
|
34
|
-
if (node.attrs) {
|
|
35
|
-
const attributes = Object.entries(node.attrs)
|
|
36
|
-
.map((item: [string, string]) => `${item[0]}="${item[1]}"`)
|
|
37
|
-
.join(' ');
|
|
38
|
-
const childrenHtml: string = typeof node.children === 'string' ? node.children : (node.children || []).map((child: RichTextProps.Text | RichTextProps.HTMLElement) => nodeToHtml(child)).join('');
|
|
39
|
-
return `<${node.name}${attributes ? ' ' + attributes : ''}>${childrenHtml}</${node.name}>`;
|
|
40
|
-
}
|
|
41
|
-
return ''
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElement> | string) {
|
|
45
|
-
return typeof nodes === 'string' ? nodes: `<div>${nodes.map(node => nodeToHtml(node)).join('')}</div>`
|
|
46
|
-
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import commonStyleModify from './style'
|
|
4
|
+
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
5
|
+
import { getNodeThresholds, shouldBindEvent } from './utils/helper'
|
|
6
|
+
|
|
7
|
+
import type { TaroScrollViewElement, TaroAny, TaroEvent } from '@tarojs/runtime'
|
|
8
|
+
|
|
9
|
+
interface ScrollViewAttrs {
|
|
10
|
+
scrollBar: BarState
|
|
11
|
+
}
|
|
12
|
+
interface ScrollViewCurrentOffset {
|
|
13
|
+
xOffset: number
|
|
14
|
+
yOffset: number
|
|
15
|
+
}
|
|
16
|
+
interface ScrollViewEvent {
|
|
17
|
+
deltaX: number
|
|
18
|
+
deltaY: number
|
|
19
|
+
scrollLeft: number
|
|
20
|
+
scrollTop: number
|
|
21
|
+
scrollWidth: number
|
|
22
|
+
scrollHeight: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getAttributes (node: TaroScrollViewElement): ScrollViewAttrs {
|
|
26
|
+
const _attrs = node._attrs
|
|
27
|
+
const scrollAttrs: ScrollViewAttrs = {
|
|
28
|
+
scrollBar: typeof _attrs.showScrollbar === 'boolean'
|
|
29
|
+
? _attrs.showScrollbar ? BarState.On : BarState.Off
|
|
30
|
+
: BarState.Auto
|
|
31
|
+
}
|
|
32
|
+
return scrollAttrs
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', scrollOffset?: number) {
|
|
36
|
+
const currentOffset = node.scroller.currentOffset() as ScrollViewCurrentOffset
|
|
37
|
+
const currentXOffset = currentOffset?.xOffset || 0
|
|
38
|
+
const currentYOffset = currentOffset?.yOffset || 0
|
|
39
|
+
const value: ScrollViewEvent = {
|
|
40
|
+
deltaX: vp2px(node._attrs.scrollX ? scrollOffset : 0),
|
|
41
|
+
deltaY: vp2px(node._attrs.scrollX ? 0 : scrollOffset),
|
|
42
|
+
scrollLeft: vp2px(currentXOffset),
|
|
43
|
+
scrollTop: vp2px(currentYOffset),
|
|
44
|
+
scrollWidth: vp2px(Number(node._nodeInfo?._scroll?.width)),
|
|
45
|
+
scrollHeight: vp2px(Number(node._nodeInfo?._scroll?.height)),
|
|
46
|
+
}
|
|
47
|
+
const event: TaroEvent = createTaroEvent(eventName, { detail: value }, node)
|
|
48
|
+
|
|
49
|
+
eventHandler(event, eventName, node)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Component
|
|
53
|
+
export default struct TaroScrollList {
|
|
54
|
+
@Builder customBuilder() {}
|
|
55
|
+
@BuilderParam createLazyChildren: (node: TaroScrollViewElement, layer?: number) => void = this.customBuilder
|
|
56
|
+
@ObjectLink node: TaroScrollViewElement
|
|
57
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
58
|
+
|
|
59
|
+
aboutToAppear(): void {
|
|
60
|
+
if (this.node) {
|
|
61
|
+
this.node._instance = this
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
handleScroll = (scrollOffset: number) => {
|
|
66
|
+
handleScrollEvent(this.node, 'scroll', scrollOffset)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
build() {
|
|
70
|
+
List({
|
|
71
|
+
scroller: this.node.scroller
|
|
72
|
+
}) {
|
|
73
|
+
this.createLazyChildren(this.node, 0)
|
|
74
|
+
}
|
|
75
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
76
|
+
.sticky(StickyStyle.Header)
|
|
77
|
+
.listDirection(this.node.getAttribute('scrollX') ? Axis.Horizontal: Axis.Vertical)
|
|
78
|
+
.align(Alignment.TopStart)
|
|
79
|
+
.clip(true)
|
|
80
|
+
.scrollBar(getAttributes(this.node).scrollBar)
|
|
81
|
+
.onScrollIndex((first: number, last: number) => {
|
|
82
|
+
const scrollindexfns = (this.node?.__listeners?.['scrollindex'] || []) as Function[]
|
|
83
|
+
scrollindexfns.forEach(fn => {
|
|
84
|
+
fn({
|
|
85
|
+
first,
|
|
86
|
+
last
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
91
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
|
|
92
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
93
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
94
|
+
}))
|
|
95
|
+
.onDidScroll(shouldBindEvent((scrollOffset: number) => { handleScrollEvent(this.node, 'scroll', scrollOffset) }, this.node, ['scroll']))
|
|
96
|
+
.onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
|
|
97
|
+
.onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
|
|
98
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
99
|
+
.onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
3
|
import commonStyleModify from './style'
|
|
4
|
-
import
|
|
5
|
-
import { FlexManager } from './utils/
|
|
4
|
+
import PseduoChildren from './pseudo'
|
|
5
|
+
import { FlexManager } from './utils/flexManager'
|
|
6
6
|
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
7
|
-
import { getNodeThresholds,
|
|
7
|
+
import { getNodeThresholds, getStyleAttr, shouldBindEvent } from './utils/helper'
|
|
8
8
|
|
|
9
|
-
import type { TaroAny,
|
|
9
|
+
import type { TaroAny, TaroScrollViewElement, TaroEvent } from '@tarojs/runtime'
|
|
10
10
|
|
|
11
11
|
interface ScrollViewAttrs {
|
|
12
12
|
scrollBar: BarState
|
|
@@ -49,83 +49,83 @@ function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', x
|
|
|
49
49
|
deltaY: vp2px(yOffset),
|
|
50
50
|
scrollLeft: vp2px(currentXOffset),
|
|
51
51
|
scrollTop: vp2px(currentYOffset),
|
|
52
|
-
scrollWidth: vp2px(Number(node._scroll?.width)),
|
|
53
|
-
scrollHeight: vp2px(Number(node._scroll?.height)),
|
|
52
|
+
scrollWidth: vp2px(Number(node._nodeInfo?._scroll?.width)),
|
|
53
|
+
scrollHeight: vp2px(Number(node._nodeInfo?._scroll?.height)),
|
|
54
54
|
}
|
|
55
55
|
const event: TaroEvent = createTaroEvent(eventName, { detail: value }, node)
|
|
56
56
|
|
|
57
57
|
eventHandler(event, eventName, node)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
@Extend(Row)
|
|
61
|
-
function rowAttrs (style: TaroStyleType) {
|
|
62
|
-
.constraintSize({
|
|
63
|
-
minWidth: style.minWidth || style.width,
|
|
64
|
-
maxWidth: style.maxWidth,
|
|
65
|
-
minHeight: style.minHeight,
|
|
66
|
-
maxHeight: style.maxHeight
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@Extend(Column)
|
|
71
|
-
function columnAttrs (style: TaroStyleType) {
|
|
72
|
-
.constraintSize({
|
|
73
|
-
minWidth: style.minWidth,
|
|
74
|
-
maxWidth: style.maxWidth,
|
|
75
|
-
minHeight: style.minHeight || style.height,
|
|
76
|
-
maxHeight: style.maxHeight
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
60
|
@Component
|
|
81
61
|
export default struct TaroScrollView {
|
|
62
|
+
@Builder customBuilder() {}
|
|
63
|
+
@BuilderParam createLazyChildren: (node: TaroScrollViewElement, layer?: number) => void = this.customBuilder
|
|
82
64
|
@ObjectLink node: TaroScrollViewElement
|
|
65
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
66
|
+
|
|
67
|
+
aboutToAppear(): void {
|
|
68
|
+
if (this.node) {
|
|
69
|
+
this.node._instance = this
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
isScrollX() {
|
|
74
|
+
return this.node._attrs.scrollX || getStyleAttr(this.node, 'overflow') === 'scroll' && getStyleAttr(this.node, 'flexDirection') === FlexDirection.Row
|
|
75
|
+
}
|
|
83
76
|
|
|
84
77
|
build () {
|
|
85
78
|
Scroll(this.node.scroller) {
|
|
86
|
-
if (this.
|
|
79
|
+
if (this.isScrollX()) {
|
|
87
80
|
Row() {
|
|
88
|
-
|
|
81
|
+
if (this.node._pseudo_before || this.node._pseudo_after) {
|
|
82
|
+
PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
|
|
83
|
+
} else {
|
|
84
|
+
this.createLazyChildren(this.node, 0)
|
|
85
|
+
}
|
|
89
86
|
}
|
|
90
|
-
.
|
|
91
|
-
.
|
|
87
|
+
.alignItems(FlexManager.alignItems<VerticalAlign>(this.node))
|
|
88
|
+
.justifyContent(FlexManager.justifyContent(this.node))
|
|
89
|
+
.height(getStyleAttr(this.node, 'height'))
|
|
92
90
|
.width(null)
|
|
93
91
|
.onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
|
|
94
|
-
this.node._scroll = areaResult
|
|
92
|
+
this.node._nodeInfo._scroll = areaResult
|
|
95
93
|
}, this.node, ['scroll', 'scrollstart', 'scrollend']))
|
|
96
|
-
.alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
|
|
97
|
-
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
98
94
|
.flexGrow(0).flexShrink(0)
|
|
99
95
|
} else {
|
|
100
96
|
Column() {
|
|
101
|
-
|
|
97
|
+
if (this.node._pseudo_before || this.node._pseudo_after) {
|
|
98
|
+
PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
|
|
99
|
+
} else {
|
|
100
|
+
this.createLazyChildren(this.node, 0)
|
|
101
|
+
}
|
|
102
102
|
}
|
|
103
|
-
.
|
|
104
|
-
.
|
|
103
|
+
.alignItems(FlexManager.alignItems<HorizontalAlign>(this.node))
|
|
104
|
+
.justifyContent(FlexManager.justifyContent(this.node))
|
|
105
|
+
.width(getStyleAttr(this.node, 'width'))
|
|
105
106
|
.height(null)
|
|
106
|
-
.alignItems(HorizontalAlign.Start)
|
|
107
107
|
.onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
|
|
108
|
-
this.node._scroll = areaResult
|
|
108
|
+
this.node._nodeInfo._scroll = areaResult
|
|
109
109
|
}, this.node, ['scroll', 'scrollstart', 'scrollend']))
|
|
110
|
-
.alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
|
|
111
|
-
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
112
110
|
.flexGrow(0).flexShrink(0)
|
|
113
111
|
}
|
|
114
112
|
}
|
|
115
|
-
.
|
|
116
|
-
.
|
|
117
|
-
.
|
|
118
|
-
.
|
|
113
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
114
|
+
.width(this.isScrollX() ? getStyleAttr(this.node, 'width') : undefined)
|
|
115
|
+
.height(!this.isScrollX() ? getStyleAttr(this.node, 'height') : undefined)
|
|
116
|
+
.align(Alignment.TopStart)
|
|
117
|
+
.clip(true)
|
|
119
118
|
.scrollable(getScrollable(this.node))
|
|
120
119
|
.scrollBar(getAttributes(this.node).scrollBar)
|
|
121
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
122
|
-
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
120
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
121
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
|
|
123
122
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
124
123
|
this.node._nodeInfo.areaInfo = res[1]
|
|
125
124
|
}))
|
|
126
|
-
.
|
|
125
|
+
.onDidScroll(shouldBindEvent((xOffset: number, yOffset: number) => { handleScrollEvent(this.node, 'scroll', xOffset, yOffset) }, this.node, ['scroll']))
|
|
127
126
|
.onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
|
|
128
127
|
.onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
|
|
129
128
|
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
129
|
+
.onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -10,6 +10,7 @@ interface SliderAttrs {
|
|
|
10
10
|
trackColor?: ResourceColor
|
|
11
11
|
trackThickness?: Length
|
|
12
12
|
blockColor?: ResourceColor
|
|
13
|
+
disabled?: boolean
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
@Extend(Slider)
|
|
@@ -18,6 +19,7 @@ function attrs (attr: SliderAttrs) {
|
|
|
18
19
|
.trackColor(attr.trackColor)
|
|
19
20
|
.trackThickness(attr.trackThickness)
|
|
20
21
|
.blockColor(attr.blockColor)
|
|
22
|
+
.enabled(!attr.disabled)
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
function getAttributes (node: TaroSliderElement): SliderAttrs {
|
|
@@ -27,6 +29,7 @@ function getAttributes (node: TaroSliderElement): SliderAttrs {
|
|
|
27
29
|
sliderAttrs.trackColor = _attrs.backgroundColor || _attrs.color || '#e9e9e9'
|
|
28
30
|
sliderAttrs.trackThickness = _attrs.blockSize
|
|
29
31
|
sliderAttrs.blockColor = _attrs.blockColor || '#ffffff'
|
|
32
|
+
sliderAttrs.disabled = !!_attrs.disabled
|
|
30
33
|
return sliderAttrs
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -37,9 +40,12 @@ function themeStyles(isDisabled: boolean) {
|
|
|
37
40
|
|
|
38
41
|
@Component
|
|
39
42
|
export default struct TaroSlider {
|
|
43
|
+
@Builder customBuilder() {}
|
|
44
|
+
@BuilderParam createLazyChildren: (node: TaroSliderElement, layer?: number) => void = this.customBuilder
|
|
40
45
|
@ObjectLink node: TaroSliderElement
|
|
41
46
|
|
|
42
47
|
@State value: number = 0
|
|
48
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
43
49
|
|
|
44
50
|
aboutToAppear () {
|
|
45
51
|
if (this.node) {
|
|
@@ -62,7 +68,7 @@ export default struct TaroSlider {
|
|
|
62
68
|
style: SliderStyle.OutSet,
|
|
63
69
|
direction: Axis.Horizontal
|
|
64
70
|
})
|
|
65
|
-
.attributeModifier(commonStyleModify.setNode(node))
|
|
71
|
+
.attributeModifier(commonStyleModify.setNode(node).setAnimationStyle(this.overwriteStyle))
|
|
66
72
|
.attrs(getAttributes(node))
|
|
67
73
|
.width(!!node._attrs.showValue ? '90%' : '100%')
|
|
68
74
|
.themeStyles(!!node._attrs.disabled)
|
|
@@ -74,7 +80,7 @@ export default struct TaroSlider {
|
|
|
74
80
|
} else {
|
|
75
81
|
this.value = value
|
|
76
82
|
this.node?.updateFormWidgetValue(value)
|
|
77
|
-
|
|
83
|
+
|
|
78
84
|
if (mode === SliderChangeMode.End) {
|
|
79
85
|
const event: TaroEvent = createTaroEvent('change', { detail: { value: this.value } }, node)
|
|
80
86
|
eventHandler(event, 'change', node)
|
|
@@ -84,7 +90,7 @@ export default struct TaroSlider {
|
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
})
|
|
87
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
93
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
88
94
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
89
95
|
if (this.node) {
|
|
90
96
|
this.node._nodeInfo.areaInfo = res[1]
|
|
@@ -94,18 +100,16 @@ export default struct TaroSlider {
|
|
|
94
100
|
}
|
|
95
101
|
|
|
96
102
|
build() {
|
|
97
|
-
if (this.node) {
|
|
98
|
-
|
|
99
|
-
Row() {
|
|
100
|
-
this.createSlider(this.node)
|
|
101
|
-
Text(Number(this.value).toFixed(0))
|
|
102
|
-
.width('10%')
|
|
103
|
-
.textAlign(TextAlign.Center)
|
|
104
|
-
.opacity(!!this.node._attrs.disabled ? 0.4 : 1)
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
103
|
+
if (!!this.node._attrs.showValue) {
|
|
104
|
+
Row() {
|
|
107
105
|
this.createSlider(this.node)
|
|
106
|
+
Text(Number(this.value).toFixed(0))
|
|
107
|
+
.width('10%')
|
|
108
|
+
.textAlign(TextAlign.Center)
|
|
109
|
+
.opacity(!!this.node._attrs.disabled ? 0.4 : 1)
|
|
108
110
|
}
|
|
111
|
+
} else {
|
|
112
|
+
this.createSlider(this.node)
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
|
-
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import commonStyleModify from './style'
|
|
2
|
+
|
|
3
|
+
import type { TaroViewElement, TaroElement, TaroAny } from '@tarojs/runtime'
|
|
4
|
+
|
|
5
|
+
@Component
|
|
6
|
+
export default struct TaroStickySection {
|
|
7
|
+
@Builder customBuilder() {}
|
|
8
|
+
@BuilderParam createLazyChildren: (node: TaroViewElement, layer?: number) => void = this.customBuilder
|
|
9
|
+
@ObjectLink node: TaroViewElement
|
|
10
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
11
|
+
|
|
12
|
+
aboutToAppear(): void {
|
|
13
|
+
if (this.node) {
|
|
14
|
+
this.node._instance = this
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Builder
|
|
19
|
+
itemHead(header: TaroViewElement) {
|
|
20
|
+
Stack() {
|
|
21
|
+
LazyForEach(header, (item: TaroElement) => {
|
|
22
|
+
if (item.tagName === 'STICKY-HEADER') {
|
|
23
|
+
this.createLazyChildren(item as TaroViewElement, 0)
|
|
24
|
+
}
|
|
25
|
+
}, (item: TaroElement) => `${item._nid}-${item._nodeInfo?.layer || 0}`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
build() {
|
|
30
|
+
ListItemGroup({
|
|
31
|
+
header: this.itemHead(this.node)
|
|
32
|
+
}) {
|
|
33
|
+
ForEach(this.node.children, (item: TaroElement) => {
|
|
34
|
+
if (item.tagName === 'LIST-VIEW') {
|
|
35
|
+
this.createLazyChildren(item as TaroViewElement, 0)
|
|
36
|
+
}
|
|
37
|
+
}, (item: TaroElement) => `${item._nid}-${item._nodeInfo?.layer || 0}`)
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
41
|
+
}
|
|
42
|
+
}
|