@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121

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 (143) hide show
  1. package/dist/apis/base/system.ts +60 -25
  2. package/dist/apis/base/weapp/life-cycle.ts +1 -1
  3. package/dist/apis/canvas/index.ts +10 -1
  4. package/dist/apis/device/clipboard.ts +23 -8
  5. package/dist/apis/framework/index.ts +2 -6
  6. package/dist/apis/index.ts +25 -17
  7. package/dist/apis/media/image/index.ts +169 -17
  8. package/dist/apis/route/index.ts +1 -2
  9. package/dist/apis/storage/index.ts +135 -131
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +3 -2
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +2 -2
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +6 -6
  16. package/dist/apis/ui/tab-bar.ts +4 -5
  17. package/dist/apis/utils/index.ts +20 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/selectorQuery.ts +26 -13
  21. package/dist/components-harmony-ets/button.ets +36 -9
  22. package/dist/components-harmony-ets/canvas.ets +51 -0
  23. package/dist/components-harmony-ets/checkbox.ets +69 -60
  24. package/dist/components-harmony-ets/form.ets +33 -15
  25. package/dist/components-harmony-ets/icon.ets +16 -8
  26. package/dist/components-harmony-ets/image.ets +22 -6
  27. package/dist/components-harmony-ets/index.ets +39 -0
  28. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  29. package/dist/components-harmony-ets/input.ets +63 -37
  30. package/dist/components-harmony-ets/label.ets +43 -21
  31. package/dist/components-harmony-ets/listView.ets +32 -0
  32. package/dist/components-harmony-ets/movableArea.ets +110 -51
  33. package/dist/components-harmony-ets/movableView.ets +74 -47
  34. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  35. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  36. package/dist/components-harmony-ets/picker.ets +36 -33
  37. package/dist/components-harmony-ets/progress.ets +31 -24
  38. package/dist/components-harmony-ets/pseudo.ets +80 -0
  39. package/dist/components-harmony-ets/radio.ets +75 -66
  40. package/dist/components-harmony-ets/richText.ets +4 -25
  41. package/dist/components-harmony-ets/scrollList.ets +108 -0
  42. package/dist/components-harmony-ets/scrollView.ets +46 -42
  43. package/dist/components-harmony-ets/slider.ets +19 -15
  44. package/dist/components-harmony-ets/stickySection.ets +42 -0
  45. package/dist/components-harmony-ets/style.ets +386 -129
  46. package/dist/components-harmony-ets/swiper.ets +42 -5
  47. package/dist/components-harmony-ets/switch.ets +36 -32
  48. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  49. package/dist/components-harmony-ets/text.ets +102 -46
  50. package/dist/components-harmony-ets/textArea.ets +49 -34
  51. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  52. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  53. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  54. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  55. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  56. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  57. package/dist/components-harmony-ets/utils/index.ts +54 -50
  58. package/dist/components-harmony-ets/utils/styles.ets +169 -91
  59. package/dist/components-harmony-ets/video.ets +28 -20
  60. package/dist/components-harmony-ets/view.ets +45 -39
  61. package/dist/components-harmony-ets/webView.ets +6 -5
  62. package/dist/index.d.ts +152 -0
  63. package/dist/index.js +73 -44
  64. package/dist/index.js.map +1 -1
  65. package/dist/runtime-ets/bom/URL.ts +2 -0
  66. package/dist/runtime-ets/bom/document.ts +5 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
  68. package/dist/runtime-ets/bom/history.ts +1 -0
  69. package/dist/runtime-ets/bom/location.ts +1 -0
  70. package/dist/runtime-ets/bom/navigator.ts +1 -21
  71. package/dist/runtime-ets/bom/raf.ts +1 -37
  72. package/dist/runtime-ets/bom/window.ts +10 -4
  73. package/dist/runtime-ets/constant.ts +17 -10
  74. package/dist/runtime-ets/current.ts +5 -2
  75. package/dist/runtime-ets/dom/bind.ts +28 -12
  76. package/dist/runtime-ets/dom/class-list.ts +2 -2
  77. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  78. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  79. package/dist/runtime-ets/dom/document.ts +9 -12
  80. package/dist/runtime-ets/dom/element/canvas.ts +137 -0
  81. package/dist/runtime-ets/dom/element/element.ts +379 -55
  82. package/dist/runtime-ets/dom/element/form.ts +26 -22
  83. package/dist/runtime-ets/dom/element/index.ts +22 -2
  84. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  85. package/dist/runtime-ets/dom/element/movableView.ts +238 -2
  86. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  87. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  88. package/dist/runtime-ets/dom/element/text.ts +0 -8
  89. package/dist/runtime-ets/dom/element/video.ts +4 -4
  90. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  91. package/dist/runtime-ets/dom/event-source.ts +1 -0
  92. package/dist/runtime-ets/dom/event.ts +3 -5
  93. package/dist/runtime-ets/dom/eventTarget.ts +3 -4
  94. package/dist/runtime-ets/dom/node.ts +53 -22
  95. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  96. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  97. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  98. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  99. package/dist/runtime-ets/emitter/emitter.ts +1 -0
  100. package/dist/runtime-ets/env.ts +1 -0
  101. package/dist/runtime-ets/index.ts +23 -7
  102. package/dist/runtime-ets/interface/event.ts +1 -1
  103. package/dist/runtime-ets/interface/index.ts +6 -0
  104. package/dist/runtime-ets/utils/index.ts +78 -19
  105. package/dist/runtime-ets/utils/info.ts +2 -2
  106. package/dist/runtime-ets/utils/router.ts +9 -0
  107. package/dist/runtime-framework/react/app.ts +15 -11
  108. package/dist/runtime-framework/react/hooks.ts +1 -2
  109. package/dist/runtime-framework/react/index.ts +0 -2
  110. package/dist/runtime-framework/react/native-page.ts +217 -81
  111. package/dist/runtime-framework/react/page.ts +4 -10
  112. package/dist/runtime-framework/react/utils/index.ts +3 -3
  113. package/dist/runtime-framework/solid/app.ts +29 -46
  114. package/dist/runtime-framework/solid/connect.ts +21 -3
  115. package/dist/runtime-framework/solid/hooks.ts +16 -11
  116. package/dist/runtime-framework/solid/index.ts +6 -2
  117. package/dist/runtime-framework/solid/page.ts +84 -31
  118. package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
  119. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  120. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  121. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  122. package/dist/runtime-utils.d.ts +827 -0
  123. package/dist/runtime-utils.js +574 -285
  124. package/dist/runtime-utils.js.map +1 -1
  125. package/dist/runtime.d.ts +1 -0
  126. package/dist/runtime.js +574 -285
  127. package/dist/runtime.js.map +1 -1
  128. package/index.js +3 -1
  129. package/package.json +14 -15
  130. package/static/media/cancel.svg +1 -1
  131. package/static/media/circle.svg +1 -1
  132. package/static/media/clear.svg +1 -1
  133. package/static/media/download.svg +1 -1
  134. package/static/media/info.svg +1 -1
  135. package/static/media/info_circle.svg +1 -1
  136. package/static/media/search.svg +1 -1
  137. package/static/media/success.svg +1 -1
  138. package/static/media/success_no_circle.svg +1 -1
  139. package/static/media/warn.svg +1 -1
  140. package/types/harmony.d.ts +5 -0
  141. package/types/index.d.ts +4 -0
  142. package/types/runtime.d.ts +1 -1
  143. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,11 +1,29 @@
