@tarojs/plugin-platform-harmony-ets 4.0.0-beta.1 → 4.0.0-beta.11

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.
Files changed (67) hide show
  1. package/dist/apis/device/memory.ts +10 -3
  2. package/dist/apis/index.ts +2 -0
  3. package/dist/apis/network/request.ts +5 -5
  4. package/dist/apis/route/index.ts +15 -0
  5. package/dist/apis/storage/index.ts +124 -60
  6. package/dist/apis/wxml/index.ts +2 -0
  7. package/dist/components-harmony-ets/button.ets +54 -100
  8. package/dist/components-harmony-ets/checkbox.ets +25 -140
  9. package/dist/components-harmony-ets/form.ets +34 -78
  10. package/dist/components-harmony-ets/icon.ets +24 -82
  11. package/dist/components-harmony-ets/image.ets +16 -76
  12. package/dist/components-harmony-ets/innerHtml.ets +10 -6
  13. package/dist/components-harmony-ets/input.ets +3 -62
  14. package/dist/components-harmony-ets/label.ets +46 -83
  15. package/dist/components-harmony-ets/movableArea.ets +67 -0
  16. package/dist/components-harmony-ets/movableView.ets +66 -0
  17. package/dist/components-harmony-ets/picker.ets +33 -141
  18. package/dist/components-harmony-ets/progress.ets +45 -0
  19. package/dist/components-harmony-ets/radio.ets +24 -140
  20. package/dist/components-harmony-ets/richText.ets +17 -78
  21. package/dist/components-harmony-ets/scrollView.ets +61 -155
  22. package/dist/components-harmony-ets/slider.ets +5 -69
  23. package/dist/components-harmony-ets/style.ets +154 -0
  24. package/dist/components-harmony-ets/swiper.ets +26 -86
  25. package/dist/components-harmony-ets/switch.ets +5 -69
  26. package/dist/components-harmony-ets/text.ets +29 -87
  27. package/dist/components-harmony-ets/textArea.ets +3 -62
  28. package/dist/components-harmony-ets/utils/flexManager.ets +44 -6
  29. package/dist/components-harmony-ets/utils/helper.ets +2 -2
  30. package/dist/components-harmony-ets/utils/styles.ets +12 -1
  31. package/dist/components-harmony-ets/video.ets +29 -88
  32. package/dist/components-harmony-ets/view.ets +38 -144
  33. package/dist/components-harmony-ets/webView.ets +55 -0
  34. package/dist/index.js +122 -17
  35. package/dist/index.js.map +1 -1
  36. package/dist/runtime-ets/bom/window.ts +2 -2
  37. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +23 -3
  38. package/dist/runtime-ets/dom/document.ts +21 -4
  39. package/dist/runtime-ets/dom/element/element.ts +0 -1
  40. package/dist/runtime-ets/dom/element/form.ts +11 -4
  41. package/dist/runtime-ets/dom/element/index.ts +12 -1
  42. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  43. package/dist/runtime-ets/dom/element/movableView.ts +12 -0
  44. package/dist/runtime-ets/dom/element/normal.ts +9 -2
  45. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  46. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  47. package/dist/runtime-ets/dom/element/text.ts +1 -0
  48. package/dist/runtime-ets/dom/element/video.ts +1 -0
  49. package/dist/runtime-ets/dom/element/webView.ts +69 -0
  50. package/dist/runtime-ets/dom/node.ts +18 -17
  51. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +73 -0
  52. package/dist/runtime-ets/dom/stylesheet/util.ts +3 -1
  53. package/dist/runtime-ets/index.ts +1 -2
  54. package/dist/runtime-ets/utils/index.ts +4 -1
  55. package/dist/runtime-framework/react/app.ts +12 -22
  56. package/dist/runtime-framework/react/hooks.ts +3 -3
  57. package/dist/runtime-framework/react/index.ts +1 -0
  58. package/dist/runtime-framework/react/native-page.ts +344 -0
  59. package/dist/runtime-framework/react/page.ts +2 -2
  60. package/dist/runtime-framework/solid/hooks.ts +3 -3
  61. package/dist/runtime-utils.js +134 -68
  62. package/dist/runtime-utils.js.map +1 -1
  63. package/dist/runtime.js +134 -68
  64. package/dist/runtime.js.map +1 -1
  65. package/package.json +10 -10
  66. package/types/runtime.d.ts +2 -0
  67. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -1,5 +1,7 @@
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
7
  import type { StandardProps, TextProps } from '@tarojs/components/types'
