@tarojs/plugin-platform-harmony-ets 4.0.0-beta.2 → 4.0.0-beta.21

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 (87) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/framework/index.ts +1 -5
  3. package/dist/apis/index.ts +3 -1
  4. package/dist/apis/network/request.ts +5 -5
  5. package/dist/apis/route/index.ts +15 -0
  6. package/dist/apis/storage/index.ts +124 -60
  7. package/dist/apis/wxml/IntersectionObserver.ts +5 -3
  8. package/dist/apis/wxml/index.ts +2 -0
  9. package/dist/components-harmony-ets/button.ets +41 -78
  10. package/dist/components-harmony-ets/checkbox.ets +19 -209
  11. package/dist/components-harmony-ets/form.ets +38 -160
  12. package/dist/components-harmony-ets/icon.ets +31 -83
  13. package/dist/components-harmony-ets/image.ets +22 -78
  14. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  15. package/dist/components-harmony-ets/input.ets +10 -67
  16. package/dist/components-harmony-ets/label.ets +52 -173
  17. package/dist/components-harmony-ets/movableArea.ets +89 -0
  18. package/dist/components-harmony-ets/movableView.ets +67 -0
  19. package/dist/components-harmony-ets/picker.ets +32 -147
  20. package/dist/components-harmony-ets/progress.ets +47 -0
  21. package/dist/components-harmony-ets/pseudo.ets +80 -0
  22. package/dist/components-harmony-ets/radio.ets +19 -210
  23. package/dist/components-harmony-ets/richText.ets +22 -102
  24. package/dist/components-harmony-ets/scrollView.ets +66 -169
  25. package/dist/components-harmony-ets/slider.ets +10 -72
  26. package/dist/components-harmony-ets/style.ets +244 -0
  27. package/dist/components-harmony-ets/swiper.ets +30 -87
  28. package/dist/components-harmony-ets/switch.ets +9 -71
  29. package/dist/components-harmony-ets/text.ets +38 -89
  30. package/dist/components-harmony-ets/textArea.ets +10 -67
  31. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  32. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  33. package/dist/components-harmony-ets/utils/flexManager.ets +8 -7
  34. package/dist/components-harmony-ets/utils/helper.ets +5 -4
  35. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  36. package/dist/components-harmony-ets/utils/index.ts +55 -2
  37. package/dist/components-harmony-ets/utils/styles.ets +45 -85
  38. package/dist/components-harmony-ets/video.ets +33 -88
  39. package/dist/components-harmony-ets/view.ets +47 -160
  40. package/dist/components-harmony-ets/webView.ets +44 -99
  41. package/dist/index.d.ts +151 -0
  42. package/dist/index.js +58 -29
  43. package/dist/index.js.map +1 -1
  44. package/dist/runtime-ets/bom/window.ts +4 -2
  45. package/dist/runtime-ets/current.ts +2 -0
  46. package/dist/runtime-ets/dom/bind.ts +0 -1
  47. package/dist/runtime-ets/dom/cssNesting.ts +311 -0
  48. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +15 -40
  49. package/dist/runtime-ets/dom/document.ts +21 -8
  50. package/dist/runtime-ets/dom/element/element.ts +53 -9
  51. package/dist/runtime-ets/dom/element/form.ts +11 -4
  52. package/dist/runtime-ets/dom/element/index.ts +12 -1
  53. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  54. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  55. package/dist/runtime-ets/dom/element/normal.ts +8 -3
  56. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  57. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  58. package/dist/runtime-ets/dom/element/text.ts +1 -0
  59. package/dist/runtime-ets/dom/element/video.ts +1 -0
  60. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  61. package/dist/runtime-ets/dom/event.ts +0 -1
  62. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  63. package/dist/runtime-ets/dom/node.ts +18 -17
  64. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +184 -207
  65. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  66. package/dist/runtime-ets/dom/stylesheet/type.ts +18 -6
  67. package/dist/runtime-ets/dom/stylesheet/util.ts +19 -15
  68. package/dist/runtime-ets/index.ts +2 -2
  69. package/dist/runtime-ets/interface/event.ts +1 -1
  70. package/dist/runtime-ets/utils/index.ts +24 -9
  71. package/dist/runtime-framework/react/app.ts +5 -1
  72. package/dist/runtime-framework/react/hooks.ts +3 -3
  73. package/dist/runtime-framework/react/native-page.ts +14 -9
  74. package/dist/runtime-framework/react/page.ts +1 -0
  75. package/dist/runtime-framework/solid/hooks.ts +3 -3
  76. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  77. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  78. package/dist/runtime-utils.d.ts +825 -0
  79. package/dist/runtime-utils.js +185 -91
  80. package/dist/runtime-utils.js.map +1 -1
  81. package/dist/runtime.d.ts +1 -0
  82. package/dist/runtime.js +185 -91
  83. package/dist/runtime.js.map +1 -1
  84. package/index.js +3 -1
  85. package/package.json +10 -10
  86. package/types/index.d.ts +4 -0
  87. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -14,6 +14,8 @@ import {
14
14
  TaroSwitchElement,
15
15
  TaroTextAreaElement
16
16
  } from './form'
