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

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 (87) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/framework/index.ts +1 -5
  3. package/dist/apis/index.ts +3 -1
  4. package/dist/apis/network/request.ts +5 -5
  5. package/dist/apis/route/index.ts +15 -0
  6. package/dist/apis/storage/index.ts +124 -60
  7. package/dist/apis/wxml/IntersectionObserver.ts +5 -3
  8. package/dist/apis/wxml/index.ts +2 -0
  9. package/dist/components-harmony-ets/button.ets +41 -78
  10. package/dist/components-harmony-ets/checkbox.ets +19 -209
  11. package/dist/components-harmony-ets/form.ets +38 -160
  12. package/dist/components-harmony-ets/icon.ets +31 -83
  13. package/dist/components-harmony-ets/image.ets +22 -78
  14. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  15. package/dist/components-harmony-ets/input.ets +10 -67
  16. package/dist/components-harmony-ets/label.ets +52 -173
  17. package/dist/components-harmony-ets/movableArea.ets +89 -0
  18. package/dist/components-harmony-ets/movableView.ets +67 -0
  19. package/dist/components-harmony-ets/picker.ets +32 -147
  20. package/dist/components-harmony-ets/progress.ets +47 -0
  21. package/dist/components-harmony-ets/pseudo.ets +80 -0
  22. package/dist/components-harmony-ets/radio.ets +19 -210
  23. package/dist/components-harmony-ets/richText.ets +22 -102
  24. package/dist/components-harmony-ets/scrollView.ets +66 -169
  25. package/dist/components-harmony-ets/slider.ets +10 -72
  26. package/dist/components-harmony-ets/style.ets +244 -0
  27. package/dist/components-harmony-ets/swiper.ets +30 -87
  28. package/dist/components-harmony-ets/switch.ets +9 -71
  29. package/dist/components-harmony-ets/text.ets +38 -89
  30. package/dist/components-harmony-ets/textArea.ets +10 -67
  31. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  32. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  33. package/dist/components-harmony-ets/utils/flexManager.ets +8 -7
  34. package/dist/components-harmony-ets/utils/helper.ets +5 -4
  35. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  36. package/dist/components-harmony-ets/utils/index.ts +55 -2
  37. package/dist/components-harmony-ets/utils/styles.ets +45 -85
  38. package/dist/components-harmony-ets/video.ets +33 -88
  39. package/dist/components-harmony-ets/view.ets +47 -160
  40. package/dist/components-harmony-ets/webView.ets +44 -99
  41. package/dist/index.d.ts +151 -0
  42. package/dist/index.js +58 -29
  43. package/dist/index.js.map +1 -1
  44. package/dist/runtime-ets/bom/window.ts +4 -2
  45. package/dist/runtime-ets/current.ts +2 -0
  46. package/dist/runtime-ets/dom/bind.ts +0 -1
  47. package/dist/runtime-ets/dom/cssNesting.ts +311 -0
  48. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +15 -40
  49. package/dist/runtime-ets/dom/document.ts +21 -8
  50. package/dist/runtime-ets/dom/element/element.ts +53 -9
  51. package/dist/runtime-ets/dom/element/form.ts +11 -4
  52. package/dist/runtime-ets/dom/element/index.ts +12 -1
  53. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  54. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  55. package/dist/runtime-ets/dom/element/normal.ts +8 -3
  56. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  57. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  58. package/dist/runtime-ets/dom/element/text.ts +1 -0
  59. package/dist/runtime-ets/dom/element/video.ts +1 -0
  60. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  61. package/dist/runtime-ets/dom/event.ts +0 -1
  62. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  63. package/dist/runtime-ets/dom/node.ts +18 -17
  64. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +184 -207
  65. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  66. package/dist/runtime-ets/dom/stylesheet/type.ts +18 -6
  67. package/dist/runtime-ets/dom/stylesheet/util.ts +19 -15
  68. package/dist/runtime-ets/index.ts +2 -2
  69. package/dist/runtime-ets/interface/event.ts +1 -1
  70. package/dist/runtime-ets/utils/index.ts +24 -9
  71. package/dist/runtime-framework/react/app.ts +5 -1
  72. package/dist/runtime-framework/react/hooks.ts +3 -3
  73. package/dist/runtime-framework/react/native-page.ts +14 -9
  74. package/dist/runtime-framework/react/page.ts +1 -0
  75. package/dist/runtime-framework/solid/hooks.ts +3 -3
  76. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  77. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  78. package/dist/runtime-utils.d.ts +825 -0
  79. package/dist/runtime-utils.js +185 -91
  80. package/dist/runtime-utils.js.map +1 -1
  81. package/dist/runtime.d.ts +1 -0
  82. package/dist/runtime.js +185 -91
  83. package/dist/runtime.js.map +1 -1
  84. package/index.js +3 -1
  85. package/package.json +10 -10
  86. package/types/index.d.ts +4 -0
  87. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- import matrix4 from '@ohos.matrix4'
