@tarojs/plugin-framework-react 4.0.0-canary.1 → 4.0.0-canary.11
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 +14 -0
- package/dist/api-loader.js.map +1 -1
- package/dist/index.js +164 -32
- package/dist/index.js.map +1 -1
- package/dist/reconciler.js +347 -0
- package/dist/reconciler.js.map +1 -0
- package/dist/runtime.js +291 -61
- package/dist/runtime.js.map +1 -1
- package/package.json +19 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconciler.js","sources":["../src/runtime/reconciler/h.ts","../src/runtime/reconciler/props.ts","../src/runtime/reconciler/render.ts","../src/runtime/reconciler/use.ts","../src/runtime/reconciler/index.ts"],"sourcesContent":["import { TaroNode } from '@tarojs/runtime'\nimport { children as solidChildren, createRenderEffect, onCleanup, splitProps } from 'solid-js'\n\nimport { createElement, createTextNode, effect, insert, insertNode, setProp } from './render'\n\nimport type { Accessor } from 'solid-js'\nimport type { ResolvedChildren } from 'solid-js/types/reactive/signal'\n\nexport type Component = (props?: any) => TaroNode\n\ntype Children =\n | undefined\n | string\n | number\n | TaroNode\n | TaroNode[]\n | Component\n | Component[]\n | Accessor<ResolvedChildren>\n | (() => Component[])\n\nexport function h(tagName: string, props?: any, children?: Children) {\n if (typeof tagName !== 'string') {\n throw Error(`h function cant create ele for ${tagName}`)\n }\n const ele = createElement(tagName)\n const [local, otherProps] = splitProps(props, ['ref', 'children'])\n\n setProps(ele, otherProps)\n\n if (local.ref) {\n createRenderEffect(() => {\n if (typeof local.ref === 'function') {\n local.ref(ele)\n } else {\n local.ref = ele\n }\n })\n }\n\n // get 的处理\n if (local.hasOwnProperty('children')) {\n const descriptor = Object.getOwnPropertyDescriptor(local, 'children')\n if (descriptor?.get) {\n children = solidChildren(() => local.children)\n } else {\n children = local.children\n }\n }\n insertNodes(ele, children)\n\n return ele\n}\n\nfunction setProps(ele: TaroNode, otherProps: Record<string, any> = {}) {\n const desc = { ...otherProps }\n const plain_keys = Object.keys(desc).filter((key) => {\n if (desc[key]?.get) {\n return false\n }\n return true\n })\n const [plainProps, getterValues] = splitProps(otherProps, plain_keys)\n\n // 普通属性直接赋值\n if (Object.keys(plainProps)?.length) {\n for (const key in plainProps) {\n setProp(ele, key, plainProps[key])\n }\n }\n\n // 特殊属性 放到createRenderEffect中\n if (Object.keys(getterValues)?.length) {\n let preProps = {} as typeof getterValues\n effect(() => {\n for (const key in getterValues) {\n const val = getterValues[key]\n\n if (val === preProps[key]) {\n continue\n }\n setProp(ele, key, val, preProps[key])\n preProps[key] = val\n }\n })\n onCleanup(() => {\n preProps = {}\n })\n }\n}\n\nfunction insertNodes(parent: TaroNode, children: Children) {\n if (children === undefined) {\n return\n }\n\n let list = [] as TaroNode[] | (() => TaroNode)[]\n if (!Array.isArray(children)) {\n list = [children] as TaroNode[] | (() => TaroNode)[]\n } else {\n list = children\n }\n for (let i = 0; i < list.length; i++) {\n const child = list[i]\n const type = typeof child\n if (type === 'function') {\n insert(parent, child, null)\n continue\n }\n if (Array.isArray(child)) {\n insertNodes(parent, child)\n continue\n }\n\n if (child instanceof TaroNode) {\n insertNode(parent, child)\n continue\n }\n\n if (type === 'string') {\n const node = createTextNode(child as unknown as string)\n insertNode(parent, node)\n continue\n }\n\n if (type === 'number' || type === 'boolean' || child instanceof Date || child instanceof RegExp) {\n const node = createTextNode(child.toString())\n insertNode(parent, node)\n continue\n }\n }\n}\n","import { FormElement } from '@tarojs/runtime'\nimport { capitalize, internalComponents, isFunction, isObject, toCamelCase } from '@tarojs/shared'\n\nimport type { TaroElement } from '@tarojs/runtime'\n\nexport type Props = Record<string, unknown>\n\nfunction isEventName (s: string) {\n return s[0] === 'o' && s[1] === 'n'\n}\n\nexport function updateProps (dom: TaroElement, oldProps: Props, newProps: Props) {\n const updatePayload = getUpdatePayload(dom, oldProps, newProps)\n if (updatePayload){\n updatePropsByPayload(dom, oldProps, updatePayload)\n }\n}\n\nexport function updatePropsByPayload (dom: TaroElement, oldProps: Props, updatePayload: any[]){\n for (let i = 0; i < updatePayload.length; i += 2){ // key, value 成对出现\n const key = updatePayload[i]; const newProp = updatePayload[i+1]; const oldProp = oldProps[key]\n setProperty(dom, key, newProp, oldProp)\n }\n}\n\nexport function getUpdatePayload (dom: TaroElement, oldProps: Props, newProps: Props){\n let i: string\n let updatePayload: any[] | null = null\n\n for (i in oldProps) {\n if (!(i in newProps)) {\n (updatePayload = updatePayload || []).push(i, null)\n }\n }\n const isFormElement = dom instanceof FormElement\n for (i in newProps) {\n if (oldProps[i] !== newProps[i] || (isFormElement && i === 'value')) {\n (updatePayload = updatePayload || []).push(i, newProps[i])\n }\n }\n\n return updatePayload\n}\n\n// function eventProxy (e: CommonEvent) {\n// const el = document.getElementById(e.currentTarget.id)\n// const handlers = el!.__handlers[e.type]\n// handlers[0](e)\n// }\n\nfunction setEvent (dom: TaroElement, name: string, value: unknown, oldValue?: unknown) {\n const isCapture = name.endsWith('Capture')\n let eventName = name.toLowerCase().slice(2)\n if (isCapture) {\n eventName = eventName.slice(0, -7)\n }\n\n const compName = capitalize(toCamelCase(dom.tagName.toLowerCase()))\n\n if (eventName === 'click' && process.env.TARO_PLATFORM !== 'harmony' && compName in internalComponents) {\n eventName = 'tap'\n }\n\n if (isFunction(value)) {\n if (oldValue) {\n dom.removeEventListener(eventName, oldValue as any, false)\n dom.addEventListener(eventName, value, { isCapture, sideEffect: false })\n } else {\n dom.addEventListener(eventName, value, isCapture)\n }\n } else {\n dom.removeEventListener(eventName, oldValue as any)\n }\n}\n\ninterface DangerouslySetInnerHTML {\n __html?: string\n}\ntype ClassList = { [key: string]: boolean }\n\nfunction diffClassList (newVal: ClassList, oldVal: ClassList) {\n const result: ClassList = {}\n for (const key in oldVal) {\n if (newVal[key] !== oldVal[key]) {\n result[key] = newVal[key]\n }\n }\n for (const key in newVal) {\n if (result.hasOwnProperty(key)) {\n continue\n }\n result[key] = newVal[key]\n }\n return result\n}\n\nexport function setProperty (dom: TaroElement, name: string, value: unknown, oldValue?: unknown) {\n name = name === 'className' ? 'class' : name\n\n if (['key', 'children', 'ref'].includes(name)) return\n\n if (name === 'classList') {\n const map = diffClassList(value as ClassList, oldValue as ClassList)\n for (const key in map) {\n if (key === '') {\n continue\n }\n if (map[key]) {\n (dom as any).classList.add(key)\n } else {\n (dom as any).classList.remove(key)\n }\n }\n } else if (isEventName(name)) {\n setEvent(dom, name, value, oldValue)\n } else if (name === 'dangerouslySetInnerHTML') {\n const newHtml = (value as DangerouslySetInnerHTML)?.__html ?? ''\n const oldHtml = (oldValue as DangerouslySetInnerHTML)?.__html ?? ''\n if (newHtml || oldHtml) {\n if (oldHtml !== newHtml) {\n dom.innerHTML = newHtml\n }\n }\n } else if (!isFunction(value)) {\n if (value == null) {\n dom.removeAttribute(name)\n } else {\n // 处理对象类型的style样式\n if (name === 'style' && isObject(value)) {\n value = Object.keys(value).reduce((acc, key) => {\n acc.push(`${key}: ${(value as Record<string, string>)[key]}`)\n return acc\n }, [] as string[]).join(';')\n }\n dom.setAttribute(name, value as string)\n }\n }\n}\n","import { document, TaroText } from '@tarojs/runtime'\nimport { isFunction, isString } from '@tarojs/shared'\nimport { createRenderer } from 'solid-js/universal'\n\nimport { h } from './h'\nimport { setProperty } from './props'\n\nimport type { TaroElement, TaroNode } from '@tarojs/runtime'\n\nconst renderer = createRenderer<TaroNode>({\n createElement(type: string) {\n return document.createElement(type)\n },\n createTextNode(text) {\n return document.createTextNode(text)\n },\n replaceText(textNode, value) {\n textNode.textContent = value\n },\n setProperty(node: TaroElement, name: string, value, prev) {\n setProperty(node, name, value, prev)\n },\n insertNode(parent, node, anchor) {\n parent.insertBefore(node, anchor)\n },\n isTextNode(node: TaroNode) {\n if (isString(node)) return true\n return node instanceof TaroText\n },\n removeNode(parent: TaroElement, node: TaroElement) {\n parent.removeChild(node)\n },\n getParentNode(node: TaroNode) {\n return node.parentNode || undefined\n },\n getFirstChild(node: TaroElement) {\n return node.firstChild || undefined\n },\n getNextSibling(node: TaroElement) {\n return node.nextSibling || undefined\n },\n})\n\nexport const render = renderer.render\nexport const effect = renderer.effect\nexport const memo = renderer.memo\nexport const createComponent = (type, props?) => {\n if (isString(type)) return h(type, props)\n if (isFunction(type)) return renderer.createComponent(type, props)\n return renderer.createComponent(Fragment, props)\n}\nexport const createElement = renderer.createElement\nexport const createTextNode = renderer.createTextNode\nexport const insertNode = renderer.insertNode\nexport const insert = renderer.insert\nexport const spread = renderer.spread\nexport const setProp = renderer.setProp\nexport const mergeProps = renderer.mergeProps\nexport const use = renderer.use\n\nfunction Fragment(props) {\n return props.children\n}\nfunction jsx(type, props) {\n return h(type, props)\n}\n\nexport { Fragment, jsx, jsx as jsxDEV, jsx as jsxs }\n","import { noop } from '@tarojs/shared'\nimport { batch } from 'solid-js'\n\nexport function flushSync () {\n batch(noop)\n}\n\nexport function unstable_batchedUpdates (fn) {\n batch(fn)\n}\n","import {\n $DEVCOMP,\n ComponentProps,\n createEffect,\n createMemo,\n getOwner,\n JSX,\n onCleanup,\n runWithOwner,\n sharedConfig,\n splitProps,\n untrack,\n ValidComponent\n} from 'solid-js'\n\nimport { createElement, insert, spread } from './render'\n\nexport * from './props'\nexport * from './render'\nexport * from './use'\n\nexport function Portal<T extends boolean = false, S extends boolean = false> (props: {\n mount?: Node\n ref?:\n | (S extends true ? SVGGElement : HTMLDivElement)\n | ((\n el: (T extends true ? { readonly shadowRoot: ShadowRoot } : object) & (S extends true ? SVGGElement : HTMLDivElement)\n ) => void)\n children: JSX.Element\n}) {\n const marker = document.createTextNode('')\n const mount = () => props.mount || document.body\n const owner = getOwner()\n let content: undefined | (() => JSX.Element)\n let hydrating = !!sharedConfig.context\n\n createEffect(\n () => {\n // basically we backdoor into a sort of renderEffect here\n if (hydrating) (getOwner() as any).user = hydrating = false\n content || (content = runWithOwner(owner, () => createMemo(() => props.children)))\n const el = mount()\n const container: any = createElement('view')\n const renderRoot = container\n\n Object.defineProperty(container, '_$host', {\n get () {\n return marker.parentNode\n },\n configurable: true\n })\n insert(renderRoot, content)\n el.appendChild(container)\n props.ref && (props as any).ref(container)\n onCleanup(() => el.removeChild(container))\n\n },\n undefined,\n { render: !hydrating }\n )\n return marker\n}\n\nexport type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = {\n [K in keyof P]: P[K];\n} & {\n component: T | undefined\n};\n\nexport function Dynamic<T extends ValidComponent> (props: DynamicProps<T>): JSX.Element {\n const [p, others] = splitProps(props, ['component'])\n const cached = createMemo(() => p.component)\n return createMemo(() => {\n const component = cached()\n switch (typeof component) {\n case 'function':\n // eslint-disable-next-line no-constant-condition\n if ('_DX_DEV_') Object.assign(component, { [$DEVCOMP]: true })\n return untrack(() => component(others))\n\n case 'string':\n // eslint-disable-next-line no-case-declarations\n const el = createElement(component)\n spread(el, others, false)\n return el\n\n default:\n break\n }\n }) as unknown as JSX.Element\n}\n"],"names":["children","solidChildren","document"],"mappings":";;;;;SAqBgB,CAAC,CAAC,OAAe,EAAE,KAAW,EAAEA,UAAmB,EAAA;AACjE,IAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;AAC/B,QAAA,MAAM,KAAK,CAAC,CAAA,+BAAA,EAAkC,OAAO,CAAA,CAAE,CAAC,CAAA;KACzD;AACD,IAAA,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;AAClC,IAAA,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAA;AAElE,IAAA,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;AAEzB,IAAA,IAAI,KAAK,CAAC,GAAG,EAAE;QACb,kBAAkB,CAAC,MAAK;AACtB,YAAA,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,EAAE;AACnC,gBAAA,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;aACf;iBAAM;AACL,gBAAA,KAAK,CAAC,G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OAAO,CAA4B,KAAsB,EAAA;AACvE,IAAA,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IACpD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAA;IAC5C,OAAO,UAAU,CAAC,MAAK;AACrB,QAAA,MAAM,SAAS,GAAG,MAAM,EAAE,CAAA;QAC1B,QAAQ,OAAO,SAAS;AACtB,YAAA,KAAK,UAAU;;AAEb,gBAAgB,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAA;gBAC9D,OAAO,OAAO,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AAEzC,YAAA,KAAK,QAAQ;;AAEX,gBAAA,MAAM,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;AACnC,gBAAA,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACzB,gBAAA,OAAO,EAAE,CAAA;SAIZ;AACH,KAAC,CAA2B,CAAA;AAC9B;;;;"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { EMPTY_OBJ, isFunction, isArray,
|
|
2
|
-
import { Current, getPageInstance, injectPageInstance, incrementId, document, getPath, window, CONTEXT_ACTIONS, safeExecute, removePageInstance, ON_READY, requestAnimationFrame, eventCenter, getOnReadyEventKey, ON_SHOW, getOnShowEventKey, ON_HIDE, getOnHideEventKey, eventHandler, addLeadingSlash } from '@tarojs/runtime';
|
|
1
|
+
import { EMPTY_OBJ, isFunction, isArray, hooks, ensure, isUndefined } from '@tarojs/shared';
|
|
2
|
+
import { Current, getPageInstance, injectPageInstance, incrementId, document, perf, PAGE_INIT, getPath, window, CONTEXT_ACTIONS, safeExecute, removePageInstance, ON_READY, requestAnimationFrame, eventCenter, getOnReadyEventKey, ON_SHOW, getOnShowEventKey, ON_HIDE, getOnHideEventKey, eventHandler, addLeadingSlash } from '@tarojs/runtime';
|
|
3
|
+
import * as Solid from 'solid-js';
|
|
4
|
+
import { createContext, createMemo, useContext, createRenderEffect, onCleanup } from 'solid-js';
|
|
5
|
+
import * as SolidReconciler from '@tarojs/plugin-framework-react/dist/reconciler';
|
|
3
6
|
|
|
4
7
|
const reactMeta = {
|
|
5
8
|
PageContext: EMPTY_OBJ,
|
|
6
|
-
R: EMPTY_OBJ
|
|
9
|
+
R: EMPTY_OBJ,
|
|
10
|
+
};
|
|
11
|
+
const solidMeta = {
|
|
12
|
+
PageContext: createContext(''),
|
|
7
13
|
};
|
|
8
14
|
|
|
9
15
|
const HOOKS_APP_ID = 'taro-app';
|
|
@@ -44,49 +50,87 @@ function setRouterParams(options) {
|
|
|
44
50
|
|
|
45
51
|
const createTaroHook = (lifecycle) => {
|
|
46
52
|
return (fn) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
fnRef.current
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// callback is immutable but inner function is up to date
|
|
63
|
-
const callback = (...args) => fnRef.current(...args);
|
|
64
|
-
if (isFunction(inst[lifecycle])) {
|
|
65
|
-
(inst[lifecycle]) = [inst[lifecycle], callback];
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
(inst[lifecycle]) = [
|
|
69
|
-
...((inst[lifecycle]) || []),
|
|
70
|
-
callback
|
|
71
|
-
];
|
|
72
|
-
}
|
|
73
|
-
if (first) {
|
|
74
|
-
injectPageInstance(inst, id);
|
|
75
|
-
}
|
|
76
|
-
return () => {
|
|
77
|
-
const inst = instRef.current;
|
|
78
|
-
if (!inst)
|
|
79
|
-
return;
|
|
80
|
-
const list = inst[lifecycle];
|
|
81
|
-
if (list === callback) {
|
|
82
|
-
(inst[lifecycle]) = undefined;
|
|
53
|
+
if (process.env.FRAMEWORK !== 'solid') {
|
|
54
|
+
const { R: React, PageContext } = reactMeta;
|
|
55
|
+
const id = React.useContext(PageContext) || HOOKS_APP_ID;
|
|
56
|
+
const instRef = React.useRef();
|
|
57
|
+
// hold fn ref and keep up to date
|
|
58
|
+
const fnRef = React.useRef(fn);
|
|
59
|
+
if (fnRef.current !== fn)
|
|
60
|
+
fnRef.current = fn;
|
|
61
|
+
React.useLayoutEffect(() => {
|
|
62
|
+
let inst = instRef.current = getPageInstance(id);
|
|
63
|
+
let first = false;
|
|
64
|
+
if (!inst) {
|
|
65
|
+
first = true;
|
|
66
|
+
instRef.current = Object.create(null);
|
|
67
|
+
inst = instRef.current;
|
|
83
68
|
}
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
// callback is immutable but inner function is up to date
|
|
70
|
+
const callback = (...args) => fnRef.current(...args);
|
|
71
|
+
if (isFunction(inst[lifecycle])) {
|
|
72
|
+
(inst[lifecycle]) = [inst[lifecycle], callback];
|
|
86
73
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
else {
|
|
75
|
+
(inst[lifecycle]) = [
|
|
76
|
+
...((inst[lifecycle]) || []),
|
|
77
|
+
callback
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
if (first) {
|
|
81
|
+
injectPageInstance(inst, id);
|
|
82
|
+
}
|
|
83
|
+
return () => {
|
|
84
|
+
const inst = instRef.current;
|
|
85
|
+
if (!inst)
|
|
86
|
+
return;
|
|
87
|
+
const list = inst[lifecycle];
|
|
88
|
+
if (list === callback) {
|
|
89
|
+
(inst[lifecycle]) = undefined;
|
|
90
|
+
}
|
|
91
|
+
else if (isArray(list)) {
|
|
92
|
+
(inst[lifecycle]) = list.filter(item => item !== callback);
|
|
93
|
+
}
|
|
94
|
+
instRef.current = undefined;
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const context = useContext(solidMeta.PageContext);
|
|
100
|
+
const id = context || HOOKS_APP_ID;
|
|
101
|
+
createRenderEffect(() => {
|
|
102
|
+
let inst = getPageInstance(id);
|
|
103
|
+
let first = false;
|
|
104
|
+
if (!inst) {
|
|
105
|
+
first = true;
|
|
106
|
+
inst = Object.create({
|
|
107
|
+
id: id,
|
|
108
|
+
type: 'page',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (isFunction(inst[lifecycle])) {
|
|
112
|
+
inst[lifecycle] = [inst[lifecycle], fn];
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
inst[lifecycle] = [
|
|
116
|
+
...((inst[lifecycle]) || []),
|
|
117
|
+
fn
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
if (first) {
|
|
121
|
+
injectPageInstance(inst, id);
|
|
122
|
+
}
|
|
123
|
+
onCleanup(() => {
|
|
124
|
+
const list = inst[lifecycle];
|
|
125
|
+
if (list === fn) {
|
|
126
|
+
(inst[lifecycle]) = undefined;
|
|
127
|
+
}
|
|
128
|
+
else if (isArray(list)) {
|
|
129
|
+
(inst[lifecycle]) = list.filter(item => item !== fn);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
90
134
|
};
|
|
91
135
|
};
|
|
92
136
|
/** LifeCycle */
|
|
@@ -115,8 +159,13 @@ const useTitleClick = createTaroHook('onTitleClick');
|
|
|
115
159
|
/** Router */
|
|
116
160
|
const useReady = createTaroHook('onReady');
|
|
117
161
|
const useRouter = (dynamic = false) => {
|
|
118
|
-
|
|
119
|
-
|
|
162
|
+
if (process.env.FRAMEWORK !== 'solid') {
|
|
163
|
+
const React = reactMeta.R;
|
|
164
|
+
return dynamic ? Current.router : React.useMemo(() => Current.router, []);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return dynamic ? Current.router : createMemo(() => Current.router);
|
|
168
|
+
}
|
|
120
169
|
};
|
|
121
170
|
const useTabItemTap = createTaroHook('onTabItemTap');
|
|
122
171
|
const useScope = () => undefined;
|
|
@@ -152,7 +201,6 @@ let h$1;
|
|
|
152
201
|
let ReactDOM$1;
|
|
153
202
|
let Fragment;
|
|
154
203
|
const pageKeyId = incrementId();
|
|
155
|
-
const isWeb = isWebPlatform();
|
|
156
204
|
function setReconciler(ReactDOM) {
|
|
157
205
|
hooks.tap('getLifecycle', function (instance, lifecycle) {
|
|
158
206
|
lifecycle = lifecycle.replace(/^on(Show|Hide)$/, 'componentDid$1');
|
|
@@ -165,7 +213,12 @@ function setReconciler(ReactDOM) {
|
|
|
165
213
|
});
|
|
166
214
|
});
|
|
167
215
|
hooks.tap('batchedEventUpdates', function (cb) {
|
|
168
|
-
|
|
216
|
+
if (process.env.FRAMEWORK !== 'solid') {
|
|
217
|
+
ReactDOM === null || ReactDOM === void 0 ? void 0 : ReactDOM.unstable_batchedUpdates(cb);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
Solid.batch(cb);
|
|
221
|
+
}
|
|
169
222
|
});
|
|
170
223
|
hooks.tap('mergePageInstance', function (prev, next) {
|
|
171
224
|
if (!prev || !next)
|
|
@@ -180,7 +233,8 @@ function setReconciler(ReactDOM) {
|
|
|
180
233
|
next[item] = nextList.concat(prevList);
|
|
181
234
|
});
|
|
182
235
|
});
|
|
183
|
-
|
|
236
|
+
// TODO 使用 solid 时,暂不支持以下事件
|
|
237
|
+
if (process.env.TARO_PLATFORM === 'web' && process.env.FRAMEWORK !== 'solid') {
|
|
184
238
|
hooks.tap('createPullDownComponent', (el, _, R, customWrapper) => {
|
|
185
239
|
const isReactComponent = isClassComponent(R, el);
|
|
186
240
|
return R.forwardRef((props, ref) => {
|
|
@@ -193,8 +247,19 @@ function setReconciler(ReactDOM) {
|
|
|
193
247
|
return h$1(customWrapper || 'taro-pull-to-refresh-core', null, h$1(el, Object.assign(Object.assign({}, newProps), refs)));
|
|
194
248
|
});
|
|
195
249
|
});
|
|
196
|
-
hooks.tap('getDOMNode', inst => {
|
|
197
|
-
|
|
250
|
+
hooks.tap('getDOMNode', (inst) => {
|
|
251
|
+
// 由于react 18移除了ReactDOM.findDOMNode方法,修复H5端 Taro.createSelectorQuery设置in(scope)时,报错问题
|
|
252
|
+
// https://zh-hans.react.dev/reference/react-dom/findDOMNode
|
|
253
|
+
if (!inst) {
|
|
254
|
+
return document;
|
|
255
|
+
}
|
|
256
|
+
else if (inst instanceof HTMLElement) {
|
|
257
|
+
return inst;
|
|
258
|
+
}
|
|
259
|
+
else if (inst.$taroPath) {
|
|
260
|
+
const el = document.getElementById(inst.$taroPath);
|
|
261
|
+
return el !== null && el !== void 0 ? el : document;
|
|
262
|
+
}
|
|
198
263
|
});
|
|
199
264
|
}
|
|
200
265
|
}
|
|
@@ -235,7 +300,7 @@ function connectReactPage(R, id) {
|
|
|
235
300
|
const children = this.state.hasError
|
|
236
301
|
? []
|
|
237
302
|
: h$1(reactMeta.PageContext.Provider, { value: id }, h$1(Page, Object.assign(Object.assign({}, this.props), refs)));
|
|
238
|
-
if (
|
|
303
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
239
304
|
return h$1('div', { id, className: 'taro_page' }, children);
|
|
240
305
|
}
|
|
241
306
|
else {
|
|
@@ -255,7 +320,7 @@ function connectReactPage(R, id) {
|
|
|
255
320
|
*/
|
|
256
321
|
function createReactApp(App, react, dom, config) {
|
|
257
322
|
if (process.env.NODE_ENV !== 'production') {
|
|
258
|
-
ensure(!!dom, '构建 React/Nerv 项目请把 process.env.FRAMEWORK 设置为 \'react\'/\'nerv\' ');
|
|
323
|
+
ensure(!!dom, '构建 React/Nerv 项目请把 process.env.FRAMEWORK 设置为 \'react\'/\'preact\'/\'nerv\' ');
|
|
259
324
|
}
|
|
260
325
|
reactMeta.R = react;
|
|
261
326
|
h$1 = react.createElement;
|
|
@@ -276,7 +341,7 @@ function createReactApp(App, react, dom, config) {
|
|
|
276
341
|
function renderReactRoot() {
|
|
277
342
|
var _a, _b;
|
|
278
343
|
let appId = 'app';
|
|
279
|
-
if (
|
|
344
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
280
345
|
appId = (config === null || config === void 0 ? void 0 : config.appId) || appId;
|
|
281
346
|
}
|
|
282
347
|
const container = document.getElementById(appId);
|
|
@@ -303,7 +368,10 @@ function createReactApp(App, react, dom, config) {
|
|
|
303
368
|
const key = id + pageKeyId();
|
|
304
369
|
const page = () => h$1(pageWrapper, { key, tid: id });
|
|
305
370
|
this.pages.push(page);
|
|
306
|
-
this.forceUpdate(
|
|
371
|
+
this.forceUpdate((...args) => {
|
|
372
|
+
perf.stop(PAGE_INIT);
|
|
373
|
+
return cb(...args);
|
|
374
|
+
});
|
|
307
375
|
}
|
|
308
376
|
unmount(id, cb) {
|
|
309
377
|
const elements = this.elements;
|
|
@@ -321,10 +389,10 @@ function createReactApp(App, react, dom, config) {
|
|
|
321
389
|
if (isReactComponent) {
|
|
322
390
|
props = { ref: appInstanceRef };
|
|
323
391
|
}
|
|
324
|
-
return h$1(App, props,
|
|
392
|
+
return h$1(App, props, process.env.TARO_PLATFORM === 'web' ? h$1(Fragment !== null && Fragment !== void 0 ? Fragment : 'div', null, elements.slice()) : elements.slice());
|
|
325
393
|
}
|
|
326
394
|
}
|
|
327
|
-
if (
|
|
395
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
328
396
|
renderReactRoot();
|
|
329
397
|
}
|
|
330
398
|
const [ONLAUNCH, ONSHOW, ONHIDE] = hooks.call('getMiniLifecycleImpl').app;
|
|
@@ -351,7 +419,7 @@ function createReactApp(App, react, dom, config) {
|
|
|
351
419
|
[ONLAUNCH]: setDefaultDescriptor({
|
|
352
420
|
value(options) {
|
|
353
421
|
setRouterParams(options);
|
|
354
|
-
if (
|
|
422
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
355
423
|
// 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后执行 render
|
|
356
424
|
renderReactRoot();
|
|
357
425
|
}
|
|
@@ -470,6 +538,161 @@ function createReactApp(App, react, dom, config) {
|
|
|
470
538
|
Current.app = appObj;
|
|
471
539
|
return appObj;
|
|
472
540
|
}
|
|
541
|
+
function createSolidApp(App, config) {
|
|
542
|
+
setReconciler();
|
|
543
|
+
const appRef = {
|
|
544
|
+
mount: () => { },
|
|
545
|
+
unmount: () => { },
|
|
546
|
+
};
|
|
547
|
+
function getAppInstance() {
|
|
548
|
+
return appRef;
|
|
549
|
+
}
|
|
550
|
+
function AppWrapper() {
|
|
551
|
+
const [pages, setPages] = Solid.createSignal([]);
|
|
552
|
+
appRef.mount = (component, id) => {
|
|
553
|
+
setPages((old) => {
|
|
554
|
+
return [...old, { id, component }];
|
|
555
|
+
});
|
|
556
|
+
};
|
|
557
|
+
appRef.unmount = (id) => {
|
|
558
|
+
setPages(pages().filter((item) => {
|
|
559
|
+
return item.id !== id;
|
|
560
|
+
}));
|
|
561
|
+
};
|
|
562
|
+
return SolidReconciler.createComponent(App, {
|
|
563
|
+
ref: appRef,
|
|
564
|
+
children: SolidReconciler.createComponent(Solid.For, {
|
|
565
|
+
get each() {
|
|
566
|
+
return pages();
|
|
567
|
+
},
|
|
568
|
+
children: ({ id, component }) => {
|
|
569
|
+
const children = () => SolidReconciler.createComponent(solidMeta.PageContext.Provider, {
|
|
570
|
+
value: id,
|
|
571
|
+
children: () => {
|
|
572
|
+
injectPageInstance({ id: id, type: 'page' }, id);
|
|
573
|
+
return SolidReconciler.createComponent(component, {
|
|
574
|
+
tid: id,
|
|
575
|
+
});
|
|
576
|
+
},
|
|
577
|
+
});
|
|
578
|
+
const root = process.env.TARO_PLATFORM === 'web'
|
|
579
|
+
? document.createElement('div')
|
|
580
|
+
: SolidReconciler.createElement('root');
|
|
581
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
582
|
+
root.setAttribute('id', id);
|
|
583
|
+
root.classList.add('taro_page');
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
SolidReconciler.setProp(root, 'id', id);
|
|
587
|
+
}
|
|
588
|
+
SolidReconciler.insert(root, children);
|
|
589
|
+
return root;
|
|
590
|
+
},
|
|
591
|
+
}),
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
function renderSolidRoot() {
|
|
595
|
+
let appId = 'app';
|
|
596
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
597
|
+
appId = (config === null || config === void 0 ? void 0 : config.appId) || appId;
|
|
598
|
+
}
|
|
599
|
+
const container = document.getElementById(appId);
|
|
600
|
+
SolidReconciler.render(AppWrapper, container);
|
|
601
|
+
}
|
|
602
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
603
|
+
renderSolidRoot();
|
|
604
|
+
}
|
|
605
|
+
const [ONLAUNCH, ONSHOW, ONHIDE] = hooks.call('getMiniLifecycleImpl').app;
|
|
606
|
+
const appObj = Object.create({
|
|
607
|
+
mount(component, id, cb) {
|
|
608
|
+
const appInstance = getAppInstance();
|
|
609
|
+
appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount(component, id);
|
|
610
|
+
Solid.batch((...args) => {
|
|
611
|
+
perf.stop(PAGE_INIT);
|
|
612
|
+
return cb(...args);
|
|
613
|
+
});
|
|
614
|
+
},
|
|
615
|
+
unmount(id, cb) {
|
|
616
|
+
const appInstance = getAppInstance();
|
|
617
|
+
appInstance === null || appInstance === void 0 ? void 0 : appInstance.unmount(id);
|
|
618
|
+
Solid.batch(cb);
|
|
619
|
+
},
|
|
620
|
+
}, {
|
|
621
|
+
config: setDefaultDescriptor({
|
|
622
|
+
configurable: true,
|
|
623
|
+
value: config,
|
|
624
|
+
}),
|
|
625
|
+
[ONLAUNCH]: setDefaultDescriptor({
|
|
626
|
+
value(options) {
|
|
627
|
+
setRouterParams(options);
|
|
628
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
629
|
+
renderSolidRoot();
|
|
630
|
+
}
|
|
631
|
+
const onLaunch = () => {
|
|
632
|
+
var _a;
|
|
633
|
+
const app = getAppInstance();
|
|
634
|
+
if (app) {
|
|
635
|
+
// 把 App Class 上挂载的额外属性同步到全局 app 对象中
|
|
636
|
+
if (app.taroGlobalData) {
|
|
637
|
+
const globalData = app.taroGlobalData;
|
|
638
|
+
const keys = Object.keys(globalData);
|
|
639
|
+
const descriptors = Object.getOwnPropertyDescriptors(globalData);
|
|
640
|
+
keys.forEach(key => {
|
|
641
|
+
Object.defineProperty(this, key, {
|
|
642
|
+
configurable: true,
|
|
643
|
+
enumerable: true,
|
|
644
|
+
get() {
|
|
645
|
+
return globalData[key];
|
|
646
|
+
},
|
|
647
|
+
set(value) {
|
|
648
|
+
globalData[key] = value;
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
Object.defineProperties(this, descriptors);
|
|
653
|
+
}
|
|
654
|
+
(_a = app.onCreate) === null || _a === void 0 ? void 0 : _a.call(app);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
onLaunch();
|
|
658
|
+
triggerAppHook('onLaunch', options);
|
|
659
|
+
},
|
|
660
|
+
}),
|
|
661
|
+
[ONSHOW]: setDefaultDescriptor({
|
|
662
|
+
value(options) {
|
|
663
|
+
setRouterParams(options);
|
|
664
|
+
triggerAppHook('onShow', options);
|
|
665
|
+
},
|
|
666
|
+
}),
|
|
667
|
+
[ONHIDE]: setDefaultDescriptor({
|
|
668
|
+
value() {
|
|
669
|
+
triggerAppHook('onHide');
|
|
670
|
+
},
|
|
671
|
+
}),
|
|
672
|
+
onError: setDefaultDescriptor({
|
|
673
|
+
value(error) {
|
|
674
|
+
triggerAppHook('onError', error);
|
|
675
|
+
},
|
|
676
|
+
}),
|
|
677
|
+
onPageNotFound: setDefaultDescriptor({
|
|
678
|
+
value(res) {
|
|
679
|
+
triggerAppHook('onPageNotFound', res);
|
|
680
|
+
},
|
|
681
|
+
}),
|
|
682
|
+
});
|
|
683
|
+
function triggerAppHook(lifecycle, ...option) {
|
|
684
|
+
const instance = getPageInstance(HOOKS_APP_ID);
|
|
685
|
+
if (instance) {
|
|
686
|
+
const app = getAppInstance();
|
|
687
|
+
const func = hooks.call('getLifecycle', instance, lifecycle);
|
|
688
|
+
if (Array.isArray(func)) {
|
|
689
|
+
func.forEach((cb) => cb.apply(app, option));
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
Current.app = appObj;
|
|
694
|
+
return appObj;
|
|
695
|
+
}
|
|
473
696
|
|
|
474
697
|
const getNativeCompId = incrementId();
|
|
475
698
|
let h;
|
|
@@ -559,7 +782,7 @@ function initNativeComponentEntry(params) {
|
|
|
559
782
|
// create
|
|
560
783
|
const nativeApp = document.createElement('nativeComponent');
|
|
561
784
|
// insert
|
|
562
|
-
app.appendChild(nativeApp);
|
|
785
|
+
app === null || app === void 0 ? void 0 : app.appendChild(nativeApp);
|
|
563
786
|
app = nativeApp;
|
|
564
787
|
}
|
|
565
788
|
// eslint-disable-next-line react/no-deprecated
|
|
@@ -729,6 +952,13 @@ function createNativePageConfig(Component, pageName, data, react, reactDOM, page
|
|
|
729
952
|
hooks.call('modifyPageObject', pageObj);
|
|
730
953
|
return pageObj;
|
|
731
954
|
}
|
|
955
|
+
function createH5NativeComponentConfig(Component, react, reactdom) {
|
|
956
|
+
reactMeta.R = react;
|
|
957
|
+
h = react.createElement;
|
|
958
|
+
ReactDOM = reactdom;
|
|
959
|
+
setReconciler(ReactDOM);
|
|
960
|
+
return Component;
|
|
961
|
+
}
|
|
732
962
|
function createNativeComponentConfig(Component, react, reactdom, componentConfig) {
|
|
733
963
|
var _a, _b;
|
|
734
964
|
reactMeta.R = react;
|
|
@@ -868,7 +1098,7 @@ hooks.tap('initNativeApi', function (taro) {
|
|
|
868
1098
|
taro[hook] = taroHooks[hook];
|
|
869
1099
|
}
|
|
870
1100
|
});
|
|
871
|
-
if (
|
|
1101
|
+
if (process.env.FRAMEWORK === 'preact' && process.env.TARO_PLATFORM === 'mini') {
|
|
872
1102
|
const options = require('preact').options;
|
|
873
1103
|
const oldVNodeHook = options.vnode;
|
|
874
1104
|
const oldDiffedHook = options.diffed;
|
|
@@ -931,5 +1161,5 @@ if (__TARO_FRAMEWORK__ === 'preact' && process.env.TARO_PLATFORM === 'mini') {
|
|
|
931
1161
|
// })
|
|
932
1162
|
}
|
|
933
1163
|
|
|
934
|
-
export { connectReactPage, createNativeComponentConfig, createNativePageConfig, createReactApp, setReconciler, useAddToFavorites, useDidHide, useDidShow, useError, useLaunch, useLoad, useOptionMenuClick, usePageNotFound, usePageScroll, usePullDownRefresh, usePullIntercept, useReachBottom, useReady, useResize, useRouter, useSaveExitState, useScope, useShareAppMessage, useShareTimeline, useTabItemTap, useTitleClick, useUnhandledRejection, useUnload };
|
|
1164
|
+
export { connectReactPage, createH5NativeComponentConfig, createNativeComponentConfig, createNativePageConfig, createReactApp, createSolidApp, setReconciler, useAddToFavorites, useDidHide, useDidShow, useError, useLaunch, useLoad, useOptionMenuClick, usePageNotFound, usePageScroll, usePullDownRefresh, usePullIntercept, useReachBottom, useReady, useResize, useRouter, useSaveExitState, useScope, useShareAppMessage, useShareTimeline, useTabItemTap, useTitleClick, useUnhandledRejection, useUnload };
|
|
935
1165
|
//# sourceMappingURL=runtime.js.map
|