@tarojs/plugin-platform-harmony-ets 4.0.0-beta.7 → 4.0.0-beta.70

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 (128) 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 +9 -1
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/network/request.ts +5 -5
  7. package/dist/apis/route/index.ts +15 -0
  8. package/dist/apis/storage/index.ts +146 -78
  9. package/dist/apis/ui/animation/animation.ts +71 -29
  10. package/dist/apis/ui/background.ts +2 -1
  11. package/dist/apis/ui/interaction/index.ts +42 -59
  12. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  13. package/dist/apis/ui/scroll/index.ts +1 -1
  14. package/dist/apis/utils/index.ts +1 -1
  15. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  16. package/dist/apis/wxml/index.ts +2 -0
  17. package/dist/apis/wxml/selectorQuery.ts +24 -11
  18. package/dist/components-harmony-ets/button.ets +48 -34
  19. package/dist/components-harmony-ets/canvas.ets +51 -0
  20. package/dist/components-harmony-ets/checkbox.ets +69 -61
  21. package/dist/components-harmony-ets/form.ets +51 -29
  22. package/dist/components-harmony-ets/icon.ets +31 -19
  23. package/dist/components-harmony-ets/image.ets +34 -14
  24. package/dist/components-harmony-ets/index.ets +92 -0
  25. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  26. package/dist/components-harmony-ets/input.ets +45 -41
  27. package/dist/components-harmony-ets/label.ets +69 -42
  28. package/dist/components-harmony-ets/listView.ets +26 -0
  29. package/dist/components-harmony-ets/movableArea.ets +126 -0
  30. package/dist/components-harmony-ets/movableView.ets +77 -0
  31. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  32. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  33. package/dist/components-harmony-ets/picker.ets +42 -38
  34. package/dist/components-harmony-ets/progress.ets +52 -0
  35. package/dist/components-harmony-ets/pseudo.ets +80 -0
  36. package/dist/components-harmony-ets/radio.ets +71 -64
  37. package/dist/components-harmony-ets/richText.ets +14 -30
  38. package/dist/components-harmony-ets/scrollList.ets +94 -0
  39. package/dist/components-harmony-ets/scrollView.ets +61 -57
  40. package/dist/components-harmony-ets/slider.ets +15 -14
  41. package/dist/components-harmony-ets/stickySection.ets +42 -0
  42. package/dist/components-harmony-ets/style.ets +372 -130
  43. package/dist/components-harmony-ets/swiper.ets +61 -20
  44. package/dist/components-harmony-ets/switch.ets +30 -28
  45. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  46. package/dist/components-harmony-ets/text.ets +135 -49
  47. package/dist/components-harmony-ets/textArea.ets +47 -35
  48. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  49. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  50. package/dist/components-harmony-ets/utils/flexManager.ets +47 -19
  51. package/dist/components-harmony-ets/utils/helper.ets +18 -5
  52. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  53. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  54. package/dist/components-harmony-ets/utils/index.ts +54 -50
  55. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  56. package/dist/components-harmony-ets/video.ets +34 -21
  57. package/dist/components-harmony-ets/view.ets +63 -52
  58. package/dist/components-harmony-ets/webView.ets +40 -34
  59. package/dist/index.d.ts +152 -0
  60. package/dist/index.js +85 -42
  61. package/dist/index.js.map +1 -1
  62. package/dist/runtime-ets/bom/document.ts +6 -4
  63. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  64. package/dist/runtime-ets/bom/window.ts +7 -0
  65. package/dist/runtime-ets/current.ts +3 -0
  66. package/dist/runtime-ets/dom/bind.ts +28 -12
  67. package/dist/runtime-ets/dom/class-list.ts +2 -2
  68. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  69. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  70. package/dist/runtime-ets/dom/document.ts +22 -8
  71. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  72. package/dist/runtime-ets/dom/element/element.ts +334 -58
  73. package/dist/runtime-ets/dom/element/form.ts +23 -26
  74. package/dist/runtime-ets/dom/element/index.ts +25 -2
  75. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  76. package/dist/runtime-ets/dom/element/movableView.ts +209 -0
  77. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  78. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  79. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  80. package/dist/runtime-ets/dom/element/text.ts +1 -8
  81. package/dist/runtime-ets/dom/element/video.ts +5 -4
  82. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  83. package/dist/runtime-ets/dom/event.ts +2 -4
  84. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  85. package/dist/runtime-ets/dom/node.ts +49 -28
  86. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
  87. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  88. package/dist/runtime-ets/dom/stylesheet/type.ts +49 -9
  89. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  90. package/dist/runtime-ets/index.ts +2 -1
  91. package/dist/runtime-ets/interface/event.ts +1 -1
  92. package/dist/runtime-ets/utils/index.ts +69 -13
  93. package/dist/runtime-ets/utils/info.ts +2 -2
  94. package/dist/runtime-framework/react/app.ts +7 -2
  95. package/dist/runtime-framework/react/hooks.ts +0 -1
  96. package/dist/runtime-framework/react/index.ts +0 -2
  97. package/dist/runtime-framework/react/native-page.ts +32 -14
  98. package/dist/runtime-framework/react/page.ts +3 -8
  99. package/dist/runtime-framework/solid/app.ts +25 -45
  100. package/dist/runtime-framework/solid/connect.ts +21 -3
  101. package/dist/runtime-framework/solid/hooks.ts +16 -11
  102. package/dist/runtime-framework/solid/index.ts +6 -2
  103. package/dist/runtime-framework/solid/page.ts +84 -30
  104. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  105. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  106. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  107. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  108. package/dist/runtime-utils.d.ts +827 -0
  109. package/dist/runtime-utils.js +425 -200
  110. package/dist/runtime-utils.js.map +1 -1
  111. package/dist/runtime.d.ts +1 -0
  112. package/dist/runtime.js +425 -200
  113. package/dist/runtime.js.map +1 -1
  114. package/index.js +3 -1
  115. package/package.json +13 -13
  116. package/static/media/cancel.svg +1 -1
  117. package/static/media/circle.svg +1 -1
  118. package/static/media/clear.svg +1 -1
  119. package/static/media/download.svg +1 -1
  120. package/static/media/info.svg +1 -1
  121. package/static/media/info_circle.svg +1 -1
  122. package/static/media/search.svg +1 -1
  123. package/static/media/success.svg +1 -1
  124. package/static/media/success_no_circle.svg +1 -1
  125. package/static/media/warn.svg +1 -1
  126. package/types/harmony.d.ts +4 -0
  127. package/types/index.d.ts +4 -0
  128. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,13 +1,14 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