@@ -20,6 +22,14 @@ export function getFontAttributes (node: TaroElement): TaroTextStyleType {
20
22
  return attributes
21
23
  }
22
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
+
23
33
  export function getNormalAttributes (node: TaroElement): TaroStyleType {
24
34
  const hmStyle = node.hmStyle
25
35
 
@@ -39,7 +49,7 @@ export function getNormalAttributes (node: TaroElement): TaroStyleType {
39
49
  flexShrink: hmStyle.flexShrink,
40
50
  alignSelf: hmStyle.alignSelf,
41
51
  // 尺寸相关
42
- width: hmStyle.width,
52
+ width: isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width,
43
53
  height: hmStyle.height,
44
54
  minHeight: hmStyle.minHeight,
45
55
  maxHeight: hmStyle.maxHeight,
@@ -99,6 +109,7 @@ export function getNormalAttributes (node: TaroElement): TaroStyleType {
99
109
  overflow: hmStyle.overflow,
100
110
  id: _attrs.id || _nid,
101
111
  opacity: hmStyle.opacity,
112
+ zIndex: hmStyle.zIndex
102
113
  // focus: _attrs.focus || false,
103
114
  }
104
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 { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
5
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
5
6
 
6
- import type { TaroStyleType, TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
7
8
 
8
9
  export interface VideoOptions {
9
10
  src?: string | Resource
@@ -21,71 +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
- .flexGrow(style.flexGrow)
29
- .flexShrink(style.flexShrink)
30
- .flexBasis(style.flexBasis)
31
- .alignSelf(style.alignSelf)
32
- .padding({
33
- top: style.paddingTop,
34
- right: style.paddingRight,
35
- bottom: style.paddingBottom,
36
- left: style.paddingLeft
37
- })
38
- .margin({
39
- top: style.marginTop,
40
- right: style.marginRight,
41
- bottom: style.marginBottom,
42
- left: style.marginLeft
43
- })
44
- .width(style.width)
45
- .height(style.height)
46
- .constraintSize({
47
- minWidth: style.minWidth,
48
- maxWidth: style.maxWidth,
49
- minHeight: style.minHeight,
50
- maxHeight: style.maxHeight
51
- })
52
- .backgroundColor(style.backgroundColor)
53
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
54
- .backgroundImageSize(style.backgroundSize)
55
- .backgroundImagePosition(style.backgroundPosition)
56
- .borderStyle({
57
- top: style.borderTopStyle,
58
- right: style.borderRightStyle,
59
- bottom: style.borderBottomStyle,
60
- left: style.borderLeftStyle
61
- })
62
- .borderWidth({
63
- top: style.borderTopWidth,
64
- right: style.borderRightWidth,
65
- bottom: style.borderBottomWidth,
66
- left: style.borderLeftWidth
67
- })
68
- .borderColor({
69
- top: style.borderTopColor,
70
- right: style.borderRightColor,
71
- bottom: style.borderBottomColor,
72
- left: style.borderLeftColor
73
- })
74
- .borderRadius({
75
- topLeft: style.borderTopLeftRadius,
76
- topRight: style.borderTopRightRadius,
77
- bottomLeft: style.borderBottomLeftRadius,
78
- bottomRight: style.borderBottomRightRadius
79
- })
80
- .zIndex(style.zIndex)
81
- .opacity(style.opacity)
82
- .linearGradient(style.linearGradient)
83
- .clip(style.overflow)
84
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
85
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
86
- .transform(style.transform)
87
- }
88
-
89
25
  @Extend(Video)
90
26
  function props(attr: VideoAttrs) {
91
27
  .muted(attr.muted)
@@ -142,25 +78,30 @@ function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
142
78
  emitEvent(node, 'timeUpdate', { currentTime: e.time})
143
79
  }
144
80
 
145
- @Builder
146
- export default function TaroVideo (node: TaroVideoElement) {
147
- Video(getVideoData(node))
148
- .attrs(getNormalAttributes(node))
149
- .props(getVideoProps(node))
150
- .aspectRatio(4 / 3)
151
- .onStart(shouldBindEvent(() => { emitEvent(node, 'play') }, node, ['play']))
152
- .onPause(shouldBindEvent(() => { emitEvent(node, 'pause') }, node, ['pause']))
153
- .onFinish(shouldBindEvent(() => { emitEvent(node, 'ended') }, node, ['ended']))
154
- .onError(shouldBindEvent(() => { emitEvent(node, 'error') }, node, ['error']))
155
- .onUpdate((e) => { handleUpdate(node, e) })
156
- .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'loadedMetaData', { duration: e.duration }) }, node, ['loadedmetadata']))
157
- .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'seeking', { duration: e.time }) }, node, ['seeking']))
158
- .onSeeked(shouldBindEvent(() => { emitEvent(node, 'seeked') }, node, ['seeked']))
159
- .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, node, ['fullscreenchange']))
160
- .onClick((e: ClickEvent) => { eventHandler(e, 'click', node) })
161
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
162
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
163
- node._nodeInfo.areaInfo = res[1]
164
- }))
165
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
81
+ @Component
82
+ export default struct TaroVideo {
83
+ @ObjectLink node: TaroVideoElement
84
+
85
+ build () {
86
+ Video(getVideoData(this.node))
87
+ .attributeModifier(commonStyleModify.setNode(this.node))
88
+ .props(getVideoProps(this.node))
89
+ .aspectRatio(4 / 3)
90
+ .onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
91
+ .onPause(shouldBindEvent(() => { emitEvent(this.node, 'pause') }, this.node, ['pause']))
92
+ .onFinish(shouldBindEvent(() => { emitEvent(this.node, 'ended') }, this.node, ['ended']))
93
+ .onError(shouldBindEvent(() => { emitEvent(this.node, 'error') }, this.node, ['error']))
94
+ .onUpdate((e) => { handleUpdate(this.node, e) })
95
+ .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
96
+ .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'seeking', { duration: e.time }) }, this.node, ['seeking']))
97
+ .onSeeked(shouldBindEvent(() => { emitEvent(this.node, 'seeked') }, this.node, ['seeked']))
98
+ .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
99
+ .onClick((e: ClickEvent) => { eventHandler(e, 'click', this.node) })
100
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
101
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
102
+ this.node._nodeInfo.areaInfo = res[1]
103
+ }))
104
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
105
+ }
106
+
166
107
  }
@@ -1,172 +1,66 @@
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, TaroAny, TaroStyleType } from '@tarojs/runtime'
9
+ import type { TaroViewElement, TaroStyleType, TaroAny } from '@tarojs/runtime'
9
10
 
10
- @Extend(Flex)
11
- function flexAttrs (style: TaroStyleType) {
12
- .id(style.id)
13
- .key(style.id)
14
- .flexGrow(style.flexGrow)
15
- .flexShrink(style.flexShrink)
16
- .flexBasis(style.flexBasis)
17
- .alignSelf(style.alignSelf)
18
- .padding({
19
- top: style.paddingTop,
20
- right: style.paddingRight,
21
- bottom: style.paddingBottom,
22
- left: style.paddingLeft
23
- })
24
- .margin({
25
- top: style.marginTop,
26
- right: style.marginRight,
27
- bottom: style.marginBottom,
28
- left: style.marginLeft
29
- })
30
- .width(style.width)
31
- .height(style.height)
11
+ @Extend(Row)
12
+ function rowAttrs (style: TaroStyleType) {
32
13
  .constraintSize({
33
- minWidth: style.minWidth,
14
+ minWidth: style.minWidth || style.width,
34
15
  maxWidth: style.maxWidth,
35
16
  minHeight: style.minHeight,
36
17
  maxHeight: style.maxHeight
37
18
  })
38
- .backgroundColor(style.backgroundColor)
39
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
40
- .backgroundImageSize(style.backgroundSize)
41
- .backgroundImagePosition(style.backgroundPosition)
42
- .borderStyle({
43
- top: style.borderTopStyle,
44
- right: style.borderRightStyle,
45
- bottom: style.borderBottomStyle,
46
- left: style.borderLeftStyle
47
- })
48
- .borderWidth({
49
- top: style.borderTopWidth,
50
- right: style.borderRightWidth,
51
- bottom: style.borderBottomWidth,
52
- left: style.borderLeftWidth
53
- })
54
- .borderColor({
55
- top: style.borderTopColor,
56
- right: style.borderRightColor,
57
- bottom: style.borderBottomColor,
58
- left: style.borderLeftColor
59
- })
60
- .borderRadius({
61
- topLeft: style.borderTopLeftRadius,
62
- topRight: style.borderTopRightRadius,
63
- bottomLeft: style.borderBottomLeftRadius,
64
- bottomRight: style.borderBottomRightRadius
65
- })
66
- .zIndex(style.zIndex)
67
- .opacity(style.opacity)
68
- .linearGradient(style.linearGradient)
69
- .clip(style.overflow)
70
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
71
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
72
- .transform(style.transform)
73
19
  }
74
20
 
75
-
76
21
  @Extend(Column)
77
22
  function columnAttrs (style: TaroStyleType) {
78
- .id(style.id)
79
- .key(style.id)
80
- .flexGrow(style.flexGrow)
81
- .flexShrink(style.flexShrink)
82
- .flexBasis(style.flexBasis)
83
- .alignSelf(style.alignSelf)
84
- .padding({
85
- top: style.paddingTop,
86
- right: style.paddingRight,
87
- bottom: style.paddingBottom,
88
- left: style.paddingLeft
89
- })
90
- .margin({
91
- top: style.marginTop,
92
- right: style.marginRight,
93
- bottom: style.marginBottom,
94
- left: style.marginLeft
95
- })
96
- .width(style.width)
97
- .height(style.height)
98
23
  .constraintSize({
99
24
  minWidth: style.minWidth,
100
25
  maxWidth: style.maxWidth,
101
- minHeight: style.minHeight,
26
+ minHeight: style.minHeight || style.height,
102
27
  maxHeight: style.maxHeight
103
28
  })
104
- .backgroundColor(style.backgroundColor)
105
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
106
- .backgroundImageSize(style.backgroundSize)
107
- .backgroundImagePosition(style.backgroundPosition)
108
- .borderStyle({
109
- top: style.borderTopStyle,
110
- right: style.borderRightStyle,
111
- bottom: style.borderBottomStyle,
112
- left: style.borderLeftStyle
113
- })
114
- .borderWidth({
115
- top: style.borderTopWidth,
116
- right: style.borderRightWidth,
117
- bottom: style.borderBottomWidth,
118
- left: style.borderLeftWidth
119
- })
120
- .borderColor({
121
- top: style.borderTopColor,
122
- right: style.borderRightColor,
123
- bottom: style.borderBottomColor,
124
- left: style.borderLeftColor
125
- })
126
- .borderRadius({
127
- topLeft: style.borderTopLeftRadius,
128
- topRight: style.borderTopRightRadius,
129
- bottomLeft: style.borderBottomLeftRadius,
130
- bottomRight: style.borderBottomRightRadius
131
- })
132
- .zIndex(style.zIndex)
133
- .opacity(style.opacity)
134
- .linearGradient(style.linearGradient)
135
- .clip(style.overflow)
136
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
137
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
138
- .transform(style.transform)
139
29
  }
140
30
 
141
- function isFlexNode (node: TaroViewElement) {
142
- return !!node.hmStyle?.display?.includes('flex')
143
- }
31
+ @Component
32
+ export default struct TaroView {
33
+ @ObjectLink node: TaroViewElement
144
34
 
145
- @Builder
146
- export default function TaroView (node: TaroViewElement) {
147
- if (isFlexNode(node)) {
148
- Flex(FlexManager.flexOptions(node)) {
149
- createLazyChildren(node)
150
- }
151
- .flexAttrs(getNormalAttributes(node))
152
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
153
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
154
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
155
- node._nodeInfo.areaInfo = res[1]
156
- }))
157
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
158
- } else {
159
- Column() {
160
- createLazyChildren(node)
35
+ build () {
36
+ if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
37
+ Row() {
38
+ createLazyChildren(this.node)
39
+ }
40
+ .attributeModifier(commonStyleModify.setNode(this.node))
41
+ .rowAttrs(getNormalAttributes(this.node))
42
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
43
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
44
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
45
+ this.node._nodeInfo.areaInfo = res[1]
46
+ }))
47
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
48
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
49
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
50
+ } else {
51
+ Column() {
52
+ createLazyChildren(this.node)
53
+ }
54
+ .attributeModifier(commonStyleModify.setNode(this.node))
55
+ .columnAttrs(getNormalAttributes(this.node))
56
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
57
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
58
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
59
+ this.node._nodeInfo.areaInfo = res[1]
60
+ }))
61
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
62
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
63
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
161
64
  }
