add embed example
This commit is contained in:
62
examples/Components/Routes/Embeds/Iframe.js
Normal file
62
examples/Components/Routes/Embeds/Iframe.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Node } from 'tiptap/utils'
|
||||
|
||||
export default class IframeNode extends Node {
|
||||
|
||||
get name() {
|
||||
return 'iframe'
|
||||
}
|
||||
|
||||
get schema() {
|
||||
return {
|
||||
attrs: {
|
||||
src: {
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
group: 'block',
|
||||
selectable: false,
|
||||
parseDOM: [{
|
||||
tag: 'iframe',
|
||||
getAttrs: dom => ({
|
||||
src: dom.getAttribute('src'),
|
||||
}),
|
||||
}],
|
||||
toDOM: node => ['iframe', {
|
||||
src: node.attrs.src,
|
||||
frameborder: 0,
|
||||
allowfullscreen: 'true',
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
get view() {
|
||||
return {
|
||||
props: ['node', 'updateAttrs', 'editable'],
|
||||
data() {
|
||||
return {
|
||||
url: this.node.attrs.src,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChange(event) {
|
||||
if (!this.editable) {
|
||||
return
|
||||
}
|
||||
|
||||
this.url = event.target.value
|
||||
|
||||
this.updateAttrs({
|
||||
url: this.url,
|
||||
})
|
||||
},
|
||||
},
|
||||
template: `
|
||||
<div class="iframe">
|
||||
<iframe class="iframe__embed" :src="url"></iframe>
|
||||
<input class="iframe__input" type="text" :value="url" @input="onChange" v-if="editable" />
|
||||
</div>
|
||||
`,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user