refactor(editor): improve selection parity and exhaustiveness

This commit is contained in:
clawdbot 2026-01-27 23:12:47 +08:00
parent 38119cbe55
commit 0df4e9a704

View File

@ -1,5 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import type { Screen, WidgetNode } from '@astralview/sdk'; import type { Screen, WidgetNode } from '@astralview/sdk';
import { assertNever } from '@astralview/sdk';
import { Button, Space, Typography } from 'antd'; import { Button, Space, Typography } from 'antd';
import type { ResizeHandle } from './types'; import type { ResizeHandle } from './types';
import { rectFromPoints } from './geometry'; import { rectFromPoints } from './geometry';
@ -232,7 +233,7 @@ export function Canvas(props: CanvasProps) {
const p = clientToWorld(e.clientX, e.clientY); const p = clientToWorld(e.clientX, e.clientY);
if (!p) return; if (!p) return;
const additive = e.ctrlKey || e.metaKey; const additive = e.ctrlKey || e.metaKey || e.shiftKey;
if (!additive) props.onSelectSingle(undefined); if (!additive) props.onSelectSingle(undefined);
props.onBeginBoxSelect(e, p.x, p.y, additive); props.onBeginBoxSelect(e, p.x, p.y, additive);
setBox(rectFromPoints({ x: p.x, y: p.y }, { x: p.x, y: p.y })); setBox(rectFromPoints({ x: p.x, y: p.y }, { x: p.x, y: p.y }));
@ -555,7 +556,10 @@ function NodeView(props: {
borderStyle: node.hidden ? 'dashed' : 'solid', borderStyle: node.hidden ? 'dashed' : 'solid',
}} }}
> >
{node.type === 'text' ? ( {(() => {
switch (node.type) {
case 'text':
return (
<div <div
style={{ style={{
width: '100%', width: '100%',
@ -597,7 +601,10 @@ function NodeView(props: {
{node.props.text} {node.props.text}
</span> </span>
</div> </div>
) : node.type === 'image' ? ( );
case 'image':
return (
<div <div
style={{ style={{
width: '100%', width: '100%',
@ -619,7 +626,10 @@ function NodeView(props: {
}} }}
/> />
</div> </div>
) : node.type === 'iframe' ? ( );
case 'iframe':
return (
<div <div
style={{ style={{
width: '100%', width: '100%',
@ -641,7 +651,10 @@ function NodeView(props: {
title={node.id} title={node.id}
/> />
</div> </div>
) : node.type === 'video' ? ( );
case 'video':
return (
<div <div
style={{ style={{
width: '100%', width: '100%',
@ -668,7 +681,12 @@ function NodeView(props: {
}} }}
/> />
</div> </div>
) : null} );
default:
return assertNever(node);
}
})()}
{props.selected && !node.locked && !node.hidden && <ResizeHandles onPointerDown={props.onResizePointerDown} />} {props.selected && !node.locked && !node.hidden && <ResizeHandles onPointerDown={props.onResizePointerDown} />}
</div> </div>