weifuwu 0.33.10 → 0.34.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.
@@ -1,34 +1,18 @@
1
1
  /**
2
- * weifuwu/client 应用 — 创建 ctx + 中间件链 + 挂载组件
2
+ * weifuwu/client 应用 — createApp + ctx.ui.render
3
3
  *
4
- * ```tsx
5
- * import { createApp, ws, router } from 'weifuwu/client'
4
+ * createApp() → app.use(mw) → app.mount('#root', RootComponent)
6
5
  *
7
- * const app = createApp()
8
- * app.use(ws())
9
- * app.use(router({ routes }))
10
- * app.mount('#root', AppShell)
11
- * ```
6
+ * ctx.ui mount 时注入:
7
+ * ctx.ui.render() 触发组件重渲染
8
+ * ctx.ui.$ 持久化组件状态(由渲染器管理)
9
+ * ctx.ui.ready 首次执行标记(由渲染器管理)
12
10
  */
13
11
  import type { WfuiContext, AppMiddleware } from './types.ts';
14
- import type { Component } from './jsx-runtime.ts';
15
- /**
16
- * 创建 weifuwu/client 应用
17
- */
12
+ import type { Component } from './vnode.ts';
18
13
  export declare function createApp(): {
19
- ctx: WfuiContext;
20
- use: (mw: AppMiddleware) => any;
21
- mount: (rootSelector: string, RootComponent: Component) => Promise<void>;
22
- /**
23
- * Hydrate 一个已由 SSR 渲染的区域。
24
- * 不清除目标容器内的内容,只附加组件输出。
25
- *
26
- * ```ts
27
- * const app = createApp()
28
- * app.use(api())
29
- * app.use(auth())
30
- * app.hydrate('#comments', CommentSection, { postId: '123' })
31
- * ```
32
- */
33
- hydrate: (selector: string, Component: Component, props?: Record<string, unknown>) => void;
14
+ readonly ctx: WfuiContext;
15
+ use(mw: AppMiddleware): /*elided*/ any;
16
+ mount(rootSelector: string, RootComponent: Component): Promise<void>;
17
+ destroy(): void;
34
18
  };
