@tarojs/plugin-platform-harmony-ets 4.0.0-canary.8 → 4.0.0

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 (135) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +23 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/media/image/index.ts +169 -17
  7. package/dist/apis/network/request.ts +5 -5
  8. package/dist/apis/route/index.ts +15 -0
  9. package/dist/apis/storage/index.ts +146 -78
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +2 -1
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +5 -5
  16. package/dist/apis/ui/tab-bar.ts +3 -3
  17. package/dist/apis/utils/index.ts +21 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/index.ts +2 -0
  21. package/dist/apis/wxml/selectorQuery.ts +26 -13
  22. package/dist/components-harmony-ets/button.ets +63 -77
  23. package/dist/components-harmony-ets/canvas.ets +51 -0
  24. package/dist/components-harmony-ets/checkbox.ets +75 -258
  25. package/dist/components-harmony-ets/form.ets +51 -158
  26. package/dist/components-harmony-ets/icon.ets +33 -83
  27. package/dist/components-harmony-ets/image.ets +35 -79
  28. package/dist/components-harmony-ets/index.ets +92 -0
  29. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  30. package/dist/components-harmony-ets/input.ets +64 -101
  31. package/dist/components-harmony-ets/label.ets +72 -174
  32. package/dist/components-harmony-ets/listView.ets +31 -0
  33. package/dist/components-harmony-ets/movableArea.ets +126 -0
  34. package/dist/components-harmony-ets/movableView.ets +93 -0
  35. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  36. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  37. package/dist/components-harmony-ets/picker.ets +46 -163
  38. package/dist/components-harmony-ets/progress.ets +52 -0
  39. package/dist/components-harmony-ets/pseudo.ets +80 -0
  40. package/dist/components-harmony-ets/radio.ets +80 -264
  41. package/dist/components-harmony-ets/richText.ets +20 -102
  42. package/dist/components-harmony-ets/scrollList.ets +108 -0
  43. package/dist/components-harmony-ets/scrollView.ets +71 -160
  44. package/dist/components-harmony-ets/slider.ets +22 -82
  45. package/dist/components-harmony-ets/stickySection.ets +42 -0
  46. package/dist/components-harmony-ets/style.ets +410 -0
  47. package/dist/components-harmony-ets/swiper.ets +64 -87
  48. package/dist/components-harmony-ets/switch.ets +39 -99
  49. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  50. package/dist/components-harmony-ets/text.ets +111 -113
  51. package/dist/components-harmony-ets/textArea.ets +51 -95
  52. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  53. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  54. package/dist/components-harmony-ets/utils/flexManager.ets +50 -19
  55. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  56. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  57. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  58. package/dist/components-harmony-ets/utils/index.ts +54 -50
  59. package/dist/components-harmony-ets/utils/styles.ets +172 -92
  60. package/dist/components-harmony-ets/video.ets +37 -88
  61. package/dist/components-harmony-ets/view.ets +63 -159
  62. package/dist/components-harmony-ets/webView.ets +41 -98
  63. package/dist/index.d.ts +152 -0
  64. package/dist/index.js +187 -56
  65. package/dist/index.js.map +1 -1
  66. package/dist/runtime-ets/bom/document.ts +6 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  68. package/dist/runtime-ets/bom/window.ts +9 -2
  69. package/dist/runtime-ets/current.ts +5 -1
  70. package/dist/runtime-ets/dom/bind.ts +28 -12
  71. package/dist/runtime-ets/dom/class-list.ts +2 -2
  72. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  73. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  74. package/dist/runtime-ets/dom/document.ts +22 -8
  75. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  76. package/dist/runtime-ets/dom/element/element.ts +376 -57
  77. package/dist/runtime-ets/dom/element/form.ts +31 -26
  78. package/dist/runtime-ets/dom/element/index.ts +30 -2
  79. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  80. package/dist/runtime-ets/dom/element/movableView.ts +248 -0
  81. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  82. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  83. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  84. package/dist/runtime-ets/dom/element/text.ts +1 -8
  85. package/dist/runtime-ets/dom/element/video.ts +5 -4
  86. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  87. package/dist/runtime-ets/dom/event.ts +3 -5
  88. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  89. package/dist/runtime-ets/dom/node.ts +65 -32
  90. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  91. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  92. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  93. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  94. package/dist/runtime-ets/index.ts +2 -2
  95. package/dist/runtime-ets/interface/event.ts +1 -1
  96. package/dist/runtime-ets/utils/index.ts +74 -13
  97. package/dist/runtime-ets/utils/info.ts +2 -2
  98. package/dist/runtime-framework/react/app.ts +25 -30
  99. package/dist/runtime-framework/react/hooks.ts +3 -4
  100. package/dist/runtime-framework/react/index.ts +0 -2
  101. package/dist/runtime-framework/react/native-page.ts +219 -82
  102. package/dist/runtime-framework/react/page.ts +6 -10
  103. package/dist/runtime-framework/react/utils/index.ts +3 -3
  104. package/dist/runtime-framework/solid/app.ts +30 -46
  105. package/dist/runtime-framework/solid/connect.ts +21 -3
  106. package/dist/runtime-framework/solid/hooks.ts +17 -12
  107. package/dist/runtime-framework/solid/index.ts +6 -2
  108. package/dist/runtime-framework/solid/page.ts +85 -31
  109. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  110. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  111. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  112. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  113. package/dist/runtime-utils.d.ts +827 -0
  114. package/dist/runtime-utils.js +618 -245
  115. package/dist/runtime-utils.js.map +1 -1
  116. package/dist/runtime.d.ts +1 -0
  117. package/dist/runtime.js +618 -245
  118. package/dist/runtime.js.map +1 -1
  119. package/index.js +3 -1
  120. package/package.json +14 -15
  121. package/static/media/cancel.svg +1 -1
  122. package/static/media/circle.svg +1 -1
  123. package/static/media/clear.svg +1 -1
  124. package/static/media/download.svg +1 -1
  125. package/static/media/info.svg +1 -1
  126. package/static/media/info_circle.svg +1 -1
  127. package/static/media/search.svg +1 -1
  128. package/static/media/success.svg +1 -1
  129. package/static/media/success_no_circle.svg +1 -1
  130. package/static/media/warn.svg +1 -1
  131. package/types/harmony.d.ts +5 -0
  132. package/types/index.d.ts +4 -0
  133. package/types/runtime.d.ts +3 -1
  134. package/dist/runtime-ets/utils/bind.ts +0 -24
  135. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,11 +1,15 @@