1
- import { TaroNode } from '@tarojs/runtime'
2
1
  import { hooks } from '@tarojs/shared'
3
2
  import { batch } from 'solid-js'
4
3
 
5
- export type Component = (props?: any) => TaroNode
4
+ import { ensureIsArray } from './utils'
6
5
 
7
- export function setReconciler() {
6
+ import type { TaroNode } from '@tarojs/runtime'
7
+
8
+ export type SolidComponent = (props?: any) => TaroNode
9
+
10
+ export function setReconciler () {
8
11
  hooks.tap('batchedEventUpdates', function (cb) {
9
12
  batch(cb)
10
13
  })
14
+
15
+ hooks.tap('mergePageInstance', function (prev, next) {
16
+ if (!prev || !next) return
17
+
18
+ // 子组件使用 lifecycle hooks 注册了生命周期后,会存在 prev,里面是注册的生命周期回调。
19
+
20
+ // prev 使用 Object.create(null) 创建,H5 的 fast-refresh 可能也会导致存在 prev,要排除这些意外产生的 prev
21
+ if ('constructor' in prev) return
22
+
23
+ Object.keys(prev).forEach(item => {
24
+ const prevList = prev[item]
25
+ const nextList = ensureIsArray<() => any>(next[item])
26
+ next[item] = nextList.concat(prevList)
27
+ })
28
+ })
11
29
  }
@@ -1,9 +1,4 @@
1
- import {
2
- AppInstance,
3
- Current,
4
- PageLifeCycle,
5
- TFunc
6
- } from '@tarojs/runtime'
1
+ import { Current } from '@tarojs/runtime'
7
2
  import { isArray, isFunction } from '@tarojs/shared'
8
3
  import {
9
4
  createMemo,
@@ -15,6 +10,12 @@ import { ReactMeta } from './app'
15
10
  import { getPageInstance, injectPageInstance } from './page'
16
11
  import { HOOKS_APP_ID } from './utils'
17
12
 
13
+ import type {
14
+ AppInstance,
15
+ PageLifeCycle,
16
+ TFunc
17
+ } from '@tarojs/runtime'
18
+
18
19
  const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
19
20
  return (fn: TFunc) => {
20
21
  const id = ReactMeta.PageContext || HOOKS_APP_ID
@@ -30,10 +31,13 @@ const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
30
31
  })
31
32
  }
