//#region src/core/content/visual-editing.d.ts /** A reference from a rendered region back to the field that produced it. */ interface EditRef { collection: string; id: number; field: string; } /** The data attribute editable regions are tagged with. */ declare const EDIT_ATTR = "data-louise-edit"; /** * Per-item stable key on `array`/block items (#15, per-block tagging). The * editor's block builder stamps this on each block it creates so a click-to- * edit ref (`blocks.<_key>`) survives reordering—unlike a bare array index. * It rides along in the block's JSON (the `array` field is a verbatim JSON * column) and is never rendered as an input (the editor only renders declared * sub-fields). */ declare const BLOCK_KEY = "_key"; /** * Generate a stable block key. Deliberately starts with a letter so a ref * segment `blocks.` is always distinguishable from a legacy index path * (`blocks..`) by whether the segment is numeric—see * {@link parseBlockFieldRef}'s consumers. */ declare function newBlockKey(): string; /** * Split a block field path into the array field name and the target block's * key (or legacy index). Handles both the per-block wrapper ref * (`blocks.<_key>`) and the per-field live-preview path (`blocks.. * `)—either way the first segment is the array, the second the * block. Returns null for a bare array ref (`blocks`) that names no specific * block. Shared by the editor (routing a click to a block) and the block * builder (focusing it) so the two can't drift. */ declare function parseBlockFieldRef(field: string): { field: string; key: string; } | null; /** `postMessage` payload type for a click-to-edit selection. */ declare const VISUAL_EDIT_MESSAGE = "louise:visual-edit"; declare function encodeEditRef(ref: EditRef): string; /** Parse an {@link EditRef} string, or null if malformed. */ declare function decodeEditRef(value: string): EditRef | null; /** * Attribute object to spread onto a rendered element so the overlay can map * it back to its source field, for example, `

`. */ declare function editAttr(ref: EditRef): Record; interface VisualEditingMessage { type: typeof VISUAL_EDIT_MESSAGE; ref: EditRef; } /** `postMessage` type carrying in-progress field values into the preview. */ declare const PREVIEW_VALUES_MESSAGE = "louise:preview-values"; interface PreviewValuesMessage { type: typeof PREVIEW_VALUES_MESSAGE; /** Which document the values belong to—must match the preview's. */ collection: string; id: number; /** Field key → current value (only string values patch text regions). */ values: Record; } /** * Patch tagged regions' text from in-progress field values. For each string * value, updates every `[data-louise-edit="collection:id:field"]` element's * `textContent`. Pure (takes the root to search), so it's unit-testable * without a live preview window. */ declare function applyPreviewValues(root: ParentNode, target: { collection: string; id: number; }, values: Record): void; interface PreviewSyncOptions { /** The document this preview renders—messages for others are ignored. */ collection: string; id: number; /** Where to search for tagged regions. Default `document`. */ root?: ParentNode; /** * Only accept messages from this origin (the editor). Set it: without it, * any window that can reach the preview can rewrite its visible text, and * the preview logs a warning when it mounts (#698). */ allowedOrigin?: string; } /** * Mount the live-preview receiver on a preview page (browser-only). Listens * for {@link PreviewValuesMessage} from the editor window and patches tagged * text regions via {@link applyPreviewValues}. Returns a cleanup function. */ declare function mountPreviewSync(options: PreviewSyncOptions): () => void; interface VisualEditingOptions { /** Called with the decoded ref when an editable region is clicked. */ onSelect?: (ref: EditRef, element: Element) => void; /** * Origin to `postMessage` the selection to the parent window. Default * `"*"`. Set to the editor origin in production. */ targetOrigin?: string; /** Outline color for the hover highlight. Default a teal accent. */ highlightColor?: string; /** * Resolve a stega-encoded {@link EditRef} from a text run (pass `stegaDecode` * from `louise-toolkit/stega`). When provided, the overlay ALSO hit-tests text * nodes: prose tagged invisibly via stega becomes a click target with no * wrapper element—in addition to the `data-louise-edit` element targets. * Kept as an injected callback so this module stays free of the optional * `@vercel/stega` dependency. */ resolveStega?: (text: string) => EditRef | null; } /** * Mount the click-to-edit overlay. Browser-only—call from a preview page's * client script. Highlights `[data-louise-edit]` elements on hover and, on * click, calls `onSelect` and posts a {@link VisualEditingMessage} to the * parent window. With `resolveStega`, also hit-tests stega-tagged text runs * (highlighted via a floating box, since a text node has no outline). Returns a * cleanup function that removes the listeners. */ declare function mountVisualEditing(options?: VisualEditingOptions): () => void; /** * Strip stega payloads from a copied selection's `text`/`html`, and report * whether anything was removed—so {@link mountStegaClipboardGuard} only * overrides the clipboard when a payload was actually present (an ordinary copy * is left to the browser). Pure, so the decision is testable without a live * `Selection`/`ClipboardEvent`. */ declare function cleanCopiedStega(text: string, html: string): { text: string; html: string; changed: boolean; }; /** * Mount the clipboard guard (browser-only). Installs a capturing `copy` listener * that rewrites the copied `text/plain` (+ `text/html`) through {@link stegaClean}, * but only when a stega payload is present, so a normal copy is untouched. * * Idempotent: installs a single listener per document (which survives soft * navigation, since the document persists), so it's safe to call on every mount. * References `document` lazily, so importing it server-side is harmless. Returns * a cleanup function. The edit client mounts this automatically; call it yourself * only if you wire visual editing by hand. */ declare function mountStegaClipboardGuard(target?: Document): () => void; //#endregion export { mountVisualEditing as _, PreviewSyncOptions as a, VisualEditingMessage as c, cleanCopiedStega as d, decodeEditRef as f, mountStegaClipboardGuard as g, mountPreviewSync as h, PREVIEW_VALUES_MESSAGE as i, VisualEditingOptions as l, encodeEditRef as m, EDIT_ATTR as n, PreviewValuesMessage as o, editAttr as p, EditRef as r, VISUAL_EDIT_MESSAGE as s, BLOCK_KEY as t, applyPreviewValues as u, newBlockKey as v, parseBlockFieldRef as y };