1
1
  // @ts-nocheck
2
- import matrix4 from '@ohos.matrix4'
2
+ // import matrix4 from '@ohos.matrix4'
3
3
 
4
4
  export interface HarmonyStyle extends TaroStyleType {
5
5
  textAlign?: TextAlign
6
6
  textOverflow?: HarmonyType.Overflow
7
7
  WebkitLineClamp?: number
8
+ whiteSpace?: string
8
9
  letterSpacing?: number | string
10
+ verticalAlign?: Alignment
11
+ lineHeight?: Length
12
+ wordBreak?: string
9
13
  }
10
14
 
11
15
  export interface TaroStyleType {
@@ -30,11 +34,14 @@ export interface TaroStyleType {
30
34
  maxWidth?: Length
31
35
 
32
36
  display?: 'flex' | 'block' | 'none'
37
+ visibility?: 'visible' | 'hidden'
33
38
 
34
39
  // position
35
40
  position?: 'relative' | 'absolute' | 'fixed'
36
- top?: Length
37
- left?: Length
41
+ top?: Dimension
42
+ left?: Dimension
43
+ bottom?: Dimension
44
+ right?: Dimension
38
45
 
39
46
  // flex
40
47
  flexBasis?: number | string
@@ -54,6 +61,10 @@ export interface TaroStyleType {
54
61
  backgroundSize?: SizeOptions | ImageSize
55
62
  backgroundPosition?: Position | Alignment
56
63
 
64
+ // 渐变
65
+ linearGradient?: HarmonyType.LinearGradient
66
+ radialGradient?: HarmonyType.RadialGradient
67
+
57
68
  // transform
58
69
  rotate?: HarmonyType.Transform.Rotate
59
70
  translate?: HarmonyType.Transform.Translate
@@ -89,24 +100,46 @@ export interface TaroStyleType {
89
100
  fontStyle?: FontStyle
90
101
  fontWeight?: number | FontWeight | string
91
102
  fontFamily?: string | Resource
92
- lineHeight?: string | number | Resource
93
- textDecoration?: TextDecorationType
103
+ textDecoration?: {
104
+ type: TextDecorationType
105
+ }
94
106
 
95
- // gradient
96
- linearGradient?: HarmonyType.LinearGradient
107
+ // animation
108
+ animationName?: {
109
+ percentage: number
110
+ event: TaroStyleType
111
+ }[]
112
+ animationDuration?: number
113
+ animationTimingFunction?: string
114
+ animationDelay?: number
115
+ animationIterationCount?: number
116
+
117
+ // shadow
118
+ boxShadow?: {
119
+ radius: number
120
+ color?: string
121
+ offsetX?: number
122
+ offsetY?: number
123
+ fill?: boolean
124
+ }
97
125
 
98
126
  // other
99
127
  opacity?: number | Resource
100
128
  zIndex?: number
101
- overflow?: boolean
129
+ overflow?: string
102
130
  focus?: boolean
131
+ content?: string
103
132
  }
104
133
 
105
134
  export interface TaroTextStyleType {
106
135
  textAlign?: TextAlign
107
136
  textOverflow?: HarmonyType.Overflow
108
137
  WebkitLineClamp?: number
138
+ whiteSpace?: string
109
139
  letterSpacing?: number | string
140
+ verticalAlign?: Alignment
141
+ lineHeight?: string | number | Resource
142
+ wordBreak?: WordBreak
110
143
  }
111
144
 
112
145
  export namespace HarmonyType {
@@ -121,6 +154,12 @@ export namespace HarmonyType {
121
154
  colors: Array<[ResourceColor, number]>
122
155
  repeating?: boolean
123
156
  }
157
+ export interface RadialGradient {
158
+ center: any
159
+ radius: number | string
160
+ colors: Array<[ResourceColor, number]>
161
+ repeating?: boolean
162
+ }
124
163
  export interface Overflow {
125
164
  overflow: TextOverflow
126
165
  }
@@ -134,7 +173,6 @@ export namespace HarmonyType {
134
173
  export interface backgroundImage {
135
174
  src: ResourceStr
136
175
  repeat?: ImageRepeat
137
- colors?: Array<[ResourceColor, number]>
138
176
  }
139
177
  export type backgroundImageSize = SizeOptions | ImageSize
140
178
  export type backgroundImagePosition = Position | Alignment
@@ -166,7 +204,11 @@ export namespace HarmonyType {
166
204
  centerX?: number | string
167
205
  centerY?: number | string
168
206
  }
169
- export type Transform = matrix4.Matrix4Transit
207
+ // export type Transform = matrix4.Matrix4Transit
208
+ export type Transform = {
209
+ Translate?: Translate
210
+ Scale?: Scale
211
+ Rotate?: Rotate
212
+ }
170
213
  }
171
214
  }
172
-
@@ -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
@@ -184,53 +183,53 @@ export class BORDER_STYLE_MAP {
184
183
  case BorderStyle.Solid: return 'solid'
185
184
  default: return ''
186
185
  }
187
-
188
186
  }
189
187
  }
190
188
 
191
-
192
189
  export function getNodeMarginOrPaddingData (dataValue: string) {
193
190
  let res: any = {}
194
191
  if (dataValue) {
195
- const values = dataValue.trim().split(new RegExp('\\s+'))
192
+ const values = dataValue.toString().trim().split(new RegExp('\\s+'))
193
+ let val1: string
194
+ let val2: string
196
195
  switch (values.length) {
197
196
  case 1:
198
- res = { top: values[0], right: values[0], bottom: values[0], left: values[0] }
197
+ val1 = getUnit(values[0])
198
+ res = { top: val1, right: val1, bottom: val1, left: val1 }
199
199
  break
200
200
  case 2:
201
- res = { top: values[0], right: values[1], bottom: values[0], left: values[1] }
201
+ val1 = getUnit(values[0])
202
+ val2 = getUnit(values[1])
203
+ res = { top: val1, right: val2, bottom: val1, left: val2 }
202
204
  break
203
205
  case 3:
204
- res = { top: values[0], right: values[1], bottom: values[2], left: values[1] }
206
+ val2 = getUnit(values[1])
207
+ res = { top: getUnit(values[0]), right: val2, bottom: getUnit(values[2]), left: val2 }
205
208
  break
206
209
  case 4:
207
- res = { top: values[0], right: values[1], bottom: values[2], left: values[3] }
210
+ res = { top: getUnit(values[0]), right: getUnit(values[1]), bottom: getUnit(values[2]), left: getUnit(values[3]) }
208
211
  break
209
212
  default:
210
213
  break
211
214
  }
212
- Object.keys(res).forEach(key => {
213
- res[key] = getUnit(res[key]) || 0
214
- })
215
215
  }
216
216
  return res
217
217
  }
218
218
 
219
-
220
219
  export function getUnit (val) {
221
220
  // 空的字符串代表 Reconciler remove 了这个 prop,不进行后面的逻辑了
222
221
  if (val === '') return val
223
222
 
224
- if (/\d+(vp)$/.test(val)) {
223
+ if (/\d+(vp|px)$/.test(val)) {
225
224
  return val
226
225
  } else if (isNumber(val)) {
227
- return convertNumber2VP(parseFloat(val))
226
+ return parseFloat(val) + 'px'
228
227
  }
229
228
  if (val) {
230
229
  // 匹配vw\vh
231
- const exec = val.match(/(\d+)(vw|vh|px)$/)
230
+ const exec = val.match(/(-?\d*(\.\d+)?)(vw|vh)$/)
232
231
  if (exec) {
233
- const [, num, unit] = exec
232
+ const [, num, , unit] = exec
234
233
  return convertNumber2VP(parseFloat(num), unit)
235
234
  }
236
235
  }
@@ -238,19 +237,26 @@ export function getUnit (val) {
238
237
  }
239
238
 
240
239
  export function getTransform(transform) {
240
+ // if (transform) {
241
+ // return transform.reduce((res, item) => {
242
+ // switch (item.type) {
243
+ // case 'Translate': return res.translate(item.value)
244
+ // case 'Scale': return res.scale(item.value)
245
+ // case 'Rotate': return res.rotate(item.value)
246
+ // case 'Matrix': return res.combine(matrix4.init(item.value))
247
+ // }
248
+ // return res
249
+ // }, matrix4.identity())
250
+ // }
251
+ const result = {}
241
252
  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())
253
+ transform.forEach((item) => {
254
+ result[item.type] = item.value
255
+ })
256
+ return result
251
257
  }
252
258
  }
253
259
 
254
260
  export function capitalizeFirstLetter (str: string) {
255
261
  return str.charAt(0).toUpperCase() + str.slice(1)
256
- }
262
+ }
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  import _display from '@ohos.display'
2
- import { pxTransformHelper } from '@tarojs/taro'
2
+ import { getSystemInfoSync, pxTransformHelper } from '@tarojs/taro'
3
3
 
