feat(site-builder): reusable global sections with per-page overrides

Make a top-level section global (context menu), place instances from the
Section library's new Global tab, edit the master once in its own zone
("Editing global section" banner, Done - update N instances) and every
instance on every page/header/footer is rebuilt from it. Instances are real
inlined subtrees (custom.global on the root, custom.gkey on every node), so
export and published output are unchanged static HTML.

- utils/global-sections.ts: pure model (createMaster, instantiate,
  syncInstances, collectOverridesFromInstance, applyOverrides, detach,
  findInstanceRoot, master zone round trip). Unchanged input returns the
  identical string; sync keeps the instance root id and the instance's own
  inner ids per gkey.
- PageContext: __global__:<id> zone (editGlobal / finishGlobal); leaving it
  commits the master (rev + 1 only when it changed), syncs every stored
  slot and applies the sync to the returned-to canvas as ONE undo step.
- GlobalSectionsContext: makeGlobal / insertInstance / detach / setOverride
  / resetOverride / remove (refused while used), one undo step each.
- Inline text edits inside an instance record an override (text + html)
  via useGlobalOverrideCommit; GuidedStyles shows a Global section panel
  (Edit master, Detach, content override fields) instead of style panels.
- RenderNode: Global badge, dashed outline, lock icon on inner nodes.
- buildSavePayload: a master zone on the canvas is never saved into a page.

Refs #57

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-10-07 12:28:53 -07:00
1 parent 48061d37ae
commit dd8b99be06
15 files changed
+1898 -29

No files matched your search

@@ -7,6 +7,7 @@ import {
resolveInlineHtml,
markExternalLinks,
} from '../../utils/inline-html';
import { useGlobalOverrideCommit } from '../../state/GlobalInstanceContext';
interface InlineTextProps {
text?: string;
@@ -35,6 +36,7 @@ export function useInlineEditable(
) {
const elRef = useRef<HTMLElement | null>(null);
const pendingRef = useRef(false);
const commitProps = useGlobalOverrideCommit(setProp); // #57: inside a global instance -> override
const commit = useCallback(() => {
if (!pendingRef.current) return;
@@ -45,8 +47,8 @@ export function useInlineEditable(
const clean = sanitizeInlineHtml(el.innerHTML);
const nextText = inlineHtmlToText(clean);
const nextHtml = isPlainInlineHtml(clean) ? '' : clean;
setProp((p) => { p.html = nextHtml; p.text = nextText; });
}, [setProp]);
commitProps((p) => { p.html = nextHtml; p.text = nextText; });
}, [commitProps]);
// Deselect without a blur (e.g. Escape, programmatic selection change).
useEffect(() => {