- import { getNormalAttributes, parseStyles, shouldBindEvent, getNodeThresholds } from './utils/helper'
4
+ import { parseStyles, shouldBindEvent, getNodeThresholds } from './utils/helper'
5
5
  import { INPUT_TYPE_MAP, INPUT_CONFIRM_MAP } from './utils/constant/style'
6
6
 
7
7
  import type { TaroStyleType, TaroAny, TaroInputElement, TaroEvent } from '@tarojs/runtime'
8
8
 
9
9
  interface InputAttrs {
10
10
  textAlign?: TextAlign
11
+ autoFocus?: boolean
11
12
  }
12
13
 
13
14
  @Extend(TextInput)
@@ -22,12 +23,13 @@ function styles (style: TaroStyleType) {
22
23
  @Extend(TextInput)
23
24
  function attrs(attr: InputAttrs) {
24
25
  .textAlign(attr.textAlign)
26
+ .defaultFocus(attr.autoFocus)
25
27
  }
26
28
 
27
-
28
29
  function getAttributes(node: TaroInputElement): InputAttrs {
29
30
  return {
30
31
  textAlign: node.hmStyle.textAlign,
32
+ autoFocus: node._attrs.autoFocus || node._attrs.focus || false,
31
33
  }
32
34
  }
33
35
 
@@ -48,7 +50,10 @@ function getPlaceholderColor (node: TaroInputElement): string {
48
50
  export default struct TaroInput {
49
51
  @State value: string = ''
50
52
 
51
- 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> = {}
52
57
 
53
58
  aboutToAppear () {
54
59
  if (this.node) {
@@ -63,43 +68,42 @@ export default struct TaroInput {
63
68
  }
64
69
 
65
70
  build () {
66
- if (this.node) {
67
- TextInput({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
68
- .key(this.node._nid)
69
- .type(getInputType(this.node))
70
- .maxLength(Number(this.node._attrs?.maxlength) || null)
71
- .placeholderColor(getPlaceholderColor(this.node))
72
- .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
73
- .attributeModifier(commonStyleModify.setNode(this.node))
74
- .styles(getNormalAttributes(this.node))
75
- .attrs(getAttributes(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
- .onSubmit(() => {
84
- const event: TaroEvent = createTaroEvent('confirm', { detail: { value: this.value } }, this.node)
85
- eventHandler(event, 'confirm', this.node)
86
- })
87
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
88
- .onBlur(() => {
89
- const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
90
- eventHandler(event, 'blur', this.node)
91
- })
92
- .onFocus(() => {
93
- const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
94
-
95
- eventHandler(event, 'focus', this.node)
96
- })
97
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
98
- if (this.node) {
99
- this.node._nodeInfo.areaInfo = res[1]
100
- }
101
- }))
102
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
103
- }
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))
104
108
  }
105
109
  }
@@ -1,12 +1,13 @@
1
1
  import { Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import commonStyleModify from './style'
4
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { FlexManager } from './utils/FlexManager'
7
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
6
+ import { FlexManager } from './utils/flexManager'
7
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
8
 
9
9
  import type { TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
10
+ import { isUndefined } from '@tarojs/shared'
10
11
 
11
12
  function handleTargetChange (id: string) {
12
13
  const taro: TaroAny = Current.taro
@@ -34,45 +35,71 @@ function handleTargetChange (id: string) {
34
35
  }
35
36
  }
36
37
 
37
- @Builder
38
- export default function TaroLabel (node: TaroLabelElement) {
39
- if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
40
- Row() {
41
- 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
42
48
  }
43
- .attributeModifier(commonStyleModify.setNode(node))
44
- .onClick((e: ClickEvent) => {
45
- const firstChild: TaroElement | null = node.childNodes[0] as TaroElement | null
46
- const id: string = node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
47
-
48
- handleTargetChange(id)
49
- eventHandler(e, 'click', node)
50
- })
51
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
52
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
53
- node._nodeInfo.areaInfo = res[1]
54
- }))
55
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
56
- .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
57
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
58
- } else {
59
- Column() {
60
- createLazyChildren(node)
49
+ }
50
+
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))
61
103
  }
