@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27 → 4.0.0-alpha.0

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 (176) hide show
  1. package/dist/apis/apis.ts +6 -2
  2. package/dist/apis/base/crypto.ts +4 -0
  3. package/dist/apis/base/debug.ts +5 -0
  4. package/dist/apis/base/index.ts +9 -1
  5. package/dist/apis/base/performance.ts +8 -0
  6. package/dist/apis/base/system.ts +1 -1
  7. package/dist/apis/base/update.ts +5 -0
  8. package/dist/apis/base/weapp/app-event.ts +75 -0
  9. package/dist/apis/base/weapp/life-cycle.ts +21 -0
  10. package/dist/apis/canvas/index.ts +18 -0
  11. package/dist/apis/data-analysis/index.ts +6 -0
  12. package/dist/apis/device/accelerometer.ts +2 -1
  13. package/dist/apis/device/accessibility.ts +4 -0
  14. package/dist/apis/device/battery.ts +2 -2
  15. package/dist/apis/device/bluetooth-ble.ts +19 -0
  16. package/dist/apis/device/bluetooth-peripheral.ts +6 -0
  17. package/dist/apis/device/bluetooth.ts +16 -0
  18. package/dist/apis/device/calendar.ts +5 -0
  19. package/dist/apis/device/clipboard.ts +1 -1
  20. package/dist/apis/device/compass.ts +21 -0
  21. package/dist/apis/device/contact.ts +5 -0
  22. package/dist/apis/device/crypto.ts +4 -0
  23. package/dist/apis/device/gyroscope.ts +7 -0
  24. package/dist/apis/device/iBeacon.ts +10 -0
  25. package/dist/apis/device/index.ts +15 -0
  26. package/dist/apis/device/keyboard.ts +2 -1
  27. package/dist/apis/device/motion.ts +6 -0
  28. package/dist/apis/device/network.ts +26 -9
  29. package/dist/apis/device/nfc.ts +10 -0
  30. package/dist/apis/device/phone.ts +2 -1
  31. package/dist/apis/device/scan.ts +4 -0
  32. package/dist/apis/device/screen.ts +2 -1
  33. package/dist/apis/device/sms.ts +4 -0
  34. package/dist/apis/device/vibrate.ts +19 -11
  35. package/dist/apis/device/wifi.ts +15 -0
  36. package/dist/apis/ext/index.ts +5 -0
  37. package/dist/apis/files/index.ts +2 -1
  38. package/dist/apis/files/manager.ts +2 -1
  39. package/dist/apis/framework/index.ts +5 -6
  40. package/dist/apis/location/index.ts +61 -68
  41. package/dist/apis/media/EditorContext.ts +32 -0
  42. package/dist/apis/media/audio/index.ts +18 -0
  43. package/dist/apis/media/background-audio/index.ts +16 -0
  44. package/dist/apis/media/camera.ts +16 -0
  45. package/dist/apis/media/common.ts +2 -1
  46. package/dist/apis/media/{image.ts → image/index.ts} +3 -2
  47. package/dist/apis/media/index.ts +10 -0
  48. package/dist/apis/media/live.ts +5 -0
  49. package/dist/apis/media/map.ts +4 -0
  50. package/dist/apis/media/media-recorder.ts +4 -0
  51. package/dist/apis/media/recorder.ts +6 -0
  52. package/dist/apis/media/video/VideoContext.ts +19 -0
  53. package/dist/apis/media/{video.ts → video/index.ts} +12 -2
  54. package/dist/apis/media/video-decoder.ts +4 -0
  55. package/dist/apis/media/video-processing.ts +4 -0
  56. package/dist/apis/media/voip.ts +19 -0
  57. package/dist/apis/network/index.ts +3 -0
  58. package/dist/apis/network/mdns.ts +13 -0
  59. package/dist/apis/network/request.ts +2 -1
  60. package/dist/apis/network/tcp.ts +4 -0
  61. package/dist/apis/network/udp.ts +4 -0
  62. package/dist/apis/network/webSocket.ts +2 -6
  63. package/dist/apis/open-api/account.ts +4 -0
  64. package/dist/apis/open-api/address.ts +4 -0
  65. package/dist/apis/open-api/authorize.ts +5 -0
  66. package/dist/apis/open-api/card.ts +5 -0
  67. package/dist/apis/open-api/channels-live.ts +11 -0
  68. package/dist/apis/open-api/customer-service.ts +4 -0
  69. package/dist/apis/open-api/device-voip.ts +5 -0
  70. package/dist/apis/open-api/facial.ts +7 -0
  71. package/dist/apis/open-api/favorites.ts +5 -0
  72. package/dist/apis/open-api/group.ts +4 -0
  73. package/dist/apis/open-api/index.ts +20 -6
  74. package/dist/apis/open-api/invoice.ts +5 -0
  75. package/dist/apis/open-api/license-plate.ts +4 -0
  76. package/dist/apis/open-api/login.ts +6 -0
  77. package/dist/apis/open-api/my-miniprogram.ts +4 -0
  78. package/dist/apis/open-api/privacy.ts +7 -0
  79. package/dist/apis/open-api/red-package.ts +4 -0
  80. package/dist/apis/open-api/settings.ts +5 -0
  81. package/dist/apis/open-api/soter.ts +6 -0
  82. package/dist/apis/open-api/subscribe-message.ts +6 -0
  83. package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
  84. package/dist/apis/open-api/werun.ts +5 -0
  85. package/dist/apis/payment/index.ts +6 -0
  86. package/dist/apis/route/index.ts +4 -28
  87. package/dist/apis/share/index.ts +33 -0
  88. package/dist/apis/storage/background-fetch.ts +7 -0
  89. package/dist/apis/storage/cache-manager.ts +4 -0
  90. package/dist/apis/storage/index.ts +20 -18
  91. package/dist/apis/ui/{animation.ts → animation/animation.ts} +2 -2
  92. package/dist/apis/ui/animation/index.ts +7 -0
  93. package/dist/apis/ui/background.ts +2 -18
  94. package/dist/apis/ui/custom-component.ts +8 -0
  95. package/dist/apis/ui/fonts.ts +4 -0
  96. package/dist/apis/ui/index.ts +8 -10
  97. package/dist/apis/ui/interaction/index.ts +3 -0
  98. package/dist/apis/ui/menu.ts +4 -0
  99. package/dist/apis/ui/navigation-bar/index.ts +60 -21
  100. package/dist/apis/ui/pull-down-refresh.ts +1 -1
  101. package/dist/apis/{page → ui/scroll}/index.ts +27 -22
  102. package/dist/apis/ui/sticky.ts +4 -0
  103. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +3 -5
  104. package/dist/apis/ui/window.ts +20 -0
  105. package/dist/apis/utils/handler.ts +4 -4
  106. package/dist/apis/worker/index.ts +4 -0
  107. package/dist/apis/wxml/IntersectionObserver.ts +12 -21
  108. package/dist/apis/wxml/index.ts +5 -2
  109. package/dist/apis/wxml/nodesRef.ts +2 -2
  110. package/dist/apis/wxml/selectorQuery.ts +3 -4
  111. package/dist/components-harmony-ets/button.ets +90 -64
  112. package/dist/components-harmony-ets/checkbox.ets +53 -98
  113. package/dist/components-harmony-ets/form.ets +16 -112
  114. package/dist/components-harmony-ets/icon.ets +59 -46
  115. package/dist/components-harmony-ets/image.ets +15 -40
  116. package/dist/components-harmony-ets/innerHtml.ets +6 -74
  117. package/dist/components-harmony-ets/input.ets +58 -128
  118. package/dist/components-harmony-ets/label.ets +43 -69
  119. package/dist/components-harmony-ets/picker.ets +114 -137
  120. package/dist/components-harmony-ets/radio.ets +55 -103
  121. package/dist/components-harmony-ets/richText.ets +17 -41
  122. package/dist/components-harmony-ets/scrollView.ets +69 -101
  123. package/dist/components-harmony-ets/slider.ets +35 -58
  124. package/dist/components-harmony-ets/swiper.ets +24 -135
  125. package/dist/components-harmony-ets/switch.ets +25 -55
  126. package/dist/components-harmony-ets/text.ets +42 -46
  127. package/dist/components-harmony-ets/textArea.ets +39 -107
  128. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  129. package/dist/components-harmony-ets/utils/flexManager.ets +3 -88
  130. package/dist/components-harmony-ets/utils/helper.ets +2 -62
  131. package/dist/components-harmony-ets/utils/index.ts +1 -1
  132. package/dist/components-harmony-ets/utils/styles.ets +6 -9
  133. package/dist/components-harmony-ets/video.ets +63 -92
  134. package/dist/components-harmony-ets/view.ets +65 -40
  135. package/dist/index.js +33 -4
  136. package/dist/index.js.map +1 -1
  137. package/dist/runtime-ets/bom/getComputedStyle.ts +1 -1
  138. package/dist/runtime-ets/dom/bind.ts +80 -0
  139. package/dist/runtime-ets/dom/class-list.ts +2 -4
  140. package/dist/runtime-ets/dom/comment.ts +1 -2
  141. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +1 -1
  142. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  143. package/dist/runtime-ets/dom/document.ts +14 -43
  144. package/dist/runtime-ets/dom/element/element.ts +162 -0
  145. package/dist/runtime-ets/dom/element/form.ts +397 -0
  146. package/dist/runtime-ets/dom/element/index.ts +89 -0
  147. package/dist/runtime-ets/dom/element/normal.ts +75 -0
  148. package/dist/runtime-ets/dom/element/scrollView.ts +14 -0
  149. package/dist/runtime-ets/dom/element/text.ts +17 -0
  150. package/dist/runtime-ets/dom/element/video.ts +49 -0
  151. package/dist/runtime-ets/dom/event.ts +24 -1
  152. package/dist/runtime-ets/dom/eventTarget.ts +2 -1
  153. package/dist/runtime-ets/dom/node.ts +74 -44
  154. package/dist/runtime-ets/dom/stylesheet/index.ts +136 -23
  155. package/dist/runtime-ets/dom/stylesheet/type.ts +4 -3
  156. package/dist/runtime-ets/dom/stylesheet/util.ts +71 -1
  157. package/dist/runtime-ets/index.ts +0 -1
  158. package/dist/runtime-ets/utils/bind.ts +3 -14
  159. package/dist/runtime-ets/utils/index.ts +12 -7
  160. package/dist/runtime-ets/utils/info.ts +22 -50
  161. package/dist/runtime-framework/react/app.ts +3 -6
  162. package/dist/runtime-framework/react/page.ts +2 -9
  163. package/dist/runtime-framework/solid/page.ts +0 -6
  164. package/dist/runtime-utils.js +1150 -339
  165. package/dist/runtime-utils.js.map +1 -1
  166. package/dist/runtime.js +1150 -339
  167. package/dist/runtime.js.map +1 -1
  168. package/package.json +8 -8
  169. package/types/runtime.d.ts +4 -0
  170. package/LICENSE +0 -160
  171. package/dist/components-harmony-ets/base.ets +0 -63
  172. package/dist/components-harmony-ets/element.ets +0 -223
  173. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  174. package/dist/runtime-ets/dom/element.ts +0 -457
  175. package/dist/runtime-ets/dom/text.ts +0 -19
  176. package/types/api.d.ts +0 -4
