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

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 (33) hide show
  1. package/dist/apis/device/memory.ts +10 -3
  2. package/dist/components-harmony-ets/button.ets +19 -24
  3. package/dist/components-harmony-ets/checkbox.ets +85 -7
  4. package/dist/components-harmony-ets/form.ets +93 -11
  5. package/dist/components-harmony-ets/label.ets +105 -17
  6. package/dist/components-harmony-ets/picker.ets +16 -4
  7. package/dist/components-harmony-ets/radio.ets +85 -7
  8. package/dist/components-harmony-ets/scrollView.ets +1 -1
  9. package/dist/components-harmony-ets/text.ets +3 -3
  10. package/dist/components-harmony-ets/utils/flexManager.ets +43 -6
  11. package/dist/components-harmony-ets/utils/helper.ets +1 -1
  12. package/dist/components-harmony-ets/utils/styles.ets +11 -1
  13. package/dist/components-harmony-ets/view.ets +11 -14
  14. package/dist/components-harmony-ets/webView.ets +113 -0
  15. package/dist/index.js +85 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +23 -3
  18. package/dist/runtime-ets/dom/element/index.ts +4 -1
  19. package/dist/runtime-ets/dom/element/normal.ts +1 -0
  20. package/dist/runtime-ets/dom/element/webView.ts +61 -0
  21. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +73 -0
  22. package/dist/runtime-ets/dom/stylesheet/util.ts +3 -1
  23. package/dist/runtime-ets/utils/index.ts +4 -1
  24. package/dist/runtime-framework/react/app.ts +12 -22
  25. package/dist/runtime-framework/react/index.ts +1 -0
  26. package/dist/runtime-framework/react/native-page.ts +344 -0
  27. package/dist/runtime-framework/react/page.ts +2 -2
  28. package/dist/runtime-utils.js +9 -3
  29. package/dist/runtime-utils.js.map +1 -1
  30. package/dist/runtime.js +9 -3
  31. package/dist/runtime.js.map +1 -1
  32. package/package.json +8 -8
  33. package/types/runtime.d.ts +2 -0
@@ -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.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,
@@ -7,8 +7,8 @@ import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils
7
7
 
8
8
  import type { TaroViewElement, TaroAny, TaroStyleType } from '@tarojs/runtime'
9
9
 
