@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.
- package/dist/apis/apis.ts +6 -2
- package/dist/apis/base/crypto.ts +4 -0
- package/dist/apis/base/debug.ts +5 -0
- package/dist/apis/base/index.ts +9 -1
- package/dist/apis/base/performance.ts +8 -0
- package/dist/apis/base/system.ts +1 -1
- package/dist/apis/base/update.ts +5 -0
- package/dist/apis/base/weapp/app-event.ts +75 -0
- package/dist/apis/base/weapp/life-cycle.ts +21 -0
- package/dist/apis/canvas/index.ts +18 -0
- package/dist/apis/data-analysis/index.ts +6 -0
- package/dist/apis/device/accelerometer.ts +2 -1
- package/dist/apis/device/accessibility.ts +4 -0
- package/dist/apis/device/battery.ts +2 -2
- package/dist/apis/device/bluetooth-ble.ts +19 -0
- package/dist/apis/device/bluetooth-peripheral.ts +6 -0
- package/dist/apis/device/bluetooth.ts +16 -0
- package/dist/apis/device/calendar.ts +5 -0
- package/dist/apis/device/clipboard.ts +1 -1
- package/dist/apis/device/compass.ts +21 -0
- package/dist/apis/device/contact.ts +5 -0
- package/dist/apis/device/crypto.ts +4 -0
- package/dist/apis/device/gyroscope.ts +7 -0
- package/dist/apis/device/iBeacon.ts +10 -0
- package/dist/apis/device/index.ts +15 -0
- package/dist/apis/device/keyboard.ts +2 -1
- package/dist/apis/device/motion.ts +6 -0
- package/dist/apis/device/network.ts +26 -9
- package/dist/apis/device/nfc.ts +10 -0
- package/dist/apis/device/phone.ts +2 -1
- package/dist/apis/device/scan.ts +4 -0
- package/dist/apis/device/screen.ts +2 -1
- package/dist/apis/device/sms.ts +4 -0
- package/dist/apis/device/vibrate.ts +19 -11
- package/dist/apis/device/wifi.ts +15 -0
- package/dist/apis/ext/index.ts +5 -0
- package/dist/apis/files/index.ts +2 -1
- package/dist/apis/files/manager.ts +2 -1
- package/dist/apis/framework/index.ts +5 -6
- package/dist/apis/location/index.ts +61 -68
- package/dist/apis/media/EditorContext.ts +32 -0
- package/dist/apis/media/audio/index.ts +18 -0
- package/dist/apis/media/background-audio/index.ts +16 -0
- package/dist/apis/media/camera.ts +16 -0
- package/dist/apis/media/common.ts +2 -1
- package/dist/apis/media/{image.ts → image/index.ts} +3 -2
- package/dist/apis/media/index.ts +10 -0
- package/dist/apis/media/live.ts +5 -0
- package/dist/apis/media/map.ts +4 -0
- package/dist/apis/media/media-recorder.ts +4 -0
- package/dist/apis/media/recorder.ts +6 -0
- package/dist/apis/media/video/VideoContext.ts +19 -0
- package/dist/apis/media/{video.ts → video/index.ts} +12 -2
- package/dist/apis/media/video-decoder.ts +4 -0
- package/dist/apis/media/video-processing.ts +4 -0
- package/dist/apis/media/voip.ts +19 -0
- package/dist/apis/network/index.ts +3 -0
- package/dist/apis/network/mdns.ts +13 -0
- package/dist/apis/network/request.ts +2 -1
- package/dist/apis/network/tcp.ts +4 -0
- package/dist/apis/network/udp.ts +4 -0
- package/dist/apis/network/webSocket.ts +2 -6
- package/dist/apis/open-api/account.ts +4 -0
- package/dist/apis/open-api/address.ts +4 -0
- package/dist/apis/open-api/authorize.ts +5 -0
- package/dist/apis/open-api/card.ts +5 -0
- package/dist/apis/open-api/channels-live.ts +11 -0
- package/dist/apis/open-api/customer-service.ts +4 -0
- package/dist/apis/open-api/device-voip.ts +5 -0
- package/dist/apis/open-api/facial.ts +7 -0
- package/dist/apis/open-api/favorites.ts +5 -0
- package/dist/apis/open-api/group.ts +4 -0
- package/dist/apis/open-api/index.ts +20 -6
- package/dist/apis/open-api/invoice.ts +5 -0
- package/dist/apis/open-api/license-plate.ts +4 -0
- package/dist/apis/open-api/login.ts +6 -0
- package/dist/apis/open-api/my-miniprogram.ts +4 -0
- package/dist/apis/open-api/privacy.ts +7 -0
- package/dist/apis/open-api/red-package.ts +4 -0
- package/dist/apis/open-api/settings.ts +5 -0
- package/dist/apis/open-api/soter.ts +6 -0
- package/dist/apis/open-api/subscribe-message.ts +6 -0
- package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
- package/dist/apis/open-api/werun.ts +5 -0
- package/dist/apis/payment/index.ts +6 -0
- package/dist/apis/route/index.ts +4 -28
- package/dist/apis/share/index.ts +33 -0
- package/dist/apis/storage/background-fetch.ts +7 -0
- package/dist/apis/storage/cache-manager.ts +4 -0
- package/dist/apis/storage/index.ts +20 -18
- package/dist/apis/ui/{animation.ts → animation/animation.ts} +2 -2
- package/dist/apis/ui/animation/index.ts +7 -0
- package/dist/apis/ui/background.ts +2 -18
- package/dist/apis/ui/custom-component.ts +8 -0
- package/dist/apis/ui/fonts.ts +4 -0
- package/dist/apis/ui/index.ts +8 -10
- package/dist/apis/ui/interaction/index.ts +3 -0
- package/dist/apis/ui/menu.ts +4 -0
- package/dist/apis/ui/navigation-bar/index.ts +60 -21
- package/dist/apis/ui/pull-down-refresh.ts +1 -1
- package/dist/apis/{page → ui/scroll}/index.ts +27 -22
- package/dist/apis/ui/sticky.ts +4 -0
- package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +3 -5
- package/dist/apis/ui/window.ts +20 -0
- package/dist/apis/utils/handler.ts +4 -4
- package/dist/apis/worker/index.ts +4 -0
- package/dist/apis/wxml/IntersectionObserver.ts +12 -21
- package/dist/apis/wxml/index.ts +5 -2
- package/dist/apis/wxml/nodesRef.ts +2 -2
- package/dist/apis/wxml/selectorQuery.ts +3 -4
- package/dist/components-harmony-ets/button.ets +90 -64
- package/dist/components-harmony-ets/checkbox.ets +53 -98
- package/dist/components-harmony-ets/form.ets +16 -112
- package/dist/components-harmony-ets/icon.ets +59 -46
- package/dist/components-harmony-ets/image.ets +15 -40
- package/dist/components-harmony-ets/innerHtml.ets +6 -74
- package/dist/components-harmony-ets/input.ets +58 -128
- package/dist/components-harmony-ets/label.ets +43 -69
- package/dist/components-harmony-ets/picker.ets +114 -137
- package/dist/components-harmony-ets/radio.ets +55 -103
- package/dist/components-harmony-ets/richText.ets +17 -41
- package/dist/components-harmony-ets/scrollView.ets +69 -101
- package/dist/components-harmony-ets/slider.ets +35 -58
- package/dist/components-harmony-ets/swiper.ets +24 -135
- package/dist/components-harmony-ets/switch.ets +25 -55
- package/dist/components-harmony-ets/text.ets +42 -46
- package/dist/components-harmony-ets/textArea.ets +39 -107
- package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
- package/dist/components-harmony-ets/utils/flexManager.ets +3 -88
- package/dist/components-harmony-ets/utils/helper.ets +2 -62
- package/dist/components-harmony-ets/utils/index.ts +1 -1
- package/dist/components-harmony-ets/utils/styles.ets +6 -9
- package/dist/components-harmony-ets/video.ets +63 -92
- package/dist/components-harmony-ets/view.ets +65 -40
- package/dist/index.js +33 -4
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/getComputedStyle.ts +1 -1
- package/dist/runtime-ets/dom/bind.ts +80 -0
- package/dist/runtime-ets/dom/class-list.ts +2 -4
- package/dist/runtime-ets/dom/comment.ts +1 -2
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +1 -1
- package/dist/runtime-ets/dom/dataSource.ts +64 -0
- package/dist/runtime-ets/dom/document.ts +14 -43
- package/dist/runtime-ets/dom/element/element.ts +162 -0
- package/dist/runtime-ets/dom/element/form.ts +397 -0
- package/dist/runtime-ets/dom/element/index.ts +89 -0
- package/dist/runtime-ets/dom/element/normal.ts +75 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +14 -0
- package/dist/runtime-ets/dom/element/text.ts +17 -0
- package/dist/runtime-ets/dom/element/video.ts +49 -0
- package/dist/runtime-ets/dom/event.ts +24 -1
- package/dist/runtime-ets/dom/eventTarget.ts +2 -1
- package/dist/runtime-ets/dom/node.ts +74 -44
- package/dist/runtime-ets/dom/stylesheet/index.ts +136 -23
- package/dist/runtime-ets/dom/stylesheet/type.ts +4 -3
- package/dist/runtime-ets/dom/stylesheet/util.ts +71 -1
- package/dist/runtime-ets/index.ts +0 -1
- package/dist/runtime-ets/utils/bind.ts +3 -14
- package/dist/runtime-ets/utils/index.ts +12 -7
- package/dist/runtime-ets/utils/info.ts +22 -50
- package/dist/runtime-framework/react/app.ts +3 -6
- package/dist/runtime-framework/react/page.ts +2 -9
- package/dist/runtime-framework/solid/page.ts +0 -6
- package/dist/runtime-utils.js +1150 -339
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +1150 -339
- package/dist/runtime.js.map +1 -1
- package/package.json +8 -8
- package/types/runtime.d.ts +4 -0
- package/LICENSE +0 -160
- package/dist/components-harmony-ets/base.ets +0 -63
- package/dist/components-harmony-ets/element.ets +0 -223
- package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
- package/dist/runtime-ets/dom/element.ts +0 -457
- package/dist/runtime-ets/dom/text.ts +0 -19
- 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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
49
|
+
eventSource.set(this._nid, this as TaroAny)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
totalCount(): number {
|
|
53
|
+
return this.childNodes?.length || 0
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
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.
|
|
58
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
113
|
-
|
|
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
|
-
|
|
148
|
-
this.childNodes
|
|
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
|
-
|
|
163
|
-
|
|
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
|
-
|
|
182
|
-
|
|
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
|
|
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 (
|
|
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 (
|
|
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
|
+
}
|