weifuwu 0.85.0 → 0.86.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 +5 -5
- package/dist/components/Editor/Editor.d.ts +8 -7
- package/dist/components/Editor/edit-events.d.ts +27 -0
- package/dist/components/Editor/model/apply.d.ts +23 -0
- package/dist/components/Editor/model/diff.d.ts +25 -0
- package/dist/components/Editor/model/dom.d.ts +27 -0
- package/dist/components/Editor/model/history.d.ts +21 -0
- package/dist/components/Editor/model/html.d.ts +16 -0
- package/dist/components/Editor/model/inverse.d.ts +20 -0
- package/dist/components/Editor/model/types.d.ts +116 -0
- package/dist/components/Editor/tools/table.d.ts +5 -2
- package/dist/components/Editor/tools/toolbar.d.ts +1 -1
- package/dist/components/Editor/tools/types.d.ts +25 -0
- package/dist/components/FilePreview/FilePreview.d.ts +42 -0
- package/dist/components/FilePreview/markdown.d.ts +23 -0
- package/dist/components/OfficeEditor/ai/ai-bridge.d.ts +39 -0
- package/dist/components/OfficeEditor/model/apply.d.ts +25 -0
- package/dist/components/OfficeEditor/model/types.d.ts +224 -0
- package/dist/components/SheetGrid/SheetGrid.d.ts +30 -0
- package/dist/components/SlideCanvas/SlideCanvas.d.ts +28 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +54 -14
- package/dist/components/style.css +679 -4
- package/dist/index.js +38 -11
- package/dist/office/docx.d.ts +33 -0
- package/dist/office/pptx.d.ts +24 -0
- package/dist/office/xlsx.d.ts +25 -0
- package/dist/office/xml-serialize.d.ts +18 -0
- package/dist/office/xml.d.ts +21 -0
- package/dist/office/zip.d.ts +21 -0
- package/dist/ui-dom/index.js +7 -7
- package/dist/ui-dom/locale/en_US.d.ts +14 -0
- package/dist/ui-dom/locale/zh_CN.d.ts +14 -0
- package/dist/ui-dom/testing.js +5 -5
- package/dist/ui-dom/types.d.ts +3 -1
- package/dist/ui-dom/vdom3/delegate.d.ts +5 -0
- package/dist/ui-dom/vdom3.js +7 -7
- package/docs/components-map.md +12 -0
- package/docs/components.md +124 -2
- package/package.json +1 -1
- package/dist/components/Editor/tools/format.d.ts +0 -11
package/docs/components.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 本页为 weifuwu 官方文档拆分页 · [返回 README](../README.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
118 个 HTML 原语组件。每个是 `async (initProps, ctx) => (props) => Promise<VNode>`(两阶段组件,与前端框架同一模型——外层工厂 + 内层 renderFn 强制异步),引用 `--wf-*` CSS 变量做主题。另含 `confirm()` / `toast()` 命令式中间件。
|
|
6
6
|
|
|
7
7
|
> **组件速查(weifuwu 组件 ↔ antd / Element Plus / shadcn-ui 对应 + 迁移示例)**:见 [`docs/components-map.md`](components-map.md)——从其他组件库迁来的开发者按功能直接找对应组件。
|
|
8
8
|
> **自定义组件开发**:见 [docs/custom-components.md](custom-components.md)——usePopup/useControlled/对话框/AI 组件/类型纪律逐步指南。
|
|
@@ -634,7 +634,129 @@ props 变化 ──────────────────────
|
|
|
634
634
|
|-----|--------|-----------|------|
|
|
635
635
|
| Chart | `Chart` | `type: ChartType`, `data`, `options`, `title`, `area` | SVG 图表(line/bar/pie)|
|
|
636
636
|
| DatePicker | `DatePicker` | `mode: DatePickerMode`, `value`, `onChange`, `placeholder`, `disabled` | 日期选择器(date/datetime/time/range)|
|
|
637
|
-
| Editor | `Editor` | `value`, `onChange`, `toolbar`, `placeholder`, `disabled` |
|
|
637
|
+
| Editor | `Editor` | `value`, `onChange`, `toolbar`, `placeholder`, `disabled`, `ai?` | 富文本编辑器(事件流事务层:撤销/重做/时光机;AI 协作可选) |
|
|
638
|
+
| FilePreview | `FilePreview` | `type`, `content?`, `url?`, `editable?`, `ai?`, `onSave?` | 文件预览(md/html/pdf/office/text)——基于事件流,md/text 可编辑 |
|
|
639
|
+
|
|
640
|
+
### Editor(富文本编辑器 + AI 协作)
|
|
641
|
+
|
|
642
|
+
基于 contentEditable 的富文本编辑器,**事件流事务层**:语义操作(格式/链接/图片/表格/AI 替换)→ `edit:commit`(before 快照 + 事件)→ 撤销/重做/时光机精确到任意版本。
|
|
643
|
+
|
|
644
|
+
```tsx
|
|
645
|
+
import { Editor } from 'weifuwu/components'
|
|
646
|
+
|
|
647
|
+
<Editor value={html} onChange={v => setHtml(v)} placeholder="输入内容..." />
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
**Props**:
|
|
651
|
+
|
|
652
|
+
| Prop | 类型 | 说明 |
|
|
653
|
+
|------|------|------|
|
|
654
|
+
| `value` / `onChange` | `string` / `(html) => void` | 受控 HTML(内部模型为准——输出经序列化归一化) |
|
|
655
|
+
| `toolbar` | `ToolbarItem[]` | 工具栏项(bold/italic/h1-3/align/link/image/table/clear/source…);默认 18 项 |
|
|
656
|
+
| `placeholder` / `disabled` / `minHeight` | | 占位符 / 禁用 / 最小高度 |
|
|
657
|
+
| `onUpload` | `(file) => Promise<string>` | 图片上传(返回 URL);不传则 URL 输入 |
|
|
658
|
+
| `ai` | `EditorAiOptions` | **AI 协作(可选)**——见下 |
|
|
659
|
+
| `draftKey` | `string` | **草稿持久化(可选)**:内容自动保存(防抖 500ms),挂载时 `value` 为空且存在草稿 → 自动恢复(刷新/崩溃不丢) |
|
|
660
|
+
|
|
661
|
+
**撤销/重做/时光机**:
|
|
662
|
+
|
|
663
|
+
- `Ctrl+Z` / `Ctrl+Y`:一步撤销/重做**语义操作**(输入合并为单步——连续打字一次撤销全退)
|
|
664
|
+
- 工具栏 🕘 **操作历史**:commit 列表(标签 + 时间)→ 点击回到任意版本(redo 保留可重做回来)
|
|
665
|
+
|
|
666
|
+
**AI 协作**(`ai` prop——不传则无 AI 能力):
|
|
667
|
+
|
|
668
|
+
```tsx
|
|
669
|
+
<Editor
|
|
670
|
+
value={html}
|
|
671
|
+
onChange={v => setHtml(v)}
|
|
672
|
+
ai={{ url: '/api/ai-editor' }} // wf: SSE 端点(docs/ai-contract.md)
|
|
673
|
+
/>
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
- 工具栏 AI 动作组(默认:润色/翻译/缩写/扩写/纠错)——选中文本(无选区 = 全文)→ 点击 → 浮层**流式**生成建议(原文 diff 对比)→ **接受**(替换 = 一个原子撤销步)/ **拒绝**
|
|
677
|
+
- `Ctrl+Enter`:快速触发最近使用的 AI 动作
|
|
678
|
+
- 自定义动作:`ai.actions`(prompt 模板注入 `{selection}`)
|
|
679
|
+
|
|
680
|
+
```tsx
|
|
681
|
+
<Editor value={html} onChange={v => setHtml(v)}
|
|
682
|
+
ai={{
|
|
683
|
+
url: '/api/ai-editor',
|
|
684
|
+
actions: [{
|
|
685
|
+
id: 'tone', label: '改语气',
|
|
686
|
+
prompt: ({ selection }) => `请把以下文本改为正式语气:\n\n${selection}`,
|
|
687
|
+
}],
|
|
688
|
+
}} />
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
### FilePreview(文件预览——基于事件流)
|
|
692
|
+
|
|
693
|
+
md/html/pdf/office/text 文件预览——**文档 = fold(事件流)**(复用 Editor 文档模型):
|
|
694
|
+
md/text 解析为 DocState——预览/编辑/撤销/AI 同一模型;编辑后可序列化回 md 保存。
|
|
695
|
+
|
|
696
|
+
```tsx
|
|
697
|
+
import { FilePreview } from 'weifuwu/components'
|
|
698
|
+
|
|
699
|
+
// md 预览 + 编辑 + AI 协作(润色文档 = 原子撤销)
|
|
700
|
+
<FilePreview type="md" content={md} editable ai={{ url: '/api/ai' }}
|
|
701
|
+
onSave={(md) => saveToSandbox(md)} fileName="README.md" />
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
**类型支持矩阵**:
|
|
705
|
+
|
|
706
|
+
| 类型 | 预览 | 编辑 | 说明 |
|
|
707
|
+
|------|------|------|------|
|
|
708
|
+
| `md` | ✅ 复用 `<Markdown>`(安全 token 渲染:表格/任务列表/URL 白名单) | ✅ 复用 `<Editor>`(事件流事务层——撤销/时光机/AI) | 编辑保存 = 序列化回 Markdown |
|
|
709
|
+
| `text` | `<pre>` | ✅ 复用 `<Editor>` | 纯文本 |
|
|
710
|
+
| `html` | ✅ iframe `sandbox`(安全隔离——不直插 DOM) | ❌(安全边界) | 只读 |
|
|
711
|
+
| `pdf` | ✅ iframe(浏览器原生查看器) | ❌ | 只读 |
|
|
712
|
+
| `office` | ✅ iframe(服务端转换产物 URL) | ❌ | 转换由服务端提供(前端零依赖——诚实裁剪) |
|
|
713
|
+
|
|
714
|
+
**Props**:`type`(可选——按 `fileName`/`url` 扩展名自动探测:md/txt/html/pdf/
|
|
715
|
+
docx 等)、`content`(md/html/text)、`url`(远程加载/文件服务路径)、
|
|
716
|
+
`editable`(md/text 切换 Editor)、`ai`(编辑模式透传 Editor AI 协作)、
|
|
717
|
+
`onSave(content, type)`(保存回写)、`onLoad`(解析完成)、`height`。
|
|
718
|
+
|
|
719
|
+
**交互**:工具条「复制」(原始内容——`ctx.browser.copyText`)+「保存」;
|
|
720
|
+
编辑模式 `Ctrl+S` 保存。远程文件(sandbox 路径):`url` 加载 + `onSave` 回写。
|
|
721
|
+
|
|
722
|
+
### SheetGrid(xlsx 网格编辑器——ODES 事件流)
|
|
723
|
+
|
|
724
|
+
**Props**:`workbook`(受控 WorkbookState——稀疏 cells Map)、`onChange`、
|
|
725
|
+
`ai`(AI 公式——SSE wf:)、`readonly`、`height`。
|
|
726
|
+
|
|
727
|
+
**能力**:单元格编辑(点击 → input → Enter/focusout 提交)、行列增删(引用平移)、
|
|
728
|
+
撤销(Ctrl+Z——commit 快照)、sheet 标签切换、**AI 公式**(选中单元格 → 相邻数据
|
|
729
|
+
上下文提示 → 浮层确认 → 接受 = cell-set commit 原子撤销)。
|
|
730
|
+
|
|
731
|
+
**事件流**:每个编辑 = `OfficeOp` → `__edit_tail(50, 'office')` 审计;AI 接受带
|
|
732
|
+
`target=messageId`(跨端关联 `__ai_events`)。
|
|
733
|
+
|
|
734
|
+
### SlideCanvas(pptx 画布编辑器——ODES 事件流)
|
|
735
|
+
|
|
736
|
+
**Props**:`deck`(受控 DeckState——slide → shape 几何集合)、`onChange`、
|
|
737
|
+
`ai`(AI 润色)、`readonly`、`height`。
|
|
738
|
+
|
|
739
|
+
**能力**:960×540 画布(scale 适配)、shape 拖拽移动/右下角缩放(pointerup 原子
|
|
740
|
+
提交)、双击文本编辑、幻灯片增删、Delete 删除、撤销、**AI 润色**(选中 shape →
|
|
741
|
+
浮层确认 → 接受 = shape-set commit)。
|
|
742
|
+
|
|
743
|
+
### Office 前端转换(零依赖——无需后端)
|
|
744
|
+
|
|
745
|
+
`weifuwu/office`(源码 `src/office/`——打包进 components):docx/xlsx/pptx ↔
|
|
746
|
+
ODES 模型(DocState/WorkbookState/DeckState)双向转换——自研 ZIP(EOCD→central→
|
|
747
|
+
local + `DecompressionStream('deflate-raw')`)+ 轻量 XML 解析器 + VNode 组件化
|
|
748
|
+
生成 OOXML(OOXML 也是 VNode——与前端 VNode → DOM 同构)。
|
|
749
|
+
|
|
750
|
+
**用法**(FilePreview 内置):`editable` office 类型 → 打开本地 docx/xlsx/pptx →
|
|
751
|
+
对应编辑器(Editor/SheetGrid/SlideCanvas)→ 下载导出。裁剪:复杂分节/公式计算/
|
|
752
|
+
动画母版——诚实提示。
|
|
753
|
+
|
|
754
|
+
**事件流**:预览加载 `editEmit('preview')`(`__edit_tail` 可审计);编辑走 Editor
|
|
755
|
+
commit 事件流(同一时间线)。**sandbox 集成**:`url` 加载 + `onSave` 回写由消费方接
|
|
756
|
+
文件读写工具。
|
|
757
|
+
|
|
758
|
+
**裁剪**:docx/xlsx/pptx 前端解析不做(零依赖——office 由服务端转换);代码块/
|
|
759
|
+
表格编辑时降级(超 Editor 模型——见 md 转换文档)。
|
|
638
760
|
|
|
639
761
|
### 布局
|
|
640
762
|
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* weifuwu/components/Editor/tools — 格式化命令
|
|
3
|
-
*/
|
|
4
|
-
import type { FormatState, ToolbarItem } from './types.ts';
|
|
5
|
-
/** 查询当前选区格式状态 */
|
|
6
|
-
export declare function queryFormats(): FormatState;
|
|
7
|
-
/** 执行 execCommand(经 browser 环境抽象) */
|
|
8
|
-
export declare function exec(cmd: string, value?: string): void;
|
|
9
|
-
/** 根据工具项执行格式化(formatBlock 类带 toggle:当前已是该块格式 → 回默认块——
|
|
10
|
-
* 真实浏览器验收发现 Chrome 对重复 formatBlock 同值不切换,标题/引用无法反选) */
|
|
11
|
-
export declare function execFormat(item: ToolbarItem): void;
|