fix(global-sections): block structural edits inside a global-section instance

syncInstances rebuilds an instance's subtree from the master, so a node
dropped, pasted, duplicated or moved into an instance vanished from every page
on the next master edit. Chosen approach: BLOCK (not preserve-on-sync):
- every resolver component's Craft canMoveIn/canMoveOut refuses a canvas inside
  an instance (canvas DnD, Layers DnD, actions.move); synthetic shell-inner
  nodes now carry the component's rules instead of hardcoded allow-all
- insertBlock (BlocksPanel / EmptyContainerAdd / palette), paste (menu +
  shortcut), duplicate (menu + shortcut) and Sitesmith patch/section replace
  redirect to after the instance or refuse; no empty-container '+' inside one
The instance root still moves/duplicates as a whole; content overrides are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-10-07 13:32:34 -07:00
1 parent ca500d36a9
commit 6d22aabdc0
11 files changed
+271 -17

No files matched your search

+7 -1
View File
@@ -1,4 +1,5 @@
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
import { instanceMeta } from '../utils/global-sections';
import { useEditor } from '@craftjs/core';
import { BLOCKS, insertBlock } from '../panels/left/blocks-registry';
@@ -42,7 +43,12 @@ export const EmptyContainerAdd: React.FC = () => {
const eligible = (id: string | undefined): id is string => {
if (!id || id === 'ROOT') return false;
const n = state.nodes[id];
return !!n && !!n.data.isCanvas && n.data.nodes.length === 0;
if (!n || !n.data.isCanvas || n.data.nodes.length !== 0) return false;
// #57: no "+" inside a global-section instance (its structure belongs to the master).
for (let p: any = n, guard = 0; p && guard < 500; p = p.data.parent ? state.nodes[p.data.parent] : null, guard++) {
if (instanceMeta(p.data)) return false;
}
return true;
};
const hovered = [...state.events.hovered][0];
const selected = [...state.events.selected][0];
+7 -1
View File
@@ -1,4 +1,5 @@
import { registerCommands, type Command, type CommandContext } from './commands';
import { insertTargetOutsideInstance, isInsideInstance } from '../utils/global-sections';
import { findDeletableTarget, getAncestorIds, getParentId } from '../utils/craft-helpers';
import { regenerateTreeIds } from '../utils/craft-tree';
import { getClipboardTree, setClipboardTree } from '../hooks/clipboard';
@@ -64,6 +65,8 @@ function duplicateAll({ query, actions, selectedIds }: CommandContext): void {
const idx = sib ? sib.siblings.indexOf(id) : -1;
// Linked nodes (columns, section inner) are not in `nodes` and cannot be copied alone.
if (!sib || idx === -1) continue;
// #57: a copy inside an instance would be wiped by the next master sync.
if (isInsideInstance(query, sib.parentId)) continue;
const tree = regenerateTreeIds(query.node(id).toNodeTree());
created.push(insertTree(step(), tree, sib.parentId, idx + 1));
} catch (err) {
@@ -104,8 +107,11 @@ function pasteClipboard({ query, actions, selectedIds }: CommandContext): void {
if (idx !== -1) index = idx + 1;
}
}
// #57: pasting next to a node inside an instance lands after the instance.
const at = insertTargetOutsideInstance(query, parentId, index);
if (!at) return;
const tree = regenerateTreeIds(clip);
actions.selectNode(insertTree(actions, tree, parentId, index));
actions.selectNode(insertTree(actions, tree, at.parentId, at.index));
}
/** One step among siblings. Moving down walks the selection in reverse so a run of