@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.0 → 4.0.0-alpha.3

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 (77) hide show
  1. package/dist/apis/device/memory.ts +10 -3
  2. package/dist/apis/index.ts +2 -0
  3. package/dist/apis/media/video/VideoContext.ts +56 -7
  4. package/dist/apis/media/video/index.ts +3 -2
  5. package/dist/apis/network/request.ts +5 -5
  6. package/dist/apis/route/index.ts +15 -0
  7. package/dist/apis/wxml/index.ts +2 -0
  8. package/dist/components-harmony-ets/button.ets +26 -40
  9. package/dist/components-harmony-ets/checkbox.ets +70 -99
  10. package/dist/components-harmony-ets/form.ets +29 -42
  11. package/dist/components-harmony-ets/icon.ets +6 -34
  12. package/dist/components-harmony-ets/image.ets +2 -32
  13. package/dist/components-harmony-ets/innerHtml.ets +2 -2
  14. package/dist/components-harmony-ets/input.ets +7 -27
  15. package/dist/components-harmony-ets/label.ets +40 -47
  16. package/dist/components-harmony-ets/picker.ets +66 -73
  17. package/dist/components-harmony-ets/radio.ets +72 -101
  18. package/dist/components-harmony-ets/richText.ets +4 -36
  19. package/dist/components-harmony-ets/scrollView.ets +34 -74
  20. package/dist/components-harmony-ets/slider.ets +9 -34
  21. package/dist/components-harmony-ets/style.ets +154 -0
  22. package/dist/components-harmony-ets/swiper.ets +4 -34
  23. package/dist/components-harmony-ets/switch.ets +43 -56
  24. package/dist/components-harmony-ets/text.ets +7 -34
  25. package/dist/components-harmony-ets/textArea.ets +8 -28
  26. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -11
  27. package/dist/components-harmony-ets/utils/flexManager.ets +45 -7
  28. package/dist/components-harmony-ets/utils/helper.ets +2 -2
  29. package/dist/components-harmony-ets/utils/styles.ets +58 -20
  30. package/dist/components-harmony-ets/video.ets +4 -34
  31. package/dist/components-harmony-ets/view.ets +25 -67
  32. package/dist/components-harmony-ets/webView.ets +50 -0
  33. package/dist/index.js +103 -5
  34. package/dist/index.js.map +1 -1
  35. package/dist/runtime-ets/bom/window.ts +2 -2
  36. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +30 -6
  37. package/dist/runtime-ets/dom/document.ts +21 -4
  38. package/dist/runtime-ets/dom/element/element.ts +1 -0
  39. package/dist/runtime-ets/dom/element/form.ts +11 -2
  40. package/dist/runtime-ets/dom/element/index.ts +4 -1
  41. package/dist/runtime-ets/dom/element/normal.ts +1 -0
  42. package/dist/runtime-ets/dom/element/webView.ts +61 -0
  43. package/dist/runtime-ets/dom/node.ts +29 -16
  44. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +624 -0
  45. package/dist/runtime-ets/dom/stylesheet/index.ts +216 -354
  46. package/dist/runtime-ets/dom/stylesheet/type.ts +46 -11
  47. package/dist/runtime-ets/dom/stylesheet/util.ts +58 -6
  48. package/dist/runtime-ets/index.ts +1 -2
  49. package/dist/runtime-ets/interface/event.ts +2 -1
  50. package/dist/runtime-ets/utils/index.ts +6 -1
  51. package/dist/runtime-ets/utils/info.ts +3 -1
  52. package/dist/runtime-framework/react/app.ts +12 -22
  53. package/dist/runtime-framework/react/hooks.ts +3 -3
  54. package/dist/runtime-framework/react/index.ts +1 -0
  55. package/dist/runtime-framework/react/native-page.ts +344 -0
  56. package/dist/runtime-framework/react/page.ts +2 -2
  57. package/dist/runtime-framework/solid/hooks.ts +3 -3
  58. package/dist/runtime-utils.js +76 -20
  59. package/dist/runtime-utils.js.map +1 -1
  60. package/dist/runtime.js +76 -20
  61. package/dist/runtime.js.map +1 -1
  62. package/package.json +12 -11
  63. package/static/media/cancel.svg +1 -0
  64. package/static/media/circle.svg +1 -0
  65. package/static/media/clear.svg +1 -0
  66. package/static/media/download.svg +1 -0
  67. package/static/media/info.svg +1 -0
  68. package/static/media/info_circle.svg +1 -0
  69. package/static/media/search.svg +1 -0
  70. package/static/media/success.svg +1 -0
  71. package/static/media/success_no_circle.svg +1 -0
  72. package/static/media/taro_arrow_left.svg +1 -0
  73. package/static/media/taro_home.svg +1 -0
  74. package/static/media/waiting.svg +1 -0
  75. package/static/media/warn.svg +1 -0
  76. package/types/runtime.d.ts +2 -0
  77. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -1,20 +1,33 @@