32
33
 
33
- if (isFunction(inst![lifecycle])) {
34
- inst![lifecycle] = [inst?.[lifecycle], fn]
34
+ if (isFunction(inst[lifecycle])) {
35
+ inst[lifecycle] = [inst[lifecycle], fn]
35
36
  } else {
36
- inst![lifecycle] = [...(inst![lifecycle] || []), fn]
37
+ inst[lifecycle] = [
38
+ ...((inst[lifecycle]) || []),
39
+ fn
40
+ ]
37
41
  }
38
42
 
39
43
  if (first) {
@@ -43,9 +47,9 @@ const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
43
47
  onCleanup(() => {
44
48
  const list = inst![lifecycle]
45
49
  if (list === fn) {
46
- inst![lifecycle] = undefined
50
+ (inst[lifecycle]) = undefined
47
51
  } else if (isArray(list)) {
48
- inst![lifecycle] = list.filter((item) => item !== fn)
52
+ (inst[lifecycle]) = list.filter(item => item !== fn)
49
53
  }
50
54
  })
51
55
  })
@@ -58,6 +62,7 @@ export const useDidShow = createTaroHook('componentDidShow')
58
62
 
59
63
  /** App */
60
64
  export const useError = createTaroHook('onError')
65
+ export const useUnhandledRejection = createTaroHook('onUnhandledRejection')
61
66
  export const useLaunch = createTaroHook('onLaunch')
62
67
  export const usePageNotFound = createTaroHook('onPageNotFound')
63
68
 
@@ -1,8 +1,12 @@
1
1
  import { hooks } from '@tarojs/shared'
2
2
 
3
- // declare const __TARO_FRAMEWORK__: string;
3
+ import * as taroHooks from './hooks'
4
4
 
5
- hooks.tap('initNativeApi', function (_taro) {})
5
+ hooks.tap('initNativeApi', function (taro) {
6
+ for (const hook in taroHooks) {
7
+ taro[hook] = taroHooks[hook]
8
+ }
9
+ })
6
10
 
