修复 React 迁移遗留:分镜检查器改文案用 ref 取代失效的 .sb-insp 选择器、受控勾选框补 onChange 消除只读告警、seed 回落空串保持受控、登录用户名补回 #login-user;同步用例计数
parent
20e8f19eca
commit
e4715cf967
|
|
@ -86,7 +86,7 @@ api/ → app/ → pages/ → components/{ui,forms,media}/ → hooks/ ·
|
|||
|
||||
## 3. 测试规范
|
||||
|
||||
- **归属**:自动化用例一律放 `backend/tests/`(当前 43 个文件、487 条)。
|
||||
- **归属**:自动化用例一律放 `backend/tests/`(当前 43 个文件、495 条)。
|
||||
新增能力必须同时带用例;修 bug 必须先写能复现的用例,再改代码。
|
||||
- **两类测试分工明确**:
|
||||
- `backend/tests/`(pytest + TestClient,进程内):契约、状态机、边界值,
|
||||
|
|
@ -215,7 +215,7 @@ sudo ./scripts/server.sh systemd > /etc/systemd/system/nex-animation.service #
|
|||
按顺序,任一步不过就不要提交:
|
||||
|
||||
```bash
|
||||
cd backend && ../.venv/bin/python -m pytest -q # 487 passed, 1 skipped(约 3 分钟)
|
||||
cd backend && ../.venv/bin/python -m pytest -q # 494 passed, 1 skipped(约 3 分钟)
|
||||
bash -n scripts/*.sh # 改过脚本就必须过,shell 没有编译器兜底
|
||||
# 改过 .gitignore:跑 ./scripts/deploy.sh --check,第 3 条不变量会验它没吃掉代码
|
||||
cd frontend && npm run build # 前端类型与打包
|
||||
|
|
|
|||
|
|
@ -1190,7 +1190,8 @@ export default function AssetLibrary() {
|
|||
selectedMedia.has(media.id) && 'border-accent-line shadow-[0_0_0_1px_var(--c-accent-tint)]')}>
|
||||
<label title="勾选后可批量删除(Shift 范围选择)" className={cn(PICK, 'left-[12px] top-[12px]')}>
|
||||
<input type="checkbox" checked={selectedMedia.has(media.id)}
|
||||
onClick={(e) => { e.stopPropagation(); toggleMedia(media, idx, e.shiftKey) }} />
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) => toggleMedia(media, idx, (e.nativeEvent as MouseEvent).shiftKey)} />
|
||||
</label>
|
||||
<MediaThumb item={wallQueue[idx]} size="sm" radius={8} queue={wallQueue} index={idx}
|
||||
title={`${media.name || media.kind_label} · ${media.owner_name}`} />
|
||||
|
|
@ -1238,7 +1239,8 @@ export default function AssetLibrary() {
|
|||
<label className="contents max-short:hidden"
|
||||
title={isSelected(row) ? '取消选择' : '勾选后可批量引入 / 打标签 / 删除(Shift 范围选择)'}>
|
||||
<input type="checkbox" checked={isSelected(row)}
|
||||
onClick={(e) => { e.stopPropagation(); toggleSelect(row, idx, e.shiftKey) }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) => toggleSelect(row, idx, (e.nativeEvent as MouseEvent).shiftKey)}
|
||||
className="self-center flex-none w-[14px] h-[14px] m-0 accent-accent cursor-pointer" />
|
||||
</label>
|
||||
<Portrait name={row.name} sm />
|
||||
|
|
@ -1316,7 +1318,8 @@ export default function AssetLibrary() {
|
|||
<label className={PICK}
|
||||
title={isSelected(row) ? '取消选择' : '勾选后可批量引入 / 打标签 / 删除(Shift 范围选择)'}>
|
||||
<input type="checkbox" checked={isSelected(row)}
|
||||
onClick={(e) => { e.stopPropagation(); toggleSelect(row, idx, e.shiftKey) }} />
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) => toggleSelect(row, idx, (e.nativeEvent as MouseEvent).shiftKey)} />
|
||||
</label>
|
||||
<div className="flex items-start gap-2.5 pl-[22px] min-w-0">
|
||||
<Portrait name={row.name} />
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ export default function Login() {
|
|||
|
||||
<label className="mb-[10px] flex flex-col gap-[5px] text-caption">
|
||||
<span className="text-muted">用户名</span>
|
||||
<input ref={userRef} value={form.username} autoComplete="username" spellCheck={false}
|
||||
<input id="login-user" ref={userRef} value={form.username} autoComplete="username" spellCheck={false}
|
||||
placeholder={'如 ' + (user?.username || 'admin')}
|
||||
onChange={(e) => setForm((f) => ({ ...f, username: e.target.value }))} />
|
||||
</label>
|
||||
|
|
|
|||
|
|
@ -1344,13 +1344,16 @@ const PICKED = 'border-l-2 border-l-accent-line -ml-[12px] pl-[10px] rounded-[6p
|
|||
* 卡片 / 表格行首的裸勾选框(.lib-pick)。
|
||||
*
|
||||
* 不放可见文字,选的是谁由 aria-label 说明;Shift 连选读的是原生事件的
|
||||
* shiftKey,所以事件原样传给上层的 togglePick,别在这里换算成布尔值。
|
||||
* shiftKey,所以把 onChange 的 nativeEvent 原样交给上层的 togglePick,
|
||||
* 别在这里换算成布尔值。(受控 checkbox 必须挂 onChange,只写 onClick 会被
|
||||
* React 当成只读字段,每个渲染周期往控制台刷一条 error。)
|
||||
*/
|
||||
function PickBox({ checked, label, className, onToggle }: {
|
||||
checked: boolean; label: string; className?: string; onToggle: (ev?: { shiftKey?: boolean }) => void
|
||||
}) {
|
||||
return (
|
||||
<input type="checkbox" checked={checked} aria-label={label} onClick={(e) => onToggle(e)}
|
||||
<input type="checkbox" checked={checked} aria-label={label}
|
||||
onChange={(e) => onToggle(e.nativeEvent as MouseEvent)}
|
||||
className={cn('flex-none w-[14px] h-[14px] m-0 accent-accent cursor-pointer', className)} />
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -549,7 +549,9 @@ export default function Storyboard() {
|
|||
const value = (full as any)[key]
|
||||
if (value !== undefined && value !== null) (next as any)[key] = value
|
||||
}
|
||||
next.seed = full.seed ?? null
|
||||
// seed 必须回落到空串而不是 null:`<input type=number value={null}>` 会让 React 报警,
|
||||
// 并把输入框切成非受控(下一镜会带着上一镜留在 DOM 里的值);保存时 intOrNull('') 同样得到 null。
|
||||
next.seed = full.seed ?? ''
|
||||
next.lines = normalizeLines(full)
|
||||
next.ambience = full.ambience || ''
|
||||
next.sound_effects = (Array.isArray(full.sound_effects) ? full.sound_effects : [])
|
||||
|
|
@ -578,11 +580,18 @@ export default function Storyboard() {
|
|||
if (row) await select(row.id)
|
||||
}
|
||||
|
||||
/* 检查器本体与「画面描述」的 DOM 句柄。旧站靠 document.querySelector('.sb-insp')
|
||||
跨组件摸元素,类名换成工具类之后那个钩子就不存在了——「✎ 改文案」点了不聚焦,
|
||||
属于静默失效(querySelector 返回 null 谁都不报错)。ref 挂在节点上,
|
||||
与样式类名彻底脱钩,改皮肤不会再弄丢行为。 */
|
||||
const inspRef = useRef<HTMLElement>(null)
|
||||
const descRef = useRef<HTMLTextAreaElement>(null)
|
||||
|
||||
/** 窄屏时检查器堆在看板上方,选中镜头后把它滚进视野,避免"点了没反应"的错觉 */
|
||||
function scrollToInspector() {
|
||||
if (!window.matchMedia('(max-width: 1080px)').matches) return
|
||||
requestAnimationFrame(() => {
|
||||
document.querySelector('.sb-insp')?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
inspRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -974,9 +983,9 @@ export default function Storyboard() {
|
|||
setInspectorTab('shot')
|
||||
if (live.current.selectedId !== shot.id) await select(shot.id, false)
|
||||
/* 四个页签的内容全都保持挂载、只用 hidden 收起来(见检查器注释),
|
||||
所以这里才 querySelector 得到;再等两帧让 hidden 真正摘掉,量出来的位置才对。 */
|
||||
所以 ref 一直挂在节点上;再等两帧让 hidden 真正摘掉,量出来的位置才对。 */
|
||||
await new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())))
|
||||
const el = document.querySelector<HTMLTextAreaElement>('.sb-insp textarea[data-field="description"]')
|
||||
const el = descRef.current
|
||||
if (!el) return
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
el.focus({ preventScroll: true })
|
||||
|
|
@ -1395,7 +1404,7 @@ export default function Storyboard() {
|
|||
)}
|
||||
</main>
|
||||
|
||||
{/* ===== 检查器(.sb-insp)=====
|
||||
{/* ===== 检查器(inspRef)=====
|
||||
它不是 Drawer:Drawer 是模态(Esc 关闭 + 锁滚动 + 遮罩吞点击),
|
||||
而改分镜要「左边挑镜头、右边改文案」来回看,遮罩会把看板挡死。
|
||||
这里保留抽屉的皮肤(同一套 head/body/actions 类名),自己管开合。 */}
|
||||
|
|
@ -1408,7 +1417,7 @@ export default function Storyboard() {
|
|||
/* 1400 / 1080 / 720 这三档没有命名断点(huge=1440 / mid=1180 / mid2=1100 / nav=900),
|
||||
只能写任意值变体:检查器要同时放下「提示词 + 参考图 + 参数」两列,
|
||||
按 1180 回落会在 1200px 屏上就把字段挤成一列,编辑区被表单撑爆。 */
|
||||
<aside className={cn(
|
||||
<aside ref={inspRef} className={cn(
|
||||
'fixed top-(--nex-bar) right-0 bottom-0 left-auto z-[60] flex max-h-[calc(100vh-var(--nex-bar))] '
|
||||
+ 'w-[min(max(900px,68vw),1500px)] flex-col overflow-hidden border-l border-line-strong bg-sunken shadow-drawer '
|
||||
+ 'max-[1400px]:w-[min(880px,calc(100vw-24px))] max-[1080px]:w-[min(760px,calc(100vw-24px))] max-[720px]:w-screen'
|
||||
|
|
@ -1460,7 +1469,7 @@ export default function Storyboard() {
|
|||
</Field>
|
||||
</FormRow>
|
||||
<FieldBlock label="画面描述" title="这段描述是生成提示词的主体">
|
||||
<textarea data-field="description" rows={4} value={draft.description}
|
||||
<textarea ref={descRef} data-field="description" rows={4} value={draft.description}
|
||||
placeholder="星舰舰桥,林澈凝视全息星图"
|
||||
onChange={(e) => edit({ description: e.target.value })} />
|
||||
</FieldBlock>
|
||||
|
|
|
|||
Loading…
Reference in New Issue