2
+ // import matrix4 from '@ohos.matrix4'
3
3
  import { isNumber } from '@tarojs/shared'
4
4
 
5
5
  import { convertNumber2VP } from '../../'
@@ -163,7 +163,6 @@ export class FlexManager {
163
163
  }
164
164
  }
165
165
 
166
-
167
166
  export class BORDER_STYLE_MAP {
168
167
  static solid = BorderStyle.Solid
169
168
  static dotted = BorderStyle.Dotted
@@ -188,11 +187,10 @@ export class BORDER_STYLE_MAP {
188
187
  }
189
188
  }
190
189
 
191
-
192
190
  export function getNodeMarginOrPaddingData (dataValue: string) {
193
191
  let res: any = {}
194
192
  if (dataValue) {
195
- const values = dataValue.trim().split(new RegExp('\\s+'))
193
+ const values = dataValue.toString().trim().split(new RegExp('\\s+'))
196
194
  switch (values.length) {
197
195
  case 1:
198
196
  res = { top: values[0], right: values[0], bottom: values[0], left: values[0] }
@@ -216,7 +214,6 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
216
214
  return res
217
215
  }
218
216
 
219
-
220
217
  export function getUnit (val) {
221
218
  // 空的字符串代表 Reconciler remove 了这个 prop,不进行后面的逻辑了
222
219
  if (val === '') return val
@@ -238,19 +235,26 @@ export function getUnit (val) {
238
235
  }
239
236
 
240
237
  export function getTransform(transform) {
238
+ // if (transform) {
239
+ // return transform.reduce((res, item) => {
240
+ // switch (item.type) {
241
+ // case 'Translate': return res.translate(item.value)
242
+ // case 'Scale': return res.scale(item.value)
243
+ // case 'Rotate': return res.rotate(item.value)
244
+ // case 'Matrix': return res.combine(matrix4.init(item.value))
245
+ // }
246
+ // return res
247
+ // }, matrix4.identity())
248
+ // }
249
+ const result = {}
241
250
  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
+ transform.forEach((item) => {
252
+ result[item.type] = item.value
253
+ })
254
+ return result
251
255
  }
252
256
  }
253
257
 
254
258
  export function capitalizeFirstLetter (str: string) {
255
259
  return str.charAt(0).toUpperCase() + str.slice(1)
256
- }
260
+ }
@@ -10,9 +10,9 @@ export * from './dom/element'
10
10
  export * from './dom/event'
11
11
  export * from './dom/node'
12
12
  export * from './dom/stylesheet'
13
+ export * from './dom/cssNesting'
13
14
  export * from './interface'
14
15
  export * from './utils'
15
- export * from './utils/bind'
16
16
  export * from './utils/info'
17
- export { URLSearchParams, eventSource } from '@tarojs/runtime/dist/runtime.esm'
17
+ export { URL, URLSearchParams, eventSource, Events } from '@tarojs/runtime/dist/runtime.esm'
18
18
  export { hooks } from '@tarojs/shared'
@@ -7,4 +7,4 @@ export interface EventOptions {
7
7
  export interface EventHandler<T = any, R = void> {
8
8
  (...args: T[]): R
9
9
  _stop?: boolean
10
- }
10
+ }
@@ -45,21 +45,37 @@ export function convertNumber2VP (value: number, unit = 'px') {
45
45
  return pxTransformHelper(value, 'vp')
46
46
  }
47
47
 
48
- export function calcDynamicStyle (styleSheet: Record<string, CSSProperties>, classNames: string, style: CSSProperties): CSSProperties {
48
+ // 合并静态样式,从样式表里面找到对应的样式
49
+ export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames: string, style: CSSProperties): CSSProperties {
49
50
  const obj: CSSProperties[] = []
50
51
  const classes = typeof classNames === 'string' ? classNames.split(' ') : []
51
- for (let i = 0; i < classes.length; i++) {
52
- const className = classes[i]
53
- if (styleSheet[className]) {
54
- obj.push(styleSheet[className])
52
+ if (classes.length === 1) {
53
+ if (style) {
54
+ return Object.assign({}, styleSheet[classNames], style)
55
+ } else {
56
+ // 同一个引用
57
+ return styleSheet[classNames]
55
58
  }
59
+ } else {
60
+ for (let i = 0; i < classes.length; i++) {
61
+ const className = classes[i]
62
+ if (styleSheet[className]) {
63
+ obj.push(styleSheet[className])
64
+ }
65
+ }
66
+ if (style) {
67
+ obj.push(style)
68
+ }
69
+ return Object.assign.apply(null, [{}].concat(obj))
56
70
  }
71
+ }
57
72
 
73
+ // 动态样式计算,需要经过web2harmony进行反转
74
+ export function calcDynamicStyle (style: CSSProperties): CSSProperties {
58
75
  if (style) {
59
- obj.push(convertWebStyle2HmStyle(style))
76
+ return convertWebStyle2HmStyle(style)
60
77
  }
61
-
62
- return Object.assign.apply(null, [{}].concat(obj))
78
+ return {}
63
79
  }
64
80
 
65
81
  export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
@@ -91,7 +107,6 @@ export function bindFn (fn: any, ctx: any, ...args: any) {
91
107
  }
92
108
  }
93
109
 
94
-
95
110
  // 使用深度优先遍历寻找节点树中对应的子节点,且只需要找到第一个
96
111
  // 通过 selector 判断是 id 还是 selector,从 node 的 id 和 className 属性中寻找
97
112
  export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: true): T[] | null;
@@ -237,7 +237,11 @@ export function createReactApp (
237
237
  }
238
238
  } as unknown as AppInstance