@@ -0,0 +1,89 @@
1
+ import { Current } from '../../current'
2
+ import { TaroTextNode } from '../node'
3
+ import { TaroElement } from './element'
4
+ import {
5
+ FormElement,
6
+ TaroCheckboxElement,
7
+ TaroCheckboxGroupElement,
8
+ TaroFormElement,
9
+ TaroInputElement,
10
+ TaroPickerElement,
11
+ TaroRadioElement,
12
+ TaroRadioGroupElement,
13
+ TaroSliderElement,
14
+ TaroSwitchElement,
15
+ TaroTextAreaElement
16
+ } from './form'
17
+ import {
18
+ TaroButtonElement,
19
+ TaroIconElement,
20
+ TaroImageElement,
21
+ TaroLabelElement,
22
+ TaroRichTextElement,
23
+ TaroSwiperElement,
24
+ TaroSwiperItemElement,
25
+ TaroViewElement
26
+ } from './normal'
27
+ import { TaroScrollViewElement } from './scrollView'
28
+ import { TaroTextElement } from './text'
29
+ import { TaroVideoElement } from './video'
30
+
31
+ export function initHarmonyElement () {
32
+ Current.createHarmonyElement = (tagName: string) => {
33
+ switch (tagName) {
34
+ case 'view': return new TaroViewElement()
35
+ case 'image': return new TaroImageElement()
36
+ case 'text': return new TaroTextElement()
37
+ case 'button': return new TaroButtonElement()
38
+ case 'scroll-view': return new TaroScrollViewElement()
39
+ case 'checkbox-group': return new TaroCheckboxGroupElement()
40
+ case 'input': return new TaroInputElement()
41
+ case 'picker': return new TaroPickerElement()
42
+ case 'radio-group': return new TaroRadioGroupElement()
43
+ case 'slider': return new TaroSliderElement()
44
+ case 'switch': return new TaroSwitchElement()
45
+ case 'video': return new TaroVideoElement()
46
+ case 'checkbox': return new TaroCheckboxElement()
47
+ case 'radio': return new TaroRadioElement()
48
+ case 'icon': return new TaroIconElement()
49
+ case 'label': return new TaroLabelElement()
50
+ case 'rich-text': return new TaroRichTextElement()
51
+ case 'swiper': return new TaroSwiperElement()
52
+ case 'swiper-item': return new TaroSwiperItemElement()
53
+ case 'textarea': return new TaroTextAreaElement()
54
+ case 'form': return new TaroFormElement()
55
+ default: return new TaroElement(tagName)
56
+ }
57
+ }
58
+
59
+ Current.createTextNode = (value: string): TaroTextNode => {
60
+ const node = new TaroTextNode(value)
61
+ return node
62
+ }
63
+ }
64
+
65
+ export {
66
+ FormElement,
67
+ TaroButtonElement,
68
+ TaroCheckboxElement,
69
+ TaroCheckboxGroupElement,
70
+ TaroElement,
71
+ TaroFormElement,
72
+ TaroIconElement,
73
+ TaroImageElement,
74
+ TaroInputElement,
75
+ TaroLabelElement,
76
+ TaroPickerElement,
77
+ TaroRadioElement,
78
+ TaroRadioGroupElement,
79
+ TaroRichTextElement,
80
+ TaroScrollViewElement,
81
+ TaroSliderElement,
82
+ TaroSwiperElement,
83
+ TaroSwiperItemElement,
84
+ TaroSwitchElement,
85
+ TaroTextAreaElement,
86
+ TaroTextElement,
87
+ TaroVideoElement,
88
+ TaroViewElement
89
+ }
@@ -0,0 +1,75 @@
1
+
2
+ import { TaroElement } from './element'
3
+
4
+ import type {
5
+ ButtonProps,
6
+ IconProps,
7
+ ImageProps,
8
+ LabelProps,
9
+ RichTextProps,
10
+ SwiperItemProps,
11
+ SwiperProps,
12
+ ViewProps
13
+ } from '@tarojs/components/types'
14
+
15
+ class TaroViewElement extends TaroElement<ViewProps> {
16
+ constructor() {
17
+ super('View')
18
+ }
19
+ }
20
+
21
+ class TaroImageElement extends TaroElement<ImageProps> {
22
+ constructor() {
23
+ super('Image')
24
+ }
25
+ }
26
+
27
+ class TaroButtonElement extends TaroElement<ButtonProps> {
28
+ constructor() {
29
+ super('Button')
30
+ }
31
+ }
32
+
33
+
34
+ class TaroIconElement extends TaroElement<IconProps>{
35
+ constructor() {
36
+ super('Icon')
37
+ }
38
+ }
39
+
40
+ class TaroLabelElement extends TaroElement<LabelProps>{
41
+ constructor() {
42
+ super('Label')
43
+ }
44
+ }
45
+
46
+ class TaroRichTextElement extends TaroElement<RichTextProps>{
47
+ constructor() {
48
+ super('RichText')
49
+ }
50
+ }
51
+
52
+ class TaroSwiperElement extends TaroElement<SwiperProps>{
53
+ controller: SwiperController = new SwiperController()
54
+
55
+ constructor() {
56
+ super('Swiper')
57
+ }
58
+ }
59
+
60
+ class TaroSwiperItemElement extends TaroElement<SwiperItemProps>{
61
+ constructor() {
62
+ super('SwiperItem')
63
+ }
64
+ }
65
+
66
+ export {
67
+ TaroButtonElement,
68
+ TaroIconElement,
69
+ TaroImageElement,
70
+ TaroLabelElement,
71
+ TaroRichTextElement,
72
+ TaroSwiperElement,
73
+ TaroSwiperItemElement,
74
+ TaroViewElement,
75
+ }
@@ -0,0 +1,14 @@
1
+ import { bindScrollTo } from '../bind'
2
+ import { TaroElement } from './element'
3
+
4
+ import type { ScrollViewProps } from '@tarojs/components/types'
5
+
6
+ export class TaroScrollViewElement extends TaroElement<ScrollViewProps> {
7
+ scroller: Scroller = new Scroller()
8
+
9
+ constructor() {
10
+ super('ScrollView')
11
+
12
+ bindScrollTo(this)
13
+ }
14
+ }
@@ -0,0 +1,17 @@
1
+ import { TaroNode } from '../node'
2
+ import { TaroElement } from './element'
3
+
4
+ import type { TextProps } from '@tarojs/components/types'
5
+
6
+ export class TaroTextElement extends TaroElement<TextProps> {
7
+ constructor() {
8
+ super('Text')
9
+ }
10
+
11
+ public appendChild (child: TaroNode): TaroNode {
12
+ super.appendChild(child)
13
+
14
+ this.updateComponent()
15
+ return child
16
+ }
17
+ }
@@ -0,0 +1,49 @@
1
+ import { TaroElement } from './element'
2
+
3
+ import type { VideoProps } from '@tarojs/components/types'
4
+
5
+ export class TaroVideoElement extends TaroElement<VideoProps> {
6
+ _currentTime = 0
7
+
8
+ controller: VideoController = new VideoController()
9
+
10
+ constructor() {
11
+ super('Video')
12
+ }
13
+
14
+ async play() {
15
+ try {
16
+ this.controller.start()
17
+ return Promise.resolve()
18
+ } catch (e) {
19
+ return Promise.reject(e)
20
+ }
21
+ }
22
+
23
+ pause() {
24
+ try {
25
+ this.controller.pause()
26
+ return Promise.resolve()
27
+ } catch (e) {
28
+ return Promise.reject(e)
29
+ }
30
+ }
31
+
32
+ stop() {
33
+ try {
34
+ this.controller.stop()
35
+ return Promise.resolve()
36
+ } catch (e) {
37
+ return Promise.reject(e)
38
+ }
39
+ }
40
+
41
+ get currentTime() {
42
+ return this._currentTime
43
+ }
44
+
45
+ set currentTime(val: number) {
46
+ this._currentTime = val
47
+ this.controller.setCurrentTime(val)
48
+ }
49
+ }
@@ -1,7 +1,7 @@
1
1
  import { hooks } from '@tarojs/shared'
