@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,43 +1,18 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { getNormalAttributes, parseStyles, shouldBindEvent, getNodeThresholds } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { parseStyles, shouldBindEvent, getNodeThresholds } from './utils/helper'
4
5
  import { INPUT_TYPE_MAP, INPUT_CONFIRM_MAP } from './utils/constant/style'
5
6
 
6
7
  import type { TaroStyleType, TaroAny, TaroInputElement, TaroEvent } from '@tarojs/runtime'
7
8
 
8
9
  interface InputAttrs {
9
10
  textAlign?: TextAlign
11
+ autoFocus?: boolean
10
12
  }
11
13
 
12
14
  @Extend(TextInput)
13
15
  function styles (style: TaroStyleType) {
14
- .id(style.id)
15
- .key(style.id)
16
- .padding(style.padding)
17
- .margin(style.margin)
18
- .width(style.width)
19
- .height(style.height)
20
- .constraintSize(style.constraintSize)
21
- .flexGrow(style.flexGrow)
22
- .flexShrink(style.flexShrink)
23
- .flexBasis(style.flexBasis)
24
- .alignSelf(style.alignSelf)
25
- .backgroundColor(style.backgroundColor)
26
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
27
- .backgroundImageSize(style.backgroundImageSize)
28
- .backgroundImagePosition(style.backgroundImagePosition)
29
- .rotate(style.rotate)
30
- .scale(style.scale)
31
- .translate(style.translate)
32
- .transform(style.transform)
33
- .borderStyle(style.borderStyle)
34
- .borderWidth(style.borderWidth)
35
- .borderColor(style.borderColor)
36
- .borderRadius(style.borderRadius)
37
- .linearGradient(style.linearGradient)
38
- .zIndex(style.zIndex)
39
- .opacity(style.opacity)
40
- .clip(style.clip)
41
16
  .fontColor(style.color)
42
17
  .fontSize(style.fontSize)
43
18
  .fontWeight(style.fontWeight)
@@ -48,12 +23,13 @@ function styles (style: TaroStyleType) {
48
23
  @Extend(TextInput)
49
24
  function attrs(attr: InputAttrs) {
50
25
  .textAlign(attr.textAlign)
26
+ .defaultFocus(attr.autoFocus)
51
27
  }
52
28
 
53
-
54
29
  function getAttributes(node: TaroInputElement): InputAttrs {
55
30
  return {
56
31
  textAlign: node.hmStyle.textAlign,
32
+ autoFocus: node._attrs.autoFocus || node._attrs.focus || false,
57
33
  }
58
34
  }
59
35
 
@@ -74,52 +50,60 @@ function getPlaceholderColor (node: TaroInputElement): string {
74
50
  export default struct TaroInput {
75
51
  @State value: string = ''
76
52
 
77
- node: TaroInputElement | null = null
53
+ @Builder customBuilder() {}
54
+ @BuilderParam createLazyChildren: (node: TaroInputElement) => void = this.customBuilder
55
+ @ObjectLink node: TaroInputElement
56
+ @State overwriteStyle: Record<string, TaroAny> = {}
78
57
 
79
58
  aboutToAppear () {
80
59
  if (this.node) {
81
60
  this.value = this.node.value
82
61
  this.node._instance = this
62
+
63
+ if (!this.node._isInit) {
64
+ this.node._isInit = true
65
+ this.node._reset = this.node.value || ''
66
+ }
83
67
  }
84
68
  }
85
69
 
86
70
  build () {
87
- if (this.node) {
88
- TextInput({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
89
- .key(this.node._nid)
90
- .type(getInputType(this.node))
91
- .maxLength(Number(this.node._attrs?.maxlength) || null)
92
- .placeholderColor(getPlaceholderColor(this.node))
93
- .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
94
- .styles(getNormalAttributes(this.node))
95
- .attrs(getAttributes(this.node))
96
- .onChange((value: string) => {
97
- const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
98
-
99
- this.value = value
100
- this.node?.updateFormWidgetValue(value)
101
- eventHandler(event, 'input', this.node)
102
- })
103
- .onSubmit(() => {
104
- const event: TaroEvent = createTaroEvent('confirm', { detail: { value: this.value } }, this.node)
105
- eventHandler(event, 'confirm', this.node)
106
- })
107
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
108
- .onBlur(() => {
109
- const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
110
- eventHandler(event, 'blur', this.node)
111
- })
112
- .onFocus(() => {
113
- const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
114
-
115
- eventHandler(event, 'focus', this.node)
116
- })
117
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
118
- if (this.node) {
119
- this.node._nodeInfo.areaInfo = res[1]
120
- }
121
- }))
122
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
123
- }
71
+ TextInput({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
72
+ .key(this.node._nid)
73
+ .type(getInputType(this.node))
74
+ .maxLength(Number(this.node._attrs?.maxlength) || null)
75
+ .placeholderColor(getPlaceholderColor(this.node))
76
+ .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
77
+ .padding(0) // Note: 移出 Input 默认 padding 设置
78
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
79
+ .styles(this.node?.hmStyle)
80
+ .attrs(getAttributes(this.node))
81
+ .onChange((value: string) => {
82
+ const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
83
+
84
+ this.value = value
85
+ this.node?.updateFormWidgetValue(value)
86
+ eventHandler(event, 'input', this.node)
87
+ })
88
+ .onSubmit(() => {
89
+ const event: TaroEvent = createTaroEvent('confirm', { detail: { value: this.value } }, this.node)
90
+ eventHandler(event, 'confirm', this.node)
91
+ })
92
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
93
+ .onBlur(() => {
94
+ const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
95
+ eventHandler(event, 'blur', this.node)
96
+ })
97
+ .onFocus(() => {
98
+ const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
99
+
100
+ eventHandler(event, 'focus', this.node)
101
+ })
102
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
103
+ if (this.node) {
104
+ this.node._nodeInfo.areaInfo = res[1]
105
+ }
106
+ }))
107
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
124
108
  }
125
109
  }
@@ -1,48 +1,19 @@
1
1
  import { Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import { createLazyChildren } from './render'
4
- import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
- import { FlexManager } from './utils/FlexManager'
6
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
7
4
 
8
- import type { TaroStyleType, TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
5
+ import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
+ import { FlexManager } from './utils/flexManager'
7
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
9
8
 
10
- @Extend(Flex)
11
- function attrs (style: TaroStyleType) {
12
- .id(style.id)
13
- .key(style.id)
14
- .padding(style.padding)
15
- .margin(style.margin)
16
- .width(style.width)
17
- .height(style.height)
18
- .constraintSize(style.constraintSize)
19
- .flexGrow(style.flexGrow)
20
- .flexShrink(style.flexShrink)
21
- .flexBasis(style.flexBasis)
22
- .alignSelf(style.alignSelf)
23
- .backgroundColor(style.backgroundColor)
24
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
25
- .backgroundImageSize(style.backgroundImageSize)
26
- .backgroundImagePosition(style.backgroundImagePosition)
27
- .rotate(style.rotate)
28
- .scale(style.scale)
29
- .translate(style.translate)
30
- .transform(style.transform)
31
- .borderStyle(style.borderStyle)
32
- .borderWidth(style.borderWidth)
33
- .borderColor(style.borderColor)
34
- .borderRadius(style.borderRadius)
35
- .linearGradient(style.linearGradient)
36
- .zIndex(style.zIndex)
37
- .opacity(style.opacity)
38
- .clip(style.clip)
39
- }
9
+ import type { TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
10
+ import { isUndefined } from '@tarojs/shared'
40
11
 
41
12
  function handleTargetChange (id: string) {
42
13
  const taro: TaroAny = Current.taro
43
14
  const page: TaroAny = taro.getCurrentInstance().page
44
- const currentPageNode: TaroElement = getPageScrollerOrNode(page.node, page)
45
- const node: TaroElement | null = currentPageNode.getElementById(id)
15
+ const currentPageNode: TaroElement = getPageScrollerOrNode(page?.node, page)
16
+ const node: TaroElement | null = currentPageNode?.getElementById(id)
46
17
 
47
18
  if (!node) return
48
19
 
@@ -64,22 +35,71 @@ function handleTargetChange (id: string) {
64
35
  }
65
36
  }
66
37
 
67
- @Builder
68
- export default function TaroLabel (node: TaroLabelElement) {
69
- Flex(FlexManager.flexOptions(node)) {
70
- createLazyChildren(node)
38
+ @Component
39
+ export default struct TaroLabel {
40
+ @Builder customBuilder() {}
41
+ @BuilderParam createLazyChildren: (node: TaroLabelElement) => void = this.customBuilder
42
+ @ObjectLink node: TaroLabelElement
43
+ @State overwriteStyle: Record<string, TaroAny> = {}
44
+
45
+ aboutToAppear(): void {
46
+ if (this.node) {
47
+ this.node._instance = this
48
+ }
71
49
  }
72
- .attrs(getNormalAttributes(node))
73
- .onClick((e: ClickEvent) => {
74
- const firstChild: TaroElement | null = node.childNodes[0] as TaroElement | null
75
- const id: string = node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
76
50
 
77
- handleTargetChange(id)
78
- eventHandler(e, 'click', node)
79
- })
80
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
81
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
82
- node._nodeInfo.areaInfo = res[1]
83
- }))
84
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
51
+ build() {
52
+ if (FlexManager.useFlexLayout(this.node)) {
53
+ Flex(FlexManager.flexOptions(this.node)) {
54
+ this.createLazyChildren(this.node)
55
+ }
56
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
57
+ .onClick((e: ClickEvent) => {
58
+ const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
59
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
60
+
61
+ handleTargetChange(id)
62
+ eventHandler(e, 'click', this.node)
63
+ })
64
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
65
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
66
+ this.node._nodeInfo.areaInfo = res[1]
67
+ }))
68
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
69
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
70
+ Row() {
71
+ this.createLazyChildren(this.node)
72
+ }
73
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
74
+ .onClick((e: ClickEvent) => {
75
+ const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
76
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
77
+
78
+ handleTargetChange(id)
79
+ eventHandler(e, 'click', this.node)
80
+ })
81
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
82
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
83
+ this.node._nodeInfo.areaInfo = res[1]
84
+ }))
85
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
86
+ } else {
87
+ Column() {
88
+ this.createLazyChildren(this.node)
89
+ }
90
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
91
+ .onClick((e: ClickEvent) => {
92
+ const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
93
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
94
+
95
+ handleTargetChange(id)
96
+ eventHandler(e, 'click', this.node)
97
+ })
98
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
99
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
100
+ this.node._nodeInfo.areaInfo = res[1]
101
+ }))
102
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
103
+ }
104
+ }
85
105
  }
