UNPKG

tiptap-extension-iframely

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