@@ -1,139 +1,29 @@
1
1
  /**
2
- * weifuwu/client — 响应式前端框架,TSX + Signal
3
- *
4
- * 零虚拟 DOM,零外部依赖。组件模型:(props, ctx) => Node。
5
- *
6
- * ```tsx
7
- * import { signal, createApp, api, auth, ws, router, RouteView, Show, For } from 'weifuwu/client'
8
- * import type { WfuiContext } from 'weifuwu/client'
9
- *
10
- * const app = createApp()
11
- * app.use(api())
12
- * app.use(auth())
13
- * app.use(ws())
14
- * app.use(router({ routes }))
15
- * app.mount('#root', AppShell)
16
- * ```
17
- *
18
- * ## 核心概念
19
- *
20
- * | 导出 | 类型 | 用途 |
21
- * |------|------|------|
22
- * | `signal()` | function | 响应式数据容器 |
23
- * | `computed()` | function | 衍生信号 |
24
- * | `effect()` | function | 自动追踪依赖的副作用 |
25
- * | `batch()` | function | 批量更新(合并多次写入为一次通知)|
26
- * | `untrack()` | function | 不追踪依赖地读取信号 |
27
- * | `onMount()` | function | 组件挂载回调 |
28
- * | `onCleanup()` | function | 组件卸载回调 |
29
- * | `createApp()` | function | 应用实例(中间件链 + 挂载) |
30
- * | `createResource()` | function | 异步数据资源(loading/error/data)|
31
- * | `useForm()` | function | 表单状态管理(字段绑定/验证/提交)|
32
- * | `createStyles()` | function | 组件级作用域 CSS |
33
- */
34
- /** 创建响应式数据容器。变化时自动通知依赖方。 */
35
- export { signal } from './signal.ts';
36
- /** 基于其他 signal 的衍生值,自动缓存。 */
37
- export { computed } from './signal.ts';
38
- /** 自动追踪 signal 依赖,变化时重跑回调。返回 dispose 函数。 */
39
- export { effect } from './signal.ts';
40
- /**
41
- * 批量更新 — 将多个信号写入合并为一次通知。
42
- *
43
- * ```ts
44
- * batch(() => {
45
- * a.value = 1
46
- * b.value = 2
47
- * })
48
- * // 只触发一次 effect,而非两次
49
- * ```
50
- */
51
- export { batch } from './signal.ts';
52
- /** Signal 类型。 */
53
- export type { Signal } from './signal.ts';
54
- /** JSX 工厂函数 — 由 esbuild / tsc 自动调用。 */
55
- export { jsx, jsxs, jsxDEV } from './jsx-runtime.ts';
56
- /** 不产生包装元素的片段组件。 */
57
- export { Fragment } from './jsx-runtime.ts';
58
- /**
59
- * 条件渲染 — when 为 Signal 时响应式切换。
60
- *
61
- * ```tsx
62
- * <Show when={isLoggedIn} fallback={<LoginPage />}>
63
- * <Dashboard />
64
- * </Show>
65
- * ```
66
- */
67
- export { Show } from './jsx-runtime.ts';
68
- /**
69
- * 列表渲染 — each 为 Signal 时响应式更新。支持 keyBy 属性复用 DOM 节点。
70
- *
71
- * ```tsx
72
- * <For each={items} keyBy="id">
73
- * {(item) => <div>{item.name}</div>}
74
- * </For>
75
- * ```
76
- */
77
- export { For } from './jsx-runtime.ts';
78
- /**
79
- * onMount — 组件根元素挂载到 DOM 后执行的回调。
80
- * 返回函数在组件卸载时自动清理。
81
- *
82
- * ```tsx
83
- * function Chart() {
84
- * onMount(() => {
85
- * const chart = echarts.init(el)
86
- * return () => chart.dispose()
87
- * })
88
- * return <div ref={el => chartEl = el} />
89
- * }
90
- * ```
91
- */
92
- export { onMount } from './jsx-runtime.ts';
93
- /**
94
- * onCleanup — 组件卸载时执行的回调(清理定时器、订阅等)。
95
- *
96
- * ```tsx
97
- * function Timer() {
98
- * const id = setInterval(tick, 1000)
99
- * onCleanup(() => clearInterval(id))
100
- * return <div>...</div>
101
- * }
102
- * ```
103
- */
104
- export { onCleanup } from './jsx-runtime.ts';
105
- /** 组件类型签名:(props, ctx) => Node */
106
- export type { Component } from './jsx-runtime.ts';
107
- /** 应用上下文 — 组件通过第二个参数 ctx 访问。 */
108
- export type { WfuiContext } from './types.ts';
109
- /** 中间件签名:(ctx) => ctx */
110
- export type { AppMiddleware } from './types.ts';
111
- /** 路由定义:path / component / auth / title / loader */
112
- export type { RouteDef } from './types.ts';
113
- /**
114
- * 创建 weifuwu/client 应用实例。
115
- *
116
- * ```tsx
117
- * const app = createApp()
118
- * app.use(api())
119
- * app.use(auth())
120
- * app.use(router({ routes }))
121
- * await app.mount('#root', AppShell)
122
- * ```
123
- */
2
+ * weifuwu/client — VDOM 前端框架
3
+ *
4
+ * 概念:
5
+ * 组件 = (props, ctx) => VNode
6
+ * 状态 = JS 变量
7
+ * 更新 = ctx.ui.render()
8
+ * 挂载/卸载 = ref 回调
9
+ *
10
+ * 导出:
11
+ * h / jsx / jsxs / jsxDEV / Fragment → JSX 工厂
12
+ * createApp → 应用引导
13
+ * router / RouteView → 路由
14
+ * api / auth / ws → 中间件
15
+ * extendCtx → ctx 扩展
16
+ * WfuiContext / AppMiddleware / RouteDef → 类型
17
+ */
18
+ export { h, jsx, jsxs, jsxDEV, Fragment } from './vnode.ts';
19
+ export type { VNode, VNodeType, Component } from './vnode.ts';
124
20
  export { createApp } from './app.ts';
125
- /**
126
- * 路由中间件 — 注入 ctx.route / ctx.app.navigate。
127
- * 支持 hash / history 模式,loader 数据预取,auth 守卫。
128
- */
129
- export { router } from './router.ts';
130
- /**
131
- * RouteView 组件 — 渲染当前路由匹配的组件。
132
- * 用 `<RouteView />` 放在布局中作为路由出口。
133
- */
134
- export { RouteView } from './router.ts';
135
- /**
136
- * WebSocket 中间件 — 注入 ctx.ws(send / onMessage / join / leave)。
137
- * 自动重连,支持房间。
138
- */
21
+ export { router, RouteView } from './router.ts';
139
22
  export { ws } from './middleware/ws.ts';
23
+ export { api } from './middleware/api.ts';
24
+ export { auth } from './middleware/auth.ts';
25
+ export type { ApiClient, ApiOptions, ApiRequestOptions } from './middleware/api.ts';
26
+ export { ApiError } from './middleware/api.ts';
27
+ export type { AuthClient, AuthOptions } from './middleware/auth.ts';
28
+ export { extendCtx } from './types.ts';
29
+ export type { WfuiContext, AppMiddleware, RouteDef } from './types.ts';