import { BaseBlockHandler, type IBlockEventHandlers } from '../block.base.js'; import type { IBlock } from '../../wysiwyg.types.js'; import { cssManager } from '@design.estate/dees-element'; import { WysiwygSelection } from '../../wysiwyg.selection.js'; import hlight from 'highlight.js'; import { cssGeistFontFamily, cssMonoFontFamily } from '../../../00fonts.js'; import { PROGRAMMING_LANGUAGES } from '../../wysiwyg.constants.js'; /** * CodeBlockHandler with improved architecture * * Key features: * 1. Simple DOM structure * 2. Line number handling * 3. Syntax highlighting only when not focused (grey text while editing) * 4. Clean event handling * 5. Copy button functionality */ export class CodeBlockHandler extends BaseBlockHandler { type = 'code'; private highlightTimer: any = null; render(block: IBlock, isSelected: boolean): string { const language = block.metadata?.language || 'typescript'; const content = block.content || ''; const lineCount = content.split('\n').length; // Generate line numbers let lineNumbersHtml = ''; for (let i = 1; i <= lineCount; i++) { lineNumbersHtml += `
${this.escapeHtml(content)}