162
- .columnAttrs(getNormalAttributes(node))
163
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
164
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
165
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
166
- node._nodeInfo.areaInfo = res[1]
167
- }))
168
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
169
- .alignItems(HorizontalAlign.Start)
170
- .justifyContent(node.hmStyle.justifyContent)
171
65
  }
172
66
  }
@@ -0,0 +1,55 @@
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
+ @Component
18
+ export default struct TaroWebView {
19
+ @ObjectLink node: TaroWebViewElement
20
+
21
+ build () {
22
+ Web({ src: this.node._attrs.src, controller: this.node.controller })
23
+ .attributeModifier(commonStyleModify.setNode(this.node))
24
+ .onPageEnd((e: IPageLoad) => {
25
+ // 1. 创建消息端口
26
+ this.node.ports = this.node.controller.createWebMessagePorts(true)
27
+ // 2. 发送端口1到HTML5
28
+ this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
29
+ // 3. 保存端口0到本地
30
+ this.node.nativePort = this.node.ports[0]
31
+ // 4. 设置回调函数
32
+ this.node.nativePort.onMessageEventExt((result) => {
33
+ const message = this.node.handleMessageFromWeb(result)
34
+ const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
35
+
36
+ eventHandler(messageEvent, 'message', this.node)
37
+ })
38
+
39
+ const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
40
+
41
+ eventHandler(onLoadEvent, 'load', this.node)
42
+ })
43
+ .onErrorReceive(shouldBindEvent((e: IError) => {
44
+ const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
45
+
46
+ eventHandler(event, 'error', this.node)
47
+ }, this.node, ['error']))
48
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
49
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
50
+ this.node._nodeInfo.areaInfo = res[1]
51
+ }))
52
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
53
+
54
+ }
55
+ }
package/dist/index.js CHANGED
@@ -75,6 +75,86 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
75
75
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
76
  };
