Spaces:
Running
Running
root commited on
Commit ·
25b6182
1
Parent(s): b18394e
正文/通读工具栏统一方形图标+悬停提示;手机:侧栏全屏带返回、正文时隐藏底栏、选字批注按钮、批注底部弹层
Browse files- fanqie/dist/index.html +2 -2
- public/assets/{index-qhWvnfsQ.js → index-C3EsJA9A.js} +0 -0
- public/assets/{index-D_zwU3UE.css → index-uerEeeeu.css} +0 -0
- public/index.html +2 -2
- ui-src/src/App.tsx +1 -1
- ui-src/src/rooms/Book.tsx +1 -1
- ui-src/src/rooms/Editor.tsx +16 -12
- ui-src/src/rooms/Reader.tsx +21 -14
- ui-src/src/rooms/Review.tsx +45 -5
- ui-src/src/styles.css +60 -0
- ui-src/src/ui.tsx +12 -0
fanqie/dist/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
-
<script type="module" crossorigin src="/assets/index-
|
| 12 |
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
|
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
+
<script type="module" crossorigin src="/assets/index-C3EsJA9A.js"></script>
|
| 12 |
+
<link rel="stylesheet" crossorigin href="/assets/index-uerEeeeu.css">
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
public/assets/{index-qhWvnfsQ.js → index-C3EsJA9A.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
public/assets/{index-D_zwU3UE.css → index-uerEeeeu.css}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
public/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
-
<script type="module" crossorigin src="/assets/index-
|
| 12 |
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
|
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
+
<script type="module" crossorigin src="/assets/index-C3EsJA9A.js"></script>
|
| 12 |
+
<link rel="stylesheet" crossorigin href="/assets/index-uerEeeeu.css">
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
ui-src/src/App.tsx
CHANGED
|
@@ -101,7 +101,7 @@ function Shell({ onLock }: { onLock: () => void }) {
|
|
| 101 |
else content = <Shelf />
|
| 102 |
|
| 103 |
return (
|
| 104 |
-
<div className={cx('shell', head === 'book' && parts[2] === 'read' && 'reading')}>
|
| 105 |
<nav className="rail" aria-label="主导航">
|
| 106 |
<button className="rail-brand" onClick={() => go('shelf')} title="小说写作台"><Feather size={18} /></button>
|
| 107 |
<div className="rail-items">
|
|
|
|
| 101 |
else content = <Shelf />
|
| 102 |
|
| 103 |
return (
|
| 104 |
+
<div className={cx('shell', head === 'book' && parts[2] === 'read' && 'reading', head === 'book' && /^chapter_/.test(parts[2] || '') && 'in-chapter')}>
|
| 105 |
<nav className="rail" aria-label="主导航">
|
| 106 |
<button className="rail-brand" onClick={() => go('shelf')} title="小说写作台"><Feather size={18} /></button>
|
| 107 |
<div className="rail-items">
|
ui-src/src/rooms/Book.tsx
CHANGED
|
@@ -83,7 +83,7 @@ export default function Book({ projectId, sub, arg = '' }: { projectId: string;
|
|
| 83 |
{showBinder && <Binder ctx={ctx} sub={sub} onAddChapter={addChapter} onCollapse={() => setBinderOpen(false)} />}
|
| 84 |
{showBinder && <div className="panel-scrim binder-scrim" onClick={() => setBinderOpen(false)} aria-hidden="true" />}
|
| 85 |
{!showBinder && !focus && sub !== 'read' && (
|
| 86 |
-
<button className="binder-peek" onClick={openBinder}
|
| 87 |
)}
|
| 88 |
<div className="book-main">{main}</div>
|
| 89 |
</div>
|
|
|
|
| 83 |
{showBinder && <Binder ctx={ctx} sub={sub} onAddChapter={addChapter} onCollapse={() => setBinderOpen(false)} />}
|
| 84 |
{showBinder && <div className="panel-scrim binder-scrim" onClick={() => setBinderOpen(false)} aria-hidden="true" />}
|
| 85 |
{!showBinder && !focus && sub !== 'read' && (
|
| 86 |
+
<button className="binder-peek" onClick={openBinder} data-tip="展开目录" aria-label="展开目录"><PanelLeftOpen size={16} /></button>
|
| 87 |
)}
|
| 88 |
<div className="book-main">{main}</div>
|
| 89 |
</div>
|
ui-src/src/rooms/Editor.tsx
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
import {
|
| 3 |
Save, Maximize2, Minimize2, PanelRightClose, PanelRightOpen, History, ClipboardCheck, Sparkles, FileCog,
|
| 4 |
-
Type, AlignLeft, RotateCcw, Eye, GitCompare, Copy, Send, X, Check, AlertTriangle, Undo2, Highlighter, Scale, ChevronRight,
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { locateNotes, NotesPanel, ReviewText, segmentText, useNotes } from './Review'
|
| 7 |
import { agentApi, Chapter, projectsApi, Version, VersionMeta } from '../api'
|
| 8 |
import { AskLog, AuditCard, SayToAi } from './Agent'
|
| 9 |
import { PeerPanel, locateDisputes, peerCount, usePeer } from './Peer'
|
| 10 |
import { cnNum, copyText, countWords, cx, diffParagraphs, fmtAgo, fmtDate, go, CHAPTER_STATUS, VERSION_KIND, useLocal, useDebounced, useAsync } from '../lib'
|
| 11 |
-
import { AutoText, Empty, ErrorNote, Field, ListEditor, Loading, Modal, Spinner, Tabs, useConfirm, useToast, Segmented, Tag } from '../ui'
|
| 12 |
import type { BookCtx } from './Book'
|
| 13 |
import { noteProgress, pct } from './progress'
|
| 14 |
|
|
@@ -321,15 +321,15 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 321 |
</div>
|
| 322 |
<div className="eb-right">
|
| 323 |
<span className="eb-count" title={`本章 ${words.toLocaleString()} 字(去掉空白)${session ? `,本次 ${session > 0 ? '+' : ''}${session}` : ''};看到 ${Math.round(pos * 100)}%`}><b>{words.toLocaleString()}</b> 字{session !== 0 && <em className={session > 0 ? 'up' : 'down'}>{session > 0 ? '+' : ''}{session}</em>}</span>
|
| 324 |
-
<
|
| 325 |
-
<
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
<
|
| 332 |
-
{
|
| 333 |
</div>
|
| 334 |
</div>
|
| 335 |
</div>
|
|
@@ -373,6 +373,10 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 373 |
{showInspector && <div className="panel-scrim insp-scrim" onClick={() => setInspectorRaw(false)} aria-hidden="true" />}
|
| 374 |
{showInspector && (
|
| 375 |
<aside className="inspector">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
<Tabs<Tab> value={tab} onChange={setTab} className="inspector-tabs" items={[
|
| 377 |
{ id: 'chapter', label: <><FileCog size={14} />本章</> },
|
| 378 |
{ id: 'notes', label: <><Highlighter size={14} />批注</>, count: openNotes || undefined },
|
|
@@ -432,7 +436,7 @@ function LayoutMenu({ fontSize, setFontSize, pageWidth, setPageWidth, onIndent }
|
|
| 432 |
}, [open])
|
| 433 |
return (
|
| 434 |
<div className="menu-wrap" ref={ref}>
|
| 435 |
-
<
|
| 436 |
{open && (
|
| 437 |
<div className="popover layout-pop">
|
| 438 |
<div className="pop-title">字号</div>
|
|
|
|
| 1 |
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
import {
|
| 3 |
Save, Maximize2, Minimize2, PanelRightClose, PanelRightOpen, History, ClipboardCheck, Sparkles, FileCog,
|
| 4 |
+
Type, AlignLeft, RotateCcw, Eye, GitCompare, Copy, Send, X, Check, AlertTriangle, Undo2, Highlighter, Scale, ChevronRight, ChevronLeft,
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { locateNotes, NotesPanel, ReviewText, segmentText, useNotes } from './Review'
|
| 7 |
import { agentApi, Chapter, projectsApi, Version, VersionMeta } from '../api'
|
| 8 |
import { AskLog, AuditCard, SayToAi } from './Agent'
|
| 9 |
import { PeerPanel, locateDisputes, peerCount, usePeer } from './Peer'
|
| 10 |
import { cnNum, copyText, countWords, cx, diffParagraphs, fmtAgo, fmtDate, go, CHAPTER_STATUS, VERSION_KIND, useLocal, useDebounced, useAsync } from '../lib'
|
| 11 |
+
import { AutoText, Empty, ErrorNote, Field, ListEditor, Loading, Modal, Spinner, Tabs, useConfirm, useToast, Segmented, Tag, TbBtn } from '../ui'
|
| 12 |
import type { BookCtx } from './Book'
|
| 13 |
import { noteProgress, pct } from './progress'
|
| 14 |
|
|
|
|
| 321 |
</div>
|
| 322 |
<div className="eb-right">
|
| 323 |
<span className="eb-count" title={`本章 ${words.toLocaleString()} 字(去掉空白)${session ? `,本次 ${session > 0 ? '+' : ''}${session}` : ''};看到 ${Math.round(pos * 100)}%`}><b>{words.toLocaleString()}</b> 字{session !== 0 && <em className={session > 0 ? 'up' : 'down'}>{session > 0 ? '+' : ''}{session}</em>}</span>
|
| 324 |
+
<div className="tb-group">
|
| 325 |
+
<TbBtn tip={reviewMode ? `退出批阅${openNotes ? `(${openNotes} 条待改)` : ''}` : `批阅:选中句子写批注${openNotes ? `(${openNotes} 条待改)` : ''}`} on={reviewMode} badge={openNotes} onClick={() => setReviewMode(!reviewMode)}><Highlighter size={16} /></TbBtn>
|
| 326 |
+
<LayoutMenu fontSize={fontSize} setFontSize={setFontSize} pageWidth={pageWidth} setPageWidth={setPageWidth} onIndent={indentAll} />
|
| 327 |
+
<TbBtn tip={focus ? '退出专注(Esc)' : '专注写作(Ctrl+Shift+F)'} on={focus} onClick={() => setFocus(!focus)}>{focus ? <Minimize2 size={16} /> : <Maximize2 size={16} />}</TbBtn>
|
| 328 |
+
<div className="save-wrap">
|
| 329 |
+
<TbBtn tip={dirty ? '存为版本(Ctrl+S)· 有未存的改动' : '存为版本(Ctrl+S)'} primary dot={dirty} disabled={saving} onClick={() => setSaveOpen(o => !o)}>{saving ? <Spinner size={14} /> : <Save size={16} />}</TbBtn>
|
| 330 |
+
{saveOpen && <SavePopover onClose={() => setSaveOpen(false)} onSave={saveVersion} saving={saving} />}
|
| 331 |
+
</div>
|
| 332 |
+
{!focus && <><i className="tb-sep" /><span className="tb-end"><TbBtn tip={inspector ? '收起侧栏' : '展开侧栏(本章、批注、分歧、检查、版本)'} on={inspector} onClick={() => setInspector(!inspector)}>{inspector ? <PanelRightClose size={16} /> : <PanelRightOpen size={16} />}</TbBtn></span></>}
|
| 333 |
</div>
|
| 334 |
</div>
|
| 335 |
</div>
|
|
|
|
| 373 |
{showInspector && <div className="panel-scrim insp-scrim" onClick={() => setInspectorRaw(false)} aria-hidden="true" />}
|
| 374 |
{showInspector && (
|
| 375 |
<aside className="inspector">
|
| 376 |
+
<div className="insp-head">
|
| 377 |
+
<button className="insp-back" onClick={() => setInspectorRaw(false)}><ChevronLeft size={18} />返回正文</button>
|
| 378 |
+
<span className="insp-where">第{cnNum(detail.number)}章 {detail.title}</span>
|
| 379 |
+
</div>
|
| 380 |
<Tabs<Tab> value={tab} onChange={setTab} className="inspector-tabs" items={[
|
| 381 |
{ id: 'chapter', label: <><FileCog size={14} />本章</> },
|
| 382 |
{ id: 'notes', label: <><Highlighter size={14} />批注</>, count: openNotes || undefined },
|
|
|
|
| 436 |
}, [open])
|
| 437 |
return (
|
| 438 |
<div className="menu-wrap" ref={ref}>
|
| 439 |
+
<TbBtn tip="版面:字号、稿纸宽度、段首缩进" on={open} onClick={() => setOpen(o => !o)}><Type size={16} /></TbBtn>
|
| 440 |
{open && (
|
| 441 |
<div className="popover layout-pop">
|
| 442 |
<div className="pop-title">字号</div>
|
ui-src/src/rooms/Reader.tsx
CHANGED
|
@@ -2,8 +2,8 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
| 2 |
import { ChevronLeft, ChevronRight, ArrowLeft, PenLine, Minus, Plus, List, X, Highlighter, Type, Scale } from 'lucide-react'
|
| 3 |
import { Chapter, Note, PeerItem, projectsApi } from '../api'
|
| 4 |
import { cnNum, countWords, cx, go, useAsync, useLocal } from '../lib'
|
| 5 |
-
import { Empty, ErrorNote, Spinner, useToast } from '../ui'
|
| 6 |
-
import { locateNotes, NoteForm, NOTE_TYPE, SEVERITY, plainCopy, segmentText, useNotes, type Dispute, type Located } from './Review'
|
| 7 |
import { locateDisputes, usePeer } from './Peer'
|
| 8 |
import type { BookCtx } from './Book'
|
| 9 |
import { noteProgress } from './progress'
|
|
@@ -213,12 +213,20 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 213 |
r.selectNodeContents(el); r.setEnd(node, off)
|
| 214 |
return Number(el.dataset.off) + r.toString().length
|
| 215 |
}
|
| 216 |
-
const
|
|
|
|
| 217 |
if (!review || text == null) return
|
| 218 |
-
const s = window.getSelection()
|
| 219 |
const page = pageRef.current
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
const a = offsetIn(r.startContainer, r.startOffset), b = offsetIn(r.endContainer, r.endOffset)
|
| 223 |
if (a == null || b == null || b <= a || !text.slice(a, b).trim()) return
|
| 224 |
const rect = r.getBoundingClientRect(), host = page.getBoundingClientRect()
|
|
@@ -268,18 +276,16 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 268 |
return (
|
| 269 |
<div className={cx('reader', th.bg && 'themed', theme === 'night' && 'dark')} style={style}>
|
| 270 |
<div className="reader-bar">
|
| 271 |
-
<
|
| 272 |
<button className="reader-where" onClick={() => { setTocOpen(o => !o); setSetOpen(false) }} title="章节目录">
|
| 273 |
<List size={14} />
|
| 274 |
<span className="rw-t">第{ch.number}章 · {ch.title}</span>
|
| 275 |
<em>{idx + 1}/{list.length}</em>
|
| 276 |
</button>
|
| 277 |
-
<div className="reader-tools">
|
| 278 |
-
<
|
| 279 |
-
|
| 280 |
-
</
|
| 281 |
-
<button className={cx('btn small ghost', setOpen && 'on')} onClick={() => { setSetOpen(o => !o); setTocOpen(false) }} title="字体、字号、背景"><Type size={14} /><span className="hide-sm">阅读设置</span></button>
|
| 282 |
-
<button className="btn small ghost" onClick={() => go(`book/${pid}/${cid}`)} title="在稿纸里编辑这一章"><PenLine size={14} /><span className="hide-sm">编辑</span></button>
|
| 283 |
</div>
|
| 284 |
<i className="reader-progress" style={{ transform: `scaleX(${progress})` }} />
|
| 285 |
</div>
|
|
@@ -335,7 +341,7 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 335 |
</div>
|
| 336 |
)}
|
| 337 |
<div className="reader-scroll" ref={scrollRef} onScroll={onScroll} onClick={() => { tocOpen && setTocOpen(false); setOpen && setSetOpen(false); pop && setPop(null) }}>
|
| 338 |
-
<article className={cx('reader-page', review && 'reviewing')} ref={pageRef} onMouseUp={onUp} onCopy={plainCopy}>
|
| 339 |
{showVol && <div className="reader-vol">{ch.volume}</div>}
|
| 340 |
<div className="reader-num">第{cnNum(ch.number)}章</div>
|
| 341 |
<h1 className="reader-title">{ch.title}</h1>
|
|
@@ -346,6 +352,7 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 346 |
: paras.length === 0 ? <Empty title="这一章还没有正文"><button className="link-btn" onClick={() => go(`book/${pid}/${cid}`)}>去稿纸里写</button></Empty>
|
| 347 |
: <div className="reader-body">{paras.map(renderPara)}</div>}
|
| 348 |
|
|
|
|
| 349 |
{sel && <NoteForm style={{ top: sel.top, left: sel.left }} quote={(text || '').slice(sel.start, sel.end)} onClose={() => { setSel(null); window.getSelection()?.removeAllRanges() }} onSave={createNote} />}
|
| 350 |
{pop && (
|
| 351 |
<div className="note-form floating reader-note-pop" style={{ top: pop.top, left: pop.left }} onMouseUp={e => e.stopPropagation()} onClick={e => e.stopPropagation()}>
|
|
|
|
| 2 |
import { ChevronLeft, ChevronRight, ArrowLeft, PenLine, Minus, Plus, List, X, Highlighter, Type, Scale } from 'lucide-react'
|
| 3 |
import { Chapter, Note, PeerItem, projectsApi } from '../api'
|
| 4 |
import { cnNum, countWords, cx, go, useAsync, useLocal } from '../lib'
|
| 5 |
+
import { Empty, ErrorNote, Spinner, TbBtn, useToast } from '../ui'
|
| 6 |
+
import { isTouch, PickPill, useTouchPick, locateNotes, NoteForm, NOTE_TYPE, SEVERITY, plainCopy, segmentText, useNotes, type Dispute, type Located } from './Review'
|
| 7 |
import { locateDisputes, usePeer } from './Peer'
|
| 8 |
import type { BookCtx } from './Book'
|
| 9 |
import { noteProgress } from './progress'
|
|
|
|
| 213 |
r.selectNodeContents(el); r.setEnd(node, off)
|
| 214 |
return Number(el.dataset.off) + r.toString().length
|
| 215 |
}
|
| 216 |
+
const [touchRange, clearTouch] = useTouchPick(review, pageRef)
|
| 217 |
+
const onUp = (given?: Range) => {
|
| 218 |
if (!review || text == null) return
|
|
|
|
| 219 |
const page = pageRef.current
|
| 220 |
+
let r: Range
|
| 221 |
+
if (given) r = given
|
| 222 |
+
else {
|
| 223 |
+
if (isTouch()) return
|
| 224 |
+
const s = window.getSelection()
|
| 225 |
+
if (!s || s.isCollapsed || !page || !page.contains(s.anchorNode) || !page.contains(s.focusNode)) return
|
| 226 |
+
r = s.getRangeAt(0)
|
| 227 |
+
}
|
| 228 |
+
if (!page) return
|
| 229 |
+
clearTouch()
|
| 230 |
const a = offsetIn(r.startContainer, r.startOffset), b = offsetIn(r.endContainer, r.endOffset)
|
| 231 |
if (a == null || b == null || b <= a || !text.slice(a, b).trim()) return
|
| 232 |
const rect = r.getBoundingClientRect(), host = page.getBoundingClientRect()
|
|
|
|
| 276 |
return (
|
| 277 |
<div className={cx('reader', th.bg && 'themed', theme === 'night' && 'dark')} style={style}>
|
| 278 |
<div className="reader-bar">
|
| 279 |
+
<TbBtn className="tip-l" tip="回到作品概览" onClick={() => go(`book/${pid}/about`)}><ArrowLeft size={16} /></TbBtn>
|
| 280 |
<button className="reader-where" onClick={() => { setTocOpen(o => !o); setSetOpen(false) }} title="章节目录">
|
| 281 |
<List size={14} />
|
| 282 |
<span className="rw-t">第{ch.number}章 · {ch.title}</span>
|
| 283 |
<em>{idx + 1}/{list.length}</em>
|
| 284 |
</button>
|
| 285 |
+
<div className="reader-tools tb-group">
|
| 286 |
+
<TbBtn tip={review ? '退出批阅' : `批阅:选中句子写批注${openNotes ? `(${openNotes} 条)` : ''}`} on={review} badge={openNotes} onClick={() => { setReview(!review); setSel(null) }}><Highlighter size={16} /></TbBtn>
|
| 287 |
+
<TbBtn tip="阅读设置:字体、字号、行距、背景" on={setOpen} onClick={() => { setSetOpen(o => !o); setTocOpen(false) }}><Type size={16} /></TbBtn>
|
| 288 |
+
<span className="tb-end"><TbBtn tip="在稿纸里编辑这一章" onClick={() => go(`book/${pid}/${cid}`)}><PenLine size={16} /></TbBtn></span>
|
|
|
|
|
|
|
| 289 |
</div>
|
| 290 |
<i className="reader-progress" style={{ transform: `scaleX(${progress})` }} />
|
| 291 |
</div>
|
|
|
|
| 341 |
</div>
|
| 342 |
)}
|
| 343 |
<div className="reader-scroll" ref={scrollRef} onScroll={onScroll} onClick={() => { tocOpen && setTocOpen(false); setOpen && setSetOpen(false); pop && setPop(null) }}>
|
| 344 |
+
<article className={cx('reader-page', review && 'reviewing')} ref={pageRef} onMouseUp={() => onUp()} onCopy={plainCopy}>
|
| 345 |
{showVol && <div className="reader-vol">{ch.volume}</div>}
|
| 346 |
<div className="reader-num">第{cnNum(ch.number)}章</div>
|
| 347 |
<h1 className="reader-title">{ch.title}</h1>
|
|
|
|
| 352 |
: paras.length === 0 ? <Empty title="这一章还没有正文"><button className="link-btn" onClick={() => go(`book/${pid}/${cid}`)}>去稿纸里写</button></Empty>
|
| 353 |
: <div className="reader-body">{paras.map(renderPara)}</div>}
|
| 354 |
|
| 355 |
+
{!sel && <PickPill range={touchRange} onPick={r => onUp(r)} />}
|
| 356 |
{sel && <NoteForm style={{ top: sel.top, left: sel.left }} quote={(text || '').slice(sel.start, sel.end)} onClose={() => { setSel(null); window.getSelection()?.removeAllRanges() }} onSave={createNote} />}
|
| 357 |
{pop && (
|
| 358 |
<div className="note-form floating reader-note-pop" style={{ top: pop.top, left: pop.left }} onMouseUp={e => e.stopPropagation()} onClick={e => e.stopPropagation()}>
|
ui-src/src/rooms/Review.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
|
|
|
| 2 |
import { Check, Copy, MessageSquarePlus, Pencil, Send, Trash2, RotateCcw, Highlighter, X } from 'lucide-react'
|
| 3 |
import { Chapter, Note, projectsApi, Review } from '../api'
|
| 4 |
import { cnNum, copyText, cx, fmtAgo } from '../lib'
|
|
@@ -57,6 +58,36 @@ export const plainCopy = (e: React.ClipboardEvent) => {
|
|
| 57 |
e.clipboardData.setData('text/plain', s)
|
| 58 |
}
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
/* ---------- 批阅模式:只读正文 + 高亮 + 选中加批注 ---------- */
|
| 61 |
export function ReviewText({ text, notes, active, onPick, onCreate, disputes, onDispute }: {
|
| 62 |
text: string; notes: Located[]; active: string; onPick: (id: string) => void
|
|
@@ -76,11 +107,19 @@ export function ReviewText({ text, notes, active, onPick, onCreate, disputes, on
|
|
| 76 |
if (el) { el.scrollIntoView({ block: 'center', behavior: 'smooth' }); el.classList.remove('flash'); void el.offsetWidth; el.classList.add('flash') }
|
| 77 |
}, [active])
|
| 78 |
|
| 79 |
-
const
|
| 80 |
-
|
| 81 |
const box = ref.current
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
const pre = document.createRange()
|
| 85 |
pre.selectNodeContents(box); pre.setEnd(r.startContainer, r.startOffset)
|
| 86 |
const start = pre.toString().length
|
|
@@ -92,7 +131,7 @@ export function ReviewText({ text, notes, active, onPick, onCreate, disputes, on
|
|
| 92 |
|
| 93 |
return (
|
| 94 |
<div className="review-wrap">
|
| 95 |
-
<div ref={ref} className="review-text" onMouseUp={onUp} onCopy={plainCopy}>
|
| 96 |
{segs.map((s, i) => s.n
|
| 97 |
? <mark key={i} data-nid={s.n.note_id} className={cx('nm', `sev-${s.n.severity}`, s.n.type === 'praise' && 'praise', s.n.note_id === active && 'on', s.n.status !== 'open' && 'done', s.d && 'dm')}
|
| 98 |
onClick={e => { e.stopPropagation(); onPick(s.n!.note_id) }} title={s.n.comment}>{s.t}</mark>
|
|
@@ -100,6 +139,7 @@ export function ReviewText({ text, notes, active, onPick, onCreate, disputes, on
|
|
| 100 |
: <React.Fragment key={i}>{s.t}</React.Fragment>)}
|
| 101 |
{!text && <span className="muted">稿纸还是空的。</span>}
|
| 102 |
</div>
|
|
|
|
| 103 |
{sel && <NoteForm style={{ top: sel.top, left: sel.left }} quote={sel.quote} onClose={() => { setSel(null); window.getSelection()?.removeAllRanges() }}
|
| 104 |
onSave={async f => { const ok = await onCreate({ ...f, quote: sel.quote, start: sel.start, end: sel.end }); if (ok) { setSel(null); window.getSelection()?.removeAllRanges() } return ok }} />}
|
| 105 |
</div>
|
|
|
|
| 1 |
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
+
import { createPortal } from 'react-dom'
|
| 3 |
import { Check, Copy, MessageSquarePlus, Pencil, Send, Trash2, RotateCcw, Highlighter, X } from 'lucide-react'
|
| 4 |
import { Chapter, Note, projectsApi, Review } from '../api'
|
| 5 |
import { cnNum, copyText, cx, fmtAgo } from '../lib'
|
|
|
|
| 58 |
e.clipboardData.setData('text/plain', s)
|
| 59 |
}
|
| 60 |
|
| 61 |
+
/* ---------- 手机上选字:系统长按选中后,底部出现「批注所选」按钮(手机没有鼠标松开事件) ---------- */
|
| 62 |
+
export const isTouch = () => typeof window !== 'undefined' && window.matchMedia?.('(pointer: coarse)').matches
|
| 63 |
+
export function useTouchPick(enabled: boolean, box: React.RefObject<HTMLElement | null>) {
|
| 64 |
+
const [range, setRange] = useState<Range | null>(null)
|
| 65 |
+
useEffect(() => {
|
| 66 |
+
if (!enabled || !isTouch()) { setRange(null); return }
|
| 67 |
+
let t: any
|
| 68 |
+
const on = () => {
|
| 69 |
+
clearTimeout(t)
|
| 70 |
+
t = setTimeout(() => {
|
| 71 |
+
const s = window.getSelection(), el = box.current
|
| 72 |
+
if (s && !s.isCollapsed && s.rangeCount && el && el.contains(s.anchorNode) && el.contains(s.focusNode) && s.toString().trim()) setRange(s.getRangeAt(0).cloneRange())
|
| 73 |
+
else setRange(null)
|
| 74 |
+
}, 220)
|
| 75 |
+
}
|
| 76 |
+
document.addEventListener('selectionchange', on)
|
| 77 |
+
return () => { document.removeEventListener('selectionchange', on); clearTimeout(t) }
|
| 78 |
+
}, [enabled])
|
| 79 |
+
return [range, () => setRange(null)] as const
|
| 80 |
+
}
|
| 81 |
+
export function PickPill({ range, onPick }: { range: Range | null; onPick: (r: Range) => void }) {
|
| 82 |
+
if (!range) return null
|
| 83 |
+
const q = range.toString().trim()
|
| 84 |
+
return createPortal(
|
| 85 |
+
<div className="pick-pill" onPointerDown={e => e.preventDefault()} onMouseDown={e => e.preventDefault()}>
|
| 86 |
+
<span>「{q.length > 14 ? q.slice(0, 14) + '…' : q}」</span>
|
| 87 |
+
<button className="btn primary small" onClick={() => onPick(range)}><Highlighter size={14} />批注所选</button>
|
| 88 |
+
</div>, document.body)
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
/* ---------- 批阅模式:只读正文 + 高亮 + 选中加批注 ---------- */
|
| 92 |
export function ReviewText({ text, notes, active, onPick, onCreate, disputes, onDispute }: {
|
| 93 |
text: string; notes: Located[]; active: string; onPick: (id: string) => void
|
|
|
|
| 107 |
if (el) { el.scrollIntoView({ block: 'center', behavior: 'smooth' }); el.classList.remove('flash'); void el.offsetWidth; el.classList.add('flash') }
|
| 108 |
}, [active])
|
| 109 |
|
| 110 |
+
const [touchRange, clearTouch] = useTouchPick(true, ref)
|
| 111 |
+
const onUp = (given?: Range) => {
|
| 112 |
const box = ref.current
|
| 113 |
+
let r: Range
|
| 114 |
+
if (given) r = given
|
| 115 |
+
else {
|
| 116 |
+
if (isTouch()) return
|
| 117 |
+
const s = window.getSelection()
|
| 118 |
+
if (!s || s.isCollapsed || !box || !box.contains(s.anchorNode) || !box.contains(s.focusNode)) return
|
| 119 |
+
r = s.getRangeAt(0)
|
| 120 |
+
}
|
| 121 |
+
if (!box) return
|
| 122 |
+
clearTouch()
|
| 123 |
const pre = document.createRange()
|
| 124 |
pre.selectNodeContents(box); pre.setEnd(r.startContainer, r.startOffset)
|
| 125 |
const start = pre.toString().length
|
|
|
|
| 131 |
|
| 132 |
return (
|
| 133 |
<div className="review-wrap">
|
| 134 |
+
<div ref={ref} className="review-text" onMouseUp={() => onUp()} onCopy={plainCopy}>
|
| 135 |
{segs.map((s, i) => s.n
|
| 136 |
? <mark key={i} data-nid={s.n.note_id} className={cx('nm', `sev-${s.n.severity}`, s.n.type === 'praise' && 'praise', s.n.note_id === active && 'on', s.n.status !== 'open' && 'done', s.d && 'dm')}
|
| 137 |
onClick={e => { e.stopPropagation(); onPick(s.n!.note_id) }} title={s.n.comment}>{s.t}</mark>
|
|
|
|
| 139 |
: <React.Fragment key={i}>{s.t}</React.Fragment>)}
|
| 140 |
{!text && <span className="muted">稿纸还是空的。</span>}
|
| 141 |
</div>
|
| 142 |
+
{!sel && <PickPill range={touchRange} onPick={r => onUp(r)} />}
|
| 143 |
{sel && <NoteForm style={{ top: sel.top, left: sel.left }} quote={sel.quote} onClose={() => { setSel(null); window.getSelection()?.removeAllRanges() }}
|
| 144 |
onSave={async f => { const ok = await onCreate({ ...f, quote: sel.quote, start: sel.start, end: sel.end }); if (ok) { setSel(null); window.getSelection()?.removeAllRanges() } return ok }} />}
|
| 145 |
</div>
|
ui-src/src/styles.css
CHANGED
|
@@ -1858,3 +1858,63 @@ details.older[open] { display: flex; flex-direction: column; gap: 8px; }
|
|
| 1858 |
.change-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
|
| 1859 |
.change-hunk { display: flex; flex-direction: column; gap: 2px; font-family: var(--serif); font-size: 14px; line-height: 1.8; }
|
| 1860 |
.change-para { font-family: var(--sans); font-size: 11.5px; color: var(--ink-3); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1858 |
.change-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
|
| 1859 |
.change-hunk { display: flex; flex-direction: column; gap: 2px; font-family: var(--serif); font-size: 14px; line-height: 1.8; }
|
| 1860 |
.change-para { font-family: var(--sans); font-size: 11.5px; color: var(--ink-3); }
|
| 1861 |
+
|
| 1862 |
+
/* ---------- 工具栏方形图标按钮(与目录展开按钮同款) ---------- */
|
| 1863 |
+
.tb-btn { position: relative; flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); box-shadow: var(--shadow-s); transition: color .15s, background-color .15s, border-color .15s, box-shadow .15s; }
|
| 1864 |
+
.tb-btn:hover:not(:disabled) { color: var(--ink); box-shadow: var(--shadow); }
|
| 1865 |
+
.tb-btn.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
|
| 1866 |
+
.tb-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
|
| 1867 |
+
.tb-btn.primary:hover:not(:disabled) { background: var(--accent-2); color: var(--accent-ink); }
|
| 1868 |
+
.tb-btn:disabled { opacity: .5; cursor: default; }
|
| 1869 |
+
.tb-badge { position: absolute; top: -6px; right: -6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; font-style: normal; font-size: 10px; font-weight: 600; line-height: 16px; text-align: center; background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 2px var(--bg); }
|
| 1870 |
+
.tb-btn.on .tb-badge { background: var(--err); color: #fff; }
|
| 1871 |
+
.tb-dot { position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 2px var(--surface); }
|
| 1872 |
+
.tb-btn.primary .tb-dot { background: #fff; box-shadow: none; }
|
| 1873 |
+
.tb-group { display: flex; align-items: center; gap: 6px; flex: none; }
|
| 1874 |
+
.tb-sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; flex: none; }
|
| 1875 |
+
@media (hover: hover) {
|
| 1876 |
+
.tb-btn[data-tip]::after { content: attr(data-tip); position: absolute; top: calc(100% + 7px); left: 50%; transform: translateX(-50%) translateY(-2px); padding: 4px 8px; border-radius: 6px; background: var(--ink); color: var(--bg); font-size: 12px; line-height: 1.4; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s, transform .12s; z-index: 50; box-shadow: var(--shadow); }
|
| 1877 |
+
.tb-btn[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); transition-delay: .25s; }
|
| 1878 |
+
.tb-end .tb-btn[data-tip]::after, .tb-btn.tip-r[data-tip]::after { left: auto; right: 0; transform: translateY(-2px); }
|
| 1879 |
+
.tb-end .tb-btn[data-tip]:hover::after, .tb-btn.tip-r[data-tip]:hover::after { transform: none; }
|
| 1880 |
+
.tb-btn.tip-l[data-tip]::after { left: 0; transform: translateY(-2px); }
|
| 1881 |
+
.tb-btn.tip-l[data-tip]:hover::after { transform: none; }
|
| 1882 |
+
.binder-peek[data-tip]::after { content: attr(data-tip); position: absolute; top: calc(100% + 7px); left: 0; padding: 4px 8px; border-radius: 6px; background: var(--ink); color: var(--bg); font-size: 12px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 50; }
|
| 1883 |
+
.binder-peek[data-tip]:hover::after { opacity: 1; transition-delay: .25s; }
|
| 1884 |
+
}
|
| 1885 |
+
|
| 1886 |
+
/* ---------- 侧栏顶部「返回正文」(平板、手机侧栏盖住正文时) ---------- */
|
| 1887 |
+
.insp-head { display: none; }
|
| 1888 |
+
@media (max-width: 1000px) {
|
| 1889 |
+
.insp-head { display: flex; align-items: center; gap: 10px; flex: none; height: 50px; padding: 0 12px 0 6px; border-bottom: 1px solid var(--line); background: var(--surface); }
|
| 1890 |
+
.insp-back { display: inline-flex; align-items: center; gap: 2px; height: 36px; padding: 0 10px 0 4px; border-radius: 8px; font-size: 14.5px; font-weight: 600; color: var(--accent); flex: none; }
|
| 1891 |
+
.insp-back:active { background: var(--accent-soft); }
|
| 1892 |
+
.insp-where { min-width: 0; font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
| 1893 |
+
}
|
| 1894 |
+
@media (max-width: 760px) {
|
| 1895 |
+
.editor.with-inspector .inspector { position: fixed; inset: 0; z-index: 90; width: 100% !important; border-left: 0; box-shadow: none; padding-bottom: env(safe-area-inset-bottom); animation: sheet-r .24s var(--ease); }
|
| 1896 |
+
.insp-head { padding-top: env(safe-area-inset-top); height: calc(50px + env(safe-area-inset-top)); }
|
| 1897 |
+
.inspector-tabs { overflow-x: auto; scrollbar-width: none; }
|
| 1898 |
+
.inspector-tabs::-webkit-scrollbar { display: none; }
|
| 1899 |
+
.inspector-tabs .tab { flex: 0 0 auto; padding-inline: 10px; font-size: 13px; }
|
| 1900 |
+
.inspector-body { padding: 14px 14px 40px; -webkit-overflow-scrolling: touch; }
|
| 1901 |
+
.insp-scrim { display: none !important; }
|
| 1902 |
+
/* 在一章里时收起底部导航,正文占满屏幕;回书房走目录里的「书房」 */
|
| 1903 |
+
.shell.in-chapter .rail { display: none; }
|
| 1904 |
+
.shell.in-chapter .stage { height: 100%; }
|
| 1905 |
+
.binder { width: min(86vw, 320px); }
|
| 1906 |
+
.binder-ch, .binder-link { min-height: 40px; }
|
| 1907 |
+
.editor-bar { height: 50px; gap: 6px; padding: 0 8px 0 50px; }
|
| 1908 |
+
.tb-group { gap: 5px; }
|
| 1909 |
+
.tb-btn { width: 34px; height: 34px; }
|
| 1910 |
+
.binder-peek { width: 34px; height: 34px; top: 8px; left: 8px; }
|
| 1911 |
+
.paper-text, .review-text { -webkit-user-select: text; user-select: text; }
|
| 1912 |
+
/* 批注表单在手机上做成底部弹层,不被键盘和屏幕边缘挤掉 */
|
| 1913 |
+
.note-form.floating { position: fixed !important; left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; max-width: none; border-radius: 16px 16px 0 0; z-index: 120; max-height: 75dvh; overflow: auto; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(0,0,0,.18); animation: sheet .24s var(--ease); }
|
| 1914 |
+
}
|
| 1915 |
+
@keyframes sheet-r { from { transform: translateX(30px); opacity: 0; } }
|
| 1916 |
+
.pick-pill { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 110; display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 24px); padding: 6px 6px 6px 14px; border-radius: 99px; background: var(--raised); border: 1px solid var(--line); box-shadow: var(--shadow-l); font-size: 13px; color: var(--ink-2); animation: sheet .2s var(--ease); }
|
| 1917 |
+
.pick-pill span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
|
| 1918 |
+
.pick-pill .btn { border-radius: 99px; flex: none; height: 34px; }
|
| 1919 |
+
.reader-tools.tb-group { gap: 6px; }
|
| 1920 |
+
.reader.themed .tb-btn:not(.on):not(.primary) { background: transparent; border-color: color-mix(in srgb, var(--rink) 20%, transparent); color: color-mix(in srgb, var(--rink) 80%, transparent); box-shadow: none; }
|
ui-src/src/ui.tsx
CHANGED
|
@@ -295,3 +295,15 @@ export function Tag({ children, tone, onClick, active, title }: { children: Reac
|
|
| 295 |
export function Stars({ n, max = 5 }: { n: number; max?: number }) {
|
| 296 |
return <span className="stars" title={`质量 ${n}/${max}`}>{Array.from({ length: max }, (_, i) => <i key={i} className={i < n ? 'on' : ''} />)}</span>
|
| 297 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
export function Stars({ n, max = 5 }: { n: number; max?: number }) {
|
| 296 |
return <span className="stars" title={`质量 ${n}/${max}`}>{Array.from({ length: max }, (_, i) => <i key={i} className={i < n ? 'on' : ''} />)}</span>
|
| 297 |
}
|
| 298 |
+
|
| 299 |
+
/* 工具栏方形图标按钮:只放图标,鼠标经过显示文字(手机上长按也有系统提示) */
|
| 300 |
+
export function TbBtn({ tip, onClick, on, primary, badge, dot, disabled, children, className }: {
|
| 301 |
+
tip: string; onClick?: (e: React.MouseEvent) => void; on?: boolean; primary?: boolean; badge?: number; dot?: boolean; disabled?: boolean; children: React.ReactNode; className?: string
|
| 302 |
+
}) {
|
| 303 |
+
return (
|
| 304 |
+
<button type="button" className={cx('tb-btn', on && 'on', primary && 'primary', className)} onClick={onClick} disabled={disabled} data-tip={tip} aria-label={tip} aria-pressed={on || undefined}>
|
| 305 |
+
{children}
|
| 306 |
+
{badge ? <em className="tb-badge">{badge > 99 ? '99+' : badge}</em> : dot ? <i className="tb-dot" /> : null}
|
| 307 |
+
</button>
|
| 308 |
+
)
|
| 309 |
+
}
|