2
2
 
3
3
  import { CONFIRM, CURRENT_TARGET, INPUT, KEY_CODE, TARGET, TIME_STAMP, TYPE } from '../constant'
4
- import { TaroElement } from './element'
4
+ import { TaroElement } from './element/element'
5
5
 
6
6
  import type { EventOptions } from '../interface'
7
7
 
@@ -162,3 +162,26 @@ export function eventHandler (event, type: string, node: TaroElement) {
162
162
  })
163
163
  }
164
164
  }
165
+
166
+ export function createTaroEvent(type: string, opts: Partial<EventOptions> = {}, node?: TaroElement) {
167
+ opts.bubbles ||= true
168
+ opts.cancelable ||= true
169
+ const e = new TaroEvent(type, opts as Required<EventOptions>)
170
+
171
+ if (node) {
172
+ const properties: Record<string, PropertyDescriptor> = {}
173
+ properties.target = properties.currentTarget = {
174
+ get() {
175
+ return node
176
+ }
177
+ }
178
+ Object.defineProperties(e, properties)
179
+ }
180
+ for (const key in opts) {
181
+ if (['bubbles', 'cancelable'].includes(key)) {
182
+ continue
183
+ }
184
+ e[key] = opts[key]
185
+ }
186
+ return e
187
+ }
@@ -37,7 +37,7 @@ class TaroEventTarget extends Events {
37
37
 
38
38
  public removeEventListener (type: string, listener: fn) {
39
39
  const listeners = this.__listeners[type]
40
- if (listeners.length) {
40
+ if (listeners?.length) {
41
41
  this.__listeners[type] = listeners.filter(item => item !== listener)
42
42
  }
43
43
  }
@@ -95,4 +95,5 @@ class TaroEventTarget extends Events {
95
95
  }
96
96
  }
97
97
 
98
+
98
99
  export { TaroEventTarget }
@@ -1,9 +1,11 @@
1
1
  import { eventSource } from '@tarojs/runtime/dist/runtime.esm'
2
2
 
3
- import { TaroEventTarget } from './eventTarget'
3
+ import TaroDataSourceElement from './dataSource'
4
4
 
5
+ import type { StandardProps } from '@tarojs/components/types'
6
+ import type { TaroAny } from '../utils'
5
7
  import type { TaroDocument } from './document'
6
- import type { TaroElement } from './element'
8
+ import type { TaroElement } from './element/element'
7
9
 
8
10
  export enum NodeType {
9
11
  ELEMENT_NODE = 1,
@@ -23,41 +25,53 @@ function genId (): string {
23
25
  return `_n_${_id++}`
24
26
  }
25
27
 
26
- export class TaroNode extends TaroEventTarget {
28
+ export class TaroNode extends TaroDataSourceElement {
27
29
  public readonly nodeName: string
28
30
  public readonly nodeType: NodeType
29
31
  public childNodes: TaroNode[] = []
30
32
  public parentNode: TaroNode | null = null
31
33
  public _nid: string = genId()
32
34
 
33
- public _doc: TaroDocument
35
+ public _doc: TaroDocument | null = null
34
36
  // 是否为半编译模板下的节点
35
37
  public _isCompileMode = false
36
38
  // 是否为半编译模板下拥有自主更新权的节点
37
39
  public _isDynamicNode = false
38
- public _instance: any
39
40
 
40
- private _updateTrigger = 0
41
+ public _updateTrigger = 0
41
42
  private _textContent = ''
42
43
 
43
- constructor(nodeName, nodeType = NodeType.ELEMENT_NODE) {
44
+ constructor(nodeName: string, nodeType = NodeType.ELEMENT_NODE) {
44
45
  super()
46
+
45
47
  this.nodeType = nodeType
46
48
  this.nodeName = nodeName
47
- eventSource.set(this._nid, this as any)
49
+ eventSource.set(this._nid, this as TaroAny)
50
+ }
51
+
52
+ totalCount(): number {
53
+ return this.childNodes?.length || 0
48
54
  }
49
55
 
50
- protected findIndex (refChild: TaroNode): number {
51
- // @Observe 会影响 === 判断,只能比较 _nid
56
+ getData(index: number): TaroElement<StandardProps> {
57
+ return this.childNodes[index] as TaroElement
58
+ }
59
+
60
+ public findIndex (refChild: TaroNode): number {
52
61
  return this.childNodes.findIndex(node => node._nid === refChild._nid)
53
62
  }
54
63
 
55
64
  // 更新对应的 ArkUI 组件
56
65
  public updateComponent () {
57
- if (this._isDynamicNode || !this._isCompileMode) {
58
- this._updateTrigger += 1
66
+ if (!this.parentNode || !this.parentNode.listeners?.length) return
67
+
68
+ const idx = this.parentNode.findIndex(this)
69
+
70
+ if (idx >= 0) {
71
+ this._updateTrigger++
72
+ this.parentNode.notifyDataChange(idx)
59
73
  } else {
60
- this.parentNode?.updateComponent()
74
+ this.parentNode.notifyDataReload()
61
75
  }
62
76
  }
63
77
 
@@ -102,15 +116,11 @@ export class TaroNode extends TaroEventTarget {
102
116
  public set textContent (value: string) {
103
117
  if (this.nodeType === NodeType.TEXT_NODE) {
104
118
  this._textContent = value
105
- // if (this.parentNode && this.ownerDocument) {
106
- // const text = this.ownerDocument.createTextNode(value)
107
- // this.parentNode.replaceChild(text, this)
108
- // } else {
109
- // this._textContent = value
110
- // }
119
+ this.parentNode?.updateComponent()
111
120
  } else if (this.nodeType === NodeType.ELEMENT_NODE) {
112
- const text = this.ownerDocument.createTextNode(value)
113
- this.childNodes = [text]
121
+ const node = new TaroTextNode(value)
122
+ node._doc = this.ownerDocument
123
+ this.childNodes = [node]
114
124
  }
115
125
  }
116
126
 
@@ -125,13 +135,14 @@ export class TaroNode extends TaroEventTarget {
125
135
  }
126
136
  }
127
137
 
128
- public set nodeValue (value: string) {
129
- if (this.nodeType === NodeType.TEXT_NODE) {
138
+ public set nodeValue (value: string | null) {
139
+ if (this.nodeType === NodeType.TEXT_NODE && value) {
130
140
  this.textContent = value
141
+ this.parentNode?.updateComponent()
131
142
  }
132
143
  }
133
144
 
134
- public get ownerDocument (): TaroDocument {
145
+ public get ownerDocument (): TaroDocument | null {
135
146
  return this._doc
136
147
  }
137
148
 
@@ -144,8 +155,9 @@ export class TaroNode extends TaroEventTarget {
144
155
  public appendChild (child: TaroNode): TaroNode {
145
156
  child.parentNode?.removeChild(child)
146
157
  child.parentNode = this
147
- // this.childNodes.push(child)
148
- this.childNodes = [...this.childNodes, child]
158
+
159
+ this.childNodes.push(child)
160
+ this.notifyDataAdd(this.childNodes.length - 1)
149
161
 
150
162
  checkIsCompileModeAndInstallAfterDOMAction(child, this)
151
163
  return child
@@ -158,11 +170,9 @@ export class TaroNode extends TaroEventTarget {
158
170
  this.appendChild(newNode)
159
171
  } else {
160
172
  const idxOfRef = this.findIndex(referenceNode)
161
- this.childNodes = [
162
- ...this.childNodes.slice(0, idxOfRef),
163
- newNode,
164
- ...this.childNodes.slice(idxOfRef)
165
- ]
173
+ this.childNodes.splice(idxOfRef, 0, newNode)
174
+ // TODO: 优化
175
+ this.notifyDataReload()
166
176
  }
167
177
 
168
178
  checkIsCompileModeAndInstallAfterDOMAction(newNode, this)
@@ -177,11 +187,9 @@ export class TaroNode extends TaroEventTarget {
177
187
 
178
188
  if (idxOfRef < 0) throw new Error('TaroNode:replaceChild NotFoundError')
179
189
 
180
- this.childNodes = [
181
- ...this.childNodes.slice(0, idxOfRef),
182
- newChild,
183
- ...this.childNodes.slice(idxOfRef + 1)
184
- ]
190
+ this.childNodes[idxOfRef] = newChild
191
+ oldChild.dispose()
192
+ this.notifyDataChange(idxOfRef)
185
193
 
186
194
  checkIsCompileModeAndInstallAfterDOMAction(newChild, this)
187
195
 
@@ -194,22 +202,44 @@ export class TaroNode extends TaroEventTarget {
194
202
  const idx = this.findIndex(child)
195
203
  if (idx < 0) throw new Error('TaroNode:removeChild NotFoundError')
196
204
 
197
- this.childNodes = this.childNodes.filter((_, index) => index !== idx)
205
+ this.childNodes.splice(idx, 1)
206
+ child.dispose()
207
+ this.notifyDataDelete(idx)
198
208
 
199
209
  checkIsCompileModeAndUninstallAfterDOMAction(child)
200
210
 
201
211
  return child
202
212
  }
213
+
214
+ public dispose () {
215
+ this.parentNode = null
216
+ this.childNodes = []
217
+ }
218
+ }
219
+
220
+ export class TaroTextNode extends TaroNode {
221
+ constructor(value = '', nodeName = '#text', nodeType: NodeType = NodeType.TEXT_NODE) {
222
+ super(nodeName, nodeType)
223
+ this.textContent = value
224
+ }
225
+
226
+ public get data (): string {
227
+ return this.textContent
228
+ }
229
+
230
+ public set data (value: string) {
231
+ this.textContent = value
232
+ }
203
233
  }
204
234
 
205
- function checkIsCompileModeAndInstallAfterDOMAction (node: TaroNode, parentNode: TaroNode) {
206
- if (!parentNode._isCompileMode) return
235
+ function checkIsCompileModeAndInstallAfterDOMAction (_node: TaroNode, _parentNode: TaroNode) {
236
+ // if (!parentNode._isCompileMode) return
207
237
 
208
- parentNode._instance?.dynamicCenter?.install?.(node, parentNode)
238
+ // parentNode._instance?.dynamicCenter?.install?.(node, parentNode)
209
239
  }
210
240
 
211
- function checkIsCompileModeAndUninstallAfterDOMAction (node: TaroNode) {
212
- if (!node._isCompileMode) return
241
+ function checkIsCompileModeAndUninstallAfterDOMAction (_node: TaroNode) {
242
+ // if (!node._isCompileMode) return
213
243
 
214
- node._instance?.dynamicCenter?.uninstall?.(node)
215
- }
244
+ // node._instance?.dynamicCenter?.uninstall?.(node)
245
+ }