62
- .attributeModifier(commonStyleModify.setNode(node))
63
- .onClick((e: ClickEvent) => {
64
- const firstChild: TaroElement | null = node.childNodes[0] as TaroElement | null
65
- const id: string = node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
66
-
67
- handleTargetChange(id)
68
- eventHandler(e, 'click', node)
69
- })
70
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
71
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
72
- node._nodeInfo.areaInfo = res[1]
73
- }))
74
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
75
- .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
76
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
77
104
  }
78
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,126 @@
1
+ import type { TaroAny, TaroMovableAreaElement, TaroMovableViewElement } from '@tarojs/runtime'
2
+
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 customBuilder() {}
11
+ @BuilderParam createLazyChildren: (node: TaroMovableAreaElement) => void = this.customBuilder
12
+ @ObjectLink node: TaroMovableAreaElement
13
+ @State overwriteStyle: Record<string, TaroAny> = {}
14
+
15
+ aboutToAppear(): void {
16
+ if (this.node) {
17
+ this.node._instance = this
18
+ }
19
+ }
20
+
21
+ build() {
22
+ if (FlexManager.useFlexLayout(this.node)) {
23
+ Flex(FlexManager.flexOptions(this.node)) {
24
+ this.createLazyChildren(this.node)
25
+ }
26
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
27
+ .clip(true)
28
+ .onAreaChange((oldValue: Area, newValue: Area) => {
29
+ this.node.childNodes.forEach(item => {
30
+ if(item.nodeName === 'MOVABLE-VIEW') {
31
+ ;(item as TaroMovableViewElement).area = {
32
+ w: Number( newValue.width),
33
+ h: Number(newValue.height)
34
+ }
35
+ }
36
+ })
37
+ })
38
+ .gesture(
39
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
40
+ this.node.childNodes.forEach(item => {
41
+ if(item.nodeName === 'MOVABLE-VIEW') {
42
+ ;(item as TaroMovableViewElement).startScale()
43
+ }
44
+ })
45
+ }).onActionUpdate((event) => {
46
+ const scaleArea = this.node.getAttribute('scaleArea')
47
+ if (scaleArea) {
48
+ this.node.childNodes.forEach(item => {
49
+ if(item.nodeName === 'MOVABLE-VIEW') {
50
+ ;(item as TaroMovableViewElement).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
+ this.node.childNodes.forEach(item => {
64
+ if(item.nodeName === 'MOVABLE-VIEW') {
65
+ ;(item as TaroMovableViewElement).area = {
66
+ w: Number( newValue.width),
67
+ h: Number(newValue.height)
68
+ }
69
+ }
70
+ })
71
+ })
72
+ .gesture(
73
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
74
+ this.node.childNodes.forEach(item => {
75
+ if(item.nodeName === 'MOVABLE-VIEW') {
76
+ ;(item as TaroMovableViewElement).startScale()
77
+ }
78
+ })
79
+ }).onActionUpdate((event) => {
80
+ const scaleArea = this.node.getAttribute('scaleArea')
81
+ if (scaleArea) {
82
+ this.node.childNodes.forEach(item => {
83
+ if(item.nodeName === 'MOVABLE-VIEW') {
84
+ ;(item as TaroMovableViewElement).doScale(event.scale)
85
+ }
86
+ })
87
+ }
88
+ })
89
+ )
90
+ } else {
91
+ Column() {
92
+ this.createLazyChildren(this.node)
93
+ }
94
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
95
+ .clip(true)
96
+ .onAreaChange((oldValue: Area, newValue: Area) => {
97
+ this.node.childNodes.forEach(item => {
98
+ if(item.nodeName === 'MOVABLE-VIEW') {
99
+ ;(item as TaroMovableViewElement).area = {
100
+ w: Number( newValue.width),
101
+ h: Number(newValue.height)
102
+ }
103
+ }
104
+ })
105
+ })
106
+ .gesture(
107
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
108
+ this.node.childNodes.forEach(item => {
109
+ if(item.nodeName === 'MOVABLE-VIEW') {
110
+ ;(item as TaroMovableViewElement).startScale()
111
+ }
112
+ })
113
+ }).onActionUpdate((event) => {
114
+ const scaleArea = this.node.getAttribute('scaleArea')
115
+ if (scaleArea) {
116
+ this.node.childNodes.forEach(item => {
117
+ if(item.nodeName === 'MOVABLE-VIEW') {
118
+ ;(item as TaroMovableViewElement).doScale(event.scale)
119
+ }
120
+ })
121
+ }
122
+ })
123
+ )
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,77 @@
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
+ setTimeout(() => {
21
+ const x = this.node.getAttribute('x') ? Number(this.node.getAttribute('x')) : 0
22
+ const y = this.node.getAttribute('y') ? Number(this.node.getAttribute('y')) : 0
23
+ this.node.checkPositionBoundary({ x, y }, this.node.scaleValue)
24
+ }, 0)
25
+ }
26
+ }
27
+
28
+ build() {
29
+ Stack() {
30
+ if (FlexManager.useFlexLayout(this.node)) {
31
+ Flex(FlexManager.flexOptions(this.node)) {
32
+ this.createLazyChildren(this.node)
33
+ }
34
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
35
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
36
+ Row() {
37
+ this.createLazyChildren(this.node)
38
+ }
39
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
40
+ } else {
41
+ Column() {
42
+ this.createLazyChildren(this.node)
43
+ }
44
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
45
+ }
46
+ }
47
+ .translate({ x: this.node.position.x, y: this.node.position.y })
48
+ .scale({ x: this.node.scaleValue, y: this.node.scaleValue })
49
+ .onAreaChange((oldValue: Area, newValue: Area) => {
50
+ this.node.selfSize = { w: Number(newValue.width), h: Number(newValue.height) }
51
+ })
52
+ .gesture(
53
+ GestureGroup(GestureMode.Exclusive,
54
+ PanGesture({ fingers: 1 }).onActionStart((e: GestureEvent) => {
55
+
56
+ this.node.startMove()
57
+ this.node.callTouchEventFnFromGesture('touchstart', e)
58
+ }).onActionUpdate((e: GestureEvent) => {
59
+ this.node.callTouchEventFnFromGesture('touchmove', e)
60
+ this.node.doMove({
61
+ x: e.offsetX,
62
+ y: e.offsetY
63
+ })
64
+
65
+ }).onActionEnd((e: GestureEvent) => {
66
+ this.node.callTouchEventFnFromGesture('touchend', e)
67
+ this.node.checkPositionBoundary(this.node.position, this.node.scaleValue)
68
+ }),
69
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
70
+ this.node.startScale()
71
+ }).onActionUpdate((event) => {
72
+ this.node.doScale(event.scale)
73
+ })
74
+ )
75
+ )
76
+ }
77
+ }
@@ -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
+ }
@@ -0,0 +1,94 @@
1
+ import { APP, eventCenter } from '@tarojs/runtime/dist/runtime.esm'
2
+ import { getCurrentInstance, pageScrollTo } from '@tarojs/taro'
3
+
4
+ import { isTagFirstChild } from './utils/helper'
5
+
6
+ import type { TaroAny, TaroPageMetaElement } from '@tarojs/runtime'
7
+
8
+ export interface IComponentAttributeUpdateEvents {
9
+ id: string
10
+ tagName: string
11
+ attribute: string
12
+ value: TaroAny
13
+ }
14
+
15
+ @Component
16
+ export default struct TaroPageMeta {
17
+ @Builder customBuilder() {}
18
+ @BuilderParam createLazyChildren: (node: TaroPageMetaElement) => void = this.customBuilder
19
+ @ObjectLink node: TaroPageMetaElement
20
+
21
+ page: TaroAny = {}
22
+
23
+ aboutToAppear(): void {
24
+ if (!isTagFirstChild(this.node, APP, 2)) {
25
+ // PageMeta 只能是页面内的第一个元素
26
+ console.error('PageMeta 只能是页面内的第一个元素。')
27
+ }
28
+
29
+ this.page = getCurrentInstance().page
30
+ if (this.node) {
31
+ this.node._instance = this
32
+ }
33
+
34
+ // FIXME 在 Harmony 提供 @Watch 文档后,根据 node 实际使用更细粒度的监听
35
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
36
+ this.handleAttributes(this.node._attrs)
37
+ }
38
+
39
+ aboutToDisappear(): void {
40
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
41
+ }
42
+
43
+ handleAttributeUpdate = (opt: IComponentAttributeUpdateEvents) => {
44
+ if (opt.id === this.node._nid && opt.tagName === 'PAGE-META') {
45
+ const attrs: Record<string, TaroAny> = {}
46
+ attrs[opt.attribute] = opt.value
47
+ this.handleAttributes(attrs)
48
+ }
49
+ }
50
+
51
+ handleAttributes (attrs: Record<string, TaroAny>) {
52
+ const options: Record<string, TaroAny> = {}
53
+ let triggerStyleEvent = false
54
+
55
+ // FIXME 更新类型支持度
56
+ if (attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor) {
57
+ options.backgroundColorContext = attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor
58
+ triggerStyleEvent = true
59
+ }
60
+ if (attrs.backgroundColorBottom || attrs.backgroundColor) {
61
+ options.backgroundColor = attrs.backgroundColorBottom || attrs.backgroundColor
62
+ triggerStyleEvent = true
63
+ }
64
+ if (attrs.backgroundTextStyle) {
65
+ options.backgroundTextStyle = attrs.backgroundTextStyle
66
+ triggerStyleEvent = true
67
+ }
68
+
69
+ if (this.page === getCurrentInstance().page) {
70
+ if (attrs.scrollTop || attrs.scrollDuration) {
71
+ pageScrollTo({
72
+ scrollTop: attrs.scrollTop || this.node._attrs.scrollTop,
73
+ duration: attrs.scrollDuration || this.node._attrs.scrollDuration,
74
+ } as TaroAny)
75
+ }
76
+ }
77
+ // pageStyle
78
+ // rootFontSize
79
+ // pageFontSize
80
+ // pageOrientation
81
+ if (triggerStyleEvent) {
82
+ eventCenter.trigger('__taroPageStyle', options)
83
+ }
84
+ // onResize
85
+ // onScroll
86
+ // onScrollDone
87
+ }
88
+
89
+ build() {
90
+ if (true) {
91
+ this.createLazyChildren(this.node)
92
+ }
93
+ }
94
+ }