actview 3.1.0 → 3.2.0

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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ## 核心功能
8
8
 
9
9
  - **vue 运行时 re-export**:响应式(`ref` / `reactive` / `computed` / `watch` / `effectScope`)、组件(`defineComponent` / `createApp` / `h`)、生命周期、内置组件(`KeepAlive` / `Teleport` / `Suspense` / `Transition` / `TransitionGroup`)
10
- - **defineComponent 桥接**(React 语义):`ctx.slots` `props.children`(读时求值),props 读不到时从 attrs 兜底;**有 props 声明时自动落根**(`inheritAttrs` 开启,未消费 attrs 透传到根元素 + scoped data-v 生效),无声明时保持不透传(React 语义,避免 props 污染 DOM)
10
+ - **defineComponent 桥接**(React 对齐):props 读不到时从 attrs 兜底(React 风格任意 props 可读);**`props.children` 渲染期读取 = 子内容值**(React 语义,非渲染期读取返回 undefined 并提示——判断有无子内容用 `props.slots.default != null`);`props.slots.default()` 具名插槽/显式调用(render 期);**createVNode 包装**:`<p {...props}>` 展开的 children 键自动抽进第三参(React 对齐);桥接虚拟键(children/slots)不参与展开/遍历;**有 props 声明时自动落根**(`inheritAttrs` 开启,未消费 attrs 透传到根元素 + scoped data-v 生效),无声明时保持不透传(React 语义,避免 props 污染 DOM)
11
11
  - **createContext**:React 语义(`.Provider` / `.use()`),基于 vue `provide/inject`
12
12
  - **JSX 类型层**:全局 `IntrinsicElements` 完整标签表(React 语义属性)+ vue 组件兼容;组件 props 严格检查(未声明 prop 报错)
13
13
 
package/dist/index.d.ts CHANGED
@@ -1,23 +1,31 @@
1
1
  import { VNode, Reactive, SetupContext } from 'vue';
2
- export { App, Comment, Component, ComponentPublicInstance, ComputedRef, DeepReadonly, DefineComponent, EffectScope, EffectScope as EffectScopeType, EmitsOptions, Fragment, InjectionKey, KeepAlive, Plugin, PropType, Reactive, Ref, RenderFunction, SetupContext, ShallowReactive, ShallowRef, Slot, Slots, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VNode, VNodeChild, VNodeTypes, WatchCallback, WatchOptions, WatchSource, WritableComputedRef, cloneVNode, computed, createApp, createVNode, customRef, defineAsyncComponent, effectScope, getCurrentInstance, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, isShallow, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, onWatcherCleanup, provide, proxyRefs, reactive, readonly, ref, resolveComponent, resolveDirective, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, toValue, triggerRef, unref, useAttrs, useId, useSlots, useTemplateRef, version, watch, watchEffect, watchPostEffect, watchSyncEffect, withDirectives } from 'vue';
2
+ export { App, Comment, Component, ComponentPublicInstance, ComputedRef, DeepReadonly, DefineComponent, EffectScope, EffectScope as EffectScopeType, EmitsOptions, Fragment, InjectionKey, KeepAlive, Plugin, PropType, Reactive, Ref, RenderFunction, SetupContext, ShallowReactive, ShallowRef, Slot, Slots, Static, Teleport, Text, Transition, TransitionGroup, VNode, VNodeChild, VNodeTypes, WatchCallback, WatchOptions, WatchSource, WritableComputedRef, cloneVNode, computed, createApp, customRef, defineAsyncComponent, effectScope, getCurrentInstance, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, isShallow, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, onWatcherCleanup, provide, proxyRefs, reactive, readonly, ref, resolveComponent, resolveDirective, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, toValue, triggerRef, unref, useAttrs, useId, useSlots, useTemplateRef, version, watch, watchEffect, watchPostEffect, watchSyncEffect, withDirectives } from 'vue';
3
3
 
4
+ declare function createVNode(type: any, props: any, children?: any): VNode;
5
+ interface SuspenseProps {
6
+ /** React 语义:异步解析期间显示的 fallback(桥接为 vue #fallback 插槽) */
7
+ fallback?: any;
8
+ /** vue 原生插槽(默认插槽 props.slots.default()) */
9
+ slots?: any;
10
+ /** 其余透传:vue Suspense 事件/选项 */
11
+ [key: string]: any;
12
+ }
13
+ declare const Suspense: ActViewComponent<SuspenseProps>;
4
14
  /**
5
15
  * v2 组件类型(类型层形状):
6
16
  * 运行时是 vue DefineComponent(createApp/渲染消费),但类型层用自定义形状
7
17
  * ——只有 call signature、无构造签名。TS 6 的 JSX 检查(getJsxReferenceKind)
8
18
  * 按「构造签名 → Component 路径($props 宽松)/ 调用签名 → Function 路径
9
19
  * (props = 参数类型,严格)」分流——无构造签名让组件走 Function 路径,
10
- * props 检查精确为 Props & { children }(React 严格语义:未声明 prop 报错)。
20
+ * props 检查精确为 Props(React 严格语义:未声明 prop 报错)。
21
+ * 子内容类型:JSX children 属性来自全局 IntrinsicAttributes(react-jsx
22
+ * 机制);组件内读 props.slots(vue 原生,类型由组件 props 声明或 any)。
11
23
  */