1
+ // @ts-nocheck
1
2
  import matrix4 from '@ohos.matrix4'
2
3
 
3
4
  export interface HarmonyStyle extends TaroStyleType {
4
5
  textAlign?: TextAlign
5
6
  textOverflow?: HarmonyType.Overflow
6
- maxLines?: number
7
+ WebkitLineClamp?: number
7
8
  letterSpacing?: number | string
8
9
  }
9
10
 
10
11
  export interface TaroStyleType {
11
12
  id?: string
12
13
 
13
- padding?: Padding
14
- margin?: Margin
14
+ paddingTop?: Length
15
+ paddingRight?: Length
16
+ paddingBottom?: Length
17
+ paddingLeft?: Length
18
+
19
+ marginTop?: Length
20
+ marginRight?: Length
21
+ marginBottom?: Length
22
+ marginLeft?: Length
23
+
15
24
  width?: Length
16
25
  height?: Length
17
- constraintSize?: ConstraintSizeOptions
26
+
27
+ minHeight?: Length
28
+ maxHeight?: Length
29
+ minWidth?: Length
30
+ maxWidth?: Length
18
31
 
19
32
  display?: 'flex' | 'block' | 'none'
20
33
 
@@ -28,7 +41,7 @@ export interface TaroStyleType {
28
41
  flexGrow?: number
29
42
  flexShrink?: number
30
43
  alignSelf?: ItemAlign
31
- direction?: FlexDirection
44
+ flexDirection?: FlexDirection
32
45
  justifyContent?: FlexAlign
33
46
  alignItems?: ItemAlign
34
47
  flexWrap?: FlexWrap
@@ -36,22 +49,39 @@ export interface TaroStyleType {
36
49
 
37
50
  // background
38
51
  backgroundColor?: ResourceColor
39
- backgroundImage?: ResourceStr
52
+ backgroundImage?: HarmonyType.Background.BackgroundImage
40
53
  backgroundRepeat?: ImageRepeat
41
- backgroundImageSize?: SizeOptions | ImageSize
42
- backgroundImagePosition?: Position | Alignment
54
+ backgroundSize?: SizeOptions | ImageSize
55
+ backgroundPosition?: Position | Alignment
43
56
 
44
57
  // transform
45
58
  rotate?: HarmonyType.Transform.Rotate
46
59
  translate?: HarmonyType.Transform.Translate
47
60
  scale?: HarmonyType.Transform.Scale
48
61
  transform?: HarmonyType.Transform.Transform
62
+ transformOrigin?: HarmonyType.Transform.Origin
49
63
 
50
64
  // border
51
65
  borderWidth?: Length | EdgeWidths
66
+ borderLeftWidth?: Length
67
+ borderRightWidth?: Length
68
+ borderTopWidth?: Length
69
+ borderBottomWidth?: Length
52
70
  borderColor?: ResourceColor | EdgeColors
71
+ borderLeftColor?: ResourceColor
72
+ borderRightColor?: ResourceColor
73
+ borderTopColor?: ResourceColor
74
+ borderBottomColor?: ResourceColor
53
75
  borderStyle?: BorderStyle | EdgeStyles
76
+ borderLeftStyle?: BorderStyle
77
+ borderRightStyle?: BorderStyle
78
+ borderTopStyle?: BorderStyle
79
+ borderBottomStyle?: BorderStyle
54
80
  borderRadius?: Length | BorderRadiuses
81
+ borderTopLeftRadius?: Length
82
+ borderTopRightRadius?: Length
83
+ borderBottomLeftRadius?: Length
84
+ borderBottomRightRadius?: Length
55
85
 
56
86
  // text
57
87
  color?: ResourceColor
@@ -60,7 +90,7 @@ export interface TaroStyleType {
60
90
  fontWeight?: number | FontWeight | string
61
91
  fontFamily?: string | Resource
62
92
  lineHeight?: string | number | Resource
63
- decoration?: TextDecorationType
93
+ textDecoration?: TextDecorationType
64
94
 
65
95
  // gradient
66
96
  linearGradient?: HarmonyType.LinearGradient
@@ -68,14 +98,14 @@ export interface TaroStyleType {
68
98
  // other
69
99
  opacity?: number | Resource
70
100
  zIndex?: number
71
- clip?: boolean
101
+ overflow?: boolean
72
102
  focus?: boolean
73
103
  }
74
104
 
75
105
  export interface TaroTextStyleType {
76
106
  textAlign?: TextAlign
77
107
  textOverflow?: HarmonyType.Overflow
78
- maxLines?: number
108
+ WebkitLineClamp?: number
79
109
  letterSpacing?: number | string
80
110
  }
81
111
 
@@ -104,11 +134,16 @@ export namespace HarmonyType {
104
134
  export interface backgroundImage {
105
135
  src: ResourceStr
106
136
  repeat?: ImageRepeat
137
+ colors?: Array<[ResourceColor, number]>
107
138
  }
108
139
  export type backgroundImageSize = SizeOptions | ImageSize
109
140
  export type backgroundImagePosition = Position | Alignment
110
141
  }
111
142
  export namespace Transform {
143
+ export interface Origin {
144
+ x?: number
145
+ y?: number
146
+ }
112
147
  export interface Rotate {
113
148
  x?: number
114
149
  y?: number
@@ -1,10 +1,10 @@
1
1
  // @ts-nocheck
2
+ import matrix4 from '@ohos.matrix4'
2
3
  import { isNumber } from '@tarojs/shared'
3
4
 
4
5
  import { convertNumber2VP } from '../../'
5
6
 
6
7
  export class FlexManager {
7
-
8
8
  static flexAlign (value: string | number | undefined): FlexAlign {
9
9
  switch (value) {
10
10
  case 'flex-end':
@@ -163,6 +163,32 @@ export class FlexManager {
163
163
  }
164
164
  }
165
165
 
166
+
167
+ export class BORDER_STYLE_MAP {
168
+ static solid = BorderStyle.Solid
169
+ static dotted = BorderStyle.Dotted
170
+ static dashed = BorderStyle.Dashed
171
+
172
+ static get(type: string): BorderStyle {
173
+ switch (type) {
174
+ case 'dotted': return BorderStyle.Dotted
175
+ case 'dashed': return BorderStyle.Dashed
176
+ default: return BorderStyle.Solid
177
+ }
178
+ }
179
+
180
+ static reverse(type: BorderStyle): string {
181
+ switch (type) {
182
+ case BorderStyle.Dotted: return 'dotted'
183
+ case BorderStyle.Dashed: return 'dashed'
184
+ case BorderStyle.Solid: return 'solid'
185
+ default: return ''
186
+ }
187
+
188
+ }
189
+ }
190
+
191
+
166
192
  export function getNodeMarginOrPaddingData (dataValue: string) {
167
193
  let res: any = {}
168
194
  if (dataValue) {
@@ -184,10 +210,7 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
184
210
  break
185
211
  }
186
212
  Object.keys(res).forEach(key => {
187
- const exec = `${res[key]}`.match(/(\d+)(px)$/)
188
- if (exec && values.length > 1) {
189
- res[key] = getUnit(+exec[1])
190
- }
213
+ res[key] = getUnit(res[key]) || 0
191
214
  })
192
215
  }
193
216
  return res
@@ -195,10 +218,39 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
195
218
 
196
219
 
197
220
  export function getUnit (val) {
221
+ // 空的字符串代表 Reconciler remove 了这个 prop,不进行后面的逻辑了
222
+ if (val === '') return val
223
+
198
224
  if (/\d+(vp)$/.test(val)) {
199
225
  return val
200
- } else if (isNumber(val) || /\d+px$/.test(val)) {
226
+ } else if (isNumber(val)) {
201
227
  return convertNumber2VP(parseFloat(val))
202
228
  }
229
+ if (val) {
230
+ // 匹配vw\vh
231
+ const exec = val.match(/(\d+)(vw|vh|px)$/)
232
+ if (exec) {
233
+ const [, num, unit] = exec
234
+ return convertNumber2VP(parseFloat(num), unit)
235
+ }
236
+ }
203
237
  return val
204
238
  }
239
+
240
+ export function getTransform(transform) {
241
+ if (transform) {
242
+ return transform.reduce((res, item) => {
243
+ switch (item.type) {
244
+ case 'Translate': return res.translate(item.value)
245
+ case 'Scale': return res.scale(item.value)
246
+ case 'Rotate': return res.rotate(item.value)
247
+ case 'Matrix': return res.combine(matrix4.init(item.value))
248
+ }
249
+ return res
250
+ }, matrix4.identity())
251
+ }
252
+ }
253
+
254
+ export function capitalizeFirstLetter (str: string) {
255
+ return str.charAt(0).toUpperCase() + str.slice(1)
256
+ }
@@ -12,7 +12,6 @@ export * from './dom/node'
12
12
  export * from './dom/stylesheet'
13
13
  export * from './interface'
14
14
  export * from './utils'
15
- export * from './utils/bind'
16
15
  export * from './utils/info'
17
- export { URLSearchParams, eventSource } from '@tarojs/runtime/dist/runtime.esm'
16
+ export { URLSearchParams, eventSource, Events } from '@tarojs/runtime/dist/runtime.esm'
18
17
  export { hooks } from '@tarojs/shared'
@@ -4,6 +4,7 @@ export interface EventOptions {
4
4
  [x: string]: any
5
5
  }
6
6
 
7
- export interface EventHandler extends Function {
7
+ export interface EventHandler<T = any, R = void> {
8
+ (...args: T[]): R
8
9
  _stop?: boolean
9
10
  }
@@ -2,6 +2,7 @@ import _display from '@ohos.display'
2
2
  import { pxTransformHelper } from '@tarojs/taro'
3
3
 
4
4
  import { NodeType } from '../dom/node'
5
+ import convertWebStyle2HmStyle from '../dom/stylesheet/covertWeb2Hm'
5
6
 
6
7
  import type { CSSProperties } from 'react'
7
8
  import type { TaroElement } from '../dom/element/element'
@@ -53,7 +54,11 @@ export function calcDynamicStyle (styleSheet: Record<string, CSSProperties>, cla
53
54
  obj.push(styleSheet[className])
54
55
  }
55
56
  }
56
- obj.push(style)
57
+
58
+ if (style) {
59
+ obj.push(convertWebStyle2HmStyle(style))
60
+ }
61
+
57
62
  return Object.assign.apply(null, [{}].concat(obj))
58
63
  }
59
64
 
@@ -50,7 +50,9 @@ function tapCallbackToNodeAndUpdate (node: TaroElement, eventName: string, callb
50
50
  callback && callback(...eventResult)
51
51
  }
52
52
 
53
- node.updateComponent()
53
+ if (!node._isDynamicNode || !node._isCompileMode) {
54
+ node.updateComponent()
55
+ }
54
56
  }
55
57
 
56
58
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -1,5 +1,5 @@
1
1
  import { Current, document } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
- import { eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
2
+ import { AppInstance, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
3
3
 
4
4
  import { setReconciler } from './connect'
5
5
  import { injectPageInstance } from './page'
@@ -26,8 +26,11 @@ const pageKeyId = incrementId()
26
26
 
27
27
  export function connectReactPage (
28
28
  R: typeof React,
29
- id: string
29
+ id: string,
30
+ getCtx: () => any
30
31
  ) {
32
+ const ctx = getCtx?.()
33
+
31
34
  return (Page): React.ComponentClass<any> => {
32
35
  // eslint-disable-next-line dot-notation
33
36
  const isReactComponent = isClassComponent(R, Page)
@@ -63,7 +66,7 @@ export function connectReactPage (
63
66
  const children = this.state.hasError
64
67
  ? []
65
68
  : h(ReactMeta.PageContext.Provider, { value: id }, h(Page, {
66
- ...this.props,
69
+ ...Object.assign({}, ctx?.props, this.props),
67
70
  ...refs
68
71
  }))
69
72
 
@@ -126,8 +129,8 @@ export function createReactApp (
126
129
  appWrapperResolver(this)
127
130
  }
128
131
 
129
- public mount (pageComponent: any, id: string, cb: () => void) {
130
- const pageWrapper = connectReactPage(react, id)(pageComponent)
132
+ public mount (pageComponent: any, id: string, getCtx: () => any, cb: () => void) {
133
+ const pageWrapper = connectReactPage(react, id, getCtx)(pageComponent)
131
134
  const key = id + pageKeyId()
132
135
  const page = () => h(pageWrapper, { key, tid: id })
133
136
  this.pages.push(page)
@@ -169,14 +172,13 @@ export function createReactApp (
169
172
  render (cb: () => void) {
170
173
  appWrapper.forceUpdate(cb)
171
174
  },
172
- mount (component: any, id: string, cb: () => void) {
175
+ mount (component: any, id: string, getCtx: () => any, cb: () => void) {
173
176
  if (appWrapper) {
174
- appWrapper.mount(component, id, cb)
177
+ appWrapper.mount(component, id, getCtx, cb)
175
178
  } else {
176
- appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, cb))
179
+ appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, getCtx, cb))
177
180
  }
178
181
  },
179
-
180
182
  unmount (id: string, cb: () => void) {
181
183
  appWrapper?.unmount(id, cb)
182
184
  },
@@ -233,19 +235,7 @@ export function createReactApp (
233
235
  app?.componentDidHide?.()
234
236
  })
235
237
  }
236
- }
237
-
238
- // TODO: function componennt hook
239
- // function triggerAppHook (lifecycle: string, ...option) {
240
- // const instance = getPageInstance('taro-app')
241
- // if (instance) {
242
- // const app = getAppInstance()
243
- // const func = hooks.call('getLifecycle', instance, lifecycle)
244
- // if (Array.isArray(func)) {
245
- // func.forEach(cb => cb.apply(app, option))
246
- // }
247
- // }
248
- // }
238
+ } as unknown as AppInstance
249
239
 
250
240
  Current.app = app
251
241
 
@@ -7,14 +7,14 @@ import { HOOKS_APP_ID } from './utils'
7
7
 
8
8
  import type {
9
9
  AppInstance,
10
- Func,
11
10
  Instance,
12
11
  PageLifeCycle,
13
- PageProps
12
+ PageProps,
13
+ TFunc
14
14
  } from '@tarojs/runtime/dist/runtime.esm'
15
15
 
16
16
  const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
17
- return (fn: Func) => {
17
+ return (fn: TFunc) => {
18
18
  const { R: React, PageContext } = ReactMeta
19
19
  const id = React.useContext(PageContext) || HOOKS_APP_ID
20
20
  const instRef = React.useRef<Instance<PageProps>>()
@@ -13,4 +13,5 @@ hooks.tap('initNativeApi', function (taro) {
13
13
  export * from './app'
14
14
  export * from './connect'
15
15
  export * from './hooks'
16
+ export * from './native-page'
16
17
  export * from './page'