12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { Node } from '@tiptap/core'
- export interface IframeOptions {
- allowFullscreen: boolean,
- HTMLAttributes: {
- [key: string]: any
- },
- }
- declare module '@tiptap/core' {
- interface Commands<ReturnType> {
- iframe: {
- /**
- * Add an iframe
- */
- setIframe: (options: { src: string }) => ReturnType,
- }
- }
- }
- export default Node.create({
- name: 'Iframe',
- group: 'block',
- atom: true,
- defaultOptions: <IframeOptions>{
- allowFullscreen: true,
- HTMLAttributes: {
- class: 'iframe-wrapper',
- },
- },
- addAttributes() {
- return {
- src: {
- default: null,
- },
- frameborder: {
- default: 0,
- },
- scrolling: {
- default: "auto",
- },
- width: {
- default: "500",
- },
- height: {
- default: "300"
- },
- class: {
- default: "",
- },
- allowfullscreen: {
- default: this.options.allowFullscreen,
- },
- }
- },
- parseHTML() {
- return [{
- tag: 'iframe',
- }]
- },
- renderHTML({ HTMLAttributes }) {
- return ['div', this.options.HTMLAttributes, ['iframe', HTMLAttributes]]
- },
- addCommands() {
- return {
- setIframe: (options: { src: string }) => ({ tr, dispatch }) => {
- const { selection } = tr
- const node = this.type.create(options)
- if (dispatch) {
- tr.replaceRangeWith(selection.from, selection.to, node)
- }
- return true
- },
- }
- },
- })
|