@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,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
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Solid 运行时
|
|
2
|
+
|
|
3
|
+
## reconciler
|
|
4
|
+
|
|
5
|
+
基于 `solid/universal` 的 Solid 渲染器,连接 `@tarojs/runtime` 的 DOM 实例,相当于小程序版的 `solid-js/web`,暴露的 API 也和 `solid-js/web` 保持一致。
|
|
6
|
+
|
|
7
|
+
- render
|
|
8
|
+
- effect
|
|
9
|
+
- memo
|
|
10
|
+
- createComponent
|
|
11
|
+
- createElement
|
|
12
|
+
- createTextNode
|
|
13
|
+
- insertNode
|
|
14
|
+
- insert
|
|
15
|
+
- spread
|
|
16
|
+
- setProp
|
|
17
|
+
- mergeProps
|
|
18
|
+
|
|
19
|
+
需要新增 babel-presets-solid 插件配置,用于转换 SolidJS 的 JSX 语法。
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
module.exports = {
|
|
23
|
+
presets: [
|
|
24
|
+
['taro', {
|
|
25
|
+
framework: 'react',
|
|
26
|
+
ts: true,
|
|
27
|
+
}],
|
|
28
|
+
['babel-preset-solid', {
|
|
29
|
+
// 指向 SolidJS 的 reconciler
|
|
30
|
+
moduleName: '@tarojs/plugin-framework-react/dist/runtime/reconciler',
|
|
31
|
+
generate: 'universal',
|
|
32
|
+
}]
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 附录 1: [可能无法转换/兼容 SolidJS 的 React API 列表](https://github.com/solidjs-community/solid-codemod/issues/2)
|
|
38
|
+
|
|
39
|
+
### react
|
|
40
|
+
|
|
41
|
+
- cloneElement - Probably Element.cloneNode, but this highly depends on the usage and only works for DOM nodes not components.
|
|
42
|
+
- createFactory
|
|
43
|
+
- isValidElement - the lack of VDOM makes this impossible, however, instanceof Element can be a valid workaround in some cases.
|
|
44
|
+
- createRef - we can probably create a library shim such that this one exists and still returns the object, but we can convert those ref property usages into a callback assignment e.g. (el) => ref.current = el.
|
|
45
|
+
- forwardRef - Can be removed or provide a library shim, which ever works.
|
|
46
|
+
- memo - There's already a memo function in SolidJS but it behaves differently. We can remove this during compilation since it is totally unnecessary.
|
|
47
|
+
- useReducer - provide a library shim
|
|
48
|
+
- useRef - we can remove this and change VariableDeclaration, but that also requires current property accesses.
|
|
49
|
+
- useLayoutEffect - I'm not sure if createRenderEffect can replace this.
|
|
50
|
+
- useImperativeHandle - library shim
|
|
51
|
+
- useCallback - can be removed
|
|
52
|
+
- useDebugValue - statement can be removed.
|
|
53
|
+
- useDeferredValue - Now this one is highly different from createDeferred. We'll probably need Ryan's consultation.
|
|
54
|
+
- Mutable Sources - library shim
|
|
55
|
+
- useInsertionEffect - I'm not sure what this is, but I believe it is discussed in the <style> guide for React in the working group
|
|
56
|
+
- useSyncExternalStore - library shim
|
|
57
|
+
- Fragment - library shim, but I think I've suggested Ryan to add this one into the SolidJS core.
|
|
58
|
+
|
|
59
|
+
### react-dom
|
|
60
|
+
|
|
61
|
+
- findDOMNode
|
|
62
|
+
- unmountComponentAtNode - This one's impossible.
|
|
63
|
+
- flushSync - not sure what this is for, probably for flushing updates.
|
|
64
|
+
- unstable_renderSubtreeIntoContainer - I think this one was used in React Server Components, but given we don't have VDOM, this one's impossible.
|
|
65
|
+
- unstable_scheduleHydration
|
|
66
|
+
- unstable_flushControlled
|
|
67
|
+
|
|
68
|
+
## 附录 2: React 与 SolidJS 写法差异
|
|
69
|
+
|
|
70
|
+
> 参考:[solid-reactor](https://github.com/yellowsink/solid-reactor)
|
|
71
|
+
|
|
72
|
+
### API
|
|
73
|
+
|
|
74
|
+
- `useState` => `createSignal`
|
|
75
|
+
- `useEffect` => `createEffect`
|
|
76
|
+
- attempting to recreate the "run on every rerender" behaviour
|
|
77
|
+
- `useReducer` => `createSignal` + a function
|
|
78
|
+
- `useRef` => `{ current: <value> }` + a variable
|
|
79
|
+
- convert (useRef-returned only) refs in `ref={myRef}` to `ref={myRef.current}`.
|
|
80
|
+
|
|
81
|
+
### 样式
|
|
82
|
+
|
|
83
|
+
- camelCase(`marginRight`) => kebab-case(`margin-right`)
|
|
84
|
+
|
|
85
|
+
React.useRef => createSignal
|
|
86
|
+
React.createRef => createSignal
|
|
87
|
+
React.useLayoutEffect => [createRenderEffect, onCleanup]
|
|
88
|
+
React.useMemo => createMemo
|
|
89
|
+
ReactDOM.unstable_batchedUpdates => batch
|
|
90
|
+
|
|
91
|
+
React.Component => renderer.createComponent
|
|
92
|
+
ReactDOM.render => renderer.render
|
|
93
|
+
h => React.createElement => renderer.createElement
|
|
94
|
+
|
|
95
|
+
ReactDOM.findDOMNode
|
|
96
|
+
|
|
97
|
+
createRoot
|
|
98
|
+
createContext
|
|
99
|
+
useContext
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Current, document } from '@tarojs/runtime'
|
|
2
|
+
import { hooks, isWebPlatform } from '@tarojs/shared'
|
|
3
|
+
import { batch, createContext, createRoot, createSignal, For } from 'solid-js'
|
|
4
|
+
|
|
5
|
+
import { setReconciler } from './connect'
|
|
6
|
+
import { getPageInstance, injectPageInstance } from './page'
|
|
7
|
+
import { createComponent, h, render } from './reconciler'
|
|
8
|
+
import { EMPTY_OBJ, HOOKS_APP_ID, setDefaultDescriptor, setRouterParams } from './utils'
|
|
9
|
+
|
|
10
|
+
import type { AppInstance, Instance, PageLifeCycle, PageProps, ReactAppInstance } from '@tarojs/runtime'
|
|
11
|
+
import type { AppConfig } from '@tarojs/taro'
|
|
12
|
+
import type { Component } from './connect'
|
|
13
|
+
|
|
14
|
+
const isWeb = isWebPlatform()
|
|
15
|
+
|
|
16
|
+
export const ReactMeta = {
|
|
17
|
+
R: EMPTY_OBJ,
|
|
18
|
+
Container: EMPTY_OBJ,
|
|
19
|
+
PageContext: EMPTY_OBJ
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createSolidApp(App: Component, config: AppConfig) {
|
|
23
|
+
setReconciler()
|
|
24
|
+
|
|
25
|
+
if (ReactMeta.PageContext === EMPTY_OBJ) {
|
|
26
|
+
ReactMeta.PageContext = createContext<string>()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let appRef: ReactAppInstance
|
|
30
|
+
function getAppInstance(): any {
|
|
31
|
+
return appRef
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderReactRoot() {
|
|
35
|
+
let appId = 'app'
|
|
36
|
+
if (isWeb) {
|
|
37
|
+
appId = config?.appId || appId
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (ReactMeta.Container === EMPTY_OBJ) {
|
|
41
|
+
const Container = document.createElement('view')
|
|
42
|
+
|
|
43
|
+
Container.id = appId
|
|
44
|
+
ReactMeta.Container = Container
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const root = createRoot(() => ReactMeta.Container)
|
|
48
|
+
render(AppWrapper, root)
|
|
49
|
+
}
|
|
50
|
+
const [pages, setPages] = createSignal<any[]>([])
|
|
51
|
+
|
|
52
|
+
function AppWrapper () {
|
|
53
|
+
appRef = {} as unknown as ReactAppInstance
|
|
54
|
+
return createComponent(App, {
|
|
55
|
+
children: createComponent(For as unknown as Component, {
|
|
56
|
+
get each() {
|
|
57
|
+
return pages()
|
|
58
|
+
},
|
|
59
|
+
children: ({ id, component }) => {
|
|
60
|
+
const children = () =>
|
|
61
|
+
createComponent(ReactMeta.PageContext.Provider as unknown as Component, {
|
|
62
|
+
value: id,
|
|
63
|
+
children: () => {
|
|
64
|
+
injectPageInstance(
|
|
65
|
+
{ id: id, type: 'page' } as unknown as Instance<PageProps>,
|
|
66
|
+
id
|
|
67
|
+
)
|
|
68
|
+
return createComponent(component, {
|
|
69
|
+
tid: id,
|
|
70
|
+
})
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
if (isWeb) {
|
|
75
|
+
return h('div', { id, className: 'taro_page' }, children)
|
|
76
|
+
} else {
|
|
77
|
+
return h('root', { id }, children)
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!isWeb) {
|
|
85
|
+
renderReactRoot()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const [ONLAUNCH, ONSHOW, ONHIDE] = hooks.call('getMiniLifecycleImpl')!.app
|
|
89
|
+
|
|
90
|
+
const appObj: AppInstance = Object.create(
|
|
91
|
+
{
|
|
92
|
+
mount(component: Component, id: string, cb: () => void) {
|
|
93
|
+
setPages((old) => [
|
|
94
|
+
...old,
|
|
95
|
+
{ id, component },
|
|
96
|
+
])
|
|
97
|
+
batch(cb)
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
unmount(id: string, cb: () => void) {
|
|
101
|
+
setPages(
|
|
102
|
+
pages().filter((item) => {
|
|
103
|
+
return item.id !== id
|
|
104
|
+
})
|
|
105
|
+
)
|
|
106
|
+
batch(cb)
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
config: setDefaultDescriptor({
|
|
111
|
+
configurable: true,
|
|
112
|
+
value: config,
|
|
113
|
+
}),
|
|
114
|
+
|
|
115
|
+
[ONLAUNCH]: setDefaultDescriptor({
|
|
116
|
+
value(options) {
|
|
117
|
+
setRouterParams(options)
|
|
118
|
+
|
|
119
|
+
if (isWeb) {
|
|
120
|
+
// 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后执行 render
|
|
121
|
+
renderReactRoot()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const onLaunch = () => {
|
|
125
|
+
const app = getAppInstance()
|
|
126
|
+
|
|
127
|
+
if (app) {
|
|
128
|
+
// 把 App Class 上挂载的额外属性同步到全局 app 对象中
|
|
129
|
+
if (app.taroGlobalData) {
|
|
130
|
+
const globalData = app.taroGlobalData
|
|
131
|
+
const keys = Object.keys(globalData)
|
|
132
|
+
const descriptors = Object.getOwnPropertyDescriptors(globalData)
|
|
133
|
+
keys.forEach(key => {
|
|
134
|
+
Object.defineProperty(this, key, {
|
|
135
|
+
configurable: true,
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get () {
|
|
138
|
+
return globalData[key]
|
|
139
|
+
},
|
|
140
|
+
set (value) {
|
|
141
|
+
globalData[key] = value
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
Object.defineProperties(this, descriptors)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
app.onCreate?.()
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
onLaunch()
|
|
153
|
+
triggerAppHook('onLaunch', options)
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
|
|
157
|
+
[ONSHOW]: setDefaultDescriptor({
|
|
158
|
+
value(options) {
|
|
159
|
+
setRouterParams(options)
|
|
160
|
+
triggerAppHook('onShow', options)
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
163
|
+
|
|
164
|
+
[ONHIDE]: setDefaultDescriptor({
|
|
165
|
+
value() {
|
|
166
|
+
triggerAppHook('onHide')
|
|
167
|
+
},
|
|
168
|
+
}),
|
|
169
|
+
|
|
170
|
+
onError: setDefaultDescriptor({
|
|
171
|
+
value(error: string) {
|
|
172
|
+
triggerAppHook('onError', error)
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
|
|
176
|
+
onPageNotFound: setDefaultDescriptor({
|
|
177
|
+
value(res: unknown) {
|
|
178
|
+
triggerAppHook('onPageNotFound', res)
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
}
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
function triggerAppHook(
|
|
185
|
+
lifecycle: keyof PageLifeCycle | keyof AppInstance,
|
|
186
|
+
...option
|
|
187
|
+
) {
|
|
188
|
+
const instance = getPageInstance(HOOKS_APP_ID)
|
|
189
|
+
if (instance) {
|
|
190
|
+
const app = getAppInstance()
|
|
191
|
+
const func = hooks.call('getLifecycle', instance, lifecycle)
|
|
192
|
+
if (Array.isArray(func)) {
|
|
193
|
+
func.forEach((cb) => cb.apply(app, option))
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Current.app = appObj
|
|
199
|
+
return appObj
|
|
200
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TaroNode } from '@tarojs/runtime'
|
|
2
|
+
import { hooks } from '@tarojs/shared'
|
|
3
|
+
import { batch } from 'solid-js'
|
|
4
|
+
|
|
5
|
+
export type Component = (props?: any) => TaroNode
|
|
6
|
+
|
|
7
|
+
export function setReconciler() {
|
|
8
|
+
hooks.tap('batchedEventUpdates', function (cb) {
|
|
9
|
+
batch(cb)
|
|
10
|
+
})
|
|
11
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppInstance,
|
|
3
|
+
Current,
|
|
4
|
+
Func,
|
|
5
|
+
PageLifeCycle
|
|
6
|
+
} from '@tarojs/runtime'
|
|
7
|
+
import { isArray, isFunction } from '@tarojs/shared'
|
|
8
|
+
import {
|
|
9
|
+
createMemo,
|
|
10
|
+
createRenderEffect,
|
|
11
|
+
onCleanup,
|
|
12
|
+
} from 'solid-js'
|
|
13
|
+
|
|
14
|
+
import { ReactMeta } from './app'
|
|
15
|
+
import { getPageInstance, injectPageInstance } from './page'
|
|
16
|
+
import { HOOKS_APP_ID } from './utils'
|
|
17
|
+
|
|
18
|
+
const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
|
|
19
|
+
return (fn: Func) => {
|
|
20
|
+
const id = ReactMeta.PageContext || HOOKS_APP_ID
|
|
21
|
+
|
|
22
|
+
createRenderEffect(() => {
|
|
23
|
+
let inst = getPageInstance(id)
|
|
24
|
+
let first = false
|
|
25
|
+
if (!inst) {
|
|
26
|
+
first = true
|
|
27
|
+
inst = Object.create({
|
|
28
|
+
id: id,
|
|
29
|
+
type: 'page',
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isFunction(inst![lifecycle])) {
|
|
34
|
+
inst![lifecycle] = [inst?.[lifecycle], fn]
|
|
35
|
+
} else {
|
|
36
|
+
inst![lifecycle] = [...(inst![lifecycle] || []), fn]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (first) {
|
|
40
|
+
injectPageInstance(inst!, id)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onCleanup(() => {
|
|
44
|
+
const list = inst![lifecycle]
|
|
45
|
+
if (list === fn) {
|
|
46
|
+
inst![lifecycle] = undefined
|
|
47
|
+
} else if (isArray(list)) {
|
|
48
|
+
inst![lifecycle] = list.filter((item) => item !== fn)
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** LifeCycle */
|
|
56
|
+
export const useDidHide = createTaroHook('componentDidHide')
|
|
57
|
+
export const useDidShow = createTaroHook('componentDidShow')
|
|
58
|
+
|
|
59
|
+
/** App */
|
|
60
|
+
export const useError = createTaroHook('onError')
|
|
61
|
+
export const useLaunch = createTaroHook('onLaunch')
|
|
62
|
+
export const usePageNotFound = createTaroHook('onPageNotFound')
|
|
63
|
+
|
|
64
|
+
/** Page */
|
|
65
|
+
export const useLoad = createTaroHook('onLoad')
|
|
66
|
+
export const usePageScroll = createTaroHook('onPageScroll')
|
|
67
|
+
export const usePullDownRefresh = createTaroHook('onPullDownRefresh')
|
|
68
|
+
export const usePullIntercept = createTaroHook('onPullIntercept')
|
|
69
|
+
export const useReachBottom = createTaroHook('onReachBottom')
|
|
70
|
+
export const useResize = createTaroHook('onResize')
|
|
71
|
+
export const useUnload = createTaroHook('onUnload')
|
|
72
|
+
|
|
73
|
+
/** Mini-Program */
|
|
74
|
+
export const useAddToFavorites = createTaroHook('onAddToFavorites')
|
|
75
|
+
export const useOptionMenuClick = createTaroHook('onOptionMenuClick')
|
|
76
|
+
export const useSaveExitState = createTaroHook('onSaveExitState')
|
|
77
|
+
export const useShareAppMessage = createTaroHook('onShareAppMessage')
|
|
78
|
+
export const useShareTimeline = createTaroHook('onShareTimeline')
|
|
79
|
+
export const useTitleClick = createTaroHook('onTitleClick')
|
|
80
|
+
|
|
81
|
+
/** Router */
|
|
82
|
+
export const useReady = createTaroHook('onReady')
|
|
83
|
+
export const useRouter = (dynamic = false) => {
|
|
84
|
+
return dynamic ? Current.router : createMemo(() => Current.router)
|
|
85
|
+
}
|
|
86
|
+
export const useTabItemTap = createTaroHook('onTabItemTap')
|
|
87
|
+
|
|
88
|
+
export const useScope = () => undefined
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Current } from '@tarojs/runtime'
|
|
2
|
+
import { isArray, isFunction, isUndefined } from '@tarojs/shared'
|
|
3
|
+
|
|
4
|
+
import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './contant'
|
|
5
|
+
import { incrementId } from './utils'
|
|
6
|
+
|
|
7
|
+
// TODO TYPE
|
|
8
|
+
const instances = new Map<string, any>()
|
|
9
|
+
const pageId = incrementId()
|
|
10
|
+
|
|
11
|
+
// TODO TYPE
|
|
12
|
+
export function injectPageInstance (inst: any, id: string) {
|
|
13
|
+
instances.set(id, inst)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// TODO TYPE
|
|
17
|
+
export function getPageInstance (id: string): any {
|
|
18
|
+
return instances.get(id)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function removePageInstance (id: string) {
|
|
22
|
+
instances.delete(id)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function addLeadingSlash (path?: string): string {
|
|
26
|
+
if (path == null) {
|
|
27
|
+
return ''
|
|
28
|
+
}
|
|
29
|
+
return path.charAt(0) === '/' ? path : '/' + path
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function safeExecute (path: string, lifecycle: string, ...args: unknown[]) {
|
|
33
|
+
const instance = instances.get(path)
|
|
34
|
+
|
|
35
|
+
if (instance == null) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const func = instance[lifecycle]
|
|
40
|
+
|
|
41
|
+
if (isArray(func)) {
|
|
42
|
+
const res = func.map(fn => fn.apply(instance, args))
|
|
43
|
+
return res[0]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!isFunction(func)) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return func.apply(instance, args)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function stringify (obj?: Record<string, unknown>) {
|
|
54
|
+
if (obj == null) {
|
|
55
|
+
return ''
|
|
56
|
+
}
|
|
57
|
+
const path = Object.keys(obj).map((key) => {
|
|
58
|
+
return key + '=' + obj[key]
|
|
59
|
+
}).join('&')
|
|
60
|
+
return path === '' ? path : '?' + path
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getPath (id: string, options?: Record<string, unknown>): string {
|
|
64
|
+
const idx = id.indexOf('?')
|
|
65
|
+
|
|
66
|
+
return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getOnReadyEventKey (path: string) {
|
|
70
|
+
return path + '.' + ON_READY
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getOnShowEventKey (path: string) {
|
|
74
|
+
return path + '.' + ON_SHOW
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getOnHideEventKey (path: string) {
|
|
78
|
+
return path + '.' + ON_HIDE
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function createPageConfig (component: any, pageName?: string) {
|
|
82
|
+
// 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上
|
|
83
|
+
const id = pageName ?? `taro_page_${pageId()}`
|
|
84
|
+
// TODO TYPE
|
|
85
|
+
let pageElement: any = null
|
|
86
|
+
let unmounting = false
|
|
87
|
+
let prepareMountList: (() => void)[] = []
|
|
88
|
+
|
|
89
|
+
// TODO TYPE
|
|
90
|
+
function setCurrentRouter (page) {
|
|
91
|
+
const router = page.route || page.__route__ || page.$taroPath
|
|
92
|
+
|
|
93
|
+
Current.router = {
|
|
94
|
+
params: page.$taroParams!,
|
|
95
|
+
path: addLeadingSlash(router),
|
|
96
|
+
$taroPath: page.$taroPath,
|
|
97
|
+
onReady: getOnReadyEventKey(id),
|
|
98
|
+
onShow: getOnShowEventKey(id),
|
|
99
|
+
onHide: getOnHideEventKey(id)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!isUndefined(page.exitState)) {
|
|
103
|
+
Current.router.exitState = page.exitState
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let loadResolver: (...args: any[]) => void
|
|
108
|
+
let hasLoaded: Promise<void>
|
|
109
|
+
const page = {
|
|
110
|
+
onLoad (options: Readonly<Record<string, unknown>> = {}, cb?: (...args: any[]) => any) {
|
|
111
|
+
hasLoaded = new Promise(resolve => { loadResolver = resolve })
|
|
112
|
+
|
|
113
|
+
Current.page = this as any
|
|
114
|
+
|
|
115
|
+
// this.$taroPath 是页面唯一标识
|
|
116
|
+
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() })
|
|
117
|
+
const $taroPath = this.$taroPath = getPath(id, uniqueOptions)
|
|
118
|
+
|
|
119
|
+
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
120
|
+
if (this.$taroParams == null) {
|
|
121
|
+
this.$taroParams = uniqueOptions
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
setCurrentRouter(this)
|
|
125
|
+
|
|
126
|
+
// window.trigger(CONTEXT_ACTIONS.INIT, $taroPath)
|
|
127
|
+
|
|
128
|
+
const mount = () => {
|
|
129
|
+
Current.app!.mount!(component, $taroPath, () => {
|
|
130
|
+
// TODO TYPE env
|
|
131
|
+
// pageElement = document.getElementById($taroPath)
|
|
132
|
+
|
|
133
|
+
// if (!pageElement) {
|
|
134
|
+
// throw new Error(`没有找到页面实例。`)
|
|
135
|
+
// }
|
|
136
|
+
|
|
137
|
+
safeExecute($taroPath, ON_LOAD, this.$taroParams)
|
|
138
|
+
loadResolver()
|
|
139
|
+
cb && cb()
|
|
140
|
+
// pageElement.ctx = this
|
|
141
|
+
// pageElement.performUpdate(true, cb)
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (unmounting) {
|
|
146
|
+
prepareMountList.push(mount)
|
|
147
|
+
} else {
|
|
148
|
+
mount()
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
onUnLoad () {
|
|
152
|
+
const $taroPath = this.$taroPath
|
|
153
|
+
// 销毁当前页面的上下文信息
|
|
154
|
+
// window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
|
|
155
|
+
|
|
156
|
+
// 触发onUnload生命周期
|
|
157
|
+
safeExecute($taroPath, ON_UNLOAD)
|
|
158
|
+
unmounting = true
|
|
159
|
+
Current.app!.unmount!($taroPath, () => {
|
|
160
|
+
unmounting = false
|
|
161
|
+
instances.delete($taroPath)
|
|
162
|
+
if (pageElement) {
|
|
163
|
+
pageElement.ctx = null
|
|
164
|
+
pageElement = null
|
|
165
|
+
}
|
|
166
|
+
if (prepareMountList.length) {
|
|
167
|
+
prepareMountList.forEach(fn => fn())
|
|
168
|
+
prepareMountList = []
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
},
|
|
172
|
+
onShow (options = {}) {
|
|
173
|
+
hasLoaded.then(() => {
|
|
174
|
+
// 设置 Current 的 page 和 router
|
|
175
|
+
Current.page = this as any
|
|
176
|
+
setCurrentRouter(this)
|
|
177
|
+
// 恢复上下文信息
|
|
178
|
+
// window.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath)
|
|
179
|
+
// 触发生命周期
|
|
180
|
+
safeExecute(this.$taroPath, ON_SHOW, options)
|
|
181
|
+
// TODO 通过事件触发子组件的生命周期
|
|
182
|
+
// raf(() => eventCenter.trigger(getOnShowEventKey(id)))
|
|
183
|
+
})
|
|
184
|
+
},
|
|
185
|
+
onHide () {
|
|
186
|
+
// 缓存当前页面上下文信息
|
|
187
|
+
// window.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath)
|
|
188
|
+
|
|
189
|
+
// 设置 Current 的 page 和 router
|
|
190
|
+
if (Current.page === this) {
|
|
191
|
+
Current.page = null
|
|
192
|
+
Current.router = null
|
|
193
|
+
}
|
|
194
|
+
// 触发生命周期
|
|
195
|
+
safeExecute(this.$taroPath, ON_HIDE)
|
|
196
|
+
// TODO 通过事件触发子组件的生命周期
|
|
197
|
+
// eventCenter.trigger(getOnHideEventKey(id))
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return page
|
|
202
|
+
}
|