@tarojs/plugin-platform-harmony-ets 4.0.0-beta.22 → 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/index.ts +22 -12
- 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 +13 -5
- 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/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 +4 -59
- package/dist/components-harmony-ets/video.ets +9 -2
- package/dist/components-harmony-ets/view.ets +9 -2
- 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/element.ts +1 -5
- package/dist/runtime-ets/dom/element/form.ts +4 -14
- 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 +12 -11
- 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 +16 -2
- package/dist/runtime-ets/utils/info.ts +1 -1
- package/dist/runtime-framework/react/native-page.ts +1 -0
- package/dist/runtime-framework/react/page.ts +1 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +3 -8
- package/dist/runtime-utils.js +16 -10
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +16 -10
- package/dist/runtime.js.map +1 -1
- package/package.json +10 -9
- /package/dist/template/{container.js/container.js → container.js} +0 -0
|
@@ -31,10 +31,12 @@ export default struct TaroSwitch {
|
|
|
31
31
|
@Builder customBuilder() {}
|
|
32
32
|
@BuilderParam createLazyChildren: (node: TaroSwitchElement) => void = this.customBuilder
|
|
33
33
|
@ObjectLink node: TaroSwitchElement
|
|
34
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
34
35
|
|
|
35
36
|
aboutToAppear () {
|
|
36
37
|
if (this.node && !this.node._isInit) {
|
|
37
38
|
this.node._isInit = true
|
|
39
|
+
this.node._instance = this
|
|
38
40
|
this.node._reset = this.node.checked || false
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -45,7 +47,7 @@ export default struct TaroSwitch {
|
|
|
45
47
|
type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
|
|
46
48
|
isOn: this.node.checked,
|
|
47
49
|
})
|
|
48
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
50
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
49
51
|
.attrs(getAttributes(this.node))
|
|
50
52
|
.themeStyles(!!this.node._attrs.disabled)
|
|
51
53
|
.onChange((isOn: boolean) => {
|
|
@@ -44,6 +44,13 @@ export default struct TaroText {
|
|
|
44
44
|
@Builder customBuilder() {}
|
|
45
45
|
@BuilderParam createLazyChildren: (node: TaroTextElement) => void = this.customBuilder
|
|
46
46
|
@ObjectLink node: TaroTextElement
|
|
47
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
48
|
+
|
|
49
|
+
aboutToAppear(): void {
|
|
50
|
+
if (this.node) {
|
|
51
|
+
this.node._instance = this
|
|
52
|
+
}
|
|
53
|
+
}
|
|
47
54
|
|
|
48
55
|
build () {
|
|
49
56
|
if (this.node.nodeType === NodeType.TEXT_NODE) {
|
|
@@ -66,7 +73,7 @@ export default struct TaroText {
|
|
|
66
73
|
if (this.node.hmStyle?.display !== 'none') {
|
|
67
74
|
Text(this.node.textContent)
|
|
68
75
|
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
69
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
76
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
70
77
|
.textNormalFontStyle(this.node?.hmStyle)
|
|
71
78
|
.textSpecialFontStyle(getFontAttributes(this.node))
|
|
72
79
|
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
@@ -33,6 +33,7 @@ export default struct TaroTextArea {
|
|
|
33
33
|
@Builder customBuilder() {}
|
|
34
34
|
@BuilderParam createLazyChildren: (node: TaroTextAreaElement) => void = this.customBuilder
|
|
35
35
|
@ObjectLink node: TaroTextAreaElement
|
|
36
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
36
37
|
|
|
37
38
|
aboutToAppear () {
|
|
38
39
|
if (this.node) {
|
|
@@ -52,7 +53,7 @@ export default struct TaroTextArea {
|
|
|
52
53
|
.key(this.node._nid)
|
|
53
54
|
.maxLength(Number(this.node._attrs?.maxlength) || null)
|
|
54
55
|
.placeholderColor(getPlaceholderColor(this.node))
|
|
55
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
56
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
56
57
|
.textStyle(this.node?.hmStyle)
|
|
57
58
|
.textAttr(getFontAttributes(this.node))
|
|
58
59
|
.onChange((value: string) => {
|
|
@@ -14,7 +14,7 @@ class FlexManager {
|
|
|
14
14
|
static isFlexNode (node: TaroElement): boolean {
|
|
15
15
|
return !!node.hmStyle?.display?.includes('flex')
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
|
|
19
19
|
if (direction === FlexDirection.Column) {
|
|
20
20
|
switch (alignItems) {
|
|
@@ -38,7 +38,7 @@ class FlexManager {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
static flexOptions (node: TaroElement): IFlexOptions {
|
|
41
|
-
const hmStyle = node.hmStyle
|
|
41
|
+
const hmStyle = node.hmStyle || {}
|
|
42
42
|
const isFlex = FlexManager.isFlexNode(node)
|
|
43
43
|
const justifyContent: FlexAlign = isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
|
|
44
44
|
|
|
@@ -31,9 +31,7 @@ export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function getNodeThresholds (node: TaroElement): number[] | null {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return node?._nodeInfo.thresholds || null
|
|
34
|
+
return node?._nodeInfo?.thresholds || null
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
|
|
@@ -21,70 +21,15 @@ export function getMultiSelector(ctx, range, rangeKey, value) {
|
|
|
21
21
|
}))
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function getUnit (val) {
|
|
25
|
-
if (/\d+
|
|
24
|
+
export function getUnit (val: string | number): string {
|
|
25
|
+
if (isNumber(val) || /\d+px$/.test(val)) {
|
|
26
|
+
return convertNumber2VP(parseFloat(val as string))
|
|
27
|
+
} else if (/\d+(vp)$/.test(val)) {
|
|
26
28
|
return val
|
|
27
|
-
} else if (isNumber(val) || /\d+px$/.test(val)) {
|
|
28
|
-
return convertNumber2VP(parseFloat(val))
|
|
29
29
|
}
|
|
30
30
|
return val
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function handleNodeStyleData (dataValue: string, handler: (values: string[]) => { [key: string]: string } | void) {
|
|
34
|
-
let res: any = {}
|
|
35
|
-
if (dataValue) {
|
|
36
|
-
const values = dataValue.toString().trim().split(/\s+/)
|
|
37
|
-
const data = handler(values)
|
|
38
|
-
|
|
39
|
-
if (!data) return res
|
|
40
|
-
|
|
41
|
-
res = data
|
|
42
|
-
|
|
43
|
-
Object.keys(res).forEach(key => {
|
|
44
|
-
const exec = `${res[key]}`.match(/(\d+)(px)$/)
|
|
45
|
-
if (exec && values.length > 1) {
|
|
46
|
-
res[key] = getUnit(+exec[1])
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return res
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function getNodeBorderRadiusData (dataValue: string) {
|
|
55
|
-
return handleNodeStyleData(dataValue, values => {
|
|
56
|
-
switch (values.length) {
|
|
57
|
-
case 1:
|
|
58
|
-
return { topLeft: values[0], topRight: values[0], bottomRight: values[0], bottomLeft: values[0] }
|
|
59
|
-
case 2:
|
|
60
|
-
return { topLeft: values[0], topRight: values[1], bottomRight: values[0], bottomLeft: values[1] }
|
|
61
|
-
case 3:
|
|
62
|
-
return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[1] }
|
|
63
|
-
case 4:
|
|
64
|
-
return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[3] }
|
|
65
|
-
default:
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function getNodeMarginOrPaddingData (dataValue: string) {
|
|
72
|
-
return handleNodeStyleData(dataValue, values => {
|
|
73
|
-
switch (values.length) {
|
|
74
|
-
case 1:
|
|
75
|
-
return { top: values[0], right: values[0], bottom: values[0], left: values[0] }
|
|
76
|
-
case 2:
|
|
77
|
-
return { top: values[0], right: values[1], bottom: values[0], left: values[1] }
|
|
78
|
-
case 3:
|
|
79
|
-
return { top: values[0], right: values[1], bottom: values[2], left: values[1] }
|
|
80
|
-
case 4:
|
|
81
|
-
return { top: values[0], right: values[1], bottom: values[2], left: values[3] }
|
|
82
|
-
default:
|
|
83
|
-
break
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
33
|
export function generateText (node: TaroRichTextElement): string {
|
|
89
34
|
return parseHtmlNode(node._attrs.nodes || '')
|
|
90
35
|
}
|
|
@@ -73,7 +73,7 @@ function getVideoProps (node: TaroVideoElement): VideoAttrs {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
|
|
76
|
-
node._currentTime = e.time
|
|
76
|
+
node._nodeInfo._currentTime = e.time
|
|
77
77
|
|
|
78
78
|
emitEvent(node, 'timeUpdate', { currentTime: e.time})
|
|
79
79
|
}
|
|
@@ -83,11 +83,18 @@ export default struct TaroVideo {
|
|
|
83
83
|
@Builder customBuilder() {}
|
|
84
84
|
@BuilderParam createLazyChildren: (node: TaroVideoElement) => void = this.customBuilder
|
|
85
85
|
@ObjectLink node: TaroVideoElement
|
|
86
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
87
|
+
|
|
88
|
+
aboutToAppear(): void {
|
|
89
|
+
if (this.node) {
|
|
90
|
+
this.node._instance = this
|
|
91
|
+
}
|
|
92
|
+
}
|
|
86
93
|
|
|
87
94
|
build () {
|
|
88
95
|
if (this.node.hmStyle?.display !== 'none') {
|
|
89
96
|
Video(getVideoData(this.node))
|
|
90
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
97
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
91
98
|
.props(getVideoProps(this.node))
|
|
92
99
|
.aspectRatio(4 / 3)
|
|
93
100
|
.onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
|
|
@@ -13,6 +13,13 @@ export default struct TaroView {
|
|
|
13
13
|
@Builder customBuilder() {}
|
|
14
14
|
@BuilderParam createLazyChildren: (node: TaroViewElement) => void = this.customBuilder
|
|
15
15
|
@ObjectLink node: TaroViewElement
|
|
16
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
17
|
+
|
|
18
|
+
aboutToAppear(): void {
|
|
19
|
+
if (this.node) {
|
|
20
|
+
this.node._instance = this
|
|
21
|
+
}
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
build () {
|
|
18
25
|
if (this.node.hmStyle?.display !== 'none') {
|
|
@@ -24,7 +31,7 @@ export default struct TaroView {
|
|
|
24
31
|
this.createLazyChildren(this.node)
|
|
25
32
|
}
|
|
26
33
|
}
|
|
27
|
-
.attributeModifier(rowModify.setNode(this.node))
|
|
34
|
+
.attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
28
35
|
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
29
36
|
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
30
37
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
@@ -41,7 +48,7 @@ export default struct TaroView {
|
|
|
41
48
|
this.createLazyChildren(this.node)
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
|
-
.attributeModifier(columnModify.setNode(this.node))
|
|
51
|
+
.attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
45
52
|
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
46
53
|
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
47
54
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Current } from '../current'
|
|
1
2
|
import { ObjectAssign } from '../utils'
|
|
2
3
|
|
|
3
4
|
import type { TaroAny } from '../utils'
|
|
@@ -54,7 +55,7 @@ export function bindAnimation (node: TaroElement) {
|
|
|
54
55
|
animateParams.duration = 0
|
|
55
56
|
}
|
|
56
57
|
animateParams.curve = Curve[convertToCamelCase(timingFunction)] || Curve.EaseInOut
|
|
57
|
-
animateTo(animateParams, () => {
|
|
58
|
+
Current.uiContext.animateTo(animateParams, () => {
|
|
58
59
|
const transformOrigin: string = anim.transformOrigin
|
|
59
60
|
|
|
60
61
|
if (transformOrigin) {
|
|
@@ -69,8 +70,7 @@ export function bindAnimation (node: TaroElement) {
|
|
|
69
70
|
})
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
node.
|
|
73
|
-
node.updateComponent()
|
|
73
|
+
node._instance.overwriteStyle = anim.rule
|
|
74
74
|
})
|
|
75
75
|
})
|
|
76
76
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { parseClasses } from '../utils'
|
|
2
|
+
|
|
3
|
+
import type { CSSProperties, ReactElement } from 'react'
|
|
4
|
+
|
|
1
5
|
// 抽出来的嵌套查询
|
|
2
6
|
// const __nesting_style__ = [
|
|
3
7
|
// {
|
|
@@ -8,7 +12,7 @@
|
|
|
8
12
|
// }
|
|
9
13
|
// },
|
|
10
14
|
// ]
|
|
11
|
-
//
|
|
15
|
+
//
|
|
12
16
|
// function Index() {
|
|
13
17
|
// return __combine_nesting_style__(jsx(TaroViewTagName, {
|
|
14
18
|
// className: "container aaa",
|
|
@@ -39,8 +43,6 @@
|
|
|
39
43
|
// }), __nesting_style__);
|
|
40
44
|
// }
|
|
41
45
|
|
|
42
|
-
import type { ReactElement } from 'react'
|
|
43
|
-
|
|
44
46
|
type TMappingNode = {
|
|
45
47
|
node: ReactElement
|
|
46
48
|
children: TMapping
|
|
@@ -71,6 +73,13 @@ function depthTraversal(root: ReactElement) {
|
|
|
71
73
|
const traverse = (tree) => {
|
|
72
74
|
const result: Record<string, TMapping> = {}
|
|
73
75
|
if (tree && tree.props) {
|
|
76
|
+
// 兜底适配:如果Taro组件被原封不动的再别的地方导出使用,导致无法在编译环境添加__hmStyle
|
|
77
|
+
// import { View } from '~/components'
|
|
78
|
+
// hack:如果是taro节点,但是被赋予了__styleSheet,则走一下__styleSheet转__hmStyle
|
|
79
|
+
if (tree.props.__styleSheet && typeof tree.type !== 'function') {
|
|
80
|
+
tree.props.__hmStyle = tree.props.__styleSheet.value
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
// 后代选择器
|
|
75
84
|
const descendant_map = {
|
|
76
85
|
node: tree,
|
|
@@ -93,7 +102,7 @@ function depthTraversal(root: ReactElement) {
|
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
// 拆分classnames
|
|
96
|
-
const classnames = (tree.props.className || '')
|
|
105
|
+
const classnames = parseClasses(tree.props.className || '')
|
|
97
106
|
for (let i = 0; i < classnames.length; i++) {
|
|
98
107
|
const cls = classnames[i]
|
|
99
108
|
let name = cls
|
|
@@ -128,17 +137,19 @@ function depthTraversal(root: ReactElement) {
|
|
|
128
137
|
|
|
129
138
|
const leaf_map = traverse(leaf)
|
|
130
139
|
if (!leaf_map) return
|
|
140
|
+
|
|
131
141
|
// 直接后代
|
|
132
142
|
Object.assign(descendant_map.children, leaf_map)
|
|
143
|
+
|
|
133
144
|
// 子孙后代
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
Object.assign(descendant_map.descendants, leaf_child_map.descendants)
|
|
145
|
+
const grandchild: (Record<string, TMapping> | TMapping)[] = [leaf_map]
|
|
146
|
+
Object.keys(leaf_map).forEach(key => {
|
|
147
|
+
const leaf_child_map = class_mapping[key]
|
|
148
|
+
if (leaf_child_map?.descendants) {
|
|
149
|
+
grandchild.push(leaf_child_map.descendants)
|
|
140
150
|
}
|
|
141
|
-
}
|
|
151
|
+
})
|
|
152
|
+
Object.assign(descendant_map.descendants, ...grandchild)
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
traverse(root)
|
|
@@ -151,7 +162,7 @@ function depthTraversal(root: ReactElement) {
|
|
|
151
162
|
// 将嵌套样式与节点合并
|
|
152
163
|
function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias: Record<string, string[]>) {
|
|
153
164
|
|
|
154
|
-
const findElement = (selector_string, combinator_type, selector_mapping) => {
|
|
165
|
+
const findElement = (selector_string, combinator_type, selector_mapping, remainder_selector, declaration) => {
|
|
155
166
|
let selector_list = [selector_string]
|
|
156
167
|
const selector_nodes: TSelectorNode[] = []
|
|
157
168
|
let shouldUseCombinations = false
|
|
@@ -184,6 +195,15 @@ function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias
|
|
|
184
195
|
}
|
|
185
196
|
// 找出最后搜寻出来的node
|
|
186
197
|
if (obj) {
|
|
198
|
+
if (typeof obj.node.type === 'function') {
|
|
199
|
+
// 自定义组件,往下传递需要搜寻的内容向里面搜寻
|
|
200
|
+
const nestingData = {
|
|
201
|
+
selectors: [selector_string, combinator_type, ...remainder_selector.slice()],
|
|
202
|
+
declaration: declaration
|
|
203
|
+
}
|
|
204
|
+
obj.node.props.__nesting = obj.node.props.__nesting ?
|
|
205
|
+
[...obj.node.props.__nesting, nestingData] : [nestingData]
|
|
206
|
+
}
|
|
187
207
|
selector_nodes.push({
|
|
188
208
|
mapping: (obj.ref || obj)[combinator_type === ' > ' ? 'children' : 'descendants'],
|
|
189
209
|
node: obj.node
|
|
@@ -193,6 +213,15 @@ function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias
|
|
|
193
213
|
// 查询选择器的节点
|
|
194
214
|
const object = selector_mapping[selector]
|
|
195
215
|
if (object) {
|
|
216
|
+
if (typeof object.node.type === 'function') {
|
|
217
|
+
// 自定义组件,往下传递需要搜寻的内容向里面搜寻
|
|
218
|
+
const nestingData = {
|
|
219
|
+
selectors: [selector_string, combinator_type, ...remainder_selector.slice()],
|
|
220
|
+
declaration: declaration
|
|
221
|
+
}
|
|
222
|
+
object.node.props.__nesting = object.node.props.__nesting ?
|
|
223
|
+
[...object.node.props.__nesting, nestingData] : [nestingData]
|
|
224
|
+
}
|
|
196
225
|
selector_nodes.push({
|
|
197
226
|
mapping: (object.ref || object)[combinator_type === ' > ' ? 'children' : 'descendants'],
|
|
198
227
|
node: object.node
|
|
@@ -202,16 +231,16 @@ function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias
|
|
|
202
231
|
}
|
|
203
232
|
return selector_nodes
|
|
204
233
|
}
|
|
205
|
-
const findSelector = (selectors, current_mapping): TSelectorNode[] => {
|
|
234
|
+
const findSelector = (selectors, current_mapping, declaration): TSelectorNode[] => {
|
|
206
235
|
const new_selectors = selectors.slice()
|
|
207
236
|
const selector_string = new_selectors.shift()
|
|
208
237
|
const combinator_type = new_selectors.shift()
|
|
209
|
-
const _elements = findElement(selector_string, combinator_type, current_mapping)
|
|
238
|
+
const _elements = findElement(selector_string, combinator_type, current_mapping, new_selectors, declaration)
|
|
210
239
|
if (_elements.length) {
|
|
211
240
|
if (new_selectors.length) {
|
|
212
241
|
let elements: TSelectorNode[] = []
|
|
213
242
|
_elements.forEach(element => {
|
|
214
|
-
elements = elements.concat(findSelector(new_selectors.slice(), element.mapping))
|
|
243
|
+
elements = elements.concat(findSelector(new_selectors.slice(), element.mapping, declaration))
|
|
215
244
|
})
|
|
216
245
|
return elements
|
|
217
246
|
} else {
|
|
@@ -225,10 +254,10 @@ function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias
|
|
|
225
254
|
// 合并样式
|
|
226
255
|
nestingStyle.forEach(({ selectors, declaration }) => {
|
|
227
256
|
// 获取选中的节点列表
|
|
228
|
-
const selectors_elements = findSelector(selectors, class_mapping)
|
|
257
|
+
const selectors_elements = findSelector(selectors, class_mapping, declaration)
|
|
229
258
|
for (let i = 0; i < selectors_elements.length; i++) {
|
|
230
259
|
const ele = selectors_elements[i].node
|
|
231
|
-
if (ele) {
|
|
260
|
+
if (ele && typeof ele !== 'function') {
|
|
232
261
|
// 直接注入到__hmStyle
|
|
233
262
|
// Hack: ReactElement会在dev模式下被冻结,所以在dev模式下,我们会将Object.freeze覆盖使其失效
|
|
234
263
|
if (ele.props.__hmStyle) {
|
|
@@ -299,13 +328,66 @@ function findSendNode (selectorArr: string[], selector_mapping: TMapping) {
|
|
|
299
328
|
return obj
|
|
300
329
|
}
|
|
301
330
|
|
|
331
|
+
function insertParentStyle(data: {key: string, value: CSSProperties}, class_mapping: TMapping, alias: Record<string, string[]>) {
|
|
332
|
+
const { key, value } = data
|
|
333
|
+
key.split(' ').forEach(key => {
|
|
334
|
+
let classnames = [key]
|
|
335
|
+
if (alias[key]) {
|
|
336
|
+
classnames = classnames.concat(alias[key])
|
|
337
|
+
}
|
|
338
|
+
classnames.forEach(name => {
|
|
339
|
+
if (class_mapping[name]) {
|
|
340
|
+
// 插入样式
|
|
341
|
+
const ele = class_mapping[key].node
|
|
342
|
+
if (ele) {
|
|
343
|
+
// 直接注入到__hmStyle
|
|
344
|
+
// Hack: ReactElement会在dev模式下被冻结,所以在dev模式下,我们会将Object.freeze覆盖使其失效
|
|
345
|
+
if (ele.props.__hmStyle) {
|
|
346
|
+
ele.props.__hmStyle = Object.assign({}, ele.props.__hmStyle, value)
|
|
347
|
+
} else {
|
|
348
|
+
ele.props.__hmStyle = value
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
}
|
|
356
|
+
|
|
302
357
|
// 合并嵌套样式
|
|
303
358
|
// 1、构建映射表,生成一份扁平的样式表结构
|
|
304
359
|
// 2、遍历嵌套样式,根据选择器查找节点,合并样式
|
|
305
|
-
export function __combine_nesting_style__(react_tree: ReactElement, styles: NestingStyle) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
360
|
+
export function __combine_nesting_style__(react_tree: ReactElement, styles: NestingStyle | null) {
|
|
361
|
+
if (react_tree) {
|
|
362
|
+
let newStyle = styles
|
|
363
|
+
const parentProps: {
|
|
364
|
+
__styleSheet?: {key: string, value: CSSProperties}
|
|
365
|
+
__nesting?: NestingStyle
|
|
366
|
+
} = // @ts-ignore
|
|
367
|
+
react_tree._owner?.pendingProps // Hack:取出父组件的props,考虑版本问题,取的内部属性,可能会有问题
|
|
368
|
+
|
|
369
|
+
if (newStyle || (parentProps && (parentProps.__styleSheet || parentProps.__nesting))) {
|
|
370
|
+
// 1、循环一遍,构建出一颗JSX映射表
|
|
371
|
+
const { mapping, alias } = depthTraversal(react_tree)
|
|
372
|
+
if (parentProps) {
|
|
373
|
+
// 2、如果自定义节点,则增加合成__stylesheet步骤,将父节点的样式合并到当前节点
|
|
374
|
+
if (parentProps.__styleSheet) {
|
|
375
|
+
insertParentStyle(parentProps.__styleSheet, mapping, alias)
|
|
376
|
+
// @ts-ignore
|
|
377
|
+
parentProps.__styleSheet = null // 释放内存
|
|
378
|
+
}
|
|
379
|
+
// 3、如果自定节点,存在需要往下查询的嵌套样式,需要合并到子组件
|
|
380
|
+
if (parentProps.__nesting) {
|
|
381
|
+
newStyle = (newStyle || []).concat(parentProps.__nesting)
|
|
382
|
+
// @ts-ignore
|
|
383
|
+
parentProps.__nesting = null // 释放内存
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// 4、合并嵌套样式样式
|
|
387
|
+
if (newStyle && newStyle.length) {
|
|
388
|
+
combineStyle(newStyle, mapping, alias)
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
310
392
|
return react_tree
|
|
311
393
|
}
|
|
@@ -53,11 +53,7 @@ class CSSStyleDeclaration {
|
|
|
53
53
|
prop = prop.includes('-') ? toCamelCase(prop) : prop
|
|
54
54
|
const node = this.el
|
|
55
55
|
if ((typeof value === 'string' && value.length) || typeof value === 'number' || isObject(value)) {
|
|
56
|
-
|
|
57
|
-
const newProperty = convertWebStyle2HmStyle({ [prop]: value })
|
|
58
|
-
Object.keys(newProperty).forEach(key => {
|
|
59
|
-
node._st.hmStyle[key] = newProperty[key]
|
|
60
|
-
})
|
|
56
|
+
convertWebStyle2HmStyle({ [prop]: value }, node)
|
|
61
57
|
} else if (!value) {
|
|
62
58
|
this.removeProperty(prop)
|
|
63
59
|
}
|
|
@@ -82,6 +78,7 @@ class CSSStyleDeclaration {
|
|
|
82
78
|
type ICSSStyleDeclaration = CSSStyleDeclaration & Record<string, any>
|
|
83
79
|
|
|
84
80
|
function createCSSStyleDeclaration (node: TaroElement): CSSStyleDeclaration {
|
|
81
|
+
// FIXME 临时使用 Proxy 代理,后续需要优化
|
|
85
82
|
return new Proxy(new CSSStyleDeclaration(node), {
|
|
86
83
|
set (target, prop: string, value) {
|
|
87
84
|
if (prop === 'cssText') {
|
|
@@ -26,6 +26,7 @@ export class TaroElement<
|
|
|
26
26
|
U extends BaseTouchEvent<any> = ITouchEvent
|
|
27
27
|
> extends TaroNode {
|
|
28
28
|
public _innerHTML = ''
|
|
29
|
+
public _instance: TaroAny
|
|
29
30
|
public _nodeInfo: TaroAny = {}
|
|
30
31
|
public readonly tagName: string
|
|
31
32
|
public dataset: Record<string, unknown> = EMPTY_OBJ
|
|
@@ -91,11 +92,6 @@ export class TaroElement<
|
|
|
91
92
|
break
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
if (name === ID) {
|
|
95
|
-
eventSource.delete(this._attrs.id)
|
|
96
|
-
eventSource.set(value, this as TaroAny)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
95
|
this._attrs[name] = value
|
|
100
96
|
|
|
101
97
|
const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
|
|
@@ -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,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
|
}
|