@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121

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 (143) hide show
  1. package/dist/apis/base/system.ts +60 -25
  2. package/dist/apis/base/weapp/life-cycle.ts +1 -1
  3. package/dist/apis/canvas/index.ts +10 -1
  4. package/dist/apis/device/clipboard.ts +23 -8
  5. package/dist/apis/framework/index.ts +2 -6
  6. package/dist/apis/index.ts +25 -17
  7. package/dist/apis/media/image/index.ts +169 -17
  8. package/dist/apis/route/index.ts +1 -2
  9. package/dist/apis/storage/index.ts +135 -131
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +3 -2
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +2 -2
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +6 -6
  16. package/dist/apis/ui/tab-bar.ts +4 -5
  17. package/dist/apis/utils/index.ts +20 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/selectorQuery.ts +26 -13
  21. package/dist/components-harmony-ets/button.ets +36 -9
  22. package/dist/components-harmony-ets/canvas.ets +51 -0
  23. package/dist/components-harmony-ets/checkbox.ets +69 -60
  24. package/dist/components-harmony-ets/form.ets +33 -15
  25. package/dist/components-harmony-ets/icon.ets +16 -8
  26. package/dist/components-harmony-ets/image.ets +22 -6
  27. package/dist/components-harmony-ets/index.ets +39 -0
  28. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  29. package/dist/components-harmony-ets/input.ets +63 -37
  30. package/dist/components-harmony-ets/label.ets +43 -21
  31. package/dist/components-harmony-ets/listView.ets +32 -0
  32. package/dist/components-harmony-ets/movableArea.ets +110 -51
  33. package/dist/components-harmony-ets/movableView.ets +74 -47
  34. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  35. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  36. package/dist/components-harmony-ets/picker.ets +36 -33
  37. package/dist/components-harmony-ets/progress.ets +31 -24
  38. package/dist/components-harmony-ets/pseudo.ets +80 -0
  39. package/dist/components-harmony-ets/radio.ets +75 -66
  40. package/dist/components-harmony-ets/richText.ets +4 -25
  41. package/dist/components-harmony-ets/scrollList.ets +108 -0
  42. package/dist/components-harmony-ets/scrollView.ets +46 -42
  43. package/dist/components-harmony-ets/slider.ets +19 -15
  44. package/dist/components-harmony-ets/stickySection.ets +42 -0
  45. package/dist/components-harmony-ets/style.ets +386 -129
  46. package/dist/components-harmony-ets/swiper.ets +42 -5
  47. package/dist/components-harmony-ets/switch.ets +36 -32
  48. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  49. package/dist/components-harmony-ets/text.ets +102 -46
  50. package/dist/components-harmony-ets/textArea.ets +49 -34
  51. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  52. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  53. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  54. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  55. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  56. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  57. package/dist/components-harmony-ets/utils/index.ts +54 -50
  58. package/dist/components-harmony-ets/utils/styles.ets +169 -91
  59. package/dist/components-harmony-ets/video.ets +28 -20
  60. package/dist/components-harmony-ets/view.ets +45 -39
  61. package/dist/components-harmony-ets/webView.ets +6 -5
  62. package/dist/index.d.ts +152 -0
  63. package/dist/index.js +73 -44
  64. package/dist/index.js.map +1 -1
  65. package/dist/runtime-ets/bom/URL.ts +2 -0
  66. package/dist/runtime-ets/bom/document.ts +5 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
  68. package/dist/runtime-ets/bom/history.ts +1 -0
  69. package/dist/runtime-ets/bom/location.ts +1 -0
  70. package/dist/runtime-ets/bom/navigator.ts +1 -21
  71. package/dist/runtime-ets/bom/raf.ts +1 -37
  72. package/dist/runtime-ets/bom/window.ts +10 -4
  73. package/dist/runtime-ets/constant.ts +17 -10
  74. package/dist/runtime-ets/current.ts +5 -2
  75. package/dist/runtime-ets/dom/bind.ts +28 -12
  76. package/dist/runtime-ets/dom/class-list.ts +2 -2
  77. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  78. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  79. package/dist/runtime-ets/dom/document.ts +9 -12
  80. package/dist/runtime-ets/dom/element/canvas.ts +137 -0
  81. package/dist/runtime-ets/dom/element/element.ts +379 -55
  82. package/dist/runtime-ets/dom/element/form.ts +26 -22
  83. package/dist/runtime-ets/dom/element/index.ts +22 -2
  84. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  85. package/dist/runtime-ets/dom/element/movableView.ts +238 -2
  86. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  87. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  88. package/dist/runtime-ets/dom/element/text.ts +0 -8
  89. package/dist/runtime-ets/dom/element/video.ts +4 -4
  90. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  91. package/dist/runtime-ets/dom/event-source.ts +1 -0
  92. package/dist/runtime-ets/dom/event.ts +3 -5
  93. package/dist/runtime-ets/dom/eventTarget.ts +3 -4
  94. package/dist/runtime-ets/dom/node.ts +53 -22
  95. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  96. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  97. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  98. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  99. package/dist/runtime-ets/emitter/emitter.ts +1 -0
  100. package/dist/runtime-ets/env.ts +1 -0
  101. package/dist/runtime-ets/index.ts +23 -7
  102. package/dist/runtime-ets/interface/event.ts +1 -1
  103. package/dist/runtime-ets/interface/index.ts +6 -0
  104. package/dist/runtime-ets/utils/index.ts +78 -19
  105. package/dist/runtime-ets/utils/info.ts +2 -2
  106. package/dist/runtime-ets/utils/router.ts +9 -0
  107. package/dist/runtime-framework/react/app.ts +15 -11
  108. package/dist/runtime-framework/react/hooks.ts +1 -2
  109. package/dist/runtime-framework/react/index.ts +0 -2
  110. package/dist/runtime-framework/react/native-page.ts +217 -81
  111. package/dist/runtime-framework/react/page.ts +4 -10
  112. package/dist/runtime-framework/react/utils/index.ts +3 -3
  113. package/dist/runtime-framework/solid/app.ts +29 -46
  114. package/dist/runtime-framework/solid/connect.ts +21 -3
  115. package/dist/runtime-framework/solid/hooks.ts +16 -11
  116. package/dist/runtime-framework/solid/index.ts +6 -2
  117. package/dist/runtime-framework/solid/page.ts +84 -31
  118. package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
  119. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  120. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  121. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  122. package/dist/runtime-utils.d.ts +827 -0
  123. package/dist/runtime-utils.js +574 -285
  124. package/dist/runtime-utils.js.map +1 -1
  125. package/dist/runtime.d.ts +1 -0
  126. package/dist/runtime.js +574 -285
  127. package/dist/runtime.js.map +1 -1
  128. package/index.js +3 -1
  129. package/package.json +14 -15
  130. package/static/media/cancel.svg +1 -1
  131. package/static/media/circle.svg +1 -1
  132. package/static/media/clear.svg +1 -1
  133. package/static/media/download.svg +1 -1
  134. package/static/media/info.svg +1 -1
  135. package/static/media/info_circle.svg +1 -1
  136. package/static/media/search.svg +1 -1
  137. package/static/media/success.svg +1 -1
  138. package/static/media/success_no_circle.svg +1 -1
  139. package/static/media/warn.svg +1 -1
  140. package/types/harmony.d.ts +5 -0
  141. package/types/index.d.ts +4 -0
  142. package/types/runtime.d.ts +1 -1
  143. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,14 +1,13 @@
1
1
  import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, TaroPickerElement, createTaroEvent } from '@tarojs/runtime'
2
- import { createLazyChildren } from './render'
3
2
  import commonStyleModify from './style'
4
3
  import { getSingleSelector, getMultiSelector } from './utils'
5
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
5
  import { FlexManager } from './utils/flexManager'
7
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
6
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
7
 
9
8
  import type { TaroAny, TaroEvent } from '@tarojs/runtime'
10
9
 
11
- import { PickerDateProps, PickerMultiSelectorProps, PickerSelectorProps, PickerTimeProps } from './types'
10
+ import { PickerDateProps, PickerMultiSelectorProps, PickerSelectorProps, PickerTimeProps } from '@tarojs/components/types'
12
11
 
13
12
  interface TimeRange {
14
13
  startHH: number
@@ -146,9 +145,10 @@ export struct PickerView {
146
145
  color: '#000'
147
146
  })
148
147
  .canLoop(false)
149
- .attributeModifier(commonStyleModify.setNode(this.node))
150
- .width(getNormalAttributes(this.node).width || '100%')
151
- .backgroundColor(getNormalAttributes(this.node).backgroundColor || '#fff')
148
+ .attributeModifier(commonStyleModify.setNode(this.node, {
149
+ width: '100%',
150
+ backgroundColor: '#fff'
151
+ }))
152
152
  .onChange((_, index) => {
153
153
  this.node?.updateFormWidgetValue(index)
154
154
  })
@@ -158,9 +158,10 @@ export struct PickerView {
158
158
  color: '#000'
159
159
  })
160
160
  .canLoop(false)
161
- .attributeModifier(commonStyleModify.setNode(this.node))
162
- .width(getNormalAttributes(this.node).width || '100%')
163
- .backgroundColor(getNormalAttributes(this.node).backgroundColor || '#fff')
161
+ .attributeModifier(commonStyleModify.setNode(this.node, {
162
+ width: '100%',
163
+ backgroundColor: '#fff'
164
+ }))
164
165
  .onChange((_, index) => {
165
166
  if (index instanceof Array) {
166
167
  this.node?.updateFormWidgetValue(index)
@@ -187,9 +188,10 @@ export struct PickerView {
187
188
  .selectedTextStyle({
188
189
  color: '#000'
189
190
  })
190
- .attributeModifier(commonStyleModify.setNode(this.node))
191
- .width(getNormalAttributes(this.node).width || '100%')
192
- .backgroundColor(getNormalAttributes(this.node).backgroundColor || '#fff')
191
+ .attributeModifier(commonStyleModify.setNode(this.node, {
192
+ width: '100%',
193
+ backgroundColor: '#fff'
194
+ }))
193
195
  .onDateChange(value => {
194
196
  const data = value.toLocaleDateString().split('/')
195
197
  const day = data[1]
@@ -203,9 +205,10 @@ export struct PickerView {
203
205
  color: '#000'
204
206
  })
205
207
  .canLoop(false)
206
- .attributeModifier(commonStyleModify.setNode(this.node))
207
- .width(getNormalAttributes(this.node).width || '100%')
208
- .backgroundColor(getNormalAttributes(this.node).backgroundColor || '#fff')
208
+ .attributeModifier(commonStyleModify.setNode(this.node, {
209
+ width: '100%',
210
+ backgroundColor: '#fff'
211
+ }))
209
212
  .onChange((value) => {
210
213
  this.node?.updateFormWidgetValue(`${('00'+value[0]).slice(-2)}:${('00'+value[1]).slice(-2)}`)
211
214
  })
@@ -222,6 +225,8 @@ export struct PickerView {
222
225
 
223
226
  @Component
224
227
  export default struct TaroPicker {
228
+ @Builder customBuilder() {}
229
+ @BuilderParam createLazyChildren: (node: TaroPickerElement, layer?: number) => void = this.customBuilder
225
230
  @ObjectLink node: TaroPickerElement
226
231
 
227
232
  aboutToAppear () {
@@ -293,7 +298,7 @@ export default struct TaroPicker {
293
298
  .onClick((e: ClickEvent) => {
294
299
  eventHandler(e, 'click', this.node)
295
300
  })
296
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
301
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
297
302
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
298
303
  if (this.node) {
299
304
  this.node._nodeInfo.areaInfo = res[1]
@@ -306,24 +311,22 @@ export default struct TaroPicker {
306
311
  }
307
312
 
308
313
  build() {
309
- if (this.node) {
310
- if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
311
- Row() {
312
- createLazyChildren(this.node)
313
- }
314
- .defaultEvent()
315
- .visibleChangeEvent()
316
- .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
317
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
318
- } else {
319
- Column() {
320
- createLazyChildren(this.node)
321
- }
322
- .defaultEvent()
323
- .visibleChangeEvent()
324
- .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
325
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
314
+ if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
315
+ Row() {
316
+ this.createLazyChildren(this.node, 0)
317
+ }
318
+ .defaultEvent()
319
+ .visibleChangeEvent()
320
+ .alignItems(FlexManager.alignItems<VerticalAlign>(this.node))
321
+ .justifyContent(FlexManager.justifyContent(this.node))
322
+ } else {
323
+ Column() {
324
+ this.createLazyChildren(this.node, 0)
326
325
  }
326
+ .defaultEvent()
327
+ .visibleChangeEvent()
328
+ .alignItems(FlexManager.alignItems<HorizontalAlign>(this.node))
329
+ .justifyContent(FlexManager.justifyContent(this.node))
327
330
  }
328
331
  }
329
332
  }
@@ -9,36 +9,43 @@ const PROGRESS_DEFAULTINFOFONTSIZE = 16
9
9
 
10
10
  @Component
11
11
  export default struct TaroProgress {
12
+ @Builder customBuilder() {}
13
+ @BuilderParam createLazyChildren: (node: TaroProgressElement, layer?: number) => void = this.customBuilder
12
14
  @ObjectLink node: TaroProgressElement
15
+ @State overwriteStyle: Record<string, TaroAny> = {}
13
16
 
14
- build() {
17
+ aboutToAppear(): void {
15
18
  if (this.node) {
16
- Row({ space: 5 }) {
17
- Progress({
18
- value: parseFloat(this.node.getAttribute('percent')),
19
- type: ProgressType.Linear
19
+ this.node._instance = this
20
+ }
21
+ }
22
+
23
+ build() {
24
+ Row({ space: 5 }) {
25
+ Progress({
26
+ value: parseFloat(this.node.getAttribute('percent')),
27
+ type: ProgressType.Linear
28
+ })
29
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
30
+ .color(this.node.getAttribute('activeColor') ?? PROGRESS_ACTIVECOLOR)
31
+ .backgroundColor(this.node.getAttribute('backgroundColor') ?? PROGRESS_BACKGROUNDCOLOR)
32
+ .style({
33
+ strokeWidth: this.node.getAttribute('strokeWidth'),
34
+ strokeRadius: parseFloat(this.node.getAttribute('borderRadius')),
35
+ enableSmoothEffect: Boolean(this.node.getAttribute('active')),
20
36
  })
21
- .attributeModifier(commonStyleModify.setNode(this.node))
22
- .color(this.node.getAttribute('activeColor') ?? PROGRESS_ACTIVECOLOR)
23
- .backgroundColor(this.node.getAttribute('backgroundColor') ?? PROGRESS_BACKGROUNDCOLOR)
24
- .style({
25
- strokeWidth: this.node.getAttribute('strokeWidth'),
26
- strokeRadius: parseFloat(this.node.getAttribute('borderRadius')),
27
- enableSmoothEffect: Boolean(this.node.getAttribute('active')),
28
- })
29
37
 
30
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
31
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
32
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
33
- if (this.node) {
34
- this.node._nodeInfo.areaInfo = res[1]
35
- }
36
- }))
38
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
39
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
40
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
41
+ if (this.node) {
42
+ this.node._nodeInfo.areaInfo = res[1]
43
+ }
44
+ }))
37
45
 
38
- if (this.node.getAttribute('showInfo')) {
39
- Text(`${this.node.getAttribute('percent')}%`)
40
- .fontSize(this.node.getAttribute('fontSize') ?? PROGRESS_DEFAULTINFOFONTSIZE)
41
- }
46
+ if (this.node.getAttribute('showInfo')) {
47
+ Text(`${this.node.getAttribute('percent')}%`)
48
+ .fontSize(this.node.getAttribute('fontSize') ?? PROGRESS_DEFAULTINFOFONTSIZE)
42
49
  }
43
50
  }
44
51
  }
@@ -0,0 +1,80 @@
1
+ import { getFontAttributes } from './utils/helper'
2
+ import { pseudoModify } from './style'
3
+
4
+ import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroViewElement } from '@tarojs/runtime'
5
+
6
+ @Extend(Flex)
7
+ function flexAttrs (style: TaroStyleType) {
8
+ .constraintSize({
9
+ minWidth: style.minWidth,
10
+ maxWidth: style.maxWidth,
11
+ minHeight: style.minHeight || style.height,
12
+ maxHeight: style.maxHeight
13
+ })
14
+ }
15
+
16
+
17
+ @Extend(Text)
18
+ function textNormalFontStyle (style: TaroStyleType) {
19
+ .id(style.id)
20
+ .key(style.id)
21
+ .opacity(style.opacity)
22
+ .fontColor(style.color)
23
+ .fontSize(style.fontSize)
24
+ .fontWeight(style.fontWeight)
25
+ .fontStyle(style.fontStyle)
26
+ .fontFamily(style.fontFamily)
27
+ .decoration({
28
+ type: style.textDecoration?.type || TextDecorationType.None,
29
+ color: style.color
30
+ })
31
+ }
32
+
33
+ @Extend(Text)
34
+ function textSpecialFontStyle(attr: TaroTextStyleType) {
35
+ .textAlign(attr.textAlign)
36
+ .align(attr.verticalAlign)
37
+ .textOverflow(attr.textOverflow)
38
+ .maxLines(attr.WebkitLineClamp)
39
+ .letterSpacing(attr.letterSpacing)
40
+ .lineHeight(attr.lineHeight)
41
+ }
42
+
43
+ @Component
44
+ export default struct PseduoChildren {
45
+ @Builder customBuilder() {}
46
+ @BuilderParam createLazyChildren: (node: TaroAny, layer?: number) => void = this.customBuilder
47
+ @ObjectLink node: TaroViewElement
48
+
49
+ build () {
50
+ if (true) {
51
+ // 伪类::Before
52
+ if (this.node._pseudo_before) {
53
+ if (this.node._pseudo_before?.hmStyle.content) {
54
+ Text(this.node._pseudo_before.hmStyle.content)
55
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_before.hmStyle))
56
+ .textNormalFontStyle(this.node._pseudo_before.hmStyle || {})
57
+ .textSpecialFontStyle(getFontAttributes(this.node))
58
+ } else {
59
+ Flex() {}
60
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_before.hmStyle || {}))
61
+ .flexAttrs(this.node._pseudo_before.hmStyle || {})
62
+ }
63
+ }
64
+ this.createLazyChildren(this.node, 0)
65
+ // 伪类::After
66
+ if (this.node._pseudo_after) {
67
+ if (this.node._pseudo_after?.hmStyle.content) {
68
+ Text(this.node._pseudo_after.hmStyle.content)
69
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_after.hmStyle))
70
+ .textNormalFontStyle(this.node._pseudo_after.hmStyle || {})
71
+ .textSpecialFontStyle(getFontAttributes(this.node))
72
+ } else {
73
+ Flex() {}
74
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_after.hmStyle || {}))
75
+ .flexAttrs(this.node._pseudo_after.hmStyle || {})
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
@@ -1,22 +1,23 @@
1
- import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
1
+ import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import commonStyleModify from './style'
4
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
5
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
5
  import { FlexManager } from './utils/flexManager'
7
6
  import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
7
 
9
- import { TaroEvent, TaroAny, HarmonyType, TaroRadioGroupElement, TaroRadioElement } from '@tarojs/runtime'
8
+ import type { HarmonyType, TaroAny, TaroEvent, TaroRadioElement, TaroRadioGroupElement } from '@tarojs/runtime'
10
9
 
11
10
  interface RadioAttrs {
12
11
  radioStyle?: HarmonyType.RadioStyle
13
12
  themeStyles?: boolean
13
+ disabled?: boolean
14
14
  }
15
15
 
16
16
  @Extend(Radio)
17
17
  function radioAttr (attr: RadioAttrs) {
18
18
  .radioStyle(attr.radioStyle)
19
- .themeStyles(attr.themeStyles)
19
+ .themeStyles(attr.themeStyles || false)
20
+ .enabled(!attr.disabled)
20
21
  }
21
22
 
22
23
  function getAttributes (node: TaroRadioElement): RadioAttrs {
@@ -25,6 +26,7 @@ function getAttributes (node: TaroRadioElement): RadioAttrs {
25
26
  checkedBackgroundColor: node._attrs.color || '#1aad19'
26
27
  }
27
28
  radioAttrs.themeStyles = !!node._attrs.disabled
29
+ radioAttrs.disabled = !!node._attrs.disabled
28
30
  return radioAttrs
29
31
  }
30
32
 
@@ -35,59 +37,61 @@ function themeStyles(isDisabled: boolean) {
35
37
 
36
38
  @Component
37
39
  export struct TaroRadio {
40
+ @Builder customBuilder() {}
41
+ @BuilderParam createLazyChildren: (node: TaroRadioElement, layer?: number) => void = this.customBuilder
38
42
  @ObjectLink node: TaroRadioElement
43
+ @State overwriteStyle: Record<string, TaroAny> = {}
39
44
 
40
45
  aboutToAppear () {
41
46
  if (this.node && !this.node._isInit) {
42
47
  this.node._isInit = true
48
+ this.node._instance = this
43
49
  this.node._reset = this.node.checked || false
44
50
  }
45
51
  }
46
52
 
47
53
  build () {
48
- if (this.node) {
49
- Stack() {
50
- Row() {
51
- Radio({
52
- group: this.node.group || this.node.parentNode?._nid || '',
53
- value: this.node.value || '',
54
- })
55
- .checked(this.node.checked)
56
- .attributeModifier(commonStyleModify.setNode(this.node))
57
- .radioAttr(getAttributes(this.node))
58
- .onChange((value: boolean) => {
59
- if (this.node) {
60
- if (!!this.node?._attrs.disabled) {
61
- this.node.updateComponent()
62
- } else {
63
- this.node.updateCheckedValue(value)
64
-
65
- if (value) {
66
- const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
67
- eventHandler(event, 'change', this.node)
68
- }
54
+ Stack() {
55
+ Row() {
56
+ Radio({
57
+ group: this.node.group || this.node.parentNode?._nid.toString() || '',
58
+ value: this.node.value || '',
59
+ })
60
+ .checked(this.node.checked)
61
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
62
+ .radioAttr(getAttributes(this.node))
63
+ .onChange((value: boolean) => {
64
+ if (this.node) {
65
+ if (!!this.node?._attrs.disabled) {
66
+ this.node.updateComponent()
67
+ } else {
68
+ this.node.updateCheckedValue(value)
69
+
70
+ if (value) {
71
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
72
+ eventHandler(event, 'change', this.node)
69
73
  }
70
74
  }
71
- })
72
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
73
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
74
- if (this.node) {
75
- this.node._nodeInfo.areaInfo = res[1]
76
- }
77
- }))
78
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
79
- Text(this.node.textContent)
80
- .textAlign(TextAlign.Center)
81
- .opacity(!!this.node?._attrs.disabled ? 0.4 : 1)
82
- }
83
- .onClick(() => {
84
- if (this.node) {
85
- if (!this.node._checked && !this.node?._attrs.disabled) {
86
- this.node.checked = !this.node.checked
87
75
  }
88
- }
89
- })
76
+ })
77
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
78
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
79
+ if (this.node) {
80
+ this.node._nodeInfo.areaInfo = res[1]
81
+ }
82
+ }))
83
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
84
+ Text(this.node.textContent)
85
+ .textAlign(TextAlign.Center)
86
+ .opacity(!!this.node?._attrs.disabled ? 0.4 : 1)
90
87
  }
88
+ .onClick(() => {
89
+ if (this.node) {
90
+ if (!this.node._checked && !this.node?._attrs.disabled) {
91
+ this.node.checked = !this.node.checked
92
+ }
93
+ }
94
+ })
91
95
  }
92
96
  }
93
97
  }
@@ -95,7 +99,10 @@ export struct TaroRadio {
95
99
 
96
100
  @Component
97
101
  export struct TaroRadioGroup {
102
+ @Builder customBuilder() {}
103
+ @BuilderParam createLazyChildren: (node: TaroRadioGroupElement, layer?: number) => void = this.customBuilder
98
104
  @ObjectLink node: TaroRadioGroupElement
105
+ @State overwriteStyle: Record<string, TaroAny> = {}
99
106
 
100
107
  @Styles visibleChangeEvent () {
101
108
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
@@ -103,9 +110,10 @@ export struct TaroRadioGroup {
103
110
 
104
111
  aboutToAppear () {
105
112
  if (this.node) {
113
+ this.node._instance = this
106
114
  const childList = this.node.getElementsByTagName<TaroRadioElement>('RADIO')
107
115
  childList.forEach(element => {
108
- element.group = this.node?._attrs.name || this.node?._nid
116
+ element.group = this.node?._attrs.name || this.node?._nid.toString()
109
117
  })
110
118
  // 阻止事件冒泡传递上去
111
119
  this.node.addEventListener('change', (e: TaroEvent) => e.stopPropagation())
@@ -113,8 +121,8 @@ export struct TaroRadioGroup {
113
121
  }
114
122
 
115
123
  @Styles defaultEvent () {
116
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
117
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
124
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
125
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
118
126
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
119
127
  if (this.node) {
120
128
  this.node._nodeInfo.areaInfo = res[1]
@@ -123,26 +131,27 @@ export struct TaroRadioGroup {
123
131
  }
124
132
 
125
133
  build() {
126
- if (this.node) {
127
- if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
128
- Row() {
129
- createLazyChildren(this.node)
130
- }
131
- .attributeModifier(commonStyleModify.setNode(this.node))
132
- .defaultEvent()
133
- .visibleChangeEvent()
134
- .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
135
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
136
- } else {
137
- Column() {
138
- createLazyChildren(this.node)
139
- }
140
- .attributeModifier(commonStyleModify.setNode(this.node))
141
- .defaultEvent()
142
- .visibleChangeEvent()
143
- .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
144
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
134
+ if (FlexManager.useFlexLayout(this.node)) {
135
+ Flex(FlexManager.flexOptions(this.node)) {
136
+ this.createLazyChildren(this.node, 0)
137
+ }
138
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
139
+ .defaultEvent()
140
+ .visibleChangeEvent()
141
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
142
+ Row() {
143
+ this.createLazyChildren(this.node, 0)
144
+ }
145
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
146
+ .defaultEvent()
147
+ .visibleChangeEvent()
148
+ } else {
149
+ Column() {
150
+ this.createLazyChildren(this.node, 0)
145
151
  }
152
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
153
+ .defaultEvent()
154
+ .visibleChangeEvent()
146
155
  }
147
156
  }
148
157
  }
@@ -1,46 +1,25 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
+ import { generateText } from './utils'
4
5
  import { getNodeThresholds, shouldBindEvent } from './utils/helper'
5
6
 
6
- import type { RichTextProps } from '@tarojs/components/types/RichText'
7
7
  import type { TaroAny, TaroRichTextElement } from '@tarojs/runtime'
8
8
 
9
- function generateText (node: TaroRichTextElement): string {
10
- return parseHtmlNode(node._attrs.nodes || '')
11
- }
12
-
13
9
  @Component
14
10
  export default struct TaroRichText {
11
+ @Builder customBuilder() {}
12
+ @BuilderParam createLazyChildren: (node: TaroRichTextElement, layer?: number) => void = this.customBuilder
15
13
  @ObjectLink node: TaroRichTextElement
16
14
 
17
15
  build () {
18
16
  RichText(generateText(this.node))
19
17
  .attributeModifier(commonStyleModify.setNode(this.node))
20
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
18
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
21
19
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
22
20
  this.node._nodeInfo.areaInfo = res[1]
23
21
  }))
24
22
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
25
-
26
23
  }
27
24
  }
28
25
 
29
- // 将nodeTree转换成harmony需要的string结构
30
- function nodeToHtml(node: RichTextProps.Text | RichTextProps.HTMLElement): string {
31
- if (node.type === 'text') {
32
- return node.text;
33
- }
34
- if (node.attrs) {
35
- const attributes = Object.entries(node.attrs)
36
- .map((item: [string, string]) => `${item[0]}="${item[1]}"`)
37
- .join(' ');
38
- const childrenHtml: string = typeof node.children === 'string' ? node.children : (node.children || []).map((child: RichTextProps.Text | RichTextProps.HTMLElement) => nodeToHtml(child)).join('');
39
- return `<${node.name}${attributes ? ' ' + attributes : ''}>${childrenHtml}</${node.name}>`;
40
- }
41
- return ''
42
- }
43
-
44
- function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElement> | string) {
45
- return typeof nodes === 'string' ? nodes: `<div>${nodes.map(node => nodeToHtml(node)).join('')}</div>`
46
- }
@@ -0,0 +1,108 @@
1
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
+
3
+ import commonStyleModify from './style'
4
+ import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
6
+
7
+ import type { TaroAny, TaroEvent, TaroScrollViewElement } from '@tarojs/runtime'
8
+
9
+ interface ScrollViewAttrs {
10
+ scrollBar: BarState
11
+ }
12
+ interface ScrollViewCurrentOffset {
13
+ xOffset: number
14
+ yOffset: number
15
+ }
16
+ interface ScrollViewEvent {
17
+ deltaX: number
18
+ deltaY: number
19
+ scrollLeft: number
20
+ scrollTop: number
21
+ scrollWidth: number
22
+ scrollHeight: number
23
+ }
24
+
25
+ function getAttributes (node: TaroScrollViewElement): ScrollViewAttrs {
26
+ const _attrs = node._attrs
27
+ const scrollAttrs: ScrollViewAttrs = {
28
+ scrollBar: typeof _attrs.showScrollbar === 'boolean'
29
+ ? _attrs.showScrollbar ? BarState.On : BarState.Off
30
+ : BarState.Auto
31
+ }
32
+ return scrollAttrs
33
+ }
34
+
35
+ function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', scrollOffset?: number) {
36
+ if (!node || !node.scroller) return
37
+
38
+ const currentOffset = node.scroller.currentOffset() as ScrollViewCurrentOffset
39
+
40
+ if (!currentOffset) return
41
+
42
+ const currentXOffset = currentOffset?.xOffset || 0
43
+ const currentYOffset = currentOffset?.yOffset || 0
44
+ const value: ScrollViewEvent = {
45
+ deltaX: vp2px(node._attrs.scrollX ? scrollOffset : 0),
46
+ deltaY: vp2px(node._attrs.scrollX ? 0 : scrollOffset),
47
+ scrollLeft: vp2px(currentXOffset),
48
+ scrollTop: vp2px(currentYOffset),
49
+ scrollWidth: vp2px(Number(node._nodeInfo?._scroll?.width)),
50
+ scrollHeight: vp2px(Number(node._nodeInfo?._scroll?.height)),
51
+ }
52
+ const event: TaroEvent = createTaroEvent(eventName, { detail: value }, node)
53
+
54
+ eventHandler(event, eventName, node)
55
+ }
56
+
57
+ @Component
58
+ export default struct TaroScrollList {
59
+ @Builder customBuilder() {}
60
+ @BuilderParam createLazyChildren: (node: TaroScrollViewElement, layer?: number) => void = this.customBuilder
61
+ @ObjectLink node: TaroScrollViewElement
62
+ @State overwriteStyle: Record<string, TaroAny> = {}
63
+
64
+ aboutToAppear(): void {
65
+ if (this.node) {
66
+ this.node._instance = this
67
+ }
68
+ }
69
+
70
+ handleScroll = (scrollOffset: number) => {
71
+ handleScrollEvent(this.node, 'scroll', scrollOffset)
72
+ }
73
+
74
+ build() {
75
+ List({
76
+ scroller: this.node.scroller
77
+ }) {
78
+ this.createLazyChildren(this.node, 0)
79
+ }
80
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
81
+ .sticky(StickyStyle.Header)
82
+ .listDirection(this.node.getAttribute('scrollX') ? Axis.Horizontal: Axis.Vertical)
83
+ .align(Alignment.TopStart)
84
+ .clip(true)
85
+ .scrollBar(getAttributes(this.node).scrollBar)
86
+ .onScrollIndex((first: number, last: number) => {
87
+ const scrollindexfns = (this.node?.__listeners?.['scrollindex'] || []) as Function[]
88
+ scrollindexfns.forEach(fn => {
89
+ fn({
90
+ first,
91
+ last
92
+ })
93
+ })
94
+ })
95
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
96
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
97
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
98
+ this.node._nodeInfo.areaInfo = res[1]
99
+ }))
100
+ .onDidScroll(shouldBindEvent((scrollOffset: number) => { handleScrollEvent(this.node, 'scroll', scrollOffset) }, this.node, ['scroll']))
101
+ .onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
102
+ .onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
103
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
104
+ .onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
105
+ }
106
+ }
107
+
108
+