@tarojs/plugin-platform-harmony-ets 4.0.0-beta.10 → 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 (38) hide show
  1. package/dist/components-harmony-ets/button.ets +34 -31
  2. package/dist/components-harmony-ets/checkbox.ets +3 -2
  3. package/dist/components-harmony-ets/form.ets +30 -27
  4. package/dist/components-harmony-ets/icon.ets +22 -18
  5. package/dist/components-harmony-ets/image.ets +15 -11
  6. package/dist/components-harmony-ets/innerHtml.ets +9 -5
  7. package/dist/components-harmony-ets/input.ets +1 -1
  8. package/dist/components-harmony-ets/label.ets +43 -39
  9. package/dist/components-harmony-ets/movableArea.ets +67 -0
  10. package/dist/components-harmony-ets/movableView.ets +66 -0
  11. package/dist/components-harmony-ets/picker.ets +2 -1
  12. package/dist/components-harmony-ets/progress.ets +45 -0
  13. package/dist/components-harmony-ets/radio.ets +2 -2
  14. package/dist/components-harmony-ets/richText.ets +14 -9
  15. package/dist/components-harmony-ets/scrollView.ets +36 -32
  16. package/dist/components-harmony-ets/slider.ets +1 -1
  17. package/dist/components-harmony-ets/swiper.ets +23 -19
  18. package/dist/components-harmony-ets/switch.ets +1 -1
  19. package/dist/components-harmony-ets/text.ets +28 -22
  20. package/dist/components-harmony-ets/textArea.ets +1 -1
  21. package/dist/components-harmony-ets/video.ets +26 -21
  22. package/dist/components-harmony-ets/view.ets +33 -29
  23. package/dist/components-harmony-ets/webView.ets +37 -32
  24. package/dist/index.js +35 -15
  25. package/dist/index.js.map +1 -1
  26. package/dist/runtime-ets/dom/element/element.ts +0 -1
  27. package/dist/runtime-ets/dom/element/form.ts +11 -4
  28. package/dist/runtime-ets/dom/element/index.ts +9 -1
  29. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  30. package/dist/runtime-ets/dom/element/movableView.ts +12 -0
  31. package/dist/runtime-ets/dom/element/normal.ts +8 -2
  32. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  33. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  34. package/dist/runtime-ets/dom/element/text.ts +1 -0
  35. package/dist/runtime-ets/dom/element/video.ts +1 -0
  36. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  37. package/dist/runtime-ets/dom/node.ts +18 -17
  38. package/package.json +8 -8
@@ -77,51 +77,55 @@ function columnAttrs (style: TaroStyleType) {
77
77
  })
78
78
  }
79
79
 
80
- @Builder
81
- export default function TaroScrollView (node: TaroScrollViewElement) {
82
- Scroll(node.scroller) {
83
- if (node._attrs.scrollX) {
80
+ @Component
81
+ export default struct TaroScrollView {
82
+ @ObjectLink node: TaroScrollViewElement
83
+
84
+ build () {
85
+ Scroll(this.node.scroller) {
86
+ if (this.node._attrs.scrollX) {
84
87
  Row() {
85
- createLazyChildren(node)
88
+ createLazyChildren(this.node)
86
89
  }
87
- .attributeModifier(commonStyleModify.setNode(node))
88
- .rowAttrs(getNormalAttributes(node))
90
+ .attributeModifier(commonStyleModify.setNode(this.node))
91
+ .rowAttrs(getNormalAttributes(this.node))
89
92
  .width(null)
90
93
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
91
- node._scroll = areaResult
92
- }, node, ['scroll', 'scrollstart', 'scrollend']))
93
- .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
94
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
94
+ this.node._scroll = areaResult
95
+ }, this.node, ['scroll', 'scrollstart', 'scrollend']))
96
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
97
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
95
98
  .flexGrow(0).flexShrink(0)
96
99
  } else {
97
100
  Column() {
98
- createLazyChildren(node)
101
+ createLazyChildren(this.node)
99
102
  }
100
- .attributeModifier(commonStyleModify.setNode(node))
101
- .columnAttrs(getNormalAttributes(node))
103
+ .attributeModifier(commonStyleModify.setNode(this.node))
104
+ .columnAttrs(getNormalAttributes(this.node))
102
105
  .height(null)
103
106
  .alignItems(HorizontalAlign.Start)
104
107
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
105
- node._scroll = areaResult
106
- }, node, ['scroll', 'scrollstart', 'scrollend']))
107
- .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
108
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
108
+ this.node._scroll = areaResult
109
+ }, this.node, ['scroll', 'scrollstart', 'scrollend']))
110
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
111
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
109
112
  .flexGrow(0).flexShrink(0)
