@tarojs/plugin-platform-harmony-ets 4.0.0-beta.49 → 4.0.0-beta.50

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.
@@ -11,7 +11,8 @@ export function setBackgroundColor(options: Taro.setBackgroundColor.Option) {
11
11
 
12
12
  return new Promise((resolve, reject) => {
13
13
  eventCenter.trigger('__taroPageStyle', {
14
- backgroundColor: options.backgroundColor || options.backgroundColorTop || options.backgroundColorBottom,
14
+ backgroundColor: options.backgroundColorBottom || options.backgroundColor,
15
+ backgroundColorContext: options.backgroundColorTop || options.backgroundColor
15
16
  })
16
17
 
17
18
  return handle.success({}, { resolve, reject })
@@ -153,7 +153,7 @@ export function showActionSheet (options) {
153
153
  reject,
154
154
  {
155
155
  ...data,
156
- errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet')
156
+ errMsg: data.errMsg?.replace('showActionMenu', 'showActionSheet')
157
157
  },
158
158
  options
159
159
  )
@@ -19,7 +19,7 @@ export const setNavigationBarTitle: typeof Taro.setNavigationBarTitle = function
19
19
 
20
20
  export const setNavigationBarColor: typeof Taro.setNavigationBarColor = function (options) {
21
21
  const { success, fail, complete } = options || {}
22
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete })
22
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete })
23
23
 
