-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add iframe extension to insert embeds
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<command-button | ||
:command="openInsertVideoControl" | ||
tooltip="Insert Video" | ||
icon="video" | ||
/> | ||
</template> | ||
|
||
<script> | ||
import CommandButton from './CommandButton.vue'; | ||
export default { | ||
name: 'IframeCommandButton', | ||
components: { | ||
CommandButton, | ||
}, | ||
props: { | ||
editorContext: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
methods: { | ||
openInsertVideoControl () { | ||
this.$prompt('', 'Insert Video', { | ||
confirmButtonText: 'Insert', | ||
cancelButtonText: 'Cancel', | ||
inputPlaceholder: 'Href', | ||
roundButton: true, | ||
}).then(({ value: href }) => { | ||
this.editorContext.commands.iframe({ src: href }); | ||
}).catch(() => { | ||
}); | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Node } from 'tiptap'; | ||
import IframeCommandButton from '../components/MenuCommands/IframeCommandButton.vue'; | ||
|
||
export default class Iframe 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', | ||
}], | ||
}; | ||
} | ||
|
||
commands ({ type }) { | ||
return attrs => (state, dispatch) => { | ||
const { selection } = state; | ||
const position = selection.$cursor ? selection.$cursor.pos : selection.$to.pos; | ||
const node = type.create(attrs); | ||
const transaction = state.tr.insert(position, node); | ||
dispatch(transaction); | ||
}; | ||
} | ||
|
||
get view () { | ||
return { | ||
props: ['node', 'updateAttrs', 'view'], | ||
computed: { | ||
src: { | ||
get () { | ||
return this.node.attrs.src; | ||
}, | ||
set (src) { | ||
this.updateAttrs({ | ||
src, | ||
}); | ||
}, | ||
}, | ||
}, | ||
template: ` | ||
<div class="iframe"> | ||
<iframe class="iframe__embed" :src="src"></iframe> | ||
</div> | ||
`, | ||
}; | ||
} | ||
|
||
menuBtnView (editorContext) { | ||
return { | ||
component: IframeCommandButton, | ||
componentProps: { | ||
editorContext, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters