fix: Prevent layer interactions when not editing

Guard layer selection, cursor, and resize interactions behind
the editing state to avoid unintended modifications in view mode.
This commit is contained in:
hyper
2026-08-07 11:24:57 +08:00
parent 6bcdca3a77
commit a69a41875d
2 changed files with 11 additions and 3 deletions
+7 -3
View File
@@ -40,6 +40,9 @@ export function CardLayer(props: CardLayerProps) {
const isLayerSelected = (layerIndex: number) =>
selectedLayer() === layerIndex;
const isEditing = () =>
props.store.state.isEditing && !props.store.state.fixed;
const getFrameBounds = (layer: LayerConfig) => {
const dims = dimensions();
const left = (layer.x1 - 1) * dims.cellWidth;
@@ -75,10 +78,11 @@ export function CardLayer(props: CardLayerProps) {
return (
<>
<article
class="absolute flex flex-col items-stretch justify-center prose text-black prose-sm cursor-pointer"
class="absolute flex flex-col items-stretch justify-center prose text-black prose-sm"
classList={{
"cursor-pointer": isEditing(),
"ring-2 ring-blue-500 ring-offset-1":
isSelected() && !draggingState(),
isSelected() && !draggingState() && isEditing(),
}}
style={{
...getLayerStyle(layer, dimensions()),
@@ -88,7 +92,7 @@ export function CardLayer(props: CardLayerProps) {
innerHTML={renderLayerContent(props.cardData[layer.prop])}
onClick={(e) => handleLayerClick(index(), e)}
/>
<Show when={isSelected()}>
<Show when={isSelected() && isEditing()}>
<div
class="absolute border-2 border-blue-500 pointer-events-none z-10"
style={{
@@ -87,6 +87,8 @@ export function useLayerInteraction(
const handleLayerClick = (index: number, e: MouseEvent) => {
e.stopPropagation();
if (!store.state.isEditing || store.state.fixed) return;
const currentlySelected = store.state.selectedLayer;
if (currentlySelected === index) {
@@ -100,6 +102,7 @@ export function useLayerInteraction(
const handleCardClick = (e: MouseEvent, cardEl: HTMLElement) => {
if (store.state.draggingState) return;
if (!store.state.isEditing || store.state.fixed) return;
const { gridX, gridY } = calculateGridCoords(e, cardEl);
const overlapping = getOverlappingLayers(gridX, gridY);
@@ -147,6 +150,7 @@ export function useLayerInteraction(
edge?: "n" | "s" | "e" | "w",
e?: MouseEvent,
) => {
if (!store.state.isEditing || store.state.fixed) return;
if (store.state.selectedLayer === null) return;
if (e) e.stopPropagation();