@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27
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/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- package/types/webpack-sources.d.ts +108 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Events } from '@tarojs/runtime/dist/runtime.esm'
|
|
2
|
+
import { isArray } from '@tarojs/shared'
|
|
3
|
+
|
|
4
|
+
import { TaroEvent } from './event'
|
|
5
|
+
|
|
6
|
+
import type { EventHandler } from '../interface'
|
|
7
|
+
|
|
8
|
+
interface IOptions {
|
|
9
|
+
capture?: boolean
|
|
10
|
+
once?: boolean
|
|
11
|
+
passive?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type fn = (...args: any[]) => any
|
|
15
|
+
|
|
16
|
+
class TaroEventTarget extends Events {
|
|
17
|
+
__listeners: Record<string, EventHandler[]> = {}
|
|
18
|
+
|
|
19
|
+
public addEventListener (type: string, listener: fn, options?: IOptions) {
|
|
20
|
+
const once = options?.once ?? false
|
|
21
|
+
|
|
22
|
+
if (once) {
|
|
23
|
+
const wrapper = () => {
|
|
24
|
+
listener.apply(this, arguments)
|
|
25
|
+
this.removeEventListener(type, wrapper)
|
|
26
|
+
}
|
|
27
|
+
this.addEventListener(type, wrapper)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const listeners = this.__listeners[type]
|
|
31
|
+
if (Array.isArray(listeners)) {
|
|
32
|
+
listeners.push(listener)
|
|
33
|
+
} else {
|
|
34
|
+
this.__listeners[type] = [listener]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public removeEventListener (type: string, listener: fn) {
|
|
39
|
+
const listeners = this.__listeners[type]
|
|
40
|
+
if (listeners.length) {
|
|
41
|
+
this.__listeners[type] = listeners.filter(item => item !== listener)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public dispatchEvent (event: TaroEvent) {
|
|
46
|
+
const cancelable = event.cancelable
|
|
47
|
+
const listeners = this.__listeners[event.type]
|
|
48
|
+
|
|
49
|
+
if (!Array.isArray(listeners)) {
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (let i = listeners.length; i--;) {
|
|
54
|
+
const listener = listeners[i]
|
|
55
|
+
let result: unknown
|
|
56
|
+
if (listener._stop) {
|
|
57
|
+
listener._stop = false
|
|
58
|
+
} else {
|
|
59
|
+
result = listener.call(this, event)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if ((result === false || event._end) && cancelable) {
|
|
63
|
+
event.defaultPrevented = true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (event._end && event._stop) {
|
|
67
|
+
break
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if (event._stop) {
|
|
73
|
+
this._stopPropagation(event)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
return listeners != null
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private _stopPropagation (event: TaroEvent) {
|
|
81
|
+
let target = this
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
while ((target = target.parentNode as this)) {
|
|
84
|
+
const listeners = target.__listeners[event.type]
|
|
85
|
+
|
|
86
|
+
if (!isArray(listeners)) {
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (let i = listeners.length; i--;) {
|
|
91
|
+
const l = listeners[i]
|
|
92
|
+
l._stop = true
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { TaroEventTarget }
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { eventSource } from '@tarojs/runtime/dist/runtime.esm'
|
|
2
|
+
|
|
3
|
+
import { TaroEventTarget } from './eventTarget'
|
|
4
|
+
|
|
5
|
+
import type { TaroDocument } from './document'
|
|
6
|
+
import type { TaroElement } from './element'
|
|
7
|
+
|
|
8
|
+
export enum NodeType {
|
|
9
|
+
ELEMENT_NODE = 1,
|
|
10
|
+
ATTRIBUTE_NODE = 2,
|
|
11
|
+
TEXT_NODE = 3,
|
|
12
|
+
CDATA_SECTION_NODE = 4,
|
|
13
|
+
ENTITY_REFERENCE_NODE = 5,
|
|
14
|
+
PROCESSING_INSTRUCTION_NODE = 7,
|
|
15
|
+
COMMENT_NODE = 8,
|
|
16
|
+
DOCUMENT_NODE = 9,
|
|
17
|
+
DOCUMENT_TYPE_NODE = 10,
|
|
18
|
+
DOCUMENT_FRAGMENT_NODE = 11
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let _id = 0
|
|
22
|
+
function genId (): string {
|
|
23
|
+
return `_n_${_id++}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class TaroNode extends TaroEventTarget {
|
|
27
|
+
public readonly nodeName: string
|
|
28
|
+
public readonly nodeType: NodeType
|
|
29
|
+
public childNodes: TaroNode[] = []
|
|
30
|
+
public parentNode: TaroNode | null = null
|
|
31
|
+
public _nid: string = genId()
|
|
32
|
+
|
|
33
|
+
public _doc: TaroDocument
|
|
34
|
+
// 是否为半编译模板下的节点
|
|
35
|
+
public _isCompileMode = false
|
|
36
|
+
// 是否为半编译模板下拥有自主更新权的节点
|
|
37
|
+
public _isDynamicNode = false
|
|
38
|
+
public _instance: any
|
|
39
|
+
|
|
40
|
+
private _updateTrigger = 0
|
|
41
|
+
private _textContent = ''
|
|
42
|
+
|
|
43
|
+
constructor(nodeName, nodeType = NodeType.ELEMENT_NODE) {
|
|
44
|
+
super()
|
|
45
|
+
this.nodeType = nodeType
|
|
46
|
+
this.nodeName = nodeName
|
|
47
|
+
eventSource.set(this._nid, this as any)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected findIndex (refChild: TaroNode): number {
|
|
51
|
+
// @Observe 会影响 === 判断,只能比较 _nid
|
|
52
|
+
return this.childNodes.findIndex(node => node._nid === refChild._nid)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 更新对应的 ArkUI 组件
|
|
56
|
+
public updateComponent () {
|
|
57
|
+
if (this._isDynamicNode || !this._isCompileMode) {
|
|
58
|
+
this._updateTrigger += 1
|
|
59
|
+
} else {
|
|
60
|
+
this.parentNode?.updateComponent()
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get firstChild (): TaroNode | null{
|
|
65
|
+
return this.childNodes[0] || null
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public get lastChild (): TaroNode | null {
|
|
69
|
+
return this.childNodes[this.childNodes.length - 1] || null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public get nextSibling (): TaroNode | null {
|
|
73
|
+
const parentNode = this.parentNode
|
|
74
|
+
return parentNode?.childNodes[parentNode.findIndex(this) + 1] || null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public get previousSibling (): TaroNode | null {
|
|
78
|
+
const parentNode = this.parentNode
|
|
79
|
+
return parentNode?.childNodes[parentNode.findIndex(this) - 1] || null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public get parentElement (): TaroElement | null {
|
|
83
|
+
const parentNode = this.parentNode
|
|
84
|
+
if (parentNode?.nodeType === NodeType.ELEMENT_NODE) {
|
|
85
|
+
return parentNode as TaroElement
|
|
86
|
+
}
|
|
87
|
+
return null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public get textContent (): string {
|
|
91
|
+
if (this.nodeType === NodeType.TEXT_NODE) {
|
|
92
|
+
return this._textContent
|
|
93
|
+
} else if (this.nodeType === NodeType.ELEMENT_NODE) {
|
|
94
|
+
const content = this.childNodes.reduce((prev, node) => {
|
|
95
|
+
return prev + node.textContent
|
|
96
|
+
}, '')
|
|
97
|
+
return content
|
|
98
|
+
}
|
|
99
|
+
return ''
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public set textContent (value: string) {
|
|
103
|
+
if (this.nodeType === NodeType.TEXT_NODE) {
|
|
104
|
+
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
|
+
// }
|
|
111
|
+
} else if (this.nodeType === NodeType.ELEMENT_NODE) {
|
|
112
|
+
const text = this.ownerDocument.createTextNode(value)
|
|
113
|
+
this.childNodes = [text]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public get nodeValue (): string | null {
|
|
118
|
+
switch (this.nodeType) {
|
|
119
|
+
case NodeType.TEXT_NODE:
|
|
120
|
+
return this.textContent
|
|
121
|
+
case NodeType.COMMENT_NODE:
|
|
122
|
+
return 'comment'
|
|
123
|
+
default:
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public set nodeValue (value: string) {
|
|
129
|
+
if (this.nodeType === NodeType.TEXT_NODE) {
|
|
130
|
+
this.textContent = value
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public get ownerDocument (): TaroDocument {
|
|
135
|
+
return this._doc
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public hasChildNodes (): boolean {
|
|
139
|
+
return this.childNodes.length > 0
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// TODO cloneNode()、contains()
|
|
143
|
+
|
|
144
|
+
public appendChild (child: TaroNode): TaroNode {
|
|
145
|
+
child.parentNode?.removeChild(child)
|
|
146
|
+
child.parentNode = this
|
|
147
|
+
// this.childNodes.push(child)
|
|
148
|
+
this.childNodes = [...this.childNodes, child]
|
|
149
|
+
|
|
150
|
+
checkIsCompileModeAndInstallAfterDOMAction(child, this)
|
|
151
|
+
return child
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public insertBefore (newNode: TaroNode, referenceNode: TaroNode | null): TaroNode {
|
|
155
|
+
newNode.parentNode?.removeChild(newNode)
|
|
156
|
+
|
|
157
|
+
if (referenceNode === null) {
|
|
158
|
+
this.appendChild(newNode)
|
|
159
|
+
} else {
|
|
160
|
+
const idxOfRef = this.findIndex(referenceNode)
|
|
161
|
+
this.childNodes = [
|
|
162
|
+
...this.childNodes.slice(0, idxOfRef),
|
|
163
|
+
newNode,
|
|
164
|
+
...this.childNodes.slice(idxOfRef)
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
checkIsCompileModeAndInstallAfterDOMAction(newNode, this)
|
|
169
|
+
|
|
170
|
+
return newNode
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public replaceChild (newChild: TaroNode, oldChild: TaroNode): TaroNode {
|
|
174
|
+
newChild.parentNode?.removeChild(newChild)
|
|
175
|
+
|
|
176
|
+
const idxOfRef = this.findIndex(oldChild)
|
|
177
|
+
|
|
178
|
+
if (idxOfRef < 0) throw new Error('TaroNode:replaceChild NotFoundError')
|
|
179
|
+
|
|
180
|
+
this.childNodes = [
|
|
181
|
+
...this.childNodes.slice(0, idxOfRef),
|
|
182
|
+
newChild,
|
|
183
|
+
...this.childNodes.slice(idxOfRef + 1)
|
|
184
|
+
]
|
|
185
|
+
|
|
186
|
+
checkIsCompileModeAndInstallAfterDOMAction(newChild, this)
|
|
187
|
+
|
|
188
|
+
return oldChild
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public removeChild (child: TaroNode): TaroNode {
|
|
192
|
+
if (!child) throw new Error('TaroNode:removeChild TypeError')
|
|
193
|
+
|
|
194
|
+
const idx = this.findIndex(child)
|
|
195
|
+
if (idx < 0) throw new Error('TaroNode:removeChild NotFoundError')
|
|
196
|
+
|
|
197
|
+
this.childNodes = this.childNodes.filter((_, index) => index !== idx)
|
|
198
|
+
|
|
199
|
+
checkIsCompileModeAndUninstallAfterDOMAction(child)
|
|
200
|
+
|
|
201
|
+
return child
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function checkIsCompileModeAndInstallAfterDOMAction (node: TaroNode, parentNode: TaroNode) {
|
|
206
|
+
if (!parentNode._isCompileMode) return
|
|
207
|
+
|
|
208
|
+
parentNode._instance?.dynamicCenter?.install?.(node, parentNode)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function checkIsCompileModeAndUninstallAfterDOMAction (node: TaroNode) {
|
|
212
|
+
if (!node._isCompileMode) return
|
|
213
|
+
|
|
214
|
+
node._instance?.dynamicCenter?.uninstall?.(node)
|
|
215
|
+
}
|