110
113
  }
111
114
  }
112
- .width(getNormalAttributes(node).width)
113
- .height(getNormalAttributes(node).height)
114
- .flexGrow(getNormalAttributes(node).flexGrow)
115
- .flexShrink(getNormalAttributes(node).flexShrink)
116
- .scrollable(getScrollable(node))
117
- .scrollBar(getAttributes(node).scrollBar)
118
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
119
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
120
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
121
- node._nodeInfo.areaInfo = res[1]
115
+ .width(getNormalAttributes(this.node).width)
116
+ .height(getNormalAttributes(this.node).height)
117
+ .flexGrow(getNormalAttributes(this.node).flexGrow)
118
+ .flexShrink(getNormalAttributes(this.node).flexShrink)
119
+ .scrollable(getScrollable(this.node))
120
+ .scrollBar(getAttributes(this.node).scrollBar)
121
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
122
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
123
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
124
+ this.node._nodeInfo.areaInfo = res[1]
122
125
  }))
123
- .onScroll(shouldBindEvent(() => { handleScrollEvent(node, 'scroll') }, node, ['scroll']))
124
- .onScrollStart(shouldBindEvent(() => { handleScrollEvent(node, 'scrollstart') }, node, ['scrollstart']))
125
- .onScrollStop(shouldBindEvent(() => { handleScrollEvent(node, 'scrollend') }, node, ['scrollend']))
126
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
126
+ .onScroll(shouldBindEvent(() => { handleScrollEvent(this.node, 'scroll') }, this.node, ['scroll']))
127
+ .onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
128
+ .onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
129
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
130
+ }
127
131
  }
@@ -37,7 +37,7 @@ function themeStyles(isDisabled: boolean) {
37
37
 
38
38
  @Component
39
39
  export default struct TaroSlider {
40
- node: TaroSliderElement | null = null
40
+ @ObjectLink node: TaroSliderElement
41
41
 
42
42
  @State value: number = 0
43
43
 
@@ -40,24 +40,28 @@ function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
40
40
  return swiperAttrs
41
41
  }
42
42
 
43
- @Builder
44
- export default function TaroSwiper (node: TaroSwiperElement) {
45
- Swiper(node.controller) {
46
- createLazyChildren(node)
43
+ @Component
44
+ export default struct TaroSwiper {
45
+ @ObjectLink node: TaroSwiperElement
46
+
47
+ build () {
48
+ Swiper(this.node.controller) {
49
+ createLazyChildren(this.node)
50
+ }
51
+ .attributeModifier(commonStyleModify.setNode(this.node))
52
+ .swiperAttr(getSwiperAttributes(this.node))
53
+ .indicatorStyle({
54
+ color: this.node.getAttribute('indicatorColor'),
55
+ selectedColor: this.node.getAttribute('indicatorActiveColor')
56
+ })
57
+ .onChange((index: number) => {
58
+ const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
59
+ eventHandler(event, 'change', this.node)
60
+ })
61
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
62
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
63
+ this.node._nodeInfo.areaInfo = res[1]
64
+ }))
65
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
47
66
  }
48
- .attributeModifier(commonStyleModify.setNode(node))
49
- .swiperAttr(getSwiperAttributes(node))
50
- .indicatorStyle({
51
- color: node.getAttribute('indicatorColor'),
52
- selectedColor: node.getAttribute('indicatorActiveColor')
53
- })
54
- .onChange((index: number) => {
55
- const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, node)
56
- eventHandler(event, 'change', node)
57
- })
58
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
59
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
60
- node._nodeInfo.areaInfo = res[1]
61
- }))
62
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
63
67
  }
