component WysiwygEditor { outputs { input(payload: { value?: string | number | boolean | null; values?: Array; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null) change(payload: { value?: string | number | boolean | null; values?: Array; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null) focus(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object }) blur(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object }) } props { size: string = "default" color: string = "primary" title: string = "Wysiwyg Editor" description: string = "" items: unknown[] = [] variant: string = "default" value: string = "" readonly: boolean = false placeholder: string = "Write something…" class: string = "" } functions { client function format(command, sourceEvent, root, editor) { sourceEvent.preventDefault() root = sourceEvent.currentTarget.closest(".wrn-editor") editor = root.querySelector("[contenteditable]") editor.focus() document.execCommand(command, false, null) output.input({ value: editor.innerHTML, text: editor.textContent }) output.change({ value: editor.innerHTML, text: editor.textContent }) } client function edit(sourceEvent) { output.input({ value: sourceEvent.currentTarget.innerHTML, text: sourceEvent.currentTarget.textContent }) } client function finish(sourceEvent) { output.change({ value: sourceEvent.currentTarget.innerHTML, text: sourceEvent.currentTarget.textContent }); output.blur({ sourceEvent: sourceEvent }) } } view {
{#if title}{title}{/if}{#if description}

{description}

{/if}
{value}
} style { .wrn-editor { display:grid; gap:.65rem; color:var(--wrn-color-text); } .wrn-editor > p { margin:0; color:var(--wrn-color-muted); font-size:.875rem; } .wrn-editor__surface { border:1px solid var(--wrn-color-border); border-radius:var(--wrn-radius-md); overflow:hidden; background:var(--wrn-color-surface); } .wrn-editor__toolbar { display:flex; flex-wrap:wrap; gap:.25rem; padding:.4rem; border-bottom:1px solid var(--wrn-color-border); } .wrn-editor button { display:grid; place-items:center; width:2rem; height:2rem; border:0; border-radius:4px; background:transparent; color:inherit; cursor:pointer; } .wrn-editor button:hover { background:var(--wrn-color-surface-2); } .wrn-editor button span { width:1rem; height:1rem; } .wrn-editor__content { min-height:10rem; padding:1rem; outline-offset:-2px; font-size:.875rem; line-height:1.65; } .wrn-editor__content:empty::before { content:attr(data-placeholder); color:var(--wrn-color-muted); pointer-events:none; } } }