import { html, css, CSSResult, property } from '@skhemata/skhemata-base'; import { SkhemataEditorQuill } from '@skhemata/skhemata-editor-quill'; import { SkhemataFormInput } from './SkhemataFormInput'; export class SkhemataFormQuill extends SkhemataFormInput { @property({ type: Number }) campaignId; static get styles() { return [ ...super.styles, css` button.dropzone { cursor: pointer; border: none; margin: 0; padding: 0; width: 100%; height: 100%; border-radius: 4px; background: transparent; } .message { width: max-content; } #dropzone { border: none; } img { max-height: 15rem; } #sp-message { padding: 1rem; } .description { margin-bottom: 1rem; } `, ]; } static get scopedElements() { return { 'sk-quill': SkhemataEditorQuill, }; } @property({ type: Object, attribute: false }) dropzone: any; @property({ type: HTMLElement }) editor: any; @property({ type: String }) helpMessage = ''; async firstUpdated() { await super.firstUpdated(); this.editor = this.shadowRoot.getElementById('editor'); this.editor.updateComplete.then(() => { this.initQuill(); }); } initQuill() { if(this.value) { // const delta = JSON.parse(this.value)?.ops; // this.editor.setContents(delta); const delta = this.editor.quill?.clipboard.convert(this.value) this.editor.quill.setContents(delta, 'silent'); } this.editor.quill?.on('text-change', () => { // this.value = JSON.stringify(this.editor.quill.getContents()); this.value = this.editor.quill.root.innerHTML; }); } render() { const field = html`
${this.label && !this.horizontal ? html`` : null}
${this.description && !this.horizontal ? html`

${this.description}

` : null}
${!this.valid ? html`

${this.errorMessage}

` : ``}
`; const horizontalFieldLabel = html`
${this.label ? html`` : null} ${this.description ? html`

${this.description}

` : null}
`; const horizontalField = html`
${this.label || this.description ? horizontalFieldLabel : null}
${field}
`; return this.horizontal ? horizontalField : field; } }