@tarojs/plugin-platform-harmony-ets 4.0.0-beta.0 → 4.0.0-beta.10
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/device/memory.ts +10 -3
- package/dist/apis/index.ts +2 -0
- package/dist/apis/media/video/VideoContext.ts +56 -7
- package/dist/apis/media/video/index.ts +3 -2
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +124 -60
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/components-harmony-ets/button.ets +26 -40
- package/dist/components-harmony-ets/checkbox.ets +70 -99
- package/dist/components-harmony-ets/form.ets +29 -42
- package/dist/components-harmony-ets/icon.ets +6 -34
- package/dist/components-harmony-ets/image.ets +2 -32
- package/dist/components-harmony-ets/innerHtml.ets +2 -2
- package/dist/components-harmony-ets/input.ets +7 -27
- package/dist/components-harmony-ets/label.ets +40 -47
- package/dist/components-harmony-ets/picker.ets +66 -73
- package/dist/components-harmony-ets/radio.ets +72 -101
- package/dist/components-harmony-ets/richText.ets +4 -36
- package/dist/components-harmony-ets/scrollView.ets +34 -74
- package/dist/components-harmony-ets/slider.ets +9 -34
- package/dist/components-harmony-ets/style.ets +154 -0
- package/dist/components-harmony-ets/swiper.ets +4 -34
- package/dist/components-harmony-ets/switch.ets +43 -56
- package/dist/components-harmony-ets/text.ets +7 -34
- package/dist/components-harmony-ets/textArea.ets +8 -28
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -11
- package/dist/components-harmony-ets/utils/flexManager.ets +45 -7
- package/dist/components-harmony-ets/utils/helper.ets +2 -2
- package/dist/components-harmony-ets/utils/styles.ets +58 -20
- package/dist/components-harmony-ets/video.ets +4 -34
- package/dist/components-harmony-ets/view.ets +25 -67
- package/dist/components-harmony-ets/webView.ets +50 -0
- package/dist/index.js +103 -5
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/window.ts +2 -2
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +30 -6
- package/dist/runtime-ets/dom/document.ts +21 -4
- package/dist/runtime-ets/dom/element/element.ts +1 -0
- package/dist/runtime-ets/dom/element/form.ts +11 -2
- package/dist/runtime-ets/dom/element/index.ts +4 -1
- package/dist/runtime-ets/dom/element/normal.ts +1 -0
- package/dist/runtime-ets/dom/element/webView.ts +61 -0
- package/dist/runtime-ets/dom/node.ts +29 -16
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +624 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +216 -354
- package/dist/runtime-ets/dom/stylesheet/type.ts +46 -11
- package/dist/runtime-ets/dom/stylesheet/util.ts +58 -6
- package/dist/runtime-ets/index.ts +1 -2
- package/dist/runtime-ets/interface/event.ts +2 -1
- package/dist/runtime-ets/utils/index.ts +6 -1
- package/dist/runtime-ets/utils/info.ts +3 -1
- package/dist/runtime-framework/react/app.ts +12 -22
- package/dist/runtime-framework/react/hooks.ts +3 -3
- package/dist/runtime-framework/react/index.ts +1 -0
- package/dist/runtime-framework/react/native-page.ts +344 -0
- package/dist/runtime-framework/react/page.ts +2 -2
- package/dist/runtime-framework/solid/hooks.ts +3 -3
- package/dist/runtime-utils.js +181 -80
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +181 -80
- package/dist/runtime.js.map +1 -1
- package/package.json +12 -11
- package/static/media/cancel.svg +1 -0
- package/static/media/circle.svg +1 -0
- package/static/media/clear.svg +1 -0
- package/static/media/download.svg +1 -0
- package/static/media/info.svg +1 -0
- package/static/media/info_circle.svg +1 -0
- package/static/media/search.svg +1 -0
- package/static/media/success.svg +1 -0
- package/static/media/success_no_circle.svg +1 -0
- package/static/media/taro_arrow_left.svg +1 -0
- package/static/media/taro_home.svg +1 -0
- package/static/media/waiting.svg +1 -0
- package/static/media/warn.svg +1 -0
- package/types/runtime.d.ts +2 -0
- package/dist/runtime-ets/utils/bind.ts +0 -24
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import { isUndefined } from '@tarojs/shared'
|
|
1
2
|
import { ObjectAssign } from '@tarojs/runtime'
|
|
2
3
|
|
|
4
|
+
import { FlexManager } from './FlexManager'
|
|
3
5
|
import { TEXT_DEFAULT_STYLE } from './constant/style'
|
|
4
6
|
|
|
5
|
-
import type { StandardProps } from '@tarojs/components/types'
|
|
7
|
+
import type { StandardProps, TextProps } from '@tarojs/components/types'
|
|
6
8
|
import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyType, HarmonyStyle } from '@tarojs/runtime'
|
|
7
9
|
|
|
8
10
|
export function getFontAttributes (node: TaroElement): TaroTextStyleType {
|
|
9
11
|
const hmStyle = node.hmStyle
|
|
12
|
+
const attrs: TextProps = node._attrs || {}
|
|
10
13
|
|
|
11
14
|
const attributes: TaroAny = {
|
|
12
|
-
|
|
15
|
+
WebkitLineClamp: attrs.maxLines || hmStyle.WebkitLineClamp || Infinity,
|
|
13
16
|
// 已做处理的属性
|
|
14
17
|
letterSpacing: hmStyle.letterSpacing,
|
|
15
18
|
textAlign: hmStyle.textAlign,
|
|
@@ -19,17 +22,25 @@ export function getFontAttributes (node: TaroElement): TaroTextStyleType {
|
|
|
19
22
|
return attributes
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
// 模拟 div 自动撑满父元素的情况
|
|
26
|
+
function isMaxWidthView (node: TaroElement) {
|
|
27
|
+
const parentNode: TaroElement = node.parentNode as TaroElement
|
|
28
|
+
|
|
29
|
+
return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' &&
|
|
30
|
+
!(FlexManager.isFlexNode(parentNode) && FlexManager.flexOptions(parentNode).direction !== FlexDirection.Column)
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
export function getNormalAttributes (node: TaroElement): TaroStyleType {
|
|
23
34
|
const hmStyle = node.hmStyle
|
|
24
35
|
|
|
25
36
|
const _nid = node._nid
|
|
26
37
|
const _attrs: StandardProps = node._attrs || {}
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
let linearGradient: HarmonyType.LinearGradient | undefined = undefined
|
|
40
|
+
// 渐变
|
|
41
|
+
if (hmStyle.backgroundImage?.colors) {
|
|
42
|
+
linearGradient = hmStyle.backgroundImage
|
|
43
|
+
}
|
|
33
44
|
|
|
34
45
|
let normalAttributes: HarmonyStyle = {
|
|
35
46
|
// Flex相关
|
|
@@ -38,28 +49,54 @@ export function getNormalAttributes (node: TaroElement): TaroStyleType {
|
|
|
38
49
|
flexShrink: hmStyle.flexShrink,
|
|
39
50
|
alignSelf: hmStyle.alignSelf,
|
|
40
51
|
// 尺寸相关
|
|
41
|
-
width: hmStyle.width,
|
|
52
|
+
width: isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width,
|
|
42
53
|
height: hmStyle.height,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
minHeight: hmStyle.minHeight,
|
|
55
|
+
maxHeight: hmStyle.maxHeight,
|
|
56
|
+
minWidth: hmStyle.minWidth,
|
|
57
|
+
maxWidth: hmStyle.maxWidth,
|
|
58
|
+
marginTop: hmStyle.marginTop,
|
|
59
|
+
marginRight: hmStyle.marginRight,
|
|
60
|
+
marginBottom: hmStyle.marginBottom,
|
|
61
|
+
marginLeft: hmStyle.marginLeft,
|
|
62
|
+
paddingTop: hmStyle.paddingTop,
|
|
63
|
+
paddingRight: hmStyle.paddingRight,
|
|
64
|
+
paddingBottom: hmStyle.paddingBottom,
|
|
65
|
+
paddingLeft: hmStyle.paddingLeft,
|
|
46
66
|
// 边框相关
|
|
47
67
|
borderStyle: hmStyle.borderStyle,
|
|
68
|
+
borderTopStyle: hmStyle.borderTopStyle,
|
|
69
|
+
borderRightStyle: hmStyle.borderRightStyle,
|
|
70
|
+
borderBottomStyle: hmStyle.borderBottomStyle,
|
|
71
|
+
borderLeftStyle: hmStyle.borderLeftStyle,
|
|
48
72
|
borderWidth: hmStyle.borderWidth,
|
|
73
|
+
borderTopWidth: hmStyle.borderTopWidth,
|
|
74
|
+
borderRightWidth: hmStyle.borderRightWidth,
|
|
75
|
+
borderBottomWidth: hmStyle.borderBottomWidth,
|
|
76
|
+
borderLeftWidth: hmStyle.borderLeftWidth,
|
|
49
77
|
borderColor: hmStyle.borderColor,
|
|
78
|
+
borderTopColor: hmStyle.borderTopColor,
|
|
79
|
+
borderRightColor: hmStyle.borderRightColor,
|
|
80
|
+
borderBottomColor: hmStyle.borderBottomColor,
|
|
81
|
+
borderLeftColor: hmStyle.borderLeftColor,
|
|
50
82
|
borderRadius: hmStyle.borderRadius,
|
|
83
|
+
borderTopLeftRadius: hmStyle.borderTopLeftRadius,
|
|
84
|
+
borderTopRightRadius: hmStyle.borderTopRightRadius,
|
|
85
|
+
borderBottomRightRadius: hmStyle.borderBottomRightRadius,
|
|
86
|
+
borderBottomLeftRadius: hmStyle.borderBottomLeftRadius,
|
|
51
87
|
// 背景相关
|
|
52
88
|
backgroundColor: hmStyle.backgroundColor,
|
|
53
89
|
backgroundImage: hmStyle.backgroundImage,
|
|
54
|
-
|
|
90
|
+
backgroundSize: hmStyle.backgroundSize,
|
|
55
91
|
backgroundRepeat: hmStyle.backgroundRepeat,
|
|
56
|
-
|
|
57
|
-
linearGradient
|
|
92
|
+
backgroundPosition: hmStyle.backgroundPosition,
|
|
93
|
+
linearGradient,
|
|
58
94
|
// 变换相关
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
95
|
+
transform: hmStyle.transform,
|
|
96
|
+
transformOrigin: {
|
|
97
|
+
x: hmStyle.transformOrigin?.x || 0,
|
|
98
|
+
y: hmStyle.transformOrigin?.y || 0
|
|
99
|
+
},
|
|
63
100
|
// 通用文本相关
|
|
64
101
|
color: hmStyle.color,
|
|
65
102
|
fontSize: hmStyle.fontSize,
|
|
@@ -67,11 +104,12 @@ export function getNormalAttributes (node: TaroElement): TaroStyleType {
|
|
|
67
104
|
fontWeight: hmStyle.fontWeight,
|
|
68
105
|
fontFamily: hmStyle.fontFamily || TEXT_DEFAULT_STYLE.FONT_FAMILY,
|
|
69
106
|
lineHeight: hmStyle.lineHeight,
|
|
70
|
-
|
|
107
|
+
textDecoration: hmStyle.textDecoration,
|
|
71
108
|
// 其他
|
|
72
|
-
|
|
109
|
+
overflow: hmStyle.overflow,
|
|
73
110
|
id: _attrs.id || _nid,
|
|
74
111
|
opacity: hmStyle.opacity,
|
|
112
|
+
zIndex: hmStyle.zIndex
|
|
75
113
|
// focus: _attrs.focus || false,
|
|
76
114
|
}
|
|
77
115
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
|
+
import commonStyleModify from './style'
|
|
3
4
|
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
4
|
-
import {
|
|
5
|
+
import { shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
5
6
|
|
|
6
|
-
import type {
|
|
7
|
+
import type { TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
|
|
7
8
|
|
|
8
9
|
export interface VideoOptions {
|
|
9
10
|
src?: string | Resource
|
|
@@ -21,37 +22,6 @@ export interface VideoUpdateEvent {
|
|
|
21
22
|
time: number
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
@Extend(Video)
|
|
25
|
-
function attrs (style: TaroStyleType) {
|
|
26
|
-
.id(style.id)
|
|
27
|
-
.key(style.id)
|
|
28
|
-
.padding(style.padding)
|
|
29
|
-
.margin(style.margin)
|
|
30
|
-
.width(style.width)
|
|
31
|
-
.height(style.height)
|
|
32
|
-
.constraintSize(style.constraintSize)
|
|
33
|
-
.flexGrow(style.flexGrow)
|
|
34
|
-
.flexShrink(style.flexShrink)
|
|
35
|
-
.flexBasis(style.flexBasis)
|
|
36
|
-
.alignSelf(style.alignSelf)
|
|
37
|
-
.backgroundColor(style.backgroundColor)
|
|
38
|
-
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
39
|
-
.backgroundImageSize(style.backgroundImageSize)
|
|
40
|
-
.backgroundImagePosition(style.backgroundImagePosition)
|
|
41
|
-
.rotate(style.rotate)
|
|
42
|
-
.scale(style.scale)
|
|
43
|
-
.translate(style.translate)
|
|
44
|
-
.transform(style.transform)
|
|
45
|
-
.borderStyle(style.borderStyle)
|
|
46
|
-
.borderWidth(style.borderWidth)
|
|
47
|
-
.borderColor(style.borderColor)
|
|
48
|
-
.borderRadius(style.borderRadius)
|
|
49
|
-
.linearGradient(style.linearGradient)
|
|
50
|
-
.zIndex(style.zIndex)
|
|
51
|
-
.opacity(style.opacity)
|
|
52
|
-
.clip(style.clip)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
25
|
@Extend(Video)
|
|
56
26
|
function props(attr: VideoAttrs) {
|
|
57
27
|
.muted(attr.muted)
|
|
@@ -111,7 +81,7 @@ function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
|
|
|
111
81
|
@Builder
|
|
112
82
|
export default function TaroVideo (node: TaroVideoElement) {
|
|
113
83
|
Video(getVideoData(node))
|
|
114
|
-
.
|
|
84
|
+
.attributeModifier(commonStyleModify.setNode(node))
|
|
115
85
|
.props(getVideoProps(node))
|
|
116
86
|
.aspectRatio(4 / 3)
|
|
117
87
|
.onStart(shouldBindEvent(() => { emitEvent(node, 'play') }, node, ['play']))
|
|
@@ -1,96 +1,54 @@
|
|
|
1
1
|
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
|
+
import commonStyleModify from './style'
|
|
3
4
|
import { createLazyChildren } from './render'
|
|
4
5
|
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
5
6
|
import { FlexManager } from './utils/FlexManager'
|
|
6
7
|
import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
|
|
7
8
|
|
|
8
|
-
import type { TaroViewElement,
|
|
9
|
+
import type { TaroViewElement, TaroStyleType, TaroAny } from '@tarojs/runtime'
|
|
9
10
|
|
|
10
|
-
@Extend(
|
|
11
|
-
function
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.padding(style.padding)
|
|
19
|
-
.margin(style.margin)
|
|
20
|
-
.width(style.width)
|
|
21
|
-
.height(style.height)
|
|
22
|
-
.constraintSize(style.constraintSize)
|
|
23
|
-
.backgroundColor(style.backgroundColor)
|
|
24
|
-
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
25
|
-
.backgroundImageSize(style.backgroundImageSize)
|
|
26
|
-
.backgroundImagePosition(style.backgroundImagePosition)
|
|
27
|
-
.rotate(style.rotate)
|
|
28
|
-
.scale(style.scale)
|
|
29
|
-
.translate(style.translate)
|
|
30
|
-
.transform(style.transform)
|
|
31
|
-
.borderStyle(style.borderStyle)
|
|
32
|
-
.borderWidth(style.borderWidth)
|
|
33
|
-
.borderColor(style.borderColor)
|
|
34
|
-
.borderRadius(style.borderRadius)
|
|
35
|
-
.linearGradient(style.linearGradient)
|
|
36
|
-
.zIndex(style.zIndex)
|
|
37
|
-
.opacity(style.opacity)
|
|
38
|
-
.clip(style.clip)
|
|
11
|
+
@Extend(Row)
|
|
12
|
+
function rowAttrs (style: TaroStyleType) {
|
|
13
|
+
.constraintSize({
|
|
14
|
+
minWidth: style.minWidth || style.width,
|
|
15
|
+
maxWidth: style.maxWidth,
|
|
16
|
+
minHeight: style.minHeight,
|
|
17
|
+
maxHeight: style.maxHeight
|
|
18
|
+
})
|
|
39
19
|
}
|
|
40
20
|
|
|
41
|
-
|
|
42
21
|
@Extend(Column)
|
|
43
22
|
function columnAttrs (style: TaroStyleType) {
|
|
44
|
-
.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.padding(style.padding)
|
|
51
|
-
.margin(style.margin)
|
|
52
|
-
.width(style.width)
|
|
53
|
-
.height(style.height)
|
|
54
|
-
.constraintSize(style.constraintSize)
|
|
55
|
-
.backgroundColor(style.backgroundColor)
|
|
56
|
-
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
57
|
-
.backgroundImageSize(style.backgroundImageSize)
|
|
58
|
-
.backgroundImagePosition(style.backgroundImagePosition)
|
|
59
|
-
.rotate(style.rotate)
|
|
60
|
-
.scale(style.scale)
|
|
61
|
-
.translate(style.translate)
|
|
62
|
-
.transform(style.transform)
|
|
63
|
-
.borderStyle(style.borderStyle)
|
|
64
|
-
.borderWidth(style.borderWidth)
|
|
65
|
-
.borderColor(style.borderColor)
|
|
66
|
-
.borderRadius(style.borderRadius)
|
|
67
|
-
.linearGradient(style.linearGradient)
|
|
68
|
-
.zIndex(style.zIndex)
|
|
69
|
-
.opacity(style.opacity)
|
|
70
|
-
.clip(style.clip)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function isFlexNode (node: TaroViewElement) {
|
|
74
|
-
return !!node.hmStyle?.display?.includes('flex')
|
|
23
|
+
.constraintSize({
|
|
24
|
+
minWidth: style.minWidth,
|
|
25
|
+
maxWidth: style.maxWidth,
|
|
26
|
+
minHeight: style.minHeight || style.height,
|
|
27
|
+
maxHeight: style.maxHeight
|
|
28
|
+
})
|
|
75
29
|
}
|
|
76
30
|
|
|
77
31
|
@Builder
|
|
78
32
|
export default function TaroView (node: TaroViewElement) {
|
|
79
|
-
if (isFlexNode(node)) {
|
|
80
|
-
|
|
33
|
+
if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
|
|
34
|
+
Row() {
|
|
81
35
|
createLazyChildren(node)
|
|
82
36
|
}
|
|
83
|
-
.
|
|
37
|
+
.attributeModifier(commonStyleModify.setNode(node))
|
|
38
|
+
.rowAttrs(getNormalAttributes(node))
|
|
84
39
|
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
|
|
85
40
|
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
|
|
86
41
|
.onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
87
42
|
node._nodeInfo.areaInfo = res[1]
|
|
88
43
|
}))
|
|
89
44
|
.onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
|
|
45
|
+
.alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
|
|
46
|
+
.justifyContent(FlexManager.flexOptions(node).justifyContent)
|
|
90
47
|
} else {
|
|
91
48
|
Column() {
|
|
92
49
|
createLazyChildren(node)
|
|
93
50
|
}
|
|
51
|
+
.attributeModifier(commonStyleModify.setNode(node))
|
|
94
52
|
.columnAttrs(getNormalAttributes(node))
|
|
95
53
|
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
|
|
96
54
|
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
|
|
@@ -98,7 +56,7 @@ export default function TaroView (node: TaroViewElement) {
|
|
|
98
56
|
node._nodeInfo.areaInfo = res[1]
|
|
99
57
|
}))
|
|
100
58
|
.onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
|
|
101
|
-
.alignItems(
|
|
102
|
-
.justifyContent(node.
|
|
59
|
+
.alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
|
|
60
|
+
.justifyContent(FlexManager.flexOptions(node).justifyContent)
|
|
103
61
|
}
|
|
104
62
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import commonStyleModify from './style'
|
|
4
|
+
import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
5
|
+
|
|
6
|
+
import type { TaroAny, TaroWebViewElement, TaroStyleType, TaroEvent } from '@tarojs/runtime'
|
|
7
|
+
|
|
8
|
+
interface IPageLoad {
|
|
9
|
+
url: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IError {
|
|
13
|
+
request: WebResourceRequest
|
|
14
|
+
error: WebResourceError
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Builder
|
|
18
|
+
export default function TaroWebView (node: TaroWebViewElement) {
|
|
19
|
+
Web({ src: node._attrs.src, controller: node.controller })
|
|
20
|
+
.attributeModifier(commonStyleModify.setNode(node))
|
|
21
|
+
.onPageEnd((e: IPageLoad) => {
|
|
22
|
+
// 1. 创建消息端口
|
|
23
|
+
node.ports = node.controller.createWebMessagePorts(true)
|
|
24
|
+
// 2. 发送端口1到HTML5
|
|
25
|
+
node.controller.postMessage('init_web_messageport', [node.ports[1]], '*');
|
|
26
|
+
// 3. 保存端口0到本地
|
|
27
|
+
node.nativePort = node.ports[0]
|
|
28
|
+
// 4. 设置回调函数
|
|
29
|
+
node.nativePort.onMessageEventExt((result) => {
|
|
30
|
+
const message = node.handleMessageFromWeb(result)
|
|
31
|
+
const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, node)
|
|
32
|
+
|
|
33
|
+
eventHandler(messageEvent, 'message', node)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: node._attrs.src } }, node)
|
|
37
|
+
|
|
38
|
+
eventHandler(onLoadEvent, 'load', node)
|
|
39
|
+
})
|
|
40
|
+
.onErrorReceive(shouldBindEvent((e: IError) => {
|
|
41
|
+
const event: TaroEvent = createTaroEvent('error', { detail: { url: node._attrs.src, fullUrl: e.request.getRequestUrl() } }, node)
|
|
42
|
+
|
|
43
|
+
eventHandler(event, 'error', node)
|
|
44
|
+
}, node, ['error']))
|
|
45
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
|
|
46
|
+
.onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
47
|
+
node._nodeInfo.areaInfo = res[1]
|
|
48
|
+
}))
|
|
49
|
+
.onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
|
|
50
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
44
44
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
45
45
|
PERFORMANCE OF THIS SOFTWARE.
|
|
46
46
|
***************************************************************************** */
|
|
47
|
-
/* global Reflect, Promise */
|
|
47
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
@@ -68,6 +68,91 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
68
68
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
69
69
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
70
70
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
74
|
+
var e = new Error(message);
|
|
75
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function apiLoader(str) {
|
|
79
|
+
return `import {
|
|
80
|
+
useAddToFavorites,
|
|
81
|
+
useDidHide,
|
|
82
|
+
useDidShow,
|
|
83
|
+
useError,
|
|
84
|
+
useLaunch,
|
|
85
|
+
useLoad,
|
|
86
|
+
useOptionMenuClick,
|
|
87
|
+
usePageNotFound,
|
|
88
|
+
usePageScroll,
|
|
89
|
+
usePullDownRefresh,
|
|
90
|
+
usePullIntercept,
|
|
91
|
+
useReachBottom,
|
|
92
|
+
useReady,
|
|
93
|
+
useResize,
|
|
94
|
+
useRouter,
|
|
95
|
+
useSaveExitState,
|
|
96
|
+
useShareAppMessage,
|
|
97
|
+
useShareTimeline,
|
|
98
|
+
useTabItemTap,
|
|
99
|
+
useTitleClick,
|
|
100
|
+
useScope,
|
|
101
|
+
useUnhandledRejection,
|
|
102
|
+
useUnload
|
|
103
|
+
} from '@tarojs/plugin-framework-react/dist/runtime'
|
|
104
|
+
${str}
|
|
105
|
+
|
|
106
|
+
taro.useAddToFavorites = useAddToFavorites
|
|
107
|
+
taro.useDidHide = useDidHide
|
|
108
|
+
taro.useDidShow = useDidShow
|
|
109
|
+
taro.useError = useError
|
|
110
|
+
taro.useLaunch = useLaunch
|
|
111
|
+
taro.useLoad = useLoad
|
|
112
|
+
taro.useOptionMenuClick = useOptionMenuClick
|
|
113
|
+
taro.usePageNotFound = usePageNotFound
|
|
114
|
+
taro.usePageScroll = usePageScroll
|
|
115
|
+
taro.usePullDownRefresh = usePullDownRefresh
|
|
116
|
+
taro.usePullIntercept = usePullIntercept
|
|
117
|
+
taro.useReachBottom = useReachBottom
|
|
118
|
+
taro.useReady = useReady
|
|
119
|
+
taro.useResize = useResize
|
|
120
|
+
taro.useRouter = useRouter
|
|
121
|
+
taro.useSaveExitState = useSaveExitState
|
|
122
|
+
taro.useShareAppMessage = useShareAppMessage
|
|
123
|
+
taro.useShareTimeline = useShareTimeline
|
|
124
|
+
taro.useTabItemTap = useTabItemTap
|
|
125
|
+
taro.useTitleClick = useTitleClick
|
|
126
|
+
taro.useScope = useScope
|
|
127
|
+
taro.useUnhandledRejection = useUnhandledRejection
|
|
128
|
+
taro.useUnload = useUnload
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
useAddToFavorites,
|
|
132
|
+
useDidHide,
|
|
133
|
+
useDidShow,
|
|
134
|
+
useError,
|
|
135
|
+
useLaunch,
|
|
136
|
+
useLoad,
|
|
137
|
+
useOptionMenuClick,
|
|
138
|
+
usePageNotFound,
|
|
139
|
+
usePageScroll,
|
|
140
|
+
usePullDownRefresh,
|
|
141
|
+
usePullIntercept,
|
|
142
|
+
useReachBottom,
|
|
143
|
+
useReady,
|
|
144
|
+
useResize,
|
|
145
|
+
useRouter,
|
|
146
|
+
useSaveExitState,
|
|
147
|
+
useShareAppMessage,
|
|
148
|
+
useShareTimeline,
|
|
149
|
+
useTabItemTap,
|
|
150
|
+
useTitleClick,
|
|
151
|
+
useScope,
|
|
152
|
+
useUnhandledRejection,
|
|
153
|
+
useUnload
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
71
156
|
}
|
|
72
157
|
|
|
73
158
|
const PLATFORM_NAME = 'harmony';
|
|
@@ -159,7 +244,8 @@ class TaroPlatformHarmony extends service.TaroPlatform {
|
|
|
159
244
|
FRAMEWORK: JSON.stringify(this.config.framework),
|
|
160
245
|
TARO_ENV: JSON.stringify(this.platform),
|
|
161
246
|
TARO_PLATFORM: JSON.stringify(this.platformType),
|
|
162
|
-
TARO_VERSION: JSON.stringify(_package.getPkgVersion())
|
|
247
|
+
TARO_VERSION: JSON.stringify(_package.getPkgVersion()),
|
|
248
|
+
SUPPORT_TARO_POLYFILL: 'disabled',
|
|
163
249
|
},
|
|
164
250
|
});
|
|
165
251
|
return Object.assign(Object.assign(Object.assign({}, config), { buildAdapter: config.platform, fileType: this.fileType, platformType: this.platformType, useETS: this.useETS, useJSON5: this.useJSON5 }), extraOptions);
|
|
@@ -364,8 +450,16 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
|
364
450
|
? path__namespace.join(path__namespace.dirname(target), `${basename}${ext}`)
|
|
365
451
|
: path__namespace.join(target, `index${isDTS ? '.d.ts' : ext}`);
|
|
366
452
|
}
|
|
367
|
-
else
|
|
368
|
-
|
|
453
|
+
else {
|
|
454
|
+
const libPath = path__namespace.relative(targetPath, target);
|
|
455
|
+
if (libDir !== libPath) {
|
|
456
|
+
if (path__namespace.relative(libPath, libDir).startsWith('.')) {
|
|
457
|
+
target = path__namespace.join(targetPath, libDir);
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
target = path__namespace.join(targetPath, libName, `index${ext}`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
369
463
|
}
|
|
370
464
|
}
|
|
371
465
|
}
|
|
@@ -380,6 +474,10 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
|
380
474
|
}
|
|
381
475
|
else if (stat.isFile()) {
|
|
382
476
|
let code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
|
|
477
|
+
// TODO: 后续这部分代码应该根据使用的框架抽离到对应的平台插件处
|
|
478
|
+
if ([/(@tarojs[\\/]plugin-platform-harmony-ets|taro-platform-harmony)[\\/]dist[\\/]apis[\\/]index\.ts/].some(e => e.test(lib))) {
|
|
479
|
+
code = apiLoader(code);
|
|
480
|
+
}
|
|
383
481
|
if (this.extensions.includes(path__namespace.extname(lib))) {
|
|
384
482
|
code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
|
|
385
483
|
const { outputRoot } = this.ctx.runOpts.config;
|
|
@@ -552,7 +650,7 @@ function App(props) {
|
|
|
552
650
|
isFile: (file) => {
|
|
553
651
|
try {
|
|
554
652
|
const stat = helper.fs.lstatSync(file);
|
|
555
|
-
return stat.isFile() || (file.endsWith(mediaPath) && stat.isDirectory());
|
|
653
|
+
return stat.isFile() || (file.endsWith(mediaPath.replace('/', path__namespace.sep)) && stat.isDirectory());
|
|
556
654
|
}
|
|
557
655
|
catch (_) { } // eslint-disable-line no-empty
|
|
558
656
|
return false;
|