weifuwu 0.74.0 → 0.76.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 +20 -20
- package/dist/ai/types.d.ts +3 -1
- package/dist/components/AiChat/AiChat.d.ts +5 -1
- package/dist/components/ApprovalCard/ApprovalCard.d.ts +5 -2
- package/dist/components/Button/Button.d.ts +2 -0
- package/dist/components/CitationCard/CitationCard.d.ts +38 -0
- package/dist/components/Command/Command.d.ts +1 -1
- package/dist/components/JsonSchemaForm/JsonSchemaForm.d.ts +48 -0
- package/dist/components/ReasoningBlock/ReasoningBlock.d.ts +25 -0
- package/dist/components/Select/Select.d.ts +11 -1
- package/dist/components/SessionList/SessionList.d.ts +42 -0
- package/dist/components/TreeSelect/TreeSelect.d.ts +3 -2
- package/dist/components/index.d.ts +10 -2
- package/dist/components/index.js +14 -14
- package/dist/components/style.css +608 -20
- package/dist/index.d.ts +0 -2
- package/dist/index.js +141 -433
- package/dist/layout/weifuwu-layout.css +9 -0
- package/dist/test/client/setup.d.ts +12 -0
- package/dist/ui/index.d.ts +3 -3
- package/dist/ui-dom/Confirm.d.ts +5 -41
- package/dist/ui-dom/Notification.d.ts +8 -70
- package/dist/ui-dom/Toast.d.ts +8 -43
- package/dist/ui-dom/ai.d.ts +1 -1
- package/dist/ui-dom/browser.d.ts +1 -1
- package/dist/ui-dom/focus-trap.d.ts +1 -1
- package/dist/ui-dom/hooks/chat.d.ts +11 -0
- package/dist/ui-dom/hooks/events.d.ts +30 -0
- package/dist/ui-dom/hooks/external.d.ts +20 -0
- package/dist/ui-dom/hooks/index.d.ts +31 -0
- package/dist/ui-dom/hooks/input.d.ts +33 -0
- package/dist/ui-dom/hooks/media.d.ts +17 -0
- package/dist/ui-dom/hooks/popup.d.ts +37 -0
- package/dist/ui-dom/hooks/stable.d.ts +39 -0
- package/dist/ui-dom/hooks/test/hooks.test.d.ts +1 -0
- package/dist/ui-dom/hooks/types.d.ts +78 -0
- package/dist/ui-dom/index.d.ts +19 -17
- package/dist/ui-dom/index.js +12 -10
- package/dist/ui-dom/jsx-runtime.js +1 -1
- package/dist/ui-dom/middleware/api.d.ts +3 -3
- package/dist/ui-dom/middleware/auth.d.ts +1 -1
- package/dist/ui-dom/motion.d.ts +1 -1
- package/dist/ui-dom/popup.d.ts +1 -1
- package/dist/ui-dom/scroll-lock.d.ts +1 -1
- package/dist/ui-dom/store.d.ts +24 -0
- package/dist/ui-dom/testing.d.ts +74 -0
- package/dist/ui-dom/testing.js +1 -0
- package/dist/ui-dom/testing.test.d.ts +1 -0
- package/dist/ui-dom/types.d.ts +34 -17
- package/dist/ui-dom/use-chat.d.ts +19 -14
- package/dist/ui-dom/vdom/build.d.ts +34 -0
- package/dist/ui-dom/vdom/diff.d.ts +34 -0
- package/dist/ui-dom/vdom/hydration.d.ts +17 -0
- package/dist/ui-dom/vdom/index.d.ts +23 -0
- package/dist/ui-dom/vdom/mount.d.ts +49 -0
- package/dist/ui-dom/vdom/registry.d.ts +27 -0
- package/dist/ui-dom/vdom/render.d.ts +13 -0
- package/dist/ui-dom/vdom/scheduler.d.ts +13 -0
- package/dist/ui-dom/vdom/serve.d.ts +30 -0
- package/dist/ui-dom/vdom/ssr.d.ts +44 -0
- package/dist/ui-dom/vnode.d.ts +11 -44
- package/dist/user/token.d.ts +1 -1
- package/docs/compat-three-library.md +1 -1
- package/docs/components-map.md +19 -2
- package/docs/components.md +9 -4
- package/docs/custom-components.md +19 -14
- package/docs/data.md +16 -33
- package/docs/environment.md +1 -1
- package/docs/frontend-middleware.md +65 -79
- package/docs/frontend-ui-dom.md +4 -2
- package/docs/frontend.md +35 -38
- package/docs/layout.md +2 -2
- package/docs/realtime.md +23 -28
- package/docs/saas.md +8 -6
- package/package.json +5 -1
- package/dist/ui/ssr-page.d.ts +0 -41
- package/dist/ui/ssr.d.ts +0 -35
- package/dist/ui-dom/diff.d.ts +0 -28
- package/dist/ui-dom/hydration.d.ts +0 -13
- package/dist/ui-dom/reactive.d.ts +0 -6
- package/dist/ui-dom/registry.d.ts +0 -39
- package/dist/ui-dom/render.d.ts +0 -46
- package/dist/ui-dom/route-match.d.ts +0 -22
- package/dist/ui-dom/serve.d.ts +0 -28
- package/dist/ui-dom/ssr.d.ts +0 -56
- package/dist/ui-dom/ui.d.ts +0 -78
package/dist/ui/index.d.ts
CHANGED
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
import type { Middleware } from '../types.ts';
|
|
29
|
-
import type { Component
|
|
29
|
+
import type { Component } from '../ui-dom/vnode.ts';
|
|
30
30
|
declare module '../types.ts' {
|
|
31
31
|
interface Context {
|
|
32
32
|
ui: {
|
|
33
33
|
/** Tagged template → HTML Response */
|
|
34
34
|
html: UiHtmlTag;
|
|
35
|
-
/** 编译 TSX → JS bundle Response(支持包名 weifuwu/
|
|
35
|
+
/** 编译 TSX → JS bundle Response(支持包名 weifuwu/ui-dom 或文件路径) */
|
|
36
36
|
js: (entryPath: string) => Promise<Response>;
|
|
37
37
|
/** 读取 CSS → CSS Response(支持包名 weifuwu/layout、weifuwu/components/style.css 或文件路径) */
|
|
38
38
|
css: (entryPath: string) => Promise<Response>;
|
|
@@ -41,7 +41,7 @@ declare module '../types.ts' {
|
|
|
41
41
|
* 支持 async 工厂组件:await 工厂 → 数据进 HTML。
|
|
42
42
|
* opts.data(Map)收集 ctx.data 预取结果,用 ctx.ui.ssrData(data) 序列化进 __DATA__。
|
|
43
43
|
*/
|
|
44
|
-
ssr: (Comp: Component
|
|
44
|
+
ssr: (Comp: Component, props?: Record<string, any>, opts?: {
|
|
45
45
|
data?: Map<string, unknown>;
|
|
46
46
|
}) => Promise<string>;
|
|
47
47
|
/** 序列化 SSR 数据存储 → <script>window.__DATA__=...</script>(HtmlSafe) */
|
package/dist/ui-dom/Confirm.d.ts
CHANGED
|
@@ -1,44 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* weifuwu/
|
|
2
|
+
* weifuwu/ui-dom — Confirm(命令式中间件)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* v1 退役(design/render-only-plan.md):实现已收敛到 components/Confirm(vdom 引擎,
|
|
5
|
+
* mountCommand + render-only)。本文件保留为公开 API 兼容入口。
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export interface ConfirmProps {
|
|
10
|
-
open?: boolean;
|
|
11
|
-
title?: string;
|
|
12
|
-
/** 提示内容(文本或任意 VNode) */
|
|
13
|
-
message?: any;
|
|
14
|
-
confirmText?: string;
|
|
15
|
-
cancelText?: string;
|
|
16
|
-
variant?: 'primary' | 'danger';
|
|
17
|
-
/** 对话框宽度,如 '500px'、'80%',默认 Modal 的 400px */
|
|
18
|
-
width?: string;
|
|
19
|
-
/** 遮罩点击是否取消(默认 false:危险操作防误触;显式传 true 可恢复) */
|
|
20
|
-
maskClosable?: boolean;
|
|
21
|
-
onConfirm?: () => void;
|
|
22
|
-
onCancel?: () => void;
|
|
23
|
-
}
|
|
24
|
-
/** 命令式 ctx.confirm 的选项(ConfirmProps 的子集) */
|
|
25
|
-
export interface ConfirmOptions {
|
|
26
|
-
title?: string;
|
|
27
|
-
confirmText?: string;
|
|
28
|
-
cancelText?: string;
|
|
29
|
-
variant?: 'primary' | 'danger';
|
|
30
|
-
width?: string;
|
|
31
|
-
maskClosable?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/** 命令式 ctx.confirm 的注入类型(AppMiddleware<{}, ConfirmInjected>) */
|
|
34
|
-
export interface ConfirmInjected {
|
|
35
|
-
confirm: (message: string, options?: ConfirmOptions) => Promise<boolean>;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 命令式中间件:注入 ctx.confirm()
|
|
39
|
-
*
|
|
40
|
-
* 每次调用挂载 Confirm 组件到独立容器(mountVNode),
|
|
41
|
-
* resolve 后 callRefCleanup 清理(含 Modal 的 portal DOM)+ 移除容器。
|
|
42
|
-
*/
|
|
43
|
-
export declare function confirm(): AppMiddleware<{}, ConfirmInjected>;
|
|
44
|
-
export declare const Confirm: Component<ConfirmProps>;
|
|
7
|
+
export { Confirm, confirm } from '../components/Confirm/Confirm.ts';
|
|
8
|
+
export type { ConfirmProps, ConfirmOptions, ConfirmInjected } from '../components/Confirm/Confirm.ts';
|
|
@@ -1,70 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
description?: string;
|
|
10
|
-
/** 自动关闭时间(ms),0 = 不自动关闭,默认 4500 */
|
|
11
|
-
duration?: number;
|
|
12
|
-
action?: {
|
|
13
|
-
label: string;
|
|
14
|
-
onClick: () => void;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export interface NotificationProps {
|
|
18
|
-
items?: NotificationItem[];
|
|
19
|
-
onRemove?: (id: string) => void;
|
|
20
|
-
position?: NotificationPosition;
|
|
21
|
-
/** 全局默认自动关闭时间(ms),默认 4500 */
|
|
22
|
-
duration?: number;
|
|
23
|
-
/** 最大显示条数,超出移除最早,默认 0 = 不限制 */
|
|
24
|
-
max?: number;
|
|
25
|
-
}
|
|
26
|
-
export interface NotificationOptions {
|
|
27
|
-
position?: NotificationPosition;
|
|
28
|
-
duration?: number;
|
|
29
|
-
max?: number;
|
|
30
|
-
}
|
|
31
|
-
/** 通知(对应 antd/EP Notification 队列式):title + description + icon + 操作,聚合角落 */
|
|
32
|
-
export declare const Notification: Component<NotificationProps>;
|
|
33
|
-
export interface NotificationInjected {
|
|
34
|
-
notification: {
|
|
35
|
-
(title: string, opts?: {
|
|
36
|
-
type?: NotificationType;
|
|
37
|
-
description?: string;
|
|
38
|
-
duration?: number;
|
|
39
|
-
action?: NotificationItem['action'];
|
|
40
|
-
}): void;
|
|
41
|
-
open: (opts: {
|
|
42
|
-
type?: NotificationType;
|
|
43
|
-
title: string;
|
|
44
|
-
description?: string;
|
|
45
|
-
duration?: number;
|
|
46
|
-
action?: NotificationItem['action'];
|
|
47
|
-
}) => void;
|
|
48
|
-
success: (opts: {
|
|
49
|
-
title: string;
|
|
50
|
-
description?: string;
|
|
51
|
-
duration?: number;
|
|
52
|
-
}) => void;
|
|
53
|
-
error: (opts: {
|
|
54
|
-
title: string;
|
|
55
|
-
description?: string;
|
|
56
|
-
duration?: number;
|
|
57
|
-
}) => void;
|
|
58
|
-
info: (opts: {
|
|
59
|
-
title: string;
|
|
60
|
-
description?: string;
|
|
61
|
-
duration?: number;
|
|
62
|
-
}) => void;
|
|
63
|
-
warning: (opts: {
|
|
64
|
-
title: string;
|
|
65
|
-
description?: string;
|
|
66
|
-
duration?: number;
|
|
67
|
-
}) => void;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
export declare function notification(opts?: NotificationOptions): AppMiddleware<{}, NotificationInjected>;
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/ui-dom — Notification(命令式中间件)
|
|
3
|
+
*
|
|
4
|
+
* v1 退役(design/render-only-plan.md):实现已收敛到 components/Notification(vdom 引擎,
|
|
5
|
+
* mountCommand + render-only)。本文件保留为公开 API 兼容入口。
|
|
6
|
+
*/
|
|
7
|
+
export { Notification, notification } from '../components/Notification/Notification.ts';
|
|
8
|
+
export type { NotificationType, NotificationPosition, NotificationItem, NotificationProps, NotificationOptions, NotificationInjected, } from '../components/Notification/Notification.ts';
|
package/dist/ui-dom/Toast.d.ts
CHANGED
|
@@ -1,43 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/** 此条目的自动消失时间(ms),覆盖 Toast 的默认 duration */
|
|
10
|
-
duration?: number;
|
|
11
|
-
/** 操作按钮(如"撤销"):点击不自动关闭,由回调自行移除 */
|
|
12
|
-
action?: {
|
|
13
|
-
label: string;
|
|
14
|
-
onClick: () => void;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export interface ToastProps {
|
|
18
|
-
toasts?: ToastItem[];
|
|
19
|
-
onRemove?: (id: string) => void;
|
|
20
|
-
/** 容器位置,默认 top-right */
|
|
21
|
-
position?: ToastPosition;
|
|
22
|
-
/** 全局默认自动消失时间(ms),0 = 不自动消失,默认 0 */
|
|
23
|
-
duration?: number;
|
|
24
|
-
/** 最大显示条数,超出时移除最早条目,默认 0 = 不限制 */
|
|
25
|
-
max?: number;
|
|
26
|
-
}
|
|
27
|
-
/** 命令式 ctx.toast 的全局配置 */
|
|
28
|
-
export interface ToastOptions {
|
|
29
|
-
position?: ToastPosition;
|
|
30
|
-
/** 默认自动消失时间(ms),0 = 不消失,默认 3000 */
|
|
31
|
-
duration?: number;
|
|
32
|
-
/** 最大显示条数,超出移除最早,默认 3 */
|
|
33
|
-
max?: number;
|
|
34
|
-
}
|
|
35
|
-
export declare const Toast: Component<ToastProps>;
|
|
36
|
-
/** 命令式 ctx.toast 的注入类型(AppMiddleware<{}, ToastInjected>) */
|
|
37
|
-
export interface ToastInjected {
|
|
38
|
-
toast: (message: string, type?: ToastType, duration?: number, action?: {
|
|
39
|
-
label: string;
|
|
40
|
-
onClick: () => void;
|
|
41
|
-
}) => void;
|
|
42
|
-
}
|
|
43
|
-
export declare function toast(opts?: ToastOptions): AppMiddleware<{}, ToastInjected>;
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/ui-dom — Toast(命令式中间件)
|
|
3
|
+
*
|
|
4
|
+
* v1 退役(design/render-only-plan.md):实现已收敛到 components/Toast(vdom 引擎,
|
|
5
|
+
* mountCommand + render-only)。本文件保留为公开 API 兼容入口。
|
|
6
|
+
*/
|
|
7
|
+
export { Toast, toast } from '../components/Toast/Toast.ts';
|
|
8
|
+
export type { ToastType, ToastPosition, ToastItem, ToastProps, ToastOptions, ToastInjected, } from '../components/Toast/Toast.ts';
|
package/dist/ui-dom/ai.d.ts
CHANGED
package/dist/ui-dom/browser.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/chat — AI 对话会话(useChat)
|
|
3
|
+
*
|
|
4
|
+
* 会话语义 + 工具调用内嵌 + HITL 审批。render-only 方案(design/render-only-plan.md):
|
|
5
|
+
* state 是**普通对象**(不再挂组件 $),变化 → notify → 订阅者重渲染;
|
|
6
|
+
* handle 带 subscribe——共享会话的子组件用 ctx.ui.useExternal(handle) 订阅。
|
|
7
|
+
*/
|
|
8
|
+
import type { HookEnv } from './types.ts';
|
|
9
|
+
import type { UseChatHandle, UseChatOptions } from '../use-chat.ts';
|
|
10
|
+
/** AI 对话会话(会话语义 + 工具调用内嵌 + HITL 审批) */
|
|
11
|
+
export declare function useChat(env: HookEnv, options: UseChatOptions): UseChatHandle;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/events — 事件/键盘/拖拽 hooks
|
|
3
|
+
*
|
|
4
|
+
* useGlobalKey / useDrag / useDragDrop
|
|
5
|
+
*/
|
|
6
|
+
import type { HookEnv } from './types.ts';
|
|
7
|
+
/** 全局键盘监听:window keydown,mount 注册 + 卸载清理。返回退订函数。 */
|
|
8
|
+
export declare function useGlobalKey(env: HookEnv, handler: (e: KeyboardEvent) => void): () => void;
|
|
9
|
+
/** 指针拖拽:pointerdown 捕获 → window pointermove(delta)/pointerup(释放)。 */
|
|
10
|
+
export declare function useDrag(env: HookEnv, options: {
|
|
11
|
+
onStart?: (e: PointerEvent) => void;
|
|
12
|
+
onMove: (e: PointerEvent, delta: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}) => void;
|
|
16
|
+
onEnd?: (e: PointerEvent) => void;
|
|
17
|
+
}): {
|
|
18
|
+
onPointerDown: (e: PointerEvent) => void;
|
|
19
|
+
};
|
|
20
|
+
/** 原生 DnD:drop/dragover/dragleave(dragover 自动 preventDefault)。 */
|
|
21
|
+
export declare function useDragDrop(env: HookEnv, options: {
|
|
22
|
+
onDrop?: (e: DragEvent) => void;
|
|
23
|
+
onDragOver?: (e: DragEvent) => void;
|
|
24
|
+
onDragLeave?: (e: DragEvent) => void;
|
|
25
|
+
onDragStart?: (e: DragEvent) => void;
|
|
26
|
+
onDragEnd?: (e: DragEvent) => void;
|
|
27
|
+
}): {
|
|
28
|
+
dropProps: Record<string, any>;
|
|
29
|
+
dragProps: Record<string, any>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useExternal — 订阅共享状态(render-only 共享原语,见 design/render-only-plan.md)
|
|
3
|
+
*
|
|
4
|
+
* 与 useInView/useScrollPosition 同构(mount 阶段注册,生命周期框架管):
|
|
5
|
+
* - mount 注册:订阅 store(任何变化 → 自身重渲染)
|
|
6
|
+
* - unmount 自动退订(onComponentUnmountFor——无手动退订纪律,无 §4.6 __watch 泄漏)
|
|
7
|
+
* - 返回 store 本身(活引用)——渲染函数里读最新值:
|
|
8
|
+
* createStore 产物 → store.state.xxx
|
|
9
|
+
* useChat handle → handle.messages(handle 就是活 state)
|
|
10
|
+
*
|
|
11
|
+
* 参数契约:任何「可订阅状态」——{ subscribe(cb): unsub } 即可(结构化类型)。
|
|
12
|
+
* SSR 无害:createSsrUi 的 useExternal shim 只返回 store 不订阅。
|
|
13
|
+
*/
|
|
14
|
+
import type { HookEnv } from './types.ts';
|
|
15
|
+
/** 可订阅状态(useExternal 入参——结构化类型,不要求专用 store) */
|
|
16
|
+
export interface Subscribable {
|
|
17
|
+
subscribe(cb: () => void): () => void;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
export declare function useExternal(env: HookEnv, store: Subscribable): Subscribable;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks — 汇总导出
|
|
3
|
+
*
|
|
4
|
+
* hooks 重构:所有 ctx.ui.useXXX 的实现从 createUi 拆出为独立 hooks 函数,
|
|
5
|
+
* 签名统一 `useXXX(env, ...args)`。ui.ts 组装 HookEnv + 薄转发。
|
|
6
|
+
*/
|
|
7
|
+
export type { HookEnv, MediaRegistryItem, PopupTracker, ScrollTracker } from './types.ts';
|
|
8
|
+
export { useStableRef } from './stable.ts';
|
|
9
|
+
export { useHoverCapable } from './stable.ts';
|
|
10
|
+
export { useReducedMotion } from './stable.ts';
|
|
11
|
+
export { useAnimationEnd } from './stable.ts';
|
|
12
|
+
export { useLongPress } from './stable.ts';
|
|
13
|
+
export { usePresence } from './stable.ts';
|
|
14
|
+
export { useTween } from './stable.ts';
|
|
15
|
+
export { useMedia } from './media.ts';
|
|
16
|
+
export { useBreakpoint } from './media.ts';
|
|
17
|
+
export { useVisualViewport } from './media.ts';
|
|
18
|
+
export { useInView } from './media.ts';
|
|
19
|
+
export { useScrollPosition } from './media.ts';
|
|
20
|
+
export { useControlled } from './input.ts';
|
|
21
|
+
export { useControlledInput } from './input.ts';
|
|
22
|
+
export { useAsync } from './input.ts';
|
|
23
|
+
export { useGlobalKey } from './events.ts';
|
|
24
|
+
export { useDrag } from './events.ts';
|
|
25
|
+
export { useDragDrop } from './events.ts';
|
|
26
|
+
export { usePopupPosition } from './popup.ts';
|
|
27
|
+
export { usePopup } from './popup.ts';
|
|
28
|
+
export { useOpen } from './popup.ts';
|
|
29
|
+
export { useDialog } from './popup.ts';
|
|
30
|
+
export { useChat } from './chat.ts';
|
|
31
|
+
export { useExternal } from './external.ts';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/input — 受控/输入/异步取数 hooks
|
|
3
|
+
*
|
|
4
|
+
* useControlled / useControlledInput / useAsync
|
|
5
|
+
*/
|
|
6
|
+
import type { HookEnv } from './types.ts';
|
|
7
|
+
import type { UseAsyncHandle } from '../types.ts';
|
|
8
|
+
/** 受控/非受控状态统一:value !== undefined → 受控(setValue 只走 onChange) */
|
|
9
|
+
export declare function useControlled<T>(env: HookEnv, options: {
|
|
10
|
+
value?: T;
|
|
11
|
+
onChange?: (v: T) => void;
|
|
12
|
+
name?: string;
|
|
13
|
+
}): {
|
|
14
|
+
value: T | undefined;
|
|
15
|
+
setValue: (v: T) => void;
|
|
16
|
+
controlled: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** 受控输入原语(C3):useControlled + 内部输入态/选中态(输入焦点保持) */
|
|
19
|
+
export declare function useControlledInput(env: HookEnv, options: {
|
|
20
|
+
value?: string;
|
|
21
|
+
onChange?: (v: string) => void;
|
|
22
|
+
name?: string;
|
|
23
|
+
}): {
|
|
24
|
+
keyword: string;
|
|
25
|
+
setKeyword(v: string): void;
|
|
26
|
+
selectedLabel: string;
|
|
27
|
+
setSelectedLabel(v: string): void;
|
|
28
|
+
value: string | undefined;
|
|
29
|
+
setValue: (v: string) => void;
|
|
30
|
+
controlled: boolean;
|
|
31
|
+
};
|
|
32
|
+
/** 异步取数工具(mount 阶段调用):loading/error 自动管理 + 数据就绪自动渲染 */
|
|
33
|
+
export declare function useAsync<T>(env: HookEnv, fetcher: () => Promise<T>): UseAsyncHandle<T>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/media — 响应式媒体/视口 hooks
|
|
3
|
+
*
|
|
4
|
+
* useMedia / useBreakpoint / useVisualViewport / useInView / useScrollPosition
|
|
5
|
+
*/
|
|
6
|
+
import type { HookEnv } from './types.ts';
|
|
7
|
+
import type { UseInViewOptions, UseInViewHandle, UseScrollPositionOptions, UseScrollPositionHandle, VisualViewportHandle } from '../types.ts';
|
|
8
|
+
/** 响应式媒体查询:注册监听,值变化时自动 dirty。callback 立即执行一次当前值。 */
|
|
9
|
+
export declare function useMedia(env: HookEnv, query: string, callback: (matches: boolean) => void): void;
|
|
10
|
+
/** 响应式断点:注册命名断点监听,值变化时自动 dirty */
|
|
11
|
+
export declare function useBreakpoint(env: HookEnv, bpsOrCallback: Record<string, string> | ((vp: string) => void), callback?: (vp: string) => void): void;
|
|
12
|
+
/** 可视视口跟踪(visualViewport):键盘弹起/缩放时自动更新 + dirty */
|
|
13
|
+
export declare function useVisualViewport(env: HookEnv): VisualViewportHandle;
|
|
14
|
+
/** 可见性观察(IntersectionObserver 封装):isIn 响应式——变化自动 dirty 当前组件 */
|
|
15
|
+
export declare function useInView(env: HookEnv, options: UseInViewOptions): UseInViewHandle;
|
|
16
|
+
/** 滚动位置跟踪(全局 scroll 监听 + rAF 节流):返回响应式 y,变化自动 dirty */
|
|
17
|
+
export declare function useScrollPosition(env: HookEnv, options: UseScrollPositionOptions): UseScrollPositionHandle;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/popup — 弹层 hooks
|
|
3
|
+
*
|
|
4
|
+
* usePopupPosition / usePopup / useOpen / useDialog
|
|
5
|
+
*/
|
|
6
|
+
import type { HookEnv } from './types.ts';
|
|
7
|
+
import type { PopupPositionOptions, PopupPosition, UsePopupOptions, UsePopupHandle } from '../types.ts';
|
|
8
|
+
/** 弹层位置跟踪:滚动/resize 时自动重算 fixed 坐标(0 rect 防护) */
|
|
9
|
+
export declare function usePopupPosition(env: HookEnv, options: PopupPositionOptions): PopupPosition;
|
|
10
|
+
/**
|
|
11
|
+
* 弹层组合器:收敛 open 状态 + 触发(hover/tap 降级/longpress)+ Escape +
|
|
12
|
+
* 外部点击 + 定位/视口 clamp + portal。
|
|
13
|
+
*/
|
|
14
|
+
export declare function usePopup(env: HookEnv, options: UsePopupOptions): UsePopupHandle;
|
|
15
|
+
/** 显隐打开状态机(C4):trigger/focus/blur 协调。默认只开不关 */
|
|
16
|
+
export declare function useOpen(env: HookEnv, options: {
|
|
17
|
+
open?: boolean;
|
|
18
|
+
onOpenChange?: (open: boolean) => void;
|
|
19
|
+
openOnFocus?: boolean;
|
|
20
|
+
name?: string;
|
|
21
|
+
}): {
|
|
22
|
+
readonly open: boolean;
|
|
23
|
+
setOpen: (v: boolean) => void;
|
|
24
|
+
triggerProps: {
|
|
25
|
+
onClick: () => void;
|
|
26
|
+
onFocus: () => void;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** 全屏对话框组合器:退场状态机 + 滚动锁 + 焦点 trap(基于 usePresence) */
|
|
30
|
+
export declare function useDialog(env: HookEnv, options?: {
|
|
31
|
+
name?: string;
|
|
32
|
+
}): {
|
|
33
|
+
readonly phase: "closed" | "open" | "exit";
|
|
34
|
+
rootRef: (el: HTMLElement | null) => void;
|
|
35
|
+
panelRef: (el: HTMLElement | null) => void;
|
|
36
|
+
sync: (open: boolean) => "closed" | "open" | "exit";
|
|
37
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/stable — 基础/稳定 hooks(无共享全局状态依赖)
|
|
3
|
+
*
|
|
4
|
+
* useStableRef / useHoverCapable / useReducedMotion / useAnimationEnd /
|
|
5
|
+
* useLongPress / usePresence / useTween
|
|
6
|
+
*/
|
|
7
|
+
import type { HookEnv } from './types.ts';
|
|
8
|
+
import type { UseLongPressOptions, UseLongPressHandle } from '../types.ts';
|
|
9
|
+
/** 稳定 ref 引用:mount 作用域持有,跨渲染引用恒等(内联 ref 陷阱根治) */
|
|
10
|
+
export declare function useStableRef(_env: HookEnv, init: (el: HTMLElement | null) => void, cleanup?: () => void): (el: HTMLElement | null) => void;
|
|
11
|
+
/** 当前设备是否支持 hover(matchMedia '(hover: hover)',mount 期一次判定) */
|
|
12
|
+
export declare function useHoverCapable(env: HookEnv): boolean;
|
|
13
|
+
/** 响应式系统偏好(prefers-reduced-motion)。mount 期一次判定 */
|
|
14
|
+
export declare function useReducedMotion(_env: HookEnv): boolean;
|
|
15
|
+
/** 元素动画完成回调(animationend):stableRef——ref 挂载绑定、卸载清理、引用恒定 */
|
|
16
|
+
export declare function useAnimationEnd(env: HookEnv, cb: () => void, opts?: {
|
|
17
|
+
once?: boolean;
|
|
18
|
+
}): (node: HTMLElement | null) => void;
|
|
19
|
+
/** 长按手势:pointerdown 按住 duration 触发,提前松开/位移取消,桌面右键兼容 */
|
|
20
|
+
export declare function useLongPress(env: HookEnv, options: UseLongPressOptions): UseLongPressHandle;
|
|
21
|
+
/**
|
|
22
|
+
* 通用显隐状态机:open → exit → closed(animationend 延迟卸载)。
|
|
23
|
+
* useDialog 基于它——状态机单点实现。
|
|
24
|
+
*/
|
|
25
|
+
export declare function usePresence(env: HookEnv, options?: {
|
|
26
|
+
name?: string;
|
|
27
|
+
}): {
|
|
28
|
+
readonly phase: "closed" | "open" | "exit";
|
|
29
|
+
ref: (el: HTMLElement | null) => void;
|
|
30
|
+
sync: (open: boolean) => "closed" | "open" | "exit";
|
|
31
|
+
};
|
|
32
|
+
/** 数值补间:rAF + ease + reduced-motion 直落终值。目标变化自动补间。 */
|
|
33
|
+
export declare function useTween(env: HookEnv, target: number, opts?: {
|
|
34
|
+
duration?: number;
|
|
35
|
+
ease?: 'linear' | 'easeOutCubic';
|
|
36
|
+
}): {
|
|
37
|
+
value: number;
|
|
38
|
+
reset: (to: number) => void;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/types — Hook 运行时上下文(HookEnv)
|
|
3
|
+
*
|
|
4
|
+
* hooks 重构:所有 `ctx.ui.useXXX` 的实现从 createUi 移到 src/ui-dom/hooks/,
|
|
5
|
+
* 签名统一为 `useXXX(env, ...args)`——显式接收 HookEnv(封装 ui 内部能力),
|
|
6
|
+
* 不再依赖 `this`(ui 对象)与 createUi 闭包。
|
|
7
|
+
*
|
|
8
|
+
* ui.ts 的 createUi 组装 env + 薄转发(ctx.ui.useXXX 兼容组件库,实现已在 hooks/)。
|
|
9
|
+
*/
|
|
10
|
+
import type { BrowserEnv } from '../types.ts';
|
|
11
|
+
/** 媒体查询注册表项(跨组件共享——useMedia/useBreakpoint 按 key 去重注册) */
|
|
12
|
+
export interface MediaRegistryItem {
|
|
13
|
+
mql?: MediaQueryList;
|
|
14
|
+
handler?: (e: MediaQueryListEvent) => void;
|
|
15
|
+
mqls?: Array<{
|
|
16
|
+
mql: MediaQueryList;
|
|
17
|
+
handler: () => void;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/** popup 定位 tracker(跨组件共享——全局 scroll/resize 监听重算) */
|
|
21
|
+
export interface PopupTracker {
|
|
22
|
+
pos: {
|
|
23
|
+
top: number;
|
|
24
|
+
left: number;
|
|
25
|
+
};
|
|
26
|
+
getEl: () => HTMLElement | null;
|
|
27
|
+
isOpen: () => boolean;
|
|
28
|
+
compute: (rect: DOMRect) => {
|
|
29
|
+
top: number;
|
|
30
|
+
left: number;
|
|
31
|
+
width?: number;
|
|
32
|
+
};
|
|
33
|
+
panel?: () => HTMLElement | null;
|
|
34
|
+
margin?: number;
|
|
35
|
+
}
|
|
36
|
+
/** scroll tracker(跨组件共享——useScrollPosition) */
|
|
37
|
+
export interface ScrollTracker {
|
|
38
|
+
handle: {
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
getScroller: () => HTMLElement | Window;
|
|
42
|
+
}
|
|
43
|
+
export interface HookEnv {
|
|
44
|
+
/** 当前组件 id(ui._selfId / _selfVNode._id 解析) */
|
|
45
|
+
selfId(): string | undefined;
|
|
46
|
+
/** 触发渲染(render-only 唯一触发) */
|
|
47
|
+
render(ids?: string[]): void;
|
|
48
|
+
/** 浏览器环境(ctx.browser) */
|
|
49
|
+
browser: BrowserEnv;
|
|
50
|
+
/** 组件卸载回调注册(hooks 清理用——onComponentUnmountFor)——返回退订函数 */
|
|
51
|
+
onUnmount(fn: (id: string) => void): () => void;
|
|
52
|
+
/** 注册表实例(selfId 注册/查询)——结构兼容(第 1 代/vdom 均含 idRegistry) */
|
|
53
|
+
registry: {
|
|
54
|
+
idRegistry: Map<string, any>;
|
|
55
|
+
};
|
|
56
|
+
/** 跨组件共享:媒体查询注册表 */
|
|
57
|
+
mediaRegistry: Map<string, MediaRegistryItem>;
|
|
58
|
+
/** 跨组件共享:popup 定位 tracker */
|
|
59
|
+
popupTrackers: Map<string, PopupTracker>;
|
|
60
|
+
/** 跨组件共享:scroll tracker */
|
|
61
|
+
scrollTrackers: Map<string, ScrollTracker>;
|
|
62
|
+
/** 渲染保护期(渲染请求被跳过) */
|
|
63
|
+
isMounting(): boolean;
|
|
64
|
+
isRendering(): boolean;
|
|
65
|
+
/** 受控缺回调 warn 去重(跨组件按 name 幂等) */
|
|
66
|
+
warned: Set<string>;
|
|
67
|
+
/** useControlled 非受控内部值(按 selfId) */
|
|
68
|
+
uncontrolledValues: Map<string, any>;
|
|
69
|
+
/** useControlledInput 内部输入态(按 selfId) */
|
|
70
|
+
inputStates: Map<string, {
|
|
71
|
+
keyword: string;
|
|
72
|
+
selectedLabel: string;
|
|
73
|
+
}>;
|
|
74
|
+
/** useOpen 非受控内部打开态(按 selfId) */
|
|
75
|
+
openStates: Map<string, boolean>;
|
|
76
|
+
/** 惰性挂载全局 scroll/resize 监听(幂等) */
|
|
77
|
+
ensurePopupListeners(): void;
|
|
78
|
+
}
|
package/dist/ui-dom/index.d.ts
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* weifuwu/ui-dom —
|
|
2
|
+
* weifuwu/ui-dom — 前端路由 + 渲染运行时(v2 vdom 引擎,render-only)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* 渲染运行时 = vdom(第 2 代引擎,design/render-only-plan.md):
|
|
5
|
+
* - 渲染触发唯一原语 ctx.ui.render()(无 $ / dirty——无自动渲染)
|
|
6
|
+
* - 共享状态:createStore + ctx.ui.useExternal
|
|
7
|
+
* - 命令式挂载:mountCommand/unmountCommand(弹窗中间件在 components 各组件内部)
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* 定稿架构(design/ui-architecture.md):req = window.location,res = VNode,
|
|
10
|
+
* uiServe = VDOM(落地);handler = 异步组件;middleware = 两阶段 async。
|
|
11
11
|
*/
|
|
12
12
|
export { UIRouter } from './router.ts';
|
|
13
13
|
export type { UIRouterOptions, RouteMatch } from './router.ts';
|
|
14
|
-
export {
|
|
15
|
-
export type { UIServeOptions, UIServeHandle } from './serve.ts';
|
|
16
|
-
export { h, jsx, jsxs, jsxDEV, Fragment, Portal, createPortal, Placeholder, Suspense } from './vnode.ts';
|
|
14
|
+
export { h, jsx, jsxs, jsxDEV, Fragment, Portal, createPortal } from './vnode.ts';
|
|
17
15
|
export type { VNode, VNodeChild, VNodeType, Component } from './vnode.ts';
|
|
18
|
-
export { createReactiveState } from './reactive.ts';
|
|
19
16
|
export { createClientBrowser } from './browser.ts';
|
|
20
|
-
export { mountVNode } from './render.ts';
|
|
21
|
-
export { callRefCleanup } from './render.ts';
|
|
22
17
|
export { animateOut } from './motion.ts';
|
|
23
|
-
export { patchValue } from './diff.ts';
|
|
24
|
-
export { hydrateVNode } from './hydration.ts';
|
|
25
|
-
export { isAsyncComponent, asyncComponent } from './vnode.ts';
|
|
26
18
|
export { api } from './middleware/api.ts';
|
|
27
19
|
export type { ApiClient, ApiOptions, ApiRequestOptions, ApiInjected } from './middleware/api.ts';
|
|
28
20
|
export { auth } from './middleware/auth.ts';
|
|
29
21
|
export type { AuthClient, AuthInjected } from './middleware/auth.ts';
|
|
30
22
|
export { ws } from './middleware/ws.ts';
|
|
31
23
|
export type { WsClient, WsInjected } from './middleware/ws.ts';
|
|
32
|
-
export { ssrPage, serializeData, ssrToString } from './ssr.ts';
|
|
33
24
|
export type { UIRequest, UIResponse, UIHandler, UIMiddleware, UIRouteDef, WfuiContext, } from './types.ts';
|
|
25
|
+
export { uiServe } from './vdom/serve.ts';
|
|
26
|
+
export type { UIServeOptions, UIServeHandle } from './vdom/serve.ts';
|
|
27
|
+
export { patchValue } from './vdom/diff.ts';
|
|
28
|
+
export { hydrateVNode } from './vdom/hydration.ts';
|
|
29
|
+
export { ssrPage, ssrToString, serializeData } from './vdom/ssr.ts';
|
|
30
|
+
export { mountRoot, createVdomContext, mountCommand, unmountCommand, createCommandContainer } from './vdom/mount.ts';
|
|
31
|
+
export { buildVNode } from './vdom/build.ts';
|
|
32
|
+
export { renderValue } from './vdom/render.ts';
|
|
33
|
+
export { createScheduler, type Scheduler } from './vdom/scheduler.ts';
|
|
34
|
+
export { createStore } from './store.ts';
|
|
35
|
+
export type { ExternalStore } from './store.ts';
|