「记一条」面板里正文是个 textarea,排版、表格、贴图都没有——创建时反而比 详情页更寒酸。现在新建面板直接用详情同款 Vditor 编辑器,创建与修改一个模样。 - `RichTextEditor` 的 `itemId` 改为可选:新建时还没有条目 id,正文照写, 只是上传按钮不摆出来;真去贴图会提示「先保存这条内容,再回来贴图」。 - `KnowledgeComposer` 的正文换用 `RichTextEditor`(minHeight 320),页脚提示 按有没有条目 id 给不同文案。 - 安卓:新建对话框不再放纯文本正文框,保存后直接进 `RichTextEditorScreen` 写正文(排版、表格、贴图都在那儿),写完回到列表并展开详情。 - e2e 增加一条断言:新建面板里的正文就是富文本编辑器(aria-label=正文 的 contenteditable),正文按真实键盘输入后 Markdown 正常落库。 验证:`tsc --noEmit` 通过、`vite build` 通过、`knowledge-notebook.mjs` 11 项 全绿(新增「新建面板的正文是富文本编辑器」)。安卓端本机仍是 JDK 25 + Gradle 8.7/AGP 8.7.3 不兼容,本次未编译验证。
This commit is contained in:
@@ -18,7 +18,8 @@ interface Props {
|
||||
onChange: (next: string) => void;
|
||||
/** 图片要落到具体条目下,所以这两个是必填 */
|
||||
wsId: string;
|
||||
itemId: string;
|
||||
/** 新建场景还没有条目 id:正文照样能写,只是暂时不能贴图(贴图前必须先存草稿) */
|
||||
itemId?: string;
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
/** 编辑器初始高度(px) */
|
||||
@@ -112,7 +113,8 @@ export function RichTextEditor({
|
||||
"line",
|
||||
"code",
|
||||
"inline-code",
|
||||
"upload",
|
||||
// 没有条目 id 就没有上传落点,索性不摆这个按钮,免得点了才报错
|
||||
...(itemId ? ["upload"] : []),
|
||||
"table",
|
||||
"|",
|
||||
"undo",
|
||||
@@ -129,6 +131,10 @@ export function RichTextEditor({
|
||||
accept: "image/*",
|
||||
multiple: true,
|
||||
handler: async (files: File[]) => {
|
||||
if (!itemId) {
|
||||
onErrorRef.current?.("先保存这条内容,再回来贴图或传附件");
|
||||
return null;
|
||||
}
|
||||
const images = files.filter((file) => file.type.startsWith("image/"));
|
||||
if (images.length === 0) {
|
||||
onErrorRef.current?.("只能插入图片");
|
||||
@@ -211,7 +217,9 @@ export function RichTextEditor({
|
||||
<p className="mt-1 text-2xs text-ink-400">
|
||||
{uploading
|
||||
? "正在上传图片…"
|
||||
: "支持直接粘贴或拖入图片;内容按 Markdown 保存,模型和导出都读得懂"}
|
||||
: itemId
|
||||
? "支持直接粘贴或拖入图片;内容按 Markdown 保存,模型和导出都读得懂"
|
||||
: "内容按 Markdown 保存;存下来之后就能直接贴图、传附件"}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
+14
-10
@@ -707,17 +707,21 @@ function KnowledgeComposer({
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="block">
|
||||
<div>
|
||||
<span className="label">正文</span>
|
||||
<textarea
|
||||
className="input min-h-64 resize-y font-mono text-sm leading-relaxed"
|
||||
rows={14}
|
||||
placeholder={"可以直接写 Markdown:\n\n## 步骤\n1. 停灰度\n2. 回滚镜像\n3. 验证关键接口"}
|
||||
value={body}
|
||||
onChange={(e) => setBody(e.target.value)}
|
||||
aria-label="正文"
|
||||
/>
|
||||
</label>
|
||||
{/* 和详情抽屉同一个富文本编辑器:新建时就该能排版、写表格,而不是先存一个纯文本框 */}
|
||||
<div className="rounded-xl border border-line-200 bg-paper-50 px-3 py-2">
|
||||
<RichTextEditor
|
||||
ariaLabel="正文"
|
||||
wsId={wsId}
|
||||
value={body}
|
||||
onChange={setBody}
|
||||
minHeight={320}
|
||||
onError={setError}
|
||||
placeholder={"写下要点、步骤、结论…\n\n标题、类型、分类、标签都在上面,正文就是这张备忘的主体。"}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && <InlineAlert>{error}</InlineAlert>}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user