@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121
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/base/system.ts +60 -25
- package/dist/apis/base/weapp/life-cycle.ts +1 -1
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +23 -8
- package/dist/apis/framework/index.ts +2 -6
- package/dist/apis/index.ts +25 -17
- package/dist/apis/media/image/index.ts +169 -17
- package/dist/apis/route/index.ts +1 -2
- package/dist/apis/storage/index.ts +135 -131
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +3 -2
- package/dist/apis/ui/interaction/index.ts +58 -59
- package/dist/apis/ui/navigation-bar/index.ts +2 -2
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +6 -6
- package/dist/apis/ui/tab-bar.ts +4 -5
- package/dist/apis/utils/index.ts +20 -2
- package/dist/apis/utils/permissions.ts +6 -0
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +36 -9
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +69 -60
- package/dist/components-harmony-ets/form.ets +33 -15
- package/dist/components-harmony-ets/icon.ets +16 -8
- package/dist/components-harmony-ets/image.ets +22 -6
- package/dist/components-harmony-ets/index.ets +39 -0
- package/dist/components-harmony-ets/innerHtml.ets +6 -5
- package/dist/components-harmony-ets/input.ets +63 -37
- package/dist/components-harmony-ets/label.ets +43 -21
- package/dist/components-harmony-ets/listView.ets +32 -0
- package/dist/components-harmony-ets/movableArea.ets +110 -51
- package/dist/components-harmony-ets/movableView.ets +74 -47
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +36 -33
- package/dist/components-harmony-ets/progress.ets +31 -24
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +75 -66
- package/dist/components-harmony-ets/richText.ets +4 -25
- package/dist/components-harmony-ets/scrollList.ets +108 -0
- package/dist/components-harmony-ets/scrollView.ets +46 -42
- package/dist/components-harmony-ets/slider.ets +19 -15
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +386 -129
- package/dist/components-harmony-ets/swiper.ets +42 -5
- package/dist/components-harmony-ets/switch.ets +36 -32
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +102 -46
- package/dist/components-harmony-ets/textArea.ets +49 -34
- package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
- package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
- package/dist/components-harmony-ets/utils/helper.ets +20 -8
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +169 -91
- package/dist/components-harmony-ets/video.ets +28 -20
- package/dist/components-harmony-ets/view.ets +45 -39
- package/dist/components-harmony-ets/webView.ets +6 -5
- package/dist/index.d.ts +152 -0
- package/dist/index.js +73 -44
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/URL.ts +2 -0
- package/dist/runtime-ets/bom/document.ts +5 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
- package/dist/runtime-ets/bom/history.ts +1 -0
- package/dist/runtime-ets/bom/location.ts +1 -0
- package/dist/runtime-ets/bom/navigator.ts +1 -21
- package/dist/runtime-ets/bom/raf.ts +1 -37
- package/dist/runtime-ets/bom/window.ts +10 -4
- package/dist/runtime-ets/constant.ts +17 -10
- package/dist/runtime-ets/current.ts +5 -2
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +419 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
- package/dist/runtime-ets/dom/document.ts +9 -12
- package/dist/runtime-ets/dom/element/canvas.ts +137 -0
- package/dist/runtime-ets/dom/element/element.ts +379 -55
- package/dist/runtime-ets/dom/element/form.ts +26 -22
- package/dist/runtime-ets/dom/element/index.ts +22 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
- package/dist/runtime-ets/dom/element/movableView.ts +238 -2
- package/dist/runtime-ets/dom/element/normal.ts +27 -6
- package/dist/runtime-ets/dom/element/progress.ts +0 -2
- package/dist/runtime-ets/dom/element/text.ts +0 -8
- package/dist/runtime-ets/dom/element/video.ts +4 -4
- package/dist/runtime-ets/dom/element/webView.ts +4 -5
- package/dist/runtime-ets/dom/event-source.ts +1 -0
- package/dist/runtime-ets/dom/event.ts +3 -5
- package/dist/runtime-ets/dom/eventTarget.ts +3 -4
- package/dist/runtime-ets/dom/node.ts +53 -22
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
- package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
- package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/emitter/emitter.ts +1 -0
- package/dist/runtime-ets/env.ts +1 -0
- package/dist/runtime-ets/index.ts +23 -7
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/interface/index.ts +6 -0
- package/dist/runtime-ets/utils/index.ts +78 -19
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-ets/utils/router.ts +9 -0
- package/dist/runtime-framework/react/app.ts +15 -11
- package/dist/runtime-framework/react/hooks.ts +1 -2
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +217 -81
- package/dist/runtime-framework/react/page.ts +4 -10
- package/dist/runtime-framework/react/utils/index.ts +3 -3
- package/dist/runtime-framework/solid/app.ts +29 -46
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +84 -31
- package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +3 -5
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +574 -285
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +574 -285
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -1
- package/static/media/circle.svg +1 -1
- package/static/media/clear.svg +1 -1
- package/static/media/download.svg +1 -1
- package/static/media/info.svg +1 -1
- package/static/media/info_circle.svg +1 -1
- package/static/media/search.svg +1 -1
- package/static/media/success.svg +1 -1
- package/static/media/success_no_circle.svg +1 -1
- package/static/media/warn.svg +1 -1
- package/types/harmony.d.ts +5 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +1 -1
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -1,63 +1,117 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { getPageById } from '@tarojs/plugin-framework-react/dist/runtime'
|
|
3
|
+
import { EMPTY_OBJ, toCamelCase } from '@tarojs/shared'
|
|
2
4
|
|
|
3
5
|
import { ATTRIBUTES_CALLBACK_TRIGGER_MAP, ID } from '../../constant'
|
|
6
|
+
import { Current } from '../../current'
|
|
7
|
+
import { eventCenter } from '../../emitter/emitter'
|
|
4
8
|
import { findChildNodeWithDFS } from '../../utils'
|
|
5
9
|
import { initComponentNodeInfo, triggerAttributesCallback } from '../../utils/info'
|
|
6
10
|
import { bindAnimation } from '../bind'
|
|
7
11
|
import { ClassList } from '../class-list'
|
|
12
|
+
import { createCSSStyleDeclaration } from '../cssStyleDeclaration'
|
|
13
|
+
import { eventSource } from '../event-source'
|
|
8
14
|
import { NodeType, TaroNode } from '../node'
|
|
9
|
-
import StyleSheet from '../stylesheet'
|
|
15
|
+
import StyleSheet, { HarmonyStyle, TaroStyleType } from '../stylesheet'
|
|
10
16
|
|
|
11
|
-
import type { StandardProps } from '@tarojs/components/types'
|
|
12
|
-
import type { TaroAny } from '../../
|
|
17
|
+
import type { BaseTouchEvent, ITouchEvent, StandardProps } from '@tarojs/components/types'
|
|
18
|
+
import type { TaroAny } from '../../interface'
|
|
13
19
|
import type { ICSSStyleDeclaration } from '../cssStyleDeclaration'
|
|
14
20
|
|
|
15
|
-
type NamedNodeMap =
|
|
21
|
+
type NamedNodeMap = { name: string, value: string }[]
|
|
16
22
|
|
|
17
23
|
export interface TaroExtraProps {
|
|
18
24
|
compileMode?: string | boolean
|
|
19
25
|
compileIf?: boolean
|
|
20
26
|
disabled?: boolean
|
|
27
|
+
__hmStyle?: TaroStyleType
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
export class TaroElement<
|
|
30
|
+
export class TaroElement<
|
|
31
|
+
T extends StandardProps<any, U> = StandardProps,
|
|
32
|
+
U extends BaseTouchEvent<any> = ITouchEvent
|
|
33
|
+
> extends TaroNode {
|
|
24
34
|
public _innerHTML = ''
|
|
25
|
-
public _nodeInfo: TaroAny = {
|
|
35
|
+
public _nodeInfo: TaroAny = {
|
|
36
|
+
layer: 0 // 渲染层级
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public _hm_instance: TaroAny
|
|
40
|
+
public weak_hm_instance: WeakRef<TaroAny>
|
|
41
|
+
public use_weak_hm_instance: boolean = true
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
public get hm_instance(): TaroAny {
|
|
45
|
+
if (this.use_weak_hm_instance && this.weak_hm_instance) {
|
|
46
|
+
return this.weak_hm_instance?.deref()
|
|
47
|
+
}
|
|
48
|
+
return this._hm_instance
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public set hm_instance(instance) {
|
|
52
|
+
if (this.use_weak_hm_instance && instance) {
|
|
53
|
+
this.weak_hm_instance = new WeakRef(instance)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
this._hm_instance = instance
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
public get _instance () {
|
|
61
|
+
return this.hm_instance
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public set _instance (value) {
|
|
65
|
+
this.hm_instance = value
|
|
66
|
+
if (this._nodeInfo.aboutToAppear) {
|
|
67
|
+
let task
|
|
68
|
+
// eslint-disable-next-line no-cond-assign
|
|
69
|
+
while (task = this._nodeInfo.aboutToAppear.shift()) {
|
|
70
|
+
task()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
26
75
|
public readonly tagName: string
|
|
76
|
+
public dataset: Record<string, unknown> = EMPTY_OBJ
|
|
27
77
|
public _attrs: T & TaroExtraProps = {} as T & TaroExtraProps
|
|
28
78
|
|
|
79
|
+
private _page: any
|
|
80
|
+
|
|
29
81
|
constructor(tagName: string) {
|
|
30
82
|
super(tagName.replace(new RegExp('(?<=.)([A-Z])', 'g'), '-$1').toUpperCase(), NodeType.ELEMENT_NODE)
|
|
31
83
|
this.tagName = this.nodeName
|
|
32
|
-
|
|
84
|
+
this._style = createCSSStyleDeclaration(this)
|
|
33
85
|
initComponentNodeInfo(this)
|
|
34
86
|
bindAnimation(this)
|
|
87
|
+
|
|
88
|
+
this._page = Current.page
|
|
35
89
|
}
|
|
36
90
|
|
|
37
|
-
public set id
|
|
91
|
+
public set id(value: string) {
|
|
38
92
|
this.setAttribute('id', value)
|
|
39
93
|
}
|
|
40
94
|
|
|
41
|
-
public get id
|
|
42
|
-
return this.getAttribute('id') || this._nid
|
|
95
|
+
public get id(): string {
|
|
96
|
+
return this.getAttribute('id') || `${this._nid}`
|
|
43
97
|
}
|
|
44
98
|
|
|
45
|
-
public set className
|
|
99
|
+
public set className(value: string) {
|
|
46
100
|
this.setAttribute('class', value)
|
|
47
101
|
}
|
|
48
102
|
|
|
49
|
-
public get className
|
|
103
|
+
public get className(): string {
|
|
50
104
|
return this.getAttribute('class') || ''
|
|
51
105
|
}
|
|
52
106
|
|
|
53
|
-
public get classList
|
|
107
|
+
public get classList(): ClassList {
|
|
54
108
|
return new ClassList(this.className, this)
|
|
55
109
|
}
|
|
56
110
|
|
|
57
|
-
public get attributes
|
|
111
|
+
public get attributes(): NamedNodeMap {
|
|
58
112
|
const list: NamedNodeMap = []
|
|
59
113
|
|
|
60
|
-
Object.keys(this._attrs).forEach(name => {
|
|
114
|
+
Object.keys(this._attrs).forEach((name) => {
|
|
61
115
|
const value: TaroAny = this._attrs[name]
|
|
62
116
|
|
|
63
117
|
list.push({ name, value })
|
|
@@ -66,73 +120,118 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
66
120
|
return list
|
|
67
121
|
}
|
|
68
122
|
|
|
69
|
-
public get children
|
|
70
|
-
return this.childNodes.filter(node => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
|
|
123
|
+
public get children(): TaroElement[] {
|
|
124
|
+
return this.childNodes.filter((node) => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
|
|
71
125
|
}
|
|
72
126
|
|
|
73
|
-
public setAttribute
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
127
|
+
public setAttribute(name: string, value: TaroAny): void {
|
|
128
|
+
switch (name) {
|
|
129
|
+
case ID:
|
|
130
|
+
eventSource.delete(this._attrs.id)
|
|
131
|
+
eventSource.set(value, this as TaroAny)
|
|
132
|
+
break
|
|
133
|
+
default:
|
|
134
|
+
if (name.startsWith('data-')) {
|
|
135
|
+
if (this.dataset === EMPTY_OBJ) {
|
|
136
|
+
this.dataset = Object.create(null)
|
|
137
|
+
}
|
|
138
|
+
this.dataset[toCamelCase(name.replace(/^data-/, ''))] = value
|
|
139
|
+
}
|
|
140
|
+
break
|
|
77
141
|
}
|
|
78
142
|
|
|
79
143
|
this._attrs[name] = value
|
|
80
144
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
145
|
+
// 混合开发的组件没办法自动更新,需要把父级的结点删掉新建
|
|
146
|
+
// Current.nativeComponentNames会在render.ets中赋值
|
|
147
|
+
if (Current.nativeComponentNames?.includes(this.tagName)) {
|
|
148
|
+
const idxOfRef = this.parentNode?.findIndex(this)
|
|
85
149
|
|
|
86
|
-
if (
|
|
150
|
+
if (idxOfRef !== undefined) {
|
|
151
|
+
this._nativeUpdateTrigger++
|
|
152
|
+
this.parentNode?.notifyDataChange(idxOfRef)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (['PAGE-META', 'NAVIGATION-BAR'].includes(this.tagName)) {
|
|
157
|
+
// FIXME 等 Harmony 支持更细粒度的 @Watch 方法后移出
|
|
158
|
+
eventCenter.trigger('__taroComponentAttributeUpdate', {
|
|
159
|
+
id: this._nid,
|
|
160
|
+
tagName: this.tagName,
|
|
161
|
+
attribute: name,
|
|
162
|
+
value
|
|
163
|
+
})
|
|
164
|
+
} else {
|
|
165
|
+
const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
|
|
166
|
+
if (attributeTriggerValue) {
|
|
167
|
+
const triggerName: TaroAny = attributeTriggerValue.triggerName
|
|
168
|
+
const valueInspect: TaroAny = attributeTriggerValue.valueInspect
|
|
87
169
|
|
|
88
|
-
|
|
170
|
+
if (valueInspect && !valueInspect(value)) return
|
|
171
|
+
|
|
172
|
+
triggerAttributesCallback(this, triggerName)
|
|
173
|
+
}
|
|
89
174
|
}
|
|
90
175
|
}
|
|
91
176
|
|
|
92
|
-
public getAttribute
|
|
177
|
+
public getAttribute(name: string): string {
|
|
93
178
|
return this._attrs[name]
|
|
94
179
|
}
|
|
95
180
|
|
|
96
|
-
public removeAttribute
|
|
181
|
+
public removeAttribute(name: string): void {
|
|
97
182
|
this._attrs[name] = null
|
|
98
183
|
}
|
|
99
184
|
|
|
100
|
-
public hasAttribute
|
|
185
|
+
public hasAttribute(name: string): boolean {
|
|
101
186
|
return !!this._attrs[name]
|
|
102
187
|
}
|
|
103
188
|
|
|
104
|
-
public hasAttributes
|
|
189
|
+
public hasAttributes(): boolean {
|
|
105
190
|
return Object.keys(this._attrs).length > 0
|
|
106
191
|
}
|
|
107
192
|
|
|
108
|
-
public getElementById<T extends TaroElement = TaroElement>
|
|
109
|
-
return findChildNodeWithDFS<T>(
|
|
110
|
-
|
|
111
|
-
|
|
193
|
+
public getElementById<T extends TaroElement = TaroElement>(id: string | undefined | null) {
|
|
194
|
+
return findChildNodeWithDFS<T>(
|
|
195
|
+
this as TaroAny,
|
|
196
|
+
(el) => {
|
|
197
|
+
return el.id === id
|
|
198
|
+
},
|
|
199
|
+
false
|
|
200
|
+
)
|
|
112
201
|
}
|
|
113
202
|
|
|
114
|
-
public getElementsByTagName<T extends TaroElement = TaroElement>
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
|
|
203
|
+
public getElementsByTagName<T extends TaroElement = TaroElement>(tagName: string) {
|
|
204
|
+
return (
|
|
205
|
+
findChildNodeWithDFS<T>(
|
|
206
|
+
this as TaroAny,
|
|
207
|
+
(el) => {
|
|
208
|
+
return el.nodeName === tagName || (tagName === '*' && (this as TaroAny) !== el)
|
|
209
|
+
},
|
|
210
|
+
true
|
|
211
|
+
) || []
|
|
212
|
+
)
|
|
118
213
|
}
|
|
119
214
|
|
|
120
|
-
public getElementsByClassName<T extends TaroElement = TaroElement>
|
|
215
|
+
public getElementsByClassName<T extends TaroElement = TaroElement>(className: string) {
|
|
121
216
|
const classNames = className.trim().split(new RegExp('\\s+'))
|
|
122
217
|
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
218
|
+
return (
|
|
219
|
+
findChildNodeWithDFS<T>(
|
|
220
|
+
this as TaroAny,
|
|
221
|
+
(el) => {
|
|
222
|
+
const classList = el.classList
|
|
223
|
+
return classNames.every((c) => {
|
|
224
|
+
const bool = classList.contains(c)
|
|
225
|
+
|
|
226
|
+
return bool
|
|
227
|
+
})
|
|
228
|
+
},
|
|
229
|
+
true
|
|
230
|
+
) || []
|
|
231
|
+
)
|
|
131
232
|
}
|
|
132
233
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
public set innerHTML (value: string) {
|
|
234
|
+
public set innerHTML(value: string) {
|
|
136
235
|
if (this.nodeType === NodeType.ELEMENT_NODE && this.ownerDocument) {
|
|
137
236
|
const ele = this.ownerDocument.createElement('inner-html')
|
|
138
237
|
ele._innerHTML = value
|
|
@@ -140,20 +239,245 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
140
239
|
}
|
|
141
240
|
}
|
|
142
241
|
|
|
143
|
-
public get innerHTML
|
|
242
|
+
public get innerHTML(): string {
|
|
144
243
|
return this._innerHTML
|
|
145
244
|
}
|
|
146
245
|
|
|
246
|
+
// 存放的样式,获取其实跟获取style是一样的,只不过这里取的更快捷,不需要走style的get方法进到cssStyleDeclaration
|
|
147
247
|
public _st = new StyleSheet()
|
|
148
248
|
|
|
149
249
|
// 经转换后的鸿蒙样式
|
|
150
|
-
public get hmStyle
|
|
250
|
+
public get hmStyle() {
|
|
151
251
|
return this._st.hmStyle
|
|
152
252
|
}
|
|
153
253
|
|
|
154
254
|
public _style: ICSSStyleDeclaration | null = null
|
|
155
255
|
|
|
156
|
-
public get style
|
|
256
|
+
public get style(): ICSSStyleDeclaration | null {
|
|
157
257
|
return this._style
|
|
158
258
|
}
|
|
259
|
+
|
|
260
|
+
// 伪元素,不存在style动态设置,均已被转换为鸿蒙样式
|
|
261
|
+
// 可根据实际情况,迁移到具体的组件中,如View、ScrollView中,Text\Image其实是不需要的
|
|
262
|
+
public _pseudo_before: StyleSheet | null = null
|
|
263
|
+
|
|
264
|
+
public set_pseudo_before(value: HarmonyStyle | null) {
|
|
265
|
+
if (value) {
|
|
266
|
+
if (!this._pseudo_before) {
|
|
267
|
+
this._pseudo_before = new StyleSheet()
|
|
268
|
+
}
|
|
269
|
+
Object.keys(value).forEach(key => {
|
|
270
|
+
this._pseudo_before!.hmStyle[key] = value[key]
|
|
271
|
+
})
|
|
272
|
+
} else {
|
|
273
|
+
this._pseudo_before = null
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public _pseudo_after: StyleSheet | null = null
|
|
278
|
+
|
|
279
|
+
public set_pseudo_after(value: HarmonyStyle | null) {
|
|
280
|
+
if (value) {
|
|
281
|
+
if (!this._pseudo_after) {
|
|
282
|
+
this._pseudo_after = new StyleSheet()
|
|
283
|
+
}
|
|
284
|
+
Object.keys(value).forEach(key => {
|
|
285
|
+
this._pseudo_after!.hmStyle[key] = value[key]
|
|
286
|
+
})
|
|
287
|
+
} else {
|
|
288
|
+
this._pseudo_after = null
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 伪类,在获取的时候根据dom和parent的关系,动态设置
|
|
293
|
+
public _pseudo_class: Record<string, StyleSheet | null> = {
|
|
294
|
+
// ["::first-child"]: new StyleSheet(),
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public set_pseudo_class(name: string, value: HarmonyStyle | null) {
|
|
298
|
+
if (value) {
|
|
299
|
+
if (!this._pseudo_class[name]) {
|
|
300
|
+
this._pseudo_class[name] = new StyleSheet()
|
|
301
|
+
}
|
|
302
|
+
Object.keys(value).forEach(key => {
|
|
303
|
+
this._pseudo_class[name]!.hmStyle[key] = value[key]
|
|
304
|
+
})
|
|
305
|
+
} else {
|
|
306
|
+
this._pseudo_class[name] = null
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
get currentLayerNode () {
|
|
311
|
+
if (!this._page) return null
|
|
312
|
+
if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
|
|
313
|
+
this._page.layerNode ||= []
|
|
314
|
+
this._page.layerNode[this._page.tabBarCurrentIndex] ||= Current.createHarmonyElement('VIEW')
|
|
315
|
+
// Tabbar
|
|
316
|
+
return this._page.layerNode[this._page.tabBarCurrentIndex]
|
|
317
|
+
} else {
|
|
318
|
+
this._page.layerNode ||= Current.createHarmonyElement('VIEW')
|
|
319
|
+
return this._page.layerNode
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
get currentLayerParents () {
|
|
324
|
+
if (!this._page) return null
|
|
325
|
+
if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
|
|
326
|
+
this._page.layerParents ||= {}
|
|
327
|
+
this._page.layerParents[this._page.tabBarCurrentIndex] ||= {}
|
|
328
|
+
// Tabbar
|
|
329
|
+
return this._page.layerParents[this._page.tabBarCurrentIndex]
|
|
330
|
+
} else {
|
|
331
|
+
this._page.layerParents ||= {}
|
|
332
|
+
return this._page.layerParents
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// 设置渲染层级,0为正常层级,大于0为固定层级
|
|
337
|
+
// 1、appendChild的时候会判断是否需要设置层级
|
|
338
|
+
// 2、taro-react的setProperty,在处理属性变化的时候,会判断是否需要设置层级
|
|
339
|
+
// 3、removeChild的时候,会判断是否需要移除层级
|
|
340
|
+
public setLayer (value: number) {
|
|
341
|
+
if (!this.parentNode) return // 没有父节点,不需要设置层级关系
|
|
342
|
+
|
|
343
|
+
const currentPage = getPageById(this.getAttribute('__fixed'))
|
|
344
|
+
if (currentPage) {
|
|
345
|
+
this._page = currentPage
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this._nodeInfo.layer = value
|
|
349
|
+
|
|
350
|
+
const currentLayerNode = this.currentLayerNode
|
|
351
|
+
const currentLayerParents = this.currentLayerParents
|
|
352
|
+
if (!currentLayerNode || !currentLayerParents) return
|
|
353
|
+
if (value > 0) {
|
|
354
|
+
// 插入到固定浮层
|
|
355
|
+
currentLayerNode.childNodes.push(this)
|
|
356
|
+
currentLayerNode.notifyDataAdd(currentLayerNode.childNodes.length - 1)
|
|
357
|
+
// 绑定祖先的节点id,建立关系,方便在祖先卸载(removeChild)的时候,能够找到该节点使其卸载
|
|
358
|
+
const _parentRecord = {}
|
|
359
|
+
generateLayerParentIds(_parentRecord, this)
|
|
360
|
+
currentLayerParents[this.getStrNid()] = _parentRecord
|
|
361
|
+
} else {
|
|
362
|
+
const idx = currentLayerNode.childNodes.findIndex(n => n.getStrNid() === this.getStrNid())
|
|
363
|
+
currentLayerNode.childNodes.splice(idx, 1)
|
|
364
|
+
currentLayerNode.notifyDataDelete(idx)
|
|
365
|
+
|
|
366
|
+
delete currentLayerParents[this.getStrNid()]
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (this.parentNode) {
|
|
370
|
+
this.parentNode.notifyDataChange(this.parentNode.findIndex(this))
|
|
371
|
+
this.updateComponent()
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
protected toggleLayer(add: boolean) {
|
|
376
|
+
if (add) {
|
|
377
|
+
if (this._st?.hmStyle.position === 'fixed') {
|
|
378
|
+
this.setLayer(1)
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
const currentLayerParents = this.currentLayerParents
|
|
382
|
+
if (!currentLayerParents) return
|
|
383
|
+
// 识别Current.page.layerParents里面是否有需要移除的固定元素
|
|
384
|
+
if (this._nodeInfo?.layer > 0) {
|
|
385
|
+
delete currentLayerParents[this.getStrNid()]
|
|
386
|
+
this.setLayer(0)
|
|
387
|
+
} else {
|
|
388
|
+
Object.keys(currentLayerParents).forEach(fixedId => {
|
|
389
|
+
const parentIds = currentLayerParents[fixedId]
|
|
390
|
+
if (parentIds[this.getStrNid()]) {
|
|
391
|
+
// 需要移除fixedId
|
|
392
|
+
delete currentLayerParents[fixedId]
|
|
393
|
+
const fixedNode = eventSource.get(this.getNumNid(fixedId)) as unknown as TaroElement
|
|
394
|
+
if (fixedNode) {
|
|
395
|
+
fixedNode.setLayer(0)
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// 设置动画
|
|
404
|
+
public setAnimation (playing) {
|
|
405
|
+
if (!this._instance) {
|
|
406
|
+
if (!this._nodeInfo.aboutToAppear) {
|
|
407
|
+
this._nodeInfo.aboutToAppear = []
|
|
408
|
+
}
|
|
409
|
+
this._nodeInfo.aboutToAppear.push(() => {
|
|
410
|
+
this.setAnimation(playing)
|
|
411
|
+
})
|
|
412
|
+
return
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const keyframes = this._st.hmStyle.animationName
|
|
416
|
+
|
|
417
|
+
// 防止动画闪烁,需要把第一帧的内容先设置上去设置初始样式
|
|
418
|
+
if (playing && keyframes && keyframes[0] && keyframes[0].percentage === 0) {
|
|
419
|
+
this._instance.overwriteStyle = keyframes[0].event
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// 首次设置,不用实例替换
|
|
423
|
+
if (!this._nodeInfo.hasAnimation && playing) {
|
|
424
|
+
this._nodeInfo.hasAnimation = true
|
|
425
|
+
// 下一帧播放,等节点样式首次设置上去在进行覆盖
|
|
426
|
+
setTimeout(() => {
|
|
427
|
+
if (playing) {
|
|
428
|
+
this.playAnimation()
|
|
429
|
+
}
|
|
430
|
+
}, 0)
|
|
431
|
+
} else if (this.parentNode) {
|
|
432
|
+
const idx = this.parentNode.findIndex(this)
|
|
433
|
+
// Note: 因为keyframeAnimateTo无法暂停,华为没有支持,只能临时先换掉实例,重新创建ark节点,使得原本的keyframeAnimateTo失效
|
|
434
|
+
// remove
|
|
435
|
+
this.parentNode.childNodes.splice(idx, 1)
|
|
436
|
+
this.parentNode.notifyDataDelete(idx)
|
|
437
|
+
|
|
438
|
+
// 下一帧播放,等实例被移除掉,再重新插入
|
|
439
|
+
setTimeout(() => {
|
|
440
|
+
// insert
|
|
441
|
+
this.parentNode?.childNodes.splice(idx, 0, this)
|
|
442
|
+
this.parentNode?.notifyDataAdd(idx)
|
|
443
|
+
|
|
444
|
+
// 执行动画
|
|
445
|
+
if (playing) {
|
|
446
|
+
this.playAnimation()
|
|
447
|
+
}
|
|
448
|
+
}, playing ? 0 : 100)
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private playAnimation () {
|
|
453
|
+
const {
|
|
454
|
+
animationDuration = 0, animationDelay = 0, animationIterationCount = 1, animationName: keyframes,
|
|
455
|
+
animationTimingFunction
|
|
456
|
+
} = this._st.hmStyle
|
|
457
|
+
|
|
458
|
+
if (keyframes) {
|
|
459
|
+
let cur_percentage = 0
|
|
460
|
+
this._instance.getUIContext()?.keyframeAnimateTo({
|
|
461
|
+
delay: animationDelay,
|
|
462
|
+
iterations: animationIterationCount,
|
|
463
|
+
}, keyframes.map(item => {
|
|
464
|
+
const duration = (item.percentage - cur_percentage) * animationDuration
|
|
465
|
+
cur_percentage = item.percentage
|
|
466
|
+
return {
|
|
467
|
+
duration: duration,
|
|
468
|
+
curve: item.event.animationTimingFunction || animationTimingFunction,
|
|
469
|
+
event: () => {
|
|
470
|
+
this._instance.overwriteStyle = item.event
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}))
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function generateLayerParentIds(ids: Record<string, true>, node?: TaroElement) {
|
|
479
|
+
if (node?.parentElement) {
|
|
480
|
+
ids[node.parentElement.getStrNid()] = true
|
|
481
|
+
generateLayerParentIds(ids, node.parentElement)
|
|
482
|
+
}
|
|
159
483
|
}
|
|
@@ -29,14 +29,10 @@ interface FormWidgetProps extends StandardProps {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends TaroElement<T> {
|
|
32
|
-
_instance
|
|
33
|
-
|
|
34
32
|
_isInit = false
|
|
35
33
|
|
|
36
34
|
_name = ''
|
|
37
35
|
|
|
38
|
-
_value: TaroAny = ''
|
|
39
|
-
|
|
40
36
|
_reset: TaroAny = ''
|
|
41
37
|
|
|
42
38
|
constructor (tagName: string) {
|
|
@@ -45,7 +41,7 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
45
41
|
bindFocus(this)
|
|
46
42
|
|
|
47
43
|
this._name = this._attrs.name || ''
|
|
48
|
-
this._value = this._attrs.value || ''
|
|
44
|
+
this._nodeInfo._value = this._attrs.value || ''
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
public setAttribute (name: string, value: any): void {
|
|
@@ -60,17 +56,22 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
58
|
|
|
59
|
+
public removeAttribute(name: string): void {
|
|
60
|
+
if (name === 'value') {
|
|
61
|
+
this.value = ''
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
63
65
|
public get name () {
|
|
64
66
|
return this._attrs.name || ''
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
public set name (val: string) {
|
|
68
70
|
this.updateFormWidgetName(val)
|
|
69
|
-
this.updateComponent()
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
public get value () {
|
|
73
|
-
return this._value
|
|
74
|
+
return this._nodeInfo._value
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
public set value (val: TaroAny) {
|
|
@@ -78,8 +79,6 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
78
79
|
|
|
79
80
|
if (this._instance) {
|
|
80
81
|
this._instance.value = val
|
|
81
|
-
} else {
|
|
82
|
-
this.updateComponent()
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
|
@@ -89,7 +88,7 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
public updateFormWidgetValue (val: TaroAny) {
|
|
92
|
-
this._value = val
|
|
91
|
+
this._nodeInfo._value = val
|
|
93
92
|
this._attrs.value = val
|
|
94
93
|
}
|
|
95
94
|
|
|
@@ -121,7 +120,6 @@ class TaroCheckedElement<T extends StandardProps & { checked?: boolean } = Stand
|
|
|
121
120
|
|
|
122
121
|
set checked (val: boolean) {
|
|
123
122
|
this.updateCheckedValue(val)
|
|
124
|
-
this.updateComponent()
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
public updateCheckedValue (val: boolean) {
|
|
@@ -175,6 +173,14 @@ class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormW
|
|
|
175
173
|
}
|
|
176
174
|
}
|
|
177
175
|
|
|
176
|
+
public get value () {
|
|
177
|
+
return super.value
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public set value (val: TaroAny) {
|
|
181
|
+
super.value = `${val}`
|
|
182
|
+
}
|
|
183
|
+
|
|
178
184
|
private onKeyboardHeightChange (height: number) {
|
|
179
185
|
const event: TaroEvent = createTaroEvent('keyboardHeightChange', { detail: { height: height, duration: 0 } }, this)
|
|
180
186
|
|
|
@@ -195,7 +201,7 @@ class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormW
|
|
|
195
201
|
}
|
|
196
202
|
|
|
197
203
|
@Observed
|
|
198
|
-
class TaroTextAreaElement extends TaroInputElement<TextareaProps>{
|
|
204
|
+
class TaroTextAreaElement extends TaroInputElement<TextareaProps> {
|
|
199
205
|
controller: TextAreaController = new TextAreaController()
|
|
200
206
|
|
|
201
207
|
constructor() {
|
|
@@ -203,14 +209,14 @@ class TaroTextAreaElement extends TaroInputElement<TextareaProps>{
|
|
|
203
209
|
}
|
|
204
210
|
}
|
|
205
211
|
@Observed
|
|
206
|
-
class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps>{
|
|
212
|
+
class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps> {
|
|
207
213
|
constructor() {
|
|
208
214
|
super('Checkbox')
|
|
209
215
|
}
|
|
210
216
|
}
|
|
211
217
|
|
|
212
218
|
@Observed
|
|
213
|
-
class TaroRadioElement extends TaroCheckedElement<RadioProps>{
|
|
219
|
+
class TaroRadioElement extends TaroCheckedElement<RadioProps> {
|
|
214
220
|
public group?: string
|
|
215
221
|
|
|
216
222
|
constructor() {
|
|
@@ -220,12 +226,10 @@ class TaroRadioElement extends TaroCheckedElement<RadioProps>{
|
|
|
220
226
|
|
|
221
227
|
@Observed
|
|
222
228
|
class TaroSliderElement extends TaroFormWidgetElement<SliderProps> {
|
|
223
|
-
_value = 0
|
|
224
|
-
|
|
225
229
|
constructor() {
|
|
226
230
|
super('Slider')
|
|
227
231
|
|
|
228
|
-
this._value = Number(this._attrs.value || 0)
|
|
232
|
+
this._nodeInfo._value = Number(this._attrs.value || 0)
|
|
229
233
|
}
|
|
230
234
|
}
|
|
231
235
|
@Observed
|
|
@@ -242,7 +246,7 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
|
|
|
242
246
|
case 'selector': {
|
|
243
247
|
const key = this._attrs.rangeKey
|
|
244
248
|
const item = this._attrs.range[this.value]
|
|
245
|
-
|
|
249
|
+
|
|
246
250
|
if (key) {
|
|
247
251
|
return item[key]
|
|
248
252
|
} else {
|
|
@@ -271,7 +275,7 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
|
|
|
271
275
|
super.reset()
|
|
272
276
|
|
|
273
277
|
const event: TaroEvent = createTaroEvent('change', { detail: { value: this._reset } }, this)
|
|
274
|
-
|
|
278
|
+
|
|
275
279
|
event.stopPropagation()
|
|
276
280
|
eventHandler(event, 'change', this)
|
|
277
281
|
}
|
|
@@ -347,7 +351,7 @@ class TaroFormElement extends TaroFormWidgetElement {
|
|
|
347
351
|
|
|
348
352
|
findChildNodeWithDFS<TaroFormWidgetElement>(this, item => {
|
|
349
353
|
if (!item.name) return false
|
|
350
|
-
|
|
354
|
+
|
|
351
355
|
switch (item.nodeName) {
|
|
352
356
|
case 'INPUT':
|
|
353
357
|
case 'RADIO':
|
|
@@ -378,9 +382,9 @@ class TaroFormElement extends TaroFormWidgetElement {
|
|
|
378
382
|
e.stopPropagation()
|
|
379
383
|
switch (item.nodeName) {
|
|
380
384
|
case 'INPUT':
|
|
381
|
-
case 'SLIDER':
|
|
385
|
+
case 'SLIDER':
|
|
382
386
|
case 'PICKER':
|
|
383
|
-
case 'RADIO':
|
|
387
|
+
case 'RADIO':
|
|
384
388
|
case 'SWITCH':
|
|
385
389
|
case 'CHECKBOX':
|
|
386
390
|
case 'TEXTAREA':
|