4
4
  import { NodeType } from '../dom/node'
5
5
  import convertWebStyle2HmStyle from '../dom/stylesheet/covertWeb2Hm'
@@ -38,32 +38,90 @@ export function convertNumber2PX (value: number) {
38
38
  return pxTransformHelper(value, 'vp')
39
39
  }
40
40
 
41
- export function convertNumber2VP (value: number, unit = 'px') {
41
+ export function convertNumber2VP (value: number, unit = 'px'): string | number {
42
42
  if (unit === 'vw' || unit === 'vh') {
43
- return (value / 100 * (unit === 'vw' ? display.width: display.height)) + 'px'
43
+ return (value / 100 * (unit === 'vw' ? display.width : display.height)) + 'px'
44
+ }
45
+ if (unit === 'PX') {
46
+ // 特殊单位:相当于PX、pX、Px
47
+ return pxTransformHelper(value, 'PX')
44
48
  }
45
49
  return pxTransformHelper(value, 'vp')
46
50
  }
47
51
 
48
- export function calcDynamicStyle (styleSheet: Record<string, CSSProperties>, classNames: string, style: CSSProperties): CSSProperties {
52
+ export function parseClasses (classNames = ''): string[] {
53
+ if (typeof classNames !== 'string') {
54
+ return []
55
+ }
56
+ return classNames.includes(' ') ? classNames.split(' ') : [classNames]
57
+ }
58
+
59
+ // 合并静态样式,从样式表里面找到对应的样式
60
+ export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames = ''): CSSProperties {
61
+ classNames = classNames || '' // 兼容有些开发者传入了false/null等非字符串类型
49
62
  const obj: CSSProperties[] = []
50
- 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])
63
+
64
+ if (!styleSheet.cache) {
65
+ styleSheet.cache = {}
66
+ }
67
+ const cache: Record<string, CSSProperties> = styleSheet.cache as Record<string, CSSProperties>
68
+
69
+ const classes = parseClasses(classNames)
70
+ if (!classes.length) return {}
71
+ if (classes.length === 1) {
72
+ // 同一个引用
73
+ return styleSheet[classes[0]]
74
+ } else {
75
+ if (cache[classNames]) {
76
+ return cache[classNames]
77
+ } else {
78
+ for (let i = 0; i < classes.length; i++) {
79
+ const className = classes[i]
80
+ if (styleSheet[className]) {
81
+ obj.push(styleSheet[className])
82
+ }
83
+ }
84
+ const result = Object.assign.apply(null, [{}].concat(obj))
85
+
86
+ cache[classNames] = result
87
+
88
+ return result
55
89
  }
56
90
  }
