| 427 | } |
| 428 | |
| 429 | export default actionable(targetable(class extends HTMLElement { |
| 430 | static [target.static] = [ |
| 431 | 'textarea', |
| 432 | 'editorElement', |
| 433 | 'boldButton', |
| 434 | 'italicButton', |
| 435 | 'underlineButton', |
| 436 | 'linkButton', |
| 437 | 'linkTooltipTemplate' |
| 438 | ] |
| 439 | |
| 440 | async connectedCallback () { |
| 441 | if (!this.textarea || !this.editorElement) return |
| 442 | |
| 443 | this.textarea.style.display = 'none' |
| 444 | this.adjustShortcutsForPlatform() |
| 445 | |
| 446 | const tiptap = await loadTiptap() |
| 447 | |
| 448 | const { Editor, Extension, Document, Text, HardBreak, UndoRedo, Gapcursor, Dropcursor } = tiptap |
| 449 | |
| 450 | this.emailDocument = new DOMParser().parseFromString(this.textarea.value, 'text/html') |
| 451 | |
| 452 | const shadow = this.editorElement.attachShadow({ mode: 'open' }) |
| 453 | |
| 454 | shadow.adoptedStyleSheets = [editorStylesheet] |
| 455 | |
| 456 | this.emailDocument.head.querySelectorAll('style').forEach((style) => { |
| 457 | shadow.appendChild(style.cloneNode(true)) |
| 458 | }) |
| 459 | |
| 460 | const container = document.createElement('div') |
| 461 | const bodyStyle = this.emailDocument.body.getAttribute('style') |
| 462 | |
| 463 | if (bodyStyle) container.setAttribute('style', bodyStyle) |
| 464 | |
| 465 | shadow.appendChild(container) |
| 466 | |
| 467 | const LinkShortcut = Extension.create({ |
| 468 | name: 'linkShortcut', |
| 469 | addKeyboardShortcuts: () => ({ |
| 470 | 'Mod-k': () => { |
| 471 | this.toggleLink() |
| 472 | |
| 473 | return true |
| 474 | } |
| 475 | }) |
| 476 | }) |
| 477 | |
| 478 | this.editor = new Editor({ |
| 479 | element: container, |
| 480 | extensions: [ |
| 481 | Document, |
| 482 | Text, |
| 483 | HardBreak, |
| 484 | UndoRedo, |
| 485 | Gapcursor, |
| 486 | Dropcursor, |
nothing calls this directly
no outgoing calls
no test coverage detected