@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.16 → 4.0.0-alpha.18

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.
@@ -6,6 +6,21 @@ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
6
6
 
7
7
  import type { TaroAny, TaroEvent, TaroButtonElement, TaroStyleType } from '@tarojs/runtime'
8
8
 
9
+ interface ButtonAttrs {
10
+ disabled?: boolean
11
+ }
12
+
13
+ @Extend(Button)
14
+ function attrs(attr: ButtonAttrs) {
15
+ .enabled(!attr.disabled)
16
+ }
17
+
18
+ function getAttributes(node: TaroButtonElement): ButtonAttrs {
19
+ return {
20
+ disabled: node._attrs.disabled || false,
21
+ }
22
+ }
23
+
9
24
  @Extend(Button)
10
25
  function themeStyles(style: TaroStyleType) {
11
26
  .fontColor(style.color)
@@ -121,6 +136,7 @@ export default struct TaroButton {
121
136
  }
122
137
  .themeStyles(getThemeAttributes(this.node))
123
138
  .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
139
+ .attrs(getAttributes(this.node))
124
140
  .constraintSize({
125
141
  minWidth: this.node.hmStyle?.minWidth || getButtonMinWidth(this.node),
126
142
  minHeight: this.node.hmStyle?.minHeight || getButtonMinHeight(this.node),
@@ -13,17 +13,20 @@ interface CheckboxOptions {
13
13
  }
14
14
  interface CheckboxAttrs {
15
15
  selectedColor?: ResourceColor
16
+ disabled?: boolean
16
17
  }
17
18
 
18
19
  @Extend(Checkbox)
19
20
  function checkboxAttr(attr: CheckboxAttrs) {
20
21
  .selectedColor(attr.selectedColor)
22
+ .enabled(!attr.disabled)
21
23
  }
22
24
 
23
25
  function getAttributes (node: TaroCheckboxElement): CheckboxAttrs {
24
26
  const _attrs = node._attrs
25
27
  const checkboxAttrs: CheckboxAttrs = {}
26
28
  checkboxAttrs.selectedColor = _attrs.color || '#1aad19'
29
+ checkboxAttrs.disabled = !!_attrs.disabled
27
30
  return checkboxAttrs
28
31
  }
29
32
 
@@ -1,7 +1,7 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
- import { parseStyles, shouldBindEvent, getNodeThresholds } from './utils/helper'
4
+ import { parseStyles, shouldBindEvent, getNodeThresholds, getStyleAttr } from './utils/helper'
5
5
  import { INPUT_TYPE_MAP, INPUT_CONFIRM_MAP } from './utils/constant/style'
6
6
 
7
7
  import type { TaroStyleType, TaroAny, TaroInputElement, TaroEvent } from '@tarojs/runtime'
@@ -9,6 +9,7 @@ import type { TaroStyleType, TaroAny, TaroInputElement, TaroEvent } from '@taroj
9
9
  interface InputAttrs {
10
10
  textAlign?: TextAlign
11
11
  autoFocus?: boolean
12
+ disabled?: boolean
12
13
  }
13
14
 
14
15
  @Extend(TextInput)
@@ -24,12 +25,14 @@ function styles (style: TaroStyleType) {
24
25
  function attrs(attr: InputAttrs) {
25
26
  .textAlign(attr.textAlign)
26
27
  .defaultFocus(attr.autoFocus)
28
+ .enabled(!attr.disabled)
27
29
  }
28
30
 
29
31
  function getAttributes(node: TaroInputElement): InputAttrs {
30
32
  return {
31
33
  textAlign: node.hmStyle.textAlign,
32
34
  autoFocus: node._attrs.autoFocus || node._attrs.focus || false,
35
+ disabled: node._attrs.disabled || false,
33
36
  }
34
37
  }
35
38
 
@@ -75,6 +78,7 @@ export default struct TaroInput {
75
78
  .placeholderColor(getPlaceholderColor(this.node))
76
79
  .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
77
80
  .padding(0) // Note: 移出 Input 默认 padding 设置
81
+ .backgroundColor(getStyleAttr(this.node, "backgroundColor"))//
78
82
  .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
79
83
  .styles(this.node?.hmStyle)
80
84
  .attrs(getAttributes(this.node))
@@ -32,8 +32,8 @@ export default struct TaroMovableArea {
32
32
  }
33
33
  .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
34
34
  .clip(true)
35
- .onAreaChange((oldValue: Area, newValue: Area) => {
36
- areaChangeHandle(this.node, newValue)
35
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
36
+ sizeChangeHandle(this.node, newValue)
37
37
  })
38
38
  .gesture(
39
39
  PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
@@ -59,8 +59,8 @@ export default struct TaroMovableArea {
59
59
  }
60
60
  .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
61
61
  .clip(true)
62
- .onAreaChange((oldValue: Area, newValue: Area) => {
63
- areaChangeHandle(this.node, newValue)
62
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
63
+ sizeChangeHandle(this.node, newValue)
64
64
  })
65
65
  .gesture(
66
66
  PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
@@ -86,8 +86,8 @@ export default struct TaroMovableArea {
86
86
  }
87
87
  .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
88
88
  .clip(true)
89
- .onAreaChange((oldValue: Area, newValue: Area) => {
90
- areaChangeHandle(this.node, newValue)
89
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
90
+ sizeChangeHandle(this.node, newValue)
91
91
  })
92
92
  .gesture(
93
93
  PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
@@ -110,7 +110,9 @@ export default struct TaroMovableArea {
110
110
  }
111
111
  }
112
112
  }
113
- function areaChangeHandle(node: TaroMovableAreaElement,newValue: Area) {
113
+
114
+
115
+ function sizeChangeHandle(node: TaroMovableAreaElement, newValue: Area | SizeOptions) {
114
116
  node.childNodes.forEach(item => {
115
117
  if (isTaroMovableViewElement(item)) {
116
118
  if (item.area?.w !== Number(newValue.width) || item.area?.h !== Number(newValue.height)) {
@@ -41,7 +41,7 @@ export default struct TaroMovableView {
41
41
  }
42
42
  .translate({ x: this.node.position.x, y: this.node.position.y })
43
43
  .scale({ x: this.node.scaleValue, y: this.node.scaleValue })
44
- .onAreaChange((oldValue: Area, newValue: Area) => {
44
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
45
45
  if (this.node.selfSize?.w !== Number(newValue.width) || this.node.selfSize?.h !== Number(newValue.height)) {
46
46
  this.node.selfSize = { w: Number(newValue.width), h: Number(newValue.height) }
47
47
  }
@@ -11,12 +11,14 @@ import { isUndefined } from '@tarojs/shared'
11
11
  interface RadioAttrs {
12
12
  radioStyle?: HarmonyType.RadioStyle
13
13
  themeStyles?: boolean
14
+ disabled?: boolean
14
15
  }
15
16
 
16
17
  @Extend(Radio)
17
18
  function radioAttr (attr: RadioAttrs) {
18
19
  .radioStyle(attr.radioStyle)
19
20
  .themeStyles(attr.themeStyles)
21
+ .enabled(!attr.disabled)
20
22
  }
21
23
 
22
24
  function getAttributes (node: TaroRadioElement): RadioAttrs {
@@ -25,6 +27,7 @@ function getAttributes (node: TaroRadioElement): RadioAttrs {
25
27
  checkedBackgroundColor: node._attrs.color || '#1aad19'
26
28
  }
27
29
  radioAttrs.themeStyles = !!node._attrs.disabled
30
+ radioAttrs.disabled = !!node._attrs.disabled
28
31
  return radioAttrs
29
32
  }
30
33
 
@@ -10,6 +10,7 @@ interface SliderAttrs {
10
10
  trackColor?: ResourceColor
11
11
  trackThickness?: Length
12
12
  blockColor?: ResourceColor
13
+ disabled?: boolean
13
14
  }
14
15
 
15
16
  @Extend(Slider)
@@ -18,6 +19,7 @@ function attrs (attr: SliderAttrs) {
18
19
  .trackColor(attr.trackColor)
19
20
  .trackThickness(attr.trackThickness)
20
21
  .blockColor(attr.blockColor)
22
+ .enabled(!attr.disabled)
21
23
  }
22
24
 
23
25
  function getAttributes (node: TaroSliderElement): SliderAttrs {
@@ -27,6 +29,7 @@ function getAttributes (node: TaroSliderElement): SliderAttrs {
27
29
  sliderAttrs.trackColor = _attrs.backgroundColor || _attrs.color || '#e9e9e9'
28
30
  sliderAttrs.trackThickness = _attrs.blockSize
29
31
  sliderAttrs.blockColor = _attrs.blockColor || '#ffffff'
32
+ sliderAttrs.disabled = !!_attrs.disabled
30
33
  return sliderAttrs
31
34
  }
32
35
 
@@ -7,18 +7,20 @@ import type { TaroAny, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
7
7
 
8
8
  interface SwitchAttrs {
9
9
  selectedColor?: ResourceColor
10
+ disabled?: boolean
10
11
  }
11
12
 
12
13
  @Extend(Toggle)
13
14
  function attrs(attr: SwitchAttrs) {
14
15
  .selectedColor(attr.selectedColor)
16
+ .enabled(!attr.disabled)
15
17
  }
16
18
 
17
19
  function getAttributes (node: TaroSwitchElement): SwitchAttrs {
18
- const _attrs = node._attrs
19
- const switchStyle: SwitchAttrs = {}
20
- switchStyle.selectedColor = _attrs.color || '#04BE02'
21
- return switchStyle
20
+ const attr: SwitchAttrs = {}
21
+ attr.selectedColor = node._attrs.color || '#04BE02'
22
+ attr.disabled = !!node._attrs.disabled
23
+ return attr
22
24
  }
23
25
 
24
26
  @Extend(Toggle)
@@ -7,6 +7,7 @@ import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroTextAreaElement, Ta
7
7
 
8
8
  interface TextareaAttrs extends TaroTextStyleType {
9
9
  autoFocus?: boolean
10
+ disabled?: boolean
10
11
  }
11
12
 
12
13
  @Extend(TextArea)
@@ -23,11 +24,13 @@ function textAttr(attr: TextareaAttrs) {
23
24
  .textAlign(attr.textAlign)
24
25
  .maxLines(attr.WebkitLineClamp)
25
26
  .defaultFocus(attr.autoFocus)
27
+ .enabled(!attr.disabled)
26
28
  }
27
29
 
28
30
  function getAttributes(node: TaroTextAreaElement): TextareaAttrs {
29
31
  const attrs: TaroAny = getFontAttributes(node)
30
32
  attrs.autoFocus = node._attrs.autoFocus || node._attrs.focus || false
33
+ attrs.disabled = node._attrs.disabled || false
31
34
  return attrs
32
35
  }
33
36
 
@@ -1,7 +1,6 @@
1
1
  import { parseClasses } from '../utils'
2
2
 
3
3
  import type { CSSProperties, ReactElement } from 'react'
4
-
5
4
  // 抽出来的嵌套查询
6
5
  // const __nesting_style__ = [
7
6
  // {
@@ -74,7 +73,7 @@ function depthTraversal(root: ReactElement) {
74
73
  const result: Record<string, TMapping> = {}
75
74
  if (tree && tree.props) {
76
75
  // 兜底适配:如果Taro组件被原封不动的再别的地方导出使用,导致无法在编译环境添加__hmStyle
77
- // import { View } from '~/components'
76
+ // import { View } from '../../../~/components'
78
77
  // hack:如果是taro节点,但是被赋予了__styleSheet,则走一下__styleSheet转__hmStyle
79
78
  if (tree.props.__styleSheet && typeof tree.type !== 'function') {
80
79
  tree.props.__hmStyle = Object.assign({}, tree.props.__hmStyle, tree.props.__styleSheet.value)
@@ -128,28 +127,34 @@ function depthTraversal(root: ReactElement) {
128
127
  const processLeaf = (leaf, descendant_map: TMappingNode) => {
129
128
  if (!leaf) return
130
129
 
131
- // 如果是个数组
132
- if (leaf instanceof Array) {
133
- for (let i = 0; i < leaf.length; i++) {
134
- processLeaf(leaf[i], descendant_map)
130
+ const queue = [leaf]
131
+
132
+ while (queue.length > 0) {
133
+ const current = queue.shift()
134
+
135
+ if (current instanceof Array) {
136
+ for (let i = 0; i < current.length; i++) {
137
+ queue.push(current[i])
138
+ }
139
+ continue
135
140
  }
136
- }
137
141
 
138
- const leaf_map = traverse(leaf)
139
- if (!leaf_map) return
142
+ const leaf_map = traverse(current)
143
+ if (!leaf_map) continue
140
144
 
141
- // 直接后代
142
- Object.assign(descendant_map.children, leaf_map)
145
+ // 直接后代
146
+ Object.assign(descendant_map.children, leaf_map)
143
147
 
144
- // 子孙后代
145
- const grandchild: (Record<string, TMapping> | TMapping)[] = [leaf_map]
146
- Object.keys(leaf_map).forEach(key => {
147
- const leaf_child_map = class_mapping[key]
148
- if (leaf_child_map?.descendants) {
149
- grandchild.push(leaf_child_map.descendants)
150
- }
151
- })
152
- Object.assign(descendant_map.descendants, ...grandchild)
148
+ // 子孙后代
149
+ const grandchild: (Record<string, TMapping> | TMapping)[] = [leaf_map]
150
+ Object.keys(leaf_map).forEach(key => {
151
+ const leaf_child_map = class_mapping[key]
152
+ if (leaf_child_map?.descendants) {
153
+ grandchild.push(leaf_child_map.descendants)
154
+ }
155
+ })
156
+ Object.assign(descendant_map.descendants, ...grandchild)
157
+ }
153
158
  }
154
159
 
155
160
  traverse(root)
@@ -239,24 +244,29 @@ function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias
239
244
  }
240
245
  return selector_nodes
241
246
  }
242
- const findSelector = (selectors, current_mapping, declaration): TSelectorNode[] => {
243
- const new_selectors = selectors.slice()
244
- const selector_string = new_selectors.shift()
245
- const combinator_type = new_selectors.shift()
246
- const _elements = findElement(selector_string, combinator_type, current_mapping, new_selectors, declaration)
247
- if (_elements.length) {
248
- if (new_selectors.length) {
249
- let elements: TSelectorNode[] = []
250
- _elements.forEach(element => {
251
- elements = elements.concat(findSelector(new_selectors.slice(), element.mapping, declaration))
252
- })
253
- return elements
254
- } else {
255
- return _elements
247
+ const findSelector = (selectors: string[], current_mapping: any, declaration: any): TSelectorNode[] => {
248
+ const workQueue: { selectors: string[], current_mapping: any }[] = [{ selectors, current_mapping }]
249
+ let resultElements: TSelectorNode[] = []
250
+ while (workQueue.length > 0) {
251
+ const { selectors: currentSelectors, current_mapping: currentMapping } = workQueue.shift()!
252
+ const new_selectors = currentSelectors.slice()
253
+ const selector_string = new_selectors.shift()
254
+ const combinator_type = new_selectors.shift()
255
+
256
+ const _elements = findElement(selector_string, combinator_type, currentMapping, new_selectors, declaration)
257
+
258
+ if (_elements.length) {
259
+ if (new_selectors.length) {
260
+ _elements.forEach(element => {
261
+ workQueue.push({ selectors: new_selectors.slice(), current_mapping: element.mapping })
262
+ })
263
+ } else {
264
+ resultElements = resultElements.concat(_elements)
265
+ }
256
266
  }
257
- } else {
258
- return []
259
267
  }
268
+
269
+ return resultElements
260
270
  }
261
271
  if (nestingStyle && nestingStyle instanceof Array) {
262
272
  // 合并样式
@@ -53,12 +53,16 @@ export class TaroElement<
53
53
  public dataset: Record<string, unknown> = EMPTY_OBJ
54
54
  public _attrs: T & TaroExtraProps = {} as T & TaroExtraProps
55
55
 
56
+ private _page: any
57
+
56
58
  constructor(tagName: string) {
57
59
  super(tagName.replace(new RegExp('(?<=.)([A-Z])', 'g'), '-$1').toUpperCase(), NodeType.ELEMENT_NODE)
58
60
  this.tagName = this.nodeName
59
61
  this._style = createCSSStyleDeclaration(this)
60
62
  initComponentNodeInfo(this)
61
63
  bindAnimation(this)
64
+
65
+ this._page = Current.page
62
66
  }
63
67
 
64
68
  public set id(value: string) {
@@ -270,28 +274,28 @@ export class TaroElement<
270
274
  }
271
275
 
272
276
  get currentLayerNode () {
273
- if (!Current.page) return null
274
- if (typeof Current.page.tabBarCurrentIndex !== 'undefined') {
275
- Current.page.layerNode ||= []
276
- Current.page.layerNode[Current.page.tabBarCurrentIndex] ||= Current.createHarmonyElement('VIEW')
277
+ if (!this._page) return null
278
+ if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
279
+ this._page.layerNode ||= []
280
+ this._page.layerNode[this._page.tabBarCurrentIndex] ||= Current.createHarmonyElement('VIEW')
277
281
  // Tabbar
278
- return Current.page.layerNode[Current.page.tabBarCurrentIndex]
282
+ return this._page.layerNode[this._page.tabBarCurrentIndex]
279
283
  } else {
280
- Current.page.layerNode ||= Current.createHarmonyElement('VIEW')
281
- return Current.page.layerNode
284
+ this._page.layerNode ||= Current.createHarmonyElement('VIEW')
285
+ return this._page.layerNode
282
286
  }
283
287
  }
284
288
 
285
289
  get currentLayerParents () {
286
- if (!Current.page) return null
287
- if (typeof Current.page.tabBarCurrentIndex !== 'undefined') {
288
- Current.page.layerParents ||= []
289
- Current.page.layerParents[Current.page.tabBarCurrentIndex] ||= []
290
+ if (!this._page) return null
291
+ if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
292
+ this._page.layerParents ||= []
293
+ this._page.layerParents[this._page.tabBarCurrentIndex] ||= []
290
294
  // Tabbar
291
- return Current.page.layerParents[Current.page.tabBarCurrentIndex]
295
+ return this._page.layerParents[this._page.tabBarCurrentIndex]
292
296
  } else {
293
- Current.page.layerParents ||= []
294
- return Current.page.layerParents
297
+ this._page.layerParents ||= []
298
+ return this._page.layerParents
295
299
  }
296
300
  }
297
301
 
@@ -232,6 +232,8 @@ export class TaroMovableViewElement extends TaroElement<MovableViewProps & { ani
232
232
  const touchFns = (this?.__listeners?.[eventName] || []) as Function[]
233
233
  touchFns.forEach(fn => {
234
234
  fn({
235
+ _hmEvent: gestureEvent,
236
+ target: this,
235
237
  changedTouches: gestureEvent.fingerList.map(finger => ({
236
238
  clientX: finger.globalX,
237
239
  clientY: finger.globalY
@@ -196,7 +196,7 @@ export function createReactApp (
196
196
  const keys = Object.keys(globalData)
197
197
  const descriptors = Object.getOwnPropertyDescriptors(globalData)
198
198
  keys.forEach(key => {
199
- Object.defineProperty(this, key, {
199
+ Object.defineProperty(Current?.app || this, key, {
200
200
  configurable: true,
201
201
  enumerable: true,
202
202
  get () {
@@ -207,7 +207,7 @@ export function createReactApp (
207
207
  }
208
208
  })
209
209
  })
210
- Object.defineProperties(this, descriptors)
210
+ Object.defineProperties(Current?.app || this, descriptors)
211
211
  }
212
212
 
213
213
  app.onCreate?.()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-platform-harmony-ets",
3
- "version": "4.0.0-alpha.16",
3
+ "version": "4.0.0-alpha.18",
4
4
  "description": "OpenHarmony & 鸿蒙系统插件",
5
5
  "author": "O2Team",
6
6
  "homepage": "https://gitee.com/openharmony-sig/taro",
@@ -26,22 +26,22 @@
26
26
  "dependencies": {
27
27
  "webpack-sources": "^3.2.3",
28
28
  "webpack": "5.78.0",
29
- "@tarojs/components": "4.0.0-alpha.16",
30
- "@tarojs/helper": "4.0.0-alpha.16",
31
- "@tarojs/service": "4.0.0-alpha.16",
32
- "@tarojs/runner-utils": "4.0.0-alpha.16",
33
- "@tarojs/runtime": "4.0.0-alpha.16",
34
- "@tarojs/taro": "4.0.0-alpha.16",
35
- "@tarojs/shared": "4.0.0-alpha.16"
29
+ "@tarojs/components": "4.0.0-alpha.18",
30
+ "@tarojs/runner-utils": "4.0.0-alpha.18",
31
+ "@tarojs/runtime": "4.0.0-alpha.18",
32
+ "@tarojs/helper": "4.0.0-alpha.18",
33
+ "@tarojs/shared": "4.0.0-alpha.18",
34
+ "@tarojs/taro": "4.0.0-alpha.18",
35
+ "@tarojs/service": "4.0.0-alpha.18"
36
36
  },
37
37
  "devDependencies": {
38
38
  "fast-glob": "^3.3.1",
39
- "rollup": "^3.8.1",
39
+ "rollup": "^3.29.4",
40
40
  "rollup-plugin-node-externals": "^5.0.0",
41
41
  "rollup-plugin-ts": "^3.0.2",
42
42
  "solid-js": "^1.8.16",
43
43
  "tslib": "^2.4.0",
44
- "rollup-plugin-copy": "4.0.0-alpha.16"
44
+ "rollup-plugin-copy": "4.0.0-alpha.18"
45
45
  },
46
46
  "scripts": {
47
47
  "prod": "pnpm run build",