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:
@@ -40,6 +40,9 @@ export function CardLayer(props: CardLayerProps) {
|
|||||||
const isLayerSelected = (layerIndex: number) =>
|
const isLayerSelected = (layerIndex: number) =>
|
||||||
selectedLayer() === layerIndex;
|
selectedLayer() === layerIndex;
|
||||||
|
|
||||||
|
const isEditing = () =>
|
||||||
|
props.store.state.isEditing && !props.store.state.fixed;
|
||||||
|
|
||||||
const getFrameBounds = (layer: LayerConfig) => {
|
const getFrameBounds = (layer: LayerConfig) => {
|
||||||
const dims = dimensions();
|
const dims = dimensions();
|
||||||
const left = (layer.x1 - 1) * dims.cellWidth;
|
const left = (layer.x1 - 1) * dims.cellWidth;
|
||||||
@@ -75,10 +78,11 @@ export function CardLayer(props: CardLayerProps) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<article
|
<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={{
|
classList={{
|
||||||
|
"cursor-pointer": isEditing(),
|
||||||
"ring-2 ring-blue-500 ring-offset-1":
|
"ring-2 ring-blue-500 ring-offset-1":
|
||||||
isSelected() && !draggingState(),
|
isSelected() && !draggingState() && isEditing(),
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
...getLayerStyle(layer, dimensions()),
|
...getLayerStyle(layer, dimensions()),
|
||||||
@@ -88,7 +92,7 @@ export function CardLayer(props: CardLayerProps) {
|
|||||||
innerHTML={renderLayerContent(props.cardData[layer.prop])}
|
innerHTML={renderLayerContent(props.cardData[layer.prop])}
|
||||||
onClick={(e) => handleLayerClick(index(), e)}
|
onClick={(e) => handleLayerClick(index(), e)}
|
||||||
/>
|
/>
|
||||||
<Show when={isSelected()}>
|
<Show when={isSelected() && isEditing()}>
|
||||||
<div
|
<div
|
||||||
class="absolute border-2 border-blue-500 pointer-events-none z-10"
|
class="absolute border-2 border-blue-500 pointer-events-none z-10"
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ export function useLayerInteraction(
|
|||||||
const handleLayerClick = (index: number, e: MouseEvent) => {
|
const handleLayerClick = (index: number, e: MouseEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
|
if (!store.state.isEditing || store.state.fixed) return;
|
||||||
|
|
||||||
const currentlySelected = store.state.selectedLayer;
|
const currentlySelected = store.state.selectedLayer;
|
||||||
|
|
||||||
if (currentlySelected === index) {
|
if (currentlySelected === index) {
|
||||||
@@ -100,6 +102,7 @@ export function useLayerInteraction(
|
|||||||
|
|
||||||
const handleCardClick = (e: MouseEvent, cardEl: HTMLElement) => {
|
const handleCardClick = (e: MouseEvent, cardEl: HTMLElement) => {
|
||||||
if (store.state.draggingState) return;
|
if (store.state.draggingState) return;
|
||||||
|
if (!store.state.isEditing || store.state.fixed) return;
|
||||||
|
|
||||||
const { gridX, gridY } = calculateGridCoords(e, cardEl);
|
const { gridX, gridY } = calculateGridCoords(e, cardEl);
|
||||||
const overlapping = getOverlappingLayers(gridX, gridY);
|
const overlapping = getOverlappingLayers(gridX, gridY);
|
||||||
@@ -147,6 +150,7 @@ export function useLayerInteraction(
|
|||||||
edge?: "n" | "s" | "e" | "w",
|
edge?: "n" | "s" | "e" | "w",
|
||||||
e?: MouseEvent,
|
e?: MouseEvent,
|
||||||
) => {
|
) => {
|
||||||
|
if (!store.state.isEditing || store.state.fixed) return;
|
||||||
if (store.state.selectedLayer === null) return;
|
if (store.state.selectedLayer === null) return;
|
||||||
if (e) e.stopPropagation();
|
if (e) e.stopPropagation();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user