@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.2 → 4.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apis/base/system.ts +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +16 -8
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +25 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/storage/index.ts +146 -78
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +42 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +5 -5
- package/dist/apis/ui/tab-bar.ts +3 -3
- package/dist/apis/utils/index.ts +2 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +64 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +72 -61
- package/dist/components-harmony-ets/form.ets +51 -29
- package/dist/components-harmony-ets/icon.ets +31 -19
- package/dist/components-harmony-ets/image.ets +34 -14
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +49 -41
- package/dist/components-harmony-ets/label.ets +71 -44
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +42 -38
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +74 -64
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +61 -57
- package/dist/components-harmony-ets/slider.ets +18 -14
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +381 -130
- package/dist/components-harmony-ets/swiper.ets +61 -20
- package/dist/components-harmony-ets/switch.ets +36 -32
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +135 -49
- package/dist/components-harmony-ets/textArea.ets +50 -35
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
- package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
- package/dist/components-harmony-ets/utils/helper.ets +18 -5
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +170 -93
- package/dist/components-harmony-ets/video.ets +34 -21
- package/dist/components-harmony-ets/view.ets +63 -52
- package/dist/components-harmony-ets/webView.ets +40 -34
- package/dist/index.d.ts +152 -0
- package/dist/index.js +99 -55
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +7 -0
- package/dist/runtime-ets/current.ts +3 -0
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +419 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
- package/dist/runtime-ets/dom/document.ts +8 -11
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +348 -57
- package/dist/runtime-ets/dom/element/form.ts +31 -26
- package/dist/runtime-ets/dom/element/index.ts +30 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +244 -0
- package/dist/runtime-ets/dom/element/normal.ts +35 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +12 -5
- package/dist/runtime-ets/dom/event.ts +2 -4
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +54 -29
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
- package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
- package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/index.ts +2 -1
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/utils/index.ts +73 -13
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-framework/react/app.ts +9 -4
- package/dist/runtime-framework/react/hooks.ts +0 -1
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +154 -77
- package/dist/runtime-framework/react/page.ts +3 -8
- package/dist/runtime-framework/solid/app.ts +25 -45
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +84 -30
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +0 -2
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +435 -218
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +435 -218
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -1
- package/static/media/circle.svg +1 -1
- package/static/media/clear.svg +1 -1
- package/static/media/download.svg +1 -1
- package/static/media/info.svg +1 -1
- package/static/media/info_circle.svg +1 -1
- package/static/media/search.svg +1 -1
- package/static/media/success.svg +1 -1
- package/static/media/success_no_circle.svg +1 -1
- package/static/media/warn.svg +1 -1
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +1 -1
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -29,14 +29,10 @@ interface FormWidgetProps extends StandardProps {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends TaroElement<T> {
|
|
32
|
-
_instance
|
|
33
|
-
|
|
34
32
|
_isInit = false
|
|
35
33
|
|
|
36
34
|
_name = ''
|
|
37
35
|
|
|
38
|
-
_value: TaroAny = ''
|
|
39
|
-
|
|
40
36
|
_reset: TaroAny = ''
|
|
41
37
|
|
|
42
38
|
constructor (tagName: string) {
|
|
@@ -45,7 +41,7 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
45
41
|
bindFocus(this)
|
|
46
42
|
|
|
47
43
|
this._name = this._attrs.name || ''
|
|
48
|
-
this._value = this._attrs.value || ''
|
|
44
|
+
this._nodeInfo._value = this._attrs.value || ''
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
public setAttribute (name: string, value: any): void {
|
|
@@ -66,11 +62,10 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
66
62
|
|
|
67
63
|
public set name (val: string) {
|
|
68
64
|
this.updateFormWidgetName(val)
|
|
69
|
-
this.updateComponent()
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
public get value () {
|
|
73
|
-
return this._value
|
|
68
|
+
return this._nodeInfo._value
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
public set value (val: TaroAny) {
|
|
@@ -78,8 +73,6 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
78
73
|
|
|
79
74
|
if (this._instance) {
|
|
80
75
|
this._instance.value = val
|
|
81
|
-
} else {
|
|
82
|
-
this.updateComponent()
|
|
83
76
|
}
|
|
84
77
|
}
|
|
85
78
|
|
|
@@ -89,7 +82,7 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
|
|
|
89
82
|
}
|
|
90
83
|
|
|
91
84
|
public updateFormWidgetValue (val: TaroAny) {
|
|
92
|
-
this._value = val
|
|
85
|
+
this._nodeInfo._value = val
|
|
93
86
|
this._attrs.value = val
|
|
94
87
|
}
|
|
95
88
|
|
|
@@ -121,7 +114,6 @@ class TaroCheckedElement<T extends StandardProps & { checked?: boolean } = Stand
|
|
|
121
114
|
|
|
122
115
|
set checked (val: boolean) {
|
|
123
116
|
this.updateCheckedValue(val)
|
|
124
|
-
this.updateComponent()
|
|
125
117
|
}
|
|
126
118
|
|
|
127
119
|
public updateCheckedValue (val: boolean) {
|
|
@@ -134,6 +126,7 @@ class TaroCheckedElement<T extends StandardProps & { checked?: boolean } = Stand
|
|
|
134
126
|
}
|
|
135
127
|
}
|
|
136
128
|
|
|
129
|
+
@Observed
|
|
137
130
|
class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormWidgetElement<T> {
|
|
138
131
|
_height = 0
|
|
139
132
|
|
|
@@ -174,6 +167,14 @@ class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormW
|
|
|
174
167
|
}
|
|
175
168
|
}
|
|
176
169
|
|
|
170
|
+
public get value () {
|
|
171
|
+
return super.value
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public set value (val: TaroAny) {
|
|
175
|
+
super.value = `${val}`
|
|
176
|
+
}
|
|
177
|
+
|
|
177
178
|
private onKeyboardHeightChange (height: number) {
|
|
178
179
|
const event: TaroEvent = createTaroEvent('keyboardHeightChange', { detail: { height: height, duration: 0 } }, this)
|
|
179
180
|
|
|
@@ -193,38 +194,39 @@ class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormW
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
|
|
197
|
-
class TaroTextAreaElement extends TaroInputElement<TextareaProps>{
|
|
197
|
+
@Observed
|
|
198
|
+
class TaroTextAreaElement extends TaroInputElement<TextareaProps> {
|
|
198
199
|
controller: TextAreaController = new TextAreaController()
|
|
199
200
|
|
|
200
201
|
constructor() {
|
|
201
202
|
super('TextArea')
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
|
-
|
|
205
|
-
class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps>{
|
|
205
|
+
@Observed
|
|
206
|
+
class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps> {
|
|
206
207
|
constructor() {
|
|
207
208
|
super('Checkbox')
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
|
|
212
|
+
@Observed
|
|
213
|
+
class TaroRadioElement extends TaroCheckedElement<RadioProps> {
|
|
212
214
|
public group?: string
|
|
213
215
|
|
|
214
216
|
constructor() {
|
|
215
217
|
super('Radio')
|
|
216
218
|
}
|
|
217
219
|
}
|
|
218
|
-
class TaroSliderElement extends TaroFormWidgetElement<SliderProps> {
|
|
219
|
-
_value = 0
|
|
220
220
|
|
|
221
|
+
@Observed
|
|
222
|
+
class TaroSliderElement extends TaroFormWidgetElement<SliderProps> {
|
|
221
223
|
constructor() {
|
|
222
224
|
super('Slider')
|
|
223
225
|
|
|
224
|
-
this._value = Number(this._attrs.value || 0)
|
|
226
|
+
this._nodeInfo._value = Number(this._attrs.value || 0)
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
|
-
|
|
229
|
+
@Observed
|
|
228
230
|
class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | PickerTimeProps | PickerDateProps | PickerMultiSelectorProps> {
|
|
229
231
|
constructor() {
|
|
230
232
|
super('Picker')
|
|
@@ -238,7 +240,7 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
|
|
|
238
240
|
case 'selector': {
|
|
239
241
|
const key = this._attrs.rangeKey
|
|
240
242
|
const item = this._attrs.range[this.value]
|
|
241
|
-
|
|
243
|
+
|
|
242
244
|
if (key) {
|
|
243
245
|
return item[key]
|
|
244
246
|
} else {
|
|
@@ -267,18 +269,19 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
|
|
|
267
269
|
super.reset()
|
|
268
270
|
|
|
269
271
|
const event: TaroEvent = createTaroEvent('change', { detail: { value: this._reset } }, this)
|
|
270
|
-
|
|
272
|
+
|
|
271
273
|
event.stopPropagation()
|
|
272
274
|
eventHandler(event, 'change', this)
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
|
|
278
|
+
@Observed
|
|
276
279
|
class TaroSwitchElement extends TaroCheckedElement<SwitchProps> {
|
|
277
280
|
constructor() {
|
|
278
281
|
super('Switch')
|
|
279
282
|
}
|
|
280
283
|
}
|
|
281
|
-
|
|
284
|
+
@Observed
|
|
282
285
|
class TaroCheckboxGroupElement extends TaroFormWidgetElement<CheckboxGroupProps> {
|
|
283
286
|
constructor() {
|
|
284
287
|
super('CheckboxGroup')
|
|
@@ -304,6 +307,7 @@ class TaroCheckboxGroupElement extends TaroFormWidgetElement<CheckboxGroupProps>
|
|
|
304
307
|
}
|
|
305
308
|
}
|
|
306
309
|
|
|
310
|
+
@Observed
|
|
307
311
|
class TaroRadioGroupElement extends TaroFormWidgetElement<RadioGroupProps> {
|
|
308
312
|
constructor() {
|
|
309
313
|
super('RadioGroup')
|
|
@@ -329,6 +333,7 @@ class TaroRadioGroupElement extends TaroFormWidgetElement<RadioGroupProps> {
|
|
|
329
333
|
}
|
|
330
334
|
}
|
|
331
335
|
|
|
336
|
+
@Observed
|
|
332
337
|
class TaroFormElement extends TaroFormWidgetElement {
|
|
333
338
|
constructor() {
|
|
334
339
|
super('Form')
|
|
@@ -340,7 +345,7 @@ class TaroFormElement extends TaroFormWidgetElement {
|
|
|
340
345
|
|
|
341
346
|
findChildNodeWithDFS<TaroFormWidgetElement>(this, item => {
|
|
342
347
|
if (!item.name) return false
|
|
343
|
-
|
|
348
|
+
|
|
344
349
|
switch (item.nodeName) {
|
|
345
350
|
case 'INPUT':
|
|
346
351
|
case 'RADIO':
|
|
@@ -371,9 +376,9 @@ class TaroFormElement extends TaroFormWidgetElement {
|
|
|
371
376
|
e.stopPropagation()
|
|
372
377
|
switch (item.nodeName) {
|
|
373
378
|
case 'INPUT':
|
|
374
|
-
case 'SLIDER':
|
|
379
|
+
case 'SLIDER':
|
|
375
380
|
case 'PICKER':
|
|
376
|
-
case 'RADIO':
|
|
381
|
+
case 'RADIO':
|
|
377
382
|
case 'SWITCH':
|
|
378
383
|
case 'CHECKBOX':
|
|
379
384
|
case 'TEXTAREA':
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Current } from '../../current'
|
|
2
2
|
import { TaroTextNode } from '../node'
|
|
3
|
+
import { TaroCanvasElement } from './canvas'
|
|
3
4
|
import { TaroElement } from './element'
|
|
4
5
|
import {
|
|
5
6
|
FormElement,
|
|
@@ -14,20 +15,26 @@ import {
|
|
|
14
15
|
TaroSwitchElement,
|
|
15
16
|
TaroTextAreaElement
|
|
16
17
|
} from './form'
|
|
18
|
+
import { TaroMovableAreaElement } from './movableArea'
|
|
19
|
+
import { isTaroMovableViewElement, TaroMovableViewElement } from './movableView'
|
|
17
20
|
import {
|
|
18
21
|
TaroButtonElement,
|
|
19
22
|
TaroIconElement,
|
|
20
23
|
TaroImageElement,
|
|
21
24
|
TaroLabelElement,
|
|
25
|
+
TaroNavigationBarElement,
|
|
26
|
+
TaroOtherElement,
|
|
27
|
+
TaroPageMetaElement,
|
|
22
28
|
TaroRichTextElement,
|
|
23
29
|
TaroSwiperElement,
|
|
24
30
|
TaroSwiperItemElement,
|
|
25
31
|
TaroViewElement
|
|
26
32
|
} from './normal'
|
|
33
|
+
import { TaroProgressElement } from './progress'
|
|
27
34
|
import { TaroScrollViewElement } from './scrollView'
|
|
28
35
|
import { TaroTextElement } from './text'
|
|
29
36
|
import { TaroVideoElement } from './video'
|
|
30
|
-
import { TaroWebViewElement } from './webView'
|
|
37
|
+
import { TaroInnerHtmlElement, TaroWebViewElement } from './webView'
|
|
31
38
|
|
|
32
39
|
export function initHarmonyElement () {
|
|
33
40
|
Current.createHarmonyElement = (tagName: string) => {
|
|
@@ -36,7 +43,11 @@ export function initHarmonyElement () {
|
|
|
36
43
|
case 'image': return new TaroImageElement()
|
|
37
44
|
case 'text': return new TaroTextElement()
|
|
38
45
|
case 'button': return new TaroButtonElement()
|
|
46
|
+
case 'movable-area': return new TaroMovableAreaElement()
|
|
47
|
+
case 'movable-view': return new TaroMovableViewElement()
|
|
48
|
+
case 'progress': return new TaroProgressElement()
|
|
39
49
|
case 'scroll-view': return new TaroScrollViewElement()
|
|
50
|
+
case 'scroll-list': return new TaroScrollViewElement()
|
|
40
51
|
case 'checkbox-group': return new TaroCheckboxGroupElement()
|
|
41
52
|
case 'input': return new TaroInputElement()
|
|
42
53
|
case 'picker': return new TaroPickerElement()
|
|
@@ -49,12 +60,16 @@ export function initHarmonyElement () {
|
|
|
49
60
|
case 'icon': return new TaroIconElement()
|
|
50
61
|
case 'label': return new TaroLabelElement()
|
|
51
62
|
case 'rich-text': return new TaroRichTextElement()
|
|
63
|
+
case 'canvas': return new TaroCanvasElement()
|
|
52
64
|
case 'swiper': return new TaroSwiperElement()
|
|
53
65
|
case 'swiper-item': return new TaroSwiperItemElement()
|
|
54
66
|
case 'textarea': return new TaroTextAreaElement()
|
|
55
67
|
case 'form': return new TaroFormElement()
|
|
56
68
|
case 'web-view': return new TaroWebViewElement()
|
|
57
|
-
|
|
69
|
+
case 'inner-html': return new TaroInnerHtmlElement()
|
|
70
|
+
case 'page-meta': return new TaroPageMetaElement()
|
|
71
|
+
case 'navigation-bar': return new TaroNavigationBarElement()
|
|
72
|
+
default: return new TaroOtherElement(tagName)
|
|
58
73
|
}
|
|
59
74
|
}
|
|
60
75
|
|
|
@@ -67,15 +82,23 @@ export function initHarmonyElement () {
|
|
|
67
82
|
export {
|
|
68
83
|
FormElement,
|
|
69
84
|
TaroButtonElement,
|
|
85
|
+
TaroCanvasElement,
|
|
70
86
|
TaroCheckboxElement,
|
|
71
87
|
TaroCheckboxGroupElement,
|
|
72
88
|
TaroElement,
|
|
73
89
|
TaroFormElement,
|
|
74
90
|
TaroIconElement,
|
|
75
91
|
TaroImageElement,
|
|
92
|
+
TaroInnerHtmlElement,
|
|
76
93
|
TaroInputElement,
|
|
77
94
|
TaroLabelElement,
|
|
95
|
+
TaroMovableAreaElement,
|
|
96
|
+
TaroMovableViewElement,
|
|
97
|
+
TaroNavigationBarElement,
|
|
98
|
+
TaroOtherElement,
|
|
99
|
+
TaroPageMetaElement,
|
|
78
100
|
TaroPickerElement,
|
|
101
|
+
TaroProgressElement,
|
|
79
102
|
TaroRadioElement,
|
|
80
103
|
TaroRadioGroupElement,
|
|
81
104
|
TaroRichTextElement,
|
|
@@ -90,3 +113,8 @@ export {
|
|
|
90
113
|
TaroViewElement,
|
|
91
114
|
TaroWebViewElement
|
|
92
115
|
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
isTaroMovableViewElement
|
|
120
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { TaroElement } from './element'
|
|
2
|
+
|
|
3
|
+
import type { MovableViewProps } from '@tarojs/components/types'
|
|
4
|
+
import type { TaroAny } from '../../utils'
|
|
5
|
+
|
|
6
|
+
type Tsize = {
|
|
7
|
+
w: number
|
|
8
|
+
h: number
|
|
9
|
+
}
|
|
10
|
+
type Tpoint = {
|
|
11
|
+
x: number
|
|
12
|
+
y: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function calcPosition(postion: number, start: number, end: number) {
|
|
16
|
+
if (postion <= end && postion >= start) {
|
|
17
|
+
return postion
|
|
18
|
+
} else if (postion < start) {
|
|
19
|
+
return start
|
|
20
|
+
} else {
|
|
21
|
+
return end
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isTaroMovableViewElement (item: TaroAny): item is TaroMovableViewElement {
|
|
26
|
+
return item instanceof TaroMovableViewElement
|
|
27
|
+
}
|
|
28
|
+
@Observed
|
|
29
|
+
export class TaroMovableViewElement extends TaroElement<MovableViewProps & { animation: undefined }> {
|
|
30
|
+
_scaleValue = 1
|
|
31
|
+
_scalevalueTemp = 1
|
|
32
|
+
|
|
33
|
+
// 父级区别的大小
|
|
34
|
+
_area?: Tsize
|
|
35
|
+
// 自己元素的大小
|
|
36
|
+
_selfSize?: Tsize
|
|
37
|
+
_areaInited: false
|
|
38
|
+
_selfSizeInited: false
|
|
39
|
+
|
|
40
|
+
// 元素的位置
|
|
41
|
+
_position: Tpoint = {
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 0,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_positionTemp: Tpoint = {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
constructor() {
|
|
52
|
+
super('MovableView')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get _outOfBounds() {
|
|
56
|
+
if (this.getAttribute('outOfBounds')) {
|
|
57
|
+
return this.selfSize ? this.selfSize.w / 3 : 0
|
|
58
|
+
}
|
|
59
|
+
return 0
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
startScale() {
|
|
63
|
+
this._scalevalueTemp = this._scaleValue
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
doScale(val: number) {
|
|
67
|
+
const scale = this.getAttribute('scale')
|
|
68
|
+
|
|
69
|
+
// 禁止缩放的时候不生效
|
|
70
|
+
if (scale) {
|
|
71
|
+
this.scaleValue = val * this._scalevalueTemp
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
set scaleValue(val: number) {
|
|
76
|
+
if (this.checkScaleValueInBounds(val)) {
|
|
77
|
+
this._scaleValue = val
|
|
78
|
+
|
|
79
|
+
this.checkPositionBoundary(this.position, val)
|
|
80
|
+
|
|
81
|
+
const scaleFns = this?.__listeners?.scale || []
|
|
82
|
+
scaleFns.forEach((fn) => {
|
|
83
|
+
fn({ ...this.position, scale: this.scaleValue })
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get visibility () {
|
|
89
|
+
return this._areaInited && this._selfSizeInited ? Visibility.Visible : Visibility.Hidden
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get scaleValue() {
|
|
93
|
+
return this._scaleValue
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
startMove() {
|
|
97
|
+
this._positionTemp = this._position
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
doMove(val: Tpoint) {
|
|
101
|
+
if (!this.area || !this.selfSize) {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
if (this.getAttribute('disabled')) {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
const direction = this.getAttribute('direction')
|
|
108
|
+
|
|
109
|
+
// 容器的宽高终点
|
|
110
|
+
const areaWidthEnd = this.area.w - this.selfSize.w * this.scaleValue
|
|
111
|
+
const areaHeightEnd = this.area.h - this.selfSize.h * this.scaleValue
|
|
112
|
+
|
|
113
|
+
const incrementWidth = (this.scaleValue - 1) * this.selfSize.w
|
|
114
|
+
const incrementHeight = (this.scaleValue - 1) * this.selfSize.h
|
|
115
|
+
|
|
116
|
+
let x = this._positionTemp.x
|
|
117
|
+
let y = this._positionTemp.y
|
|
118
|
+
if (['all', 'horizontal'].includes(direction)) {
|
|
119
|
+
const nextX = this._positionTemp.x + val.x * this.scaleValue
|
|
120
|
+
x = calcPosition(
|
|
121
|
+
nextX,
|
|
122
|
+
incrementWidth * 0.5 - this._outOfBounds,
|
|
123
|
+
areaWidthEnd + incrementWidth * 0.5 + this._outOfBounds
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (['all', 'vertical'].includes(direction)) {
|
|
128
|
+
const nextY = this._positionTemp.y + val.y * this.scaleValue
|
|
129
|
+
y = calcPosition(
|
|
130
|
+
nextY,
|
|
131
|
+
incrementHeight * 0.5 - this._outOfBounds,
|
|
132
|
+
areaHeightEnd + incrementHeight * 0.5 + this._outOfBounds
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const changeFns = this?.__listeners?.change || []
|
|
137
|
+
changeFns.forEach((fn) => {
|
|
138
|
+
fn({ x, y, source: 'touch' })
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
this.position = {
|
|
142
|
+
x: x,
|
|
143
|
+
y: y,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
get position() {
|
|
148
|
+
return this._position
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
set position(val: Tpoint) {
|
|
152
|
+
this._position = val
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
set area(val: Tsize) {
|
|
156
|
+
if (val.w === this._area?.w && val.h === this._area?.h) return
|
|
157
|
+
this._area = val
|
|
158
|
+
if (!this._areaInited) {
|
|
159
|
+
this._areaInited = true
|
|
160
|
+
this.initPositionFromAttribute()
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
get area(): Tsize | undefined {
|
|
165
|
+
return this._area
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
set selfSize(val: Tsize) {
|
|
169
|
+
if (val.w === this._selfSize?.w && val.h === this._selfSize?.h) return
|
|
170
|
+
this._selfSize = val
|
|
171
|
+
if (!this._selfSizeInited) {
|
|
172
|
+
this._selfSizeInited = true
|
|
173
|
+
this.initPositionFromAttribute()
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
get selfSize(): Tsize | undefined {
|
|
178
|
+
return this._selfSize
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
initPositionFromAttribute () {
|
|
182
|
+
if (!this.area || !this.selfSize) {
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
const x = this.getAttribute('x') ? Number(this.getAttribute('x')) : 0
|
|
186
|
+
const y = this.getAttribute('y') ? Number(this.getAttribute('y')) : 0
|
|
187
|
+
this.checkPositionBoundary({ x, y }, this.scaleValue)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
checkPositionBoundary(position: Tpoint, scale: number) {
|
|
191
|
+
if (!this.area || !this.selfSize) {
|
|
192
|
+
return { x: 0, y: 0 }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const areaWidthEnd = this.area.w - this.selfSize.w * scale
|
|
196
|
+
const areaHeightEnd = this.area.h - this.selfSize.h * scale
|
|
197
|
+
|
|
198
|
+
const incrementWidth = (scale - 1) * this.selfSize.w
|
|
199
|
+
const incrementHeight = (scale - 1) * this.selfSize.h
|
|
200
|
+
|
|
201
|
+
this.position = {
|
|
202
|
+
x: calcPosition(position.x, incrementWidth * 0.5, areaWidthEnd + incrementWidth * 0.5),
|
|
203
|
+
y: calcPosition(position.y, incrementHeight * 0.5, areaHeightEnd + incrementHeight * 0.5),
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
checkScaleValueInBounds(currentScale: number) {
|
|
208
|
+
const scaleMin = this.getAttribute('scaleMin')
|
|
209
|
+
const scaleMax = this.getAttribute('scaleMax')
|
|
210
|
+
|
|
211
|
+
if (scaleMin && Number(scaleMin) >= 0.1 && currentScale < Number(scaleMin)) {
|
|
212
|
+
return false
|
|
213
|
+
} else if (scaleMax && Number(scaleMax) >= 0.1 && currentScale > Number(scaleMax)) {
|
|
214
|
+
return false
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return true
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public setAttribute(name: string, value: any): void {
|
|
221
|
+
if (name === 'x') {
|
|
222
|
+
this.checkPositionBoundary({ x: value, y: this.position.y }, this.scaleValue)
|
|
223
|
+
}
|
|
224
|
+
if (name === 'y') {
|
|
225
|
+
this.checkPositionBoundary({ x: this.position.x, y: value }, this.scaleValue)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
super.setAttribute(name, value)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public callTouchEventFnFromGesture(eventName: string, gestureEvent: GestureEvent) {
|
|
232
|
+
const touchFns = (this?.__listeners?.[eventName] || []) as Function[]
|
|
233
|
+
touchFns.forEach(fn => {
|
|
234
|
+
fn({
|
|
235
|
+
_hmEvent: gestureEvent,
|
|
236
|
+
target: this,
|
|
237
|
+
changedTouches: gestureEvent.fingerList.map(finger => ({
|
|
238
|
+
clientX: finger.globalX,
|
|
239
|
+
clientY: finger.globalY
|
|
240
|
+
}))
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -6,50 +6,60 @@ import type {
|
|
|
6
6
|
IconProps,
|
|
7
7
|
ImageProps,
|
|
8
8
|
LabelProps,
|
|
9
|
+
NavigationBarProps,
|
|
10
|
+
PageMetaProps,
|
|
9
11
|
RichTextProps,
|
|
10
12
|
SwiperItemProps,
|
|
11
13
|
SwiperProps,
|
|
12
14
|
ViewProps
|
|
13
15
|
} from '@tarojs/components/types'
|
|
14
16
|
|
|
17
|
+
@Observed
|
|
18
|
+
class TaroOtherElement extends TaroElement<ViewProps> {}
|
|
19
|
+
|
|
20
|
+
@Observed
|
|
15
21
|
class TaroViewElement extends TaroElement<ViewProps> {
|
|
16
22
|
constructor() {
|
|
17
23
|
super('View')
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
|
|
27
|
+
@Observed
|
|
21
28
|
class TaroImageElement extends TaroElement<ImageProps> {
|
|
22
29
|
constructor() {
|
|
23
30
|
super('Image')
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
@Observed
|
|
27
35
|
class TaroButtonElement extends TaroElement<ButtonProps> {
|
|
28
36
|
constructor() {
|
|
29
37
|
super('Button')
|
|
30
38
|
}
|
|
31
39
|
}
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
class TaroIconElement extends TaroElement<IconProps>{
|
|
41
|
+
@Observed
|
|
42
|
+
class TaroIconElement extends TaroElement<IconProps> {
|
|
35
43
|
constructor() {
|
|
36
44
|
super('Icon')
|
|
37
45
|
}
|
|
38
46
|
}
|
|
39
|
-
|
|
40
|
-
class TaroLabelElement extends TaroElement<LabelProps>{
|
|
47
|
+
@Observed
|
|
48
|
+
class TaroLabelElement extends TaroElement<LabelProps> {
|
|
41
49
|
constructor() {
|
|
42
50
|
super('Label')
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
@Observed
|
|
55
|
+
class TaroRichTextElement extends TaroElement<RichTextProps> {
|
|
47
56
|
constructor() {
|
|
48
57
|
super('RichText')
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
@Observed
|
|
62
|
+
class TaroSwiperElement extends TaroElement<SwiperProps> {
|
|
53
63
|
controller: SwiperController = new SwiperController()
|
|
54
64
|
|
|
55
65
|
constructor() {
|
|
@@ -57,20 +67,37 @@ class TaroSwiperElement extends TaroElement<SwiperProps>{
|
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
|
|
70
|
+
@Observed
|
|
71
|
+
class TaroSwiperItemElement extends TaroElement<SwiperItemProps> {
|
|
61
72
|
constructor() {
|
|
62
73
|
super('SwiperItem')
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
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
|
+
}
|
|
66
90
|
|
|
67
91
|
export {
|
|
68
92
|
TaroButtonElement,
|
|
69
93
|
TaroIconElement,
|
|
70
94
|
TaroImageElement,
|
|
71
95
|
TaroLabelElement,
|
|
96
|
+
TaroNavigationBarElement,
|
|
97
|
+
TaroOtherElement,
|
|
98
|
+
TaroPageMetaElement,
|
|
72
99
|
TaroRichTextElement,
|
|
73
100
|
TaroSwiperElement,
|
|
74
101
|
TaroSwiperItemElement,
|
|
75
|
-
TaroViewElement
|
|
102
|
+
TaroViewElement
|
|
76
103
|
}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { TaroNode } from '../node'
|
|
2
1
|
import { TaroElement } from './element'
|
|
3
2
|
|
|
4
3
|
import type { TextProps } from '@tarojs/components/types'
|
|
5
4
|
|
|
5
|
+
@Observed
|
|
6
6
|
export class TaroTextElement extends TaroElement<TextProps> {
|
|
7
7
|
constructor() {
|
|
8
8
|
super('Text')
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
public appendChild (child: TaroNode): TaroNode {
|
|
12
|
-
super.appendChild(child)
|
|
13
|
-
|
|
14
|
-
this.updateComponent()
|
|
15
|
-
return child
|
|
16
|
-
}
|
|
17
10
|
}
|