@@ -28,7 +28,7 @@ function themeStyles(isDisabled: boolean) {
28
28
 
29
29
  @Component
30
30
  export default struct TaroSwitch {
31
- node: TaroSwitchElement | null = null
31
+ @ObjectLink node: TaroSwitchElement
32
32
 
33
33
  aboutToAppear () {
34
34
  if (this.node && !this.node._isInit) {
@@ -38,29 +38,35 @@ function getButtonFontSize (node: TaroButtonElement) {
38
38
  return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
39
39
  }
40
40
 
41
- @Builder
42
- export default function TaroText (node: TaroTextElement) {
43
- if (node.nodeType === NodeType.TEXT_NODE && node.parentNode) {
44
- if ((node.parentNode as TaroElement).tagName === 'BUTTON') {
45
- Text(node.textContent)
46
- .textNormalFontStyle(getNormalAttributes(node.parentNode as TaroElement))
47
- .textSpecialFontStyle(getFontAttributes(node.parentNode as TaroElement))
48
- .fontSize((node.parentNode as TaroButtonElement).hmStyle.fontSize || getButtonFontSize((node.parentNode as TaroButtonElement)))
49
- .fontColor((node.parentNode as TaroButtonElement).hmStyle.color || getButtonColor(node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((node.parentNode as TaroButtonElement)._attrs.type).text))
41
+ @Component
42
+ export default struct TaroText {
43
+ @ObjectLink node: TaroTextElement
44
+
45
+ build () {
46
+ if (this.node.nodeType === NodeType.TEXT_NODE && this.node.parentNode) {
47
+ if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
48
+ Text(this.node.textContent)
49
+ .textNormalFontStyle(getNormalAttributes(this.node.parentNode as TaroElement))
50
+ .textSpecialFontStyle(getFontAttributes(this.node.parentNode as TaroElement))
51
+ .fontSize((this.node.parentNode as TaroButtonElement).hmStyle.fontSize || getButtonFontSize(this.node.parentNode as TaroButtonElement))
52
+ .fontColor((this.node.parentNode as TaroButtonElement).hmStyle.color || getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type).text))
53
+ } else {
54
+ Text(this.node.textContent)
55
+ .textNormalFontStyle(getNormalAttributes(this.node.parentNode as TaroElement))
56
+ .textSpecialFontStyle(getFontAttributes(this.node.parentNode as TaroElement))
57
+ .width(getNormalAttributes(this.node.parentNode as TaroElement).width)
58
+ .height(getNormalAttributes(this.node.parentNode as TaroElement).height)
59
+ }
50
60
  } else {
51
- Text(node.textContent)
52
- .textNormalFontStyle(getNormalAttributes(node.parentNode as TaroElement))
53
- .textSpecialFontStyle(getFontAttributes(node.parentNode as TaroElement))
61
+ Text(this.node.textContent)
62
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
63
+ .attributeModifier(commonStyleModify.setNode(this.node))
64
+ .textNormalFontStyle(getNormalAttributes(this.node))
65
+ .textSpecialFontStyle(getFontAttributes(this.node))
66
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
67
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
68
+ this.node._nodeInfo.areaInfo = res[1]
69
+ }))
54
70
  }
55
- } else {
56
- Text(node.textContent)
57
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
58
- .attributeModifier(commonStyleModify.setNode(node))
59
- .textNormalFontStyle(getNormalAttributes(node))
60
- .textSpecialFontStyle(getFontAttributes(node))
61
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
62
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
63
- node._nodeInfo.areaInfo = res[1]
64
- }))
65
71
  }
