tiptap-extension-iframely
Version:
A Tiptap extension for adding embedded content with Iframely.
2 lines (1 loc) • 894 B
JavaScript
import{Node as o,mergeAttributes as d}from"@tiptap/core";import{NodeViewWrapper as i,ReactNodeViewRenderer as s}from"@tiptap/react";import{useEffect as m,useRef as a}from"react";import{jsx as n}from"react/jsx-runtime";var c=o.create({name:"iframely",group:"block",atom:!0,draggable:!0,addAttributes(){return{src:{default:null}}},parseHTML(){return[{tag:'div[data-type="iframely-embed"]'}]},renderHTML({HTMLAttributes:e}){return["div",d(e,{"data-type":"iframely-embed"})]},addCommands(){return{setIframelyEmbed:e=>({commands:r})=>r.insertContent({type:this.name,attrs:e})}},addNodeView(){return s(({node:e})=>{let r=a(null),t=a(!1);return m(()=>{t.current||!r.current||typeof window.iframely!="undefined"&&(window.iframely.load(r.current,e.attrs.src),t.current=!0)},[e.attrs.src]),n(i,{children:n("div",{ref:r,className:"not-prose my-8 overflow-hidden shadow-sm"})})})}});export{c as Iframely};