@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.
Files changed (139) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/device/memory.ts +10 -3
  5. package/dist/apis/framework/index.ts +1 -5
  6. package/dist/apis/index.ts +27 -17
  7. package/dist/apis/media/image/index.ts +1 -1
  8. package/dist/apis/media/video/VideoContext.ts +56 -7
  9. package/dist/apis/media/video/index.ts +3 -2
  10. package/dist/apis/network/request.ts +5 -5
  11. package/dist/apis/route/index.ts +15 -0
  12. package/dist/apis/storage/index.ts +146 -78
  13. package/dist/apis/ui/animation/animation.ts +71 -29
  14. package/dist/apis/ui/background.ts +2 -1
  15. package/dist/apis/ui/interaction/index.ts +42 -59
  16. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  17. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  18. package/dist/apis/ui/scroll/index.ts +5 -5
  19. package/dist/apis/ui/tab-bar.ts +3 -3
  20. package/dist/apis/utils/index.ts +1 -1
  21. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  22. package/dist/apis/wxml/index.ts +2 -0
  23. package/dist/apis/wxml/selectorQuery.ts +26 -13
  24. package/dist/components-harmony-ets/button.ets +68 -68
  25. package/dist/components-harmony-ets/canvas.ets +51 -0
  26. package/dist/components-harmony-ets/checkbox.ets +81 -102
  27. package/dist/components-harmony-ets/form.ets +54 -45
  28. package/dist/components-harmony-ets/icon.ets +34 -50
  29. package/dist/components-harmony-ets/image.ets +35 -45
  30. package/dist/components-harmony-ets/index.ets +92 -0
  31. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  32. package/dist/components-harmony-ets/input.ets +51 -67
  33. package/dist/components-harmony-ets/label.ets +73 -53
  34. package/dist/components-harmony-ets/listView.ets +26 -0
  35. package/dist/components-harmony-ets/movableArea.ets +124 -0
  36. package/dist/components-harmony-ets/movableView.ets +93 -0
  37. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  38. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  39. package/dist/components-harmony-ets/picker.ets +74 -77
  40. package/dist/components-harmony-ets/progress.ets +52 -0
  41. package/dist/components-harmony-ets/pseudo.ets +80 -0
  42. package/dist/components-harmony-ets/radio.ets +82 -104
  43. package/dist/components-harmony-ets/richText.ets +20 -68
  44. package/dist/components-harmony-ets/scrollList.ets +94 -0
  45. package/dist/components-harmony-ets/scrollView.ets +67 -103
  46. package/dist/components-harmony-ets/slider.ets +23 -47
  47. package/dist/components-harmony-ets/stickySection.ets +42 -0
  48. package/dist/components-harmony-ets/style.ets +396 -0
  49. package/dist/components-harmony-ets/swiper.ets +64 -53
  50. package/dist/components-harmony-ets/switch.ets +44 -55
  51. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  52. package/dist/components-harmony-ets/text.ets +134 -75
  53. package/dist/components-harmony-ets/textArea.ets +54 -62
  54. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  55. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  56. package/dist/components-harmony-ets/utils/flexManager.ets +76 -8
  57. package/dist/components-harmony-ets/utils/helper.ets +20 -7
  58. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  59. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  60. package/dist/components-harmony-ets/utils/index.ts +54 -50
  61. package/dist/components-harmony-ets/utils/styles.ets +178 -63
  62. package/dist/components-harmony-ets/video.ets +37 -54
  63. package/dist/components-harmony-ets/view.ets +63 -94
  64. package/dist/components-harmony-ets/webView.ets +56 -0
  65. package/dist/index.d.ts +152 -0
  66. package/dist/index.js +199 -58
  67. package/dist/index.js.map +1 -1
  68. package/dist/runtime-ets/bom/document.ts +6 -4
  69. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  70. package/dist/runtime-ets/bom/window.ts +9 -2
  71. package/dist/runtime-ets/current.ts +3 -0
  72. package/dist/runtime-ets/dom/bind.ts +28 -12
  73. package/dist/runtime-ets/dom/class-list.ts +2 -2
  74. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  75. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +29 -19
  76. package/dist/runtime-ets/dom/document.ts +22 -8
  77. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  78. package/dist/runtime-ets/dom/element/element.ts +334 -57
  79. package/dist/runtime-ets/dom/element/form.ts +32 -26
  80. package/dist/runtime-ets/dom/element/index.ts +33 -2
  81. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  82. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  83. package/dist/runtime-ets/dom/element/normal.ts +36 -8
  84. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  85. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  86. package/dist/runtime-ets/dom/element/text.ts +1 -8
  87. package/dist/runtime-ets/dom/element/video.ts +5 -4
  88. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  89. package/dist/runtime-ets/dom/event.ts +2 -4
  90. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  91. package/dist/runtime-ets/dom/node.ts +62 -27
  92. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  93. package/dist/runtime-ets/dom/stylesheet/index.ts +98 -518
  94. package/dist/runtime-ets/dom/stylesheet/type.ts +92 -17
  95. package/dist/runtime-ets/dom/stylesheet/util.ts +74 -16
  96. package/dist/runtime-ets/index.ts +2 -2
  97. package/dist/runtime-ets/interface/event.ts +3 -2
  98. package/dist/runtime-ets/utils/index.ts +77 -12
  99. package/dist/runtime-ets/utils/info.ts +4 -2
  100. package/dist/runtime-framework/react/app.ts +17 -22
  101. package/dist/runtime-framework/react/hooks.ts +3 -4
  102. package/dist/runtime-framework/react/index.ts +1 -2
  103. package/dist/runtime-framework/react/native-page.ts +421 -0
  104. package/dist/runtime-framework/react/page.ts +4 -9
  105. package/dist/runtime-framework/solid/app.ts +25 -45
  106. package/dist/runtime-framework/solid/connect.ts +21 -3
  107. package/dist/runtime-framework/solid/hooks.ts +17 -12
  108. package/dist/runtime-framework/solid/index.ts +6 -2
  109. package/dist/runtime-framework/solid/page.ts +84 -30
  110. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  111. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  112. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  113. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  114. package/dist/runtime-utils.d.ts +827 -0
  115. package/dist/runtime-utils.js +510 -237
  116. package/dist/runtime-utils.js.map +1 -1
  117. package/dist/runtime.d.ts +1 -0
  118. package/dist/runtime.js +510 -237
  119. package/dist/runtime.js.map +1 -1
  120. package/index.js +3 -1
  121. package/package.json +14 -15
  122. package/static/media/cancel.svg +1 -0
  123. package/static/media/circle.svg +1 -0
  124. package/static/media/clear.svg +1 -0
  125. package/static/media/download.svg +1 -0
  126. package/static/media/info.svg +1 -0
  127. package/static/media/info_circle.svg +1 -0
  128. package/static/media/search.svg +1 -0
  129. package/static/media/success.svg +1 -0
  130. package/static/media/success_no_circle.svg +1 -0
  131. package/static/media/taro_arrow_left.svg +1 -0
  132. package/static/media/taro_home.svg +1 -0
  133. package/static/media/waiting.svg +1 -0
  134. package/static/media/warn.svg +1 -0
  135. package/types/harmony.d.ts +4 -0
  136. package/types/index.d.ts +4 -0
  137. package/types/runtime.d.ts +3 -1
  138. package/dist/runtime-ets/utils/bind.ts +0 -24
  139. /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, getNormalAttributes, getFontAttributes, shouldBindEvent } from './utils/helper'
