weifuwu 0.75.0 → 0.77.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.
Files changed (75) hide show
  1. package/README.md +48 -53
  2. package/dist/ai/types.d.ts +2 -0
  3. package/dist/components/AiChat/AiChat.d.ts +5 -1
  4. package/dist/components/ApprovalCard/ApprovalCard.d.ts +5 -2
  5. package/dist/components/CitationCard/CitationCard.d.ts +38 -0
  6. package/dist/components/Command/Command.d.ts +1 -1
  7. package/dist/components/DatePicker/DatePicker.d.ts +1 -1
  8. package/dist/components/JsonSchemaForm/JsonSchemaForm.d.ts +48 -0
  9. package/dist/components/ReasoningBlock/ReasoningBlock.d.ts +25 -0
  10. package/dist/components/Select/Select.d.ts +11 -1
  11. package/dist/components/SessionList/SessionList.d.ts +42 -0
  12. package/dist/components/Tour/Tour.d.ts +1 -1
  13. package/dist/components/TreeSelect/TreeSelect.d.ts +3 -2
  14. package/dist/components/index.d.ts +10 -2
  15. package/dist/components/index.js +14 -14
  16. package/dist/components/style.css +625 -20
  17. package/dist/index.js +1349 -1529
  18. package/dist/layout/weifuwu-layout.css +9 -0
  19. package/dist/scheduler/index.d.ts +7 -2
  20. package/dist/test/client/setup.d.ts +12 -0
  21. package/dist/ui/index.d.ts +2 -2
  22. package/dist/ui-dom/Confirm.d.ts +5 -41
  23. package/dist/ui-dom/Notification.d.ts +8 -70
  24. package/dist/ui-dom/Toast.d.ts +8 -43
  25. package/dist/ui-dom/hooks/chat.d.ts +11 -0
  26. package/dist/ui-dom/hooks/events.d.ts +30 -0
  27. package/dist/ui-dom/hooks/external.d.ts +20 -0
  28. package/dist/ui-dom/hooks/index.d.ts +30 -0
  29. package/dist/ui-dom/hooks/input.d.ts +33 -0
  30. package/dist/ui-dom/hooks/media.d.ts +17 -0
  31. package/dist/ui-dom/hooks/popup.d.ts +28 -0
  32. package/dist/ui-dom/hooks/stable.d.ts +39 -0
  33. package/dist/ui-dom/hooks/test/hooks.test.d.ts +1 -0
  34. package/dist/ui-dom/hooks/types.d.ts +77 -0
  35. package/dist/ui-dom/index.d.ts +19 -17
  36. package/dist/ui-dom/index.js +11 -11
  37. package/dist/ui-dom/jsx-runtime.js +1 -1
  38. package/dist/ui-dom/store.d.ts +24 -0
  39. package/dist/ui-dom/testing.d.ts +74 -0
  40. package/dist/ui-dom/testing.js +1 -0
  41. package/dist/ui-dom/testing.test.d.ts +1 -0
  42. package/dist/ui-dom/types.d.ts +55 -50
  43. package/dist/ui-dom/use-chat.d.ts +19 -14
  44. package/dist/ui-dom/vdom/build.d.ts +41 -0
  45. package/dist/ui-dom/vdom/diff.d.ts +33 -0
  46. package/dist/ui-dom/vdom/hydration.d.ts +17 -0
  47. package/dist/ui-dom/vdom/index.d.ts +23 -0
  48. package/dist/ui-dom/vdom/mount.d.ts +58 -0
  49. package/dist/ui-dom/vdom/registry.d.ts +27 -0
  50. package/dist/ui-dom/vdom/render.d.ts +15 -0
  51. package/dist/ui-dom/vdom/serve.d.ts +30 -0
  52. package/dist/ui-dom/vdom/ssr.d.ts +44 -0
  53. package/dist/ui-dom/vnode.d.ts +19 -31
  54. package/docs/components-map.md +18 -1
  55. package/docs/components.md +12 -7
  56. package/docs/custom-components.md +90 -60
  57. package/docs/examples.md +35 -41
  58. package/docs/frontend-middleware.md +3 -4
  59. package/docs/frontend-ui-dom.md +21 -18
  60. package/docs/frontend.md +243 -168
  61. package/docs/layout.md +2 -2
  62. package/docs/mobile.md +2 -2
  63. package/docs/realtime.md +8 -3
  64. package/package.json +5 -1
  65. package/dist/ui/ssr.d.ts +0 -35
  66. package/dist/ui-dom/diff.d.ts +0 -28
  67. package/dist/ui-dom/focus-trap.d.ts +0 -4
  68. package/dist/ui-dom/hydration.d.ts +0 -13
  69. package/dist/ui-dom/reactive.d.ts +0 -6
  70. package/dist/ui-dom/registry.d.ts +0 -27
  71. package/dist/ui-dom/render.d.ts +0 -46
  72. package/dist/ui-dom/scroll-lock.d.ts +0 -5
  73. package/dist/ui-dom/serve.d.ts +0 -28
  74. package/dist/ui-dom/ssr.d.ts +0 -57
  75. package/dist/ui-dom/ui.d.ts +0 -78
@@ -23,16 +23,15 @@
23
23
  ### 两阶段组件模型:从 hooks 心智负担中解脱
24
24
 
25
25
  ```tsx
26
- const Counter = (initProps, ctx) => {
27
- const $ = ctx.ui.$()
28
- $.count = initProps.initial ?? 0 // mount:只执行一次
29
- return (props) =>
30
- h('button', { onClick: () => $.count += props.step }, $.count) // render
26
+ const Counter = async (initProps, ctx) => {
27
+ let count = initProps.initial ?? 0 // mount:只执行一次
28
+ return async (props) =>
29
+ h('button', { onClick: () => { count += props.step; ctx.ui.render() } }, count) // render
31
30
  }
32
31
  ```
33
32
 
34
- - **没有 hooks 规则、没有依赖数组、没有闭包陷阱**。外层 = 初始化(一次),内层 = 渲染(每次变化)。`$` Proxy 赋值自动触发组件级重渲染——**状态更新就是赋值**,不需要思考 `useState`/`useEffect`/`useMemo` 三件套的触发时机。
35
- - **状态驱动渲染**:`$.x = val` → dirty → 局部 patch。组件库手动优先(行为可预测、测试简单),业务层自动优先(省样板、不易遗漏)——按场景选模式而非被迫统一。
33
+ - **没有 hooks 规则、没有依赖数组、没有闭包陷阱**。外层 = 初始化(一次),内层 = 渲染(每次变化)。
34
+ - **render-only 确定性渲染**(design/render-only-plan.md):渲染只发生在 `ctx.ui.render()` 调用处——改状态后显式 `render()`,行为可静态推导。无 `$` Proxy、无隐式触发;跨组件共享用 `createStore` + `ctx.ui.useExternal()`。
36
35
 
37
36
  ### 框架即纪律:浏览器环境抽象把常见坑变成编译期/审计期错误
38
37
 
@@ -55,7 +54,7 @@ AGENTS.md 每条纪律对应真实事故(JSONViewer selfId 错位、AutoComple
55
54
 
56
55
  | 维度 | 价值 |
57
56
  |------|------|
58
- | **上手** | 两阶段组件 + 赋值即渲染——无 hooks/依赖数组心智负担 |
57
+ | **上手** | 两阶段组件 + 改状态后 render()——无 hooks/依赖数组心智负担 |
59
58
  | **后端互迁** | req/res/中间件契约同构,SSR 透明,一份 router 两端共享 |
60
59
  | **可靠性** | 确定性失败、诚实裁剪、环境边界、测试侧同构 |
61
60
  | **效率** | 弹层/数据管道/事件原语全覆盖——不重复造轮子 |
@@ -74,14 +73,13 @@ const app = new UIRouter()
74
73
 
75
74
  app.use(toast()) // ctx 注入链(对齐后端 app.use——注入 ctx.toast)
76
75
 
77
- // handler = 异步组件:async (location, ctx) => VNode($ 有效)
76
+ // handler = 异步组件:async (location, ctx) => VNode(render-only——改状态后 ctx.ui.render())
78
77
  app.get('/', async (location, ctx) => {
79
78
  const info = await ctx.data.get('/api/info', async () => ({ title: '首页' }))
80
- const $ = ctx.ui.$()
81
- $.clicks = $.clicks ?? 0
79
+ let clicks = 0
82
80
  return h('div', {},
83
81
  h('h2', {}, info.title),
84
- h(Button, { onClick: () => $.clicks++ }, `点击 ${$.clicks} 次`),
82
+ h(Button, { onClick: () => { clicks++; ctx.ui.render() } }, `点击 ${clicks} 次`),
85
83
  h(Button, { variant: 'secondary', onClick: () => ctx.toast?.('提示', 'success') }, '弹 toast'),
86
84
  )
87
85
  })
@@ -119,17 +117,22 @@ handler 只产 VNode,落地由 serve 决定——SSR 与 SPA 是两种落地
119
117
 
120
118
  VNode 契约以 ui-dom 为唯一来源(Fragment/Portal symbol 由 ui-dom 自持)——components 产的 VNode
121
119
  直接被 ui-dom 渲染器识别。渲染算法(render/diff/createUi 原语)在 ui-dom 内自主实现,
122
- **registry/popup-tracker/dirty 集合局部实例**(serve 每实例隔离)。
120
+ **registry/popup-tracker 局部实例**(serve 每实例隔离)。
123
121
 
124
122
  命令式工厂(toast/confirm/notification)位于 ui-dom(`src/ui-dom/Toast.ts` 等):
125
123
  components 消费端 import `weifuwu/ui-dom`(构建外部化,共享同一模块实例)。
126
124
 
127
- ### $ 响应式(两层)
125
+ ### render-only 渲染(唯一触发:ctx.ui.render())
128
126
 
129
- | 层级 | 触发 | 重渲染范围 |
127
+ | 原语 | 触发 | 重渲染范围 |
130
128
  |------|------|-----------|
131
- | 路由实例级 `$`(handler 的 `ctx.ui.$()`) | 赋值 | 重渲染 handler(data 缓存命中) |
132
- | 组件级 `$`(子组件 `ctx.ui.$()`) | 赋值 | **仅该组件**(父 handler 不重跑) |
129
+ | `ctx.ui.render()`(无参) | 主动调用 | 当前组件(闭包绑定,无 this 陷阱) |
130
+ | `ctx.ui.render(['id'])` | 主动调用 | 指定组件(selfId 注册的语义 ID) |
131
+ | `ctx.ui.useExternal(store)` | store 变更自动 | **仅订阅组件**(unmount 自动退订) |
132
+
133
+ - 状态是普通对象(`let` / `createStore`)——改状态后显式 `render()`,无赋值自动渲染
134
+ - 跨组件共享:`createStore` + `useExternal`(替代已删除的 `$` Proxy / `dirty`)
135
+ - hooks(useMedia/useInView/usePopup 等)事件驱动重渲染——与"赋值自动"本质不同
133
136
 
134
137
  ## SSR + hydration(端到端)
135
138
 
@@ -154,7 +157,7 @@ uiServe(app, { root: '#root', hydrate: true })
154
157
  |------|------|
155
158
  | `ctx.params` / `ctx.query` | 路由参数 / URL query(顶层,对齐后端) |
156
159
  | `ctx.data.get/set/has` | 数据管道(缓存 + in-flight 合并 + `__DATA__` 种子) |
157
- | `ctx.ui.*` | 19 原语(`$`/`dirty`/`render`/`usePopup`/`useChat`/`useInView`…) |
160
+ | `ctx.ui.*` | 原语(`render`/`useExternal`/`usePopup`/`useChat`/`useInView`…) |
158
161
  | `ctx.browser.*` | 环境抽象(window/document 唯一入口,SSR shim 同构) |
159
162
  | `ctx.toast` / `ctx.confirm` / `ctx.notification` | 命令式注入(`app.use(toast())` 等) |
160
163