/** * Pure helpers for the HTML embed node view. Kept out of the React component so * the sandbox srcdoc builder and the execution/edit policy can be unit-tested * against a bare environment with no Tiptap/Mantine providers. */ /** postMessage type the sandboxed iframe uses to report its content height. */ export const HTML_EMBED_HEIGHT_MESSAGE = "gitmost-html-embed-height"; /** * Build the `srcdoc` document for the sandboxed embed iframe. * * The user's `source` is placed verbatim, then a small bootstrap `; return `${source || ""}${bootstrap}`; } /** * Execution policy split by editor mode: * - READ-ONLY / public-share view: the SERVER already decided whether to * include the embed (it strips htmlEmbed from shared content when the * workspace master toggle is OFF). An anonymous viewer has no workspace and * thus reads `featureEnabled` as false, so we must NOT gate rendering on it * here — we render exactly the `source` the server chose to serve. * - EDITABLE editor: gate on the per-workspace master toggle so an author sees * the inert placeholder when the feature is OFF. */ export function shouldExecute( isEditable: boolean, featureEnabled: boolean, ): boolean { return !isEditable || featureEnabled; } /** * The edit affordance is only meaningful in edit mode and is offered only when * the workspace master toggle is ON. The block renders in a sandboxed iframe * (no same-origin access), so authoring is allowed to ANY member — there is no * admin requirement. */ export function canEdit(isEditable: boolean, featureEnabled: boolean): boolean { return isEditable && featureEnabled; }