8
+ import { getNodeThresholds, getStyleAttr, shouldBindEvent, getNormalAttributes } from './utils/helper'
6
9
 
7
- import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, TaroTextStyleType, TaroStyleType } from '@tarojs/runtime'
10
+ import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, HarmonyStyle } from '@tarojs/runtime'
8
11
 
9
- @Extend(Text)
10
- function textNormalStyle (style: TaroStyleType) {
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
- @Extend(Text)
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
- @Extend(Text)
55
- function textSpecialFontStyle(attr: TaroTextStyleType) {
56
- .textAlign(attr.textAlign)
57
- .textOverflow(attr.textOverflow)
58
- .maxLines(attr.maxLines)
59
- .letterSpacing(attr.letterSpacing)
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
- return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
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
- export default function TaroText (node: TaroTextElement) {
70
- if (node.nodeType === NodeType.TEXT_NODE && node.parentNode) {
71
- if ((node.parentNode as TaroElement).tagName === 'BUTTON') {
72
- Text(node.textContent)
73
- .textNormalFontStyle(getNormalAttributes(node.parentNode as TaroElement))
74
- .textSpecialFontStyle(getFontAttributes(node.parentNode as TaroElement))
75
- .fontSize((node.parentNode as TaroButtonElement).hmStyle.fontSize || getButtonFontSize((node.parentNode as TaroButtonElement)))
76
- .fontColor((node.parentNode as TaroButtonElement).hmStyle.color || getButtonColor(node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((node.parentNode as TaroButtonElement)._attrs.type).text))
77
- } else {
78
- Text(node.textContent)
79
- .textNormalFontStyle(getNormalAttributes(node.parentNode as TaroElement))
80
- .textSpecialFontStyle(getFontAttributes(node.parentNode as TaroElement))
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 { getNodeThresholds, getNormalAttributes, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
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: TaroTextStyleType) {
22
+ function textAttr(attr: TextareaAttrs) {
45
23
  .textAlign(attr.textAlign)
46
- .maxLines(attr.maxLines)
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
- node: TaroTextAreaElement | null = null
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
- if (this.node) {
70
- TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
71
- .key(this.node._nid)
72
- .maxLength(Number(this.node._attrs?.maxlength) || null)
73
- .placeholderColor(getPlaceholderColor(this.node))
74
- .textStyle(getNormalAttributes(this.node))
75
- .textAttr(getFontAttributes(this.node))
76
- .onChange((value: string) => {
77
- const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
78
-
79
- this.value = value
80
- this.node?.updateFormWidgetValue(value)
81
- eventHandler(event, 'input', this.node)
82
- })
83
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
84
- .onBlur(() => {
85
- const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
86
- eventHandler(event, 'blur', this.node)
87
- })
88
- .onFocus(() => {
89
- const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
90
-
91
- eventHandler(event, 'focus', this.node)
92
- })
93
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
94
- if (this.node) {
95
- this.node._nodeInfo.areaInfo = res[1]
96
- }
97
- }))
98
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
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 { bindFocus, bindInstanceToNode, bindScrollTo, initComponentNodeInfo, TaroAny, TaroElement } from '@tarojs/runtime'
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] = null
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
- // 而为了让半编译模板中每个 node 都能响应 api 的调用,因此 initComponentNodeInfo、bindInstanceToNode 和各种 bindAttribute 都需要执行
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 { TaroAny, TaroElement } from '@tarojs/runtime'
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 flexOptions (node: TaroElement): FlexOptions {
5
- const hmStyle = node.hmStyle
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
- let flexDirection = hmStyle.direction
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
- justifyContent: hmStyle.justifyContent,
15
- alignItems: hmStyle.alignItems,
16
- wrap: hmStyle.flexWrap,
17
- alignContent: hmStyle.alignContent,
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 { getNormalAttributes, getFontAttributes } from './styles'
1
+ import { VIEW } from '@tarojs/runtime/dist/runtime.esm'
2
2
 
3
- import type { Func } from '@tarojs/runtime/dist/runtime.esm'
4
- import type { TaroElement } from '@tarojs/runtime'
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: Func, node: TaroElement, eventNames: string[], disabled = false) {
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
- if (!node) return null
36
+ return node?._nodeInfo?.thresholds || null
37
+ }
35
38
 
36
- return node?._nodeInfo.thresholds || null
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 }
@@ -99,5 +99,4 @@ function parseTag(htmlString, startIndex) {
99
99
  return tag
100
100
  }
101
101
 
102
-
103
- export default parseHTML
102
+ export default parseHTML
@@ -15,7 +15,7 @@ function buildDomTree(dom: TTreeNode) {
15
15
  case 'span': tagName = 'text'; break
16
16
  }
17
17
  if (!tagName) return null
18
-
18
+
19
19
  const ele = document.createElement(tagName)
20
20
  attributes && Object.keys(attributes).forEach(key => {
21
21
  if (key === 'style') {