feat(wysiwyg): Add more block types

This commit is contained in:
Juergen Kunz
2025-06-24 20:32:03 +00:00
parent 856d354b5a
commit 68b4e9ec8e
6 changed files with 998 additions and 54 deletions

View File

@ -131,7 +131,6 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
// Listen for custom selection events from blocks
this.addEventListener('block-text-selected', (e: CustomEvent) => {
console.log('Received block-text-selected event:', e.detail);
if (!this.slashMenu.visible && e.detail.hasSelection && e.detail.text.length > 0) {
this.selectedText = e.detail.text;
@ -143,7 +142,6 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
y: Math.max(45, e.detail.rect.top - 45)
};
console.log('Showing formatting menu at:', coords);
// Show the formatting menu at the calculated position
this.formattingMenu.show(
@ -533,6 +531,20 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
// For image blocks, clear content and set empty metadata
currentBlock.content = '';
currentBlock.metadata = { url: '', loading: false };
} else if (type === 'youtube') {
// For YouTube blocks, clear content and set empty metadata
currentBlock.content = '';
currentBlock.metadata = { videoId: '', url: '' };
} else if (type === 'markdown') {
// For Markdown blocks, preserve content and default to edit mode
currentBlock.metadata = { showPreview: false };
} else if (type === 'html') {
// For HTML blocks, preserve content and default to edit mode
currentBlock.metadata = { showPreview: false };
} else if (type === 'attachment') {
// For attachment blocks, clear content and set empty files array
currentBlock.content = '';
currentBlock.metadata = { files: [] };
} else {
// For all other block types, ensure content is clean
currentBlock.content = currentBlock.content || '';
@ -556,10 +568,10 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
blockComponent.focusListItem();
}
});
} else if (type !== 'divider' && type !== 'image') {
} else if (type !== 'divider' && type !== 'image' && type !== 'youtube' && type !== 'markdown' && type !== 'html' && type !== 'attachment') {
this.blockOperations.focusBlock(currentBlock.id, 'start');
} else if (type === 'image') {
// Focus the image block (which will show the upload interface)
} else if (type === 'image' || type === 'youtube' || type === 'markdown' || type === 'html' || type === 'attachment') {
// Focus the non-editable block
this.blockOperations.focusBlock(currentBlock.id);
}
}
@ -733,7 +745,6 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
private updateFormattingMenuPosition(): void {
console.log('updateFormattingMenuPosition called');
// Get all shadow roots
const shadowRoots: ShadowRoot[] = [];
@ -749,7 +760,6 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
});
const coords = WysiwygFormatting.getSelectionCoordinates(...shadowRoots);
console.log('Selection coordinates:', coords);
if (coords) {
// Show the global formatting menu at absolute coordinates
@ -758,7 +768,6 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
async (command: string) => await this.applyFormat(command)
);
} else {
console.log('No coordinates found');
}
}
@ -924,7 +933,6 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
* Undo the last action
*/
private undo(): void {
console.log('Undo triggered');
const state = this.history.undo();
if (state) {
this.restoreState(state);
@ -935,7 +943,6 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
* Redo the next action
*/
private redo(): void {
console.log('Redo triggered');
const state = this.history.redo();
if (state) {
this.restoreState(state);