tiptap-editor-codeveda 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -17,9 +17,10 @@ declare interface TiptapProps {
|
|
|
17
17
|
}) => void;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export declare const TiptapViewer: ({ styles, editorContent, }: {
|
|
20
|
+
export declare const TiptapViewer: ({ styles, editorContent, immediatelyRender, }: {
|
|
21
21
|
styles?: string;
|
|
22
22
|
editorContent?: string;
|
|
23
|
+
immediatelyRender?: boolean;
|
|
23
24
|
}) => JSX.Element | null;
|
|
24
25
|
|
|
25
26
|
export declare function useEditorContent(initial?: EditorContentPayload): {
|
|
@@ -8502,9 +8502,10 @@ const Ks = ({ editor: t, isReadOnly: e }) => {
|
|
|
8502
8502
|
] }) : null;
|
|
8503
8503
|
}, ka = ({
|
|
8504
8504
|
styles: t,
|
|
8505
|
-
editorContent: e
|
|
8505
|
+
editorContent: e,
|
|
8506
|
+
immediatelyRender: n = !1
|
|
8506
8507
|
}) => {
|
|
8507
|
-
const [,
|
|
8508
|
+
const [, r] = U({}), [o] = U(!0), i = yn({
|
|
8508
8509
|
extensions: [
|
|
8509
8510
|
jn,
|
|
8510
8511
|
Dn,
|
|
@@ -8546,22 +8547,23 @@ const Ks = ({ editor: t, isReadOnly: e }) => {
|
|
|
8546
8547
|
})
|
|
8547
8548
|
],
|
|
8548
8549
|
content: e || "<h1>Nothing on Canvas :(</h1>",
|
|
8549
|
-
editable: !
|
|
8550
|
+
editable: !o,
|
|
8551
|
+
immediatelyRender: n,
|
|
8550
8552
|
editorProps: {
|
|
8551
8553
|
attributes: {
|
|
8552
8554
|
class: `prose prose-sm sm:prose lg:prose-lg xl:prose-2xl mx-auto focus:outline-none min-h-[400px] p-4 ${t}`
|
|
8553
8555
|
}
|
|
8554
8556
|
},
|
|
8555
8557
|
onUpdate: () => {
|
|
8556
|
-
|
|
8558
|
+
r({});
|
|
8557
8559
|
},
|
|
8558
8560
|
onSelectionUpdate: () => {
|
|
8559
|
-
|
|
8561
|
+
r({});
|
|
8560
8562
|
}
|
|
8561
8563
|
});
|
|
8562
8564
|
return ge(() => {
|
|
8563
|
-
|
|
8564
|
-
}, [
|
|
8565
|
+
i && i.setEditable(!o);
|
|
8566
|
+
}, [i, o]), i ? /* @__PURE__ */ c.jsx("div", { className: "w-full max-w-6xl mx-auto p-4", children: /* @__PURE__ */ c.jsx(vn, { editor: i, className: "tiptap-editor" }) }) : null;
|
|
8565
8567
|
};
|
|
8566
8568
|
function Ca(t) {
|
|
8567
8569
|
const [e, n] = U(
|
|
@@ -34,4 +34,4 @@ React keys must be passed directly to JSX without using spread:
|
|
|
34
34
|
<li>And much more...</li>
|
|
35
35
|
</ul>
|
|
36
36
|
<p>Place your cursor at an empty line to see the floating menu, or select text to see formatting options in the bubble menu.</p>
|
|
37
|
-
`,editable:!l,editorProps:{attributes:{class:"prose prose-sm sm:prose lg:prose-lg xl:prose-2xl mx-auto focus:outline-none min-h-[400px] p-4"}},onUpdate:()=>{n?.({html:p.getHTML(),json:p.getJSON()}),a({})},onSelectionUpdate:()=>{n?.({html:p.getHTML(),json:p.getJSON()}),a({})}});k.useEffect(()=>{p&&p.setEditable(!l)},[p,l]),k.useEffect(()=>{if(!p)return;const v=()=>{if(p.isActive("table")&&!l){const{from:N}=p.state.selection;let C=null;const M=p.view.domAtPos(N);if(M.node&&M.node.parentElement){let T=M.node.parentElement;for(;T&&T!==p.view.dom;){if(T.tagName==="TABLE"){C=T;break}T=T.parentElement}}if(C){const T=C.getBoundingClientRect(),L=p.view.dom.getBoundingClientRect();w({top:T.top-L.top-60,left:T.left-L.left,show:!0})}}else w(N=>({...N,show:!1}))},x=()=>{v()};return p.on("selectionUpdate",x),p.on("update",x),()=>{p.off("selectionUpdate",x),p.off("update",x)}},[p]),k.useEffect(()=>{const v=x=>{x.target.closest(".image-input-container")||s(!1)};return o&&document.addEventListener("mousedown",v),()=>{document.removeEventListener("mousedown",v)}},[o]);const E=k.useCallback(async()=>{const v=document.createElement("input");v.type="file",v.accept="image/*",v.onchange=async x=>{const N=x.target.files?.[0];if(N&&t)try{f(!0);const C=await t(N);C&&p?.chain().focus().setImage({src:C}).run()}catch(C){console.error("Failed to upload image:",C),alert("Failed to upload image. Please try again.")}finally{f(!1)}},v.click()},[p,t]),y=k.useCallback(()=>{r.trim()&&(p?.chain().focus().setImage({src:r.trim()}).run(),i(""),s(!1))},[p,r]),S=k.useCallback(async()=>{const v=document.createElement("input");v.type="file",v.accept="video/*",v.onchange=async x=>{const N=x.target.files?.[0];if(N&&e)try{m(!0);const C=await e(N);if(C){console.log("Attempting to insert video:",{src:C,type:N.type,title:N.name});try{const M=p?.chain().focus().setVideo({src:C,type:N.type,title:N.name}).run();console.log("Video insertion result:",M)}catch(M){throw console.error("Error inserting video into editor:",M),M}}}catch(C){console.error("Failed to upload video:",C),console.error("Error details:",{message:C instanceof Error?C.message:"Unknown error",stack:C instanceof Error?C.stack:"No stack trace"}),alert(`Failed to upload video: ${C instanceof Error?C.message:"Unknown error"}`)}finally{m(!1)}else if(N&&!e){const C=new FileReader;C.onload=M=>{const T=M.target?.result;console.log("Attempting to insert base64 video:",{src:T.substring(0,100)+"...",type:N.type,title:N.name});try{const L=p?.chain().focus().setVideo({src:T,type:N.type,title:N.name}).run();console.log("Base64 video insertion result:",L)}catch(L){console.error("Error inserting base64 video into editor:",L)}},C.readAsDataURL(N)}},v.click()},[p,e]),R=k.useCallback(()=>{if(p)return Zo(p)},[p]);return p?c.jsxs("div",{className:"w-full max-w-6xl mx-auto p-4",children:[p&&c.jsx(Go,{editor:p}),c.jsx(Yo,{editor:p,isReadOnly:l,setIsReadOnly:d,onLogContent:R}),c.jsx(ki,{editor:p,isReadOnly:l,onImageUpload:E,onVideoUpload:S,isImageUploading:u,isVideoUploading:h,showImageInput:o,setShowImageInput:s,imageUrl:r,setImageUrl:i,handleImageUrlInsert:y,imageUploadFunction:t}),c.jsxs("div",{className:"relative border border-gray-300 border-t-1 rounded-t-lg rounded-b-lg min-h-[400px]",children:[c.jsx(G.EditorContent,{editor:p,className:"tiptap-editor"}),c.jsx(Wo,{editor:p,isReadOnly:l,onImageClick:()=>s(!o)}),c.jsx(qo,{editor:p,isReadOnly:l}),c.jsx(Ko,{editor:p,isReadOnly:l,position:b})]})]}):null},Qo=({styles:t,editorContent:e})=>{const[,
|
|
37
|
+
`,editable:!l,editorProps:{attributes:{class:"prose prose-sm sm:prose lg:prose-lg xl:prose-2xl mx-auto focus:outline-none min-h-[400px] p-4"}},onUpdate:()=>{n?.({html:p.getHTML(),json:p.getJSON()}),a({})},onSelectionUpdate:()=>{n?.({html:p.getHTML(),json:p.getJSON()}),a({})}});k.useEffect(()=>{p&&p.setEditable(!l)},[p,l]),k.useEffect(()=>{if(!p)return;const v=()=>{if(p.isActive("table")&&!l){const{from:N}=p.state.selection;let C=null;const M=p.view.domAtPos(N);if(M.node&&M.node.parentElement){let T=M.node.parentElement;for(;T&&T!==p.view.dom;){if(T.tagName==="TABLE"){C=T;break}T=T.parentElement}}if(C){const T=C.getBoundingClientRect(),L=p.view.dom.getBoundingClientRect();w({top:T.top-L.top-60,left:T.left-L.left,show:!0})}}else w(N=>({...N,show:!1}))},x=()=>{v()};return p.on("selectionUpdate",x),p.on("update",x),()=>{p.off("selectionUpdate",x),p.off("update",x)}},[p]),k.useEffect(()=>{const v=x=>{x.target.closest(".image-input-container")||s(!1)};return o&&document.addEventListener("mousedown",v),()=>{document.removeEventListener("mousedown",v)}},[o]);const E=k.useCallback(async()=>{const v=document.createElement("input");v.type="file",v.accept="image/*",v.onchange=async x=>{const N=x.target.files?.[0];if(N&&t)try{f(!0);const C=await t(N);C&&p?.chain().focus().setImage({src:C}).run()}catch(C){console.error("Failed to upload image:",C),alert("Failed to upload image. Please try again.")}finally{f(!1)}},v.click()},[p,t]),y=k.useCallback(()=>{r.trim()&&(p?.chain().focus().setImage({src:r.trim()}).run(),i(""),s(!1))},[p,r]),S=k.useCallback(async()=>{const v=document.createElement("input");v.type="file",v.accept="video/*",v.onchange=async x=>{const N=x.target.files?.[0];if(N&&e)try{m(!0);const C=await e(N);if(C){console.log("Attempting to insert video:",{src:C,type:N.type,title:N.name});try{const M=p?.chain().focus().setVideo({src:C,type:N.type,title:N.name}).run();console.log("Video insertion result:",M)}catch(M){throw console.error("Error inserting video into editor:",M),M}}}catch(C){console.error("Failed to upload video:",C),console.error("Error details:",{message:C instanceof Error?C.message:"Unknown error",stack:C instanceof Error?C.stack:"No stack trace"}),alert(`Failed to upload video: ${C instanceof Error?C.message:"Unknown error"}`)}finally{m(!1)}else if(N&&!e){const C=new FileReader;C.onload=M=>{const T=M.target?.result;console.log("Attempting to insert base64 video:",{src:T.substring(0,100)+"...",type:N.type,title:N.name});try{const L=p?.chain().focus().setVideo({src:T,type:N.type,title:N.name}).run();console.log("Base64 video insertion result:",L)}catch(L){console.error("Error inserting base64 video into editor:",L)}},C.readAsDataURL(N)}},v.click()},[p,e]),R=k.useCallback(()=>{if(p)return Zo(p)},[p]);return p?c.jsxs("div",{className:"w-full max-w-6xl mx-auto p-4",children:[p&&c.jsx(Go,{editor:p}),c.jsx(Yo,{editor:p,isReadOnly:l,setIsReadOnly:d,onLogContent:R}),c.jsx(ki,{editor:p,isReadOnly:l,onImageUpload:E,onVideoUpload:S,isImageUploading:u,isVideoUploading:h,showImageInput:o,setShowImageInput:s,imageUrl:r,setImageUrl:i,handleImageUrlInsert:y,imageUploadFunction:t}),c.jsxs("div",{className:"relative border border-gray-300 border-t-1 rounded-t-lg rounded-b-lg min-h-[400px]",children:[c.jsx(G.EditorContent,{editor:p,className:"tiptap-editor"}),c.jsx(Wo,{editor:p,isReadOnly:l,onImageClick:()=>s(!o)}),c.jsx(qo,{editor:p,isReadOnly:l}),c.jsx(Ko,{editor:p,isReadOnly:l,position:b})]})]}):null},Qo=({styles:t,editorContent:e,immediatelyRender:n=!1})=>{const[,r]=k.useState({}),[i]=k.useState(!0),o=G.useEditor({extensions:[Kt,Gt,Ut,Ft,Ht,Yt.configure({inline:!1,allowBase64:!0}),Zt.configure({openOnClick:!1,autolink:!0,defaultProtocol:"https"}),pn,mn,Xt,Qt.configure({types:["textStyle"]}),en.configure({multicolor:!0}),hn,gn,bn,wn,xn,yn,vn,En,Sn.configure({inline:!1,allowBase64:!0,HTMLAttributes:{class:"max-w-full h-auto rounded-lg shadow-sm"}})],content:e||"<h1>Nothing on Canvas :(</h1>",editable:!i,immediatelyRender:n,editorProps:{attributes:{class:`prose prose-sm sm:prose lg:prose-lg xl:prose-2xl mx-auto focus:outline-none min-h-[400px] p-4 ${t}`}},onUpdate:()=>{r({})},onSelectionUpdate:()=>{r({})}});return k.useEffect(()=>{o&&o.setEditable(!i)},[o,i]),o?c.jsx("div",{className:"w-full max-w-6xl mx-auto p-4",children:c.jsx(G.EditorContent,{editor:o,className:"tiptap-editor"})}):null};function es(t){const[e,n]=k.useState(t??{html:"",json:null}),r=k.useCallback(i=>{n(i)},[]);return{content:e,html:e.html,json:e.json,setContent:r}}j.TiptapEditor=Xo,j.TiptapViewer=Qo,j.useEditorContent=es,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED