actview 1.1.1 → 3.1.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 +91 -63
- package/dist/index.d.ts +55 -1
- package/dist/index.js +139 -43
- package/package.json +4 -8
package/README.md
CHANGED
|
@@ -1,63 +1,91 @@
|
|
|
1
|
-
# actview
|
|
2
|
-
|
|
3
|
-
**ActView
|
|
4
|
-
|
|
5
|
-
`
|
|
6
|
-
|
|
7
|
-
## 核心功能
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## 安装
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
pnpm add actview
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
# actview
|
|
2
|
+
|
|
3
|
+
**ActView v2 — Vue 引擎 + React 语义 JSX**
|
|
4
|
+
|
|
5
|
+
运行时基于 `vue` 官方包(零自研):响应式 / 调度 / patch / diff / 内置组件 / SSR 全部复用。JSX 语法层面对齐 React:`className` / `htmlFor` / `onChange` 语义、`{}` 表达式、受控组件、`props.children` 直读。
|
|
6
|
+
|
|
7
|
+
## 核心功能
|
|
8
|
+
|
|
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)
|
|
11
|
+
- **createContext**:React 语义(`.Provider` / `.use()`),基于 vue `provide/inject`
|
|
12
|
+
- **JSX 类型层**:全局 `IntrinsicElements` 完整标签表(React 语义属性)+ vue 组件兼容;组件 props 严格检查(未声明 prop 报错)
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add actview vue
|
|
18
|
+
pnpm add -D @actview/plugin-vite
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`vite.config.ts`:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { defineConfig } from 'vite'
|
|
25
|
+
import { actviewJsxPlugin } from '@actview/plugin-vite'
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
plugins: [actviewJsxPlugin()],
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`tsconfig.json`:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"compilerOptions": {
|
|
37
|
+
"jsx": "react-jsx",
|
|
38
|
+
"jsxImportSource": "actview"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 快速开始
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { createApp, ref } from 'actview'
|
|
47
|
+
|
|
48
|
+
// 函数组件:编译期自动包 defineComponent(React 函数组件语义)
|
|
49
|
+
function App() {
|
|
50
|
+
const count = ref(0)
|
|
51
|
+
return () => (
|
|
52
|
+
<button className="c" onClick={() => count.value++}>
|
|
53
|
+
{count.value}
|
|
54
|
+
</button>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
createApp(App).mount('#app')
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
JSX 由 `@actview/plugin-jsx` 编译(Babel 直出 `createVNode`):
|
|
62
|
+
- `className` → `class`、`htmlFor` → `for`、`onChange` → `onInput`(text-like input/textarea)
|
|
63
|
+
- `dangerouslySetInnerHTML={{ __html }}` → `innerHTML`
|
|
64
|
+
- `v-model` / `v-show` 等 Vue 指令属性可直接使用
|
|
65
|
+
- `props.children` 桥接:组件内直接读 `props.children`(React 语义)
|
|
66
|
+
|
|
67
|
+
## 生态复用(不重复造轮子)
|
|
68
|
+
|
|
69
|
+
| 需求 | 方案 |
|
|
70
|
+
|---|---|
|
|
71
|
+
| 路由 | `vue-router` |
|
|
72
|
+
| 状态管理 | `pinia` |
|
|
73
|
+
| 测试 | `@testing-library/vue` |
|
|
74
|
+
| devtools | vue devtools(浏览器插件) |
|
|
75
|
+
| hooks | vue 原语(`ref` / `computed` / `watch` 内联组合) |
|
|
76
|
+
|
|
77
|
+
## API(re-export 自 vue)
|
|
78
|
+
|
|
79
|
+
| 分组 | 导出 |
|
|
80
|
+
|---|---|
|
|
81
|
+
| 应用 | `createApp` |
|
|
82
|
+
| 组件 | `defineComponent`(桥接版)/ `h` / `createVNode` / `mergeProps` / `defineAsyncComponent` |
|
|
83
|
+
| 响应式 | `ref` / `reactive` / `computed` / `watch` / `watchEffect` / `customRef` / `proxyRefs` / `effectScope` / `nextTick` |
|
|
84
|
+
| 生命周期 | `onMounted` / `onUpdated` / `onBeforeUnmount` / `onUnmounted` / `onErrorCaptured` / `onServerPrefetch` |
|
|
85
|
+
| 依赖注入 | `provide` / `inject` / `createContext` |
|
|
86
|
+
| 内置组件 | `KeepAlive` / `Teleport` / `Suspense` / `Transition` / `TransitionGroup` / `Fragment` / `Text` |
|
|
87
|
+
| 其他 | `useId` / `useTemplateRef` / `useAttrs` / `useSlots` / `version` |
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,55 @@
|
|
|
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';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* v2 组件类型(类型层形状):
|
|
6
|
+
* 运行时是 vue DefineComponent(createApp/渲染消费),但类型层用自定义形状
|
|
7
|
+
* ——只有 call signature、无构造签名。TS 6 的 JSX 检查(getJsxReferenceKind)
|
|
8
|
+
* 按「构造签名 → Component 路径($props 宽松)/ 调用签名 → Function 路径
|
|
9
|
+
* (props = 参数类型,严格)」分流——无构造签名让组件走 Function 路径,
|
|
10
|
+
* props 检查精确为 Props & { children }(React 严格语义:未声明 prop 报错)。
|
|
11
|
+
*/
|
|
12
|
+
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;
|
|
17
|
+
/** ElementAttributesProperty{ $props } 兜底(vue 全局 JSX 机制) */
|
|
18
|
+
$props: Props & {
|
|
19
|
+
children?: any;
|
|
20
|
+
};
|
|
21
|
+
name?: string;
|
|
22
|
+
/** vue 组件标记(运行时是 DefineComponent) */
|
|
23
|
+
__isVue?: true;
|
|
24
|
+
__vccOpts?: any;
|
|
25
|
+
};
|
|
26
|
+
interface ActViewDefineComponentOptions {
|
|
27
|
+
name?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 运行时 props 声明(@actview/plugin-jsx 编译期从类型注解提取注入,
|
|
30
|
+
* 也可手写)。存在时开启自动落根:未消费的 attrs(class / data-v-* /
|
|
31
|
+
* 事件 / 透传属性)自动 apply 到根元素。
|
|
32
|
+
*/
|
|
33
|
+
props?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
declare function defineComponent<Props extends Record<string, any> = Record<string, any>>(setup: (props: Props, ctx: SetupContext) => unknown, options?: ActViewDefineComponentOptions | string): ActViewComponent<Props>;
|
|
36
|
+
interface Context<T> {
|
|
37
|
+
/** 内部唯一键(Symbol):对象身份即键 */
|
|
38
|
+
readonly _key: symbol;
|
|
39
|
+
/** <Ctx value={v}> 直接作组件用(React 19 风格) */
|
|
40
|
+
__setup: (props: any, ctx: any) => any;
|
|
41
|
+
name?: string;
|
|
42
|
+
/** <Ctx.Provider value={v}> 经典风格 */
|
|
43
|
+
Provider: Context<T>;
|
|
44
|
+
/** 消费:返回注入表中原样存储的值;无 Provider 时返回 defaultValue */
|
|
45
|
+
use: () => T;
|
|
46
|
+
/** 类型层面伪装 call signature,让 <Ctx value=...> 通过 JSX 类型检查 */
|
|
47
|
+
(props: {
|
|
48
|
+
value?: T;
|
|
49
|
+
children?: any;
|
|
50
|
+
}): any;
|
|
51
|
+
}
|
|
52
|
+
declare function createContext<T extends object>(defaultValue: Reactive<T>): Context<T>;
|
|
53
|
+
declare function createContext<T>(defaultValue: T): Context<T>;
|
|
54
|
+
|
|
55
|
+
export { type ActViewComponent, type ActViewDefineComponentOptions, type Context, createContext, defineComponent };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
ref,
|
|
4
|
+
shallowRef,
|
|
5
|
+
triggerRef,
|
|
6
|
+
isRef,
|
|
7
|
+
unref,
|
|
8
|
+
toValue,
|
|
9
|
+
toRef,
|
|
10
|
+
toRefs,
|
|
5
11
|
reactive,
|
|
6
12
|
shallowReactive,
|
|
7
13
|
readonly,
|
|
@@ -12,23 +18,38 @@ import {
|
|
|
12
18
|
isReadonly,
|
|
13
19
|
isProxy,
|
|
14
20
|
isShallow,
|
|
15
|
-
nextTick,
|
|
16
21
|
computed,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
triggerRef,
|
|
20
|
-
isRef,
|
|
21
|
-
unref,
|
|
22
|
-
unrefs,
|
|
23
|
-
toValue,
|
|
24
|
-
toRef,
|
|
25
|
-
toRefs,
|
|
26
|
-
rawRef,
|
|
22
|
+
customRef,
|
|
23
|
+
proxyRefs,
|
|
27
24
|
watch,
|
|
28
25
|
watchEffect,
|
|
26
|
+
watchPostEffect,
|
|
27
|
+
watchSyncEffect,
|
|
29
28
|
onWatcherCleanup,
|
|
30
29
|
effectScope,
|
|
30
|
+
getCurrentScope,
|
|
31
31
|
onScopeDispose,
|
|
32
|
+
EffectScope
|
|
33
|
+
} from "vue";
|
|
34
|
+
import {
|
|
35
|
+
createApp,
|
|
36
|
+
nextTick,
|
|
37
|
+
h,
|
|
38
|
+
createVNode,
|
|
39
|
+
cloneVNode,
|
|
40
|
+
mergeProps,
|
|
41
|
+
isVNode,
|
|
42
|
+
withDirectives,
|
|
43
|
+
Fragment,
|
|
44
|
+
Text,
|
|
45
|
+
Comment,
|
|
46
|
+
Static,
|
|
47
|
+
KeepAlive,
|
|
48
|
+
Teleport,
|
|
49
|
+
Suspense,
|
|
50
|
+
Transition,
|
|
51
|
+
TransitionGroup,
|
|
52
|
+
defineAsyncComponent,
|
|
32
53
|
onBeforeMount,
|
|
33
54
|
onMounted,
|
|
34
55
|
onUpdated,
|
|
@@ -41,47 +62,120 @@ import {
|
|
|
41
62
|
onRenderTracked,
|
|
42
63
|
onRenderTriggered,
|
|
43
64
|
provide,
|
|
44
|
-
|
|
45
|
-
useId,
|
|
46
|
-
useRootElement,
|
|
47
|
-
useProp,
|
|
48
|
-
useProps,
|
|
65
|
+
inject,
|
|
49
66
|
getCurrentInstance,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
useId,
|
|
68
|
+
useAttrs,
|
|
69
|
+
useSlots,
|
|
70
|
+
useTemplateRef,
|
|
71
|
+
resolveComponent,
|
|
72
|
+
resolveDirective,
|
|
73
|
+
version
|
|
74
|
+
} from "vue";
|
|
75
|
+
import {
|
|
76
|
+
defineComponent as vueDefineComponent,
|
|
77
|
+
Fragment as _Fragment,
|
|
78
|
+
h as h2,
|
|
79
|
+
inject as inject2,
|
|
80
|
+
provide as provide2
|
|
81
|
+
} from "vue";
|
|
82
|
+
function defineComponent(setup, options) {
|
|
83
|
+
const opts = typeof options === "string" ? { name: options } : options ?? {};
|
|
84
|
+
return vueDefineComponent({
|
|
85
|
+
name: opts.name,
|
|
86
|
+
// 编译期提取的 props 声明(无则 undefined——组件保持「任意 props 兜底」)
|
|
87
|
+
props: opts.props,
|
|
88
|
+
// 有 props 声明 → 开启自动落根(透传 + scoped data-v 生效);
|
|
89
|
+
// 无声明 → false(React 语义:避免未消费 props 以 DOM 属性形式污染根元素)
|
|
90
|
+
inheritAttrs: !!opts.props,
|
|
91
|
+
setup(props, ctx) {
|
|
92
|
+
const attrs = ctx.attrs;
|
|
93
|
+
const bridge = new Proxy(props, {
|
|
94
|
+
get(t, k) {
|
|
95
|
+
if (k === "children") return ctx.slots.default?.() ?? null;
|
|
96
|
+
if (k === "slots") return ctx.slots;
|
|
97
|
+
const own = Reflect.get(t, k);
|
|
98
|
+
if (own !== void 0) return own;
|
|
99
|
+
return attrs[k];
|
|
100
|
+
},
|
|
101
|
+
has(t, k) {
|
|
102
|
+
return k === "children" || k === "slots" || Reflect.has(t, k) || k in attrs;
|
|
103
|
+
},
|
|
104
|
+
ownKeys(t) {
|
|
105
|
+
return [
|
|
106
|
+
.../* @__PURE__ */ new Set([
|
|
107
|
+
...Reflect.ownKeys(t),
|
|
108
|
+
...Reflect.ownKeys(attrs),
|
|
109
|
+
"children",
|
|
110
|
+
"slots"
|
|
111
|
+
])
|
|
112
|
+
];
|
|
113
|
+
},
|
|
114
|
+
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
|
+
return Reflect.getOwnPropertyDescriptor(t, k) ?? Reflect.getOwnPropertyDescriptor(attrs, k);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return setup(bridge, ctx);
|
|
126
|
+
}
|
|
127
|
+
// 返回类型以声明为准(vue 的推断带 ExtractPropTypes 包装,与泛型 Props 不完全同构)
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function createContext(defaultValue) {
|
|
131
|
+
const key = /* @__PURE__ */ Symbol("actview-context");
|
|
132
|
+
const provider = defineComponent(function(props) {
|
|
133
|
+
provide2(key, props.value ?? defaultValue);
|
|
134
|
+
return () => h2(_Fragment, null, props.children ?? null);
|
|
135
|
+
}, "ActViewContext.Provider");
|
|
136
|
+
const ctx = {
|
|
137
|
+
_key: key,
|
|
138
|
+
__setup: provider.__setup,
|
|
139
|
+
name: "ActViewContext",
|
|
140
|
+
Provider: provider,
|
|
141
|
+
use() {
|
|
142
|
+
return inject2(key, defaultValue);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return ctx;
|
|
146
|
+
}
|
|
63
147
|
export {
|
|
64
|
-
|
|
148
|
+
Comment,
|
|
149
|
+
EffectScope,
|
|
150
|
+
Fragment,
|
|
65
151
|
KeepAlive,
|
|
152
|
+
Static,
|
|
66
153
|
Suspense,
|
|
67
154
|
Teleport,
|
|
155
|
+
Text,
|
|
68
156
|
Transition,
|
|
69
157
|
TransitionGroup,
|
|
158
|
+
cloneVNode,
|
|
70
159
|
computed,
|
|
71
160
|
createApp,
|
|
72
161
|
createContext,
|
|
162
|
+
createVNode,
|
|
163
|
+
customRef,
|
|
164
|
+
defineAsyncComponent,
|
|
73
165
|
defineComponent,
|
|
74
166
|
effectScope,
|
|
75
167
|
getCurrentInstance,
|
|
76
168
|
getCurrentScope,
|
|
77
|
-
|
|
169
|
+
h,
|
|
170
|
+
inject,
|
|
78
171
|
isProxy,
|
|
79
172
|
isReactive,
|
|
80
173
|
isReadonly,
|
|
81
174
|
isRef,
|
|
82
175
|
isShallow,
|
|
83
|
-
|
|
176
|
+
isVNode,
|
|
84
177
|
markRaw,
|
|
178
|
+
mergeProps,
|
|
85
179
|
nextTick,
|
|
86
180
|
onActivated,
|
|
87
181
|
onBeforeMount,
|
|
@@ -97,12 +191,12 @@ export {
|
|
|
97
191
|
onUpdated,
|
|
98
192
|
onWatcherCleanup,
|
|
99
193
|
provide,
|
|
100
|
-
|
|
194
|
+
proxyRefs,
|
|
101
195
|
reactive,
|
|
102
196
|
readonly,
|
|
103
197
|
ref,
|
|
104
|
-
|
|
105
|
-
|
|
198
|
+
resolveComponent,
|
|
199
|
+
resolveDirective,
|
|
106
200
|
shallowReactive,
|
|
107
201
|
shallowReadonly,
|
|
108
202
|
shallowRef,
|
|
@@ -112,12 +206,14 @@ export {
|
|
|
112
206
|
toValue,
|
|
113
207
|
triggerRef,
|
|
114
208
|
unref,
|
|
115
|
-
|
|
209
|
+
useAttrs,
|
|
116
210
|
useId,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
useRootElement,
|
|
211
|
+
useSlots,
|
|
212
|
+
useTemplateRef,
|
|
213
|
+
version,
|
|
121
214
|
watch,
|
|
122
|
-
watchEffect
|
|
215
|
+
watchEffect,
|
|
216
|
+
watchPostEffect,
|
|
217
|
+
watchSyncEffect,
|
|
218
|
+
withDirectives
|
|
123
219
|
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "actview",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"description": "ActView v2:Vue 引擎 + React 语义 JSX(运行时基于 vue 官方包,JSX 由 @actview/plugin-jsx 编译)",
|
|
5
6
|
"exports": {
|
|
6
7
|
".": {
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
9
|
"import": "./dist/index.js"
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"@actview/jsx": "^1.1.0"
|
|
14
|
-
},
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"@actview/core": "^1.1.0",
|
|
17
|
-
"@actview/jsx": "^1.1.0"
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"vue": "^3.5.0"
|
|
18
14
|
},
|
|
19
15
|
"files": [
|
|
20
16
|
"dist"
|