17
+ import { TaroMovableAreaElement } from './movableArea'
18
+ import { TaroMovableViewElement } from './movableView'
17
19
  import {
18
20
  TaroButtonElement,
19
21
  TaroIconElement,
@@ -24,10 +26,11 @@ import {
24
26
  TaroSwiperItemElement,
25
27
  TaroViewElement
26
28
  } from './normal'
29
+ import { TaroProgressElement } from './progress'
27
30
  import { TaroScrollViewElement } from './scrollView'
28
31
  import { TaroTextElement } from './text'
29
32
  import { TaroVideoElement } from './video'
30
- import { TaroWebViewElement } from './webView'
33
+ import { TaroInnerHtmlElement, TaroWebViewElement } from './webView'
31
34
 
32
35
  export function initHarmonyElement () {
33
36
  Current.createHarmonyElement = (tagName: string) => {
@@ -36,6 +39,9 @@ export function initHarmonyElement () {
36
39
  case 'image': return new TaroImageElement()
37
40
  case 'text': return new TaroTextElement()
38
41
  case 'button': return new TaroButtonElement()
42
+ case 'movable-area': return new TaroMovableAreaElement()
43
+ case 'movable-view': return new TaroMovableViewElement()
44
+ case 'progress': return new TaroProgressElement()
39
45
  case 'scroll-view': return new TaroScrollViewElement()
40
46
  case 'checkbox-group': return new TaroCheckboxGroupElement()
41
47
  case 'input': return new TaroInputElement()
@@ -54,6 +60,7 @@ export function initHarmonyElement () {
54
60
  case 'textarea': return new TaroTextAreaElement()
55
61
  case 'form': return new TaroFormElement()
56
62
  case 'web-view': return new TaroWebViewElement()
63
+ case 'inner-html': return new TaroInnerHtmlElement()
57
64
  default: return new TaroElement(tagName)
58
65
  }
59
66
  }
@@ -73,9 +80,13 @@ export {
73
80
  TaroFormElement,
74
81
  TaroIconElement,
75
82
  TaroImageElement,
83
+ TaroInnerHtmlElement,
76
84
  TaroInputElement,
77
85
  TaroLabelElement,
86
+ TaroMovableAreaElement,
87
+ TaroMovableViewElement,
78
88
  TaroPickerElement,
89
+ TaroProgressElement,
79
90
  TaroRadioElement,
80
91
  TaroRadioGroupElement,
81
92
  TaroRichTextElement,
@@ -0,0 +1,12 @@
1
+
2
+ import { TaroElement } from './element'
3
+
4
+ import type { MovableAreaProps } from '@tarojs/components/types'
5
+
6
+ @Observed
7
+ export class TaroMovableAreaElement extends TaroElement<MovableAreaProps> {
8
+
9
+ constructor() {
10
+ super('MovableArea')
11
+ }
12
+ }
@@ -0,0 +1,193 @@
1
+ import { TaroElement } from './element'
2
+
3
+ import type { MovableViewProps } from '@tarojs/components/types'
4
+
5
+ type Tsize = {
6
+ w: number
7
+ h: number
8
+ }
9
+ type Tpoint = {
10
+ x: number
11
+ y: number
12
+ }
13
+
14
+ function calcPosition(postion: number, start: number, end: number) {
15
+ if (postion <= end && postion >= start) {
16
+ return postion
17
+ } else if (postion < start) {
18
+ return start
19
+ } else {
20
+ return end
21
+ }
22
+ }
23
+
24
+ @Observed
25
+ export class TaroMovableViewElement extends TaroElement<MovableViewProps & { animation: undefined }> {
26
+ _scaleValue = 1
27
+ _scalevalueTemp = 1
28
+
29
+ // 父级区别的大小
30
+ _area?: Tsize
31
+ // 自己元素的大小
32
+ _selfSize?: Tsize
33
+
34
+ // 元素的位置
35
+ _position: Tpoint = {
36
+ x: 0,
37
+ y: 0,
38
+ }
39
+
40
+ _positionTemp: Tpoint = {
41
+ x: 0,
42
+ y: 0,
43
+ }
44
+
45
+ constructor() {
46
+ super('MovableView')
47
+ }
48
+
49
+ get _outOfBounds() {
50
+ if (this.getAttribute('outOfBounds')) {
51
+ return this.selfSize ? this.selfSize.w / 3 : 0
52
+ }
53
+ return 0
54
+ }
55
+
56
+ set area(val: Tsize) {
57
+ this._area = val
58
+ }
59
+
60
+ get area(): Tsize | undefined {
61
+ return this._area
62
+ }
63
+
64
+ startScale() {
65
+ this._scalevalueTemp = this._scaleValue
66
+ }
67
+
68
+ doScale(val: number) {
69
+ const scale = this.getAttribute('scale')
70
+
71
+ // 禁止缩放的时候不生效
72
+ if (scale) {
73
+ this.scaleValue = val * this._scalevalueTemp
74
+ }
75
+ }
76
+
77
+ set scaleValue(val: number) {
78
+ if (this.checkScaleValueInBounds(val)) {
79
+ this._scaleValue = val
80
+
81
+ this.checkPositionBoundary(this.position, val)
82
+
83
+ const bindscale = this.getAttribute('bindscale')
84
+ typeof bindscale === 'function' && bindscale({ ...this.position, scale: this.scaleValue })
85
+ }
86
+ }
87
+
88
+ get scaleValue() {
89
+ return this._scaleValue
90
+ }
91
+
92
+ startMove() {
93
+ this._positionTemp = this._position
94
+ }
95
+
96
+ doMove(val: Tpoint) {
97
+ if (!this.area || !this.selfSize) return
98
+ if (this.getAttribute('disabled')) return
99
+ const direction = this.getAttribute('direction')
100
+
101
+ // 容器的宽高终点
102
+ const areaWidthEnd = this.area.w - this.selfSize.w * this.scaleValue
103
+ const areaHeightEnd = this.area.h - this.selfSize.h * this.scaleValue
104
+
105
+ const incrementWidth = (this.scaleValue - 1) * this.selfSize.w
106
+ const incrementHeight = (this.scaleValue - 1) * this.selfSize.h
107
+
108
+ let x = this._positionTemp.x
109
+ let y = this._positionTemp.y
110
+ if (['all', 'horizontal'].includes(direction)) {
111
+ const nextX = this._positionTemp.x + val.x * this.scaleValue
112
+ x = calcPosition(
113
+ nextX,
114
+ incrementWidth * 0.5 - this._outOfBounds,
115
+ areaWidthEnd + incrementWidth * 0.5 + this._outOfBounds
116
+ )
117
+ }
118
+
119
+ if (['all', 'vertical'].includes(direction)) {
120
+ const nextY = this._positionTemp.y + val.y * this.scaleValue
121
+ y = calcPosition(
122
+ nextY,
123
+ incrementHeight * 0.5 - this._outOfBounds,
124
+ areaHeightEnd + incrementHeight * 0.5 + this._outOfBounds
125
+ )
126
+ }
127
+ const bindchange = this.getAttribute('bindchange')
128
+ if (typeof bindchange === 'function') {
129
+ bindchange({ x, y, source: 'touch' })
130
+ }
131
+ this.position = {
132
+ x: x,
133
+ y: y,
134
+ }
135
+ }
136
+
137
+ get position() {
138
+ return this._position
139
+ }
140
+
141
+ set position(val: Tpoint) {
142
+ this._position = val
143
+ }
144
+
145
+ set selfSize(val: Tsize) {
146
+ this._selfSize = val
147
+ }
148
+
149
+ get selfSize(): Tsize | undefined {
150
+ return this._selfSize
151
+ }
152
+
153
+ checkPositionBoundary(position: Tpoint, scale: number) {
154
+ if (!this.area || !this.selfSize) {
155
+ return { x: 0, y: 0 }
156
+ }
157
+
158
+ const areaWidthEnd = this.area.w - this.selfSize.w * scale
159
+ const areaHeightEnd = this.area.h - this.selfSize.h * scale
160
+
161
+ const incrementWidth = (scale - 1) * this.selfSize.w
162
+ const incrementHeight = (scale - 1) * this.selfSize.h
163
+
164
+ this.position = {
165
+ x: calcPosition(position.x, incrementWidth * 0.5, areaWidthEnd + incrementWidth * 0.5),
166
+ y: calcPosition(position.y, incrementHeight * 0.5, areaHeightEnd + incrementHeight * 0.5),
167
+ }
168
+ }
169
+
170
+ checkScaleValueInBounds(currentScale: number) {
171
+ const scaleMin = this.getAttribute('scaleMin')
172
+ const scaleMax = this.getAttribute('scaleMax')
173
+
174
+ if (scaleMin && Number(scaleMin) >= 0.1 && currentScale < Number(scaleMin)) {
175
+ return false
176
+ } else if (scaleMax && Number(scaleMax) >= 0.1 && currentScale > Number(scaleMax)) {
177
+ return false
178
+ }
179
+
180
+ return true
181
+ }
182
+
183
+ public setAttribute(name: string, value: any): void {
184
+ if (name === 'x') {
185
+ this.checkPositionBoundary({ x: value, y: this.position.y }, this.scaleValue)
186
+ }
187
+ if (name === 'y') {
188
+ this.checkPositionBoundary({ x: this.position.x, y: value }, this.scaleValue)
189
+ }
190
+
191
+ super.setAttribute(name, value)
192
+ }
193
+ }
@@ -12,43 +12,48 @@ import type {
12
12
  ViewProps
13
13
  } from '@tarojs/components/types'
14
14
 
15
+ @Observed
15
16
  class TaroViewElement extends TaroElement<ViewProps> {
16
17
  constructor() {
17
18
  super('View')
18
19
  }
19
20
  }
20
21
 
22
+ @Observed
21
23
  class TaroImageElement extends TaroElement<ImageProps> {
22
24
  constructor() {
23
25
  super('Image')
24
26
  }
25
27
  }
26
28
 
29
+ @Observed
27
30
  class TaroButtonElement extends TaroElement<ButtonProps> {
28
31
  constructor() {
29
32
  super('Button')
30
33
  }
31
34
  }
32
35
 
33
-
36
+ @Observed
34
37
  class TaroIconElement extends TaroElement<IconProps>{
35
38
  constructor() {
36
39
  super('Icon')
37
40
  }
38
41
  }
39
-
42
+ @Observed
40
43
  class TaroLabelElement extends TaroElement<LabelProps>{
41
44
  constructor() {
42
45
  super('Label')
43
46
  }
44
47
  }
45
48
 
49
+ @Observed
46
50
  class TaroRichTextElement extends TaroElement<RichTextProps>{
47
51
  constructor() {
48
52
  super('RichText')
49
53
  }
50
54
  }
51
55
 
56
+ @Observed
52
57
  class TaroSwiperElement extends TaroElement<SwiperProps>{
53
58
  controller: SwiperController = new SwiperController()
54
59
 
@@ -57,13 +62,13 @@ class TaroSwiperElement extends TaroElement<SwiperProps>{
57
62
  }
58
63
  }
59
64
 
65
+ @Observed
60
66
  class TaroSwiperItemElement extends TaroElement<SwiperItemProps>{
61
67
  constructor() {
62
68
  super('SwiperItem')
63
69
  }
64
70
  }
65
71
 
66
-
67
72
  export {
68
73
  TaroButtonElement,
69
74
  TaroIconElement,
@@ -0,0 +1,13 @@
1
+
2
+ import { TaroElement } from './element'
3
+
4
+ import type { ProgressProps } from '@tarojs/components/types'
5
+
6
+ @Observed
7
+ export class TaroProgressElement extends TaroElement<ProgressProps> {
8
+
9
+ constructor() {
10
+ super('Progress')
11
+
12
+ }
13
+ }
@@ -3,6 +3,7 @@ import { TaroElement } from './element'
3
3
 
4
4
  import type { ScrollViewProps } from '@tarojs/components/types'
5
5
 
6
+ @Observed
6
7
  export class TaroScrollViewElement extends TaroElement<ScrollViewProps> {
7
8
  scroller: Scroller = new Scroller()
8
9
 
@@ -3,6 +3,7 @@ import { TaroElement } from './element'
3
3
 
4
4
  import type { TextProps } from '@tarojs/components/types'
5
5
 
6
+ @Observed
6
7
  export class TaroTextElement extends TaroElement<TextProps> {
7
8
  constructor() {
8
9
  super('Text')
@@ -2,6 +2,7 @@ import { TaroElement } from './element'
2
2
 
3
3
  import type { VideoProps } from '@tarojs/components/types'
4
4
 
5
+ @Observed
5
6
  export class TaroVideoElement extends TaroElement<VideoProps> {
6
7
  _currentTime = 0
7
8
 
@@ -5,6 +5,14 @@ import { TaroElement } from './element'
5
5
 
6
6
  import type { WebViewProps } from '@tarojs/components/types'
7
7
 
8
+ @Observed
9
+ export class TaroInnerHtmlElement extends TaroElement {
10
+ constructor() {
11
+ super('InnerHtml')
12
+ }
13
+ }
14
+
15
+ @Observed
8
16
  export class TaroWebViewElement extends TaroElement<WebViewProps>{
9
17
  ports: web_webview.WebMessagePort[] = []
10
18
 
@@ -55,7 +55,6 @@ export class TaroEvent<T = any> {
55
55
  }
56
56
  }
57
57
 
58
-
59
58
  export function createEvent (event: TaroEvent | string, type?: string, node?: TaroElement) {
60
59
  if (typeof event === 'string') {
61
60
  // For Vue3 using document.createEvent
@@ -68,12 +68,10 @@ class TaroEventTarget extends Events {
68
68
  }
69
69
  }
70
70
 
71
-
72
71
  if (event._stop) {
73
72
  this._stopPropagation(event)
74
73
  }
75
74
 
76
-
77
75
  return listeners != null
78
76
  }
79
77
 
@@ -95,5 +93,4 @@ class TaroEventTarget extends Events {
95
93
  }
96
94
  }
97
95
 
98
-
99
96
  export { TaroEventTarget }
@@ -63,27 +63,27 @@ export class TaroNode extends TaroDataSourceElement {
63
63
  return this.childNodes.findIndex(node => node._nid === refChild._nid)
64
64
  }
65
65
 
66
+ public updateTextNode () {
67
+ // @ts-ignore
68
+ if (this.childNodes.length <= 0 || this.tagName !== 'VIEW') return
69
+
70
+ // TextNode 不具备 props 更新能力,需要由父节点来进行触发
71
+ this.childNodes.forEach(item => {
72
+ if (item.nodeType !== NodeType.TEXT_NODE) return
73
+
74
+ item._updateTrigger++
75
+ })
76
+ }
77
+
66
78
  // 更新对应的 ArkUI 组件
67
79
  public updateComponent () {
68
- if (!this._isCompileMode && (!this.parentNode || !this.parentNode.listeners?.length)) return
69
-
70
- const idx = this.parentNode.findIndex(this)
80
+ if (!this._isCompileMode) return
71
81
 
72
- if (this._isCompileMode) {
73
- // 半编译模式下走 @State 的更新模式
74
- if (this._isDynamicNode) {
75
- this._updateTrigger++
76
- } else {
77
- this.parentNode.updateComponent()
78
- }
82
+ // 半编译模式下走 @State 的更新模式
83
+ if (this._isDynamicNode) {
84
+ this._updateTrigger++
79
85
  } else {
80
- // 非半编译模式下走 LazyForEach 的更新模式
81
- if (idx >= 0) {
82
- this._updateTrigger++
83
- this.parentNode.notifyDataChange(idx)
84
- } else {
85
- this.parentNode.notifyDataReload()
86
- }
86
+ this.parentNode.updateComponent()
87
87
  }
88
88
  }
89
89
 
@@ -229,6 +229,7 @@ export class TaroNode extends TaroDataSourceElement {
229
229
  }
230
230
  }
231
231
 
232
+ @Observed
232
233
  export class TaroTextNode extends TaroNode {
233
234
  constructor(value = '', nodeName = '#text', nodeType: NodeType = NodeType.TEXT_NODE) {
234
235
  super(nodeName, nodeType)