fix(delete): redirect Delete to owning component when target is empty linked node
Linked Craft.js nodes (column children of ColumnLayout, section-inner of Section, etc.) are structurally non-deletable — actions.delete throws and the error was silently swallowed. Empty layouts ended up undeletable from the canvas because clicks always landed on the linked children that fill the layout's visible area. Adds findDeletableTarget(): when target is a linked node and ALL its linked siblings are also empty (i.e., the layout itself is empty), redirect deletion to the owning parent. Refuses to redirect when any sibling has content, to protect against nuking a 3-col layout that has content in other cols. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import React, { useEffect, useCallback, useRef } from 'react';
|
||||
import { useEditor } from '@craftjs/core';
|
||||
import { findDeletableTarget } from '../../utils/craft-helpers';
|
||||
|
||||
interface ContextMenuProps {
|
||||
visible: boolean;
|
||||
@@ -143,14 +144,18 @@ export const ContextMenu: React.FC<ContextMenuProps> = ({
|
||||
}, [nodeId, actions, getParentId, onClose]);
|
||||
|
||||
const deleteNode = useCallback(() => {
|
||||
if (!nodeId || nodeId === 'ROOT') return;
|
||||
const target = findDeletableTarget(query, nodeId);
|
||||
if (!target) {
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
actions.delete(nodeId);
|
||||
actions.delete(target);
|
||||
} catch (e) {
|
||||
console.error('Delete failed:', e);
|
||||
}
|
||||
onClose();
|
||||
}, [nodeId, actions, onClose]);
|
||||
}, [nodeId, actions, query, onClose]);
|
||||
|
||||
if (!visible) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user