24
24
  return new Promise((resolve, reject) => {
25
25
  eventCenter.trigger('__taroNavigationStyle', {
@@ -22,6 +22,8 @@ import TaroMovableArea from './movableArea'
22
22
  import TaroMovableView from './movableView'
23
23
  import { TaroRadio, TaroRadioGroup } from './radio'
24
24
  import { TaroCheckboxGroup, TaroCheckbox } from './checkbox'
25
+ import TaroPageMeta from './pageMeta'
26
+ import TaroNavigationBar from './navigationBar'
25
27
 
26
28
  import commonStyleModify, { rowModify, columnModify, textModify, setNormalTextAttributeIntoInstance } from './style'
27
29
  import { getButtonColor } from './button'
@@ -78,4 +80,6 @@ export {
78
80
  TaroRadioGroup,
79
81
  TaroCheckboxGroup,
80
82
  TaroCheckbox,
83
+ TaroPageMeta,
84
+ TaroNavigationBar,
81
85
  }
@@ -35,12 +35,11 @@ function handleTargetChange (id: string) {
35
35
  }
36
36
  }
37
37
 
38
-
39
38
  @Component
40
39
  export default struct TaroLabel {
41
40
  @Builder customBuilder() {}
42
- @BuilderParam createLazyChildren: (node:TaroLabelElement) => void = this.customBuilder
43
- @ObjectLink node:TaroLabelElement
41
+ @BuilderParam createLazyChildren: (node: TaroLabelElement) => void = this.customBuilder
42
+ @ObjectLink node: TaroLabelElement
44
43
  @State overwriteStyle: Record<string, TaroAny> = {}
45
44
 
46
45
  aboutToAppear(): void {
@@ -50,7 +49,6 @@ export default struct TaroLabel {
50
49
  }
51
50
 
52
51
  build() {
53
-
54
52
  if (FlexManager.useFlexLayout(this.node)) {
55
53
  Flex(FlexManager.flexOptions(this.node)) {
56
54
  this.createLazyChildren(this.node)
@@ -0,0 +1,25 @@
1
+ import { isTagFirstChild } from './utils/helper'
2
+
3
+ import type { TaroNavigationBarElement } from '@tarojs/runtime'
4
+
5
+ @Component
6
+ export default struct TaroNavigationBar {
7
+ @Builder customBuilder() {}
8
+ @BuilderParam createLazyChildren: (node: TaroNavigationBarElement) => void = this.customBuilder
9
+ @ObjectLink node: TaroNavigationBarElement
10
+
11
+ aboutToAppear(): void {
12
+ if (!isTagFirstChild(this.node, 'page-meta')) {
13
+ console.error('NavigationBar 只能是 PageMeta 内的第一个节点。')
14
+ }
15
+ if (this.node) {
16
+ this.node._instance = this
17
+ }
18
+ }
19
+
20
+ build() {
21
+ if (true) {
22
+ this.createLazyChildren(this.node)
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,28 @@
1
+ import { APP } from '@tarojs/runtime/dist/runtime.esm'
2
+
3
+ import { isTagFirstChild } from './utils/helper'
4
+
5
+ import type { TaroPageMetaElement } from '@tarojs/runtime'
6
+
7
+ @Component
8
+ export default struct TaroPageMeta {
9
+ @Builder customBuilder() {}
10
+ @BuilderParam createLazyChildren: (node: TaroPageMetaElement) => void = this.customBuilder
11
+ @ObjectLink node: TaroPageMetaElement
12
+
13
+ aboutToAppear(): void {
14
+ if (!isTagFirstChild(this.node, APP, 2)) {
15
+ // PageMeta 只能是页面内的第一个元素
16
+ console.error('PageMeta 只能是页面内的第一个元素。')
17
+ }
18
+ if (this.node) {
19
+ this.node._instance = this
20
+ }
21
+ }
22
+
23
+ build() {
24
+ if (true) {
25
+ this.createLazyChildren(this.node)
26
+ }
27
+ }
28
+ }
@@ -35,6 +35,8 @@ export const TaroAdTagName = 'ad'
35
35
  export const TaroWebViewTagName = 'web-view'
36
36
  export const TaroBlockTagName = 'block'
37
37
  export const TaroMapTagName = 'map'
38
+ export const TaroPageMetaTagName = 'page-meta'
39
+ export const TaroNavigationBarTagName = 'navigation-bar'
38
40
  export const TaroSlotTagName = 'slot'
39
41
  export const TaroNativeSlotTagName = 'native-slot'
40
42
  export const TaroCustomWrapperTagName = 'custom-wrapper'
@@ -1,7 +1,9 @@
1
+ import { VIEW } from '@tarojs/runtime/dist/runtime.esm'
2
+
1
3
  import { getNormalAttributes, getFontAttributes, getStyleAttr } from './styles'
2
4
 
3
5
  import type { TFunc } from '@tarojs/runtime/dist/runtime.esm'
4
- import type { TaroElement } from '@tarojs/runtime'
6
+ import type { TaroElement, TaroNode } from '@tarojs/runtime'
5
7
 
6
8
  export const parseStyles = (styles = ''): Record<string, string> => {
7
9
  const styleObj: Record<string, string> = {}
@@ -34,5 +36,16 @@ export function getNodeThresholds (node: TaroElement): number[] | null {
34
36
  return node?._nodeInfo?.thresholds || null
35
37
  }
36
38
 
39
+ export function isTagFirstChild (node: TaroElement, tagName = VIEW, level = 0): boolean {
40
+ const parent: TaroElement | null = node.parentElement
41
+ const list: TaroNode[] = node.parentNode?.childNodes || []
42
+ if (!parent || list.length < 1 || level < 0) return false
43
+
44
+ if (parent.nodeName === tagName.toUpperCase()) {
45
+ return list[0] === node
46
+ } else {
47
+ return list[0] === node && isTagFirstChild(parent, tagName, --level)
48
+ }
49
+ }
37
50
 
38
51
  export { getNormalAttributes, getFontAttributes, getStyleAttr }
@@ -135,6 +135,12 @@ function getPseudoClass (node: TaroElement): HarmonyStyle | null {
135
135
  }
136
136
  break
137
137
  }
138
+ case "::empty": {
139
+ if (node.children?.length === 0) {
140
+ return pseudoStylesheet.hmStyle
141
+ }
142
+ break
143
+ }
138
144
  default: {
139
145
  // 解析nth-child()
140
146
  // 找出当前节点在父节点中的位置
@@ -1,3 +1,5 @@
1
+ import { APP, BODY, HEAD, HTML } from '@tarojs/runtime/dist/runtime.esm'
2
+
1
3
  import { TaroDocument } from '../dom/document'
2
4
  import { window } from './window'
3
5
 
@@ -15,11 +17,11 @@ function createDocument (): TaroDocument {
15
17
 
16
18
  const doc = new TaroDocument(window)
17
19
  const documentCreateElement = doc.createElement.bind(doc)
18
- const html = documentCreateElement('html')
19
- const head = documentCreateElement('head')
20
- const body = documentCreateElement('body')
20
+ const html = documentCreateElement(HTML)
21
+ const head = documentCreateElement(HEAD)
22
+ const body = documentCreateElement(BODY)
21
23
  const container = documentCreateElement('container') // 多包一层主要为了兼容 vue
22
- const app = documentCreateElement('app')
24
+ const app = documentCreateElement(APP)
23
25
  app.id = 'app'
24
26
 
25
27
  doc.appendChild(html)
@@ -31,7 +33,7 @@ function createDocument (): TaroDocument {
31
33
  doc.documentElement = html
32
34
  doc.head = head
33
35
  doc.body = body
34
-
36
+
35
37
  return doc
36
38
  }
37
39
 
@@ -70,7 +70,7 @@ export function bindAnimation (node: TaroElement) {
70
70
  animateParams.duration = 0
71
71
  }
72
72
  animateParams.curve = Curve[convertToCamelCase(timingFunction)] || Curve.EaseInOut
73
- Current.uiContext.animateTo(animateParams, () => {
73
+ node._instance.getUIContext()?.animateTo(animateParams, () => {
74
74
  const transformOrigin: string = anim.transformOrigin
75
75
  if (transformOrigin) {
76
76
  const splitOrigin = transformOrigin.split(' ')
@@ -403,7 +403,7 @@ export class TaroElement<
403
403
 
404
404
  if (keyframes) {
405
405
  let cur_percentage = 0
406
- Current.uiContext.keyframeAnimateTo({
406
+ this._instance.getUIContext()?.keyframeAnimateTo({
407
407
  delay: animationDelay,
408
408
  iterations: animationIterationCount,
409
409
  }, keyframes.map(item => {
@@ -187,7 +187,7 @@ class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormW
187
187
  }
188
188
 
189
189
  @Observed
190
- class TaroTextAreaElement extends TaroInputElement<TextareaProps>{
190
+ class TaroTextAreaElement extends TaroInputElement<TextareaProps> {
191
191
  controller: TextAreaController = new TextAreaController()
192
192
 
193
193
  constructor() {
@@ -195,14 +195,14 @@ class TaroTextAreaElement extends TaroInputElement<TextareaProps>{
195
195
  }
196
196
  }
197
197
  @Observed
198
- class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps>{
198
+ class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps> {
199
199
  constructor() {
200
200
  super('Checkbox')
201
201
  }
202
202
  }
203
203
 
204
204
  @Observed
205
- class TaroRadioElement extends TaroCheckedElement<RadioProps>{
205
+ class TaroRadioElement extends TaroCheckedElement<RadioProps> {
206
206
  public group?: string
207
207
 
208
208
  constructor() {
@@ -232,7 +232,7 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
232
232
  case 'selector': {
233
233
  const key = this._attrs.rangeKey
234
234
  const item = this._attrs.range[this.value]
235
-
235
+
236
236
  if (key) {
237
237
  return item[key]
238
238
  } else {
@@ -261,7 +261,7 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
261
261
  super.reset()
262
262
 
263
263
  const event: TaroEvent = createTaroEvent('change', { detail: { value: this._reset } }, this)
264
-
264
+
265
265
  event.stopPropagation()
266
266
  eventHandler(event, 'change', this)
267
267
  }
@@ -337,7 +337,7 @@ class TaroFormElement extends TaroFormWidgetElement {
337
337
 
338
338
  findChildNodeWithDFS<TaroFormWidgetElement>(this, item => {
339
339
  if (!item.name) return false
340
-
340
+
341
341
  switch (item.nodeName) {
342
342
  case 'INPUT':
343
343
  case 'RADIO':
@@ -368,9 +368,9 @@ class TaroFormElement extends TaroFormWidgetElement {
368
368
  e.stopPropagation()
369
369
  switch (item.nodeName) {
370
370
  case 'INPUT':
371
- case 'SLIDER':
371
+ case 'SLIDER':
372
372
  case 'PICKER':
373
- case 'RADIO':
373
+ case 'RADIO':
374
374
  case 'SWITCH':
375
375
  case 'CHECKBOX':
376
376
  case 'TEXTAREA':
@@ -22,7 +22,9 @@ import {
22
22
  TaroIconElement,
23
23
  TaroImageElement,
24
24
  TaroLabelElement,
25
+ TaroNavigationBarElement,
25
26
  TaroOtherElement,
27
+ TaroPageMetaElement,
26
28
  TaroRichTextElement,
27
29
  TaroSwiperElement,
28
30
  TaroSwiperItemElement,
@@ -64,6 +66,8 @@ export function initHarmonyElement () {
64
66
  case 'form': return new TaroFormElement()
65
67
  case 'web-view': return new TaroWebViewElement()
66
68
  case 'inner-html': return new TaroInnerHtmlElement()
69
+ case 'page-meta': return new TaroPageMetaElement()
70
+ case 'navigation-bar': return new TaroNavigationBarElement()
67
71
  default: return new TaroOtherElement(tagName)
68
72
  }
69
73
  }
@@ -89,7 +93,9 @@ export {
89
93
  TaroLabelElement,
90
94
  TaroMovableAreaElement,
91
95
  TaroMovableViewElement,
96
+ TaroNavigationBarElement,
92
97
  TaroOtherElement,
98
+ TaroPageMetaElement,
93
99
  TaroPickerElement,
94
100
  TaroProgressElement,
95
101
  TaroRadioElement,
@@ -6,6 +6,8 @@ import type {
6
6
  IconProps,
7
7
  ImageProps,
8
8
  LabelProps,
9
+ NavigationBarProps,
10
+ PageMetaProps,
9
11
  RichTextProps,
10
12
  SwiperItemProps,
11
13
  SwiperProps,
@@ -37,27 +39,27 @@ class TaroButtonElement extends TaroElement<ButtonProps> {
37
39
  }
38
40
 
39
41
  @Observed
40
- class TaroIconElement extends TaroElement<IconProps>{
42
+ class TaroIconElement extends TaroElement<IconProps> {
41
43
  constructor() {
42
44
  super('Icon')
43
45
  }
44
46
  }
45
47
  @Observed
46
- class TaroLabelElement extends TaroElement<LabelProps>{
48
+ class TaroLabelElement extends TaroElement<LabelProps> {
47
49
  constructor() {
48
50
  super('Label')
49
51
  }
50
52
  }
51
53
 
52
54
  @Observed
53
- class TaroRichTextElement extends TaroElement<RichTextProps>{
55
+ class TaroRichTextElement extends TaroElement<RichTextProps> {
54
56
  constructor() {
55
57
  super('RichText')
56
58
  }
57
59
  }
58
60
 
59
61
  @Observed
60
- class TaroSwiperElement extends TaroElement<SwiperProps>{
62
+ class TaroSwiperElement extends TaroElement<SwiperProps> {
61
63
  controller: SwiperController = new SwiperController()
62
64
 
63
65
  constructor() {
@@ -66,18 +68,34 @@ class TaroSwiperElement extends TaroElement<SwiperProps>{
66
68
  }
67
69
 
68
70
  @Observed
69
- class TaroSwiperItemElement extends TaroElement<SwiperItemProps>{
71
+ class TaroSwiperItemElement extends TaroElement<SwiperItemProps> {
70
72
  constructor() {
71
73
  super('SwiperItem')
72
74
  }
73
75
  }
74
76
 
77
+ @Observed
78
+ class TaroPageMetaElement extends TaroElement<PageMetaProps> {
79
+ constructor() {
80
+ super('PageMeta')
81
+ }
82
+ }
83
+
84
+ @Observed
85
+ class TaroNavigationBarElement extends TaroElement<NavigationBarProps> {
86
+ constructor() {
87
+ super('NavigationBar')
88
+ }
89
+ }
90
+
75
91
  export {
76
92
  TaroButtonElement,
77
93
  TaroIconElement,
78
94
  TaroImageElement,
79
95
  TaroLabelElement,
96
+ TaroNavigationBarElement,
80
97
  TaroOtherElement,
98
+ TaroPageMetaElement,
81
99
  TaroRichTextElement,
82
100
  TaroSwiperElement,
83
101
  TaroSwiperItemElement,
@@ -13,13 +13,13 @@ export class TaroInnerHtmlElement extends TaroElement {
13
13
  }
14
14
 
15
15
  @Observed
16
- export class TaroWebViewElement extends TaroElement<WebViewProps>{
16
+ export class TaroWebViewElement extends TaroElement<WebViewProps> {
17
17
  ports: web_webview.WebMessagePort[] = []
18
18
 
19
19
  nativePort: web_webview.WebMessagePort | null = null
20
20
 
21
21
  message: web_webview.WebMessageExt = new web_webview.WebMessageExt()
22
-
22
+
23
23
  controller: web_webview.WebviewController = new web_webview.WebviewController()
24
24
 
25
25
  constructor() {
@@ -62,7 +62,7 @@ export class TaroWebViewElement extends TaroElement<WebViewProps>{
62
62
  }
63
63
  catch (error) {
64
64
  const e: business_error.BusinessError = error as business_error.BusinessError
65
-
65
+
66
66
  console.error(`ErrorCode: ${e.code}, Message: ${e.message}`)
67
67
  }
68
68
  }
@@ -90,7 +90,7 @@ export class TaroNode extends TaroDataSourceElement {
90
90
  return this._nid
91
91
  }
92
92
 
93
- public get firstChild (): TaroNode | null{
93
+ public get firstChild (): TaroNode | null {
94
94
  return this.childNodes[0] || null
95
95
  }
96
96
 
@@ -49,31 +49,39 @@ export function convertNumber2VP (value: number, unit = 'px'): string | number {
49
49
  return pxTransformHelper(value, 'vp')
50
50
  }
51
51
 
52
- export function parseClasses (classNames: string | string[] = []): string[] {
53
- if (typeof classNames === 'string') {
54
- return classNames.includes(' ') ? classNames.split(' ') : [classNames]
55
- } else if (Array.isArray(classNames)) {
56
- return classNames // Note: 不考虑支持单个元素传入多个类名的情况,过于损耗性能
57
- }
58
-
59
- return []
52
+ export function parseClasses (classNames = ''): string[] {
53
+ return classNames.includes(' ') ? classNames.split(' ') : [classNames]
60
54
  }
61
55
 
62
56
  // 合并静态样式,从样式表里面找到对应的样式
63
- export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames: string | string[] = []): CSSProperties {
57
+ export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames = ''): CSSProperties {
64
58
  const obj: CSSProperties[] = []
59
+
60
+ if (!styleSheet.cache) {
61
+ styleSheet.cache = {}
62
+ }
63
+ const cache: Record<string, CSSProperties> = styleSheet.cache as Record<string, CSSProperties>
64
+
65
65
  const classes = parseClasses(classNames)
66
66
  if (classes.length === 1) {
67
67
  // 同一个引用
68
68
  return styleSheet[classes[0]]
69
69
  } else {
70
- for (let i = 0; i < classes.length; i++) {
71
- const className = classes[i]
72
- if (styleSheet[className]) {
73
- obj.push(styleSheet[className])
70
+ if (cache[classNames]) {
71
+ return cache[classNames]
72
+ } else {
73
+ for (let i = 0; i < classes.length; i++) {
74
+ const className = classes[i]
75
+ if (styleSheet[className]) {
76
+ obj.push(styleSheet[className])
77
+ }
74
78
  }
79
+ const result = Object.assign.apply(null, [{}].concat(obj))
80
+
81
+ cache[classNames] = result
82
+
83
+ return result
75
84
  }
76
- return Object.assign.apply(null, [{}].concat(obj))
77
85
  }
78
86
  }
79
87
 
@@ -3601,7 +3601,8 @@ function setBackgroundColor(options) {
3601
3601
  const handle = new MethodHandler({ name: 'setBackgroundColor', success, fail, complete });
3602
3602
  return new Promise((resolve, reject) => {
3603
3603
  eventCenter.trigger('__taroPageStyle', {
3604
- backgroundColor: options.backgroundColor || options.backgroundColorTop || options.backgroundColorBottom,
3604
+ backgroundColor: options.backgroundColorBottom || options.backgroundColor,
3605
+ backgroundColorContext: options.backgroundColorTop || options.backgroundColor
3605
3606
  });
3606
3607
  return handle.success({}, { resolve, reject });
3607
3608
  });
@@ -3724,8 +3725,9 @@ function showActionSheet(options) {
3724
3725
  buttons
3725
3726
  };
3726
3727
  promptAction.showActionMenu(actionSheetOptions, (error, data) => {
3728
+ var _a;
3727
3729
  if (error) {
3728
- callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet') }), options);
3730
+ callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: (_a = data.errMsg) === null || _a === void 0 ? void 0 : _a.replace('showActionMenu', 'showActionSheet') }), options);
3729
3731
  }
3730
3732
  callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
3731
3733
  });
@@ -3761,7 +3763,7 @@ const setNavigationBarTitle = function (options) {
3761
3763
  };
3762
3764
  const setNavigationBarColor = function (options) {
3763
3765
  const { success, fail, complete } = options || {};
3764
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
3766
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
3765
3767
  return new Promise((resolve, reject) => {
3766
3768
  eventCenter.trigger('__taroNavigationStyle', {
3767
3769
  animation: options.animation,