feat(editor): Add wysiwyg editor
This commit is contained in:
@ -220,7 +220,7 @@ export const demoFunc = () => html`
|
|||||||
<code>\`\`\`</code> Code block
|
<code>\`\`\`</code> Code block
|
||||||
</div>
|
</div>
|
||||||
<div class="shortcut">
|
<div class="shortcut">
|
||||||
<code>-</code> Bullet list
|
<code>* </code> or <code>- </code> Bullet list
|
||||||
</div>
|
</div>
|
||||||
<div class="shortcut">
|
<div class="shortcut">
|
||||||
<code>1.</code> Numbered list
|
<code>1.</code> Numbered list
|
||||||
|
@ -503,27 +503,38 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
|
|||||||
block.content = '';
|
block.content = '';
|
||||||
|
|
||||||
// Force update the block
|
// Force update the block
|
||||||
|
this.requestUpdate();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const blockElement = this.shadowRoot!.querySelector(`[data-block-id="${block.id}"]`) as HTMLDivElement;
|
const blockElement = this.shadowRoot!.querySelector(`[data-block-id="${block.id}"]`) as HTMLDivElement;
|
||||||
if (blockElement) {
|
if (blockElement) {
|
||||||
blockElement.textContent = '';
|
|
||||||
blockElement.focus();
|
blockElement.focus();
|
||||||
|
// Place cursor at the beginning for headings
|
||||||
|
const range = document.createRange();
|
||||||
|
const sel = window.getSelection();
|
||||||
|
range.selectNodeContents(blockElement);
|
||||||
|
range.collapse(true);
|
||||||
|
sel!.removeAllRanges();
|
||||||
|
sel!.addRange(range);
|
||||||
}
|
}
|
||||||
});
|
}, 0);
|
||||||
|
|
||||||
this.updateValue();
|
this.updateValue();
|
||||||
this.requestUpdate();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for list shortcuts
|
// Check for list shortcuts
|
||||||
const listPatterns = [
|
const listPatterns = [
|
||||||
{ pattern: /^(\*|-) $/, type: 'bullet' },
|
{ pattern: /^[*-] $/, type: 'bullet' },
|
||||||
{ pattern: /^(\d+)\. $/, type: 'ordered' },
|
{ pattern: /^(\d+)\. $/, type: 'ordered' },
|
||||||
{ pattern: /^(\d+)\) $/, type: 'ordered' }
|
{ pattern: /^(\d+)\) $/, type: 'ordered' }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Debug: Log content when it starts with * or -
|
||||||
|
if (block.content.startsWith('*') || block.content.startsWith('-')) {
|
||||||
|
console.log('List shortcut check - content:', JSON.stringify(block.content), 'length:', block.content.length);
|
||||||
|
}
|
||||||
|
|
||||||
for (const { pattern, type } of listPatterns) {
|
for (const { pattern, type } of listPatterns) {
|
||||||
if (pattern.test(block.content)) {
|
if (pattern.test(block.content)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -562,16 +573,21 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
|
|||||||
block.type = 'quote';
|
block.type = 'quote';
|
||||||
block.content = '';
|
block.content = '';
|
||||||
|
|
||||||
|
this.requestUpdate();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const blockElement = this.shadowRoot!.querySelector(`[data-block-id="${block.id}"]`) as HTMLDivElement;
|
const blockElement = this.shadowRoot!.querySelector(`[data-block-id="${block.id}"]`) as HTMLDivElement;
|
||||||
if (blockElement) {
|
if (blockElement) {
|
||||||
blockElement.textContent = '';
|
|
||||||
blockElement.focus();
|
blockElement.focus();
|
||||||
|
const range = document.createRange();
|
||||||
|
const sel = window.getSelection();
|
||||||
|
range.selectNodeContents(blockElement);
|
||||||
|
range.collapse(true);
|
||||||
|
sel!.removeAllRanges();
|
||||||
|
sel!.addRange(range);
|
||||||
}
|
}
|
||||||
});
|
}, 0);
|
||||||
|
|
||||||
this.updateValue();
|
this.updateValue();
|
||||||
this.requestUpdate();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,16 +597,21 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
|
|||||||
block.type = 'code';
|
block.type = 'code';
|
||||||
block.content = '';
|
block.content = '';
|
||||||
|
|
||||||
|
this.requestUpdate();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const blockElement = this.shadowRoot!.querySelector(`[data-block-id="${block.id}"]`) as HTMLDivElement;
|
const blockElement = this.shadowRoot!.querySelector(`[data-block-id="${block.id}"]`) as HTMLDivElement;
|
||||||
if (blockElement) {
|
if (blockElement) {
|
||||||
blockElement.textContent = '';
|
|
||||||
blockElement.focus();
|
blockElement.focus();
|
||||||
|
const range = document.createRange();
|
||||||
|
const sel = window.getSelection();
|
||||||
|
range.selectNodeContents(blockElement);
|
||||||
|
range.collapse(true);
|
||||||
|
sel!.removeAllRanges();
|
||||||
|
sel!.addRange(range);
|
||||||
}
|
}
|
||||||
});
|
}, 0);
|
||||||
|
|
||||||
this.updateValue();
|
this.updateValue();
|
||||||
this.requestUpdate();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user