cms-renderer 0.6.10 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/block-renderer.d.ts +27 -8
- package/dist/lib/block-renderer.js +409 -109
- package/dist/lib/block-renderer.js.map +1 -1
- package/dist/lib/client-editable-block.d.ts +5 -2
- package/dist/lib/client-editable-block.js +53 -11
- package/dist/lib/client-editable-block.js.map +1 -1
- package/dist/lib/custom-schemas.js.map +1 -1
- package/dist/lib/parametric-route.d.ts +7 -3
- package/dist/lib/parametric-route.js +411 -135
- package/dist/lib/parametric-route.js.map +1 -1
- package/dist/lib/renderer.js +411 -135
- package/dist/lib/renderer.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/block-renderer.tsx","../../lib/cms-post-message.ts"],"sourcesContent":["/**\n * Block Renderer Component\n *\n * Dispatches block data to the appropriate component using the ComponentMap pattern.\n * This is the main entry point for rendering blocks from the CMS.\n */\n\nimport React from 'react';\nimport { ClientEditableBlock } from './client-editable-block';\nimport { getCmsParentTargetOrigin } from './cms-post-message';\nimport type { BlockComponentRegistry, BlockData, ResolvedRouteParams } from './types';\n\ntype TextInfo = {\n value: string;\n path: Array<string | number>;\n parentType?: React.ElementType;\n key?: React.Key | null;\n inSvg?: boolean;\n};\n\ntype ElementInfo = {\n element: React.ReactElement;\n path: Array<string | number>;\n};\n\ntype WalkVisitors = {\n /**\n * Called for every string/number child encountered.\n * Return:\n * - same string (or modified)\n * - a ReactNode (e.g. wrap in <span/>)\n */\n onText?: (info: TextInfo) => React.ReactNode;\n\n /**\n * Called for every ReactElement encountered (after children are processed).\n * Return:\n * - same element\n * - a cloned/modified element\n */\n onElement?: (info: ElementInfo) => React.ReactElement;\n};\n\n/**\n * Recursively maps a ReactNode tree, allowing transformations of text nodes and/or elements.\n * SSR-safe: does not touch DOM APIs.\n */\nexport function walkReactNode(\n node: React.ReactNode,\n visitors: WalkVisitors,\n ctx: {\n path?: Array<string | number>;\n parentType?: React.ElementType;\n key?: React.Key | null;\n inSvg?: boolean;\n } = {}\n): React.ReactNode {\n const path = ctx.path ?? [];\n\n // Fast-path primitives\n if (node == null || typeof node === 'boolean') return node;\n\n if (typeof node === 'string' || typeof node === 'number') {\n const value = String(node);\n return visitors.onText\n ? visitors.onText({ value, path, parentType: ctx.parentType, key: ctx.key, inSvg: ctx.inSvg })\n : node;\n }\n\n // Arrays\n if (Array.isArray(node)) {\n return node.map((child, i) => {\n // biome-ignore lint/suspicious/noExplicitAny: React child key access\n const childKey = (child as any)?.key ?? null;\n const result = walkReactNode(child, visitors, {\n path: [...path, i],\n parentType: ctx.parentType,\n key: childKey,\n inSvg: ctx.inSvg,\n });\n // Ensure array children have keys\n if (React.isValidElement(result) && result.key == null) {\n return React.cloneElement(result, { key: childKey ?? `arr-${path.join('-')}-${i}` });\n }\n return result;\n });\n }\n\n // ReactElement (including Fragment)\n if (React.isValidElement(node)) {\n // biome-ignore lint/suspicious/noExplicitAny: React element props access\n const el = node as React.ReactElement<any>;\n const elProps = el.props as Record<string, unknown> | null;\n\n // Track SVG context so we never inject <span> inside SVG subtrees\n const nextInSvg = ctx.inSvg || el.type === 'svg';\n\n // Recurse into children (if any)\n const hasChildren = elProps && 'children' in elProps;\n const nextChildren = hasChildren\n ? React.Children.map(elProps.children as React.ReactNode, (child, i) => {\n // biome-ignore lint/suspicious/noExplicitAny: React child key access\n const childKey = (child as any)?.key ?? null;\n const result = walkReactNode(child, visitors, {\n path: [...path, 'children', i],\n parentType: el.type as React.ElementType,\n key: childKey,\n inSvg: nextInSvg,\n });\n // Ensure children have keys\n if (React.isValidElement(result) && result.key == null) {\n return React.cloneElement(result, { key: childKey ?? `child-${path.join('-')}-${i}` });\n }\n return result;\n })\n : (elProps?.children as React.ReactNode);\n\n // Only clone if children changed (or if you want to force a clone)\n const cloned = hasChildren\n ? React.cloneElement(el, undefined, nextChildren as React.ReactNode)\n : el;\n\n return visitors.onElement ? visitors.onElement({ element: cloned, path }) : cloned;\n }\n\n // Functions, symbols, portals, etc. are rare here; return as-is\n return node;\n}\n\n// -----------------------------------------------------------------------------\n// Content Value Extraction\n// -----------------------------------------------------------------------------\n\ntype ContentMatch = {\n contentPath: string;\n value: string;\n};\n\n/**\n * Extracts all string values from a content object with their paths.\n * Returns a Map where keys are string values and values are arrays of content paths.\n */\nfunction extractContentValues(\n content: Record<string, unknown>,\n basePath: string[] = []\n): Map<string, ContentMatch[]> {\n const map = new Map<string, ContentMatch[]>();\n\n function walk(obj: unknown, path: string[]) {\n if (typeof obj === 'string' && obj.trim() !== '') {\n const contentPath = path.join('.');\n const existing = map.get(obj) || [];\n existing.push({ contentPath, value: obj });\n map.set(obj, existing);\n } else if (Array.isArray(obj)) {\n for (let index = 0; index < obj.length; index++) {\n walk(obj[index], [...path, String(index)]);\n }\n } else if (obj && typeof obj === 'object') {\n for (const [key, value] of Object.entries(obj)) {\n walk(value, [...path, key]);\n }\n }\n }\n\n walk(content, basePath);\n return map;\n}\n\n// -----------------------------------------------------------------------------\n// CmsEditableInit — render once per page in edit mode\n// -----------------------------------------------------------------------------\n\n/**\n * Renders the shared CMS edit-mode styles and click-routing script.\n * Place this once at the top of your page when edit_mode is active.\n */\nexport function CmsEditableInit({\n cmsUrl,\n cmsParentOrigin,\n}: {\n cmsUrl?: string;\n /** Admin window origin when proxied (from ?cms_parent_origin=). */\n cmsParentOrigin?: string;\n}) {\n const cmsParentOriginJson = JSON.stringify(\n getCmsParentTargetOrigin(cmsUrl, cmsParentOrigin) ?? ''\n );\n\n return (\n <>\n <style>{`\n [data-cms-editable] {\n cursor: pointer;\n border-radius: 2px;\n }\n [data-cms-editable]:hover {\n outline: 2px solid #3b82f6;\n outline-offset: 2px;\n }\n .cms-block-toolbar {\n position: fixed;\n display: flex;\n gap: 4px;\n background: #1f2937;\n border-radius: 6px;\n padding: 4px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);\n transition: opacity 0.15s ease;\n z-index: 99999;\n pointer-events: auto;\n }\n .cms-block-toolbar button {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n border: none;\n background: transparent;\n color: #9ca3af;\n border-radius: 4px;\n cursor: pointer;\n transition: background 0.15s ease, color 0.15s ease;\n }\n .cms-block-toolbar button:hover {\n background: #374151;\n color: #fff;\n }\n .cms-block-toolbar button.delete:hover {\n background: #dc2626;\n color: #fff;\n }\n .cms-block-toolbar button:disabled {\n opacity: 0.4;\n cursor: not-allowed;\n }\n .cms-block-toolbar button:disabled:hover {\n background: transparent;\n color: #9ca3af;\n }\n .cms-block-toolbar svg {\n width: 16px;\n height: 16px;\n }\n `}</style>\n <script\n // biome-ignore lint/security/noDangerouslySetInnerHtml: Inline script for iframe postMessage click routing\n dangerouslySetInnerHTML={{\n __html: `\n (function() {\n var cmsParentOrigin = ${cmsParentOriginJson};\n if (!window.__cmsEditableInitialized) {\n window.__cmsEditableInitialized = true;\n\n document.addEventListener('click', function(e) {\n if (e.target.closest('.cms-block-toolbar')) return;\n\n var editableTarget = e.target.closest('[data-cms-editable]');\n if (editableTarget) {\n var message = {\n type: 'cms-editable-click',\n blockId: editableTarget.getAttribute('data-block-id'),\n blockType: editableTarget.getAttribute('data-block-type'),\n contentPath: editableTarget.getAttribute('data-content-path')\n };\n if (cmsParentOrigin && window.parent && window.parent !== window) {\n window.parent.postMessage(message, cmsParentOrigin);\n }\n return;\n }\n\n var blockTarget = e.target.closest('[data-cms-block]');\n if (blockTarget) {\n var message = {\n type: 'cms-editable-click',\n blockId: blockTarget.getAttribute('data-block-id'),\n blockType: blockTarget.getAttribute('data-block-type'),\n contentPath: null\n };\n if (cmsParentOrigin && window.parent && window.parent !== window) {\n window.parent.postMessage(message, cmsParentOrigin);\n }\n }\n });\n }\n })();\n `,\n }}\n />\n </>\n );\n}\n\n// -----------------------------------------------------------------------------\n// Props\n// -----------------------------------------------------------------------------\n\ninterface BlockRendererProps {\n /**\n * The block data to render.\n * Must have a `type` field that maps to a registered component.\n */\n block: BlockData;\n registry: Partial<BlockComponentRegistry>;\n /**\n * If true, renders the component without any tree walking or editable wrappers.\n */\n disableEditable?: boolean;\n /**\n * Resolved route parameters from parametric routes.\n * Each key is a param name (e.g., \"country\") with its value, schema name, and full document.\n */\n routeParams?: ResolvedRouteParams;\n /**\n * The current URL path (e.g. \"/en/test\").\n * When provided, enables path-namespaced component lookup.\n * Registry keys like \"/{lang}/test Article\" will be matched against this path,\n * where `{x}` and `(x)` are treated as single-segment wildcards.\n */\n path?: string;\n}\n\n// -----------------------------------------------------------------------------\n// Path-namespaced component resolution\n// -----------------------------------------------------------------------------\n\n/**\n * Returns true if each segment of `path` matches the corresponding segment in\n * `pattern`, where a pattern segment wrapped in `{…}` or `(…)` is a wildcard.\n */\nfunction pathMatchesPattern(path: string, pattern: string): boolean {\n const pathSegs = path.split('/').filter(Boolean);\n const patternSegs = pattern.split('/').filter(Boolean);\n if (pathSegs.length !== patternSegs.length) return false;\n for (let i = 0; i < patternSegs.length; i++) {\n const seg = patternSegs[i];\n if (!seg) return false;\n if ((seg.startsWith('{') && seg.endsWith('}')) || (seg.startsWith('(') && seg.endsWith(')'))) {\n continue;\n }\n if (seg !== pathSegs[i]) return false;\n }\n return true;\n}\n\n/**\n * Resolves the component for `blockType` from the registry.\n *\n * When `path` is provided, keys of the form `\"/{pattern} BlockType\"` are\n * checked first. The first key whose path pattern matches the current path\n * and whose block-type suffix matches `blockType` wins. Falls back to a\n * direct `registry[blockType]` lookup.\n */\nfunction resolveComponent(\n registry: Partial<BlockComponentRegistry>,\n blockType: string,\n path?: string\n): BlockComponentRegistry[string] | undefined {\n if (path) {\n for (const key of Object.keys(registry)) {\n if (!key.startsWith('/')) continue;\n const spaceIdx = key.indexOf(' ');\n if (spaceIdx === -1) continue;\n const pathPattern = key.slice(0, spaceIdx);\n const registeredType = key.slice(spaceIdx + 1);\n if (registeredType !== blockType) continue;\n if (pathMatchesPattern(path, pathPattern)) {\n return registry[key];\n }\n }\n }\n return registry[blockType];\n}\n\n// -----------------------------------------------------------------------------\n// Component\n// -----------------------------------------------------------------------------\n\n/**\n * Renders a single block by dispatching to the appropriate component.\n *\n * Uses the ComponentMap pattern: the block's `type` field determines which\n * component renders the block's `content`.\n *\n * In editable mode, wraps the block in a ClientEditableBlock that:\n * - Stamps data-cms-block attributes directly on the component's root element\n * - Injects data-cms-editable spans around matching text nodes\n * - Portals the BlockToolbar into the component's root element\n *\n * Render CmsEditableInit once at the page level to include the shared styles\n * and click-routing script.\n */\nexport function BlockRenderer({\n block,\n registry,\n disableEditable,\n routeParams,\n path,\n}: BlockRendererProps) {\n const Component = resolveComponent(registry, block.type, path);\n\n if (!Component) {\n // Log warning in development, render nothing in production\n if (process.env.NODE_ENV === 'development') {\n console.warn(`[BlockRenderer] Unknown block type: ${block.type}`);\n }\n return null;\n }\n\n // Extract language code from route params if any param is bound to the language schema.\n const language = routeParams\n ? Object.values(routeParams).find((p) => p.schemaName === 'language')?.value\n : undefined;\n\n const component = (\n <Component content={block.content} routeParams={routeParams} language={language} />\n );\n\n if (disableEditable) {\n return component;\n }\n\n // Build content entries for client-side text matching\n const contentValueMap = extractContentValues(block.content as Record<string, unknown>);\n const contentEntries = Array.from(contentValueMap.entries())\n .map(([value, matches]) => ({ v: value, p: matches[0]?.contentPath }))\n .filter((e): e is { v: string; p: string } => !!e.p);\n\n return (\n <ClientEditableBlock blockId={block.id} blockType={block.type} contentEntries={contentEntries}>\n {component}\n </ClientEditableBlock>\n );\n}\n","/**\n * Trusted-origin helpers for CMS template-builder postMessage traffic\n * between the admin UI (parent) and the site preview iframe (child).\n */\n\nexport const CMS_PARENT_ORIGIN_PARAM = 'cms_parent_origin';\n\nexport function parseOrigin(url: string | undefined): string | null {\n if (!url) return null;\n try {\n return new URL(url).origin;\n } catch {\n return null;\n }\n}\n\nfunction getParentOriginFromQueryParam(): string | null {\n if (typeof window === 'undefined') return null;\n const value = new URLSearchParams(window.location.search).get(CMS_PARENT_ORIGIN_PARAM);\n return parseOrigin(value ?? undefined);\n}\n\nfunction getReferrerOrigin(): string | null {\n if (typeof document === 'undefined' || !document.referrer) return null;\n return parseOrigin(document.referrer);\n}\n\n/** Same-origin embed (e.g. proxied admin + preview on the customer domain). */\nfunction getSameOriginParentOrigin(): string | null {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) {\n return null;\n }\n try {\n return window.parent.location.origin;\n } catch {\n return null;\n }\n}\n\n/** Origins allowed to send messages to the preview iframe (CMS admin hosts). */\nexport function getAllowedCmsParentOrigins(explicitParentOrigin?: string): string[] {\n const origins = new Set<string>();\n const apiOrigin = parseOrigin(process.env.NEXT_PUBLIC_CMS_API_URL);\n if (apiOrigin) origins.add(apiOrigin);\n\n const fromQuery = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromQuery) origins.add(fromQuery);\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) origins.add(referrerOrigin);\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) origins.add(sameOriginParent);\n\n return [...origins];\n}\n\n/**\n * Target origin when posting from the preview iframe to the CMS parent.\n *\n * When the admin is proxied on a customer domain, the parent window origin is\n * the customer site — not NEXT_PUBLIC_CMS_API_URL. Prefer explicit/referrer/\n * same-origin parent detection over the CMS API URL.\n */\nexport function getCmsParentTargetOrigin(\n preferredCmsUrl?: string,\n explicitParentOrigin?: string\n): string | null {\n const fromExplicit = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromExplicit) return fromExplicit;\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) return referrerOrigin;\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) return sameOriginParent;\n\n const preferredOrigin = parseOrigin(preferredCmsUrl);\n if (preferredOrigin) return preferredOrigin;\n\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n return allowed[0] ?? null;\n}\n\nexport function isTrustedCmsParentMessage(\n event: MessageEvent,\n explicitParentOrigin?: string\n): boolean {\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n if (allowed.length === 0) return false;\n if (!allowed.includes(event.origin)) return false;\n return event.source === window.parent;\n}\n\nexport function postMessageToCmsParent(\n message: unknown,\n options?: { preferredCmsUrl?: string; explicitParentOrigin?: string }\n): void {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) return;\n const targetOrigin = getCmsParentTargetOrigin(\n options?.preferredCmsUrl,\n options?.explicitParentOrigin\n );\n if (!targetOrigin) return;\n window.parent.postMessage(message, targetOrigin);\n}\n"],"mappings":";AAOA,OAAO,WAAW;AAClB,SAAS,2BAA2B;;;ACH7B,IAAM,0BAA0B;AAEhC,SAAS,YAAY,KAAwC;AAClE,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,gCAA+C;AACtD,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,QAAM,QAAQ,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAAE,IAAI,uBAAuB;AACrF,SAAO,YAAY,SAAS,MAAS;AACvC;AAEA,SAAS,oBAAmC;AAC1C,MAAI,OAAO,aAAa,eAAe,CAAC,SAAS,SAAU,QAAO;AAClE,SAAO,YAAY,SAAS,QAAQ;AACtC;AAGA,SAAS,4BAA2C;AAClD,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,UAAU,OAAO,WAAW,QAAQ;AAC/E,WAAO;AAAA,EACT;AACA,MAAI;AACF,WAAO,OAAO,OAAO,SAAS;AAAA,EAChC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,2BAA2B,sBAAyC;AAClF,QAAM,UAAU,oBAAI,IAAY;AAChC,QAAM,YAAY,YAAY,QAAQ,IAAI,uBAAuB;AACjE,MAAI,UAAW,SAAQ,IAAI,SAAS;AAEpC,QAAM,YAAY,YAAY,oBAA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d,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,uCAAuC,MAAM,IAAI,EAAE;AAAA,IAClE;AACA,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,cACb,OAAO,OAAO,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,eAAe,UAAU,GAAG,QACrE;AAEJ,QAAM,YACJ,oBAAC,aAAU,SAAS,MAAM,SAAS,aAA0B,UAAoB;AAGnF,MAAI,iBAAiB;AACnB,WAAO;AAAA,EACT;AAGA,QAAM,kBAAkB,qBAAqB,MAAM,OAAkC;AACrF,QAAM,iBAAiB,MAAM,KAAK,gBAAgB,QAAQ,CAAC,EACxD,IAAI,CAAC,CAAC,OAAO,OAAO,OAAO,EAAE,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG,YAAY,EAAE,EACpE,OAAO,CAAC,MAAqC,CAAC,CAAC,EAAE,CAAC;AAErD,SACE,oBAAC,uBAAoB,SAAS,MAAM,IAAI,WAAW,MAAM,MAAM,gBAC5D,qBACH;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../lib/block-renderer.tsx","../../lib/cms-overlay-script.ts","../../lib/cms-post-message.ts"],"sourcesContent":["/**\n * Block Renderer Component\n *\n * Dispatches block data to the appropriate component using the ComponentMap pattern.\n * This is the main entry point for rendering blocks from the CMS.\n */\n\nimport React from 'react';\nimport { generateCmsOverlayScript } from './cms-overlay-script';\nimport { getCmsParentTargetOrigin } from './cms-post-message';\nimport type { BlockComponentRegistry, BlockData, ResolvedRouteParams } from './types';\n\ntype TextInfo = {\n value: string;\n path: Array<string | number>;\n parentType?: React.ElementType;\n key?: React.Key | null;\n inSvg?: boolean;\n};\n\ntype ElementInfo = {\n element: React.ReactElement;\n path: Array<string | number>;\n};\n\ntype WalkVisitors = {\n /**\n * Called for every string/number child encountered.\n * Return:\n * - same string (or modified)\n * - a ReactNode (e.g. wrap in <span/>)\n */\n onText?: (info: TextInfo) => React.ReactNode;\n\n /**\n * Called for every ReactElement encountered (after children are processed).\n * Return:\n * - same element\n * - a cloned/modified element\n */\n onElement?: (info: ElementInfo) => React.ReactElement;\n};\n\n/**\n * Recursively maps a ReactNode tree, allowing transformations of text nodes and/or elements.\n * SSR-safe: does not touch DOM APIs.\n */\nexport function walkReactNode(\n node: React.ReactNode,\n visitors: WalkVisitors,\n ctx: {\n path?: Array<string | number>;\n parentType?: React.ElementType;\n key?: React.Key | null;\n inSvg?: boolean;\n } = {}\n): React.ReactNode {\n const path = ctx.path ?? [];\n\n // Fast-path primitives\n if (node == null || typeof node === 'boolean') return node;\n\n if (typeof node === 'string' || typeof node === 'number') {\n const value = String(node);\n return visitors.onText\n ? visitors.onText({ value, path, parentType: ctx.parentType, key: ctx.key, inSvg: ctx.inSvg })\n : node;\n }\n\n // Arrays\n if (Array.isArray(node)) {\n return node.map((child, i) => {\n // biome-ignore lint/suspicious/noExplicitAny: React child key access\n const childKey = (child as any)?.key ?? null;\n const result = walkReactNode(child, visitors, {\n path: [...path, i],\n parentType: ctx.parentType,\n key: childKey,\n inSvg: ctx.inSvg,\n });\n // Ensure array children have keys\n if (React.isValidElement(result) && result.key == null) {\n return React.cloneElement(result, { key: childKey ?? `arr-${path.join('-')}-${i}` });\n }\n return result;\n });\n }\n\n // ReactElement (including Fragment)\n if (React.isValidElement(node)) {\n // biome-ignore lint/suspicious/noExplicitAny: React element props access\n const el = node as React.ReactElement<any>;\n const elProps = el.props as Record<string, unknown> | null;\n\n // Track SVG context so we never inject <span> inside SVG subtrees\n const nextInSvg = ctx.inSvg || el.type === 'svg';\n\n // Recurse into children (if any)\n const hasChildren = elProps && 'children' in elProps;\n const nextChildren = hasChildren\n ? React.Children.map(elProps.children as React.ReactNode, (child, i) => {\n // biome-ignore lint/suspicious/noExplicitAny: React child key access\n const childKey = (child as any)?.key ?? null;\n const result = walkReactNode(child, visitors, {\n path: [...path, 'children', i],\n parentType: el.type as React.ElementType,\n key: childKey,\n inSvg: nextInSvg,\n });\n // Ensure children have keys\n if (React.isValidElement(result) && result.key == null) {\n return React.cloneElement(result, { key: childKey ?? `child-${path.join('-')}-${i}` });\n }\n return result;\n })\n : (elProps?.children as React.ReactNode);\n\n // Only clone if children changed (or if you want to force a clone)\n const cloned = hasChildren\n ? React.cloneElement(el, undefined, nextChildren as React.ReactNode)\n : el;\n\n return visitors.onElement ? visitors.onElement({ element: cloned, path }) : cloned;\n }\n\n // Functions, symbols, portals, etc. are rare here; return as-is\n return node;\n}\n\n// -----------------------------------------------------------------------------\n// Content Value Extraction\n// -----------------------------------------------------------------------------\n\ntype ContentMatch = {\n contentPath: string;\n value: string;\n};\n\n/**\n * Extracts all string values from a content object with their paths.\n * Returns a Map where keys are string values and values are arrays of content paths.\n */\nexport function extractContentValues(\n content: Record<string, unknown>,\n basePath: string[] = []\n): Map<string, ContentMatch[]> {\n const map = new Map<string, ContentMatch[]>();\n\n function walk(obj: unknown, path: string[]) {\n if (typeof obj === 'string' && obj.trim() !== '') {\n const contentPath = path.join('.');\n const existing = map.get(obj) || [];\n existing.push({ contentPath, value: obj });\n map.set(obj, existing);\n } else if (Array.isArray(obj)) {\n for (let index = 0; index < obj.length; index++) {\n walk(obj[index], [...path, String(index)]);\n }\n } else if (obj && typeof obj === 'object') {\n for (const [key, value] of Object.entries(obj)) {\n walk(value, [...path, key]);\n }\n }\n }\n\n walk(content, basePath);\n return map;\n}\n\n// -----------------------------------------------------------------------------\n// CmsEditableInit — render once per page in edit mode\n// -----------------------------------------------------------------------------\n\n/**\n * Renders the shared CMS edit-mode styles and click-routing script.\n * Place this once at the top of your page when edit_mode is active.\n */\nexport function CmsEditableInit({\n cmsUrl,\n cmsParentOrigin,\n}: {\n cmsUrl?: string;\n /** Admin window origin when proxied (from ?cms_parent_origin=). */\n cmsParentOrigin?: string;\n}) {\n const targetOrigin = getCmsParentTargetOrigin(cmsUrl, cmsParentOrigin) ?? '';\n\n return (\n <script\n // biome-ignore lint/security/noDangerouslySetInnerHtml: Inline script for CMS overlay functionality\n dangerouslySetInnerHTML={{\n __html: generateCmsOverlayScript(targetOrigin),\n }}\n />\n );\n}\n\n// -----------------------------------------------------------------------------\n// Props\n// -----------------------------------------------------------------------------\n\ninterface BlockRendererProps {\n /**\n * The block data to render.\n * Must have a `type` field that maps to a registered component.\n */\n block: BlockData;\n registry: Partial<BlockComponentRegistry>;\n /**\n * If true, renders the component without any tree walking or editable wrappers.\n */\n disableEditable?: boolean;\n /**\n * Resolved route parameters from parametric routes.\n * Each key is a param name (e.g., \"country\") with its value, schema name, and full document.\n */\n routeParams?: ResolvedRouteParams;\n /**\n * The current URL path (e.g. \"/en/test\").\n * When provided, enables path-namespaced component lookup.\n * Registry keys like \"/{lang}/test Article\" will be matched against this path,\n * where `{x}` and `(x)` are treated as single-segment wildcards.\n */\n path?: string;\n}\n\n// -----------------------------------------------------------------------------\n// Path-namespaced component resolution\n// -----------------------------------------------------------------------------\n\n/**\n * Returns true if each segment of `path` matches the corresponding segment in\n * `pattern`, where a pattern segment wrapped in `{…}` or `(…)` is a wildcard.\n */\nexport function pathMatchesPattern(path: string, pattern: string): boolean {\n const pathSegs = path.split('/').filter(Boolean);\n const patternSegs = pattern.split('/').filter(Boolean);\n if (pathSegs.length !== patternSegs.length) return false;\n for (let i = 0; i < patternSegs.length; i++) {\n const seg = patternSegs[i];\n if (!seg) return false;\n if ((seg.startsWith('{') && seg.endsWith('}')) || (seg.startsWith('(') && seg.endsWith(')'))) {\n continue;\n }\n if (seg !== pathSegs[i]) return false;\n }\n return true;\n}\n\n/**\n * Resolves the component for `blockType` from the registry.\n *\n * When `path` is provided, keys of the form `\"/{pattern} BlockType\"` are\n * checked first. The first key whose path pattern matches the current path\n * and whose block-type suffix matches `blockType` wins. Falls back to a\n * direct `registry[blockType]` lookup.\n */\nexport function resolveComponent(\n registry: Partial<BlockComponentRegistry>,\n blockType: string,\n path?: string\n): BlockComponentRegistry[string] | undefined {\n if (path) {\n for (const key of Object.keys(registry)) {\n if (!key.startsWith('/')) continue;\n const spaceIdx = key.indexOf(' ');\n if (spaceIdx === -1) continue;\n const pathPattern = key.slice(0, spaceIdx);\n const registeredType = key.slice(spaceIdx + 1);\n if (registeredType !== blockType) continue;\n if (pathMatchesPattern(path, pathPattern)) {\n return registry[key];\n }\n }\n }\n return registry[blockType];\n}\n\n// -----------------------------------------------------------------------------\n// Component\n// -----------------------------------------------------------------------------\n\n/**\n * Renders a single block by dispatching to the appropriate component.\n *\n * Uses the ComponentMap pattern: the block's `type` field determines which\n * component renders the block's `content`.\n *\n * In editable mode, renders a hidden sentinel before the component. The shared\n * CMS overlay script uses that sentinel to stamp attributes on the component's\n * root element without adding a layout-affecting wrapper.\n */\nexport function BlockRenderer({\n block,\n registry,\n disableEditable,\n routeParams,\n path,\n}: BlockRendererProps) {\n const Component = resolveComponent(registry, block.type, path);\n\n if (!Component) {\n // Log warning in development, render nothing in production\n if (process.env.NODE_ENV === 'development') {\n console.warn(`[BlockRenderer] Unknown block type: ${block.type}`);\n }\n return null;\n }\n\n // Extract language code from route params if any param is bound to the language schema.\n const language = routeParams\n ? Object.values(routeParams).find((p) => p.schemaName === 'language')?.value\n : undefined;\n\n const component = (\n <Component content={block.content} routeParams={routeParams} language={language} />\n );\n\n if (disableEditable) {\n return component;\n }\n\n return (\n <>\n <span\n data-cms-sentinel=\"\"\n data-block-id={block.id}\n data-block-type={block.type}\n style={{ display: 'none' }}\n aria-hidden=\"true\"\n />\n {component}\n </>\n );\n}\n","/**\n * CMS Overlay Script\n *\n * Framework-agnostic vanilla JS script that handles all CMS edit mode overlays:\n * - Block hover outlines\n * - Cursor indicator\n * - Block toolbar (move up/down, delete)\n *\n * Uses a sentinel-based approach: hidden <span> elements mark block positions,\n * and this script stamps data attributes on the actual block elements (next sibling).\n * This avoids wrapper elements that could break layouts.\n *\n * Compatible with Next.js, TanStack Start, Remix, and other frameworks.\n */\n\nexport function generateCmsOverlayScript(cmsParentOrigin: string): string {\n return `\n(function() {\n if (window.__cmsOverlayInitialized) return;\n window.__cmsOverlayInitialized = true;\n\n var CMS_PARENT_ORIGIN = ${JSON.stringify(cmsParentOrigin)};\n\n var style = document.createElement('style');\n style.setAttribute('data-cms-overlay', '');\n style.textContent = \\`\n [data-cms-editable] {\n cursor: pointer;\n border-radius: 2px;\n }\n [data-cms-editable]:hover {\n outline: 2px solid #3b82f6;\n outline-offset: 2px;\n }\n #cms-overlay-root {\n position: fixed;\n top: 0;\n left: 0;\n width: 0;\n height: 0;\n pointer-events: none;\n z-index: 99998;\n }\n #cms-overlay-root > * {\n pointer-events: auto;\n }\n .cms-block-outline {\n position: fixed;\n border: 2px solid #3b82f6;\n border-radius: 4px;\n pointer-events: none;\n z-index: 99997;\n transition: all 0.15s ease;\n }\n .cms-block-outline.cms-outline-selected {\n border-color: #2563eb;\n border-width: 3px;\n }\n .cms-block-cursor {\n position: fixed;\n width: 22px;\n height: 22px;\n background: radial-gradient(circle, #fff 5px, #000 5px);\n border-radius: 50%;\n pointer-events: none;\n z-index: 99999;\n transform: translate(-50%, -50%);\n opacity: 0;\n transition: opacity 0.1s ease;\n }\n .cms-block-cursor.cms-cursor-visible {\n opacity: 1;\n }\n .cms-block-toolbar {\n position: fixed;\n display: flex;\n gap: 4px;\n background: #1f2937;\n border-radius: 6px;\n padding: 4px;\n box-shadow: 0 4px 12px rgba(0,0,0,0.25);\n z-index: 99999;\n pointer-events: none;\n opacity: 0;\n transform: scale(0.9) translateY(4px);\n transition: opacity 0.15s ease, transform 0.15s ease;\n }\n .cms-block-toolbar.cms-toolbar-visible {\n opacity: 1;\n transform: scale(1) translateY(0);\n pointer-events: auto;\n }\n .cms-block-toolbar button {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n border: none;\n background: transparent;\n color: #9ca3af;\n border-radius: 4px;\n cursor: pointer;\n transition: background 0.15s ease, color 0.15s ease;\n }\n .cms-block-toolbar button:hover {\n background: #374151;\n color: #fff;\n }\n .cms-block-toolbar button.delete:hover {\n background: #dc2626;\n color: #fff;\n }\n .cms-block-toolbar button:disabled {\n opacity: 0.4;\n cursor: not-allowed;\n }\n .cms-block-toolbar button:disabled:hover {\n background: transparent;\n color: #9ca3af;\n }\n .cms-block-toolbar svg {\n width: 16px;\n height: 16px;\n }\n \\`;\n document.head.appendChild(style);\n\n function stampBlockElements() {\n var sentinels = document.querySelectorAll('[data-cms-sentinel]');\n sentinels.forEach(function(sentinel) {\n var blockEl = sentinel.nextElementSibling;\n if (!blockEl) return;\n\n var blockId = sentinel.getAttribute('data-block-id');\n var blockType = sentinel.getAttribute('data-block-type');\n\n blockEl.setAttribute('data-cms-block', '');\n blockEl.setAttribute('data-block-id', blockId);\n blockEl.setAttribute('data-block-type', blockType);\n blockEl.setAttribute('data-cms-editable', '');\n });\n }\n\n stampBlockElements();\n\n var stampObserver = new MutationObserver(function(mutations) {\n var needsStamp = mutations.some(function(m) {\n return m.addedNodes.length > 0;\n });\n if (needsStamp) stampBlockElements();\n });\n stampObserver.observe(document.body, { childList: true, subtree: true });\n\n var overlayRoot = document.createElement('div');\n overlayRoot.id = 'cms-overlay-root';\n document.body.appendChild(overlayRoot);\n\n var cursor = document.createElement('div');\n cursor.className = 'cms-block-cursor';\n overlayRoot.appendChild(cursor);\n\n var outline = document.createElement('div');\n outline.className = 'cms-block-outline';\n outline.style.display = 'none';\n overlayRoot.appendChild(outline);\n\n var selectedOutline = document.createElement('div');\n selectedOutline.className = 'cms-block-outline cms-outline-selected';\n selectedOutline.style.display = 'none';\n overlayRoot.appendChild(selectedOutline);\n\n var toolbar = document.createElement('div');\n toolbar.className = 'cms-block-toolbar';\n toolbar.setAttribute('data-cms-toolbar', '');\n toolbar.innerHTML = \\`\n <button class=\"move-up\" title=\"Move up\">\n <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <path d=\"M18 15l-6-6-6 6\"/>\n </svg>\n </button>\n <button class=\"move-down\" title=\"Move down\">\n <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <path d=\"M6 9l6 6 6-6\"/>\n </svg>\n </button>\n <button class=\"delete\" title=\"Delete\">\n <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <path d=\"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16\"/>\n </svg>\n </button>\n \\`;\n overlayRoot.appendChild(toolbar);\n\n var currentBlockId = null;\n var toolbarVisible = false;\n var selectedBlockId = null;\n\n function postToParent(message) {\n if (!CMS_PARENT_ORIGIN || !window.parent || window.parent === window) {\n return;\n }\n window.parent.postMessage(message, CMS_PARENT_ORIGIN);\n }\n\n function sendReadySignal() {\n postToParent({ type: 'cms-preview-ready' });\n }\n sendReadySignal();\n // The preview iframe can execute before the admin listener is attached.\n setTimeout(sendReadySignal, 500);\n setTimeout(sendReadySignal, 1500);\n\n function getBlockElement(blockId) {\n return document.querySelector('[data-block-id=\"' + blockId + '\"]');\n }\n\n function getAllBlocks() {\n return Array.from(document.querySelectorAll('[data-cms-block]'));\n }\n\n function getBlockIndex(blockId) {\n var blocks = getAllBlocks();\n for (var i = 0; i < blocks.length; i++) {\n if (blocks[i].getAttribute('data-block-id') === blockId) return i;\n }\n return -1;\n }\n\n function updateOutline(el, outlineEl) {\n if (!el) {\n outlineEl.style.display = 'none';\n return;\n }\n var rect = el.getBoundingClientRect();\n outlineEl.style.display = 'block';\n outlineEl.style.top = rect.top + 'px';\n outlineEl.style.left = rect.left + 'px';\n outlineEl.style.width = rect.width + 'px';\n outlineEl.style.height = rect.height + 'px';\n }\n\n function positionToolbar(x, y) {\n var rect = toolbar.getBoundingClientRect();\n var top = Math.max(4, y - rect.height - 12);\n var left = Math.max(4, Math.min(x - rect.width / 2, window.innerWidth - rect.width - 4));\n toolbar.style.top = top + 'px';\n toolbar.style.left = left + 'px';\n }\n\n function showToolbar(x, y, blockId) {\n currentBlockId = blockId;\n toolbarVisible = true;\n positionToolbar(x, y);\n toolbar.classList.add('cms-toolbar-visible');\n\n var index = getBlockIndex(blockId);\n var total = getAllBlocks().length;\n toolbar.querySelector('.move-up').disabled = index <= 0;\n toolbar.querySelector('.move-down').disabled = index >= total - 1;\n }\n\n function hideToolbar() {\n toolbarVisible = false;\n toolbar.classList.remove('cms-toolbar-visible');\n }\n\n function showCursor(x, y) {\n cursor.style.top = y + 'px';\n cursor.style.left = x + 'px';\n cursor.classList.add('cms-cursor-visible');\n }\n\n function hideCursor() {\n cursor.classList.remove('cms-cursor-visible');\n }\n\n document.addEventListener('mouseover', function(e) {\n if (toolbarVisible) return;\n var block = e.target.closest('[data-cms-block]');\n if (block) {\n updateOutline(block, outline);\n }\n });\n\n document.addEventListener('mouseout', function(e) {\n var block = e.target.closest('[data-cms-block]');\n var related = e.relatedTarget ? e.relatedTarget.closest('[data-cms-block]') : null;\n if (block && block !== related) {\n outline.style.display = 'none';\n hideCursor();\n }\n });\n\n document.addEventListener('mousemove', function(e) {\n if (toolbarVisible) return;\n var block = e.target.closest('[data-cms-block]');\n if (block) {\n showCursor(e.clientX, e.clientY);\n }\n });\n\n document.addEventListener('contextmenu', function(e) {\n if (e.target.closest('[data-cms-toolbar]')) return;\n var block = e.target.closest('[data-cms-block]');\n if (block) {\n if (toolbarVisible) return;\n e.preventDefault();\n hideCursor();\n outline.style.display = 'none';\n var blockId = block.getAttribute('data-block-id');\n showToolbar(e.clientX, e.clientY, blockId);\n }\n });\n\n document.addEventListener('click', function(e) {\n if (toolbarVisible && !e.target.closest('[data-cms-toolbar]')) {\n var block = e.target.closest('[data-cms-block]');\n if (!block || block.getAttribute('data-block-id') !== currentBlockId) {\n hideToolbar();\n }\n }\n\n if (e.target.closest('[data-cms-toolbar]')) return;\n\n var editable = e.target.closest('[data-cms-editable]');\n if (editable) {\n postToParent({\n type: 'cms-editable-click',\n blockId: editable.getAttribute('data-block-id'),\n blockType: editable.getAttribute('data-block-type'),\n contentPath: editable.getAttribute('data-content-path')\n });\n return;\n }\n\n var block = e.target.closest('[data-cms-block]');\n if (block) {\n postToParent({\n type: 'cms-editable-click',\n blockId: block.getAttribute('data-block-id'),\n blockType: block.getAttribute('data-block-type'),\n contentPath: null\n });\n }\n });\n\n toolbar.querySelector('.move-up').addEventListener('click', function() {\n if (!currentBlockId) return;\n postToParent({ type: 'cms-block-move', blockId: currentBlockId, direction: 'up' });\n hideToolbar();\n });\n\n toolbar.querySelector('.move-down').addEventListener('click', function() {\n if (!currentBlockId) return;\n postToParent({ type: 'cms-block-move', blockId: currentBlockId, direction: 'down' });\n hideToolbar();\n });\n\n toolbar.querySelector('.delete').addEventListener('click', function() {\n if (!currentBlockId) return;\n postToParent({ type: 'cms-block-delete', blockId: currentBlockId });\n hideToolbar();\n });\n\n window.addEventListener('scroll', function() {\n hideCursor();\n hideToolbar();\n if (selectedBlockId) {\n var el = getBlockElement(selectedBlockId);\n updateOutline(el, selectedOutline);\n }\n }, { passive: true, capture: true });\n\n window.addEventListener('resize', function() {\n if (selectedBlockId) {\n var el = getBlockElement(selectedBlockId);\n updateOutline(el, selectedOutline);\n }\n }, { passive: true });\n\n window.addEventListener('message', function(e) {\n if (CMS_PARENT_ORIGIN && e.origin !== CMS_PARENT_ORIGIN) return;\n if (e.source !== window.parent) return;\n\n if (e.data && e.data.type === 'cms-select-block') {\n selectedBlockId = e.data.blockId || null;\n if (selectedBlockId) {\n var el = getBlockElement(selectedBlockId);\n updateOutline(el, selectedOutline);\n } else {\n selectedOutline.style.display = 'none';\n }\n }\n });\n})();\n`;\n}\n","/**\n * Trusted-origin helpers for CMS template-builder postMessage traffic\n * between the admin UI (parent) and the site preview iframe (child).\n */\n\nexport const CMS_PARENT_ORIGIN_PARAM = 'cms_parent_origin';\n\nexport function parseOrigin(url: string | undefined): string | null {\n if (!url) return null;\n try {\n return new URL(url).origin;\n } catch {\n return null;\n }\n}\n\nfunction getParentOriginFromQueryParam(): string | null {\n if (typeof window === 'undefined') return null;\n const value = new URLSearchParams(window.location.search).get(CMS_PARENT_ORIGIN_PARAM);\n return parseOrigin(value ?? undefined);\n}\n\nfunction getReferrerOrigin(): string | null {\n if (typeof document === 'undefined' || !document.referrer) return null;\n return parseOrigin(document.referrer);\n}\n\n/** Same-origin embed (e.g. proxied admin + preview on the customer domain). */\nfunction getSameOriginParentOrigin(): string | null {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) {\n return null;\n }\n try {\n return window.parent.location.origin;\n } catch {\n return null;\n }\n}\n\n/** Origins allowed to send messages to the preview iframe (CMS admin hosts). */\nexport function getAllowedCmsParentOrigins(explicitParentOrigin?: string): string[] {\n const origins = new Set<string>();\n const apiOrigin = parseOrigin(process.env.NEXT_PUBLIC_CMS_API_URL);\n if (apiOrigin) origins.add(apiOrigin);\n\n const fromQuery = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromQuery) origins.add(fromQuery);\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) origins.add(referrerOrigin);\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) origins.add(sameOriginParent);\n\n return [...origins];\n}\n\n/**\n * Target origin when posting from the preview iframe to the CMS parent.\n *\n * When the admin is proxied on a customer domain, the parent window origin is\n * the customer site — not NEXT_PUBLIC_CMS_API_URL. Prefer explicit/referrer/\n * same-origin parent detection over the CMS API URL.\n */\nexport function getCmsParentTargetOrigin(\n preferredCmsUrl?: string,\n explicitParentOrigin?: string\n): string | null {\n const fromExplicit = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromExplicit) return fromExplicit;\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) return referrerOrigin;\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) return sameOriginParent;\n\n const preferredOrigin = parseOrigin(preferredCmsUrl);\n if (preferredOrigin) return preferredOrigin;\n\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n return allowed[0] ?? null;\n}\n\nexport function isTrustedCmsParentMessage(\n event: MessageEvent,\n explicitParentOrigin?: string\n): boolean {\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n if (allowed.length === 0) return false;\n if (!allowed.includes(event.origin)) return false;\n return event.source === window.parent;\n}\n\nexport function postMessageToCmsParent(\n message: unknown,\n options?: { preferredCmsUrl?: string; explicitParentOrigin?: string }\n): void {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) return;\n const targetOrigin = getCmsParentTargetOrigin(\n options?.preferredCmsUrl,\n options?.explicitParentOrigin\n );\n if (!targetOrigin) return;\n window.parent.postMessage(message, targetOrigin);\n}\n"],"mappings":";AAOA,OAAO,WAAW;;;ACQX,SAAS,yBAAyB,iBAAiC;AACxE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA,4BAKmB,KAAK,UAAU,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AO,KAAK,QAAQ,GAAG;AACvC,UAAI,CAAC,IAAI,WAAW,GAAG,EAAG;AAC1B,YAAM,WAAW,IAAI,QAAQ,GAAG;AAChC,UAAI,aAAa,GAAI;AACrB,YAAM,cAAc,IAAI,MAAM,GAAG,QAAQ;AACzC,YAAM,iBAAiB,IAAI,MAAM,WAAW,CAAC;AAC7C,UAAI,mBAAmB,UAAW;AAClC,UAAI,mBAAmB,MAAM,WAAW,GAAG;AACzC,eAAO,SAAS,GAAG;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACA,SAAO,SAAS,SAAS;AAC3B;AAgBO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuB;AACrB,QAAM,YAAY,iBAAiB,UAAU,MAAM,MAAM,IAAI;AAE7D,MAAI,CAAC,WAAW;AAEd,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,uCAAuC,MAAM,IAAI,EAAE;AAAA,IAClE;AACA,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,cACb,OAAO,OAAO,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,eAAe,UAAU,GAAG,QACrE;AAEJ,QAAM,YACJ,oBAAC,aAAU,SAAS,MAAM,SAAS,aAA0B,UAAoB;AAGnF,MAAI,iBAAiB;AACnB,WAAO;AAAA,EACT;AAEA,SACE,iCACE;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,qBAAkB;AAAA,QAClB,iBAAe,MAAM;AAAA,QACrB,mBAAiB,MAAM;AAAA,QACvB,OAAO,EAAE,SAAS,OAAO;AAAA,QACzB,eAAY;AAAA;AAAA,IACd;AAAA,IACC;AAAA,KACH;AAEJ;","names":[]}
|
|
@@ -17,11 +17,14 @@ interface ClientEditableBlockProps {
|
|
|
17
17
|
* On mount, finds the component's root element via nextElementSibling and:
|
|
18
18
|
* - Stamps data-cms-block, data-block-id, data-block-type directly on it
|
|
19
19
|
* - Injects data-cms-editable spans around matching text nodes
|
|
20
|
-
* - Portals the BlockToolbar into
|
|
21
|
-
* never clipped by overflow:hidden or stacking contexts on the block
|
|
20
|
+
* - Portals the BlockToolbar into a dedicated overlay root with position:fixed
|
|
21
|
+
* so it is never clipped by overflow:hidden or stacking contexts on the block
|
|
22
22
|
*
|
|
23
23
|
* Uses a MutationObserver to re-inject spans after every DOM mutation
|
|
24
24
|
* (e.g. animated state changes that swap visible elements).
|
|
25
|
+
*
|
|
26
|
+
* The overlay root (#cms-overlay-root) is created lazily on first mount to ensure
|
|
27
|
+
* compatibility with both Next.js and TanStack Start's streaming SSR hydration.
|
|
25
28
|
*/
|
|
26
29
|
declare function ClientEditableBlock({ blockId, blockType, contentEntries, children, }: ClientEditableBlockProps): react.JSX.Element;
|
|
27
30
|
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
4
|
// lib/client-editable-block.tsx
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useLayoutEffect as useLayoutEffectBase,
|
|
9
|
+
useRef as useRef2,
|
|
10
|
+
useState
|
|
11
|
+
} from "react";
|
|
6
12
|
import { createPortal } from "react-dom";
|
|
7
13
|
|
|
8
14
|
// lib/block-outline.tsx
|
|
@@ -185,9 +191,23 @@ var BlockToolbar = forwardRef(function BlockToolbar2({ blockId }, ref) {
|
|
|
185
191
|
|
|
186
192
|
// lib/client-editable-block.tsx
|
|
187
193
|
import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
194
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffectBase : useEffect;
|
|
195
|
+
var CMS_OVERLAY_ROOT_ID = "cms-overlay-root";
|
|
188
196
|
var CMS_STYLES = `
|
|
189
197
|
[data-cms-editable] { cursor: pointer; border-radius: 2px; }
|
|
190
198
|
[data-cms-editable]:hover { outline: 2px solid #3b82f6; outline-offset: 2px; }
|
|
199
|
+
#${CMS_OVERLAY_ROOT_ID} {
|
|
200
|
+
position: fixed;
|
|
201
|
+
top: 0;
|
|
202
|
+
left: 0;
|
|
203
|
+
width: 0;
|
|
204
|
+
height: 0;
|
|
205
|
+
pointer-events: none;
|
|
206
|
+
z-index: 99998;
|
|
207
|
+
}
|
|
208
|
+
#${CMS_OVERLAY_ROOT_ID} > * {
|
|
209
|
+
pointer-events: auto;
|
|
210
|
+
}
|
|
191
211
|
.cms-block-cursor {
|
|
192
212
|
position: fixed; width: 22px; height: 22px;
|
|
193
213
|
background: radial-gradient(circle, #fff 5px, #000 5px);
|
|
@@ -221,13 +241,31 @@ var CMS_STYLES = `
|
|
|
221
241
|
.cms-block-toolbar svg { width: 16px; height: 16px; }
|
|
222
242
|
`;
|
|
223
243
|
var cmsGlobalInjected = false;
|
|
244
|
+
var cmsOverlayRoot = null;
|
|
245
|
+
function getCmsOverlayRoot() {
|
|
246
|
+
if (typeof document === "undefined" || !document.body) return null;
|
|
247
|
+
if (cmsOverlayRoot && document.contains(cmsOverlayRoot)) {
|
|
248
|
+
return cmsOverlayRoot;
|
|
249
|
+
}
|
|
250
|
+
let root = document.getElementById(CMS_OVERLAY_ROOT_ID);
|
|
251
|
+
if (!root) {
|
|
252
|
+
root = document.createElement("div");
|
|
253
|
+
root.id = CMS_OVERLAY_ROOT_ID;
|
|
254
|
+
document.body.appendChild(root);
|
|
255
|
+
}
|
|
256
|
+
cmsOverlayRoot = root;
|
|
257
|
+
return root;
|
|
258
|
+
}
|
|
224
259
|
function ensureCmsGlobals() {
|
|
225
260
|
if (cmsGlobalInjected) return;
|
|
261
|
+
if (typeof document === "undefined" || typeof window === "undefined") return;
|
|
226
262
|
cmsGlobalInjected = true;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
263
|
+
if (document.head) {
|
|
264
|
+
const style = document.createElement("style");
|
|
265
|
+
style.setAttribute("data-cms", "");
|
|
266
|
+
style.textContent = CMS_STYLES;
|
|
267
|
+
document.head.appendChild(style);
|
|
268
|
+
}
|
|
231
269
|
if (!window.__cmsEditableInitialized) {
|
|
232
270
|
window.__cmsEditableInitialized = true;
|
|
233
271
|
document.addEventListener("click", (e) => {
|
|
@@ -334,9 +372,12 @@ function ClientEditableBlock({
|
|
|
334
372
|
}
|
|
335
373
|
}, [blockId, blockType, contentEntries, getBlockRoot]);
|
|
336
374
|
useEffect(() => {
|
|
375
|
+
if (process.env.NODE_ENV === "development") {
|
|
376
|
+
console.log("[CMS] ClientEditableBlock mounted", { blockId, blockType });
|
|
377
|
+
}
|
|
337
378
|
setMounted(true);
|
|
338
|
-
}, []);
|
|
339
|
-
|
|
379
|
+
}, [blockId, blockType]);
|
|
380
|
+
useIsomorphicLayoutEffect(() => {
|
|
340
381
|
ensureCmsGlobals();
|
|
341
382
|
const blockRoot = getBlockRoot();
|
|
342
383
|
if (!blockRoot) return;
|
|
@@ -438,15 +479,16 @@ function ClientEditableBlock({
|
|
|
438
479
|
window.removeEventListener("message", handleWindowMessage);
|
|
439
480
|
};
|
|
440
481
|
}, [injectSpans, blockId, blockType, getBlockRoot]);
|
|
482
|
+
const portalRoot = mounted ? getCmsOverlayRoot() : null;
|
|
441
483
|
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
442
484
|
/* @__PURE__ */ jsx3("span", { ref: sentinelRef, style: { display: "none" }, "aria-hidden": true }),
|
|
443
485
|
children,
|
|
444
|
-
|
|
486
|
+
portalRoot && (selectedOutlineRect ?? hoverOutlineRect) && createPortal(
|
|
445
487
|
/* @__PURE__ */ jsx3(BlockOutline, { blockRect: selectedOutlineRect ?? hoverOutlineRect }),
|
|
446
|
-
|
|
488
|
+
portalRoot
|
|
447
489
|
),
|
|
448
|
-
|
|
449
|
-
|
|
490
|
+
portalRoot && createPortal(/* @__PURE__ */ jsx3("div", { ref: cursorElRef, className: "cms-block-cursor" }), portalRoot),
|
|
491
|
+
portalRoot && createPortal(/* @__PURE__ */ jsx3(BlockToolbar, { ref: toolbarElRef, blockId }), portalRoot)
|
|
450
492
|
] });
|
|
451
493
|
}
|
|
452
494
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/client-editable-block.tsx","../../lib/block-outline.tsx","../../lib/block-toolbar.tsx","../../lib/cms-post-message.ts"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { BlockOutline } from './block-outline';\nimport { BlockToolbar } from './block-toolbar';\nimport { isTrustedCmsParentMessage, postMessageToCmsParent } from './cms-post-message';\n\n// ---------------------------------------------------------------------------\n// Global styles + click-routing — injected once into <head> on first mount.\n// We do this programmatically because Next.js RSC marks body-level <style> and\n// <script> tags as inactive (they appear greyed-out in DevTools and are not\n// applied by the browser).\n// ---------------------------------------------------------------------------\n\nconst CMS_STYLES = `\n [data-cms-editable] { cursor: pointer; border-radius: 2px; }\n [data-cms-editable]:hover { outline: 2px solid #3b82f6; outline-offset: 2px; }\n .cms-block-cursor {\n position: fixed; width: 22px; height: 22px;\n background: radial-gradient(circle, #fff 5px, #000 5px);\n border-radius: 50%;\n pointer-events: none; z-index: 99999;\n transform: translate(-50%, -50%);\n opacity: 0; transition: opacity 0.1s ease;\n }\n .cms-block-cursor.cms-cursor-visible { opacity: 1; }\n .cms-block-toolbar {\n position: fixed;\n display: flex; gap: 4px; background: #1f2937; border-radius: 6px; padding: 4px;\n box-shadow: 0 4px 12px rgba(0,0,0,0.25);\n z-index: 99999; pointer-events: none;\n opacity: 0; transform: scale(0.9) translateY(4px);\n transition: opacity 0.15s ease, transform 0.15s ease;\n }\n .cms-block-toolbar.cms-toolbar-visible {\n opacity: 1; transform: scale(1) translateY(0); pointer-events: auto;\n }\n .cms-block-toolbar button {\n display: flex; align-items: center; justify-content: center;\n width: 28px; height: 28px; border: none; background: transparent;\n color: #9ca3af; border-radius: 4px; cursor: pointer;\n transition: background 0.15s ease, color 0.15s ease;\n }\n .cms-block-toolbar button:hover { background: #374151; color: #fff; }\n .cms-block-toolbar button.delete:hover { background: #dc2626; color: #fff; }\n .cms-block-toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }\n .cms-block-toolbar button:disabled:hover { background: transparent; color: #9ca3af; }\n .cms-block-toolbar svg { width: 16px; height: 16px; }\n`;\n\nlet cmsGlobalInjected = false;\n\nfunction ensureCmsGlobals() {\n if (cmsGlobalInjected) return;\n cmsGlobalInjected = true;\n\n const style = document.createElement('style');\n style.setAttribute('data-cms', '');\n style.textContent = CMS_STYLES;\n document.head.appendChild(style);\n\n if (!(window as Window & { __cmsEditableInitialized?: boolean }).__cmsEditableInitialized) {\n (window as Window & { __cmsEditableInitialized?: boolean }).__cmsEditableInitialized = true;\n document.addEventListener('click', (e) => {\n const target = e.target as Element;\n if (target.closest('.cms-block-toolbar')) return;\n\n const editable = target.closest('[data-cms-editable]');\n if (editable) {\n const msg = {\n type: 'cms-editable-click',\n blockId: editable.getAttribute('data-block-id'),\n blockType: editable.getAttribute('data-block-type'),\n contentPath: editable.getAttribute('data-content-path'),\n };\n postMessageToCmsParent(msg);\n return;\n }\n\n const block = target.closest('[data-cms-block]');\n if (block) {\n const msg = {\n type: 'cms-editable-click',\n blockId: block.getAttribute('data-block-id'),\n blockType: block.getAttribute('data-block-type'),\n contentPath: null,\n };\n postMessageToCmsParent(msg);\n }\n });\n }\n}\n\ninterface ContentEntry {\n v: string;\n p: string;\n}\n\ninterface ClientEditableBlockProps {\n blockId: string;\n blockType: string;\n contentEntries: ContentEntry[];\n children: React.ReactNode;\n}\n\n/**\n * Client-side block editable wrapper.\n *\n * Renders a hidden sentinel span followed by the block's children (no wrapper div).\n * On mount, finds the component's root element via nextElementSibling and:\n * - Stamps data-cms-block, data-block-id, data-block-type directly on it\n * - Injects data-cms-editable spans around matching text nodes\n * - Portals the BlockToolbar into document.body with position:fixed so it is\n * never clipped by overflow:hidden or stacking contexts on the block itself\n *\n * Uses a MutationObserver to re-inject spans after every DOM mutation\n * (e.g. animated state changes that swap visible elements).\n */\nexport function ClientEditableBlock({\n blockId,\n blockType,\n contentEntries,\n children,\n}: ClientEditableBlockProps) {\n const sentinelRef = useRef<HTMLSpanElement>(null);\n const observerRef = useRef<MutationObserver | null>(null);\n const isInjectingRef = useRef(false);\n const cursorElRef = useRef<HTMLDivElement>(null);\n const toolbarElRef = useRef<HTMLDivElement>(null);\n const toolbarVisibleRef = useRef(false);\n const [mounted, setMounted] = useState(false);\n const [hoverOutlineRect, setHoverOutlineRect] = useState<DOMRect | null>(null);\n const [selectedOutlineRect, setSelectedOutlineRect] = useState<DOMRect | null>(null);\n\n const getBlockRoot = useCallback((): HTMLElement | null => {\n return (sentinelRef.current?.nextElementSibling as HTMLElement) ?? null;\n }, []);\n\n const injectSpans = useCallback(() => {\n if (isInjectingRef.current) return;\n const blockRoot = getBlockRoot();\n if (!blockRoot) return;\n\n isInjectingRef.current = true;\n // Disconnect observer while we mutate the DOM to avoid re-entrant calls.\n observerRef.current?.disconnect();\n\n try {\n // Remove previously injected text-level spans, restoring the original text nodes.\n const existing = Array.from(\n blockRoot.querySelectorAll<HTMLElement>('span[data-cms-editable][data-content-path]')\n );\n for (const span of existing) {\n const parent = span.parentNode;\n if (!parent) continue;\n while (span.firstChild) parent.insertBefore(span.firstChild, span);\n parent.removeChild(span);\n }\n\n // Walk all visible text nodes and wrap the ones that match content values.\n const used = new Set<string>();\n const walker = document.createTreeWalker(blockRoot, NodeFilter.SHOW_TEXT, null);\n const textNodes: Text[] = [];\n let n = walker.nextNode();\n while (n !== null) {\n const textNode = n as Text;\n if (\n textNode.parentElement?.closest('.cms-block-toolbar') == null &&\n textNode.nodeValue?.trim()\n ) {\n textNodes.push(textNode);\n }\n n = walker.nextNode();\n }\n\n for (const textNode of textNodes) {\n // Never inject spans inside SVG — <span> is not valid SVG content\n if (textNode.parentElement?.closest('svg') != null) continue;\n\n const text = textNode.nodeValue;\n if (!text) continue;\n for (const entry of contentEntries) {\n if (used.has(entry.p)) continue;\n if (text.indexOf(entry.v) !== -1 && text.trim() === entry.v.trim()) {\n used.add(entry.p);\n const span = document.createElement('span');\n span.setAttribute('data-cms-editable', '');\n span.setAttribute('data-block-id', blockId);\n span.setAttribute('data-block-type', blockType);\n span.setAttribute('data-content-path', entry.p);\n textNode.parentNode?.insertBefore(span, textNode);\n span.appendChild(textNode);\n break;\n }\n }\n }\n } finally {\n isInjectingRef.current = false;\n // Reconnect after our mutations are done.\n const root = getBlockRoot();\n if (root && observerRef.current) {\n observerRef.current.observe(root, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n }\n }\n }, [blockId, blockType, contentEntries, getBlockRoot]);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n useLayoutEffect(() => {\n ensureCmsGlobals();\n\n const blockRoot = getBlockRoot();\n if (!blockRoot) return;\n\n // Stamp CMS attributes directly on the component's root element.\n blockRoot.setAttribute('data-cms-block', '');\n blockRoot.setAttribute('data-block-id', blockId);\n blockRoot.setAttribute('data-block-type', blockType);\n\n // Position toolbar at (x, y) without animating the placement itself —\n // suppress top/left transitions for the instant snap, then restore.\n const positionToolbar = (x: number, y: number) => {\n const el = toolbarElRef.current;\n if (!el) return;\n const { width: tw, height: th } = el.getBoundingClientRect();\n const top = Math.max(4, y - th - 12);\n const left = Math.max(4, Math.min(x - tw / 2, window.innerWidth - tw - 4));\n el.style.transition = 'opacity 0.15s ease, transform 0.15s ease';\n el.style.top = `${top}px`;\n el.style.left = `${left}px`;\n };\n\n const refreshSelectedOutline = () => {\n setSelectedOutlineRect((current) => (current ? blockRoot.getBoundingClientRect() : current));\n };\n\n // Cursor circle follows the mouse to indicate the block is interactive.\n const showCursor = (e: MouseEvent) => {\n if (toolbarVisibleRef.current) return;\n setHoverOutlineRect(blockRoot.getBoundingClientRect());\n const el = cursorElRef.current;\n if (!el) return;\n el.style.top = `${e.clientY}px`;\n el.style.left = `${e.clientX}px`;\n el.classList.add('cms-cursor-visible');\n };\n const moveCursor = (e: MouseEvent) => {\n if (toolbarVisibleRef.current) return;\n const el = cursorElRef.current;\n if (!el) return;\n el.style.top = `${e.clientY}px`;\n el.style.left = `${e.clientX}px`;\n };\n const hideCursor = () => {\n cursorElRef.current?.classList.remove('cms-cursor-visible');\n setHoverOutlineRect(null);\n };\n\n // On right-click: first time suppresses the browser context menu and shows\n // the CMS toolbar instead. If the toolbar is already visible the event is\n // not prevented so the browser's native context menu opens as a fallback.\n const handleContextMenu = (e: MouseEvent) => {\n if ((e.target as Element).closest('[data-cms-toolbar]')) return;\n if (toolbarVisibleRef.current) return; // fall through to browser context menu\n e.preventDefault();\n hideCursor();\n positionToolbar(e.clientX, e.clientY);\n toolbarVisibleRef.current = true;\n toolbarElRef.current?.classList.add('cms-toolbar-visible');\n };\n\n // Dismiss toolbar when clicking outside this block or its toolbar.\n const handleClickOutside = (e: MouseEvent) => {\n if (!toolbarVisibleRef.current) return;\n const target = e.target as Element;\n if (target.closest('[data-cms-toolbar]')) return;\n if (blockRoot.contains(target)) return;\n toolbarElRef.current?.classList.remove('cms-toolbar-visible');\n toolbarVisibleRef.current = false;\n };\n\n const hideOnScroll = () => {\n hideCursor();\n toolbarElRef.current?.classList.remove('cms-toolbar-visible');\n toolbarVisibleRef.current = false;\n refreshSelectedOutline();\n };\n\n const handleWindowMessage = (event: MessageEvent) => {\n if (!isTrustedCmsParentMessage(event)) return;\n if (event.data?.type !== 'cms-select-block') return;\n const selectedBlockId = typeof event.data.blockId === 'string' ? event.data.blockId : null;\n if (selectedBlockId === blockId) {\n setSelectedOutlineRect(blockRoot.getBoundingClientRect());\n } else {\n setSelectedOutlineRect(null);\n }\n };\n\n blockRoot.addEventListener('mouseenter', showCursor);\n blockRoot.addEventListener('mousemove', moveCursor);\n blockRoot.addEventListener('mouseleave', hideCursor);\n blockRoot.addEventListener('contextmenu', handleContextMenu);\n document.addEventListener('click', handleClickOutside);\n window.addEventListener('scroll', hideOnScroll, { passive: true, capture: true });\n window.addEventListener('resize', refreshSelectedOutline, { passive: true });\n window.addEventListener('message', handleWindowMessage);\n\n // Initial span injection after React's first commit.\n injectSpans();\n\n // Re-inject whenever the child component mutates the DOM.\n const observer = new MutationObserver(injectSpans);\n observerRef.current = observer;\n observer.observe(blockRoot, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n return () => {\n observer.disconnect();\n observerRef.current = null;\n blockRoot.removeEventListener('mouseenter', showCursor);\n blockRoot.removeEventListener('mousemove', moveCursor);\n blockRoot.removeEventListener('mouseleave', hideCursor);\n blockRoot.removeEventListener('contextmenu', handleContextMenu);\n document.removeEventListener('click', handleClickOutside);\n window.removeEventListener('scroll', hideOnScroll, { capture: true });\n window.removeEventListener('resize', refreshSelectedOutline);\n window.removeEventListener('message', handleWindowMessage);\n };\n }, [injectSpans, blockId, blockType, getBlockRoot]);\n\n return (\n <>\n <span ref={sentinelRef} style={{ display: 'none' }} aria-hidden />\n {children}\n {mounted &&\n (selectedOutlineRect ?? hoverOutlineRect) &&\n createPortal(\n <BlockOutline blockRect={(selectedOutlineRect ?? hoverOutlineRect) as DOMRect} />,\n document.body\n )}\n {mounted &&\n createPortal(<div ref={cursorElRef} className=\"cms-block-cursor\" />, document.body)}\n {mounted &&\n createPortal(<BlockToolbar ref={toolbarElRef} blockId={blockId} />, document.body)}\n </>\n );\n}\n","'use client';\n\nimport { useLayoutEffect, useRef } from 'react';\n\n/**\n * Block Outline Component\n *\n * Renders a position:fixed border overlay around a hovered block.\n * Tries up to 3 offset values (4px → 0px → -2px inset) to keep every\n * edge of the border visible inside the viewport before giving up.\n */\nexport function BlockOutline({ blockRect }: { blockRect: DOMRect }) {\n const outlineRef = useRef<HTMLDivElement>(null);\n\n useLayoutEffect(() => {\n const el = outlineRef.current;\n if (!el) return;\n\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n\n // Attempt progressively smaller offsets until the border is fully visible.\n // offset=4 → normal outline-offset feel\n // offset=0 → border flush with block edge\n // offset=-2 → border drawn inside the block (inset)\n const offsets = [4, 0, -2];\n\n for (const offset of offsets) {\n const pad = offset + 2; // 2px border + offset\n el.style.top = `${blockRect.top - pad}px`;\n el.style.left = `${blockRect.left - pad}px`;\n el.style.width = `${blockRect.width + pad * 2}px`;\n el.style.height = `${blockRect.height + pad * 2}px`;\n\n const rect = el.getBoundingClientRect();\n if (rect.top >= 0 && rect.left >= 0 && rect.right <= vw && rect.bottom <= vh) break;\n }\n }, [blockRect]);\n\n return (\n <div\n ref={outlineRef}\n data-cms-outline=\"true\"\n style={{\n position: 'fixed',\n border: '2px solid #3b82f6',\n borderRadius: '2px',\n pointerEvents: 'none',\n zIndex: 99998,\n boxSizing: 'border-box',\n }}\n />\n );\n}\n","'use client';\n\nimport { ChevronDownIcon, ChevronUpIcon, PlusIcon, TrashIcon } from '@heroicons/react/24/outline';\nimport { forwardRef } from 'react';\nimport { postMessageToCmsParent } from './cms-post-message';\n\n/**\n * Block Toolbar Component\n *\n * Provides move up/down and delete controls for blocks in edit mode.\n * Position is managed imperatively by the parent via a forwarded ref —\n * the toolbar follows the mouse cursor and has no internal layout logic.\n */\n\nexport const BlockToolbar = forwardRef<HTMLDivElement, { blockId: string }>(function BlockToolbar(\n { blockId },\n ref\n) {\n const handleAction = (action: string) => {\n postMessageToCmsParent({ type: 'cms-block-action', action, blockId });\n };\n\n return (\n <div ref={ref} className=\"cms-block-toolbar\" data-cms-toolbar=\"true\">\n <button\n type=\"button\"\n title=\"Move up\"\n aria-label=\"Move up\"\n data-action=\"move-up\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('move-up');\n }}\n >\n <ChevronUpIcon />\n </button>\n <button\n type=\"button\"\n title=\"Move down\"\n aria-label=\"Move down\"\n data-action=\"move-down\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('move-down');\n }}\n >\n <ChevronDownIcon />\n </button>\n <button\n type=\"button\"\n title=\"Add block\"\n aria-label=\"Add block\"\n data-action=\"add-block\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('add-block');\n }}\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n className=\"delete\"\n title=\"Delete block\"\n aria-label=\"Delete block\"\n data-action=\"delete\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('delete');\n }}\n >\n <TrashIcon />\n </button>\n </div>\n );\n});\n","/**\n * Trusted-origin helpers for CMS template-builder postMessage traffic\n * between the admin UI (parent) and the site preview iframe (child).\n */\n\nexport const CMS_PARENT_ORIGIN_PARAM = 'cms_parent_origin';\n\nexport function parseOrigin(url: string | undefined): string | null {\n if (!url) return null;\n try {\n return new URL(url).origin;\n } catch {\n return null;\n }\n}\n\nfunction getParentOriginFromQueryParam(): string | null {\n if (typeof window === 'undefined') return null;\n const value = new URLSearchParams(window.location.search).get(CMS_PARENT_ORIGIN_PARAM);\n return parseOrigin(value ?? undefined);\n}\n\nfunction getReferrerOrigin(): string | null {\n if (typeof document === 'undefined' || !document.referrer) return null;\n return parseOrigin(document.referrer);\n}\n\n/** Same-origin embed (e.g. proxied admin + preview on the customer domain). */\nfunction getSameOriginParentOrigin(): string | null {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) {\n return null;\n }\n try {\n return window.parent.location.origin;\n } catch {\n return null;\n }\n}\n\n/** Origins allowed to send messages to the preview iframe (CMS admin hosts). */\nexport function getAllowedCmsParentOrigins(explicitParentOrigin?: string): string[] {\n const origins = new Set<string>();\n const apiOrigin = parseOrigin(process.env.NEXT_PUBLIC_CMS_API_URL);\n if (apiOrigin) origins.add(apiOrigin);\n\n const fromQuery = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromQuery) origins.add(fromQuery);\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) origins.add(referrerOrigin);\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) origins.add(sameOriginParent);\n\n return [...origins];\n}\n\n/**\n * Target origin when posting from the preview iframe to the CMS parent.\n *\n * When the admin is proxied on a customer domain, the parent window origin is\n * the customer site — not NEXT_PUBLIC_CMS_API_URL. Prefer explicit/referrer/\n * same-origin parent detection over the CMS API URL.\n */\nexport function getCmsParentTargetOrigin(\n preferredCmsUrl?: string,\n explicitParentOrigin?: string\n): string | null {\n const fromExplicit = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromExplicit) return fromExplicit;\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) return referrerOrigin;\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) return sameOriginParent;\n\n const preferredOrigin = parseOrigin(preferredCmsUrl);\n if (preferredOrigin) return preferredOrigin;\n\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n return allowed[0] ?? null;\n}\n\nexport function isTrustedCmsParentMessage(\n event: MessageEvent,\n explicitParentOrigin?: string\n): boolean {\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n if (allowed.length === 0) return false;\n if (!allowed.includes(event.origin)) return false;\n return event.source === window.parent;\n}\n\nexport function postMessageToCmsParent(\n message: unknown,\n options?: { preferredCmsUrl?: string; explicitParentOrigin?: string }\n): void {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) return;\n const targetOrigin = getCmsParentTargetOrigin(\n options?.preferredCmsUrl,\n options?.explicitParentOrigin\n );\n if (!targetOrigin) return;\n window.parent.postMessage(message, targetOrigin);\n}\n"],"mappings":";;;;AAEA,SAAS,aAAa,WAAW,mBAAAA,kBAAiB,UAAAC,SAAQ,gBAAgB;AAC1E,SAAS,oBAAoB;;;ACD7B,SAAS,iBAAiB,cAAc;AAsCpC;AA7BG,SAAS,aAAa,EAAE,UAAU,GAA2B;AAClE,QAAM,aAAa,OAAuB,IAAI;AAE9C,kBAAgB,MAAM;AACpB,UAAM,KAAK,WAAW;AACtB,QAAI,CAAC,GAAI;AAET,UAAM,KAAK,OAAO;AAClB,UAAM,KAAK,OAAO;AAMlB,UAAM,UAAU,CAAC,GAAG,GAAG,EAAE;AAEzB,eAAW,UAAU,SAAS;AAC5B,YAAM,MAAM,SAAS;AACrB,SAAG,MAAM,M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AoB,aAAa,UAAU;AACrD,gBAAU,oBAAoB,cAAc,UAAU;AACtD,gBAAU,oBAAoB,eAAe,iBAAiB;AAC9D,eAAS,oBAAoB,SAAS,kBAAkB;AACxD,aAAO,oBAAoB,UAAU,cAAc,EAAE,SAAS,KAAK,CAAC;AACpE,aAAO,oBAAoB,UAAU,sBAAsB;AAC3D,aAAO,oBAAoB,WAAW,mBAAmB;AAAA,IAC3D;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,WAAW,YAAY,CAAC;AAElD,SACE,gBAAAF,MAAA,YACE;AAAA,oBAAAD,KAAC,UAAK,KAAK,aAAa,OAAO,EAAE,SAAS,OAAO,GAAG,eAAW,MAAC;AAAA,IAC/D;AAAA,IACA,YACE,uBAAuB,qBACxB;AAAA,MACE,gBAAAA,KAAC,gBAAa,WAAY,uBAAuB,kBAA8B;AAAA,MAC/E,SAAS;AAAA,IACX;AAAA,IACD,WACC,aAAa,gBAAAA,KAAC,SAAI,KAAK,aAAa,WAAU,oBAAmB,GAAI,SAAS,IAAI;AAAA,IACnF,WACC,aAAa,gBAAAA,KAAC,gBAAa,KAAK,cAAc,SAAkB,GAAI,SAAS,IAAI;AAAA,KACrF;AAEJ;","names":["useLayoutEffect","useRef","jsx","BlockToolbar","jsx","jsxs","useRef","useLayoutEffect"]}
|
|
1
|
+
{"version":3,"sources":["../../lib/client-editable-block.tsx","../../lib/block-outline.tsx","../../lib/block-toolbar.tsx","../../lib/cms-post-message.ts"],"sourcesContent":["'use client';\n\nimport {\n useCallback,\n useEffect,\n useLayoutEffect as useLayoutEffectBase,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { BlockOutline } from './block-outline';\nimport { BlockToolbar } from './block-toolbar';\nimport { isTrustedCmsParentMessage, postMessageToCmsParent } from './cms-post-message';\n\n// Use useEffect as fallback for useLayoutEffect during SSR to avoid React warnings.\n// This is safe because the layout effect code only runs on the client anyway.\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffectBase : useEffect;\n\n// ---------------------------------------------------------------------------\n// Global styles + click-routing — injected once into <head> on first mount.\n// We do this programmatically because Next.js RSC marks body-level <style> and\n// <script> tags as inactive (they appear greyed-out in DevTools and are not\n// applied by the browser).\n// ---------------------------------------------------------------------------\n\nconst CMS_OVERLAY_ROOT_ID = 'cms-overlay-root';\n\nconst CMS_STYLES = `\n [data-cms-editable] { cursor: pointer; border-radius: 2px; }\n [data-cms-editable]:hover { outline: 2px solid #3b82f6; outline-offset: 2px; }\n #${CMS_OVERLAY_ROOT_ID} {\n position: fixed;\n top: 0;\n left: 0;\n width: 0;\n height: 0;\n pointer-events: none;\n z-index: 99998;\n }\n #${CMS_OVERLAY_ROOT_ID} > * {\n pointer-events: auto;\n }\n .cms-block-cursor {\n position: fixed; width: 22px; height: 22px;\n background: radial-gradient(circle, #fff 5px, #000 5px);\n border-radius: 50%;\n pointer-events: none; z-index: 99999;\n transform: translate(-50%, -50%);\n opacity: 0; transition: opacity 0.1s ease;\n }\n .cms-block-cursor.cms-cursor-visible { opacity: 1; }\n .cms-block-toolbar {\n position: fixed;\n display: flex; gap: 4px; background: #1f2937; border-radius: 6px; padding: 4px;\n box-shadow: 0 4px 12px rgba(0,0,0,0.25);\n z-index: 99999; pointer-events: none;\n opacity: 0; transform: scale(0.9) translateY(4px);\n transition: opacity 0.15s ease, transform 0.15s ease;\n }\n .cms-block-toolbar.cms-toolbar-visible {\n opacity: 1; transform: scale(1) translateY(0); pointer-events: auto;\n }\n .cms-block-toolbar button {\n display: flex; align-items: center; justify-content: center;\n width: 28px; height: 28px; border: none; background: transparent;\n color: #9ca3af; border-radius: 4px; cursor: pointer;\n transition: background 0.15s ease, color 0.15s ease;\n }\n .cms-block-toolbar button:hover { background: #374151; color: #fff; }\n .cms-block-toolbar button.delete:hover { background: #dc2626; color: #fff; }\n .cms-block-toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }\n .cms-block-toolbar button:disabled:hover { background: transparent; color: #9ca3af; }\n .cms-block-toolbar svg { width: 16px; height: 16px; }\n`;\n\nlet cmsGlobalInjected = false;\nlet cmsOverlayRoot: HTMLElement | null = null;\n\n/**\n * Returns the CMS overlay portal root element, creating it if necessary.\n * Uses a dedicated container instead of document.body to ensure compatibility\n * with both Next.js and TanStack Start's streaming SSR hydration.\n */\nfunction getCmsOverlayRoot(): HTMLElement | null {\n if (typeof document === 'undefined' || !document.body) return null;\n\n if (cmsOverlayRoot && document.contains(cmsOverlayRoot)) {\n return cmsOverlayRoot;\n }\n\n let root = document.getElementById(CMS_OVERLAY_ROOT_ID);\n if (!root) {\n root = document.createElement('div');\n root.id = CMS_OVERLAY_ROOT_ID;\n document.body.appendChild(root);\n }\n\n cmsOverlayRoot = root;\n return root;\n}\n\nfunction ensureCmsGlobals() {\n if (cmsGlobalInjected) return;\n if (typeof document === 'undefined' || typeof window === 'undefined') return;\n cmsGlobalInjected = true;\n\n if (document.head) {\n const style = document.createElement('style');\n style.setAttribute('data-cms', '');\n style.textContent = CMS_STYLES;\n document.head.appendChild(style);\n }\n\n if (!(window as Window & { __cmsEditableInitialized?: boolean }).__cmsEditableInitialized) {\n (window as Window & { __cmsEditableInitialized?: boolean }).__cmsEditableInitialized = true;\n document.addEventListener('click', (e) => {\n const target = e.target as Element;\n if (target.closest('.cms-block-toolbar')) return;\n\n const editable = target.closest('[data-cms-editable]');\n if (editable) {\n const msg = {\n type: 'cms-editable-click',\n blockId: editable.getAttribute('data-block-id'),\n blockType: editable.getAttribute('data-block-type'),\n contentPath: editable.getAttribute('data-content-path'),\n };\n postMessageToCmsParent(msg);\n return;\n }\n\n const block = target.closest('[data-cms-block]');\n if (block) {\n const msg = {\n type: 'cms-editable-click',\n blockId: block.getAttribute('data-block-id'),\n blockType: block.getAttribute('data-block-type'),\n contentPath: null,\n };\n postMessageToCmsParent(msg);\n }\n });\n }\n}\n\ninterface ContentEntry {\n v: string;\n p: string;\n}\n\ninterface ClientEditableBlockProps {\n blockId: string;\n blockType: string;\n contentEntries: ContentEntry[];\n children: React.ReactNode;\n}\n\n/**\n * Client-side block editable wrapper.\n *\n * Renders a hidden sentinel span followed by the block's children (no wrapper div).\n * On mount, finds the component's root element via nextElementSibling and:\n * - Stamps data-cms-block, data-block-id, data-block-type directly on it\n * - Injects data-cms-editable spans around matching text nodes\n * - Portals the BlockToolbar into a dedicated overlay root with position:fixed\n * so it is never clipped by overflow:hidden or stacking contexts on the block\n *\n * Uses a MutationObserver to re-inject spans after every DOM mutation\n * (e.g. animated state changes that swap visible elements).\n *\n * The overlay root (#cms-overlay-root) is created lazily on first mount to ensure\n * compatibility with both Next.js and TanStack Start's streaming SSR hydration.\n */\nexport function ClientEditableBlock({\n blockId,\n blockType,\n contentEntries,\n children,\n}: ClientEditableBlockProps) {\n const sentinelRef = useRef<HTMLSpanElement>(null);\n const observerRef = useRef<MutationObserver | null>(null);\n const isInjectingRef = useRef(false);\n const cursorElRef = useRef<HTMLDivElement>(null);\n const toolbarElRef = useRef<HTMLDivElement>(null);\n const toolbarVisibleRef = useRef(false);\n const [mounted, setMounted] = useState(false);\n const [hoverOutlineRect, setHoverOutlineRect] = useState<DOMRect | null>(null);\n const [selectedOutlineRect, setSelectedOutlineRect] = useState<DOMRect | null>(null);\n\n const getBlockRoot = useCallback((): HTMLElement | null => {\n return (sentinelRef.current?.nextElementSibling as HTMLElement) ?? null;\n }, []);\n\n const injectSpans = useCallback(() => {\n if (isInjectingRef.current) return;\n const blockRoot = getBlockRoot();\n if (!blockRoot) return;\n\n isInjectingRef.current = true;\n // Disconnect observer while we mutate the DOM to avoid re-entrant calls.\n observerRef.current?.disconnect();\n\n try {\n // Remove previously injected text-level spans, restoring the original text nodes.\n const existing = Array.from(\n blockRoot.querySelectorAll<HTMLElement>('span[data-cms-editable][data-content-path]')\n );\n for (const span of existing) {\n const parent = span.parentNode;\n if (!parent) continue;\n while (span.firstChild) parent.insertBefore(span.firstChild, span);\n parent.removeChild(span);\n }\n\n // Walk all visible text nodes and wrap the ones that match content values.\n const used = new Set<string>();\n const walker = document.createTreeWalker(blockRoot, NodeFilter.SHOW_TEXT, null);\n const textNodes: Text[] = [];\n let n = walker.nextNode();\n while (n !== null) {\n const textNode = n as Text;\n if (\n textNode.parentElement?.closest('.cms-block-toolbar') == null &&\n textNode.nodeValue?.trim()\n ) {\n textNodes.push(textNode);\n }\n n = walker.nextNode();\n }\n\n for (const textNode of textNodes) {\n // Never inject spans inside SVG — <span> is not valid SVG content\n if (textNode.parentElement?.closest('svg') != null) continue;\n\n const text = textNode.nodeValue;\n if (!text) continue;\n for (const entry of contentEntries) {\n if (used.has(entry.p)) continue;\n if (text.indexOf(entry.v) !== -1 && text.trim() === entry.v.trim()) {\n used.add(entry.p);\n const span = document.createElement('span');\n span.setAttribute('data-cms-editable', '');\n span.setAttribute('data-block-id', blockId);\n span.setAttribute('data-block-type', blockType);\n span.setAttribute('data-content-path', entry.p);\n textNode.parentNode?.insertBefore(span, textNode);\n span.appendChild(textNode);\n break;\n }\n }\n }\n } finally {\n isInjectingRef.current = false;\n // Reconnect after our mutations are done.\n const root = getBlockRoot();\n if (root && observerRef.current) {\n observerRef.current.observe(root, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n }\n }\n }, [blockId, blockType, contentEntries, getBlockRoot]);\n\n useEffect(() => {\n if (process.env.NODE_ENV === 'development') {\n console.log('[CMS] ClientEditableBlock mounted', { blockId, blockType });\n }\n setMounted(true);\n }, [blockId, blockType]);\n\n useIsomorphicLayoutEffect(() => {\n ensureCmsGlobals();\n\n const blockRoot = getBlockRoot();\n if (!blockRoot) return;\n\n // Stamp CMS attributes directly on the component's root element.\n blockRoot.setAttribute('data-cms-block', '');\n blockRoot.setAttribute('data-block-id', blockId);\n blockRoot.setAttribute('data-block-type', blockType);\n\n // Position toolbar at (x, y) without animating the placement itself —\n // suppress top/left transitions for the instant snap, then restore.\n const positionToolbar = (x: number, y: number) => {\n const el = toolbarElRef.current;\n if (!el) return;\n const { width: tw, height: th } = el.getBoundingClientRect();\n const top = Math.max(4, y - th - 12);\n const left = Math.max(4, Math.min(x - tw / 2, window.innerWidth - tw - 4));\n el.style.transition = 'opacity 0.15s ease, transform 0.15s ease';\n el.style.top = `${top}px`;\n el.style.left = `${left}px`;\n };\n\n const refreshSelectedOutline = () => {\n setSelectedOutlineRect((current) => (current ? blockRoot.getBoundingClientRect() : current));\n };\n\n // Cursor circle follows the mouse to indicate the block is interactive.\n const showCursor = (e: MouseEvent) => {\n if (toolbarVisibleRef.current) return;\n setHoverOutlineRect(blockRoot.getBoundingClientRect());\n const el = cursorElRef.current;\n if (!el) return;\n el.style.top = `${e.clientY}px`;\n el.style.left = `${e.clientX}px`;\n el.classList.add('cms-cursor-visible');\n };\n const moveCursor = (e: MouseEvent) => {\n if (toolbarVisibleRef.current) return;\n const el = cursorElRef.current;\n if (!el) return;\n el.style.top = `${e.clientY}px`;\n el.style.left = `${e.clientX}px`;\n };\n const hideCursor = () => {\n cursorElRef.current?.classList.remove('cms-cursor-visible');\n setHoverOutlineRect(null);\n };\n\n // On right-click: first time suppresses the browser context menu and shows\n // the CMS toolbar instead. If the toolbar is already visible the event is\n // not prevented so the browser's native context menu opens as a fallback.\n const handleContextMenu = (e: MouseEvent) => {\n if ((e.target as Element).closest('[data-cms-toolbar]')) return;\n if (toolbarVisibleRef.current) return; // fall through to browser context menu\n e.preventDefault();\n hideCursor();\n positionToolbar(e.clientX, e.clientY);\n toolbarVisibleRef.current = true;\n toolbarElRef.current?.classList.add('cms-toolbar-visible');\n };\n\n // Dismiss toolbar when clicking outside this block or its toolbar.\n const handleClickOutside = (e: MouseEvent) => {\n if (!toolbarVisibleRef.current) return;\n const target = e.target as Element;\n if (target.closest('[data-cms-toolbar]')) return;\n if (blockRoot.contains(target)) return;\n toolbarElRef.current?.classList.remove('cms-toolbar-visible');\n toolbarVisibleRef.current = false;\n };\n\n const hideOnScroll = () => {\n hideCursor();\n toolbarElRef.current?.classList.remove('cms-toolbar-visible');\n toolbarVisibleRef.current = false;\n refreshSelectedOutline();\n };\n\n const handleWindowMessage = (event: MessageEvent) => {\n if (!isTrustedCmsParentMessage(event)) return;\n if (event.data?.type !== 'cms-select-block') return;\n const selectedBlockId = typeof event.data.blockId === 'string' ? event.data.blockId : null;\n if (selectedBlockId === blockId) {\n setSelectedOutlineRect(blockRoot.getBoundingClientRect());\n } else {\n setSelectedOutlineRect(null);\n }\n };\n\n blockRoot.addEventListener('mouseenter', showCursor);\n blockRoot.addEventListener('mousemove', moveCursor);\n blockRoot.addEventListener('mouseleave', hideCursor);\n blockRoot.addEventListener('contextmenu', handleContextMenu);\n document.addEventListener('click', handleClickOutside);\n window.addEventListener('scroll', hideOnScroll, { passive: true, capture: true });\n window.addEventListener('resize', refreshSelectedOutline, { passive: true });\n window.addEventListener('message', handleWindowMessage);\n\n // Initial span injection after React's first commit.\n injectSpans();\n\n // Re-inject whenever the child component mutates the DOM.\n const observer = new MutationObserver(injectSpans);\n observerRef.current = observer;\n observer.observe(blockRoot, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n return () => {\n observer.disconnect();\n observerRef.current = null;\n blockRoot.removeEventListener('mouseenter', showCursor);\n blockRoot.removeEventListener('mousemove', moveCursor);\n blockRoot.removeEventListener('mouseleave', hideCursor);\n blockRoot.removeEventListener('contextmenu', handleContextMenu);\n document.removeEventListener('click', handleClickOutside);\n window.removeEventListener('scroll', hideOnScroll, { capture: true });\n window.removeEventListener('resize', refreshSelectedOutline);\n window.removeEventListener('message', handleWindowMessage);\n };\n }, [injectSpans, blockId, blockType, getBlockRoot]);\n\n const portalRoot = mounted ? getCmsOverlayRoot() : null;\n\n return (\n <>\n <span ref={sentinelRef} style={{ display: 'none' }} aria-hidden />\n {children}\n {portalRoot &&\n (selectedOutlineRect ?? hoverOutlineRect) &&\n createPortal(\n <BlockOutline blockRect={(selectedOutlineRect ?? hoverOutlineRect) as DOMRect} />,\n portalRoot\n )}\n {portalRoot &&\n createPortal(<div ref={cursorElRef} className=\"cms-block-cursor\" />, portalRoot)}\n {portalRoot &&\n createPortal(<BlockToolbar ref={toolbarElRef} blockId={blockId} />, portalRoot)}\n </>\n );\n}\n","'use client';\n\nimport { useLayoutEffect, useRef } from 'react';\n\n/**\n * Block Outline Component\n *\n * Renders a position:fixed border overlay around a hovered block.\n * Tries up to 3 offset values (4px → 0px → -2px inset) to keep every\n * edge of the border visible inside the viewport before giving up.\n */\nexport function BlockOutline({ blockRect }: { blockRect: DOMRect }) {\n const outlineRef = useRef<HTMLDivElement>(null);\n\n useLayoutEffect(() => {\n const el = outlineRef.current;\n if (!el) return;\n\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n\n // Attempt progressively smaller offsets until the border is fully visible.\n // offset=4 → normal outline-offset feel\n // offset=0 → border flush with block edge\n // offset=-2 → border drawn inside the block (inset)\n const offsets = [4, 0, -2];\n\n for (const offset of offsets) {\n const pad = offset + 2; // 2px border + offset\n el.style.top = `${blockRect.top - pad}px`;\n el.style.left = `${blockRect.left - pad}px`;\n el.style.width = `${blockRect.width + pad * 2}px`;\n el.style.height = `${blockRect.height + pad * 2}px`;\n\n const rect = el.getBoundingClientRect();\n if (rect.top >= 0 && rect.left >= 0 && rect.right <= vw && rect.bottom <= vh) break;\n }\n }, [blockRect]);\n\n return (\n <div\n ref={outlineRef}\n data-cms-outline=\"true\"\n style={{\n position: 'fixed',\n border: '2px solid #3b82f6',\n borderRadius: '2px',\n pointerEvents: 'none',\n zIndex: 99998,\n boxSizing: 'border-box',\n }}\n />\n );\n}\n","'use client';\n\nimport { ChevronDownIcon, ChevronUpIcon, PlusIcon, TrashIcon } from '@heroicons/react/24/outline';\nimport { forwardRef } from 'react';\nimport { postMessageToCmsParent } from './cms-post-message';\n\n/**\n * Block Toolbar Component\n *\n * Provides move up/down and delete controls for blocks in edit mode.\n * Position is managed imperatively by the parent via a forwarded ref —\n * the toolbar follows the mouse cursor and has no internal layout logic.\n */\n\nexport const BlockToolbar = forwardRef<HTMLDivElement, { blockId: string }>(function BlockToolbar(\n { blockId },\n ref\n) {\n const handleAction = (action: string) => {\n postMessageToCmsParent({ type: 'cms-block-action', action, blockId });\n };\n\n return (\n <div ref={ref} className=\"cms-block-toolbar\" data-cms-toolbar=\"true\">\n <button\n type=\"button\"\n title=\"Move up\"\n aria-label=\"Move up\"\n data-action=\"move-up\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('move-up');\n }}\n >\n <ChevronUpIcon />\n </button>\n <button\n type=\"button\"\n title=\"Move down\"\n aria-label=\"Move down\"\n data-action=\"move-down\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('move-down');\n }}\n >\n <ChevronDownIcon />\n </button>\n <button\n type=\"button\"\n title=\"Add block\"\n aria-label=\"Add block\"\n data-action=\"add-block\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('add-block');\n }}\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n className=\"delete\"\n title=\"Delete block\"\n aria-label=\"Delete block\"\n data-action=\"delete\"\n onClick={(e) => {\n e.stopPropagation();\n handleAction('delete');\n }}\n >\n <TrashIcon />\n </button>\n </div>\n );\n});\n","/**\n * Trusted-origin helpers for CMS template-builder postMessage traffic\n * between the admin UI (parent) and the site preview iframe (child).\n */\n\nexport const CMS_PARENT_ORIGIN_PARAM = 'cms_parent_origin';\n\nexport function parseOrigin(url: string | undefined): string | null {\n if (!url) return null;\n try {\n return new URL(url).origin;\n } catch {\n return null;\n }\n}\n\nfunction getParentOriginFromQueryParam(): string | null {\n if (typeof window === 'undefined') return null;\n const value = new URLSearchParams(window.location.search).get(CMS_PARENT_ORIGIN_PARAM);\n return parseOrigin(value ?? undefined);\n}\n\nfunction getReferrerOrigin(): string | null {\n if (typeof document === 'undefined' || !document.referrer) return null;\n return parseOrigin(document.referrer);\n}\n\n/** Same-origin embed (e.g. proxied admin + preview on the customer domain). */\nfunction getSameOriginParentOrigin(): string | null {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) {\n return null;\n }\n try {\n return window.parent.location.origin;\n } catch {\n return null;\n }\n}\n\n/** Origins allowed to send messages to the preview iframe (CMS admin hosts). */\nexport function getAllowedCmsParentOrigins(explicitParentOrigin?: string): string[] {\n const origins = new Set<string>();\n const apiOrigin = parseOrigin(process.env.NEXT_PUBLIC_CMS_API_URL);\n if (apiOrigin) origins.add(apiOrigin);\n\n const fromQuery = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromQuery) origins.add(fromQuery);\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) origins.add(referrerOrigin);\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) origins.add(sameOriginParent);\n\n return [...origins];\n}\n\n/**\n * Target origin when posting from the preview iframe to the CMS parent.\n *\n * When the admin is proxied on a customer domain, the parent window origin is\n * the customer site — not NEXT_PUBLIC_CMS_API_URL. Prefer explicit/referrer/\n * same-origin parent detection over the CMS API URL.\n */\nexport function getCmsParentTargetOrigin(\n preferredCmsUrl?: string,\n explicitParentOrigin?: string\n): string | null {\n const fromExplicit = parseOrigin(explicitParentOrigin) ?? getParentOriginFromQueryParam();\n if (fromExplicit) return fromExplicit;\n\n const referrerOrigin = getReferrerOrigin();\n if (referrerOrigin) return referrerOrigin;\n\n const sameOriginParent = getSameOriginParentOrigin();\n if (sameOriginParent) return sameOriginParent;\n\n const preferredOrigin = parseOrigin(preferredCmsUrl);\n if (preferredOrigin) return preferredOrigin;\n\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n return allowed[0] ?? null;\n}\n\nexport function isTrustedCmsParentMessage(\n event: MessageEvent,\n explicitParentOrigin?: string\n): boolean {\n const allowed = getAllowedCmsParentOrigins(explicitParentOrigin);\n if (allowed.length === 0) return false;\n if (!allowed.includes(event.origin)) return false;\n return event.source === window.parent;\n}\n\nexport function postMessageToCmsParent(\n message: unknown,\n options?: { preferredCmsUrl?: string; explicitParentOrigin?: string }\n): void {\n if (typeof window === 'undefined' || !window.parent || window.parent === window) return;\n const targetOrigin = getCmsParentTargetOrigin(\n options?.preferredCmsU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