@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.0 → 4.0.0-alpha.10
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/device/memory.ts +10 -3
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +27 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/media/video/VideoContext.ts +56 -7
- package/dist/apis/media/video/index.ts +3 -2
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- 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 +1 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +68 -68
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +81 -102
- package/dist/components-harmony-ets/form.ets +54 -45
- package/dist/components-harmony-ets/icon.ets +34 -50
- package/dist/components-harmony-ets/image.ets +35 -45
- 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 +51 -67
- package/dist/components-harmony-ets/label.ets +73 -53
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/movableArea.ets +124 -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 +74 -77
- 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 +82 -104
- package/dist/components-harmony-ets/richText.ets +20 -68
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +67 -103
- package/dist/components-harmony-ets/slider.ets +23 -47
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +396 -0
- package/dist/components-harmony-ets/swiper.ets +64 -53
- package/dist/components-harmony-ets/switch.ets +44 -55
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +134 -75
- package/dist/components-harmony-ets/textArea.ets +54 -62
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
- package/dist/components-harmony-ets/utils/flexManager.ets +76 -8
- package/dist/components-harmony-ets/utils/helper.ets +20 -7
- 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 +178 -63
- package/dist/components-harmony-ets/video.ets +37 -54
- package/dist/components-harmony-ets/view.ets +63 -94
- package/dist/components-harmony-ets/webView.ets +56 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +199 -58
- 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 +9 -2
- 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 +409 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +29 -19
- package/dist/runtime-ets/dom/document.ts +22 -8
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +334 -57
- package/dist/runtime-ets/dom/element/form.ts +32 -26
- package/dist/runtime-ets/dom/element/index.ts +33 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +242 -0
- package/dist/runtime-ets/dom/element/normal.ts +36 -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 +68 -0
- 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 +62 -27
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +98 -518
- package/dist/runtime-ets/dom/stylesheet/type.ts +92 -17
- package/dist/runtime-ets/dom/stylesheet/util.ts +74 -16
- package/dist/runtime-ets/index.ts +2 -2
- package/dist/runtime-ets/interface/event.ts +3 -2
- package/dist/runtime-ets/utils/index.ts +77 -12
- package/dist/runtime-ets/utils/info.ts +4 -2
- package/dist/runtime-framework/react/app.ts +17 -22
- package/dist/runtime-framework/react/hooks.ts +3 -4
- package/dist/runtime-framework/react/index.ts +1 -2
- package/dist/runtime-framework/react/native-page.ts +421 -0
- package/dist/runtime-framework/react/page.ts +4 -9
- 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 +17 -12
- 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 +510 -237
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +510 -237
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -0
- package/static/media/circle.svg +1 -0
- package/static/media/clear.svg +1 -0
- package/static/media/download.svg +1 -0
- package/static/media/info.svg +1 -0
- package/static/media/info_circle.svg +1 -0
- package/static/media/search.svg +1 -0
- package/static/media/success.svg +1 -0
- package/static/media/success_no_circle.svg +1 -0
- package/static/media/taro_arrow_left.svg +1 -0
- package/static/media/taro_home.svg +1 -0
- package/static/media/waiting.svg +1 -0
- package/static/media/warn.svg +1 -0
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +3 -1
- package/dist/runtime-ets/utils/bind.ts +0 -24
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -1,93 +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
|
|
|
4
|
+
import { textModify, setNormalTextAttributeIntoInstance } from './style'
|
|
3
5
|
import { getButtonColor } from './button'
|
|
6
|
+
import { getImageMode } from './image'
|
|
4
7
|
import { BUTTON_THEME_COLOR } from './utils/constant/style'
|
|
5
|
-
import { getNodeThresholds,
|
|
8
|
+
import { getNodeThresholds, getStyleAttr, shouldBindEvent, getNormalAttributes } from './utils/helper'
|
|
6
9
|
|
|
7
|
-
import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny,
|
|
10
|
+
import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, HarmonyStyle } from '@tarojs/runtime'
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.padding(style.padding)
|
|
12
|
-
.margin(style.margin)
|
|
13
|
-
.width(style.width)
|
|
14
|
-
.height(style.height)
|
|
15
|
-
.constraintSize(style.constraintSize)
|
|
16
|
-
.flexGrow(style.flexGrow)
|
|
17
|
-
.flexShrink(style.flexShrink)
|
|
18
|
-
.flexBasis(style.flexBasis)
|
|
19
|
-
.alignSelf(style.alignSelf)
|
|
20
|
-
.backgroundColor(style.backgroundColor)
|
|
21
|
-
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
22
|
-
.backgroundImageSize(style.backgroundImageSize)
|
|
23
|
-
.backgroundImagePosition(style.backgroundImagePosition)
|
|
24
|
-
.rotate(style.rotate)
|
|
25
|
-
.scale(style.scale)
|
|
26
|
-
.translate(style.translate)
|
|
27
|
-
.transform(style.transform)
|
|
28
|
-
.borderStyle(style.borderStyle)
|
|
29
|
-
.borderWidth(style.borderWidth)
|
|
30
|
-
.borderColor(style.borderColor)
|
|
31
|
-
.borderRadius(style.borderRadius)
|
|
32
|
-
.linearGradient(style.linearGradient)
|
|
33
|
-
.zIndex(style.zIndex)
|
|
34
|
-
.clip(style.clip)
|
|
35
|
-
}
|
|
12
|
+
function getButtonFontSize (node: TaroButtonElement): string | number {
|
|
13
|
+
const isMini = node._attrs.size === 'mini'
|
|
36
14
|
|
|
37
|
-
|
|
38
|
-
function textNormalFontStyle (style: TaroStyleType) {
|
|
39
|
-
.id(style.id)
|
|
40
|
-
.key(style.id)
|
|
41
|
-
.opacity(style.opacity)
|
|
42
|
-
.fontColor(style.color)
|
|
43
|
-
.fontSize(style.fontSize)
|
|
44
|
-
.fontWeight(style.fontWeight)
|
|
45
|
-
.fontStyle(style.fontStyle)
|
|
46
|
-
.fontFamily(style.fontFamily)
|
|
47
|
-
.lineHeight(style.lineHeight)
|
|
48
|
-
.decoration({
|
|
49
|
-
type: style.decoration,
|
|
50
|
-
color: style.color
|
|
51
|
-
})
|
|
15
|
+
return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
|
|
52
16
|
}
|
|
53
17
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
}
|
|
60
27
|
}
|
|
61
28
|
|
|
62
|
-
function getButtonFontSize (node: TaroButtonElement) {
|
|
63
|
-
const isMini = node._attrs.size === 'mini'
|
|
64
29
|
|
|
65
|
-
|
|
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
|
+
}
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
@Builder
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.
|
|
80
|
-
.
|
|
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)
|
|
81
148
|
}
|
|
82
|
-
} else {
|
|
83
|
-
Text(node.textContent)
|
|
84
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
|
|
85
|
-
.onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
86
|
-
node._nodeInfo.areaInfo = res[1]
|
|
87
|
-
}))
|
|
88
|
-
.textNormalStyle(getNormalAttributes(node))
|
|
89
|
-
.textNormalFontStyle(getNormalAttributes(node))
|
|
90
|
-
.textSpecialFontStyle(getFontAttributes(node))
|
|
91
|
-
.onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
|
|
92
149
|
}
|
|
93
150
|
}
|
|
151
|
+
|
|
152
|
+
const spanModify = new SpanStyleModify()
|
|
@@ -1,38 +1,16 @@
|
|
|
1
1
|
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import commonStyleModify from './style'
|
|
4
|
+
import { getNodeThresholds, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
|
|
4
5
|
|
|
5
6
|
import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroTextAreaElement, TaroEvent } from '@tarojs/runtime'
|
|
6
7
|
|
|
8
|
+
interface TextareaAttrs extends TaroTextStyleType {
|
|
9
|
+
autoFocus?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
@Extend(TextArea)
|
|
8
13
|
function textStyle (style: TaroStyleType) {
|
|
9
|
-
.id(style.id)
|
|
10
|
-
.key(style.id)
|
|
11
|
-
.padding(style.padding)
|
|
12
|
-
.margin(style.margin)
|
|
13
|
-
.width(style.width)
|
|
14
|
-
.height(style.height)
|
|
15
|
-
.constraintSize(style.constraintSize)
|
|
16
|
-
.flexGrow(style.flexGrow)
|
|
17
|
-
.flexShrink(style.flexShrink)
|
|
18
|
-
.flexBasis(style.flexBasis)
|
|
19
|
-
.alignSelf(style.alignSelf)
|
|
20
|
-
.backgroundColor(style.backgroundColor)
|
|
21
|
-
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
22
|
-
.backgroundImageSize(style.backgroundImageSize)
|
|
23
|
-
.backgroundImagePosition(style.backgroundImagePosition)
|
|
24
|
-
.rotate(style.rotate)
|
|
25
|
-
.scale(style.scale)
|
|
26
|
-
.translate(style.translate)
|
|
27
|
-
.transform(style.transform)
|
|
28
|
-
.borderStyle(style.borderStyle)
|
|
29
|
-
.borderWidth(style.borderWidth)
|
|
30
|
-
.borderColor(style.borderColor)
|
|
31
|
-
.borderRadius(style.borderRadius)
|
|
32
|
-
.linearGradient(style.linearGradient)
|
|
33
|
-
.zIndex(style.zIndex)
|
|
34
|
-
.opacity(style.opacity)
|
|
35
|
-
.clip(style.clip)
|
|
36
14
|
.fontColor(style.color)
|
|
37
15
|
.fontSize(style.fontSize)
|
|
38
16
|
.fontWeight(style.fontWeight)
|
|
@@ -41,9 +19,16 @@ function textStyle (style: TaroStyleType) {
|
|
|
41
19
|
}
|
|
42
20
|
|
|
43
21
|
@Extend(TextArea)
|
|
44
|
-
function textAttr(attr:
|
|
22
|
+
function textAttr(attr: TextareaAttrs) {
|
|
45
23
|
.textAlign(attr.textAlign)
|
|
46
|
-
.maxLines(attr.
|
|
24
|
+
.maxLines(attr.WebkitLineClamp)
|
|
25
|
+
.defaultFocus(attr.autoFocus)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getAttributes(node: TaroTextAreaElement): TextareaAttrs {
|
|
29
|
+
const attrs: TaroAny = getFontAttributes(node)
|
|
30
|
+
attrs.autoFocus = node._attrs.autoFocus || node._attrs.focus || false
|
|
31
|
+
return attrs
|
|
47
32
|
}
|
|
48
33
|
|
|
49
34
|
function getPlaceholderColor (node: TaroTextAreaElement): string {
|
|
@@ -56,46 +41,53 @@ function getPlaceholderColor (node: TaroTextAreaElement): string {
|
|
|
56
41
|
export default struct TaroTextArea {
|
|
57
42
|
@State value: string = ''
|
|
58
43
|
|
|
59
|
-
|
|
44
|
+
@Builder customBuilder() {}
|
|
45
|
+
@BuilderParam createLazyChildren: (node: TaroTextAreaElement) => void = this.customBuilder
|
|
46
|
+
@ObjectLink node: TaroTextAreaElement
|
|
47
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
60
48
|
|
|
61
49
|
aboutToAppear () {
|
|
62
50
|
if (this.node) {
|
|
63
51
|
this.value = this.node.value
|
|
64
52
|
this.node._instance = this
|
|
53
|
+
|
|
54
|
+
if (!this.node._isInit) {
|
|
55
|
+
this.node._isInit = true
|
|
56
|
+
this.node._reset = this.node.value || ''
|
|
57
|
+
}
|
|
65
58
|
}
|
|
66
59
|
}
|
|
67
60
|
|
|
68
61
|
build () {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
62
|
+
TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
|
|
63
|
+
.key(this.node._nid)
|
|
64
|
+
.maxLength(Number(this.node._attrs?.maxlength) || null)
|
|
65
|
+
.placeholderColor(getPlaceholderColor(this.node))
|
|
66
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
67
|
+
.textStyle(this.node?.hmStyle)
|
|
68
|
+
.textAttr(getAttributes(this.node))
|
|
69
|
+
.onChange((value: string) => {
|
|
70
|
+
const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
|
|
71
|
+
|
|
72
|
+
this.value = value
|
|
73
|
+
this.node?.updateFormWidgetValue(value)
|
|
74
|
+
eventHandler(event, 'input', this.node)
|
|
75
|
+
})
|
|
76
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
77
|
+
.onBlur(() => {
|
|
78
|
+
const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
|
|
79
|
+
eventHandler(event, 'blur', this.node)
|
|
80
|
+
})
|
|
81
|
+
.onFocus(() => {
|
|
82
|
+
const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
|
|
83
|
+
|
|
84
|
+
eventHandler(event, 'focus', this.node)
|
|
85
|
+
})
|
|
86
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
87
|
+
if (this.node) {
|
|
88
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
89
|
+
}
|
|
90
|
+
}))
|
|
91
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
100
92
|
}
|
|
101
93
|
}
|
|
@@ -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] }
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { bindAnimation } from './helper'
|
|
1
|
+
import { TaroAny, TaroElement } from '@tarojs/runtime'
|
|
4
2
|
|
|
5
3
|
export class DynamicCenter {
|
|
6
|
-
|
|
7
4
|
install (node: TaroElement, parentNode: TaroElement) {
|
|
8
5
|
if (!parentNode._isCompileMode) return
|
|
9
6
|
|
|
@@ -14,7 +11,7 @@ export class DynamicCenter {
|
|
|
14
11
|
if (!node._isCompileMode || !node._instance) return
|
|
15
12
|
|
|
16
13
|
if (node._attrs?._dynamicID) {
|
|
17
|
-
node._instance[node._attrs._dynamicID] =
|
|
14
|
+
node._instance[node._attrs._dynamicID] = new TaroElement('Ignore')
|
|
18
15
|
}
|
|
19
16
|
node._instance = null
|
|
20
17
|
}
|
|
@@ -25,13 +22,7 @@ export class DynamicCenter {
|
|
|
25
22
|
const dynamicID = node._attrs?._dynamicID
|
|
26
23
|
|
|
27
24
|
// dynamicID 只是为了更新到精准的 node
|
|
28
|
-
|
|
29
|
-
initComponentNodeInfo(component, node)
|
|
30
|
-
bindInstanceToNode(node, component)
|
|
31
|
-
bindFocus(node)
|
|
32
|
-
bindAnimation(node)
|
|
33
|
-
bindScrollTo(node, component)
|
|
34
|
-
|
|
25
|
+
node._instance = component
|
|
35
26
|
node._isCompileMode = true
|
|
36
27
|
|
|
37
28
|
if (dynamicID) {
|
|
@@ -45,4 +36,4 @@ export class DynamicCenter {
|
|
|
45
36
|
this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
|
|
46
37
|
}
|
|
47
38
|
}
|
|
48
|
-
}
|
|
39
|
+
}
|
|
@@ -1,21 +1,89 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TaroElement, HarmonyStyle } from '@tarojs/runtime'
|
|
2
|
+
import { isUndefined } from '@tarojs/shared'
|
|
3
|
+
import { getNormalAttributes } from './styles.ets'
|
|
4
|
+
|
|
5
|
+
interface IFlexOptions {
|
|
6
|
+
direction: FlexDirection,
|
|
7
|
+
justifyContent: FlexAlign,
|
|
8
|
+
alignItems: ItemAlign,
|
|
9
|
+
wrap?: FlexWrap,
|
|
10
|
+
alignContent?: FlexAlign
|
|
11
|
+
}
|
|
2
12
|
|
|
3
13
|
class FlexManager {
|
|
4
|
-
static
|
|
5
|
-
|
|
14
|
+
static isFlexNode (node: TaroElement): boolean {
|
|
15
|
+
return !!node.hmStyle?.display?.includes('flex')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
|
|
19
|
+
if (direction === FlexDirection.Column) {
|
|
20
|
+
switch (alignItems) {
|
|
21
|
+
case ItemAlign.Center:
|
|
22
|
+
return HorizontalAlign.Center
|
|
23
|
+
case ItemAlign.End:
|
|
24
|
+
return HorizontalAlign.End
|
|
25
|
+
default:
|
|
26
|
+
return HorizontalAlign.Start
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
switch (alignItems) {
|
|
30
|
+
case ItemAlign.Center:
|
|
31
|
+
return VerticalAlign.Center
|
|
32
|
+
case ItemAlign.End:
|
|
33
|
+
return VerticalAlign.Bottom
|
|
34
|
+
default:
|
|
35
|
+
return VerticalAlign.Top
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
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
|
+
}
|
|
6
46
|
|
|
7
|
-
|
|
47
|
+
static flexOptions (node: TaroElement): IFlexOptions {
|
|
48
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
|
|
49
|
+
const isFlex = FlexManager.isFlexNode(node)
|
|
50
|
+
let flexDirection = hmStyle.flexDirection
|
|
8
51
|
if (!flexDirection && flexDirection !== 0) {
|
|
9
52
|
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
10
53
|
}
|
|
11
54
|
|
|
12
55
|
return {
|
|
56
|
+
alignItems: isFlex ? (isUndefined(hmStyle.alignItems) ? ItemAlign.Start : hmStyle.alignItems) : ItemAlign.Start,
|
|
57
|
+
justifyContent: isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start,
|
|
13
58
|
direction: flexDirection,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
59
|
+
wrap: isFlex ? hmStyle.flexWrap: FlexWrap.NoWrap,
|
|
60
|
+
alignContent: isFlex ? hmStyle.alignContent: FlexAlign.Start
|
|
61
|
+
}
|
|
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
|
|
18
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
|
|
19
87
|
}
|
|
20
88
|
}
|
|
21
89
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VIEW } from '@tarojs/runtime/dist/runtime.esm'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import { getNormalAttributes, getFontAttributes, getStyleAttr } from './styles'
|
|
4
|
+
|
|
5
|
+
import type { TFunc } from '@tarojs/runtime/dist/runtime.esm'
|
|
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> = {}
|
|
@@ -20,7 +22,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
|
|
|
20
22
|
return styleObj
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
export function shouldBindEvent (cb:
|
|
25
|
+
export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames: string[], disabled = false) {
|
|
24
26
|
if (!node || node._attrs?.disabled || disabled) return null
|
|
25
27
|
if (!node.__listeners) {
|
|
26
28
|
return null
|
|
@@ -31,9 +33,20 @@ export function shouldBindEvent (cb: Func, node: TaroElement, eventNames: string
|
|
|
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 }
|