10
- @Extend(Flex)
11
- function flexAttrs (style: TaroStyleType) {
10
+ @Extend(Column)
11
+ function columnAttrs (style: TaroStyleType) {
12
12
  .id(style.id)
13
13
  .key(style.id)
14
14
  .flexGrow(style.flexGrow)
@@ -72,9 +72,8 @@ function flexAttrs (style: TaroStyleType) {
72
72
  .transform(style.transform)
73
73
  }
74
74
 
75
-
76
- @Extend(Column)
77
- function columnAttrs (style: TaroStyleType) {
75
+ @Extend(Row)
76
+ function rowAttrs (style: TaroStyleType) {
78
77
  .id(style.id)
79
78
  .key(style.id)
80
79
  .flexGrow(style.flexGrow)
@@ -138,23 +137,21 @@ function columnAttrs (style: TaroStyleType) {
138
137
  .transform(style.transform)
139
138
  }
140
139
 
141
- function isFlexNode (node: TaroViewElement) {
142
- return !!node.hmStyle?.display?.includes('flex')
143
- }
144
-
145
140
  @Builder
146
141
  export default function TaroView (node: TaroViewElement) {
147
- if (isFlexNode(node)) {
148
- Flex(FlexManager.flexOptions(node)) {
142
+ if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
143
+ Row() {
149
144
  createLazyChildren(node)
150
145
  }
151
- .flexAttrs(getNormalAttributes(node))
146
+ .rowAttrs(getNormalAttributes(node))
152
147
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
153
148
  .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
154
149
  .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
155
150
  node._nodeInfo.areaInfo = res[1]
156
151
  }))
157
152
  .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
153
+ .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
154
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
158
155
  } else {
159
156
  Column() {
160
157
  createLazyChildren(node)
@@ -166,7 +163,7 @@ export default function TaroView (node: TaroViewElement) {
166
163
  node._nodeInfo.areaInfo = res[1]
167
164
  }))
168
165
  .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
169
- .alignItems(HorizontalAlign.Start)
170
- .justifyContent(node.hmStyle.justifyContent)
166
+ .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
167
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
171
168
  }
172
169
  }
@@ -0,0 +1,113 @@
1
+ import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
+
3
+ import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
4
+
5
+ import type { TaroAny, TaroWebViewElement, TaroStyleType, TaroEvent } from '@tarojs/runtime'
6
+
7
+ interface IPageLoad {
8
+ url: string
9
+ }
10
+
11
+ interface IError {
12
+ request: WebResourceRequest
13
+ error: WebResourceError
14
+ }
15
+
16
+ @Extend(Web)
17
+ function attrs (style: TaroStyleType) {
18
+ .id(style.id)
19
+ .key(style.id)
20
+ .flexGrow(style.flexGrow)
21
+ .flexShrink(style.flexShrink)
22
+ .flexBasis(style.flexBasis)
23
+ .alignSelf(style.alignSelf)
24
+ .padding({
25
+ top: style.paddingTop,
26
+ right: style.paddingRight,
27
+ bottom: style.paddingBottom,
28
+ left: style.paddingLeft
29
+ })
30
+ .margin({
31
+ top: style.marginTop,
32
+ right: style.marginRight,
33
+ bottom: style.marginBottom,
34
+ left: style.marginLeft
35
+ })
36
+ .width(style.width)
37
+ .height(style.height)
38
+ .constraintSize({
39
+ minWidth: style.minWidth,
40
+ maxWidth: style.maxWidth,
41
+ minHeight: style.minHeight,
42
+ maxHeight: style.maxHeight
43
+ })
44
+ .backgroundColor(style.backgroundColor)
45
+ .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
46
+ .backgroundImageSize(style.backgroundSize)
47
+ .backgroundImagePosition(style.backgroundPosition)
48
+ .borderStyle({
49
+ top: style.borderTopStyle,
50
+ right: style.borderRightStyle,
51
+ bottom: style.borderBottomStyle,
52
+ left: style.borderLeftStyle
53
+ })
54
+ .borderWidth({
55
+ top: style.borderTopWidth,
56
+ right: style.borderRightWidth,
57
+ bottom: style.borderBottomWidth,
58
+ left: style.borderLeftWidth
59
+ })
60
+ .borderColor({
61
+ top: style.borderTopColor,
62
+ right: style.borderRightColor,
63
+ bottom: style.borderBottomColor,
64
+ left: style.borderLeftColor
65
+ })
66
+ .borderRadius({
67
+ topLeft: style.borderTopLeftRadius,
68
+ topRight: style.borderTopRightRadius,
69
+ bottomLeft: style.borderBottomLeftRadius,
70
+ bottomRight: style.borderBottomRightRadius
71
+ })
72
+ .zIndex(style.zIndex)
73
+ .opacity(style.opacity)
74
+ .clip(style.overflow)
75
+ .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
76
+ .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
77
+ .transform(style.transform)
78
+ }
79
+
80
+ @Builder
81
+ export default function TaroWebView (node: TaroWebViewElement) {
82
+ Web({ src: node._attrs.src, controller: node.controller })
83
+ .attrs(getNormalAttributes(node))
84
+ .onPageEnd((e: IPageLoad) => {
85
+ // 1. 创建消息端口
86
+ node.ports = node.controller.createWebMessagePorts(true)
87
+ // 2. 发送端口1到HTML5
88
+ node.controller.postMessage('init_web_messageport', [node.ports[1]], '*');
89
+ // 3. 保存端口0到本地
90
+ node.nativePort = node.ports[0]
91
+ // 4. 设置回调函数
92
+ node.nativePort.onMessageEventExt((result) => {
93
+ const message = node.handleMessageFromWeb(result)
94
+ const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, node)
95
+
96
+ eventHandler(messageEvent, 'message', node)
97
+ })
98
+
99
+ const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: node._attrs.src } }, node)
100
+
101
+ eventHandler(onLoadEvent, 'load', node)
102
+ })
103
+ .onErrorReceive(shouldBindEvent((e: IError) => {
104
+ const event: TaroEvent = createTaroEvent('error', { detail: { url: node._attrs.src, fullUrl: e.request.getRequestUrl() } }, node)
105
+
106
+ eventHandler(event, 'error', node)
107
+ }, node, ['error']))
108
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
109
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
110
+ node._nodeInfo.areaInfo = res[1]
111
+ }))
112
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
113
+ }
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';
@@ -393,6 +473,10 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
393
473
  }
394
474
  else if (stat.isFile()) {
395
475
  let code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
476
+ // TODO: 后续这部分代码应该根据使用的框架抽离到对应的平台插件处
477
+ if ([/taro-platform-harmony[\\/]dist[\\/]apis[\\/]index\.ts/].some(e => e.test(lib))) {
478
+ code = apiLoader(code);
479
+ }
396
480
  if (this.extensions.includes(path__namespace.extname(lib))) {
397
481
  code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
398
482
  const { outputRoot } = this.ctx.runOpts.config;
@@ -565,7 +649,7 @@ function App(props) {
565
649
  isFile: (file) => {
566
650
  try {
567
651
  const stat = helper.fs.lstatSync(file);
568
- return stat.isFile() || (file.endsWith(mediaPath) && stat.isDirectory());
652
+ return stat.isFile() || (file.endsWith(mediaPath.replace('/', path__namespace.sep)) && stat.isDirectory());
569
653
  }
570
654
  catch (_) { } // eslint-disable-line no-empty
571
655
  return false;