66
72
  }
@@ -30,7 +30,7 @@ function getPlaceholderColor (node: TaroTextAreaElement): string {
30
30
  export default struct TaroTextArea {
31
31
  @State value: string = ''
32
32
 
33
- node: TaroTextAreaElement | null = null
33
+ @ObjectLink node: TaroTextAreaElement
34
34
 
35
35
  aboutToAppear () {
36
36
  if (this.node) {
@@ -78,25 +78,30 @@ function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
78
78
  emitEvent(node, 'timeUpdate', { currentTime: e.time})
79
79
  }
80
80
 
81
- @Builder
82
- export default function TaroVideo (node: TaroVideoElement) {
83
- Video(getVideoData(node))
84
- .attributeModifier(commonStyleModify.setNode(node))
85
- .props(getVideoProps(node))
86
- .aspectRatio(4 / 3)
87
- .onStart(shouldBindEvent(() => { emitEvent(node, 'play') }, node, ['play']))
88
- .onPause(shouldBindEvent(() => { emitEvent(node, 'pause') }, node, ['pause']))
89
- .onFinish(shouldBindEvent(() => { emitEvent(node, 'ended') }, node, ['ended']))
90
- .onError(shouldBindEvent(() => { emitEvent(node, 'error') }, node, ['error']))
91
- .onUpdate((e) => { handleUpdate(node, e) })
92
- .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'loadedMetaData', { duration: e.duration }) }, node, ['loadedmetadata']))
93
- .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'seeking', { duration: e.time }) }, node, ['seeking']))
94
- .onSeeked(shouldBindEvent(() => { emitEvent(node, 'seeked') }, node, ['seeked']))
95
- .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, node, ['fullscreenchange']))
96
- .onClick((e: ClickEvent) => { eventHandler(e, 'click', node) })
97
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
98
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
99
- node._nodeInfo.areaInfo = res[1]
100
- }))
101
- .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
+
102
107
  }
@@ -28,35 +28,39 @@ function columnAttrs (style: TaroStyleType) {
28
28
  })
29
29
  }
30
30
 
31
- @Builder
32
- export default function TaroView (node: TaroViewElement) {
33
- if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
34
- Row() {
35
- createLazyChildren(node)
36
- }
37
- .attributeModifier(commonStyleModify.setNode(node))
38
- .rowAttrs(getNormalAttributes(node))
39
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
40
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
41
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
42
- node._nodeInfo.areaInfo = res[1]
43
- }))
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)
47
- } else {
48
- Column() {
49
- createLazyChildren(node)
31
+ @Component
32
+ export default struct TaroView {
33
+ @ObjectLink node: TaroViewElement
34
+
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)
50
64
  }
51
- .attributeModifier(commonStyleModify.setNode(node))
52
- .columnAttrs(getNormalAttributes(node))
53
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
54
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
55
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
56
- node._nodeInfo.areaInfo = res[1]
57
- }))
58
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
59
- .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
60
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
61
65
  }
62
66
  }
@@ -14,37 +14,42 @@ interface IError {
14
14
  error: WebResourceError
15
15
  }
16
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)
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)
34
42
  })
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))
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
+ }
50
55
  }
package/dist/index.js CHANGED
@@ -372,8 +372,8 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
372
372
  return;
373
373
  if (this.excludeLibraries.some(e => typeof e === 'string' ? e === lib : e.test(lib)))
374
374
  return;
375
+ const { outputRoot, chorePackagePrefix } = this.ctx.runOpts.config;
375
376
  if (sync) {
376
- const { outputRoot } = this.ctx.runOpts.config;
377
377
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
378
378
  // FIXME 不支持 alias 配置
379
379
  const libName = lib;
@@ -479,6 +479,7 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
479
479
  code = apiLoader(code);
480
480
  }