91
+ }
57
92
 
93
+ // 动态样式计算,需要经过web2harmony进行反转
94
+ export function calcDynamicStyle (style: CSSProperties): CSSProperties {
58
95
  if (style) {
59
- obj.push(convertWebStyle2HmStyle(style))
96
+ return convertWebStyle2HmStyle(style)
60
97
  }
61
-
62
- return Object.assign.apply(null, [{}].concat(obj))
98
+ return {}
99
+ }
100
+
101
+ // css env()环境样式获取
102
+ export function __env__(safeAreaType: string, fallback?: string | number) {
103
+ const sysInfo = getSystemInfoSync()
104
+
105
+ switch (safeAreaType) {
106
+ case 'safe-area-inset-top': {
107
+ return sysInfo.safeArea?.top ? `${sysInfo.safeArea?.top}px` : fallback
108
+ }
109
+ case 'safe-area-inset-right': {
110
+ return sysInfo.safeArea?.right ? `${sysInfo.screenWidth - sysInfo.safeArea?.right}px` : fallback
111
+ }
112
+ case 'safe-area-inset-bottom': {
113
+ return sysInfo.safeArea?.bottom ? `${sysInfo.screenHeight - sysInfo.safeArea?.bottom}px` : fallback
114
+ }
115
+ case 'safe-area-inset-left': {
116
+ return sysInfo.safeArea?.left ? `${sysInfo.safeArea?.left}px` : fallback
117
+ }
118
+ }
119
+ return fallback
63
120
  }
64
121
 
65
122
  export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
66
123
  if (!page) return scrollerOrNode
124
+ if (page.cacheData) return page.cacheData
67
125
 
68
126
  const isArrayData = scrollerOrNode instanceof Array
69
127
 
@@ -76,6 +134,10 @@ export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
76
134
  return scrollerOrNode
77
135
  }
78
136
 
137
+ export function ObjectKeys(obj: object): string[] {
138
+ return Object.keys(obj)
139
+ }
140
+
79
141
  export function ObjectAssign(...objects) {
80
142
  return Object.assign.apply(this, [{}].concat(...objects))
81
143
  }
@@ -91,7 +153,6 @@ export function bindFn (fn: any, ctx: any, ...args: any) {
91
153
  }
92
154
  }
93
155
 
94
-
95
156
  // 使用深度优先遍历寻找节点树中对应的子节点,且只需要找到第一个
96
157
  // 通过 selector 判断是 id 还是 selector,从 node 的 id 和 className 属性中寻找
97
158
  export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: true): T[] | null;
@@ -50,7 +50,7 @@ function tapCallbackToNodeAndUpdate (node: TaroElement, eventName: string, callb
50
50
  callback && callback(...eventResult)
51
51
  }
52
52
 
53
- if (!node._isDynamicNode || !node._isCompileMode) {
53
+ if (!node._isDynamicNode && node._isCompileMode) {
54
54
  node.updateComponent()
55
55
  }
56
56
  }
@@ -91,7 +91,7 @@ export function triggerAttributesCallback (node, attributeName) {
91
91
 
92
92
  const value = node._attrs[attributeName]
93
93
  const cb = node._nodeInfo.attributeCallback[attributeName]
94
-
94
+
95
95
  isFunction(cb) && cb(value)
96
96
  }
97
97
 
@@ -5,6 +5,7 @@ import { setReconciler } from './connect'
5
5
  import { injectPageInstance } from './page'
6
6
  import { EMPTY_OBJ, incrementId, isClassComponent } from './utils'
7
7
 
8
+ import type { AppInstance } from '@tarojs/runtime'
8
9
  import type React from 'react'
9
10
 
10
11
  let h: typeof React.createElement
@@ -22,12 +23,15 @@ export const ReactMeta: IReactMeta = {
22
23
  PageContext: EMPTY_OBJ
23
24
  }
24
25
 
25
- const pageKeyId = incrementId()
26
+ const pageKeyId = incrementId(1)
26
27
 
27
28
  export function connectReactPage (
28
29
  R: typeof React,
29
- id: string
30
+ id: string,
31
+ getCtx: () => any
30
32
  ) {
33
+ const ctx = getCtx?.()
34
+
31
35
  return (Page): React.ComponentClass<any> => {
32
36
  // eslint-disable-next-line dot-notation
33
37
  const isReactComponent = isClassComponent(R, Page)
@@ -63,12 +67,12 @@ export function connectReactPage (
63
67
  const children = this.state.hasError
64
68
  ? []
65
69
  : h(ReactMeta.PageContext.Provider, { value: id }, h(Page, {
66
- ...this.props,
70
+ ...Object.assign({}, ctx?.props, this.props),
67
71
  ...refs
68
72
  }))
69
73
 
70
74
  return h(
71
- 'view',
75
+ 'taro-page',
72
76
  { id, className: 'taro_page' },
73
77
  children
74
78
  )
@@ -81,7 +85,7 @@ export function createReactApp (
81
85
  App,
82
86
  react,
83
87
  dom,
84
- _config?: any
88
+ config?: any
85
89
  ) {
86
90
  ReactMeta.R = react
87
91
  h = react.createElement
@@ -103,10 +107,10 @@ export function createReactApp (
103
107
  }
104
108
 
105
109
  function renderReactRoot () {
106
- const appId = 'app'
110
+ const appId = config?.appId || 'app'
107
111
 
108
112
  if (ReactMeta.Container === EMPTY_OBJ) {
109
- const Container = document.createElement('view')
113
+ const Container = document.getElementById(appId)
110
114
 
111
115
  Container.id = appId
112
116
  ReactMeta.Container = Container
@@ -126,9 +130,9 @@ export function createReactApp (
126
130
  appWrapperResolver(this)
127
131
  }
128
132
 
129
- public mount (pageComponent: any, id: string, cb: () => void) {
130
- const pageWrapper = connectReactPage(react, id)(pageComponent)
131
- const key = id + pageKeyId()
133
+ public mount (pageComponent: any, id: string, getCtx: () => any, cb: () => void) {
134
+ const pageWrapper = connectReactPage(react, id, getCtx)(pageComponent)
135
+ const key = `${id}_${pageKeyId()}`
132
136
  const page = () => h(pageWrapper, { key, tid: id })
133
137
  this.pages.push(page)
134
138
  this.forceUpdate(cb)
@@ -169,14 +173,13 @@ export function createReactApp (
169
173
  render (cb: () => void) {
170
174
  appWrapper.forceUpdate(cb)
171
175
  },
172
- mount (component: any, id: string, cb: () => void) {
176
+ mount (component: any, id: string, getCtx: () => any, cb: () => void) {
173
177
  if (appWrapper) {
174
- appWrapper.mount(component, id, cb)
178
+ appWrapper.mount(component, id, getCtx, cb)
175
179
  } else {
176
- appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, cb))
180
+ appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, getCtx, cb))
177
181
  }
178
182
  },
179
-
180
183
  unmount (id: string, cb: () => void) {
181
184
  appWrapper?.unmount(id, cb)
182
185
  },
@@ -193,7 +196,7 @@ export function createReactApp (
193
196
  const keys = Object.keys(globalData)
194
197
  const descriptors = Object.getOwnPropertyDescriptors(globalData)
195
198
  keys.forEach(key => {
196
- Object.defineProperty(this, key, {
199
+ Object.defineProperty(Current?.app || this, key, {
197
200
  configurable: true,
198
201
  enumerable: true,
199
202
  get () {
@@ -204,7 +207,7 @@ export function createReactApp (
204
207
  }
205
208
  })
206
209
  })
207
- Object.defineProperties(this, descriptors)
210
+ Object.defineProperties(Current?.app || this, descriptors)
208
211
  }
209
212
 
210
213
  app.onCreate?.()
@@ -233,21 +236,13 @@ export function createReactApp (
233
236
  app?.componentDidHide?.()
234
237
  })
235
238
  }
236
- }
239
+ } as unknown as AppInstance
237
240
 
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
- // }
249
-
250
- Current.app = app
241
+ if (Current.app) {
242
+ Current.app = Object.assign(app, Current.app)
243
+ } else {
244
+ Current.app = app
245
+ }
251
246
 
252
247
  return app
253
248
  }
@@ -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>>()
@@ -24,7 +24,6 @@ const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
24
24
  if (fnRef.current !== fn) fnRef.current = fn
25
25
 
26
26
  React.useLayoutEffect(() => {
27
-
28
27
  let inst = instRef.current = getPageInstance(id)
29
28
  let first = false
30
29
  if (!inst) {
@@ -2,8 +2,6 @@ import { hooks } from '@tarojs/shared'
2
2
 
3
3
  import * as taroHooks from './hooks'
4
4
 
5
- // declare const __TARO_FRAMEWORK__: string;
6
-
7
5
  hooks.tap('initNativeApi', function (taro) {
8
6
  for (const hook in taroHooks) {
9
7
  taro[hook] = taroHooks[hook]