77
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
+ `;
156
+ }
157
+
78
158
  const PLATFORM_NAME = 'harmony';
79
159
  const PACKAGE_NAME = '@tarojs/plugin-platform-harmony-ets';
80
160
  const PLUGIN_NAME = 'TaroHarmony';
@@ -164,7 +244,8 @@ class TaroPlatformHarmony extends service.TaroPlatform {
164
244
  FRAMEWORK: JSON.stringify(this.config.framework),
165
245
  TARO_ENV: JSON.stringify(this.platform),
166
246
  TARO_PLATFORM: JSON.stringify(this.platformType),
167
- TARO_VERSION: JSON.stringify(_package.getPkgVersion())
247
+ TARO_VERSION: JSON.stringify(_package.getPkgVersion()),
248
+ SUPPORT_TARO_POLYFILL: 'disabled',
168
249
  },
169
250
  });
170
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);
@@ -291,8 +372,8 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
291
372
  return;
292
373
  if (this.excludeLibraries.some(e => typeof e === 'string' ? e === lib : e.test(lib)))
293
374
  return;
375
+ const { outputRoot, chorePackagePrefix } = this.ctx.runOpts.config;
294
376
  if (sync) {
295
- const { outputRoot } = this.ctx.runOpts.config;
296
377
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
297
378
  // FIXME 不支持 alias 配置
298
379
  const libName = lib;
@@ -393,7 +474,12 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
393
474
  }
394
475
  else if (stat.isFile()) {
395
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
+ }
396
481
  if (this.extensions.includes(path__namespace.extname(lib))) {
482
+ // Note: 查询 externals 内的依赖,并将它们添加到 externalDeps 中
397
483
  code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
398
484
  const { outputRoot } = this.ctx.runOpts.config;
399
485
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
@@ -417,8 +503,10 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
417
503
  code = '// @ts-nocheck\n' + code;
418
504
  }
419
505
  }
420
- if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
421
- code = `/// <reference path="global.d.ts" />
506
+ // Note: 传入 chorePackagePrefix 时,不生成核心依赖库
507
+ if (!chorePackagePrefix) {
508
+ if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
509
+ code = `/// <reference path="global.d.ts" />
422
510
 
423
511
  /// <reference path="taro.api.d.ts" />
424
512
  /// <reference path="taro.component.d.ts" />
@@ -438,14 +526,15 @@ declare global {
438
526
  const defineAppConfig: (config: Taro.Config) => Taro.Config
439
527
  const definePageConfig: (config: Taro.Config) => Taro.Config
440
528
  }`;
441
- }
442
- try {
443
- const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
444
- helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
445
- helper.fs.writeFileSync(targetPath, code);
446
- }
447
- catch (e) {
448
- console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
529
+ }
530
+ try {
531
+ const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
532
+ helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
533
+ helper.fs.writeFileSync(targetPath, code);
534
+ }
535
+ catch (e) {
536
+ console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
537
+ }
449
538
  }