12
24
  type ActViewComponent<Props extends Record<string, any> = Record<string, any>> = {
13
- /** 类型层 call signature:TS 走 Function 路径,props = Props & { children } */
14
- (props: Props & {
15
- children?: any;
16
- }): VNode;
25
+ /** 类型层 call signature:TS 走 Function 路径,props = Props */
26
+ (props: Props): VNode;
17
27
  /** ElementAttributesProperty{ $props } 兜底(vue 全局 JSX 机制) */
18
- $props: Props & {
19
- children?: any;
20
- };
28
+ $props: Props;
21
29
  name?: string;
22
30
  /** vue 组件标记(运行时是 DefineComponent) */
23
31
  __isVue?: true;
@@ -36,8 +44,8 @@ declare function defineComponent<Props extends Record<string, any> = Record<stri
36
44
  interface Context<T> {
37
45
  /** 内部唯一键(Symbol):对象身份即键 */
38
46
  readonly _key: symbol;
39
- /** <Ctx value={v}> 直接作组件用(React 19 风格) */
40
- __setup: (props: any, ctx: any) => any;
47
+ /** vue 组件对象形态的 setup——<Ctx value={v}> 直接作组件用(React 19 风格) */
48
+ setup: (props: any, setupCtx: any) => any;
41
49
  name?: string;
42
50
  /** <Ctx.Provider value={v}> 经典风格 */
43
51
  Provider: Context<T>;
@@ -52,4 +60,4 @@ interface Context<T> {
52
60
  declare function createContext<T extends object>(defaultValue: Reactive<T>): Context<T>;
53
61
  declare function createContext<T>(defaultValue: T): Context<T>;
54
62
 
55
- export { type ActViewComponent, type ActViewDefineComponentOptions, type Context, createContext, defineComponent };
63
+ export { type ActViewComponent, type ActViewDefineComponentOptions, type Context, Suspense, type SuspenseProps, createContext, createVNode, defineComponent };
package/dist/index.js CHANGED
@@ -35,7 +35,6 @@ import {
35
35
  createApp,
36
36
  nextTick,
37
37
  h,
38
- createVNode,
39
38
  cloneVNode,
40
39
  mergeProps,
41
40
  isVNode,
@@ -46,7 +45,6 @@ import {
46
45
  Static,
47
46
  KeepAlive,
48
47
  Teleport,
49
- Suspense,
50
48
  Transition,
51
49
  TransitionGroup,
52
50
  defineAsyncComponent,
@@ -73,12 +71,55 @@ import {
73
71
  version
74
72
  } from "vue";
75
73
  import {
74
+ createVNode as vueCreateVNode,
76
75
  defineComponent as vueDefineComponent,
77
76
  Fragment as _Fragment,
78
77
  h as h2,
79
78
  inject as inject2,
80
- provide as provide2
79
+ isVNode as isVNode2,
80
+ provide as provide2,
81
+ Suspense as VueSuspense
81
82
  } from "vue";
83
+ var activeRenderDepth = 0;
84
+ function wrapSlots(children) {
85
+ if (children && typeof children === "object" && !Array.isArray(children) && !isVNode2(children)) {
86
+ for (const k in children) {
87
+ const fn = children[k];
88
+ if (typeof fn === "function") {
89
+ children[k] = (...args) => {
90
+ activeRenderDepth++;
91
+ try {
92
+ return fn(...args);
93
+ } finally {
94
+ activeRenderDepth--;
95
+ }
96
+ };
97
+ }
98
+ }
99
+ }
100
+ return children;
101
+ }
102
+ function createVNode(type, props, children) {
103
+ if (props && "children" in props) {
104
+ if (children == null) {
105
+ children = props.children;
106
+ }
107
+ delete props.children;
108
+ }
109
+ if (children != null && !Array.isArray(children) && isVNode2(children)) {
110
+ children = [children];
111
+ }
112
+ return vueCreateVNode(type, props, wrapSlots(children));
113
+ }
114
+ var Suspense = defineComponent(function(props) {
115
+ return () => {
116
+ const { fallback, ...rest } = props;
117
+ return h2(VueSuspense, rest, {
118
+ default: () => props.slots?.default?.() ?? [],
119
+ fallback: () => fallback != null ? fallback : []
120
+ });
121
+ };
122
+ }, "ActViewSuspense");
82
123
  function defineComponent(setup, options) {
83
124
  const opts = typeof options === "string" ? { name: options } : options ?? {};
84
125
  return vueDefineComponent({
@@ -90,39 +131,55 @@ function defineComponent(setup, options) {
90
131
  inheritAttrs: !!opts.props,
91
132
  setup(props, ctx) {
92
133
  const attrs = ctx.attrs;
134
+ let renderPhase = false;
135
+ let warnedNonRenderRead = false;
93
136
  const bridge = new Proxy(props, {
94
137
  get(t, k) {
95
- if (k === "children") return ctx.slots.default?.() ?? null;
96
138
  if (k === "slots") return ctx.slots;
139
+ if (k === "children") {
140
+ if (renderPhase || activeRenderDepth > 0) {
141
+ return ctx.slots.default?.() ?? null;
142
+ }
143
+ if (!warnedNonRenderRead) {
144
+ warnedNonRenderRead = true;
145
+ console.warn(
146
+ "[actview] \u975E\u6E32\u67D3\u671F\u8BFB\u53D6 props.children\uFF1A\u63D2\u69FD\u5185\u5BB9\u53EA\u5728\u6E32\u67D3\u671F\u53EF\u7528\u3002\u5224\u65AD\u6709\u65E0\u5B50\u5185\u5BB9\u8BF7\u7528 props.slots.default != null\uFF1B\u6E32\u67D3\u671F\u7528 props.children \u6216 props.slots.default()"
147
+ );
148
+ }
149
+ return void 0;
150
+ }
97
151
  const own = Reflect.get(t, k);
98
152
  if (own !== void 0) return own;
99
153
  return attrs[k];
100
154
  },
101
155
  has(t, k) {
102
- return k === "children" || k === "slots" || Reflect.has(t, k) || k in attrs;
156
+ return k === "slots" || k === "children" || Reflect.has(t, k) || k in attrs;
103
157
  },
104
158
  ownKeys(t) {
105
159
  return [
106
160
  .../* @__PURE__ */ new Set([
107
161
  ...Reflect.ownKeys(t),
108
- ...Reflect.ownKeys(attrs),
109
- "children",
110
- "slots"
162
+ ...Reflect.ownKeys(attrs)
111
163
  ])
112
164
  ];
113
165
  },
114
166
  getOwnPropertyDescriptor(t, k) {
115
- if (k === "children" || k === "slots") {
116
- return {
117
- enumerable: true,
118
- configurable: true,
119
- value: k === "children" ? ctx.slots.default?.() ?? null : ctx.slots
120
- };
121
- }
122
167
  return Reflect.getOwnPropertyDescriptor(t, k) ?? Reflect.getOwnPropertyDescriptor(attrs, k);
123
168
  }
124
169
  });
125
- return setup(bridge, ctx);
170
+ const userResult = setup(bridge, ctx);
171
+ if (typeof userResult === "function") {
172
+ const userRender = userResult;
173
+ return () => {
174
+ renderPhase = true;
175
+ try {
176
+ return userRender();
177
+ } finally {
178
+ renderPhase = false;
179
+ }
180
+ };
181
+ }
182
+ return userResult;
126
183
  }
127
184
  // 返回类型以声明为准(vue 的推断带 ExtractPropTypes 包装,与泛型 Props 不完全同构)
128
185
  });
@@ -131,13 +188,19 @@ function createContext(defaultValue) {
131
188
  const key = /* @__PURE__ */ Symbol("actview-context");
132
189
  const provider = defineComponent(function(props) {
133
190
  provide2(key, props.value ?? defaultValue);
134
- return () => h2(_Fragment, null, props.children ?? null);
191
+ return () => h2(_Fragment, null, props.slots.default?.() ?? null);
135
192
  }, "ActViewContext.Provider");
136
193
  const ctx = {
137
194
  _key: key,
138
- __setup: provider.__setup,
139
195
  name: "ActViewContext",
140
196
  Provider: provider,
197
+ // React 19 风格 <Ctx value={v}>:Context 直接作组件——
198
+ // vue 组件对象 setup 形态(provide + 渲染 children)
199
+ setup(props, setupCtx) {
200
+ const value = props.value ?? setupCtx.attrs?.value ?? defaultValue;
201
+ provide2(key, value);
202
+ return () => h2(_Fragment, null, setupCtx.slots?.default?.() ?? null);
203
+ },
141
204
  use() {
142
205
  return inject2(key, defaultValue);
143
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "actview",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "type": "module",
5
5
  "description": "ActView v2:Vue 引擎 + React 语义 JSX(运行时基于 vue 官方包,JSX 由 @actview/plugin-jsx 编译)",
6
6
  "exports": {