@weapp-vite/react 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.d.mts +8 -9
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/defineProperty.mjs +1 -1
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/toPrimitive.mjs +1 -1
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/toPropertyKey.mjs +1 -1
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/typeof.mjs +1 -1
- package/dist/dev/hostTree/index.mjs +1 -1
- package/dist/dev/hostTree/nodes.mjs +1 -1
- package/dist/dev/hostTree/staticBindings.mjs +4 -2
- package/dist/dev/hostTree/staticBindings.mjs.map +1 -1
- package/dist/dev/renderer.mjs +1 -1
- package/dist/event.mjs +1 -1
- package/dist/hostTree/index.d.mts +3 -4
- package/dist/hostTree/index.mjs +1 -1
- package/dist/hostTree/nodes.d.mts +5 -6
- package/dist/hostTree/nodes.mjs +1 -1
- package/dist/hostTree/staticBindings.mjs +1 -1
- package/dist/renderer.d.mts +4 -5
- package/dist/renderer.mjs +1 -1
- package/dist/types.d.mts +7 -8
- package/package.json +2 -2
- /package/dist/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/defineProperty.mjs +0 -0
- /package/dist/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/toPrimitive.mjs +0 -0
- /package/dist/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/toPropertyKey.mjs +0 -0
- /package/dist/_virtual/{_@oxc-project_runtime@0.147.0 → _@oxc-project_runtime@0.148.0}/helpers/esm/typeof.mjs +0 -0
package/dist/components.d.mts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { MiniProgramHostProps } from "./types.mjs";
|
|
2
2
|
//#region src/components.d.ts
|
|
3
|
-
declare const Button: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
4
|
-
declare const Input: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
5
|
-
declare const Slot: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
6
|
-
declare const Text: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
-
declare const View: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
8
|
-
type NativeComponentProps<Props extends object> = Props & Omit<MiniProgramHostProps, keyof Props>;
|
|
9
|
-
declare function createNativeComponent<Props extends object = Record<string, unknown>>(type: string): (props: NativeComponentProps<Props>) => import("react").DOMElement<Props & Omit<MiniProgramHostProps, keyof Props>, Element>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { Button, Input, NativeComponentProps, Slot, Text, View, createNativeComponent };
|
|
3
|
+
export declare const Button: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
4
|
+
export declare const Input: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
5
|
+
export declare const Slot: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
6
|
+
export declare const Text: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export declare const View: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
|
|
8
|
+
export type NativeComponentProps<Props extends object> = Props & Omit<MiniProgramHostProps, keyof Props>;
|
|
9
|
+
export declare function createNativeComponent<Props extends object = Record<string, unknown>>(type: string): (props: NativeComponentProps<Props>) => import("react").DOMElement<Props & Omit<MiniProgramHostProps, keyof Props>, Element>;
|
|
10
|
+
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import toPropertyKey from "./toPropertyKey.mjs";
|
|
2
2
|
|
|
3
|
-
//#region \0@oxc-project+runtime@0.
|
|
3
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
|
|
4
4
|
function _defineProperty(e, r, t) {
|
|
5
5
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
6
6
|
value: t,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _typeof from "./typeof.mjs";
|
|
2
2
|
|
|
3
|
-
//#region \0@oxc-project+runtime@0.
|
|
3
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
|
|
4
4
|
function toPrimitive(t, r) {
|
|
5
5
|
if ("object" != _typeof(t) || !t) return t;
|
|
6
6
|
var e = t[Symbol.toPrimitive];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _typeof from "./typeof.mjs";
|
|
2
2
|
import toPrimitive from "./toPrimitive.mjs";
|
|
3
3
|
|
|
4
|
-
//#region \0@oxc-project+runtime@0.
|
|
4
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
|
|
5
5
|
function toPropertyKey(t) {
|
|
6
6
|
var i = toPrimitive(t, "string");
|
|
7
7
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.
|
|
1
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
|
|
2
2
|
function _typeof(o) {
|
|
3
3
|
"@babel/helpers - typeof";
|
|
4
4
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hasSerializedPropChanges } from "./serialization.mjs";
|
|
2
|
-
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/defineProperty.mjs";
|
|
3
3
|
import { HostElement, HostText, attachHostNode } from "./nodes.mjs";
|
|
4
4
|
import { StaticBindingState, hasStaticBindingChanges, readStaticSlot } from "./staticBindings.mjs";
|
|
5
5
|
import { WEAPP_REACT_ROOT_DATA_KEY, WEAPP_REACT_SLOTS_DATA_KEY } from "@weapp-core/constants";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serializeProps, serializeStyle } from "./serialization.mjs";
|
|
2
|
-
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/defineProperty.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/hostTree/nodes.ts
|
|
5
5
|
function attach(parent, child, index) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serializeStyle } from "./serialization.mjs";
|
|
2
|
-
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/defineProperty.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/hostTree/staticBindings.ts
|
|
5
5
|
function isTextNode(node) {
|
|
@@ -67,7 +67,9 @@ var StaticBindingState = class {
|
|
|
67
67
|
for (const element of elements) {
|
|
68
68
|
const fields = readStaticBindingFields(element.props);
|
|
69
69
|
if (fields.length === 0) continue;
|
|
70
|
-
|
|
70
|
+
const slot = {};
|
|
71
|
+
for (const field of fields) slot[field] = readBindingValue(element, field);
|
|
72
|
+
slots[element.sid] = slot;
|
|
71
73
|
}
|
|
72
74
|
return slots;
|
|
73
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticBindings.mjs","names":[],"sources":["../../../src/hostTree/staticBindings.ts"],"sourcesContent":["import type { HostProps } from '../types'\nimport { serializeStyle } from './serialization'\n\ninterface BindingTextNode {\n value: string\n}\n\ninterface BindingElementNode {\n children: BindingNode[]\n props: HostProps\n sid: string\n}\n\ntype BindingNode = BindingElementNode | BindingTextNode\n\nfunction isTextNode(node: BindingNode): node is BindingTextNode {\n return 'value' in node\n}\n\nfunction collectText(node: BindingNode): string {\n if (isTextNode(node)) {\n return node.value\n }\n return node.children.map(collectText).join('')\n}\n\nexport function readStaticBindingFields(props: HostProps) {\n const value = props.__bindingFields\n return typeof value === 'string' && value\n ? value.split(',').filter(Boolean)\n : []\n}\n\nexport function readStaticSlot(props: HostProps) {\n const value = props.__slot\n if (typeof value !== 'string' || !value) {\n throw new Error('static template host node 缺少编译期 __slot')\n }\n return value\n}\n\nfunction readBindingValue(element: BindingElementNode, field: string, props = element.props) {\n if (field === 'text') {\n return element.children.map(collectText).join('')\n }\n if (field === 'className') {\n return props.className ?? props.class ?? ''\n }\n if (field === 'style') {\n return serializeStyle(props.style) ?? ''\n }\n return props[field]\n}\n\nexport function hasStaticBindingChanges(previous: HostProps, next: HostProps) {\n const fields = readStaticBindingFields(next)\n return fields.some((field) => {\n if (field === 'text') {\n return false\n }\n if (field === 'className') {\n return (previous.className ?? previous.class) !== (next.className ?? next.class)\n }\n if (field === 'style') {\n return serializeStyle(previous.style) !== serializeStyle(next.style)\n }\n return previous[field] !== next[field]\n })\n}\n\nexport class StaticBindingState {\n private dirty = new Map<BindingElementNode, Set<string>>()\n\n clear() {\n this.dirty.clear()\n }\n\n markField(element: BindingElementNode, field: string) {\n let fields = this.dirty.get(element)\n if (!fields) {\n fields = new Set<string>()\n this.dirty.set(element, fields)\n }\n fields.add(field)\n }\n\n markProps(element: BindingElementNode, previous: HostProps, next: HostProps) {\n for (const field of readStaticBindingFields(next)) {\n if (field === 'text') {\n continue\n }\n if (readBindingValue(element, field, previous) !== readBindingValue(element, field, next)) {\n this.markField(element, field)\n }\n }\n }\n\n snapshot(elements: Iterable<BindingElementNode>) {\n const slots: Record<string, Record<string, unknown>> = {}\n for (const element of elements) {\n const fields = readStaticBindingFields(element.props)\n if (fields.length === 0) {\n continue\n }\n
|
|
1
|
+
{"version":3,"file":"staticBindings.mjs","names":[],"sources":["../../../src/hostTree/staticBindings.ts"],"sourcesContent":["import type { HostProps } from '../types'\nimport { serializeStyle } from './serialization'\n\ninterface BindingTextNode {\n value: string\n}\n\ninterface BindingElementNode {\n children: BindingNode[]\n props: HostProps\n sid: string\n}\n\ntype BindingNode = BindingElementNode | BindingTextNode\n\nfunction isTextNode(node: BindingNode): node is BindingTextNode {\n return 'value' in node\n}\n\nfunction collectText(node: BindingNode): string {\n if (isTextNode(node)) {\n return node.value\n }\n return node.children.map(collectText).join('')\n}\n\nexport function readStaticBindingFields(props: HostProps) {\n const value = props.__bindingFields\n return typeof value === 'string' && value\n ? value.split(',').filter(Boolean)\n : []\n}\n\nexport function readStaticSlot(props: HostProps) {\n const value = props.__slot\n if (typeof value !== 'string' || !value) {\n throw new Error('static template host node 缺少编译期 __slot')\n }\n return value\n}\n\nfunction readBindingValue(element: BindingElementNode, field: string, props = element.props) {\n if (field === 'text') {\n return element.children.map(collectText).join('')\n }\n if (field === 'className') {\n return props.className ?? props.class ?? ''\n }\n if (field === 'style') {\n return serializeStyle(props.style) ?? ''\n }\n return props[field]\n}\n\nexport function hasStaticBindingChanges(previous: HostProps, next: HostProps) {\n const fields = readStaticBindingFields(next)\n return fields.some((field) => {\n if (field === 'text') {\n return false\n }\n if (field === 'className') {\n return (previous.className ?? previous.class) !== (next.className ?? next.class)\n }\n if (field === 'style') {\n return serializeStyle(previous.style) !== serializeStyle(next.style)\n }\n return previous[field] !== next[field]\n })\n}\n\nexport class StaticBindingState {\n private dirty = new Map<BindingElementNode, Set<string>>()\n\n clear() {\n this.dirty.clear()\n }\n\n markField(element: BindingElementNode, field: string) {\n let fields = this.dirty.get(element)\n if (!fields) {\n fields = new Set<string>()\n this.dirty.set(element, fields)\n }\n fields.add(field)\n }\n\n markProps(element: BindingElementNode, previous: HostProps, next: HostProps) {\n for (const field of readStaticBindingFields(next)) {\n if (field === 'text') {\n continue\n }\n if (readBindingValue(element, field, previous) !== readBindingValue(element, field, next)) {\n this.markField(element, field)\n }\n }\n }\n\n snapshot(elements: Iterable<BindingElementNode>) {\n const slots: Record<string, Record<string, unknown>> = {}\n for (const element of elements) {\n const fields = readStaticBindingFields(element.props)\n if (fields.length === 0) {\n continue\n }\n const slot: Record<string, unknown> = {}\n for (const field of fields) {\n slot[field] = readBindingValue(element, field)\n }\n slots[element.sid] = slot\n }\n return slots\n }\n\n takePayload() {\n const payload: Record<string, unknown> = {}\n for (const [element, fields] of this.dirty) {\n for (const field of fields) {\n payload[`slots.${element.sid}.${field}`] = readBindingValue(element, field)\n }\n }\n this.dirty.clear()\n return payload\n }\n}\n"],"mappings":";;;;AAeA,SAAS,WAAW,MAA4C;CAC9D,OAAO,WAAW;AACpB;AAEA,SAAS,YAAY,MAA2B;CAC9C,IAAI,WAAW,IAAI,GACjB,OAAO,KAAK;CAEd,OAAO,KAAK,SAAS,IAAI,WAAW,CAAC,CAAC,KAAK,EAAE;AAC/C;AAEA,SAAgB,wBAAwB,OAAkB;CACxD,MAAM,QAAQ,MAAM;CACpB,OAAO,OAAO,UAAU,YAAY,QAChC,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,IAC/B,CAAC;AACP;AAEA,SAAgB,eAAe,OAAkB;CAC/C,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO,UAAU,YAAY,CAAC,OAChC,MAAM,IAAI,MAAM,wCAAwC;CAE1D,OAAO;AACT;AAEA,SAAS,iBAAiB,SAA6B,OAAe,QAAQ,QAAQ,OAAO;CAC3F,IAAI,UAAU,QACZ,OAAO,QAAQ,SAAS,IAAI,WAAW,CAAC,CAAC,KAAK,EAAE;CAElD,IAAI,UAAU,aAAa;;EACzB,mCAAO,MAAM,wEAAa,MAAM,4CAAS;CAC3C;CACA,IAAI,UAAU,SAAS;;EACrB,0BAAO,eAAe,MAAM,KAAK,8DAAK;CACxC;CACA,OAAO,MAAM;AACf;AAEA,SAAgB,wBAAwB,UAAqB,MAAiB;CAE5E,OADe,wBAAwB,IAC3B,CAAC,CAAC,MAAM,UAAU;EAC5B,IAAI,UAAU,QACZ,OAAO;EAET,IAAI,UAAU,aAAa;;GACzB,+BAAQ,SAAS,8EAAa,SAAS,+BAAY,KAAK,sEAAa,KAAK;EAC5E;EACA,IAAI,UAAU,SACZ,OAAO,eAAe,SAAS,KAAK,MAAM,eAAe,KAAK,KAAK;EAErE,OAAO,SAAS,WAAW,KAAK;CAClC,CAAC;AACH;AAEA,IAAa,qBAAb,MAAgC;;wBACtB,yBAAQ,IAAI,IAAqC;;CAEzD,QAAQ;EACN,KAAK,MAAM,MAAM;CACnB;CAEA,UAAU,SAA6B,OAAe;EACpD,IAAI,SAAS,KAAK,MAAM,IAAI,OAAO;EACnC,IAAI,CAAC,QAAQ;GACX,yBAAS,IAAI,IAAY;GACzB,KAAK,MAAM,IAAI,SAAS,MAAM;EAChC;EACA,OAAO,IAAI,KAAK;CAClB;CAEA,UAAU,SAA6B,UAAqB,MAAiB;EAC3E,KAAK,MAAM,SAAS,wBAAwB,IAAI,GAAG;GACjD,IAAI,UAAU,QACZ;GAEF,IAAI,iBAAiB,SAAS,OAAO,QAAQ,MAAM,iBAAiB,SAAS,OAAO,IAAI,GACtF,KAAK,UAAU,SAAS,KAAK;EAEjC;CACF;CAEA,SAAS,UAAwC;EAC/C,MAAM,QAAiD,CAAC;EACxD,KAAK,MAAM,WAAW,UAAU;GAC9B,MAAM,SAAS,wBAAwB,QAAQ,KAAK;GACpD,IAAI,OAAO,WAAW,GACpB;GAEF,MAAM,OAAgC,CAAC;GACvC,KAAK,MAAM,SAAS,QAClB,KAAK,SAAS,iBAAiB,SAAS,KAAK;GAE/C,MAAM,QAAQ,OAAO;EACvB;EACA,OAAO;CACT;CAEA,cAAc;EACZ,MAAM,UAAmC,CAAC;EAC1C,KAAK,MAAM,CAAC,SAAS,WAAW,KAAK,OACnC,KAAK,MAAM,SAAS,QAClB,QAAQ,SAAS,QAAQ,IAAI,GAAG,WAAW,iBAAiB,SAAS,KAAK;EAG9E,KAAK,MAAM,MAAM;EACjB,OAAO;CACT;AACF"}
|
package/dist/dev/renderer.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { HostRoot } from "./hostTree/index.mjs";
|
|
|
3
3
|
import { dispatchHostEvent } from "./event.mjs";
|
|
4
4
|
import { createContext } from "react";
|
|
5
5
|
import Reconciler from "react-reconciler";
|
|
6
|
-
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants
|
|
6
|
+
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants";
|
|
7
7
|
|
|
8
8
|
//#region src/renderer.ts
|
|
9
9
|
function propsChanged(previous, next) {
|
package/dist/event.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HostElement as e}from"./hostTree/nodes.mjs";import
|
|
1
|
+
import{HostElement as e}from"./hostTree/nodes.mjs";import{WEAPP_REACT_EVENT_DATASET_KEY as t}from"@weapp-core/constants";function n(e){return`on${e.charAt(0).toUpperCase()}${e.slice(1)}`}function r(r,i){var a,o;let s=(a=i.currentTarget)==null||(a=a.dataset)==null?void 0:a[t];if(typeof s!=`string`)return;let c=r.getNode(s);if(!(c instanceof e))return;let l=[],u=c;for(;u;)l.push(u),u=u.parent instanceof e?u.parent:null;let d=!1,f={currentTarget:c,detail:(o=i.detail)==null?{}:o,nativeEvent:i,stopPropagation:()=>{d=!0},target:c,type:i.type},p=n(i.type);for(let e of l.slice().reverse()){let t=e.props[`${p}Capture`];if(typeof t==`function`&&(f.currentTarget=e,t(f)),d){r.flush();return}}for(let e of l){let t=e.props[p];if(typeof t==`function`&&(f.currentTarget=e,t(f)),d)break}r.flush()}export{r as dispatchHostEvent};
|
|
@@ -3,8 +3,8 @@ import { HostElement, HostNode, HostParent, HostText } from "./nodes.mjs";
|
|
|
3
3
|
import "./serialization.mjs";
|
|
4
4
|
import "../index.mjs";
|
|
5
5
|
//#region src/hostTree/index.d.ts
|
|
6
|
-
type HostRenderMode = 'static-bindings' | 'tree';
|
|
7
|
-
declare class HostRoot {
|
|
6
|
+
export type HostRenderMode = 'static-bindings' | 'tree';
|
|
7
|
+
export declare class HostRoot {
|
|
8
8
|
readonly children: HostNode[];
|
|
9
9
|
readonly renderMode: HostRenderMode;
|
|
10
10
|
private dirtyNodes;
|
|
@@ -44,5 +44,4 @@ declare class HostRoot {
|
|
|
44
44
|
private flushStaticBindings;
|
|
45
45
|
flush(): void;
|
|
46
46
|
}
|
|
47
|
-
//#endregion
|
|
48
|
-
export { HostRenderMode, HostRoot };
|
|
47
|
+
//#endregion
|
package/dist/hostTree/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hasSerializedPropChanges as e}from"./serialization.mjs";import t from"../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import{hasSerializedPropChanges as e}from"./serialization.mjs";import t from"../_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/defineProperty.mjs";import{HostElement as n,HostText as r,attachHostNode as i}from"./nodes.mjs";import{StaticBindingState as a,hasStaticBindingChanges as o,readStaticSlot as s}from"./staticBindings.mjs";import{WEAPP_REACT_ROOT_DATA_KEY as c,WEAPP_REACT_SLOTS_DATA_KEY as l}from"@weapp-core/constants";var u=class r{constructor(e,n=`tree`){t(this,`children`,[]),t(this,`renderMode`,void 0),t(this,`dirtyNodes`,new Set),t(this,`dirtyStructures`,new Set),t(this,`mounted`,!1),t(this,`nodeId`,0),t(this,`nodes`,new Map),t(this,`pendingFlush`,!1),t(this,`adapter`,void 0),t(this,`staticBindings`,new a),t(this,`staticMismatch`,void 0),t(this,`unmounting`,!1),this.adapter=e,this.renderMode=n}beginUnmount(){this.unmounting=!0}assertStaticTemplateValid(){if(!this.staticMismatch)return;let e=this.staticMismatch;throw this.staticMismatch=void 0,e}createElementSid(e){return this.renderMode===`static-bindings`?s(e):this.nextSid()}nextSid(){return this.nodeId+=1,`r${this.nodeId}`}register(e){if(this.renderMode===`static-bindings`&&e instanceof n&&this.nodes.has(e.sid))throw Error(`static template slot 冲突:${e.sid}`);this.nodes.set(e.sid,e)}unregisterTree(e){this.nodes.delete(e.sid),e instanceof n&&e.children.forEach(e=>this.unregisterTree(e))}getNode(e){return this.nodes.get(e)}append(e){i(this,e),this.markStructure(this)}insertBefore(e,t){let n=this.children.indexOf(t);i(this,e,n<0?void 0:n),this.markStructure(this)}remove(e){let t=this.children.indexOf(e);t<0||(this.children.splice(t,1),e.parent=null,this.unregisterTree(e),this.markStructure(this))}clear(){this.children.forEach(e=>this.unregisterTree(e)),this.children.length=0,this.markStructure(this)}markNode(e){this.dirtyNodes.add(e),this.scheduleFlush()}markElementProps(e,t,n){if(this.renderMode===`static-bindings`){this.staticBindings.markProps(e,t,n),this.scheduleFlush();return}this.markNode(e)}markStaticText(e){this.staticBindings.markField(e,`text`),this.scheduleFlush()}markStructure(e){if(this.renderMode===`static-bindings`){this.mounted&&!this.unmounting&&(this.staticMismatch=Error(`static template 运行时结构发生变化,需要切换 dynamic island fallback`));return}this.dirtyStructures.add(e),this.scheduleFlush()}scheduleFlush(){this.pendingFlush||(this.pendingFlush=!0,Promise.resolve().then(()=>this.flush()))}pathOf(e){if(e instanceof r)return`root`;let t=e.parent;if(!t)return;let n=this.pathOf(t),i=t.children.indexOf(e);return n&&i>=0?`${n}.cn[${i}]`:void 0}hasStructuralAncestor(e){let t=e.parent;for(;t;){if(this.dirtyStructures.has(t))return!0;t=t instanceof n?t.parent:null}return!1}snapshot(){return{cn:this.children.map(e=>e.serialize())}}shouldNotifyPropUpdate(t,n){return this.renderMode===`static-bindings`?o(t,n):e(t,n)}staticElements(){return Array.from(this.nodes.values()).filter(e=>e instanceof n)}flushStaticBindings(){if(this.staticMismatch){this.staticBindings.clear();return}if(!this.mounted){this.mounted=!0,this.staticBindings.clear(),this.adapter.setData({[l]:this.staticBindings.snapshot(this.staticElements())});return}let e=this.staticBindings.takePayload();Object.keys(e).length>0&&!this.unmounting&&this.adapter.setData(e)}flush(){if(this.pendingFlush=!1,this.renderMode===`static-bindings`){this.flushStaticBindings();return}if(!this.mounted){this.mounted=!0,this.dirtyNodes.clear(),this.dirtyStructures.clear(),this.adapter.setData({[c]:this.snapshot()});return}let e={};for(let t of this.dirtyStructures){let n=this.pathOf(t);n&&(e[`${n}.cn`]=t.children.map(e=>e.serialize()))}for(let t of this.dirtyNodes){if(this.hasStructuralAncestor(t))continue;let n=this.pathOf(t);n&&(e[n]=t.serialize())}this.dirtyNodes.clear(),this.dirtyStructures.clear(),Object.keys(e).length>0&&this.adapter.setData(e)}};export{n as HostElement,u as HostRoot,r as HostText};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { HostProps, SerializedHostNode } from "../types.mjs";
|
|
2
2
|
import { HostRoot } from "./index.mjs";
|
|
3
3
|
//#region src/hostTree/nodes.d.ts
|
|
4
|
-
type HostParent = HostElement | HostRoot;
|
|
5
|
-
type HostNode = HostElement | HostText;
|
|
6
|
-
declare class HostText {
|
|
4
|
+
export type HostParent = HostElement | HostRoot;
|
|
5
|
+
export type HostNode = HostElement | HostText;
|
|
6
|
+
export declare class HostText {
|
|
7
7
|
parent: HostParent | null;
|
|
8
8
|
readonly root: HostRoot;
|
|
9
9
|
readonly sid: string;
|
|
@@ -12,7 +12,7 @@ declare class HostText {
|
|
|
12
12
|
serialize(): SerializedHostNode;
|
|
13
13
|
setValue(value: string): void;
|
|
14
14
|
}
|
|
15
|
-
declare class HostElement {
|
|
15
|
+
export declare class HostElement {
|
|
16
16
|
readonly children: HostNode[];
|
|
17
17
|
parent: HostParent | null;
|
|
18
18
|
props: HostProps;
|
|
@@ -26,5 +26,4 @@ declare class HostElement {
|
|
|
26
26
|
serialize(): SerializedHostNode;
|
|
27
27
|
updateProps(props: HostProps, notify?: boolean): void;
|
|
28
28
|
}
|
|
29
|
-
//#endregion
|
|
30
|
-
export { HostElement, HostNode, HostParent, HostText };
|
|
29
|
+
//#endregion
|
package/dist/hostTree/nodes.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{serializeProps as e,serializeStyle as t}from"./serialization.mjs";import n from"../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import{serializeProps as e,serializeStyle as t}from"./serialization.mjs";import n from"../_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/defineProperty.mjs";function r(e,t,n){if(t.parent){let e=t.parent.children.indexOf(t);e>=0&&t.parent.children.splice(e,1)}t.parent=e,n===void 0?e.children.push(t):e.children.splice(n,0,t)}var i=class{constructor(e,t,r){n(this,`parent`,null),n(this,`root`,void 0),n(this,`sid`,void 0),n(this,`value`,void 0),this.root=e,this.sid=t,this.value=r,e.register(this)}serialize(){return{nn:`#text`,sid:this.sid,v:this.value}}setValue(e){e!==this.value&&(this.value=e,this.root.renderMode===`static-bindings`&&this.parent&&`props`in this.parent?this.root.markStaticText(this.parent):this.root.markNode(this))}},a=class{constructor(e,t,r,i){n(this,`children`,[]),n(this,`parent`,null),n(this,`props`,void 0),n(this,`root`,void 0),n(this,`sid`,void 0),n(this,`type`,void 0),this.props=i,this.root=e,this.sid=t,this.type=r,e.register(this)}append(e,t=!0){r(this,e),t&&this.root.markStructure(this)}insertBefore(e,t){let n=this.children.indexOf(t);r(this,e,n<0?void 0:n),this.root.markStructure(this)}remove(e){let t=this.children.indexOf(e);t<0||(this.children.splice(t,1),e.parent=null,this.root.unregisterTree(e),this.root.markStructure(this))}serialize(){var n;let r=(n=this.props.className)==null?this.props.class:n,i={nn:this.type,sid:this.sid};this.children.length>0&&(i.cn=this.children.map(e=>e.serialize())),typeof r==`string`&&r&&(i.cl=r);let a=t(this.props.style);a&&(i.st=a);let o=e(this.props);return o&&(i.p=o),i}updateProps(e,t=!0){let n=this.props;this.props=e,t&&this.root.markElementProps(this,n,e)}};function o(e,t,n){r(e,t,n)}export{a as HostElement,i as HostText,o as attachHostNode};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{serializeStyle as e}from"./serialization.mjs";import t from"../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import{serializeStyle as e}from"./serialization.mjs";import t from"../_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/defineProperty.mjs";function n(e){return`value`in e}function r(e){return n(e)?e.value:e.children.map(r).join(``)}function i(e){let t=e.__bindingFields;return typeof t==`string`&&t?t.split(`,`).filter(Boolean):[]}function a(e){let t=e.__slot;if(typeof t!=`string`||!t)throw Error(`static template host node 缺少编译期 __slot`);return t}function o(t,n,i=t.props){if(n===`text`)return t.children.map(r).join(``);if(n===`className`){var a,o;return(a=(o=i.className)==null?i.class:o)==null?``:a}if(n===`style`){var s;return(s=e(i.style))==null?``:s}return i[n]}function s(t,n){return i(n).some(r=>{if(r===`text`)return!1;if(r===`className`){var i,a;return((i=t.className)==null?t.class:i)!==((a=n.className)==null?n.class:a)}return r===`style`?e(t.style)!==e(n.style):t[r]!==n[r]})}var c=class{constructor(){t(this,`dirty`,new Map)}clear(){this.dirty.clear()}markField(e,t){let n=this.dirty.get(e);n||(n=new Set,this.dirty.set(e,n)),n.add(t)}markProps(e,t,n){for(let r of i(n))r!==`text`&&o(e,r,t)!==o(e,r,n)&&this.markField(e,r)}snapshot(e){let t={};for(let n of e){let e=i(n.props);if(e.length===0)continue;let r={};for(let t of e)r[t]=o(n,t);t[n.sid]=r}return t}takePayload(){let e={};for(let[t,n]of this.dirty)for(let r of n)e[`slots.${t.sid}.${r}`]=o(t,r);return this.dirty.clear(),e}};export{c as StaticBindingState,s as hasStaticBindingChanges,i as readStaticBindingFields,a as readStaticSlot};
|
package/dist/renderer.d.mts
CHANGED
|
@@ -2,16 +2,15 @@ import { MiniProgramEventLike, MiniProgramPageAdapter } from "./types.mjs";
|
|
|
2
2
|
import { HostRenderMode, HostRoot } from "./hostTree/index.mjs";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
//#region src/renderer.d.ts
|
|
5
|
-
interface ReactMiniProgramRoot {
|
|
5
|
+
export interface ReactMiniProgramRoot {
|
|
6
6
|
dispatchEvent: (event: MiniProgramEventLike) => void;
|
|
7
7
|
flush: () => void;
|
|
8
8
|
getSnapshot: () => ReturnType<HostRoot['snapshot']>;
|
|
9
9
|
render: (element: ReactNode) => void;
|
|
10
10
|
unmount: () => void;
|
|
11
11
|
}
|
|
12
|
-
interface ReactMiniProgramRootOptions {
|
|
12
|
+
export interface ReactMiniProgramRootOptions {
|
|
13
13
|
renderMode?: HostRenderMode;
|
|
14
14
|
}
|
|
15
|
-
declare function createReactMiniProgramRoot(adapter: MiniProgramPageAdapter, options?: ReactMiniProgramRootOptions): ReactMiniProgramRoot;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { ReactMiniProgramRoot, ReactMiniProgramRootOptions, createReactMiniProgramRoot };
|
|
15
|
+
export declare function createReactMiniProgramRoot(adapter: MiniProgramPageAdapter, options?: ReactMiniProgramRootOptions): ReactMiniProgramRoot;
|
|
16
|
+
//#endregion
|
package/dist/renderer.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HostElement as e,HostText as t}from"./hostTree/nodes.mjs";import{HostRoot as n}from"./hostTree/index.mjs";import{dispatchHostEvent as r}from"./event.mjs";import{createContext as i}from"react";import a from"react-reconciler";import{DefaultEventPriority as o,NoEventPriority as s}from"react-reconciler/constants
|
|
1
|
+
import{HostElement as e,HostText as t}from"./hostTree/nodes.mjs";import{HostRoot as n}from"./hostTree/index.mjs";import{dispatchHostEvent as r}from"./event.mjs";import{createContext as i}from"react";import a from"react-reconciler";import{DefaultEventPriority as o,NoEventPriority as s}from"react-reconciler/constants";function c(e,t){let n=Object.keys(e).filter(e=>e!==`children`),r=Object.keys(t).filter(e=>e!==`children`);return n.length!==r.length||r.some(n=>e[n]!==t[n])}let l=s;const u={},d={HostTransitionContext:i(null),NotPendingTransition:null,afterActiveInstanceBlur(){},appendChild(e,t){e.append(t)},appendChildToContainer(e,t){e.append(t)},appendInitialChild(e,t){e.append(t,!1)},beforeActiveInstanceBlur(){},cancelTimeout:clearTimeout,clearContainer(e){e.clear()},commitMount(){},commitTextUpdate(e,t,n){e.setValue(n)},commitUpdate(e,t,n,r){c(n,r)&&e.updateProps(r,e.root.shouldNotifyPropUpdate(n,r))},createInstance(t,n,r){return new e(r,r.createElementSid(n),t,n)},createTextInstance(e,n){return new t(n,n.nextSid(),e)},detachDeletedInstance(){},finalizeInitialChildren(){return!1},getChildHostContext(e){return e},getCurrentUpdatePriority(){return l},getInstanceFromNode(){return null},getInstanceFromScope(){return null},getPublicInstance(e){return e},getRootHostContext(){return u},getSuspendedCommitReason(){return null},hideInstance(e){e.updateProps({...e.props,hidden:!0})},hideTextInstance(e){e.setValue(``)},insertBefore(e,t,n){e.insertBefore(t,n)},insertInContainerBefore(e,t,n){e.insertBefore(t,n)},isPrimaryRenderer:!0,maySuspendCommit(){return!1},maySuspendCommitInSyncRender(){return!1},maySuspendCommitOnUpdate(){return!1},noTimeout:-1,preloadInstance(){return!0},prepareForCommit(){return null},preparePortalMount(){},prepareScopeUpdate(){},requestPostPaintCallback(e){setTimeout(()=>e(Date.now()),0)},resetFormInstance(){},resolveEventTimeStamp(){return-1.1},resolveEventType(){return null},resolveUpdatePriority(){return l===s?o:l},removeChild(e,t){e.remove(t)},removeChildFromContainer(e,t){e.remove(t)},resetAfterCommit(e){e.flush()},resetTextContent(){},scheduleMicrotask(e){Promise.resolve().then(e)},scheduleTimeout:setTimeout,setCurrentUpdatePriority(e){l=e},shouldAttemptEagerTransition(){return!1},shouldSetTextContent(){return!1},supportsHydration:!1,supportsMicrotasks:!0,supportsMutation:!0,supportsPersistence:!1,suspendInstance(){},startSuspendingCommit(){},trackSchedulerEvent(){},unhideInstance(e,t){e.updateProps(t)},unhideTextInstance(e,t){e.setValue(t)},waitForCommitToBeReady(){return null},warnsIfNotActing:!0},f=a(d);function p(e){return f.createContainer(e,0,null,!1,!1,``,e=>{throw e},()=>{},e=>{throw e},()=>{})}function m(e,t={}){let i=new n(e,t.renderMode),a=p(i);return{dispatchEvent(e){f.flushSyncFromReconciler(()=>r(i,e)),i.assertStaticTemplateValid(),i.flush()},flush(){f.flushSyncFromReconciler(),i.flush()},getSnapshot(){return i.snapshot()},render(e){f.updateContainerSync(e,a,null),f.flushSyncWork(),i.assertStaticTemplateValid(),i.flush()},unmount(){i.beginUnmount(),f.updateContainerSync(null,a,null),f.flushSyncWork(),i.flush()}}}export{m as createReactMiniProgramRoot};
|
package/dist/types.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
//#region src/types.d.ts
|
|
3
|
-
interface MiniProgramEventLike {
|
|
3
|
+
export interface MiniProgramEventLike {
|
|
4
4
|
currentTarget?: {
|
|
5
5
|
dataset?: Record<string, unknown>;
|
|
6
6
|
};
|
|
@@ -8,10 +8,10 @@ interface MiniProgramEventLike {
|
|
|
8
8
|
target?: unknown;
|
|
9
9
|
type: string;
|
|
10
10
|
}
|
|
11
|
-
interface MiniProgramPageAdapter {
|
|
11
|
+
export interface MiniProgramPageAdapter {
|
|
12
12
|
setData: (payload: Record<string, unknown>, callback?: () => void) => void;
|
|
13
13
|
}
|
|
14
|
-
interface SerializedHostNode {
|
|
14
|
+
export interface SerializedHostNode {
|
|
15
15
|
cl?: string;
|
|
16
16
|
cn?: SerializedHostNode[];
|
|
17
17
|
nn: string;
|
|
@@ -20,8 +20,8 @@ interface SerializedHostNode {
|
|
|
20
20
|
st?: string;
|
|
21
21
|
v?: string;
|
|
22
22
|
}
|
|
23
|
-
type HostProps = Record<string, unknown>;
|
|
24
|
-
interface MiniProgramHostProps {
|
|
23
|
+
export type HostProps = Record<string, unknown>;
|
|
24
|
+
export interface MiniProgramHostProps {
|
|
25
25
|
children?: ReactNode;
|
|
26
26
|
checked?: boolean;
|
|
27
27
|
class?: string;
|
|
@@ -38,7 +38,7 @@ interface MiniProgramHostProps {
|
|
|
38
38
|
type?: string;
|
|
39
39
|
value?: string | number;
|
|
40
40
|
}
|
|
41
|
-
type HostEventHandler = (event: {
|
|
41
|
+
export type HostEventHandler = (event: {
|
|
42
42
|
currentTarget: unknown;
|
|
43
43
|
detail: Record<string, unknown>;
|
|
44
44
|
nativeEvent: MiniProgramEventLike;
|
|
@@ -46,5 +46,4 @@ type HostEventHandler = (event: {
|
|
|
46
46
|
target: unknown;
|
|
47
47
|
type: string;
|
|
48
48
|
}) => unknown;
|
|
49
|
-
//#endregion
|
|
50
|
-
export { HostEventHandler, HostProps, MiniProgramEventLike, MiniProgramHostProps, MiniProgramPageAdapter, SerializedHostNode };
|
|
49
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.4",
|
|
5
5
|
"description": "React 19 runtime for weapp-vite mini programs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"react-reconciler": "0.33.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@weapp-core/constants": "0.2.
|
|
52
|
+
"@weapp-core/constants": "0.2.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "19.2.18",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|