@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27
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/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- package/types/webpack-sources.d.ts +108 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { TaroNode } from '@tarojs/runtime'
|
|
2
|
+
import { children as solidChildren, createRenderEffect, onCleanup, splitProps } from 'solid-js'
|
|
3
|
+
|
|
4
|
+
import { createElement, createTextNode, effect, insert, insertNode, setProp } from './render'
|
|
5
|
+
|
|
6
|
+
import type { Accessor } from 'solid-js'
|
|
7
|
+
import type { ResolvedChildren } from 'solid-js/types/reactive/signal'
|
|
8
|
+
|
|
9
|
+
export type Component = (props?: any) => TaroNode
|
|
10
|
+
|
|
11
|
+
type Children =
|
|
12
|
+
| undefined
|
|
13
|
+
| string
|
|
14
|
+
| number
|
|
15
|
+
| TaroNode
|
|
16
|
+
| TaroNode[]
|
|
17
|
+
| Component
|
|
18
|
+
| Component[]
|
|
19
|
+
| Accessor<ResolvedChildren>
|
|
20
|
+
| (() => Component[])
|
|
21
|
+
|
|
22
|
+
export function h(tagName: string, props?: any, children?: Children) {
|
|
23
|
+
if (typeof tagName !== 'string') {
|
|
24
|
+
throw Error(`h function cant create ele for ${tagName}`)
|
|
25
|
+
}
|
|
26
|
+
const ele = createElement(tagName)
|
|
27
|
+
const [local, otherProps] = splitProps(props, ['ref', 'children'])
|
|
28
|
+
|
|
29
|
+
setProps(ele, otherProps)
|
|
30
|
+
|
|
31
|
+
if (local.ref) {
|
|
32
|
+
createRenderEffect(() => {
|
|
33
|
+
if (typeof local.ref === 'function') {
|
|
34
|
+
local.ref(ele)
|
|
35
|
+
} else {
|
|
36
|
+
local.ref = ele
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// get 的处理
|
|
42
|
+
if (local.hasOwnProperty('children')) {
|
|
43
|
+
const descriptor = Object.getOwnPropertyDescriptor(local, 'children')
|
|
44
|
+
if (descriptor?.get) {
|
|
45
|
+
children = solidChildren(() => local.children)
|
|
46
|
+
} else {
|
|
47
|
+
children = local.children
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
insertNodes(ele, children)
|
|
51
|
+
|
|
52
|
+
return ele
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function setProps(ele: TaroNode, otherProps: Record<string, any> = {}) {
|
|
56
|
+
const desc = { ...otherProps }
|
|
57
|
+
const plain_keys = Object.keys(desc).filter((key) => {
|
|
58
|
+
if (desc[key]?.get) {
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
return true
|
|
62
|
+
})
|
|
63
|
+
const [plainProps, getterValues] = splitProps(otherProps, plain_keys)
|
|
64
|
+
|
|
65
|
+
// 普通属性直接赋值
|
|
66
|
+
if (Object.keys(plainProps)?.length) {
|
|
67
|
+
for (const key in plainProps) {
|
|
68
|
+
setProp(ele, key, plainProps[key])
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 特殊属性 放到createRenderEffect中
|
|
73
|
+
if (Object.keys(getterValues)?.length) {
|
|
74
|
+
let preProps = {} as typeof getterValues
|
|
75
|
+
effect(() => {
|
|
76
|
+
for (const key in getterValues) {
|
|
77
|
+
const val = getterValues[key]
|
|
78
|
+
|
|
79
|
+
if (val === preProps[key]) {
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
setProp(ele, key, val, preProps[key])
|
|
83
|
+
preProps[key] = val
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
onCleanup(() => {
|
|
87
|
+
preProps = {}
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function insertNodes(parent: TaroNode, children: Children) {
|
|
93
|
+
if (children === undefined) {
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let list = [] as TaroNode[] | (() => TaroNode)[]
|
|
98
|
+
if (!Array.isArray(children)) {
|
|
99
|
+
list = [children] as TaroNode[] | (() => TaroNode)[]
|
|
100
|
+
} else {
|
|
101
|
+
list = children
|
|
102
|
+
}
|
|
103
|
+
for (let i = 0; i < list.length; i++) {
|
|
104
|
+
const child = list[i]
|
|
105
|
+
const type = typeof child
|
|
106
|
+
if (type === 'function') {
|
|
107
|
+
insert(parent, child, null)
|
|
108
|
+
continue
|
|
109
|
+
}
|
|
110
|
+
if (Array.isArray(child)) {
|
|
111
|
+
insertNodes(parent, child)
|
|
112
|
+
continue
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (child instanceof TaroNode) {
|
|
116
|
+
insertNode(parent, child)
|
|
117
|
+
continue
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (type === 'string') {
|
|
121
|
+
const node = createTextNode(child as unknown as string)
|
|
122
|
+
insertNode(parent, node)
|
|
123
|
+
continue
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (type === 'number' || type === 'boolean' || child instanceof Date || child instanceof RegExp) {
|
|
127
|
+
const node = createTextNode(child.toString())
|
|
128
|
+
insertNode(parent, node)
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { convertNumber2PX, FormElement } from '@tarojs/runtime'
|
|
2
|
+
import { capitalize, internalComponents, isFunction, isNumber, isObject, isString, toCamelCase } from '@tarojs/shared'
|
|
3
|
+
|
|
4
|
+
import type { Style, TaroElement } from '@tarojs/runtime'
|
|
5
|
+
|
|
6
|
+
export type Props = Record<string, unknown>
|
|
7
|
+
|
|
8
|
+
function isEventName (s: string) {
|
|
9
|
+
return s[0] === 'o' && s[1] === 'n'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const IS_NON_DIMENSIONAL = /max|aspect|acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i
|
|
13
|
+
|
|
14
|
+
export function updateProps (dom: TaroElement, oldProps: Props, newProps: Props) {
|
|
15
|
+
const updatePayload = getUpdatePayload(dom, oldProps, newProps)
|
|
16
|
+
if (updatePayload){
|
|
17
|
+
updatePropsByPayload(dom, oldProps, updatePayload)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function updatePropsByPayload (dom: TaroElement, oldProps: Props, updatePayload: any[]){
|
|
22
|
+
for (let i = 0; i < updatePayload.length; i += 2){ // key, value 成对出现
|
|
23
|
+
const key = updatePayload[i]; const newProp = updatePayload[i+1]; const oldProp = oldProps[key]
|
|
24
|
+
setProperty(dom, key, newProp, oldProp)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getUpdatePayload (dom: TaroElement, oldProps: Props, newProps: Props){
|
|
29
|
+
let i: string
|
|
30
|
+
let updatePayload: any[] | null = null
|
|
31
|
+
|
|
32
|
+
for (i in oldProps) {
|
|
33
|
+
if (!(i in newProps)) {
|
|
34
|
+
(updatePayload = updatePayload || []).push(i, null)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const isFormElement = dom instanceof FormElement
|
|
38
|
+
for (i in newProps) {
|
|
39
|
+
if (oldProps[i] !== newProps[i] || (isFormElement && i === 'value')) {
|
|
40
|
+
(updatePayload = updatePayload || []).push(i, newProps[i])
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return updatePayload
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// function eventProxy (e: CommonEvent) {
|
|
48
|
+
// const el = document.getElementById(e.currentTarget.id)
|
|
49
|
+
// const handlers = el!.__handlers[e.type]
|
|
50
|
+
// handlers[0](e)
|
|
51
|
+
// }
|
|
52
|
+
|
|
53
|
+
function setEvent (dom: TaroElement, name: string, value: unknown, oldValue?: unknown) {
|
|
54
|
+
const isCapture = name.endsWith('Capture')
|
|
55
|
+
let eventName = name.toLowerCase().slice(2)
|
|
56
|
+
if (isCapture) {
|
|
57
|
+
eventName = eventName.slice(0, -7)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const compName = capitalize(toCamelCase(dom.tagName.toLowerCase()))
|
|
61
|
+
|
|
62
|
+
if (eventName === 'click' && compName in internalComponents) {
|
|
63
|
+
eventName = 'tap'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isFunction(value)) {
|
|
67
|
+
const isHarmony = process.env.TARO_PLATFORM === 'harmony'
|
|
68
|
+
if (oldValue) {
|
|
69
|
+
dom.removeEventListener(eventName, oldValue as any, !isHarmony ? false : undefined)
|
|
70
|
+
dom.addEventListener(eventName, value, !isHarmony ? { isCapture, sideEffect: false } : undefined)
|
|
71
|
+
} else {
|
|
72
|
+
dom.addEventListener(eventName, value, !isHarmony ? isCapture : undefined)
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
dom.removeEventListener(eventName, oldValue as any)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function setStyle (style: Style, key: string, value: string | number) {
|
|
80
|
+
if (key[0] === '-') {
|
|
81
|
+
style.setProperty(key, value.toString())
|
|
82
|
+
// css variables need not further judgment
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
style[key] =
|
|
87
|
+
isNumber(value) && IS_NON_DIMENSIONAL.test(key) === false
|
|
88
|
+
? convertNumber2PX(value)
|
|
89
|
+
: value == null
|
|
90
|
+
? ''
|
|
91
|
+
: value
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type StyleValue = Record<string, string | number>
|
|
95
|
+
interface DangerouslySetInnerHTML {
|
|
96
|
+
__html?: string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function setProperty (dom: TaroElement, name: string, value: unknown, oldValue?: unknown) {
|
|
100
|
+
name = name === 'className' ? 'class' : name
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
name === 'key' ||
|
|
104
|
+
name === 'children' ||
|
|
105
|
+
name === 'ref'
|
|
106
|
+
) {
|
|
107
|
+
// skip
|
|
108
|
+
} else if (name === 'style') {
|
|
109
|
+
const style = dom.style
|
|
110
|
+
if (isString(value)) {
|
|
111
|
+
style.cssText = value
|
|
112
|
+
} else {
|
|
113
|
+
if (isString(oldValue)) {
|
|
114
|
+
style.cssText = ''
|
|
115
|
+
oldValue = null
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (isObject<StyleValue>(oldValue)) {
|
|
119
|
+
for (const i in oldValue) {
|
|
120
|
+
if (!(value && i in (value as StyleValue))) {
|
|
121
|
+
setStyle(style, i, '')
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (isObject<StyleValue>(value)) {
|
|
127
|
+
for (const i in value) {
|
|
128
|
+
if (!oldValue || value[i] !== (oldValue as StyleValue)[i]) {
|
|
129
|
+
setStyle(style, i, value[i])
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} else if (isEventName(name)) {
|
|
135
|
+
setEvent(dom, name, value, oldValue)
|
|
136
|
+
} else if (name === 'dangerouslySetInnerHTML') {
|
|
137
|
+
const newHtml = (value as DangerouslySetInnerHTML)?.__html ?? ''
|
|
138
|
+
const oldHtml = (oldValue as DangerouslySetInnerHTML)?.__html ?? ''
|
|
139
|
+
if (newHtml || oldHtml) {
|
|
140
|
+
if (oldHtml !== newHtml) {
|
|
141
|
+
dom.innerHTML = newHtml
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else if (!isFunction(value)) {
|
|
145
|
+
if (value == null) {
|
|
146
|
+
dom.removeAttribute(name)
|
|
147
|
+
} else {
|
|
148
|
+
dom.setAttribute(name, value as string)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import TaroText from '@tarojs/components/text'
|
|
2
|
+
import { document } from '@tarojs/runtime'
|
|
3
|
+
import { createRenderer } from 'solid-js/universal'
|
|
4
|
+
|
|
5
|
+
import { h } from './h'
|
|
6
|
+
import { setProperty } from './props'
|
|
7
|
+
|
|
8
|
+
import type { TaroElement, TaroNode } from '@tarojs/runtime'
|
|
9
|
+
|
|
10
|
+
const renderer = createRenderer<TaroNode>({
|
|
11
|
+
createElement(type: string) {
|
|
12
|
+
return document.createElement(type)
|
|
13
|
+
},
|
|
14
|
+
createTextNode(text) {
|
|
15
|
+
return document.createTextNode(text)
|
|
16
|
+
},
|
|
17
|
+
replaceText(textNode: typeof TaroText, value) {
|
|
18
|
+
textNode.textContent = value
|
|
19
|
+
},
|
|
20
|
+
setProperty(node: TaroElement, name: string, value, prev) {
|
|
21
|
+
setProperty(node, name, value, prev)
|
|
22
|
+
},
|
|
23
|
+
insertNode(parent, node, anchor) {
|
|
24
|
+
parent.insertBefore(node, anchor)
|
|
25
|
+
},
|
|
26
|
+
isTextNode(node: TaroNode) {
|
|
27
|
+
if (typeof node === 'string') {
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
return node instanceof TaroText
|
|
31
|
+
},
|
|
32
|
+
removeNode(parent: TaroElement, node: TaroElement) {
|
|
33
|
+
parent.removeChild(node)
|
|
34
|
+
},
|
|
35
|
+
getParentNode(node: TaroNode) {
|
|
36
|
+
return node.parentNode || undefined
|
|
37
|
+
},
|
|
38
|
+
getFirstChild(node: TaroElement) {
|
|
39
|
+
return node.firstChild || undefined
|
|
40
|
+
},
|
|
41
|
+
getNextSibling(node: TaroElement) {
|
|
42
|
+
return node.nextSibling || undefined
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export const render = renderer.render
|
|
47
|
+
export const effect = renderer.effect
|
|
48
|
+
export const memo = renderer.memo
|
|
49
|
+
export const createComponent = (type, props) => {
|
|
50
|
+
if (typeof type === 'string') {
|
|
51
|
+
return h(type, props)
|
|
52
|
+
}
|
|
53
|
+
return renderer.createComponent(type, props)
|
|
54
|
+
}
|
|
55
|
+
export const createElement = renderer.createElement
|
|
56
|
+
export const createTextNode = renderer.createTextNode
|
|
57
|
+
export const insertNode = renderer.insertNode
|
|
58
|
+
export const insert = renderer.insert
|
|
59
|
+
export const spread = renderer.spread
|
|
60
|
+
export const setProp = renderer.setProp
|
|
61
|
+
export const mergeProps = renderer.mergeProps
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Current } from '@tarojs/runtime'
|
|
2
|
+
import { isArray } from '@tarojs/shared'
|
|
3
|
+
|
|
4
|
+
export * from './is'
|
|
5
|
+
|
|
6
|
+
export const noop = (..._: unknown[]) => {}
|
|
7
|
+
|
|
8
|
+
export function capitalize (s: string) {
|
|
9
|
+
return s.charAt(0).toUpperCase() + s.slice(1)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const incrementId = () => {
|
|
13
|
+
let n = 0
|
|
14
|
+
return () => (n++).toString()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const EMPTY_OBJ: any = {}
|
|
18
|
+
|
|
19
|
+
export const HOOKS_APP_ID = 'taro-app'
|
|
20
|
+
|
|
21
|
+
export function ensureIsArray<T>(item: T | T[]): T[] {
|
|
22
|
+
if (isArray(item)) {
|
|
23
|
+
return item
|
|
24
|
+
} else {
|
|
25
|
+
return item ? [item] : []
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* set writable, enumerable to true
|
|
31
|
+
*/
|
|
32
|
+
export function setDefaultDescriptor(obj: Record<string, any>) {
|
|
33
|
+
obj.writable = true
|
|
34
|
+
obj.enumerable = true
|
|
35
|
+
return obj
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 设置入口的路由参数
|
|
40
|
+
* @param options 小程序传入的参数
|
|
41
|
+
*/
|
|
42
|
+
export function setRouterParams(options) {
|
|
43
|
+
Current.router = {
|
|
44
|
+
params: options?.query,
|
|
45
|
+
...options,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function isClassComponent (R, component) {
|
|
2
|
+
const prototype = component.prototype
|
|
3
|
+
|
|
4
|
+
// For React Redux
|
|
5
|
+
if (component.displayName?.includes('Connect')) return false
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
isFunction(component.render) ||
|
|
9
|
+
!!prototype?.isReactComponent ||
|
|
10
|
+
prototype instanceof R.Component // compat for some others react-like library
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isString (o: unknown): o is string {
|
|
15
|
+
return typeof o === 'string'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isUndefined (o: unknown): o is undefined {
|
|
19
|
+
return typeof o === 'undefined'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isNull (o: unknown): o is null {
|
|
23
|
+
return o === null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isObject<T> (o: unknown): o is T {
|
|
27
|
+
return o !== null && typeof o === 'object'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isBoolean (o: unknown): o is boolean {
|
|
31
|
+
return o === true || o === false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isFunction (o: unknown): o is (...args: any[]) => any {
|
|
35
|
+
return typeof o === 'function'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function isNumber (o: unknown): o is number {
|
|
39
|
+
return typeof o === 'number'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isBooleanStringLiteral (o: unknown): o is string {
|
|
43
|
+
return o === 'true' || o === 'false'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const isArray = Array.isArray
|