450
539
  }
451
540
  else if (stat.isSymbolicLink()) {
@@ -467,7 +556,7 @@ declare global {
467
556
  const that = this;
468
557
  const { appPath } = that.ctx.paths;
469
558
  const { config } = that.ctx.runOpts;
470
- const { outputRoot } = config;
559
+ const { outputRoot, ohPackage = {}, chorePackagePrefix } = config;
471
560
  if (!that.framework.includes('vue')) {
472
561
  that.excludeLibraries.push(/\bvue\b/);
473
562
  }
@@ -483,7 +572,22 @@ declare global {
483
572
  /^solid-js\/universal$/,
484
573
  ]);
485
574
  }
575
+ const externals = Object.keys(ohPackage.dependencies || []).concat(Object.keys(ohPackage.devDependencies || []));
486
576
  function modifyResolveId({ source = '', importer = '', options = {}, name = 'modifyResolveId', resolve }) {
577
+ if (externals.includes(source)) {
578
+ return {
579
+ external: true,
580
+ id: source,
581
+ resolvedBy: name,
582
+ };
583
+ }
584
+ if (chorePackagePrefix && that.indexOfLibraries(source) > -1) {
585
+ return {
586
+ external: true,
587
+ id: path__namespace.join(chorePackagePrefix, source),
588
+ resolvedBy: name,
589
+ };
590
+ }
487
591
  if (shared.isFunction(resolve)) {
488
592
  if (source === that.runtimePath || that.runtimePath.includes(source)) {
489
593
  return resolve('@tarojs/runtime', importer, options);
@@ -565,7 +669,7 @@ function App(props) {
565
669
  isFile: (file) => {
566
670
  try {
567
671
  const stat = helper.fs.lstatSync(file);
568
- return stat.isFile() || (file.endsWith(mediaPath) && stat.isDirectory());
672
+ return stat.isFile() || (file.endsWith(mediaPath.replace('/', path__namespace.sep)) && stat.isDirectory());
569
673
  }
570
674
  catch (_) { } // eslint-disable-line no-empty
571
675
  return false;
@@ -1066,7 +1170,7 @@ class Harmony extends service.TaroPlatformBase {
1066
1170
  const outDir = path.join(compsOutDir, name);
1067
1171
  helper.fs.copy(src, outDir);
1068
1172
  });
1069
- this.modifyHostPackageDep(outDir);
1173
+ this.modifyHostPackage(config.harmony);
1070
1174
  });
1071
1175
  }
1072
1176
  modifyWebpackConfig() {
@@ -1129,13 +1233,13 @@ class Harmony extends service.TaroPlatformBase {
1129
1233
  console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
1130
1234
  });
1131
1235
  }
1132
- modifyHostPackageDep(dest) {
1236
+ modifyHostPackage({ projectPath, hapName = 'entry' }) {
1133
1237
  return __awaiter(this, void 0, void 0, function* () {
1238
+ const packageJsonFile = path.join(projectPath, hapName, 'package.json');
1134
1239
  const hmsDeps = {
1135
1240
  '@hmscore/hms-js-base': '^6.1.0-300',
1136
1241
  '@hmscore/hms-jsb-account': '^1.0.300'
1137
1242
  };
1138
- const packageJsonFile = path.resolve(dest, '../../../../../package.json');
1139
1243
  const isExists = yield helper.fs.pathExists(packageJsonFile);
1140
1244
  if (!isExists)
1141
1245
  return;
@@ -1152,6 +1256,7 @@ class Harmony extends service.TaroPlatformBase {
1152
1256
  }
1153
1257
  packageJson = JSON.stringify(packageJson);
1154
1258
  yield helper.fs.writeFile(packageJsonFile, packageJson);
1259
+ return packageJson;
1155
1260
  });
1156
1261
  }
1157
1262
  getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {