actview 1.1.0 → 3.0.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 +46 -1
- package/dist/index.js +135 -43
- package/package.json +3 -3
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 兜底,`inheritAttrs: false`
|
|
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,46 @@
|
|
|
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
|
+
declare function defineComponent<Props extends Record<string, any> = Record<string, any>>(setup: (props: Props, ctx: SetupContext) => unknown, name?: string): ActViewComponent<Props>;
|
|
27
|
+
interface Context<T> {
|
|
28
|
+
/** 内部唯一键(Symbol):对象身份即键 */
|
|
29
|
+
readonly _key: symbol;
|
|
30
|
+
/** <Ctx value={v}> 直接作组件用(React 19 风格) */
|
|
31
|
+
__setup: (props: any, ctx: any) => any;
|
|
32
|
+
name?: string;
|
|
33
|
+
/** <Ctx.Provider value={v}> 经典风格 */
|
|
34
|
+
Provider: Context<T>;
|
|
35
|
+
/** 消费:返回注入表中原样存储的值;无 Provider 时返回 defaultValue */
|
|
36
|
+
use: () => T;
|
|
37
|
+
/** 类型层面伪装 call signature,让 <Ctx value=...> 通过 JSX 类型检查 */
|
|
38
|
+
(props: {
|
|
39
|
+
value?: T;
|
|
40
|
+
children?: any;
|
|
41
|
+
}): any;
|
|
42
|
+
}
|
|
43
|
+
declare function createContext<T extends object>(defaultValue: Reactive<T>): Context<T>;
|
|
44
|
+
declare function createContext<T>(defaultValue: T): Context<T>;
|
|
45
|
+
|
|
46
|
+
export { type ActViewComponent, 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,116 @@ 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, name) {
|
|
83
|
+
return vueDefineComponent({
|
|
84
|
+
name,
|
|
85
|
+
// 未消费 props 不自动落根 DOM(React 语义;Vue 默认 inheritAttrs 会落)
|
|
86
|
+
inheritAttrs: false,
|
|
87
|
+
setup(props, ctx) {
|
|
88
|
+
const attrs = ctx.attrs;
|
|
89
|
+
const bridge = new Proxy(props, {
|
|
90
|
+
get(t, k) {
|
|
91
|
+
if (k === "children") return ctx.slots.default?.() ?? null;
|
|
92
|
+
if (k === "slots") return ctx.slots;
|
|
93
|
+
const own = Reflect.get(t, k);
|
|
94
|
+
if (own !== void 0) return own;
|
|
95
|
+
return attrs[k];
|
|
96
|
+
},
|
|
97
|
+
has(t, k) {
|
|
98
|
+
return k === "children" || k === "slots" || Reflect.has(t, k) || k in attrs;
|
|
99
|
+
},
|
|
100
|
+
ownKeys(t) {
|
|
101
|
+
return [
|
|
102
|
+
.../* @__PURE__ */ new Set([
|
|
103
|
+
...Reflect.ownKeys(t),
|
|
104
|
+
...Reflect.ownKeys(attrs),
|
|
105
|
+
"children",
|
|
106
|
+
"slots"
|
|
107
|
+
])
|
|
108
|
+
];
|
|
109
|
+
},
|
|
110
|
+
getOwnPropertyDescriptor(t, k) {
|
|
111
|
+
if (k === "children" || k === "slots") {
|
|
112
|
+
return {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
configurable: true,
|
|
115
|
+
value: k === "children" ? ctx.slots.default?.() ?? null : ctx.slots
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return Reflect.getOwnPropertyDescriptor(t, k) ?? Reflect.getOwnPropertyDescriptor(attrs, k);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return setup(bridge, ctx);
|
|
122
|
+
}
|
|
123
|
+
// 返回类型以声明为准(vue 的推断带 ExtractPropTypes 包装,与泛型 Props 不完全同构)
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function createContext(defaultValue) {
|
|
127
|
+
const key = /* @__PURE__ */ Symbol("actview-context");
|
|
128
|
+
const provider = defineComponent(function(props) {
|
|
129
|
+
provide2(key, props.value ?? defaultValue);
|
|
130
|
+
return () => h2(_Fragment, null, props.children ?? null);
|
|
131
|
+
}, "ActViewContext.Provider");
|
|
132
|
+
const ctx = {
|
|
133
|
+
_key: key,
|
|
134
|
+
__setup: provider.__setup,
|
|
135
|
+
name: "ActViewContext",
|
|
136
|
+
Provider: provider,
|
|
137
|
+
use() {
|
|
138
|
+
return inject2(key, defaultValue);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
return ctx;
|
|
142
|
+
}
|
|
63
143
|
export {
|
|
64
|
-
|
|
144
|
+
Comment,
|
|
145
|
+
EffectScope,
|
|
146
|
+
Fragment,
|
|
65
147
|
KeepAlive,
|
|
148
|
+
Static,
|
|
66
149
|
Suspense,
|
|
67
150
|
Teleport,
|
|
151
|
+
Text,
|
|
68
152
|
Transition,
|
|
69
153
|
TransitionGroup,
|
|
154
|
+
cloneVNode,
|
|
70
155
|
computed,
|
|
71
156
|
createApp,
|
|
72
157
|
createContext,
|
|
158
|
+
createVNode,
|
|
159
|
+
customRef,
|
|
160
|
+
defineAsyncComponent,
|
|
73
161
|
defineComponent,
|
|
74
162
|
effectScope,
|
|
75
163
|
getCurrentInstance,
|
|
76
164
|
getCurrentScope,
|
|
77
|
-
|
|
165
|
+
h,
|
|
166
|
+
inject,
|
|
78
167
|
isProxy,
|
|
79
168
|
isReactive,
|
|
80
169
|
isReadonly,
|
|
81
170
|
isRef,
|
|
82
171
|
isShallow,
|
|
83
|
-
|
|
172
|
+
isVNode,
|
|
84
173
|
markRaw,
|
|
174
|
+
mergeProps,
|
|
85
175
|
nextTick,
|
|
86
176
|
onActivated,
|
|
87
177
|
onBeforeMount,
|
|
@@ -97,12 +187,12 @@ export {
|
|
|
97
187
|
onUpdated,
|
|
98
188
|
onWatcherCleanup,
|
|
99
189
|
provide,
|
|
100
|
-
|
|
190
|
+
proxyRefs,
|
|
101
191
|
reactive,
|
|
102
192
|
readonly,
|
|
103
193
|
ref,
|
|
104
|
-
|
|
105
|
-
|
|
194
|
+
resolveComponent,
|
|
195
|
+
resolveDirective,
|
|
106
196
|
shallowReactive,
|
|
107
197
|
shallowReadonly,
|
|
108
198
|
shallowRef,
|
|
@@ -112,12 +202,14 @@ export {
|
|
|
112
202
|
toValue,
|
|
113
203
|
triggerRef,
|
|
114
204
|
unref,
|
|
115
|
-
|
|
205
|
+
useAttrs,
|
|
116
206
|
useId,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
useRootElement,
|
|
207
|
+
useSlots,
|
|
208
|
+
useTemplateRef,
|
|
209
|
+
version,
|
|
121
210
|
watch,
|
|
122
|
-
watchEffect
|
|
211
|
+
watchEffect,
|
|
212
|
+
watchPostEffect,
|
|
213
|
+
watchSyncEffect,
|
|
214
|
+
withDirectives
|
|
123
215
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "actview",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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",
|
|
@@ -9,8 +10,7 @@
|
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
|
-
"
|
|
13
|
-
"@actview/jsx": "^1.1.0"
|
|
13
|
+
"vue": "^3.5.0"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|