mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
improve demo resizing
This commit is contained in:
parent
ed0dc2d5ef
commit
f439538f38
@ -5,7 +5,7 @@
|
||||
</div>
|
||||
<iframe
|
||||
v-show="!isLoading"
|
||||
v-resize
|
||||
v-resize.quiet
|
||||
:src="`/demos/${name}?${query}`"
|
||||
style="background-color: transparent;"
|
||||
width="100%"
|
||||
|
@ -23,8 +23,17 @@ export default function (Vue, { head }) {
|
||||
Vue.use(PortalVue)
|
||||
|
||||
Vue.directive('resize', {
|
||||
bind(el, { value = {} }) {
|
||||
el.addEventListener('load', () => iframeResize(value, el))
|
||||
bind: (el, { value = {} }) => {
|
||||
el.addEventListener('load', () => {
|
||||
iframeResize({
|
||||
...value,
|
||||
messageCallback(messageData) {
|
||||
if (messageData.message === 'resize') {
|
||||
el.iFrameResizer.resize()
|
||||
}
|
||||
},
|
||||
}, el)
|
||||
})
|
||||
},
|
||||
unbind(el) {
|
||||
el.iFrameResizer.removeListeners()
|
||||
|
@ -23,6 +23,26 @@ export default {
|
||||
],
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
resizeObserver: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.resizeObserver = new window.ResizeObserver(() => {
|
||||
if (window.parentIFrame) {
|
||||
window.parentIFrame.sendMessage('resize')
|
||||
}
|
||||
})
|
||||
|
||||
this.resizeObserver.observe(document.body)
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.resizeObserver.unobserve(document.body)
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user