7
11
  export * from './app'
8
12
  export * from './connect'
@@ -1,13 +1,16 @@
1
- import { Current } from '@tarojs/runtime'
2
- import { isArray, isFunction, isUndefined } from '@tarojs/shared'
1
+ import { addLeadingSlash, CONTEXT_ACTIONS, Current, document, env, eventCenter, requestAnimationFrame, window } from '@tarojs/runtime'
2
+ import { hooks, isArray, isFunction, isUndefined } from '@tarojs/shared'
3
3
 
4
- import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './contant'
4
+ import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './constant'
5
5
  import { incrementId } from './utils'
6
6
 
7
+ import type { PageConfig } from '@tarojs/taro'
8
+
7
9
  const instances = new Map<string, any>()
8
- const pageId = incrementId()
10
+ const pageId = incrementId(1)
9
11
 
10
12
  export function injectPageInstance (inst: any, id: string) {
13
+ hooks.call('mergePageInstance', instances.get(id), inst)
11
14
  instances.set(id, inst)
12
15
  }
13
16
 
@@ -19,13 +22,6 @@ export function removePageInstance (id: string) {
19
22
  instances.delete(id)
20
23
  }
21
24
 
22
- export function addLeadingSlash (path?: string): string {
23
- if (path == null) {
24
- return ''
25
- }
26
- return path.charAt(0) === '/' ? path : '/' + path
27
- }
28
-
29
25
  export function safeExecute (path: string, lifecycle: string, ...args: unknown[]) {
30
26
  const instance = instances.get(path)
31
27
 
@@ -33,6 +29,7 @@ export function safeExecute (path: string, lifecycle: string, ...args: unknown[]
33
29
  return
34
30
  }
35
31
 
32
+ lifecycle = lifecycle.replace(/^on(Show|Hide)$/, 'componentDid$1')
36
33
  const func = instance[lifecycle]
37
34
 
38
35
  if (isArray(func)) {
@@ -75,9 +72,19 @@ export function getOnHideEventKey (path: string) {
75
72
  return path + '.' + ON_HIDE
76
73
  }
77
74
 
78
- export function createPageConfig (component: any, pageName?: string) {
75
+ export function createPageConfig (component: any, pageName?: string, pageConfig?: PageConfig) {
79
76
  // 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上
80
77
  const id = pageName ?? `taro_page_${pageId()}`
78
+ const [
79
+ ONLOAD,
80
+ ONUNLOAD,
81
+ ONREADY,
82
+ ONSHOW,
83
+ ONHIDE,
84
+ LIFECYCLES,
85
+ SIDE_EFFECT_LIFECYCLES,
86
+ ] = hooks.call('getMiniLifecycleImpl')!.page
87
+
81
88
  let pageElement: any = null
82
89
  let unmounting = false
83
90
  let prepareMountList: (() => void)[] = []
@@ -102,7 +109,7 @@ export function createPageConfig (component: any, pageName?: string) {
102
109
  let loadResolver: (...args: any[]) => void
103
110
  let hasLoaded: Promise<void>
104
111
  const page = {
105
- onLoad (options: Readonly<Record<string, unknown>> = {}, cb?: (...args: any[]) => any) {
112
+ [ONLOAD] (options: Readonly<Record<string, unknown>> = {}, cb?: (...args: any[]) => any) {
106
113
  hasLoaded = new Promise(resolve => { loadResolver = resolve })
107
114
 
108
115
  Current.page = this as any
@@ -118,21 +125,21 @@ export function createPageConfig (component: any, pageName?: string) {
118
125
 
119
126
  setCurrentRouter(this)
120
127
 
121
- // window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
128
+ window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
122
129
 
123
130
  const mount = () => {
131
+ // @ts-ignore
124
132
  Current.app!.mount!(component, $taroPath, () => {
125
- // pageElement = document.getElementById($taroPath)
133
+ pageElement = document.getElementById($taroPath)
126
134
 
127
- // if (!pageElement) {
128
- // throw new Error(`没有找到页面实例。`)
129
- // }
135
+ if (!pageElement) {
136
+ throw new Error(`没有找到页面实例。`)
137
+ }
130
138
 
131
139
  safeExecute($taroPath, ON_LOAD, this.$taroParams)
132
140
  loadResolver()
133
- cb && cb()
134
- // pageElement.ctx = this
135
- // pageElement.performUpdate(true, cb)
141
+ cb && cb(pageElement)
142
+ pageElement.ctx = this
136
143
  })
137
144
  }
138
145
 
@@ -142,10 +149,10 @@ export function createPageConfig (component: any, pageName?: string) {
142
149
  mount()
143
150
  }
144
151
  },
145
- onUnLoad () {
152
+ [ONUNLOAD] () {
146
153
  const $taroPath = this.$taroPath
147
154
  // 销毁当前页面的上下文信息
148
- // window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
155
+ window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
149
156
 
150
157
  // 触发onUnload生命周期
151
158
  safeExecute($taroPath, ON_UNLOAD)
@@ -163,22 +170,31 @@ export function createPageConfig (component: any, pageName?: string) {
163
170
  }
164
171
  })
165
172
  },
166
- onShow (options = {}) {
173
+ [ONREADY] () {
174
+ hasLoaded.then(() => {
175
+ // 触发生命周期
176
+ safeExecute(this.$taroPath, ON_READY)
177
+ // 通过事件触发子组件的生命周期
178
+ requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
179
+ this.onReady.called = true
180
+ })
181
+ },
182
+ [ONSHOW] (options = {}) {
167
183
  hasLoaded.then(() => {
168
184
  // 设置 Current 的 page 和 router
169
185
  Current.page = this as any
170
186
  setCurrentRouter(this)
171
187
  // 恢复上下文信息
172
- // window.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath)
188
+ window.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath)
173
189
  // 触发生命周期
174
190
  safeExecute(this.$taroPath, ON_SHOW, options)
175
- // TODO 通过事件触发子组件的生命周期
176
- // raf(() => eventCenter.trigger(getOnShowEventKey(id)))
191
+ // 通过事件触发子组件的生命周期
192
+ requestAnimationFrame(() => eventCenter.trigger(getOnShowEventKey(id)))
177
193
  })
178
194
  },
179
- onHide () {
195
+ [ONHIDE] () {
180
196
  // 缓存当前页面上下文信息
181
- // window.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath)
197
+ window.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath)
182
198
 
183
199
  // 设置 Current 的 page 和 router
184
200
  if (Current.page === this) {
@@ -188,9 +204,46 @@ export function createPageConfig (component: any, pageName?: string) {
188
204
  // 触发生命周期
189
205
  safeExecute(this.$taroPath, ON_HIDE)
190
206
  // TODO 通过事件触发子组件的生命周期
191
- // eventCenter.trigger(getOnHideEventKey(id))
192
- }
207
+ eventCenter.trigger(getOnHideEventKey(id))
208
+ },
193
209
  }
194
210
 
211
+ LIFECYCLES.forEach((lifecycle) => {
212
+ let isDefer = false
213
+ lifecycle = lifecycle.replace(/^defer:/, () => {
214
+ isDefer = true
215
+ return ''
216
+ })
217
+ page[lifecycle] = function () {
218
+ const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments)
219
+ if (isDefer) {
220
+ hasLoaded.then(exec)
221
+ } else {
222
+ return exec()
223
+ }
224
+ }
225
+ })
226
+
227
+ // onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
228
+ SIDE_EFFECT_LIFECYCLES.forEach(lifecycle => {
229
+ if (component[lifecycle] ||
230
+ component.prototype?.[lifecycle] ||
231
+ component[lifecycle.replace(/^on/, 'enable')] ||
232
+ pageConfig?.[lifecycle.replace(/^on/, 'enable')]
233
+ ) {
234
+ page[lifecycle] = function (...args) {
235
+ const target = args[0]?.target as any
236
+ if (target?.id) {
237
+ const id = target.id
238
+ const element = env.document.getElementById(id)
239
+ if (element) {
240
+ target.dataset = element.dataset
241
+ }
242
+ }
243
+ return safeExecute(this.$taroPath, lifecycle, ...args)
244
+ }
245
+ }
246
+ })
247
+
195
248
  return page
196
249
  }
@@ -1,31 +1,35 @@
1
1
  import { convertNumber2PX, FormElement } from '@tarojs/runtime'
2
- import { capitalize, internalComponents, isFunction, isNumber, isObject, isString, toCamelCase } from '@tarojs/shared'
2
+ import { capitalize, internalComponents, isFunction, isNumber, isObject, isString, PLATFORM_TYPE, toCamelCase } from '@tarojs/shared'
3
3
 
4
4
  import type { Style, TaroElement } from '@tarojs/runtime'
5
5
 
6
6
  export type Props = Record<string, unknown>
7
7
 
8
+ const IS_NON_DIMENSIONAL = /max|aspect|acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i
9
+
8
10
  function isEventName (s: string) {
9
11
  return s[0] === 'o' && s[1] === 'n'
10
12
  }
11
13
 
12
- const IS_NON_DIMENSIONAL = /max|aspect|acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i
14
+ function isEqual (obj1, obj2) {
15
+ return JSON.stringify(obj1) === JSON.stringify(obj2)
16
+ }
13
17
 
14
18
  export function updateProps (dom: TaroElement, oldProps: Props, newProps: Props) {
15
19
  const updatePayload = getUpdatePayload(dom, oldProps, newProps)
16
- if (updatePayload){
20
+ if (updatePayload) {
17
21
  updatePropsByPayload(dom, oldProps, updatePayload)
18
22
  }
19
23
  }
20
24
 
21
- export function updatePropsByPayload (dom: TaroElement, oldProps: Props, updatePayload: any[]){
22
- for (let i = 0; i < updatePayload.length; i += 2){ // key, value 成对出现
23
- const key = updatePayload[i]; const newProp = updatePayload[i+1]; const oldProp = oldProps[key]
25
+ export function updatePropsByPayload (dom: TaroElement, oldProps: Props, updatePayload: any[]) {
26
+ for (let i = 0; i < updatePayload.length; i += 2) { // key, value 成对出现
27
+ const key = updatePayload[i]; const newProp = updatePayload[i + 1]; const oldProp = oldProps[key]
24
28
  setProperty(dom, key, newProp, oldProp)
25
29
  }
26
30
  }
27
31
 
28
- export function getUpdatePayload (dom: TaroElement, oldProps: Props, newProps: Props){
32
+ export function getUpdatePayload (dom: TaroElement, oldProps: Props, newProps: Props) {
29
33
  let i: string
30
34
  let updatePayload: any[] | null = null
31
35
 
@@ -59,36 +63,40 @@ function setEvent (dom: TaroElement, name: string, value: unknown, oldValue?: un
59
63
 
60
64
  const compName = capitalize(toCamelCase(dom.tagName.toLowerCase()))
61
65
 
62
- if (eventName === 'click' && compName in internalComponents) {
66
+ if (eventName === 'click' && process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY && compName in internalComponents) {
63
67
  eventName = 'tap'
64
68
  }
65
69
 
66
70
  if (isFunction(value)) {
67
- const isHarmony = process.env.TARO_PLATFORM === 'harmony'
68
71
  if (oldValue) {
69
- dom.removeEventListener(eventName, oldValue as any, !isHarmony ? false : undefined)
70
- dom.addEventListener(eventName, value, !isHarmony ? { isCapture, sideEffect: false } : undefined)
72
+ dom.removeEventListener(eventName, oldValue as any, process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY ? false : undefined)
73
+ dom.addEventListener(eventName, value, process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY ? { isCapture, sideEffect: false } : undefined)
71
74
  } else {
72
- dom.addEventListener(eventName, value, !isHarmony ? isCapture : undefined)
75
+ dom.addEventListener(eventName, value, process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY ? isCapture : undefined)
73
76
  }
74
77
  } else {
75
78
  dom.removeEventListener(eventName, oldValue as any)
76
79
  }
77
80
  }
78
81
 
79
- function setStyle (style: Style, key: string, value: string | number) {
80
- if (key[0] === '-') {
81
- style.setProperty(key, value.toString())
82
+ function setStyle (style: Style, key: string, value: unknown) {
83
+ if (key[0] === '-' && process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY) {
82
84
  // css variables need not further judgment
85
+ style.setProperty(key, (value as string).toString())
83
86
  return
84
87
  }
85
88
 
86
- style[key] =
87
- isNumber(value) && IS_NON_DIMENSIONAL.test(key) === false
88
- ? convertNumber2PX(value)
89
- : value == null
90
- ? ''
91
- : value
89
+ if (process.env.TARO_PLATFORM === PLATFORM_TYPE.HARMONY && key.startsWith('_')) {
90
+ // harmony样式已处理
91
+ style[key] = value == null ? '' : value
92
+ } else {
93
+ style[key] =
94
+ isNumber(value) && IS_NON_DIMENSIONAL.test(key) === false
95
+ ? convertNumber2PX(value)
96
+ : value == null
97
+ ? ''
98
+ : value
99
+ }
92
100
  }
93
101
 
94
102
  type StyleValue = Record<string, string | number>
@@ -99,13 +107,9 @@ interface DangerouslySetInnerHTML {
99
107
  export function setProperty (dom: TaroElement, name: string, value: unknown, oldValue?: unknown) {
100
108
  name = name === 'className' ? 'class' : name
101
109
 
102
- if (
103
- name === 'key' ||
104
- name === 'children' ||
105
- name === 'ref'
106
- ) {
107
- // skip
108
- } else if (name === 'style') {
110
+ if (['key', 'children', 'ref'].includes(name)) return
111
+
112
+ if (name === 'style') {
109
113
  const style = dom.style
110
114
  if (isString(value)) {
111
115
  style.cssText = value
@@ -118,6 +122,7 @@ export function setProperty (dom: TaroElement, name: string, value: unknown, old
118
122
  if (isObject<StyleValue>(oldValue)) {
119
123
  for (const i in oldValue) {
120
124
  if (!(value && i in (value as StyleValue))) {
125
+ // harmony设置style,路径设置路径如下:dom.style => cssStyleDeclaration.setProperty => convertWebStyle2HmStyle => dom._st.hmStyle
121
126
  setStyle(style, i, '')
122
127
  }
123
128
  }
@@ -125,12 +130,40 @@ export function setProperty (dom: TaroElement, name: string, value: unknown, old
125
130
 
126
131
  if (isObject<StyleValue>(value)) {
127
132
  for (const i in value) {
128
- if (!oldValue || value[i] !== (oldValue as StyleValue)[i]) {
133
+ if (!oldValue || !isEqual(value[i], (oldValue as StyleValue)[i])) {
129
134
  setStyle(style, i, value[i])
130
135
  }
131
136
  }
132
137
  }
133
138
  }
139
+ } else if (name === '__hmStyle') {
140
+ // 鸿蒙样式特殊处理
141
+ // @ts-ignore
142
+ const style = dom._st.hmStyle // __hmStyle是已经被处理过的鸿蒙样式,可以直接塞进hmStyle对象内
143
+ if (isObject<StyleValue>(oldValue)) {
144
+ for (const i in oldValue) {
145
+ if (!(value && i in (value as StyleValue))) {
146
+ // 鸿蒙伪类特殊处理
147
+ if (process.env.TARO_PLATFORM === PLATFORM_TYPE.HARMONY && (i === '::after' || i === '::before')) {
148
+ setPseudo(dom, i, null)
149
+ } else {
150
+ style[i] = ''
151
+ }
152
+ }
153
+ }
154
+ }
155
+ if (isObject<StyleValue>(value)) {
156
+ for (const i in value) {
157
+ if (!oldValue || !isEqual(value[i], (oldValue as StyleValue)[i])) {
158
+ // 鸿蒙伪类特殊处理
159
+ if (process.env.TARO_PLATFORM === PLATFORM_TYPE.HARMONY && (i === '::after' || i === '::before')) {
160
+ setPseudo(dom, i, value[i] as unknown as StyleValue)
161
+ } else {
162
+ style[i] = value[i]
163
+ }
164
+ }
165
+ }
166
+ }
134
167
  } else if (isEventName(name)) {
135
168
  setEvent(dom, name, value, oldValue)
136
169
  } else if (name === 'dangerouslySetInnerHTML') {
@@ -149,3 +182,14 @@ export function setProperty (dom: TaroElement, name: string, value: unknown, old
149
182
  }
150
183
  }
151
184
  }
185
+
186
+ // 设置鸿蒙伪类属性(特殊设置)
187
+ function setPseudo(dom: TaroElement, name: '::after' | '::before', value: StyleValue | null) {
188
+ if (name === '::after') {
189
+ // @ts-ignore
190
+ dom.set_pseudo_after(value)
191
+ } else if (name === '::before') {
192
+ // @ts-ignore
193
+ dom.set_pseudo_before(value)
194
+ }
195
+ }
@@ -1,5 +1,7 @@
1
- import TaroText from '@tarojs/components/text'
1
+ // @ts-ignore
2
+ import { TaroText } from '@tarojs/components'
2
3
  import { document } from '@tarojs/runtime'
4
+ import { isFunction, isString } from '@tarojs/shared'
3
5
  import { createRenderer } from 'solid-js/universal'
4
6
 
5
7
  import { h } from './h'
@@ -46,11 +48,10 @@ const renderer = createRenderer<TaroNode>({
46
48
  export const render = renderer.render
47
49
  export const effect = renderer.effect
48
50
  export const memo = renderer.memo
49
- export const createComponent = (type, props) => {
50
- if (typeof type === 'string') {
51
- return h(type, props)
52
- }
53
- return renderer.createComponent(type, props)
51
+ export const createComponent = (type, props?) => {
52
+ if (isString(type)) return h(type, props)
53
+ if (isFunction(type)) return renderer.createComponent(type, props)
54
+ return renderer.createComponent(Fragment, props)
54
55
  }
55
56
  export const createElement = renderer.createElement
56
57
  export const createTextNode = renderer.createTextNode
@@ -59,3 +60,12 @@ export const insert = renderer.insert
59
60
  export const spread = renderer.spread
60
61
  export const setProp = renderer.setProp
61
62
  export const mergeProps = renderer.mergeProps
63
+
64
+ function Fragment(props) {
65
+ return props.children
66
+ }
67
+ function jsx(type, props) {
68
+ return createComponent(type, props)
69
+ }
70
+
71
+ export { Fragment, jsx, jsx as jsxDEV, jsx as jsxs }
@@ -5,4 +5,3 @@ export function use(fn, ele, accessor) {
5
5
  fn(ele, accessor)
6
6
  })
7
7
  }
8
-
@@ -9,9 +9,9 @@ export function capitalize (s: string) {
9
9
  return s.charAt(0).toUpperCase() + s.slice(1)
10
10
  }
11
11
 
12
- export const incrementId = () => {
13
- let n = 0
14
- return () => (n++).toString()
12
+ export const incrementId = (init = 0) => {
13
+ let n = init
14
+ return () => n++
15
15
  }
16
16
 
17
17
  export const EMPTY_OBJ: any = {}
@@ -45,5 +45,3 @@ export function setRouterParams(options) {
45
45
  ...options,
46
46
  }
47
47
  }
48
-
49
-