import { html, type TemplateResult } from '@design.estate/dees-element'; import { type IBlock } from './wysiwyg.types.js'; import { WysiwygConverters } from './wysiwyg.converters.js'; export class WysiwygBlocks { static renderListContent(content: string, metadata?: any): string { const items = content.split('\n').filter(item => item.trim()); if (items.length === 0) return ''; const listTag = metadata?.listType === 'ordered' ? 'ol' : 'ul'; return `<${listTag}>${items.map(item => `
  • ${WysiwygConverters.escapeHtml(item)}
  • `).join('')}`; } static renderBlock( block: IBlock, isSelected: boolean, handlers: { onInput: (e: InputEvent) => void; onKeyDown: (e: KeyboardEvent) => void; onFocus: () => void; onBlur: () => void; onCompositionStart: () => void; onCompositionEnd: () => void; } ): TemplateResult { if (block.type === 'divider') { return html`

    `; } if (block.type === 'list') { return html`
    `; } return html`
    `; } static setCursorToEnd(element: HTMLElement): void { const range = document.createRange(); const sel = window.getSelection(); range.selectNodeContents(element); range.collapse(false); sel!.removeAllRanges(); sel!.addRange(range); } static setCursorToStart(element: HTMLElement): void { const range = document.createRange(); const sel = window.getSelection(); range.selectNodeContents(element); range.collapse(true); sel!.removeAllRanges(); sel!.addRange(range); } static focusListItem(listElement: HTMLElement): void { const firstLi = listElement.querySelector('li'); if (firstLi) { firstLi.focus(); const range = document.createRange(); const sel = window.getSelection(); range.selectNodeContents(firstLi); range.collapse(true); sel!.removeAllRanges(); sel!.addRange(range); } } }