@tarojs/plugin-platform-harmony-ets 4.0.0-beta.21 → 4.0.0-beta.23
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 +1 -1
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/index.ts +24 -11
- package/dist/apis/ui/animation/animation.ts +2 -1
- package/dist/apis/wxml/IntersectionObserver.ts +5 -1
- package/dist/components-harmony-ets/button.ets +8 -1
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +7 -3
- package/dist/components-harmony-ets/form.ets +10 -2
- package/dist/components-harmony-ets/icon.ets +8 -1
- package/dist/components-harmony-ets/image.ets +8 -1
- package/dist/components-harmony-ets/index.ets +53 -0
- package/dist/components-harmony-ets/input.ets +2 -1
- package/dist/components-harmony-ets/label.ets +9 -2
- package/dist/components-harmony-ets/movableArea.ets +10 -3
- package/dist/components-harmony-ets/movableView.ets +10 -3
- package/dist/components-harmony-ets/picker.ets +1 -1
- package/dist/components-harmony-ets/progress.ets +8 -1
- package/dist/components-harmony-ets/radio.ets +7 -3
- package/dist/components-harmony-ets/scrollView.ets +9 -2
- package/dist/components-harmony-ets/slider.ets +2 -1
- package/dist/components-harmony-ets/style.ets +40 -4
- package/dist/components-harmony-ets/swiper.ets +8 -1
- package/dist/components-harmony-ets/switch.ets +3 -1
- package/dist/components-harmony-ets/text.ets +8 -1
- package/dist/components-harmony-ets/textArea.ets +2 -1
- package/dist/components-harmony-ets/utils/flexManager.ets +2 -2
- package/dist/components-harmony-ets/utils/helper.ets +1 -3
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +8 -62
- package/dist/components-harmony-ets/video.ets +9 -2
- package/dist/components-harmony-ets/view.ets +9 -2
- package/dist/index.d.ts +1 -1
- package/dist/runtime-ets/bom/window.ts +5 -0
- package/dist/runtime-ets/current.ts +1 -0
- package/dist/runtime-ets/dom/bind.ts +3 -3
- package/dist/runtime-ets/dom/cssNesting.ts +104 -22
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +2 -5
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +59 -44
- package/dist/runtime-ets/dom/element/form.ts +4 -14
- package/dist/runtime-ets/dom/element/index.ts +4 -2
- package/dist/runtime-ets/dom/element/progress.ts +0 -1
- package/dist/runtime-ets/dom/element/text.ts +0 -8
- package/dist/runtime-ets/dom/element/video.ts +4 -3
- package/dist/runtime-ets/dom/node.ts +15 -14
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +5 -4
- package/dist/runtime-ets/dom/stylesheet/util.ts +12 -10
- package/dist/runtime-ets/utils/index.ts +20 -2
- package/dist/runtime-ets/utils/info.ts +1 -1
- package/dist/runtime-framework/react/app.ts +2 -1
- package/dist/runtime-framework/react/native-page.ts +3 -2
- package/dist/runtime-framework/react/page.ts +1 -0
- package/dist/runtime-framework/solid/app.ts +19 -39
- package/dist/runtime-framework/solid/connect.ts +20 -2
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +7 -1
- package/dist/runtime-framework/solid/page.ts +84 -23
- package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
- package/dist/runtime-framework/solid/reconciler/render.ts +2 -1
- package/dist/runtime-utils.d.ts +3 -1
- package/dist/runtime-utils.js +24 -12
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +24 -12
- package/dist/runtime.js.map +1 -1
- package/package.json +10 -10
- /package/dist/components-harmony-ets/{index.ts → tag.ts} +0 -0
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { eventSource, TaroAny, TaroNode } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { TaroElement } from './element'
|
|
4
|
+
|
|
5
|
+
import type { CanvasProps, CanvasTouchEvent } from '@tarojs/components/types'
|
|
6
|
+
|
|
7
|
+
export class CanvasRenderingContext2DWXAdapter extends CanvasRenderingContext2D {
|
|
8
|
+
// constructor(settings?: RenderingContextSetting) {
|
|
9
|
+
// super(settings)
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
createCircularGradient() {
|
|
13
|
+
// Not supported now
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
draw(cb?: (...args: any[]) => any) {
|
|
17
|
+
typeof cb === 'function' && cb()
|
|
18
|
+
// Not supported now
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setFillStyle(fillStyle: typeof this.fillStyle) {
|
|
22
|
+
this.fillStyle = fillStyle
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setFontSize(fontSize: number) {
|
|
26
|
+
const font = this.font.split(' ')
|
|
27
|
+
font[2] = `${fontSize}`
|
|
28
|
+
this.font = font.join(' ')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setGlobalAlpha(globalAlpha: typeof this.globalAlpha) {
|
|
32
|
+
this.globalAlpha = globalAlpha
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setLineCap(lineCap: typeof this.lineCap) {
|
|
36
|
+
this.lineCap = lineCap
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setLineJoin(lineJoin: typeof this.lineJoin) {
|
|
40
|
+
this.lineJoin = lineJoin
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setLineWidth(lineWidth: typeof this.lineWidth) {
|
|
44
|
+
this.lineWidth = lineWidth
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setMiterLimit(miterLimit: typeof this.miterLimit) {
|
|
48
|
+
this.miterLimit = miterLimit
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setShadow(offsetX: number, offsetY: number, blur: number, color: string) {
|
|
52
|
+
this.shadowOffsetX = offsetX
|
|
53
|
+
this.shadowOffsetY = offsetY
|
|
54
|
+
this.shadowBlur = blur
|
|
55
|
+
this.shadowColor = color
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setStrokeStyle(strokeStyle: typeof this.strokeStyle) {
|
|
59
|
+
this.strokeStyle = strokeStyle
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setTextAlign(textAlign: typeof this.textAlign) {
|
|
63
|
+
this.textAlign = textAlign
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setTextBaseline(textBaseline: typeof this.textBaseline) {
|
|
67
|
+
this.textBaseline = textBaseline
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function getContextKey(obj) {
|
|
71
|
+
let currentObj = obj
|
|
72
|
+
let res = []
|
|
73
|
+
while (currentObj) {
|
|
74
|
+
if (currentObj instanceof CanvasRenderingContext2D) {
|
|
75
|
+
res = [...res, ...Object.getOwnPropertyNames(currentObj)]
|
|
76
|
+
}
|
|
77
|
+
currentObj = Object.getPrototypeOf(currentObj)
|
|
78
|
+
}
|
|
79
|
+
return res
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Observed
|
|
83
|
+
export class TaroCanvasElement extends TaroElement<CanvasProps, CanvasTouchEvent> {
|
|
84
|
+
_drawList: {
|
|
85
|
+
key: string
|
|
86
|
+
value: TaroAny
|
|
87
|
+
}[] = []
|
|
88
|
+
|
|
89
|
+
settings: RenderingContextSettings
|
|
90
|
+
_context: CanvasRenderingContext2D
|
|
91
|
+
_contextProxy: CanvasRenderingContext2D
|
|
92
|
+
|
|
93
|
+
constructor() {
|
|
94
|
+
super('Canvas')
|
|
95
|
+
this.settings = new RenderingContextSettings(true)
|
|
96
|
+
const context = new CanvasRenderingContext2DWXAdapter(this.settings) as CanvasRenderingContext2D
|
|
97
|
+
this._context = context
|
|
98
|
+
|
|
99
|
+
const proxyObj = getContextKey(context).reduce((obj, key) => {
|
|
100
|
+
if (typeof context[key] === 'function') {
|
|
101
|
+
obj[key] = new Proxy(context[key], {
|
|
102
|
+
apply: (target, thisArg, argumentsList) => {
|
|
103
|
+
this._drawList.push({
|
|
104
|
+
key,
|
|
105
|
+
value: argumentsList,
|
|
106
|
+
})
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
} else {
|
|
110
|
+
obj[key] = context[key]
|
|
111
|
+
}
|
|
112
|
+
return obj
|
|
113
|
+
}, {})
|
|
114
|
+
|
|
115
|
+
this._contextProxy = new Proxy(proxyObj, {
|
|
116
|
+
set: (_, property, value) => {
|
|
117
|
+
this._drawList.push({
|
|
118
|
+
key: property,
|
|
119
|
+
value,
|
|
120
|
+
})
|
|
121
|
+
return true
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get context() {
|
|
127
|
+
return this._contextProxy
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public setAttribute(name: string, value: TaroAny): void {
|
|
131
|
+
if (name === 'canvasId') {
|
|
132
|
+
eventSource.set(`canvasId-${value}`, this as TaroNode)
|
|
133
|
+
}
|
|
134
|
+
super.setAttribute(name, value)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -10,10 +10,10 @@ import { type ICSSStyleDeclaration, createCSSStyleDeclaration } from '../cssStyl
|
|
|
10
10
|
import { NodeType, TaroNode } from '../node'
|
|
11
11
|
import StyleSheet, { HarmonyStyle } from '../stylesheet'
|
|
12
12
|
|
|
13
|
-
import type { StandardProps } from '@tarojs/components/types'
|
|
13
|
+
import type { BaseTouchEvent, ITouchEvent, StandardProps } from '@tarojs/components/types'
|
|
14
14
|
import type { TaroAny } from '../../utils'
|
|
15
15
|
|
|
16
|
-
type NamedNodeMap =
|
|
16
|
+
type NamedNodeMap = { name: string, value: string }[]
|
|
17
17
|
|
|
18
18
|
export interface TaroExtraProps {
|
|
19
19
|
compileMode?: string | boolean
|
|
@@ -21,8 +21,12 @@ export interface TaroExtraProps {
|
|
|
21
21
|
disabled?: boolean
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export class TaroElement<
|
|
24
|
+
export class TaroElement<
|
|
25
|
+
T extends StandardProps<any, U> = StandardProps,
|
|
26
|
+
U extends BaseTouchEvent<any> = ITouchEvent
|
|
27
|
+
> extends TaroNode {
|
|
25
28
|
public _innerHTML = ''
|
|
29
|
+
public _instance: TaroAny
|
|
26
30
|
public _nodeInfo: TaroAny = {}
|
|
27
31
|
public readonly tagName: string
|
|
28
32
|
public dataset: Record<string, unknown> = EMPTY_OBJ
|
|
@@ -36,30 +40,30 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
36
40
|
bindAnimation(this)
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
public set id
|
|
43
|
+
public set id(value: string) {
|
|
40
44
|
this.setAttribute('id', value)
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
public get id
|
|
47
|
+
public get id(): string {
|
|
44
48
|
return this.getAttribute('id') || this._nid
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
public set className
|
|
51
|
+
public set className(value: string) {
|
|
48
52
|
this.setAttribute('class', value)
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
public get className
|
|
55
|
+
public get className(): string {
|
|
52
56
|
return this.getAttribute('class') || ''
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
public get classList
|
|
59
|
+
public get classList(): ClassList {
|
|
56
60
|
return new ClassList(this.className, this)
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
public get attributes
|
|
63
|
+
public get attributes(): NamedNodeMap {
|
|
60
64
|
const list: NamedNodeMap = []
|
|
61
65
|
|
|
62
|
-
Object.keys(this._attrs).forEach(name => {
|
|
66
|
+
Object.keys(this._attrs).forEach((name) => {
|
|
63
67
|
const value: TaroAny = this._attrs[name]
|
|
64
68
|
|
|
65
69
|
list.push({ name, value })
|
|
@@ -68,11 +72,11 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
68
72
|
return list
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
public get children
|
|
72
|
-
return this.childNodes.filter(node => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
|
|
75
|
+
public get children(): TaroElement[] {
|
|
76
|
+
return this.childNodes.filter((node) => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
public setAttribute
|
|
79
|
+
public setAttribute(name: string, value: TaroAny): void {
|
|
76
80
|
switch (name) {
|
|
77
81
|
case ID:
|
|
78
82
|
eventSource.delete(this._attrs.id)
|
|
@@ -88,11 +92,6 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
88
92
|
break
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
if (name === ID) {
|
|
92
|
-
eventSource.delete(this._attrs.id)
|
|
93
|
-
eventSource.set(value, this as TaroAny)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
95
|
this._attrs[name] = value
|
|
97
96
|
|
|
98
97
|
const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
|
|
@@ -106,48 +105,64 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
public getAttribute
|
|
108
|
+
public getAttribute(name: string): string {
|
|
110
109
|
return this._attrs[name]
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
public removeAttribute
|
|
112
|
+
public removeAttribute(name: string): void {
|
|
114
113
|
this._attrs[name] = null
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
public hasAttribute
|
|
116
|
+
public hasAttribute(name: string): boolean {
|
|
118
117
|
return !!this._attrs[name]
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
public hasAttributes
|
|
120
|
+
public hasAttributes(): boolean {
|
|
122
121
|
return Object.keys(this._attrs).length > 0
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
public getElementById<T extends TaroElement = TaroElement>
|
|
126
|
-
return findChildNodeWithDFS<T>(
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
public getElementById<T extends TaroElement = TaroElement>(id: string | undefined | null) {
|
|
125
|
+
return findChildNodeWithDFS<T>(
|
|
126
|
+
this as TaroAny,
|
|
127
|
+
(el) => {
|
|
128
|
+
return el.id === id
|
|
129
|
+
},
|
|
130
|
+
false
|
|
131
|
+
)
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
public getElementsByTagName<T extends TaroElement = TaroElement>
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
public getElementsByTagName<T extends TaroElement = TaroElement>(tagName: string) {
|
|
135
|
+
return (
|
|
136
|
+
findChildNodeWithDFS<T>(
|
|
137
|
+
this as TaroAny,
|
|
138
|
+
(el) => {
|
|
139
|
+
return el.nodeName === tagName || (tagName === '*' && (this as TaroAny) !== el)
|
|
140
|
+
},
|
|
141
|
+
true
|
|
142
|
+
) || []
|
|
143
|
+
)
|
|
135
144
|
}
|
|
136
145
|
|
|
137
|
-
public getElementsByClassName<T extends TaroElement = TaroElement>
|
|
146
|
+
public getElementsByClassName<T extends TaroElement = TaroElement>(className: string) {
|
|
138
147
|
const classNames = className.trim().split(new RegExp('\\s+'))
|
|
139
148
|
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
149
|
+
return (
|
|
150
|
+
findChildNodeWithDFS<T>(
|
|
151
|
+
this as TaroAny,
|
|
152
|
+
(el) => {
|
|
153
|
+
const classList = el.classList
|
|
154
|
+
return classNames.every((c) => {
|
|
155
|
+
const bool = classList.contains(c)
|
|
144
156
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
return bool
|
|
158
|
+
})
|
|
159
|
+
},
|
|
160
|
+
true
|
|
161
|
+
) || []
|
|
162
|
+
)
|
|
148
163
|
}
|
|
149
164
|
|
|
150
|
-
public set innerHTML
|
|
165
|
+
public set innerHTML(value: string) {
|
|
151
166
|
if (this.nodeType === NodeType.ELEMENT_NODE && this.ownerDocument) {
|
|
152
167
|
const ele = this.ownerDocument.createElement('inner-html')
|
|
153
168
|
ele._innerHTML = value
|
|
@@ -155,7 +170,7 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
172
|
|
|
158
|
-
public get innerHTML
|
|
173
|
+
public get innerHTML(): string {
|
|
159
174
|
return this._innerHTML
|
|
160
175
|
}
|
|
161
176
|
|
|
@@ -163,13 +178,13 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
163
178
|
public _st = new StyleSheet()
|
|
164
179
|
|
|
165
180
|
// 经转换后的鸿蒙样式
|
|
166
|
-
public get hmStyle
|
|
181
|
+
public get hmStyle() {
|
|
167
182
|
return this._st.hmStyle
|
|
168
183
|
}
|
|
169
184
|
|
|
170
185
|
public _style: ICSSStyleDeclaration | null = null
|
|
171
186
|
|
|
172
|
-
public get style
|
|
187
|
+
public get style(): ICSSStyleDeclaration | null {
|
|
173
188
|
return this._style
|
|
174
189
|
}
|
|
175
190
|
|
|
@@ -177,7 +192,7 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
177
192
|
// 可根据实际情况,迁移到具体的组件中,如View、ScrollView中,Text\Image其实是不需要的
|
|
178
193
|
public _pseudo_before: StyleSheet | null = null
|
|
179
194
|
|
|
180
|
-
public set_pseudo_before
|
|
195
|
+
public set_pseudo_before(value: HarmonyStyle | null) {
|
|
181
196
|
if (value) {
|
|
182
197
|
if (!this._pseudo_before) {
|
|
183
198
|
this._pseudo_before = new StyleSheet()
|
|
@@ -192,7 +207,7 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
192
207
|
|
|
193
208
|
public _pseudo_after: StyleSheet | null = null
|
|
194
209
|
|
|
195
|
-
public set_pseudo_after
|
|
210
|
+
public set_pseudo_after(value: HarmonyStyle | null) {
|
|
196
211
|
if (value) {
|
|
197
212
|
if (!this._pseudo_after) {
|
|
198
213
|
this._pseudo_after = new StyleSheet()
|
|
@@ -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 {
|
|
@@ -66,11 +62,10 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
66
62
|
|
|
67
63
|
public set name (val: string) {
|
|
68
64
|
this.updateFormWidgetName(val)
|
|
69
|
-
this.updateComponent()
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
public get value () {
|
|
73
|
-
return this._value
|
|
68
|
+
return this._nodeInfo._value
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
public set value (val: TaroAny) {
|
|
@@ -78,8 +73,6 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
78
73
|
|
|
79
74
|
if (this._instance) {
|
|
80
75
|
this._instance.value = val
|
|
81
|
-
} else {
|
|
82
|
-
this.updateComponent()
|
|
83
76
|
}
|
|
84
77
|
}
|
|
85
78
|
|
|
@@ -89,7 +82,7 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
89
82
|
}
|
|
90
83
|
|
|
91
84
|
public updateFormWidgetValue (val: TaroAny) {
|
|
92
|
-
this._value = val
|
|
85
|
+
this._nodeInfo._value = val
|
|
93
86
|
this._attrs.value = val
|
|
94
87
|
}
|
|
95
88
|
|
|
@@ -121,7 +114,6 @@ class TaroCheckedElement<T extends StandardProps & { checked?: boolean } = Stand
|
|
|
121
114
|
|
|
122
115
|
set checked (val: boolean) {
|
|
123
116
|
this.updateCheckedValue(val)
|
|
124
|
-
this.updateComponent()
|
|
125
117
|
}
|
|
126
118
|
|
|
127
119
|
public updateCheckedValue (val: boolean) {
|
|
@@ -220,12 +212,10 @@ class TaroRadioElement extends TaroCheckedElement<RadioProps>{
|
|
|
220
212
|
|
|
221
213
|
@Observed
|
|
222
214
|
class TaroSliderElement extends TaroFormWidgetElement<SliderProps> {
|
|
223
|
-
_value = 0
|
|
224
|
-
|
|
225
215
|
constructor() {
|
|
226
216
|
super('Slider')
|
|
227
217
|
|
|
228
|
-
this._value = Number(this._attrs.value || 0)
|
|
218
|
+
this._nodeInfo._value = Number(this._attrs.value || 0)
|
|
229
219
|
}
|
|
230
220
|
}
|
|
231
221
|
@Observed
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Current } from '../../current'
|
|
2
2
|
import { TaroTextNode } from '../node'
|
|
3
|
+
import { TaroCanvasElement } from './canvas'
|
|
3
4
|
import { TaroElement } from './element'
|
|
4
5
|
import {
|
|
5
6
|
FormElement,
|
|
@@ -55,6 +56,7 @@ export function initHarmonyElement () {
|
|
|
55
56
|
case 'icon': return new TaroIconElement()
|
|
56
57
|
case 'label': return new TaroLabelElement()
|
|
57
58
|
case 'rich-text': return new TaroRichTextElement()
|
|
59
|
+
case 'canvas': return new TaroCanvasElement()
|
|
58
60
|
case 'swiper': return new TaroSwiperElement()
|
|
59
61
|
case 'swiper-item': return new TaroSwiperItemElement()
|
|
60
62
|
case 'textarea': return new TaroTextAreaElement()
|
|
@@ -74,6 +76,7 @@ export function initHarmonyElement () {
|
|
|
74
76
|
export {
|
|
75
77
|
FormElement,
|
|
76
78
|
TaroButtonElement,
|
|
79
|
+
TaroCanvasElement,
|
|
77
80
|
TaroCheckboxElement,
|
|
78
81
|
TaroCheckboxGroupElement,
|
|
79
82
|
TaroElement,
|
|
@@ -99,5 +102,4 @@ export {
|
|
|
99
102
|
TaroTextElement,
|
|
100
103
|
TaroVideoElement,
|
|
101
104
|
TaroViewElement,
|
|
102
|
-
TaroWebViewElement
|
|
103
|
-
}
|
|
105
|
+
TaroWebViewElement }
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TaroNode } from '../node'
|
|
2
1
|
import { TaroElement } from './element'
|
|
3
2
|
|
|
4
3
|
import type { TextProps } from '@tarojs/components/types'
|
|
@@ -8,11 +7,4 @@ export class TaroTextElement extends TaroElement<TextProps> {
|
|
|
8
7
|
constructor() {
|
|
9
8
|
super('Text')
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
public appendChild (child: TaroNode): TaroNode {
|
|
13
|
-
super.appendChild(child)
|
|
14
|
-
|
|
15
|
-
this.updateComponent()
|
|
16
|
-
return child
|
|
17
|
-
}
|
|
18
10
|
}
|
|
@@ -4,12 +4,13 @@ import type { VideoProps } from '@tarojs/components/types'
|
|
|
4
4
|
|
|
5
5
|
@Observed
|
|
6
6
|
export class TaroVideoElement extends TaroElement<VideoProps> {
|
|
7
|
-
_currentTime = 0
|
|
8
7
|
|
|
9
8
|
controller: VideoController = new VideoController()
|
|
10
9
|
|
|
11
10
|
constructor() {
|
|
12
11
|
super('Video')
|
|
12
|
+
|
|
13
|
+
this._nodeInfo._currentTime = 0
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
async play() {
|
|
@@ -40,11 +41,11 @@ export class TaroVideoElement extends TaroElement<VideoProps> {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
get currentTime() {
|
|
43
|
-
return this._currentTime
|
|
44
|
+
return this._nodeInfo._currentTime
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
set currentTime(val: number) {
|
|
47
|
-
this._currentTime = val
|
|
48
|
+
this._nodeInfo._currentTime = val
|
|
48
49
|
this.controller.setCurrentTime(val)
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -59,8 +59,8 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
59
59
|
return this.childNodes[index] as TaroElement
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public findIndex (refChild
|
|
63
|
-
return this.childNodes.findIndex(node => node._nid === refChild
|
|
62
|
+
public findIndex (refChild?: TaroNode): number {
|
|
63
|
+
return this.childNodes.findIndex(node => node._nid === refChild?._nid)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
public updateTextNode () {
|
|
@@ -77,13 +77,11 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
77
77
|
|
|
78
78
|
// 更新对应的 ArkUI 组件
|
|
79
79
|
public updateComponent () {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// 半编译模式下走 @State 的更新模式
|
|
83
|
-
if (this._isDynamicNode) {
|
|
80
|
+
// 非半编译模式或者半编译模式下拥有自主更新权力的节点走 @State 的更新模式
|
|
81
|
+
if (this._isDynamicNode || !this._isCompileMode) {
|
|
84
82
|
this._updateTrigger++
|
|
85
83
|
} else {
|
|
86
|
-
this.parentNode
|
|
84
|
+
this.parentNode?.updateComponent()
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
|
|
@@ -128,11 +126,12 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
128
126
|
public set textContent (value: string) {
|
|
129
127
|
if (this.nodeType === NodeType.TEXT_NODE) {
|
|
130
128
|
this._textContent = value
|
|
131
|
-
this.parentNode?.updateComponent()
|
|
132
129
|
} else if (this.nodeType === NodeType.ELEMENT_NODE) {
|
|
133
130
|
const node = new TaroTextNode(value)
|
|
134
131
|
node._doc = this.ownerDocument
|
|
135
|
-
|
|
132
|
+
node.parentNode = this
|
|
133
|
+
this.childNodes.length = 0
|
|
134
|
+
this.childNodes.push(node)
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
|
|
@@ -150,7 +149,6 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
150
149
|
public set nodeValue (value: string | null) {
|
|
151
150
|
if (this.nodeType === NodeType.TEXT_NODE && value) {
|
|
152
151
|
this.textContent = value
|
|
153
|
-
this.parentNode?.updateComponent()
|
|
154
152
|
}
|
|
155
153
|
}
|
|
156
154
|
|
|
@@ -163,11 +161,13 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
163
161
|
}
|
|
164
162
|
|
|
165
163
|
// TODO cloneNode()、contains()
|
|
166
|
-
|
|
167
|
-
public appendChild (child: TaroNode): TaroNode {
|
|
164
|
+
public connectParentNode (child: TaroNode) {
|
|
168
165
|
child.parentNode?.removeChild(child)
|
|
169
166
|
child.parentNode = this
|
|
167
|
+
}
|
|
170
168
|
|
|
169
|
+
public appendChild (child: TaroNode): TaroNode {
|
|
170
|
+
this.connectParentNode(child)
|
|
171
171
|
this.childNodes.push(child)
|
|
172
172
|
this.notifyDataAdd(this.childNodes.length - 1)
|
|
173
173
|
|
|
@@ -175,14 +175,15 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
175
175
|
return child
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
public insertBefore (newNode: TaroNode, referenceNode
|
|
178
|
+
public insertBefore (newNode: TaroNode, referenceNode?: TaroNode): TaroNode {
|
|
179
179
|
newNode.parentNode?.removeChild(newNode)
|
|
180
180
|
|
|
181
|
-
if (referenceNode
|
|
181
|
+
if (!referenceNode) {
|
|
182
182
|
this.appendChild(newNode)
|
|
183
183
|
} else {
|
|
184
184
|
const idxOfRef = this.findIndex(referenceNode)
|
|
185
185
|
this.childNodes.splice(idxOfRef, 0, newNode)
|
|
186
|
+
this.connectParentNode(newNode)
|
|
186
187
|
// TODO: 优化
|
|
187
188
|
this.notifyDataReload()
|
|
188
189
|
}
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { CSSProperties } from 'react'
|
|
4
4
|
|
|
5
|
+
import { TaroElement } from '../element/element'
|
|
5
6
|
import { BORDER_STYLE_MAP, capitalizeFirstLetter, FlexManager, getNodeMarginOrPaddingData, getUnit } from './util'
|
|
6
7
|
|
|
7
|
-
// 将web端的style转换为hm端的style
|
|
8
|
-
export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
|
|
9
|
-
const hmStyle: Record<string, any> = {}
|
|
8
|
+
// Note: 将 web 端的 style 转换为 hm 端的 style
|
|
9
|
+
export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?: TaroElement) {
|
|
10
|
+
const hmStyle: Record<string, any> = node?._st?.hmStyle || {}
|
|
10
11
|
Object.keys(webStyle).forEach((key) => {
|
|
11
12
|
const value = webStyle[key]
|
|
12
13
|
switch (key) {
|
|
@@ -405,7 +406,7 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
|
|
|
405
406
|
}
|
|
406
407
|
case 'WebkitLineClamp': {
|
|
407
408
|
hmStyle.WebkitLineClamp = Number(value)
|
|
408
|
-
break
|
|
409
|
+
break
|
|
409
410
|
}
|
|
410
411
|
case 'transform': {
|
|
411
412
|
// todo: 需要更新
|
|
@@ -183,7 +183,6 @@ export class BORDER_STYLE_MAP {
|
|
|
183
183
|
case BorderStyle.Solid: return 'solid'
|
|
184
184
|
default: return ''
|
|
185
185
|
}
|
|
186
|
-
|
|
187
186
|
}
|
|
188
187
|
}
|
|
189
188
|
|
|
@@ -191,25 +190,28 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
|
|
|
191
190
|
let res: any = {}
|
|
192
191
|
if (dataValue) {
|
|
193
192
|
const values = dataValue.toString().trim().split(new RegExp('\\s+'))
|
|
193
|
+
let val1: string
|
|
194
|
+
let val2: string
|
|
194
195
|
switch (values.length) {
|
|
195
196
|
case 1:
|
|
196
|
-
|
|
197
|
+
val1 = getUnit(values[0])
|
|
198
|
+
res = { top: val1, right: val1, bottom: val1, left: val1 }
|
|
197
199
|
break
|
|
198
200
|
case 2:
|
|
199
|
-
|
|
201
|
+
val1 = getUnit(values[0])
|
|
202
|
+
val2 = getUnit(values[1])
|
|
203
|
+
res = { top: val1, right: val2, bottom: val1, left: val2 }
|
|
200
204
|
break
|
|
201
205
|
case 3:
|
|
202
|
-
|
|
206
|
+
val2 = getUnit(values[1])
|
|
207
|
+
res = { top: getUnit(values[0]), right: val2, bottom: getUnit(values[2]), left: val2 }
|
|
203
208
|
break
|
|
204
209
|
case 4:
|
|
205
|
-
res = { top: values[0], right: values[1], bottom: values[2], left: values[3] }
|
|
210
|
+
res = { top: getUnit(values[0]), right: getUnit(values[1]), bottom: getUnit(values[2]), left: getUnit(values[3]) }
|
|
206
211
|
break
|
|
207
212
|
default:
|
|
208
213
|
break
|
|
209
214
|
}
|
|
210
|
-
Object.keys(res).forEach(key => {
|
|
211
|
-
res[key] = getUnit(res[key]) || 0
|
|
212
|
-
})
|
|
213
215
|
}
|
|
214
216
|
return res
|
|
215
217
|
}
|
|
@@ -225,9 +227,9 @@ export function getUnit (val) {
|
|
|
225
227
|
}
|
|
226
228
|
if (val) {
|
|
227
229
|
// 匹配vw\vh
|
|
228
|
-
const exec = val.match(/(
|
|
230
|
+
const exec = val.match(/(-?\d*(\.\d+)?)(vw|vh|px)$/)
|
|
229
231
|
if (exec) {
|
|
230
|
-
const [, num, unit] = exec
|
|
232
|
+
const [, num, , unit] = exec
|
|
231
233
|
return convertNumber2VP(parseFloat(num), unit)
|
|
232
234
|
}
|
|
233
235
|
}
|