@weapp-vite/react 0.1.0 → 0.2.1

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.
Files changed (24) hide show
  1. package/README.md +29 -0
  2. package/dist/components.d.mts +4 -1
  3. package/dist/components.mjs +1 -1
  4. package/dist/dev/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/defineProperty.mjs +1 -1
  5. package/dist/dev/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/toPrimitive.mjs +1 -1
  6. package/dist/dev/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/toPropertyKey.mjs +1 -1
  7. package/dist/dev/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/typeof.mjs +1 -1
  8. package/dist/dev/components.mjs +8 -1
  9. package/dist/dev/components.mjs.map +1 -1
  10. package/dist/dev/hostTree/index.mjs +1 -1
  11. package/dist/dev/hostTree/nodes.mjs +1 -1
  12. package/dist/dev/hostTree/staticBindings.mjs +1 -1
  13. package/dist/dev/index.mjs +2 -2
  14. package/dist/event.mjs +1 -1
  15. package/dist/hostTree/index.mjs +1 -1
  16. package/dist/hostTree/nodes.mjs +1 -1
  17. package/dist/hostTree/staticBindings.mjs +1 -1
  18. package/dist/index.d.mts +2 -2
  19. package/dist/index.mjs +1 -1
  20. package/package.json +12 -4
  21. /package/dist/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/defineProperty.mjs +0 -0
  22. /package/dist/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/toPrimitive.mjs +0 -0
  23. /package/dist/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/toPropertyKey.mjs +0 -0
  24. /package/dist/_virtual/{_@oxc-project_runtime@0.143.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/typeof.mjs +0 -0
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @weapp-vite/react
2
+
3
+ `@weapp-vite/react` 是 `weapp-vite` 的 React 19 小程序 renderer,提供 `View`、`Text`、`Button`、`Input` 等 host components,以及原生自定义组件互操作能力。
4
+
5
+ ## 自定义组件 bridge
6
+
7
+ ```tsx
8
+ import { createNativeComponent, Slot } from '@weapp-vite/react'
9
+
10
+ interface CardProps {
11
+ label: string
12
+ onValueChange?: (event: { detail: { value: number } }) => void
13
+ value: number
14
+ }
15
+
16
+ const NativeCard = createNativeComponent<CardProps>('native-card')
17
+
18
+ export function ReactLeaf() {
19
+ return <Slot />
20
+ }
21
+ ```
22
+
23
+ bridge tag 必须在当前 TSX 顶层通过字符串字面量声明,并在页面或组件 JSON 的 `usingComponents` 中注册。动态 props、默认 slot 和自定义事件均由静态模板编译器处理:`onValueChange` 映射为 `bind:value-change`,`onValueChangeCapture` 映射为 `capture-bind:value-change`。
24
+
25
+ 首版不支持 bridge 组件出现在条件或列表等动态结构中,也不支持跨文件 bridge 声明、scoped slot、model 或动态 tag。`renderMode: 'auto'` 遇到这类结构会直接报告可操作的编译错误。
26
+
27
+ React 项目需要使用 Wevu SFC 时,应同时安装 `wevu` 并启用 Vue 编译。React TSX 仍由 React owner 处理,`.vue` 由 Wevu compiler 处理;编译后的 Wevu 组件通过同一 bridge API 引用。
28
+
29
+ 完整配置和示例见 [React 小程序接入](https://vite.icebreaker.top/integration/react)。
@@ -2,7 +2,10 @@ import { MiniProgramHostProps } from "./types.mjs";
2
2
  //#region src/components.d.ts
3
3
  declare const Button: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
4
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>>;
5
6
  declare const Text: (props: MiniProgramHostProps) => import("react").ReactElement<MiniProgramHostProps, string | import("react").JSXElementConstructor<any>>;
6
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>;
7
10
  //#endregion
8
- export { Button, Input, Text, View };
11
+ export { Button, Input, NativeComponentProps, Slot, Text, View, createNativeComponent };
@@ -1 +1 @@
1
- import{createElement as e}from"react";function t(t){return function(n){return e(t,n)}}const n=t(`button`),r=t(`input`),i=t(`text`),a=t(`view`);export{n as Button,r as Input,i as Text,a as View};
1
+ import{createElement as e}from"react";function t(t){return function(n){return e(t,n)}}const n=t(`button`),r=t(`input`),i=t(`slot`),a=t(`text`),o=t(`view`);function s(t){if(!t)throw TypeError(`native component tag name must be a non-empty string`);return function(n){return e(t,n)}}export{n as Button,r as Input,i as Slot,a as Text,o as View,s as createNativeComponent};
@@ -1,6 +1,6 @@
1
1
  import toPropertyKey from "./toPropertyKey.mjs";
2
2
 
3
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/defineProperty.js
3
+ //#region \0@oxc-project+runtime@0.146.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.143.0/helpers/esm/toPrimitive.js
3
+ //#region \0@oxc-project+runtime@0.146.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.143.0/helpers/esm/toPropertyKey.js
4
+ //#region \0@oxc-project+runtime@0.146.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.143.0/helpers/esm/typeof.js
1
+ //#region \0@oxc-project+runtime@0.146.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) {
@@ -8,9 +8,16 @@ function createHostComponent(type) {
8
8
  }
9
9
  const Button = createHostComponent("button");
10
10
  const Input = createHostComponent("input");
11
+ const Slot = createHostComponent("slot");
11
12
  const Text = createHostComponent("text");
12
13
  const View = createHostComponent("view");
14
+ function createNativeComponent(type) {
15
+ if (!type) throw new TypeError("native component tag name must be a non-empty string");
16
+ return function MiniProgramNativeComponent(props) {
17
+ return createElement(type, props);
18
+ };
19
+ }
13
20
 
14
21
  //#endregion
15
- export { Button, Input, Text, View };
22
+ export { Button, Input, Slot, Text, View, createNativeComponent };
16
23
  //# sourceMappingURL=components.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"components.mjs","names":[],"sources":["../../src/components.ts"],"sourcesContent":["import type { MiniProgramHostProps } from './types'\nimport { createElement } from 'react'\n\nfunction createHostComponent(type: string) {\n return function MiniProgramHostComponent(props: MiniProgramHostProps) {\n return createElement(type, props)\n }\n}\n\nexport const Button = createHostComponent('button')\nexport const Input = createHostComponent('input')\nexport const Text = createHostComponent('text')\nexport const View = createHostComponent('view')\n"],"mappings":";;;AAGA,SAAS,oBAAoB,MAAc;CACzC,OAAO,SAAS,yBAAyB,OAA6B;EACpE,OAAO,cAAc,MAAM,KAAK;CAClC;AACF;AAEA,MAAa,SAAS,oBAAoB,QAAQ;AAClD,MAAa,QAAQ,oBAAoB,OAAO;AAChD,MAAa,OAAO,oBAAoB,MAAM;AAC9C,MAAa,OAAO,oBAAoB,MAAM"}
1
+ {"version":3,"file":"components.mjs","names":[],"sources":["../../src/components.ts"],"sourcesContent":["import type { MiniProgramHostProps } from './types'\nimport { createElement } from 'react'\n\nfunction createHostComponent(type: string) {\n return function MiniProgramHostComponent(props: MiniProgramHostProps) {\n return createElement(type, props)\n }\n}\n\nexport const Button = createHostComponent('button')\nexport const Input = createHostComponent('input')\nexport const Slot = createHostComponent('slot')\nexport const Text = createHostComponent('text')\nexport const View = createHostComponent('view')\n\nexport type NativeComponentProps<Props extends object> = Props & Omit<MiniProgramHostProps, keyof Props>\n\nexport function createNativeComponent<Props extends object = Record<string, unknown>>(type: string) {\n if (!type) {\n throw new TypeError('native component tag name must be a non-empty string')\n }\n return function MiniProgramNativeComponent(props: NativeComponentProps<Props>) {\n return createElement(type, props)\n }\n}\n"],"mappings":";;;AAGA,SAAS,oBAAoB,MAAc;CACzC,OAAO,SAAS,yBAAyB,OAA6B;EACpE,OAAO,cAAc,MAAM,KAAK;CAClC;AACF;AAEA,MAAa,SAAS,oBAAoB,QAAQ;AAClD,MAAa,QAAQ,oBAAoB,OAAO;AAChD,MAAa,OAAO,oBAAoB,MAAM;AAC9C,MAAa,OAAO,oBAAoB,MAAM;AAC9C,MAAa,OAAO,oBAAoB,MAAM;AAI9C,SAAgB,sBAAsE,MAAc;CAClG,IAAI,CAAC,MACH,MAAM,IAAI,UAAU,sDAAsD;CAE5E,OAAO,SAAS,2BAA2B,OAAoC;EAC7E,OAAO,cAAc,MAAM,KAAK;CAClC;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { hasSerializedPropChanges } from "./serialization.mjs";
2
- import _defineProperty from "../_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/defineProperty.mjs";
2
+ import _defineProperty from "../_virtual/_@oxc-project_runtime@0.146.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.143.0/helpers/esm/defineProperty.mjs";
2
+ import _defineProperty from "../_virtual/_@oxc-project_runtime@0.146.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.143.0/helpers/esm/defineProperty.mjs";
2
+ import _defineProperty from "../_virtual/_@oxc-project_runtime@0.146.0/helpers/esm/defineProperty.mjs";
3
3
 
4
4
  //#region src/hostTree/staticBindings.ts
5
5
  function isTextNode(node) {
@@ -1,4 +1,4 @@
1
- import { Button, Input, Text, View } from "./components.mjs";
1
+ import { Button, Input, Slot, Text, View, createNativeComponent } from "./components.mjs";
2
2
  import { createReactMiniProgramRoot } from "./renderer.mjs";
3
3
 
4
- export { Button, Input, Text, View, createReactMiniProgramRoot };
4
+ export { Button, Input, Slot, Text, View, createNativeComponent, createReactMiniProgramRoot };
package/dist/event.mjs CHANGED
@@ -1 +1 @@
1
- import{HostElement as e}from"./hostTree/nodes.mjs";import"./hostTree/index.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};
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};
@@ -1 +1 @@
1
- import{hasSerializedPropChanges as e}from"./serialization.mjs";import t from"../_virtual/_@oxc-project_runtime@0.143.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
+ import{hasSerializedPropChanges as e}from"./serialization.mjs";import t from"../_virtual/_@oxc-project_runtime@0.146.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 +1 @@
1
- import{serializeProps as e,serializeStyle as t}from"./serialization.mjs";import n from"../_virtual/_@oxc-project_runtime@0.143.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
+ import{serializeProps as e,serializeStyle as t}from"./serialization.mjs";import n from"../_virtual/_@oxc-project_runtime@0.146.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.143.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);e.length!==0&&(t[n.sid]=Object.fromEntries(e.map(e=>[e,o(n,e)])))}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};
1
+ import{serializeStyle as e}from"./serialization.mjs";import t from"../_virtual/_@oxc-project_runtime@0.146.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);e.length!==0&&(t[n.sid]=Object.fromEntries(e.map(e=>[e,o(n,e)])))}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/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { HostEventHandler, HostProps, MiniProgramEventLike, MiniProgramHostProps, MiniProgramPageAdapter, SerializedHostNode } from "./types.mjs";
2
- import { Button, Input, Text, View } from "./components.mjs";
2
+ import { Button, Input, NativeComponentProps, Slot, Text, View, createNativeComponent } from "./components.mjs";
3
3
  import { ReactMiniProgramRoot, ReactMiniProgramRootOptions, createReactMiniProgramRoot } from "./renderer.mjs";
4
- export { Button, type HostEventHandler, type HostProps, Input, type MiniProgramEventLike, type MiniProgramHostProps, type MiniProgramPageAdapter, type ReactMiniProgramRoot, type ReactMiniProgramRootOptions, type SerializedHostNode, Text, View, createReactMiniProgramRoot };
4
+ export { Button, type HostEventHandler, type HostProps, Input, type MiniProgramEventLike, type MiniProgramHostProps, type MiniProgramPageAdapter, type NativeComponentProps, type ReactMiniProgramRoot, type ReactMiniProgramRootOptions, type SerializedHostNode, Slot, Text, View, createNativeComponent, createReactMiniProgramRoot };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{Button as e,Input as t,Text as n,View as r}from"./components.mjs";import{createReactMiniProgramRoot as i}from"./renderer.mjs";export{e as Button,t as Input,n as Text,r as View,i as createReactMiniProgramRoot};
1
+ import{Button as e,Input as t,Slot as n,Text as r,View as i,createNativeComponent as a}from"./components.mjs";import{createReactMiniProgramRoot as o}from"./renderer.mjs";export{e as Button,t as Input,n as Slot,r as Text,i as View,a as createNativeComponent,o as createReactMiniProgramRoot};
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@weapp-vite/react",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.1",
5
5
  "description": "React 19 runtime for weapp-vite mini programs",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/weapp-vite/weapp-vite.git",
10
+ "directory": "packages-runtime/react"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/weapp-vite/weapp-vite/issues"
14
+ },
7
15
  "sideEffects": false,
8
16
  "exports": {
9
17
  ".": {
@@ -41,13 +49,13 @@
41
49
  "react-reconciler": "0.33.0"
42
50
  },
43
51
  "dependencies": {
44
- "@weapp-core/constants": "0.1.16"
52
+ "@weapp-core/constants": "0.2.0"
45
53
  },
46
54
  "devDependencies": {
47
- "@types/react": "19.2.17",
55
+ "@types/react": "19.2.18",
48
56
  "@types/react-reconciler": "0.33.0",
49
57
  "miniprogram-api-typings": "^5.2.3",
50
- "react": "19.2.7",
58
+ "react": "19.2.8",
51
59
  "react-reconciler": "0.33.0"
52
60
  },
53
61
  "scripts": {