@@ -0,0 +1,26 @@
1
+ import commonStyleModify from './style'
2
+
3
+ import type { TaroViewElement, TaroAny } from '@tarojs/runtime'
4
+
5
+ @Component
6
+ export default struct TaroListView {
7
+ @Builder customBuilder() {}
8
+ @BuilderParam createLazyChildren: (node: TaroViewElement) => void = this.customBuilder
9
+ @ObjectLink node: TaroViewElement
10
+ @State overwriteStyle: Record<string, TaroAny> = {}
11
+
12
+ aboutToAppear(): void {
13
+ if (this.node) {
14
+ this.node._instance = this
15
+ }
16
+ }
17
+
18
+ build() {
19
+ ListItem() {
20
+ Stack() {
21
+ this.createLazyChildren(this.node)
22
+ }
23
+ }
24
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
25
+ }
26
+ }
@@ -0,0 +1,124 @@
1
+ import type { TaroAny, TaroMovableAreaElement, TaroMovableViewElement } from '@tarojs/runtime'
2
+ import { isTaroMovableViewElement } from '@tarojs/runtime'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+
5
+ import { FlexManager } from './utils/flexManager'
6
+ import { isUndefined } from '@tarojs/shared'
7
+
8
+ @Component
9
+ export default struct TaroMovableArea {
10
+ @Builder
11
+ customBuilder() {
12
+ }
13
+
14
+ @BuilderParam createLazyChildren: (node: TaroMovableAreaElement) => void = this.customBuilder
15
+ @ObjectLink node: TaroMovableAreaElement
16
+ @State overwriteStyle: Record<string, TaroAny> = {}
17
+
18
+ aboutToAppear(): void {
19
+ if (this.node) {
20
+ this.node._instance = this
21
+ }
22
+ }
23
+
24
+
25
+
26
+
27
+
28
+ build() {
29
+ if (FlexManager.useFlexLayout(this.node)) {
30
+ Flex(FlexManager.flexOptions(this.node)) {
31
+ this.createLazyChildren(this.node)
32
+ }
33
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
34
+ .clip(true)
35
+ .onAreaChange((oldValue: Area, newValue: Area) => {
36
+ areaChangeHandle(this.node, newValue)
37
+ })
38
+ .gesture(
39
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
40
+ this.node.childNodes.forEach(item => {
41
+ if (isTaroMovableViewElement(item)) {
42
+ item.startScale()
43
+ }
44
+ })
45
+ }).onActionUpdate((event) => {
46
+ const scaleArea = this.node.getAttribute('scaleArea')
47
+ if (scaleArea) {
48
+ this.node.childNodes.forEach(item => {
49
+ if (isTaroMovableViewElement(item)) {
50
+ item.doScale(event.scale)
51
+ }
52
+ })
53
+ }
54
+ })
55
+ )
56
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
57
+ Row() {
58
+ this.createLazyChildren(this.node)
59
+ }
60
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
61
+ .clip(true)
62
+ .onAreaChange((oldValue: Area, newValue: Area) => {
63
+ areaChangeHandle(this.node, newValue)
64
+ })
65
+ .gesture(
66
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
67
+ this.node.childNodes.forEach(item => {
68
+ if (isTaroMovableViewElement(item)) {
69
+ item.startScale()
70
+ }
71
+ })
72
+ }).onActionUpdate((event) => {
73
+ const scaleArea = this.node.getAttribute('scaleArea')
74
+ if (scaleArea) {
75
+ this.node.childNodes.forEach(item => {
76
+ if (isTaroMovableViewElement(item)) {
77
+ item.doScale(event.scale)
78
+ }
79
+ })
80
+ }
81
+ })
82
+ )
83
+ } else {
84
+ Column() {
85
+ this.createLazyChildren(this.node)
86
+ }
87
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
88
+ .clip(true)
89
+ .onAreaChange((oldValue: Area, newValue: Area) => {
90
+ areaChangeHandle(this.node, newValue)
91
+ })
92
+ .gesture(
93
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
94
+ this.node.childNodes.forEach(item => {
95
+ if (isTaroMovableViewElement(item)) {
96
+ item.startScale()
97
+ }
98
+ })
99
+ }).onActionUpdate((event) => {
100
+ const scaleArea = this.node.getAttribute('scaleArea')
101
+ if (scaleArea) {
102
+ this.node.childNodes.forEach(item => {
103
+ if (isTaroMovableViewElement(item)) {
104
+ item.doScale(event.scale)
105
+ }
106
+ })
107
+ }
108
+ })
109
+ )
110
+ }
111
+ }
112
+ }
113
+ function areaChangeHandle(node: TaroMovableAreaElement,newValue: Area) {
114
+ node.childNodes.forEach(item => {
115
+ if (isTaroMovableViewElement(item)) {
116
+ if (item.area?.w !== Number(newValue.width) || item.area?.h !== Number(newValue.height)) {
117
+ item.area = {
118
+ w: Number(newValue.width),
119
+ h: Number(newValue.height)
120
+ }
121
+ }
122
+ }
123
+ })
124
+ }
@@ -0,0 +1,93 @@
1
+ import type { TaroAny, TaroMovableViewElement, TaroElement } from '@tarojs/runtime'
2
+
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+
5
+ import { FlexManager } from './utils/flexManager'
6
+
7
+
8
+
9
+ @Component
10
+ export default struct TaroMovableView {
11
+ @Builder customBuilder() {}
12
+ @BuilderParam createLazyChildren: (node: TaroMovableViewElement) => void = this.customBuilder
13
+ @ObjectLink node: TaroMovableViewElement
14
+ @State overwriteStyle: Record<string, TaroAny> = {}
15
+
16
+ aboutToAppear(): void {
17
+ if (this.node) {
18
+ this.node._instance = this
19
+
20
+ }
21
+ }
22
+
23
+ build() {
24
+ Stack() {
25
+ if (FlexManager.useFlexLayout(this.node)) {
26
+ Flex(FlexManager.flexOptions(this.node)) {
27
+ this.createLazyChildren(this.node)
28
+ }
29
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
30
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
31
+ Row() {
32
+ this.createLazyChildren(this.node)
33
+ }
34
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
35
+ } else {
36
+ Column() {
37
+ this.createLazyChildren(this.node)
38
+ }
39
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
40
+ }
41
+ }
42
+ .translate({ x: this.node.position.x, y: this.node.position.y })
43
+ .scale({ x: this.node.scaleValue, y: this.node.scaleValue })
44
+ .onAreaChange((oldValue: Area, newValue: Area) => {
45
+ if (this.node.selfSize?.w !== Number(newValue.width) || this.node.selfSize?.h !== Number(newValue.height)) {
46
+ this.node.selfSize = { w: Number(newValue.width), h: Number(newValue.height) }
47
+ }
48
+ })
49
+ .visibility(this.node.visibility)
50
+ .gesture(
51
+ GestureGroup(GestureMode.Parallel,
52
+ PanGesture(getPanOption(this.node)).onActionStart((e: GestureEvent) => {
53
+
54
+ this.node.startMove()
55
+ this.node.callTouchEventFnFromGesture('touchstart', e)
56
+ }).onActionUpdate((e: GestureEvent) => {
57
+ this.node.callTouchEventFnFromGesture('touchmove', e)
58
+ this.node.doMove({
59
+ x: e.offsetX,
60
+ y: e.offsetY
61
+ })
62
+
63
+ }).onActionEnd((e: GestureEvent) => {
64
+ this.node.callTouchEventFnFromGesture('touchend', e)
65
+ this.node.checkPositionBoundary(this.node.position, this.node.scaleValue)
66
+ }),
67
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
68
+ this.node.startScale()
69
+ }).onActionUpdate((event) => {
70
+ this.node.doScale(event.scale)
71
+ })
72
+ )
73
+ )
74
+ }
75
+ }
76
+
77
+
78
+ function getPanOption(node: TaroMovableViewElement) {
79
+ const attrDirection = node.getAttribute('direction')
80
+ let panDirection = PanDirection.All
81
+
82
+ if(node.getAttribute('disabled')) {
83
+ panDirection = PanDirection.None
84
+ } else if(attrDirection === 'horizontal') {
85
+ panDirection = PanDirection.Horizontal
86
+ } else if (attrDirection === 'vertical') {
87
+ panDirection = PanDirection.Vertical
88
+ }
89
+ return new PanGestureOptions({
90
+ direction: panDirection,
91
+ fingers: 1
92
+ })
93
+ }
@@ -0,0 +1,65 @@
1
+ import { eventCenter } from '@tarojs/runtime/dist/runtime.esm'
2
+
3
+ import { isTagFirstChild } from './utils/helper'
4
+
5
+ import type { TaroAny, TaroNavigationBarElement } from '@tarojs/runtime'
6
+ import type { IComponentAttributeUpdateEvents } from './pageMeta'
7
+
8
+ @Component
9
+ export default struct TaroNavigationBar {
10
+ @Builder customBuilder() {}
11
+ @BuilderParam createLazyChildren: (node: TaroNavigationBarElement) => void = this.customBuilder
12
+ @ObjectLink node: TaroNavigationBarElement
13
+
14
+ aboutToAppear(): void {
15
+ if (!isTagFirstChild(this.node, 'page-meta')) {
16
+ console.error('NavigationBar 只能是 PageMeta 内的第一个节点。')
17
+ }
18
+ if (this.node) {
19
+ this.node._instance = this
20
+ }
21
+
22
+ // FIXME 在 Harmony 提供 @Watch 文档后,根据 node 实际使用更细粒度的监听
23
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
24
+ this.handleAttributes(this.node._attrs)
25
+ }
26
+
27
+ aboutToDisappear(): void {
28
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
29
+ }
30
+
31
+ handleAttributeUpdate = (opt: IComponentAttributeUpdateEvents) => {
32
+ if (opt.id === this.node._nid && opt.tagName === 'NAVIGATION-BAR') {
33
+ const attrs: Record<string, TaroAny> = {}
34
+ attrs[opt.attribute] = opt.value
35
+ this.handleAttributes(attrs)
36
+ }
37
+ }
38
+
39
+ handleAttributes (attrs: Record<string, TaroAny>) {
40
+ const options: Record<string, TaroAny> = {}
41
+
42
+ if (attrs.title) {
43
+ options.title = attrs.title
44
+ }
45
+ if (attrs.loading) {
46
+ options.loading = attrs.loading
47
+ }
48
+ if (attrs.backgroundColor) {
49
+ options.backgroundColor = attrs.backgroundColor
50
+ }
51
+ if (attrs.frontColor) {
52
+ options.frontColor = attrs.frontColor
53
+ }
54
+ eventCenter.trigger('__taroNavigationStyle', options)
55
+ // FIXME: 以下属性暂时不支持
56
+ // attrs.colorAnimationDuration
57
+ // attrs.colorAnimationTimingFunc
58
+ }
59
+
60
+ build() {
61
+ if (true) {
62
+ this.createLazyChildren(this.node)
63
+ }
64
+ }
65
+ }