fix build

This commit is contained in:
Philipp Kühn
2021-08-26 15:15:47 +02:00
parent 52381b53fc
commit c5f3d0161b

View File

@@ -1,36 +1,38 @@
import iframeResize from 'iframe-resizer/js/iframeResizer' import iframeResize from 'iframe-resizer/js/iframeResizer'
class TiptapDemo extends HTMLElement { if (typeof window === 'object' && !window.process) {
url = 'https://embed.tiptap.dev' class TiptapDemo extends HTMLElement {
url = 'https://embed.tiptap.dev'
connectedCallback() { connectedCallback() {
const wrapper = document.createElement('div') const wrapper = document.createElement('div')
const iframe = document.createElement('iframe') const iframe = document.createElement('iframe')
const shadow = this.attachShadow({ mode: 'open' }) const shadow = this.attachShadow({ mode: 'open' })
const name = this.getAttribute('name') const name = this.getAttribute('name')
const inline = this.getAttribute('inline') === '' const inline = this.getAttribute('inline') === ''
const hideSource = this.getAttribute('hideSource') === '' const hideSource = this.getAttribute('hideSource') === ''
iframe.src = `${this.url}/preview/${name}?inline=${inline}&hideSource=${hideSource}` iframe.src = `${this.url}/preview/${name}?inline=${inline}&hideSource=${hideSource}`
iframe.width = '100%' iframe.width = '100%'
iframe.height = '0' iframe.height = '0'
iframe.frameBorder = '0' iframe.frameBorder = '0'
shadow.appendChild(wrapper) shadow.appendChild(wrapper)
iframe.addEventListener('load', () => { iframe.addEventListener('load', () => {
iframeResize({}, iframe) iframeResize({}, iframe)
}, { once: true }) }, { once: true })
const observer = new IntersectionObserver(([entry]) => { const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) { if (entry.isIntersecting) {
observer.unobserve(wrapper) observer.unobserve(wrapper)
wrapper.appendChild(iframe) wrapper.appendChild(iframe)
} }
}) })
observer.observe(wrapper) observer.observe(wrapper)
}
} }
}
window.customElements.define('tiptap-demo', TiptapDemo) window.customElements.define('tiptap-demo', TiptapDemo)
}