239
239
 
240
- Current.app = app
240
+ if (Current.app) {
241
+ Current.app = Object.assign(app, Current.app)
242
+ } else {
243
+ Current.app = app
244
+ }
241
245
 
242
246
  return app
243
247
  }
@@ -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>>()
@@ -1,5 +1,5 @@
1
1
  import { Current, document, requestAnimationFrame, TaroElement, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
- import { CONTEXT_ACTIONS, env, eventCenter, Func } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
2
+ import { CONTEXT_ACTIONS, env, eventCenter, TFunc } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
3
3
  import { ensure, hooks, isUndefined } from '@tarojs/shared'
4
4
 
5
5
  import { ReactMeta as reactMeta } from './app'
@@ -27,7 +27,7 @@ let nativeComponentApp: AppInstance
27
27
  interface InitNativeComponentEntryParams {
28
28
  R: typeof React
29
29
  ReactDOM: typeof ReactDOM
30
- cb?: Func
30
+ cb?: TFunc
31
31
  // 是否使用默认的 DOM 入口 - app;默认为true,false的时候,会创建一个新的dom并且把它挂载在 app 下面
32
32
  isDefaultEntryDom?: boolean
33
33
  }
@@ -80,7 +80,11 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
80
80
 
81
81
  componentDidMount () {
82
82
  if (isDefaultEntryDom) {
83
- Current.app = this
83
+ if (Current.app) {
84
+ Current.app = Object.assign(this, Current.app)
85
+ } else {
86
+ Current.app = this
87
+ }
84
88
  } else {
85
89
  nativeComponentApp = this
86
90
  }
@@ -200,7 +204,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
200
204
 
201
205
  const pageObj: Record<string, any> = {
202
206
  options: pageConfig,
203
- [ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: Func) {
207
+ [ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: TFunc) {
204
208
  hasLoaded = new Promise(resolve => { loadResolver = resolve })
205
209
  Current.page = this as any
206
210
  this.config = pageConfig || {}
@@ -253,7 +257,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
253
257
  window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
254
258
  // 触发onUnload生命周期
255
259
  safeExecute($taroPath, ONUNLOAD)
256
- resetCurrent()
260
+ resetCurrent.call(this)
257
261
  unmounting = true
258
262
  Current.app!.unmount!($taroPath, () => {
259
263
  unmounting = false
@@ -306,12 +310,13 @@ export function createNativePageConfig (Component, pageName: string, react: type
306
310
  }
307
311
 
308
312
  function resetCurrent () {
309
- // 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
310
- Current.page = null
311
- Current.router = null
313
+ if (Current.page === this) {
314
+ // 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
315
+ Current.page = null
316
+ Current.router = null
317
+ }
312
318
  }
313
319
 
314
-
315
320
  LIFECYCLES.forEach((lifecycle) => {
316
321
  pageObj[lifecycle] = function () {
317
322
  return safeExecute(this.$taroPath, lifecycle, ...arguments)
@@ -184,6 +184,7 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
184
184
  safeExecute(this.$taroPath, ON_READY)
185
185
  // 通过事件触发子组件的生命周期
186
186
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
187
+ this.onReady.called = true
187
188
  })
188
189
  },
189
190
  [ONSHOW] (options = {}) {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  AppInstance,
3
3
  Current,
4
- Func,
5
- PageLifeCycle
4
+ PageLifeCycle,
5
+ TFunc
6
6
  } from '@tarojs/runtime'
7
7
  import { isArray, isFunction } from '@tarojs/shared'
8
8
  import {
@@ -16,7 +16,7 @@ import { getPageInstance, injectPageInstance } from './page'
16
16
  import { HOOKS_APP_ID } from './utils'
17
17
 
18
18
  const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
19
- return (fn: Func) => {
19
+ return (fn: TFunc) => {
20
20
  const id = ReactMeta.PageContext || HOOKS_APP_ID
21
21
 
22
22
  createRenderEffect(() => {
@@ -5,4 +5,3 @@ export function use(fn, ele, accessor) {
5
5
  fn(ele, accessor)
6
6
  })
7
7
  }
8
-
@@ -45,5 +45,3 @@ export function setRouterParams(options) {
45
45
  ...options,
46
46
  }
47
47
  }
48
-
49
-