481
481
  if (this.extensions.includes(path__namespace.extname(lib))) {
482
+ // Note: 查询 externals 内的依赖,并将它们添加到 externalDeps 中
482
483
  code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
483
484
  const { outputRoot } = this.ctx.runOpts.config;
484
485
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
@@ -502,8 +503,10 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
502
503
  code = '// @ts-nocheck\n' + code;
503
504
  }
504
505
  }
505
- if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
506
- 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" />
507
510
 
508
511
  /// <reference path="taro.api.d.ts" />
509
512
  /// <reference path="taro.component.d.ts" />
@@ -523,14 +526,15 @@ declare global {
523
526
  const defineAppConfig: (config: Taro.Config) => Taro.Config
524
527
  const definePageConfig: (config: Taro.Config) => Taro.Config
525
528
  }`;
526
- }
527
- try {
528
- const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
529
- helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
530
- helper.fs.writeFileSync(targetPath, code);
531
- }
532
- catch (e) {
533
- 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
+ }
534
538
  }
535
539
  }
536
540
  else if (stat.isSymbolicLink()) {
@@ -552,7 +556,7 @@ declare global {
552
556
  const that = this;
553
557
  const { appPath } = that.ctx.paths;
554
558
  const { config } = that.ctx.runOpts;
555
- const { outputRoot } = config;
559
+ const { outputRoot, ohPackage = {}, chorePackagePrefix } = config;
556
560
  if (!that.framework.includes('vue')) {
557
561
  that.excludeLibraries.push(/\bvue\b/);
558
562
  }
@@ -568,7 +572,22 @@ declare global {
568
572
  /^solid-js\/universal$/,
569
573
  ]);
570
574
  }
575
+ const externals = Object.keys(ohPackage.dependencies || []).concat(Object.keys(ohPackage.devDependencies || []));
571
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
+ }
572
591
  if (shared.isFunction(resolve)) {
573
592
  if (source === that.runtimePath || that.runtimePath.includes(source)) {
574
593
  return resolve('@tarojs/runtime', importer, options);
@@ -1151,7 +1170,7 @@ class Harmony extends service.TaroPlatformBase {
1151
1170
  const outDir = path.join(compsOutDir, name);
1152
1171
  helper.fs.copy(src, outDir);
1153
1172
  });
1154
- this.modifyHostPackageDep(outDir);
1173
+ this.modifyHostPackage(config.harmony);
1155
1174
  });
1156
1175
  }
1157
1176
  modifyWebpackConfig() {
@@ -1214,13 +1233,13 @@ class Harmony extends service.TaroPlatformBase {
1214
1233
  console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
1215
1234
  });
1216
1235
  }
1217
- modifyHostPackageDep(dest) {
1236
+ modifyHostPackage({ projectPath, hapName = 'entry' }) {
1218
1237
  return __awaiter(this, void 0, void 0, function* () {
1238
+ const packageJsonFile = path.join(projectPath, hapName, 'package.json');
1219
1239
  const hmsDeps = {
1220
1240
  '@hmscore/hms-js-base': '^6.1.0-300',
1221
1241
  '@hmscore/hms-jsb-account': '^1.0.300'
1222
1242
  };
1223
- const packageJsonFile = path.resolve(dest, '../../../../../package.json');
1224
1243
  const isExists = yield helper.fs.pathExists(packageJsonFile);
1225
1244
  if (!isExists)
1226
1245
  return;
@@ -1237,6 +1256,7 @@ class Harmony extends service.TaroPlatformBase {
1237
1256
  }
1238
1257
  packageJson = JSON.stringify(packageJson);
1239
1258
  yield helper.fs.writeFile(packageJsonFile, packageJson);
1259
+ return packageJson;
1240
1260
  });
1241
1261
  }
1242
1262
  getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {