Reuse scene editor workspace for detachable viewers

This commit is contained in:
Codex
2026-11-14 21:05:12 +03:00
parent 64908711a4
commit ce1b707348
4 changed files with 14 additions and 10 deletions
+7 -6
View File
@@ -5,9 +5,9 @@ import {Icon} from './Icon.js';
import {WindowSuspensionContext} from './WindowSuspensionContext.js';
import {cn} from './cn.js';
export interface EditorWorkspaceProps {editing:boolean;title:ReactNode;subtitle?:ReactNode;onBack:()=>void;children:ReactNode;className?:string}
export interface EditorWorkspaceProps {editing:boolean;title:ReactNode;subtitle?:ReactNode;onBack:()=>void;children:ReactNode;className?:string;purpose?:'edit'|'view';headerActions?:ReactNode}
/** One mounted renderer moves between its original slot and a modeless editor window. */
export function EditorWorkspace({editing,title,subtitle,onBack,children,className}:EditorWorkspaceProps){
export function EditorWorkspace({editing,title,subtitle,onBack,children,className,purpose='edit',headerActions}:EditorWorkspaceProps){
const suspend=useContext(WindowSuspensionContext);
useLayoutEffect(()=>{if(editing)return suspend?.();},[editing,suspend]);
const inline=useRef<HTMLDivElement>(null),[host]=useState(()=>document.createElement('div'));
@@ -28,10 +28,11 @@ export function EditorWorkspace({editing,title,subtitle,onBack,children,classNam
{editing&&<header className="nodedc-window__head nodedc-editor-workspace__head">
<div className="nodedc-window__titles"><h1 id={titleId} className="nodedc-window__title">{title}</h1>{subtitle&&<p className="nodedc-window__subtitle">{subtitle}</p>}</div>
<div className="nodedc-window__actions">
<IconButton data-editor-back label="Вернуться из редактора сцены" onClick={onBack}><Icon name="chevron-left"/></IconButton>
<IconButton label={expanded?'Восстановить окно редактора':'Развернуть окно редактора'} onClick={()=>setExpanded(v=>!v)}><Icon name={expanded?'minimize':'expand'}/></IconButton>
<IconButton label="Завершить редактирование сцены" aria-pressed onClick={onBack}><Icon name="edit"/></IconButton>
<IconButton label="Закрыть редактор сцены" onClick={onBack}><Icon name="close"/></IconButton>
{headerActions}
<IconButton data-editor-back label={purpose==='view'?'Вернуть просмотр в рабочую область':'Вернуться из редактора сцены'} onClick={onBack}><Icon name="chevron-left"/></IconButton>
<IconButton label={expanded?(purpose==='view'?'Восстановить окно просмотра':'Восстановить окно редактора'):(purpose==='view'?'Развернуть окно просмотра':'Развернуть окно редактора')} onClick={()=>setExpanded(v=>!v)}><Icon name={expanded?'minimize':'expand'}/></IconButton>
{purpose==='edit'&&<IconButton label="Завершить редактирование сцены" aria-pressed onClick={onBack}><Icon name="edit"/></IconButton>}
<IconButton label={purpose==='view'?'Закрыть отдельное окно просмотра':'Закрыть редактор сцены'} onClick={onBack}><Icon name="close"/></IconButton>
</div>
</header>}
<div className="nodedc-editor-workspace__body">{children}</div>