@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.2 → 4.0.0-alpha.21
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 +146 -78
- 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 +64 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +72 -61
- package/dist/components-harmony-ets/form.ets +51 -29
- package/dist/components-harmony-ets/icon.ets +31 -19
- package/dist/components-harmony-ets/image.ets +34 -14
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +49 -41
- package/dist/components-harmony-ets/label.ets +71 -44
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- 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 +42 -38
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +74 -64
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +61 -57
- 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 +381 -130
- package/dist/components-harmony-ets/swiper.ets +61 -20
- package/dist/components-harmony-ets/switch.ets +36 -32
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +135 -49
- package/dist/components-harmony-ets/textArea.ets +50 -35
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- 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 +18 -5
- 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 +34 -21
- package/dist/components-harmony-ets/view.ets +63 -52
- package/dist/components-harmony-ets/webView.ets +40 -34
- package/dist/index.d.ts +152 -0
- package/dist/index.js +99 -55
- 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 +3 -0
- 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 +348 -57
- package/dist/runtime-ets/dom/element/form.ts +31 -26
- package/dist/runtime-ets/dom/element/index.ts +30 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +244 -0
- package/dist/runtime-ets/dom/element/normal.ts +35 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +12 -5
- package/dist/runtime-ets/dom/event.ts +2 -4
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +54 -29
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
- 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 +73 -13
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-framework/react/app.ts +9 -4
- 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 +154 -77
- package/dist/runtime-framework/react/page.ts +3 -8
- package/dist/runtime-framework/solid/app.ts +25 -45
- 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 +84 -30
- 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 +0 -2
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +435 -218
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +435 -218
- 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
|
@@ -7,18 +7,20 @@ import type { TaroAny, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
|
|
|
7
7
|
|
|
8
8
|
interface SwitchAttrs {
|
|
9
9
|
selectedColor?: ResourceColor
|
|
10
|
+
disabled?: boolean
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
@Extend(Toggle)
|
|
13
14
|
function attrs(attr: SwitchAttrs) {
|
|
14
15
|
.selectedColor(attr.selectedColor)
|
|
16
|
+
.enabled(!attr.disabled)
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
function getAttributes (node: TaroSwitchElement): SwitchAttrs {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return
|
|
20
|
+
const attr: SwitchAttrs = {}
|
|
21
|
+
attr.selectedColor = node._attrs.color || '#04BE02'
|
|
22
|
+
attr.disabled = !!node._attrs.disabled
|
|
23
|
+
return attr
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
@Extend(Toggle)
|
|
@@ -28,43 +30,45 @@ function themeStyles(isDisabled: boolean) {
|
|
|
28
30
|
|
|
29
31
|
@Component
|
|
30
32
|
export default struct TaroSwitch {
|
|
31
|
-
|
|
33
|
+
@Builder customBuilder() {}
|
|
34
|
+
@BuilderParam createLazyChildren: (node: TaroSwitchElement) => void = this.customBuilder
|
|
35
|
+
@ObjectLink node: TaroSwitchElement
|
|
36
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
32
37
|
|
|
33
38
|
aboutToAppear () {
|
|
34
39
|
if (this.node && !this.node._isInit) {
|
|
35
40
|
this.node._isInit = true
|
|
41
|
+
this.node._instance = this
|
|
36
42
|
this.node._reset = this.node.checked || false
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
build () {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
if (this.node) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.node.updateComponent()
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
62
|
-
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
63
|
-
if (this.node) {
|
|
64
|
-
this.node._nodeInfo.areaInfo = res[1]
|
|
47
|
+
Toggle({
|
|
48
|
+
type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
|
|
49
|
+
isOn: this.node.checked,
|
|
50
|
+
})
|
|
51
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
52
|
+
.attrs(getAttributes(this.node))
|
|
53
|
+
.themeStyles(!!this.node._attrs.disabled)
|
|
54
|
+
.onChange((isOn: boolean) => {
|
|
55
|
+
if (this.node) {
|
|
56
|
+
if (!this.node?._attrs.disabled) {
|
|
57
|
+
const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, this.node)
|
|
58
|
+
|
|
59
|
+
this.node.updateCheckedValue(isOn)
|
|
60
|
+
eventHandler(event, 'change', this.node)
|
|
61
|
+
} else {
|
|
62
|
+
this.node.updateComponent()
|
|
65
63
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
67
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
68
|
+
if (this.node) {
|
|
69
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
70
|
+
}
|
|
71
|
+
}))
|
|
72
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
69
73
|
}
|
|
70
74
|
}
|
|
@@ -35,6 +35,8 @@ export const TaroAdTagName = 'ad'
|
|
|
35
35
|
export const TaroWebViewTagName = 'web-view'
|
|
36
36
|
export const TaroBlockTagName = 'block'
|
|
37
37
|
export const TaroMapTagName = 'map'
|
|
38
|
+
export const TaroPageMetaTagName = 'page-meta'
|
|
39
|
+
export const TaroNavigationBarTagName = 'navigation-bar'
|
|
38
40
|
export const TaroSlotTagName = 'slot'
|
|
39
41
|
export const TaroNativeSlotTagName = 'native-slot'
|
|
40
42
|
export const TaroCustomWrapperTagName = 'custom-wrapper'
|
|
@@ -47,3 +49,7 @@ export const TaroListTagName = 'list'
|
|
|
47
49
|
export const TaroListItemTagName = 'list-item'
|
|
48
50
|
export const TaroOpenDataTagName = 'open-data'
|
|
49
51
|
export const TaroIgnoreTagName = 'ignore'
|
|
52
|
+
|
|
53
|
+
export const TaroStickySectionTagName = 'sticky-section'
|
|
54
|
+
export const TaroStickyHeaderTagName = 'sticky-header'
|
|
55
|
+
export const TaroListViewTagName = 'list-view'
|
|
@@ -1,66 +1,152 @@
|
|
|
1
|
+
import { isString } from '@tarojs/shared'
|
|
1
2
|
import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
+
import { textModify, setNormalTextAttributeIntoInstance } from './style'
|
|
4
5
|
import { getButtonColor } from './button'
|
|
6
|
+
import { getImageMode } from './image'
|
|
5
7
|
import { BUTTON_THEME_COLOR } from './utils/constant/style'
|
|
6
|
-
import { getNodeThresholds,
|
|
8
|
+
import { getNodeThresholds, getStyleAttr, shouldBindEvent, getNormalAttributes } from './utils/helper'
|
|
7
9
|
|
|
8
|
-
import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny,
|
|
10
|
+
import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, HarmonyStyle } from '@tarojs/runtime'
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.opacity(style.opacity)
|
|
15
|
-
.fontColor(style.color)
|
|
16
|
-
.fontSize(style.fontSize)
|
|
17
|
-
.fontWeight(style.fontWeight)
|
|
18
|
-
.fontStyle(style.fontStyle)
|
|
19
|
-
.fontFamily(style.fontFamily)
|
|
20
|
-
.lineHeight(style.lineHeight)
|
|
21
|
-
.decoration({
|
|
22
|
-
type: style.textDecoration,
|
|
23
|
-
color: style.color
|
|
24
|
-
})
|
|
12
|
+
function getButtonFontSize (node: TaroButtonElement): string | number {
|
|
13
|
+
const isMini = node._attrs.size === 'mini'
|
|
14
|
+
|
|
15
|
+
return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
|
|
25
16
|
}
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
function getTextInViewWidth (node: TaroElement | null): TaroAny {
|
|
19
|
+
if (node) {
|
|
20
|
+
const hmStyle = node.hmStyle || {}
|
|
21
|
+
const isFlexView = hmStyle.display === 'flex'
|
|
22
|
+
const width: TaroAny = getStyleAttr(node, 'width')
|
|
23
|
+
const isPercentWidth = isString(width) && width.includes('%')
|
|
24
|
+
|
|
25
|
+
return isFlexView || isPercentWidth ? null : getStyleAttr(node, 'width')
|
|
26
|
+
}
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
function getButtonFontSize (node: TaroButtonElement) {
|
|
36
|
-
const isMini = node._attrs.size === 'mini'
|
|
37
29
|
|
|
38
|
-
|
|
30
|
+
@Component
|
|
31
|
+
export default struct TaroText {
|
|
32
|
+
@Builder customBuilder() {}
|
|
33
|
+
@BuilderParam createLazyChildren: (node: TaroTextElement) => void = this.customBuilder
|
|
34
|
+
@ObjectLink node: TaroTextElement
|
|
35
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
36
|
+
|
|
37
|
+
aboutToAppear(): void {
|
|
38
|
+
if (this.node) {
|
|
39
|
+
this.node._instance = this
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
build () {
|
|
44
|
+
if (this.node.nodeType === NodeType.TEXT_NODE) {
|
|
45
|
+
if (this.node.parentNode) {
|
|
46
|
+
if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
|
|
47
|
+
Text(this.node.textContent)
|
|
48
|
+
.attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement, {
|
|
49
|
+
fontSize: getButtonFontSize(this.node.parentNode as TaroButtonElement),
|
|
50
|
+
color: getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type || '').text)
|
|
51
|
+
}))
|
|
52
|
+
} else {
|
|
53
|
+
Text(this.node.textContent)
|
|
54
|
+
.attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement))
|
|
55
|
+
.width(getTextInViewWidth(this.node.parentElement))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
Text(this.node.textContent) {
|
|
60
|
+
// text 下还有标签
|
|
61
|
+
if (this.node.childNodes.length > 1 || ((this.node.childNodes[0] && this.node.childNodes[0] as TaroElement)?.nodeType === NodeType.ELEMENT_NODE)) {
|
|
62
|
+
ForEach(this.node.childNodes, (item: TaroElement) => {
|
|
63
|
+
createTextChildNode(item)
|
|
64
|
+
}, (item: TaroElement) => `${item._nid}${this.node._updateTrigger}`)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
68
|
+
.attributeModifier(textModify.setNode(this.node).withNormalStyle().setAnimationStyle(this.overwriteStyle))
|
|
69
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
70
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
71
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
72
|
+
}))
|
|
73
|
+
}
|
|
74
|
+
}
|
|
39
75
|
}
|
|
40
76
|
|
|
41
77
|
@Builder
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
.
|
|
78
|
+
function createTextChildNode (item: TaroElement) {
|
|
79
|
+
if (item.tagName === 'IMAGE') {
|
|
80
|
+
ImageSpan(item.getAttribute('src'))
|
|
81
|
+
// .attributeModifier(commonStyleModify.setNode(item))
|
|
82
|
+
.objectFit(getImageMode(item.getAttribute('mode')))
|
|
83
|
+
// .verticalAlign(align)
|
|
84
|
+
.width(item._st.hmStyle.width)
|
|
85
|
+
.height(item._st.hmStyle.height)
|
|
86
|
+
.margin({
|
|
87
|
+
top: item._st.hmStyle.marginTop,
|
|
88
|
+
left: item._st.hmStyle.marginLeft,
|
|
89
|
+
right: item._st.hmStyle.marginRight,
|
|
90
|
+
bottom: item._st.hmStyle.marginBottom,
|
|
91
|
+
})
|
|
92
|
+
.padding({
|
|
93
|
+
top: item._st.hmStyle.paddingTop,
|
|
94
|
+
left: item._st.hmStyle.paddingLeft,
|
|
95
|
+
right: item._st.hmStyle.paddingRight,
|
|
96
|
+
bottom: item._st.hmStyle.paddingBottom,
|
|
97
|
+
})
|
|
98
|
+
.textBackgroundStyle({
|
|
99
|
+
color: item._st.hmStyle.backgroundColor,
|
|
100
|
+
radius: {
|
|
101
|
+
topLeft: item._st.hmStyle.borderTopLeftRadius,
|
|
102
|
+
topRight: item._st.hmStyle.borderTopRightRadius,
|
|
103
|
+
bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
|
|
104
|
+
bottomRight: item._st.hmStyle.borderBottomRightRadius,
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
.borderRadius({
|
|
108
|
+
topLeft: item._st.hmStyle.borderTopLeftRadius,
|
|
109
|
+
topRight: item._st.hmStyle.borderTopRightRadius,
|
|
110
|
+
bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
|
|
111
|
+
bottomRight: item._st.hmStyle.borderBottomRightRadius
|
|
112
|
+
})
|
|
113
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
|
|
114
|
+
} else if (item.nodeType === NodeType.TEXT_NODE) {
|
|
115
|
+
Span(item.textContent)
|
|
116
|
+
} else if (item.tagName === 'TEXT') {
|
|
117
|
+
Span(item.textContent)
|
|
118
|
+
.attributeModifier(spanModify.setNode(item))
|
|
119
|
+
.letterSpacing(item._st.hmStyle.letterSpacing)
|
|
120
|
+
.textBackgroundStyle({
|
|
121
|
+
color: item._st.hmStyle.backgroundColor,
|
|
122
|
+
radius: {
|
|
123
|
+
topLeft: item._st.hmStyle.borderTopLeftRadius,
|
|
124
|
+
topRight: item._st.hmStyle.borderTopRightRadius,
|
|
125
|
+
bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
|
|
126
|
+
bottomRight: item._st.hmStyle.borderBottomRightRadius,
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class SpanStyleModify implements AttributeModifier<SpanAttribute> {
|
|
134
|
+
node: TaroTextElement | null = null
|
|
135
|
+
style: HarmonyStyle | null = null
|
|
136
|
+
overwriteStyle: Record<string, TaroAny> = {}
|
|
137
|
+
withNormal = false
|
|
138
|
+
|
|
139
|
+
setNode (node: TaroTextElement) {
|
|
140
|
+
this.node = node
|
|
141
|
+
this.style = getNormalAttributes(this.node)
|
|
142
|
+
return this
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
applyNormalAttribute(instance: SpanAttribute): void {
|
|
146
|
+
if (this.node && this.style) {
|
|
147
|
+
setNormalTextAttributeIntoInstance(instance, this.style, this.node)
|
|
54
148
|
}
|
|
55
|
-
} else {
|
|
56
|
-
Text(node.textContent)
|
|
57
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
|
|
58
|
-
.attributeModifier(commonStyleModify.setNode(node))
|
|
59
|
-
.textNormalFontStyle(getNormalAttributes(node))
|
|
60
|
-
.textSpecialFontStyle(getFontAttributes(node))
|
|
61
|
-
.onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
|
|
62
|
-
.onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
63
|
-
node._nodeInfo.areaInfo = res[1]
|
|
64
|
-
}))
|
|
65
149
|
}
|
|
66
150
|
}
|
|
151
|
+
|
|
152
|
+
const spanModify = new SpanStyleModify()
|
|
@@ -1,10 +1,15 @@
|
|
|
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 { getNodeThresholds,
|
|
4
|
+
import { getNodeThresholds, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
|
|
5
5
|
|
|
6
6
|
import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroTextAreaElement, TaroEvent } from '@tarojs/runtime'
|
|
7
7
|
|
|
8
|
+
interface TextareaAttrs extends TaroTextStyleType {
|
|
9
|
+
autoFocus?: boolean
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
@Extend(TextArea)
|
|
9
14
|
function textStyle (style: TaroStyleType) {
|
|
10
15
|
.fontColor(style.color)
|
|
@@ -15,9 +20,18 @@ function textStyle (style: TaroStyleType) {
|
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
@Extend(TextArea)
|
|
18
|
-
function textAttr(attr:
|
|
23
|
+
function textAttr(attr: TextareaAttrs) {
|
|
19
24
|
.textAlign(attr.textAlign)
|
|
20
25
|
.maxLines(attr.WebkitLineClamp)
|
|
26
|
+
.defaultFocus(attr.autoFocus)
|
|
27
|
+
.enabled(!attr.disabled)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getAttributes(node: TaroTextAreaElement): TextareaAttrs {
|
|
31
|
+
const attrs: TaroAny = getFontAttributes(node)
|
|
32
|
+
attrs.autoFocus = node._attrs.autoFocus || node._attrs.focus || false
|
|
33
|
+
attrs.disabled = node._attrs.disabled || false
|
|
34
|
+
return attrs
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
function getPlaceholderColor (node: TaroTextAreaElement): string {
|
|
@@ -30,7 +44,10 @@ function getPlaceholderColor (node: TaroTextAreaElement): string {
|
|
|
30
44
|
export default struct TaroTextArea {
|
|
31
45
|
@State value: string = ''
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
@Builder customBuilder() {}
|
|
48
|
+
@BuilderParam createLazyChildren: (node: TaroTextAreaElement) => void = this.customBuilder
|
|
49
|
+
@ObjectLink node: TaroTextAreaElement
|
|
50
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
34
51
|
|
|
35
52
|
aboutToAppear () {
|
|
36
53
|
if (this.node) {
|
|
@@ -45,37 +62,35 @@ export default struct TaroTextArea {
|
|
|
45
62
|
}
|
|
46
63
|
|
|
47
64
|
build () {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
79
|
-
}
|
|
65
|
+
TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
|
|
66
|
+
.key(this.node._nid)
|
|
67
|
+
.maxLength(Number(this.node._attrs?.maxlength) || null)
|
|
68
|
+
.placeholderColor(getPlaceholderColor(this.node))
|
|
69
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
70
|
+
.textStyle(this.node?.hmStyle)
|
|
71
|
+
.textAttr(getAttributes(this.node))
|
|
72
|
+
.onChange((value: string) => {
|
|
73
|
+
const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
|
|
74
|
+
|
|
75
|
+
this.value = value
|
|
76
|
+
this.node?.updateFormWidgetValue(value)
|
|
77
|
+
eventHandler(event, 'input', this.node)
|
|
78
|
+
})
|
|
79
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
80
|
+
.onBlur(() => {
|
|
81
|
+
const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
|
|
82
|
+
eventHandler(event, 'blur', this.node)
|
|
83
|
+
})
|
|
84
|
+
.onFocus(() => {
|
|
85
|
+
const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
|
|
86
|
+
|
|
87
|
+
eventHandler(event, 'focus', this.node)
|
|
88
|
+
})
|
|
89
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
90
|
+
if (this.node) {
|
|
91
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
92
|
+
}
|
|
93
|
+
}))
|
|
94
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
80
95
|
}
|
|
81
96
|
}
|
|
@@ -60,7 +60,7 @@ class AttributeManager {
|
|
|
60
60
|
const dataValue: string = AttributeManager.getNodeStyle(style, 'animation')
|
|
61
61
|
|
|
62
62
|
if (dataValue) {
|
|
63
|
-
let values: string[] = dataValue.trim().split(new RegExp("/\s+/"))
|
|
63
|
+
let values: string[] = dataValue.toString().trim().split(new RegExp("/\s+/"))
|
|
64
64
|
switch (values.length) {
|
|
65
65
|
case 4:
|
|
66
66
|
res = { duration: values[0], curve: values[1], delay: values[2] }
|
|
@@ -11,7 +11,7 @@ export class DynamicCenter {
|
|
|
11
11
|
if (!node._isCompileMode || !node._instance) return
|
|
12
12
|
|
|
13
13
|
if (node._attrs?._dynamicID) {
|
|
14
|
-
node._instance[node._attrs._dynamicID] =
|
|
14
|
+
node._instance[node._attrs._dynamicID] = new TaroElement('Ignore')
|
|
15
15
|
}
|
|
16
16
|
node._instance = null
|
|
17
17
|
}
|
|
@@ -36,4 +36,4 @@ export class DynamicCenter {
|
|
|
36
36
|
this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|
|
@@ -1,60 +1,90 @@
|
|
|
1
|
-
import type { TaroElement } from '@tarojs/runtime'
|
|
1
|
+
import type { TaroElement, HarmonyStyle } from '@tarojs/runtime'
|
|
2
2
|
import { isUndefined } from '@tarojs/shared'
|
|
3
|
+
import { getNormalAttributes } from './styles'
|
|
3
4
|
|
|
4
5
|
interface IFlexOptions {
|
|
5
6
|
direction: FlexDirection,
|
|
6
7
|
justifyContent: FlexAlign,
|
|
7
|
-
alignItems:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// alignContent: FlexAlignContent
|
|
8
|
+
alignItems: ItemAlign,
|
|
9
|
+
wrap?: FlexWrap,
|
|
10
|
+
alignContent?: FlexAlign
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
class FlexManager {
|
|
14
14
|
static isFlexNode (node: TaroElement): boolean {
|
|
15
15
|
return !!node.hmStyle?.display?.includes('flex')
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
|
|
19
19
|
if (direction === FlexDirection.Column) {
|
|
20
20
|
switch (alignItems) {
|
|
21
|
-
case ItemAlign.
|
|
22
|
-
return HorizontalAlign.
|
|
21
|
+
case ItemAlign.Center:
|
|
22
|
+
return HorizontalAlign.Center
|
|
23
23
|
case ItemAlign.End:
|
|
24
24
|
return HorizontalAlign.End
|
|
25
25
|
default:
|
|
26
|
-
return HorizontalAlign.
|
|
26
|
+
return HorizontalAlign.Start
|
|
27
27
|
}
|
|
28
28
|
} else {
|
|
29
29
|
switch (alignItems) {
|
|
30
|
-
case ItemAlign.
|
|
31
|
-
return VerticalAlign.
|
|
30
|
+
case ItemAlign.Center:
|
|
31
|
+
return VerticalAlign.Center
|
|
32
32
|
case ItemAlign.End:
|
|
33
33
|
return VerticalAlign.Bottom
|
|
34
34
|
default:
|
|
35
|
-
return VerticalAlign.
|
|
35
|
+
return VerticalAlign.Top
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
static useFlexLayout (node: TaroElement): boolean {
|
|
41
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
|
|
42
|
+
const isReverse = hmStyle.flexDirection && [FlexDirection.RowReverse, FlexDirection.ColumnReverse].indexOf(hmStyle.flexDirection) !== -1;
|
|
43
|
+
const isUnknownAlign = [ItemAlign.Stretch, ItemAlign.Baseline].indexOf(hmStyle.alignItems!) !== -1;
|
|
44
|
+
return !isUndefined(hmStyle.flexWrap) || isReverse || isUnknownAlign;
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
static flexOptions (node: TaroElement): IFlexOptions {
|
|
41
|
-
const hmStyle = node
|
|
48
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
|
|
42
49
|
const isFlex = FlexManager.isFlexNode(node)
|
|
43
|
-
const justifyContent: FlexAlign = isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
|
|
44
|
-
|
|
45
50
|
let flexDirection = hmStyle.flexDirection
|
|
46
51
|
if (!flexDirection && flexDirection !== 0) {
|
|
47
52
|
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
const alignItems = isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start
|
|
51
|
-
|
|
52
55
|
return {
|
|
53
|
-
alignItems,
|
|
54
|
-
justifyContent,
|
|
56
|
+
alignItems: isFlex ? (isUndefined(hmStyle.alignItems) ? ItemAlign.Start : hmStyle.alignItems) : ItemAlign.Start,
|
|
57
|
+
justifyContent: isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start,
|
|
55
58
|
direction: flexDirection,
|
|
59
|
+
wrap: isFlex ? hmStyle.flexWrap: FlexWrap.NoWrap,
|
|
60
|
+
alignContent: isFlex ? hmStyle.alignContent: FlexAlign.Start
|
|
56
61
|
}
|
|
57
62
|
}
|
|
63
|
+
|
|
64
|
+
static direction (node: TaroElement): FlexDirection {
|
|
65
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node)
|
|
66
|
+
let flexDirection = hmStyle.flexDirection
|
|
67
|
+
if (!flexDirection && flexDirection !== 0) {
|
|
68
|
+
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
69
|
+
}
|
|
70
|
+
return flexDirection
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static alignItems<T> (node: TaroElement): T {
|
|
74
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node)
|
|
75
|
+
const isFlex = FlexManager.isFlexNode(node)
|
|
76
|
+
let flexDirection = hmStyle.flexDirection
|
|
77
|
+
if (!flexDirection && flexDirection !== 0) {
|
|
78
|
+
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
79
|
+
}
|
|
80
|
+
return (isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start) as T
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static justifyContent (node: TaroElement): FlexAlign {
|
|
84
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node)
|
|
85
|
+
const isFlex = FlexManager.isFlexNode(node)
|
|
86
|
+
return isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
|
|
87
|
+
}
|
|
58
88
|
}
|
|
59
89
|
|
|
60
90
|
export { FlexManager }
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VIEW } from '@tarojs/runtime/dist/runtime.esm'
|
|
2
|
+
|
|
3
|
+
import { getNormalAttributes, getFontAttributes, getStyleAttr } from './styles'
|
|
2
4
|
|
|
3
5
|
import type { TFunc } from '@tarojs/runtime/dist/runtime.esm'
|
|
4
|
-
import type { TaroElement } from '@tarojs/runtime'
|
|
6
|
+
import type { TaroElement, TaroNode } from '@tarojs/runtime'
|
|
5
7
|
|
|
6
8
|
export const parseStyles = (styles = ''): Record<string, string> => {
|
|
7
9
|
const styleObj: Record<string, string> = {}
|
|
@@ -31,9 +33,20 @@ export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export function getNodeThresholds (node: TaroElement): number[] | null {
|
|
34
|
-
|
|
36
|
+
return node?._nodeInfo?.thresholds || null
|
|
37
|
+
}
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
export function isTagFirstChild (node: TaroElement, tagName = VIEW, level = 0): boolean {
|
|
40
|
+
const parent: TaroElement | null = node.parentElement
|
|
41
|
+
const list: TaroNode[] = node.parentNode?.childNodes || []
|
|
42
|
+
if (list.length < 1 || level < 0) return false
|
|
43
|
+
else if (!parent) return true
|
|
44
|
+
|
|
45
|
+
if (parent.nodeName === tagName.toUpperCase()) {
|
|
46
|
+
return list[0] === node
|
|
47
|
+
} else {
|
|
48
|
+
return (list[0] === node) && isTagFirstChild(parent, tagName, --level)
|
|
49
|
+
}
|
|
37
50
|
}
|
|
38
51
|
|
|
39
|
-
export { getNormalAttributes, getFontAttributes }
|
|
52
|
+
export { getNormalAttributes, getFontAttributes, getStyleAttr }
|